@zenvor/view360 4.0.0-beta.7-fork.1
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/LICENSE +19 -0
- package/README.md +88 -0
- package/css/base.css +19 -0
- package/css/base.min.css +1 -0
- package/css/control-bar.css +329 -0
- package/css/control-bar.min.css +1 -0
- package/css/helper.css +51 -0
- package/css/helper.min.css +1 -0
- package/css/hotspot.css +21 -0
- package/css/hotspot.min.css +1 -0
- package/css/loading-spinner.css +37 -0
- package/css/loading-spinner.min.css +1 -0
- package/css/variable.css +1 -0
- package/css/variable.min.css +0 -0
- package/css/view360.css +468 -0
- package/css/view360.min.css +1 -0
- package/css/vr.css +8 -0
- package/css/vr.min.css +1 -0
- package/declaration/View360.d.ts +150 -0
- package/declaration/cfc/const.d.ts +1 -0
- package/declaration/cfc/index.d.ts +4 -0
- package/declaration/cfc/utils.d.ts +1 -0
- package/declaration/cfc/withMethods.d.ts +2 -0
- package/declaration/const/browser.d.ts +71 -0
- package/declaration/const/error.d.ts +47 -0
- package/declaration/const/external.d.ts +33 -0
- package/declaration/const/internal.d.ts +34 -0
- package/declaration/control/CameraControl.d.ts +10 -0
- package/declaration/control/GyroControl.d.ts +30 -0
- package/declaration/control/PanoControl.d.ts +58 -0
- package/declaration/control/RotateControl.d.ts +75 -0
- package/declaration/control/ZoomControl.d.ts +45 -0
- package/declaration/control/index.d.ts +7 -0
- package/declaration/control/input/GyroInput.d.ts +46 -0
- package/declaration/control/input/KeyboardInput.d.ts +21 -0
- package/declaration/control/input/MouseInput.d.ts +16 -0
- package/declaration/control/input/PinchInput.d.ts +14 -0
- package/declaration/control/input/PointerInput.d.ts +18 -0
- package/declaration/control/input/TouchInput.d.ts +21 -0
- package/declaration/control/input/WheelInput.d.ts +16 -0
- package/declaration/core/AutoResizer.d.ts +13 -0
- package/declaration/core/Autoplay.d.ts +54 -0
- package/declaration/core/Camera.d.ts +88 -0
- package/declaration/core/CameraAnimation.d.ts +25 -0
- package/declaration/core/CameraPath.d.ts +55 -0
- package/declaration/core/CubeTexturePainter.d.ts +16 -0
- package/declaration/core/FrameAnimator.d.ts +13 -0
- package/declaration/core/Motion.d.ts +39 -0
- package/declaration/core/Object3D.d.ts +21 -0
- package/declaration/core/ShaderProgram.d.ts +10 -0
- package/declaration/core/TextureLoader.d.ts +26 -0
- package/declaration/core/TriangleMesh.d.ts +20 -0
- package/declaration/core/VertexArrayObject.d.ts +14 -0
- package/declaration/core/VertexData.d.ts +8 -0
- package/declaration/core/View360Error.d.ts +5 -0
- package/declaration/core/WebGLContext.d.ts +74 -0
- package/declaration/core/WebGLRenderer.d.ts +26 -0
- package/declaration/core/XRManager.d.ts +33 -0
- package/declaration/core/index.d.ts +12 -0
- package/declaration/geometry/CubeGeometry.d.ts +9 -0
- package/declaration/geometry/CylinderGeometry.d.ts +5 -0
- package/declaration/geometry/Geometry.d.ts +8 -0
- package/declaration/geometry/PlaneGeometry.d.ts +5 -0
- package/declaration/geometry/SphereGeometry.d.ts +5 -0
- package/declaration/hotspot/Hotspot.d.ts +7 -0
- package/declaration/hotspot/HotspotRenderer.d.ts +17 -0
- package/declaration/hotspot/index.d.ts +4 -0
- package/declaration/index.cjs.d.ts +3 -0
- package/declaration/index.d.ts +11 -0
- package/declaration/index.umd.d.ts +2 -0
- package/declaration/plugin/ControlBar/AutoHide.d.ts +42 -0
- package/declaration/plugin/ControlBar/ControlBar.d.ts +113 -0
- package/declaration/plugin/ControlBar/ControlBarItem.d.ts +15 -0
- package/declaration/plugin/ControlBar/FullscreenButton.d.ts +19 -0
- package/declaration/plugin/ControlBar/GyroButton.d.ts +14 -0
- package/declaration/plugin/ControlBar/PieView.d.ts +26 -0
- package/declaration/plugin/ControlBar/PlayButton.d.ts +16 -0
- package/declaration/plugin/ControlBar/ProgressBar.d.ts +23 -0
- package/declaration/plugin/ControlBar/RangeControl.d.ts +27 -0
- package/declaration/plugin/ControlBar/VRButton.d.ts +12 -0
- package/declaration/plugin/ControlBar/VideoControl.d.ts +11 -0
- package/declaration/plugin/ControlBar/VideoTime.d.ts +17 -0
- package/declaration/plugin/ControlBar/VolumeControl.d.ts +23 -0
- package/declaration/plugin/ControlBar/const.d.ts +41 -0
- package/declaration/plugin/ControlBar/index.d.ts +11 -0
- package/declaration/plugin/LoadingSpinner/LoadingSpinner.d.ts +22 -0
- package/declaration/plugin/View360Plugin.d.ts +6 -0
- package/declaration/plugin/index.d.ts +5 -0
- package/declaration/projection/CorrectionPass.d.ts +26 -0
- package/declaration/projection/CubemapProjection.d.ts +19 -0
- package/declaration/projection/CubestripProjection.d.ts +18 -0
- package/declaration/projection/CylindricalProjection.d.ts +22 -0
- package/declaration/projection/EquiangularProjection.d.ts +13 -0
- package/declaration/projection/EquirectProjection.d.ts +15 -0
- package/declaration/projection/LittlePlanetProjection.d.ts +21 -0
- package/declaration/projection/Projection.d.ts +19 -0
- package/declaration/projection/StereoEquiProjection.d.ts +25 -0
- package/declaration/projection/WideAngleCorrectionProjection.d.ts +27 -0
- package/declaration/projection/WideAngleRealtimeProjection.d.ts +50 -0
- package/declaration/projection/index.d.ts +12 -0
- package/declaration/texture/Texture.d.ts +18 -0
- package/declaration/texture/Texture2D.d.ts +11 -0
- package/declaration/texture/TextureCube.d.ts +12 -0
- package/declaration/texture/TextureRenderTarget.d.ts +8 -0
- package/declaration/texture/TextureVideo.d.ts +11 -0
- package/declaration/type/events.d.ts +74 -0
- package/declaration/type/external.d.ts +13 -0
- package/declaration/type/internal.d.ts +47 -0
- package/declaration/type/utils.d.ts +11 -0
- package/declaration/uniform/Uniform.d.ts +7 -0
- package/declaration/uniform/UniformBoolean.d.ts +7 -0
- package/declaration/uniform/UniformCanvasCube.d.ts +12 -0
- package/declaration/uniform/UniformFloat.d.ts +7 -0
- package/declaration/uniform/UniformInt.d.ts +7 -0
- package/declaration/uniform/UniformMatrix.d.ts +8 -0
- package/declaration/uniform/UniformTexture2D.d.ts +11 -0
- package/declaration/uniform/UniformTextureCube.d.ts +12 -0
- package/declaration/uniform/UniformTextureRenderTarget.d.ts +11 -0
- package/declaration/uniform/UniformVec2.d.ts +7 -0
- package/declaration/uniform/UniformVec3.d.ts +7 -0
- package/declaration/uniform/UniformVector4Array.d.ts +7 -0
- package/declaration/utils.d.ts +25 -0
- package/dist/view360.cjs.js +9392 -0
- package/dist/view360.cjs.js.map +1 -0
- package/dist/view360.esm.js +9274 -0
- package/dist/view360.esm.js.map +1 -0
- package/dist/view360.js +9350 -0
- package/dist/view360.js.map +1 -0
- package/dist/view360.min.js +2 -0
- package/dist/view360.min.js.map +1 -0
- package/dist/view360.pkgd.js +48537 -0
- package/dist/view360.pkgd.js.map +1 -0
- package/dist/view360.pkgd.min.js +16 -0
- package/dist/view360.pkgd.min.js.map +1 -0
- package/package.json +110 -0
- package/sass/base.sass +17 -0
- package/sass/control-bar.sass +284 -0
- package/sass/helper.sass +51 -0
- package/sass/hotspot.sass +20 -0
- package/sass/loading-spinner.sass +34 -0
- package/sass/variable.sass +2 -0
- package/sass/view360.sass +6 -0
- package/sass/vr.sass +10 -0
- package/src/View360.ts +1220 -0
- package/src/cfc/const.ts +15 -0
- package/src/cfc/index.ts +8 -0
- package/src/cfc/utils.ts +12 -0
- package/src/cfc/withMethods.ts +40 -0
- package/src/const/browser.ts +109 -0
- package/src/const/error.ts +83 -0
- package/src/const/external.ts +77 -0
- package/src/const/internal.ts +53 -0
- package/src/control/CameraControl.ts +53 -0
- package/src/control/GyroControl.ts +225 -0
- package/src/control/PanoControl.ts +434 -0
- package/src/control/RotateControl.ts +411 -0
- package/src/control/ZoomControl.ts +254 -0
- package/src/control/index.ts +24 -0
- package/src/control/input/GyroInput.ts +315 -0
- package/src/control/input/KeyboardInput.ts +151 -0
- package/src/control/input/MouseInput.ts +102 -0
- package/src/control/input/PinchInput.ts +101 -0
- package/src/control/input/PointerInput.ts +118 -0
- package/src/control/input/TouchInput.ts +138 -0
- package/src/control/input/WheelInput.ts +89 -0
- package/src/core/AutoResizer.ts +92 -0
- package/src/core/Autoplay.ts +326 -0
- package/src/core/Camera.ts +616 -0
- package/src/core/CameraAnimation.ts +110 -0
- package/src/core/CameraPath.ts +454 -0
- package/src/core/CubeTexturePainter.ts +95 -0
- package/src/core/FrameAnimator.ts +69 -0
- package/src/core/Motion.ts +205 -0
- package/src/core/Object3D.ts +81 -0
- package/src/core/ShaderProgram.ts +21 -0
- package/src/core/TextureLoader.ts +303 -0
- package/src/core/TriangleMesh.ts +54 -0
- package/src/core/VertexArrayObject.ts +29 -0
- package/src/core/VertexData.ts +23 -0
- package/src/core/View360Error.ts +35 -0
- package/src/core/WebGLContext.ts +558 -0
- package/src/core/WebGLRenderer.ts +205 -0
- package/src/core/XRManager.ts +193 -0
- package/src/core/index.ts +35 -0
- package/src/geometry/CubeGeometry.ts +121 -0
- package/src/geometry/CylinderGeometry.ts +49 -0
- package/src/geometry/Geometry.ts +23 -0
- package/src/geometry/PlaneGeometry.ts +36 -0
- package/src/geometry/SphereGeometry.ts +55 -0
- package/src/hotspot/Hotspot.ts +32 -0
- package/src/hotspot/HotspotRenderer.ts +155 -0
- package/src/hotspot/index.ts +11 -0
- package/src/index.cjs.ts +13 -0
- package/src/index.ts +21 -0
- package/src/index.umd.ts +10 -0
- package/src/plugin/ControlBar/AutoHide.ts +246 -0
- package/src/plugin/ControlBar/ControlBar.ts +564 -0
- package/src/plugin/ControlBar/ControlBarItem.ts +84 -0
- package/src/plugin/ControlBar/FullscreenButton.ts +145 -0
- package/src/plugin/ControlBar/GyroButton.ts +124 -0
- package/src/plugin/ControlBar/PieView.ts +195 -0
- package/src/plugin/ControlBar/PlayButton.ts +130 -0
- package/src/plugin/ControlBar/ProgressBar.ts +175 -0
- package/src/plugin/ControlBar/RangeControl.ts +165 -0
- package/src/plugin/ControlBar/VRButton.ts +78 -0
- package/src/plugin/ControlBar/VideoControl.ts +79 -0
- package/src/plugin/ControlBar/VideoTime.ts +120 -0
- package/src/plugin/ControlBar/VolumeControl.ts +220 -0
- package/src/plugin/ControlBar/const.ts +72 -0
- package/src/plugin/ControlBar/index.ts +31 -0
- package/src/plugin/LoadingSpinner/LoadingSpinner.ts +116 -0
- package/src/plugin/View360Plugin.ts +30 -0
- package/src/plugin/index.ts +16 -0
- package/src/projection/CorrectionPass.ts +161 -0
- package/src/projection/CubemapProjection.ts +92 -0
- package/src/projection/CubestripProjection.ts +85 -0
- package/src/projection/CylindricalProjection.ts +123 -0
- package/src/projection/EquiangularProjection.ts +52 -0
- package/src/projection/EquirectProjection.ts +56 -0
- package/src/projection/LittlePlanetProjection.ts +82 -0
- package/src/projection/Projection.ts +103 -0
- package/src/projection/StereoEquiProjection.ts +104 -0
- package/src/projection/WideAngleCorrectionProjection.ts +307 -0
- package/src/projection/WideAngleRealtimeProjection.ts +653 -0
- package/src/projection/index.ts +36 -0
- package/src/shader/common.frag +7 -0
- package/src/shader/common.vert +12 -0
- package/src/shader/correction.frag +110 -0
- package/src/shader/cube.frag +8 -0
- package/src/shader/cube.vert +12 -0
- package/src/shader/eac.frag +40 -0
- package/src/shader/fullscreen.vert +7 -0
- package/src/shader/little-planet.frag +47 -0
- package/src/shader/little-planet.vert +12 -0
- package/src/shader/stereoequi.vert +15 -0
- package/src/shader/wideangle_realtime.frag +109 -0
- package/src/shader/wideangle_realtime.vert +17 -0
- package/src/shim.d.ts +9 -0
- package/src/texture/Texture.ts +47 -0
- package/src/texture/Texture2D.ts +34 -0
- package/src/texture/TextureCube.ts +36 -0
- package/src/texture/TextureRenderTarget.ts +33 -0
- package/src/texture/TextureVideo.ts +56 -0
- package/src/type/events.ts +389 -0
- package/src/type/external.ts +78 -0
- package/src/type/internal.ts +54 -0
- package/src/type/utils.ts +27 -0
- package/src/types/hls.d.ts +78 -0
- package/src/uniform/Uniform.ts +20 -0
- package/src/uniform/UniformBoolean.ts +23 -0
- package/src/uniform/UniformCanvasCube.ts +44 -0
- package/src/uniform/UniformFloat.ts +23 -0
- package/src/uniform/UniformInt.ts +25 -0
- package/src/uniform/UniformMatrix.ts +24 -0
- package/src/uniform/UniformTexture2D.ts +46 -0
- package/src/uniform/UniformTextureCube.ts +51 -0
- package/src/uniform/UniformTextureRenderTarget.ts +55 -0
- package/src/uniform/UniformVec2.ts +25 -0
- package/src/uniform/UniformVec3.ts +25 -0
- package/src/uniform/UniformVector4Array.ts +23 -0
- package/src/utils.ts +217 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-present NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import Component from "@egjs/component";
|
|
6
|
+
import * as BROWSER from "../../const/browser";
|
|
7
|
+
import { CONTROL_EVENTS } from "../../const/internal";
|
|
8
|
+
import { InputEvents } from "../../type/internal";
|
|
9
|
+
|
|
10
|
+
class PointerInput extends Component<InputEvents<{ x: number, y: number }, PointerEvent>> {
|
|
11
|
+
private _el: HTMLElement | null;
|
|
12
|
+
private _prevPos: [number, number];
|
|
13
|
+
|
|
14
|
+
public constructor() {
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
this._el = null;
|
|
18
|
+
this._prevPos = [0, 0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public enable(element: HTMLElement) {
|
|
22
|
+
if (this._el) return;
|
|
23
|
+
|
|
24
|
+
element.addEventListener(BROWSER.EVENTS.POINTER_DOWN, this._onPointerDown);
|
|
25
|
+
element.addEventListener(BROWSER.EVENTS.POINTER_CANCEL, this._onPointerCancel);
|
|
26
|
+
|
|
27
|
+
this._el = element;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public disable() {
|
|
31
|
+
const el = this._el;
|
|
32
|
+
if (!el) return;
|
|
33
|
+
|
|
34
|
+
el.removeEventListener(BROWSER.EVENTS.POINTER_DOWN, this._onPointerDown);
|
|
35
|
+
this._clearSubevents(el);
|
|
36
|
+
|
|
37
|
+
this._el = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private _clearSubevents(el: HTMLElement) {
|
|
41
|
+
el.removeEventListener(BROWSER.EVENTS.POINTER_MOVE, this._onPointerMove);
|
|
42
|
+
el.removeEventListener(BROWSER.EVENTS.POINTER_UP, this._onPointerUp);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private _onPointerDown = (evt: PointerEvent) => {
|
|
46
|
+
const el = this._el;
|
|
47
|
+
|
|
48
|
+
if (!el || !evt.isPrimary) return;
|
|
49
|
+
|
|
50
|
+
if (el.focus) {
|
|
51
|
+
el.focus();
|
|
52
|
+
} else {
|
|
53
|
+
window.focus();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this._prevPos[0] = evt.clientX;
|
|
57
|
+
this._prevPos[1] = evt.clientY;
|
|
58
|
+
|
|
59
|
+
el.setPointerCapture(evt.pointerId);
|
|
60
|
+
el.addEventListener(BROWSER.EVENTS.POINTER_MOVE, this._onPointerMove);
|
|
61
|
+
el.addEventListener(BROWSER.EVENTS.POINTER_UP, this._onPointerUp);
|
|
62
|
+
|
|
63
|
+
this.trigger(CONTROL_EVENTS.INPUT_START, {
|
|
64
|
+
srcEvent: evt,
|
|
65
|
+
isTouch: false,
|
|
66
|
+
isKeyboard: false
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
private _onPointerMove = (evt: PointerEvent) => {
|
|
71
|
+
if (!evt.isPrimary) return;
|
|
72
|
+
|
|
73
|
+
evt.preventDefault();
|
|
74
|
+
|
|
75
|
+
const x = evt.clientX;
|
|
76
|
+
const y = evt.clientY;
|
|
77
|
+
const prevPos = this._prevPos;
|
|
78
|
+
const deltaX = x - prevPos[0];
|
|
79
|
+
const deltaY = y - prevPos[1];
|
|
80
|
+
|
|
81
|
+
this.trigger(CONTROL_EVENTS.CHANGE, {
|
|
82
|
+
delta: {
|
|
83
|
+
x: deltaX,
|
|
84
|
+
y: deltaY
|
|
85
|
+
},
|
|
86
|
+
isTouch: false,
|
|
87
|
+
isKeyboard: false
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
prevPos[0] = x;
|
|
91
|
+
prevPos[1] = y;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
private _onPointerUp = (evt: PointerEvent) => {
|
|
95
|
+
const el = this._el;
|
|
96
|
+
if (!el || !evt.isPrimary) return;
|
|
97
|
+
|
|
98
|
+
this._prevPos[0] = 0;
|
|
99
|
+
this._prevPos[1] = 0;
|
|
100
|
+
|
|
101
|
+
this._clearSubevents(el);
|
|
102
|
+
|
|
103
|
+
this.trigger(CONTROL_EVENTS.INPUT_END, {
|
|
104
|
+
isTouch: false,
|
|
105
|
+
isKeyboard: false,
|
|
106
|
+
scrolling: false
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
private _onPointerCancel = (evt: PointerEvent) => {
|
|
111
|
+
const el = this._el;
|
|
112
|
+
if (!el || !evt.isPrimary) return;
|
|
113
|
+
|
|
114
|
+
this._clearSubevents(el);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default PointerInput;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-present NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import Component from "@egjs/component";
|
|
6
|
+
import * as BROWSER from "../../const/browser";
|
|
7
|
+
import { CONTROL_EVENTS } from "../../const/internal";
|
|
8
|
+
import { InputEvents } from "../../type/internal";
|
|
9
|
+
import { isFullscreen } from "../../utils";
|
|
10
|
+
|
|
11
|
+
class TouchInput extends Component<InputEvents<{ x: number, y: number }, TouchEvent>> {
|
|
12
|
+
private _el: HTMLElement | null;
|
|
13
|
+
private _prevPos: [number, number];
|
|
14
|
+
private _isFirstTouch: boolean;
|
|
15
|
+
private _scrolling: boolean;
|
|
16
|
+
private _scrollable: boolean;
|
|
17
|
+
|
|
18
|
+
public get scrollable() { return this._scrollable; }
|
|
19
|
+
public set scrollable(val: boolean) { this._scrollable = val; }
|
|
20
|
+
|
|
21
|
+
public constructor() {
|
|
22
|
+
super();
|
|
23
|
+
|
|
24
|
+
this._el = null;
|
|
25
|
+
this._prevPos = [0, 0];
|
|
26
|
+
this._isFirstTouch = false;
|
|
27
|
+
this._scrolling = false;
|
|
28
|
+
this._scrollable = false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public enable(element: HTMLElement) {
|
|
32
|
+
if (this._el) return;
|
|
33
|
+
|
|
34
|
+
element.addEventListener(BROWSER.EVENTS.TOUCH_START, this._onTouchStart, { passive: false });
|
|
35
|
+
element.addEventListener(BROWSER.EVENTS.TOUCH_MOVE, this._onTouchMove, { passive: false });
|
|
36
|
+
element.addEventListener(BROWSER.EVENTS.TOUCH_END, this._onTouchEnd);
|
|
37
|
+
|
|
38
|
+
this._el = element;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public disable() {
|
|
42
|
+
const element = this._el;
|
|
43
|
+
if (!element) return;
|
|
44
|
+
|
|
45
|
+
element.removeEventListener(BROWSER.EVENTS.TOUCH_START, this._onTouchStart);
|
|
46
|
+
element.removeEventListener(BROWSER.EVENTS.TOUCH_MOVE, this._onTouchMove);
|
|
47
|
+
element.removeEventListener(BROWSER.EVENTS.TOUCH_END, this._onTouchEnd);
|
|
48
|
+
|
|
49
|
+
this._el = null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private _onTouchStart = (evt: TouchEvent) => {
|
|
53
|
+
if (evt.touches.length > 1 || this._scrolling) return;
|
|
54
|
+
|
|
55
|
+
const touch = evt.touches[0];
|
|
56
|
+
|
|
57
|
+
this._isFirstTouch = true;
|
|
58
|
+
this._prevPos[0] = touch.clientX;
|
|
59
|
+
this._prevPos[1] = touch.clientY;
|
|
60
|
+
|
|
61
|
+
this.trigger(CONTROL_EVENTS.INPUT_START, {
|
|
62
|
+
srcEvent: evt,
|
|
63
|
+
isTouch: true,
|
|
64
|
+
isKeyboard: false
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
private _onTouchMove = (evt: TouchEvent) => {
|
|
69
|
+
// Only the one finger motion should be considered
|
|
70
|
+
if (evt.touches.length > 1 || this._scrolling) return;
|
|
71
|
+
|
|
72
|
+
const touch = evt.touches[0];
|
|
73
|
+
const scrollable = this._scrollable;
|
|
74
|
+
const prevPos = this._prevPos;
|
|
75
|
+
|
|
76
|
+
const x = touch.clientX;
|
|
77
|
+
const y = touch.clientY;
|
|
78
|
+
const deltaX = x - prevPos[0];
|
|
79
|
+
const deltaY = y - prevPos[1];
|
|
80
|
+
|
|
81
|
+
if (this._isFirstTouch) {
|
|
82
|
+
if (scrollable && !isFullscreen()) {
|
|
83
|
+
if (Math.abs(deltaY) > Math.abs(deltaX)) {
|
|
84
|
+
// Assume Scrolling
|
|
85
|
+
this._scrolling = true;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this._isFirstTouch = false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (evt.cancelable !== false) {
|
|
94
|
+
evt.preventDefault();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.trigger(CONTROL_EVENTS.CHANGE, {
|
|
98
|
+
delta: {
|
|
99
|
+
x: deltaX,
|
|
100
|
+
y: deltaY
|
|
101
|
+
},
|
|
102
|
+
isTouch: true,
|
|
103
|
+
isKeyboard: false
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
prevPos[0] = x;
|
|
107
|
+
prevPos[1] = y;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
private _onTouchEnd = (evt: TouchEvent) => {
|
|
111
|
+
if (evt.touches.length !== 0) return;
|
|
112
|
+
|
|
113
|
+
const touch = evt.touches[0];
|
|
114
|
+
const prevPos = this._prevPos;
|
|
115
|
+
|
|
116
|
+
if (touch) {
|
|
117
|
+
prevPos[0] = touch.clientX;
|
|
118
|
+
prevPos[1] = touch.clientY;
|
|
119
|
+
} else {
|
|
120
|
+
prevPos[0] = 0;
|
|
121
|
+
prevPos[1] = 0;
|
|
122
|
+
|
|
123
|
+
this.trigger(CONTROL_EVENTS.INPUT_END, {
|
|
124
|
+
isTouch: true,
|
|
125
|
+
isKeyboard: false,
|
|
126
|
+
scrolling: this._scrolling
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (evt.cancelable !== false) {
|
|
131
|
+
evt.preventDefault();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this._scrolling = false;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default TouchInput;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-present NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import Component from "@egjs/component";
|
|
6
|
+
import * as BROWSER from "../../const/browser";
|
|
7
|
+
import { CONTROL_EVENTS, DEFAULT_ANIMATION_DURATION } from "../../const/internal";
|
|
8
|
+
import { InputEvents } from "../../type/internal";
|
|
9
|
+
|
|
10
|
+
class WheelInput extends Component<InputEvents<number, WheelEvent>> {
|
|
11
|
+
private _el: HTMLElement | null;
|
|
12
|
+
private _scrollable: boolean;
|
|
13
|
+
private _baseScale: number;
|
|
14
|
+
private _inputTimer: number;
|
|
15
|
+
|
|
16
|
+
public get scrollable() { return this._scrollable; }
|
|
17
|
+
public set scrollable(val: boolean) { this._scrollable = val; }
|
|
18
|
+
|
|
19
|
+
public constructor() {
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
this._el = null;
|
|
23
|
+
this._baseScale = 0.04;
|
|
24
|
+
this._scrollable = false;
|
|
25
|
+
this._inputTimer = -1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public enable(element: HTMLElement) {
|
|
29
|
+
if (this._el) return;
|
|
30
|
+
|
|
31
|
+
element.addEventListener(BROWSER.EVENTS.WHEEL, this._onWheel, { passive: false, capture: false });
|
|
32
|
+
|
|
33
|
+
this._el = element;
|
|
34
|
+
this._clearTimer();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public disable() {
|
|
38
|
+
const element = this._el;
|
|
39
|
+
if (!element) return;
|
|
40
|
+
|
|
41
|
+
element.removeEventListener(BROWSER.EVENTS.WHEEL, this._onWheel, false);
|
|
42
|
+
|
|
43
|
+
this._el = null;
|
|
44
|
+
this._clearTimer();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private _onWheel = (evt: WheelEvent) => {
|
|
48
|
+
const scrollable = this._scrollable;
|
|
49
|
+
|
|
50
|
+
if (evt.deltaY === 0 || scrollable) return;
|
|
51
|
+
|
|
52
|
+
evt.preventDefault();
|
|
53
|
+
evt.stopPropagation();
|
|
54
|
+
|
|
55
|
+
if (this._inputTimer < 0) {
|
|
56
|
+
this.trigger(CONTROL_EVENTS.INPUT_START, {
|
|
57
|
+
srcEvent: evt,
|
|
58
|
+
isTouch: false,
|
|
59
|
+
isKeyboard: false
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
this._clearTimer();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const delta = this._baseScale * evt.deltaY;
|
|
66
|
+
|
|
67
|
+
this.trigger(CONTROL_EVENTS.CHANGE, {
|
|
68
|
+
delta,
|
|
69
|
+
isTouch: false,
|
|
70
|
+
isKeyboard: false
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
this._inputTimer = window.setTimeout(() => {
|
|
74
|
+
this.trigger(CONTROL_EVENTS.INPUT_END, {
|
|
75
|
+
isTouch: false,
|
|
76
|
+
isKeyboard: false,
|
|
77
|
+
scrolling: false
|
|
78
|
+
});
|
|
79
|
+
this._inputTimer = -1;
|
|
80
|
+
}, DEFAULT_ANIMATION_DURATION);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
private _clearTimer() {
|
|
84
|
+
window.clearTimeout(this._inputTimer);
|
|
85
|
+
this._inputTimer = -1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default WheelInput;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-present NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import * as BROWSER from "../const/browser";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Automatic resizer that uses both ResizeObserver and window resize event
|
|
9
|
+
*/
|
|
10
|
+
class AutoResizer {
|
|
11
|
+
private _enabled: boolean;
|
|
12
|
+
private _resizeObserver: ResizeObserver | null;
|
|
13
|
+
private _useResizeObserver: boolean;
|
|
14
|
+
private _onResize: () => any;
|
|
15
|
+
|
|
16
|
+
public get useResizeObserver() { return this._useResizeObserver; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns whether AutoResizer is enabled
|
|
20
|
+
*/
|
|
21
|
+
public get enabled() { return this._enabled; }
|
|
22
|
+
|
|
23
|
+
/** */
|
|
24
|
+
public constructor(useResizeObserver: boolean, onResize: () => any) {
|
|
25
|
+
this._useResizeObserver = useResizeObserver;
|
|
26
|
+
|
|
27
|
+
this._enabled = false;
|
|
28
|
+
this._resizeObserver = null;
|
|
29
|
+
this._onResize = onResize;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Enable resizer
|
|
34
|
+
*/
|
|
35
|
+
public enable(element: HTMLElement): this {
|
|
36
|
+
if (this._enabled) {
|
|
37
|
+
this.disable();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (this._useResizeObserver && !!window.ResizeObserver) {
|
|
41
|
+
const bbox = element.getBoundingClientRect();
|
|
42
|
+
const resizeImmediate = bbox.width !== 0 || bbox.height !== 0;
|
|
43
|
+
|
|
44
|
+
const resizeObserver = new ResizeObserver(resizeImmediate ? this._skipFirstResize : this._onResize);
|
|
45
|
+
|
|
46
|
+
resizeObserver.observe(element);
|
|
47
|
+
|
|
48
|
+
this._resizeObserver = resizeObserver;
|
|
49
|
+
} else {
|
|
50
|
+
window.addEventListener(BROWSER.EVENTS.RESIZE, this._onResize);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this._enabled = true;
|
|
54
|
+
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Disable resizer
|
|
60
|
+
*/
|
|
61
|
+
public disable(): this {
|
|
62
|
+
if (!this._enabled) return this;
|
|
63
|
+
|
|
64
|
+
const resizeObserver = this._resizeObserver;
|
|
65
|
+
if (resizeObserver) {
|
|
66
|
+
resizeObserver.disconnect();
|
|
67
|
+
this._resizeObserver = null;
|
|
68
|
+
} else {
|
|
69
|
+
window.removeEventListener(BROWSER.EVENTS.RESIZE, this._onResize);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this._enabled = false;
|
|
73
|
+
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
78
|
+
private _skipFirstResize = (() => {
|
|
79
|
+
let isFirstResize = true;
|
|
80
|
+
|
|
81
|
+
return (() => {
|
|
82
|
+
if (isFirstResize) {
|
|
83
|
+
isFirstResize = false;
|
|
84
|
+
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this._onResize();
|
|
88
|
+
});
|
|
89
|
+
})();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default AutoResizer;
|