@blorkfield/overlay-core 0.8.5 → 0.8.6

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/index.cjs CHANGED
@@ -1421,7 +1421,6 @@ var OverlayScene = class {
1421
1421
  this.updateCallbacks = [];
1422
1422
  this.animationFrameId = null;
1423
1423
  this.mouse = null;
1424
- this.mouseConstraint = null;
1425
1424
  this.fonts = [];
1426
1425
  this.fontsInitialized = false;
1427
1426
  this.letterDebugInfo = /* @__PURE__ */ new Map();
@@ -1443,19 +1442,9 @@ var OverlayScene = class {
1443
1442
  };
1444
1443
  // Follow targets for follow-{key} tagged objects
1445
1444
  this.followTargets = /* @__PURE__ */ new Map();
1446
- // Programmatic grab state - tracks initial positions for relative movement
1447
- this.grabState = null;
1448
- /** Filter drag events - only allow grabbing objects with 'grabable' tag */
1449
- this.handleStartDrag = (event) => {
1450
- const body = event.body;
1451
- if (!body) return;
1452
- const entry = this.findObjectByBody(body);
1453
- if (!entry || !entry.tags.includes("grabable")) {
1454
- if (this.mouseConstraint) {
1455
- this.mouseConstraint.constraint.bodyB = null;
1456
- }
1457
- }
1458
- };
1445
+ // Delta-based grab tracking (no constraint physics)
1446
+ this.grabbedObjectId = null;
1447
+ this.lastGrabMousePosition = null;
1459
1448
  /** Handle canvas clicks for click-to-fall behavior */
1460
1449
  this.handleCanvasClick = (event) => {
1461
1450
  const rect = this.canvas.getBoundingClientRect();
@@ -1520,8 +1509,20 @@ var OverlayScene = class {
1520
1509
  if (!this.followTargets.has("mouse") && this.mouse) {
1521
1510
  this.followTargets.set("mouse", { x: this.mouse.position.x, y: this.mouse.position.y });
1522
1511
  }
1512
+ if (this.grabbedObjectId && this.lastGrabMousePosition) {
1513
+ const entry = this.objects.get(this.grabbedObjectId);
1514
+ const mouseTarget = this.followTargets.get("mouse");
1515
+ if (entry && mouseTarget) {
1516
+ const dx = mouseTarget.x - this.lastGrabMousePosition.x;
1517
+ const dy = mouseTarget.y - this.lastGrabMousePosition.y;
1518
+ if (dx !== 0 || dy !== 0) {
1519
+ import_matter_js5.default.Body.translate(entry.body, { x: dx, y: dy });
1520
+ }
1521
+ this.lastGrabMousePosition = { x: mouseTarget.x, y: mouseTarget.y };
1522
+ }
1523
+ }
1523
1524
  for (const entry of this.objects.values()) {
1524
- const isDragging = this.mouseConstraint?.body === entry.body;
1525
+ const isDragging = this.grabbedObjectId === entry.id;
1525
1526
  if (!isDragging) {
1526
1527
  for (const tag of entry.tags) {
1527
1528
  const key = tag === "follow" ? "mouse" : tag.startsWith("follow-") ? tag.slice(7) : null;
@@ -1569,24 +1570,7 @@ var OverlayScene = class {
1569
1570
  import_matter_js5.default.Composite.add(this.engine.world, this.boundaries);
1570
1571
  this.checkInitialFloorIntegrity();
1571
1572
  this.mouse = import_matter_js5.default.Mouse.create(canvas);
1572
- this.mouseConstraint = import_matter_js5.default.MouseConstraint.create(this.engine, {
1573
- mouse: this.mouse,
1574
- constraint: {
1575
- stiffness: 0.2,
1576
- render: { visible: false }
1577
- }
1578
- });
1579
- import_matter_js5.default.Composite.add(this.engine.world, this.mouseConstraint);
1580
- const wheelHandler = this.mouse.mousewheel;
1581
- if (wheelHandler) {
1582
- canvas.removeEventListener("mousewheel", wheelHandler);
1583
- canvas.removeEventListener("DOMMouseScroll", wheelHandler);
1584
- canvas.removeEventListener("wheel", wheelHandler);
1585
- }
1586
- canvas.style.touchAction = "pan-x pan-y";
1587
- import_matter_js5.default.Events.on(this.mouseConstraint, "startdrag", this.handleStartDrag);
1588
1573
  canvas.addEventListener("click", this.handleCanvasClick);
1589
- this.render.mouse = this.mouse;
1590
1574
  this.effectManager = new EffectManager(
1591
1575
  this.config.bounds,
1592
1576
  (cfg) => this.spawnObjectAsync(cfg),
@@ -2008,9 +1992,6 @@ var OverlayScene = class {
2008
1992
  }
2009
1993
  destroy() {
2010
1994
  this.stop();
2011
- if (this.mouseConstraint) {
2012
- import_matter_js5.default.Events.off(this.mouseConstraint, "startdrag", this.handleStartDrag);
2013
- }
2014
1995
  this.canvas.removeEventListener("click", this.handleCanvasClick);
2015
1996
  import_matter_js5.default.Events.off(this.render, "beforeRender", this.handleBeforeRender);
2016
1997
  import_matter_js5.default.Events.off(this.render, "afterRender", this.handleAfterRender);
@@ -2338,23 +2319,6 @@ var OverlayScene = class {
2338
2319
  */
2339
2320
  setFollowTarget(key, x, y) {
2340
2321
  this.followTargets.set(key, { x, y });
2341
- if (key === "mouse" && this.mouse) {
2342
- if (this.grabState && this.mouseConstraint?.constraint.bodyB) {
2343
- const deltaX = x - this.grabState.grabMouseX;
2344
- const deltaY = y - this.grabState.grabMouseY;
2345
- const newX = this.grabState.grabBodyX + deltaX;
2346
- const newY = this.grabState.grabBodyY + deltaY;
2347
- this.mouse.position.x = newX;
2348
- this.mouse.position.y = newY;
2349
- this.mouse.absolute.x = newX;
2350
- this.mouse.absolute.y = newY;
2351
- } else {
2352
- this.mouse.position.x = x;
2353
- this.mouse.position.y = y;
2354
- this.mouse.absolute.x = x;
2355
- this.mouse.absolute.y = y;
2356
- }
2357
- }
2358
2322
  }
2359
2323
  /**
2360
2324
  * Remove a follow target. Objects with the corresponding tag will stop following.
@@ -2379,9 +2343,9 @@ var OverlayScene = class {
2379
2343
  * @returns The ID of the grabbed object, or null if no grabable object at position
2380
2344
  */
2381
2345
  startGrab() {
2382
- if (!this.mouseConstraint || !this.mouse) return null;
2383
2346
  const mouseTarget = this.followTargets.get("mouse");
2384
- const position = mouseTarget ?? { x: this.mouse.position.x, y: this.mouse.position.y };
2347
+ const position = mouseTarget ?? (this.mouse ? { x: this.mouse.position.x, y: this.mouse.position.y } : null);
2348
+ if (!position) return null;
2385
2349
  const bodies = import_matter_js5.default.Query.point(
2386
2350
  import_matter_js5.default.Composite.allBodies(this.engine.world),
2387
2351
  position
@@ -2389,30 +2353,8 @@ var OverlayScene = class {
2389
2353
  for (const body of bodies) {
2390
2354
  const entry = this.findObjectByBody(body);
2391
2355
  if (entry && entry.tags.includes("grabable")) {
2392
- this.mouse.button = 0;
2393
- this.grabState = {
2394
- entityId: entry.id,
2395
- grabMouseX: position.x,
2396
- grabMouseY: position.y,
2397
- grabBodyX: entry.body.position.x,
2398
- grabBodyY: entry.body.position.y
2399
- };
2400
- this.mouseConstraint.constraint.pointA = {
2401
- x: entry.body.position.x,
2402
- y: entry.body.position.y
2403
- };
2404
- this.mouseConstraint.constraint.bodyB = entry.body;
2405
- this.mouseConstraint.constraint.pointB = { x: 0, y: 0 };
2406
- this.mouse.position.x = entry.body.position.x;
2407
- this.mouse.position.y = entry.body.position.y;
2408
- this.mouse.absolute.x = entry.body.position.x;
2409
- this.mouse.absolute.y = entry.body.position.y;
2410
- console.log("[overlay-core] startGrab success", {
2411
- entityId: entry.id,
2412
- mousePosition: position,
2413
- bodyPosition: { x: entry.body.position.x, y: entry.body.position.y },
2414
- grabState: this.grabState
2415
- });
2356
+ this.grabbedObjectId = entry.id;
2357
+ this.lastGrabMousePosition = { x: position.x, y: position.y };
2416
2358
  return entry.id;
2417
2359
  }
2418
2360
  }
@@ -2422,22 +2364,15 @@ var OverlayScene = class {
2422
2364
  * Release any currently grabbed object.
2423
2365
  */
2424
2366
  endGrab() {
2425
- if (this.mouseConstraint) {
2426
- this.mouseConstraint.constraint.bodyB = null;
2427
- }
2428
- if (this.mouse) {
2429
- this.mouse.button = -1;
2430
- }
2431
- this.grabState = null;
2367
+ this.grabbedObjectId = null;
2368
+ this.lastGrabMousePosition = null;
2432
2369
  }
2433
2370
  /**
2434
2371
  * Get the ID of the currently grabbed object.
2435
2372
  * @returns The ID of the grabbed object, or null if nothing is grabbed
2436
2373
  */
2437
2374
  getGrabbedObject() {
2438
- if (!this.mouseConstraint?.constraint.bodyB) return null;
2439
- const entry = this.findObjectByBody(this.mouseConstraint.constraint.bodyB);
2440
- return entry?.id ?? null;
2375
+ return this.grabbedObjectId;
2441
2376
  }
2442
2377
  // ==================== PHYSICS MANIPULATION METHODS ====================
2443
2378
  /**