vevet 2.3.0 → 2.4.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.
- package/build/cdn/index.js +1 -1
- package/build/cjs/index.js +2 -0
- package/build/cjs/utils/scroll/getScrollValues.js +20 -0
- package/build/cjs/utils/scroll/index.js +12 -0
- package/build/cjs/utils/scroll/scrollTo.js +41 -0
- package/build/cjs/utils/scroll/scrollToElement.js +39 -0
- package/build/cjs/utils/scroll/to.js +41 -0
- package/build/es/index.js +2 -0
- package/build/es/utils/scroll/getScrollValues.js +16 -0
- package/build/es/utils/scroll/index.js +4 -0
- package/build/es/utils/scroll/scrollTo.js +34 -0
- package/build/es/utils/scroll/scrollToElement.js +32 -0
- package/build/es/utils/scroll/to.js +34 -0
- package/build/types/components/scroll/types.d.ts +2 -5
- package/build/types/components/scroll/types.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/utils/scroll/getScrollValues.d.ts +9 -0
- package/build/types/utils/scroll/getScrollValues.d.ts.map +1 -0
- package/build/types/utils/scroll/index.d.ts +5 -0
- package/build/types/utils/scroll/index.d.ts.map +1 -0
- package/build/types/utils/scroll/scrollTo.d.ts +28 -0
- package/build/types/utils/scroll/scrollTo.d.ts.map +1 -0
- package/build/types/utils/scroll/scrollToElement.d.ts +32 -0
- package/build/types/utils/scroll/scrollToElement.d.ts.map +1 -0
- package/build/types/utils/scroll/to.d.ts +28 -0
- package/build/types/utils/scroll/to.d.ts.map +1 -0
- package/build/types/utils/types/general.d.ts +6 -0
- package/build/types/utils/types/general.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ts/components/scroll/types.ts +3 -5
- package/src/ts/index.ts +2 -0
- package/src/ts/utils/scroll/getScrollValues.ts +20 -0
- package/src/ts/utils/scroll/index.ts +9 -0
- package/src/ts/utils/scroll/scrollTo.ts +65 -0
- package/src/ts/utils/scroll/scrollToElement.ts +74 -0
- package/src/ts/utils/types/general.ts +7 -0
package/build/cjs/index.js
CHANGED
|
@@ -23,6 +23,7 @@ exports.CustomCursor = exports.SplitText = exports.SmoothScrollDragPlugin = expo
|
|
|
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");
|
|
@@ -85,5 +86,6 @@ var utils = {
|
|
|
85
86
|
common: common,
|
|
86
87
|
listeners: listeners,
|
|
87
88
|
math: math,
|
|
89
|
+
scroll: scroll,
|
|
88
90
|
};
|
|
89
91
|
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;
|
package/build/es/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as common from './utils/common';
|
|
2
2
|
import * as listeners from './utils/listeners';
|
|
3
3
|
import * as math from './utils/math';
|
|
4
|
+
import * as scroll from './utils/scroll';
|
|
4
5
|
import * as GeneralTypes from './utils/types/general';
|
|
5
6
|
import { Application } from './app/Application';
|
|
6
7
|
import { Viewport } from './app/events/Viewport';
|
|
@@ -34,5 +35,6 @@ const utils = {
|
|
|
34
35
|
common,
|
|
35
36
|
listeners,
|
|
36
37
|
math,
|
|
38
|
+
scroll,
|
|
37
39
|
};
|
|
38
40
|
export { utils, GeneralTypes, Application, Viewport, PageLoad, Callbacks, MutableProp, Module, Component, Plugin, Page, WheelHandler, AnimationFrame, StaticTimeline, Timeline, Preloader, ProgressPreloader, Dragger, DraggerMove, DraggerDirection, Ctx2D, Ctx2DPrerender, SmoothScroll, ScrollBar, ScrollEventsBase, ScrollView, SmoothScrollKeyboardPlugin, SmoothScrollDragPlugin, SplitText, CustomCursor, };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get scroll values of a certain element
|
|
3
|
+
*/
|
|
4
|
+
export default function getScrollValues(selector = window) {
|
|
5
|
+
if (selector) {
|
|
6
|
+
const scrollTop = selector instanceof Window
|
|
7
|
+
? selector.pageYOffset : selector.scrollTop;
|
|
8
|
+
const scrollLeft = selector instanceof Window
|
|
9
|
+
? selector.pageXOffset : selector.scrollLeft;
|
|
10
|
+
return {
|
|
11
|
+
scrollTop,
|
|
12
|
+
scrollLeft,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Timeline } from '../../components/timeline/Timeline';
|
|
2
|
+
import getScrollValues from './getScrollValues';
|
|
3
|
+
/**
|
|
4
|
+
* Scroll to coordinates
|
|
5
|
+
*/
|
|
6
|
+
export default function scrollTo({ container = window, top = 0, left = 0, duration = 250, }) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
// save start values
|
|
9
|
+
const startValues = getScrollValues(container);
|
|
10
|
+
if (startValues) {
|
|
11
|
+
// create animation
|
|
12
|
+
const timeline = new Timeline({
|
|
13
|
+
duration,
|
|
14
|
+
});
|
|
15
|
+
timeline.addCallback('progress', (data) => {
|
|
16
|
+
if (container) {
|
|
17
|
+
container.scrollTo({
|
|
18
|
+
top: startValues.scrollTop
|
|
19
|
+
+ (top - startValues.scrollTop) * data.easing,
|
|
20
|
+
left: startValues.scrollLeft
|
|
21
|
+
+ (left - startValues.scrollLeft) * data.easing,
|
|
22
|
+
behavior: 'auto',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
timeline.addCallback('end', () => {
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
timeline.play();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
reject();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { selectOne } from 'vevet-dom';
|
|
2
|
+
import getScrollValues from './getScrollValues';
|
|
3
|
+
import clamp from '../math/clamp';
|
|
4
|
+
import scrollTo from './scrollTo';
|
|
5
|
+
/**
|
|
6
|
+
* Scroll to element
|
|
7
|
+
*/
|
|
8
|
+
export default function scrollToElement({ container = window, el, top = 0, left = 0, duration = 250, }) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const startValues = getScrollValues(container);
|
|
11
|
+
if (startValues) {
|
|
12
|
+
const element = selectOne(el);
|
|
13
|
+
if (element) {
|
|
14
|
+
const bounding = element.getBoundingClientRect();
|
|
15
|
+
const toTop = clamp(bounding.top + startValues.scrollTop - top, [0, Infinity]);
|
|
16
|
+
const toLeft = clamp(bounding.left + startValues.scrollLeft - left, [0, Infinity]);
|
|
17
|
+
scrollTo({
|
|
18
|
+
container,
|
|
19
|
+
top: toTop,
|
|
20
|
+
left: toLeft,
|
|
21
|
+
duration,
|
|
22
|
+
}).then(() => {
|
|
23
|
+
resolve();
|
|
24
|
+
}).catch(() => {
|
|
25
|
+
reject();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
reject();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Timeline } from '../../components/timeline/Timeline';
|
|
2
|
+
import getScrollValues from './getScrollValues';
|
|
3
|
+
/**
|
|
4
|
+
* Scroll to coordinates
|
|
5
|
+
*/
|
|
6
|
+
export default function scrollTo({ container = window, top = 0, left = 0, duration = 250, }) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
// save start values
|
|
9
|
+
const startValues = getScrollValues(container);
|
|
10
|
+
if (startValues) {
|
|
11
|
+
// create animation
|
|
12
|
+
const timeline = new Timeline({
|
|
13
|
+
duration,
|
|
14
|
+
});
|
|
15
|
+
timeline.addCallback('progress', (data) => {
|
|
16
|
+
if (container) {
|
|
17
|
+
container.scrollTo({
|
|
18
|
+
top: startValues.scrollTop
|
|
19
|
+
+ (top - startValues.scrollTop) * data.easing,
|
|
20
|
+
left: startValues.scrollLeft
|
|
21
|
+
+ (left - startValues.scrollLeft) * data.easing,
|
|
22
|
+
behavior: 'auto',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
timeline.addCallback('end', () => {
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
timeline.play();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
reject();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
scrollTo(options: ScrollToOptions): void;
|
|
4
|
-
scrollTo(x: number, y: number): void;
|
|
5
|
-
scrollLeft: number;
|
|
1
|
+
import { ScrollLike } from '../../utils/types/general';
|
|
2
|
+
export interface ScrollableElement extends ScrollLike {
|
|
6
3
|
scrollWidth: number;
|
|
7
4
|
scrollHeight: number;
|
|
8
5
|
clientWidth: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ts/components/scroll/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/ts/components/scroll/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACxB"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as common from './utils/common';
|
|
2
2
|
import * as listeners from './utils/listeners';
|
|
3
3
|
import * as math from './utils/math';
|
|
4
|
+
import * as scroll from './utils/scroll';
|
|
4
5
|
import * as GeneralTypes from './utils/types/general';
|
|
5
6
|
import { Application, NApplication } from './app/Application';
|
|
6
7
|
import { Viewport, NViewport } from './app/events/Viewport';
|
|
@@ -34,6 +35,7 @@ declare const utils: {
|
|
|
34
35
|
common: typeof common;
|
|
35
36
|
listeners: typeof listeners;
|
|
36
37
|
math: typeof math;
|
|
38
|
+
scroll: typeof scroll;
|
|
37
39
|
};
|
|
38
40
|
export { utils, GeneralTypes, Application, NApplication, Viewport, NViewport, PageLoad, NPageLoad, Callbacks, NCallbacks, MutableProp, NMutableProp, Module, NModule, Component, NComponent, Plugin, NPlugin, Page, NPage, WheelHandler, NWheelHandler, AnimationFrame, NAnimationFrame, StaticTimeline, NStaticTimeline, Timeline, NTimeline, Preloader, NPreloader, ProgressPreloader, NProgressPreloader, Dragger, NDragger, DraggerMove, NDraggerMove, DraggerDirection, NDraggerDirection, Ctx2D, NCtx2D, Ctx2DPrerender, NCtx2DPrerender, SmoothScroll, NSmoothScroll, ScrollBar, NScrollBar, ScrollEventsBase, NScrollEventsBase, ScrollView, NScrollView, SmoothScrollKeyboardPlugin, NSmoothScrollKeyboardPlugin, SmoothScrollDragPlugin, NSmoothScrollDragPlugin, SplitText, NSplitText, CustomCursor, NCustomCursor, };
|
|
39
41
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ScrollLike } from '../types/general';
|
|
2
|
+
/**
|
|
3
|
+
* Get scroll values of a certain element
|
|
4
|
+
*/
|
|
5
|
+
export default function getScrollValues(selector?: (Window | Element | ScrollLike | undefined)): {
|
|
6
|
+
scrollTop: number;
|
|
7
|
+
scrollLeft: number;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=getScrollValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getScrollValues.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/scroll/getScrollValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACnC,QAAQ,GAAE,CAAC,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAU;;;EAajE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/scroll/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACH,SAAS,EACT,QAAQ,IAAI,EAAE,EACd,eAAe,IAAI,SAAS,GAC/B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ScrollLike } from '../types/general';
|
|
2
|
+
interface Props {
|
|
3
|
+
/**
|
|
4
|
+
* @default window
|
|
5
|
+
*/
|
|
6
|
+
container?: Window | Element | ScrollLike;
|
|
7
|
+
/**
|
|
8
|
+
* top padding
|
|
9
|
+
* @default 0
|
|
10
|
+
*/
|
|
11
|
+
top?: number;
|
|
12
|
+
/**
|
|
13
|
+
* left padding
|
|
14
|
+
* @default 0
|
|
15
|
+
*/
|
|
16
|
+
left?: number;
|
|
17
|
+
/**
|
|
18
|
+
* scroll duration
|
|
19
|
+
* @default 250
|
|
20
|
+
*/
|
|
21
|
+
duration?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Scroll to coordinates
|
|
25
|
+
*/
|
|
26
|
+
export default function scrollTo({ container, top, left, duration, }: Props): Promise<void>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=scrollTo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollTo.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/scroll/scrollTo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,UAAU,KAAK;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IAC1C;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAE,EAC9B,SAAkB,EAClB,GAAO,EACP,IAAQ,EACR,QAAc,GACjB,EAAE,KAAK,iBA8BP"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ScrollLike } from '../types/general';
|
|
2
|
+
interface Props {
|
|
3
|
+
/**
|
|
4
|
+
* @default window
|
|
5
|
+
*/
|
|
6
|
+
container?: Window | Element | ScrollLike;
|
|
7
|
+
/**
|
|
8
|
+
* The target element
|
|
9
|
+
*/
|
|
10
|
+
el: Element | string;
|
|
11
|
+
/**
|
|
12
|
+
* top padding
|
|
13
|
+
* @default 0
|
|
14
|
+
*/
|
|
15
|
+
top?: number;
|
|
16
|
+
/**
|
|
17
|
+
* left padding
|
|
18
|
+
* @default 0
|
|
19
|
+
*/
|
|
20
|
+
left?: number;
|
|
21
|
+
/**
|
|
22
|
+
* scroll duration
|
|
23
|
+
* @default 250
|
|
24
|
+
*/
|
|
25
|
+
duration?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Scroll to element
|
|
29
|
+
*/
|
|
30
|
+
export default function scrollToElement({ container, el, top, left, duration, }: Props): Promise<void>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=scrollToElement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollToElement.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/scroll/scrollToElement.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,UAAU,KAAK;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IAC1C;;OAEG;IACH,EAAE,EAAE,OAAO,GAAG,MAAM,CAAC;IACrB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAE,EACrC,SAAkB,EAClB,EAAE,EACF,GAAO,EACP,IAAQ,EACR,QAAc,GACjB,EAAE,KAAK,iBAgCP"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ScrollLike } from '../types/general';
|
|
2
|
+
interface Props {
|
|
3
|
+
/**
|
|
4
|
+
* @default window
|
|
5
|
+
*/
|
|
6
|
+
container?: Window | Element | ScrollLike;
|
|
7
|
+
/**
|
|
8
|
+
* top padding
|
|
9
|
+
* @default 0
|
|
10
|
+
*/
|
|
11
|
+
top?: number;
|
|
12
|
+
/**
|
|
13
|
+
* left padding
|
|
14
|
+
* @default 0
|
|
15
|
+
*/
|
|
16
|
+
left?: number;
|
|
17
|
+
/**
|
|
18
|
+
* scroll duration
|
|
19
|
+
* @default 250
|
|
20
|
+
*/
|
|
21
|
+
duration?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Scroll to coordinates
|
|
25
|
+
*/
|
|
26
|
+
export default function scrollTo({ container, top, left, duration, }: Props): Promise<void>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=to.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/scroll/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,UAAU,KAAK;IACX;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;IAC1C;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAE,EAC9B,SAAkB,EAClB,GAAO,EACP,IAAQ,EACR,QAAc,GACjB,EAAE,KAAK,iBA8BP"}
|
|
@@ -4,4 +4,10 @@ export interface IRemovable {
|
|
|
4
4
|
export interface IDestroyable {
|
|
5
5
|
destroy: () => void;
|
|
6
6
|
}
|
|
7
|
+
export interface ScrollLike {
|
|
8
|
+
scrollTop: number;
|
|
9
|
+
scrollLeft: number;
|
|
10
|
+
scrollTo(options: ScrollToOptions): void;
|
|
11
|
+
scrollTo(x: number, y: number): void;
|
|
12
|
+
}
|
|
7
13
|
//# sourceMappingURL=general.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/types/general.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB"}
|
|
1
|
+
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../../../src/ts/utils/types/general.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
scrollTo(x: number, y: number): void;
|
|
5
|
-
scrollLeft: number;
|
|
1
|
+
import { ScrollLike } from '../../utils/types/general';
|
|
2
|
+
|
|
3
|
+
export interface ScrollableElement extends ScrollLike {
|
|
6
4
|
scrollWidth: number;
|
|
7
5
|
scrollHeight: number;
|
|
8
6
|
clientWidth: number;
|
package/src/ts/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as common from './utils/common';
|
|
2
2
|
import * as listeners from './utils/listeners';
|
|
3
3
|
import * as math from './utils/math';
|
|
4
|
+
import * as scroll from './utils/scroll';
|
|
4
5
|
|
|
5
6
|
import * as GeneralTypes from './utils/types/general';
|
|
6
7
|
|
|
@@ -48,6 +49,7 @@ const utils = {
|
|
|
48
49
|
common,
|
|
49
50
|
listeners,
|
|
50
51
|
math,
|
|
52
|
+
scroll,
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ScrollLike } from '../types/general';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get scroll values of a certain element
|
|
5
|
+
*/
|
|
6
|
+
export default function getScrollValues (
|
|
7
|
+
selector: (Window | Element | ScrollLike | undefined) = window,
|
|
8
|
+
) {
|
|
9
|
+
if (selector) {
|
|
10
|
+
const scrollTop = selector instanceof Window
|
|
11
|
+
? selector.pageYOffset : selector.scrollTop;
|
|
12
|
+
const scrollLeft = selector instanceof Window
|
|
13
|
+
? selector.pageXOffset : selector.scrollLeft;
|
|
14
|
+
return {
|
|
15
|
+
scrollTop,
|
|
16
|
+
scrollLeft,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Timeline } from '../../components/timeline/Timeline';
|
|
2
|
+
import { ScrollLike } from '../types/general';
|
|
3
|
+
import getScrollValues from './getScrollValues';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
/**
|
|
7
|
+
* @default window
|
|
8
|
+
*/
|
|
9
|
+
container?: Window | Element | ScrollLike;
|
|
10
|
+
/**
|
|
11
|
+
* top padding
|
|
12
|
+
* @default 0
|
|
13
|
+
*/
|
|
14
|
+
top?: number;
|
|
15
|
+
/**
|
|
16
|
+
* left padding
|
|
17
|
+
* @default 0
|
|
18
|
+
*/
|
|
19
|
+
left?: number;
|
|
20
|
+
/**
|
|
21
|
+
* scroll duration
|
|
22
|
+
* @default 250
|
|
23
|
+
*/
|
|
24
|
+
duration?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Scroll to coordinates
|
|
29
|
+
*/
|
|
30
|
+
export default function scrollTo ({
|
|
31
|
+
container = window,
|
|
32
|
+
top = 0,
|
|
33
|
+
left = 0,
|
|
34
|
+
duration = 250,
|
|
35
|
+
}: Props) {
|
|
36
|
+
return new Promise<void>((
|
|
37
|
+
resolve, reject,
|
|
38
|
+
) => {
|
|
39
|
+
// save start values
|
|
40
|
+
const startValues = getScrollValues(container);
|
|
41
|
+
if (startValues) {
|
|
42
|
+
// create animation
|
|
43
|
+
const timeline = new Timeline({
|
|
44
|
+
duration,
|
|
45
|
+
});
|
|
46
|
+
timeline.addCallback('progress', (data) => {
|
|
47
|
+
if (container) {
|
|
48
|
+
container.scrollTo({
|
|
49
|
+
top: startValues.scrollTop
|
|
50
|
+
+ (top - startValues.scrollTop) * data.easing,
|
|
51
|
+
left: startValues.scrollLeft
|
|
52
|
+
+ (left - startValues.scrollLeft) * data.easing,
|
|
53
|
+
behavior: 'auto',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
timeline.addCallback('end', () => {
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
60
|
+
timeline.play();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
reject();
|
|
64
|
+
});
|
|
65
|
+
}
|