@studiometa/js-toolkit 2.12.1 → 3.0.0-alpha.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/Base.d.ts +8 -8
- package/Base/Base.js +75 -78
- package/Base/Base.js.map +2 -2
- package/Base/features.d.ts +15 -2
- package/Base/features.js +31 -1
- package/Base/features.js.map +2 -2
- package/Base/index.d.ts +1 -0
- package/Base/index.js +4 -0
- package/Base/index.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.d.ts +6 -6
- package/Base/managers/ChildrenManager.js +34 -20
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/EventsManager.d.ts +6 -28
- package/Base/managers/EventsManager.js +54 -64
- package/Base/managers/EventsManager.js.map +2 -2
- package/Base/managers/OptionsManager.d.ts +6 -6
- package/Base/managers/OptionsManager.js +29 -23
- package/Base/managers/OptionsManager.js.map +3 -3
- package/Base/managers/RefsManager.d.ts +1 -1
- package/Base/managers/RefsManager.js +23 -34
- package/Base/managers/RefsManager.js.map +3 -3
- package/Base/managers/ResponsiveOptionsManager.js +7 -4
- package/Base/managers/ResponsiveOptionsManager.js.map +2 -2
- package/Base/managers/ServicesManager.d.ts +2 -4
- package/Base/managers/ServicesManager.js +2 -3
- package/Base/managers/ServicesManager.js.map +2 -2
- package/Base/utils.d.ts +10 -5
- package/Base/utils.js +37 -23
- package/Base/utils.js.map +2 -2
- package/README.md +107 -6
- package/decorators/index.d.ts +1 -1
- package/decorators/index.js +1 -1
- package/decorators/index.js.map +1 -1
- package/decorators/withBreakpointManager.js +6 -4
- package/decorators/withBreakpointManager.js.map +2 -2
- package/decorators/withBreakpointObserver.d.ts +0 -1
- package/decorators/withBreakpointObserver.js +5 -3
- package/decorators/withBreakpointObserver.js.map +2 -2
- package/decorators/withIntersectionObserver.js +3 -5
- package/decorators/withIntersectionObserver.js.map +2 -2
- package/decorators/withMountOnMediaQuery.js +3 -3
- package/decorators/withMountOnMediaQuery.js.map +2 -2
- package/decorators/withMountWhenInView.js +3 -3
- package/decorators/withMountWhenInView.js.map +2 -2
- package/decorators/withName.d.ts +6 -0
- package/decorators/withName.js +12 -0
- package/decorators/withName.js.map +7 -0
- package/decorators/withScrolledInView/utils.d.ts +12 -1
- package/decorators/withScrolledInView/utils.js.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.js +7 -62
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/helpers/createApp.d.ts +3 -4
- package/helpers/createApp.js +21 -11
- package/helpers/createApp.js.map +2 -2
- package/helpers/getDirectChildren.js +10 -5
- package/helpers/getDirectChildren.js.map +2 -2
- package/helpers/importWhenVisible.js +1 -2
- package/helpers/importWhenVisible.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +2 -4
- package/index.js.map +2 -2
- package/package.json +2 -10
- package/services/index.d.ts +1 -1
- package/services/index.js.map +2 -2
- package/services/pointer.d.ts +1 -1
- package/services/pointer.js +3 -3
- package/services/pointer.js.map +2 -2
- package/services/raf.js +2 -4
- package/services/raf.js.map +2 -2
- package/services/resize.d.ts +7 -6
- package/services/resize.js +18 -26
- package/services/resize.js.map +2 -2
- package/services/scroll.d.ts +14 -0
- package/services/scroll.js +39 -21
- package/services/scroll.js.map +2 -2
- package/utils/SmartQueue.d.ts +1 -1
- package/utils/SmartQueue.js +1 -1
- package/utils/SmartQueue.js.map +2 -2
- package/utils/css/animate.d.ts +33 -15
- package/utils/css/animate.js +67 -26
- package/utils/css/animate.js.map +2 -2
- package/utils/css/getOffsetSizes.js +2 -2
- package/utils/css/getOffsetSizes.js.map +1 -1
- package/utils/css/index.d.ts +2 -1
- package/utils/css/index.js +4 -4
- package/utils/css/index.js.map +2 -2
- package/utils/css/matrix.d.ts +1 -1
- package/utils/css/matrix.js.map +2 -2
- package/utils/css/transform.d.ts +1 -1
- package/utils/css/transform.js +1 -1
- package/utils/css/transform.js.map +2 -2
- package/utils/css/utils.d.ts +1 -1
- package/utils/css/utils.js +1 -1
- package/utils/css/utils.js.map +2 -2
- package/utils/index.d.ts +6 -4
- package/utils/index.js +17 -16
- package/utils/index.js.map +2 -2
- package/utils/is.d.ts +12 -0
- package/utils/is.js +17 -0
- package/utils/is.js.map +2 -2
- package/utils/math/createRange.d.ts +4 -0
- package/utils/math/createRange.js +13 -0
- package/utils/math/createRange.js.map +7 -0
- package/utils/math/ease.d.ts +1 -0
- package/utils/math/ease.js +2 -0
- package/utils/math/ease.js.map +2 -2
- package/utils/math/index.d.ts +5 -3
- package/utils/math/index.js +7 -3
- package/utils/math/index.js.map +2 -2
- package/utils/math/mean.d.ts +1 -0
- package/utils/math/mean.js +17 -0
- package/utils/math/mean.js.map +7 -0
- package/utils/memo.d.ts +5 -0
- package/utils/memo.js +14 -0
- package/utils/memo.js.map +7 -0
- package/utils/nextFrame.d.ts +4 -22
- package/utils/nextFrame.js +3 -10
- package/utils/nextFrame.js.map +2 -2
- package/utils/nextMicrotask.d.ts +4 -1
- package/utils/nextMicrotask.js +3 -3
- package/utils/nextMicrotask.js.map +2 -2
- package/utils/nextTick.d.ts +4 -1
- package/utils/nextTick.js +3 -3
- package/utils/nextTick.js.map +2 -2
- package/utils/random.d.ts +15 -0
- package/utils/random.js +15 -0
- package/utils/random.js.map +7 -0
- package/utils/scrollTo.d.ts +30 -6
- package/utils/scrollTo.js +97 -43
- package/utils/scrollTo.js.map +2 -2
- package/utils/string/changeCase.d.ts +24 -0
- package/utils/string/changeCase.js +47 -0
- package/utils/string/changeCase.js.map +7 -0
- package/utils/string/index.d.ts +1 -0
- package/utils/string/index.js +1 -0
- package/utils/string/index.js.map +2 -2
- package/utils/{focusTrap.d.ts → trapFocus.d.ts} +2 -10
- package/utils/{focusTrap.js → trapFocus.js} +5 -9
- package/utils/trapFocus.js.map +7 -0
- package/utils/tween.d.ts +59 -10
- package/utils/tween.js +24 -18
- package/utils/tween.js.map +2 -2
- package/Base/Base.cjs +0 -420
- package/Base/Base.cjs.map +0 -7
- package/Base/features.cjs +0 -27
- package/Base/features.cjs.map +0 -7
- package/Base/index.cjs +0 -21
- package/Base/index.cjs.map +0 -7
- package/Base/managers/AbstractManager.cjs +0 -78
- package/Base/managers/AbstractManager.cjs.map +0 -7
- package/Base/managers/ChildrenManager.cjs +0 -156
- package/Base/managers/ChildrenManager.cjs.map +0 -7
- package/Base/managers/EventsManager.cjs +0 -305
- package/Base/managers/EventsManager.cjs.map +0 -7
- package/Base/managers/OptionsManager.cjs +0 -198
- package/Base/managers/OptionsManager.cjs.map +0 -7
- package/Base/managers/RefsManager.cjs +0 -118
- package/Base/managers/RefsManager.cjs.map +0 -7
- package/Base/managers/ResponsiveOptionsManager.cjs +0 -79
- package/Base/managers/ResponsiveOptionsManager.cjs.map +0 -7
- package/Base/managers/ServicesManager.cjs +0 -161
- package/Base/managers/ServicesManager.cjs.map +0 -7
- package/Base/managers/index.cjs +0 -39
- package/Base/managers/index.cjs.map +0 -7
- package/Base/types.cjs +0 -19
- package/Base/types.cjs.map +0 -7
- package/Base/utils.cjs +0 -95
- package/Base/utils.cjs.map +0 -7
- package/decorators/index.cjs +0 -33
- package/decorators/index.cjs.map +0 -7
- package/decorators/withBreakpointManager.cjs +0 -102
- package/decorators/withBreakpointManager.cjs.map +0 -7
- package/decorators/withBreakpointObserver.cjs +0 -128
- package/decorators/withBreakpointObserver.cjs.map +0 -7
- package/decorators/withDrag.cjs +0 -56
- package/decorators/withDrag.cjs.map +0 -7
- package/decorators/withExtraConfig.cjs +0 -50
- package/decorators/withExtraConfig.cjs.map +0 -7
- package/decorators/withFreezedOptions.cjs +0 -50
- package/decorators/withFreezedOptions.cjs.map +0 -7
- package/decorators/withIntersectionObserver.cjs +0 -71
- package/decorators/withIntersectionObserver.cjs.map +0 -7
- package/decorators/withMountOnMediaQuery.cjs +0 -86
- package/decorators/withMountOnMediaQuery.cjs.map +0 -7
- package/decorators/withMountWhenInView.cjs +0 -92
- package/decorators/withMountWhenInView.cjs.map +0 -7
- package/decorators/withMountWhenPrefersMotion.cjs +0 -30
- package/decorators/withMountWhenPrefersMotion.cjs.map +0 -7
- package/decorators/withRelativePointer.cjs +0 -56
- package/decorators/withRelativePointer.cjs.map +0 -7
- package/decorators/withResponsiveOptions.cjs +0 -41
- package/decorators/withResponsiveOptions.cjs.map +0 -7
- package/decorators/withScrolledInView/index.cjs +0 -22
- package/decorators/withScrolledInView/index.cjs.map +0 -7
- package/decorators/withScrolledInView/types.cjs +0 -19
- package/decorators/withScrolledInView/types.cjs.map +0 -7
- package/decorators/withScrolledInView/utils.cjs +0 -99
- package/decorators/withScrolledInView/utils.cjs.map +0 -7
- package/decorators/withScrolledInView/withScrolledInView.cjs +0 -249
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +0 -7
- package/decorators/withVue2.cjs +0 -68
- package/decorators/withVue2.cjs.map +0 -7
- package/decorators/withVue2.d.ts +0 -16
- package/decorators/withVue2.js +0 -46
- package/decorators/withVue2.js.map +0 -7
- package/helpers/createApp.cjs +0 -58
- package/helpers/createApp.cjs.map +0 -7
- package/helpers/getClosestParent.cjs +0 -45
- package/helpers/getClosestParent.cjs.map +0 -7
- package/helpers/getDirectChildren.cjs +0 -47
- package/helpers/getDirectChildren.cjs.map +0 -7
- package/helpers/getInstanceFromElement.cjs +0 -32
- package/helpers/getInstanceFromElement.cjs.map +0 -7
- package/helpers/importOnInteraction.cjs +0 -48
- package/helpers/importOnInteraction.cjs.map +0 -7
- package/helpers/importOnMediaQuery.cjs +0 -44
- package/helpers/importOnMediaQuery.cjs.map +0 -7
- package/helpers/importWhenIdle.cjs +0 -46
- package/helpers/importWhenIdle.cjs.map +0 -7
- package/helpers/importWhenPrefersMotion.cjs +0 -40
- package/helpers/importWhenPrefersMotion.cjs.map +0 -7
- package/helpers/importWhenVisible.cjs +0 -44
- package/helpers/importWhenVisible.cjs.map +0 -7
- package/helpers/index.cjs +0 -53
- package/helpers/index.cjs.map +0 -7
- package/helpers/utils.cjs +0 -37
- package/helpers/utils.cjs.map +0 -7
- package/index.cjs +0 -31
- package/index.cjs.map +0 -7
- package/services/drag.cjs +0 -231
- package/services/drag.cjs.map +0 -7
- package/services/index.cjs +0 -51
- package/services/index.cjs.map +0 -7
- package/services/key.cjs +0 -97
- package/services/key.cjs.map +0 -7
- package/services/load.cjs +0 -60
- package/services/load.cjs.map +0 -7
- package/services/pointer.cjs +0 -145
- package/services/pointer.cjs.map +0 -7
- package/services/raf.cjs +0 -80
- package/services/raf.cjs.map +0 -7
- package/services/resize.cjs +0 -107
- package/services/resize.cjs.map +0 -7
- package/services/scroll.cjs +0 -119
- package/services/scroll.cjs.map +0 -7
- package/services/service.cjs +0 -69
- package/services/service.cjs.map +0 -7
- package/utils/Queue.cjs +0 -93
- package/utils/Queue.cjs.map +0 -7
- package/utils/SmartQueue.cjs +0 -73
- package/utils/SmartQueue.cjs.map +0 -7
- package/utils/collide/boundingRectToCircle.cjs +0 -36
- package/utils/collide/boundingRectToCircle.cjs.map +0 -7
- package/utils/collide/collideCircleCircle.cjs +0 -35
- package/utils/collide/collideCircleCircle.cjs.map +0 -7
- package/utils/collide/collideCircleRect.cjs +0 -47
- package/utils/collide/collideCircleRect.cjs.map +0 -7
- package/utils/collide/collidePointCircle.cjs +0 -32
- package/utils/collide/collidePointCircle.cjs.map +0 -7
- package/utils/collide/collidePointRect.cjs +0 -32
- package/utils/collide/collidePointRect.cjs.map +0 -7
- package/utils/collide/collideRectRect.cjs +0 -32
- package/utils/collide/collideRectRect.cjs.map +0 -7
- package/utils/collide/index.cjs +0 -47
- package/utils/collide/index.cjs.map +0 -7
- package/utils/css/animate.cjs +0 -202
- package/utils/css/animate.cjs.map +0 -7
- package/utils/css/classes.cjs +0 -51
- package/utils/css/classes.cjs.map +0 -7
- package/utils/css/getOffsetSizes.cjs +0 -48
- package/utils/css/getOffsetSizes.cjs.map +0 -7
- package/utils/css/index.cjs +0 -52
- package/utils/css/index.cjs.map +0 -7
- package/utils/css/matrix.cjs +0 -30
- package/utils/css/matrix.cjs.map +0 -7
- package/utils/css/styles.cjs +0 -45
- package/utils/css/styles.cjs.map +0 -7
- package/utils/css/transform.cjs +0 -91
- package/utils/css/transform.cjs.map +0 -7
- package/utils/css/transition.cjs +0 -145
- package/utils/css/transition.cjs.map +0 -7
- package/utils/css/utils.cjs +0 -32
- package/utils/css/utils.cjs.map +0 -7
- package/utils/debounce.cjs +0 -35
- package/utils/debounce.cjs.map +0 -7
- package/utils/dom/ancestors.cjs +0 -37
- package/utils/dom/ancestors.cjs.map +0 -7
- package/utils/dom/index.cjs +0 -21
- package/utils/dom/index.cjs.map +0 -7
- package/utils/focusTrap.cjs +0 -93
- package/utils/focusTrap.cjs.map +0 -7
- package/utils/focusTrap.js.map +0 -7
- package/utils/getComponentResolver.cjs +0 -38
- package/utils/getComponentResolver.cjs.map +0 -7
- package/utils/has.cjs +0 -29
- package/utils/has.cjs.map +0 -7
- package/utils/history.cjs +0 -92
- package/utils/history.cjs.map +0 -7
- package/utils/index.cjs +0 -76
- package/utils/index.cjs.map +0 -7
- package/utils/is.cjs +0 -41
- package/utils/is.cjs.map +0 -7
- package/utils/keyCodes.cjs +0 -36
- package/utils/keyCodes.cjs.map +0 -7
- package/utils/math/clamp.cjs +0 -29
- package/utils/math/clamp.cjs.map +0 -7
- package/utils/math/clamp01.cjs +0 -40
- package/utils/math/clamp01.cjs.map +0 -7
- package/utils/math/createEases.cjs +0 -33
- package/utils/math/createEases.cjs.map +0 -7
- package/utils/math/damp.cjs +0 -29
- package/utils/math/damp.cjs.map +0 -7
- package/utils/math/ease.cjs +0 -82
- package/utils/math/ease.cjs.map +0 -7
- package/utils/math/index.cjs +0 -54
- package/utils/math/index.cjs.map +0 -7
- package/utils/math/inertiaFinalValue.cjs +0 -47
- package/utils/math/inertiaFinalValue.cjs.map +0 -7
- package/utils/math/lerp.cjs +0 -29
- package/utils/math/lerp.cjs.map +0 -7
- package/utils/math/map.cjs +0 -29
- package/utils/math/map.cjs.map +0 -7
- package/utils/math/round.cjs +0 -29
- package/utils/math/round.cjs.map +0 -7
- package/utils/memoize.cjs +0 -48
- package/utils/memoize.cjs.map +0 -7
- package/utils/nextFrame.cjs +0 -41
- package/utils/nextFrame.cjs.map +0 -7
- package/utils/nextMicrotask.cjs +0 -30
- package/utils/nextMicrotask.cjs.map +0 -7
- package/utils/nextTick.cjs +0 -31
- package/utils/nextTick.cjs.map +0 -7
- package/utils/noop.cjs +0 -32
- package/utils/noop.cjs.map +0 -7
- package/utils/object/autoBind.cjs +0 -60
- package/utils/object/autoBind.cjs.map +0 -7
- package/utils/object/autoBind.d.ts +0 -14
- package/utils/object/autoBind.js +0 -28
- package/utils/object/autoBind.js.map +0 -7
- package/utils/object/getAllProperties.cjs +0 -39
- package/utils/object/getAllProperties.cjs.map +0 -7
- package/utils/object/index.cjs +0 -39
- package/utils/object/index.cjs.map +0 -7
- package/utils/object/index.d.ts +0 -2
- package/utils/object/index.js +0 -7
- package/utils/object/index.js.map +0 -7
- package/utils/scheduler.cjs +0 -75
- package/utils/scheduler.cjs.map +0 -7
- package/utils/scrollTo.cjs +0 -88
- package/utils/scrollTo.cjs.map +0 -7
- package/utils/string/endsWith.cjs +0 -35
- package/utils/string/endsWith.cjs.map +0 -7
- package/utils/string/index.cjs +0 -58
- package/utils/string/index.cjs.map +0 -7
- package/utils/string/startsWith.cjs +0 -35
- package/utils/string/startsWith.cjs.map +0 -7
- package/utils/string/withLeadingCharacters.cjs +0 -40
- package/utils/string/withLeadingCharacters.cjs.map +0 -7
- package/utils/string/withLeadingSlash.cjs +0 -40
- package/utils/string/withLeadingSlash.cjs.map +0 -7
- package/utils/string/withTrailingCharacters.cjs +0 -40
- package/utils/string/withTrailingCharacters.cjs.map +0 -7
- package/utils/string/withTrailingSlash.cjs +0 -40
- package/utils/string/withTrailingSlash.cjs.map +0 -7
- package/utils/string/withoutLeadingCharacters.cjs +0 -29
- package/utils/string/withoutLeadingCharacters.cjs.map +0 -7
- package/utils/string/withoutLeadingCharactersRecursive.cjs +0 -45
- package/utils/string/withoutLeadingCharactersRecursive.cjs.map +0 -7
- package/utils/string/withoutLeadingSlash.cjs +0 -40
- package/utils/string/withoutLeadingSlash.cjs.map +0 -7
- package/utils/string/withoutTrailingCharacters.cjs +0 -29
- package/utils/string/withoutTrailingCharacters.cjs.map +0 -7
- package/utils/string/withoutTrailingCharactersRecursive.cjs +0 -45
- package/utils/string/withoutTrailingCharactersRecursive.cjs.map +0 -7
- package/utils/string/withoutTrailingSlash.cjs +0 -40
- package/utils/string/withoutTrailingSlash.cjs.map +0 -7
- package/utils/throttle.cjs +0 -37
- package/utils/throttle.cjs.map +0 -7
- package/utils/tween.cjs +0 -122
- package/utils/tween.cjs.map +0 -7
- package/utils/wait.cjs +0 -31
- package/utils/wait.cjs.map +0 -7
package/utils/is.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const isDev = typeof __DEV__ !== "undefined" && __DEV__;
|
|
2
|
+
const isNull = (value) => value === null;
|
|
2
3
|
const isFunction = (value) => typeof value === "function";
|
|
3
4
|
const isDefined = (value) => typeof value !== "undefined";
|
|
4
5
|
const isString = (value) => typeof value === "string";
|
|
@@ -6,12 +7,28 @@ const isObject = (value) => typeof value === "object" && !!value && value.toStri
|
|
|
6
7
|
const isNumber = (value) => typeof value === "number" && !Number.isNaN(value);
|
|
7
8
|
const isBoolean = (value) => typeof value === "boolean";
|
|
8
9
|
const isArray = Array.isArray;
|
|
10
|
+
const isEmptyString = (value) => isString(value) && value.length === 0;
|
|
11
|
+
const isEmpty = (value) => {
|
|
12
|
+
if (isNull(value) || !isDefined(value)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (isString(value) || isArray(value)) {
|
|
16
|
+
return value.length === 0;
|
|
17
|
+
}
|
|
18
|
+
if (isObject(value)) {
|
|
19
|
+
return value.constructor === Object && Object.keys(value).length === 0;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
9
23
|
export {
|
|
10
24
|
isArray,
|
|
11
25
|
isBoolean,
|
|
12
26
|
isDefined,
|
|
13
27
|
isDev,
|
|
28
|
+
isEmpty,
|
|
29
|
+
isEmptyString,
|
|
14
30
|
isFunction,
|
|
31
|
+
isNull,
|
|
15
32
|
isNumber,
|
|
16
33
|
isObject,
|
|
17
34
|
isString
|
package/utils/is.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/is.ts"],
|
|
4
|
-
"sourcesContent": ["// eslint-disable-next-line no-undef\nexport const isDev = typeof __DEV__ !== 'undefined' && __DEV__;\n\n/**\n * Test if the given value is a function.\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport const isFunction = (value: unknown): value is Function => typeof value === 'function';\n\n/**\n * Test if a value is defined or not.\n */\nexport const isDefined = (value: unknown): boolean => typeof value !== 'undefined';\n\n/**\n * Test if value is a string.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Test if the given value is an object.\n */\nexport const isObject = (value: unknown): boolean =>\n typeof value === 'object' && !!value && value.toString() === '[object Object]';\n\n/**\n * Test if a given value is a number.\n */\nexport const isNumber = (value: unknown): value is number =>\n typeof value === 'number' && !Number.isNaN(value);\n\n/**\n * Test if a given value is a boolean.\n */\nexport const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';\n\n// eslint-disable-next-line prefer-destructuring\nexport const isArray = Array.isArray;\n"],
|
|
5
|
-
"mappings": "AACO,MAAM,QAAQ,OAAO,YAAY,eAAe;
|
|
4
|
+
"sourcesContent": ["// eslint-disable-next-line no-undef\nexport const isDev = typeof __DEV__ !== 'undefined' && __DEV__;\n\n/**\n * Test is the given value is null.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Test if the given value is a function.\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport const isFunction = (value: unknown): value is Function => typeof value === 'function';\n\n/**\n * Test if a value is defined or not.\n */\nexport const isDefined = (value: unknown): boolean => typeof value !== 'undefined';\n\n/**\n * Test if value is a string.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Test if the given value is an object.\n */\nexport const isObject = (value: unknown): boolean =>\n typeof value === 'object' && !!value && value.toString() === '[object Object]';\n\n/**\n * Test if a given value is a number.\n */\nexport const isNumber = (value: unknown): value is number =>\n typeof value === 'number' && !Number.isNaN(value);\n\n/**\n * Test if a given value is a boolean.\n */\nexport const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';\n\n// eslint-disable-next-line prefer-destructuring\nexport const isArray = Array.isArray;\n\n/**\n * Test if a given value is an empty string.\n */\nexport const isEmptyString = (value?: unknown): boolean => isString(value) && value.length === 0;\n\n/**\n * Test if the given value is empty.\n */\nexport const isEmpty = (value?) => {\n if (isNull(value) || !isDefined(value)) {\n return true;\n }\n\n if (isString(value) || isArray(value)) {\n return value.length === 0;\n }\n\n if (isObject(value)) {\n return value.constructor === Object && Object.keys(value).length === 0;\n }\n\n return false;\n};\n"],
|
|
5
|
+
"mappings": "AACO,MAAM,QAAQ,OAAO,YAAY,eAAe;AAKhD,MAAM,SAAS,CAAC,UAAkC,UAAU;AAM5D,MAAM,aAAa,CAAC,UAAsC,OAAO,UAAU;AAK3E,MAAM,YAAY,CAAC,UAA4B,OAAO,UAAU;AAKhE,MAAM,WAAW,CAAC,UAAoC,OAAO,UAAU;AAKvE,MAAM,WAAW,CAAC,UACvB,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,SAAS,MAAM;AAKxD,MAAM,WAAW,CAAC,UACvB,OAAO,UAAU,YAAY,CAAC,OAAO,MAAM,KAAK;AAK3C,MAAM,YAAY,CAAC,UAAqC,OAAO,UAAU;AAGzE,MAAM,UAAU,MAAM;AAKtB,MAAM,gBAAgB,CAAC,UAA6B,SAAS,KAAK,KAAK,MAAM,WAAW;AAKxF,MAAM,UAAU,CAAC,UAAW;AACjC,MAAI,OAAO,KAAK,KAAK,CAAC,UAAU,KAAK,GAAG;AACtC,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,KAAK,KAAK,QAAQ,KAAK,GAAG;AACrC,WAAO,MAAM,WAAW;AAAA,EAC1B;AAEA,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,MAAM,gBAAgB,UAAU,OAAO,KAAK,KAAK,EAAE,WAAW;AAAA,EACvE;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/math/createRange.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Create an array from a given range and with the given incremental step.\n */\nexport function createRange(min: number, max: number, step: number): number[] {\n const result: number[] = [];\n let value = min;\n\n while (value <= max) {\n result.push(value);\n value += step;\n }\n\n return result;\n}\n"],
|
|
5
|
+
"mappings": "AAGO,SAAS,YAAY,KAAa,KAAa,MAAwB;AAC5E,QAAM,SAAmB,CAAC;AAC1B,MAAI,QAAQ;AAEZ,SAAO,SAAS,KAAK;AACnB,WAAO,KAAK,KAAK;AACjB,aAAS;AAAA,EACX;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/utils/math/ease.d.ts
CHANGED
package/utils/math/ease.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createEaseOut, createEaseInOut } from "./createEases.js";
|
|
2
|
+
import { noopValue } from "../noop.js";
|
|
2
3
|
function easeInQuad(progress) {
|
|
3
4
|
return progress ** 2;
|
|
4
5
|
}
|
|
@@ -49,6 +50,7 @@ export {
|
|
|
49
50
|
easeInQuart,
|
|
50
51
|
easeInQuint,
|
|
51
52
|
easeInSine,
|
|
53
|
+
noopValue as easeLinear,
|
|
52
54
|
easeOutCirc,
|
|
53
55
|
easeOutCubic,
|
|
54
56
|
easeOutExpo,
|
package/utils/math/ease.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/math/ease.ts"],
|
|
4
|
-
"sourcesContent": ["import { createEaseOut, createEaseInOut } from './createEases.js';\n\n/**\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInQuad(progress: number) {\n return progress ** 2;\n}\n\nexport const easeOutQuad = createEaseOut(easeInQuad);\nexport const easeInOutQuad = createEaseInOut(easeInQuad);\n\n/**\n * Ease in cubic.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInCubic(progress: number) {\n return progress ** 3;\n}\n\nexport const easeOutCubic = createEaseOut(easeInCubic);\nexport const easeInOutCubic = createEaseInOut(easeInCubic);\n\n/**\n * Ease in quart.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInQuart(progress: number) {\n return progress ** 4;\n}\n\nexport const easeOutQuart = createEaseOut(easeInQuart);\nexport const easeInOutQuart = createEaseInOut(easeInQuart);\n\n/**\n * Ease in quint.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInQuint(progress: number) {\n return progress ** 5;\n}\n\nexport const easeOutQuint = createEaseOut(easeInQuint);\nexport const easeInOutQuint = createEaseInOut(easeInQuint);\n\n/**\n * Ease in sine.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInSine(progress: number) {\n return progress === 1 ? 1 : -Math.cos((progress * Math.PI) / 2) + 1;\n}\n\nexport const easeOutSine = createEaseOut(easeInSine);\nexport const easeInOutSine = createEaseInOut(easeInSine);\n\n/**\n * Ease in circ.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInCirc(progress: number) {\n return -(Math.sqrt(1 - progress * progress) - 1);\n}\n\nexport const easeOutCirc = createEaseOut(easeInCirc);\nexport const easeInOutCirc = createEaseInOut(easeInCirc);\n\n/**\n * Ease in exponential.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInExpo(progress: number) {\n return progress === 0 ? 0 : 2 ** (10 * (progress - 1));\n}\n\nexport const easeOutExpo = createEaseOut(easeInExpo);\nexport const easeInOutExpo = createEaseInOut(easeInExpo);\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,eAAe,uBAAuB;
|
|
4
|
+
"sourcesContent": ["import { createEaseOut, createEaseInOut } from './createEases.js';\n\nexport { noopValue as easeLinear } from '../noop.js';\n\n/**\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInQuad(progress: number) {\n return progress ** 2;\n}\n\nexport const easeOutQuad = createEaseOut(easeInQuad);\nexport const easeInOutQuad = createEaseInOut(easeInQuad);\n\n/**\n * Ease in cubic.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInCubic(progress: number) {\n return progress ** 3;\n}\n\nexport const easeOutCubic = createEaseOut(easeInCubic);\nexport const easeInOutCubic = createEaseInOut(easeInCubic);\n\n/**\n * Ease in quart.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInQuart(progress: number) {\n return progress ** 4;\n}\n\nexport const easeOutQuart = createEaseOut(easeInQuart);\nexport const easeInOutQuart = createEaseInOut(easeInQuart);\n\n/**\n * Ease in quint.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInQuint(progress: number) {\n return progress ** 5;\n}\n\nexport const easeOutQuint = createEaseOut(easeInQuint);\nexport const easeInOutQuint = createEaseInOut(easeInQuint);\n\n/**\n * Ease in sine.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInSine(progress: number) {\n return progress === 1 ? 1 : -Math.cos((progress * Math.PI) / 2) + 1;\n}\n\nexport const easeOutSine = createEaseOut(easeInSine);\nexport const easeInOutSine = createEaseInOut(easeInSine);\n\n/**\n * Ease in circ.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInCirc(progress: number) {\n return -(Math.sqrt(1 - progress * progress) - 1);\n}\n\nexport const easeOutCirc = createEaseOut(easeInCirc);\nexport const easeInOutCirc = createEaseInOut(easeInCirc);\n\n/**\n * Ease in exponential.\n *\n * @param {number} progress Progress value betwen 0 and 1.\n * @returns {number} Eased value between 0 and 1.\n */\nexport function easeInExpo(progress: number) {\n return progress === 0 ? 0 : 2 ** (10 * (progress - 1));\n}\n\nexport const easeOutExpo = createEaseOut(easeInExpo);\nexport const easeInOutExpo = createEaseInOut(easeInExpo);\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,eAAe,uBAAuB;AAE/C,SAAsB,iBAAkB;AAMjC,SAAS,WAAW,UAAkB;AAC3C,SAAO,YAAY;AACrB;AAEO,MAAM,cAAc,cAAc,UAAU;AAC5C,MAAM,gBAAgB,gBAAgB,UAAU;AAQhD,SAAS,YAAY,UAAkB;AAC5C,SAAO,YAAY;AACrB;AAEO,MAAM,eAAe,cAAc,WAAW;AAC9C,MAAM,iBAAiB,gBAAgB,WAAW;AAQlD,SAAS,YAAY,UAAkB;AAC5C,SAAO,YAAY;AACrB;AAEO,MAAM,eAAe,cAAc,WAAW;AAC9C,MAAM,iBAAiB,gBAAgB,WAAW;AAQlD,SAAS,YAAY,UAAkB;AAC5C,SAAO,YAAY;AACrB;AAEO,MAAM,eAAe,cAAc,WAAW;AAC9C,MAAM,iBAAiB,gBAAgB,WAAW;AAQlD,SAAS,WAAW,UAAkB;AAC3C,SAAO,aAAa,IAAI,IAAI,CAAC,KAAK,IAAK,WAAW,KAAK,KAAM,CAAC,IAAI;AACpE;AAEO,MAAM,cAAc,cAAc,UAAU;AAC5C,MAAM,gBAAgB,gBAAgB,UAAU;AAQhD,SAAS,WAAW,UAAkB;AAC3C,SAAO,EAAE,KAAK,KAAK,IAAI,WAAW,QAAQ,IAAI;AAChD;AAEO,MAAM,cAAc,cAAc,UAAU;AAC5C,MAAM,gBAAgB,gBAAgB,UAAU;AAQhD,SAAS,WAAW,UAAkB;AAC3C,SAAO,aAAa,IAAI,IAAI,MAAM,MAAM,WAAW;AACrD;AAEO,MAAM,cAAc,cAAc,UAAU;AAC5C,MAAM,gBAAgB,gBAAgB,UAAU;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/math/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export * as ease from './ease.js';
|
|
2
|
+
export * from './createEases.js';
|
|
3
|
+
export * from './ease.js';
|
|
4
|
+
export { createRange } from './createRange.js';
|
|
1
5
|
export { default as clamp } from './clamp.js';
|
|
2
6
|
export { default as clamp01 } from './clamp01.js';
|
|
3
7
|
export { default as damp } from './damp.js';
|
|
@@ -5,6 +9,4 @@ export { default as inertiaFinalValue } from './inertiaFinalValue.js';
|
|
|
5
9
|
export { default as lerp } from './lerp.js';
|
|
6
10
|
export { default as map } from './map.js';
|
|
7
11
|
export { default as round } from './round.js';
|
|
8
|
-
export
|
|
9
|
-
export * as ease from './ease.js';
|
|
10
|
-
export * from './createEases.js';
|
|
12
|
+
export { mean } from './mean.js';
|
package/utils/math/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import * as ease from "./ease.js";
|
|
2
|
+
export * from "./createEases.js";
|
|
3
|
+
export * from "./ease.js";
|
|
4
|
+
import { createRange } from "./createRange.js";
|
|
1
5
|
import { default as default2 } from "./clamp.js";
|
|
2
6
|
import { default as default3 } from "./clamp01.js";
|
|
3
7
|
import { default as default4 } from "./damp.js";
|
|
@@ -5,17 +9,17 @@ import { default as default5 } from "./inertiaFinalValue.js";
|
|
|
5
9
|
import { default as default6 } from "./lerp.js";
|
|
6
10
|
import { default as default7 } from "./map.js";
|
|
7
11
|
import { default as default8 } from "./round.js";
|
|
8
|
-
|
|
9
|
-
import * as ease from "./ease.js";
|
|
10
|
-
export * from "./createEases.js";
|
|
12
|
+
import { mean } from "./mean.js";
|
|
11
13
|
export {
|
|
12
14
|
default2 as clamp,
|
|
13
15
|
default3 as clamp01,
|
|
16
|
+
createRange,
|
|
14
17
|
default4 as damp,
|
|
15
18
|
ease,
|
|
16
19
|
default5 as inertiaFinalValue,
|
|
17
20
|
default6 as lerp,
|
|
18
21
|
default7 as map,
|
|
22
|
+
mean,
|
|
19
23
|
default8 as round
|
|
20
24
|
};
|
|
21
25
|
//# sourceMappingURL=index.js.map
|
package/utils/math/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/math/index.ts"],
|
|
4
|
-
"sourcesContent": ["export
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,gBAAwB;AACjC,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAoC;AAC7C,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAsB;AAC/B,SAAoB,WAAXA,gBAAwB;AACjC,
|
|
4
|
+
"sourcesContent": ["export * as ease from './ease.js';\nexport * from './createEases.js';\nexport * from './ease.js';\nexport { createRange } from './createRange.js';\nexport { default as clamp } from './clamp.js';\nexport { default as clamp01 } from './clamp01.js';\nexport { default as damp } from './damp.js';\nexport { default as inertiaFinalValue } from './inertiaFinalValue.js';\nexport { default as lerp } from './lerp.js';\nexport { default as map } from './map.js';\nexport { default as round } from './round.js';\nexport { mean } from './mean.js';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,UAAU;AACtB,cAAc;AACd,cAAc;AACd,SAAS,mBAAmB;AAC5B,SAAoB,WAAXA,gBAAwB;AACjC,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAoC;AAC7C,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAsB;AAC/B,SAAoB,WAAXA,gBAAwB;AACjC,SAAS,YAAY;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mean(numbers: number[]): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function mean(numbers) {
|
|
2
|
+
if (numbers.length === 0) {
|
|
3
|
+
return 0;
|
|
4
|
+
}
|
|
5
|
+
if (numbers.length === 1) {
|
|
6
|
+
return numbers[0];
|
|
7
|
+
}
|
|
8
|
+
let sum = 0;
|
|
9
|
+
for (const value of numbers) {
|
|
10
|
+
sum += value;
|
|
11
|
+
}
|
|
12
|
+
return sum / numbers.length;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
mean
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=mean.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/math/mean.ts"],
|
|
4
|
+
"sourcesContent": ["export function mean(numbers: number[]) {\n if (numbers.length === 0) {\n return 0;\n }\n\n if (numbers.length === 1) {\n return numbers[0];\n }\n\n let sum = 0;\n for (const value of numbers) {\n sum += value;\n }\n\n return sum / numbers.length;\n}\n"],
|
|
5
|
+
"mappings": "AAAO,SAAS,KAAK,SAAmB;AACtC,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO,QAAQ,CAAC;AAAA,EAClB;AAEA,MAAI,MAAM;AACV,aAAW,SAAS,SAAS;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,QAAQ;AACvB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/utils/memo.d.ts
ADDED
package/utils/memo.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function memo(fn) {
|
|
2
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3
|
+
return function cached(...args) {
|
|
4
|
+
const key = args.join("");
|
|
5
|
+
if (!cache.has(key)) {
|
|
6
|
+
cache.set(key, fn(...args));
|
|
7
|
+
}
|
|
8
|
+
return cache.get(key);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
memo
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=memo.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/utils/memo.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Memoize the result of a function with a single argument indefinitely.\n * This is a simpler implementation of the `memoize` function.\n */\nexport function memo<T extends (...args: unknown[]) => unknown>(fn: T): T {\n const cache = new Map<string, ReturnType<T>>();\n\n // @ts-ignore\n return function cached(...args) {\n const key = args.join('');\n if (!cache.has(key)) {\n cache.set(key, fn(...args) as ReturnType<T>);\n }\n return cache.get(key);\n };\n}\n"],
|
|
5
|
+
"mappings": "AAIO,SAAS,KAAgD,IAAU;AACxE,QAAM,QAAQ,oBAAI,IAA2B;AAG7C,SAAO,SAAS,UAAU,MAAM;AAC9B,UAAM,MAAM,KAAK,KAAK,EAAE;AACxB,QAAI,CAAC,MAAM,IAAI,GAAG,GAAG;AACnB,YAAM,IAAI,KAAK,GAAG,GAAG,IAAI,CAAkB;AAAA,IAC7C;AACA,WAAO,MAAM,IAAI,GAAG;AAAA,EACtB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/utils/nextFrame.d.ts
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
* RequestAnimation frame polyfill.
|
|
3
|
-
*
|
|
4
|
-
* @see https://github.com/vuejs/vue/blob/ec78fc8b6d03e59da669be1adf4b4b5abf670a34/dist/vue.runtime.esm.js#L7355
|
|
5
|
-
*/
|
|
6
|
-
export declare function getRaf(): (handler: Function) => number;
|
|
7
|
-
/**
|
|
8
|
-
* Get a function to cancel the method returned by `getRaf()`.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getCancelRaf(): (id: number) => void;
|
|
1
|
+
type Callback = (time?: DOMHighResTimeStamp) => any;
|
|
11
2
|
/**
|
|
12
3
|
* Wait for the next frame to execute a function.
|
|
13
|
-
*
|
|
14
|
-
* @template {() => any} T
|
|
15
|
-
* @param {T} [fn] The callback function to execute.
|
|
16
|
-
* @returns {Promise<T extends Function ? ReturnType<T> : undefined>} A Promise resolving when the next frame is reached.
|
|
17
|
-
* @example
|
|
18
|
-
* ```js
|
|
19
|
-
* nextFrame(() => console.log('hello world'));
|
|
20
|
-
*
|
|
21
|
-
* await nextFrame();
|
|
22
|
-
* console.log('hello world');
|
|
23
|
-
* ```
|
|
24
4
|
*/
|
|
25
|
-
export declare function nextFrame
|
|
5
|
+
export declare function nextFrame(): Promise<DOMHighResTimeStamp>;
|
|
6
|
+
export declare function nextFrame<T extends Callback>(callback?: T): Promise<ReturnType<T>>;
|
|
7
|
+
export {};
|
package/utils/nextFrame.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { isFunction } from "./is.js";
|
|
2
2
|
import { hasWindow } from "./has.js";
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
function getCancelRaf() {
|
|
7
|
-
return hasWindow() && window.cancelAnimationFrame ? window.cancelAnimationFrame.bind(window) : clearTimeout;
|
|
8
|
-
}
|
|
9
|
-
function nextFrame(fn) {
|
|
3
|
+
function nextFrame(callback) {
|
|
4
|
+
const fn = hasWindow() ? window?.requestAnimationFrame ?? setTimeout : setTimeout;
|
|
10
5
|
return new Promise((resolve) => {
|
|
11
|
-
|
|
6
|
+
fn((time) => resolve(isFunction(callback) ? callback(time) : time));
|
|
12
7
|
});
|
|
13
8
|
}
|
|
14
9
|
export {
|
|
15
|
-
getCancelRaf,
|
|
16
|
-
getRaf,
|
|
17
10
|
nextFrame
|
|
18
11
|
};
|
|
19
12
|
//# sourceMappingURL=nextFrame.js.map
|
package/utils/nextFrame.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/nextFrame.ts"],
|
|
4
|
-
"sourcesContent": ["import { isFunction } from './is.js';\nimport { hasWindow } from './has.js';\n\n
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import { isFunction } from './is.js';\nimport { hasWindow } from './has.js';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Callback = (time?: DOMHighResTimeStamp) => any;\n\n/**\n * Wait for the next frame to execute a function.\n */\nexport function nextFrame(): Promise<DOMHighResTimeStamp>;\nexport function nextFrame<T extends Callback>(callback?: T): Promise<ReturnType<T>>;\nexport function nextFrame<T extends Callback>(callback?: T): Promise<ReturnType<T>> {\n const fn = hasWindow() ? window?.requestAnimationFrame ?? setTimeout : setTimeout;\n return new Promise((resolve) => {\n fn((time) => resolve(isFunction(callback) ? callback(time) : time));\n });\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAUnB,SAAS,UAA8B,UAAsC;AAClF,QAAM,KAAK,UAAU,IAAI,QAAQ,yBAAyB,aAAa;AACvE,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,OAAG,CAAC,SAAS,QAAQ,WAAW,QAAQ,IAAI,SAAS,IAAI,IAAI,IAAI,CAAC;AAAA,EACpE,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/nextMicrotask.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
type Callback = (...args: any[]) => any;
|
|
1
2
|
/**
|
|
2
3
|
* Wait for the next microtask.
|
|
3
4
|
*/
|
|
4
|
-
export
|
|
5
|
+
export declare function nextMicrotask(): Promise<void>;
|
|
6
|
+
export declare function nextMicrotask<T extends Callback>(callback?: T): Promise<ReturnType<T>>;
|
|
7
|
+
export {};
|
package/utils/nextMicrotask.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isFunction } from "./is.js";
|
|
2
|
-
async function nextMicrotask(
|
|
3
|
-
return Promise.resolve().then(() => isFunction(
|
|
2
|
+
async function nextMicrotask(callback) {
|
|
3
|
+
return Promise.resolve().then(() => isFunction(callback) && callback());
|
|
4
4
|
}
|
|
5
5
|
export {
|
|
6
|
-
nextMicrotask
|
|
6
|
+
nextMicrotask
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=nextMicrotask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/nextMicrotask.ts"],
|
|
4
|
-
"sourcesContent": ["import { isFunction } from './is.js';\n\n/**\n * Wait for the next microtask.\n */\nexport
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;
|
|
4
|
+
"sourcesContent": ["import { isFunction } from './is.js';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Callback = (...args: any[]) => any;\n\n/**\n * Wait for the next microtask.\n */\nexport async function nextMicrotask(): Promise<void>;\nexport async function nextMicrotask<T extends Callback>(callback?: T): Promise<ReturnType<T>>;\nexport async function nextMicrotask<T extends Callback>(callback?: T): Promise<ReturnType<T>> {\n return Promise.resolve().then(() => isFunction(callback) && callback());\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAU3B,eAAsB,cAAkC,UAAsC;AAC5F,SAAO,QAAQ,QAAQ,EAAE,KAAK,MAAM,WAAW,QAAQ,KAAK,SAAS,CAAC;AACxE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/nextTick.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
type Callback = (...args: any[]) => any;
|
|
1
2
|
/**
|
|
2
3
|
* Wait for the next tick.
|
|
3
4
|
*/
|
|
4
|
-
export
|
|
5
|
+
export declare function nextTick(): Promise<void>;
|
|
6
|
+
export declare function nextTick<T extends Callback>(callback?: T): Promise<ReturnType<T>>;
|
|
7
|
+
export {};
|
package/utils/nextTick.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isFunction } from "./is.js";
|
|
2
2
|
import { wait } from "./wait.js";
|
|
3
|
-
async function nextTick(
|
|
4
|
-
return wait().then(isFunction(
|
|
3
|
+
async function nextTick(callback) {
|
|
4
|
+
return wait().then(isFunction(callback) && callback);
|
|
5
5
|
}
|
|
6
6
|
export {
|
|
7
|
-
nextTick
|
|
7
|
+
nextTick
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=nextTick.js.map
|
package/utils/nextTick.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/nextTick.ts"],
|
|
4
|
-
"sourcesContent": ["import { isFunction } from './is.js';\nimport { wait } from './wait.js';\n\n
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAAY;
|
|
4
|
+
"sourcesContent": ["import { isFunction } from './is.js';\nimport { wait } from './wait.js';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Callback = (...args: any[]) => any;\n\n/**\n * Wait for the next tick.\n */\nexport async function nextTick(): Promise<void>;\nexport async function nextTick<T extends Callback>(callback?: T): Promise<ReturnType<T>>;\nexport async function nextTick<T extends Callback>(callback?: T): Promise<ReturnType<T>> {\n return wait().then(isFunction(callback) && (callback as ReturnType<T>));\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AAUrB,eAAsB,SAA6B,UAAsC;AACvF,SAAO,KAAK,EAAE,KAAK,WAAW,QAAQ,KAAM,QAA0B;AACxE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a random integer between bounds
|
|
3
|
+
*
|
|
4
|
+
* @param {number} a Lower bound
|
|
5
|
+
* @param {number} b Upper bound
|
|
6
|
+
* @returns {number}
|
|
7
|
+
*/
|
|
8
|
+
export declare function randomInt(a: number, b?: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* Get a random item of an array or a random character of a string
|
|
11
|
+
*
|
|
12
|
+
* @param {T[] | string} items Array or string
|
|
13
|
+
* @returns {T | undefined}
|
|
14
|
+
*/
|
|
15
|
+
export declare function randomItem<T>(items: T[] | string): T | string | undefined;
|
package/utils/random.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isArray, isString } from "./is.js";
|
|
2
|
+
function randomInt(a, b = 0) {
|
|
3
|
+
return Math.floor(Math.random() * (a - b + 1)) + b;
|
|
4
|
+
}
|
|
5
|
+
function randomItem(items) {
|
|
6
|
+
if (!isArray(items) && !isString(items)) {
|
|
7
|
+
throw new Error("randomItem() expects an array or a string as argument.");
|
|
8
|
+
}
|
|
9
|
+
return items.length > 0 ? items[randomInt(items.length - 1)] : void 0;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
randomInt,
|
|
13
|
+
randomItem
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/utils/random.ts"],
|
|
4
|
+
"sourcesContent": ["import { isArray, isString } from './is.js';\n\n/**\n * Get a random integer between bounds\n *\n * @param {number} a Lower bound\n * @param {number} b Upper bound\n * @returns {number}\n */\nexport function randomInt(a: number, b = 0): number {\n return Math.floor(Math.random() * (a - b + 1)) + b;\n}\n\n/**\n * Get a random item of an array or a random character of a string\n *\n * @param {T[] | string} items Array or string\n * @returns {T | undefined}\n */\nexport function randomItem<T>(items: T[] | string): T | string | undefined {\n if (!isArray(items) && !isString(items)) {\n throw new Error('randomItem() expects an array or a string as argument.');\n }\n return items.length > 0 ? items[randomInt(items.length - 1)] : undefined;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,gBAAgB;AAS3B,SAAS,UAAU,GAAW,IAAI,GAAW;AAClD,SAAO,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,IAAI,EAAE,IAAI;AACnD;AAQO,SAAS,WAAc,OAA6C;AACzE,MAAI,CAAC,QAAQ,KAAK,KAAK,CAAC,SAAS,KAAK,GAAG;AACvC,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,SAAO,MAAM,SAAS,IAAI,MAAM,UAAU,MAAM,SAAS,CAAC,CAAC,IAAI;AACjE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/utils/scrollTo.d.ts
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
|
+
import type { TweenOptions } from './tween.js';
|
|
2
|
+
export interface ScrollPosition {
|
|
3
|
+
left: number;
|
|
4
|
+
top: number;
|
|
5
|
+
}
|
|
6
|
+
export type ScrollTarget = string | HTMLElement | number | Partial<ScrollPosition>;
|
|
7
|
+
export interface ScrollToOptions extends TweenOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Root element that will be scrolled.
|
|
10
|
+
*/
|
|
11
|
+
rootElement?: HTMLElement | typeof window;
|
|
12
|
+
/**
|
|
13
|
+
* Scroll direction.
|
|
14
|
+
*/
|
|
15
|
+
axis?: (typeof scrollTo.axis)[keyof typeof scrollTo.axis];
|
|
16
|
+
/**
|
|
17
|
+
* Distance from the target.
|
|
18
|
+
*/
|
|
19
|
+
offset?: number;
|
|
20
|
+
}
|
|
1
21
|
/**
|
|
2
|
-
*
|
|
22
|
+
* Scroll to an element.
|
|
3
23
|
*
|
|
4
|
-
* @returns {Promise<
|
|
24
|
+
* @returns {Promise<ScrollPosition>} A promising resolving with the scroll position.
|
|
5
25
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
26
|
+
export declare function scrollTo(target: string | HTMLElement | number | Partial<ScrollPosition>, { rootElement, axis, offset, ...tweenOptions }?: ScrollToOptions): Promise<ScrollPosition>;
|
|
27
|
+
export declare namespace scrollTo {
|
|
28
|
+
var axis: {
|
|
29
|
+
x: symbol;
|
|
30
|
+
y: symbol;
|
|
31
|
+
both: symbol;
|
|
32
|
+
};
|
|
33
|
+
}
|