vitral 0.10.1 → 0.11.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 (87) hide show
  1. package/dist/angular.d.ts +2 -2
  2. package/dist/angular.js +13 -10
  3. package/dist/auto.js +11 -8
  4. package/dist/{capture-A6JQNNQY.js → capture-2I5IQ2C2.js} +2 -1
  5. package/dist/{channel-2DUQQPPA.js → channel-ABGK26Q5.js} +5 -3
  6. package/dist/{chunk-WAU6OKK3.js → chunk-2SAI6S2H.js} +11 -3
  7. package/dist/chunk-2Z4OH3BP.js +85 -0
  8. package/dist/chunk-5O6XDJBR.js +15 -0
  9. package/dist/chunk-623K4UNS.js +70 -0
  10. package/dist/{chunk-VTGHPX4J.js → chunk-6JH2I65O.js} +15 -13
  11. package/dist/{chunk-FOEXP52G.js → chunk-7P5O3REI.js} +46 -15
  12. package/dist/{chunk-EVVYV5ED.js → chunk-AL6MLNVY.js} +49 -21
  13. package/dist/{chunk-CFJC4GRB.js → chunk-AQUQD3NA.js} +17 -8
  14. package/dist/chunk-B3PFMWZT.js +21 -0
  15. package/dist/{chunk-463H6B56.js → chunk-BQGVAXFM.js} +3 -4
  16. package/dist/{chunk-TW7KYJQ6.js → chunk-GGMM56TM.js} +1 -1
  17. package/dist/{chunk-SC2KF7GJ.js → chunk-IKCEA3YN.js} +3 -3
  18. package/dist/chunk-JWDDXX5O.js +6 -0
  19. package/dist/{chunk-B2MPYF4M.js → chunk-KCF46XOX.js} +4 -2
  20. package/dist/{chunk-R3HUMHNL.js → chunk-LDOSAAEF.js} +15 -0
  21. package/dist/{chunk-MGG5BW3U.js → chunk-MICF64AZ.js} +2 -2
  22. package/dist/{chunk-QINOFHG6.js → chunk-NQ6ZTGQZ.js} +2 -2
  23. package/dist/chunk-QQWE5J6U.js +37 -0
  24. package/dist/{chunk-VK6W7KHM.js → chunk-SPSAXBPR.js} +10 -6
  25. package/dist/{chunk-UYOPJ4XQ.js → chunk-UCFOXMOR.js} +1 -1
  26. package/dist/cli.js +119 -8
  27. package/dist/{contract-IXM52LVW.js → contract-3JY7SOGQ.js} +1 -1
  28. package/dist/{dedupe-SRAPOK3V.js → dedupe-M63VMCWA.js} +3 -1
  29. package/dist/edge.d.ts +4 -2
  30. package/dist/edge.js +69 -46
  31. package/dist/element.d.ts +2 -2
  32. package/dist/element.js +11 -8
  33. package/dist/embed.js +2 -2
  34. package/dist/{events-CWdYSrkz.d.ts → events-II6hXM3Q.d.ts} +1 -1
  35. package/dist/expose-2S3TCXSP.js +18 -0
  36. package/dist/federation.d.ts +1 -1
  37. package/dist/{hydrate-IVQNHOP3.js → hydrate-FJHHLW5G.js} +22 -12
  38. package/dist/iframe.js +15 -12
  39. package/dist/index.d.ts +6 -6
  40. package/dist/index.js +25 -11
  41. package/dist/{loader-CLRMRRFv.d.ts → loader-Bmul2-5T.d.ts} +1 -1
  42. package/dist/next-config.d.ts +30 -10
  43. package/dist/next-config.js +29 -20
  44. package/dist/next-host.d.ts +11 -5
  45. package/dist/next-host.js +54 -29
  46. package/dist/next-server.d.ts +56 -0
  47. package/dist/next-server.js +90 -0
  48. package/dist/preact.d.ts +4 -4
  49. package/dist/preact.js +10 -7
  50. package/dist/prefetch.d.ts +40 -3
  51. package/dist/prefetch.js +100 -30
  52. package/dist/react-server.d.ts +16 -5
  53. package/dist/react-server.js +8 -3
  54. package/dist/react.d.ts +20 -6
  55. package/dist/react.js +14 -9
  56. package/dist/{reframe-ZOQPW552.js → reframe-HIYA2TIU.js} +10 -9
  57. package/dist/route-4KQITYD4.js +138 -0
  58. package/dist/routes.d.ts +2 -2
  59. package/dist/routes.js +12 -9
  60. package/dist/{shadow-PZGQKUA4.js → shadow-7ZV4JEO6.js} +4 -3
  61. package/dist/sign.d.ts +49 -0
  62. package/dist/sign.js +15 -0
  63. package/dist/single-spa.d.ts +1 -1
  64. package/dist/{slot-DRYmGvvV.d.ts → slot--WLgdcW_.d.ts} +1 -1
  65. package/dist/snapshot.d.ts +6 -0
  66. package/dist/snapshot.js +125 -0
  67. package/dist/solid.d.ts +3 -3
  68. package/dist/solid.js +10 -7
  69. package/dist/sri-AMQOKKWR.js +17 -0
  70. package/dist/ssr-markup-BCPpGmss.d.ts +13 -0
  71. package/dist/state-B1FJi8I9.d.ts +14 -0
  72. package/dist/svelte.d.ts +4 -4
  73. package/dist/svelte.js +10 -7
  74. package/dist/sw.d.ts +48 -1
  75. package/dist/sw.js +79 -2
  76. package/dist/testing.d.ts +2 -2
  77. package/dist/testing.js +10 -7
  78. package/dist/{types-g8WEVD_b.d.ts → types-DJautV-K.d.ts} +86 -1
  79. package/dist/vitals.js +2 -1
  80. package/dist/vite.d.ts +4 -2
  81. package/dist/vite.js +62 -12
  82. package/dist/vue.d.ts +3 -3
  83. package/dist/vue.js +12 -9
  84. package/package.json +37 -19
  85. package/dist/expose-BA4HSXDP.js +0 -17
  86. package/dist/sri-LQBLQMG5.js +0 -14
  87. package/dist/state-BDdCwc21.d.ts +0 -4
@@ -1,13 +1,18 @@
1
1
  import {
2
2
  RemoteTree
3
- } from "./chunk-B2MPYF4M.js";
3
+ } from "./chunk-KCF46XOX.js";
4
4
  import "./chunk-MLKGABMK.js";
5
5
 
6
6
  // src/react-server.tsx
7
7
  import { renderToString } from "react-dom/server";
8
8
  import { jsx } from "react/jsx-runtime";
9
- function reactRender(Component) {
10
- return (props) => renderToString(/* @__PURE__ */ jsx(RemoteTree, { Component, props, ctx: null }));
9
+ function reactRender(Component, options) {
10
+ if (!options?.state) return (props) => renderToString(/* @__PURE__ */ jsx(RemoteTree, { Component, props, ctx: null }));
11
+ const load = options.state;
12
+ return async (props) => {
13
+ const state = await load(props);
14
+ return { html: renderToString(/* @__PURE__ */ jsx(RemoteTree, { Component, props, ctx: null, state })), state };
15
+ };
11
16
  }
12
17
  export {
13
18
  reactRender
package/dist/react.d.ts CHANGED
@@ -1,10 +1,10 @@
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-g8WEVD_b.js';
5
- export { E as EventBus } from './types-g8WEVD_b.js';
6
- import { P as PreloadOptions } from './loader-CLRMRRFv.js';
7
- export { e as events } from './events-CWdYSrkz.js';
4
+ import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared, R as RemoteContext } from './types-DJautV-K.js';
5
+ export { E as EventBus } from './types-DJautV-K.js';
6
+ import { P as PreloadOptions } from './loader-Bmul2-5T.js';
7
+ export { e as events } from './events-II6hXM3Q.js';
8
8
  import './errors-kjBv6IH_.js';
9
9
 
10
10
  /**
@@ -22,6 +22,12 @@ import './errors-kjBv6IH_.js';
22
22
  declare function reactRemote<P extends Props>(Component: ComponentType<P>): RemoteModule<P>;
23
23
  /** Dentro de um remote: dá acesso ao contexto (nome, eventos, baseUrl). */
24
24
  declare function useVitral(): RemoteContext | null;
25
+ /**
26
+ * Dentro de um remote: o estado que o `render` do servidor buscou
27
+ * (`reactRender(C, { state })`). O mesmo no SSR e na hidratação; numa
28
+ * montagem sem SSR, `undefined`.
29
+ */
30
+ declare function useInitialState<T = unknown>(): T | undefined;
25
31
  /**
26
32
  * Dentro de um remote: onde renderizar portais. No Shadow DOM é um elemento
27
33
  * dentro do shadow root (com os estilos do remote); fora de um remote,
@@ -64,6 +70,14 @@ interface RemoteProps<P extends Props = Props> {
64
70
  priority?: RequestPriority;
65
71
  /** Ao sair da página, guarda o remote montado (LRU, padrão 5) e na volta só atualiza as props. */
66
72
  keepAlive?: boolean | number;
73
+ /**
74
+ * HTML do remote renderizado no servidor (`remoteProps` de
75
+ * `vitral/next-server` com `ssr`). Aparece antes do JS e o remote hidrata
76
+ * em vez de montar. As `props` têm de ser as mesmas do servidor.
77
+ */
78
+ ssr?: string | null;
79
+ /** Mostra a última tela do remote na visita de volta (`snapshots()` de `vitral/snapshot`). */
80
+ snapshot?: boolean;
67
81
  }
68
82
  /**
69
83
  * Começa a baixar um remote antes de algum `<Remote>` montar (no ocioso, no
@@ -76,6 +90,6 @@ declare function preload(name: string, options?: PreloadOptions): void;
76
90
  * remote monta no cliente, então não há erro de hidratação. Com o nome em
77
91
  * `Remotes` (`npx vitral types`), as props são checadas.
78
92
  */
79
- declare function Remote<P extends Props = Props, N extends string = string>({ name, src, props, isolate, fallback, error, onError, className, loading, prefetch, priority, keepAlive, }: RemoteProps<P> & CheckedProps<N>): JSXRuntime.JSX.Element;
93
+ declare function Remote<P extends Props = Props, N extends string = string>({ name, src, props, isolate, fallback, error, onError, className, loading, prefetch, priority, keepAlive, ssr, snapshot, }: RemoteProps<P> & CheckedProps<N>): JSXRuntime.JSX.Element;
80
94
 
81
- export { Remote, type RemoteProps, preload, reactRemote, useEvent, useEventValue, usePortalContainer, useShared, useVitral };
95
+ export { Remote, type RemoteProps, preload, reactRemote, useEvent, useEventValue, useInitialState, usePortalContainer, useShared, useVitral };
package/dist/react.js CHANGED
@@ -5,21 +5,25 @@ import {
5
5
  reactRemote,
6
6
  useEvent,
7
7
  useEventValue,
8
+ useInitialState,
8
9
  usePortalContainer,
9
10
  useShared,
10
11
  useVitral
11
- } from "./chunk-FOEXP52G.js";
12
- import "./chunk-B2MPYF4M.js";
13
- import "./chunk-WAU6OKK3.js";
14
- import "./chunk-VTGHPX4J.js";
12
+ } from "./chunk-7P5O3REI.js";
13
+ import "./chunk-KCF46XOX.js";
14
+ import "./chunk-2SAI6S2H.js";
15
+ import "./chunk-6JH2I65O.js";
16
+ import "./chunk-AL6MLNVY.js";
17
+ import "./chunk-MICF64AZ.js";
18
+ import "./chunk-IKCEA3YN.js";
19
+ import "./chunk-GGMM56TM.js";
20
+ import "./chunk-BQGVAXFM.js";
21
+ import "./chunk-JWDDXX5O.js";
22
+ import "./chunk-2Z4OH3BP.js";
23
+ import "./chunk-4E33RZMM.js";
15
24
  import {
16
25
  events
17
26
  } from "./chunk-EQZOJU3B.js";
18
- import "./chunk-EVVYV5ED.js";
19
- import "./chunk-MGG5BW3U.js";
20
- import "./chunk-SC2KF7GJ.js";
21
- import "./chunk-TW7KYJQ6.js";
22
- import "./chunk-463H6B56.js";
23
27
  import "./chunk-GNPFWISJ.js";
24
28
  import "./chunk-MLKGABMK.js";
25
29
  export {
@@ -29,6 +33,7 @@ export {
29
33
  reactRemote,
30
34
  useEvent,
31
35
  useEventValue,
36
+ useInitialState,
32
37
  usePortalContainer,
33
38
  useShared,
34
39
  useVitral
@@ -1,27 +1,28 @@
1
1
  import {
2
2
  splitName
3
- } from "./chunk-QINOFHG6.js";
3
+ } from "./chunk-NQ6ZTGQZ.js";
4
4
  import {
5
5
  verifyIntegrity
6
- } from "./chunk-UYOPJ4XQ.js";
6
+ } from "./chunk-UCFOXMOR.js";
7
7
  import {
8
8
  resolveEntry
9
- } from "./chunk-EVVYV5ED.js";
10
- import "./chunk-MGG5BW3U.js";
9
+ } from "./chunk-AL6MLNVY.js";
10
+ import "./chunk-MICF64AZ.js";
11
11
  import {
12
12
  prefetchCss
13
- } from "./chunk-SC2KF7GJ.js";
13
+ } from "./chunk-IKCEA3YN.js";
14
14
  import {
15
15
  fetchBytes,
16
16
  metric,
17
17
  withRetry,
18
18
  withTimeout
19
- } from "./chunk-TW7KYJQ6.js";
19
+ } from "./chunk-GGMM56TM.js";
20
20
  import {
21
21
  RemoteError,
22
22
  isRemoteError,
23
23
  report
24
- } from "./chunk-463H6B56.js";
24
+ } from "./chunk-BQGVAXFM.js";
25
+ import "./chunk-JWDDXX5O.js";
25
26
  import {
26
27
  protocol
27
28
  } from "./chunk-GNPFWISJ.js";
@@ -57,12 +58,12 @@ async function load(name, _isolate, priority) {
57
58
  prefetchCss(r, true, priority);
58
59
  t = performance.now();
59
60
  const bytes = integrity && await withRetry(retries, async () => {
60
- const b = await fetchBytes(r.entry, timeout, name, { priority });
61
+ const b = await fetchBytes(r.entry, timeout, name, { priority, .../ed25519-/.test(integrity) && { integrity } });
61
62
  await verifyIntegrity(name, b, integrity);
62
63
  return b;
63
64
  });
64
65
  const url = bytes ? URL.createObjectURL(new Blob([bytes], { type: "text/javascript" })) : r.entry;
65
- const { registryFor } = await import("./shadow-PZGQKUA4.js");
66
+ const { registryFor } = await import("./shadow-7ZV4JEO6.js");
66
67
  realm = createRealm(r.name ?? name, registryFor(r.name ?? name));
67
68
  let ns;
68
69
  try {
@@ -0,0 +1,138 @@
1
+ import "./chunk-MLKGABMK.js";
2
+
3
+ // src/cli/route.ts
4
+ import { existsSync, readFileSync } from "fs";
5
+ import { join, resolve } from "path";
6
+ var SHELL = ["main", "main-app", "pages/_app", "webpack", "react-refresh"];
7
+ var LOCALE = /(^|[/\\])(locales?|i18n|lang|langs|translations?|messages)[/\\](.*[/\\])?[^/\\]*\.json$/i;
8
+ var KB = (n) => `${Math.round(n / 1024)} kB`;
9
+ var pkgOf = (name) => {
10
+ const m = /node_modules[/\\]((?:@[^/\\]+[/\\])?[^/\\]+)/.exec(name.split("!").pop().replace(/.*node_modules[/\\]\.pnpm[/\\][^/\\]+[/\\]node_modules/, "node_modules"));
11
+ return m?.[1].replace(/\\/g, "/");
12
+ };
13
+ function leaves(list = []) {
14
+ return list.flatMap((m) => m.modules?.length ? leaves(m.modules) : [m]);
15
+ }
16
+ function client(s) {
17
+ if (s.entrypoints && Object.keys(s.entrypoints).some((k) => k.startsWith("pages/") || k === "main")) return s;
18
+ return s.children?.map(client).find((c) => c.entrypoints) ?? s;
19
+ }
20
+ function routeEntry(names, route) {
21
+ const r = route.replace(/^\/+/, "").replace(/\/+$/, "") || "index";
22
+ return names.find((n) => n === route) ?? names.find((n) => n === `pages/${r}`) ?? names.find((n) => n === `pages/${r}/index`) ?? names.find((n) => n.startsWith(`pages/${r}/`) && /\[/.test(n));
23
+ }
24
+ function routeReport(o) {
25
+ const cwd = o.cwd ?? process.cwd();
26
+ const raw = JSON.parse(readFileSync(resolve(cwd, o.stats), "utf8"));
27
+ const s = client(raw);
28
+ const groups = { ...s.namedChunkGroups, ...s.entrypoints };
29
+ const names = Object.keys(groups);
30
+ const page = routeEntry(names, o.route);
31
+ if (!page) throw new Error(`[vitral] a rota ${o.route} n\xE3o est\xE1 nos stats. Entrypoints: ${names.filter((n) => n.startsWith("pages/")).join(", ") || names.join(", ")}`);
32
+ const entries = [...SHELL.filter((n) => groups[n]), page];
33
+ const ids = new Set(entries.flatMap((n) => groups[n].chunks ?? []).map(String));
34
+ const fromChunks = (s.chunks ?? []).filter((c) => ids.has(String(c.id))).flatMap((c) => leaves(c.modules));
35
+ const all = fromChunks.length ? fromChunks : leaves(s.modules).filter((m) => m.chunks?.some((c) => ids.has(String(c))));
36
+ const seen = /* @__PURE__ */ new Map();
37
+ for (const m of all) seen.set(m.identifier ?? m.name ?? "", m);
38
+ const mods = [...seen.values()].filter((m) => (m.size ?? 0) > 0 && !/^(webpack\/runtime|\(webpack\))/.test(m.name ?? ""));
39
+ const byPkg = /* @__PURE__ */ new Map();
40
+ let bytes = 0;
41
+ for (const m of mods) {
42
+ bytes += m.size;
43
+ const p = pkgOf(m.name ?? "") ?? "(c\xF3digo do app)";
44
+ byPkg.set(p, (byPkg.get(p) ?? 0) + m.size);
45
+ }
46
+ const top = o.top ?? 15;
47
+ const packages = [...byPkg].map(([name, b]) => ({ name, bytes: b })).sort((a, b) => b.bytes - a.bytes);
48
+ const short = (n) => n.replace(/^(.*?[/\\])?node_modules[/\\](\.pnpm[/\\][^/\\]+[/\\]node_modules[/\\])?/, "node_modules/");
49
+ const modules = mods.map((m) => ({ name: short(m.name ?? "?"), bytes: m.size })).sort((a, b) => b.bytes - a.bytes);
50
+ const checks = [];
51
+ const locales = mods.filter((m) => LOCALE.test(m.name ?? ""));
52
+ const localeBytes = locales.reduce((n, m) => n + m.size, 0);
53
+ if (localeBytes > 20 * 1024)
54
+ checks.push({
55
+ status: "warn",
56
+ title: `tradu\xE7\xF5es no JS da rota: ${locales.length} arquivo(s), ${KB(localeBytes)}`,
57
+ cause: "cada l\xEDngua e cada namespace entram no bundle, mesmo os que a p\xE1gina n\xE3o mostra; o navegador baixa e interpreta tudo antes de hidratar",
58
+ fix: "carregue a l\xEDngua ativa sob demanda (import() por l\xEDngua ou um backend HTTP do i18next) e deixe no bundle s\xF3 o idioma padr\xE3o, se precisar"
59
+ });
60
+ const dead = mods.filter((m) => Array.isArray(m.providedExports) && m.providedExports.length > 0 && (m.usedExports === false || Array.isArray(m.usedExports) && m.usedExports.length === 0));
61
+ const deadBytes = dead.reduce((n, m) => n + m.size, 0);
62
+ if (deadBytes > 10 * 1024) {
63
+ const pk = [...new Set(dead.map((m) => pkgOf(m.name ?? "")).filter(Boolean))].slice(0, 5);
64
+ checks.push({
65
+ status: "warn",
66
+ title: `${dead.length} m\xF3dulo(s) sem nenhum export usado na rota: ${KB(deadBytes)}`,
67
+ cause: `o webpack s\xF3 os mant\xE9m por efeito colateral${pk.length ? ` (${pk.join(", ")})` : ""}: o pacote n\xE3o declara "sideEffects": false, ou um arquivo do barrel tem c\xF3digo no topo`,
68
+ fix: 'declare "sideEffects": false (ou a lista dos arquivos com efeito) no package.json do pacote, ou importe do subpath em vez do barrel'
69
+ });
70
+ }
71
+ const whole = mods.filter((m) => m.usedExports === true && m.reasons?.some((r) => /\.vitral[/\\]host-config/.test(r.moduleName ?? "")));
72
+ const wholeBytes = whole.reduce((n, m) => n + m.size, 0);
73
+ if (wholeBytes > 10 * 1024)
74
+ checks.push({
75
+ status: "warn",
76
+ title: `ofertas de share com todos os exports: ${whole.length} m\xF3dulo(s), ${KB(wholeBytes)}`,
77
+ cause: "a oferta foi gerada sem os nomes que o remote usa: o build do host n\xE3o achou o vitral.json de algum remote, ou o manifesto \xE9 de uma vers\xE3o anterior \xE0 0.10",
78
+ fix: "deixe o vitral.json de cada remote em public/ ou em manifestFile no build do host, e rebuilde o remote com vitral 0.10 ou mais nova"
79
+ });
80
+ const hostPkgs = new Map(packages.map((p) => [p.name, p.bytes]));
81
+ for (const r of o.remotes ?? []) checks.push(...overlap(resolve(cwd, r), hostPkgs, cwd));
82
+ if (!checks.length) checks.push({ status: "ok", title: "nada fora do comum nos bytes da rota" });
83
+ return { route: page, entries, bytes, packages: packages.slice(0, top), modules: modules.slice(0, top), checks };
84
+ }
85
+ function overlap(path, host, cwd) {
86
+ const dir = path.endsWith(".json") ? resolve(path, "..") : path;
87
+ const file = path.endsWith(".json") ? path : join(dir, "vitral.json");
88
+ let m;
89
+ try {
90
+ m = JSON.parse(readFileSync(file, "utf8"));
91
+ } catch {
92
+ return [{ status: "error", title: `remote ${path}: vitral.json n\xE3o encontrado` }];
93
+ }
94
+ const name = m.name ?? path;
95
+ const sbom = join(dir, m.sbom?.file ?? "sbom.cdx.json");
96
+ if (!existsSync(sbom))
97
+ return [{ status: "warn", title: `${name}: sem SBOM, n\xE3o d\xE1 para cruzar os pacotes`, fix: "gere o remote com vitral({ sbom: true }) para listar o que ele leva no bundle" }];
98
+ const comps = JSON.parse(readFileSync(sbom, "utf8")).components ?? [];
99
+ const shared = new Set((m.dedupe ?? []).map((d) => d.name));
100
+ const groupOf = (p) => p === "react-dom" || p === "scheduler" ? "react" : p;
101
+ const both = comps.map((c) => c.group ? `${c.group}/${c.name}` : c.name).filter((p) => host.has(p) && !shared.has(groupOf(p))).map((p) => ({ p, bytes: host.get(p), version: installedVersion(cwd, p), remote: comps.find((c) => (c.group ? `${c.group}/${c.name}` : c.name) === p)?.version })).sort((a, b) => b.bytes - a.bytes);
102
+ if (!both.length) return [{ status: "ok", title: `${name}: nenhum pacote em dobro com o host nesta rota` }];
103
+ const list = both.slice(0, 8).map((b) => `${b.p} (${KB(b.bytes)} no host; ${b.version ?? "?"} no host, ${b.remote ?? "?"} no remote)`);
104
+ const same = both.filter((b) => b.version && b.remote && b.version.split(".")[0] === b.remote.split(".")[0]).map((b) => b.p);
105
+ return [
106
+ {
107
+ status: "warn",
108
+ title: `${name}: ${both.length} pacote(s) que o host e o remote levam cada um: ${list.join(", ")}`,
109
+ cause: "a p\xE1gina baixa e interpreta duas c\xF3pias do mesmo pacote",
110
+ fix: same.length ? `ofere\xE7a no host com share: ${JSON.stringify(same.slice(0, 8))} e ponha no dedupe do remote; as vers\xF5es t\xEAm o mesmo major` : "alinhe as vers\xF5es (major diferente n\xE3o divide a c\xF3pia) e depois ponha em share/dedupe"
111
+ }
112
+ ];
113
+ }
114
+ function installedVersion(cwd, pkg) {
115
+ try {
116
+ return JSON.parse(readFileSync(join(cwd, "node_modules", pkg, "package.json"), "utf8")).version;
117
+ } catch {
118
+ }
119
+ }
120
+ function formatRoute(r) {
121
+ const mark = { ok: "\u2713", warn: "!", error: "\u2717" };
122
+ const lines = [`Rota ${r.route} (${r.entries.join(" + ")}): ${KB(r.bytes)} de c\xF3digo-fonte`, "", "Pacotes que mais pesam"];
123
+ for (const p of r.packages) lines.push(` ${KB(p.bytes).padStart(7)} ${p.name}`);
124
+ lines.push("", "M\xF3dulos que mais pesam");
125
+ for (const m of r.modules) lines.push(` ${KB(m.bytes).padStart(7)} ${m.name}`);
126
+ lines.push("");
127
+ for (const c of r.checks) {
128
+ lines.push(` ${mark[c.status]} ${c.title}`);
129
+ if (c.cause) lines.push(` Causa: ${c.cause}`);
130
+ if (c.fix) lines.push(` O que fazer: ${c.fix}`);
131
+ }
132
+ return lines.join("\n");
133
+ }
134
+ export {
135
+ formatRoute,
136
+ routeEntry,
137
+ routeReport
138
+ };
package/dist/routes.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as Routes, a as RouteMatch } from './match-CMBM_jLW.js';
2
- import { P as Props } from './types-g8WEVD_b.js';
3
- import { S as SlotStatus } from './slot-DRYmGvvV.js';
2
+ import { P as Props } from './types-DJautV-K.js';
3
+ import { S as SlotStatus } from './slot--WLgdcW_.js';
4
4
  import './errors-kjBv6IH_.js';
5
5
 
6
6
  interface RoutesOptions {
package/dist/routes.js CHANGED
@@ -3,17 +3,20 @@ import {
3
3
  } from "./chunk-OVVGVPIV.js";
4
4
  import {
5
5
  createSlot
6
- } from "./chunk-VTGHPX4J.js";
6
+ } from "./chunk-6JH2I65O.js";
7
+ import {
8
+ warmSsr
9
+ } from "./chunk-AL6MLNVY.js";
10
+ import "./chunk-MICF64AZ.js";
11
+ import "./chunk-IKCEA3YN.js";
12
+ import "./chunk-GGMM56TM.js";
13
+ import "./chunk-BQGVAXFM.js";
14
+ import "./chunk-JWDDXX5O.js";
15
+ import "./chunk-2Z4OH3BP.js";
16
+ import "./chunk-4E33RZMM.js";
7
17
  import {
8
18
  navigate
9
19
  } from "./chunk-EQZOJU3B.js";
10
- import {
11
- warmSsr
12
- } from "./chunk-EVVYV5ED.js";
13
- import "./chunk-MGG5BW3U.js";
14
- import "./chunk-SC2KF7GJ.js";
15
- import "./chunk-TW7KYJQ6.js";
16
- import "./chunk-463H6B56.js";
17
20
  import "./chunk-GNPFWISJ.js";
18
21
  import "./chunk-MLKGABMK.js";
19
22
 
@@ -119,7 +122,7 @@ var VitralOutletElement = class extends Base {
119
122
  if (ssr?.getAttribute("data-vitral-slot") === name) {
120
123
  this.#status("loading", null);
121
124
  warmSsr(ssr);
122
- import("./hydrate-IVQNHOP3.js").then((m) => {
125
+ import("./hydrate-FJHHLW5G.js").then((m) => {
123
126
  if (this.#route === name && !this.#slot) this.#slot = m.hydrateSlot(this, ssr, { ...options, props: this.#props });
124
127
  else ssr.remove();
125
128
  });
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  fetchCssText,
3
3
  injectCss
4
- } from "./chunk-SC2KF7GJ.js";
5
- import "./chunk-TW7KYJQ6.js";
6
- import "./chunk-463H6B56.js";
4
+ } from "./chunk-IKCEA3YN.js";
5
+ import "./chunk-GGMM56TM.js";
6
+ import "./chunk-BQGVAXFM.js";
7
+ import "./chunk-JWDDXX5O.js";
7
8
  import "./chunk-GNPFWISJ.js";
8
9
  import "./chunk-MLKGABMK.js";
9
10
 
package/dist/sign.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { KeyObject } from 'node:crypto';
2
+
3
+ /**
4
+ * Assinatura dos arquivos do remote (SRI por assinatura, Chrome 141+).
5
+ *
6
+ * O host fixa a chave pública do remote em `configure({ remotes: { x: { url,
7
+ * keys } } })`. O servidor do remote manda, em cada arquivo, os headers
8
+ * `Unencoded-Digest`, `Signature-Input` e `Signature` (RFC 9421 com Ed25519).
9
+ * Um arquivo trocado no CDN sem a chave privada não roda, mesmo que o
10
+ * `vitral.json` trocado traga os hashes novos.
11
+ *
12
+ * A assinatura cobre só o hash do conteúdo, então dá para gerar os headers no
13
+ * build (`vitral sign dist`) e servir como arquivo estático (`_headers` do
14
+ * Netlify e do Cloudflare Pages, ou `vitral-signatures.json` para outro servidor).
15
+ */
16
+
17
+ type SignatureHeaders = {
18
+ 'Unencoded-Digest': string;
19
+ 'Signature-Input': string;
20
+ Signature: string;
21
+ };
22
+ /** Chave pública em base64 (os 32 bytes da chave), o formato de `keys` e do `keyid`. */
23
+ declare function publicKeyOf(key: KeyObject | string): string;
24
+ /** Novo par de chaves: a privada em PEM (guarde como segredo do CI), a pública para o host. */
25
+ declare function keygen(): {
26
+ privateKey: string;
27
+ publicKey: string;
28
+ };
29
+ /** Headers de assinatura de um arquivo. */
30
+ declare function signBody(body: Uint8Array, privateKey: KeyObject | string): SignatureHeaders;
31
+ /**
32
+ * Confere, no servidor, a assinatura de uma resposta: o hash de `body` bate
33
+ * com o `Unencoded-Digest`, e a assinatura é de uma das `keys`.
34
+ */
35
+ declare function verifyBody(body: Uint8Array, headers: Headers | Record<string, string | undefined>, keys: string[]): boolean;
36
+ interface SignDirOptions {
37
+ /** Caminho público da pasta no servidor (ex.: `/carrinho/`). Padrão: `/`. */
38
+ base?: string;
39
+ /** Grava `_headers` (Netlify, Cloudflare Pages). Padrão: true. */
40
+ headersFile?: boolean;
41
+ }
42
+ /**
43
+ * Assina os arquivos de `dir` e grava `vitral-signatures.json` (caminho
44
+ * público → headers) e `_headers`. Rode depois do build e de `vitral dict`:
45
+ * qualquer mudança num arquivo depois disso invalida a assinatura.
46
+ */
47
+ declare function signDir(dir: string, privateKey: string, o?: SignDirOptions): Record<string, SignatureHeaders>;
48
+
49
+ export { type SignDirOptions, type SignatureHeaders, keygen, publicKeyOf, signBody, signDir, verifyBody };
package/dist/sign.js ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ keygen,
3
+ publicKeyOf,
4
+ signBody,
5
+ signDir,
6
+ verifyBody
7
+ } from "./chunk-623K4UNS.js";
8
+ import "./chunk-MLKGABMK.js";
9
+ export {
10
+ keygen,
11
+ publicKeyOf,
12
+ signBody,
13
+ signDir,
14
+ verifyBody
15
+ };
@@ -1,4 +1,4 @@
1
- import { P as Props, a as RemoteModule } from './types-g8WEVD_b.js';
1
+ import { P as Props, a as RemoteModule } from './types-DJautV-K.js';
2
2
  import './errors-kjBv6IH_.js';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { R as RemoteError } from './errors-kjBv6IH_.js';
2
- import { P as Props, I as Isolation, d as StyleOptions } from './types-g8WEVD_b.js';
2
+ import { P as Props, I as Isolation, e as StyleOptions } from './types-DJautV-K.js';
3
3
 
4
4
  type SlotStatus = 'loading' | 'ready' | 'error';
5
5
  interface SlotOptions<P extends Props = Props> {
@@ -0,0 +1,6 @@
1
+ /** Liga o snapshot nesta página. */
2
+ declare function snapshots(): void;
3
+ /** Apaga os snapshots guardados (no logout, por exemplo). */
4
+ declare function clearSnapshots(): void;
5
+
6
+ export { clearSnapshots, snapshots };
@@ -0,0 +1,125 @@
1
+ import {
2
+ ctxHooks
3
+ } from "./chunk-JWDDXX5O.js";
4
+ import {
5
+ protocol
6
+ } from "./chunk-GNPFWISJ.js";
7
+ import "./chunk-MLKGABMK.js";
8
+
9
+ // src/core/snapshot.ts
10
+ var KEY = "vitral:snap:";
11
+ var MAX = 1e5;
12
+ function hash(s) {
13
+ let h = 5381;
14
+ for (let i = 0; i < s.length; i++) h = h * 33 ^ s.charCodeAt(i);
15
+ return (h >>> 0).toString(36);
16
+ }
17
+ function keyOf(name, props) {
18
+ try {
19
+ return KEY + name + ":" + hash(JSON.stringify(props ?? {}));
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+ function store() {
25
+ try {
26
+ return sessionStorage;
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+ function read(name, props) {
32
+ const k = keyOf(name, props);
33
+ try {
34
+ const raw = k && store()?.getItem(k);
35
+ const s = raw ? JSON.parse(raw) : null;
36
+ return typeof s?.html === "string" && Array.isArray(s.css) ? s : null;
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+ function show(target, snap) {
42
+ for (const [href, integrity] of snap.css)
43
+ if (!document.querySelector(`link[rel=stylesheet][href="${CSS.escape(href)}"]`)) {
44
+ const l = document.createElement("link");
45
+ l.rel = "stylesheet";
46
+ l.href = href;
47
+ l.crossOrigin = "anonymous";
48
+ if (integrity) l.integrity = integrity;
49
+ document.head.append(l);
50
+ }
51
+ const box = document.createElement("div");
52
+ box.setAttribute("data-vitral-snapshot", "");
53
+ box.setAttribute("aria-hidden", "true");
54
+ box.inert = true;
55
+ box.style.display = "contents";
56
+ box.append(clean(snap.html));
57
+ target.prepend(box);
58
+ return () => box.remove();
59
+ }
60
+ function clean(html) {
61
+ const t = document.createElement("template");
62
+ t.innerHTML = html;
63
+ for (const el of t.content.querySelectorAll("script,iframe,object,embed,frame,[data-vitral-snapshot]")) el.remove();
64
+ for (const el of t.content.querySelectorAll("*")) for (const a of [...el.attributes]) if (/^on/i.test(a.name)) el.removeAttribute(a.name);
65
+ return t.content;
66
+ }
67
+ async function cssOf(name) {
68
+ try {
69
+ const r = await protocol().load(name, () => Promise.reject(new Error("n\xE3o carregado")));
70
+ return r.isolate === "shadow" ? [] : r.css.map((href) => [href, r.sri?.[href]]);
71
+ } catch {
72
+ return [];
73
+ }
74
+ }
75
+ function save(name, props, box, css) {
76
+ const k = keyOf(name, props);
77
+ const root = box.querySelector(":scope>[data-vitral-slot]>[data-vitral-root]");
78
+ if (!k || !root) return;
79
+ const html = root.outerHTML;
80
+ const s = store();
81
+ try {
82
+ if (html.length > MAX) s?.removeItem(k);
83
+ else s?.setItem(k, JSON.stringify({ html, css }));
84
+ } catch {
85
+ }
86
+ }
87
+ function attach(target, name, props, box, onSnapshot) {
88
+ let ready = false;
89
+ let css = [];
90
+ let hide = () => {
91
+ };
92
+ const found = read(name, props());
93
+ if (found) {
94
+ const off = show(target, found);
95
+ onSnapshot?.(true);
96
+ hide = () => (off(), onSnapshot?.(false), hide = () => {
97
+ });
98
+ }
99
+ const keep = () => {
100
+ const b = box();
101
+ if (ready && b) save(name, props(), b, css);
102
+ };
103
+ addEventListener("pagehide", keep);
104
+ return (status) => {
105
+ if (status === void 0) return keep(), removeEventListener("pagehide", keep), hide();
106
+ if (status !== "loading") hide();
107
+ ready = status === "ready";
108
+ if (ready) cssOf(name).then((c) => css = c);
109
+ };
110
+ }
111
+
112
+ // src/snapshot.ts
113
+ function snapshots() {
114
+ ctxHooks.snapshot = attach;
115
+ }
116
+ function clearSnapshots() {
117
+ try {
118
+ for (const k of Object.keys(sessionStorage)) if (k.startsWith("vitral:snap:")) sessionStorage.removeItem(k);
119
+ } catch {
120
+ }
121
+ }
122
+ export {
123
+ clearSnapshots,
124
+ snapshots
125
+ };
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-g8WEVD_b.js';
3
- export { R as RemoteContext } from './types-g8WEVD_b.js';
2
+ import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared } from './types-DJautV-K.js';
3
+ export { R as RemoteContext } from './types-DJautV-K.js';
4
4
  import { R as RemoteError } from './errors-kjBv6IH_.js';
5
- export { e as events } from './events-CWdYSrkz.js';
5
+ export { e as events } from './events-II6hXM3Q.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,21 +1,24 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-WAU6OKK3.js";
3
+ } from "./chunk-2SAI6S2H.js";
4
4
  import {
5
5
  defineRemote,
6
6
  memoSelect,
7
7
  same,
8
8
  shared
9
- } from "./chunk-VTGHPX4J.js";
9
+ } from "./chunk-6JH2I65O.js";
10
+ import "./chunk-AL6MLNVY.js";
11
+ import "./chunk-MICF64AZ.js";
12
+ import "./chunk-IKCEA3YN.js";
13
+ import "./chunk-GGMM56TM.js";
14
+ import "./chunk-BQGVAXFM.js";
15
+ import "./chunk-JWDDXX5O.js";
16
+ import "./chunk-2Z4OH3BP.js";
17
+ import "./chunk-4E33RZMM.js";
10
18
  import {
11
19
  events,
12
20
  navigate
13
21
  } from "./chunk-EQZOJU3B.js";
14
- import "./chunk-EVVYV5ED.js";
15
- import "./chunk-MGG5BW3U.js";
16
- import "./chunk-SC2KF7GJ.js";
17
- import "./chunk-TW7KYJQ6.js";
18
- import "./chunk-463H6B56.js";
19
22
  import "./chunk-GNPFWISJ.js";
20
23
  import "./chunk-MLKGABMK.js";
21
24
 
@@ -0,0 +1,17 @@
1
+ import {
2
+ importVerified,
3
+ signature,
4
+ verified
5
+ } from "./chunk-SPSAXBPR.js";
6
+ import "./chunk-UCFOXMOR.js";
7
+ import "./chunk-MICF64AZ.js";
8
+ import "./chunk-GGMM56TM.js";
9
+ import "./chunk-BQGVAXFM.js";
10
+ import "./chunk-JWDDXX5O.js";
11
+ import "./chunk-GNPFWISJ.js";
12
+ import "./chunk-MLKGABMK.js";
13
+ export {
14
+ importVerified,
15
+ signature,
16
+ verified
17
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * O HTML que o servidor escreve no lugar do remote, sem Shadow DOM: o mesmo
3
+ * DOM que a montagem cria, para a hidratação (`core/hydrate.ts`) reusar.
4
+ * Serve ao gateway (`vitral/edge`) e ao host Next (`vitral/next-server`).
5
+ */
6
+
7
+ /** O que o `render` do servidor devolve: o HTML, ou o HTML e o estado inicial. */
8
+ type ServerRendered = string | {
9
+ html: string;
10
+ state?: unknown;
11
+ };
12
+
13
+ export type { ServerRendered as S };