@lvce-editor/editor-worker 2.6.0 → 3.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.
@@ -1372,67 +1372,6 @@ const unwrapJsonRpcResult = responseMessage => {
1372
1372
  }
1373
1373
  throw new JsonRpcError('unexpected response message');
1374
1374
  };
1375
- const isMessagePort = value => {
1376
- return typeof MessagePort !== 'undefined' && value instanceof MessagePort;
1377
- };
1378
- const isInstanceOf = (value, constructorName) => {
1379
- return value?.constructor?.name === constructorName;
1380
- };
1381
- const isMessagePortMain = value => {
1382
- return isInstanceOf(value, 'MessagePortMain');
1383
- };
1384
- const isOffscreenCanvas = value => {
1385
- return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
1386
- };
1387
- const isSocket = value => {
1388
- return isInstanceOf(value, 'Socket');
1389
- };
1390
- const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
1391
- const isTransferrable = value => {
1392
- for (const fn of transferrables) {
1393
- if (fn(value)) {
1394
- return true;
1395
- }
1396
- }
1397
- return false;
1398
- };
1399
- const walkValue = (value, transferrables) => {
1400
- if (!value) {
1401
- return;
1402
- }
1403
- if (isTransferrable(value)) {
1404
- transferrables.push(value);
1405
- }
1406
- if (Array.isArray(value)) {
1407
- for (const item of value) {
1408
- walkValue(item, transferrables);
1409
- }
1410
- return;
1411
- }
1412
- if (typeof value === 'object') {
1413
- for (const property of Object.values(value)) {
1414
- walkValue(property, transferrables);
1415
- }
1416
- }
1417
- };
1418
- const getTransferrables = value => {
1419
- const transferrables = [];
1420
- walkValue(value, transferrables);
1421
- return transferrables;
1422
- };
1423
- const isSingleTransferrable = value => {
1424
- return isSocket(value);
1425
- };
1426
- const getTransferrableParams = value => {
1427
- const transferrables = getTransferrables(value);
1428
- if (transferrables.length === 0) {
1429
- return undefined;
1430
- }
1431
- if (isSingleTransferrable(transferrables[0])) {
1432
- return transferrables[0];
1433
- }
1434
- return transferrables;
1435
- };
1436
1375
  const create$1$1 = (message, error) => {
1437
1376
  return {
1438
1377
  jsonrpc: Two,
@@ -1555,17 +1494,15 @@ const invoke$5 = async (ipc, method, ...params) => {
1555
1494
  // TODO deprecated old typings,
1556
1495
  // always use automatic transferrable detection
1557
1496
  const invokeAndTransfer$2 = async (ipc, handle, method, ...params) => {
1558
- let transfer = handle;
1559
1497
  if (typeof handle === 'string') {
1560
1498
  params = [method, ...params];
1561
1499
  method = handle;
1562
- transfer = getTransferrableParams(params);
1563
1500
  }
1564
1501
  const {
1565
1502
  message,
1566
1503
  promise
1567
1504
  } = create$2$1(method, params);
1568
- ipc.sendAndTransfer(message, transfer);
1505
+ ipc.sendAndTransfer(message);
1569
1506
  const responseMessage = await promise;
1570
1507
  const result = unwrapJsonRpcResult(responseMessage);
1571
1508
  return result;
@@ -3417,7 +3354,7 @@ const goTo = async ({
3417
3354
  endRowIndex: definition.endRowIndex,
3418
3355
  endColumnIndex: definition.endColumnIndex
3419
3356
  };
3420
- await invoke$3( /* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
3357
+ await invoke$3(/* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
3421
3358
  return editor;
3422
3359
  } catch (error) {
3423
3360
  // TODO if editor is already disposed at this point, do nothing
@@ -3542,7 +3479,7 @@ const goToTypeDefinition = (editor, explicit = true) => {
3542
3479
  const Editor = 3;
3543
3480
 
3544
3481
  const handleContextMenu = async (editor, button, x, y) => {
3545
- await invoke$3( /* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
3482
+ await invoke$3(/* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
3546
3483
  return editor;
3547
3484
  };
3548
3485
 
@@ -6412,7 +6349,7 @@ const toggleComment = async editor => {
6412
6349
  } catch (error$1) {
6413
6350
  error(error$1);
6414
6351
  // TODO use correct position
6415
- await editorShowMessage( /* editor */editor, /* rowIndex */0, /* columnIndex */0, /* message */`${error$1}`, /* isError */true);
6352
+ await editorShowMessage(/* editor */editor, /* rowIndex */0, /* columnIndex */0, /* message */`${error$1}`, /* isError */true);
6416
6353
  return editor;
6417
6354
  }
6418
6355
  };
@@ -8894,6 +8831,56 @@ const Auto = () => {
8894
8831
  const getData$1 = event => {
8895
8832
  return event.data;
8896
8833
  };
8834
+ const walkValue = (value, transferrables, isTransferrable) => {
8835
+ if (!value) {
8836
+ return;
8837
+ }
8838
+ if (isTransferrable(value)) {
8839
+ transferrables.push(value);
8840
+ return;
8841
+ }
8842
+ if (Array.isArray(value)) {
8843
+ for (const item of value) {
8844
+ walkValue(item, transferrables, isTransferrable);
8845
+ }
8846
+ return;
8847
+ }
8848
+ if (typeof value === 'object') {
8849
+ for (const property of Object.values(value)) {
8850
+ walkValue(property, transferrables, isTransferrable);
8851
+ }
8852
+ return;
8853
+ }
8854
+ };
8855
+ const isMessagePort = value => {
8856
+ return value && value instanceof MessagePort;
8857
+ };
8858
+ const isMessagePortMain = value => {
8859
+ return value && value.constructor && value.constructor.name === 'MessagePortMain';
8860
+ };
8861
+ const isOffscreenCanvas = value => {
8862
+ return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
8863
+ };
8864
+ const isInstanceOf = (value, constructorName) => {
8865
+ return value?.constructor?.name === constructorName;
8866
+ };
8867
+ const isSocket = value => {
8868
+ return isInstanceOf(value, 'Socket');
8869
+ };
8870
+ const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
8871
+ const isTransferrable = value => {
8872
+ for (const fn of transferrables) {
8873
+ if (fn(value)) {
8874
+ return true;
8875
+ }
8876
+ }
8877
+ return false;
8878
+ };
8879
+ const getTransferrables = value => {
8880
+ const transferrables = [];
8881
+ walkValue(value, transferrables, isTransferrable);
8882
+ return transferrables;
8883
+ };
8897
8884
  const attachEvents = that => {
8898
8885
  const handleMessage = (...args) => {
8899
8886
  const data = that.getData(...args);
@@ -8915,14 +8902,14 @@ class Ipc extends EventTarget {
8915
8902
  }
8916
8903
  }
8917
8904
  const readyMessage = 'ready';
8918
- const listen$3 = () => {
8905
+ const listen$4 = () => {
8919
8906
  // @ts-ignore
8920
8907
  if (typeof WorkerGlobalScope === 'undefined') {
8921
8908
  throw new TypeError('module is not in web worker scope');
8922
8909
  }
8923
8910
  return globalThis;
8924
8911
  };
8925
- const signal$2 = global => {
8912
+ const signal$3 = global => {
8926
8913
  global.postMessage(readyMessage);
8927
8914
  };
8928
8915
  class IpcChildWithModuleWorker extends Ipc {
@@ -8933,7 +8920,8 @@ class IpcChildWithModuleWorker extends Ipc {
8933
8920
  // @ts-ignore
8934
8921
  this._rawIpc.postMessage(message);
8935
8922
  }
8936
- sendAndTransfer(message, transfer) {
8923
+ sendAndTransfer(message) {
8924
+ const transfer = getTransferrables(message);
8937
8925
  // @ts-ignore
8938
8926
  this._rawIpc.postMessage(message, transfer);
8939
8927
  }
@@ -8947,14 +8935,14 @@ class IpcChildWithModuleWorker extends Ipc {
8947
8935
  this._rawIpc.addEventListener('message', callback);
8948
8936
  }
8949
8937
  }
8950
- const wrap$5 = global => {
8938
+ const wrap$6 = global => {
8951
8939
  return new IpcChildWithModuleWorker(global);
8952
8940
  };
8953
8941
  const IpcChildWithModuleWorker$1 = {
8954
8942
  __proto__: null,
8955
- listen: listen$3,
8956
- signal: signal$2,
8957
- wrap: wrap$5
8943
+ listen: listen$4,
8944
+ signal: signal$3,
8945
+ wrap: wrap$6
8958
8946
  };
8959
8947
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
8960
8948
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
@@ -8966,6 +8954,18 @@ const joinLines = lines => {
8966
8954
  const splitLines = lines => {
8967
8955
  return lines.split(NewLine$1);
8968
8956
  };
8957
+ const isModuleNotFoundMessage = line => {
8958
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
8959
+ };
8960
+ const getModuleNotFoundError = stderr => {
8961
+ const lines = splitLines(stderr);
8962
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
8963
+ const message = lines[messageIndex];
8964
+ return {
8965
+ message,
8966
+ code: ERR_MODULE_NOT_FOUND
8967
+ };
8968
+ };
8969
8969
  const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
8970
8970
  const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
8971
8971
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
@@ -9014,18 +9014,6 @@ const isModuleNotFoundError = stderr => {
9014
9014
  }
9015
9015
  return stderr.includes('ERR_MODULE_NOT_FOUND');
9016
9016
  };
9017
- const isModuleNotFoundMessage = line => {
9018
- return line.includes('ERR_MODULE_NOT_FOUND');
9019
- };
9020
- const getModuleNotFoundError = stderr => {
9021
- const lines = splitLines(stderr);
9022
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
9023
- const message = lines[messageIndex];
9024
- return {
9025
- message,
9026
- code: ERR_MODULE_NOT_FOUND
9027
- };
9028
- };
9029
9017
  const isNormalStackLine = line => {
9030
9018
  return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
9031
9019
  };
@@ -9172,16 +9160,21 @@ const waitForFirstMessage = async port => {
9172
9160
  // @ts-ignore
9173
9161
  return event.data;
9174
9162
  };
9175
- const listen$2 = async () => {
9176
- const parentIpcRaw = listen$3();
9177
- signal$2(parentIpcRaw);
9178
- const parentIpc = wrap$5(parentIpcRaw);
9163
+ const listen$3 = async () => {
9164
+ const parentIpcRaw = listen$4();
9165
+ signal$3(parentIpcRaw);
9166
+ const parentIpc = wrap$6(parentIpcRaw);
9179
9167
  const firstMessage = await waitForFirstMessage(parentIpc);
9180
9168
  if (firstMessage.method !== 'initialize') {
9181
9169
  throw new IpcError('unexpected first message');
9182
9170
  }
9183
9171
  const type = firstMessage.params[0];
9184
9172
  if (type === 'message-port') {
9173
+ parentIpc.send({
9174
+ jsonrpc: '2.0',
9175
+ id: firstMessage.id,
9176
+ result: null
9177
+ });
9185
9178
  parentIpc.dispose();
9186
9179
  const port = firstMessage.params[1];
9187
9180
  return port;
@@ -9198,7 +9191,8 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
9198
9191
  send(message) {
9199
9192
  this._rawIpc.postMessage(message);
9200
9193
  }
9201
- sendAndTransfer(message, transfer) {
9194
+ sendAndTransfer(message) {
9195
+ const transfer = getTransferrables(message);
9202
9196
  this._rawIpc.postMessage(message, transfer);
9203
9197
  }
9204
9198
  dispose() {
@@ -9214,15 +9208,15 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
9214
9208
  this._rawIpc.start();
9215
9209
  }
9216
9210
  }
9217
- const wrap$4 = port => {
9211
+ const wrap$5 = port => {
9218
9212
  return new IpcChildWithModuleWorkerAndMessagePort(port);
9219
9213
  };
9220
9214
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
9221
9215
  __proto__: null,
9222
- listen: listen$2,
9223
- wrap: wrap$4
9216
+ listen: listen$3,
9217
+ wrap: wrap$5
9224
9218
  };
9225
- const listen$4 = ({
9219
+ const listen$2 = ({
9226
9220
  port
9227
9221
  }) => {
9228
9222
  return port;
@@ -9240,7 +9234,8 @@ class IpcChildWithMessagePort extends Ipc {
9240
9234
  send(message) {
9241
9235
  this._rawIpc.postMessage(message);
9242
9236
  }
9243
- sendAndTransfer(message, transfer) {
9237
+ sendAndTransfer(message) {
9238
+ const transfer = getTransferrables(message);
9244
9239
  this._rawIpc.postMessage(message, transfer);
9245
9240
  }
9246
9241
  dispose() {
@@ -9259,7 +9254,7 @@ const wrap$2 = port => {
9259
9254
  };
9260
9255
  const IpcChildWithMessagePort$1 = {
9261
9256
  __proto__: null,
9262
- listen: listen$4,
9257
+ listen: listen$2,
9263
9258
  signal,
9264
9259
  wrap: wrap$2
9265
9260
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "2.6.0",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",