vevet 2.2.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/build/cdn/index.js +1 -1
  2. package/build/cjs/app/events/Viewport.js +17 -6
  3. package/build/cjs/components/scroll/section/ScrollSectionProgress.js +261 -0
  4. package/build/cjs/index.js +5 -1
  5. package/build/cjs/utils/scroll/getScrollValues.js +20 -0
  6. package/build/cjs/utils/scroll/index.js +12 -0
  7. package/build/cjs/utils/scroll/scrollTo.js +41 -0
  8. package/build/cjs/utils/scroll/scrollToElement.js +39 -0
  9. package/build/cjs/utils/scroll/to.js +41 -0
  10. package/build/es/app/events/Viewport.js +16 -6
  11. package/build/es/components/scroll/section/ScrollSectionProgress.js +181 -0
  12. package/build/es/index.js +4 -1
  13. package/build/es/utils/scroll/getScrollValues.js +16 -0
  14. package/build/es/utils/scroll/index.js +4 -0
  15. package/build/es/utils/scroll/scrollTo.js +34 -0
  16. package/build/es/utils/scroll/scrollToElement.js +32 -0
  17. package/build/es/utils/scroll/to.js +34 -0
  18. package/build/types/app/events/Viewport.d.ts +9 -1
  19. package/build/types/app/events/Viewport.d.ts.map +1 -1
  20. package/build/types/components/scroll/section/ScrollSectionProgress.d.ts +131 -0
  21. package/build/types/components/scroll/section/ScrollSectionProgress.d.ts.map +1 -0
  22. package/build/types/components/scroll/types.d.ts +2 -5
  23. package/build/types/components/scroll/types.d.ts.map +1 -1
  24. package/build/types/index.d.ts +4 -1
  25. package/build/types/index.d.ts.map +1 -1
  26. package/build/types/utils/scroll/getScrollValues.d.ts +9 -0
  27. package/build/types/utils/scroll/getScrollValues.d.ts.map +1 -0
  28. package/build/types/utils/scroll/index.d.ts +5 -0
  29. package/build/types/utils/scroll/index.d.ts.map +1 -0
  30. package/build/types/utils/scroll/scrollTo.d.ts +28 -0
  31. package/build/types/utils/scroll/scrollTo.d.ts.map +1 -0
  32. package/build/types/utils/scroll/scrollToElement.d.ts +32 -0
  33. package/build/types/utils/scroll/scrollToElement.d.ts.map +1 -0
  34. package/build/types/utils/scroll/to.d.ts +28 -0
  35. package/build/types/utils/scroll/to.d.ts.map +1 -0
  36. package/build/types/utils/types/general.d.ts +6 -0
  37. package/build/types/utils/types/general.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/ts/app/events/Viewport.ts +18 -6
  40. package/src/ts/components/scroll/section/ScrollSectionProgress.ts +344 -0
  41. package/src/ts/components/scroll/types.ts +3 -5
  42. package/src/ts/index.ts +4 -0
  43. package/src/ts/utils/scroll/getScrollValues.ts +20 -0
  44. package/src/ts/utils/scroll/index.ts +9 -0
  45. package/src/ts/utils/scroll/scrollTo.ts +65 -0
  46. package/src/ts/utils/scroll/scrollToElement.ts +74 -0
  47. package/src/ts/utils/types/general.ts +7 -0
@@ -263,7 +263,12 @@ var Viewport = /** @class */ (function (_super) {
263
263
  /**
264
264
  * Launch callbacks on resize.
265
265
  */
266
- Viewport.prototype._onResize = function () {
266
+ Viewport.prototype._onResize = function (
267
+ /**
268
+ * force all callbacks
269
+ */
270
+ force) {
271
+ if (force === void 0) { force = false; }
267
272
  // copy previous values
268
273
  var prevWidth = this._prevSize.w;
269
274
  var prevHeight = this._prevSize.h;
@@ -278,29 +283,35 @@ var Viewport = /** @class */ (function (_super) {
278
283
  orientationChanged: (width > height) !== (prevWidth > prevHeight),
279
284
  };
280
285
  // only when width is changed
281
- if (width !== prevWidth && height === prevHeight) {
286
+ if (force || (width !== prevWidth && height === prevHeight)) {
282
287
  this.tbt('w_', changes);
283
288
  }
284
289
  // only when height is changed
285
- if (height !== prevHeight && width === prevWidth) {
290
+ if (force || (height !== prevHeight && width === prevWidth)) {
286
291
  this.tbt('h_', changes);
287
292
  }
288
293
  // when height & width are changed
289
- if (width !== prevWidth && height !== prevHeight) {
294
+ if (force || (width !== prevWidth && height !== prevHeight)) {
290
295
  this.tbt('wh', changes);
291
296
  this.tbt('hw', changes);
292
297
  }
293
298
  // when width is changed
294
- if (width !== prevWidth) {
299
+ if (force || width !== prevWidth) {
295
300
  this.tbt('w', changes);
296
301
  }
297
302
  // when height changed
298
- if (height !== prevHeight) {
303
+ if (force || height !== prevHeight) {
299
304
  this.tbt('h', changes);
300
305
  }
301
306
  // on any change
302
307
  this.tbt('', changes);
303
308
  };
309
+ /**
310
+ * Force launching all callbacks
311
+ */
312
+ Viewport.prototype.forceResize = function () {
313
+ this._onResize(true);
314
+ };
304
315
  return Viewport;
305
316
  }(Callbacks_1.Callbacks));
306
317
  exports.Viewport = Viewport;
@@ -0,0 +1,261 @@
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
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.ScrollSectionProgress = void 0;
33
+ var vevet_dom_1 = require("vevet-dom");
34
+ var onScroll_1 = __importDefault(require("../../../utils/listeners/onScroll"));
35
+ var Component_1 = require("../../../base/Component");
36
+ var clampScope_1 = __importDefault(require("../../../utils/math/clampScope"));
37
+ var getScrollValues_1 = __importDefault(require("../../../utils/scroll/getScrollValues"));
38
+ /**
39
+ * Elements into viewport
40
+ */
41
+ var ScrollSectionProgress = /** @class */ (function (_super) {
42
+ __extends(ScrollSectionProgress, _super);
43
+ function ScrollSectionProgress(initialProp, init) {
44
+ if (init === void 0) { init = true; }
45
+ var _this = _super.call(this, initialProp, false) || this;
46
+ // get scroll container
47
+ if (typeof _this.prop.container === 'string') {
48
+ _this._scrollContainer = (0, vevet_dom_1.selectOne)(_this.prop.container);
49
+ }
50
+ else {
51
+ _this._scrollContainer = _this.prop.container;
52
+ }
53
+ // get section element
54
+ if (typeof _this.prop.section === 'string') {
55
+ _this._section = (0, vevet_dom_1.selectOne)(_this.prop.section);
56
+ }
57
+ else {
58
+ _this._section = _this.prop.section;
59
+ }
60
+ // set defaults
61
+ _this._progress = -0.001;
62
+ _this._scopeScroll = [0, 0];
63
+ _this._scopeIn = [0, 0];
64
+ _this._scopeMove = [0, 0];
65
+ _this._scopeOut = [0, 0];
66
+ // initialize the class
67
+ if (init) {
68
+ _this.init();
69
+ }
70
+ return _this;
71
+ }
72
+ ScrollSectionProgress.prototype._getDefaultProp = function () {
73
+ return __assign(__assign({}, _super.prototype._getDefaultProp.call(this)), { container: window, updateOnResize: '', resizeTimeout: 0 });
74
+ };
75
+ Object.defineProperty(ScrollSectionProgress.prototype, "scrollContainer", {
76
+ get: function () {
77
+ return this._scrollContainer;
78
+ },
79
+ enumerable: false,
80
+ configurable: true
81
+ });
82
+ Object.defineProperty(ScrollSectionProgress.prototype, "section", {
83
+ get: function () {
84
+ return this._section;
85
+ },
86
+ enumerable: false,
87
+ configurable: true
88
+ });
89
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeScroll", {
90
+ get: function () {
91
+ return this._scopeScroll;
92
+ },
93
+ enumerable: false,
94
+ configurable: true
95
+ });
96
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeIn", {
97
+ get: function () {
98
+ return this._scopeIn;
99
+ },
100
+ enumerable: false,
101
+ configurable: true
102
+ });
103
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeMove", {
104
+ get: function () {
105
+ return this._scopeMove;
106
+ },
107
+ enumerable: false,
108
+ configurable: true
109
+ });
110
+ Object.defineProperty(ScrollSectionProgress.prototype, "scopeOut", {
111
+ get: function () {
112
+ return this._scopeOut;
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ Object.defineProperty(ScrollSectionProgress.prototype, "progress", {
118
+ /**
119
+ * Global progress
120
+ */
121
+ get: function () {
122
+ return this._progress;
123
+ },
124
+ set: function (val) {
125
+ this._progress = val;
126
+ },
127
+ enumerable: false,
128
+ configurable: true
129
+ });
130
+ ScrollSectionProgress.prototype.init = function () {
131
+ _super.prototype.init.call(this);
132
+ };
133
+ // Set Module Events
134
+ ScrollSectionProgress.prototype._setEvents = function () {
135
+ var _this = this;
136
+ _super.prototype._setEvents.call(this);
137
+ // set resize events
138
+ this.addViewportCallback(this.prop.viewportTarget, function () {
139
+ _this.resize();
140
+ }, {
141
+ timeout: this.prop.resizeTimeout,
142
+ });
143
+ // resize on page loaded
144
+ this._loadedEvent = this._app.onPageLoaded();
145
+ this._loadedEvent.then(function () {
146
+ _this.resize();
147
+ }).catch(function () { });
148
+ // set scroll events
149
+ this._scrollEvent = (0, onScroll_1.default)({
150
+ container: this.prop.container,
151
+ callback: this._handleScroll.bind(this),
152
+ });
153
+ };
154
+ ScrollSectionProgress.prototype._onPropMutate = function () {
155
+ _super.prototype._onPropMutate.call(this);
156
+ this.resize();
157
+ };
158
+ Object.defineProperty(ScrollSectionProgress.prototype, "progressIn", {
159
+ /**
160
+ * 'in' progress
161
+ */
162
+ get: function () {
163
+ return (0, clampScope_1.default)(this.progress, this.scopeIn) || 0;
164
+ },
165
+ enumerable: false,
166
+ configurable: true
167
+ });
168
+ Object.defineProperty(ScrollSectionProgress.prototype, "progressOut", {
169
+ /**
170
+ * 'out' progress
171
+ */
172
+ get: function () {
173
+ return (0, clampScope_1.default)(this.progress, this.scopeOut) || 0;
174
+ },
175
+ enumerable: false,
176
+ configurable: true
177
+ });
178
+ Object.defineProperty(ScrollSectionProgress.prototype, "progressMove", {
179
+ /**
180
+ * 'move' progress
181
+ */
182
+ get: function () {
183
+ return (0, clampScope_1.default)(this.progress, this.scopeMove) || 0;
184
+ },
185
+ enumerable: false,
186
+ configurable: true
187
+ });
188
+ /**
189
+ * Handle scroll event
190
+ */
191
+ ScrollSectionProgress.prototype._handleScroll = function () {
192
+ // calculate scopes
193
+ var scrollData = (0, getScrollValues_1.default)(this.scrollContainer);
194
+ if (!scrollData) {
195
+ return;
196
+ }
197
+ this._render(scrollData);
198
+ };
199
+ /**
200
+ * Resize the scene
201
+ */
202
+ ScrollSectionProgress.prototype.resize = function () {
203
+ // calculate scopes
204
+ var scrollData = (0, getScrollValues_1.default)(this.scrollContainer);
205
+ if (!scrollData) {
206
+ return;
207
+ }
208
+ // get sizes
209
+ var bounding = this.section.getBoundingClientRect();
210
+ var vHeight = this._app.viewport.height;
211
+ // calculate scroll scope
212
+ var inStart = scrollData.scrollTop + bounding.top - vHeight;
213
+ var moveEnd = scrollData.scrollTop + bounding.top + bounding.height;
214
+ var scrollLine = moveEnd - inStart;
215
+ this._scopeScroll = [inStart, moveEnd];
216
+ // calculate scopes
217
+ this._scopeIn = [0, vHeight / scrollLine];
218
+ this._scopeOut = [1 - vHeight / scrollLine, 1];
219
+ this._scopeMove = [this._scopeIn[1], this._scopeOut[0]];
220
+ // launch callbacks
221
+ this.callbacks.tbt('resize', false);
222
+ // render the scene
223
+ this._render(scrollData, true);
224
+ };
225
+ /**
226
+ * Render the scene
227
+ */
228
+ ScrollSectionProgress.prototype._render = function (scrollData, force) {
229
+ if (force === void 0) { force = false; }
230
+ var canRender = this._canRender(scrollData, force);
231
+ if (!canRender) {
232
+ return;
233
+ }
234
+ this.callbacks.tbt('render', false);
235
+ };
236
+ /**
237
+ * Check if the section can be rendered
238
+ */
239
+ ScrollSectionProgress.prototype._canRender = function (scrollData, force) {
240
+ if (force === void 0) { force = false; }
241
+ if (!scrollData) {
242
+ return false;
243
+ }
244
+ var scrollTop = scrollData.scrollTop;
245
+ var prevProgress = this.progress;
246
+ var progress = (0, clampScope_1.default)(scrollTop, [this._scopeScroll[0], this._scopeScroll[1]]) || 0;
247
+ this.progress = progress;
248
+ return force || (progress !== prevProgress);
249
+ };
250
+ /**
251
+ * Destroy the module
252
+ */
253
+ ScrollSectionProgress.prototype._destroy = function () {
254
+ var _a, _b;
255
+ _super.prototype._destroy.call(this);
256
+ (_a = this._scrollEvent) === null || _a === void 0 ? void 0 : _a.remove();
257
+ (_b = this._loadedEvent) === null || _b === void 0 ? void 0 : _b.cancel();
258
+ };
259
+ return ScrollSectionProgress;
260
+ }(Component_1.Component));
261
+ exports.ScrollSectionProgress = ScrollSectionProgress;
@@ -19,10 +19,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.CustomCursor = exports.SplitText = exports.SmoothScrollDragPlugin = exports.SmoothScrollKeyboardPlugin = exports.ScrollView = exports.ScrollEventsBase = exports.ScrollBar = exports.SmoothScroll = exports.Ctx2DPrerender = exports.Ctx2D = exports.DraggerDirection = exports.DraggerMove = exports.Dragger = exports.ProgressPreloader = exports.Preloader = exports.Timeline = exports.StaticTimeline = exports.AnimationFrame = exports.WheelHandler = exports.Page = exports.Plugin = exports.Component = exports.Module = exports.MutableProp = exports.Callbacks = exports.PageLoad = exports.Viewport = exports.Application = exports.GeneralTypes = exports.utils = void 0;
22
+ exports.CustomCursor = exports.SplitText = exports.ScrollSectionProgress = exports.SmoothScrollDragPlugin = exports.SmoothScrollKeyboardPlugin = exports.ScrollView = exports.ScrollEventsBase = exports.ScrollBar = exports.SmoothScroll = exports.Ctx2DPrerender = exports.Ctx2D = exports.DraggerDirection = exports.DraggerMove = exports.Dragger = exports.ProgressPreloader = exports.Preloader = exports.Timeline = exports.StaticTimeline = exports.AnimationFrame = exports.WheelHandler = exports.Page = exports.Plugin = exports.Component = exports.Module = exports.MutableProp = exports.Callbacks = exports.PageLoad = exports.Viewport = exports.Application = exports.GeneralTypes = exports.utils = void 0;
23
23
  var common = __importStar(require("./utils/common"));
24
24
  var listeners = __importStar(require("./utils/listeners"));
25
25
  var math = __importStar(require("./utils/math"));
26
+ var scroll = __importStar(require("./utils/scroll"));
26
27
  var GeneralTypes = __importStar(require("./utils/types/general"));
27
28
  exports.GeneralTypes = GeneralTypes;
28
29
  var Application_1 = require("./app/Application");
@@ -77,6 +78,8 @@ var SmoothScrollKeyboardPlugin_1 = require("./components/scroll/plugins/SmoothSc
77
78
  Object.defineProperty(exports, "SmoothScrollKeyboardPlugin", { enumerable: true, get: function () { return SmoothScrollKeyboardPlugin_1.SmoothScrollKeyboardPlugin; } });
78
79
  var SmoothScrollDragPlugin_1 = require("./components/scroll/plugins/SmoothScrollDragPlugin");
79
80
  Object.defineProperty(exports, "SmoothScrollDragPlugin", { enumerable: true, get: function () { return SmoothScrollDragPlugin_1.SmoothScrollDragPlugin; } });
81
+ var ScrollSectionProgress_1 = require("./components/scroll/section/ScrollSectionProgress");
82
+ Object.defineProperty(exports, "ScrollSectionProgress", { enumerable: true, get: function () { return ScrollSectionProgress_1.ScrollSectionProgress; } });
80
83
  var SplitText_1 = require("./components/text/SplitText");
81
84
  Object.defineProperty(exports, "SplitText", { enumerable: true, get: function () { return SplitText_1.SplitText; } });
82
85
  var CustomCursor_1 = require("./components/cursor/CustomCursor");
@@ -85,5 +88,6 @@ var utils = {
85
88
  common: common,
86
89
  listeners: listeners,
87
90
  math: math,
91
+ scroll: scroll,
88
92
  };
89
93
  exports.utils = utils;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Get scroll values of a certain element
5
+ */
6
+ function getScrollValues(selector) {
7
+ if (selector === void 0) { selector = window; }
8
+ if (selector) {
9
+ var scrollTop = selector instanceof Window
10
+ ? selector.pageYOffset : selector.scrollTop;
11
+ var scrollLeft = selector instanceof Window
12
+ ? selector.pageXOffset : selector.scrollLeft;
13
+ return {
14
+ scrollTop: scrollTop,
15
+ scrollLeft: scrollLeft,
16
+ };
17
+ }
18
+ return undefined;
19
+ }
20
+ exports.default = getScrollValues;
@@ -0,0 +1,12 @@
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.toElement = exports.to = exports.getValues = void 0;
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ exports.getValues = getScrollValues_1.default;
9
+ var scrollTo_1 = __importDefault(require("./scrollTo"));
10
+ exports.to = scrollTo_1.default;
11
+ var scrollToElement_1 = __importDefault(require("./scrollToElement"));
12
+ exports.toElement = scrollToElement_1.default;
@@ -0,0 +1,41 @@
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
+ var Timeline_1 = require("../../components/timeline/Timeline");
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ /**
9
+ * Scroll to coordinates
10
+ */
11
+ function scrollTo(_a) {
12
+ var _b = _a.container, container = _b === void 0 ? window : _b, _c = _a.top, top = _c === void 0 ? 0 : _c, _d = _a.left, left = _d === void 0 ? 0 : _d, _e = _a.duration, duration = _e === void 0 ? 250 : _e;
13
+ return new Promise(function (resolve, reject) {
14
+ // save start values
15
+ var startValues = (0, getScrollValues_1.default)(container);
16
+ if (startValues) {
17
+ // create animation
18
+ var timeline = new Timeline_1.Timeline({
19
+ duration: duration,
20
+ });
21
+ timeline.addCallback('progress', function (data) {
22
+ if (container) {
23
+ container.scrollTo({
24
+ top: startValues.scrollTop
25
+ + (top - startValues.scrollTop) * data.easing,
26
+ left: startValues.scrollLeft
27
+ + (left - startValues.scrollLeft) * data.easing,
28
+ behavior: 'auto',
29
+ });
30
+ }
31
+ });
32
+ timeline.addCallback('end', function () {
33
+ resolve();
34
+ });
35
+ timeline.play();
36
+ return;
37
+ }
38
+ reject();
39
+ });
40
+ }
41
+ exports.default = scrollTo;
@@ -0,0 +1,39 @@
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
+ var vevet_dom_1 = require("vevet-dom");
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ var clamp_1 = __importDefault(require("../math/clamp"));
9
+ var scrollTo_1 = __importDefault(require("./scrollTo"));
10
+ /**
11
+ * Scroll to element
12
+ */
13
+ function scrollToElement(_a) {
14
+ var _b = _a.container, container = _b === void 0 ? window : _b, el = _a.el, _c = _a.top, top = _c === void 0 ? 0 : _c, _d = _a.left, left = _d === void 0 ? 0 : _d, _e = _a.duration, duration = _e === void 0 ? 250 : _e;
15
+ return new Promise(function (resolve, reject) {
16
+ var startValues = (0, getScrollValues_1.default)(container);
17
+ if (startValues) {
18
+ var element = (0, vevet_dom_1.selectOne)(el);
19
+ if (element) {
20
+ var bounding = element.getBoundingClientRect();
21
+ var toTop = (0, clamp_1.default)(bounding.top + startValues.scrollTop - top, [0, Infinity]);
22
+ var toLeft = (0, clamp_1.default)(bounding.left + startValues.scrollLeft - left, [0, Infinity]);
23
+ (0, scrollTo_1.default)({
24
+ container: container,
25
+ top: toTop,
26
+ left: toLeft,
27
+ duration: duration,
28
+ }).then(function () {
29
+ resolve();
30
+ }).catch(function () {
31
+ reject();
32
+ });
33
+ }
34
+ return;
35
+ }
36
+ reject();
37
+ });
38
+ }
39
+ exports.default = scrollToElement;
@@ -0,0 +1,41 @@
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
+ var Timeline_1 = require("../../components/timeline/Timeline");
7
+ var getScrollValues_1 = __importDefault(require("./getScrollValues"));
8
+ /**
9
+ * Scroll to coordinates
10
+ */
11
+ function scrollTo(_a) {
12
+ var _b = _a.container, container = _b === void 0 ? window : _b, _c = _a.top, top = _c === void 0 ? 0 : _c, _d = _a.left, left = _d === void 0 ? 0 : _d, _e = _a.duration, duration = _e === void 0 ? 250 : _e;
13
+ return new Promise(function (resolve, reject) {
14
+ // save start values
15
+ var startValues = (0, getScrollValues_1.default)(container);
16
+ if (startValues) {
17
+ // create animation
18
+ var timeline = new Timeline_1.Timeline({
19
+ duration: duration,
20
+ });
21
+ timeline.addCallback('progress', function (data) {
22
+ if (container) {
23
+ container.scrollTo({
24
+ top: startValues.scrollTop
25
+ + (top - startValues.scrollTop) * data.easing,
26
+ left: startValues.scrollLeft
27
+ + (left - startValues.scrollLeft) * data.easing,
28
+ behavior: 'auto',
29
+ });
30
+ }
31
+ });
32
+ timeline.addCallback('end', function () {
33
+ resolve();
34
+ });
35
+ timeline.play();
36
+ return;
37
+ }
38
+ reject();
39
+ });
40
+ }
41
+ exports.default = scrollTo;
@@ -194,7 +194,11 @@ export class Viewport extends Callbacks {
194
194
  /**
195
195
  * Launch callbacks on resize.
196
196
  */
197
- _onResize() {
197
+ _onResize(
198
+ /**
199
+ * force all callbacks
200
+ */
201
+ force = false) {
198
202
  // copy previous values
199
203
  const prevWidth = this._prevSize.w;
200
204
  const prevHeight = this._prevSize.h;
@@ -209,27 +213,33 @@ export class Viewport extends Callbacks {
209
213
  orientationChanged: (width > height) !== (prevWidth > prevHeight),
210
214
  };
211
215
  // only when width is changed
212
- if (width !== prevWidth && height === prevHeight) {
216
+ if (force || (width !== prevWidth && height === prevHeight)) {
213
217
  this.tbt('w_', changes);
214
218
  }
215
219
  // only when height is changed
216
- if (height !== prevHeight && width === prevWidth) {
220
+ if (force || (height !== prevHeight && width === prevWidth)) {
217
221
  this.tbt('h_', changes);
218
222
  }
219
223
  // when height & width are changed
220
- if (width !== prevWidth && height !== prevHeight) {
224
+ if (force || (width !== prevWidth && height !== prevHeight)) {
221
225
  this.tbt('wh', changes);
222
226
  this.tbt('hw', changes);
223
227
  }
224
228
  // when width is changed
225
- if (width !== prevWidth) {
229
+ if (force || width !== prevWidth) {
226
230
  this.tbt('w', changes);
227
231
  }
228
232
  // when height changed
229
- if (height !== prevHeight) {
233
+ if (force || height !== prevHeight) {
230
234
  this.tbt('h', changes);
231
235
  }
232
236
  // on any change
233
237
  this.tbt('', changes);
234
238
  }
239
+ /**
240
+ * Force launching all callbacks
241
+ */
242
+ forceResize() {
243
+ this._onResize(true);
244
+ }
235
245
  }