blecsd 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/LICENSE +4 -2
  2. package/README.md +209 -66
  3. package/dist/3d/index.d.ts +2 -2
  4. package/dist/3d/index.js +1 -1
  5. package/dist/audio/index.d.ts +2 -2
  6. package/dist/{border-D_Jb4ZJV.d.ts → border-Jb7TrMob.d.ts} +20 -10
  7. package/dist/chunk-2IEMMRUO.js +1 -0
  8. package/dist/chunk-3AV52GY5.js +1 -0
  9. package/dist/chunk-3LHLSY3Y.js +1 -0
  10. package/dist/chunk-3O4TQHGK.js +4 -0
  11. package/dist/chunk-3UJWZ5ZN.js +1 -0
  12. package/dist/chunk-5N3O25O7.js +1 -0
  13. package/dist/chunk-6M2J5QUA.js +1 -0
  14. package/dist/chunk-7IQEUVGF.js +1 -0
  15. package/dist/chunk-A6M6TFBL.js +1 -0
  16. package/dist/chunk-CUEUJAHK.js +3 -0
  17. package/dist/chunk-D42Q2KKR.js +1 -0
  18. package/dist/chunk-DYEXOFUU.js +2 -0
  19. package/dist/chunk-DYU72XLL.js +1 -0
  20. package/dist/chunk-E4CJRSND.js +1 -0
  21. package/dist/chunk-EAY7B5GL.js +1 -0
  22. package/dist/chunk-FCMTWFSE.js +1 -0
  23. package/dist/chunk-FL56THSI.js +25 -0
  24. package/dist/{chunk-2UBBZFE4.js → chunk-G437VE43.js} +1 -1
  25. package/dist/chunk-GGXNWT36.js +8 -0
  26. package/dist/chunk-HLFORKXS.js +1 -0
  27. package/dist/chunk-J7MBKEBY.js +1 -0
  28. package/dist/{chunk-TYMY2TBR.js → chunk-JHCKPCUH.js} +3 -3
  29. package/dist/chunk-K3SX2LY5.js +1 -0
  30. package/dist/chunk-LDAFEXN5.js +1 -0
  31. package/dist/chunk-MKMFUXLB.js +33 -0
  32. package/dist/chunk-MQWPHPUM.js +1 -0
  33. package/dist/chunk-MTI376CU.js +5 -0
  34. package/dist/chunk-MTV2RJZD.js +1 -0
  35. package/dist/chunk-NPDPBAW6.js +4 -0
  36. package/dist/chunk-OB66FB4F.js +1 -0
  37. package/dist/chunk-OR3BZY7C.js +1 -0
  38. package/dist/{chunk-VNZ6CWJA.js → chunk-R7AICVRN.js} +2 -2
  39. package/dist/{chunk-3B7MIVW6.js → chunk-RZ7FGVI6.js} +1 -1
  40. package/dist/chunk-UMGTXSQB.js +11 -0
  41. package/dist/chunk-X3Q3T2SS.js +4 -0
  42. package/dist/{chunk-JKVHO4LH.js → chunk-XZJRWFOS.js} +1 -1
  43. package/dist/chunk-ZAHG7Y3X.js +1 -0
  44. package/dist/cli/init.d.ts +1 -1
  45. package/dist/componentStorage-CJTh-TPO.d.ts +246 -0
  46. package/dist/components/index.d.ts +1942 -514
  47. package/dist/components/index.js +1 -1
  48. package/dist/core/index.d.ts +857 -259
  49. package/dist/core/index.js +1 -1
  50. package/dist/debug/index.d.ts +491 -98
  51. package/dist/debug/index.js +1 -1
  52. package/dist/dirtyTracking-C4v8MmM9.d.ts +235 -0
  53. package/dist/errors/index.d.ts +12 -12
  54. package/dist/errors/index.js +1 -1
  55. package/dist/{events-BbbxkgvX.d.ts → events-9ForpTfM.d.ts} +75 -2
  56. package/dist/game/index.d.ts +7 -7
  57. package/dist/game/index.js +1 -1
  58. package/dist/{gameLoop-BIPW7-OY.d.ts → gameLoop-C-Ez_i54.d.ts} +2 -2
  59. package/dist/{index-zSGJ2eUk.d.ts → index-DBS5Uefn.d.ts} +2 -2
  60. package/dist/index.d.ts +283 -20
  61. package/dist/index.js +3 -1
  62. package/dist/input/index.d.ts +1 -1
  63. package/dist/input/index.js +1 -1
  64. package/dist/{inputActions-CefRUBuT.d.ts → inputActions-CRsUtTHM.d.ts} +10 -721
  65. package/dist/packedStore-BgvnEdE7.d.ts +191 -0
  66. package/dist/{renderable-jTMOA-GK.d.ts → renderable-CwqGwrEV.d.ts} +9 -9
  67. package/dist/{scheduler-DcfoFuum.d.ts → scheduler-CMcYew9Z.d.ts} +65 -3
  68. package/dist/systems/index.d.ts +356 -55
  69. package/dist/systems/index.js +1 -1
  70. package/dist/terminal/index.d.ts +2233 -2299
  71. package/dist/terminal/index.js +1 -1
  72. package/dist/{tilemap-D1HJvKy3.d.ts → tilemap-BirMJdbu.d.ts} +92 -3
  73. package/dist/{types-BcsvoKzf.d.ts → types-CPB4CpbH.d.ts} +2 -2
  74. package/dist/utils/index.d.ts +27 -180
  75. package/dist/utils/index.js +1 -1
  76. package/dist/{virtualScrollback-DvZTRU8a.d.ts → virtualScrollback-D9uLFe8l.d.ts} +4 -4
  77. package/dist/{virtualViewport-Dx2iJliO.d.ts → virtualViewport-Bpv6jlKt.d.ts} +283 -761
  78. package/dist/widgets/bigText.d.ts +1 -1
  79. package/dist/widgets/bigText.js +1 -1
  80. package/dist/widgets/index.d.ts +10519 -5463
  81. package/dist/widgets/index.js +1 -1
  82. package/package.json +102 -6
  83. package/dist/chunk-35I22JJO.js +0 -1
  84. package/dist/chunk-3EGGGI5J.js +0 -3
  85. package/dist/chunk-4X4N4HNQ.js +0 -2
  86. package/dist/chunk-AQ7LW75B.js +0 -1
  87. package/dist/chunk-AXZQAH4X.js +0 -1
  88. package/dist/chunk-BCADUCOZ.js +0 -1
  89. package/dist/chunk-EJ5WVDDZ.js +0 -6
  90. package/dist/chunk-FT7BMYSN.js +0 -1
  91. package/dist/chunk-FYEBZAWN.js +0 -1
  92. package/dist/chunk-GYHI26UE.js +0 -1
  93. package/dist/chunk-H2YAOJDW.js +0 -1
  94. package/dist/chunk-K2B2OXQ5.js +0 -5
  95. package/dist/chunk-K37L3G4Z.js +0 -4
  96. package/dist/chunk-KD55INV7.js +0 -1
  97. package/dist/chunk-KFAK4A3G.js +0 -1
  98. package/dist/chunk-LCN2ZITE.js +0 -1
  99. package/dist/chunk-OUXUPF3V.js +0 -33
  100. package/dist/chunk-P6CJO3BC.js +0 -1
  101. package/dist/chunk-PI5UOHOH.js +0 -1
  102. package/dist/chunk-PSXXMBVJ.js +0 -1
  103. package/dist/chunk-TRK4422V.js +0 -12
  104. package/dist/chunk-W5OU7Z6J.js +0 -1
  105. package/dist/chunk-WNG4A3K7.js +0 -4
  106. package/dist/chunk-XRJNAHNG.js +0 -19
  107. package/dist/chunk-XZA63ZPO.js +0 -1
  108. package/dist/chunk-YAMOSPWB.js +0 -4
  109. package/dist/chunk-YD6ULIUR.js +0 -1
  110. package/dist/{keyParser-Bwm8-l7v.d.ts → keyParser-BnHbg2iD.d.ts} +1 -1
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Packed Store: Cache-friendly storage with stable handles
3
+ *
4
+ * Implements the three-vector pattern for O(1) add/remove operations
5
+ * with stable identifiers and cache-friendly iteration:
6
+ *
7
+ * - data[]: Dense contiguous storage for actual values
8
+ * - dataIndex[]: Maps handle index → position in data array
9
+ * - id[]: Maps position in data → handle index (inverse mapping)
10
+ * - generations[]: Tracks generation at each slot for stale handle detection
11
+ *
12
+ * @module core/storage/packedStore
13
+ */
14
+ /**
15
+ * Handle to an element in a packed store.
16
+ * The combination of index and generation ensures handles
17
+ * become invalid after the element is removed.
18
+ */
19
+ interface PackedHandle {
20
+ readonly index: number;
21
+ readonly gen: number;
22
+ }
23
+ /**
24
+ * Packed store state. All arrays are parallel structures
25
+ * that work together to provide stable handles with O(1) operations.
26
+ */
27
+ interface PackedStore<T> {
28
+ /** Dense contiguous data array for cache-friendly iteration */
29
+ readonly data: T[];
30
+ /** Maps handle index → position in data array */
31
+ readonly dataIndex: Int32Array;
32
+ /** Maps data position → handle index (inverse of dataIndex) */
33
+ readonly id: Int32Array;
34
+ /** Generation counter for each slot (bumped on removal) */
35
+ readonly generations: Uint32Array;
36
+ /** Number of live elements */
37
+ size: number;
38
+ /** Total allocated capacity */
39
+ capacity: number;
40
+ }
41
+ /**
42
+ * Creates a new packed store with optional initial capacity.
43
+ *
44
+ * @param initialCapacity - Initial capacity hint (default 64)
45
+ * @returns Empty packed store
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * import { createPackedStore, addToStore } from 'blecsd';
50
+ *
51
+ * interface Particle { x: number; y: number; vx: number; vy: number; }
52
+ * const particles = createPackedStore<Particle>();
53
+ * const handle = addToStore(particles, { x: 0, y: 0, vx: 1, vy: 0 });
54
+ * ```
55
+ */
56
+ declare function createPackedStore<T>(initialCapacity?: number): PackedStore<T>;
57
+ /**
58
+ * Adds a value to the packed store and returns a stable handle.
59
+ *
60
+ * If there are freed slots from prior deletions, one is reused.
61
+ * Otherwise, capacity is expanded as needed.
62
+ *
63
+ * @param store - The packed store
64
+ * @param value - Value to add
65
+ * @returns Handle to the stored value
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const handle = addToStore(store, { name: 'entity1' });
70
+ * // handle.index is stable even after other elements are removed
71
+ * ```
72
+ */
73
+ declare function addToStore<T>(store: PackedStore<T>, value: T): PackedHandle;
74
+ /**
75
+ * Checks if a handle is valid (points to a live element).
76
+ *
77
+ * @param store - The packed store
78
+ * @param handle - Handle to validate
79
+ * @returns True if the handle points to a live element
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * if (isValidHandle(store, handle)) {
84
+ * const value = getFromStore(store, handle);
85
+ * }
86
+ * ```
87
+ */
88
+ declare function isValidHandle<T>(store: PackedStore<T>, handle: PackedHandle): boolean;
89
+ /**
90
+ * Gets the value associated with a handle.
91
+ *
92
+ * @param store - The packed store
93
+ * @param handle - Handle to the element
94
+ * @returns The value, or undefined if handle is invalid
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const particle = getFromStore(particles, handle);
99
+ * if (particle) {
100
+ * console.log(particle.x, particle.y);
101
+ * }
102
+ * ```
103
+ */
104
+ declare function getFromStore<T>(store: PackedStore<T>, handle: PackedHandle): T | undefined;
105
+ /**
106
+ * Sets (replaces) the value at a handle.
107
+ *
108
+ * @param store - The packed store
109
+ * @param handle - Handle to the element
110
+ * @param value - New value
111
+ * @returns True if successful, false if handle is invalid
112
+ */
113
+ declare function setInStore<T>(store: PackedStore<T>, handle: PackedHandle, value: T): boolean;
114
+ /**
115
+ * Removes an element from the packed store using swap-and-pop.
116
+ *
117
+ * The handle becomes invalid after removal. Any other handles
118
+ * remain valid (this is the key benefit of the three-vector pattern).
119
+ *
120
+ * @param store - The packed store
121
+ * @param handle - Handle to remove
122
+ * @returns True if removed, false if handle was invalid
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * removeFromStore(particles, handle);
127
+ * // handle is now invalid, but other handles remain valid
128
+ * ```
129
+ */
130
+ declare function removeFromStore<T>(store: PackedStore<T>, handle: PackedHandle): boolean;
131
+ /**
132
+ * Clears all elements from the store but retains capacity.
133
+ *
134
+ * @param store - The packed store to clear
135
+ */
136
+ declare function clearStore<T>(store: PackedStore<T>): void;
137
+ /**
138
+ * Iterates over all live elements in the store.
139
+ * Iteration is cache-friendly as it traverses the dense data array.
140
+ *
141
+ * @param store - The packed store
142
+ * @param fn - Callback for each element (receives value and handle)
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * forEachInStore(particles, (particle, handle) => {
147
+ * particle.x += particle.vx;
148
+ * particle.y += particle.vy;
149
+ * });
150
+ * ```
151
+ */
152
+ declare function forEachInStore<T>(store: PackedStore<T>, fn: (value: T, handle: PackedHandle) => void): void;
153
+ /**
154
+ * Maps over all live elements, producing a new array.
155
+ *
156
+ * @param store - The packed store
157
+ * @param fn - Transform function
158
+ * @returns Array of transformed values
159
+ */
160
+ declare function mapStore<T, U>(store: PackedStore<T>, fn: (value: T, handle: PackedHandle) => U): U[];
161
+ /**
162
+ * Returns the dense data array for direct iteration.
163
+ * This is the fastest way to iterate when you don't need handles.
164
+ *
165
+ * WARNING: Do not modify the array structure (push/pop/splice).
166
+ * The returned array is a view into internal storage.
167
+ *
168
+ * @param store - The packed store
169
+ * @returns Readonly view of the dense data array (length = store.size)
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * // Fastest iteration when handles aren't needed
174
+ * const data = getStoreData(particles);
175
+ * for (let i = 0; i < particles.size; i++) {
176
+ * const p = data[i];
177
+ * p.x += p.vx;
178
+ * }
179
+ * ```
180
+ */
181
+ declare function getStoreData<T>(store: PackedStore<T>): readonly T[];
182
+ /**
183
+ * Gets the current number of live elements.
184
+ */
185
+ declare function getStoreSize<T>(store: PackedStore<T>): number;
186
+ /**
187
+ * Gets the current capacity (including freed slots).
188
+ */
189
+ declare function getStoreCapacity<T>(store: PackedStore<T>): number;
190
+
191
+ export { type PackedStore as P, type PackedHandle as a, addToStore as b, clearStore as c, createPackedStore as d, getStoreCapacity as e, forEachInStore as f, getFromStore as g, getStoreData as h, getStoreSize as i, isValidHandle as j, mapStore as m, removeFromStore as r, setInStore as s };
@@ -1,4 +1,4 @@
1
- import { W as World, E as Entity } from './types-BcsvoKzf.js';
1
+ import { W as World, E as Entity } from './types-CPB4CpbH.js';
2
2
 
3
3
  /**
4
4
  * Renderable component for visual styling of entities.
@@ -61,21 +61,21 @@ declare const Renderable: {
61
61
  */
62
62
  interface StyleOptions {
63
63
  /** Foreground color (hex string or packed number) */
64
- fg?: string | number;
64
+ fg?: string | number | undefined;
65
65
  /** Background color (hex string or packed number) */
66
- bg?: string | number;
66
+ bg?: string | number | undefined;
67
67
  /** Bold text */
68
- bold?: boolean;
68
+ bold?: boolean | undefined;
69
69
  /** Underlined text */
70
- underline?: boolean;
70
+ underline?: boolean | undefined;
71
71
  /** Blinking text */
72
- blink?: boolean;
72
+ blink?: boolean | undefined;
73
73
  /** Inverse colors */
74
- inverse?: boolean;
74
+ inverse?: boolean | undefined;
75
75
  /** Transparent background */
76
- transparent?: boolean;
76
+ transparent?: boolean | undefined;
77
77
  /** Opacity for alpha blending (0-1, where 1 = fully opaque) */
78
- opacity?: number;
78
+ opacity?: number | undefined;
79
79
  }
80
80
  /**
81
81
  * Style data returned by getStyle.
@@ -1,10 +1,63 @@
1
- import { L as LoopPhase, S as System, W as World } from './types-BcsvoKzf.js';
1
+ import { L as LoopPhase, S as System, W as World } from './types-CPB4CpbH.js';
2
2
 
3
3
  /**
4
4
  * System scheduler for ordered execution.
5
5
  * @module core/scheduler
6
6
  */
7
7
 
8
+ /**
9
+ * Per-phase timing data for a single frame.
10
+ */
11
+ interface PhaseTimingData {
12
+ /** Phase identifier */
13
+ readonly phase: LoopPhase;
14
+ /** Time spent in this phase in milliseconds */
15
+ duration: number;
16
+ /** Number of systems executed in this phase */
17
+ systemCount: number;
18
+ }
19
+ /**
20
+ * Frame telemetry data collected during scheduler execution.
21
+ */
22
+ interface FrameTelemetry {
23
+ /** Per-phase timing data */
24
+ readonly phases: ReadonlyArray<PhaseTimingData>;
25
+ /** Total frame time in milliseconds */
26
+ totalFrameTime: number;
27
+ /** Frame number (increments each run) */
28
+ frameNumber: number;
29
+ }
30
+ /**
31
+ * Telemetry configuration options.
32
+ */
33
+ interface TelemetryConfig {
34
+ /** Enable telemetry collection (default: false) */
35
+ enabled: boolean;
36
+ /** Maximum number of frames to keep in history (default: 0 = current frame only) */
37
+ historySize?: number;
38
+ }
39
+ /**
40
+ * Frame budget configuration for adaptive performance.
41
+ */
42
+ interface AdaptiveFrameBudgetConfig {
43
+ /** Enable frame budget enforcement (default: false) */
44
+ enabled: boolean;
45
+ /** Target frame time in milliseconds (default: 16.67ms for 60fps) */
46
+ budgetMs?: number;
47
+ /** Phases that can be skipped when over budget (default: [ANIMATION]) */
48
+ skippablePhases?: ReadonlyArray<LoopPhase>;
49
+ }
50
+ /**
51
+ * Frame budget status for the current frame.
52
+ */
53
+ interface AdaptiveFrameBudgetStatus {
54
+ /** Whether budget was exceeded this frame */
55
+ exceeded: boolean;
56
+ /** Phases that were skipped this frame */
57
+ skippedPhases: ReadonlyArray<LoopPhase>;
58
+ /** Time remaining in budget (negative if exceeded) */
59
+ remainingMs: number;
60
+ }
8
61
  /**
9
62
  * Gets the current frame's delta time.
10
63
  * Call this from within a system to get the time elapsed since the last frame.
@@ -60,6 +113,15 @@ interface Scheduler {
60
113
  hasSystem(system: System): boolean;
61
114
  clearPhase(phase: LoopPhase): void;
62
115
  clearAllSystems(): void;
116
+ enableTelemetry(config?: TelemetryConfig): void;
117
+ disableTelemetry(): void;
118
+ getTelemetry(): FrameTelemetry | null;
119
+ getTelemetryHistory(): ReadonlyArray<FrameTelemetry>;
120
+ isTelemetryEnabled(): boolean;
121
+ enableFrameBudget(config?: AdaptiveFrameBudgetConfig): void;
122
+ disableFrameBudget(): void;
123
+ getAdaptiveFrameBudgetStatus(): AdaptiveFrameBudgetStatus | null;
124
+ isFrameBudgetEnabled(): boolean;
63
125
  }
64
126
  /**
65
127
  * Creates a new scheduler instance.
@@ -74,7 +136,7 @@ interface Scheduler {
74
136
  *
75
137
  * // Register systems
76
138
  * scheduler.registerSystem(LoopPhase.UPDATE, movementSystem);
77
- * scheduler.registerSystem(LoopPhase.PHYSICS, physicsSystem);
139
+ * scheduler.registerSystem(LoopPhase.ANIMATION, physicsSystem);
78
140
  * scheduler.registerSystem(LoopPhase.RENDER, renderSystem);
79
141
  *
80
142
  * // Run in game loop
@@ -83,4 +145,4 @@ interface Scheduler {
83
145
  */
84
146
  declare function createScheduler(): Scheduler;
85
147
 
86
- export { type Scheduler as S, createScheduler as c, getDeltaTime as g };
148
+ export { type AdaptiveFrameBudgetConfig as A, type FrameTelemetry as F, type PhaseTimingData as P, type Scheduler as S, type TelemetryConfig as T, type AdaptiveFrameBudgetStatus as a, createScheduler as c, getDeltaTime as g };