@lvce-editor/activity-bar-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,1656 @@
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
+ message,
186
+ code: ERR_MODULE_NOT_FOUND
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
+ message: `Incompatible native node module: ${message}`,
210
+ code: E_INCOMPATIBLE_NATIVE_MODULE
211
+ };
212
+ };
213
+ const getModuleSyntaxError = () => {
214
+ return {
215
+ message: `ES Modules are not supported in electron`,
216
+ code: E_MODULES_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
+ message: actualMessage,
236
+ code: '',
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
+ message,
247
+ code,
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
+ resolve,
309
+ promise
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
+ jsonrpc: '2.0',
330
+ id: firstMessage.id,
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
+ const Two = '2.0';
373
+ const create$4 = (method, params) => {
374
+ return {
375
+ jsonrpc: Two,
376
+ method,
377
+ params
378
+ };
379
+ };
380
+ const callbacks = Object.create(null);
381
+ const set$4 = (id, fn) => {
382
+ callbacks[id] = fn;
383
+ };
384
+ const get$2 = id => {
385
+ return callbacks[id];
386
+ };
387
+ const remove = id => {
388
+ delete callbacks[id];
389
+ };
390
+ let id = 0;
391
+ const create$3 = () => {
392
+ return ++id;
393
+ };
394
+ const registerPromise = () => {
395
+ const id = create$3();
396
+ const {
397
+ resolve,
398
+ promise
399
+ } = Promise.withResolvers();
400
+ set$4(id, resolve);
401
+ return {
402
+ id,
403
+ promise
404
+ };
405
+ };
406
+ const create$2$1 = (method, params) => {
407
+ const {
408
+ id,
409
+ promise
410
+ } = registerPromise();
411
+ const message = {
412
+ jsonrpc: Two,
413
+ method,
414
+ params,
415
+ id
416
+ };
417
+ return {
418
+ message,
419
+ promise
420
+ };
421
+ };
422
+ class JsonRpcError extends Error {
423
+ constructor(message) {
424
+ super(message);
425
+ this.name = 'JsonRpcError';
426
+ }
427
+ }
428
+ const NewLine = '\n';
429
+ const DomException = 'DOMException';
430
+ const ReferenceError$1 = 'ReferenceError';
431
+ const SyntaxError$1 = 'SyntaxError';
432
+ const TypeError$1 = 'TypeError';
433
+ const getErrorConstructor = (message, type) => {
434
+ if (type) {
435
+ switch (type) {
436
+ case DomException:
437
+ return DOMException;
438
+ case TypeError$1:
439
+ return TypeError;
440
+ case SyntaxError$1:
441
+ return SyntaxError;
442
+ case ReferenceError$1:
443
+ return ReferenceError;
444
+ default:
445
+ return Error;
446
+ }
447
+ }
448
+ if (message.startsWith('TypeError: ')) {
449
+ return TypeError;
450
+ }
451
+ if (message.startsWith('SyntaxError: ')) {
452
+ return SyntaxError;
453
+ }
454
+ if (message.startsWith('ReferenceError: ')) {
455
+ return ReferenceError;
456
+ }
457
+ return Error;
458
+ };
459
+ const constructError = (message, type, name) => {
460
+ const ErrorConstructor = getErrorConstructor(message, type);
461
+ if (ErrorConstructor === DOMException && name) {
462
+ return new ErrorConstructor(message, name);
463
+ }
464
+ if (ErrorConstructor === Error) {
465
+ const error = new Error(message);
466
+ if (name && name !== 'VError') {
467
+ error.name = name;
468
+ }
469
+ return error;
470
+ }
471
+ return new ErrorConstructor(message);
472
+ };
473
+ const joinLines = lines => {
474
+ return lines.join(NewLine);
475
+ };
476
+ const splitLines = lines => {
477
+ return lines.split(NewLine);
478
+ };
479
+ const getCurrentStack = () => {
480
+ const stackLinesToSkip = 3;
481
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
482
+ return currentStack;
483
+ };
484
+ const getNewLineIndex = (string, startIndex = undefined) => {
485
+ return string.indexOf(NewLine, startIndex);
486
+ };
487
+ const getParentStack = error => {
488
+ let parentStack = error.stack || error.data || error.message || '';
489
+ if (parentStack.startsWith(' at')) {
490
+ parentStack = error.message + NewLine + parentStack;
491
+ }
492
+ return parentStack;
493
+ };
494
+ const MethodNotFound = -32601;
495
+ const Custom = -32001;
496
+ const restoreJsonRpcError = error => {
497
+ const currentStack = getCurrentStack();
498
+ if (error && error instanceof Error) {
499
+ if (typeof error.stack === 'string') {
500
+ error.stack = error.stack + NewLine + currentStack;
501
+ }
502
+ return error;
503
+ }
504
+ if (error && error.code && error.code === MethodNotFound) {
505
+ const restoredError = new JsonRpcError(error.message);
506
+ const parentStack = getParentStack(error);
507
+ restoredError.stack = parentStack + NewLine + currentStack;
508
+ return restoredError;
509
+ }
510
+ if (error && error.message) {
511
+ const restoredError = constructError(error.message, error.type, error.name);
512
+ if (error.data) {
513
+ if (error.data.stack && error.data.type && error.message) {
514
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
515
+ } else if (error.data.stack) {
516
+ restoredError.stack = error.data.stack;
517
+ }
518
+ if (error.data.codeFrame) {
519
+ // @ts-ignore
520
+ restoredError.codeFrame = error.data.codeFrame;
521
+ }
522
+ if (error.data.code) {
523
+ // @ts-ignore
524
+ restoredError.code = error.data.code;
525
+ }
526
+ if (error.data.type) {
527
+ // @ts-ignore
528
+ restoredError.name = error.data.type;
529
+ }
530
+ } else {
531
+ if (error.stack) {
532
+ const lowerStack = restoredError.stack || '';
533
+ // @ts-ignore
534
+ const indexNewLine = getNewLineIndex(lowerStack);
535
+ const parentStack = getParentStack(error);
536
+ // @ts-ignore
537
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
538
+ }
539
+ if (error.codeFrame) {
540
+ // @ts-ignore
541
+ restoredError.codeFrame = error.codeFrame;
542
+ }
543
+ }
544
+ return restoredError;
545
+ }
546
+ if (typeof error === 'string') {
547
+ return new Error(`JsonRpc Error: ${error}`);
548
+ }
549
+ return new Error(`JsonRpc Error: ${error}`);
550
+ };
551
+ const unwrapJsonRpcResult = responseMessage => {
552
+ if ('error' in responseMessage) {
553
+ const restoredError = restoreJsonRpcError(responseMessage.error);
554
+ throw restoredError;
555
+ }
556
+ if ('result' in responseMessage) {
557
+ return responseMessage.result;
558
+ }
559
+ throw new JsonRpcError('unexpected response message');
560
+ };
561
+ const warn = (...args) => {
562
+ console.warn(...args);
563
+ };
564
+ const resolve = (id, response) => {
565
+ const fn = get$2(id);
566
+ if (!fn) {
567
+ console.log(response);
568
+ warn(`callback ${id} may already be disposed`);
569
+ return;
570
+ }
571
+ fn(response);
572
+ remove(id);
573
+ };
574
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
575
+ const getErrorType = prettyError => {
576
+ if (prettyError && prettyError.type) {
577
+ return prettyError.type;
578
+ }
579
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
580
+ return prettyError.constructor.name;
581
+ }
582
+ return undefined;
583
+ };
584
+ const isAlreadyStack = line => {
585
+ return line.trim().startsWith('at ');
586
+ };
587
+ const getStack = prettyError => {
588
+ const stackString = prettyError.stack || '';
589
+ const newLineIndex = stackString.indexOf('\n');
590
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
591
+ return stackString.slice(newLineIndex + 1);
592
+ }
593
+ return stackString;
594
+ };
595
+ const getErrorProperty = (error, prettyError) => {
596
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
597
+ return {
598
+ code: MethodNotFound,
599
+ message: error.message,
600
+ data: error.stack
601
+ };
602
+ }
603
+ return {
604
+ code: Custom,
605
+ message: prettyError.message,
606
+ data: {
607
+ stack: getStack(prettyError),
608
+ codeFrame: prettyError.codeFrame,
609
+ type: getErrorType(prettyError),
610
+ code: prettyError.code,
611
+ name: prettyError.name
612
+ }
613
+ };
614
+ };
615
+ const create$1$1 = (id, error) => {
616
+ return {
617
+ jsonrpc: Two,
618
+ id,
619
+ error
620
+ };
621
+ };
622
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
623
+ const prettyError = preparePrettyError(error);
624
+ logError(error, prettyError);
625
+ const errorProperty = getErrorProperty(error, prettyError);
626
+ return create$1$1(id, errorProperty);
627
+ };
628
+ const create$5 = (message, result) => {
629
+ return {
630
+ jsonrpc: Two,
631
+ id: message.id,
632
+ result: result ?? null
633
+ };
634
+ };
635
+ const getSuccessResponse = (message, result) => {
636
+ const resultProperty = result ?? null;
637
+ return create$5(message, resultProperty);
638
+ };
639
+ const getErrorResponseSimple = (id, error) => {
640
+ return {
641
+ jsonrpc: Two,
642
+ id,
643
+ error: {
644
+ code: Custom,
645
+ // @ts-ignore
646
+ message: error.message,
647
+ data: error
648
+ }
649
+ };
650
+ };
651
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
652
+ try {
653
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
654
+ return getSuccessResponse(message, result);
655
+ } catch (error) {
656
+ if (ipc.canUseSimpleErrorResponse) {
657
+ return getErrorResponseSimple(message.id, error);
658
+ }
659
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
660
+ }
661
+ };
662
+ const defaultPreparePrettyError = error => {
663
+ return error;
664
+ };
665
+ const defaultLogError = () => {
666
+ // ignore
667
+ };
668
+ const defaultRequiresSocket = () => {
669
+ return false;
670
+ };
671
+ const defaultResolve = resolve;
672
+
673
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
674
+ const normalizeParams = args => {
675
+ if (args.length === 1) {
676
+ const options = args[0];
677
+ return {
678
+ ipc: options.ipc,
679
+ message: options.message,
680
+ execute: options.execute,
681
+ resolve: options.resolve || defaultResolve,
682
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
683
+ logError: options.logError || defaultLogError,
684
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
685
+ };
686
+ }
687
+ return {
688
+ ipc: args[0],
689
+ message: args[1],
690
+ execute: args[2],
691
+ resolve: args[3],
692
+ preparePrettyError: args[4],
693
+ logError: args[5],
694
+ requiresSocket: args[6]
695
+ };
696
+ };
697
+ const handleJsonRpcMessage = async (...args) => {
698
+ const options = normalizeParams(args);
699
+ const {
700
+ message,
701
+ ipc,
702
+ execute,
703
+ resolve,
704
+ preparePrettyError,
705
+ logError,
706
+ requiresSocket
707
+ } = options;
708
+ if ('id' in message) {
709
+ if ('method' in message) {
710
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
711
+ try {
712
+ ipc.send(response);
713
+ } catch (error) {
714
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
715
+ ipc.send(errorResponse);
716
+ }
717
+ return;
718
+ }
719
+ resolve(message.id, message);
720
+ return;
721
+ }
722
+ if ('method' in message) {
723
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
724
+ return;
725
+ }
726
+ throw new JsonRpcError('unexpected message');
727
+ };
728
+ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
729
+ const {
730
+ message,
731
+ promise
732
+ } = create$2$1(method, params);
733
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
734
+ ipc.sendAndTransfer(message);
735
+ } else {
736
+ ipc.send(message);
737
+ }
738
+ const responseMessage = await promise;
739
+ return unwrapJsonRpcResult(responseMessage);
740
+ };
741
+ const send = (transport, method, ...params) => {
742
+ const message = create$4(method, params);
743
+ transport.send(message);
744
+ };
745
+ const invoke$2 = (ipc, method, ...params) => {
746
+ return invokeHelper(ipc, method, params, false);
747
+ };
748
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
749
+ return invokeHelper(ipc, method, params, true);
750
+ };
751
+
752
+ class CommandNotFoundError extends Error {
753
+ constructor(command) {
754
+ super(`Command not found ${command}`);
755
+ this.name = 'CommandNotFoundError';
756
+ }
757
+ }
758
+ const commands = Object.create(null);
759
+ const register = commandMap => {
760
+ Object.assign(commands, commandMap);
761
+ };
762
+ const getCommand = key => {
763
+ return commands[key];
764
+ };
765
+ const execute = (command, ...args) => {
766
+ const fn = getCommand(command);
767
+ if (!fn) {
768
+ throw new CommandNotFoundError(command);
769
+ }
770
+ return fn(...args);
771
+ };
772
+
773
+ const createRpc = ipc => {
774
+ const rpc = {
775
+ // @ts-ignore
776
+ ipc,
777
+ /**
778
+ * @deprecated
779
+ */
780
+ send(method, ...params) {
781
+ send(ipc, method, ...params);
782
+ },
783
+ invoke(method, ...params) {
784
+ return invoke$2(ipc, method, ...params);
785
+ },
786
+ invokeAndTransfer(method, ...params) {
787
+ return invokeAndTransfer$1(ipc, method, ...params);
788
+ },
789
+ async dispose() {
790
+ await ipc?.dispose();
791
+ }
792
+ };
793
+ return rpc;
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, resolve, preparePrettyError, logError, actualRequiresSocket);
808
+ };
809
+ const handleIpc = ipc => {
810
+ if ('addEventListener' in ipc) {
811
+ ipc.addEventListener('message', handleMessage);
812
+ } else if ('on' in ipc) {
813
+ // deprecated
814
+ ipc.on('message', handleMessage);
815
+ }
816
+ };
817
+ const listen$1 = async (module, options) => {
818
+ const rawIpc = await module.listen(options);
819
+ if (module.signal) {
820
+ module.signal(rawIpc);
821
+ }
822
+ const ipc = module.wrap(rawIpc);
823
+ return ipc;
824
+ };
825
+ const create$2 = async ({
826
+ commandMap
827
+ }) => {
828
+ // TODO create a commandMap per rpc instance
829
+ register(commandMap);
830
+ const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
831
+ handleIpc(ipc);
832
+ const rpc = createRpc(ipc);
833
+ return rpc;
834
+ };
835
+ const WebWorkerRpcClient = {
836
+ __proto__: null,
837
+ create: create$2
838
+ };
839
+ const createMockRpc = ({
840
+ commandMap
841
+ }) => {
842
+ const invocations = [];
843
+ const invoke = (method, ...params) => {
844
+ invocations.push([method, ...params]);
845
+ const command = commandMap[method];
846
+ if (!command) {
847
+ throw new Error(`command ${method} not found`);
848
+ }
849
+ return command(...params);
850
+ };
851
+ const mockRpc = {
852
+ invoke,
853
+ invokeAndTransfer: invoke,
854
+ invocations
855
+ };
856
+ return mockRpc;
857
+ };
858
+
859
+ const toCommandId = key => {
860
+ const dotIndex = key.indexOf('.');
861
+ return key.slice(dotIndex + 1);
862
+ };
863
+ const create$1 = () => {
864
+ const states = Object.create(null);
865
+ const commandMapRef = {};
866
+ return {
867
+ get(uid) {
868
+ return states[uid];
869
+ },
870
+ set(uid, oldState, newState) {
871
+ states[uid] = {
872
+ oldState,
873
+ newState
874
+ };
875
+ },
876
+ dispose(uid) {
877
+ delete states[uid];
878
+ },
879
+ getKeys() {
880
+ return Object.keys(states).map(key => {
881
+ return Number.parseInt(key);
882
+ });
883
+ },
884
+ clear() {
885
+ for (const key of Object.keys(states)) {
886
+ delete states[key];
887
+ }
888
+ },
889
+ wrapCommand(fn) {
890
+ const wrapped = async (uid, ...args) => {
891
+ const {
892
+ newState
893
+ } = states[uid];
894
+ const newerState = await fn(newState, ...args);
895
+ if (newState === newerState) {
896
+ return;
897
+ }
898
+ const latest = states[uid];
899
+ states[uid] = {
900
+ oldState: latest.oldState,
901
+ newState: newerState
902
+ };
903
+ };
904
+ return wrapped;
905
+ },
906
+ wrapGetter(fn) {
907
+ const wrapped = (uid, ...args) => {
908
+ const {
909
+ newState
910
+ } = states[uid];
911
+ return fn(newState, ...args);
912
+ };
913
+ return wrapped;
914
+ },
915
+ diff(uid, modules, numbers) {
916
+ const {
917
+ oldState,
918
+ newState
919
+ } = states[uid];
920
+ const diffResult = [];
921
+ for (let i = 0; i < modules.length; i++) {
922
+ const fn = modules[i];
923
+ if (!fn(oldState, newState)) {
924
+ diffResult.push(numbers[i]);
925
+ }
926
+ }
927
+ return diffResult;
928
+ },
929
+ getCommandIds() {
930
+ const keys = Object.keys(commandMapRef);
931
+ const ids = keys.map(toCommandId);
932
+ return ids;
933
+ },
934
+ registerCommands(commandMap) {
935
+ Object.assign(commandMapRef, commandMap);
936
+ }
937
+ };
938
+ };
939
+ const terminate = () => {
940
+ globalThis.close();
941
+ };
942
+
943
+ const {
944
+ get: get$1,
945
+ set: set$3,
946
+ registerCommands,
947
+ getCommandIds,
948
+ wrapGetter,
949
+ wrapCommand
950
+ } = create$1();
951
+
952
+ const List = 1;
953
+
954
+ const focus = state => {
955
+ if (state.focus) {
956
+ return state;
957
+ }
958
+ return {
959
+ ...state,
960
+ focus: List
961
+ };
962
+ };
963
+
964
+ const focusIndex = (state, index) => {
965
+ return {
966
+ ...state,
967
+ focusedIndex: index,
968
+ focused: true
969
+ };
970
+ };
971
+
972
+ const focusFirst = state => {
973
+ return focusIndex(state, -1);
974
+ };
975
+
976
+ const focusLast = state => {
977
+ return focusIndex(state, -1);
978
+ };
979
+
980
+ const focusNext = state => {
981
+ return focusIndex(state, -1);
982
+ };
983
+
984
+ const focusNone = state => {
985
+ const {
986
+ focusedIndex
987
+ } = state;
988
+ if (focusedIndex === -1) {
989
+ return state;
990
+ }
991
+ return focusIndex(state, -1);
992
+ };
993
+
994
+ const Button = 'event.button';
995
+ const ClientX = 'event.clientX';
996
+ const ClientY = 'event.clientY';
997
+ const CtrlKey = 'event.ctrlKey';
998
+ const DeltaMode = 'event.deltaMode';
999
+ const DeltaY = 'event.deltaY';
1000
+ const TargetValue = 'event.target.value';
1001
+
1002
+ const Enter = 3;
1003
+ const Space = 9;
1004
+ const PageUp = 10;
1005
+ const PageDown = 11;
1006
+ const End = 255;
1007
+ const Home = 12;
1008
+ const UpArrow = 14;
1009
+ const DownArrow = 16;
1010
+
1011
+ const LeftClick = 0;
1012
+
1013
+ const DebugWorker = 55;
1014
+ const RendererWorker$1 = 1;
1015
+
1016
+ const FocusActivityBar = 5;
1017
+
1018
+ const getKeyBindings$1 = () => {
1019
+ return [{
1020
+ key: DownArrow,
1021
+ command: 'ActivityBar.focusNext',
1022
+ when: FocusActivityBar
1023
+ }, {
1024
+ key: UpArrow,
1025
+ command: 'ActivityBar.focusPrevious',
1026
+ when: FocusActivityBar
1027
+ }, {
1028
+ key: Home,
1029
+ command: 'ActivityBar.focusFirst',
1030
+ when: FocusActivityBar
1031
+ }, {
1032
+ key: PageUp,
1033
+ command: 'ActivityBar.focusFirst',
1034
+ when: FocusActivityBar
1035
+ }, {
1036
+ key: PageDown,
1037
+ command: 'ActivityBar.focusLast',
1038
+ when: FocusActivityBar
1039
+ }, {
1040
+ key: End,
1041
+ command: 'ActivityBar.focusLast',
1042
+ when: FocusActivityBar
1043
+ }, {
1044
+ key: Space,
1045
+ command: 'ActivityBar.selectCurrent',
1046
+ when: FocusActivityBar
1047
+ }, {
1048
+ key: Enter,
1049
+ command: 'ActivityBar.selectCurrent',
1050
+ when: FocusActivityBar
1051
+ }];
1052
+ };
1053
+
1054
+ const handleBlur = state => {
1055
+ return {
1056
+ ...state,
1057
+ focused: false
1058
+ };
1059
+ };
1060
+
1061
+ const show = async (x, y, id, ...args) => {
1062
+ // TODO
1063
+ };
1064
+
1065
+ const rpcs = Object.create(null);
1066
+ const set$2 = (id, rpc) => {
1067
+ rpcs[id] = rpc;
1068
+ };
1069
+ const get = id => {
1070
+ return rpcs[id];
1071
+ };
1072
+
1073
+ const create = rpcId => {
1074
+ return {
1075
+ // @ts-ignore
1076
+ invoke(method, ...params) {
1077
+ const rpc = get(rpcId);
1078
+ // @ts-ignore
1079
+ return rpc.invoke(method, ...params);
1080
+ },
1081
+ // @ts-ignore
1082
+ invokeAndTransfer(method, ...params) {
1083
+ const rpc = get(rpcId);
1084
+ // @ts-ignore
1085
+ return rpc.invokeAndTransfer(method, ...params);
1086
+ },
1087
+ set(rpc) {
1088
+ set$2(rpcId, rpc);
1089
+ },
1090
+ async dispose() {
1091
+ const rpc = get(rpcId);
1092
+ await rpc.dispose();
1093
+ }
1094
+ };
1095
+ };
1096
+
1097
+ const {
1098
+ invoke: invoke$1,
1099
+ invokeAndTransfer,
1100
+ set: set$1,
1101
+ dispose
1102
+ } = create(RendererWorker$1);
1103
+ const searchFileHtml = async uri => {
1104
+ return invoke$1('ExtensionHost.searchFileWithHtml', uri);
1105
+ };
1106
+ const getFilePathElectron = async file => {
1107
+ return invoke$1('FileSystemHandle.getFilePathElectron', file);
1108
+ };
1109
+ const showContextMenu = async (x, y, id, ...args) => {
1110
+ return invoke$1('ContextMenu.show', x, y, id, ...args);
1111
+ };
1112
+ const getElectronVersion = async () => {
1113
+ return invoke$1('Process.getElectronVersion');
1114
+ };
1115
+ const applyBulkReplacement = async bulkEdits => {
1116
+ await invoke$1('BulkReplacement.applyBulkReplacement', bulkEdits);
1117
+ };
1118
+ const setColorTheme = async id => {
1119
+ // @ts-ignore
1120
+ return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1121
+ };
1122
+ const getNodeVersion = async () => {
1123
+ return invoke$1('Process.getNodeVersion');
1124
+ };
1125
+ const getChromeVersion = async () => {
1126
+ return invoke$1('Process.getChromeVersion');
1127
+ };
1128
+ const getV8Version = async () => {
1129
+ return invoke$1('Process.getV8Version');
1130
+ };
1131
+ const getFileHandles = async fileIds => {
1132
+ const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
1133
+ return files;
1134
+ };
1135
+ const setWorkspacePath = async path => {
1136
+ await invoke$1('Workspace.setPath', path);
1137
+ };
1138
+ const registerWebViewInterceptor = async (id, port) => {
1139
+ await invokeAndTransfer('WebView.registerInterceptor', id, port);
1140
+ };
1141
+ const unregisterWebViewInterceptor = async id => {
1142
+ await invoke$1('WebView.unregisterInterceptor', id);
1143
+ };
1144
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1145
+ const command = 'HandleMessagePort.handleMessagePort';
1146
+ // @ts-ignore
1147
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1148
+ };
1149
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1150
+ const command = 'Errors.handleMessagePort';
1151
+ // @ts-ignore
1152
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1153
+ };
1154
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1155
+ const command = 'Markdown.handleMessagePort';
1156
+ // @ts-ignore
1157
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1158
+ };
1159
+ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1160
+ const command = 'IconTheme.handleMessagePort';
1161
+ // @ts-ignore
1162
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1163
+ };
1164
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1165
+ const command = 'FileSystem.handleMessagePort';
1166
+ // @ts-ignore
1167
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1168
+ };
1169
+ const readFile = async uri => {
1170
+ return invoke$1('FileSystem.readFile', uri);
1171
+ };
1172
+ const getWebViewSecret = async key => {
1173
+ // @ts-ignore
1174
+ return invoke$1('WebView.getSecret', key);
1175
+ };
1176
+ const setWebViewPort = async (uid, port, origin, portType) => {
1177
+ return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1178
+ };
1179
+ const setFocus = key => {
1180
+ return invoke$1('Focus.setFocus', key);
1181
+ };
1182
+ const getFileIcon = async options => {
1183
+ return invoke$1('IconTheme.getFileIcon', options);
1184
+ };
1185
+ const getColorThemeNames = async () => {
1186
+ return invoke$1('ColorTheme.getColorThemeNames');
1187
+ };
1188
+ const disableExtension = async id => {
1189
+ // @ts-ignore
1190
+ return invoke$1('ExtensionManagement.disable', id);
1191
+ };
1192
+ const enableExtension = async id => {
1193
+ // @ts-ignore
1194
+ return invoke$1('ExtensionManagement.enable', id);
1195
+ };
1196
+ const handleDebugChange = async params => {
1197
+ // @ts-ignore
1198
+ return invoke$1('Run And Debug.handleChange', params);
1199
+ };
1200
+ const getFolderIcon = async options => {
1201
+ return invoke$1('IconTheme.getFolderIcon', options);
1202
+ };
1203
+ const closeWidget = async widgetId => {
1204
+ return invoke$1('Viewlet.closeWidget', widgetId);
1205
+ };
1206
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1207
+ const command = 'HandleMessagePort.handleMessagePort2';
1208
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1209
+ };
1210
+ const sendMessagePortToSearchProcess = async port => {
1211
+ await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1212
+ };
1213
+ const confirm = async (message, options) => {
1214
+ // @ts-ignore
1215
+ const result = await invoke$1('ConfirmPrompt.prompt', message, options);
1216
+ return result;
1217
+ };
1218
+ const getRecentlyOpened = async () => {
1219
+ return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1220
+ };
1221
+ const getKeyBindings = async () => {
1222
+ return invoke$1('KeyBindingsInitial.getKeyBindings');
1223
+ };
1224
+ const writeClipBoardText = async text => {
1225
+ await invoke$1('ClipBoard.writeText', /* text */text);
1226
+ };
1227
+ const writeClipBoardImage = async blob => {
1228
+ // @ts-ignore
1229
+ await invoke$1('ClipBoard.writeImage', /* text */blob);
1230
+ };
1231
+ const searchFileMemory = async uri => {
1232
+ // @ts-ignore
1233
+ return invoke$1('ExtensionHost.searchFileWithMemory', uri);
1234
+ };
1235
+ const searchFileFetch = async uri => {
1236
+ return invoke$1('ExtensionHost.searchFileWithFetch', uri);
1237
+ };
1238
+ const showMessageBox = async options => {
1239
+ return invoke$1('ElectronDialog.showMessageBox', options);
1240
+ };
1241
+ const handleDebugResumed = async params => {
1242
+ await invoke$1('Run And Debug.handleResumed', params);
1243
+ };
1244
+ const openWidget = async name => {
1245
+ await invoke$1('Viewlet.openWidget', name);
1246
+ };
1247
+ const getIcons = async requests => {
1248
+ const icons = await invoke$1('IconTheme.getIcons', requests);
1249
+ return icons;
1250
+ };
1251
+ const activateByEvent = event => {
1252
+ return invoke$1('ExtensionHostManagement.activateByEvent', event);
1253
+ };
1254
+ const setAdditionalFocus = focusKey => {
1255
+ // @ts-ignore
1256
+ return invoke$1('Focus.setAdditionalFocus', focusKey);
1257
+ };
1258
+ const getActiveEditorId = () => {
1259
+ // @ts-ignore
1260
+ return invoke$1('GetActiveEditor.getActiveEditorId');
1261
+ };
1262
+ const getWorkspacePath = () => {
1263
+ return invoke$1('Workspace.getPath');
1264
+ };
1265
+ const sendMessagePortToRendererProcess = async port => {
1266
+ const command = 'HandleMessagePort.handleMessagePort';
1267
+ // @ts-ignore
1268
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1269
+ };
1270
+ const getPreference = async key => {
1271
+ return await invoke$1('Preferences.get', key);
1272
+ };
1273
+ const getAllExtensions = async () => {
1274
+ return invoke$1('ExtensionManagement.getAllExtensions');
1275
+ };
1276
+ const rerenderEditor = async key => {
1277
+ // @ts-ignore
1278
+ return invoke$1('Editor.rerender', key);
1279
+ };
1280
+ const handleDebugPaused = async params => {
1281
+ await invoke$1('Run And Debug.handlePaused', params);
1282
+ };
1283
+ const openUri = async (uri, focus, options) => {
1284
+ await invoke$1('Main.openUri', uri, focus, options);
1285
+ };
1286
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
1287
+ await invokeAndTransfer(
1288
+ // @ts-ignore
1289
+ 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1290
+ };
1291
+ const handleDebugScriptParsed = async script => {
1292
+ await invoke$1('Run And Debug.handleScriptParsed', script);
1293
+ };
1294
+ const getWindowId = async () => {
1295
+ return invoke$1('GetWindowId.getWindowId');
1296
+ };
1297
+ const getBlob = async uri => {
1298
+ // @ts-ignore
1299
+ return invoke$1('FileSystem.getBlob', uri);
1300
+ };
1301
+ const getExtensionCommands = async () => {
1302
+ return invoke$1('ExtensionHost.getCommands');
1303
+ };
1304
+ const showErrorDialog = async errorInfo => {
1305
+ // @ts-ignore
1306
+ await invoke$1('ErrorHandling.showErrorDialog', errorInfo);
1307
+ };
1308
+ const getFolderSize = async uri => {
1309
+ // @ts-ignore
1310
+ return await invoke$1('FileSystem.getFolderSize', uri);
1311
+ };
1312
+ const getExtension = async id => {
1313
+ // @ts-ignore
1314
+ return invoke$1('ExtensionManagement.getExtension', id);
1315
+ };
1316
+ const getMarkdownDom = async html => {
1317
+ // @ts-ignore
1318
+ return invoke$1('Markdown.getVirtualDom', html);
1319
+ };
1320
+ const renderMarkdown = async (markdown, options) => {
1321
+ // @ts-ignore
1322
+ return invoke$1('Markdown.renderMarkdown', markdown, options);
1323
+ };
1324
+ const openNativeFolder = async uri => {
1325
+ // @ts-ignore
1326
+ await invoke$1('OpenNativeFolder.openNativeFolder', uri);
1327
+ };
1328
+ const uninstallExtension = async id => {
1329
+ return invoke$1('ExtensionManagement.uninstall', id);
1330
+ };
1331
+ const installExtension = async id => {
1332
+ // @ts-ignore
1333
+ return invoke$1('ExtensionManagement.install', id);
1334
+ };
1335
+ const openExtensionSearch = async () => {
1336
+ // @ts-ignore
1337
+ return invoke$1('SideBar.openViewlet', 'Extensions');
1338
+ };
1339
+ const setExtensionsSearchValue = async searchValue => {
1340
+ // @ts-ignore
1341
+ return invoke$1('Extensions.handleInput', searchValue);
1342
+ };
1343
+ const openExternal = async uri => {
1344
+ // @ts-ignore
1345
+ await invoke$1('Open.openExternal', uri);
1346
+ };
1347
+ const openUrl = async uri => {
1348
+ // @ts-ignore
1349
+ await invoke$1('Open.openUrl', uri);
1350
+ };
1351
+ const getAllPreferences = async () => {
1352
+ // @ts-ignore
1353
+ return invoke$1('Preferences.getAll');
1354
+ };
1355
+ const showSaveFilePicker = async () => {
1356
+ // @ts-ignore
1357
+ return invoke$1('FilePicker.showSaveFilePicker');
1358
+ };
1359
+ const getLogsDir = async () => {
1360
+ // @ts-ignore
1361
+ return invoke$1('PlatformPaths.getLogsDir');
1362
+ };
1363
+ const registerMockRpc = commandMap => {
1364
+ const mockRpc = createMockRpc({
1365
+ commandMap
1366
+ });
1367
+ set$1(mockRpc);
1368
+ return mockRpc;
1369
+ };
1370
+
1371
+ const RendererWorker = {
1372
+ __proto__: null,
1373
+ activateByEvent,
1374
+ applyBulkReplacement,
1375
+ closeWidget,
1376
+ confirm,
1377
+ disableExtension,
1378
+ dispose,
1379
+ enableExtension,
1380
+ getActiveEditorId,
1381
+ getAllExtensions,
1382
+ getAllPreferences,
1383
+ getBlob,
1384
+ getChromeVersion,
1385
+ getColorThemeNames,
1386
+ getElectronVersion,
1387
+ getExtension,
1388
+ getExtensionCommands,
1389
+ getFileHandles,
1390
+ getFileIcon,
1391
+ getFilePathElectron,
1392
+ getFolderIcon,
1393
+ getFolderSize,
1394
+ getIcons,
1395
+ getKeyBindings,
1396
+ getLogsDir,
1397
+ getMarkdownDom,
1398
+ getNodeVersion,
1399
+ getPreference,
1400
+ getRecentlyOpened,
1401
+ getV8Version,
1402
+ getWebViewSecret,
1403
+ getWindowId,
1404
+ getWorkspacePath,
1405
+ handleDebugChange,
1406
+ handleDebugPaused,
1407
+ handleDebugResumed,
1408
+ handleDebugScriptParsed,
1409
+ installExtension,
1410
+ invoke: invoke$1,
1411
+ invokeAndTransfer,
1412
+ openExtensionSearch,
1413
+ openExternal,
1414
+ openNativeFolder,
1415
+ openUri,
1416
+ openUrl,
1417
+ openWidget,
1418
+ readFile,
1419
+ registerMockRpc,
1420
+ registerWebViewInterceptor,
1421
+ renderMarkdown,
1422
+ rerenderEditor,
1423
+ searchFileFetch,
1424
+ searchFileHtml,
1425
+ searchFileMemory,
1426
+ sendMessagePortToEditorWorker,
1427
+ sendMessagePortToErrorWorker,
1428
+ sendMessagePortToExtensionHostWorker,
1429
+ sendMessagePortToFileSystemWorker,
1430
+ sendMessagePortToIconThemeWorker,
1431
+ sendMessagePortToMarkdownWorker,
1432
+ sendMessagePortToRendererProcess,
1433
+ sendMessagePortToSearchProcess,
1434
+ sendMessagePortToSyntaxHighlightingWorker,
1435
+ set: set$1,
1436
+ setAdditionalFocus,
1437
+ setColorTheme,
1438
+ setExtensionsSearchValue,
1439
+ setFocus,
1440
+ setWebViewPort,
1441
+ setWorkspacePath,
1442
+ showContextMenu,
1443
+ showErrorDialog,
1444
+ showMessageBox,
1445
+ showSaveFilePicker,
1446
+ uninstallExtension,
1447
+ unregisterWebViewInterceptor,
1448
+ writeClipBoardImage,
1449
+ writeClipBoardText
1450
+ };
1451
+
1452
+ const {
1453
+ set,
1454
+ invoke
1455
+ } = RendererWorker;
1456
+
1457
+ const handleClickSettings = async (state, x, y, viewletId) => {
1458
+ await show();
1459
+ return state;
1460
+ };
1461
+ const handleClickAdditionalViews = async (state, x, y, viewletId) => {
1462
+ await show();
1463
+ return state;
1464
+ };
1465
+ const handleClickOther = async (state, x, y, viewletId) => {
1466
+ // TODO ask renderer worker asynchronously if sidebar is visible
1467
+
1468
+ const {
1469
+ sideBarVisible,
1470
+ currentViewletId
1471
+ } = state;
1472
+ if (sideBarVisible) {
1473
+ if (currentViewletId === viewletId) {
1474
+ await invoke('Layout.hideSideBar');
1475
+ } else {
1476
+ await invoke(/* SideBar.show */'SideBar.show', /* id */viewletId);
1477
+ }
1478
+ } else {
1479
+ // TODO should show side bar with viewletId
1480
+ // @ts-ignore
1481
+ await invoke('Layout.showSideBar');
1482
+ }
1483
+ return state;
1484
+ };
1485
+ const handleClick = async (state, button, index, x, y) => {
1486
+ if (button !== LeftClick) {
1487
+ return state;
1488
+ }
1489
+ const {
1490
+ activityBarItems
1491
+ } = state;
1492
+ const item = activityBarItems[index];
1493
+ const viewletId = item.id;
1494
+ switch (viewletId) {
1495
+ case 'Settings':
1496
+ return handleClickSettings(state);
1497
+ case 'Additional Views':
1498
+ return handleClickAdditionalViews(state);
1499
+ default:
1500
+ return handleClickOther(state, x, y, viewletId);
1501
+ }
1502
+ };
1503
+
1504
+ const findIndex = (activityBarItems, id) => {
1505
+ for (let i = 0; i < activityBarItems.length; i++) {
1506
+ if (activityBarItems[i].id === id) {
1507
+ return i;
1508
+ }
1509
+ }
1510
+ return -1;
1511
+ };
1512
+
1513
+ const handleSideBarViewletChange = (state, id, ...args) => {
1514
+ const index = findIndex(state.activityBarItems, id);
1515
+ return {
1516
+ ...state,
1517
+ selectedIndex: index
1518
+ };
1519
+ };
1520
+
1521
+ const applyRender = (oldState, newState, diffResult) => {
1522
+ const commands = [];
1523
+ return commands;
1524
+ };
1525
+
1526
+ const render2 = (uid, diffResult) => {
1527
+ const {
1528
+ newState
1529
+ } = get$1(uid);
1530
+ set$3(uid, newState, newState);
1531
+ const commands = applyRender();
1532
+ return commands;
1533
+ };
1534
+
1535
+ const HandleClick = 1;
1536
+ const HandleClickOpenFolder = 2;
1537
+ const HandleContextMenu = 3;
1538
+ const HandleDragLeave = 4;
1539
+ const HandleDragOver = 5;
1540
+ const HandleDrop = 6;
1541
+ const HandleEditingInput = 7;
1542
+ const HandleInputBlur = 8;
1543
+ const HandleInputClick = 9;
1544
+ const HandleListBlur = 11;
1545
+ const HandleListFocus = 12;
1546
+ const HandlePointerDown = 14;
1547
+ const HandleWheel = 15;
1548
+ const HandleDragStart = 17;
1549
+
1550
+ const renderEventListeners = () => {
1551
+ return [{
1552
+ name: HandleInputBlur,
1553
+ params: ['handleInputBlur']
1554
+ },
1555
+ // {
1556
+ // name: DomEventListenersFunctions.HandleInputKeyDown,
1557
+ // params: ['handleInputKeyDown'],
1558
+ // stopPropagation: true, // TODO find a way to do this without stopPropagation
1559
+ // },
1560
+ // {
1561
+ // name: DomEventListenersFunctions.HandleListKeyDown,
1562
+ // params: ['handleKeyDown', 'event.key'],
1563
+ // preventDefault: true,
1564
+ // },
1565
+ {
1566
+ name: HandleListFocus,
1567
+ params: ['handleFocus', 'event.isTrusted', 'event.target.className']
1568
+ }, {
1569
+ name: HandleListBlur,
1570
+ params: ['handleBlur']
1571
+ }, {
1572
+ name: HandleClick,
1573
+ params: ['handleClickAt', 'event.defaultPrevented', Button, CtrlKey, 'event.shiftKey', ClientX, ClientY],
1574
+ preventDefault: true
1575
+ }, {
1576
+ name: HandleInputClick,
1577
+ params: ['handleInputClick'],
1578
+ preventDefault: true
1579
+ }, {
1580
+ name: HandleClickOpenFolder,
1581
+ params: ['handleClickOpenFolder'],
1582
+ preventDefault: true
1583
+ }, {
1584
+ name: HandlePointerDown,
1585
+ params: ['handlePointerDown', Button, ClientX, ClientY]
1586
+ // preventDefault: true,
1587
+ }, {
1588
+ name: HandleEditingInput,
1589
+ params: ['updateEditingValue', TargetValue]
1590
+ }, {
1591
+ name: HandleContextMenu,
1592
+ params: ['handleContextMenu', Button, ClientX, ClientY],
1593
+ preventDefault: true
1594
+ }, {
1595
+ name: HandleWheel,
1596
+ params: ['handleWheel', DeltaMode, DeltaY],
1597
+ passive: true
1598
+ }, {
1599
+ name: HandleDragOver,
1600
+ params: ['handleDragOver', ClientX, ClientY],
1601
+ preventDefault: true
1602
+ }, {
1603
+ name: HandleDrop,
1604
+ params: ['handleDrop', ClientX, ClientY, 'event.dataTransfer.files2', 'event.dataTransfer.files'],
1605
+ preventDefault: true
1606
+ }, {
1607
+ name: HandleDragLeave,
1608
+ params: ['handleDragLeave']
1609
+ }, {
1610
+ name: HandleDragStart,
1611
+ params: ['handleDragStart'],
1612
+ // @ts-ignore
1613
+ dragEffect: 'copyMove'
1614
+ }];
1615
+ };
1616
+
1617
+ const saveState = state => {
1618
+ const {
1619
+ uid
1620
+ } = state;
1621
+ return {
1622
+ uid
1623
+ };
1624
+ };
1625
+
1626
+ const commandMap = {
1627
+ 'ActivityBar.focus': wrapCommand(focus),
1628
+ 'ActivityBar.focusFirst': wrapCommand(focusFirst),
1629
+ 'ActivityBar.focusIndex': wrapCommand(focusIndex),
1630
+ 'ActivityBar.focusLast': wrapCommand(focusLast),
1631
+ 'ActivityBar.focusNext': wrapCommand(focusNext),
1632
+ 'ActivityBar.handleBlur': wrapCommand(handleBlur),
1633
+ 'ActivityBar.focusNone': wrapCommand(focusNone),
1634
+ 'ActivityBar.handleSideBarViewletChange': wrapCommand(handleSideBarViewletChange),
1635
+ 'ActivityBar.getKeyBindings': getKeyBindings$1,
1636
+ 'ActivityBar.handleClick': wrapCommand(handleClick),
1637
+ 'ActivityBar.getCommandIds': getCommandIds,
1638
+ 'ActivityBar.render2': render2,
1639
+ 'ActivityBar.renderEventListeners': renderEventListeners,
1640
+ 'ActivityBar.saveState': wrapGetter(saveState),
1641
+ 'ActivityBar.terminate': terminate
1642
+ };
1643
+
1644
+ const listen = async () => {
1645
+ registerCommands(commandMap);
1646
+ const rpc = await WebWorkerRpcClient.create({
1647
+ commandMap: commandMap
1648
+ });
1649
+ set(rpc);
1650
+ };
1651
+
1652
+ const main = async () => {
1653
+ await listen();
1654
+ };
1655
+
1656
+ main();