@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.
Files changed (261) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +88 -0
  3. package/css/base.css +19 -0
  4. package/css/base.min.css +1 -0
  5. package/css/control-bar.css +329 -0
  6. package/css/control-bar.min.css +1 -0
  7. package/css/helper.css +51 -0
  8. package/css/helper.min.css +1 -0
  9. package/css/hotspot.css +21 -0
  10. package/css/hotspot.min.css +1 -0
  11. package/css/loading-spinner.css +37 -0
  12. package/css/loading-spinner.min.css +1 -0
  13. package/css/variable.css +1 -0
  14. package/css/variable.min.css +0 -0
  15. package/css/view360.css +468 -0
  16. package/css/view360.min.css +1 -0
  17. package/css/vr.css +8 -0
  18. package/css/vr.min.css +1 -0
  19. package/declaration/View360.d.ts +150 -0
  20. package/declaration/cfc/const.d.ts +1 -0
  21. package/declaration/cfc/index.d.ts +4 -0
  22. package/declaration/cfc/utils.d.ts +1 -0
  23. package/declaration/cfc/withMethods.d.ts +2 -0
  24. package/declaration/const/browser.d.ts +71 -0
  25. package/declaration/const/error.d.ts +47 -0
  26. package/declaration/const/external.d.ts +33 -0
  27. package/declaration/const/internal.d.ts +34 -0
  28. package/declaration/control/CameraControl.d.ts +10 -0
  29. package/declaration/control/GyroControl.d.ts +30 -0
  30. package/declaration/control/PanoControl.d.ts +58 -0
  31. package/declaration/control/RotateControl.d.ts +75 -0
  32. package/declaration/control/ZoomControl.d.ts +45 -0
  33. package/declaration/control/index.d.ts +7 -0
  34. package/declaration/control/input/GyroInput.d.ts +46 -0
  35. package/declaration/control/input/KeyboardInput.d.ts +21 -0
  36. package/declaration/control/input/MouseInput.d.ts +16 -0
  37. package/declaration/control/input/PinchInput.d.ts +14 -0
  38. package/declaration/control/input/PointerInput.d.ts +18 -0
  39. package/declaration/control/input/TouchInput.d.ts +21 -0
  40. package/declaration/control/input/WheelInput.d.ts +16 -0
  41. package/declaration/core/AutoResizer.d.ts +13 -0
  42. package/declaration/core/Autoplay.d.ts +54 -0
  43. package/declaration/core/Camera.d.ts +88 -0
  44. package/declaration/core/CameraAnimation.d.ts +25 -0
  45. package/declaration/core/CameraPath.d.ts +55 -0
  46. package/declaration/core/CubeTexturePainter.d.ts +16 -0
  47. package/declaration/core/FrameAnimator.d.ts +13 -0
  48. package/declaration/core/Motion.d.ts +39 -0
  49. package/declaration/core/Object3D.d.ts +21 -0
  50. package/declaration/core/ShaderProgram.d.ts +10 -0
  51. package/declaration/core/TextureLoader.d.ts +26 -0
  52. package/declaration/core/TriangleMesh.d.ts +20 -0
  53. package/declaration/core/VertexArrayObject.d.ts +14 -0
  54. package/declaration/core/VertexData.d.ts +8 -0
  55. package/declaration/core/View360Error.d.ts +5 -0
  56. package/declaration/core/WebGLContext.d.ts +74 -0
  57. package/declaration/core/WebGLRenderer.d.ts +26 -0
  58. package/declaration/core/XRManager.d.ts +33 -0
  59. package/declaration/core/index.d.ts +12 -0
  60. package/declaration/geometry/CubeGeometry.d.ts +9 -0
  61. package/declaration/geometry/CylinderGeometry.d.ts +5 -0
  62. package/declaration/geometry/Geometry.d.ts +8 -0
  63. package/declaration/geometry/PlaneGeometry.d.ts +5 -0
  64. package/declaration/geometry/SphereGeometry.d.ts +5 -0
  65. package/declaration/hotspot/Hotspot.d.ts +7 -0
  66. package/declaration/hotspot/HotspotRenderer.d.ts +17 -0
  67. package/declaration/hotspot/index.d.ts +4 -0
  68. package/declaration/index.cjs.d.ts +3 -0
  69. package/declaration/index.d.ts +11 -0
  70. package/declaration/index.umd.d.ts +2 -0
  71. package/declaration/plugin/ControlBar/AutoHide.d.ts +42 -0
  72. package/declaration/plugin/ControlBar/ControlBar.d.ts +113 -0
  73. package/declaration/plugin/ControlBar/ControlBarItem.d.ts +15 -0
  74. package/declaration/plugin/ControlBar/FullscreenButton.d.ts +19 -0
  75. package/declaration/plugin/ControlBar/GyroButton.d.ts +14 -0
  76. package/declaration/plugin/ControlBar/PieView.d.ts +26 -0
  77. package/declaration/plugin/ControlBar/PlayButton.d.ts +16 -0
  78. package/declaration/plugin/ControlBar/ProgressBar.d.ts +23 -0
  79. package/declaration/plugin/ControlBar/RangeControl.d.ts +27 -0
  80. package/declaration/plugin/ControlBar/VRButton.d.ts +12 -0
  81. package/declaration/plugin/ControlBar/VideoControl.d.ts +11 -0
  82. package/declaration/plugin/ControlBar/VideoTime.d.ts +17 -0
  83. package/declaration/plugin/ControlBar/VolumeControl.d.ts +23 -0
  84. package/declaration/plugin/ControlBar/const.d.ts +41 -0
  85. package/declaration/plugin/ControlBar/index.d.ts +11 -0
  86. package/declaration/plugin/LoadingSpinner/LoadingSpinner.d.ts +22 -0
  87. package/declaration/plugin/View360Plugin.d.ts +6 -0
  88. package/declaration/plugin/index.d.ts +5 -0
  89. package/declaration/projection/CorrectionPass.d.ts +26 -0
  90. package/declaration/projection/CubemapProjection.d.ts +19 -0
  91. package/declaration/projection/CubestripProjection.d.ts +18 -0
  92. package/declaration/projection/CylindricalProjection.d.ts +22 -0
  93. package/declaration/projection/EquiangularProjection.d.ts +13 -0
  94. package/declaration/projection/EquirectProjection.d.ts +15 -0
  95. package/declaration/projection/LittlePlanetProjection.d.ts +21 -0
  96. package/declaration/projection/Projection.d.ts +19 -0
  97. package/declaration/projection/StereoEquiProjection.d.ts +25 -0
  98. package/declaration/projection/WideAngleCorrectionProjection.d.ts +27 -0
  99. package/declaration/projection/WideAngleRealtimeProjection.d.ts +50 -0
  100. package/declaration/projection/index.d.ts +12 -0
  101. package/declaration/texture/Texture.d.ts +18 -0
  102. package/declaration/texture/Texture2D.d.ts +11 -0
  103. package/declaration/texture/TextureCube.d.ts +12 -0
  104. package/declaration/texture/TextureRenderTarget.d.ts +8 -0
  105. package/declaration/texture/TextureVideo.d.ts +11 -0
  106. package/declaration/type/events.d.ts +74 -0
  107. package/declaration/type/external.d.ts +13 -0
  108. package/declaration/type/internal.d.ts +47 -0
  109. package/declaration/type/utils.d.ts +11 -0
  110. package/declaration/uniform/Uniform.d.ts +7 -0
  111. package/declaration/uniform/UniformBoolean.d.ts +7 -0
  112. package/declaration/uniform/UniformCanvasCube.d.ts +12 -0
  113. package/declaration/uniform/UniformFloat.d.ts +7 -0
  114. package/declaration/uniform/UniformInt.d.ts +7 -0
  115. package/declaration/uniform/UniformMatrix.d.ts +8 -0
  116. package/declaration/uniform/UniformTexture2D.d.ts +11 -0
  117. package/declaration/uniform/UniformTextureCube.d.ts +12 -0
  118. package/declaration/uniform/UniformTextureRenderTarget.d.ts +11 -0
  119. package/declaration/uniform/UniformVec2.d.ts +7 -0
  120. package/declaration/uniform/UniformVec3.d.ts +7 -0
  121. package/declaration/uniform/UniformVector4Array.d.ts +7 -0
  122. package/declaration/utils.d.ts +25 -0
  123. package/dist/view360.cjs.js +9392 -0
  124. package/dist/view360.cjs.js.map +1 -0
  125. package/dist/view360.esm.js +9274 -0
  126. package/dist/view360.esm.js.map +1 -0
  127. package/dist/view360.js +9350 -0
  128. package/dist/view360.js.map +1 -0
  129. package/dist/view360.min.js +2 -0
  130. package/dist/view360.min.js.map +1 -0
  131. package/dist/view360.pkgd.js +48537 -0
  132. package/dist/view360.pkgd.js.map +1 -0
  133. package/dist/view360.pkgd.min.js +16 -0
  134. package/dist/view360.pkgd.min.js.map +1 -0
  135. package/package.json +110 -0
  136. package/sass/base.sass +17 -0
  137. package/sass/control-bar.sass +284 -0
  138. package/sass/helper.sass +51 -0
  139. package/sass/hotspot.sass +20 -0
  140. package/sass/loading-spinner.sass +34 -0
  141. package/sass/variable.sass +2 -0
  142. package/sass/view360.sass +6 -0
  143. package/sass/vr.sass +10 -0
  144. package/src/View360.ts +1220 -0
  145. package/src/cfc/const.ts +15 -0
  146. package/src/cfc/index.ts +8 -0
  147. package/src/cfc/utils.ts +12 -0
  148. package/src/cfc/withMethods.ts +40 -0
  149. package/src/const/browser.ts +109 -0
  150. package/src/const/error.ts +83 -0
  151. package/src/const/external.ts +77 -0
  152. package/src/const/internal.ts +53 -0
  153. package/src/control/CameraControl.ts +53 -0
  154. package/src/control/GyroControl.ts +225 -0
  155. package/src/control/PanoControl.ts +434 -0
  156. package/src/control/RotateControl.ts +411 -0
  157. package/src/control/ZoomControl.ts +254 -0
  158. package/src/control/index.ts +24 -0
  159. package/src/control/input/GyroInput.ts +315 -0
  160. package/src/control/input/KeyboardInput.ts +151 -0
  161. package/src/control/input/MouseInput.ts +102 -0
  162. package/src/control/input/PinchInput.ts +101 -0
  163. package/src/control/input/PointerInput.ts +118 -0
  164. package/src/control/input/TouchInput.ts +138 -0
  165. package/src/control/input/WheelInput.ts +89 -0
  166. package/src/core/AutoResizer.ts +92 -0
  167. package/src/core/Autoplay.ts +326 -0
  168. package/src/core/Camera.ts +616 -0
  169. package/src/core/CameraAnimation.ts +110 -0
  170. package/src/core/CameraPath.ts +454 -0
  171. package/src/core/CubeTexturePainter.ts +95 -0
  172. package/src/core/FrameAnimator.ts +69 -0
  173. package/src/core/Motion.ts +205 -0
  174. package/src/core/Object3D.ts +81 -0
  175. package/src/core/ShaderProgram.ts +21 -0
  176. package/src/core/TextureLoader.ts +303 -0
  177. package/src/core/TriangleMesh.ts +54 -0
  178. package/src/core/VertexArrayObject.ts +29 -0
  179. package/src/core/VertexData.ts +23 -0
  180. package/src/core/View360Error.ts +35 -0
  181. package/src/core/WebGLContext.ts +558 -0
  182. package/src/core/WebGLRenderer.ts +205 -0
  183. package/src/core/XRManager.ts +193 -0
  184. package/src/core/index.ts +35 -0
  185. package/src/geometry/CubeGeometry.ts +121 -0
  186. package/src/geometry/CylinderGeometry.ts +49 -0
  187. package/src/geometry/Geometry.ts +23 -0
  188. package/src/geometry/PlaneGeometry.ts +36 -0
  189. package/src/geometry/SphereGeometry.ts +55 -0
  190. package/src/hotspot/Hotspot.ts +32 -0
  191. package/src/hotspot/HotspotRenderer.ts +155 -0
  192. package/src/hotspot/index.ts +11 -0
  193. package/src/index.cjs.ts +13 -0
  194. package/src/index.ts +21 -0
  195. package/src/index.umd.ts +10 -0
  196. package/src/plugin/ControlBar/AutoHide.ts +246 -0
  197. package/src/plugin/ControlBar/ControlBar.ts +564 -0
  198. package/src/plugin/ControlBar/ControlBarItem.ts +84 -0
  199. package/src/plugin/ControlBar/FullscreenButton.ts +145 -0
  200. package/src/plugin/ControlBar/GyroButton.ts +124 -0
  201. package/src/plugin/ControlBar/PieView.ts +195 -0
  202. package/src/plugin/ControlBar/PlayButton.ts +130 -0
  203. package/src/plugin/ControlBar/ProgressBar.ts +175 -0
  204. package/src/plugin/ControlBar/RangeControl.ts +165 -0
  205. package/src/plugin/ControlBar/VRButton.ts +78 -0
  206. package/src/plugin/ControlBar/VideoControl.ts +79 -0
  207. package/src/plugin/ControlBar/VideoTime.ts +120 -0
  208. package/src/plugin/ControlBar/VolumeControl.ts +220 -0
  209. package/src/plugin/ControlBar/const.ts +72 -0
  210. package/src/plugin/ControlBar/index.ts +31 -0
  211. package/src/plugin/LoadingSpinner/LoadingSpinner.ts +116 -0
  212. package/src/plugin/View360Plugin.ts +30 -0
  213. package/src/plugin/index.ts +16 -0
  214. package/src/projection/CorrectionPass.ts +161 -0
  215. package/src/projection/CubemapProjection.ts +92 -0
  216. package/src/projection/CubestripProjection.ts +85 -0
  217. package/src/projection/CylindricalProjection.ts +123 -0
  218. package/src/projection/EquiangularProjection.ts +52 -0
  219. package/src/projection/EquirectProjection.ts +56 -0
  220. package/src/projection/LittlePlanetProjection.ts +82 -0
  221. package/src/projection/Projection.ts +103 -0
  222. package/src/projection/StereoEquiProjection.ts +104 -0
  223. package/src/projection/WideAngleCorrectionProjection.ts +307 -0
  224. package/src/projection/WideAngleRealtimeProjection.ts +653 -0
  225. package/src/projection/index.ts +36 -0
  226. package/src/shader/common.frag +7 -0
  227. package/src/shader/common.vert +12 -0
  228. package/src/shader/correction.frag +110 -0
  229. package/src/shader/cube.frag +8 -0
  230. package/src/shader/cube.vert +12 -0
  231. package/src/shader/eac.frag +40 -0
  232. package/src/shader/fullscreen.vert +7 -0
  233. package/src/shader/little-planet.frag +47 -0
  234. package/src/shader/little-planet.vert +12 -0
  235. package/src/shader/stereoequi.vert +15 -0
  236. package/src/shader/wideangle_realtime.frag +109 -0
  237. package/src/shader/wideangle_realtime.vert +17 -0
  238. package/src/shim.d.ts +9 -0
  239. package/src/texture/Texture.ts +47 -0
  240. package/src/texture/Texture2D.ts +34 -0
  241. package/src/texture/TextureCube.ts +36 -0
  242. package/src/texture/TextureRenderTarget.ts +33 -0
  243. package/src/texture/TextureVideo.ts +56 -0
  244. package/src/type/events.ts +389 -0
  245. package/src/type/external.ts +78 -0
  246. package/src/type/internal.ts +54 -0
  247. package/src/type/utils.ts +27 -0
  248. package/src/types/hls.d.ts +78 -0
  249. package/src/uniform/Uniform.ts +20 -0
  250. package/src/uniform/UniformBoolean.ts +23 -0
  251. package/src/uniform/UniformCanvasCube.ts +44 -0
  252. package/src/uniform/UniformFloat.ts +23 -0
  253. package/src/uniform/UniformInt.ts +25 -0
  254. package/src/uniform/UniformMatrix.ts +24 -0
  255. package/src/uniform/UniformTexture2D.ts +46 -0
  256. package/src/uniform/UniformTextureCube.ts +51 -0
  257. package/src/uniform/UniformTextureRenderTarget.ts +55 -0
  258. package/src/uniform/UniformVec2.ts +25 -0
  259. package/src/uniform/UniformVec3.ts +25 -0
  260. package/src/uniform/UniformVector4Array.ts +23 -0
  261. 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;