@lvce-editor/ipc 11.0.1 → 11.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/browser.js +186 -145
- package/dist/electron.js +2 -2
- package/dist/index.d.ts +1 -0
- package/package.json +4 -3
package/dist/browser.js
CHANGED
|
@@ -2,6 +2,30 @@ const getData$1 = event => {
|
|
|
2
2
|
return event.data;
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
+
const attachEvents = that => {
|
|
6
|
+
const handleMessage = (...args) => {
|
|
7
|
+
const data = that.getData(...args);
|
|
8
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
9
|
+
data
|
|
10
|
+
}));
|
|
11
|
+
};
|
|
12
|
+
that.onMessage(handleMessage);
|
|
13
|
+
const handleClose = event => {
|
|
14
|
+
that.dispatchEvent(new Event('close'));
|
|
15
|
+
};
|
|
16
|
+
that.onClose(handleClose);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
class Ipc extends EventTarget {
|
|
20
|
+
constructor(rawIpc) {
|
|
21
|
+
super();
|
|
22
|
+
this._rawIpc = rawIpc;
|
|
23
|
+
attachEvents(this);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const readyMessage = 'ready';
|
|
28
|
+
|
|
5
29
|
const walkValue = (value, transferrables, isTransferrable) => {
|
|
6
30
|
if (!value) {
|
|
7
31
|
return;
|
|
@@ -61,38 +85,146 @@ const getTransferrables = value => {
|
|
|
61
85
|
return transferrables;
|
|
62
86
|
};
|
|
63
87
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
const removeValues = (value, toRemove) => {
|
|
89
|
+
if (!value) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
const newItems = [];
|
|
94
|
+
for (const item of value) {
|
|
95
|
+
if (!toRemove.includes(item)) {
|
|
96
|
+
newItems.push(removeValues(item, toRemove));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return newItems;
|
|
100
|
+
}
|
|
101
|
+
if (typeof value === 'object') {
|
|
102
|
+
const newObject = Object.create(null);
|
|
103
|
+
for (const [key, property] of Object.entries(value)) {
|
|
104
|
+
if (!toRemove.includes(property)) {
|
|
105
|
+
newObject[key] = removeValues(property, toRemove);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return newObject;
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// workaround for electron not supporting transferrable objects
|
|
114
|
+
// as parameters. If the transferrable object is a parameter, in electron
|
|
115
|
+
// only an empty objected is received in the main process
|
|
116
|
+
const fixElectronParameters = value => {
|
|
117
|
+
const transfer = getTransferrables(value);
|
|
118
|
+
const newValue = removeValues(value, transfer);
|
|
119
|
+
return {
|
|
120
|
+
newValue,
|
|
121
|
+
transfer
|
|
74
122
|
};
|
|
75
|
-
that.onClose(handleClose);
|
|
76
123
|
};
|
|
77
124
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
125
|
+
const listen$4 = () => {
|
|
126
|
+
return window;
|
|
127
|
+
};
|
|
128
|
+
const signal$4 = global => {
|
|
129
|
+
global.postMessage(readyMessage);
|
|
130
|
+
};
|
|
131
|
+
class IpcChildWithElectronWindow extends Ipc {
|
|
132
|
+
getData(event) {
|
|
133
|
+
return getData$1(event);
|
|
134
|
+
}
|
|
135
|
+
send(message) {
|
|
136
|
+
this._rawIpc.postMessage(message);
|
|
137
|
+
}
|
|
138
|
+
sendAndTransfer(message) {
|
|
139
|
+
const {
|
|
140
|
+
newValue,
|
|
141
|
+
transfer
|
|
142
|
+
} = fixElectronParameters(message);
|
|
143
|
+
this._rawIpc.postMessage(newValue, location.origin, transfer);
|
|
144
|
+
}
|
|
145
|
+
dispose() {
|
|
146
|
+
// ignore
|
|
147
|
+
}
|
|
148
|
+
onClose(callback) {
|
|
149
|
+
// ignore
|
|
150
|
+
}
|
|
151
|
+
onMessage(callback) {
|
|
152
|
+
const wrapped = event => {
|
|
153
|
+
const {
|
|
154
|
+
ports
|
|
155
|
+
} = event;
|
|
156
|
+
if (ports.length) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
callback(event);
|
|
160
|
+
this._rawIpc.removeEventListener('message', wrapped);
|
|
161
|
+
};
|
|
162
|
+
this._rawIpc.addEventListener('message', wrapped);
|
|
83
163
|
}
|
|
84
164
|
}
|
|
165
|
+
const wrap$7 = window => {
|
|
166
|
+
return new IpcChildWithElectronWindow(window);
|
|
167
|
+
};
|
|
85
168
|
|
|
86
|
-
const
|
|
169
|
+
const IpcChildWithElectronWindow$1 = {
|
|
170
|
+
__proto__: null,
|
|
171
|
+
listen: listen$4,
|
|
172
|
+
signal: signal$4,
|
|
173
|
+
wrap: wrap$7
|
|
174
|
+
};
|
|
87
175
|
|
|
88
|
-
const listen$
|
|
176
|
+
const listen$3 = ({
|
|
177
|
+
port
|
|
178
|
+
}) => {
|
|
179
|
+
return port;
|
|
180
|
+
};
|
|
181
|
+
const signal$3 = port => {
|
|
182
|
+
port.postMessage(readyMessage);
|
|
183
|
+
};
|
|
184
|
+
class IpcChildWithMessagePort extends Ipc {
|
|
185
|
+
constructor(port) {
|
|
186
|
+
super(port);
|
|
187
|
+
}
|
|
188
|
+
getData(event) {
|
|
189
|
+
return getData$1(event);
|
|
190
|
+
}
|
|
191
|
+
send(message) {
|
|
192
|
+
this._rawIpc.postMessage(message);
|
|
193
|
+
}
|
|
194
|
+
sendAndTransfer(message) {
|
|
195
|
+
const transfer = getTransferrables(message);
|
|
196
|
+
this._rawIpc.postMessage(message, transfer);
|
|
197
|
+
}
|
|
198
|
+
dispose() {
|
|
199
|
+
// ignore
|
|
200
|
+
}
|
|
201
|
+
onClose(callback) {
|
|
202
|
+
// ignore
|
|
203
|
+
}
|
|
204
|
+
onMessage(callback) {
|
|
205
|
+
this._rawIpc.addEventListener('message', callback);
|
|
206
|
+
this._rawIpc.start();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const wrap$6 = port => {
|
|
210
|
+
return new IpcChildWithMessagePort(port);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const IpcChildWithMessagePort$1 = {
|
|
214
|
+
__proto__: null,
|
|
215
|
+
listen: listen$3,
|
|
216
|
+
signal: signal$3,
|
|
217
|
+
wrap: wrap$6
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const listen$2 = () => {
|
|
89
221
|
// @ts-ignore
|
|
90
222
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
91
223
|
throw new TypeError('module is not in web worker scope');
|
|
92
224
|
}
|
|
93
225
|
return globalThis;
|
|
94
226
|
};
|
|
95
|
-
const signal$
|
|
227
|
+
const signal$2 = global => {
|
|
96
228
|
global.postMessage(readyMessage);
|
|
97
229
|
};
|
|
98
230
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -118,15 +250,15 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
118
250
|
this._rawIpc.addEventListener('message', callback);
|
|
119
251
|
}
|
|
120
252
|
}
|
|
121
|
-
const wrap$
|
|
253
|
+
const wrap$5 = global => {
|
|
122
254
|
return new IpcChildWithModuleWorker(global);
|
|
123
255
|
};
|
|
124
256
|
|
|
125
257
|
const IpcChildWithModuleWorker$1 = {
|
|
126
258
|
__proto__: null,
|
|
127
|
-
listen: listen$
|
|
128
|
-
signal: signal$
|
|
129
|
-
wrap: wrap$
|
|
259
|
+
listen: listen$2,
|
|
260
|
+
signal: signal$2,
|
|
261
|
+
wrap: wrap$5
|
|
130
262
|
};
|
|
131
263
|
|
|
132
264
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
@@ -250,10 +382,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
250
382
|
|
|
251
383
|
const normalizeLine = line => {
|
|
252
384
|
if (line.startsWith('Error: ')) {
|
|
253
|
-
return line.slice(
|
|
385
|
+
return line.slice('Error: '.length);
|
|
254
386
|
}
|
|
255
387
|
if (line.startsWith('VError: ')) {
|
|
256
|
-
return line.slice(
|
|
388
|
+
return line.slice('VError: '.length);
|
|
257
389
|
}
|
|
258
390
|
return line;
|
|
259
391
|
};
|
|
@@ -355,10 +487,10 @@ const waitForFirstMessage = async port => {
|
|
|
355
487
|
return event.data;
|
|
356
488
|
};
|
|
357
489
|
|
|
358
|
-
const listen$
|
|
359
|
-
const parentIpcRaw = listen$
|
|
360
|
-
signal$
|
|
361
|
-
const parentIpc = wrap$
|
|
490
|
+
const listen$1 = async () => {
|
|
491
|
+
const parentIpcRaw = listen$2();
|
|
492
|
+
signal$2(parentIpcRaw);
|
|
493
|
+
const parentIpc = wrap$5(parentIpcRaw);
|
|
362
494
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
363
495
|
if (firstMessage.method !== 'initialize') {
|
|
364
496
|
throw new IpcError('unexpected first message');
|
|
@@ -403,20 +535,20 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
403
535
|
this._rawIpc.start();
|
|
404
536
|
}
|
|
405
537
|
}
|
|
406
|
-
const wrap$
|
|
538
|
+
const wrap$4 = port => {
|
|
407
539
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
408
540
|
};
|
|
409
541
|
|
|
410
542
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
411
543
|
__proto__: null,
|
|
412
|
-
listen: listen$
|
|
413
|
-
wrap: wrap$
|
|
544
|
+
listen: listen$1,
|
|
545
|
+
wrap: wrap$4
|
|
414
546
|
};
|
|
415
547
|
|
|
416
|
-
const listen
|
|
548
|
+
const listen = () => {
|
|
417
549
|
return window;
|
|
418
550
|
};
|
|
419
|
-
const signal$
|
|
551
|
+
const signal$1 = global => {
|
|
420
552
|
global.postMessage(readyMessage);
|
|
421
553
|
};
|
|
422
554
|
class IpcChildWithWindow extends Ipc {
|
|
@@ -450,145 +582,54 @@ class IpcChildWithWindow extends Ipc {
|
|
|
450
582
|
this._rawIpc.addEventListener('message', wrapped);
|
|
451
583
|
}
|
|
452
584
|
}
|
|
453
|
-
const wrap$
|
|
585
|
+
const wrap$3 = window => {
|
|
454
586
|
return new IpcChildWithWindow(window);
|
|
455
587
|
};
|
|
456
588
|
|
|
457
589
|
const IpcChildWithWindow$1 = {
|
|
458
590
|
__proto__: null,
|
|
459
|
-
listen
|
|
460
|
-
signal: signal$2,
|
|
461
|
-
wrap: wrap$4
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
const removeValues = (value, toRemove) => {
|
|
465
|
-
if (!value) {
|
|
466
|
-
return value;
|
|
467
|
-
}
|
|
468
|
-
if (Array.isArray(value)) {
|
|
469
|
-
const newItems = [];
|
|
470
|
-
for (const item of value) {
|
|
471
|
-
if (!toRemove.includes(item)) {
|
|
472
|
-
newItems.push(removeValues(item, toRemove));
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
return newItems;
|
|
476
|
-
}
|
|
477
|
-
if (typeof value === 'object') {
|
|
478
|
-
const newObject = Object.create(null);
|
|
479
|
-
for (const [key, property] of Object.entries(value)) {
|
|
480
|
-
if (!toRemove.includes(property)) {
|
|
481
|
-
newObject[key] = removeValues(property, toRemove);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return newObject;
|
|
485
|
-
}
|
|
486
|
-
return value;
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
// workaround for electron not supporting transferrable objects
|
|
490
|
-
// as parameters. If the transferrable object is a parameter, in electron
|
|
491
|
-
// only an empty objected is received in the main process
|
|
492
|
-
const fixElectronParameters = value => {
|
|
493
|
-
const transfer = getTransferrables(value);
|
|
494
|
-
const newValue = removeValues(value, transfer);
|
|
495
|
-
return {
|
|
496
|
-
newValue,
|
|
497
|
-
transfer
|
|
498
|
-
};
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
const listen$1 = () => {
|
|
502
|
-
return window;
|
|
503
|
-
};
|
|
504
|
-
const signal$1 = global => {
|
|
505
|
-
global.postMessage(readyMessage);
|
|
506
|
-
};
|
|
507
|
-
class IpcChildWithElectronWindow extends Ipc {
|
|
508
|
-
getData(event) {
|
|
509
|
-
return getData$1(event);
|
|
510
|
-
}
|
|
511
|
-
send(message) {
|
|
512
|
-
this._rawIpc.postMessage(message);
|
|
513
|
-
}
|
|
514
|
-
sendAndTransfer(message) {
|
|
515
|
-
const {
|
|
516
|
-
newValue,
|
|
517
|
-
transfer
|
|
518
|
-
} = fixElectronParameters(message);
|
|
519
|
-
this._rawIpc.postMessage(newValue, location.origin, transfer);
|
|
520
|
-
}
|
|
521
|
-
dispose() {
|
|
522
|
-
// ignore
|
|
523
|
-
}
|
|
524
|
-
onClose(callback) {
|
|
525
|
-
// ignore
|
|
526
|
-
}
|
|
527
|
-
onMessage(callback) {
|
|
528
|
-
const wrapped = event => {
|
|
529
|
-
const {
|
|
530
|
-
ports
|
|
531
|
-
} = event;
|
|
532
|
-
if (ports.length) {
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
callback(event);
|
|
536
|
-
this._rawIpc.removeEventListener('message', wrapped);
|
|
537
|
-
};
|
|
538
|
-
this._rawIpc.addEventListener('message', wrapped);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
const wrap$3 = window => {
|
|
542
|
-
return new IpcChildWithElectronWindow(window);
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
const IpcChildWithElectronWindow$1 = {
|
|
546
|
-
__proto__: null,
|
|
547
|
-
listen: listen$1,
|
|
591
|
+
listen,
|
|
548
592
|
signal: signal$1,
|
|
549
593
|
wrap: wrap$3
|
|
550
594
|
};
|
|
551
595
|
|
|
552
|
-
const
|
|
553
|
-
|
|
596
|
+
const create$2 = ({
|
|
597
|
+
messagePort
|
|
554
598
|
}) => {
|
|
555
|
-
|
|
599
|
+
if (!isMessagePort(messagePort)) {
|
|
600
|
+
throw new IpcError('port must be of type MessagePort');
|
|
601
|
+
}
|
|
602
|
+
return messagePort;
|
|
556
603
|
};
|
|
557
|
-
const signal =
|
|
558
|
-
|
|
604
|
+
const signal = messagePort => {
|
|
605
|
+
messagePort.start();
|
|
559
606
|
};
|
|
560
|
-
class
|
|
607
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
561
608
|
constructor(port) {
|
|
562
609
|
super(port);
|
|
563
610
|
}
|
|
564
|
-
getData
|
|
565
|
-
return getData$1(event);
|
|
566
|
-
}
|
|
611
|
+
getData = getData$1;
|
|
567
612
|
send(message) {
|
|
568
613
|
this._rawIpc.postMessage(message);
|
|
569
614
|
}
|
|
570
615
|
sendAndTransfer(message) {
|
|
571
|
-
|
|
572
|
-
this._rawIpc.postMessage(message, transfer);
|
|
616
|
+
throw new Error('not implemented');
|
|
573
617
|
}
|
|
574
618
|
dispose() {
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
onClose(callback) {
|
|
578
|
-
// ignore
|
|
619
|
+
this._rawIpc.close();
|
|
579
620
|
}
|
|
580
621
|
onMessage(callback) {
|
|
581
622
|
this._rawIpc.addEventListener('message', callback);
|
|
582
|
-
this._rawIpc.start();
|
|
583
623
|
}
|
|
624
|
+
onClose(callback) {}
|
|
584
625
|
}
|
|
585
|
-
const wrap$2 =
|
|
586
|
-
return new
|
|
626
|
+
const wrap$2 = messagePort => {
|
|
627
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
587
628
|
};
|
|
588
629
|
|
|
589
|
-
const
|
|
630
|
+
const IpcParentWithMessagePort$1 = {
|
|
590
631
|
__proto__: null,
|
|
591
|
-
|
|
632
|
+
create: create$2,
|
|
592
633
|
signal,
|
|
593
634
|
wrap: wrap$2
|
|
594
635
|
};
|
|
@@ -808,4 +849,4 @@ const IpcParentWithWebSocket$1 = {
|
|
|
808
849
|
wrap
|
|
809
850
|
};
|
|
810
851
|
|
|
811
|
-
export { IpcChildWithElectronWindow$1 as IpcChildWithElectronWindow, IpcChildWithMessagePort$1 as IpcChildWithMessagePort, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithWindow$1 as IpcChildWithWindow, IpcParentWithModuleWorker$1 as IpcParentWithModuleWorker, IpcParentWithWebSocket$1 as IpcParentWithWebSocket };
|
|
852
|
+
export { IpcChildWithElectronWindow$1 as IpcChildWithElectronWindow, IpcChildWithMessagePort$1 as IpcChildWithMessagePort, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithWindow$1 as IpcChildWithWindow, IpcParentWithMessagePort$1 as IpcParentWithMessagePort, IpcParentWithModuleWorker$1 as IpcParentWithModuleWorker, IpcParentWithWebSocket$1 as IpcParentWithWebSocket };
|
package/dist/electron.js
CHANGED
|
@@ -356,10 +356,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
356
356
|
|
|
357
357
|
const normalizeLine = line => {
|
|
358
358
|
if (line.startsWith('Error: ')) {
|
|
359
|
-
return line.slice(
|
|
359
|
+
return line.slice('Error: '.length);
|
|
360
360
|
}
|
|
361
361
|
if (line.startsWith('VError: ')) {
|
|
362
|
-
return line.slice(
|
|
362
|
+
return line.slice('VError: '.length);
|
|
363
363
|
}
|
|
364
364
|
return line;
|
|
365
365
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -26,3 +26,4 @@ export const IpcParentWithElectronUtilityProcess: IpcParent
|
|
|
26
26
|
export const IpcParentWithNodeForkedProcess: IpcParent
|
|
27
27
|
export const IpcParentWithNodeWorker: IpcParent
|
|
28
28
|
export const IpcParentWithElectronMessagePort: IpcParent
|
|
29
|
+
export const IpcParentWithMessagePort: IpcParent
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/ipc",
|
|
3
|
-
"version": "11.0
|
|
3
|
+
"version": "11.2.0",
|
|
4
4
|
"description": "Inter Process Communication for Lvce Editor",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"keywords": [
|
|
8
9
|
"ipc"
|
|
9
10
|
],
|
|
@@ -15,8 +16,8 @@
|
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
18
|
"@lvce-editor/assert": "^1.3.0",
|
|
18
|
-
"@lvce-editor/verror": "^1.
|
|
19
|
-
"@lvce-editor/web-socket-server": "^1.
|
|
19
|
+
"@lvce-editor/verror": "^1.6.0",
|
|
20
|
+
"@lvce-editor/web-socket-server": "^1.4.0"
|
|
20
21
|
},
|
|
21
22
|
"engines": {
|
|
22
23
|
"node": ">=18"
|