@lvce-editor/about-view 7.1.0 → 7.2.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.
- package/dist/aboutWorkerMain.js +288 -219
- package/package.json +1 -1
package/dist/aboutWorkerMain.js
CHANGED
|
@@ -369,12 +369,33 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
369
369
|
wrap: wrap$e
|
|
370
370
|
};
|
|
371
371
|
|
|
372
|
+
class CommandNotFoundError extends Error {
|
|
373
|
+
constructor(command) {
|
|
374
|
+
super(`Command not found ${command}`);
|
|
375
|
+
this.name = 'CommandNotFoundError';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const commands = Object.create(null);
|
|
379
|
+
const register = commandMap => {
|
|
380
|
+
Object.assign(commands, commandMap);
|
|
381
|
+
};
|
|
382
|
+
const getCommand = key => {
|
|
383
|
+
return commands[key];
|
|
384
|
+
};
|
|
385
|
+
const execute = (command, ...args) => {
|
|
386
|
+
const fn = getCommand(command);
|
|
387
|
+
if (!fn) {
|
|
388
|
+
throw new CommandNotFoundError(command);
|
|
389
|
+
}
|
|
390
|
+
return fn(...args);
|
|
391
|
+
};
|
|
392
|
+
|
|
372
393
|
const Two$1 = '2.0';
|
|
373
394
|
const callbacks = Object.create(null);
|
|
374
395
|
const get$2 = id => {
|
|
375
396
|
return callbacks[id];
|
|
376
397
|
};
|
|
377
|
-
const remove = id => {
|
|
398
|
+
const remove$1 = id => {
|
|
378
399
|
delete callbacks[id];
|
|
379
400
|
};
|
|
380
401
|
class JsonRpcError extends Error {
|
|
@@ -393,12 +414,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
393
414
|
switch (type) {
|
|
394
415
|
case DomException:
|
|
395
416
|
return DOMException;
|
|
396
|
-
case TypeError$1:
|
|
397
|
-
return TypeError;
|
|
398
|
-
case SyntaxError$1:
|
|
399
|
-
return SyntaxError;
|
|
400
417
|
case ReferenceError$1:
|
|
401
418
|
return ReferenceError;
|
|
419
|
+
case SyntaxError$1:
|
|
420
|
+
return SyntaxError;
|
|
421
|
+
case TypeError$1:
|
|
422
|
+
return TypeError;
|
|
402
423
|
default:
|
|
403
424
|
return Error;
|
|
404
425
|
}
|
|
@@ -527,7 +548,7 @@ const resolve = (id, response) => {
|
|
|
527
548
|
return;
|
|
528
549
|
}
|
|
529
550
|
fn(response);
|
|
530
|
-
remove(id);
|
|
551
|
+
remove$1(id);
|
|
531
552
|
};
|
|
532
553
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
533
554
|
const getErrorType = prettyError => {
|
|
@@ -554,56 +575,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
554
575
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
555
576
|
return {
|
|
556
577
|
code: MethodNotFound,
|
|
557
|
-
|
|
558
|
-
|
|
578
|
+
data: error.stack,
|
|
579
|
+
message: error.message
|
|
559
580
|
};
|
|
560
581
|
}
|
|
561
582
|
return {
|
|
562
583
|
code: Custom,
|
|
563
|
-
message: prettyError.message,
|
|
564
584
|
data: {
|
|
565
|
-
stack: getStack(prettyError),
|
|
566
|
-
codeFrame: prettyError.codeFrame,
|
|
567
|
-
type: getErrorType(prettyError),
|
|
568
585
|
code: prettyError.code,
|
|
569
|
-
|
|
570
|
-
|
|
586
|
+
codeFrame: prettyError.codeFrame,
|
|
587
|
+
name: prettyError.name,
|
|
588
|
+
stack: getStack(prettyError),
|
|
589
|
+
type: getErrorType(prettyError)
|
|
590
|
+
},
|
|
591
|
+
message: prettyError.message
|
|
571
592
|
};
|
|
572
593
|
};
|
|
573
|
-
const create$1$
|
|
594
|
+
const create$1$1 = (id, error) => {
|
|
574
595
|
return {
|
|
575
|
-
|
|
596
|
+
error,
|
|
576
597
|
id,
|
|
577
|
-
|
|
598
|
+
jsonrpc: Two$1
|
|
578
599
|
};
|
|
579
600
|
};
|
|
580
601
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
581
602
|
const prettyError = preparePrettyError(error);
|
|
582
603
|
logError(error, prettyError);
|
|
583
604
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
584
|
-
return create$1$
|
|
605
|
+
return create$1$1(id, errorProperty);
|
|
585
606
|
};
|
|
586
|
-
const create$
|
|
607
|
+
const create$7 = (message, result) => {
|
|
587
608
|
return {
|
|
588
|
-
jsonrpc: Two$1,
|
|
589
609
|
id: message.id,
|
|
610
|
+
jsonrpc: Two$1,
|
|
590
611
|
result: result ?? null
|
|
591
612
|
};
|
|
592
613
|
};
|
|
593
614
|
const getSuccessResponse = (message, result) => {
|
|
594
615
|
const resultProperty = result ?? null;
|
|
595
|
-
return create$
|
|
616
|
+
return create$7(message, resultProperty);
|
|
596
617
|
};
|
|
597
618
|
const getErrorResponseSimple = (id, error) => {
|
|
598
619
|
return {
|
|
599
|
-
jsonrpc: Two$1,
|
|
600
|
-
id,
|
|
601
620
|
error: {
|
|
602
621
|
code: Custom,
|
|
622
|
+
data: error,
|
|
603
623
|
// @ts-ignore
|
|
604
|
-
message: error.message
|
|
605
|
-
|
|
606
|
-
|
|
624
|
+
message: error.message
|
|
625
|
+
},
|
|
626
|
+
id,
|
|
627
|
+
jsonrpc: Two$1
|
|
607
628
|
};
|
|
608
629
|
};
|
|
609
630
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -633,35 +654,35 @@ const normalizeParams = args => {
|
|
|
633
654
|
if (args.length === 1) {
|
|
634
655
|
const options = args[0];
|
|
635
656
|
return {
|
|
657
|
+
execute: options.execute,
|
|
636
658
|
ipc: options.ipc,
|
|
659
|
+
logError: options.logError || defaultLogError,
|
|
637
660
|
message: options.message,
|
|
638
|
-
execute: options.execute,
|
|
639
|
-
resolve: options.resolve || defaultResolve,
|
|
640
661
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
641
|
-
|
|
642
|
-
|
|
662
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
663
|
+
resolve: options.resolve || defaultResolve
|
|
643
664
|
};
|
|
644
665
|
}
|
|
645
666
|
return {
|
|
667
|
+
execute: args[2],
|
|
646
668
|
ipc: args[0],
|
|
669
|
+
logError: args[5],
|
|
647
670
|
message: args[1],
|
|
648
|
-
execute: args[2],
|
|
649
|
-
resolve: args[3],
|
|
650
671
|
preparePrettyError: args[4],
|
|
651
|
-
|
|
652
|
-
|
|
672
|
+
requiresSocket: args[6],
|
|
673
|
+
resolve: args[3]
|
|
653
674
|
};
|
|
654
675
|
};
|
|
655
676
|
const handleJsonRpcMessage = async (...args) => {
|
|
656
677
|
const options = normalizeParams(args);
|
|
657
678
|
const {
|
|
658
|
-
message,
|
|
659
|
-
ipc,
|
|
660
679
|
execute,
|
|
661
|
-
|
|
662
|
-
preparePrettyError,
|
|
680
|
+
ipc,
|
|
663
681
|
logError,
|
|
664
|
-
|
|
682
|
+
message,
|
|
683
|
+
preparePrettyError,
|
|
684
|
+
requiresSocket,
|
|
685
|
+
resolve
|
|
665
686
|
} = options;
|
|
666
687
|
if ('id' in message) {
|
|
667
688
|
if ('method' in message) {
|
|
@@ -684,36 +705,17 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
684
705
|
throw new JsonRpcError('unexpected message');
|
|
685
706
|
};
|
|
686
707
|
|
|
687
|
-
class CommandNotFoundError extends Error {
|
|
688
|
-
constructor(command) {
|
|
689
|
-
super(`Command not found ${command}`);
|
|
690
|
-
this.name = 'CommandNotFoundError';
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
const commands = Object.create(null);
|
|
694
|
-
const register = commandMap => {
|
|
695
|
-
Object.assign(commands, commandMap);
|
|
696
|
-
};
|
|
697
|
-
const getCommand = key => {
|
|
698
|
-
return commands[key];
|
|
699
|
-
};
|
|
700
|
-
const execute = (command, ...args) => {
|
|
701
|
-
const fn = getCommand(command);
|
|
702
|
-
if (!fn) {
|
|
703
|
-
throw new CommandNotFoundError(command);
|
|
704
|
-
}
|
|
705
|
-
return fn(...args);
|
|
706
|
-
};
|
|
707
|
-
|
|
708
708
|
const Two = '2.0';
|
|
709
|
-
|
|
709
|
+
|
|
710
|
+
const create$6 = (method, params) => {
|
|
710
711
|
return {
|
|
711
712
|
jsonrpc: Two,
|
|
712
713
|
method,
|
|
713
714
|
params
|
|
714
715
|
};
|
|
715
716
|
};
|
|
716
|
-
|
|
717
|
+
|
|
718
|
+
const create$5 = (id, method, params) => {
|
|
717
719
|
const message = {
|
|
718
720
|
id,
|
|
719
721
|
jsonrpc: Two,
|
|
@@ -722,15 +724,14 @@ const create$n = (id, method, params) => {
|
|
|
722
724
|
};
|
|
723
725
|
return message;
|
|
724
726
|
};
|
|
727
|
+
|
|
725
728
|
let id = 0;
|
|
726
|
-
const create$
|
|
729
|
+
const create$4 = () => {
|
|
727
730
|
return ++id;
|
|
728
731
|
};
|
|
729
732
|
|
|
730
|
-
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
731
|
-
|
|
732
733
|
const registerPromise = map => {
|
|
733
|
-
const id = create$
|
|
734
|
+
const id = create$4();
|
|
734
735
|
const {
|
|
735
736
|
promise,
|
|
736
737
|
resolve
|
|
@@ -742,13 +743,12 @@ const registerPromise = map => {
|
|
|
742
743
|
};
|
|
743
744
|
};
|
|
744
745
|
|
|
745
|
-
// @ts-ignore
|
|
746
746
|
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
747
747
|
const {
|
|
748
748
|
id,
|
|
749
749
|
promise
|
|
750
750
|
} = registerPromise(callbacks);
|
|
751
|
-
const message = create$
|
|
751
|
+
const message = create$5(id, method, params);
|
|
752
752
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
753
753
|
ipc.sendAndTransfer(message);
|
|
754
754
|
} else {
|
|
@@ -784,12 +784,13 @@ const createRpc = ipc => {
|
|
|
784
784
|
* @deprecated
|
|
785
785
|
*/
|
|
786
786
|
send(method, ...params) {
|
|
787
|
-
const message = create$
|
|
787
|
+
const message = create$6(method, params);
|
|
788
788
|
ipc.send(message);
|
|
789
789
|
}
|
|
790
790
|
};
|
|
791
791
|
return rpc;
|
|
792
792
|
};
|
|
793
|
+
|
|
793
794
|
const requiresSocket = () => {
|
|
794
795
|
return false;
|
|
795
796
|
};
|
|
@@ -804,6 +805,7 @@ const handleMessage = event => {
|
|
|
804
805
|
const actualExecute = event?.target?.execute || execute;
|
|
805
806
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
806
807
|
};
|
|
808
|
+
|
|
807
809
|
const handleIpc = ipc => {
|
|
808
810
|
if ('addEventListener' in ipc) {
|
|
809
811
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -812,6 +814,7 @@ const handleIpc = ipc => {
|
|
|
812
814
|
ipc.on('message', handleMessage);
|
|
813
815
|
}
|
|
814
816
|
};
|
|
817
|
+
|
|
815
818
|
const listen$1 = async (module, options) => {
|
|
816
819
|
const rawIpc = await module.listen(options);
|
|
817
820
|
if (module.signal) {
|
|
@@ -820,7 +823,8 @@ const listen$1 = async (module, options) => {
|
|
|
820
823
|
const ipc = module.wrap(rawIpc);
|
|
821
824
|
return ipc;
|
|
822
825
|
};
|
|
823
|
-
|
|
826
|
+
|
|
827
|
+
const create$3 = async ({
|
|
824
828
|
commandMap
|
|
825
829
|
}) => {
|
|
826
830
|
// TODO create a commandMap per rpc instance
|
|
@@ -830,14 +834,26 @@ const create$1$1 = async ({
|
|
|
830
834
|
const rpc = createRpc(ipc);
|
|
831
835
|
return rpc;
|
|
832
836
|
};
|
|
833
|
-
const WebWorkerRpcClient = {
|
|
834
|
-
__proto__: null,
|
|
835
|
-
create: create$1$1
|
|
836
|
-
};
|
|
837
|
-
|
|
838
|
-
const TargetName = 'event.target.name';
|
|
839
837
|
|
|
840
|
-
const
|
|
838
|
+
const createMockRpc = ({
|
|
839
|
+
commandMap
|
|
840
|
+
}) => {
|
|
841
|
+
const invocations = [];
|
|
842
|
+
const invoke = (method, ...params) => {
|
|
843
|
+
invocations.push([method, ...params]);
|
|
844
|
+
const command = commandMap[method];
|
|
845
|
+
if (!command) {
|
|
846
|
+
throw new Error(`command ${method} not found`);
|
|
847
|
+
}
|
|
848
|
+
return command(...params);
|
|
849
|
+
};
|
|
850
|
+
const mockRpc = {
|
|
851
|
+
invocations,
|
|
852
|
+
invoke,
|
|
853
|
+
invokeAndTransfer: invoke
|
|
854
|
+
};
|
|
855
|
+
return mockRpc;
|
|
856
|
+
};
|
|
841
857
|
|
|
842
858
|
const rpcs = Object.create(null);
|
|
843
859
|
const set$2 = (id, rpc) => {
|
|
@@ -846,7 +862,11 @@ const set$2 = (id, rpc) => {
|
|
|
846
862
|
const get$1 = id => {
|
|
847
863
|
return rpcs[id];
|
|
848
864
|
};
|
|
865
|
+
const remove = id => {
|
|
866
|
+
delete rpcs[id];
|
|
867
|
+
};
|
|
849
868
|
|
|
869
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
850
870
|
const create$2 = rpcId => {
|
|
851
871
|
return {
|
|
852
872
|
async dispose() {
|
|
@@ -865,12 +885,38 @@ const create$2 = rpcId => {
|
|
|
865
885
|
// @ts-ignore
|
|
866
886
|
return rpc.invokeAndTransfer(method, ...params);
|
|
867
887
|
},
|
|
888
|
+
registerMockRpc(commandMap) {
|
|
889
|
+
const mockRpc = createMockRpc({
|
|
890
|
+
commandMap
|
|
891
|
+
});
|
|
892
|
+
set$2(rpcId, mockRpc);
|
|
893
|
+
// @ts-ignore
|
|
894
|
+
mockRpc[Symbol.dispose] = () => {
|
|
895
|
+
remove(rpcId);
|
|
896
|
+
};
|
|
897
|
+
// @ts-ignore
|
|
898
|
+
return mockRpc;
|
|
899
|
+
},
|
|
868
900
|
set(rpc) {
|
|
869
901
|
set$2(rpcId, rpc);
|
|
870
902
|
}
|
|
871
903
|
};
|
|
872
904
|
};
|
|
873
905
|
|
|
906
|
+
const Button$2 = 1;
|
|
907
|
+
const Div = 4;
|
|
908
|
+
const Text = 12;
|
|
909
|
+
const Br = 55;
|
|
910
|
+
|
|
911
|
+
const TargetName = 'event.target.name';
|
|
912
|
+
|
|
913
|
+
const Tab = 2;
|
|
914
|
+
const Escape = 8;
|
|
915
|
+
|
|
916
|
+
const Shift = 1 << 10 >>> 0;
|
|
917
|
+
|
|
918
|
+
const RendererWorker = 1;
|
|
919
|
+
|
|
874
920
|
const {
|
|
875
921
|
invoke,
|
|
876
922
|
set: set$1
|
|
@@ -914,42 +960,68 @@ const create$1 = () => {
|
|
|
914
960
|
const states = Object.create(null);
|
|
915
961
|
const commandMapRef = {};
|
|
916
962
|
return {
|
|
917
|
-
|
|
918
|
-
|
|
963
|
+
clear() {
|
|
964
|
+
for (const key of Object.keys(states)) {
|
|
965
|
+
delete states[key];
|
|
966
|
+
}
|
|
919
967
|
},
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
};
|
|
968
|
+
diff(uid, modules, numbers) {
|
|
969
|
+
const {
|
|
970
|
+
newState,
|
|
971
|
+
oldState
|
|
972
|
+
} = states[uid];
|
|
973
|
+
const diffResult = [];
|
|
974
|
+
for (let i = 0; i < modules.length; i++) {
|
|
975
|
+
const fn = modules[i];
|
|
976
|
+
if (!fn(oldState, newState)) {
|
|
977
|
+
diffResult.push(numbers[i]);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
return diffResult;
|
|
925
981
|
},
|
|
926
982
|
dispose(uid) {
|
|
927
983
|
delete states[uid];
|
|
928
984
|
},
|
|
985
|
+
get(uid) {
|
|
986
|
+
return states[uid];
|
|
987
|
+
},
|
|
988
|
+
getCommandIds() {
|
|
989
|
+
const keys = Object.keys(commandMapRef);
|
|
990
|
+
const ids = keys.map(toCommandId);
|
|
991
|
+
return ids;
|
|
992
|
+
},
|
|
929
993
|
getKeys() {
|
|
930
994
|
return Object.keys(states).map(key => {
|
|
931
|
-
return Number.
|
|
995
|
+
return Number.parseFloat(key);
|
|
932
996
|
});
|
|
933
997
|
},
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
998
|
+
registerCommands(commandMap) {
|
|
999
|
+
Object.assign(commandMapRef, commandMap);
|
|
1000
|
+
},
|
|
1001
|
+
set(uid, oldState, newState) {
|
|
1002
|
+
states[uid] = {
|
|
1003
|
+
newState,
|
|
1004
|
+
oldState
|
|
1005
|
+
};
|
|
938
1006
|
},
|
|
939
1007
|
wrapCommand(fn) {
|
|
940
1008
|
const wrapped = async (uid, ...args) => {
|
|
941
1009
|
const {
|
|
942
|
-
|
|
943
|
-
|
|
1010
|
+
newState,
|
|
1011
|
+
oldState
|
|
944
1012
|
} = states[uid];
|
|
945
1013
|
const newerState = await fn(newState, ...args);
|
|
946
1014
|
if (oldState === newerState || newState === newerState) {
|
|
947
1015
|
return;
|
|
948
1016
|
}
|
|
949
|
-
const
|
|
1017
|
+
const latestOld = states[uid];
|
|
1018
|
+
const latestNew = {
|
|
1019
|
+
...latestOld.newState,
|
|
1020
|
+
...newerState
|
|
1021
|
+
};
|
|
950
1022
|
states[uid] = {
|
|
951
|
-
|
|
952
|
-
|
|
1023
|
+
newState: latestNew,
|
|
1024
|
+
oldState: latestOld.oldState
|
|
953
1025
|
};
|
|
954
1026
|
};
|
|
955
1027
|
return wrapped;
|
|
@@ -963,27 +1035,36 @@ const create$1 = () => {
|
|
|
963
1035
|
};
|
|
964
1036
|
return wrapped;
|
|
965
1037
|
},
|
|
966
|
-
|
|
967
|
-
const {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
|
|
1038
|
+
wrapLoadContent(fn) {
|
|
1039
|
+
const wrapped = async (uid, ...args) => {
|
|
1040
|
+
const {
|
|
1041
|
+
newState,
|
|
1042
|
+
oldState
|
|
1043
|
+
} = states[uid];
|
|
1044
|
+
const result = await fn(newState, ...args);
|
|
1045
|
+
const {
|
|
1046
|
+
error,
|
|
1047
|
+
state
|
|
1048
|
+
} = result;
|
|
1049
|
+
if (oldState === state || newState === state) {
|
|
1050
|
+
return {
|
|
1051
|
+
error
|
|
1052
|
+
};
|
|
976
1053
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
1054
|
+
const latestOld = states[uid];
|
|
1055
|
+
const latestNew = {
|
|
1056
|
+
...latestOld.newState,
|
|
1057
|
+
...state
|
|
1058
|
+
};
|
|
1059
|
+
states[uid] = {
|
|
1060
|
+
newState: latestNew,
|
|
1061
|
+
oldState: latestOld.oldState
|
|
1062
|
+
};
|
|
1063
|
+
return {
|
|
1064
|
+
error
|
|
1065
|
+
};
|
|
1066
|
+
};
|
|
1067
|
+
return wrapped;
|
|
987
1068
|
}
|
|
988
1069
|
};
|
|
989
1070
|
};
|
|
@@ -1099,25 +1180,15 @@ const focusPrevious = state => {
|
|
|
1099
1180
|
};
|
|
1100
1181
|
};
|
|
1101
1182
|
|
|
1102
|
-
const Button$2 = 1;
|
|
1103
|
-
const Div = 4;
|
|
1104
|
-
const Text = 12;
|
|
1105
|
-
const Br = 55;
|
|
1106
|
-
|
|
1107
|
-
const Tab = 2;
|
|
1108
|
-
const Escape = 8;
|
|
1109
|
-
|
|
1110
|
-
const Shift = 1 << 10 >>> 0;
|
|
1111
|
-
|
|
1112
1183
|
const mergeClassNames = (...classNames) => {
|
|
1113
1184
|
return classNames.filter(Boolean).join(' ');
|
|
1114
1185
|
};
|
|
1115
1186
|
|
|
1116
1187
|
const text = data => {
|
|
1117
1188
|
return {
|
|
1118
|
-
|
|
1189
|
+
childCount: 0,
|
|
1119
1190
|
text: data,
|
|
1120
|
-
|
|
1191
|
+
type: Text
|
|
1121
1192
|
};
|
|
1122
1193
|
};
|
|
1123
1194
|
|
|
@@ -1369,6 +1440,22 @@ const inSomeYears = years => {
|
|
|
1369
1440
|
});
|
|
1370
1441
|
};
|
|
1371
1442
|
|
|
1443
|
+
const formatRelativeDateRange = (seconds, range) => {
|
|
1444
|
+
const value = Math.floor(seconds / range.divisor);
|
|
1445
|
+
if (value === 1) {
|
|
1446
|
+
return range.one();
|
|
1447
|
+
}
|
|
1448
|
+
return range.some(value);
|
|
1449
|
+
};
|
|
1450
|
+
const formatRelativeDate = (seconds, ranges) => {
|
|
1451
|
+
for (const range of ranges) {
|
|
1452
|
+
if (seconds < range.limit) {
|
|
1453
|
+
return formatRelativeDateRange(seconds, range);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
throw new Error('unreachable');
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1372
1459
|
const minute = 60;
|
|
1373
1460
|
const hour = minute * 60;
|
|
1374
1461
|
const day = hour * 24;
|
|
@@ -1377,103 +1464,85 @@ const month = day * 30;
|
|
|
1377
1464
|
const year = day * 365;
|
|
1378
1465
|
|
|
1379
1466
|
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
|
1467
|
+
const ranges$1 = [{
|
|
1468
|
+
divisor: 1,
|
|
1469
|
+
limit: minute,
|
|
1470
|
+
one: inOneSecond,
|
|
1471
|
+
some: inSomeSeconds
|
|
1472
|
+
}, {
|
|
1473
|
+
divisor: minute,
|
|
1474
|
+
limit: hour,
|
|
1475
|
+
one: inOneMinute,
|
|
1476
|
+
some: inSomeMinutes
|
|
1477
|
+
}, {
|
|
1478
|
+
divisor: hour,
|
|
1479
|
+
limit: day,
|
|
1480
|
+
one: inOneHour,
|
|
1481
|
+
some: inSomeHours
|
|
1482
|
+
}, {
|
|
1483
|
+
divisor: day,
|
|
1484
|
+
limit: week,
|
|
1485
|
+
one: inOneDay,
|
|
1486
|
+
some: inSomeDays
|
|
1487
|
+
}, {
|
|
1488
|
+
divisor: week,
|
|
1489
|
+
limit: month,
|
|
1490
|
+
one: inOneWeek,
|
|
1491
|
+
some: inSomeWeeks
|
|
1492
|
+
}, {
|
|
1493
|
+
divisor: month,
|
|
1494
|
+
limit: year,
|
|
1495
|
+
one: inOneMonth,
|
|
1496
|
+
some: inSomeMonths
|
|
1497
|
+
}, {
|
|
1498
|
+
divisor: year,
|
|
1499
|
+
limit: Number.POSITIVE_INFINITY,
|
|
1500
|
+
one: inOneYear,
|
|
1501
|
+
some: inSomeYears
|
|
1502
|
+
}];
|
|
1380
1503
|
const formatDateFuture = seconds => {
|
|
1381
|
-
|
|
1382
|
-
if (seconds === 1) {
|
|
1383
|
-
return inOneSecond();
|
|
1384
|
-
}
|
|
1385
|
-
return inSomeSeconds(seconds);
|
|
1386
|
-
}
|
|
1387
|
-
if (seconds < hour) {
|
|
1388
|
-
const minutes = Math.floor(seconds / minute);
|
|
1389
|
-
if (minutes === 1) {
|
|
1390
|
-
return inOneMinute();
|
|
1391
|
-
}
|
|
1392
|
-
return inSomeMinutes(minutes);
|
|
1393
|
-
}
|
|
1394
|
-
if (seconds < day) {
|
|
1395
|
-
const days = Math.floor(seconds / hour);
|
|
1396
|
-
if (days === 1) {
|
|
1397
|
-
return inOneHour();
|
|
1398
|
-
}
|
|
1399
|
-
return inSomeHours(days);
|
|
1400
|
-
}
|
|
1401
|
-
if (seconds < week) {
|
|
1402
|
-
const days = Math.floor(seconds / day);
|
|
1403
|
-
if (days === 1) {
|
|
1404
|
-
return inOneDay();
|
|
1405
|
-
}
|
|
1406
|
-
return inSomeDays(days);
|
|
1407
|
-
}
|
|
1408
|
-
if (seconds < month) {
|
|
1409
|
-
const weeks = Math.floor(seconds / week);
|
|
1410
|
-
if (weeks === 1) {
|
|
1411
|
-
return inOneWeek();
|
|
1412
|
-
}
|
|
1413
|
-
return inSomeWeeks(weeks);
|
|
1414
|
-
}
|
|
1415
|
-
if (seconds < year) {
|
|
1416
|
-
const months = Math.floor(seconds / month);
|
|
1417
|
-
if (months === 1) {
|
|
1418
|
-
return inOneMonth();
|
|
1419
|
-
}
|
|
1420
|
-
return inSomeMonths(months);
|
|
1421
|
-
}
|
|
1422
|
-
const years = Math.floor(seconds / year);
|
|
1423
|
-
if (years === 1) {
|
|
1424
|
-
return inOneYear();
|
|
1425
|
-
}
|
|
1426
|
-
return inSomeYears(years);
|
|
1504
|
+
return formatRelativeDate(seconds, ranges$1);
|
|
1427
1505
|
};
|
|
1428
1506
|
|
|
1429
1507
|
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
|
1508
|
+
const ranges = [{
|
|
1509
|
+
divisor: 1,
|
|
1510
|
+
limit: minute,
|
|
1511
|
+
one: oneSecondAgo,
|
|
1512
|
+
some: someSecondsAgo
|
|
1513
|
+
}, {
|
|
1514
|
+
divisor: minute,
|
|
1515
|
+
limit: hour,
|
|
1516
|
+
one: oneMinuteAgo,
|
|
1517
|
+
some: someMinutesAgo
|
|
1518
|
+
}, {
|
|
1519
|
+
divisor: hour,
|
|
1520
|
+
limit: day,
|
|
1521
|
+
one: oneHourAgo,
|
|
1522
|
+
some: someHoursAgo
|
|
1523
|
+
}, {
|
|
1524
|
+
divisor: day,
|
|
1525
|
+
limit: week,
|
|
1526
|
+
one: oneDayAgo,
|
|
1527
|
+
some: someDaysAgo
|
|
1528
|
+
}, {
|
|
1529
|
+
divisor: week,
|
|
1530
|
+
limit: month,
|
|
1531
|
+
one: oneWeekAgo,
|
|
1532
|
+
some: someWeeksAgo
|
|
1533
|
+
}, {
|
|
1534
|
+
divisor: month,
|
|
1535
|
+
limit: year,
|
|
1536
|
+
one: oneMonthAgo,
|
|
1537
|
+
some: someMonthsAgo
|
|
1538
|
+
}, {
|
|
1539
|
+
divisor: year,
|
|
1540
|
+
limit: Number.POSITIVE_INFINITY,
|
|
1541
|
+
one: oneYearAgo,
|
|
1542
|
+
some: someYearsAgo
|
|
1543
|
+
}];
|
|
1430
1544
|
const formatDatePast = seconds => {
|
|
1431
|
-
|
|
1432
|
-
if (seconds === 1) {
|
|
1433
|
-
return oneSecondAgo();
|
|
1434
|
-
}
|
|
1435
|
-
return someSecondsAgo(seconds);
|
|
1436
|
-
}
|
|
1437
|
-
if (seconds < hour) {
|
|
1438
|
-
const minutes = Math.floor(seconds / minute);
|
|
1439
|
-
if (minutes === 1) {
|
|
1440
|
-
return oneMinuteAgo();
|
|
1441
|
-
}
|
|
1442
|
-
return someMinutesAgo(minutes);
|
|
1443
|
-
}
|
|
1444
|
-
if (seconds < day) {
|
|
1445
|
-
const days = Math.floor(seconds / hour);
|
|
1446
|
-
if (days === 1) {
|
|
1447
|
-
return oneHourAgo();
|
|
1448
|
-
}
|
|
1449
|
-
return someHoursAgo(days);
|
|
1450
|
-
}
|
|
1451
|
-
if (seconds < week) {
|
|
1452
|
-
const days = Math.floor(seconds / day);
|
|
1453
|
-
if (days === 1) {
|
|
1454
|
-
return oneDayAgo();
|
|
1455
|
-
}
|
|
1456
|
-
return someDaysAgo(days);
|
|
1457
|
-
}
|
|
1458
|
-
if (seconds < month) {
|
|
1459
|
-
const weeks = Math.floor(seconds / week);
|
|
1460
|
-
if (weeks === 1) {
|
|
1461
|
-
return oneWeekAgo();
|
|
1462
|
-
}
|
|
1463
|
-
return someWeeksAgo(weeks);
|
|
1464
|
-
}
|
|
1465
|
-
if (seconds < year) {
|
|
1466
|
-
const months = Math.floor(seconds / month);
|
|
1467
|
-
if (months === 1) {
|
|
1468
|
-
return oneMonthAgo();
|
|
1469
|
-
}
|
|
1470
|
-
return someMonthsAgo(months);
|
|
1471
|
-
}
|
|
1472
|
-
const years = Math.floor(seconds / year);
|
|
1473
|
-
if (years === 1) {
|
|
1474
|
-
return oneYearAgo();
|
|
1475
|
-
}
|
|
1476
|
-
return someYearsAgo(years);
|
|
1545
|
+
return formatRelativeDate(seconds, ranges);
|
|
1477
1546
|
};
|
|
1478
1547
|
|
|
1479
1548
|
// based on https://github.com/microsoft/vscode/blob/bd782eb059e133d3a20fdb446b8feb0010a278ad/src/vs/base/common/date.ts (License MIT)
|
|
@@ -1880,7 +1949,7 @@ const commandMap = {
|
|
|
1880
1949
|
|
|
1881
1950
|
const listen = async () => {
|
|
1882
1951
|
registerCommands(commandMap);
|
|
1883
|
-
const rpc = await
|
|
1952
|
+
const rpc = await create$3({
|
|
1884
1953
|
commandMap: commandMap
|
|
1885
1954
|
});
|
|
1886
1955
|
set$1(rpc);
|