@ceeblue/web-utils 3.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web-utils.d.ts +28 -5
- package/dist/web-utils.js +38 -22
- package/dist/web-utils.js.map +1 -1
- package/dist/web-utils.min.js +1 -1
- package/dist/web-utils.min.js.map +1 -1
- package/package.json +1 -1
package/dist/web-utils.d.ts
CHANGED
|
@@ -302,7 +302,7 @@ type Params = {
|
|
|
302
302
|
/**
|
|
303
303
|
* Optional query to add into the generated url of connection
|
|
304
304
|
*/
|
|
305
|
-
query?:
|
|
305
|
+
query?: URLSearchParams;
|
|
306
306
|
};
|
|
307
307
|
/**
|
|
308
308
|
* Type of connection
|
|
@@ -349,6 +349,20 @@ declare namespace Connect {
|
|
|
349
349
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
350
350
|
*/
|
|
351
351
|
|
|
352
|
+
type FilterOnKey<T> = T extends 'once' | 'on' ? never : T extends `on${infer R}` ? R : never;
|
|
353
|
+
type CaseVariations<T extends string> = string extends T ? string : Lowercase<T> | Capitalize<T>;
|
|
354
|
+
/**
|
|
355
|
+
* Extract all event keys from a class.
|
|
356
|
+
* @example
|
|
357
|
+
* class Logger extends EventEmitter {
|
|
358
|
+
* onLog(log:string) { console.log(log); }
|
|
359
|
+
* onClick(log:string) { console.log(log); }
|
|
360
|
+
* }
|
|
361
|
+
* type LoggerEvents = EventKeys<Logger>; // "log" | "click"
|
|
362
|
+
*/
|
|
363
|
+
type EventKeys<Keys> = keyof {
|
|
364
|
+
[K in keyof Keys as CaseVariations<FilterOnKey<K>>]: never;
|
|
365
|
+
};
|
|
352
366
|
/**
|
|
353
367
|
* A advanced EventEmitter which allows to declare event as natural function in the inheriting children class,
|
|
354
368
|
* function must start by `on` prefix to be recognized as an event.
|
|
@@ -402,7 +416,7 @@ declare class EventEmitter extends Loggable {
|
|
|
402
416
|
* @param event Subscriber Function
|
|
403
417
|
* @param options.signal Optional `AbortSignal` to stop this or multiple subscriptions in same time
|
|
404
418
|
*/
|
|
405
|
-
on(name:
|
|
419
|
+
on(name: EventKeys<this>, event: Function, options?: {
|
|
406
420
|
signal?: AbortSignal;
|
|
407
421
|
}): void;
|
|
408
422
|
/**
|
|
@@ -411,7 +425,7 @@ declare class EventEmitter extends Loggable {
|
|
|
411
425
|
* @param event Subscriber Function
|
|
412
426
|
* @param options.abortSignal Optional `AbortSignal` to stop this or multiple subscriptions in same time
|
|
413
427
|
*/
|
|
414
|
-
once(name:
|
|
428
|
+
once(name: EventKeys<this>, event: Function, options?: {
|
|
415
429
|
signal?: AbortSignal;
|
|
416
430
|
}): void;
|
|
417
431
|
/**
|
|
@@ -419,7 +433,7 @@ declare class EventEmitter extends Loggable {
|
|
|
419
433
|
* @param name Name of event without the 'on' prefix (ex: 'log' to 'onLog' event declared)
|
|
420
434
|
* @param event Unsubscriber Function, must be the one passed to {@link on} or {@link once} subscription methods
|
|
421
435
|
*/
|
|
422
|
-
off(name:
|
|
436
|
+
off(name: EventKeys<this>, event: Function): boolean;
|
|
423
437
|
private _event;
|
|
424
438
|
}
|
|
425
439
|
|
|
@@ -783,10 +797,11 @@ declare function objectFrom(value: any, params: {
|
|
|
783
797
|
}): any;
|
|
784
798
|
/**
|
|
785
799
|
* Returns entries from something iterable, such as a Map, Set, or Array
|
|
800
|
+
* If value is null it returns an empty array
|
|
786
801
|
* @param value iterable input
|
|
787
802
|
* @returns An javascript object
|
|
788
803
|
*/
|
|
789
|
-
declare function objectEntries(value: any): [string, any][];
|
|
804
|
+
declare function objectEntries(value: any | null): [string, any][];
|
|
790
805
|
/**
|
|
791
806
|
* Converts various data types, such as objects, strings, exceptions, errors,
|
|
792
807
|
* or numbers, into a string representation. Since it offers a more comprehensive format,
|
|
@@ -1144,6 +1159,14 @@ declare class UIMetrics {
|
|
|
1144
1159
|
* set the metric unit-step in pixels
|
|
1145
1160
|
*/
|
|
1146
1161
|
set stepSize(value: number);
|
|
1162
|
+
/**
|
|
1163
|
+
* Return the space width available to display average metric
|
|
1164
|
+
*/
|
|
1165
|
+
get averageDisplayWidth(): number;
|
|
1166
|
+
/**
|
|
1167
|
+
* Return the count of displayable metrics regarding the space available on the screen
|
|
1168
|
+
*/
|
|
1169
|
+
get displayableCount(): number;
|
|
1147
1170
|
private _ui;
|
|
1148
1171
|
private _html?;
|
|
1149
1172
|
private _lineHeight;
|
package/dist/web-utils.js
CHANGED
|
@@ -258,10 +258,14 @@ function objectFrom(value, params) {
|
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
260
260
|
* Returns entries from something iterable, such as a Map, Set, or Array
|
|
261
|
+
* If value is null it returns an empty array
|
|
261
262
|
* @param value iterable input
|
|
262
263
|
* @returns An javascript object
|
|
263
264
|
*/
|
|
264
265
|
function objectEntries(value) {
|
|
266
|
+
if (!value) {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
265
269
|
if (value.entries) {
|
|
266
270
|
return value.entries();
|
|
267
271
|
}
|
|
@@ -1222,8 +1226,8 @@ function buildURL(type, params, protocol = 'wss') {
|
|
|
1222
1226
|
if (params.accessToken) {
|
|
1223
1227
|
url.searchParams.set('id', params.accessToken);
|
|
1224
1228
|
}
|
|
1225
|
-
for (const key
|
|
1226
|
-
url.searchParams.set(key,
|
|
1229
|
+
for (const [key, value] of objectEntries(params.query)) {
|
|
1230
|
+
url.searchParams.set(key, value);
|
|
1227
1231
|
}
|
|
1228
1232
|
return url;
|
|
1229
1233
|
}var Connect=/*#__PURE__*/Object.freeze({__proto__:null,get Type(){return Type},buildURL:buildURL,defineMediaExt:defineMediaExt});/**
|
|
@@ -1286,19 +1290,18 @@ class EventEmitter extends Loggable {
|
|
|
1286
1290
|
if (name.length < 3 || !name.startsWith('on')) {
|
|
1287
1291
|
continue;
|
|
1288
1292
|
}
|
|
1289
|
-
|
|
1293
|
+
let defaultEvent = proto[name];
|
|
1294
|
+
if (defaultEvent instanceof Function) {
|
|
1290
1295
|
const events = new Set();
|
|
1291
1296
|
this._events.set(name.substring(2).toLowerCase(), events);
|
|
1292
|
-
let defaultEvent = proto[name];
|
|
1293
1297
|
const raise = (...args) => {
|
|
1294
|
-
// Call default event if not
|
|
1295
|
-
|
|
1296
|
-
defaultEvent.call(this, ...args);
|
|
1297
|
-
}
|
|
1298
|
+
// Call default event if not undefined, can happen if assigned to null/undefined
|
|
1299
|
+
const result = defaultEvent ? defaultEvent.call(this, ...args) : undefined;
|
|
1298
1300
|
// Call subscribers
|
|
1299
1301
|
for (const event of events) {
|
|
1300
1302
|
event(...args);
|
|
1301
1303
|
}
|
|
1304
|
+
return result;
|
|
1302
1305
|
};
|
|
1303
1306
|
Object.defineProperties(this, {
|
|
1304
1307
|
[name]: {
|
|
@@ -1322,8 +1325,8 @@ class EventEmitter extends Loggable {
|
|
|
1322
1325
|
*/
|
|
1323
1326
|
on(name, event, options) {
|
|
1324
1327
|
var _a;
|
|
1325
|
-
if (
|
|
1326
|
-
throw Error('event
|
|
1328
|
+
if (typeof event !== 'function') {
|
|
1329
|
+
throw Error('event callback must be a function');
|
|
1327
1330
|
}
|
|
1328
1331
|
const events = this._event(name);
|
|
1329
1332
|
events.add(event);
|
|
@@ -1337,8 +1340,8 @@ class EventEmitter extends Loggable {
|
|
|
1337
1340
|
*/
|
|
1338
1341
|
once(name, event, options) {
|
|
1339
1342
|
var _a;
|
|
1340
|
-
if (
|
|
1341
|
-
throw Error('event
|
|
1343
|
+
if (typeof event !== 'function') {
|
|
1344
|
+
throw Error('event callback must be a function');
|
|
1342
1345
|
}
|
|
1343
1346
|
const events = this._event(name);
|
|
1344
1347
|
events.add((...args) => {
|
|
@@ -1356,7 +1359,7 @@ class EventEmitter extends Loggable {
|
|
|
1356
1359
|
if (!event) {
|
|
1357
1360
|
throw Error('event to unsubscribe cannot be null');
|
|
1358
1361
|
}
|
|
1359
|
-
this._event(name).delete(event);
|
|
1362
|
+
return this._event(name).delete(event);
|
|
1360
1363
|
}
|
|
1361
1364
|
_event(name) {
|
|
1362
1365
|
const events = this._events.get(name.toLowerCase());
|
|
@@ -2253,6 +2256,20 @@ class UIMetrics {
|
|
|
2253
2256
|
set stepSize(value) {
|
|
2254
2257
|
this._stepSize = value;
|
|
2255
2258
|
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Return the space width available to display average metric
|
|
2261
|
+
*/
|
|
2262
|
+
get averageDisplayWidth() {
|
|
2263
|
+
// 7 chars (1 char width ≈ fontSize/2)
|
|
2264
|
+
return (this._legendFontSize / 2) * 7;
|
|
2265
|
+
}
|
|
2266
|
+
/**
|
|
2267
|
+
* Return the count of displayable metrics regarding the space available on the screen
|
|
2268
|
+
*/
|
|
2269
|
+
get displayableCount() {
|
|
2270
|
+
const width = this._ui.clientWidth - this.averageDisplayWidth;
|
|
2271
|
+
return Math.ceil((width - this._labelWidth) / this._stepSize);
|
|
2272
|
+
}
|
|
2256
2273
|
constructor(ui) {
|
|
2257
2274
|
this._ui = ui;
|
|
2258
2275
|
// default values in pixels
|
|
@@ -2281,21 +2298,20 @@ class UIMetrics {
|
|
|
2281
2298
|
return;
|
|
2282
2299
|
}
|
|
2283
2300
|
this._html = '';
|
|
2284
|
-
const
|
|
2285
|
-
const
|
|
2301
|
+
const averageDisplayWidth = this.averageDisplayWidth;
|
|
2302
|
+
const averageCenter = averageDisplayWidth / 2;
|
|
2303
|
+
const width = this._ui.clientWidth - averageDisplayWidth;
|
|
2286
2304
|
const graphHeight = this._lineHeight - 2 * this._graphMargin;
|
|
2287
2305
|
const graphMiddle = Math.round(this._lineHeight / 2);
|
|
2288
2306
|
const textY = Math.round(this._lineHeight / 2 + this._textMargin);
|
|
2289
2307
|
const titleWidth = this._labelWidth - 2 * this._textMargin;
|
|
2290
|
-
const
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
if (x >= width) {
|
|
2294
|
-
x -= values.splice(0, Math.ceil((x - width) / this._stepSize)).length * this._stepSize;
|
|
2295
|
-
}
|
|
2308
|
+
for (const [key, fullValues] of stats) {
|
|
2309
|
+
const displayableCount = Math.ceil((width - this._labelWidth) / this._stepSize);
|
|
2310
|
+
const values = fullValues.slice(Math.max(0, fullValues.length - displayableCount));
|
|
2296
2311
|
if (!values.length) {
|
|
2297
2312
|
continue;
|
|
2298
2313
|
}
|
|
2314
|
+
let x = this._labelWidth + values.length * this._stepSize;
|
|
2299
2315
|
/*
|
|
2300
2316
|
<svg class="list-group-item p-0" style="height: 40px;" xmlns="http://www.w3.org/2000/svg">
|
|
2301
2317
|
<text x="5" y="22">M text</text>
|
|
@@ -2403,4 +2419,4 @@ class UIMetrics {
|
|
|
2403
2419
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
2404
2420
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
2405
2421
|
*/
|
|
2406
|
-
const VERSION = '
|
|
2422
|
+
const VERSION = '4.0.0';export{BinaryReader,BinaryWriter,BitReader,ByteRate,Connect,EpochTime,EventEmitter,FixMap,Log,LogLevel,Loggable,NetAddress,Numbers,Queue,SDP,UIMetrics,Util,VERSION,WebSocketReliable,log};//# sourceMappingURL=web-utils.js.map
|