@studiometa/js-toolkit 2.0.0-beta.8 → 2.0.0-rc.2

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 (189) hide show
  1. package/Base/index.cjs +285 -0
  2. package/Base/index.d.ts +11 -2
  3. package/Base/index.js +114 -197
  4. package/Base/managers/ChildrenManager.cjs +146 -0
  5. package/Base/managers/ChildrenManager.d.ts +9 -1
  6. package/Base/managers/ChildrenManager.js +60 -59
  7. package/Base/managers/EventsManager.cjs +183 -0
  8. package/Base/managers/EventsManager.js +72 -112
  9. package/Base/managers/OptionsManager.cjs +174 -0
  10. package/Base/managers/OptionsManager.d.ts +9 -5
  11. package/Base/managers/OptionsManager.js +60 -90
  12. package/Base/managers/RefsManager.cjs +99 -0
  13. package/Base/managers/RefsManager.js +30 -35
  14. package/Base/managers/ServicesManager.cjs +131 -0
  15. package/Base/managers/ServicesManager.js +39 -67
  16. package/Base/utils.cjs +41 -0
  17. package/Base/utils.js +12 -11
  18. package/README.md +13 -70
  19. package/decorators/index.cjs +45 -0
  20. package/decorators/index.d.ts +9 -9
  21. package/decorators/index.js +20 -9
  22. package/decorators/withBreakpointManager.cjs +85 -0
  23. package/decorators/withBreakpointManager.js +18 -39
  24. package/decorators/withBreakpointObserver.cjs +115 -0
  25. package/decorators/withBreakpointObserver.js +44 -86
  26. package/decorators/withDrag.cjs +53 -0
  27. package/decorators/withDrag.js +24 -26
  28. package/decorators/withExtraConfig.cjs +43 -0
  29. package/decorators/withExtraConfig.js +17 -12
  30. package/decorators/withFreezedOptions.cjs +37 -0
  31. package/decorators/withFreezedOptions.d.ts +14 -0
  32. package/decorators/withFreezedOptions.js +15 -0
  33. package/decorators/withIntersectionObserver.cjs +62 -0
  34. package/decorators/withIntersectionObserver.js +29 -32
  35. package/decorators/withMountWhenInView.cjs +69 -0
  36. package/decorators/withMountWhenInView.js +31 -52
  37. package/decorators/withScrolledInView.cjs +114 -0
  38. package/decorators/withScrolledInView.d.ts +2 -1
  39. package/decorators/withScrolledInView.js +35 -39
  40. package/decorators/withVue2.cjs +61 -0
  41. package/decorators/withVue2.js +27 -32
  42. package/helpers/createApp.cjs +52 -0
  43. package/helpers/createApp.d.ts +2 -2
  44. package/helpers/createApp.js +12 -12
  45. package/helpers/importOnInteraction.cjs +52 -0
  46. package/helpers/importOnInteraction.js +17 -18
  47. package/helpers/importWhenIdle.cjs +49 -0
  48. package/helpers/importWhenIdle.js +14 -17
  49. package/helpers/importWhenVisible.cjs +50 -0
  50. package/helpers/importWhenVisible.js +16 -18
  51. package/helpers/index.cjs +35 -0
  52. package/helpers/index.d.ts +4 -5
  53. package/helpers/index.js +10 -5
  54. package/helpers/utils.cjs +35 -0
  55. package/helpers/utils.js +7 -6
  56. package/index.cjs +33 -0
  57. package/index.d.ts +4 -21
  58. package/index.js +7 -5
  59. package/package.json +14 -4
  60. package/services/Service.cjs +76 -0
  61. package/services/Service.js +19 -32
  62. package/services/drag.cjs +213 -0
  63. package/services/drag.d.ts +1 -0
  64. package/services/drag.js +64 -68
  65. package/services/index.cjs +41 -0
  66. package/services/index.d.ts +7 -8
  67. package/services/index.js +16 -8
  68. package/services/key.cjs +104 -0
  69. package/services/key.js +28 -36
  70. package/services/load.cjs +72 -0
  71. package/services/load.js +17 -19
  72. package/services/pointer.cjs +162 -0
  73. package/services/pointer.js +43 -60
  74. package/services/raf.cjs +83 -0
  75. package/services/raf.js +20 -28
  76. package/services/resize.cjs +108 -0
  77. package/services/resize.js +33 -42
  78. package/services/scroll.cjs +131 -0
  79. package/services/scroll.js +26 -35
  80. package/utils/collide/boundingRectToCircle.cjs +34 -0
  81. package/utils/collide/boundingRectToCircle.d.ts +1 -1
  82. package/utils/collide/boundingRectToCircle.js +7 -10
  83. package/utils/collide/collideCircleCircle.cjs +34 -0
  84. package/utils/collide/collideCircleCircle.js +8 -7
  85. package/utils/collide/collideCircleRect.cjs +46 -0
  86. package/utils/collide/collideCircleRect.js +10 -12
  87. package/utils/collide/collidePointCircle.cjs +31 -0
  88. package/utils/collide/collidePointCircle.js +8 -5
  89. package/utils/collide/collidePointRect.cjs +28 -0
  90. package/utils/collide/collidePointRect.js +5 -2
  91. package/utils/collide/collideRectRect.cjs +28 -0
  92. package/utils/collide/collideRectRect.js +5 -2
  93. package/utils/collide/index.cjs +39 -0
  94. package/utils/collide/index.d.ts +6 -7
  95. package/utils/collide/index.js +14 -7
  96. package/utils/css/classes.cjs +47 -0
  97. package/utils/css/classes.d.ts +10 -9
  98. package/utils/css/classes.js +18 -14
  99. package/utils/css/index.cjs +38 -0
  100. package/utils/css/index.d.ts +4 -5
  101. package/utils/css/index.js +13 -5
  102. package/utils/css/matrix.cjs +30 -0
  103. package/utils/css/matrix.js +7 -5
  104. package/utils/css/styles.cjs +44 -0
  105. package/utils/css/styles.d.ts +6 -18
  106. package/utils/css/styles.js +12 -12
  107. package/utils/css/transition.cjs +120 -0
  108. package/utils/css/transition.d.ts +15 -9
  109. package/utils/css/transition.js +70 -119
  110. package/utils/debounce.cjs +34 -0
  111. package/utils/debounce.js +7 -9
  112. package/utils/focusTrap.cjs +82 -0
  113. package/utils/focusTrap.js +30 -21
  114. package/utils/history.cjs +89 -0
  115. package/utils/history.js +28 -57
  116. package/utils/index.cjs +54 -0
  117. package/utils/index.d.ts +14 -35
  118. package/utils/index.js +32 -17
  119. package/utils/keyCodes.cjs +35 -0
  120. package/utils/keyCodes.js +5 -2
  121. package/utils/math/clamp.cjs +28 -0
  122. package/utils/math/clamp.js +5 -2
  123. package/utils/math/clamp01.cjs +32 -0
  124. package/utils/math/clamp01.js +6 -3
  125. package/utils/math/damp.cjs +28 -0
  126. package/utils/math/damp.js +5 -4
  127. package/utils/math/ease.cjs +88 -0
  128. package/utils/math/ease.d.ts +78 -0
  129. package/utils/math/ease.js +66 -0
  130. package/utils/math/index.cjs +43 -0
  131. package/utils/math/index.d.ts +8 -8
  132. package/utils/math/index.js +17 -8
  133. package/utils/math/inertiaFinalValue.cjs +37 -0
  134. package/utils/math/inertiaFinalValue.js +8 -10
  135. package/utils/math/lerp.cjs +28 -0
  136. package/utils/math/lerp.js +5 -2
  137. package/utils/math/map.cjs +28 -0
  138. package/utils/math/map.js +5 -2
  139. package/utils/math/round.cjs +28 -0
  140. package/utils/math/round.js +5 -3
  141. package/utils/memoize.cjs +43 -0
  142. package/utils/memoize.js +10 -19
  143. package/utils/nextFrame.cjs +38 -0
  144. package/utils/nextFrame.d.ts +4 -3
  145. package/utils/nextFrame.js +13 -10
  146. package/utils/nextMicrotask.cjs +28 -0
  147. package/utils/nextMicrotask.d.ts +8 -0
  148. package/utils/nextMicrotask.js +6 -0
  149. package/utils/nextTick.cjs +30 -0
  150. package/utils/nextTick.d.ts +8 -0
  151. package/utils/nextTick.js +8 -0
  152. package/utils/object/autoBind.cjs +49 -0
  153. package/utils/object/autoBind.js +12 -22
  154. package/utils/object/getAllProperties.cjs +37 -0
  155. package/utils/object/getAllProperties.js +10 -13
  156. package/utils/object/index.cjs +33 -0
  157. package/utils/object/index.d.ts +3 -4
  158. package/utils/object/index.js +8 -4
  159. package/utils/object/isObject.cjs +28 -0
  160. package/utils/object/isObject.js +6 -3
  161. package/utils/scrollTo.cjs +80 -0
  162. package/utils/scrollTo.js +20 -40
  163. package/utils/string/index.cjs +47 -0
  164. package/utils/string/index.d.ts +10 -11
  165. package/utils/string/index.js +22 -11
  166. package/utils/string/withLeadingCharacters.cjs +32 -0
  167. package/utils/string/withLeadingCharacters.js +7 -4
  168. package/utils/string/withLeadingSlash.cjs +32 -0
  169. package/utils/string/withLeadingSlash.js +7 -4
  170. package/utils/string/withTrailingCharacters.cjs +32 -0
  171. package/utils/string/withTrailingCharacters.js +7 -4
  172. package/utils/string/withTrailingSlash.cjs +32 -0
  173. package/utils/string/withTrailingSlash.js +7 -4
  174. package/utils/string/withoutLeadingCharacters.cjs +28 -0
  175. package/utils/string/withoutLeadingCharacters.js +6 -3
  176. package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
  177. package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
  178. package/utils/string/withoutLeadingSlash.cjs +32 -0
  179. package/utils/string/withoutLeadingSlash.js +7 -4
  180. package/utils/string/withoutTrailingCharacters.cjs +28 -0
  181. package/utils/string/withoutTrailingCharacters.js +6 -3
  182. package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
  183. package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
  184. package/utils/string/withoutTrailingSlash.cjs +32 -0
  185. package/utils/string/withoutTrailingSlash.js +7 -4
  186. package/utils/throttle.cjs +36 -0
  187. package/utils/throttle.js +9 -9
  188. package/index.modern.js +0 -1
  189. package/index.umd.js +0 -1
package/Base/index.cjs ADDED
@@ -0,0 +1,285 @@
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
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));
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
+ };
26
+
27
+ // packages/js-toolkit/Base/index.js
28
+ var Base_exports = {};
29
+ __export(Base_exports, {
30
+ default: () => Base
31
+ });
32
+ module.exports = __toCommonJS(Base_exports);
33
+ var import_utils = require("./utils.cjs");
34
+ var import_ChildrenManager = __toESM(require("./managers/ChildrenManager.cjs"), 1);
35
+ var import_RefsManager = __toESM(require("./managers/RefsManager.cjs"), 1);
36
+ var import_ServicesManager = __toESM(require("./managers/ServicesManager.cjs"), 1);
37
+ var import_EventsManager = __toESM(require("./managers/EventsManager.cjs"), 1);
38
+ var import_OptionsManager = __toESM(require("./managers/OptionsManager.cjs"), 1);
39
+ var id = 0;
40
+ var isDev = typeof __DEV__ !== "undefined" && __DEV__;
41
+ function noop() {
42
+ }
43
+ var Base = class extends EventTarget {
44
+ constructor(element) {
45
+ super();
46
+ __publicField(this, "$parent", null);
47
+ __publicField(this, "$id");
48
+ __publicField(this, "$el");
49
+ __publicField(this, "$isMounted", false);
50
+ __publicField(this, "__eventHandlers", /* @__PURE__ */ new Map());
51
+ __publicField(this, "__services");
52
+ __publicField(this, "__refs");
53
+ __publicField(this, "__options");
54
+ __publicField(this, "__children");
55
+ __publicField(this, "__events");
56
+ if (!element) {
57
+ throw new Error("The root element must be defined.");
58
+ }
59
+ const { __config } = this;
60
+ if (__config.name === "Base") {
61
+ throw new Error("The `config.name` property is required.");
62
+ }
63
+ this.$id = `${__config.name}-${id}`;
64
+ id += 1;
65
+ this.$el = element;
66
+ if (!this.$el.__base__) {
67
+ this.$el.__base__ = /* @__PURE__ */ new WeakMap();
68
+ }
69
+ this.$el.__base__.set(this.__ctor, this);
70
+ this.__options = new import_OptionsManager.default(element, __config.options || {}, __config);
71
+ this.__services = new import_ServicesManager.default(this);
72
+ this.__events = new import_EventsManager.default(element, this);
73
+ this.__children = new import_ChildrenManager.default(this, element, __config.components || {}, this.__events);
74
+ this.__refs = new import_RefsManager.default(this, element, __config.refs || [], this.__events);
75
+ if (isDev) {
76
+ this.__debug("constructor", this);
77
+ }
78
+ return this;
79
+ }
80
+ get $root() {
81
+ if (!this.$parent) {
82
+ return this;
83
+ }
84
+ let parent = this.$parent;
85
+ let root = this.$parent;
86
+ while (parent) {
87
+ if (!parent.$parent) {
88
+ root = parent;
89
+ }
90
+ parent = parent.$parent;
91
+ }
92
+ return root;
93
+ }
94
+ get __config() {
95
+ let proto = Object.getPrototypeOf(this);
96
+ let { config } = proto.constructor;
97
+ while (proto.constructor.config && proto.constructor.$isBase) {
98
+ config = {
99
+ ...proto.constructor.config,
100
+ ...config
101
+ };
102
+ if (proto.constructor.config.options) {
103
+ config.options = {
104
+ ...proto.constructor.config.options,
105
+ ...config.options
106
+ };
107
+ }
108
+ if (proto.constructor.config.emits && config.emits) {
109
+ config.emits = [...proto.constructor.config.emits, ...config.emits];
110
+ }
111
+ proto = Object.getPrototypeOf(proto);
112
+ }
113
+ return config;
114
+ }
115
+ get $services() {
116
+ return this.__services;
117
+ }
118
+ get $refs() {
119
+ return this.__refs;
120
+ }
121
+ get $options() {
122
+ return this.__options;
123
+ }
124
+ get $children() {
125
+ return this.__children;
126
+ }
127
+ get $log() {
128
+ return this.__options.log ? window.console.log.bind(window, `[${this.__config.name}]`) : noop;
129
+ }
130
+ get __debug() {
131
+ return isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) : noop;
132
+ }
133
+ __callMethod(method, ...args) {
134
+ if (isDev) {
135
+ this.__debug("callMethod", method, ...args);
136
+ }
137
+ this.$emit(method, ...args);
138
+ if (typeof this[method] !== "function") {
139
+ return;
140
+ }
141
+ this[method].call(this, ...args);
142
+ if (isDev) {
143
+ this.__debug(method, this, ...args);
144
+ }
145
+ }
146
+ __hasEvent(event) {
147
+ const eventHandlers = this.__eventHandlers.get(event);
148
+ return eventHandlers && eventHandlers.size > 0;
149
+ }
150
+ $mount() {
151
+ if (this.$isMounted) {
152
+ return this;
153
+ }
154
+ this.$isMounted = true;
155
+ if (isDev) {
156
+ this.__debug("$mount");
157
+ }
158
+ this.$children.registerAll();
159
+ this.$refs.registerAll();
160
+ this.__events.bindRootElement();
161
+ this.$services.enableAll();
162
+ this.$children.mountAll();
163
+ this.__callMethod("mounted");
164
+ return this;
165
+ }
166
+ $update() {
167
+ if (isDev) {
168
+ this.__debug("$update");
169
+ }
170
+ this.$refs.unregisterAll();
171
+ this.$services.disableAll();
172
+ this.$children.registerAll();
173
+ this.$refs.registerAll();
174
+ this.$services.enableAll();
175
+ this.$children.updateAll();
176
+ this.__callMethod("updated");
177
+ return this;
178
+ }
179
+ $destroy() {
180
+ if (!this.$isMounted) {
181
+ return this;
182
+ }
183
+ this.$isMounted = false;
184
+ if (isDev) {
185
+ this.__debug("$destroy");
186
+ }
187
+ this.__events.unbindRootElement();
188
+ this.$refs.unregisterAll();
189
+ this.$services.disableAll();
190
+ this.$children.destroyAll();
191
+ this.__callMethod("destroyed");
192
+ return this;
193
+ }
194
+ $terminate() {
195
+ if (isDev) {
196
+ this.__debug("$terminate");
197
+ }
198
+ this.$destroy();
199
+ this.__callMethod("terminated");
200
+ this.$el.__base__.set(this.__ctor, "terminated");
201
+ }
202
+ __testEventIsDefined(event) {
203
+ if (!(Array.isArray(this.__config.emits) && this.__config.emits.includes(event))) {
204
+ console.warn(`[${this.__config.name}]`, `The "${event}" event is missing from the configuration.`);
205
+ }
206
+ }
207
+ __addEmits(event) {
208
+ const ctor = this.__ctor;
209
+ if (Array.isArray(ctor.config.emits)) {
210
+ ctor.config.emits.push(event);
211
+ } else {
212
+ ctor.config.emits = [event];
213
+ }
214
+ }
215
+ __removeEmits(event) {
216
+ const ctor = this.__ctor;
217
+ const index = ctor.config.emits.findIndex((value) => value === event);
218
+ ctor.config.emits.splice(index, 1);
219
+ }
220
+ get __ctor() {
221
+ return this.constructor;
222
+ }
223
+ $on(event, listener, options) {
224
+ if (isDev) {
225
+ this.__debug("$on", event, listener, options);
226
+ }
227
+ if (isDev) {
228
+ this.__testEventIsDefined(event);
229
+ }
230
+ let set = this.__eventHandlers.get(event);
231
+ if (!set) {
232
+ set = /* @__PURE__ */ new Set();
233
+ this.__eventHandlers.set(event, set);
234
+ }
235
+ set.add(listener);
236
+ this.addEventListener(event, listener, options);
237
+ return () => {
238
+ this.$off(event, listener, options);
239
+ };
240
+ }
241
+ $off(event, listener, options) {
242
+ if (isDev) {
243
+ this.__debug("$off", event, listener);
244
+ }
245
+ if (isDev) {
246
+ this.__testEventIsDefined(event);
247
+ }
248
+ this.__eventHandlers.get(event).delete(listener);
249
+ this.removeEventListener(event, listener, options);
250
+ }
251
+ $emit(event, ...args) {
252
+ if (isDev) {
253
+ this.__debug("$emit", event, args);
254
+ }
255
+ if (isDev) {
256
+ this.__testEventIsDefined(event);
257
+ }
258
+ this.dispatchEvent(new CustomEvent(event, {
259
+ detail: args
260
+ }));
261
+ }
262
+ static $factory(nameOrSelector) {
263
+ if (!nameOrSelector) {
264
+ throw new Error("The $factory method requires a component\u2019s name or selector to be specified.");
265
+ }
266
+ return (0, import_utils.getComponentElements)(nameOrSelector).map((el) => new this(el).$mount());
267
+ }
268
+ };
269
+ __publicField(Base, "$isBase", true);
270
+ __publicField(Base, "config", {
271
+ name: "Base",
272
+ emits: [
273
+ "mounted",
274
+ "updated",
275
+ "destroyed",
276
+ "terminated",
277
+ "ticked",
278
+ "scrolled",
279
+ "resized",
280
+ "moved",
281
+ "loaded",
282
+ "keyed"
283
+ ]
284
+ });
285
+ if (module.exports.default) module.exports = module.exports.default;
package/Base/index.d.ts CHANGED
@@ -57,9 +57,11 @@ export default class Base extends EventTarget {
57
57
  $id: string;
58
58
  /**
59
59
  * The root element.
60
- * @type {HTMLElement}
60
+ * @type {HTMLElement & { __base__?: WeakMap<BaseConstructor, Base | 'terminated'> }}
61
61
  */
62
- $el: HTMLElement;
62
+ $el: HTMLElement & {
63
+ __base__?: WeakMap<BaseConstructor, Base | 'terminated'>;
64
+ };
63
65
  /**
64
66
  * The state of the component.
65
67
  * @type {Boolean}
@@ -199,6 +201,13 @@ export default class Base extends EventTarget {
199
201
  * @returns {void}
200
202
  */
201
203
  private __removeEmits;
204
+ /**
205
+ * Get the instance constructor.
206
+ *
207
+ * @private
208
+ * @returns {BaseConstructor}
209
+ */
210
+ private get __ctor();
202
211
  /**
203
212
  * Bind a listener function to an event.
204
213
  *