@lvce-editor/title-bar-worker 3.7.0 → 3.9.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 +209 -32
- 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');
|
|
@@ -1382,6 +1518,18 @@ const createDefaultState = (uid = DEFAULT_UID) => ({
|
|
|
1382
1518
|
y: 0
|
|
1383
1519
|
});
|
|
1384
1520
|
|
|
1521
|
+
const HandleClick = 1;
|
|
1522
|
+
const HandleClickMinimize = 2;
|
|
1523
|
+
const HandleClickClose = 3;
|
|
1524
|
+
const HandleClickToggleMaximize = 4;
|
|
1525
|
+
const HandleFocusIn = 5;
|
|
1526
|
+
const HandleFocusOut = 6;
|
|
1527
|
+
const HandlePointerOut = 7;
|
|
1528
|
+
const HandlePointerOver = 8;
|
|
1529
|
+
const HandleMenuClick = 9;
|
|
1530
|
+
const HandleMenuMouseOver = 10;
|
|
1531
|
+
const HandleContextMenu = 11;
|
|
1532
|
+
|
|
1385
1533
|
const emptyObject = {};
|
|
1386
1534
|
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
1387
1535
|
const i18nString = (key, placeholders = emptyObject) => {
|
|
@@ -1511,17 +1659,17 @@ const getTitleBarButtonsElectron = (controlsOverlayEnabled, titleBarStyleCustom)
|
|
|
1511
1659
|
icon: 'Minimize',
|
|
1512
1660
|
id: 'Minimize',
|
|
1513
1661
|
label: minimize$1(),
|
|
1514
|
-
onClick:
|
|
1662
|
+
onClick: HandleClickMinimize
|
|
1515
1663
|
}, {
|
|
1516
1664
|
icon: 'Maximize',
|
|
1517
1665
|
id: 'ToggleMaximize',
|
|
1518
1666
|
label: maximize$1(),
|
|
1519
|
-
onClick:
|
|
1667
|
+
onClick: HandleClickToggleMaximize
|
|
1520
1668
|
}, {
|
|
1521
1669
|
icon: 'ChromeClose',
|
|
1522
1670
|
id: 'Close',
|
|
1523
1671
|
label: close$1(),
|
|
1524
|
-
onClick:
|
|
1672
|
+
onClick: HandleClickClose
|
|
1525
1673
|
}];
|
|
1526
1674
|
}
|
|
1527
1675
|
return [];
|
|
@@ -2228,12 +2376,13 @@ const getMenuEntries2 = async (state, props) => {
|
|
|
2228
2376
|
}
|
|
2229
2377
|
};
|
|
2230
2378
|
|
|
2231
|
-
const getEntryMap = async (state, menuIds) => {
|
|
2379
|
+
const getEntryMap = async (state, menuIds, platform) => {
|
|
2232
2380
|
const map = Object.create(null);
|
|
2233
2381
|
for (const id of menuIds) {
|
|
2234
2382
|
const entries = await getMenuEntries2(state, {
|
|
2235
2383
|
// @ts-ignore
|
|
2236
|
-
menuId: id
|
|
2384
|
+
menuId: id,
|
|
2385
|
+
platform
|
|
2237
2386
|
});
|
|
2238
2387
|
map[id] = entries;
|
|
2239
2388
|
}
|
|
@@ -2385,8 +2534,11 @@ const setItems = async items => {
|
|
|
2385
2534
|
return invoke('WebView.compatSharedProcessInvoke', 'ElectronApplicationMenu.setItems', windowId, items);
|
|
2386
2535
|
};
|
|
2387
2536
|
const hydrate = async state => {
|
|
2537
|
+
const {
|
|
2538
|
+
platform
|
|
2539
|
+
} = state;
|
|
2388
2540
|
const ids = getMenuIds();
|
|
2389
|
-
const map = await getEntryMap(state, ids);
|
|
2541
|
+
const map = await getEntryMap(state, ids, platform);
|
|
2390
2542
|
const {
|
|
2391
2543
|
commandMap,
|
|
2392
2544
|
electronMenu
|
|
@@ -2812,7 +2964,34 @@ const getFontString = (fontWeight, fontSize, fontFamily) => {
|
|
|
2812
2964
|
return `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
2813
2965
|
};
|
|
2814
2966
|
|
|
2815
|
-
const
|
|
2967
|
+
const launchTextMeasurementWorker = async () => {
|
|
2968
|
+
const rpc = await TransferMessagePortRpcParent.create({
|
|
2969
|
+
commandMap: {},
|
|
2970
|
+
async send(port) {
|
|
2971
|
+
await sendMessagePortToTextMeasurementWorker(port);
|
|
2972
|
+
}
|
|
2973
|
+
});
|
|
2974
|
+
return {
|
|
2975
|
+
invoke: rpc.invoke.bind(rpc),
|
|
2976
|
+
async [Symbol.asyncDispose]() {
|
|
2977
|
+
await rpc.dispose();
|
|
2978
|
+
}
|
|
2979
|
+
};
|
|
2980
|
+
};
|
|
2981
|
+
|
|
2982
|
+
const measureTextWidths2 = async (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2983
|
+
if (typeof letterSpacing !== 'number') {
|
|
2984
|
+
throw new TypeError('letterSpacing must be of type number');
|
|
2985
|
+
}
|
|
2986
|
+
await using rpc = await launchTextMeasurementWorker();
|
|
2987
|
+
const isMonospaceFont = false;
|
|
2988
|
+
const charWidth = 0;
|
|
2989
|
+
// @ts-ignore
|
|
2990
|
+
const result = await rpc.invoke('TextMeasurement.measureTextWidths', texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
|
|
2991
|
+
return result;
|
|
2992
|
+
};
|
|
2993
|
+
|
|
2994
|
+
const measureTextWidthsOld = async (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2816
2995
|
if (typeof letterSpacing !== 'number') {
|
|
2817
2996
|
throw new TypeError('letterSpacing must be of type number');
|
|
2818
2997
|
}
|
|
@@ -2829,13 +3008,20 @@ const measureTextWidths = (texts, fontWeight, fontSize, fontFamily, letterSpacin
|
|
|
2829
3008
|
}
|
|
2830
3009
|
return widths;
|
|
2831
3010
|
};
|
|
3011
|
+
const measureTextWidths = async (texts, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
3012
|
+
try {
|
|
3013
|
+
return measureTextWidths2(texts, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
3014
|
+
} catch {
|
|
3015
|
+
return measureTextWidthsOld(texts, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
3016
|
+
}
|
|
3017
|
+
};
|
|
2832
3018
|
|
|
2833
3019
|
const getLabel = entry => {
|
|
2834
3020
|
return entry.label;
|
|
2835
3021
|
};
|
|
2836
|
-
const addWidths = (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
3022
|
+
const addWidths = async (entries, labelPadding, fontWeight, fontSize, fontFamily, letterSpacing) => {
|
|
2837
3023
|
const labels = entries.map(getLabel);
|
|
2838
|
-
const widths = measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
3024
|
+
const widths = await measureTextWidths(labels, fontWeight, fontSize, fontFamily, letterSpacing);
|
|
2839
3025
|
const withWidths = [];
|
|
2840
3026
|
for (let i = 0; i < entries.length; i++) {
|
|
2841
3027
|
const entry = entries[i];
|
|
@@ -2873,12 +3059,15 @@ const loadContent2 = async state => {
|
|
|
2873
3059
|
titleBarStyleCustom
|
|
2874
3060
|
} = state;
|
|
2875
3061
|
const titleBarEntries = await getMenuEntries$2(platform);
|
|
2876
|
-
const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
3062
|
+
const withWidths = await addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
|
|
2877
3063
|
const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
|
|
2878
3064
|
const workspaceUri = await invoke('Workspace.getUri');
|
|
2879
3065
|
const title = getTitle(workspaceUri);
|
|
2880
3066
|
const iconWidth = 30;
|
|
2881
|
-
|
|
3067
|
+
|
|
3068
|
+
// TODO load preferences here
|
|
3069
|
+
|
|
3070
|
+
if (titleBarStyleCustom === false && platform === Electron$1) {
|
|
2882
3071
|
return hydrate(state);
|
|
2883
3072
|
}
|
|
2884
3073
|
return {
|
|
@@ -3215,18 +3404,6 @@ const getTitleBarIconVirtualDom = (titleBarIconEnabled, iconSrc) => {
|
|
|
3215
3404
|
}];
|
|
3216
3405
|
};
|
|
3217
3406
|
|
|
3218
|
-
const HandleClick = 1;
|
|
3219
|
-
const HandleClickMinimize = 2;
|
|
3220
|
-
const HandleClickToggleClose = 3;
|
|
3221
|
-
const HandleClickToggleMaximize = 4;
|
|
3222
|
-
const HandleFocusIn = 5;
|
|
3223
|
-
const HandleFocusOut = 6;
|
|
3224
|
-
const HandlePointerOut = 7;
|
|
3225
|
-
const HandlePointerOver = 8;
|
|
3226
|
-
const HandleMenuClick = 9;
|
|
3227
|
-
const HandleMenuMouseOver = 10;
|
|
3228
|
-
const HandleContextMenu = 11;
|
|
3229
|
-
|
|
3230
3407
|
const getItemVirtualDom = item => {
|
|
3231
3408
|
// @ts-ignore
|
|
3232
3409
|
const {
|
|
@@ -3349,7 +3526,7 @@ const getTitleBarVirtualDom = state => {
|
|
|
3349
3526
|
titleBarTitleEnabled,
|
|
3350
3527
|
width
|
|
3351
3528
|
} = state;
|
|
3352
|
-
if (titleBarStyleCustom) {
|
|
3529
|
+
if (!titleBarStyleCustom) {
|
|
3353
3530
|
return [{
|
|
3354
3531
|
childCount: 0,
|
|
3355
3532
|
type: Div$1
|
|
@@ -3411,7 +3588,7 @@ const renderEventListeners = () => {
|
|
|
3411
3588
|
name: HandleContextMenu,
|
|
3412
3589
|
params: ['handleContextMenu', Button$1, ClientX, ClientY]
|
|
3413
3590
|
}, {
|
|
3414
|
-
name:
|
|
3591
|
+
name: HandleClickClose,
|
|
3415
3592
|
params: ['handleClickClose']
|
|
3416
3593
|
}, {
|
|
3417
3594
|
name: HandleClickToggleMaximize,
|