@studiometa/js-toolkit 2.0.0-beta.9 → 2.0.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.
- package/Base/index.cjs +284 -0
- package/Base/index.d.ts +36 -28
- package/Base/index.js +113 -197
- package/Base/managers/ChildrenManager.cjs +146 -0
- package/Base/managers/ChildrenManager.d.ts +11 -3
- package/Base/managers/ChildrenManager.js +60 -59
- package/Base/managers/EventsManager.cjs +183 -0
- package/Base/managers/EventsManager.d.ts +13 -20
- package/Base/managers/EventsManager.js +72 -112
- package/Base/managers/OptionsManager.cjs +173 -0
- package/Base/managers/OptionsManager.d.ts +20 -13
- package/Base/managers/OptionsManager.js +60 -91
- package/Base/managers/RefsManager.cjs +99 -0
- package/Base/managers/RefsManager.d.ts +4 -4
- package/Base/managers/RefsManager.js +28 -38
- package/Base/managers/ServicesManager.cjs +134 -0
- package/Base/managers/ServicesManager.d.ts +14 -8
- package/Base/managers/ServicesManager.js +42 -67
- package/Base/utils.cjs +41 -0
- package/Base/utils.d.ts +4 -4
- package/Base/utils.js +12 -11
- package/decorators/index.cjs +45 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +20 -8
- package/decorators/withBreakpointManager.cjs +84 -0
- package/decorators/withBreakpointManager.d.ts +2 -2
- package/decorators/withBreakpointManager.js +18 -40
- package/decorators/withBreakpointObserver.cjs +114 -0
- package/decorators/withBreakpointObserver.d.ts +1 -1
- package/decorators/withBreakpointObserver.js +45 -88
- package/decorators/withDrag.cjs +53 -0
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withDrag.js +24 -26
- package/decorators/withExtraConfig.cjs +43 -0
- package/decorators/withExtraConfig.d.ts +1 -1
- package/decorators/withExtraConfig.js +17 -12
- package/decorators/withFreezedOptions.cjs +37 -0
- package/decorators/withFreezedOptions.d.ts +14 -0
- package/decorators/withFreezedOptions.js +15 -0
- package/decorators/withIntersectionObserver.cjs +61 -0
- package/decorators/withIntersectionObserver.d.ts +1 -1
- package/decorators/withIntersectionObserver.js +29 -33
- package/decorators/withMountWhenInView.cjs +68 -0
- package/decorators/withMountWhenInView.d.ts +1 -1
- package/decorators/withMountWhenInView.js +31 -53
- package/decorators/withScrolledInView.cjs +114 -0
- package/decorators/withScrolledInView.d.ts +1 -1
- package/decorators/withScrolledInView.js +35 -39
- package/decorators/withVue2.cjs +61 -0
- package/decorators/withVue2.js +27 -32
- package/helpers/createApp.cjs +52 -0
- package/helpers/createApp.d.ts +3 -26
- package/helpers/createApp.js +12 -12
- package/helpers/getInstanceFromElement.cjs +32 -0
- package/helpers/getInstanceFromElement.d.ts +14 -0
- package/helpers/getInstanceFromElement.js +10 -0
- package/helpers/importOnInteraction.cjs +52 -0
- package/helpers/importOnInteraction.d.ts +3 -5
- package/helpers/importOnInteraction.js +17 -18
- package/helpers/importWhenIdle.cjs +49 -0
- package/helpers/importWhenIdle.d.ts +3 -5
- package/helpers/importWhenIdle.js +14 -17
- package/helpers/importWhenVisible.cjs +50 -0
- package/helpers/importWhenVisible.d.ts +4 -6
- package/helpers/importWhenVisible.js +16 -18
- package/helpers/index.cjs +37 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +12 -4
- package/helpers/utils.cjs +35 -0
- package/helpers/utils.d.ts +3 -4
- package/helpers/utils.js +7 -6
- package/index.cjs +33 -0
- package/index.js +7 -4
- package/package.json +14 -4
- package/services/Service.cjs +76 -0
- package/services/Service.d.ts +9 -9
- package/services/Service.js +19 -32
- package/services/drag.cjs +212 -0
- package/services/drag.d.ts +3 -2
- package/services/drag.js +64 -69
- package/services/index.cjs +41 -0
- package/services/index.js +16 -7
- package/services/key.cjs +104 -0
- package/services/key.d.ts +1 -1
- package/services/key.js +28 -36
- package/services/load.cjs +72 -0
- package/services/load.d.ts +1 -1
- package/services/load.js +17 -19
- package/services/pointer.cjs +162 -0
- package/services/pointer.d.ts +1 -1
- package/services/pointer.js +43 -60
- package/services/raf.cjs +83 -0
- package/services/raf.d.ts +1 -1
- package/services/raf.js +20 -28
- package/services/resize.cjs +108 -0
- package/services/resize.d.ts +1 -1
- package/services/resize.js +33 -42
- package/services/scroll.cjs +131 -0
- package/services/scroll.d.ts +1 -1
- package/services/scroll.js +26 -35
- package/utils/collide/boundingRectToCircle.cjs +34 -0
- package/utils/collide/boundingRectToCircle.d.ts +6 -6
- package/utils/collide/boundingRectToCircle.js +7 -10
- package/utils/collide/collideCircleCircle.cjs +34 -0
- package/utils/collide/collideCircleCircle.d.ts +4 -4
- package/utils/collide/collideCircleCircle.js +8 -7
- package/utils/collide/collideCircleRect.cjs +46 -0
- package/utils/collide/collideCircleRect.d.ts +8 -8
- package/utils/collide/collideCircleRect.js +10 -12
- package/utils/collide/collidePointCircle.cjs +31 -0
- package/utils/collide/collidePointCircle.d.ts +6 -6
- package/utils/collide/collidePointCircle.js +8 -5
- package/utils/collide/collidePointRect.cjs +28 -0
- package/utils/collide/collidePointRect.d.ts +7 -7
- package/utils/collide/collidePointRect.js +5 -2
- package/utils/collide/collideRectRect.cjs +28 -0
- package/utils/collide/collideRectRect.d.ts +5 -5
- package/utils/collide/collideRectRect.js +5 -2
- package/utils/collide/index.cjs +39 -0
- package/utils/collide/index.js +14 -6
- package/utils/css/classes.cjs +47 -0
- package/utils/css/classes.d.ts +13 -12
- package/utils/css/classes.js +19 -15
- package/utils/css/index.cjs +38 -0
- package/utils/css/index.d.ts +2 -2
- package/utils/css/index.js +13 -6
- package/utils/css/matrix.cjs +30 -0
- package/utils/css/matrix.d.ts +14 -15
- package/utils/css/matrix.js +7 -5
- package/utils/css/styles.cjs +44 -0
- package/utils/css/styles.d.ts +8 -20
- package/utils/css/styles.js +12 -12
- package/utils/css/transition.cjs +120 -0
- package/utils/css/transition.d.ts +15 -9
- package/utils/css/transition.js +70 -119
- package/utils/debounce.cjs +34 -0
- package/utils/debounce.d.ts +4 -4
- package/utils/debounce.js +7 -9
- package/utils/focusTrap.cjs +82 -0
- package/utils/focusTrap.d.ts +1 -0
- package/utils/focusTrap.js +31 -22
- package/utils/history.cjs +89 -0
- package/utils/history.d.ts +13 -11
- package/utils/history.js +28 -57
- package/utils/index.cjs +54 -0
- package/utils/index.d.ts +4 -1
- package/utils/index.js +32 -11
- package/utils/keyCodes.cjs +35 -0
- package/utils/keyCodes.js +5 -2
- package/utils/math/clamp.cjs +28 -0
- package/utils/math/clamp.d.ts +1 -1
- package/utils/math/clamp.js +5 -2
- package/utils/math/clamp01.cjs +32 -0
- package/utils/math/clamp01.d.ts +1 -1
- package/utils/math/clamp01.js +6 -3
- package/utils/math/damp.cjs +28 -0
- package/utils/math/damp.d.ts +6 -6
- package/utils/math/damp.js +5 -4
- package/utils/math/ease.cjs +88 -0
- package/utils/math/ease.d.ts +7 -7
- package/utils/math/ease.js +50 -25
- package/utils/math/index.cjs +43 -0
- package/utils/math/index.js +17 -8
- package/utils/math/inertiaFinalValue.cjs +37 -0
- package/utils/math/inertiaFinalValue.d.ts +5 -5
- package/utils/math/inertiaFinalValue.js +8 -10
- package/utils/math/lerp.cjs +28 -0
- package/utils/math/lerp.d.ts +4 -4
- package/utils/math/lerp.js +5 -2
- package/utils/math/map.cjs +28 -0
- package/utils/math/map.d.ts +6 -6
- package/utils/math/map.js +5 -2
- package/utils/math/round.cjs +28 -0
- package/utils/math/round.d.ts +4 -4
- package/utils/math/round.js +5 -3
- package/utils/memoize.cjs +43 -0
- package/utils/memoize.d.ts +1 -1
- package/utils/memoize.js +10 -19
- package/utils/nextFrame.cjs +38 -0
- package/utils/nextFrame.d.ts +6 -6
- package/utils/nextFrame.js +13 -10
- package/utils/nextMicrotask.cjs +28 -0
- package/utils/nextMicrotask.d.ts +8 -0
- package/utils/nextMicrotask.js +6 -0
- package/utils/nextTick.cjs +30 -0
- package/utils/nextTick.d.ts +8 -0
- package/utils/nextTick.js +8 -0
- package/utils/object/autoBind.cjs +49 -0
- package/utils/object/autoBind.d.ts +3 -3
- package/utils/object/autoBind.js +12 -22
- package/utils/object/getAllProperties.cjs +37 -0
- package/utils/object/getAllProperties.d.ts +3 -3
- package/utils/object/getAllProperties.js +10 -13
- package/utils/object/index.cjs +33 -0
- package/utils/object/index.js +8 -3
- package/utils/object/isObject.cjs +28 -0
- package/utils/object/isObject.d.ts +1 -1
- package/utils/object/isObject.js +6 -3
- package/utils/scrollTo.cjs +80 -0
- package/utils/scrollTo.d.ts +1 -1
- package/utils/scrollTo.js +20 -40
- package/utils/string/index.cjs +47 -0
- package/utils/string/index.js +22 -10
- package/utils/string/withLeadingCharacters.cjs +32 -0
- package/utils/string/withLeadingCharacters.d.ts +3 -2
- package/utils/string/withLeadingCharacters.js +7 -4
- package/utils/string/withLeadingSlash.cjs +32 -0
- package/utils/string/withLeadingSlash.d.ts +1 -1
- package/utils/string/withLeadingSlash.js +7 -4
- package/utils/string/withTrailingCharacters.cjs +32 -0
- package/utils/string/withTrailingCharacters.d.ts +3 -2
- package/utils/string/withTrailingCharacters.js +7 -4
- package/utils/string/withTrailingSlash.cjs +32 -0
- package/utils/string/withTrailingSlash.d.ts +1 -1
- package/utils/string/withTrailingSlash.js +7 -4
- package/utils/string/withoutLeadingCharacters.cjs +28 -0
- package/utils/string/withoutLeadingCharacters.d.ts +3 -2
- package/utils/string/withoutLeadingCharacters.js +6 -3
- package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
- package/utils/string/withoutLeadingSlash.cjs +32 -0
- package/utils/string/withoutLeadingSlash.d.ts +1 -1
- package/utils/string/withoutLeadingSlash.js +7 -4
- package/utils/string/withoutTrailingCharacters.cjs +28 -0
- package/utils/string/withoutTrailingCharacters.d.ts +3 -2
- package/utils/string/withoutTrailingCharacters.js +6 -3
- package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
- package/utils/string/withoutTrailingSlash.cjs +32 -0
- package/utils/string/withoutTrailingSlash.d.ts +1 -1
- package/utils/string/withoutTrailingSlash.js +7 -4
- package/utils/throttle.cjs +36 -0
- package/utils/throttle.d.ts +3 -3
- package/utils/throttle.js +9 -9
- package/index.modern.js +0 -1
- package/index.umd.js +0 -1
|
@@ -1,64 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
import getAllProperties from "../../utils/object/getAllProperties.js";
|
|
8
|
+
import RefsManager from "./RefsManager.js";
|
|
9
|
+
class EventsManager {
|
|
5
10
|
constructor(rootElement, base) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
handleEvent: event => {
|
|
14
|
-
var normalizedEventName = EventsManager.normalizeName(event.type);
|
|
15
|
-
var method = "on".concat(normalizedEventName);
|
|
16
|
-
|
|
11
|
+
__publicField(this, "__rootElement");
|
|
12
|
+
__publicField(this, "__base");
|
|
13
|
+
__publicField(this, "__methodsCache", /* @__PURE__ */ new Map());
|
|
14
|
+
__publicField(this, "__rootElementHandler", {
|
|
15
|
+
handleEvent: (event) => {
|
|
16
|
+
const normalizedEventName = EventsManager.normalizeName(event.type);
|
|
17
|
+
const method = `on${normalizedEventName}`;
|
|
17
18
|
this.__base[method](event);
|
|
18
19
|
}
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var index = 0;
|
|
29
|
-
|
|
21
|
+
__publicField(this, "__refsHandler", {
|
|
22
|
+
handleEvent: (event) => {
|
|
23
|
+
const ref = event.currentTarget;
|
|
24
|
+
const refName = RefsManager.normalizeRefName(ref.dataset.ref);
|
|
25
|
+
const normalizedRefName = EventsManager.normalizeName(refName);
|
|
26
|
+
const normalizedEventName = EventsManager.normalizeName(event.type);
|
|
27
|
+
const method = `on${normalizedRefName}${normalizedEventName}`;
|
|
28
|
+
let index = 0;
|
|
30
29
|
if (Array.isArray(this.__base.$refs[refName])) {
|
|
31
30
|
index = this.__base.$refs[refName].indexOf(ref);
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
this.__base[method](event, index);
|
|
35
33
|
}
|
|
36
34
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
childrenManager.registeredNames.find(name => {
|
|
35
|
+
__publicField(this, "__childrenHandler", {
|
|
36
|
+
handleEvent: (event) => {
|
|
37
|
+
const child = event.currentTarget;
|
|
38
|
+
let childName;
|
|
39
|
+
let index = 0;
|
|
40
|
+
const childrenManager = this.__base.$children;
|
|
41
|
+
childrenManager.registeredNames.find((name) => {
|
|
45
42
|
if (childrenManager[name].includes(child)) {
|
|
46
43
|
childName = name;
|
|
47
44
|
index = childrenManager[name].indexOf(child);
|
|
48
45
|
return true;
|
|
49
46
|
}
|
|
50
|
-
|
|
51
47
|
return false;
|
|
52
48
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
const normalizedRefName = EventsManager.normalizeName(childName);
|
|
50
|
+
const normalizedEventName = EventsManager.normalizeName(event.type);
|
|
51
|
+
const method = `on${normalizedRefName}${normalizedEventName}`;
|
|
52
|
+
const args = Array.isArray(event.detail) ? event.detail : [];
|
|
58
53
|
this.__base[method](...args, index, event);
|
|
59
54
|
}
|
|
60
55
|
});
|
|
61
|
-
|
|
62
56
|
Object.defineProperties(this, {
|
|
63
57
|
__rootElement: {
|
|
64
58
|
enumerable: false,
|
|
@@ -92,108 +86,74 @@ export default class EventsManager {
|
|
|
92
86
|
}
|
|
93
87
|
});
|
|
94
88
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
methods.forEach(method => {
|
|
103
|
-
var event = this.__getEventNameByMethod(method, name);
|
|
104
|
-
|
|
105
|
-
elements.forEach(element => element[action](event, this.__refsHandler));
|
|
89
|
+
__manageRef(name, elements, mode = "add") {
|
|
90
|
+
const action = `${mode}EventListener`;
|
|
91
|
+
const methods = this.__getEventMethodsByName(name);
|
|
92
|
+
methods.forEach((method) => {
|
|
93
|
+
const event = this.__getEventNameByMethod(method, name);
|
|
94
|
+
elements.forEach((element) => element[action](event, this.__refsHandler));
|
|
106
95
|
});
|
|
107
96
|
}
|
|
108
|
-
|
|
109
97
|
bindRef(name, elements) {
|
|
110
98
|
this.__manageRef(name, elements);
|
|
111
99
|
}
|
|
112
|
-
|
|
113
100
|
unbindRef(name, elements) {
|
|
114
|
-
this.__manageRef(name, elements,
|
|
101
|
+
this.__manageRef(name, elements, "remove");
|
|
115
102
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var methods = this.__getEventMethodsByName(name);
|
|
122
|
-
|
|
123
|
-
methods.forEach(method => {
|
|
124
|
-
var event = this.__getEventNameByMethod(method, name);
|
|
125
|
-
|
|
103
|
+
__manageChild(name, instance, mode = "add") {
|
|
104
|
+
const action = mode === "add" ? "$on" : "$off";
|
|
105
|
+
const methods = this.__getEventMethodsByName(name);
|
|
106
|
+
methods.forEach((method) => {
|
|
107
|
+
const event = this.__getEventNameByMethod(method, name);
|
|
126
108
|
instance[action](event, this.__childrenHandler);
|
|
127
109
|
});
|
|
128
110
|
}
|
|
129
|
-
|
|
130
111
|
bindChild(name, instance) {
|
|
131
112
|
this.__manageChild(name, instance);
|
|
132
113
|
}
|
|
133
|
-
|
|
134
114
|
unbindChild(name, instance) {
|
|
135
|
-
this.__manageChild(name, instance,
|
|
115
|
+
this.__manageChild(name, instance, "remove");
|
|
136
116
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
var {
|
|
145
|
-
emits = []
|
|
146
|
-
} = this.__base.__config;
|
|
147
|
-
methods.forEach(method => {
|
|
148
|
-
var event = this.__getEventNameByMethod(method);
|
|
149
|
-
|
|
150
|
-
var target = emits.includes(event) ? this.__base : this.__rootElement;
|
|
117
|
+
__manageRootElement(mode = "add") {
|
|
118
|
+
const modeMethod = `${mode}EventListener`;
|
|
119
|
+
const methods = this.__getEventMethodsByName();
|
|
120
|
+
const { emits = [] } = this.__base.__config;
|
|
121
|
+
methods.forEach((method) => {
|
|
122
|
+
const event = this.__getEventNameByMethod(method);
|
|
123
|
+
const target = emits.includes(event) ? this.__base : this.__rootElement;
|
|
151
124
|
target[modeMethod](event, this.__rootElementHandler);
|
|
152
125
|
});
|
|
153
126
|
}
|
|
154
|
-
|
|
155
127
|
bindRootElement() {
|
|
156
128
|
this.__manageRootElement();
|
|
157
129
|
}
|
|
158
|
-
|
|
159
130
|
unbindRootElement() {
|
|
160
|
-
this.__manageRootElement(
|
|
131
|
+
this.__manageRootElement("remove");
|
|
161
132
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
var regex = new RegExp("^on".concat(normalizedName, "([A-Z].*)$"));
|
|
167
|
-
var [, event] = method.match(regex);
|
|
133
|
+
__getEventNameByMethod(method, name = "") {
|
|
134
|
+
const normalizedName = EventsManager.normalizeName(name);
|
|
135
|
+
const regex = new RegExp(`^on${normalizedName}([A-Z].*)$`);
|
|
136
|
+
const [, event] = method.match(regex);
|
|
168
137
|
return EventsManager.normalizeEventName(event);
|
|
169
138
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var key = regex.toString();
|
|
176
|
-
|
|
177
|
-
var methods = this.__methodsCache.get(key);
|
|
178
|
-
|
|
139
|
+
__getEventMethodsByName(name = "") {
|
|
140
|
+
const normalizedName = EventsManager.normalizeName(name);
|
|
141
|
+
const regex = new RegExp(`^on${normalizedName}[A-Z].*$`);
|
|
142
|
+
const key = regex.toString();
|
|
143
|
+
let methods = this.__methodsCache.get(key);
|
|
179
144
|
if (!methods) {
|
|
180
|
-
methods = Array.from(getAllProperties(this.__base, [], method => regex.test(method)).reduce((set,
|
|
181
|
-
var [method] = _ref;
|
|
182
|
-
return set.add(method);
|
|
183
|
-
}, new Set()));
|
|
184
|
-
|
|
145
|
+
methods = Array.from(getAllProperties(this.__base, [], (method) => regex.test(method)).reduce((set, [method]) => set.add(method), /* @__PURE__ */ new Set()));
|
|
185
146
|
this.__methodsCache.set(key, methods);
|
|
186
147
|
}
|
|
187
|
-
|
|
188
148
|
return methods;
|
|
189
149
|
}
|
|
190
|
-
|
|
191
150
|
static normalizeName(name) {
|
|
192
|
-
return name.replace(/[A-Z]([A-Z].*)/g, c => c.toLowerCase()).replace(/[^a-zA-Z\d\s:]/g,
|
|
151
|
+
return name.replace(/[A-Z]([A-Z].*)/g, (c) => c.toLowerCase()).replace(/[^a-zA-Z\d\s:]/g, " ").replace(/(^\w|\s+\w)/g, (c) => c.trim().toUpperCase()).trim();
|
|
193
152
|
}
|
|
194
|
-
|
|
195
153
|
static normalizeEventName(name) {
|
|
196
|
-
return name.replace(/[A-Z]/g, c =>
|
|
154
|
+
return name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`).replace(/^-/, "");
|
|
197
155
|
}
|
|
198
|
-
|
|
199
|
-
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
EventsManager as default
|
|
159
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
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/managers/OptionsManager.js
|
|
28
|
+
var OptionsManager_exports = {};
|
|
29
|
+
__export(OptionsManager_exports, {
|
|
30
|
+
default: () => OptionsManager
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(OptionsManager_exports);
|
|
33
|
+
var import_deepmerge = __toESM(require("deepmerge"), 1);
|
|
34
|
+
var import_isObject = __toESM(require("../../utils/object/isObject.cjs"), 1);
|
|
35
|
+
var _OptionsManager = class {
|
|
36
|
+
constructor(element, schema, baseConfig) {
|
|
37
|
+
__publicField(this, "__element");
|
|
38
|
+
__publicField(this, "__values", {});
|
|
39
|
+
__publicField(this, "__defaultValues", {
|
|
40
|
+
String: "",
|
|
41
|
+
Number: 0,
|
|
42
|
+
Boolean: false,
|
|
43
|
+
Array: () => [],
|
|
44
|
+
Object: () => ({})
|
|
45
|
+
});
|
|
46
|
+
__publicField(this, "name", "Base");
|
|
47
|
+
__publicField(this, "debug", false);
|
|
48
|
+
__publicField(this, "log", false);
|
|
49
|
+
var _a, _b;
|
|
50
|
+
Object.defineProperties(this, {
|
|
51
|
+
__element: {
|
|
52
|
+
enumerable: false,
|
|
53
|
+
writable: false,
|
|
54
|
+
value: element
|
|
55
|
+
},
|
|
56
|
+
__values: {
|
|
57
|
+
enumerable: false,
|
|
58
|
+
writable: false,
|
|
59
|
+
value: this.__values
|
|
60
|
+
},
|
|
61
|
+
__defaultValues: {
|
|
62
|
+
enumerable: false,
|
|
63
|
+
writable: false,
|
|
64
|
+
value: this.__defaultValues
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
this.name = baseConfig.name;
|
|
68
|
+
schema.debug = {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: (_a = baseConfig.debug) != null ? _a : false
|
|
71
|
+
};
|
|
72
|
+
schema.log = {
|
|
73
|
+
type: Boolean,
|
|
74
|
+
default: (_b = baseConfig.log) != null ? _b : false
|
|
75
|
+
};
|
|
76
|
+
Object.entries(schema).forEach(([name, config]) => {
|
|
77
|
+
this.__register(name, config);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
__register(name, config) {
|
|
81
|
+
const isObjectConfig = typeof config === "object";
|
|
82
|
+
const hasDefaultValue = !_OptionsManager.types.includes(config);
|
|
83
|
+
const type = isObjectConfig ? config.type : config;
|
|
84
|
+
if (!_OptionsManager.types.includes(type)) {
|
|
85
|
+
throw new Error(`The "${name}" option has an invalid type. The allowed types are: String, Number, Boolean, Array and Object.`);
|
|
86
|
+
}
|
|
87
|
+
const defaultValue = hasDefaultValue ? config.default : this.__defaultValues[type.name];
|
|
88
|
+
if ((type === Array || type === Object) && typeof defaultValue !== "function") {
|
|
89
|
+
throw new Error(`The default value for options of type "${type.name}" must be returned by a function.`);
|
|
90
|
+
}
|
|
91
|
+
Object.defineProperty(this, name, {
|
|
92
|
+
get: () => {
|
|
93
|
+
return this.get(name, type, defaultValue, isObjectConfig ? config.merge : void 0);
|
|
94
|
+
},
|
|
95
|
+
set: (value) => {
|
|
96
|
+
this.set(name, type, value, defaultValue);
|
|
97
|
+
},
|
|
98
|
+
enumerable: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
get(name, type, defaultValue, merge) {
|
|
102
|
+
const propertyName = _OptionsManager.__getPropertyName(name);
|
|
103
|
+
const hasProperty = this.__hasProperty(propertyName);
|
|
104
|
+
if (type === Boolean) {
|
|
105
|
+
if (defaultValue) {
|
|
106
|
+
const negatedPropertyName = _OptionsManager.__getPropertyName(name, "No");
|
|
107
|
+
const hasNegatedProperty = this.__hasProperty(negatedPropertyName);
|
|
108
|
+
return !hasNegatedProperty;
|
|
109
|
+
}
|
|
110
|
+
return hasProperty || defaultValue;
|
|
111
|
+
}
|
|
112
|
+
const value = this.__element.dataset[propertyName];
|
|
113
|
+
if (type === Number) {
|
|
114
|
+
return hasProperty ? Number(value) : defaultValue;
|
|
115
|
+
}
|
|
116
|
+
if (type === Array || type === Object) {
|
|
117
|
+
if (!this.__values[name]) {
|
|
118
|
+
let val = hasProperty ? JSON.parse(value) : defaultValue();
|
|
119
|
+
if (typeof merge !== "undefined") {
|
|
120
|
+
val = typeof merge === "boolean" ? (0, import_deepmerge.default)(defaultValue(), val) : (0, import_deepmerge.default)(defaultValue(), val, merge);
|
|
121
|
+
}
|
|
122
|
+
this.__values[name] = val;
|
|
123
|
+
}
|
|
124
|
+
return this.__values[name];
|
|
125
|
+
}
|
|
126
|
+
return hasProperty ? value : defaultValue;
|
|
127
|
+
}
|
|
128
|
+
set(name, type, value, defaultValue) {
|
|
129
|
+
const propertyName = _OptionsManager.__getPropertyName(name);
|
|
130
|
+
if (value.constructor.name !== type.name) {
|
|
131
|
+
const val = Array.isArray(value) || (0, import_isObject.default)(value) ? JSON.stringify(value) : value;
|
|
132
|
+
throw new TypeError(`The "${val}" value for the "${name}" option must be of type "${type.name}"`);
|
|
133
|
+
}
|
|
134
|
+
switch (type) {
|
|
135
|
+
case Boolean:
|
|
136
|
+
if (defaultValue) {
|
|
137
|
+
const negatedPropertyName = _OptionsManager.__getPropertyName(name, "No");
|
|
138
|
+
if (value) {
|
|
139
|
+
delete this.__element.dataset[negatedPropertyName];
|
|
140
|
+
} else {
|
|
141
|
+
this.__element.dataset[negatedPropertyName] = "";
|
|
142
|
+
}
|
|
143
|
+
} else if (value) {
|
|
144
|
+
this.__element.dataset[propertyName] = "";
|
|
145
|
+
} else {
|
|
146
|
+
delete this.__element.dataset[propertyName];
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
case Array:
|
|
150
|
+
case Object:
|
|
151
|
+
this.__values[name] = value;
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
this.__element.dataset[propertyName] = value;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
__hasProperty(prop) {
|
|
158
|
+
return typeof this.__element.dataset[prop] !== "undefined";
|
|
159
|
+
}
|
|
160
|
+
static __getPropertyName(name, prefix = "") {
|
|
161
|
+
const key = name + prefix;
|
|
162
|
+
if (_OptionsManager.__propertyNameCache.has(key)) {
|
|
163
|
+
return _OptionsManager.__propertyNameCache.get(key);
|
|
164
|
+
}
|
|
165
|
+
const propertyName = `option${prefix}${name.replace(/^\w/, (c) => c.toUpperCase())}`;
|
|
166
|
+
_OptionsManager.__propertyNameCache.set(key, propertyName);
|
|
167
|
+
return propertyName;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var OptionsManager = _OptionsManager;
|
|
171
|
+
__publicField(OptionsManager, "types", [String, Number, Boolean, Array, Object]);
|
|
172
|
+
__publicField(OptionsManager, "__propertyNameCache", /* @__PURE__ */ new Map());
|
|
173
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @typedef {import('deepmerge').Options} DeepmergeOptions
|
|
2
3
|
* @typedef {import('../index.js').BaseConfig} BaseConfig
|
|
3
4
|
* @typedef {StringConstructor|NumberConstructor|BooleanConstructor|ArrayConstructor|ObjectConstructor} OptionType
|
|
4
|
-
* @typedef {{
|
|
5
|
-
* @typedef {OptionType |
|
|
5
|
+
* @typedef {{type: OptionType, default: string | number | boolean | (() => Array | Object), merge?: boolean | DeepmergeOptions}} OptionObject
|
|
6
|
+
* @typedef {OptionType | OptionObject} OptionValue
|
|
6
7
|
* @typedef {{ [name:string]: OptionValue }} OptionsSchema
|
|
7
8
|
* @typedef {{ [optionName:string]: any }} OptionsInterface
|
|
8
9
|
*/
|
|
@@ -29,7 +30,8 @@ export default class OptionsManager {
|
|
|
29
30
|
* Get a property name.
|
|
30
31
|
*
|
|
31
32
|
* @param {string} name
|
|
32
|
-
* @
|
|
33
|
+
* @param {string} [prefix]
|
|
34
|
+
* @returns {string}
|
|
33
35
|
* @private
|
|
34
36
|
*/
|
|
35
37
|
private static __getPropertyName;
|
|
@@ -71,7 +73,7 @@ export default class OptionsManager {
|
|
|
71
73
|
debug: boolean;
|
|
72
74
|
/**
|
|
73
75
|
* Default value for the log property.
|
|
74
|
-
* @type {
|
|
76
|
+
* @type {boolean}
|
|
75
77
|
*/
|
|
76
78
|
log: boolean;
|
|
77
79
|
/**
|
|
@@ -79,41 +81,46 @@ export default class OptionsManager {
|
|
|
79
81
|
*
|
|
80
82
|
* @param {string} name
|
|
81
83
|
* @param {OptionValue} config
|
|
82
|
-
* @
|
|
84
|
+
* @returns {void}
|
|
83
85
|
* @private
|
|
84
86
|
*/
|
|
85
87
|
private __register;
|
|
86
88
|
/**
|
|
87
89
|
* Get an option value.
|
|
88
90
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
91
|
+
* @param {string} name The option name.
|
|
92
|
+
* @param {OptionType} type The option data's type.
|
|
93
|
+
* @param {any} defaultValue The default value for this option.
|
|
94
|
+
* @param {boolean|DeepmergeOptions} [merge] Wether to merge the value with the default or not.
|
|
95
|
+
* @returns {any}
|
|
92
96
|
*/
|
|
93
|
-
get(name: string, type: OptionType, defaultValue: any): any;
|
|
97
|
+
get(name: string, type: OptionType, defaultValue: any, merge?: boolean | DeepmergeOptions): any;
|
|
94
98
|
/**
|
|
95
99
|
* Set an option value.
|
|
96
100
|
*
|
|
97
|
-
* @param {
|
|
101
|
+
* @param {string} name The option name.
|
|
98
102
|
* @param {OptionType} type The option data's type.
|
|
99
103
|
* @param {any} value The new value for this option.
|
|
104
|
+
* @param {any} defaultValue The default value for this option.
|
|
100
105
|
*/
|
|
101
106
|
set(name: string, type: OptionType, value: any, defaultValue: any): void;
|
|
102
107
|
/**
|
|
103
108
|
* Test if the element has a given property.
|
|
104
109
|
*
|
|
105
110
|
* @param {string} prop
|
|
106
|
-
* @
|
|
111
|
+
* @returns {boolean}
|
|
107
112
|
*/
|
|
108
113
|
__hasProperty(prop: string): boolean;
|
|
109
114
|
}
|
|
115
|
+
export type DeepmergeOptions = import('deepmerge').Options;
|
|
110
116
|
export type BaseConfig = import('../index.js').BaseConfig;
|
|
111
117
|
export type OptionType = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor;
|
|
112
|
-
export type
|
|
118
|
+
export type OptionObject = {
|
|
113
119
|
type: OptionType;
|
|
114
120
|
default: string | number | boolean | (() => any[] | any);
|
|
121
|
+
merge?: boolean | DeepmergeOptions;
|
|
115
122
|
};
|
|
116
|
-
export type OptionValue = OptionType |
|
|
123
|
+
export type OptionValue = OptionType | OptionObject;
|
|
117
124
|
export type OptionsSchema = {
|
|
118
125
|
[name: string]: OptionValue;
|
|
119
126
|
};
|