@lvce-editor/title-bar-worker 3.7.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 +190 -16
- 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,6 +1364,7 @@ const create$2 = rpcId => {
|
|
|
1234
1364
|
|
|
1235
1365
|
const {
|
|
1236
1366
|
invoke,
|
|
1367
|
+
invokeAndTransfer,
|
|
1237
1368
|
set: set$1
|
|
1238
1369
|
} = create$2(RendererWorker);
|
|
1239
1370
|
const showContextMenu2 = async (uid, menuId, x, y, args) => {
|
|
@@ -1244,6 +1375,11 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
|
|
|
1244
1375
|
// @ts-ignore
|
|
1245
1376
|
await invoke('ContextMenu.show2', uid, menuId, x, y, args);
|
|
1246
1377
|
};
|
|
1378
|
+
const sendMessagePortToTextMeasurementWorker = async port => {
|
|
1379
|
+
const command = 'TextMeasurement.handleMessagePort';
|
|
1380
|
+
// @ts-ignore
|
|
1381
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToTextMeasurementWorker', port, command, 0);
|
|
1382
|
+
};
|
|
1247
1383
|
const minimizeWindow = async () => {
|
|
1248
1384
|
// @ts-ignore
|
|
1249
1385
|
return invoke('ElectronWindow.minimize');
|
|
@@ -2228,12 +2364,13 @@ const getMenuEntries2 = async (state, props) => {
|
|
|
2228
2364
|
}
|
|
2229
2365
|
};
|
|
2230
2366
|
|
|
2231
|
-
const getEntryMap = async (state, menuIds) => {
|
|
2367
|
+
const getEntryMap = async (state, menuIds, platform) => {
|
|
2232
2368
|
const map = Object.create(null);
|
|
2233
2369
|
for (const id of menuIds) {
|
|
2234
2370
|
const entries = await getMenuEntries2(state, {
|
|
2235
2371
|
// @ts-ignore
|
|
2236
|
-
menuId: id
|
|
2372
|
+
menuId: id,
|
|
2373
|
+
platform
|
|
2237
2374
|
});
|
|
2238
2375
|
map[id] = entries;
|
|
2239
2376
|
}
|
|
@@ -2385,8 +2522,11 @@ const setItems = async items => {
|
|
|
2385
2522
|
return invoke('WebView.compatSharedProcessInvoke', 'ElectronApplicationMenu.setItems', windowId, items);
|
|
2386
2523
|
};
|
|
2387
2524
|
const hydrate = async state => {
|
|
2525
|
+
const {
|
|
2526
|
+
platform
|
|
2527
|
+
} = state;
|
|
2388
2528
|
const ids = getMenuIds();
|
|
2389
|
-
const map = await getEntryMap(state, ids);
|
|
2529
|
+
const map = await getEntryMap(state, ids, platform);
|
|
2390
2530
|
const {
|
|
2391
2531
|
commandMap,
|
|
2392
2532
|
electronMenu
|
|
@@ -2812,7 +2952,34 @@ const getFontString = (fontWeight, fontSize, fontFamily) => {
|
|
|
2812
2952
|
return `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
2813
2953
|
};
|
|
2814
2954
|
|
|
2815
|
-
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) => {
|
|
2816
2983
|
if (typeof letterSpacing !== 'number') {
|
|
2817
2984
|
throw new TypeError('letterSpacing must be of type number');
|
|
2818
2985
|
}
|
|
@@ -2829,13 +2996,20 @@ const measureTextWidths = (texts, fontWeight, fontSize, fontFamily, letterSpacin
|
|
|
2829
2996
|
}
|
|
2830
2997
|
return widths;
|
|
2831
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
|
+
};
|
|
2832
3006
|
|
|
2833
3007
|
const getLabel = entry => {
|
|
2834
3008
|
return entry.label;
|
|
2835
3009
|
};
|
|
2836
|
-
const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
3010
|
+
const addWidths = async (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2837
3011
|
const labels = entries.map(getLabel);
|
|
2838
|
-
const widths = measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
3012
|
+
const widths = await measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
2839
3013
|
const withWidths = [];
|
|
2840
3014
|
for (let i = 0; i < entries.length; i++) {
|
|
2841
3015
|
const entry = entries[i];
|
|
@@ -2873,12 +3047,12 @@ const loadContent2 = async state => {
|
|
|
2873
3047
|
titleBarStyleCustom
|
|
2874
3048
|
} = state;
|
|
2875
3049
|
const titleBarEntries = await getMenuEntries$2(platform);
|
|
2876
|
-
const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
3050
|
+
const withWidths = await addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
2877
3051
|
const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
|
|
2878
3052
|
const workspaceUri = await invoke('Workspace.getUri');
|
|
2879
3053
|
const title = getTitle(workspaceUri);
|
|
2880
3054
|
const iconWidth = 30;
|
|
2881
|
-
if (titleBarStyleCustom === false) {
|
|
3055
|
+
if (titleBarStyleCustom === false && platform === Electron$1) {
|
|
2882
3056
|
return hydrate(state);
|
|
2883
3057
|
}
|
|
2884
3058
|
return {
|
|
@@ -3349,7 +3523,7 @@ const getTitleBarVirtualDom = state => {
|
|
|
3349
3523
|
titleBarTitleEnabled,
|
|
3350
3524
|
width
|
|
3351
3525
|
} = state;
|
|
3352
|
-
if (titleBarStyleCustom) {
|
|
3526
|
+
if (!titleBarStyleCustom) {
|
|
3353
3527
|
return [{
|
|
3354
3528
|
childCount: 0,
|
|
3355
3529
|
type: Div$1
|