@opengeoweb/metronome 17.0.1 → 17.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/package.json +19 -7
- package/readme.mdx +7 -0
- package/index.d.ts +0 -1
- package/index.esm.js +0 -232
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# metronome
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Running unit tests
|
|
6
|
+
|
|
7
|
+
Run `nx test metronome` to execute the unit tests via [Jest](https://jestjs.io).
|
|
8
|
+
|
|
9
|
+
## Running storybook
|
|
10
|
+
|
|
11
|
+
Run `nx storybook metronome` to build and view the storybook at http://localhost:5700/.
|
|
12
|
+
|
|
13
|
+
### TypeScript Documentation
|
|
14
|
+
|
|
15
|
+
- [TypeScript Docs](https://opengeoweb.gitlab.io/opengeoweb/typescript-docs/metronome/)
|
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/metronome",
|
|
3
|
-
"version": "17.0
|
|
3
|
+
"version": "17.1.0",
|
|
4
4
|
"description": "GeoWeb metronome library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git@gitlab.com:opengeoweb/opengeoweb.git"
|
|
9
9
|
},
|
|
10
|
+
"main": "./dist/index.esm.js",
|
|
11
|
+
"module": "./dist/index.esm.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": "./package.json",
|
|
15
|
+
".": {
|
|
16
|
+
"@opengeoweb/source": "./src/index.ts",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.esm.js",
|
|
19
|
+
"default": "./dist/index.esm.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
10
22
|
"devDependencies": {
|
|
11
23
|
"eslint-plugin-storybook": "10.3.3"
|
|
12
24
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"package.json"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/readme.mdx
ADDED
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.esm.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
function _arrayLikeToArray(r, a) {
|
|
2
|
-
(null == a || a > r.length) && (a = r.length);
|
|
3
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
4
|
-
return n;
|
|
5
|
-
}
|
|
6
|
-
function _createForOfIteratorHelperLoose(r, e) {
|
|
7
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
8
|
-
if (t) return (t = t.call(r)).next.bind(t);
|
|
9
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
10
|
-
t && (r = t);
|
|
11
|
-
var o = 0;
|
|
12
|
-
return function () {
|
|
13
|
-
return o >= r.length ? {
|
|
14
|
-
done: true
|
|
15
|
-
} : {
|
|
16
|
-
done: false,
|
|
17
|
-
value: r[o++]
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
22
|
-
}
|
|
23
|
-
function _unsupportedIterableToArray(r, a) {
|
|
24
|
-
if (r) {
|
|
25
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
26
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
27
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/* *
|
|
32
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
33
|
-
* you may not use this file except in compliance with the License.
|
|
34
|
-
* You may obtain a copy of the License at
|
|
35
|
-
*
|
|
36
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
37
|
-
*
|
|
38
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
39
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
40
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
41
|
-
* See the License for the specific language governing permissions and
|
|
42
|
-
* limitations under the License.
|
|
43
|
-
*
|
|
44
|
-
* Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
45
|
-
* Copyright 2024 - Finnish Meteorological Institute (FMI)
|
|
46
|
-
* Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
|
|
47
|
-
* */
|
|
48
|
-
/**
|
|
49
|
-
* This class should NEVER be initialized with new Metronome(). Use the
|
|
50
|
-
* exported variable. To reset the metronome use unregisterAllTimers()
|
|
51
|
-
* to remove all existing timers followed by init() to initialize the
|
|
52
|
-
* ticks.
|
|
53
|
-
*/
|
|
54
|
-
var Metronome = /*#__PURE__*/function () {
|
|
55
|
-
function Metronome() {
|
|
56
|
-
this.tickId = void 0;
|
|
57
|
-
this.timers = void 0;
|
|
58
|
-
this.interval = void 0;
|
|
59
|
-
this.handleTimerTicks = void 0;
|
|
60
|
-
this.tickId = 0;
|
|
61
|
-
this.step = this.step.bind(this);
|
|
62
|
-
this.isPaused = this.isPaused.bind(this);
|
|
63
|
-
this.continueTimer = this.continueTimer.bind(this);
|
|
64
|
-
this.pauseTimer = this.pauseTimer.bind(this);
|
|
65
|
-
this.toggleTimer = this.toggleTimer.bind(this);
|
|
66
|
-
this.init = this.init.bind(this);
|
|
67
|
-
this.unregisterAllTimers = this.unregisterAllTimers.bind(this);
|
|
68
|
-
this.setSpeed = this.setSpeed.bind(this);
|
|
69
|
-
this.interval = null;
|
|
70
|
-
this.init();
|
|
71
|
-
this.handleTimerTicks = null;
|
|
72
|
-
this.timers = [];
|
|
73
|
-
}
|
|
74
|
-
var _proto = Metronome.prototype;
|
|
75
|
-
_proto.init = function init() {
|
|
76
|
-
if (this.interval != null) {
|
|
77
|
-
clearInterval(this.interval);
|
|
78
|
-
}
|
|
79
|
-
this.interval = setInterval(this.step, 10);
|
|
80
|
-
};
|
|
81
|
-
_proto.unregisterAllTimers = function unregisterAllTimers() {
|
|
82
|
-
this.timers.length = 0;
|
|
83
|
-
};
|
|
84
|
-
_proto.step = function step() {
|
|
85
|
-
var _this = this;
|
|
86
|
-
this.tickId += 1;
|
|
87
|
-
var triggeredTimerIds = [];
|
|
88
|
-
this.timers.forEach(function (timer) {
|
|
89
|
-
// Delay in x10 ms
|
|
90
|
-
var delay = 100 / timer.hertz;
|
|
91
|
-
// Get nearest multiple of delay
|
|
92
|
-
var nearestDelay = delay * Math.floor((_this.tickId + delay / 2) / delay);
|
|
93
|
-
var distanceToDelay = _this.tickId - nearestDelay;
|
|
94
|
-
if (Math.abs(distanceToDelay) < 0.5 || distanceToDelay === -0.5) {
|
|
95
|
-
if (!timer.isPaused) {
|
|
96
|
-
timer.timerFunc == null || timer.timerFunc(timer.timerId, _this.tickId);
|
|
97
|
-
triggeredTimerIds.push(timer.timerId);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
// Trigger the handleTimerTicks function with all collected timerIds
|
|
102
|
-
if (triggeredTimerIds.length > 0) {
|
|
103
|
-
var _this$handleTimerTick;
|
|
104
|
-
(_this$handleTimerTick = this.handleTimerTicks) == null || _this$handleTimerTick.call(this, triggeredTimerIds);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Multiple timers with varying frequencies can be made at the same
|
|
110
|
-
* time however each timerId must be unique. If you attempt to create
|
|
111
|
-
* two timers with the same timerId, the second will silently be ignored.
|
|
112
|
-
*
|
|
113
|
-
* @param timerFunc The function to be executed at the given hertz frequency
|
|
114
|
-
* @param hertz Frequency of the timer given in hertz
|
|
115
|
-
* @param timerId Id of the timer
|
|
116
|
-
* @returns Timer or nothing if no timer was created
|
|
117
|
-
*/;
|
|
118
|
-
_proto.register = function register(timerFunc, hertz, timerId) {
|
|
119
|
-
var existingTimer = this.timers.find(function (timer) {
|
|
120
|
-
return timer.timerId === timerId;
|
|
121
|
-
});
|
|
122
|
-
if (existingTimer) {
|
|
123
|
-
existingTimer.hertz = hertz;
|
|
124
|
-
existingTimer.timerFunc = timerFunc;
|
|
125
|
-
return existingTimer;
|
|
126
|
-
}
|
|
127
|
-
this.timers.push({
|
|
128
|
-
timerFunc: timerFunc,
|
|
129
|
-
hertz: hertz,
|
|
130
|
-
timerId: timerId,
|
|
131
|
-
isPaused: false
|
|
132
|
-
});
|
|
133
|
-
return this.timers.at(-1);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Unregistering a timer completely removes it, if you want to pause a
|
|
138
|
-
* timer, then use pauseTimer()
|
|
139
|
-
*
|
|
140
|
-
* @param timerId Id of the timer
|
|
141
|
-
*/;
|
|
142
|
-
_proto.unregister = function unregister(timerId) {
|
|
143
|
-
var indexToRemove = this.timers.findIndex(function (timer) {
|
|
144
|
-
return timer.timerId === timerId;
|
|
145
|
-
});
|
|
146
|
-
if (indexToRemove > -1) {
|
|
147
|
-
this.timers.splice(indexToRemove, 1);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Checks if a timer is paused
|
|
153
|
-
*
|
|
154
|
-
* @param timerId Id of the timer
|
|
155
|
-
* @returns true if the timer is paused, false if it is running
|
|
156
|
-
*/;
|
|
157
|
-
_proto.isPaused = function isPaused(timerId) {
|
|
158
|
-
for (var _iterator = _createForOfIteratorHelperLoose(this.timers), _step; !(_step = _iterator()).done;) {
|
|
159
|
-
var timer = _step.value;
|
|
160
|
-
if (timer.timerId === timerId && timer.isPaused) {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Continues running a timer
|
|
169
|
-
*
|
|
170
|
-
* @param timerId Id of the timer
|
|
171
|
-
*/;
|
|
172
|
-
_proto.continueTimer = function continueTimer(timerId) {
|
|
173
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(this.timers), _step2; !(_step2 = _iterator2()).done;) {
|
|
174
|
-
var timer = _step2.value;
|
|
175
|
-
if (timer.timerId === timerId) {
|
|
176
|
-
timer.isPaused = false;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Pauses a timer
|
|
184
|
-
*
|
|
185
|
-
* @param timerId Id of the timer
|
|
186
|
-
*/;
|
|
187
|
-
_proto.pauseTimer = function pauseTimer(timerId) {
|
|
188
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(this.timers), _step3; !(_step3 = _iterator3()).done;) {
|
|
189
|
-
var timer = _step3.value;
|
|
190
|
-
if (timer.timerId === timerId) {
|
|
191
|
-
timer.isPaused = true;
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Toggles a timer to be paused or running. Be careful when asking redux
|
|
199
|
-
* to toggle a timer, it might toggle twice and therefore do nothing
|
|
200
|
-
*
|
|
201
|
-
* @param timerId Id of the timer
|
|
202
|
-
*/;
|
|
203
|
-
_proto.toggleTimer = function toggleTimer(timerId) {
|
|
204
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(this.timers), _step4; !(_step4 = _iterator4()).done;) {
|
|
205
|
-
var timer = _step4.value;
|
|
206
|
-
if (timer.timerId === timerId) {
|
|
207
|
-
timer.isPaused = !timer.isPaused;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Sets the speed of a timer to a new frequency given in hertz
|
|
215
|
-
*
|
|
216
|
-
* @param timerId Id of the timer
|
|
217
|
-
* @param hertz Frequency of the timer given in hertz
|
|
218
|
-
*/;
|
|
219
|
-
_proto.setSpeed = function setSpeed(timerId, hertz) {
|
|
220
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(this.timers), _step5; !(_step5 = _iterator5()).done;) {
|
|
221
|
-
var timer = _step5.value;
|
|
222
|
-
if (timer.timerId === timerId) {
|
|
223
|
-
timer.hertz = hertz;
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
return Metronome;
|
|
229
|
-
}();
|
|
230
|
-
var metronome = new Metronome();
|
|
231
|
-
|
|
232
|
-
export { metronome };
|