@bloopjs/web 0.0.89 → 0.0.90
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/dist/App.d.ts.map +1 -1
- package/dist/mod.js +151 -7
- package/dist/mod.js.map +5 -5
- package/package.json +3 -3
- package/src/App.ts +60 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloopjs/web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
4
4
|
"author": "Neil Sarkar",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"typescript": "^5"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@bloopjs/bloop": "0.0.
|
|
37
|
-
"@bloopjs/engine": "0.0.
|
|
36
|
+
"@bloopjs/bloop": "0.0.90",
|
|
37
|
+
"@bloopjs/engine": "0.0.90",
|
|
38
38
|
"@preact/signals": "^1.3.1",
|
|
39
39
|
"partysocket": "^1.1.6",
|
|
40
40
|
"preact": "^10.25.4"
|
package/src/App.ts
CHANGED
|
@@ -179,6 +179,63 @@ export class App {
|
|
|
179
179
|
// Skip emitting input events during replay to avoid filling the event buffer
|
|
180
180
|
const shouldEmitInputs = () => !this.sim.isReplaying;
|
|
181
181
|
|
|
182
|
+
// Resize handling - emits resize events when viewport changes
|
|
183
|
+
let resizeObserver: ResizeObserver | null = null;
|
|
184
|
+
let cleanupPixelRatio: (() => void) | null = null;
|
|
185
|
+
|
|
186
|
+
const emitResize = () => {
|
|
187
|
+
const canvas = this.canvas;
|
|
188
|
+
const pixelRatio = window.devicePixelRatio || 1;
|
|
189
|
+
|
|
190
|
+
let width: number;
|
|
191
|
+
let height: number;
|
|
192
|
+
|
|
193
|
+
if (canvas) {
|
|
194
|
+
const rect = canvas.getBoundingClientRect();
|
|
195
|
+
width = Math.round(rect.width);
|
|
196
|
+
height = Math.round(rect.height);
|
|
197
|
+
} else {
|
|
198
|
+
// Fallback to window dimensions if no canvas
|
|
199
|
+
width = window.innerWidth;
|
|
200
|
+
height = window.innerHeight;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
this.sim.emit.resize(
|
|
204
|
+
width,
|
|
205
|
+
height,
|
|
206
|
+
Math.round(width * pixelRatio),
|
|
207
|
+
Math.round(height * pixelRatio),
|
|
208
|
+
pixelRatio,
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// Observe canvas size changes
|
|
213
|
+
const canvas = this.canvas;
|
|
214
|
+
if (canvas) {
|
|
215
|
+
resizeObserver = new ResizeObserver(() => emitResize());
|
|
216
|
+
resizeObserver.observe(canvas);
|
|
217
|
+
} else {
|
|
218
|
+
// Fallback: observe window resize if no canvas
|
|
219
|
+
window.addEventListener("resize", emitResize);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Detect devicePixelRatio changes (monitor switch, browser zoom)
|
|
223
|
+
const updatePixelRatioListener = () => {
|
|
224
|
+
const mediaQuery = window.matchMedia(
|
|
225
|
+
`(resolution: ${window.devicePixelRatio}dppx)`,
|
|
226
|
+
);
|
|
227
|
+
const handler = () => {
|
|
228
|
+
emitResize();
|
|
229
|
+
updatePixelRatioListener(); // Re-register for new ratio
|
|
230
|
+
};
|
|
231
|
+
mediaQuery.addEventListener("change", handler, { once: true });
|
|
232
|
+
return () => mediaQuery.removeEventListener("change", handler);
|
|
233
|
+
};
|
|
234
|
+
cleanupPixelRatio = updatePixelRatioListener();
|
|
235
|
+
|
|
236
|
+
// Emit initial resize event
|
|
237
|
+
emitResize();
|
|
238
|
+
|
|
182
239
|
const handleKeydown = (event: KeyboardEvent) => {
|
|
183
240
|
if (shouldEmitInputs()) this.sim.emit.keydown(event.code as Key);
|
|
184
241
|
};
|
|
@@ -360,6 +417,9 @@ export class App {
|
|
|
360
417
|
window.removeEventListener("touchstart", handleTouchstart);
|
|
361
418
|
window.removeEventListener("touchend", handleTouchend);
|
|
362
419
|
window.removeEventListener("touchmove", handleTouchmove);
|
|
420
|
+
window.removeEventListener("resize", emitResize);
|
|
421
|
+
resizeObserver?.disconnect();
|
|
422
|
+
cleanupPixelRatio?.();
|
|
363
423
|
if (this.#rafHandle != null) {
|
|
364
424
|
cancelAnimationFrame(this.#rafHandle);
|
|
365
425
|
}
|