@studiometa/js-toolkit 2.0.1 → 2.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/Base/index.cjs +55 -18
  2. package/Base/index.d.ts +23 -1
  3. package/Base/index.js +55 -18
  4. package/Base/managers/AbstractManager.cjs +56 -0
  5. package/Base/managers/AbstractManager.d.ts +44 -0
  6. package/Base/managers/AbstractManager.js +35 -0
  7. package/Base/managers/ChildrenManager.cjs +79 -100
  8. package/Base/managers/ChildrenManager.d.ts +7 -82
  9. package/Base/managers/ChildrenManager.js +76 -100
  10. package/Base/managers/EventsManager.cjs +75 -99
  11. package/Base/managers/EventsManager.d.ts +31 -100
  12. package/Base/managers/EventsManager.js +75 -99
  13. package/Base/managers/OptionsManager.cjs +65 -78
  14. package/Base/managers/OptionsManager.d.ts +37 -79
  15. package/Base/managers/OptionsManager.js +66 -79
  16. package/Base/managers/RefsManager.cjs +44 -68
  17. package/Base/managers/RefsManager.d.ts +10 -64
  18. package/Base/managers/RefsManager.js +41 -69
  19. package/Base/managers/ResponsiveOptionsManager.cjs +62 -0
  20. package/Base/managers/ResponsiveOptionsManager.d.ts +26 -0
  21. package/Base/managers/ResponsiveOptionsManager.js +37 -0
  22. package/Base/managers/ServicesManager.cjs +5 -11
  23. package/Base/managers/ServicesManager.d.ts +2 -11
  24. package/Base/managers/ServicesManager.js +5 -11
  25. package/decorators/index.cjs +2 -0
  26. package/decorators/index.d.ts +1 -0
  27. package/decorators/index.js +6 -4
  28. package/decorators/withResponsiveOptions.cjs +39 -0
  29. package/decorators/withResponsiveOptions.d.ts +8 -0
  30. package/decorators/withResponsiveOptions.js +14 -0
  31. package/decorators/withScrolledInView.cjs +66 -23
  32. package/decorators/withScrolledInView.d.ts +4 -2
  33. package/decorators/withScrolledInView.js +67 -24
  34. package/package.json +2 -1
  35. package/services/Service.cjs +2 -2
  36. package/services/Service.d.ts +9 -1
  37. package/services/Service.js +2 -2
  38. package/services/raf.cjs +16 -0
  39. package/services/raf.js +16 -0
  40. package/utils/css/animate.cjs +207 -0
  41. package/utils/css/animate.d.ts +57 -0
  42. package/utils/css/animate.js +182 -0
  43. package/utils/css/getOffsetSizes.cjs +47 -0
  44. package/utils/css/getOffsetSizes.d.ts +15 -0
  45. package/utils/css/getOffsetSizes.js +25 -0
  46. package/utils/css/index.cjs +6 -0
  47. package/utils/css/index.d.ts +3 -0
  48. package/utils/css/index.js +9 -4
  49. package/utils/css/transform.cjs +91 -0
  50. package/utils/css/transform.d.ts +43 -0
  51. package/utils/css/transform.js +66 -0
  52. package/utils/index.cjs +5 -0
  53. package/utils/index.d.ts +3 -0
  54. package/utils/index.js +5 -0
  55. package/utils/isDefined.cjs +28 -0
  56. package/utils/isDefined.d.ts +7 -0
  57. package/utils/isDefined.js +6 -0
  58. package/utils/isFunction.cjs +28 -0
  59. package/utils/isFunction.d.ts +7 -0
  60. package/utils/isFunction.js +6 -0
  61. package/utils/math/index.cjs +2 -0
  62. package/utils/math/index.d.ts +1 -0
  63. package/utils/math/index.js +2 -0
  64. package/utils/scheduler.cjs +73 -0
  65. package/utils/scheduler.d.ts +19 -0
  66. package/utils/scheduler.js +51 -0
@@ -1,78 +1,50 @@
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
- class RefsManager {
8
- constructor(base, element, refs, eventsManager) {
9
- __publicField(this, "__element");
10
- __publicField(this, "__refs");
11
- __publicField(this, "__base");
12
- __publicField(this, "__eventsManager");
13
- Object.defineProperties(this, {
14
- __element: {
15
- enumerable: false,
16
- writable: false,
17
- value: element
18
- },
19
- __refs: {
20
- enumerable: false,
21
- writable: false,
22
- value: refs
23
- },
24
- __base: {
25
- enumerable: false,
26
- writable: false,
27
- value: base
28
- },
29
- __eventsManager: {
30
- enumerable: false,
31
- writable: false,
32
- value: eventsManager
33
- }
34
- });
35
- }
36
- registerAll() {
37
- this.__refs.forEach((refName) => this.__register(refName));
1
+ import AbstractManager from "./AbstractManager.js";
2
+ function normalizeRefName(name) {
3
+ return name.endsWith("[]") ? name.replace(/\[\]$/, "") : name;
4
+ }
5
+ function __filterRefsBelongingToInstance(that, ref) {
6
+ let ancestor = ref.parentElement;
7
+ while (ancestor && ancestor.dataset.component === void 0) {
8
+ ancestor = ancestor.parentElement;
38
9
  }
39
- unregisterAll() {
40
- this.__refs.forEach((refName) => this.__unregister(refName));
10
+ return ancestor === null || ancestor === that.__element;
11
+ }
12
+ function __register(that, refName) {
13
+ const isMultiple = refName.endsWith("[]");
14
+ const propName = normalizeRefName(refName);
15
+ const refs = Array.from(that.__element.querySelectorAll(`[data-ref="${refName}"]`)).filter((ref) => __filterRefsBelongingToInstance(that, ref));
16
+ if (!isMultiple && refs.length > 1) {
17
+ console.warn(`[${that.__base.$options.name}]`, `The "${refName}" ref has been found multiple times.`, "Did you forgot to add the `[]` suffix to its name?");
41
18
  }
42
- __register(refName) {
43
- const isMultiple = refName.endsWith("[]");
44
- const propName = RefsManager.normalizeRefName(refName);
45
- const refs = Array.from(this.__element.querySelectorAll(`[data-ref="${refName}"]`)).filter((ref) => this.__filterRefsBelongingToInstance(ref));
46
- if (!isMultiple && refs.length > 1) {
47
- console.warn(`[${this.__base.$options.name}]`, `The "${refName}" ref has been found multiple times.`, "Did you forgot to add the `[]` suffix to its name?");
48
- }
49
- if (!isMultiple && refs.length <= 1 && refs[0] === void 0) {
50
- console.warn(`[${this.__base.$options.name}]`, `The "${refName}" ref is missing.`, `Is there an \`[data-ref="${refName}"]\` element in the component's scope?`);
51
- return;
52
- }
53
- this.__eventsManager.bindRef(refName, refs);
54
- Object.defineProperty(this, propName, {
55
- value: isMultiple || refs.length > 1 ? refs : refs[0],
56
- enumerable: true,
57
- configurable: true
58
- });
19
+ if (!isMultiple && refs.length <= 1 && refs[0] === void 0) {
20
+ console.warn(`[${that.__base.$options.name}]`, `The "${refName}" ref is missing.`, `Is there an \`[data-ref="${refName}"]\` element in the component's scope?`);
21
+ return;
59
22
  }
60
- __unregister(refName) {
61
- const propName = RefsManager.normalizeRefName(refName);
62
- const refs = Array.isArray(this[propName]) ? this[propName] : [this[propName]];
63
- this.__eventsManager.unbindRef(refName, refs);
23
+ that.__eventsManager.bindRef(refName, refs);
24
+ Object.defineProperty(that, propName, {
25
+ value: isMultiple || refs.length > 1 ? refs : refs[0],
26
+ enumerable: true,
27
+ configurable: true
28
+ });
29
+ }
30
+ function __unregister(that, refName) {
31
+ const propName = normalizeRefName(refName);
32
+ const refs = Array.isArray(that[propName]) ? that[propName] : [that[propName]];
33
+ that.__eventsManager.unbindRef(refName, refs);
34
+ }
35
+ class RefsManager extends AbstractManager {
36
+ get __refs() {
37
+ var _a;
38
+ return (_a = this.__config.refs) != null ? _a : [];
64
39
  }
65
- static normalizeRefName(name) {
66
- return name.endsWith("[]") ? name.replace(/\[\]$/, "") : name;
40
+ registerAll() {
41
+ this.__refs.forEach((refName) => __register(this, refName));
67
42
  }
68
- __filterRefsBelongingToInstance(ref) {
69
- let ancestor = ref.parentElement;
70
- while (ancestor && ancestor.dataset.component === void 0) {
71
- ancestor = ancestor.parentElement;
72
- }
73
- return ancestor === null || ancestor === this.__element;
43
+ unregisterAll() {
44
+ this.__refs.forEach((refName) => __unregister(this, refName));
74
45
  }
75
46
  }
76
47
  export {
77
- RefsManager as default
48
+ RefsManager as default,
49
+ normalizeRefName
78
50
  };
@@ -0,0 +1,62 @@
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/Base/managers/ResponsiveOptionsManager.js
23
+ var ResponsiveOptionsManager_exports = {};
24
+ __export(ResponsiveOptionsManager_exports, {
25
+ default: () => ResponsiveOptionsManager
26
+ });
27
+ module.exports = __toCommonJS(ResponsiveOptionsManager_exports);
28
+ var import_OptionsManager = __toESM(require("./OptionsManager.cjs"), 1);
29
+ var import_services = require("../../services/index.cjs");
30
+ function __getResponsiveName(that, name) {
31
+ const { breakpoint } = (0, import_services.useResize)().props();
32
+ if (!breakpoint) {
33
+ return name;
34
+ }
35
+ let responsiveName = name;
36
+ const propertyName = (0, import_OptionsManager.__getPropertyName)(name);
37
+ const regex = new RegExp(`${propertyName}:(.+)$`);
38
+ Object.keys(that.__element.dataset).filter((optionName) => regex.test(optionName)).forEach((optionName) => {
39
+ const [, breakpoints] = optionName.match(regex);
40
+ const isInBreakpoint = breakpoints.split(":").includes(breakpoint);
41
+ if (isInBreakpoint) {
42
+ responsiveName = optionName.replace(/^option/, "");
43
+ }
44
+ });
45
+ return responsiveName;
46
+ }
47
+ var ResponsiveOptionsManager = class extends import_OptionsManager.default {
48
+ get(name, config) {
49
+ if (!config.responsive) {
50
+ return super.get(name, config);
51
+ }
52
+ return super.get(__getResponsiveName(this, name), config);
53
+ }
54
+ set(name, value, config) {
55
+ if (!config.responsive) {
56
+ super.set(name, value, config);
57
+ return;
58
+ }
59
+ console.warn(`[${this.__config.name}]`, "Responsive options are read-only.");
60
+ }
61
+ };
62
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Class options to manage options as data attributes on an HTML element.
3
+ */
4
+ export default class ResponsiveOptionsManager extends OptionsManager {
5
+ /**
6
+ * Get an option value.
7
+ *
8
+ * @param {string} name The option name.
9
+ * @param {ResponsiveOptionObject} config The option configuration.
10
+ * @returns {any}
11
+ */
12
+ get(name: string, config: ResponsiveOptionObject): any;
13
+ /**
14
+ * Set an option value.
15
+ *
16
+ * @param {string} name The option name.
17
+ * @param {any} value The new value.
18
+ * @param {ResponsiveOptionObject} config The option configuration.
19
+ */
20
+ set(name: string, value: any, config: ResponsiveOptionObject): void;
21
+ }
22
+ export type OptionObject = import('./OptionsManager.js').OptionObject;
23
+ export type ResponsiveOptionObject = OptionObject & {
24
+ responsive?: boolean;
25
+ };
26
+ import OptionsManager from "./OptionsManager.js";
@@ -0,0 +1,37 @@
1
+ import OptionsManager, { __getPropertyName } from "./OptionsManager.js";
2
+ import { useResize } from "../../services/index.js";
3
+ function __getResponsiveName(that, name) {
4
+ const { breakpoint } = useResize().props();
5
+ if (!breakpoint) {
6
+ return name;
7
+ }
8
+ let responsiveName = name;
9
+ const propertyName = __getPropertyName(name);
10
+ const regex = new RegExp(`${propertyName}:(.+)$`);
11
+ Object.keys(that.__element.dataset).filter((optionName) => regex.test(optionName)).forEach((optionName) => {
12
+ const [, breakpoints] = optionName.match(regex);
13
+ const isInBreakpoint = breakpoints.split(":").includes(breakpoint);
14
+ if (isInBreakpoint) {
15
+ responsiveName = optionName.replace(/^option/, "");
16
+ }
17
+ });
18
+ return responsiveName;
19
+ }
20
+ class ResponsiveOptionsManager extends OptionsManager {
21
+ get(name, config) {
22
+ if (!config.responsive) {
23
+ return super.get(name, config);
24
+ }
25
+ return super.get(__getResponsiveName(this, name), config);
26
+ }
27
+ set(name, value, config) {
28
+ if (!config.responsive) {
29
+ super.set(name, value, config);
30
+ return;
31
+ }
32
+ console.warn(`[${this.__config.name}]`, "Responsive options are read-only.");
33
+ }
34
+ }
35
+ export {
36
+ ResponsiveOptionsManager as default
37
+ };
@@ -36,6 +36,7 @@ var import_resize = __toESM(require("../../services/resize.cjs"), 1);
36
36
  var import_scroll = __toESM(require("../../services/scroll.cjs"), 1);
37
37
  var import_key = __toESM(require("../../services/key.cjs"), 1);
38
38
  var import_load = __toESM(require("../../services/load.cjs"), 1);
39
+ var import_AbstractManager = __toESM(require("./AbstractManager.cjs"), 1);
39
40
  var import_utils = require("../utils.cjs");
40
41
  var SERVICES_MAP = {
41
42
  scrolled: import_scroll.default,
@@ -46,17 +47,10 @@ var SERVICES_MAP = {
46
47
  loaded: import_load.default
47
48
  };
48
49
  var SERVICE_NAMES = Object.keys(SERVICES_MAP);
49
- var ServicesManager = class {
50
- constructor(instance) {
51
- __publicField(this, "__base");
50
+ var ServicesManager = class extends import_AbstractManager.default {
51
+ constructor() {
52
+ super(...arguments);
52
53
  __publicField(this, "__customServices", {});
53
- Object.defineProperties(this, {
54
- __base: {
55
- enumerable: false,
56
- writable: false,
57
- value: instance
58
- }
59
- });
60
54
  }
61
55
  get __services() {
62
56
  return {
@@ -85,7 +79,7 @@ var ServicesManager = class {
85
79
  const { add } = this.__services[service]();
86
80
  const self = this;
87
81
  function serviceHandler(...args) {
88
- self.__base.__callMethod(service, ...args);
82
+ return self.__base.__callMethod(service, ...args);
89
83
  }
90
84
  add(this.__base.$id, serviceHandler);
91
85
  return this.disable.bind(this, service);
@@ -7,17 +7,7 @@
7
7
  *
8
8
  * @todo Add support for disabled services on mount when the method is defined.
9
9
  */
10
- export default class ServicesManager {
11
- /**
12
- * Class constructor.
13
- * @param {Base} instance The Base instance.
14
- */
15
- constructor(instance: Base);
16
- /**
17
- * @type {Base}
18
- * @private
19
- */
20
- private __base;
10
+ export default class ServicesManager extends AbstractManager {
21
11
  /**
22
12
  * @type {Record<string, () => ServiceInterface>}
23
13
  */
@@ -101,6 +91,7 @@ export type ServiceName = keyof {
101
91
  keyed: typeof useKey;
102
92
  loaded: typeof useLoad;
103
93
  } | string;
94
+ import AbstractManager from "./AbstractManager.js";
104
95
  declare namespace SERVICES_MAP {
105
96
  export { useScroll as scrolled };
106
97
  export { useResize as resized };
@@ -10,6 +10,7 @@ import useResize from "../../services/resize.js";
10
10
  import useScroll from "../../services/scroll.js";
11
11
  import useKey from "../../services/key.js";
12
12
  import useLoad from "../../services/load.js";
13
+ import AbstractManager from "./AbstractManager.js";
13
14
  import { hasMethod } from "../utils.js";
14
15
  const SERVICES_MAP = {
15
16
  scrolled: useScroll,
@@ -20,17 +21,10 @@ const SERVICES_MAP = {
20
21
  loaded: useLoad
21
22
  };
22
23
  const SERVICE_NAMES = Object.keys(SERVICES_MAP);
23
- class ServicesManager {
24
- constructor(instance) {
25
- __publicField(this, "__base");
24
+ class ServicesManager extends AbstractManager {
25
+ constructor() {
26
+ super(...arguments);
26
27
  __publicField(this, "__customServices", {});
27
- Object.defineProperties(this, {
28
- __base: {
29
- enumerable: false,
30
- writable: false,
31
- value: instance
32
- }
33
- });
34
28
  }
35
29
  get __services() {
36
30
  return {
@@ -59,7 +53,7 @@ class ServicesManager {
59
53
  const { add } = this.__services[service]();
60
54
  const self = this;
61
55
  function serviceHandler(...args) {
62
- self.__base.__callMethod(service, ...args);
56
+ return self.__base.__callMethod(service, ...args);
63
57
  }
64
58
  add(this.__base.$id, serviceHandler);
65
59
  return this.disable.bind(this, service);
@@ -29,6 +29,7 @@ __export(decorators_exports, {
29
29
  withFreezedOptions: () => import_withFreezedOptions.default,
30
30
  withIntersectionObserver: () => import_withIntersectionObserver.default,
31
31
  withMountWhenInView: () => import_withMountWhenInView.default,
32
+ withResponsiveOptions: () => import_withResponsiveOptions.default,
32
33
  withScrolledInView: () => import_withScrolledInView.default,
33
34
  withVue2: () => import_withVue2.default
34
35
  });
@@ -40,6 +41,7 @@ var import_withExtraConfig = __toESM(require("./withExtraConfig.cjs"), 1);
40
41
  var import_withFreezedOptions = __toESM(require("./withFreezedOptions.cjs"), 1);
41
42
  var import_withIntersectionObserver = __toESM(require("./withIntersectionObserver.cjs"), 1);
42
43
  var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
44
+ var import_withResponsiveOptions = __toESM(require("./withResponsiveOptions.cjs"), 1);
43
45
  var import_withScrolledInView = __toESM(require("./withScrolledInView.cjs"), 1);
44
46
  var import_withVue2 = __toESM(require("./withVue2.cjs"), 1);
45
47
  if (module.exports.default) module.exports = module.exports.default;
@@ -5,5 +5,6 @@ export { default as withExtraConfig } from "./withExtraConfig.js";
5
5
  export { default as withFreezedOptions } from "./withFreezedOptions.js";
6
6
  export { default as withIntersectionObserver } from "./withIntersectionObserver.js";
7
7
  export { default as withMountWhenInView } from "./withMountWhenInView.js";
8
+ export { default as withResponsiveOptions } from "./withResponsiveOptions.js";
8
9
  export { default as withScrolledInView } from "./withScrolledInView.js";
9
10
  export { default as withVue2 } from "./withVue2.js";
@@ -5,8 +5,9 @@ import { default as default5 } from "./withExtraConfig.js";
5
5
  import { default as default6 } from "./withFreezedOptions.js";
6
6
  import { default as default7 } from "./withIntersectionObserver.js";
7
7
  import { default as default8 } from "./withMountWhenInView.js";
8
- import { default as default9 } from "./withScrolledInView.js";
9
- import { default as default10 } from "./withVue2.js";
8
+ import { default as default9 } from "./withResponsiveOptions.js";
9
+ import { default as default10 } from "./withScrolledInView.js";
10
+ import { default as default11 } from "./withVue2.js";
10
11
  export {
11
12
  default2 as withBreakpointManager,
12
13
  default3 as withBreakpointObserver,
@@ -15,6 +16,7 @@ export {
15
16
  default6 as withFreezedOptions,
16
17
  default7 as withIntersectionObserver,
17
18
  default8 as withMountWhenInView,
18
- default9 as withScrolledInView,
19
- default10 as withVue2
19
+ default9 as withResponsiveOptions,
20
+ default10 as withScrolledInView,
21
+ default11 as withVue2
20
22
  };
@@ -0,0 +1,39 @@
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/decorators/withResponsiveOptions.js
23
+ var withResponsiveOptions_exports = {};
24
+ __export(withResponsiveOptions_exports, {
25
+ default: () => withResponsiveOptions
26
+ });
27
+ module.exports = __toCommonJS(withResponsiveOptions_exports);
28
+ var import_ResponsiveOptionsManager = __toESM(require("../Base/managers/ResponsiveOptionsManager.cjs"), 1);
29
+ function withResponsiveOptions(BaseClass) {
30
+ return class extends BaseClass {
31
+ get __managers() {
32
+ return {
33
+ ...super.__managers,
34
+ OptionsManager: import_ResponsiveOptionsManager.default
35
+ };
36
+ }
37
+ };
38
+ }
39
+ if (module.exports.default) module.exports = module.exports.default;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Extends the configuration of an existing class.
3
+ *
4
+ * @template {import('../Base').BaseConstructor} T
5
+ * @param {T} BaseClass The Base class to extend.
6
+ * @returns {T}
7
+ */
8
+ export default function withResponsiveOptions<T extends typeof import("../Base").default>(BaseClass: T): T;
@@ -0,0 +1,14 @@
1
+ import ResponsiveOptionsManager from "../Base/managers/ResponsiveOptionsManager.js";
2
+ function withResponsiveOptions(BaseClass) {
3
+ return class extends BaseClass {
4
+ get __managers() {
5
+ return {
6
+ ...super.__managers,
7
+ OptionsManager: ResponsiveOptionsManager
8
+ };
9
+ }
10
+ };
11
+ }
12
+ export {
13
+ withResponsiveOptions as default
14
+ };
@@ -32,11 +32,12 @@ __export(withScrolledInView_exports, {
32
32
  module.exports = __toCommonJS(withScrolledInView_exports);
33
33
  var import_withMountWhenInView = __toESM(require("./withMountWhenInView.cjs"), 1);
34
34
  var import_utils = require("../utils/index.cjs");
35
- function withScrolledInView(BaseClass, options) {
35
+ var scheduler = (0, import_utils.useScheduler)(["update", "render"]);
36
+ function withScrolledInView(BaseClass, options = {}) {
36
37
  var _a;
37
38
  return _a = class extends (0, import_withMountWhenInView.default)(BaseClass, options) {
38
- constructor() {
39
- super(...arguments);
39
+ constructor(element) {
40
+ super(element);
40
41
  __publicField(this, "__props", {
41
42
  start: {
42
43
  x: 0,
@@ -61,37 +62,79 @@ function withScrolledInView(BaseClass, options) {
61
62
  });
62
63
  __publicField(this, "dampFactor", 0.1);
63
64
  __publicField(this, "dampPrecision", 1e-3);
65
+ const delegate = {
66
+ handleEvent(event) {
67
+ delegate[event.type](event.detail[0]);
68
+ },
69
+ resized: () => {
70
+ this.__setProps();
71
+ },
72
+ scrolled: (props) => {
73
+ if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
74
+ this.$services.enable("ticked");
75
+ }
76
+ },
77
+ ticked: () => {
78
+ this.__props.current.x = (0, import_utils.clamp)(window.pageXOffset, this.__props.start.x, this.__props.end.x);
79
+ this.__props.progress.x = (0, import_utils.clamp01)((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
80
+ this.__props.dampedProgress.x = (0, import_utils.damp)(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
81
+ this.__props.current.y = (0, import_utils.clamp)(window.pageYOffset, this.__props.start.y, this.__props.end.y);
82
+ this.__props.progress.y = (0, import_utils.clamp01)((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
83
+ this.__props.dampedProgress.y = (0, import_utils.damp)(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
84
+ if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
85
+ this.$services.disable("ticked");
86
+ }
87
+ scheduler.update(() => {
88
+ const renderFn = this.__callMethod("scrolledInView", this.__props);
89
+ if ((0, import_utils.isFunction)(renderFn)) {
90
+ scheduler.render(() => {
91
+ renderFn(this.__props);
92
+ });
93
+ }
94
+ });
95
+ }
96
+ };
97
+ this.$on("before-mounted", () => {
98
+ this.$on("resized", delegate);
99
+ this.$on("scrolled", delegate);
100
+ this.$on("ticked", delegate);
101
+ });
102
+ this.$on("mounted", () => {
103
+ this.__setProps();
104
+ });
105
+ this.$on("destroyed", () => {
106
+ this.$off("resized", delegate);
107
+ this.$off("scrolled", delegate);
108
+ this.$off("ticked", delegate);
109
+ });
64
110
  }
65
111
  mounted() {
66
- this.__setProps();
112
+ if ((0, import_utils.isFunction)(super.mounted))
113
+ super.mounted();
67
114
  }
68
- resized() {
69
- this.__setProps();
115
+ resized(props) {
116
+ if ((0, import_utils.isFunction)(super.resized))
117
+ super.resized(props);
70
118
  }
71
119
  scrolled(props) {
72
- if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
73
- this.$services.enable("ticked");
74
- }
120
+ if ((0, import_utils.isFunction)(super.scrolled))
121
+ super.scrolled(props);
122
+ }
123
+ ticked(props) {
124
+ if ((0, import_utils.isFunction)(super.ticked))
125
+ super.ticked(props);
75
126
  }
76
- ticked() {
77
- this.__props.current.x = (0, import_utils.clamp)(window.pageXOffset, this.__props.start.x, this.__props.end.x);
78
- this.__props.progress.x = (0, import_utils.clamp01)((this.__props.current.x - this.__props.start.x) / (this.__props.end.x - this.__props.start.x));
79
- this.__props.dampedProgress.x = (0, import_utils.damp)(this.__props.progress.x, this.__props.dampedProgress.x, this.dampFactor, this.dampPrecision);
80
- this.__props.current.y = (0, import_utils.clamp)(window.pageYOffset, this.__props.start.y, this.__props.end.y);
81
- this.__props.progress.y = (0, import_utils.clamp01)((this.__props.current.y - this.__props.start.y) / (this.__props.end.y - this.__props.start.y));
82
- this.__props.dampedProgress.y = (0, import_utils.damp)(this.__props.progress.y, this.__props.dampedProgress.y, this.dampFactor, this.dampPrecision);
83
- if (this.__props.dampedProgress.x === this.__props.progress.x && this.__props.dampedProgress.y === this.__props.progress.y) {
84
- this.$services.disable("ticked");
85
- }
86
- this.__callMethod("scrolledInView", this.__props);
127
+ destroyed() {
128
+ if ((0, import_utils.isFunction)(super.destroyed))
129
+ super.destroyed();
87
130
  }
88
131
  __setProps() {
89
- const sizes = this.$el.getBoundingClientRect();
90
- const yEnd = sizes.top + window.pageYOffset + sizes.height;
132
+ const sizes = options.useOffsetSizes ? (0, import_utils.getOffsetSizes)(this.$el) : this.$el.getBoundingClientRect();
133
+ const yEnd = sizes.y + window.pageYOffset + sizes.height;
91
134
  const yStart = yEnd - window.innerHeight - sizes.height;
92
135
  const yCurrent = (0, import_utils.clamp)(window.pageYOffset, yStart, yEnd);
93
136
  const yProgress = (0, import_utils.clamp01)((yCurrent - yStart) / (yEnd - yStart));
94
- const xEnd = sizes.left + window.pageXOffset + sizes.width;
137
+ const xEnd = sizes.x + window.pageXOffset + sizes.width;
95
138
  const xStart = xEnd - window.innerWidth - sizes.width;
96
139
  const xCurrent = (0, import_utils.clamp)(window.pageXOffset, xStart, xEnd);
97
140
  const xProgress = (0, import_utils.clamp01)((xCurrent - xStart) / (xEnd - xStart));
@@ -8,10 +8,12 @@
8
8
  *
9
9
  * @template {BaseConstructor} T
10
10
  * @param {T} BaseClass
11
- * @param {IntersectionObserverInit} options
11
+ * @param {IntersectionObserverInit & { useOffsetSizes?: boolean }} options
12
12
  * @returns {T}
13
13
  */
14
- export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options: IntersectionObserverInit): T;
14
+ export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options?: IntersectionObserverInit & {
15
+ useOffsetSizes?: boolean;
16
+ }): T;
15
17
  export type Base = import('../Base').default;
16
18
  export type BaseConstructor = import('../Base').BaseConstructor;
17
19
  export type BaseConfig = import('../Base').BaseConfig;