@blorkfield/overlay-core 0.8.3 → 0.8.5
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 +9 -10
- package/dist/index.cjs +40 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -551,6 +551,7 @@ declare class OverlayScene {
|
|
|
551
551
|
private backgroundManager;
|
|
552
552
|
private lifecycleCallbacks;
|
|
553
553
|
private followTargets;
|
|
554
|
+
private grabState;
|
|
554
555
|
static createContainer(parent: HTMLElement, options?: ContainerOptions): {
|
|
555
556
|
canvas: HTMLCanvasElement;
|
|
556
557
|
bounds: Bounds;
|
package/dist/index.d.ts
CHANGED
|
@@ -551,6 +551,7 @@ declare class OverlayScene {
|
|
|
551
551
|
private backgroundManager;
|
|
552
552
|
private lifecycleCallbacks;
|
|
553
553
|
private followTargets;
|
|
554
|
+
private grabState;
|
|
554
555
|
static createContainer(parent: HTMLElement, options?: ContainerOptions): {
|
|
555
556
|
canvas: HTMLCanvasElement;
|
|
556
557
|
bounds: Bounds;
|
package/dist/index.js
CHANGED
|
@@ -1398,6 +1398,8 @@ var OverlayScene = class {
|
|
|
1398
1398
|
};
|
|
1399
1399
|
// Follow targets for follow-{key} tagged objects
|
|
1400
1400
|
this.followTargets = /* @__PURE__ */ new Map();
|
|
1401
|
+
// Programmatic grab state - tracks initial positions for relative movement
|
|
1402
|
+
this.grabState = null;
|
|
1401
1403
|
/** Filter drag events - only allow grabbing objects with 'grabable' tag */
|
|
1402
1404
|
this.handleStartDrag = (event) => {
|
|
1403
1405
|
const body = event.body;
|
|
@@ -2292,10 +2294,21 @@ var OverlayScene = class {
|
|
|
2292
2294
|
setFollowTarget(key, x, y) {
|
|
2293
2295
|
this.followTargets.set(key, { x, y });
|
|
2294
2296
|
if (key === "mouse" && this.mouse) {
|
|
2295
|
-
this.
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2297
|
+
if (this.grabState && this.mouseConstraint?.constraint.bodyB) {
|
|
2298
|
+
const deltaX = x - this.grabState.grabMouseX;
|
|
2299
|
+
const deltaY = y - this.grabState.grabMouseY;
|
|
2300
|
+
const newX = this.grabState.grabBodyX + deltaX;
|
|
2301
|
+
const newY = this.grabState.grabBodyY + deltaY;
|
|
2302
|
+
this.mouse.position.x = newX;
|
|
2303
|
+
this.mouse.position.y = newY;
|
|
2304
|
+
this.mouse.absolute.x = newX;
|
|
2305
|
+
this.mouse.absolute.y = newY;
|
|
2306
|
+
} else {
|
|
2307
|
+
this.mouse.position.x = x;
|
|
2308
|
+
this.mouse.position.y = y;
|
|
2309
|
+
this.mouse.absolute.x = x;
|
|
2310
|
+
this.mouse.absolute.y = y;
|
|
2311
|
+
}
|
|
2299
2312
|
}
|
|
2300
2313
|
}
|
|
2301
2314
|
/**
|
|
@@ -2332,11 +2345,29 @@ var OverlayScene = class {
|
|
|
2332
2345
|
const entry = this.findObjectByBody(body);
|
|
2333
2346
|
if (entry && entry.tags.includes("grabable")) {
|
|
2334
2347
|
this.mouse.button = 0;
|
|
2335
|
-
this.
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2348
|
+
this.grabState = {
|
|
2349
|
+
entityId: entry.id,
|
|
2350
|
+
grabMouseX: position.x,
|
|
2351
|
+
grabMouseY: position.y,
|
|
2352
|
+
grabBodyX: entry.body.position.x,
|
|
2353
|
+
grabBodyY: entry.body.position.y
|
|
2339
2354
|
};
|
|
2355
|
+
this.mouseConstraint.constraint.pointA = {
|
|
2356
|
+
x: entry.body.position.x,
|
|
2357
|
+
y: entry.body.position.y
|
|
2358
|
+
};
|
|
2359
|
+
this.mouseConstraint.constraint.bodyB = entry.body;
|
|
2360
|
+
this.mouseConstraint.constraint.pointB = { x: 0, y: 0 };
|
|
2361
|
+
this.mouse.position.x = entry.body.position.x;
|
|
2362
|
+
this.mouse.position.y = entry.body.position.y;
|
|
2363
|
+
this.mouse.absolute.x = entry.body.position.x;
|
|
2364
|
+
this.mouse.absolute.y = entry.body.position.y;
|
|
2365
|
+
console.log("[overlay-core] startGrab success", {
|
|
2366
|
+
entityId: entry.id,
|
|
2367
|
+
mousePosition: position,
|
|
2368
|
+
bodyPosition: { x: entry.body.position.x, y: entry.body.position.y },
|
|
2369
|
+
grabState: this.grabState
|
|
2370
|
+
});
|
|
2340
2371
|
return entry.id;
|
|
2341
2372
|
}
|
|
2342
2373
|
}
|
|
@@ -2352,6 +2383,7 @@ var OverlayScene = class {
|
|
|
2352
2383
|
if (this.mouse) {
|
|
2353
2384
|
this.mouse.button = -1;
|
|
2354
2385
|
}
|
|
2386
|
+
this.grabState = null;
|
|
2355
2387
|
}
|
|
2356
2388
|
/**
|
|
2357
2389
|
* Get the ID of the currently grabbed object.
|