@lvce-editor/iframe-worker 1.2.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.
- package/dist/iframeWorkerMain.js +22 -24
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -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
|
};
|
|
@@ -339,27 +359,13 @@ const commandMap = {
|
|
|
339
359
|
'Location.getProtocol': getProtocol,
|
|
340
360
|
'WebView.getBaseUrl': getWebViewBaseUrl,
|
|
341
361
|
'WebView.getFrameAncestors': getWebViewFrameAncestors,
|
|
362
|
+
'WebView.getHtml': getWebViewHtml,
|
|
342
363
|
'WebView.getIframeSrc': getIframeSrc,
|
|
343
364
|
'WebView.getOrigin': getWebViewOrigin,
|
|
344
365
|
'WebView.getSandbox': getIframeSandbox,
|
|
345
366
|
'WebView.getWebViewCsp': getWebViewCsp
|
|
346
367
|
};
|
|
347
368
|
|
|
348
|
-
const state = {
|
|
349
|
-
commands: Object.create(null)
|
|
350
|
-
};
|
|
351
|
-
const registerCommand = (key, fn) => {
|
|
352
|
-
state.commands[key] = fn;
|
|
353
|
-
};
|
|
354
|
-
const registerCommands = commandMap => {
|
|
355
|
-
for (const [key, value] of Object.entries(commandMap)) {
|
|
356
|
-
registerCommand(key, value);
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
const getCommand = key => {
|
|
360
|
-
return state.commands[key];
|
|
361
|
-
};
|
|
362
|
-
|
|
363
369
|
const Two = '2.0';
|
|
364
370
|
class AssertionError extends Error {
|
|
365
371
|
constructor(message) {
|
|
@@ -545,14 +551,6 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
545
551
|
throw new JsonRpcError('unexpected message');
|
|
546
552
|
};
|
|
547
553
|
|
|
548
|
-
const execute = (command, ...args) => {
|
|
549
|
-
const fn = getCommand(command);
|
|
550
|
-
if (!fn) {
|
|
551
|
-
throw new Error(`[iframe-worker] command not found ${command}`);
|
|
552
|
-
}
|
|
553
|
-
return fn(...args);
|
|
554
|
-
};
|
|
555
|
-
|
|
556
554
|
const requiresSocket = () => {
|
|
557
555
|
return false;
|
|
558
556
|
};
|
|
@@ -999,7 +997,7 @@ const listen$1 = async ({
|
|
|
999
997
|
};
|
|
1000
998
|
|
|
1001
999
|
const listen = async () => {
|
|
1002
|
-
|
|
1000
|
+
register(commandMap);
|
|
1003
1001
|
const ipc = await listen$1({
|
|
1004
1002
|
method: Auto()
|
|
1005
1003
|
});
|