@oasys/oecs 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +108 -1
  2. package/README.md +20 -8
  3. package/dist/core/ecs/archetype.d.cts +3 -3
  4. package/dist/core/ecs/archetype.d.ts +3 -3
  5. package/dist/core/ecs/component.d.cts +25 -0
  6. package/dist/core/ecs/component.d.ts +25 -0
  7. package/dist/core/ecs/component.d.ts.map +1 -1
  8. package/dist/core/ecs/ecs.d.cts +67 -49
  9. package/dist/core/ecs/ecs.d.ts +67 -49
  10. package/dist/core/ecs/ecs.d.ts.map +1 -1
  11. package/dist/core/ecs/entity.d.cts +1 -1
  12. package/dist/core/ecs/entity.d.ts +1 -1
  13. package/dist/core/ecs/facades.d.cts +1 -1
  14. package/dist/core/ecs/facades.d.ts +1 -1
  15. package/dist/core/ecs/host_commands.d.cts +30 -20
  16. package/dist/core/ecs/host_commands.d.ts +30 -20
  17. package/dist/core/ecs/host_commands.d.ts.map +1 -1
  18. package/dist/core/ecs/index.d.cts +3 -3
  19. package/dist/core/ecs/index.d.ts +3 -3
  20. package/dist/core/ecs/index.d.ts.map +1 -1
  21. package/dist/core/ecs/observer.d.cts +1 -1
  22. package/dist/core/ecs/observer.d.ts +1 -1
  23. package/dist/core/ecs/observer.d.ts.map +1 -1
  24. package/dist/core/ecs/query.d.cts +22 -6
  25. package/dist/core/ecs/query.d.ts +22 -6
  26. package/dist/core/ecs/query.d.ts.map +1 -1
  27. package/dist/core/ecs/ref.d.ts.map +1 -1
  28. package/dist/core/ecs/run_condition.d.cts +1 -1
  29. package/dist/core/ecs/run_condition.d.ts +1 -1
  30. package/dist/core/ecs/run_condition.d.ts.map +1 -1
  31. package/dist/core/ecs/store.d.cts +10 -23
  32. package/dist/core/ecs/store.d.ts +10 -23
  33. package/dist/core/ecs/store.d.ts.map +1 -1
  34. package/dist/dev_flag.d.cts +0 -15
  35. package/dist/dev_flag.d.ts +0 -15
  36. package/dist/dev_flag.d.ts.map +1 -1
  37. package/dist/extensions/editor/editor.d.cts +31 -29
  38. package/dist/extensions/editor/editor.d.ts +31 -29
  39. package/dist/extensions/editor/editor.d.ts.map +1 -1
  40. package/dist/extensions/editor/field_handle.d.cts +3 -3
  41. package/dist/extensions/editor/field_handle.d.ts +3 -3
  42. package/dist/extensions/editor/field_handle.d.ts.map +1 -1
  43. package/dist/extensions/editor/index.cjs +1 -1
  44. package/dist/extensions/editor/index.development.cjs +1 -0
  45. package/dist/extensions/editor/index.development.js +239 -0
  46. package/dist/extensions/editor/index.js +53 -51
  47. package/dist/extensions/reactive/index.development.cjs +1 -0
  48. package/dist/extensions/reactive/index.development.js +215 -0
  49. package/dist/extensions/solid/index.development.cjs +1 -0
  50. package/dist/extensions/solid/index.development.js +40 -0
  51. package/dist/{host_commands-i4cAeyL5.js → host_commands-BI8pEmjH.js} +26 -18
  52. package/dist/{host_commands-BF8QMi3c.cjs → host_commands-CxhpzMx9.cjs} +1 -1
  53. package/dist/index.cjs +1 -1
  54. package/dist/index.d.cts +3 -3
  55. package/dist/index.d.ts +3 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.development.cjs +1 -0
  58. package/dist/index.development.js +8116 -0
  59. package/dist/index.js +269 -214
  60. package/dist/internal-BMDgWZbt.js +2485 -0
  61. package/dist/internal-LiTSB_tG.cjs +2 -0
  62. package/dist/internal.cjs +1 -1
  63. package/dist/internal.development.cjs +1 -0
  64. package/dist/internal.development.js +24 -0
  65. package/dist/internal.js +1 -1
  66. package/dist/interop-DqxleBo7.js +18 -0
  67. package/dist/interop-T1HZ-Dpa.cjs +1 -0
  68. package/dist/kernel-Cz2Kxlwl.js +240 -0
  69. package/dist/kernel-sw7ScKWu.cjs +1 -0
  70. package/dist/primitives.development.cjs +1 -0
  71. package/dist/primitives.development.js +45 -0
  72. package/dist/reactive/index.development.cjs +1 -0
  73. package/dist/reactive/index.development.js +18 -0
  74. package/dist/shallow-9S1pY_Iw.js +159 -0
  75. package/dist/shallow-C5YmTbtb.cjs +1 -0
  76. package/dist/shared.development.cjs +1 -0
  77. package/dist/shared.development.js +7 -0
  78. package/dist/version.d.cts +1 -1
  79. package/dist/version.d.ts +1 -1
  80. package/package.json +31 -2
@@ -5,7 +5,7 @@ import { ComponentDef, ComponentHandle, ComponentSchema, EntityID, CompleteField
5
5
  * to the reactive read channel (e.g. a `reactiveMap`/`reactiveStruct` projection)
6
6
  * or to `ecs.getField`; `undefined` for an unknown slot falls back to `0`.
7
7
  */
8
- export type FieldReader = (eid: EntityID, def: ComponentDef, field: string) => number | undefined;
8
+ export type FieldReader = (entityId: EntityID, def: ComponentDef, field: string) => number | undefined;
9
9
  /**
10
10
  * A reified, undoable unit of editor work: the `forward` commands and their
11
11
  * `inverse`, both plain `HostCommand` data on the one bus. The arrays are mutable
@@ -42,33 +42,35 @@ export declare class TransactionBuilder {
42
42
  * also forwards the new id to the caller. The finalizer re-fires on redo, so the
43
43
  * inverse tracks the current id.
44
44
  */
45
- spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (eid: EntityID) => void): this;
45
+ spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (entityId: EntityID) => void): this;
46
46
  /**
47
- * Despawn `eid`. Inverse: respawn from `restore` (the components+values to
47
+ * Despawn `entityId`. Inverse: respawn from `restore` (the components+values to
48
48
  * recreate — read them from the channel before despawning). Undo respawns the
49
49
  * DATA, not the identity: the new entity gets a fresh id, and the respawn's
50
50
  * `onSpawned` rewrites this despawn's target so redo removes the respawned
51
51
  * entity rather than the dead original.
52
52
  */
53
- despawn<Defs extends readonly ComponentDef[]>(eid: EntityID, restore: SpawnEntries<Defs>): this;
53
+ despawn<Defs extends readonly ComponentDef[]>(entityId: EntityID, restore: SpawnEntries<Defs>): this;
54
54
  /**
55
- * Set `field` of `def` on `eid` to `value`. Inverse: set it back to the value
55
+ * Set `field` of `def` on `entityId` to `value`. Inverse: set it back to the value
56
56
  * this edit replaced — read from the staged overlay / shadow (so stacked edits,
57
57
  * within one build or before a commit, invert correctly) or, failing that, the
58
58
  * read channel (`0` if unknown).
59
59
  */
60
- setField<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): this;
61
- /** Add `def` (with complete `values`) to `eid`. Inverse: remove it. */
62
- addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
60
+ setField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): this;
61
+ /** Attach `def` (with complete `values`) to `entityId`. Inverse: remove it.
62
+ * Bare `add` the namespaced-handle grammar (matches `ctx.commands.add` and
63
+ * the queue's `add`), not `addComponent`. */
64
+ add<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
63
65
  /**
64
- * Remove `def` from `eid`. Inverse: re-add it from `restore` (the field values
65
- * to recreate — read them from the channel before removing).
66
+ * Detach `def` from `entityId`. Inverse: re-add it from `restore` (the field values
67
+ * to recreate — read them from the channel before removing). Bare `remove` — see `add`.
66
68
  */
67
- removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): this;
68
- /** Disable `eid`. Inverse: enable it. */
69
- disable(eid: EntityID): this;
70
- /** Enable `eid`. Inverse: disable it. */
71
- enable(eid: EntityID): this;
69
+ remove<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): this;
70
+ /** Disable `entityId`. Inverse: enable it. */
71
+ disable(entityId: EntityID): this;
72
+ /** Enable `entityId`. Inverse: disable it. */
73
+ enable(entityId: EntityID): this;
72
74
  }
73
75
  /**
74
76
  * The editor's undo/redo manager over a {@link HostCommandQueue}. Each action is a
@@ -97,19 +99,19 @@ export declare class Editor {
97
99
  */
98
100
  transaction(build: (tx: TransactionBuilder) => void): EditorTransaction;
99
101
  /** Spawn `components` as its own undo entry. `onSpawned` reports the new id. */
100
- spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (eid: EntityID) => void): EditorTransaction;
101
- /** Despawn `eid` as its own undo entry; `restore` recreates it on undo. */
102
- despawn<Defs extends readonly ComponentDef[]>(eid: EntityID, restore: SpawnEntries<Defs>): EditorTransaction;
102
+ spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (entityId: EntityID) => void): EditorTransaction;
103
+ /** Despawn `entityId` as its own undo entry; `restore` recreates it on undo. */
104
+ despawn<Defs extends readonly ComponentDef[]>(entityId: EntityID, restore: SpawnEntries<Defs>): EditorTransaction;
103
105
  /** Set one field as its own undo entry. */
104
- setField<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): EditorTransaction;
105
- /** Add a component as its own undo entry. */
106
- addComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): EditorTransaction;
107
- /** Remove a component as its own undo entry; `restore` re-adds it on undo. */
108
- removeComponent<S extends ComponentSchema>(eid: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): EditorTransaction;
109
- /** Disable `eid` as its own undo entry. */
110
- disable(eid: EntityID): EditorTransaction;
111
- /** Enable `eid` as its own undo entry. */
112
- enable(eid: EntityID): EditorTransaction;
106
+ setField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): EditorTransaction;
107
+ /** Attach a component as its own undo entry. Bare `add` (see `TransactionBuilder.add`). */
108
+ add<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): EditorTransaction;
109
+ /** Detach a component as its own undo entry; `restore` re-adds it on undo. Bare `remove`. */
110
+ remove<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): EditorTransaction;
111
+ /** Disable `entityId` as its own undo entry. */
112
+ disable(entityId: EntityID): EditorTransaction;
113
+ /** Enable `entityId` as its own undo entry. */
114
+ enable(entityId: EntityID): EditorTransaction;
113
115
  /**
114
116
  * Undo the most recent transaction: enqueue its inverse commands (in reverse
115
117
  * order — a group unwinds last-action-first) on the bus and move it to the redo
@@ -145,7 +147,7 @@ export declare class Editor {
145
147
  /** Read one committed `(entity, component, field)` slot through the reader
146
148
  * this editor was constructed with — the default read for `fieldHandle`
147
149
  * when no channel thunk is supplied (M11). */
148
- committedField(eid: EntityID, def: ComponentDef, field: string): number | undefined;
150
+ committedField(entityId: EntityID, def: ComponentDef, field: string): number | undefined;
149
151
  /**
150
152
  * The pending value the editor believes for a field that the committed read
151
153
  * channel has NOT caught up to yet (the shadow), or `undefined` if none. Lets an
@@ -161,7 +163,7 @@ export declare class Editor {
161
163
  * the next edit to the slot. `value` (the read channel) is always the source of
162
164
  * truth; `pending` is only the optimistic bridge.
163
165
  */
164
- pendingField(eid: EntityID, def: ComponentHandle, field: string): number | undefined;
166
+ pendingField(entityId: EntityID, def: ComponentHandle, field: string): number | undefined;
165
167
  /** Enqueue forward commands, record the transaction, clear redo, sync shadow. */
166
168
  private commit;
167
169
  /** Keep the setField shadow in step with the commands just enqueued. */
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAEhB,YAAY,EACZ,MAAM,gBAAgB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAElG;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;I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AErB;IAED,uEAAuE;IACvE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAQpC,OAAO,CAAC,MAAM;IAId;;kDAE8C;IAC9C,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxF;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAkBzF,iFAAiF;IACjF,OAAO,CAAC,MAAM;IAad,wEAAwE;IACxE,OAAO,CAAC,WAAW;CAOnB"}
@@ -26,9 +26,9 @@ export interface FieldHandle {
26
26
  readonly pending: number | undefined;
27
27
  }
28
28
  /**
29
- * Build a {@link FieldHandle} for one `(eid, def, field)` slot. `read` is the
29
+ * Build a {@link FieldHandle} for one `(entityId, def, field)` slot. `read` is the
30
30
  * tracked read of the reactive channel for this field (e.g.
31
- * `() => sync.map.get(eid)?.x`); `set` routes through `editor.setField`, so the
31
+ * `() => sync.map.get(entityId)?.x`); `set` routes through `editor.setField`, so the
32
32
  * edit is queued, batched, and undoable.
33
33
  *
34
34
  * `read` is optional (M11): omitted, the handle reads through the editor's own
@@ -36,5 +36,5 @@ export interface FieldHandle {
36
36
  * but NOT reactive — supply the channel thunk when the handle's `value` must
37
37
  * subscribe inside a tracking scope.
38
38
  */
39
- export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, eid: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
39
+ export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
40
40
  //# sourceMappingURL=field_handle.d.ts.map
@@ -26,9 +26,9 @@ export interface FieldHandle {
26
26
  readonly pending: number | undefined;
27
27
  }
28
28
  /**
29
- * Build a {@link FieldHandle} for one `(eid, def, field)` slot. `read` is the
29
+ * Build a {@link FieldHandle} for one `(entityId, def, field)` slot. `read` is the
30
30
  * tracked read of the reactive channel for this field (e.g.
31
- * `() => sync.map.get(eid)?.x`); `set` routes through `editor.setField`, so the
31
+ * `() => sync.map.get(entityId)?.x`); `set` routes through `editor.setField`, so the
32
32
  * edit is queued, batched, and undoable.
33
33
  *
34
34
  * `read` is optional (M11): omitted, the handle reads through the editor's own
@@ -36,5 +36,5 @@ export interface FieldHandle {
36
36
  * but NOT reactive — supply the channel thunk when the handle's `value` must
37
37
  * subscribe inside a tracking scope.
38
38
  */
39
- export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, eid: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
39
+ export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
40
40
  //# sourceMappingURL=field_handle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"field_handle.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/field_handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,8EAA8E;IAC9E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACpD,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,EACvB,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAC7B,WAAW,CAYb"}
1
+ {"version":3,"file":"field_handle.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/field_handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,8EAA8E;IAC9E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACpD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,EACvB,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAC7B,WAAW,CAYb"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(r,t,e){return`${r}:${t.id}:${e}`}const a=new WeakMap;class h{constructor(t,e){this.readField=t,this.shadow=e,a.set(this,{forward:[],inverse:[]})}staged=new Map;get _txn(){return a.get(this)}spawn(t,e){const n={kind:"despawn",eid:0};return this._txn.inverse.push(n),this._txn.forward.push({kind:"spawn",components:t,onSpawned:s=>{n.eid=s,e?.(s)}}),this}despawn(t,e){const n={kind:"despawn",eid:t};return this._txn.forward.push(n),this._txn.inverse.push({kind:"spawn",components:e,onSpawned:s=>{n.eid=s}}),this}setField(t,e,n,s){const i=d(t,e,n),o=this.staged.get(i)??this.shadow.get(i)??this.readField(t,e,n)??0;return this.staged.set(i,s),this._txn.forward.push({kind:"set_field",eid:t,def:e,field:n,value:s}),this._txn.inverse.push({kind:"set_field",eid:t,def:e,field:n,value:o}),this}addComponent(t,e,n){return this._txn.forward.push({kind:"add_component",eid:t,def:e,values:n}),this._txn.inverse.push({kind:"remove_component",eid:t,def:e}),this}removeComponent(t,e,n){return this._txn.forward.push({kind:"remove_component",eid:t,def:e}),this._txn.inverse.push({kind:"add_component",eid:t,def:e,values:n}),this}disable(t){return this._txn.forward.push({kind:"disable",eid:t}),this._txn.inverse.push({kind:"enable",eid:t}),this}enable(t){return this._txn.forward.push({kind:"enable",eid:t}),this._txn.inverse.push({kind:"disable",eid:t}),this}}class u{constructor(t,e){this.queue=t,this.readField=e}undoStack=[];redoStack=[];listeners=[];shadow=new Map;transaction(t){const e=new h(this.readField,this.shadow);return t(e),this.commit(a.get(e))}spawn(t,e){return this.transaction(n=>n.spawn(t,e))}despawn(t,e){return this.transaction(n=>n.despawn(t,e))}setField(t,e,n,s){return this.transaction(i=>i.setField(t,e,n,s))}addComponent(t,e,n){return this.transaction(s=>s.addComponent(t,e,n))}removeComponent(t,e,n){return this.transaction(s=>s.removeComponent(t,e,n))}disable(t){return this.transaction(e=>e.disable(t))}enable(t){return this.transaction(e=>e.enable(t))}undo(){const t=this.undoStack.pop();if(t===void 0)return!1;const e=t.inverse.slice().reverse();for(const n of e)this.queue.push(n);return this.applyShadow(e),this.redoStack.push(t),this.notify(),!0}redo(){const t=this.redoStack.pop();if(t===void 0)return!1;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.notify(),!0}clear(){this.undoStack.length=0,this.redoStack.length=0,this.shadow.clear(),this.notify()}depths(){return{undo:this.undoStack.length,redo:this.redoStack.length}}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}onChange(t){return this.listeners.push(t),()=>{const e=this.listeners.indexOf(t);e!==-1&&this.listeners.splice(e,1)}}notify(){for(const t of this.listeners.slice())t()}committedField(t,e,n){return this.readField(t,e,n)}pendingField(t,e,n){const s=d(t,e,n),i=this.shadow.get(s);if(i===void 0)return;const o=this.readField(t,e,n);if(o===i||o===void 0){this.shadow.delete(s);return}return i}commit(t){if(t.forward.length===0)return t;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.redoStack.length=0,this.notify(),t}applyShadow(t){for(const e of t)e.kind==="set_field"&&this.shadow.set(d(e.eid,e.def,e.field),e.value)}}function c(r,t,e,n,s){return{get value(){return s!==void 0?s():r.committedField(t,e,n)},set(i){r.setField(t,e,n,i)},get pending(){return r.pendingField(t,e,n)}}}exports.Editor=u;exports.TransactionBuilder=h;exports.fieldHandle=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(r,t,e){return`${r}:${t.id}:${e}`}const a=new WeakMap;class h{constructor(t,e){this.readField=t,this.shadow=e,a.set(this,{forward:[],inverse:[]})}staged=new Map;get _txn(){return a.get(this)}spawn(t,e){const s={kind:"despawn",eid:0};return this._txn.inverse.push(s),this._txn.forward.push({kind:"spawn",components:t,onSpawned:n=>{s.eid=n,e?.(n)}}),this}despawn(t,e){const s={kind:"despawn",eid:t};return this._txn.forward.push(s),this._txn.inverse.push({kind:"spawn",components:e,onSpawned:n=>{s.eid=n}}),this}setField(t,e,s,n){const i=o(t,e,s),d=this.staged.get(i)??this.shadow.get(i)??this.readField(t,e,s)??0;return this.staged.set(i,n),this._txn.forward.push({kind:"set_field",eid:t,def:e,field:s,value:n}),this._txn.inverse.push({kind:"set_field",eid:t,def:e,field:s,value:d}),this}add(t,e,s){return this._txn.forward.push({kind:"add_component",eid:t,def:e,values:s}),this._txn.inverse.push({kind:"remove_component",eid:t,def:e}),this}remove(t,e,s){return this._txn.forward.push({kind:"remove_component",eid:t,def:e}),this._txn.inverse.push({kind:"add_component",eid:t,def:e,values:s}),this}disable(t){return this._txn.forward.push({kind:"disable",eid:t}),this._txn.inverse.push({kind:"enable",eid:t}),this}enable(t){return this._txn.forward.push({kind:"enable",eid:t}),this._txn.inverse.push({kind:"disable",eid:t}),this}}class u{constructor(t,e){this.queue=t,this.readField=e}undoStack=[];redoStack=[];listeners=[];shadow=new Map;transaction(t){const e=new h(this.readField,this.shadow);return t(e),this.commit(a.get(e))}spawn(t,e){return this.transaction(s=>s.spawn(t,e))}despawn(t,e){return this.transaction(s=>s.despawn(t,e))}setField(t,e,s,n){return this.transaction(i=>i.setField(t,e,s,n))}add(t,e,s){return this.transaction(n=>n.add(t,e,s))}remove(t,e,s){return this.transaction(n=>n.remove(t,e,s))}disable(t){return this.transaction(e=>e.disable(t))}enable(t){return this.transaction(e=>e.enable(t))}undo(){const t=this.undoStack.pop();if(t===void 0)return!1;const e=t.inverse.slice().reverse();for(const s of e)this.queue.push(s);return this.applyShadow(e),this.redoStack.push(t),this.notify(),!0}redo(){const t=this.redoStack.pop();if(t===void 0)return!1;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.notify(),!0}clear(){this.undoStack.length=0,this.redoStack.length=0,this.shadow.clear(),this.notify()}depths(){return{undo:this.undoStack.length,redo:this.redoStack.length}}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}onChange(t){return this.listeners.push(t),()=>{const e=this.listeners.indexOf(t);e!==-1&&this.listeners.splice(e,1)}}notify(){for(const t of this.listeners.slice())t()}committedField(t,e,s){return this.readField(t,e,s)}pendingField(t,e,s){const n=o(t,e,s),i=this.shadow.get(n);if(i===void 0)return;const d=this.readField(t,e,s);if(d===i||d===void 0){this.shadow.delete(n);return}return i}commit(t){if(t.forward.length===0)return t;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.redoStack.length=0,this.notify(),t}applyShadow(t){for(const e of t)e.kind==="set_field"&&this.shadow.set(o(e.eid,e.def,e.field),e.value)}}function c(r,t,e,s,n){return{get value(){return n!==void 0?n():r.committedField(t,e,s)},set(i){r.setField(t,e,s,i)},get pending(){return r.pendingField(t,e,s)}}}exports.Editor=u;exports.TransactionBuilder=h;exports.fieldHandle=c;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(r,t,e){return`${r}:${t.id}:${e}`}const a=new WeakMap;class h{constructor(t,e){this.readField=t,this.shadow=e,a.set(this,{forward:[],inverse:[]})}staged=new Map;get _txn(){return a.get(this)}spawn(t,e){const s={kind:"despawn",eid:0};return this._txn.inverse.push(s),this._txn.forward.push({kind:"spawn",components:t,onSpawned:n=>{s.eid=n,e?.(n)}}),this}despawn(t,e){const s={kind:"despawn",eid:t};return this._txn.forward.push(s),this._txn.inverse.push({kind:"spawn",components:e,onSpawned:n=>{s.eid=n}}),this}setField(t,e,s,n){const i=o(t,e,s),d=this.staged.get(i)??this.shadow.get(i)??this.readField(t,e,s)??0;return this.staged.set(i,n),this._txn.forward.push({kind:"set_field",eid:t,def:e,field:s,value:n}),this._txn.inverse.push({kind:"set_field",eid:t,def:e,field:s,value:d}),this}add(t,e,s){return this._txn.forward.push({kind:"add_component",eid:t,def:e,values:s}),this._txn.inverse.push({kind:"remove_component",eid:t,def:e}),this}remove(t,e,s){return this._txn.forward.push({kind:"remove_component",eid:t,def:e}),this._txn.inverse.push({kind:"add_component",eid:t,def:e,values:s}),this}disable(t){return this._txn.forward.push({kind:"disable",eid:t}),this._txn.inverse.push({kind:"enable",eid:t}),this}enable(t){return this._txn.forward.push({kind:"enable",eid:t}),this._txn.inverse.push({kind:"disable",eid:t}),this}}class u{constructor(t,e){this.queue=t,this.readField=e}undoStack=[];redoStack=[];listeners=[];shadow=new Map;transaction(t){const e=new h(this.readField,this.shadow);return t(e),this.commit(a.get(e))}spawn(t,e){return this.transaction(s=>s.spawn(t,e))}despawn(t,e){return this.transaction(s=>s.despawn(t,e))}setField(t,e,s,n){return this.transaction(i=>i.setField(t,e,s,n))}add(t,e,s){return this.transaction(n=>n.add(t,e,s))}remove(t,e,s){return this.transaction(n=>n.remove(t,e,s))}disable(t){return this.transaction(e=>e.disable(t))}enable(t){return this.transaction(e=>e.enable(t))}undo(){const t=this.undoStack.pop();if(t===void 0)return!1;const e=t.inverse.slice().reverse();for(const s of e)this.queue.push(s);return this.applyShadow(e),this.redoStack.push(t),this.notify(),!0}redo(){const t=this.redoStack.pop();if(t===void 0)return!1;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.notify(),!0}clear(){this.undoStack.length=0,this.redoStack.length=0,this.shadow.clear(),this.notify()}depths(){return{undo:this.undoStack.length,redo:this.redoStack.length}}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}onChange(t){return this.listeners.push(t),()=>{const e=this.listeners.indexOf(t);e!==-1&&this.listeners.splice(e,1)}}notify(){for(const t of this.listeners.slice())t()}committedField(t,e,s){return this.readField(t,e,s)}pendingField(t,e,s){const n=o(t,e,s),i=this.shadow.get(n);if(i===void 0)return;const d=this.readField(t,e,s);if(d===i||d===void 0){this.shadow.delete(n);return}return i}commit(t){if(t.forward.length===0)return t;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.redoStack.length=0,this.notify(),t}applyShadow(t){for(const e of t)e.kind==="set_field"&&this.shadow.set(o(e.eid,e.def,e.field),e.value)}}function c(r,t,e,s,n){return{get value(){return n!==void 0?n():r.committedField(t,e,s)},set(i){r.setField(t,e,s,i)},get pending(){return r.pendingField(t,e,s)}}}exports.Editor=u;exports.TransactionBuilder=h;exports.fieldHandle=c;
@@ -0,0 +1,239 @@
1
+ function o(r, t, e) {
2
+ return `${r}:${t.id}:${e}`;
3
+ }
4
+ const a = /* @__PURE__ */ new WeakMap();
5
+ class h {
6
+ /** @internal */
7
+ constructor(t, e) {
8
+ this.readField = t, this.shadow = e, a.set(this, { forward: [], inverse: [] });
9
+ }
10
+ /** Values staged by THIS build, layered over the editor's shared shadow. Kept
11
+ * transaction-local so an aborted build (the callback throws before commit)
12
+ * leaves the shared shadow untouched — a phantom staged value would poison
13
+ * `pendingField` and seed the NEXT edit's inverse with a value the world never
14
+ * held. The one merge point into the shared shadow is commit's `applyShadow`. */
15
+ staged = /* @__PURE__ */ new Map();
16
+ get _txn() {
17
+ return a.get(this);
18
+ }
19
+ spawn(t, e) {
20
+ const s = {
21
+ kind: "despawn",
22
+ eid: 0
23
+ };
24
+ return this._txn.inverse.push(s), this._txn.forward.push({
25
+ kind: "spawn",
26
+ components: t,
27
+ onSpawned: (n) => {
28
+ s.eid = n, e?.(n);
29
+ }
30
+ }), this;
31
+ }
32
+ despawn(t, e) {
33
+ const s = { kind: "despawn", eid: t };
34
+ return this._txn.forward.push(s), this._txn.inverse.push({
35
+ kind: "spawn",
36
+ components: e,
37
+ onSpawned: (n) => {
38
+ s.eid = n;
39
+ }
40
+ }), this;
41
+ }
42
+ /**
43
+ * Set `field` of `def` on `entityId` to `value`. Inverse: set it back to the value
44
+ * this edit replaced — read from the staged overlay / shadow (so stacked edits,
45
+ * within one build or before a commit, invert correctly) or, failing that, the
46
+ * read channel (`0` if unknown).
47
+ */
48
+ setField(t, e, s, n) {
49
+ const i = o(t, e, s), d = this.staged.get(i) ?? this.shadow.get(i) ?? this.readField(t, e, s) ?? 0;
50
+ return this.staged.set(i, n), this._txn.forward.push({ kind: "set_field", eid: t, def: e, field: s, value: n }), this._txn.inverse.push({ kind: "set_field", eid: t, def: e, field: s, value: d }), this;
51
+ }
52
+ /** Attach `def` (with complete `values`) to `entityId`. Inverse: remove it.
53
+ * Bare `add` — the namespaced-handle grammar (matches `ctx.commands.add` and
54
+ * the queue's `add`), not `addComponent`. */
55
+ add(t, e, s) {
56
+ return this._txn.forward.push({ kind: "add_component", eid: t, def: e, values: s }), this._txn.inverse.push({ kind: "remove_component", eid: t, def: e }), this;
57
+ }
58
+ /**
59
+ * Detach `def` from `entityId`. Inverse: re-add it from `restore` (the field values
60
+ * to recreate — read them from the channel before removing). Bare `remove` — see `add`.
61
+ */
62
+ remove(t, e, s) {
63
+ return this._txn.forward.push({ kind: "remove_component", eid: t, def: e }), this._txn.inverse.push({
64
+ kind: "add_component",
65
+ eid: t,
66
+ def: e,
67
+ values: s
68
+ }), this;
69
+ }
70
+ /** Disable `entityId`. Inverse: enable it. */
71
+ disable(t) {
72
+ return this._txn.forward.push({ kind: "disable", eid: t }), this._txn.inverse.push({ kind: "enable", eid: t }), this;
73
+ }
74
+ /** Enable `entityId`. Inverse: disable it. */
75
+ enable(t) {
76
+ return this._txn.forward.push({ kind: "enable", eid: t }), this._txn.inverse.push({ kind: "disable", eid: t }), this;
77
+ }
78
+ }
79
+ class u {
80
+ constructor(t, e) {
81
+ this.queue = t, this.readField = e;
82
+ }
83
+ undoStack = [];
84
+ redoStack = [];
85
+ /** onChange subscribers — see {@link onChange}. */
86
+ listeners = [];
87
+ /** Per-`(entity, component, field)` shadow of edited values, for inverse correctness. */
88
+ shadow = /* @__PURE__ */ new Map();
89
+ /**
90
+ * Group several actions into ONE undo entry. Build them on the passed
91
+ * {@link TransactionBuilder}; the whole group commits (enqueues its forward
92
+ * commands) and lands on the undo stack atomically, clearing the redo stack.
93
+ */
94
+ transaction(t) {
95
+ const e = new h(this.readField, this.shadow);
96
+ return t(e), this.commit(a.get(e));
97
+ }
98
+ spawn(t, e) {
99
+ return this.transaction((s) => s.spawn(t, e));
100
+ }
101
+ despawn(t, e) {
102
+ return this.transaction((s) => s.despawn(t, e));
103
+ }
104
+ /** Set one field as its own undo entry. */
105
+ setField(t, e, s, n) {
106
+ return this.transaction((i) => i.setField(t, e, s, n));
107
+ }
108
+ /** Attach a component as its own undo entry. Bare `add` (see `TransactionBuilder.add`). */
109
+ add(t, e, s) {
110
+ return this.transaction((n) => n.add(t, e, s));
111
+ }
112
+ /** Detach a component as its own undo entry; `restore` re-adds it on undo. Bare `remove`. */
113
+ remove(t, e, s) {
114
+ return this.transaction((n) => n.remove(t, e, s));
115
+ }
116
+ /** Disable `entityId` as its own undo entry. */
117
+ disable(t) {
118
+ return this.transaction((e) => e.disable(t));
119
+ }
120
+ /** Enable `entityId` as its own undo entry. */
121
+ enable(t) {
122
+ return this.transaction((e) => e.enable(t));
123
+ }
124
+ /**
125
+ * Undo the most recent transaction: enqueue its inverse commands (in reverse
126
+ * order — a group unwinds last-action-first) on the bus and move it to the redo
127
+ * stack. Returns `false` if the undo stack is empty.
128
+ */
129
+ undo() {
130
+ const t = this.undoStack.pop();
131
+ if (t === void 0) return !1;
132
+ const e = t.inverse.slice().reverse();
133
+ for (const s of e) this.queue.push(s);
134
+ return this.applyShadow(e), this.redoStack.push(t), this.notify(), !0;
135
+ }
136
+ /**
137
+ * Redo the most recently undone transaction: re-enqueue its forward commands on
138
+ * the bus and move it back to the undo stack. Returns `false` if the redo stack
139
+ * is empty.
140
+ */
141
+ redo() {
142
+ const t = this.redoStack.pop();
143
+ if (t === void 0) return !1;
144
+ for (const e of t.forward) this.queue.push(e);
145
+ return this.applyShadow(t.forward), this.undoStack.push(t), this.notify(), !0;
146
+ }
147
+ /** Drop both stacks (e.g. on load). Does not touch the world. */
148
+ clear() {
149
+ this.undoStack.length = 0, this.redoStack.length = 0, this.shadow.clear(), this.notify();
150
+ }
151
+ /** Current stack depths — for an "Undo (3)" / "Redo" affordance. */
152
+ depths() {
153
+ return { undo: this.undoStack.length, redo: this.redoStack.length };
154
+ }
155
+ /** `true` when `undo()` would do something — allocation-free (M10). */
156
+ get canUndo() {
157
+ return this.undoStack.length > 0;
158
+ }
159
+ /** `true` when `redo()` would do something — allocation-free (M10). */
160
+ get canRedo() {
161
+ return this.redoStack.length > 0;
162
+ }
163
+ /**
164
+ * Subscribe to undo/redo-stack changes: fires after every commit, undo,
165
+ * redo, and clear — the push signal an "Undo (3)" affordance needs instead
166
+ * of polling `depths()` per frame (M10). Returns an unsubscribe function.
167
+ * Callbacks run synchronously in subscription order; read `canUndo` /
168
+ * `canRedo` / `depths()` inside.
169
+ */
170
+ onChange(t) {
171
+ return this.listeners.push(t), () => {
172
+ const e = this.listeners.indexOf(t);
173
+ e !== -1 && this.listeners.splice(e, 1);
174
+ };
175
+ }
176
+ notify() {
177
+ for (const t of this.listeners.slice()) t();
178
+ }
179
+ /** Read one committed `(entity, component, field)` slot through the reader
180
+ * this editor was constructed with — the default read for `fieldHandle`
181
+ * when no channel thunk is supplied (M11). */
182
+ committedField(t, e, s) {
183
+ return this.readField(t, e, s);
184
+ }
185
+ /**
186
+ * The pending value the editor believes for a field that the committed read
187
+ * channel has NOT caught up to yet (the shadow), or `undefined` if none. Lets an
188
+ * inspector echo an edit between the `set` and the tick that commits it.
189
+ *
190
+ * Self-resolving: once the read channel reports the shadowed value (the edit
191
+ * landed) — or reports `undefined` (the slot is gone: entity despawned or
192
+ * component removed) — the entry is dropped and this returns `undefined`, so
193
+ * `pending` does not outlive its set→commit window and shadow a later external
194
+ * write, nor a dead slot's lifetime. The one
195
+ * residual: if an external write changes the field to a *different* value within
196
+ * the same window before this is next consulted, `pending` can read stale until
197
+ * the next edit to the slot. `value` (the read channel) is always the source of
198
+ * truth; `pending` is only the optimistic bridge.
199
+ */
200
+ pendingField(t, e, s) {
201
+ const n = o(t, e, s), i = this.shadow.get(n);
202
+ if (i === void 0) return;
203
+ const d = this.readField(t, e, s);
204
+ if (d === i || d === void 0) {
205
+ this.shadow.delete(n);
206
+ return;
207
+ }
208
+ return i;
209
+ }
210
+ /** Enqueue forward commands, record the transaction, clear redo, sync shadow. */
211
+ commit(t) {
212
+ if (t.forward.length === 0) return t;
213
+ for (const e of t.forward) this.queue.push(e);
214
+ return this.applyShadow(t.forward), this.undoStack.push(t), this.redoStack.length = 0, this.notify(), t;
215
+ }
216
+ /** Keep the setField shadow in step with the commands just enqueued. */
217
+ applyShadow(t) {
218
+ for (const e of t)
219
+ e.kind === "set_field" && this.shadow.set(o(e.eid, e.def, e.field), e.value);
220
+ }
221
+ }
222
+ function c(r, t, e, s, n) {
223
+ return {
224
+ get value() {
225
+ return n !== void 0 ? n() : r.committedField(t, e, s);
226
+ },
227
+ set(i) {
228
+ r.setField(t, e, s, i);
229
+ },
230
+ get pending() {
231
+ return r.pendingField(t, e, s);
232
+ }
233
+ };
234
+ }
235
+ export {
236
+ u as Editor,
237
+ h as TransactionBuilder,
238
+ c as fieldHandle
239
+ };