@lvce-editor/embeds-process 4.1.0 → 4.3.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.
@@ -14,17 +14,18 @@ const getAll = () => {
14
14
  return Object.entries(ipcMap);
15
15
  };
16
16
 
17
+ const MainProcess$2 = -5;
18
+ const SharedProcess$2 = 1;
19
+
17
20
  const rpcs = Object.create(null);
18
- const set$7 = (id, rpc) => {
21
+ const set$5 = (id, rpc) => {
19
22
  rpcs[id] = rpc;
20
23
  };
21
24
  const get$1 = id => {
22
25
  return rpcs[id];
23
26
  };
24
27
 
25
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
26
-
27
- const create$6 = rpcId => {
28
+ const create$5 = rpcId => {
28
29
  return {
29
30
  // @ts-ignore
30
31
  invoke(method, ...params) {
@@ -39,33 +40,14 @@ const create$6 = rpcId => {
39
40
  return rpc.invokeAndTransfer(method, ...params);
40
41
  },
41
42
  set(rpc) {
42
- set$7(rpcId, rpc);
43
+ set$5(rpcId, rpc);
44
+ },
45
+ async dispose() {
46
+ const rpc = get$1(rpcId);
47
+ await rpc.dispose();
43
48
  }
44
49
  };
45
50
  };
46
- const MainProcess$1 = -5;
47
- const SharedProcess$1 = 1;
48
- const {
49
- invoke: invoke$3,
50
- set: set$3
51
- } = create$6(MainProcess$1);
52
- const MainProcess$2 = {
53
- __proto__: null,
54
- invoke: invoke$3,
55
- set: set$3
56
- };
57
- const {
58
- set: set$4
59
- } = create$6(SharedProcess$1);
60
- const SharedProcess$2 = {
61
- __proto__: null,
62
- set: set$4
63
- };
64
-
65
- const {
66
- invoke: invoke$1,
67
- set: set$2
68
- } = MainProcess$2;
69
51
 
70
52
  const normalizeLine = line => {
71
53
  if (line.startsWith('Error: ')) {
@@ -123,175 +105,55 @@ class VError extends Error {
123
105
  }
124
106
  }
125
107
 
126
- const dispose = async id => {
127
- try {
128
- await invoke$1('ElectronWebContents.dispose', id);
129
- } catch (error) {
130
- throw new VError(error, `Failed to dispose webcontents`);
131
- }
132
- };
133
- const callFunction = (webContentsId, method, ...params) => {
134
- return invoke$1(`ElectronWebContents.callFunction`, webContentsId, method, ...params);
135
- };
136
- const focus = webContentsId => {
137
- return callFunction(webContentsId, 'focus');
138
- };
139
- const openDevtools = webContentsId => {
140
- return callFunction(webContentsId, 'openDevTools');
141
- };
142
- const reload = webContentsId => {
143
- return callFunction(webContentsId, 'reload');
144
- };
145
- const forward = webContentsId => {
146
- return callFunction(webContentsId, 'goForward');
147
- };
148
- const backward = webContentsId => {
149
- return callFunction(webContentsId, 'goBack');
150
- };
151
- const inspectElement = (webContentsId, x, y) => {
152
- return callFunction(webContentsId, `inspectElement`, x, y);
153
- };
154
-
155
108
  class AssertionError extends Error {
156
109
  constructor(message) {
157
110
  super(message);
158
111
  this.name = 'AssertionError';
159
112
  }
160
113
  }
114
+ const Object$1 = 1;
115
+ const Number$1 = 2;
116
+ const Array$1 = 3;
117
+ const String = 4;
118
+ const Boolean = 5;
119
+ const Function = 6;
120
+ const Null = 7;
121
+ const Unknown = 8;
161
122
  const getType = value => {
162
123
  switch (typeof value) {
163
124
  case 'number':
164
- return 'number';
125
+ return Number$1;
165
126
  case 'function':
166
- return 'function';
127
+ return Function;
167
128
  case 'string':
168
- return 'string';
129
+ return String;
169
130
  case 'object':
170
131
  if (value === null) {
171
- return 'null';
132
+ return Null;
172
133
  }
173
134
  if (Array.isArray(value)) {
174
- return 'array';
135
+ return Array$1;
175
136
  }
176
- return 'object';
137
+ return Object$1;
177
138
  case 'boolean':
178
- return 'boolean';
139
+ return Boolean;
179
140
  default:
180
- return 'unknown';
141
+ return Unknown;
181
142
  }
182
143
  };
183
144
  const object = value => {
184
145
  const type = getType(value);
185
- if (type !== 'object') {
146
+ if (type !== Object$1) {
186
147
  throw new AssertionError('expected value to be of type object');
187
148
  }
188
149
  };
189
150
  const number = value => {
190
151
  const type = getType(value);
191
- if (type !== 'number') {
152
+ if (type !== Number$1) {
192
153
  throw new AssertionError('expected value to be of type number');
193
154
  }
194
155
  };
195
156
 
196
- const createWebContentsView = async (ipcId, restoreId, fallthroughKeyBindings) => {
197
- number(restoreId);
198
- // TODO race condition: ipc can be disposed while webcontents are being created
199
- const webContentsId = await invoke$1('ElectronWebContentsView.createWebContentsView', restoreId);
200
- add(webContentsId, ipcId);
201
- // TODO get window id from renderer worker
202
- await invoke$1('ElectronWebContentsView.attachEventListeners', webContentsId);
203
- await invoke$1('ElectronWebContentsViewFunctions.setBackgroundColor', webContentsId, 'white');
204
- return webContentsId;
205
- };
206
- const disposeWebContentsView = async id => {
207
- await invoke$1('ElectronWebContentsView.disposeWebContentsView', id);
208
- await dispose(id);
209
- };
210
- const resizeWebContentsView = async (id, ...args) => {
211
- return invoke$1('ElectronWebContentsViewFunctions.resizeBrowserView', id, ...args);
212
- };
213
- const setIframeSrc = async (id, ...args) => {
214
- return invoke$1('ElectronWebContentsViewFunctions.setIframeSrc', id, ...args);
215
- };
216
- const setIframeSrcFallback = async (id, ...args) => {
217
- return invoke$1('ElectronWebContentsViewFunctions.setIframeSrcFallback', id, ...args);
218
- };
219
- const setFallthroughKeyBindings = async (id, ...args) => {
220
- return invoke$1('ElectronWebContentsViewFunctions.setFallthroughKeyBindings', id, ...args);
221
- };
222
- const getStats = async (id, ...args) => {
223
- return invoke$1('ElectronWebContentsViewFunctions.getStats', id, ...args);
224
- };
225
- const getDomTree = async id => {
226
- // @ts-ignore
227
- return invoke$1('ElectronWebContentsViewFunctions.getDomTree', id);
228
- };
229
- const insertCss = async (id, css) => {
230
- // @ts-ignore
231
- return invoke$1('ElectronWebContentsViewFunctions.insertCss', id, css);
232
- };
233
- const insertJavaScript = async (id, css) => {
234
- // @ts-ignore
235
- return invoke$1('ElectronWebContentsViewFunctions.insertJavaScript', id, css);
236
- };
237
- const show = async (id, ...args) => {
238
- return invoke$1('ElectronWebContentsViewFunctions.show', id, ...args);
239
- };
240
- const forwardIpcEvent = key => (id, ...args) => {
241
- const ipc = get$2(id);
242
- if (!ipc) {
243
- return;
244
- }
245
- ipc.send(key, id, ...args);
246
- };
247
- const handleDidNavigate = forwardIpcEvent('ElectronWebContentsView.handleDidNavigate');
248
- const handleTitleUpdated = forwardIpcEvent('ElectronWebContentsView.handleTitleUpdated');
249
- const handleWillNavigate = forwardIpcEvent('ElectronWebContentsView.handleWillNavigate');
250
- const handleContextMenu = forwardIpcEvent('ElectronWebContentsView.handleContextMenu');
251
- const handleKeyBinding = forwardIpcEvent('ElectronWebContentsView.handleKeyBinding');
252
- const handleBrowserViewDestroyed = (id, ...args) => {
253
- // TODO send to embeds worker?
254
- };
255
-
256
- const applyIncomingIpcResponse = async (target, response, ipcId) => {
257
- switch (response.type) {
258
- case 'handle':
259
- break;
260
- default:
261
- throw new Error('unexpected response');
262
- }
263
- };
264
-
265
- const handleIncomingIpcMessagePort = async (module, handle, message) => {
266
- const target = await module.targetMessagePort(handle, message);
267
- const response = module.upgradeMessagePort(handle, message);
268
- return {
269
- target,
270
- response
271
- };
272
- };
273
-
274
- const commandMapRef = {};
275
-
276
- const getIdsToDispose = ipc => {
277
- const entries = getAll();
278
- const toDispose = [];
279
- for (const [id, value] of entries) {
280
- if (value === ipc) {
281
- toDispose.push(Number.parseInt(id));
282
- }
283
- }
284
- return toDispose;
285
- };
286
- const handleIpcClosed = async event => {
287
- const idsToDispose = getIdsToDispose(event.target);
288
- for (const id of idsToDispose) {
289
- remove$1(id);
290
- await disposeWebContentsView(id);
291
- }
292
- // SharedProcessIpc.send('HandleMessagePortForEmbedsProcess.handleEmbedsProcessIpcClosed')
293
- };
294
-
295
157
  const isMessagePort = value => {
296
158
  return value && value instanceof MessagePort;
297
159
  };
@@ -614,7 +476,7 @@ const listen$a = () => {
614
476
  parentPort
615
477
  } = process;
616
478
  if (!parentPort) {
617
- throw new Error('parent port must be defined');
479
+ throw new IpcError('parent port must be defined');
618
480
  }
619
481
  return parentPort;
620
482
  };
@@ -672,7 +534,7 @@ const getTransferrablesNode = value => {
672
534
  };
673
535
  const listen$5 = async () => {
674
536
  if (!process.send) {
675
- throw new Error('process.send must be defined');
537
+ throw new IpcError('process.send must be defined');
676
538
  }
677
539
  return process;
678
540
  };
@@ -714,7 +576,7 @@ const listen$3 = async () => {
714
576
  parentPort
715
577
  } = await import('node:worker_threads');
716
578
  if (!parentPort) {
717
- throw new IpcError('parentPort is required');
579
+ throw new IpcError('parentPort is required for node worker threads ipc');
718
580
  }
719
581
  return parentPort;
720
582
  };
@@ -849,8 +711,6 @@ const handleUpgrade$1 = async (...args) => {
849
711
  // @ts-ignore
850
712
  return module.handleUpgrade(...args);
851
713
  };
852
-
853
- // @ts-ignore
854
714
  const listen$1$1 = async ({
855
715
  request,
856
716
  handle
@@ -871,8 +731,6 @@ const listen$1$1 = async ({
871
731
  const signal$4 = webSocket => {
872
732
  webSocket.resume();
873
733
  };
874
-
875
- // @ts-ignore
876
734
  const wrap$9 = webSocket => {
877
735
  return {
878
736
  webSocket,
@@ -927,7 +785,7 @@ const IpcChildWithWebSocket = {
927
785
  };
928
786
 
929
787
  const Two = '2.0';
930
- const create$4$1 = (method, params) => {
788
+ const create$4 = (method, params) => {
931
789
  return {
932
790
  jsonrpc: Two,
933
791
  method,
@@ -935,7 +793,7 @@ const create$4$1 = (method, params) => {
935
793
  };
936
794
  };
937
795
  const callbacks = Object.create(null);
938
- const set$1 = (id, fn) => {
796
+ const set$4 = (id, fn) => {
939
797
  callbacks[id] = fn;
940
798
  };
941
799
  const get = id => {
@@ -954,7 +812,7 @@ const registerPromise = () => {
954
812
  resolve,
955
813
  promise
956
814
  } = Promise.withResolvers();
957
- set$1(id, resolve);
815
+ set$4(id, resolve);
958
816
  return {
959
817
  id,
960
818
  promise
@@ -1027,6 +885,17 @@ const constructError = (message, type, name) => {
1027
885
  }
1028
886
  return new ErrorConstructor(message);
1029
887
  };
888
+ const joinLines = lines => {
889
+ return lines.join(NewLine);
890
+ };
891
+ const splitLines = lines => {
892
+ return lines.split(NewLine);
893
+ };
894
+ const getCurrentStack = () => {
895
+ const stackLinesToSkip = 3;
896
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
897
+ return currentStack;
898
+ };
1030
899
  const getNewLineIndex = (string, startIndex = undefined) => {
1031
900
  return string.indexOf(NewLine, startIndex);
1032
901
  };
@@ -1037,19 +906,16 @@ const getParentStack = error => {
1037
906
  }
1038
907
  return parentStack;
1039
908
  };
1040
- const joinLines = lines => {
1041
- return lines.join(NewLine);
1042
- };
1043
909
  const MethodNotFound = -32601;
1044
910
  const Custom = -32001;
1045
- const splitLines = lines => {
1046
- return lines.split(NewLine);
1047
- };
1048
911
  const restoreJsonRpcError = error => {
912
+ const currentStack = getCurrentStack();
1049
913
  if (error && error instanceof Error) {
914
+ if (typeof error.stack === 'string') {
915
+ error.stack = error.stack + NewLine + currentStack;
916
+ }
1050
917
  return error;
1051
918
  }
1052
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
1053
919
  if (error && error.code && error.code === MethodNotFound) {
1054
920
  const restoredError = new JsonRpcError(error.message);
1055
921
  const parentStack = getParentStack(error);
@@ -1130,6 +996,17 @@ const getErrorType = prettyError => {
1130
996
  }
1131
997
  return undefined;
1132
998
  };
999
+ const isAlreadyStack = line => {
1000
+ return line.trim().startsWith('at ');
1001
+ };
1002
+ const getStack = prettyError => {
1003
+ const stackString = prettyError.stack || '';
1004
+ const newLineIndex = stackString.indexOf('\n');
1005
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
1006
+ return stackString.slice(newLineIndex + 1);
1007
+ }
1008
+ return stackString;
1009
+ };
1133
1010
  const getErrorProperty = (error, prettyError) => {
1134
1011
  if (error && error.code === E_COMMAND_NOT_FOUND) {
1135
1012
  return {
@@ -1142,7 +1019,7 @@ const getErrorProperty = (error, prettyError) => {
1142
1019
  code: Custom,
1143
1020
  message: prettyError.message,
1144
1021
  data: {
1145
- stack: prettyError.stack,
1022
+ stack: getStack(prettyError),
1146
1023
  codeFrame: prettyError.codeFrame,
1147
1024
  type: getErrorType(prettyError),
1148
1025
  code: prettyError.code,
@@ -1150,18 +1027,18 @@ const getErrorProperty = (error, prettyError) => {
1150
1027
  }
1151
1028
  };
1152
1029
  };
1153
- const create$1 = (message, error) => {
1030
+ const create$1 = (id, error) => {
1154
1031
  return {
1155
1032
  jsonrpc: Two,
1156
- id: message.id,
1033
+ id,
1157
1034
  error
1158
1035
  };
1159
1036
  };
1160
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
1037
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
1161
1038
  const prettyError = preparePrettyError(error);
1162
1039
  logError(error, prettyError);
1163
1040
  const errorProperty = getErrorProperty(error, prettyError);
1164
- return create$1(message, errorProperty);
1041
+ return create$1(id, errorProperty);
1165
1042
  };
1166
1043
  const create = (message, result) => {
1167
1044
  return {
@@ -1174,12 +1051,27 @@ const getSuccessResponse = (message, result) => {
1174
1051
  const resultProperty = result ?? null;
1175
1052
  return create(message, resultProperty);
1176
1053
  };
1054
+ const getErrorResponseSimple = (id, error) => {
1055
+ return {
1056
+ jsonrpc: Two,
1057
+ id,
1058
+ error: {
1059
+ code: Custom,
1060
+ // @ts-ignore
1061
+ message: error.message,
1062
+ data: error
1063
+ }
1064
+ };
1065
+ };
1177
1066
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
1178
1067
  try {
1179
1068
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
1180
1069
  return getSuccessResponse(message, result);
1181
1070
  } catch (error) {
1182
- return getErrorResponse(message, error, preparePrettyError, logError);
1071
+ if (ipc.canUseSimpleErrorResponse) {
1072
+ return getErrorResponseSimple(message.id, error);
1073
+ }
1074
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
1183
1075
  }
1184
1076
  };
1185
1077
  const defaultPreparePrettyError = error => {
@@ -1234,7 +1126,7 @@ const handleJsonRpcMessage = async (...args) => {
1234
1126
  try {
1235
1127
  ipc.send(response);
1236
1128
  } catch (error) {
1237
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
1129
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
1238
1130
  ipc.send(errorResponse);
1239
1131
  }
1240
1132
  return;
@@ -1262,16 +1154,22 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
1262
1154
  return unwrapJsonRpcResult(responseMessage);
1263
1155
  };
1264
1156
  const send = (transport, method, ...params) => {
1265
- const message = create$4$1(method, params);
1157
+ const message = create$4(method, params);
1266
1158
  transport.send(message);
1267
1159
  };
1268
- const invoke = (ipc, method, ...params) => {
1160
+ const invoke$3 = (ipc, method, ...params) => {
1269
1161
  return invokeHelper(ipc, method, params, false);
1270
1162
  };
1271
- const invokeAndTransfer = (ipc, method, ...params) => {
1163
+ const invokeAndTransfer$2 = (ipc, method, ...params) => {
1272
1164
  return invokeHelper(ipc, method, params, true);
1273
1165
  };
1274
1166
 
1167
+ class CommandNotFoundError extends Error {
1168
+ constructor(command) {
1169
+ super(`Command not found ${command}`);
1170
+ this.name = 'CommandNotFoundError';
1171
+ }
1172
+ }
1275
1173
  const commands = Object.create(null);
1276
1174
  const register = commandMap => {
1277
1175
  Object.assign(commands, commandMap);
@@ -1282,7 +1180,7 @@ const getCommand = key => {
1282
1180
  const execute = (command, ...args) => {
1283
1181
  const fn = getCommand(command);
1284
1182
  if (!fn) {
1285
- throw new Error(`command not found ${command}`);
1183
+ throw new CommandNotFoundError(command);
1286
1184
  }
1287
1185
  return fn(...args);
1288
1186
  };
@@ -1298,10 +1196,10 @@ const createRpc = ipc => {
1298
1196
  send(ipc, method, ...params);
1299
1197
  },
1300
1198
  invoke(method, ...params) {
1301
- return invoke(ipc, method, ...params);
1199
+ return invoke$3(ipc, method, ...params);
1302
1200
  },
1303
1201
  invokeAndTransfer(method, ...params) {
1304
- return invokeAndTransfer(ipc, method, ...params);
1202
+ return invokeAndTransfer$2(ipc, method, ...params);
1305
1203
  },
1306
1204
  async dispose() {
1307
1205
  await ipc?.dispose();
@@ -1339,7 +1237,7 @@ const listen$2 = async (module, options) => {
1339
1237
  const ipc = module.wrap(rawIpc);
1340
1238
  return ipc;
1341
1239
  };
1342
- const create$e = async ({
1240
+ const create$k = async ({
1343
1241
  commandMap,
1344
1242
  messagePort,
1345
1243
  requiresSocket
@@ -1358,9 +1256,9 @@ const create$e = async ({
1358
1256
  };
1359
1257
  const ElectronMessagePortRpcClient = {
1360
1258
  __proto__: null,
1361
- create: create$e
1259
+ create: create$k
1362
1260
  };
1363
- const create$d = async ({
1261
+ const create$j = async ({
1364
1262
  commandMap
1365
1263
  }) => {
1366
1264
  // TODO create a commandMap per rpc instance
@@ -1372,9 +1270,9 @@ const create$d = async ({
1372
1270
  };
1373
1271
  const ElectronUtilityProcessRpcClient = {
1374
1272
  __proto__: null,
1375
- create: create$d
1273
+ create: create$j
1376
1274
  };
1377
- const create$7 = async ({
1275
+ const create$a = async ({
1378
1276
  commandMap
1379
1277
  }) => {
1380
1278
  // TODO create a commandMap per rpc instance
@@ -1386,9 +1284,9 @@ const create$7 = async ({
1386
1284
  };
1387
1285
  const NodeForkedProcessRpcClient = {
1388
1286
  __proto__: null,
1389
- create: create$7
1287
+ create: create$a
1390
1288
  };
1391
- const create$5 = async ({
1289
+ const create$8 = async ({
1392
1290
  commandMap,
1393
1291
  request,
1394
1292
  handle,
@@ -1409,9 +1307,9 @@ const create$5 = async ({
1409
1307
  };
1410
1308
  const NodeWebSocketRpcClient = {
1411
1309
  __proto__: null,
1412
- create: create$5
1310
+ create: create$8
1413
1311
  };
1414
- const create$4 = async ({
1312
+ const create$7 = async ({
1415
1313
  commandMap
1416
1314
  }) => {
1417
1315
  // TODO create a commandMap per rpc instance
@@ -1423,7 +1321,170 @@ const create$4 = async ({
1423
1321
  };
1424
1322
  const NodeWorkerRpcClient = {
1425
1323
  __proto__: null,
1426
- create: create$4
1324
+ create: create$7
1325
+ };
1326
+
1327
+ const {
1328
+ invoke: invoke$2,
1329
+ invokeAndTransfer: invokeAndTransfer$1,
1330
+ set: set$3,
1331
+ dispose: dispose$2
1332
+ } = create$5(MainProcess$2);
1333
+
1334
+ const MainProcess$1 = {
1335
+ __proto__: null,
1336
+ dispose: dispose$2,
1337
+ invoke: invoke$2,
1338
+ invokeAndTransfer: invokeAndTransfer$1,
1339
+ set: set$3
1340
+ };
1341
+
1342
+ const {
1343
+ invoke: invoke$1,
1344
+ invokeAndTransfer,
1345
+ set: set$2,
1346
+ dispose: dispose$1
1347
+ } = create$5(SharedProcess$2);
1348
+
1349
+ const SharedProcess$1 = {
1350
+ __proto__: null,
1351
+ dispose: dispose$1,
1352
+ invoke: invoke$1,
1353
+ invokeAndTransfer,
1354
+ set: set$2
1355
+ };
1356
+
1357
+ const {
1358
+ invoke,
1359
+ set: set$1
1360
+ } = MainProcess$1;
1361
+
1362
+ const dispose = async id => {
1363
+ try {
1364
+ await invoke('ElectronWebContents.dispose', id);
1365
+ } catch (error) {
1366
+ throw new VError(error, `Failed to dispose webcontents`);
1367
+ }
1368
+ };
1369
+ const callFunction = (webContentsId, method, ...params) => {
1370
+ return invoke(`ElectronWebContents.callFunction`, webContentsId, method, ...params);
1371
+ };
1372
+ const focus = webContentsId => {
1373
+ return callFunction(webContentsId, 'focus');
1374
+ };
1375
+ const openDevtools = webContentsId => {
1376
+ return callFunction(webContentsId, 'openDevTools');
1377
+ };
1378
+ const reload = webContentsId => {
1379
+ return callFunction(webContentsId, 'reload');
1380
+ };
1381
+ const forward = webContentsId => {
1382
+ return callFunction(webContentsId, 'goForward');
1383
+ };
1384
+ const backward = webContentsId => {
1385
+ return callFunction(webContentsId, 'goBack');
1386
+ };
1387
+ const inspectElement = (webContentsId, x, y) => {
1388
+ return callFunction(webContentsId, `inspectElement`, x, y);
1389
+ };
1390
+
1391
+ const createWebContentsView = async (ipcId, restoreId, fallthroughKeyBindings) => {
1392
+ number(restoreId);
1393
+ // TODO race condition: ipc can be disposed while webcontents are being created
1394
+ const webContentsId = await invoke('ElectronWebContentsView.createWebContentsView', restoreId);
1395
+ add(webContentsId, ipcId);
1396
+ // TODO get window id from renderer worker
1397
+ await invoke('ElectronWebContentsView.attachEventListeners', webContentsId);
1398
+ await invoke('ElectronWebContentsViewFunctions.setBackgroundColor', webContentsId, 'white');
1399
+ return webContentsId;
1400
+ };
1401
+ const disposeWebContentsView = async id => {
1402
+ await invoke('ElectronWebContentsView.disposeWebContentsView', id);
1403
+ await dispose(id);
1404
+ };
1405
+ const resizeWebContentsView = async (id, ...args) => {
1406
+ return invoke('ElectronWebContentsViewFunctions.resizeBrowserView', id, ...args);
1407
+ };
1408
+ const setIframeSrc = async (id, ...args) => {
1409
+ return invoke('ElectronWebContentsViewFunctions.setIframeSrc', id, ...args);
1410
+ };
1411
+ const setIframeSrcFallback = async (id, ...args) => {
1412
+ return invoke('ElectronWebContentsViewFunctions.setIframeSrcFallback', id, ...args);
1413
+ };
1414
+ const setFallthroughKeyBindings = async (id, ...args) => {
1415
+ return invoke('ElectronWebContentsViewFunctions.setFallthroughKeyBindings', id, ...args);
1416
+ };
1417
+ const getStats = async (id, ...args) => {
1418
+ return invoke('ElectronWebContentsViewFunctions.getStats', id, ...args);
1419
+ };
1420
+ const getDomTree = async id => {
1421
+ // @ts-ignore
1422
+ return invoke('ElectronWebContentsViewFunctions.getDomTree', id);
1423
+ };
1424
+ const insertCss = async (id, css) => {
1425
+ // @ts-ignore
1426
+ return invoke('ElectronWebContentsViewFunctions.insertCss', id, css);
1427
+ };
1428
+ const insertJavaScript = async (id, css) => {
1429
+ // @ts-ignore
1430
+ return invoke('ElectronWebContentsViewFunctions.insertJavaScript', id, css);
1431
+ };
1432
+ const show = async (id, ...args) => {
1433
+ return invoke('ElectronWebContentsViewFunctions.show', id, ...args);
1434
+ };
1435
+ const forwardIpcEvent = key => (id, ...args) => {
1436
+ const ipc = get$2(id);
1437
+ if (!ipc) {
1438
+ return;
1439
+ }
1440
+ ipc.send(key, id, ...args);
1441
+ };
1442
+ const handleDidNavigate = forwardIpcEvent('ElectronWebContentsView.handleDidNavigate');
1443
+ const handleTitleUpdated = forwardIpcEvent('ElectronWebContentsView.handleTitleUpdated');
1444
+ const handleWillNavigate = forwardIpcEvent('ElectronWebContentsView.handleWillNavigate');
1445
+ const handleContextMenu = forwardIpcEvent('ElectronWebContentsView.handleContextMenu');
1446
+ const handleKeyBinding = forwardIpcEvent('ElectronWebContentsView.handleKeyBinding');
1447
+ const handleBrowserViewDestroyed = (id, ...args) => {
1448
+ // TODO send to embeds worker?
1449
+ };
1450
+
1451
+ const applyIncomingIpcResponse = async (target, response, ipcId) => {
1452
+ switch (response.type) {
1453
+ case 'handle':
1454
+ break;
1455
+ default:
1456
+ throw new Error('unexpected response');
1457
+ }
1458
+ };
1459
+
1460
+ const handleIncomingIpcMessagePort = async (module, handle, message) => {
1461
+ const target = await module.targetMessagePort(handle, message);
1462
+ const response = module.upgradeMessagePort(handle, message);
1463
+ return {
1464
+ target,
1465
+ response
1466
+ };
1467
+ };
1468
+
1469
+ const commandMapRef = {};
1470
+
1471
+ const getIdsToDispose = ipc => {
1472
+ const entries = getAll();
1473
+ const toDispose = [];
1474
+ for (const [id, value] of entries) {
1475
+ if (value === ipc) {
1476
+ toDispose.push(Number.parseInt(id));
1477
+ }
1478
+ }
1479
+ return toDispose;
1480
+ };
1481
+ const handleIpcClosed = async event => {
1482
+ const idsToDispose = getIdsToDispose(event.target);
1483
+ for (const id of idsToDispose) {
1484
+ remove$1(id);
1485
+ await disposeWebContentsView(id);
1486
+ }
1487
+ // SharedProcessIpc.send('HandleMessagePortForEmbedsProcess.handleEmbedsProcessIpcClosed')
1427
1488
  };
1428
1489
 
1429
1490
  const NodeWorker = 1;
@@ -1502,7 +1563,7 @@ const targetMessagePort$1 = async (messagePort, message) => {
1502
1563
  method: ElectronMessagePort,
1503
1564
  messagePort
1504
1565
  });
1505
- set$2(rpc);
1566
+ set$1(rpc);
1506
1567
  return rpc;
1507
1568
  };
1508
1569
  const upgradeMessagePort$1 = () => {
@@ -1519,7 +1580,7 @@ const HandleIpcMainProcess = {
1519
1580
 
1520
1581
  const {
1521
1582
  set
1522
- } = SharedProcess$2;
1583
+ } = SharedProcess$1;
1523
1584
 
1524
1585
  const targetMessagePort = async (messagePort, message) => {
1525
1586
  object(messagePort);
@@ -1545,12 +1606,14 @@ const HandleIpcSharedProcess = {
1545
1606
  const EmbedsWorker = 77;
1546
1607
  const MainProcess = -5;
1547
1608
  const SharedProcess = 1;
1609
+ const SharedProcessAlt = 1492;
1548
1610
  const EmbedsWorkerAlt = 208;
1549
1611
 
1550
1612
  const getModule = ipcId => {
1551
1613
  number(ipcId);
1552
1614
  switch (ipcId) {
1553
1615
  case SharedProcess:
1616
+ case SharedProcessAlt:
1554
1617
  return HandleIpcSharedProcess;
1555
1618
  // deprecated
1556
1619
  case EmbedsWorker:
@@ -1597,7 +1660,7 @@ const createMainProcessRpc = async port => {
1597
1660
 
1598
1661
  const initialize = async port => {
1599
1662
  const rpc = await createMainProcessRpc(port);
1600
- set$2(rpc);
1663
+ set$1(rpc);
1601
1664
  };
1602
1665
 
1603
1666
  const commandMap = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/embeds-process",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "description": "Embeds Process",
5
5
  "keywords": [
6
6
  "Lvce Editor"