@lvce-editor/renderer-process 8.7.0 → 9.1.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/rendererProcessMain.js +123 -51
- package/package.json +1 -1
|
@@ -513,13 +513,13 @@ const number$1 = value => {
|
|
|
513
513
|
const state$1$1 = {
|
|
514
514
|
callbacks: Object.create(null)
|
|
515
515
|
};
|
|
516
|
-
const set$
|
|
516
|
+
const set$7 = (id, fn) => {
|
|
517
517
|
state$1$1.callbacks[id] = fn;
|
|
518
518
|
};
|
|
519
|
-
const get$
|
|
519
|
+
const get$8 = id => {
|
|
520
520
|
return state$1$1.callbacks[id];
|
|
521
521
|
};
|
|
522
|
-
const remove$
|
|
522
|
+
const remove$3 = id => {
|
|
523
523
|
delete state$1$1.callbacks[id];
|
|
524
524
|
};
|
|
525
525
|
const state$a = {
|
|
@@ -550,7 +550,7 @@ const registerPromise = () => {
|
|
|
550
550
|
resolve,
|
|
551
551
|
promise
|
|
552
552
|
} = withResolvers$2();
|
|
553
|
-
set$
|
|
553
|
+
set$7(id, resolve);
|
|
554
554
|
return {
|
|
555
555
|
id,
|
|
556
556
|
promise
|
|
@@ -558,14 +558,14 @@ const registerPromise = () => {
|
|
|
558
558
|
};
|
|
559
559
|
const resolve = (id, args) => {
|
|
560
560
|
number$1(id);
|
|
561
|
-
const fn = get$
|
|
561
|
+
const fn = get$8(id);
|
|
562
562
|
if (!fn) {
|
|
563
563
|
console.log(args);
|
|
564
564
|
warn$1(`callback ${id} may already be disposed`);
|
|
565
565
|
return;
|
|
566
566
|
}
|
|
567
567
|
fn(args);
|
|
568
|
-
remove$
|
|
568
|
+
remove$3(id);
|
|
569
569
|
};
|
|
570
570
|
const create$2$1 = (method, params) => {
|
|
571
571
|
const {
|
|
@@ -861,7 +861,7 @@ const preparePrettyError = error => {
|
|
|
861
861
|
return error;
|
|
862
862
|
};
|
|
863
863
|
const logError$1 = error => {
|
|
864
|
-
|
|
864
|
+
// error is logged in renderer worker
|
|
865
865
|
};
|
|
866
866
|
const handleMessage = event => {
|
|
867
867
|
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError$1, requiresSocket);
|
|
@@ -908,10 +908,54 @@ const getModule$1 = method => {
|
|
|
908
908
|
}
|
|
909
909
|
};
|
|
910
910
|
|
|
911
|
+
const hasFlag = key => {
|
|
912
|
+
if (typeof location === 'undefined' || typeof document === 'undefined') {
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
915
|
+
const configElement = document.getElementById('Config');
|
|
916
|
+
if (!configElement) {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
const text = configElement.textContent;
|
|
920
|
+
if (!text) {
|
|
921
|
+
return false;
|
|
922
|
+
}
|
|
923
|
+
const config = JSON.parse(text);
|
|
924
|
+
const result = config[key];
|
|
925
|
+
return result;
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
const shouldLaunchMultipleWorkers = hasFlag('prelaunchWorkers');
|
|
929
|
+
|
|
930
|
+
const ipcs = Object.create(null);
|
|
931
|
+
const set$6 = (name, ipc) => {
|
|
932
|
+
ipcs[name] = ipc;
|
|
933
|
+
};
|
|
934
|
+
const get$7 = name => {
|
|
935
|
+
return ipcs[name];
|
|
936
|
+
};
|
|
937
|
+
const remove$2 = name => {
|
|
938
|
+
delete ipcs[name];
|
|
939
|
+
};
|
|
940
|
+
const has = name => {
|
|
941
|
+
return ipcs[name];
|
|
942
|
+
};
|
|
943
|
+
|
|
911
944
|
const create$K = async ({
|
|
912
945
|
method,
|
|
913
946
|
...options
|
|
914
947
|
}) => {
|
|
948
|
+
if (shouldLaunchMultipleWorkers && options.name && has(options.name)) {
|
|
949
|
+
if (!options.id) {
|
|
950
|
+
throw new Error('id is required');
|
|
951
|
+
}
|
|
952
|
+
// TODO rename method
|
|
953
|
+
// TODO avoid cyclic dependency
|
|
954
|
+
const port = get$7(options.name);
|
|
955
|
+
remove$2(options.name);
|
|
956
|
+
await invokeAndTransfer('Transferrable.transfer', options.id, port);
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
915
959
|
const module = await getModule$1(method);
|
|
916
960
|
// @ts-ignore
|
|
917
961
|
return module.create(options);
|
|
@@ -1456,57 +1500,79 @@ const handleUnhandledError = (message, filename, lineno, colno, error) => {
|
|
|
1456
1500
|
|
|
1457
1501
|
const editorWorkerUrl = `${assetDir}/packages/renderer-worker/node_modules/@lvce-editor/editor-worker/dist/editorWorkerMain.js`;
|
|
1458
1502
|
|
|
1459
|
-
const launchEditorWorker = async
|
|
1460
|
-
|
|
1503
|
+
const launchEditorWorker = async port => {
|
|
1504
|
+
const ipc = await create$K({
|
|
1461
1505
|
name: 'Editor Worker',
|
|
1462
|
-
url: editorWorkerUrl
|
|
1506
|
+
url: editorWorkerUrl,
|
|
1507
|
+
method: ModuleWorkerWithMessagePort,
|
|
1508
|
+
port
|
|
1463
1509
|
});
|
|
1510
|
+
return ipc;
|
|
1464
1511
|
};
|
|
1465
1512
|
|
|
1466
1513
|
const hydrate$3 = async () => {
|
|
1514
|
+
const {
|
|
1515
|
+
port1,
|
|
1516
|
+
port2
|
|
1517
|
+
} = new MessageChannel();
|
|
1467
1518
|
// TODO only launch port and send to renderer worker
|
|
1468
|
-
|
|
1519
|
+
const promise = launchEditorWorker(port1);
|
|
1520
|
+
set$6('Editor Worker', port2);
|
|
1521
|
+
await promise;
|
|
1469
1522
|
};
|
|
1470
1523
|
|
|
1524
|
+
const isElectron = platform === Electron$1;
|
|
1525
|
+
|
|
1471
1526
|
const extensionHostWorkerUrl = `${assetDir}/packages/extension-host-worker/src/extensionHostWorkerMain.ts`;
|
|
1472
1527
|
|
|
1473
|
-
const launchExtensionHostWorker = async
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1528
|
+
const launchExtensionHostWorker = async port => {
|
|
1529
|
+
const name = isElectron ? 'Extension Host (Electron)' : 'Extension Host';
|
|
1530
|
+
const ipc = await create$K({
|
|
1531
|
+
name,
|
|
1532
|
+
url: extensionHostWorkerUrl,
|
|
1533
|
+
method: ModuleWorkerWithMessagePort,
|
|
1534
|
+
port
|
|
1477
1535
|
});
|
|
1536
|
+
return ipc;
|
|
1478
1537
|
};
|
|
1479
1538
|
|
|
1480
1539
|
const hydrate$2 = async () => {
|
|
1540
|
+
const {
|
|
1541
|
+
port1,
|
|
1542
|
+
port2
|
|
1543
|
+
} = new MessageChannel();
|
|
1481
1544
|
// TODO only launch port and send to renderer worker
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
if (typeof location === 'undefined') {
|
|
1487
|
-
return false;
|
|
1488
|
-
}
|
|
1489
|
-
const params = new URLSearchParams(location.search);
|
|
1490
|
-
return params.has(key);
|
|
1545
|
+
const promise = launchExtensionHostWorker(port1);
|
|
1546
|
+
const name = isElectron ? 'Extension Host (Electron)' : 'Extension Host';
|
|
1547
|
+
set$6(name, port2);
|
|
1548
|
+
await promise;
|
|
1491
1549
|
};
|
|
1492
1550
|
|
|
1493
1551
|
const syntaxHighlightingWorkerUrl = `${assetDir}/packages/renderer-worker/node_modules/@lvce-editor/syntax-highlighting-worker/dist/syntaxHighlightingWorkerMain.js`;
|
|
1494
1552
|
|
|
1495
|
-
const launchSyntaxHighlightingWorker = async
|
|
1496
|
-
|
|
1553
|
+
const launchSyntaxHighlightingWorker = async port => {
|
|
1554
|
+
const ipc = await create$K({
|
|
1497
1555
|
name: 'Syntax Highlighting Worker',
|
|
1498
|
-
url: syntaxHighlightingWorkerUrl
|
|
1556
|
+
url: syntaxHighlightingWorkerUrl,
|
|
1557
|
+
method: ModuleWorkerWithMessagePort,
|
|
1558
|
+
port
|
|
1499
1559
|
});
|
|
1560
|
+
return ipc;
|
|
1500
1561
|
};
|
|
1501
1562
|
|
|
1502
1563
|
const hydrate$1 = async () => {
|
|
1564
|
+
const {
|
|
1565
|
+
port1,
|
|
1566
|
+
port2
|
|
1567
|
+
} = new MessageChannel();
|
|
1503
1568
|
// TODO only launch port and send to renderer worker
|
|
1504
|
-
|
|
1569
|
+
const promise = launchSyntaxHighlightingWorker(port1);
|
|
1570
|
+
set$6('Syntax Highlighting Worker', port2);
|
|
1571
|
+
await promise;
|
|
1505
1572
|
};
|
|
1506
1573
|
|
|
1507
|
-
const launchMultipleWorkers = hasFlag('prelaunchWorkers');
|
|
1508
1574
|
const launchWorkers = () => {
|
|
1509
|
-
if (
|
|
1575
|
+
if (shouldLaunchMultipleWorkers) {
|
|
1510
1576
|
return Promise.all([hydrate$4(), hydrate$3(), hydrate$1(), hydrate$2()]);
|
|
1511
1577
|
}
|
|
1512
1578
|
return hydrate$4();
|
|
@@ -3049,6 +3115,24 @@ const ImagePreview_ipc = {
|
|
|
3049
3115
|
name: name$o
|
|
3050
3116
|
};
|
|
3051
3117
|
|
|
3118
|
+
const getTitleBarHeight = () => {
|
|
3119
|
+
if (
|
|
3120
|
+
// @ts-expect-error
|
|
3121
|
+
navigator.windowControlsOverlay?.getTitlebarAreaRect) {
|
|
3122
|
+
// @ts-expect-error
|
|
3123
|
+
const titleBarRect = navigator.windowControlsOverlay.getTitlebarAreaRect();
|
|
3124
|
+
return titleBarRect.height;
|
|
3125
|
+
}
|
|
3126
|
+
return 0;
|
|
3127
|
+
};
|
|
3128
|
+
const getBounds = () => {
|
|
3129
|
+
return {
|
|
3130
|
+
windowWidth: window.innerWidth,
|
|
3131
|
+
windowHeight: window.innerHeight,
|
|
3132
|
+
titleBarHeight: getTitleBarHeight()
|
|
3133
|
+
};
|
|
3134
|
+
};
|
|
3135
|
+
|
|
3052
3136
|
const getPathName = () => {
|
|
3053
3137
|
return location.pathname;
|
|
3054
3138
|
};
|
|
@@ -3069,24 +3153,6 @@ const hydrate = () => {
|
|
|
3069
3153
|
// addEventListener('popstate', handlePopState)
|
|
3070
3154
|
};
|
|
3071
3155
|
|
|
3072
|
-
const getTitleBarHeight = () => {
|
|
3073
|
-
if (
|
|
3074
|
-
// @ts-expect-error
|
|
3075
|
-
navigator.windowControlsOverlay?.getTitlebarAreaRect) {
|
|
3076
|
-
// @ts-expect-error
|
|
3077
|
-
const titleBarRect = navigator.windowControlsOverlay.getTitlebarAreaRect();
|
|
3078
|
-
return titleBarRect.height;
|
|
3079
|
-
}
|
|
3080
|
-
return 0;
|
|
3081
|
-
};
|
|
3082
|
-
const getBounds = () => {
|
|
3083
|
-
return {
|
|
3084
|
-
windowWidth: window.innerWidth,
|
|
3085
|
-
windowHeight: window.innerHeight,
|
|
3086
|
-
titleBarHeight: getTitleBarHeight()
|
|
3087
|
-
};
|
|
3088
|
-
};
|
|
3089
|
-
|
|
3090
3156
|
const getInitData = () => {
|
|
3091
3157
|
const initData = {
|
|
3092
3158
|
Location: {
|
|
@@ -3094,6 +3160,9 @@ const getInitData = () => {
|
|
|
3094
3160
|
},
|
|
3095
3161
|
Layout: {
|
|
3096
3162
|
bounds: getBounds()
|
|
3163
|
+
},
|
|
3164
|
+
Config: {
|
|
3165
|
+
shouldLaunchMultipleWorkers: shouldLaunchMultipleWorkers
|
|
3097
3166
|
}
|
|
3098
3167
|
};
|
|
3099
3168
|
return initData;
|
|
@@ -5452,6 +5521,11 @@ const listen$3 = async () => {
|
|
|
5452
5521
|
}
|
|
5453
5522
|
const type = firstMessage.params[0];
|
|
5454
5523
|
if (type === 'message-port') {
|
|
5524
|
+
parentIpc.send({
|
|
5525
|
+
jsonrpc: '2.0',
|
|
5526
|
+
id: firstMessage.id,
|
|
5527
|
+
result: null
|
|
5528
|
+
});
|
|
5455
5529
|
parentIpc.dispose();
|
|
5456
5530
|
const port = firstMessage.params[1];
|
|
5457
5531
|
return port;
|
|
@@ -5885,7 +5959,7 @@ const create$y = async ({
|
|
|
5885
5959
|
// TODO await promise
|
|
5886
5960
|
// TODO call separate method HandleMessagePort.handleMessagePort or
|
|
5887
5961
|
// HandleIncomingIpc.handleIncomingIpc
|
|
5888
|
-
invokeAndTransfer$1(ipc,
|
|
5962
|
+
await invokeAndTransfer$1(ipc, 'initialize', 'message-port', port);
|
|
5889
5963
|
unhandleIpc(ipc);
|
|
5890
5964
|
return undefined;
|
|
5891
5965
|
};
|
|
@@ -5906,8 +5980,6 @@ const handleIpcOnce = ipc => {
|
|
|
5906
5980
|
}
|
|
5907
5981
|
};
|
|
5908
5982
|
|
|
5909
|
-
const isElectron = platform === Electron$1;
|
|
5910
|
-
|
|
5911
5983
|
// TODO use handleIncomingIpc function
|
|
5912
5984
|
const create$x = async ({
|
|
5913
5985
|
port,
|