rattail 1.0.13 → 1.0.14
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/lib/index.cjs +79 -0
- package/lib/index.d.cts +21 -1
- package/lib/index.d.ts +21 -1
- package/lib/index.global.js +78 -0
- package/lib/index.js +78 -0
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -121,6 +121,7 @@ __export(src_exports, {
|
|
|
121
121
|
merge: () => merge,
|
|
122
122
|
mergeWith: () => mergeWith,
|
|
123
123
|
minBy: () => minBy,
|
|
124
|
+
motion: () => motion,
|
|
124
125
|
normalizeToArray: () => normalizeToArray,
|
|
125
126
|
objectToString: () => objectToString,
|
|
126
127
|
omit: () => omit,
|
|
@@ -1045,6 +1046,83 @@ function download(val, filename = "file") {
|
|
|
1045
1046
|
document.body.removeChild(a);
|
|
1046
1047
|
}
|
|
1047
1048
|
|
|
1049
|
+
// src/util/motion.ts
|
|
1050
|
+
function motion(options) {
|
|
1051
|
+
const {
|
|
1052
|
+
from,
|
|
1053
|
+
to,
|
|
1054
|
+
duration = 300,
|
|
1055
|
+
frame = () => {
|
|
1056
|
+
},
|
|
1057
|
+
timingFunction = (value2) => value2,
|
|
1058
|
+
onStateChange = () => {
|
|
1059
|
+
}
|
|
1060
|
+
} = options;
|
|
1061
|
+
let state = "pending";
|
|
1062
|
+
let value = from;
|
|
1063
|
+
const distance = to - from;
|
|
1064
|
+
let ticker = void 0;
|
|
1065
|
+
let startTime = void 0;
|
|
1066
|
+
let pausedTime = void 0;
|
|
1067
|
+
let sleepTime = 0;
|
|
1068
|
+
function start() {
|
|
1069
|
+
if (state === "running" || state === "finished") {
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
setState("running");
|
|
1073
|
+
const now = performance.now();
|
|
1074
|
+
startTime = startTime != null ? startTime : now;
|
|
1075
|
+
sleepTime += pausedTime != null ? now - pausedTime : 0;
|
|
1076
|
+
pausedTime = void 0;
|
|
1077
|
+
tick();
|
|
1078
|
+
function tick() {
|
|
1079
|
+
ticker = requestAnimationFrame(() => {
|
|
1080
|
+
const now2 = performance.now();
|
|
1081
|
+
const executionTime = now2 - startTime - sleepTime;
|
|
1082
|
+
const progress = clamp(executionTime / duration, 0, 1);
|
|
1083
|
+
value = distance * timingFunction(progress) + from;
|
|
1084
|
+
if (progress >= 1) {
|
|
1085
|
+
setState("finished");
|
|
1086
|
+
frame({ value: to, done: true });
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
frame({ value, done: false });
|
|
1090
|
+
tick();
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function pause() {
|
|
1095
|
+
if (state !== "running") {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
cancelAnimationFrame(ticker);
|
|
1099
|
+
setState("paused");
|
|
1100
|
+
pausedTime = performance.now();
|
|
1101
|
+
}
|
|
1102
|
+
function reset() {
|
|
1103
|
+
cancelAnimationFrame(ticker);
|
|
1104
|
+
setState("pending");
|
|
1105
|
+
value = from;
|
|
1106
|
+
ticker = void 0;
|
|
1107
|
+
startTime = void 0;
|
|
1108
|
+
pausedTime = void 0;
|
|
1109
|
+
sleepTime = 0;
|
|
1110
|
+
}
|
|
1111
|
+
function getState() {
|
|
1112
|
+
return state;
|
|
1113
|
+
}
|
|
1114
|
+
function setState(_state) {
|
|
1115
|
+
state = _state;
|
|
1116
|
+
onStateChange(_state);
|
|
1117
|
+
}
|
|
1118
|
+
return {
|
|
1119
|
+
start,
|
|
1120
|
+
pause,
|
|
1121
|
+
reset,
|
|
1122
|
+
getState
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1048
1126
|
// src/function/call.ts
|
|
1049
1127
|
function call(fn, ...args) {
|
|
1050
1128
|
if (isArray(fn)) {
|
|
@@ -1459,6 +1537,7 @@ function ceil(val, precision = 0) {
|
|
|
1459
1537
|
merge,
|
|
1460
1538
|
mergeWith,
|
|
1461
1539
|
minBy,
|
|
1540
|
+
motion,
|
|
1462
1541
|
normalizeToArray,
|
|
1463
1542
|
objectToString,
|
|
1464
1543
|
omit,
|
package/lib/index.d.cts
CHANGED
|
@@ -107,6 +107,26 @@ declare function tryParseJSON<T>(json: string): T | undefined;
|
|
|
107
107
|
|
|
108
108
|
declare function download(val: string | Blob | File, filename?: string): void;
|
|
109
109
|
|
|
110
|
+
interface MotionOptions {
|
|
111
|
+
from: number;
|
|
112
|
+
to: number;
|
|
113
|
+
duration?: number;
|
|
114
|
+
frame?: ({ value, done }: {
|
|
115
|
+
value: number;
|
|
116
|
+
done: boolean;
|
|
117
|
+
}) => void;
|
|
118
|
+
timingFunction?: (v: number) => number;
|
|
119
|
+
onStateChange?: (state: MotionState) => void;
|
|
120
|
+
}
|
|
121
|
+
type MotionState = 'running' | 'paused' | 'pending' | 'finished';
|
|
122
|
+
interface Motion {
|
|
123
|
+
start: () => void;
|
|
124
|
+
pause: () => void;
|
|
125
|
+
reset: () => void;
|
|
126
|
+
getState: () => MotionState;
|
|
127
|
+
}
|
|
128
|
+
declare function motion(options: MotionOptions): Motion;
|
|
129
|
+
|
|
110
130
|
declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
|
|
111
131
|
|
|
112
132
|
declare function once<F extends (...args: any[]) => any>(fn: F): (this: unknown, ...args: Parameters<F>) => ReturnType<F>;
|
|
@@ -270,4 +290,4 @@ declare function floor(val: number, precision?: number): number;
|
|
|
270
290
|
|
|
271
291
|
declare function ceil(val: number, precision?: number): number;
|
|
272
292
|
|
|
273
|
-
export { type BEM, type ClassName, type Classes, NOOP, type PromiseWithResolvers, type Storage, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
|
293
|
+
export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
package/lib/index.d.ts
CHANGED
|
@@ -107,6 +107,26 @@ declare function tryParseJSON<T>(json: string): T | undefined;
|
|
|
107
107
|
|
|
108
108
|
declare function download(val: string | Blob | File, filename?: string): void;
|
|
109
109
|
|
|
110
|
+
interface MotionOptions {
|
|
111
|
+
from: number;
|
|
112
|
+
to: number;
|
|
113
|
+
duration?: number;
|
|
114
|
+
frame?: ({ value, done }: {
|
|
115
|
+
value: number;
|
|
116
|
+
done: boolean;
|
|
117
|
+
}) => void;
|
|
118
|
+
timingFunction?: (v: number) => number;
|
|
119
|
+
onStateChange?: (state: MotionState) => void;
|
|
120
|
+
}
|
|
121
|
+
type MotionState = 'running' | 'paused' | 'pending' | 'finished';
|
|
122
|
+
interface Motion {
|
|
123
|
+
start: () => void;
|
|
124
|
+
pause: () => void;
|
|
125
|
+
reset: () => void;
|
|
126
|
+
getState: () => MotionState;
|
|
127
|
+
}
|
|
128
|
+
declare function motion(options: MotionOptions): Motion;
|
|
129
|
+
|
|
110
130
|
declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
|
|
111
131
|
|
|
112
132
|
declare function once<F extends (...args: any[]) => any>(fn: F): (this: unknown, ...args: Parameters<F>) => ReturnType<F>;
|
|
@@ -270,4 +290,4 @@ declare function floor(val: number, precision?: number): number;
|
|
|
270
290
|
|
|
271
291
|
declare function ceil(val: number, precision?: number): number;
|
|
272
292
|
|
|
273
|
-
export { type BEM, type ClassName, type Classes, NOOP, type PromiseWithResolvers, type Storage, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
|
293
|
+
export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
package/lib/index.global.js
CHANGED
|
@@ -122,6 +122,7 @@ var Rattail = (() => {
|
|
|
122
122
|
merge: () => merge,
|
|
123
123
|
mergeWith: () => mergeWith,
|
|
124
124
|
minBy: () => minBy,
|
|
125
|
+
motion: () => motion,
|
|
125
126
|
normalizeToArray: () => normalizeToArray,
|
|
126
127
|
objectToString: () => objectToString,
|
|
127
128
|
omit: () => omit,
|
|
@@ -1045,6 +1046,83 @@ var Rattail = (() => {
|
|
|
1045
1046
|
document.body.removeChild(a);
|
|
1046
1047
|
}
|
|
1047
1048
|
|
|
1049
|
+
// src/util/motion.ts
|
|
1050
|
+
function motion(options) {
|
|
1051
|
+
const {
|
|
1052
|
+
from,
|
|
1053
|
+
to,
|
|
1054
|
+
duration = 300,
|
|
1055
|
+
frame = () => {
|
|
1056
|
+
},
|
|
1057
|
+
timingFunction = (value2) => value2,
|
|
1058
|
+
onStateChange = () => {
|
|
1059
|
+
}
|
|
1060
|
+
} = options;
|
|
1061
|
+
let state = "pending";
|
|
1062
|
+
let value = from;
|
|
1063
|
+
const distance = to - from;
|
|
1064
|
+
let ticker = void 0;
|
|
1065
|
+
let startTime = void 0;
|
|
1066
|
+
let pausedTime = void 0;
|
|
1067
|
+
let sleepTime = 0;
|
|
1068
|
+
function start() {
|
|
1069
|
+
if (state === "running" || state === "finished") {
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
setState("running");
|
|
1073
|
+
const now = performance.now();
|
|
1074
|
+
startTime = startTime != null ? startTime : now;
|
|
1075
|
+
sleepTime += pausedTime != null ? now - pausedTime : 0;
|
|
1076
|
+
pausedTime = void 0;
|
|
1077
|
+
tick();
|
|
1078
|
+
function tick() {
|
|
1079
|
+
ticker = requestAnimationFrame(() => {
|
|
1080
|
+
const now2 = performance.now();
|
|
1081
|
+
const executionTime = now2 - startTime - sleepTime;
|
|
1082
|
+
const progress = clamp(executionTime / duration, 0, 1);
|
|
1083
|
+
value = distance * timingFunction(progress) + from;
|
|
1084
|
+
if (progress >= 1) {
|
|
1085
|
+
setState("finished");
|
|
1086
|
+
frame({ value: to, done: true });
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
frame({ value, done: false });
|
|
1090
|
+
tick();
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function pause() {
|
|
1095
|
+
if (state !== "running") {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
cancelAnimationFrame(ticker);
|
|
1099
|
+
setState("paused");
|
|
1100
|
+
pausedTime = performance.now();
|
|
1101
|
+
}
|
|
1102
|
+
function reset() {
|
|
1103
|
+
cancelAnimationFrame(ticker);
|
|
1104
|
+
setState("pending");
|
|
1105
|
+
value = from;
|
|
1106
|
+
ticker = void 0;
|
|
1107
|
+
startTime = void 0;
|
|
1108
|
+
pausedTime = void 0;
|
|
1109
|
+
sleepTime = 0;
|
|
1110
|
+
}
|
|
1111
|
+
function getState() {
|
|
1112
|
+
return state;
|
|
1113
|
+
}
|
|
1114
|
+
function setState(_state) {
|
|
1115
|
+
state = _state;
|
|
1116
|
+
onStateChange(_state);
|
|
1117
|
+
}
|
|
1118
|
+
return {
|
|
1119
|
+
start,
|
|
1120
|
+
pause,
|
|
1121
|
+
reset,
|
|
1122
|
+
getState
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1048
1126
|
// src/function/call.ts
|
|
1049
1127
|
function call(fn, ...args) {
|
|
1050
1128
|
if (isArray(fn)) {
|
package/lib/index.js
CHANGED
|
@@ -896,6 +896,83 @@ function download(val, filename = "file") {
|
|
|
896
896
|
document.body.removeChild(a);
|
|
897
897
|
}
|
|
898
898
|
|
|
899
|
+
// src/util/motion.ts
|
|
900
|
+
function motion(options) {
|
|
901
|
+
const {
|
|
902
|
+
from,
|
|
903
|
+
to,
|
|
904
|
+
duration = 300,
|
|
905
|
+
frame = () => {
|
|
906
|
+
},
|
|
907
|
+
timingFunction = (value2) => value2,
|
|
908
|
+
onStateChange = () => {
|
|
909
|
+
}
|
|
910
|
+
} = options;
|
|
911
|
+
let state = "pending";
|
|
912
|
+
let value = from;
|
|
913
|
+
const distance = to - from;
|
|
914
|
+
let ticker = void 0;
|
|
915
|
+
let startTime = void 0;
|
|
916
|
+
let pausedTime = void 0;
|
|
917
|
+
let sleepTime = 0;
|
|
918
|
+
function start() {
|
|
919
|
+
if (state === "running" || state === "finished") {
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
setState("running");
|
|
923
|
+
const now = performance.now();
|
|
924
|
+
startTime = startTime != null ? startTime : now;
|
|
925
|
+
sleepTime += pausedTime != null ? now - pausedTime : 0;
|
|
926
|
+
pausedTime = void 0;
|
|
927
|
+
tick();
|
|
928
|
+
function tick() {
|
|
929
|
+
ticker = requestAnimationFrame(() => {
|
|
930
|
+
const now2 = performance.now();
|
|
931
|
+
const executionTime = now2 - startTime - sleepTime;
|
|
932
|
+
const progress = clamp(executionTime / duration, 0, 1);
|
|
933
|
+
value = distance * timingFunction(progress) + from;
|
|
934
|
+
if (progress >= 1) {
|
|
935
|
+
setState("finished");
|
|
936
|
+
frame({ value: to, done: true });
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
frame({ value, done: false });
|
|
940
|
+
tick();
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function pause() {
|
|
945
|
+
if (state !== "running") {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
cancelAnimationFrame(ticker);
|
|
949
|
+
setState("paused");
|
|
950
|
+
pausedTime = performance.now();
|
|
951
|
+
}
|
|
952
|
+
function reset() {
|
|
953
|
+
cancelAnimationFrame(ticker);
|
|
954
|
+
setState("pending");
|
|
955
|
+
value = from;
|
|
956
|
+
ticker = void 0;
|
|
957
|
+
startTime = void 0;
|
|
958
|
+
pausedTime = void 0;
|
|
959
|
+
sleepTime = 0;
|
|
960
|
+
}
|
|
961
|
+
function getState() {
|
|
962
|
+
return state;
|
|
963
|
+
}
|
|
964
|
+
function setState(_state) {
|
|
965
|
+
state = _state;
|
|
966
|
+
onStateChange(_state);
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
start,
|
|
970
|
+
pause,
|
|
971
|
+
reset,
|
|
972
|
+
getState
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
|
|
899
976
|
// src/function/call.ts
|
|
900
977
|
function call(fn, ...args) {
|
|
901
978
|
if (isArray(fn)) {
|
|
@@ -1309,6 +1386,7 @@ export {
|
|
|
1309
1386
|
merge,
|
|
1310
1387
|
mergeWith,
|
|
1311
1388
|
minBy,
|
|
1389
|
+
motion,
|
|
1312
1390
|
normalizeToArray,
|
|
1313
1391
|
objectToString,
|
|
1314
1392
|
omit,
|