@studiometa/js-toolkit 2.0.0-beta.11 → 2.0.0-beta.12

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