@lvce-editor/iframe-worker 5.14.0 → 5.16.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 +60 -50
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -486,7 +486,7 @@ const callbacks = Object.create(null);
|
|
|
486
486
|
const set$1 = (id, fn) => {
|
|
487
487
|
callbacks[id] = fn;
|
|
488
488
|
};
|
|
489
|
-
const get = id => {
|
|
489
|
+
const get$1 = id => {
|
|
490
490
|
return callbacks[id];
|
|
491
491
|
};
|
|
492
492
|
const remove = id => {
|
|
@@ -659,7 +659,7 @@ const warn = (...args) => {
|
|
|
659
659
|
console.warn(...args);
|
|
660
660
|
};
|
|
661
661
|
const resolve = (id, response) => {
|
|
662
|
-
const fn = get(id);
|
|
662
|
+
const fn = get$1(id);
|
|
663
663
|
if (!fn) {
|
|
664
664
|
console.log(response);
|
|
665
665
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -813,7 +813,7 @@ const send = (transport, method, ...params) => {
|
|
|
813
813
|
const message = create$4(method, params);
|
|
814
814
|
transport.send(message);
|
|
815
815
|
};
|
|
816
|
-
const invoke$
|
|
816
|
+
const invoke$5 = (ipc, method, ...params) => {
|
|
817
817
|
return invokeHelper(ipc, method, params, false);
|
|
818
818
|
};
|
|
819
819
|
const invokeAndTransfer$4 = (ipc, method, ...params) => {
|
|
@@ -846,7 +846,7 @@ const createRpc = ipc => {
|
|
|
846
846
|
send(ipc, method, ...params);
|
|
847
847
|
},
|
|
848
848
|
invoke(method, ...params) {
|
|
849
|
-
return invoke$
|
|
849
|
+
return invoke$5(ipc, method, ...params);
|
|
850
850
|
},
|
|
851
851
|
invokeAndTransfer(method, ...params) {
|
|
852
852
|
return invokeAndTransfer$4(ipc, method, ...params);
|
|
@@ -970,7 +970,7 @@ const assetDir = getAssetDir();
|
|
|
970
970
|
const state$1 = {
|
|
971
971
|
rpc: undefined
|
|
972
972
|
};
|
|
973
|
-
const invoke$
|
|
973
|
+
const invoke$4 = (method, ...params) => {
|
|
974
974
|
const rpc = state$1.rpc;
|
|
975
975
|
return rpc.invoke(method, ...params);
|
|
976
976
|
};
|
|
@@ -982,8 +982,8 @@ const setRpc = rpc => {
|
|
|
982
982
|
state$1.rpc = rpc;
|
|
983
983
|
};
|
|
984
984
|
|
|
985
|
-
const invoke$
|
|
986
|
-
return invoke$
|
|
985
|
+
const invoke$3 = async (method, ...params) => {
|
|
986
|
+
return invoke$4('WebView.compatExtensionHostWorkerInvoke', method, ...params);
|
|
987
987
|
};
|
|
988
988
|
const invokeAndTransfer$2 = async (method, ...params) => {
|
|
989
989
|
return invokeAndTransfer$3('WebView.compatExtensionHostWorkerInvokeAndTransfer', method, ...params);
|
|
@@ -1183,7 +1183,7 @@ const getPortTuple = () => {
|
|
|
1183
1183
|
};
|
|
1184
1184
|
|
|
1185
1185
|
const getSavedState = async () => {
|
|
1186
|
-
return invoke$
|
|
1186
|
+
return invoke$4('WebView.getSavedState');
|
|
1187
1187
|
};
|
|
1188
1188
|
|
|
1189
1189
|
const getSavedWebViewState = async id => {
|
|
@@ -1252,7 +1252,7 @@ const getIframePermissionPolicy = webView => {
|
|
|
1252
1252
|
};
|
|
1253
1253
|
|
|
1254
1254
|
const getWebViews = async () => {
|
|
1255
|
-
return invoke$
|
|
1255
|
+
return invoke$4('WebView.getWebViews');
|
|
1256
1256
|
};
|
|
1257
1257
|
|
|
1258
1258
|
const AllowScripts = 'allow-scripts';
|
|
@@ -1300,8 +1300,8 @@ const getPort = () => {
|
|
|
1300
1300
|
return location.port;
|
|
1301
1301
|
};
|
|
1302
1302
|
|
|
1303
|
-
const invoke$
|
|
1304
|
-
return invoke$
|
|
1303
|
+
const invoke$2 = async (method, ...params) => {
|
|
1304
|
+
return invoke$4('WebView.compatRendererProcessInvoke', method, ...params);
|
|
1305
1305
|
};
|
|
1306
1306
|
const invokeAndTransfer$1 = async (method, ...params) => {
|
|
1307
1307
|
return invokeAndTransfer$3('WebView.compatRendererProcessInvokeAndTransfer', method, ...params);
|
|
@@ -1313,27 +1313,27 @@ const setPort = async (uid, port, origin, portType) => {
|
|
|
1313
1313
|
await invokeAndTransfer$1('WebView.setPort', uid, port, origin, portType);
|
|
1314
1314
|
};
|
|
1315
1315
|
|
|
1316
|
-
const invoke = async (method, ...params) => {
|
|
1317
|
-
return invoke$
|
|
1316
|
+
const invoke$1 = async (method, ...params) => {
|
|
1317
|
+
return invoke$4('WebView.compatSharedProcessInvoke', method, ...params);
|
|
1318
1318
|
};
|
|
1319
1319
|
|
|
1320
1320
|
const registerProtocol = async () => {
|
|
1321
|
-
await invoke('WebViewServer.registerProtocol');
|
|
1321
|
+
await invoke$1('WebViewServer.registerProtocol');
|
|
1322
1322
|
};
|
|
1323
1323
|
const create = async (previewServerId, useNewWebViewHandler) => {
|
|
1324
|
-
await invoke('WebViewServer.create', previewServerId, useNewWebViewHandler);
|
|
1324
|
+
await invoke$1('WebViewServer.create', previewServerId, useNewWebViewHandler);
|
|
1325
1325
|
};
|
|
1326
1326
|
const start = async (previewServerId, webViewPort) => {
|
|
1327
|
-
await invoke('WebViewServer.start', previewServerId, webViewPort);
|
|
1327
|
+
await invoke$1('WebViewServer.start', previewServerId, webViewPort);
|
|
1328
1328
|
};
|
|
1329
1329
|
const setInfo2 = async info => {
|
|
1330
|
-
await invoke('WebViewServer.setInfo2', info);
|
|
1330
|
+
await invoke$1('WebViewServer.setInfo2', info);
|
|
1331
1331
|
};
|
|
1332
1332
|
const setInfo = async (previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent) => {
|
|
1333
|
-
await invoke('WebViewServer.setInfo', previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1333
|
+
await invoke$1('WebViewServer.setInfo', previewServerId, webViewId, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1334
1334
|
};
|
|
1335
1335
|
const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent, remotePathPrefix) => {
|
|
1336
|
-
await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1336
|
+
await invoke$1('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1337
1337
|
};
|
|
1338
1338
|
|
|
1339
1339
|
const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, webViewId, remotePathPrefix, useNewWebViewHandler) => {
|
|
@@ -1404,7 +1404,7 @@ const create2 = async ({
|
|
|
1404
1404
|
}) => {
|
|
1405
1405
|
let root = '';
|
|
1406
1406
|
if (platform === Remote) {
|
|
1407
|
-
root = await invoke('Platform.getRoot');
|
|
1407
|
+
root = await invoke$1('Platform.getRoot');
|
|
1408
1408
|
}
|
|
1409
1409
|
const webViews = await getWebViews();
|
|
1410
1410
|
const locationProtocol = getProtocol$1();
|
|
@@ -1436,7 +1436,7 @@ const create2 = async ({
|
|
|
1436
1436
|
const permissionPolicyString = permissionPolicy.join('; ');
|
|
1437
1437
|
const iframeCsp = platform === Web ? csp : '';
|
|
1438
1438
|
const credentialless = getCredentialLess(locationHost);
|
|
1439
|
-
await invoke$
|
|
1439
|
+
await invoke$4('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1440
1440
|
const {
|
|
1441
1441
|
port1,
|
|
1442
1442
|
port2
|
|
@@ -1444,18 +1444,18 @@ const create2 = async ({
|
|
|
1444
1444
|
const portId = create$1();
|
|
1445
1445
|
const remotePathPrefix = '/remote';
|
|
1446
1446
|
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix);
|
|
1447
|
-
await invoke$
|
|
1447
|
+
await invoke$2('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1448
1448
|
|
|
1449
1449
|
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
1450
1450
|
// and causes flash of unstyled content, maybe a better way would be to just send the
|
|
1451
1451
|
// port and wait for the first port message
|
|
1452
|
-
await invoke$
|
|
1452
|
+
await invoke$2('WebView.load', id);
|
|
1453
1453
|
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1454
1454
|
const portType = '';
|
|
1455
1455
|
await setPort(id, port1, origin, portType);
|
|
1456
1456
|
await invokeAndTransfer$2('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
|
|
1457
1457
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1458
|
-
await invoke$
|
|
1458
|
+
await invoke$3('ExtensionHostWebView.load', webViewId, savedState);
|
|
1459
1459
|
return {
|
|
1460
1460
|
iframeSrc,
|
|
1461
1461
|
sandbox,
|
|
@@ -1465,6 +1465,9 @@ const create2 = async ({
|
|
|
1465
1465
|
};
|
|
1466
1466
|
};
|
|
1467
1467
|
|
|
1468
|
+
const invoke = async (method, ...params) => {
|
|
1469
|
+
return invoke$4('WebView.compatRendererWorkerInvoke', method, ...params);
|
|
1470
|
+
};
|
|
1468
1471
|
const invokeAndTransfer = async (method, ...params) => {
|
|
1469
1472
|
return invokeAndTransfer$3('WebView.compatRendererWorkerInvokeAndTransfer', method, ...params);
|
|
1470
1473
|
};
|
|
@@ -1491,6 +1494,10 @@ const createWebViewConnection = async (uid, origin) => {
|
|
|
1491
1494
|
return rpc;
|
|
1492
1495
|
};
|
|
1493
1496
|
|
|
1497
|
+
const readFile = uri => {
|
|
1498
|
+
return invoke('FileSystem.readFile', uri);
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1494
1501
|
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
1495
1502
|
const getProtocol = uri => {
|
|
1496
1503
|
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
@@ -1500,6 +1507,17 @@ const getProtocol = uri => {
|
|
|
1500
1507
|
return '';
|
|
1501
1508
|
};
|
|
1502
1509
|
|
|
1510
|
+
const rpcs = Object.create(null);
|
|
1511
|
+
const set = (id, rpc) => {
|
|
1512
|
+
rpcs[id] = rpc;
|
|
1513
|
+
};
|
|
1514
|
+
const get = id => {
|
|
1515
|
+
return rpcs[id];
|
|
1516
|
+
};
|
|
1517
|
+
const getAll = () => {
|
|
1518
|
+
return rpcs;
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1503
1521
|
// TODO if webViewId is provided,
|
|
1504
1522
|
// 1. read file as blob
|
|
1505
1523
|
// 2. send blob to webview
|
|
@@ -1508,15 +1526,12 @@ const getProtocol = uri => {
|
|
|
1508
1526
|
// 5. provide objectUrl to extension
|
|
1509
1527
|
|
|
1510
1528
|
const getRemoteUrlForWebView = async options => {
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
// const [rpc, blob] = await Promise.all([CreateWebViewIpc.createWebViewIpc(webView), Rpc.invoke('FileSystem.getBlob', uri)])
|
|
1518
|
-
// const objectUrl = await rpc.invoke('createObjectUrl', blob)
|
|
1519
|
-
// return objectUrl
|
|
1529
|
+
const webView = get(options.id);
|
|
1530
|
+
const rpcPromise = createWebViewConnection(webView.webViewUid, webView.origin);
|
|
1531
|
+
const blobPromise = invoke('FileSystem.getBlob', options.uri);
|
|
1532
|
+
const [rpc, blob] = await Promise.all([rpcPromise, blobPromise]);
|
|
1533
|
+
const objectUrl = await rpc.invoke('createObjectUrl', blob);
|
|
1534
|
+
return objectUrl;
|
|
1520
1535
|
};
|
|
1521
1536
|
|
|
1522
1537
|
const getRemoteUrl = async options => {
|
|
@@ -1538,11 +1553,12 @@ const getRemoteUrl = async options => {
|
|
|
1538
1553
|
}
|
|
1539
1554
|
return `/remote/${uri}`;
|
|
1540
1555
|
}
|
|
1541
|
-
return getRemoteUrlForWebView();
|
|
1556
|
+
return getRemoteUrlForWebView(options);
|
|
1542
1557
|
};
|
|
1543
1558
|
|
|
1544
1559
|
const commandMap$1 = {
|
|
1545
|
-
'WebView.getRemoteUrl': getRemoteUrl
|
|
1560
|
+
'WebView.getRemoteUrl': getRemoteUrl,
|
|
1561
|
+
'WebView.readFile': readFile
|
|
1546
1562
|
};
|
|
1547
1563
|
|
|
1548
1564
|
const getWebViewWorkerRpc = async rpcInfo => {
|
|
@@ -1562,19 +1578,11 @@ const getWebViewWorkerRpc = async rpcInfo => {
|
|
|
1562
1578
|
return rpc;
|
|
1563
1579
|
};
|
|
1564
1580
|
|
|
1565
|
-
const rpcs = Object.create(null);
|
|
1566
|
-
const set = (id, rpc) => {
|
|
1567
|
-
rpcs[id] = rpc;
|
|
1568
|
-
};
|
|
1569
|
-
const getAll = () => {
|
|
1570
|
-
return rpcs;
|
|
1571
|
-
};
|
|
1572
|
-
|
|
1573
1581
|
const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, origin) => {
|
|
1574
1582
|
if (!webView || !webView.rpc || typeof webView.rpc !== 'string') {
|
|
1575
1583
|
return;
|
|
1576
1584
|
}
|
|
1577
|
-
const rpcInfo = await invoke$
|
|
1585
|
+
const rpcInfo = await invoke$3('WebView.getRpcInfo', webView.rpc);
|
|
1578
1586
|
if (rpcInfo.type !== 'web-worker') {
|
|
1579
1587
|
throw new Error(`only web worker rpc is supported for webviews`);
|
|
1580
1588
|
}
|
|
@@ -1582,7 +1590,9 @@ const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, or
|
|
|
1582
1590
|
const webViewInfo = {
|
|
1583
1591
|
rpc,
|
|
1584
1592
|
webViewId: webView.id,
|
|
1585
|
-
portId: portId
|
|
1593
|
+
portId: portId,
|
|
1594
|
+
webViewUid,
|
|
1595
|
+
origin
|
|
1586
1596
|
};
|
|
1587
1597
|
set(portId, webViewInfo);
|
|
1588
1598
|
await rpc.invoke('LoadFile.loadFile', rpcInfo.url);
|
|
@@ -1642,7 +1652,7 @@ const create3 = async ({
|
|
|
1642
1652
|
}) => {
|
|
1643
1653
|
let root = '';
|
|
1644
1654
|
if (platform === Remote) {
|
|
1645
|
-
root = await invoke('Platform.getRoot');
|
|
1655
|
+
root = await invoke$1('Platform.getRoot');
|
|
1646
1656
|
}
|
|
1647
1657
|
const webViews = await getWebViews();
|
|
1648
1658
|
const webViewId = getWebViewId(webViews, uri);
|
|
@@ -1678,16 +1688,16 @@ const create3 = async ({
|
|
|
1678
1688
|
const permissionPolicyString = permissionPolicy.join('; ');
|
|
1679
1689
|
const iframeCsp = platform === Web ? csp : '';
|
|
1680
1690
|
const credentialless = getCredentialLess(locationHost);
|
|
1681
|
-
await invoke$
|
|
1691
|
+
await invoke$4('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1682
1692
|
const portId = create$1();
|
|
1683
1693
|
const remotePathPrefix = '/remote';
|
|
1684
1694
|
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler);
|
|
1685
|
-
await invoke$
|
|
1695
|
+
await invoke$2('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1686
1696
|
|
|
1687
1697
|
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
1688
1698
|
// and causes flash of unstyled content, maybe a better way would be to just send the
|
|
1689
1699
|
// port and wait for the first port message
|
|
1690
|
-
await invoke$
|
|
1700
|
+
await invoke$2('WebView.load', id);
|
|
1691
1701
|
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1692
1702
|
const hasOldRpc = !webView || !webView.rpc || typeof webView.rpc !== 'string';
|
|
1693
1703
|
if (hasOldRpc) {
|
|
@@ -1701,7 +1711,7 @@ const create3 = async ({
|
|
|
1701
1711
|
}
|
|
1702
1712
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1703
1713
|
if (hasOldRpc) {
|
|
1704
|
-
await invoke$
|
|
1714
|
+
await invoke$3('ExtensionHostWebView.load', webViewId, savedState);
|
|
1705
1715
|
}
|
|
1706
1716
|
await createWebViewRpc(webView, savedState, uri, portId, id, origin);
|
|
1707
1717
|
return {
|