@jsenv/core 25.3.0-alpha.0 → 25.4.2

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.
Files changed (107) hide show
  1. package/dist/browser_runtime/asset-manifest.json +2 -2
  2. package/dist/browser_runtime/{browser_runtime_91c5a3b8.js → browser_runtime_0e3396a1.js} +15 -16
  3. package/dist/browser_runtime/{browser_runtime_91c5a3b8.js.map → browser_runtime_0e3396a1.js.map} +13 -13
  4. package/dist/build_manifest.js +5 -5
  5. package/dist/compile_proxy/asset-manifest.json +2 -2
  6. package/dist/compile_proxy/compile_proxy.html__inline__20_f4285042.js.map +343 -0
  7. package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_ab528227.html} +358 -397
  8. package/dist/redirector/asset-manifest.json +2 -2
  9. package/dist/redirector/redirector.html__inline__12_404b8295.js.map +349 -0
  10. package/dist/redirector/{redirector_3e9a97b9.html → redirector_6df2620a.html} +369 -407
  11. package/dist/toolbar/asset-manifest.json +2 -2
  12. package/dist/toolbar/toolbar.main_279b3a68.js.map +764 -0
  13. package/dist/toolbar/{toolbar_361afb84.html → toolbar_0a91ca3b.html} +1509 -1583
  14. package/dist/toolbar_injector/asset-manifest.json +2 -2
  15. package/dist/toolbar_injector/{toolbar_injector_fac1e995.js → toolbar_injector_34f6ad8e.js} +18 -15
  16. package/dist/toolbar_injector/{toolbar_injector_fac1e995.js.map → toolbar_injector_34f6ad8e.js.map} +15 -15
  17. package/package.json +10 -10
  18. package/src/buildProject.js +31 -26
  19. package/src/dev_server.js +111 -92
  20. package/src/execute.js +3 -8
  21. package/src/importUsingChildProcess.js +1 -0
  22. package/src/internal/browser_launcher/{browser_runtime_report.js → browser_runtime_profile.js} +21 -15
  23. package/src/internal/browser_launcher/executeHtmlFile.js +22 -14
  24. package/src/internal/browser_launcher/from_playwright.js +6 -4
  25. package/src/internal/browser_runtime/browser_runtime.js +12 -14
  26. package/src/internal/browser_runtime/createBrowserRuntime.js +7 -6
  27. package/src/internal/browser_utils/fetchAndEvalUsingFetch.js +1 -1
  28. package/src/internal/browser_utils/fetchJson.js +1 -1
  29. package/src/internal/browser_utils/{fetch-browser.js → fetch_browser.js} +0 -2
  30. package/src/internal/building/buildUsingRollup.js +41 -57
  31. package/src/internal/building/rollup_plugin_jsenv.js +28 -8
  32. package/src/internal/compiling/babel_parse_error.js +9 -0
  33. package/src/internal/{babel_plugin_transform_import_meta.js → compiling/babel_plugin_transform_import_meta.js} +53 -36
  34. package/src/internal/compiling/compileFile.js +2 -2
  35. package/src/internal/compiling/compileHtml.js +1 -1
  36. package/src/internal/compiling/createCompiledFileService.js +25 -74
  37. package/src/internal/compiling/js-compilation-service/transformJs.js +151 -23
  38. package/src/internal/compiling/jsenvCompilerForHtml.js +29 -32
  39. package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -2
  40. package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -4
  41. package/src/internal/compiling/jsenv_directory/comparison_utils.js +24 -0
  42. package/src/internal/compiling/{compile-directory/compile-asset.js → jsenv_directory/compile_asset.js} +0 -0
  43. package/src/internal/compiling/jsenv_directory/compile_context.js +68 -0
  44. package/src/internal/compiling/jsenv_directory/compile_profile.js +218 -0
  45. package/src/internal/compiling/{compile-directory/createLockRegistry.js → jsenv_directory/file_lock_registry.js} +0 -0
  46. package/src/internal/compiling/{compile-directory/createLockRegistry.test.js → jsenv_directory/file_lock_registry.test.js} +2 -1
  47. package/src/internal/compiling/{compile-directory → jsenv_directory}/fs-optimized-for-cache.js +0 -0
  48. package/src/internal/compiling/{compile-directory → jsenv_directory}/getOrGenerateCompiledFile.js +2 -2
  49. package/src/internal/compiling/jsenv_directory/jsenv_directory.js +174 -0
  50. package/src/internal/compiling/{compile-directory → jsenv_directory}/updateMeta.js +1 -1
  51. package/src/internal/compiling/{compile-directory → jsenv_directory}/validateCache.js +0 -0
  52. package/src/internal/compiling/sse_service/sse_service.js +369 -0
  53. package/src/internal/compiling/startCompileServer.js +157 -804
  54. package/src/internal/compiling/transformResultToCompilationResult.js +2 -2
  55. package/src/internal/dev_server/exploring/exploring.js +10 -8
  56. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +92 -78
  57. package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
  58. package/src/internal/dev_server/toolbar/toolbar.html +46 -16
  59. package/src/internal/dev_server/toolbar/toolbar.injector.js +17 -15
  60. package/src/internal/dev_server/toolbar/toolbar.main.js +12 -16
  61. package/src/internal/executing/executeConcurrently.js +1 -1
  62. package/src/internal/executing/executePlan.js +2 -3
  63. package/src/internal/{generateGroupMap → features}/babel_plugins_compatibility.js +8 -8
  64. package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +20 -0
  65. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +23 -0
  66. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +25 -0
  67. package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +37 -0
  68. package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +9 -0
  69. package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +14 -0
  70. package/src/internal/features/browser_feature_detection/browser_feature_detection.js +89 -0
  71. package/src/internal/{browser_feature_detection → features/browser_feature_detection}/compile_proxy.html +1 -1
  72. package/src/internal/features/browser_feature_detection/execute_with_script_module.js +24 -0
  73. package/src/internal/features/features_compat_from_runtime.js +38 -0
  74. package/src/internal/features/features_compat_from_runtime_support.js +31 -0
  75. package/src/internal/{generateGroupMap → features}/features_compatibility.js +3 -3
  76. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_dynamic_import.mjs +0 -0
  77. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_top_level_await.mjs +0 -0
  78. package/src/internal/{node_feature_detection/nodeSupportsDynamicImport.js → features/node_feature_detection/node_feature_detect_dynamic_import.js} +0 -0
  79. package/src/internal/{node_feature_detection/nodeSupportsTopLevelAwait.js → features/node_feature_detection/node_feature_detect_top_level_await.js} +0 -0
  80. package/src/internal/features/node_feature_detection/node_feature_detection.js +66 -0
  81. package/src/internal/node_launcher/createControllableNodeProcess.js +4 -6
  82. package/src/internal/node_launcher/node_runtime_report.js +15 -9
  83. package/src/internal/node_runtime/fetchSource.js +2 -4
  84. package/src/internal/node_runtime/nodeControllableFile.mjs +1 -5
  85. package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
  86. package/src/internal/redirector/redirector.html +40 -0
  87. package/src/internal/{generateGroupMap/jsenvRuntimeSupport.js → runtime_support/jsenv_runtime_support.js} +0 -0
  88. package/src/internal/{generateGroupMap → runtime_support}/runtime_support.js +0 -0
  89. package/src/internal/url_conversion.js +12 -17
  90. package/src/launchNode.js +29 -41
  91. package/dist/compile_proxy/compile_proxy.html__inline__20_809f35f7.js.map +0 -392
  92. package/dist/redirector/redirector.html__inline__15_e391410e.js.map +0 -397
  93. package/dist/toolbar/toolbar.main_6c1b3d82.js.map +0 -802
  94. package/src/internal/CONSTANTS.js +0 -11
  95. package/src/internal/browser_feature_detection/browser_feature_detection.js +0 -274
  96. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +0 -242
  97. package/src/internal/dev_server/redirector/redirector.html +0 -48
  98. package/src/internal/generateGroupMap/generateGroupMap.js +0 -65
  99. package/src/internal/generateGroupMap/one_runtime_compat.js +0 -38
  100. package/src/internal/generateGroupMap/runtime_compat.js +0 -34
  101. package/src/internal/generateGroupMap/runtime_compat_composition.js +0 -76
  102. package/src/internal/generateGroupMap/shake_babel_plugin_map.js +0 -21
  103. package/src/internal/node_feature_detection/node_feature_detection.js +0 -117
  104. package/src/internal/node_runtime/detectNode.js +0 -3
  105. package/src/internal/runtime/computeCompileIdFromGroupId.js +0 -30
  106. package/src/internal/runtime/resolveGroup.js +0 -13
  107. package/src/internal/runtime/resolveRuntimeGroup.js +0 -11
@@ -1915,19 +1915,29 @@ html[data-toolbar-visible] #toolbar-trigger {
1915
1915
  <div class="files_compilation_text">
1916
1916
  <span data-when="filesCompilation:no">Files shown are source files</span>
1917
1917
  <span data-when="filesCompilation:html_only">Files shown are source files, except html</span>
1918
- <span data-when="filesCompilation:yes">Files shown are compiled</span>
1918
+ <span data-when="filesCompilation:yes">Files shown are compiled for {runtime}</span>
1919
+ <span data-when="filesCompilation:mismatch">Files shown are compiled for an other runtime</span>
1919
1920
  </div>
1920
- <a data-when="compiled:yes" class="go_to_source_link" href="javascript:void(0);">Switch to source files</a>
1921
- <a data-when="compiled:no" class="go_to_compiled_link" href="javascript:void(0);">Switch to compiled files</a>
1921
+ <a data-when="compilation_link:source" class="link_to_source_files" href="javascript:void(0);">Switch to source files</a>
1922
+ <a data-when="compilation_link:mismatch" class="link_to_appropriate_files" href="javascript:void(0);">Switch to appropriate files</a>
1923
+ <a data-when="compilation_link:compiled" class="link_to_compiled_files" href="javascript:void(0);">Switch to compiled files</a>
1924
+ <a data-when="compilation_link:force" class="link_to_compilation_forced_files" href="javascript:void(0);">Force compilation</a>
1922
1925
  </div>
1923
1926
  </div>
1924
1927
  </div>
1925
1928
  </div>
1926
1929
  </div>
1927
1930
  <button id="settings-button" class="toolbar-icon-wrapper">
1928
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px" height="24px" class="iconToolbar">
1929
- <path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"></path>
1930
- </svg>
1931
+ <div data-when="has_warning:yes">
1932
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 511.999 511.999" width="24px" height="24px" class="iconToolbar">
1933
+ <path d="M506.43 421.536 291.573 49.394c-15.814-27.391-55.327-27.401-71.147 0L5.568 421.536c-15.814 27.391 3.934 61.616 35.574 61.616h429.714c31.629.001 51.394-34.214 35.574-61.616zm-231.609-36.502c0 10.394-8.427 18.821-18.821 18.821s-18.821-8.427-18.821-18.821v-11.239c0-10.394 8.427-18.821 18.821-18.821s18.821 8.427 18.821 18.821v11.239zm0-73.332c0 10.394-8.427 18.821-18.821 18.821s-18.821-8.427-18.821-18.821v-107.89c0-10.394 8.427-18.821 18.821-18.821s18.821 8.427 18.821 18.821v107.89z"></path>
1934
+ </svg>
1935
+ </div>
1936
+ <div data-when="has_warning:no">
1937
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px" height="24px" class="iconToolbar">
1938
+ <path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"></path>
1939
+ </svg>
1940
+ </div>
1931
1941
  </button>
1932
1942
  </section>
1933
1943
 
@@ -2182,64 +2192,6 @@ html[data-toolbar-visible] #toolbar-trigger {
2182
2192
  return relativeUrl;
2183
2193
  };
2184
2194
 
2185
- var _defineProperty = function (obj, key, value) {
2186
- // Shortcircuit the slow defineProperty path when possible.
2187
- // We are trying to avoid issues where setters defined on the
2188
- // prototype cause side effects under the fast path of simple
2189
- // assignment. By checking for existence of the property with
2190
- // the in operator, we can optimize most of this overhead away.
2191
- if (key in obj) {
2192
- Object.defineProperty(obj, key, {
2193
- value: value,
2194
- enumerable: true,
2195
- configurable: true,
2196
- writable: true
2197
- });
2198
- } else {
2199
- obj[key] = value;
2200
- }
2201
-
2202
- return obj;
2203
- };
2204
-
2205
- function ownKeys(object, enumerableOnly) {
2206
- var keys = Object.keys(object);
2207
-
2208
- if (Object.getOwnPropertySymbols) {
2209
- var symbols = Object.getOwnPropertySymbols(object);
2210
-
2211
- if (enumerableOnly) {
2212
- symbols = symbols.filter(function (sym) {
2213
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
2214
- });
2215
- }
2216
-
2217
- keys.push.apply(keys, symbols);
2218
- }
2219
-
2220
- return keys;
2221
- }
2222
-
2223
- function _objectSpread2(target) {
2224
- for (var i = 1; i < arguments.length; i++) {
2225
- var source = arguments[i] != null ? arguments[i] : {};
2226
-
2227
- if (i % 2) {
2228
- ownKeys(Object(source), true).forEach(function (key) {
2229
- _defineProperty(target, key, source[key]);
2230
- });
2231
- } else if (Object.getOwnPropertyDescriptors) {
2232
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
2233
- } else {
2234
- ownKeys(Object(source)).forEach(function (key) {
2235
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2236
- });
2237
- }
2238
- }
2239
-
2240
- return target;
2241
- }
2242
-
2243
2195
  var objectWithoutPropertiesLoose = function (source, excluded) {
2244
2196
  if (source === null) return {};
2245
2197
  var target = {};
@@ -2275,740 +2227,142 @@ html[data-toolbar-visible] #toolbar-trigger {
2275
2227
 
2276
2228
  return target;
2277
2229
  };
2278
- /* eslint-env browser */
2279
-
2280
2230
 
2281
- function _await$5(value, then, direct) {
2282
- if (direct) {
2283
- return then ? then(value) : value;
2231
+ var updateIframeOverflowOnParentWindow = function updateIframeOverflowOnParentWindow() {
2232
+ if (!window.parent) {
2233
+ // can happen while parent iframe reloads
2234
+ return;
2284
2235
  }
2285
2236
 
2286
- if (!value || !value.then) {
2287
- value = Promise.resolve(value);
2288
- }
2237
+ var aTooltipIsOpened = document.querySelector("[data-tooltip-visible]") || document.querySelector("[data-tooltip-auto-visible]");
2238
+ var settingsAreOpened = document.querySelector("#settings[data-active]");
2289
2239
 
2290
- return then ? value.then(then) : value;
2291
- }
2240
+ if (aTooltipIsOpened || settingsAreOpened) {
2241
+ enableIframeOverflowOnParentWindow();
2242
+ } else {
2243
+ disableIframeOverflowOnParentWindow();
2244
+ }
2245
+ };
2292
2246
 
2293
- function _async$6(f) {
2294
- return function () {
2295
- for (var args = [], i = 0; i < arguments.length; i++) {
2296
- args[i] = arguments[i];
2297
- }
2247
+ var iframeOverflowEnabled = false;
2298
2248
 
2299
- try {
2300
- return Promise.resolve(f.apply(this, args));
2301
- } catch (e) {
2302
- return Promise.reject(e);
2303
- }
2304
- };
2305
- }
2249
+ var enableIframeOverflowOnParentWindow = function enableIframeOverflowOnParentWindow() {
2250
+ if (iframeOverflowEnabled) return;
2251
+ iframeOverflowEnabled = true;
2252
+ var iframe = getToolbarIframe();
2253
+ var transitionDuration = iframe.style.transitionDuration;
2254
+ setStyles(iframe, {
2255
+ "height": "100%",
2256
+ "transition-duration": "0ms"
2257
+ });
2306
2258
 
2307
- function _call$2(body, then, direct) {
2308
- if (direct) {
2309
- return then ? then(body()) : body();
2259
+ if (transitionDuration) {
2260
+ setTimeout(function () {
2261
+ setStyles(iframe, {
2262
+ "transition-duration": transitionDuration
2263
+ });
2264
+ });
2310
2265
  }
2266
+ };
2311
2267
 
2312
- try {
2313
- var result = Promise.resolve(body());
2314
- return then ? result.then(then) : result;
2315
- } catch (e) {
2316
- return Promise.reject(e);
2268
+ var disableIframeOverflowOnParentWindow = function disableIframeOverflowOnParentWindow() {
2269
+ if (!iframeOverflowEnabled) return;
2270
+ iframeOverflowEnabled = false;
2271
+ var iframe = getToolbarIframe();
2272
+ var transitionDuration = iframe.style.transitionDuration;
2273
+ setStyles(iframe, {
2274
+ "height": "40px",
2275
+ "transition-duration": "0ms"
2276
+ });
2277
+
2278
+ if (transitionDuration) {
2279
+ setTimeout(function () {
2280
+ setStyles(iframe, {
2281
+ "transition-duration": transitionDuration
2282
+ });
2283
+ });
2317
2284
  }
2318
- }
2285
+ };
2319
2286
 
2320
- var fetchUsingXHR = _async$6(function (url) {
2321
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2322
- signal = _ref.signal,
2323
- _ref$method = _ref.method,
2324
- method = _ref$method === void 0 ? "GET" : _ref$method,
2325
- _ref$credentials = _ref.credentials,
2326
- credentials = _ref$credentials === void 0 ? "same-origin" : _ref$credentials,
2327
- _ref$headers = _ref.headers,
2328
- headers = _ref$headers === void 0 ? {} : _ref$headers,
2329
- _ref$body = _ref.body,
2330
- body = _ref$body === void 0 ? null : _ref$body;
2287
+ var getToolbarIframe = function getToolbarIframe() {
2288
+ var iframes = Array.from(window.parent.document.querySelectorAll("iframe"));
2289
+ return iframes.find(function (iframe) {
2290
+ return iframe.contentWindow === window;
2291
+ });
2292
+ };
2331
2293
 
2332
- var headersPromise = createPromiseAndHooks();
2333
- var bodyPromise = createPromiseAndHooks();
2334
- var xhr = new XMLHttpRequest();
2294
+ var forceHideElement = function forceHideElement(element) {
2295
+ element.setAttribute("data-force-hide", "");
2296
+ };
2335
2297
 
2336
- var failure = function failure(error) {
2337
- // if it was already resolved, we must reject the body promise
2338
- if (headersPromise.settled) {
2339
- bodyPromise.reject(error);
2298
+ var removeForceHideElement = function removeForceHideElement(element) {
2299
+ element.removeAttribute("data-force-hide");
2300
+ };
2301
+
2302
+ var setStyles = function setStyles(element, styles) {
2303
+ var elementStyle = element.style;
2304
+ var restoreStyles = Object.keys(styles).map(function (styleName) {
2305
+ var restore;
2306
+
2307
+ if (styleName in elementStyle) {
2308
+ var currentStyle = elementStyle[styleName];
2309
+
2310
+ restore = function restore() {
2311
+ elementStyle[styleName] = currentStyle;
2312
+ };
2340
2313
  } else {
2341
- headersPromise.reject(error);
2314
+ restore = function restore() {
2315
+ delete elementStyle[styleName];
2316
+ };
2342
2317
  }
2343
- };
2344
2318
 
2345
- var cleanup = function cleanup() {
2346
- xhr.ontimeout = null;
2347
- xhr.onerror = null;
2348
- xhr.onload = null;
2349
- xhr.onreadystatechange = null;
2319
+ elementStyle[styleName] = styles[styleName];
2320
+ return restore;
2321
+ });
2322
+ return function () {
2323
+ restoreStyles.forEach(function (restore) {
2324
+ return restore();
2325
+ });
2350
2326
  };
2327
+ };
2351
2328
 
2352
- xhr.ontimeout = function () {
2353
- cleanup();
2354
- failure(new Error("xhr request timeout on ".concat(url, ".")));
2355
- };
2329
+ var toolbarSectionIsActive = function toolbarSectionIsActive(element) {
2330
+ return element.hasAttribute("data-active");
2331
+ };
2356
2332
 
2357
- xhr.onerror = function (error) {
2358
- cleanup(); // unfortunately with have no clue why it fails
2359
- // might be cors for instance
2333
+ var activateToolbarSection = function activateToolbarSection(element) {
2334
+ element.setAttribute("data-active", "");
2335
+ };
2360
2336
 
2361
- failure(createRequestError(error, {
2362
- url: url
2363
- }));
2364
- };
2337
+ var deactivateToolbarSection = function deactivateToolbarSection(element) {
2338
+ element.removeAttribute("data-active");
2339
+ };
2365
2340
 
2366
- xhr.onload = function () {
2367
- cleanup();
2368
- bodyPromise.resolve();
2369
- };
2341
+ var startJavaScriptAnimation = function startJavaScriptAnimation(_ref6) {
2342
+ var _ref6$duration = _ref6.duration,
2343
+ duration = _ref6$duration === void 0 ? 300 : _ref6$duration,
2344
+ _ref6$timingFunction = _ref6.timingFunction,
2345
+ timingFunction = _ref6$timingFunction === void 0 ? function (t) {
2346
+ return t;
2347
+ } : _ref6$timingFunction,
2348
+ _ref6$onProgress = _ref6.onProgress,
2349
+ onProgress = _ref6$onProgress === void 0 ? function () {} : _ref6$onProgress,
2350
+ _ref6$onCancel = _ref6.onCancel,
2351
+ onCancel = _ref6$onCancel === void 0 ? function () {} : _ref6$onCancel,
2352
+ _ref6$onComplete = _ref6.onComplete,
2353
+ onComplete = _ref6$onComplete === void 0 ? function () {} : _ref6$onComplete;
2370
2354
 
2371
- signal.addEventListener("abort", function () {
2372
- xhr.abort();
2373
- var abortError = new Error("aborted");
2374
- abortError.name = "AbortError";
2375
- failure(abortError);
2376
- });
2355
+ if (isNaN(duration)) {
2356
+ // console.warn(`duration must be a number, received ${duration}`)
2357
+ return function () {};
2358
+ }
2377
2359
 
2378
- xhr.onreadystatechange = function () {
2379
- // https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/readyState
2380
- var readyState = xhr.readyState;
2381
-
2382
- if (readyState === 2) {
2383
- headersPromise.resolve();
2384
- } else if (readyState === 4) {
2385
- cleanup();
2386
- bodyPromise.resolve();
2387
- }
2388
- };
2389
-
2390
- xhr.open(method, url, true);
2391
- Object.keys(headers).forEach(function (key) {
2392
- xhr.setRequestHeader(key, headers[key]);
2393
- });
2394
- xhr.withCredentials = computeWithCredentials({
2395
- credentials: credentials,
2396
- url: url
2397
- });
2398
-
2399
- if ("responseType" in xhr && hasBlob) {
2400
- xhr.responseType = "blob";
2401
- }
2402
-
2403
- xhr.send(body);
2404
- return _await$5(headersPromise, function () {
2405
- // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL
2406
- var responseUrl = "responseURL" in xhr ? xhr.responseURL : headers["x-request-url"];
2407
- var responseStatus = xhr.status;
2408
- var responseStatusText = xhr.statusText;
2409
- var responseHeaders = getHeadersFromXHR(xhr);
2410
-
2411
- var readBody = function readBody() {
2412
- return _await$5(bodyPromise, function () {
2413
- var status = xhr.status; // in Chrome on file:/// URLs, status is 0
2414
-
2415
- if (status === 0) {
2416
- responseStatus = 200;
2417
- }
2418
-
2419
- var body = "response" in xhr ? xhr.response : xhr.responseText;
2420
- return {
2421
- responseBody: body,
2422
- responseBodyType: detectBodyType(body)
2423
- };
2424
- });
2425
- };
2426
-
2427
- var text = function text() {
2428
- return _call$2(readBody, function (_ref2) {
2429
- var responseBody = _ref2.responseBody,
2430
- responseBodyType = _ref2.responseBodyType;
2431
-
2432
- if (responseBodyType === "blob") {
2433
- return blobToText(responseBody);
2434
- }
2435
-
2436
- if (responseBodyType === "formData") {
2437
- throw new Error("could not read FormData body as text");
2438
- }
2439
-
2440
- return responseBodyType === "dataView" ? arrayBufferToText(responseBody.buffer) : responseBodyType === "arrayBuffer" ? arrayBufferToText(responseBody) : String(responseBody);
2441
- });
2442
- };
2443
-
2444
- var json = function json() {
2445
- return _call$2(text, JSON.parse);
2446
- };
2447
-
2448
- var blob = _async$6(function () {
2449
- if (!hasBlob) {
2450
- throw new Error("blob not supported");
2451
- }
2452
-
2453
- return _call$2(readBody, function (_ref3) {
2454
- var responseBody = _ref3.responseBody,
2455
- responseBodyType = _ref3.responseBodyType;
2456
-
2457
- if (responseBodyType === "blob") {
2458
- return responseBody;
2459
- }
2460
-
2461
- if (responseBodyType === "dataView") {
2462
- return new Blob([cloneBuffer(responseBody.buffer)]);
2463
- }
2464
-
2465
- if (responseBodyType === "arrayBuffer") {
2466
- return new Blob([cloneBuffer(responseBody)]);
2467
- }
2468
-
2469
- if (responseBodyType === "formData") {
2470
- throw new Error("could not read FormData body as blob");
2471
- }
2472
-
2473
- return new Blob([String(responseBody)]);
2474
- });
2475
- });
2476
-
2477
- var arrayBuffer = function arrayBuffer() {
2478
- return _call$2(readBody, function (_ref4) {
2479
- var responseBody = _ref4.responseBody,
2480
- responseBodyType = _ref4.responseBodyType;
2481
- return responseBodyType === "arrayBuffer" ? cloneBuffer(responseBody) : _call$2(blob, blobToArrayBuffer);
2482
- });
2483
- };
2484
-
2485
- var formData = _async$6(function () {
2486
- if (!hasFormData) {
2487
- throw new Error("formData not supported");
2488
- }
2489
-
2490
- return _call$2(text, textToFormData);
2491
- });
2492
-
2493
- return {
2494
- url: responseUrl,
2495
- status: responseStatus,
2496
- statusText: responseStatusText,
2497
- headers: responseHeaders,
2498
- text: text,
2499
- json: json,
2500
- blob: blob,
2501
- arrayBuffer: arrayBuffer,
2502
- formData: formData
2503
- };
2504
- });
2505
- });
2506
-
2507
- var canUseBlob = function canUseBlob() {
2508
- if (typeof window.FileReader !== "function") return false;
2509
- if (typeof window.Blob !== "function") return false;
2510
-
2511
- try {
2512
- // eslint-disable-next-line no-new
2513
- new Blob();
2514
- return true;
2515
- } catch (e) {
2516
- return false;
2517
- }
2518
- };
2519
-
2520
- var hasBlob = canUseBlob();
2521
- var hasFormData = typeof window.FormData === "function";
2522
- var hasArrayBuffer = typeof window.ArrayBuffer === "function";
2523
- var hasSearchParams = typeof window.URLSearchParams === "function";
2524
-
2525
- var createRequestError = function createRequestError(error, _ref5) {
2526
- var url = _ref5.url;
2527
- return new Error("error during xhr request on ".concat(url, ".\n--- error stack ---\n").concat(error.stack));
2528
- };
2529
-
2530
- var createPromiseAndHooks = function createPromiseAndHooks() {
2531
- var resolve;
2532
- var reject;
2533
- var promise = new Promise(function (res, rej) {
2534
- resolve = function resolve(value) {
2535
- promise.settled = true;
2536
- res(value);
2537
- };
2538
-
2539
- reject = function reject(value) {
2540
- promise.settled = true;
2541
- rej(value);
2542
- };
2543
- });
2544
- promise.resolve = resolve;
2545
- promise.reject = reject;
2546
- return promise;
2547
- }; // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
2548
-
2549
-
2550
- var computeWithCredentials = function computeWithCredentials(_ref6) {
2551
- var credentials = _ref6.credentials,
2552
- url = _ref6.url;
2553
-
2554
- if (credentials === "same-origin") {
2555
- return originSameAsGlobalOrigin(url);
2556
- }
2557
-
2558
- return credentials === "include";
2559
- };
2560
-
2561
- var originSameAsGlobalOrigin = function originSameAsGlobalOrigin(url) {
2562
- // if we cannot read globalOrigin from window.location.origin, let's consider it's ok
2563
- if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== "object") return true;
2564
- if (_typeof(window.location) !== "object") return true;
2565
- var globalOrigin = window.location.origin;
2566
- if (globalOrigin === "null") return true;
2567
- return hrefToOrigin(url) === globalOrigin;
2568
- };
2569
-
2570
- var detectBodyType = function detectBodyType(body) {
2571
- if (!body) {
2572
- return "";
2573
- }
2574
-
2575
- if (typeof body === "string") {
2576
- return "text";
2577
- }
2578
-
2579
- if (hasBlob && Blob.prototype.isPrototypeOf(body)) {
2580
- return "blob";
2581
- }
2582
-
2583
- if (hasFormData && FormData.prototype.isPrototypeOf(body)) {
2584
- return "formData";
2585
- }
2586
-
2587
- if (hasArrayBuffer) {
2588
- if (hasBlob && isDataView(body)) {
2589
- return "dataView";
2590
- }
2591
-
2592
- if (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body)) {
2593
- return "arrayBuffer";
2594
- }
2595
- }
2596
-
2597
- if (hasSearchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
2598
- return "searchParams";
2599
- }
2600
-
2601
- return "";
2602
- }; // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
2603
-
2604
-
2605
- var getHeadersFromXHR = function getHeadersFromXHR(xhr) {
2606
- var headerMap = {};
2607
- var headersString = xhr.getAllResponseHeaders();
2608
- if (headersString === "") return headerMap;
2609
- var lines = headersString.trim().split(/[\r\n]+/);
2610
- lines.forEach(function (line) {
2611
- var parts = line.split(": ");
2612
- var name = parts.shift();
2613
- var value = parts.join(": ");
2614
- headerMap[name.toLowerCase()] = value;
2615
- });
2616
- return headerMap;
2617
- };
2618
-
2619
- var hrefToOrigin = function hrefToOrigin(href) {
2620
- var scheme = hrefToScheme(href);
2621
-
2622
- if (scheme === "file") {
2623
- return "file://";
2624
- }
2625
-
2626
- if (scheme === "http" || scheme === "https") {
2627
- var secondProtocolSlashIndex = scheme.length + "://".length;
2628
- var pathnameSlashIndex = href.indexOf("/", secondProtocolSlashIndex);
2629
- if (pathnameSlashIndex === -1) return href;
2630
- return href.slice(0, pathnameSlashIndex);
2631
- }
2632
-
2633
- return href.slice(0, scheme.length + 1);
2634
- };
2635
-
2636
- var hrefToScheme = function hrefToScheme(href) {
2637
- var colonIndex = href.indexOf(":");
2638
- if (colonIndex === -1) return "";
2639
- return href.slice(0, colonIndex);
2640
- };
2641
-
2642
- var isDataView = function isDataView(obj) {
2643
- return obj && DataView.prototype.isPrototypeOf(obj);
2644
- };
2645
-
2646
- var isArrayBufferView = ArrayBuffer.isView || function () {
2647
- var viewClasses = ["[object Int8Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Int16Array]", "[object Uint16Array]", "[object Int32Array]", "[object Uint32Array]", "[object Float32Array]", "[object Float64Array]"];
2648
- return function (value) {
2649
- return value && viewClasses.includes(Object.prototype.toString.call(value));
2650
- };
2651
- }();
2652
-
2653
- var textToFormData = function textToFormData(text) {
2654
- var form = new FormData();
2655
- text.trim().split("&").forEach(function (bytes) {
2656
- if (bytes) {
2657
- var split = bytes.split("=");
2658
- var name = split.shift().replace(/\+/g, " ");
2659
- var value = split.join("=").replace(/\+/g, " ");
2660
- form.append(decodeURIComponent(name), decodeURIComponent(value));
2661
- }
2662
- });
2663
- return form;
2664
- };
2665
-
2666
- var blobToArrayBuffer = _async$6(function (blob) {
2667
- var reader = new FileReader();
2668
- var promise = fileReaderReady(reader);
2669
- reader.readAsArrayBuffer(blob);
2670
- return promise;
2671
- });
2672
-
2673
- var blobToText = function blobToText(blob) {
2674
- var reader = new FileReader();
2675
- var promise = fileReaderReady(reader);
2676
- reader.readAsText(blob);
2677
- return promise;
2678
- };
2679
-
2680
- var arrayBufferToText = function arrayBufferToText(arrayBuffer) {
2681
- var view = new Uint8Array(arrayBuffer);
2682
- var chars = new Array(view.length);
2683
- var i = 0;
2684
-
2685
- while (i < view.length) {
2686
- chars[i] = String.fromCharCode(view[i]);
2687
- i++;
2688
- }
2689
-
2690
- return chars.join("");
2691
- };
2692
-
2693
- var fileReaderReady = function fileReaderReady(reader) {
2694
- return new Promise(function (resolve, reject) {
2695
- reader.onload = function () {
2696
- resolve(reader.result);
2697
- };
2698
-
2699
- reader.onerror = function () {
2700
- reject(reader.error);
2701
- };
2702
- });
2703
- };
2704
-
2705
- var cloneBuffer = function cloneBuffer(buffer) {
2706
- if (buffer.slice) {
2707
- return buffer.slice(0);
2708
- }
2709
-
2710
- var view = new Uint8Array(buffer.byteLength);
2711
- view.set(new Uint8Array(buffer));
2712
- return view.buffer;
2713
- };
2714
-
2715
- var _excluded$1 = ["mode"];
2716
-
2717
- function _await$4(value, then, direct) {
2718
- if (direct) {
2719
- return then ? then(value) : value;
2720
- }
2721
-
2722
- if (!value || !value.then) {
2723
- value = Promise.resolve(value);
2724
- }
2725
-
2726
- return then ? value.then(then) : value;
2727
- }
2728
-
2729
- function _async$5(f) {
2730
- return function () {
2731
- for (var args = [], i = 0; i < arguments.length; i++) {
2732
- args[i] = arguments[i];
2733
- }
2734
-
2735
- try {
2736
- return Promise.resolve(f.apply(this, args));
2737
- } catch (e) {
2738
- return Promise.reject(e);
2739
- }
2740
- };
2741
- }
2742
-
2743
- var fetchNative = _async$5(function (url) {
2744
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2745
-
2746
- var _ref$mode = _ref.mode,
2747
- mode = _ref$mode === void 0 ? "cors" : _ref$mode,
2748
- options = _objectWithoutProperties(_ref, _excluded$1);
2749
-
2750
- return _await$4(window.fetch(url, _objectSpread2({
2751
- mode: mode
2752
- }, options)), function (response) {
2753
- return {
2754
- url: response.url,
2755
- status: response.status,
2756
- statusText: "",
2757
- headers: responseToHeaders(response),
2758
- text: function text() {
2759
- return response.text();
2760
- },
2761
- json: function json() {
2762
- return response.json();
2763
- },
2764
- blob: function blob() {
2765
- return response.blob();
2766
- },
2767
- arrayBuffer: function arrayBuffer() {
2768
- return response.arrayBuffer();
2769
- },
2770
- formData: function formData() {
2771
- return response.formData();
2772
- }
2773
- };
2774
- });
2775
- });
2776
-
2777
- var responseToHeaders = function responseToHeaders(response) {
2778
- var headers = {};
2779
- response.headers.forEach(function (value, name) {
2780
- headers[name] = value;
2781
- });
2782
- return headers;
2783
- };
2784
-
2785
- var fetchUrl = typeof window.fetch === "function" && typeof window.AbortController === "function" ? fetchNative : fetchUsingXHR;
2786
-
2787
- function _await$3(value, then, direct) {
2788
- if (direct) {
2789
- return then ? then(value) : value;
2790
- }
2791
-
2792
- if (!value || !value.then) {
2793
- value = Promise.resolve(value);
2794
- }
2795
-
2796
- return then ? value.then(then) : value;
2797
- }
2798
-
2799
- function _async$4(f) {
2800
- return function () {
2801
- for (var args = [], i = 0; i < arguments.length; i++) {
2802
- args[i] = arguments[i];
2803
- }
2804
-
2805
- try {
2806
- return Promise.resolve(f.apply(this, args));
2807
- } catch (e) {
2808
- return Promise.reject(e);
2809
- }
2810
- };
2811
- }
2812
-
2813
- var fetchJson = _async$4(function (url) {
2814
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2815
- return _await$3(fetchUrl(url, options), function (response) {
2816
- return _await$3(response.json());
2817
- });
2818
- });
2819
-
2820
- function _await$2(value, then, direct) {
2821
- if (direct) {
2822
- return then ? then(value) : value;
2823
- }
2824
-
2825
- if (!value || !value.then) {
2826
- value = Promise.resolve(value);
2827
- }
2828
-
2829
- return then ? value.then(then) : value;
2830
- }
2831
-
2832
- function _catch$1(body, recover) {
2833
- try {
2834
- var result = body();
2835
- } catch (e) {
2836
- return recover(e);
2837
- }
2838
-
2839
- if (result && result.then) {
2840
- return result.then(void 0, recover);
2841
- }
2842
-
2843
- return result;
2844
- }
2845
-
2846
- function _async$3(f) {
2847
- return function () {
2848
- for (var args = [], i = 0; i < arguments.length; i++) {
2849
- args[i] = arguments[i];
2850
- }
2851
-
2852
- try {
2853
- return Promise.resolve(f.apply(this, args));
2854
- } catch (e) {
2855
- return Promise.reject(e);
2856
- }
2857
- };
2858
- }
2859
-
2860
- var fetchExploringJson = _async$3(function () {
2861
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
2862
- signal = _ref.signal;
2863
-
2864
- return _catch$1(function () {
2865
- return _await$2(fetchJson("/.jsenv/exploring.json", {
2866
- signal: signal
2867
- }));
2868
- }, function (e) {
2869
- if (signal && signal.aborted && e.name === "AbortError") {
2870
- throw e;
2871
- }
2872
-
2873
- throw new Error("Cannot communicate with exploring server due to a network error\n--- error stack ---\n".concat(e.stack));
2874
- });
2875
- });
2876
-
2877
- var updateIframeOverflowOnParentWindow = function updateIframeOverflowOnParentWindow() {
2878
- if (!window.parent) {
2879
- // can happen while parent iframe reloads
2880
- return;
2881
- }
2882
-
2883
- var aTooltipIsOpened = document.querySelector("[data-tooltip-visible]") || document.querySelector("[data-tooltip-auto-visible]");
2884
- var settingsAreOpened = document.querySelector("#settings[data-active]");
2885
-
2886
- if (aTooltipIsOpened || settingsAreOpened) {
2887
- enableIframeOverflowOnParentWindow();
2888
- } else {
2889
- disableIframeOverflowOnParentWindow();
2890
- }
2891
- };
2892
-
2893
- var iframeOverflowEnabled = false;
2894
-
2895
- var enableIframeOverflowOnParentWindow = function enableIframeOverflowOnParentWindow() {
2896
- if (iframeOverflowEnabled) return;
2897
- iframeOverflowEnabled = true;
2898
- var iframe = getToolbarIframe();
2899
- var transitionDuration = iframe.style.transitionDuration;
2900
- setStyles(iframe, {
2901
- "height": "100%",
2902
- "transition-duration": "0ms"
2903
- });
2904
-
2905
- if (transitionDuration) {
2906
- setTimeout(function () {
2907
- setStyles(iframe, {
2908
- "transition-duration": transitionDuration
2909
- });
2910
- });
2911
- }
2912
- };
2913
-
2914
- var disableIframeOverflowOnParentWindow = function disableIframeOverflowOnParentWindow() {
2915
- if (!iframeOverflowEnabled) return;
2916
- iframeOverflowEnabled = false;
2917
- var iframe = getToolbarIframe();
2918
- var transitionDuration = iframe.style.transitionDuration;
2919
- setStyles(iframe, {
2920
- "height": "40px",
2921
- "transition-duration": "0ms"
2922
- });
2923
-
2924
- if (transitionDuration) {
2925
- setTimeout(function () {
2926
- setStyles(iframe, {
2927
- "transition-duration": transitionDuration
2928
- });
2929
- });
2930
- }
2931
- };
2932
-
2933
- var getToolbarIframe = function getToolbarIframe() {
2934
- var iframes = Array.from(window.parent.document.querySelectorAll("iframe"));
2935
- return iframes.find(function (iframe) {
2936
- return iframe.contentWindow === window;
2937
- });
2938
- };
2939
-
2940
- var forceHideElement = function forceHideElement(element) {
2941
- element.setAttribute("data-force-hide", "");
2942
- };
2943
-
2944
- var removeForceHideElement = function removeForceHideElement(element) {
2945
- element.removeAttribute("data-force-hide");
2946
- };
2947
-
2948
- var setStyles = function setStyles(element, styles) {
2949
- var elementStyle = element.style;
2950
- var restoreStyles = Object.keys(styles).map(function (styleName) {
2951
- var restore;
2952
-
2953
- if (styleName in elementStyle) {
2954
- var currentStyle = elementStyle[styleName];
2955
-
2956
- restore = function restore() {
2957
- elementStyle[styleName] = currentStyle;
2958
- };
2959
- } else {
2960
- restore = function restore() {
2961
- delete elementStyle[styleName];
2962
- };
2963
- }
2964
-
2965
- elementStyle[styleName] = styles[styleName];
2966
- return restore;
2967
- });
2968
- return function () {
2969
- restoreStyles.forEach(function (restore) {
2970
- return restore();
2971
- });
2972
- };
2973
- };
2974
-
2975
- var toolbarSectionIsActive = function toolbarSectionIsActive(element) {
2976
- return element.hasAttribute("data-active");
2977
- };
2978
-
2979
- var activateToolbarSection = function activateToolbarSection(element) {
2980
- element.setAttribute("data-active", "");
2981
- };
2982
-
2983
- var deactivateToolbarSection = function deactivateToolbarSection(element) {
2984
- element.removeAttribute("data-active");
2985
- };
2986
-
2987
- var startJavaScriptAnimation = function startJavaScriptAnimation(_ref6) {
2988
- var _ref6$duration = _ref6.duration,
2989
- duration = _ref6$duration === void 0 ? 300 : _ref6$duration,
2990
- _ref6$timingFunction = _ref6.timingFunction,
2991
- timingFunction = _ref6$timingFunction === void 0 ? function (t) {
2992
- return t;
2993
- } : _ref6$timingFunction,
2994
- _ref6$onProgress = _ref6.onProgress,
2995
- onProgress = _ref6$onProgress === void 0 ? function () {} : _ref6$onProgress,
2996
- _ref6$onCancel = _ref6.onCancel,
2997
- onCancel = _ref6$onCancel === void 0 ? function () {} : _ref6$onCancel,
2998
- _ref6$onComplete = _ref6.onComplete,
2999
- onComplete = _ref6$onComplete === void 0 ? function () {} : _ref6$onComplete;
3000
-
3001
- if (isNaN(duration)) {
3002
- // console.warn(`duration must be a number, received ${duration}`)
3003
- return function () {};
3004
- }
3005
-
3006
- duration = parseInt(duration, 10);
3007
- var startMs = performance.now();
3008
- var currentRequestAnimationFrameId;
3009
- var done = false;
3010
- var rawProgress = 0;
3011
- var progress = 0;
2360
+ duration = parseInt(duration, 10);
2361
+ var startMs = performance.now();
2362
+ var currentRequestAnimationFrameId;
2363
+ var done = false;
2364
+ var rawProgress = 0;
2365
+ var progress = 0;
3012
2366
 
3013
2367
  var handler = function handler() {
3014
2368
  currentRequestAnimationFrameId = null;
@@ -3122,33 +2476,6 @@ html[data-toolbar-visible] #toolbar-trigger {
3122
2476
  });
3123
2477
  };
3124
2478
 
3125
- var renderToolbarSettings = function renderToolbarSettings() {
3126
- document.querySelector("#settings-button").onclick = toggleSettings;
3127
- document.querySelector("#button-close-settings").onclick = toggleSettings;
3128
- };
3129
-
3130
- var toggleSettings = function toggleSettings() {
3131
- if (settingsAreVisible()) {
3132
- hideSettings();
3133
- } else {
3134
- showSettings();
3135
- }
3136
- };
3137
-
3138
- var settingsAreVisible = function settingsAreVisible() {
3139
- return toolbarSectionIsActive(document.querySelector("#settings"));
3140
- };
3141
-
3142
- var hideSettings = function hideSettings() {
3143
- deactivateToolbarSection(document.querySelector("#settings"));
3144
- updateIframeOverflowOnParentWindow();
3145
- };
3146
-
3147
- var showSettings = function showSettings() {
3148
- activateToolbarSection(document.querySelector("#settings"));
3149
- updateIframeOverflowOnParentWindow();
3150
- };
3151
-
3152
2479
  var enableVariant = function enableVariant(rootNode, variables) {
3153
2480
  var nodesNotMatching = Array.from(rootNode.querySelectorAll("[".concat(attributeIndicatingACondition, "]")));
3154
2481
  nodesNotMatching.forEach(function (nodeNotMatching) {
@@ -3214,9 +2541,106 @@ html[data-toolbar-visible] #toolbar-trigger {
3214
2541
  node.removeAttribute(name);
3215
2542
  };
3216
2543
 
3217
- var _excluded = ["clickToFocus", "clickToClose"];
2544
+ var renderToolbarSettings = function renderToolbarSettings() {
2545
+ document.querySelector("#settings-button").onclick = toggleSettings;
2546
+ document.querySelector("#button-close-settings").onclick = toggleSettings;
2547
+ };
2548
+
2549
+ var toggleSettings = function toggleSettings() {
2550
+ if (settingsAreVisible()) {
2551
+ hideSettings();
2552
+ } else {
2553
+ showSettings();
2554
+ }
2555
+ };
2556
+
2557
+ var enableWarningStyle = function enableWarningStyle() {
2558
+ enableVariant(document.querySelector("#settings-button"), {
2559
+ has_warning: "yes"
2560
+ });
2561
+ };
2562
+
2563
+ var disableWarningStyle = function disableWarningStyle() {
2564
+ enableVariant(document.querySelector("#settings-button"), {
2565
+ has_warning: "no"
2566
+ });
2567
+ };
2568
+
2569
+ var settingsAreVisible = function settingsAreVisible() {
2570
+ return toolbarSectionIsActive(document.querySelector("#settings"));
2571
+ };
2572
+
2573
+ var hideSettings = function hideSettings() {
2574
+ deactivateToolbarSection(document.querySelector("#settings"));
2575
+ updateIframeOverflowOnParentWindow();
2576
+ };
2577
+
2578
+ var showSettings = function showSettings() {
2579
+ activateToolbarSection(document.querySelector("#settings"));
2580
+ updateIframeOverflowOnParentWindow();
2581
+ };
2582
+
2583
+ var _defineProperty = function (obj, key, value) {
2584
+ // Shortcircuit the slow defineProperty path when possible.
2585
+ // We are trying to avoid issues where setters defined on the
2586
+ // prototype cause side effects under the fast path of simple
2587
+ // assignment. By checking for existence of the property with
2588
+ // the in operator, we can optimize most of this overhead away.
2589
+ if (key in obj) {
2590
+ Object.defineProperty(obj, key, {
2591
+ value: value,
2592
+ enumerable: true,
2593
+ configurable: true,
2594
+ writable: true
2595
+ });
2596
+ } else {
2597
+ obj[key] = value;
2598
+ }
2599
+
2600
+ return obj;
2601
+ };
2602
+
2603
+ function ownKeys(object, enumerableOnly) {
2604
+ var keys = Object.keys(object);
2605
+
2606
+ if (Object.getOwnPropertySymbols) {
2607
+ var symbols = Object.getOwnPropertySymbols(object);
2608
+
2609
+ if (enumerableOnly) {
2610
+ symbols = symbols.filter(function (sym) {
2611
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
2612
+ });
2613
+ }
2614
+
2615
+ keys.push.apply(keys, symbols);
2616
+ }
2617
+
2618
+ return keys;
2619
+ }
2620
+
2621
+ function _objectSpread2(target) {
2622
+ for (var i = 1; i < arguments.length; i++) {
2623
+ var source = arguments[i] != null ? arguments[i] : {};
2624
+
2625
+ if (i % 2) {
2626
+ ownKeys(Object(source), true).forEach(function (key) {
2627
+ _defineProperty(target, key, source[key]);
2628
+ });
2629
+ } else if (Object.getOwnPropertyDescriptors) {
2630
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
2631
+ } else {
2632
+ ownKeys(Object(source)).forEach(function (key) {
2633
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2634
+ });
2635
+ }
2636
+ }
2637
+
2638
+ return target;
2639
+ }
2640
+
2641
+ var _excluded$1 = ["clickToFocus", "clickToClose"];
3218
2642
 
3219
- function _async$2(f) {
2643
+ function _async$9(f) {
3220
2644
  return function () {
3221
2645
  for (var args = [], i = 0; i < arguments.length; i++) {
3222
2646
  args[i] = arguments[i];
@@ -3230,7 +2654,7 @@ html[data-toolbar-visible] #toolbar-trigger {
3230
2654
  };
3231
2655
  }
3232
2656
 
3233
- function _await$1(value, then, direct) {
2657
+ function _await$a(value, then, direct) {
3234
2658
  if (direct) {
3235
2659
  return then ? then(value) : value;
3236
2660
  }
@@ -3346,526 +2770,901 @@ html[data-toolbar-visible] #toolbar-trigger {
3346
2770
  };
3347
2771
 
3348
2772
  var permission = "default";
3349
- var notify = notificationAvailable ? _async$2(function (title) {
2773
+ var notify = notificationAvailable ? _async$9(function (title) {
3350
2774
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3351
2775
 
3352
2776
  var _ref$clickToFocus = _ref.clickToFocus,
3353
2777
  clickToFocus = _ref$clickToFocus === void 0 ? false : _ref$clickToFocus,
3354
2778
  _ref$clickToClose = _ref.clickToClose,
3355
2779
  clickToClose = _ref$clickToClose === void 0 ? false : _ref$clickToClose,
3356
- options = _objectWithoutProperties(_ref, _excluded);
2780
+ options = _objectWithoutProperties(_ref, _excluded$1);
2781
+
2782
+ if (permission !== "granted") {
2783
+ return null;
2784
+ }
2785
+
2786
+ var notification = new Notification(title, options);
2787
+ arrayOfOpenedNotifications.push(notification);
2788
+
2789
+ notification.onclick = function () {
2790
+ // but if the user navigated inbetween
2791
+ // focusing window will show something else
2792
+ // in that case it could be great to do something
2793
+ // maybe like showing a message saying this execution
2794
+ // is no longer visible
2795
+ // we could also navigauate to this file execution but
2796
+ // there is no guarantee re-executing the file would give same output
2797
+ // and it would also trigger an other notification
2798
+ if (clickToFocus) window.focus();
2799
+ if (clickToClose) notification.close();
2800
+ };
2801
+
2802
+ notification.onclose = function () {
2803
+ var index = arrayOfOpenedNotifications.indexOf(notification);
2804
+
2805
+ if (index > -1) {
2806
+ arrayOfOpenedNotifications.splice(index, 1);
2807
+ }
2808
+ };
2809
+
2810
+ return notification;
2811
+ }) : function () {};
2812
+ var requestPromise;
2813
+ var requestPermission = notificationAvailable ? _async$9(function () {
2814
+ if (requestPromise) return requestPromise;
2815
+ requestPromise = Notification.requestPermission();
2816
+ return _await$a(requestPromise, function (_requestPromise) {
2817
+ permission = _requestPromise;
2818
+ requestPromise = undefined;
2819
+ return permission;
2820
+ });
2821
+ }) : function () {
2822
+ return Promise.resolve("default");
2823
+ };
2824
+ var DARK_THEME = "dark";
2825
+ var LIGHT_THEME = "light";
2826
+ var themePreference = createPreference("theme");
2827
+
2828
+ var renderToolbarTheme = function renderToolbarTheme() {
2829
+ var theme = getThemePreference();
2830
+ var checkbox = document.querySelector("#checkbox-dark-theme");
2831
+ checkbox.checked = theme === DARK_THEME;
2832
+ setTheme(theme);
2833
+
2834
+ checkbox.onchange = function () {
2835
+ if (checkbox.checked) {
2836
+ setThemePreference(DARK_THEME);
2837
+ setTheme(DARK_THEME);
2838
+ } else {
2839
+ setThemePreference(LIGHT_THEME);
2840
+ setTheme(LIGHT_THEME);
2841
+ }
2842
+ };
2843
+ };
2844
+
2845
+ var getThemePreference = function getThemePreference() {
2846
+ return themePreference.has() ? themePreference.get() : DARK_THEME;
2847
+ };
2848
+
2849
+ var setThemePreference = function setThemePreference(value) {
2850
+ themePreference.set(value);
2851
+ setTheme(value);
2852
+ };
2853
+
2854
+ var setTheme = function setTheme(theme) {
2855
+ document.querySelector("html").setAttribute("data-theme", theme);
2856
+ };
2857
+
2858
+ var animationPreference = createPreference("animation");
2859
+
2860
+ var renderToolbarAnimation = function renderToolbarAnimation() {
2861
+ var animCheckbox = document.querySelector("#toggle-anims");
2862
+ animCheckbox.checked = getAnimationPreference();
2863
+
2864
+ animCheckbox.onchange = function () {
2865
+ setAnimationPreference(animCheckbox.checked);
2866
+ onPreferenceChange(animCheckbox.checked);
2867
+ };
2868
+
2869
+ onPreferenceChange(); // enable toolbar transition only after first render
2870
+
2871
+ setTimeout(function () {
2872
+ document.querySelector("#toolbar").setAttribute("data-animate", "");
2873
+ });
2874
+ };
2875
+
2876
+ var onPreferenceChange = function onPreferenceChange() {
2877
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getAnimationPreference();
2878
+
2879
+ if (value) {
2880
+ enableAnimation();
2881
+ } else {
2882
+ disableAnimation();
2883
+ }
2884
+ };
2885
+
2886
+ var getAnimationPreference = function getAnimationPreference() {
2887
+ return animationPreference.has() ? animationPreference.get() : true;
2888
+ };
2889
+
2890
+ var setAnimationPreference = function setAnimationPreference(value) {
2891
+ return animationPreference.set(value);
2892
+ };
2893
+
2894
+ var enableAnimation = function enableAnimation() {
2895
+ document.documentElement.removeAttribute("data-animation-disabled");
2896
+ };
2897
+
2898
+ var disableAnimation = function disableAnimation() {
2899
+ document.documentElement.setAttribute("data-animation-disabled", "");
2900
+ };
2901
+
2902
+ var createHorizontalBreakpoint = function createHorizontalBreakpoint(breakpointValue) {
2903
+ return createBreakpoint(windowWidthMeasure, breakpointValue);
2904
+ };
2905
+
2906
+ var createMeasure = function createMeasure(_ref) {
2907
+ var compute = _ref.compute,
2908
+ register = _ref.register;
2909
+ var currentValue = compute();
2910
+
2911
+ var get = function get() {
2912
+ return compute();
2913
+ };
2914
+
2915
+ var changed = createSignal();
2916
+
2917
+ var unregister = function unregister() {};
2918
+
2919
+ if (register) {
2920
+ unregister = register(function () {
2921
+ var value = compute();
2922
+
2923
+ if (value !== currentValue) {
2924
+ var previousValue = value;
2925
+ currentValue = value;
2926
+ changed.notify(value, previousValue);
2927
+ }
2928
+ });
2929
+ }
2930
+
2931
+ return {
2932
+ get: get,
2933
+ changed: changed,
2934
+ unregister: unregister
2935
+ };
2936
+ };
2937
+
2938
+ var createSignal = function createSignal() {
2939
+ var callbackArray = [];
2940
+
2941
+ var listen = function listen(callback) {
2942
+ callbackArray.push(callback);
2943
+ return function () {
2944
+ var index = callbackArray.indexOf(callback);
2945
+
2946
+ if (index > -1) {
2947
+ callbackArray.splice(index, 1);
2948
+ }
2949
+ };
2950
+ };
2951
+
2952
+ var notify = function notify() {
2953
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2954
+ args[_key] = arguments[_key];
2955
+ }
2956
+
2957
+ callbackArray.slice().forEach(function (callback) {
2958
+ callback.apply(void 0, args);
2959
+ });
2960
+ };
2961
+
2962
+ return {
2963
+ listen: listen,
2964
+ notify: notify
2965
+ };
2966
+ };
2967
+
2968
+ var windowWidthMeasure = createMeasure({
2969
+ name: "window-width",
2970
+ compute: function compute() {
2971
+ return window.innerWidth;
2972
+ },
2973
+ register: function register(onchange) {
2974
+ window.addEventListener("resize", onchange);
2975
+ window.addEventListener("orientationchange", onchange);
2976
+ return function () {
2977
+ window.removeEventListener("resize", onchange);
2978
+ window.removeEventListener("orientationchange", onchange);
2979
+ };
2980
+ }
2981
+ });
2982
+
2983
+ var createBreakpoint = function createBreakpoint(measure, breakpointValue) {
2984
+ var getBreakpointState = function getBreakpointState() {
2985
+ var value = measure.get();
2986
+
2987
+ if (value < breakpointValue) {
2988
+ return "below";
2989
+ }
2990
+
2991
+ if (value > breakpointValue) {
2992
+ return "above";
2993
+ }
2994
+
2995
+ return "equals";
2996
+ };
2997
+
2998
+ var currentBreakpointState = getBreakpointState();
2999
+
3000
+ var isAbove = function isAbove() {
3001
+ return measure.get() > breakpointValue;
3002
+ };
3003
+
3004
+ var isBelow = function isBelow() {
3005
+ return measure.get() < breakpointValue;
3006
+ };
3007
+
3008
+ var breakpointChanged = createSignal();
3009
+ measure.changed.listen(function () {
3010
+ var breakpointState = getBreakpointState();
3011
+
3012
+ if (breakpointState !== currentBreakpointState) {
3013
+ var breakpointStatePrevious = currentBreakpointState;
3014
+ currentBreakpointState = breakpointState;
3015
+ breakpointChanged.notify(breakpointState, breakpointStatePrevious);
3016
+ }
3017
+ });
3018
+ return {
3019
+ isAbove: isAbove,
3020
+ isBelow: isBelow,
3021
+ changed: breakpointChanged
3022
+ };
3023
+ }; // const windowScrollTop = createMeasure({
3024
+ // name: "window-scroll-top",
3025
+ // compute: () => window.scrollTop,
3026
+ // register: (onchange) => {
3027
+ // window.addEventListener("scroll", onchange)
3028
+ // return () => {
3029
+ // window.removeEventListener("scroll", onchange)
3030
+ // }
3031
+ // },
3032
+ // })
3357
3033
 
3358
- if (permission !== "granted") {
3359
- return null;
3360
- }
3361
3034
 
3362
- var notification = new Notification(title, options);
3363
- arrayOfOpenedNotifications.push(notification);
3035
+ var WINDOW_MEDIUM_WIDTH = 570;
3364
3036
 
3365
- notification.onclick = function () {
3366
- // but if the user navigated inbetween
3367
- // focusing window will show something else
3368
- // in that case it could be great to do something
3369
- // maybe like showing a message saying this execution
3370
- // is no longer visible
3371
- // we could also navigauate to this file execution but
3372
- // there is no guarantee re-executing the file would give same output
3373
- // and it would also trigger an other notification
3374
- if (clickToFocus) window.focus();
3375
- if (clickToClose) notification.close();
3376
- };
3037
+ var renderExecutionInToolbar = function renderExecutionInToolbar(_ref) {
3038
+ var executedFileRelativeUrl = _ref.executedFileRelativeUrl; // reset file execution indicator ui
3377
3039
 
3378
- notification.onclose = function () {
3379
- var index = arrayOfOpenedNotifications.indexOf(notification);
3040
+ applyExecutionIndicator();
3041
+ removeForceHideElement(document.querySelector("#execution-indicator")); // apply responsive design on fileInput if needed + add listener on resize screen
3380
3042
 
3381
- if (index > -1) {
3382
- arrayOfOpenedNotifications.splice(index, 1);
3383
- }
3043
+ var input = document.querySelector("#file-input");
3044
+ var fileWidthBreakpoint = createHorizontalBreakpoint(WINDOW_MEDIUM_WIDTH);
3045
+
3046
+ var handleFileWidthBreakpoint = function handleFileWidthBreakpoint() {
3047
+ resizeInput(input, fileWidthBreakpoint);
3384
3048
  };
3385
3049
 
3386
- return notification;
3387
- }) : function () {};
3388
- var requestPromise;
3389
- var requestPermission = notificationAvailable ? _async$2(function () {
3390
- if (requestPromise) return requestPromise;
3391
- requestPromise = Notification.requestPermission();
3392
- return _await$1(requestPromise, function (_requestPromise) {
3393
- permission = _requestPromise;
3394
- requestPromise = undefined;
3395
- return permission;
3050
+ handleFileWidthBreakpoint();
3051
+ fileWidthBreakpoint.changed.listen(handleFileWidthBreakpoint);
3052
+ input.value = executedFileRelativeUrl;
3053
+ resizeInput(input, fileWidthBreakpoint);
3054
+ activateToolbarSection(document.querySelector("#file"));
3055
+ removeForceHideElement(document.querySelector("#file"));
3056
+
3057
+ window.parent.__jsenv__.executionResultPromise.then(function (_ref2) {
3058
+ var status = _ref2.status,
3059
+ startTime = _ref2.startTime,
3060
+ endTime = _ref2.endTime;
3061
+ var execution = {
3062
+ status: status,
3063
+ startTime: startTime,
3064
+ endTime: endTime
3065
+ };
3066
+ applyExecutionIndicator(execution);
3067
+ var executionStorageKey = executedFileRelativeUrl;
3068
+ var previousExecution = sessionStorage.hasOwnProperty(executionStorageKey) ? JSON.parse(sessionStorage.getItem(executionStorageKey)) : undefined;
3069
+ notifyExecutionResult(executedFileRelativeUrl, execution, previousExecution);
3070
+ sessionStorage.setItem(executedFileRelativeUrl, JSON.stringify(execution));
3396
3071
  });
3397
- }) : function () {
3398
- return Promise.resolve("default");
3399
3072
  };
3400
- var DARK_THEME = "dark";
3401
- var LIGHT_THEME = "light";
3402
- var themePreference = createPreference("theme");
3403
3073
 
3404
- var renderToolbarTheme = function renderToolbarTheme() {
3405
- var theme = getThemePreference();
3406
- var checkbox = document.querySelector("#checkbox-dark-theme");
3407
- checkbox.checked = theme === DARK_THEME;
3408
- setTheme(theme);
3074
+ var applyExecutionIndicator = function applyExecutionIndicator() {
3075
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
3076
+ _ref3$status = _ref3.status,
3077
+ status = _ref3$status === void 0 ? "running" : _ref3$status,
3078
+ startTime = _ref3.startTime,
3079
+ endTime = _ref3.endTime;
3409
3080
 
3410
- checkbox.onchange = function () {
3411
- if (checkbox.checked) {
3412
- setThemePreference(DARK_THEME);
3413
- setTheme(DARK_THEME);
3414
- } else {
3415
- setThemePreference(LIGHT_THEME);
3416
- setTheme(LIGHT_THEME);
3417
- }
3081
+ var executionIndicator = document.querySelector("#execution-indicator");
3082
+ enableVariant(executionIndicator, {
3083
+ execution: status
3084
+ });
3085
+ var variantNode = executionIndicator.querySelector("[data-when-active]");
3086
+
3087
+ variantNode.querySelector("button").onclick = function () {
3088
+ return toggleTooltip(executionIndicator);
3418
3089
  };
3419
- };
3420
3090
 
3421
- var getThemePreference = function getThemePreference() {
3422
- return themePreference.has() ? themePreference.get() : DARK_THEME;
3091
+ variantNode.querySelector(".tooltip").textContent = computeText({
3092
+ status: status,
3093
+ startTime: startTime,
3094
+ endTime: endTime
3095
+ });
3423
3096
  };
3424
3097
 
3425
- var setThemePreference = function setThemePreference(value) {
3426
- themePreference.set(value);
3427
- setTheme(value);
3098
+ var computeText = function computeText(_ref4) {
3099
+ var status = _ref4.status,
3100
+ startTime = _ref4.startTime,
3101
+ endTime = _ref4.endTime;
3102
+
3103
+ if (status === "completed") {
3104
+ return "Execution completed in ".concat(endTime - startTime, "ms");
3105
+ }
3106
+
3107
+ if (status === "errored") {
3108
+ return "Execution failed in ".concat(endTime - startTime, "ms");
3109
+ }
3110
+
3111
+ if (status === "running") {
3112
+ return "Executing...";
3113
+ }
3114
+
3115
+ return "";
3428
3116
  };
3429
3117
 
3430
- var setTheme = function setTheme(theme) {
3431
- document.querySelector("html").setAttribute("data-theme", theme);
3118
+ var resizeInput = function resizeInput(input, fileWidthBreakpoint) {
3119
+ var size = fileWidthBreakpoint.isBelow() ? 20 : 40;
3120
+
3121
+ if (input.value.length > size) {
3122
+ input.style.width = "".concat(size, "ch");
3123
+ } else {
3124
+ input.style.width = "".concat(input.value.length, "ch");
3125
+ }
3432
3126
  };
3127
+ /* eslint-env browser */
3433
3128
 
3434
- var animationPreference = createPreference("animation");
3435
3129
 
3436
- var renderToolbarAnimation = function renderToolbarAnimation() {
3437
- var animCheckbox = document.querySelector("#toggle-anims");
3438
- animCheckbox.checked = getAnimationPreference();
3130
+ function _await$9(value, then, direct) {
3131
+ if (direct) {
3132
+ return then ? then(value) : value;
3133
+ }
3439
3134
 
3440
- animCheckbox.onchange = function () {
3441
- setAnimationPreference(animCheckbox.checked);
3442
- onPreferenceChange(animCheckbox.checked);
3443
- };
3135
+ if (!value || !value.then) {
3136
+ value = Promise.resolve(value);
3137
+ }
3444
3138
 
3445
- onPreferenceChange(); // enable toolbar transition only after first render
3139
+ return then ? value.then(then) : value;
3140
+ }
3446
3141
 
3447
- setTimeout(function () {
3448
- document.querySelector("#toolbar").setAttribute("data-animate", "");
3449
- });
3450
- };
3142
+ function _async$8(f) {
3143
+ return function () {
3144
+ for (var args = [], i = 0; i < arguments.length; i++) {
3145
+ args[i] = arguments[i];
3146
+ }
3451
3147
 
3452
- var onPreferenceChange = function onPreferenceChange() {
3453
- var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getAnimationPreference();
3148
+ try {
3149
+ return Promise.resolve(f.apply(this, args));
3150
+ } catch (e) {
3151
+ return Promise.reject(e);
3152
+ }
3153
+ };
3154
+ }
3454
3155
 
3455
- if (value) {
3456
- enableAnimation();
3457
- } else {
3458
- disableAnimation();
3156
+ function _call$1(body, then, direct) {
3157
+ if (direct) {
3158
+ return then ? then(body()) : body();
3459
3159
  }
3460
- };
3461
3160
 
3462
- var getAnimationPreference = function getAnimationPreference() {
3463
- return animationPreference.has() ? animationPreference.get() : true;
3464
- };
3161
+ try {
3162
+ var result = Promise.resolve(body());
3163
+ return then ? result.then(then) : result;
3164
+ } catch (e) {
3165
+ return Promise.reject(e);
3166
+ }
3167
+ }
3465
3168
 
3466
- var setAnimationPreference = function setAnimationPreference(value) {
3467
- return animationPreference.set(value);
3468
- };
3169
+ var fetchUsingXHR = _async$8(function (url) {
3170
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
3171
+ signal = _ref.signal,
3172
+ _ref$method = _ref.method,
3173
+ method = _ref$method === void 0 ? "GET" : _ref$method,
3174
+ _ref$credentials = _ref.credentials,
3175
+ credentials = _ref$credentials === void 0 ? "same-origin" : _ref$credentials,
3176
+ _ref$headers = _ref.headers,
3177
+ headers = _ref$headers === void 0 ? {} : _ref$headers,
3178
+ _ref$body = _ref.body,
3179
+ body = _ref$body === void 0 ? null : _ref$body;
3469
3180
 
3470
- var enableAnimation = function enableAnimation() {
3471
- document.documentElement.removeAttribute("data-animation-disabled");
3472
- };
3181
+ var headersPromise = createPromiseAndHooks();
3182
+ var bodyPromise = createPromiseAndHooks();
3183
+ var xhr = new XMLHttpRequest();
3473
3184
 
3474
- var disableAnimation = function disableAnimation() {
3475
- document.documentElement.setAttribute("data-animation-disabled", "");
3476
- };
3185
+ var failure = function failure(error) {
3186
+ // if it was already resolved, we must reject the body promise
3187
+ if (headersPromise.settled) {
3188
+ bodyPromise.reject(error);
3189
+ } else {
3190
+ headersPromise.reject(error);
3191
+ }
3192
+ };
3477
3193
 
3478
- var createHorizontalBreakpoint = function createHorizontalBreakpoint(breakpointValue) {
3479
- return createBreakpoint(windowWidthMeasure, breakpointValue);
3480
- };
3194
+ var cleanup = function cleanup() {
3195
+ xhr.ontimeout = null;
3196
+ xhr.onerror = null;
3197
+ xhr.onload = null;
3198
+ xhr.onreadystatechange = null;
3199
+ };
3481
3200
 
3482
- var createMeasure = function createMeasure(_ref) {
3483
- var compute = _ref.compute,
3484
- register = _ref.register;
3485
- var currentValue = compute();
3201
+ xhr.ontimeout = function () {
3202
+ cleanup();
3203
+ failure(new Error("xhr request timeout on ".concat(url, ".")));
3204
+ };
3486
3205
 
3487
- var get = function get() {
3488
- return compute();
3206
+ xhr.onerror = function (error) {
3207
+ cleanup(); // unfortunately with have no clue why it fails
3208
+ // might be cors for instance
3209
+
3210
+ failure(createRequestError(error, {
3211
+ url: url
3212
+ }));
3213
+ };
3214
+
3215
+ xhr.onload = function () {
3216
+ cleanup();
3217
+ bodyPromise.resolve();
3489
3218
  };
3490
3219
 
3491
- var changed = createSignal();
3220
+ signal.addEventListener("abort", function () {
3221
+ xhr.abort();
3222
+ var abortError = new Error("aborted");
3223
+ abortError.name = "AbortError";
3224
+ failure(abortError);
3225
+ });
3226
+
3227
+ xhr.onreadystatechange = function () {
3228
+ // https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/readyState
3229
+ var readyState = xhr.readyState;
3492
3230
 
3493
- var unregister = function unregister() {};
3231
+ if (readyState === 2) {
3232
+ headersPromise.resolve();
3233
+ } else if (readyState === 4) {
3234
+ cleanup();
3235
+ bodyPromise.resolve();
3236
+ }
3237
+ };
3494
3238
 
3495
- if (register) {
3496
- unregister = register(function () {
3497
- var value = compute();
3239
+ xhr.open(method, url, true);
3240
+ Object.keys(headers).forEach(function (key) {
3241
+ xhr.setRequestHeader(key, headers[key]);
3242
+ });
3243
+ xhr.withCredentials = computeWithCredentials({
3244
+ credentials: credentials,
3245
+ url: url
3246
+ });
3498
3247
 
3499
- if (value !== currentValue) {
3500
- var previousValue = value;
3501
- currentValue = value;
3502
- changed.notify(value, previousValue);
3503
- }
3504
- });
3248
+ if ("responseType" in xhr && hasBlob) {
3249
+ xhr.responseType = "blob";
3505
3250
  }
3506
3251
 
3507
- return {
3508
- get: get,
3509
- changed: changed,
3510
- unregister: unregister
3511
- };
3512
- };
3252
+ xhr.send(body);
3253
+ return _await$9(headersPromise, function () {
3254
+ // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL
3255
+ var responseUrl = "responseURL" in xhr ? xhr.responseURL : headers["x-request-url"];
3256
+ var responseStatus = xhr.status;
3257
+ var responseStatusText = xhr.statusText;
3258
+ var responseHeaders = getHeadersFromXHR(xhr);
3513
3259
 
3514
- var createSignal = function createSignal() {
3515
- var callbackArray = [];
3260
+ var readBody = function readBody() {
3261
+ return _await$9(bodyPromise, function () {
3262
+ var status = xhr.status; // in Chrome on file:/// URLs, status is 0
3516
3263
 
3517
- var listen = function listen(callback) {
3518
- callbackArray.push(callback);
3519
- return function () {
3520
- var index = callbackArray.indexOf(callback);
3264
+ if (status === 0) {
3265
+ responseStatus = 200;
3266
+ }
3521
3267
 
3522
- if (index > -1) {
3523
- callbackArray.splice(index, 1);
3524
- }
3268
+ var body = "response" in xhr ? xhr.response : xhr.responseText;
3269
+ return {
3270
+ responseBody: body,
3271
+ responseBodyType: detectBodyType(body)
3272
+ };
3273
+ });
3525
3274
  };
3526
- };
3527
3275
 
3528
- var notify = function notify() {
3529
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3530
- args[_key] = arguments[_key];
3531
- }
3276
+ var text = function text() {
3277
+ return _call$1(readBody, function (_ref2) {
3278
+ var responseBody = _ref2.responseBody,
3279
+ responseBodyType = _ref2.responseBodyType;
3532
3280
 
3533
- callbackArray.slice().forEach(function (callback) {
3534
- callback.apply(void 0, args);
3535
- });
3536
- };
3281
+ if (responseBodyType === "blob") {
3282
+ return blobToText(responseBody);
3283
+ }
3537
3284
 
3538
- return {
3539
- listen: listen,
3540
- notify: notify
3541
- };
3542
- };
3285
+ if (responseBodyType === "formData") {
3286
+ throw new Error("could not read FormData body as text");
3287
+ }
3543
3288
 
3544
- var windowWidthMeasure = createMeasure({
3545
- name: "window-width",
3546
- compute: function compute() {
3547
- return window.innerWidth;
3548
- },
3549
- register: function register(onchange) {
3550
- window.addEventListener("resize", onchange);
3551
- window.addEventListener("orientationchange", onchange);
3552
- return function () {
3553
- window.removeEventListener("resize", onchange);
3554
- window.removeEventListener("orientationchange", onchange);
3289
+ return responseBodyType === "dataView" ? arrayBufferToText(responseBody.buffer) : responseBodyType === "arrayBuffer" ? arrayBufferToText(responseBody) : String(responseBody);
3290
+ });
3555
3291
  };
3556
- }
3557
- });
3558
-
3559
- var createBreakpoint = function createBreakpoint(measure, breakpointValue) {
3560
- var getBreakpointState = function getBreakpointState() {
3561
- var value = measure.get();
3562
3292
 
3563
- if (value < breakpointValue) {
3564
- return "below";
3565
- }
3293
+ var json = function json() {
3294
+ return _call$1(text, JSON.parse);
3295
+ };
3566
3296
 
3567
- if (value > breakpointValue) {
3568
- return "above";
3569
- }
3297
+ var blob = _async$8(function () {
3298
+ if (!hasBlob) {
3299
+ throw new Error("blob not supported");
3300
+ }
3570
3301
 
3571
- return "equals";
3572
- };
3302
+ return _call$1(readBody, function (_ref3) {
3303
+ var responseBody = _ref3.responseBody,
3304
+ responseBodyType = _ref3.responseBodyType;
3573
3305
 
3574
- var currentBreakpointState = getBreakpointState();
3306
+ if (responseBodyType === "blob") {
3307
+ return responseBody;
3308
+ }
3575
3309
 
3576
- var isAbove = function isAbove() {
3577
- return measure.get() > breakpointValue;
3578
- };
3310
+ if (responseBodyType === "dataView") {
3311
+ return new Blob([cloneBuffer(responseBody.buffer)]);
3312
+ }
3579
3313
 
3580
- var isBelow = function isBelow() {
3581
- return measure.get() < breakpointValue;
3582
- };
3314
+ if (responseBodyType === "arrayBuffer") {
3315
+ return new Blob([cloneBuffer(responseBody)]);
3316
+ }
3583
3317
 
3584
- var breakpointChanged = createSignal();
3585
- measure.changed.listen(function () {
3586
- var breakpointState = getBreakpointState();
3318
+ if (responseBodyType === "formData") {
3319
+ throw new Error("could not read FormData body as blob");
3320
+ }
3587
3321
 
3588
- if (breakpointState !== currentBreakpointState) {
3589
- var breakpointStatePrevious = currentBreakpointState;
3590
- currentBreakpointState = breakpointState;
3591
- breakpointChanged.notify(breakpointState, breakpointStatePrevious);
3592
- }
3593
- });
3594
- return {
3595
- isAbove: isAbove,
3596
- isBelow: isBelow,
3597
- changed: breakpointChanged
3598
- };
3599
- }; // const windowScrollTop = createMeasure({
3600
- // name: "window-scroll-top",
3601
- // compute: () => window.scrollTop,
3602
- // register: (onchange) => {
3603
- // window.addEventListener("scroll", onchange)
3604
- // return () => {
3605
- // window.removeEventListener("scroll", onchange)
3606
- // }
3607
- // },
3608
- // })
3322
+ return new Blob([String(responseBody)]);
3323
+ });
3324
+ });
3609
3325
 
3326
+ var arrayBuffer = function arrayBuffer() {
3327
+ return _call$1(readBody, function (_ref4) {
3328
+ var responseBody = _ref4.responseBody,
3329
+ responseBodyType = _ref4.responseBodyType;
3330
+ return responseBodyType === "arrayBuffer" ? cloneBuffer(responseBody) : _call$1(blob, blobToArrayBuffer);
3331
+ });
3332
+ };
3610
3333
 
3611
- var WINDOW_MEDIUM_WIDTH = 570;
3334
+ var formData = _async$8(function () {
3335
+ if (!hasFormData) {
3336
+ throw new Error("formData not supported");
3337
+ }
3612
3338
 
3613
- var renderExecutionInToolbar = function renderExecutionInToolbar(_ref) {
3614
- var executedFileRelativeUrl = _ref.executedFileRelativeUrl; // reset file execution indicator ui
3339
+ return _call$1(text, textToFormData);
3340
+ });
3615
3341
 
3616
- applyExecutionIndicator();
3617
- removeForceHideElement(document.querySelector("#execution-indicator")); // apply responsive design on fileInput if needed + add listener on resize screen
3342
+ return {
3343
+ url: responseUrl,
3344
+ status: responseStatus,
3345
+ statusText: responseStatusText,
3346
+ headers: responseHeaders,
3347
+ text: text,
3348
+ json: json,
3349
+ blob: blob,
3350
+ arrayBuffer: arrayBuffer,
3351
+ formData: formData
3352
+ };
3353
+ });
3354
+ });
3618
3355
 
3619
- var input = document.querySelector("#file-input");
3620
- var fileWidthBreakpoint = createHorizontalBreakpoint(WINDOW_MEDIUM_WIDTH);
3356
+ var canUseBlob = function canUseBlob() {
3357
+ if (typeof window.FileReader !== "function") return false;
3358
+ if (typeof window.Blob !== "function") return false;
3621
3359
 
3622
- var handleFileWidthBreakpoint = function handleFileWidthBreakpoint() {
3623
- resizeInput(input, fileWidthBreakpoint);
3624
- };
3360
+ try {
3361
+ // eslint-disable-next-line no-new
3362
+ new Blob();
3363
+ return true;
3364
+ } catch (e) {
3365
+ return false;
3366
+ }
3367
+ };
3625
3368
 
3626
- handleFileWidthBreakpoint();
3627
- fileWidthBreakpoint.changed.listen(handleFileWidthBreakpoint);
3628
- input.value = executedFileRelativeUrl;
3629
- resizeInput(input, fileWidthBreakpoint);
3630
- activateToolbarSection(document.querySelector("#file"));
3631
- removeForceHideElement(document.querySelector("#file"));
3369
+ var hasBlob = canUseBlob();
3370
+ var hasFormData = typeof window.FormData === "function";
3371
+ var hasArrayBuffer = typeof window.ArrayBuffer === "function";
3372
+ var hasSearchParams = typeof window.URLSearchParams === "function";
3632
3373
 
3633
- window.parent.__jsenv__.executionResultPromise.then(function (_ref2) {
3634
- var status = _ref2.status,
3635
- startTime = _ref2.startTime,
3636
- endTime = _ref2.endTime;
3637
- var execution = {
3638
- status: status,
3639
- startTime: startTime,
3640
- endTime: endTime
3641
- };
3642
- applyExecutionIndicator(execution);
3643
- var executionStorageKey = executedFileRelativeUrl;
3644
- var previousExecution = sessionStorage.hasOwnProperty(executionStorageKey) ? JSON.parse(sessionStorage.getItem(executionStorageKey)) : undefined;
3645
- notifyExecutionResult(executedFileRelativeUrl, execution, previousExecution);
3646
- sessionStorage.setItem(executedFileRelativeUrl, JSON.stringify(execution));
3647
- });
3374
+ var createRequestError = function createRequestError(error, _ref5) {
3375
+ var url = _ref5.url;
3376
+ return new Error("error during xhr request on ".concat(url, ".\n--- error stack ---\n").concat(error.stack));
3648
3377
  };
3649
3378
 
3650
- var applyExecutionIndicator = function applyExecutionIndicator() {
3651
- var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
3652
- _ref3$status = _ref3.status,
3653
- status = _ref3$status === void 0 ? "running" : _ref3$status,
3654
- startTime = _ref3.startTime,
3655
- endTime = _ref3.endTime;
3379
+ var createPromiseAndHooks = function createPromiseAndHooks() {
3380
+ var resolve;
3381
+ var reject;
3382
+ var promise = new Promise(function (res, rej) {
3383
+ resolve = function resolve(value) {
3384
+ promise.settled = true;
3385
+ res(value);
3386
+ };
3656
3387
 
3657
- var executionIndicator = document.querySelector("#execution-indicator");
3658
- enableVariant(executionIndicator, {
3659
- execution: status
3388
+ reject = function reject(value) {
3389
+ promise.settled = true;
3390
+ rej(value);
3391
+ };
3660
3392
  });
3661
- var variantNode = executionIndicator.querySelector("[data-when-active]");
3393
+ promise.resolve = resolve;
3394
+ promise.reject = reject;
3395
+ return promise;
3396
+ }; // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
3662
3397
 
3663
- variantNode.querySelector("button").onclick = function () {
3664
- return toggleTooltip(executionIndicator);
3665
- };
3666
3398
 
3667
- variantNode.querySelector(".tooltip").textContent = computeText({
3668
- status: status,
3669
- startTime: startTime,
3670
- endTime: endTime
3671
- });
3399
+ var computeWithCredentials = function computeWithCredentials(_ref6) {
3400
+ var credentials = _ref6.credentials,
3401
+ url = _ref6.url;
3402
+
3403
+ if (credentials === "same-origin") {
3404
+ return originSameAsGlobalOrigin(url);
3405
+ }
3406
+
3407
+ return credentials === "include";
3672
3408
  };
3673
3409
 
3674
- var computeText = function computeText(_ref4) {
3675
- var status = _ref4.status,
3676
- startTime = _ref4.startTime,
3677
- endTime = _ref4.endTime;
3410
+ var originSameAsGlobalOrigin = function originSameAsGlobalOrigin(url) {
3411
+ // if we cannot read globalOrigin from window.location.origin, let's consider it's ok
3412
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== "object") return true;
3413
+ if (_typeof(window.location) !== "object") return true;
3414
+ var globalOrigin = window.location.origin;
3415
+ if (globalOrigin === "null") return true;
3416
+ return hrefToOrigin(url) === globalOrigin;
3417
+ };
3678
3418
 
3679
- if (status === "completed") {
3680
- return "Execution completed in ".concat(endTime - startTime, "ms");
3419
+ var detectBodyType = function detectBodyType(body) {
3420
+ if (!body) {
3421
+ return "";
3681
3422
  }
3682
3423
 
3683
- if (status === "errored") {
3684
- return "Execution failed in ".concat(endTime - startTime, "ms");
3424
+ if (typeof body === "string") {
3425
+ return "text";
3685
3426
  }
3686
3427
 
3687
- if (status === "running") {
3688
- return "Executing...";
3428
+ if (hasBlob && Blob.prototype.isPrototypeOf(body)) {
3429
+ return "blob";
3689
3430
  }
3690
3431
 
3691
- return "";
3692
- };
3432
+ if (hasFormData && FormData.prototype.isPrototypeOf(body)) {
3433
+ return "formData";
3434
+ }
3693
3435
 
3694
- var resizeInput = function resizeInput(input, fileWidthBreakpoint) {
3695
- var size = fileWidthBreakpoint.isBelow() ? 20 : 40;
3436
+ if (hasArrayBuffer) {
3437
+ if (hasBlob && isDataView(body)) {
3438
+ return "dataView";
3439
+ }
3696
3440
 
3697
- if (input.value.length > size) {
3698
- input.style.width = "".concat(size, "ch");
3699
- } else {
3700
- input.style.width = "".concat(input.value.length, "ch");
3441
+ if (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body)) {
3442
+ return "arrayBuffer";
3443
+ }
3701
3444
  }
3702
- };
3703
3445
 
3704
- var createDetailedMessage = function createDetailedMessage(message) {
3705
- var details = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3706
- var string = "".concat(message);
3707
- Object.keys(details).forEach(function (key) {
3708
- var value = details[key];
3709
- string += "\n--- ".concat(key, " ---\n").concat(Array.isArray(value) ? value.join("\n") : value);
3710
- });
3711
- return string;
3712
- };
3713
-
3714
- var COMPILE_ID_OTHERWISE = "otherwise";
3446
+ if (hasSearchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
3447
+ return "searchParams";
3448
+ }
3715
3449
 
3716
- var computeCompileIdFromGroupId = function computeCompileIdFromGroupId(_ref) {
3717
- var groupId = _ref.groupId,
3718
- groupMap = _ref.groupMap;
3450
+ return "";
3451
+ }; // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
3719
3452
 
3720
- if (typeof groupId === "undefined") {
3721
- if (COMPILE_ID_OTHERWISE in groupMap) {
3722
- return COMPILE_ID_OTHERWISE;
3723
- }
3724
3453
 
3725
- var keys = Object.keys(groupMap);
3454
+ var getHeadersFromXHR = function getHeadersFromXHR(xhr) {
3455
+ var headerMap = {};
3456
+ var headersString = xhr.getAllResponseHeaders();
3457
+ if (headersString === "") return headerMap;
3458
+ var lines = headersString.trim().split(/[\r\n]+/);
3459
+ lines.forEach(function (line) {
3460
+ var parts = line.split(": ");
3461
+ var name = parts.shift();
3462
+ var value = parts.join(": ");
3463
+ headerMap[name.toLowerCase()] = value;
3464
+ });
3465
+ return headerMap;
3466
+ };
3726
3467
 
3727
- if (keys.length === 1) {
3728
- return keys[0];
3729
- }
3468
+ var hrefToOrigin = function hrefToOrigin(href) {
3469
+ var scheme = hrefToScheme(href);
3730
3470
 
3731
- throw new Error(createUnexpectedGroupIdMessage({
3732
- groupMap: groupMap
3733
- }));
3471
+ if (scheme === "file") {
3472
+ return "file://";
3734
3473
  }
3735
3474
 
3736
- if (groupId in groupMap === false) {
3737
- throw new Error(createUnexpectedGroupIdMessage({
3738
- groupId: groupId,
3739
- groupMap: groupMap
3740
- }));
3475
+ if (scheme === "http" || scheme === "https") {
3476
+ var secondProtocolSlashIndex = scheme.length + "://".length;
3477
+ var pathnameSlashIndex = href.indexOf("/", secondProtocolSlashIndex);
3478
+ if (pathnameSlashIndex === -1) return href;
3479
+ return href.slice(0, pathnameSlashIndex);
3741
3480
  }
3742
3481
 
3743
- return groupId;
3482
+ return href.slice(0, scheme.length + 1);
3744
3483
  };
3745
3484
 
3746
- var createUnexpectedGroupIdMessage = function createUnexpectedGroupIdMessage(_ref2) {
3747
- var _createDetailedMessag;
3485
+ var hrefToScheme = function hrefToScheme(href) {
3486
+ var colonIndex = href.indexOf(":");
3487
+ if (colonIndex === -1) return "";
3488
+ return href.slice(0, colonIndex);
3489
+ };
3748
3490
 
3749
- var compileId = _ref2.compileId,
3750
- groupMap = _ref2.groupMap;
3751
- return createDetailedMessage("unexpected groupId.", (_createDetailedMessag = {}, _defineProperty(_createDetailedMessag, "expected compiled id", Object.keys(groupMap)), _defineProperty(_createDetailedMessag, "received compile id", compileId), _createDetailedMessag));
3491
+ var isDataView = function isDataView(obj) {
3492
+ return obj && DataView.prototype.isPrototypeOf(obj);
3752
3493
  };
3753
3494
 
3754
- var valueToVersion = function valueToVersion(value) {
3755
- if (typeof value === "number") {
3756
- return numberToVersion(value);
3757
- }
3495
+ var isArrayBufferView = ArrayBuffer.isView || function () {
3496
+ var viewClasses = ["[object Int8Array]", "[object Uint8Array]", "[object Uint8ClampedArray]", "[object Int16Array]", "[object Uint16Array]", "[object Int32Array]", "[object Uint32Array]", "[object Float32Array]", "[object Float64Array]"];
3497
+ return function (value) {
3498
+ return value && viewClasses.includes(Object.prototype.toString.call(value));
3499
+ };
3500
+ }();
3758
3501
 
3759
- if (typeof value === "string") {
3760
- return stringToVersion(value);
3761
- }
3502
+ var textToFormData = function textToFormData(text) {
3503
+ var form = new FormData();
3504
+ text.trim().split("&").forEach(function (bytes) {
3505
+ if (bytes) {
3506
+ var split = bytes.split("=");
3507
+ var name = split.shift().replace(/\+/g, " ");
3508
+ var value = split.join("=").replace(/\+/g, " ");
3509
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
3510
+ }
3511
+ });
3512
+ return form;
3513
+ };
3514
+
3515
+ var blobToArrayBuffer = _async$8(function (blob) {
3516
+ var reader = new FileReader();
3517
+ var promise = fileReaderReady(reader);
3518
+ reader.readAsArrayBuffer(blob);
3519
+ return promise;
3520
+ });
3762
3521
 
3763
- throw new TypeError("version must be a number or a string, got ".concat(value));
3522
+ var blobToText = function blobToText(blob) {
3523
+ var reader = new FileReader();
3524
+ var promise = fileReaderReady(reader);
3525
+ reader.readAsText(blob);
3526
+ return promise;
3764
3527
  };
3765
3528
 
3766
- var numberToVersion = function numberToVersion(number) {
3767
- return {
3768
- major: number,
3769
- minor: 0,
3770
- patch: 0
3771
- };
3529
+ var arrayBufferToText = function arrayBufferToText(arrayBuffer) {
3530
+ var view = new Uint8Array(arrayBuffer);
3531
+ var chars = new Array(view.length);
3532
+ var i = 0;
3533
+
3534
+ while (i < view.length) {
3535
+ chars[i] = String.fromCharCode(view[i]);
3536
+ i++;
3537
+ }
3538
+
3539
+ return chars.join("");
3772
3540
  };
3773
3541
 
3774
- var stringToVersion = function stringToVersion(string) {
3775
- if (string.indexOf(".") > -1) {
3776
- var parts = string.split(".");
3777
- return {
3778
- major: Number(parts[0]),
3779
- minor: parts[1] ? Number(parts[1]) : 0,
3780
- patch: parts[2] ? Number(parts[2]) : 0
3542
+ var fileReaderReady = function fileReaderReady(reader) {
3543
+ return new Promise(function (resolve, reject) {
3544
+ reader.onload = function () {
3545
+ resolve(reader.result);
3781
3546
  };
3782
- }
3783
3547
 
3784
- if (isNaN(string)) {
3785
- return {
3786
- major: 0,
3787
- minor: 0,
3788
- patch: 0
3548
+ reader.onerror = function () {
3549
+ reject(reader.error);
3789
3550
  };
3551
+ });
3552
+ };
3553
+
3554
+ var cloneBuffer = function cloneBuffer(buffer) {
3555
+ if (buffer.slice) {
3556
+ return buffer.slice(0);
3790
3557
  }
3791
3558
 
3792
- return {
3793
- major: Number(string),
3794
- minor: 0,
3795
- patch: 0
3796
- };
3559
+ var view = new Uint8Array(buffer.byteLength);
3560
+ view.set(new Uint8Array(buffer));
3561
+ return view.buffer;
3797
3562
  };
3798
3563
 
3799
- var versionCompare = function versionCompare(versionA, versionB) {
3800
- var semanticVersionA = valueToVersion(versionA);
3801
- var semanticVersionB = valueToVersion(versionB);
3802
- var majorDiff = semanticVersionA.major - semanticVersionB.major;
3564
+ var _excluded = ["mode"];
3803
3565
 
3804
- if (majorDiff > 0) {
3805
- return majorDiff;
3566
+ function _await$8(value, then, direct) {
3567
+ if (direct) {
3568
+ return then ? then(value) : value;
3806
3569
  }
3807
3570
 
3808
- if (majorDiff < 0) {
3809
- return majorDiff;
3571
+ if (!value || !value.then) {
3572
+ value = Promise.resolve(value);
3810
3573
  }
3811
3574
 
3812
- var minorDiff = semanticVersionA.minor - semanticVersionB.minor;
3575
+ return then ? value.then(then) : value;
3576
+ }
3813
3577
 
3814
- if (minorDiff > 0) {
3815
- return minorDiff;
3816
- }
3578
+ function _async$7(f) {
3579
+ return function () {
3580
+ for (var args = [], i = 0; i < arguments.length; i++) {
3581
+ args[i] = arguments[i];
3582
+ }
3817
3583
 
3818
- if (minorDiff < 0) {
3819
- return minorDiff;
3820
- }
3584
+ try {
3585
+ return Promise.resolve(f.apply(this, args));
3586
+ } catch (e) {
3587
+ return Promise.reject(e);
3588
+ }
3589
+ };
3590
+ }
3821
3591
 
3822
- var patchDiff = semanticVersionA.patch - semanticVersionB.patch;
3592
+ var fetchNative = _async$7(function (url) {
3593
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3823
3594
 
3824
- if (patchDiff > 0) {
3825
- return patchDiff;
3826
- }
3595
+ var _ref$mode = _ref.mode,
3596
+ mode = _ref$mode === void 0 ? "cors" : _ref$mode,
3597
+ options = _objectWithoutProperties(_ref, _excluded);
3827
3598
 
3828
- if (patchDiff < 0) {
3829
- return patchDiff;
3830
- }
3599
+ return _await$8(window.fetch(url, _objectSpread2({
3600
+ mode: mode
3601
+ }, options)), function (response) {
3602
+ return {
3603
+ url: response.url,
3604
+ status: response.status,
3605
+ statusText: "",
3606
+ headers: responseToHeaders(response),
3607
+ text: function text() {
3608
+ return response.text();
3609
+ },
3610
+ json: function json() {
3611
+ return response.json();
3612
+ },
3613
+ blob: function blob() {
3614
+ return response.blob();
3615
+ },
3616
+ arrayBuffer: function arrayBuffer() {
3617
+ return response.arrayBuffer();
3618
+ },
3619
+ formData: function formData() {
3620
+ return response.formData();
3621
+ }
3622
+ };
3623
+ });
3624
+ });
3831
3625
 
3832
- return 0;
3626
+ var responseToHeaders = function responseToHeaders(response) {
3627
+ var headers = {};
3628
+ response.headers.forEach(function (value, name) {
3629
+ headers[name] = value;
3630
+ });
3631
+ return headers;
3833
3632
  };
3834
3633
 
3835
- var versionIsBelow = function versionIsBelow(versionSupposedBelow, versionSupposedAbove) {
3836
- return versionCompare(versionSupposedBelow, versionSupposedAbove) < 0;
3837
- };
3634
+ var fetchUrl = typeof window.fetch === "function" && typeof window.AbortController === "function" ? fetchNative : fetchUsingXHR;
3838
3635
 
3839
- var findHighestVersion = function findHighestVersion() {
3840
- for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
3841
- values[_key] = arguments[_key];
3636
+ function _await$7(value, then, direct) {
3637
+ if (direct) {
3638
+ return then ? then(value) : value;
3842
3639
  }
3843
3640
 
3844
- if (values.length === 0) throw new Error("missing argument");
3845
- return values.reduce(function (highestVersion, value) {
3846
- if (versionIsBelow(highestVersion, value)) {
3847
- return value;
3848
- }
3641
+ if (!value || !value.then) {
3642
+ value = Promise.resolve(value);
3643
+ }
3849
3644
 
3850
- return highestVersion;
3851
- });
3852
- };
3645
+ return then ? value.then(then) : value;
3646
+ }
3853
3647
 
3854
- var resolveGroup = function resolveGroup(_ref, groupMap) {
3855
- var name = _ref.name,
3856
- version = _ref.version;
3857
- return Object.keys(groupMap).find(function (compileIdCandidate) {
3858
- var minRuntimeVersions = groupMap[compileIdCandidate].minRuntimeVersions;
3859
- var versionForGroup = minRuntimeVersions[name];
3648
+ function _async$6(f) {
3649
+ return function () {
3650
+ for (var args = [], i = 0; i < arguments.length; i++) {
3651
+ args[i] = arguments[i];
3652
+ }
3860
3653
 
3861
- if (!versionForGroup) {
3862
- return false;
3654
+ try {
3655
+ return Promise.resolve(f.apply(this, args));
3656
+ } catch (e) {
3657
+ return Promise.reject(e);
3863
3658
  }
3659
+ };
3660
+ }
3864
3661
 
3865
- var highestVersion = findHighestVersion(version, versionForGroup);
3866
- return highestVersion === version;
3662
+ var fetchJson = _async$6(function (url) {
3663
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3664
+ return _await$7(fetchUrl(url, options), function (response) {
3665
+ return _await$7(response.json());
3867
3666
  });
3868
- };
3667
+ });
3869
3668
  /*
3870
3669
  * Prefer window.navigator.userAgentData before resorting to
3871
3670
  * window.navigator.userAgent because of
@@ -4104,28 +3903,338 @@ html[data-toolbar-visible] #toolbar-trigger {
4104
3903
  };
4105
3904
  };
4106
3905
 
4107
- var normalizeName = function normalizeName(name) {
4108
- return name.toLowerCase();
4109
- };
3906
+ var normalizeName = function normalizeName(name) {
3907
+ return name.toLowerCase();
3908
+ };
3909
+
3910
+ var normalizeVersion = function normalizeVersion(version) {
3911
+ if (version.indexOf(".") > -1) {
3912
+ var parts = version.split("."); // remove extraneous .
3913
+
3914
+ return parts.slice(0, 3).join(".");
3915
+ }
3916
+
3917
+ if (version.indexOf("_") > -1) {
3918
+ var _parts = version.split("_"); // remove extraneous _
3919
+
3920
+
3921
+ return _parts.slice(0, 3).join("_");
3922
+ }
3923
+
3924
+ return version;
3925
+ };
3926
+
3927
+ var executeWithScriptModuleInjection = function executeWithScriptModuleInjection(code) {
3928
+ var scriptModule = document.createElement("script");
3929
+ scriptModule.type = "module";
3930
+ var loadPromise = new Promise(function (resolve, reject) {
3931
+ scriptModule.onload = function () {
3932
+ document.body.removeChild(scriptModule);
3933
+ resolve();
3934
+ };
3935
+
3936
+ scriptModule.onerror = function () {
3937
+ document.body.removeChild(scriptModule);
3938
+ reject();
3939
+ };
3940
+
3941
+ document.body.appendChild(scriptModule);
3942
+ });
3943
+ scriptModule.src = asBase64Url(code);
3944
+ return loadPromise;
3945
+ };
3946
+
3947
+ var asBase64Url = function asBase64Url(text) {
3948
+ var mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "application/javascript";
3949
+ return "data:".concat(mimeType, ";base64,").concat(window.btoa(text));
3950
+ };
3951
+
3952
+ function _await$6(value, then, direct) {
3953
+ if (direct) {
3954
+ return then ? then(value) : value;
3955
+ }
3956
+
3957
+ if (!value || !value.then) {
3958
+ value = Promise.resolve(value);
3959
+ }
3960
+
3961
+ return then ? value.then(then) : value;
3962
+ }
3963
+
3964
+ function _catch$4(body, recover) {
3965
+ try {
3966
+ var result = body();
3967
+ } catch (e) {
3968
+ return recover(e);
3969
+ }
3970
+
3971
+ if (result && result.then) {
3972
+ return result.then(void 0, recover);
3973
+ }
3974
+
3975
+ return result;
3976
+ }
3977
+
3978
+ function _async$5(f) {
3979
+ return function () {
3980
+ for (var args = [], i = 0; i < arguments.length; i++) {
3981
+ args[i] = arguments[i];
3982
+ }
3983
+
3984
+ try {
3985
+ return Promise.resolve(f.apply(this, args));
3986
+ } catch (e) {
3987
+ return Promise.reject(e);
3988
+ }
3989
+ };
3990
+ }
3991
+
3992
+ var supportsImportmap = _async$5(function () {
3993
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
3994
+ _ref$remote = _ref.remote,
3995
+ remote = _ref$remote === void 0 ? true : _ref$remote;
3996
+
3997
+ var specifier = asBase64Url("export default false");
3998
+ var importMap = {
3999
+ imports: _defineProperty({}, specifier, asBase64Url("export default true"))
4000
+ };
4001
+ var importmapScript = document.createElement("script");
4002
+ var importmapString = JSON.stringify(importMap, null, " ");
4003
+ importmapScript.type = "importmap";
4004
+
4005
+ if (remote) {
4006
+ importmapScript.src = "data:application/json;base64,".concat(window.btoa(importmapString));
4007
+ } else {
4008
+ importmapScript.textContent = importmapString;
4009
+ }
4010
+
4011
+ document.body.appendChild(importmapScript);
4012
+ return _catch$4(function () {
4013
+ return _await$6(executeWithScriptModuleInjection("import supported from \"".concat(specifier, "\"; window.__jsenv_runtime_test_importmap__ = supported")), function () {
4014
+ document.body.removeChild(importmapScript);
4015
+ var supported = window.__jsenv_runtime_test_importmap__;
4016
+ delete window.__jsenv_runtime_test_importmap__;
4017
+ return supported;
4018
+ });
4019
+ }, function () {
4020
+ document.body.removeChild(importmapScript);
4021
+ return false;
4022
+ });
4023
+ });
4024
+
4025
+ function _await$5(value, then, direct) {
4026
+ if (direct) {
4027
+ return then ? then(value) : value;
4028
+ }
4029
+
4030
+ if (!value || !value.then) {
4031
+ value = Promise.resolve(value);
4032
+ }
4033
+
4034
+ return then ? value.then(then) : value;
4035
+ }
4036
+
4037
+ function _catch$3(body, recover) {
4038
+ try {
4039
+ var result = body();
4040
+ } catch (e) {
4041
+ return recover(e);
4042
+ }
4043
+
4044
+ if (result && result.then) {
4045
+ return result.then(void 0, recover);
4046
+ }
4047
+
4048
+ return result;
4049
+ }
4050
+
4051
+ function _async$4(f) {
4052
+ return function () {
4053
+ for (var args = [], i = 0; i < arguments.length; i++) {
4054
+ args[i] = arguments[i];
4055
+ }
4056
+
4057
+ try {
4058
+ return Promise.resolve(f.apply(this, args));
4059
+ } catch (e) {
4060
+ return Promise.reject(e);
4061
+ }
4062
+ };
4063
+ }
4064
+
4065
+ var supportsDynamicImport = _async$4(function () {
4066
+ var moduleSource = asBase64Url("export default 42");
4067
+ return _catch$3(function () {
4068
+ return _await$5(executeWithScriptModuleInjection("window.__jsenv_runtime_test_dynamic_import__ = import(".concat(JSON.stringify(moduleSource), ")")), function () {
4069
+ return _await$5(window.__jsenv_runtime_test_dynamic_import__, function (namespace) {
4070
+ delete window.__jsenv_runtime_test_dynamic_import__;
4071
+ return namespace.default === 42;
4072
+ });
4073
+ });
4074
+ }, function () {
4075
+ return false;
4076
+ });
4077
+ });
4078
+
4079
+ function _await$4(value, then, direct) {
4080
+ if (direct) {
4081
+ return then ? then(value) : value;
4082
+ }
4083
+
4084
+ if (!value || !value.then) {
4085
+ value = Promise.resolve(value);
4086
+ }
4087
+
4088
+ return then ? value.then(then) : value;
4089
+ }
4090
+
4091
+ function _catch$2(body, recover) {
4092
+ try {
4093
+ var result = body();
4094
+ } catch (e) {
4095
+ return recover(e);
4096
+ }
4097
+
4098
+ if (result && result.then) {
4099
+ return result.then(void 0, recover);
4100
+ }
4101
+
4102
+ return result;
4103
+ }
4104
+
4105
+ var supportsTopLevelAwait = function supportsTopLevelAwait() {
4106
+ return _await$4(_catch$2(function () {
4107
+ return _await$4(executeWithScriptModuleInjection("window.__jsenv_runtime_test_top_level_await__ = await Promise.resolve(42)"), function () {
4108
+ var supported = window.__jsenv_runtime_test_top_level_await__ === 42;
4109
+ delete window.__jsenv_runtime_test_top_level_await__;
4110
+ return supported;
4111
+ });
4112
+ }, function () {
4113
+ return false;
4114
+ }));
4115
+ };
4116
+
4117
+ function _await$3(value, then, direct) {
4118
+ if (direct) {
4119
+ return then ? then(value) : value;
4120
+ }
4121
+
4122
+ if (!value || !value.then) {
4123
+ value = Promise.resolve(value);
4124
+ }
4125
+
4126
+ return then ? value.then(then) : value;
4127
+ }
4128
+
4129
+ function _catch$1(body, recover) {
4130
+ try {
4131
+ var result = body();
4132
+ } catch (e) {
4133
+ return recover(e);
4134
+ }
4135
+
4136
+ if (result && result.then) {
4137
+ return result.then(void 0, recover);
4138
+ }
4139
+
4140
+ return result;
4141
+ }
4142
+
4143
+ function _async$3(f) {
4144
+ return function () {
4145
+ for (var args = [], i = 0; i < arguments.length; i++) {
4146
+ args[i] = arguments[i];
4147
+ }
4148
+
4149
+ try {
4150
+ return Promise.resolve(f.apply(this, args));
4151
+ } catch (e) {
4152
+ return Promise.reject(e);
4153
+ }
4154
+ };
4155
+ }
4156
+
4157
+ var supportsJsonImportAssertions = _async$3(function () {
4158
+ var jsonBase64Url = asBase64Url("42", "application/json");
4159
+ var moduleSource = asBase64Url("import data from \"".concat(jsonBase64Url, "\" assert { type: \"json\" }\n export default data"));
4160
+ return _catch$1(function () {
4161
+ return _await$3(executeWithScriptModuleInjection("window.__jsenv_runtime_test_json_import_assertion__ = import(".concat(JSON.stringify(moduleSource), ")")), function () {
4162
+ return _await$3(window.__jsenv_runtime_test_json_import_assertion__, function (namespace) {
4163
+ var supported = namespace.default === 42;
4164
+ delete window.__jsenv_runtime_test_json_import_assertion__;
4165
+ return supported;
4166
+ });
4167
+ });
4168
+ }, function () {
4169
+ return false;
4170
+ });
4171
+ });
4172
+
4173
+ function _await$2(value, then, direct) {
4174
+ if (direct) {
4175
+ return then ? then(value) : value;
4176
+ }
4177
+
4178
+ if (!value || !value.then) {
4179
+ value = Promise.resolve(value);
4180
+ }
4181
+
4182
+ return then ? value.then(then) : value;
4183
+ }
4184
+
4185
+ function _catch(body, recover) {
4186
+ try {
4187
+ var result = body();
4188
+ } catch (e) {
4189
+ return recover(e);
4190
+ }
4191
+
4192
+ if (result && result.then) {
4193
+ return result.then(void 0, recover);
4194
+ }
4110
4195
 
4111
- var normalizeVersion = function normalizeVersion(version) {
4112
- if (version.indexOf(".") > -1) {
4113
- var parts = version.split("."); // remove extraneous .
4196
+ return result;
4197
+ }
4114
4198
 
4115
- return parts.slice(0, 3).join(".");
4116
- }
4199
+ function _async$2(f) {
4200
+ return function () {
4201
+ for (var args = [], i = 0; i < arguments.length; i++) {
4202
+ args[i] = arguments[i];
4203
+ }
4117
4204
 
4118
- if (version.indexOf("_") > -1) {
4119
- var _parts = version.split("_"); // remove extraneous _
4205
+ try {
4206
+ return Promise.resolve(f.apply(this, args));
4207
+ } catch (e) {
4208
+ return Promise.reject(e);
4209
+ }
4210
+ };
4211
+ }
4120
4212
 
4213
+ var supportsCssImportAssertions = _async$2(function () {
4214
+ var cssBase64Url = asBase64Url("p { color: red; }", "text/css");
4215
+ var moduleSource = asBase64Url("import css from \"".concat(cssBase64Url, "\" assert { type: \"css\" }\n export default css"));
4216
+ return _catch(function () {
4217
+ return _await$2(executeWithScriptModuleInjection("window.__jsenv_runtime_test_css_import_assertion__ = import(".concat(JSON.stringify(moduleSource), ")")), function () {
4218
+ return _await$2(window.__jsenv_runtime_test_css_import_assertion__, function (namespace) {
4219
+ return namespace.default instanceof CSSStyleSheet;
4220
+ });
4221
+ });
4222
+ }, function () {
4223
+ return false;
4224
+ });
4225
+ });
4121
4226
 
4122
- return _parts.slice(0, 3).join("_");
4227
+ var supportsNewStylesheet = function supportsNewStylesheet() {
4228
+ try {
4229
+ // eslint-disable-next-line no-new
4230
+ new CSSStyleSheet();
4231
+ return true;
4232
+ } catch (e) {
4233
+ return false;
4123
4234
  }
4124
-
4125
- return version;
4126
4235
  };
4127
4236
 
4128
- function _await(value, then, direct) {
4237
+ function _await$1(value, then, direct) {
4129
4238
  if (direct) {
4130
4239
  return then ? then(value) : value;
4131
4240
  }
@@ -4151,7 +4260,7 @@ html[data-toolbar-visible] #toolbar-trigger {
4151
4260
  };
4152
4261
  }
4153
4262
 
4154
- function _call$1(body, then, direct) {
4263
+ function _call(body, then, direct) {
4155
4264
  if (direct) {
4156
4265
  return then ? then(body()) : body();
4157
4266
  }
@@ -4164,134 +4273,74 @@ html[data-toolbar-visible] #toolbar-trigger {
4164
4273
  }
4165
4274
  }
4166
4275
 
4167
- function _invoke(body, then) {
4168
- var result = body();
4169
-
4170
- if (result && result.then) {
4171
- return result.then(then);
4172
- }
4173
-
4174
- return then(result);
4175
- }
4176
-
4177
- function _catch(body, recover) {
4178
- try {
4179
- var result = body();
4180
- } catch (e) {
4181
- return recover(e);
4182
- }
4183
-
4184
- if (result && result.then) {
4185
- return result.then(void 0, recover);
4186
- }
4187
-
4188
- return result;
4189
- }
4190
-
4191
4276
  var scanBrowserRuntimeFeatures = _async$1(function () {
4192
4277
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
4193
4278
  _ref$coverageHandledF = _ref.coverageHandledFromOutside,
4194
4279
  coverageHandledFromOutside = _ref$coverageHandledF === void 0 ? false : _ref$coverageHandledF,
4195
- _ref$failFastOnFeatur = _ref.failFastOnFeatureDetection,
4196
- failFastOnFeatureDetection = _ref$failFastOnFeatur === void 0 ? false : _ref$failFastOnFeatur;
4197
-
4198
- return _await(fetchJson("/.jsenv/__compile_server_meta__.json"), function (_ref2) {
4199
- var outDirectoryRelativeUrl = _ref2.outDirectoryRelativeUrl,
4280
+ _ref$forceCompilation = _ref.forceCompilation,
4281
+ forceCompilation = _ref$forceCompilation === void 0 ? false : _ref$forceCompilation,
4282
+ _ref$forceSource = _ref.forceSource,
4283
+ forceSource = _ref$forceSource === void 0 ? false : _ref$forceSource;
4284
+
4285
+ var jsenvCompileProfileUrl = "/__jsenv_compile_profile__";
4286
+ return _await$1(fetchJson(jsenvCompileProfileUrl), function (_ref2) {
4287
+ var jsenvDirectoryRelativeUrl = _ref2.jsenvDirectoryRelativeUrl,
4200
4288
  inlineImportMapIntoHTML = _ref2.inlineImportMapIntoHTML,
4201
- customCompilerPatterns = _ref2.customCompilerPatterns,
4202
- compileServerGroupMap = _ref2.compileServerGroupMap;
4203
- var browser = detectBrowser();
4204
- var compileId = computeCompileIdFromGroupId({
4205
- groupId: resolveGroup(browser, compileServerGroupMap),
4206
- groupMap: compileServerGroupMap
4207
- });
4208
- var groupInfo = compileServerGroupMap[compileId];
4209
- var featuresReport = {
4210
- importmap: undefined,
4211
- dynamicImport: undefined,
4212
- topLevelAwait: undefined,
4213
- jsonImportAssertions: undefined,
4214
- cssImportAssertions: undefined,
4215
- newStylesheet: undefined
4216
- };
4217
- return _await(detectSupportedFeatures({
4218
- featuresReport: featuresReport,
4219
- failFastOnFeatureDetection: failFastOnFeatureDetection,
4289
+ availableCompileIds = _ref2.availableCompileIds;
4290
+
4291
+ var _detectBrowser = detectBrowser(),
4292
+ name = _detectBrowser.name,
4293
+ version = _detectBrowser.version;
4294
+
4295
+ return _await$1(detectSupportedFeatures({
4296
+ coverageHandledFromOutside: coverageHandledFromOutside,
4220
4297
  inlineImportMapIntoHTML: inlineImportMapIntoHTML
4221
- }), function () {
4222
- return _await(adjustMissingFeatureNames(groupInfo, {
4298
+ }), function (featuresReport) {
4299
+ var runtimeReport = {
4300
+ env: {
4301
+ browser: true
4302
+ },
4303
+ name: name,
4304
+ version: version,
4223
4305
  featuresReport: featuresReport,
4224
- coverageHandledFromOutside: coverageHandledFromOutside
4225
- }), function (missingFeatureNames) {
4226
- var canAvoidCompilation = customCompilerPatterns.length === 0 && missingFeatureNames.length === 0 && featuresReport.importmap && featuresReport.dynamicImport && featuresReport.topLevelAwait;
4306
+ forceSource: forceSource,
4307
+ forceCompilation: forceCompilation
4308
+ };
4309
+ return _await$1(fetchJson(jsenvCompileProfileUrl, {
4310
+ method: "POST",
4311
+ headers: {
4312
+ "content-type": "application/json"
4313
+ },
4314
+ body: JSON.stringify(runtimeReport)
4315
+ }), function (_ref3) {
4316
+ var compileProfile = _ref3.compileProfile,
4317
+ compileId = _ref3.compileId;
4227
4318
  return {
4228
- canAvoidCompilation: canAvoidCompilation,
4229
- featuresReport: featuresReport,
4230
- customCompilerPatterns: customCompilerPatterns,
4231
- missingFeatureNames: missingFeatureNames,
4319
+ jsenvDirectoryRelativeUrl: jsenvDirectoryRelativeUrl,
4232
4320
  inlineImportMapIntoHTML: inlineImportMapIntoHTML,
4233
- outDirectoryRelativeUrl: outDirectoryRelativeUrl,
4234
- compileId: compileId,
4235
- browser: browser
4321
+ availableCompileIds: availableCompileIds,
4322
+ runtimeReport: runtimeReport,
4323
+ compileProfile: compileProfile,
4324
+ compileId: compileId
4236
4325
  };
4237
4326
  });
4238
4327
  });
4239
4328
  });
4240
4329
  });
4241
4330
 
4242
- var adjustMissingFeatureNames = _async$1(function (groupInfo, _ref3) {
4243
- var featuresReport = _ref3.featuresReport,
4244
- coverageHandledFromOutside = _ref3.coverageHandledFromOutside;
4245
- var missingFeatureNames = groupInfo.missingFeatureNames;
4246
- var missingFeatureNamesCopy = missingFeatureNames.slice();
4247
-
4248
- var markAsSupported = function markAsSupported(name) {
4249
- var index = missingFeatureNamesCopy.indexOf(name);
4250
-
4251
- if (index > -1) {
4252
- missingFeatureNamesCopy.splice(index, 1);
4253
- }
4254
- }; // When instrumentation CAN be handed by playwright
4255
- // https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions
4256
- // coverageHandledFromOutside is true and "transform-instrument" becomes non mandatory
4257
-
4258
-
4259
- if (coverageHandledFromOutside) {
4260
- markAsSupported("transform-instrument");
4261
- }
4262
-
4263
- return _invoke(function () {
4264
- if (missingFeatureNames.includes("transform-import-assertions")) {
4265
- return _call$1(supportsJsonImportAssertions, function (jsonImportAssertions) {
4266
- featuresReport.jsonImportAssertions = jsonImportAssertions;
4267
- return _call$1(supportsCssImportAssertions, function (cssImportAssertions) {
4268
- featuresReport.cssImportAssertions = cssImportAssertions;
4269
-
4270
- if (jsonImportAssertions && cssImportAssertions) {
4271
- markAsSupported("transform-import-assertions");
4272
- }
4273
- });
4274
- });
4275
- }
4276
- }, function () {
4277
- if (missingFeatureNames.includes("new-stylesheet-as-jsenv-import")) {
4278
- var newStylesheet = supportsNewStylesheet();
4279
- featuresReport.newStylesheet = newStylesheet;
4280
- markAsSupported("new-stylesheet-as-jsenv-import");
4281
- }
4282
-
4283
- return missingFeatureNamesCopy;
4284
- });
4285
- });
4286
-
4287
4331
  var detectSupportedFeatures = _async$1(function (_ref4) {
4288
- var featuresReport = _ref4.featuresReport,
4289
- failFastOnFeatureDetection = _ref4.failFastOnFeatureDetection,
4290
- inlineImportMapIntoHTML = _ref4.inlineImportMapIntoHTML; // start testing importmap support first and not in paralell
4332
+ var coverageHandledFromOutside = _ref4.coverageHandledFromOutside,
4333
+ inlineImportMapIntoHTML = _ref4.inlineImportMapIntoHTML;
4334
+ var featuresReport = {};
4335
+ featuresReport["import_http"] = true;
4336
+ featuresReport["coverage_js"] = coverageHandledFromOutside; // new CSSStyleSheet
4337
+
4338
+ featuresReport["new_stylesheet"] = supportsNewStylesheet(); // importmap
4339
+ // start testing importmap support first and not in paralell
4291
4340
  // so that there is not module script loaded beore importmap is injected
4292
4341
  // it would log an error in chrome console and return undefined
4293
4342
 
4294
- return _await(supportsImportmap({
4343
+ return _await$1(supportsImportmap({
4295
4344
  // chrome supports inline but not remote importmap
4296
4345
  // https://github.com/WICG/import-maps/issues/235
4297
4346
  // at this stage we won't know if the html file will use
@@ -4301,150 +4350,27 @@ html[data-toolbar-visible] #toolbar-trigger {
4301
4350
  // and in that case we can test only the local importmap support
4302
4351
  // so we test importmap support and the remote one
4303
4352
  remote: !inlineImportMapIntoHTML
4304
- }), function (importmap) {
4305
- featuresReport.importmap = importmap;
4306
-
4307
- if (!importmap && failFastOnFeatureDetection) {
4308
- return;
4309
- }
4310
-
4311
- return _call$1(supportsDynamicImport, function (dynamicImport) {
4312
- featuresReport.dynamicImport = dynamicImport;
4313
-
4314
- if (!dynamicImport && failFastOnFeatureDetection) {
4315
- return;
4316
- }
4317
-
4318
- return _call$1(supportsTopLevelAwait, function (topLevelAwait) {
4319
- featuresReport.topLevelAwait = topLevelAwait;
4320
- });
4321
- });
4322
- });
4323
- });
4324
-
4325
- var supportsImportmap = _async$1(function () {
4326
- var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
4327
- _ref5$remote = _ref5.remote,
4328
- remote = _ref5$remote === void 0 ? true : _ref5$remote;
4329
-
4330
- var specifier = asBase64Url("export default false");
4331
- var importMap = {
4332
- imports: _defineProperty({}, specifier, asBase64Url("export default true"))
4333
- };
4334
- var importmapScript = document.createElement("script");
4335
- var importmapString = JSON.stringify(importMap, null, " ");
4336
- importmapScript.type = "importmap";
4337
-
4338
- if (remote) {
4339
- importmapScript.src = "data:application/json;base64,".concat(window.btoa(importmapString));
4340
- } else {
4341
- importmapScript.textContent = importmapString;
4342
- }
4343
-
4344
- document.body.appendChild(importmapScript);
4345
- return _catch(function () {
4346
- return _await(executeWithScriptModuleInjection("import supported from \"".concat(specifier, "\"; window.__jsenv_runtime_test_importmap__ = supported")), function () {
4347
- document.body.removeChild(importmapScript);
4348
- return window.__jsenv_runtime_test_importmap__;
4349
- });
4350
- }, function () {
4351
- document.body.removeChild(importmapScript);
4352
- return false;
4353
- });
4354
- });
4355
-
4356
- var supportsDynamicImport = _async$1(function () {
4357
- var moduleSource = asBase64Url("export default 42");
4358
- return _catch(function () {
4359
- return _await(executeWithScriptModuleInjection("window.__jsenv_runtime_test_dynamic_import__ = import(".concat(JSON.stringify(moduleSource), ")")), function () {
4360
- return _await(window.__jsenv_runtime_test_dynamic_import__, function (namespace) {
4361
- return namespace.default === 42;
4362
- });
4363
- });
4364
- }, function () {
4365
- return false;
4366
- });
4367
- });
4368
-
4369
- var supportsNewStylesheet = function supportsNewStylesheet() {
4370
- try {
4371
- // eslint-disable-next-line no-new
4372
- new CSSStyleSheet();
4373
- return true;
4374
- } catch (e) {
4375
- return false;
4376
- }
4377
- };
4378
-
4379
- var supportsTopLevelAwait = function supportsTopLevelAwait() {
4380
- return _await(_catch(function () {
4381
- return _await(executeWithScriptModuleInjection("window.__jsenv_runtime_test_top_level_await__ = await Promise.resolve(42)"), function () {
4382
- return window.__jsenv_runtime_test_top_level_await__ === 42;
4383
- });
4384
- }, function () {
4385
- return false;
4386
- }));
4387
- }; // to execute in a browser devtools
4388
- // const featuresReport = {}
4389
- // await detectSupportedFeatures({ featuresReport, inlineImportMapIntoHTML: true })
4390
- // console.log(featuresReport)
4353
+ }), function (_supportsImportmap) {
4354
+ featuresReport.importmap = _supportsImportmap; // dynamic import
4391
4355
 
4356
+ return _call(supportsDynamicImport, function (_supportsDynamicImpor) {
4357
+ featuresReport["import_dynamic"] = _supportsDynamicImpor; // top level await
4392
4358
 
4393
- var supportsJsonImportAssertions = _async$1(function () {
4394
- var jsonBase64Url = asBase64Url("42", "application/json");
4395
- var moduleSource = asBase64Url("import data from \"".concat(jsonBase64Url, "\" assert { type: \"json\" }\nexport default data"));
4396
- return _catch(function () {
4397
- return _await(executeWithScriptModuleInjection("window.__jsenv_runtime_test_json_import_assertion__ = import(".concat(JSON.stringify(moduleSource), ")")), function () {
4398
- return _await(window.__jsenv_runtime_test_json_import_assertion__, function (namespace) {
4399
- return namespace.default === 42;
4400
- });
4401
- });
4402
- }, function () {
4403
- return false;
4404
- });
4405
- });
4359
+ return _call(supportsTopLevelAwait, function (_supportsTopLevelAwai) {
4360
+ featuresReport["top_level_await"] = _supportsTopLevelAwai; // import assertions
4406
4361
 
4407
- var supportsCssImportAssertions = _async$1(function () {
4408
- var cssBase64Url = asBase64Url("p { color: red; }", "text/css");
4409
- var moduleSource = asBase64Url("import css from \"".concat(cssBase64Url, "\" assert { type: \"css\" }\nexport default css"));
4410
- return _catch(function () {
4411
- return _await(executeWithScriptModuleInjection("window.__jsenv_runtime_test_css_import_assertion__ = import(".concat(JSON.stringify(moduleSource), ")")), function () {
4412
- return _await(window.__jsenv_runtime_test_css_import_assertion__, function (namespace) {
4413
- return namespace.default instanceof CSSStyleSheet;
4362
+ return _call(supportsJsonImportAssertions, function (_supportsJsonImportAs) {
4363
+ featuresReport["import_assertion_type_json"] = _supportsJsonImportAs;
4364
+ return _call(supportsCssImportAssertions, function (_supportsCssImportAss) {
4365
+ featuresReport["import_assertion_type_css"] = _supportsCssImportAss;
4366
+ return featuresReport;
4367
+ });
4368
+ });
4414
4369
  });
4415
4370
  });
4416
- }, function () {
4417
- return false;
4418
4371
  });
4419
4372
  });
4420
4373
 
4421
- var executeWithScriptModuleInjection = function executeWithScriptModuleInjection(code) {
4422
- var scriptModule = document.createElement("script");
4423
- scriptModule.type = "module";
4424
- var loadPromise = new Promise(function (resolve, reject) {
4425
- scriptModule.onload = function () {
4426
- document.body.removeChild(scriptModule);
4427
- resolve();
4428
- };
4429
-
4430
- scriptModule.onerror = function () {
4431
- document.body.removeChild(scriptModule);
4432
- reject();
4433
- };
4434
-
4435
- document.body.appendChild(scriptModule);
4436
- });
4437
- scriptModule.src = asBase64Url(code);
4438
- return loadPromise;
4439
- };
4440
-
4441
- var asBase64Url = function asBase64Url(text) {
4442
- var mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "application/javascript";
4443
- return "data:".concat(mimeType, ";base64,").concat(window.btoa(text));
4444
- }; // const cssImportAssertions = await supportsCssImportAssertions()
4445
- // console.log({ cssImportAssertions })
4446
-
4447
-
4448
4374
  var renderCompilationInToolbar = function renderCompilationInToolbar(_ref) {
4449
4375
  var compileGroup = _ref.compileGroup;
4450
4376
  var browserSupportRootNode = document.querySelector("#browser_support");
@@ -4452,14 +4378,12 @@ html[data-toolbar-visible] #toolbar-trigger {
4452
4378
  removeForceHideElement(browserSupportRootNode);
4453
4379
  removeForceHideElement(filesCompilationRootNode);
4454
4380
  scanBrowserRuntimeFeatures().then(function (_ref2) {
4455
- var canAvoidCompilation = _ref2.canAvoidCompilation,
4456
- featuresReport = _ref2.featuresReport,
4457
- customCompilerPatterns = _ref2.customCompilerPatterns,
4458
- missingFeatureNames = _ref2.missingFeatureNames,
4381
+ var jsenvDirectoryRelativeUrl = _ref2.jsenvDirectoryRelativeUrl,
4459
4382
  inlineImportMapIntoHTML = _ref2.inlineImportMapIntoHTML,
4460
- outDirectoryRelativeUrl = _ref2.outDirectoryRelativeUrl,
4461
- compileId = _ref2.compileId;
4462
- var browserSupport = canAvoidCompilation ? inlineImportMapIntoHTML ? "partial" : "full" : "no";
4383
+ compileProfile = _ref2.compileProfile,
4384
+ compileId = _ref2.compileId,
4385
+ runtimeReport = _ref2.runtimeReport;
4386
+ var browserSupport = compileId ? "no" : inlineImportMapIntoHTML ? "partial" : "full";
4463
4387
  enableVariant(browserSupportRootNode, {
4464
4388
  browserSupport: browserSupport
4465
4389
  });
@@ -4467,57 +4391,64 @@ html[data-toolbar-visible] #toolbar-trigger {
4467
4391
  if (browserSupport === "no") {
4468
4392
  browserSupportRootNode.querySelector("a.browser_support_read_more_link").onclick = function () {
4469
4393
  // eslint-disable-next-line no-alert
4470
- window.alert("Source files needs to be compiled to be executable in this browser because: ".concat(getBrowserSupportMessage({
4471
- missingOnly: true,
4472
- featuresReport: featuresReport,
4473
- customCompilerPatterns: customCompilerPatterns,
4474
- missingFeatureNames: missingFeatureNames,
4475
- inlineImportMapIntoHTML: inlineImportMapIntoHTML
4394
+ window.alert("Source files needs to be compiled to be executable in this browser because: ".concat(listWhatIsMissing({
4395
+ compileProfile: compileProfile
4476
4396
  })));
4477
4397
  };
4478
4398
  } else if (browserSupport === "partial") {
4479
4399
  browserSupportRootNode.querySelector("a.browser_support_read_more_link").onclick = function () {
4480
4400
  // eslint-disable-next-line no-alert
4481
- window.alert("Source files (except html) can be executed directly in this browser because: ".concat(getBrowserSupportMessage({
4482
- featuresReport: featuresReport,
4483
- customCompilerPatterns: customCompilerPatterns,
4484
- missingFeatureNames: missingFeatureNames,
4401
+ window.alert("Source files (except html) can be executed directly in this browser because: ".concat(listWhatIsSupported({
4485
4402
  inlineImportMapIntoHTML: inlineImportMapIntoHTML
4486
4403
  })));
4487
4404
  };
4488
4405
  } else if (browserSupport === "full") {
4489
4406
  browserSupportRootNode.querySelector("a.browser_support_read_more_link").onclick = function () {
4490
4407
  // eslint-disable-next-line no-alert
4491
- window.alert("Source files can be executed directly in this browser because: ".concat(getBrowserSupportMessage({
4492
- featuresReport: featuresReport,
4493
- customCompilerPatterns: customCompilerPatterns,
4494
- missingFeatureNames: missingFeatureNames,
4408
+ window.alert("Source files can be executed directly in this browser because: ".concat(listWhatIsSupported({
4495
4409
  inlineImportMapIntoHTML: inlineImportMapIntoHTML
4496
4410
  })));
4497
4411
  };
4498
4412
  }
4499
4413
 
4500
- var filesCompilation = compileGroup.compileId ? "yes" : inlineImportMapIntoHTML ? "html_only" : "no";
4414
+ var actualCompileId = compileGroup.compileId;
4415
+ var expectedCompiledId = compileId;
4416
+ var shouldSwitchCompileId = expectedCompiledId && actualCompileId && actualCompileId !== expectedCompiledId;
4417
+ var shouldCompile = !actualCompileId && browserSupport === "no";
4418
+ var filesCompilation = shouldSwitchCompileId ? "mismatch" : actualCompileId ? "yes" : inlineImportMapIntoHTML ? "html_only" : "no";
4419
+ var hasWarning = shouldCompile || shouldSwitchCompileId;
4501
4420
  enableVariant(filesCompilationRootNode, {
4502
4421
  filesCompilation: filesCompilation,
4503
- compiled: compileGroup.compileId ? "yes" : "no"
4422
+ compilation_link: shouldSwitchCompileId ? "mismatch" : actualCompileId ? "source" : expectedCompiledId ? "compiled" : "force"
4504
4423
  });
4505
4424
 
4506
- filesCompilationRootNode.querySelector("a.go_to_source_link").onclick = function () {
4507
- window.parent.location = "/".concat(compileGroup.fileRelativeUrl);
4425
+ if (filesCompilation === "yes") {
4426
+ document.querySelector(".files_compilation_text").innerHTML = "Files shown are compiled for ".concat(runtimeReport.name, "@").concat(runtimeReport.version);
4427
+ }
4428
+
4429
+ filesCompilationRootNode.querySelector("a.link_to_source_files").onclick = function () {
4430
+ window.parent.location.href = "/".concat(compileGroup.fileRelativeUrl);
4431
+ };
4432
+
4433
+ filesCompilationRootNode.querySelector("a.link_to_compiled_files").onclick = function () {
4434
+ window.parent.location.href = "/".concat(jsenvDirectoryRelativeUrl).concat(expectedCompiledId, "/").concat(compileGroup.fileRelativeUrl);
4508
4435
  };
4509
4436
 
4510
- filesCompilationRootNode.querySelector("a.go_to_compiled_link").onclick = function () {
4511
- window.parent.location = "/".concat(outDirectoryRelativeUrl).concat(compileId, "/").concat(compileGroup.fileRelativeUrl);
4437
+ filesCompilationRootNode.querySelector("a.link_to_compilation_forced_files").onclick = function () {
4438
+ window.parent.location.href = "/".concat(jsenvDirectoryRelativeUrl, "force/").concat(compileGroup.fileRelativeUrl);
4512
4439
  };
4513
4440
 
4514
- var shouldCompile = filesCompilation !== "yes" && browserSupport === "no";
4441
+ filesCompilationRootNode.querySelector("a.link_to_appropriate_files").onclick = function () {
4442
+ window.parent.location.href = "/".concat(jsenvDirectoryRelativeUrl).concat(expectedCompiledId, "/").concat(compileGroup.fileRelativeUrl);
4443
+ };
4515
4444
 
4516
- if (shouldCompile) {
4445
+ if (hasWarning) {
4446
+ enableWarningStyle();
4517
4447
  document.querySelector(".files_compilation_text").setAttribute("data-warning", "");
4518
4448
  document.querySelector(".browser_support_text").setAttribute("data-warning", "");
4519
4449
  document.querySelector("#settings-button").setAttribute("data-warning", "");
4520
4450
  } else {
4451
+ disableWarningStyle();
4521
4452
  document.querySelector(".files_compilation_text").removeAttribute("data-warning");
4522
4453
  document.querySelector(".browser_support_text").removeAttribute("data-warning");
4523
4454
  document.querySelector("#settings-button").removeAttribute("data-warning");
@@ -4525,56 +4456,54 @@ html[data-toolbar-visible] #toolbar-trigger {
4525
4456
  });
4526
4457
  };
4527
4458
 
4528
- var getBrowserSupportMessage = function getBrowserSupportMessage(_ref3) {
4529
- var missingOnly = _ref3.missingOnly,
4530
- featuresReport = _ref3.featuresReport,
4531
- customCompilerPatterns = _ref3.customCompilerPatterns,
4532
- missingFeatureNames = _ref3.missingFeatureNames,
4533
- inlineImportMapIntoHTML = _ref3.inlineImportMapIntoHTML;
4459
+ var listWhatIsSupported = function listWhatIsSupported(_ref3) {
4460
+ var inlineImportMapIntoHTML = _ref3.inlineImportMapIntoHTML;
4534
4461
  var parts = [];
4535
4462
 
4536
- if (featuresReport.importmap) {
4537
- if (!missingOnly) {
4538
- if (inlineImportMapIntoHTML) {
4539
- parts.push("importmaps are supported (only when inlined in html files)");
4540
- } else {
4541
- parts.push("importmaps are supported");
4542
- }
4543
- }
4463
+ if (inlineImportMapIntoHTML) {
4464
+ parts.push("importmaps are supported (only when inlined in html files)");
4544
4465
  } else {
4466
+ parts.push("importmaps are supported");
4467
+ }
4468
+
4469
+ parts.push("dynamic imports are supported");
4470
+ parts.push("top level await is supported");
4471
+ parts.push("all features are natively supported");
4472
+ return "\n- ".concat(parts.join("\n- "));
4473
+ };
4474
+
4475
+ var listWhatIsMissing = function listWhatIsMissing(_ref4) {
4476
+ var compileProfile = _ref4.compileProfile;
4477
+ var parts = [];
4478
+ var missingFeatures = compileProfile.missingFeatures;
4479
+
4480
+ if (missingFeatures.importmap) {
4545
4481
  parts.push("importmaps are not supported");
4546
4482
  }
4547
4483
 
4548
- if (featuresReport.dynamicImport) {
4549
- if (!missingOnly) {
4550
- parts.push("dynamic imports are supported");
4551
- }
4552
- } else {
4484
+ if (missingFeatures.dynamicImport) {
4553
4485
  parts.push("dynamic imports are not supported");
4554
4486
  }
4555
4487
 
4556
- if (featuresReport.topLevelAwait) {
4557
- if (!missingOnly) {
4558
- parts.push("top level await is supported");
4559
- }
4560
- } else {
4488
+ if (missingFeatures.topLevelAwait) {
4561
4489
  parts.push("top level await is not supported");
4562
4490
  }
4563
4491
 
4492
+ var missingFeatureNames = Object.keys(missingFeatures).filter(function (name) {
4493
+ return name !== "importmap" && name !== "dynamicImport" && name !== "topLevelAwait" && name !== "custom_compiler_patterns";
4494
+ });
4564
4495
  var missingFeatureCount = missingFeatureNames.length;
4565
4496
 
4566
- if (missingFeatureCount === 0) {
4567
- if (!missingOnly) {
4568
- parts.push("all features are natively supported");
4569
- }
4570
- } else {
4497
+ if (missingFeatureCount > 0) {
4571
4498
  parts.push("".concat(missingFeatureCount, " features are missing: ").concat(missingFeatureNames));
4572
4499
  }
4573
4500
 
4574
- var customCompilerCount = customCompilerPatterns.length;
4575
- if (customCompilerCount === 0) ;else {
4576
- parts.push("".concat(customCompilerCount, " custom compilers enabled: ").concat(customCompilerPatterns));
4501
+ var custom_compiler_patterns = missingFeatures.custom_compiler_patterns;
4502
+
4503
+ if (custom_compiler_patterns) {
4504
+ parts.push("".concat(custom_compiler_patterns.length, " custom compilers enabled: ").concat(custom_compiler_patterns));
4577
4505
  }
4506
+
4578
4507
  return "\n- ".concat(parts.join("\n- "));
4579
4508
  };
4580
4509
 
@@ -4750,17 +4679,16 @@ html[data-toolbar-visible] #toolbar-trigger {
4750
4679
  document.querySelector("#overflow-menu").removeAttribute("data-animate");
4751
4680
  };
4752
4681
 
4753
- function _call(body, then, direct) {
4682
+ function _await(value, then, direct) {
4754
4683
  if (direct) {
4755
- return then ? then(body()) : body();
4684
+ return then ? then(value) : value;
4756
4685
  }
4757
4686
 
4758
- try {
4759
- var result = Promise.resolve(body());
4760
- return then ? result.then(then) : result;
4761
- } catch (e) {
4762
- return Promise.reject(e);
4687
+ if (!value || !value.then) {
4688
+ value = Promise.resolve(value);
4763
4689
  }
4690
+
4691
+ return then ? value.then(then) : value;
4764
4692
  }
4765
4693
 
4766
4694
  var toolbarVisibilityPreference = createPreference("toolbar");
@@ -4779,66 +4707,67 @@ html[data-toolbar-visible] #toolbar-trigger {
4779
4707
  };
4780
4708
  }
4781
4709
 
4782
- var renderToolbar = _async(function () {
4710
+ var renderToolbar = _async(function (_ref) {
4711
+ var exploringJSON = _ref.exploringJSON;
4783
4712
  var executedFileCompiledUrl = window.parent.location.href;
4784
4713
  var compileServerOrigin = window.parent.location.origin; // this should not block the whole toolbar rendering + interactivity
4785
4714
 
4786
- return _call(fetchExploringJson, function (exploringConfig) {
4787
- var outDirectoryRelativeUrl = exploringConfig.outDirectoryRelativeUrl,
4788
- livereloading = exploringConfig.livereloading;
4789
- var compileGroup = getCompileGroup({
4790
- executedFileCompiledUrl: executedFileCompiledUrl,
4791
- outDirectoryRelativeUrl: outDirectoryRelativeUrl,
4792
- compileServerOrigin: compileServerOrigin
4793
- });
4794
- var executedFileRelativeUrl = compileGroup.fileRelativeUrl;
4795
- var toolbarOverlay = document.querySelector("#toolbar-overlay");
4715
+ var jsenvDirectoryRelativeUrl = exploringJSON.jsenvDirectoryRelativeUrl,
4716
+ livereloading = exploringJSON.livereloading;
4717
+ var compileGroup = getCompileGroup({
4718
+ executedFileCompiledUrl: executedFileCompiledUrl,
4719
+ jsenvDirectoryRelativeUrl: jsenvDirectoryRelativeUrl,
4720
+ compileServerOrigin: compileServerOrigin
4721
+ });
4722
+ var executedFileRelativeUrl = compileGroup.fileRelativeUrl;
4723
+ var toolbarOverlay = document.querySelector("#toolbar-overlay");
4796
4724
 
4797
- toolbarOverlay.onclick = function () {
4798
- hideAllTooltip();
4799
- hideSettings();
4800
- };
4725
+ toolbarOverlay.onclick = function () {
4726
+ hideAllTooltip();
4727
+ hideSettings();
4728
+ };
4801
4729
 
4802
- var toolbarVisible = toolbarVisibilityPreference.has() ? toolbarVisibilityPreference.get() : true;
4730
+ var toolbarVisible = toolbarVisibilityPreference.has() ? toolbarVisibilityPreference.get() : true;
4803
4731
 
4804
- if (toolbarVisible) {
4805
- showToolbar({
4806
- animate: false
4807
- });
4808
- } else {
4809
- hideToolbar({
4810
- animate: false
4811
- });
4812
- }
4732
+ if (toolbarVisible) {
4733
+ showToolbar({
4734
+ animate: false
4735
+ });
4736
+ } else {
4737
+ hideToolbar({
4738
+ animate: false
4739
+ });
4740
+ }
4813
4741
 
4814
- document.querySelector(".toolbar-icon-wrapper").onclick = function () {
4815
- window.parent.location.href = "/";
4816
- };
4742
+ document.querySelector(".toolbar-icon-wrapper").onclick = function () {
4743
+ window.parent.location.href = "/";
4744
+ };
4817
4745
 
4818
- renderToolbarNotification();
4819
- makeToolbarResponsive();
4820
- renderToolbarSettings();
4821
- renderToolbarAnimation();
4822
- renderToolbarTheme();
4823
- renderExecutionInToolbar({
4824
- executedFileRelativeUrl: executedFileRelativeUrl
4825
- });
4826
- renderCompilationInToolbar({
4827
- compileGroup: compileGroup
4828
- }); // this might become active but we need to detect this somehow
4829
-
4830
- deactivateToolbarSection(document.querySelector("#file-list-link"));
4831
- initToolbarEventSource({
4832
- executedFileRelativeUrl: executedFileRelativeUrl,
4833
- livereloading: livereloading
4834
- }); // if user click enter or space quickly while closing toolbar
4835
- // it will cancel the closing
4836
- // that's why I used toggleToolbar and not hideToolbar
4837
-
4838
- document.querySelector("#button-close-toolbar").onclick = function () {
4839
- return toogleToolbar();
4840
- };
4746
+ renderToolbarNotification();
4747
+ makeToolbarResponsive();
4748
+ renderToolbarSettings();
4749
+ renderToolbarAnimation();
4750
+ renderToolbarTheme();
4751
+ renderExecutionInToolbar({
4752
+ executedFileRelativeUrl: executedFileRelativeUrl
4841
4753
  });
4754
+ renderCompilationInToolbar({
4755
+ compileGroup: compileGroup
4756
+ }); // this might become active but we need to detect this somehow
4757
+
4758
+ deactivateToolbarSection(document.querySelector("#file-list-link"));
4759
+ initToolbarEventSource({
4760
+ executedFileRelativeUrl: executedFileRelativeUrl,
4761
+ livereloading: livereloading
4762
+ }); // if user click enter or space quickly while closing toolbar
4763
+ // it will cancel the closing
4764
+ // that's why I used toggleToolbar and not hideToolbar
4765
+
4766
+ document.querySelector("#button-close-toolbar").onclick = function () {
4767
+ return toogleToolbar();
4768
+ };
4769
+
4770
+ return _await();
4842
4771
  });
4843
4772
 
4844
4773
  var toogleToolbar = function toogleToolbar() {
@@ -4861,9 +4790,9 @@ html[data-toolbar-visible] #toolbar-trigger {
4861
4790
 
4862
4791
 
4863
4792
  var showToolbar = function showToolbar() {
4864
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
4865
- _ref$animate = _ref.animate,
4866
- animate = _ref$animate === void 0 ? true : _ref$animate;
4793
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
4794
+ _ref2$animate = _ref2.animate,
4795
+ animate = _ref2$animate === void 0 ? true : _ref2$animate;
4867
4796
 
4868
4797
  toolbarVisibilityPreference.set(true);
4869
4798
 
@@ -4902,8 +4831,8 @@ html[data-toolbar-visible] #toolbar-trigger {
4902
4831
  var scrollEnd = scrollY + 40;
4903
4832
  startJavaScriptAnimation({
4904
4833
  duration: 300,
4905
- onProgress: function onProgress(_ref2) {
4906
- var progress = _ref2.progress;
4834
+ onProgress: function onProgress(_ref3) {
4835
+ var progress = _ref3.progress;
4907
4836
  var value = scrollY + (scrollEnd - scrollY) * progress;
4908
4837
  parentDocumentElement.scrollTop = value;
4909
4838
  }
@@ -4928,26 +4857,24 @@ html[data-toolbar-visible] #toolbar-trigger {
4928
4857
  };
4929
4858
  };
4930
4859
 
4931
- var getCompileGroup = function getCompileGroup(_ref3) {
4932
- var executedFileCompiledUrl = _ref3.executedFileCompiledUrl,
4933
- outDirectoryRelativeUrl = _ref3.outDirectoryRelativeUrl,
4934
- compileServerOrigin = _ref3.compileServerOrigin;
4935
- var outDirectoryServerUrl = String(new URL(outDirectoryRelativeUrl, compileServerOrigin));
4860
+ var getCompileGroup = function getCompileGroup(_ref4) {
4861
+ var executedFileCompiledUrl = _ref4.executedFileCompiledUrl,
4862
+ jsenvDirectoryRelativeUrl = _ref4.jsenvDirectoryRelativeUrl,
4863
+ compileServerOrigin = _ref4.compileServerOrigin;
4864
+ var jsenvDirectoryServerUrl = new URL(jsenvDirectoryRelativeUrl, compileServerOrigin).href;
4936
4865
 
4937
- if (urlIsInsideOf(executedFileCompiledUrl, outDirectoryServerUrl)) {
4938
- var afterCompileDirectory = urlToRelativeUrl(executedFileCompiledUrl, outDirectoryServerUrl);
4866
+ if (urlIsInsideOf(executedFileCompiledUrl, jsenvDirectoryServerUrl)) {
4867
+ var afterCompileDirectory = urlToRelativeUrl(executedFileCompiledUrl, jsenvDirectoryServerUrl);
4939
4868
  var slashIndex = afterCompileDirectory.indexOf("/");
4940
4869
  var fileRelativeUrl = afterCompileDirectory.slice(slashIndex + 1);
4941
4870
  return {
4942
4871
  fileRelativeUrl: fileRelativeUrl,
4943
- outDirectoryRelativeUrl: outDirectoryRelativeUrl,
4944
4872
  compileId: afterCompileDirectory.slice(0, slashIndex)
4945
4873
  };
4946
4874
  }
4947
4875
 
4948
4876
  return {
4949
4877
  fileRelativeUrl: new URL(executedFileCompiledUrl).pathname.slice(1),
4950
- outDirectoryRelativeUrl: outDirectoryRelativeUrl,
4951
4878
  compileId: null
4952
4879
  };
4953
4880
  };
@@ -4989,14 +4916,13 @@ html[data-toolbar-visible] #toolbar-trigger {
4989
4916
  };
4990
4917
 
4991
4918
  window.toolbar = {
4992
- render: renderToolbar,
4993
4919
  show: showToolbar,
4994
4920
  hide: function hide() {
4995
4921
  return hideToolbar();
4996
4922
  }
4997
4923
  };
4998
- addExternalCommandCallback("renderToolbar", function () {
4999
- renderToolbar();
4924
+ addExternalCommandCallback("renderToolbar", function (data) {
4925
+ renderToolbar(data);
5000
4926
  });
5001
4927
  addExternalCommandCallback("showToolbar", function () {
5002
4928
  showToolbar();
@@ -5009,7 +4935,7 @@ html[data-toolbar-visible] #toolbar-trigger {
5009
4935
  };
5010
4936
  });
5011
4937
 
5012
- //# sourceMappingURL=toolbar.main_6c1b3d82.js.map</script>
4938
+ //# sourceMappingURL=toolbar.main_279b3a68.js.map</script>
5013
4939
 
5014
4940
 
5015
4941
  </body></html>