minerender 2.1.0-alpha.117 → 2.1.0-alpha.118

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.
@@ -13276,6 +13276,8 @@ import { Controls, Euler as Euler11, MathUtils as MathUtils2, Quaternion as Quat
13276
13276
  var VANILLA_FLY_SPEED = 10.89;
13277
13277
  var PITCH_LIMIT = Math.PI / 2;
13278
13278
  var MOVE_EPSILON = 1e-6;
13279
+ var MAX_STEP_SECONDS = 0.1;
13280
+ var CLICK_SLOP_PIXELS = 4;
13279
13281
  var _euler = new Euler11(0, 0, 0, "YXZ");
13280
13282
  var _forward = new Vector313();
13281
13283
  var _right = new Vector313();
@@ -13310,7 +13312,8 @@ var FlyControls = class extends Controls {
13310
13312
  right: ["KeyD", "ArrowRight"],
13311
13313
  up: ["Space"],
13312
13314
  down: ["ShiftLeft", "ShiftRight"],
13313
- sprint: ["ControlLeft", "ControlRight"]
13315
+ // Not Control: Ctrl+W closes the browser tab on Windows and Linux, and a page cannot block it.
13316
+ sprint: ["KeyR"]
13314
13317
  };
13315
13318
  this._pressed = /* @__PURE__ */ new Set();
13316
13319
  this._velocity = new Vector313();
@@ -13318,8 +13321,12 @@ var FlyControls = class extends Controls {
13318
13321
  this._lastQuaternion = new Quaternion6();
13319
13322
  this._position0 = new Vector313();
13320
13323
  this._quaternion0 = new Quaternion6();
13324
+ this._dragX = 0;
13325
+ this._dragY = 0;
13321
13326
  this._dragMoved = false;
13327
+ this._dragTravel = 0;
13322
13328
  this._locked = false;
13329
+ this._madeFocusable = false;
13323
13330
  this._onKeyDown = (event) => this.handleKey(event, true);
13324
13331
  this._onKeyUp = (event) => this.handleKey(event, false);
13325
13332
  this._onPointerDown = (event) => this.handlePointerDown(event);
@@ -13349,7 +13356,10 @@ var FlyControls = class extends Controls {
13349
13356
  element.addEventListener("wheel", this._onWheel, { passive: false });
13350
13357
  element.addEventListener("blur", this._onBlur);
13351
13358
  element.style.touchAction = "none";
13352
- if (element.tabIndex < 0) element.tabIndex = 0;
13359
+ if (element.tabIndex < 0) {
13360
+ element.tabIndex = 0;
13361
+ this._madeFocusable = true;
13362
+ }
13353
13363
  }
13354
13364
  disconnect() {
13355
13365
  const element = this.domElement;
@@ -13367,6 +13377,10 @@ var FlyControls = class extends Controls {
13367
13377
  element.removeEventListener("wheel", this._onWheel);
13368
13378
  element.removeEventListener("blur", this._onBlur);
13369
13379
  element.style.touchAction = "auto";
13380
+ if (this._madeFocusable) {
13381
+ element.removeAttribute("tabindex");
13382
+ this._madeFocusable = false;
13383
+ }
13370
13384
  this.unlock();
13371
13385
  this._locked = false;
13372
13386
  this.releaseKeys();
@@ -13437,6 +13451,7 @@ var FlyControls = class extends Controls {
13437
13451
  /**
13438
13452
  * Advances movement by `delta` seconds (measured since the previous call when omitted)
13439
13453
  * and dispatches `change` when the camera moved.
13454
+ * A step longer than 0.1 s is applied as 0.1 s.
13440
13455
  */
13441
13456
  update(delta) {
13442
13457
  if (delta === void 0) {
@@ -13448,7 +13463,7 @@ var FlyControls = class extends Controls {
13448
13463
  this._velocity.set(0, 0, 0);
13449
13464
  return;
13450
13465
  }
13451
- if (delta > 0) this.move(delta);
13466
+ if (delta > 0) this.move(Math.min(delta, MAX_STEP_SECONDS));
13452
13467
  this.notifyChange();
13453
13468
  }
13454
13469
  move(delta) {
@@ -13495,15 +13510,21 @@ var FlyControls = class extends Controls {
13495
13510
  this._pressed.clear();
13496
13511
  }
13497
13512
  handleKey(event, down) {
13513
+ if (event.code === "MetaLeft" || event.code === "MetaRight") this.releaseKeys();
13498
13514
  const action = this.actionFor(event.code);
13499
13515
  if (!action) return;
13500
13516
  const ownsInput = this.enabled && (this._locked || event.target === this.domElement);
13501
- if (down && !ownsInput) return;
13517
+ if (down && (!ownsInput || this.isBrowserShortcut(event))) return;
13502
13518
  const pressed = this._pressed.has(action);
13503
13519
  if (down) this._pressed.add(action);
13504
13520
  else this._pressed.delete(action);
13505
13521
  if (ownsInput || this.enabled && pressed) event.preventDefault();
13506
13522
  }
13523
+ /** A key pressed with Control, Alt, or Command stays a browser shortcut unless that modifier is bound to an action. */
13524
+ isBrowserShortcut(event) {
13525
+ const bound = (modifier) => Object.values(this.keys).some((codes) => codes.some((code) => code.startsWith(modifier)));
13526
+ return event.ctrlKey && !bound("Control") || event.altKey && !bound("Alt") || event.metaKey && !bound("Meta");
13527
+ }
13507
13528
  actionFor(code) {
13508
13529
  for (const action in this.keys) {
13509
13530
  if (this.keys[action].includes(code)) return action;
@@ -13523,7 +13544,10 @@ var FlyControls = class extends Controls {
13523
13544
  if (this._dragPointer !== void 0) return;
13524
13545
  if (event.pointerType === "mouse" && event.button !== 0 && event.button !== 2) return;
13525
13546
  this._dragPointer = event.pointerId;
13547
+ this._dragX = event.clientX;
13548
+ this._dragY = event.clientY;
13526
13549
  this._dragMoved = false;
13550
+ this._dragTravel = 0;
13527
13551
  element.setPointerCapture?.(event.pointerId);
13528
13552
  }
13529
13553
  onJoystickSide(event) {
@@ -13539,8 +13563,20 @@ var FlyControls = class extends Controls {
13539
13563
  return;
13540
13564
  }
13541
13565
  if (!this._locked && event.pointerId !== this._dragPointer) return;
13542
- const dx = event.movementX ?? 0;
13543
- const dy = event.movementY ?? 0;
13566
+ let dx, dy;
13567
+ if (this._locked) {
13568
+ dx = event.movementX ?? 0;
13569
+ dy = event.movementY ?? 0;
13570
+ } else {
13571
+ dx = event.clientX - this._dragX;
13572
+ dy = event.clientY - this._dragY;
13573
+ this._dragX = event.clientX;
13574
+ this._dragY = event.clientY;
13575
+ if (!this._dragMoved) {
13576
+ this._dragTravel += Math.hypot(dx, dy);
13577
+ if (this._dragTravel <= CLICK_SLOP_PIXELS) return;
13578
+ }
13579
+ }
13544
13580
  if (!dx && !dy) return;
13545
13581
  this._dragMoved = true;
13546
13582
  this.turn(dx, dy);
@@ -15500,6 +15536,7 @@ var Renderer = class _Renderer {
15500
15536
  /**
15501
15537
  * Replaces renderer-owned controls with the selected mode, keeping the camera where it is.
15502
15538
  * Switching to orbit controls targets the point the camera looks at, at the previous orbit distance.
15539
+ * The previous controls object is disposed, so its listeners and settings do not carry over.
15503
15540
  * Returns the new controls, or undefined when controls were disabled at construction or after disposal.
15504
15541
  */
15505
15542
  setControlsMode(mode) {