vitral 0.3.0 → 0.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 (55) hide show
  1. package/dist/angular.d.ts +2 -2
  2. package/dist/angular.js +7 -7
  3. package/dist/auto.js +7 -7
  4. package/dist/{capture-JYFERAPL.js → capture-TT5WBLJ6.js} +1 -1
  5. package/dist/channel-2YPYGX3J.js +95 -0
  6. package/dist/{chunk-AKNNHQ2H.js → chunk-463H6B56.js} +5 -0
  7. package/dist/chunk-54CBIZES.js +105 -0
  8. package/dist/{chunk-ZAC6QQI6.js → chunk-6EX5KYT5.js} +4 -4
  9. package/dist/{chunk-3YXI3G34.js → chunk-BCC25ANK.js} +11 -5
  10. package/dist/{chunk-TD4S3IHA.js → chunk-EMSB2NVX.js} +10 -8
  11. package/dist/{chunk-SDB5AZEI.js → chunk-IH3ZT3QU.js} +2 -2
  12. package/dist/{chunk-GNHCZRQP.js → chunk-TW7KYJQ6.js} +1 -1
  13. package/dist/{chunk-AH7KNMBW.js → chunk-UYOPJ4XQ.js} +1 -1
  14. package/dist/{chunk-IHTUM6LT.js → chunk-W6322KGP.js} +2 -2
  15. package/dist/{chunk-I3VSKSAZ.js → chunk-WD4CDGDZ.js} +21 -20
  16. package/dist/cli.js +1152 -37
  17. package/dist/devtools.d.ts +32 -2
  18. package/dist/devtools.js +27 -12
  19. package/dist/element.d.ts +12 -3
  20. package/dist/element.js +7 -7
  21. package/dist/embed.js +2 -0
  22. package/dist/{events-D5gs7rff.d.ts → events-Dkpkw_Sv.d.ts} +1 -1
  23. package/dist/expose-OVWTPHH5.js +15 -0
  24. package/dist/federation.d.ts +89 -0
  25. package/dist/federation.js +101 -0
  26. package/dist/iframe.js +7 -7
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.js +5 -5
  29. package/dist/overrides-NP754HY7.js +27 -0
  30. package/dist/preact.d.ts +4 -4
  31. package/dist/preact.js +6 -6
  32. package/dist/react.d.ts +3 -3
  33. package/dist/react.js +6 -6
  34. package/dist/routes.d.ts +2 -2
  35. package/dist/routes.js +5 -5
  36. package/dist/{shadow-6HELCHCJ.js → shadow-PVSETNMZ.js} +66 -5
  37. package/dist/single-spa.d.ts +40 -0
  38. package/dist/single-spa.js +52 -0
  39. package/dist/{slot-DqXTwGbs.d.ts → slot-UPg6ob9v.d.ts} +1 -1
  40. package/dist/solid.d.ts +3 -3
  41. package/dist/solid.js +6 -6
  42. package/dist/{sri-JMX6JLQP.js → sri-M7ZRU57G.js} +40 -10
  43. package/dist/svelte.d.ts +4 -4
  44. package/dist/svelte.js +6 -6
  45. package/dist/testing.d.ts +1 -1
  46. package/dist/testing.js +5 -5
  47. package/dist/{types-Czvm-siZ.d.ts → types-CA2p9KHC.d.ts} +112 -4
  48. package/dist/vite.d.ts +18 -0
  49. package/dist/vite.js +341 -35
  50. package/dist/vue.d.ts +3 -3
  51. package/dist/vue.js +6 -6
  52. package/package.json +79 -21
  53. package/dist/chunk-DXORSF4X.js +0 -42
  54. package/dist/expose-JUOUN5N5.js +0 -15
  55. package/dist/overrides-NZAIUGK5.js +0 -15
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ReactNode, ComponentType } from 'react';
2
2
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
3
3
  import * as JSXRuntime from 'react/jsx-runtime';
4
- import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared, R as RemoteContext } from './types-Czvm-siZ.js';
5
- export { E as EventBus } from './types-Czvm-siZ.js';
6
- export { e as events } from './events-D5gs7rff.js';
4
+ import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared, R as RemoteContext } from './types-CA2p9KHC.js';
5
+ export { E as EventBus } from './types-CA2p9KHC.js';
6
+ export { e as events } from './events-Dkpkw_Sv.js';
7
7
  import './errors-kjBv6IH_.js';
8
8
 
9
9
  /**
package/dist/react.js CHANGED
@@ -1,18 +1,18 @@
1
1
  "use client";
2
2
  import {
3
3
  hostSlot
4
- } from "./chunk-IHTUM6LT.js";
4
+ } from "./chunk-W6322KGP.js";
5
5
  import {
6
6
  defineRemote,
7
7
  events,
8
8
  memoSelect,
9
9
  same,
10
10
  shared
11
- } from "./chunk-I3VSKSAZ.js";
12
- import "./chunk-TD4S3IHA.js";
13
- import "./chunk-ZAC6QQI6.js";
14
- import "./chunk-GNHCZRQP.js";
15
- import "./chunk-AKNNHQ2H.js";
11
+ } from "./chunk-WD4CDGDZ.js";
12
+ import "./chunk-EMSB2NVX.js";
13
+ import "./chunk-6EX5KYT5.js";
14
+ import "./chunk-TW7KYJQ6.js";
15
+ import "./chunk-463H6B56.js";
16
16
  import {
17
17
  protocol
18
18
  } from "./chunk-GNPFWISJ.js";
package/dist/routes.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as Props } from './types-Czvm-siZ.js';
2
- import { S as SlotStatus } from './slot-DqXTwGbs.js';
1
+ import { P as Props } from './types-CA2p9KHC.js';
2
+ import { S as SlotStatus } from './slot-UPg6ob9v.js';
3
3
  import './errors-kjBv6IH_.js';
4
4
 
5
5
  /** Padrão de URL → nome do remote. A primeira rota que bate vence. */
package/dist/routes.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createSlot,
3
3
  navigate
4
- } from "./chunk-I3VSKSAZ.js";
5
- import "./chunk-TD4S3IHA.js";
6
- import "./chunk-ZAC6QQI6.js";
7
- import "./chunk-GNHCZRQP.js";
8
- import "./chunk-AKNNHQ2H.js";
4
+ } from "./chunk-WD4CDGDZ.js";
5
+ import "./chunk-EMSB2NVX.js";
6
+ import "./chunk-6EX5KYT5.js";
7
+ import "./chunk-TW7KYJQ6.js";
8
+ import "./chunk-463H6B56.js";
9
9
  import "./chunk-GNPFWISJ.js";
10
10
 
11
11
  // src/routes.ts
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  fetchCssText,
3
3
  injectCss
4
- } from "./chunk-ZAC6QQI6.js";
5
- import "./chunk-GNHCZRQP.js";
6
- import "./chunk-AKNNHQ2H.js";
4
+ } from "./chunk-6EX5KYT5.js";
5
+ import "./chunk-TW7KYJQ6.js";
6
+ import "./chunk-463H6B56.js";
7
7
  import "./chunk-GNPFWISJ.js";
8
8
 
9
9
  // src/core/shadow.ts
@@ -23,6 +23,66 @@ function prefetch(r, priority) {
23
23
  for (const u of urls) fetchCssText(u, r.sri?.[u], priority).catch(noop);
24
24
  injectCss(global, null, r.sri);
25
25
  }
26
+ async function attachShadowRoot(target, make, r, global = {}, local = {}) {
27
+ const name = make().getAttribute("data-vitral-root");
28
+ let registry = registryFor(name);
29
+ let root = target.shadowRoot;
30
+ if (!root && !fake(registry))
31
+ try {
32
+ root = target.attachShadow({ mode: "open", customElementRegistry: registry });
33
+ } catch {
34
+ broken = true;
35
+ registries.delete(name);
36
+ registry = registryFor(name);
37
+ }
38
+ root ??= target.attachShadow({ mode: "open" });
39
+ const own = root.customElementRegistry ?? registry;
40
+ let el = make();
41
+ if (!fake(own))
42
+ try {
43
+ el = make({ customElementRegistry: own });
44
+ } catch {
45
+ }
46
+ root.appendChild(el);
47
+ return [...await attachStyles(root, el, r, global, local), root, own, el];
48
+ }
49
+ var registries = /* @__PURE__ */ new Map();
50
+ var broken = false;
51
+ var fake = (registry) => Object.getPrototypeOf(registry) === customElements;
52
+ var owners = /* @__PURE__ */ new Map();
53
+ function registryFor(name) {
54
+ let registry = registries.get(name);
55
+ if (registry) return registry;
56
+ let real = customElements;
57
+ if (!broken && "initialize" in CustomElementRegistry.prototype)
58
+ try {
59
+ real = new CustomElementRegistry();
60
+ } catch {
61
+ broken = true;
62
+ }
63
+ const shared = real === customElements;
64
+ const own = registry = shared ? Object.create(real) : real;
65
+ if (shared) {
66
+ for (const k of ["get", "getName", "upgrade", "whenDefined"]) if (k in real) own[k] = real[k].bind(real);
67
+ }
68
+ const define = real.define;
69
+ own.define = (tag, ctor, options) => {
70
+ const had = real.get(tag);
71
+ const owner = owners.get(tag);
72
+ if (!had) return shared && owners.set(tag, name), define.call(real, tag, ctor, options);
73
+ if (shared && had !== ctor && owner !== name && dev())
74
+ console.warn(`[vitral] ${name}: <${tag}> j\xE1 foi definido por ${owner ?? "outro c\xF3digo"}; fica essa defini\xE7\xE3o. Sem Scoped Custom Element Registries, os remotes dividem o registro global.`);
75
+ };
76
+ registries.set(name, registry);
77
+ return registry;
78
+ }
79
+ function dev() {
80
+ try {
81
+ return process.env.NODE_ENV !== "production";
82
+ } catch {
83
+ return false;
84
+ }
85
+ }
26
86
  async function attachStyles(root, el, r, global = {}, local = {}) {
27
87
  const sri = r.sri ?? {};
28
88
  const [css, ready, up] = plan(r);
@@ -93,6 +153,7 @@ function mirrorTheme(el) {
93
153
  return () => observer.disconnect();
94
154
  }
95
155
  export {
96
- attachStyles,
97
- prefetch
156
+ attachShadowRoot,
157
+ prefetch,
158
+ registryFor
98
159
  };
@@ -0,0 +1,40 @@
1
+ import { P as Props, a as RemoteModule } from './types-CA2p9KHC.js';
2
+ import './errors-kjBv6IH_.js';
3
+
4
+ /**
5
+ * App do single-spa como remote do vitral, sem reescrever o app:
6
+ *
7
+ * // src/vitral-remote.js
8
+ * import { singleSpaRemote } from 'vitral/single-spa'
9
+ * import * as lifecycles from './main' // exporta bootstrap, mount e unmount
10
+ *
11
+ * export default singleSpaRemote(lifecycles)
12
+ *
13
+ * Funciona com os lifecycles de `single-spa-react`, `single-spa-vue`,
14
+ * `single-spa-angular` etc. e com lifecycles escritos à mão. Os lifecycles
15
+ * recebem as props do host mais `name` e `domElement` (o elemento do remote).
16
+ */
17
+
18
+ /** Um lifecycle do single-spa: uma função ou uma lista delas, em sequência. */
19
+ type SingleSpaLifecycle = ((props: any) => unknown) | ((props: any) => unknown)[];
20
+ /** O que um app ou parcel do single-spa exporta. */
21
+ interface SingleSpaLifecycles {
22
+ bootstrap?: SingleSpaLifecycle;
23
+ mount: SingleSpaLifecycle;
24
+ unmount: SingleSpaLifecycle;
25
+ update?: SingleSpaLifecycle;
26
+ }
27
+ /**
28
+ * Embrulha os lifecycles de um app do single-spa no contrato `mount`.
29
+ *
30
+ * - `bootstrap` roda uma vez, antes do primeiro `mount`.
31
+ * - Os lifecycles nunca se sobrepõem: um `mount` espera o `unmount` anterior.
32
+ * - `update(props)` chama o `update` do app (parcels); sem ele, o app é
33
+ * desmontado e montado de novo com as props novas.
34
+ * - Duas instâncias ao mesmo tempo recebem `name` diferentes (`conta`, `conta-2`).
35
+ */
36
+ declare function singleSpaRemote<P extends Props = Props>(lifecycles: SingleSpaLifecycles | {
37
+ default: SingleSpaLifecycles;
38
+ }): RemoteModule<P>;
39
+
40
+ export { type SingleSpaLifecycle, type SingleSpaLifecycles, singleSpaRemote };
@@ -0,0 +1,52 @@
1
+ // src/single-spa.ts
2
+ async function run(fns, props) {
3
+ for (const fn of [fns ?? []].flat()) await fn(props);
4
+ }
5
+ function singleSpaRemote(lifecycles) {
6
+ const l = "mount" in lifecycles ? lifecycles : lifecycles.default;
7
+ if (typeof l?.mount == "undefined" || typeof l.unmount == "undefined") throw new Error("[vitral] singleSpaRemote: faltam os lifecycles mount e unmount");
8
+ let booted;
9
+ let queue = Promise.resolve();
10
+ const used = /* @__PURE__ */ new Set();
11
+ const step = (fn) => queue = queue.then(fn, fn);
12
+ const boot = (props) => booted ??= run(l.bootstrap, props).catch((e) => {
13
+ booted = void 0;
14
+ throw e;
15
+ });
16
+ return {
17
+ async mount(el, props, ctx) {
18
+ let name = ctx.name;
19
+ for (let i = 2; used.has(name); i++) name = `${ctx.name}-${i}`;
20
+ used.add(name);
21
+ let current = { ...props, name, domElement: el };
22
+ try {
23
+ await step(async () => {
24
+ await boot(current);
25
+ await run(l.mount, current);
26
+ });
27
+ } catch (e) {
28
+ used.delete(name);
29
+ throw e;
30
+ }
31
+ const report = (e) => ctx.reportError(e);
32
+ return {
33
+ update(next) {
34
+ const before = current;
35
+ current = { ...next, name, domElement: el };
36
+ const job = l.update ? step(() => run(l.update, current)) : step(async () => {
37
+ await run(l.unmount, before);
38
+ await run(l.mount, current);
39
+ });
40
+ job.catch(report);
41
+ },
42
+ unmount() {
43
+ used.delete(name);
44
+ step(() => run(l.unmount, current)).catch(report);
45
+ }
46
+ };
47
+ }
48
+ };
49
+ }
50
+ export {
51
+ singleSpaRemote
52
+ };
@@ -1,5 +1,5 @@
1
1
  import { R as RemoteError } from './errors-kjBv6IH_.js';
2
- import { P as Props, I as Isolation, b as StyleOptions } from './types-Czvm-siZ.js';
2
+ import { P as Props, I as Isolation, d as StyleOptions } from './types-CA2p9KHC.js';
3
3
 
4
4
  type SlotStatus = 'loading' | 'ready' | 'error';
5
5
  interface SlotOptions<P extends Props = Props> {
package/dist/solid.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JSX, Component, Accessor } from 'solid-js';
2
- import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared } from './types-Czvm-siZ.js';
3
- export { R as RemoteContext } from './types-Czvm-siZ.js';
2
+ import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared } from './types-CA2p9KHC.js';
3
+ export { R as RemoteContext } from './types-CA2p9KHC.js';
4
4
  import { R as RemoteError } from './errors-kjBv6IH_.js';
5
- export { e as events } from './events-D5gs7rff.js';
5
+ export { e as events } from './events-Dkpkw_Sv.js';
6
6
  export { n as navigate } from './navigate-BRG1WJUM.js';
7
7
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
8
8
 
package/dist/solid.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-IHTUM6LT.js";
3
+ } from "./chunk-W6322KGP.js";
4
4
  import {
5
5
  defineRemote,
6
6
  events,
@@ -8,11 +8,11 @@ import {
8
8
  navigate,
9
9
  same,
10
10
  shared
11
- } from "./chunk-I3VSKSAZ.js";
12
- import "./chunk-TD4S3IHA.js";
13
- import "./chunk-ZAC6QQI6.js";
14
- import "./chunk-GNHCZRQP.js";
15
- import "./chunk-AKNNHQ2H.js";
11
+ } from "./chunk-WD4CDGDZ.js";
12
+ import "./chunk-EMSB2NVX.js";
13
+ import "./chunk-6EX5KYT5.js";
14
+ import "./chunk-TW7KYJQ6.js";
15
+ import "./chunk-463H6B56.js";
16
16
  import "./chunk-GNPFWISJ.js";
17
17
 
18
18
  // src/solid.ts
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  verifyIntegrity
3
- } from "./chunk-AH7KNMBW.js";
3
+ } from "./chunk-UYOPJ4XQ.js";
4
4
  import {
5
5
  addLink,
6
6
  fetchBytes,
7
7
  withTimeout
8
- } from "./chunk-GNHCZRQP.js";
8
+ } from "./chunk-TW7KYJQ6.js";
9
9
  import {
10
10
  RemoteError
11
- } from "./chunk-AKNNHQ2H.js";
11
+ } from "./chunk-463H6B56.js";
12
12
  import "./chunk-GNPFWISJ.js";
13
13
 
14
14
  // src/core/sri.ts
@@ -41,7 +41,24 @@ var STRICT = /^(sha(256|384|512)-[A-Za-z0-9+/]+={0,2}( +|$))+$/;
41
41
  var PROBE = "data:text/javascript,export{}";
42
42
  var PROBE_SRI = "sha256-d3bjIZdvLjBurwdLwkSVOnEBPFFly+T1SR9r3VVHBGg=";
43
43
  var maps;
44
+ var probing;
44
45
  var preloads;
46
+ var KEY = "vitral:sri-map";
47
+ async function useMap(sri) {
48
+ if (probing) return await probing && addMap(sri, false);
49
+ let seen = false;
50
+ try {
51
+ seen = localStorage[KEY] === navigator.userAgent;
52
+ } catch {
53
+ }
54
+ const ok = await (probing = addMap(sri, !seen));
55
+ if (ok && !seen)
56
+ try {
57
+ localStorage[KEY] = navigator.userAgent;
58
+ } catch {
59
+ }
60
+ return ok;
61
+ }
45
62
  var tick = () => new Promise((resolve) => {
46
63
  const c = new MessageChannel();
47
64
  c.port1.onmessage = () => resolve();
@@ -65,7 +82,7 @@ async function verified(build, run) {
65
82
  }
66
83
  });
67
84
  };
68
- if (maps !== false && (maps = await addMap(sri))) {
85
+ if (maps !== false && (maps = await useMap(sri))) {
69
86
  await share();
70
87
  for (const u of chunks) fetch(u, { priority }).catch(() => {
71
88
  });
@@ -78,7 +95,12 @@ async function verified(build, run) {
78
95
  return entry;
79
96
  }
80
97
  }
81
- async function addMap(integrity) {
98
+ async function addMap(sri, probe) {
99
+ if (!HTMLScriptElement.supports?.("importmap")) return false;
100
+ const integrity = {};
101
+ for (const u in sri) if (!/\.css([?#]|$)/.test(u)) integrity[u] = sri[u];
102
+ const urls = probe ? ["export{}", "export{}//"].map((c) => URL.createObjectURL(new Blob([c], { type: "text/javascript" }))) : [];
103
+ for (const u of urls) integrity[u] = PROBE_SRI;
82
104
  let ok = true;
83
105
  try {
84
106
  const s = document.createElement("script");
@@ -88,11 +110,17 @@ async function addMap(integrity) {
88
110
  s.addEventListener("securitypolicyviolation", () => ok = false);
89
111
  s.textContent = JSON.stringify({ integrity });
90
112
  document.head.append(s);
113
+ await tick();
114
+ await tick();
115
+ if (ok && probe) ok = await check((u) => import(
116
+ /* @vite-ignore */
117
+ /* webpackIgnore: true */
118
+ u
119
+ ), urls[0], urls[1]);
91
120
  } catch {
92
- return false;
121
+ ok = false;
93
122
  }
94
- await tick();
95
- await tick();
123
+ for (const u of urls) URL.revokeObjectURL(u);
96
124
  return ok;
97
125
  }
98
126
  function preload(href, integrity, fetchPriority = "auto") {
@@ -104,9 +132,11 @@ function preload(href, integrity, fetchPriority = "auto") {
104
132
  }
105
133
  function checkPreloads() {
106
134
  if (!document.createElement("link").relList.supports("modulepreload")) return Promise.resolve(false);
107
- const run = (href, good) => preload(href, PROBE_SRI).then(() => good, () => !good);
135
+ return check((href) => preload(href, PROBE_SRI), PROBE, PROBE + "//");
136
+ }
137
+ function check(load, good, bad) {
108
138
  return Promise.race([
109
- Promise.all([run(PROBE, true), run(PROBE + "//", false)]).then(([a, b]) => a && b),
139
+ Promise.all([load(good).then(() => true, () => false), load(bad).then(() => false, () => true)]).then(([a, b]) => a && b),
110
140
  new Promise((resolve) => setTimeout(resolve, 3e3, false))
111
141
  ]);
112
142
  }
package/dist/svelte.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Component } from 'svelte';
2
- import { P as Props, I as Isolation, a as RemoteModule } from './types-Czvm-siZ.js';
3
- export { R as RemoteContext } from './types-Czvm-siZ.js';
2
+ import { P as Props, I as Isolation, a as RemoteModule } from './types-CA2p9KHC.js';
3
+ export { R as RemoteContext } from './types-CA2p9KHC.js';
4
4
  import { R as RemoteError } from './errors-kjBv6IH_.js';
5
- import { S as SlotStatus } from './slot-DqXTwGbs.js';
6
- export { e as events } from './events-D5gs7rff.js';
5
+ import { S as SlotStatus } from './slot-UPg6ob9v.js';
6
+ export { e as events } from './events-Dkpkw_Sv.js';
7
7
  export { n as navigate } from './navigate-BRG1WJUM.js';
8
8
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
9
9
 
package/dist/svelte.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-IHTUM6LT.js";
3
+ } from "./chunk-W6322KGP.js";
4
4
  import {
5
5
  defineRemote,
6
6
  events,
7
7
  navigate
8
- } from "./chunk-I3VSKSAZ.js";
9
- import "./chunk-TD4S3IHA.js";
10
- import "./chunk-ZAC6QQI6.js";
11
- import "./chunk-GNHCZRQP.js";
12
- import "./chunk-AKNNHQ2H.js";
8
+ } from "./chunk-WD4CDGDZ.js";
9
+ import "./chunk-EMSB2NVX.js";
10
+ import "./chunk-6EX5KYT5.js";
11
+ import "./chunk-TW7KYJQ6.js";
12
+ import "./chunk-463H6B56.js";
13
13
  import "./chunk-GNPFWISJ.js";
14
14
 
15
15
  // src/svelte.ts
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as Props, R as RemoteContext } from './types-Czvm-siZ.js';
1
+ import { P as Props, R as RemoteContext } from './types-CA2p9KHC.js';
2
2
  export { r as resetVitral } from './state-BDdCwc21.js';
3
3
  import './errors-kjBv6IH_.js';
4
4
 
package/dist/testing.js CHANGED
@@ -1,10 +1,10 @@
1
- import "./chunk-I3VSKSAZ.js";
1
+ import "./chunk-WD4CDGDZ.js";
2
2
  import {
3
3
  register
4
- } from "./chunk-TD4S3IHA.js";
5
- import "./chunk-ZAC6QQI6.js";
6
- import "./chunk-GNHCZRQP.js";
7
- import "./chunk-AKNNHQ2H.js";
4
+ } from "./chunk-EMSB2NVX.js";
5
+ import "./chunk-6EX5KYT5.js";
6
+ import "./chunk-TW7KYJQ6.js";
7
+ import "./chunk-463H6B56.js";
8
8
  import {
9
9
  resetProtocol
10
10
  } from "./chunk-GNPFWISJ.js";
@@ -99,6 +99,17 @@ interface RemoteContext {
99
99
  * Hosts antigos não mandam este campo.
100
100
  */
101
101
  portalContainer?: HTMLElement;
102
+ /**
103
+ * Registro de custom elements do remote. No Shadow DOM, onde o navegador
104
+ * tem Scoped Custom Element Registries (Chrome 146+, Safari 26+), é um
105
+ * registro só deste remote, usado pelo shadow root e pelo elemento `el`:
106
+ * dois remotes podem definir `<ds-button>` de versões diferentes. Sem
107
+ * suporte, e fora do Shadow DOM, é o `customElements` global. No Shadow
108
+ * DOM, `define` de uma tag já definida não lança: fica a definição que já
109
+ * existe, com um aviso em dev quando ela veio de outro remote. Hosts
110
+ * antigos não mandam este campo: use `ctx.customElements ?? customElements`.
111
+ */
112
+ customElements?: CustomElementRegistry;
102
113
  /** Avisa o host de um erro em tempo de execução (os adaptadores já chamam). */
103
114
  reportError(error: unknown): void;
104
115
  /** Navega a página inteira (host e todos os roteadores) para `url`. */
@@ -124,6 +135,21 @@ interface RemoteContext {
124
135
  * (`provide`, `shared` ou um hook); senão, importe `shared` de 'vitral'.
125
136
  */
126
137
  shared?: SharedApi;
138
+ /**
139
+ * Só quando o remote roda como MCP App (`vitral({ target: 'mcp-app' })`):
140
+ * fala JSON-RPC direto com o host MCP, para o que `events` não cobre
141
+ * (`tools/call`, `resources/read`, `ui/request-display-mode`…).
142
+ */
143
+ mcp?: McpAppBridge;
144
+ }
145
+ /** `ctx.mcp` de um remote empacotado como MCP App. */
146
+ interface McpAppBridge {
147
+ /** Pedido ao host; resolve com `result` ou rejeita com `error.message`. */
148
+ request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
149
+ /** Notificação ao host (sem resposta). */
150
+ notify(method: string, params?: Record<string, unknown>): void;
151
+ /** O `hostContext` atual (tema, idioma, tamanho do container…), já com as mudanças. */
152
+ hostContext(): Record<string, unknown> | undefined;
127
153
  }
128
154
  interface MountedRemote<P extends Props = Props> {
129
155
  update?(props: P): void;
@@ -149,7 +175,7 @@ interface RemoteEntry {
149
175
  /** Isolamento padrão para este remote. */
150
176
  isolate?: Isolation;
151
177
  /**
152
- * O `vitral.json` já baixado (ex.: por `vitral registry`), para não buscá-lo
178
+ * O `vitral.json` já baixado (ex.: no build do host), para não buscá-lo
153
179
  * na hora. Os caminhos dele são relativos a `url`, e os hashes ficam fixos
154
180
  * no host.
155
181
  */
@@ -159,6 +185,60 @@ interface RemoteEntry {
159
185
  * Vence a de `configure`. Veja `VitralConfig.contract`.
160
186
  */
161
187
  contract?: string;
188
+ /**
189
+ * Com `url` apontando para um canal (`canal.json`): escolhe a versão deste
190
+ * usuário. Devolve a versão (`'1.5.0'`) ou a URL de um `vitral.json`;
191
+ * `undefined` usa a regra padrão (`canary.percent`). Veja `Channel`.
192
+ */
193
+ resolve?: (channel: Channel, ctx: ChannelContext) => string | undefined | Promise<string | undefined>;
194
+ /**
195
+ * Volta para a estável, até o fim da sessão, quando a versão que não é a
196
+ * estável gera `errors` erros numa janela de `mounts` montagens. Padrão
197
+ * `{ errors: 3, mounts: 20 }`. `false` desliga.
198
+ */
199
+ rollback?: {
200
+ errors?: number;
201
+ mounts?: number;
202
+ } | false;
203
+ }
204
+ /**
205
+ * Arquivo-ponteiro de um remote (o canal, ex.: `canal.json`): diz que versão
206
+ * cada usuário recebe. Cada versão fica na própria pasta, ao lado do canal
207
+ * (`'1.4.0'` → `1.4.0/vitral.json`), ou é a URL de um `vitral.json`.
208
+ *
209
+ * { "stable": "1.4.0", "canary": { "version": "1.5.0", "percent": 10 } }
210
+ */
211
+ interface Channel {
212
+ /** Versão de todos os usuários fora da canary. */
213
+ stable: string;
214
+ /** Versão nova para `percent`% dos usuários (0 a 100). */
215
+ canary?: {
216
+ version: string;
217
+ percent: number;
218
+ };
219
+ /** Campos próprios, para o `resolve` do host ler (ex.: `"beta": "1.6.0"`). */
220
+ [key: string]: unknown;
221
+ }
222
+ /** O que o `resolve` de um canal recebe além do canal. */
223
+ interface ChannelContext {
224
+ /** Nome do remote. */
225
+ name: string;
226
+ /**
227
+ * Número de 0 a 99, sempre o mesmo para este navegador (ou para
228
+ * `canaryKey`) e este remote. A regra padrão dá a canary a quem tem
229
+ * `bucket < percent`.
230
+ */
231
+ bucket: number;
232
+ }
233
+ /** Aviso de rollback automático, para `configure({ onRollback })`. */
234
+ interface RollbackInfo {
235
+ name: string;
236
+ /** Versão abandonada (como o canal ou o `resolve` a escreveram). */
237
+ from: string;
238
+ /** Versão estável, usada daqui até o fim da sessão. */
239
+ to: string;
240
+ errors: number;
241
+ mounts: number;
162
242
  }
163
243
  /**
164
244
  * `none`: CSS com escopo. `shadow`: Shadow DOM. `iframe`: iframe com
@@ -178,6 +258,15 @@ interface StyleOptions {
178
258
  */
179
259
  mirrorTheme?: boolean;
180
260
  }
261
+ /** Opções de `configure({ devOverrides })`. */
262
+ interface DevOverrides {
263
+ /**
264
+ * Modelo da URL de um apelido: `?vitral=checkout@pr-123` com
265
+ * `'https://{name}-{ref}.preview.empresa.com'` vira
266
+ * `https://checkout-pr-123.preview.empresa.com/vitral.json`.
267
+ */
268
+ preview?: string;
269
+ }
181
270
  interface VitralConfig {
182
271
  /** Mapa nome → URL (ou entrada completa), ou a URL de um JSON com esse mapa. */
183
272
  remotes?: Record<string, string | RemoteEntry> | string;
@@ -196,9 +285,10 @@ interface VitralConfig {
196
285
  * Liga os overrides de desenvolvimento (`?vitral=nome@url` e
197
286
  * `localStorage['vitral:overrides']`) fora de localhost. Em localhost já
198
287
  * valem. Nunca ligue em produção: um link com `?vitral=` executaria código
199
- * de qualquer origem.
288
+ * de qualquer origem. O objeto também liga e aceita `preview`, o modelo de
289
+ * URL dos apelidos (`?vitral=checkout@pr-123`).
200
290
  */
201
- devOverrides?: boolean;
291
+ devOverrides?: boolean | DevOverrides;
202
292
  /** Estilos do host no Shadow DOM: `{ inherit: ['/assets/base.css'] }`. */
203
293
  styles?: StyleOptions;
204
294
  /** Recebe o tempo de cada etapa do carregamento (para RUM). */
@@ -232,6 +322,16 @@ interface VitralConfig {
232
322
  * conferido. `'*'` confere só as dependências.
233
323
  */
234
324
  contract?: string;
325
+ /**
326
+ * Chave estável do usuário (ex.: o id dele) para sortear quem recebe a
327
+ * canary de um canal. Padrão: um id aleatório guardado no `localStorage`.
328
+ */
329
+ canaryKey?: string;
330
+ /**
331
+ * Chamado quando a versão canary de um canal passa do limite de erros e o
332
+ * host volta para a estável (veja `RemoteEntry.rollback`).
333
+ */
334
+ onRollback?: (info: RollbackInfo) => void;
235
335
  }
236
336
  /** Módulos de um grupo de `dedupe`, por especificador (`'react-dom/client'`). */
237
337
  type SharedModules = Record<string, unknown>;
@@ -294,6 +394,14 @@ interface RemoteManifest {
294
394
  * antigos), o runtime faz esse trabalho em cada página.
295
395
  */
296
396
  shadow?: ShadowCss;
397
+ /**
398
+ * SBOM CycloneDX do remote (opção `sbom` do plugin): o arquivo, relativo
399
+ * ao manifesto, e o hash dele. O runtime não usa; é para auditoria.
400
+ */
401
+ sbom?: {
402
+ file: string;
403
+ integrity: string;
404
+ };
297
405
  }
298
406
  /** Contrato do remote no `vitral.json`. */
299
407
  interface RemoteContract {
@@ -324,4 +432,4 @@ interface EventBus {
324
432
  last<T = unknown>(type: string): T | undefined;
325
433
  }
326
434
 
327
- export { type CheckedProps as C, type EventBus as E, type Handler as H, type Isolation as I, type MountedRemote as M, type Props as P, type RemoteContext as R, type Shared as S, type VitralConfig as V, type RemoteModule as a, type StyleOptions as b, type RemoteEntry as c, type SharedValue as d, type PropsOf as e, type ProvideOptions as f, type ProvidedValue as g, type RemoteContract as h, type RemoteManifest as i, type RemoteMetric as j, type Remotes as k, type SharedApi as l, type SharedModules as m, type SharedType as n, batch as o, provide as p, shared as s };
435
+ export { type CheckedProps as C, type DevOverrides as D, type EventBus as E, type Handler as H, type Isolation as I, type MountedRemote as M, type Props as P, type RemoteContext as R, type Shared as S, type VitralConfig as V, type RemoteModule as a, type SharedModules as b, type RemoteEntry as c, type StyleOptions as d, type SharedValue as e, type Channel as f, type ChannelContext as g, type McpAppBridge as h, type PropsOf as i, type ProvideOptions as j, type ProvidedValue as k, type RemoteContract as l, type RemoteManifest as m, type RemoteMetric as n, type Remotes as o, type RollbackInfo as p, type SharedApi as q, type SharedType as r, batch as s, provide as t, shared as u };
package/dist/vite.d.ts CHANGED
@@ -80,6 +80,24 @@ interface VitralViteOptions extends CssBuildOptions {
80
80
  contract?: {
81
81
  version?: string;
82
82
  };
83
+ /**
84
+ * Gera `sbom.cdx.json` (CycloneDX 1.6) com os pacotes npm que entraram no
85
+ * bundle, e o `vitral.json` aponta para ele em `sbom`. Padrão: false.
86
+ */
87
+ sbom?: boolean;
88
+ /**
89
+ * `'mcp-app'`: o build gera só `mcp-app.html`, um HTML único com o JS e o
90
+ * CSS inline, para um servidor MCP servir como recurso `ui://` (MCP Apps).
91
+ * As notificações do host viram props e `ctx.events.emit` vira mensagem
92
+ * para o host. Não combina com `exposes`, `dedupe` nem `shared`.
93
+ */
94
+ target?: 'mcp-app';
95
+ /**
96
+ * Grava o build em uma pasta por versão (`dist/1.5.0/`), para publicar
97
+ * cada versão sem apagar as anteriores e escolher qual vale num canal
98
+ * (`canal.json`). Usa `version` (ou a do package.json). Padrão: false.
99
+ */
100
+ versionDir?: boolean;
83
101
  }
84
102
  declare function vitral(options?: VitralViteOptions): Plugin;
85
103