@studiometa/js-toolkit 1.7.2 → 2.0.0-alpha.10
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.d.ts +217 -0
- package/Base/index.js +237 -0
- package/Base/managers/ChildrenManager.d.ts +108 -0
- package/Base/managers/ChildrenManager.js +124 -0
- package/Base/managers/EventsManager.d.ts +190 -0
- package/Base/managers/EventsManager.js +195 -0
- package/Base/managers/OptionsManager.d.ts +120 -0
- package/Base/managers/OptionsManager.js +180 -0
- package/Base/managers/RefsManager.d.ts +84 -0
- package/Base/managers/RefsManager.js +83 -0
- package/{abstracts/Base/classes/Services.d.ts → Base/managers/ServicesManager.d.ts} +22 -7
- package/Base/managers/ServicesManager.js +115 -0
- package/{abstracts/Base → Base}/utils.d.ts +0 -30
- package/Base/utils.js +43 -0
- package/README.md +12 -70
- package/decorators/index.js +1 -2
- package/decorators/withBreakpointManager.d.ts +5 -5
- package/decorators/withBreakpointManager.js +41 -79
- package/decorators/withBreakpointObserver.d.ts +4 -4
- package/decorators/withBreakpointObserver.js +54 -77
- package/decorators/withDrag.d.ts +6 -6
- package/decorators/withDrag.js +17 -41
- package/decorators/withExtraConfig.d.ts +6 -6
- package/decorators/withExtraConfig.js +2 -24
- package/decorators/withIntersectionObserver.d.ts +4 -4
- package/decorators/withIntersectionObserver.js +17 -60
- package/decorators/withMountWhenInView.d.ts +8 -8
- package/decorators/withMountWhenInView.js +23 -51
- package/helpers/createApp.d.ts +4 -4
- package/helpers/createApp.js +10 -12
- package/helpers/importOnInteraction.d.ts +6 -6
- package/helpers/importOnInteraction.js +7 -8
- package/helpers/importWhenIdle.d.ts +4 -4
- package/helpers/importWhenIdle.js +7 -8
- package/helpers/importWhenVisible.d.ts +6 -6
- package/helpers/importWhenVisible.js +9 -16
- package/helpers/index.d.ts +1 -3
- package/helpers/index.js +1 -4
- package/helpers/utils.js +2 -3
- package/index.d.ts +19 -5
- package/index.js +5 -6
- package/index.modern.js +1 -3230
- package/index.umd.js +1 -3586
- package/package.json +3 -6
- package/{abstracts → services}/Service.d.ts +0 -0
- package/services/Service.js +63 -0
- package/services/drag.js +144 -180
- package/services/index.js +1 -2
- package/services/key.js +56 -98
- package/services/load.d.ts +1 -1
- package/services/load.js +22 -51
- package/services/pointer.js +118 -157
- package/services/raf.js +37 -65
- package/services/resize.js +46 -98
- package/services/scroll.js +81 -120
- package/utils/collide/boundingRectToCircle.js +7 -6
- package/utils/collide/collideCircleCircle.js +1 -2
- package/utils/collide/collideCircleRect.js +1 -2
- package/utils/collide/collidePointCircle.js +1 -2
- package/utils/collide/collidePointRect.js +1 -2
- package/utils/collide/collideRectRect.js +1 -2
- package/utils/collide/index.js +1 -2
- package/utils/css/classes.js +2 -3
- package/utils/css/index.js +1 -2
- package/utils/css/matrix.js +1 -2
- package/utils/css/styles.js +3 -8
- package/utils/css/transition.js +67 -140
- package/utils/debounce.js +3 -4
- package/utils/focusTrap.js +4 -5
- package/utils/history.js +12 -19
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -2
- package/utils/keyCodes.js +1 -2
- package/utils/math/clamp.js +1 -2
- package/utils/math/clamp01.js +1 -2
- package/utils/math/damp.js +1 -2
- package/utils/math/index.js +1 -2
- package/utils/math/inertiaFinalValue.js +1 -2
- package/utils/math/lerp.js +1 -2
- package/utils/math/map.js +1 -2
- package/utils/math/round.js +1 -2
- package/utils/memoize.d.ts +30 -0
- package/utils/memoize.js +30 -0
- package/utils/nextFrame.js +4 -9
- package/utils/object/autoBind.js +11 -19
- package/utils/object/getAllProperties.d.ts +6 -3
- package/utils/object/getAllProperties.js +10 -8
- package/utils/object/index.js +1 -2
- package/utils/object/isObject.js +2 -4
- package/utils/string/index.js +1 -2
- package/utils/string/withLeadingCharacters.js +1 -2
- package/utils/string/withLeadingSlash.js +1 -2
- package/utils/string/withTrailingCharacters.js +1 -2
- package/utils/string/withTrailingSlash.js +1 -2
- package/utils/string/withoutLeadingCharacters.js +1 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +1 -2
- package/utils/string/withoutLeadingSlash.js +1 -2
- package/utils/string/withoutTrailingCharacters.js +1 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +1 -2
- package/utils/string/withoutTrailingSlash.js +1 -2
- package/utils/throttle.js +2 -3
- package/abstracts/Base/children.d.ts +0 -16
- package/abstracts/Base/children.js +0 -66
- package/abstracts/Base/children.js.map +0 -1
- package/abstracts/Base/classes/Options.d.ts +0 -37
- package/abstracts/Base/classes/Options.js +0 -182
- package/abstracts/Base/classes/Options.js.map +0 -1
- package/abstracts/Base/classes/Services.js +0 -120
- package/abstracts/Base/classes/Services.js.map +0 -1
- package/abstracts/Base/components.d.ts +0 -22
- package/abstracts/Base/components.js +0 -67
- package/abstracts/Base/components.js.map +0 -1
- package/abstracts/Base/events.d.ts +0 -8
- package/abstracts/Base/events.js +0 -185
- package/abstracts/Base/events.js.map +0 -1
- package/abstracts/Base/index.d.ts +0 -176
- package/abstracts/Base/index.js +0 -215
- package/abstracts/Base/index.js.map +0 -1
- package/abstracts/Base/options.d.ts +0 -17
- package/abstracts/Base/options.js +0 -112
- package/abstracts/Base/options.js.map +0 -1
- package/abstracts/Base/refs.d.ts +0 -30
- package/abstracts/Base/refs.js +0 -60
- package/abstracts/Base/refs.js.map +0 -1
- package/abstracts/Base/utils.js +0 -102
- package/abstracts/Base/utils.js.map +0 -1
- package/abstracts/EventManager.d.ts +0 -41
- package/abstracts/EventManager.js +0 -88
- package/abstracts/EventManager.js.map +0 -1
- package/abstracts/Service.js +0 -82
- package/abstracts/Service.js.map +0 -1
- package/abstracts/index.d.ts +0 -4
- package/abstracts/index.js +0 -5
- package/abstracts/index.js.map +0 -1
- package/components/Accordion/Accordion.d.ts +0 -83
- package/components/Accordion/Accordion.js +0 -121
- package/components/Accordion/Accordion.js.map +0 -1
- package/components/Accordion/AccordionItem.d.ts +0 -122
- package/components/Accordion/AccordionItem.js +0 -327
- package/components/Accordion/AccordionItem.js.map +0 -1
- package/components/Accordion/index.d.ts +0 -27
- package/components/Accordion/index.js +0 -39
- package/components/Accordion/index.js.map +0 -1
- package/components/Cursor.d.ts +0 -138
- package/components/Cursor.js +0 -167
- package/components/Cursor.js.map +0 -1
- package/components/Draggable.d.ts +0 -49
- package/components/Draggable.js +0 -77
- package/components/Draggable.js.map +0 -1
- package/components/Modal.d.ts +0 -158
- package/components/Modal.js +0 -270
- package/components/Modal.js.map +0 -1
- package/components/Tabs.d.ts +0 -108
- package/components/Tabs.js +0 -195
- package/components/Tabs.js.map +0 -1
- package/components/index.d.ts +0 -6
- package/components/index.js +0 -7
- package/components/index.js.map +0 -1
- package/decorators/index.js.map +0 -1
- package/decorators/withBreakpointManager.js.map +0 -1
- package/decorators/withBreakpointObserver.js.map +0 -1
- package/decorators/withDrag.js.map +0 -1
- package/decorators/withExtraConfig.js.map +0 -1
- package/decorators/withIntersectionObserver.js.map +0 -1
- package/decorators/withMountWhenInView.js.map +0 -1
- package/full.d.ts +0 -10
- package/full.js +0 -12
- package/full.js.map +0 -1
- package/full.modern.js +0 -7523
- package/full.modern.js.map +0 -1
- package/full.umd.js +0 -8277
- package/full.umd.js.map +0 -1
- package/helpers/createApp.js.map +0 -1
- package/helpers/createBase.d.ts +0 -7
- package/helpers/createBase.js +0 -7
- package/helpers/createBase.js.map +0 -1
- package/helpers/defineComponent.d.ts +0 -11
- package/helpers/defineComponent.js +0 -68
- package/helpers/defineComponent.js.map +0 -1
- package/helpers/importOnInteraction.js.map +0 -1
- package/helpers/importWhenIdle.js.map +0 -1
- package/helpers/importWhenVisible.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/helpers/utils.js.map +0 -1
- package/index.js.map +0 -1
- package/index.modern.js.map +0 -1
- package/index.umd.js.map +0 -1
- package/services/drag.js.map +0 -1
- package/services/index.js.map +0 -1
- package/services/key.js.map +0 -1
- package/services/load.js.map +0 -1
- package/services/pointer.js.map +0 -1
- package/services/raf.js.map +0 -1
- package/services/resize.js.map +0 -1
- package/services/scroll.js.map +0 -1
- package/utils/collide/boundingRectToCircle.js.map +0 -1
- package/utils/collide/collideCircleCircle.js.map +0 -1
- package/utils/collide/collideCircleRect.js.map +0 -1
- package/utils/collide/collidePointCircle.js.map +0 -1
- package/utils/collide/collidePointRect.js.map +0 -1
- package/utils/collide/collideRectRect.js.map +0 -1
- package/utils/collide/index.js.map +0 -1
- package/utils/css/classes.js.map +0 -1
- package/utils/css/index.js.map +0 -1
- package/utils/css/matrix.js.map +0 -1
- package/utils/css/styles.js.map +0 -1
- package/utils/css/transition.js.map +0 -1
- package/utils/debounce.js.map +0 -1
- package/utils/focusTrap.js.map +0 -1
- package/utils/history.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/keyCodes.js.map +0 -1
- package/utils/math/clamp.js.map +0 -1
- package/utils/math/clamp01.js.map +0 -1
- package/utils/math/damp.js.map +0 -1
- package/utils/math/index.js.map +0 -1
- package/utils/math/inertiaFinalValue.js.map +0 -1
- package/utils/math/lerp.js.map +0 -1
- package/utils/math/map.js.map +0 -1
- package/utils/math/round.js.map +0 -1
- package/utils/nextFrame.js.map +0 -1
- package/utils/object/autoBind.js.map +0 -1
- package/utils/object/getAllProperties.js.map +0 -1
- package/utils/object/index.js.map +0 -1
- package/utils/object/isObject.js.map +0 -1
- package/utils/string/index.js.map +0 -1
- package/utils/string/withLeadingCharacters.js.map +0 -1
- package/utils/string/withLeadingSlash.js.map +0 -1
- package/utils/string/withTrailingCharacters.js.map +0 -1
- package/utils/string/withTrailingSlash.js.map +0 -1
- package/utils/string/withoutLeadingCharacters.js.map +0 -1
- package/utils/string/withoutLeadingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutLeadingSlash.js.map +0 -1
- package/utils/string/withoutTrailingCharacters.js.map +0 -1
- package/utils/string/withoutTrailingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutTrailingSlash.js.map +0 -1
- package/utils/throttle.js.map +0 -1
package/index.umd.js
CHANGED
|
@@ -1,3586 +1 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = global || self, factory(global.Base = {}));
|
|
5
|
-
}(this, (function (exports) {
|
|
6
|
-
function _defineProperties(target, props) {
|
|
7
|
-
for (var i = 0; i < props.length; i++) {
|
|
8
|
-
var descriptor = props[i];
|
|
9
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
-
descriptor.configurable = true;
|
|
11
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
17
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
18
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
19
|
-
return Constructor;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function _extends() {
|
|
23
|
-
_extends = Object.assign || function (target) {
|
|
24
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
25
|
-
var source = arguments[i];
|
|
26
|
-
|
|
27
|
-
for (var key in source) {
|
|
28
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
29
|
-
target[key] = source[key];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return _extends.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function _inheritsLoose(subClass, superClass) {
|
|
41
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
42
|
-
subClass.prototype.constructor = subClass;
|
|
43
|
-
|
|
44
|
-
_setPrototypeOf(subClass, superClass);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function _setPrototypeOf(o, p) {
|
|
48
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
49
|
-
o.__proto__ = p;
|
|
50
|
-
return o;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return _setPrototypeOf(o, p);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
57
|
-
if (source == null) return {};
|
|
58
|
-
var target = {};
|
|
59
|
-
var sourceKeys = Object.keys(source);
|
|
60
|
-
var key, i;
|
|
61
|
-
|
|
62
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
63
|
-
key = sourceKeys[i];
|
|
64
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
65
|
-
target[key] = source[key];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return target;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function _assertThisInitialized(self) {
|
|
72
|
-
if (self === void 0) {
|
|
73
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return self;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
80
|
-
if (!o) return;
|
|
81
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
82
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
83
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
84
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
85
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function _arrayLikeToArray(arr, len) {
|
|
89
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
90
|
-
|
|
91
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
92
|
-
|
|
93
|
-
return arr2;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
97
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
98
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
99
|
-
|
|
100
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
101
|
-
if (it) o = it;
|
|
102
|
-
var i = 0;
|
|
103
|
-
return function () {
|
|
104
|
-
if (i >= o.length) return {
|
|
105
|
-
done: true
|
|
106
|
-
};
|
|
107
|
-
return {
|
|
108
|
-
done: false,
|
|
109
|
-
value: o[i++]
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
var id$1 = 0;
|
|
118
|
-
|
|
119
|
-
function _classPrivateFieldLooseKey(name) {
|
|
120
|
-
return "__private_" + id$1++ + "_" + name;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function _classPrivateFieldLooseBase(receiver, privateKey) {
|
|
124
|
-
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
|
125
|
-
throw new TypeError("attempted to use private field on non-instance");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return receiver;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Gets all non-builtin properties up the prototype chain.
|
|
133
|
-
*
|
|
134
|
-
* @param {Object} object The object to get the propeties from.
|
|
135
|
-
* @param {Array=} [props=[]] The already existing properties.
|
|
136
|
-
* @return {Array<[String, Object]>} An array of properties and the prototype they belong to.
|
|
137
|
-
*/
|
|
138
|
-
function getAllProperties(object, props) {
|
|
139
|
-
if (props === void 0) {
|
|
140
|
-
props = [];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
var proto = Object.getPrototypeOf(object);
|
|
144
|
-
|
|
145
|
-
if (proto === Object.prototype) {
|
|
146
|
-
return props;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return getAllProperties(proto, Object.getOwnPropertyNames(proto).map(function (name) {
|
|
150
|
-
return [name, proto];
|
|
151
|
-
}).reduce(function (acc, val) {
|
|
152
|
-
return [].concat(acc, [val]);
|
|
153
|
-
}, props));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Auto-bind methods to an instance.
|
|
158
|
-
*
|
|
159
|
-
* @param {Object} instance The instance.
|
|
160
|
-
* @param {Object} options Define specific methods to include or exlude.
|
|
161
|
-
* @param {Array<String|RegExp>} [options.include] Methods to include.
|
|
162
|
-
* @param {Array<String|RegExp>} [options.exclude] Methods to exclude.
|
|
163
|
-
* @return {Object} The instance.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
function autoBind(instance, options) {
|
|
167
|
-
var _ref = options || {},
|
|
168
|
-
exclude = _ref.exclude,
|
|
169
|
-
include = _ref.include;
|
|
170
|
-
|
|
171
|
-
var filter = function filter(key) {
|
|
172
|
-
var match = function match(pattern) {
|
|
173
|
-
return typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
if (include) {
|
|
177
|
-
return include.some(match);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (exclude) {
|
|
181
|
-
return !exclude.some(match);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return true;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
getAllProperties(instance).filter(function (_ref2) {
|
|
188
|
-
var key = _ref2[0];
|
|
189
|
-
return key !== 'constructor' && filter(key);
|
|
190
|
-
}).forEach(function (_ref3) {
|
|
191
|
-
var key = _ref3[0],
|
|
192
|
-
object = _ref3[1];
|
|
193
|
-
var descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
194
|
-
|
|
195
|
-
if (descriptor && typeof descriptor.value === 'function') {
|
|
196
|
-
instance[key] = instance[key].bind(instance);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
return instance;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/* eslint no-underscore-dangle: ["error", { "allow": ["_events"] }] */
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Event management class.
|
|
206
|
-
*/
|
|
207
|
-
var EventManager = /*#__PURE__*/function () {
|
|
208
|
-
function EventManager() {
|
|
209
|
-
this._events = {};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
var _proto = EventManager.prototype;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Bind a listener function to an event.
|
|
216
|
-
*
|
|
217
|
-
* @param {String} event Name of the event.
|
|
218
|
-
* @param {Function} listener Function to be called.
|
|
219
|
-
* @return {Function} A function to unbind the listener.
|
|
220
|
-
*/
|
|
221
|
-
_proto.$on = function $on(event, listener) {
|
|
222
|
-
var _this = this;
|
|
223
|
-
|
|
224
|
-
if (!Array.isArray(this._events[event])) {
|
|
225
|
-
this._events[event] = [];
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
this._events[event].push(listener);
|
|
229
|
-
|
|
230
|
-
return function () {
|
|
231
|
-
_this.$off(event, listener);
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Unbind a listener function from an event.
|
|
236
|
-
*
|
|
237
|
-
* @param {String} event Name of the event.
|
|
238
|
-
* @param {Function} listener Function to be removed.
|
|
239
|
-
* @return {EventManager} The current instance.
|
|
240
|
-
*/
|
|
241
|
-
;
|
|
242
|
-
|
|
243
|
-
_proto.$off = function $off(event, listener) {
|
|
244
|
-
// If no event specified, we remove them all.
|
|
245
|
-
if (!event) {
|
|
246
|
-
this._events = {};
|
|
247
|
-
return this;
|
|
248
|
-
} // If no listener have been specified, we remove all
|
|
249
|
-
// the listeners for the given event.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (!listener) {
|
|
253
|
-
this._events[event] = [];
|
|
254
|
-
return this;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
var index = this._events[event].indexOf(listener);
|
|
258
|
-
|
|
259
|
-
if (index > -1) {
|
|
260
|
-
this._events[event].splice(index, 1);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return this;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Emits an event.
|
|
267
|
-
*
|
|
268
|
-
* @param {String} event Name of the event.
|
|
269
|
-
* @param {Array} args The arguments to apply to the functions bound to this event.
|
|
270
|
-
* @return {EventManager} The current instance.
|
|
271
|
-
*/
|
|
272
|
-
;
|
|
273
|
-
|
|
274
|
-
_proto.$emit = function $emit(event) {
|
|
275
|
-
var _arguments = arguments,
|
|
276
|
-
_this2 = this;
|
|
277
|
-
|
|
278
|
-
if (!Array.isArray(this._events[event])) {
|
|
279
|
-
return this;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
this._events[event].forEach(function (listener) {
|
|
283
|
-
listener.apply(_this2, [].slice.call(_arguments, 1));
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
return this;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Bind a listener function to an event for one execution only.
|
|
290
|
-
*
|
|
291
|
-
* @param {String} event Name of the event.
|
|
292
|
-
* @param {Function} listener Function to be called.
|
|
293
|
-
* @return {EventManager} The current instance.
|
|
294
|
-
*/
|
|
295
|
-
;
|
|
296
|
-
|
|
297
|
-
_proto.$once = function $once(event, listener) {
|
|
298
|
-
var instance = this;
|
|
299
|
-
this.$on(event,
|
|
300
|
-
/**
|
|
301
|
-
* @param {...any} args
|
|
302
|
-
*/
|
|
303
|
-
function handler() {
|
|
304
|
-
instance.$off(event, handler);
|
|
305
|
-
listener.apply(instance, [].slice.call(arguments));
|
|
306
|
-
});
|
|
307
|
-
return this;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
return EventManager;
|
|
311
|
-
}();
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* @typedef {import('./index.js').default} Base
|
|
315
|
-
* @typedef {import('./index.js').BaseConfig} BaseConfig
|
|
316
|
-
*/
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Get the config from a Base instance, either the new static one or the old getter one.
|
|
320
|
-
*
|
|
321
|
-
* @param {Base} instance The instance to get the config from.
|
|
322
|
-
* @return {BaseConfig} A Base class configuration object.
|
|
323
|
-
*/
|
|
324
|
-
function getConfig(instance) {
|
|
325
|
-
// @ts-ignore
|
|
326
|
-
var config = instance.constructor.config || instance.config;
|
|
327
|
-
|
|
328
|
-
if (!config) {
|
|
329
|
-
throw new Error('The `config` property must be defined.');
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (!config.name) {
|
|
333
|
-
throw new Error('The `config.name` property is required.');
|
|
334
|
-
} // @ts-ignore
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (instance.config && !instance.constructor.config) {
|
|
338
|
-
console.warn("[" + config.name + "]", 'Defining the `config` as a getter is deprecated, replace it with a static property.');
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return config;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Display a console warning for the given instance.
|
|
345
|
-
*
|
|
346
|
-
* @param {Base} instance A Base instance.
|
|
347
|
-
* @param {...String} msg Values to display in the console.
|
|
348
|
-
*/
|
|
349
|
-
|
|
350
|
-
function warn(instance) {
|
|
351
|
-
var _console;
|
|
352
|
-
|
|
353
|
-
var _getConfig = getConfig(instance),
|
|
354
|
-
name = _getConfig.name;
|
|
355
|
-
|
|
356
|
-
(_console = console).warn.apply(_console, ["[" + name + "]"].concat([].slice.call(arguments, 1)));
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Display a console log for the given instance.
|
|
360
|
-
*
|
|
361
|
-
* @param {Base} instance The instance to log information from.
|
|
362
|
-
* @param {...any} msg The data to print to the console.
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
|
-
function log(instance) {
|
|
366
|
-
var _console2;
|
|
367
|
-
|
|
368
|
-
var _getConfig2 = getConfig(instance),
|
|
369
|
-
name = _getConfig2.name;
|
|
370
|
-
|
|
371
|
-
(_console2 = console).log.apply(_console2, ["[" + name + "]"].concat([].slice.call(arguments, 1)));
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Verbose debug for the component.
|
|
375
|
-
*
|
|
376
|
-
* @param {Base} instance The instance to debug.
|
|
377
|
-
* @param {...any} args The data to print.
|
|
378
|
-
*/
|
|
379
|
-
|
|
380
|
-
function debug(instance) {
|
|
381
|
-
if (instance.$options.debug) {
|
|
382
|
-
log.apply(void 0, [instance, '[debug]'].concat([].slice.call(arguments, 1)));
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Test if an object has a method.
|
|
387
|
-
*
|
|
388
|
-
* @param {Object} obj The object to test
|
|
389
|
-
* @param {String} name The method's name
|
|
390
|
-
* @return {Boolean}
|
|
391
|
-
*/
|
|
392
|
-
|
|
393
|
-
function hasMethod(obj, name) {
|
|
394
|
-
return typeof obj[name] === 'function';
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Call the given method while applying the given arguments.
|
|
398
|
-
*
|
|
399
|
-
* @param {Base} instance The Base instance on which to trigger the method.
|
|
400
|
-
* @param {String} method The method to call.
|
|
401
|
-
* @param {...any} args The arguments to pass to the method.
|
|
402
|
-
*/
|
|
403
|
-
|
|
404
|
-
function callMethod(instance, method) {
|
|
405
|
-
var _instance$method;
|
|
406
|
-
|
|
407
|
-
var args = [].slice.call(arguments, 2);
|
|
408
|
-
|
|
409
|
-
if (__DEV__) {
|
|
410
|
-
debug.apply(void 0, [instance, 'callMethod', method].concat(args));
|
|
411
|
-
} // Prevent duplicate call of `mounted` and `destroyed`
|
|
412
|
-
// methods based on the component status
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (method === 'destroyed' && !instance.$isMounted || method === 'mounted' && instance.$isMounted) {
|
|
416
|
-
if (__DEV__) {
|
|
417
|
-
debug(instance, 'not', method, 'because the method has already been triggered once.');
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
return instance;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
instance.$emit.apply(instance, [method].concat(args)); // We always emit an event, but we do not call the method if it does not exist
|
|
424
|
-
|
|
425
|
-
if (!hasMethod(instance, method)) {
|
|
426
|
-
return instance;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
(_instance$method = instance[method]).call.apply(_instance$method, [instance].concat(args));
|
|
430
|
-
|
|
431
|
-
if (__DEV__) {
|
|
432
|
-
debug.apply(void 0, [instance, method, instance].concat(args));
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return instance;
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Get a list of elements based on the name of a component.
|
|
439
|
-
*
|
|
440
|
-
* @param {String} nameOrSelector
|
|
441
|
-
* The name or selector to used for this component.
|
|
442
|
-
* @param {HTMLElement|Document} element
|
|
443
|
-
* The root element on which to query the selector, defaults to `document`.
|
|
444
|
-
* @return {Array<HTMLElement>}
|
|
445
|
-
* A list of elements on which the component should be mounted.
|
|
446
|
-
*/
|
|
447
|
-
|
|
448
|
-
function getComponentElements(nameOrSelector, element) {
|
|
449
|
-
if (element === void 0) {
|
|
450
|
-
element = document;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
var selector = "[data-component=\"" + nameOrSelector + "\"]";
|
|
454
|
-
var elements = [];
|
|
455
|
-
|
|
456
|
-
try {
|
|
457
|
-
elements = Array.from(element.querySelectorAll(selector)); // eslint-disable-next-line no-empty
|
|
458
|
-
} catch (_unused) {} // If no child component found with the default selector, try a classic DOM selector
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (elements.length === 0) {
|
|
462
|
-
elements = Array.from(element.querySelectorAll(nameOrSelector));
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return elements;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* @typedef {import('./index.js').default} Base
|
|
470
|
-
* @typedef {import('./index.js').BaseComponent} BaseComponent
|
|
471
|
-
* @typedef {import('./index.js').BaseAsyncComponent} BaseAsyncComponent
|
|
472
|
-
* @typedef {import('./index.js').BaseConfigComponents} BaseConfigComponents
|
|
473
|
-
*/
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Get a child component.
|
|
477
|
-
*
|
|
478
|
-
* @param {HTMLElement & { __base__?: Base | 'terminated' }} el
|
|
479
|
-
* The root element of the child component.
|
|
480
|
-
* @param {BaseComponent|BaseAsyncComponent} ComponentClass
|
|
481
|
-
* A Base class or a Promise for async components.
|
|
482
|
-
* @param {Base} parent
|
|
483
|
-
* The parent component instance.
|
|
484
|
-
* @return {Base|Promise|'terminated'}
|
|
485
|
-
* A Base instance or a Promise resolving to a Base instance.
|
|
486
|
-
*/
|
|
487
|
-
|
|
488
|
-
function getChild(el, ComponentClass, parent) {
|
|
489
|
-
// Return existing instance if it exists
|
|
490
|
-
if (el.__base__) {
|
|
491
|
-
return el.__base__;
|
|
492
|
-
} // Return a new instance if the component class is a child of the Base class
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if ('$isBase' in ComponentClass) {
|
|
496
|
-
var child = new ComponentClass(el);
|
|
497
|
-
Object.defineProperty(child, '$parent', {
|
|
498
|
-
get: function get() {
|
|
499
|
-
return parent;
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
return child;
|
|
503
|
-
} // Resolve async components
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
return ComponentClass(parent).then(function (module) {
|
|
507
|
-
var _module$default;
|
|
508
|
-
|
|
509
|
-
// @ts-ignore
|
|
510
|
-
return getChild(el, (_module$default = module.default) != null ? _module$default : module, parent);
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Get child components.
|
|
515
|
-
* @param {Base} instance The component's instance.
|
|
516
|
-
* @param {HTMLElement} element The component's root element
|
|
517
|
-
* @param {BaseConfigComponents} components The children components' classes
|
|
518
|
-
* @return {null|Object} Returns `null` if no child components are defined or an object of all child component instances
|
|
519
|
-
*/
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
function getChildren(instance, element, components) {
|
|
523
|
-
if (__DEV__) {
|
|
524
|
-
debug(instance, 'before:getChildren', element, components);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
var children = Object.entries(components).reduce(function (acc, _ref) {
|
|
528
|
-
var name = _ref[0],
|
|
529
|
-
ComponentClass = _ref[1];
|
|
530
|
-
Object.defineProperty(acc, name, {
|
|
531
|
-
get: function get() {
|
|
532
|
-
var elements = getComponentElements(name, element);
|
|
533
|
-
|
|
534
|
-
if (elements.length === 0) {
|
|
535
|
-
return [];
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
return elements.map(function (el) {
|
|
539
|
-
return getChild(el, ComponentClass, instance);
|
|
540
|
-
}) // Filter out terminated children
|
|
541
|
-
// @ts-ignore
|
|
542
|
-
.filter(function (el) {
|
|
543
|
-
return el !== 'terminated';
|
|
544
|
-
});
|
|
545
|
-
},
|
|
546
|
-
enumerable: true,
|
|
547
|
-
configurable: true
|
|
548
|
-
});
|
|
549
|
-
return acc;
|
|
550
|
-
}, {});
|
|
551
|
-
instance.$emit('get:children', children);
|
|
552
|
-
|
|
553
|
-
if (__DEV__) {
|
|
554
|
-
debug(instance, 'after:getChildren', children);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
return children;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
var isMergeableObject = function isMergeableObject(value) {
|
|
561
|
-
return isNonNullObject(value)
|
|
562
|
-
&& !isSpecial(value)
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
function isNonNullObject(value) {
|
|
566
|
-
return !!value && typeof value === 'object'
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function isSpecial(value) {
|
|
570
|
-
var stringValue = Object.prototype.toString.call(value);
|
|
571
|
-
|
|
572
|
-
return stringValue === '[object RegExp]'
|
|
573
|
-
|| stringValue === '[object Date]'
|
|
574
|
-
|| isReactElement(value)
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25
|
|
578
|
-
var canUseSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
579
|
-
var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;
|
|
580
|
-
|
|
581
|
-
function isReactElement(value) {
|
|
582
|
-
return value.$$typeof === REACT_ELEMENT_TYPE
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
function emptyTarget(val) {
|
|
586
|
-
return Array.isArray(val) ? [] : {}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
function cloneUnlessOtherwiseSpecified(value, options) {
|
|
590
|
-
return (options.clone !== false && options.isMergeableObject(value))
|
|
591
|
-
? deepmerge(emptyTarget(value), value, options)
|
|
592
|
-
: value
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
function defaultArrayMerge(target, source, options) {
|
|
596
|
-
return target.concat(source).map(function(element) {
|
|
597
|
-
return cloneUnlessOtherwiseSpecified(element, options)
|
|
598
|
-
})
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
function getMergeFunction(key, options) {
|
|
602
|
-
if (!options.customMerge) {
|
|
603
|
-
return deepmerge
|
|
604
|
-
}
|
|
605
|
-
var customMerge = options.customMerge(key);
|
|
606
|
-
return typeof customMerge === 'function' ? customMerge : deepmerge
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
function getEnumerableOwnPropertySymbols(target) {
|
|
610
|
-
return Object.getOwnPropertySymbols
|
|
611
|
-
? Object.getOwnPropertySymbols(target).filter(function(symbol) {
|
|
612
|
-
return target.propertyIsEnumerable(symbol)
|
|
613
|
-
})
|
|
614
|
-
: []
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
function getKeys(target) {
|
|
618
|
-
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target))
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
function propertyIsOnObject(object, property) {
|
|
622
|
-
try {
|
|
623
|
-
return property in object
|
|
624
|
-
} catch(_) {
|
|
625
|
-
return false
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
// Protects from prototype poisoning and unexpected merging up the prototype chain.
|
|
630
|
-
function propertyIsUnsafe(target, key) {
|
|
631
|
-
return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,
|
|
632
|
-
&& !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,
|
|
633
|
-
&& Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable.
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
function mergeObject(target, source, options) {
|
|
637
|
-
var destination = {};
|
|
638
|
-
if (options.isMergeableObject(target)) {
|
|
639
|
-
getKeys(target).forEach(function(key) {
|
|
640
|
-
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
getKeys(source).forEach(function(key) {
|
|
644
|
-
if (propertyIsUnsafe(target, key)) {
|
|
645
|
-
return
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
|
|
649
|
-
destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
|
|
650
|
-
} else {
|
|
651
|
-
destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
return destination
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
function deepmerge(target, source, options) {
|
|
658
|
-
options = options || {};
|
|
659
|
-
options.arrayMerge = options.arrayMerge || defaultArrayMerge;
|
|
660
|
-
options.isMergeableObject = options.isMergeableObject || isMergeableObject;
|
|
661
|
-
// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()
|
|
662
|
-
// implementations can use it. The caller may not replace it.
|
|
663
|
-
options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
|
|
664
|
-
|
|
665
|
-
var sourceIsArray = Array.isArray(source);
|
|
666
|
-
var targetIsArray = Array.isArray(target);
|
|
667
|
-
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
|
|
668
|
-
|
|
669
|
-
if (!sourceAndTargetTypesMatch) {
|
|
670
|
-
return cloneUnlessOtherwiseSpecified(source, options)
|
|
671
|
-
} else if (sourceIsArray) {
|
|
672
|
-
return options.arrayMerge(target, source, options)
|
|
673
|
-
} else {
|
|
674
|
-
return mergeObject(target, source, options)
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
deepmerge.all = function deepmergeAll(array, options) {
|
|
679
|
-
if (!Array.isArray(array)) {
|
|
680
|
-
throw new Error('first argument should be an array')
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
return array.reduce(function(prev, next) {
|
|
684
|
-
return deepmerge(prev, next, options)
|
|
685
|
-
}, {})
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
var deepmerge_1 = deepmerge;
|
|
689
|
-
|
|
690
|
-
var cjs = deepmerge_1;
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
|
|
694
|
-
*/
|
|
695
|
-
/**
|
|
696
|
-
* Lower case as a function.
|
|
697
|
-
*/
|
|
698
|
-
function lowerCase(str) {
|
|
699
|
-
return str.toLowerCase();
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
|
703
|
-
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
704
|
-
// Remove all non-word characters.
|
|
705
|
-
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
706
|
-
/**
|
|
707
|
-
* Normalize the string into something other libraries can manipulate easier.
|
|
708
|
-
*/
|
|
709
|
-
function noCase(input, options) {
|
|
710
|
-
if (options === void 0) { options = {}; }
|
|
711
|
-
var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
|
|
712
|
-
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
713
|
-
var start = 0;
|
|
714
|
-
var end = result.length;
|
|
715
|
-
// Trim the delimiter from around the output string.
|
|
716
|
-
while (result.charAt(start) === "\0")
|
|
717
|
-
start++;
|
|
718
|
-
while (result.charAt(end - 1) === "\0")
|
|
719
|
-
end--;
|
|
720
|
-
// Transform each token independently.
|
|
721
|
-
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Replace `re` in the input string with the replacement value.
|
|
725
|
-
*/
|
|
726
|
-
function replace(input, re, value) {
|
|
727
|
-
if (re instanceof RegExp)
|
|
728
|
-
return input.replace(re, value);
|
|
729
|
-
return re.reduce(function (input, re) { return input.replace(re, value); }, input);
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
var copyProperty = function copyProperty(to, from, property, ignoreNonConfigurable) {
|
|
733
|
-
// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
|
|
734
|
-
// `Function#prototype` is non-writable and non-configurable so can never be modified.
|
|
735
|
-
if (property === 'length' || property === 'prototype') {
|
|
736
|
-
return;
|
|
737
|
-
} // `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here.
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
if (property === 'arguments' || property === 'caller') {
|
|
741
|
-
return;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
var toDescriptor = Object.getOwnPropertyDescriptor(to, property);
|
|
745
|
-
var fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
|
|
746
|
-
|
|
747
|
-
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
Object.defineProperty(to, property, fromDescriptor);
|
|
752
|
-
}; // `Object.defineProperty()` throws if the property exists, is not configurable and either:
|
|
753
|
-
// - one its descriptors is changed
|
|
754
|
-
// - it is non-writable and its value is changed
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
var canCopyProperty = function canCopyProperty(toDescriptor, fromDescriptor) {
|
|
758
|
-
return toDescriptor === undefined || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
var changePrototype = function changePrototype(to, from) {
|
|
762
|
-
var fromPrototype = Object.getPrototypeOf(from);
|
|
763
|
-
|
|
764
|
-
if (fromPrototype === Object.getPrototypeOf(to)) {
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
Object.setPrototypeOf(to, fromPrototype);
|
|
769
|
-
};
|
|
770
|
-
|
|
771
|
-
var wrappedToString = function wrappedToString(withName, fromBody) {
|
|
772
|
-
return "/* Wrapped " + withName + "*/\n" + fromBody;
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
var toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
|
|
776
|
-
var toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name'); // We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
|
|
777
|
-
// We use `bind()` instead of a closure for the same reason.
|
|
778
|
-
// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
|
|
779
|
-
|
|
780
|
-
var changeToString = function changeToString(to, from, name) {
|
|
781
|
-
var withName = name === '' ? '' : "with " + name.trim() + "() ";
|
|
782
|
-
var newToString = wrappedToString.bind(null, withName, from.toString()); // Ensure `to.toString.toString` is non-enumerable and has the same `same`
|
|
783
|
-
|
|
784
|
-
Object.defineProperty(newToString, 'name', toStringName);
|
|
785
|
-
Object.defineProperty(to, 'toString', _extends({}, toStringDescriptor, {
|
|
786
|
-
value: newToString
|
|
787
|
-
}));
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
function mimicFunction(to, from, _temp) {
|
|
791
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
792
|
-
_ref$ignoreNonConfigu = _ref.ignoreNonConfigurable,
|
|
793
|
-
ignoreNonConfigurable = _ref$ignoreNonConfigu === void 0 ? false : _ref$ignoreNonConfigu;
|
|
794
|
-
|
|
795
|
-
var name = to.name;
|
|
796
|
-
|
|
797
|
-
for (var _iterator = _createForOfIteratorHelperLoose(Reflect.ownKeys(from)), _step; !(_step = _iterator()).done;) {
|
|
798
|
-
var property = _step.value;
|
|
799
|
-
copyProperty(to, from, property, ignoreNonConfigurable);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
changePrototype(to, from);
|
|
803
|
-
changeToString(to, from, name);
|
|
804
|
-
return to;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
808
|
-
|
|
809
|
-
function getDefaultExportFromCjs (x) {
|
|
810
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
function createCommonjsModule(fn) {
|
|
814
|
-
var module = { exports: {} };
|
|
815
|
-
return fn(module, module.exports), module.exports;
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
var pDefer = () => {
|
|
819
|
-
const ret = {};
|
|
820
|
-
|
|
821
|
-
ret.promise = new Promise((resolve, reject) => {
|
|
822
|
-
ret.resolve = resolve;
|
|
823
|
-
ret.reject = reject;
|
|
824
|
-
});
|
|
825
|
-
|
|
826
|
-
return ret;
|
|
827
|
-
};
|
|
828
|
-
|
|
829
|
-
var dist = createCommonjsModule(function (module, exports) {
|
|
830
|
-
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
831
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
832
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
833
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
834
|
-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
835
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
836
|
-
});
|
|
837
|
-
};
|
|
838
|
-
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
839
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
840
|
-
};
|
|
841
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
842
|
-
const p_defer_1 = __importDefault(pDefer);
|
|
843
|
-
function mapAgeCleaner(map, property = 'maxAge') {
|
|
844
|
-
let processingKey;
|
|
845
|
-
let processingTimer;
|
|
846
|
-
let processingDeferred;
|
|
847
|
-
const cleanup = () => __awaiter(this, void 0, void 0, function* () {
|
|
848
|
-
if (processingKey !== undefined) {
|
|
849
|
-
// If we are already processing an item, we can safely exit
|
|
850
|
-
return;
|
|
851
|
-
}
|
|
852
|
-
const setupTimer = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
853
|
-
processingDeferred = p_defer_1.default();
|
|
854
|
-
const delay = item[1][property] - Date.now();
|
|
855
|
-
if (delay <= 0) {
|
|
856
|
-
// Remove the item immediately if the delay is equal to or below 0
|
|
857
|
-
map.delete(item[0]);
|
|
858
|
-
processingDeferred.resolve();
|
|
859
|
-
return;
|
|
860
|
-
}
|
|
861
|
-
// Keep track of the current processed key
|
|
862
|
-
processingKey = item[0];
|
|
863
|
-
processingTimer = setTimeout(() => {
|
|
864
|
-
// Remove the item when the timeout fires
|
|
865
|
-
map.delete(item[0]);
|
|
866
|
-
if (processingDeferred) {
|
|
867
|
-
processingDeferred.resolve();
|
|
868
|
-
}
|
|
869
|
-
}, delay);
|
|
870
|
-
// tslint:disable-next-line:strict-type-predicates
|
|
871
|
-
if (typeof processingTimer.unref === 'function') {
|
|
872
|
-
// Don't hold up the process from exiting
|
|
873
|
-
processingTimer.unref();
|
|
874
|
-
}
|
|
875
|
-
return processingDeferred.promise;
|
|
876
|
-
});
|
|
877
|
-
try {
|
|
878
|
-
for (const entry of map) {
|
|
879
|
-
yield setupTimer(entry);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
catch (_a) {
|
|
883
|
-
// Do nothing if an error occurs, this means the timer was cleaned up and we should stop processing
|
|
884
|
-
}
|
|
885
|
-
processingKey = undefined;
|
|
886
|
-
});
|
|
887
|
-
const reset = () => {
|
|
888
|
-
processingKey = undefined;
|
|
889
|
-
if (processingTimer !== undefined) {
|
|
890
|
-
clearTimeout(processingTimer);
|
|
891
|
-
processingTimer = undefined;
|
|
892
|
-
}
|
|
893
|
-
if (processingDeferred !== undefined) { // tslint:disable-line:early-exit
|
|
894
|
-
processingDeferred.reject(undefined);
|
|
895
|
-
processingDeferred = undefined;
|
|
896
|
-
}
|
|
897
|
-
};
|
|
898
|
-
const originalSet = map.set.bind(map);
|
|
899
|
-
map.set = (key, value) => {
|
|
900
|
-
if (map.has(key)) {
|
|
901
|
-
// If the key already exist, remove it so we can add it back at the end of the map.
|
|
902
|
-
map.delete(key);
|
|
903
|
-
}
|
|
904
|
-
// Call the original `map.set`
|
|
905
|
-
const result = originalSet(key, value);
|
|
906
|
-
// If we are already processing a key and the key added is the current processed key, stop processing it
|
|
907
|
-
if (processingKey && processingKey === key) {
|
|
908
|
-
reset();
|
|
909
|
-
}
|
|
910
|
-
// Always run the cleanup method in case it wasn't started yet
|
|
911
|
-
cleanup(); // tslint:disable-line:no-floating-promises
|
|
912
|
-
return result;
|
|
913
|
-
};
|
|
914
|
-
cleanup(); // tslint:disable-line:no-floating-promises
|
|
915
|
-
return map;
|
|
916
|
-
}
|
|
917
|
-
exports.default = mapAgeCleaner;
|
|
918
|
-
// Add support for CJS
|
|
919
|
-
module.exports = mapAgeCleaner;
|
|
920
|
-
module.exports.default = mapAgeCleaner;
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
var mapAgeCleaner = /*@__PURE__*/getDefaultExportFromCjs(dist);
|
|
924
|
-
|
|
925
|
-
var cacheStore = new WeakMap();
|
|
926
|
-
/**
|
|
927
|
-
[Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input.
|
|
928
|
-
|
|
929
|
-
@param fn - Function to be memoized.
|
|
930
|
-
|
|
931
|
-
@example
|
|
932
|
-
```
|
|
933
|
-
import mem from 'mem';
|
|
934
|
-
|
|
935
|
-
let index = 0;
|
|
936
|
-
const counter = () => ++index;
|
|
937
|
-
const memoized = mem(counter);
|
|
938
|
-
|
|
939
|
-
memoized('foo');
|
|
940
|
-
//=> 1
|
|
941
|
-
|
|
942
|
-
// Cached as it's the same argument
|
|
943
|
-
memoized('foo');
|
|
944
|
-
//=> 1
|
|
945
|
-
|
|
946
|
-
// Not cached anymore as the arguments changed
|
|
947
|
-
memoized('bar');
|
|
948
|
-
//=> 2
|
|
949
|
-
|
|
950
|
-
memoized('bar');
|
|
951
|
-
//=> 2
|
|
952
|
-
```
|
|
953
|
-
*/
|
|
954
|
-
|
|
955
|
-
function mem(fn, _temp) {
|
|
956
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
957
|
-
cacheKey = _ref.cacheKey,
|
|
958
|
-
_ref$cache = _ref.cache,
|
|
959
|
-
cache = _ref$cache === void 0 ? new Map() : _ref$cache,
|
|
960
|
-
maxAge = _ref.maxAge;
|
|
961
|
-
|
|
962
|
-
if (typeof maxAge === 'number') {
|
|
963
|
-
mapAgeCleaner(cache);
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
var memoized = function memoized() {
|
|
967
|
-
var arguments_ = [].slice.call(arguments);
|
|
968
|
-
var key = cacheKey ? cacheKey(arguments_) : arguments_[0];
|
|
969
|
-
var cacheItem = cache.get(key);
|
|
970
|
-
|
|
971
|
-
if (cacheItem) {
|
|
972
|
-
return cacheItem.data; // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
var result = fn.apply(this, arguments_);
|
|
976
|
-
cache.set(key, {
|
|
977
|
-
data: result,
|
|
978
|
-
maxAge: maxAge ? Date.now() + maxAge : Number.POSITIVE_INFINITY
|
|
979
|
-
});
|
|
980
|
-
return result; // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
981
|
-
};
|
|
982
|
-
|
|
983
|
-
mimicFunction(memoized, fn, {
|
|
984
|
-
ignoreNonConfigurable: true
|
|
985
|
-
});
|
|
986
|
-
cacheStore.set(memoized, cache);
|
|
987
|
-
return memoized;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
/**
|
|
991
|
-
* Test if the given value is an object.
|
|
992
|
-
*
|
|
993
|
-
* @param {*} value The value to test.
|
|
994
|
-
* @return {Boolean} Whether or not the value is an object.
|
|
995
|
-
*/
|
|
996
|
-
function isObject(value) {
|
|
997
|
-
return typeof value === 'object' && !!value && value.toString() === '[object Object]';
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* @typedef {StringConstructor|NumberConstructor|BooleanConstructor|ArrayConstructor|ObjectConstructor} OptionType
|
|
1002
|
-
* @typedef {{ [name:string]: OptionType | { type: OptionType, default: String|Number|Boolean|(() => Array|Object)} }} OptionsSchema
|
|
1003
|
-
* @typedef {{ [optionName:string]: any }} OptionsInterface
|
|
1004
|
-
*/
|
|
1005
|
-
|
|
1006
|
-
/**
|
|
1007
|
-
* Get the attribute name based on the given option name.
|
|
1008
|
-
* @param {String} name The option name.
|
|
1009
|
-
*/
|
|
1010
|
-
|
|
1011
|
-
function getAttributeName(name) {
|
|
1012
|
-
return "data-option-" + noCase(name, {
|
|
1013
|
-
delimiter: '-'
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
var memoizedGetAttributeName = mem(getAttributeName);
|
|
1018
|
-
/**
|
|
1019
|
-
* Class options to manage options as data attributes on an HTML element.
|
|
1020
|
-
* @augments {OptionsInterface}
|
|
1021
|
-
*/
|
|
1022
|
-
|
|
1023
|
-
var _element = /*#__PURE__*/_classPrivateFieldLooseKey("element");
|
|
1024
|
-
|
|
1025
|
-
var _values = /*#__PURE__*/_classPrivateFieldLooseKey("values");
|
|
1026
|
-
|
|
1027
|
-
var _defaultValues = /*#__PURE__*/_classPrivateFieldLooseKey("defaultValues");
|
|
1028
|
-
|
|
1029
|
-
var Options = /*#__PURE__*/function () {
|
|
1030
|
-
/** @type {HTMLElement} The HTML element holding the options attributes. */
|
|
1031
|
-
|
|
1032
|
-
/** @type {Object} An object to store Array and Object values for reference. */
|
|
1033
|
-
|
|
1034
|
-
/** @type {Array} List of allowed types. */
|
|
1035
|
-
|
|
1036
|
-
/**
|
|
1037
|
-
* The default values to return for each available type.
|
|
1038
|
-
* @type {Object}
|
|
1039
|
-
*/
|
|
1040
|
-
|
|
1041
|
-
/**
|
|
1042
|
-
* Class constructor.
|
|
1043
|
-
*
|
|
1044
|
-
* @param {HTMLElement} element The HTML element storing the options.
|
|
1045
|
-
* @param {OptionsSchema} schema A Base class config.
|
|
1046
|
-
*/
|
|
1047
|
-
function Options(element, schema) {
|
|
1048
|
-
var _this = this;
|
|
1049
|
-
|
|
1050
|
-
Object.defineProperty(this, _element, {
|
|
1051
|
-
writable: true,
|
|
1052
|
-
value: void 0
|
|
1053
|
-
});
|
|
1054
|
-
Object.defineProperty(this, _values, {
|
|
1055
|
-
writable: true,
|
|
1056
|
-
value: {}
|
|
1057
|
-
});
|
|
1058
|
-
Object.defineProperty(this, _defaultValues, {
|
|
1059
|
-
writable: true,
|
|
1060
|
-
value: {
|
|
1061
|
-
String: '',
|
|
1062
|
-
Number: 0,
|
|
1063
|
-
Boolean: false,
|
|
1064
|
-
Array: function Array() {
|
|
1065
|
-
return [];
|
|
1066
|
-
},
|
|
1067
|
-
Object: function Object() {
|
|
1068
|
-
return {};
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
});
|
|
1072
|
-
_classPrivateFieldLooseBase(this, _element)[_element] = element;
|
|
1073
|
-
Object.entries(schema).forEach(function (_ref) {
|
|
1074
|
-
var name = _ref[0],
|
|
1075
|
-
config = _ref[1];
|
|
1076
|
-
var isObjectConfig = !Options.types.includes(config);
|
|
1077
|
-
/** @type {OptionType} */
|
|
1078
|
-
// @ts-ignore
|
|
1079
|
-
|
|
1080
|
-
var type = isObjectConfig ? config.type : config;
|
|
1081
|
-
|
|
1082
|
-
if (!Options.types.includes(type)) {
|
|
1083
|
-
throw new Error("The \"" + name + "\" option has an invalid type. The allowed types are: String, Number, Boolean, Array and Object.");
|
|
1084
|
-
} // @ts-ignore
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
var defaultValue = isObjectConfig ? config.default : _classPrivateFieldLooseBase(_this, _defaultValues)[_defaultValues][type.name];
|
|
1088
|
-
|
|
1089
|
-
if ((type === Array || type === Object) && typeof defaultValue !== 'function') {
|
|
1090
|
-
throw new Error("The default value for options of type \"" + type.name + "\" must be returned by a function.");
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
Object.defineProperty(_this, name, {
|
|
1094
|
-
get: function get() {
|
|
1095
|
-
return this.get(name, type, defaultValue);
|
|
1096
|
-
},
|
|
1097
|
-
set: function set(value) {
|
|
1098
|
-
this.set(name, type, value, defaultValue);
|
|
1099
|
-
},
|
|
1100
|
-
enumerable: true
|
|
1101
|
-
});
|
|
1102
|
-
});
|
|
1103
|
-
return this;
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* Get an option value.
|
|
1107
|
-
*
|
|
1108
|
-
* @param {String} name The option name.
|
|
1109
|
-
* @param {ArrayConstructor|ObjectConstructor|StringConstructor|NumberConstructor|BooleanConstructor} type The option data's type.
|
|
1110
|
-
* @param {any} defaultValue The default value for this option.
|
|
1111
|
-
*/
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
var _proto = Options.prototype;
|
|
1115
|
-
|
|
1116
|
-
_proto.get = function get(name, type, defaultValue) {
|
|
1117
|
-
var _this2 = this;
|
|
1118
|
-
|
|
1119
|
-
var attributeName = memoizedGetAttributeName(name);
|
|
1120
|
-
|
|
1121
|
-
var hasAttribute = _classPrivateFieldLooseBase(this, _element)[_element].hasAttribute(attributeName);
|
|
1122
|
-
|
|
1123
|
-
if (type === Boolean) {
|
|
1124
|
-
if (defaultValue) {
|
|
1125
|
-
var negatedAttributeName = memoizedGetAttributeName("no-" + name);
|
|
1126
|
-
|
|
1127
|
-
var hasNegatedAttribute = _classPrivateFieldLooseBase(this, _element)[_element].hasAttribute(negatedAttributeName);
|
|
1128
|
-
|
|
1129
|
-
return !hasNegatedAttribute;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
return hasAttribute || defaultValue;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
var value = _classPrivateFieldLooseBase(this, _element)[_element].getAttribute(attributeName);
|
|
1136
|
-
|
|
1137
|
-
if (type === Number) {
|
|
1138
|
-
return hasAttribute ? Number(value) : defaultValue;
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
if (type === Array || type === Object) {
|
|
1142
|
-
var val = cjs(defaultValue(), hasAttribute ? JSON.parse(value) : _classPrivateFieldLooseBase(this, _defaultValues)[_defaultValues][type.name]());
|
|
1143
|
-
|
|
1144
|
-
if (!_classPrivateFieldLooseBase(this, _values)[_values][name]) {
|
|
1145
|
-
_classPrivateFieldLooseBase(this, _values)[_values][name] = val;
|
|
1146
|
-
} else if (val !== _classPrivateFieldLooseBase(this, _values)[_values][name]) {
|
|
1147
|
-
// When getting the value, wait for the next loop to update the data attribute
|
|
1148
|
-
// with the new value. This is a simple trick to avoid using a Proxy to watch
|
|
1149
|
-
// for any deep changes on an array or object. It should not break anything as
|
|
1150
|
-
// the original value is read once from the data attribute and is then read from
|
|
1151
|
-
// the private property `#values`.
|
|
1152
|
-
setTimeout(function () {
|
|
1153
|
-
_classPrivateFieldLooseBase(_this2, _element)[_element].setAttribute(attributeName, JSON.stringify(_classPrivateFieldLooseBase(_this2, _values)[_values][name]));
|
|
1154
|
-
}, 0);
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
return _classPrivateFieldLooseBase(this, _values)[_values][name];
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
return hasAttribute ? value : defaultValue;
|
|
1161
|
-
}
|
|
1162
|
-
/**
|
|
1163
|
-
* Set an option value.
|
|
1164
|
-
*
|
|
1165
|
-
* @param {String} name The option name.
|
|
1166
|
-
* @param {ArrayConstructor|ObjectConstructor|StringConstructor|NumberConstructor|BooleanConstructor} type The option data's type.
|
|
1167
|
-
* @param {any} value The new value for this option.
|
|
1168
|
-
*/
|
|
1169
|
-
;
|
|
1170
|
-
|
|
1171
|
-
_proto.set = function set(name, type, value, defaultValue) {
|
|
1172
|
-
var attributeName = memoizedGetAttributeName(name);
|
|
1173
|
-
|
|
1174
|
-
if (value.constructor.name !== type.name) {
|
|
1175
|
-
var val = Array.isArray(value) || isObject(value) ? JSON.stringify(value) : value;
|
|
1176
|
-
throw new TypeError("The \"" + val + "\" value for the \"" + name + "\" option must be of type \"" + type.name + "\"");
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
switch (type) {
|
|
1180
|
-
case Boolean:
|
|
1181
|
-
if (defaultValue) {
|
|
1182
|
-
var negatedAttributeName = memoizedGetAttributeName("no-" + name);
|
|
1183
|
-
|
|
1184
|
-
if (value) {
|
|
1185
|
-
_classPrivateFieldLooseBase(this, _element)[_element].removeAttribute(negatedAttributeName);
|
|
1186
|
-
} else {
|
|
1187
|
-
_classPrivateFieldLooseBase(this, _element)[_element].setAttribute(negatedAttributeName, '');
|
|
1188
|
-
}
|
|
1189
|
-
} else if (value) {
|
|
1190
|
-
_classPrivateFieldLooseBase(this, _element)[_element].setAttribute(attributeName, '');
|
|
1191
|
-
} else {
|
|
1192
|
-
_classPrivateFieldLooseBase(this, _element)[_element].removeAttribute(attributeName);
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
break;
|
|
1196
|
-
|
|
1197
|
-
case Array:
|
|
1198
|
-
case Object:
|
|
1199
|
-
_classPrivateFieldLooseBase(this, _values)[_values][name] = value;
|
|
1200
|
-
|
|
1201
|
-
_classPrivateFieldLooseBase(this, _element)[_element].setAttribute(attributeName, JSON.stringify(value));
|
|
1202
|
-
|
|
1203
|
-
break;
|
|
1204
|
-
|
|
1205
|
-
default:
|
|
1206
|
-
_classPrivateFieldLooseBase(this, _element)[_element].setAttribute(attributeName, value);
|
|
1207
|
-
|
|
1208
|
-
}
|
|
1209
|
-
};
|
|
1210
|
-
|
|
1211
|
-
return Options;
|
|
1212
|
-
}();
|
|
1213
|
-
|
|
1214
|
-
Options.types = [String, Number, Boolean, Array, Object];
|
|
1215
|
-
|
|
1216
|
-
/**
|
|
1217
|
-
* @typedef {import('./index.js').default} Base
|
|
1218
|
-
* @typedef {import('./index.js').BaseOptions} BaseOptions
|
|
1219
|
-
* @typedef {import('./classes/Options.js').OptionsSchema} OptionsSchema
|
|
1220
|
-
*/
|
|
1221
|
-
|
|
1222
|
-
/**
|
|
1223
|
-
* Get the legacy options from the `config` properties.
|
|
1224
|
-
*
|
|
1225
|
-
* @param {Base} instance The component's instance.
|
|
1226
|
-
* @param {Object} config The component's config.
|
|
1227
|
-
* @return {OptionsSchema}
|
|
1228
|
-
*/
|
|
1229
|
-
|
|
1230
|
-
function getLegacyOptionsSchema(instance, config) {
|
|
1231
|
-
// Add legacy options to the schema
|
|
1232
|
-
var propsToExclude = ['name', 'log', 'debug', 'components', 'refs', 'options'];
|
|
1233
|
-
return Object.keys(config).reduce(
|
|
1234
|
-
/**
|
|
1235
|
-
* @param {OptionsSchema} schema
|
|
1236
|
-
* @param {String} propName
|
|
1237
|
-
*/
|
|
1238
|
-
function (schema, propName) {
|
|
1239
|
-
if (propsToExclude.includes(propName)) {
|
|
1240
|
-
return schema;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
var value = config[propName];
|
|
1244
|
-
var type = value === null || value === undefined ? Object : value.constructor; // Default to object type as it should work for any values.
|
|
1245
|
-
|
|
1246
|
-
if (!Options.types.includes(type)) {
|
|
1247
|
-
type = Object;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
warn(instance, '\n Options must be defined in the `config.options` property.', "\n Consider moving the `config." + propName + "` option to `config.options." + propName + "`.");
|
|
1251
|
-
|
|
1252
|
-
if (type === Array || type === Object) {
|
|
1253
|
-
schema[propName] = {
|
|
1254
|
-
type: type,
|
|
1255
|
-
default: function _default() {
|
|
1256
|
-
return value;
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1259
|
-
} else {
|
|
1260
|
-
schema[propName] = {
|
|
1261
|
-
type: type,
|
|
1262
|
-
default: value
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
return schema;
|
|
1267
|
-
}, {});
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Get the inherited options values from the current instance parent classes.
|
|
1271
|
-
* @param {Base} instance The component's instance.
|
|
1272
|
-
* @return {OptionsSchema}
|
|
1273
|
-
*/
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
function getParentOptionsSchema(instance) {
|
|
1277
|
-
/** @type {OptionsSchema} [description] */
|
|
1278
|
-
var schema = {};
|
|
1279
|
-
/** @type {Base|false} Merge inherited options. */
|
|
1280
|
-
|
|
1281
|
-
var prototype = instance;
|
|
1282
|
-
|
|
1283
|
-
while (prototype) {
|
|
1284
|
-
var getterConfig = prototype.config; // @ts-ignore
|
|
1285
|
-
|
|
1286
|
-
var staticConfig = prototype.constructor.config;
|
|
1287
|
-
|
|
1288
|
-
if (getterConfig || staticConfig) {
|
|
1289
|
-
schema = Object.assign((getterConfig || {}).options || {}, (staticConfig || {}).options || {}, schema);
|
|
1290
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
1291
|
-
} else {
|
|
1292
|
-
prototype = false;
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
return schema;
|
|
1297
|
-
}
|
|
1298
|
-
/**
|
|
1299
|
-
* Update an Options object with the legacy values from the element's `data-options` attribute.
|
|
1300
|
-
*
|
|
1301
|
-
* @param {Base} instance The component's instance.
|
|
1302
|
-
* @param {HTMLElement} element The component's root element.
|
|
1303
|
-
* @param {Options} options The component's options.
|
|
1304
|
-
*/
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
function updateOptionsWithLegacyValues(instance, element, options) {
|
|
1308
|
-
// Update legacy options with value from the `data-options` attribute
|
|
1309
|
-
var legacyOptionsValues = {};
|
|
1310
|
-
|
|
1311
|
-
if (element.dataset.options) {
|
|
1312
|
-
warn(instance, 'The `data-options` attribute usage is deprecated, use multiple `data-option-...` attributes instead.');
|
|
1313
|
-
|
|
1314
|
-
try {
|
|
1315
|
-
legacyOptionsValues = JSON.parse(element.dataset.options);
|
|
1316
|
-
} catch (err) {
|
|
1317
|
-
throw new Error('Can not parse the `data-options` attribute. Is it a valid JSON string?');
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
Object.entries(legacyOptionsValues).forEach(function (_ref) {
|
|
1322
|
-
var optionName = _ref[0],
|
|
1323
|
-
optionValue = _ref[1];
|
|
1324
|
-
options[optionName] = optionValue;
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
* Get a component's options.
|
|
1329
|
-
*
|
|
1330
|
-
* @param {Base} instance The component's instance.
|
|
1331
|
-
* @param {HTMLElement} element The component's root element.
|
|
1332
|
-
* @param {Object} config The component's default config.
|
|
1333
|
-
* @return {Options & BaseOptions} The component's merged options.
|
|
1334
|
-
*/
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
function getOptions(instance, element, config) {
|
|
1338
|
-
var _config$log, _config$debug;
|
|
1339
|
-
|
|
1340
|
-
/** @type {OptionsSchema} */
|
|
1341
|
-
var schema = _extends({
|
|
1342
|
-
name: {
|
|
1343
|
-
type: String,
|
|
1344
|
-
default: config.name
|
|
1345
|
-
},
|
|
1346
|
-
log: {
|
|
1347
|
-
type: Boolean,
|
|
1348
|
-
default: (_config$log = config.log) != null ? _config$log : false
|
|
1349
|
-
},
|
|
1350
|
-
debug: {
|
|
1351
|
-
type: Boolean,
|
|
1352
|
-
default: (_config$debug = config.debug) != null ? _config$debug : false
|
|
1353
|
-
}
|
|
1354
|
-
}, getParentOptionsSchema(instance), getLegacyOptionsSchema(instance, config), config.options || {});
|
|
1355
|
-
|
|
1356
|
-
var options = new Options(element, schema);
|
|
1357
|
-
updateOptionsWithLegacyValues(instance, element, options);
|
|
1358
|
-
instance.$emit('get:options', options);
|
|
1359
|
-
return options;
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
/**
|
|
1363
|
-
* @typedef {import('./index.js').default} Base
|
|
1364
|
-
*/
|
|
1365
|
-
|
|
1366
|
-
/**
|
|
1367
|
-
* A ponyfill for the CSS `:scope` selector which is not supported in IE11.
|
|
1368
|
-
* The following method will return an array of elements similare to the
|
|
1369
|
-
* `:scope ${selector}` selector.
|
|
1370
|
-
*
|
|
1371
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/:scope
|
|
1372
|
-
* @see https://github.com/jonathantneal/element-qsa-scope
|
|
1373
|
-
*
|
|
1374
|
-
* @param {HTMLElement} element The element from which the scope is taken.
|
|
1375
|
-
* @param {String} selector The children selector.
|
|
1376
|
-
* @param {String} uniqId A uniq ID to prefix the selector with.
|
|
1377
|
-
* @return {Array} A list of elements.
|
|
1378
|
-
*/
|
|
1379
|
-
|
|
1380
|
-
function scopeSelectorPonyfill(element, selector, uniqId) {
|
|
1381
|
-
var list = [];
|
|
1382
|
-
|
|
1383
|
-
try {
|
|
1384
|
-
list = Array.from(element.querySelectorAll(":scope " + selector));
|
|
1385
|
-
} catch (err) {
|
|
1386
|
-
var attr = "data-uniq-id";
|
|
1387
|
-
var scopedSelector = "[" + attr + "=\"" + uniqId + "\"] " + selector;
|
|
1388
|
-
element.setAttribute(attr, uniqId);
|
|
1389
|
-
list = Array.from(element.querySelectorAll(scopedSelector));
|
|
1390
|
-
element.removeAttribute(attr);
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
return list;
|
|
1394
|
-
}
|
|
1395
|
-
/**
|
|
1396
|
-
* Get all refs of a component.
|
|
1397
|
-
*
|
|
1398
|
-
* @param {Base} instance The component's instance.
|
|
1399
|
-
* @param {HTMLElement} element The component's root element.
|
|
1400
|
-
* @return {Object} Return an object containing all the component's refs.
|
|
1401
|
-
*/
|
|
1402
|
-
|
|
1403
|
-
function getRefs(instance, element) {
|
|
1404
|
-
var definedRefs = getConfig(instance).refs || [];
|
|
1405
|
-
/** @type {Array<HTMLElement>} */
|
|
1406
|
-
|
|
1407
|
-
var allRefs = Array.from(element.querySelectorAll("[data-ref]"));
|
|
1408
|
-
var childrenRefs = scopeSelectorPonyfill(element, '[data-component] [data-ref]', instance.$id);
|
|
1409
|
-
var elements = allRefs.filter(function (ref) {
|
|
1410
|
-
return !childrenRefs.includes(ref);
|
|
1411
|
-
});
|
|
1412
|
-
var refs = elements.reduce(
|
|
1413
|
-
/**
|
|
1414
|
-
* @param {Object} $refs
|
|
1415
|
-
* @param {HTMLElement & {__base__?: Base}} $ref
|
|
1416
|
-
*/
|
|
1417
|
-
function ($refs, $ref) {
|
|
1418
|
-
var refName = $ref.dataset.ref;
|
|
1419
|
-
|
|
1420
|
-
if (!definedRefs.includes(refName)) {
|
|
1421
|
-
warn(instance, "The \"" + refName + "\" ref is not defined in the class configuration.", 'Did you forgot to define it?');
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
var $realRef = $ref.__base__ ? $ref.__base__ : $ref;
|
|
1425
|
-
|
|
1426
|
-
if (refName.endsWith('[]')) {
|
|
1427
|
-
refName = refName.replace(/\[\]$/, '');
|
|
1428
|
-
|
|
1429
|
-
if (!$refs[refName]) {
|
|
1430
|
-
$refs[refName] = [];
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
if ($refs[refName]) {
|
|
1435
|
-
if (Array.isArray($refs[refName])) {
|
|
1436
|
-
$refs[refName].push($realRef);
|
|
1437
|
-
} else {
|
|
1438
|
-
$refs[refName] = [$refs[refName], $realRef];
|
|
1439
|
-
warn(instance, "The \"" + refName + "\" ref has been found multiple times.", 'Did you forgot to add the `[]` suffix to its name?');
|
|
1440
|
-
}
|
|
1441
|
-
} else {
|
|
1442
|
-
$refs[refName] = $realRef;
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
return $refs;
|
|
1446
|
-
}, {});
|
|
1447
|
-
instance.$emit('get:refs', refs);
|
|
1448
|
-
return refs;
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
/**
|
|
1452
|
-
* @typedef {import('./index.js').default} Base
|
|
1453
|
-
*/
|
|
1454
|
-
|
|
1455
|
-
/**
|
|
1456
|
-
* Mount a given component which might be async.
|
|
1457
|
-
*
|
|
1458
|
-
* @param {Base|Promise<Base>} component The component to mount.
|
|
1459
|
-
* @return {void}
|
|
1460
|
-
*/
|
|
1461
|
-
|
|
1462
|
-
function mountComponent(component) {
|
|
1463
|
-
if (component instanceof Promise) {
|
|
1464
|
-
component.then(function (instance) {
|
|
1465
|
-
return instance.$mount();
|
|
1466
|
-
});
|
|
1467
|
-
} else {
|
|
1468
|
-
component.$mount();
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* Mount children components of a given instance.
|
|
1473
|
-
*
|
|
1474
|
-
* @param {Base} instance The parent component's instance.
|
|
1475
|
-
* @return {void}
|
|
1476
|
-
*/
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
function mountComponents(instance) {
|
|
1480
|
-
if (__DEV__) {
|
|
1481
|
-
debug(instance, 'mountComponents', instance.$children);
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
Object.values(instance.$children).forEach(function ($child) {
|
|
1485
|
-
if (__DEV__) {
|
|
1486
|
-
debug(instance, 'mountComponent', $child);
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
$child.forEach(mountComponent);
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
|
-
/**
|
|
1493
|
-
* Mount or update the given component.
|
|
1494
|
-
*
|
|
1495
|
-
* @param {Base|Promise<Base>} component [description]
|
|
1496
|
-
* @return {void}
|
|
1497
|
-
*/
|
|
1498
|
-
|
|
1499
|
-
function mountOrUpdateComponent(component) {
|
|
1500
|
-
if (component instanceof Promise) {
|
|
1501
|
-
component.then(function (instance) {
|
|
1502
|
-
return instance.$isMounted ? instance.$update() : instance.$mount();
|
|
1503
|
-
});
|
|
1504
|
-
} else {
|
|
1505
|
-
var method = component.$isMounted ? '$update' : '$mount';
|
|
1506
|
-
component[method]();
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Mount or updte children components of the given instance.
|
|
1511
|
-
*
|
|
1512
|
-
* @param {Base} instance The parent component's instance.
|
|
1513
|
-
* @return {void}
|
|
1514
|
-
*/
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
function mountOrUpdateComponents(instance) {
|
|
1518
|
-
if (__DEV__) {
|
|
1519
|
-
debug(instance, 'mountComponents', instance.$children);
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
Object.values(instance.$children).forEach(function ($child) {
|
|
1523
|
-
$child.forEach(mountOrUpdateComponent);
|
|
1524
|
-
});
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* Destroy a given component which might be async.
|
|
1528
|
-
*
|
|
1529
|
-
* @param {Base|Promise} component The component to destroy.
|
|
1530
|
-
* @return {void}
|
|
1531
|
-
*/
|
|
1532
|
-
|
|
1533
|
-
function destroyComponent(component) {
|
|
1534
|
-
if (component instanceof Promise) {
|
|
1535
|
-
component.then(function (instance) {
|
|
1536
|
-
return instance.$destroy();
|
|
1537
|
-
});
|
|
1538
|
-
} else {
|
|
1539
|
-
component.$destroy();
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
/**
|
|
1543
|
-
* Destroy children components of a given instance.
|
|
1544
|
-
*
|
|
1545
|
-
* @param {Base} instance The parent component's instance.
|
|
1546
|
-
* @return {void}
|
|
1547
|
-
*/
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
function destroyComponents(instance) {
|
|
1551
|
-
if (__DEV__) {
|
|
1552
|
-
debug(instance, 'destroyComponents', instance.$children);
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
Object.values(instance.$children).forEach(
|
|
1556
|
-
/**
|
|
1557
|
-
* @param {Array<Base>} $child
|
|
1558
|
-
*/
|
|
1559
|
-
function ($child) {
|
|
1560
|
-
$child.forEach(destroyComponent);
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
/**
|
|
1565
|
-
* Service abstract class
|
|
1566
|
-
*/
|
|
1567
|
-
var Service = /*#__PURE__*/function () {
|
|
1568
|
-
/**
|
|
1569
|
-
* Class constructor, used to test the abstract class implementation.
|
|
1570
|
-
*/
|
|
1571
|
-
function Service() {
|
|
1572
|
-
this.callbacks = new Map();
|
|
1573
|
-
this.isInit = false;
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
* Getter to get the services properties.
|
|
1577
|
-
* This getter MUST be implementer by the service extending this class.
|
|
1578
|
-
* @return {Object}
|
|
1579
|
-
*/
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
var _proto = Service.prototype;
|
|
1583
|
-
|
|
1584
|
-
/**
|
|
1585
|
-
* Method to initialize the service behaviors.
|
|
1586
|
-
* This method MUST be implemented by the service extending this class.
|
|
1587
|
-
*
|
|
1588
|
-
* @return {Service} The current instance
|
|
1589
|
-
*/
|
|
1590
|
-
_proto.init = function init() {
|
|
1591
|
-
throw new Error('The `init` method must be implemented.');
|
|
1592
|
-
}
|
|
1593
|
-
/**
|
|
1594
|
-
* Method to kill the service behaviors.
|
|
1595
|
-
* This method MUST be implemented by the service extending this class.
|
|
1596
|
-
*
|
|
1597
|
-
* @return {Service} The current instance
|
|
1598
|
-
*/
|
|
1599
|
-
;
|
|
1600
|
-
|
|
1601
|
-
_proto.kill = function kill() {
|
|
1602
|
-
throw new Error('The `kill` method must be implemented.');
|
|
1603
|
-
}
|
|
1604
|
-
/**
|
|
1605
|
-
* Add a callback.
|
|
1606
|
-
*
|
|
1607
|
-
* @param {String} key The callback's identifier
|
|
1608
|
-
* @param {Function} callback The callback function
|
|
1609
|
-
* @return {this} The current instance
|
|
1610
|
-
*/
|
|
1611
|
-
;
|
|
1612
|
-
|
|
1613
|
-
_proto.add = function add(key, callback) {
|
|
1614
|
-
if (this.has(key)) {
|
|
1615
|
-
throw new Error("A callback with the key `" + key + "` has already been registered.");
|
|
1616
|
-
} // Initialize the service when we add the first callback
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
if (this.callbacks.size === 0 && !this.isInit) {
|
|
1620
|
-
this.init();
|
|
1621
|
-
this.isInit = true;
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
|
-
this.callbacks.set(key, callback);
|
|
1625
|
-
return this;
|
|
1626
|
-
}
|
|
1627
|
-
/**
|
|
1628
|
-
* Test if a callback with the given key has already been added.
|
|
1629
|
-
*
|
|
1630
|
-
* @param {String} key The identifier to test
|
|
1631
|
-
* @return {Boolean} Whether or not the identifier already exists
|
|
1632
|
-
*/
|
|
1633
|
-
;
|
|
1634
|
-
|
|
1635
|
-
_proto.has = function has(key) {
|
|
1636
|
-
return this.callbacks.has(key);
|
|
1637
|
-
}
|
|
1638
|
-
/**
|
|
1639
|
-
* Get the callback tied to the given key.
|
|
1640
|
-
*
|
|
1641
|
-
* @param {String} key The identifier to get
|
|
1642
|
-
* @return {Function} The callback function
|
|
1643
|
-
*/
|
|
1644
|
-
;
|
|
1645
|
-
|
|
1646
|
-
_proto.get = function get(key) {
|
|
1647
|
-
return this.callbacks.get(key);
|
|
1648
|
-
}
|
|
1649
|
-
/**
|
|
1650
|
-
* Remove the callback tied to the given key.
|
|
1651
|
-
*
|
|
1652
|
-
* @param {String} key The identifier to remove
|
|
1653
|
-
* @return {Service} The current instance
|
|
1654
|
-
*/
|
|
1655
|
-
;
|
|
1656
|
-
|
|
1657
|
-
_proto.remove = function remove(key) {
|
|
1658
|
-
this.callbacks.delete(key); // Kill the service when we remove the last callback
|
|
1659
|
-
|
|
1660
|
-
if (this.callbacks.size === 0 && this.isInit) {
|
|
1661
|
-
this.kill();
|
|
1662
|
-
this.isInit = false;
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
return this;
|
|
1666
|
-
}
|
|
1667
|
-
/**
|
|
1668
|
-
* Trigger each added callback with the given arguments.
|
|
1669
|
-
*
|
|
1670
|
-
* @param {Array} args All the arguments to apply to the callback
|
|
1671
|
-
* @return {Service} The current instance
|
|
1672
|
-
*/
|
|
1673
|
-
;
|
|
1674
|
-
|
|
1675
|
-
_proto.trigger = function trigger() {
|
|
1676
|
-
var args = [].slice.call(arguments);
|
|
1677
|
-
this.callbacks.forEach(function forEachCallback(callback) {
|
|
1678
|
-
callback.apply(void 0, args);
|
|
1679
|
-
});
|
|
1680
|
-
return this;
|
|
1681
|
-
};
|
|
1682
|
-
|
|
1683
|
-
_createClass(Service, [{
|
|
1684
|
-
key: "props",
|
|
1685
|
-
get: function get() {
|
|
1686
|
-
throw new Error('The `props` getter must be implemented.');
|
|
1687
|
-
}
|
|
1688
|
-
}]);
|
|
1689
|
-
|
|
1690
|
-
return Service;
|
|
1691
|
-
}();
|
|
1692
|
-
|
|
1693
|
-
/**
|
|
1694
|
-
* @typedef {import('./index').ServiceInterface} ServiceInterface
|
|
1695
|
-
*/
|
|
1696
|
-
|
|
1697
|
-
/**
|
|
1698
|
-
* @typedef {Object} PointerServiceProps
|
|
1699
|
-
* @property {MouseEvent | TouchEvent} event
|
|
1700
|
-
* @property {Boolean} isDown
|
|
1701
|
-
* @property {Number} x
|
|
1702
|
-
* @property {Number} y
|
|
1703
|
-
* @property {{ x: Boolean, y: Boolean }} changed
|
|
1704
|
-
* @property {{ x: Number, y: Number }} last
|
|
1705
|
-
* @property {{ x: Number, y: Number }} delta
|
|
1706
|
-
* @property {{ x: Number, y: Number }} progress
|
|
1707
|
-
* @property {{ x: Number, y: Number }} max
|
|
1708
|
-
*/
|
|
1709
|
-
|
|
1710
|
-
/**
|
|
1711
|
-
* @typedef {Object} PointerService
|
|
1712
|
-
* @property {(key:String, callback:(props:PointerServiceProps) => void) => void} add
|
|
1713
|
-
* Add a function to the resize service. The key must be uniq.
|
|
1714
|
-
* @property {() => PointerServiceProps} props
|
|
1715
|
-
* Get the current values of the resize service props.
|
|
1716
|
-
*/
|
|
1717
|
-
|
|
1718
|
-
/**
|
|
1719
|
-
* Test if an event is an instance of TouchEvent.
|
|
1720
|
-
*
|
|
1721
|
-
* @param {TouchEvent|MouseEvent} event The event instance to test.
|
|
1722
|
-
* @return {Boolean} Is it a TouchEvent?
|
|
1723
|
-
*/
|
|
1724
|
-
|
|
1725
|
-
function isTouchEvent(event) {
|
|
1726
|
-
return typeof TouchEvent !== 'undefined' && event instanceof TouchEvent;
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* Pointer service
|
|
1730
|
-
*/
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
var Pointer = /*#__PURE__*/function (_Service) {
|
|
1734
|
-
_inheritsLoose(Pointer, _Service);
|
|
1735
|
-
|
|
1736
|
-
function Pointer() {
|
|
1737
|
-
var _this;
|
|
1738
|
-
|
|
1739
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1740
|
-
args[_key] = arguments[_key];
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
_this = _Service.call.apply(_Service, [this].concat(args)) || this;
|
|
1744
|
-
_this.isDown = false;
|
|
1745
|
-
_this.y = window.innerHeight / 2;
|
|
1746
|
-
_this.yLast = window.innerHeight / 2;
|
|
1747
|
-
_this.x = window.innerWidth / 2;
|
|
1748
|
-
_this.xLast = window.innerWidth / 2;
|
|
1749
|
-
_this.hasRaf = false;
|
|
1750
|
-
return _this;
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
var _proto = Pointer.prototype;
|
|
1754
|
-
|
|
1755
|
-
/**
|
|
1756
|
-
* Bind the handler to the mousemove and touchmove events.
|
|
1757
|
-
* Bind the up and down handler to the mousedown, mouseup, touchstart and touchend events.
|
|
1758
|
-
*
|
|
1759
|
-
* @return {Pointer}
|
|
1760
|
-
*/
|
|
1761
|
-
_proto.init = function init() {
|
|
1762
|
-
document.documentElement.addEventListener('mouseenter', this, {
|
|
1763
|
-
once: true,
|
|
1764
|
-
capture: true
|
|
1765
|
-
});
|
|
1766
|
-
var options = {
|
|
1767
|
-
passive: true,
|
|
1768
|
-
capture: true
|
|
1769
|
-
};
|
|
1770
|
-
document.addEventListener('mousemove', this, options);
|
|
1771
|
-
document.addEventListener('touchmove', this, options);
|
|
1772
|
-
document.addEventListener('mousedown', this, options);
|
|
1773
|
-
document.addEventListener('touchstart', this, options);
|
|
1774
|
-
document.addEventListener('mouseup', this, options);
|
|
1775
|
-
document.addEventListener('touchend', this, options);
|
|
1776
|
-
return this;
|
|
1777
|
-
}
|
|
1778
|
-
/**
|
|
1779
|
-
* Handle events.
|
|
1780
|
-
* @param {MouseEvent|TouchEvent} event The event object.
|
|
1781
|
-
*/
|
|
1782
|
-
;
|
|
1783
|
-
|
|
1784
|
-
_proto.handleEvent = function handleEvent(event) {
|
|
1785
|
-
// eslint-disable-next-line default-case
|
|
1786
|
-
switch (event.type) {
|
|
1787
|
-
case 'mouseenter':
|
|
1788
|
-
case 'mousemove':
|
|
1789
|
-
case 'touchmove':
|
|
1790
|
-
this.handler(event);
|
|
1791
|
-
break;
|
|
1792
|
-
|
|
1793
|
-
case 'mousedown':
|
|
1794
|
-
case 'touchstart':
|
|
1795
|
-
this.downHandler();
|
|
1796
|
-
break;
|
|
1797
|
-
|
|
1798
|
-
case 'mouseup':
|
|
1799
|
-
case 'touchend':
|
|
1800
|
-
this.upHandler();
|
|
1801
|
-
break;
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
/**
|
|
1805
|
-
* Unbind all handlers from their bounded event.
|
|
1806
|
-
*
|
|
1807
|
-
* @return {Pointer}
|
|
1808
|
-
*/
|
|
1809
|
-
;
|
|
1810
|
-
|
|
1811
|
-
_proto.kill = function kill() {
|
|
1812
|
-
document.removeEventListener('mousemove', this);
|
|
1813
|
-
document.removeEventListener('touchmove', this);
|
|
1814
|
-
document.removeEventListener('mousedown', this);
|
|
1815
|
-
document.removeEventListener('touchstart', this);
|
|
1816
|
-
document.removeEventListener('mouseup', this);
|
|
1817
|
-
document.removeEventListener('touchend', this);
|
|
1818
|
-
return this;
|
|
1819
|
-
}
|
|
1820
|
-
/**
|
|
1821
|
-
* The service handler.
|
|
1822
|
-
* @param {MouseEvent|TouchEvent} event The mouse event object.
|
|
1823
|
-
*/
|
|
1824
|
-
;
|
|
1825
|
-
|
|
1826
|
-
_proto.handler = function handler(event) {
|
|
1827
|
-
this.updateValues(event);
|
|
1828
|
-
this.trigger(this.props);
|
|
1829
|
-
}
|
|
1830
|
-
/**
|
|
1831
|
-
* Handler for the pointer's down action.
|
|
1832
|
-
*
|
|
1833
|
-
* @return {void}
|
|
1834
|
-
*/
|
|
1835
|
-
;
|
|
1836
|
-
|
|
1837
|
-
_proto.downHandler = function downHandler() {
|
|
1838
|
-
this.isDown = true;
|
|
1839
|
-
this.trigger(this.props);
|
|
1840
|
-
}
|
|
1841
|
-
/**
|
|
1842
|
-
* Handler for the pointer's up action.
|
|
1843
|
-
*
|
|
1844
|
-
* @return {void}
|
|
1845
|
-
*/
|
|
1846
|
-
;
|
|
1847
|
-
|
|
1848
|
-
_proto.upHandler = function upHandler() {
|
|
1849
|
-
this.isDown = false;
|
|
1850
|
-
this.trigger(this.props);
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Update the pointer positions.
|
|
1854
|
-
*
|
|
1855
|
-
* @param {MouseEvent|TouchEvent} event The event object.
|
|
1856
|
-
* @return {void}
|
|
1857
|
-
*/
|
|
1858
|
-
;
|
|
1859
|
-
|
|
1860
|
-
_proto.updateValues = function updateValues(event) {
|
|
1861
|
-
var _event$touches$, _event$touches$2;
|
|
1862
|
-
|
|
1863
|
-
this.event = event;
|
|
1864
|
-
this.yLast = this.y;
|
|
1865
|
-
this.xLast = this.x; // Check pointer Y
|
|
1866
|
-
// We either get data from a touch event `event.touches[0].clientY` or from
|
|
1867
|
-
// a mouse event `event.clientY`.
|
|
1868
|
-
|
|
1869
|
-
var y = isTouchEvent(event) ?
|
|
1870
|
-
/** @type {TouchEvent} */
|
|
1871
|
-
(_event$touches$ = event.touches[0]) == null ? void 0 : _event$touches$.clientY :
|
|
1872
|
-
/** @type {MouseEvent} */
|
|
1873
|
-
event.clientY;
|
|
1874
|
-
|
|
1875
|
-
if (y !== this.y) {
|
|
1876
|
-
this.y = y;
|
|
1877
|
-
} // Check pointer X
|
|
1878
|
-
// We either get data from a touch event `event.touches[0].clientX` or from
|
|
1879
|
-
// a mouse event `event.clientX`.
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
var x = isTouchEvent(event) ?
|
|
1883
|
-
/** @type {TouchEvent} */
|
|
1884
|
-
(_event$touches$2 = event.touches[0]) == null ? void 0 : _event$touches$2.clientX :
|
|
1885
|
-
/** @type {MouseEvent} */
|
|
1886
|
-
event.clientX;
|
|
1887
|
-
|
|
1888
|
-
if (x !== this.x) {
|
|
1889
|
-
this.x = x;
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Get the pointer props.
|
|
1894
|
-
*
|
|
1895
|
-
* @type {Object}
|
|
1896
|
-
*/
|
|
1897
|
-
;
|
|
1898
|
-
|
|
1899
|
-
_createClass(Pointer, [{
|
|
1900
|
-
key: "props",
|
|
1901
|
-
get: function get() {
|
|
1902
|
-
return {
|
|
1903
|
-
event: this.event,
|
|
1904
|
-
isDown: this.isDown,
|
|
1905
|
-
x: this.x,
|
|
1906
|
-
y: this.y,
|
|
1907
|
-
changed: {
|
|
1908
|
-
x: this.x !== this.xLast,
|
|
1909
|
-
y: this.y !== this.yLast
|
|
1910
|
-
},
|
|
1911
|
-
last: {
|
|
1912
|
-
x: this.xLast,
|
|
1913
|
-
y: this.yLast
|
|
1914
|
-
},
|
|
1915
|
-
delta: {
|
|
1916
|
-
x: this.x - this.xLast,
|
|
1917
|
-
y: this.y - this.yLast
|
|
1918
|
-
},
|
|
1919
|
-
progress: {
|
|
1920
|
-
x: this.x / window.innerWidth,
|
|
1921
|
-
y: this.y / window.innerHeight
|
|
1922
|
-
},
|
|
1923
|
-
max: {
|
|
1924
|
-
x: window.innerWidth,
|
|
1925
|
-
y: window.innerHeight
|
|
1926
|
-
}
|
|
1927
|
-
};
|
|
1928
|
-
}
|
|
1929
|
-
}]);
|
|
1930
|
-
|
|
1931
|
-
return Pointer;
|
|
1932
|
-
}(Service);
|
|
1933
|
-
|
|
1934
|
-
var pointer = null;
|
|
1935
|
-
/**
|
|
1936
|
-
* Use the pointer.
|
|
1937
|
-
*
|
|
1938
|
-
* ```js
|
|
1939
|
-
* import usePointer from '@studiometa/js-toolkit/services';
|
|
1940
|
-
* const { add, remove, props } = usePointer();
|
|
1941
|
-
* add('id', () => {});
|
|
1942
|
-
* remove('id');
|
|
1943
|
-
* props();
|
|
1944
|
-
* ```
|
|
1945
|
-
*
|
|
1946
|
-
* @return {ServiceInterface & PointerService}
|
|
1947
|
-
*/
|
|
1948
|
-
|
|
1949
|
-
function usePointer() {
|
|
1950
|
-
if (!pointer) {
|
|
1951
|
-
pointer = new Pointer();
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
var add = pointer.add.bind(pointer);
|
|
1955
|
-
var remove = pointer.remove.bind(pointer);
|
|
1956
|
-
var has = pointer.has.bind(pointer);
|
|
1957
|
-
|
|
1958
|
-
var props = function props() {
|
|
1959
|
-
return pointer.props;
|
|
1960
|
-
};
|
|
1961
|
-
|
|
1962
|
-
return {
|
|
1963
|
-
add: add,
|
|
1964
|
-
remove: remove,
|
|
1965
|
-
has: has,
|
|
1966
|
-
props: props
|
|
1967
|
-
};
|
|
1968
|
-
}
|
|
1969
|
-
|
|
1970
|
-
/**
|
|
1971
|
-
* RequestAnimation frame polyfill.
|
|
1972
|
-
* @see https://github.com/vuejs/vue/blob/ec78fc8b6d03e59da669be1adf4b4b5abf670a34/dist/vue.runtime.esm.js#L7355
|
|
1973
|
-
* @return {(handler: Function) => number}
|
|
1974
|
-
*/
|
|
1975
|
-
function getRaf() {
|
|
1976
|
-
return typeof window !== 'undefined' && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : setTimeout;
|
|
1977
|
-
}
|
|
1978
|
-
/**
|
|
1979
|
-
* Get a function to cancel the method returned by `getRaf()`.
|
|
1980
|
-
*
|
|
1981
|
-
* @return {(id:number) => void}
|
|
1982
|
-
*/
|
|
1983
|
-
|
|
1984
|
-
function getCancelRaf() {
|
|
1985
|
-
return typeof window !== 'undefined' && window.cancelAnimationFrame ? window.cancelAnimationFrame.bind(window) : clearTimeout;
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
/**
|
|
1989
|
-
* @typedef {import('./index').ServiceInterface} ServiceInterface
|
|
1990
|
-
*/
|
|
1991
|
-
|
|
1992
|
-
/**
|
|
1993
|
-
* @typedef {Object} RafServiceProps
|
|
1994
|
-
* @property {DOMHighResTimeStamp} time
|
|
1995
|
-
*/
|
|
1996
|
-
|
|
1997
|
-
/**
|
|
1998
|
-
* @typedef {Object} RafService
|
|
1999
|
-
* @property {(key:String, callback:(props:RafServiceProps) => void) => void} add
|
|
2000
|
-
* Add a function to the resize service. The key must be uniq.
|
|
2001
|
-
* @property {() => RafServiceProps} props
|
|
2002
|
-
* Get the current values of the resize service props.
|
|
2003
|
-
*/
|
|
2004
|
-
|
|
2005
|
-
/**
|
|
2006
|
-
* Tick service
|
|
2007
|
-
*/
|
|
2008
|
-
|
|
2009
|
-
var Raf = /*#__PURE__*/function (_Service) {
|
|
2010
|
-
_inheritsLoose(Raf, _Service);
|
|
2011
|
-
|
|
2012
|
-
/** @type {Boolean} Whether the loop is running or not. */
|
|
2013
|
-
|
|
2014
|
-
/** @type {number} */
|
|
2015
|
-
|
|
2016
|
-
/**
|
|
2017
|
-
* Bind loop to the instance.
|
|
2018
|
-
*/
|
|
2019
|
-
function Raf() {
|
|
2020
|
-
var _this;
|
|
2021
|
-
|
|
2022
|
-
_this = _Service.call(this) || this;
|
|
2023
|
-
_this.isTicking = false;
|
|
2024
|
-
_this.id = 0;
|
|
2025
|
-
_this.raf = getRaf();
|
|
2026
|
-
_this.cancelRaf = getCancelRaf();
|
|
2027
|
-
_this.loop = _this.loop.bind(_assertThisInitialized(_this));
|
|
2028
|
-
return _this;
|
|
2029
|
-
}
|
|
2030
|
-
/**
|
|
2031
|
-
* Start the requestAnimationFrame loop.
|
|
2032
|
-
*
|
|
2033
|
-
* @return {Raf}
|
|
2034
|
-
*/
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
var _proto = Raf.prototype;
|
|
2038
|
-
|
|
2039
|
-
_proto.init = function init() {
|
|
2040
|
-
this.isTicking = true;
|
|
2041
|
-
this.loop();
|
|
2042
|
-
return this;
|
|
2043
|
-
}
|
|
2044
|
-
/**
|
|
2045
|
-
* Loop method.
|
|
2046
|
-
*/
|
|
2047
|
-
;
|
|
2048
|
-
|
|
2049
|
-
_proto.loop = function loop() {
|
|
2050
|
-
this.trigger(this.props);
|
|
2051
|
-
|
|
2052
|
-
if (!this.isTicking) {
|
|
2053
|
-
return;
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
this.id = this.raf(this.loop);
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Stop the requestAnimationFrame loop.
|
|
2060
|
-
*
|
|
2061
|
-
* @return {Raf}
|
|
2062
|
-
*/
|
|
2063
|
-
;
|
|
2064
|
-
|
|
2065
|
-
_proto.kill = function kill() {
|
|
2066
|
-
this.cancelRaf(this.id);
|
|
2067
|
-
this.isTicking = false;
|
|
2068
|
-
return this;
|
|
2069
|
-
}
|
|
2070
|
-
/**
|
|
2071
|
-
* Get raf props.
|
|
2072
|
-
*
|
|
2073
|
-
* @todo Return elapsed time / index?
|
|
2074
|
-
* @type {Object}
|
|
2075
|
-
*/
|
|
2076
|
-
;
|
|
2077
|
-
|
|
2078
|
-
_createClass(Raf, [{
|
|
2079
|
-
key: "props",
|
|
2080
|
-
get: function get() {
|
|
2081
|
-
return {
|
|
2082
|
-
time: window.performance.now()
|
|
2083
|
-
};
|
|
2084
|
-
}
|
|
2085
|
-
}]);
|
|
2086
|
-
|
|
2087
|
-
return Raf;
|
|
2088
|
-
}(Service);
|
|
2089
|
-
|
|
2090
|
-
var instance$1 = null;
|
|
2091
|
-
/**
|
|
2092
|
-
* Use the RequestAnimationFrame (raf) service.
|
|
2093
|
-
*
|
|
2094
|
-
* ```js
|
|
2095
|
-
* import { useRaf } from '@studiometa/js/services';
|
|
2096
|
-
* const { add, remove, props } = useRag();
|
|
2097
|
-
* add(id, (props) => {});
|
|
2098
|
-
* remove(id);
|
|
2099
|
-
* props();
|
|
2100
|
-
* ```
|
|
2101
|
-
*
|
|
2102
|
-
* @return {ServiceInterface & RafService}
|
|
2103
|
-
*/
|
|
2104
|
-
|
|
2105
|
-
function useRaf$1() {
|
|
2106
|
-
if (!instance$1) {
|
|
2107
|
-
instance$1 = new Raf();
|
|
2108
|
-
}
|
|
2109
|
-
|
|
2110
|
-
var add = instance$1.add.bind(instance$1);
|
|
2111
|
-
var remove = instance$1.remove.bind(instance$1);
|
|
2112
|
-
var has = instance$1.has.bind(instance$1); // eslint-disable-next-line require-jsdoc
|
|
2113
|
-
|
|
2114
|
-
function props() {
|
|
2115
|
-
return instance$1.props;
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
return {
|
|
2119
|
-
add: add,
|
|
2120
|
-
remove: remove,
|
|
2121
|
-
has: has,
|
|
2122
|
-
props: props
|
|
2123
|
-
};
|
|
2124
|
-
}
|
|
2125
|
-
|
|
2126
|
-
/**
|
|
2127
|
-
* Returns a function, that, as long as it continues to be invoked,
|
|
2128
|
-
* will not be triggered. The function will be called after it stops
|
|
2129
|
-
* being called for N milliseconds.
|
|
2130
|
-
*
|
|
2131
|
-
* @param {(...args:any[]) => void} fn The function to call.
|
|
2132
|
-
* @param {Number=} [delay=300] The delay in ms to wait before calling the function.
|
|
2133
|
-
* @return {(...args:any[]) => void} The debounced function.
|
|
2134
|
-
*/
|
|
2135
|
-
function debounce(fn, delay) {
|
|
2136
|
-
if (delay === void 0) {
|
|
2137
|
-
delay = 300;
|
|
2138
|
-
}
|
|
2139
|
-
|
|
2140
|
-
var timeout;
|
|
2141
|
-
return function debounced() {
|
|
2142
|
-
var _arguments = arguments;
|
|
2143
|
-
clearTimeout(timeout);
|
|
2144
|
-
timeout = setTimeout(function () {
|
|
2145
|
-
fn.apply(void 0, [].slice.call(_arguments));
|
|
2146
|
-
}, delay);
|
|
2147
|
-
};
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
/**
|
|
2151
|
-
* @typedef {import('./index').ServiceInterface} ServiceInterface
|
|
2152
|
-
*/
|
|
2153
|
-
|
|
2154
|
-
/**
|
|
2155
|
-
* @typedef {Object} ResizeServiceProps
|
|
2156
|
-
* @property {Number} width
|
|
2157
|
-
* @property {Number} height
|
|
2158
|
-
* @property {Number} ratio
|
|
2159
|
-
* @property {'square'|'landscape'|'portrait'} orientation
|
|
2160
|
-
* @property {String} [breakpoint]
|
|
2161
|
-
* @property {String[]} [breakpoints]
|
|
2162
|
-
*/
|
|
2163
|
-
|
|
2164
|
-
/**
|
|
2165
|
-
* @typedef {Object} ResizeService
|
|
2166
|
-
* @property {(key:String, callback:(props:ResizeServiceProps) => void) => void} add
|
|
2167
|
-
* Add a function to the resize service. The key must be uniq.
|
|
2168
|
-
* @property {() => ResizeServiceProps} props
|
|
2169
|
-
* Get the current values of the resize service props.
|
|
2170
|
-
*/
|
|
2171
|
-
|
|
2172
|
-
/**
|
|
2173
|
-
* Resize service
|
|
2174
|
-
*
|
|
2175
|
-
* ```
|
|
2176
|
-
* import { useResize } from '@studiometa/js/services';
|
|
2177
|
-
* const { add, remove, props } = useResize();
|
|
2178
|
-
* add(key, (props) => {});
|
|
2179
|
-
* remove(key);
|
|
2180
|
-
* props();
|
|
2181
|
-
* ```
|
|
2182
|
-
*/
|
|
2183
|
-
|
|
2184
|
-
var Resize = /*#__PURE__*/function (_Service) {
|
|
2185
|
-
_inheritsLoose(Resize, _Service);
|
|
2186
|
-
|
|
2187
|
-
function Resize() {
|
|
2188
|
-
return _Service.apply(this, arguments) || this;
|
|
2189
|
-
}
|
|
2190
|
-
|
|
2191
|
-
var _proto = Resize.prototype;
|
|
2192
|
-
|
|
2193
|
-
/**
|
|
2194
|
-
* Bind the handler to the resize event.
|
|
2195
|
-
*
|
|
2196
|
-
* @return {this}
|
|
2197
|
-
*/
|
|
2198
|
-
_proto.init = function init() {
|
|
2199
|
-
var _this = this;
|
|
2200
|
-
|
|
2201
|
-
this.handler = debounce(function () {
|
|
2202
|
-
_this.trigger(_this.props);
|
|
2203
|
-
}).bind(this);
|
|
2204
|
-
|
|
2205
|
-
if (this.canUseResizeObserver) {
|
|
2206
|
-
this.resizeObserver = new ResizeObserver(this.handler);
|
|
2207
|
-
this.resizeObserver.observe(document.documentElement);
|
|
2208
|
-
} else {
|
|
2209
|
-
window.addEventListener('resize', this.handler);
|
|
2210
|
-
}
|
|
2211
|
-
|
|
2212
|
-
return this;
|
|
2213
|
-
}
|
|
2214
|
-
/**
|
|
2215
|
-
* Unbind the handler from the resize event.
|
|
2216
|
-
*
|
|
2217
|
-
* @return {this}
|
|
2218
|
-
*/
|
|
2219
|
-
;
|
|
2220
|
-
|
|
2221
|
-
_proto.kill = function kill() {
|
|
2222
|
-
if (this.canUseResizeObserver) {
|
|
2223
|
-
this.resizeObserver.disconnect();
|
|
2224
|
-
} else {
|
|
2225
|
-
window.removeEventListener('resize', this.handler);
|
|
2226
|
-
}
|
|
2227
|
-
|
|
2228
|
-
delete this.resizeObserver;
|
|
2229
|
-
return this;
|
|
2230
|
-
}
|
|
2231
|
-
/**
|
|
2232
|
-
* Get resize props.
|
|
2233
|
-
*
|
|
2234
|
-
* @type {ResizeServiceProps}
|
|
2235
|
-
*/
|
|
2236
|
-
;
|
|
2237
|
-
|
|
2238
|
-
_createClass(Resize, [{
|
|
2239
|
-
key: "props",
|
|
2240
|
-
get: function get() {
|
|
2241
|
-
/** @type {ResizeServiceProps} [description] */
|
|
2242
|
-
var props = {
|
|
2243
|
-
width: window.innerWidth,
|
|
2244
|
-
height: window.innerHeight,
|
|
2245
|
-
ratio: window.innerWidth / window.innerHeight,
|
|
2246
|
-
orientation: 'square'
|
|
2247
|
-
};
|
|
2248
|
-
|
|
2249
|
-
if (props.ratio > 1) {
|
|
2250
|
-
props.orientation = 'landscape';
|
|
2251
|
-
}
|
|
2252
|
-
|
|
2253
|
-
if (props.ratio < 1) {
|
|
2254
|
-
props.orientation = 'portrait';
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
if (this.breakpointElement) {
|
|
2258
|
-
props.breakpoint = this.breakpoint;
|
|
2259
|
-
props.breakpoints = this.breakpoints;
|
|
2260
|
-
}
|
|
2261
|
-
|
|
2262
|
-
return props;
|
|
2263
|
-
}
|
|
2264
|
-
/**
|
|
2265
|
-
* The element holding the breakpoints data.
|
|
2266
|
-
* @return {HTMLElement}
|
|
2267
|
-
*/
|
|
2268
|
-
|
|
2269
|
-
}, {
|
|
2270
|
-
key: "breakpointElement",
|
|
2271
|
-
get: function get() {
|
|
2272
|
-
return document.querySelector('[data-breakpoint]') || null;
|
|
2273
|
-
}
|
|
2274
|
-
/**
|
|
2275
|
-
* Get the current breakpoint.
|
|
2276
|
-
* @return {String}
|
|
2277
|
-
*/
|
|
2278
|
-
|
|
2279
|
-
}, {
|
|
2280
|
-
key: "breakpoint",
|
|
2281
|
-
get: function get() {
|
|
2282
|
-
return window.getComputedStyle(this.breakpointElement, '::before').getPropertyValue('content').replace(/"/g, '');
|
|
2283
|
-
}
|
|
2284
|
-
/**
|
|
2285
|
-
* Get all breakpoints.
|
|
2286
|
-
* @return {Array}
|
|
2287
|
-
*/
|
|
2288
|
-
|
|
2289
|
-
}, {
|
|
2290
|
-
key: "breakpoints",
|
|
2291
|
-
get: function get() {
|
|
2292
|
-
var breakpoints = window.getComputedStyle(this.breakpointElement, '::after').getPropertyValue('content').replace(/"/g, '');
|
|
2293
|
-
return breakpoints.split(',');
|
|
2294
|
-
}
|
|
2295
|
-
/**
|
|
2296
|
-
* Test if we can use the `ResizeObserver` API.
|
|
2297
|
-
* @return {Boolean}
|
|
2298
|
-
*/
|
|
2299
|
-
|
|
2300
|
-
}, {
|
|
2301
|
-
key: "canUseResizeObserver",
|
|
2302
|
-
get: function get() {
|
|
2303
|
-
return typeof window.ResizeObserver !== 'undefined';
|
|
2304
|
-
}
|
|
2305
|
-
}]);
|
|
2306
|
-
|
|
2307
|
-
return Resize;
|
|
2308
|
-
}(Service);
|
|
2309
|
-
|
|
2310
|
-
var resize = null;
|
|
2311
|
-
/**
|
|
2312
|
-
* Use the resize service.
|
|
2313
|
-
*
|
|
2314
|
-
* ```js
|
|
2315
|
-
* import useResize from '@studiometa/js-toolkit/services/resize';
|
|
2316
|
-
* const { add, remove, props } = useResize();
|
|
2317
|
-
* add(key, (props) => {});
|
|
2318
|
-
* remove(key);
|
|
2319
|
-
* props();
|
|
2320
|
-
* ```
|
|
2321
|
-
* @return {ServiceInterface & ResizeService}
|
|
2322
|
-
*/
|
|
2323
|
-
|
|
2324
|
-
function useResize() {
|
|
2325
|
-
if (!resize) {
|
|
2326
|
-
resize = new Resize();
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
|
-
var add = resize.add.bind(resize);
|
|
2330
|
-
var remove = resize.remove.bind(resize);
|
|
2331
|
-
var has = resize.has.bind(resize);
|
|
2332
|
-
|
|
2333
|
-
var props = function props() {
|
|
2334
|
-
return resize.props;
|
|
2335
|
-
};
|
|
2336
|
-
|
|
2337
|
-
return {
|
|
2338
|
-
add: add,
|
|
2339
|
-
remove: remove,
|
|
2340
|
-
has: has,
|
|
2341
|
-
props: props
|
|
2342
|
-
};
|
|
2343
|
-
}
|
|
2344
|
-
|
|
2345
|
-
/**
|
|
2346
|
-
* @typedef {import('./index').ServiceInterface} ServiceInterface
|
|
2347
|
-
*/
|
|
2348
|
-
|
|
2349
|
-
/**
|
|
2350
|
-
* @typedef {Object} ScrollServiceProps
|
|
2351
|
-
* @property {Number} x
|
|
2352
|
-
* @property {Number} y
|
|
2353
|
-
* @property {{ x: Boolean, y: Boolean }} changed
|
|
2354
|
-
* @property {{ x: Number, y: Number }} last
|
|
2355
|
-
* @property {{ x: Number, y: Number }} delta
|
|
2356
|
-
* @property {{ x: Number, y: Number }} progress
|
|
2357
|
-
* @property {{ x: Number, y: Number }} max
|
|
2358
|
-
* @property {{ x: 'LEFT'|'RIGHT'|'NONE', y: 'UP'|'DOWN'|'NONE' }} direction
|
|
2359
|
-
*/
|
|
2360
|
-
|
|
2361
|
-
/**
|
|
2362
|
-
* @typedef {Object} ScrollService
|
|
2363
|
-
* @property {(key:String, callback:(props:ScrollServiceProps) => void) => void} add
|
|
2364
|
-
* Add a function to the resize service. The key must be uniq.
|
|
2365
|
-
* @property {() => ScrollServiceProps} props
|
|
2366
|
-
* Get the current values of the resize service props.
|
|
2367
|
-
*/
|
|
2368
|
-
|
|
2369
|
-
/**
|
|
2370
|
-
* Scroll service
|
|
2371
|
-
*/
|
|
2372
|
-
|
|
2373
|
-
var Scroll = /*#__PURE__*/function (_Service) {
|
|
2374
|
-
_inheritsLoose(Scroll, _Service);
|
|
2375
|
-
|
|
2376
|
-
function Scroll() {
|
|
2377
|
-
var _this;
|
|
2378
|
-
|
|
2379
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2380
|
-
args[_key] = arguments[_key];
|
|
2381
|
-
}
|
|
2382
|
-
|
|
2383
|
-
_this = _Service.call.apply(_Service, [this].concat(args)) || this;
|
|
2384
|
-
_this.y = window.pageYOffset;
|
|
2385
|
-
_this.yLast = window.pageYOffset;
|
|
2386
|
-
_this.x = window.pageXOffset;
|
|
2387
|
-
_this.xLast = window.pageXOffset;
|
|
2388
|
-
return _this;
|
|
2389
|
-
}
|
|
2390
|
-
|
|
2391
|
-
var _proto = Scroll.prototype;
|
|
2392
|
-
|
|
2393
|
-
/**
|
|
2394
|
-
* Bind the handler to the scroll event.
|
|
2395
|
-
*
|
|
2396
|
-
* @return {Scroll}
|
|
2397
|
-
*/
|
|
2398
|
-
_proto.init = function init() {
|
|
2399
|
-
document.addEventListener('scroll', this, {
|
|
2400
|
-
passive: true,
|
|
2401
|
-
capture: true
|
|
2402
|
-
});
|
|
2403
|
-
return this;
|
|
2404
|
-
}
|
|
2405
|
-
/**
|
|
2406
|
-
* Debounced handler.
|
|
2407
|
-
*
|
|
2408
|
-
* @return {() => void}
|
|
2409
|
-
*/
|
|
2410
|
-
;
|
|
2411
|
-
|
|
2412
|
-
/**
|
|
2413
|
-
* Scroll event handler.
|
|
2414
|
-
*
|
|
2415
|
-
* @return {void}
|
|
2416
|
-
*/
|
|
2417
|
-
_proto.handleEvent = function handleEvent() {
|
|
2418
|
-
this.trigger(this.props);
|
|
2419
|
-
this.debouncedHandler();
|
|
2420
|
-
}
|
|
2421
|
-
/**
|
|
2422
|
-
* Unbind the handler from the scroll event.
|
|
2423
|
-
*
|
|
2424
|
-
* @return {Scroll}
|
|
2425
|
-
*/
|
|
2426
|
-
;
|
|
2427
|
-
|
|
2428
|
-
_proto.kill = function kill() {
|
|
2429
|
-
document.removeEventListener('scroll', this);
|
|
2430
|
-
return this;
|
|
2431
|
-
}
|
|
2432
|
-
/**
|
|
2433
|
-
* Get scroll props.
|
|
2434
|
-
*
|
|
2435
|
-
* @type {Object}
|
|
2436
|
-
*/
|
|
2437
|
-
;
|
|
2438
|
-
|
|
2439
|
-
_createClass(Scroll, [{
|
|
2440
|
-
key: "debouncedHandler",
|
|
2441
|
-
get: function get() {
|
|
2442
|
-
var _this2 = this;
|
|
2443
|
-
|
|
2444
|
-
var debounced = debounce(function () {
|
|
2445
|
-
_this2.trigger(_this2.props);
|
|
2446
|
-
}, 0); // Define property to avoid multiple call to the getter
|
|
2447
|
-
|
|
2448
|
-
Object.defineProperty(this, 'debouncedHandler', {
|
|
2449
|
-
value: debounced
|
|
2450
|
-
});
|
|
2451
|
-
return debounced;
|
|
2452
|
-
}
|
|
2453
|
-
}, {
|
|
2454
|
-
key: "props",
|
|
2455
|
-
get: function get() {
|
|
2456
|
-
this.yLast = this.y;
|
|
2457
|
-
this.xLast = this.x; // Check scroll Y
|
|
2458
|
-
|
|
2459
|
-
if (window.pageYOffset !== this.y) {
|
|
2460
|
-
this.y = window.pageYOffset;
|
|
2461
|
-
} // Check scroll x
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
if (window.pageXOffset !== this.x) {
|
|
2465
|
-
this.x = window.pageXOffset;
|
|
2466
|
-
}
|
|
2467
|
-
|
|
2468
|
-
return {
|
|
2469
|
-
x: this.x,
|
|
2470
|
-
y: this.y,
|
|
2471
|
-
changed: {
|
|
2472
|
-
x: this.x !== this.xLast,
|
|
2473
|
-
y: this.y !== this.yLast
|
|
2474
|
-
},
|
|
2475
|
-
last: {
|
|
2476
|
-
x: this.xLast,
|
|
2477
|
-
y: this.yLast
|
|
2478
|
-
},
|
|
2479
|
-
delta: {
|
|
2480
|
-
x: this.x - this.xLast,
|
|
2481
|
-
y: this.y - this.yLast
|
|
2482
|
-
},
|
|
2483
|
-
progress: {
|
|
2484
|
-
x: this.max.x === 0 ? 1 : this.x / this.max.x,
|
|
2485
|
-
y: this.max.y === 0 ? 1 : this.y / this.max.y
|
|
2486
|
-
},
|
|
2487
|
-
direction: {
|
|
2488
|
-
/* eslint-disable no-nested-ternary */
|
|
2489
|
-
x: this.x > this.xLast ? 'RIGHT' : this.x < this.xLast ? 'LEFT' : 'NONE',
|
|
2490
|
-
y: this.y > this.yLast ? 'DOWN' : this.y < this.yLast ? 'UP' : 'NONE'
|
|
2491
|
-
/* eslint-enable no-nested-ternary */
|
|
2492
|
-
|
|
2493
|
-
},
|
|
2494
|
-
max: this.max
|
|
2495
|
-
};
|
|
2496
|
-
}
|
|
2497
|
-
/**
|
|
2498
|
-
* Get scroll max values.
|
|
2499
|
-
*
|
|
2500
|
-
* @type {Object}
|
|
2501
|
-
*/
|
|
2502
|
-
|
|
2503
|
-
}, {
|
|
2504
|
-
key: "max",
|
|
2505
|
-
get: function get() {
|
|
2506
|
-
return {
|
|
2507
|
-
x: (document.scrollingElement || document.body).scrollWidth - window.innerWidth,
|
|
2508
|
-
y: (document.scrollingElement || document.body).scrollHeight - window.innerHeight
|
|
2509
|
-
};
|
|
2510
|
-
}
|
|
2511
|
-
}]);
|
|
2512
|
-
|
|
2513
|
-
return Scroll;
|
|
2514
|
-
}(Service);
|
|
2515
|
-
|
|
2516
|
-
var scroll = null;
|
|
2517
|
-
/**
|
|
2518
|
-
* Use the scroll service.
|
|
2519
|
-
*
|
|
2520
|
-
* ```js
|
|
2521
|
-
* import { useScroll } from '@studiometa/js-toolkit/services';
|
|
2522
|
-
* const { add, remove, props } = useScroll();
|
|
2523
|
-
* add(key, (props) => {});
|
|
2524
|
-
* remove(key);
|
|
2525
|
-
* props();
|
|
2526
|
-
* ```
|
|
2527
|
-
*
|
|
2528
|
-
* @return {ServiceInterface & ScrollService}
|
|
2529
|
-
*/
|
|
2530
|
-
|
|
2531
|
-
function useScroll() {
|
|
2532
|
-
if (!scroll) {
|
|
2533
|
-
scroll = new Scroll();
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
var add = scroll.add.bind(scroll);
|
|
2537
|
-
var remove = scroll.remove.bind(scroll);
|
|
2538
|
-
var has = scroll.has.bind(scroll);
|
|
2539
|
-
|
|
2540
|
-
var props = function props() {
|
|
2541
|
-
return scroll.props;
|
|
2542
|
-
};
|
|
2543
|
-
|
|
2544
|
-
return {
|
|
2545
|
-
add: add,
|
|
2546
|
-
remove: remove,
|
|
2547
|
-
has: has,
|
|
2548
|
-
props: props
|
|
2549
|
-
};
|
|
2550
|
-
}
|
|
2551
|
-
|
|
2552
|
-
var keyCodes = {
|
|
2553
|
-
ENTER: 13,
|
|
2554
|
-
SPACE: 32,
|
|
2555
|
-
TAB: 9,
|
|
2556
|
-
ESC: 27,
|
|
2557
|
-
LEFT: 37,
|
|
2558
|
-
UP: 38,
|
|
2559
|
-
RIGHT: 39,
|
|
2560
|
-
DOWN: 40
|
|
2561
|
-
};
|
|
2562
|
-
|
|
2563
|
-
/**
|
|
2564
|
-
* @typedef {import('./index').ServiceInterface} ServiceInterface
|
|
2565
|
-
*/
|
|
2566
|
-
|
|
2567
|
-
/**
|
|
2568
|
-
* @typedef {Object} KeyServiceProps
|
|
2569
|
-
* @property {KeyboardEvent} event
|
|
2570
|
-
* @property {Number} triggered
|
|
2571
|
-
* @property {Boolean} isUp
|
|
2572
|
-
* @property {Boolean} isDown
|
|
2573
|
-
* @property {Boolean} ENTER
|
|
2574
|
-
* @property {Boolean} SPACE
|
|
2575
|
-
* @property {Boolean} TAB
|
|
2576
|
-
* @property {Boolean} ESC
|
|
2577
|
-
* @property {Boolean} LEFT
|
|
2578
|
-
* @property {Boolean} UP
|
|
2579
|
-
* @property {Boolean} RIGHT
|
|
2580
|
-
* @property {Boolean} DOWN
|
|
2581
|
-
*/
|
|
2582
|
-
|
|
2583
|
-
/**
|
|
2584
|
-
* @typedef {Object} KeyService
|
|
2585
|
-
* @property {(key:String, callback:(props:KeyServiceProps) => void) => void} add
|
|
2586
|
-
* Add a function to the resize service. The key must be uniq.
|
|
2587
|
-
* @property {() => KeyServiceProps} props
|
|
2588
|
-
* Get the current values of the resize service props.
|
|
2589
|
-
*/
|
|
2590
|
-
|
|
2591
|
-
/**
|
|
2592
|
-
* Scroll service
|
|
2593
|
-
*/
|
|
2594
|
-
|
|
2595
|
-
var Key = /*#__PURE__*/function (_Service) {
|
|
2596
|
-
_inheritsLoose(Key, _Service);
|
|
2597
|
-
|
|
2598
|
-
function Key() {
|
|
2599
|
-
var _this;
|
|
2600
|
-
|
|
2601
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2602
|
-
args[_key] = arguments[_key];
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
_this = _Service.call.apply(_Service, [this].concat(args)) || this;
|
|
2606
|
-
_this.event = {};
|
|
2607
|
-
_this.triggered = 0;
|
|
2608
|
-
_this.previousEvent = {};
|
|
2609
|
-
return _this;
|
|
2610
|
-
}
|
|
2611
|
-
|
|
2612
|
-
var _proto = Key.prototype;
|
|
2613
|
-
|
|
2614
|
-
/**
|
|
2615
|
-
* Bind the handler to the keyboard event.
|
|
2616
|
-
*
|
|
2617
|
-
* @return {Key}
|
|
2618
|
-
*/
|
|
2619
|
-
_proto.init = function init() {
|
|
2620
|
-
var _this2 = this;
|
|
2621
|
-
|
|
2622
|
-
this.handler = function (event) {
|
|
2623
|
-
_this2.event = event;
|
|
2624
|
-
|
|
2625
|
-
_this2.trigger(_this2.props);
|
|
2626
|
-
};
|
|
2627
|
-
|
|
2628
|
-
document.addEventListener('keydown', this.handler, {
|
|
2629
|
-
passive: false
|
|
2630
|
-
});
|
|
2631
|
-
document.addEventListener('keyup', this.handler, {
|
|
2632
|
-
passive: false
|
|
2633
|
-
});
|
|
2634
|
-
return this;
|
|
2635
|
-
}
|
|
2636
|
-
/**
|
|
2637
|
-
* Unbind the handler from the keyboard event.
|
|
2638
|
-
*
|
|
2639
|
-
* @return {Key}
|
|
2640
|
-
*/
|
|
2641
|
-
;
|
|
2642
|
-
|
|
2643
|
-
_proto.kill = function kill() {
|
|
2644
|
-
document.removeEventListener('keydown', this.handler);
|
|
2645
|
-
document.removeEventListener('keyup', this.handler);
|
|
2646
|
-
return this;
|
|
2647
|
-
}
|
|
2648
|
-
/**
|
|
2649
|
-
* Get keyboard props.
|
|
2650
|
-
*
|
|
2651
|
-
* @type {Object}
|
|
2652
|
-
*/
|
|
2653
|
-
;
|
|
2654
|
-
|
|
2655
|
-
_createClass(Key, [{
|
|
2656
|
-
key: "props",
|
|
2657
|
-
get: function get() {
|
|
2658
|
-
var _this3 = this;
|
|
2659
|
-
|
|
2660
|
-
var keys = Object.entries(keyCodes).reduce(function (acc, _ref) {
|
|
2661
|
-
var name = _ref[0],
|
|
2662
|
-
code = _ref[1];
|
|
2663
|
-
acc[name] = code === _this3.event.keyCode;
|
|
2664
|
-
return acc;
|
|
2665
|
-
}, {});
|
|
2666
|
-
|
|
2667
|
-
if (!this.previousEvent.type) {
|
|
2668
|
-
this.triggered = 0;
|
|
2669
|
-
}
|
|
2670
|
-
|
|
2671
|
-
if (this.event.type === 'keydown' && this.previousEvent.type === 'keydown') {
|
|
2672
|
-
this.triggered += 1;
|
|
2673
|
-
} else {
|
|
2674
|
-
this.triggered = 1;
|
|
2675
|
-
}
|
|
2676
|
-
|
|
2677
|
-
this.previousEvent = this.event;
|
|
2678
|
-
return _extends({
|
|
2679
|
-
event: this.event,
|
|
2680
|
-
triggered: this.triggered,
|
|
2681
|
-
direction: this.event.type === 'keydown' ? 'down' : 'up',
|
|
2682
|
-
isUp: this.event.type === 'keyup',
|
|
2683
|
-
isDown: this.event.type === 'keydown'
|
|
2684
|
-
}, keys);
|
|
2685
|
-
}
|
|
2686
|
-
}]);
|
|
2687
|
-
|
|
2688
|
-
return Key;
|
|
2689
|
-
}(Service);
|
|
2690
|
-
|
|
2691
|
-
var key = null;
|
|
2692
|
-
/**
|
|
2693
|
-
* Use the keyboard service.
|
|
2694
|
-
*
|
|
2695
|
-
* ```js
|
|
2696
|
-
* import { useKey } from '@studiometa/js-toolkit/services';
|
|
2697
|
-
* const { add, remove, props } = useKey();
|
|
2698
|
-
* add(key, (props) => {});
|
|
2699
|
-
* remove(key);
|
|
2700
|
-
* props();
|
|
2701
|
-
* ```
|
|
2702
|
-
*
|
|
2703
|
-
* @return {ServiceInterface & KeyService}
|
|
2704
|
-
*/
|
|
2705
|
-
|
|
2706
|
-
function useKey() {
|
|
2707
|
-
if (!key) {
|
|
2708
|
-
key = new Key();
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2711
|
-
var add = key.add.bind(key);
|
|
2712
|
-
var remove = key.remove.bind(key);
|
|
2713
|
-
var has = key.has.bind(key);
|
|
2714
|
-
|
|
2715
|
-
var props = function props() {
|
|
2716
|
-
return key.props;
|
|
2717
|
-
};
|
|
2718
|
-
|
|
2719
|
-
return {
|
|
2720
|
-
add: add,
|
|
2721
|
-
remove: remove,
|
|
2722
|
-
has: has,
|
|
2723
|
-
props: props
|
|
2724
|
-
};
|
|
2725
|
-
}
|
|
2726
|
-
|
|
2727
|
-
/**
|
|
2728
|
-
* @typedef {import('./index').ServiceInterface} ServiceInterface
|
|
2729
|
-
*/
|
|
2730
|
-
|
|
2731
|
-
/**
|
|
2732
|
-
* @typedef {Object} LoadServiceProps
|
|
2733
|
-
* @property {DOMHighResTimeStamp} time
|
|
2734
|
-
*/
|
|
2735
|
-
|
|
2736
|
-
/**
|
|
2737
|
-
* @typedef {Object} LoadService
|
|
2738
|
-
* @property {(key:String, callback:(props:LoadServiceProps) => void) => void} add
|
|
2739
|
-
* Add a function to the resize service. The key must be uniq.
|
|
2740
|
-
* @property {() => LoadServiceProps} props
|
|
2741
|
-
* Get the current values of the resize service props.
|
|
2742
|
-
*/
|
|
2743
|
-
|
|
2744
|
-
/**
|
|
2745
|
-
* Load service
|
|
2746
|
-
*/
|
|
2747
|
-
|
|
2748
|
-
var Load = /*#__PURE__*/function (_Service) {
|
|
2749
|
-
_inheritsLoose(Load, _Service);
|
|
2750
|
-
|
|
2751
|
-
function Load() {
|
|
2752
|
-
return _Service.apply(this, arguments) || this;
|
|
2753
|
-
}
|
|
2754
|
-
|
|
2755
|
-
var _proto = Load.prototype;
|
|
2756
|
-
|
|
2757
|
-
/**
|
|
2758
|
-
* Start the requestAnimationFrame loop.
|
|
2759
|
-
*
|
|
2760
|
-
* @return {Load}
|
|
2761
|
-
*/
|
|
2762
|
-
_proto.init = function init() {
|
|
2763
|
-
var _this = this;
|
|
2764
|
-
|
|
2765
|
-
this.handler = function () {
|
|
2766
|
-
_this.trigger(_this.props);
|
|
2767
|
-
};
|
|
2768
|
-
|
|
2769
|
-
window.addEventListener('load', this.handler);
|
|
2770
|
-
return this;
|
|
2771
|
-
}
|
|
2772
|
-
/**
|
|
2773
|
-
* Stop the requestAnimationFrame loop.
|
|
2774
|
-
*
|
|
2775
|
-
* @return {Load}
|
|
2776
|
-
*/
|
|
2777
|
-
;
|
|
2778
|
-
|
|
2779
|
-
_proto.kill = function kill() {
|
|
2780
|
-
window.removeEventListener('load', this.handler);
|
|
2781
|
-
return this;
|
|
2782
|
-
}
|
|
2783
|
-
/**
|
|
2784
|
-
* Get raf props.
|
|
2785
|
-
*
|
|
2786
|
-
* @todo Return elapsed time / index?
|
|
2787
|
-
* @type {Object}
|
|
2788
|
-
*/
|
|
2789
|
-
;
|
|
2790
|
-
|
|
2791
|
-
_createClass(Load, [{
|
|
2792
|
-
key: "props",
|
|
2793
|
-
get: function get() {
|
|
2794
|
-
return {};
|
|
2795
|
-
}
|
|
2796
|
-
}]);
|
|
2797
|
-
|
|
2798
|
-
return Load;
|
|
2799
|
-
}(Service);
|
|
2800
|
-
|
|
2801
|
-
var instance = null;
|
|
2802
|
-
/**
|
|
2803
|
-
* Use the load service.
|
|
2804
|
-
*
|
|
2805
|
-
* ```js
|
|
2806
|
-
* import { useLoad } from '@studiometa/js/services';
|
|
2807
|
-
* const { add, remove, props } = useRag();
|
|
2808
|
-
* add(id, (props) => {});
|
|
2809
|
-
* remove(id);
|
|
2810
|
-
* props();
|
|
2811
|
-
* ```
|
|
2812
|
-
*
|
|
2813
|
-
* @return {ServiceInterface & LoadService}
|
|
2814
|
-
*/
|
|
2815
|
-
|
|
2816
|
-
function useRaf() {
|
|
2817
|
-
if (!instance) {
|
|
2818
|
-
instance = new Load();
|
|
2819
|
-
}
|
|
2820
|
-
|
|
2821
|
-
var add = instance.add.bind(instance);
|
|
2822
|
-
var remove = instance.remove.bind(instance);
|
|
2823
|
-
var has = instance.has.bind(instance); // eslint-disable-next-line require-jsdoc
|
|
2824
|
-
|
|
2825
|
-
function props() {
|
|
2826
|
-
return instance.props;
|
|
2827
|
-
}
|
|
2828
|
-
|
|
2829
|
-
return {
|
|
2830
|
-
add: add,
|
|
2831
|
-
remove: remove,
|
|
2832
|
-
has: has,
|
|
2833
|
-
props: props
|
|
2834
|
-
};
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
/**
|
|
2838
|
-
* @typedef {import('../index').default} Base
|
|
2839
|
-
* @typedef {import('../../../services').ServiceInterface} ServiceInterface
|
|
2840
|
-
*/
|
|
2841
|
-
|
|
2842
|
-
/**
|
|
2843
|
-
* @type {Record<string, () => ServiceInterface>}
|
|
2844
|
-
*/
|
|
2845
|
-
|
|
2846
|
-
var SERVICES_MAP = {
|
|
2847
|
-
scrolled: useScroll,
|
|
2848
|
-
resized: useResize,
|
|
2849
|
-
ticked: useRaf$1,
|
|
2850
|
-
moved: usePointer,
|
|
2851
|
-
keyed: useKey,
|
|
2852
|
-
loaded: useRaf
|
|
2853
|
-
};
|
|
2854
|
-
/**
|
|
2855
|
-
* @typedef {keyof SERVICES_MAP} ServiceName
|
|
2856
|
-
*/
|
|
2857
|
-
|
|
2858
|
-
/**
|
|
2859
|
-
* Services management for the Base class.
|
|
2860
|
-
*/
|
|
2861
|
-
|
|
2862
|
-
var _base = /*#__PURE__*/_classPrivateFieldLooseKey("base");
|
|
2863
|
-
|
|
2864
|
-
var Services = /*#__PURE__*/function () {
|
|
2865
|
-
/** @type {Base} */
|
|
2866
|
-
|
|
2867
|
-
/**
|
|
2868
|
-
* Class constructor.
|
|
2869
|
-
* @param {Base} instance The Base instance.
|
|
2870
|
-
*/
|
|
2871
|
-
function Services(instance) {
|
|
2872
|
-
Object.defineProperty(this, _base, {
|
|
2873
|
-
writable: true,
|
|
2874
|
-
value: void 0
|
|
2875
|
-
});
|
|
2876
|
-
_classPrivateFieldLooseBase(this, _base)[_base] = instance;
|
|
2877
|
-
}
|
|
2878
|
-
/**
|
|
2879
|
-
* Test if the given service is registered.
|
|
2880
|
-
*
|
|
2881
|
-
* @param {ServiceName} service The name of the service.
|
|
2882
|
-
* @return {Boolean}
|
|
2883
|
-
*/
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
var _proto = Services.prototype;
|
|
2887
|
-
|
|
2888
|
-
_proto.has = function has(service) {
|
|
2889
|
-
if (!hasMethod(_classPrivateFieldLooseBase(this, _base)[_base], service) && !SERVICES_MAP[service]) {
|
|
2890
|
-
return false;
|
|
2891
|
-
}
|
|
2892
|
-
|
|
2893
|
-
var _SERVICES_MAP$service = SERVICES_MAP[service](),
|
|
2894
|
-
has = _SERVICES_MAP$service.has;
|
|
2895
|
-
|
|
2896
|
-
return has(_classPrivateFieldLooseBase(this, _base)[_base].$id);
|
|
2897
|
-
}
|
|
2898
|
-
/**
|
|
2899
|
-
* Init the given service and bind it to the given instance.
|
|
2900
|
-
*
|
|
2901
|
-
* @param {ServiceName} service The name of the service.
|
|
2902
|
-
* @return {() => void} A function to unbind the service.
|
|
2903
|
-
*/
|
|
2904
|
-
;
|
|
2905
|
-
|
|
2906
|
-
_proto.enable = function enable(service) {
|
|
2907
|
-
if (this.has(service)) {
|
|
2908
|
-
return this.disable.bind(this, service);
|
|
2909
|
-
}
|
|
2910
|
-
|
|
2911
|
-
if (!hasMethod(_classPrivateFieldLooseBase(this, _base)[_base], service) || !SERVICES_MAP[service]) {
|
|
2912
|
-
return function noop() {};
|
|
2913
|
-
}
|
|
2914
|
-
|
|
2915
|
-
var _SERVICES_MAP$service2 = SERVICES_MAP[service](),
|
|
2916
|
-
add = _SERVICES_MAP$service2.add;
|
|
2917
|
-
|
|
2918
|
-
var self = this;
|
|
2919
|
-
/**
|
|
2920
|
-
* @param {any[]} args
|
|
2921
|
-
*/
|
|
2922
|
-
|
|
2923
|
-
function serviceHandler() {
|
|
2924
|
-
callMethod.apply(void 0, [_classPrivateFieldLooseBase(self, _base)[_base], service].concat([].slice.call(arguments)));
|
|
2925
|
-
}
|
|
2926
|
-
|
|
2927
|
-
add(_classPrivateFieldLooseBase(this, _base)[_base].$id, serviceHandler);
|
|
2928
|
-
return this.disable.bind(this, service);
|
|
2929
|
-
}
|
|
2930
|
-
/**
|
|
2931
|
-
* Enable all services and return methods to disable them.
|
|
2932
|
-
*
|
|
2933
|
-
* @return {Function[]}
|
|
2934
|
-
*/
|
|
2935
|
-
;
|
|
2936
|
-
|
|
2937
|
-
_proto.enableAll = function enableAll() {
|
|
2938
|
-
var _this = this;
|
|
2939
|
-
|
|
2940
|
-
return Object.keys(SERVICES_MAP).map(
|
|
2941
|
-
/** @param {ServiceName} serviceName */
|
|
2942
|
-
function (serviceName) {
|
|
2943
|
-
return _this.enable(serviceName);
|
|
2944
|
-
});
|
|
2945
|
-
}
|
|
2946
|
-
/**
|
|
2947
|
-
* Disable all services.
|
|
2948
|
-
*
|
|
2949
|
-
* @return {void}
|
|
2950
|
-
*/
|
|
2951
|
-
;
|
|
2952
|
-
|
|
2953
|
-
_proto.disableAll = function disableAll() {
|
|
2954
|
-
var _this2 = this;
|
|
2955
|
-
|
|
2956
|
-
Object.keys(SERVICES_MAP).forEach(
|
|
2957
|
-
/** @param {ServiceName} serviceName */
|
|
2958
|
-
function (serviceName) {
|
|
2959
|
-
_this2.disable(serviceName);
|
|
2960
|
-
});
|
|
2961
|
-
}
|
|
2962
|
-
/**
|
|
2963
|
-
* Disable a service.
|
|
2964
|
-
*
|
|
2965
|
-
* @param {String} service The name of the service.
|
|
2966
|
-
* @return {void}
|
|
2967
|
-
*/
|
|
2968
|
-
;
|
|
2969
|
-
|
|
2970
|
-
_proto.disable = function disable(service) {
|
|
2971
|
-
if (!SERVICES_MAP[service]) {
|
|
2972
|
-
return;
|
|
2973
|
-
}
|
|
2974
|
-
|
|
2975
|
-
var _SERVICES_MAP$service3 = SERVICES_MAP[service](),
|
|
2976
|
-
remove = _SERVICES_MAP$service3.remove;
|
|
2977
|
-
|
|
2978
|
-
remove(_classPrivateFieldLooseBase(this, _base)[_base].$id);
|
|
2979
|
-
}
|
|
2980
|
-
/**
|
|
2981
|
-
* Register a new service to be enabled/disabled.
|
|
2982
|
-
*
|
|
2983
|
-
* @param {string} name The name of the service hook.
|
|
2984
|
-
* @param {() => ServiceInterface} useFunction The `use...` function for the service.
|
|
2985
|
-
*/
|
|
2986
|
-
;
|
|
2987
|
-
|
|
2988
|
-
_proto.register = function register(name, useFunction) {
|
|
2989
|
-
SERVICES_MAP[name] = useFunction;
|
|
2990
|
-
}
|
|
2991
|
-
/**
|
|
2992
|
-
* Unregister a new service to be enabled disabled.
|
|
2993
|
-
*
|
|
2994
|
-
* @param {string} name The name of the service hooK
|
|
2995
|
-
*/
|
|
2996
|
-
;
|
|
2997
|
-
|
|
2998
|
-
_proto.unregister = function unregister(name) {
|
|
2999
|
-
delete SERVICES_MAP[name];
|
|
3000
|
-
};
|
|
3001
|
-
|
|
3002
|
-
return Services;
|
|
3003
|
-
}();
|
|
3004
|
-
|
|
3005
|
-
/**
|
|
3006
|
-
* @typedef {import('./index.js').default} Base
|
|
3007
|
-
*/
|
|
3008
|
-
|
|
3009
|
-
/**
|
|
3010
|
-
* Bind event handler methods to the root HTML element.
|
|
3011
|
-
*
|
|
3012
|
-
* @param {Base} instance A Base instance.
|
|
3013
|
-
* @param {Array} eventMethods A list of methods to bind.
|
|
3014
|
-
* @return {Array} A list of unbind functions.
|
|
3015
|
-
*/
|
|
3016
|
-
|
|
3017
|
-
function bindRootEvents(instance, eventMethods) {
|
|
3018
|
-
return eventMethods.map(function (eventMethod) {
|
|
3019
|
-
var eventName = eventMethod.replace(/^on/, '').toLowerCase();
|
|
3020
|
-
|
|
3021
|
-
var handler = function handler() {
|
|
3022
|
-
var args = [].slice.call(arguments);
|
|
3023
|
-
|
|
3024
|
-
if (__DEV__) {
|
|
3025
|
-
debug.apply(void 0, [instance, eventMethod, instance.$el].concat(args));
|
|
3026
|
-
}
|
|
3027
|
-
|
|
3028
|
-
instance[eventMethod].apply(instance, args);
|
|
3029
|
-
};
|
|
3030
|
-
|
|
3031
|
-
instance.$el.addEventListener(eventName, handler);
|
|
3032
|
-
return function () {
|
|
3033
|
-
instance.$el.removeEventListener(eventName, handler);
|
|
3034
|
-
};
|
|
3035
|
-
});
|
|
3036
|
-
}
|
|
3037
|
-
/**
|
|
3038
|
-
* Bind event handler methods to refs HTML element.
|
|
3039
|
-
*
|
|
3040
|
-
* @param {Base} instance A Base instance.
|
|
3041
|
-
* @param {Array} eventMethods A list of methods to bind.
|
|
3042
|
-
* @return {Array} A list of unbind functions.
|
|
3043
|
-
*/
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
function bindRefsEvents(instance, eventMethods) {
|
|
3047
|
-
var unbindMethods = [];
|
|
3048
|
-
Object.entries(instance.$refs).forEach(function (_ref) {
|
|
3049
|
-
var refName = _ref[0],
|
|
3050
|
-
$refOrRefs = _ref[1];
|
|
3051
|
-
var $refs = Array.isArray($refOrRefs) ? $refOrRefs : [$refOrRefs];
|
|
3052
|
-
var refEventMethod = "on" + refName.replace(/^\w/, function (c) {
|
|
3053
|
-
return c.toUpperCase();
|
|
3054
|
-
});
|
|
3055
|
-
eventMethods.filter(function (eventMethod) {
|
|
3056
|
-
return eventMethod.startsWith(refEventMethod);
|
|
3057
|
-
}).forEach(function (eventMethod) {
|
|
3058
|
-
$refs.forEach(function ($ref, index) {
|
|
3059
|
-
var eventName = eventMethod.replace(refEventMethod, '').toLowerCase();
|
|
3060
|
-
|
|
3061
|
-
var handler = function handler() {
|
|
3062
|
-
var args = [].slice.call(arguments);
|
|
3063
|
-
|
|
3064
|
-
if (__DEV__) {
|
|
3065
|
-
debug.apply(void 0, [instance, eventMethod, $ref].concat(args, [index]));
|
|
3066
|
-
}
|
|
3067
|
-
|
|
3068
|
-
instance[eventMethod].apply(instance, args.concat([index]));
|
|
3069
|
-
};
|
|
3070
|
-
|
|
3071
|
-
if (__DEV__) {
|
|
3072
|
-
debug(instance, 'binding ref event', refName, eventName);
|
|
3073
|
-
}
|
|
3074
|
-
|
|
3075
|
-
if ($ref instanceof instance.constructor) {
|
|
3076
|
-
// @ts-ignore
|
|
3077
|
-
$ref = $ref.$el; // eslint-disable-line no-param-reassign
|
|
3078
|
-
}
|
|
3079
|
-
/** @type {HTMLElement} */
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
$ref.addEventListener(eventName, handler);
|
|
3083
|
-
|
|
3084
|
-
var unbindMethod = function unbindMethod() {
|
|
3085
|
-
if (__DEV__) {
|
|
3086
|
-
debug(instance, 'unbinding ref event', refName, eventMethod);
|
|
3087
|
-
}
|
|
3088
|
-
/** @type {HTMLElement} */
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
$ref.removeEventListener(eventName, handler);
|
|
3092
|
-
};
|
|
3093
|
-
|
|
3094
|
-
unbindMethods.push(unbindMethod);
|
|
3095
|
-
});
|
|
3096
|
-
});
|
|
3097
|
-
});
|
|
3098
|
-
return unbindMethods;
|
|
3099
|
-
}
|
|
3100
|
-
/**
|
|
3101
|
-
* Bind event handler methods to children Base instance.
|
|
3102
|
-
* @param {Base} instance A Base instance.
|
|
3103
|
-
* @param {Array} eventMethods A list of methods to bind.
|
|
3104
|
-
* @return {Array} A list of unbind functions.
|
|
3105
|
-
*/
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
function bindChildrenEvents(instance, eventMethods) {
|
|
3109
|
-
var unbindMethods = [];
|
|
3110
|
-
Object.entries(instance.$children).forEach(function (_ref2) {
|
|
3111
|
-
var childName = _ref2[0],
|
|
3112
|
-
$children = _ref2[1];
|
|
3113
|
-
var childEventMethod = "on" + childName.replace(/^\w/, function (c) {
|
|
3114
|
-
return c.toUpperCase();
|
|
3115
|
-
});
|
|
3116
|
-
eventMethods.filter(function (eventMethod) {
|
|
3117
|
-
return eventMethod.startsWith(childEventMethod);
|
|
3118
|
-
}).forEach(function (eventMethod) {
|
|
3119
|
-
$children.forEach(
|
|
3120
|
-
/**
|
|
3121
|
-
* @param {Base|Promise<Base>} $child
|
|
3122
|
-
* @param {Number} index
|
|
3123
|
-
*/
|
|
3124
|
-
function ($child, index) {
|
|
3125
|
-
try {
|
|
3126
|
-
var _temp3 = function _temp3() {
|
|
3127
|
-
var unbindMethod = $child.$on(eventName, handler);
|
|
3128
|
-
unbindMethods.push(function () {
|
|
3129
|
-
if (__DEV__) {
|
|
3130
|
-
debug(instance, 'unbinding child event', childName, eventName);
|
|
3131
|
-
}
|
|
3132
|
-
|
|
3133
|
-
unbindMethod();
|
|
3134
|
-
});
|
|
3135
|
-
};
|
|
3136
|
-
|
|
3137
|
-
var eventName = eventMethod.replace(childEventMethod, '').toLowerCase();
|
|
3138
|
-
|
|
3139
|
-
var handler = function handler() {
|
|
3140
|
-
var args = [].slice.call(arguments);
|
|
3141
|
-
|
|
3142
|
-
if (__DEV__) {
|
|
3143
|
-
debug.apply(void 0, [instance, eventMethod, $child].concat(args, [index]));
|
|
3144
|
-
}
|
|
3145
|
-
|
|
3146
|
-
instance[eventMethod].apply(instance, args.concat([index]));
|
|
3147
|
-
};
|
|
3148
|
-
|
|
3149
|
-
if (__DEV__) {
|
|
3150
|
-
debug(instance, 'binding child event', childName, eventName);
|
|
3151
|
-
}
|
|
3152
|
-
|
|
3153
|
-
var _temp4 = function () {
|
|
3154
|
-
if ($child instanceof Promise) {
|
|
3155
|
-
// eslint-disable-next-line no-param-reassign
|
|
3156
|
-
return Promise.resolve($child).then(function (_$child) {
|
|
3157
|
-
$child = _$child;
|
|
3158
|
-
});
|
|
3159
|
-
}
|
|
3160
|
-
}();
|
|
3161
|
-
|
|
3162
|
-
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
|
|
3163
|
-
} catch (e) {
|
|
3164
|
-
return Promise.reject(e);
|
|
3165
|
-
}
|
|
3166
|
-
});
|
|
3167
|
-
});
|
|
3168
|
-
});
|
|
3169
|
-
return unbindMethods;
|
|
3170
|
-
}
|
|
3171
|
-
/**
|
|
3172
|
-
* Bind ref and children component's events to their corresponding method.
|
|
3173
|
-
*
|
|
3174
|
-
* @param {Base} instance A Base instance.
|
|
3175
|
-
* @return {Array} A list of methods to unbind the events.
|
|
3176
|
-
*/
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
function bindEvents(instance) {
|
|
3180
|
-
var ROOT_EVENT_REGEX = /^on[A-Z][a-z]+$/;
|
|
3181
|
-
var REFS_CHILDREN_EVENT_REGEX = /^on([A-Z]([a-z]+)?)([A-Z][a-z]+)+$/; // Get all event methods
|
|
3182
|
-
|
|
3183
|
-
var eventMethods = getAllProperties(instance).reduce(function (acc, _ref3) {
|
|
3184
|
-
var name = _ref3[0];
|
|
3185
|
-
|
|
3186
|
-
// Testing camelCase with one word: onEvent.
|
|
3187
|
-
if (ROOT_EVENT_REGEX.test(name) && !acc.root.includes(name)) {
|
|
3188
|
-
acc.root.push(name);
|
|
3189
|
-
return acc;
|
|
3190
|
-
} // Testing camelCase with more than two words: onRefEvent.
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
if (REFS_CHILDREN_EVENT_REGEX.test(name) && !acc.refsOrChildren.includes(name)) {
|
|
3194
|
-
acc.refsOrChildren.push(name);
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
|
-
return acc;
|
|
3198
|
-
}, {
|
|
3199
|
-
root: [],
|
|
3200
|
-
refsOrChildren: []
|
|
3201
|
-
});
|
|
3202
|
-
var unbindMethods = [].concat(bindRootEvents(instance, eventMethods.root), bindRefsEvents(instance, eventMethods.refsOrChildren), bindChildrenEvents(instance, eventMethods.refsOrChildren));
|
|
3203
|
-
return unbindMethods;
|
|
3204
|
-
}
|
|
3205
|
-
|
|
3206
|
-
if (typeof __DEV__ === 'undefined') {
|
|
3207
|
-
if (typeof globalThis !== 'undefined') {
|
|
3208
|
-
globalThis.__DEV__ = false;
|
|
3209
|
-
} else if (typeof window !== 'undefined') {
|
|
3210
|
-
window.__DEV__ = false;
|
|
3211
|
-
}
|
|
3212
|
-
}
|
|
3213
|
-
|
|
3214
|
-
var id = 0;
|
|
3215
|
-
/**
|
|
3216
|
-
* @typedef {typeof Base} BaseComponent
|
|
3217
|
-
* @typedef {(Base) => Promise<BaseComponent | { default: BaseComponent }>} BaseAsyncComponent
|
|
3218
|
-
* @typedef {{ name: string, debug: boolean, log: boolean, [name:string]: any }} BaseOptions
|
|
3219
|
-
* @typedef {{ [name:string]: HTMLElement | HTMLElement[] | Base | Base[] | Promise<Base> | Promise<Base>[] }} BaseRefs
|
|
3220
|
-
* @typedef {{ [nameOrSelector:string]: Base[] | Promise<Base>[] }} BaseChildren
|
|
3221
|
-
* @typedef {{ [nameOrSelector:string]: BaseComponent | BaseAsyncComponent }} BaseConfigComponents
|
|
3222
|
-
* @typedef {import('./classes/Options').OptionsSchema} BaseConfigOptions
|
|
3223
|
-
*/
|
|
3224
|
-
|
|
3225
|
-
/**
|
|
3226
|
-
* @typedef {Object} BaseConfig
|
|
3227
|
-
* @property {String} name
|
|
3228
|
-
* @property {Boolean} [debug]
|
|
3229
|
-
* @property {Boolean} [log]
|
|
3230
|
-
* @property {String[]} [refs]
|
|
3231
|
-
* @property {BaseConfigComponents} [components]
|
|
3232
|
-
* @property {BaseConfigOptions} [options]
|
|
3233
|
-
*/
|
|
3234
|
-
|
|
3235
|
-
/**
|
|
3236
|
-
* @typedef {import('./classes/Services.js').ServiceName} ServiceName
|
|
3237
|
-
*/
|
|
3238
|
-
|
|
3239
|
-
/**
|
|
3240
|
-
* Base class to easily create components.
|
|
3241
|
-
*
|
|
3242
|
-
* @example
|
|
3243
|
-
* ```js
|
|
3244
|
-
* class Component extends Base {
|
|
3245
|
-
* static config = {
|
|
3246
|
-
* name: 'Component',
|
|
3247
|
-
* log: true,
|
|
3248
|
-
* };
|
|
3249
|
-
*
|
|
3250
|
-
* mounted() {
|
|
3251
|
-
* this.$log('Component is mounted!');
|
|
3252
|
-
* }
|
|
3253
|
-
* }
|
|
3254
|
-
*
|
|
3255
|
-
* class App extends Base {
|
|
3256
|
-
* static config = {
|
|
3257
|
-
* name: 'App',
|
|
3258
|
-
* components: {
|
|
3259
|
-
* Component,
|
|
3260
|
-
* },
|
|
3261
|
-
* };
|
|
3262
|
-
* }
|
|
3263
|
-
*
|
|
3264
|
-
* new App(document.body).$mount();
|
|
3265
|
-
* ```
|
|
3266
|
-
*/
|
|
3267
|
-
|
|
3268
|
-
var Base = /*#__PURE__*/function (_EventManager) {
|
|
3269
|
-
_inheritsLoose(Base, _EventManager);
|
|
3270
|
-
|
|
3271
|
-
/**
|
|
3272
|
-
* Class constructor where all the magic takes place.
|
|
3273
|
-
*
|
|
3274
|
-
* @param {HTMLElement} element The component's root element dd.
|
|
3275
|
-
*/
|
|
3276
|
-
function Base(element) {
|
|
3277
|
-
var _this;
|
|
3278
|
-
|
|
3279
|
-
_this = _EventManager.call(this) || this;
|
|
3280
|
-
_this.$parent = null;
|
|
3281
|
-
_this.$isMounted = false;
|
|
3282
|
-
|
|
3283
|
-
if (!element) {
|
|
3284
|
-
throw new Error('The root element must be defined.');
|
|
3285
|
-
}
|
|
3286
|
-
|
|
3287
|
-
var _getConfig = getConfig(_assertThisInitialized(_this)),
|
|
3288
|
-
name = _getConfig.name;
|
|
3289
|
-
/** @type {String} */
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
_this.$id = name + "-" + id;
|
|
3293
|
-
id += 1;
|
|
3294
|
-
/** @type {HTMLElement} */
|
|
3295
|
-
|
|
3296
|
-
_this.$el = element;
|
|
3297
|
-
_this.$options = getOptions(_assertThisInitialized(_this), element, getConfig(_assertThisInitialized(_this)));
|
|
3298
|
-
_this.$children = getChildren(_assertThisInitialized(_this), _this.$el, getConfig(_assertThisInitialized(_this)).components || {});
|
|
3299
|
-
_this.$services = new Services(_assertThisInitialized(_this));
|
|
3300
|
-
|
|
3301
|
-
if (!('__base__' in _this.$el)) {
|
|
3302
|
-
Object.defineProperty(_this.$el, '__base__', {
|
|
3303
|
-
get: function get() {
|
|
3304
|
-
return _assertThisInitialized(_this);
|
|
3305
|
-
},
|
|
3306
|
-
configurable: true
|
|
3307
|
-
});
|
|
3308
|
-
} // Autobind all methods to the instance
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
autoBind(_assertThisInitialized(_this), {
|
|
3312
|
-
exclude: [].concat(_this._excludeFromAutoBind)
|
|
3313
|
-
});
|
|
3314
|
-
var unbindMethods = [];
|
|
3315
|
-
|
|
3316
|
-
_this.$on('mounted', function () {
|
|
3317
|
-
_this.$services.enableAll();
|
|
3318
|
-
|
|
3319
|
-
unbindMethods = [].concat(bindEvents(_assertThisInitialized(_this)));
|
|
3320
|
-
mountComponents(_assertThisInitialized(_this));
|
|
3321
|
-
_this.$isMounted = true;
|
|
3322
|
-
});
|
|
3323
|
-
|
|
3324
|
-
_this.$on('updated', function () {
|
|
3325
|
-
_this.$services.disableAll();
|
|
3326
|
-
|
|
3327
|
-
unbindMethods.forEach(function (method) {
|
|
3328
|
-
return method();
|
|
3329
|
-
});
|
|
3330
|
-
unbindMethods = [].concat(bindEvents(_assertThisInitialized(_this)));
|
|
3331
|
-
|
|
3332
|
-
_this.$services.enableAll();
|
|
3333
|
-
|
|
3334
|
-
mountOrUpdateComponents(_assertThisInitialized(_this));
|
|
3335
|
-
});
|
|
3336
|
-
|
|
3337
|
-
_this.$on('destroyed', function () {
|
|
3338
|
-
_this.$isMounted = false;
|
|
3339
|
-
|
|
3340
|
-
_this.$services.disableAll();
|
|
3341
|
-
|
|
3342
|
-
unbindMethods.forEach(function (method) {
|
|
3343
|
-
return method();
|
|
3344
|
-
});
|
|
3345
|
-
destroyComponents(_assertThisInitialized(_this));
|
|
3346
|
-
});
|
|
3347
|
-
|
|
3348
|
-
if (__DEV__) {
|
|
3349
|
-
debug(_assertThisInitialized(_this), 'constructor', _assertThisInitialized(_this));
|
|
3350
|
-
}
|
|
3351
|
-
|
|
3352
|
-
return _assertThisInitialized(_this) || _assertThisInitialized(_this);
|
|
3353
|
-
}
|
|
3354
|
-
/**
|
|
3355
|
-
* Small helper to log stuff.
|
|
3356
|
-
*
|
|
3357
|
-
* @return {(...args: any) => void} A log function if the log options is active.
|
|
3358
|
-
*/
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
var _proto = Base.prototype;
|
|
3362
|
-
|
|
3363
|
-
/**
|
|
3364
|
-
* Trigger the `mounted` callback.
|
|
3365
|
-
*/
|
|
3366
|
-
_proto.$mount = function $mount() {
|
|
3367
|
-
if (__DEV__) {
|
|
3368
|
-
debug(this, '$mount');
|
|
3369
|
-
}
|
|
3370
|
-
|
|
3371
|
-
callMethod(this, 'mounted');
|
|
3372
|
-
return this;
|
|
3373
|
-
}
|
|
3374
|
-
/**
|
|
3375
|
-
* Update the instance children.
|
|
3376
|
-
*/
|
|
3377
|
-
;
|
|
3378
|
-
|
|
3379
|
-
_proto.$update = function $update() {
|
|
3380
|
-
if (__DEV__) {
|
|
3381
|
-
debug(this, '$update');
|
|
3382
|
-
}
|
|
3383
|
-
|
|
3384
|
-
callMethod(this, 'updated');
|
|
3385
|
-
return this;
|
|
3386
|
-
}
|
|
3387
|
-
/**
|
|
3388
|
-
* Trigger the `destroyed` callback.
|
|
3389
|
-
*/
|
|
3390
|
-
;
|
|
3391
|
-
|
|
3392
|
-
_proto.$destroy = function $destroy() {
|
|
3393
|
-
if (__DEV__) {
|
|
3394
|
-
debug(this, '$destroy');
|
|
3395
|
-
}
|
|
3396
|
-
|
|
3397
|
-
callMethod(this, 'destroyed');
|
|
3398
|
-
return this;
|
|
3399
|
-
}
|
|
3400
|
-
/**
|
|
3401
|
-
* Terminate a child instance when it is not needed anymore.
|
|
3402
|
-
* @return {void}
|
|
3403
|
-
*/
|
|
3404
|
-
;
|
|
3405
|
-
|
|
3406
|
-
_proto.$terminate = function $terminate() {
|
|
3407
|
-
if (__DEV__) {
|
|
3408
|
-
debug(this, '$terminate');
|
|
3409
|
-
} // First, destroy the component.
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
this.$destroy(); // Execute the `terminated` hook if it exists
|
|
3413
|
-
|
|
3414
|
-
callMethod(this, 'terminated'); // Delete the reference to the instance
|
|
3415
|
-
// delete this.$el.__base__;
|
|
3416
|
-
// And update its status to prevent re-instantiation when accessing the
|
|
3417
|
-
// parent's `$children` property
|
|
3418
|
-
|
|
3419
|
-
Object.defineProperty(this.$el, '__base__', {
|
|
3420
|
-
value: 'terminated',
|
|
3421
|
-
configurable: false,
|
|
3422
|
-
writable: false
|
|
3423
|
-
});
|
|
3424
|
-
}
|
|
3425
|
-
/**
|
|
3426
|
-
* Factory method to generate multiple instance of the class.
|
|
3427
|
-
*
|
|
3428
|
-
* @param {String} nameOrSelector The selector on which to mount each instance.
|
|
3429
|
-
* @return {Array<Base>} A list of the created instance.
|
|
3430
|
-
*/
|
|
3431
|
-
;
|
|
3432
|
-
|
|
3433
|
-
Base.$factory = function $factory(nameOrSelector) {
|
|
3434
|
-
var _this2 = this;
|
|
3435
|
-
|
|
3436
|
-
if (!nameOrSelector) {
|
|
3437
|
-
throw new Error('The $factory method requires a component’s name or selector to be specified.');
|
|
3438
|
-
}
|
|
3439
|
-
|
|
3440
|
-
return getComponentElements(nameOrSelector).map(function (el) {
|
|
3441
|
-
return new _this2(el).$mount();
|
|
3442
|
-
});
|
|
3443
|
-
};
|
|
3444
|
-
|
|
3445
|
-
_createClass(Base, [{
|
|
3446
|
-
key: "_excludeFromAutoBind",
|
|
3447
|
-
get:
|
|
3448
|
-
/**
|
|
3449
|
-
* The instance parent.
|
|
3450
|
-
* @type {Base}
|
|
3451
|
-
*/
|
|
3452
|
-
|
|
3453
|
-
/**
|
|
3454
|
-
* The state of the component.
|
|
3455
|
-
* @type {Boolean}
|
|
3456
|
-
*/
|
|
3457
|
-
|
|
3458
|
-
/**
|
|
3459
|
-
* This is a Base instance.
|
|
3460
|
-
* @type {Boolean}
|
|
3461
|
-
*/
|
|
3462
|
-
|
|
3463
|
-
/**
|
|
3464
|
-
* Get properties to exclude from the autobind call.
|
|
3465
|
-
* @return {Array<String|RegExp>}
|
|
3466
|
-
*/
|
|
3467
|
-
function get() {
|
|
3468
|
-
return ['$mount', '$update', '$destroy', '$terminate', '$log', '$on', '$once', '$off', '$emit', 'mounted', 'loaded', 'ticked', 'resized', 'moved', 'keyed', 'scrolled', 'destroyed', 'terminated'];
|
|
3469
|
-
}
|
|
3470
|
-
/**
|
|
3471
|
-
* @deprecated Use the static `config` property instead.
|
|
3472
|
-
* @return {BaseConfig}
|
|
3473
|
-
*/
|
|
3474
|
-
|
|
3475
|
-
}, {
|
|
3476
|
-
key: "config",
|
|
3477
|
-
get: function get() {
|
|
3478
|
-
return null;
|
|
3479
|
-
}
|
|
3480
|
-
/** @type {BaseConfig} */
|
|
3481
|
-
|
|
3482
|
-
}, {
|
|
3483
|
-
key: "$refs",
|
|
3484
|
-
get:
|
|
3485
|
-
/**
|
|
3486
|
-
* Get the component's refs.
|
|
3487
|
-
* @return {BaseRefs}
|
|
3488
|
-
*/
|
|
3489
|
-
function get() {
|
|
3490
|
-
return getRefs(this, this.$el);
|
|
3491
|
-
}
|
|
3492
|
-
}, {
|
|
3493
|
-
key: "$log",
|
|
3494
|
-
get: function get() {
|
|
3495
|
-
return this.$options.log ? window.console.log.bind(window, "[" + this.$options.name + "]") : function noop() {};
|
|
3496
|
-
}
|
|
3497
|
-
}]);
|
|
3498
|
-
|
|
3499
|
-
return Base;
|
|
3500
|
-
}(EventManager);
|
|
3501
|
-
|
|
3502
|
-
Base.$isBase = true;
|
|
3503
|
-
|
|
3504
|
-
var _excluded = ["config", "methods"];
|
|
3505
|
-
/**
|
|
3506
|
-
* @typedef {import('../abstracts/Base').BaseComponent} BaseComponent
|
|
3507
|
-
*/
|
|
3508
|
-
|
|
3509
|
-
/**
|
|
3510
|
-
* Define a component without a class.
|
|
3511
|
-
*
|
|
3512
|
-
* @param {Object} options The component's object
|
|
3513
|
-
* @return {BaseComponent} A component's class.
|
|
3514
|
-
*/
|
|
3515
|
-
|
|
3516
|
-
function defineComponent(options) {
|
|
3517
|
-
var config = options.config,
|
|
3518
|
-
methods = options.methods,
|
|
3519
|
-
hooks = _objectWithoutPropertiesLoose(options, _excluded);
|
|
3520
|
-
|
|
3521
|
-
if (!config) {
|
|
3522
|
-
throw new Error('The `config` property is required.');
|
|
3523
|
-
}
|
|
3524
|
-
|
|
3525
|
-
if (!config.name) {
|
|
3526
|
-
throw new Error('The `config.name` property is required.');
|
|
3527
|
-
}
|
|
3528
|
-
/**
|
|
3529
|
-
* Component class.
|
|
3530
|
-
*/
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
var Component = /*#__PURE__*/function (_Base) {
|
|
3534
|
-
_inheritsLoose(Component, _Base);
|
|
3535
|
-
|
|
3536
|
-
function Component() {
|
|
3537
|
-
return _Base.apply(this, arguments) || this;
|
|
3538
|
-
}
|
|
3539
|
-
|
|
3540
|
-
return Component;
|
|
3541
|
-
}(Base);
|
|
3542
|
-
|
|
3543
|
-
Component.config = config;
|
|
3544
|
-
var allowedHooks = ['mounted', 'loaded', 'ticked', 'resized', 'moved', 'keyed', 'scrolled', 'destroyed', 'terminated'];
|
|
3545
|
-
var filteredHooks = Object.entries(hooks).reduce(function (acc, _ref) {
|
|
3546
|
-
var name = _ref[0],
|
|
3547
|
-
fn = _ref[1];
|
|
3548
|
-
|
|
3549
|
-
if (allowedHooks.includes(name)) {
|
|
3550
|
-
acc[name] = fn;
|
|
3551
|
-
} else {
|
|
3552
|
-
throw new Error("\n The \"" + name + "\" method is not a Base lifecycle hook,\n it should be placed in the \"method\" property.\n The following hooks are available: " + allowedHooks.join(', ') + "\n ");
|
|
3553
|
-
}
|
|
3554
|
-
|
|
3555
|
-
return acc;
|
|
3556
|
-
}, {});
|
|
3557
|
-
[].concat(Object.entries(methods || {}), Object.entries(filteredHooks)).forEach(function (_ref2) {
|
|
3558
|
-
var name = _ref2[0],
|
|
3559
|
-
fn = _ref2[1];
|
|
3560
|
-
Component.prototype[name] = fn;
|
|
3561
|
-
});
|
|
3562
|
-
return Component;
|
|
3563
|
-
}
|
|
3564
|
-
|
|
3565
|
-
/**
|
|
3566
|
-
* Create a Base instance with the given object configuration.
|
|
3567
|
-
*
|
|
3568
|
-
* @param {HTMLElement|String} elementOrSelector The instance root HTML element.
|
|
3569
|
-
* @param {Object} options The Base class configuration.
|
|
3570
|
-
*/
|
|
3571
|
-
|
|
3572
|
-
function createBase(elementOrSelector, options) {
|
|
3573
|
-
var Component = defineComponent(options);
|
|
3574
|
-
/** @type {HTMLElement} */
|
|
3575
|
-
|
|
3576
|
-
var element = typeof elementOrSelector === 'string' ? document.querySelector(elementOrSelector) : elementOrSelector;
|
|
3577
|
-
return new Component(element);
|
|
3578
|
-
}
|
|
3579
|
-
|
|
3580
|
-
exports.Base = Base;
|
|
3581
|
-
exports.createBase = createBase;
|
|
3582
|
-
exports.default = Base;
|
|
3583
|
-
exports.defineComponent = defineComponent;
|
|
3584
|
-
|
|
3585
|
-
})));
|
|
3586
|
-
//# sourceMappingURL=index.umd.js.map
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).Base={})}(this,function(e){function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e}).apply(this,arguments)}var i=0;function r(e){return"__private_"+i+++"_"+e}function s(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}function n(e,t){return"function"==typeof e[t]}function o(e,t){var i=[].slice.call(arguments,2);return e.__debug("callMethod",t,...i),"destroyed"===t&&!e.$isMounted||"mounted"===t&&e.$isMounted?(e.__debug("not",t,"because the method has already been triggered once."),e):(e.$emit(t,...i),n(e,t)?(e[t].call(e,...i),e.__debug(t,e,...i),e):e)}function a(e,t){void 0===t&&(t=document);var i='[data-component="'+e+'"]',r=[];try{r=Array.from(t.querySelectorAll(i))}catch(e){}return 0===r.length&&(r=Array.from(t.querySelectorAll(e))),r}class h{get registeredNames(){return Object.keys(this).filter(e=>!e.startsWith("__"))}constructor(e,t,i,r){Object.defineProperties(this,{__base:{enumerable:!1,writable:!1,value:e},__element:{enumerable:!1,writable:!1,value:t},__components:{enumerable:!1,writable:!1,value:i},__eventsManager:{enumerable:!1,writable:!1,value:r}})}registerAll(){Object.entries(this.__components).forEach(e=>{var[t,i]=e;return this.__register(t,i)})}__register(e,t){Object.defineProperty(this,e,{enumerable:!0,configurable:!0,get:()=>{var i=a(e,this.__element);return 0===i.length?[]:i.map(i=>this.__getChild(i,t,e)).filter(e=>"terminated"!==e)}})}__getChild(e,t,i){if(e.__base__)return e.__base__;if("$isBase"in t){var r=new t(e);return Object.defineProperty(r,"$parent",{get:()=>this.__base}),r}return t(this.__base).then(t=>{var r;return this.__getChild(e,null!=(r=t.default)?r:t,i)})}mountAll(){this.__triggerHookForAll("$mount")}updateAll(){this.__triggerHookForAll("$update")}destroyAll(){this.__triggerHookForAll("$destroy")}__triggerHookForAll(e){this.registeredNames.forEach(t=>{this[t].forEach(i=>{i instanceof Promise?i.then(i=>this.__triggerHook(e,i,t)):this.__triggerHook(e,i,t)})})}__triggerHook(e,t,i){"$update"!==e||t.$isMounted||(e="$mount"),"$update"!==e&&"$destroy"!==e||this.__eventsManager.unbindChild(i,t),"$update"!==e&&"$mount"!==e||this.__eventsManager.bindChild(i,t),t[e]()}}class d{constructor(e,t,i,r){Object.defineProperties(this,{__element:{enumerable:!1,writable:!1,value:t},__refs:{enumerable:!1,writable:!1,value:i},__base:{enumerable:!1,writable:!1,value:e},__eventsManager:{enumerable:!1,writable:!1,value:r}})}registerAll(){this.__refs.forEach(e=>this.__register(e))}unregisterAll(){this.__refs.forEach(e=>this.__unregister(e))}__register(e){var t=e.endsWith("[]"),i=d.normalizeRefName(e),r=Array.from(this.__element.querySelectorAll('[data-ref="'+e+'"]')).filter(e=>this.__filterRefsBelongingToInstance(e));!t&&r.length>1&&console.warn("["+this.__base.$options.name+"]",'The "'+e+'" ref has been found multiple times.',"Did you forgot to add the `[]` suffix to its name?"),this.__eventsManager.bindRef(e,r),Object.defineProperty(this,i,{value:t||r.length>1?r:r[0],enumerable:!0,configurable:!0})}__unregister(e){var t=d.normalizeRefName(e),i=Array.isArray(this[t])?this[t]:[this[t]];this.__eventsManager.unbindRef(e,i)}static normalizeRefName(e){return e.endsWith("[]")?e.replace(/\[\]$/,""):e}__filterRefsBelongingToInstance(e){for(var t=e.parentElement;t&&void 0===t.dataset.component;)t=t.parentElement;return null===t||t===this.__element}}class l{constructor(){this.callbacks=new Map,this.isInit=!1}get props(){throw new Error("The `props` getter must be implemented.")}init(){throw new Error("The `init` method must be implemented.")}kill(){throw new Error("The `kill` method must be implemented.")}add(e,t){if(this.has(e))throw new Error("A callback with the key `"+e+"` has already been registered.");return 0!==this.callbacks.size||this.isInit||(this.init(),this.isInit=!0),this.callbacks.set(e,t),this}has(e){return this.callbacks.has(e)}get(e){return this.callbacks.get(e)}remove(e){return this.callbacks.delete(e),0===this.callbacks.size&&this.isInit&&(this.kill(),this.isInit=!1),this}trigger(){var e=[].slice.call(arguments);return this.callbacks.forEach(function(t){t(...e)}),this}}function u(e){return"undefined"!=typeof TouchEvent&&e instanceof TouchEvent}class c extends l{constructor(){super(...arguments),this.isDown=!1,this.y=window.innerHeight/2,this.yLast=window.innerHeight/2,this.x=window.innerWidth/2,this.xLast=window.innerWidth/2,this.hasRaf=!1}init(){document.documentElement.addEventListener("mouseenter",this,{once:!0,capture:!0});var e={passive:!0,capture:!0};return document.addEventListener("mousemove",this,e),document.addEventListener("touchmove",this,e),document.addEventListener("mousedown",this,e),document.addEventListener("touchstart",this,e),document.addEventListener("mouseup",this,e),document.addEventListener("touchend",this,e),this}handleEvent(e){switch(e.type){case"mouseenter":case"mousemove":case"touchmove":this.handler(e);break;case"mousedown":case"touchstart":this.downHandler();break;case"mouseup":case"touchend":this.upHandler()}}kill(){return document.removeEventListener("mousemove",this),document.removeEventListener("touchmove",this),document.removeEventListener("mousedown",this),document.removeEventListener("touchstart",this),document.removeEventListener("mouseup",this),document.removeEventListener("touchend",this),this}handler(e){this.updateValues(e),this.trigger(this.props)}downHandler(){this.isDown=!0,this.trigger(this.props)}upHandler(){this.isDown=!1,this.trigger(this.props)}updateValues(e){var t,i;this.event=e,this.yLast=this.y,this.xLast=this.x;var r=u(e)?null==(t=e.touches[0])?void 0:t.clientY:e.clientY;r!==this.y&&(this.y=r);var s=u(e)?null==(i=e.touches[0])?void 0:i.clientX:e.clientX;s!==this.x&&(this.x=s)}get props(){return{event:this.event,isDown:this.isDown,x:this.x,y:this.y,changed:{x:this.x!==this.xLast,y:this.y!==this.yLast},last:{x:this.xLast,y:this.yLast},delta:{x:this.x-this.xLast,y:this.y-this.yLast},progress:{x:this.x/window.innerWidth,y:this.y/window.innerHeight},max:{x:window.innerWidth,y:window.innerHeight}}}}var p=null;function m(){return p||(p=new c),{add:p.add.bind(p),remove:p.remove.bind(p),has:p.has.bind(p),props:()=>p.props}}class v extends l{constructor(){super(),this.isTicking=!1,this.id=0,this.raf="undefined"!=typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):setTimeout,this.cancelRaf="undefined"!=typeof window&&window.cancelAnimationFrame?window.cancelAnimationFrame.bind(window):clearTimeout,this.loop=this.loop.bind(this)}init(){return this.isTicking=!0,this.loop(),this}loop(){this.trigger(this.props),this.isTicking&&(this.id=this.raf(this.loop))}kill(){return this.cancelRaf(this.id),this.isTicking=!1,this}get props(){return{time:window.performance.now()}}}var _=null;function f(){return _||(_=new v),{add:_.add.bind(_),remove:_.remove.bind(_),has:_.has.bind(_),props:function(){return _.props}}}function g(e,t){var i;return void 0===t&&(t=300),function(){clearTimeout(i),i=setTimeout(()=>{e(...[].slice.call(arguments))},t)}}class b extends l{init(){return this.handler=g(()=>{this.trigger(this.props)}).bind(this),window.addEventListener("resize",this.handler),this}kill(){return window.removeEventListener("resize",this.handler),this}get props(){var e={width:window.innerWidth,height:window.innerHeight,ratio:window.innerWidth/window.innerHeight,orientation:"square"};return e.ratio>1&&(e.orientation="landscape"),e.ratio<1&&(e.orientation="portrait"),this.breakpointElement&&(e.breakpoint=this.breakpoint,e.breakpoints=this.breakpoints),e}get breakpointElement(){return document.querySelector("[data-breakpoint]")||null}get breakpoint(){return window.getComputedStyle(this.breakpointElement,"::before").getPropertyValue("content").replace(/"/g,"")}get breakpoints(){return window.getComputedStyle(this.breakpointElement,"::after").getPropertyValue("content").replace(/"/g,"").split(",")}}var y=null;function w(){return y||(y=new b),{add:y.add.bind(y),remove:y.remove.bind(y),has:y.has.bind(y),props:()=>y.props}}class $ extends l{constructor(){super(...arguments),this.y=window.pageYOffset,this.yLast=window.pageYOffset,this.x=window.pageXOffset,this.xLast=window.pageXOffset}init(){return document.addEventListener("scroll",this,{passive:!0,capture:!0}),this}get debouncedHandler(){var e=g(()=>{this.trigger(this.props)},0);return Object.defineProperty(this,"debouncedHandler",{value:e}),e}handleEvent(){this.trigger(this.props),this.debouncedHandler()}kill(){return document.removeEventListener("scroll",this),this}get props(){return this.yLast=this.y,this.xLast=this.x,window.pageYOffset!==this.y&&(this.y=window.pageYOffset),window.pageXOffset!==this.x&&(this.x=window.pageXOffset),{x:this.x,y:this.y,changed:{x:this.x!==this.xLast,y:this.y!==this.yLast},last:{x:this.xLast,y:this.yLast},delta:{x:this.x-this.xLast,y:this.y-this.yLast},progress:{x:0===this.max.x?1:this.x/this.max.x,y:0===this.max.y?1:this.y/this.max.y},direction:{x:this.x>this.xLast?"RIGHT":this.x<this.xLast?"LEFT":"NONE",y:this.y>this.yLast?"DOWN":this.y<this.yLast?"UP":"NONE"},max:this.max}}get max(){return{x:(document.scrollingElement||document.body).scrollWidth-window.innerWidth,y:(document.scrollingElement||document.body).scrollHeight-window.innerHeight}}}var E=null;function x(){return E||(E=new $),{add:E.add.bind(E),remove:E.remove.bind(E),has:E.has.bind(E),props:()=>E.props}}var k={ENTER:13,SPACE:32,TAB:9,ESC:27,LEFT:37,UP:38,RIGHT:39,DOWN:40};class O extends l{constructor(){super(...arguments),this.event={},this.triggered=0,this.previousEvent={}}init(){return this.handler=e=>{this.event=e,this.trigger(this.props)},document.addEventListener("keydown",this.handler,{passive:!1}),document.addEventListener("keyup",this.handler,{passive:!1}),this}kill(){return document.removeEventListener("keydown",this.handler),document.removeEventListener("keyup",this.handler),this}get props(){var e=Object.entries(k).reduce((e,t)=>{var[i,r]=t;return e[i]=r===this.event.keyCode,e},{});return this.previousEvent.type||(this.triggered=0),"keydown"===this.event.type&&"keydown"===this.previousEvent.type?this.triggered+=1:this.triggered=1,this.previousEvent=this.event,t({event:this.event,triggered:this.triggered,direction:"keydown"===this.event.type?"down":"up",isUp:"keyup"===this.event.type,isDown:"keydown"===this.event.type},e)}}var A=null;function L(){return A||(A=new O),{add:A.add.bind(A),remove:A.remove.bind(A),has:A.has.bind(A),props:()=>A.props}}class j extends l{init(){return this.handler=()=>{this.trigger(this.props)},window.addEventListener("load",this.handler),this}kill(){return window.removeEventListener("load",this.handler),this}get props(){return{}}}var M=null;function N(){return M||(M=new j),{add:M.add.bind(M),remove:M.remove.bind(M),has:M.has.bind(M),props:function(){return M.props}}}var T={scrolled:x,resized:w,ticked:f,moved:m,keyed:L,loaded:N},B=Object.keys(T);class H{get __services(){return t({},this.__customServices,T)}constructor(e){this.__customServices={},Object.defineProperties(this,{__base:{enumerable:!1,writable:!1,value:e}})}has(e){if(!n(this.__base,e)&&!this.__services[e])return!1;var{has:t}=this.__services[e]();return t(this.__base.$id)}enable(e){if(this.has(e))return this.disable.bind(this,e);if(!n(this.__base,e)||!this.__services[e])return function(){};var{add:t}=this.__services[e](),i=this;return t(this.__base.$id,function(){o(i.__base,e,...[].slice.call(arguments))}),this.disable.bind(this,e)}enableAll(){return Object.keys(this.__services).map(e=>this.enable(e))}disableAll(){Object.keys(this.__services).forEach(e=>{this.disable(e)})}disable(e){if(this.__services[e]){var{remove:t}=this.__services[e]();t(this.__base.$id)}}register(e,t){this.__customServices[e]=t}unregister(e){if(B.includes(e))throw new Error("[ServicesManager] The `"+e+"` core service can not be unregistered.");delete this.__customServices[e]}}function P(e,t,i){void 0===t&&(t=[]),void 0===i&&(i=null);var r=Object.getPrototypeOf(e);if(r===Object.prototype)return t;var s=Object.getOwnPropertyNames(r);return"function"==typeof i&&(s=s.filter(e=>i(e,r))),s=s.map(e=>[e,r]).reduce((e,t)=>[...e,t],t),P(r,s,i)}class S{constructor(e,t){this.__methodsCache=new Map,this.__rootElementHandler={handleEvent:e=>{var t=S.normalizeName(e.type);this.__base["on"+t](e)}},this.__refsHandler={handleEvent:e=>{var t=e.currentTarget,i=d.normalizeRefName(t.dataset.ref),r="on"+S.normalizeName(i)+S.normalizeName(e.type),s=0;Array.isArray(this.__base.$refs[i])&&(s=this.__base.$refs[i].indexOf(t)),this.__base[r](e,s)}},this.__childrenHandler={handleEvent:e=>{var t,i=e.currentTarget.__base__,r=0,s=this.__base.$children;s.registeredNames.find(e=>!!s[e].includes(i)&&(t=e,r=s[e].indexOf(i),!0));var n="on"+S.normalizeName(t)+S.normalizeName(e.type),o=Array.isArray(e.detail)?e.detail:[];this.__base[n](...o,r,e)}},Object.defineProperties(this,{__rootElement:{enumerable:!1,writable:!1,value:e},__base:{enumerable:!1,writable:!1,value:t},__methodsCache:{enumerable:!1,writable:!1,value:this.__methodsCache},__rootElementHandler:{enumerable:!1,writable:!1,value:this.__rootElementHandler},__refsHandler:{enumerable:!1,writable:!1,value:this.__refsHandler},__childrenHandler:{enumerable:!1,writable:!1,value:this.__childrenHandler}})}__manageRef(e,t,i){void 0===i&&(i="add");var r=i+"EventListener";this.__getEventMethodsByName(e).forEach(i=>{var s=this.__getEventNameByMethod(i,e);t.forEach(e=>e[r](s,this.__refsHandler))})}bindRef(e,t){this.__manageRef(e,t)}unbindRef(e,t){this.__manageRef(e,t,"remove")}__manageChild(e,t,i){void 0===i&&(i="add");var r="add"===i?"$on":"$off";this.__getEventMethodsByName(e).forEach(i=>{var s=this.__getEventNameByMethod(i,e);t[r](s,this.__childrenHandler)})}bindChild(e,t){this.__manageChild(e,t)}unbindChild(e,t){this.__manageChild(e,t,"remove")}__manageRootElement(e){void 0===e&&(e="add");var t=e+"EventListener";this.__getEventMethodsByName().forEach(e=>{var i=this.__getEventNameByMethod(e);this.__rootElement[t](i,this.__rootElementHandler)})}bindRootElement(){this.__manageRootElement()}unbindRootElement(){this.__manageRootElement("remove")}__getEventNameByMethod(e,t){void 0===t&&(t="");var i=S.normalizeName(t),r=new RegExp("^on"+i+"([A-Z].*)$"),[,s]=e.match(r);return S.normalizeEventName(s)}__getEventMethodsByName(e){void 0===e&&(e="");var t=S.normalizeName(e),i=new RegExp("^on"+t+"[A-Z].*$"),r=i.toString(),s=this.__methodsCache.get(r);return s||(s=Array.from(P(this.__base,[],e=>i.test(e)).reduce((e,t)=>{var[i]=t;return e.add(i)},new Set)),this.__methodsCache.set(r,s)),s}static normalizeName(e){return e.replace(/[A-Z]([A-Z].*)/g,e=>e.toLowerCase()).replace(/[^a-zA-Z\d\s:]/g," ").replace(/(^\w|\s+\w)/g,e=>e.trim().toUpperCase()).trim()}static normalizeEventName(e){return e.replace(/[A-Z]/g,e=>"-"+e.toLowerCase()).replace(/^-/,"")}}var C=function(e){return function(e){return!!e&&"object"==typeof e}(e)&&!function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===I}(e)}(e)},I="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function R(e,t){return!1!==t.clone&&t.isMergeableObject(e)?V(Array.isArray(e)?[]:{},e,t):e}function W(e,t,i){return e.concat(t).map(function(e){return R(e,i)})}function z(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return e.propertyIsEnumerable(t)}):[]}(e))}function D(e,t){try{return t in e}catch(e){return!1}}function V(e,t,i){(i=i||{}).arrayMerge=i.arrayMerge||W,i.isMergeableObject=i.isMergeableObject||C,i.cloneUnlessOtherwiseSpecified=R;var r=Array.isArray(t);return r===Array.isArray(e)?r?i.arrayMerge(e,t,i):function(e,t,i){var r={};return i.isMergeableObject(e)&&z(e).forEach(function(t){r[t]=R(e[t],i)}),z(t).forEach(function(s){(function(e,t){return D(e,t)&&!(Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))})(e,s)||(r[s]=D(e,s)&&i.isMergeableObject(t[s])?function(e,t){if(!t.customMerge)return V;var i=t.customMerge(e);return"function"==typeof i?i:V}(s,i)(e[s],t[s],i):R(t[s],i))}),r}(e,t,i):R(t,i)}V.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(e,i){return V(e,i,t)},{})};var q=V;class F{constructor(e,t,i){var r,s;return this.__values={},this.__defaultValues={String:"",Number:0,Boolean:!1,Array:()=>[],Object:()=>({})},this.name="Base",this.debug=!1,this.log=!1,Object.defineProperties(this,{__element:{enumerable:!1,writable:!1,value:e},__values:{enumerable:!1,writable:!1,value:this.__values},__defaultValues:{enumerable:!1,writable:!1,value:this.__defaultValues}}),this.name=i.name,t.debug={type:Boolean,default:null!=(r=i.debug)&&r},t.log={type:Boolean,default:null!=(s=i.log)&&s},Object.entries(t).forEach(e=>{var[t,i]=e;this.__register(t,i)}),this}__register(e,t){var i=!F.types.includes(t),r=i?t.type:t;if(!F.types.includes(r))throw new Error('The "'+e+'" option has an invalid type. The allowed types are: String, Number, Boolean, Array and Object.');var s=i?t.default:this.__defaultValues[r.name];if((r===Array||r===Object)&&"function"!=typeof s)throw new Error('The default value for options of type "'+r.name+'" must be returned by a function.');Object.defineProperty(this,e,{get:()=>this.get(e,r,s),set:t=>{this.set(e,r,t,s)},enumerable:!0})}get(e,t,i){var r=F.__getPropertyName(e),s=this.__hasProperty(r);if(t===Boolean){if(i){var n=F.__getPropertyName(e,"No");return!this.__hasProperty(n)}return s||i}var o=this.__element.dataset[r];if(t===Number)return s?Number(o):i;if(t===Array||t===Object){var a=q(i(),s?JSON.parse(o):this.__defaultValues[t.name]());return this.__values[e]||(this.__values[e]=a),this.__values[e]}return s?o:i}set(e,t,i,r){var s=F.__getPropertyName(e);if(i.constructor.name!==t.name){var n=Array.isArray(i)||function(e){return"object"==typeof e&&!!e&&"[object Object]"===e.toString()}(i)?JSON.stringify(i):i;throw new TypeError('The "'+n+'" value for the "'+e+'" option must be of type "'+t.name+'"')}switch(t){case Boolean:if(r){var o=F.__getPropertyName(e,"No");i?delete this.__element.dataset[o]:this.__element.dataset[o]=""}else i?this.__element.dataset[s]="":delete this.__element.dataset[s];break;case Array:case Object:this.__values[e]=i;break;default:this.__element.dataset[s]=i}}__hasProperty(e){return void 0!==this.__element.dataset[e]}static __getPropertyName(e,t){void 0===t&&(t="");var i=e+t;if(F.__propertyNameCache.has(i))return F.__propertyNameCache.get(i);var r="option"+t+e.replace(/^\w/,e=>e.toUpperCase());return F.__propertyNameCache.set(i,r),r}}F.types=[String,Number,Boolean,Array,Object],F.__propertyNameCache=new Map;var G=0;function Y(){}class X{get $root(){if(!this.$parent)return this;for(var e=this.$parent,t=this.$parent;e;)e.$parent||(t=e),e=e.$parent;return t}get __config(){for(var e=Object.getPrototypeOf(this),{config:i}=e.constructor;e.constructor.config&&e.constructor.$isBase;)i=t({},e.constructor.config,i),e.constructor.config.options&&(i.options=t({},e.constructor.config.options,i.options)),e=Object.getPrototypeOf(e);return i}get $services(){var e=this.__services;return this.$emit("get:services",e),e}get $refs(){var e=this.__refs;return this.$emit("get:refs",e),e}get $options(){var e=this.__options;return this.$emit("get:options",e),e}get $children(){var e=this.__children;return this.$emit("get:children",e),e}get $log(){return this.__options.log?window.console.log.bind(window,"["+this.__config.name+"]"):Y}get __debug(){return this.__options.debug&&void 0!==window.__DEV__&&window.__DEV__?window.console.log.bind(window,"[debug] ["+this.$id+"]"):Y}constructor(e){if(this.$parent=null,this.$isMounted=!1,!e)throw new Error("The root element must be defined.");var{__config:t}=this;if(!t)throw new Error("The `config` static property must be defined.");if(!t.name)throw new Error("The `config.name` property is required.");return this.$id=t.name+"-"+G,G+=1,this.$el=e,"__base__"in this.$el||Object.defineProperty(this.$el,"__base__",{get:()=>this,configurable:!0}),this.__options=new F(e,t.options||{},t),this.__services=new H(this),this.__events=new S(e,this),this.__children=new h(this,e,t.components||{},this.__events),this.__refs=new d(this,e,t.refs||[],this.__events),this.__debug("constructor",this),this}$mount(){return this.__debug("$mount"),this.$children.registerAll(),this.$refs.registerAll(),this.__events.bindRootElement(),this.$services.enableAll(),this.$children.mountAll(),o(this,"mounted"),this.$isMounted=!0,this}$update(){return this.__debug("$update"),this.$refs.unregisterAll(),this.$services.disableAll(),this.$children.registerAll(),this.$refs.registerAll(),this.$services.enableAll(),this.$children.updateAll(),o(this,"updated"),this}$destroy(){return this.__debug("$destroy"),this.__events.unbindRootElement(),this.$refs.unregisterAll(),this.$services.disableAll(),this.$children.destroyAll(),o(this,"destroyed"),this.$isMounted=!1,this}$terminate(){this.__debug("$terminate"),this.$destroy(),o(this,"terminated"),Object.defineProperty(this.$el,"__base__",{value:"terminated",configurable:!1,writable:!1})}static $factory(e){if(!e)throw new Error("The $factory method requires a component’s name or selector to be specified.");return a(e).map(e=>new this(e).$mount())}$on(e,t,i){return this.__debug("$on",e,t,i),this.$el.addEventListener(e,t,i),()=>{this.$off(e,t,i)}}$off(e,t,i){this.__debug("$off",e,t),this.$el.removeEventListener(e,t,i)}$emit(e){var t=[].slice.call(arguments,1);this.__debug("$emit",e,t),this.$el.dispatchEvent(new CustomEvent(e,{detail:t}))}}function U(e){var{breakpoint:t}=w().props();e.forEach(e=>{var[i,r]=e;i.includes(t)&&!r.$isMounted?setTimeout(()=>r.$mount(),0):!i.includes(t)&&r.$isMounted&&r.$destroy()})}X.$isBase=!0;var Z=new WeakMap;function J(e,t){void 0===t&&(t=w().props().breakpoint);var{activeBreakpoints:i,inactiveBreakpoints:r}=e.$options,s=i&&i.split(" ").includes(t),n=r&&r.split(" ").includes(t);return i&&s||r&&!n?"$mount":"$destroy"}function K(e){var{activeBreakpoints:t,inactiveBreakpoints:i}=e.$options;return Boolean(t||i)}function Q(e,t){!function(e){var{activeBreakpoints:t,inactiveBreakpoints:i,name:r}=e.$options;if(t&&i)throw new Error("["+r+"] Incorrect configuration: the `activeBreakpoints` and `inactiveBreakpoints` are not compatible.")}(t);var{add:i,has:r}=w();r(e)||i(e,function(e){var{breakpoint:i}=e,r=J(t,i);"$destroy"===r&&t.$isMounted?t[r]():"$mount"!==r||t.$isMounted||setTimeout(()=>t[r](),0)})}function ee(e,t,i){if(void 0===i&&(i=.85),i>=1||i<=0)throw new Error("The `factor` parameter must be a number greater than 0 and smaller than 1, `"+i+"` given.");for(var r=t,s=e;Math.abs(r)>.1;)s+=r,r*=i;return s}var te="drag",ie="inertia",re=0;class se extends l{constructor(e,i){return void 0===i&&(i={}),super(),this.isGrabbing=!1,this.hasInertia=!1,this.x=0,this.y=0,this.delta={x:0,y:0},this.origin={x:0,y:0},this.distance={x:0,y:0},this.final={x:0,y:0},this.options={factor:.85},this.id="drag-"+(re+=1),this.target=e,this.options=t({},this.options,i),this.pointerHandler=this.pointerHandler.bind(this),this.rafHandler=this.rafHandler.bind(this),this}init(){var e={passive:!0};return this.target.addEventListener("mousedown",this,e),this.target.addEventListener("touchstart",this,e),m().add(this.id,this.pointerHandler),this}kill(){return this.target.removeEventListener("mousemove",this),this.target.removeEventListener("touchmove",this),m().remove(this.id),this}handleEvent(e){var t=e instanceof MouseEvent?e.clientX:e.touches[0].clientX,i=e instanceof MouseEvent?e.clientY:e.touches[0].clientY;this.start(t,i)}start(e,t){this.x=e,this.y=t,this.origin.x=e,this.origin.y=t,this.delta.x=0,this.delta.y=0,this.distance.x=0,this.distance.y=0,this.final.x=e,this.final.y=t,this.mode="start",this.isGrabbing=!0,this.trigger(this.props)}drop(){this.isGrabbing=!1,this.mode="drop",this.hasInertia=!0,this.final.x=ee(this.x,this.delta.x,this.options.factor),this.final.y=ee(this.y,this.delta.y,this.options.factor),this.trigger(this.props),setTimeout(()=>{var e=f();e.remove(this.id),e.add(this.id,this.rafHandler)},0)}stop(){f().remove(this.id),this.hasInertia=!1,this.mode="stop",this.trigger(this.props)}rafHandler(){this.isGrabbing||(this.x+=this.delta.x,this.y+=this.delta.y,this.distance.x=this.x-this.origin.x,this.distance.y=this.y-this.origin.y,this.delta.x*=this.options.factor,this.delta.y*=this.options.factor,this.mode!==ie&&(this.mode=ie),this.trigger(this.props),Math.abs(this.delta.x)<.1&&Math.abs(this.delta.y)<.1&&this.stop())}pointerHandler(e){this.isGrabbing&&(this.x=e.x,this.y=e.y,this.delta.x=e.delta.x,this.delta.y=e.delta.y,this.final.x=e.x,this.final.y=e.y,this.distance.x=this.x-this.origin.x,this.distance.y=this.y-this.origin.y,this.mode!==te&&(this.mode=te),this.trigger(this.props),e.isDown||this.drop())}get props(){return{target:this.target,mode:this.mode,isGrabbing:this.isGrabbing,hasInertia:this.hasInertia,x:this.x,y:this.y,delta:this.delta,origin:this.origin,distance:this.distance,final:this.final}}}var ne=new WeakMap;function oe(e,t){var i=ne.get(e);return i||(i=new se(e,t),ne.set(e,i)),{add:i.add.bind(i),remove:i.remove.bind(i),has:i.has.bind(i),props:()=>i.props}}var ae=["target"];function he(e,t){return"string"==typeof e?a(e,t):Array.isArray(e)?e:[e]}e.Base=X,e.createApp=function(e,t){var i,r="complete"===document.readyState;r?i=new e(t).$mount():document.addEventListener("readystatechange",()=>{"complete"===document.readyState&&(i=new e(t).$mount(),r=!0)});var s=new Promise(e=>{document.addEventListener("readystatechange",()=>{"complete"===document.readyState&&setTimeout(()=>e(i),0)})});return function(){return r?Promise.resolve(i):s}},e.importOnInteraction=function(e,t,i,r){var s="string"==typeof i?[i]:i;return new Promise(i=>{var n=he(t,null==r?void 0:r.$el),o={capture:!0,passive:!0,once:!0},a=()=>{(t=>{e().then(e=>{t("default"in e?e.default:e)})})(i)};n.forEach(e=>{s.forEach(t=>{e.addEventListener(t,a,o)})})})},e.importWhenIdle=function(e,t){var i=t=>{e().then(e=>{t("default"in e?e.default:e)})};return new Promise(e=>{var r,s=null!=(r=null==t?void 0:t.timeout)?r:1;"requestIdleCallback"in window?window.requestIdleCallback(()=>{setTimeout(()=>{i(e)},0)},{timeout:null==t?void 0:t.timeout}):setTimeout(()=>{i(e)},s)})},e.importWhenVisible=function(e,t,i,r){return void 0===r&&(r={}),new Promise(s=>{var n=new IntersectionObserver(t=>{t.some(e=>e.isIntersecting)&&setTimeout(()=>{((t,i)=>{e().then(e=>{t("default"in e?e.default:e),n.disconnect()})})(s)},0)},r);he(t,null==i?void 0:i.$el).forEach(e=>n.observe(e))})},e.useDrag=oe,e.useKey=L,e.useLoad=N,e.usePointer=m,e.useRaf=f,e.useResize=w,e.useScroll=x,e.withBreakpointManager=function(e,t){if(!Array.isArray(t))throw new Error("[withBreakpointManager] The `breakpoints` parameter must be an array.");if(t.length<2)throw new Error("[withBreakpointManager] You must define at least 2 breakpoints.");var{add:i,props:r}=w();if(!r().breakpoint)throw new Error("The `BreakpointManager` class requires breakpoints to be defined.");return class extends e{constructor(e){return super(e),Z.has(this)||Z.set(this,function(e,t){return t.map(t=>{var[i,r]=t,s=new r(e.$el);return Object.defineProperty(s,"$parent",{get:()=>e.$parent}),[i,s]})}(this,t)),i("BreakpointManager-"+this.$id,()=>{U(Z.get(this))}),this.instances=Z.get(this),this}$mount(){return super.$mount(),U(Z.get(this)),this}$destroy(){return Array.isArray(Z.get(this))&&Z.get(this).forEach(e=>{var[,t]=e;t.$destroy()}),super.$destroy()}}},e.withBreakpointObserver=function(e){var i,r,s,n,o;return r=i=class extends e{constructor(e){super(e);var{remove:t,props:i}=w(),{name:r}=this.$options;if(!i().breakpoint)throw new Error("["+r+"] The `BreakpointObserver` class requires breakpoints to be defined.");var s="BreakpointObserver-"+this.$id;return new MutationObserver(e=>{var[i]=e;if("attributes"===i.type&&("data-options"===i.attributeName||i.attributeName.startsWith("data-option-"))){if(!K(this))return this.$mount(),void t(s);Q(s,this)}}).observe(this.$el,{attributes:!0}),K(this)?(Q(s,this),this):this}$mount(){return K(this)?"$mount"===J(this)?super.$mount():this:super.$mount()}},i.config=t({},e.config||{},{name:(null!=(s=null==e||null==(n=e.config)?void 0:n.name)?s:"")+"WithBreakpointObserver",options:t({},(null==e||null==(o=e.config)?void 0:o.options)||{},{activeBreakpoints:String,inactiveBreakpoints:String})}),r},e.withDrag=function(e,t){return void 0===t&&(t={target(){return this.$el}}),class extends e{constructor(e){super(e),this.$on("mounted",()=>{var{target:e}=t,i=function(e,t){if(null==e)return{};var i,r,s={},n=Object.keys(e);for(r=0;r<n.length;r++)t.indexOf(i=n[r])>=0||(s[i]=e[i]);return s}(t,ae),r=oe.bind(void 0,e.call(this),i);this.$services.register("dragged",r),this.$services.enable("dragged")}),this.$on("destroyed",()=>{this.$services.disable("dragged"),this.$services.unregister("dragged")})}}},e.withExtraConfig=function(e,t,i){var r,s;void 0===i&&(i={});var n=q(e.config,t,i);return n.name===e.config.name&&(n.name=e.config.name+"WithExtraConfig"),s=r=class extends e{},r.config=n,s},e.withIntersectionObserver=function(e,i){var r,s,n,o,a;return void 0===i&&(i={threshold:[...new Array(101)].map((e,t)=>t/100)}),s=r=class extends e{constructor(e){if(super(e),!this.intersected||"function"!=typeof this.intersected)throw new Error("[withIntersectionObserver] The `intersected` method must be defined.");return this.$observer=new IntersectionObserver(e=>{this.__debug("intersected",e),this.$emit("intersected",e),this.intersected(e)},t({},i,this.$options.intersectionObserver||{})),this.$on("mounted",()=>{this.$observer.observe(this.$el)}),this.$on("destroyed",()=>{this.$observer.unobserve(this.$el)}),this}},r.config=t({},e.config||{},{name:(null!=(n=null==e||null==(o=e.config)?void 0:o.name)?n:"")+"WithIntersectionObserver",options:t({},(null==e||null==(a=e.config)?void 0:a.options)||{},{intersectionObserver:Object})}),s},e.withMountWhenInView=function(e,i){var n,o,a,h,d,l,u;return void 0===i&&(i={threshold:[0,1]}),o=r("isVisible"),a=r("observer"),h=n=class extends e{constructor(e){return super(e),Object.defineProperty(this,o,{writable:!0,value:!1}),Object.defineProperty(this,a,{writable:!0,value:void 0}),s(this,a)[a]=new IntersectionObserver(e=>{var t=e.reduce((e,t)=>e||t.isIntersecting,!1);s(this,o)[o]!==t&&(s(this,o)[o]=t,this[t?"$mount":"$destroy"]())},t({},i,this.$options.intersectionObserver)),s(this,a)[a].observe(this.$el),this.$on("terminated",()=>{s(this,a)[a].disconnect()}),this}$mount(){return s(this,o)[o]&&super.$mount(),this}},n.config=t({},e.config||{},{name:(null!=(d=null==e||null==(l=e.config)?void 0:l.name)?d:"")+"WithMountWhenInView",options:t({},(null==e||null==(u=e.config)?void 0:u.options)||{},{intersectionObserver:Object})}),h}});
|