rattail 1.0.19 → 1.0.20

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 CHANGED
@@ -71,6 +71,7 @@ __export(src_exports, {
71
71
  differenceWith: () => differenceWith,
72
72
  doubleRaf: () => doubleRaf,
73
73
  download: () => download,
74
+ duration: () => duration,
74
75
  ensurePrefix: () => ensurePrefix,
75
76
  ensureSuffix: () => ensureSuffix,
76
77
  find: () => find,
@@ -785,6 +786,7 @@ __export(util_exports, {
785
786
  createStorage: () => createStorage,
786
787
  doubleRaf: () => doubleRaf,
787
788
  download: () => download,
789
+ duration: () => duration,
788
790
  getAllParentScroller: () => getAllParentScroller,
789
791
  getParentScroller: () => getParentScroller,
790
792
  getRect: () => getRect,
@@ -1099,7 +1101,7 @@ function motion(options) {
1099
1101
  const {
1100
1102
  from,
1101
1103
  to,
1102
- duration = 300,
1104
+ duration: duration2 = 300,
1103
1105
  frame = () => {
1104
1106
  },
1105
1107
  timingFunction = (value2) => value2,
@@ -1127,7 +1129,7 @@ function motion(options) {
1127
1129
  ticker = requestAnimationFrame(() => {
1128
1130
  const now2 = performance.now();
1129
1131
  const executionTime = now2 - startTime - sleepTime;
1130
- const progress = clamp(executionTime / duration, 0, 1);
1132
+ const progress = clamp(executionTime / duration2, 0, 1);
1131
1133
  value = distance * timingFunction(progress) + from;
1132
1134
  if (progress >= 1) {
1133
1135
  setState("finished");
@@ -1171,6 +1173,58 @@ function motion(options) {
1171
1173
  };
1172
1174
  }
1173
1175
 
1176
+ // src/util/duration.ts
1177
+ function duration() {
1178
+ const ctx = {
1179
+ value: 0,
1180
+ years,
1181
+ months,
1182
+ weeks,
1183
+ days,
1184
+ hours,
1185
+ minutes,
1186
+ seconds,
1187
+ milliseconds,
1188
+ valueOf
1189
+ };
1190
+ function years(value) {
1191
+ ctx.value += value * 365 * 24 * 60 * 60 * 1e3;
1192
+ return ctx;
1193
+ }
1194
+ function months(value) {
1195
+ ctx.value += value * 30 * 24 * 60 * 60 * 1e3;
1196
+ return ctx;
1197
+ }
1198
+ function weeks(value) {
1199
+ ctx.value += value * 7 * 24 * 60 * 60 * 1e3;
1200
+ return ctx;
1201
+ }
1202
+ function days(value) {
1203
+ ctx.value += value * 24 * 60 * 60 * 1e3;
1204
+ return ctx;
1205
+ }
1206
+ function hours(value) {
1207
+ ctx.value += value * 60 * 60 * 1e3;
1208
+ return ctx;
1209
+ }
1210
+ function minutes(value) {
1211
+ ctx.value += value * 60 * 1e3;
1212
+ return ctx;
1213
+ }
1214
+ function seconds(value) {
1215
+ ctx.value += value * 1e3;
1216
+ return ctx;
1217
+ }
1218
+ function milliseconds(value) {
1219
+ ctx.value += value;
1220
+ return ctx;
1221
+ }
1222
+ function valueOf(options = { milliseconds: true }) {
1223
+ return options.milliseconds ? ctx.value : ctx.value / 1e3;
1224
+ }
1225
+ return ctx;
1226
+ }
1227
+
1174
1228
  // src/util/index.ts
1175
1229
  __reExport(util_exports, require("mitt"));
1176
1230
  var import_mitt = __toESM(require("mitt"), 1);
@@ -1525,6 +1579,7 @@ function ceil(val, precision = 0) {
1525
1579
  differenceWith,
1526
1580
  doubleRaf,
1527
1581
  download,
1582
+ duration,
1528
1583
  ensurePrefix,
1529
1584
  ensureSuffix,
1530
1585
  find,
package/lib/index.d.cts CHANGED
@@ -130,6 +130,21 @@ interface Motion {
130
130
  }
131
131
  declare function motion(options: MotionOptions): Motion;
132
132
 
133
+ declare function duration(): {
134
+ value: number;
135
+ years: (value: number) => any;
136
+ months: (value: number) => any;
137
+ weeks: (value: number) => any;
138
+ days: (value: number) => any;
139
+ hours: (value: number) => any;
140
+ minutes: (value: number) => any;
141
+ seconds: (value: number) => any;
142
+ milliseconds: (value: number) => any;
143
+ valueOf: (options?: {
144
+ milliseconds: boolean;
145
+ }) => number;
146
+ };
147
+
133
148
  declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
134
149
 
135
150
  declare function once<F extends (...args: any[]) => any>(fn: F): (this: unknown, ...args: Parameters<F>) => ReturnType<F>;
@@ -295,4 +310,4 @@ declare function floor(val: number, precision?: number): number;
295
310
 
296
311
  declare function ceil(val: number, precision?: number): number;
297
312
 
298
- export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, 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 };
313
+ export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, 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
@@ -130,6 +130,21 @@ interface Motion {
130
130
  }
131
131
  declare function motion(options: MotionOptions): Motion;
132
132
 
133
+ declare function duration(): {
134
+ value: number;
135
+ years: (value: number) => any;
136
+ months: (value: number) => any;
137
+ weeks: (value: number) => any;
138
+ days: (value: number) => any;
139
+ hours: (value: number) => any;
140
+ minutes: (value: number) => any;
141
+ seconds: (value: number) => any;
142
+ milliseconds: (value: number) => any;
143
+ valueOf: (options?: {
144
+ milliseconds: boolean;
145
+ }) => number;
146
+ };
147
+
133
148
  declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
134
149
 
135
150
  declare function once<F extends (...args: any[]) => any>(fn: F): (this: unknown, ...args: Parameters<F>) => ReturnType<F>;
@@ -295,4 +310,4 @@ declare function floor(val: number, precision?: number): number;
295
310
 
296
311
  declare function ceil(val: number, precision?: number): number;
297
312
 
298
- export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, 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 };
313
+ export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, 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 };
@@ -61,6 +61,7 @@ var Rattail = (() => {
61
61
  differenceWith: () => differenceWith,
62
62
  doubleRaf: () => doubleRaf,
63
63
  download: () => download,
64
+ duration: () => duration,
64
65
  ensurePrefix: () => ensurePrefix,
65
66
  ensureSuffix: () => ensureSuffix,
66
67
  find: () => find,
@@ -1060,7 +1061,7 @@ var Rattail = (() => {
1060
1061
  const {
1061
1062
  from,
1062
1063
  to,
1063
- duration = 300,
1064
+ duration: duration2 = 300,
1064
1065
  frame = () => {
1065
1066
  },
1066
1067
  timingFunction = (value2) => value2,
@@ -1088,7 +1089,7 @@ var Rattail = (() => {
1088
1089
  ticker = requestAnimationFrame(() => {
1089
1090
  const now2 = performance.now();
1090
1091
  const executionTime = now2 - startTime - sleepTime;
1091
- const progress = clamp(executionTime / duration, 0, 1);
1092
+ const progress = clamp(executionTime / duration2, 0, 1);
1092
1093
  value = distance * timingFunction(progress) + from;
1093
1094
  if (progress >= 1) {
1094
1095
  setState("finished");
@@ -1132,6 +1133,58 @@ var Rattail = (() => {
1132
1133
  };
1133
1134
  }
1134
1135
 
1136
+ // src/util/duration.ts
1137
+ function duration() {
1138
+ const ctx = {
1139
+ value: 0,
1140
+ years,
1141
+ months,
1142
+ weeks,
1143
+ days,
1144
+ hours,
1145
+ minutes,
1146
+ seconds,
1147
+ milliseconds,
1148
+ valueOf
1149
+ };
1150
+ function years(value) {
1151
+ ctx.value += value * 365 * 24 * 60 * 60 * 1e3;
1152
+ return ctx;
1153
+ }
1154
+ function months(value) {
1155
+ ctx.value += value * 30 * 24 * 60 * 60 * 1e3;
1156
+ return ctx;
1157
+ }
1158
+ function weeks(value) {
1159
+ ctx.value += value * 7 * 24 * 60 * 60 * 1e3;
1160
+ return ctx;
1161
+ }
1162
+ function days(value) {
1163
+ ctx.value += value * 24 * 60 * 60 * 1e3;
1164
+ return ctx;
1165
+ }
1166
+ function hours(value) {
1167
+ ctx.value += value * 60 * 60 * 1e3;
1168
+ return ctx;
1169
+ }
1170
+ function minutes(value) {
1171
+ ctx.value += value * 60 * 1e3;
1172
+ return ctx;
1173
+ }
1174
+ function seconds(value) {
1175
+ ctx.value += value * 1e3;
1176
+ return ctx;
1177
+ }
1178
+ function milliseconds(value) {
1179
+ ctx.value += value;
1180
+ return ctx;
1181
+ }
1182
+ function valueOf(options = { milliseconds: true }) {
1183
+ return options.milliseconds ? ctx.value : ctx.value / 1e3;
1184
+ }
1185
+ return ctx;
1186
+ }
1187
+
1135
1188
  // node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
1136
1189
  function mitt_default(n) {
1137
1190
  return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
package/lib/index.js CHANGED
@@ -59,6 +59,7 @@ __export(src_exports, {
59
59
  differenceWith: () => differenceWith,
60
60
  doubleRaf: () => doubleRaf,
61
61
  download: () => download,
62
+ duration: () => duration,
62
63
  ensurePrefix: () => ensurePrefix,
63
64
  ensureSuffix: () => ensureSuffix,
64
65
  find: () => find,
@@ -772,6 +773,7 @@ __export(util_exports, {
772
773
  createStorage: () => createStorage,
773
774
  doubleRaf: () => doubleRaf,
774
775
  download: () => download,
776
+ duration: () => duration,
775
777
  getAllParentScroller: () => getAllParentScroller,
776
778
  getParentScroller: () => getParentScroller,
777
779
  getRect: () => getRect,
@@ -1086,7 +1088,7 @@ function motion(options) {
1086
1088
  const {
1087
1089
  from,
1088
1090
  to,
1089
- duration = 300,
1091
+ duration: duration2 = 300,
1090
1092
  frame = () => {
1091
1093
  },
1092
1094
  timingFunction = (value2) => value2,
@@ -1114,7 +1116,7 @@ function motion(options) {
1114
1116
  ticker = requestAnimationFrame(() => {
1115
1117
  const now2 = performance.now();
1116
1118
  const executionTime = now2 - startTime - sleepTime;
1117
- const progress = clamp(executionTime / duration, 0, 1);
1119
+ const progress = clamp(executionTime / duration2, 0, 1);
1118
1120
  value = distance * timingFunction(progress) + from;
1119
1121
  if (progress >= 1) {
1120
1122
  setState("finished");
@@ -1158,6 +1160,58 @@ function motion(options) {
1158
1160
  };
1159
1161
  }
1160
1162
 
1163
+ // src/util/duration.ts
1164
+ function duration() {
1165
+ const ctx = {
1166
+ value: 0,
1167
+ years,
1168
+ months,
1169
+ weeks,
1170
+ days,
1171
+ hours,
1172
+ minutes,
1173
+ seconds,
1174
+ milliseconds,
1175
+ valueOf
1176
+ };
1177
+ function years(value) {
1178
+ ctx.value += value * 365 * 24 * 60 * 60 * 1e3;
1179
+ return ctx;
1180
+ }
1181
+ function months(value) {
1182
+ ctx.value += value * 30 * 24 * 60 * 60 * 1e3;
1183
+ return ctx;
1184
+ }
1185
+ function weeks(value) {
1186
+ ctx.value += value * 7 * 24 * 60 * 60 * 1e3;
1187
+ return ctx;
1188
+ }
1189
+ function days(value) {
1190
+ ctx.value += value * 24 * 60 * 60 * 1e3;
1191
+ return ctx;
1192
+ }
1193
+ function hours(value) {
1194
+ ctx.value += value * 60 * 60 * 1e3;
1195
+ return ctx;
1196
+ }
1197
+ function minutes(value) {
1198
+ ctx.value += value * 60 * 1e3;
1199
+ return ctx;
1200
+ }
1201
+ function seconds(value) {
1202
+ ctx.value += value * 1e3;
1203
+ return ctx;
1204
+ }
1205
+ function milliseconds(value) {
1206
+ ctx.value += value;
1207
+ return ctx;
1208
+ }
1209
+ function valueOf(options = { milliseconds: true }) {
1210
+ return options.milliseconds ? ctx.value : ctx.value / 1e3;
1211
+ }
1212
+ return ctx;
1213
+ }
1214
+
1161
1215
  // src/util/index.ts
1162
1216
  __reExport(util_exports, mitt_star);
1163
1217
  import * as mitt_star from "mitt";
@@ -1512,6 +1566,7 @@ export {
1512
1566
  differenceWith,
1513
1567
  doubleRaf,
1514
1568
  download,
1569
+ duration,
1515
1570
  ensurePrefix,
1516
1571
  ensureSuffix,
1517
1572
  find,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "A utilities library for front-end developers, lightweight and ts-friendly",
5
5
  "keywords": [
6
6
  "utilities library",