vevet 1.4.27 → 2.0.1-dev.3
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 +1 -1
- package/README.md +7 -71
- package/build/cdn/index.js +12 -0
- package/build/cdn/index.js.LICENSE.txt +14 -0
- package/build/cjs/app/Application.js +297 -0
- package/build/cjs/app/events/PageLoad.js +74 -0
- package/build/cjs/app/events/Viewport.js +303 -0
- package/build/cjs/base/Callbacks.js +232 -0
- package/build/cjs/base/Component.js +56 -0
- package/build/cjs/base/Module.js +262 -0
- package/build/cjs/base/MutableProp.js +165 -0
- package/build/cjs/base/Plugin.js +56 -0
- package/build/cjs/components/animation-frame/AnimationFrame.js +183 -0
- package/build/cjs/components/canvas/Ctx2D.js +200 -0
- package/build/cjs/components/canvas/Ctx2DPrerender.js +72 -0
- package/build/cjs/components/cursor/CustomCursor.js +344 -0
- package/build/cjs/components/dragger/Dragger.js +229 -0
- package/build/cjs/components/dragger/DraggerDirection.js +77 -0
- package/build/cjs/components/dragger/DraggerMove.js +84 -0
- package/build/cjs/components/loading/Preloader.js +229 -0
- package/build/cjs/components/loading/ProgressPreloader.js +377 -0
- package/build/cjs/components/page/Page.js +353 -0
- package/build/cjs/components/scroll/custom-scroll/CustomScroll.js +517 -0
- package/build/cjs/components/scroll/plugins/SmoothScrollDragPlugin.js +178 -0
- package/build/cjs/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +138 -0
- package/build/cjs/components/scroll/scrollable/ScrollEventsBase.js +133 -0
- package/build/cjs/components/scroll/scrollable/ScrollView.js +315 -0
- package/build/cjs/components/scroll/scrollbar/Bar.js +315 -0
- package/build/cjs/components/scroll/scrollbar/ScrollBar.js +206 -0
- package/build/cjs/components/scroll/smooth-scroll/SmoothScroll.js +625 -0
- package/build/cjs/components/scroll/types.js +2 -0
- package/build/cjs/components/split-text/SplitText.js +233 -0
- package/build/cjs/components/text/SplitText.js +329 -0
- package/build/cjs/components/timeline/StaticTimeline.js +137 -0
- package/build/cjs/components/timeline/Timeline.js +190 -0
- package/build/cjs/index.js +87 -0
- package/build/cjs/utils/common/index.js +12 -0
- package/build/cjs/utils/common/mergeWithoutArrays.js +19 -0
- package/build/cjs/utils/common/randID.js +11 -0
- package/build/cjs/utils/common/timeoutCallback.js +17 -0
- package/build/cjs/utils/errors.js +8 -0
- package/build/cjs/utils/listeners/index.js +10 -0
- package/build/cjs/utils/listeners/intersectionObserverSupported.js +11 -0
- package/build/cjs/utils/listeners/onScroll.js +47 -0
- package/build/cjs/utils/math/boundVal.js +16 -0
- package/build/cjs/utils/math/index.js +12 -0
- package/build/cjs/utils/math/lerp.js +15 -0
- package/build/cjs/utils/math/scopeProgress.js +25 -0
- package/build/cjs/utils/types/general.js +2 -0
- package/build/cjs/utils/types/utility.js +2 -0
- package/build/es/app/Application.js +210 -0
- package/build/es/app/events/PageLoad.js +47 -0
- package/build/es/app/events/Viewport.js +232 -0
- package/build/es/base/Callbacks.js +205 -0
- package/build/es/base/Component.js +32 -0
- package/build/es/base/Module.js +225 -0
- package/build/es/base/MutableProp.js +152 -0
- package/build/es/base/Plugin.js +31 -0
- package/build/es/components/animation-frame/AnimationFrame.js +145 -0
- package/build/es/components/canvas/Ctx2D.js +133 -0
- package/build/es/components/canvas/Ctx2DPrerender.js +37 -0
- package/build/es/components/cursor/CustomCursor.js +274 -0
- package/build/es/components/dragger/Dragger.js +175 -0
- package/build/es/components/dragger/DraggerDirection.js +42 -0
- package/build/es/components/dragger/DraggerMove.js +56 -0
- package/build/es/components/loading/Preloader.js +164 -0
- package/build/es/components/loading/ProgressPreloader.js +304 -0
- package/build/es/components/page/Page.js +283 -0
- package/build/es/components/scroll/custom-scroll/CustomScroll.js +486 -0
- package/build/es/components/scroll/plugins/SmoothScrollDragPlugin.js +140 -0
- package/build/es/components/scroll/plugins/SmoothScrollKeyboardPlugin.js +109 -0
- package/build/es/components/scroll/scrollable/ScrollEventsBase.js +79 -0
- package/build/es/components/scroll/scrollable/ScrollView.js +264 -0
- package/build/es/components/scroll/scrollbar/Bar.js +262 -0
- package/build/es/components/scroll/scrollbar/ScrollBar.js +152 -0
- package/build/es/components/scroll/smooth-scroll/SmoothScroll.js +519 -0
- package/build/es/components/scroll/types.js +1 -0
- package/build/es/components/split-text/SplitText.js +199 -0
- package/build/es/components/text/SplitText.js +270 -0
- package/build/es/components/timeline/StaticTimeline.js +92 -0
- package/build/es/components/timeline/Timeline.js +141 -0
- package/build/es/index.js +37 -0
- package/build/es/utils/common/index.js +4 -0
- package/build/es/utils/common/mergeWithoutArrays.js +13 -0
- package/build/es/utils/common/randID.js +7 -0
- package/build/es/utils/common/timeoutCallback.js +14 -0
- package/build/es/utils/errors.js +5 -0
- package/build/es/utils/listeners/index.js +3 -0
- package/build/es/utils/listeners/intersectionObserverSupported.js +8 -0
- package/build/es/utils/listeners/onScroll.js +44 -0
- package/build/es/utils/math/boundVal.js +12 -0
- package/build/es/utils/math/index.js +4 -0
- package/build/es/utils/math/lerp.js +11 -0
- package/build/es/utils/math/scopeProgress.js +22 -0
- package/build/es/utils/types/general.js +1 -0
- package/build/es/utils/types/utility.js +1 -0
- package/build/types/app/Application.d.ts +161 -0
- package/build/types/app/Application.d.ts.map +1 -0
- package/build/types/app/events/PageLoad.d.ts +28 -0
- package/build/types/app/events/PageLoad.d.ts.map +1 -0
- package/build/types/app/events/Viewport.d.ts +137 -0
- package/build/types/app/events/Viewport.d.ts.map +1 -0
- package/build/types/base/Callbacks.d.ts +174 -0
- package/build/types/base/Callbacks.d.ts.map +1 -0
- package/build/types/base/Component.d.ts +48 -0
- package/build/types/base/Component.d.ts.map +1 -0
- package/build/types/base/Module.d.ts +179 -0
- package/build/types/base/Module.d.ts.map +1 -0
- package/build/types/base/MutableProp.d.ts +142 -0
- package/build/types/base/MutableProp.d.ts.map +1 -0
- package/build/types/base/Plugin.d.ts +35 -0
- package/build/types/base/Plugin.d.ts.map +1 -0
- package/build/types/components/animation-frame/AnimationFrame.d.ts +96 -0
- package/build/types/components/animation-frame/AnimationFrame.d.ts.map +1 -0
- package/build/types/components/canvas/Ctx2D.d.ts +111 -0
- package/build/types/components/canvas/Ctx2D.d.ts.map +1 -0
- package/build/types/components/canvas/Ctx2DPrerender.d.ts +41 -0
- package/build/types/components/canvas/Ctx2DPrerender.d.ts.map +1 -0
- package/build/types/components/cursor/CustomCursor.d.ts +181 -0
- package/build/types/components/cursor/CustomCursor.d.ts.map +1 -0
- package/build/types/components/dragger/Dragger.d.ts +120 -0
- package/build/types/components/dragger/Dragger.d.ts.map +1 -0
- package/build/types/components/dragger/DraggerDirection.d.ts +39 -0
- package/build/types/components/dragger/DraggerDirection.d.ts.map +1 -0
- package/build/types/components/dragger/DraggerMove.d.ts +49 -0
- package/build/types/components/dragger/DraggerMove.d.ts.map +1 -0
- package/build/types/components/loading/Preloader.d.ts +107 -0
- package/build/types/components/loading/Preloader.d.ts.map +1 -0
- package/build/types/components/loading/ProgressPreloader.d.ts +166 -0
- package/build/types/components/loading/ProgressPreloader.d.ts.map +1 -0
- package/build/types/components/page/Page.d.ts +126 -0
- package/build/types/components/page/Page.d.ts.map +1 -0
- package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts +322 -0
- package/build/types/components/scroll/custom-scroll/CustomScroll.d.ts.map +1 -0
- package/build/types/components/scroll/plugins/SmoothScrollDragPlugin.d.ts +97 -0
- package/build/types/components/scroll/plugins/SmoothScrollDragPlugin.d.ts.map +1 -0
- package/build/types/components/scroll/plugins/SmoothScrollKeyboardPlugin.d.ts +34 -0
- package/build/types/components/scroll/plugins/SmoothScrollKeyboardPlugin.d.ts.map +1 -0
- package/build/types/components/scroll/scrollable/ScrollEventsBase.d.ts +60 -0
- package/build/types/components/scroll/scrollable/ScrollEventsBase.d.ts.map +1 -0
- package/build/types/components/scroll/scrollable/ScrollView.d.ts +140 -0
- package/build/types/components/scroll/scrollable/ScrollView.d.ts.map +1 -0
- package/build/types/components/scroll/scrollbar/Bar.d.ts +84 -0
- package/build/types/components/scroll/scrollbar/Bar.d.ts.map +1 -0
- package/build/types/components/scroll/scrollbar/ScrollBar.d.ts +109 -0
- package/build/types/components/scroll/scrollbar/ScrollBar.d.ts.map +1 -0
- package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts +307 -0
- package/build/types/components/scroll/smooth-scroll/SmoothScroll.d.ts.map +1 -0
- package/build/types/components/scroll/types.d.ts +11 -0
- package/build/types/components/scroll/types.d.ts.map +1 -0
- package/build/types/components/split-text/SplitText.d.ts +118 -0
- package/build/types/components/split-text/SplitText.d.ts.map +1 -0
- package/build/types/components/text/SplitText.d.ts +118 -0
- package/build/types/components/text/SplitText.d.ts.map +1 -0
- package/build/types/components/timeline/StaticTimeline.d.ts +92 -0
- package/build/types/components/timeline/StaticTimeline.d.ts.map +1 -0
- package/build/types/components/timeline/Timeline.d.ts +101 -0
- package/build/types/components/timeline/Timeline.d.ts.map +1 -0
- package/build/types/index.d.ts +38 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/utils/common/index.d.ts +5 -0
- package/build/types/utils/common/index.d.ts.map +1 -0
- package/build/types/utils/common/mergeWithoutArrays.d.ts +6 -0
- package/build/types/utils/common/mergeWithoutArrays.d.ts.map +1 -0
- package/build/types/utils/common/randID.d.ts +5 -0
- package/build/types/utils/common/randID.d.ts.map +1 -0
- package/build/types/utils/common/timeoutCallback.d.ts +6 -0
- package/build/types/utils/common/timeoutCallback.d.ts.map +1 -0
- package/build/types/utils/errors.d.ts +3 -0
- package/build/types/utils/errors.d.ts.map +1 -0
- package/build/types/utils/listeners/index.d.ts +4 -0
- package/build/types/utils/listeners/index.d.ts.map +1 -0
- package/build/types/utils/listeners/intersectionObserverSupported.d.ts +2 -0
- package/build/types/utils/listeners/intersectionObserverSupported.d.ts.map +1 -0
- package/build/types/utils/listeners/onScroll.d.ts +10 -0
- package/build/types/utils/listeners/onScroll.d.ts.map +1 -0
- package/build/types/utils/math/boundVal.d.ts +5 -0
- package/build/types/utils/math/boundVal.d.ts.map +1 -0
- package/build/types/utils/math/index.d.ts +5 -0
- package/build/types/utils/math/index.d.ts.map +1 -0
- package/build/types/utils/math/lerp.d.ts +5 -0
- package/build/types/utils/math/lerp.d.ts.map +1 -0
- package/build/types/utils/math/scopeProgress.d.ts +20 -0
- package/build/types/utils/math/scopeProgress.d.ts.map +1 -0
- package/build/types/utils/types/general.d.ts +7 -0
- package/build/types/utils/types/general.d.ts.map +1 -0
- package/build/types/utils/types/utility.d.ts +14 -0
- package/build/types/utils/types/utility.d.ts.map +1 -0
- package/package.json +88 -82
- package/src/cdn/index.js +3 -0
- package/src/sass/base.scss +3 -0
- package/src/sass/components/cursor/_custom-cursor.scss +63 -0
- package/src/sass/components/index.scss +6 -0
- package/src/sass/components/loading/_preloader.scss +15 -0
- package/src/sass/components/scroll/_scrollbar.scss +73 -0
- package/src/sass/components/scroll/_smooth-scroll.scss +17 -0
- package/src/sass/index.scss +3 -0
- package/src/sass/mixins/_scroll.scss +7 -0
- package/{dist/scss → src/sass}/mixins/_transition.scss +8 -4
- package/src/sass/mixins/_viewport.scss +69 -0
- package/src/sass/mixins/index.scss +3 -0
- package/src/ts/app/Application.ts +350 -0
- package/src/ts/app/events/PageLoad.ts +79 -0
- package/src/ts/app/events/Viewport.ts +365 -0
- package/src/ts/base/Callbacks.ts +380 -0
- package/src/ts/base/Component.ts +83 -0
- package/src/ts/base/Module.ts +385 -0
- package/src/ts/base/MutableProp.ts +242 -0
- package/src/ts/base/Plugin.ts +76 -0
- package/src/ts/components/animation-frame/AnimationFrame.ts +264 -0
- package/src/ts/components/canvas/Ctx2D.ts +260 -0
- package/src/ts/components/canvas/Ctx2DPrerender.ts +96 -0
- package/src/ts/components/cursor/CustomCursor.ts +462 -0
- package/src/ts/components/dragger/Dragger.ts +313 -0
- package/src/ts/components/dragger/DraggerDirection.ts +106 -0
- package/src/ts/components/dragger/DraggerMove.ts +114 -0
- package/src/ts/components/loading/Preloader.ts +279 -0
- package/src/ts/components/loading/ProgressPreloader.ts +484 -0
- package/src/ts/components/page/Page.ts +421 -0
- package/src/ts/components/scroll/plugins/SmoothScrollDragPlugin.ts +251 -0
- package/src/ts/components/scroll/plugins/SmoothScrollKeyboardPlugin.ts +166 -0
- package/src/ts/components/scroll/scrollable/ScrollEventsBase.ts +151 -0
- package/src/ts/components/scroll/scrollable/ScrollView.ts +435 -0
- package/src/ts/components/scroll/scrollbar/Bar.ts +364 -0
- package/src/ts/components/scroll/scrollbar/ScrollBar.ts +292 -0
- package/src/ts/components/scroll/smooth-scroll/SmoothScroll.ts +861 -0
- package/src/ts/components/scroll/types.ts +10 -0
- package/src/ts/components/text/SplitText.ts +418 -0
- package/src/ts/components/timeline/StaticTimeline.ts +197 -0
- package/src/ts/components/timeline/Timeline.ts +256 -0
- package/src/ts/index.ts +94 -0
- package/src/ts/utils/common/index.ts +9 -0
- package/src/ts/utils/common/mergeWithoutArrays.ts +20 -0
- package/src/ts/utils/common/randID.ts +9 -0
- package/src/ts/utils/common/timeoutCallback.ts +16 -0
- package/src/ts/utils/errors.ts +6 -0
- package/src/ts/utils/listeners/index.ts +7 -0
- package/src/ts/utils/listeners/intersectionObserverSupported.ts +10 -0
- package/src/ts/utils/listeners/onScroll.ts +56 -0
- package/src/ts/utils/math/boundVal.ts +15 -0
- package/src/ts/utils/math/index.ts +9 -0
- package/src/ts/utils/math/lerp.ts +16 -0
- package/src/ts/utils/math/scopeProgress.ts +23 -0
- package/src/ts/utils/types/general.ts +7 -0
- package/src/ts/utils/types/utility.ts +34 -0
- package/dist/js/AJAXEvent.js +0 -355
- package/dist/js/Application.js +0 -345
- package/dist/js/ColumnsModule.js +0 -392
- package/dist/js/CursorModule.js +0 -390
- package/dist/js/DraggerModule.js +0 -792
- package/dist/js/Event.js +0 -538
- package/dist/js/FilterModule.js +0 -943
- package/dist/js/FormModule.js +0 -706
- package/dist/js/FrameModule.js +0 -229
- package/dist/js/IntervalModule.js +0 -270
- package/dist/js/KeydownModule.js +0 -293
- package/dist/js/LoadEvent.js +0 -106
- package/dist/js/MenuBaseModule.js +0 -292
- package/dist/js/MenuModule.js +0 -265
- package/dist/js/MenuTimelineModule.js +0 -321
- package/dist/js/Module.js +0 -478
- package/dist/js/PageAjaxModule.js +0 -1010
- package/dist/js/PageLoadMediaPlugin.js +0 -285
- package/dist/js/PageModule.js +0 -440
- package/dist/js/PaginationModule.js +0 -961
- package/dist/js/PaginationScrollPlugin.js +0 -209
- package/dist/js/Plugin.js +0 -114
- package/dist/js/PopupModule.js +0 -942
- package/dist/js/PreloaderModule.js +0 -724
- package/dist/js/ResponsiveProp.js +0 -301
- package/dist/js/ScrollAnchorModule.js +0 -554
- package/dist/js/ScrollAnimateModule.js +0 -419
- package/dist/js/ScrollBarPlugin.js +0 -594
- package/dist/js/ScrollDragPlugin.js +0 -396
- package/dist/js/ScrollModule.js +0 -1071
- package/dist/js/ScrollViewModule.js +0 -388
- package/dist/js/SelectModule.js +0 -860
- package/dist/js/SliderCanvasModule.js +0 -733
- package/dist/js/SliderControlsPlugin.js +0 -247
- package/dist/js/SliderCounterPlugin.js +0 -278
- package/dist/js/SliderDotsPlugin.js +0 -270
- package/dist/js/SliderDragSwipePlugin.js +0 -245
- package/dist/js/SliderIntervalPlugin.js +0 -192
- package/dist/js/SliderKeydownPlugin.js +0 -185
- package/dist/js/SliderModule.js +0 -1062
- package/dist/js/SliderWheelPlugin.js +0 -194
- package/dist/js/TextAnimateModule.js +0 -663
- package/dist/js/TextSplitModule.js +0 -785
- package/dist/js/TimelineBaseModule.js +0 -405
- package/dist/js/TimelineModule.js +0 -494
- package/dist/js/URLEvent.js +0 -239
- package/dist/js/ViewportEvent.js +0 -465
- package/dist/js/WheelEventModule.js +0 -295
- package/dist/js/domChildOf.js +0 -46
- package/dist/js/domChildren.js +0 -47
- package/dist/js/domInsertAfter.js +0 -32
- package/dist/js/domRemoveChildren.js +0 -26
- package/dist/js/easing.js +0 -363
- package/dist/js/eventListenerAdd.js +0 -87
- package/dist/js/eventListenerGet.js +0 -49
- package/dist/js/eventListenerRemove.js +0 -36
- package/dist/js/generateId.js +0 -29
- package/dist/js/getBrowserName.js +0 -60
- package/dist/js/getOsName.js +0 -39
- package/dist/js/getVevetProperties.js +0 -22
- package/dist/js/index.js +0 -519
- package/dist/js/mathScopeProgress.js +0 -32
- package/dist/js/mathSpreadScopeProgress.js +0 -35
- package/dist/js/merge.js +0 -33
- package/dist/js/normalizeWheel.js +0 -97
- package/dist/js/text_animate_module_addons/_composite_elementary.js +0 -196
- package/dist/js/text_animate_module_addons/_elementary.js +0 -88
- package/dist/js/timeoutCallback.js +0 -26
- package/dist/js/vevet.js +0 -10
- package/dist/scss/_prefix.scss +0 -1
- package/dist/scss/classes/_clear.scss +0 -5
- package/dist/scss/classes/_col-row.scss +0 -48
- package/dist/scss/classes/_display.scss +0 -65
- package/dist/scss/classes/_document-reset.scss +0 -28
- package/dist/scss/classes/_document.scss +0 -7
- package/dist/scss/classes/_overflow.scss +0 -39
- package/dist/scss/classes/_position.scss +0 -55
- package/dist/scss/classes/_text.scss +0 -24
- package/dist/scss/classes/_transition.scss +0 -22
- package/dist/scss/classes/_wrap.scss +0 -31
- package/dist/scss/classes/index.scss +0 -14
- package/dist/scss/index.scss +0 -3
- package/dist/scss/mixins/_clear.scss +0 -6
- package/dist/scss/mixins/_display.scss +0 -6
- package/dist/scss/mixins/_form.scss +0 -14
- package/dist/scss/mixins/_position.scss +0 -42
- package/dist/scss/mixins/_reset.scss +0 -17
- package/dist/scss/mixins/_responsive.scss +0 -88
- package/dist/scss/mixins/index.scss +0 -7
- package/dist/scss/modules/columns/_settings.scss +0 -1
- package/dist/scss/modules/columns/index.scss +0 -19
- package/dist/scss/modules/cursor/_settings.scss +0 -7
- package/dist/scss/modules/cursor/index.scss +0 -15
- package/dist/scss/modules/form/_settings.scss +0 -15
- package/dist/scss/modules/form/index.scss +0 -57
- package/dist/scss/modules/index.scss +0 -11
- package/dist/scss/modules/menu/_button.scss +0 -58
- package/dist/scss/modules/menu/_menu.scss +0 -25
- package/dist/scss/modules/menu/_settings.scss +0 -23
- package/dist/scss/modules/menu/index.scss +0 -3
- package/dist/scss/modules/pagination/_settings.scss +0 -6
- package/dist/scss/modules/pagination/index.scss +0 -24
- package/dist/scss/modules/popup/_settings.scss +0 -26
- package/dist/scss/modules/popup/index.scss +0 -294
- package/dist/scss/modules/preloader/_settings.scss +0 -3
- package/dist/scss/modules/preloader/index.scss +0 -19
- package/dist/scss/modules/scroll/_settings.scss +0 -22
- package/dist/scss/modules/scroll/index.scss +0 -94
- package/dist/scss/modules/select/_settings.scss +0 -28
- package/dist/scss/modules/select/index.scss +0 -142
- package/dist/scss/modules/slider/_settings.scss +0 -35
- package/dist/scss/modules/slider/index.scss +0 -153
- package/dist/scss/modules/text/_settings.scss +0 -1
- package/dist/scss/modules/text/index.scss +0 -19
- package/dist/types/types.d.ts +0 -18763
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createElement } from 'vevet-dom';
|
|
2
|
+
import { Component } from '../../base/Component';
|
|
3
|
+
/**
|
|
4
|
+
* Makes working with canvas easier.
|
|
5
|
+
* It creates an HTML5 Canvas element and its 2d context and can
|
|
6
|
+
* implement automatic resize.
|
|
7
|
+
*/
|
|
8
|
+
export class Ctx2D extends Component {
|
|
9
|
+
constructor(initialProp, init = true) {
|
|
10
|
+
super(initialProp, false);
|
|
11
|
+
// set default values
|
|
12
|
+
this._width = 0;
|
|
13
|
+
this._height = 0;
|
|
14
|
+
this._dpr = 1;
|
|
15
|
+
// create canvas
|
|
16
|
+
const { append, container } = this.prop;
|
|
17
|
+
const parent = (append && container) ? container : undefined;
|
|
18
|
+
this._canvas = createElement('canvas', {
|
|
19
|
+
parent,
|
|
20
|
+
});
|
|
21
|
+
this._ctx = this._canvas.getContext('2d');
|
|
22
|
+
// and resize it for the first time
|
|
23
|
+
this.resize();
|
|
24
|
+
// initialize the class
|
|
25
|
+
if (init) {
|
|
26
|
+
this.init();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The parent container of the canvas
|
|
31
|
+
*/
|
|
32
|
+
get container() {
|
|
33
|
+
return this.prop.container;
|
|
34
|
+
}
|
|
35
|
+
get canvas() {
|
|
36
|
+
return this._canvas;
|
|
37
|
+
}
|
|
38
|
+
get ctx() {
|
|
39
|
+
return this._ctx;
|
|
40
|
+
}
|
|
41
|
+
get width() {
|
|
42
|
+
return this._width;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Canvas width without DPR
|
|
46
|
+
*/
|
|
47
|
+
get nonDPRWidth() {
|
|
48
|
+
return this.width / this.dpr;
|
|
49
|
+
}
|
|
50
|
+
get height() {
|
|
51
|
+
return this._height;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Canvas height without DPR
|
|
55
|
+
*/
|
|
56
|
+
get nonDPRHeight() {
|
|
57
|
+
return this.height / this.dpr;
|
|
58
|
+
}
|
|
59
|
+
get dpr() {
|
|
60
|
+
return this._dpr;
|
|
61
|
+
}
|
|
62
|
+
_getDefaultProp() {
|
|
63
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: false, append: true, updateOnResize: false, width: false, height: false, dpr: false });
|
|
64
|
+
}
|
|
65
|
+
// Set Module Events
|
|
66
|
+
_setEvents() {
|
|
67
|
+
super._setEvents();
|
|
68
|
+
if (this.prop.updateOnResize !== false) {
|
|
69
|
+
const viewportTarget = typeof this.prop.updateOnResize === 'boolean' ? '' : this.prop.updateOnResize;
|
|
70
|
+
this.addViewportCallback(viewportTarget, () => {
|
|
71
|
+
this.resize();
|
|
72
|
+
});
|
|
73
|
+
this.resize();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
_onPropMutate() {
|
|
77
|
+
super._onPropMutate();
|
|
78
|
+
this.resize();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Resize the canvas
|
|
82
|
+
*/
|
|
83
|
+
resize() {
|
|
84
|
+
// vars
|
|
85
|
+
const { prop, canvas } = this;
|
|
86
|
+
if (!canvas) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const app = this._app;
|
|
90
|
+
const { viewport } = app;
|
|
91
|
+
// calculate dpr
|
|
92
|
+
if (typeof prop.dpr === 'number') {
|
|
93
|
+
this._dpr = prop.dpr;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this._dpr = viewport.dpr;
|
|
97
|
+
}
|
|
98
|
+
const dpr = this._dpr;
|
|
99
|
+
// calculate new width & height
|
|
100
|
+
let newWidth = 0;
|
|
101
|
+
let newHeight = 0;
|
|
102
|
+
if (typeof prop.width === 'number' && typeof prop.height === 'number') {
|
|
103
|
+
newWidth = prop.width;
|
|
104
|
+
newHeight = prop.height;
|
|
105
|
+
}
|
|
106
|
+
else if (this.container) {
|
|
107
|
+
newWidth = this.container.clientWidth;
|
|
108
|
+
newHeight = this.container.clientHeight;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
newWidth = viewport.width;
|
|
112
|
+
newHeight = viewport.height;
|
|
113
|
+
}
|
|
114
|
+
newWidth *= dpr;
|
|
115
|
+
newHeight *= dpr;
|
|
116
|
+
// update sizes
|
|
117
|
+
this._width = newWidth;
|
|
118
|
+
this._height = newHeight;
|
|
119
|
+
// apply sizes
|
|
120
|
+
canvas.width = newWidth;
|
|
121
|
+
canvas.height = newHeight;
|
|
122
|
+
this.callbacks.tbt('resize', false);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Destroy the module
|
|
126
|
+
*/
|
|
127
|
+
_destroy() {
|
|
128
|
+
super._destroy();
|
|
129
|
+
if (this.canvas) {
|
|
130
|
+
this.canvas.remove();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getPos } from 'get-image-pos';
|
|
2
|
+
import { Ctx2D } from './Ctx2D';
|
|
3
|
+
/**
|
|
4
|
+
* The class allows you to prerender media for further use with reduced payloads.
|
|
5
|
+
*/
|
|
6
|
+
export class Ctx2DPrerender extends Ctx2D {
|
|
7
|
+
_getDefaultProp() {
|
|
8
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { media: false, posRule: 'cover' });
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resize the canvas
|
|
12
|
+
*/
|
|
13
|
+
resize() {
|
|
14
|
+
super.resize();
|
|
15
|
+
this._prerender();
|
|
16
|
+
}
|
|
17
|
+
_prerender() {
|
|
18
|
+
// check if media exists
|
|
19
|
+
const { media } = this.prop;
|
|
20
|
+
if (!media) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// get media sizes
|
|
24
|
+
const size = getPos({
|
|
25
|
+
source: media,
|
|
26
|
+
rule: this.prop.posRule,
|
|
27
|
+
scale: 1,
|
|
28
|
+
width: this.width,
|
|
29
|
+
height: this.height,
|
|
30
|
+
});
|
|
31
|
+
this._ctx.clearRect(0, 0, this.width, this.height);
|
|
32
|
+
// render the media
|
|
33
|
+
this._ctx.drawImage(media, 0, 0, size.sourceWidth, size.sourceHeight, size.x, size.y, size.width, size.height);
|
|
34
|
+
// launch callbacks on prerender
|
|
35
|
+
this.callbacks.tbt('prerender', false);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { createElement, selectOne } from 'vevet-dom';
|
|
2
|
+
import { AnimationFrame } from '../animation-frame/AnimationFrame';
|
|
3
|
+
import { Component } from '../../base/Component';
|
|
4
|
+
import lerp from '../../utils/math/lerp';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a smooth custom cursor
|
|
7
|
+
*/
|
|
8
|
+
export class CustomCursor extends Component {
|
|
9
|
+
constructor(initialProp, init = true) {
|
|
10
|
+
super(initialProp, false);
|
|
11
|
+
// get cursor container
|
|
12
|
+
const container = selectOne(this.prop.container);
|
|
13
|
+
if (container) {
|
|
14
|
+
this._container = container;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
throw new Error(`No cursor container for ${this.prop.container}`);
|
|
18
|
+
}
|
|
19
|
+
this._containerIsWindow = container instanceof Window;
|
|
20
|
+
// set default vars
|
|
21
|
+
this._x = 0;
|
|
22
|
+
this._xTarget = 0;
|
|
23
|
+
this._y = 0;
|
|
24
|
+
this._yTarget = 0;
|
|
25
|
+
this._currentFPS = 60;
|
|
26
|
+
this._canPlay = this.prop.run;
|
|
27
|
+
// initialize the class
|
|
28
|
+
if (init) {
|
|
29
|
+
this.init();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
_getDefaultProp() {
|
|
33
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, run: true, hideNativeCursor: false, render: {
|
|
34
|
+
lerp: 0.2,
|
|
35
|
+
lerpToFixed: 2,
|
|
36
|
+
normalizeLerp: false,
|
|
37
|
+
}, autoStop: true });
|
|
38
|
+
}
|
|
39
|
+
get prefix() {
|
|
40
|
+
return `${this._app.prefix}custom-cursor`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cursor container
|
|
44
|
+
*/
|
|
45
|
+
get container() {
|
|
46
|
+
return this._container;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The element for events
|
|
50
|
+
*/
|
|
51
|
+
get eventsContainer() {
|
|
52
|
+
return this._container;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The DOM parent for the cursor element
|
|
56
|
+
*/
|
|
57
|
+
get domContainer() {
|
|
58
|
+
if (this.container instanceof Window) {
|
|
59
|
+
return this._app.html;
|
|
60
|
+
}
|
|
61
|
+
return this.container;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Cursor element (outer element)
|
|
65
|
+
*/
|
|
66
|
+
get outerCursor() {
|
|
67
|
+
return this._outerCursor;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Cursor element (inner element)
|
|
71
|
+
*/
|
|
72
|
+
get innerCursor() {
|
|
73
|
+
return this._innerCursor;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Current X coordinate relative to Window
|
|
77
|
+
*/
|
|
78
|
+
get x() {
|
|
79
|
+
return this._x;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Current Y coordinate relative to Window
|
|
83
|
+
*/
|
|
84
|
+
get y() {
|
|
85
|
+
return this._y;
|
|
86
|
+
}
|
|
87
|
+
// Extra constructor
|
|
88
|
+
_constructor() {
|
|
89
|
+
super._constructor();
|
|
90
|
+
this._createCursor();
|
|
91
|
+
}
|
|
92
|
+
// Set Module Events
|
|
93
|
+
_setEvents() {
|
|
94
|
+
super._setEvents();
|
|
95
|
+
const { domContainer } = this;
|
|
96
|
+
// create animation frame
|
|
97
|
+
this._animationFrame = new AnimationFrame();
|
|
98
|
+
this._animationFrame.addCallback('frame', (data) => {
|
|
99
|
+
this._currentFPS = data.realFPS;
|
|
100
|
+
this.render();
|
|
101
|
+
});
|
|
102
|
+
if (this._canPlay) {
|
|
103
|
+
this.enable();
|
|
104
|
+
}
|
|
105
|
+
// set mouse hover events
|
|
106
|
+
this.addEventListeners(domContainer, 'mouseenter', this._handleMouseEnter.bind(this));
|
|
107
|
+
this.addEventListeners(domContainer, 'mouseleave', this._handleMouseLeave.bind(this));
|
|
108
|
+
// set move events
|
|
109
|
+
this.addEventListeners(domContainer, 'mousemove', this._handleMouseMove.bind(this));
|
|
110
|
+
// set click events events
|
|
111
|
+
this.addEventListeners(domContainer, 'mousedown', this._handleMouseDown.bind(this));
|
|
112
|
+
this.addEventListeners(domContainer, 'mouseup', this._handleMouseUp.bind(this));
|
|
113
|
+
this.addEventListeners(window, 'blur', this._handleWindowBlur.bind(this));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create custom cursor
|
|
117
|
+
*/
|
|
118
|
+
_createCursor() {
|
|
119
|
+
const { prefix, container, domContainer } = this;
|
|
120
|
+
// hide native cursor
|
|
121
|
+
if (this.prop.hideNativeCursor) {
|
|
122
|
+
domContainer.style.cursor = 'none';
|
|
123
|
+
domContainer.classList.add('hide-defaut-cursor');
|
|
124
|
+
}
|
|
125
|
+
// set classes
|
|
126
|
+
domContainer.classList.add(`${prefix}-container`);
|
|
127
|
+
// create cursor elements
|
|
128
|
+
this._outerCursor = createElement('div', {
|
|
129
|
+
class: `${prefix} ${container instanceof Window ? 'in-window' : 'in-element'} disabled`,
|
|
130
|
+
parent: domContainer,
|
|
131
|
+
});
|
|
132
|
+
this._innerCursor = createElement('div', {
|
|
133
|
+
class: `${prefix}__inner disabled`,
|
|
134
|
+
parent: this._outerCursor,
|
|
135
|
+
});
|
|
136
|
+
// launch events
|
|
137
|
+
this.callbacks.tbt('create', {
|
|
138
|
+
outerCursor: this.outerCursor,
|
|
139
|
+
innerCursor: this.innerCursor,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Destroy the cursor
|
|
144
|
+
*/
|
|
145
|
+
_destroyCursor() {
|
|
146
|
+
const { prefix, domContainer } = this;
|
|
147
|
+
domContainer.style.cursor = '';
|
|
148
|
+
domContainer.classList.remove('hide-defaut-cursor');
|
|
149
|
+
domContainer.classList.remove(`${prefix}-container`);
|
|
150
|
+
this._outerCursor.remove();
|
|
151
|
+
this._innerCursor.remove();
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Event on mouse enter
|
|
155
|
+
*/
|
|
156
|
+
_handleMouseEnter(evt) {
|
|
157
|
+
// update coordinates
|
|
158
|
+
this._xTarget = evt.clientX;
|
|
159
|
+
this._x = this._xTarget;
|
|
160
|
+
this._yTarget = evt.clientY;
|
|
161
|
+
this._y = this._yTarget;
|
|
162
|
+
// set classes
|
|
163
|
+
this.outerCursor.classList.add('in-action');
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Event on mouse leave
|
|
167
|
+
*/
|
|
168
|
+
_handleMouseLeave() {
|
|
169
|
+
this.outerCursor.classList.remove('in-action');
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Event on mouse move
|
|
173
|
+
*/
|
|
174
|
+
_handleMouseMove(evt) {
|
|
175
|
+
this._xTarget = evt.clientX;
|
|
176
|
+
this._yTarget = evt.clientY;
|
|
177
|
+
// set classes
|
|
178
|
+
this.outerCursor.classList.add('in-action');
|
|
179
|
+
// launch animation
|
|
180
|
+
if (this._canPlay) {
|
|
181
|
+
this._animationFrame.play();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Event on mouse down
|
|
186
|
+
*/
|
|
187
|
+
_handleMouseDown(evt) {
|
|
188
|
+
if (evt.which === 1) {
|
|
189
|
+
this.outerCursor.classList.add('click');
|
|
190
|
+
this.innerCursor.classList.add('click');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Event on mouse up
|
|
195
|
+
*/
|
|
196
|
+
_handleMouseUp() {
|
|
197
|
+
this.outerCursor.classList.remove('click');
|
|
198
|
+
this.innerCursor.classList.remove('click');
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Event on mouse down
|
|
202
|
+
*/
|
|
203
|
+
_handleWindowBlur() {
|
|
204
|
+
this._handleMouseUp();
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Render the scene
|
|
208
|
+
*/
|
|
209
|
+
render() {
|
|
210
|
+
// props
|
|
211
|
+
const { prop } = this;
|
|
212
|
+
const { domContainer } = this;
|
|
213
|
+
const { normalizeLerp, lerp: ease, lerpToFixed } = prop.render;
|
|
214
|
+
const fpsMultiplier = normalizeLerp ? 60 / this._currentFPS : 1;
|
|
215
|
+
// interpolate coordinates
|
|
216
|
+
this._x = lerp(this._x, this._xTarget, ease * fpsMultiplier, 0.02);
|
|
217
|
+
this._y = lerp(this._y, this._yTarget, ease * fpsMultiplier, 0.02);
|
|
218
|
+
// round the values
|
|
219
|
+
if (typeof lerpToFixed === 'number') {
|
|
220
|
+
const fixed = Math.round(Math.abs(lerpToFixed));
|
|
221
|
+
this._x = parseFloat(this._x.toFixed(fixed));
|
|
222
|
+
this._y = parseFloat(this._y.toFixed(fixed));
|
|
223
|
+
}
|
|
224
|
+
// calcu;ate real coordinates
|
|
225
|
+
let x = this._x;
|
|
226
|
+
let y = this._y;
|
|
227
|
+
if (!this._containerIsWindow) {
|
|
228
|
+
const bounding = domContainer.getBoundingClientRect();
|
|
229
|
+
x -= bounding.left;
|
|
230
|
+
y -= bounding.top;
|
|
231
|
+
}
|
|
232
|
+
// update dom coordinates
|
|
233
|
+
this.outerCursor.style.transform = `translate(${x}px, ${y}px)`;
|
|
234
|
+
// auto stop
|
|
235
|
+
if (prop.autoStop
|
|
236
|
+
&& this._x === this._xTarget && this._y === this._yTarget) {
|
|
237
|
+
this._animationFrame.pause();
|
|
238
|
+
}
|
|
239
|
+
// launch render events
|
|
240
|
+
this._callbacks.tbt('render', { x, y });
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Enable cursor
|
|
244
|
+
*/
|
|
245
|
+
enable() {
|
|
246
|
+
this._canPlay = true;
|
|
247
|
+
if (this._animationFrame.isPlaying) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this.outerCursor.classList.remove('disabled');
|
|
251
|
+
this.innerCursor.classList.remove('disabled');
|
|
252
|
+
this._animationFrame.play();
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Disable cursor
|
|
256
|
+
*/
|
|
257
|
+
disable() {
|
|
258
|
+
this._canPlay = false;
|
|
259
|
+
if (!this._animationFrame.isPlaying) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this.outerCursor.classList.add('disabled');
|
|
263
|
+
this.innerCursor.classList.add('disabled');
|
|
264
|
+
this._animationFrame.pause();
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Destroy the module
|
|
268
|
+
*/
|
|
269
|
+
_destroy() {
|
|
270
|
+
super._destroy();
|
|
271
|
+
this._destroyCursor();
|
|
272
|
+
this._animationFrame.destroy();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { addEventListener, isElement, isWindow, selectOne, } from 'vevet-dom';
|
|
2
|
+
import { Component } from '../../base/Component';
|
|
3
|
+
/**
|
|
4
|
+
* Drag & Swipe events. An abstract class
|
|
5
|
+
*/
|
|
6
|
+
export class Dragger extends Component {
|
|
7
|
+
constructor(initialProp, init = true) {
|
|
8
|
+
super(initialProp, false);
|
|
9
|
+
// get container
|
|
10
|
+
this._container = selectOne(this.prop.container);
|
|
11
|
+
if (!isElement(this._container) && !isWindow(this._container)) {
|
|
12
|
+
throw new Error('No container');
|
|
13
|
+
}
|
|
14
|
+
// set default vars
|
|
15
|
+
this._runtimeEvents = [];
|
|
16
|
+
this._isDragging = false;
|
|
17
|
+
this._pointerID = null;
|
|
18
|
+
this._coords = { x: 0, y: 0 };
|
|
19
|
+
this._prevCoords = { x: 0, y: 0 };
|
|
20
|
+
this._startCoords = { x: 0, y: 0 };
|
|
21
|
+
// initialize the class
|
|
22
|
+
if (init) {
|
|
23
|
+
this.init();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
_getDefaultProp() {
|
|
27
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: `#${this.prefix}`, usePassive: false, enabled: true });
|
|
28
|
+
}
|
|
29
|
+
get prefix() {
|
|
30
|
+
return `${this._app.prefix}dragger`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Preloader container
|
|
34
|
+
*/
|
|
35
|
+
get container() {
|
|
36
|
+
return this._container;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* If is dragging at the moment
|
|
40
|
+
*/
|
|
41
|
+
get isDragging() {
|
|
42
|
+
return this._isDragging;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Current coordinates relative to the Window
|
|
46
|
+
*/
|
|
47
|
+
get coords() {
|
|
48
|
+
return this._coords;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Coordinates on drag start
|
|
52
|
+
*/
|
|
53
|
+
get startCoords() {
|
|
54
|
+
return this._startCoords;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Set component events
|
|
58
|
+
*/
|
|
59
|
+
_setEvents() {
|
|
60
|
+
const { container } = this;
|
|
61
|
+
const { usePassive } = this.prop;
|
|
62
|
+
this.addEventListeners(container, 'mousedown', this._handleStart.bind(this), { passive: usePassive });
|
|
63
|
+
this.addEventListeners(container, 'touchstart', this._handleStart.bind(this), { passive: usePassive });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Add runtime events
|
|
67
|
+
*/
|
|
68
|
+
_addRuntimeEvents() {
|
|
69
|
+
const { usePassive } = this.prop;
|
|
70
|
+
// end
|
|
71
|
+
this._runtimeEvents.push(addEventListener(window, 'mouseup', this._handleEnd.bind(this), {
|
|
72
|
+
passive: usePassive,
|
|
73
|
+
}));
|
|
74
|
+
this._runtimeEvents.push(addEventListener(window, 'touchend', this._handleEnd.bind(this), {
|
|
75
|
+
passive: usePassive,
|
|
76
|
+
}));
|
|
77
|
+
// cancel
|
|
78
|
+
this._runtimeEvents.push(addEventListener(window, 'touchcancel', this.cancel.bind(this), {
|
|
79
|
+
passive: usePassive,
|
|
80
|
+
}));
|
|
81
|
+
this._runtimeEvents.push(addEventListener(window, 'blur', this.cancel.bind(this), {
|
|
82
|
+
passive: usePassive,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Remove runtime events
|
|
87
|
+
*/
|
|
88
|
+
_removeRuntimeEvents() {
|
|
89
|
+
this._runtimeEvents.forEach((event) => {
|
|
90
|
+
event.remove();
|
|
91
|
+
});
|
|
92
|
+
this._runtimeEvents = [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Normalize event data.
|
|
96
|
+
*/
|
|
97
|
+
_normalizeEvent(e) {
|
|
98
|
+
if (e.type.includes('touch')) {
|
|
99
|
+
const evt = e;
|
|
100
|
+
const touch = evt.targetTouches[0] || evt.changedTouches[0];
|
|
101
|
+
return {
|
|
102
|
+
x: touch.clientX,
|
|
103
|
+
y: touch.clientY,
|
|
104
|
+
id: touch.identifier,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const evt = e;
|
|
108
|
+
return {
|
|
109
|
+
x: evt.clientX,
|
|
110
|
+
y: evt.clientY,
|
|
111
|
+
id: null,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Event on start dragging
|
|
116
|
+
*/
|
|
117
|
+
_handleStart(e) {
|
|
118
|
+
if (!this.prop.enabled) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (this.isDragging) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const evt = this._normalizeEvent(e);
|
|
125
|
+
// prevent actions
|
|
126
|
+
if (e.type === 'mousedown') {
|
|
127
|
+
if (e.which === 1) {
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// update states
|
|
135
|
+
this._isDragging = true;
|
|
136
|
+
this._pointerID = evt.id;
|
|
137
|
+
// change coordinates
|
|
138
|
+
this._coords = { x: evt.x, y: evt.y };
|
|
139
|
+
this._prevCoords = { x: evt.x, y: evt.y };
|
|
140
|
+
this._startCoords = { x: evt.x, y: evt.y };
|
|
141
|
+
// add additional events
|
|
142
|
+
this._addRuntimeEvents();
|
|
143
|
+
// launch callbacks
|
|
144
|
+
this.callbacks.tbt('start', {
|
|
145
|
+
evt: e,
|
|
146
|
+
});
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Event on drag end
|
|
151
|
+
*/
|
|
152
|
+
_handleEnd(e) {
|
|
153
|
+
const evt = this._normalizeEvent(e);
|
|
154
|
+
if (!this.isDragging || evt.id !== this._pointerID) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
this.cancel();
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Cancel dragging
|
|
162
|
+
*/
|
|
163
|
+
cancel() {
|
|
164
|
+
this._removeRuntimeEvents();
|
|
165
|
+
this._isDragging = false;
|
|
166
|
+
this.callbacks.tbt('end', false);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Destroy the module
|
|
170
|
+
*/
|
|
171
|
+
_destroy() {
|
|
172
|
+
super._destroy();
|
|
173
|
+
this._removeRuntimeEvents();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Dragger } from './Dragger';
|
|
2
|
+
/**
|
|
3
|
+
* Dragger that detects direction
|
|
4
|
+
*/
|
|
5
|
+
export class DraggerDirection extends Dragger {
|
|
6
|
+
_getDefaultProp() {
|
|
7
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { min: 75 });
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Event on drag end
|
|
11
|
+
*/
|
|
12
|
+
_handleEnd(e) {
|
|
13
|
+
const res = super._handleEnd(e);
|
|
14
|
+
if (!res) {
|
|
15
|
+
return res;
|
|
16
|
+
}
|
|
17
|
+
const evt = this._normalizeEvent(e);
|
|
18
|
+
const { startCoords } = this;
|
|
19
|
+
const min = Math.abs(this.prop.min);
|
|
20
|
+
// up
|
|
21
|
+
if (startCoords.y > evt.y
|
|
22
|
+
&& Math.abs(evt.y - startCoords.y) >= min) {
|
|
23
|
+
this.callbacks.tbt('up', false);
|
|
24
|
+
}
|
|
25
|
+
// down
|
|
26
|
+
if (startCoords.y < evt.y
|
|
27
|
+
&& Math.abs(evt.y - startCoords.y) >= min) {
|
|
28
|
+
this.callbacks.tbt('down', false);
|
|
29
|
+
}
|
|
30
|
+
// left
|
|
31
|
+
if (startCoords.x > evt.x
|
|
32
|
+
&& Math.abs(evt.x - startCoords.x) >= min) {
|
|
33
|
+
this.callbacks.tbt('left', false);
|
|
34
|
+
}
|
|
35
|
+
// right
|
|
36
|
+
if (startCoords.x < evt.x
|
|
37
|
+
&& Math.abs(evt.x - startCoords.x) >= min) {
|
|
38
|
+
this.callbacks.tbt('right', false);
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|