@lvce-editor/about-view 7.10.0 → 7.12.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.
Files changed (2) hide show
  1. package/dist/aboutWorkerMain.js +1238 -1221
  2. package/package.json +1 -1
@@ -1,569 +1,3 @@
1
- const toCommandId = key => {
2
- const dotIndex = key.indexOf('.');
3
- return key.slice(dotIndex + 1);
4
- };
5
- const create$a = () => {
6
- const commandQueues = new Map();
7
- const generations = Object.create(null);
8
- const states = Object.create(null);
9
- const commandMapRef = {};
10
- const getGeneration = uid => generations[uid] || 0;
11
- const isCurrentGeneration = (uid, generation) => {
12
- return states[uid] !== undefined && getGeneration(uid) === generation;
13
- };
14
- const updateState = (uid, generation, fallbackState, updater) => {
15
- if (!isCurrentGeneration(uid, generation)) {
16
- return Promise.resolve(fallbackState);
17
- }
18
- const current = states[uid];
19
- const updatedState = updater(current.newState);
20
- if (updatedState !== current.newState) {
21
- states[uid] = {
22
- newState: updatedState,
23
- oldState: current.oldState,
24
- scheduledState: updatedState
25
- };
26
- }
27
- return Promise.resolve(updatedState);
28
- };
29
- const createAsyncCommandContext = (uid, generation) => {
30
- let latestState = states[uid].newState;
31
- return {
32
- getState: () => {
33
- if (isCurrentGeneration(uid, generation)) {
34
- latestState = states[uid].newState;
35
- }
36
- return latestState;
37
- },
38
- updateState: async updater => {
39
- latestState = await updateState(uid, generation, latestState, updater);
40
- return latestState;
41
- }
42
- };
43
- };
44
- const enqueueCommand = async (uid, command) => {
45
- const previous = commandQueues.get(uid) || Promise.resolve();
46
- const run = async () => {
47
- try {
48
- await previous;
49
- } catch {
50
- // The previous caller receives its error; later commands must still run.
51
- }
52
- await command();
53
- };
54
- const current = run();
55
- commandQueues.set(uid, current);
56
- try {
57
- await current;
58
- } finally {
59
- if (commandQueues.get(uid) === current) {
60
- commandQueues.delete(uid);
61
- }
62
- }
63
- };
64
- return {
65
- clear() {
66
- commandQueues.clear();
67
- for (const key of Object.keys(states)) {
68
- delete states[key];
69
- }
70
- },
71
- diff(uid, modules, numbers) {
72
- const {
73
- oldState,
74
- scheduledState
75
- } = states[uid];
76
- const diffResult = [];
77
- for (let i = 0; i < modules.length; i++) {
78
- const fn = modules[i];
79
- if (!fn(oldState, scheduledState)) {
80
- diffResult.push(numbers[i]);
81
- }
82
- }
83
- return diffResult;
84
- },
85
- dispose(uid) {
86
- commandQueues.delete(uid);
87
- delete states[uid];
88
- },
89
- get(uid) {
90
- return states[uid];
91
- },
92
- getCommandIds() {
93
- const keys = Object.keys(commandMapRef);
94
- const ids = keys.map(toCommandId);
95
- return ids;
96
- },
97
- getKeys() {
98
- return Object.keys(states).map(Number);
99
- },
100
- registerCommands(commandMap) {
101
- Object.assign(commandMapRef, commandMap);
102
- },
103
- set(uid, oldState, newState, scheduledState) {
104
- const current = states[uid];
105
- if (!current || oldState === newState && newState !== current.newState) {
106
- generations[uid] = getGeneration(uid) + 1;
107
- }
108
- states[uid] = {
109
- newState,
110
- oldState,
111
- scheduledState: scheduledState ?? newState
112
- };
113
- },
114
- wrapAsyncCommand(fn) {
115
- const wrapped = async (uid, ...args) => {
116
- const generation = getGeneration(uid);
117
- const context = createAsyncCommandContext(uid, generation);
118
- await fn(context, ...args);
119
- };
120
- return wrapped;
121
- },
122
- wrapCommand(fn) {
123
- const wrapped = async (uid, ...args) => {
124
- const generation = getGeneration(uid);
125
- const {
126
- newState,
127
- oldState
128
- } = states[uid];
129
- const newerState = await fn(newState, ...args);
130
- if (oldState === newerState || newState === newerState) {
131
- return;
132
- }
133
- if (!isCurrentGeneration(uid, generation)) {
134
- return;
135
- }
136
- const latestOld = states[uid];
137
- const latestNew = {
138
- ...latestOld.newState,
139
- ...newerState
140
- };
141
- states[uid] = {
142
- newState: latestNew,
143
- oldState: latestOld.oldState,
144
- scheduledState: latestNew
145
- };
146
- };
147
- return wrapped;
148
- },
149
- wrapGetter(fn) {
150
- const wrapped = (uid, ...args) => {
151
- const {
152
- newState
153
- } = states[uid];
154
- return fn(newState, ...args);
155
- };
156
- return wrapped;
157
- },
158
- wrapLoadContent(fn) {
159
- const wrapped = async (uid, ...args) => {
160
- const generation = getGeneration(uid);
161
- const {
162
- newState,
163
- oldState
164
- } = states[uid];
165
- const result = await fn(newState, ...args);
166
- const {
167
- error,
168
- state
169
- } = result;
170
- if (oldState === state || newState === state) {
171
- return {
172
- error
173
- };
174
- }
175
- if (!isCurrentGeneration(uid, generation)) {
176
- return {
177
- error
178
- };
179
- }
180
- const latestOld = states[uid];
181
- const latestNew = {
182
- ...latestOld.newState,
183
- ...state
184
- };
185
- states[uid] = {
186
- newState: latestNew,
187
- oldState: latestOld.oldState,
188
- scheduledState: latestNew
189
- };
190
- return {
191
- error
192
- };
193
- };
194
- return wrapped;
195
- },
196
- wrapSerialAsyncCommand(fn) {
197
- const wrapped = async (uid, ...args) => {
198
- await enqueueCommand(uid, async () => {
199
- if (!states[uid]) {
200
- return;
201
- }
202
- const generation = getGeneration(uid);
203
- const context = createAsyncCommandContext(uid, generation);
204
- await fn(context, ...args);
205
- });
206
- };
207
- return wrapped;
208
- },
209
- wrapSerialCommand(fn) {
210
- const wrapped = async (uid, ...args) => {
211
- await enqueueCommand(uid, async () => {
212
- if (!states[uid]) {
213
- return;
214
- }
215
- const generation = getGeneration(uid);
216
- const {
217
- newState,
218
- oldState
219
- } = states[uid];
220
- const newerState = await fn(newState, ...args);
221
- if (oldState === newerState || newState === newerState) {
222
- return;
223
- }
224
- if (!isCurrentGeneration(uid, generation)) {
225
- return;
226
- }
227
- const latestOld = states[uid];
228
- const latestNew = {
229
- ...latestOld.newState,
230
- ...newerState
231
- };
232
- states[uid] = {
233
- newState: latestNew,
234
- oldState: latestOld.oldState,
235
- scheduledState: latestNew
236
- };
237
- });
238
- };
239
- return wrapped;
240
- }
241
- };
242
- };
243
-
244
- const {
245
- dispose: dispose$1,
246
- get: get$2,
247
- getCommandIds,
248
- registerCommands,
249
- set: set$3,
250
- wrapAsyncCommand,
251
- wrapCommand
252
- } = create$a();
253
-
254
- const create$9 = uid => {
255
- const state = {
256
- focusId: 0,
257
- lines: [],
258
- productName: '',
259
- uid
260
- };
261
- set$3(uid, state, state);
262
- };
263
-
264
- const RenderFocus = 2;
265
- const RenderFocusContext = 4;
266
- const RenderAbout = 3;
267
-
268
- const diffType$2 = RenderAbout;
269
- const isEqual$2 = (oldState, newState) => {
270
- return oldState.productName === newState.productName && JSON.stringify(oldState.lines) === JSON.stringify(newState.lines);
271
- };
272
-
273
- const diffType$1 = RenderFocus;
274
- const isEqual$1 = (oldState, newState) => {
275
- return oldState.focusId === newState.focusId;
276
- };
277
-
278
- const diffType = RenderFocusContext;
279
- const isEqual = (oldState, newState) => {
280
- return oldState.focusId === newState.focusId;
281
- };
282
-
283
- const modules = [isEqual$2, isEqual$1, isEqual];
284
- const numbers = [diffType$2, diffType$1, diffType];
285
-
286
- const diff = (oldState, newState) => {
287
- const diffResult = [];
288
- for (let i = 0; i < modules.length; i++) {
289
- const fn = modules[i];
290
- if (!fn(oldState, newState)) {
291
- diffResult.push(numbers[i]);
292
- }
293
- }
294
- return diffResult;
295
- };
296
-
297
- const diff2 = uid => {
298
- const {
299
- oldState,
300
- scheduledState
301
- } = get$2(uid);
302
- const diffResult = diff(oldState, scheduledState);
303
- return diffResult;
304
- };
305
-
306
- const dispose = uid => {
307
- dispose$1(uid);
308
- };
309
-
310
- const None = 0;
311
- const Ok$2 = 1;
312
- const Copy$2 = 2;
313
-
314
- const getNextFocus = focusId => {
315
- switch (focusId) {
316
- case Copy$2:
317
- return Ok$2;
318
- case Ok$2:
319
- return Copy$2;
320
- default:
321
- return None;
322
- }
323
- };
324
-
325
- const focusNext = state => {
326
- const {
327
- focusId
328
- } = state;
329
- return {
330
- ...state,
331
- focusId: getNextFocus(focusId)
332
- };
333
- };
334
-
335
- const getPreviousFocus = focusId => {
336
- switch (focusId) {
337
- case Copy$2:
338
- return Ok$2;
339
- case Ok$2:
340
- return Copy$2;
341
- default:
342
- return None;
343
- }
344
- };
345
-
346
- const focusPrevious = state => {
347
- const {
348
- focusId
349
- } = state;
350
- return {
351
- ...state,
352
- focusId: getPreviousFocus(focusId)
353
- };
354
- };
355
-
356
- const Audio = 0;
357
- const Button$1 = 1;
358
- const Col = 2;
359
- const ColGroup = 3;
360
- const Div = 4;
361
- const H1 = 5;
362
- const Input = 6;
363
- const Kbd = 7;
364
- const Span = 8;
365
- const Table = 9;
366
- const TBody = 10;
367
- const Td = 11;
368
- const Text = 12;
369
- const Th = 13;
370
- const THead = 14;
371
- const Tr = 15;
372
- const I = 16;
373
- const Img = 17;
374
- const Root = 0;
375
- const Ins = 20;
376
- const Del = 21;
377
- const H2 = 22;
378
- const H3 = 23;
379
- const H4 = 24;
380
- const H5 = 25;
381
- const H6 = 26;
382
- const Article = 27;
383
- const Aside = 28;
384
- const Footer = 29;
385
- const Header = 30;
386
- const Nav = 40;
387
- const Section = 41;
388
- const Search = 42;
389
- const Dd = 43;
390
- const Dl = 44;
391
- const Figcaption = 45;
392
- const Figure = 46;
393
- const Hr = 47;
394
- const Li = 48;
395
- const Ol = 49;
396
- const P = 50;
397
- const Pre = 51;
398
- const A = 53;
399
- const Abbr = 54;
400
- const Br = 55;
401
- const Cite = 56;
402
- const Data = 57;
403
- const Time = 58;
404
- const Tfoot = 59;
405
- const Ul = 60;
406
- const Video = 61;
407
- const TextArea = 62;
408
- const Select = 63;
409
- const Option = 64;
410
- const Code = 65;
411
- const Label = 66;
412
- const Dt = 67;
413
- const Iframe = 68;
414
- const Main = 69;
415
- const Strong = 70;
416
- const Em = 71;
417
- const Style = 72;
418
- const Html = 73;
419
- const Head = 74;
420
- const Title = 75;
421
- const Meta = 76;
422
- const Canvas = 77;
423
- const Form = 78;
424
- const BlockQuote = 79;
425
- const Quote = 80;
426
- const Circle = 81;
427
- const Defs = 82;
428
- const Ellipse = 83;
429
- const G = 84;
430
- const Line = 85;
431
- const Path = 86;
432
- const Polygon = 87;
433
- const Polyline = 88;
434
- const Rect = 89;
435
- const Svg = 90;
436
- const Use = 91;
437
- const Reference = 100;
438
-
439
- const VirtualDomElements = {
440
- __proto__: null,
441
- A,
442
- Abbr,
443
- Article,
444
- Aside,
445
- Audio,
446
- BlockQuote,
447
- Br,
448
- Button: Button$1,
449
- Canvas,
450
- Circle,
451
- Cite,
452
- Code,
453
- Col,
454
- ColGroup,
455
- Data,
456
- Dd,
457
- Defs,
458
- Del,
459
- Div,
460
- Dl,
461
- Dt,
462
- Ellipse,
463
- Em,
464
- Figcaption,
465
- Figure,
466
- Footer,
467
- Form,
468
- G,
469
- H1,
470
- H2,
471
- H3,
472
- H4,
473
- H5,
474
- H6,
475
- Head,
476
- Header,
477
- Hr,
478
- Html,
479
- I,
480
- Iframe,
481
- Img,
482
- Input,
483
- Ins,
484
- Kbd,
485
- Label,
486
- Li,
487
- Line,
488
- Main,
489
- Meta,
490
- Nav,
491
- Ol,
492
- Option,
493
- P,
494
- Path,
495
- Polygon,
496
- Polyline,
497
- Pre,
498
- Quote,
499
- Rect,
500
- Reference,
501
- Root,
502
- Search,
503
- Section,
504
- Select,
505
- Span,
506
- Strong,
507
- Style,
508
- Svg,
509
- TBody,
510
- THead,
511
- Table,
512
- Td,
513
- Text,
514
- TextArea,
515
- Tfoot,
516
- Th,
517
- Time,
518
- Title,
519
- Tr,
520
- Ul,
521
- Use,
522
- Video
523
- };
524
-
525
- const TargetName = 'event.target.name';
526
-
527
- const Tab = 2;
528
- const Escape = 8;
529
-
530
- const Shift = 1 << 10 >>> 0;
531
-
532
- const FileSystemWorker = 209;
533
- const RendererWorker$1 = 1;
534
-
535
- const mergeClassNames = (...classNames) => {
536
- return classNames.filter(Boolean).join(' ');
537
- };
538
-
539
- const text = data => {
540
- return {
541
- childCount: 0,
542
- text: data,
543
- type: Text
544
- };
545
- };
546
-
547
- new Set(Object.values(VirtualDomElements));
548
-
549
- const FocusAbout = 4;
550
-
551
- const getKeyBindings = () => {
552
- return [{
553
- command: 'About.handleClickClose',
554
- key: Escape,
555
- when: FocusAbout
556
- }, {
557
- command: 'About.focusNext',
558
- key: Tab,
559
- when: FocusAbout
560
- }, {
561
- command: 'About.focusPrevious',
562
- key: Tab | Shift,
563
- when: FocusAbout
564
- }];
565
- };
566
-
567
1
  const normalizeLine = line => {
568
2
  if (line.startsWith('Error: ')) {
569
3
  return line.slice('Error: '.length);
@@ -1028,729 +462,1302 @@ class IpcParentWithMessagePort extends Ipc {
1028
462
  const wrap$5 = messagePort => {
1029
463
  return new IpcParentWithMessagePort(messagePort);
1030
464
  };
1031
- const IpcParentWithMessagePort$1 = {
1032
- __proto__: null,
1033
- create: create$5$1,
1034
- signal: signal$1,
1035
- wrap: wrap$5
465
+ const IpcParentWithMessagePort$1 = {
466
+ __proto__: null,
467
+ create: create$5$1,
468
+ signal: signal$1,
469
+ wrap: wrap$5
470
+ };
471
+
472
+ class CommandNotFoundError extends Error {
473
+ constructor(command) {
474
+ super(`Command not found ${command}`);
475
+ this.name = 'CommandNotFoundError';
476
+ }
477
+ }
478
+ const commands = Object.create(null);
479
+ const register = commandMap => {
480
+ Object.assign(commands, commandMap);
481
+ };
482
+ const getCommand = key => {
483
+ return commands[key];
484
+ };
485
+ const execute = (command, ...args) => {
486
+ const fn = getCommand(command);
487
+ if (!fn) {
488
+ throw new CommandNotFoundError(command);
489
+ }
490
+ return fn(...args);
491
+ };
492
+
493
+ const Two$1 = '2.0';
494
+ const callbacks = Object.create(null);
495
+ const get$2 = id => {
496
+ return callbacks[id];
497
+ };
498
+ const remove$1 = id => {
499
+ delete callbacks[id];
500
+ };
501
+ class JsonRpcError extends Error {
502
+ constructor(message) {
503
+ super(message);
504
+ this.name = 'JsonRpcError';
505
+ }
506
+ }
507
+ const NewLine$1 = '\n';
508
+ const DomException = 'DOMException';
509
+ const ReferenceError$1 = 'ReferenceError';
510
+ const SyntaxError$1 = 'SyntaxError';
511
+ const TypeError$1 = 'TypeError';
512
+ const getErrorConstructor = (message, type) => {
513
+ if (type) {
514
+ switch (type) {
515
+ case DomException:
516
+ return DOMException;
517
+ case ReferenceError$1:
518
+ return ReferenceError;
519
+ case SyntaxError$1:
520
+ return SyntaxError;
521
+ case TypeError$1:
522
+ return TypeError;
523
+ default:
524
+ return Error;
525
+ }
526
+ }
527
+ if (message.startsWith('TypeError: ')) {
528
+ return TypeError;
529
+ }
530
+ if (message.startsWith('SyntaxError: ')) {
531
+ return SyntaxError;
532
+ }
533
+ if (message.startsWith('ReferenceError: ')) {
534
+ return ReferenceError;
535
+ }
536
+ return Error;
537
+ };
538
+ const constructError = (message, type, name) => {
539
+ const ErrorConstructor = getErrorConstructor(message, type);
540
+ if (ErrorConstructor === DOMException && name) {
541
+ return new ErrorConstructor(message, name);
542
+ }
543
+ if (ErrorConstructor === Error) {
544
+ const error = new Error(message);
545
+ if (name && name !== 'VError') {
546
+ Object.defineProperty(error, 'name', {
547
+ configurable: true,
548
+ value: name
549
+ });
550
+ }
551
+ return error;
552
+ }
553
+ return new ErrorConstructor(message);
554
+ };
555
+ const joinLines$1 = lines => {
556
+ return lines.join(NewLine$1);
557
+ };
558
+ const splitLines = lines => {
559
+ return lines.split(NewLine$1);
560
+ };
561
+ const getCurrentStack = () => {
562
+ const stackLinesToSkip = 3;
563
+ const currentStack = joinLines$1(splitLines(new Error().stack || '').slice(stackLinesToSkip));
564
+ return currentStack;
565
+ };
566
+ const getNewLineIndex = (string, startIndex) => {
567
+ {
568
+ return string.indexOf(NewLine$1);
569
+ }
570
+ };
571
+ const getParentStack = error => {
572
+ let parentStack = error.stack || error.data || error.message || '';
573
+ if (parentStack.startsWith(' at')) {
574
+ parentStack = error.message + NewLine$1 + parentStack;
575
+ }
576
+ return parentStack;
577
+ };
578
+ const MethodNotFound = -32601;
579
+ const Custom = -32001;
580
+ const setStack = (error, stack) => {
581
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
582
+ if (descriptor) {
583
+ if (!descriptor.configurable && !descriptor.writable) {
584
+ return;
585
+ }
586
+ if (!descriptor.configurable && descriptor.writable) {
587
+ error.stack = stack;
588
+ return;
589
+ }
590
+ }
591
+ Object.defineProperty(error, 'stack', {
592
+ configurable: true,
593
+ value: stack,
594
+ writable: true
595
+ });
596
+ };
597
+ const restoreExistingError = (error, currentStack) => {
598
+ if (typeof error.stack === 'string') {
599
+ setStack(error, `${error.stack}${NewLine$1}${currentStack}`);
600
+ }
601
+ return error;
602
+ };
603
+ const restoreMethodNotFoundError = (error, currentStack) => {
604
+ const restoredError = new JsonRpcError(error.message);
605
+ const parentStack = getParentStack(error);
606
+ setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
607
+ return restoredError;
608
+ };
609
+ const restoreStackFromData = (restoredError, error, currentStack) => {
610
+ if (error.data.stack && error.data.type && error.message) {
611
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine$1}${error.data.stack}${NewLine$1}${currentStack}`);
612
+ return;
613
+ }
614
+ if (error.data.stack) {
615
+ setStack(restoredError, error.data.stack);
616
+ }
617
+ };
618
+ const applyDataProperties = (restoredError, error) => {
619
+ restoreStackFromData(restoredError, error, getCurrentStack());
620
+ if (error.data.codeFrame) {
621
+ // @ts-ignore
622
+ restoredError.codeFrame = error.data.codeFrame;
623
+ }
624
+ if (error.data.code) {
625
+ // @ts-ignore
626
+ restoredError.code = error.data.code;
627
+ }
628
+ if (error.data.type) {
629
+ // @ts-ignore
630
+ restoredError.name = error.data.type;
631
+ }
632
+ };
633
+ const applyDirectProperties = (restoredError, error) => {
634
+ if (error.stack) {
635
+ const lowerStack = restoredError.stack || '';
636
+ const indexNewLine = getNewLineIndex(lowerStack);
637
+ const parentStack = getParentStack(error);
638
+ // @ts-ignore
639
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
640
+ }
641
+ if (error.codeFrame) {
642
+ // @ts-ignore
643
+ restoredError.codeFrame = error.codeFrame;
644
+ }
645
+ };
646
+ const restoreMessageError = (error, _currentStack) => {
647
+ const restoredError = constructError(error.message, error.type, error.name);
648
+ if (error.data) {
649
+ applyDataProperties(restoredError, error);
650
+ } else {
651
+ applyDirectProperties(restoredError, error);
652
+ }
653
+ return restoredError;
654
+ };
655
+ const restoreJsonRpcError = error => {
656
+ const currentStack = getCurrentStack();
657
+ if (error && error instanceof Error) {
658
+ return restoreExistingError(error, currentStack);
659
+ }
660
+ if (error && error.code && error.code === MethodNotFound) {
661
+ return restoreMethodNotFoundError(error, currentStack);
662
+ }
663
+ if (error && error.message) {
664
+ return restoreMessageError(error);
665
+ }
666
+ if (typeof error === 'string') {
667
+ return new Error(`JsonRpc Error: ${error}`);
668
+ }
669
+ return new Error(`JsonRpc Error: ${error}`);
670
+ };
671
+ const unwrapJsonRpcResult = responseMessage => {
672
+ if ('error' in responseMessage) {
673
+ const restoredError = restoreJsonRpcError(responseMessage.error);
674
+ throw restoredError;
675
+ }
676
+ if ('result' in responseMessage) {
677
+ return responseMessage.result;
678
+ }
679
+ throw new JsonRpcError('unexpected response message');
680
+ };
681
+ const warn = (...args) => {
682
+ console.warn(...args);
683
+ };
684
+ const resolve = (id, response) => {
685
+ const fn = get$2(id);
686
+ if (!fn) {
687
+ console.log(response);
688
+ warn(`callback ${id} may already be disposed`);
689
+ return;
690
+ }
691
+ fn(response);
692
+ remove$1(id);
693
+ };
694
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
695
+ const getErrorType = prettyError => {
696
+ if (prettyError && prettyError.type) {
697
+ return prettyError.type;
698
+ }
699
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
700
+ return prettyError.constructor.name;
701
+ }
702
+ return undefined;
703
+ };
704
+ const isAlreadyStack = line => {
705
+ return line.trim().startsWith('at ');
706
+ };
707
+ const getStack = prettyError => {
708
+ const stackString = prettyError.stack || '';
709
+ const newLineIndex = stackString.indexOf('\n');
710
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
711
+ return stackString.slice(newLineIndex + 1);
712
+ }
713
+ return stackString;
1036
714
  };
1037
-
1038
- class CommandNotFoundError extends Error {
1039
- constructor(command) {
1040
- super(`Command not found ${command}`);
1041
- this.name = 'CommandNotFoundError';
715
+ const getErrorProperty = (error, prettyError) => {
716
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
717
+ return {
718
+ code: MethodNotFound,
719
+ data: error.stack,
720
+ message: error.message
721
+ };
1042
722
  }
1043
- }
1044
- const commands = Object.create(null);
1045
- const register = commandMap => {
1046
- Object.assign(commands, commandMap);
723
+ return {
724
+ code: Custom,
725
+ data: {
726
+ code: prettyError.code,
727
+ codeFrame: prettyError.codeFrame,
728
+ name: prettyError.name,
729
+ stack: getStack(prettyError),
730
+ type: getErrorType(prettyError)
731
+ },
732
+ message: prettyError.message
733
+ };
1047
734
  };
1048
- const getCommand = key => {
1049
- return commands[key];
735
+ const create$1$1 = (id, error) => {
736
+ return {
737
+ error,
738
+ id,
739
+ jsonrpc: Two$1
740
+ };
1050
741
  };
1051
- const execute = (command, ...args) => {
1052
- const fn = getCommand(command);
1053
- if (!fn) {
1054
- throw new CommandNotFoundError(command);
1055
- }
1056
- return fn(...args);
742
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
743
+ const prettyError = preparePrettyError(error);
744
+ logError(error, prettyError);
745
+ const errorProperty = getErrorProperty(error, prettyError);
746
+ return create$1$1(id, errorProperty);
1057
747
  };
1058
-
1059
- const Two$1 = '2.0';
1060
- const callbacks = Object.create(null);
1061
- const get$1 = id => {
1062
- return callbacks[id];
748
+ const create$a = (message, result) => {
749
+ return {
750
+ id: message.id,
751
+ jsonrpc: Two$1,
752
+ result: result ?? null
753
+ };
1063
754
  };
1064
- const remove$1 = id => {
1065
- delete callbacks[id];
755
+ const getSuccessResponse = (message, result) => {
756
+ const resultProperty = result ?? null;
757
+ return create$a(message, resultProperty);
1066
758
  };
1067
- class JsonRpcError extends Error {
1068
- constructor(message) {
1069
- super(message);
1070
- this.name = 'JsonRpcError';
1071
- }
1072
- }
1073
- const NewLine$1 = '\n';
1074
- const DomException = 'DOMException';
1075
- const ReferenceError$1 = 'ReferenceError';
1076
- const SyntaxError$1 = 'SyntaxError';
1077
- const TypeError$1 = 'TypeError';
1078
- const getErrorConstructor = (message, type) => {
1079
- if (type) {
1080
- switch (type) {
1081
- case DomException:
1082
- return DOMException;
1083
- case ReferenceError$1:
1084
- return ReferenceError;
1085
- case SyntaxError$1:
1086
- return SyntaxError;
1087
- case TypeError$1:
1088
- return TypeError;
1089
- default:
1090
- return Error;
759
+ const getErrorResponseSimple = (id, error) => {
760
+ return {
761
+ error: {
762
+ code: Custom,
763
+ data: error,
764
+ // @ts-ignore
765
+ message: error.message
766
+ },
767
+ id,
768
+ jsonrpc: Two$1
769
+ };
770
+ };
771
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
772
+ try {
773
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
774
+ return getSuccessResponse(message, result);
775
+ } catch (error) {
776
+ if (ipc.canUseSimpleErrorResponse) {
777
+ return getErrorResponseSimple(message.id, error);
1091
778
  }
779
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
1092
780
  }
1093
- if (message.startsWith('TypeError: ')) {
1094
- return TypeError;
1095
- }
1096
- if (message.startsWith('SyntaxError: ')) {
1097
- return SyntaxError;
1098
- }
1099
- if (message.startsWith('ReferenceError: ')) {
1100
- return ReferenceError;
1101
- }
1102
- return Error;
1103
781
  };
1104
- const constructError = (message, type, name) => {
1105
- const ErrorConstructor = getErrorConstructor(message, type);
1106
- if (ErrorConstructor === DOMException && name) {
1107
- return new ErrorConstructor(message, name);
782
+ const defaultPreparePrettyError = error => {
783
+ return error;
784
+ };
785
+ const defaultLogError = () => {
786
+ // ignore
787
+ };
788
+ const defaultRequiresSocket = () => {
789
+ return false;
790
+ };
791
+ const defaultResolve = resolve;
792
+
793
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
794
+ const normalizeParams = args => {
795
+ if (args.length === 1) {
796
+ const options = args[0];
797
+ return {
798
+ execute: options.execute,
799
+ ipc: options.ipc,
800
+ logError: options.logError || defaultLogError,
801
+ message: options.message,
802
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
803
+ requiresSocket: options.requiresSocket || defaultRequiresSocket,
804
+ resolve: options.resolve || defaultResolve
805
+ };
1108
806
  }
1109
- if (ErrorConstructor === Error) {
1110
- const error = new Error(message);
1111
- if (name && name !== 'VError') {
1112
- Object.defineProperty(error, 'name', {
1113
- configurable: true,
1114
- value: name
1115
- });
807
+ return {
808
+ execute: args[2],
809
+ ipc: args[0],
810
+ logError: args[5],
811
+ message: args[1],
812
+ preparePrettyError: args[4],
813
+ requiresSocket: args[6],
814
+ resolve: args[3]
815
+ };
816
+ };
817
+ const handleJsonRpcMessage = async (...args) => {
818
+ const options = normalizeParams(args);
819
+ const {
820
+ execute,
821
+ ipc,
822
+ logError,
823
+ message,
824
+ preparePrettyError,
825
+ requiresSocket,
826
+ resolve
827
+ } = options;
828
+ if ('id' in message) {
829
+ if ('method' in message) {
830
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
831
+ try {
832
+ ipc.send(response);
833
+ } catch (error) {
834
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
835
+ ipc.send(errorResponse);
836
+ }
837
+ return;
1116
838
  }
1117
- return error;
839
+ resolve(message.id, message);
840
+ return;
1118
841
  }
1119
- return new ErrorConstructor(message);
842
+ if ('method' in message) {
843
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
844
+ return;
845
+ }
846
+ throw new JsonRpcError('unexpected message');
1120
847
  };
1121
- const joinLines$1 = lines => {
1122
- return lines.join(NewLine$1);
848
+
849
+ const Two = '2.0';
850
+
851
+ const create$9 = (method, params) => {
852
+ return {
853
+ jsonrpc: Two,
854
+ method,
855
+ params
856
+ };
1123
857
  };
1124
- const splitLines = lines => {
1125
- return lines.split(NewLine$1);
858
+
859
+ const create$8 = (id, method, params) => {
860
+ const message = {
861
+ id,
862
+ jsonrpc: Two,
863
+ method,
864
+ params
865
+ };
866
+ return message;
1126
867
  };
1127
- const getCurrentStack = () => {
1128
- const stackLinesToSkip = 3;
1129
- const currentStack = joinLines$1(splitLines(new Error().stack || '').slice(stackLinesToSkip));
1130
- return currentStack;
868
+
869
+ let id = 0;
870
+ const create$7 = () => {
871
+ return ++id;
1131
872
  };
1132
- const getNewLineIndex = (string, startIndex) => {
1133
- {
1134
- return string.indexOf(NewLine$1);
1135
- }
873
+
874
+ const registerPromise = map => {
875
+ const id = create$7();
876
+ const {
877
+ promise,
878
+ resolve
879
+ } = Promise.withResolvers();
880
+ map[id] = resolve;
881
+ return {
882
+ id,
883
+ promise
884
+ };
1136
885
  };
1137
- const getParentStack = error => {
1138
- let parentStack = error.stack || error.data || error.message || '';
1139
- if (parentStack.startsWith(' at')) {
1140
- parentStack = error.message + NewLine$1 + parentStack;
886
+
887
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
888
+ const {
889
+ id,
890
+ promise
891
+ } = registerPromise(callbacks);
892
+ const message = create$8(id, method, params);
893
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
894
+ ipc.sendAndTransfer(message);
895
+ } else {
896
+ ipc.send(message);
1141
897
  }
1142
- return parentStack;
898
+ const responseMessage = await promise;
899
+ return unwrapJsonRpcResult(responseMessage);
1143
900
  };
1144
- const MethodNotFound = -32601;
1145
- const Custom = -32001;
1146
- const setStack = (error, stack) => {
1147
- const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
1148
- if (descriptor) {
1149
- if (!descriptor.configurable && !descriptor.writable) {
901
+ const createRpc = ipc => {
902
+ const callbacks = Object.create(null);
903
+ ipc._resolve = (id, response) => {
904
+ const fn = callbacks[id];
905
+ if (!fn) {
906
+ console.warn(`callback ${id} may already be disposed`);
1150
907
  return;
1151
908
  }
1152
- if (!descriptor.configurable && descriptor.writable) {
1153
- error.stack = stack;
1154
- return;
909
+ fn(response);
910
+ delete callbacks[id];
911
+ };
912
+ const rpc = {
913
+ async dispose() {
914
+ await ipc?.dispose();
915
+ },
916
+ invoke(method, ...params) {
917
+ return invokeHelper(callbacks, ipc, method, params, false);
918
+ },
919
+ invokeAndTransfer(method, ...params) {
920
+ return invokeHelper(callbacks, ipc, method, params, true);
921
+ },
922
+ // @ts-ignore
923
+ ipc,
924
+ /**
925
+ * @deprecated
926
+ */
927
+ send(method, ...params) {
928
+ const message = create$9(method, params);
929
+ ipc.send(message);
1155
930
  }
1156
- }
1157
- Object.defineProperty(error, 'stack', {
1158
- configurable: true,
1159
- value: stack,
1160
- writable: true
1161
- });
1162
- };
1163
- const restoreExistingError = (error, currentStack) => {
1164
- if (typeof error.stack === 'string') {
1165
- setStack(error, `${error.stack}${NewLine$1}${currentStack}`);
1166
- }
1167
- return error;
1168
- };
1169
- const restoreMethodNotFoundError = (error, currentStack) => {
1170
- const restoredError = new JsonRpcError(error.message);
1171
- const parentStack = getParentStack(error);
1172
- setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
1173
- return restoredError;
931
+ };
932
+ return rpc;
1174
933
  };
1175
- const restoreStackFromData = (restoredError, error, currentStack) => {
1176
- if (error.data.stack && error.data.type && error.message) {
1177
- setStack(restoredError, `${error.data.type}: ${error.message}${NewLine$1}${error.data.stack}${NewLine$1}${currentStack}`);
1178
- return;
1179
- }
1180
- if (error.data.stack) {
1181
- setStack(restoredError, error.data.stack);
1182
- }
934
+
935
+ const requiresSocket = () => {
936
+ return false;
1183
937
  };
1184
- const applyDataProperties = (restoredError, error) => {
1185
- restoreStackFromData(restoredError, error, getCurrentStack());
1186
- if (error.data.codeFrame) {
1187
- // @ts-ignore
1188
- restoredError.codeFrame = error.data.codeFrame;
1189
- }
1190
- if (error.data.code) {
1191
- // @ts-ignore
1192
- restoredError.code = error.data.code;
1193
- }
1194
- if (error.data.type) {
1195
- // @ts-ignore
1196
- restoredError.name = error.data.type;
1197
- }
938
+ const preparePrettyError = error => {
939
+ return error;
1198
940
  };
1199
- const applyDirectProperties = (restoredError, error) => {
1200
- if (error.stack) {
1201
- const lowerStack = restoredError.stack || '';
1202
- const indexNewLine = getNewLineIndex(lowerStack);
1203
- const parentStack = getParentStack(error);
1204
- // @ts-ignore
1205
- setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
1206
- }
1207
- if (error.codeFrame) {
1208
- // @ts-ignore
1209
- restoredError.codeFrame = error.codeFrame;
1210
- }
941
+ const logError = () => {
942
+ // handled by renderer worker
1211
943
  };
1212
- const restoreMessageError = (error, _currentStack) => {
1213
- const restoredError = constructError(error.message, error.type, error.name);
1214
- if (error.data) {
1215
- applyDataProperties(restoredError, error);
1216
- } else {
1217
- applyDirectProperties(restoredError, error);
1218
- }
1219
- return restoredError;
944
+ const handleMessage = event => {
945
+ const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
946
+ const actualExecute = event?.target?.execute || execute;
947
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
1220
948
  };
1221
- const restoreJsonRpcError = error => {
1222
- const currentStack = getCurrentStack();
1223
- if (error && error instanceof Error) {
1224
- return restoreExistingError(error, currentStack);
1225
- }
1226
- if (error && error.code && error.code === MethodNotFound) {
1227
- return restoreMethodNotFoundError(error, currentStack);
1228
- }
1229
- if (error && error.message) {
1230
- return restoreMessageError(error);
1231
- }
1232
- if (typeof error === 'string') {
1233
- return new Error(`JsonRpc Error: ${error}`);
949
+
950
+ const handleIpc = ipc => {
951
+ if ('addEventListener' in ipc) {
952
+ ipc.addEventListener('message', handleMessage);
953
+ } else if ('on' in ipc) {
954
+ // deprecated
955
+ ipc.on('message', handleMessage);
1234
956
  }
1235
- return new Error(`JsonRpc Error: ${error}`);
1236
957
  };
1237
- const unwrapJsonRpcResult = responseMessage => {
1238
- if ('error' in responseMessage) {
1239
- const restoredError = restoreJsonRpcError(responseMessage.error);
1240
- throw restoredError;
1241
- }
1242
- if ('result' in responseMessage) {
1243
- return responseMessage.result;
958
+
959
+ const listen$1 = async (module, options) => {
960
+ const rawIpc = await module.listen(options);
961
+ if (module.signal) {
962
+ module.signal(rawIpc);
1244
963
  }
1245
- throw new JsonRpcError('unexpected response message');
964
+ const ipc = module.wrap(rawIpc);
965
+ return ipc;
1246
966
  };
1247
- const warn = (...args) => {
1248
- console.warn(...args);
967
+
968
+ const create$6 = async ({
969
+ commandMap,
970
+ isMessagePortOpen = true,
971
+ messagePort
972
+ }) => {
973
+ // TODO create a commandMap per rpc instance
974
+ register(commandMap);
975
+ const rawIpc = await IpcParentWithMessagePort$1.create({
976
+ isMessagePortOpen,
977
+ messagePort
978
+ });
979
+ const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
980
+ handleIpc(ipc);
981
+ const rpc = createRpc(ipc);
982
+ messagePort.start();
983
+ return rpc;
1249
984
  };
1250
- const resolve = (id, response) => {
1251
- const fn = get$1(id);
1252
- if (!fn) {
1253
- console.log(response);
1254
- warn(`callback ${id} may already be disposed`);
1255
- return;
1256
- }
1257
- fn(response);
1258
- remove$1(id);
985
+
986
+ const create$5 = async ({
987
+ commandMap,
988
+ isMessagePortOpen,
989
+ send
990
+ }) => {
991
+ const {
992
+ port1,
993
+ port2
994
+ } = new MessageChannel();
995
+ await send(port1);
996
+ return create$6({
997
+ commandMap,
998
+ isMessagePortOpen,
999
+ messagePort: port2
1000
+ });
1259
1001
  };
1260
- const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
1261
- const getErrorType = prettyError => {
1262
- if (prettyError && prettyError.type) {
1263
- return prettyError.type;
1264
- }
1265
- if (prettyError && prettyError.constructor && prettyError.constructor.name) {
1266
- return prettyError.constructor.name;
1267
- }
1268
- return undefined;
1002
+
1003
+ const createSharedLazyRpc = factory => {
1004
+ let rpcPromise;
1005
+ const getOrCreate = () => {
1006
+ if (!rpcPromise) {
1007
+ rpcPromise = factory();
1008
+ }
1009
+ return rpcPromise;
1010
+ };
1011
+ return {
1012
+ async dispose() {
1013
+ const rpc = await getOrCreate();
1014
+ await rpc.dispose();
1015
+ },
1016
+ async invoke(method, ...params) {
1017
+ const rpc = await getOrCreate();
1018
+ return rpc.invoke(method, ...params);
1019
+ },
1020
+ async invokeAndTransfer(method, ...params) {
1021
+ const rpc = await getOrCreate();
1022
+ return rpc.invokeAndTransfer(method, ...params);
1023
+ },
1024
+ async send(method, ...params) {
1025
+ const rpc = await getOrCreate();
1026
+ rpc.send(method, ...params);
1027
+ }
1028
+ };
1269
1029
  };
1270
- const isAlreadyStack = line => {
1271
- return line.trim().startsWith('at ');
1030
+
1031
+ const create$4 = async ({
1032
+ commandMap,
1033
+ isMessagePortOpen,
1034
+ send
1035
+ }) => {
1036
+ return createSharedLazyRpc(() => {
1037
+ return create$5({
1038
+ commandMap,
1039
+ isMessagePortOpen,
1040
+ send
1041
+ });
1042
+ });
1272
1043
  };
1273
- const getStack = prettyError => {
1274
- const stackString = prettyError.stack || '';
1275
- const newLineIndex = stackString.indexOf('\n');
1276
- if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
1277
- return stackString.slice(newLineIndex + 1);
1278
- }
1279
- return stackString;
1044
+
1045
+ const create$3 = async ({
1046
+ commandMap
1047
+ }) => {
1048
+ // TODO create a commandMap per rpc instance
1049
+ register(commandMap);
1050
+ const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
1051
+ handleIpc(ipc);
1052
+ const rpc = createRpc(ipc);
1053
+ return rpc;
1280
1054
  };
1281
- const getErrorProperty = (error, prettyError) => {
1282
- if (error && error.code === E_COMMAND_NOT_FOUND) {
1283
- return {
1284
- code: MethodNotFound,
1285
- data: error.stack,
1286
- message: error.message
1287
- };
1288
- }
1289
- return {
1290
- code: Custom,
1291
- data: {
1292
- code: prettyError.code,
1293
- codeFrame: prettyError.codeFrame,
1294
- name: prettyError.name,
1295
- stack: getStack(prettyError),
1296
- type: getErrorType(prettyError)
1297
- },
1298
- message: prettyError.message
1055
+
1056
+ const createMockRpc = ({
1057
+ commandMap
1058
+ }) => {
1059
+ const invocations = [];
1060
+ const invoke = (method, ...params) => {
1061
+ invocations.push([method, ...params]);
1062
+ const command = commandMap[method];
1063
+ if (!command) {
1064
+ throw new Error(`command ${method} not found`);
1065
+ }
1066
+ return command(...params);
1299
1067
  };
1300
- };
1301
- const create$1$1 = (id, error) => {
1302
- return {
1303
- error,
1304
- id,
1305
- jsonrpc: Two$1
1068
+ const mockRpc = {
1069
+ invocations,
1070
+ invoke,
1071
+ invokeAndTransfer: invoke
1306
1072
  };
1073
+ return mockRpc;
1307
1074
  };
1308
- const getErrorResponse = (id, error, preparePrettyError, logError) => {
1309
- const prettyError = preparePrettyError(error);
1310
- logError(error, prettyError);
1311
- const errorProperty = getErrorProperty(error, prettyError);
1312
- return create$1$1(id, errorProperty);
1075
+
1076
+ const rpcs = Object.create(null);
1077
+ const set$4 = (id, rpc) => {
1078
+ rpcs[id] = rpc;
1313
1079
  };
1314
- const create$8 = (message, result) => {
1315
- return {
1316
- id: message.id,
1317
- jsonrpc: Two$1,
1318
- result: result ?? null
1319
- };
1080
+ const get$1 = id => {
1081
+ return rpcs[id];
1320
1082
  };
1321
- const getSuccessResponse = (message, result) => {
1322
- const resultProperty = result ?? null;
1323
- return create$8(message, resultProperty);
1083
+ const remove = id => {
1084
+ delete rpcs[id];
1324
1085
  };
1325
- const getErrorResponseSimple = (id, error) => {
1086
+
1087
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1088
+ const create$2 = rpcId => {
1326
1089
  return {
1327
- error: {
1328
- code: Custom,
1329
- data: error,
1090
+ async dispose() {
1091
+ const rpc = get$1(rpcId);
1092
+ await rpc.dispose();
1093
+ },
1094
+ // @ts-ignore
1095
+ invoke(method, ...params) {
1096
+ const rpc = get$1(rpcId);
1330
1097
  // @ts-ignore
1331
- message: error.message
1098
+ return rpc.invoke(method, ...params);
1332
1099
  },
1333
- id,
1334
- jsonrpc: Two$1
1335
- };
1336
- };
1337
- const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
1338
- try {
1339
- const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
1340
- return getSuccessResponse(message, result);
1341
- } catch (error) {
1342
- if (ipc.canUseSimpleErrorResponse) {
1343
- return getErrorResponseSimple(message.id, error);
1100
+ // @ts-ignore
1101
+ invokeAndTransfer(method, ...params) {
1102
+ const rpc = get$1(rpcId);
1103
+ // @ts-ignore
1104
+ return rpc.invokeAndTransfer(method, ...params);
1105
+ },
1106
+ registerMockRpc(commandMap) {
1107
+ const mockRpc = createMockRpc({
1108
+ commandMap
1109
+ });
1110
+ set$4(rpcId, mockRpc);
1111
+ // @ts-ignore
1112
+ mockRpc[Symbol.dispose] = () => {
1113
+ remove(rpcId);
1114
+ };
1115
+ // @ts-ignore
1116
+ return mockRpc;
1117
+ },
1118
+ set(rpc) {
1119
+ set$4(rpcId, rpc);
1344
1120
  }
1345
- return getErrorResponse(message.id, error, preparePrettyError, logError);
1346
- }
1347
- };
1348
- const defaultPreparePrettyError = error => {
1349
- return error;
1350
- };
1351
- const defaultLogError = () => {
1352
- // ignore
1121
+ };
1353
1122
  };
1354
- const defaultRequiresSocket = () => {
1355
- return false;
1123
+
1124
+ const Audio = 0;
1125
+ const Button$1 = 1;
1126
+ const Col = 2;
1127
+ const ColGroup = 3;
1128
+ const Div = 4;
1129
+ const H1 = 5;
1130
+ const Input = 6;
1131
+ const Kbd = 7;
1132
+ const Span = 8;
1133
+ const Table = 9;
1134
+ const TBody = 10;
1135
+ const Td = 11;
1136
+ const Text = 12;
1137
+ const Th = 13;
1138
+ const THead = 14;
1139
+ const Tr = 15;
1140
+ const I = 16;
1141
+ const Img = 17;
1142
+ const Root = 0;
1143
+ const Ins = 20;
1144
+ const Del = 21;
1145
+ const H2 = 22;
1146
+ const H3 = 23;
1147
+ const H4 = 24;
1148
+ const H5 = 25;
1149
+ const H6 = 26;
1150
+ const Article = 27;
1151
+ const Aside = 28;
1152
+ const Footer = 29;
1153
+ const Header = 30;
1154
+ const Nav = 40;
1155
+ const Section = 41;
1156
+ const Search = 42;
1157
+ const Dd = 43;
1158
+ const Dl = 44;
1159
+ const Figcaption = 45;
1160
+ const Figure = 46;
1161
+ const Hr = 47;
1162
+ const Li = 48;
1163
+ const Ol = 49;
1164
+ const P = 50;
1165
+ const Pre = 51;
1166
+ const A = 53;
1167
+ const Abbr = 54;
1168
+ const Br = 55;
1169
+ const Cite = 56;
1170
+ const Data = 57;
1171
+ const Time = 58;
1172
+ const Tfoot = 59;
1173
+ const Ul = 60;
1174
+ const Video = 61;
1175
+ const TextArea = 62;
1176
+ const Select = 63;
1177
+ const Option = 64;
1178
+ const Code = 65;
1179
+ const Label = 66;
1180
+ const Dt = 67;
1181
+ const Iframe = 68;
1182
+ const Main = 69;
1183
+ const Strong = 70;
1184
+ const Em = 71;
1185
+ const Style = 72;
1186
+ const Html = 73;
1187
+ const Head = 74;
1188
+ const Title = 75;
1189
+ const Meta = 76;
1190
+ const Canvas = 77;
1191
+ const Form = 78;
1192
+ const BlockQuote = 79;
1193
+ const Quote = 80;
1194
+ const Circle = 81;
1195
+ const Defs = 82;
1196
+ const Ellipse = 83;
1197
+ const G = 84;
1198
+ const Line = 85;
1199
+ const Path = 86;
1200
+ const Polygon = 87;
1201
+ const Polyline = 88;
1202
+ const Rect = 89;
1203
+ const Svg = 90;
1204
+ const Use = 91;
1205
+ const Reference = 100;
1206
+
1207
+ const VirtualDomElements = {
1208
+ __proto__: null,
1209
+ A,
1210
+ Abbr,
1211
+ Article,
1212
+ Aside,
1213
+ Audio,
1214
+ BlockQuote,
1215
+ Br,
1216
+ Button: Button$1,
1217
+ Canvas,
1218
+ Circle,
1219
+ Cite,
1220
+ Code,
1221
+ Col,
1222
+ ColGroup,
1223
+ Data,
1224
+ Dd,
1225
+ Defs,
1226
+ Del,
1227
+ Div,
1228
+ Dl,
1229
+ Dt,
1230
+ Ellipse,
1231
+ Em,
1232
+ Figcaption,
1233
+ Figure,
1234
+ Footer,
1235
+ Form,
1236
+ G,
1237
+ H1,
1238
+ H2,
1239
+ H3,
1240
+ H4,
1241
+ H5,
1242
+ H6,
1243
+ Head,
1244
+ Header,
1245
+ Hr,
1246
+ Html,
1247
+ I,
1248
+ Iframe,
1249
+ Img,
1250
+ Input,
1251
+ Ins,
1252
+ Kbd,
1253
+ Label,
1254
+ Li,
1255
+ Line,
1256
+ Main,
1257
+ Meta,
1258
+ Nav,
1259
+ Ol,
1260
+ Option,
1261
+ P,
1262
+ Path,
1263
+ Polygon,
1264
+ Polyline,
1265
+ Pre,
1266
+ Quote,
1267
+ Rect,
1268
+ Reference,
1269
+ Root,
1270
+ Search,
1271
+ Section,
1272
+ Select,
1273
+ Span,
1274
+ Strong,
1275
+ Style,
1276
+ Svg,
1277
+ TBody,
1278
+ THead,
1279
+ Table,
1280
+ Td,
1281
+ Text,
1282
+ TextArea,
1283
+ Tfoot,
1284
+ Th,
1285
+ Time,
1286
+ Title,
1287
+ Tr,
1288
+ Ul,
1289
+ Use,
1290
+ Video
1356
1291
  };
1357
- const defaultResolve = resolve;
1358
1292
 
1359
- // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
1360
- const normalizeParams = args => {
1361
- if (args.length === 1) {
1362
- const options = args[0];
1363
- return {
1364
- execute: options.execute,
1365
- ipc: options.ipc,
1366
- logError: options.logError || defaultLogError,
1367
- message: options.message,
1368
- preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
1369
- requiresSocket: options.requiresSocket || defaultRequiresSocket,
1370
- resolve: options.resolve || defaultResolve
1371
- };
1372
- }
1373
- return {
1374
- execute: args[2],
1375
- ipc: args[0],
1376
- logError: args[5],
1377
- message: args[1],
1378
- preparePrettyError: args[4],
1379
- requiresSocket: args[6],
1380
- resolve: args[3]
1381
- };
1382
- };
1383
- const handleJsonRpcMessage = async (...args) => {
1384
- const options = normalizeParams(args);
1385
- const {
1386
- execute,
1387
- ipc,
1388
- logError,
1389
- message,
1390
- preparePrettyError,
1391
- requiresSocket,
1392
- resolve
1393
- } = options;
1394
- if ('id' in message) {
1395
- if ('method' in message) {
1396
- const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1397
- try {
1398
- ipc.send(response);
1399
- } catch (error) {
1400
- const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
1401
- ipc.send(errorResponse);
1402
- }
1403
- return;
1404
- }
1405
- resolve(message.id, message);
1406
- return;
1407
- }
1408
- if ('method' in message) {
1409
- await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1410
- return;
1411
- }
1412
- throw new JsonRpcError('unexpected message');
1413
- };
1293
+ const TargetName = 'event.target.name';
1414
1294
 
1415
- const Two = '2.0';
1295
+ const Tab = 2;
1296
+ const Escape = 8;
1416
1297
 
1417
- const create$7 = (method, params) => {
1418
- return {
1419
- jsonrpc: Two,
1420
- method,
1421
- params
1422
- };
1423
- };
1298
+ const Shift = 1 << 10 >>> 0;
1424
1299
 
1425
- const create$6 = (id, method, params) => {
1426
- const message = {
1427
- id,
1428
- jsonrpc: Two,
1429
- method,
1430
- params
1431
- };
1432
- return message;
1433
- };
1300
+ const DialogWorker = 7014;
1301
+ const FileSystemWorker = 209;
1302
+ const RendererWorker$1 = 1;
1434
1303
 
1435
- let id = 0;
1436
- const create$5 = () => {
1437
- return ++id;
1438
- };
1304
+ const {
1305
+ invoke: invoke$2,
1306
+ set: set$3
1307
+ } = create$2(DialogWorker);
1439
1308
 
1440
- const registerPromise = map => {
1441
- const id = create$5();
1442
- const {
1443
- promise,
1444
- resolve
1445
- } = Promise.withResolvers();
1446
- map[id] = resolve;
1447
- return {
1448
- id,
1449
- promise
1450
- };
1309
+ const {
1310
+ invoke: invoke$1,
1311
+ set: set$2
1312
+ } = create$2(FileSystemWorker);
1313
+ const readFile = async uri => {
1314
+ return invoke$1('FileSystem.readFile', uri);
1451
1315
  };
1452
1316
 
1453
- const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
1454
- const {
1455
- id,
1456
- promise
1457
- } = registerPromise(callbacks);
1458
- const message = create$6(id, method, params);
1459
- if (useSendAndTransfer && ipc.sendAndTransfer) {
1460
- ipc.sendAndTransfer(message);
1461
- } else {
1462
- ipc.send(message);
1463
- }
1464
- const responseMessage = await promise;
1465
- return unwrapJsonRpcResult(responseMessage);
1317
+ const {
1318
+ invoke,
1319
+ invokeAndTransfer,
1320
+ set: set$1
1321
+ } = create$2(RendererWorker$1);
1322
+ const getElectronVersion$1 = async () => {
1323
+ return invoke('Process.getElectronVersion');
1466
1324
  };
1467
- const createRpc = ipc => {
1468
- const callbacks = Object.create(null);
1469
- ipc._resolve = (id, response) => {
1470
- const fn = callbacks[id];
1471
- if (!fn) {
1472
- console.warn(`callback ${id} may already be disposed`);
1473
- return;
1474
- }
1475
- fn(response);
1476
- delete callbacks[id];
1477
- };
1478
- const rpc = {
1479
- async dispose() {
1480
- await ipc?.dispose();
1481
- },
1482
- invoke(method, ...params) {
1483
- return invokeHelper(callbacks, ipc, method, params, false);
1484
- },
1485
- invokeAndTransfer(method, ...params) {
1486
- return invokeHelper(callbacks, ipc, method, params, true);
1487
- },
1488
- // @ts-ignore
1489
- ipc,
1490
- /**
1491
- * @deprecated
1492
- */
1493
- send(method, ...params) {
1494
- const message = create$7(method, params);
1495
- ipc.send(message);
1496
- }
1497
- };
1498
- return rpc;
1325
+ const getNodeVersion$1 = async () => {
1326
+ return invoke('Process.getNodeVersion');
1499
1327
  };
1500
-
1501
- const requiresSocket = () => {
1502
- return false;
1328
+ const getChromeVersion$1 = async () => {
1329
+ return invoke('Process.getChromeVersion');
1503
1330
  };
1504
- const preparePrettyError = error => {
1505
- return error;
1331
+ const getV8Version$1 = async () => {
1332
+ return invoke('Process.getV8Version');
1506
1333
  };
1507
- const logError = () => {
1508
- // handled by renderer worker
1334
+ const sendMessagePortToDialogWorker = async port => {
1335
+ const command = 'HandleMessagePort.handleMessagePort';
1336
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker', port, command);
1509
1337
  };
1510
- const handleMessage = event => {
1511
- const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
1512
- const actualExecute = event?.target?.execute || execute;
1513
- return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
1338
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1339
+ const command = 'FileSystem.handleMessagePort';
1340
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1514
1341
  };
1515
-
1516
- const handleIpc = ipc => {
1517
- if ('addEventListener' in ipc) {
1518
- ipc.addEventListener('message', handleMessage);
1519
- } else if ('on' in ipc) {
1520
- // deprecated
1521
- ipc.on('message', handleMessage);
1522
- }
1342
+ const setFocus = key => {
1343
+ return invoke('Focus.setFocus', key);
1523
1344
  };
1524
-
1525
- const listen$1 = async (module, options) => {
1526
- const rawIpc = await module.listen(options);
1527
- if (module.signal) {
1528
- module.signal(rawIpc);
1529
- }
1530
- const ipc = module.wrap(rawIpc);
1531
- return ipc;
1345
+ const closeWidget$1 = async widgetId => {
1346
+ return invoke('Viewlet.closeWidget', widgetId);
1532
1347
  };
1533
-
1534
- const create$4 = async ({
1535
- commandMap,
1536
- isMessagePortOpen = true,
1537
- messagePort
1538
- }) => {
1539
- // TODO create a commandMap per rpc instance
1540
- register(commandMap);
1541
- const rawIpc = await IpcParentWithMessagePort$1.create({
1542
- isMessagePortOpen,
1543
- messagePort
1544
- });
1545
- const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
1546
- handleIpc(ipc);
1547
- const rpc = createRpc(ipc);
1548
- messagePort.start();
1549
- return rpc;
1348
+ const writeClipBoardText = async text => {
1349
+ await invoke('ClipBoard.writeText', /* text */text);
1350
+ };
1351
+ const openWidget = async name => {
1352
+ await invoke('Viewlet.openWidget', name);
1353
+ };
1354
+ const getWindowId$1 = async () => {
1355
+ return invoke('GetWindowId.getWindowId');
1550
1356
  };
1551
1357
 
1552
- const create$3 = async ({
1553
- commandMap,
1554
- isMessagePortOpen,
1555
- send
1556
- }) => {
1557
- const {
1558
- port1,
1559
- port2
1560
- } = new MessageChannel();
1561
- await send(port1);
1562
- return create$4({
1563
- commandMap,
1564
- isMessagePortOpen,
1565
- messagePort: port2
1566
- });
1358
+ const RendererWorker = {
1359
+ __proto__: null,
1360
+ closeWidget: closeWidget$1,
1361
+ getChromeVersion: getChromeVersion$1,
1362
+ getElectronVersion: getElectronVersion$1,
1363
+ getNodeVersion: getNodeVersion$1,
1364
+ getV8Version: getV8Version$1,
1365
+ getWindowId: getWindowId$1,
1366
+ invoke,
1367
+ invokeAndTransfer,
1368
+ openWidget,
1369
+ sendMessagePortToDialogWorker,
1370
+ sendMessagePortToFileSystemWorker,
1371
+ set: set$1,
1372
+ setFocus,
1373
+ writeClipBoardText
1567
1374
  };
1568
1375
 
1569
- const createSharedLazyRpc = factory => {
1570
- let rpcPromise;
1571
- const getOrCreate = () => {
1572
- if (!rpcPromise) {
1573
- rpcPromise = factory();
1376
+ const toCommandId = key => {
1377
+ const dotIndex = key.indexOf('.');
1378
+ return key.slice(dotIndex + 1);
1379
+ };
1380
+ const create$1 = () => {
1381
+ const commandQueues = new Map();
1382
+ const generations = Object.create(null);
1383
+ const states = Object.create(null);
1384
+ const commandMapRef = {};
1385
+ const getGeneration = uid => generations[uid] || 0;
1386
+ const isCurrentGeneration = (uid, generation) => {
1387
+ return states[uid] !== undefined && getGeneration(uid) === generation;
1388
+ };
1389
+ const updateState = (uid, generation, fallbackState, updater) => {
1390
+ if (!isCurrentGeneration(uid, generation)) {
1391
+ return Promise.resolve(fallbackState);
1392
+ }
1393
+ const current = states[uid];
1394
+ const updatedState = updater(current.newState);
1395
+ if (updatedState !== current.newState) {
1396
+ states[uid] = {
1397
+ newState: updatedState,
1398
+ oldState: current.oldState,
1399
+ scheduledState: updatedState
1400
+ };
1401
+ }
1402
+ return Promise.resolve(updatedState);
1403
+ };
1404
+ const createAsyncCommandContext = (uid, generation) => {
1405
+ let latestState = states[uid].newState;
1406
+ return {
1407
+ getState: () => {
1408
+ if (isCurrentGeneration(uid, generation)) {
1409
+ latestState = states[uid].newState;
1410
+ }
1411
+ return latestState;
1412
+ },
1413
+ updateState: async updater => {
1414
+ latestState = await updateState(uid, generation, latestState, updater);
1415
+ return latestState;
1416
+ }
1417
+ };
1418
+ };
1419
+ const enqueueCommand = async (uid, command) => {
1420
+ const previous = commandQueues.get(uid) || Promise.resolve();
1421
+ const run = async () => {
1422
+ try {
1423
+ await previous;
1424
+ } catch {
1425
+ // The previous caller receives its error; later commands must still run.
1426
+ }
1427
+ await command();
1428
+ };
1429
+ const current = run();
1430
+ commandQueues.set(uid, current);
1431
+ try {
1432
+ await current;
1433
+ } finally {
1434
+ if (commandQueues.get(uid) === current) {
1435
+ commandQueues.delete(uid);
1436
+ }
1574
1437
  }
1575
- return rpcPromise;
1576
1438
  };
1577
1439
  return {
1578
- async dispose() {
1579
- const rpc = await getOrCreate();
1580
- await rpc.dispose();
1440
+ clear() {
1441
+ commandQueues.clear();
1442
+ for (const key of Object.keys(states)) {
1443
+ delete states[key];
1444
+ }
1581
1445
  },
1582
- async invoke(method, ...params) {
1583
- const rpc = await getOrCreate();
1584
- return rpc.invoke(method, ...params);
1446
+ diff(uid, modules, numbers) {
1447
+ const {
1448
+ oldState,
1449
+ scheduledState
1450
+ } = states[uid];
1451
+ const diffResult = [];
1452
+ for (let i = 0; i < modules.length; i++) {
1453
+ const fn = modules[i];
1454
+ if (!fn(oldState, scheduledState)) {
1455
+ diffResult.push(numbers[i]);
1456
+ }
1457
+ }
1458
+ return diffResult;
1585
1459
  },
1586
- async invokeAndTransfer(method, ...params) {
1587
- const rpc = await getOrCreate();
1588
- return rpc.invokeAndTransfer(method, ...params);
1460
+ dispose(uid) {
1461
+ commandQueues.delete(uid);
1462
+ delete states[uid];
1589
1463
  },
1590
- async send(method, ...params) {
1591
- const rpc = await getOrCreate();
1592
- rpc.send(method, ...params);
1464
+ get(uid) {
1465
+ return states[uid];
1466
+ },
1467
+ getCommandIds() {
1468
+ const keys = Object.keys(commandMapRef);
1469
+ const ids = keys.map(toCommandId);
1470
+ return ids;
1471
+ },
1472
+ getKeys() {
1473
+ return Object.keys(states).map(Number);
1474
+ },
1475
+ registerCommands(commandMap) {
1476
+ Object.assign(commandMapRef, commandMap);
1477
+ },
1478
+ set(uid, oldState, newState, scheduledState) {
1479
+ const current = states[uid];
1480
+ if (!current || oldState === newState && newState !== current.newState) {
1481
+ generations[uid] = getGeneration(uid) + 1;
1482
+ }
1483
+ states[uid] = {
1484
+ newState,
1485
+ oldState,
1486
+ scheduledState: scheduledState ?? newState
1487
+ };
1488
+ },
1489
+ wrapAsyncCommand(fn) {
1490
+ const wrapped = async (uid, ...args) => {
1491
+ const generation = getGeneration(uid);
1492
+ const context = createAsyncCommandContext(uid, generation);
1493
+ await fn(context, ...args);
1494
+ };
1495
+ return wrapped;
1496
+ },
1497
+ wrapCommand(fn) {
1498
+ const wrapped = async (uid, ...args) => {
1499
+ const generation = getGeneration(uid);
1500
+ const {
1501
+ newState,
1502
+ oldState
1503
+ } = states[uid];
1504
+ const newerState = await fn(newState, ...args);
1505
+ if (oldState === newerState || newState === newerState) {
1506
+ return;
1507
+ }
1508
+ if (!isCurrentGeneration(uid, generation)) {
1509
+ return;
1510
+ }
1511
+ const latestOld = states[uid];
1512
+ const latestNew = {
1513
+ ...latestOld.newState,
1514
+ ...newerState
1515
+ };
1516
+ states[uid] = {
1517
+ newState: latestNew,
1518
+ oldState: latestOld.oldState,
1519
+ scheduledState: latestNew
1520
+ };
1521
+ };
1522
+ return wrapped;
1523
+ },
1524
+ wrapGetter(fn) {
1525
+ const wrapped = (uid, ...args) => {
1526
+ const {
1527
+ newState
1528
+ } = states[uid];
1529
+ return fn(newState, ...args);
1530
+ };
1531
+ return wrapped;
1532
+ },
1533
+ wrapLoadContent(fn) {
1534
+ const wrapped = async (uid, ...args) => {
1535
+ const generation = getGeneration(uid);
1536
+ const {
1537
+ newState,
1538
+ oldState
1539
+ } = states[uid];
1540
+ const result = await fn(newState, ...args);
1541
+ const {
1542
+ error,
1543
+ state
1544
+ } = result;
1545
+ if (oldState === state || newState === state) {
1546
+ return {
1547
+ error
1548
+ };
1549
+ }
1550
+ if (!isCurrentGeneration(uid, generation)) {
1551
+ return {
1552
+ error
1553
+ };
1554
+ }
1555
+ const latestOld = states[uid];
1556
+ const latestNew = {
1557
+ ...latestOld.newState,
1558
+ ...state
1559
+ };
1560
+ states[uid] = {
1561
+ newState: latestNew,
1562
+ oldState: latestOld.oldState,
1563
+ scheduledState: latestNew
1564
+ };
1565
+ return {
1566
+ error
1567
+ };
1568
+ };
1569
+ return wrapped;
1570
+ },
1571
+ wrapSerialAsyncCommand(fn) {
1572
+ const wrapped = async (uid, ...args) => {
1573
+ await enqueueCommand(uid, async () => {
1574
+ if (!states[uid]) {
1575
+ return;
1576
+ }
1577
+ const generation = getGeneration(uid);
1578
+ const context = createAsyncCommandContext(uid, generation);
1579
+ await fn(context, ...args);
1580
+ });
1581
+ };
1582
+ return wrapped;
1583
+ },
1584
+ wrapSerialCommand(fn) {
1585
+ const wrapped = async (uid, ...args) => {
1586
+ await enqueueCommand(uid, async () => {
1587
+ if (!states[uid]) {
1588
+ return;
1589
+ }
1590
+ const generation = getGeneration(uid);
1591
+ const {
1592
+ newState,
1593
+ oldState
1594
+ } = states[uid];
1595
+ const newerState = await fn(newState, ...args);
1596
+ if (oldState === newerState || newState === newerState) {
1597
+ return;
1598
+ }
1599
+ if (!isCurrentGeneration(uid, generation)) {
1600
+ return;
1601
+ }
1602
+ const latestOld = states[uid];
1603
+ const latestNew = {
1604
+ ...latestOld.newState,
1605
+ ...newerState
1606
+ };
1607
+ states[uid] = {
1608
+ newState: latestNew,
1609
+ oldState: latestOld.oldState,
1610
+ scheduledState: latestNew
1611
+ };
1612
+ });
1613
+ };
1614
+ return wrapped;
1593
1615
  }
1594
1616
  };
1595
1617
  };
1596
1618
 
1597
- const create$2 = async ({
1598
- commandMap,
1599
- isMessagePortOpen,
1600
- send
1601
- }) => {
1602
- return createSharedLazyRpc(() => {
1603
- return create$3({
1604
- commandMap,
1605
- isMessagePortOpen,
1606
- send
1607
- });
1608
- });
1619
+ const {
1620
+ dispose: dispose$1,
1621
+ get,
1622
+ getCommandIds,
1623
+ registerCommands,
1624
+ set,
1625
+ wrapAsyncCommand,
1626
+ wrapCommand
1627
+ } = create$1();
1628
+
1629
+ const create = uid => {
1630
+ const state = {
1631
+ focusId: 0,
1632
+ lines: [],
1633
+ productName: '',
1634
+ uid
1635
+ };
1636
+ set(uid, state, state);
1637
+ };
1638
+
1639
+ const RenderFocus = 2;
1640
+ const RenderFocusContext = 4;
1641
+ const RenderAbout = 3;
1642
+
1643
+ const diffType$2 = RenderAbout;
1644
+ const isEqual$2 = (oldState, newState) => {
1645
+ return oldState.productName === newState.productName && JSON.stringify(oldState.lines) === JSON.stringify(newState.lines);
1609
1646
  };
1610
1647
 
1611
- const create$1 = async ({
1612
- commandMap
1613
- }) => {
1614
- // TODO create a commandMap per rpc instance
1615
- register(commandMap);
1616
- const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
1617
- handleIpc(ipc);
1618
- const rpc = createRpc(ipc);
1619
- return rpc;
1648
+ const diffType$1 = RenderFocus;
1649
+ const isEqual$1 = (oldState, newState) => {
1650
+ return oldState.focusId === newState.focusId;
1620
1651
  };
1621
1652
 
1622
- const createMockRpc = ({
1623
- commandMap
1624
- }) => {
1625
- const invocations = [];
1626
- const invoke = (method, ...params) => {
1627
- invocations.push([method, ...params]);
1628
- const command = commandMap[method];
1629
- if (!command) {
1630
- throw new Error(`command ${method} not found`);
1653
+ const diffType = RenderFocusContext;
1654
+ const isEqual = (oldState, newState) => {
1655
+ return oldState.focusId === newState.focusId;
1656
+ };
1657
+
1658
+ const modules = [isEqual$2, isEqual$1, isEqual];
1659
+ const numbers = [diffType$2, diffType$1, diffType];
1660
+
1661
+ const diff = (oldState, newState) => {
1662
+ const diffResult = [];
1663
+ for (let i = 0; i < modules.length; i++) {
1664
+ const fn = modules[i];
1665
+ if (!fn(oldState, newState)) {
1666
+ diffResult.push(numbers[i]);
1631
1667
  }
1632
- return command(...params);
1633
- };
1634
- const mockRpc = {
1635
- invocations,
1636
- invoke,
1637
- invokeAndTransfer: invoke
1638
- };
1639
- return mockRpc;
1668
+ }
1669
+ return diffResult;
1640
1670
  };
1641
1671
 
1642
- const rpcs = Object.create(null);
1643
- const set$2 = (id, rpc) => {
1644
- rpcs[id] = rpc;
1672
+ const diff2 = uid => {
1673
+ const {
1674
+ oldState,
1675
+ scheduledState
1676
+ } = get(uid);
1677
+ const diffResult = diff(oldState, scheduledState);
1678
+ return diffResult;
1645
1679
  };
1646
- const get = id => {
1647
- return rpcs[id];
1680
+
1681
+ const dispose = uid => {
1682
+ dispose$1(uid);
1648
1683
  };
1649
- const remove = id => {
1650
- delete rpcs[id];
1684
+
1685
+ const None = 0;
1686
+ const Ok$2 = 1;
1687
+ const Copy$2 = 2;
1688
+
1689
+ const getNextFocus = focusId => {
1690
+ switch (focusId) {
1691
+ case Copy$2:
1692
+ return Ok$2;
1693
+ case Ok$2:
1694
+ return Copy$2;
1695
+ default:
1696
+ return None;
1697
+ }
1651
1698
  };
1652
1699
 
1653
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
1654
- const create = rpcId => {
1700
+ const focusNext = state => {
1701
+ const {
1702
+ focusId
1703
+ } = state;
1655
1704
  return {
1656
- async dispose() {
1657
- const rpc = get(rpcId);
1658
- await rpc.dispose();
1659
- },
1660
- // @ts-ignore
1661
- invoke(method, ...params) {
1662
- const rpc = get(rpcId);
1663
- // @ts-ignore
1664
- return rpc.invoke(method, ...params);
1665
- },
1666
- // @ts-ignore
1667
- invokeAndTransfer(method, ...params) {
1668
- const rpc = get(rpcId);
1669
- // @ts-ignore
1670
- return rpc.invokeAndTransfer(method, ...params);
1671
- },
1672
- registerMockRpc(commandMap) {
1673
- const mockRpc = createMockRpc({
1674
- commandMap
1675
- });
1676
- set$2(rpcId, mockRpc);
1677
- // @ts-ignore
1678
- mockRpc[Symbol.dispose] = () => {
1679
- remove(rpcId);
1680
- };
1681
- // @ts-ignore
1682
- return mockRpc;
1683
- },
1684
- set(rpc) {
1685
- set$2(rpcId, rpc);
1686
- }
1705
+ ...state,
1706
+ focusId: getNextFocus(focusId)
1687
1707
  };
1688
1708
  };
1689
1709
 
1690
- const {
1691
- invoke: invoke$1,
1692
- set: set$1
1693
- } = create(FileSystemWorker);
1694
- const readFile = async uri => {
1695
- return invoke$1('FileSystem.readFile', uri);
1710
+ const getPreviousFocus = focusId => {
1711
+ switch (focusId) {
1712
+ case Copy$2:
1713
+ return Ok$2;
1714
+ case Ok$2:
1715
+ return Copy$2;
1716
+ default:
1717
+ return None;
1718
+ }
1696
1719
  };
1697
1720
 
1698
- const {
1699
- invoke,
1700
- invokeAndTransfer,
1701
- set
1702
- } = create(RendererWorker$1);
1703
- const getElectronVersion$1 = async () => {
1704
- return invoke('Process.getElectronVersion');
1705
- };
1706
- const getNodeVersion$1 = async () => {
1707
- return invoke('Process.getNodeVersion');
1708
- };
1709
- const getChromeVersion$1 = async () => {
1710
- return invoke('Process.getChromeVersion');
1711
- };
1712
- const getV8Version$1 = async () => {
1713
- return invoke('Process.getV8Version');
1714
- };
1715
- const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1716
- const command = 'FileSystem.handleMessagePort';
1717
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1718
- };
1719
- const setFocus = key => {
1720
- return invoke('Focus.setFocus', key);
1721
- };
1722
- const closeWidget$1 = async widgetId => {
1723
- return invoke('Viewlet.closeWidget', widgetId);
1724
- };
1725
- const writeClipBoardText = async text => {
1726
- await invoke('ClipBoard.writeText', /* text */text);
1727
- };
1728
- const showMessageBox$1 = async options => {
1729
- return invoke('ElectronDialog.showMessageBox', options);
1721
+ const focusPrevious = state => {
1722
+ const {
1723
+ focusId
1724
+ } = state;
1725
+ return {
1726
+ ...state,
1727
+ focusId: getPreviousFocus(focusId)
1728
+ };
1730
1729
  };
1731
- const openWidget = async name => {
1732
- await invoke('Viewlet.openWidget', name);
1730
+
1731
+ const mergeClassNames = (...classNames) => {
1732
+ return classNames.filter(Boolean).join(' ');
1733
1733
  };
1734
- const getWindowId$1 = async () => {
1735
- return invoke('GetWindowId.getWindowId');
1734
+
1735
+ const text = data => {
1736
+ return {
1737
+ childCount: 0,
1738
+ text: data,
1739
+ type: Text
1740
+ };
1736
1741
  };
1737
1742
 
1738
- const RendererWorker = {
1739
- __proto__: null,
1740
- closeWidget: closeWidget$1,
1741
- getChromeVersion: getChromeVersion$1,
1742
- getElectronVersion: getElectronVersion$1,
1743
- getNodeVersion: getNodeVersion$1,
1744
- getV8Version: getV8Version$1,
1745
- getWindowId: getWindowId$1,
1746
- invoke,
1747
- invokeAndTransfer,
1748
- openWidget,
1749
- sendMessagePortToFileSystemWorker,
1750
- set,
1751
- setFocus,
1752
- showMessageBox: showMessageBox$1,
1753
- writeClipBoardText
1743
+ new Set(Object.values(VirtualDomElements));
1744
+
1745
+ const FocusAbout = 4;
1746
+
1747
+ const getKeyBindings = () => {
1748
+ return [{
1749
+ command: 'About.handleClickClose',
1750
+ key: Escape,
1751
+ when: FocusAbout
1752
+ }, {
1753
+ command: 'About.focusNext',
1754
+ key: Tab,
1755
+ when: FocusAbout
1756
+ }, {
1757
+ command: 'About.focusPrevious',
1758
+ key: Tab | Shift,
1759
+ when: FocusAbout
1760
+ }];
1754
1761
  };
1755
1762
 
1756
1763
  const {
@@ -2274,6 +2281,32 @@ const joinBySpace = (...items) => {
2274
2281
 
2275
2282
  const Focusable = -1;
2276
2283
 
2284
+ const dialogToolBarRow = {
2285
+ childCount: 1,
2286
+ className: DialogToolBarRow,
2287
+ type: Div
2288
+ };
2289
+ const dialogMessageRow = {
2290
+ childCount: 2,
2291
+ className: DialogMessageRow,
2292
+ type: Div
2293
+ };
2294
+ const dialogContentRight = {
2295
+ childCount: 2,
2296
+ className: DialogContentRight,
2297
+ type: Div
2298
+ };
2299
+ const dialogHeading = {
2300
+ childCount: 1,
2301
+ className: DialogHeading$1,
2302
+ id: DialogHeading,
2303
+ type: Div
2304
+ };
2305
+ const dialogButtonsRow = {
2306
+ childCount: 2,
2307
+ className: DialogButtonsRow,
2308
+ type: Div
2309
+ };
2277
2310
  const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copyMessage, productName) => {
2278
2311
  const dom = [{
2279
2312
  ariaLabelledBy: joinBySpace(DialogIcon, DialogHeading),
@@ -2284,11 +2317,7 @@ const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copy
2284
2317
  role: Dialog,
2285
2318
  tabIndex: Focusable,
2286
2319
  type: Div
2287
- }, {
2288
- childCount: 1,
2289
- className: DialogToolBarRow,
2290
- type: Div
2291
- }, {
2320
+ }, dialogToolBarRow, {
2292
2321
  ariaLabel: closeMessage,
2293
2322
  childCount: 1,
2294
2323
  className: DialogClose,
@@ -2298,30 +2327,13 @@ const getDialogVirtualDom = (content, closeMessage, infoMessage, okMessage, copy
2298
2327
  childCount: 0,
2299
2328
  className: mergeClassNames(MaskIcon, MaskIconClose),
2300
2329
  type: Div
2301
- }, {
2302
- childCount: 2,
2303
- className: DialogMessageRow,
2304
- type: Div
2305
- }, {
2330
+ }, dialogMessageRow, {
2306
2331
  ariaLabel: infoMessage,
2307
2332
  childCount: 0,
2308
2333
  className: mergeClassNames(DialogIcon$1, DialogInfoIcon, MaskIcon, MaskIconInfo),
2309
2334
  id: DialogIcon,
2310
2335
  type: Div
2311
- }, {
2312
- childCount: 2,
2313
- className: DialogContentRight,
2314
- type: Div
2315
- }, {
2316
- childCount: 1,
2317
- className: DialogHeading$1,
2318
- id: DialogHeading,
2319
- type: Div
2320
- }, text(productName), ...content, {
2321
- childCount: 2,
2322
- className: DialogButtonsRow,
2323
- type: Div
2324
- }, ...getSecondaryButtonVirtualDom(okMessage, Ok$1), ...getPrimaryButtonVirtualDom(copyMessage, Copy$1)];
2336
+ }, dialogContentRight, dialogHeading, text(productName), ...content, dialogButtonsRow, ...getSecondaryButtonVirtualDom(okMessage, Ok$1), ...getPrimaryButtonVirtualDom(copyMessage, Copy$1)];
2325
2337
  return dom;
2326
2338
  };
2327
2339
 
@@ -2394,8 +2406,8 @@ const doRender = (uid, diffResult) => {
2394
2406
  const {
2395
2407
  oldState,
2396
2408
  scheduledState
2397
- } = get$2(uid);
2398
- set$3(uid, scheduledState, scheduledState);
2409
+ } = get(uid);
2410
+ set(uid, scheduledState, scheduledState);
2399
2411
  const commands = applyRender(oldState, scheduledState, diffResult);
2400
2412
  return commands;
2401
2413
  };
@@ -2433,7 +2445,7 @@ const showMessageBox = async options => {
2433
2445
  ...options,
2434
2446
  windowId
2435
2447
  };
2436
- return showMessageBox$1(finalOptions);
2448
+ return invoke$2('ElectronDialog.showMessageBox', finalOptions);
2437
2449
  };
2438
2450
 
2439
2451
  const Info = 'info';
@@ -2496,7 +2508,7 @@ const showAbout = async platform => {
2496
2508
  };
2497
2509
 
2498
2510
  const commandMap = {
2499
- 'About.create': create$9,
2511
+ 'About.create': create,
2500
2512
  'About.diff2': diff2,
2501
2513
  'About.dispose': dispose,
2502
2514
  'About.focusNext': wrapCommand(focusNext),
@@ -2519,24 +2531,29 @@ const send = async port => {
2519
2531
  await sendMessagePortToFileSystemWorker(port, 0);
2520
2532
  };
2521
2533
  const initializeFileSystemWorker = async () => {
2522
- const rpc = await create$2({
2534
+ const rpc = await create$4({
2523
2535
  commandMap: {},
2524
2536
  send
2525
2537
  });
2526
- set$1(rpc);
2538
+ set$2(rpc);
2527
2539
  };
2528
2540
 
2529
2541
  const initializeRendererWorker = async () => {
2530
- const rpc = await create$1({
2542
+ const rpc = await create$3({
2531
2543
  commandMap: commandMap
2532
2544
  });
2533
- set(rpc);
2545
+ set$1(rpc);
2534
2546
  };
2535
2547
 
2536
2548
  const listen = async () => {
2537
2549
  registerCommands(commandMap);
2538
2550
  await initializeRendererWorker();
2539
2551
  await initializeFileSystemWorker();
2552
+ const dialogRpc = await create$4({
2553
+ commandMap: {},
2554
+ send: sendMessagePortToDialogWorker
2555
+ });
2556
+ set$3(dialogRpc);
2540
2557
  };
2541
2558
 
2542
2559
  const main = async () => {