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,109 @@
|
|
|
1
|
+
import { childOf } from 'vevet-dom';
|
|
2
|
+
import { Plugin } from '../../../base/Plugin';
|
|
3
|
+
import timeoutCallback from '../../../utils/common/timeoutCallback';
|
|
4
|
+
/**
|
|
5
|
+
* A class for Plugins.
|
|
6
|
+
*/
|
|
7
|
+
export class SmoothScrollKeyboardPlugin extends Plugin {
|
|
8
|
+
_setEvents() {
|
|
9
|
+
super._setEvents();
|
|
10
|
+
this.addEventListeners(window, 'keydown', (e) => {
|
|
11
|
+
this._handleKeydown(e);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Event on a key pressed
|
|
16
|
+
*/
|
|
17
|
+
_handleKeydown(e) {
|
|
18
|
+
const component = this._component;
|
|
19
|
+
if (!component.prop.enabled) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// tab is active for everethyng, forms too
|
|
23
|
+
if (e.keyCode === 9) {
|
|
24
|
+
this._handleTab();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// check if some element is under focus
|
|
28
|
+
// if some exists, ignore key events
|
|
29
|
+
const { activeElement } = document;
|
|
30
|
+
if (activeElement) {
|
|
31
|
+
if (activeElement instanceof HTMLInputElement
|
|
32
|
+
|| activeElement instanceof HTMLTextAreaElement) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// update scroll values
|
|
37
|
+
const scrollIterator = 40;
|
|
38
|
+
switch (e.keyCode) {
|
|
39
|
+
// up
|
|
40
|
+
case 38:
|
|
41
|
+
component.targetTop -= scrollIterator;
|
|
42
|
+
break;
|
|
43
|
+
// down
|
|
44
|
+
case 40:
|
|
45
|
+
component.targetTop += scrollIterator;
|
|
46
|
+
break;
|
|
47
|
+
// right
|
|
48
|
+
case 39:
|
|
49
|
+
component.targetLeft += scrollIterator;
|
|
50
|
+
break;
|
|
51
|
+
// left
|
|
52
|
+
case 37:
|
|
53
|
+
component.targetLeft -= scrollIterator;
|
|
54
|
+
break;
|
|
55
|
+
// page down
|
|
56
|
+
case 34:
|
|
57
|
+
component.targetTop += scrollIterator * 10;
|
|
58
|
+
break;
|
|
59
|
+
// page up
|
|
60
|
+
case 33:
|
|
61
|
+
component.targetTop -= scrollIterator * 10;
|
|
62
|
+
break;
|
|
63
|
+
// home
|
|
64
|
+
case 36:
|
|
65
|
+
component.targetTop = 0;
|
|
66
|
+
component.targetLeft = 0;
|
|
67
|
+
break;
|
|
68
|
+
// end
|
|
69
|
+
case 35:
|
|
70
|
+
component.targetTop = component.scrollHeight;
|
|
71
|
+
component.targetLeft = component.scrollWidth;
|
|
72
|
+
break;
|
|
73
|
+
// space
|
|
74
|
+
case 32:
|
|
75
|
+
component.targetTop += scrollIterator * 5;
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Handle Tab key pressed
|
|
83
|
+
*/
|
|
84
|
+
_handleTab() {
|
|
85
|
+
// get active element and scroll to it
|
|
86
|
+
timeoutCallback(() => {
|
|
87
|
+
const scroll = this._component;
|
|
88
|
+
const { activeElement } = document;
|
|
89
|
+
// skip elements that do not belong to the SmoothScroll outer
|
|
90
|
+
if (!(activeElement instanceof HTMLElement)
|
|
91
|
+
|| !childOf(activeElement, scroll.outer)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// get boundings
|
|
95
|
+
const scrollOuterBounding = scroll.outer.getBoundingClientRect();
|
|
96
|
+
const activeElementBounding = activeElement.getBoundingClientRect();
|
|
97
|
+
// get element position
|
|
98
|
+
const top = scroll.scrollTop
|
|
99
|
+
+ (activeElementBounding.top - scrollOuterBounding.top)
|
|
100
|
+
- (scroll.clientHeight / 2 - activeElementBounding.height / 2);
|
|
101
|
+
const left = scroll.scrollLeft
|
|
102
|
+
+ (activeElementBounding.left - scrollOuterBounding.left)
|
|
103
|
+
- (scroll.clientWidth / 2 - activeElementBounding.width / 2);
|
|
104
|
+
// apply new targets
|
|
105
|
+
scroll.targetTop = top;
|
|
106
|
+
scroll.targetLeft = left;
|
|
107
|
+
}, 120);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { selectOne } from 'vevet-dom';
|
|
2
|
+
import { Component } from '../../../base/Component';
|
|
3
|
+
/**
|
|
4
|
+
* A base for scroll event components
|
|
5
|
+
*/
|
|
6
|
+
export class ScrollEventsBase extends Component {
|
|
7
|
+
constructor(initialProp, init = true) {
|
|
8
|
+
super(initialProp, false);
|
|
9
|
+
// get scroll container
|
|
10
|
+
if (typeof this.prop.container === 'string') {
|
|
11
|
+
this._scrollContainer = selectOne(this.prop.container);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this._scrollContainer = this.prop.container;
|
|
15
|
+
}
|
|
16
|
+
// initialize the class
|
|
17
|
+
if (init) {
|
|
18
|
+
this.init();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
_getDefaultProp() {
|
|
22
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window });
|
|
23
|
+
}
|
|
24
|
+
get scrollContainer() {
|
|
25
|
+
return this._scrollContainer;
|
|
26
|
+
}
|
|
27
|
+
get scrollableElement() {
|
|
28
|
+
if (this._scrollContainer instanceof Window) {
|
|
29
|
+
return this._app.html;
|
|
30
|
+
}
|
|
31
|
+
return this._scrollContainer;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parent of inner elements
|
|
35
|
+
*/
|
|
36
|
+
get domParent() {
|
|
37
|
+
const { scrollContainer } = this;
|
|
38
|
+
if (scrollContainer instanceof Window) {
|
|
39
|
+
return this._app.body;
|
|
40
|
+
}
|
|
41
|
+
if (scrollContainer instanceof Element) {
|
|
42
|
+
return scrollContainer;
|
|
43
|
+
}
|
|
44
|
+
return scrollContainer.outer;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Used as a "root" for IntersectionObserver
|
|
48
|
+
*/
|
|
49
|
+
get intersectionRoot() {
|
|
50
|
+
const { scrollContainer } = this;
|
|
51
|
+
if (scrollContainer instanceof Window) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (scrollContainer instanceof Element) {
|
|
55
|
+
return scrollContainer;
|
|
56
|
+
}
|
|
57
|
+
return scrollContainer.outer;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* BoundingRect of 'scrollContainer'
|
|
61
|
+
*/
|
|
62
|
+
get scrollContainerBounding() {
|
|
63
|
+
if (this.intersectionRoot) {
|
|
64
|
+
const bounding = this.intersectionRoot.getBoundingClientRect();
|
|
65
|
+
return {
|
|
66
|
+
top: bounding.top,
|
|
67
|
+
left: bounding.left,
|
|
68
|
+
width: bounding.width,
|
|
69
|
+
height: bounding.height,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
top: 0,
|
|
74
|
+
left: 0,
|
|
75
|
+
width: this._app.viewport.width,
|
|
76
|
+
height: this._app.viewport.height,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { selectAll } from 'vevet-dom';
|
|
2
|
+
import { ScrollEventsBase } from './ScrollEventsBase';
|
|
3
|
+
import onScroll from '../../../utils/listeners/onScroll';
|
|
4
|
+
import { intersectionObserverSupported } from '../../../utils/listeners';
|
|
5
|
+
import boundVal from '../../../utils/math/boundVal';
|
|
6
|
+
import timeoutCallback from '../../../utils/common/timeoutCallback';
|
|
7
|
+
/**
|
|
8
|
+
* Elements into viewport
|
|
9
|
+
*/
|
|
10
|
+
export class ScrollView extends ScrollEventsBase {
|
|
11
|
+
constructor(initialProp, init = true) {
|
|
12
|
+
super(initialProp, false);
|
|
13
|
+
this._firstStart = true;
|
|
14
|
+
// get view elements
|
|
15
|
+
this.updateElements();
|
|
16
|
+
// initialize the class
|
|
17
|
+
if (init) {
|
|
18
|
+
this.init();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
get prefix() {
|
|
22
|
+
return `${this._app.prefix}scroll-view`;
|
|
23
|
+
}
|
|
24
|
+
_getDefaultProp() {
|
|
25
|
+
return Object.assign(Object.assign({}, super._getDefaultProp()), { container: window, elements: `.${this.prefix}__el`, threshold: 0.9, states: 'in', classToToggle: 'viewed', useDelay: false, useIntersectionObserver: true });
|
|
26
|
+
}
|
|
27
|
+
init() {
|
|
28
|
+
super.init();
|
|
29
|
+
this.seekBounding();
|
|
30
|
+
}
|
|
31
|
+
// Set Module Events
|
|
32
|
+
_setEvents() {
|
|
33
|
+
super._setEvents();
|
|
34
|
+
this.resize();
|
|
35
|
+
this.addViewportCallback('', () => {
|
|
36
|
+
this.resize();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
_onPropMutate() {
|
|
40
|
+
super._onPropMutate();
|
|
41
|
+
this._removeViewEvents();
|
|
42
|
+
this.updateElements();
|
|
43
|
+
this._setViewEvents();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resize the scene
|
|
47
|
+
*/
|
|
48
|
+
resize() {
|
|
49
|
+
this._removeViewEvents();
|
|
50
|
+
this._setViewEvents();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set View events: scroll or intersection
|
|
54
|
+
*/
|
|
55
|
+
_setViewEvents() {
|
|
56
|
+
// set intersection observer
|
|
57
|
+
if (intersectionObserverSupported() && this.prop.useIntersectionObserver) {
|
|
58
|
+
// get intersecton margins
|
|
59
|
+
const { scrollContainerBounding } = this;
|
|
60
|
+
const xMargin = this._firstStart
|
|
61
|
+
? 0 : scrollContainerBounding.width * (1 - this.prop.threshold) * -1;
|
|
62
|
+
const yMargin = this._firstStart
|
|
63
|
+
? 0 : scrollContainerBounding.height * (1 - this.prop.threshold) * -1;
|
|
64
|
+
// create intersection observer
|
|
65
|
+
this._intersectionObserver = new IntersectionObserver(this._handleIntersectionObserver.bind(this), {
|
|
66
|
+
root: this.intersectionRoot,
|
|
67
|
+
threshold: 0,
|
|
68
|
+
rootMargin: `0px ${xMargin}px ${yMargin}px 0px`,
|
|
69
|
+
});
|
|
70
|
+
// add elements
|
|
71
|
+
if (this.elements) {
|
|
72
|
+
this.elements.forEach((el) => {
|
|
73
|
+
var _a;
|
|
74
|
+
(_a = this._intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(el);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// set scroll bounding events
|
|
80
|
+
this._scrollEvent = onScroll(this.prop.container, this._handleScroll.bind(this));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Remove View events: scroll or intersection
|
|
85
|
+
*/
|
|
86
|
+
_removeViewEvents() {
|
|
87
|
+
// remove scroll events
|
|
88
|
+
if (this._scrollEvent) {
|
|
89
|
+
this._scrollEvent.remove();
|
|
90
|
+
this._scrollEvent = undefined;
|
|
91
|
+
}
|
|
92
|
+
// destroy intersection observer
|
|
93
|
+
if (this._intersectionObserver) {
|
|
94
|
+
this._intersectionObserver.disconnect();
|
|
95
|
+
this._intersectionObserver = undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Element to seek
|
|
100
|
+
*/
|
|
101
|
+
get elements() {
|
|
102
|
+
return this._elements;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Update elements
|
|
106
|
+
*/
|
|
107
|
+
updateElements() {
|
|
108
|
+
// check if elements exist
|
|
109
|
+
if (typeof this.elements === 'undefined') {
|
|
110
|
+
this._elements = [];
|
|
111
|
+
}
|
|
112
|
+
// unobserve old elements
|
|
113
|
+
this.elements.forEach((el) => {
|
|
114
|
+
if (this._intersectionObserver) {
|
|
115
|
+
this._intersectionObserver.unobserve(el);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
// update elements
|
|
119
|
+
this._elements = Array.from(selectAll(this.prop.elements, this.domParent || undefined)).filter((el) => !el.classList.contains(this.prop.classToToggle));
|
|
120
|
+
// add them to the observer
|
|
121
|
+
this._elements.forEach((el) => {
|
|
122
|
+
if (this._intersectionObserver) {
|
|
123
|
+
this._intersectionObserver.observe(el);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Event on IntersectionObserver
|
|
129
|
+
*/
|
|
130
|
+
_handleIntersectionObserver(data) {
|
|
131
|
+
const parentBounding = this._firstStart ? this.scrollContainerBounding : false;
|
|
132
|
+
for (let index = 0; index < data.length; index += 1) {
|
|
133
|
+
const entry = data[index];
|
|
134
|
+
let delay = 0;
|
|
135
|
+
if (this._firstStart && !!parentBounding && entry.isIntersecting) {
|
|
136
|
+
delay = this._elementInViewportData(entry.target, parentBounding).delay;
|
|
137
|
+
}
|
|
138
|
+
this._handleInOut(entry.target, entry.isIntersecting, delay);
|
|
139
|
+
}
|
|
140
|
+
this._processUnusedElements();
|
|
141
|
+
// change states
|
|
142
|
+
if (this._firstStart) {
|
|
143
|
+
this._firstStart = false;
|
|
144
|
+
this.resize();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Event on Scroll
|
|
149
|
+
*/
|
|
150
|
+
_handleScroll() {
|
|
151
|
+
this.seekBounding();
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Seek the elements by their bounding.
|
|
155
|
+
* Only if IntersectionObserver is not used.
|
|
156
|
+
*/
|
|
157
|
+
seekBounding() {
|
|
158
|
+
// check if calculations are done through getBoundingClientRect
|
|
159
|
+
if (intersectionObserverSupported() && this.prop.useIntersectionObserver) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// vars
|
|
163
|
+
const { scrollContainerBounding } = this;
|
|
164
|
+
// go through all elements and get their boudning
|
|
165
|
+
for (let index = 0; index < this.elements.length; index += 1) {
|
|
166
|
+
const el = this.elements[index];
|
|
167
|
+
const elData = this._elementInViewportData(el, scrollContainerBounding);
|
|
168
|
+
const delay = elData.isIntersecting ? elData.delay : 0;
|
|
169
|
+
this._handleInOut(el, elData.isIntersecting, delay);
|
|
170
|
+
}
|
|
171
|
+
this._processUnusedElements();
|
|
172
|
+
// change states
|
|
173
|
+
if (this._firstStart) {
|
|
174
|
+
this._firstStart = false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Check element's bounding to define if it is in viewport
|
|
179
|
+
*/
|
|
180
|
+
_elementInViewportData(el, parentBounding) {
|
|
181
|
+
const { threshold: propThreshold, states, useDelay } = this.prop;
|
|
182
|
+
const threshold = this._firstStart ? 1 : propThreshold;
|
|
183
|
+
const bounding = el.getBoundingClientRect();
|
|
184
|
+
// check if the element is intersecting
|
|
185
|
+
let isIntersecting = false;
|
|
186
|
+
if (bounding.top < parentBounding.top + parentBounding.height * threshold
|
|
187
|
+
&& bounding.left < parentBounding.left + parentBounding.width * threshold) {
|
|
188
|
+
if (states === 'in') {
|
|
189
|
+
isIntersecting = true;
|
|
190
|
+
}
|
|
191
|
+
else if (bounding.right < parentBounding.left * threshold
|
|
192
|
+
|| bounding.bottom < parentBounding.top * threshold) {
|
|
193
|
+
isIntersecting = false;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
isIntersecting = true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// calculate delay only if it is enabled & calculations
|
|
200
|
+
// are done for the first time
|
|
201
|
+
let delay = 0;
|
|
202
|
+
if (!!useDelay && this._firstStart) {
|
|
203
|
+
const progress = boundVal(useDelay.dir === 'x'
|
|
204
|
+
? (bounding.left - parentBounding.left) / parentBounding.width
|
|
205
|
+
: (bounding.top - parentBounding.top) / parentBounding.height, [0, 1]);
|
|
206
|
+
delay = progress * useDelay.max;
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
isIntersecting,
|
|
210
|
+
delay,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Event that is triggered when an element appears or disappears
|
|
215
|
+
*/
|
|
216
|
+
_handleInOut(el, inViewport, delay = 0) {
|
|
217
|
+
const { states } = this.prop;
|
|
218
|
+
// check if need to continue
|
|
219
|
+
if ((el.scrollViewIn && inViewport)
|
|
220
|
+
|| (!el.scrollViewIn && !inViewport)) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// update props
|
|
224
|
+
el.scrollViewIn = inViewport;
|
|
225
|
+
// toggle classes
|
|
226
|
+
timeoutCallback(() => {
|
|
227
|
+
el.classList.toggle(this.prop.classToToggle, inViewport);
|
|
228
|
+
}, delay);
|
|
229
|
+
// process callbacks
|
|
230
|
+
if (inViewport && (states === 'in' || states === 'inout')) {
|
|
231
|
+
timeoutCallback(() => {
|
|
232
|
+
this.callbacks.tbt('in', el);
|
|
233
|
+
}, delay);
|
|
234
|
+
}
|
|
235
|
+
else if (!inViewport && states === 'inout') {
|
|
236
|
+
timeoutCallback(() => {
|
|
237
|
+
this.callbacks.tbt('out', el);
|
|
238
|
+
}, delay);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Remove elements that are mo more in need
|
|
243
|
+
*/
|
|
244
|
+
_processUnusedElements() {
|
|
245
|
+
if (this.prop.states !== 'in') {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// remove unused elements
|
|
249
|
+
const elementsToRemove = this._elements.filter((el) => el.scrollViewIn);
|
|
250
|
+
elementsToRemove.forEach((el) => {
|
|
251
|
+
if (this._intersectionObserver) {
|
|
252
|
+
this._intersectionObserver.unobserve(el);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
this._elements = this._elements.filter((el) => !el.scrollViewIn);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Destroy the module
|
|
259
|
+
*/
|
|
260
|
+
_destroy() {
|
|
261
|
+
super._destroy();
|
|
262
|
+
this._removeViewEvents();
|
|
263
|
+
}
|
|
264
|
+
}
|