@lvce-editor/test-worker 1.4.0 → 1.5.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/testWorkerMain.js +71 -82
- package/package.json +1 -1
package/dist/testWorkerMain.js
CHANGED
|
@@ -250,67 +250,6 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
250
250
|
}
|
|
251
251
|
throw new JsonRpcError('unexpected response message');
|
|
252
252
|
};
|
|
253
|
-
const isMessagePort = value => {
|
|
254
|
-
return typeof MessagePort !== 'undefined' && value instanceof MessagePort;
|
|
255
|
-
};
|
|
256
|
-
const isInstanceOf = (value, constructorName) => {
|
|
257
|
-
return value?.constructor?.name === constructorName;
|
|
258
|
-
};
|
|
259
|
-
const isMessagePortMain = value => {
|
|
260
|
-
return isInstanceOf(value, 'MessagePortMain');
|
|
261
|
-
};
|
|
262
|
-
const isOffscreenCanvas = value => {
|
|
263
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
264
|
-
};
|
|
265
|
-
const isSocket = value => {
|
|
266
|
-
return isInstanceOf(value, 'Socket');
|
|
267
|
-
};
|
|
268
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
269
|
-
const isTransferrable = value => {
|
|
270
|
-
for (const fn of transferrables) {
|
|
271
|
-
if (fn(value)) {
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return false;
|
|
276
|
-
};
|
|
277
|
-
const walkValue = (value, transferrables) => {
|
|
278
|
-
if (!value) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
if (isTransferrable(value)) {
|
|
282
|
-
transferrables.push(value);
|
|
283
|
-
}
|
|
284
|
-
if (Array.isArray(value)) {
|
|
285
|
-
for (const item of value) {
|
|
286
|
-
walkValue(item, transferrables);
|
|
287
|
-
}
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (typeof value === 'object') {
|
|
291
|
-
for (const property of Object.values(value)) {
|
|
292
|
-
walkValue(property, transferrables);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
const getTransferrables = value => {
|
|
297
|
-
const transferrables = [];
|
|
298
|
-
walkValue(value, transferrables);
|
|
299
|
-
return transferrables;
|
|
300
|
-
};
|
|
301
|
-
const isSingleTransferrable = value => {
|
|
302
|
-
return isSocket(value);
|
|
303
|
-
};
|
|
304
|
-
const getTransferrableParams = value => {
|
|
305
|
-
const transferrables = getTransferrables(value);
|
|
306
|
-
if (transferrables.length === 0) {
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
if (isSingleTransferrable(transferrables[0])) {
|
|
310
|
-
return transferrables[0];
|
|
311
|
-
}
|
|
312
|
-
return transferrables;
|
|
313
|
-
};
|
|
314
253
|
const create$1 = (message, error) => {
|
|
315
254
|
return {
|
|
316
255
|
jsonrpc: Two,
|
|
@@ -433,17 +372,15 @@ const invoke$1 = async (ipc, method, ...params) => {
|
|
|
433
372
|
// TODO deprecated old typings,
|
|
434
373
|
// always use automatic transferrable detection
|
|
435
374
|
const invokeAndTransfer$1 = async (ipc, handle, method, ...params) => {
|
|
436
|
-
let transfer = handle;
|
|
437
375
|
if (typeof handle === 'string') {
|
|
438
376
|
params = [method, ...params];
|
|
439
377
|
method = handle;
|
|
440
|
-
transfer = getTransferrableParams(params);
|
|
441
378
|
}
|
|
442
379
|
const {
|
|
443
380
|
message,
|
|
444
381
|
promise
|
|
445
382
|
} = create$2(method, params);
|
|
446
|
-
ipc.sendAndTransfer(message
|
|
383
|
+
ipc.sendAndTransfer(message);
|
|
447
384
|
const responseMessage = await promise;
|
|
448
385
|
const result = unwrapJsonRpcResult(responseMessage);
|
|
449
386
|
return result;
|
|
@@ -457,7 +394,7 @@ const invokeAndTransfer = (method, ...params) => {
|
|
|
457
394
|
const ipc = get$1();
|
|
458
395
|
return invokeAndTransfer$1(ipc, method, ...params);
|
|
459
396
|
};
|
|
460
|
-
const listen$
|
|
397
|
+
const listen$2 = ipc => {
|
|
461
398
|
set$1(ipc);
|
|
462
399
|
};
|
|
463
400
|
|
|
@@ -465,7 +402,7 @@ const Rpc = {
|
|
|
465
402
|
__proto__: null,
|
|
466
403
|
invoke,
|
|
467
404
|
invokeAndTransfer,
|
|
468
|
-
listen: listen$
|
|
405
|
+
listen: listen$2
|
|
469
406
|
};
|
|
470
407
|
|
|
471
408
|
const Fail = 'fail';
|
|
@@ -1739,6 +1676,56 @@ const Auto = () => {
|
|
|
1739
1676
|
const getData$1 = event => {
|
|
1740
1677
|
return event.data;
|
|
1741
1678
|
};
|
|
1679
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
1680
|
+
if (!value) {
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
if (isTransferrable(value)) {
|
|
1684
|
+
transferrables.push(value);
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
if (Array.isArray(value)) {
|
|
1688
|
+
for (const item of value) {
|
|
1689
|
+
walkValue(item, transferrables, isTransferrable);
|
|
1690
|
+
}
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
if (typeof value === 'object') {
|
|
1694
|
+
for (const property of Object.values(value)) {
|
|
1695
|
+
walkValue(property, transferrables, isTransferrable);
|
|
1696
|
+
}
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
const isMessagePort = value => {
|
|
1701
|
+
return value && value instanceof MessagePort;
|
|
1702
|
+
};
|
|
1703
|
+
const isMessagePortMain = value => {
|
|
1704
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
1705
|
+
};
|
|
1706
|
+
const isOffscreenCanvas = value => {
|
|
1707
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
1708
|
+
};
|
|
1709
|
+
const isInstanceOf = (value, constructorName) => {
|
|
1710
|
+
return value?.constructor?.name === constructorName;
|
|
1711
|
+
};
|
|
1712
|
+
const isSocket = value => {
|
|
1713
|
+
return isInstanceOf(value, 'Socket');
|
|
1714
|
+
};
|
|
1715
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
1716
|
+
const isTransferrable = value => {
|
|
1717
|
+
for (const fn of transferrables) {
|
|
1718
|
+
if (fn(value)) {
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
return false;
|
|
1723
|
+
};
|
|
1724
|
+
const getTransferrables = value => {
|
|
1725
|
+
const transferrables = [];
|
|
1726
|
+
walkValue(value, transferrables, isTransferrable);
|
|
1727
|
+
return transferrables;
|
|
1728
|
+
};
|
|
1742
1729
|
const attachEvents = that => {
|
|
1743
1730
|
const handleMessage = (...args) => {
|
|
1744
1731
|
const data = that.getData(...args);
|
|
@@ -1760,14 +1747,14 @@ class Ipc extends EventTarget {
|
|
|
1760
1747
|
}
|
|
1761
1748
|
}
|
|
1762
1749
|
const readyMessage = 'ready';
|
|
1763
|
-
const listen$
|
|
1750
|
+
const listen$4 = () => {
|
|
1764
1751
|
// @ts-ignore
|
|
1765
1752
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
1766
1753
|
throw new TypeError('module is not in web worker scope');
|
|
1767
1754
|
}
|
|
1768
1755
|
return globalThis;
|
|
1769
1756
|
};
|
|
1770
|
-
const signal$
|
|
1757
|
+
const signal$3 = global => {
|
|
1771
1758
|
global.postMessage(readyMessage);
|
|
1772
1759
|
};
|
|
1773
1760
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -1778,7 +1765,8 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
1778
1765
|
// @ts-ignore
|
|
1779
1766
|
this._rawIpc.postMessage(message);
|
|
1780
1767
|
}
|
|
1781
|
-
sendAndTransfer(message
|
|
1768
|
+
sendAndTransfer(message) {
|
|
1769
|
+
const transfer = getTransferrables(message);
|
|
1782
1770
|
// @ts-ignore
|
|
1783
1771
|
this._rawIpc.postMessage(message, transfer);
|
|
1784
1772
|
}
|
|
@@ -1792,14 +1780,14 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
1792
1780
|
this._rawIpc.addEventListener('message', callback);
|
|
1793
1781
|
}
|
|
1794
1782
|
}
|
|
1795
|
-
const wrap$
|
|
1783
|
+
const wrap$6 = global => {
|
|
1796
1784
|
return new IpcChildWithModuleWorker(global);
|
|
1797
1785
|
};
|
|
1798
1786
|
const IpcChildWithModuleWorker$1 = {
|
|
1799
1787
|
__proto__: null,
|
|
1800
|
-
listen: listen$
|
|
1801
|
-
signal: signal$
|
|
1802
|
-
wrap: wrap$
|
|
1788
|
+
listen: listen$4,
|
|
1789
|
+
signal: signal$3,
|
|
1790
|
+
wrap: wrap$6
|
|
1803
1791
|
};
|
|
1804
1792
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
1805
1793
|
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
@@ -2017,10 +2005,10 @@ const waitForFirstMessage = async port => {
|
|
|
2017
2005
|
// @ts-ignore
|
|
2018
2006
|
return event.data;
|
|
2019
2007
|
};
|
|
2020
|
-
const listen$
|
|
2021
|
-
const parentIpcRaw = listen$
|
|
2022
|
-
signal$
|
|
2023
|
-
const parentIpc = wrap$
|
|
2008
|
+
const listen$3 = async () => {
|
|
2009
|
+
const parentIpcRaw = listen$4();
|
|
2010
|
+
signal$3(parentIpcRaw);
|
|
2011
|
+
const parentIpc = wrap$6(parentIpcRaw);
|
|
2024
2012
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
2025
2013
|
if (firstMessage.method !== 'initialize') {
|
|
2026
2014
|
throw new IpcError('unexpected first message');
|
|
@@ -2043,7 +2031,8 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
2043
2031
|
send(message) {
|
|
2044
2032
|
this._rawIpc.postMessage(message);
|
|
2045
2033
|
}
|
|
2046
|
-
sendAndTransfer(message
|
|
2034
|
+
sendAndTransfer(message) {
|
|
2035
|
+
const transfer = getTransferrables(message);
|
|
2047
2036
|
this._rawIpc.postMessage(message, transfer);
|
|
2048
2037
|
}
|
|
2049
2038
|
dispose() {
|
|
@@ -2059,13 +2048,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
2059
2048
|
this._rawIpc.start();
|
|
2060
2049
|
}
|
|
2061
2050
|
}
|
|
2062
|
-
const wrap$
|
|
2051
|
+
const wrap$5 = port => {
|
|
2063
2052
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
2064
2053
|
};
|
|
2065
2054
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
2066
2055
|
__proto__: null,
|
|
2067
|
-
listen: listen$
|
|
2068
|
-
wrap: wrap$
|
|
2056
|
+
listen: listen$3,
|
|
2057
|
+
wrap: wrap$5
|
|
2069
2058
|
};
|
|
2070
2059
|
|
|
2071
2060
|
const getModule = method => {
|
|
@@ -2097,7 +2086,7 @@ const listen = async () => {
|
|
|
2097
2086
|
method: Auto()
|
|
2098
2087
|
});
|
|
2099
2088
|
handleIpc(ipc);
|
|
2100
|
-
listen$
|
|
2089
|
+
listen$2(ipc);
|
|
2101
2090
|
};
|
|
2102
2091
|
|
|
2103
2092
|
const main = async () => {
|