vitral 0.1.0 → 0.3.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 (63) hide show
  1. package/README.md +250 -217
  2. package/dist/angular.d.ts +16 -4
  3. package/dist/angular.js +26 -5
  4. package/dist/auto.d.ts +2 -0
  5. package/dist/auto.js +13 -0
  6. package/dist/capture-JYFERAPL.js +42 -0
  7. package/dist/chunk-3YXI3G34.js +181 -0
  8. package/dist/chunk-AH7KNMBW.js +20 -0
  9. package/dist/chunk-AKNNHQ2H.js +45 -0
  10. package/dist/chunk-DXORSF4X.js +42 -0
  11. package/dist/chunk-GNHCZRQP.js +79 -0
  12. package/dist/chunk-GNPFWISJ.js +80 -0
  13. package/dist/chunk-I3VSKSAZ.js +634 -0
  14. package/dist/chunk-IHTUM6LT.js +152 -0
  15. package/dist/chunk-SDB5AZEI.js +51 -0
  16. package/dist/chunk-TD4S3IHA.js +201 -0
  17. package/dist/chunk-ZAC6QQI6.js +64 -0
  18. package/dist/cli.d.ts +1 -0
  19. package/dist/cli.js +138 -0
  20. package/dist/contract-46EZFQPQ.js +17 -0
  21. package/dist/dedupe-S7BHQMOZ.js +82 -0
  22. package/dist/devtools.d.ts +12 -0
  23. package/dist/devtools.js +86 -0
  24. package/dist/element.d.ts +60 -2
  25. package/dist/element.js +10 -2
  26. package/dist/errors-kjBv6IH_.d.ts +17 -0
  27. package/dist/events-D5gs7rff.d.ts +6 -0
  28. package/dist/expose-JUOUN5N5.js +15 -0
  29. package/dist/host-slot-Cz6EiGsB.d.ts +6 -0
  30. package/dist/iframe.d.ts +28 -0
  31. package/dist/iframe.js +239 -0
  32. package/dist/index.d.ts +144 -147
  33. package/dist/index.js +40 -10
  34. package/dist/navigate-BRG1WJUM.d.ts +9 -0
  35. package/dist/otel.d.ts +44 -0
  36. package/dist/otel.js +27 -0
  37. package/dist/overrides-NZAIUGK5.js +15 -0
  38. package/dist/preact.d.ts +30 -7
  39. package/dist/preact.js +38 -9
  40. package/dist/react.d.ts +46 -7
  41. package/dist/react.js +97 -42
  42. package/dist/routes.d.ts +56 -0
  43. package/dist/routes.js +144 -0
  44. package/dist/sentry.d.ts +25 -0
  45. package/dist/sentry.js +11 -0
  46. package/dist/shadow-6HELCHCJ.js +98 -0
  47. package/dist/slot-DqXTwGbs.d.ts +36 -0
  48. package/dist/solid.d.ts +29 -6
  49. package/dist/solid.js +32 -8
  50. package/dist/sri-JMX6JLQP.js +116 -0
  51. package/dist/state-BDdCwc21.d.ts +4 -0
  52. package/dist/svelte.d.ts +19 -3
  53. package/dist/svelte.js +11 -4
  54. package/dist/testing.d.ts +3 -2
  55. package/dist/testing.js +9 -3
  56. package/dist/types-Czvm-siZ.d.ts +327 -0
  57. package/dist/vite.d.ts +66 -4
  58. package/dist/vite.js +1044 -25
  59. package/dist/vue.d.ts +86 -7
  60. package/dist/vue.js +74 -46
  61. package/package.json +181 -11
  62. package/dist/chunk-IZK6ITIJ.js +0 -96
  63. package/dist/chunk-TTL52BF2.js +0 -547
package/dist/solid.d.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { JSX, Component } from 'solid-js';
2
- import { Props, Isolation, RemoteError, RemoteModule } from './index.js';
3
- export { RemoteContext, events, navigate } from './index.js';
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';
4
+ import { R as RemoteError } from './errors-kjBv6IH_.js';
5
+ export { e as events } from './events-D5gs7rff.js';
6
+ export { n as navigate } from './navigate-BRG1WJUM.js';
7
+ import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
4
8
 
5
9
  /**
6
10
  * Adaptador Solid (e SolidStart).
@@ -12,13 +16,32 @@ export { RemoteContext, events, navigate } from './index.js';
12
16
  /** Transforma um componente Solid em um remote. O contexto chega na prop `vitral`. */
13
17
  declare function solidRemote<P extends Props>(Comp: Component<any>): RemoteModule<P>;
14
18
  interface RemoteProps<P extends Props = Props> {
15
- name: string;
19
+ name?: string;
20
+ /** URL do `vitral.json`. Dispensa `configure()`. */
21
+ src?: string;
16
22
  props?: P;
17
23
  isolate?: Isolation;
18
24
  fallback?: JSX.Element;
19
25
  error?: (error: RemoteError, retry: () => void) => JSX.Element;
20
26
  class?: string;
27
+ /** `'lazy'`: monta perto de aparecer na tela; `'idle'`: com o navegador ocioso. */
28
+ loading?: Loading;
29
+ /** Baixa antes de montar: `'hover'`, `'visible'` ou `'idle'`. */
30
+ prefetch?: Prefetch;
31
+ /** `'high'` para o remote que aparece logo ao abrir a página. */
32
+ priority?: RequestPriority;
33
+ /** Ao sair da página, guarda o remote montado (LRU, padrão 5) e na volta só atualiza as props. */
34
+ keepAlive?: boolean | number;
21
35
  }
22
- declare function Remote<P extends Props = Props>(p: RemoteProps<P>): JSX.Element;
36
+ declare function Remote<P extends Props = Props, N extends string = string>(p: RemoteProps<P> & CheckedProps<N>): JSX.Element;
37
+ /**
38
+ * Accessor de uma chave compartilhada (`provide`/`shared`). Com seletor, só
39
+ * muda quando o resultado do seletor muda (`Object.is`). A assinatura acaba
40
+ * junto com o dono reativo (componente ou `createRoot`).
41
+ *
42
+ * const nome = useShared('usuario', (u) => u?.nome)
43
+ */
44
+ declare function useShared<K extends keyof Shared, S = Shared[K] | undefined>(key: K, select?: (value: Shared[K] | undefined) => S): Accessor<S>;
45
+ declare function useShared<T = unknown, S = T | undefined>(key: string, select?: (value: T | undefined) => S): Accessor<S>;
23
46
 
24
- export { Remote, type RemoteProps, solidRemote };
47
+ export { Remote, type RemoteProps, solidRemote, useShared };
package/dist/solid.js CHANGED
@@ -1,12 +1,22 @@
1
1
  import {
2
- createSlot,
2
+ hostSlot
3
+ } from "./chunk-IHTUM6LT.js";
4
+ import {
3
5
  defineRemote,
4
6
  events,
5
- navigate
6
- } from "./chunk-TTL52BF2.js";
7
+ memoSelect,
8
+ navigate,
9
+ same,
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";
16
+ import "./chunk-GNPFWISJ.js";
7
17
 
8
18
  // src/solid.ts
9
- import { createComponent, createEffect, createSignal, mergeProps, on, onCleanup, onMount } from "solid-js";
19
+ import { createComponent, createEffect, createSignal, getOwner, mergeProps, on, onCleanup, onMount } from "solid-js";
10
20
  import { createStore, reconcile } from "solid-js/store";
11
21
  import { isServer, render } from "solid-js/web";
12
22
  function solidRemote(Comp) {
@@ -26,15 +36,20 @@ function Remote(p) {
26
36
  const [status, setStatus] = createSignal("loading");
27
37
  const [error, setError] = createSignal(null);
28
38
  const host = document.createElement("div");
29
- host.setAttribute("data-vitral", p.name);
39
+ host.setAttribute("data-vitral", p.name ?? p.src ?? "");
30
40
  if (p.class) host.className = p.class;
31
41
  const target = document.createElement("div");
32
42
  let slot = null;
33
43
  onMount(() => {
34
- slot = createSlot(target, {
44
+ slot = hostSlot(target, {
35
45
  name: p.name,
46
+ src: p.src,
36
47
  props: p.props ?? {},
37
48
  isolate: p.isolate,
49
+ loading: p.loading,
50
+ prefetch: p.prefetch,
51
+ priority: p.priority,
52
+ keepAlive: p.keepAlive,
38
53
  onStatus: (s, e) => {
39
54
  host.setAttribute("data-vitral-status", s);
40
55
  setError(() => e);
@@ -42,7 +57,7 @@ function Remote(p) {
42
57
  }
43
58
  });
44
59
  });
45
- createEffect(on(() => [p.name, p.isolate], ([name, isolate]) => slot?.set({ name, isolate }), { defer: true }));
60
+ createEffect(on(() => [p.name, p.src, p.isolate], ([name, src, isolate]) => slot?.set({ name, src, isolate }), { defer: true }));
46
61
  createEffect(on(() => ({ ...p.props ?? {} }), (props) => slot?.update(props), { defer: true }));
47
62
  onCleanup(() => slot?.destroy());
48
63
  const retry = () => slot?.retry();
@@ -52,9 +67,18 @@ function Remote(p) {
52
67
  (host.appendChild(target), host)
53
68
  ];
54
69
  }
70
+ function useShared(key, select = same) {
71
+ const handle = shared(key);
72
+ const pick = memoSelect();
73
+ const [value, setValue] = createSignal(pick(handle.get(), select), { equals: Object.is });
74
+ const off = handle.subscribe((v) => setValue(() => pick(v, select)));
75
+ if (getOwner()) onCleanup(off);
76
+ return value;
77
+ }
55
78
  export {
56
79
  Remote,
57
80
  events,
58
81
  navigate,
59
- solidRemote
82
+ solidRemote,
83
+ useShared
60
84
  };
@@ -0,0 +1,116 @@
1
+ import {
2
+ verifyIntegrity
3
+ } from "./chunk-AH7KNMBW.js";
4
+ import {
5
+ addLink,
6
+ fetchBytes,
7
+ withTimeout
8
+ } from "./chunk-GNHCZRQP.js";
9
+ import {
10
+ RemoteError
11
+ } from "./chunk-AKNNHQ2H.js";
12
+ import "./chunk-GNPFWISJ.js";
13
+
14
+ // src/core/sri.ts
15
+ var failed = /* @__PURE__ */ new Set();
16
+ async function importVerified(name, r, run, timeout) {
17
+ const { entry, integrity, priority } = r;
18
+ if (!failed.has(entry)) {
19
+ try {
20
+ const go = async () => {
21
+ const url2 = await verified(r.split ?? { entry, chunks: [], sri: { [entry]: integrity }, priority }, run);
22
+ return url2 && { ns: await run(url2) };
23
+ };
24
+ const done = await withTimeout(timeout, name, go());
25
+ if (done) return done.ns;
26
+ } catch (e) {
27
+ failed.add(entry);
28
+ if (e instanceof RemoteError && e.code === "TIMEOUT") throw e;
29
+ }
30
+ }
31
+ const bytes = await fetchBytes(entry, timeout, name, failed.has(entry) ? { priority, cache: "reload" } : { priority });
32
+ await verifyIntegrity(name, bytes, integrity);
33
+ const url = URL.createObjectURL(new Blob([bytes], { type: "text/javascript" }));
34
+ try {
35
+ return await run(url);
36
+ } finally {
37
+ URL.revokeObjectURL(url);
38
+ }
39
+ }
40
+ var STRICT = /^(sha(256|384|512)-[A-Za-z0-9+/]+={0,2}( +|$))+$/;
41
+ var PROBE = "data:text/javascript,export{}";
42
+ var PROBE_SRI = "sha256-d3bjIZdvLjBurwdLwkSVOnEBPFFly+T1SR9r3VVHBGg=";
43
+ var maps;
44
+ var preloads;
45
+ var tick = () => new Promise((resolve) => {
46
+ const c = new MessageChannel();
47
+ c.port1.onmessage = () => resolve();
48
+ c.port2.postMessage(0);
49
+ });
50
+ async function verified(build, run) {
51
+ const { entry, chunks, sri, priority = "auto", dedupe = [] } = build;
52
+ const own = dedupe.flatMap((d) => [...d.chunks ?? [], d.file]);
53
+ if (![entry, ...chunks, ...own].every((u) => STRICT.test(sri[u] ?? ""))) return;
54
+ const p = globalThis[/* @__PURE__ */ Symbol.for("vitral")];
55
+ const share = async (pre) => {
56
+ if (!run || !dedupe.length) return;
57
+ const { shared } = await import("./dedupe-S7BHQMOZ.js");
58
+ for (const d of dedupe)
59
+ shared(p)(d.name, d.range, {
60
+ version: d.version,
61
+ url: d.file,
62
+ load: async () => {
63
+ if (pre) await Promise.all([...d.chunks ?? [], d.file].map((u) => preload(u, sri[u], priority)));
64
+ return (await run(d.file)).default;
65
+ }
66
+ });
67
+ };
68
+ if (maps !== false && (maps = await addMap(sri))) {
69
+ await share();
70
+ for (const u of chunks) fetch(u, { priority }).catch(() => {
71
+ });
72
+ return entry;
73
+ }
74
+ if (await (preloads ??= checkPreloads())) {
75
+ p.sri = { ...p.sri, ...sri };
76
+ await share(true);
77
+ await Promise.all([...chunks, entry].map((u) => preload(u, sri[u], priority)));
78
+ return entry;
79
+ }
80
+ }
81
+ async function addMap(integrity) {
82
+ let ok = true;
83
+ try {
84
+ const s = document.createElement("script");
85
+ s.type = "importmap";
86
+ s.nonce = document.querySelector("script[nonce]")?.nonce ?? "";
87
+ s.onerror = () => ok = false;
88
+ s.addEventListener("securitypolicyviolation", () => ok = false);
89
+ s.textContent = JSON.stringify({ integrity });
90
+ document.head.append(s);
91
+ } catch {
92
+ return false;
93
+ }
94
+ await tick();
95
+ await tick();
96
+ return ok;
97
+ }
98
+ function preload(href, integrity, fetchPriority = "auto") {
99
+ return new Promise((resolve, reject) => {
100
+ const link = addLink("modulepreload", href, { integrity, fetchPriority });
101
+ link.onload = resolve;
102
+ link.onerror = reject;
103
+ });
104
+ }
105
+ function checkPreloads() {
106
+ if (!document.createElement("link").relList.supports("modulepreload")) return Promise.resolve(false);
107
+ const run = (href, good) => preload(href, PROBE_SRI).then(() => good, () => !good);
108
+ return Promise.race([
109
+ Promise.all([run(PROBE, true), run(PROBE + "//", false)]).then(([a, b]) => a && b),
110
+ new Promise((resolve) => setTimeout(resolve, 3e3, false))
111
+ ]);
112
+ }
113
+ export {
114
+ importVerified,
115
+ verified
116
+ };
@@ -0,0 +1,4 @@
1
+ /** Só para testes: apaga o protocolo global. */
2
+ declare function resetProtocol(): void;
3
+
4
+ export { resetProtocol as r };
package/dist/svelte.d.ts CHANGED
@@ -1,22 +1,38 @@
1
1
  import { Component } from 'svelte';
2
- import { Props, Isolation, SlotStatus, RemoteError, RemoteModule } from './index.js';
3
- export { RemoteContext, events, navigate } from './index.js';
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';
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';
7
+ export { n as navigate } from './navigate-BRG1WJUM.js';
8
+ import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
4
9
 
5
10
  /**
6
11
  * Adaptador Svelte 5 (e SvelteKit).
7
12
  *
8
13
  * Remote: export default svelteRemote(App)
9
14
  * Host: <div use:remote={{ name: 'carrinho', props: { userId } }}></div>
15
+ * <div use:remote={{ src: 'https://cdn.exemplo.com/carrinho/vitral.json' }}></div>
10
16
  * ou o Web Component <vitral-remote> de 'vitral/element'.
11
17
  */
12
18
 
13
19
  /** Transforma um componente Svelte em um remote. O contexto chega na prop `vitral`. */
14
20
  declare function svelteRemote<P extends Props>(component: Component<any>): RemoteModule<P>;
15
21
  interface RemoteActionParams<P extends Props = Props> {
16
- name: string;
22
+ name?: string;
23
+ /** URL do `vitral.json`. Dispensa `configure()`. */
24
+ src?: string;
17
25
  props?: P;
18
26
  isolate?: Isolation;
19
27
  onStatus?: (status: SlotStatus, error: RemoteError | null) => void;
28
+ /** `'lazy'`: monta perto de aparecer na tela; `'idle'`: com o navegador ocioso. */
29
+ loading?: Loading;
30
+ /** Baixa antes de montar: `'hover'`, `'visible'` ou `'idle'`. */
31
+ prefetch?: Prefetch;
32
+ /** `'high'` para o remote que aparece logo ao abrir a página. */
33
+ priority?: RequestPriority;
34
+ /** Ao sair da página, guarda o remote montado (LRU, padrão 5) e na volta só atualiza as props. */
35
+ keepAlive?: boolean | number;
20
36
  }
21
37
  /** Action Svelte: `<div use:remote={{ name, props }}>`. Funciona também em SvelteKit (só roda no cliente). */
22
38
  declare function remote<P extends Props = Props>(node: HTMLElement, params: RemoteActionParams<P>): {
package/dist/svelte.js CHANGED
@@ -1,9 +1,16 @@
1
1
  import {
2
- createSlot,
2
+ hostSlot
3
+ } from "./chunk-IHTUM6LT.js";
4
+ import {
3
5
  defineRemote,
4
6
  events,
5
7
  navigate
6
- } from "./chunk-TTL52BF2.js";
8
+ } from "./chunk-I3VSKSAZ.js";
9
+ import "./chunk-TD4S3IHA.js";
10
+ import "./chunk-ZAC6QQI6.js";
11
+ import "./chunk-GNHCZRQP.js";
12
+ import "./chunk-AKNNHQ2H.js";
13
+ import "./chunk-GNPFWISJ.js";
7
14
 
8
15
  // src/svelte.ts
9
16
  import { createClassComponent } from "svelte/legacy";
@@ -19,10 +26,10 @@ function svelteRemote(component) {
19
26
  });
20
27
  }
21
28
  function remote(node, params) {
22
- const slot = createSlot(node, params);
29
+ const slot = hostSlot(node, params);
23
30
  return {
24
31
  update(next) {
25
- slot.set({ name: next.name, isolate: next.isolate });
32
+ slot.set({ name: next.name, src: next.src, isolate: next.isolate });
26
33
  slot.update(next.props ?? {});
27
34
  },
28
35
  destroy: () => slot.destroy()
package/dist/testing.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Props, RemoteContext } from './index.js';
2
- export { __reset as resetVitral } from './index.js';
1
+ import { P as Props, R as RemoteContext } from './types-Czvm-siZ.js';
2
+ export { r as resetVitral } from './state-BDdCwc21.js';
3
+ import './errors-kjBv6IH_.js';
3
4
 
4
5
  /**
5
6
  * Utilidades de teste: monte o host sem subir nenhum remote de verdade.
package/dist/testing.js CHANGED
@@ -1,7 +1,13 @@
1
+ import "./chunk-I3VSKSAZ.js";
1
2
  import {
2
- __reset,
3
3
  register
4
- } from "./chunk-TTL52BF2.js";
4
+ } from "./chunk-TD4S3IHA.js";
5
+ import "./chunk-ZAC6QQI6.js";
6
+ import "./chunk-GNHCZRQP.js";
7
+ import "./chunk-AKNNHQ2H.js";
8
+ import {
9
+ resetProtocol
10
+ } from "./chunk-GNPFWISJ.js";
5
11
 
6
12
  // src/testing.ts
7
13
  function mockRemote(name, render = (el) => {
@@ -43,5 +49,5 @@ function failingRemote(name, message = "falha simulada") {
43
49
  export {
44
50
  failingRemote,
45
51
  mockRemote,
46
- __reset as resetVitral
52
+ resetProtocol as resetVitral
47
53
  };