@studiometa/js-toolkit 2.2.3 → 2.4.1

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.
Files changed (87) hide show
  1. package/Base/index.cjs +29 -36
  2. package/Base/index.d.ts +0 -8
  3. package/Base/index.js +18 -25
  4. package/Base/managers/EventsManager.cjs +35 -36
  5. package/Base/managers/EventsManager.js +35 -36
  6. package/Base/managers/OptionsManager.cjs +19 -13
  7. package/Base/managers/OptionsManager.js +19 -13
  8. package/Base/managers/RefsManager.cjs +8 -5
  9. package/Base/managers/RefsManager.js +8 -5
  10. package/Base/managers/ResponsiveOptionsManager.cjs +4 -1
  11. package/Base/managers/ResponsiveOptionsManager.js +4 -1
  12. package/Base/managers/ServicesManager.cjs +5 -2
  13. package/Base/managers/ServicesManager.js +6 -3
  14. package/Base/utils.cjs +23 -1
  15. package/Base/utils.d.ts +25 -0
  16. package/Base/utils.js +23 -1
  17. package/README.md +3 -3
  18. package/decorators/withBreakpointManager.cjs +15 -5
  19. package/decorators/withBreakpointManager.js +15 -5
  20. package/decorators/withBreakpointObserver.cjs +8 -2
  21. package/decorators/withBreakpointObserver.js +8 -2
  22. package/decorators/withVue2.cjs +10 -3
  23. package/decorators/withVue2.js +10 -3
  24. package/helpers/getDirectChildren.cjs +46 -0
  25. package/helpers/getDirectChildren.d.ts +24 -0
  26. package/helpers/getDirectChildren.js +24 -0
  27. package/helpers/importOnInteraction.cjs +2 -1
  28. package/helpers/importOnInteraction.js +2 -1
  29. package/helpers/importWhenVisible.cjs +2 -1
  30. package/helpers/importWhenVisible.js +2 -1
  31. package/helpers/index.cjs +2 -0
  32. package/helpers/index.d.ts +1 -0
  33. package/helpers/index.js +1 -0
  34. package/helpers/utils.cjs +3 -2
  35. package/helpers/utils.js +3 -2
  36. package/package.json +4 -1
  37. package/services/raf.cjs +2 -5
  38. package/services/raf.js +1 -1
  39. package/utils/css/animate.cjs +31 -92
  40. package/utils/css/animate.d.ts +4 -16
  41. package/utils/css/animate.js +28 -89
  42. package/utils/css/classes.cjs +2 -1
  43. package/utils/css/classes.js +2 -1
  44. package/utils/css/styles.cjs +2 -5
  45. package/utils/css/styles.js +1 -1
  46. package/utils/css/transform.cjs +13 -16
  47. package/utils/css/transform.js +1 -1
  48. package/utils/css/transition.cjs +5 -3
  49. package/utils/css/transition.js +5 -3
  50. package/utils/focusTrap.cjs +2 -1
  51. package/utils/focusTrap.js +2 -1
  52. package/utils/{isFunction.cjs → has.cjs} +7 -7
  53. package/utils/has.d.ts +6 -0
  54. package/utils/has.js +6 -0
  55. package/utils/history.cjs +5 -7
  56. package/utils/history.js +4 -3
  57. package/utils/index.cjs +5 -5
  58. package/utils/index.d.ts +3 -2
  59. package/utils/index.js +5 -5
  60. package/utils/{isDefined.cjs → is.cjs} +20 -8
  61. package/utils/is.d.ts +8 -0
  62. package/utils/is.js +18 -0
  63. package/utils/math/inertiaFinalValue.cjs +5 -3
  64. package/utils/math/inertiaFinalValue.js +2 -3
  65. package/utils/nextFrame.cjs +5 -3
  66. package/utils/nextFrame.js +5 -3
  67. package/utils/nextMicrotask.cjs +2 -1
  68. package/utils/nextMicrotask.js +2 -1
  69. package/utils/nextTick.cjs +2 -1
  70. package/utils/nextTick.js +2 -1
  71. package/utils/object/autoBind.cjs +3 -2
  72. package/utils/object/autoBind.js +3 -2
  73. package/utils/object/getAllProperties.cjs +2 -1
  74. package/utils/object/getAllProperties.js +2 -1
  75. package/utils/object/index.cjs +1 -3
  76. package/utils/object/index.d.ts +0 -1
  77. package/utils/object/index.js +1 -3
  78. package/utils/tween.cjs +114 -0
  79. package/utils/tween.d.ts +25 -0
  80. package/utils/tween.js +89 -0
  81. package/utils/isDefined.d.ts +0 -7
  82. package/utils/isDefined.js +0 -6
  83. package/utils/isFunction.d.ts +0 -7
  84. package/utils/isFunction.js +0 -6
  85. package/utils/object/isObject.cjs +0 -28
  86. package/utils/object/isObject.d.ts +0 -7
  87. package/utils/object/isObject.js +0 -6
package/utils/is.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export const isDev: boolean;
2
+ export function isFunction(value: unknown): value is Function;
3
+ export function isDefined(value: unknown): boolean;
4
+ export function isString(value: unknown): value is string;
5
+ export function isObject(value: unknown): boolean;
6
+ export function isNumber(value: unknown): value is number;
7
+ export function isBoolean(value: unknown): value is boolean;
8
+ export const isArray: (arg: any) => arg is any[];
package/utils/is.js ADDED
@@ -0,0 +1,18 @@
1
+ const isDev = typeof __DEV__ !== "undefined" && __DEV__;
2
+ const isFunction = (value) => typeof value === "function";
3
+ const isDefined = (value) => typeof value !== "undefined";
4
+ const isString = (value) => typeof value === "string";
5
+ const isObject = (value) => typeof value === "object" && !!value && value.toString() === "[object Object]";
6
+ const isNumber = (value) => typeof value === "number";
7
+ const isBoolean = (value) => typeof value === "boolean";
8
+ const isArray = Array.isArray;
9
+ export {
10
+ isArray,
11
+ isBoolean,
12
+ isDefined,
13
+ isDev,
14
+ isFunction,
15
+ isNumber,
16
+ isObject,
17
+ isString
18
+ };
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
17
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
21
 
19
22
  // packages/js-toolkit/utils/math/inertiaFinalValue.js
@@ -22,10 +25,9 @@ __export(inertiaFinalValue_exports, {
22
25
  default: () => inertiaFinalValue
23
26
  });
24
27
  module.exports = __toCommonJS(inertiaFinalValue_exports);
28
+ var import_clamp = __toESM(require("./clamp.cjs"), 1);
25
29
  function inertiaFinalValue(initialValue, initialDelta, dampFactor = 0.85) {
26
- if (dampFactor >= 1 || dampFactor <= 0) {
27
- throw new Error(`The \`factor\` parameter must be a number greater than 0 and smaller than 1, \`${dampFactor}\` given.`);
28
- }
30
+ dampFactor = (0, import_clamp.default)(dampFactor, 1e-5, 0.99999);
29
31
  let delta = initialDelta;
30
32
  let finalValue = initialValue;
31
33
  while (Math.abs(delta) > 0.1) {
@@ -1,7 +1,6 @@
1
+ import clamp from "./clamp.js";
1
2
  function inertiaFinalValue(initialValue, initialDelta, dampFactor = 0.85) {
2
- if (dampFactor >= 1 || dampFactor <= 0) {
3
- throw new Error(`The \`factor\` parameter must be a number greater than 0 and smaller than 1, \`${dampFactor}\` given.`);
4
- }
3
+ dampFactor = clamp(dampFactor, 1e-5, 0.99999);
5
4
  let delta = initialDelta;
6
5
  let finalValue = initialValue;
7
6
  while (Math.abs(delta) > 0.1) {
@@ -24,15 +24,17 @@ __export(nextFrame_exports, {
24
24
  nextFrame: () => nextFrame
25
25
  });
26
26
  module.exports = __toCommonJS(nextFrame_exports);
27
+ var import_is = require("./is.cjs");
28
+ var import_has = require("./has.cjs");
27
29
  function getRaf() {
28
- return typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : setTimeout;
30
+ return (0, import_has.hasWindow)() && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : setTimeout;
29
31
  }
30
32
  function getCancelRaf() {
31
- return typeof window !== "undefined" && window.cancelAnimationFrame ? window.cancelAnimationFrame.bind(window) : clearTimeout;
33
+ return (0, import_has.hasWindow)() && window.cancelAnimationFrame ? window.cancelAnimationFrame.bind(window) : clearTimeout;
32
34
  }
33
35
  function nextFrame(fn) {
34
36
  return new Promise((resolve) => {
35
- getRaf()(() => resolve(typeof fn === "function" && fn()));
37
+ getRaf()(() => resolve((0, import_is.isFunction)(fn) && fn()));
36
38
  });
37
39
  }
38
40
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,12 +1,14 @@
1
+ import { isFunction } from "./is.js";
2
+ import { hasWindow } from "./has.js";
1
3
  function getRaf() {
2
- return typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : setTimeout;
4
+ return hasWindow() && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : setTimeout;
3
5
  }
4
6
  function getCancelRaf() {
5
- return typeof window !== "undefined" && window.cancelAnimationFrame ? window.cancelAnimationFrame.bind(window) : clearTimeout;
7
+ return hasWindow() && window.cancelAnimationFrame ? window.cancelAnimationFrame.bind(window) : clearTimeout;
6
8
  }
7
9
  function nextFrame(fn) {
8
10
  return new Promise((resolve) => {
9
- getRaf()(() => resolve(typeof fn === "function" && fn()));
11
+ getRaf()(() => resolve(isFunction(fn) && fn()));
10
12
  });
11
13
  }
12
14
  export {
@@ -22,7 +22,8 @@ __export(nextMicrotask_exports, {
22
22
  default: () => nextMicrotask
23
23
  });
24
24
  module.exports = __toCommonJS(nextMicrotask_exports);
25
+ var import_is = require("./is.cjs");
25
26
  async function nextMicrotask(fn) {
26
- return Promise.resolve().then(() => typeof fn === "function" && fn());
27
+ return Promise.resolve().then(() => (0, import_is.isFunction)(fn) && fn());
27
28
  }
28
29
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,5 +1,6 @@
1
+ import { isFunction } from "./is.js";
1
2
  async function nextMicrotask(fn) {
2
- return Promise.resolve().then(() => typeof fn === "function" && fn());
3
+ return Promise.resolve().then(() => isFunction(fn) && fn());
3
4
  }
4
5
  export {
5
6
  nextMicrotask as default
@@ -22,9 +22,10 @@ __export(nextTick_exports, {
22
22
  default: () => nextTick
23
23
  });
24
24
  module.exports = __toCommonJS(nextTick_exports);
25
+ var import_is = require("./is.cjs");
25
26
  async function nextTick(fn) {
26
27
  return new Promise((resolve) => setTimeout(() => {
27
- resolve(typeof fn === "function" && fn());
28
+ resolve((0, import_is.isFunction)(fn) && fn());
28
29
  }, 0));
29
30
  }
30
31
  if (module.exports.default) module.exports = module.exports.default;
package/utils/nextTick.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { isFunction } from "./is.js";
1
2
  async function nextTick(fn) {
2
3
  return new Promise((resolve) => setTimeout(() => {
3
- resolve(typeof fn === "function" && fn());
4
+ resolve(isFunction(fn) && fn());
4
5
  }, 0));
5
6
  }
6
7
  export {
@@ -26,10 +26,11 @@ __export(autoBind_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(autoBind_exports);
28
28
  var import_getAllProperties = __toESM(require("./getAllProperties.cjs"), 1);
29
+ var import_is = require("../is.cjs");
29
30
  function autoBind(instance, options) {
30
31
  const { exclude, include } = options || {};
31
32
  const filter = (key) => {
32
- const match = (pattern) => typeof pattern === "string" ? key === pattern : pattern.test(key);
33
+ const match = (pattern) => (0, import_is.isString)(pattern) ? key === pattern : pattern.test(key);
33
34
  if (include) {
34
35
  return include.some(match);
35
36
  }
@@ -40,7 +41,7 @@ function autoBind(instance, options) {
40
41
  };
41
42
  (0, import_getAllProperties.default)(instance).filter(([key]) => key !== "constructor" && filter(key)).forEach(([key, object]) => {
42
43
  const descriptor = Object.getOwnPropertyDescriptor(object, key);
43
- if (descriptor && typeof descriptor.value === "function") {
44
+ if (descriptor && (0, import_is.isFunction)(descriptor.value)) {
44
45
  instance[key] = instance[key].bind(instance);
45
46
  }
46
47
  });
@@ -1,8 +1,9 @@
1
1
  import getAllProperties from "./getAllProperties.js";
2
+ import { isString, isFunction } from "../is.js";
2
3
  function autoBind(instance, options) {
3
4
  const { exclude, include } = options || {};
4
5
  const filter = (key) => {
5
- const match = (pattern) => typeof pattern === "string" ? key === pattern : pattern.test(key);
6
+ const match = (pattern) => isString(pattern) ? key === pattern : pattern.test(key);
6
7
  if (include) {
7
8
  return include.some(match);
8
9
  }
@@ -13,7 +14,7 @@ function autoBind(instance, options) {
13
14
  };
14
15
  getAllProperties(instance).filter(([key]) => key !== "constructor" && filter(key)).forEach(([key, object]) => {
15
16
  const descriptor = Object.getOwnPropertyDescriptor(object, key);
16
- if (descriptor && typeof descriptor.value === "function") {
17
+ if (descriptor && isFunction(descriptor.value)) {
17
18
  instance[key] = instance[key].bind(instance);
18
19
  }
19
20
  });
@@ -22,13 +22,14 @@ __export(getAllProperties_exports, {
22
22
  default: () => getAllProperties
23
23
  });
24
24
  module.exports = __toCommonJS(getAllProperties_exports);
25
+ var import_is = require("../is.cjs");
25
26
  function getAllProperties(object, props = [], testFn = null) {
26
27
  const proto = Object.getPrototypeOf(object);
27
28
  if (proto === Object.prototype || proto === null) {
28
29
  return props;
29
30
  }
30
31
  let foundProps = Object.getOwnPropertyNames(proto);
31
- if (typeof testFn === "function") {
32
+ if ((0, import_is.isFunction)(testFn)) {
32
33
  foundProps = foundProps.filter((name) => testFn(name, proto));
33
34
  }
34
35
  foundProps = foundProps.map((name) => [name, proto]).reduce((acc, val) => [...acc, val], props);
@@ -1,10 +1,11 @@
1
+ import { isFunction } from "../is.js";
1
2
  function getAllProperties(object, props = [], testFn = null) {
2
3
  const proto = Object.getPrototypeOf(object);
3
4
  if (proto === Object.prototype || proto === null) {
4
5
  return props;
5
6
  }
6
7
  let foundProps = Object.getOwnPropertyNames(proto);
7
- if (typeof testFn === "function") {
8
+ if (isFunction(testFn)) {
8
9
  foundProps = foundProps.filter((name) => testFn(name, proto));
9
10
  }
10
11
  foundProps = foundProps.map((name) => [name, proto]).reduce((acc, val) => [...acc, val], props);
@@ -23,11 +23,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
23
23
  var object_exports = {};
24
24
  __export(object_exports, {
25
25
  autoBind: () => import_autoBind.default,
26
- getAllProperties: () => import_getAllProperties.default,
27
- isObject: () => import_isObject.default
26
+ getAllProperties: () => import_getAllProperties.default
28
27
  });
29
28
  module.exports = __toCommonJS(object_exports);
30
29
  var import_autoBind = __toESM(require("./autoBind.cjs"), 1);
31
30
  var import_getAllProperties = __toESM(require("./getAllProperties.cjs"), 1);
32
- var import_isObject = __toESM(require("./isObject.cjs"), 1);
33
31
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,3 +1,2 @@
1
1
  export { default as autoBind } from "./autoBind.js";
2
2
  export { default as getAllProperties } from "./getAllProperties.js";
3
- export { default as isObject } from "./isObject.js";
@@ -1,8 +1,6 @@
1
1
  import { default as default2 } from "./autoBind.js";
2
2
  import { default as default3 } from "./getAllProperties.js";
3
- import { default as default4 } from "./isObject.js";
4
3
  export {
5
4
  default2 as autoBind,
6
- default3 as getAllProperties,
7
- default4 as isObject
5
+ default3 as getAllProperties
8
6
  };
@@ -0,0 +1,114 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // packages/js-toolkit/utils/tween.js
23
+ var tween_exports = {};
24
+ __export(tween_exports, {
25
+ normalizeEase: () => normalizeEase,
26
+ tween: () => tween
27
+ });
28
+ module.exports = __toCommonJS(tween_exports);
29
+ var import_easing = require("@motionone/easing");
30
+ var import_math = require("./math/index.cjs");
31
+ var import_is = require("./is.cjs");
32
+ var import_noop = require("./noop.cjs");
33
+ var import_raf = __toESM(require("../services/raf.cjs"), 1);
34
+ var id = 0;
35
+ var PROGRESS_PRECISION = 1e-4;
36
+ function normalizeEase(ease) {
37
+ if (!(0, import_is.isDefined)(ease)) {
38
+ return import_noop.noopValue;
39
+ }
40
+ if ((0, import_is.isArray)(ease)) {
41
+ return (0, import_easing.cubicBezier)(...ease);
42
+ }
43
+ return ease;
44
+ }
45
+ function tween(callback, options = {}) {
46
+ var _a;
47
+ const raf = (0, import_raf.default)();
48
+ let progressValue = 0;
49
+ let easedProgress = 0;
50
+ const ease = normalizeEase(options.easing);
51
+ let duration = (_a = options.duration) != null ? _a : 1;
52
+ duration *= 1e3;
53
+ let startTime = performance.now();
54
+ let endTime = startTime + duration;
55
+ const key = `tw-${id}`;
56
+ id += 1;
57
+ const { onStart = import_noop.noop, onProgress = import_noop.noop, onFinish = import_noop.noop } = options;
58
+ let isRunning = false;
59
+ function pause() {
60
+ isRunning = false;
61
+ raf.remove(key);
62
+ }
63
+ function progress(newProgress) {
64
+ if (typeof newProgress === "undefined") {
65
+ return easedProgress;
66
+ }
67
+ progressValue = newProgress;
68
+ easedProgress = ease(progressValue);
69
+ if (Math.abs(1 - easedProgress) < PROGRESS_PRECISION) {
70
+ progressValue = 1;
71
+ easedProgress = 1;
72
+ }
73
+ callback(easedProgress);
74
+ onProgress(progressValue, easedProgress);
75
+ if (easedProgress === 1) {
76
+ pause();
77
+ requestAnimationFrame(() => onFinish(progressValue, easedProgress));
78
+ }
79
+ return progressValue;
80
+ }
81
+ function tick(props) {
82
+ if (!isRunning) {
83
+ raf.remove(key);
84
+ return;
85
+ }
86
+ progress((0, import_math.clamp01)((0, import_math.map)(props.time, startTime, endTime, 0, 1)));
87
+ }
88
+ function start() {
89
+ onStart();
90
+ startTime = performance.now();
91
+ endTime = startTime + duration;
92
+ progressValue = 0;
93
+ easedProgress = 0;
94
+ isRunning = true;
95
+ raf.add(key, tick);
96
+ }
97
+ function play() {
98
+ if (isRunning) {
99
+ return;
100
+ }
101
+ startTime = performance.now() - (0, import_math.lerp)(0, duration, progressValue);
102
+ endTime = startTime + duration;
103
+ isRunning = true;
104
+ raf.add(key, tick);
105
+ }
106
+ return {
107
+ start,
108
+ finish: () => progress(1),
109
+ pause,
110
+ play,
111
+ progress
112
+ };
113
+ }
114
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @typedef {[number, number, number, number]} BezierCurve
3
+ * @typedef {{
4
+ * duration?: number;
5
+ * easing?: import('./math/createEases.js').EasingFunction|BezierCurve;
6
+ * onStart?: () => void;
7
+ * onProgress?: (progress: number, easedProgress: number) => void;
8
+ * onFinish?: (progress: number, easedProgress: number) => void;
9
+ * }} TweenOptions
10
+ */
11
+ /**
12
+ * Normalize a easing function with default fallbacks.
13
+ * @param {((p:number) => number)|[number,number,number,number]} ease
14
+ * @returns {(p:number) => number}
15
+ */
16
+ export function normalizeEase(ease: [number, number, number, number] | ((p: number) => number)): (p: number) => number;
17
+ /**
18
+ * Tween from 0 to 1.
19
+ * @param {(progress:number)=>any} callback
20
+ * @param {TweenOptions} [options]
21
+ * @returns {any}
22
+ */
23
+ export function tween(callback: (progress: number) => any, options?: TweenOptions): any;
24
+ export type BezierCurve = [number, number, number, number];
25
+ export type TweenOptions = TweenOptions;
package/utils/tween.js ADDED
@@ -0,0 +1,89 @@
1
+ import { cubicBezier } from "@motionone/easing";
2
+ import { lerp, map, clamp01 } from "./math/index.js";
3
+ import { isDefined, isArray } from "./is.js";
4
+ import { noop, noopValue as linear } from "./noop.js";
5
+ import useRaf from "../services/raf.js";
6
+ let id = 0;
7
+ const PROGRESS_PRECISION = 1e-4;
8
+ function normalizeEase(ease) {
9
+ if (!isDefined(ease)) {
10
+ return linear;
11
+ }
12
+ if (isArray(ease)) {
13
+ return cubicBezier(...ease);
14
+ }
15
+ return ease;
16
+ }
17
+ function tween(callback, options = {}) {
18
+ var _a;
19
+ const raf = useRaf();
20
+ let progressValue = 0;
21
+ let easedProgress = 0;
22
+ const ease = normalizeEase(options.easing);
23
+ let duration = (_a = options.duration) != null ? _a : 1;
24
+ duration *= 1e3;
25
+ let startTime = performance.now();
26
+ let endTime = startTime + duration;
27
+ const key = `tw-${id}`;
28
+ id += 1;
29
+ const { onStart = noop, onProgress = noop, onFinish = noop } = options;
30
+ let isRunning = false;
31
+ function pause() {
32
+ isRunning = false;
33
+ raf.remove(key);
34
+ }
35
+ function progress(newProgress) {
36
+ if (typeof newProgress === "undefined") {
37
+ return easedProgress;
38
+ }
39
+ progressValue = newProgress;
40
+ easedProgress = ease(progressValue);
41
+ if (Math.abs(1 - easedProgress) < PROGRESS_PRECISION) {
42
+ progressValue = 1;
43
+ easedProgress = 1;
44
+ }
45
+ callback(easedProgress);
46
+ onProgress(progressValue, easedProgress);
47
+ if (easedProgress === 1) {
48
+ pause();
49
+ requestAnimationFrame(() => onFinish(progressValue, easedProgress));
50
+ }
51
+ return progressValue;
52
+ }
53
+ function tick(props) {
54
+ if (!isRunning) {
55
+ raf.remove(key);
56
+ return;
57
+ }
58
+ progress(clamp01(map(props.time, startTime, endTime, 0, 1)));
59
+ }
60
+ function start() {
61
+ onStart();
62
+ startTime = performance.now();
63
+ endTime = startTime + duration;
64
+ progressValue = 0;
65
+ easedProgress = 0;
66
+ isRunning = true;
67
+ raf.add(key, tick);
68
+ }
69
+ function play() {
70
+ if (isRunning) {
71
+ return;
72
+ }
73
+ startTime = performance.now() - lerp(0, duration, progressValue);
74
+ endTime = startTime + duration;
75
+ isRunning = true;
76
+ raf.add(key, tick);
77
+ }
78
+ return {
79
+ start,
80
+ finish: () => progress(1),
81
+ pause,
82
+ play,
83
+ progress
84
+ };
85
+ }
86
+ export {
87
+ normalizeEase,
88
+ tween
89
+ };
@@ -1,7 +0,0 @@
1
- /**
2
- * Test if a value is defined or not.
3
- *
4
- * @param {any} value
5
- * @returns {boolean}
6
- */
7
- export default function isDefined(value: any): boolean;
@@ -1,6 +0,0 @@
1
- function isDefined(value) {
2
- return typeof value !== "undefined";
3
- }
4
- export {
5
- isDefined as default
6
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * Test if the given value is a function.
3
- *
4
- * @param {any} fn
5
- * @returns {boolean}
6
- */
7
- export default function isFunction(fn: any): boolean;
@@ -1,6 +0,0 @@
1
- function isFunction(fn) {
2
- return typeof fn === "function";
3
- }
4
- export {
5
- isFunction as default
6
- };
@@ -1,28 +0,0 @@
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/object/isObject.js
20
- var isObject_exports = {};
21
- __export(isObject_exports, {
22
- default: () => isObject
23
- });
24
- module.exports = __toCommonJS(isObject_exports);
25
- function isObject(value) {
26
- return typeof value === "object" && !!value && value.toString() === "[object Object]";
27
- }
28
- if (module.exports.default) module.exports = module.exports.default;
@@ -1,7 +0,0 @@
1
- /**
2
- * Test if the given value is an object.
3
- *
4
- * @param {*} value The value to test.
5
- * @returns {boolean} Whether or not the value is an object.
6
- */
7
- export default function isObject(value: any): boolean;
@@ -1,6 +0,0 @@
1
- function isObject(value) {
2
- return typeof value === "object" && !!value && value.toString() === "[object Object]";
3
- }
4
- export {
5
- isObject as default
6
- };