vitral 0.3.0 → 0.5.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 (70) hide show
  1. package/dist/angular.d.ts +2 -2
  2. package/dist/angular.js +7 -7
  3. package/dist/auto.js +7 -7
  4. package/dist/{capture-JYFERAPL.js → capture-TT5WBLJ6.js} +1 -1
  5. package/dist/channel-2YPYGX3J.js +95 -0
  6. package/dist/{chunk-AKNNHQ2H.js → chunk-463H6B56.js} +5 -0
  7. package/dist/{chunk-IHTUM6LT.js → chunk-4Z77XNBR.js} +2 -2
  8. package/dist/chunk-54CBIZES.js +105 -0
  9. package/dist/{chunk-TD4S3IHA.js → chunk-5JNV45BB.js} +10 -8
  10. package/dist/{chunk-SDB5AZEI.js → chunk-C3QOBAUE.js} +2 -2
  11. package/dist/chunk-DAESKNQ6.js +207 -0
  12. package/dist/{chunk-3YXI3G34.js → chunk-K6EG7DMO.js} +16 -7
  13. package/dist/{chunk-ZAC6QQI6.js → chunk-KU6HF2EW.js} +4 -4
  14. package/dist/{chunk-I3VSKSAZ.js → chunk-KZBH5MPD.js} +29 -27
  15. package/dist/chunk-NZEQGRBL.js +93 -0
  16. package/dist/chunk-PY7P5BF4.js +404 -0
  17. package/dist/{chunk-GNHCZRQP.js → chunk-TW7KYJQ6.js} +1 -1
  18. package/dist/{chunk-AH7KNMBW.js → chunk-UYOPJ4XQ.js} +1 -1
  19. package/dist/cli.js +1522 -37
  20. package/dist/devtools.d.ts +32 -2
  21. package/dist/devtools.js +27 -12
  22. package/dist/dict.d.ts +69 -0
  23. package/dist/dict.js +8 -0
  24. package/dist/edge.d.ts +118 -0
  25. package/dist/edge.js +398 -0
  26. package/dist/element.d.ts +12 -3
  27. package/dist/element.js +7 -7
  28. package/dist/embed.js +2 -0
  29. package/dist/{events-D5gs7rff.d.ts → events-0rxFlWJJ.d.ts} +1 -1
  30. package/dist/expose-IAKYHJXF.js +15 -0
  31. package/dist/federation.d.ts +89 -0
  32. package/dist/federation.js +101 -0
  33. package/dist/hydrate-YVZDJ2V7.js +168 -0
  34. package/dist/iframe.js +7 -7
  35. package/dist/index.d.ts +4 -4
  36. package/dist/index.js +5 -5
  37. package/dist/otel.d.ts +29 -1
  38. package/dist/otel.js +13 -1
  39. package/dist/overrides-NP754HY7.js +27 -0
  40. package/dist/preact.d.ts +4 -4
  41. package/dist/preact.js +6 -6
  42. package/dist/prefetch.d.ts +25 -0
  43. package/dist/prefetch.js +178 -0
  44. package/dist/react.d.ts +3 -3
  45. package/dist/react.js +6 -6
  46. package/dist/reframe-LQL4DZYP.js +251 -0
  47. package/dist/routes.d.ts +2 -2
  48. package/dist/routes.js +5 -5
  49. package/dist/{shadow-6HELCHCJ.js → shadow-S4SKHTA7.js} +66 -5
  50. package/dist/single-spa.d.ts +40 -0
  51. package/dist/single-spa.js +52 -0
  52. package/dist/{slot-DqXTwGbs.d.ts → slot-D49L1rdU.d.ts} +1 -1
  53. package/dist/solid.d.ts +3 -3
  54. package/dist/solid.js +6 -6
  55. package/dist/{sri-JMX6JLQP.js → sri-576GTDIA.js} +41 -10
  56. package/dist/svelte.d.ts +4 -4
  57. package/dist/svelte.js +6 -6
  58. package/dist/testing.d.ts +171 -3
  59. package/dist/testing.js +193 -6
  60. package/dist/{types-Czvm-siZ.d.ts → types-DUtcF3HO.d.ts} +124 -5
  61. package/dist/vitals.d.ts +29 -0
  62. package/dist/vitals.js +152 -0
  63. package/dist/vite.d.ts +18 -0
  64. package/dist/vite.js +329 -417
  65. package/dist/vue.d.ts +3 -3
  66. package/dist/vue.js +6 -6
  67. package/package.json +170 -21
  68. package/dist/chunk-DXORSF4X.js +0 -42
  69. package/dist/expose-JUOUN5N5.js +0 -15
  70. package/dist/overrides-NZAIUGK5.js +0 -15
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ReactNode, ComponentType } from 'react';
2
2
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
3
3
  import * as JSXRuntime from 'react/jsx-runtime';
4
- import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared, R as RemoteContext } from './types-Czvm-siZ.js';
5
- export { E as EventBus } from './types-Czvm-siZ.js';
6
- export { e as events } from './events-D5gs7rff.js';
4
+ import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared, R as RemoteContext } from './types-DUtcF3HO.js';
5
+ export { E as EventBus } from './types-DUtcF3HO.js';
6
+ export { e as events } from './events-0rxFlWJJ.js';
7
7
  import './errors-kjBv6IH_.js';
8
8
 
9
9
  /**
package/dist/react.js CHANGED
@@ -1,18 +1,18 @@
1
1
  "use client";
2
2
  import {
3
3
  hostSlot
4
- } from "./chunk-IHTUM6LT.js";
4
+ } from "./chunk-4Z77XNBR.js";
5
5
  import {
6
6
  defineRemote,
7
7
  events,
8
8
  memoSelect,
9
9
  same,
10
10
  shared
11
- } from "./chunk-I3VSKSAZ.js";
12
- import "./chunk-TD4S3IHA.js";
13
- import "./chunk-ZAC6QQI6.js";
14
- import "./chunk-GNHCZRQP.js";
15
- import "./chunk-AKNNHQ2H.js";
11
+ } from "./chunk-KZBH5MPD.js";
12
+ import "./chunk-5JNV45BB.js";
13
+ import "./chunk-KU6HF2EW.js";
14
+ import "./chunk-TW7KYJQ6.js";
15
+ import "./chunk-463H6B56.js";
16
16
  import {
17
17
  protocol
18
18
  } from "./chunk-GNPFWISJ.js";
@@ -0,0 +1,251 @@
1
+ import {
2
+ splitName
3
+ } from "./chunk-C3QOBAUE.js";
4
+ import {
5
+ verifyIntegrity
6
+ } from "./chunk-UYOPJ4XQ.js";
7
+ import {
8
+ resolveEntry
9
+ } from "./chunk-5JNV45BB.js";
10
+ import {
11
+ prefetchCss
12
+ } from "./chunk-KU6HF2EW.js";
13
+ import {
14
+ fetchBytes,
15
+ metric,
16
+ withRetry,
17
+ withTimeout
18
+ } from "./chunk-TW7KYJQ6.js";
19
+ import {
20
+ RemoteError,
21
+ isRemoteError,
22
+ report
23
+ } from "./chunk-463H6B56.js";
24
+ import {
25
+ protocol
26
+ } from "./chunk-GNPFWISJ.js";
27
+
28
+ // src/core/reframe.ts
29
+ var REFRAME_SCRIPT = "window.__vitral=function(u){return import(u)}";
30
+ var OWN = /^(popstate|hashchange|message|messageerror|error|unhandledrejection|rejectionhandled)$/;
31
+ var VIEW = ["innerWidth", "innerHeight", "outerWidth", "outerHeight", "devicePixelRatio", "scrollX", "scrollY", "pageXOffset", "pageYOffset", "screenX", "screenY", "visualViewport"];
32
+ var VIEW_FNS = ["matchMedia", "scrollTo", "scroll", "scrollBy", "getComputedStyle", "getSelection"];
33
+ var DOC_FNS = ["createElementNS", "createTextNode", "createComment", "createDocumentFragment", "createEvent", "createRange", "createTreeWalker", "createNodeIterator", "createAttribute", "importNode", "adoptNode", "getSelection"];
34
+ var set = (o, values) => {
35
+ for (const k in values) Object.defineProperty(o, k, { configurable: true, writable: true, value: values[k] });
36
+ };
37
+ var get = (o, getters) => {
38
+ for (const k in getters) Object.defineProperty(o, k, { configurable: true, get: getters[k] });
39
+ };
40
+ async function load(name, _isolate, priority) {
41
+ const p = protocol();
42
+ const { timeout, retries } = p.settings();
43
+ const [remote, key] = splitName(name);
44
+ let resolved;
45
+ let realm;
46
+ try {
47
+ const entry = p.entry(remote);
48
+ if (!entry) throw new RemoteError("NOT_REGISTERED", name, "remote n\xE3o registrado. Use configure({ remotes }).");
49
+ if (!entry.url) throw new RemoteError("MOUNT_FAILED", name, "remote local (module) n\xE3o roda com isolate: 'reframe': registre a URL dele");
50
+ let t = performance.now();
51
+ const { integrity, ...r } = await resolveEntry(remote, entry, priority);
52
+ delete r.split;
53
+ resolved = r;
54
+ metric(name, "manifest", t);
55
+ prefetchCss(r, true, priority);
56
+ t = performance.now();
57
+ const bytes = integrity && await withRetry(retries, async () => {
58
+ const b = await fetchBytes(r.entry, timeout, name, { priority });
59
+ await verifyIntegrity(name, b, integrity);
60
+ return b;
61
+ });
62
+ const url = bytes ? URL.createObjectURL(new Blob([bytes], { type: "text/javascript" })) : r.entry;
63
+ const { registryFor } = await import("./shadow-S4SKHTA7.js");
64
+ realm = createRealm(r.name ?? name, registryFor(r.name ?? name));
65
+ let ns;
66
+ try {
67
+ ns = await withTimeout(timeout, name, realm.load(url));
68
+ } catch (e) {
69
+ throw isRemoteError(e) ? e : new RemoteError("LOAD_FAILED", name, `falha ao importar ${r.entry}`, e);
70
+ } finally {
71
+ if (bytes) URL.revokeObjectURL(url);
72
+ }
73
+ if (key) {
74
+ const part = ns?.exposes?.[key];
75
+ if (!part) throw new RemoteError("NOT_EXPOSED", name, `${remote} n\xE3o exp\xF5e ${key}`);
76
+ ns = typeof part === "function" ? await part() : part;
77
+ }
78
+ const mod = ns?.default ?? ns;
79
+ if (typeof mod?.mount != "function") throw new RemoteError("INVALID_MODULE", name, "o m\xF3dulo n\xE3o exporta mount()");
80
+ metric(name, "js", t);
81
+ const own = realm;
82
+ return { ...r, module: { mount: (el, props, ctx) => own.mount(mod, el, props, ctx) } };
83
+ } catch (e) {
84
+ realm?.dispose();
85
+ throw report(isRemoteError(e) ? e : new RemoteError("LOAD_FAILED", name, String(e?.message ?? e), e), resolved);
86
+ }
87
+ }
88
+ function noFrames(_target, name) {
89
+ return Promise.reject(new RemoteError("MOUNT_FAILED", name, 'isolate="iframe" precisa de enableIframe(), de vitral/iframe'));
90
+ }
91
+ function createRealm(name, registry) {
92
+ const host = document;
93
+ const frame = host.createElement("iframe");
94
+ frame.setAttribute("data-vitral-reframe", name);
95
+ frame.setAttribute("aria-hidden", "true");
96
+ frame.tabIndex = -1;
97
+ frame.style.display = "none";
98
+ host.body.appendChild(frame);
99
+ const w = frame.contentWindow;
100
+ const d = w.document;
101
+ d.open();
102
+ d.close();
103
+ const realHead = d.head;
104
+ const inFrame = d.createElement.bind(d);
105
+ const script = d.createElement("script");
106
+ script.nonce = host.querySelector("script[nonce]")?.nonce ?? "";
107
+ script.textContent = REFRAME_SCRIPT;
108
+ realHead.appendChild(script);
109
+ const load2 = w.__vitral;
110
+ delete w.__vitral;
111
+ const head = host.createElement("div");
112
+ head.setAttribute("data-vitral-head", "");
113
+ head.hidden = true;
114
+ let root = null;
115
+ let body = head;
116
+ let ctx = null;
117
+ const scope = () => root ?? head;
118
+ const ctrl = new AbortController();
119
+ const listen = (target, own) => {
120
+ const add = own?.addEventListener;
121
+ const remove = own?.removeEventListener;
122
+ return {
123
+ addEventListener(type, fn, o) {
124
+ if (own && OWN.test(type)) return add.call(own, type, fn, o);
125
+ const opts = typeof o == "object" ? o : { capture: !!o };
126
+ const signal = opts.signal && AbortSignal.any ? AbortSignal.any([opts.signal, ctrl.signal]) : ctrl.signal;
127
+ target.addEventListener(type, fn, { ...opts, signal });
128
+ },
129
+ removeEventListener(type, fn, o) {
130
+ if (own && OWN.test(type)) return remove.call(own, type, fn, o);
131
+ target.removeEventListener(type, fn, o);
132
+ }
133
+ };
134
+ };
135
+ const scoped = Object.getPrototypeOf(registry) !== customElements;
136
+ const createElement = (tag, o) => {
137
+ if (/^script$/i.test(tag)) return inFrame(tag);
138
+ if (scoped && !o?.customElementRegistry)
139
+ try {
140
+ return host.createElement(tag, { ...o, customElementRegistry: registry });
141
+ } catch {
142
+ }
143
+ return host.createElement(tag, o);
144
+ };
145
+ const fromHost = {};
146
+ for (const k of DOC_FNS) fromHost[k] = host[k].bind(host);
147
+ set(d, {
148
+ ...fromHost,
149
+ ...listen(host, null),
150
+ createElement,
151
+ querySelector: (s) => scope().querySelector(s),
152
+ querySelectorAll: (s) => scope().querySelectorAll(s),
153
+ getElementById: (id) => scope().querySelector(`#${CSS.escape(id)}`),
154
+ getElementsByClassName: (c) => scope().querySelectorAll(c.trim().split(/\s+/).map((x) => "." + CSS.escape(x)).join("")),
155
+ getElementsByTagName: (t) => scope().querySelectorAll(t),
156
+ getElementsByName: (n) => scope().querySelectorAll(`[name="${CSS.escape(n)}"]`),
157
+ elementFromPoint: (x, y) => (root ?? host).elementFromPoint(x, y),
158
+ elementsFromPoint: (x, y) => (root ?? host).elementsFromPoint(x, y)
159
+ });
160
+ get(d, {
161
+ head: () => head,
162
+ body: () => body,
163
+ documentElement: () => host.documentElement,
164
+ activeElement: () => root?.activeElement ?? host.body
165
+ });
166
+ const redirect = (el) => {
167
+ const append = el.appendChild;
168
+ const before = el.insertBefore;
169
+ set(el, {
170
+ appendChild: (n) => n.nodeName == "SCRIPT" ? realHead.appendChild(n) : append.call(el, n),
171
+ insertBefore: (n, ref) => n.nodeName == "SCRIPT" ? realHead.appendChild(n) : before.call(el, n, ref)
172
+ });
173
+ };
174
+ redirect(head);
175
+ const view = {};
176
+ for (const k of VIEW) view[k] = () => window[k];
177
+ get(w, view);
178
+ const viewFns = {};
179
+ for (const k of VIEW_FNS) viewFns[k] = window[k].bind(window);
180
+ set(w, { ...viewFns, ...listen(window, w), HTMLElement, customElements: registry });
181
+ w.addEventListener("error", (e) => ctx?.reportError(e.error ?? e.message));
182
+ w.addEventListener("unhandledrejection", (e) => ctx?.reportError(e.reason));
183
+ const h = w.history;
184
+ const push = h.pushState;
185
+ const replace = h.replaceState;
186
+ const go = (fn, method) => (state, title, url) => {
187
+ fn.call(h, state, title, url);
188
+ const href = w.location.href;
189
+ if (href === location.href) return;
190
+ history[method](state, "", href);
191
+ dispatchEvent(new PopStateEvent("popstate", { state }));
192
+ protocol().events.emit("vitral:navigate", location.pathname + location.search + location.hash);
193
+ };
194
+ set(h, { pushState: go(push, "pushState"), replaceState: go(replace, "replaceState") });
195
+ const pull = () => {
196
+ const old = w.location.href;
197
+ if (old === location.href) return;
198
+ try {
199
+ replace.call(h, history.state, "", location.href);
200
+ } catch {
201
+ return;
202
+ }
203
+ w.dispatchEvent(new w.PopStateEvent("popstate", { state: history.state }));
204
+ if (old.split("#")[1] !== location.href.split("#")[1]) w.dispatchEvent(new w.HashChangeEvent("hashchange", { oldURL: old, newURL: location.href }));
205
+ };
206
+ addEventListener("popstate", pull, { signal: ctrl.signal });
207
+ globalThis.navigation?.addEventListener("currententrychange", pull, { signal: ctrl.signal });
208
+ const dispose = () => {
209
+ ctx = null;
210
+ ctrl.abort();
211
+ head.remove();
212
+ frame.remove();
213
+ };
214
+ return {
215
+ load: (url) => {
216
+ if (!load2) throw new RemoteError("LOAD_FAILED", name, "a CSP bloqueou o script do iframe do isolate: 'reframe' (libere o hash de REFRAME_SCRIPT ou use nonce)");
217
+ return load2(url);
218
+ },
219
+ async mount(mod, el, props, c) {
220
+ ctx = c;
221
+ root = c.shadowRoot;
222
+ if (root) root.prepend(head);
223
+ body = c.portalContainer ?? el;
224
+ if (body !== head) redirect(body);
225
+ pull();
226
+ let handle;
227
+ try {
228
+ handle = await mod.mount(el, props, c);
229
+ } catch (e) {
230
+ dispose();
231
+ throw e;
232
+ }
233
+ return {
234
+ update: (next) => handle.update?.(next),
235
+ unmount() {
236
+ try {
237
+ handle.unmount();
238
+ } finally {
239
+ dispose();
240
+ }
241
+ }
242
+ };
243
+ },
244
+ dispose
245
+ };
246
+ }
247
+ export {
248
+ REFRAME_SCRIPT,
249
+ load,
250
+ noFrames
251
+ };
package/dist/routes.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as Props } from './types-Czvm-siZ.js';
2
- import { S as SlotStatus } from './slot-DqXTwGbs.js';
1
+ import { P as Props } from './types-DUtcF3HO.js';
2
+ import { S as SlotStatus } from './slot-D49L1rdU.js';
3
3
  import './errors-kjBv6IH_.js';
4
4
 
5
5
  /** Padrão de URL → nome do remote. A primeira rota que bate vence. */
package/dist/routes.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createSlot,
3
3
  navigate
4
- } from "./chunk-I3VSKSAZ.js";
5
- import "./chunk-TD4S3IHA.js";
6
- import "./chunk-ZAC6QQI6.js";
7
- import "./chunk-GNHCZRQP.js";
8
- import "./chunk-AKNNHQ2H.js";
4
+ } from "./chunk-KZBH5MPD.js";
5
+ import "./chunk-5JNV45BB.js";
6
+ import "./chunk-KU6HF2EW.js";
7
+ import "./chunk-TW7KYJQ6.js";
8
+ import "./chunk-463H6B56.js";
9
9
  import "./chunk-GNPFWISJ.js";
10
10
 
11
11
  // src/routes.ts
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  fetchCssText,
3
3
  injectCss
4
- } from "./chunk-ZAC6QQI6.js";
5
- import "./chunk-GNHCZRQP.js";
6
- import "./chunk-AKNNHQ2H.js";
4
+ } from "./chunk-KU6HF2EW.js";
5
+ import "./chunk-TW7KYJQ6.js";
6
+ import "./chunk-463H6B56.js";
7
7
  import "./chunk-GNPFWISJ.js";
8
8
 
9
9
  // src/core/shadow.ts
@@ -23,6 +23,66 @@ function prefetch(r, priority) {
23
23
  for (const u of urls) fetchCssText(u, r.sri?.[u], priority).catch(noop);
24
24
  injectCss(global, null, r.sri);
25
25
  }
26
+ async function attachShadowRoot(target, make, r, global = {}, local = {}) {
27
+ const name = make().getAttribute("data-vitral-root");
28
+ let registry = registryFor(name);
29
+ let root = target.shadowRoot;
30
+ if (!root && !fake(registry))
31
+ try {
32
+ root = target.attachShadow({ mode: "open", customElementRegistry: registry });
33
+ } catch {
34
+ broken = true;
35
+ registries.delete(name);
36
+ registry = registryFor(name);
37
+ }
38
+ root ??= target.attachShadow({ mode: "open" });
39
+ const own = root.customElementRegistry ?? registry;
40
+ let el = make();
41
+ if (!fake(own))
42
+ try {
43
+ el = make({ customElementRegistry: own });
44
+ } catch {
45
+ }
46
+ if (!el.isConnected) root.appendChild(el);
47
+ return [...await attachStyles(root, el, r, global, local), root, own, el];
48
+ }
49
+ var registries = /* @__PURE__ */ new Map();
50
+ var broken = false;
51
+ var fake = (registry) => Object.getPrototypeOf(registry) === customElements;
52
+ var owners = /* @__PURE__ */ new Map();
53
+ function registryFor(name) {
54
+ let registry = registries.get(name);
55
+ if (registry) return registry;
56
+ let real = customElements;
57
+ if (!broken && "initialize" in CustomElementRegistry.prototype)
58
+ try {
59
+ real = new CustomElementRegistry();
60
+ } catch {
61
+ broken = true;
62
+ }
63
+ const shared = real === customElements;
64
+ const own = registry = shared ? Object.create(real) : real;
65
+ if (shared) {
66
+ for (const k of ["get", "getName", "upgrade", "whenDefined"]) if (k in real) own[k] = real[k].bind(real);
67
+ }
68
+ const define = real.define;
69
+ own.define = (tag, ctor, options) => {
70
+ const had = real.get(tag);
71
+ const owner = owners.get(tag);
72
+ if (!had) return shared && owners.set(tag, name), define.call(real, tag, ctor, options);
73
+ if (shared && had !== ctor && owner !== name && dev())
74
+ console.warn(`[vitral] ${name}: <${tag}> j\xE1 foi definido por ${owner ?? "outro c\xF3digo"}; fica essa defini\xE7\xE3o. Sem Scoped Custom Element Registries, os remotes dividem o registro global.`);
75
+ };
76
+ registries.set(name, registry);
77
+ return registry;
78
+ }
79
+ function dev() {
80
+ try {
81
+ return process.env.NODE_ENV !== "production";
82
+ } catch {
83
+ return false;
84
+ }
85
+ }
26
86
  async function attachStyles(root, el, r, global = {}, local = {}) {
27
87
  const sri = r.sri ?? {};
28
88
  const [css, ready, up] = plan(r);
@@ -93,6 +153,7 @@ function mirrorTheme(el) {
93
153
  return () => observer.disconnect();
94
154
  }
95
155
  export {
96
- attachStyles,
97
- prefetch
156
+ attachShadowRoot,
157
+ prefetch,
158
+ registryFor
98
159
  };
@@ -0,0 +1,40 @@
1
+ import { P as Props, a as RemoteModule } from './types-DUtcF3HO.js';
2
+ import './errors-kjBv6IH_.js';
3
+
4
+ /**
5
+ * App do single-spa como remote do vitral, sem reescrever o app:
6
+ *
7
+ * // src/vitral-remote.js
8
+ * import { singleSpaRemote } from 'vitral/single-spa'
9
+ * import * as lifecycles from './main' // exporta bootstrap, mount e unmount
10
+ *
11
+ * export default singleSpaRemote(lifecycles)
12
+ *
13
+ * Funciona com os lifecycles de `single-spa-react`, `single-spa-vue`,
14
+ * `single-spa-angular` etc. e com lifecycles escritos à mão. Os lifecycles
15
+ * recebem as props do host mais `name` e `domElement` (o elemento do remote).
16
+ */
17
+
18
+ /** Um lifecycle do single-spa: uma função ou uma lista delas, em sequência. */
19
+ type SingleSpaLifecycle = ((props: any) => unknown) | ((props: any) => unknown)[];
20
+ /** O que um app ou parcel do single-spa exporta. */
21
+ interface SingleSpaLifecycles {
22
+ bootstrap?: SingleSpaLifecycle;
23
+ mount: SingleSpaLifecycle;
24
+ unmount: SingleSpaLifecycle;
25
+ update?: SingleSpaLifecycle;
26
+ }
27
+ /**
28
+ * Embrulha os lifecycles de um app do single-spa no contrato `mount`.
29
+ *
30
+ * - `bootstrap` roda uma vez, antes do primeiro `mount`.
31
+ * - Os lifecycles nunca se sobrepõem: um `mount` espera o `unmount` anterior.
32
+ * - `update(props)` chama o `update` do app (parcels); sem ele, o app é
33
+ * desmontado e montado de novo com as props novas.
34
+ * - Duas instâncias ao mesmo tempo recebem `name` diferentes (`conta`, `conta-2`).
35
+ */
36
+ declare function singleSpaRemote<P extends Props = Props>(lifecycles: SingleSpaLifecycles | {
37
+ default: SingleSpaLifecycles;
38
+ }): RemoteModule<P>;
39
+
40
+ export { type SingleSpaLifecycle, type SingleSpaLifecycles, singleSpaRemote };
@@ -0,0 +1,52 @@
1
+ // src/single-spa.ts
2
+ async function run(fns, props) {
3
+ for (const fn of [fns ?? []].flat()) await fn(props);
4
+ }
5
+ function singleSpaRemote(lifecycles) {
6
+ const l = "mount" in lifecycles ? lifecycles : lifecycles.default;
7
+ if (typeof l?.mount == "undefined" || typeof l.unmount == "undefined") throw new Error("[vitral] singleSpaRemote: faltam os lifecycles mount e unmount");
8
+ let booted;
9
+ let queue = Promise.resolve();
10
+ const used = /* @__PURE__ */ new Set();
11
+ const step = (fn) => queue = queue.then(fn, fn);
12
+ const boot = (props) => booted ??= run(l.bootstrap, props).catch((e) => {
13
+ booted = void 0;
14
+ throw e;
15
+ });
16
+ return {
17
+ async mount(el, props, ctx) {
18
+ let name = ctx.name;
19
+ for (let i = 2; used.has(name); i++) name = `${ctx.name}-${i}`;
20
+ used.add(name);
21
+ let current = { ...props, name, domElement: el };
22
+ try {
23
+ await step(async () => {
24
+ await boot(current);
25
+ await run(l.mount, current);
26
+ });
27
+ } catch (e) {
28
+ used.delete(name);
29
+ throw e;
30
+ }
31
+ const report = (e) => ctx.reportError(e);
32
+ return {
33
+ update(next) {
34
+ const before = current;
35
+ current = { ...next, name, domElement: el };
36
+ const job = l.update ? step(() => run(l.update, current)) : step(async () => {
37
+ await run(l.unmount, before);
38
+ await run(l.mount, current);
39
+ });
40
+ job.catch(report);
41
+ },
42
+ unmount() {
43
+ used.delete(name);
44
+ step(() => run(l.unmount, current)).catch(report);
45
+ }
46
+ };
47
+ }
48
+ };
49
+ }
50
+ export {
51
+ singleSpaRemote
52
+ };
@@ -1,5 +1,5 @@
1
1
  import { R as RemoteError } from './errors-kjBv6IH_.js';
2
- import { P as Props, I as Isolation, b as StyleOptions } from './types-Czvm-siZ.js';
2
+ import { P as Props, I as Isolation, d as StyleOptions } from './types-DUtcF3HO.js';
3
3
 
4
4
  type SlotStatus = 'loading' | 'ready' | 'error';
5
5
  interface SlotOptions<P extends Props = Props> {
package/dist/solid.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JSX, Component, Accessor } from 'solid-js';
2
- import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared } from './types-Czvm-siZ.js';
3
- export { R as RemoteContext } from './types-Czvm-siZ.js';
2
+ import { P as Props, I as Isolation, C as CheckedProps, a as RemoteModule, S as Shared } from './types-DUtcF3HO.js';
3
+ export { R as RemoteContext } from './types-DUtcF3HO.js';
4
4
  import { R as RemoteError } from './errors-kjBv6IH_.js';
5
- export { e as events } from './events-D5gs7rff.js';
5
+ export { e as events } from './events-0rxFlWJJ.js';
6
6
  export { n as navigate } from './navigate-BRG1WJUM.js';
7
7
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
8
8
 
package/dist/solid.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  hostSlot
3
- } from "./chunk-IHTUM6LT.js";
3
+ } from "./chunk-4Z77XNBR.js";
4
4
  import {
5
5
  defineRemote,
6
6
  events,
@@ -8,11 +8,11 @@ import {
8
8
  navigate,
9
9
  same,
10
10
  shared
11
- } from "./chunk-I3VSKSAZ.js";
12
- import "./chunk-TD4S3IHA.js";
13
- import "./chunk-ZAC6QQI6.js";
14
- import "./chunk-GNHCZRQP.js";
15
- import "./chunk-AKNNHQ2H.js";
11
+ } from "./chunk-KZBH5MPD.js";
12
+ import "./chunk-5JNV45BB.js";
13
+ import "./chunk-KU6HF2EW.js";
14
+ import "./chunk-TW7KYJQ6.js";
15
+ import "./chunk-463H6B56.js";
16
16
  import "./chunk-GNPFWISJ.js";
17
17
 
18
18
  // src/solid.ts
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  verifyIntegrity
3
- } from "./chunk-AH7KNMBW.js";
3
+ } from "./chunk-UYOPJ4XQ.js";
4
4
  import {
5
5
  addLink,
6
6
  fetchBytes,
7
7
  withTimeout
8
- } from "./chunk-GNHCZRQP.js";
8
+ } from "./chunk-TW7KYJQ6.js";
9
9
  import {
10
10
  RemoteError
11
- } from "./chunk-AKNNHQ2H.js";
11
+ } from "./chunk-463H6B56.js";
12
12
  import "./chunk-GNPFWISJ.js";
13
13
 
14
14
  // src/core/sri.ts
@@ -41,7 +41,25 @@ var STRICT = /^(sha(256|384|512)-[A-Za-z0-9+/]+={0,2}( +|$))+$/;
41
41
  var PROBE = "data:text/javascript,export{}";
42
42
  var PROBE_SRI = "sha256-d3bjIZdvLjBurwdLwkSVOnEBPFFly+T1SR9r3VVHBGg=";
43
43
  var maps;
44
+ var mapped = /* @__PURE__ */ new Set();
45
+ var probing;
44
46
  var preloads;
47
+ var KEY = "vitral:sri-map";
48
+ async function useMap(sri) {
49
+ if (probing) return await probing && addMap(sri, false);
50
+ let seen = false;
51
+ try {
52
+ seen = localStorage[KEY] === navigator.userAgent;
53
+ } catch {
54
+ }
55
+ const ok = await (probing = addMap(sri, !seen));
56
+ if (ok && !seen)
57
+ try {
58
+ localStorage[KEY] = navigator.userAgent;
59
+ } catch {
60
+ }
61
+ return ok;
62
+ }
45
63
  var tick = () => new Promise((resolve) => {
46
64
  const c = new MessageChannel();
47
65
  c.port1.onmessage = () => resolve();
@@ -65,7 +83,7 @@ async function verified(build, run) {
65
83
  }
66
84
  });
67
85
  };
68
- if (maps !== false && (maps = await addMap(sri))) {
86
+ if (maps !== false && (maps = await useMap(sri))) {
69
87
  await share();
70
88
  for (const u of chunks) fetch(u, { priority }).catch(() => {
71
89
  });
@@ -78,7 +96,12 @@ async function verified(build, run) {
78
96
  return entry;
79
97
  }
80
98
  }
81
- async function addMap(integrity) {
99
+ async function addMap(sri, probe) {
100
+ if (!HTMLScriptElement.supports?.("importmap")) return false;
101
+ const integrity = {};
102
+ for (const u in sri) if (!/\.css([?#]|$)/.test(u) && !mapped.has(u)) mapped.add(u), integrity[u] = sri[u];
103
+ const urls = probe ? ["export{}", "export{}//"].map((c) => URL.createObjectURL(new Blob([c], { type: "text/javascript" }))) : [];
104
+ for (const u of urls) integrity[u] = PROBE_SRI;
82
105
  let ok = true;
83
106
  try {
84
107
  const s = document.createElement("script");
@@ -88,11 +111,17 @@ async function addMap(integrity) {
88
111
  s.addEventListener("securitypolicyviolation", () => ok = false);
89
112
  s.textContent = JSON.stringify({ integrity });
90
113
  document.head.append(s);
114
+ await tick();
115
+ await tick();
116
+ if (ok && probe) ok = await check((u) => import(
117
+ /* @vite-ignore */
118
+ /* webpackIgnore: true */
119
+ u
120
+ ), urls[0], urls[1]);
91
121
  } catch {
92
- return false;
122
+ ok = false;
93
123
  }
94
- await tick();
95
- await tick();
124
+ for (const u of urls) URL.revokeObjectURL(u);
96
125
  return ok;
97
126
  }
98
127
  function preload(href, integrity, fetchPriority = "auto") {
@@ -104,9 +133,11 @@ function preload(href, integrity, fetchPriority = "auto") {
104
133
  }
105
134
  function checkPreloads() {
106
135
  if (!document.createElement("link").relList.supports("modulepreload")) return Promise.resolve(false);
107
- const run = (href, good) => preload(href, PROBE_SRI).then(() => good, () => !good);
136
+ return check((href) => preload(href, PROBE_SRI), PROBE, PROBE + "//");
137
+ }
138
+ function check(load, good, bad) {
108
139
  return Promise.race([
109
- Promise.all([run(PROBE, true), run(PROBE + "//", false)]).then(([a, b]) => a && b),
140
+ Promise.all([load(good).then(() => true, () => false), load(bad).then(() => false, () => true)]).then(([a, b]) => a && b),
110
141
  new Promise((resolve) => setTimeout(resolve, 3e3, false))
111
142
  ]);
112
143
  }
package/dist/svelte.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Component } from 'svelte';
2
- import { P as Props, I as Isolation, a as RemoteModule } from './types-Czvm-siZ.js';
3
- export { R as RemoteContext } from './types-Czvm-siZ.js';
2
+ import { P as Props, I as Isolation, a as RemoteModule } from './types-DUtcF3HO.js';
3
+ export { R as RemoteContext } from './types-DUtcF3HO.js';
4
4
  import { R as RemoteError } from './errors-kjBv6IH_.js';
5
- import { S as SlotStatus } from './slot-DqXTwGbs.js';
6
- export { e as events } from './events-D5gs7rff.js';
5
+ import { S as SlotStatus } from './slot-D49L1rdU.js';
6
+ export { e as events } from './events-0rxFlWJJ.js';
7
7
  export { n as navigate } from './navigate-BRG1WJUM.js';
8
8
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
9
9