iwer 1.0.1 → 1.0.2

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/build/iwer.js CHANGED
@@ -1287,11 +1287,11 @@
1287
1287
  * This source code is licensed under the MIT license found in the
1288
1288
  * LICENSE file in the root directory of this source tree.
1289
1289
  */
1290
- const PRIVATE$k = Symbol('@immersive-web-emulation-runtime/xr-space');
1290
+ const PRIVATE$l = Symbol('@immersive-web-emulation-runtime/xr-space');
1291
1291
  class XRSpace extends EventTarget {
1292
1292
  constructor(parentSpace, offsetMatrix) {
1293
1293
  super();
1294
- this[PRIVATE$k] = {
1294
+ this[PRIVATE$l] = {
1295
1295
  parentSpace,
1296
1296
  offsetMatrix: offsetMatrix ? clone(offsetMatrix) : create$3(),
1297
1297
  emulated: true,
@@ -1306,27 +1306,27 @@
1306
1306
  class XRSpaceUtils {
1307
1307
  // Update the position component of the offsetMatrix of a given XRSpace
1308
1308
  static updateOffsetPosition(space, position) {
1309
- const offsetMatrix = space[PRIVATE$k].offsetMatrix;
1309
+ const offsetMatrix = space[PRIVATE$l].offsetMatrix;
1310
1310
  fromTranslation(offsetMatrix, position);
1311
1311
  }
1312
1312
  // Update the rotation component of the offsetMatrix of a given XRSpace using a quaternion
1313
1313
  static updateOffsetQuaternion(space, quaternion) {
1314
- const offsetMatrix = space[PRIVATE$k].offsetMatrix;
1314
+ const offsetMatrix = space[PRIVATE$l].offsetMatrix;
1315
1315
  const translation = create$2();
1316
1316
  getTranslation(translation, offsetMatrix);
1317
1317
  fromRotationTranslation(offsetMatrix, quaternion, translation);
1318
1318
  }
1319
1319
  // Update the offsetMatrix of a given XRSpace directly
1320
1320
  static updateOffsetMatrix(space, matrix) {
1321
- const offsetMatrix = space[PRIVATE$k].offsetMatrix;
1321
+ const offsetMatrix = space[PRIVATE$l].offsetMatrix;
1322
1322
  copy$3(offsetMatrix, matrix);
1323
1323
  }
1324
1324
  // Calculate the global offset matrix for a given XRSpace
1325
1325
  static calculateGlobalOffsetMatrix(space, globalOffset = create$3()) {
1326
- const parentOffset = space[PRIVATE$k].parentSpace
1327
- ? XRSpaceUtils.calculateGlobalOffsetMatrix(space[PRIVATE$k].parentSpace)
1326
+ const parentOffset = space[PRIVATE$l].parentSpace
1327
+ ? XRSpaceUtils.calculateGlobalOffsetMatrix(space[PRIVATE$l].parentSpace)
1328
1328
  : create$3(); // Identity matrix for GlobalSpace
1329
- multiply$1(globalOffset, parentOffset, space[PRIVATE$k].offsetMatrix);
1329
+ multiply$1(globalOffset, parentOffset, space[PRIVATE$l].offsetMatrix);
1330
1330
  return globalOffset;
1331
1331
  }
1332
1332
  }
@@ -1470,7 +1470,7 @@
1470
1470
  * This source code is licensed under the MIT license found in the
1471
1471
  * LICENSE file in the root directory of this source tree.
1472
1472
  */
1473
- const PRIVATE$j = Symbol('@immersive-web-emulation-runtime/gamepad');
1473
+ const PRIVATE$k = Symbol('@immersive-web-emulation-runtime/gamepad');
1474
1474
  var GamepadMappingType;
1475
1475
  (function (GamepadMappingType) {
1476
1476
  GamepadMappingType["None"] = "";
@@ -1479,7 +1479,7 @@
1479
1479
  })(GamepadMappingType || (GamepadMappingType = {}));
1480
1480
  class GamepadButton {
1481
1481
  constructor(type, eventTrigger) {
1482
- this[PRIVATE$j] = {
1482
+ this[PRIVATE$k] = {
1483
1483
  type,
1484
1484
  eventTrigger,
1485
1485
  pressed: false,
@@ -1490,23 +1490,23 @@
1490
1490
  };
1491
1491
  }
1492
1492
  get pressed() {
1493
- if (this[PRIVATE$j].type === 'manual') {
1494
- return this[PRIVATE$j].pressed;
1493
+ if (this[PRIVATE$k].type === 'manual') {
1494
+ return this[PRIVATE$k].pressed;
1495
1495
  }
1496
1496
  else {
1497
- return this[PRIVATE$j].value > 0;
1497
+ return this[PRIVATE$k].value > 0;
1498
1498
  }
1499
1499
  }
1500
1500
  get touched() {
1501
- if (this[PRIVATE$j].type === 'manual') {
1502
- return this[PRIVATE$j].touched;
1501
+ if (this[PRIVATE$k].type === 'manual') {
1502
+ return this[PRIVATE$k].touched;
1503
1503
  }
1504
1504
  else {
1505
- return this[PRIVATE$j].touched || this.pressed;
1505
+ return this[PRIVATE$k].touched || this.pressed;
1506
1506
  }
1507
1507
  }
1508
1508
  get value() {
1509
- return this[PRIVATE$j].value;
1509
+ return this[PRIVATE$k].value;
1510
1510
  }
1511
1511
  }
1512
1512
  class EmptyGamepadButton {
@@ -1518,7 +1518,7 @@
1518
1518
  }
1519
1519
  class Gamepad {
1520
1520
  constructor(gamepadConfig, id = '', index = -1) {
1521
- this[PRIVATE$j] = {
1521
+ this[PRIVATE$k] = {
1522
1522
  id,
1523
1523
  index,
1524
1524
  connected: false,
@@ -1533,43 +1533,43 @@
1533
1533
  gamepadConfig.buttons.forEach((buttonConfig) => {
1534
1534
  var _a;
1535
1535
  if (buttonConfig === null) {
1536
- this[PRIVATE$j].buttonsSequence.push(null);
1536
+ this[PRIVATE$k].buttonsSequence.push(null);
1537
1537
  }
1538
1538
  else {
1539
- this[PRIVATE$j].buttonsSequence.push(buttonConfig.id);
1540
- this[PRIVATE$j].buttonsMap[buttonConfig.id] = new GamepadButton(buttonConfig.type, (_a = buttonConfig.eventTrigger) !== null && _a !== void 0 ? _a : null);
1539
+ this[PRIVATE$k].buttonsSequence.push(buttonConfig.id);
1540
+ this[PRIVATE$k].buttonsMap[buttonConfig.id] = new GamepadButton(buttonConfig.type, (_a = buttonConfig.eventTrigger) !== null && _a !== void 0 ? _a : null);
1541
1541
  }
1542
1542
  });
1543
1543
  gamepadConfig.axes.forEach((axisConfig) => {
1544
1544
  if (axisConfig === null) {
1545
- this[PRIVATE$j].axesSequence.push(null);
1545
+ this[PRIVATE$k].axesSequence.push(null);
1546
1546
  }
1547
1547
  else {
1548
- this[PRIVATE$j].axesSequence.push(axisConfig.id + axisConfig.type);
1549
- if (!this[PRIVATE$j].axesMap[axisConfig.id]) {
1550
- this[PRIVATE$j].axesMap[axisConfig.id] = { x: 0, y: 0 };
1548
+ this[PRIVATE$k].axesSequence.push(axisConfig.id + axisConfig.type);
1549
+ if (!this[PRIVATE$k].axesMap[axisConfig.id]) {
1550
+ this[PRIVATE$k].axesMap[axisConfig.id] = { x: 0, y: 0 };
1551
1551
  }
1552
1552
  }
1553
1553
  });
1554
1554
  }
1555
1555
  get id() {
1556
- return this[PRIVATE$j].id;
1556
+ return this[PRIVATE$k].id;
1557
1557
  }
1558
1558
  get index() {
1559
- return this[PRIVATE$j].index;
1559
+ return this[PRIVATE$k].index;
1560
1560
  }
1561
1561
  get connected() {
1562
- return this[PRIVATE$j].connected;
1562
+ return this[PRIVATE$k].connected;
1563
1563
  }
1564
1564
  get timestamp() {
1565
- return this[PRIVATE$j].timestamp;
1565
+ return this[PRIVATE$k].timestamp;
1566
1566
  }
1567
1567
  get mapping() {
1568
- return this[PRIVATE$j].mapping;
1568
+ return this[PRIVATE$k].mapping;
1569
1569
  }
1570
1570
  get axes() {
1571
1571
  const axes = [];
1572
- this[PRIVATE$j].axesSequence.forEach((id) => {
1572
+ this[PRIVATE$k].axesSequence.forEach((id) => {
1573
1573
  if (id === null) {
1574
1574
  axes.push(null);
1575
1575
  }
@@ -1579,17 +1579,17 @@
1579
1579
  axes.push(
1580
1580
  // if axis type is manual, then return the x value
1581
1581
  axisType === 'y-axis'
1582
- ? this[PRIVATE$j].axesMap[axisId].y
1583
- : this[PRIVATE$j].axesMap[axisId].x);
1582
+ ? this[PRIVATE$k].axesMap[axisId].y
1583
+ : this[PRIVATE$k].axesMap[axisId].x);
1584
1584
  }
1585
1585
  });
1586
1586
  return axes;
1587
1587
  }
1588
1588
  get buttons() {
1589
- return this[PRIVATE$j].buttonsSequence.map((id) => id === null ? new EmptyGamepadButton() : this[PRIVATE$j].buttonsMap[id]);
1589
+ return this[PRIVATE$k].buttonsSequence.map((id) => id === null ? new EmptyGamepadButton() : this[PRIVATE$k].buttonsMap[id]);
1590
1590
  }
1591
1591
  get hapticActuators() {
1592
- return this[PRIVATE$j].hapticActuators;
1592
+ return this[PRIVATE$k].hapticActuators;
1593
1593
  }
1594
1594
  get vibrationActuator() {
1595
1595
  return null;
@@ -1617,10 +1617,10 @@
1617
1617
  })(XRTargetRayMode || (XRTargetRayMode = {}));
1618
1618
  class XRInputSourceArray extends Array {
1619
1619
  }
1620
- const PRIVATE$i = Symbol('@immersive-web-emulation-runtime/xr-input-source');
1620
+ const PRIVATE$j = Symbol('@immersive-web-emulation-runtime/xr-input-source');
1621
1621
  class XRInputSource {
1622
1622
  constructor(handedness, targetRayMode, profiles, targetRaySpace, gamepad, gripSpace, hand) {
1623
- this[PRIVATE$i] = {
1623
+ this[PRIVATE$j] = {
1624
1624
  handedness,
1625
1625
  targetRayMode,
1626
1626
  targetRaySpace,
@@ -1631,25 +1631,25 @@
1631
1631
  };
1632
1632
  }
1633
1633
  get handedness() {
1634
- return this[PRIVATE$i].handedness;
1634
+ return this[PRIVATE$j].handedness;
1635
1635
  }
1636
1636
  get targetRayMode() {
1637
- return this[PRIVATE$i].targetRayMode;
1637
+ return this[PRIVATE$j].targetRayMode;
1638
1638
  }
1639
1639
  get targetRaySpace() {
1640
- return this[PRIVATE$i].targetRaySpace;
1640
+ return this[PRIVATE$j].targetRaySpace;
1641
1641
  }
1642
1642
  get gripSpace() {
1643
- return this[PRIVATE$i].gripSpace;
1643
+ return this[PRIVATE$j].gripSpace;
1644
1644
  }
1645
1645
  get profiles() {
1646
- return this[PRIVATE$i].profiles;
1646
+ return this[PRIVATE$j].profiles;
1647
1647
  }
1648
1648
  get gamepad() {
1649
- return this[PRIVATE$i].gamepad;
1649
+ return this[PRIVATE$j].gamepad;
1650
1650
  }
1651
1651
  get hand() {
1652
- return this[PRIVATE$i].hand;
1652
+ return this[PRIVATE$j].hand;
1653
1653
  }
1654
1654
  }
1655
1655
 
@@ -1679,7 +1679,7 @@
1679
1679
  * This source code is licensed under the MIT license found in the
1680
1680
  * LICENSE file in the root directory of this source tree.
1681
1681
  */
1682
- const PRIVATE$h = Symbol('@immersive-web-emulation-runtime/xr-tracked-input');
1682
+ const PRIVATE$i = Symbol('@immersive-web-emulation-runtime/xr-tracked-input');
1683
1683
  const DEFAULT_TRANSFORM = {
1684
1684
  [XRHandedness.Left]: {
1685
1685
  position: new Vector3(-0.25, 1.5, -0.4),
@@ -1696,7 +1696,7 @@
1696
1696
  };
1697
1697
  class XRTrackedInput {
1698
1698
  constructor(inputSource) {
1699
- this[PRIVATE$h] = {
1699
+ this[PRIVATE$i] = {
1700
1700
  inputSource,
1701
1701
  position: DEFAULT_TRANSFORM[inputSource.handedness].position.clone(),
1702
1702
  quaternion: DEFAULT_TRANSFORM[inputSource.handedness].quaternion.clone(),
@@ -1706,59 +1706,59 @@
1706
1706
  };
1707
1707
  }
1708
1708
  get position() {
1709
- return this[PRIVATE$h].position;
1709
+ return this[PRIVATE$i].position;
1710
1710
  }
1711
1711
  get quaternion() {
1712
- return this[PRIVATE$h].quaternion;
1712
+ return this[PRIVATE$i].quaternion;
1713
1713
  }
1714
1714
  get inputSource() {
1715
- return this[PRIVATE$h].inputSource;
1715
+ return this[PRIVATE$i].inputSource;
1716
1716
  }
1717
1717
  get connected() {
1718
- return this[PRIVATE$h].connected;
1718
+ return this[PRIVATE$i].connected;
1719
1719
  }
1720
1720
  set connected(value) {
1721
- this[PRIVATE$h].connected = value;
1722
- this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].connected = value;
1721
+ this[PRIVATE$i].connected = value;
1722
+ this[PRIVATE$i].inputSource.gamepad[PRIVATE$k].connected = value;
1723
1723
  }
1724
1724
  onFrameStart(frame) {
1725
- const targetRaySpace = this[PRIVATE$h].inputSource.targetRaySpace;
1726
- fromRotationTranslation(targetRaySpace[PRIVATE$k].offsetMatrix, this[PRIVATE$h].quaternion.quat, this[PRIVATE$h].position.vec3);
1725
+ const targetRaySpace = this[PRIVATE$i].inputSource.targetRaySpace;
1726
+ fromRotationTranslation(targetRaySpace[PRIVATE$l].offsetMatrix, this[PRIVATE$i].quaternion.quat, this[PRIVATE$i].position.vec3);
1727
1727
  const session = frame.session;
1728
- this[PRIVATE$h].inputSource.gamepad.buttons.forEach((button) => {
1728
+ this[PRIVATE$i].inputSource.gamepad.buttons.forEach((button) => {
1729
1729
  if (button instanceof GamepadButton) {
1730
1730
  // apply pending values and record last frame values
1731
- button[PRIVATE$j].lastFrameValue = button[PRIVATE$j].value;
1732
- if (button[PRIVATE$j].pendingValue != null) {
1733
- button[PRIVATE$j].value = button[PRIVATE$j].pendingValue;
1734
- button[PRIVATE$j].pendingValue = null;
1731
+ button[PRIVATE$k].lastFrameValue = button[PRIVATE$k].value;
1732
+ if (button[PRIVATE$k].pendingValue != null) {
1733
+ button[PRIVATE$k].value = button[PRIVATE$k].pendingValue;
1734
+ button[PRIVATE$k].pendingValue = null;
1735
1735
  }
1736
1736
  // trigger input source events
1737
- if (button[PRIVATE$j].eventTrigger != null) {
1738
- if (button[PRIVATE$j].lastFrameValue === 0 &&
1739
- button[PRIVATE$j].value > 0) {
1740
- session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$j].eventTrigger, {
1737
+ if (button[PRIVATE$k].eventTrigger != null) {
1738
+ if (button[PRIVATE$k].lastFrameValue === 0 &&
1739
+ button[PRIVATE$k].value > 0) {
1740
+ session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$k].eventTrigger, {
1741
1741
  frame,
1742
- inputSource: this[PRIVATE$h].inputSource,
1742
+ inputSource: this[PRIVATE$i].inputSource,
1743
1743
  }));
1744
- session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$j].eventTrigger + 'start', {
1744
+ session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$k].eventTrigger + 'start', {
1745
1745
  frame,
1746
- inputSource: this[PRIVATE$h].inputSource,
1746
+ inputSource: this[PRIVATE$i].inputSource,
1747
1747
  }));
1748
1748
  }
1749
- else if (button[PRIVATE$j].lastFrameValue > 0 &&
1750
- button[PRIVATE$j].value === 0) {
1751
- session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$j].eventTrigger + 'end', {
1749
+ else if (button[PRIVATE$k].lastFrameValue > 0 &&
1750
+ button[PRIVATE$k].value === 0) {
1751
+ session.dispatchEvent(new XRInputSourceEvent(button[PRIVATE$k].eventTrigger + 'end', {
1752
1752
  frame,
1753
- inputSource: this[PRIVATE$h].inputSource,
1753
+ inputSource: this[PRIVATE$i].inputSource,
1754
1754
  }));
1755
1755
  }
1756
1756
  }
1757
1757
  }
1758
1758
  });
1759
- this[PRIVATE$h].inputSourceChanged =
1760
- this.connected !== this[PRIVATE$h].lastFrameConnected;
1761
- this[PRIVATE$h].lastFrameConnected = this.connected;
1759
+ this[PRIVATE$i].inputSourceChanged =
1760
+ this.connected !== this[PRIVATE$i].lastFrameConnected;
1761
+ this[PRIVATE$i].lastFrameConnected = this.connected;
1762
1762
  }
1763
1763
  }
1764
1764
 
@@ -1768,6 +1768,7 @@
1768
1768
  * This source code is licensed under the MIT license found in the
1769
1769
  * LICENSE file in the root directory of this source tree.
1770
1770
  */
1771
+ const PRIVATE$h = Symbol('@immersive-web-emulation-runtime/xr-controller');
1771
1772
  class XRController extends XRTrackedInput {
1772
1773
  constructor(controllerConfig, handedness, globalSpace) {
1773
1774
  if (!controllerConfig.layout[handedness]) {
@@ -1783,30 +1784,38 @@
1783
1784
  ];
1784
1785
  const inputSource = new XRInputSource(handedness, XRTargetRayMode.TrackedPointer, profiles, targetRaySpace, new Gamepad(controllerConfig.layout[handedness].gamepad), gripSpace);
1785
1786
  super(inputSource);
1787
+ this[PRIVATE$h] = {
1788
+ gamepadConfig: controllerConfig.layout[handedness].gamepad,
1789
+ };
1790
+ }
1791
+ get gamepadConfig() {
1792
+ return this[PRIVATE$h].gamepadConfig;
1786
1793
  }
1787
1794
  updateButtonValue(id, value) {
1788
1795
  if (value > 1 || value < 0) {
1789
1796
  console.warn(`Out-of-range value ${value} provided for button ${id}.`);
1790
1797
  return;
1791
1798
  }
1792
- const gamepadButton = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].buttonsMap[id];
1799
+ const gamepadButton = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
1800
+ .buttonsMap[id];
1793
1801
  if (gamepadButton) {
1794
- if (gamepadButton[PRIVATE$j].type === 'binary' &&
1802
+ if (gamepadButton[PRIVATE$k].type === 'binary' &&
1795
1803
  value != 1 &&
1796
1804
  value != 0) {
1797
1805
  console.warn(`Non-binary value ${value} provided for binary button ${id}.`);
1798
1806
  return;
1799
1807
  }
1800
- gamepadButton[PRIVATE$j].pendingValue = value;
1808
+ gamepadButton[PRIVATE$k].pendingValue = value;
1801
1809
  }
1802
1810
  else {
1803
1811
  console.warn(`Current controller does not have button ${id}.`);
1804
1812
  }
1805
1813
  }
1806
1814
  updateButtonTouch(id, touched) {
1807
- const gamepadButton = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].buttonsMap[id];
1815
+ const gamepadButton = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
1816
+ .buttonsMap[id];
1808
1817
  if (gamepadButton) {
1809
- gamepadButton[PRIVATE$j].touched = touched;
1818
+ gamepadButton[PRIVATE$k].touched = touched;
1810
1819
  }
1811
1820
  else {
1812
1821
  console.warn(`Current controller does not have button ${id}.`);
@@ -1817,7 +1826,8 @@
1817
1826
  console.warn(`Out-of-range value ${value} provided for ${id} axes.`);
1818
1827
  return;
1819
1828
  }
1820
- const axesById = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].axesMap[id];
1829
+ const axesById = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
1830
+ .axesMap[id];
1821
1831
  if (axesById) {
1822
1832
  if (type === 'x-axis') {
1823
1833
  axesById.x = value;
@@ -1835,7 +1845,8 @@
1835
1845
  console.warn(`Out-of-range value x:${x}, y:${y} provided for ${id} axes.`);
1836
1846
  return;
1837
1847
  }
1838
- const axesById = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j].axesMap[id];
1848
+ const axesById = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
1849
+ .axesMap[id];
1839
1850
  if (axesById) {
1840
1851
  axesById.x = x;
1841
1852
  axesById.y = y;
@@ -2770,20 +2781,20 @@
2770
2781
  const targetJointMatrix = targetPose.jointTransforms[jointName].offsetMatrix;
2771
2782
  const pinchJointMatrix = pinchPose.jointTransforms[jointName].offsetMatrix;
2772
2783
  const jointSpace = this.inputSource.hand.get(jointName);
2773
- interpolateMatrix(jointSpace[PRIVATE$k].offsetMatrix, targetJointMatrix, pinchJointMatrix, this.pinchValue);
2784
+ interpolateMatrix(jointSpace[PRIVATE$l].offsetMatrix, targetJointMatrix, pinchJointMatrix, this.pinchValue);
2774
2785
  if (this.inputSource.handedness === XRHandedness.Right) {
2775
- mirrorMatrixToRight(jointSpace[PRIVATE$k].offsetMatrix);
2786
+ mirrorMatrixToRight(jointSpace[PRIVATE$l].offsetMatrix);
2776
2787
  }
2777
2788
  jointSpace[PRIVATE$f].radius =
2778
2789
  (1 - this.pinchValue) * targetPose.jointTransforms[jointName].radius +
2779
2790
  this.pinchValue * pinchPose.jointTransforms[jointName].radius;
2780
2791
  });
2781
2792
  if (targetPose.gripOffsetMatrix && pinchPose.gripOffsetMatrix) {
2782
- interpolateMatrix(this.inputSource.gripSpace[PRIVATE$k].offsetMatrix, targetPose.gripOffsetMatrix, pinchPose.gripOffsetMatrix, this.pinchValue);
2793
+ interpolateMatrix(this.inputSource.gripSpace[PRIVATE$l].offsetMatrix, targetPose.gripOffsetMatrix, pinchPose.gripOffsetMatrix, this.pinchValue);
2783
2794
  }
2784
2795
  }
2785
2796
  get pinchValue() {
2786
- return this[PRIVATE$h].inputSource.gamepad[PRIVATE$j]
2797
+ return this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
2787
2798
  .buttonsMap['pinch'].value;
2788
2799
  }
2789
2800
  updatePinchValue(value) {
@@ -2791,9 +2802,9 @@
2791
2802
  console.warn(`Out-of-range value ${value} provided for pinch`);
2792
2803
  return;
2793
2804
  }
2794
- const gamepadButton = this[PRIVATE$h].inputSource.gamepad[PRIVATE$j]
2805
+ const gamepadButton = this[PRIVATE$i].inputSource.gamepad[PRIVATE$k]
2795
2806
  .buttonsMap['pinch'];
2796
- gamepadButton[PRIVATE$j].pendingValue = value;
2807
+ gamepadButton[PRIVATE$k].pendingValue = value;
2797
2808
  }
2798
2809
  onFrameStart(frame) {
2799
2810
  super.onFrameStart(frame);
@@ -3004,7 +3015,7 @@
3004
3015
  y: orientation[1],
3005
3016
  z: orientation[2],
3006
3017
  w: orientation[3],
3007
- }), space[PRIVATE$k].emulated);
3018
+ }), space[PRIVATE$l].emulated);
3008
3019
  }
3009
3020
  getViewerPose(referenceSpace) {
3010
3021
  if (!this[PRIVATE$9].animationFrame) {
@@ -3470,7 +3481,7 @@
3470
3481
  break;
3471
3482
  case XRReferenceSpaceType.Local:
3472
3483
  // creating an XRReferenceSpace with the current headset transform in global space
3473
- referenceSpace = new XRReferenceSpace(type, this[PRIVATE$6].device[PRIVATE$1].globalSpace, this[PRIVATE$6].device.viewerSpace[PRIVATE$k].offsetMatrix);
3484
+ referenceSpace = new XRReferenceSpace(type, this[PRIVATE$6].device[PRIVATE$1].globalSpace, this[PRIVATE$6].device.viewerSpace[PRIVATE$l].offsetMatrix);
3474
3485
  break;
3475
3486
  case XRReferenceSpaceType.LocalFloor:
3476
3487
  case XRReferenceSpaceType.BoundedFloor:
@@ -3736,7 +3747,76 @@
3736
3747
  * This source code is licensed under the MIT license found in the
3737
3748
  * LICENSE file in the root directory of this source tree.
3738
3749
  */
3739
- const PRIVATE$4 = Symbol('@immersive-web-emulation-runtime/action-player');
3750
+ const PRIVATE$4 = Symbol('@immersive-web-emulation-runtime/xr-system');
3751
+ class XRSystem extends EventTarget {
3752
+ constructor(device) {
3753
+ super();
3754
+ this[PRIVATE$4] = { device };
3755
+ // Initialize device change monitoring here if applicable
3756
+ }
3757
+ isSessionSupported(mode) {
3758
+ return new Promise((resolve, _reject) => {
3759
+ if (mode === XRSessionMode.Inline) {
3760
+ resolve(true);
3761
+ }
3762
+ else {
3763
+ // Check for spatial tracking permission if necessary
3764
+ resolve(this[PRIVATE$4].device.supportedSessionModes.includes(mode));
3765
+ }
3766
+ });
3767
+ }
3768
+ requestSession(mode, options = {}) {
3769
+ return new Promise((resolve, reject) => {
3770
+ this.isSessionSupported(mode)
3771
+ .then((isSupported) => {
3772
+ if (!isSupported) {
3773
+ reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
3774
+ return;
3775
+ }
3776
+ // Check for active sessions and other constraints here
3777
+ if (this[PRIVATE$4].activeSession) {
3778
+ reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
3779
+ return;
3780
+ }
3781
+ // Handle required and optional features
3782
+ const { requiredFeatures = [], optionalFeatures = [] } = options;
3783
+ const { supportedFeatures } = this[PRIVATE$4].device;
3784
+ // Check if all required features are supported
3785
+ const allRequiredSupported = requiredFeatures.every((feature) => supportedFeatures.includes(feature));
3786
+ if (!allRequiredSupported) {
3787
+ reject(new Error('One or more required features are not supported by the device.'));
3788
+ return;
3789
+ }
3790
+ // Filter out unsupported optional features
3791
+ const supportedOptionalFeatures = optionalFeatures.filter((feature) => supportedFeatures.includes(feature));
3792
+ // Combine required and supported optional features into enabled features
3793
+ const enabledFeatures = Array.from(new Set([
3794
+ ...requiredFeatures,
3795
+ ...supportedOptionalFeatures,
3796
+ WebXRFeatures.Viewer,
3797
+ WebXRFeatures.Local,
3798
+ ]));
3799
+ // Proceed with session creation
3800
+ const session = new XRSession(this[PRIVATE$4].device, mode, enabledFeatures);
3801
+ this[PRIVATE$4].activeSession = session;
3802
+ // Listen for session end to clear the active session
3803
+ session.addEventListener('end', () => {
3804
+ this[PRIVATE$4].activeSession = undefined;
3805
+ });
3806
+ resolve(session);
3807
+ })
3808
+ .catch(reject);
3809
+ });
3810
+ }
3811
+ }
3812
+
3813
+ /**
3814
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3815
+ *
3816
+ * This source code is licensed under the MIT license found in the
3817
+ * LICENSE file in the root directory of this source tree.
3818
+ */
3819
+ const PRIVATE$3 = Symbol('@immersive-web-emulation-runtime/action-player');
3740
3820
  class ActionPlayer {
3741
3821
  constructor(refSpace, recording, ipd) {
3742
3822
  const { schema, frames } = recording;
@@ -3749,7 +3829,7 @@
3749
3829
  [XREye.Right]: new XRSpace(viewerSpace),
3750
3830
  [XREye.None]: new XRSpace(viewerSpace),
3751
3831
  };
3752
- this[PRIVATE$4] = {
3832
+ this[PRIVATE$3] = {
3753
3833
  refSpace,
3754
3834
  inputSources: new Map(),
3755
3835
  inputSchemas: new Map(),
@@ -3764,8 +3844,8 @@
3764
3844
  vec3: create$2(),
3765
3845
  quat: create(),
3766
3846
  };
3767
- fromTranslation(this[PRIVATE$4].viewSpaces[XREye.Left][PRIVATE$k].offsetMatrix, fromValues$2(-ipd / 2, 0, 0));
3768
- fromTranslation(this[PRIVATE$4].viewSpaces[XREye.Right][PRIVATE$k].offsetMatrix, fromValues$2(ipd / 2, 0, 0));
3847
+ fromTranslation(this[PRIVATE$3].viewSpaces[XREye.Left][PRIVATE$l].offsetMatrix, fromValues$2(-ipd / 2, 0, 0));
3848
+ fromTranslation(this[PRIVATE$3].viewSpaces[XREye.Right][PRIVATE$l].offsetMatrix, fromValues$2(ipd / 2, 0, 0));
3769
3849
  schema.forEach((schemaEntry) => {
3770
3850
  const index = schemaEntry[0];
3771
3851
  const schema = schemaEntry[1];
@@ -3794,53 +3874,53 @@
3794
3874
  });
3795
3875
  }
3796
3876
  const inputSource = new XRInputSource(schema.handedness, schema.targetRayMode, schema.profiles, targetRaySpace, gamepad, schema.hasGrip ? new XRSpace(refSpace) : undefined, schema.hasHand ? hand : undefined);
3797
- this[PRIVATE$4].inputSources.set(index, {
3877
+ this[PRIVATE$3].inputSources.set(index, {
3798
3878
  active: false,
3799
3879
  source: inputSource,
3800
3880
  });
3801
- this[PRIVATE$4].inputSchemas.set(index, schema);
3881
+ this[PRIVATE$3].inputSchemas.set(index, schema);
3802
3882
  });
3803
3883
  }
3804
3884
  play() {
3805
- this[PRIVATE$4].recordedFramePointer = 0;
3806
- this[PRIVATE$4].playbackTime = this[PRIVATE$4].startingTimeStamp;
3807
- this[PRIVATE$4].playing = true;
3808
- this[PRIVATE$4].actualTimeStamp = performance.now();
3885
+ this[PRIVATE$3].recordedFramePointer = 0;
3886
+ this[PRIVATE$3].playbackTime = this[PRIVATE$3].startingTimeStamp;
3887
+ this[PRIVATE$3].playing = true;
3888
+ this[PRIVATE$3].actualTimeStamp = performance.now();
3809
3889
  }
3810
3890
  stop() {
3811
- this[PRIVATE$4].playing = false;
3891
+ this[PRIVATE$3].playing = false;
3812
3892
  }
3813
3893
  get playing() {
3814
- return this[PRIVATE$4].playing;
3894
+ return this[PRIVATE$3].playing;
3815
3895
  }
3816
3896
  get viewerSpace() {
3817
- return this[PRIVATE$4].viewerSpace;
3897
+ return this[PRIVATE$3].viewerSpace;
3818
3898
  }
3819
3899
  get viewSpaces() {
3820
- return this[PRIVATE$4].viewSpaces;
3900
+ return this[PRIVATE$3].viewSpaces;
3821
3901
  }
3822
3902
  get inputSources() {
3823
- return Array.from(this[PRIVATE$4].inputSources.values())
3903
+ return Array.from(this[PRIVATE$3].inputSources.values())
3824
3904
  .filter((wrapper) => wrapper.active)
3825
3905
  .map((wrapper) => wrapper.source);
3826
3906
  }
3827
3907
  playFrame() {
3828
3908
  const now = performance.now();
3829
- const delta = now - this[PRIVATE$4].actualTimeStamp;
3830
- this[PRIVATE$4].actualTimeStamp = now;
3831
- this[PRIVATE$4].playbackTime += delta;
3832
- if (this[PRIVATE$4].playbackTime > this[PRIVATE$4].endingTimeStamp) {
3909
+ const delta = now - this[PRIVATE$3].actualTimeStamp;
3910
+ this[PRIVATE$3].actualTimeStamp = now;
3911
+ this[PRIVATE$3].playbackTime += delta;
3912
+ if (this[PRIVATE$3].playbackTime > this[PRIVATE$3].endingTimeStamp) {
3833
3913
  this.stop();
3834
3914
  return;
3835
3915
  }
3836
- while (this[PRIVATE$4].frames[this[PRIVATE$4].recordedFramePointer + 1][0] < this[PRIVATE$4].playbackTime) {
3837
- this[PRIVATE$4].recordedFramePointer++;
3916
+ while (this[PRIVATE$3].frames[this[PRIVATE$3].recordedFramePointer + 1][0] < this[PRIVATE$3].playbackTime) {
3917
+ this[PRIVATE$3].recordedFramePointer++;
3838
3918
  }
3839
- const lastFrameData = this[PRIVATE$4].frames[this[PRIVATE$4].recordedFramePointer];
3840
- const nextFrameData = this[PRIVATE$4].frames[this[PRIVATE$4].recordedFramePointer + 1];
3841
- const alpha = (this[PRIVATE$4].playbackTime - lastFrameData[0]) /
3919
+ const lastFrameData = this[PRIVATE$3].frames[this[PRIVATE$3].recordedFramePointer];
3920
+ const nextFrameData = this[PRIVATE$3].frames[this[PRIVATE$3].recordedFramePointer + 1];
3921
+ const alpha = (this[PRIVATE$3].playbackTime - lastFrameData[0]) /
3842
3922
  (nextFrameData[0] - lastFrameData[0]);
3843
- this.updateXRSpaceFromMergedFrames(this[PRIVATE$4].viewerSpace, lastFrameData.slice(1, 8), nextFrameData.slice(1, 8), alpha);
3923
+ this.updateXRSpaceFromMergedFrames(this[PRIVATE$3].viewerSpace, lastFrameData.slice(1, 8), nextFrameData.slice(1, 8), alpha);
3844
3924
  const lastFrameInputs = new Map();
3845
3925
  for (let i = 8; i < lastFrameData.length; i++) {
3846
3926
  const { index, inputData } = this.processRawInputData(lastFrameData[i]);
@@ -3851,13 +3931,13 @@
3851
3931
  const { index, inputData } = this.processRawInputData(nextFrameData[i]);
3852
3932
  nextFrameInputs.set(index, inputData);
3853
3933
  }
3854
- this[PRIVATE$4].inputSources.forEach((sourceWrapper) => {
3934
+ this[PRIVATE$3].inputSources.forEach((sourceWrapper) => {
3855
3935
  sourceWrapper.active = false;
3856
3936
  });
3857
3937
  nextFrameInputs.forEach((inputData, index) => {
3858
- this[PRIVATE$4].inputSources.get(index).active = true;
3859
- const inputSource = this[PRIVATE$4].inputSources.get(index).source;
3860
- const schema = this[PRIVATE$4].inputSchemas.get(index);
3938
+ this[PRIVATE$3].inputSources.get(index).active = true;
3939
+ const inputSource = this[PRIVATE$3].inputSources.get(index).source;
3940
+ const schema = this[PRIVATE$3].inputSchemas.get(index);
3861
3941
  this.updateInputSource(inputSource, schema, lastFrameInputs.has(index) ? lastFrameInputs.get(index) : inputData, inputData, alpha);
3862
3942
  });
3863
3943
  }
@@ -3882,16 +3962,16 @@
3882
3962
  const gamepad = inputSource.gamepad;
3883
3963
  nextInputData.buttons.forEach((states, index) => {
3884
3964
  const gamepadButton = gamepad.buttons[index];
3885
- gamepadButton[PRIVATE$j].pressed = states[0] === 1 ? true : false;
3886
- gamepadButton[PRIVATE$j].touched = states[1] === 1 ? true : false;
3965
+ gamepadButton[PRIVATE$k].pressed = states[0] === 1 ? true : false;
3966
+ gamepadButton[PRIVATE$k].touched = states[1] === 1 ? true : false;
3887
3967
  const lastValue = lastInputData.buttons[index][2];
3888
3968
  const nextValue = states[2];
3889
- gamepadButton[PRIVATE$j].value =
3969
+ gamepadButton[PRIVATE$k].value =
3890
3970
  (nextValue - lastValue) * alpha + lastValue;
3891
3971
  });
3892
3972
  nextInputData.axes.forEach((nextValue, index) => {
3893
3973
  const lastValue = lastInputData.axes[index];
3894
- gamepad[PRIVATE$j].axesMap[index.toString()].x =
3974
+ gamepad[PRIVATE$k].axesMap[index.toString()].x =
3895
3975
  (nextValue - lastValue) * alpha + lastValue;
3896
3976
  });
3897
3977
  }
@@ -3901,13 +3981,13 @@
3901
3981
  const f1q = fromValues(lastTransform[3], lastTransform[4], lastTransform[5], lastTransform[6]);
3902
3982
  const f2p = fromValues$2(nextTransform[0], nextTransform[1], nextTransform[2]);
3903
3983
  const f2q = fromValues(nextTransform[3], nextTransform[4], nextTransform[5], nextTransform[6]);
3904
- lerp(this[PRIVATE$4].vec3, f1p, f2p, alpha);
3905
- slerp(this[PRIVATE$4].quat, f1q, f2q, alpha);
3906
- fromRotationTranslation(space[PRIVATE$k].offsetMatrix, this[PRIVATE$4].quat, this[PRIVATE$4].vec3);
3984
+ lerp(this[PRIVATE$3].vec3, f1p, f2p, alpha);
3985
+ slerp(this[PRIVATE$3].quat, f1q, f2q, alpha);
3986
+ fromRotationTranslation(space[PRIVATE$l].offsetMatrix, this[PRIVATE$3].quat, this[PRIVATE$3].vec3);
3907
3987
  }
3908
3988
  processRawInputData(inputDataRaw) {
3909
3989
  const index = inputDataRaw[0];
3910
- const schema = this[PRIVATE$4].inputSchemas.get(index);
3990
+ const schema = this[PRIVATE$3].inputSchemas.get(index);
3911
3991
  const targetRayTransform = inputDataRaw.slice(1, 8);
3912
3992
  const inputData = { targetRayTransform };
3913
3993
  let dataCounter = 8;
@@ -3926,7 +4006,7 @@
3926
4006
  }
3927
4007
  }
3928
4008
 
3929
- const VERSION = "1.0.1";
4009
+ const VERSION = "1.0.2";
3930
4010
 
3931
4011
  /**
3932
4012
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -3945,75 +4025,6 @@
3945
4025
  }
3946
4026
  }
3947
4027
 
3948
- /**
3949
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3950
- *
3951
- * This source code is licensed under the MIT license found in the
3952
- * LICENSE file in the root directory of this source tree.
3953
- */
3954
- const PRIVATE$3 = Symbol('@immersive-web-emulation-runtime/xr-system');
3955
- class XRSystem extends EventTarget {
3956
- constructor(device) {
3957
- super();
3958
- this[PRIVATE$3] = { device };
3959
- // Initialize device change monitoring here if applicable
3960
- }
3961
- isSessionSupported(mode) {
3962
- return new Promise((resolve, _reject) => {
3963
- if (mode === XRSessionMode.Inline) {
3964
- resolve(true);
3965
- }
3966
- else {
3967
- // Check for spatial tracking permission if necessary
3968
- resolve(this[PRIVATE$3].device.supportedSessionModes.includes(mode));
3969
- }
3970
- });
3971
- }
3972
- requestSession(mode, options = {}) {
3973
- return new Promise((resolve, reject) => {
3974
- this.isSessionSupported(mode)
3975
- .then((isSupported) => {
3976
- if (!isSupported) {
3977
- reject(new DOMException('The requested XRSession mode is not supported.', 'NotSupportedError'));
3978
- return;
3979
- }
3980
- // Check for active sessions and other constraints here
3981
- if (this[PRIVATE$3].activeSession) {
3982
- reject(new DOMException('An active XRSession already exists.', 'InvalidStateError'));
3983
- return;
3984
- }
3985
- // Handle required and optional features
3986
- const { requiredFeatures = [], optionalFeatures = [] } = options;
3987
- const { supportedFeatures } = this[PRIVATE$3].device;
3988
- // Check if all required features are supported
3989
- const allRequiredSupported = requiredFeatures.every((feature) => supportedFeatures.includes(feature));
3990
- if (!allRequiredSupported) {
3991
- reject(new Error('One or more required features are not supported by the device.'));
3992
- return;
3993
- }
3994
- // Filter out unsupported optional features
3995
- const supportedOptionalFeatures = optionalFeatures.filter((feature) => supportedFeatures.includes(feature));
3996
- // Combine required and supported optional features into enabled features
3997
- const enabledFeatures = Array.from(new Set([
3998
- ...requiredFeatures,
3999
- ...supportedOptionalFeatures,
4000
- WebXRFeatures.Viewer,
4001
- WebXRFeatures.Local,
4002
- ]));
4003
- // Proceed with session creation
4004
- const session = new XRSession(this[PRIVATE$3].device, mode, enabledFeatures);
4005
- this[PRIVATE$3].activeSession = session;
4006
- // Listen for session end to clear the active session
4007
- session.addEventListener('end', () => {
4008
- this[PRIVATE$3].activeSession = undefined;
4009
- });
4010
- resolve(session);
4011
- })
4012
- .catch(reject);
4013
- });
4014
- }
4015
- }
4016
-
4017
4028
  /**
4018
4029
  * Copyright (c) Meta Platforms, Inc. and affiliates.
4019
4030
  *
@@ -4126,6 +4137,7 @@
4126
4137
  pendingReferenceSpaceReset: false,
4127
4138
  visibilityState: XRVisibilityState.Visible,
4128
4139
  pendingVisibilityState: null,
4140
+ xrSystem: null,
4129
4141
  matrix: create$3(),
4130
4142
  globalSpace,
4131
4143
  viewerSpace,
@@ -4146,10 +4158,10 @@
4146
4158
  updateViews: () => {
4147
4159
  // update viewerSpace
4148
4160
  const viewerSpace = this[PRIVATE$1].viewerSpace;
4149
- fromRotationTranslation(viewerSpace[PRIVATE$k].offsetMatrix, this[PRIVATE$1].quaternion.quat, this[PRIVATE$1].position.vec3);
4161
+ fromRotationTranslation(viewerSpace[PRIVATE$l].offsetMatrix, this[PRIVATE$1].quaternion.quat, this[PRIVATE$1].position.vec3);
4150
4162
  // update viewSpaces
4151
- fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Left][PRIVATE$k].offsetMatrix, fromValues$2(-this[PRIVATE$1].ipd / 2, 0, 0));
4152
- fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Right][PRIVATE$k].offsetMatrix, fromValues$2(this[PRIVATE$1].ipd / 2, 0, 0));
4163
+ fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Left][PRIVATE$l].offsetMatrix, fromValues$2(-this[PRIVATE$1].ipd / 2, 0, 0));
4164
+ fromTranslation(this[PRIVATE$1].viewSpaces[XREye.Right][PRIVATE$l].offsetMatrix, fromValues$2(this[PRIVATE$1].ipd / 2, 0, 0));
4153
4165
  },
4154
4166
  onBaseLayerSet: (baseLayer) => {
4155
4167
  if (!baseLayer)
@@ -4231,8 +4243,9 @@
4231
4243
  },
4232
4244
  configurable: true,
4233
4245
  });
4246
+ this[PRIVATE$1].xrSystem = new XRSystem(this);
4234
4247
  Object.defineProperty(globalThis.navigator, 'xr', {
4235
- value: new XRSystem(this),
4248
+ value: this[PRIVATE$1].xrSystem,
4236
4249
  configurable: true,
4237
4250
  });
4238
4251
  Object.defineProperty(navigator, 'userAgent', {
@@ -4358,6 +4371,10 @@
4358
4371
  get canvasContainer() {
4359
4372
  return this[PRIVATE$1].canvasContainer;
4360
4373
  }
4374
+ get activeSession() {
4375
+ var _a;
4376
+ return (_a = this[PRIVATE$1].xrSystem) === null || _a === void 0 ? void 0 : _a[PRIVATE$4].activeSession;
4377
+ }
4361
4378
  recenter() {
4362
4379
  const deltaVec = new Vector3(-this.position.x, 0, -this.position.z);
4363
4380
  const forward = new Vector3(0, 0, -1).applyQuaternion(this.quaternion);