@lvce-editor/renderer-process 7.0.0 → 7.0.2

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.
@@ -756,7 +756,7 @@ const isSocket = value => {
756
756
  return isInstanceOf(value, 'Socket');
757
757
  };
758
758
  const transferrables = [isMessagePort$1, isMessagePortMain, isOffscreenCanvas, isSocket];
759
- const isTransferrable = value => {
759
+ const isTransferrable$1 = value => {
760
760
  for (const fn of transferrables) {
761
761
  if (fn(value)) {
762
762
  return true;
@@ -764,28 +764,28 @@ const isTransferrable = value => {
764
764
  }
765
765
  return false;
766
766
  };
767
- const walkValue = (value, transferrables) => {
767
+ const walkValue$1 = (value, transferrables) => {
768
768
  if (!value) {
769
769
  return;
770
770
  }
771
- if (isTransferrable(value)) {
771
+ if (isTransferrable$1(value)) {
772
772
  transferrables.push(value);
773
773
  }
774
774
  if (Array.isArray(value)) {
775
775
  for (const item of value) {
776
- walkValue(item, transferrables);
776
+ walkValue$1(item, transferrables);
777
777
  }
778
778
  return;
779
779
  }
780
780
  if (typeof value === 'object') {
781
781
  for (const property of Object.values(value)) {
782
- walkValue(property, transferrables);
782
+ walkValue$1(property, transferrables);
783
783
  }
784
784
  }
785
785
  };
786
786
  const getTransferrables = value => {
787
787
  const transferrables = [];
788
- walkValue(value, transferrables);
788
+ walkValue$1(value, transferrables);
789
789
  return transferrables;
790
790
  };
791
791
  const isSingleTransferrable = value => {
@@ -5503,14 +5503,14 @@ class Ipc extends EventTarget {
5503
5503
  }
5504
5504
  }
5505
5505
  const readyMessage = 'ready';
5506
- const listen$3 = () => {
5506
+ const listen$4 = () => {
5507
5507
  // @ts-ignore
5508
5508
  if (typeof WorkerGlobalScope === 'undefined') {
5509
5509
  throw new TypeError('module is not in web worker scope');
5510
5510
  }
5511
5511
  return globalThis;
5512
5512
  };
5513
- const signal$2 = global => {
5513
+ const signal$3 = global => {
5514
5514
  global.postMessage(readyMessage);
5515
5515
  };
5516
5516
  class IpcChildWithModuleWorker extends Ipc {
@@ -5535,14 +5535,14 @@ class IpcChildWithModuleWorker extends Ipc {
5535
5535
  this._rawIpc.addEventListener('message', callback);
5536
5536
  }
5537
5537
  }
5538
- const wrap$5 = global => {
5538
+ const wrap$6 = global => {
5539
5539
  return new IpcChildWithModuleWorker(global);
5540
5540
  };
5541
5541
  const IpcChildWithModuleWorker$1 = {
5542
5542
  __proto__: null,
5543
- listen: listen$3,
5544
- signal: signal$2,
5545
- wrap: wrap$5
5543
+ listen: listen$4,
5544
+ signal: signal$3,
5545
+ wrap: wrap$6
5546
5546
  };
5547
5547
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
5548
5548
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
@@ -5760,10 +5760,10 @@ const waitForFirstMessage = async port => {
5760
5760
  // @ts-ignore
5761
5761
  return event.data;
5762
5762
  };
5763
- const listen$2 = async () => {
5764
- const parentIpcRaw = listen$3();
5765
- signal$2(parentIpcRaw);
5766
- const parentIpc = wrap$5(parentIpcRaw);
5763
+ const listen$3 = async () => {
5764
+ const parentIpcRaw = listen$4();
5765
+ signal$3(parentIpcRaw);
5766
+ const parentIpc = wrap$6(parentIpcRaw);
5767
5767
  const firstMessage = await waitForFirstMessage(parentIpc);
5768
5768
  if (firstMessage.method !== 'initialize') {
5769
5769
  throw new IpcError$1('unexpected first message');
@@ -5802,13 +5802,59 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
5802
5802
  this._rawIpc.start();
5803
5803
  }
5804
5804
  }
5805
- const wrap$4 = port => {
5805
+ const wrap$5 = port => {
5806
5806
  return new IpcChildWithModuleWorkerAndMessagePort(port);
5807
5807
  };
5808
5808
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
5809
5809
  __proto__: null,
5810
- listen: listen$2,
5811
- wrap: wrap$4
5810
+ listen: listen$3,
5811
+ wrap: wrap$5
5812
+ };
5813
+ const isTransferrable = value => {
5814
+ return value instanceof MessagePort;
5815
+ };
5816
+ const UntransferrableValue = {};
5817
+ const walkValue = (value, transferrables) => {
5818
+ if (!value) {
5819
+ return value;
5820
+ }
5821
+ if (isTransferrable(value)) {
5822
+ transferrables.push(value);
5823
+ return UntransferrableValue;
5824
+ }
5825
+ if (Array.isArray(value)) {
5826
+ const newItems = [];
5827
+ for (const item of value) {
5828
+ const newItem = walkValue(item, transferrables);
5829
+ if (newItem !== UntransferrableValue) {
5830
+ newItems.push(newItem);
5831
+ }
5832
+ }
5833
+ return newItems;
5834
+ }
5835
+ if (typeof value === 'object') {
5836
+ const newObject = Object.create(null);
5837
+ for (const [key, property] of Object.entries(value)) {
5838
+ const newValue = walkValue(property, transferrables);
5839
+ if (newValue !== UntransferrableValue) {
5840
+ newObject[key] = newValue;
5841
+ }
5842
+ }
5843
+ return newObject;
5844
+ }
5845
+ return value;
5846
+ };
5847
+
5848
+ // workaround for electron not supporting transferrable objects
5849
+ // as parameters. If the transferrable object is a parameter, in electron
5850
+ // only an empty objected is received in the main process
5851
+ const fixElectronParameters = value => {
5852
+ const transfer = [];
5853
+ const newValue = walkValue(value, transfer);
5854
+ return {
5855
+ newValue,
5856
+ transfer
5857
+ };
5812
5858
  };
5813
5859
  const listen$1 = () => {
5814
5860
  return window;
@@ -5816,15 +5862,19 @@ const listen$1 = () => {
5816
5862
  const signal$1 = global => {
5817
5863
  global.postMessage(readyMessage);
5818
5864
  };
5819
- class IpcChildWithWindow extends Ipc {
5865
+ class IpcChildWithElectronWindow extends Ipc {
5820
5866
  getData(event) {
5821
5867
  return getData$1(event);
5822
5868
  }
5823
5869
  send(message) {
5824
5870
  this._rawIpc.postMessage(message);
5825
5871
  }
5826
- sendAndTransfer(message, transfer) {
5827
- this._rawIpc.postMessage(message, location.origin, transfer);
5872
+ sendAndTransfer(message, _transfer) {
5873
+ const {
5874
+ newValue,
5875
+ transfer
5876
+ } = fixElectronParameters(message);
5877
+ this._rawIpc.postMessage(newValue, location.origin, transfer);
5828
5878
  }
5829
5879
  dispose() {
5830
5880
  // ignore
@@ -5847,15 +5897,15 @@ class IpcChildWithWindow extends Ipc {
5847
5897
  }
5848
5898
  }
5849
5899
  const wrap$3 = window => {
5850
- return new IpcChildWithWindow(window);
5900
+ return new IpcChildWithElectronWindow(window);
5851
5901
  };
5852
- const IpcChildWithWindow$1 = {
5902
+ const IpcChildWithElectronWindow$1 = {
5853
5903
  __proto__: null,
5854
5904
  listen: listen$1,
5855
5905
  signal: signal$1,
5856
5906
  wrap: wrap$3
5857
5907
  };
5858
- const listen$4 = ({
5908
+ const listen$2 = ({
5859
5909
  port
5860
5910
  }) => {
5861
5911
  return port;
@@ -5892,7 +5942,7 @@ const wrap$2 = port => {
5892
5942
  };
5893
5943
  const IpcChildWithMessagePort$1 = {
5894
5944
  __proto__: null,
5895
- listen: listen$4,
5945
+ listen: listen$2,
5896
5946
  signal,
5897
5947
  wrap: wrap$2
5898
5948
  };
@@ -6195,7 +6245,7 @@ const create$x = async ({
6195
6245
  if (!isElectron) {
6196
6246
  throw new Error('Electron api was requested but is not available');
6197
6247
  }
6198
- const windowIpc = IpcChildWithWindow$1.wrap(window);
6248
+ const windowIpc = IpcChildWithElectronWindow$1.wrap(window);
6199
6249
  handleIpcOnce(windowIpc);
6200
6250
  const webContentsIds = await invokeAndTransfer$1(windowIpc, 'CreateMessagePort.createMessagePort', ipcId, port);
6201
6251
  return webContentsIds;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "",
5
5
  "main": "dist/diffWorkerMain.js",
6
6
  "type": "module",