vitral 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +1 -1
  2. package/dist/angular.d.ts +3 -2
  3. package/dist/angular.js +7 -6
  4. package/dist/auto.js +7 -6
  5. package/dist/capture-TT5WBLJ6.js +42 -0
  6. package/dist/channel-2YPYGX3J.js +95 -0
  7. package/dist/chunk-463H6B56.js +50 -0
  8. package/dist/chunk-54CBIZES.js +105 -0
  9. package/dist/chunk-6EX5KYT5.js +64 -0
  10. package/dist/{chunk-6Y3VMWHH.js → chunk-BCC25ANK.js} +11 -5
  11. package/dist/{chunk-2XF5BKV3.js → chunk-EMSB2NVX.js} +26 -13
  12. package/dist/{chunk-HP6QWU6K.js → chunk-IH3ZT3QU.js} +2 -2
  13. package/dist/{chunk-PX7PBCCT.js → chunk-TW7KYJQ6.js} +7 -17
  14. package/dist/{chunk-S5MZT5IT.js → chunk-UYOPJ4XQ.js} +1 -1
  15. package/dist/{chunk-UTYAX6MU.js → chunk-W6322KGP.js} +2 -2
  16. package/dist/{chunk-NCONW6WS.js → chunk-WD4CDGDZ.js} +73 -44
  17. package/dist/cli.js +1196 -31
  18. package/dist/contract-46EZFQPQ.js +17 -0
  19. package/dist/{dedupe-IWFIXRWG.js → dedupe-S7BHQMOZ.js} +4 -3
  20. package/dist/devtools.d.ts +32 -2
  21. package/dist/devtools.js +27 -12
  22. package/dist/element.d.ts +13 -4
  23. package/dist/element.js +7 -6
  24. package/dist/embed.js +2 -0
  25. package/dist/{errors-KKB8FGCz.d.ts → errors-kjBv6IH_.d.ts} +7 -1
  26. package/dist/{events-DUdjhfps.d.ts → events-Dkpkw_Sv.d.ts} +1 -1
  27. package/dist/expose-OVWTPHH5.js +15 -0
  28. package/dist/federation.d.ts +89 -0
  29. package/dist/federation.js +101 -0
  30. package/dist/iframe.d.ts +1 -1
  31. package/dist/iframe.js +13 -10
  32. package/dist/index.d.ts +23 -21
  33. package/dist/index.js +5 -4
  34. package/dist/otel.d.ts +44 -0
  35. package/dist/otel.js +27 -0
  36. package/dist/overrides-NP754HY7.js +27 -0
  37. package/dist/preact.d.ts +5 -5
  38. package/dist/preact.js +6 -5
  39. package/dist/react.d.ts +12 -4
  40. package/dist/react.js +11 -6
  41. package/dist/routes.d.ts +3 -3
  42. package/dist/routes.js +5 -4
  43. package/dist/sentry.d.ts +25 -0
  44. package/dist/sentry.js +11 -0
  45. package/dist/shadow-PVSETNMZ.js +159 -0
  46. package/dist/single-spa.d.ts +40 -0
  47. package/dist/single-spa.js +52 -0
  48. package/dist/{slot-pB276oPt.d.ts → slot-UPg6ob9v.d.ts} +2 -2
  49. package/dist/solid.d.ts +4 -4
  50. package/dist/solid.js +6 -5
  51. package/dist/{sri-BVKZNX5Q.js → sri-M7ZRU57G.js} +43 -11
  52. package/dist/svelte.d.ts +5 -5
  53. package/dist/svelte.js +6 -5
  54. package/dist/testing.d.ts +2 -1
  55. package/dist/testing.js +5 -4
  56. package/dist/{types-BV-hUrms.d.ts → types-CA2p9KHC.d.ts} +174 -4
  57. package/dist/vite.d.ts +26 -0
  58. package/dist/vite.js +686 -51
  59. package/dist/vue.d.ts +11 -4
  60. package/dist/vue.js +10 -5
  61. package/package.json +115 -23
  62. package/dist/chunk-DXORSF4X.js +0 -42
  63. package/dist/chunk-SFL6LTP3.js +0 -56
  64. package/dist/expose-53BEJB34.js +0 -14
  65. package/dist/overrides-NZAIUGK5.js +0 -15
  66. package/dist/shadow-MYRJQLLY.js +0 -72
package/README.md CHANGED
@@ -187,7 +187,7 @@ Para isolar por completo, use Shadow DOM:
187
187
  <Remote name="carrinho" isolate="shadow" />
188
188
  ```
189
189
 
190
- Com Shadow DOM, as regras `@property` e `@font-face` sobem para o documento, então sombras, rings, gradientes e fontes do Tailwind v4 funcionam.
190
+ Com Shadow DOM, as regras `@property` e `@font-face` sobem para o documento, então sombras, rings, gradientes e fontes do Tailwind v4 funcionam. O plugin já faz essa separação no build (campo `shadow` do `vitral.json`): a página só adota o CSS pronto. Manifestos antigos continuam funcionando, com a separação feita no navegador.
191
191
 
192
192
  O remote também pode usar o tema do host:
193
193
 
package/dist/angular.d.ts CHANGED
@@ -1,7 +1,8 @@
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-BV-hUrms.js';
3
- export { e as events } from './events-DUdjhfps.js';
2
+ import { R as RemoteContext, P as Props, a as RemoteModule, S as Shared, V as VitralConfig } from './types-CA2p9KHC.js';
3
+ export { e as events } from './events-Dkpkw_Sv.js';
4
4
  export { n as navigate } from './navigate-BRG1WJUM.js';
5
+ import './errors-kjBv6IH_.js';
5
6
 
6
7
  /**
7
8
  * Adaptador Angular (standalone, zoneless ou com zone.js).
package/dist/angular.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineVitralElement
3
- } from "./chunk-6Y3VMWHH.js";
4
- import "./chunk-UTYAX6MU.js";
3
+ } from "./chunk-BCC25ANK.js";
4
+ import "./chunk-W6322KGP.js";
5
5
  import {
6
6
  defineRemote,
7
7
  events,
@@ -9,12 +9,13 @@ import {
9
9
  navigate,
10
10
  same,
11
11
  shared
12
- } from "./chunk-NCONW6WS.js";
12
+ } from "./chunk-WD4CDGDZ.js";
13
13
  import {
14
14
  configure
15
- } from "./chunk-2XF5BKV3.js";
16
- import "./chunk-SFL6LTP3.js";
17
- import "./chunk-PX7PBCCT.js";
15
+ } from "./chunk-EMSB2NVX.js";
16
+ import "./chunk-6EX5KYT5.js";
17
+ import "./chunk-TW7KYJQ6.js";
18
+ import "./chunk-463H6B56.js";
18
19
  import "./chunk-GNPFWISJ.js";
19
20
 
20
21
  // src/angular.ts
package/dist/auto.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  defineVitralElement
3
- } from "./chunk-6Y3VMWHH.js";
4
- import "./chunk-UTYAX6MU.js";
5
- import "./chunk-NCONW6WS.js";
6
- import "./chunk-2XF5BKV3.js";
7
- import "./chunk-SFL6LTP3.js";
8
- import "./chunk-PX7PBCCT.js";
3
+ } from "./chunk-BCC25ANK.js";
4
+ import "./chunk-W6322KGP.js";
5
+ import "./chunk-WD4CDGDZ.js";
6
+ import "./chunk-EMSB2NVX.js";
7
+ import "./chunk-6EX5KYT5.js";
8
+ import "./chunk-TW7KYJQ6.js";
9
+ import "./chunk-463H6B56.js";
9
10
  import "./chunk-GNPFWISJ.js";
10
11
 
11
12
  // src/auto.ts
@@ -0,0 +1,42 @@
1
+ import {
2
+ RemoteError,
3
+ isRemoteError,
4
+ mounted,
5
+ report,
6
+ reported
7
+ } from "./chunk-463H6B56.js";
8
+ import {
9
+ protocol
10
+ } from "./chunk-GNPFWISJ.js";
11
+
12
+ // src/core/capture.ts
13
+ var on = false;
14
+ function capture() {
15
+ if (on || typeof addEventListener == "undefined") return;
16
+ on = true;
17
+ addEventListener("error", (e) => attribute(e.error, e.filename));
18
+ addEventListener("unhandledrejection", (e) => attribute(e.reason));
19
+ }
20
+ function owner(error, file) {
21
+ const url = file || String(error?.stack ?? "").match(/(?:https?|file):\/\/[^\s)'"]+/)?.[0];
22
+ if (!url) return;
23
+ const host = [...document.querySelectorAll("script[src],link[rel=modulepreload]")].map(
24
+ (el) => el.src || el.href
25
+ );
26
+ let best;
27
+ let size = 0;
28
+ for (const [name, { entry }] of mounted) {
29
+ const dir = new URL(".", entry).href;
30
+ if (dir.length > size && url.startsWith(dir) && !host.some((u) => u.startsWith(dir))) best = name, size = dir.length;
31
+ }
32
+ return best;
33
+ }
34
+ function attribute(error, file) {
35
+ if (!protocol().settings().captureGlobalErrors || isRemoteError(error) || error instanceof Object && reported.has(error)) return;
36
+ const name = owner(error, file);
37
+ if (name) report(new RemoteError("RENDER_FAILED", name, String(error?.message ?? error), error), mounted.get(name));
38
+ }
39
+ export {
40
+ capture,
41
+ owner
42
+ };
@@ -0,0 +1,95 @@
1
+ import {
2
+ absolute
3
+ } from "./chunk-TW7KYJQ6.js";
4
+ import {
5
+ RemoteError,
6
+ ctxHooks
7
+ } from "./chunk-463H6B56.js";
8
+ import {
9
+ protocol
10
+ } from "./chunk-GNPFWISJ.js";
11
+
12
+ // src/core/channel.ts
13
+ var ROLLBACK_KEY = "vitral:rollback";
14
+ var ID_KEY = "vitral:id";
15
+ var watching = /* @__PURE__ */ new Map();
16
+ var abandoned = {};
17
+ var id;
18
+ async function pick(name, entry, channel) {
19
+ if (typeof channel.stable != "string") throw new RemoteError("INVALID_MODULE", name, `canal inv\xE1lido em ${entry.url}: falta "stable"`);
20
+ ctxHooks.watch = watch;
21
+ const ctx = { name, bucket: bucket(name) };
22
+ const { canary, stable } = channel;
23
+ let version = await entry.resolve?.(channel, ctx) ?? (canary && ctx.bucket < canary.percent ? canary.version : stable);
24
+ if (version !== stable && rolledBack()[name] === version) version = stable;
25
+ if (version === stable || entry.rollback === false) watching.delete(name);
26
+ else if (watching.get(name)?.from !== version) {
27
+ watching.set(name, { from: version, to: stable, errors: 0, mounts: 0, max: { errors: 3, mounts: 20, ...entry.rollback } });
28
+ }
29
+ return { ...entry, url: versionUrl(version, entry.url), integrity: void 0, manifest: void 0 };
30
+ }
31
+ var versionUrl = (version, channel) => absolute(/[/:]|\.(m?js|json)$/.test(version) ? version : `${version}/vitral.json`, channel);
32
+ function bucket(name) {
33
+ const key = protocol().settings().canaryKey ?? browserId();
34
+ let h = 2166136261;
35
+ for (const c of `${key}:${name}`) h = Math.imul(h ^ c.charCodeAt(0), 16777619);
36
+ return (h >>> 0) % 100;
37
+ }
38
+ function browserId() {
39
+ try {
40
+ id ??= localStorage.getItem(ID_KEY) ?? void 0;
41
+ } catch {
42
+ }
43
+ if (!id) {
44
+ id = Math.random().toString(36).slice(2);
45
+ try {
46
+ localStorage.setItem(ID_KEY, id);
47
+ } catch {
48
+ }
49
+ }
50
+ return id;
51
+ }
52
+ function rolledBack() {
53
+ try {
54
+ return { ...JSON.parse(sessionStorage.getItem(ROLLBACK_KEY) || "{}"), ...abandoned };
55
+ } catch {
56
+ return abandoned;
57
+ }
58
+ }
59
+ function watch(name, error) {
60
+ for (const [key, w] of watching) {
61
+ if (name !== key && !name.startsWith(key + "/")) continue;
62
+ if (!error) {
63
+ if (++w.mounts > w.max.mounts) w.mounts = 1, w.errors = 0;
64
+ } else if (++w.errors >= w.max.errors) {
65
+ rollback(key, w);
66
+ }
67
+ }
68
+ }
69
+ function rollback(name, w) {
70
+ watching.delete(name);
71
+ abandoned = { ...rolledBack(), [name]: w.from };
72
+ try {
73
+ sessionStorage.setItem(ROLLBACK_KEY, JSON.stringify(abandoned));
74
+ } catch {
75
+ }
76
+ console.warn(`[vitral] ${name}: ${w.errors} erros em ${w.mounts} montagens da vers\xE3o ${w.from}; voltando para ${w.to}`);
77
+ try {
78
+ protocol().settings().onRollback?.({ name, from: w.from, to: w.to, errors: w.errors, mounts: w.mounts });
79
+ } catch {
80
+ }
81
+ const p = protocol();
82
+ p.register(name, p.entry(name));
83
+ p.events.emit("vitral:refresh", name);
84
+ }
85
+ function resetChannels() {
86
+ watching.clear();
87
+ abandoned = {};
88
+ id = void 0;
89
+ }
90
+ export {
91
+ bucket,
92
+ pick,
93
+ resetChannels,
94
+ versionUrl
95
+ };
@@ -0,0 +1,50 @@
1
+ import {
2
+ protocol
3
+ } from "./chunk-GNPFWISJ.js";
4
+
5
+ // src/core/hooks.ts
6
+ var ctxHooks = {};
7
+
8
+ // src/core/errors.ts
9
+ var ERROR_DOCS = "https://joaogabriel15.github.io/vitral/erros/";
10
+ var RemoteError = class extends Error {
11
+ constructor(code, remote, message, cause) {
12
+ super(`[vitral] ${remote}: ${message} (${ERROR_DOCS}${code})`);
13
+ this.code = code;
14
+ this.remote = remote;
15
+ this.cause = cause;
16
+ this.name = "RemoteError";
17
+ this.docs = `${ERROR_DOCS}${code}`;
18
+ if (typeof location != "undefined") this.route = location.pathname;
19
+ }
20
+ };
21
+ var isRemoteError = (e) => e?.name === "RemoteError";
22
+ var mounted = /* @__PURE__ */ new Map();
23
+ var reported = /* @__PURE__ */ new WeakSet();
24
+ function report(e, from) {
25
+ if (isRemoteError(e) && !reported.has(e)) {
26
+ reported.add(e);
27
+ if (e.cause instanceof Object) reported.add(e.cause);
28
+ e.entry ??= from?.entry ?? protocol().entry(e.remote)?.url;
29
+ e.version ??= from?.version;
30
+ try {
31
+ protocol().settings().onError?.(e);
32
+ } catch {
33
+ }
34
+ ctxHooks.watch?.(e.remote, e);
35
+ }
36
+ return e;
37
+ }
38
+ var fail = (e) => {
39
+ throw report(e);
40
+ };
41
+
42
+ export {
43
+ ctxHooks,
44
+ RemoteError,
45
+ isRemoteError,
46
+ mounted,
47
+ reported,
48
+ report,
49
+ fail
50
+ };
@@ -0,0 +1,105 @@
1
+ import {
2
+ protocol
3
+ } from "./chunk-GNPFWISJ.js";
4
+
5
+ // src/core/overrides.ts
6
+ var OVERRIDES_KEY = "vitral:overrides";
7
+ function overridesEnabled() {
8
+ return !!protocol().settings().devOverrides || typeof location !== "undefined" && /^(localhost|127\.0\.0\.1|\[::1\])$/.test(location.hostname);
9
+ }
10
+ var manifestUrl = (url) => /\.(json|m?js)(\?|$)/.test(url) ? url : url.replace(/\/?$/, "/vitral.json");
11
+ var isRef = (value) => /^[\w.-]+$/.test(value);
12
+ var read = (store) => {
13
+ try {
14
+ return JSON.parse(store().getItem(OVERRIDES_KEY) ?? "{}") ?? {};
15
+ } catch {
16
+ return {};
17
+ }
18
+ };
19
+ var write = (store, all) => {
20
+ try {
21
+ if (Object.keys(all).length) store().setItem(OVERRIDES_KEY, JSON.stringify(all));
22
+ else store().removeItem(OVERRIDES_KEY);
23
+ } catch {
24
+ }
25
+ };
26
+ var local = () => localStorage;
27
+ var session = () => sessionStorage;
28
+ var storedOverrides = () => read(local);
29
+ function storeOverride(name, value) {
30
+ const all = storedOverrides();
31
+ if (value) all[name] = isRef(value) ? value : manifestUrl(value);
32
+ else delete all[name];
33
+ write(local, all);
34
+ }
35
+ function tabOverrides() {
36
+ const all = read(session);
37
+ const pairs = new URLSearchParams(location.search).getAll("vitral").join(",").split(",");
38
+ if (!pairs.some(Boolean)) return all;
39
+ for (const pair of pairs) {
40
+ const at = pair.indexOf("@");
41
+ if (pair === "off") clearOverrides(), Object.keys(all).forEach((k) => delete all[k]);
42
+ else if (at > 0 && pair.slice(at + 1) === "off") delete all[pair.slice(0, at)];
43
+ else if (at > 0) all[pair.slice(0, at)] = pair.slice(at + 1);
44
+ }
45
+ write(session, all);
46
+ return all;
47
+ }
48
+ function clearOverrides() {
49
+ write(session, {});
50
+ write(local, {});
51
+ }
52
+ function dropOverride(name) {
53
+ for (const store of [session, local]) {
54
+ const all = read(store);
55
+ delete all[name];
56
+ write(store, all);
57
+ }
58
+ }
59
+ function resolveOverride(name, value) {
60
+ if (!isRef(value)) return new URL(manifestUrl(value), location.href).href;
61
+ const d = protocol().settings().devOverrides;
62
+ const preview = typeof d === "object" ? d.preview : void 0;
63
+ if (!preview) return;
64
+ const url = preview.replace(/\{name\}/g, encodeURIComponent(name)).replace(/\{ref\}/g, encodeURIComponent(value));
65
+ return new URL(manifestUrl(url), location.href).href;
66
+ }
67
+ function activeOverrides() {
68
+ const tab = tabOverrides();
69
+ const all = {};
70
+ for (const [source, map] of [["navegador", storedOverrides()], ["aba", tab]]) {
71
+ for (const [name, value] of Object.entries(map)) all[name] = { name, value, url: resolveOverride(name, value), source };
72
+ }
73
+ return Object.values(all);
74
+ }
75
+ var warned = /* @__PURE__ */ new Set();
76
+ function overrideFor(name) {
77
+ if (!overridesEnabled()) return;
78
+ const o = activeOverrides().find((o2) => o2.name === name);
79
+ if (!o) return;
80
+ const first = !warned.has(name) && warned.add(name);
81
+ if (!o.url) {
82
+ if (first) console.warn(`[vitral] override ${name}@${o.value} ignorado: falta configure({ devOverrides: { preview } })`);
83
+ return;
84
+ }
85
+ const p = protocol();
86
+ const trusted = p.settings().trusted ?? [];
87
+ const origin = new URL(o.url).origin;
88
+ if (!trusted.includes(origin)) p.configure({ trusted: [...trusted, origin] });
89
+ if (first) console.warn(`[vitral] override ativo: ${name} \u2192 ${o.url} (${o.source}). Para limpar: ?vitral=off`);
90
+ return { url: o.url };
91
+ }
92
+
93
+ export {
94
+ OVERRIDES_KEY,
95
+ overridesEnabled,
96
+ manifestUrl,
97
+ isRef,
98
+ storedOverrides,
99
+ storeOverride,
100
+ clearOverrides,
101
+ dropOverride,
102
+ resolveOverride,
103
+ activeOverrides,
104
+ overrideFor
105
+ };
@@ -0,0 +1,64 @@
1
+ import {
2
+ addLink,
3
+ fetchBytes
4
+ } from "./chunk-TW7KYJQ6.js";
5
+ import {
6
+ protocol
7
+ } from "./chunk-GNPFWISJ.js";
8
+
9
+ // src/core/css.ts
10
+ var loadedCss = /* @__PURE__ */ new WeakMap();
11
+ var cssText = /* @__PURE__ */ new Map();
12
+ var noop = () => {
13
+ };
14
+ var adopts = () => typeof CSSStyleSheet !== "undefined" && "replaceSync" in CSSStyleSheet.prototype;
15
+ function fetchCssText(href, integrity, priority) {
16
+ const key = `${href} ${integrity ?? ""}`;
17
+ let p = cssText.get(key);
18
+ if (!p) {
19
+ p = fetchBytes(href, protocol().settings().timeout, href, { integrity, priority }).then((b) => new TextDecoder().decode(b));
20
+ p.catch(() => cssText.delete(key));
21
+ cssText.set(key, p);
22
+ }
23
+ return p;
24
+ }
25
+ function prefetchCss(r, shadow, priority = "auto") {
26
+ if (shadow && adopts()) import("./shadow-PVSETNMZ.js").then((m) => m.prefetch(r, priority), noop);
27
+ else for (const href of r.css) if (!document.querySelector(`link[href="${href}"]`)) addLink("preload", href, { as: "style", integrity: r.sri?.[href] ?? "", fetchPriority: priority });
28
+ }
29
+ function injectStyles(r, shadow, make, styles) {
30
+ return shadow ? import("./shadow-PVSETNMZ.js").then((m) => m.attachShadowRoot(shadow, make, r, protocol().settings().styles, styles)) : injectCss(r.css, null, r.sri).then(() => [noop]);
31
+ }
32
+ function injectCss(urls, root, sri = {}) {
33
+ const owner = root ?? document;
34
+ let seen = loadedCss.get(owner);
35
+ if (!seen) loadedCss.set(owner, seen = /* @__PURE__ */ new Map());
36
+ const parent = root ?? document.head;
37
+ const timeout = protocol().settings().timeout;
38
+ return Promise.all(
39
+ urls.map((href) => {
40
+ let p = seen.get(href);
41
+ if (!p) {
42
+ p = new Promise((resolve) => {
43
+ const link = addLink("stylesheet", href, { integrity: sri[href] ?? "" }, parent);
44
+ setTimeout(resolve, timeout);
45
+ link.onload = () => resolve();
46
+ link.onerror = () => {
47
+ link.remove();
48
+ seen.delete(href);
49
+ resolve();
50
+ };
51
+ });
52
+ seen.set(href, p);
53
+ }
54
+ return p;
55
+ })
56
+ );
57
+ }
58
+
59
+ export {
60
+ fetchCssText,
61
+ prefetchCss,
62
+ injectStyles,
63
+ injectCss
64
+ };
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  hostSlot,
3
3
  timings
4
- } from "./chunk-UTYAX6MU.js";
4
+ } from "./chunk-W6322KGP.js";
5
5
  import {
6
6
  defineRemote,
7
7
  memoSelect,
8
8
  same,
9
9
  shared
10
- } from "./chunk-NCONW6WS.js";
10
+ } from "./chunk-WD4CDGDZ.js";
11
11
  import {
12
12
  registerSrc
13
- } from "./chunk-2XF5BKV3.js";
13
+ } from "./chunk-EMSB2NVX.js";
14
14
 
15
15
  // src/element.ts
16
16
  var Base = typeof HTMLElement === "undefined" ? class {
@@ -135,8 +135,14 @@ function defineVitralElement(tag = "vitral-remote") {
135
135
  function elementRemote(tag, setup) {
136
136
  return defineRemote({
137
137
  mount(el, props, ctx) {
138
- setup?.();
139
- const node = document.createElement(tag);
138
+ const registry = ctx.customElements ?? customElements;
139
+ const name = setup?.(registry) || tag;
140
+ let node;
141
+ try {
142
+ node = document.createElement(name, { customElementRegistry: registry });
143
+ } catch {
144
+ node = document.createElement(name);
145
+ }
140
146
  node.vitral = ctx;
141
147
  Object.assign(node, props);
142
148
  el.appendChild(node);
@@ -1,17 +1,21 @@
1
1
  import {
2
2
  prefetchCss
3
- } from "./chunk-SFL6LTP3.js";
3
+ } from "./chunk-6EX5KYT5.js";
4
4
  import {
5
- RemoteError,
6
5
  absolute,
7
6
  addLink,
8
7
  fetchJson,
9
- isRemoteError,
10
8
  metric,
11
9
  pageOrigin,
12
10
  withRetry,
13
11
  withTimeout
14
- } from "./chunk-PX7PBCCT.js";
12
+ } from "./chunk-TW7KYJQ6.js";
13
+ import {
14
+ RemoteError,
15
+ fail,
16
+ isRemoteError,
17
+ report
18
+ } from "./chunk-463H6B56.js";
15
19
  import {
16
20
  protocol
17
21
  } from "./chunk-GNPFWISJ.js";
@@ -21,7 +25,8 @@ function configure(config) {
21
25
  const p = protocol();
22
26
  const { remotes, dedupe, ...rest } = config;
23
27
  p.configure(rest);
24
- if (dedupe) p.pending(import("./dedupe-IWFIXRWG.js").then((m) => m.offer(p, dedupe)).catch(() => {
28
+ if (rest.captureGlobalErrors) import("./capture-TT5WBLJ6.js").then((m) => m.capture());
29
+ if (dedupe) p.pending(import("./dedupe-S7BHQMOZ.js").then((m) => m.offer(p, dedupe)).catch(() => {
25
30
  }));
26
31
  if (typeof remotes === "string") {
27
32
  const url = absolute(remotes);
@@ -74,7 +79,7 @@ function loadRemote(name) {
74
79
  return load(name).then((r) => r.module);
75
80
  }
76
81
  function loadModule(name) {
77
- return import("./expose-53BEJB34.js").then((m) => m.resolveModule(name, (n) => loadFile(n)));
82
+ return import("./expose-OVWTPHH5.js").then((m) => m.resolveModule(name, (n) => loadFile(n))).catch(fail);
78
83
  }
79
84
  function preload(name) {
80
85
  load(name).catch(() => {
@@ -83,13 +88,13 @@ function preload(name) {
83
88
  var paths;
84
89
  function load(name, isolate, priority) {
85
90
  const file = (n) => loadFile(n, isolate, priority);
86
- if (protocol().entry(name) || !name.includes("/")) return file(name).then((r) => mountable(name, r));
87
- return import("./expose-53BEJB34.js").then((m) => m.resolveTarget(name, file));
91
+ return (protocol().entry(name) || !name.includes("/") ? file(name).then((r) => mountable(name, r)) : import("./expose-OVWTPHH5.js").then((m) => m.resolveTarget(name, file))).catch(fail);
88
92
  }
89
93
  function loadFile(name, isolate, priority) {
90
94
  const p = protocol();
91
95
  return p.load(name, async () => {
92
- paths ??= import("./sri-BVKZNX5Q.js").catch(() => null);
96
+ paths ??= import("./sri-M7ZRU57G.js").catch(() => null);
97
+ let resolved;
93
98
  try {
94
99
  await p.pending();
95
100
  const override = await devOverride(name);
@@ -97,21 +102,22 @@ function loadFile(name, isolate, priority) {
97
102
  if (!entry) throw new RemoteError("NOT_REGISTERED", name, "remote n\xE3o registrado. Use configure({ remotes }).");
98
103
  if (entry.module) return await loadLocal(name, entry);
99
104
  let t = performance.now();
100
- const resolved = await resolveEntry(name, entry, priority);
105
+ resolved = await resolveEntry(name, entry, priority);
101
106
  metric(name, "manifest", t);
102
- prefetchCss(resolved.css, (isolate ?? resolved.isolate ?? p.settings().isolate) === "shadow", resolved.sri, priority);
107
+ prefetchCss(resolved, (isolate ?? resolved.isolate ?? p.settings().isolate) === "shadow", priority);
103
108
  t = performance.now();
104
109
  const ns = await withRetry(p.settings().retries, () => importModule(name, resolved));
105
110
  metric(name, "js", t);
106
111
  return { ...resolved, module: ns?.default ?? ns, exports: ns };
107
112
  } catch (e) {
108
- throw isRemoteError(e) ? e : new RemoteError("LOAD_FAILED", name, String(e?.message ?? e), e);
113
+ throw report(isRemoteError(e) ? e : new RemoteError("LOAD_FAILED", name, String(e?.message ?? e), e), resolved);
109
114
  }
110
115
  });
111
116
  }
112
117
  function devOverride(name) {
113
118
  try {
114
- if (/vitral/.test(location.search + localStorage.getItem("vitral:overrides"))) return import("./overrides-NZAIUGK5.js").then((m) => m.overrideFor(name));
119
+ const k = "vitral:overrides";
120
+ if (location.search.includes("vitral") || localStorage[k] || sessionStorage[k]) return import("./overrides-NP754HY7.js").then((m) => m.overrideFor(name));
115
121
  } catch {
116
122
  }
117
123
  }
@@ -123,18 +129,25 @@ async function loadLocal(name, entry) {
123
129
  async function resolveEntry(name, entry, priority) {
124
130
  checkOrigin(name, entry.url);
125
131
  const m = entry.manifest ?? (new URL(entry.url).pathname.endsWith(".json") ? await fetchJson(entry.url, protocol().settings().timeout, name, { cache: "no-cache", priority }) : { name, entry: entry.url });
132
+ if (m?.stable) return resolveEntry(name, await (await import("./channel-2YPYGX3J.js")).pick(name, entry, m), priority);
126
133
  if (typeof m?.entry !== "string") throw new RemoteError("INVALID_MODULE", name, `manifesto inv\xE1lido em ${entry.url}`);
134
+ if (m.contract && (entry.contract || protocol().settings().contract)) {
135
+ const why = await (await import("./contract-46EZFQPQ.js")).checkContract(m.contract, entry.contract);
136
+ if (why) throw new RemoteError("CONTRACT_MISMATCH", name, why);
137
+ }
127
138
  const abs = (u) => absolute(u, entry.url);
128
139
  const sri = {};
129
140
  for (const file in m.files ?? {}) sri[abs(file)] = m.files[file];
130
141
  const resolved = {
131
142
  entry: abs(m.entry),
132
143
  css: [...m.css ?? [], ...entry.css ?? []].map(abs),
144
+ shadow: m.shadow,
133
145
  // A integridade declarada pelo host vence a do manifesto, e aí só o
134
146
  // arquivo único (o que ela descreve) é usado.
135
147
  integrity: entry.integrity ?? m.integrity,
136
148
  isolate: entry.isolate,
137
149
  scope: m.scope,
150
+ version: m.version,
138
151
  sri,
139
152
  priority,
140
153
  split: m.split && !entry.integrity ? {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  mountable
3
- } from "./chunk-2XF5BKV3.js";
3
+ } from "./chunk-EMSB2NVX.js";
4
4
  import {
5
5
  RemoteError
6
- } from "./chunk-PX7PBCCT.js";
6
+ } from "./chunk-463H6B56.js";
7
7
  import {
8
8
  protocol
9
9
  } from "./chunk-GNPFWISJ.js";
@@ -1,21 +1,11 @@
1
+ import {
2
+ RemoteError,
3
+ isRemoteError
4
+ } from "./chunk-463H6B56.js";
1
5
  import {
2
6
  protocol
3
7
  } from "./chunk-GNPFWISJ.js";
4
8
 
5
- // src/core/errors.ts
6
- var ERROR_DOCS = "https://joaogabriel15.github.io/vitral/erros/";
7
- var RemoteError = class extends Error {
8
- constructor(code, remote, message, cause) {
9
- super(`[vitral] ${remote}: ${message} (${ERROR_DOCS}${code})`);
10
- this.code = code;
11
- this.remote = remote;
12
- this.cause = cause;
13
- this.name = "RemoteError";
14
- this.docs = `${ERROR_DOCS}${code}`;
15
- }
16
- };
17
- var isRemoteError = (e) => e?.name === "RemoteError";
18
-
19
9
  // src/core/util.ts
20
10
  function pageOrigin() {
21
11
  return typeof location !== "undefined" ? location.origin : null;
@@ -69,15 +59,15 @@ function addLink(rel, href, props = {}, parent = document.head) {
69
59
  }
70
60
  function metric(name, stage, start) {
71
61
  try {
72
- performance.measure(`vitral:${name}:${stage}`, { start });
62
+ const label = `vitral:${name}:${stage}`;
63
+ performance.clearMeasures(label);
64
+ performance.measure(label, { start });
73
65
  protocol().settings().onMetric?.({ name, stage, start, duration: performance.now() - start });
74
66
  } catch {
75
67
  }
76
68
  }
77
69
 
78
70
  export {
79
- RemoteError,
80
- isRemoteError,
81
71
  pageOrigin,
82
72
  absolute,
83
73
  withRetry,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RemoteError
3
- } from "./chunk-PX7PBCCT.js";
3
+ } from "./chunk-463H6B56.js";
4
4
 
5
5
  // src/core/integrity.ts
6
6
  var clean = (b64) => b64.replace(/-/g, "+").replace(/_/g, "/").replace(/=/g, "");
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createSlot
3
- } from "./chunk-NCONW6WS.js";
3
+ } from "./chunk-WD4CDGDZ.js";
4
4
  import {
5
5
  preload,
6
6
  registerSrc
7
- } from "./chunk-2XF5BKV3.js";
7
+ } from "./chunk-EMSB2NVX.js";
8
8
 
9
9
  // src/core/host-slot.ts
10
10
  var noop = () => {