@base44-preview/vite-plugin 0.2.22-pr.37.eb62313 → 0.2.22-pr.38.2655a87

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.
Files changed (89) hide show
  1. package/dist/injections/visual-edit-agent.d.ts +1 -1
  2. package/dist/injections/visual-edit-agent.d.ts.map +1 -1
  3. package/dist/injections/visual-edit-agent.js +466 -1
  4. package/dist/injections/visual-edit-agent.js.map +1 -1
  5. package/dist/statics/index.mjs +1 -5
  6. package/dist/statics/index.mjs.map +1 -1
  7. package/package.json +1 -1
  8. package/src/injections/visual-edit-agent.ts +570 -1
  9. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts +0 -25
  10. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts.map +0 -1
  11. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js +0 -95
  12. package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js.map +0 -1
  13. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts +0 -4
  14. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts.map +0 -1
  15. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js +0 -4
  16. package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js.map +0 -1
  17. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts +0 -9
  18. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts.map +0 -1
  19. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js +0 -26
  20. package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js.map +0 -1
  21. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts +0 -10
  22. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts.map +0 -1
  23. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js +0 -60
  24. package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js.map +0 -1
  25. package/dist/injections/visual-edit-agent/constants.d.ts +0 -10
  26. package/dist/injections/visual-edit-agent/constants.d.ts.map +0 -1
  27. package/dist/injections/visual-edit-agent/constants.js +0 -10
  28. package/dist/injections/visual-edit-agent/constants.js.map +0 -1
  29. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts +0 -10
  30. package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts.map +0 -1
  31. package/dist/injections/visual-edit-agent/handlers/click-handlers.js +0 -108
  32. package/dist/injections/visual-edit-agent/handlers/click-handlers.js.map +0 -1
  33. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts +0 -14
  34. package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts.map +0 -1
  35. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js +0 -64
  36. package/dist/injections/visual-edit-agent/handlers/hover-handlers.js.map +0 -1
  37. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts +0 -14
  38. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts.map +0 -1
  39. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js +0 -109
  40. package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js.map +0 -1
  41. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts +0 -26
  42. package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts.map +0 -1
  43. package/dist/injections/visual-edit-agent/handlers/message-handlers.js +0 -145
  44. package/dist/injections/visual-edit-agent/handlers/message-handlers.js.map +0 -1
  45. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts +0 -7
  46. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts.map +0 -1
  47. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js +0 -58
  48. package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js.map +0 -1
  49. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts +0 -11
  50. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts.map +0 -1
  51. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js +0 -32
  52. package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js.map +0 -1
  53. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts +0 -86
  54. package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts.map +0 -1
  55. package/dist/injections/visual-edit-agent/handlers/messages/types.js +0 -28
  56. package/dist/injections/visual-edit-agent/handlers/messages/types.js.map +0 -1
  57. package/dist/injections/visual-edit-agent/index.d.ts +0 -5
  58. package/dist/injections/visual-edit-agent/index.d.ts.map +0 -1
  59. package/dist/injections/visual-edit-agent/index.js +0 -95
  60. package/dist/injections/visual-edit-agent/index.js.map +0 -1
  61. package/dist/injections/visual-edit-agent/state/agent-state.d.ts +0 -17
  62. package/dist/injections/visual-edit-agent/state/agent-state.d.ts.map +0 -1
  63. package/dist/injections/visual-edit-agent/state/agent-state.js +0 -18
  64. package/dist/injections/visual-edit-agent/state/agent-state.js.map +0 -1
  65. package/dist/injections/visual-edit-agent/ui/overlay.d.ts +0 -26
  66. package/dist/injections/visual-edit-agent/ui/overlay.d.ts.map +0 -1
  67. package/dist/injections/visual-edit-agent/ui/overlay.js +0 -104
  68. package/dist/injections/visual-edit-agent/ui/overlay.js.map +0 -1
  69. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts +0 -14
  70. package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts.map +0 -1
  71. package/dist/injections/visual-edit-agent/utils/dom-utils.js +0 -34
  72. package/dist/injections/visual-edit-agent/utils/dom-utils.js.map +0 -1
  73. package/src/injections/visual-edit-agent/README.md +0 -222
  74. package/src/injections/visual-edit-agent/capabilities/inline-editing/core.ts +0 -120
  75. package/src/injections/visual-edit-agent/capabilities/inline-editing/index.ts +0 -10
  76. package/src/injections/visual-edit-agent/capabilities/inline-editing/styles.ts +0 -26
  77. package/src/injections/visual-edit-agent/capabilities/inline-editing/validation.ts +0 -67
  78. package/src/injections/visual-edit-agent/constants.ts +0 -9
  79. package/src/injections/visual-edit-agent/handlers/click-handlers.ts +0 -135
  80. package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +0 -78
  81. package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +0 -141
  82. package/src/injections/visual-edit-agent/handlers/message-handlers.ts +0 -191
  83. package/src/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.ts +0 -70
  84. package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +0 -40
  85. package/src/injections/visual-edit-agent/handlers/messages/types.ts +0 -112
  86. package/src/injections/visual-edit-agent/index.ts +0 -108
  87. package/src/injections/visual-edit-agent/state/agent-state.ts +0 -31
  88. package/src/injections/visual-edit-agent/ui/overlay.ts +0 -126
  89. package/src/injections/visual-edit-agent/utils/dom-utils.ts +0 -39
@@ -1,2 +1,2 @@
1
- export { setupVisualEditAgent } from "./visual-edit-agent/index.js";
1
+ export declare function setupVisualEditAgent(): void;
2
2
  //# sourceMappingURL=visual-edit-agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visual-edit-agent.d.ts","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"visual-edit-agent.d.ts","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,SAujBnC"}
@@ -1,2 +1,467 @@
1
- export { setupVisualEditAgent } from "./visual-edit-agent/index.js";
1
+ import { findElementsById, updateElementClasses } from "./utils.js";
2
+ export function setupVisualEditAgent() {
3
+ // State variables (replacing React useState/useRef)
4
+ let isVisualEditMode = false;
5
+ let isPopoverDragging = false;
6
+ let isDropdownOpen = false;
7
+ let hoverOverlays = [];
8
+ let selectedOverlays = [];
9
+ let currentHighlightedElements = [];
10
+ let selectedElementId = null;
11
+ // Create overlay element
12
+ const createOverlay = (isSelected = false) => {
13
+ const overlay = document.createElement("div");
14
+ overlay.style.position = "absolute";
15
+ overlay.style.pointerEvents = "none";
16
+ overlay.style.transition = "all 0.1s ease-in-out";
17
+ overlay.style.zIndex = "9999";
18
+ if (isSelected) {
19
+ overlay.style.border = "2px solid #2563EB";
20
+ }
21
+ else {
22
+ overlay.style.border = "2px solid #95a5fc";
23
+ overlay.style.backgroundColor = "rgba(99, 102, 241, 0.05)";
24
+ }
25
+ return overlay;
26
+ };
27
+ // Position overlay relative to element
28
+ const positionOverlay = (overlay, element, isSelected = false) => {
29
+ if (!element || !isVisualEditMode)
30
+ return;
31
+ const htmlElement = element;
32
+ // Force layout recalculation
33
+ void htmlElement.offsetWidth;
34
+ const rect = element.getBoundingClientRect();
35
+ overlay.style.top = `${rect.top + window.scrollY}px`;
36
+ overlay.style.left = `${rect.left + window.scrollX}px`;
37
+ overlay.style.width = `${rect.width}px`;
38
+ overlay.style.height = `${rect.height}px`;
39
+ // Check if label already exists in overlay
40
+ let label = overlay.querySelector("div");
41
+ if (!label) {
42
+ label = document.createElement("div");
43
+ label.textContent = element.tagName.toLowerCase();
44
+ label.style.position = "absolute";
45
+ label.style.top = "-27px";
46
+ label.style.left = "-2px";
47
+ label.style.padding = "2px 8px";
48
+ label.style.fontSize = "11px";
49
+ label.style.fontWeight = isSelected ? "500" : "400";
50
+ label.style.color = isSelected ? "#ffffff" : "#526cff";
51
+ label.style.backgroundColor = isSelected ? "#526cff" : "#DBEAFE";
52
+ label.style.borderRadius = "3px";
53
+ label.style.minWidth = "24px";
54
+ label.style.textAlign = "center";
55
+ overlay.appendChild(label);
56
+ }
57
+ };
58
+ // Clear hover overlays
59
+ const clearHoverOverlays = () => {
60
+ hoverOverlays.forEach((overlay) => {
61
+ if (overlay && overlay.parentNode) {
62
+ overlay.remove();
63
+ }
64
+ });
65
+ hoverOverlays = [];
66
+ currentHighlightedElements = [];
67
+ };
68
+ // Handle mouse over event
69
+ const handleMouseOver = (e) => {
70
+ if (!isVisualEditMode || isPopoverDragging)
71
+ return;
72
+ const target = e.target;
73
+ // Prevent hover effects when a dropdown is open
74
+ if (isDropdownOpen) {
75
+ clearHoverOverlays();
76
+ return;
77
+ }
78
+ // Prevent hover effects on SVG path elements
79
+ if (target.tagName.toLowerCase() === "path") {
80
+ clearHoverOverlays();
81
+ return;
82
+ }
83
+ // Support both data-source-location and data-visual-selector-id
84
+ const element = target.closest("[data-source-location], [data-visual-selector-id]");
85
+ if (!element) {
86
+ clearHoverOverlays();
87
+ return;
88
+ }
89
+ // Prefer data-source-location, fallback to data-visual-selector-id
90
+ const htmlElement = element;
91
+ const selectorId = htmlElement.dataset.sourceLocation ||
92
+ htmlElement.dataset.visualSelectorId;
93
+ // Skip if this element is already selected
94
+ if (selectedElementId === selectorId) {
95
+ clearHoverOverlays();
96
+ return;
97
+ }
98
+ // Find all elements with the same ID
99
+ const elements = findElementsById(selectorId || null);
100
+ // Clear previous hover overlays
101
+ clearHoverOverlays();
102
+ // Create overlays for all matching elements
103
+ elements.forEach((el) => {
104
+ const overlay = createOverlay(false);
105
+ document.body.appendChild(overlay);
106
+ hoverOverlays.push(overlay);
107
+ positionOverlay(overlay, el);
108
+ });
109
+ currentHighlightedElements = elements;
110
+ };
111
+ // Handle mouse out event
112
+ const handleMouseOut = () => {
113
+ if (isPopoverDragging)
114
+ return;
115
+ clearHoverOverlays();
116
+ };
117
+ // Handle element click
118
+ const handleElementClick = (e) => {
119
+ if (!isVisualEditMode)
120
+ return;
121
+ const target = e.target;
122
+ // Close dropdowns when clicking anywhere in iframe if a dropdown is open
123
+ if (isDropdownOpen) {
124
+ e.preventDefault();
125
+ e.stopPropagation();
126
+ e.stopImmediatePropagation();
127
+ window.parent.postMessage({ type: "close-dropdowns" }, "*");
128
+ return;
129
+ }
130
+ // Prevent clicking on SVG path elements
131
+ if (target.tagName.toLowerCase() === "path") {
132
+ return;
133
+ }
134
+ // Prevent default behavior immediately when in visual edit mode
135
+ e.preventDefault();
136
+ e.stopPropagation();
137
+ e.stopImmediatePropagation();
138
+ // Support both data-source-location and data-visual-selector-id
139
+ const element = target.closest("[data-source-location], [data-visual-selector-id]");
140
+ if (!element) {
141
+ return;
142
+ }
143
+ const htmlElement = element;
144
+ const visualSelectorId = htmlElement.dataset.sourceLocation ||
145
+ htmlElement.dataset.visualSelectorId;
146
+ // Clear any existing selected overlays
147
+ selectedOverlays.forEach((overlay) => {
148
+ if (overlay && overlay.parentNode) {
149
+ overlay.remove();
150
+ }
151
+ });
152
+ selectedOverlays = [];
153
+ // Find all elements with the same ID
154
+ const elements = findElementsById(visualSelectorId || null);
155
+ // Create selected overlays for all matching elements
156
+ elements.forEach((el) => {
157
+ const overlay = createOverlay(true);
158
+ document.body.appendChild(overlay);
159
+ selectedOverlays.push(overlay);
160
+ positionOverlay(overlay, el, true);
161
+ });
162
+ selectedElementId = visualSelectorId || null;
163
+ // Clear hover overlays
164
+ clearHoverOverlays();
165
+ // Calculate element position for popover positioning
166
+ const rect = element.getBoundingClientRect();
167
+ const elementPosition = {
168
+ top: rect.top,
169
+ left: rect.left,
170
+ right: rect.right,
171
+ bottom: rect.bottom,
172
+ width: rect.width,
173
+ height: rect.height,
174
+ centerX: rect.left + rect.width / 2,
175
+ centerY: rect.top + rect.height / 2,
176
+ };
177
+ // Send message to parent window with element info including position
178
+ const svgElement = element;
179
+ const elementData = {
180
+ type: "element-selected",
181
+ tagName: element.tagName,
182
+ classes: svgElement.className?.baseVal ||
183
+ element.className ||
184
+ "",
185
+ visualSelectorId: visualSelectorId,
186
+ content: element.innerText,
187
+ dataSourceLocation: htmlElement.dataset.sourceLocation,
188
+ isDynamicContent: htmlElement.dataset.dynamicContent === "true",
189
+ linenumber: htmlElement.dataset.linenumber,
190
+ filename: htmlElement.dataset.filename,
191
+ position: elementPosition,
192
+ };
193
+ window.parent.postMessage(elementData, "*");
194
+ };
195
+ // Unselect the current element
196
+ const unselectElement = () => {
197
+ selectedOverlays.forEach((overlay) => {
198
+ if (overlay && overlay.parentNode) {
199
+ overlay.remove();
200
+ }
201
+ });
202
+ selectedOverlays = [];
203
+ selectedElementId = null;
204
+ };
205
+ const updateElementClassesAndReposition = (visualSelectorId, classes) => {
206
+ const elements = findElementsById(visualSelectorId);
207
+ if (elements.length === 0)
208
+ return;
209
+ updateElementClasses(elements, classes);
210
+ // Use a small delay to allow the browser to recalculate layout before repositioning
211
+ setTimeout(() => {
212
+ // Reposition selected overlays
213
+ if (selectedElementId === visualSelectorId) {
214
+ selectedOverlays.forEach((overlay, index) => {
215
+ if (index < elements.length) {
216
+ positionOverlay(overlay, elements[index]);
217
+ }
218
+ });
219
+ }
220
+ // Reposition hover overlays if needed
221
+ if (currentHighlightedElements.length > 0) {
222
+ const hoveredElement = currentHighlightedElements[0];
223
+ const hoveredId = hoveredElement?.dataset?.visualSelectorId;
224
+ if (hoveredId === visualSelectorId) {
225
+ hoverOverlays.forEach((overlay, index) => {
226
+ if (index < currentHighlightedElements.length) {
227
+ positionOverlay(overlay, currentHighlightedElements[index]);
228
+ }
229
+ });
230
+ }
231
+ }
232
+ }, 50);
233
+ };
234
+ // Update element content by visual selector ID
235
+ const updateElementContent = (visualSelectorId, content) => {
236
+ const elements = findElementsById(visualSelectorId);
237
+ if (elements.length === 0) {
238
+ return;
239
+ }
240
+ elements.forEach((element) => {
241
+ element.innerText = content;
242
+ });
243
+ setTimeout(() => {
244
+ if (selectedElementId === visualSelectorId) {
245
+ selectedOverlays.forEach((overlay, index) => {
246
+ if (index < elements.length) {
247
+ positionOverlay(overlay, elements[index]);
248
+ }
249
+ });
250
+ }
251
+ }, 50);
252
+ };
253
+ // Toggle visual edit mode
254
+ const toggleVisualEditMode = (isEnabled) => {
255
+ isVisualEditMode = isEnabled;
256
+ if (!isEnabled) {
257
+ clearHoverOverlays();
258
+ selectedOverlays.forEach((overlay) => {
259
+ if (overlay && overlay.parentNode) {
260
+ overlay.remove();
261
+ }
262
+ });
263
+ selectedOverlays = [];
264
+ currentHighlightedElements = [];
265
+ selectedElementId = null;
266
+ document.body.style.cursor = "default";
267
+ document.removeEventListener("mouseover", handleMouseOver);
268
+ document.removeEventListener("mouseout", handleMouseOut);
269
+ document.removeEventListener("click", handleElementClick, true);
270
+ }
271
+ else {
272
+ document.body.style.cursor = "crosshair";
273
+ document.addEventListener("mouseover", handleMouseOver);
274
+ document.addEventListener("mouseout", handleMouseOut);
275
+ document.addEventListener("click", handleElementClick, true);
276
+ }
277
+ };
278
+ // Handle scroll events to update popover position
279
+ const handleScroll = () => {
280
+ if (selectedElementId) {
281
+ const elements = findElementsById(selectedElementId);
282
+ if (elements.length > 0) {
283
+ const element = elements[0];
284
+ const rect = element.getBoundingClientRect();
285
+ const viewportHeight = window.innerHeight;
286
+ const viewportWidth = window.innerWidth;
287
+ const isInViewport = rect.top < viewportHeight &&
288
+ rect.bottom > 0 &&
289
+ rect.left < viewportWidth &&
290
+ rect.right > 0;
291
+ const elementPosition = {
292
+ top: rect.top,
293
+ left: rect.left,
294
+ right: rect.right,
295
+ bottom: rect.bottom,
296
+ width: rect.width,
297
+ height: rect.height,
298
+ centerX: rect.left + rect.width / 2,
299
+ centerY: rect.top + rect.height / 2,
300
+ };
301
+ window.parent.postMessage({
302
+ type: "element-position-update",
303
+ position: elementPosition,
304
+ isInViewport: isInViewport,
305
+ visualSelectorId: selectedElementId,
306
+ }, "*");
307
+ }
308
+ }
309
+ };
310
+ // Handle messages from parent window
311
+ const handleMessage = (event) => {
312
+ const message = event.data;
313
+ switch (message.type) {
314
+ case "toggle-visual-edit-mode":
315
+ toggleVisualEditMode(message.data.enabled);
316
+ break;
317
+ case "update-classes":
318
+ if (message.data && message.data.classes !== undefined) {
319
+ updateElementClassesAndReposition(message.data.visualSelectorId, message.data.classes);
320
+ }
321
+ else {
322
+ console.warn("[VisualEditAgent] Invalid update-classes message:", message);
323
+ }
324
+ break;
325
+ case "unselect-element":
326
+ unselectElement();
327
+ break;
328
+ case "refresh-page":
329
+ window.location.reload();
330
+ break;
331
+ case "update-content":
332
+ if (message.data && message.data.content !== undefined) {
333
+ updateElementContent(message.data.visualSelectorId, message.data.content);
334
+ }
335
+ else {
336
+ console.warn("[VisualEditAgent] Invalid update-content message:", message);
337
+ }
338
+ break;
339
+ case "request-element-position":
340
+ if (selectedElementId) {
341
+ const elements = findElementsById(selectedElementId);
342
+ if (elements.length > 0) {
343
+ const element = elements[0];
344
+ const rect = element.getBoundingClientRect();
345
+ const viewportHeight = window.innerHeight;
346
+ const viewportWidth = window.innerWidth;
347
+ const isInViewport = rect.top < viewportHeight &&
348
+ rect.bottom > 0 &&
349
+ rect.left < viewportWidth &&
350
+ rect.right > 0;
351
+ const elementPosition = {
352
+ top: rect.top,
353
+ left: rect.left,
354
+ right: rect.right,
355
+ bottom: rect.bottom,
356
+ width: rect.width,
357
+ height: rect.height,
358
+ centerX: rect.left + rect.width / 2,
359
+ centerY: rect.top + rect.height / 2,
360
+ };
361
+ window.parent.postMessage({
362
+ type: "element-position-update",
363
+ position: elementPosition,
364
+ isInViewport: isInViewport,
365
+ visualSelectorId: selectedElementId,
366
+ }, "*");
367
+ }
368
+ }
369
+ break;
370
+ case "popover-drag-state":
371
+ if (message.data && message.data.isDragging !== undefined) {
372
+ isPopoverDragging = message.data.isDragging;
373
+ if (message.data.isDragging) {
374
+ clearHoverOverlays();
375
+ }
376
+ }
377
+ break;
378
+ case "dropdown-state":
379
+ if (message.data && message.data.isOpen !== undefined) {
380
+ isDropdownOpen = message.data.isOpen;
381
+ if (message.data.isOpen) {
382
+ clearHoverOverlays();
383
+ }
384
+ }
385
+ break;
386
+ case "update-theme-variables":
387
+ if (message.data?.variables) {
388
+ const style = document.documentElement.style;
389
+ for (const [name, value] of Object.entries(message.data.variables)) {
390
+ style.setProperty(name, value);
391
+ }
392
+ }
393
+ break;
394
+ default:
395
+ break;
396
+ }
397
+ };
398
+ // Handle window resize to reposition overlays
399
+ const handleResize = () => {
400
+ if (selectedElementId) {
401
+ const elements = findElementsById(selectedElementId);
402
+ selectedOverlays.forEach((overlay, index) => {
403
+ if (index < elements.length) {
404
+ positionOverlay(overlay, elements[index]);
405
+ }
406
+ });
407
+ }
408
+ if (currentHighlightedElements.length > 0) {
409
+ hoverOverlays.forEach((overlay, index) => {
410
+ if (index < currentHighlightedElements.length) {
411
+ positionOverlay(overlay, currentHighlightedElements[index]);
412
+ }
413
+ });
414
+ }
415
+ };
416
+ // Initialize: Add IDs to elements that don't have them but have linenumbers
417
+ const elementsWithLineNumber = document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])");
418
+ elementsWithLineNumber.forEach((el, index) => {
419
+ const htmlEl = el;
420
+ const id = `visual-id-${htmlEl.dataset.filename}-${htmlEl.dataset.linenumber}-${index}`;
421
+ htmlEl.dataset.visualSelectorId = id;
422
+ });
423
+ // Create mutation observer to detect layout changes
424
+ const mutationObserver = new MutationObserver((mutations) => {
425
+ const needsUpdate = mutations.some((mutation) => {
426
+ const hasVisualId = (node) => {
427
+ if (node.nodeType === Node.ELEMENT_NODE) {
428
+ const el = node;
429
+ if (el.dataset && el.dataset.visualSelectorId) {
430
+ return true;
431
+ }
432
+ for (let i = 0; i < el.children.length; i++) {
433
+ if (hasVisualId(el.children[i])) {
434
+ return true;
435
+ }
436
+ }
437
+ }
438
+ return false;
439
+ };
440
+ const isLayoutChange = mutation.type === "attributes" &&
441
+ (mutation.attributeName === "style" ||
442
+ mutation.attributeName === "class" ||
443
+ mutation.attributeName === "width" ||
444
+ mutation.attributeName === "height");
445
+ return isLayoutChange && hasVisualId(mutation.target);
446
+ });
447
+ if (needsUpdate) {
448
+ setTimeout(handleResize, 50);
449
+ }
450
+ });
451
+ // Set up event listeners
452
+ window.addEventListener("message", handleMessage);
453
+ window.addEventListener("scroll", handleScroll, true);
454
+ document.addEventListener("scroll", handleScroll, true);
455
+ window.addEventListener("resize", handleResize);
456
+ window.addEventListener("scroll", handleResize);
457
+ // Start observing DOM mutations
458
+ mutationObserver.observe(document.body, {
459
+ attributes: true,
460
+ childList: true,
461
+ subtree: true,
462
+ attributeFilter: ["style", "class", "width", "height"],
463
+ });
464
+ // Send ready message to parent
465
+ window.parent.postMessage({ type: "visual-edit-agent-ready" }, "*");
466
+ }
2
467
  //# sourceMappingURL=visual-edit-agent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"visual-edit-agent.js","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"visual-edit-agent.js","sourceRoot":"","sources":["../../src/injections/visual-edit-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,UAAU,oBAAoB;IAClC,oDAAoD;IACpD,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,aAAa,GAAqB,EAAE,CAAC;IACzC,IAAI,gBAAgB,GAAqB,EAAE,CAAC;IAC5C,IAAI,0BAA0B,GAAc,EAAE,CAAC;IAC/C,IAAI,iBAAiB,GAAkB,IAAI,CAAC;IAE5C,yBAAyB;IACzB,MAAM,aAAa,GAAG,CAAC,UAAU,GAAG,KAAK,EAAkB,EAAE;QAC3D,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC;QACrC,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,sBAAsB,CAAC;QAClD,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QAE9B,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC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1,isDropdownOpen:!1,hoverOverlays:[],selectedOverlays:[],currentHighlightedElements:[],selectedElementId:null,currentEditingElement:null,debouncedSendTimeout:null,isInlineEditExperimentEnabled:!1}}function l(e){if(!e)return[];let t=Array.from(document.querySelectorAll(`[data-source-location="${e}"]`));return t.length>0?t:Array.from(document.querySelectorAll(`[data-visual-selector-id="${e}"]`))}function P(e,t){e.forEach(n=>{n.setAttribute("class",t)})}var H="all 0.1s ease-in-out",V="9999",U="#2563EB",G="#95a5fc",B="rgba(99, 102, 241, 0.05)",k="-27px",F="-2px";function m(e=!1){let t=document.createElement("div");return t.style.position="absolute",t.style.pointerEvents="none",t.style.transition=H,t.style.zIndex=V,e?t.style.border=`2px solid ${U}`:(t.style.border=`2px solid ${G}`,t.style.backgroundColor=B),t}function E(e,t,n=!1,o=!0){if(!t||!o)return;t.offsetWidth;let r=t.getBoundingClientRect();e.style.top=`${r.top+window.scrollY}px`,e.style.left=`${r.left+window.scrollX}px`,e.style.width=`${r.width}px`,e.style.height=`${r.height}px`;let i=e.querySelector("div");i||(i=document.createElement("div"),i.textContent=t.tagName.toLowerCase(),i.style.position="absolute",i.style.top=k,i.style.left=F,i.style.padding="2px 8px",i.style.fontSize="11px",i.style.fontWeight=n?"500":"400",i.style.color=n?"#ffffff":"#526cff",i.style.backgroundColor=n?"#526cff":"#DBEAFE",i.style.borderRadius="3px",i.style.minWidth="24px",i.style.textAlign="center",e.appendChild(i))}function h(e){e.forEach(t=>{t&&t.parentNode&&t.remove()})}function c(e){e.isInlineEditExperimentEnabled&&e.selectedElementId&&l(e.selectedElementId).forEach(n=>{n instanceof HTMLElement&&delete n.dataset.selected}),h(e.selectedOverlays),e.selectedOverlays=[],e.selectedElementId=null}function u(e){if(!e.selectedElementId)return;let t=l(e.selectedElementId);e.selectedOverlays.forEach((n,o)=>{let r=t[o];r&&E(n,r,!0,e.isVisualEditMode)})}function O(e){e.hoverOverlays.forEach((t,n)=>{let o=e.currentHighlightedElements[n];o&&E(t,o,!1,e.isVisualEditMode)})}function s(e){h(e.hoverOverlays),e.hoverOverlays=[],e.currentHighlightedElements=[]}function j(e,t){if(!e.isVisualEditMode||e.isPopoverDragging||e.currentEditingElement)return;let n=t.target;if(e.isDropdownOpen){s(e);return}if(n.tagName.toLowerCase()==="path"){s(e);return}let o=n.closest("[data-source-location], [data-visual-selector-id]");if(!o){s(e);return}let r=o,i=r.dataset.sourceLocation||r.dataset.visualSelectorId;if(e.selectedElementId===i){s(e);return}let a=l(i||null);s(e),a.forEach(g=>{let S=m(!1);document.body.appendChild(S),e.hoverOverlays.push(S),E(S,g,!1,e.isVisualEditMode)}),e.currentHighlightedElements=a}function W(e){e.isPopoverDragging||e.currentEditingElement||s(e)}function y(){if(document.getElementById("visual-edit-focus-styles"))return;let t=document.createElement("style");t.id="visual-edit-focus-styles",t.textContent=`
2
- [data-selected="true"][contenteditable="true"]:focus {
3
- outline: none !important;
4
- }
5
- `,document.head.appendChild(t)}function M(){let e=document.getElementById("visual-edit-focus-styles");e&&e.remove()}function L(e){let t=document.createRange();t.selectNodeContents(e);let n=window.getSelection();n?.removeAllRanges(),n?.addRange(t)}function b(e){return!(!(e instanceof HTMLElement)||!["div","p","h1","h2","h3","h4","h5","h6","span","li","td","a","button","label"].includes(e.tagName.toLowerCase())||(e.textContent?.trim()||"").length===0||e.querySelector("img, video, canvas, svg")!==null||e.children.length>0||e.dataset.dynamicContent==="true")}var x=null;function A(e){x=e}var C=new WeakMap;function ee(e){x&&x(this)}function f(e){return!(!(e instanceof HTMLElement)||e.dataset.selected!=="true"||!b(e))}function _(e){y(),e.dataset.originalTextContent=e.textContent||"",e.dataset.originalCursor=e.style.cursor,e.contentEditable="true";let t=new AbortController;C.set(e,t),e.addEventListener("input",ee,{signal:t.signal}),e.style.cursor="text",L(e),setTimeout(()=>{e.focus()},0)}function D(e){let t=C.get(e);t&&(t.abort(),C.delete(e)),e.isConnected&&(M(),e.contentEditable="false",delete e.dataset.originalTextContent,e.dataset.originalCursor!==void 0&&(e.style.cursor=e.dataset.originalCursor,delete e.dataset.originalCursor))}function p(e){return{top:e.top,left:e.left,right:e.right,bottom:e.bottom,width:e.width,height:e.height,centerX:e.left+e.width/2,centerY:e.top+e.height/2}}function Y(e){return e.top<window.innerHeight&&e.bottom>0&&e.left<window.innerWidth&&e.right>0}function T(e){return e instanceof SVGElement?e.className?.baseVal||"":e.className||""}function v(e,t){e.currentEditingElement=t,e.selectedOverlays.forEach(n=>{n.style.display="none"}),_(t),window.parent.postMessage({type:"content-editing-started",visualSelectorId:e.selectedElementId},"*")}function d(e){if(!e.currentEditingElement)return;e.debouncedSendTimeout&&(clearTimeout(e.debouncedSendTimeout),e.debouncedSendTimeout=null);let t=e.currentEditingElement;D(t),e.selectedOverlays.forEach(n=>{n.style.display=""}),u(e),window.parent.postMessage({type:"content-editing-ended",visualSelectorId:e.selectedElementId},"*"),e.currentEditingElement=null}function ne(e,t){let n=t.dataset.originalTextContent,o=t.textContent,r={tagName:t.tagName,classes:T(t),visualSelectorId:e.selectedElementId,content:o,dataSourceLocation:t.dataset.sourceLocation,isDynamicContent:t.dataset.dynamicContent==="true",linenumber:t.dataset.linenumber,filename:t.dataset.filename,position:p(t.getBoundingClientRect())};window.parent.postMessage({type:"inline-edit",elementInfo:r,originalContent:n,newContent:o},"*"),t.dataset.originalTextContent=o||""}function oe(e,t){e.debouncedSendTimeout&&clearTimeout(e.debouncedSendTimeout),e.debouncedSendTimeout=setTimeout(()=>{ne(e,t)},500)}function ie(e){return t=>{u(e),oe(e,t)}}function $(e){A(ie(e))}function re(e,t,n){e.currentEditingElement&&d(e),c(e);let o=l(n);e.isInlineEditExperimentEnabled&&o.forEach(a=>{a instanceof HTMLElement&&(a.dataset.selected="true")}),o.forEach(a=>{let g=m(!0);document.body.appendChild(g),e.selectedOverlays.push(g),E(g,a,!0,e.isVisualEditMode)}),e.selectedElementId=n,s(e);let r=t,i={type:"element-selected",tagName:t.tagName,classes:T(t),visualSelectorId:n,content:r.innerText,dataSourceLocation:r.dataset.sourceLocation,isDynamicContent:r.dataset.dynamicContent==="true",linenumber:r.dataset.linenumber,filename:r.dataset.filename,position:p(t.getBoundingClientRect())};window.parent.postMessage(i,"*")}function q(e,t){if(!e.isVisualEditMode)return;let n=t.target;if(e.isInlineEditExperimentEnabled&&n instanceof HTMLElement&&n.contentEditable==="true")return;if(e.currentEditingElement){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),d(e);return}if(e.isDropdownOpen){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}if(n.tagName.toLowerCase()==="path")return;t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation();let o=n.closest("[data-source-location], [data-visual-selector-id]");if(!o)return;let r=o,i=r.dataset.sourceLocation||r.dataset.visualSelectorId;if(e.selectedElementId===i&&r.dataset.selected==="true"&&e.isInlineEditExperimentEnabled&&f(r)){v(e,r);return}re(e,o,i||null)}function le(e,t){e.isVisualEditMode=t,t?document.body.style.cursor="crosshair":(e.currentEditingElement&&d(e),s(e),c(e),e.currentHighlightedElements=[],document.body.style.cursor="default")}function z(e,t){le(e,t.data.enabled),t.data.specs?.newInlineEditEnabled!==void 0&&(e.isInlineEditExperimentEnabled=t.data.specs.newInlineEditEnabled)}function X(e,t){if(!e.isInlineEditExperimentEnabled||!t.data||!t.data.dataSourceLocation)return;let n=l(t.data.dataSourceLocation);if(n.length===0||!(n[0]instanceof HTMLElement))return;let o=n[0];if(t.data.inlineEditingMode){if(f(o)){if(e.selectedElementId!==t.data.dataSourceLocation){e.currentEditingElement&&d(e),c(e);let r=l(t.data.dataSourceLocation);r.forEach(i=>{i instanceof HTMLElement&&(i.dataset.selected="true")}),r.forEach(i=>{let a=m(!0);document.body.appendChild(a),e.selectedOverlays.push(a),E(a,i,!0,e.isVisualEditMode)}),e.selectedElementId=t.data.dataSourceLocation}v(e,o)}}else e.currentEditingElement===o&&d(e)}function K(e){if(!e.selectedElementId)return;let t=l(e.selectedElementId),[n]=t;if(!n)return;let o=n.getBoundingClientRect();window.parent.postMessage({type:"element-position-update",position:p(o),isInViewport:Y(o),visualSelectorId:e.selectedElementId},"*")}function ae(e){e.currentEditingElement&&d(e),c(e)}function se(e,t,n){let o=l(t);o.length!==0&&(P(o,n),setTimeout(()=>{e.selectedElementId===t&&u(e),e.currentHighlightedElements.length>0&&e.currentHighlightedElements[0]?.dataset?.visualSelectorId===t&&O(e)},50))}function de(e,t,n){let o=l(t);o.length!==0&&(o.forEach(r=>{r.innerText=n}),setTimeout(()=>{e.selectedElementId===t&&u(e)},50))}function w(e){K(e)}function I(e){u(e),O(e)}function Z(e,t){let n=t.data;switch(n.type){case"toggle-visual-edit-mode":z(e,n);break;case"update-classes":n.data&&n.data.classes!==void 0?se(e,n.data.visualSelectorId,n.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",n);break;case"unselect-element":ae(e);break;case"refresh-page":window.location.reload();break;case"update-content":n.data&&n.data.content!==void 0?de(e,n.data.visualSelectorId,n.data.content):console.warn("[VisualEditAgent] Invalid update-content message:",n);break;case"toggle-inline-edit-mode":X(e,n);break;case"request-element-position":K(e);break;case"popover-drag-state":n.data&&n.data.isDragging!==void 0&&(e.isPopoverDragging=n.data.isDragging,n.data.isDragging&&s(e));break;case"dropdown-state":n.data&&n.data.isOpen!==void 0&&(e.isDropdownOpen=n.data.isOpen,n.data.isOpen&&s(e));break;default:break}}function Ee(){document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((t,n)=>{let o=t,r=`visual-id-${o.dataset.filename}-${o.dataset.linenumber}-${n}`;o.dataset.visualSelectorId=r})}function ce(e){let t=null,n=o=>{if(o.nodeType!==Node.ELEMENT_NODE)return!1;let r=o;if(r.dataset?.visualSelectorId)return!0;for(let i of Array.from(r.children))if(n(i))return!0;return!1};return new MutationObserver(o=>{if(t!==null)return;o.some(i=>i.type==="attributes"&&(i.attributeName==="style"||i.attributeName==="class"||i.attributeName==="width"||i.attributeName==="height")&&n(i.target))&&(t=requestAnimationFrame(()=>{t=null,e()}))})}function ue(e){window.addEventListener("message",t=>Z(e,t)),window.addEventListener("scroll",()=>w(e),!0),document.addEventListener("scroll",()=>w(e),!0),window.addEventListener("resize",()=>I(e)),window.addEventListener("scroll",()=>I(e)),document.addEventListener("click",t=>q(e,t),!0),document.addEventListener("mouseover",t=>j(e,t)),document.addEventListener("mouseout",()=>W(e))}function J(){let e=R();Ee(),$(e),ue(e),ce(()=>I(e)).observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{J as setupVisualEditAgent};
1
+ function h(d){if(!d)return[];let f=Array.from(document.querySelectorAll(`[data-source-location="${d}"]`));return f.length>0?f:Array.from(document.querySelectorAll(`[data-visual-selector-id="${d}"]`))}function T(d,f){d.forEach(g=>{g.setAttribute("class",f)})}function V(){let d=!1,f=!1,g=!1,E=[],c=[],u=[],l=null,L=(n=!1)=>{let e=document.createElement("div");return e.style.position="absolute",e.style.pointerEvents="none",e.style.transition="all 0.1s ease-in-out",e.style.zIndex="9999",n?e.style.border="2px solid #2563EB":(e.style.border="2px solid #95a5fc",e.style.backgroundColor="rgba(99, 102, 241, 0.05)"),e},p=(n,e,t=!1)=>{if(!e||!d)return;e.offsetWidth;let s=e.getBoundingClientRect();n.style.top=`${s.top+window.scrollY}px`,n.style.left=`${s.left+window.scrollX}px`,n.style.width=`${s.width}px`,n.style.height=`${s.height}px`;let o=n.querySelector("div");o||(o=document.createElement("div"),o.textContent=e.tagName.toLowerCase(),o.style.position="absolute",o.style.top="-27px",o.style.left="-2px",o.style.padding="2px 8px",o.style.fontSize="11px",o.style.fontWeight=t?"500":"400",o.style.color=t?"#ffffff":"#526cff",o.style.backgroundColor=t?"#526cff":"#DBEAFE",o.style.borderRadius="3px",o.style.minWidth="24px",o.style.textAlign="center",n.appendChild(o))},m=()=>{E.forEach(n=>{n&&n.parentNode&&n.remove()}),E=[],u=[]},M=n=>{if(!d||f)return;let e=n.target;if(g){m();return}if(e.tagName.toLowerCase()==="path"){m();return}let t=e.closest("[data-source-location], [data-visual-selector-id]");if(!t){m();return}let a=t,s=a.dataset.sourceLocation||a.dataset.visualSelectorId;if(l===s){m();return}let o=h(s||null);m(),o.forEach(i=>{let r=L(!1);document.body.appendChild(r),E.push(r),p(r,i)}),u=o},I=()=>{f||m()},C=n=>{if(!d)return;let e=n.target;if(g){n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation(),window.parent.postMessage({type:"close-dropdowns"},"*");return}if(e.tagName.toLowerCase()==="path")return;n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation();let t=e.closest("[data-source-location], [data-visual-selector-id]");if(!t)return;let a=t,s=a.dataset.sourceLocation||a.dataset.visualSelectorId;c.forEach(v=>{v&&v.parentNode&&v.remove()}),c=[],h(s||null).forEach(v=>{let y=L(!0);document.body.appendChild(y),c.push(y),p(y,v,!0)}),l=s||null,m();let i=t.getBoundingClientRect(),r={top:i.top,left:i.left,right:i.right,bottom:i.bottom,width:i.width,height:i.height,centerX:i.left+i.width/2,centerY:i.top+i.height/2},b=t,A={type:"element-selected",tagName:t.tagName,classes:b.className?.baseVal||t.className||"",visualSelectorId:s,content:t.innerText,dataSourceLocation:a.dataset.sourceLocation,isDynamicContent:a.dataset.dynamicContent==="true",linenumber:a.dataset.linenumber,filename:a.dataset.filename,position:r};window.parent.postMessage(A,"*")},H=()=>{c.forEach(n=>{n&&n.parentNode&&n.remove()}),c=[],l=null},x=(n,e)=>{let t=h(n);t.length!==0&&(T(t,e),setTimeout(()=>{l===n&&c.forEach((a,s)=>{s<t.length&&p(a,t[s])}),u.length>0&&u[0]?.dataset?.visualSelectorId===n&&E.forEach((o,i)=>{i<u.length&&p(o,u[i])})},50))},k=(n,e)=>{let t=h(n);t.length!==0&&(t.forEach(a=>{a.innerText=e}),setTimeout(()=>{l===n&&c.forEach((a,s)=>{s<t.length&&p(a,t[s])})},50))},D=n=>{d=n,n?(document.body.style.cursor="crosshair",document.addEventListener("mouseover",M),document.addEventListener("mouseout",I),document.addEventListener("click",C,!0)):(m(),c.forEach(e=>{e&&e.parentNode&&e.remove()}),c=[],u=[],l=null,document.body.style.cursor="default",document.removeEventListener("mouseover",M),document.removeEventListener("mouseout",I),document.removeEventListener("click",C,!0))},N=()=>{if(l){let n=h(l);if(n.length>0){let t=n[0].getBoundingClientRect(),a=window.innerHeight,s=window.innerWidth,o=t.top<a&&t.bottom>0&&t.left<s&&t.right>0,i={top:t.top,left:t.left,right:t.right,bottom:t.bottom,width:t.width,height:t.height,centerX:t.left+t.width/2,centerY:t.top+t.height/2};window.parent.postMessage({type:"element-position-update",position:i,isInViewport:o,visualSelectorId:l},"*")}}},S=n=>{let e=n.data;switch(e.type){case"toggle-visual-edit-mode":D(e.data.enabled);break;case"update-classes":e.data&&e.data.classes!==void 0?x(e.data.visualSelectorId,e.data.classes):console.warn("[VisualEditAgent] Invalid update-classes message:",e);break;case"unselect-element":H();break;case"refresh-page":window.location.reload();break;case"update-content":e.data&&e.data.content!==void 0?k(e.data.visualSelectorId,e.data.content):console.warn("[VisualEditAgent] Invalid update-content message:",e);break;case"request-element-position":if(l){let t=h(l);if(t.length>0){let s=t[0].getBoundingClientRect(),o=window.innerHeight,i=window.innerWidth,r=s.top<o&&s.bottom>0&&s.left<i&&s.right>0,b={top:s.top,left:s.left,right:s.right,bottom:s.bottom,width:s.width,height:s.height,centerX:s.left+s.width/2,centerY:s.top+s.height/2};window.parent.postMessage({type:"element-position-update",position:b,isInViewport:r,visualSelectorId:l},"*")}}break;case"popover-drag-state":e.data&&e.data.isDragging!==void 0&&(f=e.data.isDragging,e.data.isDragging&&m());break;case"dropdown-state":e.data&&e.data.isOpen!==void 0&&(g=e.data.isOpen,e.data.isOpen&&m());break;case"update-theme-variables":if(e.data?.variables){let t=document.documentElement.style;for(let[a,s]of Object.entries(e.data.variables))t.setProperty(a,s)}break;default:break}},w=()=>{if(l){let n=h(l);c.forEach((e,t)=>{t<n.length&&p(e,n[t])})}u.length>0&&E.forEach((n,e)=>{e<u.length&&p(n,u[e])})};document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((n,e)=>{let t=n,a=`visual-id-${t.dataset.filename}-${t.dataset.linenumber}-${e}`;t.dataset.visualSelectorId=a});let O=new MutationObserver(n=>{n.some(t=>{let a=o=>{if(o.nodeType===Node.ELEMENT_NODE){let i=o;if(i.dataset&&i.dataset.visualSelectorId)return!0;for(let r=0;r<i.children.length;r++)if(a(i.children[r]))return!0}return!1};return t.type==="attributes"&&(t.attributeName==="style"||t.attributeName==="class"||t.attributeName==="width"||t.attributeName==="height")&&a(t.target)})&&setTimeout(w,50)});window.addEventListener("message",S),window.addEventListener("scroll",N,!0),document.addEventListener("scroll",N,!0),window.addEventListener("resize",w),window.addEventListener("scroll",w),O.observe(document.body,{attributes:!0,childList:!0,subtree:!0,attributeFilter:["style","class","width","height"]}),window.parent.postMessage({type:"visual-edit-agent-ready"},"*")}export{V as setupVisualEditAgent};
6
2
  //# sourceMappingURL=index.mjs.map