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,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.Callbacks = void 0;
|
|
15
|
+
var common_1 = require("../utils/common");
|
|
16
|
+
/**
|
|
17
|
+
* A class for callbacks' manipulation.
|
|
18
|
+
*/
|
|
19
|
+
var Callbacks = /** @class */ (function () {
|
|
20
|
+
/**
|
|
21
|
+
* @example
|
|
22
|
+
* const callback = new Callbacks();
|
|
23
|
+
*/
|
|
24
|
+
function Callbacks(callInit) {
|
|
25
|
+
if (callInit === void 0) { callInit = true; }
|
|
26
|
+
this._app = window.vevetApp;
|
|
27
|
+
this._callbacks = [];
|
|
28
|
+
// initialize callbacks
|
|
29
|
+
if (callInit) {
|
|
30
|
+
this._init();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(Callbacks.prototype, "callbacks", {
|
|
34
|
+
/**
|
|
35
|
+
* Get all callbacks
|
|
36
|
+
*/
|
|
37
|
+
get: function () {
|
|
38
|
+
return this._callbacks;
|
|
39
|
+
},
|
|
40
|
+
enumerable: false,
|
|
41
|
+
configurable: true
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the class.
|
|
45
|
+
*/
|
|
46
|
+
Callbacks.prototype._init = function () {
|
|
47
|
+
this._constructor();
|
|
48
|
+
this._setEvents();
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* An empty method that is called in {@linkcode Callbacks._init}.
|
|
52
|
+
*/
|
|
53
|
+
Callbacks.prototype._constructor = function () {
|
|
54
|
+
// code
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* An empty method that is called in {@linkcode Callbacks._init}.
|
|
58
|
+
*/
|
|
59
|
+
Callbacks.prototype._setEvents = function () {
|
|
60
|
+
// code
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Adds a callback
|
|
64
|
+
* @param target - Callback target name
|
|
65
|
+
* @param func - Callback function
|
|
66
|
+
* @param data - Callback data
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const onTarget = callback.add("target-name", () => {
|
|
70
|
+
* alert("callback");
|
|
71
|
+
* });
|
|
72
|
+
*/
|
|
73
|
+
Callbacks.prototype.add = function (target, func, data) {
|
|
74
|
+
if (data === void 0) { data = {}; }
|
|
75
|
+
var id = common_1.randID('callback');
|
|
76
|
+
var obj = {
|
|
77
|
+
id: id,
|
|
78
|
+
on: true,
|
|
79
|
+
data: __assign({ target: target,
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
do: func }, data),
|
|
82
|
+
};
|
|
83
|
+
this._callbacks.push(obj);
|
|
84
|
+
this._onAdd(id);
|
|
85
|
+
return {
|
|
86
|
+
id: id,
|
|
87
|
+
remove: this.remove.bind(this, id),
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Use it to implement some actions after adding a callback.
|
|
92
|
+
*/
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
94
|
+
Callbacks.prototype._onAdd = function (id) {
|
|
95
|
+
// code
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Remove a callback.
|
|
99
|
+
*/
|
|
100
|
+
Callbacks.prototype.remove = function (id, removeProtected) {
|
|
101
|
+
var _this = this;
|
|
102
|
+
if (removeProtected === void 0) { removeProtected = false; }
|
|
103
|
+
// remove the callback and get new ones
|
|
104
|
+
var removed = false;
|
|
105
|
+
var newCallbacks = this._callbacks.filter(function (callback) {
|
|
106
|
+
// if not ID overlap
|
|
107
|
+
if (callback.id !== id) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
// to be removed
|
|
111
|
+
var data = callback.data;
|
|
112
|
+
if (data.protected && !removeProtected) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
_this._onRemove(id);
|
|
116
|
+
removed = true;
|
|
117
|
+
return false;
|
|
118
|
+
});
|
|
119
|
+
// replace the callbacks' array
|
|
120
|
+
this._callbacks = newCallbacks;
|
|
121
|
+
// return results
|
|
122
|
+
return removed;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Use it to implement some actions after removing a callback.
|
|
126
|
+
*/
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
128
|
+
Callbacks.prototype._onRemove = function (id) {
|
|
129
|
+
// code
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Remove all callbacks.
|
|
133
|
+
*/
|
|
134
|
+
Callbacks.prototype.removeAll = function (removeProtected) {
|
|
135
|
+
if (removeProtected === void 0) { removeProtected = false; }
|
|
136
|
+
while (this._callbacks.length > 0) {
|
|
137
|
+
this.remove(this._callbacks[0].id, removeProtected);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Enable/disable a callback.
|
|
142
|
+
* @param id - ID of the callback
|
|
143
|
+
* @param enabled - True to enable, false to disable.
|
|
144
|
+
*/
|
|
145
|
+
Callbacks.prototype.turn = function (id, enabled) {
|
|
146
|
+
if (enabled === void 0) { enabled = true; }
|
|
147
|
+
var callback = this.get(id);
|
|
148
|
+
if (callback) {
|
|
149
|
+
callback.on = enabled;
|
|
150
|
+
this._onTurn(id);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Use it to implement some actions after enabling or disabling a callback.
|
|
157
|
+
*/
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
159
|
+
Callbacks.prototype._onTurn = function (id) {
|
|
160
|
+
// code
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Get a callback by id
|
|
164
|
+
*/
|
|
165
|
+
Callbacks.prototype.get = function (id) {
|
|
166
|
+
var callbacks = this._callbacks.filter(function (callback) { return callback.id === id; });
|
|
167
|
+
if (callbacks.length > 0) {
|
|
168
|
+
return callbacks[0];
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Trigger a callback. It will work only if the callback is enabled.
|
|
174
|
+
*/
|
|
175
|
+
Callbacks.prototype._trigger = function (callback, arg) {
|
|
176
|
+
// check if enabled
|
|
177
|
+
if (!callback.on) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
var _a = callback.data, timeout = _a.timeout, once = _a.once;
|
|
181
|
+
var func = callback.data.do;
|
|
182
|
+
// launch
|
|
183
|
+
if (timeout) {
|
|
184
|
+
if (arg) {
|
|
185
|
+
common_1.timeoutCallback(this._triggerFunc.bind(this, func, arg), timeout);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
common_1.timeoutCallback(this._triggerFunc.bind(this, func, false), timeout);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (arg) {
|
|
192
|
+
this._triggerFunc(func, arg);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
this._triggerFunc(func, false);
|
|
196
|
+
}
|
|
197
|
+
// remove once-callback
|
|
198
|
+
if (once) {
|
|
199
|
+
this.remove(callback.id);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Launch a callback's function
|
|
204
|
+
*/
|
|
205
|
+
Callbacks.prototype._triggerFunc = function (func, arg) {
|
|
206
|
+
if (arg) {
|
|
207
|
+
func(arg);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
func();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Trigger all enabled callbacks under a certain target name. (TBT: Trigger by target).
|
|
215
|
+
*/
|
|
216
|
+
Callbacks.prototype.tbt = function (target, arg) {
|
|
217
|
+
var _this = this;
|
|
218
|
+
this._callbacks.forEach(function (callback) {
|
|
219
|
+
if (callback.data.target === target) {
|
|
220
|
+
_this._trigger(callback, arg);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Destroy the callbacks
|
|
226
|
+
*/
|
|
227
|
+
Callbacks.prototype.destroy = function () {
|
|
228
|
+
this.removeAll(true);
|
|
229
|
+
};
|
|
230
|
+
return Callbacks;
|
|
231
|
+
}());
|
|
232
|
+
exports.Callbacks = Callbacks;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Component = void 0;
|
|
19
|
+
var Module_1 = require("./Module");
|
|
20
|
+
/**
|
|
21
|
+
* A class for Components.
|
|
22
|
+
*/
|
|
23
|
+
var Component = /** @class */ (function (_super) {
|
|
24
|
+
__extends(Component, _super);
|
|
25
|
+
function Component() {
|
|
26
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Add a single plugin
|
|
30
|
+
*/
|
|
31
|
+
Component.prototype.addPlugin = function (plugin) {
|
|
32
|
+
if (typeof this._plugins === 'undefined') {
|
|
33
|
+
this._plugins = [];
|
|
34
|
+
}
|
|
35
|
+
this._plugins.push(plugin);
|
|
36
|
+
if (!plugin.inited) {
|
|
37
|
+
plugin.initPlugin(this);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Destroy all plugins
|
|
42
|
+
*/
|
|
43
|
+
Component.prototype._destroyPlugins = function () {
|
|
44
|
+
if (this._plugins) {
|
|
45
|
+
this._plugins.forEach(function (plugin) {
|
|
46
|
+
plugin.destroy();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
Component.prototype._destroy = function () {
|
|
51
|
+
_super.prototype._destroy.call(this);
|
|
52
|
+
this._destroyPlugins();
|
|
53
|
+
};
|
|
54
|
+
return Component;
|
|
55
|
+
}(Module_1.Module));
|
|
56
|
+
exports.Component = Component;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Module = void 0;
|
|
7
|
+
var vevet_dom_1 = require("vevet-dom");
|
|
8
|
+
var Callbacks_1 = require("./Callbacks");
|
|
9
|
+
var MutableProp_1 = require("./MutableProp");
|
|
10
|
+
var mergeWithoutArrays_1 = __importDefault(require("../utils/common/mergeWithoutArrays"));
|
|
11
|
+
var errors_1 = require("../utils/errors");
|
|
12
|
+
/**
|
|
13
|
+
* A class for modules.
|
|
14
|
+
*/
|
|
15
|
+
var Module = /** @class */ (function () {
|
|
16
|
+
/**
|
|
17
|
+
* @example
|
|
18
|
+
* const mod = new Module();
|
|
19
|
+
*/
|
|
20
|
+
function Module(
|
|
21
|
+
/**
|
|
22
|
+
* Properties on script start
|
|
23
|
+
*/
|
|
24
|
+
initialProp,
|
|
25
|
+
/**
|
|
26
|
+
* Defines if you need to call {@linkcode Module.init} at the constructor's end.
|
|
27
|
+
* If you want to add responsive properties, set this argument to FALSE.
|
|
28
|
+
*/
|
|
29
|
+
init) {
|
|
30
|
+
if (init === void 0) { init = true; }
|
|
31
|
+
/**
|
|
32
|
+
* If the module is initialized
|
|
33
|
+
*/
|
|
34
|
+
this._inited = false;
|
|
35
|
+
/**
|
|
36
|
+
* Viewport callbacks
|
|
37
|
+
*/
|
|
38
|
+
this._viewportCallbacks = [];
|
|
39
|
+
// set vars
|
|
40
|
+
if (window.vevetApp) {
|
|
41
|
+
this._app = window.vevetApp;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
errors_1.throwVevetAppError();
|
|
45
|
+
}
|
|
46
|
+
// set default vars
|
|
47
|
+
this._destroyed = false;
|
|
48
|
+
this._listeners = [];
|
|
49
|
+
// create callbacks
|
|
50
|
+
this._callbacks = new Callbacks_1.Callbacks();
|
|
51
|
+
// create mutable properties
|
|
52
|
+
var prop = mergeWithoutArrays_1.default(this._getDefaultProp(), initialProp || {});
|
|
53
|
+
this._mutableProp = new MutableProp_1.MutableProp(prop, this._onPropResponsive.bind(this), this._onPropChange.bind(this), this.name);
|
|
54
|
+
if (init) {
|
|
55
|
+
this.init();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get Default properties (should be extended)
|
|
60
|
+
*/
|
|
61
|
+
Module.prototype._getDefaultProp = function () {
|
|
62
|
+
return {
|
|
63
|
+
parent: false,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
Object.defineProperty(Module.prototype, "prop", {
|
|
67
|
+
/**
|
|
68
|
+
* Current properties
|
|
69
|
+
*/
|
|
70
|
+
get: function () {
|
|
71
|
+
return this._mutableProp.prop;
|
|
72
|
+
},
|
|
73
|
+
enumerable: false,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(Module.prototype, "callbacks", {
|
|
77
|
+
/**
|
|
78
|
+
* Module Callbacks
|
|
79
|
+
*/
|
|
80
|
+
get: function () {
|
|
81
|
+
return this._callbacks;
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(Module.prototype, "prefix", {
|
|
87
|
+
/**
|
|
88
|
+
* Module prefix
|
|
89
|
+
*/
|
|
90
|
+
get: function () {
|
|
91
|
+
return '';
|
|
92
|
+
},
|
|
93
|
+
enumerable: false,
|
|
94
|
+
configurable: true
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(Module.prototype, "name", {
|
|
97
|
+
/**
|
|
98
|
+
* Get module name
|
|
99
|
+
*/
|
|
100
|
+
get: function () {
|
|
101
|
+
return this.constructor.name;
|
|
102
|
+
},
|
|
103
|
+
enumerable: false,
|
|
104
|
+
configurable: true
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(Module.prototype, "inited", {
|
|
107
|
+
get: function () {
|
|
108
|
+
return this._inited;
|
|
109
|
+
},
|
|
110
|
+
enumerable: false,
|
|
111
|
+
configurable: true
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(Module.prototype, "destroyed", {
|
|
114
|
+
get: function () {
|
|
115
|
+
return this._destroyed;
|
|
116
|
+
},
|
|
117
|
+
enumerable: false,
|
|
118
|
+
configurable: true
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Add responsive rules
|
|
122
|
+
*/
|
|
123
|
+
Module.prototype.addResponsiveProp = function (rules) {
|
|
124
|
+
if (this._inited) {
|
|
125
|
+
throw new Error('Responsive properties cannot be added because the class instance is already initialized');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this._mutableProp.addResponsiveProp(rules);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Change module properties.
|
|
133
|
+
* @example
|
|
134
|
+
*
|
|
135
|
+
* // changing properties
|
|
136
|
+
* // let's imagine that the module has the following properties:
|
|
137
|
+
* prop = {
|
|
138
|
+
* name: 'module',
|
|
139
|
+
* cute: true
|
|
140
|
+
* };
|
|
141
|
+
* // we can change some properties in it: whether one or several properties
|
|
142
|
+
* // after the properties are changed, the method _onPropChange is called.
|
|
143
|
+
* module.changeProp({
|
|
144
|
+
* cute: false
|
|
145
|
+
* });
|
|
146
|
+
*/
|
|
147
|
+
Module.prototype.changeProp = function (prop) {
|
|
148
|
+
if (prop === void 0) { prop = {}; }
|
|
149
|
+
this._mutableProp.changeProp(prop);
|
|
150
|
+
this._callbacks.tbt('changeProp', false);
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* The method that is called on window resize and properties change.
|
|
154
|
+
*/
|
|
155
|
+
Module.prototype._onPropResponsive = function () {
|
|
156
|
+
this._onPropMutate();
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* The method that is called on properties change.
|
|
160
|
+
*/
|
|
161
|
+
Module.prototype._onPropChange = function (
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
163
|
+
changedProp) {
|
|
164
|
+
this._onPropMutate();
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The method that is called on properties change.
|
|
168
|
+
*/
|
|
169
|
+
Module.prototype._onPropMutate = function () { };
|
|
170
|
+
/**
|
|
171
|
+
* Initializes the class.
|
|
172
|
+
*/
|
|
173
|
+
Module.prototype.init = function () {
|
|
174
|
+
var _this = this;
|
|
175
|
+
// return if the module is already initialized
|
|
176
|
+
if (this._inited) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
this._inited = true;
|
|
180
|
+
// continue initializing
|
|
181
|
+
this._constructor();
|
|
182
|
+
this._setEvents();
|
|
183
|
+
// destroy the current module on parent destroy
|
|
184
|
+
if (this.prop.parent) {
|
|
185
|
+
this.prop.parent.addCallback('destroy', function () {
|
|
186
|
+
_this.destroy();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Extra constructor
|
|
192
|
+
*/
|
|
193
|
+
Module.prototype._constructor = function () {
|
|
194
|
+
// code
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Set events
|
|
198
|
+
*/
|
|
199
|
+
Module.prototype._setEvents = function () {
|
|
200
|
+
// code
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Add a viewport callback that will be removed on class destroy
|
|
204
|
+
* {@see Viewport}
|
|
205
|
+
*/
|
|
206
|
+
Module.prototype.addViewportCallback = function (target, func, data) {
|
|
207
|
+
if (data === void 0) { data = {
|
|
208
|
+
name: this.constructor.name,
|
|
209
|
+
}; }
|
|
210
|
+
var callback = this._app.viewport.add(target, func, data);
|
|
211
|
+
this._viewportCallbacks.push(callback);
|
|
212
|
+
return callback;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Add a module callback
|
|
216
|
+
* {@see Callbacks}
|
|
217
|
+
*/
|
|
218
|
+
Module.prototype.addCallback = function (target, func, data) {
|
|
219
|
+
if (data === void 0) { data = {}; }
|
|
220
|
+
var callback = this.callbacks.add(target, func, data);
|
|
221
|
+
return callback;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Add a DOM event listeners
|
|
225
|
+
*/
|
|
226
|
+
Module.prototype.addEventListeners = function (el, target, callback, options) {
|
|
227
|
+
var listener = vevet_dom_1.addEventListener(el, target, callback, options);
|
|
228
|
+
this._listeners.push(listener);
|
|
229
|
+
return listener;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Destroy the module
|
|
233
|
+
*/
|
|
234
|
+
Module.prototype.destroy = function () {
|
|
235
|
+
if (this.destroyed) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this._destroy();
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Destroy the module
|
|
242
|
+
*/
|
|
243
|
+
Module.prototype._destroy = function () {
|
|
244
|
+
// destroy callbacks
|
|
245
|
+
this._callbacks.tbt('destroy', false);
|
|
246
|
+
this._callbacks.destroy();
|
|
247
|
+
// destroy mutable properties
|
|
248
|
+
this._mutableProp.destroy();
|
|
249
|
+
// destroy viewport callbacks
|
|
250
|
+
this._viewportCallbacks.forEach(function (callback) {
|
|
251
|
+
callback.remove();
|
|
252
|
+
});
|
|
253
|
+
// destroy all listeners
|
|
254
|
+
this._listeners.forEach(function (listener) {
|
|
255
|
+
listener.remove();
|
|
256
|
+
});
|
|
257
|
+
// events
|
|
258
|
+
this._destroyed = true;
|
|
259
|
+
};
|
|
260
|
+
return Module;
|
|
261
|
+
}());
|
|
262
|
+
exports.Module = Module;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MutableProp = void 0;
|
|
4
|
+
var common_1 = require("../utils/common");
|
|
5
|
+
/**
|
|
6
|
+
* A class for creating mutable properties that can change on window resize. <br><br>
|
|
7
|
+
*
|
|
8
|
+
* There are two ways to change properties:
|
|
9
|
+
* <ul>
|
|
10
|
+
* <li>
|
|
11
|
+
* To set a resize-listener on window (or use {@linkcode Viewport}).
|
|
12
|
+
* When the window is resized, change the properties with the help of
|
|
13
|
+
* {@linkcode MutableProp.changeProp}</li>
|
|
14
|
+
* <li>
|
|
15
|
+
* The second way is to use the MutableProp and add responsive properties
|
|
16
|
+
* with help of {@linkcode MutableProp.addResponsiveProp}.</li>
|
|
17
|
+
* </ul>
|
|
18
|
+
*/
|
|
19
|
+
var MutableProp = /** @class */ (function () {
|
|
20
|
+
/**
|
|
21
|
+
* @example
|
|
22
|
+
* const static = {
|
|
23
|
+
* myProp: true,
|
|
24
|
+
* };
|
|
25
|
+
* const responsive = [
|
|
26
|
+
* {
|
|
27
|
+
* breakpoint: 'm',
|
|
28
|
+
* settings: {
|
|
29
|
+
* myProp: false
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ];
|
|
33
|
+
* const prop = new MutableProp(static, responsive);
|
|
34
|
+
*/
|
|
35
|
+
function MutableProp(
|
|
36
|
+
/**
|
|
37
|
+
* The properties that were set while initialization.
|
|
38
|
+
* These properties do not change throughout time.
|
|
39
|
+
*/
|
|
40
|
+
_initProp,
|
|
41
|
+
/**
|
|
42
|
+
* A callback that is launched when properties are changed on window resize
|
|
43
|
+
*/
|
|
44
|
+
_onResponsive,
|
|
45
|
+
/**
|
|
46
|
+
* A callback that is launched when properties are changed
|
|
47
|
+
* through {@linkcode MutableProp.changeProp}
|
|
48
|
+
*/
|
|
49
|
+
_onChange,
|
|
50
|
+
/**
|
|
51
|
+
* Name of the responsive properties.
|
|
52
|
+
*/
|
|
53
|
+
_name) {
|
|
54
|
+
if (_onResponsive === void 0) { _onResponsive = function () { }; }
|
|
55
|
+
if (_onChange === void 0) { _onChange = function () { }; }
|
|
56
|
+
if (_name === void 0) { _name = 'Responsive Prop'; }
|
|
57
|
+
this._initProp = _initProp;
|
|
58
|
+
this._onResponsive = _onResponsive;
|
|
59
|
+
this._onChange = _onChange;
|
|
60
|
+
this._name = _name;
|
|
61
|
+
/**
|
|
62
|
+
* A set of responsive rules
|
|
63
|
+
*/
|
|
64
|
+
this._responsiveRules = [];
|
|
65
|
+
this._app = window.vevetApp;
|
|
66
|
+
this._refProp = common_1.mergeWithoutArrays({}, _initProp);
|
|
67
|
+
this._prop = common_1.mergeWithoutArrays({}, _initProp);
|
|
68
|
+
}
|
|
69
|
+
Object.defineProperty(MutableProp.prototype, "prop", {
|
|
70
|
+
/**
|
|
71
|
+
* Get current properties
|
|
72
|
+
*/
|
|
73
|
+
get: function () {
|
|
74
|
+
return this._prop;
|
|
75
|
+
},
|
|
76
|
+
enumerable: false,
|
|
77
|
+
configurable: true
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Add responsive rules
|
|
81
|
+
*/
|
|
82
|
+
MutableProp.prototype.addResponsiveProp = function (rules) {
|
|
83
|
+
this._responsiveRules.push(rules);
|
|
84
|
+
// add event on resize
|
|
85
|
+
if (typeof this._viewportCallback === 'undefined') {
|
|
86
|
+
this._viewportCallback = this._app.viewport.add('w', this._responseProp.bind(this, true), {
|
|
87
|
+
name: this._name,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// change properties according to the responsive prop
|
|
91
|
+
this._responseProp();
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Change properties according to the "responsive" settings
|
|
95
|
+
* @param onResize - If the method was called on window resize.
|
|
96
|
+
*/
|
|
97
|
+
MutableProp.prototype._responseProp = function (onResize) {
|
|
98
|
+
if (onResize === void 0) { onResize = false; }
|
|
99
|
+
var responsiveProp = this._responsiveRules;
|
|
100
|
+
// get sizes
|
|
101
|
+
var app = this._app;
|
|
102
|
+
var viewport = app.viewport;
|
|
103
|
+
var width = viewport.width;
|
|
104
|
+
var newProp = false;
|
|
105
|
+
var statProp = common_1.mergeWithoutArrays({}, this._refProp);
|
|
106
|
+
// go through all breakpoints
|
|
107
|
+
// and check if a proper breakpoint exists
|
|
108
|
+
responsiveProp.forEach(function (prop) {
|
|
109
|
+
// copy settings
|
|
110
|
+
var settings = prop.settings, breakpoint = prop.breakpoint;
|
|
111
|
+
// if the breakpoint is a number
|
|
112
|
+
if (typeof breakpoint === 'number') {
|
|
113
|
+
if (width <= prop.breakpoint) {
|
|
114
|
+
newProp = common_1.mergeWithoutArrays(statProp, settings);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (typeof breakpoint === 'string') {
|
|
118
|
+
var string = breakpoint.toLowerCase();
|
|
119
|
+
// viewport size
|
|
120
|
+
if ((string === 'd' && viewport.isDesktop)
|
|
121
|
+
|| (string === 't' && viewport.isTablet)
|
|
122
|
+
|| (string === 'p' && viewport.isPhone)) {
|
|
123
|
+
newProp = common_1.mergeWithoutArrays(statProp, settings);
|
|
124
|
+
}
|
|
125
|
+
// device type
|
|
126
|
+
if ((string === 'phone' && app.isPhone)
|
|
127
|
+
|| (string === 'tablet' && app.isTablet)
|
|
128
|
+
|| (string === 'mobile' && app.isMobile)) {
|
|
129
|
+
newProp = common_1.mergeWithoutArrays(statProp, settings);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
// if there's no breakpoint, restore the props
|
|
134
|
+
if (!newProp) {
|
|
135
|
+
this._prop = common_1.mergeWithoutArrays(this._prop, this._refProp);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// otherwise, change the properties
|
|
139
|
+
this._prop = common_1.mergeWithoutArrays(this._prop, newProp);
|
|
140
|
+
}
|
|
141
|
+
// responsive callback
|
|
142
|
+
if (onResize) {
|
|
143
|
+
this._onResponsive();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* This method allows you to change the properties manually.
|
|
148
|
+
*/
|
|
149
|
+
MutableProp.prototype.changeProp = function (prop) {
|
|
150
|
+
this._prop = common_1.mergeWithoutArrays(this._prop, prop);
|
|
151
|
+
this._refProp = common_1.mergeWithoutArrays(this._refProp, prop);
|
|
152
|
+
// change prop callback
|
|
153
|
+
this._onChange(prop);
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Destroy the responsive properties.
|
|
157
|
+
*/
|
|
158
|
+
MutableProp.prototype.destroy = function () {
|
|
159
|
+
if (this._viewportCallback) {
|
|
160
|
+
this._viewportCallback.remove();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
return MutableProp;
|
|
164
|
+
}());
|
|
165
|
+
exports.MutableProp = MutableProp;
|