@floegence/floe-webapp-core 0.69.0 → 0.70.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.
- package/dist/reload-placeholder.d.ts +24 -0
- package/dist/reload-placeholder.js +124 -0
- package/package.json +5 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface ReloadPlaceholderOptions {
|
|
2
|
+
/** Session-only presentation storage; never put resource data in this record. */
|
|
3
|
+
storageKey: string;
|
|
4
|
+
/** Optional session-storage identity to isolate navigation between environments. */
|
|
5
|
+
scopeStorageKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ReloadPlaceholder {
|
|
8
|
+
active(): boolean;
|
|
9
|
+
/** Keep the matching content placeholder while the live shell becomes usable. */
|
|
10
|
+
restrictTo(element: Element): void;
|
|
11
|
+
finish(): void;
|
|
12
|
+
/** Capture only anonymous geometry on pagehide, from the current authorized view. */
|
|
13
|
+
arm(root: Element, surfaces: string): void;
|
|
14
|
+
/** Explicit revocation discards the placeholder and its session record. */
|
|
15
|
+
clear(): void;
|
|
16
|
+
}
|
|
17
|
+
declare global {
|
|
18
|
+
interface Window {
|
|
19
|
+
__floeReloadPlaceholder?: ReloadPlaceholder;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Insert before external scripts/styles. It restores anonymous layout, never cached facts. */
|
|
23
|
+
export declare function createReloadPlaceholderScript(options: ReloadPlaceholderOptions): string;
|
|
24
|
+
export declare function getReloadPlaceholder(): ReloadPlaceholder | undefined;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
function P(h) {
|
|
2
|
+
const s = document, $ = 48e3, b = 240, A = () => h.scopeStorageKey ? sessionStorage.getItem(h.scopeStorageKey) ?? "" : "", g = (o) => typeof o == "string" && o.length <= 120 && !/[;{}<>\\]|url\(|var\(/i.test(o) && CSS.supports("color", o);
|
|
3
|
+
let l, a, C = "", d;
|
|
4
|
+
try {
|
|
5
|
+
const o = sessionStorage.getItem(h.storageKey), e = o && o.length <= $ ? JSON.parse(o) : void 0;
|
|
6
|
+
e?.version === 1 && e.scope === A() && e.width === innerWidth && e.height === innerHeight && g(e.background) && Array.isArray(e.scroll) && e.scroll.length <= 12 && e.scroll.every((r) => Array.isArray(r) && r.length === 3 && /^[a-z0-9-]{1,48}$/.test(r[0]) && r.slice(1).every((i) => typeof i == "number" && Number.isFinite(i) && i >= 0 && i <= 1e7)) && Array.isArray(e.boxes) && e.boxes.length > 0 && e.boxes.length <= b && e.boxes.every((r) => Array.isArray(r) && r.length === 7 && r.slice(0, 5).every((i) => typeof i == "number" && Number.isFinite(i) && i >= 0 && i <= 2e4) && g(r[5]) && g(r[6])) && (d = e);
|
|
7
|
+
} catch {
|
|
8
|
+
}
|
|
9
|
+
const M = () => {
|
|
10
|
+
if (!(!d || !s.body)) {
|
|
11
|
+
l = s.createElement("div"), l.dataset.floeReloadPlaceholder = "", l.setAttribute("aria-hidden", "true"), l.inert = !0, Object.assign(l.style, {
|
|
12
|
+
position: "fixed",
|
|
13
|
+
inset: "0",
|
|
14
|
+
zIndex: "2147483000",
|
|
15
|
+
overflow: "hidden",
|
|
16
|
+
backgroundColor: d.background,
|
|
17
|
+
pointerEvents: "none",
|
|
18
|
+
contain: "strict"
|
|
19
|
+
});
|
|
20
|
+
for (const [o, e, r, i, x, m, w] of d.boxes) {
|
|
21
|
+
const p = s.createElement("div");
|
|
22
|
+
Object.assign(p.style, {
|
|
23
|
+
position: "absolute",
|
|
24
|
+
left: `${o}px`,
|
|
25
|
+
top: `${e}px`,
|
|
26
|
+
width: `${r}px`,
|
|
27
|
+
height: `${i}px`,
|
|
28
|
+
borderRadius: `${x}px`,
|
|
29
|
+
backgroundColor: m,
|
|
30
|
+
border: `1px solid ${w}`,
|
|
31
|
+
boxSizing: "border-box"
|
|
32
|
+
}), l.append(p);
|
|
33
|
+
}
|
|
34
|
+
s.body.append(l);
|
|
35
|
+
}
|
|
36
|
+
}, v = new MutationObserver(() => {
|
|
37
|
+
s.body && (v.disconnect(), M());
|
|
38
|
+
});
|
|
39
|
+
s.body ? M() : d && v.observe(s.documentElement, { childList: !0 });
|
|
40
|
+
const y = () => {
|
|
41
|
+
v.disconnect();
|
|
42
|
+
for (const [o, e, r] of d?.scroll ?? []) {
|
|
43
|
+
const i = s.querySelector(`[data-floe-reload-scroll="${o}"]`);
|
|
44
|
+
i && (i.scrollLeft = e, i.scrollTop = r);
|
|
45
|
+
}
|
|
46
|
+
d = void 0, l?.remove(), l = void 0;
|
|
47
|
+
}, N = () => {
|
|
48
|
+
a = void 0, y();
|
|
49
|
+
try {
|
|
50
|
+
sessionStorage.removeItem(h.storageKey);
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
}, O = () => {
|
|
54
|
+
if (!a?.isConnected || l) return;
|
|
55
|
+
const o = [], e = getComputedStyle(s.body).backgroundColor;
|
|
56
|
+
if (!g(e)) return;
|
|
57
|
+
const r = (n) => {
|
|
58
|
+
const t = n.getBoundingClientRect(), c = getComputedStyle(n);
|
|
59
|
+
return t.width && t.height && t.bottom > 0 && t.right > 0 && t.top < innerHeight && t.left < innerWidth && c.visibility === "visible" ? t : null;
|
|
60
|
+
}, i = (n, t, c = "transparent", u = 3) => {
|
|
61
|
+
if (o.length >= b || !g(t) || !g(c)) return;
|
|
62
|
+
const f = Math.max(0, n.x), R = Math.max(0, n.y), k = Math.min(innerWidth, n.right) - f, E = Math.min(innerHeight, n.bottom) - R;
|
|
63
|
+
k <= 0 || E <= 0 || o.push([f, R, k, E, Math.max(0, Math.min(u, 100)), t, c]);
|
|
64
|
+
};
|
|
65
|
+
for (const n of a.querySelectorAll(C)) {
|
|
66
|
+
const t = r(n);
|
|
67
|
+
if (!t) continue;
|
|
68
|
+
const c = getComputedStyle(n);
|
|
69
|
+
i(t, c.backgroundColor, c.borderTopStyle === "none" ? "transparent" : c.borderTopColor, parseFloat(c.borderRadius) || 0);
|
|
70
|
+
}
|
|
71
|
+
const x = getComputedStyle(a).color, m = g(x) ? `color-mix(in srgb, ${x} 9%, ${e})` : "#d4d4d4";
|
|
72
|
+
for (const n of a.querySelectorAll("img,svg,input,textarea,canvas,video")) {
|
|
73
|
+
const t = r(n);
|
|
74
|
+
t && i(t, m, "transparent", Math.min(t.height / 4, 8));
|
|
75
|
+
}
|
|
76
|
+
const w = s.createTreeWalker(a, NodeFilter.SHOW_TEXT), p = s.createRange();
|
|
77
|
+
let S, T = 0;
|
|
78
|
+
for (; (S = w.nextNode()) && o.length < b && T++ < 12e3; ) {
|
|
79
|
+
const n = S.parentElement;
|
|
80
|
+
if (!(!n || n.closest('script,style,textarea,svg,[aria-hidden="true"]') || !r(n))) {
|
|
81
|
+
p.selectNodeContents(S);
|
|
82
|
+
for (const t of p.getClientRects())
|
|
83
|
+
t.width < 2 || i(new DOMRect(t.x, t.y + t.height * 0.22, t.width, t.height * 0.56), m);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (o.length)
|
|
87
|
+
try {
|
|
88
|
+
const n = [];
|
|
89
|
+
for (const u of a.querySelectorAll("[data-floe-reload-scroll]")) {
|
|
90
|
+
const f = u.getAttribute("data-floe-reload-scroll");
|
|
91
|
+
/^[a-z0-9-]{1,48}$/.test(f) && n.length < 12 && r(u) && n.push([f, u.scrollLeft, u.scrollTop]);
|
|
92
|
+
}
|
|
93
|
+
const t = { version: 1, scope: A(), width: innerWidth, height: innerHeight, background: e, boxes: o, scroll: n }, c = JSON.stringify(t);
|
|
94
|
+
c.length <= $ && sessionStorage.setItem(h.storageKey, c);
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
window.__floeReloadPlaceholder = {
|
|
99
|
+
active: () => !!d,
|
|
100
|
+
restrictTo(o) {
|
|
101
|
+
if (!l) return;
|
|
102
|
+
const e = o.getBoundingClientRect();
|
|
103
|
+
l.style.clipPath = `inset(${Math.max(0, e.top)}px ${Math.max(0, innerWidth - e.right)}px ${Math.max(0, innerHeight - e.bottom)}px ${Math.max(0, e.left)}px)`;
|
|
104
|
+
},
|
|
105
|
+
finish: y,
|
|
106
|
+
arm(o, e) {
|
|
107
|
+
a = o, C = e;
|
|
108
|
+
},
|
|
109
|
+
clear: N
|
|
110
|
+
}, window.addEventListener("pagehide", O), window.addEventListener("resize", y, { once: !0 }), window.addEventListener("pageshow", (o) => {
|
|
111
|
+
o.persisted && y();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function W(h) {
|
|
115
|
+
const s = JSON.stringify(h).replaceAll("<", "\\u003c").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
|
|
116
|
+
return `;(${P.toString()})(${s});`;
|
|
117
|
+
}
|
|
118
|
+
function H() {
|
|
119
|
+
return typeof window > "u" ? void 0 : window.__floeReloadPlaceholder;
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
W as createReloadPlaceholderScript,
|
|
123
|
+
H as getReloadPlaceholder
|
|
124
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floegence/floe-webapp-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.70.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -112,6 +112,10 @@
|
|
|
112
112
|
"types": "./dist/window-status.d.ts",
|
|
113
113
|
"import": "./dist/window-status.js",
|
|
114
114
|
"default": "./dist/window-status.js"
|
|
115
|
+
},
|
|
116
|
+
"./reload-placeholder": {
|
|
117
|
+
"types": "./dist/reload-placeholder.d.ts",
|
|
118
|
+
"import": "./dist/reload-placeholder.js"
|
|
115
119
|
}
|
|
116
120
|
},
|
|
117
121
|
"files": [
|