@wunderweb/react 0.0.0-stage → 0.5.1
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/LICENSE +21 -0
- package/dist/bridge-script-DeloNmTd.mjs +352 -0
- package/dist/bridge.d.mts +8 -0
- package/dist/bridge.mjs +2 -0
- package/dist/index.d.mts +743 -0
- package/dist/index.mjs +912 -0
- package/package.json +44 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wunderwerk software GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
//#region src/bridge-script.js
|
|
2
|
+
function mountBridge(opts) {
|
|
3
|
+
const origins = (opts?.origins || []).filter((o) => {
|
|
4
|
+
try {
|
|
5
|
+
return o !== "*" && new URL(o).origin === o;
|
|
6
|
+
} catch {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
if (window.__wcBridge || window.parent === window || !origins.length) return;
|
|
11
|
+
window.__wcBridge = true;
|
|
12
|
+
const PATH = "data-wc-path";
|
|
13
|
+
const ancestor = location.ancestorOrigins?.[0];
|
|
14
|
+
let parentOrigin = ancestor && origins.includes(ancestor) ? ancestor : null;
|
|
15
|
+
let mode = "off";
|
|
16
|
+
let selected = null;
|
|
17
|
+
let hovered = null;
|
|
18
|
+
let lastRevision = null;
|
|
19
|
+
let lastRects = "";
|
|
20
|
+
let lastBox = "";
|
|
21
|
+
let frame = 0;
|
|
22
|
+
const post = (msg) => {
|
|
23
|
+
for (const o of parentOrigin ? [parentOrigin] : origins) try {
|
|
24
|
+
window.parent.postMessage(msg, o);
|
|
25
|
+
} catch {}
|
|
26
|
+
};
|
|
27
|
+
const revision = () => {
|
|
28
|
+
const main = document.querySelector("main[data-wc-revision]");
|
|
29
|
+
return main ? Number(main.getAttribute("data-wc-revision")) : -1;
|
|
30
|
+
};
|
|
31
|
+
const url = () => location.pathname + location.search;
|
|
32
|
+
const host = document.createElement("div");
|
|
33
|
+
host.setAttribute("popover", "manual");
|
|
34
|
+
host.setAttribute("data-wc-bridge", "");
|
|
35
|
+
host.style.cssText = "position:fixed;inset:0;width:100vw;height:100vh;max-width:none;max-height:none;margin:0;padding:0;border:0;background:transparent;overflow:visible;pointer-events:none;z-index:2147483647";
|
|
36
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
37
|
+
shadow.innerHTML = "<style>.r{position:fixed;box-sizing:border-box;pointer-events:none;display:none;border-radius:2px}.h{outline:1px dashed #c36e01;background:rgba(195,110,1,.07)}.s{outline:2px solid #c36e01;outline-offset:-2px;box-shadow:inset 0 0 0 3px rgba(255,255,255,.55)}</style><div class='r h'></div><div class='r s'></div>";
|
|
38
|
+
const [hoverBox, selectBox] = shadow.querySelectorAll(".r");
|
|
39
|
+
document.body.append(host);
|
|
40
|
+
const inert = document.createElement("style");
|
|
41
|
+
inert.textContent = `[${PATH}] iframe, [${PATH}] video, [${PATH}] embed, [${PATH}] object { pointer-events: none !important; }`;
|
|
42
|
+
inert.disabled = true;
|
|
43
|
+
document.head.append(inert);
|
|
44
|
+
const show = () => {
|
|
45
|
+
if (mode !== "edit") return;
|
|
46
|
+
try {
|
|
47
|
+
if (host.matches(":popover-open")) host.hidePopover();
|
|
48
|
+
host.showPopover();
|
|
49
|
+
} catch {}
|
|
50
|
+
};
|
|
51
|
+
const visible = (el) => {
|
|
52
|
+
const pop = el.closest("[popover]");
|
|
53
|
+
return !pop || pop === host || pop.matches(":popover-open");
|
|
54
|
+
};
|
|
55
|
+
const elementsOf = (path) => [...document.querySelectorAll(`[${PATH}="${CSS.escape(path)}"]`)].filter(visible);
|
|
56
|
+
const rectOf = (path) => {
|
|
57
|
+
let r = null;
|
|
58
|
+
for (const el of elementsOf(path)) {
|
|
59
|
+
const b = el.getBoundingClientRect();
|
|
60
|
+
if (!b.width && !b.height) continue;
|
|
61
|
+
r = r ? {
|
|
62
|
+
x: Math.min(r.x, b.x),
|
|
63
|
+
y: Math.min(r.y, b.y),
|
|
64
|
+
right: Math.max(r.right, b.right),
|
|
65
|
+
bottom: Math.max(r.bottom, b.bottom)
|
|
66
|
+
} : {
|
|
67
|
+
x: b.x,
|
|
68
|
+
y: b.y,
|
|
69
|
+
right: b.right,
|
|
70
|
+
bottom: b.bottom
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return r && {
|
|
74
|
+
x: r.x,
|
|
75
|
+
y: r.y,
|
|
76
|
+
width: r.right - r.x,
|
|
77
|
+
height: r.bottom - r.y
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const place = (box, rect) => {
|
|
81
|
+
if (!rect || mode !== "edit") {
|
|
82
|
+
box.style.display = "none";
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
box.style.display = "block";
|
|
86
|
+
box.style.left = `${rect.x}px`;
|
|
87
|
+
box.style.top = `${rect.y}px`;
|
|
88
|
+
box.style.width = `${rect.width}px`;
|
|
89
|
+
box.style.height = `${rect.height}px`;
|
|
90
|
+
};
|
|
91
|
+
const px = (v) => Number.parseFloat(v) || 0;
|
|
92
|
+
const rectOfEl = (el) => {
|
|
93
|
+
const b = el.getBoundingClientRect();
|
|
94
|
+
return {
|
|
95
|
+
x: b.x,
|
|
96
|
+
y: b.y,
|
|
97
|
+
width: b.width,
|
|
98
|
+
height: b.height
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const laidOut = (el) => {
|
|
102
|
+
const cs = getComputedStyle(el);
|
|
103
|
+
const b = el.getBoundingClientRect();
|
|
104
|
+
return cs.display !== "none" && cs.position !== "absolute" && cs.position !== "fixed" && (b.width > 0 || b.height > 0);
|
|
105
|
+
};
|
|
106
|
+
const flowChildren = (el) => [...el.children].filter(laidOut);
|
|
107
|
+
const boxOf = (path) => {
|
|
108
|
+
const el = elementsOf(path)[0];
|
|
109
|
+
if (!el) return null;
|
|
110
|
+
const cs = getComputedStyle(el);
|
|
111
|
+
const box = {
|
|
112
|
+
outer: rectOfEl(el),
|
|
113
|
+
margin: {
|
|
114
|
+
top: px(cs.marginTop),
|
|
115
|
+
right: px(cs.marginRight),
|
|
116
|
+
bottom: px(cs.marginBottom),
|
|
117
|
+
left: px(cs.marginLeft)
|
|
118
|
+
},
|
|
119
|
+
viewport: window.innerWidth,
|
|
120
|
+
rem: px(getComputedStyle(document.documentElement).fontSize) || 16
|
|
121
|
+
};
|
|
122
|
+
const inner = [...el.children].find((c) => c.classList.contains("wc-inner"));
|
|
123
|
+
if (inner) {
|
|
124
|
+
const ic = getComputedStyle(inner);
|
|
125
|
+
const row = ic.flexDirection.startsWith("row");
|
|
126
|
+
const children = flowChildren(inner);
|
|
127
|
+
box.inner = {
|
|
128
|
+
rect: rectOfEl(inner),
|
|
129
|
+
padding: {
|
|
130
|
+
top: px(ic.paddingTop),
|
|
131
|
+
right: px(ic.paddingRight),
|
|
132
|
+
bottom: px(ic.paddingBottom),
|
|
133
|
+
left: px(ic.paddingLeft)
|
|
134
|
+
},
|
|
135
|
+
gap: px(row ? ic.columnGap : ic.rowGap),
|
|
136
|
+
row,
|
|
137
|
+
children: children.map(rectOfEl)
|
|
138
|
+
};
|
|
139
|
+
box.grids = children.filter((c) => !c.hasAttribute(PATH)).flatMap((c) => {
|
|
140
|
+
const gc = getComputedStyle(c);
|
|
141
|
+
const items = flowChildren(c);
|
|
142
|
+
return /grid|flex/.test(gc.display) && items.length > 1 ? [{
|
|
143
|
+
rect: rectOfEl(c),
|
|
144
|
+
rowGap: px(gc.rowGap),
|
|
145
|
+
columnGap: px(gc.columnGap),
|
|
146
|
+
children: items.map(rectOfEl)
|
|
147
|
+
}] : [];
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return box;
|
|
151
|
+
};
|
|
152
|
+
const draw = () => {
|
|
153
|
+
frame = 0;
|
|
154
|
+
const rects = {};
|
|
155
|
+
for (const p of [hovered, selected]) if (p) {
|
|
156
|
+
const r = rectOf(p);
|
|
157
|
+
if (r) rects[p] = r;
|
|
158
|
+
}
|
|
159
|
+
place(hoverBox, hovered && hovered !== selected ? rects[hovered] : null);
|
|
160
|
+
place(selectBox, selected ? rects[selected] : null);
|
|
161
|
+
const key = JSON.stringify(rects);
|
|
162
|
+
if (key !== lastRects) {
|
|
163
|
+
lastRects = key;
|
|
164
|
+
post({
|
|
165
|
+
wc: "rects",
|
|
166
|
+
rects
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const box = selected && mode === "edit" ? boxOf(selected) : null;
|
|
170
|
+
const boxKey = JSON.stringify([selected, box]);
|
|
171
|
+
if (boxKey !== lastBox) {
|
|
172
|
+
lastBox = boxKey;
|
|
173
|
+
post({
|
|
174
|
+
wc: "box",
|
|
175
|
+
path: selected,
|
|
176
|
+
box
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const r = revision();
|
|
180
|
+
if (r !== lastRevision) {
|
|
181
|
+
lastRevision = r;
|
|
182
|
+
post({
|
|
183
|
+
wc: "rendered",
|
|
184
|
+
revision: r
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const schedule = () => {
|
|
189
|
+
if (!frame) frame = requestAnimationFrame(draw);
|
|
190
|
+
};
|
|
191
|
+
const blockAt = (target) => target?.closest ? target.closest(`[${PATH}]`) : null;
|
|
192
|
+
const pathOf = (el) => el ? el.getAttribute(PATH) : null;
|
|
193
|
+
const stickyTop = () => {
|
|
194
|
+
let bottom = 0;
|
|
195
|
+
for (const el of document.querySelectorAll(".wc-header, .wc-header [data-block]")) {
|
|
196
|
+
const pos = getComputedStyle(el).position;
|
|
197
|
+
if (pos === "sticky" || pos === "fixed") bottom = Math.max(bottom, el.getBoundingClientRect().bottom);
|
|
198
|
+
}
|
|
199
|
+
return bottom;
|
|
200
|
+
};
|
|
201
|
+
document.addEventListener("mousemove", (e) => {
|
|
202
|
+
if (mode !== "edit") return;
|
|
203
|
+
const p = pathOf(blockAt(e.target));
|
|
204
|
+
if (p !== hovered) {
|
|
205
|
+
hovered = p;
|
|
206
|
+
post({
|
|
207
|
+
wc: "hover",
|
|
208
|
+
path: p
|
|
209
|
+
});
|
|
210
|
+
schedule();
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
capture: true,
|
|
214
|
+
passive: true
|
|
215
|
+
});
|
|
216
|
+
document.addEventListener("mouseleave", () => {
|
|
217
|
+
if (hovered) {
|
|
218
|
+
hovered = null;
|
|
219
|
+
post({
|
|
220
|
+
wc: "hover",
|
|
221
|
+
path: null
|
|
222
|
+
});
|
|
223
|
+
schedule();
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
const swallow = (e) => {
|
|
227
|
+
if (mode !== "edit") return false;
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
e.stopPropagation();
|
|
230
|
+
e.stopImmediatePropagation();
|
|
231
|
+
return true;
|
|
232
|
+
};
|
|
233
|
+
document.addEventListener("click", (e) => {
|
|
234
|
+
if (!swallow(e)) return;
|
|
235
|
+
selected = pathOf(blockAt(e.target));
|
|
236
|
+
post({
|
|
237
|
+
wc: "select",
|
|
238
|
+
path: selected
|
|
239
|
+
});
|
|
240
|
+
schedule();
|
|
241
|
+
}, true);
|
|
242
|
+
for (const type of [
|
|
243
|
+
"auxclick",
|
|
244
|
+
"submit",
|
|
245
|
+
"dblclick"
|
|
246
|
+
]) document.addEventListener(type, swallow, true);
|
|
247
|
+
document.addEventListener("keydown", (e) => {
|
|
248
|
+
if (mode !== "edit" || e.key !== "Escape" || !selected) return;
|
|
249
|
+
const el = elementsOf(selected)[0];
|
|
250
|
+
const parent = el ? blockAt(el.parentElement) : null;
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
selected = pathOf(parent);
|
|
253
|
+
post({
|
|
254
|
+
wc: "select",
|
|
255
|
+
path: selected
|
|
256
|
+
});
|
|
257
|
+
schedule();
|
|
258
|
+
}, true);
|
|
259
|
+
window.addEventListener("scroll", schedule, {
|
|
260
|
+
capture: true,
|
|
261
|
+
passive: true
|
|
262
|
+
});
|
|
263
|
+
window.addEventListener("resize", schedule, { passive: true });
|
|
264
|
+
document.addEventListener("toggle", (e) => {
|
|
265
|
+
if (e.target !== host) show();
|
|
266
|
+
schedule();
|
|
267
|
+
}, true);
|
|
268
|
+
if (typeof ResizeObserver === "function") new ResizeObserver(schedule).observe(document.documentElement);
|
|
269
|
+
new MutationObserver(schedule).observe(document.body, {
|
|
270
|
+
subtree: true,
|
|
271
|
+
childList: true,
|
|
272
|
+
attributes: true,
|
|
273
|
+
attributeFilter: [
|
|
274
|
+
PATH,
|
|
275
|
+
"data-wc-revision",
|
|
276
|
+
"class",
|
|
277
|
+
"style",
|
|
278
|
+
"open"
|
|
279
|
+
]
|
|
280
|
+
});
|
|
281
|
+
window.addEventListener("popstate", () => post({
|
|
282
|
+
wc: "navigate",
|
|
283
|
+
url: url()
|
|
284
|
+
}));
|
|
285
|
+
window.addEventListener("message", (e) => {
|
|
286
|
+
if (!origins.includes(e.origin) || e.source !== window.parent) return;
|
|
287
|
+
const d = e.data;
|
|
288
|
+
if (!d || typeof d.wc !== "string") return;
|
|
289
|
+
parentOrigin = e.origin;
|
|
290
|
+
switch (d.wc) {
|
|
291
|
+
case "hello":
|
|
292
|
+
post({
|
|
293
|
+
wc: "ready",
|
|
294
|
+
url: url(),
|
|
295
|
+
revision: revision()
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
case "select":
|
|
299
|
+
selected = d.path;
|
|
300
|
+
break;
|
|
301
|
+
case "hover":
|
|
302
|
+
hovered = d.path;
|
|
303
|
+
break;
|
|
304
|
+
case "scrollTo": {
|
|
305
|
+
const el = elementsOf(d.path)[0];
|
|
306
|
+
if (el) {
|
|
307
|
+
const margin = typeof d.margin === "number" ? d.margin : 16;
|
|
308
|
+
const top = el.getBoundingClientRect().top + window.scrollY - stickyTop() - margin;
|
|
309
|
+
window.scrollTo({
|
|
310
|
+
top: Math.max(0, top),
|
|
311
|
+
behavior: "smooth"
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case "mode":
|
|
317
|
+
mode = d.mode === "off" ? "off" : "edit";
|
|
318
|
+
inert.disabled = mode === "off";
|
|
319
|
+
if (mode === "off") try {
|
|
320
|
+
host.hidePopover();
|
|
321
|
+
} catch {}
|
|
322
|
+
else show();
|
|
323
|
+
break;
|
|
324
|
+
case "refresh":
|
|
325
|
+
if (revision() >= d.revision) post({
|
|
326
|
+
wc: "rendered",
|
|
327
|
+
revision: revision()
|
|
328
|
+
});
|
|
329
|
+
else if (typeof window.__wunderwebRefresh === "function") window.__wunderwebRefresh();
|
|
330
|
+
else location.reload();
|
|
331
|
+
break;
|
|
332
|
+
case "openDialog": {
|
|
333
|
+
const dialog = document.getElementById(`wc-dialog-${d.ref}`);
|
|
334
|
+
try {
|
|
335
|
+
dialog?.showPopover();
|
|
336
|
+
} catch {}
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
case "closeDialog": for (const el of document.querySelectorAll("[id^=\"wc-dialog-\"]")) if (el.matches(":popover-open")) el.hidePopover();
|
|
340
|
+
}
|
|
341
|
+
schedule();
|
|
342
|
+
});
|
|
343
|
+
lastRevision = revision();
|
|
344
|
+
post({
|
|
345
|
+
wc: "ready",
|
|
346
|
+
url: url(),
|
|
347
|
+
revision: lastRevision
|
|
348
|
+
});
|
|
349
|
+
schedule();
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
export { mountBridge as t };
|
package/dist/bridge.mjs
ADDED