@studiometa/js-toolkit 2.0.0-beta.10 → 2.0.0-beta.14

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