@lvce-editor/iframe-worker 2.0.0 → 2.1.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/iframeWorkerMain.js +65 -57
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
const commands = Object.create(null);
|
|
2
|
-
const register = commandMap => {
|
|
3
|
-
Object.assign(commands, commandMap);
|
|
4
|
-
};
|
|
5
|
-
const getCommand = key => {
|
|
6
|
-
return commands[key];
|
|
7
|
-
};
|
|
8
|
-
const execute = (command, ...args) => {
|
|
9
|
-
const fn = getCommand(command);
|
|
10
|
-
if (!fn) {
|
|
11
|
-
throw new Error(`command not found ${command}`);
|
|
12
|
-
}
|
|
13
|
-
return fn(...args);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
1
|
const Two = '2.0';
|
|
17
2
|
const state = {
|
|
18
3
|
callbacks: Object.create(null)
|
|
@@ -232,7 +217,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
232
217
|
}
|
|
233
218
|
};
|
|
234
219
|
};
|
|
235
|
-
const create$1 = (message, error) => {
|
|
220
|
+
const create$1$1 = (message, error) => {
|
|
236
221
|
return {
|
|
237
222
|
jsonrpc: Two,
|
|
238
223
|
id: message.id,
|
|
@@ -243,9 +228,9 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
243
228
|
const prettyError = preparePrettyError(error);
|
|
244
229
|
logError(error, prettyError);
|
|
245
230
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
246
|
-
return create$1(message, errorProperty);
|
|
231
|
+
return create$1$1(message, errorProperty);
|
|
247
232
|
};
|
|
248
|
-
const create
|
|
233
|
+
const create = (message, result) => {
|
|
249
234
|
return {
|
|
250
235
|
jsonrpc: Two,
|
|
251
236
|
id: message.id,
|
|
@@ -254,7 +239,7 @@ const create$4 = (message, result) => {
|
|
|
254
239
|
};
|
|
255
240
|
const getSuccessResponse = (message, result) => {
|
|
256
241
|
const resultProperty = result ?? null;
|
|
257
|
-
return create
|
|
242
|
+
return create(message, resultProperty);
|
|
258
243
|
};
|
|
259
244
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
260
245
|
try {
|
|
@@ -335,19 +320,60 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
335
320
|
message,
|
|
336
321
|
promise
|
|
337
322
|
} = create$2(method, params);
|
|
338
|
-
{
|
|
323
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
324
|
+
ipc.sendAndTransfer(message);
|
|
325
|
+
} else {
|
|
339
326
|
ipc.send(message);
|
|
340
327
|
}
|
|
341
328
|
const responseMessage = await promise;
|
|
342
329
|
return unwrapJsonRpcResult(responseMessage);
|
|
343
330
|
};
|
|
344
331
|
const invoke = (ipc, method, ...params) => {
|
|
345
|
-
return invokeHelper(ipc, method, params);
|
|
332
|
+
return invokeHelper(ipc, method, params, false);
|
|
333
|
+
};
|
|
334
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
335
|
+
return invokeHelper(ipc, method, params, true);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const commands = Object.create(null);
|
|
339
|
+
const register = commandMap => {
|
|
340
|
+
Object.assign(commands, commandMap);
|
|
341
|
+
};
|
|
342
|
+
const getCommand = key => {
|
|
343
|
+
return commands[key];
|
|
344
|
+
};
|
|
345
|
+
const execute = (command, ...args) => {
|
|
346
|
+
const fn = getCommand(command);
|
|
347
|
+
if (!fn) {
|
|
348
|
+
throw new Error(`command not found ${command}`);
|
|
349
|
+
}
|
|
350
|
+
return fn(...args);
|
|
346
351
|
};
|
|
347
352
|
|
|
348
353
|
const getData$1 = event => {
|
|
349
354
|
return event.data;
|
|
350
355
|
};
|
|
356
|
+
const attachEvents = that => {
|
|
357
|
+
const handleMessage = (...args) => {
|
|
358
|
+
const data = that.getData(...args);
|
|
359
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
360
|
+
data
|
|
361
|
+
}));
|
|
362
|
+
};
|
|
363
|
+
that.onMessage(handleMessage);
|
|
364
|
+
const handleClose = event => {
|
|
365
|
+
that.dispatchEvent(new Event('close'));
|
|
366
|
+
};
|
|
367
|
+
that.onClose(handleClose);
|
|
368
|
+
};
|
|
369
|
+
class Ipc extends EventTarget {
|
|
370
|
+
constructor(rawIpc) {
|
|
371
|
+
super();
|
|
372
|
+
this._rawIpc = rawIpc;
|
|
373
|
+
attachEvents(this);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const readyMessage = 'ready';
|
|
351
377
|
const walkValue = (value, transferrables, isTransferrable) => {
|
|
352
378
|
if (!value) {
|
|
353
379
|
return;
|
|
@@ -398,35 +424,14 @@ const getTransferrables = value => {
|
|
|
398
424
|
walkValue(value, transferrables, isTransferrable);
|
|
399
425
|
return transferrables;
|
|
400
426
|
};
|
|
401
|
-
const
|
|
402
|
-
const handleMessage = (...args) => {
|
|
403
|
-
const data = that.getData(...args);
|
|
404
|
-
that.dispatchEvent(new MessageEvent('message', {
|
|
405
|
-
data
|
|
406
|
-
}));
|
|
407
|
-
};
|
|
408
|
-
that.onMessage(handleMessage);
|
|
409
|
-
const handleClose = event => {
|
|
410
|
-
that.dispatchEvent(new Event('close'));
|
|
411
|
-
};
|
|
412
|
-
that.onClose(handleClose);
|
|
413
|
-
};
|
|
414
|
-
class Ipc extends EventTarget {
|
|
415
|
-
constructor(rawIpc) {
|
|
416
|
-
super();
|
|
417
|
-
this._rawIpc = rawIpc;
|
|
418
|
-
attachEvents(this);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const readyMessage = 'ready';
|
|
422
|
-
const listen$4 = () => {
|
|
427
|
+
const listen$2 = () => {
|
|
423
428
|
// @ts-ignore
|
|
424
429
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
425
430
|
throw new TypeError('module is not in web worker scope');
|
|
426
431
|
}
|
|
427
432
|
return globalThis;
|
|
428
433
|
};
|
|
429
|
-
const signal$
|
|
434
|
+
const signal$2 = global => {
|
|
430
435
|
global.postMessage(readyMessage);
|
|
431
436
|
};
|
|
432
437
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -452,7 +457,7 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
452
457
|
this._rawIpc.addEventListener('message', callback);
|
|
453
458
|
}
|
|
454
459
|
}
|
|
455
|
-
const wrap$
|
|
460
|
+
const wrap$5 = global => {
|
|
456
461
|
return new IpcChildWithModuleWorker(global);
|
|
457
462
|
};
|
|
458
463
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
@@ -570,10 +575,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
570
575
|
};
|
|
571
576
|
const normalizeLine$1 = line => {
|
|
572
577
|
if (line.startsWith('Error: ')) {
|
|
573
|
-
return line.slice(
|
|
578
|
+
return line.slice('Error: '.length);
|
|
574
579
|
}
|
|
575
580
|
if (line.startsWith('VError: ')) {
|
|
576
|
-
return line.slice(
|
|
581
|
+
return line.slice('VError: '.length);
|
|
577
582
|
}
|
|
578
583
|
return line;
|
|
579
584
|
};
|
|
@@ -671,10 +676,10 @@ const waitForFirstMessage = async port => {
|
|
|
671
676
|
// @ts-ignore
|
|
672
677
|
return event.data;
|
|
673
678
|
};
|
|
674
|
-
const listen$
|
|
675
|
-
const parentIpcRaw = listen$
|
|
676
|
-
signal$
|
|
677
|
-
const parentIpc = wrap$
|
|
679
|
+
const listen$1$1 = async () => {
|
|
680
|
+
const parentIpcRaw = listen$2();
|
|
681
|
+
signal$2(parentIpcRaw);
|
|
682
|
+
const parentIpc = wrap$5(parentIpcRaw);
|
|
678
683
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
679
684
|
if (firstMessage.method !== 'initialize') {
|
|
680
685
|
throw new IpcError('unexpected first message');
|
|
@@ -719,19 +724,22 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
719
724
|
this._rawIpc.start();
|
|
720
725
|
}
|
|
721
726
|
}
|
|
722
|
-
const wrap$
|
|
727
|
+
const wrap$4 = port => {
|
|
723
728
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
724
729
|
};
|
|
725
730
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
726
731
|
__proto__: null,
|
|
727
|
-
listen: listen$
|
|
728
|
-
wrap: wrap$
|
|
732
|
+
listen: listen$1$1,
|
|
733
|
+
wrap: wrap$4
|
|
729
734
|
};
|
|
730
735
|
|
|
731
736
|
const createRpc = ipc => {
|
|
732
737
|
const rpc = {
|
|
733
738
|
invoke(method, ...params) {
|
|
734
739
|
return invoke(ipc, method, ...params);
|
|
740
|
+
},
|
|
741
|
+
invokeAndTransfer(method, ...params) {
|
|
742
|
+
return invokeAndTransfer(ipc, method, ...params);
|
|
735
743
|
}
|
|
736
744
|
};
|
|
737
745
|
return rpc;
|
|
@@ -759,7 +767,7 @@ const listen$1 = async () => {
|
|
|
759
767
|
const ipc = module.wrap(rawIpc);
|
|
760
768
|
return ipc;
|
|
761
769
|
};
|
|
762
|
-
const create = async ({
|
|
770
|
+
const create$1 = async ({
|
|
763
771
|
commandMap
|
|
764
772
|
}) => {
|
|
765
773
|
// TODO create a commandMap per rpc instance
|
|
@@ -771,7 +779,7 @@ const create = async ({
|
|
|
771
779
|
};
|
|
772
780
|
const WebWorkerRpcClient = {
|
|
773
781
|
__proto__: null,
|
|
774
|
-
create
|
|
782
|
+
create: create$1
|
|
775
783
|
};
|
|
776
784
|
|
|
777
785
|
const createUrl = (protocol, host) => {
|
|
@@ -850,7 +858,7 @@ const getWebViewHtml = (baseUrl, locationOrigin, elements) => {
|
|
|
850
858
|
}
|
|
851
859
|
}
|
|
852
860
|
const middleHtml = middle.join('\n ');
|
|
853
|
-
|
|
861
|
+
const html = `<!DOCTYPE html>
|
|
854
862
|
<html>
|
|
855
863
|
<head>
|
|
856
864
|
${middleHtml}
|