@bloopjs/web 0.0.106 → 0.0.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloopjs/web",
3
- "version": "0.0.106",
3
+ "version": "0.0.108",
4
4
  "author": "Neil Sarkar",
5
5
  "type": "module",
6
6
  "repository": {
@@ -37,8 +37,8 @@
37
37
  "typescript": "^5"
38
38
  },
39
39
  "dependencies": {
40
- "@bloopjs/bloop": "0.0.106",
41
- "@bloopjs/engine": "0.0.106",
40
+ "@bloopjs/bloop": "0.0.108",
41
+ "@bloopjs/engine": "0.0.108",
42
42
  "@preact/signals": "^1.3.1",
43
43
  "partysocket": "^1.1.6",
44
44
  "preact": "^10.25.4"
package/src/App.ts CHANGED
@@ -39,6 +39,8 @@ export type StartOptions = {
39
39
  debugUi?: boolean | DebugUiOptions;
40
40
  /** Tape recording options */
41
41
  tape?: MountOptions["tape"];
42
+ /** External canvas element to use (preserves user CSS via slot projection) */
43
+ canvas?: HTMLCanvasElement;
42
44
  };
43
45
 
44
46
  const DEFAULT_BROKER_URL = "wss://webrtc-divine-glade-8064.fly.dev/ws";
@@ -55,9 +57,11 @@ export async function start(opts: StartOptions): Promise<App> {
55
57
 
56
58
  const debugOpts = opts.debugUi
57
59
  ? typeof opts.debugUi === "boolean"
58
- ? { initiallyVisible: true }
59
- : opts.debugUi
60
- : undefined;
60
+ ? { initiallyVisible: true, canvas: opts.canvas }
61
+ : { ...opts.debugUi, canvas: opts.canvas ?? opts.debugUi.canvas }
62
+ : opts.canvas
63
+ ? { canvas: opts.canvas }
64
+ : undefined;
61
65
 
62
66
  const app = new App(
63
67
  opts.sim,
@@ -10,6 +10,8 @@ export type DebugUiOptions = {
10
10
  initiallyVisible?: boolean;
11
11
  /** Container element to mount to (default: document.body) */
12
12
  container?: HTMLElement;
13
+ /** External canvas element to use (preserves user CSS via slot projection) */
14
+ canvas?: HTMLCanvasElement;
13
15
  };
14
16
 
15
17
  export class DebugUi {
@@ -49,8 +51,8 @@ export class DebugUi {
49
51
  // Initialize state
50
52
  debugState.layoutMode.value = initiallyVisible ? "letterboxed" : "off";
51
53
 
52
- // Create canvas element (game renders here)
53
- this.#canvas = document.createElement("canvas");
54
+ // Use provided canvas or create new one
55
+ this.#canvas = options.canvas ?? document.createElement("canvas");
54
56
 
55
57
  // Render Preact app
56
58
  this.#render();
@@ -68,10 +70,7 @@ export class DebugUi {
68
70
  }
69
71
 
70
72
  #render(): void {
71
- render(
72
- Root({ canvas: this.#canvas, hotkey: this.#hotkey }),
73
- this.#mountPoint,
74
- );
73
+ render(Root({ canvas: this.#canvas, hotkey: this.#hotkey }), this.#mountPoint);
75
74
  }
76
75
 
77
76
  #setupHotkey(): () => void {
@@ -121,10 +121,6 @@ function GameCanvas({ canvas }: { canvas: HTMLCanvasElement }) {
121
121
  if (container && !container.contains(canvas)) {
122
122
  container.appendChild(canvas);
123
123
  }
124
-
125
- return () => {
126
- // Don't remove canvas on cleanup - it may need to persist
127
- };
128
124
  }, [canvas]);
129
125
 
130
126
  return <div className="canvas-container" ref={containerRef} />;