@kayelaa/canvas 0.1.1 → 0.1.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.
@@ -0,0 +1,783 @@
1
+ import { a as LeaGameII, b as LeaRendererII, V as Vector2, R as RectLeaEntity, c as LeaSceneII } from './lea-DvxsutSf.cjs';
2
+
3
+ /**
4
+ * Base props interface that every Kayla component can receive.
5
+ *
6
+ * Extend this when defining custom component props:
7
+ *
8
+ * ```ts
9
+ * interface MyProps extends FCProps {
10
+ * speed: number;
11
+ * }
12
+ * ```
13
+ */
14
+ type FCProps = {
15
+ key?: string;
16
+ children?: KaylaElement<any>[];
17
+ ref?: KaylaRef<KaylaInternals.KaylaRectEntity>;
18
+ exportsRef?: KaylaRef<KaylaExports<any>>;
19
+ } & Record<string, unknown>;
20
+ type FCExports = {} & Record<string, KaylaExportables>;
21
+ interface FC<Props extends FCProps = FCProps, Exports extends FCExports = FCExports> {
22
+ (props: Props & {
23
+ ref?: KaylaElementRef;
24
+ exportsRef?: KaylaRef<KaylaExports<Exports>>;
25
+ }): KaylaElement<any>[] | KaylaElement<any> | void;
26
+ displayName?: string | undefined;
27
+ }
28
+ /**
29
+ * Creates a new game instance that coordinates scenes, renderers, and a shared ticker.
30
+ *
31
+ * The game manages the global update loop (via `updateHz`) and allows attaching multiple renderers
32
+ * and scenes. Start the game with `game.start()` to begin ticking and rendering.
33
+ *
34
+ * @param config - Configuration options
35
+ * @param config.width - Logical viewport width (used for entity coordinates)
36
+ * @param config.height - Logical viewport height
37
+ * @param config.updateHz - Tick frequency:
38
+ * - `"frames"` = run updates every render frame (RAF-synced, variable timestep)
39
+ * - number = fixed timestep in Hz (e.g. 60)
40
+ * @returns A `KaylaGame` instance
41
+ *
42
+ * @example
43
+ * const game = createGame({ width: 800, height: 600, updateHz: 60 });
44
+ * game.start();
45
+ */
46
+ declare function createGame({ width, height, updateHz: hz, }: {
47
+ width: number;
48
+ height: number;
49
+ updateHz?: number | "frames";
50
+ }): KaylaInternals.KaylaGame;
51
+ /**
52
+ * Creates a scene that manages a collection of entities and their update/draw lifecycle.
53
+ *
54
+ * Scenes handle z-sorted drawing, paused state, and entity addition/removal.
55
+ * Use `scene.spawn()` to mount a root component tree.
56
+ *
57
+ * @param name - Unique identifier for the scene
58
+ * @returns A `KaylaScene` wrapper with `.spawn()` and other methods
59
+ *
60
+ * @example
61
+ * const scene = createScene("main");
62
+ * scene.spawn(<GameWorld />);
63
+ */
64
+ declare function createScene(name: string): KaylaInternals.KaylaScene;
65
+ /**
66
+ * Creates a renderer that drives the canvas draw loop and handles pointer tracking.
67
+ *
68
+ * The renderer automatically clears the canvas each frame and emits a `"draw"` event
69
+ * where scenes can paint. Call `renderer.start()` to begin the RAF loop.
70
+ *
71
+ * @param canvas - The target `<canvas>` element
72
+ * @returns A `KaylaRenderer` instance
73
+ *
74
+ * @example
75
+ * const canvas = document.getElementById("game") as HTMLCanvasElement;
76
+ * const renderer = createRenderer(canvas);
77
+ * renderer.start();
78
+ */
79
+ declare function createRenderer(canvas: HTMLCanvasElement): KaylaRenderer;
80
+ /**
81
+ * Creates a Kayla element descriptor (virtual representation of an entity/component).
82
+ *
83
+ * This is the JSX factory used internally by the transpiler. You rarely call it directly,
84
+ * but it powers declarative trees passed to `scene.spawn()`.
85
+ *
86
+ * @template Props - Props type accepted by the component
87
+ * @param fc - The functional component
88
+ * @param props - Props including `key`, `ref`, `exportsRef`, `children`, etc.
89
+ * @returns Element descriptor
90
+ *
91
+ * @example
92
+ * const elem = createElement(Player, { x: 400, y: 300 });
93
+ * scene.spawn(elem);
94
+ */
95
+ declare function createElement<Props extends FCProps>(fc: FC<Props>, props: Props): KaylaElement<Props>;
96
+ interface KaylaElement<Props extends FCProps> {
97
+ type: FC<Props>;
98
+ props: Props;
99
+ }
100
+ /**
101
+ * Read-only view of a state value created via `useState`.
102
+ *
103
+ * Returned by `useState`. Changes via `.set()` / `.add()` / `.multiply()` may trigger
104
+ * a component refresh (re-execution of the component function), which can be expensive
105
+ * in performance-critical loops.
106
+ *
107
+ * **Performance warning:** Avoid frequent `.set()` calls in `useTick` / `usePaint` loops.
108
+ * Prefer `useSelf` or `useRef` for hot data (position, velocity, timers, counters).
109
+ * Use `useState` only for infrequent structural changes (e.g. `isDead`, `currentLevel`).
110
+ *
111
+ * @template T - Type of the stored value
112
+ */
113
+ interface KaylaState<T> extends KaylaInternals.KaylaState<T> {
114
+ }
115
+ /**
116
+ * Mutable reference object whose `.current` property persists across component refreshes.
117
+ *
118
+ * Returned by `useRef` and `useSelf`. Changes to `.current` **never** trigger refresh,
119
+ * making it safe for hot mutable data (position, velocity, timers, DOM nodes, etc.).
120
+ *
121
+ * @template T - Type of the referenced value
122
+ */
123
+ interface KaylaRef<T> extends KaylaInternals.KaylaRef<T> {
124
+ }
125
+ /**
126
+ * Game instance that coordinates scenes, renderers, and the shared ticker.
127
+ *
128
+ * @extends LeaGameII
129
+ */
130
+ interface KaylaGame extends KaylaInternals.KaylaGame {
131
+ }
132
+ /**
133
+ * Scene wrapper that manages entity lifecycle and delegates to the underlying LEA scene.
134
+ *
135
+ * @extends LeaSceneII (via internal delegation)
136
+ */
137
+ interface KaylaScene extends KaylaInternals.KaylaScene {
138
+ }
139
+ /**
140
+ * Renderer wrapper that extends LEA renderer with game integration and pointer utilities.
141
+ *
142
+ * @extends LeaRendererII
143
+ */
144
+ interface KaylaRenderer extends KaylaInternals.KaylaRenderer {
145
+ }
146
+ /**
147
+ * Internal APIs, do not use outside.
148
+ */
149
+ declare namespace KaylaInternals {
150
+ /**
151
+ * Game instance that coordinates scenes, renderers, and the shared ticker.
152
+ *
153
+ * @extends LeaGameII
154
+ */
155
+ class KaylaGame extends LeaGameII {
156
+ #private;
157
+ constructor(width: number, height: number, hz: typeof Infinity | number);
158
+ /**
159
+ * Whether the game has been started.
160
+ */
161
+ get started(): boolean;
162
+ /**
163
+ * Starts the game: starts all attached renderers and the ticker.
164
+ */
165
+ start(): void;
166
+ /**
167
+ * Stops the game: stops all attached renderers and the ticker.
168
+ */
169
+ stop(): void;
170
+ /**
171
+ * Attaches a renderer to the game.
172
+ *
173
+ * If the game is already started, the renderer is started immediately.
174
+ *
175
+ * @param renderer - The renderer to attach
176
+ */
177
+ addRenderer(renderer: KaylaRenderer): void;
178
+ /**
179
+ * Detaches a renderer from the game.
180
+ *
181
+ * If the game is running, the renderer is stopped.
182
+ *
183
+ * @param renderer - The renderer to detach
184
+ */
185
+ deleteRenderer(renderer: KaylaRenderer): void;
186
+ }
187
+ /**
188
+ * Renderer wrapper that extends LEA renderer with game integration and pointer utilities.
189
+ *
190
+ * @extends LeaRendererII
191
+ */
192
+ class KaylaRenderer extends LeaRendererII {
193
+ #private;
194
+ /**
195
+ * The attached game instance (set via `attachTo`).
196
+ */
197
+ game?: KaylaGame;
198
+ /**
199
+ * Current canvas-space pointer X coordinate.
200
+ */
201
+ pointerX: number;
202
+ /**
203
+ * Current canvas-space pointer Y coordinate.
204
+ */
205
+ pointerY: number;
206
+ constructor(canvas: HTMLCanvasElement);
207
+ listenPointerUpdates(): void;
208
+ unlistenPointerUpdates(): void;
209
+ /**
210
+ * Transforms canvas-space coordinates to world-space coordinates.
211
+ *
212
+ * @param mx - Mouse X in canvas pixels
213
+ * @param my - Mouse Y in canvas pixels
214
+ * @returns World-space position
215
+ */
216
+ pointerPosToWorldPos(mx: number, my: number): Vector2;
217
+ /**
218
+ * Returns the current pointer position in world coordinates.
219
+ *
220
+ * Requires `listenPointerUpdates()` to have been called.
221
+ *
222
+ * @returns World-space position
223
+ */
224
+ getMousePos(): Vector2;
225
+ /**
226
+ * Registers a draw callback that receives a normalized `KaylaEvent`.
227
+ *
228
+ * @param callback - Paint handler
229
+ * @returns Unsubscribe function
230
+ */
231
+ useDraw(callback: KaylaInternalComponent["onPaint"][number]): () => void;
232
+ /**
233
+ * Attaches this renderer to a game.
234
+ *
235
+ * Sets `renderer.game` and adds it to `game.#renderers`.
236
+ *
237
+ * @param game - The game to attach to
238
+ */
239
+ attachTo(game: KaylaGame): void;
240
+ /**
241
+ * Detaches this renderer from its game (if attached).
242
+ */
243
+ detach(): void;
244
+ }
245
+ class GlobalKayla {
246
+ current?: KaylaInternalComponent;
247
+ saves: {
248
+ current?: GlobalKayla["current"];
249
+ }[];
250
+ constructor();
251
+ useTick(onTick: KaylaInternalComponent["onTick"][number]): void;
252
+ usePaint(onPaint: KaylaInternalComponent["onPaint"][number]): void;
253
+ useEntity(): KaylaElementRef;
254
+ useSelf<T>(init: () => T): T;
255
+ useState<T>(initialValue?: T, { alwaysRecall }?: {
256
+ alwaysRecall?: boolean;
257
+ }): KaylaState<T>;
258
+ useRef(initialValue: typeof selfSym): KaylaElementRef;
259
+ useRef<T>(initialValue: T | null): KaylaRef<T>;
260
+ useEffect(onEffect: KaylaInternalComponent["onEffect"][number]): void;
261
+ useExports<T extends FC<any, any>>(fc: T, onExport: KaylaInternalComponent<PropOfFC<T>, ExportsOfFC<T>>["onExport"]): void;
262
+ save(): void;
263
+ restore(): void;
264
+ }
265
+ class KaylaEvent {
266
+ #private;
267
+ preventDefault(): void;
268
+ isPrevented(): boolean;
269
+ }
270
+ /**
271
+ * Read-only view of a state value created via `useState`.
272
+ *
273
+ * Returned by `useState`. Changes via `.set()` / `.add()` / `.multiply()` may trigger
274
+ * a component refresh (re-execution of the component function), which can be expensive
275
+ * in performance-critical loops.
276
+ *
277
+ * **Performance warning:** Avoid frequent `.set()` calls in `useTick` / `usePaint` loops.
278
+ * Prefer `useSelf` or `useRef` for hot data (position, velocity, timers, counters).
279
+ * Use `useState` only for infrequent structural changes (e.g. `isDead`, `currentLevel`).
280
+ *
281
+ * @template T - Type of the stored value
282
+ */
283
+ class KaylaState<T> {
284
+ #private;
285
+ alwaysRecall: boolean;
286
+ constructor(current: KaylaInternalComponent<any>, initialValue?: T, { alwaysRecall }?: {
287
+ alwaysRecall?: boolean;
288
+ });
289
+ get(this: KaylaState<T>): T;
290
+ /**
291
+ * Adds a number to the current value (only available when `T` is `number`).
292
+ *
293
+ * Convenience method that calls `.set(get() + added)`.
294
+ * Behaves exactly like `.set()` regarding refresh overhead.
295
+ *
296
+ * @param added - Value to add
297
+ * @param options - Optional control over refresh
298
+ * @param options.recall - Force refresh (default: false)
299
+ */
300
+ add(this: KaylaState<number>, added: number, { recall }?: {
301
+ recall?: boolean;
302
+ }): void;
303
+ /**
304
+ * Multiplies the current value by a number (only available when `T` is `number`).
305
+ *
306
+ * Convenience method that calls `.set(get() * multiplier)`.
307
+ * Behaves exactly like `.set()` regarding refresh overhead.
308
+ *
309
+ * @param multiplier - Value to multiply by
310
+ * @param options - Optional control over refresh
311
+ * @param options.recall - Force refresh (default: false)
312
+ */
313
+ multiply(this: KaylaState<number>, added: number, { recall }?: {
314
+ recall?: boolean;
315
+ }): void;
316
+ /**
317
+ * Updates the state value.
318
+ *
319
+ * If the new value differs from the current one (strict `!==` comparison),
320
+ * and either `recall: true` is passed or `alwaysRecall` was set at creation,
321
+ * this triggers a component refresh.
322
+ *
323
+ * Refreshing re-runs the entire component function, re-binds hooks,
324
+ * and may re-mount/unmount children — avoid in hot paths.
325
+ *
326
+ * @param newValue - The new state value
327
+ * @param options - Optional control over refresh behavior
328
+ * @param options.recall - Force a refresh even if `alwaysRecall` is false (default: false)
329
+ */
330
+ set(this: KaylaState<T>, s: T, { recall }?: {
331
+ recall?: boolean;
332
+ }): void;
333
+ /**
334
+ * The current value of the state.
335
+ *
336
+ * Reading this property is always safe and does not trigger side effects.
337
+ *
338
+ * @readonly
339
+ */
340
+ get value(): T;
341
+ /**
342
+ * Timestamp (milliseconds since epoch) of the last time the state was changed via `.set()`.
343
+ *
344
+ * Useful for dependency tracking or knowing when the value was last mutated.
345
+ *
346
+ * @readonly
347
+ */
348
+ get lastChanged(): number;
349
+ }
350
+ /**
351
+ * Mutable reference object whose `.current` property persists across component refreshes.
352
+ *
353
+ * Returned by `useRef` and `useSelf`. Changes to `.current` **never** trigger refresh,
354
+ * making it safe for hot mutable data (position, velocity, timers, DOM nodes, etc.).
355
+ *
356
+ * @template T - Type of the referenced value
357
+ */
358
+ class KaylaRef<T> {
359
+ #private;
360
+ constructor(current: KaylaInternalComponent<any>, initialValue?: T);
361
+ /**
362
+ * The mutable value held by the ref.
363
+ *
364
+ * Reading or writing this property has **no side effects** — it does **not** trigger
365
+ * component refresh, re-render, or hook re-registration.
366
+ *
367
+ * When initialized with the `self` symbol via `useRef(self)`, this becomes a reference
368
+ * to the underlying `KaylaRectEntity`.
369
+ *
370
+ * @type {T}
371
+ */
372
+ get current(): T;
373
+ set current(s: T);
374
+ }
375
+ class KaylaInternalComponent<Props extends FCProps = {}, Exports extends FCExports = FCExports> {
376
+ state: KaylaState<unknown>[];
377
+ refs: KaylaRef<unknown>[];
378
+ global: GlobalKayla;
379
+ callProps: Props;
380
+ scene: KaylaScene;
381
+ exports: KaylaExports<Exports>;
382
+ constructor(globalKayla: GlobalKayla, scene: KaylaScene, element: KaylaElement<Props>);
383
+ get key(): string;
384
+ set key(s: string);
385
+ get children(): KaylaElement<any>[];
386
+ set children(s: KaylaElement<any>[]);
387
+ entity?: KaylaRectEntity;
388
+ onExport: () => KaylaExports<Exports>;
389
+ onEffect: Array<() => (() => void) | void>;
390
+ onUnEffect: Array<() => void>;
391
+ onEffectDeps?: KaylaState<any>[] | undefined;
392
+ onPaint: Array<(ctx: CanvasRenderingContext2D, event: KaylaEvent) => void>;
393
+ onTick: Array<(deltaS: number, event: KaylaEvent) => void>;
394
+ fc?: FC<any>;
395
+ useStateCallIndex: number;
396
+ useEffectCallIndex: number;
397
+ useDrawCallIndex: number;
398
+ useStepCallIndex: number;
399
+ useRefCallIndex: number;
400
+ lastStateDeps: Array<{
401
+ stateRef: KaylaState<any>;
402
+ stamp: number;
403
+ }>;
404
+ refresh(): void;
405
+ lastChildren: KaylaInternalComponent<any>[];
406
+ isFirstUse: boolean;
407
+ use(): void;
408
+ unuse(): void;
409
+ }
410
+ class KaylaRectEntity extends RectLeaEntity {
411
+ #private;
412
+ constructor(component: KaylaInternalComponent, name: string);
413
+ update(_delta: number): void;
414
+ draw(ctx: CanvasRenderingContext2D): void;
415
+ }
416
+ class KaylaScene {
417
+ #private;
418
+ constructor(scene: LeaSceneII);
419
+ /**
420
+ * Returns the underlying LEA scene instance.
421
+ */
422
+ getScene(): LeaSceneII;
423
+ private drawHandler;
424
+ /**
425
+ * Attaches this scene to a game instance.
426
+ *
427
+ * @param game - The game to attach to
428
+ */
429
+ attachTo(game: LeaGameII): void;
430
+ /**
431
+ * Mounts a root component tree into the scene.
432
+ *
433
+ * Triggers component execution, entity creation, and hook registration.
434
+ *
435
+ * @param elem - Root Kayla element (usually JSX)
436
+ */
437
+ spawn(elem: KaylaElement<any>): void;
438
+ /**
439
+ * Detaches this scene from its game (if attached).
440
+ */
441
+ detach(): void;
442
+ private tickHandler;
443
+ }
444
+ const singleGlobalInstance: GlobalKayla;
445
+ }
446
+ /**
447
+ * Returns a stateful value and a setter to update it.
448
+ *
449
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
450
+ * The call order of all hooks is **strictly fixed** across every refresh; reordering calls will corrupt internal state.
451
+ *
452
+ * Calling the setter **may** schedule an entity refresh (re-execution of the component function),
453
+ * which re-binds all hooks to the same entity instance and potentially re-spawns children.
454
+ *
455
+ * **Critical performance warning:**
456
+ * **Do NOT** use `useState` for frequently-updated game data (position, velocity, rotation, timers, health deltas, etc.).
457
+ * Those **must** live in `useSelf` or plain `useRef`.
458
+ * `useState` is **only** for infrequent structural changes that should trigger refresh
459
+ * (e.g. `isDead` → spawn particles, `currentLevel` → reload map, `variant` → change sprite sheet).
460
+ *
461
+ * @template T The type of the state value
462
+ * @param initialValue Optional initial value
463
+ * @param options Configuration object
464
+ * @param options.alwaysRecall If `true`, **every** `.set()` call triggers a refresh (default: `false`)
465
+ * @returns A state wrapper with `.get()`, `.set()`, `.add()`, `.multiply()`, and `.lastChanged`
466
+ *
467
+ * @example Correct structural use
468
+ * const isDead = useState(false);
469
+ * if (health <= 0) isDead.set(true); // → refresh spawns death animation children
470
+ *
471
+ * @example Incorrect hot-data use (do NOT do this)
472
+ * const pos = useState({ x: 400, y: 300 }); // BAD — thrashing + GC pressure
473
+ */
474
+ declare const useState: <T>(initialValue?: T, { alwaysRecall }?: {
475
+ alwaysRecall?: boolean;
476
+ }) => KaylaInternals.KaylaState<T>;
477
+ /**
478
+ * Returns a mutable ref object whose `.current` property persists across entity refreshes.
479
+ *
480
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
481
+ * The call order of all hooks is **strictly fixed**; reordering calls will corrupt internal ref storage.
482
+ *
483
+ * Changes to `.current` **never** trigger refresh or re-bind hooks — refs are stable for the entity's lifetime.
484
+ *
485
+ * **Primary use:** Hold mutable game state, methods, timers, audio nodes, previous values, etc.
486
+ * For most entities, wrap your full logic in `useSelf()` instead (strongly recommended pattern).
487
+ *
488
+ * Special case: pass the `self` symbol to get the current LEA entity:
489
+ *
490
+ * @template T The type of the ref's value
491
+ * @param initialValue Initial value for `.current`, or `self` symbol for entity reference
492
+ * @returns A ref object with mutable `.current` property
493
+ *
494
+ * @example Entity reference
495
+ * const entity = useRef(self);
496
+ * entity.current.x += 10; // direct entity mutation, no refresh
497
+ *
498
+ * @example Mutable counter
499
+ * const timer = useRef(0);
500
+ * useTick(delta => { timer.current += delta; });
501
+ */
502
+ declare const useRef: {
503
+ (initialValue: typeof selfSym): KaylaElementRef;
504
+ <T>(initialValue: T | null): KaylaInternals.KaylaRef<T>;
505
+ };
506
+ /**
507
+ * Registers an effect that runs after entity creation and after every refresh.
508
+ *
509
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
510
+ * The call order of all hooks is **strictly fixed**; reordering calls will corrupt effect registration.
511
+ *
512
+ * The effect callback runs **synchronously** after refresh completes.
513
+ * If it returns a function, that cleanup runs **before** the next effect execution or when the entity is destroyed.
514
+ *
515
+ * Multiple `useEffect` calls **stack** — all run in declaration order.
516
+ * Effects are **re-registered** on every refresh (no dependency array in current version).
517
+ *
518
+ * **Use only for true side-effects** (event listeners, intervals, tweens, audio nodes, physics setup).
519
+ * For game logic, use `useTick` / `usePaint` / `useSelf` instead.
520
+ *
521
+ * @param effect Imperative function that may return a cleanup
522
+ */
523
+ declare const useEffect: (onEffect: KaylaInternals.KaylaInternalComponent["onEffect"][number]) => void;
524
+ /**
525
+ * Registers a callback that runs on every game tick (update phase).
526
+ *
527
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
528
+ * The call order of all hooks is **strictly fixed**; reordering calls will corrupt tick registration.
529
+ *
530
+ * Multiple `useTick` calls **stack** — all run in declaration order every tick.
531
+ * Call `event.preventDefault()` to skip remaining tick handlers for this entity (including default update).
532
+ *
533
+ * **Use for:** physics, movement, AI, timers, collision checks, input polling.
534
+ *
535
+ * @param callback Tick handler receiving delta time (seconds) and cancellable event
536
+ */
537
+ declare const useTick: (onTick: KaylaInternals.KaylaInternalComponent["onTick"][number]) => void;
538
+ /**
539
+ * Registers a callback that runs on every render frame (paint phase).
540
+ *
541
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
542
+ * The call order of all hooks is **strictly fixed**; reordering calls will corrupt paint registration.
543
+ *
544
+ * Multiple `usePaint` calls **stack** — all run in declaration order every frame.
545
+ * Call `event.preventDefault()` to skip remaining paint handlers (including default rect fill).
546
+ *
547
+ * **Use for:** drawing sprites, particles, health bars, debug overlays, name tags.
548
+ *
549
+ * @param callback Paint handler receiving canvas context and cancellable event
550
+ */
551
+ declare const usePaint: (onPaint: KaylaInternals.KaylaInternalComponent["onPaint"][number]) => void;
552
+ /**
553
+ * Defines the public API this entity exposes to its parent via the `exportsRef` prop.
554
+ *
555
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
556
+ * The call order of all hooks is **strictly fixed**; only **one** `useExports` call is allowed per component (later calls override earlier ones).
557
+ *
558
+ * The exporter function runs during every refresh; the returned object is assigned to `this.exports`.
559
+ * Parent receives it via `exportsRef.current` (stable reference).
560
+ *
561
+ * **Use for:** exposing methods (jump, takeDamage), getters (position, health), or state handles to parent.
562
+ *
563
+ * @template T The functional component type (used for type inference)
564
+ * @param component The component function itself (required for TypeScript inference)
565
+ * @param exporter Function returning the exportable values/methods
566
+ *
567
+ * @example
568
+ * useExports(Player, () => ({
569
+ * jump: () => { ... },
570
+ * getPosition: () => entity.current.pos.clone()
571
+ * }));
572
+ */
573
+ declare const useExports: <T extends FC<any, any>>(fc: T, onExport: KaylaInternals.KaylaInternalComponent<PropOfFC<T>, ExportsOfFC<T>>["onExport"]) => void;
574
+ /**
575
+ * Creates and returns a stable object (god-object) for holding most of an entity's state and logic.
576
+ *
577
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
578
+ * The call order of all hooks is **strictly fixed**; reordering calls will corrupt ref storage.
579
+ *
580
+ * The initializer runs **only once** (on first entity creation); the returned object is the **same reference** on every refresh.
581
+ *
582
+ * **Recommended pattern:** Put nearly all mutable state, methods, and game logic here.
583
+ * Use `useState` **only** for rare structural changes that should trigger refresh.
584
+ *
585
+ * @template T The type of the god-object
586
+ * @param init Factory function returning the object (called only once)
587
+ * @returns The initialized god-object (stable across refreshes)
588
+ *
589
+ * @example
590
+ * const self = useSelf(() => ({
591
+ * pos: new Vector2(400, 300),
592
+ * vel: new Vector2(100, 0),
593
+ * tick(delta) { this.pos.x += this.vel.x * delta; }
594
+ * }));
595
+ *
596
+ * useTick(delta => self.tick(delta));
597
+ */
598
+ declare const useSelf: <T>(init: () => T) => T;
599
+ /**
600
+ * Returns a direct reference to the underlying LEA entity instance managed by this component.
601
+ *
602
+ * **This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.**
603
+ * The call order of all hooks is **strictly fixed**; reordering calls will corrupt internal state.
604
+ *
605
+ * The returned reference is **stable** for the entity's lifetime and allows direct mutation of `x`, `y`, `z`, `width`, `height`, etc.
606
+ *
607
+ * @returns Reference to the `KaylaRectEntity` instance
608
+ */
609
+ declare const useEntity: () => KaylaElementRef;
610
+ /**
611
+ * Special symbol used to obtain a reference to the current entity.
612
+ *
613
+ * Pass this to `useRef` to get the underlying `KaylaRectEntity`:
614
+ *
615
+ * ```ts
616
+ * const entity = useRef(self);
617
+ * entity.current.x += 10;
618
+ * ```
619
+ *
620
+ * @see {@link useRef}
621
+ */
622
+ declare const selfSym: unique symbol;
623
+
624
+ /**
625
+ * Schedules a callback to run in the next microtask (via `Promise.resolve().then`).
626
+ *
627
+ * Used internally to defer entity refreshes safely and prevent synchronous re-entrancy.
628
+ * Rarely needed directly by users.
629
+ *
630
+ * @param callback - The function to schedule
631
+ */
632
+ declare const useNextStack: (callback: () => void) => void;
633
+ /**
634
+ * A fragment component that simply returns its children.
635
+ *
636
+ * Useful for grouping entities without adding an extra wrapper entity.
637
+ * Behaves like React.Fragment — no additional DOM/entity overhead.
638
+ *
639
+ * @example
640
+ * return (
641
+ * <KaylaFragment>
642
+ * <Enemy />
643
+ * <Coin />
644
+ * </KaylaFragment>
645
+ * );
646
+ *
647
+ * // Or shorthand:
648
+ * return (
649
+ * <>
650
+ * <Enemy />
651
+ * <Coin />
652
+ * </>
653
+ * );
654
+ */
655
+ declare const KaylaFragment: FC;
656
+ declare namespace JSX {
657
+ type Element = KaylaElement<any>;
658
+ interface IntrinsicElements {
659
+ }
660
+ type ElementType = FC<any>;
661
+ }
662
+ /**
663
+ * Marker type for values that can be exported from a component via `useExports`.
664
+ *
665
+ * Currently supports `KaylaState` or `KaylaRef` instances.
666
+ */
667
+ type KaylaExportables = KaylaState<any> | KaylaRef<any>;
668
+ /**
669
+ * Shape of the object returned by a component's `useExports` callback.
670
+ *
671
+ * @template StateMap - Record mapping export names to exportable values
672
+ */
673
+ type KaylaExports<StateMap extends Record<string, KaylaExportables>> = {
674
+ [K in keyof StateMap]: StateMap[K];
675
+ };
676
+ type PropOfFC<T extends FC<any, any>> = T extends FC<infer Props, any> ? Props : never;
677
+ type ExportsOfFC<T extends FC<any, any>> = T extends FC<any, infer Exports> ? Exports : never;
678
+ /**
679
+ * Creates a temporary ref object **outside** of component context.
680
+ *
681
+ * Unlike `useRef`, this ref **does not persist** across entity refreshes — it is recreated
682
+ * every time the component function runs. Use for one-off values or render-pass temporaries.
683
+ *
684
+ * @template T - Type of the ref's value
685
+ * @param initialValue - Initial value for `.current`
686
+ * @returns A fresh `KaylaRef` instance
687
+ *
688
+ * @example
689
+ * const temp = useDisposableRef({ count: 0 });
690
+ * // temp.current is only valid for this render
691
+ */
692
+ declare function useDisposableRef<T>(initialValue: T): KaylaInternals.KaylaRef<T>;
693
+ /**
694
+ * Reference type returned by `useEntity()` or passed via `ref` prop.
695
+ *
696
+ * Provides direct access to the underlying `KaylaRectEntity` (LEA entity wrapper).
697
+ */
698
+ interface KaylaElementRef extends KaylaRef<KaylaInternals.KaylaRectEntity> {
699
+ }
700
+
701
+ type kaylaInternals_ExportsOfFC<T extends FC<any, any>> = ExportsOfFC<T>;
702
+ type kaylaInternals_FC<Props extends FCProps = FCProps, Exports extends FCExports = FCExports> = FC<Props, Exports>;
703
+ type kaylaInternals_FCExports = FCExports;
704
+ type kaylaInternals_FCProps = FCProps;
705
+ declare const kaylaInternals_JSX: typeof JSX;
706
+ type kaylaInternals_KaylaElement<Props extends FCProps> = KaylaElement<Props>;
707
+ type kaylaInternals_KaylaElementRef = KaylaElementRef;
708
+ type kaylaInternals_KaylaExportables = KaylaExportables;
709
+ type kaylaInternals_KaylaExports<StateMap extends Record<string, KaylaExportables>> = KaylaExports<StateMap>;
710
+ declare const kaylaInternals_KaylaFragment: typeof KaylaFragment;
711
+ type kaylaInternals_KaylaGame = KaylaGame;
712
+ declare const kaylaInternals_KaylaInternals: typeof KaylaInternals;
713
+ type kaylaInternals_KaylaRef<T> = KaylaRef<T>;
714
+ type kaylaInternals_KaylaRenderer = KaylaRenderer;
715
+ type kaylaInternals_KaylaScene = KaylaScene;
716
+ type kaylaInternals_KaylaState<T> = KaylaState<T>;
717
+ type kaylaInternals_PropOfFC<T extends FC<any, any>> = PropOfFC<T>;
718
+ declare const kaylaInternals_createElement: typeof createElement;
719
+ declare const kaylaInternals_createGame: typeof createGame;
720
+ declare const kaylaInternals_createRenderer: typeof createRenderer;
721
+ declare const kaylaInternals_createScene: typeof createScene;
722
+ declare const kaylaInternals_useDisposableRef: typeof useDisposableRef;
723
+ declare const kaylaInternals_useEffect: typeof useEffect;
724
+ declare const kaylaInternals_useEntity: typeof useEntity;
725
+ declare const kaylaInternals_useExports: typeof useExports;
726
+ declare const kaylaInternals_useNextStack: typeof useNextStack;
727
+ declare const kaylaInternals_usePaint: typeof usePaint;
728
+ declare const kaylaInternals_useRef: typeof useRef;
729
+ declare const kaylaInternals_useSelf: typeof useSelf;
730
+ declare const kaylaInternals_useState: typeof useState;
731
+ declare const kaylaInternals_useTick: typeof useTick;
732
+ declare namespace kaylaInternals {
733
+ export { type kaylaInternals_ExportsOfFC as ExportsOfFC, type kaylaInternals_FC as FC, type kaylaInternals_FCExports as FCExports, type kaylaInternals_FCProps as FCProps, kaylaInternals_JSX as JSX, type kaylaInternals_KaylaElement as KaylaElement, type kaylaInternals_KaylaElementRef as KaylaElementRef, type kaylaInternals_KaylaExportables as KaylaExportables, type kaylaInternals_KaylaExports as KaylaExports, kaylaInternals_KaylaFragment as KaylaFragment, type kaylaInternals_KaylaGame as KaylaGame, kaylaInternals_KaylaInternals as KaylaInternals, type kaylaInternals_KaylaRef as KaylaRef, type kaylaInternals_KaylaRenderer as KaylaRenderer, type kaylaInternals_KaylaScene as KaylaScene, type kaylaInternals_KaylaState as KaylaState, type kaylaInternals_PropOfFC as PropOfFC, kaylaInternals_createElement as createElement, kaylaInternals_createGame as createGame, kaylaInternals_createRenderer as createRenderer, kaylaInternals_createScene as createScene, selfSym as self, kaylaInternals_useDisposableRef as useDisposableRef, kaylaInternals_useEffect as useEffect, kaylaInternals_useEntity as useEntity, kaylaInternals_useExports as useExports, kaylaInternals_useNextStack as useNextStack, kaylaInternals_usePaint as usePaint, kaylaInternals_useRef as useRef, kaylaInternals_useSelf as useSelf, kaylaInternals_useState as useState, kaylaInternals_useTick as useTick };
734
+ }
735
+
736
+ declare namespace UI {
737
+ interface UIProps extends FCProps {
738
+ x: number;
739
+ y: number;
740
+ width: number;
741
+ height: number;
742
+ onClick?: () => void;
743
+ }
744
+ const UIComponent: FC<UIProps>;
745
+ }
746
+
747
+ type Kayla_ExportsOfFC<T extends FC<any, any>> = ExportsOfFC<T>;
748
+ type Kayla_FC<Props extends FCProps = FCProps, Exports extends FCExports = FCExports> = FC<Props, Exports>;
749
+ type Kayla_FCExports = FCExports;
750
+ type Kayla_FCProps = FCProps;
751
+ declare const Kayla_JSX: typeof JSX;
752
+ type Kayla_KaylaElement<Props extends FCProps> = KaylaElement<Props>;
753
+ type Kayla_KaylaElementRef = KaylaElementRef;
754
+ type Kayla_KaylaExportables = KaylaExportables;
755
+ type Kayla_KaylaExports<StateMap extends Record<string, KaylaExportables>> = KaylaExports<StateMap>;
756
+ declare const Kayla_KaylaFragment: typeof KaylaFragment;
757
+ type Kayla_KaylaGame = KaylaGame;
758
+ declare const Kayla_KaylaInternals: typeof KaylaInternals;
759
+ type Kayla_KaylaRef<T> = KaylaRef<T>;
760
+ type Kayla_KaylaRenderer = KaylaRenderer;
761
+ type Kayla_KaylaScene = KaylaScene;
762
+ type Kayla_KaylaState<T> = KaylaState<T>;
763
+ type Kayla_PropOfFC<T extends FC<any, any>> = PropOfFC<T>;
764
+ declare const Kayla_UI: typeof UI;
765
+ declare const Kayla_createElement: typeof createElement;
766
+ declare const Kayla_createGame: typeof createGame;
767
+ declare const Kayla_createRenderer: typeof createRenderer;
768
+ declare const Kayla_createScene: typeof createScene;
769
+ declare const Kayla_useDisposableRef: typeof useDisposableRef;
770
+ declare const Kayla_useEffect: typeof useEffect;
771
+ declare const Kayla_useEntity: typeof useEntity;
772
+ declare const Kayla_useExports: typeof useExports;
773
+ declare const Kayla_useNextStack: typeof useNextStack;
774
+ declare const Kayla_usePaint: typeof usePaint;
775
+ declare const Kayla_useRef: typeof useRef;
776
+ declare const Kayla_useSelf: typeof useSelf;
777
+ declare const Kayla_useState: typeof useState;
778
+ declare const Kayla_useTick: typeof useTick;
779
+ declare namespace Kayla {
780
+ export { type Kayla_ExportsOfFC as ExportsOfFC, type Kayla_FC as FC, type Kayla_FCExports as FCExports, type Kayla_FCProps as FCProps, Kayla_JSX as JSX, kaylaInternals as Kayla, type Kayla_KaylaElement as KaylaElement, type Kayla_KaylaElementRef as KaylaElementRef, type Kayla_KaylaExportables as KaylaExportables, type Kayla_KaylaExports as KaylaExports, Kayla_KaylaFragment as KaylaFragment, type Kayla_KaylaGame as KaylaGame, Kayla_KaylaInternals as KaylaInternals, type Kayla_KaylaRef as KaylaRef, type Kayla_KaylaRenderer as KaylaRenderer, type Kayla_KaylaScene as KaylaScene, type Kayla_KaylaState as KaylaState, type Kayla_PropOfFC as PropOfFC, Kayla_UI as UI, Kayla_createElement as createElement, Kayla_createGame as createGame, Kayla_createRenderer as createRenderer, Kayla_createScene as createScene, selfSym as self, Kayla_useDisposableRef as useDisposableRef, Kayla_useEffect as useEffect, Kayla_useEntity as useEntity, Kayla_useExports as useExports, Kayla_useNextStack as useNextStack, Kayla_usePaint as usePaint, Kayla_useRef as useRef, Kayla_useSelf as useSelf, Kayla_useState as useState, Kayla_useTick as useTick };
781
+ }
782
+
783
+ export { useSelf as A, useState as B, useTick as C, type ExportsOfFC as E, type FC as F, JSX as J, Kayla as K, type PropOfFC as P, UI as U, type FCExports as a, type FCProps as b, type KaylaElement as c, type KaylaElementRef as d, type KaylaExportables as e, type KaylaExports as f, KaylaFragment as g, KaylaGame as h, KaylaInternals as i, KaylaRef as j, kaylaInternals as k, KaylaRenderer as l, KaylaScene as m, KaylaState as n, createElement as o, createGame as p, createRenderer as q, createScene as r, selfSym as s, useEffect as t, useDisposableRef as u, useEntity as v, useExports as w, useNextStack as x, usePaint as y, useRef as z };