@studiometa/js-toolkit 2.2.1 → 2.3.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.
Files changed (131) hide show
  1. package/Base/index.cjs +60 -69
  2. package/Base/index.d.ts +0 -8
  3. package/Base/index.js +67 -82
  4. package/Base/managers/AbstractManager.cjs +5 -10
  5. package/Base/managers/AbstractManager.js +5 -11
  6. package/Base/managers/ChildrenManager.cjs +2 -11
  7. package/Base/managers/ChildrenManager.js +2 -12
  8. package/Base/managers/EventsManager.cjs +61 -67
  9. package/Base/managers/EventsManager.js +61 -68
  10. package/Base/managers/OptionsManager.cjs +26 -27
  11. package/Base/managers/OptionsManager.js +26 -28
  12. package/Base/managers/RefsManager.cjs +9 -7
  13. package/Base/managers/RefsManager.js +9 -7
  14. package/Base/managers/ResponsiveOptionsManager.cjs +4 -1
  15. package/Base/managers/ResponsiveOptionsManager.js +4 -1
  16. package/Base/managers/ServicesManager.cjs +10 -16
  17. package/Base/managers/ServicesManager.js +10 -17
  18. package/Base/utils.cjs +22 -4
  19. package/Base/utils.d.ts +25 -8
  20. package/Base/utils.js +22 -4
  21. package/decorators/withBreakpointManager.cjs +15 -5
  22. package/decorators/withBreakpointManager.js +15 -5
  23. package/decorators/withBreakpointObserver.cjs +19 -18
  24. package/decorators/withBreakpointObserver.js +19 -19
  25. package/decorators/withDrag.cjs +6 -11
  26. package/decorators/withDrag.js +6 -12
  27. package/decorators/withExtraConfig.cjs +3 -8
  28. package/decorators/withExtraConfig.js +3 -9
  29. package/decorators/withFreezedOptions.cjs +1 -9
  30. package/decorators/withFreezedOptions.js +1 -10
  31. package/decorators/withIntersectionObserver.cjs +11 -16
  32. package/decorators/withIntersectionObserver.js +11 -17
  33. package/decorators/withMountWhenInView.cjs +12 -17
  34. package/decorators/withMountWhenInView.js +12 -18
  35. package/decorators/withScrolledInView.cjs +30 -35
  36. package/decorators/withScrolledInView.js +30 -36
  37. package/decorators/withVue2.cjs +20 -18
  38. package/decorators/withVue2.js +20 -19
  39. package/helpers/getInstanceFromElement.cjs +1 -2
  40. package/helpers/getInstanceFromElement.js +1 -2
  41. package/helpers/importOnInteraction.cjs +3 -2
  42. package/helpers/importOnInteraction.js +3 -2
  43. package/helpers/importWhenIdle.cjs +2 -3
  44. package/helpers/importWhenIdle.js +2 -3
  45. package/helpers/importWhenVisible.cjs +3 -2
  46. package/helpers/importWhenVisible.js +3 -2
  47. package/helpers/utils.cjs +3 -2
  48. package/helpers/utils.js +3 -2
  49. package/package.json +4 -1
  50. package/services/drag.cjs +126 -148
  51. package/services/drag.d.ts +10 -10
  52. package/services/drag.js +125 -148
  53. package/services/index.cjs +3 -1
  54. package/services/index.d.ts +1 -0
  55. package/services/index.js +3 -1
  56. package/services/key.cjs +48 -63
  57. package/services/key.d.ts +0 -8
  58. package/services/key.js +47 -63
  59. package/services/load.cjs +24 -40
  60. package/services/load.d.ts +0 -8
  61. package/services/load.js +23 -37
  62. package/services/pointer.cjs +72 -103
  63. package/services/pointer.d.ts +1 -9
  64. package/services/pointer.js +71 -100
  65. package/services/raf.cjs +38 -58
  66. package/services/raf.d.ts +0 -8
  67. package/services/raf.js +37 -55
  68. package/services/resize.cjs +59 -68
  69. package/services/resize.d.ts +0 -7
  70. package/services/resize.js +58 -68
  71. package/services/scroll.cjs +49 -71
  72. package/services/scroll.js +48 -71
  73. package/services/service.cjs +68 -0
  74. package/services/service.d.ts +18 -0
  75. package/services/service.js +46 -0
  76. package/utils/css/animate.cjs +33 -102
  77. package/utils/css/animate.d.ts +4 -13
  78. package/utils/css/animate.js +31 -100
  79. package/utils/css/classes.cjs +2 -1
  80. package/utils/css/classes.js +2 -1
  81. package/utils/css/matrix.cjs +1 -2
  82. package/utils/css/matrix.js +1 -2
  83. package/utils/css/styles.cjs +2 -5
  84. package/utils/css/styles.js +1 -1
  85. package/utils/css/transform.cjs +14 -18
  86. package/utils/css/transform.js +2 -3
  87. package/utils/css/transition.cjs +7 -10
  88. package/utils/css/transition.js +7 -11
  89. package/utils/focusTrap.cjs +2 -1
  90. package/utils/focusTrap.js +2 -1
  91. package/utils/{isFunction.cjs → has.cjs} +7 -7
  92. package/utils/has.d.ts +6 -0
  93. package/utils/has.js +6 -0
  94. package/utils/history.cjs +5 -7
  95. package/utils/history.js +4 -3
  96. package/utils/index.cjs +6 -5
  97. package/utils/index.d.ts +4 -2
  98. package/utils/index.js +6 -5
  99. package/utils/{object/isObject.cjs → is.cjs} +20 -8
  100. package/utils/is.d.ts +8 -0
  101. package/utils/is.js +18 -0
  102. package/utils/math/inertiaFinalValue.cjs +5 -3
  103. package/utils/math/inertiaFinalValue.js +2 -3
  104. package/utils/nextFrame.cjs +5 -3
  105. package/utils/nextFrame.js +5 -3
  106. package/utils/nextMicrotask.cjs +2 -1
  107. package/utils/nextMicrotask.js +2 -1
  108. package/utils/nextTick.cjs +2 -1
  109. package/utils/nextTick.js +2 -1
  110. package/utils/{isDefined.cjs → noop.cjs} +10 -7
  111. package/utils/noop.d.ts +12 -0
  112. package/utils/noop.js +9 -0
  113. package/utils/object/autoBind.cjs +3 -2
  114. package/utils/object/autoBind.js +3 -2
  115. package/utils/object/getAllProperties.cjs +2 -1
  116. package/utils/object/getAllProperties.js +2 -1
  117. package/utils/object/index.cjs +1 -3
  118. package/utils/object/index.d.ts +0 -1
  119. package/utils/object/index.js +1 -3
  120. package/utils/tween.cjs +113 -0
  121. package/utils/tween.d.ts +25 -0
  122. package/utils/tween.js +88 -0
  123. package/services/Service.cjs +0 -76
  124. package/services/Service.d.ts +0 -76
  125. package/services/Service.js +0 -55
  126. package/utils/isDefined.d.ts +0 -7
  127. package/utils/isDefined.js +0 -6
  128. package/utils/isFunction.d.ts +0 -7
  129. package/utils/isFunction.js +0 -6
  130. package/utils/object/isObject.d.ts +0 -7
  131. package/utils/object/isObject.js +0 -6
package/utils/index.cjs CHANGED
@@ -27,8 +27,6 @@ __export(utils_exports, {
27
27
  focusTrap: () => import_focusTrap.default,
28
28
  historyPush: () => import_history.push,
29
29
  historyReplace: () => import_history.replace,
30
- isDefined: () => import_isDefined.default,
31
- isFunction: () => import_isFunction.default,
32
30
  keyCodes: () => import_keyCodes.default,
33
31
  memoize: () => import_memoize.default,
34
32
  nextFrame: () => import_nextFrame.nextFrame,
@@ -36,7 +34,8 @@ __export(utils_exports, {
36
34
  nextTick: () => import_nextTick.default,
37
35
  objectToURLSearchParams: () => import_history.objectToURLSearchParams,
38
36
  scrollTo: () => import_scrollTo.default,
39
- throttle: () => import_throttle.default
37
+ throttle: () => import_throttle.default,
38
+ tween: () => import_tween.tween
40
39
  });
41
40
  module.exports = __toCommonJS(utils_exports);
42
41
  var import_debounce = __toESM(require("./debounce.cjs"), 1);
@@ -48,12 +47,14 @@ var import_nextTick = __toESM(require("./nextTick.cjs"), 1);
48
47
  var import_nextMicrotask = __toESM(require("./nextMicrotask.cjs"), 1);
49
48
  var import_throttle = __toESM(require("./throttle.cjs"), 1);
50
49
  var import_scrollTo = __toESM(require("./scrollTo.cjs"), 1);
51
- var import_isDefined = __toESM(require("./isDefined.cjs"), 1);
52
- var import_isFunction = __toESM(require("./isFunction.cjs"), 1);
50
+ __reExport(utils_exports, require("./is.cjs"), module.exports);
51
+ __reExport(utils_exports, require("./has.cjs"), module.exports);
53
52
  __reExport(utils_exports, require("./css/index.cjs"), module.exports);
54
53
  var import_history = require("./history.cjs");
55
54
  __reExport(utils_exports, require("./collide/index.cjs"), module.exports);
56
55
  __reExport(utils_exports, require("./math/index.cjs"), module.exports);
57
56
  __reExport(utils_exports, require("./string/index.cjs"), module.exports);
58
57
  __reExport(utils_exports, require("./scheduler.cjs"), module.exports);
58
+ __reExport(utils_exports, require("./noop.cjs"), module.exports);
59
+ var import_tween = require("./tween.cjs");
59
60
  if (module.exports.default) module.exports = module.exports.default;
package/utils/index.d.ts CHANGED
@@ -7,11 +7,13 @@ export { default as nextTick } from "./nextTick.js";
7
7
  export { default as nextMicrotask } from "./nextMicrotask.js";
8
8
  export { default as throttle } from "./throttle.js";
9
9
  export { default as scrollTo } from "./scrollTo.js";
10
- export { default as isDefined } from "./isDefined.js";
11
- export { default as isFunction } from "./isFunction.js";
10
+ export * from "./is.js";
11
+ export * from "./has.js";
12
12
  export * from "./css/index.js";
13
13
  export * from "./collide/index.js";
14
14
  export * from "./math/index.js";
15
15
  export * from "./string/index.js";
16
16
  export * from "./scheduler.js";
17
+ export * from "./noop.js";
18
+ export { tween } from "./tween.js";
17
19
  export { objectToURLSearchParams, push as historyPush, replace as historyReplace } from "./history.js";
package/utils/index.js CHANGED
@@ -7,8 +7,8 @@ import { default as default6 } from "./nextTick.js";
7
7
  import { default as default7 } from "./nextMicrotask.js";
8
8
  import { default as default8 } from "./throttle.js";
9
9
  import { default as default9 } from "./scrollTo.js";
10
- import { default as default10 } from "./isDefined.js";
11
- import { default as default11 } from "./isFunction.js";
10
+ export * from "./is.js";
11
+ export * from "./has.js";
12
12
  export * from "./css/index.js";
13
13
  import {
14
14
  objectToURLSearchParams,
@@ -19,13 +19,13 @@ export * from "./collide/index.js";
19
19
  export * from "./math/index.js";
20
20
  export * from "./string/index.js";
21
21
  export * from "./scheduler.js";
22
+ export * from "./noop.js";
23
+ import { tween } from "./tween.js";
22
24
  export {
23
25
  default2 as debounce,
24
26
  default3 as focusTrap,
25
27
  push as historyPush,
26
28
  replace as historyReplace,
27
- default10 as isDefined,
28
- default11 as isFunction,
29
29
  default4 as keyCodes,
30
30
  default5 as memoize,
31
31
  nextFrame,
@@ -33,5 +33,6 @@ export {
33
33
  default6 as nextTick,
34
34
  objectToURLSearchParams,
35
35
  default9 as scrollTo,
36
- default8 as throttle
36
+ default8 as throttle,
37
+ tween
37
38
  };
@@ -16,13 +16,25 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/utils/object/isObject.js
20
- var isObject_exports = {};
21
- __export(isObject_exports, {
22
- default: () => isObject
19
+ // packages/js-toolkit/utils/is.js
20
+ var is_exports = {};
21
+ __export(is_exports, {
22
+ isArray: () => isArray,
23
+ isBoolean: () => isBoolean,
24
+ isDefined: () => isDefined,
25
+ isDev: () => isDev,
26
+ isFunction: () => isFunction,
27
+ isNumber: () => isNumber,
28
+ isObject: () => isObject,
29
+ isString: () => isString
23
30
  });
24
- module.exports = __toCommonJS(isObject_exports);
25
- function isObject(value) {
26
- return typeof value === "object" && !!value && value.toString() === "[object Object]";
27
- }
31
+ module.exports = __toCommonJS(is_exports);
32
+ var isDev = typeof __DEV__ !== "undefined" && __DEV__;
33
+ var isFunction = (value) => typeof value === "function";
34
+ var isDefined = (value) => typeof value !== "undefined";
35
+ var isString = (value) => typeof value === "string";
36
+ var isObject = (value) => typeof value === "object" && !!value && value.toString() === "[object Object]";
37
+ var isNumber = (value) => typeof value === "number";
38
+ var isBoolean = (value) => typeof value === "boolean";
39
+ var isArray = Array.isArray;
28
40
  if (module.exports.default) module.exports = module.exports.default;
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 {
@@ -16,13 +16,16 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/utils/isDefined.js
20
- var isDefined_exports = {};
21
- __export(isDefined_exports, {
22
- default: () => isDefined
19
+ // packages/js-toolkit/utils/noop.js
20
+ var noop_exports = {};
21
+ __export(noop_exports, {
22
+ noop: () => noop,
23
+ noopValue: () => noopValue
23
24
  });
24
- module.exports = __toCommonJS(isDefined_exports);
25
- function isDefined(value) {
26
- return typeof value !== "undefined";
25
+ module.exports = __toCommonJS(noop_exports);
26
+ function noop() {
27
+ }
28
+ function noopValue(value) {
29
+ return value;
27
30
  }
28
31
  if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * No operation function.
3
+ * @returns {void}
4
+ */
5
+ export function noop(): void;
6
+ /**
7
+ * No operation function which return the given value unaltered.
8
+ * @template {any} T
9
+ * @param {T} value
10
+ * @returns {T}
11
+ */
12
+ export function noopValue<T extends unknown>(value: T): T;
package/utils/noop.js ADDED
@@ -0,0 +1,9 @@
1
+ function noop() {
2
+ }
3
+ function noopValue(value) {
4
+ return value;
5
+ }
6
+ export {
7
+ noop,
8
+ noopValue
9
+ };
@@ -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,113 @@
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
+ const raf = (0, import_raf.default)();
47
+ let progressValue = 0;
48
+ let easedProgress = 0;
49
+ const ease = normalizeEase(options.easing);
50
+ let duration = options.duration ?? 1;
51
+ duration *= 1e3;
52
+ let startTime = performance.now();
53
+ let endTime = startTime + duration;
54
+ const key = `tw-${id}`;
55
+ id += 1;
56
+ const { onStart = import_noop.noop, onProgress = import_noop.noop, onFinish = import_noop.noop } = options;
57
+ let isRunning = false;
58
+ function pause() {
59
+ isRunning = false;
60
+ raf.remove(key);
61
+ }
62
+ function progress(newProgress) {
63
+ if (typeof newProgress === "undefined") {
64
+ return easedProgress;
65
+ }
66
+ progressValue = newProgress;
67
+ easedProgress = ease(progressValue);
68
+ if (Math.abs(1 - easedProgress) < PROGRESS_PRECISION) {
69
+ progressValue = 1;
70
+ easedProgress = 1;
71
+ }
72
+ callback(easedProgress);
73
+ onProgress(progressValue, easedProgress);
74
+ if (easedProgress === 1) {
75
+ pause();
76
+ requestAnimationFrame(() => onFinish(progressValue, easedProgress));
77
+ }
78
+ return progressValue;
79
+ }
80
+ function tick(props) {
81
+ if (!isRunning) {
82
+ raf.remove(key);
83
+ return;
84
+ }
85
+ progress((0, import_math.clamp01)((0, import_math.map)(props.time, startTime, endTime, 0, 1)));
86
+ }
87
+ function start() {
88
+ onStart();
89
+ startTime = performance.now();
90
+ endTime = startTime + duration;
91
+ progressValue = 0;
92
+ easedProgress = 0;
93
+ isRunning = true;
94
+ raf.add(key, tick);
95
+ }
96
+ function play() {
97
+ if (isRunning) {
98
+ return;
99
+ }
100
+ startTime = performance.now() - (0, import_math.lerp)(0, duration, progressValue);
101
+ endTime = startTime + duration;
102
+ isRunning = true;
103
+ raf.add(key, tick);
104
+ }
105
+ return {
106
+ start,
107
+ finish: () => progress(1),
108
+ pause,
109
+ play,
110
+ progress
111
+ };
112
+ }
113
+ 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,88 @@
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
+ const raf = useRaf();
19
+ let progressValue = 0;
20
+ let easedProgress = 0;
21
+ const ease = normalizeEase(options.easing);
22
+ let duration = options.duration ?? 1;
23
+ duration *= 1e3;
24
+ let startTime = performance.now();
25
+ let endTime = startTime + duration;
26
+ const key = `tw-${id}`;
27
+ id += 1;
28
+ const { onStart = noop, onProgress = noop, onFinish = noop } = options;
29
+ let isRunning = false;
30
+ function pause() {
31
+ isRunning = false;
32
+ raf.remove(key);
33
+ }
34
+ function progress(newProgress) {
35
+ if (typeof newProgress === "undefined") {
36
+ return easedProgress;
37
+ }
38
+ progressValue = newProgress;
39
+ easedProgress = ease(progressValue);
40
+ if (Math.abs(1 - easedProgress) < PROGRESS_PRECISION) {
41
+ progressValue = 1;
42
+ easedProgress = 1;
43
+ }
44
+ callback(easedProgress);
45
+ onProgress(progressValue, easedProgress);
46
+ if (easedProgress === 1) {
47
+ pause();
48
+ requestAnimationFrame(() => onFinish(progressValue, easedProgress));
49
+ }
50
+ return progressValue;
51
+ }
52
+ function tick(props) {
53
+ if (!isRunning) {
54
+ raf.remove(key);
55
+ return;
56
+ }
57
+ progress(clamp01(map(props.time, startTime, endTime, 0, 1)));
58
+ }
59
+ function start() {
60
+ onStart();
61
+ startTime = performance.now();
62
+ endTime = startTime + duration;
63
+ progressValue = 0;
64
+ easedProgress = 0;
65
+ isRunning = true;
66
+ raf.add(key, tick);
67
+ }
68
+ function play() {
69
+ if (isRunning) {
70
+ return;
71
+ }
72
+ startTime = performance.now() - lerp(0, duration, progressValue);
73
+ endTime = startTime + duration;
74
+ isRunning = true;
75
+ raf.add(key, tick);
76
+ }
77
+ return {
78
+ start,
79
+ finish: () => progress(1),
80
+ pause,
81
+ play,
82
+ progress
83
+ };
84
+ }
85
+ export {
86
+ normalizeEase,
87
+ tween
88
+ };