@lvce-editor/iframe-worker 1.3.0 → 1.4.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.
@@ -1,3 +1,23 @@
1
+ const commands = Object.create(null);
2
+ const registerCommand = (key, fn) => {
3
+ commands[key] = fn;
4
+ };
5
+ const register = commandMap => {
6
+ for (const [key, value] of Object.entries(commandMap)) {
7
+ registerCommand(key, value);
8
+ }
9
+ };
10
+ const getCommand = key => {
11
+ return commands[key];
12
+ };
13
+ const execute = (command, ...args) => {
14
+ const fn = getCommand(command);
15
+ if (!fn) {
16
+ throw new Error(`command not found ${command}`);
17
+ }
18
+ return fn(...args);
19
+ };
20
+
1
21
  const createUrl = (protocol, host) => {
2
22
  return protocol + '//' + host;
3
23
  };
@@ -346,21 +366,6 @@ const commandMap = {
346
366
  'WebView.getWebViewCsp': getWebViewCsp
347
367
  };
348
368
 
349
- const state = {
350
- commands: Object.create(null)
351
- };
352
- const registerCommand = (key, fn) => {
353
- state.commands[key] = fn;
354
- };
355
- const registerCommands = commandMap => {
356
- for (const [key, value] of Object.entries(commandMap)) {
357
- registerCommand(key, value);
358
- }
359
- };
360
- const getCommand = key => {
361
- return state.commands[key];
362
- };
363
-
364
369
  const Two = '2.0';
365
370
  class AssertionError extends Error {
366
371
  constructor(message) {
@@ -546,14 +551,6 @@ const handleJsonRpcMessage = async (...args) => {
546
551
  throw new JsonRpcError('unexpected message');
547
552
  };
548
553
 
549
- const execute = (command, ...args) => {
550
- const fn = getCommand(command);
551
- if (!fn) {
552
- throw new Error(`[iframe-worker] command not found ${command}`);
553
- }
554
- return fn(...args);
555
- };
556
-
557
554
  const requiresSocket = () => {
558
555
  return false;
559
556
  };
@@ -1000,7 +997,7 @@ const listen$1 = async ({
1000
997
  };
1001
998
 
1002
999
  const listen = async () => {
1003
- registerCommands(commandMap);
1000
+ register(commandMap);
1004
1001
  const ipc = await listen$1({
1005
1002
  method: Auto()
1006
1003
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "dist/iframeWorkerMain.js",
6
6
  "type": "module",