@fulgurjs/federation 5.3.3 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/DESIGN.md +4 -0
  3. package/README.en.md +23 -3
  4. package/README.md +83 -1
  5. package/dist/bridge-app-react.cjs +14 -4
  6. package/dist/bridge-app-react.d.cts +16 -4
  7. package/dist/bridge-app-react.d.ts +16 -4
  8. package/dist/bridge-app-react.js +6 -4
  9. package/dist/bridge-app-vue.cjs +55 -9
  10. package/dist/bridge-app-vue.d.cts +25 -4
  11. package/dist/bridge-app-vue.d.ts +25 -4
  12. package/dist/bridge-app-vue.js +47 -9
  13. package/dist/bridge-core-BOWvVUxO.d.ts +91 -0
  14. package/dist/bridge-core.cjs +9 -1
  15. package/dist/bridge-core.d.cts +8 -1
  16. package/dist/bridge-core.d.ts +8 -1
  17. package/dist/bridge-core.js +2 -2
  18. package/dist/bridge-errors.cjs +55 -3
  19. package/dist/bridge-errors.d.cts +18 -2
  20. package/dist/bridge-errors.d.ts +18 -2
  21. package/dist/bridge-errors.js +11 -3
  22. package/dist/{bridge-host-react-C55RmGll.d.ts → bridge-host-react-CMVd-ym0.d.ts} +1 -1
  23. package/dist/bridge-host-react.cjs +324 -3
  24. package/dist/bridge-host-react.d.cts +2 -0
  25. package/dist/bridge-host-react.d.ts +2 -0
  26. package/dist/bridge-host-react.js +30 -4
  27. package/dist/{bridge-host-vue-BAxDKqGH.d.ts → bridge-host-vue-BuCGlLdS.d.ts} +1 -1
  28. package/dist/bridge-host-vue.cjs +335 -3
  29. package/dist/bridge-host-vue.js +42 -5
  30. package/dist/bridge-react.d.ts +5 -3
  31. package/dist/bridge-router-core-BxBx-reP.d.cts +44 -0
  32. package/dist/bridge-router-core-BxBx-reP.d.ts +44 -0
  33. package/dist/bridge-router-react.d.ts +96 -0
  34. package/dist/bridge-router-react.js +70 -0
  35. package/dist/bridge-router-vue.d.ts +75 -0
  36. package/dist/bridge-router-vue.js +73 -0
  37. package/dist/bridge-vue.d.ts +2 -2
  38. package/dist/bridge.d.ts +6 -4
  39. package/dist/{chunk-WD2ON7SN.js → chunk-BTJGYDHT.js} +303 -2
  40. package/dist/{chunk-GWJKABE7.js → chunk-GF6KOH67.js} +39 -4
  41. package/dist/{chunk-DH2QMM4Y.js → chunk-JQF7KYZF.js} +50 -2
  42. package/dist/{chunk-ZTRJLCOF.js → chunk-OXEAGRPY.js} +27 -3
  43. package/dist/{chunk-LE2G23E7.js → chunk-PRUYHYX2.js} +1 -1
  44. package/dist/chunk-WOTR2FUQ.js +266 -0
  45. package/dist/index.cjs +2 -2
  46. package/dist/index.js +2 -2
  47. package/dist/react.d.ts +51 -4
  48. package/dist/runtime-entry.d.ts +60 -4
  49. package/dist/runtime.js +1 -1
  50. package/examples/bridge/react-host/package-lock.json +105 -104
  51. package/examples/bridge/react-remote/package-lock.json +105 -104
  52. package/examples/bridge/vue-host/package-lock.json +105 -104
  53. package/examples/bridge/vue-remote/package-lock.json +105 -104
  54. package/examples/react/host/package-lock.json +1 -1
  55. package/examples/react/remote/package-lock.json +1 -1
  56. package/examples/vue/host/package-lock.json +1 -1
  57. package/examples/vue/remote/package-lock.json +1 -1
  58. package/package.json +28 -4
  59. package/dist/bridge-core-6uLJiMVa.d.ts +0 -42
@@ -77,7 +77,15 @@ var BridgeErrorCodes = {
77
77
  /** 桥接准备或生命周期失败(details.phase = getContext | mount | unmount) */
78
78
  BRIDGE_LIFECYCLE_FAILED: "MFU-016",
79
79
  /** 桥接会话参数与 AppContext 不一致(受控 sessionKey 与全局会话矛盾) */
80
- BRIDGE_SESSION_MISMATCH: "MFU-017"
80
+ BRIDGE_SESSION_MISMATCH: "MFU-017",
81
+ /** 路由同步配置/前缀冲突(basePath 非法、同页前缀冲突或重叠) */
82
+ ROUTING_CONFIG_INVALID: "MFU-030",
83
+ /** 路由协议缺失/通道失效(子应用未声明 routing 协议,或已销毁通道被再次使用) */
84
+ ROUTING_PROTOCOL_MISSING: "MFU-031",
85
+ /** 非法导航(目标越界前缀、非法 go 参数、失效实例的请求) */
86
+ ROUTING_NAVIGATION_INVALID: "MFU-032",
87
+ /** 路由准备/同步失败(重定向循环、子应用路由准备失败且已阻止错误页面显示) */
88
+ ROUTING_SYNC_FAILED: "MFU-033"
81
89
  };
82
90
  function invalidBridgeContractError(spec, mod) {
83
91
  const actual = mod === null ? "null" : typeof mod;
@@ -134,6 +142,42 @@ function invalidSessionKeyError(spec, value) {
134
142
  { spec, value: String(value) }
135
143
  );
136
144
  }
145
+ function routingConfigError(spec, reason) {
146
+ return new FgError(
147
+ BridgeErrorCodes.ROUTING_CONFIG_INVALID,
148
+ `\u73B0\u8C61\uFF1A\u6865\u63A5\u5E94\u7528 "${spec}" \u7684 URL \u540C\u6B65\u914D\u7F6E\u65E0\u6CD5\u542F\u7528\u3002
149
+ \u539F\u56E0\uFF1A${reason}
150
+ \u4FEE\u6CD5\uFF1A\u4FEE\u6B63 routing.basePath \u4E3A\u5BBF\u4E3B\u8DEF\u7531\u89C6\u89D2\u7684\u9759\u6001\u7EDD\u5BF9\u8DEF\u5F84\uFF08\u5982 "/approval"\uFF09\uFF0C\u5E76\u4FDD\u8BC1\u540C\u9875\u5404\u540C\u6B65\u5B9E\u4F8B\u524D\u7F00\u4E92\u4E0D\u91CD\u53E0\uFF1B\u5BBF\u4E3B\u8DEF\u7531\u9700\u58F0\u660E\u5BF9\u5E94\u7684\u540E\u7F00\u5339\u914D\uFF08Vue "/approval/:pathMatch(.*)*"\u3001React "/approval/*"\uFF09\u3002`,
151
+ { spec }
152
+ );
153
+ }
154
+ function routingProtocolError(spec, reason) {
155
+ return new FgError(
156
+ BridgeErrorCodes.ROUTING_PROTOCOL_MISSING,
157
+ `\u73B0\u8C61\uFF1A\u6865\u63A5\u5E94\u7528 "${spec}" \u7684 URL \u540C\u6B65\u901A\u9053\u4E0D\u53EF\u7528\u3002
158
+ \u539F\u56E0\uFF1A${reason}
159
+ \u4FEE\u6CD5\uFF1A\u5B50\u5E94\u7528\u4EE5 defineBridgeApp(\u5DE5\u5382, { routing: true }) \u58F0\u660E\u8DEF\u7531\u534F\u8BAE\u5E76\u5728\u5DE5\u5382\u7B2C\u4E8C\u53C2\u6570\u63A5\u6536 { signal, routing } \u63A5\u7EBF\u53D7\u63A7\u8DEF\u7531\uFF1B\u901A\u9053\u968F\u6302\u8F7D\u751F\u547D\u5468\u671F\u521B\u5EFA\uFF0C\u9500\u6BC1\u540E\u4E0D\u5F97\u590D\u7528\uFF08\u91CD\u6302\u4F1A\u5F97\u5230\u65B0\u901A\u9053\uFF09\u3002`,
160
+ { spec }
161
+ );
162
+ }
163
+ function routingNavigationError(spec, reason) {
164
+ return new FgError(
165
+ BridgeErrorCodes.ROUTING_NAVIGATION_INVALID,
166
+ `\u73B0\u8C61\uFF1A\u6865\u63A5\u5E94\u7528 "${spec}" \u7684\u4E00\u6B21\u5BFC\u822A\u8BF7\u6C42\u88AB\u62D2\u7EDD\u3002
167
+ \u539F\u56E0\uFF1A${reason}
168
+ \u4FEE\u6CD5\uFF1A\u5B50\u5E94\u7528\u5BFC\u822A\u76EE\u6807\u5FC5\u987B\u4F4D\u4E8E\u81EA\u8EAB basePath \u524D\u7F00\u5185\uFF08\u8DE8\u524D\u7F00\u8BF7\u7528\u5BBF\u4E3B\u83DC\u5355/\u5BBF\u4E3B\u80FD\u529B\uFF09\uFF1Bgo \u53C2\u6570\u4E3A\u6709\u9650\u6574\u6570\u4E14 |delta| \u2264 50\u3002`,
169
+ { spec }
170
+ );
171
+ }
172
+ function routingSyncError(spec, reason, chain) {
173
+ return new FgError(
174
+ BridgeErrorCodes.ROUTING_SYNC_FAILED,
175
+ `\u73B0\u8C61\uFF1A\u6865\u63A5\u5E94\u7528 "${spec}" \u7684 URL \u540C\u6B65\u5728\u91CD\u5B9A\u5411\u94FE\u4E0A\u8D85\u51FA\u4E0A\u9650\uFF08${chain.length} \u6B21\uFF09\u3002
176
+ \u539F\u56E0\uFF1A${reason}
177
+ \u4FEE\u6CD5\uFF1A\u68C0\u67E5\u5B50\u5E94\u7528\u8DEF\u7531\u7684\u91CD\u5B9A\u5411\u89C4\u5219\u662F\u5426\u4E92\u76F8\u6210\u73AF\uFF1B\u540C\u6B65\u91CD\u5B9A\u5411\u4F7F\u7528 replace \u4E14\u4E0D\u5F97\u5BF9\u540C\u4E00\u4F4D\u7F6E\u91CD\u590D\u53D1\u8D77\u3002\u76EE\u6807\u94FE\uFF1A${chain.join(" \u2192 ")}\u3002`,
178
+ { spec, chain: [...chain] }
179
+ );
180
+ }
137
181
 
138
182
  // src/bridge-core.ts
139
183
  function assertBridgeContract(spec, mod) {
@@ -238,7 +282,267 @@ function withBridgeTimeout(p, ms, spec) {
238
282
  });
239
283
  }
240
284
 
285
+ // src/bridge-router-core.ts
286
+ var MAX_REDIRECT_PER_REQUEST = 5;
287
+ var MAX_GO_DELTA = 50;
288
+ function normalizeBasePath(basePath, spec) {
289
+ const bad = (reason) => routingConfigError(spec, reason);
290
+ if (typeof basePath !== "string" || basePath === "") throw bad("basePath \u4E0D\u80FD\u4E3A\u7A7A\u3002");
291
+ if (basePath === "/") throw bad('basePath \u4E0D\u80FD\u662F\u6839 "/"\u2014\u2014\u6839\u8DEF\u5F84\u5C5E\u4E8E\u5BBF\u4E3B\u81EA\u8EAB\u9875\u9762\uFF0C\u8BF7\u4E3A\u540C\u6B65\u5B9E\u4F8B\u5206\u914D\u72EC\u7ACB\u524D\u7F00\u3002');
292
+ if (!basePath.startsWith("/")) throw bad(`basePath \u5FC5\u987B\u4EE5 "/" \u5F00\u5934\uFF1A\u5F53\u524D\u4E3A "${basePath}"\u3002`);
293
+ if (/[?#]/.test(basePath) || basePath.includes("://")) throw bad(`basePath \u4E0D\u80FD\u5305\u542B query/hash/\u534F\u8BAE\uFF1A\u5F53\u524D\u4E3A "${basePath}"\u3002`);
294
+ if (basePath.includes("*") || basePath.includes(":")) throw bad(`basePath \u4E0D\u63A5\u53D7\u901A\u914D\u7B26\u6216\u53C2\u6570\u6A21\u677F\uFF1A\u5F53\u524D\u4E3A "${basePath}"\u3002\u8BF7\u4F7F\u7528\u9759\u6001\u7EDD\u5BF9\u8DEF\u5F84\u3002`);
295
+ return basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
296
+ }
297
+ function matchesBasePath(hostPathname, basePath) {
298
+ return hostPathname === basePath || hostPathname.startsWith(basePath + "/");
299
+ }
300
+ function overlapsBasePath(a, b) {
301
+ return a === b || a.startsWith(b + "/") || b.startsWith(a + "/");
302
+ }
303
+ function toChildLocation(host, basePath) {
304
+ const rest = host.pathname === basePath ? "/" : host.pathname.slice(basePath.length);
305
+ return { pathname: rest || "/", search: host.search, hash: host.hash };
306
+ }
307
+ function toHostLocation(child, basePath, spec) {
308
+ const childPath = child.pathname === "/" ? "" : child.pathname;
309
+ if (childPath !== "" && !childPath.startsWith("/")) {
310
+ throw routingNavigationError(spec, `\u5BFC\u822A\u76EE\u6807 pathname \u5FC5\u987B\u4EE5 "/" \u5F00\u5934\uFF1A\u5F53\u524D\u4E3A "${child.pathname}"\u3002`);
311
+ }
312
+ return { pathname: basePath + childPath, search: child.search, hash: child.hash };
313
+ }
314
+ function sameLocation(a, b) {
315
+ return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash;
316
+ }
317
+ function assertChildTargetInScope(target, basePath, spec) {
318
+ if (target.pathname.includes("\0") || target.pathname.split("/").includes("..")) {
319
+ throw routingNavigationError(spec, `\u5BFC\u822A\u76EE\u6807\u8BD5\u56FE\u9003\u9038\u81EA\u8EAB\u524D\u7F00\uFF1Apathname "${target.pathname}"\u3002\u8DE8\u524D\u7F00\u5BFC\u822A\u8BF7\u901A\u8FC7\u5BBF\u4E3B\u83DC\u5355\u7B49\u5BBF\u4E3B\u80FD\u529B\u5B8C\u6210\u3002`);
320
+ }
321
+ const host = toHostLocation(target, basePath, spec);
322
+ if (!matchesBasePath(host.pathname, basePath)) {
323
+ throw routingNavigationError(spec, `\u5BFC\u822A\u76EE\u6807 ${host.pathname} \u4E0D\u5728\u524D\u7F00 ${basePath} \u4E0B\u3002`);
324
+ }
325
+ }
326
+ var activeRoutingPrefixes = /* @__PURE__ */ new Map();
327
+ function acquireRoutingPrefix(basePath, spec) {
328
+ for (const [active] of activeRoutingPrefixes) {
329
+ if ((activeRoutingPrefixes.get(active) ?? 0) > 0 && overlapsBasePath(active, basePath)) {
330
+ throw routingConfigError(spec, `\u540C\u9875\u5DF2\u6709\u5360\u7528\u524D\u7F00 "${active}" \u7684\u540C\u6B65\u5B9E\u4F8B\uFF0C\u65B0\u5B9E\u4F8B "${spec}" \u7684 basePath "${basePath}" \u4E0E\u5176\u91CD\u53E0\u3002`);
331
+ }
332
+ }
333
+ activeRoutingPrefixes.set(basePath, (activeRoutingPrefixes.get(basePath) ?? 0) + 1);
334
+ let released = false;
335
+ return () => {
336
+ if (released) return;
337
+ released = true;
338
+ activeRoutingPrefixes.set(basePath, Math.max(0, (activeRoutingPrefixes.get(basePath) ?? 1) - 1));
339
+ };
340
+ }
341
+ function assertBridgeRoutingProtocol(spec, contract) {
342
+ const r = contract?.routing;
343
+ if (!r || r.protocol !== 1) {
344
+ throw routingProtocolError(
345
+ spec,
346
+ `\u8FDC\u7A0B\u5951\u7EA6\u672A\u58F0\u660E\u8DEF\u7531\u534F\u8BAE\uFF08\u671F\u671B routing: { protocol: 1 }\uFF0C\u5B9E\u9645 ${r === void 0 ? "\u7F3A\u5931" : `protocol=${String(r?.protocol)}`}\uFF09\u3002\u5F00\u542F URL \u540C\u6B65\u4E0D\u80FD\u9759\u9ED8\u9000\u56DE memory \u6A21\u5F0F\u3002`
347
+ );
348
+ }
349
+ }
350
+ var RoutingChannel = class {
351
+ id;
352
+ basePath;
353
+ spec;
354
+ host;
355
+ listeners = /* @__PURE__ */ new Set();
356
+ current;
357
+ lastConfirmed;
358
+ seq = 0;
359
+ inflight = null;
360
+ disposed = false;
361
+ active = true;
362
+ releasePrefix;
363
+ unsubHost;
364
+ /** 连续内部 replace 计数(有界重定向检测) */
365
+ redirectChain = [];
366
+ redirectTimer;
367
+ /** 诊断观测钩子(测试断言/诊断用) */
368
+ onEvent;
369
+ constructor(id, basePath, host, spec) {
370
+ this.id = id;
371
+ this.spec = spec;
372
+ this.basePath = normalizeBasePath(basePath, spec);
373
+ this.host = host;
374
+ this.current = toChildLocation(host.getLocation(), this.basePath);
375
+ this.lastConfirmed = { ...this.current };
376
+ this.releasePrefix = acquireRoutingPrefix(this.basePath, spec);
377
+ this.unsubHost = host.subscribe((loc) => this.handleHostLocation(loc));
378
+ }
379
+ emit(loc) {
380
+ this.current = { ...loc };
381
+ for (const l of [...this.listeners]) {
382
+ try {
383
+ l(this.current);
384
+ } catch (e) {
385
+ console.error("[fulgurjs] \u5B50\u5E94\u7528\u8DEF\u7531\u8BA2\u9605\u8005\u5F02\u5E38\uFF08\u5DF2\u9694\u79BB\uFF0C\u4E0D\u5F71\u54CD\u5BBF\u4E3B\uFF09\uFF1A", e);
386
+ }
387
+ }
388
+ }
389
+ handleHostLocation(hostLoc) {
390
+ if (this.disposed) return;
391
+ if (!matchesBasePath(hostLoc.pathname, this.basePath)) {
392
+ this.onEvent?.({ type: "prefix-miss", pathname: hostLoc.pathname });
393
+ return;
394
+ }
395
+ if (!this.active) {
396
+ this.onEvent?.({ type: "paused-host-loc" });
397
+ return;
398
+ }
399
+ const child = toChildLocation(hostLoc, this.basePath);
400
+ if (this.inflight && sameLocation(child, this.inflight.target)) {
401
+ const { seq, resolve } = this.inflight;
402
+ this.inflight = null;
403
+ this.lastConfirmed = child;
404
+ this.emit(child);
405
+ this.onEvent?.({ type: "request-confirmed", seq });
406
+ resolve({ status: "committed", location: { ...child } });
407
+ return;
408
+ }
409
+ if (this.inflight) {
410
+ const { seq, resolve } = this.inflight;
411
+ this.inflight = null;
412
+ this.lastConfirmed = child;
413
+ this.emit(child);
414
+ this.onEvent?.({ type: "request-superseded", seq });
415
+ resolve({ status: "cancelled", location: { ...child } });
416
+ return;
417
+ }
418
+ this.lastConfirmed = child;
419
+ this.emit(child);
420
+ this.onEvent?.({ type: "host-broadcast" });
421
+ }
422
+ getLocation() {
423
+ return { ...this.current };
424
+ }
425
+ subscribe(listener) {
426
+ if (this.disposed) {
427
+ throw routingProtocolError(this.spec, `\u901A\u9053 ${this.id} \u5DF2\u9500\u6BC1\uFF0C\u4E0D\u80FD\u518D\u8BA2\u9605\uFF08\u65E7\u5B9E\u4F8B\u7684\u8FDF\u5230\u8BA2\u9605\u5FC5\u987B\u5931\u6548\uFF1B\u91CD\u6302\u4F1A\u5F97\u5230\u65B0\u901A\u9053\uFF09\u3002`);
428
+ }
429
+ this.listeners.add(listener);
430
+ return () => {
431
+ this.listeners.delete(listener);
432
+ };
433
+ }
434
+ async navigate(target, action) {
435
+ if (this.disposed || !this.active) {
436
+ this.onEvent?.({ type: this.disposed ? "rejected-disposed" : "rejected-inactive" });
437
+ return { status: "cancelled", location: { ...this.lastConfirmed } };
438
+ }
439
+ assertChildTargetInScope(target, this.basePath, this.spec);
440
+ if (sameLocation(target, this.lastConfirmed)) {
441
+ this.onEvent?.({ type: "noop" });
442
+ return { status: "committed", location: { ...this.lastConfirmed } };
443
+ }
444
+ if (action === "replace") {
445
+ this.redirectChain.push(target.pathname + target.search + target.hash);
446
+ } else {
447
+ this.redirectChain = [];
448
+ }
449
+ if (this.redirectTimer) clearTimeout(this.redirectTimer);
450
+ this.redirectTimer = setTimeout(() => {
451
+ this.redirectChain = [];
452
+ }, 1e3);
453
+ if (this.redirectChain.length > MAX_REDIRECT_PER_REQUEST) {
454
+ const chain = [...this.redirectChain];
455
+ this.redirectChain = [];
456
+ throw routingSyncError(this.spec, "\u540C\u4E00\u901A\u9053\u7684\u8FDE\u7EED replace \u91CD\u5B9A\u5411\u8D85\u8FC7\u4E0A\u9650\uFF08\u7591\u4F3C\u5B50\u5E94\u7528\u8DEF\u7531\u4E92\u76F8\u6210\u73AF\uFF09\u3002", chain);
457
+ }
458
+ if (this.inflight) {
459
+ const prev = this.inflight;
460
+ await new Promise((resolve) => {
461
+ const timer = setInterval(() => {
462
+ if (this.inflight !== prev) {
463
+ clearInterval(timer);
464
+ resolve();
465
+ }
466
+ }, 0);
467
+ });
468
+ if (this.disposed || !this.active) {
469
+ return { status: "cancelled", location: { ...this.lastConfirmed } };
470
+ }
471
+ if (sameLocation(target, this.lastConfirmed)) {
472
+ return { status: "committed", location: { ...this.lastConfirmed } };
473
+ }
474
+ }
475
+ const seq = ++this.seq;
476
+ this.onEvent?.({ type: "request-start", seq, target: { ...target }, action });
477
+ return new Promise((resolve) => {
478
+ this.inflight = { seq, target: { ...target }, resolve };
479
+ this.host.navigate(toHostLocation(target, this.basePath, this.spec), action).then((result) => {
480
+ if (!this.inflight || this.inflight.seq !== seq) return;
481
+ if (this.disposed || !this.active) {
482
+ this.inflight = null;
483
+ resolve({ status: "cancelled", location: { ...this.lastConfirmed } });
484
+ return;
485
+ }
486
+ this.inflight = null;
487
+ if (result.status === "committed") {
488
+ const child = toChildLocation(result.location, this.basePath);
489
+ this.lastConfirmed = child;
490
+ this.emit(child);
491
+ } else {
492
+ this.emit({ ...this.lastConfirmed });
493
+ }
494
+ this.onEvent?.({ type: "host-verdict", seq, status: result.status });
495
+ resolve(
496
+ result.status === "committed" ? { status: "committed", location: { ...this.lastConfirmed } } : { status: "cancelled", location: { ...this.lastConfirmed } }
497
+ );
498
+ }).catch(() => {
499
+ if (this.inflight?.seq === seq) {
500
+ this.inflight = null;
501
+ this.onEvent?.({ type: "host-error", seq });
502
+ this.emit({ ...this.lastConfirmed });
503
+ resolve({ status: "cancelled", location: { ...this.lastConfirmed } });
504
+ }
505
+ });
506
+ });
507
+ }
508
+ /** 委托宿主历史(有限整数);不创建第二条独立历史 */
509
+ go(delta) {
510
+ if (this.disposed || !this.active) return;
511
+ if (typeof delta !== "number" || !Number.isInteger(delta) || Math.abs(delta) > MAX_GO_DELTA) {
512
+ throw routingNavigationError(this.spec, `go \u53C2\u6570\u5FC5\u987B\u662F\u6709\u9650\u6574\u6570\uFF08|delta| \u2264 ${MAX_GO_DELTA}\uFF09\uFF1A\u5F53\u524D\u4E3A ${String(delta)}\u3002`);
513
+ }
514
+ this.host.go(delta);
515
+ }
516
+ /** KeepAlive deactivate:暂停广播与写入;通道与订阅保留(activate 后 resync) */
517
+ setActive(active) {
518
+ if (this.disposed) return;
519
+ this.active = active;
520
+ this.onEvent?.({ type: active ? "resumed" : "paused" });
521
+ if (active) this.handleHostLocation(this.host.getLocation());
522
+ }
523
+ /** 挂载生命周期结束:清理订阅/登记/在飞请求;此后一切写入失效 */
524
+ dispose() {
525
+ if (this.disposed) return;
526
+ this.disposed = true;
527
+ if (this.redirectTimer) clearTimeout(this.redirectTimer);
528
+ this.unsubHost();
529
+ this.releasePrefix();
530
+ if (this.inflight) {
531
+ const { resolve } = this.inflight;
532
+ this.inflight = null;
533
+ resolve({ status: "cancelled", location: { ...this.lastConfirmed } });
534
+ }
535
+ this.listeners.clear();
536
+ this.onEvent?.({ type: "disposed" });
537
+ }
538
+ };
539
+
241
540
  // src/bridge-host-vue.ts
541
+ var assertBridgeRoutingProtocolSpec = (spec, contract) => assertBridgeRoutingProtocol(spec, contract);
542
+ function routingKey(routing) {
543
+ if (!routing) return void 0;
544
+ return routing.basePath + "|" + String(routing.navigation && typeof routing.navigation.navigate === "function");
545
+ }
242
546
  var ERROR_STYLE = {
243
547
  padding: "16px",
244
548
  border: "1px solid #fde2e2",
@@ -316,7 +620,9 @@ function createVueBridgeAppWithLoader(loadRemote) {
316
620
  props: {
317
621
  appProps: { type: Object, required: false, default: void 0 },
318
622
  // 桥接控制参数:undefined(不启用受控会话)/ null(登出态)/ 非空字符串(登录代次)
319
- sessionKey: { type: null, required: false, default: void 0 }
623
+ sessionKey: { type: null, required: false, default: void 0 },
624
+ // URL 同步控制通道(独立于 appProps/Context;省略 = 原 memory 模式)
625
+ routing: { type: Object, required: false, default: void 0 }
320
626
  },
321
627
  setup(props) {
322
628
  const status = (0, import_vue.ref)("idle");
@@ -326,6 +632,8 @@ function createVueBridgeAppWithLoader(loadRemote) {
326
632
  let contract;
327
633
  let containerBlocked = false;
328
634
  let acquiredSession;
635
+ let channel;
636
+ let genAbort;
329
637
  const releaseAcquired = () => {
330
638
  if (acquiredSession !== void 0) {
331
639
  releaseBridgeSession(acquiredSession);
@@ -337,6 +645,10 @@ function createVueBridgeAppWithLoader(loadRemote) {
337
645
  generation++;
338
646
  const el = container.value;
339
647
  releaseAcquired();
648
+ genAbort?.abort();
649
+ genAbort = void 0;
650
+ channel?.dispose();
651
+ channel = void 0;
340
652
  if (contract && el) {
341
653
  const c = contract;
342
654
  contract = void 0;
@@ -378,7 +690,18 @@ function createVueBridgeAppWithLoader(loadRemote) {
378
690
  if (myGeneration !== generation) return;
379
691
  contract = assertBridgeContract(spec, mod);
380
692
  const appPropsSource = props.appProps ? (0, import_vue.toRaw)(props.appProps) : void 0;
381
- await contract.mount(el, { ...appPropsSource ?? {} });
693
+ genAbort = new AbortController();
694
+ let mountOptions = { signal: genAbort.signal };
695
+ if (props.routing) {
696
+ assertBridgeRoutingProtocolSpec(spec, contract);
697
+ const navigation = props.routing.navigation;
698
+ const latestLoc = navigation.getLocation();
699
+ if (myGeneration !== generation) return;
700
+ channel = new RoutingChannel(`bridge-vue:${spec}:${myGeneration}`, props.routing.basePath, navigation, spec);
701
+ mountOptions = { signal: genAbort.signal, routing: channel };
702
+ void latestLoc;
703
+ }
704
+ await contract.mount(el, { ...appPropsSource ?? {} }, mountOptions);
382
705
  if (myGeneration !== generation) return;
383
706
  status.value = "ready";
384
707
  } catch (e) {
@@ -403,6 +726,15 @@ function createVueBridgeAppWithLoader(loadRemote) {
403
726
  (0, import_vue.watch)(() => props.sessionKey, () => {
404
727
  start();
405
728
  });
729
+ (0, import_vue.watch)(() => routingKey(props.routing), (after, before) => {
730
+ if (after !== before) start();
731
+ });
732
+ (0, import_vue.onDeactivated)(() => {
733
+ channel?.setActive(false);
734
+ });
735
+ (0, import_vue.onActivated)(() => {
736
+ channel?.setActive(true);
737
+ });
406
738
  (0, import_vue.onBeforeUnmount)(() => {
407
739
  invalidate();
408
740
  });
@@ -1,3 +1,7 @@
1
+ import {
2
+ RoutingChannel,
3
+ assertBridgeRoutingProtocol
4
+ } from "./chunk-WOTR2FUQ.js";
1
5
  import {
2
6
  acquireBridgeSession,
3
7
  assertBridgeContract,
@@ -6,17 +10,22 @@ import {
6
10
  releaseBridgeSession,
7
11
  resolveBridgeContext,
8
12
  withBridgeTimeout
9
- } from "./chunk-LE2G23E7.js";
13
+ } from "./chunk-PRUYHYX2.js";
10
14
  import {
11
15
  bridgeLifecycleError
12
- } from "./chunk-DH2QMM4Y.js";
16
+ } from "./chunk-JQF7KYZF.js";
13
17
  import {
14
18
  provideAppContext
15
19
  } from "./chunk-TSYLDY6H.js";
16
20
  import "./chunk-OF2JCXTZ.js";
17
21
 
18
22
  // src/bridge-host-vue.ts
19
- import { defineComponent, h, onBeforeUnmount, onMounted, ref, shallowRef, toRaw, watch } from "vue";
23
+ import { defineComponent, h, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, shallowRef, toRaw, watch } from "vue";
24
+ var assertBridgeRoutingProtocolSpec = (spec, contract) => assertBridgeRoutingProtocol(spec, contract);
25
+ function routingKey(routing) {
26
+ if (!routing) return void 0;
27
+ return routing.basePath + "|" + String(routing.navigation && typeof routing.navigation.navigate === "function");
28
+ }
20
29
  var ERROR_STYLE = {
21
30
  padding: "16px",
22
31
  border: "1px solid #fde2e2",
@@ -94,7 +103,9 @@ function createVueBridgeAppWithLoader(loadRemote) {
94
103
  props: {
95
104
  appProps: { type: Object, required: false, default: void 0 },
96
105
  // 桥接控制参数:undefined(不启用受控会话)/ null(登出态)/ 非空字符串(登录代次)
97
- sessionKey: { type: null, required: false, default: void 0 }
106
+ sessionKey: { type: null, required: false, default: void 0 },
107
+ // URL 同步控制通道(独立于 appProps/Context;省略 = 原 memory 模式)
108
+ routing: { type: Object, required: false, default: void 0 }
98
109
  },
99
110
  setup(props) {
100
111
  const status = ref("idle");
@@ -104,6 +115,8 @@ function createVueBridgeAppWithLoader(loadRemote) {
104
115
  let contract;
105
116
  let containerBlocked = false;
106
117
  let acquiredSession;
118
+ let channel;
119
+ let genAbort;
107
120
  const releaseAcquired = () => {
108
121
  if (acquiredSession !== void 0) {
109
122
  releaseBridgeSession(acquiredSession);
@@ -115,6 +128,10 @@ function createVueBridgeAppWithLoader(loadRemote) {
115
128
  generation++;
116
129
  const el = container.value;
117
130
  releaseAcquired();
131
+ genAbort?.abort();
132
+ genAbort = void 0;
133
+ channel?.dispose();
134
+ channel = void 0;
118
135
  if (contract && el) {
119
136
  const c = contract;
120
137
  contract = void 0;
@@ -156,7 +173,18 @@ function createVueBridgeAppWithLoader(loadRemote) {
156
173
  if (myGeneration !== generation) return;
157
174
  contract = assertBridgeContract(spec, mod);
158
175
  const appPropsSource = props.appProps ? toRaw(props.appProps) : void 0;
159
- await contract.mount(el, { ...appPropsSource ?? {} });
176
+ genAbort = new AbortController();
177
+ let mountOptions = { signal: genAbort.signal };
178
+ if (props.routing) {
179
+ assertBridgeRoutingProtocolSpec(spec, contract);
180
+ const navigation = props.routing.navigation;
181
+ const latestLoc = navigation.getLocation();
182
+ if (myGeneration !== generation) return;
183
+ channel = new RoutingChannel(`bridge-vue:${spec}:${myGeneration}`, props.routing.basePath, navigation, spec);
184
+ mountOptions = { signal: genAbort.signal, routing: channel };
185
+ void latestLoc;
186
+ }
187
+ await contract.mount(el, { ...appPropsSource ?? {} }, mountOptions);
160
188
  if (myGeneration !== generation) return;
161
189
  status.value = "ready";
162
190
  } catch (e) {
@@ -181,6 +209,15 @@ function createVueBridgeAppWithLoader(loadRemote) {
181
209
  watch(() => props.sessionKey, () => {
182
210
  start();
183
211
  });
212
+ watch(() => routingKey(props.routing), (after, before) => {
213
+ if (after !== before) start();
214
+ });
215
+ onDeactivated(() => {
216
+ channel?.setActive(false);
217
+ });
218
+ onActivated(() => {
219
+ channel?.setActive(true);
220
+ });
184
221
  onBeforeUnmount(() => {
185
222
  invalidate();
186
223
  });
@@ -1,12 +1,14 @@
1
1
  import * as react from 'react';
2
- import { R as ReactBridgeAppOptions } from './bridge-host-react-C55RmGll.js';
3
- export { B as BridgeErrorFallback } from './bridge-host-react-C55RmGll.js';
4
- export { A as AppContext, B as BridgeApp } from './bridge-core-6uLJiMVa.js';
2
+ import { B as BridgeHostRouting } from './bridge-core-BOWvVUxO.js';
3
+ export { A as AppContext, a as BridgeApp } from './bridge-core-BOWvVUxO.js';
4
+ import { R as ReactBridgeAppOptions } from './bridge-host-react-CMVd-ym0.js';
5
+ export { B as BridgeErrorFallback } from './bridge-host-react-CMVd-ym0.js';
5
6
 
6
7
  /** React 宿主桥接工厂:返回 `ComponentType<{ appProps: P; sessionKey?: string | null }>` */
7
8
  declare const createReactBridgeApp: <P = Record<string, unknown>>(spec: string, options?: ReactBridgeAppOptions) => react.ComponentType<{
8
9
  appProps?: P;
9
10
  sessionKey?: string | null;
11
+ routing?: BridgeHostRouting;
10
12
  }>;
11
13
 
12
14
  export { ReactBridgeAppOptions, createReactBridgeApp };
@@ -0,0 +1,44 @@
1
+ /** 统一逻辑位置:pathname 以 / 开头;search 空串或 ? 开头;hash 空串或 # 开头 */
2
+ interface BridgeLocation {
3
+ pathname: string;
4
+ search: string;
5
+ hash: string;
6
+ }
7
+ type BridgeNavigationResult = {
8
+ status: 'committed';
9
+ location: BridgeLocation;
10
+ } | {
11
+ status: 'cancelled';
12
+ location: BridgeLocation;
13
+ };
14
+ /** 宿主导航端口(宿主适配器把 Router 包装成本接口;逻辑路径不含部署 base) */
15
+ interface BridgeHostNavigation {
16
+ getLocation(): BridgeLocation;
17
+ subscribe(listener: (location: BridgeLocation) => void): () => void;
18
+ navigate(target: BridgeLocation, action: 'push' | 'replace'): Promise<BridgeNavigationResult>;
19
+ go(delta: number): void;
20
+ }
21
+ /** 子应用路由通道(桥接宿主按挂载代次创建,随 mount 第三参数交给子应用) */
22
+ interface BridgeChildRoute {
23
+ getLocation(): BridgeLocation;
24
+ subscribe(listener: (location: BridgeLocation) => void): () => void;
25
+ navigate(target: BridgeLocation, action: 'push' | 'replace'): Promise<BridgeNavigationResult>;
26
+ go(delta: number): void;
27
+ }
28
+ /** 挂载控制参数(mount 第三参数;不混入业务 props) */
29
+ interface BridgeMountOptions {
30
+ signal?: AbortSignal;
31
+ routing?: BridgeChildRoute;
32
+ }
33
+ /** 子应用路由协议声明(defineBridgeApp(工厂, { routing: true }) 时写入) */
34
+ interface BridgeRoutingProtocol {
35
+ protocol: 1;
36
+ }
37
+ /** 宿主组件 routing prop(独立控制通道,不进 appProps/Context) */
38
+ interface BridgeHostRouting {
39
+ /** 宿主路由视角的静态绝对路径,如 "/approval";同页各同步实例不得相同或重叠 */
40
+ basePath: string;
41
+ navigation: BridgeHostNavigation;
42
+ }
43
+
44
+ export type { BridgeChildRoute as B, BridgeMountOptions as a, BridgeRoutingProtocol as b, BridgeHostRouting as c };
@@ -0,0 +1,44 @@
1
+ /** 统一逻辑位置:pathname 以 / 开头;search 空串或 ? 开头;hash 空串或 # 开头 */
2
+ interface BridgeLocation {
3
+ pathname: string;
4
+ search: string;
5
+ hash: string;
6
+ }
7
+ type BridgeNavigationResult = {
8
+ status: 'committed';
9
+ location: BridgeLocation;
10
+ } | {
11
+ status: 'cancelled';
12
+ location: BridgeLocation;
13
+ };
14
+ /** 宿主导航端口(宿主适配器把 Router 包装成本接口;逻辑路径不含部署 base) */
15
+ interface BridgeHostNavigation {
16
+ getLocation(): BridgeLocation;
17
+ subscribe(listener: (location: BridgeLocation) => void): () => void;
18
+ navigate(target: BridgeLocation, action: 'push' | 'replace'): Promise<BridgeNavigationResult>;
19
+ go(delta: number): void;
20
+ }
21
+ /** 子应用路由通道(桥接宿主按挂载代次创建,随 mount 第三参数交给子应用) */
22
+ interface BridgeChildRoute {
23
+ getLocation(): BridgeLocation;
24
+ subscribe(listener: (location: BridgeLocation) => void): () => void;
25
+ navigate(target: BridgeLocation, action: 'push' | 'replace'): Promise<BridgeNavigationResult>;
26
+ go(delta: number): void;
27
+ }
28
+ /** 挂载控制参数(mount 第三参数;不混入业务 props) */
29
+ interface BridgeMountOptions {
30
+ signal?: AbortSignal;
31
+ routing?: BridgeChildRoute;
32
+ }
33
+ /** 子应用路由协议声明(defineBridgeApp(工厂, { routing: true }) 时写入) */
34
+ interface BridgeRoutingProtocol {
35
+ protocol: 1;
36
+ }
37
+ /** 宿主组件 routing prop(独立控制通道,不进 appProps/Context) */
38
+ interface BridgeHostRouting {
39
+ /** 宿主路由视角的静态绝对路径,如 "/approval";同页各同步实例不得相同或重叠 */
40
+ basePath: string;
41
+ navigation: BridgeHostNavigation;
42
+ }
43
+
44
+ export type { BridgeChildRoute as B, BridgeMountOptions as a, BridgeRoutingProtocol as b, BridgeHostRouting as c };