@nsshunt/stsvueutils 2.0.46 → 2.0.47
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/stsvueutils.mjs +6 -2155
- package/dist/stsvueutils.mjs.map +1 -1
- package/dist/stsvueutils.umd.js +6 -2153
- package/dist/stsvueutils.umd.js.map +1 -1
- package/package.json +2 -2
- package/types/commonTypes.d.ts +0 -43
- package/types/commonTypes.d.ts.map +1 -1
- package/types/index.d.ts +2 -8
- package/types/index.d.ts.map +1 -1
- package/types/plugins/requestResponseHelper.d.ts +0 -6
- package/types/plugins/requestResponseHelper.d.ts.map +1 -1
- package/types/plugins/{emitter.d.ts → stsEmitterPlugin.d.ts} +1 -1
- package/types/plugins/stsEmitterPlugin.d.ts.map +1 -0
- package/types/plugins/{storage.d.ts → stsStoragePlugin.d.ts} +1 -1
- package/types/plugins/stsStoragePlugin.d.ts.map +1 -0
- package/types/plugins/workerManager.d.ts +0 -20
- package/types/plugins/workerManager.d.ts.map +1 -1
- package/types/stores/TelemetryStore.d.ts +0 -6
- package/types/stores/TelemetryStore.d.ts.map +1 -1
- package/types/plugins/emitter.d.ts.map +0 -1
- package/types/plugins/storage.d.ts.map +0 -1
- package/types/plugins/stsTestWorkerDefinitions.d.ts +0 -94
- package/types/plugins/stsTestWorkerDefinitions.d.ts.map +0 -1
- package/types/plugins/workerInstance.d.ts +0 -17
- package/types/plugins/workerInstance.d.ts.map +0 -1
package/dist/stsvueutils.mjs
CHANGED
|
@@ -8,26 +8,12 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
|
|
|
8
8
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
9
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
10
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
|
-
var
|
|
12
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
13
|
-
set _(value) {
|
|
14
|
-
__privateSet(obj, member, value, setter);
|
|
15
|
-
},
|
|
16
|
-
get _() {
|
|
17
|
-
return __privateGet(obj, member, getter);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
var _debug, _debug2, _debug3, _store, _debug4, _storage, _workersEx, _runner, _workerId, _options, _STSInstrumentController, _app, _STSWorkerManager_instances, CreateRunnerCopy_fn, _SetRunnerIntoWorker, _ProcessTelemetry, _CreateAsyncRunner, _PostMessageToWorker, _TerminateWorker, _StopRunner, _StopWorker, _requestResponseMessages, _requestResponseMessageTimeout, _port, _debug5, _SetupListener, _collectorCollectorPort, _requestResponseHelper, _runners, _options2, _debug6, _SetMessagePort, _AddAsyncRunner, _StopRunners;
|
|
11
|
+
var _debug, _debug2, _debug3, _store, _debug4, _storage;
|
|
21
12
|
import { inject } from "vue";
|
|
22
|
-
import { defaultLogger
|
|
23
|
-
import { STSInstrumentControllerPluginKey, GetSTSInstrumentController, Gauge, GetSTSInstrumentControllerPluginKey } from "@nsshunt/stsobservability";
|
|
24
|
-
import { defineStore } from "pinia";
|
|
13
|
+
import { defaultLogger } from "@nsshunt/stsutils";
|
|
25
14
|
const STSStoragePluginKey = Symbol("storage");
|
|
26
15
|
const STSEmitterPluginKey = Symbol("emitter");
|
|
27
16
|
const STSWorkerManagerPluginKey = Symbol("workerManager");
|
|
28
|
-
function getDefaultExportFromCjs(x) {
|
|
29
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
30
|
-
}
|
|
31
17
|
var tinyEmitter = { exports: {} };
|
|
32
18
|
var hasRequiredTinyEmitter;
|
|
33
19
|
function requireTinyEmitter() {
|
|
@@ -97,9 +83,9 @@ const STSEmitterPlugin = {
|
|
|
97
83
|
/*! js-cookie v3.0.5 | MIT */
|
|
98
84
|
function assign(target) {
|
|
99
85
|
for (var i = 1; i < arguments.length; i++) {
|
|
100
|
-
var
|
|
101
|
-
for (var key in
|
|
102
|
-
target[key] =
|
|
86
|
+
var source = arguments[i];
|
|
87
|
+
for (var key in source) {
|
|
88
|
+
target[key] = source[key];
|
|
103
89
|
}
|
|
104
90
|
}
|
|
105
91
|
return target;
|
|
@@ -351,2150 +337,15 @@ const STSStoragePlugin = {
|
|
|
351
337
|
app.provide(STSStoragePluginKey, pluginInstance);
|
|
352
338
|
}
|
|
353
339
|
};
|
|
354
|
-
const URI_BASE_VUEUTILS = "/";
|
|
355
|
-
var eIWMessageCommands = /* @__PURE__ */ ((eIWMessageCommands2) => {
|
|
356
|
-
eIWMessageCommands2["InstrumentTelemetry"] = "__STS__InstrumentTelemetry";
|
|
357
|
-
eIWMessageCommands2["MessagePort"] = "__STS__MessagePort";
|
|
358
|
-
eIWMessageCommands2["MessagePortResponse"] = "__STS__MessagePortResponse";
|
|
359
|
-
eIWMessageCommands2["AddAsyncRunner"] = "__STS__AddAsyncRunner";
|
|
360
|
-
eIWMessageCommands2["StopAllAsyncRunners"] = "__STS__StopAllAsyncRunners";
|
|
361
|
-
return eIWMessageCommands2;
|
|
362
|
-
})(eIWMessageCommands || {});
|
|
363
|
-
const TelemetryStore = defineStore("__sts__TelemetryStore", {
|
|
364
|
-
// State
|
|
365
|
-
// https://pinia.vuejs.org/core-concepts/state.html
|
|
366
|
-
state: () => {
|
|
367
|
-
return {
|
|
368
|
-
workers: {}
|
|
369
|
-
};
|
|
370
|
-
},
|
|
371
|
-
// Getters
|
|
372
|
-
// https://pinia.vuejs.org/core-concepts/getters.html
|
|
373
|
-
// Actions
|
|
374
|
-
// https://pinia.vuejs.org/core-concepts/actions.html
|
|
375
|
-
actions: {
|
|
376
|
-
RemoveWorker(workerEx) {
|
|
377
|
-
delete this.workers[workerEx.id];
|
|
378
|
-
},
|
|
379
|
-
RemoveRunner(workerEx, runnerEx) {
|
|
380
|
-
const worker = this.workers[workerEx.id];
|
|
381
|
-
if (worker && worker.runners) {
|
|
382
|
-
delete worker.runners[runnerEx.id];
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
Update(workerEx, runnerEx) {
|
|
386
|
-
if (!this.workers[workerEx.id]) {
|
|
387
|
-
this.workers[workerEx.id] = {
|
|
388
|
-
id: workerEx.id,
|
|
389
|
-
state: workerEx.state,
|
|
390
|
-
primaryThreadWorkerOptions: { ...workerEx.primaryThreadWorkerOptions },
|
|
391
|
-
workerThreadWorkerOptions: { ...workerEx.workerThreadWorkerOptions },
|
|
392
|
-
runners: {}
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
const worker = this.workers[workerEx.id];
|
|
396
|
-
if (worker.runners) {
|
|
397
|
-
if (!worker.runners[runnerEx.id]) {
|
|
398
|
-
const runner = {
|
|
399
|
-
id: runnerEx.id,
|
|
400
|
-
asyncRunnerContext: { ...runnerEx.asyncRunnerContext },
|
|
401
|
-
options: { ...runnerEx.options },
|
|
402
|
-
state: runnerEx.state,
|
|
403
|
-
instrumentData: { ...runnerEx.instrumentData }
|
|
404
|
-
};
|
|
405
|
-
worker.runners[runner.id] = runner;
|
|
406
|
-
} else {
|
|
407
|
-
const runner = worker.runners[runnerEx.id];
|
|
408
|
-
runner.instrumentData = { ...runnerEx.instrumentData };
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
var IRunnerState = /* @__PURE__ */ ((IRunnerState2) => {
|
|
415
|
-
IRunnerState2["created"] = "created";
|
|
416
|
-
IRunnerState2["running"] = "running";
|
|
417
|
-
IRunnerState2["stopped"] = "stopped";
|
|
418
|
-
IRunnerState2["paused"] = "paused";
|
|
419
|
-
IRunnerState2["error"] = "error";
|
|
420
|
-
return IRunnerState2;
|
|
421
|
-
})(IRunnerState || {});
|
|
422
|
-
var IWorkerState = /* @__PURE__ */ ((IWorkerState2) => {
|
|
423
|
-
IWorkerState2["starting"] = "starting";
|
|
424
|
-
IWorkerState2["started"] = "started";
|
|
425
|
-
IWorkerState2["stopped"] = "stopped";
|
|
426
|
-
return IWorkerState2;
|
|
427
|
-
})(IWorkerState || {});
|
|
428
|
-
var ansiStyles = { exports: {} };
|
|
429
|
-
var colorName;
|
|
430
|
-
var hasRequiredColorName;
|
|
431
|
-
function requireColorName() {
|
|
432
|
-
if (hasRequiredColorName) return colorName;
|
|
433
|
-
hasRequiredColorName = 1;
|
|
434
|
-
colorName = {
|
|
435
|
-
"aliceblue": [240, 248, 255],
|
|
436
|
-
"antiquewhite": [250, 235, 215],
|
|
437
|
-
"aqua": [0, 255, 255],
|
|
438
|
-
"aquamarine": [127, 255, 212],
|
|
439
|
-
"azure": [240, 255, 255],
|
|
440
|
-
"beige": [245, 245, 220],
|
|
441
|
-
"bisque": [255, 228, 196],
|
|
442
|
-
"black": [0, 0, 0],
|
|
443
|
-
"blanchedalmond": [255, 235, 205],
|
|
444
|
-
"blue": [0, 0, 255],
|
|
445
|
-
"blueviolet": [138, 43, 226],
|
|
446
|
-
"brown": [165, 42, 42],
|
|
447
|
-
"burlywood": [222, 184, 135],
|
|
448
|
-
"cadetblue": [95, 158, 160],
|
|
449
|
-
"chartreuse": [127, 255, 0],
|
|
450
|
-
"chocolate": [210, 105, 30],
|
|
451
|
-
"coral": [255, 127, 80],
|
|
452
|
-
"cornflowerblue": [100, 149, 237],
|
|
453
|
-
"cornsilk": [255, 248, 220],
|
|
454
|
-
"crimson": [220, 20, 60],
|
|
455
|
-
"cyan": [0, 255, 255],
|
|
456
|
-
"darkblue": [0, 0, 139],
|
|
457
|
-
"darkcyan": [0, 139, 139],
|
|
458
|
-
"darkgoldenrod": [184, 134, 11],
|
|
459
|
-
"darkgray": [169, 169, 169],
|
|
460
|
-
"darkgreen": [0, 100, 0],
|
|
461
|
-
"darkgrey": [169, 169, 169],
|
|
462
|
-
"darkkhaki": [189, 183, 107],
|
|
463
|
-
"darkmagenta": [139, 0, 139],
|
|
464
|
-
"darkolivegreen": [85, 107, 47],
|
|
465
|
-
"darkorange": [255, 140, 0],
|
|
466
|
-
"darkorchid": [153, 50, 204],
|
|
467
|
-
"darkred": [139, 0, 0],
|
|
468
|
-
"darksalmon": [233, 150, 122],
|
|
469
|
-
"darkseagreen": [143, 188, 143],
|
|
470
|
-
"darkslateblue": [72, 61, 139],
|
|
471
|
-
"darkslategray": [47, 79, 79],
|
|
472
|
-
"darkslategrey": [47, 79, 79],
|
|
473
|
-
"darkturquoise": [0, 206, 209],
|
|
474
|
-
"darkviolet": [148, 0, 211],
|
|
475
|
-
"deeppink": [255, 20, 147],
|
|
476
|
-
"deepskyblue": [0, 191, 255],
|
|
477
|
-
"dimgray": [105, 105, 105],
|
|
478
|
-
"dimgrey": [105, 105, 105],
|
|
479
|
-
"dodgerblue": [30, 144, 255],
|
|
480
|
-
"firebrick": [178, 34, 34],
|
|
481
|
-
"floralwhite": [255, 250, 240],
|
|
482
|
-
"forestgreen": [34, 139, 34],
|
|
483
|
-
"fuchsia": [255, 0, 255],
|
|
484
|
-
"gainsboro": [220, 220, 220],
|
|
485
|
-
"ghostwhite": [248, 248, 255],
|
|
486
|
-
"gold": [255, 215, 0],
|
|
487
|
-
"goldenrod": [218, 165, 32],
|
|
488
|
-
"gray": [128, 128, 128],
|
|
489
|
-
"green": [0, 128, 0],
|
|
490
|
-
"greenyellow": [173, 255, 47],
|
|
491
|
-
"grey": [128, 128, 128],
|
|
492
|
-
"honeydew": [240, 255, 240],
|
|
493
|
-
"hotpink": [255, 105, 180],
|
|
494
|
-
"indianred": [205, 92, 92],
|
|
495
|
-
"indigo": [75, 0, 130],
|
|
496
|
-
"ivory": [255, 255, 240],
|
|
497
|
-
"khaki": [240, 230, 140],
|
|
498
|
-
"lavender": [230, 230, 250],
|
|
499
|
-
"lavenderblush": [255, 240, 245],
|
|
500
|
-
"lawngreen": [124, 252, 0],
|
|
501
|
-
"lemonchiffon": [255, 250, 205],
|
|
502
|
-
"lightblue": [173, 216, 230],
|
|
503
|
-
"lightcoral": [240, 128, 128],
|
|
504
|
-
"lightcyan": [224, 255, 255],
|
|
505
|
-
"lightgoldenrodyellow": [250, 250, 210],
|
|
506
|
-
"lightgray": [211, 211, 211],
|
|
507
|
-
"lightgreen": [144, 238, 144],
|
|
508
|
-
"lightgrey": [211, 211, 211],
|
|
509
|
-
"lightpink": [255, 182, 193],
|
|
510
|
-
"lightsalmon": [255, 160, 122],
|
|
511
|
-
"lightseagreen": [32, 178, 170],
|
|
512
|
-
"lightskyblue": [135, 206, 250],
|
|
513
|
-
"lightslategray": [119, 136, 153],
|
|
514
|
-
"lightslategrey": [119, 136, 153],
|
|
515
|
-
"lightsteelblue": [176, 196, 222],
|
|
516
|
-
"lightyellow": [255, 255, 224],
|
|
517
|
-
"lime": [0, 255, 0],
|
|
518
|
-
"limegreen": [50, 205, 50],
|
|
519
|
-
"linen": [250, 240, 230],
|
|
520
|
-
"magenta": [255, 0, 255],
|
|
521
|
-
"maroon": [128, 0, 0],
|
|
522
|
-
"mediumaquamarine": [102, 205, 170],
|
|
523
|
-
"mediumblue": [0, 0, 205],
|
|
524
|
-
"mediumorchid": [186, 85, 211],
|
|
525
|
-
"mediumpurple": [147, 112, 219],
|
|
526
|
-
"mediumseagreen": [60, 179, 113],
|
|
527
|
-
"mediumslateblue": [123, 104, 238],
|
|
528
|
-
"mediumspringgreen": [0, 250, 154],
|
|
529
|
-
"mediumturquoise": [72, 209, 204],
|
|
530
|
-
"mediumvioletred": [199, 21, 133],
|
|
531
|
-
"midnightblue": [25, 25, 112],
|
|
532
|
-
"mintcream": [245, 255, 250],
|
|
533
|
-
"mistyrose": [255, 228, 225],
|
|
534
|
-
"moccasin": [255, 228, 181],
|
|
535
|
-
"navajowhite": [255, 222, 173],
|
|
536
|
-
"navy": [0, 0, 128],
|
|
537
|
-
"oldlace": [253, 245, 230],
|
|
538
|
-
"olive": [128, 128, 0],
|
|
539
|
-
"olivedrab": [107, 142, 35],
|
|
540
|
-
"orange": [255, 165, 0],
|
|
541
|
-
"orangered": [255, 69, 0],
|
|
542
|
-
"orchid": [218, 112, 214],
|
|
543
|
-
"palegoldenrod": [238, 232, 170],
|
|
544
|
-
"palegreen": [152, 251, 152],
|
|
545
|
-
"paleturquoise": [175, 238, 238],
|
|
546
|
-
"palevioletred": [219, 112, 147],
|
|
547
|
-
"papayawhip": [255, 239, 213],
|
|
548
|
-
"peachpuff": [255, 218, 185],
|
|
549
|
-
"peru": [205, 133, 63],
|
|
550
|
-
"pink": [255, 192, 203],
|
|
551
|
-
"plum": [221, 160, 221],
|
|
552
|
-
"powderblue": [176, 224, 230],
|
|
553
|
-
"purple": [128, 0, 128],
|
|
554
|
-
"rebeccapurple": [102, 51, 153],
|
|
555
|
-
"red": [255, 0, 0],
|
|
556
|
-
"rosybrown": [188, 143, 143],
|
|
557
|
-
"royalblue": [65, 105, 225],
|
|
558
|
-
"saddlebrown": [139, 69, 19],
|
|
559
|
-
"salmon": [250, 128, 114],
|
|
560
|
-
"sandybrown": [244, 164, 96],
|
|
561
|
-
"seagreen": [46, 139, 87],
|
|
562
|
-
"seashell": [255, 245, 238],
|
|
563
|
-
"sienna": [160, 82, 45],
|
|
564
|
-
"silver": [192, 192, 192],
|
|
565
|
-
"skyblue": [135, 206, 235],
|
|
566
|
-
"slateblue": [106, 90, 205],
|
|
567
|
-
"slategray": [112, 128, 144],
|
|
568
|
-
"slategrey": [112, 128, 144],
|
|
569
|
-
"snow": [255, 250, 250],
|
|
570
|
-
"springgreen": [0, 255, 127],
|
|
571
|
-
"steelblue": [70, 130, 180],
|
|
572
|
-
"tan": [210, 180, 140],
|
|
573
|
-
"teal": [0, 128, 128],
|
|
574
|
-
"thistle": [216, 191, 216],
|
|
575
|
-
"tomato": [255, 99, 71],
|
|
576
|
-
"turquoise": [64, 224, 208],
|
|
577
|
-
"violet": [238, 130, 238],
|
|
578
|
-
"wheat": [245, 222, 179],
|
|
579
|
-
"white": [255, 255, 255],
|
|
580
|
-
"whitesmoke": [245, 245, 245],
|
|
581
|
-
"yellow": [255, 255, 0],
|
|
582
|
-
"yellowgreen": [154, 205, 50]
|
|
583
|
-
};
|
|
584
|
-
return colorName;
|
|
585
|
-
}
|
|
586
|
-
var conversions;
|
|
587
|
-
var hasRequiredConversions;
|
|
588
|
-
function requireConversions() {
|
|
589
|
-
if (hasRequiredConversions) return conversions;
|
|
590
|
-
hasRequiredConversions = 1;
|
|
591
|
-
const cssKeywords = requireColorName();
|
|
592
|
-
const reverseKeywords = {};
|
|
593
|
-
for (const key of Object.keys(cssKeywords)) {
|
|
594
|
-
reverseKeywords[cssKeywords[key]] = key;
|
|
595
|
-
}
|
|
596
|
-
const convert = {
|
|
597
|
-
rgb: { channels: 3, labels: "rgb" },
|
|
598
|
-
hsl: { channels: 3, labels: "hsl" },
|
|
599
|
-
hsv: { channels: 3, labels: "hsv" },
|
|
600
|
-
hwb: { channels: 3, labels: "hwb" },
|
|
601
|
-
cmyk: { channels: 4, labels: "cmyk" },
|
|
602
|
-
xyz: { channels: 3, labels: "xyz" },
|
|
603
|
-
lab: { channels: 3, labels: "lab" },
|
|
604
|
-
lch: { channels: 3, labels: "lch" },
|
|
605
|
-
hex: { channels: 1, labels: ["hex"] },
|
|
606
|
-
keyword: { channels: 1, labels: ["keyword"] },
|
|
607
|
-
ansi16: { channels: 1, labels: ["ansi16"] },
|
|
608
|
-
ansi256: { channels: 1, labels: ["ansi256"] },
|
|
609
|
-
hcg: { channels: 3, labels: ["h", "c", "g"] },
|
|
610
|
-
apple: { channels: 3, labels: ["r16", "g16", "b16"] },
|
|
611
|
-
gray: { channels: 1, labels: ["gray"] }
|
|
612
|
-
};
|
|
613
|
-
conversions = convert;
|
|
614
|
-
for (const model of Object.keys(convert)) {
|
|
615
|
-
if (!("channels" in convert[model])) {
|
|
616
|
-
throw new Error("missing channels property: " + model);
|
|
617
|
-
}
|
|
618
|
-
if (!("labels" in convert[model])) {
|
|
619
|
-
throw new Error("missing channel labels property: " + model);
|
|
620
|
-
}
|
|
621
|
-
if (convert[model].labels.length !== convert[model].channels) {
|
|
622
|
-
throw new Error("channel and label counts mismatch: " + model);
|
|
623
|
-
}
|
|
624
|
-
const { channels, labels } = convert[model];
|
|
625
|
-
delete convert[model].channels;
|
|
626
|
-
delete convert[model].labels;
|
|
627
|
-
Object.defineProperty(convert[model], "channels", { value: channels });
|
|
628
|
-
Object.defineProperty(convert[model], "labels", { value: labels });
|
|
629
|
-
}
|
|
630
|
-
convert.rgb.hsl = function(rgb) {
|
|
631
|
-
const r = rgb[0] / 255;
|
|
632
|
-
const g = rgb[1] / 255;
|
|
633
|
-
const b = rgb[2] / 255;
|
|
634
|
-
const min = Math.min(r, g, b);
|
|
635
|
-
const max = Math.max(r, g, b);
|
|
636
|
-
const delta = max - min;
|
|
637
|
-
let h;
|
|
638
|
-
let s;
|
|
639
|
-
if (max === min) {
|
|
640
|
-
h = 0;
|
|
641
|
-
} else if (r === max) {
|
|
642
|
-
h = (g - b) / delta;
|
|
643
|
-
} else if (g === max) {
|
|
644
|
-
h = 2 + (b - r) / delta;
|
|
645
|
-
} else if (b === max) {
|
|
646
|
-
h = 4 + (r - g) / delta;
|
|
647
|
-
}
|
|
648
|
-
h = Math.min(h * 60, 360);
|
|
649
|
-
if (h < 0) {
|
|
650
|
-
h += 360;
|
|
651
|
-
}
|
|
652
|
-
const l = (min + max) / 2;
|
|
653
|
-
if (max === min) {
|
|
654
|
-
s = 0;
|
|
655
|
-
} else if (l <= 0.5) {
|
|
656
|
-
s = delta / (max + min);
|
|
657
|
-
} else {
|
|
658
|
-
s = delta / (2 - max - min);
|
|
659
|
-
}
|
|
660
|
-
return [h, s * 100, l * 100];
|
|
661
|
-
};
|
|
662
|
-
convert.rgb.hsv = function(rgb) {
|
|
663
|
-
let rdif;
|
|
664
|
-
let gdif;
|
|
665
|
-
let bdif;
|
|
666
|
-
let h;
|
|
667
|
-
let s;
|
|
668
|
-
const r = rgb[0] / 255;
|
|
669
|
-
const g = rgb[1] / 255;
|
|
670
|
-
const b = rgb[2] / 255;
|
|
671
|
-
const v = Math.max(r, g, b);
|
|
672
|
-
const diff = v - Math.min(r, g, b);
|
|
673
|
-
const diffc = function(c) {
|
|
674
|
-
return (v - c) / 6 / diff + 1 / 2;
|
|
675
|
-
};
|
|
676
|
-
if (diff === 0) {
|
|
677
|
-
h = 0;
|
|
678
|
-
s = 0;
|
|
679
|
-
} else {
|
|
680
|
-
s = diff / v;
|
|
681
|
-
rdif = diffc(r);
|
|
682
|
-
gdif = diffc(g);
|
|
683
|
-
bdif = diffc(b);
|
|
684
|
-
if (r === v) {
|
|
685
|
-
h = bdif - gdif;
|
|
686
|
-
} else if (g === v) {
|
|
687
|
-
h = 1 / 3 + rdif - bdif;
|
|
688
|
-
} else if (b === v) {
|
|
689
|
-
h = 2 / 3 + gdif - rdif;
|
|
690
|
-
}
|
|
691
|
-
if (h < 0) {
|
|
692
|
-
h += 1;
|
|
693
|
-
} else if (h > 1) {
|
|
694
|
-
h -= 1;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
return [
|
|
698
|
-
h * 360,
|
|
699
|
-
s * 100,
|
|
700
|
-
v * 100
|
|
701
|
-
];
|
|
702
|
-
};
|
|
703
|
-
convert.rgb.hwb = function(rgb) {
|
|
704
|
-
const r = rgb[0];
|
|
705
|
-
const g = rgb[1];
|
|
706
|
-
let b = rgb[2];
|
|
707
|
-
const h = convert.rgb.hsl(rgb)[0];
|
|
708
|
-
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
709
|
-
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
710
|
-
return [h, w * 100, b * 100];
|
|
711
|
-
};
|
|
712
|
-
convert.rgb.cmyk = function(rgb) {
|
|
713
|
-
const r = rgb[0] / 255;
|
|
714
|
-
const g = rgb[1] / 255;
|
|
715
|
-
const b = rgb[2] / 255;
|
|
716
|
-
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
717
|
-
const c = (1 - r - k) / (1 - k) || 0;
|
|
718
|
-
const m = (1 - g - k) / (1 - k) || 0;
|
|
719
|
-
const y = (1 - b - k) / (1 - k) || 0;
|
|
720
|
-
return [c * 100, m * 100, y * 100, k * 100];
|
|
721
|
-
};
|
|
722
|
-
function comparativeDistance(x, y) {
|
|
723
|
-
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
|
724
|
-
}
|
|
725
|
-
convert.rgb.keyword = function(rgb) {
|
|
726
|
-
const reversed = reverseKeywords[rgb];
|
|
727
|
-
if (reversed) {
|
|
728
|
-
return reversed;
|
|
729
|
-
}
|
|
730
|
-
let currentClosestDistance = Infinity;
|
|
731
|
-
let currentClosestKeyword;
|
|
732
|
-
for (const keyword of Object.keys(cssKeywords)) {
|
|
733
|
-
const value = cssKeywords[keyword];
|
|
734
|
-
const distance = comparativeDistance(rgb, value);
|
|
735
|
-
if (distance < currentClosestDistance) {
|
|
736
|
-
currentClosestDistance = distance;
|
|
737
|
-
currentClosestKeyword = keyword;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
return currentClosestKeyword;
|
|
741
|
-
};
|
|
742
|
-
convert.keyword.rgb = function(keyword) {
|
|
743
|
-
return cssKeywords[keyword];
|
|
744
|
-
};
|
|
745
|
-
convert.rgb.xyz = function(rgb) {
|
|
746
|
-
let r = rgb[0] / 255;
|
|
747
|
-
let g = rgb[1] / 255;
|
|
748
|
-
let b = rgb[2] / 255;
|
|
749
|
-
r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
|
|
750
|
-
g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
|
|
751
|
-
b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
|
|
752
|
-
const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
|
753
|
-
const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
|
754
|
-
const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
|
755
|
-
return [x * 100, y * 100, z * 100];
|
|
756
|
-
};
|
|
757
|
-
convert.rgb.lab = function(rgb) {
|
|
758
|
-
const xyz = convert.rgb.xyz(rgb);
|
|
759
|
-
let x = xyz[0];
|
|
760
|
-
let y = xyz[1];
|
|
761
|
-
let z = xyz[2];
|
|
762
|
-
x /= 95.047;
|
|
763
|
-
y /= 100;
|
|
764
|
-
z /= 108.883;
|
|
765
|
-
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
766
|
-
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
767
|
-
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
768
|
-
const l = 116 * y - 16;
|
|
769
|
-
const a = 500 * (x - y);
|
|
770
|
-
const b = 200 * (y - z);
|
|
771
|
-
return [l, a, b];
|
|
772
|
-
};
|
|
773
|
-
convert.hsl.rgb = function(hsl) {
|
|
774
|
-
const h = hsl[0] / 360;
|
|
775
|
-
const s = hsl[1] / 100;
|
|
776
|
-
const l = hsl[2] / 100;
|
|
777
|
-
let t2;
|
|
778
|
-
let t3;
|
|
779
|
-
let val;
|
|
780
|
-
if (s === 0) {
|
|
781
|
-
val = l * 255;
|
|
782
|
-
return [val, val, val];
|
|
783
|
-
}
|
|
784
|
-
if (l < 0.5) {
|
|
785
|
-
t2 = l * (1 + s);
|
|
786
|
-
} else {
|
|
787
|
-
t2 = l + s - l * s;
|
|
788
|
-
}
|
|
789
|
-
const t1 = 2 * l - t2;
|
|
790
|
-
const rgb = [0, 0, 0];
|
|
791
|
-
for (let i = 0; i < 3; i++) {
|
|
792
|
-
t3 = h + 1 / 3 * -(i - 1);
|
|
793
|
-
if (t3 < 0) {
|
|
794
|
-
t3++;
|
|
795
|
-
}
|
|
796
|
-
if (t3 > 1) {
|
|
797
|
-
t3--;
|
|
798
|
-
}
|
|
799
|
-
if (6 * t3 < 1) {
|
|
800
|
-
val = t1 + (t2 - t1) * 6 * t3;
|
|
801
|
-
} else if (2 * t3 < 1) {
|
|
802
|
-
val = t2;
|
|
803
|
-
} else if (3 * t3 < 2) {
|
|
804
|
-
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
805
|
-
} else {
|
|
806
|
-
val = t1;
|
|
807
|
-
}
|
|
808
|
-
rgb[i] = val * 255;
|
|
809
|
-
}
|
|
810
|
-
return rgb;
|
|
811
|
-
};
|
|
812
|
-
convert.hsl.hsv = function(hsl) {
|
|
813
|
-
const h = hsl[0];
|
|
814
|
-
let s = hsl[1] / 100;
|
|
815
|
-
let l = hsl[2] / 100;
|
|
816
|
-
let smin = s;
|
|
817
|
-
const lmin = Math.max(l, 0.01);
|
|
818
|
-
l *= 2;
|
|
819
|
-
s *= l <= 1 ? l : 2 - l;
|
|
820
|
-
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
821
|
-
const v = (l + s) / 2;
|
|
822
|
-
const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
|
823
|
-
return [h, sv * 100, v * 100];
|
|
824
|
-
};
|
|
825
|
-
convert.hsv.rgb = function(hsv) {
|
|
826
|
-
const h = hsv[0] / 60;
|
|
827
|
-
const s = hsv[1] / 100;
|
|
828
|
-
let v = hsv[2] / 100;
|
|
829
|
-
const hi = Math.floor(h) % 6;
|
|
830
|
-
const f = h - Math.floor(h);
|
|
831
|
-
const p = 255 * v * (1 - s);
|
|
832
|
-
const q = 255 * v * (1 - s * f);
|
|
833
|
-
const t = 255 * v * (1 - s * (1 - f));
|
|
834
|
-
v *= 255;
|
|
835
|
-
switch (hi) {
|
|
836
|
-
case 0:
|
|
837
|
-
return [v, t, p];
|
|
838
|
-
case 1:
|
|
839
|
-
return [q, v, p];
|
|
840
|
-
case 2:
|
|
841
|
-
return [p, v, t];
|
|
842
|
-
case 3:
|
|
843
|
-
return [p, q, v];
|
|
844
|
-
case 4:
|
|
845
|
-
return [t, p, v];
|
|
846
|
-
case 5:
|
|
847
|
-
return [v, p, q];
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
convert.hsv.hsl = function(hsv) {
|
|
851
|
-
const h = hsv[0];
|
|
852
|
-
const s = hsv[1] / 100;
|
|
853
|
-
const v = hsv[2] / 100;
|
|
854
|
-
const vmin = Math.max(v, 0.01);
|
|
855
|
-
let sl;
|
|
856
|
-
let l;
|
|
857
|
-
l = (2 - s) * v;
|
|
858
|
-
const lmin = (2 - s) * vmin;
|
|
859
|
-
sl = s * vmin;
|
|
860
|
-
sl /= lmin <= 1 ? lmin : 2 - lmin;
|
|
861
|
-
sl = sl || 0;
|
|
862
|
-
l /= 2;
|
|
863
|
-
return [h, sl * 100, l * 100];
|
|
864
|
-
};
|
|
865
|
-
convert.hwb.rgb = function(hwb) {
|
|
866
|
-
const h = hwb[0] / 360;
|
|
867
|
-
let wh = hwb[1] / 100;
|
|
868
|
-
let bl = hwb[2] / 100;
|
|
869
|
-
const ratio = wh + bl;
|
|
870
|
-
let f;
|
|
871
|
-
if (ratio > 1) {
|
|
872
|
-
wh /= ratio;
|
|
873
|
-
bl /= ratio;
|
|
874
|
-
}
|
|
875
|
-
const i = Math.floor(6 * h);
|
|
876
|
-
const v = 1 - bl;
|
|
877
|
-
f = 6 * h - i;
|
|
878
|
-
if ((i & 1) !== 0) {
|
|
879
|
-
f = 1 - f;
|
|
880
|
-
}
|
|
881
|
-
const n = wh + f * (v - wh);
|
|
882
|
-
let r;
|
|
883
|
-
let g;
|
|
884
|
-
let b;
|
|
885
|
-
switch (i) {
|
|
886
|
-
default:
|
|
887
|
-
case 6:
|
|
888
|
-
case 0:
|
|
889
|
-
r = v;
|
|
890
|
-
g = n;
|
|
891
|
-
b = wh;
|
|
892
|
-
break;
|
|
893
|
-
case 1:
|
|
894
|
-
r = n;
|
|
895
|
-
g = v;
|
|
896
|
-
b = wh;
|
|
897
|
-
break;
|
|
898
|
-
case 2:
|
|
899
|
-
r = wh;
|
|
900
|
-
g = v;
|
|
901
|
-
b = n;
|
|
902
|
-
break;
|
|
903
|
-
case 3:
|
|
904
|
-
r = wh;
|
|
905
|
-
g = n;
|
|
906
|
-
b = v;
|
|
907
|
-
break;
|
|
908
|
-
case 4:
|
|
909
|
-
r = n;
|
|
910
|
-
g = wh;
|
|
911
|
-
b = v;
|
|
912
|
-
break;
|
|
913
|
-
case 5:
|
|
914
|
-
r = v;
|
|
915
|
-
g = wh;
|
|
916
|
-
b = n;
|
|
917
|
-
break;
|
|
918
|
-
}
|
|
919
|
-
return [r * 255, g * 255, b * 255];
|
|
920
|
-
};
|
|
921
|
-
convert.cmyk.rgb = function(cmyk) {
|
|
922
|
-
const c = cmyk[0] / 100;
|
|
923
|
-
const m = cmyk[1] / 100;
|
|
924
|
-
const y = cmyk[2] / 100;
|
|
925
|
-
const k = cmyk[3] / 100;
|
|
926
|
-
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
927
|
-
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
928
|
-
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
929
|
-
return [r * 255, g * 255, b * 255];
|
|
930
|
-
};
|
|
931
|
-
convert.xyz.rgb = function(xyz) {
|
|
932
|
-
const x = xyz[0] / 100;
|
|
933
|
-
const y = xyz[1] / 100;
|
|
934
|
-
const z = xyz[2] / 100;
|
|
935
|
-
let r;
|
|
936
|
-
let g;
|
|
937
|
-
let b;
|
|
938
|
-
r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
939
|
-
g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
940
|
-
b = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
941
|
-
r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
|
|
942
|
-
g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
|
|
943
|
-
b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
|
|
944
|
-
r = Math.min(Math.max(0, r), 1);
|
|
945
|
-
g = Math.min(Math.max(0, g), 1);
|
|
946
|
-
b = Math.min(Math.max(0, b), 1);
|
|
947
|
-
return [r * 255, g * 255, b * 255];
|
|
948
|
-
};
|
|
949
|
-
convert.xyz.lab = function(xyz) {
|
|
950
|
-
let x = xyz[0];
|
|
951
|
-
let y = xyz[1];
|
|
952
|
-
let z = xyz[2];
|
|
953
|
-
x /= 95.047;
|
|
954
|
-
y /= 100;
|
|
955
|
-
z /= 108.883;
|
|
956
|
-
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
957
|
-
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
958
|
-
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
959
|
-
const l = 116 * y - 16;
|
|
960
|
-
const a = 500 * (x - y);
|
|
961
|
-
const b = 200 * (y - z);
|
|
962
|
-
return [l, a, b];
|
|
963
|
-
};
|
|
964
|
-
convert.lab.xyz = function(lab) {
|
|
965
|
-
const l = lab[0];
|
|
966
|
-
const a = lab[1];
|
|
967
|
-
const b = lab[2];
|
|
968
|
-
let x;
|
|
969
|
-
let y;
|
|
970
|
-
let z;
|
|
971
|
-
y = (l + 16) / 116;
|
|
972
|
-
x = a / 500 + y;
|
|
973
|
-
z = y - b / 200;
|
|
974
|
-
const y2 = y ** 3;
|
|
975
|
-
const x2 = x ** 3;
|
|
976
|
-
const z2 = z ** 3;
|
|
977
|
-
y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
|
|
978
|
-
x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
|
|
979
|
-
z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
|
|
980
|
-
x *= 95.047;
|
|
981
|
-
y *= 100;
|
|
982
|
-
z *= 108.883;
|
|
983
|
-
return [x, y, z];
|
|
984
|
-
};
|
|
985
|
-
convert.lab.lch = function(lab) {
|
|
986
|
-
const l = lab[0];
|
|
987
|
-
const a = lab[1];
|
|
988
|
-
const b = lab[2];
|
|
989
|
-
let h;
|
|
990
|
-
const hr = Math.atan2(b, a);
|
|
991
|
-
h = hr * 360 / 2 / Math.PI;
|
|
992
|
-
if (h < 0) {
|
|
993
|
-
h += 360;
|
|
994
|
-
}
|
|
995
|
-
const c = Math.sqrt(a * a + b * b);
|
|
996
|
-
return [l, c, h];
|
|
997
|
-
};
|
|
998
|
-
convert.lch.lab = function(lch) {
|
|
999
|
-
const l = lch[0];
|
|
1000
|
-
const c = lch[1];
|
|
1001
|
-
const h = lch[2];
|
|
1002
|
-
const hr = h / 360 * 2 * Math.PI;
|
|
1003
|
-
const a = c * Math.cos(hr);
|
|
1004
|
-
const b = c * Math.sin(hr);
|
|
1005
|
-
return [l, a, b];
|
|
1006
|
-
};
|
|
1007
|
-
convert.rgb.ansi16 = function(args, saturation = null) {
|
|
1008
|
-
const [r, g, b] = args;
|
|
1009
|
-
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
|
1010
|
-
value = Math.round(value / 50);
|
|
1011
|
-
if (value === 0) {
|
|
1012
|
-
return 30;
|
|
1013
|
-
}
|
|
1014
|
-
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
1015
|
-
if (value === 2) {
|
|
1016
|
-
ansi += 60;
|
|
1017
|
-
}
|
|
1018
|
-
return ansi;
|
|
1019
|
-
};
|
|
1020
|
-
convert.hsv.ansi16 = function(args) {
|
|
1021
|
-
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
1022
|
-
};
|
|
1023
|
-
convert.rgb.ansi256 = function(args) {
|
|
1024
|
-
const r = args[0];
|
|
1025
|
-
const g = args[1];
|
|
1026
|
-
const b = args[2];
|
|
1027
|
-
if (r === g && g === b) {
|
|
1028
|
-
if (r < 8) {
|
|
1029
|
-
return 16;
|
|
1030
|
-
}
|
|
1031
|
-
if (r > 248) {
|
|
1032
|
-
return 231;
|
|
1033
|
-
}
|
|
1034
|
-
return Math.round((r - 8) / 247 * 24) + 232;
|
|
1035
|
-
}
|
|
1036
|
-
const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
1037
|
-
return ansi;
|
|
1038
|
-
};
|
|
1039
|
-
convert.ansi16.rgb = function(args) {
|
|
1040
|
-
let color = args % 10;
|
|
1041
|
-
if (color === 0 || color === 7) {
|
|
1042
|
-
if (args > 50) {
|
|
1043
|
-
color += 3.5;
|
|
1044
|
-
}
|
|
1045
|
-
color = color / 10.5 * 255;
|
|
1046
|
-
return [color, color, color];
|
|
1047
|
-
}
|
|
1048
|
-
const mult = (~~(args > 50) + 1) * 0.5;
|
|
1049
|
-
const r = (color & 1) * mult * 255;
|
|
1050
|
-
const g = (color >> 1 & 1) * mult * 255;
|
|
1051
|
-
const b = (color >> 2 & 1) * mult * 255;
|
|
1052
|
-
return [r, g, b];
|
|
1053
|
-
};
|
|
1054
|
-
convert.ansi256.rgb = function(args) {
|
|
1055
|
-
if (args >= 232) {
|
|
1056
|
-
const c = (args - 232) * 10 + 8;
|
|
1057
|
-
return [c, c, c];
|
|
1058
|
-
}
|
|
1059
|
-
args -= 16;
|
|
1060
|
-
let rem;
|
|
1061
|
-
const r = Math.floor(args / 36) / 5 * 255;
|
|
1062
|
-
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
1063
|
-
const b = rem % 6 / 5 * 255;
|
|
1064
|
-
return [r, g, b];
|
|
1065
|
-
};
|
|
1066
|
-
convert.rgb.hex = function(args) {
|
|
1067
|
-
const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
|
|
1068
|
-
const string = integer.toString(16).toUpperCase();
|
|
1069
|
-
return "000000".substring(string.length) + string;
|
|
1070
|
-
};
|
|
1071
|
-
convert.hex.rgb = function(args) {
|
|
1072
|
-
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
1073
|
-
if (!match) {
|
|
1074
|
-
return [0, 0, 0];
|
|
1075
|
-
}
|
|
1076
|
-
let colorString = match[0];
|
|
1077
|
-
if (match[0].length === 3) {
|
|
1078
|
-
colorString = colorString.split("").map((char) => {
|
|
1079
|
-
return char + char;
|
|
1080
|
-
}).join("");
|
|
1081
|
-
}
|
|
1082
|
-
const integer = parseInt(colorString, 16);
|
|
1083
|
-
const r = integer >> 16 & 255;
|
|
1084
|
-
const g = integer >> 8 & 255;
|
|
1085
|
-
const b = integer & 255;
|
|
1086
|
-
return [r, g, b];
|
|
1087
|
-
};
|
|
1088
|
-
convert.rgb.hcg = function(rgb) {
|
|
1089
|
-
const r = rgb[0] / 255;
|
|
1090
|
-
const g = rgb[1] / 255;
|
|
1091
|
-
const b = rgb[2] / 255;
|
|
1092
|
-
const max = Math.max(Math.max(r, g), b);
|
|
1093
|
-
const min = Math.min(Math.min(r, g), b);
|
|
1094
|
-
const chroma = max - min;
|
|
1095
|
-
let grayscale;
|
|
1096
|
-
let hue;
|
|
1097
|
-
if (chroma < 1) {
|
|
1098
|
-
grayscale = min / (1 - chroma);
|
|
1099
|
-
} else {
|
|
1100
|
-
grayscale = 0;
|
|
1101
|
-
}
|
|
1102
|
-
if (chroma <= 0) {
|
|
1103
|
-
hue = 0;
|
|
1104
|
-
} else if (max === r) {
|
|
1105
|
-
hue = (g - b) / chroma % 6;
|
|
1106
|
-
} else if (max === g) {
|
|
1107
|
-
hue = 2 + (b - r) / chroma;
|
|
1108
|
-
} else {
|
|
1109
|
-
hue = 4 + (r - g) / chroma;
|
|
1110
|
-
}
|
|
1111
|
-
hue /= 6;
|
|
1112
|
-
hue %= 1;
|
|
1113
|
-
return [hue * 360, chroma * 100, grayscale * 100];
|
|
1114
|
-
};
|
|
1115
|
-
convert.hsl.hcg = function(hsl) {
|
|
1116
|
-
const s = hsl[1] / 100;
|
|
1117
|
-
const l = hsl[2] / 100;
|
|
1118
|
-
const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
|
|
1119
|
-
let f = 0;
|
|
1120
|
-
if (c < 1) {
|
|
1121
|
-
f = (l - 0.5 * c) / (1 - c);
|
|
1122
|
-
}
|
|
1123
|
-
return [hsl[0], c * 100, f * 100];
|
|
1124
|
-
};
|
|
1125
|
-
convert.hsv.hcg = function(hsv) {
|
|
1126
|
-
const s = hsv[1] / 100;
|
|
1127
|
-
const v = hsv[2] / 100;
|
|
1128
|
-
const c = s * v;
|
|
1129
|
-
let f = 0;
|
|
1130
|
-
if (c < 1) {
|
|
1131
|
-
f = (v - c) / (1 - c);
|
|
1132
|
-
}
|
|
1133
|
-
return [hsv[0], c * 100, f * 100];
|
|
1134
|
-
};
|
|
1135
|
-
convert.hcg.rgb = function(hcg) {
|
|
1136
|
-
const h = hcg[0] / 360;
|
|
1137
|
-
const c = hcg[1] / 100;
|
|
1138
|
-
const g = hcg[2] / 100;
|
|
1139
|
-
if (c === 0) {
|
|
1140
|
-
return [g * 255, g * 255, g * 255];
|
|
1141
|
-
}
|
|
1142
|
-
const pure = [0, 0, 0];
|
|
1143
|
-
const hi = h % 1 * 6;
|
|
1144
|
-
const v = hi % 1;
|
|
1145
|
-
const w = 1 - v;
|
|
1146
|
-
let mg = 0;
|
|
1147
|
-
switch (Math.floor(hi)) {
|
|
1148
|
-
case 0:
|
|
1149
|
-
pure[0] = 1;
|
|
1150
|
-
pure[1] = v;
|
|
1151
|
-
pure[2] = 0;
|
|
1152
|
-
break;
|
|
1153
|
-
case 1:
|
|
1154
|
-
pure[0] = w;
|
|
1155
|
-
pure[1] = 1;
|
|
1156
|
-
pure[2] = 0;
|
|
1157
|
-
break;
|
|
1158
|
-
case 2:
|
|
1159
|
-
pure[0] = 0;
|
|
1160
|
-
pure[1] = 1;
|
|
1161
|
-
pure[2] = v;
|
|
1162
|
-
break;
|
|
1163
|
-
case 3:
|
|
1164
|
-
pure[0] = 0;
|
|
1165
|
-
pure[1] = w;
|
|
1166
|
-
pure[2] = 1;
|
|
1167
|
-
break;
|
|
1168
|
-
case 4:
|
|
1169
|
-
pure[0] = v;
|
|
1170
|
-
pure[1] = 0;
|
|
1171
|
-
pure[2] = 1;
|
|
1172
|
-
break;
|
|
1173
|
-
default:
|
|
1174
|
-
pure[0] = 1;
|
|
1175
|
-
pure[1] = 0;
|
|
1176
|
-
pure[2] = w;
|
|
1177
|
-
}
|
|
1178
|
-
mg = (1 - c) * g;
|
|
1179
|
-
return [
|
|
1180
|
-
(c * pure[0] + mg) * 255,
|
|
1181
|
-
(c * pure[1] + mg) * 255,
|
|
1182
|
-
(c * pure[2] + mg) * 255
|
|
1183
|
-
];
|
|
1184
|
-
};
|
|
1185
|
-
convert.hcg.hsv = function(hcg) {
|
|
1186
|
-
const c = hcg[1] / 100;
|
|
1187
|
-
const g = hcg[2] / 100;
|
|
1188
|
-
const v = c + g * (1 - c);
|
|
1189
|
-
let f = 0;
|
|
1190
|
-
if (v > 0) {
|
|
1191
|
-
f = c / v;
|
|
1192
|
-
}
|
|
1193
|
-
return [hcg[0], f * 100, v * 100];
|
|
1194
|
-
};
|
|
1195
|
-
convert.hcg.hsl = function(hcg) {
|
|
1196
|
-
const c = hcg[1] / 100;
|
|
1197
|
-
const g = hcg[2] / 100;
|
|
1198
|
-
const l = g * (1 - c) + 0.5 * c;
|
|
1199
|
-
let s = 0;
|
|
1200
|
-
if (l > 0 && l < 0.5) {
|
|
1201
|
-
s = c / (2 * l);
|
|
1202
|
-
} else if (l >= 0.5 && l < 1) {
|
|
1203
|
-
s = c / (2 * (1 - l));
|
|
1204
|
-
}
|
|
1205
|
-
return [hcg[0], s * 100, l * 100];
|
|
1206
|
-
};
|
|
1207
|
-
convert.hcg.hwb = function(hcg) {
|
|
1208
|
-
const c = hcg[1] / 100;
|
|
1209
|
-
const g = hcg[2] / 100;
|
|
1210
|
-
const v = c + g * (1 - c);
|
|
1211
|
-
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
1212
|
-
};
|
|
1213
|
-
convert.hwb.hcg = function(hwb) {
|
|
1214
|
-
const w = hwb[1] / 100;
|
|
1215
|
-
const b = hwb[2] / 100;
|
|
1216
|
-
const v = 1 - b;
|
|
1217
|
-
const c = v - w;
|
|
1218
|
-
let g = 0;
|
|
1219
|
-
if (c < 1) {
|
|
1220
|
-
g = (v - c) / (1 - c);
|
|
1221
|
-
}
|
|
1222
|
-
return [hwb[0], c * 100, g * 100];
|
|
1223
|
-
};
|
|
1224
|
-
convert.apple.rgb = function(apple) {
|
|
1225
|
-
return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
|
|
1226
|
-
};
|
|
1227
|
-
convert.rgb.apple = function(rgb) {
|
|
1228
|
-
return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
|
|
1229
|
-
};
|
|
1230
|
-
convert.gray.rgb = function(args) {
|
|
1231
|
-
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
1232
|
-
};
|
|
1233
|
-
convert.gray.hsl = function(args) {
|
|
1234
|
-
return [0, 0, args[0]];
|
|
1235
|
-
};
|
|
1236
|
-
convert.gray.hsv = convert.gray.hsl;
|
|
1237
|
-
convert.gray.hwb = function(gray) {
|
|
1238
|
-
return [0, 100, gray[0]];
|
|
1239
|
-
};
|
|
1240
|
-
convert.gray.cmyk = function(gray) {
|
|
1241
|
-
return [0, 0, 0, gray[0]];
|
|
1242
|
-
};
|
|
1243
|
-
convert.gray.lab = function(gray) {
|
|
1244
|
-
return [gray[0], 0, 0];
|
|
1245
|
-
};
|
|
1246
|
-
convert.gray.hex = function(gray) {
|
|
1247
|
-
const val = Math.round(gray[0] / 100 * 255) & 255;
|
|
1248
|
-
const integer = (val << 16) + (val << 8) + val;
|
|
1249
|
-
const string = integer.toString(16).toUpperCase();
|
|
1250
|
-
return "000000".substring(string.length) + string;
|
|
1251
|
-
};
|
|
1252
|
-
convert.rgb.gray = function(rgb) {
|
|
1253
|
-
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
1254
|
-
return [val / 255 * 100];
|
|
1255
|
-
};
|
|
1256
|
-
return conversions;
|
|
1257
|
-
}
|
|
1258
|
-
var route;
|
|
1259
|
-
var hasRequiredRoute;
|
|
1260
|
-
function requireRoute() {
|
|
1261
|
-
if (hasRequiredRoute) return route;
|
|
1262
|
-
hasRequiredRoute = 1;
|
|
1263
|
-
const conversions2 = requireConversions();
|
|
1264
|
-
function buildGraph() {
|
|
1265
|
-
const graph = {};
|
|
1266
|
-
const models = Object.keys(conversions2);
|
|
1267
|
-
for (let len = models.length, i = 0; i < len; i++) {
|
|
1268
|
-
graph[models[i]] = {
|
|
1269
|
-
// http://jsperf.com/1-vs-infinity
|
|
1270
|
-
// micro-opt, but this is simple.
|
|
1271
|
-
distance: -1,
|
|
1272
|
-
parent: null
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
return graph;
|
|
1276
|
-
}
|
|
1277
|
-
function deriveBFS(fromModel) {
|
|
1278
|
-
const graph = buildGraph();
|
|
1279
|
-
const queue = [fromModel];
|
|
1280
|
-
graph[fromModel].distance = 0;
|
|
1281
|
-
while (queue.length) {
|
|
1282
|
-
const current = queue.pop();
|
|
1283
|
-
const adjacents = Object.keys(conversions2[current]);
|
|
1284
|
-
for (let len = adjacents.length, i = 0; i < len; i++) {
|
|
1285
|
-
const adjacent = adjacents[i];
|
|
1286
|
-
const node = graph[adjacent];
|
|
1287
|
-
if (node.distance === -1) {
|
|
1288
|
-
node.distance = graph[current].distance + 1;
|
|
1289
|
-
node.parent = current;
|
|
1290
|
-
queue.unshift(adjacent);
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
return graph;
|
|
1295
|
-
}
|
|
1296
|
-
function link(from, to) {
|
|
1297
|
-
return function(args) {
|
|
1298
|
-
return to(from(args));
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
function wrapConversion(toModel, graph) {
|
|
1302
|
-
const path = [graph[toModel].parent, toModel];
|
|
1303
|
-
let fn = conversions2[graph[toModel].parent][toModel];
|
|
1304
|
-
let cur = graph[toModel].parent;
|
|
1305
|
-
while (graph[cur].parent) {
|
|
1306
|
-
path.unshift(graph[cur].parent);
|
|
1307
|
-
fn = link(conversions2[graph[cur].parent][cur], fn);
|
|
1308
|
-
cur = graph[cur].parent;
|
|
1309
|
-
}
|
|
1310
|
-
fn.conversion = path;
|
|
1311
|
-
return fn;
|
|
1312
|
-
}
|
|
1313
|
-
route = function(fromModel) {
|
|
1314
|
-
const graph = deriveBFS(fromModel);
|
|
1315
|
-
const conversion = {};
|
|
1316
|
-
const models = Object.keys(graph);
|
|
1317
|
-
for (let len = models.length, i = 0; i < len; i++) {
|
|
1318
|
-
const toModel = models[i];
|
|
1319
|
-
const node = graph[toModel];
|
|
1320
|
-
if (node.parent === null) {
|
|
1321
|
-
continue;
|
|
1322
|
-
}
|
|
1323
|
-
conversion[toModel] = wrapConversion(toModel, graph);
|
|
1324
|
-
}
|
|
1325
|
-
return conversion;
|
|
1326
|
-
};
|
|
1327
|
-
return route;
|
|
1328
|
-
}
|
|
1329
|
-
var colorConvert;
|
|
1330
|
-
var hasRequiredColorConvert;
|
|
1331
|
-
function requireColorConvert() {
|
|
1332
|
-
if (hasRequiredColorConvert) return colorConvert;
|
|
1333
|
-
hasRequiredColorConvert = 1;
|
|
1334
|
-
const conversions2 = requireConversions();
|
|
1335
|
-
const route2 = requireRoute();
|
|
1336
|
-
const convert = {};
|
|
1337
|
-
const models = Object.keys(conversions2);
|
|
1338
|
-
function wrapRaw(fn) {
|
|
1339
|
-
const wrappedFn = function(...args) {
|
|
1340
|
-
const arg0 = args[0];
|
|
1341
|
-
if (arg0 === void 0 || arg0 === null) {
|
|
1342
|
-
return arg0;
|
|
1343
|
-
}
|
|
1344
|
-
if (arg0.length > 1) {
|
|
1345
|
-
args = arg0;
|
|
1346
|
-
}
|
|
1347
|
-
return fn(args);
|
|
1348
|
-
};
|
|
1349
|
-
if ("conversion" in fn) {
|
|
1350
|
-
wrappedFn.conversion = fn.conversion;
|
|
1351
|
-
}
|
|
1352
|
-
return wrappedFn;
|
|
1353
|
-
}
|
|
1354
|
-
function wrapRounded(fn) {
|
|
1355
|
-
const wrappedFn = function(...args) {
|
|
1356
|
-
const arg0 = args[0];
|
|
1357
|
-
if (arg0 === void 0 || arg0 === null) {
|
|
1358
|
-
return arg0;
|
|
1359
|
-
}
|
|
1360
|
-
if (arg0.length > 1) {
|
|
1361
|
-
args = arg0;
|
|
1362
|
-
}
|
|
1363
|
-
const result = fn(args);
|
|
1364
|
-
if (typeof result === "object") {
|
|
1365
|
-
for (let len = result.length, i = 0; i < len; i++) {
|
|
1366
|
-
result[i] = Math.round(result[i]);
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
return result;
|
|
1370
|
-
};
|
|
1371
|
-
if ("conversion" in fn) {
|
|
1372
|
-
wrappedFn.conversion = fn.conversion;
|
|
1373
|
-
}
|
|
1374
|
-
return wrappedFn;
|
|
1375
|
-
}
|
|
1376
|
-
models.forEach((fromModel) => {
|
|
1377
|
-
convert[fromModel] = {};
|
|
1378
|
-
Object.defineProperty(convert[fromModel], "channels", { value: conversions2[fromModel].channels });
|
|
1379
|
-
Object.defineProperty(convert[fromModel], "labels", { value: conversions2[fromModel].labels });
|
|
1380
|
-
const routes = route2(fromModel);
|
|
1381
|
-
const routeModels = Object.keys(routes);
|
|
1382
|
-
routeModels.forEach((toModel) => {
|
|
1383
|
-
const fn = routes[toModel];
|
|
1384
|
-
convert[fromModel][toModel] = wrapRounded(fn);
|
|
1385
|
-
convert[fromModel][toModel].raw = wrapRaw(fn);
|
|
1386
|
-
});
|
|
1387
|
-
});
|
|
1388
|
-
colorConvert = convert;
|
|
1389
|
-
return colorConvert;
|
|
1390
|
-
}
|
|
1391
|
-
ansiStyles.exports;
|
|
1392
|
-
var hasRequiredAnsiStyles;
|
|
1393
|
-
function requireAnsiStyles() {
|
|
1394
|
-
if (hasRequiredAnsiStyles) return ansiStyles.exports;
|
|
1395
|
-
hasRequiredAnsiStyles = 1;
|
|
1396
|
-
(function(module) {
|
|
1397
|
-
const wrapAnsi16 = (fn, offset) => (...args) => {
|
|
1398
|
-
const code = fn(...args);
|
|
1399
|
-
return `\x1B[${code + offset}m`;
|
|
1400
|
-
};
|
|
1401
|
-
const wrapAnsi256 = (fn, offset) => (...args) => {
|
|
1402
|
-
const code = fn(...args);
|
|
1403
|
-
return `\x1B[${38 + offset};5;${code}m`;
|
|
1404
|
-
};
|
|
1405
|
-
const wrapAnsi16m = (fn, offset) => (...args) => {
|
|
1406
|
-
const rgb = fn(...args);
|
|
1407
|
-
return `\x1B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
|
1408
|
-
};
|
|
1409
|
-
const ansi2ansi = (n) => n;
|
|
1410
|
-
const rgb2rgb = (r, g, b) => [r, g, b];
|
|
1411
|
-
const setLazyProperty = (object, property, get) => {
|
|
1412
|
-
Object.defineProperty(object, property, {
|
|
1413
|
-
get: () => {
|
|
1414
|
-
const value = get();
|
|
1415
|
-
Object.defineProperty(object, property, {
|
|
1416
|
-
value,
|
|
1417
|
-
enumerable: true,
|
|
1418
|
-
configurable: true
|
|
1419
|
-
});
|
|
1420
|
-
return value;
|
|
1421
|
-
},
|
|
1422
|
-
enumerable: true,
|
|
1423
|
-
configurable: true
|
|
1424
|
-
});
|
|
1425
|
-
};
|
|
1426
|
-
let colorConvert2;
|
|
1427
|
-
const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
|
1428
|
-
if (colorConvert2 === void 0) {
|
|
1429
|
-
colorConvert2 = requireColorConvert();
|
|
1430
|
-
}
|
|
1431
|
-
const offset = isBackground ? 10 : 0;
|
|
1432
|
-
const styles = {};
|
|
1433
|
-
for (const [sourceSpace, suite] of Object.entries(colorConvert2)) {
|
|
1434
|
-
const name = sourceSpace === "ansi16" ? "ansi" : sourceSpace;
|
|
1435
|
-
if (sourceSpace === targetSpace) {
|
|
1436
|
-
styles[name] = wrap(identity, offset);
|
|
1437
|
-
} else if (typeof suite === "object") {
|
|
1438
|
-
styles[name] = wrap(suite[targetSpace], offset);
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
return styles;
|
|
1442
|
-
};
|
|
1443
|
-
function assembleStyles() {
|
|
1444
|
-
const codes = /* @__PURE__ */ new Map();
|
|
1445
|
-
const styles = {
|
|
1446
|
-
modifier: {
|
|
1447
|
-
reset: [0, 0],
|
|
1448
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
1449
|
-
bold: [1, 22],
|
|
1450
|
-
dim: [2, 22],
|
|
1451
|
-
italic: [3, 23],
|
|
1452
|
-
underline: [4, 24],
|
|
1453
|
-
inverse: [7, 27],
|
|
1454
|
-
hidden: [8, 28],
|
|
1455
|
-
strikethrough: [9, 29]
|
|
1456
|
-
},
|
|
1457
|
-
color: {
|
|
1458
|
-
black: [30, 39],
|
|
1459
|
-
red: [31, 39],
|
|
1460
|
-
green: [32, 39],
|
|
1461
|
-
yellow: [33, 39],
|
|
1462
|
-
blue: [34, 39],
|
|
1463
|
-
magenta: [35, 39],
|
|
1464
|
-
cyan: [36, 39],
|
|
1465
|
-
white: [37, 39],
|
|
1466
|
-
// Bright color
|
|
1467
|
-
blackBright: [90, 39],
|
|
1468
|
-
redBright: [91, 39],
|
|
1469
|
-
greenBright: [92, 39],
|
|
1470
|
-
yellowBright: [93, 39],
|
|
1471
|
-
blueBright: [94, 39],
|
|
1472
|
-
magentaBright: [95, 39],
|
|
1473
|
-
cyanBright: [96, 39],
|
|
1474
|
-
whiteBright: [97, 39]
|
|
1475
|
-
},
|
|
1476
|
-
bgColor: {
|
|
1477
|
-
bgBlack: [40, 49],
|
|
1478
|
-
bgRed: [41, 49],
|
|
1479
|
-
bgGreen: [42, 49],
|
|
1480
|
-
bgYellow: [43, 49],
|
|
1481
|
-
bgBlue: [44, 49],
|
|
1482
|
-
bgMagenta: [45, 49],
|
|
1483
|
-
bgCyan: [46, 49],
|
|
1484
|
-
bgWhite: [47, 49],
|
|
1485
|
-
// Bright color
|
|
1486
|
-
bgBlackBright: [100, 49],
|
|
1487
|
-
bgRedBright: [101, 49],
|
|
1488
|
-
bgGreenBright: [102, 49],
|
|
1489
|
-
bgYellowBright: [103, 49],
|
|
1490
|
-
bgBlueBright: [104, 49],
|
|
1491
|
-
bgMagentaBright: [105, 49],
|
|
1492
|
-
bgCyanBright: [106, 49],
|
|
1493
|
-
bgWhiteBright: [107, 49]
|
|
1494
|
-
}
|
|
1495
|
-
};
|
|
1496
|
-
styles.color.gray = styles.color.blackBright;
|
|
1497
|
-
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
1498
|
-
styles.color.grey = styles.color.blackBright;
|
|
1499
|
-
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
1500
|
-
for (const [groupName, group] of Object.entries(styles)) {
|
|
1501
|
-
for (const [styleName, style] of Object.entries(group)) {
|
|
1502
|
-
styles[styleName] = {
|
|
1503
|
-
open: `\x1B[${style[0]}m`,
|
|
1504
|
-
close: `\x1B[${style[1]}m`
|
|
1505
|
-
};
|
|
1506
|
-
group[styleName] = styles[styleName];
|
|
1507
|
-
codes.set(style[0], style[1]);
|
|
1508
|
-
}
|
|
1509
|
-
Object.defineProperty(styles, groupName, {
|
|
1510
|
-
value: group,
|
|
1511
|
-
enumerable: false
|
|
1512
|
-
});
|
|
1513
|
-
}
|
|
1514
|
-
Object.defineProperty(styles, "codes", {
|
|
1515
|
-
value: codes,
|
|
1516
|
-
enumerable: false
|
|
1517
|
-
});
|
|
1518
|
-
styles.color.close = "\x1B[39m";
|
|
1519
|
-
styles.bgColor.close = "\x1B[49m";
|
|
1520
|
-
setLazyProperty(styles.color, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, false));
|
|
1521
|
-
setLazyProperty(styles.color, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, false));
|
|
1522
|
-
setLazyProperty(styles.color, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, false));
|
|
1523
|
-
setLazyProperty(styles.bgColor, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, true));
|
|
1524
|
-
setLazyProperty(styles.bgColor, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, true));
|
|
1525
|
-
setLazyProperty(styles.bgColor, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, true));
|
|
1526
|
-
return styles;
|
|
1527
|
-
}
|
|
1528
|
-
Object.defineProperty(module, "exports", {
|
|
1529
|
-
enumerable: true,
|
|
1530
|
-
get: assembleStyles
|
|
1531
|
-
});
|
|
1532
|
-
})(ansiStyles);
|
|
1533
|
-
return ansiStyles.exports;
|
|
1534
|
-
}
|
|
1535
|
-
var browser;
|
|
1536
|
-
var hasRequiredBrowser;
|
|
1537
|
-
function requireBrowser() {
|
|
1538
|
-
if (hasRequiredBrowser) return browser;
|
|
1539
|
-
hasRequiredBrowser = 1;
|
|
1540
|
-
browser = {
|
|
1541
|
-
stdout: false,
|
|
1542
|
-
stderr: false
|
|
1543
|
-
};
|
|
1544
|
-
return browser;
|
|
1545
|
-
}
|
|
1546
|
-
var util;
|
|
1547
|
-
var hasRequiredUtil;
|
|
1548
|
-
function requireUtil() {
|
|
1549
|
-
if (hasRequiredUtil) return util;
|
|
1550
|
-
hasRequiredUtil = 1;
|
|
1551
|
-
const stringReplaceAll = (string, substring, replacer) => {
|
|
1552
|
-
let index = string.indexOf(substring);
|
|
1553
|
-
if (index === -1) {
|
|
1554
|
-
return string;
|
|
1555
|
-
}
|
|
1556
|
-
const substringLength = substring.length;
|
|
1557
|
-
let endIndex = 0;
|
|
1558
|
-
let returnValue = "";
|
|
1559
|
-
do {
|
|
1560
|
-
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
1561
|
-
endIndex = index + substringLength;
|
|
1562
|
-
index = string.indexOf(substring, endIndex);
|
|
1563
|
-
} while (index !== -1);
|
|
1564
|
-
returnValue += string.substr(endIndex);
|
|
1565
|
-
return returnValue;
|
|
1566
|
-
};
|
|
1567
|
-
const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
1568
|
-
let endIndex = 0;
|
|
1569
|
-
let returnValue = "";
|
|
1570
|
-
do {
|
|
1571
|
-
const gotCR = string[index - 1] === "\r";
|
|
1572
|
-
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
1573
|
-
endIndex = index + 1;
|
|
1574
|
-
index = string.indexOf("\n", endIndex);
|
|
1575
|
-
} while (index !== -1);
|
|
1576
|
-
returnValue += string.substr(endIndex);
|
|
1577
|
-
return returnValue;
|
|
1578
|
-
};
|
|
1579
|
-
util = {
|
|
1580
|
-
stringReplaceAll,
|
|
1581
|
-
stringEncaseCRLFWithFirstIndex
|
|
1582
|
-
};
|
|
1583
|
-
return util;
|
|
1584
|
-
}
|
|
1585
|
-
var templates;
|
|
1586
|
-
var hasRequiredTemplates;
|
|
1587
|
-
function requireTemplates() {
|
|
1588
|
-
if (hasRequiredTemplates) return templates;
|
|
1589
|
-
hasRequiredTemplates = 1;
|
|
1590
|
-
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
1591
|
-
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
1592
|
-
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
1593
|
-
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
1594
|
-
const ESCAPES = /* @__PURE__ */ new Map([
|
|
1595
|
-
["n", "\n"],
|
|
1596
|
-
["r", "\r"],
|
|
1597
|
-
["t", " "],
|
|
1598
|
-
["b", "\b"],
|
|
1599
|
-
["f", "\f"],
|
|
1600
|
-
["v", "\v"],
|
|
1601
|
-
["0", "\0"],
|
|
1602
|
-
["\\", "\\"],
|
|
1603
|
-
["e", "\x1B"],
|
|
1604
|
-
["a", "\x07"]
|
|
1605
|
-
]);
|
|
1606
|
-
function unescape(c) {
|
|
1607
|
-
const u = c[0] === "u";
|
|
1608
|
-
const bracket = c[1] === "{";
|
|
1609
|
-
if (u && !bracket && c.length === 5 || c[0] === "x" && c.length === 3) {
|
|
1610
|
-
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
1611
|
-
}
|
|
1612
|
-
if (u && bracket) {
|
|
1613
|
-
return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
|
1614
|
-
}
|
|
1615
|
-
return ESCAPES.get(c) || c;
|
|
1616
|
-
}
|
|
1617
|
-
function parseArguments(name, arguments_) {
|
|
1618
|
-
const results = [];
|
|
1619
|
-
const chunks = arguments_.trim().split(/\s*,\s*/g);
|
|
1620
|
-
let matches;
|
|
1621
|
-
for (const chunk of chunks) {
|
|
1622
|
-
const number = Number(chunk);
|
|
1623
|
-
if (!Number.isNaN(number)) {
|
|
1624
|
-
results.push(number);
|
|
1625
|
-
} else if (matches = chunk.match(STRING_REGEX)) {
|
|
1626
|
-
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape2, character) => escape2 ? unescape(escape2) : character));
|
|
1627
|
-
} else {
|
|
1628
|
-
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
return results;
|
|
1632
|
-
}
|
|
1633
|
-
function parseStyle(style) {
|
|
1634
|
-
STYLE_REGEX.lastIndex = 0;
|
|
1635
|
-
const results = [];
|
|
1636
|
-
let matches;
|
|
1637
|
-
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
|
1638
|
-
const name = matches[1];
|
|
1639
|
-
if (matches[2]) {
|
|
1640
|
-
const args = parseArguments(name, matches[2]);
|
|
1641
|
-
results.push([name].concat(args));
|
|
1642
|
-
} else {
|
|
1643
|
-
results.push([name]);
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
return results;
|
|
1647
|
-
}
|
|
1648
|
-
function buildStyle(chalk2, styles) {
|
|
1649
|
-
const enabled = {};
|
|
1650
|
-
for (const layer of styles) {
|
|
1651
|
-
for (const style of layer.styles) {
|
|
1652
|
-
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
let current = chalk2;
|
|
1656
|
-
for (const [styleName, styles2] of Object.entries(enabled)) {
|
|
1657
|
-
if (!Array.isArray(styles2)) {
|
|
1658
|
-
continue;
|
|
1659
|
-
}
|
|
1660
|
-
if (!(styleName in current)) {
|
|
1661
|
-
throw new Error(`Unknown Chalk style: ${styleName}`);
|
|
1662
|
-
}
|
|
1663
|
-
current = styles2.length > 0 ? current[styleName](...styles2) : current[styleName];
|
|
1664
|
-
}
|
|
1665
|
-
return current;
|
|
1666
|
-
}
|
|
1667
|
-
templates = (chalk2, temporary) => {
|
|
1668
|
-
const styles = [];
|
|
1669
|
-
const chunks = [];
|
|
1670
|
-
let chunk = [];
|
|
1671
|
-
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
|
1672
|
-
if (escapeCharacter) {
|
|
1673
|
-
chunk.push(unescape(escapeCharacter));
|
|
1674
|
-
} else if (style) {
|
|
1675
|
-
const string = chunk.join("");
|
|
1676
|
-
chunk = [];
|
|
1677
|
-
chunks.push(styles.length === 0 ? string : buildStyle(chalk2, styles)(string));
|
|
1678
|
-
styles.push({ inverse, styles: parseStyle(style) });
|
|
1679
|
-
} else if (close) {
|
|
1680
|
-
if (styles.length === 0) {
|
|
1681
|
-
throw new Error("Found extraneous } in Chalk template literal");
|
|
1682
|
-
}
|
|
1683
|
-
chunks.push(buildStyle(chalk2, styles)(chunk.join("")));
|
|
1684
|
-
chunk = [];
|
|
1685
|
-
styles.pop();
|
|
1686
|
-
} else {
|
|
1687
|
-
chunk.push(character);
|
|
1688
|
-
}
|
|
1689
|
-
});
|
|
1690
|
-
chunks.push(chunk.join(""));
|
|
1691
|
-
if (styles.length > 0) {
|
|
1692
|
-
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`;
|
|
1693
|
-
throw new Error(errMessage);
|
|
1694
|
-
}
|
|
1695
|
-
return chunks.join("");
|
|
1696
|
-
};
|
|
1697
|
-
return templates;
|
|
1698
|
-
}
|
|
1699
|
-
var source;
|
|
1700
|
-
var hasRequiredSource;
|
|
1701
|
-
function requireSource() {
|
|
1702
|
-
if (hasRequiredSource) return source;
|
|
1703
|
-
hasRequiredSource = 1;
|
|
1704
|
-
const ansiStyles2 = requireAnsiStyles();
|
|
1705
|
-
const { stdout: stdoutColor, stderr: stderrColor } = requireBrowser();
|
|
1706
|
-
const {
|
|
1707
|
-
stringReplaceAll,
|
|
1708
|
-
stringEncaseCRLFWithFirstIndex
|
|
1709
|
-
} = requireUtil();
|
|
1710
|
-
const { isArray } = Array;
|
|
1711
|
-
const levelMapping = [
|
|
1712
|
-
"ansi",
|
|
1713
|
-
"ansi",
|
|
1714
|
-
"ansi256",
|
|
1715
|
-
"ansi16m"
|
|
1716
|
-
];
|
|
1717
|
-
const styles = /* @__PURE__ */ Object.create(null);
|
|
1718
|
-
const applyOptions = (object, options = {}) => {
|
|
1719
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1720
|
-
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
1721
|
-
}
|
|
1722
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1723
|
-
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
1724
|
-
};
|
|
1725
|
-
class ChalkClass {
|
|
1726
|
-
constructor(options) {
|
|
1727
|
-
return chalkFactory(options);
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
const chalkFactory = (options) => {
|
|
1731
|
-
const chalk3 = {};
|
|
1732
|
-
applyOptions(chalk3, options);
|
|
1733
|
-
chalk3.template = (...arguments_) => chalkTag(chalk3.template, ...arguments_);
|
|
1734
|
-
Object.setPrototypeOf(chalk3, Chalk.prototype);
|
|
1735
|
-
Object.setPrototypeOf(chalk3.template, chalk3);
|
|
1736
|
-
chalk3.template.constructor = () => {
|
|
1737
|
-
throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
|
|
1738
|
-
};
|
|
1739
|
-
chalk3.template.Instance = ChalkClass;
|
|
1740
|
-
return chalk3.template;
|
|
1741
|
-
};
|
|
1742
|
-
function Chalk(options) {
|
|
1743
|
-
return chalkFactory(options);
|
|
1744
|
-
}
|
|
1745
|
-
for (const [styleName, style] of Object.entries(ansiStyles2)) {
|
|
1746
|
-
styles[styleName] = {
|
|
1747
|
-
get() {
|
|
1748
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
|
1749
|
-
Object.defineProperty(this, styleName, { value: builder });
|
|
1750
|
-
return builder;
|
|
1751
|
-
}
|
|
1752
|
-
};
|
|
1753
|
-
}
|
|
1754
|
-
styles.visible = {
|
|
1755
|
-
get() {
|
|
1756
|
-
const builder = createBuilder(this, this._styler, true);
|
|
1757
|
-
Object.defineProperty(this, "visible", { value: builder });
|
|
1758
|
-
return builder;
|
|
1759
|
-
}
|
|
1760
|
-
};
|
|
1761
|
-
const usedModels = ["rgb", "hex", "keyword", "hsl", "hsv", "hwb", "ansi", "ansi256"];
|
|
1762
|
-
for (const model of usedModels) {
|
|
1763
|
-
styles[model] = {
|
|
1764
|
-
get() {
|
|
1765
|
-
const { level } = this;
|
|
1766
|
-
return function(...arguments_) {
|
|
1767
|
-
const styler = createStyler(ansiStyles2.color[levelMapping[level]][model](...arguments_), ansiStyles2.color.close, this._styler);
|
|
1768
|
-
return createBuilder(this, styler, this._isEmpty);
|
|
1769
|
-
};
|
|
1770
|
-
}
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
for (const model of usedModels) {
|
|
1774
|
-
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
1775
|
-
styles[bgModel] = {
|
|
1776
|
-
get() {
|
|
1777
|
-
const { level } = this;
|
|
1778
|
-
return function(...arguments_) {
|
|
1779
|
-
const styler = createStyler(ansiStyles2.bgColor[levelMapping[level]][model](...arguments_), ansiStyles2.bgColor.close, this._styler);
|
|
1780
|
-
return createBuilder(this, styler, this._isEmpty);
|
|
1781
|
-
};
|
|
1782
|
-
}
|
|
1783
|
-
};
|
|
1784
|
-
}
|
|
1785
|
-
const proto = Object.defineProperties(() => {
|
|
1786
|
-
}, {
|
|
1787
|
-
...styles,
|
|
1788
|
-
level: {
|
|
1789
|
-
enumerable: true,
|
|
1790
|
-
get() {
|
|
1791
|
-
return this._generator.level;
|
|
1792
|
-
},
|
|
1793
|
-
set(level) {
|
|
1794
|
-
this._generator.level = level;
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
});
|
|
1798
|
-
const createStyler = (open, close, parent) => {
|
|
1799
|
-
let openAll;
|
|
1800
|
-
let closeAll;
|
|
1801
|
-
if (parent === void 0) {
|
|
1802
|
-
openAll = open;
|
|
1803
|
-
closeAll = close;
|
|
1804
|
-
} else {
|
|
1805
|
-
openAll = parent.openAll + open;
|
|
1806
|
-
closeAll = close + parent.closeAll;
|
|
1807
|
-
}
|
|
1808
|
-
return {
|
|
1809
|
-
open,
|
|
1810
|
-
close,
|
|
1811
|
-
openAll,
|
|
1812
|
-
closeAll,
|
|
1813
|
-
parent
|
|
1814
|
-
};
|
|
1815
|
-
};
|
|
1816
|
-
const createBuilder = (self, _styler, _isEmpty) => {
|
|
1817
|
-
const builder = (...arguments_) => {
|
|
1818
|
-
if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
|
|
1819
|
-
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
|
1820
|
-
}
|
|
1821
|
-
return applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
1822
|
-
};
|
|
1823
|
-
Object.setPrototypeOf(builder, proto);
|
|
1824
|
-
builder._generator = self;
|
|
1825
|
-
builder._styler = _styler;
|
|
1826
|
-
builder._isEmpty = _isEmpty;
|
|
1827
|
-
return builder;
|
|
1828
|
-
};
|
|
1829
|
-
const applyStyle = (self, string) => {
|
|
1830
|
-
if (self.level <= 0 || !string) {
|
|
1831
|
-
return self._isEmpty ? "" : string;
|
|
1832
|
-
}
|
|
1833
|
-
let styler = self._styler;
|
|
1834
|
-
if (styler === void 0) {
|
|
1835
|
-
return string;
|
|
1836
|
-
}
|
|
1837
|
-
const { openAll, closeAll } = styler;
|
|
1838
|
-
if (string.indexOf("\x1B") !== -1) {
|
|
1839
|
-
while (styler !== void 0) {
|
|
1840
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
1841
|
-
styler = styler.parent;
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
const lfIndex = string.indexOf("\n");
|
|
1845
|
-
if (lfIndex !== -1) {
|
|
1846
|
-
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
1847
|
-
}
|
|
1848
|
-
return openAll + string + closeAll;
|
|
1849
|
-
};
|
|
1850
|
-
let template;
|
|
1851
|
-
const chalkTag = (chalk3, ...strings) => {
|
|
1852
|
-
const [firstString] = strings;
|
|
1853
|
-
if (!isArray(firstString) || !isArray(firstString.raw)) {
|
|
1854
|
-
return strings.join(" ");
|
|
1855
|
-
}
|
|
1856
|
-
const arguments_ = strings.slice(1);
|
|
1857
|
-
const parts = [firstString.raw[0]];
|
|
1858
|
-
for (let i = 1; i < firstString.length; i++) {
|
|
1859
|
-
parts.push(
|
|
1860
|
-
String(arguments_[i - 1]).replace(/[{}\\]/g, "\\$&"),
|
|
1861
|
-
String(firstString.raw[i])
|
|
1862
|
-
);
|
|
1863
|
-
}
|
|
1864
|
-
if (template === void 0) {
|
|
1865
|
-
template = requireTemplates();
|
|
1866
|
-
}
|
|
1867
|
-
return template(chalk3, parts.join(""));
|
|
1868
|
-
};
|
|
1869
|
-
Object.defineProperties(Chalk.prototype, styles);
|
|
1870
|
-
const chalk2 = Chalk();
|
|
1871
|
-
chalk2.supportsColor = stdoutColor;
|
|
1872
|
-
chalk2.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
1873
|
-
chalk2.stderr.supportsColor = stderrColor;
|
|
1874
|
-
source = chalk2;
|
|
1875
|
-
return source;
|
|
1876
|
-
}
|
|
1877
|
-
var sourceExports = requireSource();
|
|
1878
|
-
const chalk = /* @__PURE__ */ getDefaultExportFromCjs(sourceExports);
|
|
1879
|
-
chalk.level = 3;
|
|
1880
|
-
class STSWorkerManager {
|
|
1881
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1882
|
-
constructor(app, options) {
|
|
1883
|
-
__privateAdd(this, _STSWorkerManager_instances);
|
|
1884
|
-
//#agentSession: string = null;
|
|
1885
|
-
__privateAdd(this, _workersEx, {});
|
|
1886
|
-
__privateAdd(this, _runner, 0);
|
|
1887
|
-
__privateAdd(this, _workerId, 0);
|
|
1888
|
-
__privateAdd(this, _options);
|
|
1889
|
-
__privateAdd(this, _STSInstrumentController);
|
|
1890
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1891
|
-
__privateAdd(this, _app);
|
|
1892
|
-
__publicField(this, "AddWorker", async (useWorkerFactory) => {
|
|
1893
|
-
var _a;
|
|
1894
|
-
let workerFactory;
|
|
1895
|
-
if (useWorkerFactory) {
|
|
1896
|
-
workerFactory = useWorkerFactory;
|
|
1897
|
-
} else {
|
|
1898
|
-
workerFactory = __privateGet(this, _options).workerFactory;
|
|
1899
|
-
}
|
|
1900
|
-
const stsWorkerEx = {
|
|
1901
|
-
id: __privateWrapper(this, _workerId)._++,
|
|
1902
|
-
// uuidv4()
|
|
1903
|
-
worker: workerFactory.createWorkerThreadWorker(),
|
|
1904
|
-
primaryWorker: workerFactory.createPrimaryThreadWorker(__privateGet(this, _app), workerFactory.primaryThreadWorkerOptions),
|
|
1905
|
-
state: IWorkerState.starting,
|
|
1906
|
-
workerThreadWorkerOptions: workerFactory.workerThreadWorkerOptions,
|
|
1907
|
-
primaryThreadWorkerOptions: workerFactory.primaryThreadWorkerOptions,
|
|
1908
|
-
runnersEx: {},
|
|
1909
|
-
AddRunner: (runnerOptions) => this.AddRunnerToWorker(stsWorkerEx, runnerOptions),
|
|
1910
|
-
StopRunner: (runner) => __privateGet(this, _StopRunner).call(this, stsWorkerEx, runner),
|
|
1911
|
-
Stop: async () => __privateGet(this, _StopWorker).call(this, stsWorkerEx)
|
|
1912
|
-
};
|
|
1913
|
-
(_a = __privateGet(this, _STSInstrumentController)) == null ? void 0 : _a.LogEx(chalk.yellow(`Creating new worker: [${stsWorkerEx.id}]`));
|
|
1914
|
-
console.log(`Adding worker: [${stsWorkerEx.id}]`);
|
|
1915
|
-
stsWorkerEx.worker.onmessage = function(data) {
|
|
1916
|
-
console.log(data.data);
|
|
1917
|
-
};
|
|
1918
|
-
stsWorkerEx.worker.onerror = function(error) {
|
|
1919
|
-
console.log(error);
|
|
1920
|
-
};
|
|
1921
|
-
const {
|
|
1922
|
-
port1,
|
|
1923
|
-
// process message port
|
|
1924
|
-
port2
|
|
1925
|
-
// collector message port
|
|
1926
|
-
} = new MessageChannel();
|
|
1927
|
-
const workerPort = port1;
|
|
1928
|
-
console.log(`STSWorkerManager::AddWorker::workerThreadWorkerOptions: [${JSON.stringify(stsWorkerEx.workerThreadWorkerOptions)}]`);
|
|
1929
|
-
__privateGet(this, _PostMessageToWorker).call(this, stsWorkerEx, eIWMessageCommands.MessagePort, {
|
|
1930
|
-
port: port2,
|
|
1931
|
-
//applicationStoreState: stateCopy,
|
|
1932
|
-
options: { ...stsWorkerEx.workerThreadWorkerOptions }
|
|
1933
|
-
}, port2);
|
|
1934
|
-
workerPort.onmessage = async (data) => {
|
|
1935
|
-
const publishMessagePayload = data.data;
|
|
1936
|
-
switch (publishMessagePayload.command) {
|
|
1937
|
-
case eIWMessageCommands.MessagePortResponse:
|
|
1938
|
-
stsWorkerEx.state = IWorkerState.started;
|
|
1939
|
-
break;
|
|
1940
|
-
case eIWMessageCommands.InstrumentTelemetry:
|
|
1941
|
-
__privateGet(this, _ProcessTelemetry).call(this, stsWorkerEx, publishMessagePayload.payload);
|
|
1942
|
-
break;
|
|
1943
|
-
default:
|
|
1944
|
-
stsWorkerEx.primaryWorker.ProcessMessageFromWorker(workerPort, publishMessagePayload);
|
|
1945
|
-
}
|
|
1946
|
-
};
|
|
1947
|
-
__privateGet(this, _workersEx)[stsWorkerEx.id] = stsWorkerEx;
|
|
1948
|
-
console.log(`Added worker: [${stsWorkerEx.id}]`);
|
|
1949
|
-
return stsWorkerEx;
|
|
1950
|
-
});
|
|
1951
|
-
__publicField(this, "AddRunnerToWorker", (stsWorkerEx, runnerOptions) => {
|
|
1952
|
-
const runnerEx = __privateGet(this, _CreateAsyncRunner).call(this, stsWorkerEx, runnerOptions);
|
|
1953
|
-
stsWorkerEx.runnersEx[runnerEx.id] = runnerEx;
|
|
1954
|
-
__privateGet(this, _SetRunnerIntoWorker).call(this, stsWorkerEx, runnerEx);
|
|
1955
|
-
runnerEx.publishInstrumentController.LogEx(chalk.green(`Added runner: [${runnerEx.id}] into worker: [${stsWorkerEx.id}]`));
|
|
1956
|
-
return runnerEx;
|
|
1957
|
-
});
|
|
1958
|
-
__privateAdd(this, _SetRunnerIntoWorker, (workerEx, runnerEx) => {
|
|
1959
|
-
const payload = {
|
|
1960
|
-
runner: __privateMethod(this, _STSWorkerManager_instances, CreateRunnerCopy_fn).call(this, runnerEx)
|
|
1961
|
-
};
|
|
1962
|
-
__privateGet(this, _PostMessageToWorker).call(this, workerEx, eIWMessageCommands.AddAsyncRunner, payload);
|
|
1963
|
-
});
|
|
1964
|
-
__privateAdd(this, _ProcessTelemetry, (workerEx, payloadContents) => {
|
|
1965
|
-
const store = TelemetryStore();
|
|
1966
|
-
const { runner } = payloadContents;
|
|
1967
|
-
if (workerEx.runnersEx[runner.id]) {
|
|
1968
|
-
const runnerEx = workerEx.runnersEx[runner.id];
|
|
1969
|
-
let update = false;
|
|
1970
|
-
runnerEx.instrumentData = { ...runner.instrumentData };
|
|
1971
|
-
if (runner.instrumentData.message) {
|
|
1972
|
-
runnerEx.instrumentData.message = [...runner.instrumentData.message];
|
|
1973
|
-
} else {
|
|
1974
|
-
runnerEx.instrumentData.message = [];
|
|
1975
|
-
}
|
|
1976
|
-
if (runner.instrumentData.message) {
|
|
1977
|
-
runner.instrumentData.message.forEach((message) => {
|
|
1978
|
-
runnerEx.publishInstrumentController.LogEx(message);
|
|
1979
|
-
});
|
|
1980
|
-
update = true;
|
|
1981
|
-
}
|
|
1982
|
-
if (runner.instrumentData.requestCount) {
|
|
1983
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.REQUEST_COUNT_GAUGE, {
|
|
1984
|
-
val: runnerEx.instrumentData.requestCount
|
|
1985
|
-
});
|
|
1986
|
-
update = true;
|
|
1987
|
-
}
|
|
1988
|
-
if (runner.instrumentData.errorCount) {
|
|
1989
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.ERROR_COUNT_GAUGE, {
|
|
1990
|
-
val: runnerEx.instrumentData.errorCount
|
|
1991
|
-
});
|
|
1992
|
-
update = true;
|
|
1993
|
-
}
|
|
1994
|
-
if (runner.instrumentData.retryCount) {
|
|
1995
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.RETRY_COUNT_GAUGE, {
|
|
1996
|
-
val: runnerEx.instrumentData.retryCount
|
|
1997
|
-
});
|
|
1998
|
-
update = true;
|
|
1999
|
-
}
|
|
2000
|
-
if (runner.instrumentData.authenticationCount) {
|
|
2001
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.AUTHENTICATION_COUNT_GAUGE, {
|
|
2002
|
-
val: runnerEx.instrumentData.authenticationCount
|
|
2003
|
-
});
|
|
2004
|
-
update = true;
|
|
2005
|
-
}
|
|
2006
|
-
if (runner.instrumentData.authenticationErrorCount) {
|
|
2007
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, {
|
|
2008
|
-
val: runnerEx.instrumentData.authenticationErrorCount
|
|
2009
|
-
});
|
|
2010
|
-
update = true;
|
|
2011
|
-
}
|
|
2012
|
-
if (runner.instrumentData.authenticationRetryCount) {
|
|
2013
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, {
|
|
2014
|
-
val: runnerEx.instrumentData.authenticationRetryCount
|
|
2015
|
-
});
|
|
2016
|
-
update = true;
|
|
2017
|
-
}
|
|
2018
|
-
if (runner.instrumentData.coreCount) {
|
|
2019
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.CORE_COUNT_GAUGE, {
|
|
2020
|
-
val: runnerEx.instrumentData.coreCount
|
|
2021
|
-
});
|
|
2022
|
-
update = true;
|
|
2023
|
-
}
|
|
2024
|
-
if (runner.instrumentData.timer) {
|
|
2025
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.TIMER_GAUGE, {
|
|
2026
|
-
val: runnerEx.instrumentData.timer
|
|
2027
|
-
});
|
|
2028
|
-
update = true;
|
|
2029
|
-
}
|
|
2030
|
-
if (runner.instrumentData.activeRequestCount) {
|
|
2031
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.ACTIVE_REQUEST_GAUGE, {
|
|
2032
|
-
val: runnerEx.instrumentData.activeRequestCount
|
|
2033
|
-
});
|
|
2034
|
-
update = true;
|
|
2035
|
-
}
|
|
2036
|
-
if (runner.instrumentData.velocity) {
|
|
2037
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.VELOCITY_GAUGE, {
|
|
2038
|
-
Inc: runnerEx.instrumentData.velocity
|
|
2039
|
-
});
|
|
2040
|
-
update = true;
|
|
2041
|
-
}
|
|
2042
|
-
if (runner.instrumentData.duration) {
|
|
2043
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.DURATION_GAUGE, {
|
|
2044
|
-
val: runnerEx.instrumentData.duration
|
|
2045
|
-
});
|
|
2046
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.DURATION_HISTOGRAM_GAUGE, {
|
|
2047
|
-
val: runnerEx.instrumentData.duration
|
|
2048
|
-
});
|
|
2049
|
-
update = true;
|
|
2050
|
-
}
|
|
2051
|
-
if (runner.instrumentData.latency) {
|
|
2052
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.LATENCY_GAUGE, {
|
|
2053
|
-
val: runnerEx.instrumentData.latency
|
|
2054
|
-
});
|
|
2055
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.LATENCY_HISTOGRAM_GAUGE, {
|
|
2056
|
-
val: runnerEx.instrumentData.latency
|
|
2057
|
-
});
|
|
2058
|
-
update = true;
|
|
2059
|
-
}
|
|
2060
|
-
if (runner.instrumentData.childCount) {
|
|
2061
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.CHILD_COUNT, {
|
|
2062
|
-
val: runnerEx.instrumentData.childCount
|
|
2063
|
-
});
|
|
2064
|
-
update = true;
|
|
2065
|
-
}
|
|
2066
|
-
if (runner.instrumentData.rx) {
|
|
2067
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.NETWORK_RX_GAUGE, {
|
|
2068
|
-
Inc: runnerEx.instrumentData.rx
|
|
2069
|
-
});
|
|
2070
|
-
update = true;
|
|
2071
|
-
}
|
|
2072
|
-
if (runner.instrumentData.tx) {
|
|
2073
|
-
runnerEx.publishInstrumentController.UpdateInstrument(Gauge.NETWORK_TX_GAUGE, {
|
|
2074
|
-
Inc: runnerEx.instrumentData.tx
|
|
2075
|
-
});
|
|
2076
|
-
update = true;
|
|
2077
|
-
}
|
|
2078
|
-
if (update) {
|
|
2079
|
-
store.Update(workerEx, runnerEx);
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
});
|
|
2083
|
-
__privateAdd(this, _CreateAsyncRunner, (workerEx, runnerOptions) => {
|
|
2084
|
-
var _a;
|
|
2085
|
-
__privateWrapper(this, _runner)._++;
|
|
2086
|
-
(_a = __privateGet(this, _STSInstrumentController)) == null ? void 0 : _a.LogEx(chalk.yellow(`Creating new async runner: [${__privateGet(this, _runner)}]`));
|
|
2087
|
-
const asyncRunnerContext = {
|
|
2088
|
-
nid: `${workerEx.workerThreadWorkerOptions.hostName}${ModelDelimeter.COMPONENT_SEPERATOR}${workerEx.workerThreadWorkerOptions.agentId}-${workerEx.workerThreadWorkerOptions.userAgent}${ModelDelimeter.NID_SEPERATOR}worker${workerEx.id}${ModelDelimeter.SEPERATOR}${__privateGet(this, _runner)}`,
|
|
2089
|
-
id: __privateGet(this, _runner).toString(),
|
|
2090
|
-
hostName: workerEx.workerThreadWorkerOptions.hostName ? workerEx.workerThreadWorkerOptions.hostName : "host",
|
|
2091
|
-
agentName: `${workerEx.workerThreadWorkerOptions.agentId}-${workerEx.workerThreadWorkerOptions.userAgent}`,
|
|
2092
|
-
threadId: `worker${workerEx.id}`,
|
|
2093
|
-
asyncRunnerId: __privateGet(this, _runner)
|
|
2094
|
-
};
|
|
2095
|
-
const runnerEx = {
|
|
2096
|
-
id: __privateGet(this, _runner),
|
|
2097
|
-
publishInstrumentController: __privateGet(this, _STSInstrumentController).AddPublishInstrumentController(asyncRunnerContext),
|
|
2098
|
-
asyncRunnerContext,
|
|
2099
|
-
state: IRunnerState.created,
|
|
2100
|
-
options: runnerOptions,
|
|
2101
|
-
instrumentData: {
|
|
2102
|
-
requestCount: 0,
|
|
2103
|
-
errorCount: 0,
|
|
2104
|
-
retryCount: 0,
|
|
2105
|
-
authenticationCount: 0,
|
|
2106
|
-
authenticationErrorCount: 0,
|
|
2107
|
-
authenticationRetryCount: 0,
|
|
2108
|
-
velocity: 0,
|
|
2109
|
-
coreCount: 0,
|
|
2110
|
-
timer: 0,
|
|
2111
|
-
duration: 0,
|
|
2112
|
-
latency: 0,
|
|
2113
|
-
activeRequestCount: 0,
|
|
2114
|
-
message: [],
|
|
2115
|
-
childCount: 0,
|
|
2116
|
-
rx: 0,
|
|
2117
|
-
tx: 0
|
|
2118
|
-
},
|
|
2119
|
-
Stop: async () => __privateGet(this, _StopRunner).call(this, workerEx, runnerEx)
|
|
2120
|
-
};
|
|
2121
|
-
return runnerEx;
|
|
2122
|
-
});
|
|
2123
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2124
|
-
__privateAdd(this, _PostMessageToWorker, (workerEx, command, payload, transferObject) => {
|
|
2125
|
-
if (transferObject) {
|
|
2126
|
-
console.log(`#PostMessageToWorker with transfer object`);
|
|
2127
|
-
workerEx.worker.postMessage({ command, payload }, [transferObject]);
|
|
2128
|
-
console.log(`#PostMessageToWorker with transfer object - done...`);
|
|
2129
|
-
} else {
|
|
2130
|
-
console.log(`#PostMessageToWorker`);
|
|
2131
|
-
workerEx.worker.postMessage({ command, payload });
|
|
2132
|
-
}
|
|
2133
|
-
});
|
|
2134
|
-
__privateAdd(this, _TerminateWorker, (workerEx) => {
|
|
2135
|
-
if (workerEx.worker) {
|
|
2136
|
-
const store = TelemetryStore();
|
|
2137
|
-
workerEx.worker.terminate();
|
|
2138
|
-
console.log(`Terminated worker: [${workerEx.id}]`);
|
|
2139
|
-
store.RemoveWorker(workerEx);
|
|
2140
|
-
delete __privateGet(this, _workersEx)[workerEx.id];
|
|
2141
|
-
}
|
|
2142
|
-
});
|
|
2143
|
-
__privateAdd(this, _StopRunner, async (workerEx, runnerEx = null) => {
|
|
2144
|
-
if (runnerEx === null) {
|
|
2145
|
-
const ids = Object.keys(workerEx.runnersEx);
|
|
2146
|
-
if (ids.length > 0) {
|
|
2147
|
-
const id = ids[0];
|
|
2148
|
-
runnerEx = workerEx.runnersEx[id];
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
if (runnerEx !== null) {
|
|
2152
|
-
__privateGet(this, _PostMessageToWorker).call(this, workerEx, eIWMessageCommands.StopAllAsyncRunners, {
|
|
2153
|
-
runner: __privateMethod(this, _STSWorkerManager_instances, CreateRunnerCopy_fn).call(this, runnerEx)
|
|
2154
|
-
});
|
|
2155
|
-
runnerEx.publishInstrumentController.LogEx(`Terminating runner: [${runnerEx.id}]`);
|
|
2156
|
-
const promArray = [];
|
|
2157
|
-
promArray.push((async () => {
|
|
2158
|
-
await Sleep(100);
|
|
2159
|
-
return runnerEx.publishInstrumentController.EndPublish();
|
|
2160
|
-
})());
|
|
2161
|
-
const store = TelemetryStore();
|
|
2162
|
-
store.RemoveRunner(workerEx, runnerEx);
|
|
2163
|
-
delete workerEx.runnersEx[runnerEx.id];
|
|
2164
|
-
const retVal = await Promise.all(promArray);
|
|
2165
|
-
console.log(`Removed instrument workers: [${retVal}]`);
|
|
2166
|
-
}
|
|
2167
|
-
return true;
|
|
2168
|
-
});
|
|
2169
|
-
__privateAdd(this, _StopWorker, async (workerEx) => {
|
|
2170
|
-
try {
|
|
2171
|
-
if (workerEx.state !== IWorkerState.stopped) {
|
|
2172
|
-
__privateGet(this, _PostMessageToWorker).call(this, workerEx, eIWMessageCommands.StopAllAsyncRunners, null);
|
|
2173
|
-
console.log(`Terminating worker: [${workerEx.id}]`);
|
|
2174
|
-
const promArray = [];
|
|
2175
|
-
const ids = Object.keys(workerEx.runnersEx);
|
|
2176
|
-
ids.forEach((id) => {
|
|
2177
|
-
const runnerEx = workerEx.runnersEx[id];
|
|
2178
|
-
promArray.push(__privateGet(this, _StopRunner).call(this, workerEx, runnerEx));
|
|
2179
|
-
});
|
|
2180
|
-
await Promise.all(promArray);
|
|
2181
|
-
__privateGet(this, _TerminateWorker).call(this, workerEx);
|
|
2182
|
-
}
|
|
2183
|
-
return true;
|
|
2184
|
-
} catch (error) {
|
|
2185
|
-
console.log(`Error in STSTestWorker:StopWorker: [${error}]`);
|
|
2186
|
-
return false;
|
|
2187
|
-
}
|
|
2188
|
-
});
|
|
2189
|
-
__publicField(this, "GetNextAvailableWorker", () => {
|
|
2190
|
-
let leastRunnerWorker = null;
|
|
2191
|
-
for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
|
|
2192
|
-
if (leastRunnerWorker) {
|
|
2193
|
-
if (Object.keys(stsWorker.runnersEx).length < Object.keys(leastRunnerWorker.runnersEx).length) {
|
|
2194
|
-
leastRunnerWorker = stsWorker;
|
|
2195
|
-
}
|
|
2196
|
-
} else {
|
|
2197
|
-
leastRunnerWorker = stsWorker;
|
|
2198
|
-
}
|
|
2199
|
-
}
|
|
2200
|
-
return leastRunnerWorker;
|
|
2201
|
-
});
|
|
2202
|
-
__publicField(this, "GetBusyWorker", () => {
|
|
2203
|
-
let busyWorker = null;
|
|
2204
|
-
for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
|
|
2205
|
-
if (busyWorker) {
|
|
2206
|
-
if (Object.keys(stsWorker.runnersEx).length > Object.keys(busyWorker.runnersEx).length) {
|
|
2207
|
-
busyWorker = stsWorker;
|
|
2208
|
-
}
|
|
2209
|
-
} else {
|
|
2210
|
-
busyWorker = stsWorker;
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
return busyWorker;
|
|
2214
|
-
});
|
|
2215
|
-
__publicField(this, "StopAllWorkers", async () => {
|
|
2216
|
-
const promArray = [];
|
|
2217
|
-
for (const [, stsWorker] of Object.entries(this.WorkersEx)) {
|
|
2218
|
-
promArray.push(stsWorker.Stop());
|
|
2219
|
-
}
|
|
2220
|
-
await Promise.all(promArray);
|
|
2221
|
-
});
|
|
2222
|
-
__privateSet(this, _app, app);
|
|
2223
|
-
if (options) {
|
|
2224
|
-
__privateSet(this, _options, options);
|
|
2225
|
-
} else {
|
|
2226
|
-
__privateSet(this, _options, {});
|
|
2227
|
-
}
|
|
2228
|
-
console.log(chalk.yellow(`CompareSTSInstrumentControllerPluginKeyWMEx(): [${CompareSTSInstrumentControllerPluginKeyWMEx()}]`));
|
|
2229
|
-
console.log(chalk.yellow(`Attempting to get STSInstrumentControllerPlugin using symbol: [${String(STSInstrumentControllerPluginKey)}]`));
|
|
2230
|
-
__privateSet(this, _STSInstrumentController, GetSTSInstrumentController(app));
|
|
2231
|
-
console.log(chalk.yellow("keys within app.config.globalProperties.$sts"));
|
|
2232
|
-
for (const [key] of Object.entries(app.config.globalProperties.$sts)) {
|
|
2233
|
-
console.log(chalk.yellow(`${key}`));
|
|
2234
|
-
}
|
|
2235
|
-
if (!__privateGet(this, _STSInstrumentController)) {
|
|
2236
|
-
console.log(chalk.yellow(`Failed to get STSInstrumentControllerPlugin using symbol: [${String(STSInstrumentControllerPluginKey)}]`));
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
get WorkersEx() {
|
|
2240
|
-
return __privateGet(this, _workersEx);
|
|
2241
|
-
}
|
|
2242
|
-
get Options() {
|
|
2243
|
-
return __privateGet(this, _options);
|
|
2244
|
-
}
|
|
2245
|
-
set Options(options) {
|
|
2246
|
-
__privateSet(this, _options, options);
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
_workersEx = new WeakMap();
|
|
2250
|
-
_runner = new WeakMap();
|
|
2251
|
-
_workerId = new WeakMap();
|
|
2252
|
-
_options = new WeakMap();
|
|
2253
|
-
_STSInstrumentController = new WeakMap();
|
|
2254
|
-
_app = new WeakMap();
|
|
2255
|
-
_STSWorkerManager_instances = new WeakSet();
|
|
2256
|
-
CreateRunnerCopy_fn = function(runnerEx) {
|
|
2257
|
-
return {
|
|
2258
|
-
id: runnerEx.id,
|
|
2259
|
-
asyncRunnerContext: { ...runnerEx.asyncRunnerContext },
|
|
2260
|
-
options: { ...runnerEx.options },
|
|
2261
|
-
state: runnerEx.state,
|
|
2262
|
-
instrumentData: { ...runnerEx.instrumentData }
|
|
2263
|
-
};
|
|
2264
|
-
};
|
|
2265
|
-
_SetRunnerIntoWorker = new WeakMap();
|
|
2266
|
-
_ProcessTelemetry = new WeakMap();
|
|
2267
|
-
_CreateAsyncRunner = new WeakMap();
|
|
2268
|
-
_PostMessageToWorker = new WeakMap();
|
|
2269
|
-
_TerminateWorker = new WeakMap();
|
|
2270
|
-
_StopRunner = new WeakMap();
|
|
2271
|
-
_StopWorker = new WeakMap();
|
|
2272
|
-
const GetSTSInstrumentControllerPluginKeyWM = () => STSInstrumentControllerPluginKey;
|
|
2273
|
-
const CompareSTSInstrumentControllerPluginKeyWM = (val) => val === STSInstrumentControllerPluginKey;
|
|
2274
|
-
const CompareSTSInstrumentControllerPluginKeyWMEx = () => STSInstrumentControllerPluginKey === GetSTSInstrumentControllerPluginKey();
|
|
2275
|
-
const useSTSWorkerManager = () => inject(STSWorkerManagerPluginKey);
|
|
2276
|
-
const STSWorkerManagerPlugin = {
|
|
2277
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2278
|
-
install: (app, options) => {
|
|
2279
|
-
const wm = new STSWorkerManager(app, options);
|
|
2280
|
-
if (!app.config.globalProperties.$sts) {
|
|
2281
|
-
app.config.globalProperties.$sts = {};
|
|
2282
|
-
}
|
|
2283
|
-
app.config.globalProperties.$sts[STSWorkerManagerPluginKey] = wm;
|
|
2284
|
-
app.provide(STSWorkerManagerPluginKey, wm);
|
|
2285
|
-
}
|
|
2286
|
-
};
|
|
2287
|
-
class RequestResponseHelper {
|
|
2288
|
-
constructor(port) {
|
|
2289
|
-
__privateAdd(this, _requestResponseMessages, {});
|
|
2290
|
-
__privateAdd(this, _requestResponseMessageTimeout, 1e4);
|
|
2291
|
-
//@@ config
|
|
2292
|
-
__privateAdd(this, _port);
|
|
2293
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2294
|
-
__privateAdd(this, _debug5, (message) => {
|
|
2295
|
-
defaultLogger.debug(message);
|
|
2296
|
-
});
|
|
2297
|
-
__publicField(this, "PostMessage", (message) => {
|
|
2298
|
-
return new Promise((resolve, reject) => {
|
|
2299
|
-
const { messageId } = message.payload;
|
|
2300
|
-
if (messageId) {
|
|
2301
|
-
if (__privateGet(this, _requestResponseMessages)[messageId]) {
|
|
2302
|
-
reject(`RequestResponseHelper: Message with id: [${messageId}] already exists within the Request/Response record structure`);
|
|
2303
|
-
} else {
|
|
2304
|
-
__privateGet(this, _requestResponseMessages)[messageId] = {
|
|
2305
|
-
publishMessagePayload: { ...message },
|
|
2306
|
-
cb: () => {
|
|
2307
|
-
const detail = __privateGet(this, _requestResponseMessages)[messageId].publishMessagePayloadResponse;
|
|
2308
|
-
clearTimeout(__privateGet(this, _requestResponseMessages)[messageId].timeout);
|
|
2309
|
-
setTimeout(() => {
|
|
2310
|
-
delete __privateGet(this, _requestResponseMessages)[messageId];
|
|
2311
|
-
}, 0);
|
|
2312
|
-
if (detail) {
|
|
2313
|
-
__privateGet(this, _debug5).call(this, `RequestResponseHelper: Resolving response message with id: [${messageId}] from target worker port. Details: [${JSON.stringify(detail)}]`);
|
|
2314
|
-
resolve(detail);
|
|
2315
|
-
} else {
|
|
2316
|
-
const msg = `Could not get detail from this.#requestResponseMessages[messageId].publishMessagePayloadResponse`;
|
|
2317
|
-
__privateGet(this, _debug5).call(this, msg);
|
|
2318
|
-
reject(msg);
|
|
2319
|
-
}
|
|
2320
|
-
},
|
|
2321
|
-
timeout: setTimeout(() => {
|
|
2322
|
-
setTimeout(() => {
|
|
2323
|
-
delete __privateGet(this, _requestResponseMessages)[messageId];
|
|
2324
|
-
}, 0);
|
|
2325
|
-
__privateGet(this, _debug5).call(this, `RequestResponseHelper: Timeout has occurred after: [${__privateGet(this, _requestResponseMessageTimeout)}]ms with message id: [${messageId}]. Details: [${JSON.stringify(__privateGet(this, _requestResponseMessages)[messageId].publishMessagePayload)}]`);
|
|
2326
|
-
reject("RequestResponseHelper: Did not receive response form parent process.");
|
|
2327
|
-
}, __privateGet(this, _requestResponseMessageTimeout))
|
|
2328
|
-
// max message timeout allowed
|
|
2329
|
-
};
|
|
2330
|
-
__privateGet(this, _port).postMessage(message);
|
|
2331
|
-
}
|
|
2332
|
-
} else {
|
|
2333
|
-
const msg = `RequestResponseHelper: Response did not include a message id`;
|
|
2334
|
-
__privateGet(this, _debug5).call(this, msg);
|
|
2335
|
-
reject(msg);
|
|
2336
|
-
}
|
|
2337
|
-
});
|
|
2338
|
-
});
|
|
2339
|
-
__privateAdd(this, _SetupListener, () => {
|
|
2340
|
-
__privateGet(this, _port).onmessage = async (msg) => {
|
|
2341
|
-
const publishMessagePayload = msg.data;
|
|
2342
|
-
if (publishMessagePayload.payload.messageId) {
|
|
2343
|
-
const messageId = publishMessagePayload.payload.messageId;
|
|
2344
|
-
if (messageId && messageId !== "") {
|
|
2345
|
-
if (__privateGet(this, _requestResponseMessages)[messageId]) {
|
|
2346
|
-
const requestResponseMessage = __privateGet(this, _requestResponseMessages)[messageId];
|
|
2347
|
-
requestResponseMessage.publishMessagePayloadResponse = { ...publishMessagePayload };
|
|
2348
|
-
requestResponseMessage.cb();
|
|
2349
|
-
} else {
|
|
2350
|
-
throw new Error(`RequestResponseHelper: Could not find Request/Response message with id: [${messageId}]`);
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
};
|
|
2355
|
-
});
|
|
2356
|
-
__privateSet(this, _port, port);
|
|
2357
|
-
__privateGet(this, _SetupListener).call(this);
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
_requestResponseMessages = new WeakMap();
|
|
2361
|
-
_requestResponseMessageTimeout = new WeakMap();
|
|
2362
|
-
_port = new WeakMap();
|
|
2363
|
-
_debug5 = new WeakMap();
|
|
2364
|
-
_SetupListener = new WeakMap();
|
|
2365
|
-
class WorkerInstance {
|
|
2366
|
-
constructor() {
|
|
2367
|
-
__privateAdd(this, _collectorCollectorPort, null);
|
|
2368
|
-
__privateAdd(this, _requestResponseHelper, null);
|
|
2369
|
-
__privateAdd(this, _runners, {});
|
|
2370
|
-
__privateAdd(this, _options2, null);
|
|
2371
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2372
|
-
__privateAdd(this, _debug6, (message) => {
|
|
2373
|
-
defaultLogger.debug(message);
|
|
2374
|
-
});
|
|
2375
|
-
__publicField(this, "GetRandomInt", (max) => {
|
|
2376
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::GetRandomInt`);
|
|
2377
|
-
return Math.floor(Math.random() * Math.floor(max));
|
|
2378
|
-
});
|
|
2379
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2380
|
-
__publicField(this, "StartWork", async (runner) => {
|
|
2381
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::StartWork`);
|
|
2382
|
-
return;
|
|
2383
|
-
});
|
|
2384
|
-
__publicField(this, "PostTelemetry", (runner) => {
|
|
2385
|
-
if (__privateGet(this, _collectorCollectorPort)) {
|
|
2386
|
-
const message = {
|
|
2387
|
-
command: eIWMessageCommands.InstrumentTelemetry,
|
|
2388
|
-
payload: {
|
|
2389
|
-
runner
|
|
2390
|
-
}
|
|
2391
|
-
};
|
|
2392
|
-
__privateGet(this, _collectorCollectorPort).postMessage(message);
|
|
2393
|
-
}
|
|
2394
|
-
});
|
|
2395
|
-
__privateAdd(this, _SetMessagePort, (workerMessagePort) => {
|
|
2396
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::SetMessagePort`);
|
|
2397
|
-
__privateSet(this, _collectorCollectorPort, workerMessagePort.port);
|
|
2398
|
-
__privateGet(this, _collectorCollectorPort).onmessage = function(data) {
|
|
2399
|
-
console.log(`collectorCollectorPort onmessage: ${data.data}`);
|
|
2400
|
-
};
|
|
2401
|
-
__privateSet(this, _requestResponseHelper, new RequestResponseHelper(__privateGet(this, _collectorCollectorPort)));
|
|
2402
|
-
const response = {
|
|
2403
|
-
command: eIWMessageCommands.MessagePortResponse,
|
|
2404
|
-
payload: {}
|
|
2405
|
-
};
|
|
2406
|
-
__privateGet(this, _collectorCollectorPort).postMessage(response);
|
|
2407
|
-
});
|
|
2408
|
-
__publicField(this, "StartRunner", async (runner) => {
|
|
2409
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::StartRunner`);
|
|
2410
|
-
console.log(`StartTests: [${JSON.stringify(runner)}]`);
|
|
2411
|
-
runner.state = IRunnerState.running;
|
|
2412
|
-
this.StartWork(runner);
|
|
2413
|
-
});
|
|
2414
|
-
__privateAdd(this, _AddAsyncRunner, (testRunnerTelemetryPayload) => {
|
|
2415
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::AddAsyncRunner`);
|
|
2416
|
-
const { runner } = testRunnerTelemetryPayload;
|
|
2417
|
-
__privateGet(this, _runners)[runner.id] = runner;
|
|
2418
|
-
this.StartRunner(runner);
|
|
2419
|
-
});
|
|
2420
|
-
__privateAdd(this, _StopRunners, (testRunnerTelemetryPayload) => {
|
|
2421
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::StopRunners`);
|
|
2422
|
-
if (testRunnerTelemetryPayload === null) {
|
|
2423
|
-
for (const [, testRunner] of Object.entries(__privateGet(this, _runners))) {
|
|
2424
|
-
testRunner.state = IRunnerState.stopped;
|
|
2425
|
-
}
|
|
2426
|
-
} else {
|
|
2427
|
-
const runner = __privateGet(this, _runners)[testRunnerTelemetryPayload.runner.id];
|
|
2428
|
-
if (runner) {
|
|
2429
|
-
runner.state = IRunnerState.stopped;
|
|
2430
|
-
}
|
|
2431
|
-
}
|
|
2432
|
-
});
|
|
2433
|
-
__publicField(this, "ProcessMessage", async (data) => {
|
|
2434
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::ProcessMessage`);
|
|
2435
|
-
try {
|
|
2436
|
-
const payloadMessage = data.data;
|
|
2437
|
-
switch (payloadMessage.command) {
|
|
2438
|
-
case eIWMessageCommands.MessagePort:
|
|
2439
|
-
__privateGet(this, _SetMessagePort).call(this, payloadMessage.payload);
|
|
2440
|
-
__privateSet(this, _options2, payloadMessage.payload.options);
|
|
2441
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::ProcessMessage::#options: [${JSON.stringify(__privateGet(this, _options2))}]`);
|
|
2442
|
-
break;
|
|
2443
|
-
case eIWMessageCommands.AddAsyncRunner:
|
|
2444
|
-
__privateGet(this, _AddAsyncRunner).call(this, payloadMessage.payload);
|
|
2445
|
-
break;
|
|
2446
|
-
case eIWMessageCommands.StopAllAsyncRunners:
|
|
2447
|
-
__privateGet(this, _StopRunners).call(this, payloadMessage.payload);
|
|
2448
|
-
break;
|
|
2449
|
-
default:
|
|
2450
|
-
__privateGet(this, _debug6).call(this, `Invalid payloadMessage.command: [${payloadMessage.command}] - Ignoring`);
|
|
2451
|
-
}
|
|
2452
|
-
} catch (error) {
|
|
2453
|
-
console.log(error);
|
|
2454
|
-
}
|
|
2455
|
-
});
|
|
2456
|
-
__privateGet(this, _debug6).call(this, `WorkerInstance::constructor`);
|
|
2457
|
-
}
|
|
2458
|
-
get RequestResponseHelper() {
|
|
2459
|
-
return __privateGet(this, _requestResponseHelper);
|
|
2460
|
-
}
|
|
2461
|
-
get CollectorCollectorPort() {
|
|
2462
|
-
return __privateGet(this, _collectorCollectorPort);
|
|
2463
|
-
}
|
|
2464
|
-
get Options() {
|
|
2465
|
-
return __privateGet(this, _options2);
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
_collectorCollectorPort = new WeakMap();
|
|
2469
|
-
_requestResponseHelper = new WeakMap();
|
|
2470
|
-
_runners = new WeakMap();
|
|
2471
|
-
_options2 = new WeakMap();
|
|
2472
|
-
_debug6 = new WeakMap();
|
|
2473
|
-
_SetMessagePort = new WeakMap();
|
|
2474
|
-
_AddAsyncRunner = new WeakMap();
|
|
2475
|
-
_StopRunners = new WeakMap();
|
|
2476
340
|
export {
|
|
2477
341
|
ClientStorageFactory,
|
|
2478
342
|
ClientStorageType,
|
|
2479
|
-
CompareSTSInstrumentControllerPluginKeyWM,
|
|
2480
|
-
CompareSTSInstrumentControllerPluginKeyWMEx,
|
|
2481
|
-
GetSTSInstrumentControllerPluginKeyWM,
|
|
2482
|
-
IRunnerState,
|
|
2483
|
-
IWorkerState,
|
|
2484
|
-
RequestResponseHelper,
|
|
2485
343
|
STSEmitterPlugin,
|
|
2486
344
|
STSEmitterPluginKey,
|
|
2487
345
|
STSStoragePlugin,
|
|
2488
346
|
STSStoragePluginKey,
|
|
2489
|
-
STSWorkerManager,
|
|
2490
|
-
STSWorkerManagerPlugin,
|
|
2491
347
|
STSWorkerManagerPluginKey,
|
|
2492
|
-
TelemetryStore,
|
|
2493
|
-
URI_BASE_VUEUTILS,
|
|
2494
|
-
WorkerInstance,
|
|
2495
|
-
eIWMessageCommands,
|
|
2496
348
|
useSTSEmitterPlugin,
|
|
2497
|
-
useSTSStoragePlugin
|
|
2498
|
-
useSTSWorkerManager
|
|
349
|
+
useSTSStoragePlugin
|
|
2499
350
|
};
|
|
2500
351
|
//# sourceMappingURL=stsvueutils.mjs.map
|