@blorkfield/overlay-core 0.11.2 → 0.11.4
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/README.md +6 -3
- package/dist/index.cjs +68 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -19,6 +19,14 @@ interface OverlaySceneConfig {
|
|
|
19
19
|
despawnBelowFloor?: number;
|
|
20
20
|
/** Configuration for floor segments and thresholds */
|
|
21
21
|
floorConfig?: FloorConfig;
|
|
22
|
+
/**
|
|
23
|
+
* When true, every call to resize(newW, newH) translates all objects by half the dimension
|
|
24
|
+
* change so the scene centre stays visually centred. Objects keep their size and position
|
|
25
|
+
* relative to each other — only their absolute pixel coordinates shift.
|
|
26
|
+
* Useful for responsive canvases and phone rotation (portrait ↔ landscape).
|
|
27
|
+
* Default: false
|
|
28
|
+
*/
|
|
29
|
+
rescaleOnResize?: boolean;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* Configuration for floor segments and pressure thresholds.
|
|
@@ -609,6 +617,14 @@ declare class OverlayScene {
|
|
|
609
617
|
private handleMouseUp;
|
|
610
618
|
/** Handle canvas clicks for click-to-fall behavior */
|
|
611
619
|
private handleCanvasClick;
|
|
620
|
+
/** Shared tap logic for mouse click and touch tap */
|
|
621
|
+
private handleTap;
|
|
622
|
+
/** Handle touch start — single finger grabs, multi-finger passes through for scroll/zoom */
|
|
623
|
+
private handleTouchStart;
|
|
624
|
+
/** Handle touch move — only tracks if something is grabbed */
|
|
625
|
+
private handleTouchMove;
|
|
626
|
+
/** Handle touch end/cancel — release grab; if it was a tap (no grab), trigger click-to-fall */
|
|
627
|
+
private handleTouchEnd;
|
|
612
628
|
/**
|
|
613
629
|
* Handler for Matter.js beforeRender event.
|
|
614
630
|
* Draws base background layers (color + image) before physics objects.
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,14 @@ interface OverlaySceneConfig {
|
|
|
19
19
|
despawnBelowFloor?: number;
|
|
20
20
|
/** Configuration for floor segments and thresholds */
|
|
21
21
|
floorConfig?: FloorConfig;
|
|
22
|
+
/**
|
|
23
|
+
* When true, every call to resize(newW, newH) translates all objects by half the dimension
|
|
24
|
+
* change so the scene centre stays visually centred. Objects keep their size and position
|
|
25
|
+
* relative to each other — only their absolute pixel coordinates shift.
|
|
26
|
+
* Useful for responsive canvases and phone rotation (portrait ↔ landscape).
|
|
27
|
+
* Default: false
|
|
28
|
+
*/
|
|
29
|
+
rescaleOnResize?: boolean;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* Configuration for floor segments and pressure thresholds.
|
|
@@ -609,6 +617,14 @@ declare class OverlayScene {
|
|
|
609
617
|
private handleMouseUp;
|
|
610
618
|
/** Handle canvas clicks for click-to-fall behavior */
|
|
611
619
|
private handleCanvasClick;
|
|
620
|
+
/** Shared tap logic for mouse click and touch tap */
|
|
621
|
+
private handleTap;
|
|
622
|
+
/** Handle touch start — single finger grabs, multi-finger passes through for scroll/zoom */
|
|
623
|
+
private handleTouchStart;
|
|
624
|
+
/** Handle touch move — only tracks if something is grabbed */
|
|
625
|
+
private handleTouchMove;
|
|
626
|
+
/** Handle touch end/cancel — release grab; if it was a tap (no grab), trigger click-to-fall */
|
|
627
|
+
private handleTouchEnd;
|
|
612
628
|
/**
|
|
613
629
|
* Handler for Matter.js beforeRender event.
|
|
614
630
|
* Draws base background layers (color + image) before physics objects.
|
package/dist/index.js
CHANGED
|
@@ -1470,6 +1470,10 @@ var OverlayScene = class {
|
|
|
1470
1470
|
const rect = this.canvas.getBoundingClientRect();
|
|
1471
1471
|
const x = event.clientX - rect.left;
|
|
1472
1472
|
const y = event.clientY - rect.top;
|
|
1473
|
+
this.handleTap(x, y);
|
|
1474
|
+
};
|
|
1475
|
+
/** Shared tap logic for mouse click and touch tap */
|
|
1476
|
+
this.handleTap = (x, y) => {
|
|
1473
1477
|
const bodies = Matter5.Query.point(
|
|
1474
1478
|
Matter5.Composite.allBodies(this.engine.world),
|
|
1475
1479
|
{ x, y }
|
|
@@ -1487,6 +1491,42 @@ var OverlayScene = class {
|
|
|
1487
1491
|
}
|
|
1488
1492
|
}
|
|
1489
1493
|
};
|
|
1494
|
+
/** Handle touch start — single finger grabs, multi-finger passes through for scroll/zoom */
|
|
1495
|
+
this.handleTouchStart = (event) => {
|
|
1496
|
+
if (event.touches.length >= 2) return;
|
|
1497
|
+
const touch = event.touches[0];
|
|
1498
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
1499
|
+
const x = touch.clientX - rect.left;
|
|
1500
|
+
const y = touch.clientY - rect.top;
|
|
1501
|
+
this.followTargets.set("mouse", { x, y });
|
|
1502
|
+
const grabbed = this.startGrab();
|
|
1503
|
+
if (grabbed) event.preventDefault();
|
|
1504
|
+
};
|
|
1505
|
+
/** Handle touch move — only tracks if something is grabbed */
|
|
1506
|
+
this.handleTouchMove = (event) => {
|
|
1507
|
+
if (event.touches.length >= 2) return;
|
|
1508
|
+
if (!this.grabbedObjectId) return;
|
|
1509
|
+
event.preventDefault();
|
|
1510
|
+
const touch = event.touches[0];
|
|
1511
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
1512
|
+
const x = touch.clientX - rect.left;
|
|
1513
|
+
const y = touch.clientY - rect.top;
|
|
1514
|
+
this.followTargets.set("mouse", { x, y });
|
|
1515
|
+
};
|
|
1516
|
+
/** Handle touch end/cancel — release grab; if it was a tap (no grab), trigger click-to-fall */
|
|
1517
|
+
this.handleTouchEnd = (event) => {
|
|
1518
|
+
const wasGrabbed = this.grabbedObjectId !== null;
|
|
1519
|
+
this.endGrab();
|
|
1520
|
+
if (wasGrabbed) {
|
|
1521
|
+
event.preventDefault();
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
if (event.changedTouches.length > 0) {
|
|
1525
|
+
const touch = event.changedTouches[0];
|
|
1526
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
1527
|
+
this.handleTap(touch.clientX - rect.left, touch.clientY - rect.top);
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1490
1530
|
/**
|
|
1491
1531
|
* Handler for Matter.js beforeRender event.
|
|
1492
1532
|
* Draws base background layers (color + image) before physics objects.
|
|
@@ -1639,6 +1679,10 @@ var OverlayScene = class {
|
|
|
1639
1679
|
canvas.addEventListener("mousemove", this.handleMouseMove);
|
|
1640
1680
|
canvas.addEventListener("mouseup", this.handleMouseUp);
|
|
1641
1681
|
canvas.addEventListener("click", this.handleCanvasClick);
|
|
1682
|
+
canvas.addEventListener("touchstart", this.handleTouchStart, { passive: false });
|
|
1683
|
+
canvas.addEventListener("touchmove", this.handleTouchMove, { passive: false });
|
|
1684
|
+
canvas.addEventListener("touchend", this.handleTouchEnd, { passive: false });
|
|
1685
|
+
canvas.addEventListener("touchcancel", this.handleTouchEnd, { passive: false });
|
|
1642
1686
|
this.effectManager = new EffectManager(
|
|
1643
1687
|
this.config.bounds,
|
|
1644
1688
|
(cfg) => this.spawnObjectAsync(cfg),
|
|
@@ -2063,6 +2107,10 @@ var OverlayScene = class {
|
|
|
2063
2107
|
this.canvas.removeEventListener("mousemove", this.handleMouseMove);
|
|
2064
2108
|
this.canvas.removeEventListener("mouseup", this.handleMouseUp);
|
|
2065
2109
|
this.canvas.removeEventListener("click", this.handleCanvasClick);
|
|
2110
|
+
this.canvas.removeEventListener("touchstart", this.handleTouchStart);
|
|
2111
|
+
this.canvas.removeEventListener("touchmove", this.handleTouchMove);
|
|
2112
|
+
this.canvas.removeEventListener("touchend", this.handleTouchEnd);
|
|
2113
|
+
this.canvas.removeEventListener("touchcancel", this.handleTouchEnd);
|
|
2066
2114
|
Matter5.Events.off(this.render, "beforeRender", this.handleBeforeRender);
|
|
2067
2115
|
Matter5.Events.off(this.render, "afterRender", this.handleAfterRender);
|
|
2068
2116
|
Matter5.Events.off(this.engine, "collisionStart", this.handleCollisionStart);
|
|
@@ -2206,6 +2254,26 @@ var OverlayScene = class {
|
|
|
2206
2254
|
}
|
|
2207
2255
|
}
|
|
2208
2256
|
resize(width, height) {
|
|
2257
|
+
if (this.config.rescaleOnResize) {
|
|
2258
|
+
const dx = (width - this.config.bounds.right) / 2;
|
|
2259
|
+
const dy = (height - this.config.bounds.bottom) / 2;
|
|
2260
|
+
for (const entry of this.objects.values()) {
|
|
2261
|
+
const { x, y } = entry.body.position;
|
|
2262
|
+
Matter5.Body.setPosition(entry.body, { x: x + dx, y: y + dy });
|
|
2263
|
+
if (entry.originalPosition) {
|
|
2264
|
+
entry.originalPosition = {
|
|
2265
|
+
x: entry.originalPosition.x + dx,
|
|
2266
|
+
y: entry.originalPosition.y + dy
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
if (entry.domShadowElement) {
|
|
2270
|
+
const currentLeft = parseFloat(entry.domShadowElement.style.left) || 0;
|
|
2271
|
+
const currentTop = parseFloat(entry.domShadowElement.style.top) || 0;
|
|
2272
|
+
entry.domShadowElement.style.setProperty("left", `${currentLeft + dx}px`, "important");
|
|
2273
|
+
entry.domShadowElement.style.setProperty("top", `${currentTop + dy}px`, "important");
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2209
2277
|
this.canvas.width = width;
|
|
2210
2278
|
this.canvas.height = height;
|
|
2211
2279
|
this.config.bounds = { top: 0, bottom: height, left: 0, right: width };
|