vitral 0.10.1 → 0.11.1

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 (89) hide show
  1. package/README.md +23 -7
  2. package/dist/angular.d.ts +2 -2
  3. package/dist/angular.js +13 -10
  4. package/dist/auto.js +11 -8
  5. package/dist/{capture-A6JQNNQY.js → capture-2I5IQ2C2.js} +2 -1
  6. package/dist/{channel-2DUQQPPA.js → channel-ABGK26Q5.js} +5 -3
  7. package/dist/{chunk-WAU6OKK3.js → chunk-2SAI6S2H.js} +11 -3
  8. package/dist/chunk-2Z4OH3BP.js +85 -0
  9. package/dist/chunk-5O6XDJBR.js +15 -0
  10. package/dist/chunk-623K4UNS.js +70 -0
  11. package/dist/{chunk-VTGHPX4J.js → chunk-6JH2I65O.js} +15 -13
  12. package/dist/{chunk-EVVYV5ED.js → chunk-AL6MLNVY.js} +49 -21
  13. package/dist/chunk-B3PFMWZT.js +21 -0
  14. package/dist/{chunk-463H6B56.js → chunk-BQGVAXFM.js} +3 -4
  15. package/dist/{chunk-TW7KYJQ6.js → chunk-GGMM56TM.js} +1 -1
  16. package/dist/{chunk-FOEXP52G.js → chunk-I3CDUKHO.js} +69 -19
  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-CFJC4GRB.js → chunk-SVYL6UCB.js} +21 -10
  26. package/dist/{chunk-UYOPJ4XQ.js → chunk-UCFOXMOR.js} +1 -1
  27. package/dist/cli.js +119 -8
  28. package/dist/{contract-IXM52LVW.js → contract-3JY7SOGQ.js} +1 -1
  29. package/dist/{dedupe-SRAPOK3V.js → dedupe-M63VMCWA.js} +3 -1
  30. package/dist/edge.d.ts +4 -2
  31. package/dist/edge.js +69 -46
  32. package/dist/element.d.ts +3 -3
  33. package/dist/element.js +11 -8
  34. package/dist/embed.js +2 -2
  35. package/dist/{events-CWdYSrkz.d.ts → events-II6hXM3Q.d.ts} +1 -1
  36. package/dist/expose-2S3TCXSP.js +18 -0
  37. package/dist/federation.d.ts +1 -1
  38. package/dist/{hydrate-IVQNHOP3.js → hydrate-FJHHLW5G.js} +22 -12
  39. package/dist/iframe.js +15 -12
  40. package/dist/index.d.ts +6 -6
  41. package/dist/index.js +25 -11
  42. package/dist/{loader-CLRMRRFv.d.ts → loader-Bmul2-5T.d.ts} +1 -1
  43. package/dist/next-config.d.ts +30 -10
  44. package/dist/next-config.js +29 -20
  45. package/dist/next-host.d.ts +11 -5
  46. package/dist/next-host.js +54 -29
  47. package/dist/next-server.d.ts +56 -0
  48. package/dist/next-server.js +90 -0
  49. package/dist/preact.d.ts +4 -4
  50. package/dist/preact.js +10 -7
  51. package/dist/prefetch.d.ts +40 -3
  52. package/dist/prefetch.js +100 -30
  53. package/dist/react-server.d.ts +16 -5
  54. package/dist/react-server.js +8 -3
  55. package/dist/react.d.ts +20 -6
  56. package/dist/react.js +14 -9
  57. package/dist/{reframe-ZOQPW552.js → reframe-HIYA2TIU.js} +10 -9
  58. package/dist/route-4KQITYD4.js +138 -0
  59. package/dist/routes.d.ts +2 -2
  60. package/dist/routes.js +12 -9
  61. package/dist/{shadow-PZGQKUA4.js → shadow-7ZV4JEO6.js} +4 -3
  62. package/dist/sign.d.ts +49 -0
  63. package/dist/sign.js +15 -0
  64. package/dist/single-spa.d.ts +1 -1
  65. package/dist/{slot-DRYmGvvV.d.ts → slot--WLgdcW_.d.ts} +1 -1
  66. package/dist/snapshot.d.ts +6 -0
  67. package/dist/snapshot.js +125 -0
  68. package/dist/solid.d.ts +3 -3
  69. package/dist/solid.js +10 -7
  70. package/dist/sri-AMQOKKWR.js +17 -0
  71. package/dist/ssr-markup-BCPpGmss.d.ts +13 -0
  72. package/dist/state-B1FJi8I9.d.ts +14 -0
  73. package/dist/svelte.d.ts +4 -4
  74. package/dist/svelte.js +10 -7
  75. package/dist/sw.d.ts +48 -1
  76. package/dist/sw.js +79 -2
  77. package/dist/testing.d.ts +2 -2
  78. package/dist/testing.js +10 -7
  79. package/dist/{types-g8WEVD_b.d.ts → types-DJautV-K.d.ts} +86 -1
  80. package/dist/vitals.js +2 -1
  81. package/dist/vite.d.ts +4 -2
  82. package/dist/vite.js +62 -12
  83. package/dist/vue.d.ts +3 -3
  84. package/dist/vue.js +13 -10
  85. package/package.json +47 -39
  86. package/dist/expose-BA4HSXDP.js +0 -17
  87. package/dist/portals-RLXKPXBZ.js +0 -24
  88. package/dist/sri-LQBLQMG5.js +0 -14
  89. package/dist/state-BDdCwc21.d.ts +0 -4
package/README.md CHANGED
@@ -31,7 +31,7 @@ Cada equipe publica o próprio pedaço da página (um remote) com `vite build`.
31
31
  - **Deploy independente.** Cada equipe publica quando quiser. O host vê a versão nova sem novo build.
32
32
  - **CSS e erros isolados.** O CSS de um remote não muda o resto da página. Um remote fora do ar mostra o próprio erro, e o resto continua funcionando.
33
33
  - **Seguro.** O JS só roda se vier de uma origem permitida e se o hash SHA-384 bater.
34
- - **Leve e rápido.** 3,4 kB de host. Primeira visita 57% mais rápida que o Module Federation e troca de área 4,6 vezes mais rápida que o Next.js Multi-Zones.
34
+ - **Leve e rápido.** 5,1 kB de host. Abre a página na metade do tempo do Module Federation e troca de área 4,5 vezes mais rápido que o Next.js Multi-Zones.
35
35
 
36
36
  ```bash
37
37
  npm install vitral
@@ -54,15 +54,31 @@ npm install vitral
54
54
  | Trocar de área | Sem recarregar | Sem recarregar | Recarrega a página e baixa Next e React de novo | Sem recarregar |
55
55
  | Isolamento de CSS | Nenhum | Nenhum | Por página | Escopo automático ou Shadow DOM |
56
56
  | Remote fora do ar | Erro sem tratamento derruba a página | A tela de erro é com você | A zona inteira fica fora | Só aquele remote mostra erro, com `retry` |
57
- | Código de host (brotli) | 19,4 kB | 5,8 kB | Runtime do Next em cada zona | 3,4 kB |
57
+ | Código de host (brotli) | 19,4 kB | 5,8 kB | Runtime do Next em cada zona | 5,1 kB |
58
58
 
59
- Medido no [benchmark público](https://joaogabriel15.github.io/vitral/aprender/benchmark) (Chromium, rede Slow 4G, mediana de 7 visitas):
59
+ ## Velocidade
60
60
 
61
- - **57% menos tempo** na primeira visita que o Module Federation com React compartilhado (1157 ms contra 2673 ms, 1 remote).
62
- - **4,6 vezes mais rápido** para trocar de área que o Next.js Multi-Zones (184 ms contra 850 ms), com 63% menos bytes para abrir duas áreas.
63
- - **10 frameworks** cobertos por testes de ponta a ponta no CI, com host e remote de frameworks diferentes, em Chromium, Firefox, WebKit e mobile.
61
+ Medido no Chromium com rede de celular lenta (Slow 4G). Mediana de 7 visitas. Menor é melhor.
64
62
 
65
- O método e as versões usadas estão na página do benchmark.
63
+ **Contra o Module Federation**, com o React compartilhado entre os remotes:
64
+
65
+ | | vitral | Module Federation |
66
+ |---|--:|--:|
67
+ | Abrir a página com 1 remote | **1,1 s** | 2,6 s |
68
+ | Abrir a página com 8 remotes | **2,1 s** | 4,5 s |
69
+ | Baixado com 8 remotes | **153 kB** | 409 kB |
70
+
71
+ **Contra o Next.js Multi-Zones**, com o app dividido em duas áreas:
72
+
73
+ | | vitral | Multi-Zones |
74
+ |---|--:|--:|
75
+ | Abrir a primeira área | **0,7 s** | 1,0 s |
76
+ | Trocar de área | **0,2 s** | 0,8 s |
77
+ | Baixado para abrir as duas áreas | **83 kB** | 229 kB |
78
+
79
+ [Como foi medido](https://joaogabriel15.github.io/vitral/aprender/benchmark): versões, máquina e o script para rodar de novo.
80
+
81
+ Os 10 frameworks têm testes de ponta a ponta no CI, com host e remote de frameworks diferentes, em Chromium, Firefox, WebKit e mobile.
66
82
 
67
83
  ## Começo rápido
68
84
 
package/dist/angular.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { InjectionToken, Type, ApplicationConfig, Signal, Provider, EnvironmentProviders } from '@angular/core';
2
- import { R as RemoteContext, P as Props, a as RemoteModule, S as Shared, V as VitralConfig } from './types-g8WEVD_b.js';
3
- export { e as events } from './events-CWdYSrkz.js';
2
+ import { R as RemoteContext, P as Props, a as RemoteModule, S as Shared, V as VitralConfig } from './types-DJautV-K.js';
3
+ export { e as events } from './events-II6hXM3Q.js';
4
4
  export { n as navigate } from './navigate-BRG1WJUM.js';
5
5
  import './errors-kjBv6IH_.js';
6
6
 
package/dist/angular.js CHANGED
@@ -1,24 +1,27 @@
1
1
  import {
2
2
  defineVitralElement
3
- } from "./chunk-CFJC4GRB.js";
4
- import "./chunk-WAU6OKK3.js";
3
+ } from "./chunk-SVYL6UCB.js";
4
+ import "./chunk-2SAI6S2H.js";
5
5
  import {
6
6
  defineRemote,
7
7
  memoSelect,
8
8
  same,
9
9
  shared
10
- } from "./chunk-VTGHPX4J.js";
10
+ } from "./chunk-6JH2I65O.js";
11
+ import {
12
+ configure
13
+ } from "./chunk-AL6MLNVY.js";
14
+ import "./chunk-MICF64AZ.js";
15
+ import "./chunk-IKCEA3YN.js";
16
+ import "./chunk-GGMM56TM.js";
17
+ import "./chunk-BQGVAXFM.js";
18
+ import "./chunk-JWDDXX5O.js";
19
+ import "./chunk-2Z4OH3BP.js";
20
+ import "./chunk-4E33RZMM.js";
11
21
  import {
12
22
  events,
13
23
  navigate
14
24
  } from "./chunk-EQZOJU3B.js";
15
- import {
16
- configure
17
- } from "./chunk-EVVYV5ED.js";
18
- import "./chunk-MGG5BW3U.js";
19
- import "./chunk-SC2KF7GJ.js";
20
- import "./chunk-TW7KYJQ6.js";
21
- import "./chunk-463H6B56.js";
22
25
  import "./chunk-GNPFWISJ.js";
23
26
  import "./chunk-MLKGABMK.js";
24
27
 
package/dist/auto.js CHANGED
@@ -1,14 +1,17 @@
1
1
  import {
2
2
  defineVitralElement
3
- } from "./chunk-CFJC4GRB.js";
4
- import "./chunk-WAU6OKK3.js";
5
- import "./chunk-VTGHPX4J.js";
3
+ } from "./chunk-SVYL6UCB.js";
4
+ import "./chunk-2SAI6S2H.js";
5
+ import "./chunk-6JH2I65O.js";
6
+ import "./chunk-AL6MLNVY.js";
7
+ import "./chunk-MICF64AZ.js";
8
+ import "./chunk-IKCEA3YN.js";
9
+ import "./chunk-GGMM56TM.js";
10
+ import "./chunk-BQGVAXFM.js";
11
+ import "./chunk-JWDDXX5O.js";
12
+ import "./chunk-2Z4OH3BP.js";
13
+ import "./chunk-4E33RZMM.js";
6
14
  import "./chunk-EQZOJU3B.js";
7
- import "./chunk-EVVYV5ED.js";
8
- import "./chunk-MGG5BW3U.js";
9
- import "./chunk-SC2KF7GJ.js";
10
- import "./chunk-TW7KYJQ6.js";
11
- import "./chunk-463H6B56.js";
12
15
  import "./chunk-GNPFWISJ.js";
13
16
  import "./chunk-MLKGABMK.js";
14
17
 
@@ -4,7 +4,8 @@ import {
4
4
  mounted,
5
5
  report,
6
6
  reported
7
- } from "./chunk-463H6B56.js";
7
+ } from "./chunk-BQGVAXFM.js";
8
+ import "./chunk-JWDDXX5O.js";
8
9
  import {
9
10
  protocol
10
11
  } from "./chunk-GNPFWISJ.js";
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  absolute
3
- } from "./chunk-TW7KYJQ6.js";
3
+ } from "./chunk-GGMM56TM.js";
4
+ import {
5
+ RemoteError
6
+ } from "./chunk-BQGVAXFM.js";
4
7
  import {
5
- RemoteError,
6
8
  ctxHooks
7
- } from "./chunk-463H6B56.js";
9
+ } from "./chunk-JWDDXX5O.js";
8
10
  import {
9
11
  protocol
10
12
  } from "./chunk-GNPFWISJ.js";
@@ -1,10 +1,14 @@
1
1
  import {
2
2
  createSlot
3
- } from "./chunk-VTGHPX4J.js";
3
+ } from "./chunk-6JH2I65O.js";
4
4
  import {
5
+ policy,
5
6
  preload,
6
7
  registerSrc
7
- } from "./chunk-EVVYV5ED.js";
8
+ } from "./chunk-AL6MLNVY.js";
9
+ import {
10
+ ctxHooks
11
+ } from "./chunk-JWDDXX5O.js";
8
12
 
9
13
  // src/core/host-slot.ts
10
14
  var noop = () => {
@@ -92,11 +96,13 @@ function hostSlot(target, options) {
92
96
  let name = key(options);
93
97
  let status = "loading";
94
98
  let item = null;
99
+ const snap = options.snapshot ? ctxHooks.snapshot?.(target, name, () => props, () => item?.box, options.onSnapshot) : void 0;
95
100
  const onStatus = (s, e) => {
96
101
  status = s;
102
+ snap?.(s);
97
103
  options.onStatus?.(s, e);
98
104
  };
99
- const cancelPrefetch = options.prefetch ? when(target, options.prefetch, () => preload(name)) : noop;
105
+ const cancelPrefetch = options.prefetch && (options.prefetch !== "idle" || policy() !== "lazy") ? when(target, options.prefetch, () => preload(name)) : noop;
100
106
  const cancel = when(target, options.loading, () => {
101
107
  cancelPrefetch();
102
108
  const found = keepAlive ? kept.get(name) : void 0;
@@ -132,6 +138,7 @@ function hostSlot(target, options) {
132
138
  destroy() {
133
139
  cancel();
134
140
  cancelPrefetch();
141
+ snap?.();
135
142
  if (!item) return;
136
143
  if (keepAlive && status === "ready") park(name, item, keepAlive === true ? 5 : keepAlive);
137
144
  else {
@@ -148,5 +155,6 @@ function hostSlot(target, options) {
148
155
 
149
156
  export {
150
157
  timings,
158
+ when,
151
159
  hostSlot
152
160
  };
@@ -0,0 +1,85 @@
1
+ import {
2
+ satisfies
3
+ } from "./chunk-4E33RZMM.js";
4
+
5
+ // src/core/dedupe-plan.ts
6
+ var parts = (v) => v.split(/[.-]/).map((n) => Number(n) || 0);
7
+ var newer = (a, b) => {
8
+ const [x, y] = [parts(a), parts(b)];
9
+ for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return y[i] - x[i];
10
+ return 0;
11
+ };
12
+ function planDedupe(remotes, host = {}) {
13
+ const groups = /* @__PURE__ */ new Map();
14
+ for (const [remote, { url, manifest }] of Object.entries(remotes)) {
15
+ if (!manifest.split) continue;
16
+ const base = new URL(url, "http://host.invalid/");
17
+ const at = (f) => {
18
+ const u = new URL(f, base);
19
+ return u.origin === "http://host.invalid" ? u.pathname + u.search : u.href;
20
+ };
21
+ for (const d of manifest.dedupe ?? []) {
22
+ const files = [d.file, ...d.chunks ?? []];
23
+ const sri = Object.fromEntries(files.filter((f) => manifest.files?.[f]).map((f) => [at(f), manifest.files[f]]));
24
+ const copy = { version: d.version, file: at(d.file), ...d.chunks?.length && { chunks: d.chunks.map(at) }, sri };
25
+ (groups.get(d.name) ?? groups.set(d.name, []).get(d.name)).push({ remote, range: d.range, copy });
26
+ }
27
+ }
28
+ const plan = {};
29
+ const notes = [];
30
+ for (const [group, needs] of groups) {
31
+ const copies = /* @__PURE__ */ new Map();
32
+ if (host[group]) copies.set(host[group], null);
33
+ for (const n of [...needs].sort((a, b) => newer(a.copy.version, b.copy.version))) if (!copies.has(n.copy.version)) copies.set(n.copy.version, n.copy);
34
+ const versions = [...copies.keys()];
35
+ const chosen = cover(versions, needs.map((n) => n.range), host[group]);
36
+ if (chosen.length > 1) {
37
+ const by = (v) => needs.filter((n) => pick(chosen, n.range, host[group]) === v).map((n) => `${n.remote} (${n.range})`);
38
+ notes.push(`${group}: as faixas n\xE3o t\xEAm uma vers\xE3o em comum; a p\xE1gina com todos os remotes baixa ${chosen.length} c\xF3pias: ${chosen.map((v) => `${v}${copies.get(v) === null ? " do host" : ""} para ${by(v).join(", ")}`).join("; ")}.`);
39
+ }
40
+ for (const n of needs) {
41
+ const v = pick(chosen, n.range, host[group]);
42
+ const copy = v ? copies.get(v) : void 0;
43
+ if (!copy || v === n.copy.version) continue;
44
+ (plan[n.remote] ??= {})[group] = { ...copy, for: `${n.range}@${n.copy.version}` };
45
+ }
46
+ }
47
+ return { plan, notes };
48
+ }
49
+ function pick(chosen, range, host) {
50
+ if (host && chosen.includes(host) && satisfies(host, range)) return host;
51
+ return chosen.filter((v) => satisfies(v, range)).sort(newer)[0];
52
+ }
53
+ function cover(versions, ranges, host) {
54
+ const serves = versions.map((v) => ranges.map((r) => satisfies(v, r)));
55
+ const ok = (set) => ranges.every((_, j) => set.some((i) => serves[i][j]));
56
+ const score = (set) => (set.some((i) => versions[i] === host) ? 1e6 : 0) - set.reduce((a, i) => a + i, 0);
57
+ if (versions.length <= 12) {
58
+ for (let size = 1; size <= versions.length; size++) {
59
+ let best;
60
+ for (let mask = 0; mask < 1 << versions.length; mask++) {
61
+ const set = versions.map((_, i) => i).filter((i) => mask & 1 << i);
62
+ if (set.length === size && ok(set) && (!best || score(set) > score(best))) best = set;
63
+ }
64
+ if (best) return best.map((i) => versions[i]);
65
+ }
66
+ }
67
+ const left = new Set(ranges.map((_, j) => j));
68
+ const out = [];
69
+ while (left.size) {
70
+ let best = -1;
71
+ let count = 0;
72
+ for (let i = 0; i < versions.length; i++) {
73
+ const c = [...left].filter((j) => serves[i][j]).length;
74
+ if (c > count) best = i, count = c;
75
+ }
76
+ if (best < 0) break;
77
+ out.push(versions[best]);
78
+ for (const j of [...left]) if (serves[best][j]) left.delete(j);
79
+ }
80
+ return out;
81
+ }
82
+
83
+ export {
84
+ planDedupe
85
+ };
@@ -0,0 +1,15 @@
1
+ // src/core/order.ts
2
+ function ordered(files, order) {
3
+ if (!order) return files;
4
+ const at = new Map(order.map((f, i) => [f, i]));
5
+ return files.map((f, i) => [f, at.get(f) ?? order.length + i]).sort((a, b) => a[1] - b[1]).map(([f]) => f);
6
+ }
7
+ function critical(m) {
8
+ const { order = [], critical: critical2 = [] } = m.split ?? {};
9
+ return new Set(critical2.map((i) => order[i]).filter(Boolean));
10
+ }
11
+
12
+ export {
13
+ ordered,
14
+ critical
15
+ };
@@ -0,0 +1,70 @@
1
+ // src/sign.ts
2
+ import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from "crypto";
3
+ import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "fs";
4
+ import { join, posix, relative, sep } from "path";
5
+ function publicKeyOf(key) {
6
+ const k = typeof key === "string" ? createPublicKey(key) : key.type === "private" ? createPublicKey(key) : key;
7
+ return Buffer.from(k.export({ format: "jwk" }).x, "base64url").toString("base64");
8
+ }
9
+ function keygen() {
10
+ const { privateKey, publicKey } = generateKeyPairSync("ed25519");
11
+ return { privateKey: privateKey.export({ format: "pem", type: "pkcs8" }), publicKey: publicKeyOf(publicKey) };
12
+ }
13
+ var digestOf = (body) => `sha-256=:${createHash("sha256").update(body).digest("base64")}:`;
14
+ var paramsOf = (keyid) => `("unencoded-digest";sf);keyid="${keyid}";tag="sri"`;
15
+ var baseOf = (digest, params) => Buffer.from(`"unencoded-digest";sf: ${digest}
16
+ "@signature-params": ${params}`);
17
+ function signBody(body, privateKey) {
18
+ const key = typeof privateKey === "string" ? createPrivateKey(privateKey) : privateKey;
19
+ const digest = digestOf(body);
20
+ const params = paramsOf(publicKeyOf(key));
21
+ return { "Unencoded-Digest": digest, "Signature-Input": `signature=${params}`, Signature: `signature=:${sign(null, baseOf(digest, params), key).toString("base64")}:` };
22
+ }
23
+ function verifyBody(body, headers, keys) {
24
+ const get = (h) => (headers instanceof Headers ? headers.get(h) : headers[h] ?? headers[h.toLowerCase()]) ?? "";
25
+ const digest = get("Unencoded-Digest");
26
+ if (digest !== digestOf(body)) return false;
27
+ const input = /(?:^|,)\s*([\w-]+)=(\("unencoded-digest";sf\);keyid="([^"]+)";tag="sri")/.exec(get("Signature-Input"));
28
+ if (!input) return false;
29
+ const [, label, params, keyid] = input;
30
+ const sig = new RegExp(`(?:^|,)\\s*${label}=:([^:]+):`).exec(get("Signature"))?.[1];
31
+ const want = keys.map((k) => k.replace(/^ed25519-/, ""));
32
+ if (!sig || !want.includes(keyid)) return false;
33
+ const pub = createPublicKey({ key: { kty: "OKP", crv: "Ed25519", x: Buffer.from(keyid, "base64").toString("base64url") }, format: "jwk" });
34
+ return verify(null, baseOf(digest, params), pub, Buffer.from(sig, "base64"));
35
+ }
36
+ var BEGIN = "# vitral sign";
37
+ var END = "# /vitral sign";
38
+ var SIGNED = /(^|\/)vitral\.json$|\.(m?js|css)$/;
39
+ function signDir(dir, privateKey, o = {}) {
40
+ const key = createPrivateKey(privateKey);
41
+ const base = ("/" + (o.base ?? "/").replace(/^\/+|\/+$/g, "") + "/").replace(/^\/\/$/, "/");
42
+ const out = {};
43
+ const walk = (d) => {
44
+ for (const f of readdirSync(d).sort()) {
45
+ const p = join(d, f);
46
+ if (statSync(p).isDirectory()) walk(p);
47
+ else {
48
+ const rel = relative(dir, p).split(sep).join(posix.sep);
49
+ if (SIGNED.test(rel)) out[base + rel] = signBody(readFileSync(p), key);
50
+ }
51
+ }
52
+ };
53
+ walk(dir);
54
+ writeFileSync(join(dir, "vitral-signatures.json"), JSON.stringify(out, null, 2) + "\n");
55
+ if (o.headersFile !== false) {
56
+ const file = join(dir, "_headers");
57
+ const block = [BEGIN, ...Object.entries(out).flatMap(([path, h]) => [path, ...Object.entries(h).map(([k, v]) => ` ${k}: ${v}`)]), END].join("\n");
58
+ const old = existsSync(file) ? readFileSync(file, "utf8").replace(new RegExp(`\\n?${BEGIN}[\\s\\S]*?${END}\\n?`), "\n").trim() : "";
59
+ writeFileSync(file, (old ? old + "\n\n" : "") + block + "\n");
60
+ }
61
+ return out;
62
+ }
63
+
64
+ export {
65
+ publicKeyOf,
66
+ keygen,
67
+ signBody,
68
+ verifyBody,
69
+ signDir
70
+ };
@@ -1,28 +1,30 @@
1
- import {
2
- events,
3
- navigate,
4
- scopedEvents
5
- } from "./chunk-EQZOJU3B.js";
6
1
  import {
7
2
  load,
8
3
  loadFile,
9
4
  registerSrc,
10
5
  resolveEntry
11
- } from "./chunk-EVVYV5ED.js";
6
+ } from "./chunk-AL6MLNVY.js";
12
7
  import {
13
8
  injectStyles
14
- } from "./chunk-SC2KF7GJ.js";
9
+ } from "./chunk-IKCEA3YN.js";
15
10
  import {
16
11
  metric
17
- } from "./chunk-TW7KYJQ6.js";
12
+ } from "./chunk-GGMM56TM.js";
18
13
  import {
19
14
  RemoteError,
20
- ctxHooks,
21
15
  fail,
22
16
  isRemoteError,
23
17
  mounted,
24
18
  report
25
- } from "./chunk-463H6B56.js";
19
+ } from "./chunk-BQGVAXFM.js";
20
+ import {
21
+ ctxHooks
22
+ } from "./chunk-JWDDXX5O.js";
23
+ import {
24
+ events,
25
+ navigate,
26
+ scopedEvents
27
+ } from "./chunk-EQZOJU3B.js";
26
28
  import {
27
29
  protocol
28
30
  } from "./chunk-GNPFWISJ.js";
@@ -85,7 +87,7 @@ var noop = () => {
85
87
  async function checkUpdates() {
86
88
  const p = protocol();
87
89
  const found = [];
88
- const { splitName } = await import("./expose-BA4HSXDP.js");
90
+ const { splitName } = await import("./expose-2S3TCXSP.js");
89
91
  const remotes = /* @__PURE__ */ new Map();
90
92
  for (const name of live.keys()) {
91
93
  const root = splitName(name)[0];
@@ -130,8 +132,8 @@ async function mountOnce(target, name, props, options) {
130
132
  const p = protocol();
131
133
  await p.pending();
132
134
  const isolate = options.isolate ?? registered(name)?.isolate ?? p.settings().isolate;
133
- if (isolate === "iframe") return (frames ?? (await import("./reframe-ZOQPW552.js")).noFrames)(target, name, props, options).catch(fail);
134
- const { module: mod, ...resolved } = await (isolate == "reframe" ? (await import("./reframe-ZOQPW552.js")).load : load)(name, isolate, options.priority);
135
+ if (isolate === "iframe") return (frames ?? (await import("./reframe-HIYA2TIU.js")).noFrames)(target, name, props, options).catch(fail);
136
+ const { module: mod, ...resolved } = await (isolate == "reframe" ? (await import("./reframe-HIYA2TIU.js")).load : load)(name, isolate, options.priority);
135
137
  const untrack = track(name, resolved);
136
138
  ctxHooks.watch?.(name);
137
139
  const label = resolved.name ?? name;
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  dedupeModule,
3
3
  sriModule
4
- } from "./chunk-MGG5BW3U.js";
4
+ } from "./chunk-MICF64AZ.js";
5
5
  import {
6
6
  prefetchCss
7
- } from "./chunk-SC2KF7GJ.js";
7
+ } from "./chunk-IKCEA3YN.js";
8
8
  import {
9
9
  absolute,
10
10
  addLink,
@@ -13,13 +13,13 @@ import {
13
13
  pageOrigin,
14
14
  withRetry,
15
15
  withTimeout
16
- } from "./chunk-TW7KYJQ6.js";
16
+ } from "./chunk-GGMM56TM.js";
17
17
  import {
18
18
  RemoteError,
19
19
  fail,
20
20
  isRemoteError,
21
21
  report
22
- } from "./chunk-463H6B56.js";
22
+ } from "./chunk-BQGVAXFM.js";
23
23
  import {
24
24
  protocol
25
25
  } from "./chunk-GNPFWISJ.js";
@@ -29,7 +29,7 @@ function configure(config) {
29
29
  const p = protocol();
30
30
  const { remotes, dedupe, ...rest } = config;
31
31
  p.configure(rest);
32
- if (rest.captureGlobalErrors) import("./capture-A6JQNNQY.js").then((m) => m.capture());
32
+ if (rest.captureGlobalErrors) import("./capture-2I5IQ2C2.js").then((m) => m.capture());
33
33
  if (dedupe) p.pending(dedupeModule().then((m) => m.offer(p, dedupe)).catch(() => {
34
34
  }));
35
35
  if (typeof remotes === "string") {
@@ -78,12 +78,35 @@ function checkOrigin(name, url) {
78
78
  throw new RemoteError("ORIGIN_BLOCKED", name, `origem ${origin} n\xE3o est\xE1 em allowedOrigins`);
79
79
  }
80
80
 
81
+ // src/core/policy.ts
82
+ function choose(s) {
83
+ return s.saveData || /2g/.test(s.effectiveType) ? "lazy" : s.effectiveType == "3g" || s.deviceMemory <= 2 ? "critical" : "all";
84
+ }
85
+ function signals() {
86
+ const n = typeof navigator == "object" ? navigator : {};
87
+ return { saveData: n.connection?.saveData, effectiveType: n.connection?.effectiveType, deviceMemory: n.deviceMemory };
88
+ }
89
+ function signalsFrom(headers) {
90
+ const get = (k) => {
91
+ if (typeof headers.get === "function") return headers.get(k) ?? void 0;
92
+ const v = headers[k];
93
+ return Array.isArray(v) ? v[0] : v;
94
+ };
95
+ const memory = Number(get("device-memory"));
96
+ return { saveData: get("save-data") === "on" || void 0, effectiveType: get("ect"), deviceMemory: Number.isFinite(memory) && get("device-memory") ? memory : void 0 };
97
+ }
98
+ function policy() {
99
+ const n = typeof navigator == "object" ? navigator : {};
100
+ const c = n.connection || {};
101
+ return protocol().settings().policy || (c.saveData || /2g/.test(c.effectiveType) ? "lazy" : c.effectiveType == "3g" || n.deviceMemory <= 2 ? "critical" : "all");
102
+ }
103
+
81
104
  // src/core/loader.ts
82
105
  function loadRemote(name) {
83
106
  return load(name).then((r) => r.module);
84
107
  }
85
108
  function loadModule(name) {
86
- return import("./expose-BA4HSXDP.js").then((m) => m.resolveModule(name, (n) => loadFile(n))).catch(fail);
109
+ return import("./expose-2S3TCXSP.js").then((m) => m.resolveModule(name, (n) => loadFile(n))).catch(fail);
87
110
  }
88
111
  function preload(name, options = {}) {
89
112
  const done = load(name);
@@ -101,8 +124,7 @@ function routeChunks(r) {
101
124
  return Object.keys(r.sri ?? {}).filter((u) => u.startsWith(dir) && u.endsWith(".js") && !loaded.has(u));
102
125
  }
103
126
  function warmRoutes(r) {
104
- const c = navigator.connection;
105
- if (c?.saveData || /2g/.test(c?.effectiveType)) return;
127
+ if (policy() !== "all") return;
106
128
  const queue = routeChunks(r).slice();
107
129
  const next = () => queue.length && fetch(queue.shift(), { priority: "low" }).then((res) => res.arrayBuffer()).catch(() => {
108
130
  }).then(next);
@@ -124,7 +146,7 @@ function warmSsr(holder) {
124
146
  }
125
147
  function load(name, isolate, priority) {
126
148
  const file = (n) => loadFile(n, isolate, priority);
127
- return (protocol().entry(name) || !name.includes("/") ? file(name).then((r) => mountable(name, r)) : import("./expose-BA4HSXDP.js").then((m) => m.resolveTarget(name, file))).catch(fail);
149
+ return (protocol().entry(name) || !name.includes("/") ? file(name).then((r) => mountable(name, r)) : import("./expose-2S3TCXSP.js").then((m) => m.resolveTarget(name, file))).catch(fail);
128
150
  }
129
151
  function loadFile(name, isolate, priority) {
130
152
  const p = protocol();
@@ -133,7 +155,7 @@ function loadFile(name, isolate, priority) {
133
155
  let resolved;
134
156
  try {
135
157
  const known = p.entry(name);
136
- const early = known?.url && !known.module && !known.manifest && !overrides() ? prefetchManifest(known.url, name, priority) : void 0;
158
+ const early = known?.url && !known.module && !known.manifest && !overrides() ? prefetchManifest(known.url, name, priority, signed(known)) : void 0;
137
159
  await p.pending();
138
160
  const override = await devOverride(name);
139
161
  const entry = override ? { isolate: p.entry(name)?.isolate, ...override } : p.entry(name);
@@ -171,23 +193,24 @@ async function loadLocal(name, entry) {
171
193
  }
172
194
  async function resolveEntry(name, entry, priority, early) {
173
195
  checkOrigin(name, entry.url);
174
- const m = entry.manifest ?? (new URL(entry.url).pathname.endsWith(".json") ? await (early ?? manifestOf(entry.url, name, priority)) : { name, entry: entry.url });
175
- if (m?.stable) return resolveEntry(name, await (await import("./channel-2DUQQPPA.js")).pick(name, entry, m), priority);
196
+ const keys = signed(entry);
197
+ const m = entry.manifest ?? (new URL(entry.url).pathname.endsWith(".json") ? await (early ?? manifestOf(entry.url, name, priority, keys)) : { name, entry: entry.url });
198
+ if (m?.stable) return resolveEntry(name, await (await import("./channel-ABGK26Q5.js")).pick(name, entry, m), priority);
176
199
  if (typeof m?.entry !== "string") throw new RemoteError("INVALID_MODULE", name, `manifesto inv\xE1lido em ${entry.url}`);
177
200
  if (m.contract && (entry.contract || protocol().settings().contract)) {
178
- const why = await (await import("./contract-IXM52LVW.js")).checkContract(m.contract, entry.contract);
201
+ const why = await (await import("./contract-3JY7SOGQ.js")).checkContract(m.contract, entry.contract);
179
202
  if (why) throw new RemoteError("CONTRACT_MISMATCH", name, why);
180
203
  }
181
204
  const abs = (u) => absolute(u, entry.url);
182
205
  const sri = {};
183
- for (const file in m.files ?? {}) sri[abs(file)] = m.files[file];
206
+ for (const file in m.files ?? {}) sri[abs(file)] = m.files[file] + keys;
184
207
  const resolved = {
185
208
  entry: abs(m.entry),
186
209
  css: [...m.css ?? [], ...entry.css ?? []].map(abs),
187
210
  shadow: m.shadow,
188
211
  // A integridade declarada pelo host vence a do manifesto, e aí só o
189
212
  // arquivo único (o que ela descreve) é usado.
190
- integrity: entry.integrity === false ? void 0 : entry.integrity ?? m.integrity,
213
+ integrity: entry.integrity === false ? void 0 : entry.integrity ?? (m.integrity && m.integrity + keys),
191
214
  isolate: entry.isolate,
192
215
  scope: m.scope,
193
216
  version: m.version,
@@ -213,21 +236,22 @@ async function resolveEntry(name, entry, priority, early) {
213
236
  }
214
237
  return resolved;
215
238
  }
216
- function prefetchManifest(url, name, priority) {
239
+ var signed = (e) => (e.keys ?? []).map((k) => " ed25519-" + k).join("");
240
+ function prefetchManifest(url, name, priority, keys) {
217
241
  try {
218
242
  if (!new URL(url).pathname.endsWith(".json")) return;
219
243
  checkOrigin(name, url);
220
244
  } catch {
221
245
  return;
222
246
  }
223
- const f = manifestOf(url, name, priority);
247
+ const f = manifestOf(url, name, priority, keys);
224
248
  f.catch(() => {
225
249
  });
226
250
  return f;
227
251
  }
228
- function manifestOf(url, name, priority) {
252
+ function manifestOf(url, name, priority, keys) {
229
253
  const { timeout, maxStale } = protocol().settings();
230
- const fresh = fetchJson(url, timeout, name, { cache: "no-cache", credentials: "same-origin", priority });
254
+ const fresh = fetchJson(url, timeout, name, { cache: "no-cache", credentials: "same-origin", priority, integrity: keys.slice(1) });
231
255
  return maxStale ? import("./stale-XV4LNHDX.js").then((m) => m.stale(url, fresh, maxStale), () => fresh) : fresh;
232
256
  }
233
257
  async function importModule(name, r) {
@@ -242,8 +266,8 @@ async function importModule(name, r) {
242
266
  if (!r.integrity) {
243
267
  if (!r.split) return run(r.entry);
244
268
  if (r.split.dedupe?.length) {
245
- const { shared } = await dedupeModule();
246
- for (const d of r.split.dedupe)
269
+ const { shared, planned } = await dedupeModule();
270
+ for (const d of planned(name, r.split).dedupe)
247
271
  shared(protocol())(d.name, d.range, { version: d.version, url: d.file, load: async () => (await run(d.file)).default });
248
272
  }
249
273
  return run(r.split.entry);
@@ -263,6 +287,10 @@ export {
263
287
  configure,
264
288
  register,
265
289
  registerSrc,
290
+ choose,
291
+ signals,
292
+ signalsFrom,
293
+ policy,
266
294
  loadRemote,
267
295
  loadModule,
268
296
  preload,
@@ -0,0 +1,21 @@
1
+ // src/core/ssr-markup.ts
2
+ var attr = (s) => s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
3
+ var inlineJson = (v) => JSON.stringify(v).replace(/</g, "\\u003c");
4
+ function stateScript(r) {
5
+ return typeof r === "object" && r.state !== void 0 ? `<script type="application/json" data-vitral-state>${inlineJson(r.state)}</script>` : "";
6
+ }
7
+ var htmlOf = (r) => typeof r === "string" ? r : r.html;
8
+ function ssrHolder(name, m, rendered, css, seed) {
9
+ const n = attr(name);
10
+ const scope = m.scope ? ` data-vitral-scope="${attr(m.scope)}"` : "";
11
+ const links = css.map(([href, sri]) => `<link rel="stylesheet" href="${attr(href)}" crossorigin="anonymous"${sri ? ` integrity="${attr(sri)}"` : ""}>`).join("");
12
+ const manifest = seed ? `<script type="application/json" data-vitral-manifest="${attr(seed[0])}">${inlineJson(seed[1])}</script>` : "";
13
+ return `<div data-vitral-ssr data-vitral-slot="${n}">${manifest}${stateScript(rendered)}${links}<div data-vitral-root="${n}"${scope} style="display:contents">${htmlOf(rendered)}</div></div>`;
14
+ }
15
+
16
+ export {
17
+ inlineJson,
18
+ stateScript,
19
+ htmlOf,
20
+ ssrHolder
21
+ };
@@ -1,10 +1,10 @@
1
+ import {
2
+ ctxHooks
3
+ } from "./chunk-JWDDXX5O.js";
1
4
  import {
2
5
  protocol
3
6
  } from "./chunk-GNPFWISJ.js";
4
7
 
5
- // src/core/hooks.ts
6
- var ctxHooks = {};
7
-
8
8
  // src/core/errors.ts
9
9
  var ERROR_DOCS = "https://joaogabriel15.github.io/vitral/erros/";
10
10
  var RemoteError = class extends Error {
@@ -40,7 +40,6 @@ var fail = (e) => {
40
40
  };
41
41
 
42
42
  export {
43
- ctxHooks,
44
43
  RemoteError,
45
44
  isRemoteError,
46
45
  mounted,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  RemoteError,
3
3
  isRemoteError
4
- } from "./chunk-463H6B56.js";
4
+ } from "./chunk-BQGVAXFM.js";
5
5
  import {
6
6
  protocol
7
7
  } from "./chunk-GNPFWISJ.js";