@studiometa/js-toolkit 2.3.0 → 2.4.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 (60) hide show
  1. package/Base/index.cjs +41 -40
  2. package/Base/index.js +64 -57
  3. package/Base/managers/AbstractManager.cjs +10 -5
  4. package/Base/managers/AbstractManager.js +11 -5
  5. package/Base/managers/ChildrenManager.cjs +11 -2
  6. package/Base/managers/ChildrenManager.js +12 -2
  7. package/Base/managers/EventsManager.cjs +46 -41
  8. package/Base/managers/EventsManager.js +47 -41
  9. package/Base/managers/OptionsManager.cjs +14 -7
  10. package/Base/managers/OptionsManager.js +15 -7
  11. package/Base/managers/RefsManager.cjs +2 -1
  12. package/Base/managers/RefsManager.js +2 -1
  13. package/Base/managers/ServicesManager.cjs +9 -1
  14. package/Base/managers/ServicesManager.js +10 -1
  15. package/README.md +3 -3
  16. package/decorators/withBreakpointObserver.cjs +16 -11
  17. package/decorators/withBreakpointObserver.js +17 -11
  18. package/decorators/withDrag.cjs +11 -6
  19. package/decorators/withDrag.js +12 -6
  20. package/decorators/withExtraConfig.cjs +8 -3
  21. package/decorators/withExtraConfig.js +9 -3
  22. package/decorators/withFreezedOptions.cjs +9 -1
  23. package/decorators/withFreezedOptions.js +10 -1
  24. package/decorators/withIntersectionObserver.cjs +16 -11
  25. package/decorators/withIntersectionObserver.js +17 -11
  26. package/decorators/withMountWhenInView.cjs +17 -12
  27. package/decorators/withMountWhenInView.js +18 -12
  28. package/decorators/withScrolledInView.cjs +35 -30
  29. package/decorators/withScrolledInView.js +36 -30
  30. package/decorators/withVue2.cjs +15 -10
  31. package/decorators/withVue2.js +16 -10
  32. package/helpers/getDirectChildren.cjs +46 -0
  33. package/helpers/getDirectChildren.d.ts +24 -0
  34. package/helpers/getDirectChildren.js +24 -0
  35. package/helpers/getInstanceFromElement.cjs +2 -1
  36. package/helpers/getInstanceFromElement.js +2 -1
  37. package/helpers/importOnInteraction.cjs +1 -1
  38. package/helpers/importOnInteraction.js +1 -1
  39. package/helpers/importWhenIdle.cjs +3 -2
  40. package/helpers/importWhenIdle.js +3 -2
  41. package/helpers/importWhenVisible.cjs +1 -1
  42. package/helpers/importWhenVisible.js +1 -1
  43. package/helpers/index.cjs +2 -0
  44. package/helpers/index.d.ts +1 -0
  45. package/helpers/index.js +1 -0
  46. package/package.json +1 -1
  47. package/services/key.cjs +1 -1
  48. package/services/key.js +1 -1
  49. package/services/pointer.cjs +3 -2
  50. package/services/pointer.js +3 -2
  51. package/utils/css/animate.cjs +12 -8
  52. package/utils/css/animate.js +12 -8
  53. package/utils/css/matrix.cjs +2 -1
  54. package/utils/css/matrix.js +2 -1
  55. package/utils/css/transform.cjs +2 -1
  56. package/utils/css/transform.js +2 -1
  57. package/utils/css/transition.cjs +7 -2
  58. package/utils/css/transition.js +8 -2
  59. package/utils/tween.cjs +2 -1
  60. package/utils/tween.js +2 -1
@@ -1,17 +1,16 @@
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
+ };
1
7
  function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] }) {
2
- return class extends BaseClass {
3
- static config = {
4
- ...BaseClass.config,
5
- name: `${BaseClass.config.name}WithMountWhenInView`,
6
- options: {
7
- ...BaseClass.config?.options || {},
8
- intersectionObserver: Object
9
- }
10
- };
11
- __isVisible = false;
12
- __observer;
8
+ var _a, _b;
9
+ return _b = class extends BaseClass {
13
10
  constructor(element) {
14
11
  super(element);
12
+ __publicField(this, "__isVisible", false);
13
+ __publicField(this, "__observer");
15
14
  this.__observer = new IntersectionObserver((entries) => {
16
15
  const isVisible = entries.reduce((acc, entry) => acc || entry.isIntersecting, false);
17
16
  if (this.__isVisible !== isVisible) {
@@ -34,7 +33,14 @@ function withMountWhenInView(BaseClass, defaultOptions = { threshold: [0, 1] })
34
33
  }
35
34
  return this;
36
35
  }
37
- };
36
+ }, __publicField(_b, "config", {
37
+ ...BaseClass.config,
38
+ name: `${BaseClass.config.name}WithMountWhenInView`,
39
+ options: {
40
+ ...((_a = BaseClass.config) == null ? void 0 : _a.options) || {},
41
+ intersectionObserver: Object
42
+ }
43
+ }), _b;
38
44
  }
39
45
  export {
40
46
  withMountWhenInView as default
@@ -4,6 +4,7 @@ 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;
7
8
  var __export = (target, all) => {
8
9
  for (var name in all)
9
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -18,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
18
19
  };
19
20
  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
21
  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
+ };
21
26
 
22
27
  // packages/js-toolkit/decorators/withScrolledInView.js
23
28
  var withScrolledInView_exports = {};
@@ -29,37 +34,34 @@ var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1
29
34
  var import_utils = require("../utils/index.cjs");
30
35
  var scheduler = (0, import_utils.useScheduler)(["update", "render"]);
31
36
  function withScrolledInView(BaseClass, options = {}) {
32
- return class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
33
- static config = {
34
- name: `${BaseClass.config.name}WithMountWhenInView`,
35
- emits: ["scrolledInView"]
36
- };
37
- __props = {
38
- start: {
39
- x: 0,
40
- y: 0
41
- },
42
- end: {
43
- x: 0,
44
- y: 0
45
- },
46
- current: {
47
- x: 0,
48
- y: 0
49
- },
50
- progress: {
51
- x: 0,
52
- y: 0
53
- },
54
- dampedProgress: {
55
- x: 0,
56
- y: 0
57
- }
58
- };
59
- dampFactor = 0.1;
60
- dampPrecision = 1e-3;
37
+ var _a;
38
+ return _a = class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
61
39
  constructor(element) {
62
40
  super(element);
41
+ __publicField(this, "__props", {
42
+ start: {
43
+ x: 0,
44
+ y: 0
45
+ },
46
+ end: {
47
+ x: 0,
48
+ y: 0
49
+ },
50
+ current: {
51
+ x: 0,
52
+ y: 0
53
+ },
54
+ progress: {
55
+ x: 0,
56
+ y: 0
57
+ },
58
+ dampedProgress: {
59
+ x: 0,
60
+ y: 0
61
+ }
62
+ });
63
+ __publicField(this, "dampFactor", 0.1);
64
+ __publicField(this, "dampPrecision", 1e-3);
63
65
  const delegate = {
64
66
  handleEvent(event) {
65
67
  delegate[event.type](event.detail[0]);
@@ -147,6 +149,9 @@ function withScrolledInView(BaseClass, options = {}) {
147
149
  this.__props.dampedProgress.x = (0, import_utils.damp)(xProgress, this.__props.dampedProgress.x);
148
150
  this.__props.dampedProgress.y = (0, import_utils.damp)(yProgress, this.__props.dampedProgress.y);
149
151
  }
150
- };
152
+ }, __publicField(_a, "config", {
153
+ name: `${BaseClass.config.name}WithMountWhenInView`,
154
+ emits: ["scrolledInView"]
155
+ }), _a;
151
156
  }
152
157
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,38 +1,41 @@
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
+ };
1
7
  import withMountWhenInView from "./withMountWhenInView.js";
2
8
  import { damp, clamp, clamp01, getOffsetSizes, isFunction, useScheduler } from "../utils/index.js";
3
9
  const scheduler = useScheduler(["update", "render"]);
4
10
  function withScrolledInView(BaseClass, options = {}) {
5
- return class extends withMountWhenInView(BaseClass, options) {
6
- static config = {
7
- name: `${BaseClass.config.name}WithMountWhenInView`,
8
- emits: ["scrolledInView"]
9
- };
10
- __props = {
11
- start: {
12
- x: 0,
13
- y: 0
14
- },
15
- end: {
16
- x: 0,
17
- y: 0
18
- },
19
- current: {
20
- x: 0,
21
- y: 0
22
- },
23
- progress: {
24
- x: 0,
25
- y: 0
26
- },
27
- dampedProgress: {
28
- x: 0,
29
- y: 0
30
- }
31
- };
32
- dampFactor = 0.1;
33
- dampPrecision = 1e-3;
11
+ var _a;
12
+ return _a = class extends withMountWhenInView(BaseClass, options) {
34
13
  constructor(element) {
35
14
  super(element);
15
+ __publicField(this, "__props", {
16
+ start: {
17
+ x: 0,
18
+ y: 0
19
+ },
20
+ end: {
21
+ x: 0,
22
+ y: 0
23
+ },
24
+ current: {
25
+ x: 0,
26
+ y: 0
27
+ },
28
+ progress: {
29
+ x: 0,
30
+ y: 0
31
+ },
32
+ dampedProgress: {
33
+ x: 0,
34
+ y: 0
35
+ }
36
+ });
37
+ __publicField(this, "dampFactor", 0.1);
38
+ __publicField(this, "dampPrecision", 1e-3);
36
39
  const delegate = {
37
40
  handleEvent(event) {
38
41
  delegate[event.type](event.detail[0]);
@@ -120,7 +123,10 @@ function withScrolledInView(BaseClass, options = {}) {
120
123
  this.__props.dampedProgress.x = damp(xProgress, this.__props.dampedProgress.x);
121
124
  this.__props.dampedProgress.y = damp(yProgress, this.__props.dampedProgress.y);
122
125
  }
123
- };
126
+ }, __publicField(_a, "config", {
127
+ name: `${BaseClass.config.name}WithMountWhenInView`,
128
+ emits: ["scrolledInView"]
129
+ }), _a;
124
130
  }
125
131
  export {
126
132
  withScrolledInView as default
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
6
  var __export = (target, all) => {
6
7
  for (var name in all)
7
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,6 +16,10 @@ var __copyProps = (to, from, except, desc) => {
15
16
  return to;
16
17
  };
17
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __publicField = (obj, key, value) => {
20
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ return value;
22
+ };
18
23
 
19
24
  // packages/js-toolkit/decorators/withVue2.js
20
25
  var withVue2_exports = {};
@@ -24,17 +29,13 @@ __export(withVue2_exports, {
24
29
  module.exports = __toCommonJS(withVue2_exports);
25
30
  var import_utils = require("../utils/index.cjs");
26
31
  var withVue2_default = (BaseClass, Vue) => {
27
- return class WithVue2 extends BaseClass {
28
- static config = {
29
- ...BaseClass.config,
30
- name: `${BaseClass.config.name}WithVue`,
31
- refs: [...BaseClass.config?.refs ?? [], "vue"]
32
- };
33
- $vue;
34
- static vueConfig;
32
+ var _a, _b, _c;
33
+ return _c = class extends BaseClass {
35
34
  constructor(element) {
35
+ var _a2;
36
36
  super(element);
37
- const vueConfig = this.vueConfig ?? this.constructor.vueConfig;
37
+ __publicField(this, "$vue");
38
+ const vueConfig = (_a2 = this.vueConfig) != null ? _a2 : this.constructor.vueConfig;
38
39
  if (!vueConfig) {
39
40
  if (import_utils.isDev) {
40
41
  throw new Error("[withVue] You must define a `vueConfig` object.");
@@ -58,6 +59,10 @@ var withVue2_default = (BaseClass, Vue) => {
58
59
  this.$vue.$destroy();
59
60
  });
60
61
  }
61
- };
62
+ }, __publicField(_c, "config", {
63
+ ...BaseClass.config,
64
+ name: `${BaseClass.config.name}WithVue`,
65
+ refs: [...(_b = (_a = BaseClass.config) == null ? void 0 : _a.refs) != null ? _b : [], "vue"]
66
+ }), __publicField(_c, "vueConfig"), _c;
62
67
  };
63
68
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,16 +1,18 @@
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
+ };
1
7
  import { isDev, isFunction } from "../utils/index.js";
2
8
  var withVue2_default = (BaseClass, Vue) => {
3
- return class WithVue2 extends BaseClass {
4
- static config = {
5
- ...BaseClass.config,
6
- name: `${BaseClass.config.name}WithVue`,
7
- refs: [...BaseClass.config?.refs ?? [], "vue"]
8
- };
9
- $vue;
10
- static vueConfig;
9
+ var _a, _b, _c;
10
+ return _c = class extends BaseClass {
11
11
  constructor(element) {
12
+ var _a2;
12
13
  super(element);
13
- const vueConfig = this.vueConfig ?? this.constructor.vueConfig;
14
+ __publicField(this, "$vue");
15
+ const vueConfig = (_a2 = this.vueConfig) != null ? _a2 : this.constructor.vueConfig;
14
16
  if (!vueConfig) {
15
17
  if (isDev) {
16
18
  throw new Error("[withVue] You must define a `vueConfig` object.");
@@ -34,7 +36,11 @@ var withVue2_default = (BaseClass, Vue) => {
34
36
  this.$vue.$destroy();
35
37
  });
36
38
  }
37
- };
39
+ }, __publicField(_c, "config", {
40
+ ...BaseClass.config,
41
+ name: `${BaseClass.config.name}WithVue`,
42
+ refs: [...(_b = (_a = BaseClass.config) == null ? void 0 : _a.refs) != null ? _b : [], "vue"]
43
+ }), __publicField(_c, "vueConfig"), _c;
38
44
  };
39
45
  export {
40
46
  withVue2_default as default
@@ -0,0 +1,46 @@
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/helpers/getDirectChildren.js
20
+ var getDirectChildren_exports = {};
21
+ __export(getDirectChildren_exports, {
22
+ getDirectChildren: () => getDirectChildren,
23
+ isDirectChild: () => isDirectChild
24
+ });
25
+ module.exports = __toCommonJS(getDirectChildren_exports);
26
+ var import_utils = require("../utils/index.cjs");
27
+ function getDirectChildren(parentInstance, parentName, childrenName) {
28
+ const children = parentInstance.$children[childrenName];
29
+ const nestedParents = parentInstance.$children[parentName];
30
+ if (!(0, import_utils.isArray)(children)) {
31
+ return [];
32
+ }
33
+ if (!(0, import_utils.isArray)(nestedParents) || nestedParents.length <= 0) {
34
+ return children;
35
+ }
36
+ return children.filter((child) => {
37
+ return nestedParents.every((nestedParent) => {
38
+ const nestedChildren = nestedParent.$children[childrenName];
39
+ return (0, import_utils.isArray)(nestedChildren) ? !nestedChildren.includes(child) : true;
40
+ });
41
+ });
42
+ }
43
+ function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
44
+ return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
45
+ }
46
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @typedef {import('../Base/index.js').default} Base
3
+ */
4
+ /**
5
+ * Get direct children from a parent when working with nested components.
6
+ *
7
+ * @template {Base} T
8
+ * @param {Base} parentInstance
9
+ * @param {string} parentName
10
+ * @param {string} childrenName
11
+ * @returns {Array<T>}
12
+ */
13
+ export function getDirectChildren<T extends import("../Base/index.js").default>(parentInstance: Base, parentName: string, childrenName: string): T[];
14
+ /**
15
+ * Test if a component instance is a direct child from the given component.
16
+ *
17
+ * @param {Base} parentInstance
18
+ * @param {string} parentName
19
+ * @param {string} childrenName
20
+ * @param {Base} childInstance
21
+ * @returns {boolean}
22
+ */
23
+ export function isDirectChild(parentInstance: Base, parentName: string, childrenName: string, childInstance: Base): boolean;
24
+ export type Base = import('../Base/index.js').default;
@@ -0,0 +1,24 @@
1
+ import { isArray } from "../utils/index.js";
2
+ function getDirectChildren(parentInstance, parentName, childrenName) {
3
+ const children = parentInstance.$children[childrenName];
4
+ const nestedParents = parentInstance.$children[parentName];
5
+ if (!isArray(children)) {
6
+ return [];
7
+ }
8
+ if (!isArray(nestedParents) || nestedParents.length <= 0) {
9
+ return children;
10
+ }
11
+ return children.filter((child) => {
12
+ return nestedParents.every((nestedParent) => {
13
+ const nestedChildren = nestedParent.$children[childrenName];
14
+ return isArray(nestedChildren) ? !nestedChildren.includes(child) : true;
15
+ });
16
+ });
17
+ }
18
+ function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
19
+ return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
20
+ }
21
+ export {
22
+ getDirectChildren,
23
+ isDirectChild
24
+ };
@@ -23,9 +23,10 @@ __export(getInstanceFromElement_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(getInstanceFromElement_exports);
25
25
  function getInstanceFromElement(element, Constructor) {
26
+ var _a;
26
27
  if (!element.__base__) {
27
28
  return null;
28
29
  }
29
- return element.__base__.get(Constructor) ?? null;
30
+ return (_a = element.__base__.get(Constructor)) != null ? _a : null;
30
31
  }
31
32
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,8 +1,9 @@
1
1
  function getInstanceFromElement(element, Constructor) {
2
+ var _a;
2
3
  if (!element.__base__) {
3
4
  return null;
4
5
  }
5
- return element.__base__.get(Constructor) ?? null;
6
+ return (_a = element.__base__.get(Constructor)) != null ? _a : null;
6
7
  }
7
8
  export {
8
9
  getInstanceFromElement as default
@@ -34,7 +34,7 @@ function importOnInteraction(fn, nameOrSelectorOrElement, events, parent) {
34
34
  });
35
35
  };
36
36
  return new Promise((resolve) => {
37
- const elements = (0, import_utils.getTargetElements)(nameOrSelectorOrElement, parent?.$el);
37
+ const elements = (0, import_utils.getTargetElements)(nameOrSelectorOrElement, parent == null ? void 0 : parent.$el);
38
38
  const eventListenerOptions = {
39
39
  capture: true,
40
40
  passive: true,
@@ -10,7 +10,7 @@ function importOnInteraction(fn, nameOrSelectorOrElement, events, parent) {
10
10
  });
11
11
  };
12
12
  return new Promise((resolve) => {
13
- const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);
13
+ const elements = getTargetElements(nameOrSelectorOrElement, parent == null ? void 0 : parent.$el);
14
14
  const eventListenerOptions = {
15
15
  capture: true,
16
16
  passive: true,
@@ -31,7 +31,8 @@ function importWhenIdle(fn, options) {
31
31
  });
32
32
  };
33
33
  return new Promise((resolve) => {
34
- const timeout = options?.timeout ?? 1;
34
+ var _a;
35
+ const timeout = (_a = options == null ? void 0 : options.timeout) != null ? _a : 1;
35
36
  if (!("requestIdleCallback" in window)) {
36
37
  setTimeout(() => {
37
38
  resolver(resolve);
@@ -41,7 +42,7 @@ function importWhenIdle(fn, options) {
41
42
  setTimeout(() => {
42
43
  resolver(resolve);
43
44
  }, 0);
44
- }, { timeout: options?.timeout });
45
+ }, { timeout: options == null ? void 0 : options.timeout });
45
46
  }
46
47
  });
47
48
  }
@@ -7,7 +7,8 @@ function importWhenIdle(fn, options) {
7
7
  });
8
8
  };
9
9
  return new Promise((resolve) => {
10
- const timeout = options?.timeout ?? 1;
10
+ var _a;
11
+ const timeout = (_a = options == null ? void 0 : options.timeout) != null ? _a : 1;
11
12
  if (!("requestIdleCallback" in window)) {
12
13
  setTimeout(() => {
13
14
  resolver(resolve);
@@ -17,7 +18,7 @@ function importWhenIdle(fn, options) {
17
18
  setTimeout(() => {
18
19
  resolver(resolve);
19
20
  }, 0);
20
- }, { timeout: options?.timeout });
21
+ }, { timeout: options == null ? void 0 : options.timeout });
21
22
  }
22
23
  });
23
24
  }
@@ -44,7 +44,7 @@ function importWhenVisible(fn, nameOrSelectorOrElement, parent, observerOptions
44
44
  }, 0);
45
45
  }
46
46
  }, observerOptions);
47
- const elements = (0, import_utils.getTargetElements)(nameOrSelectorOrElement, parent?.$el);
47
+ const elements = (0, import_utils.getTargetElements)(nameOrSelectorOrElement, parent == null ? void 0 : parent.$el);
48
48
  elements.forEach((element) => observer.observe(element));
49
49
  });
50
50
  }
@@ -20,7 +20,7 @@ function importWhenVisible(fn, nameOrSelectorOrElement, parent, observerOptions
20
20
  }, 0);
21
21
  }
22
22
  }, observerOptions);
23
- const elements = getTargetElements(nameOrSelectorOrElement, parent?.$el);
23
+ const elements = getTargetElements(nameOrSelectorOrElement, parent == null ? void 0 : parent.$el);
24
24
  elements.forEach((element) => observer.observe(element));
25
25
  });
26
26
  }
package/helpers/index.cjs CHANGED
@@ -16,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
20
  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
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
22
 
@@ -30,6 +31,7 @@ __export(helpers_exports, {
30
31
  });
31
32
  module.exports = __toCommonJS(helpers_exports);
32
33
  var import_createApp = __toESM(require("./createApp.cjs"), 1);
34
+ __reExport(helpers_exports, require("./getDirectChildren.cjs"), module.exports);
33
35
  var import_getInstanceFromElement = __toESM(require("./getInstanceFromElement.cjs"), 1);
34
36
  var import_importOnInteraction = __toESM(require("./importOnInteraction.cjs"), 1);
35
37
  var import_importWhenIdle = __toESM(require("./importWhenIdle.cjs"), 1);
@@ -1,4 +1,5 @@
1
1
  export { default as createApp } from "./createApp.js";
2
+ export * from "./getDirectChildren.js";
2
3
  export { default as getInstanceFromElement } from "./getInstanceFromElement.js";
3
4
  export { default as importOnInteraction } from "./importOnInteraction.js";
4
5
  export { default as importWhenIdle } from "./importWhenIdle.js";
package/helpers/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { default as default2 } from "./createApp.js";
2
+ export * from "./getDirectChildren.js";
2
3
  import { default as default3 } from "./getInstanceFromElement.js";
3
4
  import { default as default4 } from "./importOnInteraction.js";
4
5
  import { default as default5 } from "./importWhenIdle.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiometa/js-toolkit",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "A set of useful little bits of JavaScript to boost your project! 🚀",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/services/key.cjs CHANGED
@@ -40,7 +40,7 @@ function createKeyService() {
40
40
  if (!previousEvent) {
41
41
  props.triggered = 0;
42
42
  }
43
- if (props.event.type === "keydown" && previousEvent?.type === "keydown") {
43
+ if (props.event.type === "keydown" && (previousEvent == null ? void 0 : previousEvent.type) === "keydown") {
44
44
  props.triggered += 1;
45
45
  } else {
46
46
  props.triggered = 1;
package/services/key.js CHANGED
@@ -13,7 +13,7 @@ function createKeyService() {
13
13
  if (!previousEvent) {
14
14
  props.triggered = 0;
15
15
  }
16
- if (props.event.type === "keydown" && previousEvent?.type === "keydown") {
16
+ if (props.event.type === "keydown" && (previousEvent == null ? void 0 : previousEvent.type) === "keydown") {
17
17
  props.triggered += 1;
18
18
  } else {
19
19
  props.triggered = 1;
@@ -29,14 +29,15 @@ function isTouchEvent(event) {
29
29
  var events = ["mousemove", "touchmove", "mousedown", "touchstart", "mouseup", "touchend"];
30
30
  function createPointerService() {
31
31
  function updateProps(event) {
32
+ var _a, _b;
32
33
  props.event = event;
33
34
  const yLast = props.y;
34
35
  const xLast = props.x;
35
- const y = isTouchEvent(event) ? event.touches[0]?.clientY : event.clientY;
36
+ const y = isTouchEvent(event) ? (_a = event.touches[0]) == null ? void 0 : _a.clientY : event.clientY;
36
37
  if (y !== props.y) {
37
38
  props.y = y;
38
39
  }
39
- const x = isTouchEvent(event) ? event.touches[0]?.clientX : event.clientX;
40
+ const x = isTouchEvent(event) ? (_b = event.touches[0]) == null ? void 0 : _b.clientX : event.clientX;
40
41
  if (x !== props.x) {
41
42
  props.x = x;
42
43
  }
@@ -5,14 +5,15 @@ function isTouchEvent(event) {
5
5
  const events = ["mousemove", "touchmove", "mousedown", "touchstart", "mouseup", "touchend"];
6
6
  function createPointerService() {
7
7
  function updateProps(event) {
8
+ var _a, _b;
8
9
  props.event = event;
9
10
  const yLast = props.y;
10
11
  const xLast = props.x;
11
- const y = isTouchEvent(event) ? event.touches[0]?.clientY : event.clientY;
12
+ const y = isTouchEvent(event) ? (_a = event.touches[0]) == null ? void 0 : _a.clientY : event.clientY;
12
13
  if (y !== props.y) {
13
14
  props.y = y;
14
15
  }
15
- const x = isTouchEvent(event) ? event.touches[0]?.clientX : event.clientX;
16
+ const x = isTouchEvent(event) ? (_b = event.touches[0]) == null ? void 0 : _b.clientX : event.clientX;
16
17
  if (x !== props.x) {
17
18
  props.x = x;
18
19
  }
@@ -48,10 +48,10 @@ function getAnimationStepValue(val, getSizeRef) {
48
48
  }
49
49
  return CSSUnitConverter[val[1]](val[0], getSizeRef);
50
50
  }
51
- var generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) => (0, import_math.lerp)(getAnimationStepValue(fromValue ?? 0, () => element[sizeRef]), getAnimationStepValue(toValue ?? 0, () => element[sizeRef]), progress);
51
+ var generateTranslateRenderStrategy = (sizeRef) => (element, fromValue, toValue, progress) => (0, import_math.lerp)(getAnimationStepValue(fromValue != null ? fromValue : 0, () => element[sizeRef]), getAnimationStepValue(toValue != null ? toValue : 0, () => element[sizeRef]), progress);
52
52
  var widthBasedTranslateRenderStrategy = generateTranslateRenderStrategy("offsetWidth");
53
53
  var heightBasedTranslateRenderStrategy = generateTranslateRenderStrategy("offsetHeight");
54
- var generateLerpRenderStrategy = (defaultValue) => (element, fromValue, toValue, progress) => (0, import_math.lerp)(fromValue ?? defaultValue, toValue ?? defaultValue, progress);
54
+ var generateLerpRenderStrategy = (defaultValue) => (element, fromValue, toValue, progress) => (0, import_math.lerp)(fromValue != null ? fromValue : defaultValue, toValue != null ? toValue : defaultValue, progress);
55
55
  var scaleRenderStrategy = generateLerpRenderStrategy(1);
56
56
  var degreesRenderStrategy = generateLerpRenderStrategy(0);
57
57
  var transformRenderStrategies = {
@@ -73,9 +73,10 @@ var transformRenderStrategies = {
73
73
  function render(element, from, to, progress) {
74
74
  const stepProgress = to.easing((0, import_math.map)(progress, from.offset, to.offset, 0, 1));
75
75
  import_scheduler.domScheduler.read(function renderRead() {
76
+ var _a, _b;
76
77
  let opacity = false;
77
78
  if ((0, import_is.isDefined)(from.opacity) || (0, import_is.isDefined)(to.opacity)) {
78
- opacity = (0, import_math.map)(stepProgress, 0, 1, from.opacity ?? 1, to.opacity ?? 1);
79
+ opacity = (0, import_math.map)(stepProgress, 0, 1, (_a = from.opacity) != null ? _a : 1, (_b = to.opacity) != null ? _b : 1);
79
80
  } else if (element.style.opacity) {
80
81
  opacity = "";
81
82
  }
@@ -101,11 +102,14 @@ function render(element, from, to, progress) {
101
102
  }
102
103
  function animate(element, keyframes, options = {}) {
103
104
  const keyframesCount = keyframes.length - 1;
104
- const normalizedKeyframes = keyframes.map((keyframe, index) => ({
105
- ...keyframe,
106
- offset: keyframe.offset ?? index / keyframesCount,
107
- easing: (0, import_tween.normalizeEase)(keyframe.easing)
108
- }));
105
+ const normalizedKeyframes = keyframes.map((keyframe, index) => {
106
+ var _a;
107
+ return {
108
+ ...keyframe,
109
+ offset: (_a = keyframe.offset) != null ? _a : index / keyframesCount,
110
+ easing: (0, import_tween.normalizeEase)(keyframe.easing)
111
+ };
112
+ });
109
113
  if (!running.has(element)) {
110
114
  running.set(element, /* @__PURE__ */ new Map());
111
115
  }