@supernovaio/prototyping-tooling 0.9.5-alpha.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/README.md +193 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +96 -0
- package/dist/build/vite-plugin-forge-ids.d.ts +7 -0
- package/dist/build/vite-plugin-forge-ids.d.ts.map +1 -0
- package/dist/client/annotation/AnnotationOverlay.d.ts +104 -0
- package/dist/client/annotation/AnnotationOverlay.d.ts.map +1 -0
- package/dist/client/design-mode/DesignModeController.d.ts +35 -0
- package/dist/client/design-mode/DesignModeController.d.ts.map +1 -0
- package/dist/client/general/ComponentRegistry.d.ts +15 -0
- package/dist/client/general/ComponentRegistry.d.ts.map +1 -0
- package/dist/client/general/ForgeClient.d.ts +39 -0
- package/dist/client/general/ForgeClient.d.ts.map +1 -0
- package/dist/client/general/SourceCodeUpdater.d.ts +15 -0
- package/dist/client/general/SourceCodeUpdater.d.ts.map +1 -0
- package/dist/client/general/element-utils.d.ts +20 -0
- package/dist/client/general/element-utils.d.ts.map +1 -0
- package/dist/client/general/overlay.d.ts +9 -0
- package/dist/client/general/overlay.d.ts.map +1 -0
- package/dist/client/general/react-detection.d.ts +49 -0
- package/dist/client/general/react-detection.d.ts.map +1 -0
- package/dist/client/general/types.d.ts +26 -0
- package/dist/client/general/types.d.ts.map +1 -0
- package/dist/client/general/xpath.d.ts +5 -0
- package/dist/client/general/xpath.d.ts.map +1 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/select-mode/SelectModeController.d.ts +31 -0
- package/dist/client/select-mode/SelectModeController.d.ts.map +1 -0
- package/dist/client.js +946 -0
- package/dist/constants-BXKWBfHg.js +55 -0
- package/dist/debug-CLzmqn3R.js +11 -0
- package/dist/host/ForgeHost.d.ts +63 -0
- package/dist/host/ForgeHost.d.ts.map +1 -0
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/types.d.ts +33 -0
- package/dist/host/types.d.ts.map +1 -0
- package/dist/host.js +154 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/useDesignMode.d.ts +12 -0
- package/dist/react/useDesignMode.d.ts.map +1 -0
- package/dist/react/useElementSelector.d.ts +12 -0
- package/dist/react/useElementSelector.d.ts.map +1 -0
- package/dist/react.js +5 -0
- package/dist/shared/constants.d.ts +27 -0
- package/dist/shared/constants.d.ts.map +1 -0
- package/dist/shared/debug.d.ts +4 -0
- package/dist/shared/debug.d.ts.map +1 -0
- package/dist/shared/events.d.ts +174 -0
- package/dist/shared/events.d.ts.map +1 -0
- package/dist/shared/messaging.d.ts +19 -0
- package/dist/shared/messaging.d.ts.map +1 -0
- package/dist/useDesignMode-VIipNUSj.js +68 -0
- package/package.json +79 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,946 @@
|
|
|
1
|
+
import { b as $, c as X, R as Y, d as U, Z as C, C as v, M as O, B as M, e as B, P as G, i as W, a as V, T as j } from "./constants-BXKWBfHg.js";
|
|
2
|
+
import { d as c } from "./debug-CLzmqn3R.js";
|
|
3
|
+
class z {
|
|
4
|
+
registry = /* @__PURE__ */ new Map();
|
|
5
|
+
register(e, t) {
|
|
6
|
+
this.registry.set(e, t);
|
|
7
|
+
}
|
|
8
|
+
registerAll(e) {
|
|
9
|
+
for (const [t, n] of Object.entries(e))
|
|
10
|
+
this.registry.set(t, n);
|
|
11
|
+
}
|
|
12
|
+
getEditableProps(e) {
|
|
13
|
+
let t = this.registry.get(e);
|
|
14
|
+
if (!t) {
|
|
15
|
+
const o = e.toLowerCase();
|
|
16
|
+
for (const [i, s] of this.registry.entries())
|
|
17
|
+
if (i.toLowerCase() === o) {
|
|
18
|
+
t = s;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const n = { p: "p", h1: "h1", h2: "h2", h3: "h3" };
|
|
23
|
+
return !t && n[e] && (t = this.registry.get(n[e])), t ? Object.entries(t.props).filter(([o, i]) => i.editable).map(([o, i]) => ({ name: o, type: i.type, options: i.options, default: i.default, editable: i.editable, label: i.label })) : [];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function H(r) {
|
|
27
|
+
if (r.id)
|
|
28
|
+
return [`*[@id="${r.id}"]`];
|
|
29
|
+
const e = [];
|
|
30
|
+
let t = r;
|
|
31
|
+
for (; t && t.nodeType === Node.ELEMENT_NODE; ) {
|
|
32
|
+
let n = t.nodeName.toLowerCase();
|
|
33
|
+
if (t.parentNode) {
|
|
34
|
+
const o = Array.from(t.parentNode.children), i = o.indexOf(t) + 1;
|
|
35
|
+
o.length > 1 && (n += `[${i}]`);
|
|
36
|
+
}
|
|
37
|
+
e.unshift(n), t = t.parentElement;
|
|
38
|
+
}
|
|
39
|
+
return e;
|
|
40
|
+
}
|
|
41
|
+
function b(r) {
|
|
42
|
+
return r.length === 1 && r[0].startsWith("*[@id=") ? `//${r[0]}` : "/" + r.join("/");
|
|
43
|
+
}
|
|
44
|
+
const u = { FunctionComponent: 0, ClassComponent: 1, IndeterminateComponent: 2, HostRoot: 3, HostPortal: 4, HostComponent: 5, HostText: 6, Fragment: 7, Mode: 8, ContextConsumer: 9, ContextProvider: 10, ForwardRef: 11, Profiler: 12, SuspenseComponent: 13, MemoComponent: 14, SimpleMemoComponent: 15, LazyComponent: 16, IncompleteClassComponent: 17, DehydratedFragment: 18, SuspenseListComponent: 19, ScopeComponent: 21, OffscreenComponent: 22, LegacyHiddenComponent: 23, CacheComponent: 24, TracingMarkerComponent: 25, HostHoistable: 26, HostSingleton: 27, IncompleteFunctionComponent: 28, Throw: 29, ViewTransitionComponent: 30, ActivityComponent: 31 }, K = /* @__PURE__ */ new Set(["Component", "PureComponent", "Fragment", "Suspense", "Profiler", "StrictMode", "Routes", "Route", "Outlet", "Root", "ErrorBoundaryHandler", "HotReload", "Hot"]), J = [/Boundary$/, /BoundaryHandler$/, /Provider$/, /Consumer$/, /^(Inner|Outer)/, /Router$/, /^Client(Page|Segment|Root)/, /^Server(Root|Component|Render)/, /^RSC/, /Context$/, /^Hot(Reload)?$/, /^(Dev|React)(Overlay|Tools|Root)/, /Overlay$/, /Handler$/, /^With[A-Z]/, /Wrapper$/, /^Root$/];
|
|
45
|
+
let T = null;
|
|
46
|
+
function N(r) {
|
|
47
|
+
const e = (t) => t.some((n) => n.startsWith("__reactFiber$") || n.startsWith("__reactInternalInstance$") || n.startsWith("__reactProps$"));
|
|
48
|
+
return e(Object.keys(r)) || e(Object.getOwnPropertyNames(r));
|
|
49
|
+
}
|
|
50
|
+
function q() {
|
|
51
|
+
if (T !== null) return T;
|
|
52
|
+
if (typeof document > "u") return !1;
|
|
53
|
+
if (document.body && N(document.body))
|
|
54
|
+
return c("client", "Detected React on document.body"), T = !0, !0;
|
|
55
|
+
for (const e of Y) {
|
|
56
|
+
const t = document.querySelector(e);
|
|
57
|
+
if (t) {
|
|
58
|
+
if (N(t))
|
|
59
|
+
return c("client", "Detected React on", e), T = !0, !0;
|
|
60
|
+
for (const n of t.children)
|
|
61
|
+
if (N(n))
|
|
62
|
+
return c("client", "Detected React on child of", e), T = !0, !0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (document.body) {
|
|
66
|
+
for (const e of document.body.children)
|
|
67
|
+
if (N(e))
|
|
68
|
+
return c("client", "Detected React on body child:", e.tagName), T = !0, !0;
|
|
69
|
+
}
|
|
70
|
+
const r = document.querySelectorAll("*");
|
|
71
|
+
for (const e of r) {
|
|
72
|
+
if (N(e))
|
|
73
|
+
return c("client", "Detected React on deep scan:", e.tagName), T = !0, !0;
|
|
74
|
+
if (r.length > U) break;
|
|
75
|
+
}
|
|
76
|
+
return c("client", "React NOT detected on page"), T = !1, !1;
|
|
77
|
+
}
|
|
78
|
+
function Z(r) {
|
|
79
|
+
const e = Object.keys(r);
|
|
80
|
+
let t = e.find((s) => s.startsWith("__reactFiber$"));
|
|
81
|
+
if (t) return r[t] || null;
|
|
82
|
+
let n = e.find((s) => s.startsWith("__reactInternalInstance$"));
|
|
83
|
+
if (n) return r[n] || null;
|
|
84
|
+
const o = Object.getOwnPropertyNames(r);
|
|
85
|
+
if (t = o.find((s) => s.startsWith("__reactFiber$")), t) return r[t] || null;
|
|
86
|
+
if (n = o.find((s) => s.startsWith("__reactInternalInstance$")), n) return r[n] || null;
|
|
87
|
+
const i = o.find((s) => {
|
|
88
|
+
if (!s.startsWith("__react")) return !1;
|
|
89
|
+
const a = r[s];
|
|
90
|
+
return a && typeof a == "object" && ("return" in a || "tag" in a);
|
|
91
|
+
});
|
|
92
|
+
return i && r[i] || null;
|
|
93
|
+
}
|
|
94
|
+
function A(r) {
|
|
95
|
+
return r ? r.displayName ? r.displayName : r.name ? r.name : null : null;
|
|
96
|
+
}
|
|
97
|
+
function Q(r) {
|
|
98
|
+
const { tag: e, type: t, elementType: n } = r;
|
|
99
|
+
if ((/* @__PURE__ */ new Set([u.HostComponent, u.HostText, u.HostHoistable, u.HostSingleton, u.Fragment, u.Mode, u.Profiler, u.DehydratedFragment, u.HostRoot, u.HostPortal, u.ScopeComponent, u.OffscreenComponent, u.LegacyHiddenComponent, u.CacheComponent, u.TracingMarkerComponent, u.Throw, u.ViewTransitionComponent, u.ActivityComponent, u.SuspenseComponent, u.SuspenseListComponent])).has(e)) return null;
|
|
100
|
+
if (e === u.ForwardRef) {
|
|
101
|
+
const i = n;
|
|
102
|
+
if (i?.render) {
|
|
103
|
+
const s = A(i.render);
|
|
104
|
+
if (s) return s;
|
|
105
|
+
}
|
|
106
|
+
return i?.displayName ? i.displayName : A(t);
|
|
107
|
+
}
|
|
108
|
+
if (e === u.MemoComponent || e === u.SimpleMemoComponent) {
|
|
109
|
+
const i = n;
|
|
110
|
+
if (i?.type) {
|
|
111
|
+
const s = A(i.type);
|
|
112
|
+
if (s) return s;
|
|
113
|
+
}
|
|
114
|
+
return i?.displayName ? i.displayName : A(t);
|
|
115
|
+
}
|
|
116
|
+
if (e === u.ContextProvider) {
|
|
117
|
+
const i = t;
|
|
118
|
+
return i?._context?.displayName ? `${i._context.displayName}.Provider` : null;
|
|
119
|
+
}
|
|
120
|
+
if (e === u.ContextConsumer) {
|
|
121
|
+
const i = t;
|
|
122
|
+
return i?.displayName ? `${i.displayName}.Consumer` : null;
|
|
123
|
+
}
|
|
124
|
+
if (e === u.LazyComponent) {
|
|
125
|
+
const i = n;
|
|
126
|
+
return i?._status === 1 && i._result ? A(i._result) : null;
|
|
127
|
+
}
|
|
128
|
+
return e === u.IncompleteClassComponent || e === u.IncompleteFunctionComponent || e === u.FunctionComponent || e === u.ClassComponent || e === u.IndeterminateComponent ? A(t) : null;
|
|
129
|
+
}
|
|
130
|
+
function ee(r) {
|
|
131
|
+
return r.length <= 2 || r.length <= 3 && r === r.toLowerCase();
|
|
132
|
+
}
|
|
133
|
+
function te(r) {
|
|
134
|
+
return !(K.has(r) || J.some((e) => e.test(r)));
|
|
135
|
+
}
|
|
136
|
+
function ne(r, e = $, t = X) {
|
|
137
|
+
if (!q())
|
|
138
|
+
return c("client", "isReactPage() = false"), { path: null, components: [] };
|
|
139
|
+
const n = [];
|
|
140
|
+
try {
|
|
141
|
+
let i = Z(r), s = 0;
|
|
142
|
+
for (; i && s < t && n.length < e; ) {
|
|
143
|
+
const a = Q(i);
|
|
144
|
+
a && !ee(a) && te(a) && n.push(a), i = i.return, s++;
|
|
145
|
+
}
|
|
146
|
+
} catch (i) {
|
|
147
|
+
return c("client", "Error walking fiber tree:", i), { path: null, components: [] };
|
|
148
|
+
}
|
|
149
|
+
return n.length === 0 ? { path: null, components: [] } : { path: n.slice().reverse().map((i) => `<${i}>`).join(" "), components: n };
|
|
150
|
+
}
|
|
151
|
+
let S = null, E = null;
|
|
152
|
+
function x(r, e, t, n = "solid") {
|
|
153
|
+
const o = document.createElement("div");
|
|
154
|
+
return Object.assign(o.style, { position: "fixed", left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px`, border: `1px ${n} ${e}`, backgroundColor: t, pointerEvents: "none", zIndex: C.HOVER_OVERLAY, borderRadius: "2px" }), o;
|
|
155
|
+
}
|
|
156
|
+
function oe(r) {
|
|
157
|
+
L();
|
|
158
|
+
const e = r.getBoundingClientRect();
|
|
159
|
+
S = x(e, v.SELECT_OVERLAY_BORDER, v.SELECT_OVERLAY_BG), S.className = "forge-overlay", document.body.appendChild(S);
|
|
160
|
+
}
|
|
161
|
+
function L() {
|
|
162
|
+
S && (S.remove(), S = null);
|
|
163
|
+
}
|
|
164
|
+
function ie() {
|
|
165
|
+
return E || (E = document.createElement("div"), Object.assign(E.style, { position: "fixed", top: "0", left: "0", width: "100%", height: "100%", backgroundColor: "transparent", pointerEvents: "auto", zIndex: C.HIT_TEST_OVERLAY, cursor: "crosshair" }), E.className = "forge-hit-test-overlay", document.body.appendChild(E), E);
|
|
166
|
+
}
|
|
167
|
+
function se() {
|
|
168
|
+
E && (E.remove(), E = null);
|
|
169
|
+
}
|
|
170
|
+
let re = 0;
|
|
171
|
+
function ae() {
|
|
172
|
+
return `ann-${Date.now()}-${++re}`;
|
|
173
|
+
}
|
|
174
|
+
class D {
|
|
175
|
+
active = !1;
|
|
176
|
+
messenger;
|
|
177
|
+
hoverOverlay = null;
|
|
178
|
+
componentTooltip = null;
|
|
179
|
+
hitTestOverlay = null;
|
|
180
|
+
dragRect = null;
|
|
181
|
+
dragHighlights = [];
|
|
182
|
+
annotationHighlights = [];
|
|
183
|
+
dots = /* @__PURE__ */ new Map();
|
|
184
|
+
isDragging = !1;
|
|
185
|
+
dragStartX = 0;
|
|
186
|
+
dragStartY = 0;
|
|
187
|
+
dragScopeParent = null;
|
|
188
|
+
hoverSuppressed = !1;
|
|
189
|
+
activeHighlightDotId = null;
|
|
190
|
+
pendingHighlightLocators = null;
|
|
191
|
+
lastHoveredElement = null;
|
|
192
|
+
accumulationId = null;
|
|
193
|
+
accumulationElements = [];
|
|
194
|
+
constructor(e) {
|
|
195
|
+
this.messenger = e, window.__forgeAnnotations = this, window.addEventListener("scroll", this.repositionAll, { capture: !0, passive: !0 }), window.addEventListener("resize", this.repositionAll, { passive: !0 });
|
|
196
|
+
}
|
|
197
|
+
activate() {
|
|
198
|
+
this.active || (this.active = !0, c("annotation", "Annotation mode activated"), this.createHitTestOverlay(), this.addListeners(), this.setMarkersVisible(!0), document.body.style.cursor = "crosshair");
|
|
199
|
+
}
|
|
200
|
+
deactivate() {
|
|
201
|
+
this.active && (this.active = !1, c("annotation", "Annotation mode deactivated"), this.removeHoverOverlay(), this.clearAnnotationHighlights(), this.removeHitTestOverlay(), this.removeDragRect(), this.removeListeners(), this.setMarkersVisible(!1), document.body.style.cursor = "");
|
|
202
|
+
}
|
|
203
|
+
selectDot(e) {
|
|
204
|
+
const t = this.dots.get(e);
|
|
205
|
+
t && (this.removeHoverOverlay(), this.hoverSuppressed = !0, this.highlightAnnotationElements(t));
|
|
206
|
+
}
|
|
207
|
+
enterAccumulation(e, t) {
|
|
208
|
+
if (this.accumulationId !== e) {
|
|
209
|
+
this.accumulationId = e, this.accumulationElements = [], this.clearAnnotationHighlights();
|
|
210
|
+
for (const n of t) {
|
|
211
|
+
const o = { xpath: b(n.xpath), forgeId: n.forgeId, forgeIdIndex: n.forgeIdIndex }, i = this.resolveLocator(o);
|
|
212
|
+
i && this.accumulationElements.push(i);
|
|
213
|
+
}
|
|
214
|
+
this.refreshAccumulationHighlights(), this.hoverSuppressed = !1, c("annotation", `Entered accumulation mode for ${e} with ${this.accumulationElements.length} elements`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exitAccumulation() {
|
|
218
|
+
if (!this.accumulationId) return;
|
|
219
|
+
const e = this.accumulationId;
|
|
220
|
+
if (this.accumulationElements.length > 0) {
|
|
221
|
+
const n = this.accumulationElements[this.accumulationElements.length - 1].getBoundingClientRect(), o = n.left + n.width / 2, i = n.bottom;
|
|
222
|
+
this.pendingAnnotations.delete(e), this.createAnnotationFromElements([...this.accumulationElements], this.accumulationElements.length > 1 ? "multi" : "single", o, i, e);
|
|
223
|
+
} else
|
|
224
|
+
this.pendingAnnotations.delete(e), this.clearAnnotationHighlights();
|
|
225
|
+
this.accumulationId = null, this.accumulationElements = [], c("annotation", `Exited accumulation mode for ${e}`);
|
|
226
|
+
}
|
|
227
|
+
refreshAccumulationHighlights() {
|
|
228
|
+
this.clearAnnotationHighlights();
|
|
229
|
+
const e = this.accumulationElements.map((t) => this.elementToLocator(t));
|
|
230
|
+
e.length > 0 && this.highlightLocators(e, this.accumulationElements.length > 1);
|
|
231
|
+
}
|
|
232
|
+
elementToLocator(e) {
|
|
233
|
+
const t = e.getAttribute("data-forge-id") || void 0;
|
|
234
|
+
let n;
|
|
235
|
+
if (t) {
|
|
236
|
+
const o = document.querySelectorAll(`[data-forge-id="${t}"]`);
|
|
237
|
+
o.length > 1 && (n = Array.from(o).indexOf(e));
|
|
238
|
+
}
|
|
239
|
+
return { xpath: b(H(e)), forgeId: t, forgeIdIndex: n };
|
|
240
|
+
}
|
|
241
|
+
elementToInfo(e) {
|
|
242
|
+
return { elementTag: e.tagName.toLowerCase(), xpath: H(e), componentName: e.getAttribute("data-component") || void 0, componentPath: this.getComponentPath(e) || void 0, forgeId: e.getAttribute("data-forge-id") || void 0, forgeIdIndex: this.resolveForgeIdIndex(e), sourcePos: e.getAttribute("data-source-pos") || void 0 };
|
|
243
|
+
}
|
|
244
|
+
resolveForgeIdIndex(e) {
|
|
245
|
+
const t = e.getAttribute("data-forge-id");
|
|
246
|
+
if (!t) return;
|
|
247
|
+
const n = document.querySelectorAll(`[data-forge-id="${t}"]`);
|
|
248
|
+
if (n.length > 1) return Array.from(n).indexOf(e);
|
|
249
|
+
}
|
|
250
|
+
sendAccumulationUpdate() {
|
|
251
|
+
if (!this.accumulationId) return;
|
|
252
|
+
const e = this.accumulationElements;
|
|
253
|
+
if (e.length === 0) {
|
|
254
|
+
this.messenger.send({ type: "ACCUMULATION_UPDATED", annotation: { id: this.accumulationId, dotX: 0, dotY: 0, mode: "single", elements: [], xpaths: [], elementTag: "" }, origin: O });
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const n = e[e.length - 1].getBoundingClientRect(), o = n.left + n.width / 2, i = n.bottom, s = e.map((g) => this.elementToInfo(g)), a = e.map((g) => this.elementToLocator(g)), l = this.getAnchorRect(a), h = o - 2, d = i - M - 2, m = l && l.width > 0 && l.height > 0 ? { x: (h - l.left) / l.width, y: (d - l.top) / l.height } : { x: 0, y: 0 }, p = s[0];
|
|
258
|
+
this.messenger.send({ type: "ACCUMULATION_UPDATED", annotation: { id: this.accumulationId, dotX: o, dotY: i, anchorOffset: m, mode: e.length > 1 ? "multi" : "single", elements: s, xpaths: s.map((g) => b(g.xpath)), elementTag: p.elementTag, componentName: p.componentName, componentPath: p.componentPath, forgeId: p.forgeId, sourcePos: p.sourcePos }, origin: O });
|
|
259
|
+
}
|
|
260
|
+
removeDot(e) {
|
|
261
|
+
const t = this.dots.get(e);
|
|
262
|
+
t && (t.element.remove(), this.dots.delete(e)), this.hoverSuppressed = !1;
|
|
263
|
+
}
|
|
264
|
+
removeAllDots() {
|
|
265
|
+
this.dots.forEach((e) => e.element.remove()), this.dots.clear();
|
|
266
|
+
}
|
|
267
|
+
restoreDots(e) {
|
|
268
|
+
this.removeAllDots();
|
|
269
|
+
for (const t of e) {
|
|
270
|
+
const n = t.elements.map((i) => ({ xpath: b(i.xpath), forgeId: i.forgeId, forgeIdIndex: i.forgeIdIndex })), o = this.getAnchorRect(n);
|
|
271
|
+
if (o && t.anchorOffset && o.width > 0 && o.height > 0) {
|
|
272
|
+
const i = { rx: t.anchorOffset.x, ry: t.anchorOffset.y }, s = o.left + i.rx * o.width, a = o.top + i.ry * o.height;
|
|
273
|
+
this.createDotAtPosition(s, a, t.mode, t.id, t.order, n, i);
|
|
274
|
+
} else
|
|
275
|
+
this.createDot(t.dotX, t.dotY, t.mode, t.id, t.order, n);
|
|
276
|
+
}
|
|
277
|
+
c("annotation", `Restored ${e.length} annotation dots`);
|
|
278
|
+
}
|
|
279
|
+
markersVisible = !1;
|
|
280
|
+
toggleMarkers() {
|
|
281
|
+
this.setMarkersVisible(!this.markersVisible);
|
|
282
|
+
}
|
|
283
|
+
setMarkersVisible(e) {
|
|
284
|
+
this.markersVisible = e;
|
|
285
|
+
const t = e ? "flex" : "none";
|
|
286
|
+
this.dots.forEach((n) => {
|
|
287
|
+
n.element.style.display = t;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
repositionAll = () => {
|
|
291
|
+
if (this.dots.forEach((e) => {
|
|
292
|
+
if (e.locators.length === 0) return;
|
|
293
|
+
const t = this.getAnchorRect(e.locators);
|
|
294
|
+
t && (e.element.style.left = `${t.left + e.anchorRatio.rx * t.width}px`, e.element.style.top = `${t.top + e.anchorRatio.ry * t.height}px`);
|
|
295
|
+
}), this.accumulationId)
|
|
296
|
+
this.refreshAccumulationHighlights();
|
|
297
|
+
else if (this.activeHighlightDotId) {
|
|
298
|
+
const e = this.dots.get(this.activeHighlightDotId);
|
|
299
|
+
e && this.highlightAnnotationElements(e);
|
|
300
|
+
} else this.annotationHighlights.length > 0 && this.pendingHighlightLocators && (this.clearAnnotationHighlightsRaw(), this.highlightLocators(this.pendingHighlightLocators.locators, this.pendingHighlightLocators.showBounding));
|
|
301
|
+
this.repositionHoverOverlay();
|
|
302
|
+
};
|
|
303
|
+
createHitTestOverlay() {
|
|
304
|
+
this.hitTestOverlay || (this.hitTestOverlay = document.createElement("div"), Object.assign(this.hitTestOverlay.style, { position: "fixed", top: "0", left: "0", width: "100%", height: "100%", backgroundColor: "transparent", pointerEvents: "auto", zIndex: C.HIT_TEST_OVERLAY, cursor: "crosshair" }), this.hitTestOverlay.className = "forge-annotation-hit-test", document.body.appendChild(this.hitTestOverlay));
|
|
305
|
+
}
|
|
306
|
+
removeHitTestOverlay() {
|
|
307
|
+
this.hitTestOverlay && (this.hitTestOverlay.remove(), this.hitTestOverlay = null);
|
|
308
|
+
}
|
|
309
|
+
showHoverOverlay(e, t, n) {
|
|
310
|
+
this.hoverOverlay && (this.hoverOverlay.remove(), this.hoverOverlay = null), this.lastHoveredElement = e;
|
|
311
|
+
const o = e.getBoundingClientRect(), i = t === v.ANNOTATION_MULTI ? v.ANNOTATION_MULTI_BG : v.ANNOTATION_SINGLE_BG;
|
|
312
|
+
this.hoverOverlay = x(o, t, i, "solid"), this.hoverOverlay.style.transition = "all 0.05s ease", this.hoverOverlay.className = "forge-annotation-hover", document.body.appendChild(this.hoverOverlay), this.showComponentTooltip(n || e, o);
|
|
313
|
+
}
|
|
314
|
+
removeHoverOverlay() {
|
|
315
|
+
this.hoverOverlay && (this.hoverOverlay.remove(), this.hoverOverlay = null), this.lastHoveredElement = null, this.removeComponentTooltip();
|
|
316
|
+
}
|
|
317
|
+
repositionHoverOverlay() {
|
|
318
|
+
if (!this.hoverOverlay || !this.lastHoveredElement) return;
|
|
319
|
+
if (!this.lastHoveredElement.isConnected) {
|
|
320
|
+
this.removeHoverOverlay();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const e = this.lastHoveredElement.getBoundingClientRect();
|
|
324
|
+
Object.assign(this.hoverOverlay.style, { left: `${e.left}px`, top: `${e.top}px`, width: `${e.width}px`, height: `${e.height}px` });
|
|
325
|
+
}
|
|
326
|
+
highlightAnnotationElements(e) {
|
|
327
|
+
this.clearAnnotationHighlights(), this.activeHighlightDotId = e.id, this.applySelectedStyle(e), this.highlightLocators(e.locators, e.mode === "multi");
|
|
328
|
+
}
|
|
329
|
+
applySelectedStyle(e) {
|
|
330
|
+
e.element.style.backgroundColor = "#0038AE", e.element.style.borderColor = "#0038AE", e.element.style.color = "#FFFFFF";
|
|
331
|
+
}
|
|
332
|
+
applyDefaultStyle(e) {
|
|
333
|
+
e.element.style.backgroundColor = "#FFFFFF", e.element.style.borderColor = "#1A58D0", e.element.style.color = "#1A58D0";
|
|
334
|
+
}
|
|
335
|
+
resolveLocator(e) {
|
|
336
|
+
if (e.forgeId) {
|
|
337
|
+
const t = document.querySelectorAll(`[data-forge-id="${e.forgeId}"]`);
|
|
338
|
+
if (t.length === 1) return t[0];
|
|
339
|
+
if (t.length > 1 && e.forgeIdIndex != null && e.forgeIdIndex < t.length)
|
|
340
|
+
return t[e.forgeIdIndex];
|
|
341
|
+
t.length > 1 && c("annotation", `Multiple elements with forge-id "${e.forgeId}", falling back to xpath`), t.length === 0 && c("annotation", `No element with forge-id "${e.forgeId}", falling back to xpath`);
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
return document.evaluate(e.xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
|
345
|
+
} catch {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
highlightLocators(e, t) {
|
|
350
|
+
this.pendingHighlightLocators = { locators: e, showBounding: t };
|
|
351
|
+
const n = [];
|
|
352
|
+
for (const o of e) {
|
|
353
|
+
const i = this.resolveLocator(o);
|
|
354
|
+
if (i) {
|
|
355
|
+
const s = i.getBoundingClientRect();
|
|
356
|
+
n.push(s);
|
|
357
|
+
const a = x(s, v.ANNOTATION_SINGLE, v.ANNOTATION_SINGLE_BG, "solid");
|
|
358
|
+
a.className = "forge-annotation-highlight", document.body.appendChild(a), this.annotationHighlights.push(a);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (t && n.length > 1) {
|
|
362
|
+
const o = Math.min(...n.map((d) => d.left)), i = Math.min(...n.map((d) => d.top)), s = Math.max(...n.map((d) => d.right)), a = Math.max(...n.map((d) => d.bottom)), l = new DOMRect(o, i, s - o, a - i), h = x(l, v.ANNOTATION_SINGLE, "transparent", "dashed");
|
|
363
|
+
h.className = "forge-annotation-bounding-rect", document.body.appendChild(h), this.annotationHighlights.push(h);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
clearAnnotationHighlightsRaw() {
|
|
367
|
+
for (const e of this.annotationHighlights) e.remove();
|
|
368
|
+
this.annotationHighlights = [];
|
|
369
|
+
}
|
|
370
|
+
clearAnnotationHighlights() {
|
|
371
|
+
if (this.activeHighlightDotId) {
|
|
372
|
+
const e = this.dots.get(this.activeHighlightDotId);
|
|
373
|
+
e && this.applyDefaultStyle(e);
|
|
374
|
+
}
|
|
375
|
+
this.clearAnnotationHighlightsRaw(), this.activeHighlightDotId = null, this.pendingHighlightLocators = null;
|
|
376
|
+
}
|
|
377
|
+
getAnchorRect(e) {
|
|
378
|
+
let t = 1 / 0, n = 1 / 0, o = -1 / 0, i = -1 / 0, s = !1;
|
|
379
|
+
for (const a of e) {
|
|
380
|
+
const l = this.resolveLocator(a);
|
|
381
|
+
if (l) {
|
|
382
|
+
const h = l.getBoundingClientRect();
|
|
383
|
+
t = Math.min(t, h.left), n = Math.min(n, h.top), o = Math.max(o, h.right), i = Math.max(i, h.bottom), s = !0;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return s ? new DOMRect(t, n, o - t, i - n) : null;
|
|
387
|
+
}
|
|
388
|
+
getComponentPath(e) {
|
|
389
|
+
const t = [], n = /* @__PURE__ */ new Set();
|
|
390
|
+
let o = e;
|
|
391
|
+
for (; o; ) {
|
|
392
|
+
const a = o.getAttribute("data-component");
|
|
393
|
+
a && !n.has(a) && (n.add(a), t.push(a)), o = o.parentElement;
|
|
394
|
+
}
|
|
395
|
+
const i = ne(e), s = [...t];
|
|
396
|
+
if (i.components.length > 0)
|
|
397
|
+
for (const a of i.components)
|
|
398
|
+
n.has(a) || (n.add(a), s.push(a));
|
|
399
|
+
if (s.length !== 0)
|
|
400
|
+
return s.reverse();
|
|
401
|
+
}
|
|
402
|
+
showComponentTooltip(e, t) {
|
|
403
|
+
this.removeComponentTooltip();
|
|
404
|
+
const n = this.getComponentPath(e);
|
|
405
|
+
if (!n) return;
|
|
406
|
+
const o = document.createElement("div");
|
|
407
|
+
Object.assign(o.style, { position: "fixed", zIndex: C.TOOLTIP, backgroundColor: "rgba(30, 30, 30, 0.92)", color: "#e4e4e7", padding: "4px 10px", borderRadius: "6px", fontSize: "11px", fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif", fontWeight: "500", letterSpacing: "0.3px", whiteSpace: "nowrap", pointerEvents: "none", backdropFilter: "blur(8px)", boxShadow: "0 2px 8px rgba(0,0,0,0.3)", transition: "opacity 0.1s ease" }), o.textContent = n.map((l) => `<${l}>`).join(" "), o.className = "forge-annotation-component-tooltip", document.body.appendChild(o);
|
|
408
|
+
const i = o.getBoundingClientRect();
|
|
409
|
+
let s = t.left + t.width / 2 - i.width / 2, a = t.top - i.height - 6;
|
|
410
|
+
s < 4 && (s = 4), s + i.width > window.innerWidth - 4 && (s = window.innerWidth - i.width - 4), a < 4 && (a = t.bottom + 6), o.style.left = `${s}px`, o.style.top = `${a}px`, this.componentTooltip = o;
|
|
411
|
+
}
|
|
412
|
+
removeComponentTooltip() {
|
|
413
|
+
this.componentTooltip && (this.componentTooltip.remove(), this.componentTooltip = null);
|
|
414
|
+
}
|
|
415
|
+
showDragRect(e, t, n, o) {
|
|
416
|
+
this.dragRect || (this.dragRect = document.createElement("div"), Object.assign(this.dragRect.style, { position: "fixed", border: `1px dashed ${v.ANNOTATION_MULTI}`, backgroundColor: v.DRAG_RECT_BG, pointerEvents: "none", zIndex: C.HOVER_OVERLAY, borderRadius: "4px" }), this.dragRect.className = "forge-annotation-drag-rect", document.body.appendChild(this.dragRect)), Object.assign(this.dragRect.style, { left: `${Math.min(e, n)}px`, top: `${Math.min(t, o)}px`, width: `${Math.abs(n - e)}px`, height: `${Math.abs(o - t)}px` });
|
|
417
|
+
}
|
|
418
|
+
removeDragRect() {
|
|
419
|
+
this.dragRect && (this.dragRect.remove(), this.dragRect = null), this.clearDragHighlights();
|
|
420
|
+
}
|
|
421
|
+
showDragHighlights(e) {
|
|
422
|
+
this.clearDragHighlights();
|
|
423
|
+
for (const t of e) {
|
|
424
|
+
const n = t.getBoundingClientRect(), o = x(n, v.ANNOTATION_MULTI, v.ANNOTATION_MULTI_BG, "solid");
|
|
425
|
+
o.className = "forge-annotation-drag-highlight", document.body.appendChild(o), this.dragHighlights.push(o);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
clearDragHighlights() {
|
|
429
|
+
for (const e of this.dragHighlights) e.remove();
|
|
430
|
+
this.dragHighlights = [];
|
|
431
|
+
}
|
|
432
|
+
createDot(e, t, n, o, i, s = []) {
|
|
433
|
+
const a = this.getAnchorRect(s), l = e - 2, h = t - M - 2, d = a && a.width > 0 && a.height > 0 ? { rx: (l - a.left) / a.width, ry: (h - a.top) / a.height } : { rx: 0, ry: 0 };
|
|
434
|
+
this.createDotAtPosition(l, h, n, o, i, s, d);
|
|
435
|
+
}
|
|
436
|
+
createDotAtPosition(e, t, n, o, i, s, a) {
|
|
437
|
+
const l = document.createElement("div");
|
|
438
|
+
Object.assign(l.style, { position: "fixed", left: `${e}px`, top: `${t}px`, minWidth: `${B}px`, height: `${M}px`, borderRadius: "50% 50% 50% 0", backgroundColor: "#FFFFFF", border: "1px solid #1A58D0", cursor: "pointer", zIndex: C.ANNOTATION_DOT, transition: "transform 0.15s ease", display: this.markersVisible ? "flex" : "none", alignItems: "center", justifyContent: "center", padding: "0 4px", fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif", fontSize: "11px", fontWeight: "700", color: "#1A58D0", lineHeight: "1", userSelect: "none" }), l.textContent = String(i), l.className = "forge-annotation-dot", l.dataset.annotationId = o, l.addEventListener("mouseenter", () => {
|
|
439
|
+
l.style.transform = "scale(1.05)", this.removeHoverOverlay();
|
|
440
|
+
}), l.addEventListener("mouseleave", () => {
|
|
441
|
+
l.style.transform = "scale(1)";
|
|
442
|
+
}), l.addEventListener("click", (h) => {
|
|
443
|
+
h.stopPropagation(), h.preventDefault(), this.hoverSuppressed = !0, this.removeHoverOverlay();
|
|
444
|
+
const d = this.dots.get(o);
|
|
445
|
+
d && this.highlightAnnotationElements(d);
|
|
446
|
+
const m = l.getBoundingClientRect();
|
|
447
|
+
this.messenger.send({ type: "ANNOTATION_DOT_CLICKED", annotationId: o, dotX: m.left, dotY: m.bottom, origin: O });
|
|
448
|
+
}), document.body.appendChild(l), this.dots.set(o, { id: o, element: l, mode: n, order: i, locators: s, anchorRatio: a });
|
|
449
|
+
}
|
|
450
|
+
updateOrders(e) {
|
|
451
|
+
for (const [t, n] of Object.entries(e)) {
|
|
452
|
+
const o = this.dots.get(t);
|
|
453
|
+
o && (o.order = n, o.element.textContent = String(n));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
elementAtPoint(e, t) {
|
|
457
|
+
this.hitTestOverlay && (this.hitTestOverlay.style.pointerEvents = "none"), this.hoverOverlay && (this.hoverOverlay.style.pointerEvents = "none"), this.dots.forEach((o) => o.element.style.pointerEvents = "none");
|
|
458
|
+
const n = document.elementFromPoint(e, t);
|
|
459
|
+
return this.hitTestOverlay && (this.hitTestOverlay.style.pointerEvents = "auto"), this.hoverOverlay && (this.hoverOverlay.style.pointerEvents = "none"), this.dots.forEach((o) => o.element.style.pointerEvents = "auto"), !n || n === document.body || n === document.documentElement ? null : this.escapeToSvgRoot(n);
|
|
460
|
+
}
|
|
461
|
+
escapeToSvgRoot(e) {
|
|
462
|
+
if (!(e instanceof SVGElement)) return e;
|
|
463
|
+
let t = e;
|
|
464
|
+
for (; t.parentElement; ) {
|
|
465
|
+
if (t.tagName.toLowerCase() === "svg" && !(t.parentElement instanceof SVGElement))
|
|
466
|
+
return t;
|
|
467
|
+
t = t.parentElement;
|
|
468
|
+
}
|
|
469
|
+
return t || e;
|
|
470
|
+
}
|
|
471
|
+
findTopmostWithSameForgeId(e) {
|
|
472
|
+
const t = e.getAttribute("data-forge-id");
|
|
473
|
+
if (!t) return e;
|
|
474
|
+
let n = e, o = e;
|
|
475
|
+
for (; n.parentElement; ) {
|
|
476
|
+
const i = n.parentElement;
|
|
477
|
+
if (i.getAttribute("data-forge-id") !== t) break;
|
|
478
|
+
o = i, n = i;
|
|
479
|
+
}
|
|
480
|
+
return o;
|
|
481
|
+
}
|
|
482
|
+
findForgeIdParent(e) {
|
|
483
|
+
let t = e.parentElement;
|
|
484
|
+
for (; t; ) {
|
|
485
|
+
if (t.getAttribute("data-forge-id")) return t;
|
|
486
|
+
t = t.parentElement;
|
|
487
|
+
}
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
elementsInRect(e, t, n, o) {
|
|
491
|
+
const i = Math.min(e, n), s = Math.min(t, o), a = Math.max(e, n), l = Math.max(t, o), h = document.querySelectorAll("[data-forge-id]"), d = [], m = /* @__PURE__ */ new Set();
|
|
492
|
+
if (h.forEach((p) => {
|
|
493
|
+
const g = p, y = g.getAttribute("data-forge-id");
|
|
494
|
+
if (!y || m.has(y) || g instanceof SVGElement && g.tagName.toLowerCase() !== "svg" || g.closest?.("svg") && g.tagName.toLowerCase() !== "svg") return;
|
|
495
|
+
const f = this.findTopmostWithSameForgeId(g);
|
|
496
|
+
if (m.has(f.getAttribute("data-forge-id") || "")) return;
|
|
497
|
+
const R = f.getBoundingClientRect();
|
|
498
|
+
R.right >= i && R.left <= a && R.bottom >= s && R.top <= l && (m.add(y), d.push(f));
|
|
499
|
+
}), this.dragScopeParent) {
|
|
500
|
+
const p = this.findForgeIdParent(this.dragScopeParent);
|
|
501
|
+
if (p)
|
|
502
|
+
return d.filter((y) => {
|
|
503
|
+
const f = this.findForgeIdParent(y);
|
|
504
|
+
return f ? this.findForgeIdParent(f) === p : !1;
|
|
505
|
+
});
|
|
506
|
+
const g = this.dragScopeParent;
|
|
507
|
+
return d.filter((y) => this.findForgeIdParent(y) === g);
|
|
508
|
+
}
|
|
509
|
+
return d;
|
|
510
|
+
}
|
|
511
|
+
handleMouseMove = (e) => {
|
|
512
|
+
if (this.hoverSuppressed) {
|
|
513
|
+
this.removeHoverOverlay();
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (this.isDragging) {
|
|
517
|
+
this.showDragRect(this.dragStartX, this.dragStartY, e.clientX, e.clientY);
|
|
518
|
+
const n = this.elementsInRect(this.dragStartX, this.dragStartY, e.clientX, e.clientY);
|
|
519
|
+
this.showDragHighlights(n), this.removeHoverOverlay();
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (e.buttons === 1) {
|
|
523
|
+
const n = e.clientX - this.dragStartX, o = e.clientY - this.dragStartY;
|
|
524
|
+
if (Math.abs(n) > D.DRAG_THRESHOLD || Math.abs(o) > D.DRAG_THRESHOLD) {
|
|
525
|
+
this.isDragging = !0;
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
const t = this.elementAtPoint(e.clientX, e.clientY);
|
|
530
|
+
if (t) {
|
|
531
|
+
const n = this.findTopmostWithSameForgeId(t);
|
|
532
|
+
this.showHoverOverlay(n, v.ANNOTATION_SINGLE, t);
|
|
533
|
+
} else
|
|
534
|
+
this.removeHoverOverlay();
|
|
535
|
+
};
|
|
536
|
+
static DRAG_THRESHOLD = 5;
|
|
537
|
+
handleMouseDown = (e) => {
|
|
538
|
+
this.dragStartX = e.clientX, this.dragStartY = e.clientY, this.isDragging = !1;
|
|
539
|
+
const t = this.elementAtPoint(e.clientX, e.clientY);
|
|
540
|
+
if (t) {
|
|
541
|
+
const n = this.findTopmostWithSameForgeId(t);
|
|
542
|
+
this.dragScopeParent = this.findForgeIdParent(n);
|
|
543
|
+
} else
|
|
544
|
+
this.dragScopeParent = null;
|
|
545
|
+
e.preventDefault();
|
|
546
|
+
};
|
|
547
|
+
handleMouseUp = (e) => {
|
|
548
|
+
if (this.isDragging) {
|
|
549
|
+
this.isDragging = !1;
|
|
550
|
+
const o = this.elementsInRect(this.dragStartX, this.dragStartY, e.clientX, e.clientY);
|
|
551
|
+
if (this.dragScopeParent = null, this.removeDragRect(), this.clearDragHighlights(), this.accumulationId && o.length > 0) {
|
|
552
|
+
for (const i of o)
|
|
553
|
+
this.accumulationElements.includes(i) || this.accumulationElements.push(i);
|
|
554
|
+
this.refreshAccumulationHighlights(), this.sendAccumulationUpdate();
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
o.length > 0 && this.createAnnotationFromElements(o, "multi", e.clientX, e.clientY);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const t = this.elementAtPoint(e.clientX, e.clientY);
|
|
561
|
+
if (!t) return;
|
|
562
|
+
const n = this.findTopmostWithSameForgeId(t);
|
|
563
|
+
if (this.accumulationId) {
|
|
564
|
+
const o = this.accumulationElements.indexOf(n);
|
|
565
|
+
o >= 0 ? this.accumulationElements.splice(o, 1) : this.accumulationElements.push(n), this.refreshAccumulationHighlights(), this.sendAccumulationUpdate();
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
this.createAnnotationFromElements([n], "single", e.clientX, e.clientY);
|
|
569
|
+
};
|
|
570
|
+
handleClick = (e) => {
|
|
571
|
+
e.preventDefault(), e.stopPropagation();
|
|
572
|
+
};
|
|
573
|
+
handleKeyDown = (e) => {
|
|
574
|
+
if (e.key === "Escape") {
|
|
575
|
+
if (this.accumulationId) {
|
|
576
|
+
this.accumulationId = null, this.accumulationElements = [], this.clearAnnotationHighlights(), this.hoverSuppressed = !1;
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
this.removeHoverOverlay(), this.removeDragRect(), this.isDragging = !1, this.dragScopeParent = null;
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
handleKeyUp = (e) => {
|
|
583
|
+
};
|
|
584
|
+
pendingAnnotations = /* @__PURE__ */ new Map();
|
|
585
|
+
confirmDot(e, t) {
|
|
586
|
+
const n = this.pendingAnnotations.get(e);
|
|
587
|
+
n && (this.createDot(n.dotX, n.dotY, n.mode, e, t, n.locators), this.pendingAnnotations.delete(e)), this.clearAnnotationHighlights(), this.hoverSuppressed = !1;
|
|
588
|
+
}
|
|
589
|
+
cancelPending(e) {
|
|
590
|
+
const t = this.pendingAnnotations.delete(e), n = this.accumulationId === e, o = this.activeHighlightDotId === e;
|
|
591
|
+
n && (this.accumulationId = null, this.accumulationElements = []), (t || n || o) && this.clearAnnotationHighlights(), this.hoverSuppressed = !1;
|
|
592
|
+
}
|
|
593
|
+
createAnnotationFromElements(e, t, n, o, i) {
|
|
594
|
+
const s = i || ae();
|
|
595
|
+
this.hoverSuppressed = !0, this.removeHoverOverlay();
|
|
596
|
+
const a = e.map((f) => this.elementToInfo(f)), l = a.map((f) => ({ xpath: b(f.xpath), forgeId: f.forgeId, forgeIdIndex: f.forgeIdIndex })), h = this.getAnchorRect(l), d = n - 2, m = o - M - 2, p = h && h.width > 0 && h.height > 0 ? { x: (d - h.left) / h.width, y: (m - h.top) / h.height } : { x: 0, y: 0 };
|
|
597
|
+
this.pendingAnnotations.set(s, { dotX: n, dotY: o, mode: t, locators: l }), this.clearDragHighlights(), this.highlightLocators(l, t === "multi");
|
|
598
|
+
const g = a[0], y = { id: s, dotX: n, dotY: o, anchorOffset: p, mode: t, elements: a, xpaths: a.map((f) => b(f.xpath)), elementTag: g.elementTag, componentName: g.componentName, componentPath: g.componentPath, forgeId: g.forgeId, sourcePos: g.sourcePos };
|
|
599
|
+
c("annotation", "Annotation created (pending):", y), this.messenger.send({ type: "ANNOTATION_CREATED", annotation: y, origin: O });
|
|
600
|
+
}
|
|
601
|
+
handleDocumentLeave = () => {
|
|
602
|
+
this.removeHoverOverlay();
|
|
603
|
+
};
|
|
604
|
+
addListeners() {
|
|
605
|
+
this.hitTestOverlay && (this.hitTestOverlay.addEventListener("mousemove", this.handleMouseMove), this.hitTestOverlay.addEventListener("mousedown", this.handleMouseDown), this.hitTestOverlay.addEventListener("mouseup", this.handleMouseUp), this.hitTestOverlay.addEventListener("click", this.handleClick), document.addEventListener("keydown", this.handleKeyDown), document.addEventListener("keyup", this.handleKeyUp), document.addEventListener("mouseleave", this.handleDocumentLeave));
|
|
606
|
+
}
|
|
607
|
+
removeListeners() {
|
|
608
|
+
this.hitTestOverlay && (this.hitTestOverlay.removeEventListener("mousemove", this.handleMouseMove), this.hitTestOverlay.removeEventListener("mousedown", this.handleMouseDown), this.hitTestOverlay.removeEventListener("mouseup", this.handleMouseUp), this.hitTestOverlay.removeEventListener("click", this.handleClick)), document.removeEventListener("keydown", this.handleKeyDown), document.removeEventListener("keyup", this.handleKeyUp), document.removeEventListener("mouseleave", this.handleDocumentLeave);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
class le {
|
|
612
|
+
messenger;
|
|
613
|
+
callbacks;
|
|
614
|
+
hitTestOverlay = null;
|
|
615
|
+
hoveredElement = null;
|
|
616
|
+
constructor(e, t) {
|
|
617
|
+
this.messenger = e, this.callbacks = t;
|
|
618
|
+
}
|
|
619
|
+
enableListeners() {
|
|
620
|
+
this.hitTestOverlay = ie(), this.hitTestOverlay.addEventListener("mousemove", this.handleMouseOver), this.hitTestOverlay.addEventListener("mouseout", this.handleMouseOut), this.hitTestOverlay.addEventListener("click", this.handleClick), document.addEventListener("scroll", this.handleScroll, !0);
|
|
621
|
+
}
|
|
622
|
+
disableListeners() {
|
|
623
|
+
this.hitTestOverlay && (this.hitTestOverlay.removeEventListener("mousemove", this.handleMouseOver), this.hitTestOverlay.removeEventListener("mouseout", this.handleMouseOut), this.hitTestOverlay.removeEventListener("click", this.handleClick)), document.removeEventListener("scroll", this.handleScroll, !0), se(), this.hitTestOverlay = null;
|
|
624
|
+
}
|
|
625
|
+
clearHover() {
|
|
626
|
+
this.hoveredElement = null, L();
|
|
627
|
+
}
|
|
628
|
+
findTopmostElementWithSameId(e) {
|
|
629
|
+
const t = e.getAttribute("data-forge-id");
|
|
630
|
+
if (!t) return e;
|
|
631
|
+
let n = e, o = e;
|
|
632
|
+
for (; n.parentElement; ) {
|
|
633
|
+
const i = n.parentElement;
|
|
634
|
+
if (i.getAttribute("data-forge-id") !== t) break;
|
|
635
|
+
o = i, n = i;
|
|
636
|
+
}
|
|
637
|
+
return o;
|
|
638
|
+
}
|
|
639
|
+
handleSelectModeClick(e) {
|
|
640
|
+
const t = b(H(e));
|
|
641
|
+
c("client", "Element clicked, XPath:", t), this.messenger.send({ type: "XPATH_REPORT", xpath: t, origin: O }), this.messenger.send({ type: "SELECT_MODE_DISABLED", origin: O });
|
|
642
|
+
}
|
|
643
|
+
handleMouseOver = (e) => {
|
|
644
|
+
if (!this.callbacks.getSelectMode() && !this.callbacks.getDesignMode() || this.callbacks.getHoverDisabled()) return;
|
|
645
|
+
this.hitTestOverlay && (this.hitTestOverlay.style.pointerEvents = "none");
|
|
646
|
+
const t = document.elementFromPoint(e.clientX, e.clientY);
|
|
647
|
+
if (this.hitTestOverlay && (this.hitTestOverlay.style.pointerEvents = "auto"), t && t !== document.body && t !== document.documentElement) {
|
|
648
|
+
const o = t.getAttribute("data-forge-id") ? this.findTopmostElementWithSameId(t) : t;
|
|
649
|
+
if (this.callbacks.getDesignMode() && o === this.callbacks.getSelectedDesignElement())
|
|
650
|
+
return;
|
|
651
|
+
this.hoveredElement = o, oe(o);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
handleMouseOut = (e) => {
|
|
655
|
+
if (!this.callbacks.getSelectMode() && !this.callbacks.getDesignMode()) return;
|
|
656
|
+
e.target === this.hoveredElement && (this.hoveredElement = null, L());
|
|
657
|
+
};
|
|
658
|
+
handleClick = (e) => {
|
|
659
|
+
if (!this.callbacks.getSelectMode() && !this.callbacks.getDesignMode()) return;
|
|
660
|
+
e.preventDefault(), e.stopPropagation(), this.hitTestOverlay && (this.hitTestOverlay.style.pointerEvents = "none");
|
|
661
|
+
const t = document.elementFromPoint(e.clientX, e.clientY);
|
|
662
|
+
this.hitTestOverlay && (this.hitTestOverlay.style.pointerEvents = "auto"), t && t !== document.body && t !== document.documentElement && (this.callbacks.getSelectMode() && this.callbacks.onSelectClick(t), this.callbacks.getDesignMode() && (L(), this.hoveredElement = null, this.callbacks.onDesignClick(t)));
|
|
663
|
+
};
|
|
664
|
+
handleScroll = () => {
|
|
665
|
+
(this.callbacks.getSelectMode() || this.callbacks.getDesignMode()) && (this.hoveredElement = null, L());
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
let w = null, _ = null, P = null;
|
|
669
|
+
async function ce() {
|
|
670
|
+
if (w && _ && P) return;
|
|
671
|
+
const [r, e, t] = await Promise.all([import("@babel/parser"), import("@babel/traverse"), import("@babel/generator")]);
|
|
672
|
+
w = r.parse;
|
|
673
|
+
const n = e.default;
|
|
674
|
+
_ = typeof n == "function" ? n : n.default;
|
|
675
|
+
const o = t.default;
|
|
676
|
+
P = typeof o == "function" ? o : o.default;
|
|
677
|
+
}
|
|
678
|
+
function k(r) {
|
|
679
|
+
return typeof r == "boolean" ? { type: "JSXExpressionContainer", expression: { type: "BooleanLiteral", value: r, loc: null }, loc: null } : typeof r == "number" ? { type: "JSXExpressionContainer", expression: { type: "NumericLiteral", value: r, loc: null }, loc: null } : { type: "StringLiteral", value: String(r), loc: null };
|
|
680
|
+
}
|
|
681
|
+
function F(r, e, t) {
|
|
682
|
+
const n = r.node.attributes.find((o) => o.type === "JSXAttribute" && o.name.type === "JSXIdentifier" && o.name.name === e);
|
|
683
|
+
return n && n.type === "JSXAttribute" ? (n.value = k(t), !0) : (r.node.attributes.push({ type: "JSXAttribute", name: { type: "JSXIdentifier", name: e }, value: k(t), loc: null }), !0);
|
|
684
|
+
}
|
|
685
|
+
async function he(r, e, t, n, o) {
|
|
686
|
+
try {
|
|
687
|
+
if (await ce(), !w || !_ || !P) return r;
|
|
688
|
+
const i = w(r, { sourceType: "module", plugins: ["jsx", "typescript"] });
|
|
689
|
+
let s = !1;
|
|
690
|
+
const a = /* @__PURE__ */ new Map();
|
|
691
|
+
if (_(i, { JSXOpeningElement(l) {
|
|
692
|
+
if (l.node.name.type !== "JSXIdentifier") return;
|
|
693
|
+
const h = l.node.loc;
|
|
694
|
+
if (!h) return;
|
|
695
|
+
const d = `${h.start.line}:${h.start.column}`;
|
|
696
|
+
a.set(d, l);
|
|
697
|
+
const m = l.node.attributes.find((p) => p.type === "JSXAttribute" && p.name.type === "JSXIdentifier" && p.name.name === "data-forge-id" && p.value?.type === "StringLiteral");
|
|
698
|
+
m && m.type === "JSXAttribute" && m.value.value === e && (s = F(l, t, n));
|
|
699
|
+
} }), !s && o) {
|
|
700
|
+
const l = o.split(":");
|
|
701
|
+
if (l.length >= 5) {
|
|
702
|
+
const h = `${l[l.length - 4]}:${l[l.length - 3]}`, d = a.get(h);
|
|
703
|
+
d && (s = F(d, t, n));
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (s)
|
|
707
|
+
return P(i, {}, r).code;
|
|
708
|
+
} catch (i) {
|
|
709
|
+
c("client", "Failed to parse/update AST:", i);
|
|
710
|
+
}
|
|
711
|
+
return r;
|
|
712
|
+
}
|
|
713
|
+
async function de(r) {
|
|
714
|
+
try {
|
|
715
|
+
const e = await fetch(`/__forge-read-source?path=${r}`);
|
|
716
|
+
if (e.ok)
|
|
717
|
+
return await e.text();
|
|
718
|
+
c("client", `Failed to fetch source for ${r}: ${e.status}`);
|
|
719
|
+
} catch (e) {
|
|
720
|
+
c("client", "Failed to fetch source:", e);
|
|
721
|
+
}
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
async function ue(r, e) {
|
|
725
|
+
try {
|
|
726
|
+
return await fetch("/__forge-update-source", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ filePath: r, source: e }) }), !0;
|
|
727
|
+
} catch (t) {
|
|
728
|
+
return c("client", "Failed to write source:", t), !1;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
class ge {
|
|
732
|
+
messenger;
|
|
733
|
+
componentRegistry;
|
|
734
|
+
selectController;
|
|
735
|
+
selectedElement = null;
|
|
736
|
+
sourceCache = /* @__PURE__ */ new Map();
|
|
737
|
+
constructor(e, t, n) {
|
|
738
|
+
this.messenger = e, this.componentRegistry = t, this.selectController = n;
|
|
739
|
+
}
|
|
740
|
+
getSelectedElement() {
|
|
741
|
+
return this.selectedElement;
|
|
742
|
+
}
|
|
743
|
+
clearSelection() {
|
|
744
|
+
this.selectedElement && (this.removeHighlight(this.selectedElement), this.selectedElement = null);
|
|
745
|
+
}
|
|
746
|
+
handleClick(e) {
|
|
747
|
+
const t = e.getAttribute("data-forge-id");
|
|
748
|
+
if (!t) {
|
|
749
|
+
c("client", "Clicked element has no data-forge-id");
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
const n = this.selectController.findTopmostElementWithSameId(e), o = n.getAttribute("data-component"), i = n.getAttribute("data-source-pos"), s = o || n.tagName.toLowerCase();
|
|
753
|
+
this.clearSelection(), this.selectedElement = n, this.applyHighlight(n);
|
|
754
|
+
const a = n.textContent?.trim() || "", l = n.tagName.toLowerCase(), h = b(H(n)), d = this.componentRegistry.getEditableProps(s), m = this.extractPropValues(n, d);
|
|
755
|
+
c("client", "Element selected in design mode:", { forgeId: t, sourcePos: i, text: a, type: l, componentName: s, editableProps: d, propValues: m }), this.messenger.send({ type: "ELEMENT_SELECTED", forgeId: t, sourcePos: i || void 0, text: a, elementType: l, xpath: h, componentName: s, editableProps: d, propValues: m, origin: O });
|
|
756
|
+
}
|
|
757
|
+
updateText(e, t) {
|
|
758
|
+
this.updateProperty(e, "children", t);
|
|
759
|
+
}
|
|
760
|
+
async updateProperty(e, t, n) {
|
|
761
|
+
const o = document.querySelector(`[data-forge-id="${e}"]`);
|
|
762
|
+
if (!o) {
|
|
763
|
+
c("client", `Element with forge ID ${e} not found`);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
const i = o.getAttribute("data-source-pos");
|
|
767
|
+
if (!i) {
|
|
768
|
+
c("client", `Element ${e} missing data-source-pos attribute`);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
const s = i.split(":");
|
|
772
|
+
if (s.length < 5) {
|
|
773
|
+
c("client", `Invalid data-source-pos format: ${i}`);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
const a = s.slice(0, -4).join(":");
|
|
777
|
+
c("client", `Updating property ${t} = ${n} for ${e} in ${a}`), this.sourceCache.delete(a);
|
|
778
|
+
const l = await de(a);
|
|
779
|
+
if (!l) return;
|
|
780
|
+
this.sourceCache.set(a, l);
|
|
781
|
+
const h = this.selectedElement?.getAttribute("data-source-pos") ?? null, d = await he(l, e, t, n, h);
|
|
782
|
+
d !== l ? (this.sourceCache.set(a, d), c("client", `Updated source for ${a}`), await ue(a, d) && (c("client", `Source written to disk and HMR triggered for ${a}`), this.messenger.send({ type: "SOURCE_UPDATED", forgeId: e, source: d, filePath: a, origin: O }))) : c("client", `No source changes detected for ${a}`);
|
|
783
|
+
}
|
|
784
|
+
applyHighlight(e) {
|
|
785
|
+
e.style.outline = `3px solid ${v.DESIGN_SELECTION_OUTLINE}`, e.style.outlineOffset = "2px";
|
|
786
|
+
}
|
|
787
|
+
removeHighlight(e) {
|
|
788
|
+
e.style.outline = "", e.style.outlineOffset = "";
|
|
789
|
+
}
|
|
790
|
+
extractPropValues(e, t) {
|
|
791
|
+
const n = this.getFiberFromElement(e);
|
|
792
|
+
if (!n) return {};
|
|
793
|
+
let o = n;
|
|
794
|
+
for (; o; ) {
|
|
795
|
+
if (o.memoizedProps && o.type && typeof o.type != "string") {
|
|
796
|
+
const i = o.memoizedProps, s = {};
|
|
797
|
+
for (const a of t) {
|
|
798
|
+
const l = a.name;
|
|
799
|
+
l === "children" ? s[l] = i.children || e.textContent?.trim() || "" : l in i && (s[l] = i[l]);
|
|
800
|
+
}
|
|
801
|
+
return c("client", "Extracted prop values:", s), s;
|
|
802
|
+
}
|
|
803
|
+
o = o.return;
|
|
804
|
+
}
|
|
805
|
+
return {};
|
|
806
|
+
}
|
|
807
|
+
getFiberFromElement(e) {
|
|
808
|
+
const t = Object.keys(e).find((n) => n.startsWith("__reactFiber") || n.startsWith("__reactInternalInstance"));
|
|
809
|
+
return t ? e[t] : null;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
class I {
|
|
813
|
+
static instance = null;
|
|
814
|
+
messenger;
|
|
815
|
+
selectMode = !1;
|
|
816
|
+
designMode = !1;
|
|
817
|
+
hoverDisabled = !1;
|
|
818
|
+
componentRegistry;
|
|
819
|
+
annotationOverlay = null;
|
|
820
|
+
selectController;
|
|
821
|
+
designController;
|
|
822
|
+
onError;
|
|
823
|
+
constructor(e) {
|
|
824
|
+
this.onError = e?.onError, c("client", "ForgeClient initialized"), this.messenger = new G(), this.componentRegistry = new z(), this.selectController = new le(this.messenger, { getSelectMode: () => this.selectMode, getDesignMode: () => this.designMode, getHoverDisabled: () => this.hoverDisabled, getSelectedDesignElement: () => this.designController.getSelectedElement(), onSelectClick: (t) => this.handleSelectClick(t), onDesignClick: (t) => this.handleDesignClick(t) }), this.designController = new ge(this.messenger, this.componentRegistry, this.selectController), this.setupMessageListener(), this.sendReady(), this.setupForgeIdPropagation(), window.__forgeClient = this;
|
|
825
|
+
}
|
|
826
|
+
static getInstance(e) {
|
|
827
|
+
return I.instance || (I.instance = new I(e)), I.instance;
|
|
828
|
+
}
|
|
829
|
+
enableAnnotationMode(e) {
|
|
830
|
+
this.setAnnotationMode(e);
|
|
831
|
+
}
|
|
832
|
+
restoreAnnotations(e) {
|
|
833
|
+
this.annotationOverlay || (this.annotationOverlay = new D(this.messenger)), this.annotationOverlay.restoreDots(e);
|
|
834
|
+
}
|
|
835
|
+
setupMessageListener() {
|
|
836
|
+
c("client", "Setting up message listener..."), this.messenger.onMessage((e) => {
|
|
837
|
+
if (W(e.data) || !e.data || typeof e.data != "object" || !("origin" in e.data)) return;
|
|
838
|
+
const t = e.data;
|
|
839
|
+
if (t.origin === V) {
|
|
840
|
+
c("client", "Received message from host:", t);
|
|
841
|
+
try {
|
|
842
|
+
switch (t.type) {
|
|
843
|
+
case "ENABLE_SELECT_MODE":
|
|
844
|
+
this.setSelectMode(t.enabled);
|
|
845
|
+
break;
|
|
846
|
+
case "ENABLE_DESIGN_MODE":
|
|
847
|
+
this.setDesignMode(t.enabled);
|
|
848
|
+
break;
|
|
849
|
+
case "UPDATE_TEXT":
|
|
850
|
+
this.designController.updateText(t.forgeId, t.text);
|
|
851
|
+
break;
|
|
852
|
+
case "UPDATE_PROPERTY":
|
|
853
|
+
this.designController.updateProperty(t.forgeId, t.propName, t.value);
|
|
854
|
+
break;
|
|
855
|
+
case "ENABLE_ANNOTATION_MODE":
|
|
856
|
+
this.setAnnotationMode(t.enabled);
|
|
857
|
+
break;
|
|
858
|
+
case "ANNOTATION_DELETED":
|
|
859
|
+
this.annotationOverlay?.cancelPending(t.annotationId), this.annotationOverlay?.removeDot(t.annotationId);
|
|
860
|
+
break;
|
|
861
|
+
case "ANNOTATION_KEEP":
|
|
862
|
+
this.annotationOverlay?.confirmDot(t.annotationId, t.order);
|
|
863
|
+
break;
|
|
864
|
+
case "SELECT_ANNOTATION":
|
|
865
|
+
this.annotationOverlay?.selectDot(t.annotationId);
|
|
866
|
+
break;
|
|
867
|
+
case "ENTER_ACCUMULATION":
|
|
868
|
+
this.annotationOverlay && this.annotationOverlay.enterAccumulation(t.annotationId, t.elements);
|
|
869
|
+
break;
|
|
870
|
+
case "EXIT_ACCUMULATION":
|
|
871
|
+
this.annotationOverlay?.exitAccumulation();
|
|
872
|
+
break;
|
|
873
|
+
case "ANNOTATION_UPDATE_ORDERS":
|
|
874
|
+
this.annotationOverlay?.updateOrders(t.orders);
|
|
875
|
+
break;
|
|
876
|
+
case "DESELECT_ELEMENT":
|
|
877
|
+
this.designController.clearSelection();
|
|
878
|
+
break;
|
|
879
|
+
case "TOGGLE_MARKERS":
|
|
880
|
+
this.annotationOverlay?.toggleMarkers();
|
|
881
|
+
break;
|
|
882
|
+
case "RESTORE_ANNOTATIONS":
|
|
883
|
+
this.annotationOverlay || (this.annotationOverlay = new D(this.messenger)), this.annotationOverlay.restoreDots(t.annotations);
|
|
884
|
+
break;
|
|
885
|
+
case "PING":
|
|
886
|
+
c("client", "Received PING");
|
|
887
|
+
break;
|
|
888
|
+
}
|
|
889
|
+
} catch (n) {
|
|
890
|
+
c("client", "Error handling message:", t.type, n), this.onError?.(n instanceof Error ? n : new Error(String(n)));
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
setSelectMode(e) {
|
|
896
|
+
this.selectMode !== e && (c("client", `Setting select mode to: ${e}`), this.selectMode = e, e ? (this.selectController.enableListeners(), document.body.style.cursor = "crosshair") : (this.selectController.disableListeners(), document.body.style.cursor = "", this.selectController.clearHover()));
|
|
897
|
+
}
|
|
898
|
+
setDesignMode(e) {
|
|
899
|
+
this.designMode !== e && (c("client", `Setting design mode to: ${e}`), this.designMode = e, e ? (this.selectController.enableListeners(), this.hoverDisabled = !1, document.body.style.cursor = "crosshair") : (this.selectController.disableListeners(), this.hoverDisabled = !1, document.body.style.cursor = "", this.selectController.clearHover()));
|
|
900
|
+
}
|
|
901
|
+
setAnnotationMode(e) {
|
|
902
|
+
e ? (this.annotationOverlay || (this.annotationOverlay = new D(this.messenger)), this.setSelectMode(!1), this.setDesignMode(!1), this.annotationOverlay.activate()) : this.annotationOverlay?.deactivate();
|
|
903
|
+
}
|
|
904
|
+
handleSelectClick(e) {
|
|
905
|
+
this.selectController.handleSelectModeClick(e), this.setSelectMode(!1);
|
|
906
|
+
}
|
|
907
|
+
handleDesignClick(e) {
|
|
908
|
+
this.designController.handleClick(e), this.setDesignMode(!1);
|
|
909
|
+
}
|
|
910
|
+
sendReady() {
|
|
911
|
+
c("client", "Scheduling CHILD_READY message..."), setTimeout(() => {
|
|
912
|
+
c("client", "Sending CHILD_READY message to parent"), this.messenger.send({ type: "CHILD_READY", origin: O });
|
|
913
|
+
}, j.CHILD_READY_DELAY);
|
|
914
|
+
}
|
|
915
|
+
setupForgeIdPropagation() {
|
|
916
|
+
const e = () => {
|
|
917
|
+
document.querySelectorAll("*").forEach((n) => {
|
|
918
|
+
const o = this.getFiberFromElement(n);
|
|
919
|
+
o && this.propagateForgeIdFromFiber(o, n);
|
|
920
|
+
});
|
|
921
|
+
};
|
|
922
|
+
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", e) : e(), new MutationObserver(() => e()).observe(document.body, { childList: !0, subtree: !0 });
|
|
923
|
+
}
|
|
924
|
+
getFiberFromElement(e) {
|
|
925
|
+
const t = Object.keys(e).find((n) => n.startsWith("__reactFiber") || n.startsWith("__reactInternalInstance"));
|
|
926
|
+
return t ? e[t] : null;
|
|
927
|
+
}
|
|
928
|
+
propagateForgeIdFromFiber(e, t) {
|
|
929
|
+
let n = e;
|
|
930
|
+
for (; n; ) {
|
|
931
|
+
if (n.memoizedProps) {
|
|
932
|
+
const o = n.memoizedProps["data-forge-id"], i = n.memoizedProps["data-component"], s = n.memoizedProps["data-source-pos"];
|
|
933
|
+
if (o && !t.getAttribute("data-forge-id")) {
|
|
934
|
+
t.setAttribute("data-forge-id", o), i && t.setAttribute("data-component", i), s && t.setAttribute("data-source-pos", s);
|
|
935
|
+
break;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
n = n.return;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
I.getInstance();
|
|
943
|
+
export {
|
|
944
|
+
I as ForgeClient,
|
|
945
|
+
G as ParentMessenger
|
|
946
|
+
};
|