@ceeblue/web-utils 3.1.0 → 3.2.1
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/commitlint.config.js +9 -0
- package/dist/web-utils.d.ts +9 -1
- package/dist/web-utils.js +196 -169
- 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 -6
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 Ceeblue B.V.
|
|
3
|
+
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
4
|
+
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
5
|
+
*/
|
|
6
|
+
export default {
|
|
7
|
+
extends: ['@commitlint/config-conventional'],
|
|
8
|
+
ignores: [commit => /^[^\r\n]*\[skip ci\]/.test(commit)]
|
|
9
|
+
};
|
package/dist/web-utils.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare class BinaryWriter {
|
|
|
53
53
|
* Write binary data
|
|
54
54
|
* @param data
|
|
55
55
|
*/
|
|
56
|
-
write(data: ArrayLike<number>): BinaryWriter;
|
|
56
|
+
write(data: ArrayLike<number> | BufferSource | string): BinaryWriter;
|
|
57
57
|
write8(value: number): BinaryWriter;
|
|
58
58
|
write16(value: number): BinaryWriter;
|
|
59
59
|
write24(value: number): BinaryWriter;
|
|
@@ -1144,6 +1144,14 @@ declare class UIMetrics {
|
|
|
1144
1144
|
* set the metric unit-step in pixels
|
|
1145
1145
|
*/
|
|
1146
1146
|
set stepSize(value: number);
|
|
1147
|
+
/**
|
|
1148
|
+
* Return the space width available to display average metric
|
|
1149
|
+
*/
|
|
1150
|
+
get averageDisplayWidth(): number;
|
|
1151
|
+
/**
|
|
1152
|
+
* Return the count of displayable metrics regarding the space available on the screen
|
|
1153
|
+
*/
|
|
1154
|
+
get displayableCount(): number;
|
|
1147
1155
|
private _ui;
|
|
1148
1156
|
private _html?;
|
|
1149
1157
|
private _lineHeight;
|
package/dist/web-utils.js
CHANGED
|
@@ -115,166 +115,6 @@ class BinaryReader {
|
|
|
115
115
|
const pos = this._position;
|
|
116
116
|
return this._data.subarray(pos, Math.max(pos, (this._position += size)));
|
|
117
117
|
}
|
|
118
|
-
}/**
|
|
119
|
-
* Copyright 2024 Ceeblue B.V.
|
|
120
|
-
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
121
|
-
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
122
|
-
*/
|
|
123
|
-
const _encoder$1 = new TextEncoder();
|
|
124
|
-
/**
|
|
125
|
-
* BinaryWriter allows to write data in its binary form
|
|
126
|
-
*/
|
|
127
|
-
class BinaryWriter {
|
|
128
|
-
get view() {
|
|
129
|
-
if (!this._view) {
|
|
130
|
-
this._view = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
|
|
131
|
-
}
|
|
132
|
-
return this._view;
|
|
133
|
-
}
|
|
134
|
-
get capacity() {
|
|
135
|
-
return this._data.byteLength;
|
|
136
|
-
}
|
|
137
|
-
constructor(dataOrSize = 64, offset = 0, length) {
|
|
138
|
-
if (typeof dataOrSize == 'number') {
|
|
139
|
-
// allocate new buffer
|
|
140
|
-
this._data = new Uint8Array(dataOrSize);
|
|
141
|
-
this._size = 0;
|
|
142
|
-
}
|
|
143
|
-
else if ('buffer' in dataOrSize) {
|
|
144
|
-
// append to existing data!
|
|
145
|
-
this._data = new Uint8Array(dataOrSize.buffer, dataOrSize.byteOffset, dataOrSize.byteLength);
|
|
146
|
-
this._size = dataOrSize.byteLength;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
// overrides data
|
|
150
|
-
this._isConst = true; // better than boolean for memory usage
|
|
151
|
-
if (length == null) {
|
|
152
|
-
// /!\ Safari does not support undefined length, so we need to use byteLength instead
|
|
153
|
-
length = dataOrSize.byteLength;
|
|
154
|
-
}
|
|
155
|
-
this._data = new Uint8Array(dataOrSize, offset, length);
|
|
156
|
-
this._size = 0;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
data() {
|
|
160
|
-
return new Uint8Array(this._data.buffer, this._data.byteOffset, this._size);
|
|
161
|
-
}
|
|
162
|
-
size() {
|
|
163
|
-
return this._size || 0;
|
|
164
|
-
}
|
|
165
|
-
next(count = 1) {
|
|
166
|
-
return this.reserve((this._size += count));
|
|
167
|
-
}
|
|
168
|
-
clear(size = 0) {
|
|
169
|
-
return this.reserve((this._size = size));
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Write binary data
|
|
173
|
-
* @param data
|
|
174
|
-
*/
|
|
175
|
-
write(data) {
|
|
176
|
-
this.reserve(this._size + data.length);
|
|
177
|
-
this._data.set(data, this._size);
|
|
178
|
-
this._size += data.length;
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
write8(value) {
|
|
182
|
-
if (value > 0xff) {
|
|
183
|
-
// cast to 8bits range
|
|
184
|
-
value = 0xff;
|
|
185
|
-
}
|
|
186
|
-
this.reserve(this._size + 1);
|
|
187
|
-
this._data[this._size++] = value;
|
|
188
|
-
return this;
|
|
189
|
-
}
|
|
190
|
-
write16(value) {
|
|
191
|
-
if (value > 0xffff) {
|
|
192
|
-
// cast to 16bits range
|
|
193
|
-
value = 0xffff;
|
|
194
|
-
}
|
|
195
|
-
this.reserve(this._size + 2);
|
|
196
|
-
this.view.setUint16(this._size, value);
|
|
197
|
-
this._size += 2;
|
|
198
|
-
return this;
|
|
199
|
-
}
|
|
200
|
-
write24(value) {
|
|
201
|
-
if (value > 0xffffff) {
|
|
202
|
-
// cast to 24bits range
|
|
203
|
-
value = 0xffffff;
|
|
204
|
-
}
|
|
205
|
-
this.reserve(this._size + 3);
|
|
206
|
-
this.view.setUint16(this._size, value >> 8);
|
|
207
|
-
this.view.setUint8((this._size += 2), value & 0xff);
|
|
208
|
-
++this._size;
|
|
209
|
-
return this;
|
|
210
|
-
}
|
|
211
|
-
write32(value) {
|
|
212
|
-
if (value > 0xffffffff) {
|
|
213
|
-
// cast to 32bits range
|
|
214
|
-
value = 0xffffffff;
|
|
215
|
-
}
|
|
216
|
-
this.reserve(this._size + 4);
|
|
217
|
-
this.view.setUint32(this._size, value);
|
|
218
|
-
this._size += 4;
|
|
219
|
-
return this;
|
|
220
|
-
}
|
|
221
|
-
write64(value) {
|
|
222
|
-
this.write32(value / 4294967296);
|
|
223
|
-
return this.write32(value & 0xffffffff);
|
|
224
|
-
}
|
|
225
|
-
writeFloat(value) {
|
|
226
|
-
this.reserve(this._size + 4);
|
|
227
|
-
this.view.setFloat32(this._size, value);
|
|
228
|
-
this._size += 4;
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
writeDouble(value) {
|
|
232
|
-
this.reserve(this._size + 8);
|
|
233
|
-
this.view.setFloat64(this._size, value);
|
|
234
|
-
this._size += 8;
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
write7Bit(value) {
|
|
238
|
-
let byte = value & 0x7f;
|
|
239
|
-
while ((value = Math.floor(value / 0x80))) {
|
|
240
|
-
// equivalent to >>=7 for JS!
|
|
241
|
-
this.write8(0x80 | byte);
|
|
242
|
-
byte = value & 0x7f;
|
|
243
|
-
}
|
|
244
|
-
return this.write8(byte);
|
|
245
|
-
}
|
|
246
|
-
writeString(value) {
|
|
247
|
-
return this.write(_encoder$1.encode(value)).write8(0);
|
|
248
|
-
}
|
|
249
|
-
writeHex(value) {
|
|
250
|
-
for (let i = 0; i < value.length; i += 2) {
|
|
251
|
-
this.write8(parseInt(value.substring(i, i + 2), 16));
|
|
252
|
-
}
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
reserve(size) {
|
|
256
|
-
if (!this._data) {
|
|
257
|
-
throw Error('buffer not writable');
|
|
258
|
-
}
|
|
259
|
-
if (size <= this._data.byteLength) {
|
|
260
|
-
return this;
|
|
261
|
-
}
|
|
262
|
-
if (this._isConst) {
|
|
263
|
-
throw Error('writing exceeds maximum ' + this._data.byteLength + ' bytes limit');
|
|
264
|
-
}
|
|
265
|
-
--size;
|
|
266
|
-
size |= size >> 1;
|
|
267
|
-
size |= size >> 2;
|
|
268
|
-
size |= size >> 4;
|
|
269
|
-
size |= size >> 8;
|
|
270
|
-
size |= size >> 16;
|
|
271
|
-
++size;
|
|
272
|
-
const data = new Uint8Array(size);
|
|
273
|
-
data.set(this._data); // copy old buffer!
|
|
274
|
-
this._data = data;
|
|
275
|
-
this._view = undefined; // release view
|
|
276
|
-
return this;
|
|
277
|
-
}
|
|
278
118
|
}/******************************************************************************
|
|
279
119
|
Copyright (c) Microsoft Corporation.
|
|
280
120
|
|
|
@@ -649,6 +489,180 @@ function trimEnd(value, chars = ' ') {
|
|
|
649
489
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
650
490
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
651
491
|
*/
|
|
492
|
+
/**
|
|
493
|
+
* BinaryWriter allows to write data in its binary form
|
|
494
|
+
*/
|
|
495
|
+
class BinaryWriter {
|
|
496
|
+
get view() {
|
|
497
|
+
if (!this._view) {
|
|
498
|
+
this._view = new DataView(this._data.buffer, this._data.byteOffset, this._data.byteLength);
|
|
499
|
+
}
|
|
500
|
+
return this._view;
|
|
501
|
+
}
|
|
502
|
+
get capacity() {
|
|
503
|
+
return this._data.byteLength;
|
|
504
|
+
}
|
|
505
|
+
constructor(dataOrSize = 64, offset = 0, length) {
|
|
506
|
+
if (typeof dataOrSize == 'number') {
|
|
507
|
+
// allocate new buffer
|
|
508
|
+
this._data = new Uint8Array(dataOrSize);
|
|
509
|
+
this._size = 0;
|
|
510
|
+
}
|
|
511
|
+
else if ('buffer' in dataOrSize) {
|
|
512
|
+
// append to existing data!
|
|
513
|
+
this._data = new Uint8Array(dataOrSize.buffer, dataOrSize.byteOffset, dataOrSize.byteLength);
|
|
514
|
+
this._size = dataOrSize.byteLength;
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
// overrides data
|
|
518
|
+
this._isConst = true; // better than boolean for memory usage
|
|
519
|
+
if (length == null) {
|
|
520
|
+
// /!\ Safari does not support undefined length, so we need to use byteLength instead
|
|
521
|
+
length = dataOrSize.byteLength;
|
|
522
|
+
}
|
|
523
|
+
this._data = new Uint8Array(dataOrSize, offset, length);
|
|
524
|
+
this._size = 0;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
data() {
|
|
528
|
+
return new Uint8Array(this._data.buffer, this._data.byteOffset, this._size);
|
|
529
|
+
}
|
|
530
|
+
size() {
|
|
531
|
+
return this._size || 0;
|
|
532
|
+
}
|
|
533
|
+
next(count = 1) {
|
|
534
|
+
return this.reserve((this._size += count));
|
|
535
|
+
}
|
|
536
|
+
clear(size = 0) {
|
|
537
|
+
return this.reserve((this._size = size));
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Write binary data
|
|
541
|
+
* @param data
|
|
542
|
+
*/
|
|
543
|
+
write(data) {
|
|
544
|
+
var _a;
|
|
545
|
+
let bin;
|
|
546
|
+
if (typeof data === 'string') {
|
|
547
|
+
// Convertit la chaîne en Uint8Array
|
|
548
|
+
bin = toBin(data);
|
|
549
|
+
}
|
|
550
|
+
else if (data instanceof ArrayBuffer) {
|
|
551
|
+
bin = new Uint8Array(data);
|
|
552
|
+
}
|
|
553
|
+
else if ('buffer' in data) {
|
|
554
|
+
bin = new Uint8Array(data.buffer, (_a = data.byteOffset) !== null && _a !== void 0 ? _a : 0, data.byteLength);
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
bin = data;
|
|
558
|
+
}
|
|
559
|
+
this.reserve(this._size + bin.length);
|
|
560
|
+
this._data.set(bin, this._size);
|
|
561
|
+
this._size += bin.length;
|
|
562
|
+
return this;
|
|
563
|
+
}
|
|
564
|
+
write8(value) {
|
|
565
|
+
if (value > 0xff) {
|
|
566
|
+
// cast to 8bits range
|
|
567
|
+
value = 0xff;
|
|
568
|
+
}
|
|
569
|
+
this.reserve(this._size + 1);
|
|
570
|
+
this._data[this._size++] = value;
|
|
571
|
+
return this;
|
|
572
|
+
}
|
|
573
|
+
write16(value) {
|
|
574
|
+
if (value > 0xffff) {
|
|
575
|
+
// cast to 16bits range
|
|
576
|
+
value = 0xffff;
|
|
577
|
+
}
|
|
578
|
+
this.reserve(this._size + 2);
|
|
579
|
+
this.view.setUint16(this._size, value);
|
|
580
|
+
this._size += 2;
|
|
581
|
+
return this;
|
|
582
|
+
}
|
|
583
|
+
write24(value) {
|
|
584
|
+
if (value > 0xffffff) {
|
|
585
|
+
// cast to 24bits range
|
|
586
|
+
value = 0xffffff;
|
|
587
|
+
}
|
|
588
|
+
this.reserve(this._size + 3);
|
|
589
|
+
this.view.setUint16(this._size, value >> 8);
|
|
590
|
+
this.view.setUint8((this._size += 2), value & 0xff);
|
|
591
|
+
++this._size;
|
|
592
|
+
return this;
|
|
593
|
+
}
|
|
594
|
+
write32(value) {
|
|
595
|
+
if (value > 0xffffffff) {
|
|
596
|
+
// cast to 32bits range
|
|
597
|
+
value = 0xffffffff;
|
|
598
|
+
}
|
|
599
|
+
this.reserve(this._size + 4);
|
|
600
|
+
this.view.setUint32(this._size, value);
|
|
601
|
+
this._size += 4;
|
|
602
|
+
return this;
|
|
603
|
+
}
|
|
604
|
+
write64(value) {
|
|
605
|
+
this.write32(value / 4294967296);
|
|
606
|
+
return this.write32(value & 0xffffffff);
|
|
607
|
+
}
|
|
608
|
+
writeFloat(value) {
|
|
609
|
+
this.reserve(this._size + 4);
|
|
610
|
+
this.view.setFloat32(this._size, value);
|
|
611
|
+
this._size += 4;
|
|
612
|
+
return this;
|
|
613
|
+
}
|
|
614
|
+
writeDouble(value) {
|
|
615
|
+
this.reserve(this._size + 8);
|
|
616
|
+
this.view.setFloat64(this._size, value);
|
|
617
|
+
this._size += 8;
|
|
618
|
+
return this;
|
|
619
|
+
}
|
|
620
|
+
write7Bit(value) {
|
|
621
|
+
let byte = value & 0x7f;
|
|
622
|
+
while ((value = Math.floor(value / 0x80))) {
|
|
623
|
+
// equivalent to >>=7 for JS!
|
|
624
|
+
this.write8(0x80 | byte);
|
|
625
|
+
byte = value & 0x7f;
|
|
626
|
+
}
|
|
627
|
+
return this.write8(byte);
|
|
628
|
+
}
|
|
629
|
+
writeString(value) {
|
|
630
|
+
return this.write(toBin(value)).write8(0);
|
|
631
|
+
}
|
|
632
|
+
writeHex(value) {
|
|
633
|
+
for (let i = 0; i < value.length; i += 2) {
|
|
634
|
+
this.write8(parseInt(value.substring(i, i + 2), 16));
|
|
635
|
+
}
|
|
636
|
+
return this;
|
|
637
|
+
}
|
|
638
|
+
reserve(size) {
|
|
639
|
+
if (!this._data) {
|
|
640
|
+
throw Error('buffer not writable');
|
|
641
|
+
}
|
|
642
|
+
if (size <= this._data.byteLength) {
|
|
643
|
+
return this;
|
|
644
|
+
}
|
|
645
|
+
if (this._isConst) {
|
|
646
|
+
throw Error('writing exceeds maximum ' + this._data.byteLength + ' bytes limit');
|
|
647
|
+
}
|
|
648
|
+
--size;
|
|
649
|
+
size |= size >> 1;
|
|
650
|
+
size |= size >> 2;
|
|
651
|
+
size |= size >> 4;
|
|
652
|
+
size |= size >> 8;
|
|
653
|
+
size |= size >> 16;
|
|
654
|
+
++size;
|
|
655
|
+
const data = new Uint8Array(size);
|
|
656
|
+
data.set(this._data); // copy old buffer!
|
|
657
|
+
this._data = data;
|
|
658
|
+
this._view = undefined; // release view
|
|
659
|
+
return this;
|
|
660
|
+
}
|
|
661
|
+
}/**
|
|
662
|
+
* Copyright 2024 Ceeblue B.V.
|
|
663
|
+
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
664
|
+
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
665
|
+
*/
|
|
652
666
|
/**
|
|
653
667
|
* Log levels
|
|
654
668
|
*/
|
|
@@ -2239,6 +2253,20 @@ class UIMetrics {
|
|
|
2239
2253
|
set stepSize(value) {
|
|
2240
2254
|
this._stepSize = value;
|
|
2241
2255
|
}
|
|
2256
|
+
/**
|
|
2257
|
+
* Return the space width available to display average metric
|
|
2258
|
+
*/
|
|
2259
|
+
get averageDisplayWidth() {
|
|
2260
|
+
// 7 chars (1 char width ≈ fontSize/2)
|
|
2261
|
+
return (this._legendFontSize / 2) * 7;
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Return the count of displayable metrics regarding the space available on the screen
|
|
2265
|
+
*/
|
|
2266
|
+
get displayableCount() {
|
|
2267
|
+
const width = this._ui.clientWidth - this.averageDisplayWidth;
|
|
2268
|
+
return Math.ceil((width - this._labelWidth) / this._stepSize);
|
|
2269
|
+
}
|
|
2242
2270
|
constructor(ui) {
|
|
2243
2271
|
this._ui = ui;
|
|
2244
2272
|
// default values in pixels
|
|
@@ -2267,21 +2295,20 @@ class UIMetrics {
|
|
|
2267
2295
|
return;
|
|
2268
2296
|
}
|
|
2269
2297
|
this._html = '';
|
|
2270
|
-
const
|
|
2271
|
-
const
|
|
2298
|
+
const averageDisplayWidth = this.averageDisplayWidth;
|
|
2299
|
+
const averageCenter = averageDisplayWidth / 2;
|
|
2300
|
+
const width = this._ui.clientWidth - averageDisplayWidth;
|
|
2272
2301
|
const graphHeight = this._lineHeight - 2 * this._graphMargin;
|
|
2273
2302
|
const graphMiddle = Math.round(this._lineHeight / 2);
|
|
2274
2303
|
const textY = Math.round(this._lineHeight / 2 + this._textMargin);
|
|
2275
2304
|
const titleWidth = this._labelWidth - 2 * this._textMargin;
|
|
2276
|
-
const
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
if (x >= width) {
|
|
2280
|
-
x -= values.splice(0, Math.ceil((x - width) / this._stepSize)).length * this._stepSize;
|
|
2281
|
-
}
|
|
2305
|
+
for (const [key, fullValues] of stats) {
|
|
2306
|
+
const displayableCount = Math.ceil((width - this._labelWidth) / this._stepSize);
|
|
2307
|
+
const values = fullValues.slice(Math.max(0, fullValues.length - displayableCount));
|
|
2282
2308
|
if (!values.length) {
|
|
2283
2309
|
continue;
|
|
2284
2310
|
}
|
|
2311
|
+
let x = this._labelWidth + values.length * this._stepSize;
|
|
2285
2312
|
/*
|
|
2286
2313
|
<svg class="list-group-item p-0" style="height: 40px;" xmlns="http://www.w3.org/2000/svg">
|
|
2287
2314
|
<text x="5" y="22">M text</text>
|
|
@@ -2389,4 +2416,4 @@ class UIMetrics {
|
|
|
2389
2416
|
* This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
|
|
2390
2417
|
* See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
|
|
2391
2418
|
*/
|
|
2392
|
-
const VERSION = '3.1
|
|
2419
|
+
const VERSION = '3.2.1';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
|