@lvce-editor/title-bar-worker 3.6.0 → 3.8.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/titleBarWorkerMain.js +214 -21
- package/package.json +1 -1
|
@@ -423,9 +423,103 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
423
423
|
listen: listen$6,
|
|
424
424
|
wrap: wrap$e
|
|
425
425
|
};
|
|
426
|
+
const addListener = (emitter, type, callback) => {
|
|
427
|
+
if ('addEventListener' in emitter) {
|
|
428
|
+
emitter.addEventListener(type, callback);
|
|
429
|
+
} else {
|
|
430
|
+
emitter.on(type, callback);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const removeListener = (emitter, type, callback) => {
|
|
434
|
+
if ('removeEventListener' in emitter) {
|
|
435
|
+
emitter.removeEventListener(type, callback);
|
|
436
|
+
} else {
|
|
437
|
+
emitter.off(type, callback);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
441
|
+
const {
|
|
442
|
+
promise,
|
|
443
|
+
resolve
|
|
444
|
+
} = Promise.withResolvers();
|
|
445
|
+
const listenerMap = Object.create(null);
|
|
446
|
+
const cleanup = value => {
|
|
447
|
+
for (const event of Object.keys(eventMap)) {
|
|
448
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
449
|
+
}
|
|
450
|
+
resolve(value);
|
|
451
|
+
};
|
|
452
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
453
|
+
const listener = event => {
|
|
454
|
+
cleanup({
|
|
455
|
+
event,
|
|
456
|
+
type
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
addListener(eventEmitter, event, listener);
|
|
460
|
+
listenerMap[event] = listener;
|
|
461
|
+
}
|
|
462
|
+
return promise;
|
|
463
|
+
};
|
|
464
|
+
const Message$1 = 3;
|
|
465
|
+
const create$5$1 = async ({
|
|
466
|
+
isMessagePortOpen,
|
|
467
|
+
messagePort
|
|
468
|
+
}) => {
|
|
469
|
+
if (!isMessagePort(messagePort)) {
|
|
470
|
+
throw new IpcError('port must be of type MessagePort');
|
|
471
|
+
}
|
|
472
|
+
if (isMessagePortOpen) {
|
|
473
|
+
return messagePort;
|
|
474
|
+
}
|
|
475
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
476
|
+
message: Message$1
|
|
477
|
+
});
|
|
478
|
+
messagePort.start();
|
|
479
|
+
const {
|
|
480
|
+
event,
|
|
481
|
+
type
|
|
482
|
+
} = await eventPromise;
|
|
483
|
+
if (type !== Message$1) {
|
|
484
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
485
|
+
}
|
|
486
|
+
if (event.data !== readyMessage) {
|
|
487
|
+
throw new IpcError('unexpected first message');
|
|
488
|
+
}
|
|
489
|
+
return messagePort;
|
|
490
|
+
};
|
|
491
|
+
const signal$1 = messagePort => {
|
|
492
|
+
messagePort.start();
|
|
493
|
+
};
|
|
494
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
495
|
+
getData = getData$2;
|
|
496
|
+
send(message) {
|
|
497
|
+
this._rawIpc.postMessage(message);
|
|
498
|
+
}
|
|
499
|
+
sendAndTransfer(message) {
|
|
500
|
+
const transfer = getTransferrables(message);
|
|
501
|
+
this._rawIpc.postMessage(message, transfer);
|
|
502
|
+
}
|
|
503
|
+
dispose() {
|
|
504
|
+
this._rawIpc.close();
|
|
505
|
+
}
|
|
506
|
+
onMessage(callback) {
|
|
507
|
+
this._rawIpc.addEventListener('message', callback);
|
|
508
|
+
}
|
|
509
|
+
onClose(callback) {}
|
|
510
|
+
}
|
|
511
|
+
const wrap$5 = messagePort => {
|
|
512
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
513
|
+
};
|
|
514
|
+
const IpcParentWithMessagePort$1 = {
|
|
515
|
+
__proto__: null,
|
|
516
|
+
create: create$5$1,
|
|
517
|
+
signal: signal$1,
|
|
518
|
+
wrap: wrap$5
|
|
519
|
+
};
|
|
426
520
|
|
|
427
521
|
const Two = '2.0';
|
|
428
|
-
const create$4 = (method, params) => {
|
|
522
|
+
const create$4$1 = (method, params) => {
|
|
429
523
|
return {
|
|
430
524
|
jsonrpc: Two,
|
|
431
525
|
method,
|
|
@@ -680,7 +774,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
680
774
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
681
775
|
return create$1$1(id, errorProperty);
|
|
682
776
|
};
|
|
683
|
-
const create$
|
|
777
|
+
const create$6 = (message, result) => {
|
|
684
778
|
return {
|
|
685
779
|
jsonrpc: Two,
|
|
686
780
|
id: message.id,
|
|
@@ -689,7 +783,7 @@ const create$5 = (message, result) => {
|
|
|
689
783
|
};
|
|
690
784
|
const getSuccessResponse = (message, result) => {
|
|
691
785
|
const resultProperty = result ?? null;
|
|
692
|
-
return create$
|
|
786
|
+
return create$6(message, resultProperty);
|
|
693
787
|
};
|
|
694
788
|
const getErrorResponseSimple = (id, error) => {
|
|
695
789
|
return {
|
|
@@ -794,13 +888,13 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
794
888
|
return unwrapJsonRpcResult(responseMessage);
|
|
795
889
|
};
|
|
796
890
|
const send = (transport, method, ...params) => {
|
|
797
|
-
const message = create$4(method, params);
|
|
891
|
+
const message = create$4$1(method, params);
|
|
798
892
|
transport.send(message);
|
|
799
893
|
};
|
|
800
894
|
const invoke$1 = (ipc, method, ...params) => {
|
|
801
895
|
return invokeHelper(ipc, method, params, false);
|
|
802
896
|
};
|
|
803
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
897
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
804
898
|
return invokeHelper(ipc, method, params, true);
|
|
805
899
|
};
|
|
806
900
|
|
|
@@ -839,7 +933,7 @@ const createRpc = ipc => {
|
|
|
839
933
|
return invoke$1(ipc, method, ...params);
|
|
840
934
|
},
|
|
841
935
|
invokeAndTransfer(method, ...params) {
|
|
842
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
936
|
+
return invokeAndTransfer$1(ipc, method, ...params);
|
|
843
937
|
},
|
|
844
938
|
async dispose() {
|
|
845
939
|
await ipc?.dispose();
|
|
@@ -877,7 +971,41 @@ const listen$1 = async (module, options) => {
|
|
|
877
971
|
const ipc = module.wrap(rawIpc);
|
|
878
972
|
return ipc;
|
|
879
973
|
};
|
|
974
|
+
const create$5 = async ({
|
|
975
|
+
commandMap,
|
|
976
|
+
messagePort
|
|
977
|
+
}) => {
|
|
978
|
+
// TODO create a commandMap per rpc instance
|
|
979
|
+
register(commandMap);
|
|
980
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
981
|
+
messagePort,
|
|
982
|
+
isMessagePortOpen: true
|
|
983
|
+
});
|
|
984
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
985
|
+
handleIpc(ipc);
|
|
986
|
+
const rpc = createRpc(ipc);
|
|
987
|
+
messagePort.start();
|
|
988
|
+
return rpc;
|
|
989
|
+
};
|
|
880
990
|
const create$3 = async ({
|
|
991
|
+
commandMap,
|
|
992
|
+
send
|
|
993
|
+
}) => {
|
|
994
|
+
const {
|
|
995
|
+
port1,
|
|
996
|
+
port2
|
|
997
|
+
} = new MessageChannel();
|
|
998
|
+
await send(port1);
|
|
999
|
+
return create$5({
|
|
1000
|
+
commandMap,
|
|
1001
|
+
messagePort: port2
|
|
1002
|
+
});
|
|
1003
|
+
};
|
|
1004
|
+
const TransferMessagePortRpcParent = {
|
|
1005
|
+
__proto__: null,
|
|
1006
|
+
create: create$3
|
|
1007
|
+
};
|
|
1008
|
+
const create$4 = async ({
|
|
881
1009
|
commandMap
|
|
882
1010
|
}) => {
|
|
883
1011
|
// TODO create a commandMap per rpc instance
|
|
@@ -889,7 +1017,7 @@ const create$3 = async ({
|
|
|
889
1017
|
};
|
|
890
1018
|
const WebWorkerRpcClient = {
|
|
891
1019
|
__proto__: null,
|
|
892
|
-
create: create$
|
|
1020
|
+
create: create$4
|
|
893
1021
|
};
|
|
894
1022
|
|
|
895
1023
|
const ContentInfo = 'contentinfo';
|
|
@@ -1196,6 +1324,8 @@ const parseKey = rawKey => {
|
|
|
1196
1324
|
};
|
|
1197
1325
|
};
|
|
1198
1326
|
|
|
1327
|
+
const Electron$1 = 2;
|
|
1328
|
+
|
|
1199
1329
|
const RendererWorker = 1;
|
|
1200
1330
|
|
|
1201
1331
|
const FocusTitleBarMenuBar = 26;
|
|
@@ -1234,8 +1364,34 @@ const create$2 = rpcId => {
|
|
|
1234
1364
|
|
|
1235
1365
|
const {
|
|
1236
1366
|
invoke,
|
|
1367
|
+
invokeAndTransfer,
|
|
1237
1368
|
set: set$1
|
|
1238
1369
|
} = create$2(RendererWorker);
|
|
1370
|
+
const showContextMenu2 = async (uid, menuId, x, y, args) => {
|
|
1371
|
+
number(uid);
|
|
1372
|
+
number(menuId);
|
|
1373
|
+
number(x);
|
|
1374
|
+
number(y);
|
|
1375
|
+
// @ts-ignore
|
|
1376
|
+
await invoke('ContextMenu.show2', uid, menuId, x, y, args);
|
|
1377
|
+
};
|
|
1378
|
+
const sendMessagePortToTextMeasurementWorker = async port => {
|
|
1379
|
+
const command = 'TextMeasurement.handleMessagePort';
|
|
1380
|
+
// @ts-ignore
|
|
1381
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToTextMeasurementWorker', port, command, 0);
|
|
1382
|
+
};
|
|
1383
|
+
const minimizeWindow = async () => {
|
|
1384
|
+
// @ts-ignore
|
|
1385
|
+
return invoke('ElectronWindow.minimize');
|
|
1386
|
+
};
|
|
1387
|
+
const maximizeWindow = async () => {
|
|
1388
|
+
// @ts-ignore
|
|
1389
|
+
return invoke('ElectronWindow.maximize');
|
|
1390
|
+
};
|
|
1391
|
+
const closeWindow = async () => {
|
|
1392
|
+
// @ts-ignore
|
|
1393
|
+
return invoke('ElectronWindow.close');
|
|
1394
|
+
};
|
|
1239
1395
|
|
|
1240
1396
|
const toCommandId = key => {
|
|
1241
1397
|
const dotIndex = key.indexOf('.');
|
|
@@ -2208,12 +2364,13 @@ const getMenuEntries2 = async (state, props) => {
|
|
|
2208
2364
|
}
|
|
2209
2365
|
};
|
|
2210
2366
|
|
|
2211
|
-
const getEntryMap = async (state, menuIds) => {
|
|
2367
|
+
const getEntryMap = async (state, menuIds, platform) => {
|
|
2212
2368
|
const map = Object.create(null);
|
|
2213
2369
|
for (const id of menuIds) {
|
|
2214
2370
|
const entries = await getMenuEntries2(state, {
|
|
2215
2371
|
// @ts-ignore
|
|
2216
|
-
menuId: id
|
|
2372
|
+
menuId: id,
|
|
2373
|
+
platform
|
|
2217
2374
|
});
|
|
2218
2375
|
map[id] = entries;
|
|
2219
2376
|
}
|
|
@@ -2365,8 +2522,11 @@ const setItems = async items => {
|
|
|
2365
2522
|
return invoke('WebView.compatSharedProcessInvoke', 'ElectronApplicationMenu.setItems', windowId, items);
|
|
2366
2523
|
};
|
|
2367
2524
|
const hydrate = async state => {
|
|
2525
|
+
const {
|
|
2526
|
+
platform
|
|
2527
|
+
} = state;
|
|
2368
2528
|
const ids = getMenuIds();
|
|
2369
|
-
const map = await getEntryMap(state, ids);
|
|
2529
|
+
const map = await getEntryMap(state, ids, platform);
|
|
2370
2530
|
const {
|
|
2371
2531
|
commandMap,
|
|
2372
2532
|
electronMenu
|
|
@@ -2457,13 +2617,13 @@ const getKeyBindings = () => {
|
|
|
2457
2617
|
};
|
|
2458
2618
|
|
|
2459
2619
|
const maximize = async () => {
|
|
2460
|
-
await
|
|
2620
|
+
await maximizeWindow();
|
|
2461
2621
|
};
|
|
2462
2622
|
const minimize = async () => {
|
|
2463
|
-
await
|
|
2623
|
+
await minimizeWindow();
|
|
2464
2624
|
};
|
|
2465
2625
|
const close = async () => {
|
|
2466
|
-
await
|
|
2626
|
+
await closeWindow();
|
|
2467
2627
|
};
|
|
2468
2628
|
|
|
2469
2629
|
const handleClickClose = async state => {
|
|
@@ -2497,8 +2657,7 @@ const handleClick$1 = async (state, className) => {
|
|
|
2497
2657
|
};
|
|
2498
2658
|
|
|
2499
2659
|
const show2 = async (uid, menuId, x, y, args) => {
|
|
2500
|
-
|
|
2501
|
-
await invoke('ContextMenu.show2', uid, menuId, x, y, args);
|
|
2660
|
+
await showContextMenu2(uid, menuId, x, y, args);
|
|
2502
2661
|
};
|
|
2503
2662
|
|
|
2504
2663
|
const handleContextMenu = async (state, button, eventX, eventY) => {
|
|
@@ -2793,7 +2952,34 @@ const getFontString = (fontWeight, fontSize, fontFamily) => {
|
|
|
2793
2952
|
return `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
2794
2953
|
};
|
|
2795
2954
|
|
|
2796
|
-
const
|
|
2955
|
+
const launchTextMeasurementWorker = async () => {
|
|
2956
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
2957
|
+
commandMap: {},
|
|
2958
|
+
async send(port) {
|
|
2959
|
+
await sendMessagePortToTextMeasurementWorker(port);
|
|
2960
|
+
}
|
|
2961
|
+
});
|
|
2962
|
+
return {
|
|
2963
|
+
invoke: rpc.invoke.bind(rpc),
|
|
2964
|
+
async [Symbol.asyncDispose]() {
|
|
2965
|
+
await rpc.dispose();
|
|
2966
|
+
}
|
|
2967
|
+
};
|
|
2968
|
+
};
|
|
2969
|
+
|
|
2970
|
+
const measureTextWidths2 = async (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2971
|
+
if (typeof letterSpacing !== 'number') {
|
|
2972
|
+
throw new TypeError('letterSpacing must be of type number');
|
|
2973
|
+
}
|
|
2974
|
+
await using rpc = await launchTextMeasurementWorker();
|
|
2975
|
+
const isMonospaceFont = false;
|
|
2976
|
+
const charWidth = 0;
|
|
2977
|
+
// @ts-ignore
|
|
2978
|
+
const result = await rpc.invoke('TextMeasurement.measureTextWidths', texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
|
|
2979
|
+
return result;
|
|
2980
|
+
};
|
|
2981
|
+
|
|
2982
|
+
const measureTextWidthsOld = async (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2797
2983
|
if (typeof letterSpacing !== 'number') {
|
|
2798
2984
|
throw new TypeError('letterSpacing must be of type number');
|
|
2799
2985
|
}
|
|
@@ -2810,13 +2996,20 @@ const measureTextWidths = (texts, fontWeight, fontSize, fontFamily, letterSpacin
|
|
|
2810
2996
|
}
|
|
2811
2997
|
return widths;
|
|
2812
2998
|
};
|
|
2999
|
+
const measureTextWidths = async (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
3000
|
+
try {
|
|
3001
|
+
return measureTextWidths2(texts, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
3002
|
+
} catch {
|
|
3003
|
+
return measureTextWidthsOld(texts, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
3004
|
+
}
|
|
3005
|
+
};
|
|
2813
3006
|
|
|
2814
3007
|
const getLabel = entry => {
|
|
2815
3008
|
return entry.label;
|
|
2816
3009
|
};
|
|
2817
|
-
const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
3010
|
+
const addWidths = async (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2818
3011
|
const labels = entries.map(getLabel);
|
|
2819
|
-
const widths = measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
3012
|
+
const widths = await measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
2820
3013
|
const withWidths = [];
|
|
2821
3014
|
for (let i = 0; i < entries.length; i++) {
|
|
2822
3015
|
const entry = entries[i];
|
|
@@ -2854,12 +3047,12 @@ const loadContent2 = async state => {
|
|
|
2854
3047
|
titleBarStyleCustom
|
|
2855
3048
|
} = state;
|
|
2856
3049
|
const titleBarEntries = await getMenuEntries$2(platform);
|
|
2857
|
-
const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
3050
|
+
const withWidths = await addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
2858
3051
|
const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
|
|
2859
3052
|
const workspaceUri = await invoke('Workspace.getUri');
|
|
2860
3053
|
const title = getTitle(workspaceUri);
|
|
2861
3054
|
const iconWidth = 30;
|
|
2862
|
-
if (titleBarStyleCustom === false) {
|
|
3055
|
+
if (titleBarStyleCustom === false && platform === Electron$1) {
|
|
2863
3056
|
return hydrate(state);
|
|
2864
3057
|
}
|
|
2865
3058
|
return {
|
|
@@ -3330,7 +3523,7 @@ const getTitleBarVirtualDom = state => {
|
|
|
3330
3523
|
titleBarTitleEnabled,
|
|
3331
3524
|
width
|
|
3332
3525
|
} = state;
|
|
3333
|
-
if (titleBarStyleCustom) {
|
|
3526
|
+
if (!titleBarStyleCustom) {
|
|
3334
3527
|
return [{
|
|
3335
3528
|
childCount: 0,
|
|
3336
3529
|
type: Div$1
|