@studiometa/js-toolkit 2.2.3 → 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 (106) hide show
  1. package/Base/index.cjs +60 -68
  2. package/Base/index.d.ts +0 -8
  3. package/Base/index.js +67 -81
  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 +6 -11
  17. package/Base/managers/ServicesManager.js +7 -13
  18. package/Base/utils.cjs +23 -1
  19. package/Base/utils.d.ts +25 -0
  20. package/Base/utils.js +23 -1
  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/key.cjs +1 -1
  51. package/services/key.js +1 -1
  52. package/services/pointer.cjs +2 -3
  53. package/services/pointer.js +2 -3
  54. package/services/raf.cjs +2 -5
  55. package/services/raf.js +1 -1
  56. package/utils/css/animate.cjs +33 -98
  57. package/utils/css/animate.d.ts +4 -16
  58. package/utils/css/animate.js +31 -96
  59. package/utils/css/classes.cjs +2 -1
  60. package/utils/css/classes.js +2 -1
  61. package/utils/css/matrix.cjs +1 -2
  62. package/utils/css/matrix.js +1 -2
  63. package/utils/css/styles.cjs +2 -5
  64. package/utils/css/styles.js +1 -1
  65. package/utils/css/transform.cjs +14 -18
  66. package/utils/css/transform.js +2 -3
  67. package/utils/css/transition.cjs +7 -10
  68. package/utils/css/transition.js +7 -11
  69. package/utils/focusTrap.cjs +2 -1
  70. package/utils/focusTrap.js +2 -1
  71. package/utils/{isFunction.cjs → has.cjs} +7 -7
  72. package/utils/has.d.ts +6 -0
  73. package/utils/has.js +6 -0
  74. package/utils/history.cjs +5 -7
  75. package/utils/history.js +4 -3
  76. package/utils/index.cjs +5 -5
  77. package/utils/index.d.ts +3 -2
  78. package/utils/index.js +5 -5
  79. package/utils/{isDefined.cjs → is.cjs} +20 -8
  80. package/utils/is.d.ts +8 -0
  81. package/utils/is.js +18 -0
  82. package/utils/math/inertiaFinalValue.cjs +5 -3
  83. package/utils/math/inertiaFinalValue.js +2 -3
  84. package/utils/nextFrame.cjs +5 -3
  85. package/utils/nextFrame.js +5 -3
  86. package/utils/nextMicrotask.cjs +2 -1
  87. package/utils/nextMicrotask.js +2 -1
  88. package/utils/nextTick.cjs +2 -1
  89. package/utils/nextTick.js +2 -1
  90. package/utils/object/autoBind.cjs +3 -2
  91. package/utils/object/autoBind.js +3 -2
  92. package/utils/object/getAllProperties.cjs +2 -1
  93. package/utils/object/getAllProperties.js +2 -1
  94. package/utils/object/index.cjs +1 -3
  95. package/utils/object/index.d.ts +0 -1
  96. package/utils/object/index.js +1 -3
  97. package/utils/tween.cjs +113 -0
  98. package/utils/tween.d.ts +25 -0
  99. package/utils/tween.js +88 -0
  100. package/utils/isDefined.d.ts +0 -7
  101. package/utils/isDefined.js +0 -6
  102. package/utils/isFunction.d.ts +0 -7
  103. package/utils/isFunction.js +0 -6
  104. package/utils/object/isObject.cjs +0 -28
  105. package/utils/object/isObject.d.ts +0 -7
  106. package/utils/object/isObject.js +0 -6
@@ -1,8 +1,9 @@
1
+ import { isArray } from "../is.js";
1
2
  function setClasses(element, classNames, method, forceToggle) {
2
3
  if (!element || !classNames) {
3
4
  return;
4
5
  }
5
- const normalizedClassNames = Array.isArray(classNames) ? classNames : classNames.split(" ");
6
+ const normalizedClassNames = isArray(classNames) ? classNames : classNames.split(" ");
6
7
  if (method !== "toggle") {
7
8
  element.classList[method](...normalizedClassNames);
8
9
  } else {
@@ -23,8 +23,7 @@ __export(matrix_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(matrix_exports);
25
25
  function matrix(transform) {
26
- var _a, _b, _c, _d, _e, _f;
27
26
  transform = transform || {};
28
- return `matrix(${(_a = transform.scaleX) != null ? _a : 1}, ${(_b = transform.skewY) != null ? _b : 0}, ${(_c = transform.skewX) != null ? _c : 0}, ${(_d = transform.scaleY) != null ? _d : 1}, ${(_e = transform.translateX) != null ? _e : 0}, ${(_f = transform.translateY) != null ? _f : 0})`;
27
+ return `matrix(${transform.scaleX ?? 1}, ${transform.skewY ?? 0}, ${transform.skewX ?? 0}, ${transform.scaleY ?? 1}, ${transform.translateX ?? 0}, ${transform.translateY ?? 0})`;
29
28
  }
30
29
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,7 +1,6 @@
1
1
  function matrix(transform) {
2
- var _a, _b, _c, _d, _e, _f;
3
2
  transform = transform || {};
4
- return `matrix(${(_a = transform.scaleX) != null ? _a : 1}, ${(_b = transform.skewY) != null ? _b : 0}, ${(_c = transform.skewX) != null ? _c : 0}, ${(_d = transform.scaleY) != null ? _d : 1}, ${(_e = transform.translateX) != null ? _e : 0}, ${(_f = transform.translateY) != null ? _f : 0})`;
3
+ return `matrix(${transform.scaleX ?? 1}, ${transform.skewY ?? 0}, ${transform.skewX ?? 0}, ${transform.scaleY ?? 1}, ${transform.translateX ?? 0}, ${transform.translateY ?? 0})`;
5
4
  }
6
5
  export {
7
6
  matrix as default
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,7 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
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
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
18
 
22
19
  // packages/js-toolkit/utils/css/styles.js
@@ -26,9 +23,9 @@ __export(styles_exports, {
26
23
  remove: () => remove
27
24
  });
28
25
  module.exports = __toCommonJS(styles_exports);
29
- var import_isObject = __toESM(require("../object/isObject.cjs"), 1);
26
+ var import_is = require("../is.cjs");
30
27
  function setStyles(element, styles, method = "add") {
31
- if (!element || !styles || !(0, import_isObject.default)(styles)) {
28
+ if (!element || !styles || !(0, import_is.isObject)(styles)) {
32
29
  return;
33
30
  }
34
31
  Object.entries(styles).forEach(([prop, value]) => {
@@ -1,4 +1,4 @@
1
- import isObject from "../object/isObject.js";
1
+ import { isObject } from "../is.js";
2
2
  function setStyles(element, styles, method = "add") {
3
3
  if (!element || !styles || !isObject(styles)) {
4
4
  return;
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,7 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
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
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
18
 
22
19
  // packages/js-toolkit/utils/css/transform.js
@@ -26,7 +23,7 @@ __export(transform_exports, {
26
23
  default: () => transform
27
24
  });
28
25
  module.exports = __toCommonJS(transform_exports);
29
- var import_isDefined = __toESM(require("../isDefined.cjs"), 1);
26
+ var import_is = require("../is.cjs");
30
27
  var TRANSFORM_PROPS = [
31
28
  "x",
32
29
  "y",
@@ -44,44 +41,43 @@ var TRANSFORM_PROPS = [
44
41
  "skewY"
45
42
  ];
46
43
  function transform(element, props) {
47
- var _a, _b, _c;
48
44
  let value = "";
49
- if ((0, import_isDefined.default)(props.x) || (0, import_isDefined.default)(props.y) || (0, import_isDefined.default)(props.z)) {
50
- value += `translate3d(${(_a = props.x) != null ? _a : 0}px, ${(_b = props.y) != null ? _b : 0}px, ${(_c = props.z) != null ? _c : 0}px) `;
45
+ if ((0, import_is.isDefined)(props.x) || (0, import_is.isDefined)(props.y) || (0, import_is.isDefined)(props.z)) {
46
+ value += `translate3d(${props.x ?? 0}px, ${props.y ?? 0}px, ${props.z ?? 0}px) `;
51
47
  }
52
- if ((0, import_isDefined.default)(props.rotate)) {
48
+ if ((0, import_is.isDefined)(props.rotate)) {
53
49
  value += `rotate(${props.rotate}deg) `;
54
50
  } else {
55
- if ((0, import_isDefined.default)(props.rotateX)) {
51
+ if ((0, import_is.isDefined)(props.rotateX)) {
56
52
  value += `rotateX(${props.rotateX}deg) `;
57
53
  }
58
- if ((0, import_isDefined.default)(props.rotateY)) {
54
+ if ((0, import_is.isDefined)(props.rotateY)) {
59
55
  value += `rotateY(${props.rotateY}deg) `;
60
56
  }
61
- if ((0, import_isDefined.default)(props.rotateZ)) {
57
+ if ((0, import_is.isDefined)(props.rotateZ)) {
62
58
  value += `rotateZ(${props.rotateZ}deg) `;
63
59
  }
64
60
  }
65
- if ((0, import_isDefined.default)(props.scale)) {
61
+ if ((0, import_is.isDefined)(props.scale)) {
66
62
  value += `scale(${props.scale}) `;
67
63
  } else {
68
- if ((0, import_isDefined.default)(props.scaleX)) {
64
+ if ((0, import_is.isDefined)(props.scaleX)) {
69
65
  value += `scaleX(${props.scaleX}) `;
70
66
  }
71
- if ((0, import_isDefined.default)(props.scaleY)) {
67
+ if ((0, import_is.isDefined)(props.scaleY)) {
72
68
  value += `scaleY(${props.scaleY}) `;
73
69
  }
74
- if ((0, import_isDefined.default)(props.scaleZ)) {
70
+ if ((0, import_is.isDefined)(props.scaleZ)) {
75
71
  value += `scaleZ(${props.scaleZ}) `;
76
72
  }
77
73
  }
78
- if ((0, import_isDefined.default)(props.skew)) {
74
+ if ((0, import_is.isDefined)(props.skew)) {
79
75
  value += `skew(${props.skew}deg) `;
80
76
  } else {
81
- if ((0, import_isDefined.default)(props.skewX)) {
77
+ if ((0, import_is.isDefined)(props.skewX)) {
82
78
  value += `skewX(${props.skewX}deg) `;
83
79
  }
84
- if ((0, import_isDefined.default)(props.skewY)) {
80
+ if ((0, import_is.isDefined)(props.skewY)) {
85
81
  value += `skewY(${props.skewY}deg) `;
86
82
  }
87
83
  }
@@ -1,4 +1,4 @@
1
- import isDefined from "../isDefined.js";
1
+ import { isDefined } from "../is.js";
2
2
  const TRANSFORM_PROPS = [
3
3
  "x",
4
4
  "y",
@@ -16,10 +16,9 @@ const TRANSFORM_PROPS = [
16
16
  "skewY"
17
17
  ];
18
18
  function transform(element, props) {
19
- var _a, _b, _c;
20
19
  let value = "";
21
20
  if (isDefined(props.x) || isDefined(props.y) || isDefined(props.z)) {
22
- value += `translate3d(${(_a = props.x) != null ? _a : 0}px, ${(_b = props.y) != null ? _b : 0}px, ${(_c = props.z) != null ? _c : 0}px) `;
21
+ value += `translate3d(${props.x ?? 0}px, ${props.y ?? 0}px, ${props.z ?? 0}px) `;
23
22
  }
24
23
  if (isDefined(props.rotate)) {
25
24
  value += `rotate(${props.rotate}deg) `;
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __export = (target, all) => {
9
8
  for (var name in all)
10
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -19,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
19
18
  };
20
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));
21
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
- var __publicField = (obj, key, value) => {
23
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
- return value;
25
- };
26
21
 
27
22
  // packages/js-toolkit/utils/css/transition.js
28
23
  var transition_exports = {};
@@ -34,11 +29,13 @@ module.exports = __toCommonJS(transition_exports);
34
29
  var import_nextFrame = require("../nextFrame.cjs");
35
30
  var classes = __toESM(require("./classes.cjs"), 1);
36
31
  var styles = __toESM(require("./styles.cjs"), 1);
32
+ var import_is = require("../is.cjs");
33
+ var import_has = require("../has.cjs");
37
34
  var cache = /* @__PURE__ */ new WeakMap();
38
35
  var Transition = class {
36
+ isTransitioning = false;
37
+ transitionEndHandler = null;
39
38
  constructor(element) {
40
- __publicField(this, "isTransitioning", false);
41
- __publicField(this, "transitionEndHandler", null);
42
39
  cache.set(element, this);
43
40
  }
44
41
  static getInstance(element) {
@@ -50,14 +47,14 @@ var Transition = class {
50
47
  }
51
48
  };
52
49
  function setClassesOrStyles(element, classesOrStyles, method = "add") {
53
- if (typeof classesOrStyles === "string" || Array.isArray(classesOrStyles)) {
50
+ if ((0, import_is.isString)(classesOrStyles) || (0, import_is.isArray)(classesOrStyles)) {
54
51
  classes[method](element, classesOrStyles);
55
52
  } else {
56
53
  styles[method](element, classesOrStyles);
57
54
  }
58
55
  }
59
56
  function testTransition(element) {
60
- if (typeof window === "undefined") {
57
+ if (!(0, import_has.hasWindow)()) {
61
58
  return false;
62
59
  }
63
60
  const { transitionDuration } = window.getComputedStyle(element);
@@ -100,7 +97,7 @@ function end(element, classesOrStyles, mode = "remove") {
100
97
  trs.transitionEndHandler = null;
101
98
  }
102
99
  async function transition(element, name, endMode = "remove") {
103
- const classesOrStyles = typeof name === "string" ? {
100
+ const classesOrStyles = (0, import_is.isString)(name) ? {
104
101
  from: `${name}-from`,
105
102
  active: `${name}-active`,
106
103
  to: `${name}-to`
@@ -1,17 +1,13 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
1
  import { nextFrame } from "../nextFrame.js";
8
2
  import * as classes from "./classes.js";
9
3
  import * as styles from "./styles.js";
4
+ import { isArray, isString } from "../is.js";
5
+ import { hasWindow } from "../has.js";
10
6
  const cache = /* @__PURE__ */ new WeakMap();
11
7
  class Transition {
8
+ isTransitioning = false;
9
+ transitionEndHandler = null;
12
10
  constructor(element) {
13
- __publicField(this, "isTransitioning", false);
14
- __publicField(this, "transitionEndHandler", null);
15
11
  cache.set(element, this);
16
12
  }
17
13
  static getInstance(element) {
@@ -23,14 +19,14 @@ class Transition {
23
19
  }
24
20
  }
25
21
  function setClassesOrStyles(element, classesOrStyles, method = "add") {
26
- if (typeof classesOrStyles === "string" || Array.isArray(classesOrStyles)) {
22
+ if (isString(classesOrStyles) || isArray(classesOrStyles)) {
27
23
  classes[method](element, classesOrStyles);
28
24
  } else {
29
25
  styles[method](element, classesOrStyles);
30
26
  }
31
27
  }
32
28
  function testTransition(element) {
33
- if (typeof window === "undefined") {
29
+ if (!hasWindow()) {
34
30
  return false;
35
31
  }
36
32
  const { transitionDuration } = window.getComputedStyle(element);
@@ -73,7 +69,7 @@ function end(element, classesOrStyles, mode = "remove") {
73
69
  trs.transitionEndHandler = null;
74
70
  }
75
71
  async function transition(element, name, endMode = "remove") {
76
- const classesOrStyles = typeof name === "string" ? {
72
+ const classesOrStyles = isString(name) ? {
77
73
  from: `${name}-from`,
78
74
  active: `${name}-active`,
79
75
  to: `${name}-to`
@@ -29,6 +29,7 @@ __export(focusTrap_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(focusTrap_exports);
31
31
  var import_keyCodes = __toESM(require("./keyCodes.cjs"), 1);
32
+ var import_is = require("./is.cjs");
32
33
  var FOCUSABLE_ELEMENTS = [
33
34
  'a[href]:not([tabindex^="-"]):not([inert])',
34
35
  'area[href]:not([tabindex^="-"]):not([inert])',
@@ -71,7 +72,7 @@ function trap(element, event) {
71
72
  }
72
73
  }
73
74
  function untrap() {
74
- if (focusedBefore && typeof focusedBefore.focus === "function") {
75
+ if (focusedBefore && (0, import_is.isFunction)(focusedBefore.focus)) {
75
76
  focusedBefore.focus();
76
77
  focusedBefore = null;
77
78
  }
@@ -1,4 +1,5 @@
1
1
  import keyCodes from "./keyCodes.js";
2
+ import { isFunction } from "./is.js";
2
3
  const FOCUSABLE_ELEMENTS = [
3
4
  'a[href]:not([tabindex^="-"]):not([inert])',
4
5
  'area[href]:not([tabindex^="-"]):not([inert])',
@@ -41,7 +42,7 @@ function trap(element, event) {
41
42
  }
42
43
  }
43
44
  function untrap() {
44
- if (focusedBefore && typeof focusedBefore.focus === "function") {
45
+ if (focusedBefore && isFunction(focusedBefore.focus)) {
45
46
  focusedBefore.focus();
46
47
  focusedBefore = null;
47
48
  }
@@ -16,13 +16,13 @@ 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/isFunction.js
20
- var isFunction_exports = {};
21
- __export(isFunction_exports, {
22
- default: () => isFunction
19
+ // packages/js-toolkit/utils/has.js
20
+ var has_exports = {};
21
+ __export(has_exports, {
22
+ hasWindow: () => hasWindow
23
23
  });
24
- module.exports = __toCommonJS(isFunction_exports);
25
- function isFunction(fn) {
26
- return typeof fn === "function";
24
+ module.exports = __toCommonJS(has_exports);
25
+ function hasWindow() {
26
+ return typeof window !== "undefined";
27
27
  }
28
28
  if (module.exports.default) module.exports = module.exports.default;
package/utils/has.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Test if the current context as a global `window` object available.
3
+ *
4
+ * @returns {boolean}
5
+ */
6
+ export function hasWindow(): boolean;
package/utils/has.js ADDED
@@ -0,0 +1,6 @@
1
+ function hasWindow() {
2
+ return typeof window !== "undefined";
3
+ }
4
+ export {
5
+ hasWindow
6
+ };
package/utils/history.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,7 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
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
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
18
 
22
19
  // packages/js-toolkit/utils/history.js
@@ -27,7 +24,8 @@ __export(history_exports, {
27
24
  replace: () => replace
28
25
  });
29
26
  module.exports = __toCommonJS(history_exports);
30
- var import_isObject = __toESM(require("./object/isObject.cjs"), 1);
27
+ var import_is = require("./is.cjs");
28
+ var import_has = require("./has.cjs");
31
29
  function updateUrlSearchParam(params, name, value) {
32
30
  if (value === "" || value === null || value === void 0) {
33
31
  if (params.has(name)) {
@@ -35,14 +33,14 @@ function updateUrlSearchParam(params, name, value) {
35
33
  }
36
34
  return params;
37
35
  }
38
- if (Array.isArray(value)) {
36
+ if ((0, import_is.isArray)(value)) {
39
37
  value.forEach((val, index) => {
40
38
  const arrayName = `${name}[${index}]`;
41
39
  updateUrlSearchParam(params, arrayName, val);
42
40
  });
43
41
  return params;
44
42
  }
45
- if ((0, import_isObject.default)(value)) {
43
+ if ((0, import_is.isObject)(value)) {
46
44
  Object.entries(value).forEach(([key, val]) => {
47
45
  const objectName = `${name}[${key}]`;
48
46
  updateUrlSearchParam(params, objectName, val);
@@ -52,7 +50,7 @@ function updateUrlSearchParam(params, name, value) {
52
50
  params.set(name, value);
53
51
  return params;
54
52
  }
55
- function objectToURLSearchParams(obj, defaultSearch = typeof window === "undefined" ? "" : window.location.search) {
53
+ function objectToURLSearchParams(obj, defaultSearch = (0, import_has.hasWindow)() ? window.location.search : "") {
56
54
  return Object.entries(obj).reduce((urlSearchParams, [name, value]) => updateUrlSearchParam(urlSearchParams, name, value), new URLSearchParams(defaultSearch));
57
55
  }
58
56
  function updateHistory(mode, options, data = {}, title = "") {
package/utils/history.js CHANGED
@@ -1,4 +1,5 @@
1
- import isObject from "./object/isObject.js";
1
+ import { isArray, isObject } from "./is.js";
2
+ import { hasWindow } from "./has.js";
2
3
  function updateUrlSearchParam(params, name, value) {
3
4
  if (value === "" || value === null || value === void 0) {
4
5
  if (params.has(name)) {
@@ -6,7 +7,7 @@ function updateUrlSearchParam(params, name, value) {
6
7
  }
7
8
  return params;
8
9
  }
9
- if (Array.isArray(value)) {
10
+ if (isArray(value)) {
10
11
  value.forEach((val, index) => {
11
12
  const arrayName = `${name}[${index}]`;
12
13
  updateUrlSearchParam(params, arrayName, val);
@@ -23,7 +24,7 @@ function updateUrlSearchParam(params, name, value) {
23
24
  params.set(name, value);
24
25
  return params;
25
26
  }
26
- function objectToURLSearchParams(obj, defaultSearch = typeof window === "undefined" ? "" : window.location.search) {
27
+ function objectToURLSearchParams(obj, defaultSearch = hasWindow() ? window.location.search : "") {
27
28
  return Object.entries(obj).reduce((urlSearchParams, [name, value]) => updateUrlSearchParam(urlSearchParams, name, value), new URLSearchParams(defaultSearch));
28
29
  }
29
30
  function updateHistory(mode, options, data = {}, title = "") {
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,8 +47,8 @@ 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);
@@ -57,4 +56,5 @@ __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);
59
58
  __reExport(utils_exports, require("./noop.cjs"), module.exports);
59
+ var import_tween = require("./tween.cjs");
60
60
  if (module.exports.default) module.exports = module.exports.default;
package/utils/index.d.ts CHANGED
@@ -7,12 +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
17
  export * from "./noop.js";
18
+ export { tween } from "./tween.js";
18
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,
@@ -20,13 +20,12 @@ export * from "./math/index.js";
20
20
  export * from "./string/index.js";
21
21
  export * from "./scheduler.js";
22
22
  export * from "./noop.js";
23
+ import { tween } from "./tween.js";
23
24
  export {
24
25
  default2 as debounce,
25
26
  default3 as focusTrap,
26
27
  push as historyPush,
27
28
  replace as historyReplace,
28
- default10 as isDefined,
29
- default11 as isFunction,
30
29
  default4 as keyCodes,
31
30
  default5 as memoize,
32
31
  nextFrame,
@@ -34,5 +33,6 @@ export {
34
33
  default6 as nextTick,
35
34
  objectToURLSearchParams,
36
35
  default9 as scrollTo,
37
- default8 as throttle
36
+ default8 as throttle,
37
+ tween
38
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/isDefined.js
20
- var isDefined_exports = {};
21
- __export(isDefined_exports, {
22
- default: () => isDefined
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(isDefined_exports);
25
- function isDefined(value) {
26
- return typeof value !== "undefined";
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;