@lvce-editor/menu-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,2696 @@
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
+ class AssertionError extends Error {
58
+ constructor(message) {
59
+ super(message);
60
+ this.name = 'AssertionError';
61
+ }
62
+ }
63
+ const Object$1 = 1;
64
+ const Number = 2;
65
+ const Array$1 = 3;
66
+ const String = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown$1 = 8;
71
+ const getType = value => {
72
+ switch (typeof value) {
73
+ case 'number':
74
+ return Number;
75
+ case 'function':
76
+ return Function;
77
+ case 'string':
78
+ return String;
79
+ case 'object':
80
+ if (value === null) {
81
+ return Null;
82
+ }
83
+ if (Array.isArray(value)) {
84
+ return Array$1;
85
+ }
86
+ return Object$1;
87
+ case 'boolean':
88
+ return Boolean$1;
89
+ default:
90
+ return Unknown$1;
91
+ }
92
+ };
93
+ const number = value => {
94
+ const type = getType(value);
95
+ if (type !== Number) {
96
+ throw new AssertionError('expected value to be of type number');
97
+ }
98
+ };
99
+
100
+ const isMessagePort = value => {
101
+ return value && value instanceof MessagePort;
102
+ };
103
+ const isMessagePortMain = value => {
104
+ return value && value.constructor && value.constructor.name === 'MessagePortMain';
105
+ };
106
+ const isOffscreenCanvas = value => {
107
+ return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
108
+ };
109
+ const isInstanceOf = (value, constructorName) => {
110
+ return value?.constructor?.name === constructorName;
111
+ };
112
+ const isSocket = value => {
113
+ return isInstanceOf(value, 'Socket');
114
+ };
115
+ const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
116
+ const isTransferrable = value => {
117
+ for (const fn of transferrables) {
118
+ if (fn(value)) {
119
+ return true;
120
+ }
121
+ }
122
+ return false;
123
+ };
124
+ const walkValue = (value, transferrables, isTransferrable) => {
125
+ if (!value) {
126
+ return;
127
+ }
128
+ if (isTransferrable(value)) {
129
+ transferrables.push(value);
130
+ return;
131
+ }
132
+ if (Array.isArray(value)) {
133
+ for (const item of value) {
134
+ walkValue(item, transferrables, isTransferrable);
135
+ }
136
+ return;
137
+ }
138
+ if (typeof value === 'object') {
139
+ for (const property of Object.values(value)) {
140
+ walkValue(property, transferrables, isTransferrable);
141
+ }
142
+ return;
143
+ }
144
+ };
145
+ const getTransferrables = value => {
146
+ const transferrables = [];
147
+ walkValue(value, transferrables, isTransferrable);
148
+ return transferrables;
149
+ };
150
+ const attachEvents = that => {
151
+ const handleMessage = (...args) => {
152
+ const data = that.getData(...args);
153
+ that.dispatchEvent(new MessageEvent('message', {
154
+ data
155
+ }));
156
+ };
157
+ that.onMessage(handleMessage);
158
+ const handleClose = event => {
159
+ that.dispatchEvent(new Event('close'));
160
+ };
161
+ that.onClose(handleClose);
162
+ };
163
+ class Ipc extends EventTarget {
164
+ constructor(rawIpc) {
165
+ super();
166
+ this._rawIpc = rawIpc;
167
+ attachEvents(this);
168
+ }
169
+ }
170
+ const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
171
+ const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
172
+ const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
173
+ const NewLine$1 = '\n';
174
+ const joinLines$1 = lines => {
175
+ return lines.join(NewLine$1);
176
+ };
177
+ const RE_AT = /^\s+at/;
178
+ const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
179
+ const isNormalStackLine = line => {
180
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
181
+ };
182
+ const getDetails = lines => {
183
+ const index = lines.findIndex(isNormalStackLine);
184
+ if (index === -1) {
185
+ return {
186
+ actualMessage: joinLines$1(lines),
187
+ rest: []
188
+ };
189
+ }
190
+ let lastIndex = index - 1;
191
+ while (++lastIndex < lines.length) {
192
+ if (!isNormalStackLine(lines[lastIndex])) {
193
+ break;
194
+ }
195
+ }
196
+ return {
197
+ actualMessage: lines[index - 1],
198
+ rest: lines.slice(index, lastIndex)
199
+ };
200
+ };
201
+ const splitLines$1 = lines => {
202
+ return lines.split(NewLine$1);
203
+ };
204
+ const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
205
+ const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
206
+ const isMessageCodeBlockStartIndex = line => {
207
+ return RE_MESSAGE_CODE_BLOCK_START.test(line);
208
+ };
209
+ const isMessageCodeBlockEndIndex = line => {
210
+ return RE_MESSAGE_CODE_BLOCK_END.test(line);
211
+ };
212
+ const getMessageCodeBlock = stderr => {
213
+ const lines = splitLines$1(stderr);
214
+ const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
215
+ const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
216
+ const relevantLines = lines.slice(startIndex, endIndex);
217
+ const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
218
+ return relevantMessage;
219
+ };
220
+ const isModuleNotFoundMessage = line => {
221
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
222
+ };
223
+ const getModuleNotFoundError = stderr => {
224
+ const lines = splitLines$1(stderr);
225
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
226
+ const message = lines[messageIndex];
227
+ return {
228
+ message,
229
+ code: ERR_MODULE_NOT_FOUND
230
+ };
231
+ };
232
+ const isModuleNotFoundError = stderr => {
233
+ if (!stderr) {
234
+ return false;
235
+ }
236
+ return stderr.includes('ERR_MODULE_NOT_FOUND');
237
+ };
238
+ const isModulesSyntaxError = stderr => {
239
+ if (!stderr) {
240
+ return false;
241
+ }
242
+ return stderr.includes('SyntaxError: Cannot use import statement outside a module');
243
+ };
244
+ const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
245
+ const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
246
+ const isUnhelpfulNativeModuleError = stderr => {
247
+ return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
248
+ };
249
+ const getNativeModuleErrorMessage = stderr => {
250
+ const message = getMessageCodeBlock(stderr);
251
+ return {
252
+ message: `Incompatible native node module: ${message}`,
253
+ code: E_INCOMPATIBLE_NATIVE_MODULE
254
+ };
255
+ };
256
+ const getModuleSyntaxError = () => {
257
+ return {
258
+ message: `ES Modules are not supported in electron`,
259
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
260
+ };
261
+ };
262
+ const getHelpfulChildProcessError = (stdout, stderr) => {
263
+ if (isUnhelpfulNativeModuleError(stderr)) {
264
+ return getNativeModuleErrorMessage(stderr);
265
+ }
266
+ if (isModulesSyntaxError(stderr)) {
267
+ return getModuleSyntaxError();
268
+ }
269
+ if (isModuleNotFoundError(stderr)) {
270
+ return getModuleNotFoundError(stderr);
271
+ }
272
+ const lines = splitLines$1(stderr);
273
+ const {
274
+ actualMessage,
275
+ rest
276
+ } = getDetails(lines);
277
+ return {
278
+ message: actualMessage,
279
+ code: '',
280
+ stack: rest
281
+ };
282
+ };
283
+ class IpcError extends VError {
284
+ // @ts-ignore
285
+ constructor(betterMessage, stdout = '', stderr = '') {
286
+ if (stdout || stderr) {
287
+ // @ts-ignore
288
+ const {
289
+ message,
290
+ code,
291
+ stack
292
+ } = getHelpfulChildProcessError(stdout, stderr);
293
+ const cause = new Error(message);
294
+ // @ts-ignore
295
+ cause.code = code;
296
+ cause.stack = stack;
297
+ super(cause, betterMessage);
298
+ } else {
299
+ super(betterMessage);
300
+ }
301
+ // @ts-ignore
302
+ this.name = 'IpcError';
303
+ // @ts-ignore
304
+ this.stdout = stdout;
305
+ // @ts-ignore
306
+ this.stderr = stderr;
307
+ }
308
+ }
309
+ const readyMessage = 'ready';
310
+ const getData$2 = event => {
311
+ return event.data;
312
+ };
313
+ const listen$7 = () => {
314
+ // @ts-ignore
315
+ if (typeof WorkerGlobalScope === 'undefined') {
316
+ throw new TypeError('module is not in web worker scope');
317
+ }
318
+ return globalThis;
319
+ };
320
+ const signal$8 = global => {
321
+ global.postMessage(readyMessage);
322
+ };
323
+ class IpcChildWithModuleWorker extends Ipc {
324
+ getData(event) {
325
+ return getData$2(event);
326
+ }
327
+ send(message) {
328
+ // @ts-ignore
329
+ this._rawIpc.postMessage(message);
330
+ }
331
+ sendAndTransfer(message) {
332
+ const transfer = getTransferrables(message);
333
+ // @ts-ignore
334
+ this._rawIpc.postMessage(message, transfer);
335
+ }
336
+ dispose() {
337
+ // ignore
338
+ }
339
+ onClose(callback) {
340
+ // ignore
341
+ }
342
+ onMessage(callback) {
343
+ this._rawIpc.addEventListener('message', callback);
344
+ }
345
+ }
346
+ const wrap$f = global => {
347
+ return new IpcChildWithModuleWorker(global);
348
+ };
349
+ const waitForFirstMessage = async port => {
350
+ const {
351
+ resolve,
352
+ promise
353
+ } = Promise.withResolvers();
354
+ port.addEventListener('message', resolve, {
355
+ once: true
356
+ });
357
+ const event = await promise;
358
+ // @ts-ignore
359
+ return event.data;
360
+ };
361
+ const listen$6 = async () => {
362
+ const parentIpcRaw = listen$7();
363
+ signal$8(parentIpcRaw);
364
+ const parentIpc = wrap$f(parentIpcRaw);
365
+ const firstMessage = await waitForFirstMessage(parentIpc);
366
+ if (firstMessage.method !== 'initialize') {
367
+ throw new IpcError('unexpected first message');
368
+ }
369
+ const type = firstMessage.params[0];
370
+ if (type === 'message-port') {
371
+ parentIpc.send({
372
+ jsonrpc: '2.0',
373
+ id: firstMessage.id,
374
+ result: null
375
+ });
376
+ parentIpc.dispose();
377
+ const port = firstMessage.params[1];
378
+ return port;
379
+ }
380
+ return globalThis;
381
+ };
382
+ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
383
+ getData(event) {
384
+ return getData$2(event);
385
+ }
386
+ send(message) {
387
+ this._rawIpc.postMessage(message);
388
+ }
389
+ sendAndTransfer(message) {
390
+ const transfer = getTransferrables(message);
391
+ this._rawIpc.postMessage(message, transfer);
392
+ }
393
+ dispose() {
394
+ if (this._rawIpc.close) {
395
+ this._rawIpc.close();
396
+ }
397
+ }
398
+ onClose(callback) {
399
+ // ignore
400
+ }
401
+ onMessage(callback) {
402
+ this._rawIpc.addEventListener('message', callback);
403
+ this._rawIpc.start();
404
+ }
405
+ }
406
+ const wrap$e = port => {
407
+ return new IpcChildWithModuleWorkerAndMessagePort(port);
408
+ };
409
+ const IpcChildWithModuleWorkerAndMessagePort$1 = {
410
+ __proto__: null,
411
+ listen: listen$6,
412
+ wrap: wrap$e
413
+ };
414
+
415
+ const Two = '2.0';
416
+ const create$4 = (method, params) => {
417
+ return {
418
+ jsonrpc: Two,
419
+ method,
420
+ params
421
+ };
422
+ };
423
+ const callbacks = Object.create(null);
424
+ const set$4 = (id, fn) => {
425
+ callbacks[id] = fn;
426
+ };
427
+ const get$2 = id => {
428
+ return callbacks[id];
429
+ };
430
+ const remove = id => {
431
+ delete callbacks[id];
432
+ };
433
+ let id$a = 0;
434
+ const create$3 = () => {
435
+ return ++id$a;
436
+ };
437
+ const registerPromise = () => {
438
+ const id = create$3();
439
+ const {
440
+ resolve,
441
+ promise
442
+ } = Promise.withResolvers();
443
+ set$4(id, resolve);
444
+ return {
445
+ id,
446
+ promise
447
+ };
448
+ };
449
+ const create$2$1 = (method, params) => {
450
+ const {
451
+ id,
452
+ promise
453
+ } = registerPromise();
454
+ const message = {
455
+ jsonrpc: Two,
456
+ method,
457
+ params,
458
+ id
459
+ };
460
+ return {
461
+ message,
462
+ promise
463
+ };
464
+ };
465
+ class JsonRpcError extends Error {
466
+ constructor(message) {
467
+ super(message);
468
+ this.name = 'JsonRpcError';
469
+ }
470
+ }
471
+ const NewLine = '\n';
472
+ const DomException = 'DOMException';
473
+ const ReferenceError$1 = 'ReferenceError';
474
+ const SyntaxError$1 = 'SyntaxError';
475
+ const TypeError$1 = 'TypeError';
476
+ const getErrorConstructor = (message, type) => {
477
+ if (type) {
478
+ switch (type) {
479
+ case DomException:
480
+ return DOMException;
481
+ case TypeError$1:
482
+ return TypeError;
483
+ case SyntaxError$1:
484
+ return SyntaxError;
485
+ case ReferenceError$1:
486
+ return ReferenceError;
487
+ default:
488
+ return Error;
489
+ }
490
+ }
491
+ if (message.startsWith('TypeError: ')) {
492
+ return TypeError;
493
+ }
494
+ if (message.startsWith('SyntaxError: ')) {
495
+ return SyntaxError;
496
+ }
497
+ if (message.startsWith('ReferenceError: ')) {
498
+ return ReferenceError;
499
+ }
500
+ return Error;
501
+ };
502
+ const constructError = (message, type, name) => {
503
+ const ErrorConstructor = getErrorConstructor(message, type);
504
+ if (ErrorConstructor === DOMException && name) {
505
+ return new ErrorConstructor(message, name);
506
+ }
507
+ if (ErrorConstructor === Error) {
508
+ const error = new Error(message);
509
+ if (name && name !== 'VError') {
510
+ error.name = name;
511
+ }
512
+ return error;
513
+ }
514
+ return new ErrorConstructor(message);
515
+ };
516
+ const joinLines = lines => {
517
+ return lines.join(NewLine);
518
+ };
519
+ const splitLines = lines => {
520
+ return lines.split(NewLine);
521
+ };
522
+ const getCurrentStack = () => {
523
+ const stackLinesToSkip = 3;
524
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
525
+ return currentStack;
526
+ };
527
+ const getNewLineIndex = (string, startIndex = undefined) => {
528
+ return string.indexOf(NewLine, startIndex);
529
+ };
530
+ const getParentStack = error => {
531
+ let parentStack = error.stack || error.data || error.message || '';
532
+ if (parentStack.startsWith(' at')) {
533
+ parentStack = error.message + NewLine + parentStack;
534
+ }
535
+ return parentStack;
536
+ };
537
+ const MethodNotFound = -32601;
538
+ const Custom = -32001;
539
+ const restoreJsonRpcError = error => {
540
+ const currentStack = getCurrentStack();
541
+ if (error && error instanceof Error) {
542
+ if (typeof error.stack === 'string') {
543
+ error.stack = error.stack + NewLine + currentStack;
544
+ }
545
+ return error;
546
+ }
547
+ if (error && error.code && error.code === MethodNotFound) {
548
+ const restoredError = new JsonRpcError(error.message);
549
+ const parentStack = getParentStack(error);
550
+ restoredError.stack = parentStack + NewLine + currentStack;
551
+ return restoredError;
552
+ }
553
+ if (error && error.message) {
554
+ const restoredError = constructError(error.message, error.type, error.name);
555
+ if (error.data) {
556
+ if (error.data.stack && error.data.type && error.message) {
557
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
558
+ } else if (error.data.stack) {
559
+ restoredError.stack = error.data.stack;
560
+ }
561
+ if (error.data.codeFrame) {
562
+ // @ts-ignore
563
+ restoredError.codeFrame = error.data.codeFrame;
564
+ }
565
+ if (error.data.code) {
566
+ // @ts-ignore
567
+ restoredError.code = error.data.code;
568
+ }
569
+ if (error.data.type) {
570
+ // @ts-ignore
571
+ restoredError.name = error.data.type;
572
+ }
573
+ } else {
574
+ if (error.stack) {
575
+ const lowerStack = restoredError.stack || '';
576
+ // @ts-ignore
577
+ const indexNewLine = getNewLineIndex(lowerStack);
578
+ const parentStack = getParentStack(error);
579
+ // @ts-ignore
580
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
581
+ }
582
+ if (error.codeFrame) {
583
+ // @ts-ignore
584
+ restoredError.codeFrame = error.codeFrame;
585
+ }
586
+ }
587
+ return restoredError;
588
+ }
589
+ if (typeof error === 'string') {
590
+ return new Error(`JsonRpc Error: ${error}`);
591
+ }
592
+ return new Error(`JsonRpc Error: ${error}`);
593
+ };
594
+ const unwrapJsonRpcResult = responseMessage => {
595
+ if ('error' in responseMessage) {
596
+ const restoredError = restoreJsonRpcError(responseMessage.error);
597
+ throw restoredError;
598
+ }
599
+ if ('result' in responseMessage) {
600
+ return responseMessage.result;
601
+ }
602
+ throw new JsonRpcError('unexpected response message');
603
+ };
604
+ const warn = (...args) => {
605
+ console.warn(...args);
606
+ };
607
+ const resolve = (id, response) => {
608
+ const fn = get$2(id);
609
+ if (!fn) {
610
+ console.log(response);
611
+ warn(`callback ${id} may already be disposed`);
612
+ return;
613
+ }
614
+ fn(response);
615
+ remove(id);
616
+ };
617
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
618
+ const getErrorType = prettyError => {
619
+ if (prettyError && prettyError.type) {
620
+ return prettyError.type;
621
+ }
622
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
623
+ return prettyError.constructor.name;
624
+ }
625
+ return undefined;
626
+ };
627
+ const isAlreadyStack = line => {
628
+ return line.trim().startsWith('at ');
629
+ };
630
+ const getStack = prettyError => {
631
+ const stackString = prettyError.stack || '';
632
+ const newLineIndex = stackString.indexOf('\n');
633
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
634
+ return stackString.slice(newLineIndex + 1);
635
+ }
636
+ return stackString;
637
+ };
638
+ const getErrorProperty = (error, prettyError) => {
639
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
640
+ return {
641
+ code: MethodNotFound,
642
+ message: error.message,
643
+ data: error.stack
644
+ };
645
+ }
646
+ return {
647
+ code: Custom,
648
+ message: prettyError.message,
649
+ data: {
650
+ stack: getStack(prettyError),
651
+ codeFrame: prettyError.codeFrame,
652
+ type: getErrorType(prettyError),
653
+ code: prettyError.code,
654
+ name: prettyError.name
655
+ }
656
+ };
657
+ };
658
+ const create$1$1 = (id, error) => {
659
+ return {
660
+ jsonrpc: Two,
661
+ id,
662
+ error
663
+ };
664
+ };
665
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
666
+ const prettyError = preparePrettyError(error);
667
+ logError(error, prettyError);
668
+ const errorProperty = getErrorProperty(error, prettyError);
669
+ return create$1$1(id, errorProperty);
670
+ };
671
+ const create$5 = (message, result) => {
672
+ return {
673
+ jsonrpc: Two,
674
+ id: message.id,
675
+ result: result ?? null
676
+ };
677
+ };
678
+ const getSuccessResponse = (message, result) => {
679
+ const resultProperty = result ?? null;
680
+ return create$5(message, resultProperty);
681
+ };
682
+ const getErrorResponseSimple = (id, error) => {
683
+ return {
684
+ jsonrpc: Two,
685
+ id,
686
+ error: {
687
+ code: Custom,
688
+ // @ts-ignore
689
+ message: error.message,
690
+ data: error
691
+ }
692
+ };
693
+ };
694
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
695
+ try {
696
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
697
+ return getSuccessResponse(message, result);
698
+ } catch (error) {
699
+ if (ipc.canUseSimpleErrorResponse) {
700
+ return getErrorResponseSimple(message.id, error);
701
+ }
702
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
703
+ }
704
+ };
705
+ const defaultPreparePrettyError = error => {
706
+ return error;
707
+ };
708
+ const defaultLogError = () => {
709
+ // ignore
710
+ };
711
+ const defaultRequiresSocket = () => {
712
+ return false;
713
+ };
714
+ const defaultResolve = resolve;
715
+
716
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
717
+ const normalizeParams = args => {
718
+ if (args.length === 1) {
719
+ const options = args[0];
720
+ return {
721
+ ipc: options.ipc,
722
+ message: options.message,
723
+ execute: options.execute,
724
+ resolve: options.resolve || defaultResolve,
725
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
726
+ logError: options.logError || defaultLogError,
727
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
728
+ };
729
+ }
730
+ return {
731
+ ipc: args[0],
732
+ message: args[1],
733
+ execute: args[2],
734
+ resolve: args[3],
735
+ preparePrettyError: args[4],
736
+ logError: args[5],
737
+ requiresSocket: args[6]
738
+ };
739
+ };
740
+ const handleJsonRpcMessage = async (...args) => {
741
+ const options = normalizeParams(args);
742
+ const {
743
+ message,
744
+ ipc,
745
+ execute,
746
+ resolve,
747
+ preparePrettyError,
748
+ logError,
749
+ requiresSocket
750
+ } = options;
751
+ if ('id' in message) {
752
+ if ('method' in message) {
753
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
754
+ try {
755
+ ipc.send(response);
756
+ } catch (error) {
757
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
758
+ ipc.send(errorResponse);
759
+ }
760
+ return;
761
+ }
762
+ resolve(message.id, message);
763
+ return;
764
+ }
765
+ if ('method' in message) {
766
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
767
+ return;
768
+ }
769
+ throw new JsonRpcError('unexpected message');
770
+ };
771
+ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
772
+ const {
773
+ message,
774
+ promise
775
+ } = create$2$1(method, params);
776
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
777
+ ipc.sendAndTransfer(message);
778
+ } else {
779
+ ipc.send(message);
780
+ }
781
+ const responseMessage = await promise;
782
+ return unwrapJsonRpcResult(responseMessage);
783
+ };
784
+ const send = (transport, method, ...params) => {
785
+ const message = create$4(method, params);
786
+ transport.send(message);
787
+ };
788
+ const invoke$2 = (ipc, method, ...params) => {
789
+ return invokeHelper(ipc, method, params, false);
790
+ };
791
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
792
+ return invokeHelper(ipc, method, params, true);
793
+ };
794
+
795
+ class CommandNotFoundError extends Error {
796
+ constructor(command) {
797
+ super(`Command not found ${command}`);
798
+ this.name = 'CommandNotFoundError';
799
+ }
800
+ }
801
+ const commands = Object.create(null);
802
+ const register = commandMap => {
803
+ Object.assign(commands, commandMap);
804
+ };
805
+ const getCommand = key => {
806
+ return commands[key];
807
+ };
808
+ const execute = (command, ...args) => {
809
+ const fn = getCommand(command);
810
+ if (!fn) {
811
+ throw new CommandNotFoundError(command);
812
+ }
813
+ return fn(...args);
814
+ };
815
+
816
+ const createRpc = ipc => {
817
+ const rpc = {
818
+ // @ts-ignore
819
+ ipc,
820
+ /**
821
+ * @deprecated
822
+ */
823
+ send(method, ...params) {
824
+ send(ipc, method, ...params);
825
+ },
826
+ invoke(method, ...params) {
827
+ return invoke$2(ipc, method, ...params);
828
+ },
829
+ invokeAndTransfer(method, ...params) {
830
+ return invokeAndTransfer$1(ipc, method, ...params);
831
+ },
832
+ async dispose() {
833
+ await ipc?.dispose();
834
+ }
835
+ };
836
+ return rpc;
837
+ };
838
+ const requiresSocket = () => {
839
+ return false;
840
+ };
841
+ const preparePrettyError = error => {
842
+ return error;
843
+ };
844
+ const logError = () => {
845
+ // handled by renderer worker
846
+ };
847
+ const handleMessage = event => {
848
+ const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
849
+ const actualExecute = event?.target?.execute || execute;
850
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
851
+ };
852
+ const handleIpc = ipc => {
853
+ if ('addEventListener' in ipc) {
854
+ ipc.addEventListener('message', handleMessage);
855
+ } else if ('on' in ipc) {
856
+ // deprecated
857
+ ipc.on('message', handleMessage);
858
+ }
859
+ };
860
+ const listen$1 = async (module, options) => {
861
+ const rawIpc = await module.listen(options);
862
+ if (module.signal) {
863
+ module.signal(rawIpc);
864
+ }
865
+ const ipc = module.wrap(rawIpc);
866
+ return ipc;
867
+ };
868
+ const create$2 = async ({
869
+ commandMap
870
+ }) => {
871
+ // TODO create a commandMap per rpc instance
872
+ register(commandMap);
873
+ const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
874
+ handleIpc(ipc);
875
+ const rpc = createRpc(ipc);
876
+ return rpc;
877
+ };
878
+ const WebWorkerRpcClient = {
879
+ __proto__: null,
880
+ create: create$2
881
+ };
882
+ const createMockRpc = ({
883
+ commandMap
884
+ }) => {
885
+ const invocations = [];
886
+ const invoke = (method, ...params) => {
887
+ invocations.push([method, ...params]);
888
+ const command = commandMap[method];
889
+ if (!command) {
890
+ throw new Error(`command ${method} not found`);
891
+ }
892
+ return command(...params);
893
+ };
894
+ const mockRpc = {
895
+ invoke,
896
+ invokeAndTransfer: invoke,
897
+ invocations
898
+ };
899
+ return mockRpc;
900
+ };
901
+
902
+ const RenderEntries = 1;
903
+ const RenderFocusedIndex = 2;
904
+ const RenderMenus = 3;
905
+
906
+ const diffType$2 = RenderEntries;
907
+ const isEqual$2 = (oldState, newState) => {
908
+ return oldState.titleBarEntries === newState.titleBarEntries && oldState.width === newState.width && oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
909
+ };
910
+
911
+ const diffType$1 = RenderFocusedIndex;
912
+ const isEqual$1 = (oldState, newState) => {
913
+ return oldState.focusedIndex === newState.focusedIndex && oldState.isMenuOpen === newState.isMenuOpen;
914
+ };
915
+
916
+ const diffType = RenderMenus;
917
+ const isEqual = (oldState, newState) => {
918
+ return oldState.menus === newState.menus;
919
+ };
920
+
921
+ const modules = [isEqual$2, isEqual$1, isEqual];
922
+ const numbers = [diffType$2, diffType$1, diffType];
923
+
924
+ const diff = (oldState, newState) => {
925
+ const diffResult = [];
926
+ for (let i = 0; i < modules.length; i++) {
927
+ const fn = modules[i];
928
+ if (!fn(oldState, newState)) {
929
+ diffResult.push(numbers[i]);
930
+ }
931
+ }
932
+ return diffResult;
933
+ };
934
+
935
+ const create$1 = () => {
936
+ const states = Object.create(null);
937
+ return {
938
+ get(uid) {
939
+ return states[uid];
940
+ },
941
+ set(uid, oldState, newState) {
942
+ states[uid] = {
943
+ oldState,
944
+ newState
945
+ };
946
+ }
947
+ };
948
+ };
949
+
950
+ const {
951
+ get: get$1,
952
+ set: set$3
953
+ } = create$1();
954
+
955
+ const diff2 = uid => {
956
+ const {
957
+ oldState,
958
+ newState
959
+ } = get$1(uid);
960
+ return diff(oldState, newState);
961
+ };
962
+
963
+ const commandsIds = ['closeMenu', 'handleClickAt', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'handleClick', 'handleFocus', 'handleFocusOut', 'handleKeyArrowDown', 'handleKeyArrowLeft', 'handleKeyArrowRight', 'handleKeyArrowUp', 'handleKeyEnd', 'handleKeyEnter', 'handleKeyEscape', 'handleKeyHome', 'handleKeySpace', 'handleMenuClick', 'handleMenuMouseOver', 'handleMouseOut', 'handleMouseOver', 'handlePointerOver', 'handlePointerOut', 'toggleIndex', 'toggleMenu'];
964
+
965
+ const getCommandIds = () => {
966
+ return commandsIds;
967
+ };
968
+
969
+ const Text = 12;
970
+
971
+ const Escape$2 = 8;
972
+ const Space$2 = 9;
973
+ const End$2 = 255;
974
+ const Home$2 = 12;
975
+ const LeftArrow$2 = 13;
976
+ const UpArrow$2 = 14;
977
+ const RightArrow$2 = 15;
978
+ const DownArrow$2 = 16;
979
+
980
+ const CtrlCmd = 1 << 11 >>> 0;
981
+ const Shift = 1 << 10 >>> 0;
982
+
983
+ const DebugWorker = 55;
984
+ const RendererWorker$1 = 1;
985
+
986
+ const mergeClassNames = (...classNames) => {
987
+ return classNames.filter(Boolean).join(' ');
988
+ };
989
+
990
+ const text = data => {
991
+ return {
992
+ type: Text,
993
+ text: data,
994
+ childCount: 0
995
+ };
996
+ };
997
+
998
+ const FocusTitleBarMenuBar = 26;
999
+
1000
+ const getKeyBindings$1 = () => {
1001
+ return [{
1002
+ key: DownArrow$2,
1003
+ command: 'TitleBarMenuBar.handleKeyArrowDown',
1004
+ when: FocusTitleBarMenuBar
1005
+ }, {
1006
+ key: UpArrow$2,
1007
+ command: 'TitleBarMenuBar.handleKeyArrowUp',
1008
+ when: FocusTitleBarMenuBar
1009
+ }, {
1010
+ key: RightArrow$2,
1011
+ command: 'TitleBarMenuBar.handleKeyArrowRight',
1012
+ when: FocusTitleBarMenuBar
1013
+ }, {
1014
+ key: LeftArrow$2,
1015
+ command: 'TitleBarMenuBar.handleKeyArrowLeft',
1016
+ when: FocusTitleBarMenuBar
1017
+ }, {
1018
+ key: Space$2,
1019
+ command: 'TitleBarMenuBar.handleKeySpace',
1020
+ when: FocusTitleBarMenuBar
1021
+ }, {
1022
+ key: Home$2,
1023
+ command: 'TitleBarMenuBar.handleKeyHome',
1024
+ when: FocusTitleBarMenuBar
1025
+ }, {
1026
+ key: End$2,
1027
+ command: 'TitleBarMenuBar.handleKeyEnd',
1028
+ when: FocusTitleBarMenuBar
1029
+ }, {
1030
+ key: Escape$2,
1031
+ command: 'TitleBarMenuBar.handleKeyEscape',
1032
+ when: FocusTitleBarMenuBar
1033
+ }];
1034
+ };
1035
+
1036
+ const emptyObject = {};
1037
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1038
+ const i18nString = (key, placeholders = emptyObject) => {
1039
+ if (placeholders === emptyObject) {
1040
+ return key;
1041
+ }
1042
+ const replacer = (match, rest) => {
1043
+ return placeholders[rest];
1044
+ };
1045
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1046
+ };
1047
+
1048
+ /**
1049
+ * @enum {string}
1050
+ */
1051
+ const UiStrings$2 = {
1052
+ Copy: 'Copy',
1053
+ CopyLineDown: 'Copy Line Down',
1054
+ CopyLineUp: 'Copy Line Up',
1055
+ Cut: 'Cut',
1056
+ MoveLineDown: 'Move Line Down',
1057
+ MoveLineUp: 'Move Line Up',
1058
+ Paste: 'Paste',
1059
+ Redo: 'Redo',
1060
+ SelectAll: 'Select All',
1061
+ ToggleBlockComment: 'Toggle Block Comment',
1062
+ ToggleLineComment: 'Toggle Line Comment',
1063
+ Undo: 'Undo'};
1064
+ const cut = () => {
1065
+ return i18nString(UiStrings$2.Cut);
1066
+ };
1067
+ const copy = () => {
1068
+ return i18nString(UiStrings$2.Copy);
1069
+ };
1070
+ const paste = () => {
1071
+ return i18nString(UiStrings$2.Paste);
1072
+ };
1073
+ const undo = () => {
1074
+ return i18nString(UiStrings$2.Undo);
1075
+ };
1076
+ const redo = () => {
1077
+ return i18nString(UiStrings$2.Redo);
1078
+ };
1079
+ const toggleLineComment = () => {
1080
+ return i18nString(UiStrings$2.ToggleLineComment);
1081
+ };
1082
+ const toggleBlockComment = () => {
1083
+ return i18nString(UiStrings$2.ToggleBlockComment);
1084
+ };
1085
+ const selectAll = () => {
1086
+ return i18nString(UiStrings$2.SelectAll);
1087
+ };
1088
+ const copyLineUp = () => {
1089
+ return i18nString(UiStrings$2.CopyLineUp);
1090
+ };
1091
+ const copyLineDown = () => {
1092
+ return i18nString(UiStrings$2.CopyLineDown);
1093
+ };
1094
+ const moveLineUp = () => {
1095
+ return i18nString(UiStrings$2.MoveLineUp);
1096
+ };
1097
+ const moveLineDown = () => {
1098
+ return i18nString(UiStrings$2.MoveLineDown);
1099
+ };
1100
+
1101
+ const Edit$1 = 2;
1102
+ const File$2 = 5;
1103
+ const Go$1 = 6;
1104
+ const Help$1 = 7;
1105
+ const OpenRecent = 9;
1106
+ const Run$1 = 10;
1107
+ const Selection$1 = 11;
1108
+ const Terminal$1 = 14;
1109
+ const TitleBar = 15;
1110
+ const View$1 = 16;
1111
+
1112
+ const Separator$1 = 1;
1113
+ const None = 0;
1114
+ const SubMenu = 4;
1115
+ const Checked = 2;
1116
+ const Unchecked = 3;
1117
+ const Disabled = 5;
1118
+ const RestoreFocus = 6;
1119
+ const Ignore = 7;
1120
+
1121
+ const menuEntrySeparator = {
1122
+ id: 'separator',
1123
+ label: '',
1124
+ flags: Separator$1,
1125
+ command: ''
1126
+ };
1127
+
1128
+ const id$9 = Edit$1;
1129
+ const getMenuEntries$c = () => {
1130
+ return [{
1131
+ id: 'undo',
1132
+ label: undo(),
1133
+ flags: Disabled,
1134
+ command: /* TODO */'-1'
1135
+ }, {
1136
+ id: 'redo',
1137
+ label: redo(),
1138
+ flags: Disabled,
1139
+ command: /* TODO */'-1'
1140
+ }, menuEntrySeparator, {
1141
+ id: 'cut',
1142
+ label: cut(),
1143
+ flags: None,
1144
+ command: /* Editor.cut */'Editor.cut'
1145
+ }, {
1146
+ id: 'copy',
1147
+ label: copy(),
1148
+ flags: None,
1149
+ command: /* Editor.copy */'Editor.copy'
1150
+ }, {
1151
+ id: 'paste',
1152
+ label: paste(),
1153
+ flags: None,
1154
+ command: /* Editor.paste */'Editor.paste'
1155
+ }, menuEntrySeparator, {
1156
+ id: 'toggle-line-comment',
1157
+ label: toggleLineComment(),
1158
+ flags: None,
1159
+ command: /* Editor.toggleLineComment */'Editor.toggleLineComment'
1160
+ }, {
1161
+ id: 'toggle-block-comment',
1162
+ label: toggleBlockComment(),
1163
+ flags: None,
1164
+ command: /* Editor.toggleBlockComment */'Editor.toggleBlockComment'
1165
+ }];
1166
+ };
1167
+
1168
+ const MenuEntriesEdit = {
1169
+ __proto__: null,
1170
+ getMenuEntries: getMenuEntries$c,
1171
+ id: id$9
1172
+ };
1173
+
1174
+ /**
1175
+ * @enum {string}
1176
+ */
1177
+ const UiStrings$1 = {
1178
+ NewFile: 'New File',
1179
+ NewWindow: 'New Window',
1180
+ OpenFile: 'Open File',
1181
+ OpenFolder: 'Open Folder',
1182
+ OpenRecent: 'Open Recent',
1183
+ Exit: 'Exit',
1184
+ Save: 'Save',
1185
+ SaveAll: 'Save All'
1186
+ };
1187
+ const newFile = () => {
1188
+ return i18nString(UiStrings$1.NewFile);
1189
+ };
1190
+ const newWindow = () => {
1191
+ return i18nString(UiStrings$1.NewWindow);
1192
+ };
1193
+ const openFile = () => {
1194
+ return i18nString(UiStrings$1.OpenFile);
1195
+ };
1196
+ const openFolder = () => {
1197
+ return i18nString(UiStrings$1.OpenFolder);
1198
+ };
1199
+ const openRecent = () => {
1200
+ return i18nString(UiStrings$1.OpenRecent);
1201
+ };
1202
+ const save = () => {
1203
+ return i18nString(UiStrings$1.Save);
1204
+ };
1205
+ const saveAll = () => {
1206
+ return i18nString(UiStrings$1.SaveAll);
1207
+ };
1208
+ const exit = () => {
1209
+ return i18nString(UiStrings$1.Exit);
1210
+ };
1211
+
1212
+ const Web = 1;
1213
+ const Electron = 2;
1214
+
1215
+ const id$8 = File$2;
1216
+ const getMenuEntries$b = platform => {
1217
+ const entries = [{
1218
+ id: 'newFile',
1219
+ label: newFile(),
1220
+ flags: None,
1221
+ command: '-1'
1222
+ }, {
1223
+ id: 'newWindow',
1224
+ label: newWindow(),
1225
+ flags: None,
1226
+ command: /* Window.openNew */'Window.openNew'
1227
+ }, menuEntrySeparator, {
1228
+ id: 'openFile',
1229
+ label: openFile(),
1230
+ flags: None,
1231
+ command: 'Dialog.openFile'
1232
+ }, {
1233
+ id: 'openFolder',
1234
+ label: openFolder(),
1235
+ flags: RestoreFocus,
1236
+ command: 'Dialog.openFolder'
1237
+ }, {
1238
+ id: OpenRecent,
1239
+ label: openRecent(),
1240
+ flags: SubMenu,
1241
+ command: ''
1242
+ }, menuEntrySeparator, {
1243
+ id: 'save',
1244
+ label: save(),
1245
+ flags: None,
1246
+ command: 'Main.save'
1247
+ }, {
1248
+ id: 'saveAll',
1249
+ label: saveAll(),
1250
+ flags: None,
1251
+ command: 'Main.saveAll'
1252
+ }];
1253
+ if (platform === Electron) {
1254
+ entries.push(menuEntrySeparator, {
1255
+ id: 'exit',
1256
+ label: exit(),
1257
+ flags: Ignore,
1258
+ command: 'Chrome.exit'
1259
+ });
1260
+ }
1261
+ return entries;
1262
+ };
1263
+
1264
+ const MenuEntriesFile = {
1265
+ __proto__: null,
1266
+ getMenuEntries: getMenuEntries$b,
1267
+ id: id$8
1268
+ };
1269
+
1270
+ const id$7 = Go$1;
1271
+ const getMenuEntries$a = () => {
1272
+ return [];
1273
+ };
1274
+
1275
+ const MenuEntriesGo = {
1276
+ __proto__: null,
1277
+ getMenuEntries: getMenuEntries$a,
1278
+ id: id$7
1279
+ };
1280
+
1281
+ const About = 'About';
1282
+ const Edit = 'Edit';
1283
+ const File$1 = 'File';
1284
+ const Go = 'Go';
1285
+ const Help = 'Help';
1286
+ const OpenProcessExplorer = 'Open Process Explorer';
1287
+ const Run = 'Run';
1288
+ const Selection = 'Selection';
1289
+ const Terminal = 'Terminal';
1290
+ const ToggleDeveloperTools = 'Toggle Developer Tools';
1291
+ const View = 'View';
1292
+
1293
+ const toggleDeveloperTools = () => {
1294
+ return i18nString(ToggleDeveloperTools);
1295
+ };
1296
+ const openProcessExplorer = () => {
1297
+ return i18nString(OpenProcessExplorer);
1298
+ };
1299
+ const about = () => {
1300
+ return i18nString(About);
1301
+ };
1302
+
1303
+ const id$6 = Help$1;
1304
+ const getMenuEntries$9 = async platform => {
1305
+ const entries = [];
1306
+ if (platform !== Web) {
1307
+ entries.push({
1308
+ id: 'toggleDeveloperTools',
1309
+ label: toggleDeveloperTools(),
1310
+ flags: None,
1311
+ command: 'Developer.toggleDeveloperTools'
1312
+ }, {
1313
+ id: 'openProcessExplorer',
1314
+ label: openProcessExplorer(),
1315
+ flags: RestoreFocus,
1316
+ command: 'Developer.openProcessExplorer'
1317
+ });
1318
+ }
1319
+ if (entries.length > 0) {
1320
+ entries.push(menuEntrySeparator);
1321
+ }
1322
+ entries.push({
1323
+ id: 'about',
1324
+ label: about(),
1325
+ flags: None,
1326
+ command: 'About.showAbout'
1327
+ });
1328
+ return entries;
1329
+ };
1330
+
1331
+ const MenuEntriesHelp = {
1332
+ __proto__: null,
1333
+ getMenuEntries: getMenuEntries$9,
1334
+ id: id$6
1335
+ };
1336
+
1337
+ const rpcs = Object.create(null);
1338
+ const set$2 = (id, rpc) => {
1339
+ rpcs[id] = rpc;
1340
+ };
1341
+ const get = id => {
1342
+ return rpcs[id];
1343
+ };
1344
+
1345
+ const create = rpcId => {
1346
+ return {
1347
+ // @ts-ignore
1348
+ invoke(method, ...params) {
1349
+ const rpc = get(rpcId);
1350
+ // @ts-ignore
1351
+ return rpc.invoke(method, ...params);
1352
+ },
1353
+ // @ts-ignore
1354
+ invokeAndTransfer(method, ...params) {
1355
+ const rpc = get(rpcId);
1356
+ // @ts-ignore
1357
+ return rpc.invokeAndTransfer(method, ...params);
1358
+ },
1359
+ set(rpc) {
1360
+ set$2(rpcId, rpc);
1361
+ },
1362
+ async dispose() {
1363
+ const rpc = get(rpcId);
1364
+ await rpc.dispose();
1365
+ }
1366
+ };
1367
+ };
1368
+
1369
+ const {
1370
+ invoke: invoke$1,
1371
+ invokeAndTransfer,
1372
+ set: set$1,
1373
+ dispose
1374
+ } = create(RendererWorker$1);
1375
+ const searchFileHtml = async uri => {
1376
+ return invoke$1('ExtensionHost.searchFileWithHtml', uri);
1377
+ };
1378
+ const getFilePathElectron = async file => {
1379
+ return invoke$1('FileSystemHandle.getFilePathElectron', file);
1380
+ };
1381
+ const showContextMenu = async (x, y, id, ...args) => {
1382
+ return invoke$1('ContextMenu.show', x, y, id, ...args);
1383
+ };
1384
+ const getElectronVersion = async () => {
1385
+ return invoke$1('Process.getElectronVersion');
1386
+ };
1387
+ const applyBulkReplacement = async bulkEdits => {
1388
+ await invoke$1('BulkReplacement.applyBulkReplacement', bulkEdits);
1389
+ };
1390
+ const setColorTheme = async id => {
1391
+ // @ts-ignore
1392
+ return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1393
+ };
1394
+ const getNodeVersion = async () => {
1395
+ return invoke$1('Process.getNodeVersion');
1396
+ };
1397
+ const getChromeVersion = async () => {
1398
+ return invoke$1('Process.getChromeVersion');
1399
+ };
1400
+ const getV8Version = async () => {
1401
+ return invoke$1('Process.getV8Version');
1402
+ };
1403
+ const getFileHandles = async fileIds => {
1404
+ const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
1405
+ return files;
1406
+ };
1407
+ const setWorkspacePath = async path => {
1408
+ await invoke$1('Workspace.setPath', path);
1409
+ };
1410
+ const registerWebViewInterceptor = async (id, port) => {
1411
+ await invokeAndTransfer('WebView.registerInterceptor', id, port);
1412
+ };
1413
+ const unregisterWebViewInterceptor = async id => {
1414
+ await invoke$1('WebView.unregisterInterceptor', id);
1415
+ };
1416
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1417
+ const command = 'HandleMessagePort.handleMessagePort';
1418
+ // @ts-ignore
1419
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1420
+ };
1421
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1422
+ const command = 'Errors.handleMessagePort';
1423
+ // @ts-ignore
1424
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1425
+ };
1426
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1427
+ const command = 'Markdown.handleMessagePort';
1428
+ // @ts-ignore
1429
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1430
+ };
1431
+ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1432
+ const command = 'IconTheme.handleMessagePort';
1433
+ // @ts-ignore
1434
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1435
+ };
1436
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1437
+ const command = 'FileSystem.handleMessagePort';
1438
+ // @ts-ignore
1439
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1440
+ };
1441
+ const readFile = async uri => {
1442
+ return invoke$1('FileSystem.readFile', uri);
1443
+ };
1444
+ const getWebViewSecret = async key => {
1445
+ // @ts-ignore
1446
+ return invoke$1('WebView.getSecret', key);
1447
+ };
1448
+ const setWebViewPort = async (uid, port, origin, portType) => {
1449
+ return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1450
+ };
1451
+ const setFocus = key => {
1452
+ return invoke$1('Focus.setFocus', key);
1453
+ };
1454
+ const getFileIcon = async options => {
1455
+ return invoke$1('IconTheme.getFileIcon', options);
1456
+ };
1457
+ const getColorThemeNames = async () => {
1458
+ return invoke$1('ColorTheme.getColorThemeNames');
1459
+ };
1460
+ const disableExtension = async id => {
1461
+ // @ts-ignore
1462
+ return invoke$1('ExtensionManagement.disable', id);
1463
+ };
1464
+ const enableExtension = async id => {
1465
+ // @ts-ignore
1466
+ return invoke$1('ExtensionManagement.enable', id);
1467
+ };
1468
+ const handleDebugChange = async params => {
1469
+ // @ts-ignore
1470
+ return invoke$1('Run And Debug.handleChange', params);
1471
+ };
1472
+ const getFolderIcon = async options => {
1473
+ return invoke$1('IconTheme.getFolderIcon', options);
1474
+ };
1475
+ const closeWidget = async widgetId => {
1476
+ return invoke$1('Viewlet.closeWidget', widgetId);
1477
+ };
1478
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1479
+ const command = 'HandleMessagePort.handleMessagePort2';
1480
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1481
+ };
1482
+ const sendMessagePortToSearchProcess = async port => {
1483
+ await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1484
+ };
1485
+ const confirm = async (message, options) => {
1486
+ // @ts-ignore
1487
+ const result = await invoke$1('ConfirmPrompt.prompt', message, options);
1488
+ return result;
1489
+ };
1490
+ const getRecentlyOpened$1 = async () => {
1491
+ return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1492
+ };
1493
+ const getKeyBindings = async () => {
1494
+ return invoke$1('KeyBindingsInitial.getKeyBindings');
1495
+ };
1496
+ const writeClipBoardText = async text => {
1497
+ await invoke$1('ClipBoard.writeText', /* text */text);
1498
+ };
1499
+ const writeClipBoardImage = async blob => {
1500
+ // @ts-ignore
1501
+ await invoke$1('ClipBoard.writeImage', /* text */blob);
1502
+ };
1503
+ const searchFileMemory = async uri => {
1504
+ // @ts-ignore
1505
+ return invoke$1('ExtensionHost.searchFileWithMemory', uri);
1506
+ };
1507
+ const searchFileFetch = async uri => {
1508
+ return invoke$1('ExtensionHost.searchFileWithFetch', uri);
1509
+ };
1510
+ const showMessageBox = async options => {
1511
+ return invoke$1('ElectronDialog.showMessageBox', options);
1512
+ };
1513
+ const handleDebugResumed = async params => {
1514
+ await invoke$1('Run And Debug.handleResumed', params);
1515
+ };
1516
+ const openWidget = async name => {
1517
+ await invoke$1('Viewlet.openWidget', name);
1518
+ };
1519
+ const getIcons = async requests => {
1520
+ const icons = await invoke$1('IconTheme.getIcons', requests);
1521
+ return icons;
1522
+ };
1523
+ const activateByEvent = event => {
1524
+ return invoke$1('ExtensionHostManagement.activateByEvent', event);
1525
+ };
1526
+ const setAdditionalFocus = focusKey => {
1527
+ // @ts-ignore
1528
+ return invoke$1('Focus.setAdditionalFocus', focusKey);
1529
+ };
1530
+ const getActiveEditorId = () => {
1531
+ // @ts-ignore
1532
+ return invoke$1('GetActiveEditor.getActiveEditorId');
1533
+ };
1534
+ const getWorkspacePath = () => {
1535
+ return invoke$1('Workspace.getPath');
1536
+ };
1537
+ const sendMessagePortToRendererProcess = async port => {
1538
+ const command = 'HandleMessagePort.handleMessagePort';
1539
+ // @ts-ignore
1540
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1541
+ };
1542
+ const getPreference = async key => {
1543
+ return await invoke$1('Preferences.get', key);
1544
+ };
1545
+ const getAllExtensions = async () => {
1546
+ return invoke$1('ExtensionManagement.getAllExtensions');
1547
+ };
1548
+ const rerenderEditor = async key => {
1549
+ // @ts-ignore
1550
+ return invoke$1('Editor.rerender', key);
1551
+ };
1552
+ const handleDebugPaused = async params => {
1553
+ await invoke$1('Run And Debug.handlePaused', params);
1554
+ };
1555
+ const openUri = async (uri, focus, options) => {
1556
+ await invoke$1('Main.openUri', uri, focus, options);
1557
+ };
1558
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
1559
+ await invokeAndTransfer(
1560
+ // @ts-ignore
1561
+ 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1562
+ };
1563
+ const handleDebugScriptParsed = async script => {
1564
+ await invoke$1('Run And Debug.handleScriptParsed', script);
1565
+ };
1566
+ const getWindowId = async () => {
1567
+ return invoke$1('GetWindowId.getWindowId');
1568
+ };
1569
+ const getBlob = async uri => {
1570
+ // @ts-ignore
1571
+ return invoke$1('FileSystem.getBlob', uri);
1572
+ };
1573
+ const getExtensionCommands = async () => {
1574
+ return invoke$1('ExtensionHost.getCommands');
1575
+ };
1576
+ const showErrorDialog = async errorInfo => {
1577
+ // @ts-ignore
1578
+ await invoke$1('ErrorHandling.showErrorDialog', errorInfo);
1579
+ };
1580
+ const getFolderSize = async uri => {
1581
+ // @ts-ignore
1582
+ return await invoke$1('FileSystem.getFolderSize', uri);
1583
+ };
1584
+ const getExtension = async id => {
1585
+ // @ts-ignore
1586
+ return invoke$1('ExtensionManagement.getExtension', id);
1587
+ };
1588
+ const getMarkdownDom = async html => {
1589
+ // @ts-ignore
1590
+ return invoke$1('Markdown.getVirtualDom', html);
1591
+ };
1592
+ const renderMarkdown = async (markdown, options) => {
1593
+ // @ts-ignore
1594
+ return invoke$1('Markdown.renderMarkdown', markdown, options);
1595
+ };
1596
+ const openNativeFolder = async uri => {
1597
+ // @ts-ignore
1598
+ await invoke$1('OpenNativeFolder.openNativeFolder', uri);
1599
+ };
1600
+ const uninstallExtension = async id => {
1601
+ return invoke$1('ExtensionManagement.uninstall', id);
1602
+ };
1603
+ const installExtension = async id => {
1604
+ // @ts-ignore
1605
+ return invoke$1('ExtensionManagement.install', id);
1606
+ };
1607
+ const openExtensionSearch = async () => {
1608
+ // @ts-ignore
1609
+ return invoke$1('SideBar.openViewlet', 'Extensions');
1610
+ };
1611
+ const setExtensionsSearchValue = async searchValue => {
1612
+ // @ts-ignore
1613
+ return invoke$1('Extensions.handleInput', searchValue);
1614
+ };
1615
+ const openExternal = async uri => {
1616
+ // @ts-ignore
1617
+ await invoke$1('Open.openExternal', uri);
1618
+ };
1619
+ const openUrl = async uri => {
1620
+ // @ts-ignore
1621
+ await invoke$1('Open.openUrl', uri);
1622
+ };
1623
+ const getAllPreferences = async () => {
1624
+ // @ts-ignore
1625
+ return invoke$1('Preferences.getAll');
1626
+ };
1627
+ const showSaveFilePicker = async () => {
1628
+ // @ts-ignore
1629
+ return invoke$1('FilePicker.showSaveFilePicker');
1630
+ };
1631
+ const getLogsDir = async () => {
1632
+ // @ts-ignore
1633
+ return invoke$1('PlatformPaths.getLogsDir');
1634
+ };
1635
+ const registerMockRpc = commandMap => {
1636
+ const mockRpc = createMockRpc({
1637
+ commandMap
1638
+ });
1639
+ set$1(mockRpc);
1640
+ return mockRpc;
1641
+ };
1642
+
1643
+ const RendererWorker = {
1644
+ __proto__: null,
1645
+ activateByEvent,
1646
+ applyBulkReplacement,
1647
+ closeWidget,
1648
+ confirm,
1649
+ disableExtension,
1650
+ dispose,
1651
+ enableExtension,
1652
+ getActiveEditorId,
1653
+ getAllExtensions,
1654
+ getAllPreferences,
1655
+ getBlob,
1656
+ getChromeVersion,
1657
+ getColorThemeNames,
1658
+ getElectronVersion,
1659
+ getExtension,
1660
+ getExtensionCommands,
1661
+ getFileHandles,
1662
+ getFileIcon,
1663
+ getFilePathElectron,
1664
+ getFolderIcon,
1665
+ getFolderSize,
1666
+ getIcons,
1667
+ getKeyBindings,
1668
+ getLogsDir,
1669
+ getMarkdownDom,
1670
+ getNodeVersion,
1671
+ getPreference,
1672
+ getRecentlyOpened: getRecentlyOpened$1,
1673
+ getV8Version,
1674
+ getWebViewSecret,
1675
+ getWindowId,
1676
+ getWorkspacePath,
1677
+ handleDebugChange,
1678
+ handleDebugPaused,
1679
+ handleDebugResumed,
1680
+ handleDebugScriptParsed,
1681
+ installExtension,
1682
+ invoke: invoke$1,
1683
+ invokeAndTransfer,
1684
+ openExtensionSearch,
1685
+ openExternal,
1686
+ openNativeFolder,
1687
+ openUri,
1688
+ openUrl,
1689
+ openWidget,
1690
+ readFile,
1691
+ registerMockRpc,
1692
+ registerWebViewInterceptor,
1693
+ renderMarkdown,
1694
+ rerenderEditor,
1695
+ searchFileFetch,
1696
+ searchFileHtml,
1697
+ searchFileMemory,
1698
+ sendMessagePortToEditorWorker,
1699
+ sendMessagePortToErrorWorker,
1700
+ sendMessagePortToExtensionHostWorker,
1701
+ sendMessagePortToFileSystemWorker,
1702
+ sendMessagePortToIconThemeWorker,
1703
+ sendMessagePortToMarkdownWorker,
1704
+ sendMessagePortToRendererProcess,
1705
+ sendMessagePortToSearchProcess,
1706
+ sendMessagePortToSyntaxHighlightingWorker,
1707
+ set: set$1,
1708
+ setAdditionalFocus,
1709
+ setColorTheme,
1710
+ setExtensionsSearchValue,
1711
+ setFocus,
1712
+ setWebViewPort,
1713
+ setWorkspacePath,
1714
+ showContextMenu,
1715
+ showErrorDialog,
1716
+ showMessageBox,
1717
+ showSaveFilePicker,
1718
+ uninstallExtension,
1719
+ unregisterWebViewInterceptor,
1720
+ writeClipBoardImage,
1721
+ writeClipBoardText
1722
+ };
1723
+
1724
+ const {
1725
+ invoke,
1726
+ set
1727
+ } = RendererWorker;
1728
+
1729
+ const getRecentlyOpened = () => {
1730
+ return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1731
+ };
1732
+
1733
+ const File = 'file://';
1734
+
1735
+ const getTitle = (homeDir, uri) => {
1736
+ if (!uri) {
1737
+ return '';
1738
+ }
1739
+ if (uri.startsWith(File)) {
1740
+ return uri.slice(File.length);
1741
+ }
1742
+ return uri;
1743
+ };
1744
+
1745
+ const getHomeDir = () => {
1746
+ return '';
1747
+ };
1748
+
1749
+ const MAX_MENU_RECENT_ENTRIES = 10;
1750
+ const toMenuItem = folder => {
1751
+ const homeDir = getHomeDir();
1752
+ const label = getTitle(homeDir, folder);
1753
+ return {
1754
+ label,
1755
+ flags: None,
1756
+ command: 'Workspace.setPath',
1757
+ args: [folder]
1758
+ };
1759
+ };
1760
+ const id$5 = OpenRecent;
1761
+ const getMenuEntries$8 = async () => {
1762
+ const allItems = await getRecentlyOpened();
1763
+ const itemsToShow = allItems.slice(0, MAX_MENU_RECENT_ENTRIES);
1764
+ const items = [];
1765
+ if (itemsToShow.length > 0) {
1766
+ items.push(...itemsToShow.map(toMenuItem), menuEntrySeparator);
1767
+ }
1768
+ items.push({
1769
+ id: 'more',
1770
+ label: '...',
1771
+ flags: None,
1772
+ command: 'QuickPick.showRecent'
1773
+ }, menuEntrySeparator, {
1774
+ id: 'clearRecentlyOpened',
1775
+ label: 'clear',
1776
+ flags: None,
1777
+ command: 'RecentlyOpened.clearRecentlyOpened'
1778
+ });
1779
+ return items;
1780
+ };
1781
+
1782
+ const MenuEntriesOpenRecent = {
1783
+ __proto__: null,
1784
+ getMenuEntries: getMenuEntries$8,
1785
+ id: id$5
1786
+ };
1787
+
1788
+ const id$4 = Run$1;
1789
+ const getMenuEntries$7 = () => {
1790
+ return [];
1791
+ };
1792
+
1793
+ const MenuEntriesRun = {
1794
+ __proto__: null,
1795
+ getMenuEntries: getMenuEntries$7,
1796
+ id: id$4
1797
+ };
1798
+
1799
+ const id$3 = Selection$1;
1800
+ const getMenuEntries$6 = () => {
1801
+ return [{
1802
+ id: 'selectAll',
1803
+ label: selectAll(),
1804
+ flags: None,
1805
+ command: 'Editor.selectAll'
1806
+ }, {
1807
+ id: 'copyLineUp',
1808
+ label: copyLineUp(),
1809
+ flags: None,
1810
+ command: 'Editor.copyLineUp'
1811
+ }, {
1812
+ id: 'copyLineDown',
1813
+ label: copyLineDown(),
1814
+ flags: None,
1815
+ command: 'Editor.copyLineDown'
1816
+ }, {
1817
+ id: 'moveLineUp',
1818
+ label: moveLineUp(),
1819
+ flags: Disabled,
1820
+ command: 'Editor.moveLineUp'
1821
+ }, {
1822
+ id: 'moveLineDown',
1823
+ label: moveLineDown(),
1824
+ flags: Disabled,
1825
+ command: 'Editor.moveLineDown'
1826
+ }];
1827
+ };
1828
+
1829
+ const MenuEntriesSelection = {
1830
+ __proto__: null,
1831
+ getMenuEntries: getMenuEntries$6,
1832
+ id: id$3
1833
+ };
1834
+
1835
+ /**
1836
+ * @enum {string}
1837
+ */
1838
+ const UiStrings = {
1839
+ NewTerminal: 'New Terminal'
1840
+ };
1841
+ const newTerminal = () => {
1842
+ return i18nString(UiStrings.NewTerminal);
1843
+ };
1844
+
1845
+ const id$2 = Terminal$1;
1846
+ const getMenuEntries$5 = () => {
1847
+ return [{
1848
+ id: 'newTerminal',
1849
+ label: newTerminal(),
1850
+ flags: None,
1851
+ command: 'Layout.togglePanel',
1852
+ args: ['Terminal']
1853
+ }];
1854
+ };
1855
+
1856
+ const MenuEntriesTerminal = {
1857
+ __proto__: null,
1858
+ getMenuEntries: getMenuEntries$5,
1859
+ id: id$2
1860
+ };
1861
+
1862
+ const file = () => {
1863
+ return i18nString(File$1);
1864
+ };
1865
+ const edit = () => {
1866
+ return i18nString(Edit);
1867
+ };
1868
+ const selection = () => {
1869
+ return i18nString(Selection);
1870
+ };
1871
+ const view = () => {
1872
+ return i18nString(View);
1873
+ };
1874
+ const go = () => {
1875
+ return i18nString(Go);
1876
+ };
1877
+ const run = () => {
1878
+ return i18nString(Run);
1879
+ };
1880
+ const terminal = () => {
1881
+ return i18nString(Terminal);
1882
+ };
1883
+ const help = () => {
1884
+ return i18nString(Help);
1885
+ };
1886
+
1887
+ const getMenuEntries$4 = () => {
1888
+ return [{
1889
+ id: File$2,
1890
+ label: file(),
1891
+ flags: SubMenu
1892
+ }, {
1893
+ id: Edit$1,
1894
+ label: edit(),
1895
+ flags: SubMenu
1896
+ }, {
1897
+ id: Selection$1,
1898
+ label: selection(),
1899
+ flags: SubMenu
1900
+ }, {
1901
+ id: View$1,
1902
+ label: view(),
1903
+ flags: SubMenu
1904
+ }, {
1905
+ id: Go$1,
1906
+ label: go(),
1907
+ flags: SubMenu
1908
+ }, {
1909
+ id: Run$1,
1910
+ label: run(),
1911
+ keyboardShortCut: 'Alt+r',
1912
+ flags: SubMenu
1913
+ }, {
1914
+ id: Terminal$1,
1915
+ label: terminal(),
1916
+ keyboardShortCut: 'Alt+t',
1917
+ flags: SubMenu
1918
+ }, {
1919
+ id: Help$1,
1920
+ label: help(),
1921
+ keyboardShortCut: 'Alt+h',
1922
+ flags: SubMenu
1923
+ }];
1924
+ };
1925
+
1926
+ const getMenuEntries$3 = () => {
1927
+ return [{
1928
+ id: File$2,
1929
+ label: file(),
1930
+ flags: None
1931
+ }, {
1932
+ id: Edit$1,
1933
+ label: edit(),
1934
+ flags: None
1935
+ }, {
1936
+ id: Selection$1,
1937
+ label: selection(),
1938
+ flags: None
1939
+ }, {
1940
+ id: View$1,
1941
+ label: view(),
1942
+ flags: None
1943
+ }, {
1944
+ id: Go$1,
1945
+ label: go(),
1946
+ flags: None
1947
+ }, {
1948
+ id: Help$1,
1949
+ label: help(),
1950
+ flags: None
1951
+ }];
1952
+ };
1953
+
1954
+ const getFn = platform => {
1955
+ switch (platform) {
1956
+ case Web:
1957
+ return getMenuEntries$3;
1958
+ default:
1959
+ return getMenuEntries$4;
1960
+ }
1961
+ };
1962
+ const id$1 = TitleBar;
1963
+ const getMenuEntries$2 = async platform => {
1964
+ const fn = getFn(platform);
1965
+ return fn();
1966
+ };
1967
+
1968
+ const MenuEntriesTitleBar = {
1969
+ __proto__: null,
1970
+ getMenuEntries: getMenuEntries$2,
1971
+ id: id$1
1972
+ };
1973
+
1974
+ const id = View$1;
1975
+ const getMenuEntries$1 = () => {
1976
+ return [];
1977
+ };
1978
+
1979
+ const MenuEntriesView = {
1980
+ __proto__: null,
1981
+ getMenuEntries: getMenuEntries$1,
1982
+ id
1983
+ };
1984
+
1985
+ const menus$1 = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
1986
+
1987
+ const getMenuIds = () => {
1988
+ return menus$1.map(menu => menu.id);
1989
+ };
1990
+ const getMenuEntries = (id, platform) => {
1991
+ const menu = menus$1.find(item => item.id === id);
1992
+ if (!menu) {
1993
+ return [];
1994
+ }
1995
+ return menu.getMenuEntries(platform);
1996
+ };
1997
+
1998
+ const maximize = async () => {
1999
+ await invoke('ElectronWindow.maximize');
2000
+ };
2001
+ const minimize = async () => {
2002
+ await invoke('ElectronWindow.minimize');
2003
+ };
2004
+ const close = async () => {
2005
+ await invoke('ElectronWindow.close');
2006
+ };
2007
+
2008
+ const handleClickClose = async state => {
2009
+ await close();
2010
+ return state;
2011
+ };
2012
+
2013
+ const handleClickMinimize = async state => {
2014
+ await minimize();
2015
+ return state;
2016
+ };
2017
+
2018
+ const handleClickToggleMaximize = async state => {
2019
+ const fn = maximize;
2020
+ await fn();
2021
+ return state;
2022
+ };
2023
+
2024
+ const handleClick = (state, className) => {
2025
+ if (className.includes('Minimize')) {
2026
+ return handleClickMinimize(state);
2027
+ }
2028
+ if (className.includes('Maximize') || className.includes('Restore')) {
2029
+ return handleClickToggleMaximize(state);
2030
+ }
2031
+ if (className.includes('Close')) {
2032
+ return handleClickClose(state);
2033
+ }
2034
+ return state;
2035
+ };
2036
+
2037
+ const handleContextMenu = state => {
2038
+ return state;
2039
+ };
2040
+
2041
+ const loadContent = async (state, titleBarEntries) => {
2042
+ return {
2043
+ ...state
2044
+ };
2045
+ };
2046
+
2047
+ const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2048
+ const getMenus = () => {
2049
+ return menus;
2050
+ };
2051
+
2052
+ const renderFocusedIndex = (oldState, newState) => {
2053
+ if (newState.focusedIndex === -1) {
2054
+ return [];
2055
+ }
2056
+ return ['Viewlet.focusSelector', '.ViewletTitleBarMenuBar'];
2057
+ };
2058
+
2059
+ const Menu$1 = 'menu';
2060
+ const MenuItem$1 = 'menuitem';
2061
+ const MenuItemCheckBox = 'menuitemcheckbox';
2062
+ const Separator = 'separator';
2063
+
2064
+ const MaskIconCheck = 'MaskIconCheck';
2065
+ const Menu = 'Menu';
2066
+ const MenuItem = 'MenuItem';
2067
+ const MenuItemCheckMark = 'MenuItemCheckMark';
2068
+ const MenuItemCheckmarkIcon = 'MenuItemCheckmarkIcon';
2069
+ const MenuItemFocused = 'MenuItemFocused';
2070
+ const MenuItemKeyBinding = 'MenuItemKeyBinding';
2071
+ const MenuItemSeparator = 'MenuItemSeparator';
2072
+ const MenuItemSeparatorLine = 'MenuItemSeparatorLine';
2073
+ const MenuItemSubMenu = 'MenuItemSubMenu';
2074
+ const MenuItemSubMenuArrowRight = 'MenuItemSubMenuArrowRight';
2075
+
2076
+ const Div = 4;
2077
+ const Span = 8;
2078
+
2079
+ const checkboxChecked = {
2080
+ type: Div,
2081
+ className: mergeClassNames(MenuItem, MenuItemCheckMark),
2082
+ role: MenuItemCheckBox,
2083
+ ariaChecked: true,
2084
+ tabIndex: -1,
2085
+ childCount: 2
2086
+ };
2087
+ const checkMark = {
2088
+ type: Div,
2089
+ className: mergeClassNames(MenuItemCheckmarkIcon, MaskIconCheck)
2090
+ };
2091
+ const getMenuItemCheckedDom = menuItem => {
2092
+ const {
2093
+ label
2094
+ } = menuItem;
2095
+ return [checkboxChecked, checkMark, text(label)];
2096
+ };
2097
+
2098
+ const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
2099
+ let string = '';
2100
+ if (ctrlKey) {
2101
+ string += 'Ctrl+';
2102
+ }
2103
+ if (shiftKey) {
2104
+ string += 'Shift+';
2105
+ }
2106
+ string += key.toUpperCase();
2107
+ return string;
2108
+ };
2109
+
2110
+ const Backspace$1 = 1;
2111
+ const Tab$1 = 2;
2112
+ const Enter$1 = 3;
2113
+ const Escape$1 = 8;
2114
+ const Space$1 = 9;
2115
+ const PageUp$1 = 10;
2116
+ const PageDown$1 = 11;
2117
+ const End$1 = 255;
2118
+ const Home$1 = 12;
2119
+ const LeftArrow$1 = 13;
2120
+ const UpArrow$1 = 14;
2121
+ const RightArrow$1 = 15;
2122
+ const DownArrow$1 = 16;
2123
+ const Insert$1 = 17;
2124
+ const Delete$1 = 18;
2125
+ const Digit0$1 = 19;
2126
+ const Digit1$1 = 20;
2127
+ const Digit2$1 = 21;
2128
+ const Digit3$1 = 22;
2129
+ const Digit4$1 = 23;
2130
+ const Digit5$1 = 24;
2131
+ const Digit6$1 = 25;
2132
+ const Digit7$1 = 26;
2133
+ const Digit8$1 = 27;
2134
+ const Digit9$1 = 28;
2135
+ const KeyA$1 = 29;
2136
+ const KeyB$1 = 30;
2137
+ const KeyC$1 = 31;
2138
+ const KeyD$1 = 32;
2139
+ const KeyE$1 = 33;
2140
+ const KeyF$1 = 34;
2141
+ const KeyG$1 = 35;
2142
+ const KeyH$1 = 36;
2143
+ const KeyI$1 = 37;
2144
+ const KeyJ$1 = 38;
2145
+ const KeyK$1 = 39;
2146
+ const KeyL$1 = 40;
2147
+ const KeyM$1 = 41;
2148
+ const KeyN$1 = 42;
2149
+ const KeyO$1 = 43;
2150
+ const KeyP$1 = 44;
2151
+ const KeyQ$1 = 45;
2152
+ const KeyR$1 = 46;
2153
+ const KeyS$1 = 47;
2154
+ const KeyT$1 = 48;
2155
+ const KeyU$1 = 49;
2156
+ const KeyV$1 = 50;
2157
+ const KeyW$1 = 51;
2158
+ const KeyX$1 = 52;
2159
+ const KeyY$1 = 53;
2160
+ const KeyZ$1 = 54;
2161
+ const F1$1 = 57;
2162
+ const F2$1 = 58;
2163
+ const F3$1 = 59;
2164
+ const F4$1 = 60;
2165
+ const F5$1 = 61;
2166
+ const F6$1 = 62;
2167
+ const Equal$1 = 84;
2168
+ const Comma$1 = 85;
2169
+ const Minus$1 = 86;
2170
+ const Backquote$1 = 89;
2171
+ const Backslash$1 = 91;
2172
+ const Star$1 = 131;
2173
+ const Plus$1 = 132;
2174
+
2175
+ const Unknown = 'Unknown';
2176
+ const Backspace = 'Backspace';
2177
+ const Tab = 'Tab';
2178
+ const Enter = 'Enter';
2179
+ const Escape = 'Escape';
2180
+ const Space = 'Space';
2181
+ const PageUp = 'PageUp';
2182
+ const PageDown = 'PageDown';
2183
+ const End = 'End';
2184
+ const Home = 'Home';
2185
+ const LeftArrow = 'LeftArrow';
2186
+ const UpArrow = 'UpArrow';
2187
+ const RightArrow = 'RightArrow';
2188
+ const DownArrow = 'DownArrow';
2189
+ const Insert = 'Insert';
2190
+ const Delete = 'Delete';
2191
+ const Digit0 = '0';
2192
+ const Digit1 = '1';
2193
+ const Digit2 = '2';
2194
+ const Digit3 = '3';
2195
+ const Digit4 = '4';
2196
+ const Digit5 = '5';
2197
+ const Digit6 = '6';
2198
+ const Digit7 = '7';
2199
+ const Digit8 = '8';
2200
+ const Digit9 = '9';
2201
+ const KeyA = 'a';
2202
+ const KeyB = 'b';
2203
+ const KeyC = 'c';
2204
+ const KeyD = 'd';
2205
+ const KeyE = 'e';
2206
+ const KeyF = 'f';
2207
+ const KeyG = 'g';
2208
+ const KeyH = 'h';
2209
+ const KeyI = 'i';
2210
+ const KeyJ = 'j';
2211
+ const KeyK = 'k';
2212
+ const KeyL = 'l';
2213
+ const KeyM = 'm';
2214
+ const KeyN = 'n';
2215
+ const KeyO = 'o';
2216
+ const KeyP = 'p';
2217
+ const KeyQ = 'q';
2218
+ const KeyR = 'r';
2219
+ const KeyS = 's';
2220
+ const KeyT = 't';
2221
+ const KeyU = 'u';
2222
+ const KeyV = 'v';
2223
+ const KeyW = 'w';
2224
+ const KeyX = 'x';
2225
+ const KeyY = 'y';
2226
+ const KeyZ = 'z';
2227
+ const F1 = 'F1';
2228
+ const F2 = 'F2';
2229
+ const F3 = 'F3';
2230
+ const F4 = 'F4';
2231
+ const F5 = 'F5';
2232
+ const F6 = 'F6';
2233
+ const Equal = '=';
2234
+ const Comma = ',';
2235
+ const Minus = 'Minus';
2236
+ const Backquote = 'Backquote';
2237
+ const Backslash = 'Backslash';
2238
+ const Star = '*';
2239
+ const Plus = '+';
2240
+
2241
+ const getKeyCodeString = keyCode => {
2242
+ switch (keyCode) {
2243
+ case Backspace$1:
2244
+ return Backspace;
2245
+ case Tab$1:
2246
+ return Tab;
2247
+ case Escape$1:
2248
+ return Escape;
2249
+ case Enter$1:
2250
+ return Enter;
2251
+ case Space$1:
2252
+ return Space;
2253
+ case PageUp$1:
2254
+ return PageUp;
2255
+ case PageDown$1:
2256
+ return PageDown;
2257
+ case End$1:
2258
+ return End;
2259
+ case Home$1:
2260
+ return Home;
2261
+ case LeftArrow$1:
2262
+ return LeftArrow;
2263
+ case UpArrow$1:
2264
+ return UpArrow;
2265
+ case RightArrow$1:
2266
+ return RightArrow;
2267
+ case DownArrow$1:
2268
+ return DownArrow;
2269
+ case Insert$1:
2270
+ return Insert;
2271
+ case Delete$1:
2272
+ return Delete;
2273
+ case Digit0$1:
2274
+ return Digit0;
2275
+ case Digit1$1:
2276
+ return Digit1;
2277
+ case Digit2$1:
2278
+ return Digit2;
2279
+ case Digit3$1:
2280
+ return Digit3;
2281
+ case Digit4$1:
2282
+ return Digit4;
2283
+ case Digit5$1:
2284
+ return Digit5;
2285
+ case Digit6$1:
2286
+ return Digit6;
2287
+ case Digit7$1:
2288
+ return Digit7;
2289
+ case Digit8$1:
2290
+ return Digit8;
2291
+ case Digit9$1:
2292
+ return Digit9;
2293
+ case KeyA$1:
2294
+ return KeyA;
2295
+ case KeyB$1:
2296
+ return KeyB;
2297
+ case KeyC$1:
2298
+ return KeyC;
2299
+ case KeyD$1:
2300
+ return KeyD;
2301
+ case KeyE$1:
2302
+ return KeyE;
2303
+ case KeyF$1:
2304
+ return KeyF;
2305
+ case KeyG$1:
2306
+ return KeyG;
2307
+ case KeyH$1:
2308
+ return KeyH;
2309
+ case KeyI$1:
2310
+ return KeyI;
2311
+ case KeyJ$1:
2312
+ return KeyJ;
2313
+ case KeyK$1:
2314
+ return KeyK;
2315
+ case KeyL$1:
2316
+ return KeyL;
2317
+ case KeyM$1:
2318
+ return KeyM;
2319
+ case KeyN$1:
2320
+ return KeyN;
2321
+ case KeyO$1:
2322
+ return KeyO;
2323
+ case KeyP$1:
2324
+ return KeyP;
2325
+ case KeyQ$1:
2326
+ return KeyQ;
2327
+ case KeyR$1:
2328
+ return KeyR;
2329
+ case KeyS$1:
2330
+ return KeyS;
2331
+ case KeyT$1:
2332
+ return KeyT;
2333
+ case KeyU$1:
2334
+ return KeyU;
2335
+ case KeyV$1:
2336
+ return KeyV;
2337
+ case KeyW$1:
2338
+ return KeyW;
2339
+ case KeyX$1:
2340
+ return KeyX;
2341
+ case KeyY$1:
2342
+ return KeyY;
2343
+ case KeyZ$1:
2344
+ return KeyZ;
2345
+ case F1$1:
2346
+ return F1;
2347
+ case F2$1:
2348
+ return F2;
2349
+ case F3$1:
2350
+ return F3;
2351
+ case F4$1:
2352
+ return F4;
2353
+ case F5$1:
2354
+ return F5;
2355
+ case F6$1:
2356
+ return F6;
2357
+ case Backslash$1:
2358
+ return Backslash;
2359
+ case Equal$1:
2360
+ return Equal;
2361
+ case Comma$1:
2362
+ return Comma;
2363
+ case Backquote$1:
2364
+ return Backquote;
2365
+ case Plus$1:
2366
+ return Plus;
2367
+ case Star$1:
2368
+ return Star;
2369
+ case Minus$1:
2370
+ return Minus;
2371
+ default:
2372
+ return Unknown;
2373
+ }
2374
+ };
2375
+
2376
+ const parseKey = rawKey => {
2377
+ number(rawKey);
2378
+ const isCtrl = Boolean(rawKey & CtrlCmd);
2379
+ const isShift = Boolean(rawKey & Shift);
2380
+ const keyCode = rawKey & 0x00_00_00_ff;
2381
+ const key = getKeyCodeString(keyCode);
2382
+ return {
2383
+ key,
2384
+ isCtrl,
2385
+ isShift
2386
+ };
2387
+ };
2388
+
2389
+ const getMenuItemDefaultDom = menuItem => {
2390
+ const {
2391
+ label,
2392
+ isFocused,
2393
+ key
2394
+ } = menuItem;
2395
+ let className = MenuItem;
2396
+ if (isFocused) {
2397
+ className += ' ' + MenuItemFocused;
2398
+ }
2399
+ const dom = [{
2400
+ type: Div,
2401
+ className,
2402
+ role: MenuItem$1,
2403
+ tabIndex: -1,
2404
+ childCount: 1
2405
+ }, text(label)];
2406
+ if (key) {
2407
+ dom[0].childCount++;
2408
+ const parsedKey = parseKey(key);
2409
+ const keyBindingsString = getKeyBindingString(parsedKey.key, false, parsedKey.isCtrl, parsedKey.isShift);
2410
+ dom.push({
2411
+ type: Span,
2412
+ className: MenuItemKeyBinding,
2413
+ childCount: 1
2414
+ }, text(keyBindingsString));
2415
+ }
2416
+ return dom;
2417
+ };
2418
+
2419
+ const disabled = {
2420
+ type: Div,
2421
+ className: MenuItem,
2422
+ role: MenuItem$1,
2423
+ tabIndex: -1,
2424
+ disabled: true,
2425
+ childCount: 1
2426
+ };
2427
+ const getMenuItemDisabledDom = menuItem => {
2428
+ const {
2429
+ label
2430
+ } = menuItem;
2431
+ return [disabled, text(label)];
2432
+ };
2433
+
2434
+ const getMenuItemsNoopDom = () => {
2435
+ return [];
2436
+ };
2437
+
2438
+ const separator = {
2439
+ type: Div,
2440
+ className: MenuItemSeparator,
2441
+ role: Separator,
2442
+ childCount: 1
2443
+ };
2444
+ const separatorLine = {
2445
+ type: Div,
2446
+ className: MenuItemSeparatorLine,
2447
+ childCount: 0
2448
+ };
2449
+ const getMenuItemSeparatorDom = menuItem => {
2450
+ return [separator, separatorLine];
2451
+ };
2452
+
2453
+ const arrowRight = {
2454
+ type: Div,
2455
+ className: MenuItemSubMenuArrowRight,
2456
+ childCount: 0
2457
+ };
2458
+ const getMenuItemSubMenuDom = menuItem => {
2459
+ const {
2460
+ label,
2461
+ isFocused,
2462
+ isExpanded,
2463
+ level
2464
+ } = menuItem;
2465
+ let className = MenuItem;
2466
+ className += ' ' + MenuItemSubMenu;
2467
+ if (isFocused) {
2468
+ className += ' ' + MenuItemFocused;
2469
+ }
2470
+ return [{
2471
+ type: Div,
2472
+ className,
2473
+ role: MenuItem$1,
2474
+ tabIndex: -1,
2475
+ ariaHasPopup: true,
2476
+ ariaExpanded: isExpanded,
2477
+ ariaOwns: isExpanded ? `Menu-${level + 1}` : undefined,
2478
+ childCount: 2
2479
+ }, text(label), arrowRight];
2480
+ };
2481
+
2482
+ const checkboxUnchecked = {
2483
+ type: Div,
2484
+ className: MenuItem,
2485
+ role: MenuItemCheckBox,
2486
+ ariaChecked: false,
2487
+ tabIndex: -1,
2488
+ childCount: 1
2489
+ };
2490
+ const getMenuItemUncheckedDom = menuItem => {
2491
+ const {
2492
+ label
2493
+ } = menuItem;
2494
+ return [checkboxUnchecked, text(label)];
2495
+ };
2496
+
2497
+ const getMenuItemRenderer = flags => {
2498
+ switch (flags) {
2499
+ case None:
2500
+ case RestoreFocus:
2501
+ case Ignore:
2502
+ return getMenuItemDefaultDom;
2503
+ case Separator$1:
2504
+ return getMenuItemSeparatorDom;
2505
+ case Checked:
2506
+ return getMenuItemCheckedDom;
2507
+ case Unchecked:
2508
+ return getMenuItemUncheckedDom;
2509
+ case Disabled:
2510
+ return getMenuItemDisabledDom;
2511
+ case SubMenu:
2512
+ return getMenuItemSubMenuDom;
2513
+ default:
2514
+ return getMenuItemsNoopDom;
2515
+ }
2516
+ };
2517
+
2518
+ const getMenuItemVirtualDom = menuItem => {
2519
+ const {
2520
+ flags
2521
+ } = menuItem;
2522
+ const fn = getMenuItemRenderer(flags);
2523
+ return fn(menuItem);
2524
+ };
2525
+
2526
+ const getMenuVirtualDom = menuItems => {
2527
+ const dom = [{
2528
+ type: Div,
2529
+ className: Menu,
2530
+ role: Menu$1,
2531
+ tabIndex: -1,
2532
+ childCount: menuItems.length
2533
+ }, ...menuItems.flatMap(getMenuItemVirtualDom)];
2534
+ return dom;
2535
+ };
2536
+
2537
+ const getVisible = (items, focusedIndex, expanded, level) => {
2538
+ const visibleItems = [];
2539
+ for (let i = 0; i < items.length; i++) {
2540
+ const item = items[i];
2541
+ const {
2542
+ flags,
2543
+ label
2544
+ } = item;
2545
+ visibleItems.push({
2546
+ label,
2547
+ flags,
2548
+ isFocused: i === focusedIndex,
2549
+ isExpanded: i === focusedIndex && expanded,
2550
+ level,
2551
+ key: item.key
2552
+ });
2553
+ }
2554
+ return visibleItems;
2555
+ };
2556
+
2557
+ const SetMenus = 'setMenus';
2558
+
2559
+ const renderMenus = (oldState, newState) => {
2560
+ const oldMenus = oldState.menus;
2561
+ const newMenus = newState.menus;
2562
+ const oldLength = oldMenus.length;
2563
+ const newLength = newMenus.length;
2564
+ const commonLength = Math.min(oldLength, newLength);
2565
+ const changes = [];
2566
+ for (let i = 0; i < commonLength; i++) {
2567
+ const oldMenu = oldMenus[i];
2568
+ const newMenu = newMenus[i];
2569
+ if (oldMenu !== newMenu) {
2570
+ const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
2571
+ const dom = getMenuVirtualDom(visible).slice(1);
2572
+ changes.push([/* method */'updateMenu', newMenu, /* newLength */newLength, dom]);
2573
+ }
2574
+ }
2575
+ const difference = newLength - oldLength;
2576
+ if (difference > 0) {
2577
+ const newMenu = newMenus.at(-1);
2578
+ const visible = getVisible(newMenu.items, newMenu.focusedIndex, newMenu.expanded, newMenu.level);
2579
+ const dom = getMenuVirtualDom(visible).slice(1);
2580
+ changes.push(['addMenu', newMenu, dom]);
2581
+ } else if (difference < 0) {
2582
+ changes.push(['closeMenus', newLength]);
2583
+ }
2584
+ return ['Viewlet.send', newState.uid, /* method */SetMenus, /* changes */changes, newState.uid];
2585
+ };
2586
+
2587
+ const getRenderer = diffType => {
2588
+ switch (diffType) {
2589
+ case RenderFocusedIndex:
2590
+ return renderFocusedIndex;
2591
+ case RenderMenus:
2592
+ return renderMenus;
2593
+ default:
2594
+ throw new Error('unknown renderer');
2595
+ }
2596
+ };
2597
+
2598
+ const applyRender = (oldState, newState, diffResult) => {
2599
+ const commands = [];
2600
+ for (const item of diffResult) {
2601
+ const fn = getRenderer(item);
2602
+ const result = fn(oldState, newState);
2603
+ if (result.length > 0) {
2604
+ commands.push(result);
2605
+ }
2606
+ }
2607
+ return commands;
2608
+ };
2609
+
2610
+ const render2 = async (uid, diffResult) => {
2611
+ const {
2612
+ oldState,
2613
+ newState
2614
+ } = get$1(uid);
2615
+ set$3(uid, newState, newState);
2616
+ const commands = applyRender(oldState, newState, diffResult);
2617
+ return commands;
2618
+ };
2619
+
2620
+ const HandleClick = 'handleClick';
2621
+ const HandleFocusIn = 'handleFocusIn';
2622
+ const HandlePointerOut = 'handlePointerOut';
2623
+ const HandlePointerOver = 'handlePointerOver';
2624
+ const HandleMenuClick = 'handleMenuClick';
2625
+ const HandleMenuMouseOver = 'handleMenuMouseOver';
2626
+
2627
+ const renderEventListeners = () => {
2628
+ return [{
2629
+ name: HandleFocusIn,
2630
+ params: ['handleFocus']
2631
+ }, {
2632
+ name: HandleMenuClick,
2633
+ params: ['handleMenuClick', 'event.clientX', 'event.clientY']
2634
+ }, {
2635
+ name: HandleMenuMouseOver,
2636
+ params: ['handleMenuMouseOver', 'event.clientX', 'event.clientY']
2637
+ }, {
2638
+ name: HandleClick,
2639
+ params: ['handleClickAt', 'event.button', 'event.clientX', 'event.clientY']
2640
+ }, {
2641
+ name: HandlePointerOut,
2642
+ params: ['handlePointerOut', 'event.clientX', 'event.clientY']
2643
+ }, {
2644
+ name: HandlePointerOver,
2645
+ params: ['handlePointerOver', 'event.clientX', 'event.clientY']
2646
+ }];
2647
+ };
2648
+
2649
+ const saveState = uid => {
2650
+ return {
2651
+ x: 1
2652
+ };
2653
+ };
2654
+
2655
+ const wrapCommand = fn => {
2656
+ const wrapped = async (uid, ...args) => {
2657
+ const {
2658
+ newState
2659
+ } = get$1(uid);
2660
+ const newerState = await fn(newState, ...args);
2661
+ if (newState === newerState) {
2662
+ return;
2663
+ }
2664
+ const latest = get$1(uid);
2665
+ set$3(uid, latest.oldState, newerState);
2666
+ };
2667
+ return wrapped;
2668
+ };
2669
+
2670
+ const commandMap = {
2671
+ 'Menu.getMenuEntries': getMenuEntries,
2672
+ 'Menu.getMenuIds': getMenuIds,
2673
+ 'Menu.handleButtonsClick': handleClick,
2674
+ 'Menu.handleContextMenu': handleContextMenu,
2675
+ 'Menu.renderEventListeners': renderEventListeners,
2676
+ 'Menu.diff2': diff2,
2677
+ 'Menu.getCommands': getCommandIds,
2678
+ 'Menu.getKeyBindings': getKeyBindings$1,
2679
+ 'Menu.getMenus': getMenus,
2680
+ 'Menu.loadContent': wrapCommand(loadContent),
2681
+ 'Menu.render2': render2,
2682
+ 'Menu.saveState': saveState
2683
+ };
2684
+
2685
+ const listen = async () => {
2686
+ const rpc = await WebWorkerRpcClient.create({
2687
+ commandMap: commandMap
2688
+ });
2689
+ set(rpc);
2690
+ };
2691
+
2692
+ const main = async () => {
2693
+ await listen();
2694
+ };
2695
+
2696
+ main();