@lvce-editor/renderer-process 9.0.0 → 9.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.
@@ -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$6 = (id, fn) => {
516
+ const set$7 = (id, fn) => {
517
517
  state$1$1.callbacks[id] = fn;
518
518
  };
519
- const get$7 = id => {
519
+ const get$8 = id => {
520
520
  return state$1$1.callbacks[id];
521
521
  };
522
- const remove$2 = id => {
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$6(id, resolve);
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$7(id);
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$2(id);
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
- console.error(error);
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,66 +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
- return launchWorker({
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
- await launchEditorWorker();
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
- return launchWorker({
1475
- name: 'Extension Host Worker',
1476
- url: extensionHostWorkerUrl
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
- await launchExtensionHostWorker();
1483
- };
1484
-
1485
- const hasFlag = key => {
1486
- if (typeof location === 'undefined' || typeof document === 'undefined') {
1487
- return false;
1488
- }
1489
- const configElement = document.getElementById('Config');
1490
- if (!configElement) {
1491
- return false;
1492
- }
1493
- const text = configElement.textContent;
1494
- if (!text) {
1495
- return false;
1496
- }
1497
- const config = JSON.parse(text);
1498
- const result = config[key];
1499
- return result;
1545
+ const promise = launchExtensionHostWorker(port1);
1546
+ const name = isElectron ? 'Extension Host (Electron)' : 'Extension Host';
1547
+ set$6(name, port2);
1548
+ await promise;
1500
1549
  };
1501
1550
 
1502
1551
  const syntaxHighlightingWorkerUrl = `${assetDir}/packages/renderer-worker/node_modules/@lvce-editor/syntax-highlighting-worker/dist/syntaxHighlightingWorkerMain.js`;
1503
1552
 
1504
- const launchSyntaxHighlightingWorker = async () => {
1505
- return launchWorker({
1553
+ const launchSyntaxHighlightingWorker = async port => {
1554
+ const ipc = await create$K({
1506
1555
  name: 'Syntax Highlighting Worker',
1507
- url: syntaxHighlightingWorkerUrl
1556
+ url: syntaxHighlightingWorkerUrl,
1557
+ method: ModuleWorkerWithMessagePort,
1558
+ port
1508
1559
  });
1560
+ return ipc;
1509
1561
  };
1510
1562
 
1511
1563
  const hydrate$1 = async () => {
1564
+ const {
1565
+ port1,
1566
+ port2
1567
+ } = new MessageChannel();
1512
1568
  // TODO only launch port and send to renderer worker
1513
- await launchSyntaxHighlightingWorker();
1569
+ const promise = launchSyntaxHighlightingWorker(port1);
1570
+ set$6('Syntax Highlighting Worker', port2);
1571
+ await promise;
1514
1572
  };
1515
1573
 
1516
- const launchMultipleWorkers = hasFlag('prelaunchWorkers');
1517
1574
  const launchWorkers = () => {
1518
- if (launchMultipleWorkers) {
1575
+ if (shouldLaunchMultipleWorkers) {
1519
1576
  return Promise.all([hydrate$4(), hydrate$3(), hydrate$1(), hydrate$2()]);
1520
1577
  }
1521
1578
  return hydrate$4();
@@ -3058,6 +3115,24 @@ const ImagePreview_ipc = {
3058
3115
  name: name$o
3059
3116
  };
3060
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
+
3061
3136
  const getPathName = () => {
3062
3137
  return location.pathname;
3063
3138
  };
@@ -3078,24 +3153,6 @@ const hydrate = () => {
3078
3153
  // addEventListener('popstate', handlePopState)
3079
3154
  };
3080
3155
 
3081
- const getTitleBarHeight = () => {
3082
- if (
3083
- // @ts-expect-error
3084
- navigator.windowControlsOverlay?.getTitlebarAreaRect) {
3085
- // @ts-expect-error
3086
- const titleBarRect = navigator.windowControlsOverlay.getTitlebarAreaRect();
3087
- return titleBarRect.height;
3088
- }
3089
- return 0;
3090
- };
3091
- const getBounds = () => {
3092
- return {
3093
- windowWidth: window.innerWidth,
3094
- windowHeight: window.innerHeight,
3095
- titleBarHeight: getTitleBarHeight()
3096
- };
3097
- };
3098
-
3099
3156
  const getInitData = () => {
3100
3157
  const initData = {
3101
3158
  Location: {
@@ -3103,6 +3160,9 @@ const getInitData = () => {
3103
3160
  },
3104
3161
  Layout: {
3105
3162
  bounds: getBounds()
3163
+ },
3164
+ Config: {
3165
+ shouldLaunchMultipleWorkers: shouldLaunchMultipleWorkers
3106
3166
  }
3107
3167
  };
3108
3168
  return initData;
@@ -5920,8 +5980,6 @@ const handleIpcOnce = ipc => {
5920
5980
  }
5921
5981
  };
5922
5982
 
5923
- const isElectron = platform === Electron$1;
5924
-
5925
5983
  // TODO use handleIncomingIpc function
5926
5984
  const create$x = async ({
5927
5985
  port,
@@ -6674,7 +6732,7 @@ const StatusBar = 'Status Bar';
6674
6732
 
6675
6733
  const getEventListenerOptions = eventName => {
6676
6734
  switch (eventName) {
6677
- case 'wheel':
6735
+ case Wheel:
6678
6736
  return {
6679
6737
  passive: true
6680
6738
  };
@@ -6710,7 +6768,7 @@ const attachEvent = ($Node, eventMap, key, value) => {
6710
6768
  console.warn('listener not found', value);
6711
6769
  return;
6712
6770
  }
6713
- const options = getEventListenerOptions(eventMap);
6771
+ const options = getEventListenerOptions(key);
6714
6772
  const wrapped = getWrappedListener(listener, eventMap.returnValue);
6715
6773
  $Node.addEventListener(key, wrapped, options);
6716
6774
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "9.0.0",
3
+ "version": "9.2.0",
4
4
  "description": "",
5
5
  "main": "dist/diffWorkerMain.js",
6
6
  "type": "module",