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.
@@ -13221,6 +13221,8 @@ import { Controls, Euler as Euler11, MathUtils as MathUtils2, Quaternion as Quat
13221
13221
  var VANILLA_FLY_SPEED = 10.89;
13222
13222
  var PITCH_LIMIT = Math.PI / 2;
13223
13223
  var MOVE_EPSILON = 1e-6;
13224
+ var MAX_STEP_SECONDS = 0.1;
13225
+ var CLICK_SLOP_PIXELS = 4;
13224
13226
  var _euler = new Euler11(0, 0, 0, "YXZ");
13225
13227
  var _forward = new Vector313();
13226
13228
  var _right = new Vector313();
@@ -13255,7 +13257,8 @@ var FlyControls = class extends Controls {
13255
13257
  right: ["KeyD", "ArrowRight"],
13256
13258
  up: ["Space"],
13257
13259
  down: ["ShiftLeft", "ShiftRight"],
13258
- sprint: ["ControlLeft", "ControlRight"]
13260
+ // Not Control: Ctrl+W closes the browser tab on Windows and Linux, and a page cannot block it.
13261
+ sprint: ["KeyR"]
13259
13262
  };
13260
13263
  this._pressed = /* @__PURE__ */ new Set();
13261
13264
  this._velocity = new Vector313();
@@ -13263,8 +13266,12 @@ var FlyControls = class extends Controls {
13263
13266
  this._lastQuaternion = new Quaternion6();
13264
13267
  this._position0 = new Vector313();
13265
13268
  this._quaternion0 = new Quaternion6();
13269
+ this._dragX = 0;
13270
+ this._dragY = 0;
13266
13271
  this._dragMoved = false;
13272
+ this._dragTravel = 0;
13267
13273
  this._locked = false;
13274
+ this._madeFocusable = false;
13268
13275
  this._onKeyDown = (event) => this.handleKey(event, true);
13269
13276
  this._onKeyUp = (event) => this.handleKey(event, false);
13270
13277
  this._onPointerDown = (event) => this.handlePointerDown(event);
@@ -13294,7 +13301,10 @@ var FlyControls = class extends Controls {
13294
13301
  element.addEventListener("wheel", this._onWheel, { passive: false });
13295
13302
  element.addEventListener("blur", this._onBlur);
13296
13303
  element.style.touchAction = "none";
13297
- if (element.tabIndex < 0) element.tabIndex = 0;
13304
+ if (element.tabIndex < 0) {
13305
+ element.tabIndex = 0;
13306
+ this._madeFocusable = true;
13307
+ }
13298
13308
  }
13299
13309
  disconnect() {
13300
13310
  const element = this.domElement;
@@ -13312,6 +13322,10 @@ var FlyControls = class extends Controls {
13312
13322
  element.removeEventListener("wheel", this._onWheel);
13313
13323
  element.removeEventListener("blur", this._onBlur);
13314
13324
  element.style.touchAction = "auto";
13325
+ if (this._madeFocusable) {
13326
+ element.removeAttribute("tabindex");
13327
+ this._madeFocusable = false;
13328
+ }
13315
13329
  this.unlock();
13316
13330
  this._locked = false;
13317
13331
  this.releaseKeys();
@@ -13382,6 +13396,7 @@ var FlyControls = class extends Controls {
13382
13396
  /**
13383
13397
  * Advances movement by `delta` seconds (measured since the previous call when omitted)
13384
13398
  * and dispatches `change` when the camera moved.
13399
+ * A step longer than 0.1 s is applied as 0.1 s.
13385
13400
  */
13386
13401
  update(delta) {
13387
13402
  if (delta === void 0) {
@@ -13393,7 +13408,7 @@ var FlyControls = class extends Controls {
13393
13408
  this._velocity.set(0, 0, 0);
13394
13409
  return;
13395
13410
  }
13396
- if (delta > 0) this.move(delta);
13411
+ if (delta > 0) this.move(Math.min(delta, MAX_STEP_SECONDS));
13397
13412
  this.notifyChange();
13398
13413
  }
13399
13414
  move(delta) {
@@ -13440,15 +13455,21 @@ var FlyControls = class extends Controls {
13440
13455
  this._pressed.clear();
13441
13456
  }
13442
13457
  handleKey(event, down) {
13458
+ if (event.code === "MetaLeft" || event.code === "MetaRight") this.releaseKeys();
13443
13459
  const action = this.actionFor(event.code);
13444
13460
  if (!action) return;
13445
13461
  const ownsInput = this.enabled && (this._locked || event.target === this.domElement);
13446
- if (down && !ownsInput) return;
13462
+ if (down && (!ownsInput || this.isBrowserShortcut(event))) return;
13447
13463
  const pressed = this._pressed.has(action);
13448
13464
  if (down) this._pressed.add(action);
13449
13465
  else this._pressed.delete(action);
13450
13466
  if (ownsInput || this.enabled && pressed) event.preventDefault();
13451
13467
  }
13468
+ /** A key pressed with Control, Alt, or Command stays a browser shortcut unless that modifier is bound to an action. */
13469
+ isBrowserShortcut(event) {
13470
+ const bound = (modifier) => Object.values(this.keys).some((codes) => codes.some((code) => code.startsWith(modifier)));
13471
+ return event.ctrlKey && !bound("Control") || event.altKey && !bound("Alt") || event.metaKey && !bound("Meta");
13472
+ }
13452
13473
  actionFor(code) {
13453
13474
  for (const action in this.keys) {
13454
13475
  if (this.keys[action].includes(code)) return action;
@@ -13468,7 +13489,10 @@ var FlyControls = class extends Controls {
13468
13489
  if (this._dragPointer !== void 0) return;
13469
13490
  if (event.pointerType === "mouse" && event.button !== 0 && event.button !== 2) return;
13470
13491
  this._dragPointer = event.pointerId;
13492
+ this._dragX = event.clientX;
13493
+ this._dragY = event.clientY;
13471
13494
  this._dragMoved = false;
13495
+ this._dragTravel = 0;
13472
13496
  element.setPointerCapture?.(event.pointerId);
13473
13497
  }
13474
13498
  onJoystickSide(event) {
@@ -13484,8 +13508,20 @@ var FlyControls = class extends Controls {
13484
13508
  return;
13485
13509
  }
13486
13510
  if (!this._locked && event.pointerId !== this._dragPointer) return;
13487
- const dx = event.movementX ?? 0;
13488
- const dy = event.movementY ?? 0;
13511
+ let dx, dy;
13512
+ if (this._locked) {
13513
+ dx = event.movementX ?? 0;
13514
+ dy = event.movementY ?? 0;
13515
+ } else {
13516
+ dx = event.clientX - this._dragX;
13517
+ dy = event.clientY - this._dragY;
13518
+ this._dragX = event.clientX;
13519
+ this._dragY = event.clientY;
13520
+ if (!this._dragMoved) {
13521
+ this._dragTravel += Math.hypot(dx, dy);
13522
+ if (this._dragTravel <= CLICK_SLOP_PIXELS) return;
13523
+ }
13524
+ }
13489
13525
  if (!dx && !dy) return;
13490
13526
  this._dragMoved = true;
13491
13527
  this.turn(dx, dy);
@@ -15403,6 +15439,7 @@ var _Renderer = class _Renderer {
15403
15439
  /**
15404
15440
  * Replaces renderer-owned controls with the selected mode, keeping the camera where it is.
15405
15441
  * Switching to orbit controls targets the point the camera looks at, at the previous orbit distance.
15442
+ * The previous controls object is disposed, so its listeners and settings do not carry over.
15406
15443
  * Returns the new controls, or undefined when controls were disabled at construction or after disposal.
15407
15444
  */
15408
15445
  setControlsMode(mode) {