@voltro/web 0.51.0 → 0.52.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.
@@ -0,0 +1,60 @@
1
+ import { createElement as e } from "react";
2
+ import { createRoot as t, hydrateRoot as n } from "react-dom/client";
3
+ //#region src/islands.tsx
4
+ var r = /* @__PURE__ */ new Map(), i = (t, n) => {
5
+ r.set(n.name, t);
6
+ let i = n.hydrate ?? "visible", a = (r) => e("div", {
7
+ "data-voltro-island": "",
8
+ "data-island-name": n.name,
9
+ "data-island-hydrate": i,
10
+ "data-island-props": o(r, n.name)
11
+ }, i === "only" ? null : e(t, r));
12
+ return a.displayName = `Island(${n.name})`, a;
13
+ }, a = (e) => r.get(e), o = (e, t) => {
14
+ if (process.env.NODE_ENV !== "production" && typeof e == "object" && e) for (let [n, r] of Object.entries(e)) {
15
+ let e = typeof r == "function" ? "a function" : r instanceof Date ? "a Date (arrives as an ISO string)" : r instanceof Map || r instanceof Set ? "a Map/Set (arrives as {})" : void 0;
16
+ e !== void 0 && console.warn(`[voltro] island "${t}" prop "${n}" is ${e} — island props cross an HTML attribute as JSON. Pass a JSON shape (string/number/boolean/array/plain object) and reconstruct richer types inside the island.`);
17
+ }
18
+ return JSON.stringify(e ?? {}).replace(/</g, "\\u003c");
19
+ }, s = (e) => {
20
+ if (!e) return {};
21
+ try {
22
+ return JSON.parse(e);
23
+ } catch {
24
+ return {};
25
+ }
26
+ }, c = (i) => {
27
+ let a = document.querySelectorAll("[data-voltro-island]:not([data-voltro-hydrated])");
28
+ for (let o of a) {
29
+ let a = o.dataset.islandName ?? "", c = r.get(a);
30
+ if (!c) {
31
+ console.warn(`[voltro] island "${a}" referenced in DOM but not registered. Did the island file get imported in this bundle?`);
32
+ continue;
33
+ }
34
+ let l = s(o.dataset.islandProps ?? null), u = o.dataset.islandHydrate ?? "visible";
35
+ o.setAttribute("data-voltro-hydrated", "pending");
36
+ let d = () => {
37
+ if (o.getAttribute("data-voltro-hydrated") === "done") return;
38
+ o.setAttribute("data-voltro-hydrated", "done");
39
+ let r = i?.wrap === void 0 ? e(c, l) : i.wrap(e(c, l));
40
+ u === "only" ? t(o).render(r) : n(o, r);
41
+ };
42
+ if (u === "load" || u === "only") d();
43
+ else if (u === "idle") {
44
+ let e = globalThis.requestIdleCallback;
45
+ e ? e(d) : setTimeout(d, 0);
46
+ } else if (u === "visible") {
47
+ let e = new IntersectionObserver((t) => {
48
+ t.some((e) => e.isIntersecting) && (e.disconnect(), d());
49
+ }, { rootMargin: "64px" });
50
+ e.observe(o);
51
+ } else if (u === "interaction") {
52
+ let e = () => {
53
+ o.removeEventListener("pointerdown", e), o.removeEventListener("keydown", e), d();
54
+ };
55
+ o.addEventListener("pointerdown", e, { passive: !0 }), o.addEventListener("keydown", e);
56
+ }
57
+ }
58
+ };
59
+ //#endregion
60
+ export { a as getIslandComponent, c as hydrateIslandsOnPage, i as island };
package/dist/mount.js CHANGED
@@ -1,2 +1,37 @@
1
- import { n as e, t } from "./mount-nudb4UCl.js";
2
- export { t as mount, e as noticeIslandsShipTheFullBundle };
1
+ import { t as e } from "./frameworkBoot-CnE9vzLQ.js";
2
+ import { hydrateIslandsOnPage as t } from "./islands.js";
3
+ import { o as n, r, t as i } from "./routerState-DAT472IC.js";
4
+ import { StrictMode as a } from "react";
5
+ import { createRoot as o, hydrateRoot as s } from "react-dom/client";
6
+ import { applyPreloadSeeds as c, applyStoreSeeds as l } from "@voltro/client";
7
+ import { jsx as u } from "react/jsx-runtime";
8
+ //#region src/mount.tsx
9
+ var d = () => !1, f = "__voltroIslandsBundleNoticeShown", p = (e) => {
10
+ if (!e) return;
11
+ let t = globalThis;
12
+ t[f] !== !0 && (t[f] = !0, console.info("[voltro] islands mode: hydration is scoped to this page's islands, but the JS payload is NOT reduced — the full app bundle is still downloaded and evaluated. Islands buy CPU, not bytes, today. See the \"Render modes\" docs page."));
13
+ }, m = (e) => `${window.location.protocol === "https:" ? "wss:" : "ws:"}//${window.location.host}/ws/${e}`, h = (f, h) => {
14
+ let g = document.getElementById(h.rootId ?? "root");
15
+ if (!g) throw Error(`@voltro/web: no #${h.rootId ?? "root"} element in the document`);
16
+ let _ = Object.entries(h.apis).map(([e, t]) => ({
17
+ name: e,
18
+ group: t.group,
19
+ descriptors: t.descriptors ?? {},
20
+ wsUrl: t.wsUrl ?? m(e),
21
+ headers: t.headers
22
+ })), v = document.getElementById(i), y = r(v?.textContent, window.location.pathname), b = y !== null && g.children.length > 0, x = document.querySelector("meta[name=\"voltro-interactive\"]")?.getAttribute("content") ?? "full";
23
+ if (x === "none") return;
24
+ if (x === "islands") {
25
+ p(d()), t();
26
+ return;
27
+ }
28
+ b && n(y), l(y?.storeSeeds), c(y?.preloadSeeds);
29
+ let S = /* @__PURE__ */ u(a, { children: /* @__PURE__ */ u(e, {
30
+ App: f,
31
+ apis: _,
32
+ ...h.Devtools ? { Devtools: h.Devtools } : {}
33
+ }) });
34
+ b ? s(g, S) : o(g).render(S);
35
+ };
36
+ //#endregion
37
+ export { h as mount, p as noticeIslandsShipTheFullBundle };