@module-federation/bridge-vue3 0.0.0-next-20241106033302 → 0.0.0-next-20241106104434

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,30 +1,33 @@
1
- import * as G from "vue";
2
- import { defineComponent as V, ref as R, watch as W, onMounted as U, onBeforeUnmount as x, createVNode as k, defineAsyncComponent as z, h as T } from "vue";
3
- import * as h from "vue-router";
4
- import { useRoute as B } from "vue-router";
5
- var O = Object.defineProperty, H = Object.getOwnPropertyDescriptor, J = Object.getOwnPropertyNames, K = Object.prototype.hasOwnProperty, X = (e, o) => {
6
- for (var r in o)
7
- O(e, r, { get: o[r], enumerable: !0 });
8
- }, Y = (e, o, r, t) => {
9
- if (o && typeof o == "object" || typeof o == "function")
10
- for (let n of J(o))
11
- !K.call(e, n) && n !== r && O(e, n, { get: () => o[n], enumerable: !(t = H(o, n)) || t.enumerable });
12
- return e;
13
- }, q = (e) => Y(O({}, "__esModule", { value: !0 }), e), I = {};
14
- X(I, {
15
- createLogger: () => N,
16
- logger: () => de
1
+ import * as Vue from "vue";
2
+ import { defineComponent, ref, watch, onMounted, onBeforeUnmount, createVNode, defineAsyncComponent, h } from "vue";
3
+ import * as VueRouter from "vue-router";
4
+ import { useRoute } from "vue-router";
5
+ var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __hasOwnProp = Object.prototype.hasOwnProperty, __export = (o, t) => {
6
+ for (var n in t)
7
+ __defProp(o, n, { get: t[n], enumerable: !0 });
8
+ }, __copyProps = (o, t, n, r) => {
9
+ if (t && typeof t == "object" || typeof t == "function")
10
+ for (let s of __getOwnPropNames(t))
11
+ !__hasOwnProp.call(o, s) && s !== n && __defProp(o, s, { get: () => t[s], enumerable: !(r = __getOwnPropDesc(t, s)) || r.enumerable });
12
+ return o;
13
+ }, __toCommonJS = (o) => __copyProps(__defProp({}, "__esModule", { value: !0 }), o), browser_exports = {};
14
+ __export(browser_exports, {
15
+ createLogger: () => createLogger2,
16
+ logger: () => logger$1
17
17
  });
18
- var Q = q(I), E = void 0, D = () => {
19
- if (typeof E < "u")
20
- return E;
18
+ var browser = __toCommonJS(browser_exports), supportsSubstitutions = void 0, supportColor = () => {
19
+ if (typeof supportsSubstitutions < "u")
20
+ return supportsSubstitutions;
21
21
  try {
22
- console.log("%c", "color:"), E = !0;
22
+ const o = "color test", t = "color: red;", n = console.log;
23
+ console.log = (...r) => {
24
+ r[0] === `%c${o}` && r[1] === t && (supportsSubstitutions = !0);
25
+ }, console.log(`%c${o}`, t), console.log = n;
23
26
  } catch {
24
- E = !1;
27
+ supportsSubstitutions = !1;
25
28
  }
26
- return E;
27
- }, _ = {
29
+ return supportsSubstitutions;
30
+ }, ansiToCss = {
28
31
  bold: "font-weight: bold;",
29
32
  red: "color: red;",
30
33
  green: "color: green;",
@@ -32,117 +35,117 @@ var Q = q(I), E = void 0, D = () => {
32
35
  dodgerblue: "color: dodgerblue;",
33
36
  magenta: "color: magenta;",
34
37
  gray: "color: gray;"
35
- }, f = (e) => D() ? (o) => {
36
- if (Array.isArray(o)) {
37
- const [r, t] = o;
38
- return [`%c${r.replace("%c", "")}`, t ? `${_[e]}${t}` : `${_[e] || ""}`];
39
- }
40
- return [`%c${String(o).replace("%c", "")}`, _[e] || ""];
41
- } : (o) => [String(o)], Z = f("bold"), ee = f("red"), C = f("green"), oe = f("orange"), L = f("dodgerblue"), re = f("magenta");
42
- f("gray");
43
- function te(e, o, r) {
44
- let t = [""];
45
- return "label" in o && (t = [r[e] || o.label || ""], t = Z(o.color ? o.color(t) : t[0])), t = t.filter(Boolean), t;
46
- }
47
- function ne(e, o, r, t) {
48
- e.length ? Array.isArray(t) ? console.log(...e, ...t) : console.log(...e, o) : Array.isArray(t) ? console.log(...t) : console.log(o, ...r);
49
- }
50
- var P = {
38
+ }, formatter = (o) => supportColor() ? (t) => {
39
+ if (Array.isArray(t)) {
40
+ const [n, r] = t;
41
+ return [`%c${n.replace("%c", "")}`, r ? `${ansiToCss[o]}${r}` : `${ansiToCss[o] || ""}`];
42
+ }
43
+ return [`%c${String(t).replace("%c", "")}`, ansiToCss[o] || ""];
44
+ } : (t) => [String(t)], bold = formatter("bold"), red = formatter("red"), green = formatter("green"), orange = formatter("orange"), dodgerblue = formatter("dodgerblue"), magenta = formatter("magenta");
45
+ formatter("gray");
46
+ function getLabel(o, t, n) {
47
+ let r = [""];
48
+ return "label" in t && (r = [n[o] || t.label || ""], r = bold(t.color ? t.color(r) : r[0])), r = r.filter(Boolean), r;
49
+ }
50
+ function finalLog(o, t, n, r) {
51
+ o.length ? Array.isArray(r) ? console.log(...o, ...r) : console.log(...o, t) : Array.isArray(r) ? console.log(...r) : console.log(t, ...n);
52
+ }
53
+ var LOG_LEVEL = {
51
54
  error: 0,
52
55
  warn: 1,
53
56
  info: 2,
54
57
  log: 3,
55
58
  verbose: 4
56
- }, ae = /at\s.*:\d+:\d+[\s\)]*$/, le = /at\s.*\(<anonymous>\)$/, ce = (e) => ae.test(e) || le.test(e), se = (e = {}, { getLabel: o, handleError: r, finalLog: t, greet: n, LOG_TYPES: c }) => {
57
- let l = e.level || "log", a = e.labels || {}, i = (s, u, ...j) => {
58
- if (P[c[s].level] > P[l])
59
+ }, errorStackRegExp = /at\s.*:\d+:\d+[\s\)]*$/, anonymousErrorStackRegExp = /at\s.*\(<anonymous>\)$/, isErrorStackMessage = (o) => errorStackRegExp.test(o) || anonymousErrorStackRegExp.test(o), createLogger$1 = (o = {}, { getLabel: t, handleError: n, finalLog: r, greet: s, LOG_TYPES: l }) => {
60
+ let a = o.level || "log", i = o.labels || {}, c = (d, p, ...m) => {
61
+ if (LOG_LEVEL[l[d].level] > LOG_LEVEL[a])
59
62
  return;
60
- if (u == null)
63
+ if (p == null)
61
64
  return console.log();
62
- let $ = c[s], v = "";
63
- const F = o(s, $, a);
64
- if (u instanceof Error)
65
- if (u.stack) {
66
- let [b, ...y] = u.stack.split(`
65
+ let y = l[d], g = "";
66
+ const R = t(d, y, i);
67
+ if (p instanceof Error)
68
+ if (p.stack) {
69
+ let [_, ...E] = p.stack.split(`
67
70
  `);
68
- b.startsWith("Error: ") && (b = b.slice(7)), v = `${b}
69
- ${r(y.join(`
71
+ _.startsWith("Error: ") && (_ = _.slice(7)), g = `${_}
72
+ ${n(E.join(`
70
73
  `))}`;
71
74
  } else
72
- v = u.message;
75
+ g = p.message;
73
76
  else
74
- $.level === "error" && typeof u == "string" ? v = u.split(`
75
- `).map((y) => ce(y) ? r(y) : y).join(`
76
- `) : v = `${u}`;
77
- t(F, v, j, u);
78
- }, d = {
77
+ y.level === "error" && typeof p == "string" ? g = p.split(`
78
+ `).map((E) => isErrorStackMessage(E) ? n(E) : E).join(`
79
+ `) : g = `${p}`;
80
+ r(R, g, m, p);
81
+ }, u = {
79
82
  // greet
80
- greet: (s) => i("log", n(s))
83
+ greet: (d) => c("log", s(d))
81
84
  };
82
- return Object.keys(c).forEach((s) => {
83
- d[s] = (...u) => i(s, ...u);
84
- }), Object.defineProperty(d, "level", {
85
- get: () => l,
86
- set(s) {
87
- l = s;
88
- }
89
- }), Object.defineProperty(d, "labels", {
85
+ return Object.keys(l).forEach((d) => {
86
+ u[d] = (...p) => c(d, ...p);
87
+ }), Object.defineProperty(u, "level", {
90
88
  get: () => a,
91
- set(s) {
92
- a = s;
93
- }
94
- }), d.override = (s) => {
95
- Object.assign(d, s);
96
- }, d;
97
- }, m = [189, 255, 243], w = [74, 194, 154], S = (e) => !/[\s\n]/.test(e);
98
- function A(e) {
99
- if (!D())
100
- return [e];
101
- const o = [...e], r = o.filter(S), t = r.length - 1;
102
- if (t === 0)
103
- return console.log(`%c${e}`, `color: rgb(${m.join(",")}); font-weight: bold;`), [e];
104
- let n = "", c = [];
105
- return o.forEach((l) => {
106
- if (S(l)) {
107
- const a = r.indexOf(l) / t, i = Math.round(m[0] + (w[0] - m[0]) * a), d = Math.round(m[1] + (w[1] - m[1]) * a), s = Math.round(m[2] + (w[2] - m[2]) * a);
108
- n += `%c${l}`, c.push(`color: rgb(${i},${d},${s}); font-weight: bold;`);
89
+ set(d) {
90
+ a = d;
91
+ }
92
+ }), Object.defineProperty(u, "labels", {
93
+ get: () => i,
94
+ set(d) {
95
+ i = d;
96
+ }
97
+ }), u.override = (d) => {
98
+ Object.assign(u, d);
99
+ }, u;
100
+ }, startColor = [189, 255, 243], endColor = [74, 194, 154], isWord = (o) => !/[\s\n]/.test(o);
101
+ function gradient(o) {
102
+ if (!supportColor())
103
+ return [o];
104
+ const t = [...o], n = t.filter(isWord), r = n.length - 1;
105
+ if (r === 0)
106
+ return console.log(`%c${o}`, `color: rgb(${startColor.join(",")}); font-weight: bold;`), [o];
107
+ let s = "", l = [];
108
+ return t.forEach((a) => {
109
+ if (isWord(a)) {
110
+ const i = n.indexOf(a) / r, c = Math.round(startColor[0] + (endColor[0] - startColor[0]) * i), u = Math.round(startColor[1] + (endColor[1] - startColor[1]) * i), d = Math.round(startColor[2] + (endColor[2] - startColor[2]) * i);
111
+ s += `%c${a}`, l.push(`color: rgb(${c},${u},${d}); font-weight: bold;`);
109
112
  } else
110
- n += l;
111
- }), [n, ...c];
113
+ s += a;
114
+ }), [s, ...l];
112
115
  }
113
- var ue = {
116
+ var LOG_TYPES = {
114
117
  // Level error
115
118
  error: {
116
119
  label: "error",
117
120
  level: "error",
118
- color: ee
121
+ color: red
119
122
  },
120
123
  // Level warn
121
124
  warn: {
122
125
  label: "warn",
123
126
  level: "warn",
124
- color: oe
127
+ color: orange
125
128
  },
126
129
  // Level info
127
130
  info: {
128
131
  label: "info",
129
132
  level: "info",
130
- color: L
133
+ color: dodgerblue
131
134
  },
132
135
  start: {
133
136
  label: "start",
134
137
  level: "info",
135
- color: L
138
+ color: dodgerblue
136
139
  },
137
140
  ready: {
138
141
  label: "ready",
139
142
  level: "info",
140
- color: C
143
+ color: green
141
144
  },
142
145
  success: {
143
146
  label: "success",
144
147
  level: "info",
145
- color: C
148
+ color: green
146
149
  },
147
150
  // Level log
148
151
  log: {
@@ -152,100 +155,2357 @@ var ue = {
152
155
  debug: {
153
156
  label: "debug",
154
157
  level: "verbose",
155
- color: re
158
+ color: magenta
156
159
  }
157
160
  };
158
- function N(e = {}) {
159
- return se(e, {
160
- handleError: (o) => o,
161
- getLabel: te,
162
- gradient: A,
163
- finalLog: ne,
164
- LOG_TYPES: ue,
165
- greet: (o) => A(o)
161
+ function createLogger2(o = {}) {
162
+ return createLogger$1(o, {
163
+ handleError: (t) => t,
164
+ getLabel,
165
+ gradient,
166
+ finalLog,
167
+ LOG_TYPES,
168
+ greet: (t) => gradient(t)
166
169
  });
167
170
  }
168
- var de = N();
169
- const ie = "FEDERATION_DEBUG", ge = "1";
170
- function me() {
171
+ var logger$1 = createLogger2();
172
+ function _extends$2() {
173
+ return _extends$2 = Object.assign || function(t) {
174
+ for (var n = 1; n < arguments.length; n++) {
175
+ var r = arguments[n];
176
+ for (var s in r)
177
+ Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
178
+ }
179
+ return t;
180
+ }, _extends$2.apply(this, arguments);
181
+ }
182
+ const MANIFEST_EXT = ".json", BROWSER_LOG_KEY = "FEDERATION_DEBUG", BROWSER_LOG_VALUE = "1", SEPARATOR = ":";
183
+ function isBrowserEnv() {
171
184
  return typeof window < "u";
172
185
  }
173
- function pe() {
186
+ function isBrowserDebug() {
174
187
  try {
175
- if (me() && window.localStorage)
176
- return localStorage.getItem(ie) === ge;
188
+ if (isBrowserEnv() && window.localStorage)
189
+ return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
177
190
  } catch {
178
191
  return !1;
179
192
  }
180
193
  return !1;
181
194
  }
182
- function fe() {
183
- return typeof process < "u" && process.env && process.env.FEDERATION_DEBUG ? !!process.env.FEDERATION_DEBUG : typeof FEDERATION_DEBUG < "u" && FEDERATION_DEBUG ? !0 : pe();
184
- }
185
- const p = "[ Module Federation ]";
186
- function ve(e) {
187
- fe() && (e.level = "verbose");
188
- }
189
- function be(e, o) {
190
- e.labels = {
191
- warn: `${o} Warn`,
192
- error: `${o} Error`,
193
- success: `${o} Success`,
194
- info: `${o} Info`,
195
- ready: `${o} Ready`,
196
- debug: `${o} Debug`
195
+ function isDebugMode() {
196
+ return typeof process < "u" && process.env && process.env.FEDERATION_DEBUG ? !!process.env.FEDERATION_DEBUG : typeof FEDERATION_DEBUG < "u" && FEDERATION_DEBUG ? !0 : isBrowserDebug();
197
+ }
198
+ const PREFIX = "[ Module Federation ]";
199
+ function setDebug(o) {
200
+ isDebugMode() && (o.level = "verbose");
201
+ }
202
+ function setPrefix(o, t) {
203
+ o.labels = {
204
+ warn: `${t} Warn`,
205
+ error: `${t} Error`,
206
+ success: `${t} Success`,
207
+ info: `${t} Info`,
208
+ ready: `${t} Ready`,
209
+ debug: `${t} Debug`
197
210
  };
198
211
  }
199
- function M(e) {
200
- const o = Q.createLogger({
212
+ function createLogger(o) {
213
+ const t = browser.createLogger({
201
214
  labels: {
202
- warn: `${p} Warn`,
203
- error: `${p} Error`,
204
- success: `${p} Success`,
205
- info: `${p} Info`,
206
- ready: `${p} Ready`,
207
- debug: `${p} Debug`
215
+ warn: `${PREFIX} Warn`,
216
+ error: `${PREFIX} Error`,
217
+ success: `${PREFIX} Success`,
218
+ info: `${PREFIX} Info`,
219
+ ready: `${PREFIX} Ready`,
220
+ debug: `${PREFIX} Debug`
208
221
  }
209
222
  });
210
- return ve(o), be(o, e), o;
223
+ return setDebug(t), setPrefix(t, o), t;
224
+ }
225
+ createLogger(PREFIX);
226
+ const LOG_CATEGORY$1 = "[ Federation Runtime ]", composeKeyWithSeparator = function(...o) {
227
+ return o.length ? o.reduce((t, n) => n ? t ? `${t}${SEPARATOR}${n}` : n : t, "") : "";
228
+ }, getResourceUrl = (o, t) => {
229
+ if ("getPublicPath" in o) {
230
+ let n;
231
+ return o.getPublicPath.startsWith("function") ? n = new Function("return " + o.getPublicPath)()() : n = new Function(o.getPublicPath)(), `${n}${t}`;
232
+ } else
233
+ return "publicPath" in o ? `${o.publicPath}${t}` : (console.warn("Cannot get resource URL. If in debug mode, please ignore.", o, t), "");
234
+ }, warn$1 = (o) => {
235
+ console.warn(`${LOG_CATEGORY$1}: ${o}`);
236
+ };
237
+ function safeToString(o) {
238
+ try {
239
+ return JSON.stringify(o, null, 2);
240
+ } catch {
241
+ return "";
242
+ }
243
+ }
244
+ const simpleJoinRemoteEntry = (o, t) => {
245
+ if (!o)
246
+ return t;
247
+ const r = ((s) => {
248
+ if (s === ".")
249
+ return "";
250
+ if (s.startsWith("./"))
251
+ return s.replace("./", "");
252
+ if (s.startsWith("/")) {
253
+ const l = s.slice(1);
254
+ return l.endsWith("/") ? l.slice(0, -1) : l;
255
+ }
256
+ return s;
257
+ })(o);
258
+ return r ? r.endsWith("/") ? `${r}${t}` : `${r}/${t}` : t;
259
+ };
260
+ function inferAutoPublicPath(o) {
261
+ return o.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
211
262
  }
212
- M(p);
213
- const g = M("[ Module Federation Bridge Vue3 ]");
214
- function _e(e) {
215
- const o = /* @__PURE__ */ new Map();
216
- return () => ({
263
+ function generateSnapshotFromManifest(o, t = {}) {
264
+ var n, r;
265
+ const { remotes: s = {}, overrides: l = {}, version: a } = t;
266
+ let i;
267
+ const c = () => "publicPath" in o.metaData ? o.metaData.publicPath === "auto" && a ? inferAutoPublicPath(a) : o.metaData.publicPath : o.metaData.getPublicPath, u = Object.keys(l);
268
+ let d = {};
269
+ if (!Object.keys(s).length) {
270
+ var p;
271
+ d = ((p = o.remotes) == null ? void 0 : p.reduce((b, I) => {
272
+ let w;
273
+ const O = I.federationContainerName;
274
+ return u.includes(O) ? w = l[O] : "version" in I ? w = I.version : w = I.entry, b[O] = {
275
+ matchedVersion: w
276
+ }, b;
277
+ }, {})) || {};
278
+ }
279
+ Object.keys(s).forEach((b) => d[b] = {
280
+ // overrides will override dependencies
281
+ matchedVersion: u.includes(b) ? l[b] : s[b]
282
+ });
283
+ const { remoteEntry: { path: m, name: y, type: g }, types: R, buildInfo: { buildVersion: _ }, globalName: E, ssrRemoteEntry: $ } = o.metaData, { exposes: v } = o;
284
+ let S = {
285
+ version: a || "",
286
+ buildVersion: _,
287
+ globalName: E,
288
+ remoteEntry: simpleJoinRemoteEntry(m, y),
289
+ remoteEntryType: g,
290
+ remoteTypes: simpleJoinRemoteEntry(R.path, R.name),
291
+ remoteTypesZip: R.zip || "",
292
+ remoteTypesAPI: R.api || "",
293
+ remotesInfo: d,
294
+ shared: o == null ? void 0 : o.shared.map((b) => ({
295
+ assets: b.assets,
296
+ sharedName: b.name,
297
+ version: b.version
298
+ })),
299
+ modules: v == null ? void 0 : v.map((b) => ({
300
+ moduleName: b.name,
301
+ modulePath: b.path,
302
+ assets: b.assets
303
+ }))
304
+ };
305
+ if ((n = o.metaData) != null && n.prefetchInterface) {
306
+ const b = o.metaData.prefetchInterface;
307
+ S = _extends$2({}, S, {
308
+ prefetchInterface: b
309
+ });
310
+ }
311
+ if ((r = o.metaData) != null && r.prefetchEntry) {
312
+ const { path: b, name: I, type: w } = o.metaData.prefetchEntry;
313
+ S = _extends$2({}, S, {
314
+ prefetchEntry: simpleJoinRemoteEntry(b, I),
315
+ prefetchEntryType: w
316
+ });
317
+ }
318
+ if ("publicPath" in o.metaData ? i = _extends$2({}, S, {
319
+ publicPath: c()
320
+ }) : i = _extends$2({}, S, {
321
+ getPublicPath: c()
322
+ }), $) {
323
+ const b = simpleJoinRemoteEntry($.path, $.name);
324
+ i.ssrRemoteEntry = b, i.ssrRemoteEntryType = $.type || "commonjs-module";
325
+ }
326
+ return i;
327
+ }
328
+ function isManifestProvider(o) {
329
+ return !!("remoteEntry" in o && o.remoteEntry.includes(MANIFEST_EXT));
330
+ }
331
+ async function safeWrapper(o, t) {
332
+ try {
333
+ return await o();
334
+ } catch (n) {
335
+ warn$1(n);
336
+ return;
337
+ }
338
+ }
339
+ function isStaticResourcesEqual(o, t) {
340
+ const n = /^(https?:)?\/\//i, r = o.replace(n, "").replace(/\/$/, ""), s = t.replace(n, "").replace(/\/$/, "");
341
+ return r === s;
342
+ }
343
+ function createScript(o) {
344
+ let t = null, n = !0, r = 2e4, s;
345
+ const l = document.getElementsByTagName("script");
346
+ for (let i = 0; i < l.length; i++) {
347
+ const c = l[i], u = c.getAttribute("src");
348
+ if (u && isStaticResourcesEqual(u, o.url)) {
349
+ t = c, n = !1;
350
+ break;
351
+ }
352
+ }
353
+ if (!t) {
354
+ const i = o.attrs;
355
+ t = document.createElement("script"), t.type = (i == null ? void 0 : i.type) === "module" ? "module" : "text/javascript";
356
+ let c;
357
+ o.createScriptHook && (c = o.createScriptHook(o.url, o.attrs), c instanceof HTMLScriptElement ? t = c : typeof c == "object" && ("script" in c && c.script && (t = c.script), "timeout" in c && c.timeout && (r = c.timeout))), t.src || (t.src = o.url), i && !c && Object.keys(i).forEach((u) => {
358
+ t && (u === "async" || u === "defer" ? t[u] = i[u] : t.getAttribute(u) || t.setAttribute(u, i[u]));
359
+ });
360
+ }
361
+ const a = async (i, c) => {
362
+ var u;
363
+ if (clearTimeout(s), t && (t.onerror = null, t.onload = null, safeWrapper(() => {
364
+ const { needDeleteScript: m = !0 } = o;
365
+ m && t != null && t.parentNode && t.parentNode.removeChild(t);
366
+ }), i && typeof i == "function")) {
367
+ var d;
368
+ const m = i(c);
369
+ if (m instanceof Promise) {
370
+ var p;
371
+ const y = await m;
372
+ return o == null || (p = o.cb) == null || p.call(o), y;
373
+ }
374
+ return o == null || (d = o.cb) == null || d.call(o), m;
375
+ }
376
+ o == null || (u = o.cb) == null || u.call(o);
377
+ };
378
+ return t.onerror = a.bind(null, t.onerror), t.onload = a.bind(null, t.onload), s = setTimeout(() => {
379
+ a(null, new Error(`Remote script "${o.url}" time-outed.`));
380
+ }, r), {
381
+ script: t,
382
+ needAttach: n
383
+ };
384
+ }
385
+ function createLink(o) {
386
+ let t = null, n = !0;
387
+ const r = document.getElementsByTagName("link");
388
+ for (let l = 0; l < r.length; l++) {
389
+ const a = r[l], i = a.getAttribute("href"), c = a.getAttribute("ref");
390
+ if (i && isStaticResourcesEqual(i, o.url) && c === o.attrs.ref) {
391
+ t = a, n = !1;
392
+ break;
393
+ }
394
+ }
395
+ if (!t) {
396
+ t = document.createElement("link"), t.setAttribute("href", o.url);
397
+ let l;
398
+ const a = o.attrs;
399
+ o.createLinkHook && (l = o.createLinkHook(o.url, a), l instanceof HTMLLinkElement && (t = l)), a && !l && Object.keys(a).forEach((i) => {
400
+ t && !t.getAttribute(i) && t.setAttribute(i, a[i]);
401
+ });
402
+ }
403
+ const s = (l, a) => {
404
+ if (t && (t.onerror = null, t.onload = null, safeWrapper(() => {
405
+ const { needDeleteLink: i = !0 } = o;
406
+ i && t != null && t.parentNode && t.parentNode.removeChild(t);
407
+ }), l)) {
408
+ const i = l(a);
409
+ return o.cb(), i;
410
+ }
411
+ o.cb();
412
+ };
413
+ return t.onerror = s.bind(null, t.onerror), t.onload = s.bind(null, t.onload), {
414
+ link: t,
415
+ needAttach: n
416
+ };
417
+ }
418
+ function loadScript(o, t) {
419
+ const { attrs: n = {}, createScriptHook: r } = t;
420
+ return new Promise((s, l) => {
421
+ const { script: a, needAttach: i } = createScript({
422
+ url: o,
423
+ cb: s,
424
+ attrs: _extends$2({
425
+ fetchpriority: "high"
426
+ }, n),
427
+ createScriptHook: r,
428
+ needDeleteScript: !0
429
+ });
430
+ i && document.head.appendChild(a);
431
+ });
432
+ }
433
+ function importNodeModule(o) {
434
+ if (!o)
435
+ throw new Error("import specifier is required");
436
+ return new Function("name", "return import(name)")(o).then((n) => n).catch((n) => {
437
+ throw console.error(`Error importing module ${o}:`, n), n;
438
+ });
439
+ }
440
+ const loadNodeFetch = async () => {
441
+ const o = await importNodeModule("node-fetch");
442
+ return o.default || o;
443
+ }, lazyLoaderHookFetch = async (o, t, n) => {
444
+ const s = await ((l, a) => n.lifecycle.fetch.emit(l, a))(o, t || {});
445
+ return !s || !(s instanceof Response) ? (typeof fetch > "u" ? await loadNodeFetch() : fetch)(o, t || {}) : s;
446
+ };
447
+ function createScriptNode(url, cb, attrs, loaderHook) {
448
+ if (loaderHook != null && loaderHook.createScriptHook) {
449
+ const o = loaderHook.createScriptHook(url);
450
+ o && typeof o == "object" && "url" in o && (url = o.url);
451
+ }
452
+ let urlObj;
453
+ try {
454
+ urlObj = new URL(url);
455
+ } catch (o) {
456
+ console.error("Error constructing URL:", o), cb(new Error(`Invalid URL: ${o}`));
457
+ return;
458
+ }
459
+ const getFetch = async () => loaderHook != null && loaderHook.fetch ? (o, t) => lazyLoaderHookFetch(o, t, loaderHook) : typeof fetch > "u" ? loadNodeFetch() : fetch, handleScriptFetch = async (f, urlObj) => {
460
+ try {
461
+ var _vm_constants;
462
+ const res = await f(urlObj.href), data = await res.text(), [path, vm] = await Promise.all([
463
+ importNodeModule("path"),
464
+ importNodeModule("vm")
465
+ ]), scriptContext = {
466
+ exports: {},
467
+ module: {
468
+ exports: {}
469
+ }
470
+ }, urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/"), filename = path.basename(urlObj.pathname);
471
+ var _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER;
472
+ const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}
473
+ })`, {
474
+ filename,
475
+ importModuleDynamically: (_vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER = (_vm_constants = vm.constants) == null ? void 0 : _vm_constants.USE_MAIN_CONTEXT_DEFAULT_LOADER) != null ? _vm_constants_USE_MAIN_CONTEXT_DEFAULT_LOADER : importNodeModule
476
+ });
477
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
478
+ const exportedInterface = scriptContext.module.exports || scriptContext.exports;
479
+ if (attrs && exportedInterface && attrs.globalName) {
480
+ const o = exportedInterface[attrs.globalName] || exportedInterface;
481
+ cb(void 0, o);
482
+ return;
483
+ }
484
+ cb(void 0, exportedInterface);
485
+ } catch (o) {
486
+ cb(o instanceof Error ? o : new Error(`Script execution error: ${o}`));
487
+ }
488
+ };
489
+ getFetch().then(async (o) => {
490
+ if ((attrs == null ? void 0 : attrs.type) === "esm" || (attrs == null ? void 0 : attrs.type) === "module")
491
+ return loadModule(urlObj.href, {
492
+ fetch: o,
493
+ vm: await importNodeModule("vm")
494
+ }).then(async (t) => {
495
+ await t.evaluate(), cb(void 0, t.namespace);
496
+ }).catch((t) => {
497
+ cb(t instanceof Error ? t : new Error(`Script execution error: ${t}`));
498
+ });
499
+ handleScriptFetch(o, urlObj);
500
+ }).catch((o) => {
501
+ cb(o);
502
+ });
503
+ }
504
+ function loadScriptNode(o, t) {
505
+ return new Promise((n, r) => {
506
+ createScriptNode(o, (s, l) => {
507
+ if (s)
508
+ r(s);
509
+ else {
510
+ var a, i;
511
+ const c = (t == null || (a = t.attrs) == null ? void 0 : a.globalName) || `__FEDERATION_${t == null || (i = t.attrs) == null ? void 0 : i.name}:custom__`, u = globalThis[c] = l;
512
+ n(u);
513
+ }
514
+ }, t.attrs, t.loaderHook);
515
+ });
516
+ }
517
+ async function loadModule(o, t) {
518
+ const { fetch: n, vm: r } = t, l = await (await n(o)).text(), a = new r.SourceTextModule(l, {
519
+ // @ts-ignore
520
+ importModuleDynamically: async (i, c) => {
521
+ const u = new URL(i, o).href;
522
+ return loadModule(u, t);
523
+ }
524
+ });
525
+ return await a.link(async (i) => {
526
+ const c = new URL(i, o).href;
527
+ return await loadModule(c, t);
528
+ }), a;
529
+ }
530
+ const LoggerInstance = createLogger("[ Module Federation Bridge Vue3 ]");
531
+ function createBridgeComponent(o) {
532
+ const t = /* @__PURE__ */ new Map();
533
+ return (n) => ({
217
534
  __APP_VERSION__: "0.7.0",
218
535
  render(r) {
219
- g.log("createBridgeComponent render Info", r);
220
- const t = G.createApp(e.rootComponent);
221
- o.set(r.dom, t);
222
- const n = e.appOptions({
536
+ var m, y;
537
+ LoggerInstance.log("createBridgeComponent render Info", r);
538
+ const s = Vue.createApp(o.rootComponent);
539
+ t.set(r.dom, s);
540
+ const l = (o == null ? void 0 : o.hooks) && (o == null ? void 0 : o.hooks.beforeBridgeRender) || ((m = n == null ? void 0 : n.hooks) == null ? void 0 : m.beforeBridgeRender), a = l && l(r), i = a && typeof a == "object" && (a != null && a.extraProps) ? a == null ? void 0 : a.extraProps : {}, c = o.appOptions({
223
541
  basename: r.basename,
224
- memoryRoute: r.memoryRoute
225
- }), c = r.memoryRoute ? h.createMemoryHistory(r.basename) : h.createWebHistory(r.basename), l = h.createRouter({
226
- ...n.router.options,
227
- history: c,
228
- routes: n.router.getRoutes()
542
+ memoryRoute: r.memoryRoute,
543
+ ...i
544
+ }), u = r.memoryRoute ? VueRouter.createMemoryHistory(r.basename) : VueRouter.createWebHistory(r.basename), d = VueRouter.createRouter({
545
+ ...c.router.options,
546
+ history: u,
547
+ routes: c.router.getRoutes()
229
548
  });
230
- g.log("createBridgeComponent render router info>>>", {
549
+ LoggerInstance.log("createBridgeComponent render router info>>>", {
231
550
  name: r.moduleName,
232
- router: l
233
- }), r.memoryRoute ? l.push(r.memoryRoute.entryPath).then(() => {
234
- t.use(l), t.mount(r.dom);
235
- }) : (t.use(l), t.mount(r.dom));
551
+ router: d
552
+ }), r.memoryRoute ? d.push(r.memoryRoute.entryPath).then(() => {
553
+ s.use(d), s.mount(r.dom);
554
+ }) : (s.use(d), s.mount(r.dom));
555
+ const p = (o == null ? void 0 : o.hooks) && (o == null ? void 0 : o.hooks.afterBridgeDestroy) || ((y = n == null ? void 0 : n.hooks) == null ? void 0 : y.afterBridgeRender);
556
+ p && p(r);
236
557
  },
237
558
  destroy(r) {
238
- g.log("createBridgeComponent destroy Info", r);
239
- const t = o.get(r == null ? void 0 : r.dom);
240
- t == null || t.unmount();
559
+ var i, c;
560
+ LoggerInstance.log("createBridgeComponent destroy Info", r);
561
+ const s = t.get(r == null ? void 0 : r.dom), l = (o == null ? void 0 : o.hooks) && (o == null ? void 0 : o.hooks.beforeBridgeDestroy) || ((i = n == null ? void 0 : n.hooks) == null ? void 0 : i.beforeBridgeDestroy);
562
+ l && l(r), s == null || s.unmount();
563
+ const a = (o == null ? void 0 : o.hooks) && (o == null ? void 0 : o.hooks.afterBridgeDestroy) || ((c = n == null ? void 0 : n.hooks) == null ? void 0 : c.afterBridgeDestroy);
564
+ a && a(r);
565
+ }
566
+ });
567
+ }
568
+ function e() {
569
+ const o = new PopStateEvent("popstate", { state: window.history.state });
570
+ window.dispatchEvent(o);
571
+ }
572
+ function _extends$1() {
573
+ return _extends$1 = Object.assign || function(t) {
574
+ for (var n = 1; n < arguments.length; n++) {
575
+ var r = arguments[n];
576
+ for (var s in r)
577
+ Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
578
+ }
579
+ return t;
580
+ }, _extends$1.apply(this, arguments);
581
+ }
582
+ function _object_without_properties_loose(o, t) {
583
+ if (o == null)
584
+ return {};
585
+ var n = {}, r = Object.keys(o), s, l;
586
+ for (l = 0; l < r.length; l++)
587
+ s = r[l], !(t.indexOf(s) >= 0) && (n[s] = o[s]);
588
+ return n;
589
+ }
590
+ const RUNTIME_001 = "RUNTIME-001", RUNTIME_002 = "RUNTIME-002", RUNTIME_003 = "RUNTIME-003", RUNTIME_004 = "RUNTIME-004", RUNTIME_005 = "RUNTIME-005", RUNTIME_006 = "RUNTIME-006", RUNTIME_007 = "RUNTIME-007", TYPE_001 = "TYPE-001", getDocsUrl = (o) => `https://module-federation.io/guide/troubleshooting/${o.split("-")[0].toLowerCase()}/${o}`, getShortErrorMsg = (o, t, n, r) => {
591
+ const s = [
592
+ `${[
593
+ t[o]
594
+ ]} #${o}`
595
+ ];
596
+ return n && s.push(`args: ${JSON.stringify(n)}`), s.push(getDocsUrl(o)), r && s.push(`Original Error Message:
597
+ ${r}`), s.join(`
598
+ `);
599
+ };
600
+ function _extends() {
601
+ return _extends = Object.assign || function(t) {
602
+ for (var n = 1; n < arguments.length; n++) {
603
+ var r = arguments[n];
604
+ for (var s in r)
605
+ Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
606
+ }
607
+ return t;
608
+ }, _extends.apply(this, arguments);
609
+ }
610
+ const runtimeDescMap = {
611
+ [RUNTIME_001]: "Failed to get remoteEntry exports.",
612
+ [RUNTIME_002]: 'The remote entry interface does not contain "init"',
613
+ [RUNTIME_003]: "Failed to get manifest.",
614
+ [RUNTIME_004]: "Failed to locate remote.",
615
+ [RUNTIME_005]: "Invalid loadShareSync function call from bundler runtime",
616
+ [RUNTIME_006]: "Invalid loadShareSync function call from runtime",
617
+ [RUNTIME_007]: "Failed to get remote snapshot."
618
+ }, typeDescMap = {
619
+ [TYPE_001]: "Failed to generate type declaration."
620
+ };
621
+ _extends({}, runtimeDescMap, typeDescMap);
622
+ function getBuilderId() {
623
+ return typeof FEDERATION_BUILD_IDENTIFIER < "u" ? FEDERATION_BUILD_IDENTIFIER : "";
624
+ }
625
+ const LOG_CATEGORY = "[ Federation Runtime ]", logger = createLogger(LOG_CATEGORY);
626
+ function assert(o, t) {
627
+ o || error(t);
628
+ }
629
+ function error(o) {
630
+ throw o instanceof Error ? (o.message = `${LOG_CATEGORY}: ${o.message}`, o) : new Error(`${LOG_CATEGORY}: ${o}`);
631
+ }
632
+ function warn(o) {
633
+ o instanceof Error && (o.message = `${LOG_CATEGORY}: ${o.message}`), logger.warn(o);
634
+ }
635
+ function addUniqueItem(o, t) {
636
+ return o.findIndex((n) => n === t) === -1 && o.push(t), o;
637
+ }
638
+ function getFMId(o) {
639
+ return "version" in o && o.version ? `${o.name}:${o.version}` : "entry" in o && o.entry ? `${o.name}:${o.entry}` : `${o.name}`;
640
+ }
641
+ function isRemoteInfoWithEntry(o) {
642
+ return typeof o.entry < "u";
643
+ }
644
+ function isPureRemoteEntry(o) {
645
+ return !o.entry.includes(".json") && o.entry.includes(".js");
646
+ }
647
+ function isObject(o) {
648
+ return o && typeof o == "object";
649
+ }
650
+ const objectToString = Object.prototype.toString;
651
+ function isPlainObject(o) {
652
+ return objectToString.call(o) === "[object Object]";
653
+ }
654
+ function arrayOptions(o) {
655
+ return Array.isArray(o) ? o : [
656
+ o
657
+ ];
658
+ }
659
+ function getRemoteEntryInfoFromSnapshot(o) {
660
+ const t = {
661
+ url: "",
662
+ type: "global",
663
+ globalName: ""
664
+ };
665
+ return isBrowserEnv() ? "remoteEntry" in o ? {
666
+ url: o.remoteEntry,
667
+ type: o.remoteEntryType,
668
+ globalName: o.globalName
669
+ } : t : "ssrRemoteEntry" in o ? {
670
+ url: o.ssrRemoteEntry || t.url,
671
+ type: o.ssrRemoteEntryType || t.type,
672
+ globalName: o.globalName
673
+ } : t;
674
+ }
675
+ const processModuleAlias = (o, t) => {
676
+ let n;
677
+ return o.endsWith("/") ? n = o.slice(0, -1) : n = o, t.startsWith(".") && (t = t.slice(1)), n = n + t, n;
678
+ }, CurrentGlobal = typeof globalThis == "object" ? globalThis : window, nativeGlobal = (() => {
679
+ try {
680
+ return document.defaultView;
681
+ } catch {
682
+ return CurrentGlobal;
683
+ }
684
+ })(), Global = nativeGlobal;
685
+ function definePropertyGlobalVal(o, t, n) {
686
+ Object.defineProperty(o, t, {
687
+ value: n,
688
+ configurable: !1,
689
+ writable: !0
690
+ });
691
+ }
692
+ function includeOwnProperty(o, t) {
693
+ return Object.hasOwnProperty.call(o, t);
694
+ }
695
+ includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__") || definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
696
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
697
+ function setGlobalDefaultVal(o) {
698
+ var t, n, r, s, l, a;
699
+ includeOwnProperty(o, "__VMOK__") && !includeOwnProperty(o, "__FEDERATION__") && definePropertyGlobalVal(o, "__FEDERATION__", o.__VMOK__), includeOwnProperty(o, "__FEDERATION__") || (definePropertyGlobalVal(o, "__FEDERATION__", {
700
+ __GLOBAL_PLUGIN__: [],
701
+ __INSTANCES__: [],
702
+ moduleInfo: {},
703
+ __SHARE__: {},
704
+ __MANIFEST_LOADING__: {},
705
+ __PRELOADED_MAP__: /* @__PURE__ */ new Map()
706
+ }), definePropertyGlobalVal(o, "__VMOK__", o.__FEDERATION__));
707
+ var i;
708
+ (i = (t = o.__FEDERATION__).__GLOBAL_PLUGIN__) != null || (t.__GLOBAL_PLUGIN__ = []);
709
+ var c;
710
+ (c = (n = o.__FEDERATION__).__INSTANCES__) != null || (n.__INSTANCES__ = []);
711
+ var u;
712
+ (u = (r = o.__FEDERATION__).moduleInfo) != null || (r.moduleInfo = {});
713
+ var d;
714
+ (d = (s = o.__FEDERATION__).__SHARE__) != null || (s.__SHARE__ = {});
715
+ var p;
716
+ (p = (l = o.__FEDERATION__).__MANIFEST_LOADING__) != null || (l.__MANIFEST_LOADING__ = {});
717
+ var m;
718
+ (m = (a = o.__FEDERATION__).__PRELOADED_MAP__) != null || (a.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
719
+ }
720
+ setGlobalDefaultVal(CurrentGlobal);
721
+ setGlobalDefaultVal(nativeGlobal);
722
+ function setGlobalFederationConstructor(o, t = isDebugMode()) {
723
+ t && (CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = o, CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.7.0");
724
+ }
725
+ function getInfoWithoutType(o, t) {
726
+ if (typeof t == "string") {
727
+ if (o[t])
728
+ return {
729
+ value: o[t],
730
+ key: t
731
+ };
732
+ {
733
+ const r = Object.keys(o);
734
+ for (const s of r) {
735
+ const [l, a] = s.split(":"), i = `${l}:${t}`, c = o[i];
736
+ if (c)
737
+ return {
738
+ value: c,
739
+ key: i
740
+ };
741
+ }
742
+ return {
743
+ value: void 0,
744
+ key: t
745
+ };
746
+ }
747
+ } else
748
+ throw new Error("key must be string");
749
+ }
750
+ const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo, getTargetSnapshotInfoByModuleInfo = (o, t) => {
751
+ const n = getFMId(o), r = getInfoWithoutType(t, n).value;
752
+ if (r && !r.version && "version" in o && o.version && (r.version = o.version), r)
753
+ return r;
754
+ if ("version" in o && o.version) {
755
+ const { version: s } = o, l = _object_without_properties_loose(o, [
756
+ "version"
757
+ ]), a = getFMId(l), i = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, a).value;
758
+ if ((i == null ? void 0 : i.version) === s)
759
+ return i;
760
+ }
761
+ }, getGlobalSnapshotInfoByModuleInfo = (o) => getTargetSnapshotInfoByModuleInfo(o, nativeGlobal.__FEDERATION__.moduleInfo), setGlobalSnapshotInfoByModuleInfo = (o, t) => {
762
+ const n = getFMId(o);
763
+ return nativeGlobal.__FEDERATION__.moduleInfo[n] = t, nativeGlobal.__FEDERATION__.moduleInfo;
764
+ }, addGlobalSnapshot = (o) => (nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, o), () => {
765
+ const t = Object.keys(o);
766
+ for (const n of t)
767
+ delete nativeGlobal.__FEDERATION__.moduleInfo[n];
768
+ }), getRemoteEntryExports = (o, t) => {
769
+ const n = t || `__FEDERATION_${o}:custom__`, r = CurrentGlobal[n];
770
+ return {
771
+ remoteEntryKey: n,
772
+ entryExports: r
773
+ };
774
+ }, getGlobalHostPlugins = () => nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__, getPreloaded = (o) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(o), setPreloaded = (o) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(o, !0);
775
+ function registerPlugins(o, t) {
776
+ const n = getGlobalHostPlugins();
777
+ return n.length > 0 && n.forEach((r) => {
778
+ o != null && o.find((s) => s.name !== r.name) && o.push(r);
779
+ }), o && o.length > 0 && o.forEach((r) => {
780
+ t.forEach((s) => {
781
+ s.applyPlugin(r);
782
+ });
783
+ }), o;
784
+ }
785
+ const DEFAULT_SCOPE = "default", DEFAULT_REMOTE_TYPE = "global";
786
+ class SyncHook {
787
+ on(t) {
788
+ typeof t == "function" && this.listeners.add(t);
789
+ }
790
+ once(t) {
791
+ const n = this;
792
+ this.on(function r(...s) {
793
+ return n.remove(r), t.apply(null, s);
794
+ });
795
+ }
796
+ emit(...t) {
797
+ let n;
798
+ return this.listeners.size > 0 && this.listeners.forEach((r) => {
799
+ n = r(...t);
800
+ }), n;
801
+ }
802
+ remove(t) {
803
+ this.listeners.delete(t);
804
+ }
805
+ removeAll() {
806
+ this.listeners.clear();
807
+ }
808
+ constructor(t) {
809
+ this.type = "", this.listeners = /* @__PURE__ */ new Set(), t && (this.type = t);
810
+ }
811
+ }
812
+ class AsyncHook extends SyncHook {
813
+ emit(...t) {
814
+ let n;
815
+ const r = Array.from(this.listeners);
816
+ if (r.length > 0) {
817
+ let s = 0;
818
+ const l = (a) => a === !1 ? !1 : s < r.length ? Promise.resolve(r[s++].apply(null, t)).then(l) : a;
819
+ n = l();
241
820
  }
821
+ return Promise.resolve(n);
822
+ }
823
+ }
824
+ function checkReturnData(o, t) {
825
+ if (!isObject(t))
826
+ return !1;
827
+ if (o !== t) {
828
+ for (const n in o)
829
+ if (!(n in t))
830
+ return !1;
831
+ }
832
+ return !0;
833
+ }
834
+ class SyncWaterfallHook extends SyncHook {
835
+ emit(t) {
836
+ isObject(t) || error(`The data for the "${this.type}" hook should be an object.`);
837
+ for (const n of this.listeners)
838
+ try {
839
+ const r = n(t);
840
+ if (checkReturnData(t, r))
841
+ t = r;
842
+ else {
843
+ this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
844
+ break;
845
+ }
846
+ } catch (r) {
847
+ warn(r), this.onerror(r);
848
+ }
849
+ return t;
850
+ }
851
+ constructor(t) {
852
+ super(), this.onerror = error, this.type = t;
853
+ }
854
+ }
855
+ class AsyncWaterfallHook extends SyncHook {
856
+ emit(t) {
857
+ isObject(t) || error(`The response data for the "${this.type}" hook must be an object.`);
858
+ const n = Array.from(this.listeners);
859
+ if (n.length > 0) {
860
+ let r = 0;
861
+ const s = (a) => (warn(a), this.onerror(a), t), l = (a) => {
862
+ if (checkReturnData(t, a)) {
863
+ if (t = a, r < n.length)
864
+ try {
865
+ return Promise.resolve(n[r++](t)).then(l, s);
866
+ } catch (i) {
867
+ return s(i);
868
+ }
869
+ } else
870
+ this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
871
+ return t;
872
+ };
873
+ return Promise.resolve(l(t));
874
+ }
875
+ return Promise.resolve(t);
876
+ }
877
+ constructor(t) {
878
+ super(), this.onerror = error, this.type = t;
879
+ }
880
+ }
881
+ class PluginSystem {
882
+ applyPlugin(t) {
883
+ assert(isPlainObject(t), "Plugin configuration is invalid.");
884
+ const n = t.name;
885
+ assert(n, "A name must be provided by the plugin."), this.registerPlugins[n] || (this.registerPlugins[n] = t, Object.keys(this.lifecycle).forEach((r) => {
886
+ const s = t[r];
887
+ s && this.lifecycle[r].on(s);
888
+ }));
889
+ }
890
+ removePlugin(t) {
891
+ assert(t, "A name is required.");
892
+ const n = this.registerPlugins[t];
893
+ assert(n, `The plugin "${t}" is not registered.`), Object.keys(n).forEach((r) => {
894
+ r !== "name" && this.lifecycle[r].remove(n[r]);
895
+ });
896
+ }
897
+ // eslint-disable-next-line @typescript-eslint/no-shadow
898
+ inherit({ lifecycle: t, registerPlugins: n }) {
899
+ Object.keys(t).forEach((r) => {
900
+ assert(!this.lifecycle[r], `The hook "${r}" has a conflict and cannot be inherited.`), this.lifecycle[r] = t[r];
901
+ }), Object.keys(n).forEach((r) => {
902
+ assert(!this.registerPlugins[r], `The plugin "${r}" has a conflict and cannot be inherited.`), this.applyPlugin(n[r]);
903
+ });
904
+ }
905
+ constructor(t) {
906
+ this.registerPlugins = {}, this.lifecycle = t, this.lifecycleKeys = Object.keys(t);
907
+ }
908
+ }
909
+ const buildIdentifier = "[0-9A-Za-z-]+", build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`, numericIdentifier = "0|[1-9]\\d*", numericIdentifierLoose = "[0-9]+", nonNumericIdentifier = "\\d*[a-zA-Z-][a-zA-Z0-9-]*", preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`, preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`, preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`, preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`, xRangeIdentifier = `${numericIdentifier}|x|X|\\*`, xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`, hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`, mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`, loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`, gtlt = "((?:<|>)?=?)", comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`, loneTilde = "(?:~>?)", tildeTrim = `(\\s*)${loneTilde}\\s+`, loneCaret = "(?:\\^)", caretTrim = `(\\s*)${loneCaret}\\s+`, star = "(<|>)?=?\\s*\\*", caret = `^${loneCaret}${xRangePlain}$`, mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`, fullPlain = `v?${mainVersion}${preRelease}?${build}?`, tilde = `^${loneTilde}${xRangePlain}$`, xRange = `^${gtlt}\\s*${xRangePlain}$`, comparator = `^${gtlt}\\s*(${fullPlain})$|^$`, gte0 = "^\\s*>=\\s*0.0.0\\s*$";
910
+ function parseRegex(o) {
911
+ return new RegExp(o);
912
+ }
913
+ function isXVersion(o) {
914
+ return !o || o.toLowerCase() === "x" || o === "*";
915
+ }
916
+ function pipe(...o) {
917
+ return (t) => o.reduce((n, r) => r(n), t);
918
+ }
919
+ function extractComparator(o) {
920
+ return o.match(parseRegex(comparator));
921
+ }
922
+ function combineVersion(o, t, n, r) {
923
+ const s = `${o}.${t}.${n}`;
924
+ return r ? `${s}-${r}` : s;
925
+ }
926
+ function parseHyphen(o) {
927
+ return o.replace(parseRegex(hyphenRange), (t, n, r, s, l, a, i, c, u, d, p, m) => (isXVersion(r) ? n = "" : isXVersion(s) ? n = `>=${r}.0.0` : isXVersion(l) ? n = `>=${r}.${s}.0` : n = `>=${n}`, isXVersion(u) ? c = "" : isXVersion(d) ? c = `<${Number(u) + 1}.0.0-0` : isXVersion(p) ? c = `<${u}.${Number(d) + 1}.0-0` : m ? c = `<=${u}.${d}.${p}-${m}` : c = `<=${c}`, `${n} ${c}`.trim()));
928
+ }
929
+ function parseComparatorTrim(o) {
930
+ return o.replace(parseRegex(comparatorTrim), "$1$2$3");
931
+ }
932
+ function parseTildeTrim(o) {
933
+ return o.replace(parseRegex(tildeTrim), "$1~");
934
+ }
935
+ function parseCaretTrim(o) {
936
+ return o.replace(parseRegex(caretTrim), "$1^");
937
+ }
938
+ function parseCarets(o) {
939
+ return o.trim().split(/\s+/).map((t) => t.replace(parseRegex(caret), (n, r, s, l, a) => isXVersion(r) ? "" : isXVersion(s) ? `>=${r}.0.0 <${Number(r) + 1}.0.0-0` : isXVersion(l) ? r === "0" ? `>=${r}.${s}.0 <${r}.${Number(s) + 1}.0-0` : `>=${r}.${s}.0 <${Number(r) + 1}.0.0-0` : a ? r === "0" ? s === "0" ? `>=${r}.${s}.${l}-${a} <${r}.${s}.${Number(l) + 1}-0` : `>=${r}.${s}.${l}-${a} <${r}.${Number(s) + 1}.0-0` : `>=${r}.${s}.${l}-${a} <${Number(r) + 1}.0.0-0` : r === "0" ? s === "0" ? `>=${r}.${s}.${l} <${r}.${s}.${Number(l) + 1}-0` : `>=${r}.${s}.${l} <${r}.${Number(s) + 1}.0-0` : `>=${r}.${s}.${l} <${Number(r) + 1}.0.0-0`)).join(" ");
940
+ }
941
+ function parseTildes(o) {
942
+ return o.trim().split(/\s+/).map((t) => t.replace(parseRegex(tilde), (n, r, s, l, a) => isXVersion(r) ? "" : isXVersion(s) ? `>=${r}.0.0 <${Number(r) + 1}.0.0-0` : isXVersion(l) ? `>=${r}.${s}.0 <${r}.${Number(s) + 1}.0-0` : a ? `>=${r}.${s}.${l}-${a} <${r}.${Number(s) + 1}.0-0` : `>=${r}.${s}.${l} <${r}.${Number(s) + 1}.0-0`)).join(" ");
943
+ }
944
+ function parseXRanges(o) {
945
+ return o.split(/\s+/).map((t) => t.trim().replace(parseRegex(xRange), (n, r, s, l, a, i) => {
946
+ const c = isXVersion(s), u = c || isXVersion(l), d = u || isXVersion(a);
947
+ return r === "=" && d && (r = ""), i = "", c ? r === ">" || r === "<" ? "<0.0.0-0" : "*" : r && d ? (u && (l = 0), a = 0, r === ">" ? (r = ">=", u ? (s = Number(s) + 1, l = 0, a = 0) : (l = Number(l) + 1, a = 0)) : r === "<=" && (r = "<", u ? s = Number(s) + 1 : l = Number(l) + 1), r === "<" && (i = "-0"), `${r + s}.${l}.${a}${i}`) : u ? `>=${s}.0.0${i} <${Number(s) + 1}.0.0-0` : d ? `>=${s}.${l}.0${i} <${s}.${Number(l) + 1}.0-0` : n;
948
+ })).join(" ");
949
+ }
950
+ function parseStar(o) {
951
+ return o.trim().replace(parseRegex(star), "");
952
+ }
953
+ function parseGTE0(o) {
954
+ return o.trim().replace(parseRegex(gte0), "");
955
+ }
956
+ function compareAtom(o, t) {
957
+ return o = Number(o) || o, t = Number(t) || t, o > t ? 1 : o === t ? 0 : -1;
958
+ }
959
+ function comparePreRelease(o, t) {
960
+ const { preRelease: n } = o, { preRelease: r } = t;
961
+ if (n === void 0 && r)
962
+ return 1;
963
+ if (n && r === void 0)
964
+ return -1;
965
+ if (n === void 0 && r === void 0)
966
+ return 0;
967
+ for (let s = 0, l = n.length; s <= l; s++) {
968
+ const a = n[s], i = r[s];
969
+ if (a !== i)
970
+ return a === void 0 && i === void 0 ? 0 : a ? i ? compareAtom(a, i) : -1 : 1;
971
+ }
972
+ return 0;
973
+ }
974
+ function compareVersion(o, t) {
975
+ return compareAtom(o.major, t.major) || compareAtom(o.minor, t.minor) || compareAtom(o.patch, t.patch) || comparePreRelease(o, t);
976
+ }
977
+ function eq(o, t) {
978
+ return o.version === t.version;
979
+ }
980
+ function compare(o, t) {
981
+ switch (o.operator) {
982
+ case "":
983
+ case "=":
984
+ return eq(o, t);
985
+ case ">":
986
+ return compareVersion(o, t) < 0;
987
+ case ">=":
988
+ return eq(o, t) || compareVersion(o, t) < 0;
989
+ case "<":
990
+ return compareVersion(o, t) > 0;
991
+ case "<=":
992
+ return eq(o, t) || compareVersion(o, t) > 0;
993
+ case void 0:
994
+ return !0;
995
+ default:
996
+ return !1;
997
+ }
998
+ }
999
+ function parseComparatorString(o) {
1000
+ return pipe(
1001
+ // handle caret
1002
+ // ^ --> * (any, kinda silly)
1003
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
1004
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
1005
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
1006
+ // ^1.2.3 --> >=1.2.3 <2.0.0-0
1007
+ // ^1.2.0 --> >=1.2.0 <2.0.0-0
1008
+ parseCarets,
1009
+ // handle tilde
1010
+ // ~, ~> --> * (any, kinda silly)
1011
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
1012
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
1013
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
1014
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
1015
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
1016
+ parseTildes,
1017
+ parseXRanges,
1018
+ parseStar
1019
+ )(o);
1020
+ }
1021
+ function parseRange(o) {
1022
+ return pipe(
1023
+ // handle hyphenRange
1024
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
1025
+ parseHyphen,
1026
+ // handle trim comparator
1027
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
1028
+ parseComparatorTrim,
1029
+ // handle trim tilde
1030
+ // `~ 1.2.3` => `~1.2.3`
1031
+ parseTildeTrim,
1032
+ // handle trim caret
1033
+ // `^ 1.2.3` => `^1.2.3`
1034
+ parseCaretTrim
1035
+ )(o.trim()).split(/\s+/).join(" ");
1036
+ }
1037
+ function satisfy(o, t) {
1038
+ if (!o)
1039
+ return !1;
1040
+ const s = parseRange(t).split(" ").map((m) => parseComparatorString(m)).join(" ").split(/\s+/).map((m) => parseGTE0(m)), l = extractComparator(o);
1041
+ if (!l)
1042
+ return !1;
1043
+ const [, a, , i, c, u, d] = l, p = {
1044
+ operator: a,
1045
+ version: combineVersion(i, c, u, d),
1046
+ major: i,
1047
+ minor: c,
1048
+ patch: u,
1049
+ preRelease: d == null ? void 0 : d.split(".")
1050
+ };
1051
+ for (const m of s) {
1052
+ const y = extractComparator(m);
1053
+ if (!y)
1054
+ return !1;
1055
+ const [, g, , R, _, E, $] = y, v = {
1056
+ operator: g,
1057
+ version: combineVersion(R, _, E, $),
1058
+ major: R,
1059
+ minor: _,
1060
+ patch: E,
1061
+ preRelease: $ == null ? void 0 : $.split(".")
1062
+ };
1063
+ if (!compare(v, p))
1064
+ return !1;
1065
+ }
1066
+ return !0;
1067
+ }
1068
+ function formatShare(o, t, n, r) {
1069
+ let s;
1070
+ "get" in o ? s = o.get : "lib" in o ? s = () => Promise.resolve(o.lib) : s = () => Promise.resolve(() => {
1071
+ throw new Error(`Can not get shared '${n}'!`);
1072
+ }), o.strategy && warn('"shared.strategy is deprecated, please set in initOptions.shareStrategy instead!"');
1073
+ var l, a, i;
1074
+ return _extends$1({
1075
+ deps: [],
1076
+ useIn: [],
1077
+ from: t,
1078
+ loading: null
1079
+ }, o, {
1080
+ shareConfig: _extends$1({
1081
+ requiredVersion: `^${o.version}`,
1082
+ singleton: !1,
1083
+ eager: !1,
1084
+ strictVersion: !1
1085
+ }, o.shareConfig),
1086
+ get: s,
1087
+ loaded: o != null && o.loaded || "lib" in o ? !0 : void 0,
1088
+ version: (l = o.version) != null ? l : "0",
1089
+ scope: Array.isArray(o.scope) ? o.scope : [
1090
+ (a = o.scope) != null ? a : "default"
1091
+ ],
1092
+ strategy: ((i = o.strategy) != null ? i : r) || "version-first"
242
1093
  });
243
1094
  }
244
- function ye() {
245
- const e = new PopStateEvent("popstate", { state: window.history.state });
246
- window.dispatchEvent(e);
1095
+ function formatShareConfigs(o, t) {
1096
+ const n = t.shared || {}, r = t.name, s = Object.keys(n).reduce((a, i) => {
1097
+ const c = arrayOptions(n[i]);
1098
+ return a[i] = a[i] || [], c.forEach((u) => {
1099
+ a[i].push(formatShare(u, r, i, t.shareStrategy));
1100
+ }), a;
1101
+ }, {}), l = _extends$1({}, o.shared);
1102
+ return Object.keys(s).forEach((a) => {
1103
+ l[a] ? s[a].forEach((i) => {
1104
+ l[a].find((u) => u.version === i.version) || l[a].push(i);
1105
+ }) : l[a] = s[a];
1106
+ }), {
1107
+ shared: l,
1108
+ shareInfos: s
1109
+ };
1110
+ }
1111
+ function versionLt(o, t) {
1112
+ const n = (r) => {
1113
+ if (!Number.isNaN(Number(r))) {
1114
+ const l = r.split(".");
1115
+ let a = r;
1116
+ for (let i = 0; i < 3 - l.length; i++)
1117
+ a += ".0";
1118
+ return a;
1119
+ }
1120
+ return r;
1121
+ };
1122
+ return !!satisfy(n(o), `<=${n(t)}`);
1123
+ }
1124
+ const findVersion = (o, t) => {
1125
+ const n = t || function(r, s) {
1126
+ return versionLt(r, s);
1127
+ };
1128
+ return Object.keys(o).reduce((r, s) => !r || n(r, s) || r === "0" ? s : r, 0);
1129
+ }, isLoaded = (o) => !!o.loaded || typeof o.lib == "function", isLoading = (o) => !!o.loading;
1130
+ function findSingletonVersionOrderByVersion(o, t, n) {
1131
+ const r = o[t][n], s = function(l, a) {
1132
+ return !isLoaded(r[l]) && versionLt(l, a);
1133
+ };
1134
+ return findVersion(o[t][n], s);
1135
+ }
1136
+ function findSingletonVersionOrderByLoaded(o, t, n) {
1137
+ const r = o[t][n], s = function(l, a) {
1138
+ const i = (c) => isLoaded(c) || isLoading(c);
1139
+ return i(r[a]) ? i(r[l]) ? !!versionLt(l, a) : !0 : i(r[l]) ? !1 : versionLt(l, a);
1140
+ };
1141
+ return findVersion(o[t][n], s);
1142
+ }
1143
+ function getFindShareFunction(o) {
1144
+ return o === "loaded-first" ? findSingletonVersionOrderByLoaded : findSingletonVersionOrderByVersion;
247
1145
  }
248
- const Ee = /* @__PURE__ */ V({
1146
+ function getRegisteredShare(o, t, n, r) {
1147
+ if (!o)
1148
+ return;
1149
+ const { shareConfig: s, scope: l = DEFAULT_SCOPE, strategy: a } = n, i = Array.isArray(l) ? l : [
1150
+ l
1151
+ ];
1152
+ for (const c of i)
1153
+ if (s && o[c] && o[c][t]) {
1154
+ const { requiredVersion: u } = s, p = getFindShareFunction(a)(o, c, t), m = () => {
1155
+ if (s.singleton) {
1156
+ if (typeof u == "string" && !satisfy(p, u)) {
1157
+ const R = `Version ${p} from ${p && o[c][t][p].from} of shared singleton module ${t} does not satisfy the requirement of ${n.from} which needs ${u})`;
1158
+ s.strictVersion ? error(R) : warn(R);
1159
+ }
1160
+ return o[c][t][p];
1161
+ } else {
1162
+ if (u === !1 || u === "*" || satisfy(p, u))
1163
+ return o[c][t][p];
1164
+ for (const [R, _] of Object.entries(o[c][t]))
1165
+ if (satisfy(R, u))
1166
+ return _;
1167
+ }
1168
+ }, y = {
1169
+ shareScopeMap: o,
1170
+ scope: c,
1171
+ pkgName: t,
1172
+ version: p,
1173
+ GlobalFederation: Global.__FEDERATION__,
1174
+ resolver: m
1175
+ };
1176
+ return (r.emit(y) || y).resolver();
1177
+ }
1178
+ }
1179
+ function getGlobalShareScope() {
1180
+ return Global.__FEDERATION__.__SHARE__;
1181
+ }
1182
+ function getTargetSharedOptions(o) {
1183
+ const { pkgName: t, extraOptions: n, shareInfos: r } = o, s = (i) => {
1184
+ if (!i)
1185
+ return;
1186
+ const c = {};
1187
+ i.forEach((p) => {
1188
+ c[p.version] = p;
1189
+ });
1190
+ const d = findVersion(c, function(p, m) {
1191
+ return !isLoaded(c[p]) && versionLt(p, m);
1192
+ });
1193
+ return c[d];
1194
+ };
1195
+ var l;
1196
+ const a = (l = n == null ? void 0 : n.resolver) != null ? l : s;
1197
+ return Object.assign({}, a(r[t]), n == null ? void 0 : n.customShareInfo);
1198
+ }
1199
+ function matchRemoteWithNameAndExpose(o, t) {
1200
+ for (const n of o) {
1201
+ const r = t.startsWith(n.name);
1202
+ let s = t.replace(n.name, "");
1203
+ if (r) {
1204
+ if (s.startsWith("/")) {
1205
+ const i = n.name;
1206
+ return s = `.${s}`, {
1207
+ pkgNameOrAlias: i,
1208
+ expose: s,
1209
+ remote: n
1210
+ };
1211
+ } else if (s === "")
1212
+ return {
1213
+ pkgNameOrAlias: n.name,
1214
+ expose: ".",
1215
+ remote: n
1216
+ };
1217
+ }
1218
+ const l = n.alias && t.startsWith(n.alias);
1219
+ let a = n.alias && t.replace(n.alias, "");
1220
+ if (n.alias && l) {
1221
+ if (a && a.startsWith("/")) {
1222
+ const i = n.alias;
1223
+ return a = `.${a}`, {
1224
+ pkgNameOrAlias: i,
1225
+ expose: a,
1226
+ remote: n
1227
+ };
1228
+ } else if (a === "")
1229
+ return {
1230
+ pkgNameOrAlias: n.alias,
1231
+ expose: ".",
1232
+ remote: n
1233
+ };
1234
+ }
1235
+ }
1236
+ }
1237
+ function matchRemote(o, t) {
1238
+ for (const n of o)
1239
+ if (t === n.name || n.alias && t === n.alias)
1240
+ return n;
1241
+ }
1242
+ async function loadEsmEntry({ entry: o, remoteEntryExports: t }) {
1243
+ return new Promise((n, r) => {
1244
+ try {
1245
+ t ? n(t) : import(
1246
+ /* webpackIgnore: true */
1247
+ o
1248
+ ).then(n).catch(r);
1249
+ } catch (s) {
1250
+ r(s);
1251
+ }
1252
+ });
1253
+ }
1254
+ async function loadSystemJsEntry({ entry: o, remoteEntryExports: t }) {
1255
+ return new Promise((n, r) => {
1256
+ try {
1257
+ t ? n(t) : typeof __system_context__ > "u" ? System.import(o).then(n).catch(r) : new Function("callbacks", `System.import("${o}").then(callbacks[0]).catch(callbacks[1])`)([
1258
+ n,
1259
+ r
1260
+ ]);
1261
+ } catch (s) {
1262
+ r(s);
1263
+ }
1264
+ });
1265
+ }
1266
+ async function loadEntryScript({ name: o, globalName: t, entry: n, loaderHook: r }) {
1267
+ const { entryExports: s } = getRemoteEntryExports(o, t);
1268
+ return s || loadScript(n, {
1269
+ attrs: {},
1270
+ createScriptHook: (l, a) => {
1271
+ const i = r.lifecycle.createScript.emit({
1272
+ url: l,
1273
+ attrs: a
1274
+ });
1275
+ if (i && (i instanceof HTMLScriptElement || "script" in i || "timeout" in i))
1276
+ return i;
1277
+ }
1278
+ }).then(() => {
1279
+ const { remoteEntryKey: l, entryExports: a } = getRemoteEntryExports(o, t);
1280
+ return assert(a, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
1281
+ remoteName: o,
1282
+ remoteEntryUrl: n,
1283
+ remoteEntryKey: l
1284
+ })), a;
1285
+ }).catch((l) => {
1286
+ throw l;
1287
+ });
1288
+ }
1289
+ async function loadEntryDom({ remoteInfo: o, remoteEntryExports: t, loaderHook: n }) {
1290
+ const { entry: r, entryGlobalName: s, name: l, type: a } = o;
1291
+ switch (a) {
1292
+ case "esm":
1293
+ case "module":
1294
+ return loadEsmEntry({
1295
+ entry: r,
1296
+ remoteEntryExports: t
1297
+ });
1298
+ case "system":
1299
+ return loadSystemJsEntry({
1300
+ entry: r,
1301
+ remoteEntryExports: t
1302
+ });
1303
+ default:
1304
+ return loadEntryScript({
1305
+ entry: r,
1306
+ globalName: s,
1307
+ name: l,
1308
+ loaderHook: n
1309
+ });
1310
+ }
1311
+ }
1312
+ async function loadEntryNode({ remoteInfo: o, loaderHook: t }) {
1313
+ const { entry: n, entryGlobalName: r, name: s, type: l } = o, { entryExports: a } = getRemoteEntryExports(s, r);
1314
+ return a || loadScriptNode(n, {
1315
+ attrs: {
1316
+ name: s,
1317
+ globalName: r,
1318
+ type: l
1319
+ },
1320
+ loaderHook: {
1321
+ createScriptHook: (i, c = {}) => {
1322
+ const u = t.lifecycle.createScript.emit({
1323
+ url: i,
1324
+ attrs: c
1325
+ });
1326
+ if (u && "url" in u)
1327
+ return u;
1328
+ }
1329
+ }
1330
+ }).then(() => {
1331
+ const { remoteEntryKey: i, entryExports: c } = getRemoteEntryExports(s, r);
1332
+ return assert(c, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
1333
+ remoteName: s,
1334
+ remoteEntryUrl: n,
1335
+ remoteEntryKey: i
1336
+ })), c;
1337
+ }).catch((i) => {
1338
+ throw i;
1339
+ });
1340
+ }
1341
+ function getRemoteEntryUniqueKey(o) {
1342
+ const { entry: t, name: n } = o;
1343
+ return composeKeyWithSeparator(n, t);
1344
+ }
1345
+ async function getRemoteEntry({ origin: o, remoteEntryExports: t, remoteInfo: n }) {
1346
+ const r = getRemoteEntryUniqueKey(n);
1347
+ if (t)
1348
+ return t;
1349
+ if (!globalLoading[r]) {
1350
+ const s = o.remoteHandler.hooks.lifecycle.loadEntry;
1351
+ o.loaderHook.lifecycle.createScript;
1352
+ const l = o.loaderHook;
1353
+ globalLoading[r] = s.emit({
1354
+ loaderHook: l,
1355
+ remoteInfo: n,
1356
+ remoteEntryExports: t
1357
+ }).then((a) => a || (isBrowserEnv() ? loadEntryDom({
1358
+ remoteInfo: n,
1359
+ remoteEntryExports: t,
1360
+ loaderHook: l
1361
+ }) : loadEntryNode({
1362
+ remoteInfo: n,
1363
+ loaderHook: l
1364
+ })));
1365
+ }
1366
+ return globalLoading[r];
1367
+ }
1368
+ function getRemoteInfo(o) {
1369
+ return _extends$1({}, o, {
1370
+ entry: "entry" in o ? o.entry : "",
1371
+ type: o.type || DEFAULT_REMOTE_TYPE,
1372
+ entryGlobalName: o.entryGlobalName || o.name,
1373
+ shareScope: o.shareScope || DEFAULT_SCOPE
1374
+ });
1375
+ }
1376
+ let Module = class {
1377
+ async getEntry() {
1378
+ if (this.remoteEntryExports)
1379
+ return this.remoteEntryExports;
1380
+ const t = await getRemoteEntry({
1381
+ origin: this.host,
1382
+ remoteInfo: this.remoteInfo,
1383
+ remoteEntryExports: this.remoteEntryExports
1384
+ });
1385
+ return assert(t, `remoteEntryExports is undefined
1386
+ ${safeToString(this.remoteInfo)}`), this.remoteEntryExports = t, this.remoteEntryExports;
1387
+ }
1388
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1389
+ async get(t, n, r, s) {
1390
+ const { loadFactory: l = !0 } = r || {
1391
+ loadFactory: !0
1392
+ }, a = await this.getEntry();
1393
+ if (!this.inited) {
1394
+ const p = this.host.shareScopeMap, m = this.remoteInfo.shareScope || "default";
1395
+ p[m] || (p[m] = {});
1396
+ const y = p[m], g = [], R = {
1397
+ version: this.remoteInfo.version || ""
1398
+ };
1399
+ Object.defineProperty(R, "shareScopeMap", {
1400
+ value: p,
1401
+ // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
1402
+ enumerable: !1
1403
+ });
1404
+ const _ = await this.host.hooks.lifecycle.beforeInitContainer.emit({
1405
+ shareScope: y,
1406
+ // @ts-ignore shareScopeMap will be set by Object.defineProperty
1407
+ remoteEntryInitOptions: R,
1408
+ initScope: g,
1409
+ remoteInfo: this.remoteInfo,
1410
+ origin: this.host
1411
+ });
1412
+ typeof (a == null ? void 0 : a.init) > "u" && error(getShortErrorMsg(RUNTIME_002, runtimeDescMap, {
1413
+ remoteName: name,
1414
+ remoteEntryUrl: this.remoteInfo.entry,
1415
+ remoteEntryKey: this.remoteInfo.entryGlobalName
1416
+ })), await a.init(_.shareScope, _.initScope, _.remoteEntryInitOptions), await this.host.hooks.lifecycle.initContainer.emit(_extends$1({}, _, {
1417
+ id: t,
1418
+ remoteSnapshot: s,
1419
+ remoteEntryExports: a
1420
+ }));
1421
+ }
1422
+ this.lib = a, this.inited = !0;
1423
+ let i;
1424
+ i = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
1425
+ remoteEntryExports: a,
1426
+ expose: n,
1427
+ moduleInfo: this.remoteInfo
1428
+ }), i || (i = await a.get(n)), assert(i, `${getFMId(this.remoteInfo)} remote don't export ${n}.`);
1429
+ const c = processModuleAlias(this.remoteInfo.name, n), u = this.wraperFactory(i, c);
1430
+ return l ? await u() : u;
1431
+ }
1432
+ wraperFactory(t, n) {
1433
+ function r(s, l) {
1434
+ s && typeof s == "object" && Object.isExtensible(s) && !Object.getOwnPropertyDescriptor(s, Symbol.for("mf_module_id")) && Object.defineProperty(s, Symbol.for("mf_module_id"), {
1435
+ value: l,
1436
+ enumerable: !1
1437
+ });
1438
+ }
1439
+ return t instanceof Promise ? async () => {
1440
+ const s = await t();
1441
+ return r(s, n), s;
1442
+ } : () => {
1443
+ const s = t();
1444
+ return r(s, n), s;
1445
+ };
1446
+ }
1447
+ constructor({ remoteInfo: t, host: n }) {
1448
+ this.inited = !1, this.lib = void 0, this.remoteInfo = t, this.host = n;
1449
+ }
1450
+ };
1451
+ function defaultPreloadArgs(o) {
1452
+ return _extends$1({
1453
+ resourceCategory: "sync",
1454
+ share: !0,
1455
+ depsRemote: !0,
1456
+ prefetchInterface: !1
1457
+ }, o);
1458
+ }
1459
+ function formatPreloadArgs(o, t) {
1460
+ return t.map((n) => {
1461
+ const r = matchRemote(o, n.nameOrAlias);
1462
+ return assert(r, `Unable to preload ${n.nameOrAlias} as it is not included in ${!r && safeToString({
1463
+ remoteInfo: r,
1464
+ remotes: o
1465
+ })}`), {
1466
+ remote: r,
1467
+ preloadConfig: defaultPreloadArgs(n)
1468
+ };
1469
+ });
1470
+ }
1471
+ function normalizePreloadExposes(o) {
1472
+ return o ? o.map((t) => t === "." ? t : t.startsWith("./") ? t.replace("./", "") : t) : [];
1473
+ }
1474
+ function preloadAssets(o, t, n, r = !0) {
1475
+ const { cssAssets: s, jsAssetsWithoutEntry: l, entryAssets: a } = n;
1476
+ if (t.options.inBrowser) {
1477
+ if (a.forEach((i) => {
1478
+ const { moduleInfo: c } = i, u = t.moduleCache.get(o.name);
1479
+ getRemoteEntry(u ? {
1480
+ origin: t,
1481
+ remoteInfo: c,
1482
+ remoteEntryExports: u.remoteEntryExports
1483
+ } : {
1484
+ origin: t,
1485
+ remoteInfo: c,
1486
+ remoteEntryExports: void 0
1487
+ });
1488
+ }), r) {
1489
+ const i = {
1490
+ rel: "preload",
1491
+ as: "style"
1492
+ };
1493
+ s.forEach((c) => {
1494
+ const { link: u, needAttach: d } = createLink({
1495
+ url: c,
1496
+ cb: () => {
1497
+ },
1498
+ attrs: i,
1499
+ createLinkHook: (p, m) => {
1500
+ const y = t.loaderHook.lifecycle.createLink.emit({
1501
+ url: p,
1502
+ attrs: m
1503
+ });
1504
+ if (y instanceof HTMLLinkElement)
1505
+ return y;
1506
+ }
1507
+ });
1508
+ d && document.head.appendChild(u);
1509
+ });
1510
+ } else {
1511
+ const i = {
1512
+ rel: "stylesheet",
1513
+ type: "text/css"
1514
+ };
1515
+ s.forEach((c) => {
1516
+ const { link: u, needAttach: d } = createLink({
1517
+ url: c,
1518
+ cb: () => {
1519
+ },
1520
+ attrs: i,
1521
+ createLinkHook: (p, m) => {
1522
+ const y = t.loaderHook.lifecycle.createLink.emit({
1523
+ url: p,
1524
+ attrs: m
1525
+ });
1526
+ if (y instanceof HTMLLinkElement)
1527
+ return y;
1528
+ },
1529
+ needDeleteLink: !1
1530
+ });
1531
+ d && document.head.appendChild(u);
1532
+ });
1533
+ }
1534
+ if (r) {
1535
+ const i = {
1536
+ rel: "preload",
1537
+ as: "script"
1538
+ };
1539
+ l.forEach((c) => {
1540
+ const { link: u, needAttach: d } = createLink({
1541
+ url: c,
1542
+ cb: () => {
1543
+ },
1544
+ attrs: i,
1545
+ createLinkHook: (p, m) => {
1546
+ const y = t.loaderHook.lifecycle.createLink.emit({
1547
+ url: p,
1548
+ attrs: m
1549
+ });
1550
+ if (y instanceof HTMLLinkElement)
1551
+ return y;
1552
+ }
1553
+ });
1554
+ d && document.head.appendChild(u);
1555
+ });
1556
+ } else {
1557
+ const i = {
1558
+ fetchpriority: "high",
1559
+ type: (o == null ? void 0 : o.type) === "module" ? "module" : "text/javascript"
1560
+ };
1561
+ l.forEach((c) => {
1562
+ const { script: u, needAttach: d } = createScript({
1563
+ url: c,
1564
+ cb: () => {
1565
+ },
1566
+ attrs: i,
1567
+ createScriptHook: (p, m) => {
1568
+ const y = t.loaderHook.lifecycle.createScript.emit({
1569
+ url: p,
1570
+ attrs: m
1571
+ });
1572
+ if (y instanceof HTMLScriptElement)
1573
+ return y;
1574
+ },
1575
+ needDeleteScript: !0
1576
+ });
1577
+ d && document.head.appendChild(u);
1578
+ });
1579
+ }
1580
+ }
1581
+ }
1582
+ function assignRemoteInfo(o, t) {
1583
+ const n = getRemoteEntryInfoFromSnapshot(t);
1584
+ n.url || error(`The attribute remoteEntry of ${o.name} must not be undefined.`);
1585
+ let r = getResourceUrl(t, n.url);
1586
+ !isBrowserEnv() && !r.startsWith("http") && (r = `https:${r}`), o.type = n.type, o.entryGlobalName = n.globalName, o.entry = r, o.version = t.version, o.buildVersion = t.buildVersion;
1587
+ }
1588
+ function snapshotPlugin() {
1589
+ return {
1590
+ name: "snapshot-plugin",
1591
+ async afterResolve(o) {
1592
+ const { remote: t, pkgNameOrAlias: n, expose: r, origin: s, remoteInfo: l } = o;
1593
+ if (!isRemoteInfoWithEntry(t) || !isPureRemoteEntry(t)) {
1594
+ const { remoteSnapshot: a, globalSnapshot: i } = await s.snapshotHandler.loadRemoteSnapshotInfo(t);
1595
+ assignRemoteInfo(l, a);
1596
+ const c = {
1597
+ remote: t,
1598
+ preloadConfig: {
1599
+ nameOrAlias: n,
1600
+ exposes: [
1601
+ r
1602
+ ],
1603
+ resourceCategory: "sync",
1604
+ share: !1,
1605
+ depsRemote: !1
1606
+ }
1607
+ }, u = await s.remoteHandler.hooks.lifecycle.generatePreloadAssets.emit({
1608
+ origin: s,
1609
+ preloadOptions: c,
1610
+ remoteInfo: l,
1611
+ remote: t,
1612
+ remoteSnapshot: a,
1613
+ globalSnapshot: i
1614
+ });
1615
+ return u && preloadAssets(l, s, u, !1), _extends$1({}, o, {
1616
+ remoteSnapshot: a
1617
+ });
1618
+ }
1619
+ return o;
1620
+ }
1621
+ };
1622
+ }
1623
+ function splitId(o) {
1624
+ const t = o.split(":");
1625
+ return t.length === 1 ? {
1626
+ name: t[0],
1627
+ version: void 0
1628
+ } : t.length === 2 ? {
1629
+ name: t[0],
1630
+ version: t[1]
1631
+ } : {
1632
+ name: t[1],
1633
+ version: t[2]
1634
+ };
1635
+ }
1636
+ function traverseModuleInfo(o, t, n, r, s = {}, l) {
1637
+ const a = getFMId(t), { value: i } = getInfoWithoutType(o, a), c = l || i;
1638
+ if (c && !isManifestProvider(c) && (n(c, t, r), c.remotesInfo)) {
1639
+ const u = Object.keys(c.remotesInfo);
1640
+ for (const d of u) {
1641
+ if (s[d])
1642
+ continue;
1643
+ s[d] = !0;
1644
+ const p = splitId(d), m = c.remotesInfo[d];
1645
+ traverseModuleInfo(o, {
1646
+ name: p.name,
1647
+ version: m.matchedVersion
1648
+ }, n, !1, s, void 0);
1649
+ }
1650
+ }
1651
+ }
1652
+ function generatePreloadAssets(o, t, n, r, s) {
1653
+ const l = [], a = [], i = [], c = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), { options: d } = o, { preloadConfig: p } = t, { depsRemote: m } = p;
1654
+ if (traverseModuleInfo(r, n, (_, E, $) => {
1655
+ let v;
1656
+ if ($)
1657
+ v = p;
1658
+ else if (Array.isArray(m)) {
1659
+ const T = m.find((A) => A.nameOrAlias === E.name || A.nameOrAlias === E.alias);
1660
+ if (!T)
1661
+ return;
1662
+ v = defaultPreloadArgs(T);
1663
+ } else if (m === !0)
1664
+ v = p;
1665
+ else
1666
+ return;
1667
+ const S = getResourceUrl(_, getRemoteEntryInfoFromSnapshot(_).url);
1668
+ S && i.push({
1669
+ name: E.name,
1670
+ moduleInfo: {
1671
+ name: E.name,
1672
+ entry: S,
1673
+ type: "remoteEntryType" in _ ? _.remoteEntryType : "global",
1674
+ entryGlobalName: "globalName" in _ ? _.globalName : E.name,
1675
+ shareScope: "",
1676
+ version: "version" in _ ? _.version : void 0
1677
+ },
1678
+ url: S
1679
+ });
1680
+ let b = "modules" in _ ? _.modules : [];
1681
+ const I = normalizePreloadExposes(v.exposes);
1682
+ if (I.length && "modules" in _) {
1683
+ var w;
1684
+ b = _ == null || (w = _.modules) == null ? void 0 : w.reduce((T, A) => ((I == null ? void 0 : I.indexOf(A.moduleName)) !== -1 && T.push(A), T), []);
1685
+ }
1686
+ function O(T) {
1687
+ const A = T.map((P) => getResourceUrl(_, P));
1688
+ return v.filter ? A.filter(v.filter) : A;
1689
+ }
1690
+ if (b) {
1691
+ const T = b.length;
1692
+ for (let A = 0; A < T; A++) {
1693
+ const P = b[A], M = `${E.name}/${P.moduleName}`;
1694
+ o.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
1695
+ id: P.moduleName === "." ? E.name : M,
1696
+ name: E.name,
1697
+ remoteSnapshot: _,
1698
+ preloadConfig: v,
1699
+ remote: E,
1700
+ origin: o
1701
+ }), !getPreloaded(M) && (v.resourceCategory === "all" ? (l.push(...O(P.assets.css.async)), l.push(...O(P.assets.css.sync)), a.push(...O(P.assets.js.async)), a.push(...O(P.assets.js.sync))) : (v.resourceCategory = "sync") && (l.push(...O(P.assets.css.sync)), a.push(...O(P.assets.js.sync))), setPreloaded(M));
1702
+ }
1703
+ }
1704
+ }, !0, {}, s), s.shared) {
1705
+ const _ = (E, $) => {
1706
+ const v = getRegisteredShare(o.shareScopeMap, $.sharedName, E, o.sharedHandler.hooks.lifecycle.resolveShare);
1707
+ v && typeof v.lib == "function" && ($.assets.js.sync.forEach((S) => {
1708
+ c.add(S);
1709
+ }), $.assets.css.sync.forEach((S) => {
1710
+ u.add(S);
1711
+ }));
1712
+ };
1713
+ s.shared.forEach((E) => {
1714
+ var $;
1715
+ const v = ($ = d.shared) == null ? void 0 : $[E.sharedName];
1716
+ if (!v)
1717
+ return;
1718
+ const S = E.version ? v.find((I) => I.version === E.version) : v;
1719
+ if (!S)
1720
+ return;
1721
+ arrayOptions(S).forEach((I) => {
1722
+ _(I, E);
1723
+ });
1724
+ });
1725
+ }
1726
+ const g = a.filter((_) => !c.has(_));
1727
+ return {
1728
+ cssAssets: l.filter((_) => !u.has(_)),
1729
+ jsAssetsWithoutEntry: g,
1730
+ entryAssets: i
1731
+ };
1732
+ }
1733
+ const generatePreloadAssetsPlugin = function() {
1734
+ return {
1735
+ name: "generate-preload-assets-plugin",
1736
+ async generatePreloadAssets(o) {
1737
+ const { origin: t, preloadOptions: n, remoteInfo: r, remote: s, globalSnapshot: l, remoteSnapshot: a } = o;
1738
+ return isRemoteInfoWithEntry(s) && isPureRemoteEntry(s) ? {
1739
+ cssAssets: [],
1740
+ jsAssetsWithoutEntry: [],
1741
+ entryAssets: [
1742
+ {
1743
+ name: s.name,
1744
+ url: s.entry,
1745
+ moduleInfo: {
1746
+ name: r.name,
1747
+ entry: s.entry,
1748
+ type: r.type || "global",
1749
+ entryGlobalName: "",
1750
+ shareScope: ""
1751
+ }
1752
+ }
1753
+ ]
1754
+ } : (assignRemoteInfo(r, a), generatePreloadAssets(t, n, r, l, a));
1755
+ }
1756
+ };
1757
+ };
1758
+ function getGlobalRemoteInfo(o, t) {
1759
+ const n = getGlobalSnapshotInfoByModuleInfo({
1760
+ name: t.options.name,
1761
+ version: t.options.version
1762
+ }), r = n && "remotesInfo" in n && n.remotesInfo && getInfoWithoutType(n.remotesInfo, o.name).value;
1763
+ return r && r.matchedVersion ? {
1764
+ hostGlobalSnapshot: n,
1765
+ globalSnapshot: getGlobalSnapshot(),
1766
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1767
+ name: o.name,
1768
+ version: r.matchedVersion
1769
+ })
1770
+ } : {
1771
+ hostGlobalSnapshot: void 0,
1772
+ globalSnapshot: getGlobalSnapshot(),
1773
+ remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({
1774
+ name: o.name,
1775
+ version: "version" in o ? o.version : void 0
1776
+ })
1777
+ };
1778
+ }
1779
+ class SnapshotHandler {
1780
+ async loadSnapshot(t) {
1781
+ const { options: n } = this.HostInstance, { hostGlobalSnapshot: r, remoteSnapshot: s, globalSnapshot: l } = this.getGlobalRemoteInfo(t), { remoteSnapshot: a, globalSnapshot: i } = await this.hooks.lifecycle.loadSnapshot.emit({
1782
+ options: n,
1783
+ moduleInfo: t,
1784
+ hostGlobalSnapshot: r,
1785
+ remoteSnapshot: s,
1786
+ globalSnapshot: l
1787
+ });
1788
+ return {
1789
+ remoteSnapshot: a,
1790
+ globalSnapshot: i
1791
+ };
1792
+ }
1793
+ // eslint-disable-next-line max-lines-per-function
1794
+ async loadRemoteSnapshotInfo(t) {
1795
+ const { options: n } = this.HostInstance;
1796
+ await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
1797
+ options: n,
1798
+ moduleInfo: t
1799
+ });
1800
+ let r = getGlobalSnapshotInfoByModuleInfo({
1801
+ name: this.HostInstance.options.name,
1802
+ version: this.HostInstance.options.version
1803
+ });
1804
+ r || (r = {
1805
+ version: this.HostInstance.options.version || "",
1806
+ remoteEntry: "",
1807
+ remotesInfo: {}
1808
+ }, addGlobalSnapshot({
1809
+ [this.HostInstance.options.name]: r
1810
+ })), r && "remotesInfo" in r && !getInfoWithoutType(r.remotesInfo, t.name).value && ("version" in t || "entry" in t) && (r.remotesInfo = _extends$1({}, r == null ? void 0 : r.remotesInfo, {
1811
+ [t.name]: {
1812
+ matchedVersion: "version" in t ? t.version : t.entry
1813
+ }
1814
+ }));
1815
+ const { hostGlobalSnapshot: s, remoteSnapshot: l, globalSnapshot: a } = this.getGlobalRemoteInfo(t), { remoteSnapshot: i, globalSnapshot: c } = await this.hooks.lifecycle.loadSnapshot.emit({
1816
+ options: n,
1817
+ moduleInfo: t,
1818
+ hostGlobalSnapshot: s,
1819
+ remoteSnapshot: l,
1820
+ globalSnapshot: a
1821
+ });
1822
+ let u, d;
1823
+ if (i)
1824
+ if (isManifestProvider(i)) {
1825
+ const p = isBrowserEnv() ? i.remoteEntry : i.ssrRemoteEntry || i.remoteEntry || "", m = await this.getManifestJson(p, t, {}), y = setGlobalSnapshotInfoByModuleInfo(_extends$1({}, t, {
1826
+ // The global remote may be overridden
1827
+ // Therefore, set the snapshot key to the global address of the actual request
1828
+ entry: p
1829
+ }), m);
1830
+ u = m, d = y;
1831
+ } else {
1832
+ const { remoteSnapshot: p } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
1833
+ options: this.HostInstance.options,
1834
+ moduleInfo: t,
1835
+ remoteSnapshot: i,
1836
+ from: "global"
1837
+ });
1838
+ u = p, d = c;
1839
+ }
1840
+ else if (isRemoteInfoWithEntry(t)) {
1841
+ const p = await this.getManifestJson(t.entry, t, {}), m = setGlobalSnapshotInfoByModuleInfo(t, p), { remoteSnapshot: y } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
1842
+ options: this.HostInstance.options,
1843
+ moduleInfo: t,
1844
+ remoteSnapshot: p,
1845
+ from: "global"
1846
+ });
1847
+ u = y, d = m;
1848
+ } else
1849
+ error(getShortErrorMsg(RUNTIME_007, runtimeDescMap, {
1850
+ hostName: t.name,
1851
+ hostVersion: t.version,
1852
+ globalSnapshot: JSON.stringify(c)
1853
+ }));
1854
+ return await this.hooks.lifecycle.afterLoadSnapshot.emit({
1855
+ options: n,
1856
+ moduleInfo: t,
1857
+ remoteSnapshot: u
1858
+ }), {
1859
+ remoteSnapshot: u,
1860
+ globalSnapshot: d
1861
+ };
1862
+ }
1863
+ getGlobalRemoteInfo(t) {
1864
+ return getGlobalRemoteInfo(t, this.HostInstance);
1865
+ }
1866
+ async getManifestJson(t, n, r) {
1867
+ const s = async () => {
1868
+ let a = this.manifestCache.get(t);
1869
+ if (a)
1870
+ return a;
1871
+ try {
1872
+ let i = await this.loaderHook.lifecycle.fetch.emit(t, {});
1873
+ return (!i || !(i instanceof Response)) && (i = await fetch(t, {})), a = await i.json(), assert(a.metaData && a.exposes && a.shared, `${t} is not a federation manifest`), this.manifestCache.set(t, a), a;
1874
+ } catch (i) {
1875
+ delete this.manifestLoading[t], error(getShortErrorMsg(RUNTIME_003, runtimeDescMap, {
1876
+ manifestUrl: t,
1877
+ moduleName: n.name
1878
+ }, `${i}`));
1879
+ }
1880
+ }, l = async () => {
1881
+ const a = await s(), i = generateSnapshotFromManifest(a, {
1882
+ version: t
1883
+ }), { remoteSnapshot: c } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
1884
+ options: this.HostInstance.options,
1885
+ moduleInfo: n,
1886
+ manifestJson: a,
1887
+ remoteSnapshot: i,
1888
+ manifestUrl: t,
1889
+ from: "manifest"
1890
+ });
1891
+ return c;
1892
+ };
1893
+ return this.manifestLoading[t] || (this.manifestLoading[t] = l().then((a) => a)), this.manifestLoading[t];
1894
+ }
1895
+ constructor(t) {
1896
+ this.loadingHostSnapshot = null, this.manifestCache = /* @__PURE__ */ new Map(), this.hooks = new PluginSystem({
1897
+ beforeLoadRemoteSnapshot: new AsyncHook("beforeLoadRemoteSnapshot"),
1898
+ loadSnapshot: new AsyncWaterfallHook("loadGlobalSnapshot"),
1899
+ loadRemoteSnapshot: new AsyncWaterfallHook("loadRemoteSnapshot"),
1900
+ afterLoadSnapshot: new AsyncWaterfallHook("afterLoadSnapshot")
1901
+ }), this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__, this.HostInstance = t, this.loaderHook = t.loaderHook;
1902
+ }
1903
+ }
1904
+ class SharedHandler {
1905
+ // register shared in shareScopeMap
1906
+ registerShared(t, n) {
1907
+ const { shareInfos: r, shared: s } = formatShareConfigs(t, n);
1908
+ return Object.keys(r).forEach((a) => {
1909
+ r[a].forEach((c) => {
1910
+ !getRegisteredShare(this.shareScopeMap, a, c, this.hooks.lifecycle.resolveShare) && c && c.lib && this.setShared({
1911
+ pkgName: a,
1912
+ lib: c.lib,
1913
+ get: c.get,
1914
+ loaded: !0,
1915
+ shared: c,
1916
+ from: n.name
1917
+ });
1918
+ });
1919
+ }), {
1920
+ shareInfos: r,
1921
+ shared: s
1922
+ };
1923
+ }
1924
+ async loadShare(t, n) {
1925
+ const { host: r } = this, s = getTargetSharedOptions({
1926
+ pkgName: t,
1927
+ extraOptions: n,
1928
+ shareInfos: r.options.shared
1929
+ });
1930
+ s != null && s.scope && await Promise.all(s.scope.map(async (u) => {
1931
+ await Promise.all(this.initializeSharing(u, {
1932
+ strategy: s.strategy
1933
+ }));
1934
+ }));
1935
+ const l = await this.hooks.lifecycle.beforeLoadShare.emit({
1936
+ pkgName: t,
1937
+ shareInfo: s,
1938
+ shared: r.options.shared,
1939
+ origin: r
1940
+ }), { shareInfo: a } = l;
1941
+ assert(a, `Cannot find ${t} Share in the ${r.options.name}. Please ensure that the ${t} Share parameters have been injected`);
1942
+ const i = getRegisteredShare(this.shareScopeMap, t, a, this.hooks.lifecycle.resolveShare), c = (u) => {
1943
+ u.useIn || (u.useIn = []), addUniqueItem(u.useIn, r.options.name);
1944
+ };
1945
+ if (i && i.lib)
1946
+ return c(i), i.lib;
1947
+ if (i && i.loading && !i.loaded) {
1948
+ const u = await i.loading;
1949
+ return i.loaded = !0, i.lib || (i.lib = u), c(i), u;
1950
+ } else if (i) {
1951
+ const d = (async () => {
1952
+ const p = await i.get();
1953
+ a.lib = p, a.loaded = !0, c(a);
1954
+ const m = getRegisteredShare(this.shareScopeMap, t, a, this.hooks.lifecycle.resolveShare);
1955
+ return m && (m.lib = p, m.loaded = !0), p;
1956
+ })();
1957
+ return this.setShared({
1958
+ pkgName: t,
1959
+ loaded: !1,
1960
+ shared: i,
1961
+ from: r.options.name,
1962
+ lib: null,
1963
+ loading: d
1964
+ }), d;
1965
+ } else {
1966
+ if (n != null && n.customShareInfo)
1967
+ return !1;
1968
+ const d = (async () => {
1969
+ const p = await a.get();
1970
+ a.lib = p, a.loaded = !0, c(a);
1971
+ const m = getRegisteredShare(this.shareScopeMap, t, a, this.hooks.lifecycle.resolveShare);
1972
+ return m && (m.lib = p, m.loaded = !0), p;
1973
+ })();
1974
+ return this.setShared({
1975
+ pkgName: t,
1976
+ loaded: !1,
1977
+ shared: a,
1978
+ from: r.options.name,
1979
+ lib: null,
1980
+ loading: d
1981
+ }), d;
1982
+ }
1983
+ }
1984
+ /**
1985
+ * This function initializes the sharing sequence (executed only once per share scope).
1986
+ * It accepts one argument, the name of the share scope.
1987
+ * If the share scope does not exist, it creates one.
1988
+ */
1989
+ // eslint-disable-next-line @typescript-eslint/member-ordering
1990
+ initializeSharing(t = DEFAULT_SCOPE, n) {
1991
+ const { host: r } = this, s = n == null ? void 0 : n.from, l = n == null ? void 0 : n.strategy;
1992
+ let a = n == null ? void 0 : n.initScope;
1993
+ const i = [];
1994
+ if (s !== "build") {
1995
+ const { initTokens: g } = this;
1996
+ a || (a = []);
1997
+ let R = g[t];
1998
+ if (R || (R = g[t] = {
1999
+ from: this.host.name
2000
+ }), a.indexOf(R) >= 0)
2001
+ return i;
2002
+ a.push(R);
2003
+ }
2004
+ const c = this.shareScopeMap, u = r.options.name;
2005
+ c[t] || (c[t] = {});
2006
+ const d = c[t], p = (g, R) => {
2007
+ var _;
2008
+ const { version: E, eager: $ } = R;
2009
+ d[g] = d[g] || {};
2010
+ const v = d[g], S = v[E], b = !!(S && (S.eager || (_ = S.shareConfig) != null && _.eager));
2011
+ (!S || S.strategy !== "loaded-first" && !S.loaded && (!$ != !b ? $ : u > S.from)) && (v[E] = R);
2012
+ }, m = (g) => g && g.init && g.init(c[t], a), y = async (g) => {
2013
+ const { module: R } = await r.remoteHandler.getRemoteModuleAndOptions({
2014
+ id: g
2015
+ });
2016
+ if (R.getEntry) {
2017
+ let _;
2018
+ try {
2019
+ _ = await R.getEntry();
2020
+ } catch (E) {
2021
+ _ = await r.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
2022
+ id: g,
2023
+ error: E,
2024
+ from: "runtime",
2025
+ lifecycle: "beforeLoadShare",
2026
+ origin: r
2027
+ });
2028
+ }
2029
+ R.inited || (await m(_), R.inited = !0);
2030
+ }
2031
+ };
2032
+ return Object.keys(r.options.shared).forEach((g) => {
2033
+ r.options.shared[g].forEach((_) => {
2034
+ _.scope.includes(t) && p(g, _);
2035
+ });
2036
+ }), (r.options.shareStrategy === "version-first" || l === "version-first") && r.options.remotes.forEach((g) => {
2037
+ g.shareScope === t && i.push(y(g.name));
2038
+ }), i;
2039
+ }
2040
+ // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
2041
+ // 1. If the loaded shared already exists globally, then it will be reused
2042
+ // 2. If lib exists in local shared, it will be used directly
2043
+ // 3. If the local get returns something other than Promise, then it will be used directly
2044
+ loadShareSync(t, n) {
2045
+ const { host: r } = this, s = getTargetSharedOptions({
2046
+ pkgName: t,
2047
+ extraOptions: n,
2048
+ shareInfos: r.options.shared
2049
+ });
2050
+ s != null && s.scope && s.scope.forEach((i) => {
2051
+ this.initializeSharing(i, {
2052
+ strategy: s.strategy
2053
+ });
2054
+ });
2055
+ const l = getRegisteredShare(this.shareScopeMap, t, s, this.hooks.lifecycle.resolveShare), a = (i) => {
2056
+ i.useIn || (i.useIn = []), addUniqueItem(i.useIn, r.options.name);
2057
+ };
2058
+ if (l) {
2059
+ if (typeof l.lib == "function")
2060
+ return a(l), l.loaded || (l.loaded = !0, l.from === r.options.name && (s.loaded = !0)), l.lib;
2061
+ if (typeof l.get == "function") {
2062
+ const i = l.get();
2063
+ if (!(i instanceof Promise))
2064
+ return a(l), this.setShared({
2065
+ pkgName: t,
2066
+ loaded: !0,
2067
+ from: r.options.name,
2068
+ lib: i,
2069
+ shared: l
2070
+ }), i;
2071
+ }
2072
+ }
2073
+ if (s.lib)
2074
+ return s.loaded || (s.loaded = !0), s.lib;
2075
+ if (s.get) {
2076
+ const i = s.get();
2077
+ if (i instanceof Promise) {
2078
+ const c = (n == null ? void 0 : n.from) === "build" ? RUNTIME_005 : RUNTIME_006;
2079
+ throw new Error(getShortErrorMsg(c, runtimeDescMap, {
2080
+ hostName: r.options.name,
2081
+ sharedPkgName: t
2082
+ }));
2083
+ }
2084
+ return s.lib = i, this.setShared({
2085
+ pkgName: t,
2086
+ loaded: !0,
2087
+ from: r.options.name,
2088
+ lib: s.lib,
2089
+ shared: s
2090
+ }), s.lib;
2091
+ }
2092
+ throw new Error(getShortErrorMsg(RUNTIME_006, runtimeDescMap, {
2093
+ hostName: r.options.name,
2094
+ sharedPkgName: t
2095
+ }));
2096
+ }
2097
+ initShareScopeMap(t, n, r = {}) {
2098
+ const { host: s } = this;
2099
+ this.shareScopeMap[t] = n, this.hooks.lifecycle.initContainerShareScopeMap.emit({
2100
+ shareScope: n,
2101
+ options: s.options,
2102
+ origin: s,
2103
+ scopeName: t,
2104
+ hostShareScopeMap: r.hostShareScopeMap
2105
+ });
2106
+ }
2107
+ setShared({ pkgName: t, shared: n, from: r, lib: s, loading: l, loaded: a, get: i }) {
2108
+ const { version: c, scope: u = "default" } = n, d = _object_without_properties_loose(n, [
2109
+ "version",
2110
+ "scope"
2111
+ ]);
2112
+ (Array.isArray(u) ? u : [
2113
+ u
2114
+ ]).forEach((m) => {
2115
+ if (this.shareScopeMap[m] || (this.shareScopeMap[m] = {}), this.shareScopeMap[m][t] || (this.shareScopeMap[m][t] = {}), !this.shareScopeMap[m][t][c]) {
2116
+ this.shareScopeMap[m][t][c] = _extends$1({
2117
+ version: c,
2118
+ scope: [
2119
+ "default"
2120
+ ]
2121
+ }, d, {
2122
+ lib: s,
2123
+ loaded: a,
2124
+ loading: l
2125
+ }), i && (this.shareScopeMap[m][t][c].get = i);
2126
+ return;
2127
+ }
2128
+ const y = this.shareScopeMap[m][t][c];
2129
+ l && !y.loading && (y.loading = l);
2130
+ });
2131
+ }
2132
+ _setGlobalShareScopeMap(t) {
2133
+ const n = getGlobalShareScope(), r = t.id || t.name;
2134
+ r && !n[r] && (n[r] = this.shareScopeMap);
2135
+ }
2136
+ constructor(t) {
2137
+ this.hooks = new PluginSystem({
2138
+ afterResolve: new AsyncWaterfallHook("afterResolve"),
2139
+ beforeLoadShare: new AsyncWaterfallHook("beforeLoadShare"),
2140
+ // not used yet
2141
+ loadShare: new AsyncHook(),
2142
+ resolveShare: new SyncWaterfallHook("resolveShare"),
2143
+ // maybe will change, temporarily for internal use only
2144
+ initContainerShareScopeMap: new SyncWaterfallHook("initContainerShareScopeMap")
2145
+ }), this.host = t, this.shareScopeMap = {}, this.initTokens = {}, this._setGlobalShareScopeMap(t.options);
2146
+ }
2147
+ }
2148
+ class RemoteHandler {
2149
+ formatAndRegisterRemote(t, n) {
2150
+ return (n.remotes || []).reduce((s, l) => (this.registerRemote(l, s, {
2151
+ force: !1
2152
+ }), s), t.remotes);
2153
+ }
2154
+ setIdToRemoteMap(t, n) {
2155
+ const { remote: r, expose: s } = n, { name: l, alias: a } = r;
2156
+ if (this.idToRemoteMap[t] = {
2157
+ name: r.name,
2158
+ expose: s
2159
+ }, a && t.startsWith(l)) {
2160
+ const i = t.replace(l, a);
2161
+ this.idToRemoteMap[i] = {
2162
+ name: r.name,
2163
+ expose: s
2164
+ };
2165
+ return;
2166
+ }
2167
+ if (a && t.startsWith(a)) {
2168
+ const i = t.replace(a, l);
2169
+ this.idToRemoteMap[i] = {
2170
+ name: r.name,
2171
+ expose: s
2172
+ };
2173
+ }
2174
+ }
2175
+ // eslint-disable-next-line max-lines-per-function
2176
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2177
+ async loadRemote(t, n) {
2178
+ const { host: r } = this;
2179
+ try {
2180
+ const { loadFactory: s = !0 } = n || {
2181
+ loadFactory: !0
2182
+ }, { module: l, moduleOptions: a, remoteMatchInfo: i } = await this.getRemoteModuleAndOptions({
2183
+ id: t
2184
+ }), { pkgNameOrAlias: c, remote: u, expose: d, id: p, remoteSnapshot: m } = i, y = await l.get(p, d, n, m), g = await this.hooks.lifecycle.onLoad.emit({
2185
+ id: p,
2186
+ pkgNameOrAlias: c,
2187
+ expose: d,
2188
+ exposeModule: s ? y : void 0,
2189
+ exposeModuleFactory: s ? void 0 : y,
2190
+ remote: u,
2191
+ options: a,
2192
+ moduleInstance: l,
2193
+ origin: r
2194
+ });
2195
+ return this.setIdToRemoteMap(t, i), typeof g == "function" ? g : y;
2196
+ } catch (s) {
2197
+ const { from: l = "runtime" } = n || {
2198
+ from: "runtime"
2199
+ }, a = await this.hooks.lifecycle.errorLoadRemote.emit({
2200
+ id: t,
2201
+ error: s,
2202
+ from: l,
2203
+ lifecycle: "onLoad",
2204
+ origin: r
2205
+ });
2206
+ if (!a)
2207
+ throw s;
2208
+ return a;
2209
+ }
2210
+ }
2211
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2212
+ async preloadRemote(t) {
2213
+ const { host: n } = this;
2214
+ await this.hooks.lifecycle.beforePreloadRemote.emit({
2215
+ preloadOps: t,
2216
+ options: n.options,
2217
+ origin: n
2218
+ });
2219
+ const r = formatPreloadArgs(n.options.remotes, t);
2220
+ await Promise.all(r.map(async (s) => {
2221
+ const { remote: l } = s, a = getRemoteInfo(l), { globalSnapshot: i, remoteSnapshot: c } = await n.snapshotHandler.loadRemoteSnapshotInfo(l), u = await this.hooks.lifecycle.generatePreloadAssets.emit({
2222
+ origin: n,
2223
+ preloadOptions: s,
2224
+ remote: l,
2225
+ remoteInfo: a,
2226
+ globalSnapshot: i,
2227
+ remoteSnapshot: c
2228
+ });
2229
+ u && preloadAssets(a, n, u);
2230
+ }));
2231
+ }
2232
+ registerRemotes(t, n) {
2233
+ const { host: r } = this;
2234
+ t.forEach((s) => {
2235
+ this.registerRemote(s, r.options.remotes, {
2236
+ force: n == null ? void 0 : n.force
2237
+ });
2238
+ });
2239
+ }
2240
+ async getRemoteModuleAndOptions(t) {
2241
+ const { host: n } = this, { id: r } = t;
2242
+ let s;
2243
+ try {
2244
+ s = await this.hooks.lifecycle.beforeRequest.emit({
2245
+ id: r,
2246
+ options: n.options,
2247
+ origin: n
2248
+ });
2249
+ } catch (g) {
2250
+ if (s = await this.hooks.lifecycle.errorLoadRemote.emit({
2251
+ id: r,
2252
+ options: n.options,
2253
+ origin: n,
2254
+ from: "runtime",
2255
+ error: g,
2256
+ lifecycle: "beforeRequest"
2257
+ }), !s)
2258
+ throw g;
2259
+ }
2260
+ const { id: l } = s, a = matchRemoteWithNameAndExpose(n.options.remotes, l);
2261
+ assert(a, getShortErrorMsg(RUNTIME_004, runtimeDescMap, {
2262
+ hostName: n.options.name,
2263
+ requestId: l
2264
+ }));
2265
+ const { remote: i } = a, c = getRemoteInfo(i), u = await n.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends$1({
2266
+ id: l
2267
+ }, a, {
2268
+ options: n.options,
2269
+ origin: n,
2270
+ remoteInfo: c
2271
+ })), { remote: d, expose: p } = u;
2272
+ assert(d && p, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${l}.`);
2273
+ let m = n.moduleCache.get(d.name);
2274
+ const y = {
2275
+ host: n,
2276
+ remoteInfo: c
2277
+ };
2278
+ return m || (m = new Module(y), n.moduleCache.set(d.name, m)), {
2279
+ module: m,
2280
+ moduleOptions: y,
2281
+ remoteMatchInfo: u
2282
+ };
2283
+ }
2284
+ registerRemote(t, n, r) {
2285
+ const { host: s } = this, l = () => {
2286
+ if (t.alias) {
2287
+ const i = n.find((c) => {
2288
+ var u;
2289
+ return t.alias && (c.name.startsWith(t.alias) || ((u = c.alias) == null ? void 0 : u.startsWith(t.alias)));
2290
+ });
2291
+ assert(!i, `The alias ${t.alias} of remote ${t.name} is not allowed to be the prefix of ${i && i.name} name or alias`);
2292
+ }
2293
+ "entry" in t && isBrowserEnv() && !t.entry.startsWith("http") && (t.entry = new URL(t.entry, window.location.origin).href), t.shareScope || (t.shareScope = DEFAULT_SCOPE), t.type || (t.type = DEFAULT_REMOTE_TYPE);
2294
+ };
2295
+ this.hooks.lifecycle.beforeRegisterRemote.emit({
2296
+ remote: t,
2297
+ origin: s
2298
+ });
2299
+ const a = n.find((i) => i.name === t.name);
2300
+ if (!a)
2301
+ l(), n.push(t), this.hooks.lifecycle.registerRemote.emit({
2302
+ remote: t,
2303
+ origin: s
2304
+ });
2305
+ else {
2306
+ const i = [
2307
+ `The remote "${t.name}" is already registered.`,
2308
+ r != null && r.force ? "Hope you have known that OVERRIDE it may have some unexpected errors" : 'If you want to merge the remote, you can set "force: true".'
2309
+ ];
2310
+ r != null && r.force && (this.removeRemote(a), l(), n.push(t), this.hooks.lifecycle.registerRemote.emit({
2311
+ remote: t,
2312
+ origin: s
2313
+ })), warn$1(i.join(" "));
2314
+ }
2315
+ }
2316
+ removeRemote(t) {
2317
+ try {
2318
+ const { host: r } = this, { name: s } = t, l = r.options.remotes.findIndex((i) => i.name === s);
2319
+ l !== -1 && r.options.remotes.splice(l, 1);
2320
+ const a = r.moduleCache.get(t.name);
2321
+ if (a) {
2322
+ const i = a.remoteInfo, c = i.entryGlobalName;
2323
+ if (CurrentGlobal[c]) {
2324
+ var n;
2325
+ (n = Object.getOwnPropertyDescriptor(CurrentGlobal, c)) != null && n.configurable ? delete CurrentGlobal[c] : CurrentGlobal[c] = void 0;
2326
+ }
2327
+ const u = getRemoteEntryUniqueKey(a.remoteInfo);
2328
+ globalLoading[u] && delete globalLoading[u], r.snapshotHandler.manifestCache.delete(i.entry);
2329
+ let d = i.buildVersion ? composeKeyWithSeparator(i.name, i.buildVersion) : i.name;
2330
+ const p = CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((y) => i.buildVersion ? y.options.id === d : y.name === d);
2331
+ if (p !== -1) {
2332
+ const y = CurrentGlobal.__FEDERATION__.__INSTANCES__[p];
2333
+ d = y.options.id || d;
2334
+ const g = getGlobalShareScope();
2335
+ let R = !0;
2336
+ const _ = [];
2337
+ Object.keys(g).forEach((E) => {
2338
+ const $ = g[E];
2339
+ $ && Object.keys($).forEach((v) => {
2340
+ const S = $[v];
2341
+ S && Object.keys(S).forEach((b) => {
2342
+ const I = S[b];
2343
+ I && Object.keys(I).forEach((w) => {
2344
+ const O = I[w];
2345
+ O && typeof O == "object" && O.from === i.name && (O.loaded || O.loading ? (O.useIn = O.useIn.filter((T) => T !== i.name), O.useIn.length ? R = !1 : _.push([
2346
+ E,
2347
+ v,
2348
+ b,
2349
+ w
2350
+ ])) : _.push([
2351
+ E,
2352
+ v,
2353
+ b,
2354
+ w
2355
+ ]));
2356
+ });
2357
+ });
2358
+ });
2359
+ }), R && (y.shareScopeMap = {}, delete g[d]), _.forEach(([E, $, v, S]) => {
2360
+ var b, I, w;
2361
+ (w = g[E]) == null || (I = w[$]) == null || (b = I[v]) == null || delete b[S];
2362
+ }), CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(p, 1);
2363
+ }
2364
+ const { hostGlobalSnapshot: m } = getGlobalRemoteInfo(t, r);
2365
+ if (m) {
2366
+ const y = m && "remotesInfo" in m && m.remotesInfo && getInfoWithoutType(m.remotesInfo, t.name).key;
2367
+ y && (delete m.remotesInfo[y], Global.__FEDERATION__.__MANIFEST_LOADING__[y] && delete Global.__FEDERATION__.__MANIFEST_LOADING__[y]);
2368
+ }
2369
+ r.moduleCache.delete(t.name);
2370
+ }
2371
+ } catch (r) {
2372
+ logger.log("removeRemote fail: ", r);
2373
+ }
2374
+ }
2375
+ constructor(t) {
2376
+ this.hooks = new PluginSystem({
2377
+ beforeRegisterRemote: new SyncWaterfallHook("beforeRegisterRemote"),
2378
+ registerRemote: new SyncWaterfallHook("registerRemote"),
2379
+ beforeRequest: new AsyncWaterfallHook("beforeRequest"),
2380
+ onLoad: new AsyncHook("onLoad"),
2381
+ handlePreloadModule: new SyncHook("handlePreloadModule"),
2382
+ errorLoadRemote: new AsyncHook("errorLoadRemote"),
2383
+ beforePreloadRemote: new AsyncHook("beforePreloadRemote"),
2384
+ generatePreloadAssets: new AsyncHook("generatePreloadAssets"),
2385
+ // not used yet
2386
+ afterPreloadRemote: new AsyncHook(),
2387
+ loadEntry: new AsyncHook()
2388
+ }), this.host = t, this.idToRemoteMap = {};
2389
+ }
2390
+ }
2391
+ class FederationHost {
2392
+ initOptions(t) {
2393
+ this.registerPlugins(t.plugins);
2394
+ const n = this.formatOptions(this.options, t);
2395
+ return this.options = n, n;
2396
+ }
2397
+ async loadShare(t, n) {
2398
+ return this.sharedHandler.loadShare(t, n);
2399
+ }
2400
+ // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
2401
+ // 1. If the loaded shared already exists globally, then it will be reused
2402
+ // 2. If lib exists in local shared, it will be used directly
2403
+ // 3. If the local get returns something other than Promise, then it will be used directly
2404
+ loadShareSync(t, n) {
2405
+ return this.sharedHandler.loadShareSync(t, n);
2406
+ }
2407
+ initializeSharing(t = DEFAULT_SCOPE, n) {
2408
+ return this.sharedHandler.initializeSharing(t, n);
2409
+ }
2410
+ initRawContainer(t, n, r) {
2411
+ const s = getRemoteInfo({
2412
+ name: t,
2413
+ entry: n
2414
+ }), l = new Module({
2415
+ host: this,
2416
+ remoteInfo: s
2417
+ });
2418
+ return l.remoteEntryExports = r, this.moduleCache.set(t, l), l;
2419
+ }
2420
+ // eslint-disable-next-line max-lines-per-function
2421
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2422
+ async loadRemote(t, n) {
2423
+ return this.remoteHandler.loadRemote(t, n);
2424
+ }
2425
+ // eslint-disable-next-line @typescript-eslint/member-ordering
2426
+ async preloadRemote(t) {
2427
+ return this.remoteHandler.preloadRemote(t);
2428
+ }
2429
+ initShareScopeMap(t, n, r = {}) {
2430
+ this.sharedHandler.initShareScopeMap(t, n, r);
2431
+ }
2432
+ formatOptions(t, n) {
2433
+ const { shared: r } = formatShareConfigs(t, n), { userOptions: s, options: l } = this.hooks.lifecycle.beforeInit.emit({
2434
+ origin: this,
2435
+ userOptions: n,
2436
+ options: t,
2437
+ shareInfo: r
2438
+ }), a = this.remoteHandler.formatAndRegisterRemote(l, s), { shared: i } = this.sharedHandler.registerShared(l, s), c = [
2439
+ ...l.plugins
2440
+ ];
2441
+ s.plugins && s.plugins.forEach((d) => {
2442
+ c.includes(d) || c.push(d);
2443
+ });
2444
+ const u = _extends$1({}, t, n, {
2445
+ plugins: c,
2446
+ remotes: a,
2447
+ shared: i
2448
+ });
2449
+ return this.hooks.lifecycle.init.emit({
2450
+ origin: this,
2451
+ options: u
2452
+ }), u;
2453
+ }
2454
+ registerPlugins(t) {
2455
+ const n = registerPlugins(t, [
2456
+ this.hooks,
2457
+ this.remoteHandler.hooks,
2458
+ this.sharedHandler.hooks,
2459
+ this.snapshotHandler.hooks,
2460
+ this.loaderHook,
2461
+ this.bridgeHook
2462
+ ]);
2463
+ this.options.plugins = this.options.plugins.reduce((r, s) => (s && r && !r.find((l) => l.name === s.name) && r.push(s), r), n || []);
2464
+ }
2465
+ registerRemotes(t, n) {
2466
+ return this.remoteHandler.registerRemotes(t, n);
2467
+ }
2468
+ constructor(t) {
2469
+ this.hooks = new PluginSystem({
2470
+ beforeInit: new SyncWaterfallHook("beforeInit"),
2471
+ init: new SyncHook(),
2472
+ // maybe will change, temporarily for internal use only
2473
+ beforeInitContainer: new AsyncWaterfallHook("beforeInitContainer"),
2474
+ // maybe will change, temporarily for internal use only
2475
+ initContainer: new AsyncWaterfallHook("initContainer")
2476
+ }), this.version = "0.7.0", this.moduleCache = /* @__PURE__ */ new Map(), this.loaderHook = new PluginSystem({
2477
+ // FIXME: may not be suitable , not open to the public yet
2478
+ getModuleInfo: new SyncHook(),
2479
+ createScript: new SyncHook(),
2480
+ createLink: new SyncHook(),
2481
+ // only work for manifest , so not open to the public yet
2482
+ fetch: new AsyncHook(),
2483
+ getModuleFactory: new AsyncHook()
2484
+ }), this.bridgeHook = new PluginSystem({
2485
+ beforeBridgeRender: new SyncHook(),
2486
+ afterBridgeRender: new SyncHook(),
2487
+ beforeBridgeDestroy: new SyncHook(),
2488
+ afterBridgeDestroy: new SyncHook()
2489
+ });
2490
+ const n = {
2491
+ id: getBuilderId(),
2492
+ name: t.name,
2493
+ plugins: [
2494
+ snapshotPlugin(),
2495
+ generatePreloadAssetsPlugin()
2496
+ ],
2497
+ remotes: [],
2498
+ shared: {},
2499
+ inBrowser: isBrowserEnv()
2500
+ };
2501
+ this.name = t.name, this.options = n, this.snapshotHandler = new SnapshotHandler(this), this.sharedHandler = new SharedHandler(this), this.remoteHandler = new RemoteHandler(this), this.shareScopeMap = this.sharedHandler.shareScopeMap, this.registerPlugins([
2502
+ ...n.plugins,
2503
+ ...t.plugins || []
2504
+ ]), this.options = this.formatOptions(n, t);
2505
+ }
2506
+ }
2507
+ setGlobalFederationConstructor(FederationHost);
2508
+ const RemoteApp = /* @__PURE__ */ defineComponent({
249
2509
  name: "RemoteApp",
250
2510
  props: {
251
2511
  moduleName: String,
@@ -253,65 +2513,65 @@ const Ee = /* @__PURE__ */ V({
253
2513
  memoryRoute: Object,
254
2514
  providerInfo: Function
255
2515
  },
256
- setup(e) {
257
- const o = R(null), r = R(null), t = R(""), n = B(), c = () => {
258
- var d;
259
- const a = (d = e.providerInfo) == null ? void 0 : d.call(e);
260
- r.value = a;
261
- const i = {
262
- name: e.moduleName,
263
- dom: o.value,
264
- basename: e.basename,
265
- memoryRoute: e.memoryRoute
2516
+ setup(o) {
2517
+ const t = ref(null), n = ref(null), r = ref(""), s = useRoute(), l = () => {
2518
+ var u;
2519
+ const i = (u = o.providerInfo) == null ? void 0 : u.call(o);
2520
+ n.value = i;
2521
+ const c = {
2522
+ name: o.moduleName,
2523
+ dom: t.value,
2524
+ basename: o.basename,
2525
+ memoryRoute: o.memoryRoute
266
2526
  };
267
- g.log("createRemoteComponent LazyComponent render >>>", i), a.render(i);
268
- }, l = W(() => n.path, (a) => {
269
- a !== n.path && c(), t.value !== "" && t.value !== a && (g.log("createRemoteComponent dispatchPopstateEnv >>>", {
270
- ...e,
271
- pathname: n.path
272
- }), ye()), t.value = a;
2527
+ LoggerInstance.log("createRemoteComponent LazyComponent render >>>", c), i.render(c);
2528
+ }, a = watch(() => s.path, (i) => {
2529
+ i !== s.path && l(), r.value !== "" && r.value !== i && (LoggerInstance.log("createRemoteComponent dispatchPopstateEnv >>>", {
2530
+ ...o,
2531
+ pathname: s.path
2532
+ }), e()), r.value = i;
273
2533
  });
274
- return U(() => {
275
- c();
276
- }), x(() => {
277
- var a;
278
- g.log("createRemoteComponent LazyComponent destroy >>>", {
279
- ...e
280
- }), l(), (a = r.value) == null || a.destroy({
281
- dom: o.value
2534
+ return onMounted(() => {
2535
+ l();
2536
+ }), onBeforeUnmount(() => {
2537
+ var i;
2538
+ LoggerInstance.log("createRemoteComponent LazyComponent destroy >>>", {
2539
+ ...o
2540
+ }), a(), (i = n.value) == null || i.destroy({
2541
+ dom: t.value
282
2542
  });
283
- }), () => k("div", {
284
- ref: o
2543
+ }), () => createVNode("div", {
2544
+ ref: t
285
2545
  }, null);
286
2546
  }
287
2547
  });
288
- function we(e) {
289
- return z({
2548
+ function createRemoteComponent(o) {
2549
+ return defineAsyncComponent({
290
2550
  __APP_VERSION__: "0.7.0",
291
2551
  //@ts-ignore
292
2552
  loader: async () => {
293
- var i;
294
- const o = B();
295
- let r = "/";
296
- const t = (i = o.matched[0]) == null ? void 0 : i.path;
297
- t && (t.endsWith("/:pathMatch(.*)*") ? r = t.replace("/:pathMatch(.*)*", "") : r = o.matched[0].path);
298
- const n = (e == null ? void 0 : e.export) || "default";
299
- g.log("createRemoteComponent LazyComponent create >>>", {
300
- basename: r,
301
- info: e
2553
+ var c;
2554
+ const t = useRoute();
2555
+ let n = "/";
2556
+ const r = (c = t.matched[0]) == null ? void 0 : c.path;
2557
+ r && (r.endsWith("/:pathMatch(.*)*") ? n = r.replace("/:pathMatch(.*)*", "") : n = t.matched[0].path);
2558
+ const s = (o == null ? void 0 : o.export) || "default";
2559
+ LoggerInstance.log("createRemoteComponent LazyComponent create >>>", {
2560
+ basename: n,
2561
+ info: o
302
2562
  });
303
- const c = await e.loader(), l = c && c[Symbol.for("mf_module_id")], a = c[n];
304
- if (g.log(
2563
+ const l = await o.loader(), a = l && l[Symbol.for("mf_module_id")], i = l[s];
2564
+ if (LoggerInstance.log(
305
2565
  "createRemoteComponent LazyComponent loadRemote info >>>",
306
- { name: l, module: c, exportName: n, basename: r, route: o }
307
- ), n in c && typeof a == "function")
2566
+ { name: a, module: l, exportName: s, basename: n, route: t }
2567
+ ), s in l && typeof i == "function")
308
2568
  return {
309
2569
  render() {
310
- return T(Ee, {
311
- moduleName: l,
312
- ...e,
313
- providerInfo: a,
314
- basename: r
2570
+ return h(RemoteApp, {
2571
+ moduleName: a,
2572
+ ...o,
2573
+ providerInfo: i,
2574
+ basename: n
315
2575
  });
316
2576
  }
317
2577
  };
@@ -328,6 +2588,6 @@ function we(e) {
328
2588
  });
329
2589
  }
330
2590
  export {
331
- _e as createBridgeComponent,
332
- we as createRemoteComponent
2591
+ createBridgeComponent,
2592
+ createRemoteComponent
333
2593
  };