@studiometa/js-toolkit 2.0.0-rc.2 → 2.1.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 (151) hide show
  1. package/Base/index.cjs +54 -18
  2. package/Base/index.d.ts +47 -26
  3. package/Base/index.js +54 -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 +8 -83
  9. package/Base/managers/ChildrenManager.js +76 -100
  10. package/Base/managers/EventsManager.cjs +75 -99
  11. package/Base/managers/EventsManager.d.ts +37 -113
  12. package/Base/managers/EventsManager.js +75 -99
  13. package/Base/managers/OptionsManager.cjs +65 -79
  14. package/Base/managers/OptionsManager.d.ts +41 -80
  15. package/Base/managers/OptionsManager.js +66 -80
  16. package/Base/managers/RefsManager.cjs +44 -68
  17. package/Base/managers/RefsManager.d.ts +12 -66
  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 +7 -10
  23. package/Base/managers/ServicesManager.d.ts +16 -19
  24. package/Base/managers/ServicesManager.js +7 -10
  25. package/Base/utils.d.ts +4 -4
  26. package/decorators/index.cjs +2 -0
  27. package/decorators/index.d.ts +1 -0
  28. package/decorators/index.js +6 -4
  29. package/decorators/withBreakpointManager.cjs +0 -1
  30. package/decorators/withBreakpointManager.d.ts +2 -2
  31. package/decorators/withBreakpointManager.js +0 -1
  32. package/decorators/withBreakpointObserver.cjs +1 -2
  33. package/decorators/withBreakpointObserver.d.ts +1 -1
  34. package/decorators/withBreakpointObserver.js +1 -2
  35. package/decorators/withDrag.d.ts +1 -1
  36. package/decorators/withExtraConfig.d.ts +1 -1
  37. package/decorators/withFreezedOptions.cjs +12 -3
  38. package/decorators/withFreezedOptions.d.ts +1 -1
  39. package/decorators/withFreezedOptions.js +13 -3
  40. package/decorators/withIntersectionObserver.cjs +0 -1
  41. package/decorators/withIntersectionObserver.d.ts +1 -1
  42. package/decorators/withIntersectionObserver.js +0 -1
  43. package/decorators/withMountWhenInView.cjs +0 -1
  44. package/decorators/withMountWhenInView.d.ts +1 -1
  45. package/decorators/withMountWhenInView.js +0 -1
  46. package/decorators/withResponsiveOptions.cjs +39 -0
  47. package/decorators/withResponsiveOptions.d.ts +8 -0
  48. package/decorators/withResponsiveOptions.js +14 -0
  49. package/decorators/withScrolledInView.cjs +58 -23
  50. package/decorators/withScrolledInView.d.ts +5 -3
  51. package/decorators/withScrolledInView.js +59 -24
  52. package/helpers/createApp.d.ts +3 -26
  53. package/helpers/getInstanceFromElement.cjs +32 -0
  54. package/helpers/getInstanceFromElement.d.ts +14 -0
  55. package/helpers/getInstanceFromElement.js +10 -0
  56. package/helpers/importOnInteraction.d.ts +3 -5
  57. package/helpers/importWhenIdle.d.ts +3 -5
  58. package/helpers/importWhenVisible.d.ts +4 -6
  59. package/helpers/index.cjs +2 -0
  60. package/helpers/index.d.ts +1 -0
  61. package/helpers/index.js +8 -6
  62. package/helpers/utils.d.ts +3 -4
  63. package/package.json +2 -1
  64. package/services/Service.d.ts +9 -9
  65. package/services/drag.cjs +0 -1
  66. package/services/drag.d.ts +3 -3
  67. package/services/drag.js +0 -1
  68. package/services/key.d.ts +1 -1
  69. package/services/load.d.ts +1 -1
  70. package/services/pointer.d.ts +1 -1
  71. package/services/raf.d.ts +1 -1
  72. package/services/resize.cjs +2 -2
  73. package/services/resize.d.ts +1 -1
  74. package/services/resize.js +2 -2
  75. package/services/scroll.cjs +3 -1
  76. package/services/scroll.d.ts +1 -1
  77. package/services/scroll.js +3 -1
  78. package/utils/collide/boundingRectToCircle.d.ts +5 -5
  79. package/utils/collide/collideCircleCircle.d.ts +4 -4
  80. package/utils/collide/collideCircleRect.d.ts +8 -8
  81. package/utils/collide/collidePointCircle.d.ts +6 -6
  82. package/utils/collide/collidePointRect.d.ts +7 -7
  83. package/utils/collide/collideRectRect.d.ts +5 -5
  84. package/utils/css/animate.cjs +190 -0
  85. package/utils/css/animate.d.ts +57 -0
  86. package/utils/css/animate.js +165 -0
  87. package/utils/css/classes.cjs +3 -3
  88. package/utils/css/classes.d.ts +10 -10
  89. package/utils/css/classes.js +3 -3
  90. package/utils/css/getOffsetSizes.cjs +47 -0
  91. package/utils/css/getOffsetSizes.d.ts +15 -0
  92. package/utils/css/getOffsetSizes.js +25 -0
  93. package/utils/css/index.cjs +6 -0
  94. package/utils/css/index.d.ts +3 -0
  95. package/utils/css/index.js +9 -4
  96. package/utils/css/matrix.d.ts +14 -15
  97. package/utils/css/styles.d.ts +2 -2
  98. package/utils/css/transform.cjs +91 -0
  99. package/utils/css/transform.d.ts +43 -0
  100. package/utils/css/transform.js +66 -0
  101. package/utils/css/transition.cjs +2 -0
  102. package/utils/css/transition.d.ts +2 -2
  103. package/utils/css/transition.js +2 -0
  104. package/utils/debounce.d.ts +4 -4
  105. package/utils/focusTrap.cjs +1 -1
  106. package/utils/focusTrap.d.ts +1 -0
  107. package/utils/focusTrap.js +1 -1
  108. package/utils/history.d.ts +13 -11
  109. package/utils/index.cjs +4 -0
  110. package/utils/index.d.ts +2 -0
  111. package/utils/index.js +4 -0
  112. package/utils/isDefined.cjs +28 -0
  113. package/utils/isDefined.d.ts +7 -0
  114. package/utils/isDefined.js +6 -0
  115. package/utils/isFunction.cjs +28 -0
  116. package/utils/isFunction.d.ts +7 -0
  117. package/utils/isFunction.js +6 -0
  118. package/utils/math/clamp.d.ts +1 -1
  119. package/utils/math/clamp01.d.ts +1 -1
  120. package/utils/math/damp.d.ts +6 -6
  121. package/utils/math/ease.d.ts +7 -7
  122. package/utils/math/index.cjs +2 -0
  123. package/utils/math/index.d.ts +1 -0
  124. package/utils/math/index.js +2 -0
  125. package/utils/math/inertiaFinalValue.d.ts +5 -5
  126. package/utils/math/lerp.d.ts +4 -4
  127. package/utils/math/map.d.ts +6 -6
  128. package/utils/math/round.d.ts +4 -4
  129. package/utils/memoize.d.ts +1 -1
  130. package/utils/nextFrame.d.ts +3 -4
  131. package/utils/nextMicrotask.d.ts +1 -1
  132. package/utils/nextTick.d.ts +1 -1
  133. package/utils/object/autoBind.d.ts +3 -3
  134. package/utils/object/getAllProperties.d.ts +3 -3
  135. package/utils/object/isObject.d.ts +1 -1
  136. package/utils/scrollTo.cjs +1 -1
  137. package/utils/scrollTo.d.ts +1 -1
  138. package/utils/scrollTo.js +1 -1
  139. package/utils/string/withLeadingCharacters.d.ts +3 -2
  140. package/utils/string/withLeadingSlash.d.ts +1 -1
  141. package/utils/string/withTrailingCharacters.d.ts +3 -2
  142. package/utils/string/withTrailingSlash.d.ts +1 -1
  143. package/utils/string/withoutLeadingCharacters.d.ts +3 -2
  144. package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
  145. package/utils/string/withoutLeadingSlash.d.ts +1 -1
  146. package/utils/string/withoutTrailingCharacters.d.ts +3 -2
  147. package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
  148. package/utils/string/withoutTrailingSlash.d.ts +1 -1
  149. package/utils/throttle.cjs +1 -1
  150. package/utils/throttle.d.ts +3 -3
  151. package/utils/throttle.js +1 -1
@@ -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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
8
  var __export = (target, all) => {
@@ -15,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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));
18
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
22
  var __publicField = (obj, key, value) => {
20
23
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -27,120 +30,96 @@ __export(ChildrenManager_exports, {
27
30
  default: () => ChildrenManager
28
31
  });
29
32
  module.exports = __toCommonJS(ChildrenManager_exports);
33
+ var import_AbstractManager = __toESM(require("./AbstractManager.cjs"), 1);
30
34
  var import_utils = require("../utils.cjs");
31
- var ChildrenManager = class {
32
- constructor(base, element, components, eventsManager) {
33
- __publicField(this, "__base");
34
- __publicField(this, "__element");
35
- __publicField(this, "__components");
36
- __publicField(this, "__eventsManager");
37
- __publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
38
- Object.defineProperties(this, {
39
- __base: {
40
- enumerable: false,
41
- writable: false,
42
- value: base
43
- },
44
- __element: {
45
- enumerable: false,
46
- writable: false,
47
- value: element
48
- },
49
- __components: {
50
- enumerable: false,
51
- writable: false,
52
- value: components
53
- },
54
- __eventsManager: {
55
- enumerable: false,
56
- writable: false,
57
- value: eventsManager
58
- }
35
+ function __getChild(that, el, ComponentClass, name) {
36
+ const asyncComponentPromise = that.__asyncComponentPromises.get(ComponentClass);
37
+ if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
38
+ let ctor = ComponentClass;
39
+ if (asyncComponentPromise) {
40
+ ctor = asyncComponentPromise.ctor;
41
+ }
42
+ if (el.__base__ && el.__base__.has(ctor)) {
43
+ return el.__base__.get(ctor);
44
+ }
45
+ const child = new ctor(el);
46
+ Object.defineProperty(child, "$parent", { get: () => that.__base });
47
+ return child;
48
+ }
49
+ const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(that.__base);
50
+ if (!asyncComponentPromise) {
51
+ that.__asyncComponentPromises.set(ComponentClass, {
52
+ promise,
53
+ status: "pending",
54
+ ctor: void 0
59
55
  });
60
56
  }
61
- get registeredNames() {
62
- return Object.keys(this).filter((key) => !key.startsWith("__"));
57
+ return promise.then((module2) => {
58
+ var _a;
59
+ const ctor = (_a = module2.default) != null ? _a : module2;
60
+ that.__asyncComponentPromises.set(ComponentClass, {
61
+ promise,
62
+ status: "resolved",
63
+ ctor
64
+ });
65
+ return __getChild(that, el, ctor, name);
66
+ });
67
+ }
68
+ function __register(that, name, component) {
69
+ Object.defineProperty(that, name, {
70
+ enumerable: true,
71
+ configurable: true,
72
+ get: () => {
73
+ const elements = (0, import_utils.getComponentElements)(name, that.__element);
74
+ if (elements.length === 0) {
75
+ return [];
76
+ }
77
+ return elements.map((element) => __getChild(that, element, component, name)).filter((instance) => instance !== "terminated");
78
+ }
79
+ });
80
+ }
81
+ function __triggerHook(that, hook, instance, name) {
82
+ if (hook === "$update" && !instance.$isMounted) {
83
+ hook = "$mount";
63
84
  }
64
- registerAll() {
65
- Object.entries(this.__components).forEach(([name, component]) => this.__register(name, component));
85
+ if (hook === "$update" || hook === "$destroy") {
86
+ that.__eventsManager.unbindChild(name, instance);
66
87
  }
67
- __register(name, component) {
68
- Object.defineProperty(this, name, {
69
- enumerable: true,
70
- configurable: true,
71
- get: () => {
72
- const elements = (0, import_utils.getComponentElements)(name, this.__element);
73
- if (elements.length === 0) {
74
- return [];
75
- }
76
- return elements.map((element) => this.__getChild(element, component, name)).filter((instance) => instance !== "terminated");
77
- }
78
- });
88
+ if (hook === "$update" || hook === "$mount") {
89
+ that.__eventsManager.bindChild(name, instance);
79
90
  }
80
- __getChild(el, ComponentClass, name) {
81
- const asyncComponentPromise = this.__asyncComponentPromises.get(ComponentClass);
82
- if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
83
- let ctor = ComponentClass;
84
- if (asyncComponentPromise) {
85
- ctor = asyncComponentPromise.ctor;
86
- }
87
- if (el.__base__ && el.__base__.has(ctor)) {
88
- return el.__base__.get(ctor);
91
+ instance[hook]();
92
+ }
93
+ function __triggerHookForAll(that, hook) {
94
+ that.registeredNames.forEach((name) => {
95
+ that[name].forEach((instance) => {
96
+ if (instance instanceof Promise) {
97
+ instance.then((resolvedInstance) => __triggerHook(that, hook, resolvedInstance, name));
98
+ } else {
99
+ __triggerHook(that, hook, instance, name);
89
100
  }
90
- const child = new ctor(el);
91
- Object.defineProperty(child, "$parent", { get: () => this.__base });
92
- return child;
93
- }
94
- const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(this.__base);
95
- if (!asyncComponentPromise) {
96
- this.__asyncComponentPromises.set(ComponentClass, {
97
- promise,
98
- status: "pending",
99
- ctor: void 0
100
- });
101
- }
102
- return promise.then((module2) => {
103
- var _a;
104
- const ctor = (_a = module2.default) != null ? _a : module2;
105
- this.__asyncComponentPromises.set(ComponentClass, {
106
- promise,
107
- status: "resolved",
108
- ctor
109
- });
110
- return this.__getChild(el, ctor, name);
111
101
  });
102
+ });
103
+ }
104
+ var ChildrenManager = class extends import_AbstractManager.default {
105
+ constructor() {
106
+ super(...arguments);
107
+ __publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
108
+ }
109
+ get registeredNames() {
110
+ return Object.keys(this).filter((key) => !key.startsWith("__"));
111
+ }
112
+ registerAll() {
113
+ Object.entries(this.__config.components).forEach(([name, component]) => __register(this, name, component));
112
114
  }
113
115
  mountAll() {
114
- this.__triggerHookForAll("$mount");
116
+ __triggerHookForAll(this, "$mount");
115
117
  }
116
118
  updateAll() {
117
- this.__triggerHookForAll("$update");
119
+ __triggerHookForAll(this, "$update");
118
120
  }
119
121
  destroyAll() {
120
- this.__triggerHookForAll("$destroy");
121
- }
122
- __triggerHookForAll(hook) {
123
- this.registeredNames.forEach((name) => {
124
- this[name].forEach((instance) => {
125
- if (instance instanceof Promise) {
126
- instance.then((resolvedInstance) => this.__triggerHook(hook, resolvedInstance, name));
127
- } else {
128
- this.__triggerHook(hook, instance, name);
129
- }
130
- });
131
- });
132
- }
133
- __triggerHook(hook, instance, name) {
134
- if (hook === "$update" && !instance.$isMounted) {
135
- hook = "$mount";
136
- }
137
- if (hook === "$update" || hook === "$destroy") {
138
- this.__eventsManager.unbindChild(name, instance);
139
- }
140
- if (hook === "$update" || hook === "$mount") {
141
- this.__eventsManager.bindChild(name, instance);
142
- }
143
- instance[hook]();
122
+ __triggerHookForAll(this, "$destroy");
144
123
  }
145
124
  };
146
125
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,85 +1,26 @@
1
- /**
2
- * @typedef {import('../index.js').default} Base
3
- * @typedef {import('../index.js').BaseConstructor} BaseConstructor
4
- * @typedef {import('../index.js').BaseAsyncConstructor} BaseAsyncConstructor
5
- * @typedef {import('../index.js').BaseConfigComponents} BaseConfigComponents
6
- * @typedef {import('./EventsManager.js').default} EventsManager
7
- */
8
1
  /**
9
2
  * Children manager.
10
3
  */
11
- export default class ChildrenManager {
12
- /**
13
- * Class constructor.
14
- * @param {Base} base
15
- * The component's instance.
16
- * @param {HTMLElement} element
17
- * The component's root element
18
- * @param {BaseConfigComponents} components
19
- * The children components' classes
20
- * @param {EventsManager} eventsManager
21
- */
22
- constructor(base: Base, element: HTMLElement, components: BaseConfigComponents, eventsManager: EventsManager);
23
- /**
24
- * @type {Base}
25
- * @private
26
- */
27
- private __base;
28
- /**
29
- * @type {HTMLElement}
30
- * @private
31
- */
32
- private __element;
33
- /**
34
- * @type {BaseConfigComponents}
35
- * @private
36
- */
37
- private __components;
38
- /**
39
- * @type {EventsManager}
40
- * @private
41
- */
42
- private __eventsManager;
4
+ export default class ChildrenManager extends AbstractManager {
43
5
  /**
44
6
  * Store async component promises to avoid calling them multiple times and
45
7
  * waiting for them when they are already resolved.
46
8
  *
47
- * @private
48
9
  * @type {WeakMap<BaseAsyncConstructor, { promise: ReturnType<BaseAsyncConstructor>, status: 'pending'|'resolved', ctor?: BaseConstructor }>}
49
10
  */
50
- private __asyncComponentPromises;
11
+ __asyncComponentPromises: WeakMap<BaseAsyncConstructor, {
12
+ promise: ReturnType<BaseAsyncConstructor>;
13
+ status: 'pending' | 'resolved';
14
+ ctor?: BaseConstructor;
15
+ }>;
51
16
  /**
52
- * @return {string[]}
17
+ * @returns {string[]}
53
18
  */
54
19
  get registeredNames(): string[];
55
20
  /**
56
21
  * Register instances of all children components.
57
22
  */
58
23
  registerAll(): void;
59
- /**
60
- * Register instance of a child component.
61
- *
62
- * @param {string} name
63
- * The name of the child component.
64
- * @param {BaseConstructor|BaseAsyncConstructor} component
65
- * A Base class or a Promise for async components.
66
- * @private
67
- */
68
- private __register;
69
- /**
70
- * Get a child component's instance.
71
- *
72
- * @param {HTMLElement & { __base__?: WeakMap<BaseConstructor, Base> }} el
73
- * The root element of the child component.
74
- * @param {BaseConstructor|BaseAsyncConstructor} ComponentClass
75
- * A Base class or a Promise for async components.
76
- * @param {string} name
77
- * The name of the child component.
78
- * @return {Base|Promise|'terminated'}
79
- * A Base instance or a Promise resolving to a Base instance.
80
- * @private
81
- */
82
- private __getChild;
83
24
  /**
84
25
  * Mount all child component instances.
85
26
  */
@@ -92,25 +33,9 @@ export default class ChildrenManager {
92
33
  * Destroy all child component instances.
93
34
  */
94
35
  destroyAll(): void;
95
- /**
96
- * Execute the given hook for all children instances.
97
- *
98
- * @param {'$mount'|'$update'|'$destroy'} hook The hook to execute.
99
- * @private
100
- */
101
- private __triggerHookForAll;
102
- /**
103
- * Execute the given hook for the given instance.
104
- *
105
- * @param {'$mount'|'$update'|'$destroy'} hook The hook to trigger.
106
- * @param {Base} instance The target instance.
107
- * @param {string} name The name of the component.
108
- * @private
109
- */
110
- private __triggerHook;
111
36
  }
112
37
  export type Base = import('../index.js').default;
113
38
  export type BaseConstructor = import('../index.js').BaseConstructor;
114
39
  export type BaseAsyncConstructor = import('../index.js').BaseAsyncConstructor;
115
40
  export type BaseConfigComponents = import('../index.js').BaseConfigComponents;
116
- export type EventsManager = import('./EventsManager.js').default;
41
+ import AbstractManager from "./AbstractManager.js";
@@ -4,120 +4,96 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
+ import AbstractManager from "./AbstractManager.js";
7
8
  import { getComponentElements } from "../utils.js";
8
- class ChildrenManager {
9
- constructor(base, element, components, eventsManager) {
10
- __publicField(this, "__base");
11
- __publicField(this, "__element");
12
- __publicField(this, "__components");
13
- __publicField(this, "__eventsManager");
14
- __publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
15
- Object.defineProperties(this, {
16
- __base: {
17
- enumerable: false,
18
- writable: false,
19
- value: base
20
- },
21
- __element: {
22
- enumerable: false,
23
- writable: false,
24
- value: element
25
- },
26
- __components: {
27
- enumerable: false,
28
- writable: false,
29
- value: components
30
- },
31
- __eventsManager: {
32
- enumerable: false,
33
- writable: false,
34
- value: eventsManager
35
- }
9
+ function __getChild(that, el, ComponentClass, name) {
10
+ const asyncComponentPromise = that.__asyncComponentPromises.get(ComponentClass);
11
+ if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
12
+ let ctor = ComponentClass;
13
+ if (asyncComponentPromise) {
14
+ ctor = asyncComponentPromise.ctor;
15
+ }
16
+ if (el.__base__ && el.__base__.has(ctor)) {
17
+ return el.__base__.get(ctor);
18
+ }
19
+ const child = new ctor(el);
20
+ Object.defineProperty(child, "$parent", { get: () => that.__base });
21
+ return child;
22
+ }
23
+ const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(that.__base);
24
+ if (!asyncComponentPromise) {
25
+ that.__asyncComponentPromises.set(ComponentClass, {
26
+ promise,
27
+ status: "pending",
28
+ ctor: void 0
36
29
  });
37
30
  }
38
- get registeredNames() {
39
- return Object.keys(this).filter((key) => !key.startsWith("__"));
31
+ return promise.then((module) => {
32
+ var _a;
33
+ const ctor = (_a = module.default) != null ? _a : module;
34
+ that.__asyncComponentPromises.set(ComponentClass, {
35
+ promise,
36
+ status: "resolved",
37
+ ctor
38
+ });
39
+ return __getChild(that, el, ctor, name);
40
+ });
41
+ }
42
+ function __register(that, name, component) {
43
+ Object.defineProperty(that, name, {
44
+ enumerable: true,
45
+ configurable: true,
46
+ get: () => {
47
+ const elements = getComponentElements(name, that.__element);
48
+ if (elements.length === 0) {
49
+ return [];
50
+ }
51
+ return elements.map((element) => __getChild(that, element, component, name)).filter((instance) => instance !== "terminated");
52
+ }
53
+ });
54
+ }
55
+ function __triggerHook(that, hook, instance, name) {
56
+ if (hook === "$update" && !instance.$isMounted) {
57
+ hook = "$mount";
40
58
  }
41
- registerAll() {
42
- Object.entries(this.__components).forEach(([name, component]) => this.__register(name, component));
59
+ if (hook === "$update" || hook === "$destroy") {
60
+ that.__eventsManager.unbindChild(name, instance);
43
61
  }
44
- __register(name, component) {
45
- Object.defineProperty(this, name, {
46
- enumerable: true,
47
- configurable: true,
48
- get: () => {
49
- const elements = getComponentElements(name, this.__element);
50
- if (elements.length === 0) {
51
- return [];
52
- }
53
- return elements.map((element) => this.__getChild(element, component, name)).filter((instance) => instance !== "terminated");
54
- }
55
- });
62
+ if (hook === "$update" || hook === "$mount") {
63
+ that.__eventsManager.bindChild(name, instance);
56
64
  }
57
- __getChild(el, ComponentClass, name) {
58
- const asyncComponentPromise = this.__asyncComponentPromises.get(ComponentClass);
59
- if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
60
- let ctor = ComponentClass;
61
- if (asyncComponentPromise) {
62
- ctor = asyncComponentPromise.ctor;
63
- }
64
- if (el.__base__ && el.__base__.has(ctor)) {
65
- return el.__base__.get(ctor);
65
+ instance[hook]();
66
+ }
67
+ function __triggerHookForAll(that, hook) {
68
+ that.registeredNames.forEach((name) => {
69
+ that[name].forEach((instance) => {
70
+ if (instance instanceof Promise) {
71
+ instance.then((resolvedInstance) => __triggerHook(that, hook, resolvedInstance, name));
72
+ } else {
73
+ __triggerHook(that, hook, instance, name);
66
74
  }
67
- const child = new ctor(el);
68
- Object.defineProperty(child, "$parent", { get: () => this.__base });
69
- return child;
70
- }
71
- const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(this.__base);
72
- if (!asyncComponentPromise) {
73
- this.__asyncComponentPromises.set(ComponentClass, {
74
- promise,
75
- status: "pending",
76
- ctor: void 0
77
- });
78
- }
79
- return promise.then((module) => {
80
- var _a;
81
- const ctor = (_a = module.default) != null ? _a : module;
82
- this.__asyncComponentPromises.set(ComponentClass, {
83
- promise,
84
- status: "resolved",
85
- ctor
86
- });
87
- return this.__getChild(el, ctor, name);
88
75
  });
76
+ });
77
+ }
78
+ class ChildrenManager extends AbstractManager {
79
+ constructor() {
80
+ super(...arguments);
81
+ __publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
82
+ }
83
+ get registeredNames() {
84
+ return Object.keys(this).filter((key) => !key.startsWith("__"));
85
+ }
86
+ registerAll() {
87
+ Object.entries(this.__config.components).forEach(([name, component]) => __register(this, name, component));
89
88
  }
90
89
  mountAll() {
91
- this.__triggerHookForAll("$mount");
90
+ __triggerHookForAll(this, "$mount");
92
91
  }
93
92
  updateAll() {
94
- this.__triggerHookForAll("$update");
93
+ __triggerHookForAll(this, "$update");
95
94
  }
96
95
  destroyAll() {
97
- this.__triggerHookForAll("$destroy");
98
- }
99
- __triggerHookForAll(hook) {
100
- this.registeredNames.forEach((name) => {
101
- this[name].forEach((instance) => {
102
- if (instance instanceof Promise) {
103
- instance.then((resolvedInstance) => this.__triggerHook(hook, resolvedInstance, name));
104
- } else {
105
- this.__triggerHook(hook, instance, name);
106
- }
107
- });
108
- });
109
- }
110
- __triggerHook(hook, instance, name) {
111
- if (hook === "$update" && !instance.$isMounted) {
112
- hook = "$mount";
113
- }
114
- if (hook === "$update" || hook === "$destroy") {
115
- this.__eventsManager.unbindChild(name, instance);
116
- }
117
- if (hook === "$update" || hook === "$mount") {
118
- this.__eventsManager.bindChild(name, instance);
119
- }
120
- instance[hook]();
96
+ __triggerHookForAll(this, "$destroy");
121
97
  }
122
98
  }
123
99
  export {