@lvce-editor/output-view 2.14.0 → 2.16.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.
@@ -54,6 +54,49 @@ class VError extends Error {
54
54
  }
55
55
  }
56
56
 
57
+ class AssertionError extends Error {
58
+ constructor(message) {
59
+ super(message);
60
+ this.name = 'AssertionError';
61
+ }
62
+ }
63
+ const Object$1 = 1;
64
+ const Number$1 = 2;
65
+ const Array$1 = 3;
66
+ const String$1 = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown = 8;
71
+ const getType = value => {
72
+ switch (typeof value) {
73
+ case 'number':
74
+ return Number$1;
75
+ case 'function':
76
+ return Function;
77
+ case 'string':
78
+ return String$1;
79
+ case 'object':
80
+ if (value === null) {
81
+ return Null;
82
+ }
83
+ if (Array.isArray(value)) {
84
+ return Array$1;
85
+ }
86
+ return Object$1;
87
+ case 'boolean':
88
+ return Boolean$1;
89
+ default:
90
+ return Unknown;
91
+ }
92
+ };
93
+ const number = value => {
94
+ const type = getType(value);
95
+ if (type !== Number$1) {
96
+ throw new AssertionError('expected value to be of type number');
97
+ }
98
+ };
99
+
57
100
  const isMessagePort = value => {
58
101
  return value && value instanceof MessagePort;
59
102
  };
@@ -96,7 +139,6 @@ const walkValue = (value, transferrables, isTransferrable) => {
96
139
  for (const property of Object.values(value)) {
97
140
  walkValue(property, transferrables, isTransferrable);
98
141
  }
99
- return;
100
142
  }
101
143
  };
102
144
  const getTransferrables = value => {
@@ -250,7 +292,14 @@ class IpcError extends VError {
250
292
  const cause = new Error(message);
251
293
  // @ts-ignore
252
294
  cause.code = code;
253
- cause.stack = stack;
295
+ if (stack) {
296
+ Object.defineProperty(cause, 'stack', {
297
+ configurable: true,
298
+ enumerable: false,
299
+ value: stack,
300
+ writable: true
301
+ });
302
+ }
254
303
  super(cause, betterMessage);
255
304
  } else {
256
305
  super(betterMessage);
@@ -407,7 +456,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
407
456
  return promise;
408
457
  };
409
458
  const Message$1 = 3;
410
- const create$5 = async ({
459
+ const create$5$1 = async ({
411
460
  isMessagePortOpen,
412
461
  messagePort
413
462
  }) => {
@@ -458,11 +507,32 @@ const wrap$5 = messagePort => {
458
507
  };
459
508
  const IpcParentWithMessagePort$1 = {
460
509
  __proto__: null,
461
- create: create$5,
510
+ create: create$5$1,
462
511
  signal: signal$1,
463
512
  wrap: wrap$5
464
513
  };
465
514
 
515
+ class CommandNotFoundError extends Error {
516
+ constructor(command) {
517
+ super(`Command not found ${command}`);
518
+ this.name = 'CommandNotFoundError';
519
+ }
520
+ }
521
+ const commands = Object.create(null);
522
+ const register = commandMap => {
523
+ Object.assign(commands, commandMap);
524
+ };
525
+ const getCommand = key => {
526
+ return commands[key];
527
+ };
528
+ const execute = (command, ...args) => {
529
+ const fn = getCommand(command);
530
+ if (!fn) {
531
+ throw new CommandNotFoundError(command);
532
+ }
533
+ return fn(...args);
534
+ };
535
+
466
536
  const Two$1 = '2.0';
467
537
  const callbacks = Object.create(null);
468
538
  const get$2 = id => {
@@ -487,12 +557,12 @@ const getErrorConstructor = (message, type) => {
487
557
  switch (type) {
488
558
  case DomException:
489
559
  return DOMException;
490
- case TypeError$1:
491
- return TypeError;
492
- case SyntaxError$1:
493
- return SyntaxError;
494
560
  case ReferenceError$1:
495
561
  return ReferenceError;
562
+ case SyntaxError$1:
563
+ return SyntaxError;
564
+ case TypeError$1:
565
+ return TypeError;
496
566
  default:
497
567
  return Error;
498
568
  }
@@ -516,7 +586,10 @@ const constructError = (message, type, name) => {
516
586
  if (ErrorConstructor === Error) {
517
587
  const error = new Error(message);
518
588
  if (name && name !== 'VError') {
519
- error.name = name;
589
+ Object.defineProperty(error, 'name', {
590
+ configurable: true,
591
+ value: name
592
+ });
520
593
  }
521
594
  return error;
522
595
  }
@@ -533,8 +606,10 @@ const getCurrentStack = () => {
533
606
  const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
534
607
  return currentStack;
535
608
  };
536
- const getNewLineIndex = (string, startIndex = undefined) => {
537
- return string.indexOf(NewLine, startIndex);
609
+ const getNewLineIndex = (string, startIndex) => {
610
+ {
611
+ return string.indexOf(NewLine);
612
+ }
538
613
  };
539
614
  const getParentStack = error => {
540
615
  let parentStack = error.stack || error.data || error.message || '';
@@ -545,55 +620,91 @@ const getParentStack = error => {
545
620
  };
546
621
  const MethodNotFound = -32601;
547
622
  const Custom = -32001;
623
+ const setStack = (error, stack) => {
624
+ const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
625
+ if (descriptor) {
626
+ if (!descriptor.configurable && !descriptor.writable) {
627
+ return;
628
+ }
629
+ if (!descriptor.configurable && descriptor.writable) {
630
+ error.stack = stack;
631
+ return;
632
+ }
633
+ }
634
+ Object.defineProperty(error, 'stack', {
635
+ configurable: true,
636
+ value: stack,
637
+ writable: true
638
+ });
639
+ };
640
+ const restoreExistingError = (error, currentStack) => {
641
+ if (typeof error.stack === 'string') {
642
+ setStack(error, `${error.stack}${NewLine}${currentStack}`);
643
+ }
644
+ return error;
645
+ };
646
+ const restoreMethodNotFoundError = (error, currentStack) => {
647
+ const restoredError = new JsonRpcError(error.message);
648
+ const parentStack = getParentStack(error);
649
+ setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
650
+ return restoredError;
651
+ };
652
+ const restoreStackFromData = (restoredError, error, currentStack) => {
653
+ if (error.data.stack && error.data.type && error.message) {
654
+ setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
655
+ return;
656
+ }
657
+ if (error.data.stack) {
658
+ setStack(restoredError, error.data.stack);
659
+ }
660
+ };
661
+ const applyDataProperties = (restoredError, error) => {
662
+ restoreStackFromData(restoredError, error, getCurrentStack());
663
+ if (error.data.codeFrame) {
664
+ // @ts-ignore
665
+ restoredError.codeFrame = error.data.codeFrame;
666
+ }
667
+ if (error.data.code) {
668
+ // @ts-ignore
669
+ restoredError.code = error.data.code;
670
+ }
671
+ if (error.data.type) {
672
+ // @ts-ignore
673
+ restoredError.name = error.data.type;
674
+ }
675
+ };
676
+ const applyDirectProperties = (restoredError, error) => {
677
+ if (error.stack) {
678
+ const lowerStack = restoredError.stack || '';
679
+ const indexNewLine = getNewLineIndex(lowerStack);
680
+ const parentStack = getParentStack(error);
681
+ // @ts-ignore
682
+ setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
683
+ }
684
+ if (error.codeFrame) {
685
+ // @ts-ignore
686
+ restoredError.codeFrame = error.codeFrame;
687
+ }
688
+ };
689
+ const restoreMessageError = (error, _currentStack) => {
690
+ const restoredError = constructError(error.message, error.type, error.name);
691
+ if (error.data) {
692
+ applyDataProperties(restoredError, error);
693
+ } else {
694
+ applyDirectProperties(restoredError, error);
695
+ }
696
+ return restoredError;
697
+ };
548
698
  const restoreJsonRpcError = error => {
549
699
  const currentStack = getCurrentStack();
550
700
  if (error && error instanceof Error) {
551
- if (typeof error.stack === 'string') {
552
- error.stack = error.stack + NewLine + currentStack;
553
- }
554
- return error;
701
+ return restoreExistingError(error, currentStack);
555
702
  }
556
703
  if (error && error.code && error.code === MethodNotFound) {
557
- const restoredError = new JsonRpcError(error.message);
558
- const parentStack = getParentStack(error);
559
- restoredError.stack = parentStack + NewLine + currentStack;
560
- return restoredError;
704
+ return restoreMethodNotFoundError(error, currentStack);
561
705
  }
562
706
  if (error && error.message) {
563
- const restoredError = constructError(error.message, error.type, error.name);
564
- if (error.data) {
565
- if (error.data.stack && error.data.type && error.message) {
566
- restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
567
- } else if (error.data.stack) {
568
- restoredError.stack = error.data.stack;
569
- }
570
- if (error.data.codeFrame) {
571
- // @ts-ignore
572
- restoredError.codeFrame = error.data.codeFrame;
573
- }
574
- if (error.data.code) {
575
- // @ts-ignore
576
- restoredError.code = error.data.code;
577
- }
578
- if (error.data.type) {
579
- // @ts-ignore
580
- restoredError.name = error.data.type;
581
- }
582
- } else {
583
- if (error.stack) {
584
- const lowerStack = restoredError.stack || '';
585
- // @ts-ignore
586
- const indexNewLine = getNewLineIndex(lowerStack);
587
- const parentStack = getParentStack(error);
588
- // @ts-ignore
589
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
590
- }
591
- if (error.codeFrame) {
592
- // @ts-ignore
593
- restoredError.codeFrame = error.codeFrame;
594
- }
595
- }
596
- return restoredError;
707
+ return restoreMessageError(error);
597
708
  }
598
709
  if (typeof error === 'string') {
599
710
  return new Error(`JsonRpc Error: ${error}`);
@@ -648,56 +759,56 @@ const getErrorProperty = (error, prettyError) => {
648
759
  if (error && error.code === E_COMMAND_NOT_FOUND) {
649
760
  return {
650
761
  code: MethodNotFound,
651
- message: error.message,
652
- data: error.stack
762
+ data: error.stack,
763
+ message: error.message
653
764
  };
654
765
  }
655
766
  return {
656
767
  code: Custom,
657
- message: prettyError.message,
658
768
  data: {
659
- stack: getStack(prettyError),
660
- codeFrame: prettyError.codeFrame,
661
- type: getErrorType(prettyError),
662
769
  code: prettyError.code,
663
- name: prettyError.name
664
- }
770
+ codeFrame: prettyError.codeFrame,
771
+ name: prettyError.name,
772
+ stack: getStack(prettyError),
773
+ type: getErrorType(prettyError)
774
+ },
775
+ message: prettyError.message
665
776
  };
666
777
  };
667
- const create$1$2 = (id, error) => {
778
+ const create$1$1 = (id, error) => {
668
779
  return {
669
- jsonrpc: Two$1,
780
+ error,
670
781
  id,
671
- error
782
+ jsonrpc: Two$1
672
783
  };
673
784
  };
674
785
  const getErrorResponse = (id, error, preparePrettyError, logError) => {
675
786
  const prettyError = preparePrettyError(error);
676
787
  logError(error, prettyError);
677
788
  const errorProperty = getErrorProperty(error, prettyError);
678
- return create$1$2(id, errorProperty);
789
+ return create$1$1(id, errorProperty);
679
790
  };
680
- const create$3 = (message, result) => {
791
+ const create$a = (message, result) => {
681
792
  return {
682
- jsonrpc: Two$1,
683
793
  id: message.id,
794
+ jsonrpc: Two$1,
684
795
  result: result ?? null
685
796
  };
686
797
  };
687
798
  const getSuccessResponse = (message, result) => {
688
799
  const resultProperty = result ?? null;
689
- return create$3(message, resultProperty);
800
+ return create$a(message, resultProperty);
690
801
  };
691
802
  const getErrorResponseSimple = (id, error) => {
692
803
  return {
693
- jsonrpc: Two$1,
694
- id,
695
804
  error: {
696
805
  code: Custom,
806
+ data: error,
697
807
  // @ts-ignore
698
- message: error.message,
699
- data: error
700
- }
808
+ message: error.message
809
+ },
810
+ id,
811
+ jsonrpc: Two$1
701
812
  };
702
813
  };
703
814
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
@@ -727,35 +838,35 @@ const normalizeParams = args => {
727
838
  if (args.length === 1) {
728
839
  const options = args[0];
729
840
  return {
841
+ execute: options.execute,
730
842
  ipc: options.ipc,
843
+ logError: options.logError || defaultLogError,
731
844
  message: options.message,
732
- execute: options.execute,
733
- resolve: options.resolve || defaultResolve,
734
845
  preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
735
- logError: options.logError || defaultLogError,
736
- requiresSocket: options.requiresSocket || defaultRequiresSocket
846
+ requiresSocket: options.requiresSocket || defaultRequiresSocket,
847
+ resolve: options.resolve || defaultResolve
737
848
  };
738
849
  }
739
850
  return {
851
+ execute: args[2],
740
852
  ipc: args[0],
853
+ logError: args[5],
741
854
  message: args[1],
742
- execute: args[2],
743
- resolve: args[3],
744
855
  preparePrettyError: args[4],
745
- logError: args[5],
746
- requiresSocket: args[6]
856
+ requiresSocket: args[6],
857
+ resolve: args[3]
747
858
  };
748
859
  };
749
860
  const handleJsonRpcMessage = async (...args) => {
750
861
  const options = normalizeParams(args);
751
862
  const {
752
- message,
753
- ipc,
754
863
  execute,
755
- resolve,
756
- preparePrettyError,
864
+ ipc,
757
865
  logError,
758
- requiresSocket
866
+ message,
867
+ preparePrettyError,
868
+ requiresSocket,
869
+ resolve
759
870
  } = options;
760
871
  if ('id' in message) {
761
872
  if ('method' in message) {
@@ -778,36 +889,17 @@ const handleJsonRpcMessage = async (...args) => {
778
889
  throw new JsonRpcError('unexpected message');
779
890
  };
780
891
 
781
- class CommandNotFoundError extends Error {
782
- constructor(command) {
783
- super(`Command not found ${command}`);
784
- this.name = 'CommandNotFoundError';
785
- }
786
- }
787
- const commands = Object.create(null);
788
- const register = commandMap => {
789
- Object.assign(commands, commandMap);
790
- };
791
- const getCommand = key => {
792
- return commands[key];
793
- };
794
- const execute = (command, ...args) => {
795
- const fn = getCommand(command);
796
- if (!fn) {
797
- throw new CommandNotFoundError(command);
798
- }
799
- return fn(...args);
800
- };
801
-
802
892
  const Two = '2.0';
803
- const create$s = (method, params) => {
893
+
894
+ const create$9 = (method, params) => {
804
895
  return {
805
896
  jsonrpc: Two,
806
897
  method,
807
898
  params
808
899
  };
809
900
  };
810
- const create$r = (id, method, params) => {
901
+
902
+ const create$8 = (id, method, params) => {
811
903
  const message = {
812
904
  id,
813
905
  jsonrpc: Two,
@@ -816,15 +908,14 @@ const create$r = (id, method, params) => {
816
908
  };
817
909
  return message;
818
910
  };
911
+
819
912
  let id = 0;
820
- const create$q = () => {
913
+ const create$7 = () => {
821
914
  return ++id;
822
915
  };
823
916
 
824
- /* eslint-disable n/no-unsupported-features/es-syntax */
825
-
826
917
  const registerPromise = map => {
827
- const id = create$q();
918
+ const id = create$7();
828
919
  const {
829
920
  promise,
830
921
  resolve
@@ -836,13 +927,12 @@ const registerPromise = map => {
836
927
  };
837
928
  };
838
929
 
839
- // @ts-ignore
840
930
  const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
841
931
  const {
842
932
  id,
843
933
  promise
844
934
  } = registerPromise(callbacks);
845
- const message = create$r(id, method, params);
935
+ const message = create$8(id, method, params);
846
936
  if (useSendAndTransfer && ipc.sendAndTransfer) {
847
937
  ipc.sendAndTransfer(message);
848
938
  } else {
@@ -878,12 +968,13 @@ const createRpc = ipc => {
878
968
  * @deprecated
879
969
  */
880
970
  send(method, ...params) {
881
- const message = create$s(method, params);
971
+ const message = create$9(method, params);
882
972
  ipc.send(message);
883
973
  }
884
974
  };
885
975
  return rpc;
886
976
  };
977
+
887
978
  const requiresSocket = () => {
888
979
  return false;
889
980
  };
@@ -898,6 +989,7 @@ const handleMessage = event => {
898
989
  const actualExecute = event?.target?.execute || execute;
899
990
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
900
991
  };
992
+
901
993
  const handleIpc = ipc => {
902
994
  if ('addEventListener' in ipc) {
903
995
  ipc.addEventListener('message', handleMessage);
@@ -906,6 +998,7 @@ const handleIpc = ipc => {
906
998
  ipc.on('message', handleMessage);
907
999
  }
908
1000
  };
1001
+
909
1002
  const listen$1 = async (module, options) => {
910
1003
  const rawIpc = await module.listen(options);
911
1004
  if (module.signal) {
@@ -914,7 +1007,36 @@ const listen$1 = async (module, options) => {
914
1007
  const ipc = module.wrap(rawIpc);
915
1008
  return ipc;
916
1009
  };
917
- const create$4 = async ({
1010
+
1011
+ const createSharedLazyRpc = factory => {
1012
+ let rpcPromise;
1013
+ const getOrCreate = () => {
1014
+ if (!rpcPromise) {
1015
+ rpcPromise = factory();
1016
+ }
1017
+ return rpcPromise;
1018
+ };
1019
+ return {
1020
+ async dispose() {
1021
+ const rpc = await getOrCreate();
1022
+ await rpc.dispose();
1023
+ },
1024
+ async invoke(method, ...params) {
1025
+ const rpc = await getOrCreate();
1026
+ return rpc.invoke(method, ...params);
1027
+ },
1028
+ async invokeAndTransfer(method, ...params) {
1029
+ const rpc = await getOrCreate();
1030
+ return rpc.invokeAndTransfer(method, ...params);
1031
+ },
1032
+ async send(method, ...params) {
1033
+ const rpc = await getOrCreate();
1034
+ rpc.send(method, ...params);
1035
+ }
1036
+ };
1037
+ };
1038
+
1039
+ const create$6 = async ({
918
1040
  commandMap,
919
1041
  isMessagePortOpen = true,
920
1042
  messagePort
@@ -931,7 +1053,8 @@ const create$4 = async ({
931
1053
  messagePort.start();
932
1054
  return rpc;
933
1055
  };
934
- const create$2$1 = async ({
1056
+
1057
+ const create$5 = async ({
935
1058
  commandMap,
936
1059
  isMessagePortOpen,
937
1060
  send
@@ -941,17 +1064,28 @@ const create$2$1 = async ({
941
1064
  port2
942
1065
  } = new MessageChannel();
943
1066
  await send(port1);
944
- return create$4({
1067
+ return create$6({
945
1068
  commandMap,
946
1069
  isMessagePortOpen,
947
1070
  messagePort: port2
948
1071
  });
949
1072
  };
950
- const TransferMessagePortRpcParent = {
951
- __proto__: null,
952
- create: create$2$1
1073
+
1074
+ const create$4 = async ({
1075
+ commandMap,
1076
+ isMessagePortOpen,
1077
+ send
1078
+ }) => {
1079
+ return createSharedLazyRpc(() => {
1080
+ return create$5({
1081
+ commandMap,
1082
+ isMessagePortOpen,
1083
+ send
1084
+ });
1085
+ });
953
1086
  };
954
- const create$1$1 = async ({
1087
+
1088
+ const create$3 = async ({
955
1089
  commandMap
956
1090
  }) => {
957
1091
  // TODO create a commandMap per rpc instance
@@ -961,10 +1095,7 @@ const create$1$1 = async ({
961
1095
  const rpc = createRpc(ipc);
962
1096
  return rpc;
963
1097
  };
964
- const WebWorkerRpcClient = {
965
- __proto__: null,
966
- create: create$1$1
967
- };
1098
+
968
1099
  const createMockRpc = ({
969
1100
  commandMap
970
1101
  }) => {
@@ -985,35 +1116,8 @@ const createMockRpc = ({
985
1116
  return mockRpc;
986
1117
  };
987
1118
 
988
- const Log = 'log';
989
- const ToolBar = 'toolbar';
990
-
991
- const Button = 1;
992
- const Div = 4;
993
- const Input = 6;
994
- const Span = 8;
995
- const Text$1 = 12;
996
- const A = 53;
997
- const Select$1 = 63;
998
- const Option$1 = 64;
999
-
1000
- const Space = 9;
1001
- const PageUp = 10;
1002
- const PageDown = 11;
1003
- const End = 255;
1004
- const Home = 12;
1005
- const LeftArrow = 13;
1006
- const UpArrow = 14;
1007
- const RightArrow = 15;
1008
- const DownArrow = 16;
1009
-
1010
- const ExtensionHostWorker = 44;
1011
- const FileSystemWorker = 209;
1012
- const OutputWorker = 7001;
1013
- const RendererWorker = 1;
1014
-
1015
1119
  const rpcs = Object.create(null);
1016
- const set$5 = (id, rpc) => {
1120
+ const set$4 = (id, rpc) => {
1017
1121
  rpcs[id] = rpc;
1018
1122
  };
1019
1123
  const get$1 = id => {
@@ -1046,7 +1150,7 @@ const create$2 = rpcId => {
1046
1150
  const mockRpc = createMockRpc({
1047
1151
  commandMap
1048
1152
  });
1049
- set$5(rpcId, mockRpc);
1153
+ set$4(rpcId, mockRpc);
1050
1154
  // @ts-ignore
1051
1155
  mockRpc[Symbol.dispose] = () => {
1052
1156
  remove(rpcId);
@@ -1055,106 +1159,56 @@ const create$2 = rpcId => {
1055
1159
  return mockRpc;
1056
1160
  },
1057
1161
  set(rpc) {
1058
- set$5(rpcId, rpc);
1162
+ set$4(rpcId, rpc);
1059
1163
  }
1060
1164
  };
1061
1165
  };
1062
1166
 
1063
- const {
1064
- invoke: invoke$3,
1065
- set: set$4
1066
- } = create$2(ExtensionHostWorker);
1067
-
1068
- const ExtensionHost = {
1069
- __proto__: null,
1070
- invoke: invoke$3,
1071
- set: set$4
1072
- };
1167
+ const ExtensionManagementWorker = 9006;
1168
+ const FileSystemWorker = 209;
1169
+ const OutputWorker = 7001;
1170
+ const RendererWorker = 1;
1073
1171
 
1074
1172
  const {
1075
1173
  invoke: invoke$2,
1076
1174
  set: set$3
1175
+ } = create$2(ExtensionManagementWorker);
1176
+
1177
+ const {
1178
+ invoke: invoke$1,
1179
+ set: set$2
1077
1180
  } = create$2(FileSystemWorker);
1078
1181
  const readFile = async uri => {
1079
- return invoke$2('FileSystem.readFile', uri);
1182
+ return invoke$1('FileSystem.readFile', uri);
1080
1183
  };
1081
1184
  const writeFile = async (uri, content) => {
1082
- return invoke$2('FileSystem.writeFile', uri, content);
1185
+ return invoke$1('FileSystem.writeFile', uri, content);
1083
1186
  };
1084
1187
  const watchFile = async (watchId, uri, rpcId) => {
1085
- await invoke$2('FileSystem.watchFile', watchId, uri, rpcId);
1188
+ await invoke$1('FileSystem.watchFile', watchId, uri, rpcId);
1086
1189
  };
1087
1190
  const unwatchFile = async watchId => {
1088
- await invoke$2('FileSystem.unwatchFile', watchId);
1089
- };
1090
-
1091
- class AssertionError extends Error {
1092
- constructor(message) {
1093
- super(message);
1094
- this.name = 'AssertionError';
1095
- }
1096
- }
1097
- const Object$1 = 1;
1098
- const Number$1 = 2;
1099
- const Array$1 = 3;
1100
- const String$1 = 4;
1101
- const Boolean$1 = 5;
1102
- const Function = 6;
1103
- const Null = 7;
1104
- const Unknown = 8;
1105
- const getType = value => {
1106
- switch (typeof value) {
1107
- case 'number':
1108
- return Number$1;
1109
- case 'function':
1110
- return Function;
1111
- case 'string':
1112
- return String$1;
1113
- case 'object':
1114
- if (value === null) {
1115
- return Null;
1116
- }
1117
- if (Array.isArray(value)) {
1118
- return Array$1;
1119
- }
1120
- return Object$1;
1121
- case 'boolean':
1122
- return Boolean$1;
1123
- default:
1124
- return Unknown;
1125
- }
1126
- };
1127
- const number = value => {
1128
- const type = getType(value);
1129
- if (type !== Number$1) {
1130
- throw new AssertionError('expected value to be of type number');
1131
- }
1191
+ await invoke$1('FileSystem.unwatchFile', watchId);
1132
1192
  };
1133
1193
 
1134
1194
  const {
1135
- invoke: invoke$1,
1195
+ invoke,
1136
1196
  invokeAndTransfer,
1137
- set: set$2
1197
+ set: set$1
1138
1198
  } = create$2(RendererWorker);
1139
1199
  const sendMessagePortToFileSystemWorker$1 = async (port, rpcId) => {
1140
1200
  const command = 'FileSystem.handleMessagePort';
1141
- // @ts-ignore
1142
1201
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1143
1202
  };
1144
- const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1145
- const command = 'HandleMessagePort.handleMessagePort2';
1146
- await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1147
- };
1148
- const activateByEvent = (event, assetDir, platform) => {
1149
- return invoke$1('ExtensionHostManagement.activateByEvent', event, assetDir, platform);
1203
+ const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1204
+ const command = 'Extensions.handleMessagePort';
1205
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1150
1206
  };
1151
1207
  const showSaveFilePicker = async () => {
1152
- // @ts-ignore
1153
- return invoke$1('FilePicker.showSaveFilePicker');
1208
+ return invoke('FilePicker.showSaveFilePicker');
1154
1209
  };
1155
1210
  const getLogsDir$1 = async () => {
1156
- // @ts-ignore
1157
- return invoke$1('PlatformPaths.getLogsDir');
1211
+ return invoke('PlatformPaths.getLogsDir');
1158
1212
  };
1159
1213
 
1160
1214
  const toCommandId = key => {
@@ -1242,7 +1296,7 @@ const terminate = () => {
1242
1296
  globalThis.close();
1243
1297
  };
1244
1298
 
1245
- const Text = 1;
1299
+ const Text$1 = 1;
1246
1300
  const Link = 2;
1247
1301
  const LogLevel = 3;
1248
1302
  const RepeatCount = 4;
@@ -1265,6 +1319,11 @@ const filterItems = (items, filterValue) => {
1265
1319
  return items.filter(parts => getTextFromParts(parts).toLowerCase().includes(normalizedFilterValue));
1266
1320
  };
1267
1321
 
1322
+ const ExtensionOutputPrefix = 'extension-output://';
1323
+ const isExtensionOutputUri = uri => {
1324
+ return uri.startsWith(ExtensionOutputPrefix);
1325
+ };
1326
+
1268
1327
  const getAggregationKey = line => {
1269
1328
  return JSON.stringify(line.filter(part => part.type !== RepeatCount));
1270
1329
  };
@@ -1308,8 +1367,8 @@ const Actions = 'Actions';
1308
1367
  const Message = 'Message';
1309
1368
  const Viewlet = 'Viewlet';
1310
1369
  const Output$1 = 'Output';
1311
- const Option = 'Option';
1312
- const Select = 'Select';
1370
+ const Option$1 = 'Option';
1371
+ const Select$1 = 'Select';
1313
1372
  const Error$1 = 'Error';
1314
1373
  const Line = 'Line';
1315
1374
  const OutputRepeatCount = 'OutputRepeatCount';
@@ -1358,14 +1417,14 @@ const parseStructuredLogLine = line => {
1358
1417
  type: LogLevel,
1359
1418
  value: normalizeLevel(parsed.level)
1360
1419
  }, {
1361
- type: Text,
1420
+ type: Text$1,
1362
1421
  value: parsed.message
1363
1422
  }];
1364
1423
  if (!parsed.source) {
1365
1424
  return parts;
1366
1425
  }
1367
1426
  return [...parts, {
1368
- type: Text,
1427
+ type: Text$1,
1369
1428
  value: ' '
1370
1429
  }, {
1371
1430
  className: OutputSourceLink,
@@ -1403,7 +1462,7 @@ const parseLine = line => {
1403
1462
  if (!match) {
1404
1463
  if (rest) {
1405
1464
  parts.push({
1406
- type: Text,
1465
+ type: Text$1,
1407
1466
  value: rest
1408
1467
  });
1409
1468
  }
@@ -1412,7 +1471,7 @@ const parseLine = line => {
1412
1471
  const index = rest.indexOf(match);
1413
1472
  if (index > 0) {
1414
1473
  parts.push({
1415
- type: Text,
1474
+ type: Text$1,
1416
1475
  value: rest.slice(0, index)
1417
1476
  });
1418
1477
  }
@@ -1421,17 +1480,22 @@ const parseLine = line => {
1421
1480
  }
1422
1481
  if (parts.length === 0) {
1423
1482
  return [{
1424
- type: Text,
1483
+ type: Text$1,
1425
1484
  value: ''
1426
1485
  }];
1427
1486
  }
1428
1487
  return parts;
1429
1488
  };
1430
1489
 
1490
+ const readOutput = async uri => {
1491
+ if (isExtensionOutputUri(uri)) {
1492
+ return invoke$2('Extensions.readOutputChannel', uri);
1493
+ }
1494
+ return readFile(uri);
1495
+ };
1431
1496
  const loadLines = async uri => {
1432
1497
  try {
1433
- // TODO use log stream, updating the output when the file is changed
1434
- const content = await readFile(uri);
1498
+ const content = await readOutput(uri);
1435
1499
  const lines = aggregateLines(content.split('\n').map(parseLine));
1436
1500
  return {
1437
1501
  code: 0,
@@ -1454,6 +1518,13 @@ const loadLines = async uri => {
1454
1518
  }
1455
1519
  };
1456
1520
 
1521
+ const clearOutput$1 = async uri => {
1522
+ if (isExtensionOutputUri(uri)) {
1523
+ await invoke$2('Extensions.clearOutputChannel', uri);
1524
+ return;
1525
+ }
1526
+ await writeFile(uri, '');
1527
+ };
1457
1528
  const clear = async state => {
1458
1529
  const {
1459
1530
  filterValue,
@@ -1468,7 +1539,7 @@ const clear = async state => {
1468
1539
  const {
1469
1540
  uri
1470
1541
  } = option;
1471
- await writeFile(uri, '');
1542
+ await clearOutput$1(uri);
1472
1543
  const {
1473
1544
  code,
1474
1545
  error,
@@ -1499,7 +1570,7 @@ const {
1499
1570
  getCommandIds,
1500
1571
  getKeys,
1501
1572
  registerCommands,
1502
- set: set$1,
1573
+ set,
1503
1574
  wrapCommand,
1504
1575
  wrapGetter
1505
1576
  } = create$1();
@@ -1536,7 +1607,7 @@ const create = (id, uri, x, y, width, height, platform, parentId) => {
1536
1607
  x,
1537
1608
  y
1538
1609
  };
1539
- set$1(id, state, state);
1610
+ set(id, state, state);
1540
1611
  };
1541
1612
 
1542
1613
  const isEqual$2 = (oldState, newState) => {
@@ -1611,6 +1682,28 @@ const focusIndex = (state, index) => {
1611
1682
  };
1612
1683
  };
1613
1684
 
1685
+ const Log = 'log';
1686
+ const ToolBar = 'toolbar';
1687
+
1688
+ const Button = 1;
1689
+ const Div = 4;
1690
+ const Input = 6;
1691
+ const Span = 8;
1692
+ const Text = 12;
1693
+ const A = 53;
1694
+ const Select = 63;
1695
+ const Option = 64;
1696
+
1697
+ const Space = 9;
1698
+ const PageUp = 10;
1699
+ const PageDown = 11;
1700
+ const End = 255;
1701
+ const Home = 12;
1702
+ const LeftArrow = 13;
1703
+ const UpArrow = 14;
1704
+ const RightArrow = 15;
1705
+ const DownArrow = 16;
1706
+
1614
1707
  const mergeClassNames = (...classNames) => {
1615
1708
  return classNames.filter(Boolean).join(' ');
1616
1709
  };
@@ -1619,7 +1712,7 @@ const text = data => {
1619
1712
  return {
1620
1713
  childCount: 0,
1621
1714
  text: data,
1622
- type: Text$1
1715
+ type: Text
1623
1716
  };
1624
1717
  };
1625
1718
 
@@ -1742,7 +1835,7 @@ const handleFileChange = async watchId => {
1742
1835
  const instance = get(key);
1743
1836
  if (instance.newState.watchId === watchId) {
1744
1837
  // @ts-ignore
1745
- await invoke$1('Output.refresh');
1838
+ await invoke('Output.refresh');
1746
1839
  }
1747
1840
  }
1748
1841
  };
@@ -1764,7 +1857,9 @@ const setupChangeListener = async (oldWatchId, newWatchId, uri) => {
1764
1857
  unregisterWatchCallback(oldWatchId);
1765
1858
  await unwatchFile(oldWatchId);
1766
1859
  }
1767
- // TODO dispose old watcher
1860
+ if (isExtensionOutputUri(uri)) {
1861
+ return;
1862
+ }
1768
1863
  const rpcId = OutputWorker;
1769
1864
  registerWatchCallback(newWatchId, handleFileChange);
1770
1865
  await watchFile(newWatchId, uri, rpcId);
@@ -1791,7 +1886,7 @@ const selectChannel = async (state, id) => {
1791
1886
  } = await loadLines(matchingOption.uri);
1792
1887
 
1793
1888
  // TODO memory leak and race condition, need to dispose file watcher of previous uri
1794
- const newWatchId = createWatchId();
1889
+ const newWatchId = isExtensionOutputUri(matchingOption.uri) ? 0 : createWatchId();
1795
1890
  await setupChangeListener(watchId, newWatchId, matchingOption.uri);
1796
1891
  const filteredItems = filterItems(lines, filterValue);
1797
1892
  return {
@@ -1813,34 +1908,21 @@ const handleSourceLinkClick = async (state, uri) => {
1813
1908
  if (!uri) {
1814
1909
  return state;
1815
1910
  }
1816
- await invoke$1('Main.openUri', uri);
1911
+ await invoke('Main.openUri', uri);
1817
1912
  return state;
1818
1913
  };
1819
1914
 
1820
- const sendMessagePortToExtensionHostWorker2 = async port => {
1821
- await sendMessagePortToExtensionHostWorker(port);
1822
- };
1823
-
1824
- const createExtensionHostRpc = async () => {
1825
- try {
1826
- const rpc = await TransferMessagePortRpcParent.create({
1827
- commandMap: {},
1828
- send: sendMessagePortToExtensionHostWorker2
1829
- });
1830
- return rpc;
1831
- } catch (error) {
1832
- throw new VError(error, `Failed to create extension host rpc`);
1833
- }
1915
+ const createExtensionManagementWorkerRpc = async () => {
1916
+ const rpc = await create$4({
1917
+ commandMap: {},
1918
+ send: port => sendMessagePortToExtensionManagementWorker(port, OutputWorker)
1919
+ });
1920
+ return rpc;
1834
1921
  };
1835
1922
 
1836
- const {
1837
- invoke,
1838
- set
1839
- } = ExtensionHost;
1840
-
1841
- const initializeExtensionHost = async () => {
1842
- const extensionHostRpc = await createExtensionHostRpc();
1843
- set(extensionHostRpc);
1923
+ const initializeExtensionManagementWorker = async () => {
1924
+ const rpc = await createExtensionManagementWorkerRpc();
1925
+ set$3(rpc);
1844
1926
  };
1845
1927
 
1846
1928
  const sendMessagePortToFileSystemWorker = async port => {
@@ -1849,7 +1931,7 @@ const sendMessagePortToFileSystemWorker = async port => {
1849
1931
 
1850
1932
  const createFileSystemWorkerRpc = async () => {
1851
1933
  try {
1852
- const rpc = await TransferMessagePortRpcParent.create({
1934
+ const rpc = await create$5({
1853
1935
  commandMap: {},
1854
1936
  send: sendMessagePortToFileSystemWorker
1855
1937
  });
@@ -1861,11 +1943,11 @@ const createFileSystemWorkerRpc = async () => {
1861
1943
 
1862
1944
  const initializeFileSystemWorker = async () => {
1863
1945
  const rpc = await createFileSystemWorkerRpc();
1864
- set$3(rpc);
1946
+ set$2(rpc);
1865
1947
  };
1866
1948
 
1867
1949
  const initialize = async () => {
1868
- await Promise.all([initializeFileSystemWorker(), initializeExtensionHost()]);
1950
+ await Promise.all([initializeFileSystemWorker(), initializeExtensionManagementWorker()]);
1869
1951
  };
1870
1952
 
1871
1953
  const Web = 1;
@@ -1936,13 +2018,7 @@ const error = error => {
1936
2018
 
1937
2019
  const getExtensionOptions = async () => {
1938
2020
  try {
1939
- // TODO make api more declarative:
1940
- // output channels are registered in extension manifest
1941
- // only downside: it might show channels for extensions that are not active
1942
- // @ts-ignore
1943
- await activateByEvent('onOutput');
1944
- // @ts-ignore
1945
- const channels = await invoke('Output.getEnabledProviders');
2021
+ const channels = await invoke$2('Extensions.getOutputChannelProviders');
1946
2022
  return channels;
1947
2023
  } catch (error$1) {
1948
2024
  error(error$1);
@@ -2046,7 +2122,7 @@ const loadContent = async (state, savedState) => {
2046
2122
  lines
2047
2123
  } = await loadLines(uri);
2048
2124
  const filteredItems = filterItems(lines, filterValue);
2049
- const newWatchId = createWatchId();
2125
+ const newWatchId = isExtensionOutputUri(uri) ? 0 : createWatchId();
2050
2126
  await setupChangeListener(watchId, newWatchId, uri);
2051
2127
  const buttons = loadButtons();
2052
2128
  return {
@@ -2153,7 +2229,7 @@ const getLinePartDom = part => {
2153
2229
  childCount: 2,
2154
2230
  nodes: [repeatCountNode, text(part.value), spaceNode]
2155
2231
  };
2156
- case Text:
2232
+ case Text$1:
2157
2233
  return {
2158
2234
  childCount: 1,
2159
2235
  nodes: [text(part.value)]
@@ -2273,7 +2349,7 @@ const render2 = (uid, diffResult) => {
2273
2349
  newState,
2274
2350
  oldState
2275
2351
  } = get(uid);
2276
- set$1(uid, newState, newState);
2352
+ set(uid, newState, newState);
2277
2353
  const commands = applyRender(oldState, newState, diffResult);
2278
2354
  return commands;
2279
2355
  };
@@ -2325,8 +2401,8 @@ const getOptionVirtualDom = option => {
2325
2401
  } = option;
2326
2402
  return [{
2327
2403
  childCount: 1,
2328
- className: Option,
2329
- type: Option$1,
2404
+ className: Option$1,
2405
+ type: Option,
2330
2406
  value: id
2331
2407
  }, text(label)];
2332
2408
  };
@@ -2334,10 +2410,10 @@ const getOptionVirtualDom = option => {
2334
2410
  const getSelectVirtualDom = options => {
2335
2411
  return [{
2336
2412
  childCount: options.length,
2337
- className: Select,
2413
+ className: Select$1,
2338
2414
  name: Output,
2339
2415
  onChange: HandleSelect,
2340
- type: Select$1
2416
+ type: Select
2341
2417
  }, ...options.flatMap(getOptionVirtualDom)];
2342
2418
  };
2343
2419
 
@@ -2499,10 +2575,10 @@ const commandMapRef = {};
2499
2575
  const listen = async () => {
2500
2576
  registerCommands(commandMap);
2501
2577
  Object.assign(commandMapRef, commandMap);
2502
- const rpc = await WebWorkerRpcClient.create({
2578
+ const rpc = await create$3({
2503
2579
  commandMap: commandMapRef
2504
2580
  });
2505
- set$2(rpc);
2581
+ set$1(rpc);
2506
2582
  };
2507
2583
 
2508
2584
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/output-view",
3
- "version": "2.14.0",
3
+ "version": "2.16.0",
4
4
  "description": "Output View Worker",
5
5
  "repository": {
6
6
  "type": "git",