es-module-shims 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,281 +1,284 @@
1
- /** ES Module Shims Wasm @version 2.4.1 */
1
+ /** ES Module Shims Wasm @version 2.5.0 */
2
2
  (function (exports) {
3
3
 
4
- let invalidate;
5
- const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
6
- const initHotReload = () => {
7
- let _importHook = importHook,
8
- _resolveHook = resolveHook,
9
- _metaHook = metaHook;
4
+ let invalidate;
5
+ const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
6
+ const initHotReload = () => {
7
+ let _importHook = importHook,
8
+ _resolveHook = resolveHook,
9
+ _metaHook = metaHook;
10
+
11
+ let defaultResolve;
12
+ let hotResolveHook = (id, parent, _defaultResolve) => {
13
+ if (!defaultResolve) defaultResolve = _defaultResolve;
14
+ const originalParent = stripVersion(parent);
15
+ const url = stripVersion(defaultResolve(id, originalParent));
16
+ const hotState = getHotState(url);
17
+ const parents = hotState.p;
18
+ if (!parents.includes(originalParent)) parents.push(originalParent);
19
+ return toVersioned(url, hotState);
20
+ };
21
+ const hotImportHook = (url, _, __, source, sourceType) => {
22
+ const hotState = getHotState(url);
23
+ hotState.e = typeof source === 'string' ? source : true;
24
+ hotState.t = sourceType;
25
+ };
26
+ const hotMetaHook = (metaObj, url) => {
27
+ metaObj.hot = new Hot(url);
28
+ };
29
+
30
+ const Hot = class Hot {
31
+ constructor(url) {
32
+ this.data = getHotState((this.url = stripVersion(url))).d;
33
+ }
34
+ accept(deps, cb) {
35
+ if (typeof deps === 'function') {
36
+ cb = deps;
37
+ deps = null;
38
+ }
39
+ const hotState = getHotState(this.url);
40
+ if (!hotState.A) return;
41
+ (hotState.a = hotState.a || []).push([
42
+ typeof deps === 'string' ? defaultResolve(deps, this.url)
43
+ : deps ? deps.map(d => defaultResolve(d, this.url))
44
+ : null,
45
+ cb
46
+ ]);
47
+ }
48
+ dispose(cb) {
49
+ getHotState(this.url).u = cb;
50
+ }
51
+ invalidate() {
52
+ const hotState = getHotState(this.url);
53
+ hotState.a = null;
54
+ hotState.A = true;
55
+ const seen = [this.url];
56
+ for (const p of hotState.p) invalidate(p, this.url, seen);
57
+ }
58
+ };
59
+
60
+ const versionedRegEx = /\?v=\d+$/;
61
+ const stripVersion = url => {
62
+ const versionMatch = url.match(versionedRegEx);
63
+ return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
64
+ };
65
+
66
+ const toVersioned = (url, hotState) => {
67
+ const { v } = hotState;
68
+ return url + (v ? '?v=' + v : '');
69
+ };
70
+
71
+ let hotRegistry = {},
72
+ curInvalidationRoots = new Set(),
73
+ curInvalidationInterval;
74
+ const getHotState = url =>
75
+ hotRegistry[url] ||
76
+ (hotRegistry[url] = {
77
+ // version
78
+ v: 0,
79
+ // accept list ([deps, cb] pairs)
80
+ a: null,
81
+ // accepting acceptors
82
+ A: true,
83
+ // unload callback
84
+ u: null,
85
+ // entry point or inline script source
86
+ e: false,
87
+ // hot data
88
+ d: {},
89
+ // parents
90
+ p: [],
91
+ // source type
92
+ t: undefined
93
+ });
94
+
95
+ invalidate = (url, fromUrl, seen = []) => {
96
+ if (!seen.includes(url)) {
97
+ seen.push(url);
98
+ const hotState = hotRegistry[url];
99
+ if (hotState) {
100
+ hotState.A = false;
101
+ if (
102
+ fromUrl &&
103
+ hotState.a &&
104
+ hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
105
+ ) {
106
+ curInvalidationRoots.add(fromUrl);
107
+ } else {
108
+ if (hotState.e || hotState.a) curInvalidationRoots.add(url);
109
+ hotState.v++;
110
+ if (!hotState.a) for (const parent of hotState.p) invalidate(parent, url, seen);
111
+ }
112
+ }
113
+ if (!curInvalidationInterval) curInvalidationInterval = setTimeout(handleInvalidations, hotReloadInterval);
114
+ }
115
+ };
116
+
117
+ const handleInvalidations = () => {
118
+ curInvalidationInterval = null;
119
+ const earlyRoots = new Set();
120
+ for (const root of curInvalidationRoots) {
121
+ const hotState = hotRegistry[root];
122
+ topLevelLoad(
123
+ toVersioned(root, hotState),
124
+ baseUrl,
125
+ defaultFetchOpts,
126
+ typeof hotState.e === 'string' ? hotState.e : undefined,
127
+ false,
128
+ undefined,
129
+ hotState.t
130
+ ).then(m => {
131
+ if (hotState.a) {
132
+ hotState.a.every(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
133
+ // unload should be the latest unload handler from the just loaded module
134
+ if (hotState.u) {
135
+ hotState.u(hotState.d);
136
+ hotState.u = null;
137
+ }
138
+ }
139
+ for (const parent of hotState.p) {
140
+ const hotState = hotRegistry[parent];
141
+ if (hotState && hotState.a)
142
+ hotState.a.every(async ([d, c]) => {
143
+ return (
144
+ d &&
145
+ !earlyRoots.has(c) &&
146
+ (typeof d === 'string' ?
147
+ d === root && c(m)
148
+ : c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d, getHotState(d))))))))
149
+ );
150
+ });
151
+ }
152
+ }, throwError);
153
+ }
154
+ curInvalidationRoots = new Set();
155
+ };
156
+
157
+ return [
158
+ _importHook ? chain(_importHook, hotImportHook) : hotImportHook,
159
+ _resolveHook ?
160
+ (id, parent, defaultResolve) =>
161
+ hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
162
+ : hotResolveHook,
163
+ _metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
164
+ ];
165
+ };
10
166
 
11
- let defaultResolve;
12
- let hotResolveHook = (id, parent, _defaultResolve) => {
13
- if (!defaultResolve) defaultResolve = _defaultResolve;
14
- const originalParent = stripVersion(parent);
15
- const url = stripVersion(defaultResolve(id, originalParent));
16
- const parents = getHotState(url).p;
17
- if (!parents.includes(originalParent)) parents.push(originalParent);
18
- return toVersioned(url);
19
- };
20
- const hotImportHook = (url, _, __, source, sourceType) => {
21
- const hotState = getHotState(url);
22
- hotState.e = typeof source === 'string' ? source : true;
23
- hotState.t = sourceType;
24
- };
25
- const hotMetaHook = (metaObj, url) => {
26
- metaObj.hot = new Hot(url);
27
- };
167
+ const hasDocument = typeof document !== 'undefined';
28
168
 
29
- const Hot = class Hot {
30
- constructor(url) {
31
- this.data = getHotState((this.url = stripVersion(url))).d;
32
- }
33
- accept(deps, cb) {
34
- if (typeof deps === 'function') {
35
- cb = deps;
36
- deps = null;
37
- }
38
- const hotState = getHotState(this.url);
39
- if (!hotState.A) return;
40
- (hotState.a = hotState.a || []).push([
41
- typeof deps === 'string' ? defaultResolve(deps, this.url)
42
- : deps ? deps.map(d => defaultResolve(d, this.url))
43
- : null,
44
- cb
45
- ]);
46
- }
47
- dispose(cb) {
48
- getHotState(this.url).u = cb;
49
- }
50
- invalidate() {
51
- const hotState = getHotState(this.url);
52
- hotState.a = null;
53
- hotState.A = true;
54
- const seen = [this.url];
55
- for (const p of hotState.p) invalidate(p, this.url, seen);
56
- }
57
- };
169
+ const noop = () => {};
58
170
 
59
- const versionedRegEx = /\?v=\d+$/;
60
- const stripVersion = url => {
61
- const versionMatch = url.match(versionedRegEx);
62
- return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
171
+ const chain = (a, b) =>
172
+ function () {
173
+ a.apply(this, arguments);
174
+ b.apply(this, arguments);
63
175
  };
64
176
 
65
- const toVersioned = url => {
66
- const v = getHotState(url).v;
67
- return url + (v ? '?v=' + v : '');
68
- };
177
+ const dynamicImport = (u, errUrl) => import(u);
69
178
 
70
- let hotRegistry = {},
71
- curInvalidationRoots = new Set(),
72
- curInvalidationInterval;
73
- const getHotState = url =>
74
- hotRegistry[url] ||
75
- (hotRegistry[url] = {
76
- // version
77
- v: 0,
78
- // accept list ([deps, cb] pairs)
79
- a: null,
80
- // accepting acceptors
81
- A: true,
82
- // unload callback
83
- u: null,
84
- // entry point or inline script source
85
- e: false,
86
- // hot data
87
- d: {},
88
- // parents
89
- p: [],
90
- // source type
91
- t: undefined
92
- });
179
+ const defineValue = (obj, prop, value) =>
180
+ Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
93
181
 
94
- invalidate = (url, fromUrl, seen = []) => {
95
- if (!seen.includes(url)) {
96
- seen.push(url);
97
- const hotState = hotRegistry[url];
98
- if (hotState) {
99
- hotState.A = false;
100
- if (
101
- hotState.a &&
102
- hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
103
- ) {
104
- curInvalidationRoots.add(fromUrl);
105
- } else {
106
- if (hotState.e || hotState.a) curInvalidationRoots.add(url);
107
- hotState.v++;
108
- if (!hotState.a) for (const parent of hotState.p) invalidate(parent, url, seen);
109
- }
110
- }
111
- }
112
- if (!curInvalidationInterval)
113
- curInvalidationInterval = setTimeout(() => {
114
- curInvalidationInterval = null;
115
- const earlyRoots = new Set();
116
- for (const root of curInvalidationRoots) {
117
- const hotState = hotRegistry[root];
118
- topLevelLoad(
119
- toVersioned(root),
120
- baseUrl,
121
- defaultFetchOpts,
122
- typeof hotState.e === 'string' ? hotState.e : undefined,
123
- false,
124
- undefined,
125
- hotState.t
126
- ).then(m => {
127
- if (hotState.a) {
128
- hotState.a.every(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
129
- // unload should be the latest unload handler from the just loaded module
130
- if (hotState.u) {
131
- hotState.u(hotState.d);
132
- hotState.u = null;
133
- }
134
- }
135
- for (const parent of hotState.p) {
136
- const hotState = hotRegistry[parent];
137
- if (hotState && hotState.a)
138
- hotState.a.every(async ([d, c]) => {
139
- return (
140
- d &&
141
- !earlyRoots.has(c) &&
142
- (typeof d === 'string' ?
143
- d === root && c(m)
144
- : c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d)))))))
145
- );
146
- });
147
- }
148
- }, throwError);
149
- }
150
- curInvalidationRoots = new Set();
151
- }, hotReloadInterval);
152
- };
182
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
183
+
184
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
185
+ Object.assign(esmsInitOptions, self.esmsInitOptions || {});
186
+
187
+ const version = "2.5.0";
188
+
189
+ const r = esmsInitOptions.version;
190
+ if (self.importShim || (r && r !== version)) {
191
+ return;
192
+ }
193
+
194
+ // shim mode is determined on initialization, no late shim mode
195
+ const shimMode =
196
+ esmsInitOptions.shimMode ||
197
+ (hasDocument &&
198
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
199
+ .length > 0);
200
+
201
+ let importHook,
202
+ resolveHook,
203
+ fetchHook = fetch,
204
+ metaHook,
205
+ tsTransform =
206
+ esmsInitOptions.tsTransform ||
207
+ (hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
208
+ './es-module-shims-typescript.js';
209
+
210
+ const defaultFetchOpts = { credentials: 'same-origin' };
211
+
212
+ const {
213
+ revokeBlobURLs,
214
+ noLoadEventRetriggers,
215
+ enforceIntegrity,
216
+ hotReload,
217
+ hotReloadInterval = 100,
218
+ nativePassthrough = !hotReload
219
+ } = esmsInitOptions;
220
+
221
+ const globalHook = name => (typeof name === 'string' ? self[name] : name);
153
222
 
154
- return [
155
- _importHook ? chain(_importHook, hotImportHook) : hotImportHook,
156
- _resolveHook ?
157
- (id, parent, defaultResolve) =>
158
- hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
159
- : hotResolveHook,
160
- _metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
161
- ];
223
+ if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
224
+ if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
225
+ if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
226
+ if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
227
+
228
+ if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
229
+
230
+ const mapOverrides = esmsInitOptions.mapOverrides;
231
+
232
+ let nonce = esmsInitOptions.nonce;
233
+ if (!nonce && hasDocument) {
234
+ const nonceElement = document.querySelector('script[nonce]');
235
+ if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
236
+ }
237
+
238
+ const onerror = globalHook(esmsInitOptions.onerror || console.error.bind(console));
239
+
240
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
241
+ const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
242
+ const wasmInstancePhaseEnabled =
243
+ enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
244
+ const wasmSourcePhaseEnabled =
245
+ enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
246
+ const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
247
+
248
+ const onpolyfill =
249
+ esmsInitOptions.onpolyfill ?
250
+ globalHook(esmsInitOptions.onpolyfill)
251
+ : () => {
252
+ console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
253
+ };
254
+
255
+ const baseUrl =
256
+ hasDocument ?
257
+ document.baseURI
258
+ : `${location.protocol}//${location.host}${
259
+ location.pathname.includes('/') ?
260
+ location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
261
+ : location.pathname
262
+ }`;
263
+
264
+ const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
265
+ let { skip } = esmsInitOptions;
266
+ if (Array.isArray(skip)) {
267
+ const l = skip.map(s => new URL(s, baseUrl).href);
268
+ skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
269
+ } else if (typeof skip === 'string') {
270
+ const r = new RegExp(skip);
271
+ skip = s => r.test(s);
272
+ } else if (skip instanceof RegExp) {
273
+ skip = s => skip.test(s);
274
+ }
275
+
276
+ const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
277
+
278
+ const throwError = err => {
279
+ (self.reportError || dispatchError)(err), void onerror(err);
162
280
  };
163
281
 
164
- const hasDocument = typeof document !== 'undefined';
165
-
166
- const noop = () => {};
167
-
168
- const chain = (a, b) =>
169
- function () {
170
- a.apply(this, arguments);
171
- b.apply(this, arguments);
172
- };
173
-
174
- const dynamicImport = (u, errUrl) => import(u);
175
-
176
- const defineValue = (obj, prop, value) =>
177
- Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
178
-
179
- const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
180
-
181
- const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
182
- Object.assign(esmsInitOptions, self.esmsInitOptions || {});
183
-
184
- const version = "2.4.1";
185
-
186
- const r = esmsInitOptions.version;
187
- if (self.importShim || (r && r !== version)) {
188
- return;
189
- }
190
-
191
- // shim mode is determined on initialization, no late shim mode
192
- const shimMode =
193
- esmsInitOptions.shimMode ||
194
- (hasDocument &&
195
- document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
196
- .length > 0);
197
-
198
- let importHook,
199
- resolveHook,
200
- fetchHook = fetch,
201
- metaHook,
202
- tsTransform =
203
- esmsInitOptions.tsTransform ||
204
- (hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
205
- './es-module-shims-typescript.js';
206
-
207
- const defaultFetchOpts = { credentials: 'same-origin' };
208
-
209
- const {
210
- revokeBlobURLs,
211
- noLoadEventRetriggers,
212
- enforceIntegrity,
213
- hotReload,
214
- hotReloadInterval = 100,
215
- nativePassthrough = !hotReload
216
- } = esmsInitOptions;
217
-
218
- const globalHook = name => (typeof name === 'string' ? self[name] : name);
219
-
220
- if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
221
- if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
222
- if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
223
- if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
224
-
225
- if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
226
-
227
- const mapOverrides = esmsInitOptions.mapOverrides;
228
-
229
- let nonce = esmsInitOptions.nonce;
230
- if (!nonce && hasDocument) {
231
- const nonceElement = document.querySelector('script[nonce]');
232
- if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
233
- }
234
-
235
- const onerror = globalHook(esmsInitOptions.onerror || console.error.bind(console));
236
-
237
- const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
238
- const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
239
- const wasmInstancePhaseEnabled =
240
- enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
241
- const wasmSourcePhaseEnabled =
242
- enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
243
- const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
244
-
245
- const onpolyfill =
246
- esmsInitOptions.onpolyfill ?
247
- globalHook(esmsInitOptions.onpolyfill)
248
- : () => {
249
- console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
250
- };
251
-
252
- const baseUrl =
253
- hasDocument ?
254
- document.baseURI
255
- : `${location.protocol}//${location.host}${
256
- location.pathname.includes('/') ?
257
- location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
258
- : location.pathname
259
- }`;
260
-
261
- const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
262
- let { skip } = esmsInitOptions;
263
- if (Array.isArray(skip)) {
264
- const l = skip.map(s => new URL(s, baseUrl).href);
265
- skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
266
- } else if (typeof skip === 'string') {
267
- const r = new RegExp(skip);
268
- skip = s => r.test(s);
269
- } else if (skip instanceof RegExp) {
270
- skip = s => skip.test(s);
271
- }
272
-
273
- const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
274
-
275
- const throwError = err => {
276
- (self.reportError || dispatchError)(err), void onerror(err);
277
- };
278
-
279
282
  const fromParent = parent => (parent ? ` imported from ${parent}` : '');
280
283
 
281
284
  const backslashRegEx = /\\/g;
@@ -472,115 +475,115 @@
472
475
  }
473
476
  };
474
477
 
475
- // support browsers without dynamic import support (eg Firefox 6x)
476
- let supportsJsonType = false;
477
- let supportsCssType = false;
478
-
479
- const supports = hasDocument && HTMLScriptElement.supports;
480
-
481
- let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
482
- let supportsWasmInstancePhase = false;
483
- let supportsWasmSourcePhase = false;
484
- let supportsMultipleImportMaps = false;
485
-
486
- const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
487
-
488
- let featureDetectionPromise = (async function () {
489
- if (!hasDocument)
490
- return Promise.all([
491
- import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
492
- () => (
493
- (supportsJsonType = true),
494
- import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
495
- () => (supportsCssType = true),
496
- noop
497
- )
498
- ),
499
- noop
500
- ),
501
- wasmInstancePhaseEnabled &&
502
- import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
503
- () => (supportsWasmInstancePhase = true),
504
- noop
505
- ),
506
- wasmSourcePhaseEnabled &&
507
- import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
508
- () => (supportsWasmSourcePhase = true),
509
- noop
510
- )
511
- ]);
512
-
513
- const msgTag = `s${version}`;
514
- return new Promise(resolve => {
515
- const iframe = document.createElement('iframe');
516
- iframe.style.display = 'none';
517
- iframe.setAttribute('nonce', nonce);
518
- function cb({ data }) {
519
- const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
520
- if (!isFeatureDetectionMessage) return;
521
- [
522
- ,
523
- supportsImportMaps,
524
- supportsMultipleImportMaps,
525
- supportsJsonType,
526
- supportsCssType,
527
- supportsWasmSourcePhase,
528
- supportsWasmInstancePhase
529
- ] = data;
530
- resolve();
531
- document.head.removeChild(iframe);
532
- window.removeEventListener('message', cb, false);
533
- }
534
- window.addEventListener('message', cb, false);
535
-
536
- // Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. CSS gates on JSON feature check, Wasm instance phase gates on wasm source phase check.
537
- const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
538
- supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
539
- };sp=${
540
- supportsImportMaps && wasmSourcePhaseEnabled ?
541
- `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
542
- : 'false'
543
- };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
544
- supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
545
- },sp,${
546
- supportsImportMaps && wasmInstancePhaseEnabled ?
547
- `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
548
- : 'false'
549
- }]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
550
-
551
- // Safari will call onload eagerly on head injection, but we don't want the Wechat
552
- // path to trigger before setting srcdoc, therefore we track the timing
553
- let readyForOnload = false,
554
- onloadCalledWhileNotReady = false;
555
- function doOnload() {
556
- if (!readyForOnload) {
557
- onloadCalledWhileNotReady = true;
558
- return;
559
- }
560
- // WeChat browser doesn't support setting srcdoc scripts
561
- // But iframe sandboxes don't support contentDocument so we do this as a fallback
562
- const doc = iframe.contentDocument;
563
- if (doc && doc.head.childNodes.length === 0) {
564
- const s = doc.createElement('script');
565
- if (nonce) s.setAttribute('nonce', nonce);
566
- s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
567
- doc.head.appendChild(s);
568
- }
569
- }
570
-
571
- iframe.onload = doOnload;
572
- // WeChat browser requires append before setting srcdoc
573
- document.head.appendChild(iframe);
574
-
575
- // setting srcdoc is not supported in React native webviews on iOS
576
- // setting src to a blob URL results in a navigation event in webviews
577
- // document.write gives usability warnings
578
- readyForOnload = true;
579
- if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
580
- else iframe.contentDocument.write(importMapTest);
581
- // retrigger onload for Safari only if necessary
582
- if (onloadCalledWhileNotReady) doOnload();
583
- });
478
+ // support browsers without dynamic import support (eg Firefox 6x)
479
+ let supportsJsonType = false;
480
+ let supportsCssType = false;
481
+
482
+ const supports = hasDocument && HTMLScriptElement.supports;
483
+
484
+ let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
485
+ let supportsWasmInstancePhase = false;
486
+ let supportsWasmSourcePhase = false;
487
+ let supportsMultipleImportMaps = false;
488
+
489
+ const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
490
+
491
+ let featureDetectionPromise = (async function () {
492
+ if (!hasDocument)
493
+ return Promise.all([
494
+ import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
495
+ () => (
496
+ (supportsJsonType = true),
497
+ import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
498
+ () => (supportsCssType = true),
499
+ noop
500
+ )
501
+ ),
502
+ noop
503
+ ),
504
+ wasmInstancePhaseEnabled &&
505
+ import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
506
+ () => (supportsWasmInstancePhase = true),
507
+ noop
508
+ ),
509
+ wasmSourcePhaseEnabled &&
510
+ import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
511
+ () => (supportsWasmSourcePhase = true),
512
+ noop
513
+ )
514
+ ]);
515
+
516
+ const msgTag = `s${version}`;
517
+ return new Promise(resolve => {
518
+ const iframe = document.createElement('iframe');
519
+ iframe.style.display = 'none';
520
+ iframe.setAttribute('nonce', nonce);
521
+ function cb({ data }) {
522
+ const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
523
+ if (!isFeatureDetectionMessage) return;
524
+ [
525
+ ,
526
+ supportsImportMaps,
527
+ supportsMultipleImportMaps,
528
+ supportsJsonType,
529
+ supportsCssType,
530
+ supportsWasmSourcePhase,
531
+ supportsWasmInstancePhase
532
+ ] = data;
533
+ resolve();
534
+ document.head.removeChild(iframe);
535
+ window.removeEventListener('message', cb, false);
536
+ }
537
+ window.addEventListener('message', cb, false);
538
+
539
+ // Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. CSS gates on JSON feature check, Wasm instance phase gates on wasm source phase check.
540
+ const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
541
+ supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
542
+ };sp=${
543
+ supportsImportMaps && wasmSourcePhaseEnabled ?
544
+ `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
545
+ : 'false'
546
+ };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
547
+ supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
548
+ },sp,${
549
+ supportsImportMaps && wasmInstancePhaseEnabled ?
550
+ `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
551
+ : 'false'
552
+ }]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
553
+
554
+ // Safari will call onload eagerly on head injection, but we don't want the Wechat
555
+ // path to trigger before setting srcdoc, therefore we track the timing
556
+ let readyForOnload = false,
557
+ onloadCalledWhileNotReady = false;
558
+ function doOnload() {
559
+ if (!readyForOnload) {
560
+ onloadCalledWhileNotReady = true;
561
+ return;
562
+ }
563
+ // WeChat browser doesn't support setting srcdoc scripts
564
+ // But iframe sandboxes don't support contentDocument so we do this as a fallback
565
+ const doc = iframe.contentDocument;
566
+ if (doc && doc.head.childNodes.length === 0) {
567
+ const s = doc.createElement('script');
568
+ if (nonce) s.setAttribute('nonce', nonce);
569
+ s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
570
+ doc.head.appendChild(s);
571
+ }
572
+ }
573
+
574
+ iframe.onload = doOnload;
575
+ // WeChat browser requires append before setting srcdoc
576
+ document.head.appendChild(iframe);
577
+
578
+ // setting srcdoc is not supported in React native webviews on iOS
579
+ // setting src to a blob URL results in a navigation event in webviews
580
+ // document.write gives usability warnings
581
+ readyForOnload = true;
582
+ if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
583
+ else iframe.contentDocument.write(importMapTest);
584
+ // retrigger onload for Safari only if necessary
585
+ if (onloadCalledWhileNotReady) doOnload();
586
+ });
584
587
  })();
585
588
 
586
589
  /* es-module-lexer 1.7.0 */
@@ -819,7 +822,8 @@
819
822
  // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
820
823
  // because we can't syntactically pass through to dynamic import with a second argument
821
824
  if (sourceType === 'css' || sourceType === 'json') {
822
- source = `export{default}from'${url}'with{type:"${sourceType}"}`;
825
+ // Direct reexport for hot reloading skipped due to Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1965620
826
+ source = `import m from'${url}'with{type:"${sourceType}"};export default m;`;
823
827
  url += '?entry';
824
828
  }
825
829
 
@@ -1120,7 +1124,11 @@
1120
1124
  s += `if(h)h.accept(m=>({${obj}}=m))`;
1121
1125
  return { r, s, t: 'wasm' };
1122
1126
  } else if (jsonContentType.test(contentType))
1123
- return { r, s: `${hotPrefix}j=${await res.text()};export{j as default};if(h)h.accept(m=>j=m.default)`, t: 'json' };
1127
+ return {
1128
+ r,
1129
+ s: `${hotPrefix}j=${await res.text()};export{j as default};if(h)h.accept(m=>j=m.default)`,
1130
+ t: 'json'
1131
+ };
1124
1132
  else if (cssContentType.test(contentType)) {
1125
1133
  return {
1126
1134
  r,