vitral 0.11.4 → 0.12.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 (42) hide show
  1. package/README.md +133 -91
  2. package/dist/angular.js +7 -7
  3. package/dist/auto.js +7 -7
  4. package/dist/{channel-ABGK26Q5.js → channel-BHOVSU5X.js} +1 -1
  5. package/dist/{chunk-AL6MLNVY.js → chunk-52D6ZT4A.js} +16 -9
  6. package/dist/{chunk-6JH2I65O.js → chunk-I7IFR65H.js} +6 -6
  7. package/dist/{chunk-2SAI6S2H.js → chunk-JKTZODC5.js} +2 -2
  8. package/dist/{chunk-MICF64AZ.js → chunk-QGAEXUP5.js} +1 -1
  9. package/dist/{chunk-I3CDUKHO.js → chunk-RGYVSS3X.js} +11 -6
  10. package/dist/{chunk-SVYL6UCB.js → chunk-UFETTKDP.js} +4 -4
  11. package/dist/{chunk-SPSAXBPR.js → chunk-VDNFRNOG.js} +25 -8
  12. package/dist/{chunk-GGMM56TM.js → chunk-VDVVEGAO.js} +7 -0
  13. package/dist/{chunk-IKCEA3YN.js → chunk-YDO7SPF4.js} +3 -3
  14. package/dist/{chunk-NQ6ZTGQZ.js → chunk-YKLWMIEH.js} +1 -1
  15. package/dist/cli.js +22 -3
  16. package/dist/element.js +7 -7
  17. package/dist/embed.js +2 -2
  18. package/dist/{expose-2S3TCXSP.js → expose-KL6TA472.js} +5 -5
  19. package/dist/{hydrate-FJHHLW5G.js → hydrate-LS3MLFGN.js} +6 -6
  20. package/dist/iframe.js +6 -6
  21. package/dist/index.js +5 -5
  22. package/dist/next-host.d.ts +16 -3
  23. package/dist/next-host.js +30 -23
  24. package/dist/preact.d.ts +1 -0
  25. package/dist/preact.js +7 -7
  26. package/dist/prefetch.js +5 -5
  27. package/dist/react.d.ts +5 -1
  28. package/dist/react.js +7 -7
  29. package/dist/{reframe-HIYA2TIU.js → reframe-AD2UEPIO.js} +6 -6
  30. package/dist/{route-4KQITYD4.js → route-CEMWXHJI.js} +19 -1
  31. package/dist/routes.js +6 -6
  32. package/dist/{shadow-7ZV4JEO6.js → shadow-ABRO7JNY.js} +2 -2
  33. package/dist/solid.d.ts +2 -1
  34. package/dist/solid.js +18 -7
  35. package/dist/{sri-AMQOKKWR.js → sri-Z5U32IR2.js} +3 -3
  36. package/dist/svelte.js +6 -6
  37. package/dist/sw.d.ts +21 -19
  38. package/dist/sw.js +20 -9
  39. package/dist/testing.js +5 -5
  40. package/dist/vite.js +35 -0
  41. package/dist/vue.js +7 -7
  42. package/package.json +14 -14
package/dist/next-host.js CHANGED
@@ -1,32 +1,32 @@
1
1
  "use client";
2
2
  import {
3
3
  sri_exports
4
- } from "./chunk-SPSAXBPR.js";
4
+ } from "./chunk-VDNFRNOG.js";
5
5
  import {
6
6
  dedupe_exports
7
7
  } from "./chunk-LDOSAAEF.js";
8
8
  import {
9
9
  Remote,
10
10
  preload
11
- } from "./chunk-I3CDUKHO.js";
11
+ } from "./chunk-RGYVSS3X.js";
12
12
  import "./chunk-KCF46XOX.js";
13
13
  import "./chunk-UCFOXMOR.js";
14
14
  import {
15
15
  hintsOf
16
16
  } from "./chunk-QQWE5J6U.js";
17
17
  import "./chunk-5O6XDJBR.js";
18
- import "./chunk-2SAI6S2H.js";
19
- import "./chunk-6JH2I65O.js";
18
+ import "./chunk-JKTZODC5.js";
19
+ import "./chunk-I7IFR65H.js";
20
20
  import {
21
21
  configure,
22
22
  policy,
23
23
  register
24
- } from "./chunk-AL6MLNVY.js";
24
+ } from "./chunk-52D6ZT4A.js";
25
25
  import {
26
26
  bundled
27
- } from "./chunk-MICF64AZ.js";
28
- import "./chunk-IKCEA3YN.js";
29
- import "./chunk-GGMM56TM.js";
27
+ } from "./chunk-QGAEXUP5.js";
28
+ import "./chunk-YDO7SPF4.js";
29
+ import "./chunk-VDVVEGAO.js";
30
30
  import "./chunk-BQGVAXFM.js";
31
31
  import "./chunk-JWDDXX5O.js";
32
32
  import "./chunk-2Z4OH3BP.js";
@@ -109,24 +109,26 @@ function interceptClicks() {
109
109
  document.addEventListener("click", on);
110
110
  return () => document.removeEventListener("click", on);
111
111
  }
112
- function VitralNext() {
112
+ function VitralNext({ pageProps } = {}) {
113
113
  setup();
114
+ const router = useRouter();
115
+ const name = remoteFor((router?.asPath ?? "/").split(/[?#]/)[0]);
114
116
  useEffect(() => {
115
117
  const here = remoteFor(location.pathname);
116
- const go = (name) => preload(name, { routes: !!remotes[name].warmRoutes });
118
+ const go = (name2) => preload(name2, { routes: !!remotes[name2].warmRoutes });
117
119
  if (here) go(here);
118
120
  const idle = [];
119
121
  const all = policy() === "all";
120
- for (const [name, r] of Object.entries(remotes))
121
- if (all && name !== here && (r.preload ?? "idle") === "idle")
122
- idle.push(typeof requestIdleCallback === "function" ? requestIdleCallback(() => go(name), { timeout: 5e3 }) : window.setTimeout(() => go(name), 2e3));
122
+ for (const [name2, r] of Object.entries(remotes))
123
+ if (all && name2 !== here && (r.preload ?? "idle") === "idle")
124
+ idle.push(typeof requestIdleCallback === "function" ? requestIdleCallback(() => go(name2), { timeout: 5e3 }) : window.setTimeout(() => go(name2), 2e3));
123
125
  const stop = interceptNavigation();
124
126
  return () => {
125
127
  stop();
126
128
  for (const id of idle) typeof cancelIdleCallback === "function" ? cancelIdleCallback(id) : clearTimeout(id);
127
129
  };
128
130
  }, []);
129
- return null;
131
+ return useMemo(() => name ? linksFor(name, pageProps?.vitral?.[name], false) : null, [name, pageProps]);
130
132
  }
131
133
  var seeded = /* @__PURE__ */ new Map();
132
134
  function seed(name, m) {
@@ -137,16 +139,24 @@ function seed(name, m) {
137
139
  }
138
140
  var push = (url, options) => void Router.push(url, void 0, options);
139
141
  var replace = (url, options) => void Router.replace(url, void 0, options);
140
- function hints(h, shadow) {
142
+ function hints(h, shadow, replaces) {
141
143
  if (!h) return null;
142
144
  const link = (as, [href, integrity, fetchPriority]) => createElement("link", { key: `vitral:${href}`, rel: "preload", as, href, crossOrigin: "anonymous", ...integrity && { integrity }, ...fetchPriority && { fetchPriority } });
143
- return createElement(
144
- Head,
145
- null,
145
+ const out = [
146
146
  ...h.manifest ? [link("fetch", [h.manifest, h.signed])] : [],
147
+ // Com Shadow DOM o CSS vem por fetch: o preload de estilo não serviria.
147
148
  ...shadow ? [] : h.css.map((c) => link("style", c)),
148
149
  ...h.js.map((j) => link("script", j))
149
- );
150
+ ];
151
+ const have = new Set(out.map((l) => l.key));
152
+ for (const href of replaces ? [replaces.manifest, ...replaces.css.map((c) => c[0]), ...replaces.js.map((j) => j[0])] : [])
153
+ if (href && !have.has(`vitral:${href}`)) out.push(createElement("link", { key: `vitral:${href}`, rel: "dns-prefetch", href: new URL(href, "http://h.invalid").origin.replace("http://h.invalid", "/") }));
154
+ return createElement(Head, null, ...out);
155
+ }
156
+ function linksFor(name, manifest, shadow, replaces) {
157
+ const r = remotes[name];
158
+ const h = manifest && r ? hintsOf(manifest, r.url, offered(), r.integrity, r.keys) : r?.hints;
159
+ return hints(manifest && h ? { ...h, manifest: "" } : h, shadow, replaces ? r?.hints : void 0);
150
160
  }
151
161
  function NextRemote({ name, props, fallback = null, manifest, ...rest }) {
152
162
  setup();
@@ -155,10 +165,7 @@ function NextRemote({ name, props, fallback = null, manifest, ...rest }) {
155
165
  const r = remotes[name];
156
166
  const host = useMemo(() => ({ asPath: router.asPath, basePath: r?.basePath, routes: r?.routes, push, replace, events: Router.events }), [router.asPath, r]);
157
167
  const all = useMemo(() => ({ ...props, __next: host }), [props, host]);
158
- const links = useMemo(() => {
159
- const h = manifest && r ? hintsOf(manifest, r.url, offered(), r.integrity, r.keys) : r?.hints;
160
- return hints(manifest && h ? { ...h, manifest: "" } : h, rest.isolate === "shadow");
161
- }, [manifest, r, rest.isolate]);
168
+ const links = useMemo(() => linksFor(name, manifest, rest.isolate === "shadow", true), [name, manifest, rest.isolate]);
162
169
  return createElement(Fragment, null, links, router.isReady ? createElement(Remote, { ...rest, name, fallback, props: all }) : fallback);
163
170
  }
164
171
  export {
package/dist/preact.d.ts CHANGED
@@ -17,6 +17,7 @@ interface RemoteProps<P extends Props = Props> {
17
17
  props?: P;
18
18
  isolate?: Isolation;
19
19
  fallback?: VNode | string | null;
20
+ /** Mostrado se o remote falhar. Sem ela, uma mensagem curta com "Tentar de novo"; `null` não mostra nada. */
20
21
  error?: VNode | string | ((error: RemoteError, retry: () => void) => VNode | string | null) | null;
21
22
  class?: string;
22
23
  /** `'lazy'`: monta perto de aparecer na tela; `'idle'`: com o navegador ocioso. */
package/dist/preact.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-2SAI6S2H.js";
3
+ } from "./chunk-JKTZODC5.js";
4
4
  import {
5
5
  defineRemote,
6
6
  memoSelect,
7
7
  same,
8
8
  shared
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";
9
+ } from "./chunk-I7IFR65H.js";
10
+ import "./chunk-52D6ZT4A.js";
11
+ import "./chunk-QGAEXUP5.js";
12
+ import "./chunk-YDO7SPF4.js";
13
+ import "./chunk-VDVVEGAO.js";
14
14
  import "./chunk-BQGVAXFM.js";
15
15
  import "./chunk-JWDDXX5O.js";
16
16
  import "./chunk-2Z4OH3BP.js";
@@ -47,7 +47,7 @@ function Remote({ name, src, props, isolate, fallback = null, error = null, load
47
47
  const retry = () => slot.current?.retry();
48
48
  return h("div", { "data-vitral": name ?? src, "data-vitral-status": state.status, class: rest.class }, [
49
49
  state.status === "loading" ? fallback : null,
50
- state.status === "error" && state.error ? typeof error === "function" ? error(state.error, retry) : error : null,
50
+ state.status === "error" && state.error ? error === void 0 ? h("div", { role: "alert", "data-vitral-default": "error" }, ["N\xE3o foi poss\xEDvel carregar. ", h("button", { type: "button", onClick: retry }, "Tentar de novo")]) : typeof error === "function" ? error(state.error, retry) : error : null,
51
51
  // O Preact nunca coloca filhos neste div: ele pertence ao remote.
52
52
  h("div", { ref })
53
53
  ]);
package/dist/prefetch.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  policy,
3
3
  resolveEntry
4
- } from "./chunk-AL6MLNVY.js";
5
- import "./chunk-MICF64AZ.js";
6
- import "./chunk-IKCEA3YN.js";
4
+ } from "./chunk-52D6ZT4A.js";
5
+ import "./chunk-QGAEXUP5.js";
6
+ import "./chunk-YDO7SPF4.js";
7
7
  import {
8
8
  addLink
9
- } from "./chunk-GGMM56TM.js";
9
+ } from "./chunk-VDVVEGAO.js";
10
10
  import "./chunk-BQGVAXFM.js";
11
11
  import "./chunk-JWDDXX5O.js";
12
12
  import {
@@ -222,7 +222,7 @@ function modulepreload(href) {
222
222
  }
223
223
  async function verifiedOnly(r) {
224
224
  const b = r.split ?? { entry: r.entry, chunks: [], sri: { [r.entry]: r.integrity }, priority: "low" };
225
- const { verified } = await import("./sri-AMQOKKWR.js");
225
+ const { verified } = await import("./sri-Z5U32IR2.js");
226
226
  const url = await verified(b);
227
227
  if (!url) await Promise.all([...b.chunks, b.entry].map(heat));
228
228
  else if (!document.querySelector(`link[rel=modulepreload][href="${CSS.escape(url)}"]`)) await heat(url);
package/dist/react.d.ts CHANGED
@@ -58,7 +58,11 @@ interface RemoteProps<P extends Props = Props> {
58
58
  isolate?: Isolation;
59
59
  /** Mostrado enquanto o remote baixa. */
60
60
  fallback?: ReactNode;
61
- /** Mostrado se o remote falhar. Recebe o erro e uma função para tentar de novo. */
61
+ /**
62
+ * Mostrado se o remote falhar. Recebe o erro e uma função para tentar de
63
+ * novo. Sem ela, uma mensagem curta com o botão "Tentar de novo"; `null`
64
+ * não mostra nada.
65
+ */
62
66
  error?: ReactNode | ((error: Error, retry: () => void) => ReactNode);
63
67
  onError?: (error: Error) => void;
64
68
  className?: string;
package/dist/react.js CHANGED
@@ -9,14 +9,14 @@ import {
9
9
  usePortalContainer,
10
10
  useShared,
11
11
  useVitral
12
- } from "./chunk-I3CDUKHO.js";
12
+ } from "./chunk-RGYVSS3X.js";
13
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";
14
+ import "./chunk-JKTZODC5.js";
15
+ import "./chunk-I7IFR65H.js";
16
+ import "./chunk-52D6ZT4A.js";
17
+ import "./chunk-QGAEXUP5.js";
18
+ import "./chunk-YDO7SPF4.js";
19
+ import "./chunk-VDVVEGAO.js";
20
20
  import "./chunk-BQGVAXFM.js";
21
21
  import "./chunk-JWDDXX5O.js";
22
22
  import "./chunk-2Z4OH3BP.js";
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  splitName
3
- } from "./chunk-NQ6ZTGQZ.js";
3
+ } from "./chunk-YKLWMIEH.js";
4
4
  import {
5
5
  verifyIntegrity
6
6
  } from "./chunk-UCFOXMOR.js";
7
7
  import {
8
8
  resolveEntry
9
- } from "./chunk-AL6MLNVY.js";
10
- import "./chunk-MICF64AZ.js";
9
+ } from "./chunk-52D6ZT4A.js";
10
+ import "./chunk-QGAEXUP5.js";
11
11
  import {
12
12
  prefetchCss
13
- } from "./chunk-IKCEA3YN.js";
13
+ } from "./chunk-YDO7SPF4.js";
14
14
  import {
15
15
  fetchBytes,
16
16
  metric,
17
17
  withRetry,
18
18
  withTimeout
19
- } from "./chunk-GGMM56TM.js";
19
+ } from "./chunk-VDVVEGAO.js";
20
20
  import {
21
21
  RemoteError,
22
22
  isRemoteError,
@@ -63,7 +63,7 @@ async function load(name, _isolate, priority) {
63
63
  return b;
64
64
  });
65
65
  const url = bytes ? URL.createObjectURL(new Blob([bytes], { type: "text/javascript" })) : r.entry;
66
- const { registryFor } = await import("./shadow-7ZV4JEO6.js");
66
+ const { registryFor } = await import("./shadow-ABRO7JNY.js");
67
67
  realm = createRealm(r.name ?? name, registryFor(r.name ?? name));
68
68
  let ns;
69
69
  try {
@@ -44,10 +44,28 @@ function routeReport(o) {
44
44
  byPkg.set(p, (byPkg.get(p) ?? 0) + m.size);
45
45
  }
46
46
  const top = o.top ?? 15;
47
+ const checks = [];
48
+ const routeChunks = (s.chunks ?? []).filter((c) => ids.has(String(c.id)));
49
+ const assetSize = new Map((s.assets ?? []).map((a) => [a.name, a.size ?? 0]));
50
+ const jsFiles = new Set([
51
+ ...routeChunks.flatMap((c) => c.files ?? []),
52
+ ...entries.flatMap((n) => (groups[n].assets ?? []).map((a) => typeof a === "string" ? a : a.name))
53
+ ].filter((f) => /\.m?js$/.test(f)));
54
+ const groupAssets = new Map(entries.flatMap((n) => (groups[n].assets ?? []).flatMap((a) => typeof a === "string" ? [] : [[a.name, a.size ?? 0]])));
55
+ const shipped = Math.max(
56
+ routeChunks.reduce((n, c) => n + (c.size ?? 0), 0),
57
+ [...jsFiles].reduce((n, f) => n + (assetSize.get(f) ?? groupAssets.get(f) ?? 0), 0)
58
+ );
59
+ if (shipped > 2 * bytes && shipped - bytes > 50 * 1024)
60
+ checks.push({
61
+ status: "warn",
62
+ title: `os stats s\xF3 mostram ${KB(bytes)} dos ${KB(shipped)} que a rota carrega`,
63
+ cause: "os stats foram gerados sem os m\xF3dulos de cada chunk; os n\xFAmeros abaixo ficam incompletos",
64
+ fix: "gere os stats com m\xF3dulos e chunks: stats.toJson({ all: false, entrypoints: true, chunks: true, chunkModules: true, modules: true, nestedModules: true, assets: true, usedExports: true, providedExports: true, reasons: true })"
65
+ });
47
66
  const packages = [...byPkg].map(([name, b]) => ({ name, bytes: b })).sort((a, b) => b.bytes - a.bytes);
48
67
  const short = (n) => n.replace(/^(.*?[/\\])?node_modules[/\\](\.pnpm[/\\][^/\\]+[/\\]node_modules[/\\])?/, "node_modules/");
49
68
  const modules = mods.map((m) => ({ name: short(m.name ?? "?"), bytes: m.size })).sort((a, b) => b.bytes - a.bytes);
50
- const checks = [];
51
69
  const locales = mods.filter((m) => LOCALE.test(m.name ?? ""));
52
70
  const localeBytes = locales.reduce((n, m) => n + m.size, 0);
53
71
  if (localeBytes > 20 * 1024)
package/dist/routes.js CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  } from "./chunk-OVVGVPIV.js";
4
4
  import {
5
5
  createSlot
6
- } from "./chunk-6JH2I65O.js";
6
+ } from "./chunk-I7IFR65H.js";
7
7
  import {
8
8
  warmSsr
9
- } from "./chunk-AL6MLNVY.js";
10
- import "./chunk-MICF64AZ.js";
11
- import "./chunk-IKCEA3YN.js";
12
- import "./chunk-GGMM56TM.js";
9
+ } from "./chunk-52D6ZT4A.js";
10
+ import "./chunk-QGAEXUP5.js";
11
+ import "./chunk-YDO7SPF4.js";
12
+ import "./chunk-VDVVEGAO.js";
13
13
  import "./chunk-BQGVAXFM.js";
14
14
  import "./chunk-JWDDXX5O.js";
15
15
  import "./chunk-2Z4OH3BP.js";
@@ -122,7 +122,7 @@ var VitralOutletElement = class extends Base {
122
122
  if (ssr?.getAttribute("data-vitral-slot") === name) {
123
123
  this.#status("loading", null);
124
124
  warmSsr(ssr);
125
- import("./hydrate-FJHHLW5G.js").then((m) => {
125
+ import("./hydrate-LS3MLFGN.js").then((m) => {
126
126
  if (this.#route === name && !this.#slot) this.#slot = m.hydrateSlot(this, ssr, { ...options, props: this.#props });
127
127
  else ssr.remove();
128
128
  });
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  fetchCssText,
3
3
  injectCss
4
- } from "./chunk-IKCEA3YN.js";
5
- import "./chunk-GGMM56TM.js";
4
+ } from "./chunk-YDO7SPF4.js";
5
+ import "./chunk-VDVVEGAO.js";
6
6
  import "./chunk-BQGVAXFM.js";
7
7
  import "./chunk-JWDDXX5O.js";
8
8
  import "./chunk-GNPFWISJ.js";
package/dist/solid.d.ts CHANGED
@@ -22,7 +22,8 @@ interface RemoteProps<P extends Props = Props> {
22
22
  props?: P;
23
23
  isolate?: Isolation;
24
24
  fallback?: JSX.Element;
25
- error?: (error: RemoteError, retry: () => void) => JSX.Element;
25
+ /** Mostrado se o remote falhar. Sem ela, uma mensagem curta com "Tentar de novo"; `null` não mostra nada. */
26
+ error?: ((error: RemoteError, retry: () => void) => JSX.Element) | null;
26
27
  class?: string;
27
28
  /** `'lazy'`: monta perto de aparecer na tela; `'idle'`: com o navegador ocioso. */
28
29
  loading?: Loading;
package/dist/solid.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-2SAI6S2H.js";
3
+ } from "./chunk-JKTZODC5.js";
4
4
  import {
5
5
  defineRemote,
6
6
  memoSelect,
7
7
  same,
8
8
  shared
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";
9
+ } from "./chunk-I7IFR65H.js";
10
+ import "./chunk-52D6ZT4A.js";
11
+ import "./chunk-QGAEXUP5.js";
12
+ import "./chunk-YDO7SPF4.js";
13
+ import "./chunk-VDVVEGAO.js";
14
14
  import "./chunk-BQGVAXFM.js";
15
15
  import "./chunk-JWDDXX5O.js";
16
16
  import "./chunk-2Z4OH3BP.js";
@@ -70,10 +70,21 @@ function Remote(p) {
70
70
  const retry = () => slot?.retry();
71
71
  return [
72
72
  () => status() === "loading" ? p.fallback : null,
73
- () => status() === "error" && error() && p.error ? p.error(error(), retry) : null,
73
+ () => status() === "error" && error() ? p.error ? p.error(error(), retry) : p.error === null ? null : defaultError(retry) : null,
74
74
  (host.appendChild(target), host)
75
75
  ];
76
76
  }
77
+ function defaultError(retry) {
78
+ const box = document.createElement("div");
79
+ box.setAttribute("role", "alert");
80
+ box.setAttribute("data-vitral-default", "error");
81
+ const button = document.createElement("button");
82
+ button.type = "button";
83
+ button.textContent = "Tentar de novo";
84
+ button.onclick = retry;
85
+ box.append("N\xE3o foi poss\xEDvel carregar. ", button);
86
+ return box;
87
+ }
77
88
  function useShared(key, select = same) {
78
89
  const handle = shared(key);
79
90
  const pick = memoSelect();
@@ -2,10 +2,10 @@ import {
2
2
  importVerified,
3
3
  signature,
4
4
  verified
5
- } from "./chunk-SPSAXBPR.js";
5
+ } from "./chunk-VDNFRNOG.js";
6
6
  import "./chunk-UCFOXMOR.js";
7
- import "./chunk-MICF64AZ.js";
8
- import "./chunk-GGMM56TM.js";
7
+ import "./chunk-QGAEXUP5.js";
8
+ import "./chunk-VDVVEGAO.js";
9
9
  import "./chunk-BQGVAXFM.js";
10
10
  import "./chunk-JWDDXX5O.js";
11
11
  import "./chunk-GNPFWISJ.js";
package/dist/svelte.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-2SAI6S2H.js";
3
+ } from "./chunk-JKTZODC5.js";
4
4
  import {
5
5
  defineRemote
6
- } from "./chunk-6JH2I65O.js";
7
- import "./chunk-AL6MLNVY.js";
8
- import "./chunk-MICF64AZ.js";
9
- import "./chunk-IKCEA3YN.js";
10
- import "./chunk-GGMM56TM.js";
6
+ } from "./chunk-I7IFR65H.js";
7
+ import "./chunk-52D6ZT4A.js";
8
+ import "./chunk-QGAEXUP5.js";
9
+ import "./chunk-YDO7SPF4.js";
10
+ import "./chunk-VDVVEGAO.js";
11
11
  import "./chunk-BQGVAXFM.js";
12
12
  import "./chunk-JWDDXX5O.js";
13
13
  import "./chunk-2Z4OH3BP.js";
package/dist/sw.d.ts CHANGED
@@ -1,26 +1,28 @@
1
1
  import { d as RemoteManifest } from './types-DJautV-K.js';
2
2
  import './errors-kjBv6IH_.js';
3
3
 
4
+ interface FilesOptions {
5
+ /**
6
+ * Versão de cada grupo de `dedupe` que o host oferece (`{ react: '19.2.0' }`):
7
+ * a cópia própria do remote para esses grupos fica de fora.
8
+ */
9
+ offered?: Record<string, string>;
10
+ /**
11
+ * Inclui o arquivo único quando o manifesto tem build dividido. Padrão:
12
+ * false. O arquivo único só é usado em navegadores sem import map nem
13
+ * modulepreload com integrity, e depois de uma falha.
14
+ */
15
+ single?: boolean;
16
+ }
4
17
  /**
5
- * Para o service worker do host: os arquivos que um remote publica, para
6
- * guardar no cache e o remote abrir offline.
7
- *
8
- * // sw.js do host
9
- * import { remoteFiles } from 'vitral/sw'
10
- * self.addEventListener('install', (e) => e.waitUntil(
11
- * remoteFiles('/conta/vitral.json').then((urls) => caches.open('remotes').then((c) => c.addAll(urls))),
12
- * ))
13
- */
14
-
15
- /**
16
- * URLs absolutas do manifesto e de tudo que ele lista: arquivo único, CSS,
17
- * build dividido (inclusive os `import()` das rotas), cópias de `dedupe` e os
18
- * módulos de teste do SRI.
18
+ * URLs absolutas do manifesto e do que a página usa: CSS, build dividido
19
+ * (inclusive os `import()` das rotas), cópias de `dedupe` que o host não
20
+ * oferece e os módulos de teste do SRI. Sem build dividido, o arquivo único.
19
21
  */
20
- declare function remoteFiles(manifestUrl: string, init?: RequestInit): Promise<string[]>;
22
+ declare function remoteFiles(manifestUrl: string, init?: RequestInit & FilesOptions): Promise<string[]>;
21
23
  /** O mesmo que `remoteFiles`, para um manifesto já lido. */
22
- declare function filesOf(m: RemoteManifest, manifestUrl: string): string[];
23
- interface RemoteWorkerOptions {
24
+ declare function filesOf(m: RemoteManifest, manifestUrl: string, o?: FilesOptions): string[];
25
+ interface RemoteWorkerOptions extends FilesOptions {
24
26
  /** URLs dos `vitral.json` dos remotes. */
25
27
  manifests: string[];
26
28
  /** Nome do cache. Padrão `vitral-remotes`. */
@@ -35,7 +37,7 @@ interface Scope {
35
37
  }
36
38
  /**
37
39
  * Service worker do host para os remotes. No `install`, baixa o manifesto e
38
- * todos os arquivos de cada remote para o CacheStorage: o Chrome gera o cache
40
+ * os arquivos que a página usa de cada remote (`filesOf`) para o CacheStorage: o Chrome gera o cache
39
41
  * de código completo para scripts gravados durante o `install`, e a volta à
40
42
  * página compila menos. Onde há Static Routing API (Chrome 123+), os arquivos
41
43
  * com hash vão direto ao cache, sem acordar o service worker; nos outros
@@ -52,4 +54,4 @@ interface Scope {
52
54
  */
53
55
  declare function remoteWorker(self: Scope, o: RemoteWorkerOptions): void;
54
56
 
55
- export { type RemoteWorkerOptions, filesOf, remoteFiles, remoteWorker };
57
+ export { type FilesOptions, type RemoteWorkerOptions, filesOf, remoteFiles, remoteWorker };
package/dist/sw.js CHANGED
@@ -1,25 +1,36 @@
1
+ import {
2
+ satisfies
3
+ } from "./chunk-4E33RZMM.js";
1
4
  import "./chunk-MLKGABMK.js";
2
5
 
3
6
  // src/sw.ts
4
7
  async function remoteFiles(manifestUrl, init) {
5
8
  const base = new URL(manifestUrl, globalThis.location?.href);
6
- const res = await fetch(base, { cache: "no-cache", ...init });
9
+ const { offered, single, ...req } = init ?? {};
10
+ const res = await fetch(base, { cache: "no-cache", ...req });
7
11
  if (!res.ok) throw new Error(`vitral: ${base.href} respondeu ${res.status}`);
8
- return filesOf(await res.json(), base.href);
12
+ return filesOf(await res.json(), base.href, { offered, single });
9
13
  }
10
- function filesOf(m, manifestUrl) {
14
+ function filesOf(m, manifestUrl, o = {}) {
11
15
  const base = new URL(manifestUrl, globalThis.location?.href);
16
+ const s = m.split;
17
+ const dir = s ? s.entry.slice(0, s.entry.lastIndexOf("/") + 1) : "";
18
+ const served = (d) => !!o.offered?.[d.name] && satisfies(o.offered[d.name], d.range);
19
+ const own = new Set((m.dedupe ?? []).filter(served).flatMap((d) => [d.file, ...d.chunks ?? []]));
20
+ for (const f of s ? [s.entry, ...s.chunks ?? [], ...s.lazy ?? []] : []) own.delete(f);
21
+ const all = !s || o.single;
12
22
  const files = [
13
- m.entry,
23
+ ...all ? [m.entry] : [],
14
24
  ...m.css ?? [],
15
25
  ...m.shadow?.css ?? [],
16
26
  ...m.shadow?.global ?? [],
17
- ...Object.keys(m.files ?? {}),
18
- ...m.split ? [m.split.entry, ...m.split.chunks ?? []] : [],
27
+ // Sem o arquivo único, só o JS do build dividido (o resto é do arquivo único).
28
+ ...Object.keys(m.files ?? {}).filter((f) => all || !/\.m?js$/.test(f) || f.startsWith(dir)),
29
+ ...s ? [s.entry, ...s.chunks ?? [], ...s.lazy ?? []] : [],
19
30
  ...(m.dedupe ?? []).flatMap((d) => [d.file, ...d.chunks ?? []]),
20
31
  ...m.probe ?? []
21
32
  ];
22
- return [base.href, ...new Set(files.filter(Boolean).map((f) => new URL(f, base).href))];
33
+ return [base.href, ...new Set(files.filter((f) => f && !own.has(f)).map((f) => new URL(f, base).href))];
23
34
  }
24
35
  var hashed = (u, manifests) => !manifests.has(u) && /\.(js|mjs|css|wasm)$/.test(new URL(u).pathname);
25
36
  function remoteWorker(self, o) {
@@ -35,10 +46,10 @@ function remoteWorker(self, o) {
35
46
  const res = await fetch(m, { cache: "no-cache" });
36
47
  if (!res.ok) return [];
37
48
  await c.put(m, res.clone());
38
- return filesOf(await res.json(), m);
49
+ return filesOf(await res.json(), m, o);
39
50
  };
40
51
  for (const m of manifests) {
41
- const urls = known?.[0] === m ? filesOf(known[1], m) : await read(m).catch(() => []);
52
+ const urls = known?.[0] === m ? filesOf(known[1], m, o) : await read(m).catch(() => []);
42
53
  for (const u of urls) keep.add(u);
43
54
  const missing = [];
44
55
  for (const u of urls) if (hashed(u, manifests) && !await c.match(u)) missing.push(u);
package/dist/testing.js CHANGED
@@ -4,13 +4,13 @@ import {
4
4
  harness,
5
5
  verify
6
6
  } from "./chunk-DAESKNQ6.js";
7
- import "./chunk-6JH2I65O.js";
7
+ import "./chunk-I7IFR65H.js";
8
8
  import {
9
9
  register
10
- } from "./chunk-AL6MLNVY.js";
11
- import "./chunk-MICF64AZ.js";
12
- import "./chunk-IKCEA3YN.js";
13
- import "./chunk-GGMM56TM.js";
10
+ } from "./chunk-52D6ZT4A.js";
11
+ import "./chunk-QGAEXUP5.js";
12
+ import "./chunk-YDO7SPF4.js";
13
+ import "./chunk-VDVVEGAO.js";
14
14
  import "./chunk-BQGVAXFM.js";
15
15
  import "./chunk-JWDDXX5O.js";
16
16
  import "./chunk-2Z4OH3BP.js";
package/dist/vite.js CHANGED
@@ -89,6 +89,33 @@ function outputs(rolldown, hints = false) {
89
89
  ];
90
90
  }
91
91
  var compileHint = (chunk) => chunk.isEntry || !chunk.isDynamicEntry || chunk.name?.startsWith("_vitral") ? "//# allFunctionsCalledOnLoad" : "";
92
+ var CHUNKING = ["manualChunks", "advancedChunks", "codeSplitting", "inlineDynamicImports", "experimentalMinChunkSize"];
93
+ function userOutputs(list) {
94
+ if (!Array.isArray(list)) return;
95
+ const ours = (o) => o.format === "es" && ("codeSplitting" in o || "inlineDynamicImports" in o || String(o.entryFileNames ?? "").startsWith(SPLIT));
96
+ const user = list.filter((o) => !ours(o));
97
+ if (!user.length) return;
98
+ const [single, split] = list.filter(ours);
99
+ const given = Object.assign({}, ...user);
100
+ const common = Object.fromEntries(Object.entries(given).filter(([k]) => !CHUNKING.includes(k)));
101
+ const chunking = Object.fromEntries(Object.entries(given).filter(([k]) => CHUNKING.includes(k) && !(k === "codeSplitting" && given[k] === false) && k !== "inlineDynamicImports"));
102
+ return [{ ...common, ...single }, { ...common, ...chunking, ...split }];
103
+ }
104
+ function ownApart(user) {
105
+ let app;
106
+ return (id, meta) => {
107
+ if (!app) {
108
+ app = /* @__PURE__ */ new Set();
109
+ const boot = "\0" + BOOT;
110
+ const stack = [boot];
111
+ while (stack.length) {
112
+ const m = meta.getModuleInfo(stack.pop());
113
+ for (const d of [...m?.importedIds ?? [], ...m?.dynamicallyImportedIds ?? []]) if (!d.startsWith("\0vitral-own:") && !app.has(d)) app.add(d), stack.push(d);
114
+ }
115
+ }
116
+ return app.has(id) ? user(id, meta) : void 0;
117
+ };
118
+ }
92
119
  var isSplit = (bundle) => Object.values(bundle).some((f) => f.type === "chunk" && f.isEntry && f.fileName.startsWith(SPLIT));
93
120
  var helper = (load = "import", base = "import.meta.url") => `function __vitralImport(u,d){var p=globalThis[Symbol.for("vitral")],s=p&&p.sri,a=d.concat(u).map(function(x){return new URL(x,${base}).href});return Promise.all(s?a.map(function(h){return new Promise(function(ok,no){if(!s[h])return no(new Error("vitral: arquivo sem integrity: "+h));var l=document.createElement("link");l.rel="modulepreload";l.crossOrigin="anonymous";l.integrity=s[h];l.href=h;l.onload=ok;l.onerror=function(){no(new Error("vitral: integrity n\xE3o confere: "+h))};document.head.appendChild(l)})}):[]).then(function(){return ${load}(a[a.length-1])})}`;
94
121
  function collect(outDir, bundle) {
@@ -1084,6 +1111,14 @@ function vitral(options = {}) {
1084
1111
  },
1085
1112
  configResolved(c) {
1086
1113
  root = c.root;
1114
+ for (const key of ["rollupOptions", "rolldownOptions"]) {
1115
+ const o = c.build[key];
1116
+ const fixed = !mcp && o && userOutputs(o.output);
1117
+ if (!fixed) continue;
1118
+ const user = fixed[1].manualChunks;
1119
+ if (dedupe && typeof user === "function") fixed[1].manualChunks = ownApart(user);
1120
+ o.output = fixed;
1121
+ }
1087
1122
  framework = detectAdapter(c.plugins);
1088
1123
  adapter = options.adapter || framework;
1089
1124
  serve = c.command === "serve";
package/dist/vue.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  hostSlot,
3
3
  timings
4
- } from "./chunk-2SAI6S2H.js";
4
+ } from "./chunk-JKTZODC5.js";
5
5
  import {
6
6
  defineRemote,
7
7
  memoSelect,
8
8
  same,
9
9
  shared
10
- } from "./chunk-6JH2I65O.js";
11
- import "./chunk-AL6MLNVY.js";
12
- import "./chunk-MICF64AZ.js";
13
- import "./chunk-IKCEA3YN.js";
10
+ } from "./chunk-I7IFR65H.js";
11
+ import "./chunk-52D6ZT4A.js";
12
+ import "./chunk-QGAEXUP5.js";
13
+ import "./chunk-YDO7SPF4.js";
14
14
  import {
15
15
  absolute
16
- } from "./chunk-GGMM56TM.js";
16
+ } from "./chunk-VDVVEGAO.js";
17
17
  import "./chunk-BQGVAXFM.js";
18
18
  import "./chunk-JWDDXX5O.js";
19
19
  import "./chunk-2Z4OH3BP.js";
@@ -142,7 +142,7 @@ var VitralRemote = /* @__PURE__ */ defineComponent({
142
142
  const retry = () => slot?.retry();
143
143
  return () => h("div", { "data-vitral": p.name ?? p.src, "data-vitral-status": status.value }, [
144
144
  status.value === "loading" ? slots.fallback?.() : null,
145
- status.value === "error" ? slots.error?.({ error: error.value, retry }) : null,
145
+ status.value === "error" ? slots.error ? slots.error({ error: error.value, retry }) : h("div", { role: "alert", "data-vitral-default": "error" }, ["N\xE3o foi poss\xEDvel carregar. ", h("button", { type: "button", onClick: retry }, "Tentar de novo")]) : null,
146
146
  // O Vue nunca coloca filhos neste div: ele pertence ao remote.
147
147
  h("div", { ref: target })
148
148
  ]);