@state-of-geneva/bim-ecs-devtools-plugin 0.0.0-stage → 0.0.12

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.
@@ -0,0 +1,423 @@
1
+ import { ECS_SYSTEM_DISPOSED_EVENT as e, ECS_SYSTEM_REGISTERED_EVENT as t, ECS_WORLD_DISPOSING_EVENT as n, ECS_WORLD_RUNNING_EVENT as r, ECS_WORLD_STOPPING_EVENT as i, EcsIndexedComponent as a, EcsMutableComponent as o } from "@state-of-geneva/bim-ecs";
2
+ //#region src/build-graph.ts
3
+ var s = /* @__PURE__ */ new Set([
4
+ "startup",
5
+ "frame",
6
+ "component-added",
7
+ "component-removed",
8
+ "component-value-changed",
9
+ "entity-spawned",
10
+ "entity-removed"
11
+ ]);
12
+ function c(e) {
13
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = (e) => `system:${e}`, i = (e) => (t.has(e.id) || t.set(e.id, e), e.id), a = (e, t, r) => {
14
+ let i = `${e}>${t}:${r}`;
15
+ n.has(i) || n.set(i, {
16
+ id: i,
17
+ from: e,
18
+ to: t,
19
+ kind: r
20
+ });
21
+ }, o = (e) => i({
22
+ id: r(e),
23
+ kind: "system",
24
+ label: `#${e}`,
25
+ detail: "not registered"
26
+ }), c = (e, t, n) => {
27
+ switch (e.kind) {
28
+ case "on":
29
+ case "at-command": {
30
+ let n = e.kind === "on" ? "event" : "command";
31
+ for (let r of e.labels ?? []) a(i({
32
+ id: `${n}:${r}`,
33
+ kind: n,
34
+ label: r
35
+ }), t, "schedule");
36
+ return;
37
+ }
38
+ case "after": {
39
+ let r = (e.systems ?? []).map(o);
40
+ if (r.length === 1) a(r[0], t, "after");
41
+ else {
42
+ let o = i({
43
+ id: n,
44
+ kind: "after",
45
+ label: String(e.params?.combination ?? "or")
46
+ });
47
+ for (let e of r) a(e, o, "after");
48
+ a(o, t, "schedule");
49
+ }
50
+ return;
51
+ }
52
+ default: {
53
+ let r = e.without?.length ? `without ${e.without.join(", ")}` : void 0, o = l(e), u = s.has(e.kind) ? `${e.kind}:${o}${r ? `|${r}` : ""}` : n, d = i({
54
+ id: u,
55
+ kind: e.kind,
56
+ label: o,
57
+ ...r && { detail: r }
58
+ });
59
+ a(d, t, "schedule"), e.children?.forEach((e, t) => c(e, d, `${n}/${t}`));
60
+ }
61
+ }
62
+ };
63
+ for (let t of e) i({
64
+ id: r(t.id),
65
+ kind: "system",
66
+ label: t.name,
67
+ system: {
68
+ id: t.id,
69
+ running: t.running,
70
+ disposed: t.disposed
71
+ }
72
+ });
73
+ for (let t of e) {
74
+ let e = r(t.id);
75
+ c(t.scheduler, e, `${e}/scheduler`), t.then?.publish && a(e, i({
76
+ id: `event:${t.then.publish}`,
77
+ kind: "event",
78
+ label: t.then.publish
79
+ }), "publish"), t.then?.trigger && a(e, i({
80
+ id: `command:${t.then.trigger}`,
81
+ kind: "command",
82
+ label: t.then.trigger
83
+ }), "trigger");
84
+ }
85
+ return {
86
+ nodes: [...t.values()],
87
+ edges: [...n.values()]
88
+ };
89
+ }
90
+ function l({ kind: e, labels: t, params: n }) {
91
+ if (t?.length) return t.join(", ");
92
+ switch (e) {
93
+ case "timer":
94
+ case "debounce": return `${n?.delay ?? "?"}ms`;
95
+ case "when": return String(n?.predicate ?? e);
96
+ default: return e;
97
+ }
98
+ }
99
+ //#endregion
100
+ //#region src/serialize-value.ts
101
+ var u = {
102
+ maxDepth: 4,
103
+ maxEntries: 50,
104
+ maxStringLength: 300,
105
+ maxNodes: 1e3
106
+ };
107
+ function d(e, t) {
108
+ let n = {
109
+ ...u,
110
+ ...t
111
+ };
112
+ return f(e, 0, /* @__PURE__ */ new Set(), { remaining: n.maxNodes }, n);
113
+ }
114
+ function f(e, t, n, r, i) {
115
+ switch (typeof e) {
116
+ case "string": return e.length > i.maxStringLength ? `${e.slice(0, i.maxStringLength)}…` : e;
117
+ case "number": return Number.isFinite(e) ? e : {
118
+ $: "number",
119
+ v: Number.isNaN(e) ? "NaN" : e > 0 ? "Infinity" : "-Infinity"
120
+ };
121
+ case "boolean": return e;
122
+ case "undefined": return { $: "undefined" };
123
+ case "bigint": return {
124
+ $: "bigint",
125
+ v: e.toString()
126
+ };
127
+ case "symbol": return {
128
+ $: "symbol",
129
+ v: e.toString()
130
+ };
131
+ case "function": return {
132
+ $: "function",
133
+ name: e.name || "(anonymous)"
134
+ };
135
+ }
136
+ if (e === null) return null;
137
+ let a = e;
138
+ if (n.has(a)) return { $: "circular" };
139
+ let o = p(a);
140
+ if (--r.remaining < 0) return {
141
+ $: "truncated",
142
+ cls: o
143
+ };
144
+ if (a instanceof Date) return {
145
+ $: "date",
146
+ v: Number.isNaN(a.getTime()) ? "Invalid Date" : a.toISOString()
147
+ };
148
+ let s = g(a);
149
+ if (s) return {
150
+ $: "opaque",
151
+ cls: o,
152
+ ...s.desc !== void 0 && { desc: s.desc }
153
+ };
154
+ let c = Array.isArray(a) || a instanceof Map || a instanceof Set;
155
+ if (t >= i.maxDepth) return {
156
+ $: "truncated",
157
+ cls: o,
158
+ ...c && { size: m(a) }
159
+ };
160
+ n.add(a);
161
+ try {
162
+ let e = (e) => f(e, t + 1, n, r, i);
163
+ if (Array.isArray(a)) return {
164
+ $: "array",
165
+ size: a.length,
166
+ items: a.slice(0, i.maxEntries).map(e)
167
+ };
168
+ if (a instanceof Set) return {
169
+ $: "set",
170
+ size: a.size,
171
+ items: h(a.values(), i.maxEntries).map(e)
172
+ };
173
+ if (a instanceof Map) return {
174
+ $: "map",
175
+ size: a.size,
176
+ entries: h(a.entries(), i.maxEntries).map(([t, n]) => [e(t), e(n)])
177
+ };
178
+ let s = Object.keys(a);
179
+ return {
180
+ $: "object",
181
+ cls: o,
182
+ size: s.length,
183
+ entries: s.slice(0, i.maxEntries).map((t) => {
184
+ let n = Object.getOwnPropertyDescriptor(a, t);
185
+ return [t, n && "value" in n ? e(n.value) : {
186
+ $: "opaque",
187
+ cls: "Getter"
188
+ }];
189
+ })
190
+ };
191
+ } catch (e) {
192
+ return {
193
+ $: "opaque",
194
+ cls: o,
195
+ desc: `unreadable: ${String(e)}`
196
+ };
197
+ } finally {
198
+ n.delete(a);
199
+ }
200
+ }
201
+ function p(e) {
202
+ try {
203
+ return Object.getPrototypeOf(e)?.constructor?.name || "Object";
204
+ } catch {
205
+ return "Object";
206
+ }
207
+ }
208
+ function m(e) {
209
+ return Array.isArray(e) ? e.length : e.size;
210
+ }
211
+ function h(e, t) {
212
+ let n = [];
213
+ for (let r = e.next(); !r.done && n.length < t; r = e.next()) n.push(r.value);
214
+ return n;
215
+ }
216
+ function g(e) {
217
+ if (typeof Node < "u" && e instanceof Node) return { desc: e.nodeName };
218
+ if (typeof Window < "u" && e instanceof Window) return {};
219
+ if (e instanceof Error) return { desc: e.message };
220
+ if (e instanceof RegExp) return { desc: String(e) };
221
+ if (e instanceof Promise || e instanceof WeakMap || e instanceof WeakSet || typeof WeakRef < "u" && e instanceof WeakRef) return {};
222
+ if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) return { desc: `${e.byteLength} bytes` };
223
+ }
224
+ //#endregion
225
+ //#region src/inspect-entities.ts
226
+ var _ = 100, v = /* @__PURE__ */ new WeakMap(), y = 0;
227
+ function b(e) {
228
+ let t = v.get(e);
229
+ return t === void 0 && v.set(e, t = `c${y++}`), t;
230
+ }
231
+ function x(e) {
232
+ return e.prototype instanceof o ? "mutable" : e.prototype instanceof a ? "indexed" : "component";
233
+ }
234
+ function S(e) {
235
+ let t = /* @__PURE__ */ new Map(), n = [], r = 0;
236
+ for (let i of e.entities.archetypes()) {
237
+ let e = i.entities.size;
238
+ r += e;
239
+ for (let n of i.components) t.set(n, (t.get(n) ?? 0) + e);
240
+ let a = i.components.map(b).sort();
241
+ n.push({
242
+ key: a.join("+"),
243
+ components: a,
244
+ entities: e
245
+ });
246
+ }
247
+ let i = [...t].map(([e, t]) => ({
248
+ key: b(e),
249
+ name: e.name,
250
+ kind: x(e),
251
+ entities: t
252
+ }));
253
+ return i.sort((e, t) => t.entities - e.entities || e.name.localeCompare(t.name)), n.sort((e, t) => t.entities - e.entities || e.key.localeCompare(t.key)), {
254
+ entities: r,
255
+ types: i,
256
+ archetypes: n
257
+ };
258
+ }
259
+ function C(e, t = {}) {
260
+ let { with: n = [], without: r = [], limit: i = _ } = t, a = [], o = Math.max(0, t.offset ?? 0), s = 0;
261
+ for (let t of e.entities.archetypes()) {
262
+ let e = t.components.map(b);
263
+ if (!n.every((t) => e.includes(t)) || r.some((t) => e.includes(t))) continue;
264
+ let c = t.entities.size;
265
+ if (s += c, a.length >= i) continue;
266
+ if (o >= c) {
267
+ o -= c;
268
+ continue;
269
+ }
270
+ let l = 0;
271
+ for (let n of t.entities) if (!(l++ < o) && (a.push({
272
+ id: n,
273
+ components: e
274
+ }), a.length >= i)) break;
275
+ o = 0;
276
+ }
277
+ return {
278
+ total: s,
279
+ entities: a
280
+ };
281
+ }
282
+ function w(e, t) {
283
+ let n = e.entities.pool.componentsByEntity.get(t);
284
+ return n ? {
285
+ id: t,
286
+ components: [...n].map((e) => {
287
+ let t = e.constructor, n = Object.keys(e).filter((e) => e !== "_value");
288
+ return {
289
+ key: b(t),
290
+ name: t.name,
291
+ kind: x(t),
292
+ value: d(e.value),
293
+ ...n.length && { fields: d(Object.fromEntries(n.map((t) => [t, e[t]]))) }
294
+ };
295
+ })
296
+ } : null;
297
+ }
298
+ //#endregion
299
+ //#region src/devtools-bridge.ts
300
+ var T = class {
301
+ world;
302
+ id;
303
+ name;
304
+ #e = 0;
305
+ #t = [];
306
+ constructor(n, a, o) {
307
+ this.world = n, this.id = a, this.name = o;
308
+ let s = () => void this.#e++, c = (e) => this.#t.push(n.bus.subscribe(e, s));
309
+ c(t), c(e), c(r), c(i);
310
+ }
311
+ get worldInfo() {
312
+ return {
313
+ id: this.id,
314
+ name: this.name
315
+ };
316
+ }
317
+ info() {
318
+ let e = 0;
319
+ for (let t of this.world.entities.archetypes()) e += t.entities.size;
320
+ return {
321
+ ...this.worldInfo,
322
+ running: this.world.running,
323
+ revision: this.#e,
324
+ systems: this.world.systems.size,
325
+ entities: e
326
+ };
327
+ }
328
+ systems() {
329
+ return {
330
+ revision: this.#e,
331
+ graph: c(this.world.systems.describe())
332
+ };
333
+ }
334
+ components() {
335
+ return S(this.world);
336
+ }
337
+ entities(e) {
338
+ return C(this.world, e);
339
+ }
340
+ entity(e) {
341
+ return w(this.world, e);
342
+ }
343
+ resources() {
344
+ return this.world.container.list().map(({ name: e }, t) => ({
345
+ key: String(t),
346
+ name: e
347
+ }));
348
+ }
349
+ resource(e) {
350
+ let t = this.world.container.list()[Number(e)];
351
+ return t ? {
352
+ key: e,
353
+ name: t.name,
354
+ value: d(t.resource)
355
+ } : null;
356
+ }
357
+ [Symbol.dispose]() {
358
+ this.#t.splice(0).forEach((e) => e());
359
+ }
360
+ }, E = 1, D = "__BIM_ECS_DEVTOOLS__", O = [
361
+ "info",
362
+ "systems",
363
+ "components",
364
+ "entities",
365
+ "entity",
366
+ "resources",
367
+ "resource"
368
+ ];
369
+ //#endregion
370
+ //#region src/devtools-hook.ts
371
+ function k() {
372
+ let e = globalThis, t = e[D];
373
+ if (t && typeof t.attach == "function") return t;
374
+ let n = /* @__PURE__ */ new Map(), r = 0, i = {
375
+ protocol: 1,
376
+ worlds() {
377
+ return [...n.values()].map((e) => e.worldInfo);
378
+ },
379
+ call(e, t, r = []) {
380
+ let i = n.get(e);
381
+ if (!i) return {
382
+ ok: !1,
383
+ error: `Unknown world "${e}"`
384
+ };
385
+ if (!O.includes(t)) return {
386
+ ok: !1,
387
+ error: `Unknown method "${t}"`
388
+ };
389
+ try {
390
+ return {
391
+ ok: !0,
392
+ value: i[t](...r)
393
+ };
394
+ } catch (e) {
395
+ return {
396
+ ok: !1,
397
+ error: String(e)
398
+ };
399
+ }
400
+ },
401
+ attach(e) {
402
+ return n.set(e.id, e), () => void n.delete(e.id);
403
+ },
404
+ nextWorldNumber: () => ++r
405
+ };
406
+ return e[D] = i, i;
407
+ }
408
+ //#endregion
409
+ //#region src/devtools-plugin.ts
410
+ var A = /* @__PURE__ */ new WeakMap(), j = (e = {}) => (t) => {
411
+ let r = A.get(t);
412
+ if (r) return r;
413
+ let i = k(), a = i.nextWorldNumber(), o = new T(t, `world-${a}`, e.name ?? `World ${a}`);
414
+ A.set(t, o);
415
+ let s = i.attach(o);
416
+ return t.bus.subscribe(n, () => {
417
+ s(), o[Symbol.dispose](), A.delete(t);
418
+ }), o;
419
+ };
420
+ //#endregion
421
+ export { O as DEVTOOLS_API_METHODS, D as DEVTOOLS_HOOK_KEY, E as DEVTOOLS_PROTOCOL_VERSION, j as devtoolsPlugin, d as serializeValue };
422
+
423
+ //# sourceMappingURL=index.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.js","names":[],"sources":["../src/build-graph.ts","../src/serialize-value.ts","../src/inspect-entities.ts","../src/devtools-bridge.ts","../src/protocol.ts","../src/devtools-hook.ts","../src/devtools-plugin.ts"],"sourcesContent":["import type { SchedulerDescriptor, SystemDescriptor } from '@state-of-geneva/bim-ecs';\r\nimport type { GraphEdge, GraphEdgeKind, GraphNode, SystemsGraph } from './protocol';\r\n\r\n/** Kinds of schedulers whose nodes are shared: every system bound to the same thing is connected to the same node */\r\nconst SHARED_KINDS = new Set([\r\n 'startup',\r\n 'frame',\r\n 'component-added',\r\n 'component-removed',\r\n 'component-value-changed',\r\n 'entity-spawned',\r\n 'entity-removed',\r\n]);\r\n\r\n/**\r\n * Builds the systems graph from the systems descriptors.\r\n *\r\n * - Events, commands, components and queries are shared nodes, so the graph shows which systems react to the same thing\r\n * - Modifiers (`when`, `debounce`...) are private to the system they belong to\r\n * - The result only depends on the descriptors: registration order does not matter\r\n * @param systems The systems descriptors\r\n */\r\nexport function buildSystemsGraph(systems: readonly SystemDescriptor[]): SystemsGraph {\r\n const nodes = new Map<string, GraphNode>();\r\n const edges = new Map<string, GraphEdge>();\r\n\r\n const systemNodeId = (id: number) => `system:${id}`;\r\n\r\n const addNode = (node: GraphNode) => {\r\n if (!nodes.has(node.id)) nodes.set(node.id, node);\r\n return node.id;\r\n };\r\n\r\n const link = (from: string, to: string, kind: GraphEdgeKind) => {\r\n const id = `${from}>${to}:${kind}`;\r\n if (!edges.has(id)) edges.set(id, { id, from, to, kind });\r\n };\r\n\r\n /** Provides the node of a system, a placeholder is created when the system is not registered */\r\n const systemNode = (id: number) =>\r\n addNode({ id: systemNodeId(id), kind: 'system', label: `#${id}`, detail: 'not registered' });\r\n\r\n const addScheduler = (descriptor: SchedulerDescriptor, parent: string, path: string) => {\r\n switch (descriptor.kind) {\r\n case 'on':\r\n case 'at-command': {\r\n // One node per bound event / command\r\n const kind = descriptor.kind === 'on' ? 'event' : 'command';\r\n for (const label of descriptor.labels ?? []) {\r\n link(addNode({ id: `${kind}:${label}`, kind, label }), parent, 'schedule');\r\n }\r\n return;\r\n }\r\n\r\n case 'after': {\r\n const upstream = (descriptor.systems ?? []).map(systemNode);\r\n if (upstream.length === 1) {\r\n link(upstream[0], parent, 'after');\r\n } else {\r\n const junction = addNode({ id: path, kind: 'after', label: String(descriptor.params?.combination ?? 'or') });\r\n for (const source of upstream) link(source, junction, 'after');\r\n link(junction, parent, 'schedule');\r\n }\r\n return;\r\n }\r\n\r\n default: {\r\n const detail = descriptor.without?.length ? `without ${descriptor.without.join(', ')}` : undefined;\r\n const label = labelOf(descriptor);\r\n const id = SHARED_KINDS.has(descriptor.kind)\r\n ? `${descriptor.kind}:${label}${detail ? `|${detail}` : ''}`\r\n : path;\r\n\r\n const node = addNode({ id, kind: descriptor.kind, label, ...(detail && { detail }) });\r\n link(node, parent, 'schedule');\r\n descriptor.children?.forEach((child, index) => addScheduler(child, node, `${path}/${index}`));\r\n }\r\n }\r\n };\r\n\r\n // System nodes come first: placeholders are only created for missing upstream systems\r\n for (const system of systems) {\r\n addNode({\r\n id: systemNodeId(system.id),\r\n kind: 'system',\r\n label: system.name,\r\n system: { id: system.id, running: system.running, disposed: system.disposed },\r\n });\r\n }\r\n\r\n for (const system of systems) {\r\n const node = systemNodeId(system.id);\r\n addScheduler(system.scheduler, node, `${node}/scheduler`);\r\n\r\n if (system.then?.publish) {\r\n link(node, addNode({ id: `event:${system.then.publish}`, kind: 'event', label: system.then.publish }), 'publish');\r\n }\r\n if (system.then?.trigger) {\r\n link(\r\n node,\r\n addNode({ id: `command:${system.then.trigger}`, kind: 'command', label: system.then.trigger }),\r\n 'trigger',\r\n );\r\n }\r\n }\r\n\r\n return { nodes: [...nodes.values()], edges: [...edges.values()] };\r\n}\r\n\r\n/** Provides the name of the scheduler thing */\r\nfunction labelOf({ kind, labels, params }: SchedulerDescriptor) {\r\n if (labels?.length) return labels.join(', ');\r\n\r\n switch (kind) {\r\n case 'timer':\r\n case 'debounce':\r\n return `${params?.delay ?? '?'}ms`;\r\n case 'when':\r\n return String(params?.predicate ?? kind);\r\n default:\r\n return kind;\r\n }\r\n}\r\n","import type { SerializedValue } from './protocol';\r\n\r\nexport interface SerializeOptions {\r\n /** Maximum nesting depth (default: 4) */\r\n maxDepth?: number;\r\n /** Maximum number of entries/items kept per collection or object (default: 50) */\r\n maxEntries?: number;\r\n /** Maximum length of a string (default: 300) */\r\n maxStringLength?: number;\r\n /** Maximum number of nodes of the whole result (default: 1000), bounds the cost whatever the shape of the data is */\r\n maxNodes?: number;\r\n}\r\n\r\ntype Limits = Required<SerializeOptions>;\r\n\r\nconst DEFAULT_LIMITS: Limits = { maxDepth: 4, maxEntries: 50, maxStringLength: 300, maxNodes: 1000 };\r\n\r\n/**\r\n * Converts any value to a JSON-safe and bounded representation: it is safe to call on arbitrary application data\r\n * (cycles, DOM nodes, huge collections, throwing getters...) and its cost is capped by `maxNodes`.\r\n * @param value The value to serialize\r\n * @param options The limits\r\n */\r\nexport function serializeValue(value: unknown, options?: SerializeOptions): SerializedValue {\r\n const limits = { ...DEFAULT_LIMITS, ...options };\r\n return serialize(value, 0, new Set(), { remaining: limits.maxNodes }, limits);\r\n}\r\n\r\nfunction serialize(\r\n value: unknown,\r\n depth: number,\r\n ancestors: Set<object>,\r\n budget: { remaining: number },\r\n limits: Limits,\r\n): SerializedValue {\r\n switch (typeof value) {\r\n case 'string':\r\n return value.length > limits.maxStringLength ? `${value.slice(0, limits.maxStringLength)}…` : value;\r\n case 'number':\r\n if (Number.isFinite(value)) return value;\r\n return { $: 'number', v: Number.isNaN(value) ? 'NaN' : value > 0 ? 'Infinity' : '-Infinity' };\r\n case 'boolean':\r\n return value;\r\n case 'undefined':\r\n return { $: 'undefined' };\r\n case 'bigint':\r\n return { $: 'bigint', v: value.toString() };\r\n case 'symbol':\r\n return { $: 'symbol', v: value.toString() };\r\n case 'function':\r\n return { $: 'function', name: value.name || '(anonymous)' };\r\n }\r\n\r\n if (value === null) return null;\r\n\r\n const object = value as object;\r\n if (ancestors.has(object)) return { $: 'circular' };\r\n\r\n const cls = classNameOf(object);\r\n if (--budget.remaining < 0) return { $: 'truncated', cls };\r\n\r\n if (object instanceof Date) {\r\n return { $: 'date', v: Number.isNaN(object.getTime()) ? 'Invalid Date' : object.toISOString() };\r\n }\r\n const opaque = describeOpaque(object);\r\n if (opaque) return { $: 'opaque', cls, ...(opaque.desc !== undefined && { desc: opaque.desc }) };\r\n\r\n const isCollection = Array.isArray(object) || object instanceof Map || object instanceof Set;\r\n if (depth >= limits.maxDepth) {\r\n return { $: 'truncated', cls, ...(isCollection && { size: collectionSize(object) }) };\r\n }\r\n\r\n ancestors.add(object);\r\n try {\r\n const child = (item: unknown) => serialize(item, depth + 1, ancestors, budget, limits);\r\n\r\n if (Array.isArray(object)) {\r\n return { $: 'array', size: object.length, items: object.slice(0, limits.maxEntries).map(child) };\r\n }\r\n\r\n if (object instanceof Set) {\r\n return { $: 'set', size: object.size, items: take(object.values(), limits.maxEntries).map(child) };\r\n }\r\n\r\n if (object instanceof Map) {\r\n return {\r\n $: 'map',\r\n size: object.size,\r\n entries: take(object.entries(), limits.maxEntries).map(([k, v]) => [child(k), child(v)]),\r\n };\r\n }\r\n\r\n const keys = Object.keys(object);\r\n return {\r\n $: 'object',\r\n cls,\r\n size: keys.length,\r\n entries: keys.slice(0, limits.maxEntries).map((key): [string, SerializedValue] => {\r\n // Accessors are not invoked: they could have side effects or throw\r\n const descriptor = Object.getOwnPropertyDescriptor(object, key);\r\n return [key, descriptor && 'value' in descriptor ? child(descriptor.value) : { $: 'opaque', cls: 'Getter' }];\r\n }),\r\n };\r\n } catch (error) {\r\n // Exotic objects (revoked proxies...)\r\n return { $: 'opaque', cls, desc: `unreadable: ${String(error)}` };\r\n } finally {\r\n ancestors.delete(object);\r\n }\r\n}\r\n\r\n/** Provides the constructor name of an object, `Object` when it has no prototype */\r\nfunction classNameOf(object: object) {\r\n try {\r\n return (Object.getPrototypeOf(object)?.constructor?.name as string | undefined) || 'Object';\r\n } catch {\r\n return 'Object';\r\n }\r\n}\r\n\r\nfunction collectionSize(object: object) {\r\n return Array.isArray(object) ? object.length : (object as Map<unknown, unknown> | Set<unknown>).size;\r\n}\r\n\r\n/** Takes up to `count` items of an iterator */\r\nfunction take<T>(iterator: Iterator<T>, count: number) {\r\n const items: T[] = [];\r\n for (let item = iterator.next(); !item.done && items.length < count; item = iterator.next()) items.push(item.value);\r\n return items;\r\n}\r\n\r\n/** Determines whether the object is not worth (or not safe) to inspect, and provides a short description if so */\r\nfunction describeOpaque(object: object): { desc?: string } | undefined {\r\n if (typeof Node !== 'undefined' && object instanceof Node) return { desc: object.nodeName };\r\n if (typeof Window !== 'undefined' && object instanceof Window) return {};\r\n if (object instanceof Error) return { desc: object.message };\r\n if (object instanceof RegExp) return { desc: String(object) };\r\n if (object instanceof Promise) return {};\r\n if (object instanceof WeakMap || object instanceof WeakSet) return {};\r\n if (typeof WeakRef !== 'undefined' && object instanceof WeakRef) return {};\r\n if (object instanceof ArrayBuffer) return { desc: `${object.byteLength} bytes` };\r\n if (ArrayBuffer.isView(object)) return { desc: `${object.byteLength} bytes` };\r\n\r\n return undefined;\r\n}\r\n","import { EcsIndexedComponent, EcsMutableComponent, type EcsComponent, type EcsWorld } from '@state-of-geneva/bim-ecs';\r\nimport type {\r\n ArchetypeInfo,\r\n ComponentKind,\r\n ComponentsSnapshot,\r\n ComponentTypeInfo,\r\n EntitiesPage,\r\n EntitiesQuery,\r\n EntityDetail,\r\n EntitySummary,\r\n} from './protocol';\r\nimport { serializeValue } from './serialize-value';\r\n\r\ntype ComponentType = typeof EcsComponent<any>;\r\n\r\nconst DEFAULT_PAGE_SIZE = 100;\r\n\r\n/** Component type keys: component classes are global, so are their keys */\r\nconst componentTypeKeys = new WeakMap<ComponentType, string>();\r\nlet componentTypeKeyCounter = 0;\r\n\r\n/**\r\n * Provides the stable identifier of a component type. Names are not identifiers: two classes can share the same one.\r\n * @param type The component type\r\n */\r\nexport function componentTypeKey(type: ComponentType) {\r\n let key = componentTypeKeys.get(type);\r\n if (key === undefined) componentTypeKeys.set(type, (key = `c${componentTypeKeyCounter++}`));\r\n return key;\r\n}\r\n\r\nfunction componentKindOf(type: ComponentType): ComponentKind {\r\n if (type.prototype instanceof EcsMutableComponent) return 'mutable';\r\n if (type.prototype instanceof EcsIndexedComponent) return 'indexed';\r\n return 'component';\r\n}\r\n\r\n/**\r\n * Describes the component types and the archetypes of the world.\r\n * The cost is proportional to the number of archetypes, not to the number of entities.\r\n * @param world The world\r\n */\r\nexport function inspectComponents(world: EcsWorld): ComponentsSnapshot {\r\n const countsByType = new Map<ComponentType, number>();\r\n const archetypes: ArchetypeInfo[] = [];\r\n let entities = 0;\r\n\r\n for (const archetype of world.entities.archetypes()) {\r\n const count = archetype.entities.size;\r\n entities += count;\r\n\r\n for (const type of archetype.components) countsByType.set(type, (countsByType.get(type) ?? 0) + count);\r\n\r\n const components = archetype.components.map(componentTypeKey).sort();\r\n archetypes.push({ key: components.join('+'), components, entities: count });\r\n }\r\n\r\n const types: ComponentTypeInfo[] = [...countsByType].map(([type, count]) => ({\r\n key: componentTypeKey(type),\r\n name: type.name,\r\n kind: componentKindOf(type),\r\n entities: count,\r\n }));\r\n\r\n types.sort((a, b) => b.entities - a.entities || a.name.localeCompare(b.name));\r\n archetypes.sort((a, b) => b.entities - a.entities || a.key.localeCompare(b.key));\r\n\r\n return { entities, types, archetypes };\r\n}\r\n\r\n/**\r\n * Lists the entities matching the query, page by page.\r\n * Archetypes are filtered first, so the cost does not depend on the number of entities outside the requested page.\r\n * @param world The world\r\n * @param query The filter and the page\r\n */\r\nexport function inspectEntities(world: EcsWorld, query: EntitiesQuery = {}): EntitiesPage {\r\n const { with: required = [], without: excluded = [], limit = DEFAULT_PAGE_SIZE } = query;\r\n const entities: EntitySummary[] = [];\r\n let remainingOffset = Math.max(0, query.offset ?? 0);\r\n let total = 0;\r\n\r\n for (const archetype of world.entities.archetypes()) {\r\n const components = archetype.components.map(componentTypeKey);\r\n if (!required.every((key) => components.includes(key)) || excluded.some((key) => components.includes(key)))\r\n continue;\r\n\r\n const size = archetype.entities.size;\r\n total += size;\r\n\r\n if (entities.length >= limit) continue;\r\n if (remainingOffset >= size) {\r\n remainingOffset -= size;\r\n continue;\r\n }\r\n\r\n let skipped = 0;\r\n for (const id of archetype.entities) {\r\n if (skipped++ < remainingOffset) continue;\r\n entities.push({ id, components });\r\n if (entities.length >= limit) break;\r\n }\r\n remainingOffset = 0;\r\n }\r\n\r\n return { total, entities };\r\n}\r\n\r\n/**\r\n * Details an entity: its components and their values\r\n * @param world The world\r\n * @param id The entity identifier\r\n */\r\nexport function inspectEntity(world: EcsWorld, id: number): EntityDetail | null {\r\n const components = world.entities.pool.componentsByEntity.get(id);\r\n if (!components) return null;\r\n\r\n return {\r\n id,\r\n components: [...components].map((component) => {\r\n const type = component.constructor as ComponentType;\r\n\r\n // Own fields other than the value (components can be extended with some)\r\n const extra = Object.keys(component).filter((key) => key !== '_value');\r\n\r\n return {\r\n key: componentTypeKey(type),\r\n name: type.name,\r\n kind: componentKindOf(type),\r\n value: serializeValue(component.value),\r\n ...(extra.length && {\r\n fields: serializeValue(Object.fromEntries(extra.map((key) => [key, (component as any)[key]]))),\r\n }),\r\n };\r\n }),\r\n };\r\n}\r\n","import {\r\n ECS_SYSTEM_DISPOSED_EVENT,\r\n ECS_SYSTEM_REGISTERED_EVENT,\r\n ECS_WORLD_RUNNING_EVENT,\r\n ECS_WORLD_STOPPING_EVENT,\r\n type EcsEvent,\r\n type EcsWorld,\r\n} from '@state-of-geneva/bim-ecs';\r\nimport type {\r\n ComponentsSnapshot,\r\n DevtoolsApi,\r\n EntitiesPage,\r\n EntitiesQuery,\r\n EntityDetail,\r\n ResourceDetail,\r\n ResourceInfo,\r\n SystemsSnapshot,\r\n WorldInfo,\r\n WorldState,\r\n} from './protocol';\r\nimport { buildSystemsGraph } from './build-graph';\r\nimport { inspectComponents, inspectEntities, inspectEntity } from './inspect-entities';\r\nimport { serializeValue } from './serialize-value';\r\n\r\n/**\r\n * Answers the questions of a devtools consumer about a world.\r\n *\r\n * Everything is computed on demand: while nobody asks, the only runtime cost is a revision counter bumped on the few\r\n * events altering the systems structure or state. Systems processing, entities and queries are never instrumented.\r\n */\r\nexport class DevtoolsBridge implements DevtoolsApi, Disposable {\r\n #revision = 0;\r\n readonly #unsubscribes: Array<() => void> = [];\r\n\r\n constructor(\r\n private readonly world: EcsWorld,\r\n public readonly id: string,\r\n public readonly name: string,\r\n ) {\r\n const bump = () => void this.#revision++;\r\n const watch = (event: EcsEvent<any>) => this.#unsubscribes.push(world.bus.subscribe(event, bump));\r\n\r\n watch(ECS_SYSTEM_REGISTERED_EVENT);\r\n watch(ECS_SYSTEM_DISPOSED_EVENT);\r\n watch(ECS_WORLD_RUNNING_EVENT);\r\n watch(ECS_WORLD_STOPPING_EVENT);\r\n }\r\n\r\n /** Identifies the world */\r\n public get worldInfo(): WorldInfo {\r\n return { id: this.id, name: this.name };\r\n }\r\n\r\n /** @inheritdoc */\r\n public info(): WorldState {\r\n let entities = 0;\r\n for (const archetype of this.world.entities.archetypes()) entities += archetype.entities.size;\r\n\r\n return {\r\n ...this.worldInfo,\r\n running: this.world.running,\r\n revision: this.#revision,\r\n systems: this.world.systems.size,\r\n entities,\r\n };\r\n }\r\n\r\n /** @inheritdoc */\r\n public systems(): SystemsSnapshot {\r\n return { revision: this.#revision, graph: buildSystemsGraph(this.world.systems.describe()) };\r\n }\r\n\r\n /** @inheritdoc */\r\n public components(): ComponentsSnapshot {\r\n return inspectComponents(this.world);\r\n }\r\n\r\n /** @inheritdoc */\r\n public entities(query?: EntitiesQuery): EntitiesPage {\r\n return inspectEntities(this.world, query);\r\n }\r\n\r\n /** @inheritdoc */\r\n public entity(id: number): EntityDetail | null {\r\n return inspectEntity(this.world, id);\r\n }\r\n\r\n /** @inheritdoc */\r\n public resources(): ResourceInfo[] {\r\n return this.world.container.list().map(({ name }, index) => ({ key: String(index), name }));\r\n }\r\n\r\n /** @inheritdoc */\r\n public resource(key: string): ResourceDetail | null {\r\n // Resources are only appended: indexes are stable keys\r\n const entry = this.world.container.list()[Number(key)];\r\n return entry ? { key, name: entry.name, value: serializeValue(entry.resource) } : null;\r\n }\r\n\r\n /** @inheritdoc */\r\n [Symbol.dispose]() {\r\n this.#unsubscribes.splice(0).forEach((unsubscribe) => unsubscribe());\r\n }\r\n}\r\n","/**\r\n * The contract between the devtools plugin and any consumer (browser extension, in-page overlay, tests...).\r\n * Everything crossing this boundary is plain JSON: no class instance, no symbol, no presentation concern.\r\n */\r\n\r\n/** Version of the contract. Incremented on breaking changes, consumers are expected to check it. */\r\nexport const DEVTOOLS_PROTOCOL_VERSION = 1;\r\n\r\n/** Name of the global through which consumers discover the registered worlds */\r\nexport const DEVTOOLS_HOOK_KEY = '__BIM_ECS_DEVTOOLS__';\r\n\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n// Values\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n\r\n/** A JSON-safe, bounded representation of any runtime value */\r\nexport type SerializedValue =\r\n | null\r\n | boolean\r\n | number\r\n | string\r\n | { $: 'undefined' }\r\n | { $: 'number'; v: 'NaN' | 'Infinity' | '-Infinity' }\r\n | { $: 'bigint'; v: string }\r\n | { $: 'symbol'; v: string }\r\n | { $: 'function'; name: string }\r\n | { $: 'date'; v: string }\r\n /** `size` is the real size: it is greater than the number of items when the collection has been truncated */\r\n | { $: 'array'; size: number; items: SerializedValue[] }\r\n | { $: 'set'; size: number; items: SerializedValue[] }\r\n | { $: 'map'; size: number; entries: [SerializedValue, SerializedValue][] }\r\n | { $: 'object'; cls: string; size: number; entries: [string, SerializedValue][] }\r\n /** A value which is not inspected: DOM nodes, promises, weak collections, getters... */\r\n | { $: 'opaque'; cls: string; desc?: string }\r\n | { $: 'circular' }\r\n /** The depth or the node budget has been reached */\r\n | { $: 'truncated'; cls?: string; size?: number };\r\n\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n// Worlds\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n\r\n/** Identifies a world registered on the hook */\r\nexport interface WorldInfo {\r\n id: string;\r\n name: string;\r\n}\r\n\r\n/** The state of a world: cheap to compute, meant to be polled */\r\nexport interface WorldState extends WorldInfo {\r\n running: boolean;\r\n /** Changes whenever the systems structure or state changes: the cue to fetch `systems()` again */\r\n revision: number;\r\n systems: number;\r\n entities: number;\r\n}\r\n\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n// Systems\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n\r\n/**\r\n * Kind of a graph node: `system`, `event`, `command` or the kind of a scheduler (`startup`, `frame`, `timer`,\r\n * `component-added`, `component-removed`, `component-value-changed`, `entity-spawned`, `entity-removed`, `after`,\r\n * `when`, `debounce`, `debounce-frame`, `compose`, `custom`...). Consumers must tolerate unknown kinds.\r\n */\r\nexport type GraphNodeKind = string;\r\n\r\nexport interface GraphNode {\r\n /** Unique, stable across snapshots as long as the structure does not change */\r\n id: string;\r\n kind: GraphNodeKind;\r\n /** The name of the thing: system name, event name, component name, delay... */\r\n label: string;\r\n /** Secondary information, e.g. the components a query excludes */\r\n detail?: string;\r\n /** Only for `system` nodes registered in the world */\r\n system?: { id: number; running: boolean; disposed: boolean };\r\n}\r\n\r\n/**\r\n * - `schedule`: the source triggers the target (event, command, component change, startup... or a modifier chain)\r\n * - `after`: the target runs once the source system has been processed\r\n * - `publish`: the system publishes the event when processed\r\n * - `trigger`: the system triggers the command when processed\r\n */\r\nexport type GraphEdgeKind = 'schedule' | 'after' | 'publish' | 'trigger';\r\n\r\nexport interface GraphEdge {\r\n id: string;\r\n from: string;\r\n to: string;\r\n kind: GraphEdgeKind;\r\n}\r\n\r\nexport interface SystemsGraph {\r\n nodes: GraphNode[];\r\n edges: GraphEdge[];\r\n}\r\n\r\nexport interface SystemsSnapshot {\r\n revision: number;\r\n graph: SystemsGraph;\r\n}\r\n\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n// Components & entities\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n\r\nexport type ComponentKind = 'component' | 'mutable' | 'indexed';\r\n\r\nexport interface ComponentTypeInfo {\r\n /** Stable identifier of the component type, used to filter entities */\r\n key: string;\r\n name: string;\r\n kind: ComponentKind;\r\n /** The number of entities holding the component type */\r\n entities: number;\r\n}\r\n\r\nexport interface ArchetypeInfo {\r\n key: string;\r\n /** The component type keys of the archetype */\r\n components: string[];\r\n entities: number;\r\n}\r\n\r\nexport interface ComponentsSnapshot {\r\n /** The total number of entities */\r\n entities: number;\r\n types: ComponentTypeInfo[];\r\n archetypes: ArchetypeInfo[];\r\n}\r\n\r\nexport interface EntitiesQuery {\r\n /** Component type keys the entities must hold */\r\n with?: string[];\r\n /** Component type keys the entities must not hold */\r\n without?: string[];\r\n /** Defaults to 0 */\r\n offset?: number;\r\n /** Defaults to 100 */\r\n limit?: number;\r\n}\r\n\r\nexport interface EntitySummary {\r\n id: number;\r\n /** The component type keys of the entity */\r\n components: string[];\r\n}\r\n\r\nexport interface EntitiesPage {\r\n /** The number of entities matching the query, whatever the page is */\r\n total: number;\r\n entities: EntitySummary[];\r\n}\r\n\r\nexport interface EntityComponentDetail {\r\n key: string;\r\n name: string;\r\n kind: ComponentKind;\r\n value: SerializedValue;\r\n /** Additional own fields of the component, when it defines some */\r\n fields?: SerializedValue;\r\n}\r\n\r\nexport interface EntityDetail {\r\n id: number;\r\n components: EntityComponentDetail[];\r\n}\r\n\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n// Resources\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n\r\nexport interface ResourceInfo {\r\n key: string;\r\n name: string;\r\n}\r\n\r\nexport interface ResourceDetail extends ResourceInfo {\r\n value: SerializedValue;\r\n}\r\n\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n// API\r\n// ---------------------------------------------------------------------------------------------------------------------\r\n\r\n/** What a consumer can ask to a world. Every method is synchronous and returns JSON-safe data. */\r\nexport interface DevtoolsApi {\r\n info(): WorldState;\r\n systems(): SystemsSnapshot;\r\n components(): ComponentsSnapshot;\r\n entities(query?: EntitiesQuery): EntitiesPage;\r\n /** `null` when the entity does not exist */\r\n entity(id: number): EntityDetail | null;\r\n resources(): ResourceInfo[];\r\n /** `null` when the resource does not exist anymore */\r\n resource(key: string): ResourceDetail | null;\r\n}\r\n\r\n/** Names of the `DevtoolsApi` methods */\r\nexport const DEVTOOLS_API_METHODS = [\r\n 'info',\r\n 'systems',\r\n 'components',\r\n 'entities',\r\n 'entity',\r\n 'resources',\r\n 'resource',\r\n] as const satisfies ReadonlyArray<keyof DevtoolsApi>;\r\n\r\nexport type DevtoolsApiMethod = (typeof DEVTOOLS_API_METHODS)[number];\r\n\r\n/** Outcome of a call through the hook: errors travel as data, so they are never lost between contexts */\r\nexport type DevtoolsCallResult<T = unknown> = { ok: true; value: T } | { ok: false; error: string };\r\n\r\n/** The global object registered on `globalThis[DEVTOOLS_HOOK_KEY]` */\r\nexport interface DevtoolsHook {\r\n readonly protocol: number;\r\n /** The worlds currently registered */\r\n worlds(): WorldInfo[];\r\n /** The single entry point for consumers evaluating code in the page */\r\n call(worldId: string, method: DevtoolsApiMethod, args?: unknown[]): DevtoolsCallResult;\r\n}\r\n","import {\r\n DEVTOOLS_API_METHODS,\r\n DEVTOOLS_HOOK_KEY,\r\n DEVTOOLS_PROTOCOL_VERSION,\r\n type DevtoolsApiMethod,\r\n type DevtoolsCallResult,\r\n type DevtoolsHook,\r\n type WorldInfo,\r\n} from './protocol';\r\nimport type { DevtoolsBridge } from './devtools-bridge';\r\n\r\n/** The hook, with the members only plugin instances are expected to use */\r\nexport interface DevtoolsHostHook extends DevtoolsHook {\r\n /** Registers a bridge, returns the function unregistering it */\r\n attach(bridge: DevtoolsBridge): () => void;\r\n /** Provides the next world number: a hook shared by several plugin copies must keep identifiers unique */\r\n nextWorldNumber(): number;\r\n}\r\n\r\n/** Provides the hook of the page, creating it when it does not exist yet */\r\nexport function getOrCreateHook(): DevtoolsHostHook {\r\n const host = globalThis as Record<string, any>;\r\n const existing = host[DEVTOOLS_HOOK_KEY] as DevtoolsHostHook | undefined;\r\n if (existing && typeof existing.attach === 'function') return existing;\r\n\r\n const bridges = new Map<string, DevtoolsBridge>();\r\n let worldCounter = 0;\r\n\r\n const hook: DevtoolsHostHook = {\r\n protocol: DEVTOOLS_PROTOCOL_VERSION,\r\n\r\n worlds(): WorldInfo[] {\r\n return [...bridges.values()].map((bridge) => bridge.worldInfo);\r\n },\r\n\r\n call(worldId, method, args = []): DevtoolsCallResult {\r\n const bridge = bridges.get(worldId);\r\n if (!bridge) return { ok: false, error: `Unknown world \"${worldId}\"` };\r\n if (!DEVTOOLS_API_METHODS.includes(method)) return { ok: false, error: `Unknown method \"${method}\"` };\r\n\r\n try {\r\n return { ok: true, value: (bridge[method as DevtoolsApiMethod] as (...args: unknown[]) => unknown)(...args) };\r\n } catch (error) {\r\n return { ok: false, error: String(error) };\r\n }\r\n },\r\n\r\n attach(bridge) {\r\n bridges.set(bridge.id, bridge);\r\n return () => void bridges.delete(bridge.id);\r\n },\r\n\r\n nextWorldNumber: () => ++worldCounter,\r\n };\r\n\r\n host[DEVTOOLS_HOOK_KEY] = hook;\r\n return hook;\r\n}\r\n","import { ECS_WORLD_DISPOSING_EVENT, type EcsWorld } from '@state-of-geneva/bim-ecs';\r\nimport { DevtoolsBridge } from './devtools-bridge';\r\nimport { getOrCreateHook } from './devtools-hook';\r\n\r\nexport interface DevtoolsPluginOptions {\r\n /** The name displayed by devtools to identify the world (default: `World <n>`) */\r\n name?: string;\r\n}\r\n\r\n/** Bridges already installed: installing the plugin twice on a world must not register it twice */\r\nconst installedBridges = new WeakMap<EcsWorld, DevtoolsBridge>();\r\n\r\n/**\r\n * Exposes the systems, components, entities and resources of the world to devtools (e.g. the browser extension),\r\n * through the `__BIM_ECS_DEVTOOLS__` global. Nothing is computed until devtools ask for it.\r\n *\r\n * @example\r\n * if (import.meta.env.DEV) world.use(devtoolsPlugin({ name: 'Game' }));\r\n *\r\n * @param options The plugin options\r\n * @returns The plugin, which returns the bridge answering to devtools when applied (useful for tests and custom\r\n * transports)\r\n */\r\nexport const devtoolsPlugin =\r\n (options: DevtoolsPluginOptions = {}) =>\r\n (world: EcsWorld): DevtoolsBridge => {\r\n const installed = installedBridges.get(world);\r\n if (installed) return installed;\r\n\r\n const hook = getOrCreateHook();\r\n const worldNumber = hook.nextWorldNumber();\r\n const bridge = new DevtoolsBridge(world, `world-${worldNumber}`, options.name ?? `World ${worldNumber}`);\r\n installedBridges.set(world, bridge);\r\n\r\n const detach = hook.attach(bridge);\r\n world.bus.subscribe(ECS_WORLD_DISPOSING_EVENT, () => {\r\n detach();\r\n bridge[Symbol.dispose]();\r\n installedBridges.delete(world);\r\n });\r\n\r\n return bridge;\r\n };\r\n"],"mappings":";;AAIA,IAAM,oBAAe,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAUD,SAAgB,EAAkB,GAAoD;CACpF,IAAM,oBAAQ,IAAI,IAAuB,GACnC,oBAAQ,IAAI,IAAuB,GAEnC,KAAgB,MAAe,UAAU,KAEzC,KAAW,OACV,EAAM,IAAI,EAAK,EAAE,KAAG,EAAM,IAAI,EAAK,IAAI,CA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K,GAAS,GAAQ,IAAO,CAAC,GAAuB;GACnD,IAAM,IAAS,EAAQ,IAAI,CAAO;GAClC,IAAI,CAAC,GAAQ,OAAO;IAAE,IAAI;IAAO,OAAO,kBAAkB,EAAQ;GAAG;GACrE,IAAI,CAAC,EAAqB,SAAS,CAAM,GAAG,OAAO;IAAE,IAAI;IAAO,OAAO,mBAAmB,EAAO;GAAG;GAEpG,IAAI;IACF,OAAO;KAAE,IAAI;KAAM,OAAQ,EAAO,EAA4B,CAAqC,GAAG,CAAI;IAAE;GAC9G,SAAS,GAAO;IACd,OAAO;KAAE,IAAI;KAAO,OAAO,OAAO,CAAK;IAAE;GAC3C;EACF;EAEA,OAAO,GAAQ;GAEb,OADA,EAAQ,IAAI,EAAO,IAAI,CAAM,SAChB,KAAK,EAAQ,OAAO,EAAO,EAAE;EAC5C;EAEA,uBAAuB,EAAE;CAC3B;CAGA,OADA,EAAK,KAAqB,GACnB;AACT;;;AC/CA,IAAM,oBAAmB,IAAI,QAAkC,GAalD,KACV,IAAiC,CAAC,OAClC,MAAoC;CACnC,IAAM,IAAY,EAAiB,IAAI,CAAK;CAC5C,IAAI,GAAW,OAAO;CAEtB,IAAM,IAAO,EAAgB,GACvB,IAAc,EAAK,gBAAgB,GACnC,IAAS,IAAI,EAAe,GAAO,SAAS,KAAe,EAAQ,QAAQ,SAAS,GAAa;CACvG,EAAiB,IAAI,GAAO,CAAM;CAElC,IAAM,IAAS,EAAK,OAAO,CAAM;CAOjC,OANA,EAAM,IAAI,UAAU,SAAiC;EAGnD,AAFA,EAAO,GACP,EAAO,OAAO,QAAQ,CAAC,GACvB,EAAiB,OAAO,CAAK;CAC/B,CAAC,GAEM;AACT"}
@@ -0,0 +1,28 @@
1
+ import { EcsComponent, EcsWorld } from '@state-of-geneva/bim-ecs';
2
+ import { ComponentsSnapshot, EntitiesPage, EntitiesQuery, EntityDetail } from './protocol';
3
+ type ComponentType = typeof EcsComponent<any>;
4
+ /**
5
+ * Provides the stable identifier of a component type. Names are not identifiers: two classes can share the same one.
6
+ * @param type The component type
7
+ */
8
+ export declare function componentTypeKey(type: ComponentType): string;
9
+ /**
10
+ * Describes the component types and the archetypes of the world.
11
+ * The cost is proportional to the number of archetypes, not to the number of entities.
12
+ * @param world The world
13
+ */
14
+ export declare function inspectComponents(world: EcsWorld): ComponentsSnapshot;
15
+ /**
16
+ * Lists the entities matching the query, page by page.
17
+ * Archetypes are filtered first, so the cost does not depend on the number of entities outside the requested page.
18
+ * @param world The world
19
+ * @param query The filter and the page
20
+ */
21
+ export declare function inspectEntities(world: EcsWorld, query?: EntitiesQuery): EntitiesPage;
22
+ /**
23
+ * Details an entity: its components and their values
24
+ * @param world The world
25
+ * @param id The entity identifier
26
+ */
27
+ export declare function inspectEntity(world: EcsWorld, id: number): EntityDetail | null;
28
+ export {};