@studiometa/js-toolkit 2.7.0 → 2.8.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/Base/features.cjs +1 -3
- package/Base/features.cjs.map +2 -2
- package/Base/features.d.ts +1 -1
- package/Base/features.js +1 -3
- package/Base/features.js.map +2 -2
- package/Base/index.d.ts +10 -10
- package/Base/managers/OptionsManager.d.ts +9 -9
- package/Base/managers/RefsManager.cjs +13 -8
- package/Base/managers/RefsManager.cjs.map +2 -2
- package/Base/managers/RefsManager.js +14 -9
- package/Base/managers/RefsManager.js.map +2 -2
- package/Base/managers/ResponsiveOptionsManager.d.ts +1 -1
- package/Base/managers/ServicesManager.d.ts +2 -2
- package/Base/types.d.ts +1 -1
- package/Base/utils.cjs +15 -1
- package/Base/utils.cjs.map +2 -2
- package/Base/utils.js +15 -1
- package/Base/utils.js.map +2 -2
- package/decorators/index.cjs +1 -1
- package/decorators/index.cjs.map +2 -2
- package/decorators/index.d.ts +1 -1
- package/decorators/index.js +1 -1
- package/decorators/index.js.map +1 -1
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withScrolledInView/index.cjs +22 -0
- package/decorators/withScrolledInView/index.cjs.map +7 -0
- package/decorators/withScrolledInView/index.d.ts +2 -0
- package/decorators/withScrolledInView/index.js +3 -0
- package/decorators/withScrolledInView/index.js.map +7 -0
- package/decorators/withScrolledInView/types.cjs +19 -0
- package/decorators/withScrolledInView/types.cjs.map +7 -0
- package/decorators/withScrolledInView/types.d.ts +2 -0
- package/decorators/withScrolledInView/types.js +1 -0
- package/decorators/withScrolledInView/types.js.map +7 -0
- package/decorators/withScrolledInView/utils.cjs +99 -0
- package/decorators/withScrolledInView/utils.cjs.map +7 -0
- package/decorators/withScrolledInView/utils.d.ts +17 -0
- package/decorators/withScrolledInView/utils.js +77 -0
- package/decorators/withScrolledInView/utils.js.map +7 -0
- package/decorators/{withScrolledInView.cjs → withScrolledInView/withScrolledInView.cjs} +21 -9
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +7 -0
- package/decorators/{withScrolledInView.d.ts → withScrolledInView/withScrolledInView.d.ts} +6 -5
- package/decorators/{withScrolledInView.js → withScrolledInView/withScrolledInView.js} +27 -8
- package/decorators/withScrolledInView/withScrolledInView.js.map +7 -0
- package/helpers/createApp.d.ts +1 -1
- package/helpers/getClosestParent.cjs +3 -11
- package/helpers/getClosestParent.cjs.map +2 -2
- package/helpers/getClosestParent.js +3 -11
- package/helpers/getClosestParent.js.map +2 -2
- package/helpers/importWhenIdle.d.ts +1 -1
- package/package.json +2 -2
- package/services/drag.d.ts +2 -2
- package/services/index.d.ts +7 -7
- package/services/key.d.ts +1 -1
- package/services/load.d.ts +1 -1
- package/services/pointer.d.ts +1 -1
- package/services/raf.d.ts +1 -1
- package/services/resize.d.ts +1 -1
- package/services/scroll.d.ts +1 -1
- package/utils/css/animate.cjs +18 -1
- package/utils/css/animate.cjs.map +3 -3
- package/utils/css/animate.d.ts +6 -3
- package/utils/css/animate.js +18 -1
- package/utils/css/animate.js.map +3 -3
- package/utils/css/getOffsetSizes.cjs +1 -1
- package/utils/css/getOffsetSizes.cjs.map +1 -1
- package/utils/css/getOffsetSizes.js +1 -1
- package/utils/css/getOffsetSizes.js.map +1 -1
- package/utils/css/matrix.d.ts +1 -1
- package/utils/css/transform.d.ts +1 -1
- package/utils/css/transition.d.ts +2 -2
- package/utils/dom/ancestors.cjs +37 -0
- package/utils/dom/ancestors.cjs.map +7 -0
- package/utils/dom/ancestors.d.ts +8 -0
- package/utils/dom/ancestors.js +15 -0
- package/utils/dom/ancestors.js.map +7 -0
- package/utils/dom/index.cjs +21 -0
- package/utils/dom/index.cjs.map +7 -0
- package/utils/dom/index.d.ts +1 -0
- package/utils/dom/index.js +2 -0
- package/utils/dom/index.js.map +7 -0
- package/utils/index.cjs +1 -0
- package/utils/index.cjs.map +2 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/index.js.map +2 -2
- package/utils/is.cjs +1 -1
- package/utils/is.cjs.map +2 -2
- package/utils/is.js +1 -1
- package/utils/is.js.map +2 -2
- package/utils/math/createEases.d.ts +1 -1
- package/utils/tween.cjs +3 -2
- package/utils/tween.cjs.map +2 -2
- package/utils/tween.d.ts +2 -1
- package/utils/tween.js +3 -2
- package/utils/tween.js.map +2 -2
- package/decorators/withScrolledInView.cjs.map +0 -7
- package/decorators/withScrolledInView.js.map +0 -7
package/services/raf.d.ts
CHANGED
package/services/resize.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ServiceInterface } from './index.js';
|
|
2
|
-
export
|
|
2
|
+
export type ResizeService = ServiceInterface<ResizeServiceProps>;
|
|
3
3
|
export interface ResizeServiceProps {
|
|
4
4
|
width: number;
|
|
5
5
|
height: number;
|
package/services/scroll.d.ts
CHANGED
package/utils/css/animate.cjs
CHANGED
|
@@ -96,6 +96,17 @@ function render(element, from, to, progress) {
|
|
|
96
96
|
} else if (element.style.transformOrigin) {
|
|
97
97
|
transformOrigin = "";
|
|
98
98
|
}
|
|
99
|
+
let customProperties = false;
|
|
100
|
+
if ((0, import_is.isDefined)(from.vars) && (0, import_is.isDefined)(to.vars)) {
|
|
101
|
+
customProperties = from.vars.map((customPropertyName) => {
|
|
102
|
+
const customPropertyValue = (0, import_math.lerp)(
|
|
103
|
+
from[customPropertyName],
|
|
104
|
+
to[customPropertyName],
|
|
105
|
+
stepProgress
|
|
106
|
+
);
|
|
107
|
+
return [customPropertyName, customPropertyValue];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
99
110
|
const props = Object.fromEntries(
|
|
100
111
|
import_transform.TRANSFORM_PROPS.filter((name) => (0, import_is.isDefined)(from[name]) || (0, import_is.isDefined)(to[name])).map((name) => [
|
|
101
112
|
name,
|
|
@@ -109,6 +120,11 @@ function render(element, from, to, progress) {
|
|
|
109
120
|
if (transformOrigin !== false) {
|
|
110
121
|
element.style.transformOrigin = transformOrigin;
|
|
111
122
|
}
|
|
123
|
+
if (customProperties !== false) {
|
|
124
|
+
customProperties.forEach((customProperty) => {
|
|
125
|
+
element.style.setProperty(customProperty[0], customProperty[1].toString());
|
|
126
|
+
});
|
|
127
|
+
}
|
|
112
128
|
(0, import_transform.default)(element, props);
|
|
113
129
|
});
|
|
114
130
|
});
|
|
@@ -119,7 +135,8 @@ function singleAnimate(element, keyframes, options = {}) {
|
|
|
119
135
|
(keyframe, index) => ({
|
|
120
136
|
...keyframe,
|
|
121
137
|
offset: keyframe.offset ?? index / keyframesCount,
|
|
122
|
-
easing: (0, import_tween.normalizeEase)(keyframe.easing)
|
|
138
|
+
easing: (0, import_tween.normalizeEase)(keyframe.easing),
|
|
139
|
+
vars: Object.keys(keyframe).filter((key2) => key2.startsWith("--"))
|
|
123
140
|
})
|
|
124
141
|
);
|
|
125
142
|
if (!running.has(element)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/css/animate.ts"],
|
|
4
|
-
"sourcesContent": ["import { lerp, map } from '../math/index.js';\nimport { isDefined, isFunction, isNumber } from '../is.js';\nimport transform, { TRANSFORM_PROPS } from './transform.js';\nimport { domScheduler as scheduler } from '../scheduler.js';\nimport { tween, normalizeEase } from '../tween.js';\n// eslint-disable-next-line import/extensions\nimport { eachElements } from './utils.js';\nimport type { TransformProps } from './transform.js';\nimport type { EasingFunction } from '../math/index.js';\nimport type { BezierCurve, TweenOptions } from '../tween.js';\n\nexport type Keyframe = TransformProps & {\n opacity?: number;\n transformOrigin?: string;\n easing?: EasingFunction | BezierCurve;\n offset?: number;\n};\n\nexport type NormalizedKeyframe = Keyframe & {\n easing: EasingFunction;\n offset: number;\n};\n\nexport type Animate = {\n start: () => void;\n pause: () => void;\n play: () => void;\n finish: () => void;\n progress: (value?: number) => number;\n};\n\nlet id = 0;\nconst running = new WeakMap();\n\nconst CSSUnitConverter = {\n '%': (value, getSizeRef) => (value * getSizeRef()) / 100,\n vh: (value) => (value * window.innerHeight) / 100,\n vw: (value) => (value * window.innerWidth) / 100,\n vmin: (value) => (value * Math.min(window.innerWidth, window.innerHeight)) / 100,\n vmax: (value) => (value * Math.max(window.innerWidth, window.innerHeight)) / 100,\n};\n\n/**\n * Get the value from a step property.\n */\nfunction getAnimationStepValue(val: number | [number, string], getSizeRef: () => number): number {\n if (isNumber(val)) {\n return val;\n }\n\n if (!val[1] || !CSSUnitConverter[val[1]]) {\n return val[0];\n }\n\n return CSSUnitConverter[val[1]](val[0], getSizeRef);\n}\n\nconst generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) =>\n lerp(\n getAnimationStepValue(\n fromValue ?? 0,\n /* istanbul ignore next */\n () => element[sizeRef],\n ),\n getAnimationStepValue(toValue ?? 0, () => element[sizeRef]),\n progress,\n );\nconst widthBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetWidth');\nconst heightBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetHeight');\n\nconst generateLerpRenderStrategy = (defaultValue) => (element, fromValue, toValue, progress) =>\n lerp(fromValue ?? defaultValue, toValue ?? defaultValue, progress);\nconst scaleRenderStrategy = generateLerpRenderStrategy(1);\nconst degreesRenderStrategy = generateLerpRenderStrategy(0);\n\nconst transformRenderStrategies = {\n x: widthBasedTranslateRenderStrategy,\n y: heightBasedTranslateRenderStrategy,\n z: widthBasedTranslateRenderStrategy,\n scale: scaleRenderStrategy,\n scaleX: scaleRenderStrategy,\n scaleY: scaleRenderStrategy,\n scaleZ: scaleRenderStrategy,\n skew: degreesRenderStrategy,\n skewX: degreesRenderStrategy,\n skewY: degreesRenderStrategy,\n rotate: degreesRenderStrategy,\n rotateX: degreesRenderStrategy,\n rotateY: degreesRenderStrategy,\n rotateZ: degreesRenderStrategy,\n};\n\n/**\n * Render an element style based on 2 keyframes and a progress value.\n */\nfunction render(\n element: HTMLElement,\n from: NormalizedKeyframe,\n to: NormalizedKeyframe,\n progress: number,\n) {\n const stepProgress = to.easing(map(progress, from.offset, to.offset, 0, 1));\n\n scheduler.read(() => {\n let opacity: false | number | string = false;\n if (isDefined(from.opacity) || isDefined(to.opacity)) {\n opacity = map(stepProgress, 0, 1, from.opacity ?? 1, to.opacity ?? 1);\n } else if (element.style.opacity) {\n opacity = '';\n }\n\n let transformOrigin: false | string = false;\n if (isDefined(to.transformOrigin)) {\n transformOrigin = to.transformOrigin;\n } else if (element.style.transformOrigin) {\n transformOrigin = '';\n }\n\n const props = Object.fromEntries(\n TRANSFORM_PROPS.filter((name) => isDefined(from[name]) || isDefined(to[name])).map((name) => [\n name,\n transformRenderStrategies[name](element, from[name], to[name], stepProgress),\n ]),\n );\n scheduler.write(() => {\n if (opacity !== false) {\n // @ts-ignore\n element.style.opacity = opacity;\n }\n if (transformOrigin !== false) {\n element.style.transformOrigin = transformOrigin;\n }\n transform(element, props);\n });\n });\n}\n\n/**\n * Animate an element.\n */\nfunction singleAnimate(\n element: HTMLElement,\n keyframes: Keyframe[],\n options: TweenOptions = {},\n): Animate {\n const keyframesCount = keyframes.length - 1;\n const normalizedKeyframes = keyframes.map(\n (keyframe, index)
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAC1B,gBAAgD;AAChD,uBAA2C;AAC3C,uBAA0C;AAC1C,mBAAqC;AAErC,mBAA6B;
|
|
6
|
-
"names": ["scheduler", "transform"]
|
|
4
|
+
"sourcesContent": ["import { lerp, map } from '../math/index.js';\nimport { isDefined, isFunction, isNumber } from '../is.js';\nimport transform, { TRANSFORM_PROPS } from './transform.js';\nimport { domScheduler as scheduler } from '../scheduler.js';\nimport { tween, normalizeEase } from '../tween.js';\n// eslint-disable-next-line import/extensions\nimport { eachElements } from './utils.js';\nimport type { TransformProps } from './transform.js';\nimport type { EasingFunction } from '../math/index.js';\nimport type { BezierCurve, TweenOptions } from '../tween.js';\n\nexport type CSSCustomPropertyName = `--${string}`;\n\nexport type Keyframe = TransformProps & {\n opacity?: number;\n transformOrigin?: string;\n easing?: EasingFunction | BezierCurve;\n offset?: number;\n [key: CSSCustomPropertyName]: number;\n};\n\nexport type NormalizedKeyframe = Keyframe & {\n easing: EasingFunction;\n offset: number;\n vars: string[];\n};\n\nexport type Animate = {\n start: () => void;\n pause: () => void;\n play: () => void;\n finish: () => void;\n progress: (value?: number) => number;\n};\n\nlet id = 0;\nconst running = new WeakMap();\n\nconst CSSUnitConverter = {\n '%': (value, getSizeRef) => (value * getSizeRef()) / 100,\n vh: (value) => (value * window.innerHeight) / 100,\n vw: (value) => (value * window.innerWidth) / 100,\n vmin: (value) => (value * Math.min(window.innerWidth, window.innerHeight)) / 100,\n vmax: (value) => (value * Math.max(window.innerWidth, window.innerHeight)) / 100,\n};\n\n/**\n * Get the value from a step property.\n */\nfunction getAnimationStepValue(val: number | [number, string], getSizeRef: () => number): number {\n if (isNumber(val)) {\n return val;\n }\n\n if (!val[1] || !CSSUnitConverter[val[1]]) {\n return val[0];\n }\n\n return CSSUnitConverter[val[1]](val[0], getSizeRef);\n}\n\nconst generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) =>\n lerp(\n getAnimationStepValue(\n fromValue ?? 0,\n /* istanbul ignore next */\n () => element[sizeRef],\n ),\n getAnimationStepValue(toValue ?? 0, () => element[sizeRef]),\n progress,\n );\nconst widthBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetWidth');\nconst heightBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetHeight');\n\nconst generateLerpRenderStrategy = (defaultValue) => (element, fromValue, toValue, progress) =>\n lerp(fromValue ?? defaultValue, toValue ?? defaultValue, progress);\nconst scaleRenderStrategy = generateLerpRenderStrategy(1);\nconst degreesRenderStrategy = generateLerpRenderStrategy(0);\n\nconst transformRenderStrategies = {\n x: widthBasedTranslateRenderStrategy,\n y: heightBasedTranslateRenderStrategy,\n z: widthBasedTranslateRenderStrategy,\n scale: scaleRenderStrategy,\n scaleX: scaleRenderStrategy,\n scaleY: scaleRenderStrategy,\n scaleZ: scaleRenderStrategy,\n skew: degreesRenderStrategy,\n skewX: degreesRenderStrategy,\n skewY: degreesRenderStrategy,\n rotate: degreesRenderStrategy,\n rotateX: degreesRenderStrategy,\n rotateY: degreesRenderStrategy,\n rotateZ: degreesRenderStrategy,\n};\n\n/**\n * Render an element style based on 2 keyframes and a progress value.\n */\nfunction render(\n element: HTMLElement,\n from: NormalizedKeyframe,\n to: NormalizedKeyframe,\n progress: number,\n) {\n const stepProgress = to.easing(map(progress, from.offset, to.offset, 0, 1));\n\n scheduler.read(() => {\n let opacity: false | number | string = false;\n if (isDefined(from.opacity) || isDefined(to.opacity)) {\n opacity = map(stepProgress, 0, 1, from.opacity ?? 1, to.opacity ?? 1);\n } else if (element.style.opacity) {\n opacity = '';\n }\n\n let transformOrigin: false | string = false;\n if (isDefined(to.transformOrigin)) {\n transformOrigin = to.transformOrigin;\n } else if (element.style.transformOrigin) {\n transformOrigin = '';\n }\n\n let customProperties: false | [string, number][] = false;\n if (isDefined(from.vars) && isDefined(to.vars)) {\n customProperties = from.vars.map((customPropertyName) => {\n const customPropertyValue = lerp(\n from[customPropertyName],\n to[customPropertyName],\n stepProgress,\n );\n return [customPropertyName, customPropertyValue];\n });\n }\n\n const props = Object.fromEntries(\n TRANSFORM_PROPS.filter((name) => isDefined(from[name]) || isDefined(to[name])).map((name) => [\n name,\n transformRenderStrategies[name](element, from[name], to[name], stepProgress),\n ]),\n );\n scheduler.write(() => {\n if (opacity !== false) {\n // @ts-ignore\n element.style.opacity = opacity;\n }\n if (transformOrigin !== false) {\n element.style.transformOrigin = transformOrigin;\n }\n if (customProperties !== false) {\n customProperties.forEach((customProperty) => {\n element.style.setProperty(customProperty[0], customProperty[1].toString());\n });\n }\n transform(element, props);\n });\n });\n}\n\n/**\n * Animate an element.\n */\nfunction singleAnimate(\n element: HTMLElement,\n keyframes: Keyframe[],\n options: TweenOptions = {},\n): Animate {\n const keyframesCount = keyframes.length - 1;\n const normalizedKeyframes = keyframes.map(\n (keyframe, index): NormalizedKeyframe => ({\n ...keyframe,\n offset: keyframe.offset ?? index / keyframesCount,\n easing: normalizeEase(keyframe.easing),\n vars: Object.keys(keyframe).filter((key) => key.startsWith('--')),\n }),\n );\n\n if (!running.has(element)) {\n running.set(element, new Map());\n }\n\n const key = `animate-${id}`;\n id += 1;\n\n /**\n * Set the progress value.\n */\n function callback(progress: number) {\n let toIndex = 0;\n while (\n normalizedKeyframes[toIndex] &&\n normalizedKeyframes[toIndex].offset <= progress &&\n normalizedKeyframes[toIndex].offset !== 1\n ) {\n toIndex += 1;\n }\n\n render(element, normalizedKeyframes[toIndex - 1], normalizedKeyframes[toIndex], progress);\n }\n\n const controls = tween(callback, {\n ...options,\n onStart() {\n if (isFunction(options.onStart)) {\n options.onStart();\n }\n // Stop running instances\n const runningKeys = running.get(element);\n runningKeys.forEach((runningPause, runningKey) => {\n runningPause();\n runningKeys.delete(runningKey);\n });\n runningKeys.set(key, controls.pause);\n running.set(element, runningKeys);\n },\n });\n\n return controls;\n}\n\n/**\n * Animate one or more elements.\n */\nexport function animate(\n elementOrElements: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>,\n keyframes: Keyframe[],\n options: TweenOptions = {},\n): Animate {\n const controls = eachElements(elementOrElements, (element) =>\n singleAnimate(element, keyframes, options),\n );\n\n const delegate =\n (key) =>\n // eslint-disable-next-line consistent-return\n (...args) => {\n if (key === 'progress' && args.length === 0) {\n return controls[0][key]();\n }\n\n controls.forEach((control) => {\n control[key](...args);\n });\n };\n\n return {\n start: delegate('start'),\n pause: delegate('pause'),\n finish: delegate('finish'),\n play: delegate('play'),\n progress: delegate('progress'),\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAC1B,gBAAgD;AAChD,uBAA2C;AAC3C,uBAA0C;AAC1C,mBAAqC;AA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Aa;AACb,oBAAY,OAAO,UAAU;AAAA,MAC/B,CAAC;AACD,kBAAY,IAAI,KAAK,SAAS,KAAK;AACnC,cAAQ,IAAI,SAAS,WAAW;AAAA,IAClC;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAKO,SAAS,QACd,mBACA,WACA,UAAwB,CAAC,GAChB;AACT,QAAM,eAAW;AAAA,IAAa;AAAA,IAAmB,CAAC,YAChD,cAAc,SAAS,WAAW,OAAO;AAAA,EAC3C;AAEA,QAAM,WACJ,CAAC,QAED,IAAI,SAAS;AACX,QAAI,QAAQ,cAAc,KAAK,WAAW,GAAG;AAC3C,aAAO,SAAS,GAAG,KAAK;AAAA,IAC1B;AAEA,aAAS,QAAQ,CAAC,YAAY;AAC5B,cAAQ,KAAK,GAAG,IAAI;AAAA,IACtB,CAAC;AAAA,EACH;AAEF,SAAO;AAAA,IACL,OAAO,SAAS,OAAO;AAAA,IACvB,OAAO,SAAS,OAAO;AAAA,IACvB,QAAQ,SAAS,QAAQ;AAAA,IACzB,MAAM,SAAS,MAAM;AAAA,IACrB,UAAU,SAAS,UAAU;AAAA,EAC/B;AACF;",
|
|
6
|
+
"names": ["scheduler", "transform", "key"]
|
|
7
7
|
}
|
package/utils/css/animate.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import type { TransformProps } from './transform.js';
|
|
2
2
|
import type { EasingFunction } from '../math/index.js';
|
|
3
3
|
import type { BezierCurve, TweenOptions } from '../tween.js';
|
|
4
|
-
export
|
|
4
|
+
export type CSSCustomPropertyName = `--${string}`;
|
|
5
|
+
export type Keyframe = TransformProps & {
|
|
5
6
|
opacity?: number;
|
|
6
7
|
transformOrigin?: string;
|
|
7
8
|
easing?: EasingFunction | BezierCurve;
|
|
8
9
|
offset?: number;
|
|
10
|
+
[key: CSSCustomPropertyName]: number;
|
|
9
11
|
};
|
|
10
|
-
export
|
|
12
|
+
export type NormalizedKeyframe = Keyframe & {
|
|
11
13
|
easing: EasingFunction;
|
|
12
14
|
offset: number;
|
|
15
|
+
vars: string[];
|
|
13
16
|
};
|
|
14
|
-
export
|
|
17
|
+
export type Animate = {
|
|
15
18
|
start: () => void;
|
|
16
19
|
pause: () => void;
|
|
17
20
|
play: () => void;
|
package/utils/css/animate.js
CHANGED
|
@@ -66,6 +66,17 @@ function render(element, from, to, progress) {
|
|
|
66
66
|
} else if (element.style.transformOrigin) {
|
|
67
67
|
transformOrigin = "";
|
|
68
68
|
}
|
|
69
|
+
let customProperties = false;
|
|
70
|
+
if (isDefined(from.vars) && isDefined(to.vars)) {
|
|
71
|
+
customProperties = from.vars.map((customPropertyName) => {
|
|
72
|
+
const customPropertyValue = lerp(
|
|
73
|
+
from[customPropertyName],
|
|
74
|
+
to[customPropertyName],
|
|
75
|
+
stepProgress
|
|
76
|
+
);
|
|
77
|
+
return [customPropertyName, customPropertyValue];
|
|
78
|
+
});
|
|
79
|
+
}
|
|
69
80
|
const props = Object.fromEntries(
|
|
70
81
|
TRANSFORM_PROPS.filter((name) => isDefined(from[name]) || isDefined(to[name])).map((name) => [
|
|
71
82
|
name,
|
|
@@ -79,6 +90,11 @@ function render(element, from, to, progress) {
|
|
|
79
90
|
if (transformOrigin !== false) {
|
|
80
91
|
element.style.transformOrigin = transformOrigin;
|
|
81
92
|
}
|
|
93
|
+
if (customProperties !== false) {
|
|
94
|
+
customProperties.forEach((customProperty) => {
|
|
95
|
+
element.style.setProperty(customProperty[0], customProperty[1].toString());
|
|
96
|
+
});
|
|
97
|
+
}
|
|
82
98
|
transform(element, props);
|
|
83
99
|
});
|
|
84
100
|
});
|
|
@@ -89,7 +105,8 @@ function singleAnimate(element, keyframes, options = {}) {
|
|
|
89
105
|
(keyframe, index) => ({
|
|
90
106
|
...keyframe,
|
|
91
107
|
offset: keyframe.offset ?? index / keyframesCount,
|
|
92
|
-
easing: normalizeEase(keyframe.easing)
|
|
108
|
+
easing: normalizeEase(keyframe.easing),
|
|
109
|
+
vars: Object.keys(keyframe).filter((key2) => key2.startsWith("--"))
|
|
93
110
|
})
|
|
94
111
|
);
|
|
95
112
|
if (!running.has(element)) {
|
package/utils/css/animate.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/css/animate.ts"],
|
|
4
|
-
"sourcesContent": ["import { lerp, map } from '../math/index.js';\nimport { isDefined, isFunction, isNumber } from '../is.js';\nimport transform, { TRANSFORM_PROPS } from './transform.js';\nimport { domScheduler as scheduler } from '../scheduler.js';\nimport { tween, normalizeEase } from '../tween.js';\n// eslint-disable-next-line import/extensions\nimport { eachElements } from './utils.js';\nimport type { TransformProps } from './transform.js';\nimport type { EasingFunction } from '../math/index.js';\nimport type { BezierCurve, TweenOptions } from '../tween.js';\n\nexport type Keyframe = TransformProps & {\n opacity?: number;\n transformOrigin?: string;\n easing?: EasingFunction | BezierCurve;\n offset?: number;\n};\n\nexport type NormalizedKeyframe = Keyframe & {\n easing: EasingFunction;\n offset: number;\n};\n\nexport type Animate = {\n start: () => void;\n pause: () => void;\n play: () => void;\n finish: () => void;\n progress: (value?: number) => number;\n};\n\nlet id = 0;\nconst running = new WeakMap();\n\nconst CSSUnitConverter = {\n '%': (value, getSizeRef) => (value * getSizeRef()) / 100,\n vh: (value) => (value * window.innerHeight) / 100,\n vw: (value) => (value * window.innerWidth) / 100,\n vmin: (value) => (value * Math.min(window.innerWidth, window.innerHeight)) / 100,\n vmax: (value) => (value * Math.max(window.innerWidth, window.innerHeight)) / 100,\n};\n\n/**\n * Get the value from a step property.\n */\nfunction getAnimationStepValue(val: number | [number, string], getSizeRef: () => number): number {\n if (isNumber(val)) {\n return val;\n }\n\n if (!val[1] || !CSSUnitConverter[val[1]]) {\n return val[0];\n }\n\n return CSSUnitConverter[val[1]](val[0], getSizeRef);\n}\n\nconst generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) =>\n lerp(\n getAnimationStepValue(\n fromValue ?? 0,\n /* istanbul ignore next */\n () => element[sizeRef],\n ),\n getAnimationStepValue(toValue ?? 0, () => element[sizeRef]),\n progress,\n );\nconst widthBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetWidth');\nconst heightBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetHeight');\n\nconst generateLerpRenderStrategy = (defaultValue) => (element, fromValue, toValue, progress) =>\n lerp(fromValue ?? defaultValue, toValue ?? defaultValue, progress);\nconst scaleRenderStrategy = generateLerpRenderStrategy(1);\nconst degreesRenderStrategy = generateLerpRenderStrategy(0);\n\nconst transformRenderStrategies = {\n x: widthBasedTranslateRenderStrategy,\n y: heightBasedTranslateRenderStrategy,\n z: widthBasedTranslateRenderStrategy,\n scale: scaleRenderStrategy,\n scaleX: scaleRenderStrategy,\n scaleY: scaleRenderStrategy,\n scaleZ: scaleRenderStrategy,\n skew: degreesRenderStrategy,\n skewX: degreesRenderStrategy,\n skewY: degreesRenderStrategy,\n rotate: degreesRenderStrategy,\n rotateX: degreesRenderStrategy,\n rotateY: degreesRenderStrategy,\n rotateZ: degreesRenderStrategy,\n};\n\n/**\n * Render an element style based on 2 keyframes and a progress value.\n */\nfunction render(\n element: HTMLElement,\n from: NormalizedKeyframe,\n to: NormalizedKeyframe,\n progress: number,\n) {\n const stepProgress = to.easing(map(progress, from.offset, to.offset, 0, 1));\n\n scheduler.read(() => {\n let opacity: false | number | string = false;\n if (isDefined(from.opacity) || isDefined(to.opacity)) {\n opacity = map(stepProgress, 0, 1, from.opacity ?? 1, to.opacity ?? 1);\n } else if (element.style.opacity) {\n opacity = '';\n }\n\n let transformOrigin: false | string = false;\n if (isDefined(to.transformOrigin)) {\n transformOrigin = to.transformOrigin;\n } else if (element.style.transformOrigin) {\n transformOrigin = '';\n }\n\n const props = Object.fromEntries(\n TRANSFORM_PROPS.filter((name) => isDefined(from[name]) || isDefined(to[name])).map((name) => [\n name,\n transformRenderStrategies[name](element, from[name], to[name], stepProgress),\n ]),\n );\n scheduler.write(() => {\n if (opacity !== false) {\n // @ts-ignore\n element.style.opacity = opacity;\n }\n if (transformOrigin !== false) {\n element.style.transformOrigin = transformOrigin;\n }\n transform(element, props);\n });\n });\n}\n\n/**\n * Animate an element.\n */\nfunction singleAnimate(\n element: HTMLElement,\n keyframes: Keyframe[],\n options: TweenOptions = {},\n): Animate {\n const keyframesCount = keyframes.length - 1;\n const normalizedKeyframes = keyframes.map(\n (keyframe, index)
|
|
5
|
-
"mappings": "AAAA,SAAS,MAAM,WAAW;AAC1B,SAAS,WAAW,YAAY,gBAAgB;AAChD,OAAO,aAAa,uBAAuB;AAC3C,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,OAAO,qBAAqB;AAErC,SAAS,oBAAoB;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { lerp, map } from '../math/index.js';\nimport { isDefined, isFunction, isNumber } from '../is.js';\nimport transform, { TRANSFORM_PROPS } from './transform.js';\nimport { domScheduler as scheduler } from '../scheduler.js';\nimport { tween, normalizeEase } from '../tween.js';\n// eslint-disable-next-line import/extensions\nimport { eachElements } from './utils.js';\nimport type { TransformProps } from './transform.js';\nimport type { EasingFunction } from '../math/index.js';\nimport type { BezierCurve, TweenOptions } from '../tween.js';\n\nexport type CSSCustomPropertyName = `--${string}`;\n\nexport type Keyframe = TransformProps & {\n opacity?: number;\n transformOrigin?: string;\n easing?: EasingFunction | BezierCurve;\n offset?: number;\n [key: CSSCustomPropertyName]: number;\n};\n\nexport type NormalizedKeyframe = Keyframe & {\n easing: EasingFunction;\n offset: number;\n vars: string[];\n};\n\nexport type Animate = {\n start: () => void;\n pause: () => void;\n play: () => void;\n finish: () => void;\n progress: (value?: number) => number;\n};\n\nlet id = 0;\nconst running = new WeakMap();\n\nconst CSSUnitConverter = {\n '%': (value, getSizeRef) => (value * getSizeRef()) / 100,\n vh: (value) => (value * window.innerHeight) / 100,\n vw: (value) => (value * window.innerWidth) / 100,\n vmin: (value) => (value * Math.min(window.innerWidth, window.innerHeight)) / 100,\n vmax: (value) => (value * Math.max(window.innerWidth, window.innerHeight)) / 100,\n};\n\n/**\n * Get the value from a step property.\n */\nfunction getAnimationStepValue(val: number | [number, string], getSizeRef: () => number): number {\n if (isNumber(val)) {\n return val;\n }\n\n if (!val[1] || !CSSUnitConverter[val[1]]) {\n return val[0];\n }\n\n return CSSUnitConverter[val[1]](val[0], getSizeRef);\n}\n\nconst generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) =>\n lerp(\n getAnimationStepValue(\n fromValue ?? 0,\n /* istanbul ignore next */\n () => element[sizeRef],\n ),\n getAnimationStepValue(toValue ?? 0, () => element[sizeRef]),\n progress,\n );\nconst widthBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetWidth');\nconst heightBasedTranslateRenderStrategy = generateTranslateRenderStrategy('offsetHeight');\n\nconst generateLerpRenderStrategy = (defaultValue) => (element, fromValue, toValue, progress) =>\n lerp(fromValue ?? defaultValue, toValue ?? defaultValue, progress);\nconst scaleRenderStrategy = generateLerpRenderStrategy(1);\nconst degreesRenderStrategy = generateLerpRenderStrategy(0);\n\nconst transformRenderStrategies = {\n x: widthBasedTranslateRenderStrategy,\n y: heightBasedTranslateRenderStrategy,\n z: widthBasedTranslateRenderStrategy,\n scale: scaleRenderStrategy,\n scaleX: scaleRenderStrategy,\n scaleY: scaleRenderStrategy,\n scaleZ: scaleRenderStrategy,\n skew: degreesRenderStrategy,\n skewX: degreesRenderStrategy,\n skewY: degreesRenderStrategy,\n rotate: degreesRenderStrategy,\n rotateX: degreesRenderStrategy,\n rotateY: degreesRenderStrategy,\n rotateZ: degreesRenderStrategy,\n};\n\n/**\n * Render an element style based on 2 keyframes and a progress value.\n */\nfunction render(\n element: HTMLElement,\n from: NormalizedKeyframe,\n to: NormalizedKeyframe,\n progress: number,\n) {\n const stepProgress = to.easing(map(progress, from.offset, to.offset, 0, 1));\n\n scheduler.read(() => {\n let opacity: false | number | string = false;\n if (isDefined(from.opacity) || isDefined(to.opacity)) {\n opacity = map(stepProgress, 0, 1, from.opacity ?? 1, to.opacity ?? 1);\n } else if (element.style.opacity) {\n opacity = '';\n }\n\n let transformOrigin: false | string = false;\n if (isDefined(to.transformOrigin)) {\n transformOrigin = to.transformOrigin;\n } else if (element.style.transformOrigin) {\n transformOrigin = '';\n }\n\n let customProperties: false | [string, number][] = false;\n if (isDefined(from.vars) && isDefined(to.vars)) {\n customProperties = from.vars.map((customPropertyName) => {\n const customPropertyValue = lerp(\n from[customPropertyName],\n to[customPropertyName],\n stepProgress,\n );\n return [customPropertyName, customPropertyValue];\n });\n }\n\n const props = Object.fromEntries(\n TRANSFORM_PROPS.filter((name) => isDefined(from[name]) || isDefined(to[name])).map((name) => [\n name,\n transformRenderStrategies[name](element, from[name], to[name], stepProgress),\n ]),\n );\n scheduler.write(() => {\n if (opacity !== false) {\n // @ts-ignore\n element.style.opacity = opacity;\n }\n if (transformOrigin !== false) {\n element.style.transformOrigin = transformOrigin;\n }\n if (customProperties !== false) {\n customProperties.forEach((customProperty) => {\n element.style.setProperty(customProperty[0], customProperty[1].toString());\n });\n }\n transform(element, props);\n });\n });\n}\n\n/**\n * Animate an element.\n */\nfunction singleAnimate(\n element: HTMLElement,\n keyframes: Keyframe[],\n options: TweenOptions = {},\n): Animate {\n const keyframesCount = keyframes.length - 1;\n const normalizedKeyframes = keyframes.map(\n (keyframe, index): NormalizedKeyframe => ({\n ...keyframe,\n offset: keyframe.offset ?? index / keyframesCount,\n easing: normalizeEase(keyframe.easing),\n vars: Object.keys(keyframe).filter((key) => key.startsWith('--')),\n }),\n );\n\n if (!running.has(element)) {\n running.set(element, new Map());\n }\n\n const key = `animate-${id}`;\n id += 1;\n\n /**\n * Set the progress value.\n */\n function callback(progress: number) {\n let toIndex = 0;\n while (\n normalizedKeyframes[toIndex] &&\n normalizedKeyframes[toIndex].offset <= progress &&\n normalizedKeyframes[toIndex].offset !== 1\n ) {\n toIndex += 1;\n }\n\n render(element, normalizedKeyframes[toIndex - 1], normalizedKeyframes[toIndex], progress);\n }\n\n const controls = tween(callback, {\n ...options,\n onStart() {\n if (isFunction(options.onStart)) {\n options.onStart();\n }\n // Stop running instances\n const runningKeys = running.get(element);\n runningKeys.forEach((runningPause, runningKey) => {\n runningPause();\n runningKeys.delete(runningKey);\n });\n runningKeys.set(key, controls.pause);\n running.set(element, runningKeys);\n },\n });\n\n return controls;\n}\n\n/**\n * Animate one or more elements.\n */\nexport function animate(\n elementOrElements: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>,\n keyframes: Keyframe[],\n options: TweenOptions = {},\n): Animate {\n const controls = eachElements(elementOrElements, (element) =>\n singleAnimate(element, keyframes, options),\n );\n\n const delegate =\n (key) =>\n // eslint-disable-next-line consistent-return\n (...args) => {\n if (key === 'progress' && args.length === 0) {\n return controls[0][key]();\n }\n\n controls.forEach((control) => {\n control[key](...args);\n });\n };\n\n return {\n start: delegate('start'),\n pause: delegate('pause'),\n finish: delegate('finish'),\n play: delegate('play'),\n progress: delegate('progress'),\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,MAAM,WAAW;AAC1B,SAAS,WAAW,YAAY,gBAAgB;AAChD,OAAO,aAAa,uBAAuB;AAC3C,SAAS,gBAAgB,iBAAiB;AAC1C,SAAS,OAAO,qBAAqB;AAErC,SAAS,oBAAoB;AA6B7B,IAAI,KAAK;AACT,MAAM,UAAU,oBAAI,QAAQ;AAE5B,MAAM,mBAAmB;AAAA,EACvB,KAAK,CAAC,OAAO,eAAgB,QAAQ,WAAW,IAAK;AAAA,EACrD,IAAI,CAAC,UAAW,QAAQ,OAAO,cAAe;AAAA,EAC9C,IAAI,CAAC,UAAW,QAAQ,OAAO,aAAc;AAAA,EAC7C,MAAM,CAAC,UAAW,QAAQ,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAAA,EAC7E,MAAM,CAAC,UAAW,QAAQ,KAAK,IAAI,OAAO,YAAY,OAAO,WAAW,IAAK;AAC/E;AAKA,SAAS,sBAAsB,K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,GAAG,IAAI;AAAA,IACtB,CAAC;AAAA,EACH;AAEF,SAAO;AAAA,IACL,OAAO,SAAS,OAAO;AAAA,IACvB,OAAO,SAAS,OAAO;AAAA,IACvB,QAAQ,SAAS,QAAQ;AAAA,IACzB,MAAM,SAAS,MAAM;AAAA,IACrB,UAAU,SAAS,UAAU;AAAA,EAC/B;AACF;",
|
|
6
|
+
"names": ["key"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/css/getOffsetSizes.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Get a `DOMRect` like `Object` for an element, without its transforms.\n */\nexport default function getOffsetSizes(element: HTMLElement) {\n let parent = element;\n let x = -window.pageXOffset;\n let y = -window.pageYOffset;\n\n while (parent) {\n x += parent.offsetLeft;\n y += parent.offsetTop;\n // @ts-ignore\n parent = parent.offsetParent;\n }\n\n const width = element.offsetWidth;\n const height = element.
|
|
4
|
+
"sourcesContent": ["/**\n * Get a `DOMRect` like `Object` for an element, without its transforms.\n */\nexport default function getOffsetSizes(element: HTMLElement) {\n let parent = element;\n let x = -window.pageXOffset;\n let y = -window.pageYOffset;\n\n while (parent) {\n x += parent.offsetLeft;\n y += parent.offsetTop;\n // @ts-ignore\n parent = parent.offsetParent;\n }\n\n const width = element.offsetWidth;\n const height = element.offsetHeight;\n\n return {\n x,\n y,\n width,\n height,\n top: y,\n right: width + x,\n bottom: height + y,\n left: x,\n };\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGe,SAAR,eAAgC,SAAsB;AAC3D,MAAI,SAAS;AACb,MAAI,IAAI,CAAC,OAAO;AAChB,MAAI,IAAI,CAAC,OAAO;AAEhB,SAAO,QAAQ;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAEZ,aAAS,OAAO;AAAA,EAClB;AAEA,QAAM,QAAQ,QAAQ;AACtB,QAAM,SAAS,QAAQ;AAEvB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,OAAO,QAAQ;AAAA,IACf,QAAQ,SAAS;AAAA,IACjB,MAAM;AAAA,EACR;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/css/getOffsetSizes.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Get a `DOMRect` like `Object` for an element, without its transforms.\n */\nexport default function getOffsetSizes(element: HTMLElement) {\n let parent = element;\n let x = -window.pageXOffset;\n let y = -window.pageYOffset;\n\n while (parent) {\n x += parent.offsetLeft;\n y += parent.offsetTop;\n // @ts-ignore\n parent = parent.offsetParent;\n }\n\n const width = element.offsetWidth;\n const height = element.
|
|
4
|
+
"sourcesContent": ["/**\n * Get a `DOMRect` like `Object` for an element, without its transforms.\n */\nexport default function getOffsetSizes(element: HTMLElement) {\n let parent = element;\n let x = -window.pageXOffset;\n let y = -window.pageYOffset;\n\n while (parent) {\n x += parent.offsetLeft;\n y += parent.offsetTop;\n // @ts-ignore\n parent = parent.offsetParent;\n }\n\n const width = element.offsetWidth;\n const height = element.offsetHeight;\n\n return {\n x,\n y,\n width,\n height,\n top: y,\n right: width + x,\n bottom: height + y,\n left: x,\n };\n}\n"],
|
|
5
5
|
"mappings": "AAGe,SAAR,eAAgC,SAAsB;AAC3D,MAAI,SAAS;AACb,MAAI,IAAI,CAAC,OAAO;AAChB,MAAI,IAAI,CAAC,OAAO;AAEhB,SAAO,QAAQ;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAEZ,aAAS,OAAO;AAAA,EAClB;AAEA,QAAM,QAAQ,QAAQ;AACtB,QAAM,SAAS,QAAQ;AAEvB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,OAAO,QAAQ;AAAA,IACf,QAAQ,SAAS;AAAA,IACjB,MAAM;AAAA,EACR;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/css/matrix.d.ts
CHANGED
package/utils/css/transform.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type ClassesOrStyles = string | string[] | Partial<CSSStyleDeclaration>;
|
|
2
|
+
export type TransitionStyles = {
|
|
3
3
|
from?: ClassesOrStyles;
|
|
4
4
|
active?: ClassesOrStyles;
|
|
5
5
|
to?: ClassesOrStyles;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/utils/dom/ancestors.ts
|
|
20
|
+
var ancestors_exports = {};
|
|
21
|
+
__export(ancestors_exports, {
|
|
22
|
+
getAncestorWhere: () => getAncestorWhere,
|
|
23
|
+
getAncestorWhereUntil: () => getAncestorWhereUntil
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(ancestors_exports);
|
|
26
|
+
function getAncestorWhere(element, condition) {
|
|
27
|
+
if (!element) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const ancestor = element.parentElement;
|
|
31
|
+
return condition(ancestor) ? ancestor : getAncestorWhere(ancestor, condition);
|
|
32
|
+
}
|
|
33
|
+
function getAncestorWhereUntil(element, condition, until) {
|
|
34
|
+
return getAncestorWhere(element, (el) => condition(el) || until(el));
|
|
35
|
+
}
|
|
36
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
37
|
+
//# sourceMappingURL=ancestors.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/dom/ancestors.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Get an ancestor matching the given condition.\n */\nexport function getAncestorWhere(element: HTMLElement, condition: (el: HTMLElement) => boolean) {\n if (!element) {\n return null;\n }\n\n const ancestor = element.parentElement;\n\n return condition(ancestor) ? ancestor : getAncestorWhere(ancestor, condition);\n}\n\n/**\n * Get an ancestor matching the given condition, stop when the until function is truthy.\n */\nexport function getAncestorWhereUntil(\n element: HTMLElement,\n condition: (el: HTMLElement) => boolean,\n until: (el: HTMLElement) => boolean,\n): HTMLElement | null {\n return getAncestorWhere(element, (el) => condition(el) || until(el));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,iBAAiB,SAAsB,WAAyC;AAC9F,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,QAAQ;AAEzB,SAAO,UAAU,QAAQ,IAAI,WAAW,iBAAiB,UAAU,SAAS;AAC9E;AAKO,SAAS,sBACd,SACA,WACA,OACoB;AACpB,SAAO,iBAAiB,SAAS,CAAC,OAAO,UAAU,EAAE,KAAK,MAAM,EAAE,CAAC;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an ancestor matching the given condition.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getAncestorWhere(element: HTMLElement, condition: (el: HTMLElement) => boolean): any;
|
|
5
|
+
/**
|
|
6
|
+
* Get an ancestor matching the given condition, stop when the until function is truthy.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getAncestorWhereUntil(element: HTMLElement, condition: (el: HTMLElement) => boolean, until: (el: HTMLElement) => boolean): HTMLElement | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function getAncestorWhere(element, condition) {
|
|
2
|
+
if (!element) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
const ancestor = element.parentElement;
|
|
6
|
+
return condition(ancestor) ? ancestor : getAncestorWhere(ancestor, condition);
|
|
7
|
+
}
|
|
8
|
+
function getAncestorWhereUntil(element, condition, until) {
|
|
9
|
+
return getAncestorWhere(element, (el) => condition(el) || until(el));
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
getAncestorWhere,
|
|
13
|
+
getAncestorWhereUntil
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=ancestors.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/dom/ancestors.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Get an ancestor matching the given condition.\n */\nexport function getAncestorWhere(element: HTMLElement, condition: (el: HTMLElement) => boolean) {\n if (!element) {\n return null;\n }\n\n const ancestor = element.parentElement;\n\n return condition(ancestor) ? ancestor : getAncestorWhere(ancestor, condition);\n}\n\n/**\n * Get an ancestor matching the given condition, stop when the until function is truthy.\n */\nexport function getAncestorWhereUntil(\n element: HTMLElement,\n condition: (el: HTMLElement) => boolean,\n until: (el: HTMLElement) => boolean,\n): HTMLElement | null {\n return getAncestorWhere(element, (el) => condition(el) || until(el));\n}\n"],
|
|
5
|
+
"mappings": "AAGO,SAAS,iBAAiB,SAAsB,WAAyC;AAC9F,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,WAAW,QAAQ;AAEzB,SAAO,UAAU,QAAQ,IAAI,WAAW,iBAAiB,UAAU,SAAS;AAC9E;AAKO,SAAS,sBACd,SACA,WACA,OACoB;AACpB,SAAO,iBAAiB,SAAS,CAAC,OAAO,UAAU,EAAE,KAAK,MAAM,EAAE,CAAC;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/js-toolkit/utils/dom/index.ts
|
|
17
|
+
var dom_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(dom_exports);
|
|
19
|
+
__reExport(dom_exports, require("./ancestors.cjs"), module.exports);
|
|
20
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
21
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ancestors.js';
|
package/utils/index.cjs
CHANGED
|
@@ -62,5 +62,6 @@ __reExport(utils_exports, require("./scheduler.cjs"), module.exports);
|
|
|
62
62
|
__reExport(utils_exports, require("./noop.cjs"), module.exports);
|
|
63
63
|
var import_tween = require("./tween.cjs");
|
|
64
64
|
var import_Queue = require("./Queue.cjs");
|
|
65
|
+
__reExport(utils_exports, require("./dom/index.cjs"), module.exports);
|
|
65
66
|
if (module.exports.default) module.exports = module.exports.default;
|
|
66
67
|
//# sourceMappingURL=index.cjs.map
|
package/utils/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoC;AACpC,uBAAqC;AACrC,sBAAoC;AACpC,qBAAmC;AACnC,uBAA0B;AAC1B,sBAAoC;AACpC,2BAAyC;AACzC,sBAAoC;AACpC,sBAAoC;AACpC,0BAAc,qBATd;AAUA,0BAAc,sBAVd;AAYA,0BAAc,4BAZd;AAaA,qBAIO;AACP,0BAAc,gCAlBd;AAmBA,0BAAc,6BAnBd;AAoBA,0BAAc,+BApBd;AAqBA,0BAAc,4BArBd;AAsBA,0BAAc,uBAtBd;AAuBA,mBAAsB;AACtB,mBAAsB;",
|
|
4
|
+
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\nexport * from './dom/index.js';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoC;AACpC,uBAAqC;AACrC,sBAAoC;AACpC,qBAAmC;AACnC,uBAA0B;AAC1B,sBAAoC;AACpC,2BAAyC;AACzC,sBAAoC;AACpC,sBAAoC;AACpC,0BAAc,qBATd;AAUA,0BAAc,sBAVd;AAYA,0BAAc,4BAZd;AAaA,qBAIO;AACP,0BAAc,gCAlBd;AAmBA,0BAAc,6BAnBd;AAoBA,0BAAc,+BApBd;AAqBA,0BAAc,4BArBd;AAsBA,0BAAc,uBAtBd;AAuBA,mBAAsB;AACtB,mBAAsB;AACtB,0BAAc,4BAzBd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
package/utils/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\n"],
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAAgC;AACzC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA2B;AACpC,cAAc;AACd,cAAc;AAEd,cAAc;AACd;AAAA,EACE;AAAA,EACQ;AAAA,EACG;AAAA,OACN;AACP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,aAAa;AACtB,SAAS,aAAa;",
|
|
4
|
+
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\nexport * from './dom/index.js';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAAgC;AACzC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA2B;AACpC,cAAc;AACd,cAAc;AAEd,cAAc;AACd;AAAA,EACE;AAAA,EACQ;AAAA,EACG;AAAA,OACN;AACP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,cAAc;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
package/utils/is.cjs
CHANGED
|
@@ -34,7 +34,7 @@ var isFunction = (value) => typeof value === "function";
|
|
|
34
34
|
var isDefined = (value) => typeof value !== "undefined";
|
|
35
35
|
var isString = (value) => typeof value === "string";
|
|
36
36
|
var isObject = (value) => typeof value === "object" && !!value && value.toString() === "[object Object]";
|
|
37
|
-
var isNumber = (value) => typeof value === "number";
|
|
37
|
+
var isNumber = (value) => typeof value === "number" && !Number.isNaN(value);
|
|
38
38
|
var isBoolean = (value) => typeof value === "boolean";
|
|
39
39
|
var isArray = Array.isArray;
|
|
40
40
|
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/is.cjs.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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,IAAM,QAAQ,OAAO,YAAY,eAAe;AAMhD,IAAM,aAAa,CAAC,UAAsC,OAAO,UAAU;AAK3E,IAAM,YAAY,CAAC,UAA4B,OAAO,UAAU;AAKhE,IAAM,WAAW,CAAC,UAAoC,OAAO,UAAU;AAKvE,IAAM,WAAW,CAAC,UACvB,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,SAAS,MAAM;AAKxD,IAAM,WAAW,CAAC,
|
|
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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,IAAM,QAAQ,OAAO,YAAY,eAAe;AAMhD,IAAM,aAAa,CAAC,UAAsC,OAAO,UAAU;AAK3E,IAAM,YAAY,CAAC,UAA4B,OAAO,UAAU;AAKhE,IAAM,WAAW,CAAC,UAAoC,OAAO,UAAU;AAKvE,IAAM,WAAW,CAAC,UACvB,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,SAAS,MAAM;AAKxD,IAAM,WAAW,CAAC,UACvB,OAAO,UAAU,YAAY,CAAC,OAAO,MAAM,KAAK;AAK3C,IAAM,YAAY,CAAC,UAAqC,OAAO,UAAU;AAGzE,IAAM,UAAU,MAAM;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/is.js
CHANGED
|
@@ -3,7 +3,7 @@ const isFunction = (value) => typeof value === "function";
|
|
|
3
3
|
const isDefined = (value) => typeof value !== "undefined";
|
|
4
4
|
const isString = (value) => typeof value === "string";
|
|
5
5
|
const isObject = (value) => typeof value === "object" && !!value && value.toString() === "[object Object]";
|
|
6
|
-
const isNumber = (value) => typeof value === "number";
|
|
6
|
+
const isNumber = (value) => typeof value === "number" && !Number.isNaN(value);
|
|
7
7
|
const isBoolean = (value) => typeof value === "boolean";
|
|
8
8
|
const isArray = Array.isArray;
|
|
9
9
|
export {
|
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
|
|
5
|
-
"mappings": "AACO,MAAM,QAAQ,OAAO,YAAY,eAAe;AAMhD,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,
|
|
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;AAMhD,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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/tween.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var import_is = require("./is.cjs");
|
|
|
35
35
|
var import_noop = require("./noop.cjs");
|
|
36
36
|
var import_raf = __toESM(require("../services/raf.cjs"), 1);
|
|
37
37
|
var id = 0;
|
|
38
|
-
var
|
|
38
|
+
var DEFAULT_PROGRESS_PRECISION = 1e-4;
|
|
39
39
|
function normalizeEase(ease) {
|
|
40
40
|
if (!(0, import_is.isDefined)(ease)) {
|
|
41
41
|
return import_noop.noopValue;
|
|
@@ -49,6 +49,7 @@ function tween(callback, options = {}) {
|
|
|
49
49
|
const raf = (0, import_raf.default)();
|
|
50
50
|
let progressValue = 0;
|
|
51
51
|
let easedProgress = 0;
|
|
52
|
+
const precision = options.precision ?? DEFAULT_PROGRESS_PRECISION;
|
|
52
53
|
const ease = normalizeEase(options.easing);
|
|
53
54
|
let duration = options.duration ?? 1;
|
|
54
55
|
duration *= 1e3;
|
|
@@ -68,7 +69,7 @@ function tween(callback, options = {}) {
|
|
|
68
69
|
}
|
|
69
70
|
progressValue = newProgress;
|
|
70
71
|
easedProgress = ease(progressValue);
|
|
71
|
-
if (Math.abs(1 - easedProgress) <
|
|
72
|
+
if (Math.abs(1 - easedProgress) < precision) {
|
|
72
73
|
progressValue = 1;
|
|
73
74
|
easedProgress = 1;
|
|
74
75
|
}
|