@aixa-transformation/pptx-viewer 2.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +369 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/README.md +249 -0
  5. package/dist/GLTFLoader-CV33YWNT.js +2613 -0
  6. package/dist/GLTFLoader-FQJ2I67K.mjs +2611 -0
  7. package/dist/Model3DScene-5ODZLKJM.mjs +49 -0
  8. package/dist/Model3DScene-VLHFNN5B.js +51 -0
  9. package/dist/OrbitControls-HI6CI76Z.mjs +3 -0
  10. package/dist/OrbitControls-XGY7XEC6.js +12 -0
  11. package/dist/SmartArt3DScene-3FL5JELA.mjs +333 -0
  12. package/dist/SmartArt3DScene-7IZ3IJYV.js +335 -0
  13. package/dist/SurfaceChart3DScene-C6GQQQB7.mjs +77 -0
  14. package/dist/SurfaceChart3DScene-KHMGQAGP.js +79 -0
  15. package/dist/chunk-2TOLRBFU.js +27629 -0
  16. package/dist/chunk-2X72MOPZ.mjs +2796 -0
  17. package/dist/chunk-6DZX6EAA.mjs +33 -0
  18. package/dist/chunk-AD2CLKY6.js +92338 -0
  19. package/dist/chunk-CUUYYYC5.js +2800 -0
  20. package/dist/chunk-DAKELFNP.js +915 -0
  21. package/dist/chunk-F2HFXS2Z.mjs +19063 -0
  22. package/dist/chunk-F3LO2NKI.mjs +913 -0
  23. package/dist/chunk-HNI6JYAI.js +34591 -0
  24. package/dist/chunk-IKBO6CZC.js +2 -0
  25. package/dist/chunk-KVM4DBEU.mjs +91768 -0
  26. package/dist/chunk-MOEXMRVK.js +19220 -0
  27. package/dist/chunk-QGM4M3NI.js +37 -0
  28. package/dist/chunk-SQY54X47.js +43506 -0
  29. package/dist/chunk-T5U6P2JH.mjs +1 -0
  30. package/dist/chunk-TB5ZWNMX.mjs +34577 -0
  31. package/dist/chunk-W5V6CEFL.mjs +43064 -0
  32. package/dist/chunk-XAVVR6OX.mjs +27204 -0
  33. package/dist/chunk-Y6FQDUJU.js +1160 -0
  34. package/dist/chunk-YI3G35EC.mjs +1076 -0
  35. package/dist/dist-LQJHTLHL.mjs +2 -0
  36. package/dist/dist-NVA3FEUV.js +2275 -0
  37. package/dist/i18n.d.ts +2 -0
  38. package/dist/i18n.js +19 -0
  39. package/dist/i18n.mjs +2 -0
  40. package/dist/index.d.ts +44 -0
  41. package/dist/index.js +135 -0
  42. package/dist/index.mjs +6 -0
  43. package/dist/internals.d.ts +1 -0
  44. package/dist/internals.js +311 -0
  45. package/dist/internals.mjs +6 -0
  46. package/dist/pptx-viewer.css +2 -0
  47. package/dist/presentation.d.ts +1 -0
  48. package/dist/presentation.js +11 -0
  49. package/dist/presentation.mjs +2 -0
  50. package/dist/three.module-HOXVV2KF.mjs +2 -0
  51. package/dist/three.module-QSJWIYNI.js +1771 -0
  52. package/dist/viewer/index.d.ts +1 -0
  53. package/dist/viewer/index.js +76 -0
  54. package/dist/viewer/index.mjs +7 -0
  55. package/dist/y-webrtc-DFUKFWCA.mjs +4279 -0
  56. package/dist/y-webrtc-RRACJ6WX.js +4284 -0
  57. package/dist/y-websocket-T5R5YGVE.mjs +378 -0
  58. package/dist/y-websocket-WMSHYIGX.js +384 -0
  59. package/package.json +141 -0
@@ -0,0 +1,913 @@
1
+ import { Ray, Plane, MathUtils, Vector3, Controls, MOUSE, TOUCH, Quaternion, Spherical, Vector2 } from './chunk-W5V6CEFL.mjs';
2
+
3
+ // ../../node_modules/three/examples/jsm/controls/OrbitControls.js
4
+ var _changeEvent = { type: "change" };
5
+ var _startEvent = { type: "start" };
6
+ var _endEvent = { type: "end" };
7
+ var _ray = new Ray();
8
+ var _plane = new Plane();
9
+ var _TILT_LIMIT = Math.cos(70 * MathUtils.DEG2RAD);
10
+ var _v = new Vector3();
11
+ var _twoPI = 2 * Math.PI;
12
+ var _STATE = {
13
+ NONE: -1,
14
+ ROTATE: 0,
15
+ DOLLY: 1,
16
+ PAN: 2,
17
+ TOUCH_ROTATE: 3,
18
+ TOUCH_PAN: 4,
19
+ TOUCH_DOLLY_PAN: 5,
20
+ TOUCH_DOLLY_ROTATE: 6
21
+ };
22
+ var _EPS = 1e-6;
23
+ var OrbitControls = class extends Controls {
24
+ /**
25
+ * Constructs a new controls instance.
26
+ *
27
+ * @param {Object3D} object - The object that is managed by the controls.
28
+ * @param {?HTMLElement} domElement - The HTML element used for event listeners.
29
+ */
30
+ constructor(object, domElement = null) {
31
+ super(object, domElement);
32
+ this.state = _STATE.NONE;
33
+ this.target = new Vector3();
34
+ this.cursor = new Vector3();
35
+ this.minDistance = 0;
36
+ this.maxDistance = Infinity;
37
+ this.minZoom = 0;
38
+ this.maxZoom = Infinity;
39
+ this.minTargetRadius = 0;
40
+ this.maxTargetRadius = Infinity;
41
+ this.minPolarAngle = 0;
42
+ this.maxPolarAngle = Math.PI;
43
+ this.minAzimuthAngle = -Infinity;
44
+ this.maxAzimuthAngle = Infinity;
45
+ this.enableDamping = false;
46
+ this.dampingFactor = 0.05;
47
+ this.enableZoom = true;
48
+ this.zoomSpeed = 1;
49
+ this.enableRotate = true;
50
+ this.rotateSpeed = 1;
51
+ this.keyRotateSpeed = 1;
52
+ this.enablePan = true;
53
+ this.panSpeed = 1;
54
+ this.screenSpacePanning = true;
55
+ this.keyPanSpeed = 7;
56
+ this.zoomToCursor = false;
57
+ this.autoRotate = false;
58
+ this.autoRotateSpeed = 2;
59
+ this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
60
+ this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
61
+ this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
62
+ this.target0 = this.target.clone();
63
+ this.position0 = this.object.position.clone();
64
+ this.zoom0 = this.object.zoom;
65
+ this._cursorStyle = "auto";
66
+ this._domElementKeyEvents = null;
67
+ this._lastPosition = new Vector3();
68
+ this._lastQuaternion = new Quaternion();
69
+ this._lastTargetPosition = new Vector3();
70
+ this._quat = new Quaternion().setFromUnitVectors(object.up, new Vector3(0, 1, 0));
71
+ this._quatInverse = this._quat.clone().invert();
72
+ this._spherical = new Spherical();
73
+ this._sphericalDelta = new Spherical();
74
+ this._scale = 1;
75
+ this._panOffset = new Vector3();
76
+ this._rotateStart = new Vector2();
77
+ this._rotateEnd = new Vector2();
78
+ this._rotateDelta = new Vector2();
79
+ this._panStart = new Vector2();
80
+ this._panEnd = new Vector2();
81
+ this._panDelta = new Vector2();
82
+ this._dollyStart = new Vector2();
83
+ this._dollyEnd = new Vector2();
84
+ this._dollyDelta = new Vector2();
85
+ this._dollyDirection = new Vector3();
86
+ this._mouse = new Vector2();
87
+ this._performCursorZoom = false;
88
+ this._pointers = [];
89
+ this._pointerPositions = {};
90
+ this._controlActive = false;
91
+ this._onPointerMove = onPointerMove.bind(this);
92
+ this._onPointerDown = onPointerDown.bind(this);
93
+ this._onPointerUp = onPointerUp.bind(this);
94
+ this._onContextMenu = onContextMenu.bind(this);
95
+ this._onMouseWheel = onMouseWheel.bind(this);
96
+ this._onKeyDown = onKeyDown.bind(this);
97
+ this._onTouchStart = onTouchStart.bind(this);
98
+ this._onTouchMove = onTouchMove.bind(this);
99
+ this._onMouseDown = onMouseDown.bind(this);
100
+ this._onMouseMove = onMouseMove.bind(this);
101
+ this._interceptControlDown = interceptControlDown.bind(this);
102
+ this._interceptControlUp = interceptControlUp.bind(this);
103
+ if (this.domElement !== null) {
104
+ this.connect(this.domElement);
105
+ }
106
+ this.update();
107
+ }
108
+ /**
109
+ * Defines the visual representation of the cursor.
110
+ *
111
+ * @type {('auto'|'grab')}
112
+ * @default 'auto'
113
+ */
114
+ set cursorStyle(type) {
115
+ this._cursorStyle = type;
116
+ if (type === "grab") {
117
+ this.domElement.style.cursor = "grab";
118
+ } else {
119
+ this.domElement.style.cursor = "auto";
120
+ }
121
+ }
122
+ get cursorStyle() {
123
+ return this._cursorStyle;
124
+ }
125
+ connect(element) {
126
+ super.connect(element);
127
+ this.domElement.addEventListener("pointerdown", this._onPointerDown);
128
+ this.domElement.addEventListener("pointercancel", this._onPointerUp);
129
+ this.domElement.addEventListener("contextmenu", this._onContextMenu);
130
+ this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: false });
131
+ const document = this.domElement.getRootNode();
132
+ document.addEventListener("keydown", this._interceptControlDown, { passive: true, capture: true });
133
+ this.domElement.style.touchAction = "none";
134
+ }
135
+ disconnect() {
136
+ this.domElement.removeEventListener("pointerdown", this._onPointerDown);
137
+ this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove);
138
+ this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp);
139
+ this.domElement.removeEventListener("pointercancel", this._onPointerUp);
140
+ this.domElement.removeEventListener("wheel", this._onMouseWheel);
141
+ this.domElement.removeEventListener("contextmenu", this._onContextMenu);
142
+ this.stopListenToKeyEvents();
143
+ const document = this.domElement.getRootNode();
144
+ document.removeEventListener("keydown", this._interceptControlDown, { capture: true });
145
+ this.domElement.style.touchAction = "";
146
+ }
147
+ dispose() {
148
+ this.disconnect();
149
+ }
150
+ /**
151
+ * Get the current vertical rotation, in radians.
152
+ *
153
+ * @return {number} The current vertical rotation, in radians.
154
+ */
155
+ getPolarAngle() {
156
+ return this._spherical.phi;
157
+ }
158
+ /**
159
+ * Get the current horizontal rotation, in radians.
160
+ *
161
+ * @return {number} The current horizontal rotation, in radians.
162
+ */
163
+ getAzimuthalAngle() {
164
+ return this._spherical.theta;
165
+ }
166
+ /**
167
+ * Returns the distance from the camera to the target.
168
+ *
169
+ * @return {number} The distance from the camera to the target.
170
+ */
171
+ getDistance() {
172
+ return this.object.position.distanceTo(this.target);
173
+ }
174
+ /**
175
+ * Adds key event listeners to the given DOM element.
176
+ * `window` is a recommended argument for using this method.
177
+ *
178
+ * @param {HTMLElement} domElement - The DOM element
179
+ */
180
+ listenToKeyEvents(domElement) {
181
+ domElement.addEventListener("keydown", this._onKeyDown);
182
+ this._domElementKeyEvents = domElement;
183
+ }
184
+ /**
185
+ * Removes the key event listener previously defined with `listenToKeyEvents()`.
186
+ */
187
+ stopListenToKeyEvents() {
188
+ if (this._domElementKeyEvents !== null) {
189
+ this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown);
190
+ this._domElementKeyEvents = null;
191
+ }
192
+ }
193
+ /**
194
+ * Save the current state of the controls. This can later be recovered with `reset()`.
195
+ */
196
+ saveState() {
197
+ this.target0.copy(this.target);
198
+ this.position0.copy(this.object.position);
199
+ this.zoom0 = this.object.zoom;
200
+ }
201
+ /**
202
+ * Reset the controls to their state from either the last time the `saveState()`
203
+ * was called, or the initial state.
204
+ */
205
+ reset() {
206
+ this.target.copy(this.target0);
207
+ this.object.position.copy(this.position0);
208
+ this.object.zoom = this.zoom0;
209
+ this.object.updateProjectionMatrix();
210
+ this.dispatchEvent(_changeEvent);
211
+ this.update();
212
+ this.state = _STATE.NONE;
213
+ }
214
+ /**
215
+ * Programmatically pan the camera.
216
+ *
217
+ * @param {number} deltaX - The horizontal pan amount in pixels.
218
+ * @param {number} deltaY - The vertical pan amount in pixels.
219
+ */
220
+ pan(deltaX, deltaY) {
221
+ this._pan(deltaX, deltaY);
222
+ this.update();
223
+ }
224
+ /**
225
+ * Programmatically dolly in (zoom in for perspective camera).
226
+ *
227
+ * @param {number} dollyScale - The dolly scale factor.
228
+ */
229
+ dollyIn(dollyScale) {
230
+ this._dollyIn(dollyScale);
231
+ this.update();
232
+ }
233
+ /**
234
+ * Programmatically dolly out (zoom out for perspective camera).
235
+ *
236
+ * @param {number} dollyScale - The dolly scale factor.
237
+ */
238
+ dollyOut(dollyScale) {
239
+ this._dollyOut(dollyScale);
240
+ this.update();
241
+ }
242
+ /**
243
+ * Programmatically rotate the camera left (around the vertical axis).
244
+ *
245
+ * @param {number} angle - The rotation angle in radians.
246
+ */
247
+ rotateLeft(angle) {
248
+ this._rotateLeft(angle);
249
+ this.update();
250
+ }
251
+ /**
252
+ * Programmatically rotate the camera up (around the horizontal axis).
253
+ *
254
+ * @param {number} angle - The rotation angle in radians.
255
+ */
256
+ rotateUp(angle) {
257
+ this._rotateUp(angle);
258
+ this.update();
259
+ }
260
+ update(deltaTime = null) {
261
+ const position = this.object.position;
262
+ _v.copy(position).sub(this.target);
263
+ _v.applyQuaternion(this._quat);
264
+ this._spherical.setFromVector3(_v);
265
+ if (this.autoRotate && this.state === _STATE.NONE) {
266
+ this._rotateLeft(this._getAutoRotationAngle(deltaTime));
267
+ }
268
+ if (this.enableDamping) {
269
+ this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor;
270
+ this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor;
271
+ } else {
272
+ this._spherical.theta += this._sphericalDelta.theta;
273
+ this._spherical.phi += this._sphericalDelta.phi;
274
+ }
275
+ let min = this.minAzimuthAngle;
276
+ let max = this.maxAzimuthAngle;
277
+ if (isFinite(min) && isFinite(max)) {
278
+ if (min < -Math.PI) min += _twoPI;
279
+ else if (min > Math.PI) min -= _twoPI;
280
+ if (max < -Math.PI) max += _twoPI;
281
+ else if (max > Math.PI) max -= _twoPI;
282
+ if (min <= max) {
283
+ this._spherical.theta = Math.max(min, Math.min(max, this._spherical.theta));
284
+ } else {
285
+ this._spherical.theta = this._spherical.theta > (min + max) / 2 ? Math.max(min, this._spherical.theta) : Math.min(max, this._spherical.theta);
286
+ }
287
+ }
288
+ this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi));
289
+ this._spherical.makeSafe();
290
+ if (this.enableDamping === true) {
291
+ this.target.addScaledVector(this._panOffset, this.dampingFactor);
292
+ } else {
293
+ this.target.add(this._panOffset);
294
+ }
295
+ this.target.sub(this.cursor);
296
+ this.target.clampLength(this.minTargetRadius, this.maxTargetRadius);
297
+ this.target.add(this.cursor);
298
+ let zoomChanged = false;
299
+ if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera) {
300
+ this._spherical.radius = this._clampDistance(this._spherical.radius);
301
+ } else {
302
+ const prevRadius = this._spherical.radius;
303
+ this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale);
304
+ zoomChanged = prevRadius != this._spherical.radius;
305
+ }
306
+ _v.setFromSpherical(this._spherical);
307
+ _v.applyQuaternion(this._quatInverse);
308
+ position.copy(this.target).add(_v);
309
+ this.object.lookAt(this.target);
310
+ if (this.enableDamping === true) {
311
+ this._sphericalDelta.theta *= 1 - this.dampingFactor;
312
+ this._sphericalDelta.phi *= 1 - this.dampingFactor;
313
+ this._panOffset.multiplyScalar(1 - this.dampingFactor);
314
+ } else {
315
+ this._sphericalDelta.set(0, 0, 0);
316
+ this._panOffset.set(0, 0, 0);
317
+ }
318
+ if (this.zoomToCursor && this._performCursorZoom) {
319
+ let newRadius = null;
320
+ if (this.object.isPerspectiveCamera) {
321
+ const prevRadius = _v.length();
322
+ newRadius = this._clampDistance(prevRadius * this._scale);
323
+ const radiusDelta = prevRadius - newRadius;
324
+ this.object.position.addScaledVector(this._dollyDirection, radiusDelta);
325
+ this.object.updateMatrixWorld();
326
+ zoomChanged = !!radiusDelta;
327
+ } else if (this.object.isOrthographicCamera) {
328
+ const mouseBefore = new Vector3(this._mouse.x, this._mouse.y, 0);
329
+ mouseBefore.unproject(this.object);
330
+ const prevZoom = this.object.zoom;
331
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale));
332
+ this.object.updateProjectionMatrix();
333
+ zoomChanged = prevZoom !== this.object.zoom;
334
+ const mouseAfter = new Vector3(this._mouse.x, this._mouse.y, 0);
335
+ mouseAfter.unproject(this.object);
336
+ this.object.position.sub(mouseAfter).add(mouseBefore);
337
+ this.object.updateMatrixWorld();
338
+ newRadius = _v.length();
339
+ } else {
340
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.");
341
+ this.zoomToCursor = false;
342
+ }
343
+ if (newRadius !== null) {
344
+ if (this.screenSpacePanning) {
345
+ this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(newRadius).add(this.object.position);
346
+ } else {
347
+ _ray.origin.copy(this.object.position);
348
+ _ray.direction.set(0, 0, -1).transformDirection(this.object.matrix);
349
+ if (Math.abs(this.object.up.dot(_ray.direction)) < _TILT_LIMIT) {
350
+ this.object.lookAt(this.target);
351
+ } else {
352
+ _plane.setFromNormalAndCoplanarPoint(this.object.up, this.target);
353
+ _ray.intersectPlane(_plane, this.target);
354
+ }
355
+ }
356
+ }
357
+ } else if (this.object.isOrthographicCamera) {
358
+ const prevZoom = this.object.zoom;
359
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale));
360
+ if (prevZoom !== this.object.zoom) {
361
+ this.object.updateProjectionMatrix();
362
+ zoomChanged = true;
363
+ }
364
+ }
365
+ this._scale = 1;
366
+ this._performCursorZoom = false;
367
+ if (zoomChanged || this._lastPosition.distanceToSquared(this.object.position) > _EPS || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > _EPS || this._lastTargetPosition.distanceToSquared(this.target) > _EPS) {
368
+ this.dispatchEvent(_changeEvent);
369
+ this._lastPosition.copy(this.object.position);
370
+ this._lastQuaternion.copy(this.object.quaternion);
371
+ this._lastTargetPosition.copy(this.target);
372
+ return true;
373
+ }
374
+ return false;
375
+ }
376
+ _getAutoRotationAngle(deltaTime) {
377
+ if (deltaTime !== null) {
378
+ return _twoPI / 60 * this.autoRotateSpeed * deltaTime;
379
+ } else {
380
+ return _twoPI / 60 / 60 * this.autoRotateSpeed;
381
+ }
382
+ }
383
+ _getZoomScale(delta) {
384
+ const normalizedDelta = Math.abs(delta * 0.01);
385
+ return Math.pow(0.95, this.zoomSpeed * normalizedDelta);
386
+ }
387
+ _rotateLeft(angle) {
388
+ this._sphericalDelta.theta -= angle;
389
+ }
390
+ _rotateUp(angle) {
391
+ this._sphericalDelta.phi -= angle;
392
+ }
393
+ _panLeft(distance, objectMatrix) {
394
+ _v.setFromMatrixColumn(objectMatrix, 0);
395
+ _v.multiplyScalar(-distance);
396
+ this._panOffset.add(_v);
397
+ }
398
+ _panUp(distance, objectMatrix) {
399
+ if (this.screenSpacePanning === true) {
400
+ _v.setFromMatrixColumn(objectMatrix, 1);
401
+ } else {
402
+ _v.setFromMatrixColumn(objectMatrix, 0);
403
+ _v.crossVectors(this.object.up, _v);
404
+ }
405
+ _v.multiplyScalar(distance);
406
+ this._panOffset.add(_v);
407
+ }
408
+ // deltaX and deltaY are in pixels; right and down are positive
409
+ _pan(deltaX, deltaY) {
410
+ const element = this.domElement;
411
+ if (this.object.isPerspectiveCamera) {
412
+ const position = this.object.position;
413
+ _v.copy(position).sub(this.target);
414
+ let targetDistance = _v.length();
415
+ targetDistance *= Math.tan(this.object.fov / 2 * Math.PI / 180);
416
+ this._panLeft(2 * deltaX * targetDistance / element.clientHeight, this.object.matrix);
417
+ this._panUp(2 * deltaY * targetDistance / element.clientHeight, this.object.matrix);
418
+ } else if (this.object.isOrthographicCamera) {
419
+ this._panLeft(deltaX * (this.object.right - this.object.left) / this.object.zoom / element.clientWidth, this.object.matrix);
420
+ this._panUp(deltaY * (this.object.top - this.object.bottom) / this.object.zoom / element.clientHeight, this.object.matrix);
421
+ } else {
422
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
423
+ this.enablePan = false;
424
+ }
425
+ }
426
+ _dollyOut(dollyScale) {
427
+ if (this.object.isPerspectiveCamera || this.object.isOrthographicCamera) {
428
+ this._scale /= dollyScale;
429
+ } else {
430
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
431
+ this.enableZoom = false;
432
+ }
433
+ }
434
+ _dollyIn(dollyScale) {
435
+ if (this.object.isPerspectiveCamera || this.object.isOrthographicCamera) {
436
+ this._scale *= dollyScale;
437
+ } else {
438
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
439
+ this.enableZoom = false;
440
+ }
441
+ }
442
+ _updateZoomParameters(x, y) {
443
+ if (!this.zoomToCursor) {
444
+ return;
445
+ }
446
+ this._performCursorZoom = true;
447
+ const rect = this.domElement.getBoundingClientRect();
448
+ const dx = x - rect.left;
449
+ const dy = y - rect.top;
450
+ const w = rect.width;
451
+ const h = rect.height;
452
+ this._mouse.x = dx / w * 2 - 1;
453
+ this._mouse.y = -(dy / h) * 2 + 1;
454
+ this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
455
+ }
456
+ _clampDistance(dist) {
457
+ return Math.max(this.minDistance, Math.min(this.maxDistance, dist));
458
+ }
459
+ //
460
+ // event callbacks - update the object state
461
+ //
462
+ _handleMouseDownRotate(event) {
463
+ this._rotateStart.set(event.clientX, event.clientY);
464
+ }
465
+ _handleMouseDownDolly(event) {
466
+ this._updateZoomParameters(event.clientX, event.clientX);
467
+ this._dollyStart.set(event.clientX, event.clientY);
468
+ }
469
+ _handleMouseDownPan(event) {
470
+ this._panStart.set(event.clientX, event.clientY);
471
+ }
472
+ _handleMouseMoveRotate(event) {
473
+ this._rotateEnd.set(event.clientX, event.clientY);
474
+ this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
475
+ const element = this.domElement;
476
+ this._rotateLeft(_twoPI * this._rotateDelta.x / element.clientHeight);
477
+ this._rotateUp(_twoPI * this._rotateDelta.y / element.clientHeight);
478
+ this._rotateStart.copy(this._rotateEnd);
479
+ this.update();
480
+ }
481
+ _handleMouseMoveDolly(event) {
482
+ this._dollyEnd.set(event.clientX, event.clientY);
483
+ this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart);
484
+ if (this._dollyDelta.y > 0) {
485
+ this._dollyOut(this._getZoomScale(this._dollyDelta.y));
486
+ } else if (this._dollyDelta.y < 0) {
487
+ this._dollyIn(this._getZoomScale(this._dollyDelta.y));
488
+ }
489
+ this._dollyStart.copy(this._dollyEnd);
490
+ this.update();
491
+ }
492
+ _handleMouseMovePan(event) {
493
+ this._panEnd.set(event.clientX, event.clientY);
494
+ this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed);
495
+ this._pan(this._panDelta.x, this._panDelta.y);
496
+ this._panStart.copy(this._panEnd);
497
+ this.update();
498
+ }
499
+ _handleMouseWheel(event) {
500
+ this._updateZoomParameters(event.clientX, event.clientY);
501
+ if (event.deltaY < 0) {
502
+ this._dollyIn(this._getZoomScale(event.deltaY));
503
+ } else if (event.deltaY > 0) {
504
+ this._dollyOut(this._getZoomScale(event.deltaY));
505
+ }
506
+ this.update();
507
+ }
508
+ _handleKeyDown(event) {
509
+ let needsUpdate = false;
510
+ switch (event.code) {
511
+ case this.keys.UP:
512
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
513
+ if (this.enableRotate) {
514
+ this._rotateUp(_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
515
+ }
516
+ } else {
517
+ if (this.enablePan) {
518
+ this._pan(0, this.keyPanSpeed);
519
+ }
520
+ }
521
+ needsUpdate = true;
522
+ break;
523
+ case this.keys.BOTTOM:
524
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
525
+ if (this.enableRotate) {
526
+ this._rotateUp(-_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
527
+ }
528
+ } else {
529
+ if (this.enablePan) {
530
+ this._pan(0, -this.keyPanSpeed);
531
+ }
532
+ }
533
+ needsUpdate = true;
534
+ break;
535
+ case this.keys.LEFT:
536
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
537
+ if (this.enableRotate) {
538
+ this._rotateLeft(_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
539
+ }
540
+ } else {
541
+ if (this.enablePan) {
542
+ this._pan(this.keyPanSpeed, 0);
543
+ }
544
+ }
545
+ needsUpdate = true;
546
+ break;
547
+ case this.keys.RIGHT:
548
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
549
+ if (this.enableRotate) {
550
+ this._rotateLeft(-_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
551
+ }
552
+ } else {
553
+ if (this.enablePan) {
554
+ this._pan(-this.keyPanSpeed, 0);
555
+ }
556
+ }
557
+ needsUpdate = true;
558
+ break;
559
+ }
560
+ if (needsUpdate) {
561
+ event.preventDefault();
562
+ this.update();
563
+ }
564
+ }
565
+ _handleTouchStartRotate(event) {
566
+ if (this._pointers.length === 1) {
567
+ this._rotateStart.set(event.pageX, event.pageY);
568
+ } else {
569
+ const position = this._getSecondPointerPosition(event);
570
+ const x = 0.5 * (event.pageX + position.x);
571
+ const y = 0.5 * (event.pageY + position.y);
572
+ this._rotateStart.set(x, y);
573
+ }
574
+ }
575
+ _handleTouchStartPan(event) {
576
+ if (this._pointers.length === 1) {
577
+ this._panStart.set(event.pageX, event.pageY);
578
+ } else {
579
+ const position = this._getSecondPointerPosition(event);
580
+ const x = 0.5 * (event.pageX + position.x);
581
+ const y = 0.5 * (event.pageY + position.y);
582
+ this._panStart.set(x, y);
583
+ }
584
+ }
585
+ _handleTouchStartDolly(event) {
586
+ const position = this._getSecondPointerPosition(event);
587
+ const dx = event.pageX - position.x;
588
+ const dy = event.pageY - position.y;
589
+ const distance = Math.sqrt(dx * dx + dy * dy);
590
+ this._dollyStart.set(0, distance);
591
+ }
592
+ _handleTouchStartDollyPan(event) {
593
+ if (this.enableZoom) this._handleTouchStartDolly(event);
594
+ if (this.enablePan) this._handleTouchStartPan(event);
595
+ }
596
+ _handleTouchStartDollyRotate(event) {
597
+ if (this.enableZoom) this._handleTouchStartDolly(event);
598
+ if (this.enableRotate) this._handleTouchStartRotate(event);
599
+ }
600
+ _handleTouchMoveRotate(event) {
601
+ if (this._pointers.length == 1) {
602
+ this._rotateEnd.set(event.pageX, event.pageY);
603
+ } else {
604
+ const position = this._getSecondPointerPosition(event);
605
+ const x = 0.5 * (event.pageX + position.x);
606
+ const y = 0.5 * (event.pageY + position.y);
607
+ this._rotateEnd.set(x, y);
608
+ }
609
+ this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
610
+ const element = this.domElement;
611
+ this._rotateLeft(_twoPI * this._rotateDelta.x / element.clientHeight);
612
+ this._rotateUp(_twoPI * this._rotateDelta.y / element.clientHeight);
613
+ this._rotateStart.copy(this._rotateEnd);
614
+ }
615
+ _handleTouchMovePan(event) {
616
+ if (this._pointers.length === 1) {
617
+ this._panEnd.set(event.pageX, event.pageY);
618
+ } else {
619
+ const position = this._getSecondPointerPosition(event);
620
+ const x = 0.5 * (event.pageX + position.x);
621
+ const y = 0.5 * (event.pageY + position.y);
622
+ this._panEnd.set(x, y);
623
+ }
624
+ this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed);
625
+ this._pan(this._panDelta.x, this._panDelta.y);
626
+ this._panStart.copy(this._panEnd);
627
+ }
628
+ _handleTouchMoveDolly(event) {
629
+ const position = this._getSecondPointerPosition(event);
630
+ const dx = event.pageX - position.x;
631
+ const dy = event.pageY - position.y;
632
+ const distance = Math.sqrt(dx * dx + dy * dy);
633
+ this._dollyEnd.set(0, distance);
634
+ this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed));
635
+ this._dollyOut(this._dollyDelta.y);
636
+ this._dollyStart.copy(this._dollyEnd);
637
+ const centerX = (event.pageX + position.x) * 0.5;
638
+ const centerY = (event.pageY + position.y) * 0.5;
639
+ this._updateZoomParameters(centerX, centerY);
640
+ }
641
+ _handleTouchMoveDollyPan(event) {
642
+ if (this.enableZoom) this._handleTouchMoveDolly(event);
643
+ if (this.enablePan) this._handleTouchMovePan(event);
644
+ }
645
+ _handleTouchMoveDollyRotate(event) {
646
+ if (this.enableZoom) this._handleTouchMoveDolly(event);
647
+ if (this.enableRotate) this._handleTouchMoveRotate(event);
648
+ }
649
+ // pointers
650
+ _addPointer(event) {
651
+ this._pointers.push(event.pointerId);
652
+ }
653
+ _removePointer(event) {
654
+ delete this._pointerPositions[event.pointerId];
655
+ for (let i = 0; i < this._pointers.length; i++) {
656
+ if (this._pointers[i] == event.pointerId) {
657
+ this._pointers.splice(i, 1);
658
+ return;
659
+ }
660
+ }
661
+ }
662
+ _isTrackingPointer(event) {
663
+ for (let i = 0; i < this._pointers.length; i++) {
664
+ if (this._pointers[i] == event.pointerId) return true;
665
+ }
666
+ return false;
667
+ }
668
+ _trackPointer(event) {
669
+ let position = this._pointerPositions[event.pointerId];
670
+ if (position === void 0) {
671
+ position = new Vector2();
672
+ this._pointerPositions[event.pointerId] = position;
673
+ }
674
+ position.set(event.pageX, event.pageY);
675
+ }
676
+ _getSecondPointerPosition(event) {
677
+ const pointerId = event.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
678
+ return this._pointerPositions[pointerId];
679
+ }
680
+ //
681
+ _customWheelEvent(event) {
682
+ const mode = event.deltaMode;
683
+ const newEvent = {
684
+ clientX: event.clientX,
685
+ clientY: event.clientY,
686
+ deltaY: event.deltaY
687
+ };
688
+ switch (mode) {
689
+ case 1:
690
+ newEvent.deltaY *= 16;
691
+ break;
692
+ case 2:
693
+ newEvent.deltaY *= 100;
694
+ break;
695
+ }
696
+ if (event.ctrlKey && !this._controlActive) {
697
+ newEvent.deltaY *= 10;
698
+ }
699
+ return newEvent;
700
+ }
701
+ };
702
+ function onPointerDown(event) {
703
+ if (this.enabled === false) return;
704
+ if (this._pointers.length === 0) {
705
+ this.domElement.setPointerCapture(event.pointerId);
706
+ this.domElement.ownerDocument.addEventListener("pointermove", this._onPointerMove);
707
+ this.domElement.ownerDocument.addEventListener("pointerup", this._onPointerUp);
708
+ }
709
+ if (this._isTrackingPointer(event)) return;
710
+ this._addPointer(event);
711
+ if (event.pointerType === "touch") {
712
+ this._onTouchStart(event);
713
+ } else {
714
+ this._onMouseDown(event);
715
+ }
716
+ if (this._cursorStyle === "grab") {
717
+ this.domElement.style.cursor = "grabbing";
718
+ }
719
+ }
720
+ function onPointerMove(event) {
721
+ if (this.enabled === false) return;
722
+ if (event.pointerType === "touch") {
723
+ this._onTouchMove(event);
724
+ } else {
725
+ this._onMouseMove(event);
726
+ }
727
+ }
728
+ function onPointerUp(event) {
729
+ this._removePointer(event);
730
+ switch (this._pointers.length) {
731
+ case 0:
732
+ this.domElement.releasePointerCapture(event.pointerId);
733
+ this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove);
734
+ this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp);
735
+ this.dispatchEvent(_endEvent);
736
+ this.state = _STATE.NONE;
737
+ if (this._cursorStyle === "grab") {
738
+ this.domElement.style.cursor = "grab";
739
+ }
740
+ break;
741
+ case 1:
742
+ const pointerId = this._pointers[0];
743
+ const position = this._pointerPositions[pointerId];
744
+ this._onTouchStart({ pointerId, pageX: position.x, pageY: position.y });
745
+ break;
746
+ }
747
+ }
748
+ function onMouseDown(event) {
749
+ let mouseAction;
750
+ switch (event.button) {
751
+ case 0:
752
+ mouseAction = this.mouseButtons.LEFT;
753
+ break;
754
+ case 1:
755
+ mouseAction = this.mouseButtons.MIDDLE;
756
+ break;
757
+ case 2:
758
+ mouseAction = this.mouseButtons.RIGHT;
759
+ break;
760
+ default:
761
+ mouseAction = -1;
762
+ }
763
+ switch (mouseAction) {
764
+ case MOUSE.DOLLY:
765
+ if (this.enableZoom === false) return;
766
+ this._handleMouseDownDolly(event);
767
+ this.state = _STATE.DOLLY;
768
+ break;
769
+ case MOUSE.ROTATE:
770
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
771
+ if (this.enablePan === false) return;
772
+ this._handleMouseDownPan(event);
773
+ this.state = _STATE.PAN;
774
+ } else {
775
+ if (this.enableRotate === false) return;
776
+ this._handleMouseDownRotate(event);
777
+ this.state = _STATE.ROTATE;
778
+ }
779
+ break;
780
+ case MOUSE.PAN:
781
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
782
+ if (this.enableRotate === false) return;
783
+ this._handleMouseDownRotate(event);
784
+ this.state = _STATE.ROTATE;
785
+ } else {
786
+ if (this.enablePan === false) return;
787
+ this._handleMouseDownPan(event);
788
+ this.state = _STATE.PAN;
789
+ }
790
+ break;
791
+ default:
792
+ this.state = _STATE.NONE;
793
+ }
794
+ if (this.state !== _STATE.NONE) {
795
+ this.dispatchEvent(_startEvent);
796
+ }
797
+ }
798
+ function onMouseMove(event) {
799
+ switch (this.state) {
800
+ case _STATE.ROTATE:
801
+ if (this.enableRotate === false) return;
802
+ this._handleMouseMoveRotate(event);
803
+ break;
804
+ case _STATE.DOLLY:
805
+ if (this.enableZoom === false) return;
806
+ this._handleMouseMoveDolly(event);
807
+ break;
808
+ case _STATE.PAN:
809
+ if (this.enablePan === false) return;
810
+ this._handleMouseMovePan(event);
811
+ break;
812
+ }
813
+ }
814
+ function onMouseWheel(event) {
815
+ if (this.enabled === false || this.enableZoom === false || this.state !== _STATE.NONE) return;
816
+ event.preventDefault();
817
+ this.dispatchEvent(_startEvent);
818
+ this._handleMouseWheel(this._customWheelEvent(event));
819
+ this.dispatchEvent(_endEvent);
820
+ }
821
+ function onKeyDown(event) {
822
+ if (this.enabled === false) return;
823
+ this._handleKeyDown(event);
824
+ }
825
+ function onTouchStart(event) {
826
+ this._trackPointer(event);
827
+ switch (this._pointers.length) {
828
+ case 1:
829
+ switch (this.touches.ONE) {
830
+ case TOUCH.ROTATE:
831
+ if (this.enableRotate === false) return;
832
+ this._handleTouchStartRotate(event);
833
+ this.state = _STATE.TOUCH_ROTATE;
834
+ break;
835
+ case TOUCH.PAN:
836
+ if (this.enablePan === false) return;
837
+ this._handleTouchStartPan(event);
838
+ this.state = _STATE.TOUCH_PAN;
839
+ break;
840
+ default:
841
+ this.state = _STATE.NONE;
842
+ }
843
+ break;
844
+ case 2:
845
+ switch (this.touches.TWO) {
846
+ case TOUCH.DOLLY_PAN:
847
+ if (this.enableZoom === false && this.enablePan === false) return;
848
+ this._handleTouchStartDollyPan(event);
849
+ this.state = _STATE.TOUCH_DOLLY_PAN;
850
+ break;
851
+ case TOUCH.DOLLY_ROTATE:
852
+ if (this.enableZoom === false && this.enableRotate === false) return;
853
+ this._handleTouchStartDollyRotate(event);
854
+ this.state = _STATE.TOUCH_DOLLY_ROTATE;
855
+ break;
856
+ default:
857
+ this.state = _STATE.NONE;
858
+ }
859
+ break;
860
+ default:
861
+ this.state = _STATE.NONE;
862
+ }
863
+ if (this.state !== _STATE.NONE) {
864
+ this.dispatchEvent(_startEvent);
865
+ }
866
+ }
867
+ function onTouchMove(event) {
868
+ this._trackPointer(event);
869
+ switch (this.state) {
870
+ case _STATE.TOUCH_ROTATE:
871
+ if (this.enableRotate === false) return;
872
+ this._handleTouchMoveRotate(event);
873
+ this.update();
874
+ break;
875
+ case _STATE.TOUCH_PAN:
876
+ if (this.enablePan === false) return;
877
+ this._handleTouchMovePan(event);
878
+ this.update();
879
+ break;
880
+ case _STATE.TOUCH_DOLLY_PAN:
881
+ if (this.enableZoom === false && this.enablePan === false) return;
882
+ this._handleTouchMoveDollyPan(event);
883
+ this.update();
884
+ break;
885
+ case _STATE.TOUCH_DOLLY_ROTATE:
886
+ if (this.enableZoom === false && this.enableRotate === false) return;
887
+ this._handleTouchMoveDollyRotate(event);
888
+ this.update();
889
+ break;
890
+ default:
891
+ this.state = _STATE.NONE;
892
+ }
893
+ }
894
+ function onContextMenu(event) {
895
+ if (this.enabled === false) return;
896
+ event.preventDefault();
897
+ }
898
+ function interceptControlDown(event) {
899
+ if (event.key === "Control") {
900
+ this._controlActive = true;
901
+ const document = this.domElement.getRootNode();
902
+ document.addEventListener("keyup", this._interceptControlUp, { passive: true, capture: true });
903
+ }
904
+ }
905
+ function interceptControlUp(event) {
906
+ if (event.key === "Control") {
907
+ this._controlActive = false;
908
+ const document = this.domElement.getRootNode();
909
+ document.removeEventListener("keyup", this._interceptControlUp, { passive: true, capture: true });
910
+ }
911
+ }
912
+
913
+ export { OrbitControls };