@lvce-editor/ipc 10.1.0 → 10.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.
package/dist/electron.js CHANGED
@@ -501,14 +501,14 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
501
501
  this._rawIpc.on('message', callback);
502
502
  }
503
503
  }
504
- const wrap$2 = process => {
504
+ const wrap$3 = process => {
505
505
  return new IpcParentWithElectronUtilityProcess(process);
506
506
  };
507
507
 
508
508
  const IpcParentWithElectronUtilityProcess$1 = {
509
509
  __proto__: null,
510
510
  create: create$2,
511
- wrap: wrap$2
511
+ wrap: wrap$3
512
512
  };
513
513
 
514
514
  class ChildProcessError extends Error {
@@ -693,14 +693,14 @@ class IpcParentWithNodeForkedProcess extends Ipc {
693
693
  this._rawIpc.on('message', callback);
694
694
  }
695
695
  }
696
- const wrap$1 = childProcess => {
696
+ const wrap$2 = childProcess => {
697
697
  return new IpcParentWithNodeForkedProcess(childProcess);
698
698
  };
699
699
 
700
700
  const IpcParentWithNodeForkedProcess$1 = {
701
701
  __proto__: null,
702
702
  create: create$1,
703
- wrap: wrap$1
703
+ wrap: wrap$2
704
704
  };
705
705
 
706
706
  const addListener = (emitter, type, callback) => {
@@ -792,7 +792,7 @@ const create = async ({
792
792
  };
793
793
 
794
794
  // @ts-ignore
795
- const wrap = worker => {
795
+ const wrap$1 = worker => {
796
796
  return {
797
797
  worker,
798
798
  // @ts-ignore
@@ -827,7 +827,68 @@ const wrap = worker => {
827
827
  const IpcParentWithNodeWorker = {
828
828
  __proto__: null,
829
829
  create,
830
+ wrap: wrap$1
831
+ };
832
+
833
+ const getActualDataElectron = event => {
834
+ const {
835
+ data,
836
+ ports
837
+ } = event;
838
+ if (ports.length === 0) {
839
+ return data;
840
+ }
841
+ return {
842
+ ...data,
843
+ params: [...ports, ...data.params]
844
+ };
845
+ };
846
+
847
+ const listen = ({
848
+ messagePort
849
+ }) => {
850
+ if (!isMessagePortMain(messagePort)) {
851
+ throw new IpcError('port must be of type MessagePortMain');
852
+ }
853
+ return messagePort;
854
+ };
855
+ const signal = messagePort => {
856
+ messagePort.start();
857
+ };
858
+ class IpcParentWithElectronMessagePort extends Ipc {
859
+ constructor(port) {
860
+ super(port);
861
+ }
862
+ getData = getActualDataElectron;
863
+ send(message) {
864
+ this._rawIpc.postMessage(message);
865
+ }
866
+ sendAndTransfer(message) {
867
+ const {
868
+ newValue,
869
+ transfer
870
+ } = fixElectronParameters(message);
871
+ this._rawIpc.postMessage(newValue, transfer);
872
+ }
873
+ dispose() {
874
+ this._rawIpc.close();
875
+ }
876
+ onMessage(callback) {
877
+ this._rawIpc.on('message', callback);
878
+ }
879
+ onClose(callback) {
880
+ this._rawIpc.on('close', callback);
881
+ }
882
+ }
883
+ const wrap = messagePort => {
884
+ return new IpcParentWithElectronMessagePort(messagePort);
885
+ };
886
+
887
+ const IpcParentWithElectronMessagePort$1 = {
888
+ __proto__: null,
889
+ listen,
890
+ signal,
830
891
  wrap
831
892
  };
832
893
 
833
- export { IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
894
+ export { IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
package/dist/index.d.ts CHANGED
@@ -25,3 +25,4 @@ interface IpcParent {
25
25
  export const IpcParentWithElectronUtilityProcess: IpcParent
26
26
  export const IpcParentWithNodeForkedProcess: IpcParent
27
27
  export const IpcParentWithNodeWorker: IpcParent
28
+ export const IpcParentWithElectronMessagePort: IpcParent
package/dist/index.js CHANGED
@@ -97,6 +97,20 @@ const fixElectronParameters = value => {
97
97
  };
98
98
  };
99
99
 
100
+ const getActualDataElectron = event => {
101
+ const {
102
+ data,
103
+ ports
104
+ } = event;
105
+ if (ports.length === 0) {
106
+ return data;
107
+ }
108
+ return {
109
+ ...data,
110
+ params: [...ports, ...data.params]
111
+ };
112
+ };
113
+
100
114
  const attachEvents = that => {
101
115
  const handleMessage = (...args) => {
102
116
  const data = that.getData(...args);
@@ -265,7 +279,7 @@ class IpcError extends VError {
265
279
  }
266
280
  }
267
281
 
268
- const listen$8 = ({
282
+ const listen$9 = ({
269
283
  messagePort
270
284
  }) => {
271
285
  if (!isMessagePortMain(messagePort)) {
@@ -273,29 +287,14 @@ const listen$8 = ({
273
287
  }
274
288
  return messagePort;
275
289
  };
276
- const signal$6 = messagePort => {
290
+ const signal$7 = messagePort => {
277
291
  messagePort.start();
278
292
  };
279
- const getActualData$1 = event => {
280
- const {
281
- data,
282
- ports
283
- } = event;
284
- if (ports.length === 0) {
285
- return data;
286
- }
287
- return {
288
- ...data,
289
- params: [...ports, ...data.params]
290
- };
291
- };
292
293
  class IpcChildWithElectronMessagePort extends Ipc {
293
294
  constructor(port) {
294
295
  super(port);
295
296
  }
296
- getData(event) {
297
- return getActualData$1(event);
298
- }
297
+ getData = getActualDataElectron;
299
298
  send(message) {
300
299
  this._rawIpc.postMessage(message);
301
300
  }
@@ -316,15 +315,15 @@ class IpcChildWithElectronMessagePort extends Ipc {
316
315
  this._rawIpc.on('close', callback);
317
316
  }
318
317
  }
319
- const wrap$b = messagePort => {
318
+ const wrap$c = messagePort => {
320
319
  return new IpcChildWithElectronMessagePort(messagePort);
321
320
  };
322
321
 
323
322
  const IpcChildWithElectronMessagePort$1 = {
324
323
  __proto__: null,
325
- listen: listen$8,
326
- signal: signal$6,
327
- wrap: wrap$b
324
+ listen: listen$9,
325
+ signal: signal$7,
326
+ wrap: wrap$c
328
327
  };
329
328
 
330
329
  // @ts-ignore
@@ -344,7 +343,7 @@ const getUtilityProcessPortData = event => {
344
343
 
345
344
  const readyMessage = 'ready';
346
345
 
347
- const listen$7 = () => {
346
+ const listen$8 = () => {
348
347
  // @ts-ignore
349
348
  const {
350
349
  parentPort
@@ -354,7 +353,7 @@ const listen$7 = () => {
354
353
  }
355
354
  return parentPort;
356
355
  };
357
- const signal$5 = parentPort => {
356
+ const signal$6 = parentPort => {
358
357
  parentPort.postMessage(readyMessage);
359
358
  };
360
359
  class IpcChildWithElectronUtilityProcess extends Ipc {
@@ -381,29 +380,29 @@ class IpcChildWithElectronUtilityProcess extends Ipc {
381
380
  this._rawIpc.on('message', callback);
382
381
  }
383
382
  }
384
- const wrap$a = parentPort => {
383
+ const wrap$b = parentPort => {
385
384
  return new IpcChildWithElectronUtilityProcess(parentPort);
386
385
  };
387
386
 
388
387
  const IpcChildWithElectronUtilityProcess$1 = {
389
388
  __proto__: null,
390
- listen: listen$7,
391
- signal: signal$5,
392
- wrap: wrap$a
389
+ listen: listen$8,
390
+ signal: signal$6,
391
+ wrap: wrap$b
393
392
  };
394
393
 
395
394
  const getData$1 = event => {
396
395
  return event.data;
397
396
  };
398
397
 
399
- const listen$6 = () => {
398
+ const listen$7 = () => {
400
399
  // @ts-ignore
401
400
  if (typeof WorkerGlobalScope === 'undefined') {
402
401
  throw new TypeError('module is not in web worker scope');
403
402
  }
404
403
  return globalThis;
405
404
  };
406
- const signal$4 = global => {
405
+ const signal$5 = global => {
407
406
  global.postMessage(readyMessage);
408
407
  };
409
408
  class IpcChildWithModuleWorker extends Ipc {
@@ -429,15 +428,15 @@ class IpcChildWithModuleWorker extends Ipc {
429
428
  this._rawIpc.addEventListener('message', callback);
430
429
  }
431
430
  }
432
- const wrap$9 = global => {
431
+ const wrap$a = global => {
433
432
  return new IpcChildWithModuleWorker(global);
434
433
  };
435
434
 
436
435
  const IpcChildWithModuleWorker$1 = {
437
436
  __proto__: null,
438
- listen: listen$6,
439
- signal: signal$4,
440
- wrap: wrap$9
437
+ listen: listen$7,
438
+ signal: signal$5,
439
+ wrap: wrap$a
441
440
  };
442
441
 
443
442
  const withResolvers = () => {
@@ -464,10 +463,10 @@ const waitForFirstMessage = async port => {
464
463
  return event.data;
465
464
  };
466
465
 
467
- const listen$5 = async () => {
468
- const parentIpcRaw = listen$6();
469
- signal$4(parentIpcRaw);
470
- const parentIpc = wrap$9(parentIpcRaw);
466
+ const listen$6 = async () => {
467
+ const parentIpcRaw = listen$7();
468
+ signal$5(parentIpcRaw);
469
+ const parentIpc = wrap$a(parentIpcRaw);
471
470
  const firstMessage = await waitForFirstMessage(parentIpc);
472
471
  if (firstMessage.method !== 'initialize') {
473
472
  throw new IpcError('unexpected first message');
@@ -507,14 +506,14 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
507
506
  this._rawIpc.start();
508
507
  }
509
508
  }
510
- const wrap$8 = port => {
509
+ const wrap$9 = port => {
511
510
  return new IpcChildWithModuleWorkerAndMessagePort(port);
512
511
  };
513
512
 
514
513
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
515
514
  __proto__: null,
516
- listen: listen$5,
517
- wrap: wrap$8
515
+ listen: listen$6,
516
+ wrap: wrap$9
518
517
  };
519
518
 
520
519
  const getTransferrablesNode = value => {
@@ -535,13 +534,13 @@ const getActualData = (message, handle) => {
535
534
  return message;
536
535
  };
537
536
 
538
- const listen$4 = async () => {
537
+ const listen$5 = async () => {
539
538
  if (!process.send) {
540
539
  throw new Error('process.send must be defined');
541
540
  }
542
541
  return process;
543
542
  };
544
- const signal$3 = process => {
543
+ const signal$4 = process => {
545
544
  process.send(readyMessage);
546
545
  };
547
546
  class IpcChildWithNodeForkedProcess extends Ipc {
@@ -568,18 +567,18 @@ class IpcChildWithNodeForkedProcess extends Ipc {
568
567
  // ignore
569
568
  }
570
569
  }
571
- const wrap$7 = process => {
570
+ const wrap$8 = process => {
572
571
  return new IpcChildWithNodeForkedProcess(process);
573
572
  };
574
573
 
575
574
  const IpcChildWithNodeForkedProcess$1 = {
576
575
  __proto__: null,
577
- listen: listen$4,
578
- signal: signal$3,
579
- wrap: wrap$7
576
+ listen: listen$5,
577
+ signal: signal$4,
578
+ wrap: wrap$8
580
579
  };
581
580
 
582
- const listen$3 = async ({
581
+ const listen$4 = async ({
583
582
  messagePort
584
583
  }) => {
585
584
  if (!isMessagePort(messagePort)) {
@@ -587,10 +586,10 @@ const listen$3 = async ({
587
586
  }
588
587
  return messagePort;
589
588
  };
590
- const signal$2 = messagePort => {
589
+ const signal$3 = messagePort => {
591
590
  messagePort.start();
592
591
  };
593
- const wrap$6 = port => {
592
+ const wrap$7 = port => {
594
593
  return {
595
594
  port,
596
595
  on(event, listener) {
@@ -620,12 +619,12 @@ const wrap$6 = port => {
620
619
 
621
620
  const IpcChildWithNodeMessagePort = {
622
621
  __proto__: null,
623
- listen: listen$3,
624
- signal: signal$2,
625
- wrap: wrap$6
622
+ listen: listen$4,
623
+ signal: signal$3,
624
+ wrap: wrap$7
626
625
  };
627
626
 
628
- const listen$2 = async () => {
627
+ const listen$3 = async () => {
629
628
  const {
630
629
  parentPort
631
630
  } = await import('node:worker_threads');
@@ -634,10 +633,10 @@ const listen$2 = async () => {
634
633
  }
635
634
  return parentPort;
636
635
  };
637
- const signal$1 = parentPort => {
636
+ const signal$2 = parentPort => {
638
637
  parentPort.postMessage(readyMessage);
639
638
  };
640
- const wrap$5 = parentPort => {
639
+ const wrap$6 = parentPort => {
641
640
  return {
642
641
  parentPort,
643
642
  on(event, listener) {
@@ -664,13 +663,13 @@ const wrap$5 = parentPort => {
664
663
 
665
664
  const IpcChildWithNodeWorker = {
666
665
  __proto__: null,
667
- listen: listen$2,
668
- signal: signal$1,
669
- wrap: wrap$5
666
+ listen: listen$3,
667
+ signal: signal$2,
668
+ wrap: wrap$6
670
669
  };
671
670
 
672
671
  const preloadChannelType = 'port';
673
- const listen$1 = ({
672
+ const listen$2 = ({
674
673
  webContents
675
674
  }) => {
676
675
  return webContents;
@@ -707,14 +706,14 @@ class IpcChildWithRendererProcess2 extends Ipc {
707
706
  this._rawIpc.on('destroyed', callback);
708
707
  }
709
708
  }
710
- const wrap$4 = webContents => {
709
+ const wrap$5 = webContents => {
711
710
  return new IpcChildWithRendererProcess2(webContents);
712
711
  };
713
712
 
714
713
  const IpcChildWithRendererProcess2$1 = {
715
714
  __proto__: null,
716
- listen: listen$1,
717
- wrap: wrap$4
715
+ listen: listen$2,
716
+ wrap: wrap$5
718
717
  };
719
718
 
720
719
  const Open = 1;
@@ -818,7 +817,7 @@ const handleUpgrade = async (...args) => {
818
817
  };
819
818
 
820
819
  // @ts-ignore
821
- const listen = async ({
820
+ const listen$1 = async ({
822
821
  request,
823
822
  handle
824
823
  }) => {
@@ -835,12 +834,12 @@ const listen = async ({
835
834
  }
836
835
  return webSocket;
837
836
  };
838
- const signal = webSocket => {
837
+ const signal$1 = webSocket => {
839
838
  webSocket.resume();
840
839
  };
841
840
 
842
841
  // @ts-ignore
843
- const wrap$3 = webSocket => {
842
+ const wrap$4 = webSocket => {
844
843
  return {
845
844
  webSocket,
846
845
  /**
@@ -888,6 +887,53 @@ const wrap$3 = webSocket => {
888
887
  };
889
888
 
890
889
  const IpcChildWithWebSocket = {
890
+ __proto__: null,
891
+ listen: listen$1,
892
+ signal: signal$1,
893
+ wrap: wrap$4
894
+ };
895
+
896
+ const listen = ({
897
+ messagePort
898
+ }) => {
899
+ if (!isMessagePortMain(messagePort)) {
900
+ throw new IpcError('port must be of type MessagePortMain');
901
+ }
902
+ return messagePort;
903
+ };
904
+ const signal = messagePort => {
905
+ messagePort.start();
906
+ };
907
+ class IpcParentWithElectronMessagePort extends Ipc {
908
+ constructor(port) {
909
+ super(port);
910
+ }
911
+ getData = getActualDataElectron;
912
+ send(message) {
913
+ this._rawIpc.postMessage(message);
914
+ }
915
+ sendAndTransfer(message) {
916
+ const {
917
+ newValue,
918
+ transfer
919
+ } = fixElectronParameters(message);
920
+ this._rawIpc.postMessage(newValue, transfer);
921
+ }
922
+ dispose() {
923
+ this._rawIpc.close();
924
+ }
925
+ onMessage(callback) {
926
+ this._rawIpc.on('message', callback);
927
+ }
928
+ onClose(callback) {
929
+ this._rawIpc.on('close', callback);
930
+ }
931
+ }
932
+ const wrap$3 = messagePort => {
933
+ return new IpcParentWithElectronMessagePort(messagePort);
934
+ };
935
+
936
+ const IpcParentWithElectronMessagePort$1 = {
891
937
  __proto__: null,
892
938
  listen,
893
939
  signal,
@@ -1319,4 +1365,4 @@ const IpcParentWithNodeWorker = {
1319
1365
  wrap
1320
1366
  };
1321
1367
 
1322
- export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess$1 as IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
1368
+ export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess$1 as IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "description": "Inter Process Communication for Lvce Editor",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",