@spearwolf/shadow-objects 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +49 -13
- package/bundle.js +7 -7
- package/package.json +2 -2
- package/src/elements/ShaeEntElement.d.ts +4 -4
- package/src/elements/ShaeEntElement.d.ts.map +1 -1
- package/src/elements/ShaeEntElement.js +4 -5
- package/src/elements/ShaeEntElement.js.map +2 -2
- package/src/elements/ShaePropElement.d.ts +5 -5
- package/src/elements/ShaePropElement.d.ts.map +1 -1
- package/src/elements/ShaePropElement.js +2 -2
- package/src/elements/ShaePropElement.js.map +2 -2
- package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
- package/src/elements/ShaeWorkerElement.js +31 -6
- package/src/elements/ShaeWorkerElement.js.map +2 -2
- package/src/in-the-dark/Kernel.d.ts +5 -0
- package/src/in-the-dark/Kernel.d.ts.map +1 -1
- package/src/in-the-dark/Kernel.js +49 -24
- package/src/in-the-dark/Kernel.js.map +2 -2
- package/src/in-the-dark/Registry.d.ts +1 -1
- package/src/in-the-dark/Registry.d.ts.map +1 -1
- package/src/in-the-dark/Registry.js +24 -20
- package/src/in-the-dark/Registry.js.map +2 -2
- package/src/in-the-dark/ShadowObject.d.ts +1 -1
- package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
- package/src/in-the-dark/ShadowObject.js +2 -2
- package/src/in-the-dark/ShadowObject.js.map +2 -2
- package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
- package/src/in-the-dark/SignalsPath.js.map +2 -2
- package/src/in-the-dark/importModule.js +3 -3
- package/src/in-the-dark/importModule.js.map +2 -2
- package/src/types.d.ts +4 -4
- package/src/types.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.js +3 -2
- package/src/utils/ConsoleLogger.js.map +2 -2
- package/src/utils/FrameLoop.d.ts +1 -1
- package/src/utils/FrameLoop.d.ts.map +1 -1
- package/src/utils/FrameLoop.js +0 -2
- package/src/utils/FrameLoop.js.map +2 -2
- package/src/utils/attr-utils.d.ts.map +1 -1
- package/src/utils/attr-utils.js +1 -1
- package/src/utils/attr-utils.js.map +2 -2
- package/src/utils/generateUUID.d.ts +1 -1
- package/src/utils/generateUUID.d.ts.map +1 -1
- package/src/utils/props-utils.d.ts +1 -1
- package/src/utils/props-utils.d.ts.map +1 -1
- package/src/utils/waitForMessageOfType.d.ts +5 -1
- package/src/utils/waitForMessageOfType.d.ts.map +1 -1
- package/src/utils/waitForMessageOfType.js +12 -2
- package/src/utils/waitForMessageOfType.js.map +2 -2
- package/src/view/ComponentChanges.d.ts +4 -1
- package/src/view/ComponentChanges.d.ts.map +1 -1
- package/src/view/ComponentChanges.js +20 -6
- package/src/view/ComponentChanges.js.map +2 -2
- package/src/view/ComponentContext.d.ts +43 -1
- package/src/view/ComponentContext.d.ts.map +1 -1
- package/src/view/ComponentContext.js +123 -47
- package/src/view/ComponentContext.js.map +2 -2
- package/src/view/ComponentMemory.js +3 -1
- package/src/view/ComponentMemory.js.map +2 -2
- package/src/view/IShadowObjectEnvProxy.d.ts +6 -0
- package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.js +11 -6
- package/src/view/LocalShadowObjectEnv.js.map +2 -2
- package/src/view/RemoteWorkerEnv.d.ts +42 -0
- package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
- package/src/view/RemoteWorkerEnv.js +130 -18
- package/src/view/RemoteWorkerEnv.js.map +2 -2
- package/src/view/ShadowEnv.d.ts +25 -1
- package/src/view/ShadowEnv.d.ts.map +1 -1
- package/src/view/ShadowEnv.js +103 -29
- package/src/view/ShadowEnv.js.map +2 -2
- package/src/view/ViewComponent.d.ts +22 -1
- package/src/view/ViewComponent.d.ts.map +1 -1
- package/src/view/ViewComponent.js +66 -22
- package/src/view/ViewComponent.js.map +2 -2
- package/src/worker/MessageRouter.d.ts.map +1 -1
- package/src/worker/MessageRouter.js +7 -5
- package/src/worker/MessageRouter.js.map +2 -2
|
@@ -32,6 +32,8 @@ class Kernel {
|
|
|
32
32
|
this.logger = new ConsoleLogger("Kernel");
|
|
33
33
|
this.#entities = /* @__PURE__ */ new Map();
|
|
34
34
|
this.#rootEntities = /* @__PURE__ */ new Set();
|
|
35
|
+
this.#allEntities = [];
|
|
36
|
+
this.#allEntitiesReversed = [];
|
|
35
37
|
this.#allEntitiesNeedUpdate = true;
|
|
36
38
|
this.#rootContexts = /* @__PURE__ */ new Map();
|
|
37
39
|
eventize(this);
|
|
@@ -44,11 +46,21 @@ class Kernel {
|
|
|
44
46
|
#allEntitiesNeedUpdate;
|
|
45
47
|
#rootContexts;
|
|
46
48
|
getEntity(uuid) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
return this.#requireEntry(uuid).entity;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The entry for an entity that is expected to exist.
|
|
53
|
+
*
|
|
54
|
+
* The uuid is the caller's responsibility: `getEntity()` hands the throw on to its own
|
|
55
|
+
* callers, and `updateShadowObjects()` is reached only for an entity the caller has just
|
|
56
|
+
* confirmed. Failing here names the uuid instead of failing later on an undefined field.
|
|
57
|
+
*/
|
|
58
|
+
#requireEntry(uuid) {
|
|
59
|
+
const entry = this.#entities.get(uuid);
|
|
60
|
+
if (entry === void 0) {
|
|
49
61
|
throw new Error(`entity with uuid "${uuid}" not found!`);
|
|
50
62
|
}
|
|
51
|
-
return
|
|
63
|
+
return entry;
|
|
52
64
|
}
|
|
53
65
|
hasEntity(uuid) {
|
|
54
66
|
return this.#entities.has(uuid);
|
|
@@ -61,8 +73,9 @@ class Kernel {
|
|
|
61
73
|
const lvl = /* @__PURE__ */ new Map();
|
|
62
74
|
const traverse = (uuid, depth) => {
|
|
63
75
|
const e = this.getEntity(uuid);
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
const entities = lvl.get(depth);
|
|
77
|
+
if (entities) {
|
|
78
|
+
entities.push(e);
|
|
66
79
|
} else {
|
|
67
80
|
lvl.set(depth, [e]);
|
|
68
81
|
}
|
|
@@ -80,24 +93,28 @@ class Kernel {
|
|
|
80
93
|
return reverse ? this.#allEntitiesReversed : this.#allEntities;
|
|
81
94
|
}
|
|
82
95
|
getEntityGraph() {
|
|
83
|
-
return Array.from(this.#rootEntities).map((uuid) => this.getEntityGraphNode(uuid));
|
|
96
|
+
return Array.from(this.#rootEntities).map((uuid) => this.getEntityGraphNode(uuid)).filter((node) => node !== void 0);
|
|
84
97
|
}
|
|
85
98
|
getEntityGraphNode(uuid) {
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
const entry = this.#entities.get(uuid);
|
|
100
|
+
if (entry === void 0) return void 0;
|
|
101
|
+
const { token, entity } = entry;
|
|
88
102
|
return {
|
|
89
103
|
token,
|
|
90
104
|
entity,
|
|
91
105
|
props: Object.fromEntries(entity.propEntries()),
|
|
92
|
-
|
|
106
|
+
// A node the kernel no longer holds drops out of the graph.
|
|
107
|
+
children: entity.children.map((child) => this.getEntityGraphNode(child.uuid)).filter((node) => node !== void 0)
|
|
93
108
|
};
|
|
94
109
|
}
|
|
95
110
|
upgradeEntities() {
|
|
96
111
|
const entityConstructors = /* @__PURE__ */ new Map();
|
|
97
112
|
for (const entity of this.traverseLevelOrderBFS(true)) {
|
|
113
|
+
if (!this.hasEntity(entity.uuid)) continue;
|
|
98
114
|
entityConstructors.set(entity.uuid, this.updateShadowObjects(entity.uuid, 2 /* DestroyOnly */));
|
|
99
115
|
}
|
|
100
116
|
for (const entity of this.traverseLevelOrderBFS(false)) {
|
|
117
|
+
if (!this.hasEntity(entity.uuid)) continue;
|
|
101
118
|
this.updateShadowObjects(entity.uuid, 1 /* JustCreate */, entityConstructors.get(entity.uuid));
|
|
102
119
|
}
|
|
103
120
|
entityConstructors.clear();
|
|
@@ -163,11 +180,12 @@ class Kernel {
|
|
|
163
180
|
if (properties) {
|
|
164
181
|
e.setProperties(properties);
|
|
165
182
|
}
|
|
166
|
-
this.createShadowObjects(
|
|
183
|
+
this.createShadowObjects(entry);
|
|
167
184
|
}
|
|
168
185
|
destroyEntity(uuid) {
|
|
169
|
-
|
|
170
|
-
|
|
186
|
+
const entry = this.#entities.get(uuid);
|
|
187
|
+
if (entry === void 0) return;
|
|
188
|
+
const { entity, usedConstructors } = entry;
|
|
171
189
|
const childrenSnapshot = [...entity.children];
|
|
172
190
|
for (const child of childrenSnapshot) {
|
|
173
191
|
if (child.autoDestructionOnParentRemoval) {
|
|
@@ -184,14 +202,20 @@ class Kernel {
|
|
|
184
202
|
this.#rootEntities.delete(entity.uuid);
|
|
185
203
|
this.#allEntitiesNeedUpdate = true;
|
|
186
204
|
}
|
|
187
|
-
|
|
205
|
+
/**
|
|
206
|
+
* @param order the new order, or `undefined` to keep the current one. A set-parent change
|
|
207
|
+
* only carries an order when it actually changed, so an absent order must not be read as
|
|
208
|
+
* a reset to `0` — that would silently drop the order the view side still holds.
|
|
209
|
+
*/
|
|
210
|
+
setParent(uuid, parentUuid, order) {
|
|
188
211
|
const e = this.getEntity(uuid);
|
|
189
|
-
|
|
212
|
+
const nextOrder = order ?? e.order;
|
|
213
|
+
if (e.parentUuid === parentUuid && e.order === nextOrder) return;
|
|
190
214
|
if (parentUuid && !this.#entities.has(parentUuid)) {
|
|
191
215
|
throw new Error(`entity with uuid "${parentUuid}" not found!`);
|
|
192
216
|
}
|
|
193
217
|
e.removeFromParent();
|
|
194
|
-
e.order =
|
|
218
|
+
e.order = nextOrder;
|
|
195
219
|
e.parentUuid = parentUuid;
|
|
196
220
|
if (e.hasParent) {
|
|
197
221
|
this.#rootEntities.delete(uuid);
|
|
@@ -201,7 +225,7 @@ class Kernel {
|
|
|
201
225
|
e.reSubscribeToParentContexts();
|
|
202
226
|
queueMicrotask(() => {
|
|
203
227
|
if (this.logger.isDebug) {
|
|
204
|
-
this.logger.debug("entity.onParentChanged", { uuid, parentUuid, order, entity: e });
|
|
228
|
+
this.logger.debug("entity.onParentChanged", { uuid, parentUuid, order: nextOrder, entity: e });
|
|
205
229
|
}
|
|
206
230
|
emit(e, onParentChanged, e);
|
|
207
231
|
});
|
|
@@ -217,8 +241,8 @@ class Kernel {
|
|
|
217
241
|
this.updateShadowObjects(uuid);
|
|
218
242
|
}
|
|
219
243
|
changeToken(uuid, token) {
|
|
220
|
-
if (!this.#entities.has(uuid)) return;
|
|
221
244
|
const entry = this.#entities.get(uuid);
|
|
245
|
+
if (entry === void 0) return;
|
|
222
246
|
if (entry.token === token) return;
|
|
223
247
|
entry.token = token;
|
|
224
248
|
this.updateShadowObjects(uuid);
|
|
@@ -233,7 +257,7 @@ class Kernel {
|
|
|
233
257
|
* After a token change or registry changes, an entity may be given different shadow-objects.
|
|
234
258
|
*/
|
|
235
259
|
updateShadowObjects(uuid, action = 0 /* CreateAndDestroy */, nextConstructors) {
|
|
236
|
-
const entry = this.#
|
|
260
|
+
const entry = this.#requireEntry(uuid);
|
|
237
261
|
nextConstructors ??= new Set(this.registry.findConstructors(entry.token, entry.entity.truthyProps()));
|
|
238
262
|
const shouldDestroy = action === 0 /* CreateAndDestroy */ || action === 2 /* DestroyOnly */;
|
|
239
263
|
const shouldCreate = action === 0 /* CreateAndDestroy */ || action === 1 /* JustCreate */;
|
|
@@ -536,23 +560,24 @@ class Kernel {
|
|
|
536
560
|
}
|
|
537
561
|
}
|
|
538
562
|
});
|
|
539
|
-
|
|
540
|
-
|
|
563
|
+
const createdBy = entry.usedConstructors.get(construct);
|
|
564
|
+
if (createdBy) {
|
|
565
|
+
createdBy.add(shadowObject);
|
|
541
566
|
} else {
|
|
542
567
|
entry.usedConstructors.set(construct, /* @__PURE__ */ new Set([shadowObject]));
|
|
543
568
|
}
|
|
544
569
|
this.attachShadowObject(shadowObject, entry.entity);
|
|
545
570
|
return shadowObject;
|
|
546
571
|
}
|
|
547
|
-
createShadowObjects(
|
|
548
|
-
const entry = this.#entities.get(uuid);
|
|
572
|
+
createShadowObjects(entry) {
|
|
549
573
|
this.registry.findConstructors(entry.token, entry.entity.truthyProps())?.forEach((construct) => {
|
|
550
574
|
this.constructShadowObject(construct, entry);
|
|
551
575
|
});
|
|
552
576
|
}
|
|
553
577
|
findShadowObjects(uuid) {
|
|
554
|
-
|
|
555
|
-
|
|
578
|
+
const entry = this.#entities.get(uuid);
|
|
579
|
+
if (entry === void 0) return [];
|
|
580
|
+
const { usedConstructors } = entry;
|
|
556
581
|
return Array.from(new Set(Array.from(usedConstructors.values()).flatMap((objs) => Array.from(objs))));
|
|
557
582
|
}
|
|
558
583
|
attachShadowObject(shadowObject, entity) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/in-the-dark/Kernel.ts"],
|
|
4
|
-
"sourcesContent": ["import {emit, eventize, off, on, once, Priority} from '@spearwolf/eventize';\nimport {\n batch,\n type CompareFunc,\n createEffect,\n createMemo,\n createSignal,\n destroySignal,\n isSignal,\n link,\n type Signal,\n type SignalReader,\n} from '@spearwolf/signalize';\nimport {ComponentChangeType, MessageToView} from '../constants.js';\nimport type {\n IComponentChangeType,\n IComponentEvent,\n Maybe,\n ProvideContextOptions,\n ShadowObjectConstructor,\n ShadowObjectType,\n SignalValueOptions,\n SyncEvent,\n} from '../types.js';\nimport {ConsoleLogger} from '../utils/ConsoleLogger.js';\nimport {toMaybe} from '../utils/toMaybe.js';\nimport {Entity} from './Entity.js';\nimport {type OnCreate, type OnDestroy, onCreate, onDestroy, onParentChanged, onViewEvent} from './events.js';\nimport {Registry} from './Registry.js';\nimport {SignalsPath} from './SignalsPath.js';\n\nexport interface MessageToViewEvent {\n uuid: string;\n type: string;\n data?: unknown;\n transferables?: Transferable[];\n traverseChildren?: boolean;\n}\n\ninterface EntityEntry {\n token: string;\n entity: Entity;\n usedConstructors: Map<ShadowObjectConstructor, Set<ShadowObjectType>>;\n}\n\ninterface EntityGraphNode {\n token: string;\n entity: Entity;\n props: Record<string, unknown>;\n children: EntityGraphNode[];\n}\n\nenum ShadowObjectAction {\n CreateAndDestroy = 0,\n JustCreate,\n DestroyOnly,\n}\n\nconst getDisplayName = (construct: ShadowObjectConstructor) => construct.displayName || construct.name;\n\nlet provideContextOptionsDeprecatedShown = false;\nlet provideGlobalContextOptionsDeprecatedShown = false;\nlet useContextOptionsDeprecatedShown = false;\nlet useParentContextOptionsDeprecatedShown = false;\nlet usePropertyOptionsDeprecatedShown = false;\n\n/**\n * The entity kernel manages the lifecycle of all entities and shadow-objects.\n *\n * An entity is created for each view-component. The entities act as containers for the shadow-objects.\n *\n * Which shadow-objects are created is determined by the token.\n */\nexport class Kernel {\n registry: Registry;\n\n readonly logger = new ConsoleLogger('Kernel');\n\n #entities: Map<string, EntityEntry> = new Map();\n #rootEntities: Set<string> = new Set();\n\n #allEntities?: Entity[];\n #allEntitiesReversed?: Entity[];\n #allEntitiesNeedUpdate = true;\n\n #rootContexts: Map<string | symbol, SignalsPath> = new Map();\n\n constructor(registry?: Registry) {\n eventize(this);\n this.registry = Registry.get(registry);\n }\n\n getEntity(uuid: string): Entity {\n const entity = this.#entities.get(uuid)?.entity;\n if (!entity) {\n throw new Error(`entity with uuid \"${uuid}\" not found!`);\n }\n return entity;\n }\n\n hasEntity(uuid: string): boolean {\n return this.#entities.has(uuid);\n }\n\n /**\n * @returns all entities in breadth-first order\n */\n traverseLevelOrderBFS(reverse = false): Entity[] {\n if (this.#allEntitiesNeedUpdate) {\n const lvl = new Map<number, Entity[]>();\n\n const traverse = (uuid: string, depth: number) => {\n const e = this.getEntity(uuid);\n\n if (lvl.has(depth)) {\n lvl.get(depth).push(e);\n } else {\n lvl.set(depth, [e]);\n }\n\n for (const child of e.children) {\n traverse(child.uuid, depth + 1);\n }\n };\n\n this.#rootEntities.forEach((uuid) => {\n traverse(uuid, 0);\n });\n\n this.#allEntities = Array.from(lvl.entries())\n .sort((a, b) => a[0] - b[0])\n .flatMap(([, entities]) => entities);\n\n this.#allEntitiesReversed = this.#allEntities.slice().reverse();\n this.#allEntitiesNeedUpdate = false;\n }\n\n return reverse ? this.#allEntitiesReversed : this.#allEntities;\n }\n\n getEntityGraph(): EntityGraphNode[] {\n return Array.from(this.#rootEntities).map((uuid) => this.getEntityGraphNode(uuid)!);\n }\n\n private getEntityGraphNode(uuid: string): EntityGraphNode | undefined {\n if (!this.#entities.has(uuid)) return undefined;\n\n const {token, entity} = this.#entities.get(uuid);\n return {\n token,\n entity,\n props: Object.fromEntries(entity.propEntries()),\n children: entity.children.map((child) => this.getEntityGraphNode(child.uuid)),\n };\n }\n\n upgradeEntities(): void {\n const entityConstructors = new Map<String, Set<ShadowObjectConstructor>>();\n\n for (const entity of this.traverseLevelOrderBFS(true)) {\n entityConstructors.set(entity.uuid, this.updateShadowObjects(entity.uuid, ShadowObjectAction.DestroyOnly));\n }\n\n for (const entity of this.traverseLevelOrderBFS(false)) {\n this.updateShadowObjects(entity.uuid, ShadowObjectAction.JustCreate, entityConstructors.get(entity.uuid));\n }\n\n entityConstructors.clear();\n }\n\n run(event: SyncEvent): void {\n if (this.logger.isDebug) {\n this.logger.debug('sync', event);\n }\n batch(() => {\n for (const entry of event.changeTrail) {\n this.parse(entry);\n }\n });\n }\n\n private parse(entry: IComponentChangeType): void {\n switch (entry.type) {\n case ComponentChangeType.CreateEntities:\n this.createEntity(\n entry.uuid,\n entry.token,\n entry.parentUuid,\n entry.order,\n entry.properties,\n entry.autoDestructionOnParentRemoval,\n );\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.DestroyEntities:\n this.destroyEntity(entry.uuid);\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.SetParent:\n this.setParent(entry.uuid, entry.parentUuid, entry.order);\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.UpdateOrder:\n this.updateOrder(entry.uuid, entry.order);\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.ChangeProperties:\n this.changeProperties(entry.uuid, entry.properties);\n break;\n\n case ComponentChangeType.ChangeToken:\n this.changeToken(entry.uuid, entry.token);\n break;\n\n case ComponentChangeType.SendEvents:\n this.dispatchEventsToEntity(entry.uuid, entry.events);\n break;\n }\n }\n\n createEntity(\n uuid: string,\n token: string,\n parentUuid?: string,\n order = 0,\n properties?: [string, unknown][],\n autoDestructionOnParentRemoval = false,\n ): void {\n const e = new Entity(this, uuid);\n\n e.order = order;\n\n const entry: EntityEntry = {token, entity: e, usedConstructors: new Map()};\n\n this.#entities.set(uuid, entry);\n\n if (parentUuid) {\n e.parentUuid = parentUuid;\n }\n\n e.autoDestructionOnParentRemoval = autoDestructionOnParentRemoval;\n\n if (!e.hasParent) {\n this.#rootEntities.add(uuid);\n }\n\n if (properties) {\n e.setProperties(properties);\n }\n\n this.createShadowObjects(uuid);\n }\n\n destroyEntity(uuid: string): void {\n if (!this.#entities.has(uuid)) return;\n\n const {entity, usedConstructors} = this.#entities.get(uuid);\n\n // Children with autoDestructionOnParentRemoval cascade; the rest are promoted\n // to root so they remain reachable instead of leaking inside the kernel.\n // Snapshot first because both branches mutate the children list.\n const childrenSnapshot = [...entity.children];\n for (const child of childrenSnapshot) {\n if (child.autoDestructionOnParentRemoval) {\n this.destroyEntity(child.uuid);\n } else {\n child.removeFromParent();\n this.#rootEntities.add(child.uuid);\n }\n }\n\n entity.removeFromParent();\n emit(entity, onDestroy, entity);\n\n usedConstructors.clear();\n\n this.#entities.delete(entity.uuid);\n this.#rootEntities.delete(entity.uuid);\n this.#allEntitiesNeedUpdate = true;\n }\n\n setParent(uuid: string, parentUuid?: string, order = 0): void {\n const e = this.getEntity(uuid);\n\n if (e.parentUuid === parentUuid && e.order === order) return;\n\n // Validate the new parent before detaching the current one, so a bad UUID\n // never leaves the entity orphaned (KERN-5).\n if (parentUuid && !this.#entities.has(parentUuid)) {\n throw new Error(`entity with uuid \"${parentUuid}\" not found!`);\n }\n\n e.removeFromParent();\n\n e.order = order;\n e.parentUuid = parentUuid;\n\n if (e.hasParent) {\n this.#rootEntities.delete(uuid);\n } else {\n this.#rootEntities.add(uuid);\n }\n\n e.reSubscribeToParentContexts();\n\n queueMicrotask(() => {\n if (this.logger.isDebug) {\n this.logger.debug('entity.onParentChanged', {uuid, parentUuid, order, entity: e});\n }\n emit(e, onParentChanged, e);\n });\n }\n\n updateOrder(uuid: string, order: number): void {\n this.getEntity(uuid).order = order;\n }\n\n dispatchEventsToEntity(uuid: string, events: IComponentEvent[]): void {\n this.getEntity(uuid)?.dispatchViewEvents(events);\n }\n\n changeProperties(uuid: string, properties: [string, unknown][]): void {\n this.getEntity(uuid).setProperties(properties);\n this.updateShadowObjects(uuid);\n }\n\n changeToken(uuid: string, token: string): void {\n if (!this.#entities.has(uuid)) return;\n\n const entry = this.#entities.get(uuid);\n\n if (entry.token === token) return;\n\n entry.token = token;\n\n this.updateShadowObjects(uuid);\n }\n\n dispatchMessageToView(message: MessageToViewEvent): void {\n queueMicrotask(() => {\n emit(this as Kernel, MessageToView, message);\n });\n }\n\n /**\n * Create or destroy the shadow-objects of an entity using the registered constructors.\n * After a token change or registry changes, an entity may be given different shadow-objects.\n */\n private updateShadowObjects(\n uuid: string,\n action = ShadowObjectAction.CreateAndDestroy,\n nextConstructors?: Set<ShadowObjectConstructor>,\n ): Set<ShadowObjectConstructor> {\n const entry = this.#entities.get(uuid);\n nextConstructors ??= new Set(this.registry.findConstructors(entry.token, entry.entity.truthyProps()));\n\n const shouldDestroy = action === ShadowObjectAction.CreateAndDestroy || action === ShadowObjectAction.DestroyOnly;\n const shouldCreate = action === ShadowObjectAction.CreateAndDestroy || action === ShadowObjectAction.JustCreate;\n\n // destroy all shadow-objects created by constructors no longer in the list\n //\n if (shouldDestroy) {\n for (const [construct, shadowObjects] of entry.usedConstructors) {\n if (!nextConstructors.has(construct)) {\n entry.usedConstructors.delete(construct);\n for (const obj of shadowObjects) {\n this.destroyShadowObject(obj, entry.entity);\n }\n }\n }\n }\n\n // shadow-objects for new constructors are now created using the updated constructor list\n //\n if (shouldCreate) {\n for (const construct of nextConstructors) {\n if (!entry.usedConstructors.has(construct)) {\n this.constructShadowObject(construct, entry);\n }\n }\n }\n\n return nextConstructors;\n }\n\n private constructShadowObject(construct: ShadowObjectConstructor, entry: EntityEntry): ShadowObjectType {\n const unsubscribePrimary = new Set<() => any>();\n const unsubscribeSecondary = new Set<() => any>();\n\n const contextReaders = new Map<string | symbol, SignalReader<any>>();\n const contextReaderCompares = new Map<string | symbol, CompareFunc<any> | undefined>();\n const contextParentReaders = new Map<string | symbol, SignalReader<any>>();\n const contextParentReaderCompares = new Map<string | symbol, CompareFunc<any> | undefined>();\n const contextProviders = new Map<string | symbol, Signal<any>>();\n const contextRootProviders = new Map<string | symbol, Signal<any>>();\n\n const propertyReaders = new Map<string, SignalReader<any>>();\n const propertyCompares = new Map<string, CompareFunc<any> | undefined>();\n\n const getUseProperty = <T = any>(\n name: string,\n options?: SignalValueOptions<T> | CompareFunc<T | undefined>,\n ): SignalReader<T> => {\n if (!usePropertyOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"useProperty()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n usePropertyOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let propReader = propertyReaders.get(name);\n\n if (propReader === undefined) {\n propReader = createSignal<any>(undefined, opts).get;\n propertyReaders.set(name, propReader);\n propertyCompares.set(name, opts?.compare);\n const con = link(entry.entity.getPropertyReader(name), propReader);\n unsubscribeSecondary.add(con.destroy.bind(con));\n } else if (opts?.compare != null && propertyCompares.get(name) !== opts.compare) {\n console.warn(\n `[shadow-objects] useProperty(\"${name}\"): 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.`,\n );\n }\n\n return propReader;\n };\n\n const shadowObject = eventize(\n new construct({\n entity: entry.entity,\n\n provideContext<T = unknown>(\n name: string | symbol,\n sourceOrInitialValue?: T | SignalReader<T | undefined>,\n options?: ProvideContextOptions<T> | CompareFunc<T | undefined>,\n ) {\n if (!provideContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"provideContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n provideContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxProvider = contextProviders.get(name);\n\n if (ctxProvider == null) {\n const isSig = isSignal(sourceOrInitialValue);\n const initialValue = isSig ? undefined : toMaybe(sourceOrInitialValue as T);\n\n ctxProvider = createSignal(initialValue, opts?.compare ? {compare: opts.compare} : undefined);\n\n if (isSig) {\n const ln = link(sourceOrInitialValue as SignalReader<T>, ctxProvider);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n }\n\n const ln = link(ctxProvider, entry.entity.provideContext(name));\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n contextProviders.set(name, ctxProvider);\n }\n\n if (ctxProvider != null && (opts?.clearOnDestroy ?? true)) {\n unsubscribeSecondary.add(() => {\n ctxProvider.set(undefined);\n });\n }\n\n return ctxProvider;\n },\n\n provideGlobalContext<T = unknown>(\n name: string | symbol,\n sourceOrInitialValue?: T | SignalReader<T | undefined>,\n options?: ProvideContextOptions<T> | CompareFunc<T | undefined>,\n ) {\n if (!provideGlobalContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"provideGlobalContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n provideGlobalContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxProvider = contextRootProviders.get(name);\n\n if (ctxProvider == null) {\n const isSig = isSignal(sourceOrInitialValue);\n const initialValue = isSig ? undefined : toMaybe(sourceOrInitialValue as T);\n\n ctxProvider = createSignal(initialValue, opts?.compare ? {compare: opts.compare} : undefined);\n\n if (isSig) {\n const ln = link(sourceOrInitialValue as SignalReader<T>, ctxProvider);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n }\n\n const ln = link(ctxProvider, entry.entity.provideGlobalContext(name));\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n contextRootProviders.set(name, ctxProvider);\n }\n\n if (ctxProvider != null && (opts?.clearOnDestroy ?? true)) {\n unsubscribeSecondary.add(() => {\n ctxProvider.set(undefined);\n });\n }\n\n return ctxProvider;\n },\n\n useContext<T = unknown>(name: string | symbol, options?: SignalValueOptions<T> | CompareFunc<T | undefined>) {\n if (!useContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"useContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n useContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxReader = contextReaders.get(name);\n\n if (ctxReader === undefined) {\n ctxReader = createSignal<any>(undefined, opts).get;\n contextReaders.set(name, ctxReader);\n contextReaderCompares.set(name, opts?.compare);\n const ln = link(entry.entity.useContext(name), ctxReader);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n } else if (opts?.compare != null && contextReaderCompares.get(name) !== opts.compare) {\n console.warn(\n `[shadow-objects] useContext(\"${String(name)}\"): 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.`,\n );\n }\n\n return ctxReader;\n },\n\n useParentContext<T = unknown>(name: string | symbol, options?: SignalValueOptions<T> | CompareFunc<T | undefined>) {\n if (!useParentContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"useParentContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n useParentContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxReader = contextParentReaders.get(name);\n\n if (ctxReader === undefined) {\n ctxReader = createSignal<any>(undefined, opts).get;\n contextParentReaders.set(name, ctxReader);\n contextParentReaderCompares.set(name, opts?.compare);\n const ln = link(entry.entity.useParentContext(name), ctxReader);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n } else if (opts?.compare != null && contextParentReaderCompares.get(name) !== opts.compare) {\n console.warn(\n `[shadow-objects] useParentContext(\"${String(name)}\"): 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.`,\n );\n }\n\n return ctxReader;\n },\n\n dispatchMessageToView(type: string, data?: unknown, transferables?: Transferable[], traverseChildren = false) {\n entry.entity.dispatchMessageToView(type, data, transferables, traverseChildren);\n },\n\n useProperty: getUseProperty,\n\n useProperties<T extends Record<string, unknown> = Record<string, unknown>>(\n props: {[K in keyof T]: string},\n ): {\n [K in keyof T]: SignalReader<Maybe<T[K]>>;\n } {\n const result = {} as {[K in keyof T]: SignalReader<Maybe<T[K]>>};\n for (const key in props) {\n if (Object.hasOwn(props, key)) {\n result[key] = getUseProperty(props[key]);\n }\n }\n return result;\n },\n\n createResource<T = unknown>(\n factory: () => T | undefined,\n cleanup?: (resource: NonNullable<T>) => unknown,\n ): Signal<Maybe<T>> {\n const resourceSignal = createSignal<Maybe<T>>();\n\n const effect = createEffect(() => {\n const resource = toMaybe(factory());\n resourceSignal.set(resource);\n\n if (resource !== undefined && cleanup) {\n return () => {\n cleanup(resource);\n resourceSignal.set(undefined);\n };\n }\n\n return () => {\n resourceSignal.set(undefined);\n };\n });\n\n unsubscribeSecondary.add(() => {\n effect.destroy();\n resourceSignal.set(undefined);\n destroySignal(resourceSignal);\n });\n\n return resourceSignal;\n },\n\n createEffect(...args: Parameters<typeof createEffect>): ReturnType<typeof createEffect> {\n const effect = createEffect(...args);\n unsubscribeSecondary.add(effect.destroy);\n return effect;\n },\n\n createSignal<T = unknown>(...args: Parameters<typeof createSignal<T>>): ReturnType<typeof createSignal<T>> {\n const sig = createSignal<T>(...args);\n unsubscribeSecondary.add(() => {\n destroySignal(sig);\n });\n return sig;\n },\n\n createMemo<T = unknown>(...args: Parameters<typeof createMemo<T>>): SignalReader<T> {\n const sig = createMemo<T>(...args);\n unsubscribeSecondary.add(() => {\n destroySignal(sig);\n });\n return sig;\n },\n\n on(...args: any[]): ReturnType<typeof on> {\n const [firstArg] = args;\n if (typeof firstArg === 'string' || typeof firstArg === 'symbol' || Array.isArray(firstArg)) {\n // @ts-ignore\n const unsub = on(entry.entity, ...args);\n unsubscribeSecondary.add(unsub);\n return unsub;\n }\n // @ts-ignore\n const unsub = on(...args);\n unsubscribeSecondary.add(unsub);\n // return unsub;\n return Object.assign(() => {\n unsubscribeSecondary.delete(unsub);\n unsub();\n }, unsub);\n },\n\n once(...args: any[]): ReturnType<typeof once> {\n const [firstArg] = args;\n if (typeof firstArg === 'string' || typeof firstArg === 'symbol' || Array.isArray(firstArg)) {\n // @ts-ignore\n const unsub = once(entry.entity, ...args);\n unsubscribeSecondary.add(unsub);\n return unsub;\n }\n // @ts-ignore\n const unsub = once(...args);\n unsubscribeSecondary.add(unsub);\n // return unsub;\n return Object.assign(() => {\n unsubscribeSecondary.delete(unsub);\n unsub();\n }, unsub);\n },\n\n emit(...args: any[]): void {\n const [firstArg] = args;\n if (typeof firstArg === 'string' || typeof firstArg === 'symbol' || Array.isArray(firstArg)) {\n // @ts-ignore\n emit(entry.entity, ...args);\n } else {\n // @ts-ignore\n emit(...args);\n }\n },\n\n onViewEvent(callback: (type: string, data: unknown) => any) {\n const unsub = on(entry.entity, onViewEvent, (type: string, data: unknown) => {\n callback(type, data);\n });\n unsubscribeSecondary.add(unsub);\n },\n\n onDestroy(callback: () => any) {\n unsubscribePrimary.add(callback);\n },\n }),\n );\n\n if (this.logger.isInfo) {\n this.logger.info('create shadow-object', getDisplayName(construct), {shadowObject, entity: entry.entity});\n }\n\n once(entry.entity, onDestroy, Priority.Low, () => {\n if (this.logger.isInfo) {\n this.logger.info('destroy shadow-object', getDisplayName(construct), {shadowObject, entity: entry.entity});\n }\n\n for (const callback of unsubscribePrimary) {\n callback();\n }\n\n for (const callback of unsubscribeSecondary) {\n callback();\n }\n\n for (const sig of contextReaders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of contextParentReaders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of propertyReaders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of contextProviders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of contextRootProviders.values()) {\n destroySignal(sig);\n }\n\n unsubscribePrimary.clear();\n unsubscribeSecondary.clear();\n contextReaders.clear();\n contextParentReaders.clear();\n propertyReaders.clear();\n contextProviders.clear();\n contextRootProviders.clear();\n\n const otherShadowObjects = entry.usedConstructors.get(construct);\n if (otherShadowObjects) {\n otherShadowObjects.delete(shadowObject);\n if (otherShadowObjects.size === 0) {\n entry.usedConstructors.delete(construct);\n }\n }\n });\n\n // We want to keep track which shadow-objects are created by which constructors.\n // This will all\n //\n if (entry.usedConstructors.has(construct)) {\n entry.usedConstructors.get(construct).add(shadowObject);\n } else {\n entry.usedConstructors.set(construct, new Set([shadowObject]));\n }\n\n this.attachShadowObject(shadowObject, entry.entity);\n\n return shadowObject;\n }\n\n private createShadowObjects(uuid: string): void {\n const entry = this.#entities.get(uuid);\n\n this.registry.findConstructors(entry.token, entry.entity.truthyProps())?.forEach((construct) => {\n this.constructShadowObject(construct, entry);\n });\n }\n\n findShadowObjects(uuid: string): ShadowObjectType[] {\n if (!this.#entities.has(uuid)) return [];\n\n const {usedConstructors} = this.#entities.get(uuid);\n\n return Array.from(new Set(Array.from(usedConstructors.values()).flatMap((objs) => Array.from(objs))));\n }\n\n private attachShadowObject(shadowObject: object, entity: Entity): void {\n // Like all other objects, the new shadow-object should be able to respond to the events that the entity receives.\n //\n on(entity, shadowObject);\n\n // Finally, the `shadowObject.onCreate(entity)` callback is called on the shadow-object.\n //\n if (typeof (shadowObject as any)[onCreate] === 'function') {\n (shadowObject as OnCreate)[onCreate](entity);\n }\n }\n\n private destroyShadowObject(shadowObject: object, entity: Entity): void {\n if (typeof (shadowObject as any)[onDestroy] === 'function') {\n (shadowObject as OnDestroy)[onDestroy](entity);\n }\n\n emit(shadowObject, onDestroy, entity);\n\n off(entity, shadowObject);\n }\n\n findOrCreateRootContext(name: string | symbol): SignalsPath {\n let ctx = this.#rootContexts.get(name);\n if (!ctx) {\n ctx = new SignalsPath();\n this.#rootContexts.set(name, ctx);\n }\n return ctx;\n }\n\n destroy(): void {\n for (const ctx of this.#rootContexts.values()) {\n ctx.dispose();\n }\n this.#rootContexts.clear();\n\n for (const entity of this.traverseLevelOrderBFS().reverse()) {\n this.destroyEntity(entity.uuid);\n }\n }\n}"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,MAAM,UAAU,KAAK,IAAI,MAAM,gBAAe;AACtD;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAQ,qBAAqB,qBAAoB;AAWjD,SAAQ,qBAAoB;AAC5B,SAAQ,eAAc;AACtB,SAAQ,cAAa;AACrB,SAAuC,UAAU,WAAW,iBAAiB,mBAAkB;AAC/F,SAAQ,gBAAe;AACvB,SAAQ,mBAAkB;AAuB1B,IAAK,qBAAL,kBAAKA,wBAAL;AACE,EAAAA,wCAAA,sBAAmB,KAAnB;AACA,EAAAA,wCAAA;AACA,EAAAA,wCAAA;AAHG,SAAAA;AAAA,GAAA;AAML,MAAM,iBAAiB,CAAC,cAAuC,UAAU,eAAe,UAAU;AAElG,IAAI,uCAAuC;AAC3C,IAAI,6CAA6C;AACjD,IAAI,mCAAmC;AACvC,IAAI,yCAAyC;AAC7C,IAAI,oCAAoC;AASjC,MAAM,OAAO;AAAA,EAclB,YAAY,UAAqB;AAXjC,SAAS,SAAS,IAAI,cAAc,QAAQ;AAE5C,qBAAsC,oBAAI,IAAI;AAC9C,yBAA6B,oBAAI,IAAI;AAIrC,kCA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AsB,QAAsB;AAGrE,OAAG,QAAQ,YAAY;AAIvB,QAAI,OAAQ,aAAqB,QAAQ,MAAM,YAAY;AACzD,MAAC,aAA0B,QAAQ,EAAE,MAAM;AAAA,IAC7C;AAAA,EACF;AAAA,EAEQ,oBAAoB,cAAsB,QAAsB;AACtE,QAAI,OAAQ,aAAqB,SAAS,MAAM,YAAY;AAC1D,MAAC,aAA2B,SAAS,EAAE,MAAM;AAAA,IAC/C;AAEA,SAAK,cAAc,WAAW,MAAM;AAEpC,QAAI,QAAQ,YAAY;AAAA,EAC1B;AAAA,EAEA,wBAAwB,MAAoC;AAC1D,QAAI,MAAM,KAAK,cAAc,IAAI,IAAI;AACrC,QAAI,CAAC,KAAK;AACR,YAAM,IAAI,YAAY;AACtB,WAAK,cAAc,IAAI,MAAM,GAAG;AAAA,IAClC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,UAAgB;AACd,eAAW,OAAO,KAAK,cAAc,OAAO,GAAG;AAC7C,UAAI,QAAQ;AAAA,IACd;AACA,SAAK,cAAc,MAAM;AAEzB,eAAW,UAAU,KAAK,sBAAsB,EAAE,QAAQ,GAAG;AAC3D,WAAK,cAAc,OAAO,IAAI;AAAA,IAChC;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import {emit, eventize, off, on, once, Priority} from '@spearwolf/eventize';\nimport {\n batch,\n type CompareFunc,\n createEffect,\n createMemo,\n createSignal,\n destroySignal,\n isSignal,\n link,\n type Signal,\n type SignalReader,\n} from '@spearwolf/signalize';\nimport {ComponentChangeType, MessageToView} from '../constants.js';\nimport type {\n IComponentChangeType,\n IComponentEvent,\n Maybe,\n ProvideContextOptions,\n ShadowObjectConstructor,\n ShadowObjectType,\n SignalValueOptions,\n SyncEvent,\n} from '../types.js';\nimport {ConsoleLogger} from '../utils/ConsoleLogger.js';\nimport {toMaybe} from '../utils/toMaybe.js';\nimport {Entity} from './Entity.js';\nimport {type OnCreate, type OnDestroy, onCreate, onDestroy, onParentChanged, onViewEvent} from './events.js';\nimport {Registry} from './Registry.js';\nimport {SignalsPath} from './SignalsPath.js';\n\nexport interface MessageToViewEvent {\n uuid: string;\n type: string;\n data?: unknown;\n transferables?: Transferable[];\n traverseChildren?: boolean;\n}\n\ninterface EntityEntry {\n token: string;\n entity: Entity;\n usedConstructors: Map<ShadowObjectConstructor, Set<ShadowObjectType>>;\n}\n\ninterface EntityGraphNode {\n token: string;\n entity: Entity;\n props: Record<string, unknown>;\n children: EntityGraphNode[];\n}\n\nenum ShadowObjectAction {\n CreateAndDestroy = 0,\n JustCreate,\n DestroyOnly,\n}\n\nconst getDisplayName = (construct: ShadowObjectConstructor) => construct.displayName || construct.name;\n\nlet provideContextOptionsDeprecatedShown = false;\nlet provideGlobalContextOptionsDeprecatedShown = false;\nlet useContextOptionsDeprecatedShown = false;\nlet useParentContextOptionsDeprecatedShown = false;\nlet usePropertyOptionsDeprecatedShown = false;\n\n/**\n * The entity kernel manages the lifecycle of all entities and shadow-objects.\n *\n * An entity is created for each view-component. The entities act as containers for the shadow-objects.\n *\n * Which shadow-objects are created is determined by the token.\n */\nexport class Kernel {\n registry: Registry;\n\n readonly logger = new ConsoleLogger('Kernel');\n\n #entities: Map<string, EntityEntry> = new Map();\n #rootEntities: Set<string> = new Set();\n\n #allEntities: Entity[] = [];\n #allEntitiesReversed: Entity[] = [];\n #allEntitiesNeedUpdate = true;\n\n #rootContexts: Map<string | symbol, SignalsPath> = new Map();\n\n constructor(registry?: Registry) {\n eventize(this);\n this.registry = Registry.get(registry);\n }\n\n getEntity(uuid: string): Entity {\n return this.#requireEntry(uuid).entity;\n }\n\n /**\n * The entry for an entity that is expected to exist.\n *\n * The uuid is the caller's responsibility: `getEntity()` hands the throw on to its own\n * callers, and `updateShadowObjects()` is reached only for an entity the caller has just\n * confirmed. Failing here names the uuid instead of failing later on an undefined field.\n */\n #requireEntry(uuid: string): EntityEntry {\n const entry = this.#entities.get(uuid);\n if (entry === undefined) {\n throw new Error(`entity with uuid \"${uuid}\" not found!`);\n }\n return entry;\n }\n\n hasEntity(uuid: string): boolean {\n return this.#entities.has(uuid);\n }\n\n /**\n * @returns all entities in breadth-first order\n */\n traverseLevelOrderBFS(reverse = false): Entity[] {\n if (this.#allEntitiesNeedUpdate) {\n const lvl = new Map<number, Entity[]>();\n\n const traverse = (uuid: string, depth: number) => {\n const e = this.getEntity(uuid);\n\n const entities = lvl.get(depth);\n if (entities) {\n entities.push(e);\n } else {\n lvl.set(depth, [e]);\n }\n\n for (const child of e.children) {\n traverse(child.uuid, depth + 1);\n }\n };\n\n this.#rootEntities.forEach((uuid) => {\n traverse(uuid, 0);\n });\n\n this.#allEntities = Array.from(lvl.entries())\n .sort((a, b) => a[0] - b[0])\n .flatMap(([, entities]) => entities);\n\n this.#allEntitiesReversed = this.#allEntities.slice().reverse();\n this.#allEntitiesNeedUpdate = false;\n }\n\n return reverse ? this.#allEntitiesReversed : this.#allEntities;\n }\n\n getEntityGraph(): EntityGraphNode[] {\n return Array.from(this.#rootEntities)\n .map((uuid) => this.getEntityGraphNode(uuid))\n .filter((node) => node !== undefined);\n }\n\n private getEntityGraphNode(uuid: string): EntityGraphNode | undefined {\n const entry = this.#entities.get(uuid);\n if (entry === undefined) return undefined;\n\n const {token, entity} = entry;\n return {\n token,\n entity,\n props: Object.fromEntries(entity.propEntries()),\n // A node the kernel no longer holds drops out of the graph.\n children: entity.children.map((child) => this.getEntityGraphNode(child.uuid)).filter((node) => node !== undefined),\n };\n }\n\n upgradeEntities(): void {\n const entityConstructors = new Map<String, Set<ShadowObjectConstructor>>();\n\n // Both loops walk a snapshot of the entity tree, and a lifecycle callback is free to destroy\n // an entity while the upgrade is running. An entry from the snapshot can therefore be gone by\n // the time its turn comes: it needs no upgrade, and the entities behind it still do.\n for (const entity of this.traverseLevelOrderBFS(true)) {\n if (!this.hasEntity(entity.uuid)) continue;\n entityConstructors.set(entity.uuid, this.updateShadowObjects(entity.uuid, ShadowObjectAction.DestroyOnly));\n }\n\n for (const entity of this.traverseLevelOrderBFS(false)) {\n if (!this.hasEntity(entity.uuid)) continue;\n this.updateShadowObjects(entity.uuid, ShadowObjectAction.JustCreate, entityConstructors.get(entity.uuid));\n }\n\n entityConstructors.clear();\n }\n\n run(event: SyncEvent): void {\n if (this.logger.isDebug) {\n this.logger.debug('sync', event);\n }\n batch(() => {\n for (const entry of event.changeTrail) {\n this.parse(entry);\n }\n });\n }\n\n private parse(entry: IComponentChangeType): void {\n switch (entry.type) {\n case ComponentChangeType.CreateEntities:\n this.createEntity(\n entry.uuid,\n entry.token,\n entry.parentUuid,\n entry.order,\n entry.properties,\n entry.autoDestructionOnParentRemoval,\n );\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.DestroyEntities:\n this.destroyEntity(entry.uuid);\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.SetParent:\n this.setParent(entry.uuid, entry.parentUuid, entry.order);\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.UpdateOrder:\n this.updateOrder(entry.uuid, entry.order);\n this.#allEntitiesNeedUpdate = true;\n break;\n\n case ComponentChangeType.ChangeProperties:\n this.changeProperties(entry.uuid, entry.properties);\n break;\n\n case ComponentChangeType.ChangeToken:\n this.changeToken(entry.uuid, entry.token);\n break;\n\n case ComponentChangeType.SendEvents:\n this.dispatchEventsToEntity(entry.uuid, entry.events);\n break;\n }\n }\n\n createEntity(\n uuid: string,\n token: string,\n parentUuid?: string,\n order = 0,\n properties?: [string, unknown][],\n autoDestructionOnParentRemoval = false,\n ): void {\n const e = new Entity(this, uuid);\n\n e.order = order;\n\n const entry: EntityEntry = {token, entity: e, usedConstructors: new Map()};\n\n this.#entities.set(uuid, entry);\n\n if (parentUuid) {\n e.parentUuid = parentUuid;\n }\n\n e.autoDestructionOnParentRemoval = autoDestructionOnParentRemoval;\n\n if (!e.hasParent) {\n this.#rootEntities.add(uuid);\n }\n\n if (properties) {\n e.setProperties(properties);\n }\n\n this.createShadowObjects(entry);\n }\n\n destroyEntity(uuid: string): void {\n const entry = this.#entities.get(uuid);\n if (entry === undefined) return;\n\n const {entity, usedConstructors} = entry;\n\n // Children with autoDestructionOnParentRemoval cascade; the rest are promoted\n // to root so they remain reachable instead of leaking inside the kernel.\n // Snapshot first because both branches mutate the children list.\n const childrenSnapshot = [...entity.children];\n for (const child of childrenSnapshot) {\n if (child.autoDestructionOnParentRemoval) {\n this.destroyEntity(child.uuid);\n } else {\n child.removeFromParent();\n this.#rootEntities.add(child.uuid);\n }\n }\n\n entity.removeFromParent();\n emit(entity, onDestroy, entity);\n\n usedConstructors.clear();\n\n this.#entities.delete(entity.uuid);\n this.#rootEntities.delete(entity.uuid);\n this.#allEntitiesNeedUpdate = true;\n }\n\n /**\n * @param order the new order, or `undefined` to keep the current one. A set-parent change\n * only carries an order when it actually changed, so an absent order must not be read as\n * a reset to `0` \u2014 that would silently drop the order the view side still holds.\n */\n setParent(uuid: string, parentUuid?: string, order?: number): void {\n const e = this.getEntity(uuid);\n\n const nextOrder = order ?? e.order;\n\n if (e.parentUuid === parentUuid && e.order === nextOrder) return;\n\n // Validate the new parent before detaching the current one, so a bad UUID\n // never leaves the entity orphaned (KERN-5).\n if (parentUuid && !this.#entities.has(parentUuid)) {\n throw new Error(`entity with uuid \"${parentUuid}\" not found!`);\n }\n\n e.removeFromParent();\n\n e.order = nextOrder;\n e.parentUuid = parentUuid;\n\n if (e.hasParent) {\n this.#rootEntities.delete(uuid);\n } else {\n this.#rootEntities.add(uuid);\n }\n\n e.reSubscribeToParentContexts();\n\n queueMicrotask(() => {\n if (this.logger.isDebug) {\n this.logger.debug('entity.onParentChanged', {uuid, parentUuid, order: nextOrder, entity: e});\n }\n emit(e, onParentChanged, e);\n });\n }\n\n updateOrder(uuid: string, order: number): void {\n this.getEntity(uuid).order = order;\n }\n\n dispatchEventsToEntity(uuid: string, events: IComponentEvent[]): void {\n this.getEntity(uuid)?.dispatchViewEvents(events);\n }\n\n changeProperties(uuid: string, properties: [string, unknown][]): void {\n this.getEntity(uuid).setProperties(properties);\n this.updateShadowObjects(uuid);\n }\n\n changeToken(uuid: string, token: string): void {\n const entry = this.#entities.get(uuid);\n if (entry === undefined) return;\n\n if (entry.token === token) return;\n\n entry.token = token;\n\n this.updateShadowObjects(uuid);\n }\n\n dispatchMessageToView(message: MessageToViewEvent): void {\n queueMicrotask(() => {\n emit(this as Kernel, MessageToView, message);\n });\n }\n\n /**\n * Create or destroy the shadow-objects of an entity using the registered constructors.\n * After a token change or registry changes, an entity may be given different shadow-objects.\n */\n private updateShadowObjects(\n uuid: string,\n action = ShadowObjectAction.CreateAndDestroy,\n nextConstructors?: Set<ShadowObjectConstructor>,\n ): Set<ShadowObjectConstructor> {\n const entry = this.#requireEntry(uuid);\n nextConstructors ??= new Set(this.registry.findConstructors(entry.token, entry.entity.truthyProps()));\n\n const shouldDestroy = action === ShadowObjectAction.CreateAndDestroy || action === ShadowObjectAction.DestroyOnly;\n const shouldCreate = action === ShadowObjectAction.CreateAndDestroy || action === ShadowObjectAction.JustCreate;\n\n // destroy all shadow-objects created by constructors no longer in the list\n //\n if (shouldDestroy) {\n for (const [construct, shadowObjects] of entry.usedConstructors) {\n if (!nextConstructors.has(construct)) {\n entry.usedConstructors.delete(construct);\n for (const obj of shadowObjects) {\n this.destroyShadowObject(obj, entry.entity);\n }\n }\n }\n }\n\n // shadow-objects for new constructors are now created using the updated constructor list\n //\n if (shouldCreate) {\n for (const construct of nextConstructors) {\n if (!entry.usedConstructors.has(construct)) {\n this.constructShadowObject(construct, entry);\n }\n }\n }\n\n return nextConstructors;\n }\n\n private constructShadowObject(construct: ShadowObjectConstructor, entry: EntityEntry): ShadowObjectType {\n const unsubscribePrimary = new Set<() => any>();\n const unsubscribeSecondary = new Set<() => any>();\n\n const contextReaders = new Map<string | symbol, SignalReader<any>>();\n const contextReaderCompares = new Map<string | symbol, CompareFunc<any> | undefined>();\n const contextParentReaders = new Map<string | symbol, SignalReader<any>>();\n const contextParentReaderCompares = new Map<string | symbol, CompareFunc<any> | undefined>();\n const contextProviders = new Map<string | symbol, Signal<any>>();\n const contextRootProviders = new Map<string | symbol, Signal<any>>();\n\n const propertyReaders = new Map<string, SignalReader<any>>();\n const propertyCompares = new Map<string, CompareFunc<any> | undefined>();\n\n const getUseProperty = <T = any>(\n name: string,\n options?: SignalValueOptions<T> | CompareFunc<T | undefined>,\n ): SignalReader<Maybe<T>> => {\n if (!usePropertyOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"useProperty()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n usePropertyOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let propReader = propertyReaders.get(name);\n\n if (propReader === undefined) {\n propReader = createSignal<any>(undefined, opts).get;\n propertyReaders.set(name, propReader);\n propertyCompares.set(name, opts?.compare);\n const con = link(entry.entity.getPropertyReader(name), propReader);\n unsubscribeSecondary.add(con.destroy.bind(con));\n } else if (opts?.compare != null && propertyCompares.get(name) !== opts.compare) {\n console.warn(\n `[shadow-objects] useProperty(\"${name}\"): 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.`,\n );\n }\n\n return propReader;\n };\n\n const shadowObject = eventize(\n new construct({\n entity: entry.entity,\n\n provideContext<T = unknown>(\n name: string | symbol,\n sourceOrInitialValue?: T | SignalReader<T> | SignalReader<T | undefined>,\n options?: ProvideContextOptions<T> | CompareFunc<T | undefined>,\n ) {\n if (!provideContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"provideContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n provideContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxProvider = contextProviders.get(name);\n\n if (ctxProvider == null) {\n const isSig = isSignal(sourceOrInitialValue);\n const initialValue = isSig ? undefined : toMaybe(sourceOrInitialValue as T);\n\n ctxProvider = createSignal(initialValue, opts?.compare ? {compare: opts.compare} : undefined);\n\n if (isSig) {\n const ln = link(sourceOrInitialValue as SignalReader<T>, ctxProvider);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n }\n\n const ln = link(ctxProvider, entry.entity.provideContext(name));\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n contextProviders.set(name, ctxProvider);\n }\n\n if (ctxProvider != null && (opts?.clearOnDestroy ?? true)) {\n unsubscribeSecondary.add(() => {\n ctxProvider.set(undefined);\n });\n }\n\n return ctxProvider;\n },\n\n provideGlobalContext<T = unknown>(\n name: string | symbol,\n sourceOrInitialValue?: T | SignalReader<T> | SignalReader<T | undefined>,\n options?: ProvideContextOptions<T> | CompareFunc<T | undefined>,\n ) {\n if (!provideGlobalContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"provideGlobalContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n provideGlobalContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxProvider = contextRootProviders.get(name);\n\n if (ctxProvider == null) {\n const isSig = isSignal(sourceOrInitialValue);\n const initialValue = isSig ? undefined : toMaybe(sourceOrInitialValue as T);\n\n ctxProvider = createSignal(initialValue, opts?.compare ? {compare: opts.compare} : undefined);\n\n if (isSig) {\n const ln = link(sourceOrInitialValue as SignalReader<T>, ctxProvider);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n }\n\n const ln = link(ctxProvider, entry.entity.provideGlobalContext(name));\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n contextRootProviders.set(name, ctxProvider);\n }\n\n if (ctxProvider != null && (opts?.clearOnDestroy ?? true)) {\n unsubscribeSecondary.add(() => {\n ctxProvider.set(undefined);\n });\n }\n\n return ctxProvider;\n },\n\n useContext<T = unknown>(name: string | symbol, options?: SignalValueOptions<T> | CompareFunc<T | undefined>) {\n if (!useContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"useContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n useContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxReader = contextReaders.get(name);\n\n if (ctxReader === undefined) {\n ctxReader = createSignal<any>(undefined, opts).get;\n contextReaders.set(name, ctxReader);\n contextReaderCompares.set(name, opts?.compare);\n const ln = link(entry.entity.useContext(name), ctxReader);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n } else if (opts?.compare != null && contextReaderCompares.get(name) !== opts.compare) {\n console.warn(\n `[shadow-objects] useContext(\"${String(name)}\"): 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.`,\n );\n }\n\n return ctxReader;\n },\n\n useParentContext<T = unknown>(name: string | symbol, options?: SignalValueOptions<T> | CompareFunc<T | undefined>) {\n if (!useParentContextOptionsDeprecatedShown && options != null && typeof options === 'function') {\n console.warn(\n '[shadow-objects] Deprecation Warning: The \"isEqual\" option of \"useParentContext()\" is now passed as {compare} argument. Please update your code accordingly.',\n );\n useParentContextOptionsDeprecatedShown = true;\n }\n\n const opts = typeof options === 'function' ? {compare: options} : options;\n\n let ctxReader = contextParentReaders.get(name);\n\n if (ctxReader === undefined) {\n ctxReader = createSignal<any>(undefined, opts).get;\n contextParentReaders.set(name, ctxReader);\n contextParentReaderCompares.set(name, opts?.compare);\n const ln = link(entry.entity.useParentContext(name), ctxReader);\n unsubscribeSecondary.add(ln.destroy.bind(ln));\n } else if (opts?.compare != null && contextParentReaderCompares.get(name) !== opts.compare) {\n console.warn(\n `[shadow-objects] useParentContext(\"${String(name)}\"): 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.`,\n );\n }\n\n return ctxReader;\n },\n\n dispatchMessageToView(type: string, data?: unknown, transferables?: Transferable[], traverseChildren = false) {\n entry.entity.dispatchMessageToView(type, data, transferables, traverseChildren);\n },\n\n useProperty: getUseProperty,\n\n useProperties<T extends Record<string, unknown> = Record<string, unknown>>(\n props: {[K in keyof T]: string},\n ): {\n [K in keyof T]: SignalReader<Maybe<T[K]>>;\n } {\n const result = {} as {[K in keyof T]: SignalReader<Maybe<T[K]>>};\n for (const key in props) {\n if (Object.hasOwn(props, key)) {\n result[key] = getUseProperty(props[key]);\n }\n }\n return result;\n },\n\n createResource<T = unknown>(\n factory: () => T | undefined,\n cleanup?: (resource: NonNullable<T>) => unknown,\n ): Signal<Maybe<T>> {\n const resourceSignal = createSignal<Maybe<T>>();\n\n const effect = createEffect(() => {\n const resource = toMaybe(factory());\n resourceSignal.set(resource);\n\n if (resource !== undefined && cleanup) {\n return () => {\n cleanup(resource);\n resourceSignal.set(undefined);\n };\n }\n\n return () => {\n resourceSignal.set(undefined);\n };\n });\n\n unsubscribeSecondary.add(() => {\n effect.destroy();\n resourceSignal.set(undefined);\n destroySignal(resourceSignal);\n });\n\n return resourceSignal;\n },\n\n createEffect(...args: any[]): ReturnType<typeof createEffect> {\n // @ts-ignore\n const effect = createEffect(...args);\n unsubscribeSecondary.add(effect.destroy);\n return effect;\n },\n\n createSignal<T = unknown>(...args: Parameters<typeof createSignal<T>>): ReturnType<typeof createSignal<T>> {\n const sig = createSignal<T>(...args);\n unsubscribeSecondary.add(() => {\n destroySignal(sig);\n });\n return sig;\n },\n\n createMemo<T = unknown>(...args: Parameters<typeof createMemo<T>>): SignalReader<T> {\n const sig = createMemo<T>(...args);\n unsubscribeSecondary.add(() => {\n destroySignal(sig);\n });\n return sig;\n },\n\n on(...args: any[]): ReturnType<typeof on> {\n const [firstArg] = args;\n if (typeof firstArg === 'string' || typeof firstArg === 'symbol' || Array.isArray(firstArg)) {\n // @ts-ignore\n const unsub = on(entry.entity, ...args);\n unsubscribeSecondary.add(unsub);\n return unsub;\n }\n // @ts-ignore\n const unsub = on(...args);\n unsubscribeSecondary.add(unsub);\n // return unsub;\n return Object.assign(() => {\n unsubscribeSecondary.delete(unsub);\n unsub();\n }, unsub);\n },\n\n once(...args: any[]): ReturnType<typeof once> {\n const [firstArg] = args;\n if (typeof firstArg === 'string' || typeof firstArg === 'symbol' || Array.isArray(firstArg)) {\n // @ts-ignore\n const unsub = once(entry.entity, ...args);\n unsubscribeSecondary.add(unsub);\n return unsub;\n }\n // @ts-ignore\n const unsub = once(...args);\n unsubscribeSecondary.add(unsub);\n // return unsub;\n return Object.assign(() => {\n unsubscribeSecondary.delete(unsub);\n unsub();\n }, unsub);\n },\n\n emit(...args: any[]): void {\n const [firstArg] = args;\n if (typeof firstArg === 'string' || typeof firstArg === 'symbol' || Array.isArray(firstArg)) {\n // @ts-ignore\n emit(entry.entity, ...args);\n } else {\n // @ts-ignore\n emit(...args);\n }\n },\n\n onViewEvent(callback: (type: string, data: unknown) => any) {\n const unsub = on(entry.entity, onViewEvent, (type: string, data: unknown) => {\n callback(type, data);\n });\n unsubscribeSecondary.add(unsub);\n },\n\n onDestroy(callback: () => any) {\n unsubscribePrimary.add(callback);\n },\n }),\n );\n\n if (this.logger.isInfo) {\n this.logger.info('create shadow-object', getDisplayName(construct), {shadowObject, entity: entry.entity});\n }\n\n once(entry.entity, onDestroy, Priority.Low, () => {\n if (this.logger.isInfo) {\n this.logger.info('destroy shadow-object', getDisplayName(construct), {shadowObject, entity: entry.entity});\n }\n\n for (const callback of unsubscribePrimary) {\n callback();\n }\n\n for (const callback of unsubscribeSecondary) {\n callback();\n }\n\n for (const sig of contextReaders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of contextParentReaders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of propertyReaders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of contextProviders.values()) {\n destroySignal(sig);\n }\n\n for (const sig of contextRootProviders.values()) {\n destroySignal(sig);\n }\n\n unsubscribePrimary.clear();\n unsubscribeSecondary.clear();\n contextReaders.clear();\n contextParentReaders.clear();\n propertyReaders.clear();\n contextProviders.clear();\n contextRootProviders.clear();\n\n const otherShadowObjects = entry.usedConstructors.get(construct);\n if (otherShadowObjects) {\n otherShadowObjects.delete(shadowObject);\n if (otherShadowObjects.size === 0) {\n entry.usedConstructors.delete(construct);\n }\n }\n });\n\n // We want to keep track which shadow-objects are created by which constructors.\n // This will all\n //\n const createdBy = entry.usedConstructors.get(construct);\n if (createdBy) {\n createdBy.add(shadowObject);\n } else {\n entry.usedConstructors.set(construct, new Set([shadowObject]));\n }\n\n this.attachShadowObject(shadowObject, entry.entity);\n\n return shadowObject;\n }\n\n private createShadowObjects(entry: EntityEntry): void {\n this.registry.findConstructors(entry.token, entry.entity.truthyProps())?.forEach((construct) => {\n this.constructShadowObject(construct, entry);\n });\n }\n\n findShadowObjects(uuid: string): ShadowObjectType[] {\n const entry = this.#entities.get(uuid);\n if (entry === undefined) return [];\n\n const {usedConstructors} = entry;\n\n return Array.from(new Set(Array.from(usedConstructors.values()).flatMap((objs) => Array.from(objs))));\n }\n\n private attachShadowObject(shadowObject: object, entity: Entity): void {\n // Like all other objects, the new shadow-object should be able to respond to the events that the entity receives.\n //\n on(entity, shadowObject);\n\n // Finally, the `shadowObject.onCreate(entity)` callback is called on the shadow-object.\n //\n if (typeof (shadowObject as any)[onCreate] === 'function') {\n (shadowObject as OnCreate)[onCreate](entity);\n }\n }\n\n private destroyShadowObject(shadowObject: object, entity: Entity): void {\n if (typeof (shadowObject as any)[onDestroy] === 'function') {\n (shadowObject as OnDestroy)[onDestroy](entity);\n }\n\n emit(shadowObject, onDestroy, entity);\n\n off(entity, shadowObject);\n }\n\n findOrCreateRootContext(name: string | symbol): SignalsPath {\n let ctx = this.#rootContexts.get(name);\n if (!ctx) {\n ctx = new SignalsPath();\n this.#rootContexts.set(name, ctx);\n }\n return ctx;\n }\n\n destroy(): void {\n for (const ctx of this.#rootContexts.values()) {\n ctx.dispose();\n }\n this.#rootContexts.clear();\n\n for (const entity of this.traverseLevelOrderBFS().reverse()) {\n this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AM;AAAA,IAC7C;AAAA,EACF;AAAA,EAEQ,oBAAoB,cAAsB,QAAsB;AACtE,QAAI,OAAQ,aAAqB,SAAS,MAAM,YAAY;AAC1D,MAAC,aAA2B,SAAS,EAAE,MAAM;AAAA,IAC/C;AAEA,SAAK,cAAc,WAAW,MAAM;AAEpC,QAAI,QAAQ,YAAY;AAAA,EAC1B;AAAA,EAEA,wBAAwB,MAAoC;AAC1D,QAAI,MAAM,KAAK,cAAc,IAAI,IAAI;AACrC,QAAI,CAAC,KAAK;AACR,YAAM,IAAI,YAAY;AACtB,WAAK,cAAc,IAAI,MAAM,GAAG;AAAA,IAClC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,UAAgB;AACd,eAAW,OAAO,KAAK,cAAc,OAAO,GAAG;AAC7C,UAAI,QAAQ;AAAA,IACd;AACA,SAAK,cAAc,MAAM;AAEzB,eAAW,UAAU,KAAK,sBAAsB,EAAE,QAAQ,GAAG;AAC3D,WAAK,cAAc,OAAO,IAAI;AAAA,IAChC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["ShadowObjectAction", "ln", "unsub"]
|
|
7
7
|
}
|
|
@@ -4,7 +4,7 @@ export declare class Registry {
|
|
|
4
4
|
#private;
|
|
5
5
|
/** return the specified registry or, if not defined, the default registry */
|
|
6
6
|
static get(registry?: Registry): Registry;
|
|
7
|
-
define(token: string,
|
|
7
|
+
define(token: string, constructa: ShadowObjectConstructor): void;
|
|
8
8
|
appendRoute(token: string, routes: string[]): void;
|
|
9
9
|
clearRoute(route: string): void;
|
|
10
10
|
findTokensByRoute(route: string, truthyProps?: Set<string>): Set<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["../../../src/in-the-dark/Registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AA+BzD,uCAAuC;AACvC,qBAAa,QAAQ;;IACnB,6EAA6E;IAC7E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,QAAQ;IAQ9B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["../../../src/in-the-dark/Registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AA+BzD,uCAAuC;AACvC,qBAAa,QAAQ;;IACnB,6EAA6E;IAC7E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,QAAQ;IAQ9B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB;IASzD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;IAmB3C,UAAU,CAAC,KAAK,EAAE,MAAM;IASxB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;IA2CxE,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,uBAAuB,EAAE,GAAG,SAAS;IAWjG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC,KAAK;CAKN"}
|
|
@@ -14,8 +14,8 @@ const addRoutes = (set, routes) => {
|
|
|
14
14
|
};
|
|
15
15
|
const addConstructors = (entry, constructors) => {
|
|
16
16
|
if (entry != null) {
|
|
17
|
-
for (const
|
|
18
|
-
constructors.add(
|
|
17
|
+
for (const c of entry.constructors) {
|
|
18
|
+
constructors.add(c);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
};
|
|
@@ -27,24 +27,27 @@ class Registry {
|
|
|
27
27
|
#registry = /* @__PURE__ */ new Map();
|
|
28
28
|
#routes = /* @__PURE__ */ new Map();
|
|
29
29
|
#truthyPropRoutes = /* @__PURE__ */ new Map();
|
|
30
|
-
define(token,
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
define(token, constructa) {
|
|
31
|
+
const entry = this.#registry.get(token);
|
|
32
|
+
if (entry) {
|
|
33
|
+
appendTo(entry.constructors, constructa);
|
|
33
34
|
} else {
|
|
34
|
-
this.#registry.set(token, { token, constructors: [
|
|
35
|
+
this.#registry.set(token, { token, constructors: [constructa] });
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
appendRoute(token, routes) {
|
|
38
39
|
const propRoute = toPropRoute(token);
|
|
39
40
|
if (propRoute) {
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
const knownPropRoutes = this.#truthyPropRoutes.get(propRoute.key);
|
|
42
|
+
if (knownPropRoutes) {
|
|
43
|
+
addRoutes(knownPropRoutes.routes, routes);
|
|
42
44
|
} else {
|
|
43
45
|
this.#truthyPropRoutes.set(propRoute.key, { routes: new Set(routes), token: propRoute.token });
|
|
44
46
|
}
|
|
45
47
|
} else {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const knownRoutes = this.#routes.get(token);
|
|
49
|
+
if (knownRoutes) {
|
|
50
|
+
addRoutes(knownRoutes, routes);
|
|
48
51
|
} else {
|
|
49
52
|
this.#routes.set(token, new Set(routes));
|
|
50
53
|
}
|
|
@@ -60,21 +63,22 @@ class Registry {
|
|
|
60
63
|
}
|
|
61
64
|
findTokensByRoute(route, truthyProps) {
|
|
62
65
|
const tokens = /* @__PURE__ */ new Set([route]);
|
|
63
|
-
const next =
|
|
64
|
-
|
|
65
|
-
const cur = next.shift();
|
|
66
|
+
const next = Array.from(this.#routes.get(route) ?? []);
|
|
67
|
+
for (let cur = next.shift(); cur !== void 0; cur = next.shift()) {
|
|
66
68
|
if (tokens.has(cur)) {
|
|
67
69
|
continue;
|
|
68
70
|
}
|
|
69
71
|
tokens.add(cur);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const nextRoutes = this.#routes.get(cur);
|
|
73
|
+
if (nextRoutes) {
|
|
74
|
+
next.push(...Array.from(nextRoutes).filter((route2) => !tokens.has(route2)));
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
if (truthyProps) {
|
|
75
78
|
for (const prop of truthyProps) {
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
const propRoutes = this.#truthyPropRoutes.get(prop);
|
|
80
|
+
if (propRoutes) {
|
|
81
|
+
addRoutes(tokens, propRoutes.routes);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
let tokenCountBefore;
|
|
@@ -82,9 +86,9 @@ class Registry {
|
|
|
82
86
|
tokenCountBefore = tokens.size;
|
|
83
87
|
for (const token of new Set(tokens)) {
|
|
84
88
|
for (const prop of truthyProps) {
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
addRoutes(tokens,
|
|
89
|
+
const keyedRoutes = this.#truthyPropRoutes.get(`${token}@${prop}`);
|
|
90
|
+
if (keyedRoutes) {
|
|
91
|
+
addRoutes(tokens, keyedRoutes.routes);
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/in-the-dark/Registry.ts"],
|
|
4
|
-
"sourcesContent": ["import type {ShadowObjectConstructor} from '../types.js';\nimport {appendTo} from '../utils/array-utils.js';\n\ninterface RegistryEntry {\n token: string;\n constructors: ShadowObjectConstructor[];\n}\n\nconst toPropRoute = (route: string): undefined | {key: string; prop: string; token?: string} => {\n const parts = route.split('@').map((part) => part.trim());\n if (parts.length === 2 && parts[1]) {\n return parts[0] ? {key: `${parts[0]}@${parts[1]}`, prop: parts[1], token: parts[0]} : {key: parts[1], prop: parts[1]};\n } else {\n return undefined;\n }\n};\n\nconst addRoutes = (set: Set<string>, routes: string[] | Set<string>) => {\n for (const route of routes) {\n set.add(route);\n }\n};\n\nconst addConstructors = (entry: RegistryEntry | null | undefined, constructors: Set<ShadowObjectConstructor>) => {\n if (entry != null) {\n for (const
|
|
5
|
-
"mappings": "AACA,SAAQ,gBAAe;AAOvB,MAAM,cAAc,CAAC,UAA2E;AAC9F,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC;AACxD,MAAI,MAAM,WAAW,KAAK,MAAM,CAAC,GAAG;AAClC,WAAO,MAAM,CAAC,IAAI,EAAC,KAAK,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,MAAM,MAAM,CAAC,GAAG,OAAO,MAAM,CAAC,EAAC,IAAI,EAAC,KAAK,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,EAAC;AAAA,EACtH,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAEA,MAAM,YAAY,CAAC,KAAkB,WAAmC;AACtE,aAAW,SAAS,QAAQ;AAC1B,QAAI,IAAI,KAAK;AAAA,EACf;AACF;AAEA,MAAM,kBAAkB,CAAC,OAAyC,iBAA+C;AAC/G,MAAI,SAAS,MAAM;AACjB,eAAW,
|
|
4
|
+
"sourcesContent": ["import type {ShadowObjectConstructor} from '../types.js';\nimport {appendTo} from '../utils/array-utils.js';\n\ninterface RegistryEntry {\n token: string;\n constructors: ShadowObjectConstructor[];\n}\n\nconst toPropRoute = (route: string): undefined | {key: string; prop: string; token?: string} => {\n const parts = route.split('@').map((part) => part.trim());\n if (parts.length === 2 && parts[1]) {\n return parts[0] ? {key: `${parts[0]}@${parts[1]}`, prop: parts[1], token: parts[0]} : {key: parts[1], prop: parts[1]};\n } else {\n return undefined;\n }\n};\n\nconst addRoutes = (set: Set<string>, routes: string[] | Set<string>) => {\n for (const route of routes) {\n set.add(route);\n }\n};\n\nconst addConstructors = (entry: RegistryEntry | null | undefined, constructors: Set<ShadowObjectConstructor>) => {\n if (entry != null) {\n for (const c of entry.constructors) {\n constructors.add(c);\n }\n }\n};\n\n/** The shadow-object class registry */\nexport class Registry {\n /** return the specified registry or, if not defined, the default registry */\n static get(registry?: Registry) {\n return registry ?? defaultRegistry;\n }\n\n readonly #registry = new Map<string, RegistryEntry>();\n readonly #routes = new Map<string, Set<string>>();\n readonly #truthyPropRoutes = new Map<string, {routes: Set<string>; token?: string}>();\n\n define(token: string, constructa: ShadowObjectConstructor) {\n const entry = this.#registry.get(token);\n if (entry) {\n appendTo(entry.constructors, constructa);\n } else {\n this.#registry.set(token, {token, constructors: [constructa]});\n }\n }\n\n appendRoute(token: string, routes: string[]) {\n const propRoute = toPropRoute(token);\n if (propRoute) {\n const knownPropRoutes = this.#truthyPropRoutes.get(propRoute.key);\n if (knownPropRoutes) {\n addRoutes(knownPropRoutes.routes, routes);\n } else {\n this.#truthyPropRoutes.set(propRoute.key, {routes: new Set(routes), token: propRoute.token});\n }\n } else {\n const knownRoutes = this.#routes.get(token);\n if (knownRoutes) {\n addRoutes(knownRoutes, routes);\n } else {\n this.#routes.set(token, new Set(routes));\n }\n }\n }\n\n clearRoute(route: string) {\n const propRoute = toPropRoute(route);\n if (propRoute) {\n this.#truthyPropRoutes.delete(propRoute.key);\n } else {\n this.#routes.delete(route);\n }\n }\n\n findTokensByRoute(route: string, truthyProps?: Set<string>): Set<string> {\n const tokens = new Set<string>([route]);\n\n const next = Array.from(this.#routes.get(route) ?? []);\n\n for (let cur = next.shift(); cur !== undefined; cur = next.shift()) {\n if (tokens.has(cur)) {\n continue;\n }\n\n tokens.add(cur);\n\n const nextRoutes = this.#routes.get(cur);\n if (nextRoutes) {\n next.push(...Array.from(nextRoutes).filter((route) => !tokens.has(route)));\n }\n }\n\n if (truthyProps) {\n for (const prop of truthyProps) {\n const propRoutes = this.#truthyPropRoutes.get(prop);\n if (propRoutes) {\n addRoutes(tokens, propRoutes.routes);\n }\n }\n\n let tokenCountBefore: number;\n do {\n tokenCountBefore = tokens.size;\n for (const token of new Set(tokens)) {\n for (const prop of truthyProps) {\n const keyedRoutes = this.#truthyPropRoutes.get(`${token}@${prop}`);\n if (keyedRoutes) {\n addRoutes(tokens, keyedRoutes.routes);\n }\n }\n }\n } while (tokenCountBefore !== tokens.size);\n }\n\n return tokens;\n }\n\n findConstructors(route: string, truthyProps?: Set<string>): ShadowObjectConstructor[] | undefined {\n const tokens = this.findTokensByRoute(route, truthyProps);\n const constructors = new Set<ShadowObjectConstructor>();\n\n for (const token of tokens) {\n addConstructors(this.#registry.get(token), constructors);\n }\n\n return constructors.size > 0 ? Array.from(constructors) : undefined;\n }\n\n hasToken(token: string): boolean {\n return this.#registry.has(token);\n }\n\n hasRoute(route: string): boolean {\n return this.#routes.has(route);\n }\n\n clear() {\n this.#registry.clear();\n this.#routes.clear();\n this.#truthyPropRoutes.clear();\n }\n}\n\nconst defaultRegistry = new Registry();"],
|
|
5
|
+
"mappings": "AACA,SAAQ,gBAAe;AAOvB,MAAM,cAAc,CAAC,UAA2E;AAC9F,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC;AACxD,MAAI,MAAM,WAAW,KAAK,MAAM,CAAC,GAAG;AAClC,WAAO,MAAM,CAAC,IAAI,EAAC,KAAK,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,MAAM,MAAM,CAAC,GAAG,OAAO,MAAM,CAAC,EAAC,IAAI,EAAC,KAAK,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,EAAC;AAAA,EACtH,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAEA,MAAM,YAAY,CAAC,KAAkB,WAAmC;AACtE,aAAW,SAAS,QAAQ;AAC1B,QAAI,IAAI,KAAK;AAAA,EACf;AACF;AAEA,MAAM,kBAAkB,CAAC,OAAyC,iBAA+C;AAC/G,MAAI,SAAS,MAAM;AACjB,eAAW,KAAK,MAAM,cAAc;AAClC,mBAAa,IAAI,CAAC;AAAA,IACpB;AAAA,EACF;AACF;AAGO,MAAM,SAAS;AAAA;AAAA,EAEpB,OAAO,IAAI,U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QAAQ,IAAI,KAAK;AAAA,EAC/B;AAAA,EAEA,QAAQ;AACN,SAAK,UAAU,MAAM;AACrB,SAAK,QAAQ,MAAM;AACnB,SAAK,kBAAkB,MAAM;AAAA,EAC/B;AACF;AAEA,MAAM,kBAAkB,IAAI,SAAS;",
|
|
6
6
|
"names": ["route"]
|
|
7
7
|
}
|
|
@@ -13,6 +13,6 @@ export declare function ShadowObject(options: ShadowObjectDecoratorOptions): <C
|
|
|
13
13
|
* If you don't want to use the decorator, you can simply call this method instead.
|
|
14
14
|
*/
|
|
15
15
|
export declare const shadowObjects: {
|
|
16
|
-
define(token: string,
|
|
16
|
+
define(token: string, constructa: ShadowObjectConstructor, registry?: Registry): void;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=ShadowObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShadowObject.d.ts","sourceRoot":"","sources":["../../../src/in-the-dark/ShadowObject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAEvC,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,oCAAoC;AACpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,4BAA4B,IACxD,CAAC,SAAS,uBAAuB,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG;kBAG3C,GAAG,EAAE;;MAW/B;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;kBACV,MAAM,
|
|
1
|
+
{"version":3,"file":"ShadowObject.d.ts","sourceRoot":"","sources":["../../../src/in-the-dark/ShadowObject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAEvC,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,oCAAoC;AACpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,4BAA4B,IACxD,CAAC,SAAS,uBAAuB,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG;kBAG3C,GAAG,EAAE;;MAW/B;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;kBACV,MAAM,cAAc,uBAAuB,aAAa,QAAQ;CAG/E,CAAC"}
|
|
@@ -13,8 +13,8 @@ function ShadowObject(options) {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
const shadowObjects = {
|
|
16
|
-
define(token,
|
|
17
|
-
Registry.get(registry).define(token,
|
|
16
|
+
define(token, constructa, registry) {
|
|
17
|
+
Registry.get(registry).define(token, constructa);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/in-the-dark/ShadowObject.ts"],
|
|
4
|
-
"sourcesContent": ["import {eventize} from '@spearwolf/eventize';\nimport type {ShadowObjectConstructor} from '../types.js';\nimport {Registry} from './Registry.js';\n\nexport interface ShadowObjectDecoratorOptions {\n token: string;\n registry?: Registry;\n}\n\n/** The `@ShadowObject` decorator */\nexport function ShadowObject(options: ShadowObjectDecoratorOptions) {\n return <C extends ShadowObjectConstructor>(target: C, _context?: any) => {\n // @ts-ignore\n const __ShadowObject = class extends target {\n constructor(...args: any[]) {\n // @ts-ignore\n super(...args);\n eventize(this);\n }\n };\n\n Registry.get(options.registry).define(options.token, __ShadowObject);\n\n return __ShadowObject;\n };\n}\n\n/**\n * If you don't want to use the decorator, you can simply call this method instead.\n */\nexport const shadowObjects = {\n define(token: string,
|
|
5
|
-
"mappings": "AAAA,SAAQ,gBAAe;AAEvB,SAAQ,gBAAe;AAQhB,SAAS,aAAa,SAAuC;AAClE,SAAO,CAAoC,QAAW,aAAmB;AAEvE,UAAM,iBAAiB,cAAc,OAAO;AAAA,MAC1C,eAAe,MAAa;AAE1B,cAAM,GAAG,IAAI;AACb,iBAAS,IAAI;AAAA,MACf;AAAA,IACF;AAEA,aAAS,IAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,OAAO,cAAc;AAEnE,WAAO;AAAA,EACT;AACF;AAKO,MAAM,gBAAgB;AAAA,EAC3B,OAAO,OAAe,
|
|
4
|
+
"sourcesContent": ["import {eventize} from '@spearwolf/eventize';\nimport type {ShadowObjectConstructor} from '../types.js';\nimport {Registry} from './Registry.js';\n\nexport interface ShadowObjectDecoratorOptions {\n token: string;\n registry?: Registry;\n}\n\n/** The `@ShadowObject` decorator */\nexport function ShadowObject(options: ShadowObjectDecoratorOptions) {\n return <C extends ShadowObjectConstructor>(target: C, _context?: any) => {\n // @ts-ignore\n const __ShadowObject = class extends target {\n constructor(...args: any[]) {\n // @ts-ignore\n super(...args);\n eventize(this);\n }\n };\n\n Registry.get(options.registry).define(options.token, __ShadowObject);\n\n return __ShadowObject;\n };\n}\n\n/**\n * If you don't want to use the decorator, you can simply call this method instead.\n */\nexport const shadowObjects = {\n define(token: string, constructa: ShadowObjectConstructor, registry?: Registry) {\n Registry.get(registry).define(token, constructa);\n },\n};"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,gBAAe;AAEvB,SAAQ,gBAAe;AAQhB,SAAS,aAAa,SAAuC;AAClE,SAAO,CAAoC,QAAW,aAAmB;AAEvE,UAAM,iBAAiB,cAAc,OAAO;AAAA,MAC1C,eAAe,MAAa;AAE1B,cAAM,GAAG,IAAI;AACb,iBAAS,IAAI;AAAA,MACf;AAAA,IACF;AAEA,aAAS,IAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,OAAO,cAAc;AAEnE,WAAO;AAAA,EACT;AACF;AAKO,MAAM,gBAAgB;AAAA,EAC3B,OAAO,OAAe,YAAqC,UAAqB;AAC9E,aAAS,IAAI,QAAQ,EAAE,OAAO,OAAO,UAAU;AAAA,EACjD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignalsPath.d.ts","sourceRoot":"","sources":["../../../src/in-the-dark/SignalsPath.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,MAAM,EACX,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAK9B,qBAAa,WAAW;;IACtB,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAS;IAKP,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAa;IAEvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;gBAEjB,OAAO,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"SignalsPath.d.ts","sourceRoot":"","sources":["../../../src/in-the-dark/SignalsPath.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,MAAM,EACX,KAAK,UAAU,EAEhB,MAAM,sBAAsB,CAAC;AAK9B,qBAAa,WAAW;;IACtB,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAS;IAKP,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAa;IAEvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;gBAEjB,OAAO,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE;IAavC,GAAG,CAAC,GAAG,OAAO,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE;IAMjD,OAAO,CAAC,GAAG,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE;IAMrC,MAAM,CAAC,GAAG,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE;IAIpC,KAAK;IAKL,OAAO;CA6CR"}
|