@lvce-editor/ipc 4.0.1 → 5.0.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 +104 -20
- package/dist/index.js +40 -25
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const getData$
|
|
1
|
+
const getData$2 = event => {
|
|
2
2
|
return event.data;
|
|
3
3
|
};
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ const listen$2 = () => {
|
|
|
14
14
|
const signal$1 = global => {
|
|
15
15
|
global.postMessage(readyMessage);
|
|
16
16
|
};
|
|
17
|
-
const wrap$
|
|
17
|
+
const wrap$4 = global => {
|
|
18
18
|
return {
|
|
19
19
|
global,
|
|
20
20
|
/**
|
|
@@ -32,7 +32,7 @@ const wrap$3 = global => {
|
|
|
32
32
|
},
|
|
33
33
|
set onmessage(listener) {
|
|
34
34
|
const wrappedListener = event => {
|
|
35
|
-
const data = getData$
|
|
35
|
+
const data = getData$2(event);
|
|
36
36
|
// @ts-expect-error
|
|
37
37
|
listener({
|
|
38
38
|
data,
|
|
@@ -54,7 +54,7 @@ const IpcChildWithModuleWorker = {
|
|
|
54
54
|
__proto__: null,
|
|
55
55
|
listen: listen$2,
|
|
56
56
|
signal: signal$1,
|
|
57
|
-
wrap: wrap$
|
|
57
|
+
wrap: wrap$4
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
@@ -290,7 +290,7 @@ const waitForFirstMessage = async port => {
|
|
|
290
290
|
const listen$1 = async () => {
|
|
291
291
|
const parentIpcRaw = listen$2();
|
|
292
292
|
signal$1(parentIpcRaw);
|
|
293
|
-
const parentIpc = wrap$
|
|
293
|
+
const parentIpc = wrap$4(parentIpcRaw);
|
|
294
294
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
295
295
|
if (firstMessage.method !== 'initialize') {
|
|
296
296
|
throw new IpcError('unexpected first message');
|
|
@@ -303,7 +303,7 @@ const listen$1 = async () => {
|
|
|
303
303
|
}
|
|
304
304
|
return globalThis;
|
|
305
305
|
};
|
|
306
|
-
const wrap$
|
|
306
|
+
const wrap$3 = port => {
|
|
307
307
|
return {
|
|
308
308
|
port,
|
|
309
309
|
/**
|
|
@@ -323,7 +323,7 @@ const wrap$2 = port => {
|
|
|
323
323
|
if (listener) {
|
|
324
324
|
// @ts-expect-error
|
|
325
325
|
this.wrappedListener = event => {
|
|
326
|
-
const data = getData$
|
|
326
|
+
const data = getData$2(event);
|
|
327
327
|
// @ts-expect-error
|
|
328
328
|
listener({
|
|
329
329
|
data,
|
|
@@ -341,7 +341,7 @@ const wrap$2 = port => {
|
|
|
341
341
|
const IpcChildWithModuleWorkerAndMessagePort = {
|
|
342
342
|
__proto__: null,
|
|
343
343
|
listen: listen$1,
|
|
344
|
-
wrap: wrap$
|
|
344
|
+
wrap: wrap$3
|
|
345
345
|
};
|
|
346
346
|
|
|
347
347
|
const listen = () => {
|
|
@@ -351,7 +351,7 @@ const listen = () => {
|
|
|
351
351
|
const signal = global => {
|
|
352
352
|
global.postMessage(readyMessage);
|
|
353
353
|
};
|
|
354
|
-
const wrap$
|
|
354
|
+
const wrap$2 = window => {
|
|
355
355
|
return {
|
|
356
356
|
window,
|
|
357
357
|
/**
|
|
@@ -394,35 +394,46 @@ const IpcChildWithWindow = {
|
|
|
394
394
|
__proto__: null,
|
|
395
395
|
listen,
|
|
396
396
|
signal,
|
|
397
|
-
wrap: wrap$
|
|
397
|
+
wrap: wrap$2
|
|
398
398
|
};
|
|
399
399
|
|
|
400
400
|
const Message = 'message';
|
|
401
401
|
const Error$1 = 'error';
|
|
402
402
|
|
|
403
|
+
const addListener = (emitter, type, callback) => {
|
|
404
|
+
if ('addEventListener' in emitter) {
|
|
405
|
+
emitter.addEventListener(type, callback);
|
|
406
|
+
} else {
|
|
407
|
+
emitter.on(type, callback);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
const removeListener = (emitter, type, callback) => {
|
|
411
|
+
if ('removeEventListener' in emitter) {
|
|
412
|
+
emitter.removeEventListener(type, callback);
|
|
413
|
+
} else {
|
|
414
|
+
emitter.off(type, callback);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
403
417
|
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
404
418
|
const {
|
|
405
419
|
resolve,
|
|
406
420
|
promise
|
|
407
421
|
} = withResolvers();
|
|
408
422
|
const listenerMap = Object.create(null);
|
|
409
|
-
// @ts-ignore
|
|
410
423
|
const cleanup = value => {
|
|
411
424
|
for (const event of Object.keys(eventMap)) {
|
|
412
|
-
eventEmitter
|
|
425
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
413
426
|
}
|
|
414
|
-
// @ts-ignore
|
|
415
427
|
resolve(value);
|
|
416
428
|
};
|
|
417
429
|
for (const [event, type] of Object.entries(eventMap)) {
|
|
418
|
-
// @ts-ignore
|
|
419
430
|
const listener = event => {
|
|
420
431
|
cleanup({
|
|
421
432
|
type,
|
|
422
433
|
event
|
|
423
434
|
});
|
|
424
435
|
};
|
|
425
|
-
eventEmitter
|
|
436
|
+
addListener(eventEmitter, event, listener);
|
|
426
437
|
listenerMap[event] = listener;
|
|
427
438
|
}
|
|
428
439
|
return promise;
|
|
@@ -470,7 +481,7 @@ ${relevant}`;
|
|
|
470
481
|
|
|
471
482
|
const Module = 'module';
|
|
472
483
|
|
|
473
|
-
const create = async ({
|
|
484
|
+
const create$1 = async ({
|
|
474
485
|
url,
|
|
475
486
|
name
|
|
476
487
|
}) => {
|
|
@@ -499,14 +510,14 @@ const create = async ({
|
|
|
499
510
|
}
|
|
500
511
|
return worker;
|
|
501
512
|
};
|
|
502
|
-
const getData = event => {
|
|
513
|
+
const getData$1 = event => {
|
|
503
514
|
// TODO why are some events not instance of message event?
|
|
504
515
|
if (event instanceof MessageEvent) {
|
|
505
516
|
return event.data;
|
|
506
517
|
}
|
|
507
518
|
return event;
|
|
508
519
|
};
|
|
509
|
-
const wrap = worker => {
|
|
520
|
+
const wrap$1 = worker => {
|
|
510
521
|
let handleMessage;
|
|
511
522
|
return {
|
|
512
523
|
get onmessage() {
|
|
@@ -515,7 +526,7 @@ const wrap = worker => {
|
|
|
515
526
|
set onmessage(listener) {
|
|
516
527
|
if (listener) {
|
|
517
528
|
handleMessage = event => {
|
|
518
|
-
const data = getData(event);
|
|
529
|
+
const data = getData$1(event);
|
|
519
530
|
listener({
|
|
520
531
|
data,
|
|
521
532
|
target: this
|
|
@@ -536,9 +547,82 @@ const wrap = worker => {
|
|
|
536
547
|
};
|
|
537
548
|
|
|
538
549
|
const IpcParentWithModuleWorker = {
|
|
550
|
+
__proto__: null,
|
|
551
|
+
create: create$1,
|
|
552
|
+
wrap: wrap$1
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
const Open = 1;
|
|
556
|
+
const Close = 2;
|
|
557
|
+
|
|
558
|
+
const stringifyCompact = value => {
|
|
559
|
+
return JSON.stringify(value);
|
|
560
|
+
};
|
|
561
|
+
const parse = content => {
|
|
562
|
+
if (content === 'undefined') {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
try {
|
|
566
|
+
return JSON.parse(content);
|
|
567
|
+
} catch (error) {
|
|
568
|
+
throw new VError(error, 'failed to parse json');
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const waitForWebSocketToBeOpen = webSocket => {
|
|
573
|
+
return getFirstEvent(webSocket, {
|
|
574
|
+
open: Open,
|
|
575
|
+
close: Close
|
|
576
|
+
});
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
const create = async ({
|
|
580
|
+
webSocket
|
|
581
|
+
}) => {
|
|
582
|
+
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
583
|
+
// @ts-ignore
|
|
584
|
+
if (firstWebSocketEvent.type === Close) {
|
|
585
|
+
throw new IpcError('Websocket connection was immediately closed');
|
|
586
|
+
}
|
|
587
|
+
return webSocket;
|
|
588
|
+
};
|
|
589
|
+
const getData = event => {
|
|
590
|
+
return parse(event.data);
|
|
591
|
+
};
|
|
592
|
+
const wrap = webSocket => {
|
|
593
|
+
return {
|
|
594
|
+
webSocket,
|
|
595
|
+
/**
|
|
596
|
+
* @type {any}
|
|
597
|
+
*/
|
|
598
|
+
listener: undefined,
|
|
599
|
+
get onmessage() {
|
|
600
|
+
return this.listener;
|
|
601
|
+
},
|
|
602
|
+
set onmessage(listener) {
|
|
603
|
+
this.listener = listener;
|
|
604
|
+
const wrappedListener = event => {
|
|
605
|
+
const data = getData(event);
|
|
606
|
+
const syntheticEvent = {
|
|
607
|
+
data,
|
|
608
|
+
target: this
|
|
609
|
+
};
|
|
610
|
+
// @ts-ignore
|
|
611
|
+
listener(syntheticEvent);
|
|
612
|
+
};
|
|
613
|
+
this.webSocket.onmessage = wrappedListener;
|
|
614
|
+
},
|
|
615
|
+
send(message) {
|
|
616
|
+
const stringifiedMessage = stringifyCompact(message);
|
|
617
|
+
this.webSocket.send(stringifiedMessage);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
const IpcParentWithWebSocket = {
|
|
539
623
|
__proto__: null,
|
|
540
624
|
create,
|
|
541
625
|
wrap
|
|
542
626
|
};
|
|
543
627
|
|
|
544
|
-
export { IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort, IpcChildWithWindow, IpcParentWithModuleWorker };
|
|
628
|
+
export { IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort, IpcChildWithWindow, IpcParentWithModuleWorker, IpcParentWithWebSocket };
|
package/dist/index.js
CHANGED
|
@@ -150,7 +150,6 @@ const isMessagePortMain = value => {
|
|
|
150
150
|
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
151
151
|
};
|
|
152
152
|
|
|
153
|
-
// @ts-ignore
|
|
154
153
|
const listen$7 = ({
|
|
155
154
|
messagePort
|
|
156
155
|
}) => {
|
|
@@ -159,8 +158,9 @@ const listen$7 = ({
|
|
|
159
158
|
}
|
|
160
159
|
return messagePort;
|
|
161
160
|
};
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
const signal$6 = messagePort => {
|
|
162
|
+
messagePort.start();
|
|
163
|
+
};
|
|
164
164
|
const getActualData$1 = event => {
|
|
165
165
|
const {
|
|
166
166
|
data,
|
|
@@ -174,12 +174,9 @@ const getActualData$1 = event => {
|
|
|
174
174
|
params: [...ports, ...data.params]
|
|
175
175
|
};
|
|
176
176
|
};
|
|
177
|
-
|
|
178
|
-
// @ts-ignore
|
|
179
177
|
const wrap$a = messagePort => {
|
|
180
178
|
return {
|
|
181
179
|
messagePort,
|
|
182
|
-
// @ts-ignore
|
|
183
180
|
on(event, listener) {
|
|
184
181
|
if (event === 'message') {
|
|
185
182
|
// @ts-ignore
|
|
@@ -198,11 +195,9 @@ const wrap$a = messagePort => {
|
|
|
198
195
|
throw new Error('unsupported event type');
|
|
199
196
|
}
|
|
200
197
|
},
|
|
201
|
-
// @ts-ignore
|
|
202
198
|
off(event, listener) {
|
|
203
199
|
this.messagePort.off(event, listener);
|
|
204
200
|
},
|
|
205
|
-
// @ts-ignore
|
|
206
201
|
send(message) {
|
|
207
202
|
this.messagePort.postMessage(message);
|
|
208
203
|
},
|
|
@@ -210,7 +205,7 @@ const wrap$a = messagePort => {
|
|
|
210
205
|
this.messagePort.close();
|
|
211
206
|
},
|
|
212
207
|
start() {
|
|
213
|
-
|
|
208
|
+
throw new Error('start method is deprecated');
|
|
214
209
|
}
|
|
215
210
|
};
|
|
216
211
|
};
|
|
@@ -218,6 +213,7 @@ const wrap$a = messagePort => {
|
|
|
218
213
|
const IpcChildWithElectronMessagePort = {
|
|
219
214
|
__proto__: null,
|
|
220
215
|
listen: listen$7,
|
|
216
|
+
signal: signal$6,
|
|
221
217
|
wrap: wrap$a
|
|
222
218
|
};
|
|
223
219
|
|
|
@@ -250,7 +246,7 @@ const listen$6 = () => {
|
|
|
250
246
|
};
|
|
251
247
|
|
|
252
248
|
// @ts-ignore
|
|
253
|
-
const signal$
|
|
249
|
+
const signal$5 = parentPort => {
|
|
254
250
|
parentPort.postMessage(readyMessage);
|
|
255
251
|
};
|
|
256
252
|
|
|
@@ -298,7 +294,7 @@ const wrap$9 = parentPort => {
|
|
|
298
294
|
const IpcChildWithElectronUtilityProcess = {
|
|
299
295
|
__proto__: null,
|
|
300
296
|
listen: listen$6,
|
|
301
|
-
signal: signal$
|
|
297
|
+
signal: signal$5,
|
|
302
298
|
wrap: wrap$9
|
|
303
299
|
};
|
|
304
300
|
|
|
@@ -313,7 +309,7 @@ const listen$5 = () => {
|
|
|
313
309
|
}
|
|
314
310
|
return globalThis;
|
|
315
311
|
};
|
|
316
|
-
const signal$
|
|
312
|
+
const signal$4 = global => {
|
|
317
313
|
global.postMessage(readyMessage);
|
|
318
314
|
};
|
|
319
315
|
const wrap$8 = global => {
|
|
@@ -355,7 +351,7 @@ const wrap$8 = global => {
|
|
|
355
351
|
const IpcChildWithModuleWorker = {
|
|
356
352
|
__proto__: null,
|
|
357
353
|
listen: listen$5,
|
|
358
|
-
signal: signal$
|
|
354
|
+
signal: signal$4,
|
|
359
355
|
wrap: wrap$8
|
|
360
356
|
};
|
|
361
357
|
|
|
@@ -390,7 +386,7 @@ const waitForFirstMessage = async port => {
|
|
|
390
386
|
|
|
391
387
|
const listen$4 = async () => {
|
|
392
388
|
const parentIpcRaw = listen$5();
|
|
393
|
-
signal$
|
|
389
|
+
signal$4(parentIpcRaw);
|
|
394
390
|
const parentIpc = wrap$8(parentIpcRaw);
|
|
395
391
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
396
392
|
if (firstMessage.method !== 'initialize') {
|
|
@@ -453,7 +449,7 @@ const listen$3 = async () => {
|
|
|
453
449
|
};
|
|
454
450
|
|
|
455
451
|
// @ts-ignore
|
|
456
|
-
const signal$
|
|
452
|
+
const signal$3 = process => {
|
|
457
453
|
process.send(readyMessage);
|
|
458
454
|
};
|
|
459
455
|
|
|
@@ -506,7 +502,7 @@ const wrap$6 = process => {
|
|
|
506
502
|
const IpcChildWithNodeForkedProcess = {
|
|
507
503
|
__proto__: null,
|
|
508
504
|
listen: listen$3,
|
|
509
|
-
signal: signal$
|
|
505
|
+
signal: signal$3,
|
|
510
506
|
wrap: wrap$6
|
|
511
507
|
};
|
|
512
508
|
|
|
@@ -522,6 +518,9 @@ const listen$2 = async ({
|
|
|
522
518
|
}
|
|
523
519
|
return messagePort;
|
|
524
520
|
};
|
|
521
|
+
const signal$2 = messagePort => {
|
|
522
|
+
messagePort.start();
|
|
523
|
+
};
|
|
525
524
|
const wrap$5 = port => {
|
|
526
525
|
return {
|
|
527
526
|
port,
|
|
@@ -545,7 +544,7 @@ const wrap$5 = port => {
|
|
|
545
544
|
this.port.close();
|
|
546
545
|
},
|
|
547
546
|
start() {
|
|
548
|
-
|
|
547
|
+
throw new Error('start method is deprecated');
|
|
549
548
|
}
|
|
550
549
|
};
|
|
551
550
|
};
|
|
@@ -553,6 +552,7 @@ const wrap$5 = port => {
|
|
|
553
552
|
const IpcChildWithNodeMessagePort = {
|
|
554
553
|
__proto__: null,
|
|
555
554
|
listen: listen$2,
|
|
555
|
+
signal: signal$2,
|
|
556
556
|
wrap: wrap$5
|
|
557
557
|
};
|
|
558
558
|
|
|
@@ -565,7 +565,7 @@ const listen$1 = async () => {
|
|
|
565
565
|
}
|
|
566
566
|
return parentPort;
|
|
567
567
|
};
|
|
568
|
-
const signal = parentPort => {
|
|
568
|
+
const signal$1 = parentPort => {
|
|
569
569
|
parentPort.postMessage(readyMessage);
|
|
570
570
|
};
|
|
571
571
|
const wrap$4 = parentPort => {
|
|
@@ -596,36 +596,47 @@ const wrap$4 = parentPort => {
|
|
|
596
596
|
const IpcChildWithNodeWorker = {
|
|
597
597
|
__proto__: null,
|
|
598
598
|
listen: listen$1,
|
|
599
|
-
signal,
|
|
599
|
+
signal: signal$1,
|
|
600
600
|
wrap: wrap$4
|
|
601
601
|
};
|
|
602
602
|
|
|
603
603
|
const Open = 1;
|
|
604
604
|
const Close = 2;
|
|
605
605
|
|
|
606
|
+
const addListener = (emitter, type, callback) => {
|
|
607
|
+
if ('addEventListener' in emitter) {
|
|
608
|
+
emitter.addEventListener(type, callback);
|
|
609
|
+
} else {
|
|
610
|
+
emitter.on(type, callback);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
const removeListener = (emitter, type, callback) => {
|
|
614
|
+
if ('removeEventListener' in emitter) {
|
|
615
|
+
emitter.removeEventListener(type, callback);
|
|
616
|
+
} else {
|
|
617
|
+
emitter.off(type, callback);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
606
620
|
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
607
621
|
const {
|
|
608
622
|
resolve,
|
|
609
623
|
promise
|
|
610
624
|
} = withResolvers();
|
|
611
625
|
const listenerMap = Object.create(null);
|
|
612
|
-
// @ts-ignore
|
|
613
626
|
const cleanup = value => {
|
|
614
627
|
for (const event of Object.keys(eventMap)) {
|
|
615
|
-
eventEmitter
|
|
628
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
616
629
|
}
|
|
617
|
-
// @ts-ignore
|
|
618
630
|
resolve(value);
|
|
619
631
|
};
|
|
620
632
|
for (const [event, type] of Object.entries(eventMap)) {
|
|
621
|
-
// @ts-ignore
|
|
622
633
|
const listener = event => {
|
|
623
634
|
cleanup({
|
|
624
635
|
type,
|
|
625
636
|
event
|
|
626
637
|
});
|
|
627
638
|
};
|
|
628
|
-
eventEmitter
|
|
639
|
+
addListener(eventEmitter, event, listener);
|
|
629
640
|
listenerMap[event] = listener;
|
|
630
641
|
}
|
|
631
642
|
return promise;
|
|
@@ -707,6 +718,9 @@ const listen = async ({
|
|
|
707
718
|
}
|
|
708
719
|
return webSocket;
|
|
709
720
|
};
|
|
721
|
+
const signal = webSocket => {
|
|
722
|
+
webSocket.resume();
|
|
723
|
+
};
|
|
710
724
|
|
|
711
725
|
// @ts-ignore
|
|
712
726
|
const wrap$3 = webSocket => {
|
|
@@ -751,7 +765,7 @@ const wrap$3 = webSocket => {
|
|
|
751
765
|
this.webSocket.close();
|
|
752
766
|
},
|
|
753
767
|
start() {
|
|
754
|
-
|
|
768
|
+
throw new Error('start method is deprecated');
|
|
755
769
|
}
|
|
756
770
|
};
|
|
757
771
|
};
|
|
@@ -759,6 +773,7 @@ const wrap$3 = webSocket => {
|
|
|
759
773
|
const IpcChildWithWebSocket = {
|
|
760
774
|
__proto__: null,
|
|
761
775
|
listen,
|
|
776
|
+
signal,
|
|
762
777
|
wrap: wrap$3
|
|
763
778
|
};
|
|
764
779
|
|