@lvce-editor/panel-worker 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1477 @@
1
+ const normalizeLine = line => {
2
+ if (line.startsWith('Error: ')) {
3
+ return line.slice('Error: '.length);
4
+ }
5
+ if (line.startsWith('VError: ')) {
6
+ return line.slice('VError: '.length);
7
+ }
8
+ return line;
9
+ };
10
+ const getCombinedMessage = (error, message) => {
11
+ const stringifiedError = normalizeLine(`${error}`);
12
+ if (message) {
13
+ return `${message}: ${stringifiedError}`;
14
+ }
15
+ return stringifiedError;
16
+ };
17
+ const NewLine$2 = '\n';
18
+ const getNewLineIndex$1 = (string, startIndex = undefined) => {
19
+ return string.indexOf(NewLine$2, startIndex);
20
+ };
21
+ const mergeStacks = (parent, child) => {
22
+ if (!child) {
23
+ return parent;
24
+ }
25
+ const parentNewLineIndex = getNewLineIndex$1(parent);
26
+ const childNewLineIndex = getNewLineIndex$1(child);
27
+ if (childNewLineIndex === -1) {
28
+ return parent;
29
+ }
30
+ const parentFirstLine = parent.slice(0, parentNewLineIndex);
31
+ const childRest = child.slice(childNewLineIndex);
32
+ const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
33
+ if (parentFirstLine.includes(childFirstLine)) {
34
+ return parentFirstLine + childRest;
35
+ }
36
+ return child;
37
+ };
38
+ class VError extends Error {
39
+ constructor(error, message) {
40
+ const combinedMessage = getCombinedMessage(error, message);
41
+ super(combinedMessage);
42
+ this.name = 'VError';
43
+ if (error instanceof Error) {
44
+ this.stack = mergeStacks(this.stack, error.stack);
45
+ }
46
+ if (error.codeFrame) {
47
+ // @ts-ignore
48
+ this.codeFrame = error.codeFrame;
49
+ }
50
+ if (error.code) {
51
+ // @ts-ignore
52
+ this.code = error.code;
53
+ }
54
+ }
55
+ }
56
+
57
+ const isMessagePort = value => {
58
+ return value && value instanceof MessagePort;
59
+ };
60
+ const isMessagePortMain = value => {
61
+ return value && value.constructor && value.constructor.name === 'MessagePortMain';
62
+ };
63
+ const isOffscreenCanvas = value => {
64
+ return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
65
+ };
66
+ const isInstanceOf = (value, constructorName) => {
67
+ return value?.constructor?.name === constructorName;
68
+ };
69
+ const isSocket = value => {
70
+ return isInstanceOf(value, 'Socket');
71
+ };
72
+ const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
73
+ const isTransferrable = value => {
74
+ for (const fn of transferrables) {
75
+ if (fn(value)) {
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ };
81
+ const walkValue = (value, transferrables, isTransferrable) => {
82
+ if (!value) {
83
+ return;
84
+ }
85
+ if (isTransferrable(value)) {
86
+ transferrables.push(value);
87
+ return;
88
+ }
89
+ if (Array.isArray(value)) {
90
+ for (const item of value) {
91
+ walkValue(item, transferrables, isTransferrable);
92
+ }
93
+ return;
94
+ }
95
+ if (typeof value === 'object') {
96
+ for (const property of Object.values(value)) {
97
+ walkValue(property, transferrables, isTransferrable);
98
+ }
99
+ return;
100
+ }
101
+ };
102
+ const getTransferrables = value => {
103
+ const transferrables = [];
104
+ walkValue(value, transferrables, isTransferrable);
105
+ return transferrables;
106
+ };
107
+ const attachEvents = that => {
108
+ const handleMessage = (...args) => {
109
+ const data = that.getData(...args);
110
+ that.dispatchEvent(new MessageEvent('message', {
111
+ data
112
+ }));
113
+ };
114
+ that.onMessage(handleMessage);
115
+ const handleClose = event => {
116
+ that.dispatchEvent(new Event('close'));
117
+ };
118
+ that.onClose(handleClose);
119
+ };
120
+ class Ipc extends EventTarget {
121
+ constructor(rawIpc) {
122
+ super();
123
+ this._rawIpc = rawIpc;
124
+ attachEvents(this);
125
+ }
126
+ }
127
+ const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
128
+ const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
129
+ const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
130
+ const NewLine$1 = '\n';
131
+ const joinLines$1 = lines => {
132
+ return lines.join(NewLine$1);
133
+ };
134
+ const RE_AT = /^\s+at/;
135
+ const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
136
+ const isNormalStackLine = line => {
137
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
138
+ };
139
+ const getDetails = lines => {
140
+ const index = lines.findIndex(isNormalStackLine);
141
+ if (index === -1) {
142
+ return {
143
+ actualMessage: joinLines$1(lines),
144
+ rest: []
145
+ };
146
+ }
147
+ let lastIndex = index - 1;
148
+ while (++lastIndex < lines.length) {
149
+ if (!isNormalStackLine(lines[lastIndex])) {
150
+ break;
151
+ }
152
+ }
153
+ return {
154
+ actualMessage: lines[index - 1],
155
+ rest: lines.slice(index, lastIndex)
156
+ };
157
+ };
158
+ const splitLines$1 = lines => {
159
+ return lines.split(NewLine$1);
160
+ };
161
+ const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
162
+ const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
163
+ const isMessageCodeBlockStartIndex = line => {
164
+ return RE_MESSAGE_CODE_BLOCK_START.test(line);
165
+ };
166
+ const isMessageCodeBlockEndIndex = line => {
167
+ return RE_MESSAGE_CODE_BLOCK_END.test(line);
168
+ };
169
+ const getMessageCodeBlock = stderr => {
170
+ const lines = splitLines$1(stderr);
171
+ const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
172
+ const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
173
+ const relevantLines = lines.slice(startIndex, endIndex);
174
+ const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
175
+ return relevantMessage;
176
+ };
177
+ const isModuleNotFoundMessage = line => {
178
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
179
+ };
180
+ const getModuleNotFoundError = stderr => {
181
+ const lines = splitLines$1(stderr);
182
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
183
+ const message = lines[messageIndex];
184
+ return {
185
+ code: ERR_MODULE_NOT_FOUND,
186
+ message
187
+ };
188
+ };
189
+ const isModuleNotFoundError = stderr => {
190
+ if (!stderr) {
191
+ return false;
192
+ }
193
+ return stderr.includes('ERR_MODULE_NOT_FOUND');
194
+ };
195
+ const isModulesSyntaxError = stderr => {
196
+ if (!stderr) {
197
+ return false;
198
+ }
199
+ return stderr.includes('SyntaxError: Cannot use import statement outside a module');
200
+ };
201
+ const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
202
+ const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
203
+ const isUnhelpfulNativeModuleError = stderr => {
204
+ return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
205
+ };
206
+ const getNativeModuleErrorMessage = stderr => {
207
+ const message = getMessageCodeBlock(stderr);
208
+ return {
209
+ code: E_INCOMPATIBLE_NATIVE_MODULE,
210
+ message: `Incompatible native node module: ${message}`
211
+ };
212
+ };
213
+ const getModuleSyntaxError = () => {
214
+ return {
215
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
216
+ message: `ES Modules are not supported in electron`
217
+ };
218
+ };
219
+ const getHelpfulChildProcessError = (stdout, stderr) => {
220
+ if (isUnhelpfulNativeModuleError(stderr)) {
221
+ return getNativeModuleErrorMessage(stderr);
222
+ }
223
+ if (isModulesSyntaxError(stderr)) {
224
+ return getModuleSyntaxError();
225
+ }
226
+ if (isModuleNotFoundError(stderr)) {
227
+ return getModuleNotFoundError(stderr);
228
+ }
229
+ const lines = splitLines$1(stderr);
230
+ const {
231
+ actualMessage,
232
+ rest
233
+ } = getDetails(lines);
234
+ return {
235
+ code: '',
236
+ message: actualMessage,
237
+ stack: rest
238
+ };
239
+ };
240
+ class IpcError extends VError {
241
+ // @ts-ignore
242
+ constructor(betterMessage, stdout = '', stderr = '') {
243
+ if (stdout || stderr) {
244
+ // @ts-ignore
245
+ const {
246
+ code,
247
+ message,
248
+ stack
249
+ } = getHelpfulChildProcessError(stdout, stderr);
250
+ const cause = new Error(message);
251
+ // @ts-ignore
252
+ cause.code = code;
253
+ cause.stack = stack;
254
+ super(cause, betterMessage);
255
+ } else {
256
+ super(betterMessage);
257
+ }
258
+ // @ts-ignore
259
+ this.name = 'IpcError';
260
+ // @ts-ignore
261
+ this.stdout = stdout;
262
+ // @ts-ignore
263
+ this.stderr = stderr;
264
+ }
265
+ }
266
+ const readyMessage = 'ready';
267
+ const getData$2 = event => {
268
+ return event.data;
269
+ };
270
+ const listen$7 = () => {
271
+ // @ts-ignore
272
+ if (typeof WorkerGlobalScope === 'undefined') {
273
+ throw new TypeError('module is not in web worker scope');
274
+ }
275
+ return globalThis;
276
+ };
277
+ const signal$8 = global => {
278
+ global.postMessage(readyMessage);
279
+ };
280
+ class IpcChildWithModuleWorker extends Ipc {
281
+ getData(event) {
282
+ return getData$2(event);
283
+ }
284
+ send(message) {
285
+ // @ts-ignore
286
+ this._rawIpc.postMessage(message);
287
+ }
288
+ sendAndTransfer(message) {
289
+ const transfer = getTransferrables(message);
290
+ // @ts-ignore
291
+ this._rawIpc.postMessage(message, transfer);
292
+ }
293
+ dispose() {
294
+ // ignore
295
+ }
296
+ onClose(callback) {
297
+ // ignore
298
+ }
299
+ onMessage(callback) {
300
+ this._rawIpc.addEventListener('message', callback);
301
+ }
302
+ }
303
+ const wrap$f = global => {
304
+ return new IpcChildWithModuleWorker(global);
305
+ };
306
+ const waitForFirstMessage = async port => {
307
+ const {
308
+ promise,
309
+ resolve
310
+ } = Promise.withResolvers();
311
+ port.addEventListener('message', resolve, {
312
+ once: true
313
+ });
314
+ const event = await promise;
315
+ // @ts-ignore
316
+ return event.data;
317
+ };
318
+ const listen$6 = async () => {
319
+ const parentIpcRaw = listen$7();
320
+ signal$8(parentIpcRaw);
321
+ const parentIpc = wrap$f(parentIpcRaw);
322
+ const firstMessage = await waitForFirstMessage(parentIpc);
323
+ if (firstMessage.method !== 'initialize') {
324
+ throw new IpcError('unexpected first message');
325
+ }
326
+ const type = firstMessage.params[0];
327
+ if (type === 'message-port') {
328
+ parentIpc.send({
329
+ id: firstMessage.id,
330
+ jsonrpc: '2.0',
331
+ result: null
332
+ });
333
+ parentIpc.dispose();
334
+ const port = firstMessage.params[1];
335
+ return port;
336
+ }
337
+ return globalThis;
338
+ };
339
+ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
340
+ getData(event) {
341
+ return getData$2(event);
342
+ }
343
+ send(message) {
344
+ this._rawIpc.postMessage(message);
345
+ }
346
+ sendAndTransfer(message) {
347
+ const transfer = getTransferrables(message);
348
+ this._rawIpc.postMessage(message, transfer);
349
+ }
350
+ dispose() {
351
+ if (this._rawIpc.close) {
352
+ this._rawIpc.close();
353
+ }
354
+ }
355
+ onClose(callback) {
356
+ // ignore
357
+ }
358
+ onMessage(callback) {
359
+ this._rawIpc.addEventListener('message', callback);
360
+ this._rawIpc.start();
361
+ }
362
+ }
363
+ const wrap$e = port => {
364
+ return new IpcChildWithModuleWorkerAndMessagePort(port);
365
+ };
366
+ const IpcChildWithModuleWorkerAndMessagePort$1 = {
367
+ __proto__: null,
368
+ listen: listen$6,
369
+ wrap: wrap$e
370
+ };
371
+
372
+ class CommandNotFoundError extends Error {
373
+ constructor(command) {
374
+ super(`Command not found ${command}`);
375
+ this.name = 'CommandNotFoundError';
376
+ }
377
+ }
378
+ const commands = Object.create(null);
379
+ const register = commandMap => {
380
+ Object.assign(commands, commandMap);
381
+ };
382
+ const getCommand = key => {
383
+ return commands[key];
384
+ };
385
+ const execute = (command, ...args) => {
386
+ const fn = getCommand(command);
387
+ if (!fn) {
388
+ throw new CommandNotFoundError(command);
389
+ }
390
+ return fn(...args);
391
+ };
392
+
393
+ const Two$1 = '2.0';
394
+ const callbacks = Object.create(null);
395
+ const get$2 = id => {
396
+ return callbacks[id];
397
+ };
398
+ const remove$1 = id => {
399
+ delete callbacks[id];
400
+ };
401
+ class JsonRpcError extends Error {
402
+ constructor(message) {
403
+ super(message);
404
+ this.name = 'JsonRpcError';
405
+ }
406
+ }
407
+ const NewLine = '\n';
408
+ const DomException = 'DOMException';
409
+ const ReferenceError$1 = 'ReferenceError';
410
+ const SyntaxError$1 = 'SyntaxError';
411
+ const TypeError$1 = 'TypeError';
412
+ const getErrorConstructor = (message, type) => {
413
+ if (type) {
414
+ switch (type) {
415
+ case DomException:
416
+ return DOMException;
417
+ case TypeError$1:
418
+ return TypeError;
419
+ case SyntaxError$1:
420
+ return SyntaxError;
421
+ case ReferenceError$1:
422
+ return ReferenceError;
423
+ default:
424
+ return Error;
425
+ }
426
+ }
427
+ if (message.startsWith('TypeError: ')) {
428
+ return TypeError;
429
+ }
430
+ if (message.startsWith('SyntaxError: ')) {
431
+ return SyntaxError;
432
+ }
433
+ if (message.startsWith('ReferenceError: ')) {
434
+ return ReferenceError;
435
+ }
436
+ return Error;
437
+ };
438
+ const constructError = (message, type, name) => {
439
+ const ErrorConstructor = getErrorConstructor(message, type);
440
+ if (ErrorConstructor === DOMException && name) {
441
+ return new ErrorConstructor(message, name);
442
+ }
443
+ if (ErrorConstructor === Error) {
444
+ const error = new Error(message);
445
+ if (name && name !== 'VError') {
446
+ error.name = name;
447
+ }
448
+ return error;
449
+ }
450
+ return new ErrorConstructor(message);
451
+ };
452
+ const joinLines = lines => {
453
+ return lines.join(NewLine);
454
+ };
455
+ const splitLines = lines => {
456
+ return lines.split(NewLine);
457
+ };
458
+ const getCurrentStack = () => {
459
+ const stackLinesToSkip = 3;
460
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
461
+ return currentStack;
462
+ };
463
+ const getNewLineIndex = (string, startIndex = undefined) => {
464
+ return string.indexOf(NewLine, startIndex);
465
+ };
466
+ const getParentStack = error => {
467
+ let parentStack = error.stack || error.data || error.message || '';
468
+ if (parentStack.startsWith(' at')) {
469
+ parentStack = error.message + NewLine + parentStack;
470
+ }
471
+ return parentStack;
472
+ };
473
+ const MethodNotFound = -32601;
474
+ const Custom = -32001;
475
+ const restoreJsonRpcError = error => {
476
+ const currentStack = getCurrentStack();
477
+ if (error && error instanceof Error) {
478
+ if (typeof error.stack === 'string') {
479
+ error.stack = error.stack + NewLine + currentStack;
480
+ }
481
+ return error;
482
+ }
483
+ if (error && error.code && error.code === MethodNotFound) {
484
+ const restoredError = new JsonRpcError(error.message);
485
+ const parentStack = getParentStack(error);
486
+ restoredError.stack = parentStack + NewLine + currentStack;
487
+ return restoredError;
488
+ }
489
+ if (error && error.message) {
490
+ const restoredError = constructError(error.message, error.type, error.name);
491
+ if (error.data) {
492
+ if (error.data.stack && error.data.type && error.message) {
493
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
494
+ } else if (error.data.stack) {
495
+ restoredError.stack = error.data.stack;
496
+ }
497
+ if (error.data.codeFrame) {
498
+ // @ts-ignore
499
+ restoredError.codeFrame = error.data.codeFrame;
500
+ }
501
+ if (error.data.code) {
502
+ // @ts-ignore
503
+ restoredError.code = error.data.code;
504
+ }
505
+ if (error.data.type) {
506
+ // @ts-ignore
507
+ restoredError.name = error.data.type;
508
+ }
509
+ } else {
510
+ if (error.stack) {
511
+ const lowerStack = restoredError.stack || '';
512
+ // @ts-ignore
513
+ const indexNewLine = getNewLineIndex(lowerStack);
514
+ const parentStack = getParentStack(error);
515
+ // @ts-ignore
516
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
517
+ }
518
+ if (error.codeFrame) {
519
+ // @ts-ignore
520
+ restoredError.codeFrame = error.codeFrame;
521
+ }
522
+ }
523
+ return restoredError;
524
+ }
525
+ if (typeof error === 'string') {
526
+ return new Error(`JsonRpc Error: ${error}`);
527
+ }
528
+ return new Error(`JsonRpc Error: ${error}`);
529
+ };
530
+ const unwrapJsonRpcResult = responseMessage => {
531
+ if ('error' in responseMessage) {
532
+ const restoredError = restoreJsonRpcError(responseMessage.error);
533
+ throw restoredError;
534
+ }
535
+ if ('result' in responseMessage) {
536
+ return responseMessage.result;
537
+ }
538
+ throw new JsonRpcError('unexpected response message');
539
+ };
540
+ const warn = (...args) => {
541
+ console.warn(...args);
542
+ };
543
+ const resolve = (id, response) => {
544
+ const fn = get$2(id);
545
+ if (!fn) {
546
+ console.log(response);
547
+ warn(`callback ${id} may already be disposed`);
548
+ return;
549
+ }
550
+ fn(response);
551
+ remove$1(id);
552
+ };
553
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
554
+ const getErrorType = prettyError => {
555
+ if (prettyError && prettyError.type) {
556
+ return prettyError.type;
557
+ }
558
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
559
+ return prettyError.constructor.name;
560
+ }
561
+ return undefined;
562
+ };
563
+ const isAlreadyStack = line => {
564
+ return line.trim().startsWith('at ');
565
+ };
566
+ const getStack = prettyError => {
567
+ const stackString = prettyError.stack || '';
568
+ const newLineIndex = stackString.indexOf('\n');
569
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
570
+ return stackString.slice(newLineIndex + 1);
571
+ }
572
+ return stackString;
573
+ };
574
+ const getErrorProperty = (error, prettyError) => {
575
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
576
+ return {
577
+ code: MethodNotFound,
578
+ message: error.message,
579
+ data: error.stack
580
+ };
581
+ }
582
+ return {
583
+ code: Custom,
584
+ message: prettyError.message,
585
+ data: {
586
+ stack: getStack(prettyError),
587
+ codeFrame: prettyError.codeFrame,
588
+ type: getErrorType(prettyError),
589
+ code: prettyError.code,
590
+ name: prettyError.name
591
+ }
592
+ };
593
+ };
594
+ const create$1$1 = (id, error) => {
595
+ return {
596
+ jsonrpc: Two$1,
597
+ id,
598
+ error
599
+ };
600
+ };
601
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
602
+ const prettyError = preparePrettyError(error);
603
+ logError(error, prettyError);
604
+ const errorProperty = getErrorProperty(error, prettyError);
605
+ return create$1$1(id, errorProperty);
606
+ };
607
+ const create$7 = (message, result) => {
608
+ return {
609
+ jsonrpc: Two$1,
610
+ id: message.id,
611
+ result: result ?? null
612
+ };
613
+ };
614
+ const getSuccessResponse = (message, result) => {
615
+ const resultProperty = result ?? null;
616
+ return create$7(message, resultProperty);
617
+ };
618
+ const getErrorResponseSimple = (id, error) => {
619
+ return {
620
+ jsonrpc: Two$1,
621
+ id,
622
+ error: {
623
+ code: Custom,
624
+ // @ts-ignore
625
+ message: error.message,
626
+ data: error
627
+ }
628
+ };
629
+ };
630
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
631
+ try {
632
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
633
+ return getSuccessResponse(message, result);
634
+ } catch (error) {
635
+ if (ipc.canUseSimpleErrorResponse) {
636
+ return getErrorResponseSimple(message.id, error);
637
+ }
638
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
639
+ }
640
+ };
641
+ const defaultPreparePrettyError = error => {
642
+ return error;
643
+ };
644
+ const defaultLogError = () => {
645
+ // ignore
646
+ };
647
+ const defaultRequiresSocket = () => {
648
+ return false;
649
+ };
650
+ const defaultResolve = resolve;
651
+
652
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
653
+ const normalizeParams = args => {
654
+ if (args.length === 1) {
655
+ const options = args[0];
656
+ return {
657
+ ipc: options.ipc,
658
+ message: options.message,
659
+ execute: options.execute,
660
+ resolve: options.resolve || defaultResolve,
661
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
662
+ logError: options.logError || defaultLogError,
663
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
664
+ };
665
+ }
666
+ return {
667
+ ipc: args[0],
668
+ message: args[1],
669
+ execute: args[2],
670
+ resolve: args[3],
671
+ preparePrettyError: args[4],
672
+ logError: args[5],
673
+ requiresSocket: args[6]
674
+ };
675
+ };
676
+ const handleJsonRpcMessage = async (...args) => {
677
+ const options = normalizeParams(args);
678
+ const {
679
+ message,
680
+ ipc,
681
+ execute,
682
+ resolve,
683
+ preparePrettyError,
684
+ logError,
685
+ requiresSocket
686
+ } = options;
687
+ if ('id' in message) {
688
+ if ('method' in message) {
689
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
690
+ try {
691
+ ipc.send(response);
692
+ } catch (error) {
693
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
694
+ ipc.send(errorResponse);
695
+ }
696
+ return;
697
+ }
698
+ resolve(message.id, message);
699
+ return;
700
+ }
701
+ if ('method' in message) {
702
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
703
+ return;
704
+ }
705
+ throw new JsonRpcError('unexpected message');
706
+ };
707
+
708
+ const Two = '2.0';
709
+
710
+ const create$6 = (method, params) => {
711
+ return {
712
+ jsonrpc: Two,
713
+ method,
714
+ params
715
+ };
716
+ };
717
+
718
+ const create$5 = (id, method, params) => {
719
+ const message = {
720
+ id,
721
+ jsonrpc: Two,
722
+ method,
723
+ params
724
+ };
725
+ return message;
726
+ };
727
+
728
+ let id = 0;
729
+ const create$4 = () => {
730
+ return ++id;
731
+ };
732
+
733
+ const registerPromise = map => {
734
+ const id = create$4();
735
+ const {
736
+ promise,
737
+ resolve
738
+ } = Promise.withResolvers();
739
+ map[id] = resolve;
740
+ return {
741
+ id,
742
+ promise
743
+ };
744
+ };
745
+
746
+ // @ts-ignore
747
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
748
+ const {
749
+ id,
750
+ promise
751
+ } = registerPromise(callbacks);
752
+ const message = create$5(id, method, params);
753
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
754
+ ipc.sendAndTransfer(message);
755
+ } else {
756
+ ipc.send(message);
757
+ }
758
+ const responseMessage = await promise;
759
+ return unwrapJsonRpcResult(responseMessage);
760
+ };
761
+ const createRpc = ipc => {
762
+ const callbacks = Object.create(null);
763
+ ipc._resolve = (id, response) => {
764
+ const fn = callbacks[id];
765
+ if (!fn) {
766
+ console.warn(`callback ${id} may already be disposed`);
767
+ return;
768
+ }
769
+ fn(response);
770
+ delete callbacks[id];
771
+ };
772
+ const rpc = {
773
+ async dispose() {
774
+ await ipc?.dispose();
775
+ },
776
+ invoke(method, ...params) {
777
+ return invokeHelper(callbacks, ipc, method, params, false);
778
+ },
779
+ invokeAndTransfer(method, ...params) {
780
+ return invokeHelper(callbacks, ipc, method, params, true);
781
+ },
782
+ // @ts-ignore
783
+ ipc,
784
+ /**
785
+ * @deprecated
786
+ */
787
+ send(method, ...params) {
788
+ const message = create$6(method, params);
789
+ ipc.send(message);
790
+ }
791
+ };
792
+ return rpc;
793
+ };
794
+
795
+ const requiresSocket = () => {
796
+ return false;
797
+ };
798
+ const preparePrettyError = error => {
799
+ return error;
800
+ };
801
+ const logError = () => {
802
+ // handled by renderer worker
803
+ };
804
+ const handleMessage = event => {
805
+ const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
806
+ const actualExecute = event?.target?.execute || execute;
807
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
808
+ };
809
+
810
+ const handleIpc = ipc => {
811
+ if ('addEventListener' in ipc) {
812
+ ipc.addEventListener('message', handleMessage);
813
+ } else if ('on' in ipc) {
814
+ // deprecated
815
+ ipc.on('message', handleMessage);
816
+ }
817
+ };
818
+
819
+ const listen$1 = async (module, options) => {
820
+ const rawIpc = await module.listen(options);
821
+ if (module.signal) {
822
+ module.signal(rawIpc);
823
+ }
824
+ const ipc = module.wrap(rawIpc);
825
+ return ipc;
826
+ };
827
+
828
+ const create$3 = async ({
829
+ commandMap
830
+ }) => {
831
+ // TODO create a commandMap per rpc instance
832
+ register(commandMap);
833
+ const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
834
+ handleIpc(ipc);
835
+ const rpc = createRpc(ipc);
836
+ return rpc;
837
+ };
838
+
839
+ const Div = 4;
840
+ const Text = 12;
841
+ const Reference = 100;
842
+
843
+ const RendererWorker = 1;
844
+
845
+ const SetDom2 = 'Viewlet.setDom2';
846
+ const SetPatches = 'Viewlet.setPatches';
847
+
848
+ const createMockRpc = ({
849
+ commandMap
850
+ }) => {
851
+ const invocations = [];
852
+ const invoke = (method, ...params) => {
853
+ invocations.push([method, ...params]);
854
+ const command = commandMap[method];
855
+ if (!command) {
856
+ throw new Error(`command ${method} not found`);
857
+ }
858
+ return command(...params);
859
+ };
860
+ const mockRpc = {
861
+ invocations,
862
+ invoke,
863
+ invokeAndTransfer: invoke
864
+ };
865
+ return mockRpc;
866
+ };
867
+
868
+ const rpcs = Object.create(null);
869
+ const set$2 = (id, rpc) => {
870
+ rpcs[id] = rpc;
871
+ };
872
+ const get$1 = id => {
873
+ return rpcs[id];
874
+ };
875
+ const remove = id => {
876
+ delete rpcs[id];
877
+ };
878
+
879
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
880
+ const create$2 = rpcId => {
881
+ return {
882
+ async dispose() {
883
+ const rpc = get$1(rpcId);
884
+ await rpc.dispose();
885
+ },
886
+ // @ts-ignore
887
+ invoke(method, ...params) {
888
+ const rpc = get$1(rpcId);
889
+ // @ts-ignore
890
+ return rpc.invoke(method, ...params);
891
+ },
892
+ // @ts-ignore
893
+ invokeAndTransfer(method, ...params) {
894
+ const rpc = get$1(rpcId);
895
+ // @ts-ignore
896
+ return rpc.invokeAndTransfer(method, ...params);
897
+ },
898
+ registerMockRpc(commandMap) {
899
+ const mockRpc = createMockRpc({
900
+ commandMap
901
+ });
902
+ set$2(rpcId, mockRpc);
903
+ // @ts-ignore
904
+ mockRpc[Symbol.dispose] = () => {
905
+ remove(rpcId);
906
+ };
907
+ // @ts-ignore
908
+ return mockRpc;
909
+ },
910
+ set(rpc) {
911
+ set$2(rpcId, rpc);
912
+ }
913
+ };
914
+ };
915
+
916
+ const {
917
+ set: set$1
918
+ } = create$2(RendererWorker);
919
+
920
+ const toCommandId = key => {
921
+ const dotIndex = key.indexOf('.');
922
+ return key.slice(dotIndex + 1);
923
+ };
924
+ const create$1 = () => {
925
+ const states = Object.create(null);
926
+ const commandMapRef = {};
927
+ return {
928
+ clear() {
929
+ for (const key of Object.keys(states)) {
930
+ delete states[key];
931
+ }
932
+ },
933
+ diff(uid, modules, numbers) {
934
+ const {
935
+ newState,
936
+ oldState
937
+ } = states[uid];
938
+ const diffResult = [];
939
+ for (let i = 0; i < modules.length; i++) {
940
+ const fn = modules[i];
941
+ if (!fn(oldState, newState)) {
942
+ diffResult.push(numbers[i]);
943
+ }
944
+ }
945
+ return diffResult;
946
+ },
947
+ dispose(uid) {
948
+ delete states[uid];
949
+ },
950
+ get(uid) {
951
+ return states[uid];
952
+ },
953
+ getCommandIds() {
954
+ const keys = Object.keys(commandMapRef);
955
+ const ids = keys.map(toCommandId);
956
+ return ids;
957
+ },
958
+ getKeys() {
959
+ return Object.keys(states).map(key => {
960
+ return Number.parseInt(key);
961
+ });
962
+ },
963
+ registerCommands(commandMap) {
964
+ Object.assign(commandMapRef, commandMap);
965
+ },
966
+ set(uid, oldState, newState) {
967
+ states[uid] = {
968
+ newState,
969
+ oldState
970
+ };
971
+ },
972
+ wrapCommand(fn) {
973
+ const wrapped = async (uid, ...args) => {
974
+ const {
975
+ newState,
976
+ oldState
977
+ } = states[uid];
978
+ const newerState = await fn(newState, ...args);
979
+ if (oldState === newerState || newState === newerState) {
980
+ return;
981
+ }
982
+ const latestOld = states[uid];
983
+ const latestNew = {
984
+ ...latestOld.newState,
985
+ ...newerState
986
+ };
987
+ states[uid] = {
988
+ newState: latestNew,
989
+ oldState: latestOld.oldState
990
+ };
991
+ };
992
+ return wrapped;
993
+ },
994
+ wrapGetter(fn) {
995
+ const wrapped = (uid, ...args) => {
996
+ const {
997
+ newState
998
+ } = states[uid];
999
+ return fn(newState, ...args);
1000
+ };
1001
+ return wrapped;
1002
+ }
1003
+ };
1004
+ };
1005
+ const terminate = () => {
1006
+ globalThis.close();
1007
+ };
1008
+
1009
+ const {
1010
+ get,
1011
+ getCommandIds,
1012
+ registerCommands,
1013
+ set,
1014
+ wrapCommand,
1015
+ wrapGetter
1016
+ } = create$1();
1017
+
1018
+ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1019
+ const state = {
1020
+ actionsUid: 0,
1021
+ assetDir,
1022
+ badgeCounts: {},
1023
+ childUid: 0,
1024
+ errorCount: 0,
1025
+ initial: true,
1026
+ platform,
1027
+ selectedIndex: -1,
1028
+ uid,
1029
+ views: [],
1030
+ warningCount: 0
1031
+ };
1032
+ set(uid, state, state);
1033
+ };
1034
+
1035
+ const isEqual = (oldState, newState) => {
1036
+ return oldState.assetDir === newState.assetDir;
1037
+ };
1038
+
1039
+ const RenderItems = 4;
1040
+ const RenderIncremental = 11;
1041
+
1042
+ const modules = [isEqual];
1043
+ const numbers = [RenderIncremental];
1044
+
1045
+ const diff = (oldState, newState) => {
1046
+ const diffResult = [];
1047
+ for (let i = 0; i < modules.length; i++) {
1048
+ const fn = modules[i];
1049
+ if (!fn(oldState, newState)) {
1050
+ diffResult.push(numbers[i]);
1051
+ }
1052
+ }
1053
+ return diffResult;
1054
+ };
1055
+
1056
+ const diff2 = uid => {
1057
+ const {
1058
+ newState,
1059
+ oldState
1060
+ } = get(uid);
1061
+ const result = diff(oldState, newState);
1062
+ return result;
1063
+ };
1064
+
1065
+ const loadContent = async state => {
1066
+ return {
1067
+ ...state,
1068
+ errorCount: 0,
1069
+ initial: false,
1070
+ warningCount: 0
1071
+ };
1072
+ };
1073
+
1074
+ const SetText = 1;
1075
+ const Replace = 2;
1076
+ const SetAttribute = 3;
1077
+ const RemoveAttribute = 4;
1078
+ const Add = 6;
1079
+ const NavigateChild = 7;
1080
+ const NavigateParent = 8;
1081
+ const RemoveChild = 9;
1082
+ const NavigateSibling = 10;
1083
+ const SetReferenceNodeUid = 11;
1084
+
1085
+ const isKey = key => {
1086
+ return key !== 'type' && key !== 'childCount';
1087
+ };
1088
+
1089
+ const getKeys = node => {
1090
+ const keys = Object.keys(node).filter(isKey);
1091
+ return keys;
1092
+ };
1093
+
1094
+ const arrayToTree = nodes => {
1095
+ const result = [];
1096
+ let i = 0;
1097
+ while (i < nodes.length) {
1098
+ const node = nodes[i];
1099
+ const {
1100
+ children,
1101
+ nodesConsumed
1102
+ } = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
1103
+ result.push({
1104
+ node,
1105
+ children
1106
+ });
1107
+ i += 1 + nodesConsumed;
1108
+ }
1109
+ return result;
1110
+ };
1111
+ const getChildrenWithCount = (nodes, startIndex, childCount) => {
1112
+ if (childCount === 0) {
1113
+ return {
1114
+ children: [],
1115
+ nodesConsumed: 0
1116
+ };
1117
+ }
1118
+ const children = [];
1119
+ let i = startIndex;
1120
+ let remaining = childCount;
1121
+ let totalConsumed = 0;
1122
+ while (remaining > 0 && i < nodes.length) {
1123
+ const node = nodes[i];
1124
+ const nodeChildCount = node.childCount || 0;
1125
+ const {
1126
+ children: nodeChildren,
1127
+ nodesConsumed
1128
+ } = getChildrenWithCount(nodes, i + 1, nodeChildCount);
1129
+ children.push({
1130
+ node,
1131
+ children: nodeChildren
1132
+ });
1133
+ const nodeSize = 1 + nodesConsumed;
1134
+ i += nodeSize;
1135
+ totalConsumed += nodeSize;
1136
+ remaining--;
1137
+ }
1138
+ return {
1139
+ children,
1140
+ nodesConsumed: totalConsumed
1141
+ };
1142
+ };
1143
+
1144
+ const compareNodes = (oldNode, newNode) => {
1145
+ const patches = [];
1146
+ // Check if node type changed - return null to signal incompatible nodes
1147
+ // (caller should handle this with a Replace operation)
1148
+ if (oldNode.type !== newNode.type) {
1149
+ return null;
1150
+ }
1151
+ // Handle reference nodes - special handling for uid changes
1152
+ if (oldNode.type === Reference) {
1153
+ if (oldNode.uid !== newNode.uid) {
1154
+ patches.push({
1155
+ type: SetReferenceNodeUid,
1156
+ uid: newNode.uid
1157
+ });
1158
+ }
1159
+ return patches;
1160
+ }
1161
+ // Handle text nodes
1162
+ if (oldNode.type === Text && newNode.type === Text) {
1163
+ if (oldNode.text !== newNode.text) {
1164
+ patches.push({
1165
+ type: SetText,
1166
+ value: newNode.text
1167
+ });
1168
+ }
1169
+ return patches;
1170
+ }
1171
+ // Compare attributes
1172
+ const oldKeys = getKeys(oldNode);
1173
+ const newKeys = getKeys(newNode);
1174
+ // Check for attribute changes
1175
+ for (const key of newKeys) {
1176
+ if (oldNode[key] !== newNode[key]) {
1177
+ patches.push({
1178
+ type: SetAttribute,
1179
+ key,
1180
+ value: newNode[key]
1181
+ });
1182
+ }
1183
+ }
1184
+ // Check for removed attributes
1185
+ for (const key of oldKeys) {
1186
+ if (!(key in newNode)) {
1187
+ patches.push({
1188
+ type: RemoveAttribute,
1189
+ key
1190
+ });
1191
+ }
1192
+ }
1193
+ return patches;
1194
+ };
1195
+
1196
+ const treeToArray = node => {
1197
+ const result = [node.node];
1198
+ for (const child of node.children) {
1199
+ result.push(...treeToArray(child));
1200
+ }
1201
+ return result;
1202
+ };
1203
+
1204
+ const diffChildren = (oldChildren, newChildren, patches) => {
1205
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
1206
+ // Track where we are: -1 means at parent, >= 0 means at child index
1207
+ let currentChildIndex = -1;
1208
+ // Collect indices of children to remove (we'll add these patches at the end in reverse order)
1209
+ const indicesToRemove = [];
1210
+ for (let i = 0; i < maxLength; i++) {
1211
+ const oldNode = oldChildren[i];
1212
+ const newNode = newChildren[i];
1213
+ if (!oldNode && !newNode) {
1214
+ continue;
1215
+ }
1216
+ if (!oldNode) {
1217
+ // Add new node - we should be at the parent
1218
+ if (currentChildIndex >= 0) {
1219
+ // Navigate back to parent
1220
+ patches.push({
1221
+ type: NavigateParent
1222
+ });
1223
+ currentChildIndex = -1;
1224
+ }
1225
+ // Flatten the entire subtree so renderInternal can handle it
1226
+ const flatNodes = treeToArray(newNode);
1227
+ patches.push({
1228
+ type: Add,
1229
+ nodes: flatNodes
1230
+ });
1231
+ } else if (newNode) {
1232
+ // Compare nodes to see if we need any patches
1233
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
1234
+ // If nodePatches is null, the node types are incompatible - need to replace
1235
+ if (nodePatches === null) {
1236
+ // Navigate to this child
1237
+ if (currentChildIndex === -1) {
1238
+ patches.push({
1239
+ type: NavigateChild,
1240
+ index: i
1241
+ });
1242
+ currentChildIndex = i;
1243
+ } else if (currentChildIndex !== i) {
1244
+ patches.push({
1245
+ type: NavigateSibling,
1246
+ index: i
1247
+ });
1248
+ currentChildIndex = i;
1249
+ }
1250
+ // Replace the entire subtree
1251
+ const flatNodes = treeToArray(newNode);
1252
+ patches.push({
1253
+ type: Replace,
1254
+ nodes: flatNodes
1255
+ });
1256
+ // After replace, we're at the new element (same position)
1257
+ continue;
1258
+ }
1259
+ // Check if we need to recurse into children
1260
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
1261
+ // Only navigate to this element if we need to do something
1262
+ if (nodePatches.length > 0 || hasChildrenToCompare) {
1263
+ // Navigate to this child if not already there
1264
+ if (currentChildIndex === -1) {
1265
+ patches.push({
1266
+ type: NavigateChild,
1267
+ index: i
1268
+ });
1269
+ currentChildIndex = i;
1270
+ } else if (currentChildIndex !== i) {
1271
+ patches.push({
1272
+ type: NavigateSibling,
1273
+ index: i
1274
+ });
1275
+ currentChildIndex = i;
1276
+ }
1277
+ // Apply node patches (these apply to the current element, not children)
1278
+ if (nodePatches.length > 0) {
1279
+ patches.push(...nodePatches);
1280
+ }
1281
+ // Compare children recursively
1282
+ if (hasChildrenToCompare) {
1283
+ diffChildren(oldNode.children, newNode.children, patches);
1284
+ }
1285
+ }
1286
+ } else {
1287
+ // Remove old node - collect the index for later removal
1288
+ indicesToRemove.push(i);
1289
+ }
1290
+ }
1291
+ // Navigate back to parent if we ended at a child
1292
+ if (currentChildIndex >= 0) {
1293
+ patches.push({
1294
+ type: NavigateParent
1295
+ });
1296
+ currentChildIndex = -1;
1297
+ }
1298
+ // Add remove patches in reverse order (highest index first)
1299
+ // This ensures indices remain valid as we remove
1300
+ for (let j = indicesToRemove.length - 1; j >= 0; j--) {
1301
+ patches.push({
1302
+ type: RemoveChild,
1303
+ index: indicesToRemove[j]
1304
+ });
1305
+ }
1306
+ };
1307
+ const diffTrees = (oldTree, newTree, patches, path) => {
1308
+ // At the root level (path.length === 0), we're already AT the element
1309
+ // So we compare the root node directly, then compare its children
1310
+ if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
1311
+ const oldNode = oldTree[0];
1312
+ const newNode = newTree[0];
1313
+ // Compare root nodes
1314
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
1315
+ // If nodePatches is null, the root node types are incompatible - need to replace
1316
+ if (nodePatches === null) {
1317
+ const flatNodes = treeToArray(newNode);
1318
+ patches.push({
1319
+ type: Replace,
1320
+ nodes: flatNodes
1321
+ });
1322
+ return;
1323
+ }
1324
+ if (nodePatches.length > 0) {
1325
+ patches.push(...nodePatches);
1326
+ }
1327
+ // Compare children
1328
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
1329
+ diffChildren(oldNode.children, newNode.children, patches);
1330
+ }
1331
+ } else {
1332
+ // Non-root level or multiple root elements - use the regular comparison
1333
+ diffChildren(oldTree, newTree, patches);
1334
+ }
1335
+ };
1336
+
1337
+ const removeTrailingNavigationPatches = patches => {
1338
+ // Find the last non-navigation patch
1339
+ let lastNonNavigationIndex = -1;
1340
+ for (let i = patches.length - 1; i >= 0; i--) {
1341
+ const patch = patches[i];
1342
+ if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
1343
+ lastNonNavigationIndex = i;
1344
+ break;
1345
+ }
1346
+ }
1347
+ // Return patches up to and including the last non-navigation patch
1348
+ return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
1349
+ };
1350
+
1351
+ const diffTree = (oldNodes, newNodes) => {
1352
+ // Step 1: Convert flat arrays to tree structures
1353
+ const oldTree = arrayToTree(oldNodes);
1354
+ const newTree = arrayToTree(newNodes);
1355
+ // Step 3: Compare the trees
1356
+ const patches = [];
1357
+ diffTrees(oldTree, newTree, patches, []);
1358
+ // Remove trailing navigation patches since they serve no purpose
1359
+ return removeTrailingNavigationPatches(patches);
1360
+ };
1361
+
1362
+ const getStatusBarVirtualDom = () => {
1363
+ const dom = [{
1364
+ childCount: 0,
1365
+ className: 'Panel',
1366
+ type: Div
1367
+ }];
1368
+ return dom;
1369
+ };
1370
+
1371
+ const renderItems = (oldState, newState) => {
1372
+ const {
1373
+ initial,
1374
+ uid
1375
+ } = newState;
1376
+ if (initial) {
1377
+ return [SetDom2, uid, []];
1378
+ }
1379
+ const dom = getStatusBarVirtualDom();
1380
+ return [SetDom2, uid, dom];
1381
+ };
1382
+
1383
+ const renderIncremental = (oldState, newState) => {
1384
+ const oldDom = renderItems(oldState, oldState)[2];
1385
+ const newDom = renderItems(newState, newState)[2];
1386
+ const patches = diffTree(oldDom, newDom);
1387
+ return [SetPatches, newState.uid, patches];
1388
+ };
1389
+
1390
+ const getRenderer = diffType => {
1391
+ switch (diffType) {
1392
+ case RenderIncremental:
1393
+ return renderIncremental;
1394
+ case RenderItems:
1395
+ return renderItems;
1396
+ default:
1397
+ throw new Error('unknown renderer');
1398
+ }
1399
+ };
1400
+
1401
+ const applyRender = (oldState, newState, diffResult) => {
1402
+ const commands = [];
1403
+ for (const item of diffResult) {
1404
+ const fn = getRenderer(item);
1405
+ const result = fn(oldState, newState);
1406
+ if (result.length > 0) {
1407
+ commands.push(result);
1408
+ }
1409
+ }
1410
+ return commands;
1411
+ };
1412
+
1413
+ const render2 = (uid, diffResult) => {
1414
+ const {
1415
+ newState,
1416
+ oldState
1417
+ } = get(uid);
1418
+ set(uid, newState, newState);
1419
+ const commands = applyRender(oldState, newState, diffResult);
1420
+ return commands;
1421
+ };
1422
+
1423
+ const HandleClickClose = 'handleClickClose';
1424
+ const HandleClickMaximize = 'handleClickMaximize';
1425
+ const HandleClickSelectTab = 'HandleClickSelectTab';
1426
+
1427
+ const renderEventListeners = () => {
1428
+ return [{
1429
+ name: HandleClickMaximize,
1430
+ params: ['handleClickMaximize']
1431
+ }, {
1432
+ name: HandleClickClose,
1433
+ params: ['handleClickClose']
1434
+ }, {
1435
+ name: HandleClickSelectTab,
1436
+ params: ['selectIndexRaw', 'event.target.dataset.index']
1437
+ }];
1438
+ };
1439
+
1440
+ const resize = (state, dimensions) => {
1441
+ return {
1442
+ ...state,
1443
+ ...dimensions
1444
+ };
1445
+ };
1446
+
1447
+ const saveState = state => {
1448
+ return {
1449
+ x: 0
1450
+ };
1451
+ };
1452
+
1453
+ const commandMap = {
1454
+ 'StatusBar.create': create,
1455
+ 'StatusBar.diff2': diff2,
1456
+ 'StatusBar.getCommandIds': getCommandIds,
1457
+ 'StatusBar.loadContent': wrapCommand(loadContent),
1458
+ 'StatusBar.render2': render2,
1459
+ 'StatusBar.renderEventListeners': renderEventListeners,
1460
+ 'StatusBar.resize': wrapCommand(resize),
1461
+ 'StatusBar.saveState': wrapGetter(saveState),
1462
+ 'StatusBar.terminate': terminate
1463
+ };
1464
+
1465
+ const listen = async () => {
1466
+ registerCommands(commandMap);
1467
+ const rpc = await create$3({
1468
+ commandMap: commandMap
1469
+ });
1470
+ set$1(rpc);
1471
+ };
1472
+
1473
+ const main = async () => {
1474
+ await listen();
1475
+ };
1476
+
1477
+ main();