@lvce-editor/iframe-worker 3.4.0 → 3.6.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.
@@ -804,6 +804,54 @@ const WebWorkerRpcClient = {
804
804
  create: create$2
805
805
  };
806
806
 
807
+ const Web = 1;
808
+ const Electron = 2;
809
+ const Remote = 3;
810
+ const Test = 4;
811
+
812
+ /* istanbul ignore file */
813
+
814
+ // TODO this should always be completely tree shaken out during build, maybe need to be marked as @__Pure for terser to work
815
+
816
+ // TODO treeshake this function out when targeting electron
817
+
818
+ /**
819
+ * @returns {number}
820
+ */
821
+ const getPlatform = () => {
822
+ // @ts-ignore
823
+ if (typeof PLATFORM !== 'undefined') {
824
+ // @ts-ignore
825
+ return PLATFORM;
826
+ }
827
+ // @ts-ignore
828
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
829
+ return Test;
830
+ }
831
+ // TODO find a better way to pass runtime environment
832
+ if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
833
+ return Electron;
834
+ }
835
+ if (typeof name !== 'undefined' && name.endsWith('(Web)')) {
836
+ return Web;
837
+ }
838
+ return Remote;
839
+ };
840
+ const platform = getPlatform();
841
+
842
+ const getAssetDir = () => {
843
+ // @ts-ignore
844
+ if (typeof ASSET_DIR !== 'undefined') {
845
+ // @ts-ignore
846
+ return ASSET_DIR;
847
+ }
848
+ if (platform === Electron) {
849
+ return '';
850
+ }
851
+ return '';
852
+ };
853
+ const assetDir = getAssetDir();
854
+
807
855
  const state$1 = {
808
856
  rpc: undefined
809
857
  };
@@ -826,6 +874,14 @@ const invokeAndTransfer$1 = async (method, ...params) => {
826
874
  return invokeAndTransfer$2('WebView.compatExtensionHostWorkerInvokeAndTransfer', method, ...params);
827
875
  };
828
876
 
877
+ const getCredentialLess = locationHost => {
878
+ if (locationHost.startsWith('localhost:')) {
879
+ // disabled to improve performance and make testing easier
880
+ return false;
881
+ }
882
+ return true;
883
+ };
884
+
829
885
  const createUrl = (protocol, host) => {
830
886
  return protocol + '//' + host;
831
887
  };
@@ -864,41 +920,6 @@ const getWebViewHtml = (baseUrl, locationOrigin, elements, assetDir) => {
864
920
  return html;
865
921
  };
866
922
 
867
- const Web = 1;
868
- const Electron = 2;
869
- const Remote = 3;
870
- const Test = 4;
871
-
872
- /* istanbul ignore file */
873
-
874
- // TODO this should always be completely tree shaken out during build, maybe need to be marked as @__Pure for terser to work
875
-
876
- // TODO treeshake this function out when targeting electron
877
-
878
- /**
879
- * @returns {number}
880
- */
881
- const getPlatform = () => {
882
- // @ts-ignore
883
- if (typeof PLATFORM !== 'undefined') {
884
- // @ts-ignore
885
- return PLATFORM;
886
- }
887
- // @ts-ignore
888
- if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
889
- return Test;
890
- }
891
- // TODO find a better way to pass runtime environment
892
- if (typeof name !== 'undefined' && name.endsWith('(Electron)')) {
893
- return Electron;
894
- }
895
- if (typeof name !== 'undefined' && name.endsWith('(Web)')) {
896
- return Web;
897
- }
898
- return Remote;
899
- };
900
- const platform = getPlatform();
901
-
902
923
  const WebView = 'lvce-oss-webview';
903
924
 
904
925
  const getWebView$1 = (webViews, webViewId) => {
@@ -953,7 +974,9 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
953
974
  // TODO either
954
975
  // - load webviews the same as in web using blob urls
955
976
  // - load webviews from a pattern like /webviews/:id/:fileName
956
- iframeContent = iframeContent.replaceAll('/media/', '/').replaceAll('//', '/');
977
+ if (!webView.path) {
978
+ iframeContent = iframeContent.replaceAll('/media/', '/').replaceAll('//', '/');
979
+ }
957
980
  return {
958
981
  srcDoc: '',
959
982
  iframeSrc,
@@ -1101,6 +1124,11 @@ const getWebViewOrigin = (webViewPort, platform) => {
1101
1124
  return origin;
1102
1125
  };
1103
1126
 
1127
+ const getIframePermissionPolicy = webView => {
1128
+ const extensionAllow = webView.allow || [];
1129
+ return extensionAllow;
1130
+ };
1131
+
1104
1132
  const getWebViews = async () => {
1105
1133
  return invoke$3('WebView.getWebViews');
1106
1134
  };
@@ -1119,11 +1147,6 @@ const getIframeSandbox = (webView, platform) => {
1119
1147
  return [AllowScripts, AllowSameOrigin, ...extensionSandbox];
1120
1148
  };
1121
1149
 
1122
- const getIframePermissionPolicy = webView => {
1123
- const extensionAllow = webView.allow || [];
1124
- return extensionAllow;
1125
- };
1126
-
1127
1150
  const state = {
1128
1151
  id: 0
1129
1152
  };
@@ -1156,19 +1179,6 @@ const invoke = async (method, ...params) => {
1156
1179
  return invoke$3('WebView.compatSharedProcessInvoke', method, ...params);
1157
1180
  };
1158
1181
 
1159
- const getAssetDir = () => {
1160
- // @ts-ignore
1161
- if (typeof ASSET_DIR !== 'undefined') {
1162
- // @ts-ignore
1163
- return ASSET_DIR;
1164
- }
1165
- if (platform === Electron) {
1166
- return '';
1167
- }
1168
- return '';
1169
- };
1170
- const assetDir = getAssetDir();
1171
-
1172
1182
  const registerProtocol = async () => {
1173
1183
  await invoke('WebViewServer.registerProtocol');
1174
1184
  };
@@ -1213,6 +1223,7 @@ const getModule = platform => {
1213
1223
  return register$1;
1214
1224
  }
1215
1225
  };
1226
+
1216
1227
  const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
1217
1228
  const fn = getModule(platform);
1218
1229
  return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
@@ -1262,7 +1273,7 @@ const create2 = async ({
1262
1273
  const permissionPolicy = getIframePermissionPolicy(webView);
1263
1274
  const permissionPolicyString = permissionPolicy.join('; ');
1264
1275
  const iframeCsp = platform === Web ? csp : '';
1265
- const credentialless = true;
1276
+ const credentialless = getCredentialLess(locationHost);
1266
1277
  await invoke$3('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
1267
1278
  const {
1268
1279
  port1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/iframe-worker",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Web Worker to manage creation and lifecycle of iframes in Lvce Editor",
5
5
  "main": "dist/iframeWorkerMain.js",
6
6
  "type": "module",