@midscene/cli 1.8.7-beta-20260528070149.0 → 1.8.7-beta-20260528111436.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3880 @@
1
+ import * as __rspack_external_os from "os";
2
+ import * as __rspack_external_tty from "tty";
3
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
+ import node_path, { basename, dirname, extname, join, relative, resolve as external_node_path_resolve, sep } from "node:path";
5
+ import { getMidsceneRunSubDir } from "@midscene/shared/common";
6
+ import { createRequire } from "node:module";
7
+ import { pathToFileURL } from "node:url";
8
+ import { test } from "@rstest/core";
9
+ import { ScriptPlayer, parseYamlScript } from "@midscene/core/yaml";
10
+ import { buildChromeArgs, defaultViewportHeight, defaultViewportWidth, puppeteerAgentForTarget } from "@midscene/web/puppeteer-agent-launcher";
11
+ import lodash_merge from "lodash.merge";
12
+ import puppeteer from "puppeteer";
13
+ import { createServer } from "http-server";
14
+ import node_assert from "node:assert";
15
+ import { createAgent, getReportFileName } from "@midscene/core/agent";
16
+ import { processCacheConfig } from "@midscene/core/utils";
17
+ import { getDebug } from "@midscene/shared/logger";
18
+ import { AgentOverChromeBridge } from "@midscene/web/bridge-mode";
19
+ import { stripVTControlCharacters } from "node:util";
20
+ import node_process from "node:process";
21
+ var __webpack_modules__ = {
22
+ "../../node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js" (module, __unused_rspack_exports, __webpack_require__) {
23
+ module = __webpack_require__.nmd(module);
24
+ const wrapAnsi16 = (fn, offset)=>(...args)=>{
25
+ const code = fn(...args);
26
+ return `\u001B[${code + offset}m`;
27
+ };
28
+ const wrapAnsi256 = (fn, offset)=>(...args)=>{
29
+ const code = fn(...args);
30
+ return `\u001B[${38 + offset};5;${code}m`;
31
+ };
32
+ const wrapAnsi16m = (fn, offset)=>(...args)=>{
33
+ const rgb = fn(...args);
34
+ return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
35
+ };
36
+ const ansi2ansi = (n)=>n;
37
+ const rgb2rgb = (r, g, b)=>[
38
+ r,
39
+ g,
40
+ b
41
+ ];
42
+ const setLazyProperty = (object, property, get)=>{
43
+ Object.defineProperty(object, property, {
44
+ get: ()=>{
45
+ const value = get();
46
+ Object.defineProperty(object, property, {
47
+ value,
48
+ enumerable: true,
49
+ configurable: true
50
+ });
51
+ return value;
52
+ },
53
+ enumerable: true,
54
+ configurable: true
55
+ });
56
+ };
57
+ let colorConvert;
58
+ const makeDynamicStyles = (wrap, targetSpace, identity, isBackground)=>{
59
+ if (void 0 === colorConvert) colorConvert = __webpack_require__("../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js");
60
+ const offset = isBackground ? 10 : 0;
61
+ const styles = {};
62
+ for (const [sourceSpace, suite] of Object.entries(colorConvert)){
63
+ const name = 'ansi16' === sourceSpace ? 'ansi' : sourceSpace;
64
+ if (sourceSpace === targetSpace) styles[name] = wrap(identity, offset);
65
+ else if ('object' == typeof suite) styles[name] = wrap(suite[targetSpace], offset);
66
+ }
67
+ return styles;
68
+ };
69
+ function assembleStyles() {
70
+ const codes = new Map();
71
+ const styles = {
72
+ modifier: {
73
+ reset: [
74
+ 0,
75
+ 0
76
+ ],
77
+ bold: [
78
+ 1,
79
+ 22
80
+ ],
81
+ dim: [
82
+ 2,
83
+ 22
84
+ ],
85
+ italic: [
86
+ 3,
87
+ 23
88
+ ],
89
+ underline: [
90
+ 4,
91
+ 24
92
+ ],
93
+ inverse: [
94
+ 7,
95
+ 27
96
+ ],
97
+ hidden: [
98
+ 8,
99
+ 28
100
+ ],
101
+ strikethrough: [
102
+ 9,
103
+ 29
104
+ ]
105
+ },
106
+ color: {
107
+ black: [
108
+ 30,
109
+ 39
110
+ ],
111
+ red: [
112
+ 31,
113
+ 39
114
+ ],
115
+ green: [
116
+ 32,
117
+ 39
118
+ ],
119
+ yellow: [
120
+ 33,
121
+ 39
122
+ ],
123
+ blue: [
124
+ 34,
125
+ 39
126
+ ],
127
+ magenta: [
128
+ 35,
129
+ 39
130
+ ],
131
+ cyan: [
132
+ 36,
133
+ 39
134
+ ],
135
+ white: [
136
+ 37,
137
+ 39
138
+ ],
139
+ blackBright: [
140
+ 90,
141
+ 39
142
+ ],
143
+ redBright: [
144
+ 91,
145
+ 39
146
+ ],
147
+ greenBright: [
148
+ 92,
149
+ 39
150
+ ],
151
+ yellowBright: [
152
+ 93,
153
+ 39
154
+ ],
155
+ blueBright: [
156
+ 94,
157
+ 39
158
+ ],
159
+ magentaBright: [
160
+ 95,
161
+ 39
162
+ ],
163
+ cyanBright: [
164
+ 96,
165
+ 39
166
+ ],
167
+ whiteBright: [
168
+ 97,
169
+ 39
170
+ ]
171
+ },
172
+ bgColor: {
173
+ bgBlack: [
174
+ 40,
175
+ 49
176
+ ],
177
+ bgRed: [
178
+ 41,
179
+ 49
180
+ ],
181
+ bgGreen: [
182
+ 42,
183
+ 49
184
+ ],
185
+ bgYellow: [
186
+ 43,
187
+ 49
188
+ ],
189
+ bgBlue: [
190
+ 44,
191
+ 49
192
+ ],
193
+ bgMagenta: [
194
+ 45,
195
+ 49
196
+ ],
197
+ bgCyan: [
198
+ 46,
199
+ 49
200
+ ],
201
+ bgWhite: [
202
+ 47,
203
+ 49
204
+ ],
205
+ bgBlackBright: [
206
+ 100,
207
+ 49
208
+ ],
209
+ bgRedBright: [
210
+ 101,
211
+ 49
212
+ ],
213
+ bgGreenBright: [
214
+ 102,
215
+ 49
216
+ ],
217
+ bgYellowBright: [
218
+ 103,
219
+ 49
220
+ ],
221
+ bgBlueBright: [
222
+ 104,
223
+ 49
224
+ ],
225
+ bgMagentaBright: [
226
+ 105,
227
+ 49
228
+ ],
229
+ bgCyanBright: [
230
+ 106,
231
+ 49
232
+ ],
233
+ bgWhiteBright: [
234
+ 107,
235
+ 49
236
+ ]
237
+ }
238
+ };
239
+ styles.color.gray = styles.color.blackBright;
240
+ styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
241
+ styles.color.grey = styles.color.blackBright;
242
+ styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
243
+ for (const [groupName, group] of Object.entries(styles)){
244
+ for (const [styleName, style] of Object.entries(group)){
245
+ styles[styleName] = {
246
+ open: `\u001B[${style[0]}m`,
247
+ close: `\u001B[${style[1]}m`
248
+ };
249
+ group[styleName] = styles[styleName];
250
+ codes.set(style[0], style[1]);
251
+ }
252
+ Object.defineProperty(styles, groupName, {
253
+ value: group,
254
+ enumerable: false
255
+ });
256
+ }
257
+ Object.defineProperty(styles, 'codes', {
258
+ value: codes,
259
+ enumerable: false
260
+ });
261
+ styles.color.close = '\u001B[39m';
262
+ styles.bgColor.close = '\u001B[49m';
263
+ setLazyProperty(styles.color, 'ansi', ()=>makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
264
+ setLazyProperty(styles.color, 'ansi256', ()=>makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
265
+ setLazyProperty(styles.color, 'ansi16m', ()=>makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
266
+ setLazyProperty(styles.bgColor, 'ansi', ()=>makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
267
+ setLazyProperty(styles.bgColor, 'ansi256', ()=>makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
268
+ setLazyProperty(styles.bgColor, 'ansi16m', ()=>makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
269
+ return styles;
270
+ }
271
+ Object.defineProperty(module, 'exports', {
272
+ enumerable: true,
273
+ get: assembleStyles
274
+ });
275
+ },
276
+ "../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js" (module, __unused_rspack_exports, __webpack_require__) {
277
+ const ansiStyles = __webpack_require__("../../node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js");
278
+ const { stdout: stdoutColor, stderr: stderrColor } = __webpack_require__("../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js");
279
+ const { stringReplaceAll, stringEncaseCRLFWithFirstIndex } = __webpack_require__("../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js");
280
+ const { isArray } = Array;
281
+ const levelMapping = [
282
+ 'ansi',
283
+ 'ansi',
284
+ 'ansi256',
285
+ 'ansi16m'
286
+ ];
287
+ const styles = Object.create(null);
288
+ const applyOptions = (object, options = {})=>{
289
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) throw new Error('The `level` option should be an integer from 0 to 3');
290
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
291
+ object.level = void 0 === options.level ? colorLevel : options.level;
292
+ };
293
+ class ChalkClass {
294
+ constructor(options){
295
+ return chalkFactory(options);
296
+ }
297
+ }
298
+ const chalkFactory = (options)=>{
299
+ const chalk = {};
300
+ applyOptions(chalk, options);
301
+ chalk.template = (...arguments_)=>chalkTag(chalk.template, ...arguments_);
302
+ Object.setPrototypeOf(chalk, Chalk.prototype);
303
+ Object.setPrototypeOf(chalk.template, chalk);
304
+ chalk.template.constructor = ()=>{
305
+ throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
306
+ };
307
+ chalk.template.Instance = ChalkClass;
308
+ return chalk.template;
309
+ };
310
+ function Chalk(options) {
311
+ return chalkFactory(options);
312
+ }
313
+ for (const [styleName, style] of Object.entries(ansiStyles))styles[styleName] = {
314
+ get () {
315
+ const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
316
+ Object.defineProperty(this, styleName, {
317
+ value: builder
318
+ });
319
+ return builder;
320
+ }
321
+ };
322
+ styles.visible = {
323
+ get () {
324
+ const builder = createBuilder(this, this._styler, true);
325
+ Object.defineProperty(this, 'visible', {
326
+ value: builder
327
+ });
328
+ return builder;
329
+ }
330
+ };
331
+ const usedModels = [
332
+ 'rgb',
333
+ 'hex',
334
+ 'keyword',
335
+ 'hsl',
336
+ 'hsv',
337
+ 'hwb',
338
+ 'ansi',
339
+ 'ansi256'
340
+ ];
341
+ for (const model of usedModels)styles[model] = {
342
+ get () {
343
+ const { level } = this;
344
+ return function(...arguments_) {
345
+ const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
346
+ return createBuilder(this, styler, this._isEmpty);
347
+ };
348
+ }
349
+ };
350
+ for (const model of usedModels){
351
+ const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
352
+ styles[bgModel] = {
353
+ get () {
354
+ const { level } = this;
355
+ return function(...arguments_) {
356
+ const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
357
+ return createBuilder(this, styler, this._isEmpty);
358
+ };
359
+ }
360
+ };
361
+ }
362
+ const proto = Object.defineProperties(()=>{}, {
363
+ ...styles,
364
+ level: {
365
+ enumerable: true,
366
+ get () {
367
+ return this._generator.level;
368
+ },
369
+ set (level) {
370
+ this._generator.level = level;
371
+ }
372
+ }
373
+ });
374
+ const createStyler = (open, close, parent)=>{
375
+ let openAll;
376
+ let closeAll;
377
+ if (void 0 === parent) {
378
+ openAll = open;
379
+ closeAll = close;
380
+ } else {
381
+ openAll = parent.openAll + open;
382
+ closeAll = close + parent.closeAll;
383
+ }
384
+ return {
385
+ open,
386
+ close,
387
+ openAll,
388
+ closeAll,
389
+ parent
390
+ };
391
+ };
392
+ const createBuilder = (self, _styler, _isEmpty)=>{
393
+ const builder = (...arguments_)=>{
394
+ if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) return applyStyle(builder, chalkTag(builder, ...arguments_));
395
+ return applyStyle(builder, 1 === arguments_.length ? '' + arguments_[0] : arguments_.join(' '));
396
+ };
397
+ Object.setPrototypeOf(builder, proto);
398
+ builder._generator = self;
399
+ builder._styler = _styler;
400
+ builder._isEmpty = _isEmpty;
401
+ return builder;
402
+ };
403
+ const applyStyle = (self, string)=>{
404
+ if (self.level <= 0 || !string) return self._isEmpty ? '' : string;
405
+ let styler = self._styler;
406
+ if (void 0 === styler) return string;
407
+ const { openAll, closeAll } = styler;
408
+ if (-1 !== string.indexOf('\u001B')) while(void 0 !== styler){
409
+ string = stringReplaceAll(string, styler.close, styler.open);
410
+ styler = styler.parent;
411
+ }
412
+ const lfIndex = string.indexOf('\n');
413
+ if (-1 !== lfIndex) string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
414
+ return openAll + string + closeAll;
415
+ };
416
+ let template;
417
+ const chalkTag = (chalk, ...strings)=>{
418
+ const [firstString] = strings;
419
+ if (!isArray(firstString) || !isArray(firstString.raw)) return strings.join(' ');
420
+ const arguments_ = strings.slice(1);
421
+ const parts = [
422
+ firstString.raw[0]
423
+ ];
424
+ for(let i = 1; i < firstString.length; i++)parts.push(String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'), String(firstString.raw[i]));
425
+ if (void 0 === template) template = __webpack_require__("../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js");
426
+ return template(chalk, parts.join(''));
427
+ };
428
+ Object.defineProperties(Chalk.prototype, styles);
429
+ const chalk = Chalk();
430
+ chalk.supportsColor = stdoutColor;
431
+ chalk.stderr = Chalk({
432
+ level: stderrColor ? stderrColor.level : 0
433
+ });
434
+ chalk.stderr.supportsColor = stderrColor;
435
+ module.exports = chalk;
436
+ },
437
+ "../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js" (module) {
438
+ 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;
439
+ const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
440
+ const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
441
+ const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
442
+ const ESCAPES = new Map([
443
+ [
444
+ 'n',
445
+ '\n'
446
+ ],
447
+ [
448
+ 'r',
449
+ '\r'
450
+ ],
451
+ [
452
+ 't',
453
+ '\t'
454
+ ],
455
+ [
456
+ 'b',
457
+ '\b'
458
+ ],
459
+ [
460
+ 'f',
461
+ '\f'
462
+ ],
463
+ [
464
+ 'v',
465
+ '\v'
466
+ ],
467
+ [
468
+ '0',
469
+ '\0'
470
+ ],
471
+ [
472
+ '\\',
473
+ '\\'
474
+ ],
475
+ [
476
+ 'e',
477
+ '\u001B'
478
+ ],
479
+ [
480
+ 'a',
481
+ '\u0007'
482
+ ]
483
+ ]);
484
+ function unescape(c) {
485
+ const u = 'u' === c[0];
486
+ const bracket = '{' === c[1];
487
+ if (u && !bracket && 5 === c.length || 'x' === c[0] && 3 === c.length) return String.fromCharCode(parseInt(c.slice(1), 16));
488
+ if (u && bracket) return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
489
+ return ESCAPES.get(c) || c;
490
+ }
491
+ function parseArguments(name, arguments_) {
492
+ const results = [];
493
+ const chunks = arguments_.trim().split(/\s*,\s*/g);
494
+ let matches;
495
+ for (const chunk of chunks){
496
+ const number = Number(chunk);
497
+ if (Number.isNaN(number)) if (matches = chunk.match(STRING_REGEX)) results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character)=>escape ? unescape(escape) : character));
498
+ else throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
499
+ else results.push(number);
500
+ }
501
+ return results;
502
+ }
503
+ function parseStyle(style) {
504
+ STYLE_REGEX.lastIndex = 0;
505
+ const results = [];
506
+ let matches;
507
+ while(null !== (matches = STYLE_REGEX.exec(style))){
508
+ const name = matches[1];
509
+ if (matches[2]) {
510
+ const args = parseArguments(name, matches[2]);
511
+ results.push([
512
+ name
513
+ ].concat(args));
514
+ } else results.push([
515
+ name
516
+ ]);
517
+ }
518
+ return results;
519
+ }
520
+ function buildStyle(chalk, styles) {
521
+ const enabled = {};
522
+ for (const layer of styles)for (const style of layer.styles)enabled[style[0]] = layer.inverse ? null : style.slice(1);
523
+ let current = chalk;
524
+ for (const [styleName, styles] of Object.entries(enabled))if (Array.isArray(styles)) {
525
+ if (!(styleName in current)) throw new Error(`Unknown Chalk style: ${styleName}`);
526
+ current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
527
+ }
528
+ return current;
529
+ }
530
+ module.exports = (chalk, temporary)=>{
531
+ const styles = [];
532
+ const chunks = [];
533
+ let chunk = [];
534
+ temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character)=>{
535
+ if (escapeCharacter) chunk.push(unescape(escapeCharacter));
536
+ else if (style) {
537
+ const string = chunk.join('');
538
+ chunk = [];
539
+ chunks.push(0 === styles.length ? string : buildStyle(chalk, styles)(string));
540
+ styles.push({
541
+ inverse,
542
+ styles: parseStyle(style)
543
+ });
544
+ } else if (close) {
545
+ if (0 === styles.length) throw new Error('Found extraneous } in Chalk template literal');
546
+ chunks.push(buildStyle(chalk, styles)(chunk.join('')));
547
+ chunk = [];
548
+ styles.pop();
549
+ } else chunk.push(character);
550
+ });
551
+ chunks.push(chunk.join(''));
552
+ if (styles.length > 0) {
553
+ const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${1 === styles.length ? '' : 's'} (\`}\`)`;
554
+ throw new Error(errMessage);
555
+ }
556
+ return chunks.join('');
557
+ };
558
+ },
559
+ "../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js" (module) {
560
+ const stringReplaceAll = (string, substring, replacer)=>{
561
+ let index = string.indexOf(substring);
562
+ if (-1 === index) return string;
563
+ const substringLength = substring.length;
564
+ let endIndex = 0;
565
+ let returnValue = '';
566
+ do {
567
+ returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
568
+ endIndex = index + substringLength;
569
+ index = string.indexOf(substring, endIndex);
570
+ }while (-1 !== index);
571
+ returnValue += string.substr(endIndex);
572
+ return returnValue;
573
+ };
574
+ const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index)=>{
575
+ let endIndex = 0;
576
+ let returnValue = '';
577
+ do {
578
+ const gotCR = '\r' === string[index - 1];
579
+ returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
580
+ endIndex = index + 1;
581
+ index = string.indexOf('\n', endIndex);
582
+ }while (-1 !== index);
583
+ returnValue += string.substr(endIndex);
584
+ return returnValue;
585
+ };
586
+ module.exports = {
587
+ stringReplaceAll,
588
+ stringEncaseCRLFWithFirstIndex
589
+ };
590
+ },
591
+ "../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js" (module, __unused_rspack_exports, __webpack_require__) {
592
+ const cssKeywords = __webpack_require__("../../node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js");
593
+ const reverseKeywords = {};
594
+ for (const key of Object.keys(cssKeywords))reverseKeywords[cssKeywords[key]] = key;
595
+ const convert = {
596
+ rgb: {
597
+ channels: 3,
598
+ labels: 'rgb'
599
+ },
600
+ hsl: {
601
+ channels: 3,
602
+ labels: 'hsl'
603
+ },
604
+ hsv: {
605
+ channels: 3,
606
+ labels: 'hsv'
607
+ },
608
+ hwb: {
609
+ channels: 3,
610
+ labels: 'hwb'
611
+ },
612
+ cmyk: {
613
+ channels: 4,
614
+ labels: 'cmyk'
615
+ },
616
+ xyz: {
617
+ channels: 3,
618
+ labels: 'xyz'
619
+ },
620
+ lab: {
621
+ channels: 3,
622
+ labels: 'lab'
623
+ },
624
+ lch: {
625
+ channels: 3,
626
+ labels: 'lch'
627
+ },
628
+ hex: {
629
+ channels: 1,
630
+ labels: [
631
+ 'hex'
632
+ ]
633
+ },
634
+ keyword: {
635
+ channels: 1,
636
+ labels: [
637
+ 'keyword'
638
+ ]
639
+ },
640
+ ansi16: {
641
+ channels: 1,
642
+ labels: [
643
+ 'ansi16'
644
+ ]
645
+ },
646
+ ansi256: {
647
+ channels: 1,
648
+ labels: [
649
+ 'ansi256'
650
+ ]
651
+ },
652
+ hcg: {
653
+ channels: 3,
654
+ labels: [
655
+ 'h',
656
+ 'c',
657
+ 'g'
658
+ ]
659
+ },
660
+ apple: {
661
+ channels: 3,
662
+ labels: [
663
+ 'r16',
664
+ 'g16',
665
+ 'b16'
666
+ ]
667
+ },
668
+ gray: {
669
+ channels: 1,
670
+ labels: [
671
+ 'gray'
672
+ ]
673
+ }
674
+ };
675
+ module.exports = convert;
676
+ for (const model of Object.keys(convert)){
677
+ if (!('channels' in convert[model])) throw new Error('missing channels property: ' + model);
678
+ if (!('labels' in convert[model])) throw new Error('missing channel labels property: ' + model);
679
+ if (convert[model].labels.length !== convert[model].channels) throw new Error('channel and label counts mismatch: ' + model);
680
+ const { channels, labels } = convert[model];
681
+ delete convert[model].channels;
682
+ delete convert[model].labels;
683
+ Object.defineProperty(convert[model], 'channels', {
684
+ value: channels
685
+ });
686
+ Object.defineProperty(convert[model], 'labels', {
687
+ value: labels
688
+ });
689
+ }
690
+ convert.rgb.hsl = function(rgb) {
691
+ const r = rgb[0] / 255;
692
+ const g = rgb[1] / 255;
693
+ const b = rgb[2] / 255;
694
+ const min = Math.min(r, g, b);
695
+ const max = Math.max(r, g, b);
696
+ const delta = max - min;
697
+ let h;
698
+ let s;
699
+ if (max === min) h = 0;
700
+ else if (r === max) h = (g - b) / delta;
701
+ else if (g === max) h = 2 + (b - r) / delta;
702
+ else if (b === max) h = 4 + (r - g) / delta;
703
+ h = Math.min(60 * h, 360);
704
+ if (h < 0) h += 360;
705
+ const l = (min + max) / 2;
706
+ s = max === min ? 0 : l <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
707
+ return [
708
+ h,
709
+ 100 * s,
710
+ 100 * l
711
+ ];
712
+ };
713
+ convert.rgb.hsv = function(rgb) {
714
+ let rdif;
715
+ let gdif;
716
+ let bdif;
717
+ let h;
718
+ let s;
719
+ const r = rgb[0] / 255;
720
+ const g = rgb[1] / 255;
721
+ const b = rgb[2] / 255;
722
+ const v = Math.max(r, g, b);
723
+ const diff = v - Math.min(r, g, b);
724
+ const diffc = function(c) {
725
+ return (v - c) / 6 / diff + 0.5;
726
+ };
727
+ if (0 === diff) {
728
+ h = 0;
729
+ s = 0;
730
+ } else {
731
+ s = diff / v;
732
+ rdif = diffc(r);
733
+ gdif = diffc(g);
734
+ bdif = diffc(b);
735
+ if (r === v) h = bdif - gdif;
736
+ else if (g === v) h = 1 / 3 + rdif - bdif;
737
+ else if (b === v) h = 2 / 3 + gdif - rdif;
738
+ if (h < 0) h += 1;
739
+ else if (h > 1) h -= 1;
740
+ }
741
+ return [
742
+ 360 * h,
743
+ 100 * s,
744
+ 100 * v
745
+ ];
746
+ };
747
+ convert.rgb.hwb = function(rgb) {
748
+ const r = rgb[0];
749
+ const g = rgb[1];
750
+ let b = rgb[2];
751
+ const h = convert.rgb.hsl(rgb)[0];
752
+ const w = 1 / 255 * Math.min(r, Math.min(g, b));
753
+ b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
754
+ return [
755
+ h,
756
+ 100 * w,
757
+ 100 * b
758
+ ];
759
+ };
760
+ convert.rgb.cmyk = function(rgb) {
761
+ const r = rgb[0] / 255;
762
+ const g = rgb[1] / 255;
763
+ const b = rgb[2] / 255;
764
+ const k = Math.min(1 - r, 1 - g, 1 - b);
765
+ const c = (1 - r - k) / (1 - k) || 0;
766
+ const m = (1 - g - k) / (1 - k) || 0;
767
+ const y = (1 - b - k) / (1 - k) || 0;
768
+ return [
769
+ 100 * c,
770
+ 100 * m,
771
+ 100 * y,
772
+ 100 * k
773
+ ];
774
+ };
775
+ function comparativeDistance(x, y) {
776
+ return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
777
+ }
778
+ convert.rgb.keyword = function(rgb) {
779
+ const reversed = reverseKeywords[rgb];
780
+ if (reversed) return reversed;
781
+ let currentClosestDistance = 1 / 0;
782
+ let currentClosestKeyword;
783
+ for (const keyword of Object.keys(cssKeywords)){
784
+ const value = cssKeywords[keyword];
785
+ const distance = comparativeDistance(rgb, value);
786
+ if (distance < currentClosestDistance) {
787
+ currentClosestDistance = distance;
788
+ currentClosestKeyword = keyword;
789
+ }
790
+ }
791
+ return currentClosestKeyword;
792
+ };
793
+ convert.keyword.rgb = function(keyword) {
794
+ return cssKeywords[keyword];
795
+ };
796
+ convert.rgb.xyz = function(rgb) {
797
+ let r = rgb[0] / 255;
798
+ let g = rgb[1] / 255;
799
+ let b = rgb[2] / 255;
800
+ r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
801
+ g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
802
+ b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
803
+ const x = 0.4124 * r + 0.3576 * g + 0.1805 * b;
804
+ const y = 0.2126 * r + 0.7152 * g + 0.0722 * b;
805
+ const z = 0.0193 * r + 0.1192 * g + 0.9505 * b;
806
+ return [
807
+ 100 * x,
808
+ 100 * y,
809
+ 100 * z
810
+ ];
811
+ };
812
+ convert.rgb.lab = function(rgb) {
813
+ const xyz = convert.rgb.xyz(rgb);
814
+ let x = xyz[0];
815
+ let y = xyz[1];
816
+ let z = xyz[2];
817
+ x /= 95.047;
818
+ y /= 100;
819
+ z /= 108.883;
820
+ x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
821
+ y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
822
+ z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
823
+ const l = 116 * y - 16;
824
+ const a = 500 * (x - y);
825
+ const b = 200 * (y - z);
826
+ return [
827
+ l,
828
+ a,
829
+ b
830
+ ];
831
+ };
832
+ convert.hsl.rgb = function(hsl) {
833
+ const h = hsl[0] / 360;
834
+ const s = hsl[1] / 100;
835
+ const l = hsl[2] / 100;
836
+ let t2;
837
+ let t3;
838
+ let val;
839
+ if (0 === s) {
840
+ val = 255 * l;
841
+ return [
842
+ val,
843
+ val,
844
+ val
845
+ ];
846
+ }
847
+ t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
848
+ const t1 = 2 * l - t2;
849
+ const rgb = [
850
+ 0,
851
+ 0,
852
+ 0
853
+ ];
854
+ for(let i = 0; i < 3; i++){
855
+ t3 = h + 1 / 3 * -(i - 1);
856
+ if (t3 < 0) t3++;
857
+ if (t3 > 1) t3--;
858
+ val = 6 * t3 < 1 ? t1 + (t2 - t1) * 6 * t3 : 2 * t3 < 1 ? t2 : 3 * t3 < 2 ? t1 + (t2 - t1) * (2 / 3 - t3) * 6 : t1;
859
+ rgb[i] = 255 * val;
860
+ }
861
+ return rgb;
862
+ };
863
+ convert.hsl.hsv = function(hsl) {
864
+ const h = hsl[0];
865
+ let s = hsl[1] / 100;
866
+ let l = hsl[2] / 100;
867
+ let smin = s;
868
+ const lmin = Math.max(l, 0.01);
869
+ l *= 2;
870
+ s *= l <= 1 ? l : 2 - l;
871
+ smin *= lmin <= 1 ? lmin : 2 - lmin;
872
+ const v = (l + s) / 2;
873
+ const sv = 0 === l ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
874
+ return [
875
+ h,
876
+ 100 * sv,
877
+ 100 * v
878
+ ];
879
+ };
880
+ convert.hsv.rgb = function(hsv) {
881
+ const h = hsv[0] / 60;
882
+ const s = hsv[1] / 100;
883
+ let v = hsv[2] / 100;
884
+ const hi = Math.floor(h) % 6;
885
+ const f = h - Math.floor(h);
886
+ const p = 255 * v * (1 - s);
887
+ const q = 255 * v * (1 - s * f);
888
+ const t = 255 * v * (1 - s * (1 - f));
889
+ v *= 255;
890
+ switch(hi){
891
+ case 0:
892
+ return [
893
+ v,
894
+ t,
895
+ p
896
+ ];
897
+ case 1:
898
+ return [
899
+ q,
900
+ v,
901
+ p
902
+ ];
903
+ case 2:
904
+ return [
905
+ p,
906
+ v,
907
+ t
908
+ ];
909
+ case 3:
910
+ return [
911
+ p,
912
+ q,
913
+ v
914
+ ];
915
+ case 4:
916
+ return [
917
+ t,
918
+ p,
919
+ v
920
+ ];
921
+ case 5:
922
+ return [
923
+ v,
924
+ p,
925
+ q
926
+ ];
927
+ }
928
+ };
929
+ convert.hsv.hsl = function(hsv) {
930
+ const h = hsv[0];
931
+ const s = hsv[1] / 100;
932
+ const v = hsv[2] / 100;
933
+ const vmin = Math.max(v, 0.01);
934
+ let sl;
935
+ let l;
936
+ l = (2 - s) * v;
937
+ const lmin = (2 - s) * vmin;
938
+ sl = s * vmin;
939
+ sl /= lmin <= 1 ? lmin : 2 - lmin;
940
+ sl = sl || 0;
941
+ l /= 2;
942
+ return [
943
+ h,
944
+ 100 * sl,
945
+ 100 * l
946
+ ];
947
+ };
948
+ convert.hwb.rgb = function(hwb) {
949
+ const h = hwb[0] / 360;
950
+ let wh = hwb[1] / 100;
951
+ let bl = hwb[2] / 100;
952
+ const ratio = wh + bl;
953
+ let f;
954
+ if (ratio > 1) {
955
+ wh /= ratio;
956
+ bl /= ratio;
957
+ }
958
+ const i = Math.floor(6 * h);
959
+ const v = 1 - bl;
960
+ f = 6 * h - i;
961
+ if ((0x01 & i) !== 0) f = 1 - f;
962
+ const n = wh + f * (v - wh);
963
+ let r;
964
+ let g;
965
+ let b;
966
+ switch(i){
967
+ default:
968
+ case 6:
969
+ case 0:
970
+ r = v;
971
+ g = n;
972
+ b = wh;
973
+ break;
974
+ case 1:
975
+ r = n;
976
+ g = v;
977
+ b = wh;
978
+ break;
979
+ case 2:
980
+ r = wh;
981
+ g = v;
982
+ b = n;
983
+ break;
984
+ case 3:
985
+ r = wh;
986
+ g = n;
987
+ b = v;
988
+ break;
989
+ case 4:
990
+ r = n;
991
+ g = wh;
992
+ b = v;
993
+ break;
994
+ case 5:
995
+ r = v;
996
+ g = wh;
997
+ b = n;
998
+ break;
999
+ }
1000
+ return [
1001
+ 255 * r,
1002
+ 255 * g,
1003
+ 255 * b
1004
+ ];
1005
+ };
1006
+ convert.cmyk.rgb = function(cmyk) {
1007
+ const c = cmyk[0] / 100;
1008
+ const m = cmyk[1] / 100;
1009
+ const y = cmyk[2] / 100;
1010
+ const k = cmyk[3] / 100;
1011
+ const r = 1 - Math.min(1, c * (1 - k) + k);
1012
+ const g = 1 - Math.min(1, m * (1 - k) + k);
1013
+ const b = 1 - Math.min(1, y * (1 - k) + k);
1014
+ return [
1015
+ 255 * r,
1016
+ 255 * g,
1017
+ 255 * b
1018
+ ];
1019
+ };
1020
+ convert.xyz.rgb = function(xyz) {
1021
+ const x = xyz[0] / 100;
1022
+ const y = xyz[1] / 100;
1023
+ const z = xyz[2] / 100;
1024
+ let r;
1025
+ let g;
1026
+ let b;
1027
+ r = 3.2406 * x + -1.5372 * y + -0.4986 * z;
1028
+ g = -0.9689 * x + 1.8758 * y + 0.0415 * z;
1029
+ b = 0.0557 * x + -0.204 * y + 1.0570 * z;
1030
+ r = r > 0.0031308 ? 1.055 * r ** (1.0 / 2.4) - 0.055 : 12.92 * r;
1031
+ g = g > 0.0031308 ? 1.055 * g ** (1.0 / 2.4) - 0.055 : 12.92 * g;
1032
+ b = b > 0.0031308 ? 1.055 * b ** (1.0 / 2.4) - 0.055 : 12.92 * b;
1033
+ r = Math.min(Math.max(0, r), 1);
1034
+ g = Math.min(Math.max(0, g), 1);
1035
+ b = Math.min(Math.max(0, b), 1);
1036
+ return [
1037
+ 255 * r,
1038
+ 255 * g,
1039
+ 255 * b
1040
+ ];
1041
+ };
1042
+ convert.xyz.lab = function(xyz) {
1043
+ let x = xyz[0];
1044
+ let y = xyz[1];
1045
+ let z = xyz[2];
1046
+ x /= 95.047;
1047
+ y /= 100;
1048
+ z /= 108.883;
1049
+ x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
1050
+ y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
1051
+ z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
1052
+ const l = 116 * y - 16;
1053
+ const a = 500 * (x - y);
1054
+ const b = 200 * (y - z);
1055
+ return [
1056
+ l,
1057
+ a,
1058
+ b
1059
+ ];
1060
+ };
1061
+ convert.lab.xyz = function(lab) {
1062
+ const l = lab[0];
1063
+ const a = lab[1];
1064
+ const b = lab[2];
1065
+ let x;
1066
+ let y;
1067
+ let z;
1068
+ y = (l + 16) / 116;
1069
+ x = a / 500 + y;
1070
+ z = y - b / 200;
1071
+ const y2 = y ** 3;
1072
+ const x2 = x ** 3;
1073
+ const z2 = z ** 3;
1074
+ y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
1075
+ x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
1076
+ z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
1077
+ x *= 95.047;
1078
+ y *= 100;
1079
+ z *= 108.883;
1080
+ return [
1081
+ x,
1082
+ y,
1083
+ z
1084
+ ];
1085
+ };
1086
+ convert.lab.lch = function(lab) {
1087
+ const l = lab[0];
1088
+ const a = lab[1];
1089
+ const b = lab[2];
1090
+ let h;
1091
+ const hr = Math.atan2(b, a);
1092
+ h = 360 * hr / 2 / Math.PI;
1093
+ if (h < 0) h += 360;
1094
+ const c = Math.sqrt(a * a + b * b);
1095
+ return [
1096
+ l,
1097
+ c,
1098
+ h
1099
+ ];
1100
+ };
1101
+ convert.lch.lab = function(lch) {
1102
+ const l = lch[0];
1103
+ const c = lch[1];
1104
+ const h = lch[2];
1105
+ const hr = h / 360 * 2 * Math.PI;
1106
+ const a = c * Math.cos(hr);
1107
+ const b = c * Math.sin(hr);
1108
+ return [
1109
+ l,
1110
+ a,
1111
+ b
1112
+ ];
1113
+ };
1114
+ convert.rgb.ansi16 = function(args, saturation = null) {
1115
+ const [r, g, b] = args;
1116
+ let value = null === saturation ? convert.rgb.hsv(args)[2] : saturation;
1117
+ value = Math.round(value / 50);
1118
+ if (0 === value) return 30;
1119
+ let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
1120
+ if (2 === value) ansi += 60;
1121
+ return ansi;
1122
+ };
1123
+ convert.hsv.ansi16 = function(args) {
1124
+ return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
1125
+ };
1126
+ convert.rgb.ansi256 = function(args) {
1127
+ const r = args[0];
1128
+ const g = args[1];
1129
+ const b = args[2];
1130
+ if (r === g && g === b) {
1131
+ if (r < 8) return 16;
1132
+ if (r > 248) return 231;
1133
+ return Math.round((r - 8) / 247 * 24) + 232;
1134
+ }
1135
+ const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
1136
+ return ansi;
1137
+ };
1138
+ convert.ansi16.rgb = function(args) {
1139
+ let color = args % 10;
1140
+ if (0 === color || 7 === color) {
1141
+ if (args > 50) color += 3.5;
1142
+ color = color / 10.5 * 255;
1143
+ return [
1144
+ color,
1145
+ color,
1146
+ color
1147
+ ];
1148
+ }
1149
+ const mult = (~~(args > 50) + 1) * 0.5;
1150
+ const r = (1 & color) * mult * 255;
1151
+ const g = (color >> 1 & 1) * mult * 255;
1152
+ const b = (color >> 2 & 1) * mult * 255;
1153
+ return [
1154
+ r,
1155
+ g,
1156
+ b
1157
+ ];
1158
+ };
1159
+ convert.ansi256.rgb = function(args) {
1160
+ if (args >= 232) {
1161
+ const c = (args - 232) * 10 + 8;
1162
+ return [
1163
+ c,
1164
+ c,
1165
+ c
1166
+ ];
1167
+ }
1168
+ args -= 16;
1169
+ let rem;
1170
+ const r = Math.floor(args / 36) / 5 * 255;
1171
+ const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
1172
+ const b = rem % 6 / 5 * 255;
1173
+ return [
1174
+ r,
1175
+ g,
1176
+ b
1177
+ ];
1178
+ };
1179
+ convert.rgb.hex = function(args) {
1180
+ const integer = ((0xFF & Math.round(args[0])) << 16) + ((0xFF & Math.round(args[1])) << 8) + (0xFF & Math.round(args[2]));
1181
+ const string = integer.toString(16).toUpperCase();
1182
+ return '000000'.substring(string.length) + string;
1183
+ };
1184
+ convert.hex.rgb = function(args) {
1185
+ const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
1186
+ if (!match) return [
1187
+ 0,
1188
+ 0,
1189
+ 0
1190
+ ];
1191
+ let colorString = match[0];
1192
+ if (3 === match[0].length) colorString = colorString.split('').map((char)=>char + char).join('');
1193
+ const integer = parseInt(colorString, 16);
1194
+ const r = integer >> 16 & 0xFF;
1195
+ const g = integer >> 8 & 0xFF;
1196
+ const b = 0xFF & integer;
1197
+ return [
1198
+ r,
1199
+ g,
1200
+ b
1201
+ ];
1202
+ };
1203
+ convert.rgb.hcg = function(rgb) {
1204
+ const r = rgb[0] / 255;
1205
+ const g = rgb[1] / 255;
1206
+ const b = rgb[2] / 255;
1207
+ const max = Math.max(Math.max(r, g), b);
1208
+ const min = Math.min(Math.min(r, g), b);
1209
+ const chroma = max - min;
1210
+ let grayscale;
1211
+ let hue;
1212
+ grayscale = chroma < 1 ? min / (1 - chroma) : 0;
1213
+ hue = chroma <= 0 ? 0 : max === r ? (g - b) / chroma % 6 : max === g ? 2 + (b - r) / chroma : 4 + (r - g) / chroma;
1214
+ hue /= 6;
1215
+ hue %= 1;
1216
+ return [
1217
+ 360 * hue,
1218
+ 100 * chroma,
1219
+ 100 * grayscale
1220
+ ];
1221
+ };
1222
+ convert.hsl.hcg = function(hsl) {
1223
+ const s = hsl[1] / 100;
1224
+ const l = hsl[2] / 100;
1225
+ const c = l < 0.5 ? 2.0 * s * l : 2.0 * s * (1.0 - l);
1226
+ let f = 0;
1227
+ if (c < 1.0) f = (l - 0.5 * c) / (1.0 - c);
1228
+ return [
1229
+ hsl[0],
1230
+ 100 * c,
1231
+ 100 * f
1232
+ ];
1233
+ };
1234
+ convert.hsv.hcg = function(hsv) {
1235
+ const s = hsv[1] / 100;
1236
+ const v = hsv[2] / 100;
1237
+ const c = s * v;
1238
+ let f = 0;
1239
+ if (c < 1.0) f = (v - c) / (1 - c);
1240
+ return [
1241
+ hsv[0],
1242
+ 100 * c,
1243
+ 100 * f
1244
+ ];
1245
+ };
1246
+ convert.hcg.rgb = function(hcg) {
1247
+ const h = hcg[0] / 360;
1248
+ const c = hcg[1] / 100;
1249
+ const g = hcg[2] / 100;
1250
+ if (0.0 === c) return [
1251
+ 255 * g,
1252
+ 255 * g,
1253
+ 255 * g
1254
+ ];
1255
+ const pure = [
1256
+ 0,
1257
+ 0,
1258
+ 0
1259
+ ];
1260
+ const hi = h % 1 * 6;
1261
+ const v = hi % 1;
1262
+ const w = 1 - v;
1263
+ let mg = 0;
1264
+ switch(Math.floor(hi)){
1265
+ case 0:
1266
+ pure[0] = 1;
1267
+ pure[1] = v;
1268
+ pure[2] = 0;
1269
+ break;
1270
+ case 1:
1271
+ pure[0] = w;
1272
+ pure[1] = 1;
1273
+ pure[2] = 0;
1274
+ break;
1275
+ case 2:
1276
+ pure[0] = 0;
1277
+ pure[1] = 1;
1278
+ pure[2] = v;
1279
+ break;
1280
+ case 3:
1281
+ pure[0] = 0;
1282
+ pure[1] = w;
1283
+ pure[2] = 1;
1284
+ break;
1285
+ case 4:
1286
+ pure[0] = v;
1287
+ pure[1] = 0;
1288
+ pure[2] = 1;
1289
+ break;
1290
+ default:
1291
+ pure[0] = 1;
1292
+ pure[1] = 0;
1293
+ pure[2] = w;
1294
+ }
1295
+ mg = (1.0 - c) * g;
1296
+ return [
1297
+ (c * pure[0] + mg) * 255,
1298
+ (c * pure[1] + mg) * 255,
1299
+ (c * pure[2] + mg) * 255
1300
+ ];
1301
+ };
1302
+ convert.hcg.hsv = function(hcg) {
1303
+ const c = hcg[1] / 100;
1304
+ const g = hcg[2] / 100;
1305
+ const v = c + g * (1.0 - c);
1306
+ let f = 0;
1307
+ if (v > 0.0) f = c / v;
1308
+ return [
1309
+ hcg[0],
1310
+ 100 * f,
1311
+ 100 * v
1312
+ ];
1313
+ };
1314
+ convert.hcg.hsl = function(hcg) {
1315
+ const c = hcg[1] / 100;
1316
+ const g = hcg[2] / 100;
1317
+ const l = g * (1.0 - c) + 0.5 * c;
1318
+ let s = 0;
1319
+ if (l > 0.0 && l < 0.5) s = c / (2 * l);
1320
+ else if (l >= 0.5 && l < 1.0) s = c / (2 * (1 - l));
1321
+ return [
1322
+ hcg[0],
1323
+ 100 * s,
1324
+ 100 * l
1325
+ ];
1326
+ };
1327
+ convert.hcg.hwb = function(hcg) {
1328
+ const c = hcg[1] / 100;
1329
+ const g = hcg[2] / 100;
1330
+ const v = c + g * (1.0 - c);
1331
+ return [
1332
+ hcg[0],
1333
+ (v - c) * 100,
1334
+ (1 - v) * 100
1335
+ ];
1336
+ };
1337
+ convert.hwb.hcg = function(hwb) {
1338
+ const w = hwb[1] / 100;
1339
+ const b = hwb[2] / 100;
1340
+ const v = 1 - b;
1341
+ const c = v - w;
1342
+ let g = 0;
1343
+ if (c < 1) g = (v - c) / (1 - c);
1344
+ return [
1345
+ hwb[0],
1346
+ 100 * c,
1347
+ 100 * g
1348
+ ];
1349
+ };
1350
+ convert.apple.rgb = function(apple) {
1351
+ return [
1352
+ apple[0] / 65535 * 255,
1353
+ apple[1] / 65535 * 255,
1354
+ apple[2] / 65535 * 255
1355
+ ];
1356
+ };
1357
+ convert.rgb.apple = function(rgb) {
1358
+ return [
1359
+ rgb[0] / 255 * 65535,
1360
+ rgb[1] / 255 * 65535,
1361
+ rgb[2] / 255 * 65535
1362
+ ];
1363
+ };
1364
+ convert.gray.rgb = function(args) {
1365
+ return [
1366
+ args[0] / 100 * 255,
1367
+ args[0] / 100 * 255,
1368
+ args[0] / 100 * 255
1369
+ ];
1370
+ };
1371
+ convert.gray.hsl = function(args) {
1372
+ return [
1373
+ 0,
1374
+ 0,
1375
+ args[0]
1376
+ ];
1377
+ };
1378
+ convert.gray.hsv = convert.gray.hsl;
1379
+ convert.gray.hwb = function(gray) {
1380
+ return [
1381
+ 0,
1382
+ 100,
1383
+ gray[0]
1384
+ ];
1385
+ };
1386
+ convert.gray.cmyk = function(gray) {
1387
+ return [
1388
+ 0,
1389
+ 0,
1390
+ 0,
1391
+ gray[0]
1392
+ ];
1393
+ };
1394
+ convert.gray.lab = function(gray) {
1395
+ return [
1396
+ gray[0],
1397
+ 0,
1398
+ 0
1399
+ ];
1400
+ };
1401
+ convert.gray.hex = function(gray) {
1402
+ const val = 0xFF & Math.round(gray[0] / 100 * 255);
1403
+ const integer = (val << 16) + (val << 8) + val;
1404
+ const string = integer.toString(16).toUpperCase();
1405
+ return '000000'.substring(string.length) + string;
1406
+ };
1407
+ convert.rgb.gray = function(rgb) {
1408
+ const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
1409
+ return [
1410
+ val / 255 * 100
1411
+ ];
1412
+ };
1413
+ },
1414
+ "../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js" (module, __unused_rspack_exports, __webpack_require__) {
1415
+ const conversions = __webpack_require__("../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js");
1416
+ const route = __webpack_require__("../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js");
1417
+ const convert = {};
1418
+ const models = Object.keys(conversions);
1419
+ function wrapRaw(fn) {
1420
+ const wrappedFn = function(...args) {
1421
+ const arg0 = args[0];
1422
+ if (null == arg0) return arg0;
1423
+ if (arg0.length > 1) args = arg0;
1424
+ return fn(args);
1425
+ };
1426
+ if ('conversion' in fn) wrappedFn.conversion = fn.conversion;
1427
+ return wrappedFn;
1428
+ }
1429
+ function wrapRounded(fn) {
1430
+ const wrappedFn = function(...args) {
1431
+ const arg0 = args[0];
1432
+ if (null == arg0) return arg0;
1433
+ if (arg0.length > 1) args = arg0;
1434
+ const result = fn(args);
1435
+ if ('object' == typeof result) for(let len = result.length, i = 0; i < len; i++)result[i] = Math.round(result[i]);
1436
+ return result;
1437
+ };
1438
+ if ('conversion' in fn) wrappedFn.conversion = fn.conversion;
1439
+ return wrappedFn;
1440
+ }
1441
+ models.forEach((fromModel)=>{
1442
+ convert[fromModel] = {};
1443
+ Object.defineProperty(convert[fromModel], 'channels', {
1444
+ value: conversions[fromModel].channels
1445
+ });
1446
+ Object.defineProperty(convert[fromModel], 'labels', {
1447
+ value: conversions[fromModel].labels
1448
+ });
1449
+ const routes = route(fromModel);
1450
+ const routeModels = Object.keys(routes);
1451
+ routeModels.forEach((toModel)=>{
1452
+ const fn = routes[toModel];
1453
+ convert[fromModel][toModel] = wrapRounded(fn);
1454
+ convert[fromModel][toModel].raw = wrapRaw(fn);
1455
+ });
1456
+ });
1457
+ module.exports = convert;
1458
+ },
1459
+ "../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js" (module, __unused_rspack_exports, __webpack_require__) {
1460
+ const conversions = __webpack_require__("../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js");
1461
+ function buildGraph() {
1462
+ const graph = {};
1463
+ const models = Object.keys(conversions);
1464
+ for(let len = models.length, i = 0; i < len; i++)graph[models[i]] = {
1465
+ distance: -1,
1466
+ parent: null
1467
+ };
1468
+ return graph;
1469
+ }
1470
+ function deriveBFS(fromModel) {
1471
+ const graph = buildGraph();
1472
+ const queue = [
1473
+ fromModel
1474
+ ];
1475
+ graph[fromModel].distance = 0;
1476
+ while(queue.length){
1477
+ const current = queue.pop();
1478
+ const adjacents = Object.keys(conversions[current]);
1479
+ for(let len = adjacents.length, i = 0; i < len; i++){
1480
+ const adjacent = adjacents[i];
1481
+ const node = graph[adjacent];
1482
+ if (-1 === node.distance) {
1483
+ node.distance = graph[current].distance + 1;
1484
+ node.parent = current;
1485
+ queue.unshift(adjacent);
1486
+ }
1487
+ }
1488
+ }
1489
+ return graph;
1490
+ }
1491
+ function link(from, to) {
1492
+ return function(args) {
1493
+ return to(from(args));
1494
+ };
1495
+ }
1496
+ function wrapConversion(toModel, graph) {
1497
+ const path = [
1498
+ graph[toModel].parent,
1499
+ toModel
1500
+ ];
1501
+ let fn = conversions[graph[toModel].parent][toModel];
1502
+ let cur = graph[toModel].parent;
1503
+ while(graph[cur].parent){
1504
+ path.unshift(graph[cur].parent);
1505
+ fn = link(conversions[graph[cur].parent][cur], fn);
1506
+ cur = graph[cur].parent;
1507
+ }
1508
+ fn.conversion = path;
1509
+ return fn;
1510
+ }
1511
+ module.exports = function(fromModel) {
1512
+ const graph = deriveBFS(fromModel);
1513
+ const conversion = {};
1514
+ const models = Object.keys(graph);
1515
+ for(let len = models.length, i = 0; i < len; i++){
1516
+ const toModel = models[i];
1517
+ const node = graph[toModel];
1518
+ if (null !== node.parent) conversion[toModel] = wrapConversion(toModel, graph);
1519
+ }
1520
+ return conversion;
1521
+ };
1522
+ },
1523
+ "../../node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js" (module) {
1524
+ module.exports = {
1525
+ aliceblue: [
1526
+ 240,
1527
+ 248,
1528
+ 255
1529
+ ],
1530
+ antiquewhite: [
1531
+ 250,
1532
+ 235,
1533
+ 215
1534
+ ],
1535
+ aqua: [
1536
+ 0,
1537
+ 255,
1538
+ 255
1539
+ ],
1540
+ aquamarine: [
1541
+ 127,
1542
+ 255,
1543
+ 212
1544
+ ],
1545
+ azure: [
1546
+ 240,
1547
+ 255,
1548
+ 255
1549
+ ],
1550
+ beige: [
1551
+ 245,
1552
+ 245,
1553
+ 220
1554
+ ],
1555
+ bisque: [
1556
+ 255,
1557
+ 228,
1558
+ 196
1559
+ ],
1560
+ black: [
1561
+ 0,
1562
+ 0,
1563
+ 0
1564
+ ],
1565
+ blanchedalmond: [
1566
+ 255,
1567
+ 235,
1568
+ 205
1569
+ ],
1570
+ blue: [
1571
+ 0,
1572
+ 0,
1573
+ 255
1574
+ ],
1575
+ blueviolet: [
1576
+ 138,
1577
+ 43,
1578
+ 226
1579
+ ],
1580
+ brown: [
1581
+ 165,
1582
+ 42,
1583
+ 42
1584
+ ],
1585
+ burlywood: [
1586
+ 222,
1587
+ 184,
1588
+ 135
1589
+ ],
1590
+ cadetblue: [
1591
+ 95,
1592
+ 158,
1593
+ 160
1594
+ ],
1595
+ chartreuse: [
1596
+ 127,
1597
+ 255,
1598
+ 0
1599
+ ],
1600
+ chocolate: [
1601
+ 210,
1602
+ 105,
1603
+ 30
1604
+ ],
1605
+ coral: [
1606
+ 255,
1607
+ 127,
1608
+ 80
1609
+ ],
1610
+ cornflowerblue: [
1611
+ 100,
1612
+ 149,
1613
+ 237
1614
+ ],
1615
+ cornsilk: [
1616
+ 255,
1617
+ 248,
1618
+ 220
1619
+ ],
1620
+ crimson: [
1621
+ 220,
1622
+ 20,
1623
+ 60
1624
+ ],
1625
+ cyan: [
1626
+ 0,
1627
+ 255,
1628
+ 255
1629
+ ],
1630
+ darkblue: [
1631
+ 0,
1632
+ 0,
1633
+ 139
1634
+ ],
1635
+ darkcyan: [
1636
+ 0,
1637
+ 139,
1638
+ 139
1639
+ ],
1640
+ darkgoldenrod: [
1641
+ 184,
1642
+ 134,
1643
+ 11
1644
+ ],
1645
+ darkgray: [
1646
+ 169,
1647
+ 169,
1648
+ 169
1649
+ ],
1650
+ darkgreen: [
1651
+ 0,
1652
+ 100,
1653
+ 0
1654
+ ],
1655
+ darkgrey: [
1656
+ 169,
1657
+ 169,
1658
+ 169
1659
+ ],
1660
+ darkkhaki: [
1661
+ 189,
1662
+ 183,
1663
+ 107
1664
+ ],
1665
+ darkmagenta: [
1666
+ 139,
1667
+ 0,
1668
+ 139
1669
+ ],
1670
+ darkolivegreen: [
1671
+ 85,
1672
+ 107,
1673
+ 47
1674
+ ],
1675
+ darkorange: [
1676
+ 255,
1677
+ 140,
1678
+ 0
1679
+ ],
1680
+ darkorchid: [
1681
+ 153,
1682
+ 50,
1683
+ 204
1684
+ ],
1685
+ darkred: [
1686
+ 139,
1687
+ 0,
1688
+ 0
1689
+ ],
1690
+ darksalmon: [
1691
+ 233,
1692
+ 150,
1693
+ 122
1694
+ ],
1695
+ darkseagreen: [
1696
+ 143,
1697
+ 188,
1698
+ 143
1699
+ ],
1700
+ darkslateblue: [
1701
+ 72,
1702
+ 61,
1703
+ 139
1704
+ ],
1705
+ darkslategray: [
1706
+ 47,
1707
+ 79,
1708
+ 79
1709
+ ],
1710
+ darkslategrey: [
1711
+ 47,
1712
+ 79,
1713
+ 79
1714
+ ],
1715
+ darkturquoise: [
1716
+ 0,
1717
+ 206,
1718
+ 209
1719
+ ],
1720
+ darkviolet: [
1721
+ 148,
1722
+ 0,
1723
+ 211
1724
+ ],
1725
+ deeppink: [
1726
+ 255,
1727
+ 20,
1728
+ 147
1729
+ ],
1730
+ deepskyblue: [
1731
+ 0,
1732
+ 191,
1733
+ 255
1734
+ ],
1735
+ dimgray: [
1736
+ 105,
1737
+ 105,
1738
+ 105
1739
+ ],
1740
+ dimgrey: [
1741
+ 105,
1742
+ 105,
1743
+ 105
1744
+ ],
1745
+ dodgerblue: [
1746
+ 30,
1747
+ 144,
1748
+ 255
1749
+ ],
1750
+ firebrick: [
1751
+ 178,
1752
+ 34,
1753
+ 34
1754
+ ],
1755
+ floralwhite: [
1756
+ 255,
1757
+ 250,
1758
+ 240
1759
+ ],
1760
+ forestgreen: [
1761
+ 34,
1762
+ 139,
1763
+ 34
1764
+ ],
1765
+ fuchsia: [
1766
+ 255,
1767
+ 0,
1768
+ 255
1769
+ ],
1770
+ gainsboro: [
1771
+ 220,
1772
+ 220,
1773
+ 220
1774
+ ],
1775
+ ghostwhite: [
1776
+ 248,
1777
+ 248,
1778
+ 255
1779
+ ],
1780
+ gold: [
1781
+ 255,
1782
+ 215,
1783
+ 0
1784
+ ],
1785
+ goldenrod: [
1786
+ 218,
1787
+ 165,
1788
+ 32
1789
+ ],
1790
+ gray: [
1791
+ 128,
1792
+ 128,
1793
+ 128
1794
+ ],
1795
+ green: [
1796
+ 0,
1797
+ 128,
1798
+ 0
1799
+ ],
1800
+ greenyellow: [
1801
+ 173,
1802
+ 255,
1803
+ 47
1804
+ ],
1805
+ grey: [
1806
+ 128,
1807
+ 128,
1808
+ 128
1809
+ ],
1810
+ honeydew: [
1811
+ 240,
1812
+ 255,
1813
+ 240
1814
+ ],
1815
+ hotpink: [
1816
+ 255,
1817
+ 105,
1818
+ 180
1819
+ ],
1820
+ indianred: [
1821
+ 205,
1822
+ 92,
1823
+ 92
1824
+ ],
1825
+ indigo: [
1826
+ 75,
1827
+ 0,
1828
+ 130
1829
+ ],
1830
+ ivory: [
1831
+ 255,
1832
+ 255,
1833
+ 240
1834
+ ],
1835
+ khaki: [
1836
+ 240,
1837
+ 230,
1838
+ 140
1839
+ ],
1840
+ lavender: [
1841
+ 230,
1842
+ 230,
1843
+ 250
1844
+ ],
1845
+ lavenderblush: [
1846
+ 255,
1847
+ 240,
1848
+ 245
1849
+ ],
1850
+ lawngreen: [
1851
+ 124,
1852
+ 252,
1853
+ 0
1854
+ ],
1855
+ lemonchiffon: [
1856
+ 255,
1857
+ 250,
1858
+ 205
1859
+ ],
1860
+ lightblue: [
1861
+ 173,
1862
+ 216,
1863
+ 230
1864
+ ],
1865
+ lightcoral: [
1866
+ 240,
1867
+ 128,
1868
+ 128
1869
+ ],
1870
+ lightcyan: [
1871
+ 224,
1872
+ 255,
1873
+ 255
1874
+ ],
1875
+ lightgoldenrodyellow: [
1876
+ 250,
1877
+ 250,
1878
+ 210
1879
+ ],
1880
+ lightgray: [
1881
+ 211,
1882
+ 211,
1883
+ 211
1884
+ ],
1885
+ lightgreen: [
1886
+ 144,
1887
+ 238,
1888
+ 144
1889
+ ],
1890
+ lightgrey: [
1891
+ 211,
1892
+ 211,
1893
+ 211
1894
+ ],
1895
+ lightpink: [
1896
+ 255,
1897
+ 182,
1898
+ 193
1899
+ ],
1900
+ lightsalmon: [
1901
+ 255,
1902
+ 160,
1903
+ 122
1904
+ ],
1905
+ lightseagreen: [
1906
+ 32,
1907
+ 178,
1908
+ 170
1909
+ ],
1910
+ lightskyblue: [
1911
+ 135,
1912
+ 206,
1913
+ 250
1914
+ ],
1915
+ lightslategray: [
1916
+ 119,
1917
+ 136,
1918
+ 153
1919
+ ],
1920
+ lightslategrey: [
1921
+ 119,
1922
+ 136,
1923
+ 153
1924
+ ],
1925
+ lightsteelblue: [
1926
+ 176,
1927
+ 196,
1928
+ 222
1929
+ ],
1930
+ lightyellow: [
1931
+ 255,
1932
+ 255,
1933
+ 224
1934
+ ],
1935
+ lime: [
1936
+ 0,
1937
+ 255,
1938
+ 0
1939
+ ],
1940
+ limegreen: [
1941
+ 50,
1942
+ 205,
1943
+ 50
1944
+ ],
1945
+ linen: [
1946
+ 250,
1947
+ 240,
1948
+ 230
1949
+ ],
1950
+ magenta: [
1951
+ 255,
1952
+ 0,
1953
+ 255
1954
+ ],
1955
+ maroon: [
1956
+ 128,
1957
+ 0,
1958
+ 0
1959
+ ],
1960
+ mediumaquamarine: [
1961
+ 102,
1962
+ 205,
1963
+ 170
1964
+ ],
1965
+ mediumblue: [
1966
+ 0,
1967
+ 0,
1968
+ 205
1969
+ ],
1970
+ mediumorchid: [
1971
+ 186,
1972
+ 85,
1973
+ 211
1974
+ ],
1975
+ mediumpurple: [
1976
+ 147,
1977
+ 112,
1978
+ 219
1979
+ ],
1980
+ mediumseagreen: [
1981
+ 60,
1982
+ 179,
1983
+ 113
1984
+ ],
1985
+ mediumslateblue: [
1986
+ 123,
1987
+ 104,
1988
+ 238
1989
+ ],
1990
+ mediumspringgreen: [
1991
+ 0,
1992
+ 250,
1993
+ 154
1994
+ ],
1995
+ mediumturquoise: [
1996
+ 72,
1997
+ 209,
1998
+ 204
1999
+ ],
2000
+ mediumvioletred: [
2001
+ 199,
2002
+ 21,
2003
+ 133
2004
+ ],
2005
+ midnightblue: [
2006
+ 25,
2007
+ 25,
2008
+ 112
2009
+ ],
2010
+ mintcream: [
2011
+ 245,
2012
+ 255,
2013
+ 250
2014
+ ],
2015
+ mistyrose: [
2016
+ 255,
2017
+ 228,
2018
+ 225
2019
+ ],
2020
+ moccasin: [
2021
+ 255,
2022
+ 228,
2023
+ 181
2024
+ ],
2025
+ navajowhite: [
2026
+ 255,
2027
+ 222,
2028
+ 173
2029
+ ],
2030
+ navy: [
2031
+ 0,
2032
+ 0,
2033
+ 128
2034
+ ],
2035
+ oldlace: [
2036
+ 253,
2037
+ 245,
2038
+ 230
2039
+ ],
2040
+ olive: [
2041
+ 128,
2042
+ 128,
2043
+ 0
2044
+ ],
2045
+ olivedrab: [
2046
+ 107,
2047
+ 142,
2048
+ 35
2049
+ ],
2050
+ orange: [
2051
+ 255,
2052
+ 165,
2053
+ 0
2054
+ ],
2055
+ orangered: [
2056
+ 255,
2057
+ 69,
2058
+ 0
2059
+ ],
2060
+ orchid: [
2061
+ 218,
2062
+ 112,
2063
+ 214
2064
+ ],
2065
+ palegoldenrod: [
2066
+ 238,
2067
+ 232,
2068
+ 170
2069
+ ],
2070
+ palegreen: [
2071
+ 152,
2072
+ 251,
2073
+ 152
2074
+ ],
2075
+ paleturquoise: [
2076
+ 175,
2077
+ 238,
2078
+ 238
2079
+ ],
2080
+ palevioletred: [
2081
+ 219,
2082
+ 112,
2083
+ 147
2084
+ ],
2085
+ papayawhip: [
2086
+ 255,
2087
+ 239,
2088
+ 213
2089
+ ],
2090
+ peachpuff: [
2091
+ 255,
2092
+ 218,
2093
+ 185
2094
+ ],
2095
+ peru: [
2096
+ 205,
2097
+ 133,
2098
+ 63
2099
+ ],
2100
+ pink: [
2101
+ 255,
2102
+ 192,
2103
+ 203
2104
+ ],
2105
+ plum: [
2106
+ 221,
2107
+ 160,
2108
+ 221
2109
+ ],
2110
+ powderblue: [
2111
+ 176,
2112
+ 224,
2113
+ 230
2114
+ ],
2115
+ purple: [
2116
+ 128,
2117
+ 0,
2118
+ 128
2119
+ ],
2120
+ rebeccapurple: [
2121
+ 102,
2122
+ 51,
2123
+ 153
2124
+ ],
2125
+ red: [
2126
+ 255,
2127
+ 0,
2128
+ 0
2129
+ ],
2130
+ rosybrown: [
2131
+ 188,
2132
+ 143,
2133
+ 143
2134
+ ],
2135
+ royalblue: [
2136
+ 65,
2137
+ 105,
2138
+ 225
2139
+ ],
2140
+ saddlebrown: [
2141
+ 139,
2142
+ 69,
2143
+ 19
2144
+ ],
2145
+ salmon: [
2146
+ 250,
2147
+ 128,
2148
+ 114
2149
+ ],
2150
+ sandybrown: [
2151
+ 244,
2152
+ 164,
2153
+ 96
2154
+ ],
2155
+ seagreen: [
2156
+ 46,
2157
+ 139,
2158
+ 87
2159
+ ],
2160
+ seashell: [
2161
+ 255,
2162
+ 245,
2163
+ 238
2164
+ ],
2165
+ sienna: [
2166
+ 160,
2167
+ 82,
2168
+ 45
2169
+ ],
2170
+ silver: [
2171
+ 192,
2172
+ 192,
2173
+ 192
2174
+ ],
2175
+ skyblue: [
2176
+ 135,
2177
+ 206,
2178
+ 235
2179
+ ],
2180
+ slateblue: [
2181
+ 106,
2182
+ 90,
2183
+ 205
2184
+ ],
2185
+ slategray: [
2186
+ 112,
2187
+ 128,
2188
+ 144
2189
+ ],
2190
+ slategrey: [
2191
+ 112,
2192
+ 128,
2193
+ 144
2194
+ ],
2195
+ snow: [
2196
+ 255,
2197
+ 250,
2198
+ 250
2199
+ ],
2200
+ springgreen: [
2201
+ 0,
2202
+ 255,
2203
+ 127
2204
+ ],
2205
+ steelblue: [
2206
+ 70,
2207
+ 130,
2208
+ 180
2209
+ ],
2210
+ tan: [
2211
+ 210,
2212
+ 180,
2213
+ 140
2214
+ ],
2215
+ teal: [
2216
+ 0,
2217
+ 128,
2218
+ 128
2219
+ ],
2220
+ thistle: [
2221
+ 216,
2222
+ 191,
2223
+ 216
2224
+ ],
2225
+ tomato: [
2226
+ 255,
2227
+ 99,
2228
+ 71
2229
+ ],
2230
+ turquoise: [
2231
+ 64,
2232
+ 224,
2233
+ 208
2234
+ ],
2235
+ violet: [
2236
+ 238,
2237
+ 130,
2238
+ 238
2239
+ ],
2240
+ wheat: [
2241
+ 245,
2242
+ 222,
2243
+ 179
2244
+ ],
2245
+ white: [
2246
+ 255,
2247
+ 255,
2248
+ 255
2249
+ ],
2250
+ whitesmoke: [
2251
+ 245,
2252
+ 245,
2253
+ 245
2254
+ ],
2255
+ yellow: [
2256
+ 255,
2257
+ 255,
2258
+ 0
2259
+ ],
2260
+ yellowgreen: [
2261
+ 154,
2262
+ 205,
2263
+ 50
2264
+ ]
2265
+ };
2266
+ },
2267
+ "../../node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js" (module) {
2268
+ module.exports = (flag, argv = process.argv)=>{
2269
+ const prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--';
2270
+ const position = argv.indexOf(prefix + flag);
2271
+ const terminatorPosition = argv.indexOf('--');
2272
+ return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
2273
+ };
2274
+ },
2275
+ "../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js" (module, __unused_rspack_exports, __webpack_require__) {
2276
+ const os = __webpack_require__("os");
2277
+ const tty = __webpack_require__("tty");
2278
+ const hasFlag = __webpack_require__("../../node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js");
2279
+ const { env } = process;
2280
+ let forceColor;
2281
+ if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) forceColor = 0;
2282
+ else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) forceColor = 1;
2283
+ if ('FORCE_COLOR' in env) forceColor = 'true' === env.FORCE_COLOR ? 1 : 'false' === env.FORCE_COLOR ? 0 : 0 === env.FORCE_COLOR.length ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
2284
+ function translateLevel(level) {
2285
+ if (0 === level) return false;
2286
+ return {
2287
+ level,
2288
+ hasBasic: true,
2289
+ has256: level >= 2,
2290
+ has16m: level >= 3
2291
+ };
2292
+ }
2293
+ function supportsColor(haveStream, streamIsTTY) {
2294
+ if (0 === forceColor) return 0;
2295
+ if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) return 3;
2296
+ if (hasFlag('color=256')) return 2;
2297
+ if (haveStream && !streamIsTTY && void 0 === forceColor) return 0;
2298
+ const min = forceColor || 0;
2299
+ if ('dumb' === env.TERM) return min;
2300
+ if ('win32' === process.platform) {
2301
+ const osRelease = os.release().split('.');
2302
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
2303
+ return 1;
2304
+ }
2305
+ if ('CI' in env) {
2306
+ if ([
2307
+ 'TRAVIS',
2308
+ 'CIRCLECI',
2309
+ 'APPVEYOR',
2310
+ 'GITLAB_CI',
2311
+ 'GITHUB_ACTIONS',
2312
+ 'BUILDKITE'
2313
+ ].some((sign)=>sign in env) || 'codeship' === env.CI_NAME) return 1;
2314
+ return min;
2315
+ }
2316
+ if ('TEAMCITY_VERSION' in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
2317
+ if ('truecolor' === env.COLORTERM) return 3;
2318
+ if ('TERM_PROGRAM' in env) {
2319
+ const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
2320
+ switch(env.TERM_PROGRAM){
2321
+ case 'iTerm.app':
2322
+ return version >= 3 ? 3 : 2;
2323
+ case 'Apple_Terminal':
2324
+ return 2;
2325
+ }
2326
+ }
2327
+ if (/-256(color)?$/i.test(env.TERM)) return 2;
2328
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
2329
+ if ('COLORTERM' in env) return 1;
2330
+ return min;
2331
+ }
2332
+ function getSupportLevel(stream) {
2333
+ const level = supportsColor(stream, stream && stream.isTTY);
2334
+ return translateLevel(level);
2335
+ }
2336
+ module.exports = {
2337
+ supportsColor: getSupportLevel,
2338
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
2339
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
2340
+ };
2341
+ },
2342
+ os (module) {
2343
+ module.exports = __rspack_external_os;
2344
+ },
2345
+ tty (module) {
2346
+ module.exports = __rspack_external_tty;
2347
+ }
2348
+ };
2349
+ var __webpack_module_cache__ = {};
2350
+ function __webpack_require__(moduleId) {
2351
+ var cachedModule = __webpack_module_cache__[moduleId];
2352
+ if (void 0 !== cachedModule) return cachedModule.exports;
2353
+ var module = __webpack_module_cache__[moduleId] = {
2354
+ id: moduleId,
2355
+ loaded: false,
2356
+ exports: {}
2357
+ };
2358
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
2359
+ module.loaded = true;
2360
+ return module.exports;
2361
+ }
2362
+ (()=>{
2363
+ __webpack_require__.n = (module)=>{
2364
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
2365
+ __webpack_require__.d(getter, {
2366
+ a: getter
2367
+ });
2368
+ return getter;
2369
+ };
2370
+ })();
2371
+ (()=>{
2372
+ __webpack_require__.d = (exports, definition)=>{
2373
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
2374
+ enumerable: true,
2375
+ get: definition[key]
2376
+ });
2377
+ };
2378
+ })();
2379
+ (()=>{
2380
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
2381
+ })();
2382
+ (()=>{
2383
+ __webpack_require__.nmd = (module)=>{
2384
+ module.paths = [];
2385
+ if (!module.children) module.children = [];
2386
+ return module;
2387
+ };
2388
+ })();
2389
+ const notExecutedError = 'Not executed (previous task failed)';
2390
+ function createNotExecutedYamlResult(file) {
2391
+ return {
2392
+ file,
2393
+ success: false,
2394
+ executed: false,
2395
+ output: void 0,
2396
+ report: void 0,
2397
+ duration: 0,
2398
+ resultType: 'notExecuted',
2399
+ error: notExecutedError
2400
+ };
2401
+ }
2402
+ function createExecutedYamlResult(options) {
2403
+ const { file, player, duration } = options;
2404
+ const hasFailedTasks = player.taskStatusList?.some((task)=>'error' === task.status) ?? false;
2405
+ const hasPlayerError = 'error' === player.status;
2406
+ let success;
2407
+ let resultType;
2408
+ if (hasPlayerError) {
2409
+ success = false;
2410
+ resultType = 'failed';
2411
+ } else if (hasFailedTasks) {
2412
+ success = false;
2413
+ resultType = 'partialFailed';
2414
+ } else {
2415
+ success = true;
2416
+ resultType = 'success';
2417
+ }
2418
+ let outputPath = player.output || void 0;
2419
+ if (outputPath && !existsSync(outputPath)) outputPath = void 0;
2420
+ let errorMessage;
2421
+ if (player.errorInSetup?.message) errorMessage = player.errorInSetup.message;
2422
+ else if (hasPlayerError || hasFailedTasks) {
2423
+ const taskErrors = player.taskStatusList?.filter((task)=>'error' === task.status && task.error?.message).map((task)=>task.error.message);
2424
+ errorMessage = taskErrors && taskErrors.length > 0 ? taskErrors.join('; ') : hasPlayerError ? 'Execution failed' : 'Some tasks failed';
2425
+ }
2426
+ return {
2427
+ file,
2428
+ success,
2429
+ executed: true,
2430
+ output: outputPath,
2431
+ report: player.reportFile || void 0,
2432
+ duration,
2433
+ resultType,
2434
+ error: errorMessage
2435
+ };
2436
+ }
2437
+ function getExecutionSummary(results) {
2438
+ return {
2439
+ total: results.length,
2440
+ successful: getResultsByType(results, 'success').length,
2441
+ failed: getResultsByType(results, 'failed').length,
2442
+ partialFailed: getResultsByType(results, 'partialFailed').length,
2443
+ notExecuted: getResultsByType(results, 'notExecuted').length,
2444
+ totalDuration: results.reduce((sum, r)=>sum + (r.duration || 0), 0)
2445
+ };
2446
+ }
2447
+ function getResultsByType(results, resultType) {
2448
+ return results.filter((result)=>result.resultType === resultType);
2449
+ }
2450
+ function getSummaryAbsolutePath(summary) {
2451
+ return external_node_path_resolve(getMidsceneRunSubDir('output'), summary);
2452
+ }
2453
+ function writeExecutionSummaryFile(summary, results) {
2454
+ const indexPath = getSummaryAbsolutePath(summary);
2455
+ const outputDir = dirname(indexPath);
2456
+ mkdirSync(outputDir, {
2457
+ recursive: true
2458
+ });
2459
+ const executionSummary = getExecutionSummary(results);
2460
+ const indexData = {
2461
+ summary: {
2462
+ ...executionSummary,
2463
+ generatedAt: new Date().toLocaleString()
2464
+ },
2465
+ results: results.map((result)=>({
2466
+ script: relative(outputDir, result.file),
2467
+ success: result.success,
2468
+ resultType: result.resultType,
2469
+ output: result.output ? (()=>{
2470
+ const relativePath = relative(outputDir, result.output);
2471
+ return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
2472
+ })() : void 0,
2473
+ report: result.report ? relative(outputDir, result.report) : void 0,
2474
+ error: result.error,
2475
+ duration: result.duration
2476
+ }))
2477
+ };
2478
+ writeFileSync(indexPath, JSON.stringify(indexData, null, 2));
2479
+ return indexPath;
2480
+ }
2481
+ function printExecutionPlan(config) {
2482
+ console.log(' Scripts:');
2483
+ for (const file of config.files)console.log(` - ${file}`);
2484
+ console.log('📋 Execution plan');
2485
+ console.log(` Concurrency: ${config.concurrent}`);
2486
+ console.log(` Keep window: ${config.keepWindow}`);
2487
+ console.log(` Headed: ${config.headed}`);
2488
+ console.log(` Continue on error: ${config.continueOnError}`);
2489
+ console.log(` Share browser context: ${config.shareBrowserContext ?? false}`);
2490
+ console.log(` Summary output: ${config.summary}`);
2491
+ }
2492
+ function printExecutionFinished() {
2493
+ console.log('Execution finished:');
2494
+ }
2495
+ function printExecutionSummary(results, summaryPath) {
2496
+ const summary = getExecutionSummary(results);
2497
+ const successfulFiles = getResultsByType(results, 'success');
2498
+ const failedFiles = getResultsByType(results, 'failed');
2499
+ const partialFailedFiles = getResultsByType(results, 'partialFailed');
2500
+ const notExecutedFiles = getResultsByType(results, 'notExecuted');
2501
+ const success = 0 === summary.failed && 0 === summary.partialFailed && 0 === summary.notExecuted;
2502
+ console.log('\n📊 Execution Summary:');
2503
+ console.log(` Total files: ${summary.total}`);
2504
+ console.log(` Successful: ${summary.successful}`);
2505
+ console.log(` Failed: ${summary.failed}`);
2506
+ console.log(` Partial failed: ${summary.partialFailed}`);
2507
+ console.log(` Not executed: ${summary.notExecuted}`);
2508
+ console.log(` Duration: ${(summary.totalDuration / 1000).toFixed(2)}s`);
2509
+ console.log(` Summary: ${summaryPath}`);
2510
+ if (successfulFiles.length > 0) {
2511
+ console.log('\n✅ Successful files:');
2512
+ successfulFiles.forEach((result)=>{
2513
+ console.log(` ${result.file}`);
2514
+ });
2515
+ }
2516
+ if (failedFiles.length > 0) {
2517
+ console.log('\n❌ Failed files');
2518
+ failedFiles.forEach((result)=>{
2519
+ console.log(` ${result.file}`);
2520
+ if (result.error) console.log(` Error: ${result.error}`);
2521
+ });
2522
+ }
2523
+ if (partialFailedFiles.length > 0) {
2524
+ console.log('\n⚠️ Partial failed files (some tasks failed with continueOnError)');
2525
+ partialFailedFiles.forEach((result)=>{
2526
+ console.log(` ${result.file}`);
2527
+ if (result.error) console.log(` Error: ${result.error}`);
2528
+ });
2529
+ }
2530
+ if (notExecutedFiles.length > 0) {
2531
+ console.log('\n⏸️ Not executed files');
2532
+ notExecutedFiles.forEach((result)=>{
2533
+ console.log(` ${result.file}`);
2534
+ });
2535
+ }
2536
+ if (success) console.log('\n🎉 All files executed successfully!');
2537
+ else console.log('\n⚠️ Some files failed or were not executed.');
2538
+ return success;
2539
+ }
2540
+ const DEFAULT_YAML_TEST_TIMEOUT = 0;
2541
+ const toPosixPath = (value)=>value.split(sep).join('/');
2542
+ const toImportLiteral = (value)=>JSON.stringify(toPosixPath(value));
2543
+ const toVirtualModuleId = (fileStem)=>`virtual:midscene-yaml/${fileStem}.test.ts`;
2544
+ const safeFileStem = (file, index)=>{
2545
+ const base = basename(file, extname(file)).replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');
2546
+ return `${String(index + 1).padStart(3, '0')}-${base || 'case'}`;
2547
+ };
2548
+ const resolveTestName = (projectDir, yamlFile)=>{
2549
+ const relativePath = relative(projectDir, yamlFile);
2550
+ return toPosixPath(relativePath.startsWith('..') ? yamlFile : relativePath);
2551
+ };
2552
+ const createGeneratedTestContent = (options)=>{
2553
+ const testOptions = {
2554
+ testName: options.testName,
2555
+ yamlFile: options.yamlFile,
2556
+ resultFile: options.resultFile,
2557
+ ...options.caseOptions ? {
2558
+ caseOptions: options.caseOptions
2559
+ } : {},
2560
+ ...options.webRuntimeOptions ? {
2561
+ webRuntimeOptions: options.webRuntimeOptions
2562
+ } : {}
2563
+ };
2564
+ return `import { defineYamlCaseTest } from ${toImportLiteral(options.frameworkImport)};
2565
+
2566
+ defineYamlCaseTest(${JSON.stringify(testOptions, null, 2)});
2567
+ `;
2568
+ };
2569
+ const createGeneratedBatchTestContent = (options)=>{
2570
+ const testOptions = {
2571
+ testName: options.testName,
2572
+ config: options.config,
2573
+ resultFiles: options.resultFiles
2574
+ };
2575
+ return `import { defineYamlBatchTest } from ${toImportLiteral(options.frameworkImport)};
2576
+
2577
+ defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
2578
+ `;
2579
+ };
2580
+ const resolveDefaultFrameworkImport = ()=>{
2581
+ const entry = process.argv[1] ? external_node_path_resolve(process.argv[1]) : '';
2582
+ const candidates = [
2583
+ entry ? join(dirname(entry), 'framework', 'index.js') : '',
2584
+ entry ? join(dirname(entry), '..', 'dist', 'lib', 'framework', 'index.js') : ''
2585
+ ].filter(Boolean);
2586
+ const matched = candidates.find((candidate)=>existsSync(candidate));
2587
+ return matched || '@midscene/cli/dist/lib/framework/index.js';
2588
+ };
2589
+ function createRstestYamlProject(options) {
2590
+ const projectDir = external_node_path_resolve(options.projectDir || process.cwd());
2591
+ const outputDir = options.outputDir || join(getMidsceneRunSubDir('tmp'), `rstest-yaml-${Date.now()}`);
2592
+ const resultDir = options.resultDir || join(outputDir, 'results');
2593
+ const frameworkImport = options.frameworkImport || resolveDefaultFrameworkImport();
2594
+ const testTimeout = options.testTimeout ?? DEFAULT_YAML_TEST_TIMEOUT;
2595
+ rmSync(outputDir, {
2596
+ recursive: true,
2597
+ force: true
2598
+ });
2599
+ mkdirSync(resultDir, {
2600
+ recursive: true
2601
+ });
2602
+ const virtualModules = {};
2603
+ const cases = options.files.map((file, index)=>{
2604
+ const yamlFile = external_node_path_resolve(file);
2605
+ const testName = resolveTestName(projectDir, yamlFile);
2606
+ const fileStem = safeFileStem(yamlFile, index);
2607
+ const resultFile = join(resultDir, `${fileStem}.json`);
2608
+ const testModule = toVirtualModuleId(fileStem);
2609
+ virtualModules[testModule] = createGeneratedTestContent({
2610
+ frameworkImport,
2611
+ yamlFile,
2612
+ resultFile,
2613
+ testName,
2614
+ caseOptions: options.caseOptions?.[yamlFile],
2615
+ webRuntimeOptions: options.webRuntimeOptions?.[yamlFile]
2616
+ });
2617
+ return {
2618
+ yamlFile,
2619
+ testModule,
2620
+ resultFile,
2621
+ testName
2622
+ };
2623
+ });
2624
+ if (options.batchConfig) {
2625
+ const batchModule = 'virtual:midscene-yaml/batch.test.ts';
2626
+ const resultFiles = Object.fromEntries(cases.map((item)=>[
2627
+ item.yamlFile,
2628
+ item.resultFile
2629
+ ]));
2630
+ return {
2631
+ projectDir,
2632
+ outputDir,
2633
+ resultDir,
2634
+ include: [
2635
+ batchModule
2636
+ ],
2637
+ virtualModules: {
2638
+ [batchModule]: createGeneratedBatchTestContent({
2639
+ frameworkImport,
2640
+ testName: 'midscene yaml batch',
2641
+ config: options.batchConfig,
2642
+ resultFiles
2643
+ })
2644
+ },
2645
+ cases,
2646
+ maxConcurrency: 1,
2647
+ testTimeout,
2648
+ bail: options.bail
2649
+ };
2650
+ }
2651
+ return {
2652
+ projectDir,
2653
+ outputDir,
2654
+ resultDir,
2655
+ include: cases.map((item)=>item.testModule),
2656
+ virtualModules,
2657
+ cases,
2658
+ maxConcurrency: options.maxConcurrency,
2659
+ testTimeout,
2660
+ bail: options.bail
2661
+ };
2662
+ }
2663
+ const requireFromCliEntry = ()=>{
2664
+ const entry = process.argv[1] ? external_node_path_resolve(process.argv[1]) : join(process.cwd(), 'midscene-cli.js');
2665
+ return createRequire(entry);
2666
+ };
2667
+ const resolvePackageFromRstestCore = (packageName)=>{
2668
+ const require = requireFromCliEntry();
2669
+ const rstestPackageJsonPath = require.resolve('@rstest/core/package.json');
2670
+ return createRequire(rstestPackageJsonPath).resolve(packageName);
2671
+ };
2672
+ function resolveRstestCoreImportPath() {
2673
+ const require = requireFromCliEntry();
2674
+ const packageJsonPath = require.resolve('@rstest/core/package.json');
2675
+ return join(dirname(packageJsonPath), 'dist', 'index.js');
2676
+ }
2677
+ const formatRunError = (error)=>error.stack || `${error.name}: ${error.message}`;
2678
+ async function runRstestYamlProject(options) {
2679
+ const [{ runRstest }, { rspack }] = await Promise.all([
2680
+ import("@rstest/core/api"),
2681
+ import(pathToFileURL(resolvePackageFromRstestCore('@rsbuild/core')).href)
2682
+ ]);
2683
+ const { project } = options;
2684
+ const maxConcurrency = void 0 !== project.maxConcurrency ? Math.max(1, project.maxConcurrency) : void 0;
2685
+ const inlineConfig = {
2686
+ root: project.projectDir,
2687
+ include: project.include,
2688
+ testEnvironment: 'node',
2689
+ testTimeout: project.testTimeout,
2690
+ ...void 0 !== maxConcurrency ? {
2691
+ maxConcurrency
2692
+ } : {},
2693
+ ...void 0 !== maxConcurrency ? {
2694
+ pool: {
2695
+ maxWorkers: maxConcurrency,
2696
+ minWorkers: maxConcurrency
2697
+ }
2698
+ } : {},
2699
+ ...void 0 !== project.bail ? {
2700
+ bail: project.bail
2701
+ } : {},
2702
+ reporters: [],
2703
+ tools: {
2704
+ rspack: (_config, { appendPlugins })=>{
2705
+ appendPlugins(new rspack.experiments.VirtualModulesPlugin(project.virtualModules));
2706
+ }
2707
+ }
2708
+ };
2709
+ const result = await runRstest({
2710
+ cwd: options.cwd || project.projectDir,
2711
+ inlineConfig
2712
+ });
2713
+ if (!result.ok && 'pipe' !== options.stdio && result.unhandledErrors.length) console.error(result.unhandledErrors.map((error)=>formatRunError(error)).join('\n'));
2714
+ return result.ok ? 0 : 1;
2715
+ }
2716
+ const createCaseOptions = (config)=>{
2717
+ const caseOptions = {};
2718
+ for (const file of config.files)caseOptions[external_node_path_resolve(file)] = {
2719
+ globalConfig: config.globalConfig
2720
+ };
2721
+ return caseOptions;
2722
+ };
2723
+ const createWebRuntimeOptions = (config, runtimeOptions)=>{
2724
+ const caseOptions = {};
2725
+ for (const file of config.files)caseOptions[external_node_path_resolve(file)] = {
2726
+ headed: runtimeOptions.headed ?? config.headed,
2727
+ keepWindow: runtimeOptions.keepWindow ?? config.keepWindow
2728
+ };
2729
+ return caseOptions;
2730
+ };
2731
+ const readProjectResults = (project)=>project.cases.map((item)=>{
2732
+ if (existsSync(item.resultFile)) return JSON.parse(readFileSync(item.resultFile, 'utf8'));
2733
+ return createNotExecutedYamlResult(item.yamlFile);
2734
+ });
2735
+ async function runFrameworkTestConfig(config, commandOptions = {}) {
2736
+ printExecutionPlan(config);
2737
+ const projectDir = external_node_path_resolve(commandOptions.projectDir || process.cwd());
2738
+ const project = createRstestYamlProject({
2739
+ files: config.files,
2740
+ projectDir,
2741
+ outputDir: commandOptions.outputDir,
2742
+ frameworkImport: commandOptions.frameworkImport,
2743
+ caseOptions: createCaseOptions(config),
2744
+ webRuntimeOptions: createWebRuntimeOptions(config, commandOptions),
2745
+ maxConcurrency: commandOptions.concurrent ?? config.concurrent,
2746
+ bail: config.continueOnError ? 0 : 1,
2747
+ batchConfig: config.shareBrowserContext ? config : void 0
2748
+ });
2749
+ const runner = commandOptions.rstestRunner || runRstestYamlProject;
2750
+ const exitCode = await runner({
2751
+ project,
2752
+ cwd: projectDir,
2753
+ stdio: commandOptions.stdio
2754
+ });
2755
+ const results = readProjectResults(project);
2756
+ const summaryPath = writeExecutionSummaryFile(config.summary, results);
2757
+ printExecutionFinished();
2758
+ const success = printExecutionSummary(results, summaryPath);
2759
+ return success ? exitCode : 1;
2760
+ }
2761
+ class Node {
2762
+ value;
2763
+ next;
2764
+ constructor(value){
2765
+ this.value = value;
2766
+ }
2767
+ }
2768
+ class Queue {
2769
+ #head;
2770
+ #tail;
2771
+ #size;
2772
+ constructor(){
2773
+ this.clear();
2774
+ }
2775
+ enqueue(value) {
2776
+ const node = new Node(value);
2777
+ if (this.#head) {
2778
+ this.#tail.next = node;
2779
+ this.#tail = node;
2780
+ } else {
2781
+ this.#head = node;
2782
+ this.#tail = node;
2783
+ }
2784
+ this.#size++;
2785
+ }
2786
+ dequeue() {
2787
+ const current = this.#head;
2788
+ if (!current) return;
2789
+ this.#head = this.#head.next;
2790
+ this.#size--;
2791
+ return current.value;
2792
+ }
2793
+ peek() {
2794
+ if (!this.#head) return;
2795
+ return this.#head.value;
2796
+ }
2797
+ clear() {
2798
+ this.#head = void 0;
2799
+ this.#tail = void 0;
2800
+ this.#size = 0;
2801
+ }
2802
+ get size() {
2803
+ return this.#size;
2804
+ }
2805
+ *[Symbol.iterator]() {
2806
+ let current = this.#head;
2807
+ while(current){
2808
+ yield current.value;
2809
+ current = current.next;
2810
+ }
2811
+ }
2812
+ *drain() {
2813
+ while(this.#head)yield this.dequeue();
2814
+ }
2815
+ }
2816
+ function pLimit(concurrency) {
2817
+ validateConcurrency(concurrency);
2818
+ const queue = new Queue();
2819
+ let activeCount = 0;
2820
+ const resumeNext = ()=>{
2821
+ if (activeCount < concurrency && queue.size > 0) {
2822
+ queue.dequeue()();
2823
+ activeCount++;
2824
+ }
2825
+ };
2826
+ const next = ()=>{
2827
+ activeCount--;
2828
+ resumeNext();
2829
+ };
2830
+ const run = async (function_, resolve, arguments_)=>{
2831
+ const result = (async ()=>function_(...arguments_))();
2832
+ resolve(result);
2833
+ try {
2834
+ await result;
2835
+ } catch {}
2836
+ next();
2837
+ };
2838
+ const enqueue = (function_, resolve, arguments_)=>{
2839
+ new Promise((internalResolve)=>{
2840
+ queue.enqueue(internalResolve);
2841
+ }).then(run.bind(void 0, function_, resolve, arguments_));
2842
+ (async ()=>{
2843
+ await Promise.resolve();
2844
+ if (activeCount < concurrency) resumeNext();
2845
+ })();
2846
+ };
2847
+ const generator = (function_, ...arguments_)=>new Promise((resolve)=>{
2848
+ enqueue(function_, resolve, arguments_);
2849
+ });
2850
+ Object.defineProperties(generator, {
2851
+ activeCount: {
2852
+ get: ()=>activeCount
2853
+ },
2854
+ pendingCount: {
2855
+ get: ()=>queue.size
2856
+ },
2857
+ clearQueue: {
2858
+ value () {
2859
+ queue.clear();
2860
+ }
2861
+ },
2862
+ concurrency: {
2863
+ get: ()=>concurrency,
2864
+ set (newConcurrency) {
2865
+ validateConcurrency(newConcurrency);
2866
+ concurrency = newConcurrency;
2867
+ queueMicrotask(()=>{
2868
+ while(activeCount < concurrency && queue.size > 0)resumeNext();
2869
+ });
2870
+ }
2871
+ }
2872
+ });
2873
+ return generator;
2874
+ }
2875
+ function validateConcurrency(concurrency) {
2876
+ if (!((Number.isInteger(concurrency) || concurrency === 1 / 0) && concurrency > 0)) throw new TypeError('Expected `concurrency` to be a number from 1 and up');
2877
+ }
2878
+ const debug = getDebug('create-yaml-player');
2879
+ const launchServer = async (dir)=>new Promise((resolve)=>{
2880
+ const server = createServer({
2881
+ root: dir
2882
+ });
2883
+ server.listen(0, '127.0.0.1', ()=>{
2884
+ resolve(server);
2885
+ });
2886
+ });
2887
+ function resolveReportFileName(yamlReportFileName, cliTestId, yamlTestId, fileName) {
2888
+ const baseName = yamlReportFileName ?? cliTestId ?? yamlTestId ?? fileName;
2889
+ return getReportFileName(baseName);
2890
+ }
2891
+ function buildAgentOptions(yamlAgent, reportFileName, fileName) {
2892
+ return {
2893
+ ...yamlAgent || {},
2894
+ cache: processCacheConfig(yamlAgent?.cache, fileName),
2895
+ reportFileName
2896
+ };
2897
+ }
2898
+ async function createYamlPlayer(file, script, options) {
2899
+ const yamlScript = script || parseYamlScript(readFileSync(file, 'utf-8'), file);
2900
+ const clonedYamlScript = structuredClone(yamlScript);
2901
+ const fileName = basename(file, extname(file));
2902
+ const preference = {
2903
+ headed: options?.headed,
2904
+ keepWindow: options?.keepWindow,
2905
+ reportFileName: resolveReportFileName(clonedYamlScript.agent?.reportFileName, options?.testId, clonedYamlScript.agent?.testId, fileName)
2906
+ };
2907
+ const player = new ScriptPlayer(clonedYamlScript, async ()=>{
2908
+ const freeFn = [];
2909
+ const webTarget = clonedYamlScript.web || clonedYamlScript.target;
2910
+ const targetCount = [
2911
+ void 0 !== webTarget,
2912
+ void 0 !== clonedYamlScript.android,
2913
+ void 0 !== clonedYamlScript.ios,
2914
+ void 0 !== clonedYamlScript.computer,
2915
+ void 0 !== clonedYamlScript.interface
2916
+ ].filter(Boolean).length;
2917
+ if (targetCount > 1) {
2918
+ const specifiedTargets = [
2919
+ void 0 !== webTarget ? 'web' : null,
2920
+ void 0 !== clonedYamlScript.android ? 'android' : null,
2921
+ void 0 !== clonedYamlScript.ios ? 'ios' : null,
2922
+ void 0 !== clonedYamlScript.computer ? 'computer' : null,
2923
+ void 0 !== clonedYamlScript.interface ? 'interface' : null
2924
+ ].filter(Boolean);
2925
+ throw new Error(`Only one target type can be specified, but found multiple: ${specifiedTargets.join(', ')}. Please specify only one of: web, android, ios, computer, or interface.`);
2926
+ }
2927
+ if (void 0 !== webTarget) {
2928
+ if (void 0 !== clonedYamlScript.target) console.warn("target is deprecated, please use web instead. See https://midscenejs.com/automate-with-scripts-in-yaml for more information. Sorry for the inconvenience.");
2929
+ let localServer;
2930
+ let urlToVisit;
2931
+ if (webTarget.serve) {
2932
+ node_assert('string' == typeof webTarget.url, 'url is required in serve mode');
2933
+ localServer = await launchServer(webTarget.serve);
2934
+ const serverAddress = localServer.server.address();
2935
+ freeFn.push({
2936
+ name: 'local_server',
2937
+ fn: ()=>localServer?.server.close()
2938
+ });
2939
+ urlToVisit = webTarget.url.startsWith('/') ? `http://${serverAddress?.address}:${serverAddress?.port}${webTarget.url}` : `http://${serverAddress?.address}:${serverAddress?.port}/${webTarget.url}`;
2940
+ webTarget.url = urlToVisit;
2941
+ }
2942
+ if (webTarget.cdpEndpoint && webTarget.bridgeMode) throw new Error('cdpEndpoint and bridgeMode are mutually exclusive. Please specify only one.');
2943
+ if (webTarget.cdpEndpoint) {
2944
+ const cdpBrowser = options?.browser ?? await puppeteer.connect({
2945
+ browserWSEndpoint: webTarget.cdpEndpoint,
2946
+ defaultViewport: null
2947
+ });
2948
+ if (webTarget.chromeArgs) console.warn('chromeArgs are not supported in CDP mode (browser is already running). They will be ignored.');
2949
+ const { agent, freeFn: newFreeFn } = await puppeteerAgentForTarget(webTarget, {
2950
+ ...preference,
2951
+ ...buildAgentOptions(clonedYamlScript.agent, preference.reportFileName, fileName)
2952
+ }, cdpBrowser, options?.page);
2953
+ const cleanFreeFn = newFreeFn.filter((f)=>'puppeteer_browser' !== f.name);
2954
+ if (!options?.browser) cleanFreeFn.push({
2955
+ name: 'cdp_browser_disconnect',
2956
+ fn: ()=>cdpBrowser.disconnect()
2957
+ });
2958
+ freeFn.push(...cleanFreeFn);
2959
+ return {
2960
+ agent,
2961
+ freeFn
2962
+ };
2963
+ }
2964
+ if (!webTarget.bridgeMode) {
2965
+ const { agent, freeFn: newFreeFn } = await puppeteerAgentForTarget(webTarget, {
2966
+ ...preference,
2967
+ ...buildAgentOptions(clonedYamlScript.agent, preference.reportFileName, fileName)
2968
+ }, options?.browser, options?.page);
2969
+ freeFn.push(...newFreeFn);
2970
+ return {
2971
+ agent,
2972
+ freeFn
2973
+ };
2974
+ }
2975
+ node_assert('newTabWithUrl' === webTarget.bridgeMode || 'currentTab' === webTarget.bridgeMode, `bridgeMode config value must be either "newTabWithUrl" or "currentTab", but got ${webTarget.bridgeMode}`);
2976
+ if (webTarget.userAgent || null != webTarget.viewportWidth || null != webTarget.viewportHeight || null != webTarget.deviceScaleFactor || webTarget.waitForNetworkIdle || webTarget.cookie || webTarget.chromeArgs) console.warn('puppeteer options (userAgent, viewportWidth, viewportHeight, deviceScaleFactor, waitForNetworkIdle, cookie, chromeArgs) are not supported in bridge mode. They will be ignored.');
2977
+ const agent = new AgentOverChromeBridge({
2978
+ closeNewTabsAfterDisconnect: webTarget.closeNewTabsAfterDisconnect,
2979
+ closeConflictServer: true,
2980
+ ...buildAgentOptions(clonedYamlScript.agent, preference.reportFileName, fileName)
2981
+ });
2982
+ if ('newTabWithUrl' === webTarget.bridgeMode) await agent.connectNewTabWithUrl(webTarget.url);
2983
+ else {
2984
+ if (webTarget.url) console.warn('url will be ignored in bridge mode with "currentTab"');
2985
+ await agent.connectCurrentTab();
2986
+ }
2987
+ freeFn.push({
2988
+ name: 'destroy_agent_over_chrome_bridge',
2989
+ fn: ()=>agent.destroy()
2990
+ });
2991
+ return {
2992
+ agent,
2993
+ freeFn
2994
+ };
2995
+ }
2996
+ if (void 0 !== clonedYamlScript.android) {
2997
+ const androidTarget = clonedYamlScript.android;
2998
+ const { agentFromAdbDevice } = await import("@midscene/android");
2999
+ const agent = await agentFromAdbDevice(androidTarget?.deviceId, {
3000
+ ...androidTarget,
3001
+ ...buildAgentOptions(clonedYamlScript.agent, preference.reportFileName, fileName)
3002
+ });
3003
+ if (androidTarget?.launch) await agent.launch(androidTarget.launch);
3004
+ freeFn.push({
3005
+ name: 'destroy_android_agent',
3006
+ fn: ()=>agent.destroy()
3007
+ });
3008
+ return {
3009
+ agent,
3010
+ freeFn
3011
+ };
3012
+ }
3013
+ if (void 0 !== clonedYamlScript.ios) {
3014
+ const iosTarget = clonedYamlScript.ios;
3015
+ const { agentFromWebDriverAgent } = await import("@midscene/ios");
3016
+ const agent = await agentFromWebDriverAgent({
3017
+ ...iosTarget,
3018
+ ...buildAgentOptions(clonedYamlScript.agent, preference.reportFileName, fileName)
3019
+ });
3020
+ if (iosTarget?.launch) await agent.launch(iosTarget.launch);
3021
+ freeFn.push({
3022
+ name: 'destroy_ios_agent',
3023
+ fn: ()=>agent.destroy()
3024
+ });
3025
+ return {
3026
+ agent,
3027
+ freeFn
3028
+ };
3029
+ }
3030
+ if (void 0 !== clonedYamlScript.computer) {
3031
+ const computerTarget = clonedYamlScript.computer;
3032
+ const { agentForComputer } = await import("@midscene/computer");
3033
+ const agent = await agentForComputer({
3034
+ ...computerTarget,
3035
+ ...buildAgentOptions(clonedYamlScript.agent, preference.reportFileName, fileName)
3036
+ });
3037
+ freeFn.push({
3038
+ name: 'destroy_computer_agent',
3039
+ fn: ()=>agent.destroy()
3040
+ });
3041
+ return {
3042
+ agent,
3043
+ freeFn
3044
+ };
3045
+ }
3046
+ if (void 0 !== clonedYamlScript.interface) {
3047
+ const interfaceTarget = clonedYamlScript.interface;
3048
+ const moduleSpecifier = interfaceTarget.module;
3049
+ let finalModuleSpecifier;
3050
+ if (moduleSpecifier.startsWith('./') || moduleSpecifier.startsWith('../') || node_path.isAbsolute(moduleSpecifier)) {
3051
+ const resolvedPath = join(process.cwd(), moduleSpecifier);
3052
+ finalModuleSpecifier = resolvedPath;
3053
+ } else finalModuleSpecifier = moduleSpecifier;
3054
+ debug('importing module config', interfaceTarget.module, 'with export config', interfaceTarget.export, 'final module specifier', finalModuleSpecifier);
3055
+ const importedModule = await import(finalModuleSpecifier);
3056
+ const DeviceClass = interfaceTarget.export ? importedModule[interfaceTarget.export] : importedModule.default || importedModule;
3057
+ debug('DeviceClass', DeviceClass, 'with param', interfaceTarget.param);
3058
+ const device = new DeviceClass(interfaceTarget.param || {});
3059
+ debug('creating agent from device', device);
3060
+ const agent = createAgent(device, buildAgentOptions(clonedYamlScript.agent, preference.reportFileName, fileName));
3061
+ freeFn.push({
3062
+ name: 'destroy_general_interface_agent',
3063
+ fn: ()=>{
3064
+ agent.destroy();
3065
+ }
3066
+ });
3067
+ return {
3068
+ agent,
3069
+ freeFn
3070
+ };
3071
+ }
3072
+ throw new Error('No valid interface configuration found in the yaml script, should be either "web", "android", "ios", "computer", or "interface"');
3073
+ }, void 0, file);
3074
+ return player;
3075
+ }
3076
+ var source = __webpack_require__("../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js");
3077
+ var source_default = /*#__PURE__*/ __webpack_require__.n(source);
3078
+ const isTTY = process.env.MIDSCENE_CLI_LOG_ON_NON_TTY ? false : process.stdout.isTTY;
3079
+ const indent = ' ';
3080
+ const spinnerInterval = 80;
3081
+ const spinnerFrames = [
3082
+ '◰',
3083
+ '◳',
3084
+ '◲',
3085
+ '◱'
3086
+ ];
3087
+ const currentSpinningFrame = ()=>spinnerFrames[Math.floor(Date.now() / spinnerInterval) % spinnerFrames.length];
3088
+ function indicatorForStatus(status) {
3089
+ if ('init' === status) return source_default().gray('◌');
3090
+ if ('running' === status) return source_default().yellowBright(currentSpinningFrame());
3091
+ if ('done' === status) return source_default().green('✔︎');
3092
+ if ('error' === status) return source_default().red('✘');
3093
+ }
3094
+ const contextInfo = (context)=>{
3095
+ const filePath = context.file;
3096
+ const filePathToShow = relative(process.cwd(), filePath);
3097
+ const fileNameToPrint = `${source_default().gray(`${filePathToShow}`)}`;
3098
+ const fileStatusText = indicatorForStatus(context.player.status);
3099
+ const contextActionText = void 0 === context.player.currentTaskIndex && 'running' === context.player.status ? source_default().gray('(navigating)') : '';
3100
+ const errorText = context.player.errorInSetup ? `\n${indent}${source_default().red('error:')} ${context.player.errorInSetup?.message}\n${indent}${indent}${context.player.errorInSetup?.stack}` : '';
3101
+ const outputFile = context.player.output;
3102
+ const outputText = outputFile && Object.keys(context.player.result || {}).length > 0 ? `\n${indent}${source_default().gray(`output: ${outputFile}`)}` : '';
3103
+ const reportFile = context.player.reportFile;
3104
+ const reportText = reportFile ? `\n${indent}${source_default().gray(`report: ${reportFile}`)}` : '';
3105
+ const agentStatusTip = context.player.agentStatusTip;
3106
+ const agentStatusText = agentStatusTip ? `\n${indent}${source_default().gray(`agent status: ${agentStatusTip}`)}` : '';
3107
+ const mergedText = `${fileStatusText} ${fileNameToPrint} ${contextActionText}${outputText}${reportText}${errorText}${agentStatusText}`.trim();
3108
+ return {
3109
+ fileNameToPrint,
3110
+ fileStatusText,
3111
+ contextActionText,
3112
+ outputText,
3113
+ reportText,
3114
+ mergedText
3115
+ };
3116
+ };
3117
+ const singleTaskInfo = (task)=>{
3118
+ let stepText = '';
3119
+ if ('init' === task.status) stepText = '';
3120
+ else if ('running' === task.status || 'error' === task.status) if (void 0 === task.currentStep) stepText = source_default().gray('(navigating)');
3121
+ else if ('number' == typeof task.currentStep) {
3122
+ const actionText = '';
3123
+ stepText = source_default().gray(`(task ${task.currentStep + 1}/${task.totalSteps}${actionText})`.trim());
3124
+ } else stepText = source_default().gray('(unknown task)');
3125
+ const errorText = 'error' === task.status ? `\n${indent}${source_default().gray('error:')}\n${indent}${indent}${task.error?.message}` : '';
3126
+ const statusText = indicatorForStatus(task.status);
3127
+ const mergedLine = `${statusText} ${task.name} ${stepText}${errorText}`;
3128
+ return {
3129
+ nameText: task.name,
3130
+ stepText,
3131
+ errorText,
3132
+ itemStatusText: statusText,
3133
+ mergedLine
3134
+ };
3135
+ };
3136
+ function paddingLines(lines) {
3137
+ return lines.map((line)=>`${indent}${line}`);
3138
+ }
3139
+ const contextTaskListSummary = (taskStatusArray, context)=>{
3140
+ const prefixLines = [];
3141
+ const currentLine = [];
3142
+ const suffixText = [];
3143
+ const { mergedText: fileInfo } = contextInfo(context);
3144
+ if (!context.player.errorInSetup) for (const task of taskStatusArray){
3145
+ const { mergedLine } = singleTaskInfo(task);
3146
+ if ('init' === context.player.status) suffixText.push(mergedLine);
3147
+ else if ('running' === context.player.status) currentLine.push(mergedLine);
3148
+ else if ('done' === context.player.status) prefixLines.push(mergedLine);
3149
+ else if ('error' === context.player.status) prefixLines.push(mergedLine);
3150
+ }
3151
+ const lines = [
3152
+ fileInfo
3153
+ ];
3154
+ if (prefixLines.length > 0) lines.push(...paddingLines(prefixLines));
3155
+ if (currentLine.length > 0) lines.push(...paddingLines(currentLine));
3156
+ if (suffixText.length > 0) lines.push(...paddingLines(suffixText));
3157
+ return lines.join('\n');
3158
+ };
3159
+ const copyProperty = (to, from, property, ignoreNonConfigurable)=>{
3160
+ if ('length' === property || 'prototype' === property) return;
3161
+ if ('arguments' === property || 'caller' === property) return;
3162
+ const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
3163
+ const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
3164
+ if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) return;
3165
+ Object.defineProperty(to, property, fromDescriptor);
3166
+ };
3167
+ const canCopyProperty = function(toDescriptor, fromDescriptor) {
3168
+ return void 0 === toDescriptor || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
3169
+ };
3170
+ const changePrototype = (to, from)=>{
3171
+ const fromPrototype = Object.getPrototypeOf(from);
3172
+ if (fromPrototype === Object.getPrototypeOf(to)) return;
3173
+ Object.setPrototypeOf(to, fromPrototype);
3174
+ };
3175
+ const wrappedToString = (withName, fromBody)=>`/* Wrapped ${withName}*/\n${fromBody}`;
3176
+ const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
3177
+ const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');
3178
+ const changeToString = (to, from, name)=>{
3179
+ const withName = '' === name ? '' : `with ${name.trim()}() `;
3180
+ const newToString = wrappedToString.bind(null, withName, from.toString());
3181
+ Object.defineProperty(newToString, 'name', toStringName);
3182
+ const { writable, enumerable, configurable } = toStringDescriptor;
3183
+ Object.defineProperty(to, 'toString', {
3184
+ value: newToString,
3185
+ writable,
3186
+ enumerable,
3187
+ configurable
3188
+ });
3189
+ };
3190
+ function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
3191
+ const { name } = to;
3192
+ for (const property of Reflect.ownKeys(from))copyProperty(to, from, property, ignoreNonConfigurable);
3193
+ changePrototype(to, from);
3194
+ changeToString(to, from, name);
3195
+ return to;
3196
+ }
3197
+ const calledFunctions = new WeakMap();
3198
+ const onetime_onetime = (function_, options = {})=>{
3199
+ if ('function' != typeof function_) throw new TypeError('Expected a function');
3200
+ let returnValue;
3201
+ let callCount = 0;
3202
+ const functionName = function_.displayName || function_.name || '<anonymous>';
3203
+ const onetime = function(...arguments_) {
3204
+ calledFunctions.set(onetime, ++callCount);
3205
+ if (1 === callCount) {
3206
+ returnValue = function_.apply(this, arguments_);
3207
+ function_ = void 0;
3208
+ } else if (true === options.throw) throw new Error(`Function \`${functionName}\` can only be called once`);
3209
+ return returnValue;
3210
+ };
3211
+ mimicFunction(onetime, function_);
3212
+ calledFunctions.set(onetime, callCount);
3213
+ return onetime;
3214
+ };
3215
+ onetime_onetime.callCount = (function_)=>{
3216
+ if (!calledFunctions.has(function_)) throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
3217
+ return calledFunctions.get(function_);
3218
+ };
3219
+ const node_modules_onetime = onetime_onetime;
3220
+ const signals = [];
3221
+ signals.push('SIGHUP', 'SIGINT', 'SIGTERM');
3222
+ if ('win32' !== process.platform) signals.push('SIGALRM', 'SIGABRT', 'SIGVTALRM', 'SIGXCPU', 'SIGXFSZ', 'SIGUSR2', 'SIGTRAP', 'SIGSYS', 'SIGQUIT', 'SIGIOT');
3223
+ if ('linux' === process.platform) signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT');
3224
+ const processOk = (process1)=>!!process1 && 'object' == typeof process1 && 'function' == typeof process1.removeListener && 'function' == typeof process1.emit && 'function' == typeof process1.reallyExit && 'function' == typeof process1.listeners && 'function' == typeof process1.kill && 'number' == typeof process1.pid && 'function' == typeof process1.on;
3225
+ const kExitEmitter = Symbol.for('signal-exit emitter');
3226
+ const global = globalThis;
3227
+ const ObjectDefineProperty = Object.defineProperty.bind(Object);
3228
+ class Emitter {
3229
+ emitted = {
3230
+ afterExit: false,
3231
+ exit: false
3232
+ };
3233
+ listeners = {
3234
+ afterExit: [],
3235
+ exit: []
3236
+ };
3237
+ count = 0;
3238
+ id = Math.random();
3239
+ constructor(){
3240
+ if (global[kExitEmitter]) return global[kExitEmitter];
3241
+ ObjectDefineProperty(global, kExitEmitter, {
3242
+ value: this,
3243
+ writable: false,
3244
+ enumerable: false,
3245
+ configurable: false
3246
+ });
3247
+ }
3248
+ on(ev, fn) {
3249
+ this.listeners[ev].push(fn);
3250
+ }
3251
+ removeListener(ev, fn) {
3252
+ const list = this.listeners[ev];
3253
+ const i = list.indexOf(fn);
3254
+ if (-1 === i) return;
3255
+ if (0 === i && 1 === list.length) list.length = 0;
3256
+ else list.splice(i, 1);
3257
+ }
3258
+ emit(ev, code, signal) {
3259
+ if (this.emitted[ev]) return false;
3260
+ this.emitted[ev] = true;
3261
+ let ret = false;
3262
+ for (const fn of this.listeners[ev])ret = true === fn(code, signal) || ret;
3263
+ if ('exit' === ev) ret = this.emit('afterExit', code, signal) || ret;
3264
+ return ret;
3265
+ }
3266
+ }
3267
+ class SignalExitBase {
3268
+ }
3269
+ const signalExitWrap = (handler)=>({
3270
+ onExit (cb, opts) {
3271
+ return handler.onExit(cb, opts);
3272
+ },
3273
+ load () {
3274
+ return handler.load();
3275
+ },
3276
+ unload () {
3277
+ return handler.unload();
3278
+ }
3279
+ });
3280
+ class SignalExitFallback extends SignalExitBase {
3281
+ onExit() {
3282
+ return ()=>{};
3283
+ }
3284
+ load() {}
3285
+ unload() {}
3286
+ }
3287
+ class SignalExit extends SignalExitBase {
3288
+ #hupSig = 'win32' === mjs_process.platform ? 'SIGINT' : 'SIGHUP';
3289
+ #emitter = new Emitter();
3290
+ #process;
3291
+ #originalProcessEmit;
3292
+ #originalProcessReallyExit;
3293
+ #sigListeners = {};
3294
+ #loaded = false;
3295
+ constructor(process1){
3296
+ super();
3297
+ this.#process = process1;
3298
+ this.#sigListeners = {};
3299
+ for (const sig of signals)this.#sigListeners[sig] = ()=>{
3300
+ const listeners = this.#process.listeners(sig);
3301
+ let { count } = this.#emitter;
3302
+ const p = process1;
3303
+ if ('object' == typeof p.__signal_exit_emitter__ && 'number' == typeof p.__signal_exit_emitter__.count) count += p.__signal_exit_emitter__.count;
3304
+ if (listeners.length === count) {
3305
+ this.unload();
3306
+ const ret = this.#emitter.emit('exit', null, sig);
3307
+ const s = 'SIGHUP' === sig ? this.#hupSig : sig;
3308
+ if (!ret) process1.kill(process1.pid, s);
3309
+ }
3310
+ };
3311
+ this.#originalProcessReallyExit = process1.reallyExit;
3312
+ this.#originalProcessEmit = process1.emit;
3313
+ }
3314
+ onExit(cb, opts) {
3315
+ if (!processOk(this.#process)) return ()=>{};
3316
+ if (false === this.#loaded) this.load();
3317
+ const ev = opts?.alwaysLast ? 'afterExit' : 'exit';
3318
+ this.#emitter.on(ev, cb);
3319
+ return ()=>{
3320
+ this.#emitter.removeListener(ev, cb);
3321
+ if (0 === this.#emitter.listeners['exit'].length && 0 === this.#emitter.listeners['afterExit'].length) this.unload();
3322
+ };
3323
+ }
3324
+ load() {
3325
+ if (this.#loaded) return;
3326
+ this.#loaded = true;
3327
+ this.#emitter.count += 1;
3328
+ for (const sig of signals)try {
3329
+ const fn = this.#sigListeners[sig];
3330
+ if (fn) this.#process.on(sig, fn);
3331
+ } catch (_) {}
3332
+ this.#process.emit = (ev, ...a)=>this.#processEmit(ev, ...a);
3333
+ this.#process.reallyExit = (code)=>this.#processReallyExit(code);
3334
+ }
3335
+ unload() {
3336
+ if (!this.#loaded) return;
3337
+ this.#loaded = false;
3338
+ signals.forEach((sig)=>{
3339
+ const listener = this.#sigListeners[sig];
3340
+ if (!listener) throw new Error('Listener not defined for signal: ' + sig);
3341
+ try {
3342
+ this.#process.removeListener(sig, listener);
3343
+ } catch (_) {}
3344
+ });
3345
+ this.#process.emit = this.#originalProcessEmit;
3346
+ this.#process.reallyExit = this.#originalProcessReallyExit;
3347
+ this.#emitter.count -= 1;
3348
+ }
3349
+ #processReallyExit(code) {
3350
+ if (!processOk(this.#process)) return 0;
3351
+ this.#process.exitCode = code || 0;
3352
+ this.#emitter.emit('exit', this.#process.exitCode, null);
3353
+ return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
3354
+ }
3355
+ #processEmit(ev, ...args) {
3356
+ const og = this.#originalProcessEmit;
3357
+ if (!('exit' === ev && processOk(this.#process))) return og.call(this.#process, ev, ...args);
3358
+ {
3359
+ if ('number' == typeof args[0]) this.#process.exitCode = args[0];
3360
+ const ret = og.call(this.#process, ev, ...args);
3361
+ this.#emitter.emit('exit', this.#process.exitCode, null);
3362
+ return ret;
3363
+ }
3364
+ }
3365
+ }
3366
+ const mjs_process = globalThis.process;
3367
+ const { onExit, load, unload } = signalExitWrap(processOk(mjs_process) ? new SignalExit(mjs_process) : new SignalExitFallback());
3368
+ const terminal = node_process.stderr.isTTY ? node_process.stderr : node_process.stdout.isTTY ? node_process.stdout : void 0;
3369
+ const restoreCursor = terminal ? node_modules_onetime(()=>{
3370
+ onExit(()=>{
3371
+ terminal.write('\u001B[?25h');
3372
+ }, {
3373
+ alwaysLast: true
3374
+ });
3375
+ }) : ()=>{};
3376
+ const restore_cursor = restoreCursor;
3377
+ function _define_property(obj, key, value) {
3378
+ if (key in obj) Object.defineProperty(obj, key, {
3379
+ value: value,
3380
+ enumerable: true,
3381
+ configurable: true,
3382
+ writable: true
3383
+ });
3384
+ else obj[key] = value;
3385
+ return obj;
3386
+ }
3387
+ const DEFAULT_RENDER_INTERVAL = 160;
3388
+ const ESC = '\x1B[';
3389
+ const CLEAR_LINE = `${ESC}K`;
3390
+ const MOVE_CURSOR_ONE_ROW_UP = `${ESC}1A`;
3391
+ const HIDE_CURSOR = `${ESC}?25l`;
3392
+ const SHOW_CURSOR = `${ESC}?25h`;
3393
+ const SYNC_START = `${ESC}?2026h`;
3394
+ const SYNC_END = `${ESC}?2026l`;
3395
+ class TTYWindowRenderer {
3396
+ start() {
3397
+ this.finished = false;
3398
+ this.renderInterval = setInterval(()=>this.flushBuffer(), this.options.interval);
3399
+ }
3400
+ stop() {
3401
+ this.flushBuffer();
3402
+ this.write(SHOW_CURSOR, 'output');
3403
+ this.cleanups.splice(0).map((fn)=>fn());
3404
+ clearInterval(this.renderInterval);
3405
+ }
3406
+ finish() {
3407
+ this.finished = true;
3408
+ this.flushBuffer();
3409
+ clearInterval(this.renderInterval);
3410
+ }
3411
+ flushBuffer() {
3412
+ if (0 === this.buffer.length) return this.render();
3413
+ let current;
3414
+ for (const next of this.buffer.splice(0)){
3415
+ if (!current) {
3416
+ current = next;
3417
+ continue;
3418
+ }
3419
+ if (current.type !== next.type) {
3420
+ this.render(current.message, current.type);
3421
+ current = next;
3422
+ continue;
3423
+ }
3424
+ current.message += next.message;
3425
+ }
3426
+ if (current) this.render(current?.message, current?.type);
3427
+ }
3428
+ render(message, type = 'output') {
3429
+ if (this.finished) {
3430
+ this.clearWindow();
3431
+ return this.write(message || '', type);
3432
+ }
3433
+ const windowContent = this.options.getWindow();
3434
+ const rowCount = getRenderedRowCount(windowContent, this.options.outputStream);
3435
+ let padding = this.windowHeight - rowCount;
3436
+ if (padding > 0 && message) padding -= getRenderedRowCount([
3437
+ message
3438
+ ], this.options.outputStream);
3439
+ this.write(SYNC_START);
3440
+ this.clearWindow();
3441
+ if (message) this.write(message, type);
3442
+ if (padding > 0) this.write('\n'.repeat(padding));
3443
+ this.write(windowContent.join('\n'));
3444
+ this.write(SYNC_END);
3445
+ this.windowHeight = rowCount + Math.max(0, padding);
3446
+ }
3447
+ clearWindow() {
3448
+ if (0 === this.windowHeight) return;
3449
+ this.write(CLEAR_LINE);
3450
+ for(let i = 1; i < this.windowHeight; i++)this.write(`${MOVE_CURSOR_ONE_ROW_UP}${CLEAR_LINE}`);
3451
+ this.windowHeight = 0;
3452
+ }
3453
+ interceptStream(stream, type) {
3454
+ const original = stream.write;
3455
+ stream.write = (chunk, _, callback)=>{
3456
+ if (chunk) if (this.finished) this.write(chunk.toString(), type);
3457
+ else this.buffer.push({
3458
+ type,
3459
+ message: chunk.toString()
3460
+ });
3461
+ callback?.();
3462
+ };
3463
+ return function() {
3464
+ stream.write = original;
3465
+ };
3466
+ }
3467
+ write(message, type = 'output') {
3468
+ this.streams[type](message);
3469
+ }
3470
+ constructor(options){
3471
+ _define_property(this, "options", void 0);
3472
+ _define_property(this, "streams", void 0);
3473
+ _define_property(this, "buffer", []);
3474
+ _define_property(this, "renderInterval", void 0);
3475
+ _define_property(this, "windowHeight", 0);
3476
+ _define_property(this, "finished", false);
3477
+ _define_property(this, "cleanups", []);
3478
+ this.options = {
3479
+ interval: DEFAULT_RENDER_INTERVAL,
3480
+ ...options
3481
+ };
3482
+ this.streams = {
3483
+ output: options.outputStream.write.bind(options.outputStream),
3484
+ error: options.errorStream.write.bind(options.errorStream)
3485
+ };
3486
+ this.cleanups.push(this.interceptStream(process.stdout, 'output'), this.interceptStream(process.stderr, 'error'));
3487
+ restore_cursor();
3488
+ this.write(HIDE_CURSOR, 'output');
3489
+ this.start();
3490
+ }
3491
+ }
3492
+ function getRenderedRowCount(contents, stream) {
3493
+ let count = 0;
3494
+ const columns = 'columns' in stream ? stream.columns : 80;
3495
+ for (const content of contents){
3496
+ const rows = content.split('\n');
3497
+ for (const row of rows){
3498
+ const text = stripVTControlCharacters(row);
3499
+ count += Math.max(1, Math.ceil(text.length / columns));
3500
+ }
3501
+ }
3502
+ return count;
3503
+ }
3504
+ function yaml_batch_executor_define_property(obj, key, value) {
3505
+ if (key in obj) Object.defineProperty(obj, key, {
3506
+ value: value,
3507
+ enumerable: true,
3508
+ configurable: true,
3509
+ writable: true
3510
+ });
3511
+ else obj[key] = value;
3512
+ return obj;
3513
+ }
3514
+ class YamlBatchExecutor {
3515
+ async run(options = {}) {
3516
+ const generateSummary = options.generateSummary ?? true;
3517
+ const shouldPrintExecutionPlan = options.printExecutionPlan ?? true;
3518
+ const { keepWindow, headed } = this.config;
3519
+ if (shouldPrintExecutionPlan) printExecutionPlan(this.config);
3520
+ const fileContextList = [];
3521
+ let browser = null;
3522
+ let sharedPage = null;
3523
+ try {
3524
+ for (const file of this.config.files){
3525
+ const fileConfig = await this.loadFileConfig(file);
3526
+ const context = await this.createFileContext(file, fileConfig, {
3527
+ headed,
3528
+ keepWindow
3529
+ });
3530
+ fileContextList.push(context);
3531
+ }
3532
+ const needsBrowser = fileContextList.some((ctx)=>Object.keys(ctx.executionConfig.web || ctx.executionConfig.target || {}).length > 0);
3533
+ if (needsBrowser && this.config.shareBrowserContext) {
3534
+ const globalWebConfig = this.config.globalConfig?.web;
3535
+ if (globalWebConfig?.cdpEndpoint) browser = await puppeteer.connect({
3536
+ browserWSEndpoint: globalWebConfig.cdpEndpoint,
3537
+ defaultViewport: null
3538
+ });
3539
+ else {
3540
+ const width = globalWebConfig?.viewportWidth ?? defaultViewportWidth;
3541
+ const height = globalWebConfig?.viewportHeight ?? defaultViewportHeight;
3542
+ const args = buildChromeArgs({
3543
+ userAgent: globalWebConfig?.userAgent,
3544
+ windowSize: headed ? {
3545
+ width,
3546
+ height
3547
+ } : void 0,
3548
+ chromeArgs: globalWebConfig?.chromeArgs
3549
+ });
3550
+ browser = await puppeteer.launch({
3551
+ headless: !headed,
3552
+ defaultViewport: headed ? null : {
3553
+ width,
3554
+ height
3555
+ },
3556
+ args,
3557
+ acceptInsecureCerts: globalWebConfig?.acceptInsecureCerts
3558
+ });
3559
+ }
3560
+ sharedPage = await browser.newPage();
3561
+ for (const context of fileContextList){
3562
+ context.options.browser = browser;
3563
+ context.options.page = sharedPage;
3564
+ }
3565
+ }
3566
+ const { executedResults, notExecutedContexts } = await this.executeFiles(fileContextList);
3567
+ this.results = await this.processResults(executedResults, notExecutedContexts);
3568
+ } finally{
3569
+ if (browser && !this.config.keepWindow) {
3570
+ const isCdp = !!this.config.globalConfig?.web?.cdpEndpoint;
3571
+ if (isCdp) browser.disconnect();
3572
+ else await browser.close();
3573
+ }
3574
+ if (generateSummary) await this.generateOutputIndex();
3575
+ }
3576
+ return this.results;
3577
+ }
3578
+ async createFileContext(file, fileConfig, options) {
3579
+ const { globalConfig } = this.config;
3580
+ const clonedFileConfig = JSON.parse(JSON.stringify(fileConfig));
3581
+ if (clonedFileConfig.target) {
3582
+ clonedFileConfig.web = {
3583
+ ...clonedFileConfig.target,
3584
+ ...clonedFileConfig.web
3585
+ };
3586
+ delete clonedFileConfig.target;
3587
+ }
3588
+ if (globalConfig?.target) {
3589
+ globalConfig.web = {
3590
+ ...globalConfig.target,
3591
+ ...globalConfig.web
3592
+ };
3593
+ delete globalConfig.target;
3594
+ }
3595
+ const executionConfig = lodash_merge(clonedFileConfig, globalConfig);
3596
+ return {
3597
+ file,
3598
+ executionConfig,
3599
+ options
3600
+ };
3601
+ }
3602
+ async executeFiles(fileContextList) {
3603
+ const executedResults = [];
3604
+ const notExecutedContexts = [];
3605
+ const allFileContexts = [];
3606
+ for (const context of fileContextList){
3607
+ const player = await createYamlPlayer(context.file, context.executionConfig, context.options);
3608
+ allFileContexts.push({
3609
+ file: context.file,
3610
+ player
3611
+ });
3612
+ }
3613
+ let ttyRenderer;
3614
+ if (isTTY) {
3615
+ const summaryContents = ()=>{
3616
+ const summary = [
3617
+ ''
3618
+ ];
3619
+ for (const context of allFileContexts)summary.push(contextTaskListSummary(context.player.taskStatusList, context));
3620
+ summary.push('');
3621
+ return summary;
3622
+ };
3623
+ ttyRenderer = new TTYWindowRenderer({
3624
+ outputStream: process.stdout,
3625
+ errorStream: process.stderr,
3626
+ getWindow: summaryContents,
3627
+ interval: spinnerInterval
3628
+ });
3629
+ ttyRenderer.start();
3630
+ }
3631
+ try {
3632
+ const executeFile = async (context)=>{
3633
+ const allFileContext = allFileContexts.find((c)=>c.file === context.file);
3634
+ if (!allFileContext) throw new Error(`Player not found for file: ${context.file}`);
3635
+ if (!isTTY) {
3636
+ const { mergedText } = contextInfo(allFileContext);
3637
+ console.log(mergedText);
3638
+ }
3639
+ if (context.outputPath) allFileContext.player.output = context.outputPath;
3640
+ const startTime = Date.now();
3641
+ await allFileContext.player.run();
3642
+ const endTime = Date.now();
3643
+ const duration = endTime - startTime;
3644
+ const executedContext = {
3645
+ file: context.file,
3646
+ player: allFileContext.player,
3647
+ duration
3648
+ };
3649
+ if (!isTTY) console.log(contextTaskListSummary(allFileContext.player.taskStatusList, executedContext));
3650
+ return executedContext;
3651
+ };
3652
+ await this.executeConcurrently(fileContextList, executeFile, executedResults, notExecutedContexts);
3653
+ if (!isTTY) {
3654
+ console.log('\n📋 Execution Results:');
3655
+ for (const context of executedResults)console.log(contextTaskListSummary(context.player.taskStatusList, context));
3656
+ }
3657
+ } finally{
3658
+ if (ttyRenderer) ttyRenderer.stop();
3659
+ }
3660
+ return {
3661
+ executedResults,
3662
+ notExecutedContexts
3663
+ };
3664
+ }
3665
+ async executeConcurrently(fileContextList, executeFile, executedResults, notExecutedContexts) {
3666
+ const limit = pLimit(this.config.concurrent);
3667
+ if (this.config.continueOnError) {
3668
+ const tasks = fileContextList.map((context)=>limit(async ()=>{
3669
+ const executedContext = await executeFile(context);
3670
+ executedResults.push(executedContext);
3671
+ }));
3672
+ await Promise.allSettled(tasks);
3673
+ } else {
3674
+ let shouldStop = false;
3675
+ const stopLock = {
3676
+ value: false
3677
+ };
3678
+ const tasks = fileContextList.map((context)=>limit(async ()=>{
3679
+ if (stopLock.value) return void notExecutedContexts.push({
3680
+ file: context.file,
3681
+ player: null
3682
+ });
3683
+ const executedContext = await executeFile(context);
3684
+ executedResults.push(executedContext);
3685
+ if ('error' === executedContext.player.status && !stopLock.value) {
3686
+ stopLock.value = true;
3687
+ shouldStop = true;
3688
+ }
3689
+ }));
3690
+ await Promise.allSettled(tasks);
3691
+ if (shouldStop) {
3692
+ for (const context of fileContextList)if (!executedResults.some((r)=>r.file === context.file) && !notExecutedContexts.some((ctx)=>ctx.file === context.file)) notExecutedContexts.push({
3693
+ file: context.file,
3694
+ player: null
3695
+ });
3696
+ }
3697
+ }
3698
+ }
3699
+ async processResults(executedContexts, notExecutedContexts) {
3700
+ const results = [];
3701
+ for (const context of executedContexts){
3702
+ const { file, player, duration } = context;
3703
+ results.push(createExecutedYamlResult({
3704
+ file,
3705
+ player,
3706
+ duration
3707
+ }));
3708
+ }
3709
+ for (const context of notExecutedContexts)results.push(createNotExecutedYamlResult(context.file));
3710
+ return results;
3711
+ }
3712
+ async loadFileConfig(file) {
3713
+ const content = readFileSync(file, 'utf8');
3714
+ return parseYamlScript(content, file);
3715
+ }
3716
+ async generateOutputIndex() {
3717
+ try {
3718
+ writeExecutionSummaryFile(this.config.summary, this.results);
3719
+ printExecutionFinished();
3720
+ } catch (error) {
3721
+ console.error('Failed to generate output index:', error);
3722
+ }
3723
+ }
3724
+ constructor(config){
3725
+ yaml_batch_executor_define_property(this, "config", void 0);
3726
+ yaml_batch_executor_define_property(this, "results", []);
3727
+ this.config = config;
3728
+ }
3729
+ }
3730
+ async function runYamlBatch(config, options = {}) {
3731
+ return new YamlBatchExecutor(config).run(options);
3732
+ }
3733
+ const writeResultFile = (resultFile, data)=>{
3734
+ mkdirSync(dirname(resultFile), {
3735
+ recursive: true
3736
+ });
3737
+ writeFileSync(resultFile, JSON.stringify(data, null, 2));
3738
+ };
3739
+ const batchFailureMessage = (results)=>{
3740
+ const failed = results.filter((result)=>!result.success);
3741
+ return failed.map((result)=>`${result.file}: ${result.error || result.resultType}`).join('\n');
3742
+ };
3743
+ async function runYamlBatchInRstest(options) {
3744
+ const results = await runYamlBatch(options.config, {
3745
+ generateSummary: false,
3746
+ printExecutionPlan: false
3747
+ });
3748
+ for (const result of results){
3749
+ const resultFile = options.resultFiles[result.file] || options.resultFiles[external_node_path_resolve(result.file)];
3750
+ if (resultFile) writeResultFile(resultFile, result);
3751
+ }
3752
+ if (results.some((result)=>!result.success)) throw new Error(batchFailureMessage(results));
3753
+ return results;
3754
+ }
3755
+ const taskErrorMessage = (task)=>{
3756
+ if (task.error?.message) return task.error.message;
3757
+ if ('error' === task.status) return `Task "${task.name}" failed`;
3758
+ };
3759
+ const cloneJson = (value)=>JSON.parse(JSON.stringify(value));
3760
+ const normalizeTargetConfig = (config)=>{
3761
+ if (config.target) {
3762
+ config.web = {
3763
+ ...config.target,
3764
+ ...config.web
3765
+ };
3766
+ config.target = void 0;
3767
+ }
3768
+ };
3769
+ const createExecutionConfig = (file, globalConfig)=>{
3770
+ const content = readFileSync(file, 'utf8');
3771
+ const fileConfig = cloneJson(parseYamlScript(content, file));
3772
+ normalizeTargetConfig(fileConfig);
3773
+ const clonedGlobalConfig = cloneJson(globalConfig);
3774
+ normalizeTargetConfig(clonedGlobalConfig);
3775
+ return lodash_merge(fileConfig, clonedGlobalConfig);
3776
+ };
3777
+ const getYamlPlayerFailure = (player)=>{
3778
+ if (player.errorInSetup) return player.errorInSetup;
3779
+ const failedMessages = player.taskStatusList?.map(taskErrorMessage).filter(Boolean) || [];
3780
+ if ('error' === player.status || failedMessages.length > 0) {
3781
+ const details = failedMessages.length ? failedMessages.join('; ') : 'YAML case failed';
3782
+ const reportLine = player.reportFile ? `\nReport: ${player.reportFile}` : '';
3783
+ const outputLine = player.output ? `\nOutput: ${player.output}` : '';
3784
+ return new Error(`${details}${reportLine}${outputLine}`);
3785
+ }
3786
+ };
3787
+ const createYamlCaseResult = (file, player, duration)=>{
3788
+ const hasFailedTasks = player.taskStatusList?.some((task)=>'error' === task.status) ?? false;
3789
+ const hasPlayerError = 'error' === player.status;
3790
+ const outputPath = player.output && existsSync(player.output) ? player.output : void 0;
3791
+ const reportFile = player.reportFile || void 0;
3792
+ let errorMessage;
3793
+ if (player.errorInSetup?.message) errorMessage = player.errorInSetup.message;
3794
+ else if (hasPlayerError || hasFailedTasks) {
3795
+ const taskErrors = player.taskStatusList?.filter((task)=>'error' === task.status && task.error?.message).map((task)=>task.error.message);
3796
+ errorMessage = taskErrors && taskErrors.length > 0 ? taskErrors.join('; ') : hasPlayerError ? 'Execution failed' : 'Some tasks failed';
3797
+ }
3798
+ const resultType = hasPlayerError ? 'failed' : hasFailedTasks ? 'partialFailed' : 'success';
3799
+ return {
3800
+ file,
3801
+ success: 'success' === resultType,
3802
+ executed: true,
3803
+ output: outputPath,
3804
+ report: reportFile,
3805
+ duration,
3806
+ resultType,
3807
+ error: errorMessage
3808
+ };
3809
+ };
3810
+ const createYamlCaseFailure = (result)=>{
3811
+ const reportLine = result.report ? `\nReport: ${result.report}` : '';
3812
+ const outputLine = result.output ? `\nOutput: ${result.output}` : '';
3813
+ return new Error(`${result.error || 'YAML case failed'}${reportLine}${outputLine}`);
3814
+ };
3815
+ async function runYamlCaseResult(options) {
3816
+ const file = external_node_path_resolve(options.file);
3817
+ const startTime = Date.now();
3818
+ const executionConfig = options.executionConfig || (options.globalConfig ? createExecutionConfig(file, options.globalConfig) : void 0);
3819
+ const player = await createYamlPlayer(file, executionConfig, {
3820
+ headed: options.headed,
3821
+ keepWindow: options.keepWindow
3822
+ });
3823
+ await player.run();
3824
+ return createYamlCaseResult(file, player, Date.now() - startTime);
3825
+ }
3826
+ async function runYamlCase(options) {
3827
+ const result = await runYamlCaseResult(options);
3828
+ if (!result.success) throw createYamlCaseFailure(result);
3829
+ return {
3830
+ file: result.file,
3831
+ output: result.output || void 0,
3832
+ report: result.report,
3833
+ duration: result.duration || 0
3834
+ };
3835
+ }
3836
+ const errorMessageOf = (error)=>error instanceof Error ? error.message : String(error);
3837
+ const rstest_entry_writeResultFile = (resultFile, data)=>{
3838
+ mkdirSync(dirname(resultFile), {
3839
+ recursive: true
3840
+ });
3841
+ writeFileSync(resultFile, JSON.stringify(data, null, 2));
3842
+ };
3843
+ const createRuntimeFailureResult = (file, startTime, error)=>({
3844
+ file,
3845
+ success: false,
3846
+ executed: true,
3847
+ duration: Date.now() - startTime,
3848
+ resultType: 'failed',
3849
+ error: errorMessageOf(error)
3850
+ });
3851
+ function defineYamlCaseTest(options) {
3852
+ test(options.testName, async ()=>{
3853
+ const file = external_node_path_resolve(options.yamlFile);
3854
+ const startTime = Date.now();
3855
+ let result;
3856
+ try {
3857
+ result = await runYamlCaseResult({
3858
+ ...options.caseOptions,
3859
+ ...options.webRuntimeOptions,
3860
+ file
3861
+ });
3862
+ rstest_entry_writeResultFile(options.resultFile, result);
3863
+ if (!result.success && 'partialFailed' !== result.resultType) throw createYamlCaseFailure(result);
3864
+ } catch (error) {
3865
+ if (!result) rstest_entry_writeResultFile(options.resultFile, createRuntimeFailureResult(file, startTime, error));
3866
+ throw error;
3867
+ }
3868
+ });
3869
+ }
3870
+ function defineYamlBatchTest(options) {
3871
+ test(options.testName, async ()=>{
3872
+ await runYamlBatchInRstest({
3873
+ config: options.config,
3874
+ resultFiles: options.resultFiles
3875
+ });
3876
+ });
3877
+ }
3878
+ export { createRstestYamlProject, createYamlCaseFailure, createYamlCaseResult, defineYamlBatchTest, defineYamlCaseTest, getYamlPlayerFailure, resolveRstestCoreImportPath, resolveTestName, runFrameworkTestConfig, runRstestYamlProject, runYamlBatchInRstest, runYamlCase, runYamlCaseResult };
3879
+
3880
+ //# sourceMappingURL=index.mjs.map