@vibexdotnew/inspector 0.0.1 → 0.0.2

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,1018 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/expo/index.ts
22
+ var expo_exports = {};
23
+ __export(expo_exports, {
24
+ ErrorBoundary: () => ErrorBoundary,
25
+ VisualInspector: () => VisualInspector,
26
+ transformerPath: () => transformerPath,
27
+ withInspector: () => withInspector
28
+ });
29
+ module.exports = __toCommonJS(expo_exports);
30
+
31
+ // src/expo/components/VisualInspector.tsx
32
+ var import_react = require("react");
33
+ var import_react_native = require("react-native");
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var CHANNEL = "VIBEX_INSPECTOR";
36
+ var STORAGE_KEY = "vibex_inspector_active";
37
+ var SELECTED_KEY = "vibex_selected_element";
38
+ var DATA_ATTR = "data-vibex-loc";
39
+ var OVERLAY_PADDING = 4;
40
+ var MAX_SELECTIONS = 5;
41
+ var isEmbedded = () => {
42
+ if (import_react_native.Platform.OS !== "web" || typeof window === "undefined") return false;
43
+ try {
44
+ return window.self !== window.top;
45
+ } catch {
46
+ return true;
47
+ }
48
+ };
49
+ var emit = /* @__PURE__ */ (() => {
50
+ let lastPayload = "";
51
+ return (msg) => {
52
+ if (import_react_native.Platform.OS !== "web" || typeof window === "undefined") return;
53
+ const json = JSON.stringify(msg);
54
+ if (json === lastPayload) return;
55
+ lastPayload = json;
56
+ window.parent.postMessage(msg, "*");
57
+ };
58
+ })();
59
+ var padRect = (r) => ({
60
+ top: r.top - OVERLAY_PADDING,
61
+ left: r.left - OVERLAY_PADDING,
62
+ width: r.width + OVERLAY_PADDING * 2,
63
+ height: r.height + OVERLAY_PADDING * 2
64
+ });
65
+ var parseLocation = (id) => {
66
+ const parts = id.split(":");
67
+ if (parts.length < 3) return null;
68
+ const col = parseInt(parts.pop(), 10);
69
+ const line = parseInt(parts.pop(), 10);
70
+ const file = parts.join(":");
71
+ if (isNaN(line) || isNaN(col)) return null;
72
+ return { file, line, col };
73
+ };
74
+ var normalizeStyleValue = (prop, val) => {
75
+ if (prop === "backgroundColor" && (val === "rgba(0, 0, 0, 0)" || val === "transparent")) return "transparent";
76
+ if (prop === "backgroundImage" && val === "none") return "none";
77
+ if (prop === "textDecoration" && val.includes("none")) return "none";
78
+ if (prop === "fontStyle" && val === "normal") return "normal";
79
+ if (prop === "opacity" && val === "1") return "1";
80
+ if ((prop.includes("padding") || prop.includes("margin")) && (val === "0px" || val === "0")) return "0";
81
+ if (prop === "borderRadius" && val === "0px") return "0";
82
+ if (prop === "letterSpacing" && (val === "normal" || val === "0px")) return "normal";
83
+ if (prop === "gap" && (val === "normal" || val === "0px")) return "0";
84
+ return val;
85
+ };
86
+ var getComputedStyles = (el) => {
87
+ const cs = window.getComputedStyle(el);
88
+ const get = (p) => normalizeStyleValue(p, cs.getPropertyValue(p.replace(/([A-Z])/g, "-$1").toLowerCase()));
89
+ return {
90
+ fontSize: get("fontSize"),
91
+ color: get("color"),
92
+ fontWeight: get("fontWeight"),
93
+ fontFamily: get("fontFamily"),
94
+ fontStyle: get("fontStyle"),
95
+ textAlign: get("textAlign"),
96
+ textDecoration: get("textDecoration"),
97
+ lineHeight: get("lineHeight"),
98
+ letterSpacing: get("letterSpacing"),
99
+ backgroundColor: get("backgroundColor"),
100
+ backgroundImage: get("backgroundImage"),
101
+ borderRadius: get("borderRadius"),
102
+ opacity: get("opacity"),
103
+ padding: `${get("paddingTop")} ${get("paddingRight")} ${get("paddingBottom")} ${get("paddingLeft")}`,
104
+ margin: `${get("marginTop")} ${get("marginRight")} ${get("marginBottom")} ${get("marginLeft")}`,
105
+ display: get("display"),
106
+ flexDirection: get("flexDirection"),
107
+ alignItems: get("alignItems"),
108
+ justifyContent: get("justifyContent"),
109
+ gap: get("gap"),
110
+ width: get("width"),
111
+ height: get("height")
112
+ };
113
+ };
114
+ var canEditText = (el) => {
115
+ const tag = el.tagName.toLowerCase();
116
+ const editableTags = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "span", "div", "li", "a", "button", "label", "td", "th"];
117
+ if (el.contentEditable === "true" || tag === "input" || tag === "textarea") return true;
118
+ if (!editableTags.includes(tag) || !el.textContent?.trim()) return false;
119
+ const hasDirectText = Array.from(el.childNodes).some((n) => n.nodeType === Node.TEXT_NODE && n.textContent?.trim());
120
+ return el.childElementCount === 0 || el.childElementCount <= 1 && hasDirectText;
121
+ };
122
+ var getDirectText = (el) => {
123
+ let txt = "";
124
+ for (const n of el.childNodes) {
125
+ if (n.nodeType === Node.TEXT_NODE) txt += n.textContent || "";
126
+ }
127
+ return txt;
128
+ };
129
+ var normalizeImgSrc = (src) => {
130
+ if (!src) return "";
131
+ try {
132
+ const url = new URL(src, location.origin);
133
+ return url.href;
134
+ } catch {
135
+ return src;
136
+ }
137
+ };
138
+ var initialState = {
139
+ active: false,
140
+ hoveredId: null,
141
+ hoveredRect: null,
142
+ hoveredTag: null,
143
+ selectedElements: [],
144
+ isScrolling: false,
145
+ isResizing: false,
146
+ resizeHandle: null
147
+ };
148
+ function reducer(state, action) {
149
+ switch (action.type) {
150
+ case "SET_ACTIVE":
151
+ return { ...state, active: action.value };
152
+ case "SET_HOVER":
153
+ return { ...state, hoveredId: action.id, hoveredRect: action.rect, hoveredTag: action.tag };
154
+ case "ADD_SELECTED":
155
+ return { ...state, selectedElements: [...state.selectedElements, action.selected] };
156
+ case "CLEAR_SELECTIONS":
157
+ return { ...state, selectedElements: [] };
158
+ case "UPDATE_SELECTED_RECTS":
159
+ return {
160
+ ...state,
161
+ selectedElements: state.selectedElements.map((sel) => ({
162
+ ...sel,
163
+ rect: padRect(sel.element.getBoundingClientRect())
164
+ }))
165
+ };
166
+ case "SET_SCROLLING":
167
+ return { ...state, isScrolling: action.value };
168
+ case "SET_RESIZING":
169
+ return { ...state, isResizing: action.value, resizeHandle: action.handle };
170
+ case "CLEAR_HOVER":
171
+ return { ...state, hoveredId: null, hoveredRect: null, hoveredTag: null };
172
+ default:
173
+ return state;
174
+ }
175
+ }
176
+ function VisualInspector() {
177
+ const [state, dispatch2] = (0, import_react.useReducer)(reducer, initialState, (init) => {
178
+ if (import_react_native.Platform.OS === "web" && typeof window !== "undefined") {
179
+ try {
180
+ const stored = localStorage.getItem(STORAGE_KEY);
181
+ return { ...init, active: stored === "true" };
182
+ } catch {
183
+ return init;
184
+ }
185
+ }
186
+ return init;
187
+ });
188
+ const activeRef = (0, import_react.useRef)(state.active);
189
+ const selectedElRef = (0, import_react.useRef)(null);
190
+ const editingElRef = (0, import_react.useRef)(null);
191
+ const originalTextRef = (0, import_react.useRef)("");
192
+ const originalSrcRef = (0, import_react.useRef)("");
193
+ const appliedStylesRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
194
+ const scrollTimeoutRef = (0, import_react.useRef)(null);
195
+ const resizeStartRef = (0, import_react.useRef)(null);
196
+ (0, import_react.useEffect)(() => {
197
+ activeRef.current = state.active;
198
+ if (import_react_native.Platform.OS === "web" && typeof window !== "undefined") {
199
+ try {
200
+ localStorage.setItem(STORAGE_KEY, String(state.active));
201
+ } catch {
202
+ }
203
+ }
204
+ emit({ channel: CHANNEL, event: "MODE_CHANGED", active: state.active });
205
+ }, [state.active]);
206
+ (0, import_react.useEffect)(() => {
207
+ if (!isEmbedded()) return;
208
+ emit({ channel: CHANNEL, event: "READY" });
209
+ if (state.active) {
210
+ emit({ channel: CHANNEL, event: "MODE_CHANGED", active: true });
211
+ }
212
+ }, []);
213
+ const buildElementInfo = (0, import_react.useCallback)((el) => {
214
+ const id = el.getAttribute(DATA_ATTR) || "";
215
+ const tag = el.getAttribute("data-vibex-name") || el.tagName.toLowerCase();
216
+ const rect = padRect(el.getBoundingClientRect());
217
+ const editable = canEditText(el);
218
+ const styles3 = getComputedStyles(el);
219
+ const className = el.className || "";
220
+ const src = el.tagName.toLowerCase() === "img" ? el.src : void 0;
221
+ return { id, tag, rect, editable, styles: styles3, className, src };
222
+ }, []);
223
+ const handleSelect = (0, import_react.useCallback)((el, clickPos, currentSelections) => {
224
+ const info = buildElementInfo(el);
225
+ if (currentSelections.some((s) => s.id === info.id)) {
226
+ return;
227
+ }
228
+ if (currentSelections.length >= MAX_SELECTIONS) {
229
+ return;
230
+ }
231
+ selectedElRef.current = el;
232
+ const selected = {
233
+ id: info.id,
234
+ rect: info.rect,
235
+ tag: info.tag,
236
+ element: el
237
+ };
238
+ dispatch2({ type: "ADD_SELECTED", selected });
239
+ dispatch2({ type: "CLEAR_HOVER" });
240
+ const allSelected = [...currentSelections, selected];
241
+ const allInfos = allSelected.map((s) => buildElementInfo(s.element));
242
+ if (import_react_native.Platform.OS === "web" && typeof window !== "undefined") {
243
+ try {
244
+ localStorage.setItem(SELECTED_KEY, JSON.stringify({ ids: allSelected.map((s) => s.id) }));
245
+ } catch {
246
+ }
247
+ }
248
+ emit({ channel: CHANNEL, event: "SELECT", elements: allInfos, position: clickPos });
249
+ if (info.editable && el.contentEditable !== "true") {
250
+ originalTextRef.current = el.childElementCount > 0 ? getDirectText(el) : el.innerText;
251
+ el.contentEditable = "true";
252
+ editingElRef.current = el;
253
+ el.querySelectorAll("*").forEach((child) => {
254
+ child.contentEditable = "false";
255
+ });
256
+ }
257
+ if (el.tagName.toLowerCase() === "img") {
258
+ originalSrcRef.current = normalizeImgSrc(el.src);
259
+ }
260
+ }, [buildElementInfo]);
261
+ const cleanupEditing = (0, import_react.useCallback)(() => {
262
+ const el = editingElRef.current;
263
+ if (!el) return;
264
+ const id = el.getAttribute(DATA_ATTR);
265
+ if (!id) return;
266
+ const newText = el.childElementCount > 0 ? getDirectText(el) : el.innerText;
267
+ if (newText !== originalTextRef.current) {
268
+ const loc = parseLocation(id);
269
+ if (loc) {
270
+ emit({
271
+ channel: CHANNEL,
272
+ event: "TEXT_EDIT",
273
+ elementId: id,
274
+ before: originalTextRef.current,
275
+ after: newText,
276
+ source: loc
277
+ });
278
+ }
279
+ }
280
+ const styles3 = appliedStylesRef.current.get(id);
281
+ if (styles3 && Object.keys(styles3).length > 0) {
282
+ const loc = parseLocation(id);
283
+ if (loc) {
284
+ emit({
285
+ channel: CHANNEL,
286
+ event: "STYLE_COMMIT",
287
+ elementId: id,
288
+ styles: styles3,
289
+ source: loc,
290
+ className: el.className || ""
291
+ });
292
+ }
293
+ appliedStylesRef.current.delete(id);
294
+ }
295
+ if (el.tagName.toLowerCase() === "img") {
296
+ const newSrc = normalizeImgSrc(el.src);
297
+ if (newSrc !== originalSrcRef.current && originalSrcRef.current) {
298
+ const loc = parseLocation(id);
299
+ if (loc) {
300
+ emit({
301
+ channel: CHANNEL,
302
+ event: "IMAGE_COMMIT",
303
+ elementId: id,
304
+ before: originalSrcRef.current,
305
+ after: newSrc,
306
+ source: loc
307
+ });
308
+ }
309
+ }
310
+ }
311
+ el.contentEditable = "false";
312
+ el.querySelectorAll('[contenteditable="false"]').forEach((child) => {
313
+ child.removeAttribute("contenteditable");
314
+ });
315
+ editingElRef.current = null;
316
+ originalTextRef.current = "";
317
+ originalSrcRef.current = "";
318
+ }, []);
319
+ const handleDeselect = (0, import_react.useCallback)(() => {
320
+ cleanupEditing();
321
+ selectedElRef.current = null;
322
+ dispatch2({ type: "CLEAR_SELECTIONS" });
323
+ if (import_react_native.Platform.OS === "web" && typeof window !== "undefined") {
324
+ try {
325
+ localStorage.removeItem(SELECTED_KEY);
326
+ } catch {
327
+ }
328
+ }
329
+ emit({ channel: CHANNEL, event: "DESELECT" });
330
+ }, [cleanupEditing]);
331
+ (0, import_react.useEffect)(() => {
332
+ if (!isEmbedded()) return;
333
+ const onPointerMove = (e) => {
334
+ if (!activeRef.current || state.isResizing || state.isScrolling) return;
335
+ const hit = document.elementFromPoint(e.clientX, e.clientY)?.closest(`[${DATA_ATTR}]`) ?? null;
336
+ if (!hit) {
337
+ if (state.hoveredId) {
338
+ dispatch2({ type: "SET_HOVER", id: null, rect: null, tag: null });
339
+ emit({ channel: CHANNEL, event: "HOVER", element: null });
340
+ }
341
+ return;
342
+ }
343
+ const id = hit.getAttribute(DATA_ATTR);
344
+ const isSelected = state.selectedElements.some((s) => s.id === id);
345
+ if (id === state.hoveredId || isSelected) return;
346
+ const info = buildElementInfo(hit);
347
+ dispatch2({ type: "SET_HOVER", id: info.id, rect: info.rect, tag: info.tag });
348
+ emit({ channel: CHANNEL, event: "HOVER", element: info });
349
+ };
350
+ const onPointerLeave = () => {
351
+ if (!activeRef.current) return;
352
+ dispatch2({ type: "CLEAR_HOVER" });
353
+ emit({ channel: CHANNEL, event: "HOVER", element: null });
354
+ };
355
+ document.addEventListener("pointermove", onPointerMove);
356
+ document.addEventListener("pointerleave", onPointerLeave);
357
+ return () => {
358
+ document.removeEventListener("pointermove", onPointerMove);
359
+ document.removeEventListener("pointerleave", onPointerLeave);
360
+ };
361
+ }, [state.hoveredId, state.selectedElements, state.isResizing, state.isScrolling, buildElementInfo]);
362
+ (0, import_react.useEffect)(() => {
363
+ if (!isEmbedded()) return;
364
+ const onClick = (e) => {
365
+ if (!activeRef.current) return;
366
+ const target = e.target;
367
+ const link = target.closest("a");
368
+ if (link && !link.isContentEditable) {
369
+ e.preventDefault();
370
+ e.stopPropagation();
371
+ }
372
+ const hit = target.closest(`[${DATA_ATTR}]`);
373
+ if (!hit) {
374
+ handleDeselect();
375
+ return;
376
+ }
377
+ const id = hit.getAttribute(DATA_ATTR);
378
+ const isAlreadySelected = state.selectedElements.some((s) => s.id === id);
379
+ if (isAlreadySelected) return;
380
+ cleanupEditing();
381
+ handleSelect(hit, { x: e.clientX, y: e.clientY }, state.selectedElements);
382
+ };
383
+ document.addEventListener("click", onClick, true);
384
+ return () => document.removeEventListener("click", onClick, true);
385
+ }, [state.selectedElements, handleSelect, handleDeselect, cleanupEditing]);
386
+ (0, import_react.useEffect)(() => {
387
+ if (!isEmbedded()) return;
388
+ const onScroll = () => {
389
+ if (!activeRef.current) return;
390
+ if (!state.isScrolling) {
391
+ dispatch2({ type: "SET_SCROLLING", value: true });
392
+ emit({ channel: CHANNEL, event: "SCROLL_START" });
393
+ }
394
+ if (scrollTimeoutRef.current) clearTimeout(scrollTimeoutRef.current);
395
+ scrollTimeoutRef.current = window.setTimeout(() => {
396
+ dispatch2({ type: "SET_SCROLLING", value: false });
397
+ emit({ channel: CHANNEL, event: "SCROLL_END" });
398
+ dispatch2({ type: "UPDATE_SELECTED_RECTS" });
399
+ }, 150);
400
+ };
401
+ window.addEventListener("scroll", onScroll, true);
402
+ return () => window.removeEventListener("scroll", onScroll, true);
403
+ }, [state.isScrolling]);
404
+ (0, import_react.useEffect)(() => {
405
+ if (!isEmbedded()) return;
406
+ const onMessage = (e) => {
407
+ const msg = e.data;
408
+ if (msg?.channel !== CHANNEL) return;
409
+ switch (msg.action) {
410
+ case "ACTIVATE":
411
+ dispatch2({ type: "SET_ACTIVE", value: msg.value });
412
+ if (!msg.value) handleDeselect();
413
+ break;
414
+ case "SCROLL_BY":
415
+ window.scrollBy({ left: msg.dx, top: msg.dy, behavior: "auto" });
416
+ break;
417
+ case "APPLY_STYLES": {
418
+ const elements = document.querySelectorAll(`[${DATA_ATTR}="${msg.elementId}"]`);
419
+ elements.forEach((el) => {
420
+ Object.entries(msg.styles).forEach(([prop, val]) => {
421
+ const cssProp = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
422
+ el.style.setProperty(cssProp, val, "important");
423
+ });
424
+ });
425
+ const existing = appliedStylesRef.current.get(msg.elementId) || {};
426
+ appliedStylesRef.current.set(msg.elementId, { ...existing, ...msg.styles });
427
+ requestAnimationFrame(() => {
428
+ dispatch2({ type: "UPDATE_SELECTED_RECTS" });
429
+ });
430
+ break;
431
+ }
432
+ case "APPLY_IMAGE": {
433
+ const img = document.querySelector(`[${DATA_ATTR}="${msg.elementId}"]`);
434
+ if (img?.tagName.toLowerCase() === "img") {
435
+ img.removeAttribute("srcset");
436
+ img.src = msg.src;
437
+ }
438
+ break;
439
+ }
440
+ case "PREVIEW_FONT": {
441
+ const el = document.querySelector(`[${DATA_ATTR}="${msg.elementId}"]`);
442
+ if (el) {
443
+ const fontKey = msg.font.replace(/[\s']+/g, "+");
444
+ const link = document.createElement("link");
445
+ link.rel = "stylesheet";
446
+ link.href = `https://fonts.googleapis.com/css2?family=${fontKey}:wght@400;500;600;700&display=swap`;
447
+ document.head.appendChild(link);
448
+ el.style.setProperty("font-family", msg.font, "important");
449
+ }
450
+ break;
451
+ }
452
+ case "CLEAR_STYLES": {
453
+ const el = document.querySelector(`[${DATA_ATTR}="${msg.elementId}"]`);
454
+ if (el) {
455
+ el.removeAttribute("style");
456
+ appliedStylesRef.current.delete(msg.elementId);
457
+ }
458
+ break;
459
+ }
460
+ case "RESIZE": {
461
+ const el = document.querySelector(`[${DATA_ATTR}="${msg.elementId}"]`);
462
+ if (el) {
463
+ el.style.setProperty("width", `${msg.width}px`, "important");
464
+ el.style.setProperty("height", `${msg.height}px`, "important");
465
+ const existing = appliedStylesRef.current.get(msg.elementId) || {};
466
+ appliedStylesRef.current.set(msg.elementId, {
467
+ ...existing,
468
+ width: `${msg.width}px`,
469
+ height: `${msg.height}px`
470
+ });
471
+ requestAnimationFrame(() => {
472
+ dispatch2({ type: "UPDATE_SELECTED_RECTS" });
473
+ });
474
+ }
475
+ break;
476
+ }
477
+ case "HOVER_ELEMENT": {
478
+ if (!msg.elementId) {
479
+ dispatch2({ type: "CLEAR_HOVER" });
480
+ return;
481
+ }
482
+ const el = document.querySelector(`[${DATA_ATTR}="${msg.elementId}"]`);
483
+ if (el) {
484
+ const info = buildElementInfo(el);
485
+ dispatch2({ type: "SET_HOVER", id: info.id, rect: info.rect, tag: info.tag });
486
+ }
487
+ break;
488
+ }
489
+ }
490
+ };
491
+ window.addEventListener("message", onMessage);
492
+ return () => window.removeEventListener("message", onMessage);
493
+ }, [handleDeselect, buildElementInfo]);
494
+ (0, import_react.useEffect)(() => {
495
+ if (!isEmbedded()) return;
496
+ const onKeyDown = (e) => {
497
+ if (!activeRef.current) return;
498
+ if (e.key === "Escape") {
499
+ if (editingElRef.current) {
500
+ editingElRef.current.blur();
501
+ cleanupEditing();
502
+ } else if (state.selectedElements.length > 0) {
503
+ handleDeselect();
504
+ }
505
+ }
506
+ };
507
+ document.addEventListener("keydown", onKeyDown);
508
+ return () => document.removeEventListener("keydown", onKeyDown);
509
+ }, [state.selectedElements, cleanupEditing, handleDeselect]);
510
+ const onResizeStart = (0, import_react.useCallback)((handle, e) => {
511
+ if (!selectedElRef.current || import_react_native.Platform.OS !== "web") return;
512
+ const nativeEvent = e.nativeEvent;
513
+ const rect = selectedElRef.current.getBoundingClientRect();
514
+ resizeStartRef.current = { x: nativeEvent.pageX, y: nativeEvent.pageY, w: rect.width, h: rect.height };
515
+ dispatch2({ type: "SET_RESIZING", value: true, handle });
516
+ dispatch2({ type: "CLEAR_HOVER" });
517
+ }, []);
518
+ (0, import_react.useEffect)(() => {
519
+ if (!state.isResizing || !resizeStartRef.current || !state.resizeHandle || import_react_native.Platform.OS !== "web") return;
520
+ const onMouseMove = (e) => {
521
+ if (!selectedElRef.current || !resizeStartRef.current) return;
522
+ const dx = e.clientX - resizeStartRef.current.x;
523
+ const dy = e.clientY - resizeStartRef.current.y;
524
+ const handle = state.resizeHandle;
525
+ let w = resizeStartRef.current.w;
526
+ let h = resizeStartRef.current.h;
527
+ if (handle.includes("e")) w += dx;
528
+ if (handle.includes("w")) w -= dx;
529
+ if (handle.includes("s")) h += dy;
530
+ if (handle.includes("n")) h -= dy;
531
+ w = Math.max(20, w);
532
+ h = Math.max(20, h);
533
+ selectedElRef.current.style.setProperty("width", `${w}px`, "important");
534
+ selectedElRef.current.style.setProperty("height", `${h}px`, "important");
535
+ dispatch2({ type: "UPDATE_SELECTED_RECTS" });
536
+ };
537
+ const onMouseUp = () => {
538
+ if (selectedElRef.current) {
539
+ const id = selectedElRef.current.getAttribute(DATA_ATTR);
540
+ if (id) {
541
+ const cs = window.getComputedStyle(selectedElRef.current);
542
+ const loc = parseLocation(id);
543
+ if (loc) {
544
+ emit({
545
+ channel: CHANNEL,
546
+ event: "RESIZE_COMMIT",
547
+ elementId: id,
548
+ width: cs.width,
549
+ height: cs.height,
550
+ source: loc
551
+ });
552
+ }
553
+ }
554
+ }
555
+ dispatch2({ type: "SET_RESIZING", value: false, handle: null });
556
+ resizeStartRef.current = null;
557
+ };
558
+ document.addEventListener("mousemove", onMouseMove);
559
+ document.addEventListener("mouseup", onMouseUp);
560
+ return () => {
561
+ document.removeEventListener("mousemove", onMouseMove);
562
+ document.removeEventListener("mouseup", onMouseUp);
563
+ };
564
+ }, [state.isResizing, state.resizeHandle]);
565
+ (0, import_react.useEffect)(() => {
566
+ if (!state.active || import_react_native.Platform.OS !== "web") return;
567
+ const preventSubmit = (e) => {
568
+ e.preventDefault();
569
+ e.stopPropagation();
570
+ };
571
+ document.addEventListener("submit", preventSubmit, true);
572
+ return () => document.removeEventListener("submit", preventSubmit, true);
573
+ }, [state.active]);
574
+ if (import_react_native.Platform.OS !== "web" || !state.active) return null;
575
+ const resizeHandles = ["n", "ne", "e", "se", "s", "sw", "w", "nw"];
576
+ const getHandleStyle = (handle) => {
577
+ const base = {
578
+ position: "absolute",
579
+ width: 8,
580
+ height: 8,
581
+ backgroundColor: "#3b82f6",
582
+ borderWidth: 1,
583
+ borderColor: "white",
584
+ borderRadius: 2,
585
+ zIndex: 10002
586
+ };
587
+ const posMap = {
588
+ n: { top: -4, left: "50%", transform: "translateX(-50%)", cursor: "ns-resize" },
589
+ ne: { top: -4, right: -4, cursor: "nesw-resize" },
590
+ e: { top: "50%", right: -4, transform: "translateY(-50%)", cursor: "ew-resize" },
591
+ se: { bottom: -4, right: -4, cursor: "nwse-resize" },
592
+ s: { bottom: -4, left: "50%", transform: "translateX(-50%)", cursor: "ns-resize" },
593
+ sw: { bottom: -4, left: -4, cursor: "nesw-resize" },
594
+ w: { top: "50%", left: -4, transform: "translateY(-50%)", cursor: "ew-resize" },
595
+ nw: { top: -4, left: -4, cursor: "nwse-resize" }
596
+ };
597
+ return { ...base, ...posMap[handle] };
598
+ };
599
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: styles.container, pointerEvents: "box-none", children: [
600
+ state.hoveredRect && !state.selectedElements.some((s) => s.id === state.hoveredId) && !state.isScrolling && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
601
+ import_react_native.View,
602
+ {
603
+ style: [
604
+ styles.hoverOverlay,
605
+ {
606
+ top: state.hoveredRect.top,
607
+ left: state.hoveredRect.left,
608
+ width: state.hoveredRect.width,
609
+ height: state.hoveredRect.height
610
+ }
611
+ ],
612
+ pointerEvents: "none",
613
+ children: state.hoveredTag && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: styles.hoverTag, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: styles.hoverTagText, children: state.hoveredTag }) })
614
+ }
615
+ ),
616
+ !state.isScrolling && state.selectedElements.map((selected, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
617
+ import_react_native.View,
618
+ {
619
+ style: [
620
+ styles.selectedOverlay,
621
+ {
622
+ top: selected.rect.top,
623
+ left: selected.rect.left,
624
+ width: selected.rect.width,
625
+ height: selected.rect.height,
626
+ zIndex: 10001 + index
627
+ }
628
+ ],
629
+ pointerEvents: "box-none",
630
+ children: [
631
+ selected.tag && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: styles.selectedTag, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.Text, { style: styles.selectedTagText, children: [
632
+ selected.tag,
633
+ " (",
634
+ index + 1,
635
+ "/",
636
+ state.selectedElements.length,
637
+ ")"
638
+ ] }) }),
639
+ index === state.selectedElements.length - 1 && resizeHandles.map((handle) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
640
+ import_react_native.View,
641
+ {
642
+ style: getHandleStyle(handle),
643
+ onStartShouldSetResponder: () => true,
644
+ onResponderGrant: (e) => onResizeStart(handle, e)
645
+ },
646
+ handle
647
+ ))
648
+ ]
649
+ },
650
+ selected.id
651
+ ))
652
+ ] });
653
+ }
654
+ var styles = import_react_native.StyleSheet.create({
655
+ container: {
656
+ position: "absolute",
657
+ top: 0,
658
+ left: 0,
659
+ right: 0,
660
+ bottom: 0,
661
+ zIndex: 99999
662
+ },
663
+ hoverOverlay: {
664
+ position: "absolute",
665
+ borderWidth: 2,
666
+ borderStyle: "dashed",
667
+ borderColor: "#3b82f6",
668
+ backgroundColor: "rgba(59, 130, 246, 0.08)",
669
+ borderRadius: 4,
670
+ zIndex: 1e4
671
+ },
672
+ hoverTag: {
673
+ position: "absolute",
674
+ top: -22,
675
+ left: 0,
676
+ backgroundColor: "#3b82f6",
677
+ paddingHorizontal: 6,
678
+ paddingVertical: 2,
679
+ borderRadius: 3
680
+ },
681
+ hoverTagText: {
682
+ color: "white",
683
+ fontSize: 11,
684
+ fontFamily: "system-ui, sans-serif"
685
+ },
686
+ selectedOverlay: {
687
+ position: "absolute",
688
+ borderWidth: 2,
689
+ borderColor: "#3b82f6",
690
+ backgroundColor: "rgba(59, 130, 246, 0.04)",
691
+ borderRadius: 4
692
+ },
693
+ selectedTag: {
694
+ position: "absolute",
695
+ top: -22,
696
+ left: 0,
697
+ backgroundColor: "#3b82f6",
698
+ paddingHorizontal: 6,
699
+ paddingVertical: 2,
700
+ borderRadius: 3
701
+ },
702
+ selectedTagText: {
703
+ color: "white",
704
+ fontSize: 11,
705
+ fontWeight: "500",
706
+ fontFamily: "system-ui, sans-serif"
707
+ }
708
+ });
709
+
710
+ // src/expo/components/ErrorBoundary.tsx
711
+ var import_react2 = require("react");
712
+ var import_react_native2 = require("react-native");
713
+ var import_jsx_runtime2 = require("react/jsx-runtime");
714
+ var ERROR_DEDUPE_WINDOW_MS = 5e3;
715
+ var reportedErrors = /* @__PURE__ */ new Set();
716
+ function generateFingerprint(message, stack) {
717
+ const stackLine = stack?.split("\\n")[1] || "";
718
+ return `${message}: ${stackLine}`.slice(0, 200);
719
+ }
720
+ function shouldReport(fingerprint) {
721
+ if (reportedErrors.has(fingerprint)) {
722
+ return false;
723
+ }
724
+ reportedErrors.add(fingerprint);
725
+ setTimeout(() => reportedErrors.delete(fingerprint), ERROR_DEDUPE_WINDOW_MS);
726
+ return true;
727
+ }
728
+ function dispatch(data) {
729
+ if (import_react_native2.Platform.OS === "web" && typeof window !== "undefined" && window.parent !== window) {
730
+ try {
731
+ window.parent.postMessage(data, "*");
732
+ } catch {
733
+ }
734
+ } else if (import_react_native2.Platform.OS !== "web") {
735
+ try {
736
+ const { requireOptionalNativeModule } = require("expo-modules-core");
737
+ const Bridge = requireOptionalNativeModule("FlexBridge");
738
+ Bridge?.sendMessage?.({ type: "runtime-error", payload: JSON.stringify(data) });
739
+ } catch {
740
+ }
741
+ }
742
+ }
743
+ function reportException(message, origin, details) {
744
+ const fingerprint = generateFingerprint(message, details?.stack);
745
+ if (!shouldReport(fingerprint)) return;
746
+ dispatch({
747
+ type: "VIBEX_EXCEPTION",
748
+ details: {
749
+ message,
750
+ stack: details?.stack,
751
+ file: details?.file,
752
+ line: details?.line,
753
+ column: details?.column,
754
+ componentStack: details?.componentStack,
755
+ name: details?.name,
756
+ origin
757
+ },
758
+ capturedAt: Date.now()
759
+ });
760
+ }
761
+ function reportBoundaryError(error, componentStack) {
762
+ dispatch({
763
+ type: "vibex-boundary-error",
764
+ details: {
765
+ message: error.message,
766
+ stack: error.stack,
767
+ name: error.name,
768
+ componentStack
769
+ },
770
+ capturedAt: Date.now(),
771
+ client: import_react_native2.Platform.OS === "web" && typeof navigator !== "undefined" ? navigator.userAgent : `react-native-${import_react_native2.Platform.OS}`
772
+ });
773
+ }
774
+ function requestAIFix(error) {
775
+ dispatch({
776
+ type: "vibex-fix-with-ai",
777
+ details: {
778
+ message: error.message,
779
+ stack: error.stack,
780
+ name: error.name
781
+ },
782
+ capturedAt: Date.now()
783
+ });
784
+ }
785
+ function setupGlobalHandlers() {
786
+ if (import_react_native2.Platform.OS !== "web" || typeof window === "undefined") return;
787
+ window.addEventListener("error", (evt) => {
788
+ evt.preventDefault();
789
+ reportException(
790
+ evt.message || "Unknown error",
791
+ "runtime",
792
+ {
793
+ stack: evt.error?.stack,
794
+ file: evt.filename,
795
+ line: evt.lineno,
796
+ column: evt.colno
797
+ }
798
+ );
799
+ }, true);
800
+ window.addEventListener("unhandledrejection", (evt) => {
801
+ evt.preventDefault();
802
+ reportException(
803
+ evt.reason?.message ?? String(evt.reason),
804
+ "promise",
805
+ { stack: evt.reason?.stack }
806
+ );
807
+ }, true);
808
+ }
809
+ function interceptConsoleErrors() {
810
+ const original = console.error;
811
+ console.error = (...args) => {
812
+ original.apply(console, args);
813
+ const message = args.map((a) => {
814
+ if (a instanceof Error) return a.message;
815
+ if (typeof a === "object") {
816
+ try {
817
+ return JSON.stringify(a);
818
+ } catch {
819
+ return String(a);
820
+ }
821
+ }
822
+ return String(a);
823
+ }).join(" ");
824
+ if (/error|exception|failed|crash|fatal/i.test(message)) {
825
+ reportException(message, "console");
826
+ }
827
+ };
828
+ return () => {
829
+ console.error = original;
830
+ };
831
+ }
832
+ var ErrorBoundary = class extends import_react2.Component {
833
+ cleanupConsole = null;
834
+ constructor(props) {
835
+ super(props);
836
+ this.state = { hasError: false, error: null, errorInfo: null };
837
+ }
838
+ componentDidMount() {
839
+ setupGlobalHandlers();
840
+ this.cleanupConsole = interceptConsoleErrors();
841
+ }
842
+ componentWillUnmount() {
843
+ this.cleanupConsole?.();
844
+ }
845
+ static getDerivedStateFromError(error) {
846
+ return { hasError: true, error };
847
+ }
848
+ componentDidCatch(error, errorInfo) {
849
+ this.setState({ errorInfo });
850
+ reportException(error.message, "boundary", {
851
+ stack: error.stack,
852
+ name: error.name,
853
+ componentStack: errorInfo.componentStack || void 0
854
+ });
855
+ reportBoundaryError(error, errorInfo.componentStack || void 0);
856
+ this.props.onError?.(error, errorInfo);
857
+ }
858
+ handleRetry = () => {
859
+ this.setState({ hasError: false, error: null, errorInfo: null });
860
+ };
861
+ handleFixWithAI = () => {
862
+ if (this.state.error) {
863
+ requestAIFix(this.state.error);
864
+ }
865
+ };
866
+ render() {
867
+ if (this.state.hasError) {
868
+ if (this.props.fallback) return this.props.fallback;
869
+ const error = this.state.error;
870
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles2.container, children: [
871
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles2.card, children: [
872
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles2.accentBar }),
873
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles2.content, children: [
874
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles2.header, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { children: [
875
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.label, children: "Runtime Error" }),
876
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.title, children: error?.name || "Error" })
877
+ ] }) }),
878
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.message, children: error?.message || "An unexpected error occurred" }),
879
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles2.actions, children: [
880
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.TouchableOpacity, { style: styles2.primaryButton, onPress: this.handleFixWithAI, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.primaryButtonText, children: "Fix with AI" }) }),
881
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.TouchableOpacity, { style: styles2.secondaryButton, onPress: this.handleRetry, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.secondaryButtonText, children: "Retry" }) })
882
+ ] }),
883
+ __DEV__ && error?.stack && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles2.stackContainer, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.stackTrace, children: error.stack }) })
884
+ ] })
885
+ ] }),
886
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.footer, children: "Vibex" })
887
+ ] });
888
+ }
889
+ return this.props.children;
890
+ }
891
+ };
892
+ var styles2 = import_react_native2.StyleSheet.create({
893
+ container: {
894
+ flex: 1,
895
+ backgroundColor: "#fafafa",
896
+ alignItems: "center",
897
+ justifyContent: "center",
898
+ padding: 16
899
+ },
900
+ card: {
901
+ width: "100%",
902
+ maxWidth: 480,
903
+ flexDirection: "row",
904
+ borderRadius: 12,
905
+ borderWidth: 1,
906
+ borderColor: "#e5e5e5",
907
+ backgroundColor: "#fff",
908
+ overflow: "hidden"
909
+ },
910
+ accentBar: {
911
+ width: 6,
912
+ backgroundColor: "#dc2626"
913
+ },
914
+ content: {
915
+ flex: 1,
916
+ padding: 20
917
+ },
918
+ header: {
919
+ flexDirection: "row",
920
+ justifyContent: "space-between",
921
+ alignItems: "flex-start",
922
+ marginBottom: 16
923
+ },
924
+ label: {
925
+ fontSize: 10,
926
+ fontWeight: "600",
927
+ letterSpacing: 0.5,
928
+ textTransform: "uppercase",
929
+ color: "#737373",
930
+ marginBottom: 4
931
+ },
932
+ title: {
933
+ fontSize: 18,
934
+ fontWeight: "500",
935
+ color: "#171717"
936
+ },
937
+ message: {
938
+ fontSize: 14,
939
+ color: "#737373",
940
+ lineHeight: 20,
941
+ marginBottom: 20
942
+ },
943
+ actions: {
944
+ flexDirection: "row",
945
+ alignItems: "center",
946
+ gap: 12
947
+ },
948
+ primaryButton: {
949
+ backgroundColor: "#171717",
950
+ paddingHorizontal: 16,
951
+ paddingVertical: 10,
952
+ borderRadius: 6,
953
+ flexDirection: "row",
954
+ alignItems: "center",
955
+ gap: 8
956
+ },
957
+ primaryButtonText: {
958
+ color: "#fff",
959
+ fontSize: 14,
960
+ fontWeight: "500"
961
+ },
962
+ secondaryButton: {
963
+ paddingHorizontal: 12,
964
+ paddingVertical: 10
965
+ },
966
+ secondaryButtonText: {
967
+ color: "#737373",
968
+ fontSize: 14
969
+ },
970
+ stackContainer: {
971
+ marginTop: 16,
972
+ paddingTop: 16,
973
+ borderTopWidth: 1,
974
+ borderTopColor: "#e5e5e5"
975
+ },
976
+ stackTrace: {
977
+ fontSize: 11,
978
+ fontFamily: import_react_native2.Platform.OS === "ios" ? "Menlo" : "monospace",
979
+ color: "#737373",
980
+ lineHeight: 16,
981
+ maxHeight: 350,
982
+ overflow: "scroll"
983
+ },
984
+ footer: {
985
+ marginTop: 16,
986
+ fontSize: 12,
987
+ color: "#a3a3a3"
988
+ }
989
+ });
990
+
991
+ // src/expo/config.ts
992
+ var import_url = require("url");
993
+ var import_path = require("path");
994
+ var import_meta = {};
995
+ var __filename = (0, import_url.fileURLToPath)(import_meta.url);
996
+ var __dirname = (0, import_path.dirname)(__filename);
997
+ var transformerPath = (0, import_path.join)(__dirname, "..", "..", "expo", "metro-transformer.js");
998
+ function withInspector(metroConfig, options = {}) {
999
+ const { enableInProduction = false } = options;
1000
+ if (process.env.NODE_ENV === "production" && !enableInProduction) {
1001
+ return metroConfig;
1002
+ }
1003
+ return {
1004
+ ...metroConfig,
1005
+ transformer: {
1006
+ ...metroConfig.transformer,
1007
+ babelTransformerPath: transformerPath
1008
+ }
1009
+ };
1010
+ }
1011
+ // Annotate the CommonJS export names for ESM import in node:
1012
+ 0 && (module.exports = {
1013
+ ErrorBoundary,
1014
+ VisualInspector,
1015
+ transformerPath,
1016
+ withInspector
1017
+ });
1018
+ //# sourceMappingURL=index.cjs.map