@lvce-editor/title-bar-worker 2.3.0 → 2.5.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.
@@ -60,58 +60,54 @@ class AssertionError extends Error {
60
60
  this.name = 'AssertionError';
61
61
  }
62
62
  }
63
+ const Object$1 = 1;
64
+ const Number$1 = 2;
65
+ const Array$1 = 3;
66
+ const String = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown$1 = 8;
63
71
  const getType = value => {
64
72
  switch (typeof value) {
65
73
  case 'number':
66
- return 'number';
74
+ return Number$1;
67
75
  case 'function':
68
- return 'function';
76
+ return Function;
69
77
  case 'string':
70
- return 'string';
78
+ return String;
71
79
  case 'object':
72
80
  if (value === null) {
73
- return 'null';
81
+ return Null;
74
82
  }
75
83
  if (Array.isArray(value)) {
76
- return 'array';
84
+ return Array$1;
77
85
  }
78
- return 'object';
86
+ return Object$1;
79
87
  case 'boolean':
80
- return 'boolean';
88
+ return Boolean$1;
81
89
  default:
82
- return 'unknown';
90
+ return Unknown$1;
83
91
  }
84
92
  };
85
93
  const object = value => {
86
94
  const type = getType(value);
87
- if (type !== 'object') {
95
+ if (type !== Object$1) {
88
96
  throw new AssertionError('expected value to be of type object');
89
97
  }
90
98
  };
91
99
  const number = value => {
92
100
  const type = getType(value);
93
- if (type !== 'number') {
101
+ if (type !== Number$1) {
94
102
  throw new AssertionError('expected value to be of type number');
95
103
  }
96
104
  };
97
105
  const array = value => {
98
106
  const type = getType(value);
99
- if (type !== 'array') {
107
+ if (type !== Array$1) {
100
108
  throw new AssertionError('expected value to be of type array');
101
109
  }
102
110
  };
103
- const string = value => {
104
- const type = getType(value);
105
- if (type !== 'string') {
106
- throw new AssertionError('expected value to be of type string');
107
- }
108
- };
109
- const boolean = value => {
110
- const type = getType(value);
111
- if (type !== 'boolean') {
112
- throw new AssertionError('expected value to be of type boolean');
113
- }
114
- };
115
111
 
116
112
  const isMessagePort = value => {
117
113
  return value && value instanceof MessagePort;
@@ -362,22 +358,11 @@ class IpcChildWithModuleWorker extends Ipc {
362
358
  const wrap$f = global => {
363
359
  return new IpcChildWithModuleWorker(global);
364
360
  };
365
- const withResolvers = () => {
366
- let _resolve;
367
- const promise = new Promise(resolve => {
368
- _resolve = resolve;
369
- });
370
- return {
371
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
372
- resolve: _resolve,
373
- promise
374
- };
375
- };
376
361
  const waitForFirstMessage = async port => {
377
362
  const {
378
363
  resolve,
379
364
  promise
380
- } = withResolvers();
365
+ } = Promise.withResolvers();
381
366
  port.addEventListener('message', resolve, {
382
367
  once: true
383
368
  });
@@ -458,11 +443,11 @@ const remove = id => {
458
443
  delete callbacks[id];
459
444
  };
460
445
  let id$a = 0;
461
- const create$3 = () => {
446
+ const create$3$1 = () => {
462
447
  return ++id$a;
463
448
  };
464
449
  const registerPromise = () => {
465
- const id = create$3();
450
+ const id = create$3$1();
466
451
  const {
467
452
  resolve,
468
453
  promise
@@ -540,6 +525,17 @@ const constructError = (message, type, name) => {
540
525
  }
541
526
  return new ErrorConstructor(message);
542
527
  };
528
+ const joinLines = lines => {
529
+ return lines.join(NewLine);
530
+ };
531
+ const splitLines = lines => {
532
+ return lines.split(NewLine);
533
+ };
534
+ const getCurrentStack = () => {
535
+ const stackLinesToSkip = 3;
536
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
537
+ return currentStack;
538
+ };
543
539
  const getNewLineIndex = (string, startIndex = undefined) => {
544
540
  return string.indexOf(NewLine, startIndex);
545
541
  };
@@ -550,19 +546,16 @@ const getParentStack = error => {
550
546
  }
551
547
  return parentStack;
552
548
  };
553
- const joinLines = lines => {
554
- return lines.join(NewLine);
555
- };
556
549
  const MethodNotFound = -32601;
557
550
  const Custom = -32001;
558
- const splitLines = lines => {
559
- return lines.split(NewLine);
560
- };
561
551
  const restoreJsonRpcError = error => {
552
+ const currentStack = getCurrentStack();
562
553
  if (error && error instanceof Error) {
554
+ if (typeof error.stack === 'string') {
555
+ error.stack = error.stack + NewLine + currentStack;
556
+ }
563
557
  return error;
564
558
  }
565
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
566
559
  if (error && error.code && error.code === MethodNotFound) {
567
560
  const restoredError = new JsonRpcError(error.message);
568
561
  const parentStack = getParentStack(error);
@@ -643,6 +636,17 @@ const getErrorType = prettyError => {
643
636
  }
644
637
  return undefined;
645
638
  };
639
+ const isAlreadyStack = line => {
640
+ return line.trim().startsWith('at ');
641
+ };
642
+ const getStack = prettyError => {
643
+ const stackString = prettyError.stack || '';
644
+ const newLineIndex = stackString.indexOf('\n');
645
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
646
+ return stackString.slice(newLineIndex + 1);
647
+ }
648
+ return stackString;
649
+ };
646
650
  const getErrorProperty = (error, prettyError) => {
647
651
  if (error && error.code === E_COMMAND_NOT_FOUND) {
648
652
  return {
@@ -655,7 +659,7 @@ const getErrorProperty = (error, prettyError) => {
655
659
  code: Custom,
656
660
  message: prettyError.message,
657
661
  data: {
658
- stack: prettyError.stack,
662
+ stack: getStack(prettyError),
659
663
  codeFrame: prettyError.codeFrame,
660
664
  type: getErrorType(prettyError),
661
665
  code: prettyError.code,
@@ -663,18 +667,18 @@ const getErrorProperty = (error, prettyError) => {
663
667
  }
664
668
  };
665
669
  };
666
- const create$1$1 = (message, error) => {
670
+ const create$1$1 = (id, error) => {
667
671
  return {
668
672
  jsonrpc: Two,
669
- id: message.id,
673
+ id,
670
674
  error
671
675
  };
672
676
  };
673
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
677
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
674
678
  const prettyError = preparePrettyError(error);
675
679
  logError(error, prettyError);
676
680
  const errorProperty = getErrorProperty(error, prettyError);
677
- return create$1$1(message, errorProperty);
681
+ return create$1$1(id, errorProperty);
678
682
  };
679
683
  const create$5 = (message, result) => {
680
684
  return {
@@ -687,12 +691,27 @@ const getSuccessResponse = (message, result) => {
687
691
  const resultProperty = result ?? null;
688
692
  return create$5(message, resultProperty);
689
693
  };
694
+ const getErrorResponseSimple = (id, error) => {
695
+ return {
696
+ jsonrpc: Two,
697
+ id,
698
+ error: {
699
+ code: Custom,
700
+ // @ts-ignore
701
+ message: error.message,
702
+ data: error
703
+ }
704
+ };
705
+ };
690
706
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
691
707
  try {
692
708
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
693
709
  return getSuccessResponse(message, result);
694
710
  } catch (error) {
695
- return getErrorResponse(message, error, preparePrettyError, logError);
711
+ if (ipc.canUseSimpleErrorResponse) {
712
+ return getErrorResponseSimple(message.id, error);
713
+ }
714
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
696
715
  }
697
716
  };
698
717
  const defaultPreparePrettyError = error => {
@@ -747,7 +766,7 @@ const handleJsonRpcMessage = async (...args) => {
747
766
  try {
748
767
  ipc.send(response);
749
768
  } catch (error) {
750
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
769
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
751
770
  ipc.send(errorResponse);
752
771
  }
753
772
  return;
@@ -778,13 +797,19 @@ const send = (transport, method, ...params) => {
778
797
  const message = create$4(method, params);
779
798
  transport.send(message);
780
799
  };
781
- const invoke$1 = (ipc, method, ...params) => {
800
+ const invoke$2 = (ipc, method, ...params) => {
782
801
  return invokeHelper(ipc, method, params, false);
783
802
  };
784
- const invokeAndTransfer = (ipc, method, ...params) => {
803
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
785
804
  return invokeHelper(ipc, method, params, true);
786
805
  };
787
806
 
807
+ class CommandNotFoundError extends Error {
808
+ constructor(command) {
809
+ super(`Command not found ${command}`);
810
+ this.name = 'CommandNotFoundError';
811
+ }
812
+ }
788
813
  const commands = Object.create(null);
789
814
  const register = commandMap => {
790
815
  Object.assign(commands, commandMap);
@@ -795,7 +820,7 @@ const getCommand = key => {
795
820
  const execute = (command, ...args) => {
796
821
  const fn = getCommand(command);
797
822
  if (!fn) {
798
- throw new Error(`command not found ${command}`);
823
+ throw new CommandNotFoundError(command);
799
824
  }
800
825
  return fn(...args);
801
826
  };
@@ -811,10 +836,10 @@ const createRpc = ipc => {
811
836
  send(ipc, method, ...params);
812
837
  },
813
838
  invoke(method, ...params) {
814
- return invoke$1(ipc, method, ...params);
839
+ return invoke$2(ipc, method, ...params);
815
840
  },
816
841
  invokeAndTransfer(method, ...params) {
817
- return invokeAndTransfer(ipc, method, ...params);
842
+ return invokeAndTransfer$1(ipc, method, ...params);
818
843
  },
819
844
  async dispose() {
820
845
  await ipc?.dispose();
@@ -852,7 +877,7 @@ const listen$1 = async (module, options) => {
852
877
  const ipc = module.wrap(rawIpc);
853
878
  return ipc;
854
879
  };
855
- const create$2 = async ({
880
+ const create$3 = async ({
856
881
  commandMap
857
882
  }) => {
858
883
  // TODO create a commandMap per rpc instance
@@ -864,7 +889,110 @@ const create$2 = async ({
864
889
  };
865
890
  const WebWorkerRpcClient = {
866
891
  __proto__: null,
867
- create: create$2
892
+ create: create$3
893
+ };
894
+ const createMockRpc = ({
895
+ commandMap
896
+ }) => {
897
+ const invocations = [];
898
+ const invoke = (method, ...params) => {
899
+ invocations.push([method, ...params]);
900
+ const command = commandMap[method];
901
+ if (!command) {
902
+ throw new Error(`command ${method} not found`);
903
+ }
904
+ return command(...params);
905
+ };
906
+ const mockRpc = {
907
+ invoke,
908
+ invokeAndTransfer: invoke,
909
+ invocations
910
+ };
911
+ return mockRpc;
912
+ };
913
+
914
+ const toCommandId = key => {
915
+ const dotIndex = key.indexOf('.');
916
+ return key.slice(dotIndex + 1);
917
+ };
918
+ const create$2 = () => {
919
+ const states = Object.create(null);
920
+ const commandMapRef = {};
921
+ return {
922
+ get(uid) {
923
+ return states[uid];
924
+ },
925
+ set(uid, oldState, newState) {
926
+ states[uid] = {
927
+ oldState,
928
+ newState
929
+ };
930
+ },
931
+ dispose(uid) {
932
+ delete states[uid];
933
+ },
934
+ getKeys() {
935
+ return Object.keys(states).map(key => {
936
+ return Number.parseInt(key);
937
+ });
938
+ },
939
+ clear() {
940
+ for (const key of Object.keys(states)) {
941
+ delete states[key];
942
+ }
943
+ },
944
+ wrapCommand(fn) {
945
+ const wrapped = async (uid, ...args) => {
946
+ const {
947
+ newState
948
+ } = states[uid];
949
+ const newerState = await fn(newState, ...args);
950
+ if (newState === newerState) {
951
+ return;
952
+ }
953
+ const latest = states[uid];
954
+ states[uid] = {
955
+ oldState: latest.oldState,
956
+ newState: newerState
957
+ };
958
+ };
959
+ return wrapped;
960
+ },
961
+ wrapGetter(fn) {
962
+ const wrapped = (uid, ...args) => {
963
+ const {
964
+ newState
965
+ } = states[uid];
966
+ return fn(newState, ...args);
967
+ };
968
+ return wrapped;
969
+ },
970
+ diff(uid, modules, numbers) {
971
+ const {
972
+ oldState,
973
+ newState
974
+ } = states[uid];
975
+ const diffResult = [];
976
+ for (let i = 0; i < modules.length; i++) {
977
+ const fn = modules[i];
978
+ if (!fn(oldState, newState)) {
979
+ diffResult.push(numbers[i]);
980
+ }
981
+ }
982
+ return diffResult;
983
+ },
984
+ getCommandIds() {
985
+ const keys = Object.keys(commandMapRef);
986
+ const ids = keys.map(toCommandId);
987
+ return ids;
988
+ },
989
+ registerCommands(commandMap) {
990
+ Object.assign(commandMapRef, commandMap);
991
+ }
992
+ };
993
+ };
994
+ const terminate = () => {
995
+ globalThis.close();
868
996
  };
869
997
 
870
998
  const RenderEntries = 1;
@@ -900,25 +1028,11 @@ const diff = (oldState, newState) => {
900
1028
  return diffResult;
901
1029
  };
902
1030
 
903
- const create$1 = () => {
904
- const states = Object.create(null);
905
- return {
906
- get(uid) {
907
- return states[uid];
908
- },
909
- set(uid, oldState, newState) {
910
- states[uid] = {
911
- oldState,
912
- newState
913
- };
914
- }
915
- };
916
- };
917
-
918
1031
  const {
919
1032
  get: get$1,
920
- set: set$1
921
- } = create$1();
1033
+ set: set$3,
1034
+ wrapCommand
1035
+ } = create$2();
922
1036
 
923
1037
  const diff2 = uid => {
924
1038
  const {
@@ -934,104 +1048,77 @@ const getCommandIds = () => {
934
1048
  return commandsIds;
935
1049
  };
936
1050
 
937
- const Backspace$1 = 1;
938
- const Tab$1 = 2;
939
- const Enter$1 = 3;
940
- const Escape$1 = 8;
941
- const Space$1 = 9;
942
- const PageUp$1 = 10;
943
- const PageDown$1 = 11;
944
- const End$1 = 255;
945
- const Home$1 = 12;
946
- const LeftArrow$1 = 13;
947
- const UpArrow$1 = 14;
948
- const RightArrow$1 = 15;
949
- const DownArrow$1 = 16;
950
- const Insert$1 = 17;
951
- const Delete$1 = 18;
952
- const Digit0$1 = 19;
953
- const Digit1$1 = 20;
954
- const Digit2$1 = 21;
955
- const Digit3$1 = 22;
956
- const Digit4$1 = 23;
957
- const Digit5$1 = 24;
958
- const Digit6$1 = 25;
959
- const Digit7$1 = 26;
960
- const Digit8$1 = 27;
961
- const Digit9$1 = 28;
962
- const KeyA$1 = 29;
963
- const KeyB$1 = 30;
964
- const KeyC$1 = 31;
965
- const KeyD$1 = 32;
966
- const KeyE$1 = 33;
967
- const KeyF$1 = 34;
968
- const KeyG$1 = 35;
969
- const KeyH$1 = 36;
970
- const KeyI$1 = 37;
971
- const KeyJ$1 = 38;
972
- const KeyK$1 = 39;
973
- const KeyL$1 = 40;
974
- const KeyM$1 = 41;
975
- const KeyN$1 = 42;
976
- const KeyO$1 = 43;
977
- const KeyP$1 = 44;
978
- const KeyQ$1 = 45;
979
- const KeyR$1 = 46;
980
- const KeyS$1 = 47;
981
- const KeyT$1 = 48;
982
- const KeyU$1 = 49;
983
- const KeyV$1 = 50;
984
- const KeyW$1 = 51;
985
- const KeyX$1 = 52;
986
- const KeyY$1 = 53;
987
- const KeyZ$1 = 54;
988
- const F1$1 = 57;
989
- const F2$1 = 58;
990
- const F3$1 = 59;
991
- const F4$1 = 60;
992
- const F5$1 = 61;
993
- const F6$1 = 62;
994
- const Equal$1 = 84;
995
- const Comma$1 = 85;
996
- const Minus$1 = 86;
997
- const Backquote$1 = 89;
998
- const Backslash$1 = 91;
999
- const Star$1 = 131;
1000
- const Plus$1 = 132;
1051
+ const Button = 1;
1052
+ const Div = 4;
1053
+ const Span = 8;
1054
+ const Text = 12;
1055
+ const I = 16;
1056
+ const Img = 17;
1057
+
1058
+ const Escape$2 = 8;
1059
+ const Space$2 = 9;
1060
+ const End$2 = 255;
1061
+ const Home$2 = 12;
1062
+ const LeftArrow$2 = 13;
1063
+ const UpArrow$2 = 14;
1064
+ const RightArrow$2 = 15;
1065
+ const DownArrow$2 = 16;
1066
+
1067
+ const CtrlCmd = 1 << 11 >>> 0;
1068
+ const Shift = 1 << 10 >>> 0;
1069
+
1070
+ const DebugWorker = 55;
1071
+ const RendererWorker$1 = 1;
1072
+
1073
+ const mergeClassNames = (...classNames) => {
1074
+ return classNames.filter(Boolean).join(' ');
1075
+ };
1076
+
1077
+ const px = value => {
1078
+ return `${value}px`;
1079
+ };
1080
+
1081
+ const text = data => {
1082
+ return {
1083
+ type: Text,
1084
+ text: data,
1085
+ childCount: 0
1086
+ };
1087
+ };
1001
1088
 
1002
1089
  const FocusTitleBarMenuBar = 26;
1003
1090
 
1004
- const getKeyBindings = () => {
1091
+ const getKeyBindings$1 = () => {
1005
1092
  return [{
1006
- key: DownArrow$1,
1093
+ key: DownArrow$2,
1007
1094
  command: 'TitleBarMenuBar.handleKeyArrowDown',
1008
1095
  when: FocusTitleBarMenuBar
1009
1096
  }, {
1010
- key: UpArrow$1,
1097
+ key: UpArrow$2,
1011
1098
  command: 'TitleBarMenuBar.handleKeyArrowUp',
1012
1099
  when: FocusTitleBarMenuBar
1013
1100
  }, {
1014
- key: RightArrow$1,
1101
+ key: RightArrow$2,
1015
1102
  command: 'TitleBarMenuBar.handleKeyArrowRight',
1016
1103
  when: FocusTitleBarMenuBar
1017
1104
  }, {
1018
- key: LeftArrow$1,
1105
+ key: LeftArrow$2,
1019
1106
  command: 'TitleBarMenuBar.handleKeyArrowLeft',
1020
1107
  when: FocusTitleBarMenuBar
1021
1108
  }, {
1022
- key: Space$1,
1109
+ key: Space$2,
1023
1110
  command: 'TitleBarMenuBar.handleKeySpace',
1024
1111
  when: FocusTitleBarMenuBar
1025
1112
  }, {
1026
- key: Home$1,
1113
+ key: Home$2,
1027
1114
  command: 'TitleBarMenuBar.handleKeyHome',
1028
1115
  when: FocusTitleBarMenuBar
1029
1116
  }, {
1030
- key: End$1,
1117
+ key: End$2,
1031
1118
  command: 'TitleBarMenuBar.handleKeyEnd',
1032
1119
  when: FocusTitleBarMenuBar
1033
1120
  }, {
1034
- key: Escape$1,
1121
+ key: Escape$2,
1035
1122
  command: 'TitleBarMenuBar.handleKeyEscape',
1036
1123
  when: FocusTitleBarMenuBar
1037
1124
  }];
@@ -1103,7 +1190,7 @@ const moveLineDown = () => {
1103
1190
  };
1104
1191
 
1105
1192
  const Edit$1 = 2;
1106
- const File$1 = 5;
1193
+ const File$2 = 5;
1107
1194
  const Go$1 = 6;
1108
1195
  const Help$1 = 7;
1109
1196
  const OpenRecent = 9;
@@ -1217,7 +1304,7 @@ const Web = 1;
1217
1304
  const Electron = 2;
1218
1305
  const Remote = 3;
1219
1306
 
1220
- const id$8 = File$1;
1307
+ const id$8 = File$2;
1221
1308
  const getMenuEntries$c = platform => {
1222
1309
  const entries = [{
1223
1310
  id: 'newFile',
@@ -1288,7 +1375,7 @@ const CheckForUpdates = 'Check For Updates';
1288
1375
  const ClearRecentlyOpened = 'Clear Recently Opened';
1289
1376
  const Close = 'Close';
1290
1377
  const Edit = 'Edit';
1291
- const File = 'File';
1378
+ const File$1 = 'File';
1292
1379
  const Go = 'Go';
1293
1380
  const Help = 'Help';
1294
1381
  const Maximize = 'Maximize';
@@ -1365,25 +1452,390 @@ const MenuEntriesHelp = {
1365
1452
  };
1366
1453
 
1367
1454
  const rpcs = Object.create(null);
1368
- const set$3 = (id, rpc) => {
1455
+ const set$2 = (id, rpc) => {
1369
1456
  rpcs[id] = rpc;
1370
1457
  };
1371
1458
  const get = id => {
1372
1459
  return rpcs[id];
1373
1460
  };
1374
- const RendererWorker$1 = 1;
1375
- const invoke$2 = (method, ...params) => {
1376
- const rpc = get(RendererWorker$1);
1461
+
1462
+ const create$1 = rpcId => {
1463
+ return {
1464
+ // @ts-ignore
1465
+ invoke(method, ...params) {
1466
+ const rpc = get(rpcId);
1467
+ // @ts-ignore
1468
+ return rpc.invoke(method, ...params);
1469
+ },
1470
+ // @ts-ignore
1471
+ invokeAndTransfer(method, ...params) {
1472
+ const rpc = get(rpcId);
1473
+ // @ts-ignore
1474
+ return rpc.invokeAndTransfer(method, ...params);
1475
+ },
1476
+ set(rpc) {
1477
+ set$2(rpcId, rpc);
1478
+ },
1479
+ async dispose() {
1480
+ const rpc = get(rpcId);
1481
+ await rpc.dispose();
1482
+ }
1483
+ };
1484
+ };
1485
+
1486
+ const {
1487
+ invoke: invoke$1,
1488
+ invokeAndTransfer,
1489
+ set: set$1,
1490
+ dispose
1491
+ } = create$1(RendererWorker$1);
1492
+ const searchFileHtml = async uri => {
1493
+ return invoke$1('ExtensionHost.searchFileWithHtml', uri);
1494
+ };
1495
+ const getFilePathElectron = async file => {
1496
+ return invoke$1('FileSystemHandle.getFilePathElectron', file);
1497
+ };
1498
+ const showContextMenu = async (x, y, id, ...args) => {
1499
+ return invoke$1('ContextMenu.show', x, y, id, ...args);
1500
+ };
1501
+ const getElectronVersion = async () => {
1502
+ return invoke$1('Process.getElectronVersion');
1503
+ };
1504
+ const applyBulkReplacement = async bulkEdits => {
1505
+ await invoke$1('BulkReplacement.applyBulkReplacement', bulkEdits);
1506
+ };
1507
+ const setColorTheme = async id => {
1508
+ // @ts-ignore
1509
+ return invoke$1(/* ColorTheme.setColorTheme */'ColorTheme.setColorTheme', /* colorThemeId */id);
1510
+ };
1511
+ const getNodeVersion = async () => {
1512
+ return invoke$1('Process.getNodeVersion');
1513
+ };
1514
+ const getChromeVersion = async () => {
1515
+ return invoke$1('Process.getChromeVersion');
1516
+ };
1517
+ const getV8Version = async () => {
1518
+ return invoke$1('Process.getV8Version');
1519
+ };
1520
+ const getFileHandles = async fileIds => {
1521
+ const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
1522
+ return files;
1523
+ };
1524
+ const setWorkspacePath = async path => {
1525
+ await invoke$1('Workspace.setPath', path);
1526
+ };
1527
+ const registerWebViewInterceptor = async (id, port) => {
1528
+ await invokeAndTransfer('WebView.registerInterceptor', id, port);
1529
+ };
1530
+ const unregisterWebViewInterceptor = async id => {
1531
+ await invoke$1('WebView.unregisterInterceptor', id);
1532
+ };
1533
+ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1534
+ const command = 'HandleMessagePort.handleMessagePort';
1535
+ // @ts-ignore
1536
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1537
+ };
1538
+ const sendMessagePortToErrorWorker = async (port, rpcId) => {
1539
+ const command = 'Errors.handleMessagePort';
1540
+ // @ts-ignore
1541
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1542
+ };
1543
+ const sendMessagePortToMarkdownWorker = async (port, rpcId) => {
1544
+ const command = 'Markdown.handleMessagePort';
1545
+ // @ts-ignore
1546
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToMarkdownWorker', port, command, rpcId);
1547
+ };
1548
+ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1549
+ const command = 'IconTheme.handleMessagePort';
1550
+ // @ts-ignore
1551
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
1552
+ };
1553
+ const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1554
+ const command = 'FileSystem.handleMessagePort';
1377
1555
  // @ts-ignore
1378
- return rpc.invoke(method, ...params);
1556
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1379
1557
  };
1380
- const set$2 = rpc => {
1381
- set$3(RendererWorker$1, rpc);
1558
+ const readFile = async uri => {
1559
+ return invoke$1('FileSystem.readFile', uri);
1382
1560
  };
1561
+ const getWebViewSecret = async key => {
1562
+ // @ts-ignore
1563
+ return invoke$1('WebView.getSecret', key);
1564
+ };
1565
+ const setWebViewPort = async (uid, port, origin, portType) => {
1566
+ return invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
1567
+ };
1568
+ const setFocus$1 = key => {
1569
+ return invoke$1('Focus.setFocus', key);
1570
+ };
1571
+ const getFileIcon = async options => {
1572
+ return invoke$1('IconTheme.getFileIcon', options);
1573
+ };
1574
+ const getColorThemeNames = async () => {
1575
+ return invoke$1('ColorTheme.getColorThemeNames');
1576
+ };
1577
+ const disableExtension = async id => {
1578
+ // @ts-ignore
1579
+ return invoke$1('ExtensionManagement.disable', id);
1580
+ };
1581
+ const enableExtension = async id => {
1582
+ // @ts-ignore
1583
+ return invoke$1('ExtensionManagement.enable', id);
1584
+ };
1585
+ const handleDebugChange = async params => {
1586
+ // @ts-ignore
1587
+ return invoke$1('Run And Debug.handleChange', params);
1588
+ };
1589
+ const getFolderIcon = async options => {
1590
+ return invoke$1('IconTheme.getFolderIcon', options);
1591
+ };
1592
+ const closeWidget = async widgetId => {
1593
+ return invoke$1('Viewlet.closeWidget', widgetId);
1594
+ };
1595
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1596
+ const command = 'HandleMessagePort.handleMessagePort2';
1597
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1598
+ };
1599
+ const sendMessagePortToSearchProcess = async port => {
1600
+ await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
1601
+ };
1602
+ const confirm = async (message, options) => {
1603
+ // @ts-ignore
1604
+ const result = await invoke$1('ConfirmPrompt.prompt', message, options);
1605
+ return result;
1606
+ };
1607
+ const getRecentlyOpened$1 = async () => {
1608
+ return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1609
+ };
1610
+ const getKeyBindings = async () => {
1611
+ return invoke$1('KeyBindingsInitial.getKeyBindings');
1612
+ };
1613
+ const writeClipBoardText = async text => {
1614
+ await invoke$1('ClipBoard.writeText', /* text */text);
1615
+ };
1616
+ const writeClipBoardImage = async blob => {
1617
+ // @ts-ignore
1618
+ await invoke$1('ClipBoard.writeImage', /* text */blob);
1619
+ };
1620
+ const searchFileMemory = async uri => {
1621
+ // @ts-ignore
1622
+ return invoke$1('ExtensionHost.searchFileWithMemory', uri);
1623
+ };
1624
+ const searchFileFetch = async uri => {
1625
+ return invoke$1('ExtensionHost.searchFileWithFetch', uri);
1626
+ };
1627
+ const showMessageBox = async options => {
1628
+ return invoke$1('ElectronDialog.showMessageBox', options);
1629
+ };
1630
+ const handleDebugResumed = async params => {
1631
+ await invoke$1('Run And Debug.handleResumed', params);
1632
+ };
1633
+ const openWidget = async name => {
1634
+ await invoke$1('Viewlet.openWidget', name);
1635
+ };
1636
+ const getIcons = async requests => {
1637
+ const icons = await invoke$1('IconTheme.getIcons', requests);
1638
+ return icons;
1639
+ };
1640
+ const activateByEvent = event => {
1641
+ return invoke$1('ExtensionHostManagement.activateByEvent', event);
1642
+ };
1643
+ const setAdditionalFocus = focusKey => {
1644
+ // @ts-ignore
1645
+ return invoke$1('Focus.setAdditionalFocus', focusKey);
1646
+ };
1647
+ const getActiveEditorId = () => {
1648
+ // @ts-ignore
1649
+ return invoke$1('GetActiveEditor.getActiveEditorId');
1650
+ };
1651
+ const getWorkspacePath = () => {
1652
+ return invoke$1('Workspace.getPath');
1653
+ };
1654
+ const sendMessagePortToRendererProcess = async port => {
1655
+ const command = 'HandleMessagePort.handleMessagePort';
1656
+ // @ts-ignore
1657
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToRendererProcess', port, command, DebugWorker);
1658
+ };
1659
+ const getPreference = async key => {
1660
+ return await invoke$1('Preferences.get', key);
1661
+ };
1662
+ const getAllExtensions = async () => {
1663
+ return invoke$1('ExtensionManagement.getAllExtensions');
1664
+ };
1665
+ const rerenderEditor = async key => {
1666
+ // @ts-ignore
1667
+ return invoke$1('Editor.rerender', key);
1668
+ };
1669
+ const handleDebugPaused = async params => {
1670
+ await invoke$1('Run And Debug.handlePaused', params);
1671
+ };
1672
+ const openUri = async (uri, focus, options) => {
1673
+ await invoke$1('Main.openUri', uri, focus, options);
1674
+ };
1675
+ const sendMessagePortToSyntaxHighlightingWorker = async port => {
1676
+ await invokeAndTransfer(
1677
+ // @ts-ignore
1678
+ 'SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
1679
+ };
1680
+ const handleDebugScriptParsed = async script => {
1681
+ await invoke$1('Run And Debug.handleScriptParsed', script);
1682
+ };
1683
+ const getWindowId = async () => {
1684
+ return invoke$1('GetWindowId.getWindowId');
1685
+ };
1686
+ const getBlob = async uri => {
1687
+ // @ts-ignore
1688
+ return invoke$1('FileSystem.getBlob', uri);
1689
+ };
1690
+ const getExtensionCommands = async () => {
1691
+ return invoke$1('ExtensionHost.getCommands');
1692
+ };
1693
+ const showErrorDialog = async errorInfo => {
1694
+ // @ts-ignore
1695
+ await invoke$1('ErrorHandling.showErrorDialog', errorInfo);
1696
+ };
1697
+ const getFolderSize = async uri => {
1698
+ // @ts-ignore
1699
+ return await invoke$1('FileSystem.getFolderSize', uri);
1700
+ };
1701
+ const getExtension = async id => {
1702
+ // @ts-ignore
1703
+ return invoke$1('ExtensionManagement.getExtension', id);
1704
+ };
1705
+ const getMarkdownDom = async html => {
1706
+ // @ts-ignore
1707
+ return invoke$1('Markdown.getVirtualDom', html);
1708
+ };
1709
+ const renderMarkdown = async (markdown, options) => {
1710
+ // @ts-ignore
1711
+ return invoke$1('Markdown.renderMarkdown', markdown, options);
1712
+ };
1713
+ const openNativeFolder = async uri => {
1714
+ // @ts-ignore
1715
+ await invoke$1('OpenNativeFolder.openNativeFolder', uri);
1716
+ };
1717
+ const uninstallExtension = async id => {
1718
+ return invoke$1('ExtensionManagement.uninstall', id);
1719
+ };
1720
+ const installExtension = async id => {
1721
+ // @ts-ignore
1722
+ return invoke$1('ExtensionManagement.install', id);
1723
+ };
1724
+ const openExtensionSearch = async () => {
1725
+ // @ts-ignore
1726
+ return invoke$1('SideBar.openViewlet', 'Extensions');
1727
+ };
1728
+ const setExtensionsSearchValue = async searchValue => {
1729
+ // @ts-ignore
1730
+ return invoke$1('Extensions.handleInput', searchValue);
1731
+ };
1732
+ const openExternal = async uri => {
1733
+ // @ts-ignore
1734
+ await invoke$1('Open.openExternal', uri);
1735
+ };
1736
+ const openUrl = async uri => {
1737
+ // @ts-ignore
1738
+ await invoke$1('Open.openUrl', uri);
1739
+ };
1740
+ const getAllPreferences = async () => {
1741
+ // @ts-ignore
1742
+ return invoke$1('Preferences.getAll');
1743
+ };
1744
+ const showSaveFilePicker = async () => {
1745
+ // @ts-ignore
1746
+ return invoke$1('FilePicker.showSaveFilePicker');
1747
+ };
1748
+ const getLogsDir = async () => {
1749
+ // @ts-ignore
1750
+ return invoke$1('PlatformPaths.getLogsDir');
1751
+ };
1752
+ const registerMockRpc = commandMap => {
1753
+ const mockRpc = createMockRpc({
1754
+ commandMap
1755
+ });
1756
+ set$1(mockRpc);
1757
+ return mockRpc;
1758
+ };
1759
+
1383
1760
  const RendererWorker = {
1384
1761
  __proto__: null,
1385
- invoke: invoke$2,
1386
- set: set$2
1762
+ activateByEvent,
1763
+ applyBulkReplacement,
1764
+ closeWidget,
1765
+ confirm,
1766
+ disableExtension,
1767
+ dispose,
1768
+ enableExtension,
1769
+ getActiveEditorId,
1770
+ getAllExtensions,
1771
+ getAllPreferences,
1772
+ getBlob,
1773
+ getChromeVersion,
1774
+ getColorThemeNames,
1775
+ getElectronVersion,
1776
+ getExtension,
1777
+ getExtensionCommands,
1778
+ getFileHandles,
1779
+ getFileIcon,
1780
+ getFilePathElectron,
1781
+ getFolderIcon,
1782
+ getFolderSize,
1783
+ getIcons,
1784
+ getKeyBindings,
1785
+ getLogsDir,
1786
+ getMarkdownDom,
1787
+ getNodeVersion,
1788
+ getPreference,
1789
+ getRecentlyOpened: getRecentlyOpened$1,
1790
+ getV8Version,
1791
+ getWebViewSecret,
1792
+ getWindowId,
1793
+ getWorkspacePath,
1794
+ handleDebugChange,
1795
+ handleDebugPaused,
1796
+ handleDebugResumed,
1797
+ handleDebugScriptParsed,
1798
+ installExtension,
1799
+ invoke: invoke$1,
1800
+ invokeAndTransfer,
1801
+ openExtensionSearch,
1802
+ openExternal,
1803
+ openNativeFolder,
1804
+ openUri,
1805
+ openUrl,
1806
+ openWidget,
1807
+ readFile,
1808
+ registerMockRpc,
1809
+ registerWebViewInterceptor,
1810
+ renderMarkdown,
1811
+ rerenderEditor,
1812
+ searchFileFetch,
1813
+ searchFileHtml,
1814
+ searchFileMemory,
1815
+ sendMessagePortToEditorWorker,
1816
+ sendMessagePortToErrorWorker,
1817
+ sendMessagePortToExtensionHostWorker,
1818
+ sendMessagePortToFileSystemWorker,
1819
+ sendMessagePortToIconThemeWorker,
1820
+ sendMessagePortToMarkdownWorker,
1821
+ sendMessagePortToRendererProcess,
1822
+ sendMessagePortToSearchProcess,
1823
+ sendMessagePortToSyntaxHighlightingWorker,
1824
+ set: set$1,
1825
+ setAdditionalFocus,
1826
+ setColorTheme,
1827
+ setExtensionsSearchValue,
1828
+ setFocus: setFocus$1,
1829
+ setWebViewPort,
1830
+ setWorkspacePath,
1831
+ showContextMenu,
1832
+ showErrorDialog,
1833
+ showMessageBox,
1834
+ showSaveFilePicker,
1835
+ uninstallExtension,
1836
+ unregisterWebViewInterceptor,
1837
+ writeClipBoardImage,
1838
+ writeClipBoardText
1387
1839
  };
1388
1840
 
1389
1841
  const {
@@ -1395,10 +1847,15 @@ const getRecentlyOpened = () => {
1395
1847
  return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1396
1848
  };
1397
1849
 
1398
- const getTitle = uri => {
1850
+ const File = 'file://';
1851
+
1852
+ const getTitle = (homeDir, uri) => {
1399
1853
  if (!uri) {
1400
1854
  return '';
1401
1855
  }
1856
+ if (uri.startsWith(File)) {
1857
+ return uri.slice(File.length);
1858
+ }
1402
1859
  return uri;
1403
1860
  };
1404
1861
 
@@ -1409,9 +1866,14 @@ const clearRecentlyOpened = () => {
1409
1866
  return i18nString(ClearRecentlyOpened);
1410
1867
  };
1411
1868
 
1869
+ const getHomeDir = () => {
1870
+ return '';
1871
+ };
1872
+
1412
1873
  const MAX_MENU_RECENT_ENTRIES = 10;
1413
1874
  const toMenuItem = folder => {
1414
- const label = getTitle(folder);
1875
+ const homeDir = getHomeDir();
1876
+ const label = getTitle(homeDir, folder);
1415
1877
  return {
1416
1878
  label,
1417
1879
  flags: None$1,
@@ -1522,7 +1984,7 @@ const MenuEntriesTerminal = {
1522
1984
  };
1523
1985
 
1524
1986
  const file = () => {
1525
- return i18nString(File);
1987
+ return i18nString(File$1);
1526
1988
  };
1527
1989
  const edit = () => {
1528
1990
  return i18nString(Edit);
@@ -1557,7 +2019,7 @@ const close$1 = () => {
1557
2019
 
1558
2020
  const getMenuEntries$5 = () => {
1559
2021
  return [{
1560
- id: File$1,
2022
+ id: File$2,
1561
2023
  label: file(),
1562
2024
  flags: SubMenu
1563
2025
  }, {
@@ -1596,7 +2058,7 @@ const getMenuEntries$5 = () => {
1596
2058
 
1597
2059
  const getMenuEntries$4 = () => {
1598
2060
  return [{
1599
- id: File$1,
2061
+ id: File$2,
1600
2062
  label: file(),
1601
2063
  flags: None$1
1602
2064
  }, {
@@ -1737,12 +2199,6 @@ const MenuItemCheckBox = 'menuitemcheckbox';
1737
2199
  const None = 'none';
1738
2200
  const Separator = 'separator';
1739
2201
 
1740
- const Button = 1;
1741
- const Div = 4;
1742
- const I = 16;
1743
- const Img = 17;
1744
- const Span = 8;
1745
-
1746
2202
  const getIconVirtualDom = (icon, type = Div) => {
1747
2203
  return {
1748
2204
  type,
@@ -1769,18 +2225,6 @@ const createTitleBarButton = button => {
1769
2225
  return dom;
1770
2226
  };
1771
2227
 
1772
- const mergeClassNames = (...classNames) => {
1773
- return classNames.filter(Boolean).join(' ');
1774
- };
1775
- const Text = 12;
1776
- const text = data => {
1777
- return {
1778
- type: Text,
1779
- text: data,
1780
- childCount: 0
1781
- };
1782
- };
1783
-
1784
2228
  const getTitleBarButtonsVirtualDom = buttons => {
1785
2229
  const dom = [{
1786
2230
  type: Div,
@@ -1790,12 +2234,13 @@ const getTitleBarButtonsVirtualDom = buttons => {
1790
2234
  return dom;
1791
2235
  };
1792
2236
 
2237
+ const parentNode = {
2238
+ type: Div,
2239
+ className: mergeClassNames(Viewlet, TitleBarIcon),
2240
+ childCount: 1
2241
+ };
1793
2242
  const getTitleBarIconVirtualDom = iconSrc => {
1794
- return [{
1795
- type: Div,
1796
- className: mergeClassNames(Viewlet, TitleBarIcon),
1797
- childCount: 1
1798
- }, {
2243
+ return [parentNode, {
1799
2244
  type: Img,
1800
2245
  className: TitleBarIconIcon,
1801
2246
  src: iconSrc,
@@ -1804,16 +2249,16 @@ const getTitleBarIconVirtualDom = iconSrc => {
1804
2249
  }];
1805
2250
  };
1806
2251
 
1807
- const HandleClick = 'handleClick';
1808
- const HandleClickMinimize = 'handleClickMinimize';
1809
- const HandleClickToggleClose = 'handleClickToggleClose';
1810
- const HandleClickToggleMaximize = 'handleClickToggleMaximize';
1811
- const HandleFocusIn = 'handleFocusIn';
1812
- const HandleFocusOut = 'handleFocusOut';
1813
- const HandlePointerOut = 'handlePointerOut';
1814
- const HandlePointerOver = 'handlePointerOver';
1815
- const HandleMenuClick = 'handleMenuClick';
1816
- const HandleMenuMouseOver = 'handleMenuMouseOver';
2252
+ const HandleClick = 1;
2253
+ const HandleClickMinimize = 2;
2254
+ const HandleClickToggleClose = 3;
2255
+ const HandleClickToggleMaximize = 4;
2256
+ const HandleFocusIn = 5;
2257
+ const HandleFocusOut = 6;
2258
+ const HandlePointerOut = 7;
2259
+ const HandlePointerOver = 8;
2260
+ const HandleMenuClick = 9;
2261
+ const HandleMenuMouseOver = 10;
1817
2262
 
1818
2263
  const getItemVirtualDom = item => {
1819
2264
  // @ts-ignore
@@ -1823,6 +2268,7 @@ const getItemVirtualDom = item => {
1823
2268
  isOpen,
1824
2269
  isFocused
1825
2270
  } = item;
2271
+ // TODO avoid mutation
1826
2272
  const dom = [];
1827
2273
  dom.push({
1828
2274
  type: Div,
@@ -1902,7 +2348,8 @@ const handleClickToggleMaximize = async state => {
1902
2348
  return state;
1903
2349
  };
1904
2350
 
1905
- const handleClick$1 = (state, className) => {
2351
+ // TODO use button name property
2352
+ const handleClick$1 = async (state, className) => {
1906
2353
  if (className.includes('Minimize')) {
1907
2354
  return handleClickMinimize(state);
1908
2355
  }
@@ -2137,7 +2584,7 @@ const handlePointerOut = (state, clientX, clientY) => {
2137
2584
  if (index === -1) {
2138
2585
  return state;
2139
2586
  }
2140
- return handleMouseOut(state, index);
2587
+ return handleMouseOut(state);
2141
2588
  };
2142
2589
 
2143
2590
  const handleMouseOverMenuClosed = (state, index) => {
@@ -2161,74 +2608,46 @@ const handlePointerOver = (state, clientX, clientY) => {
2161
2608
  return handleMouseOver(state, index);
2162
2609
  };
2163
2610
 
2164
- const getFontString = (fontWeight, fontSize, fontFamily) => {
2165
- return `${fontWeight} ${fontSize}px ${fontFamily}`;
2166
- };
2167
-
2168
- const createTextMeasureContext = () => {
2611
+ const createTextMeasureContext = (letterSpacing, font) => {
2169
2612
  const canvas = new OffscreenCanvas(0, 0);
2170
2613
  const ctx = canvas.getContext('2d');
2171
2614
  if (!ctx) {
2172
2615
  throw new Error('Failed to get canvas context 2d');
2173
2616
  }
2617
+ ctx.letterSpacing = letterSpacing;
2618
+ ctx.font = font;
2174
2619
  return ctx;
2175
2620
  };
2176
2621
 
2177
- const state = {
2178
- ctx: undefined
2179
- };
2180
- const getOrCreate = createCtx => {
2181
- if (state.ctx) {
2182
- return state.ctx;
2183
- }
2184
- state.ctx = createCtx();
2185
- return state.ctx;
2186
- };
2187
-
2188
- const getContext = () => {
2189
- const ctx = getOrCreate(createTextMeasureContext);
2190
- return ctx;
2191
- };
2192
-
2193
- const px = value => {
2194
- return `${value}px`;
2622
+ const getFontString = (fontWeight, fontSize, fontFamily) => {
2623
+ return `${fontWeight} ${fontSize}px ${fontFamily}`;
2195
2624
  };
2196
2625
 
2197
- const getLetterSpacingString = letterSpacing => {
2198
- return px(letterSpacing);
2199
- };
2200
- const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing, isMonoSpaceFont, charWidth) => {
2201
- string(text);
2202
- number(fontWeight);
2203
- number(fontSize);
2204
- string(fontFamily);
2205
- boolean(isMonoSpaceFont);
2206
- number(charWidth);
2626
+ const measureTextWidths = (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
2207
2627
  if (typeof letterSpacing !== 'number') {
2208
2628
  throw new TypeError('letterSpacing must be of type number');
2209
2629
  }
2210
- const letterSpacingString = getLetterSpacingString(letterSpacing);
2630
+ const letterSpacingString = px(letterSpacing);
2211
2631
  const fontString = getFontString(fontWeight, fontSize, fontFamily);
2212
- const ctx = getContext();
2213
- ctx.letterSpacing = letterSpacingString;
2214
- ctx.font = fontString;
2215
- const metrics = ctx.measureText(text);
2216
- const {
2217
- width
2218
- } = metrics;
2219
- return width;
2220
- };
2221
-
2222
- const measureTitleBarEntryWidth = (label, fontWeight, fontSize, fontFamily, letterSpacing) => {
2223
- const isMonospaceFont = false;
2224
- const charWidth = 0;
2225
- return measureTextWidth(label, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
2632
+ const ctx = createTextMeasureContext(letterSpacingString, fontString);
2633
+ const widths = [];
2634
+ for (const text of texts) {
2635
+ const metrics = ctx.measureText(text);
2636
+ const {
2637
+ width
2638
+ } = metrics;
2639
+ widths.push(width);
2640
+ }
2641
+ return widths;
2226
2642
  };
2227
2643
 
2228
2644
  const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
2645
+ const labels = entries.map(entry => entry.label);
2646
+ const widths = measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
2229
2647
  const withWidths = [];
2230
- for (const entry of entries) {
2231
- const textWidth = measureTitleBarEntryWidth(entry.label, fontWeight, fontSize, fontFamily, letterSpacing);
2648
+ for (let i = 0; i < entries.length; i++) {
2649
+ const entry = entries[i];
2650
+ const textWidth = widths[i];
2232
2651
  const width = textWidth + labelPadding * 2;
2233
2652
  withWidths.push({
2234
2653
  ...entry,
@@ -2337,6 +2756,71 @@ const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
2337
2756
  return string;
2338
2757
  };
2339
2758
 
2759
+ const Backspace$1 = 1;
2760
+ const Tab$1 = 2;
2761
+ const Enter$1 = 3;
2762
+ const Escape$1 = 8;
2763
+ const Space$1 = 9;
2764
+ const PageUp$1 = 10;
2765
+ const PageDown$1 = 11;
2766
+ const End$1 = 255;
2767
+ const Home$1 = 12;
2768
+ const LeftArrow$1 = 13;
2769
+ const UpArrow$1 = 14;
2770
+ const RightArrow$1 = 15;
2771
+ const DownArrow$1 = 16;
2772
+ const Insert$1 = 17;
2773
+ const Delete$1 = 18;
2774
+ const Digit0$1 = 19;
2775
+ const Digit1$1 = 20;
2776
+ const Digit2$1 = 21;
2777
+ const Digit3$1 = 22;
2778
+ const Digit4$1 = 23;
2779
+ const Digit5$1 = 24;
2780
+ const Digit6$1 = 25;
2781
+ const Digit7$1 = 26;
2782
+ const Digit8$1 = 27;
2783
+ const Digit9$1 = 28;
2784
+ const KeyA$1 = 29;
2785
+ const KeyB$1 = 30;
2786
+ const KeyC$1 = 31;
2787
+ const KeyD$1 = 32;
2788
+ const KeyE$1 = 33;
2789
+ const KeyF$1 = 34;
2790
+ const KeyG$1 = 35;
2791
+ const KeyH$1 = 36;
2792
+ const KeyI$1 = 37;
2793
+ const KeyJ$1 = 38;
2794
+ const KeyK$1 = 39;
2795
+ const KeyL$1 = 40;
2796
+ const KeyM$1 = 41;
2797
+ const KeyN$1 = 42;
2798
+ const KeyO$1 = 43;
2799
+ const KeyP$1 = 44;
2800
+ const KeyQ$1 = 45;
2801
+ const KeyR$1 = 46;
2802
+ const KeyS$1 = 47;
2803
+ const KeyT$1 = 48;
2804
+ const KeyU$1 = 49;
2805
+ const KeyV$1 = 50;
2806
+ const KeyW$1 = 51;
2807
+ const KeyX$1 = 52;
2808
+ const KeyY$1 = 53;
2809
+ const KeyZ$1 = 54;
2810
+ const F1$1 = 57;
2811
+ const F2$1 = 58;
2812
+ const F3$1 = 59;
2813
+ const F4$1 = 60;
2814
+ const F5$1 = 61;
2815
+ const F6$1 = 62;
2816
+ const Equal$1 = 84;
2817
+ const Comma$1 = 85;
2818
+ const Minus$1 = 86;
2819
+ const Backquote$1 = 89;
2820
+ const Backslash$1 = 91;
2821
+ const Star$1 = 131;
2822
+ const Plus$1 = 132;
2823
+
2340
2824
  const Unknown = 'Unknown';
2341
2825
  const Backspace = 'Backspace';
2342
2826
  const Tab = 'Tab';
@@ -2538,9 +3022,6 @@ const getKeyCodeString = keyCode => {
2538
3022
  }
2539
3023
  };
2540
3024
 
2541
- const CtrlCmd = 1 << 11 >>> 0;
2542
- const Shift = 1 << 10 >>> 0;
2543
-
2544
3025
  const parseKey = rawKey => {
2545
3026
  number(rawKey);
2546
3027
  const isCtrl = Boolean(rawKey & CtrlCmd);
@@ -2554,16 +3035,20 @@ const parseKey = rawKey => {
2554
3035
  };
2555
3036
  };
2556
3037
 
3038
+ const classNameFocused = mergeClassNames(MenuItem$1, MenuItemFocused);
3039
+ const getMenuItemClassName = isFocused => {
3040
+ if (isFocused) {
3041
+ return classNameFocused;
3042
+ }
3043
+ return MenuItem$1;
3044
+ };
2557
3045
  const getMenuItemDefaultDom = menuItem => {
2558
3046
  const {
2559
3047
  label,
2560
3048
  isFocused,
2561
3049
  key
2562
3050
  } = menuItem;
2563
- let className = MenuItem$1;
2564
- if (isFocused) {
2565
- className += ' ' + MenuItemFocused;
2566
- }
3051
+ const className = getMenuItemClassName(isFocused);
2567
3052
  const dom = [];
2568
3053
  dom.push({
2569
3054
  type: Div,
@@ -2783,7 +3268,7 @@ const render2 = async (uid, diffResult) => {
2783
3268
  oldState,
2784
3269
  newState
2785
3270
  } = get$1(uid);
2786
- set$1(uid, newState, newState);
3271
+ set$3(uid, newState, newState);
2787
3272
  const commands = applyRender(oldState, newState, diffResult);
2788
3273
  return commands;
2789
3274
  };
@@ -2828,10 +3313,6 @@ const saveState = uid => {
2828
3313
  };
2829
3314
  };
2830
3315
 
2831
- const terminate = () => {
2832
- globalThis.close();
2833
- };
2834
-
2835
3316
  const create = (id, uri, x, y, width, height) => {
2836
3317
  const state = {
2837
3318
  uid: id,
@@ -2848,9 +3329,10 @@ const create = (id, uri, x, y, width, height) => {
2848
3329
  x,
2849
3330
  y,
2850
3331
  width,
2851
- height
3332
+ height,
3333
+ iconWidth: 30
2852
3334
  };
2853
- set$1(id, state, state);
3335
+ set$3(id, state, state);
2854
3336
  return state;
2855
3337
  };
2856
3338
 
@@ -2965,10 +3447,7 @@ const handleFocusOut = async state => {
2965
3447
  return state;
2966
3448
  };
2967
3449
 
2968
- /**
2969
- * @param {boolean} focus
2970
- */
2971
- const openMenu = (state, focus) => {
3450
+ const openMenu = async (state, focus) => {
2972
3451
  const {
2973
3452
  focusedIndex
2974
3453
  } = state;
@@ -3326,7 +3805,7 @@ const handleMenuMouseOver = async (state, level, index) => {
3326
3805
  };
3327
3806
  };
3328
3807
 
3329
- const toggleMenu = state => {
3808
+ const toggleMenu = async state => {
3330
3809
  const {
3331
3810
  isMenuOpen
3332
3811
  } = state;
@@ -3336,21 +3815,6 @@ const toggleMenu = state => {
3336
3815
  return openMenu(state, /* focus */false);
3337
3816
  };
3338
3817
 
3339
- const wrapCommand = fn => {
3340
- const wrapped = async (uid, ...args) => {
3341
- const {
3342
- newState
3343
- } = get$1(uid);
3344
- const newerState = await fn(newState, ...args);
3345
- if (newState === newerState) {
3346
- return;
3347
- }
3348
- const latest = get$1(uid);
3349
- set$1(uid, latest.oldState, newerState);
3350
- };
3351
- return wrapped;
3352
- };
3353
-
3354
3818
  const commandMap = {
3355
3819
  'TitleBar.getButtonsVirtualDom': getTitleBarButtonsVirtualDom,
3356
3820
  'TitleBar.getIconVirtualDom': getTitleBarIconVirtualDom,
@@ -3370,11 +3834,11 @@ const commandMap = {
3370
3834
  'TitleBarMenuBar.focusNext': wrapCommand(focusNext),
3371
3835
  'TitleBarMenuBar.focusPrevious': wrapCommand(focusPrevious),
3372
3836
  'TitleBarMenuBar.getCommands': getCommandIds,
3373
- 'TitleBarMenuBar.getKeyBindings': getKeyBindings,
3837
+ 'TitleBarMenuBar.getKeyBindings': getKeyBindings$1,
3374
3838
  'TitleBarMenuBar.getMenus': getMenus,
3839
+ 'TitleBarMenuBar.getTitleBarButtons': getTitleBarButtons,
3375
3840
  'TitleBarMenuBar.getVirtualDom': getTitleBarMenuBarVirtualDom,
3376
3841
  'TitleBarMenuBar.handleClick': wrapCommand(handleClick),
3377
- 'TitleBarMenuBar.getTitleBarButtons': getTitleBarButtons,
3378
3842
  'TitleBarMenuBar.handleClickAt': wrapCommand(handleClickAt),
3379
3843
  'TitleBarMenuBar.handleFocus': wrapCommand(handleFocus),
3380
3844
  'TitleBarMenuBar.handleFocusOut': wrapCommand(handleFocusOut),