@studiometa/js-toolkit 2.0.0-alpha.8 → 2.0.0-beta.10
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/Base/index.d.ts +53 -2
- package/Base/index.js +153 -46
- package/Base/managers/ChildrenManager.js +22 -4
- package/Base/managers/EventsManager.d.ts +3 -1
- package/Base/managers/EventsManager.js +38 -4
- package/Base/managers/OptionsManager.d.ts +2 -0
- package/Base/managers/OptionsManager.js +17 -1
- package/Base/managers/RefsManager.d.ts +2 -0
- package/Base/managers/RefsManager.js +27 -4
- package/Base/managers/ServicesManager.d.ts +36 -4
- package/Base/managers/ServicesManager.js +33 -7
- package/Base/utils.d.ts +0 -8
- package/Base/utils.js +0 -25
- package/README.md +13 -60
- package/decorators/index.d.ts +8 -7
- package/decorators/index.js +8 -7
- package/decorators/withBreakpointObserver.js +2 -2
- package/decorators/withDrag.d.ts +3 -3
- package/decorators/withDrag.js +14 -14
- package/decorators/withIntersectionObserver.js +5 -7
- package/decorators/withMountWhenInView.d.ts +4 -4
- package/decorators/withMountWhenInView.js +13 -6
- package/decorators/withScrolledInView.d.ts +17 -0
- package/decorators/withScrolledInView.js +94 -0
- package/decorators/withVue2.d.ts +7 -0
- package/decorators/withVue2.js +45 -0
- package/helpers/index.d.ts +4 -5
- package/helpers/index.js +4 -5
- package/index.d.ts +4 -19
- package/index.js +4 -5
- package/index.modern.js +1 -1
- package/index.umd.js +1 -1
- package/package.json +1 -1
- package/services/Service.d.ts +22 -17
- package/services/Service.js +12 -7
- package/services/drag.d.ts +5 -19
- package/services/drag.js +82 -105
- package/services/index.d.ts +13 -10
- package/services/index.js +7 -8
- package/services/key.d.ts +4 -13
- package/services/key.js +55 -56
- package/services/load.d.ts +3 -13
- package/services/load.js +32 -26
- package/services/pointer.d.ts +4 -13
- package/services/pointer.js +61 -64
- package/services/raf.d.ts +3 -13
- package/services/raf.js +22 -25
- package/services/resize.d.ts +3 -13
- package/services/resize.js +48 -30
- package/services/scroll.d.ts +3 -13
- package/services/scroll.js +65 -61
- package/utils/collide/index.d.ts +6 -7
- package/utils/collide/index.js +6 -7
- package/utils/css/index.d.ts +4 -5
- package/utils/css/index.js +6 -5
- package/utils/css/transition.js +2 -2
- package/utils/history.d.ts +6 -6
- package/utils/history.js +8 -4
- package/utils/index.d.ts +11 -13
- package/utils/index.js +11 -13
- package/utils/math/damp.d.ts +6 -5
- package/utils/math/damp.js +2 -1
- package/utils/math/ease.d.ts +78 -0
- package/utils/math/ease.js +41 -0
- package/utils/math/index.d.ts +8 -7
- package/utils/math/index.js +8 -7
- package/utils/math/inertiaFinalValue.d.ts +2 -2
- package/utils/math/inertiaFinalValue.js +4 -4
- package/utils/object/getAllProperties.js +1 -1
- package/utils/object/index.d.ts +3 -4
- package/utils/object/index.js +3 -4
- package/utils/scrollTo.d.ts +11 -0
- package/utils/scrollTo.js +75 -0
- package/utils/string/index.d.ts +10 -11
- package/utils/string/index.js +10 -11
package/utils/css/transition.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
|
|
4
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
5
|
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
7
|
|
|
8
8
|
import nextFrame from '../nextFrame.js';
|
|
9
9
|
import * as classes from './classes.js';
|
package/utils/history.d.ts
CHANGED
|
@@ -10,18 +10,18 @@ export function objectToURLSearchParams(obj: any, defaultSearch?: string): URLSe
|
|
|
10
10
|
* Push a new state.
|
|
11
11
|
*
|
|
12
12
|
* @param {HistoryOptions} options The new state.
|
|
13
|
-
* @param {Object} data
|
|
14
|
-
* @param {string} title
|
|
13
|
+
* @param {Object} [data] The data for the new state.
|
|
14
|
+
* @param {string} [title] The title for the new state.
|
|
15
15
|
*/
|
|
16
|
-
export function push(options: HistoryOptions, data
|
|
16
|
+
export function push(options: HistoryOptions, data?: any, title?: string): void;
|
|
17
17
|
/**
|
|
18
18
|
* Replace a new state.
|
|
19
19
|
*
|
|
20
20
|
* @param {HistoryOptions} options The new state.
|
|
21
|
-
* @param {Object} data
|
|
22
|
-
* @param {string} title
|
|
21
|
+
* @param {Object} [data] The data for the new state.
|
|
22
|
+
* @param {string} [title] The title for the new state.
|
|
23
23
|
*/
|
|
24
|
-
export function replace(options: HistoryOptions, data
|
|
24
|
+
export function replace(options: HistoryOptions, data?: any, title?: string): void;
|
|
25
25
|
export type HistoryOptions = {
|
|
26
26
|
path?: string | undefined;
|
|
27
27
|
search?: URLSearchParams | {
|
package/utils/history.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
4
|
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
|
|
7
7
|
import isObject from './object/isObject.js';
|
|
8
8
|
|
|
@@ -81,9 +81,13 @@ function updateHistory(mode, options) {
|
|
|
81
81
|
window.history[method](data, title, url);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export function push(options
|
|
84
|
+
export function push(options) {
|
|
85
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
86
|
+
var title = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
85
87
|
updateHistory('push', options, data, title);
|
|
86
88
|
}
|
|
87
|
-
export function replace(options
|
|
89
|
+
export function replace(options) {
|
|
90
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
91
|
+
var title = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
88
92
|
updateHistory('replace', options, data, title);
|
|
89
93
|
}
|
package/utils/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import throttle from "./throttle.js";
|
|
13
|
-
export { collide, css, debounce, focusTrap, history, keyCodes, math, memoize, nextFrame, object, string, throttle };
|
|
1
|
+
export { default as debounce } from "./debounce.js";
|
|
2
|
+
export { default as focusTrap } from "./focusTrap.js";
|
|
3
|
+
export { default as keyCodes } from "./keyCodes.js";
|
|
4
|
+
export { default as memoize } from "./memoize.js";
|
|
5
|
+
export { default as nextFrame } from "./nextFrame.js";
|
|
6
|
+
export { default as throttle } from "./throttle.js";
|
|
7
|
+
export * from "./collide/index.js";
|
|
8
|
+
export * from "./math/index.js";
|
|
9
|
+
export * from "./string/index.js";
|
|
10
|
+
export { matrix, transition } from "./css/index.js";
|
|
11
|
+
export { objectToURLSearchParams, push as historyPush, replace as historyReplace } from "./history.js";
|
package/utils/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import throttle from './throttle.js';
|
|
13
|
-
export { collide, css, debounce, focusTrap, history, keyCodes, math, memoize, nextFrame, object, string, throttle };
|
|
1
|
+
export { default as debounce } from './debounce.js';
|
|
2
|
+
export { default as focusTrap } from './focusTrap.js';
|
|
3
|
+
export { default as keyCodes } from './keyCodes.js';
|
|
4
|
+
export { default as memoize } from './memoize.js';
|
|
5
|
+
export { default as nextFrame } from './nextFrame.js';
|
|
6
|
+
export { default as throttle } from './throttle.js';
|
|
7
|
+
export { matrix, transition } from './css/index.js';
|
|
8
|
+
export { objectToURLSearchParams, push as historyPush, replace as historyReplace } from './history.js';
|
|
9
|
+
export * from './collide/index.js';
|
|
10
|
+
export * from './math/index.js';
|
|
11
|
+
export * from './string/index.js';
|
package/utils/math/damp.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get the next damped value for a given factor.
|
|
3
3
|
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {
|
|
7
|
-
* @
|
|
4
|
+
* @param {number} targetValue The final value.
|
|
5
|
+
* @param {number} currentValue The current value.
|
|
6
|
+
* @param {number=} [factor=0.5] The factor used to reach the target value.
|
|
7
|
+
* @param {number=} [precision=0.01] The precision used to calculate the latest value.
|
|
8
|
+
* @return {number} The next value.
|
|
8
9
|
*/
|
|
9
|
-
export default function damp(targetValue: number, currentValue: number, factor?: number | undefined): number;
|
|
10
|
+
export default function damp(targetValue: number, currentValue: number, factor?: number | undefined, precision?: number | undefined): number;
|
package/utils/math/damp.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export default function damp(targetValue, currentValue) {
|
|
2
2
|
var factor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.5;
|
|
3
|
-
|
|
3
|
+
var precision = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.01;
|
|
4
|
+
return Math.abs(targetValue - currentValue) < precision ? targetValue : currentValue + (targetValue - currentValue) * factor;
|
|
4
5
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {(progress: number) => number} EasingFunction
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create an out easing function.
|
|
6
|
+
*
|
|
7
|
+
* @param {EasingFunction} easeIn The ease in function.
|
|
8
|
+
* @returns {EasingFunction} The out function.
|
|
9
|
+
*/
|
|
10
|
+
export function createEaseOut(easeIn: EasingFunction): EasingFunction;
|
|
11
|
+
/**
|
|
12
|
+
* Create an in-out easing function.
|
|
13
|
+
*
|
|
14
|
+
* @param {EasingFunction} easeIn The ease in function.
|
|
15
|
+
* @return {EasingFunction} The in-out function.
|
|
16
|
+
*/
|
|
17
|
+
export function createEaseInOut(easeIn: EasingFunction): EasingFunction;
|
|
18
|
+
/**
|
|
19
|
+
* @type {EasingFunction}
|
|
20
|
+
*/
|
|
21
|
+
export function easeInQuad(progress: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Ease in cubic.
|
|
24
|
+
*
|
|
25
|
+
* @param {number} progress Progress value betwen 0 and 1.
|
|
26
|
+
* @return {number} Eased value between 0 and 1.
|
|
27
|
+
*/
|
|
28
|
+
export function easeInCubic(progress: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Ease in quart.
|
|
31
|
+
*
|
|
32
|
+
* @param {number} progress Progress value betwen 0 and 1.
|
|
33
|
+
* @return {number} Eased value between 0 and 1.
|
|
34
|
+
*/
|
|
35
|
+
export function easeInQuart(progress: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Ease in quint.
|
|
38
|
+
*
|
|
39
|
+
* @param {number} progress Progress value betwen 0 and 1.
|
|
40
|
+
* @return {number} Eased value between 0 and 1.
|
|
41
|
+
*/
|
|
42
|
+
export function easeInQuint(progress: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Ease in sine.
|
|
45
|
+
*
|
|
46
|
+
* @param {number} progress Progress value betwen 0 and 1.
|
|
47
|
+
* @return {number} Eased value between 0 and 1.
|
|
48
|
+
*/
|
|
49
|
+
export function easeInSine(progress: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* Ease in circ.
|
|
52
|
+
*
|
|
53
|
+
* @param {number} progress Progress value betwen 0 and 1.
|
|
54
|
+
* @return {number} Eased value between 0 and 1.
|
|
55
|
+
*/
|
|
56
|
+
export function easeInCirc(progress: number): number;
|
|
57
|
+
/**
|
|
58
|
+
* Ease in exponential.
|
|
59
|
+
*
|
|
60
|
+
* @param {number} progress Progress value betwen 0 and 1.
|
|
61
|
+
* @return {number} Eased value between 0 and 1.
|
|
62
|
+
*/
|
|
63
|
+
export function easeInExpo(progress: number): number;
|
|
64
|
+
export function easeOutQuad(progress: number): number;
|
|
65
|
+
export function easeInOutQuad(progress: number): number;
|
|
66
|
+
export function easeOutCubic(progress: number): number;
|
|
67
|
+
export function easeInOutCubic(progress: number): number;
|
|
68
|
+
export function easeOutQuart(progress: number): number;
|
|
69
|
+
export function easeInOutQuart(progress: number): number;
|
|
70
|
+
export function easeOutQuint(progress: number): number;
|
|
71
|
+
export function easeInOutQuint(progress: number): number;
|
|
72
|
+
export function easeOutSine(progress: number): number;
|
|
73
|
+
export function easeInOutSine(progress: number): number;
|
|
74
|
+
export function easeOutCirc(progress: number): number;
|
|
75
|
+
export function easeInOutCirc(progress: number): number;
|
|
76
|
+
export function easeOutExpo(progress: number): number;
|
|
77
|
+
export function easeInOutExpo(progress: number): number;
|
|
78
|
+
export type EasingFunction = (progress: number) => number;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function createEaseOut(easeIn) {
|
|
2
|
+
return progress => 1 - easeIn(1 - progress);
|
|
3
|
+
}
|
|
4
|
+
export function createEaseInOut(easeIn) {
|
|
5
|
+
return progress => progress === 0 ? 0 : progress === 1 ? 1 : progress < 0.5 ? easeIn(progress * 2) / 2 : 1 - easeIn((1 - progress) * 2) / 2;
|
|
6
|
+
}
|
|
7
|
+
export function easeInQuad(progress) {
|
|
8
|
+
return progress ** 2;
|
|
9
|
+
}
|
|
10
|
+
export var easeOutQuad = createEaseOut(easeInQuad);
|
|
11
|
+
export var easeInOutQuad = createEaseInOut(easeInQuad);
|
|
12
|
+
export function easeInCubic(progress) {
|
|
13
|
+
return progress ** 3;
|
|
14
|
+
}
|
|
15
|
+
export var easeOutCubic = createEaseOut(easeInCubic);
|
|
16
|
+
export var easeInOutCubic = createEaseInOut(easeInCubic);
|
|
17
|
+
export function easeInQuart(progress) {
|
|
18
|
+
return progress ** 4;
|
|
19
|
+
}
|
|
20
|
+
export var easeOutQuart = createEaseOut(easeInQuart);
|
|
21
|
+
export var easeInOutQuart = createEaseInOut(easeInQuart);
|
|
22
|
+
export function easeInQuint(progress) {
|
|
23
|
+
return progress ** 5;
|
|
24
|
+
}
|
|
25
|
+
export var easeOutQuint = createEaseOut(easeInQuint);
|
|
26
|
+
export var easeInOutQuint = createEaseInOut(easeInQuint);
|
|
27
|
+
export function easeInSine(progress) {
|
|
28
|
+
return progress === 1 ? 1 : -Math.cos(progress * Math.PI / 2) + 1;
|
|
29
|
+
}
|
|
30
|
+
export var easeOutSine = createEaseOut(easeInSine);
|
|
31
|
+
export var easeInOutSine = createEaseInOut(easeInSine);
|
|
32
|
+
export function easeInCirc(progress) {
|
|
33
|
+
return -(Math.sqrt(1 - progress * progress) - 1);
|
|
34
|
+
}
|
|
35
|
+
export var easeOutCirc = createEaseOut(easeInCirc);
|
|
36
|
+
export var easeInOutCirc = createEaseInOut(easeInCirc);
|
|
37
|
+
export function easeInExpo(progress) {
|
|
38
|
+
return 2 ** (10 * (progress - 1));
|
|
39
|
+
}
|
|
40
|
+
export var easeOutExpo = createEaseOut(easeInExpo);
|
|
41
|
+
export var easeInOutExpo = createEaseInOut(easeInExpo);
|
package/utils/math/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
1
|
+
export { default as clamp } from "./clamp.js";
|
|
2
|
+
export { default as clamp01 } from "./clamp01.js";
|
|
3
|
+
export { default as damp } from "./damp.js";
|
|
4
|
+
export { default as inertiaFinalValue } from "./inertiaFinalValue.js";
|
|
5
|
+
export { default as lerp } from "./lerp.js";
|
|
6
|
+
export { default as map } from "./map.js";
|
|
7
|
+
export { default as round } from "./round.js";
|
|
8
|
+
export * from "./ease.js";
|
package/utils/math/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
1
|
+
export { default as clamp } from './clamp.js';
|
|
2
|
+
export { default as clamp01 } from './clamp01.js';
|
|
3
|
+
export { default as damp } from './damp.js';
|
|
4
|
+
export { default as inertiaFinalValue } from './inertiaFinalValue.js';
|
|
5
|
+
export { default as lerp } from './lerp.js';
|
|
6
|
+
export { default as map } from './map.js';
|
|
7
|
+
export { default as round } from './round.js';
|
|
8
|
+
export * from './ease.js';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {Number} initialValue The final value.
|
|
5
5
|
* @param {Number} initialDelta The current value.
|
|
6
|
-
* @param {Number=} [
|
|
6
|
+
* @param {Number=} [dampFactor=0.85] The speed to reach the target value.
|
|
7
7
|
* @return {Number} The next value.
|
|
8
8
|
*/
|
|
9
|
-
export default function inertiaFinalValue(initialValue: number, initialDelta: number,
|
|
9
|
+
export default function inertiaFinalValue(initialValue: number, initialDelta: number, dampFactor?: number | undefined): number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export default function inertiaFinalValue(initialValue, initialDelta) {
|
|
2
|
-
var
|
|
2
|
+
var dampFactor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.85;
|
|
3
3
|
|
|
4
|
-
if (
|
|
5
|
-
throw new Error("The `factor` parameter must be a number greater than 0 and smaller than 1, `".concat(
|
|
4
|
+
if (dampFactor >= 1 || dampFactor <= 0) {
|
|
5
|
+
throw new Error("The `factor` parameter must be a number greater than 0 and smaller than 1, `".concat(dampFactor, "` given."));
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
var delta = initialDelta;
|
|
@@ -10,7 +10,7 @@ export default function inertiaFinalValue(initialValue, initialDelta) {
|
|
|
10
10
|
|
|
11
11
|
while (Math.abs(delta) > 0.1) {
|
|
12
12
|
finalValue += delta;
|
|
13
|
-
delta *=
|
|
13
|
+
delta *= dampFactor;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return finalValue;
|
|
@@ -3,7 +3,7 @@ export default function getAllProperties(object) {
|
|
|
3
3
|
var testFn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
4
4
|
var proto = Object.getPrototypeOf(object);
|
|
5
5
|
|
|
6
|
-
if (proto === Object.prototype) {
|
|
6
|
+
if (proto === Object.prototype || proto === null) {
|
|
7
7
|
return props;
|
|
8
8
|
}
|
|
9
9
|
|
package/utils/object/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { autoBind, getAllProperties, isObject };
|
|
1
|
+
export { default as autoBind } from "./autoBind.js";
|
|
2
|
+
export { default as getAllProperties } from "./getAllProperties.js";
|
|
3
|
+
export { default as isObject } from "./isObject.js";
|
package/utils/object/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { autoBind, getAllProperties, isObject };
|
|
1
|
+
export { default as autoBind } from './autoBind.js';
|
|
2
|
+
export { default as getAllProperties } from './getAllProperties.js';
|
|
3
|
+
export { default as isObject } from './isObject.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler for the click event on anchor links
|
|
3
|
+
*
|
|
4
|
+
* @param {HTMLElement|string} selectorElement The target element.
|
|
5
|
+
* @param {{ offset?: number, dampFactor?: number }} [options] Options for the scroll.
|
|
6
|
+
* @return {Promise<number>} A promising resolving with the target scroll position.
|
|
7
|
+
*/
|
|
8
|
+
export default function scrollTo(selectorElement: HTMLElement | string, { offset, dampFactor }?: {
|
|
9
|
+
offset?: number;
|
|
10
|
+
dampFactor?: number;
|
|
11
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import damp from './math/damp.js';
|
|
2
|
+
export default function scrollTo(selectorElement) {
|
|
3
|
+
var {
|
|
4
|
+
offset = 0,
|
|
5
|
+
dampFactor = 0.2
|
|
6
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7
|
+
var targetElement = null;
|
|
8
|
+
|
|
9
|
+
if (selectorElement instanceof HTMLElement) {
|
|
10
|
+
targetElement = selectorElement;
|
|
11
|
+
} else {
|
|
12
|
+
targetElement = document.querySelector(selectorElement);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!targetElement) {
|
|
16
|
+
return Promise.resolve(window.pageYOffset);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var sizes = targetElement.getBoundingClientRect();
|
|
20
|
+
var scrollMargin = getComputedStyle(targetElement).scrollMarginTop || '0';
|
|
21
|
+
var max = document.documentElement.scrollHeight - window.innerHeight;
|
|
22
|
+
var scrollTarget = sizes.top + window.pageYOffset + parseInt(scrollMargin, 10) + offset;
|
|
23
|
+
|
|
24
|
+
if (scrollTarget > max) {
|
|
25
|
+
scrollTarget = max;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new Promise(resolve => {
|
|
29
|
+
var isScrolling = false;
|
|
30
|
+
var scroll = window.pageYOffset;
|
|
31
|
+
var dampScroll = window.pageYOffset;
|
|
32
|
+
|
|
33
|
+
function eventHandler() {
|
|
34
|
+
isScrolling = false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function end() {
|
|
38
|
+
window.removeEventListener('wheel', eventHandler);
|
|
39
|
+
window.removeEventListener('touchmove', eventHandler);
|
|
40
|
+
resolve(window.pageYOffset);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function loop() {
|
|
44
|
+
if (!isScrolling) {
|
|
45
|
+
return end();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
dampScroll = damp(scroll, dampScroll, dampFactor);
|
|
49
|
+
window.scrollTo({
|
|
50
|
+
top: dampScroll
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (dampScroll === scroll) {
|
|
54
|
+
isScrolling = false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return requestAnimationFrame(loop);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function start(target) {
|
|
61
|
+
isScrolling = true;
|
|
62
|
+
dampScroll = window.pageYOffset;
|
|
63
|
+
scroll = target;
|
|
64
|
+
window.addEventListener('wheel', eventHandler, {
|
|
65
|
+
passive: true
|
|
66
|
+
});
|
|
67
|
+
window.addEventListener('touchmove', eventHandler, {
|
|
68
|
+
passive: true
|
|
69
|
+
});
|
|
70
|
+
loop();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
start(scrollTarget);
|
|
74
|
+
});
|
|
75
|
+
}
|
package/utils/string/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export { withLeadingCharacters, withLeadingSlash, withoutLeadingCharacters, withoutLeadingCharactersRecursive, withoutLeadingSlash, withoutTrailingCharacters, withoutTrailingCharactersRecursive, withoutTrailingSlash, withTrailingCharacters, withTrailingSlash };
|
|
1
|
+
export { default as withLeadingCharacters } from "./withLeadingCharacters.js";
|
|
2
|
+
export { default as withLeadingSlash } from "./withLeadingSlash.js";
|
|
3
|
+
export { default as withoutLeadingCharacters } from "./withoutLeadingCharacters.js";
|
|
4
|
+
export { default as withoutLeadingCharactersRecursive } from "./withoutLeadingCharactersRecursive.js";
|
|
5
|
+
export { default as withoutLeadingSlash } from "./withoutLeadingSlash.js";
|
|
6
|
+
export { default as withoutTrailingCharacters } from "./withoutTrailingCharacters.js";
|
|
7
|
+
export { default as withoutTrailingCharactersRecursive } from "./withoutTrailingCharactersRecursive.js";
|
|
8
|
+
export { default as withoutTrailingSlash } from "./withoutTrailingSlash.js";
|
|
9
|
+
export { default as withTrailingCharacters } from "./withTrailingCharacters.js";
|
|
10
|
+
export { default as withTrailingSlash } from "./withTrailingSlash.js";
|
package/utils/string/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export { withLeadingCharacters, withLeadingSlash, withoutLeadingCharacters, withoutLeadingCharactersRecursive, withoutLeadingSlash, withoutTrailingCharacters, withoutTrailingCharactersRecursive, withoutTrailingSlash, withTrailingCharacters, withTrailingSlash };
|
|
1
|
+
export { default as withLeadingCharacters } from './withLeadingCharacters.js';
|
|
2
|
+
export { default as withLeadingSlash } from './withLeadingSlash.js';
|
|
3
|
+
export { default as withoutLeadingCharacters } from './withoutLeadingCharacters.js';
|
|
4
|
+
export { default as withoutLeadingCharactersRecursive } from './withoutLeadingCharactersRecursive.js';
|
|
5
|
+
export { default as withoutLeadingSlash } from './withoutLeadingSlash.js';
|
|
6
|
+
export { default as withoutTrailingCharacters } from './withoutTrailingCharacters.js';
|
|
7
|
+
export { default as withoutTrailingCharactersRecursive } from './withoutTrailingCharactersRecursive.js';
|
|
8
|
+
export { default as withoutTrailingSlash } from './withoutTrailingSlash.js';
|
|
9
|
+
export { default as withTrailingCharacters } from './withTrailingCharacters.js';
|
|
10
|
+
export { default as withTrailingSlash } from './withTrailingSlash.js';
|