fixdog 0.0.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.
@@ -0,0 +1,1593 @@
1
+ "use client";
2
+
3
+ // src/client/init.tsx
4
+ import { useEffect as useEffect3 } from "react";
5
+
6
+ // src/instrument.ts
7
+ import {
8
+ instrument,
9
+ secure,
10
+ isCompositeFiber,
11
+ isHostFiber,
12
+ traverseFiber,
13
+ getDisplayName,
14
+ getFiberFromHostInstance
15
+ } from "bippy";
16
+ import { getSource } from "bippy/source";
17
+ var isInstrumented = false;
18
+ function setupBippyInstrumentation() {
19
+ if (isInstrumented)
20
+ return;
21
+ if (typeof window === "undefined")
22
+ return;
23
+ isInstrumented = true;
24
+ instrument(
25
+ secure({
26
+ onCommitFiberRoot: (_rendererID, _fiberRoot) => {
27
+ }
28
+ })
29
+ );
30
+ }
31
+ async function getSourceFromElement(element) {
32
+ try {
33
+ const fiber = getFiberFromHostInstance(element);
34
+ if (!fiber) {
35
+ return null;
36
+ }
37
+ const source = await getSource(fiber);
38
+ if (source && source.fileName) {
39
+ if (source.fileName.includes("node_modules") || source.fileName.includes("react-dom") || source.fileName.includes("react/")) {
40
+ return await findUserSourceFromFiber(fiber);
41
+ }
42
+ return {
43
+ fileName: source.fileName,
44
+ lineNumber: source.lineNumber ?? 1,
45
+ columnNumber: source.columnNumber ?? 1,
46
+ functionName: source.functionName ?? void 0
47
+ };
48
+ }
49
+ return await findUserSourceFromFiber(fiber);
50
+ } catch (error) {
51
+ console.warn("[UiDog Next] Error getting source from element:", error);
52
+ return null;
53
+ }
54
+ }
55
+ async function findUserSourceFromFiber(startFiber) {
56
+ let result = null;
57
+ traverseFiber(
58
+ startFiber,
59
+ async (fiber) => {
60
+ if (isCompositeFiber(fiber)) {
61
+ try {
62
+ const source = await getSource(fiber);
63
+ if (source && source.fileName) {
64
+ if (!source.fileName.includes("node_modules") && !source.fileName.includes("react-dom") && !source.fileName.includes("react/")) {
65
+ result = {
66
+ fileName: source.fileName,
67
+ lineNumber: source.lineNumber ?? 1,
68
+ columnNumber: source.columnNumber ?? 1,
69
+ functionName: source.functionName ?? getDisplayName(fiber) ?? void 0
70
+ };
71
+ return true;
72
+ }
73
+ }
74
+ } catch {
75
+ }
76
+ }
77
+ return false;
78
+ },
79
+ true
80
+ // Traverse upward (toward root)
81
+ );
82
+ return result;
83
+ }
84
+ function getComponentNameFromFiber(fiber) {
85
+ if (!fiber)
86
+ return "Unknown";
87
+ const displayName = getDisplayName(fiber);
88
+ if (displayName && displayName !== "Unknown") {
89
+ return displayName;
90
+ }
91
+ let componentName = "Unknown";
92
+ traverseFiber(
93
+ fiber,
94
+ (f) => {
95
+ if (isCompositeFiber(f)) {
96
+ const name = getDisplayName(f);
97
+ if (name && name !== "Unknown") {
98
+ componentName = name;
99
+ return true;
100
+ }
101
+ }
102
+ return false;
103
+ },
104
+ true
105
+ // Traverse upward
106
+ );
107
+ return componentName;
108
+ }
109
+
110
+ // src/source-resolver.ts
111
+ var EDITOR_SCHEMES = {
112
+ vscode: "vscode://file/{path}:{line}:{column}",
113
+ "vscode-insiders": "vscode-insiders://file/{path}:{line}:{column}",
114
+ cursor: "cursor://file/{path}:{line}:{column}",
115
+ webstorm: "webstorm://open?file={path}&line={line}&column={column}",
116
+ atom: "atom://core/open/file?filename={path}&line={line}&column={column}",
117
+ sublime: "subl://open?url=file://{path}&line={line}&column={column}"
118
+ };
119
+ function buildEditorUrl(source, editor = "cursor", projectPath = "") {
120
+ const template = EDITOR_SCHEMES[editor] || EDITOR_SCHEMES.cursor;
121
+ let fullPath = normalizeFileName(source.fileName);
122
+ if (projectPath && !fullPath.startsWith("/")) {
123
+ const normalizedProjectPath = projectPath.endsWith("/") ? projectPath.slice(0, -1) : projectPath;
124
+ fullPath = `${normalizedProjectPath}/${fullPath}`;
125
+ }
126
+ return template.replace("{path}", fullPath).replace("{line}", String(source.lineNumber || 1)).replace("{column}", String(source.columnNumber || 1));
127
+ }
128
+ function normalizeFileName(fileName) {
129
+ if (!fileName)
130
+ return "";
131
+ let normalized = fileName;
132
+ const prefixPatterns = [
133
+ /^webpack:\/\/[^/]*\//,
134
+ /^webpack-internal:\/\/\//,
135
+ /^file:\/\//,
136
+ /^about:react/,
137
+ /^\.\//,
138
+ /^https?:\/\/localhost:\d+\//,
139
+ /^https?:\/\/[^/]+\/@fs\//,
140
+ /^https?:\/\/[^/]+\//,
141
+ /^\/@fs\//,
142
+ /^@fs\//
143
+ ];
144
+ for (const pattern of prefixPatterns) {
145
+ normalized = normalized.replace(pattern, "");
146
+ }
147
+ normalized = normalized.split("?")[0].split("#")[0];
148
+ normalized = normalized.replace(/^\/+/, "/");
149
+ return normalized;
150
+ }
151
+ function isSourceFile(fileName) {
152
+ if (!fileName)
153
+ return false;
154
+ const normalized = normalizeFileName(fileName);
155
+ const excludePatterns = [
156
+ /node_modules/,
157
+ /react-dom/,
158
+ /^react\//,
159
+ /\.next\//,
160
+ /_next\//,
161
+ /webpack/,
162
+ /@vite\//,
163
+ /vite\/client/,
164
+ /\[eval\]/,
165
+ /<anonymous>/
166
+ ];
167
+ for (const pattern of excludePatterns) {
168
+ if (pattern.test(normalized)) {
169
+ return false;
170
+ }
171
+ }
172
+ const includeExtensions = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".cjs"];
173
+ return includeExtensions.some(
174
+ (ext) => normalized.toLowerCase().endsWith(ext)
175
+ );
176
+ }
177
+
178
+ // src/element-detector.ts
179
+ var detectorCleanup = null;
180
+ var isSetup = false;
181
+ function setupElementDetector(options) {
182
+ const { onElementSelected, modifier = "alt" } = options;
183
+ if (detectorCleanup) {
184
+ detectorCleanup();
185
+ }
186
+ isSetup = true;
187
+ const handleClick = async (event) => {
188
+ const modifierPressed = modifier === "alt" && event.altKey || modifier === "ctrl" && event.ctrlKey || modifier === "meta" && event.metaKey || modifier === "shift" && event.shiftKey;
189
+ if (!modifierPressed)
190
+ return;
191
+ event.preventDefault();
192
+ event.stopPropagation();
193
+ const target = event.target;
194
+ try {
195
+ const source = await getSourceFromElement(target);
196
+ if (source && source.fileName && isSourceFile(source.fileName)) {
197
+ const fiber = getFiberFromHostInstance(target);
198
+ const componentName = fiber ? getComponentNameFromFiber(fiber) : "Unknown";
199
+ const enrichedSource = {
200
+ ...source,
201
+ functionName: source.functionName || componentName
202
+ };
203
+ onElementSelected(enrichedSource, target);
204
+ } else {
205
+ console.info(
206
+ "[UiDog Next] Could not find source for element. Falling back to DOM snapshot (likely server component or library code)."
207
+ );
208
+ onElementSelected(null, target);
209
+ }
210
+ } catch (error) {
211
+ console.warn("[UiDog Next] Error detecting element source:", error);
212
+ }
213
+ };
214
+ const handleMouseMove = (event) => {
215
+ const modifierPressed = modifier === "alt" && event.altKey || modifier === "ctrl" && event.ctrlKey || modifier === "meta" && event.metaKey || modifier === "shift" && event.shiftKey;
216
+ if (!modifierPressed) {
217
+ removeHighlight();
218
+ return;
219
+ }
220
+ const target = event.target;
221
+ highlightElement(target);
222
+ };
223
+ const handleKeyUp = (event) => {
224
+ const relevantKey = modifier === "alt" && event.key === "Alt" || modifier === "ctrl" && event.key === "Control" || modifier === "meta" && event.key === "Meta" || modifier === "shift" && event.key === "Shift";
225
+ if (relevantKey) {
226
+ removeHighlight();
227
+ }
228
+ };
229
+ document.addEventListener("click", handleClick, true);
230
+ document.addEventListener("mousemove", handleMouseMove, true);
231
+ document.addEventListener("keyup", handleKeyUp, true);
232
+ detectorCleanup = () => {
233
+ document.removeEventListener("click", handleClick, true);
234
+ document.removeEventListener("mousemove", handleMouseMove, true);
235
+ document.removeEventListener("keyup", handleKeyUp, true);
236
+ removeHighlight();
237
+ isSetup = false;
238
+ };
239
+ return detectorCleanup;
240
+ }
241
+ var currentHighlight = null;
242
+ var highlightOverlay = null;
243
+ function highlightElement(element) {
244
+ if (element === highlightOverlay || highlightOverlay?.contains(element)) {
245
+ return;
246
+ }
247
+ if (!highlightOverlay) {
248
+ highlightOverlay = document.createElement("div");
249
+ highlightOverlay.id = "uidog-highlight-overlay";
250
+ highlightOverlay.style.cssText = `
251
+ position: fixed;
252
+ pointer-events: none;
253
+ background: rgba(59, 130, 246, 0.2);
254
+ border: 2px solid rgba(59, 130, 246, 0.8);
255
+ border-radius: 4px;
256
+ z-index: 999998;
257
+ transition: all 0.1s ease-out;
258
+ `;
259
+ document.body.appendChild(highlightOverlay);
260
+ }
261
+ const rect = element.getBoundingClientRect();
262
+ highlightOverlay.style.top = `${rect.top}px`;
263
+ highlightOverlay.style.left = `${rect.left}px`;
264
+ highlightOverlay.style.width = `${rect.width}px`;
265
+ highlightOverlay.style.height = `${rect.height}px`;
266
+ highlightOverlay.style.display = "block";
267
+ currentHighlight = element;
268
+ }
269
+ function removeHighlight() {
270
+ if (highlightOverlay) {
271
+ highlightOverlay.style.display = "none";
272
+ }
273
+ currentHighlight = null;
274
+ }
275
+
276
+ // src/sidebar-initializer.ts
277
+ import { createRoot } from "react-dom/client";
278
+ import { createElement } from "react";
279
+
280
+ // src/components/UiDogSidebarReact.tsx
281
+ import { useEffect as useEffect2 } from "react";
282
+
283
+ // src/components/ElementInfoDisplayReact.tsx
284
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
285
+ function ElementInfoDisplayReact(props) {
286
+ const isDomSnapshot = props.elementInfo.kind === "dom";
287
+ if (isDomSnapshot) {
288
+ const dom = props.elementInfo.domSnapshot;
289
+ const outerHTML = dom?.outerHTML || "No HTML available";
290
+ const text = dom?.text || "";
291
+ const attributes = dom?.attributes || {};
292
+ return /* @__PURE__ */ jsxs("div", { className: "uidog-element-info", children: [
293
+ /* @__PURE__ */ jsxs("div", { className: "uidog-element-info-content", children: [
294
+ /* @__PURE__ */ jsx("div", { className: "uidog-file-location", children: "Server-rendered DOM (no source available)" }),
295
+ /* @__PURE__ */ jsx(
296
+ "button",
297
+ {
298
+ className: "uidog-close-btn",
299
+ onClick: props.onClose,
300
+ title: "Close sidebar (ESC)",
301
+ "aria-label": "Close sidebar",
302
+ children: "\xD7"
303
+ }
304
+ )
305
+ ] }),
306
+ /* @__PURE__ */ jsxs("div", { className: "uidog-dom-snapshot", children: [
307
+ /* @__PURE__ */ jsx("div", { className: "uidog-dom-label", children: "outerHTML (trimmed):" }),
308
+ /* @__PURE__ */ jsx("pre", { className: "uidog-dom-snippet", children: outerHTML }),
309
+ text && /* @__PURE__ */ jsxs(Fragment, { children: [
310
+ /* @__PURE__ */ jsx("div", { className: "uidog-dom-label", children: "textContent (trimmed):" }),
311
+ /* @__PURE__ */ jsx("pre", { className: "uidog-dom-snippet", children: text })
312
+ ] }),
313
+ Object.keys(attributes).length > 0 && /* @__PURE__ */ jsxs("div", { className: "uidog-dom-attributes", children: [
314
+ /* @__PURE__ */ jsx("div", { className: "uidog-dom-label", children: "attributes:" }),
315
+ /* @__PURE__ */ jsx("ul", { children: Object.entries(attributes).map(([key, value]) => /* @__PURE__ */ jsxs("li", { children: [
316
+ /* @__PURE__ */ jsx("code", { children: key }),
317
+ "=",
318
+ /* @__PURE__ */ jsx("code", { children: value })
319
+ ] }, key)) })
320
+ ] }),
321
+ /* @__PURE__ */ jsx("div", { className: "uidog-dom-hint", children: "To see file/line info, render this DOM through a small client boundary." })
322
+ ] })
323
+ ] });
324
+ }
325
+ const fileName = props.elementInfo.filePath?.split("/").pop() || "";
326
+ const fileLocation = `Selected element at ${fileName}`;
327
+ return /* @__PURE__ */ jsx("div", { className: "uidog-element-info", children: /* @__PURE__ */ jsxs("div", { className: "uidog-element-info-content", children: [
328
+ /* @__PURE__ */ jsx("span", { className: "uidog-file-location", children: fileLocation }),
329
+ /* @__PURE__ */ jsx(
330
+ "button",
331
+ {
332
+ className: "uidog-close-btn",
333
+ onClick: props.onClose,
334
+ title: "Close sidebar (ESC)",
335
+ "aria-label": "Close sidebar",
336
+ children: "\xD7"
337
+ }
338
+ )
339
+ ] }) });
340
+ }
341
+
342
+ // src/components/ConversationalInputReact.tsx
343
+ import { useState, useEffect, useRef } from "react";
344
+
345
+ // src/api/client.ts
346
+ async function sendChatPrompt(request, apiEndpoint = "http://localhost:3000") {
347
+ try {
348
+ const response = await fetch(`${apiEndpoint}/chat`, {
349
+ method: "POST",
350
+ headers: {
351
+ "Content-Type": "application/json"
352
+ },
353
+ body: JSON.stringify(request)
354
+ });
355
+ if (!response.ok) {
356
+ const errorData = await response.json().catch(() => ({ error: response.statusText }));
357
+ return {
358
+ ok: false,
359
+ message: "",
360
+ error: errorData.error || `API error (${response.status})`
361
+ };
362
+ }
363
+ return await response.json();
364
+ } catch (error) {
365
+ if (error instanceof Error) {
366
+ return {
367
+ ok: false,
368
+ message: "",
369
+ error: error.message
370
+ };
371
+ }
372
+ return {
373
+ ok: false,
374
+ message: "",
375
+ error: "Unknown error occurred"
376
+ };
377
+ }
378
+ }
379
+ async function sendToDeveloper(request, apiEndpoint = "http://localhost:3000") {
380
+ try {
381
+ const response = await fetch(`${apiEndpoint}/send-to-dev`, {
382
+ method: "POST",
383
+ headers: {
384
+ "Content-Type": "application/json"
385
+ },
386
+ body: JSON.stringify(request)
387
+ });
388
+ if (!response.ok) {
389
+ const errorData = await response.json().catch(() => ({ error: response.statusText }));
390
+ return {
391
+ ok: false,
392
+ error: errorData.error || `API error (${response.status})`
393
+ };
394
+ }
395
+ return await response.json();
396
+ } catch (error) {
397
+ if (error instanceof Error) {
398
+ return {
399
+ ok: false,
400
+ error: error.message
401
+ };
402
+ }
403
+ return {
404
+ ok: false,
405
+ error: "Unknown error occurred"
406
+ };
407
+ }
408
+ }
409
+
410
+ // src/components/ConversationalInputReact.tsx
411
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
412
+ function ConversationalInputReact(props) {
413
+ const [userInput, setUserInput] = useState("");
414
+ const [messages, setMessages] = useState([]);
415
+ const [isLoading, setIsLoading] = useState(false);
416
+ const [sessionId, setSessionId] = useState(void 0);
417
+ const [isCreatingPR, setIsCreatingPR] = useState(false);
418
+ const [prUrl, setPrUrl] = useState(null);
419
+ const textareaRef = useRef(null);
420
+ const messagesEndRef = useRef(null);
421
+ useEffect(() => {
422
+ textareaRef.current?.focus();
423
+ }, []);
424
+ useEffect(() => {
425
+ const textarea = textareaRef.current;
426
+ if (textarea) {
427
+ textarea.style.height = "auto";
428
+ textarea.style.height = `${Math.min(textarea.scrollHeight, 200)}px`;
429
+ }
430
+ }, [userInput]);
431
+ useEffect(() => {
432
+ messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
433
+ }, [messages]);
434
+ const handleSubmit = async () => {
435
+ const input = userInput.trim();
436
+ if (!input || isLoading)
437
+ return;
438
+ const userMessage = {
439
+ id: `user-${Date.now()}`,
440
+ role: "user",
441
+ content: input,
442
+ timestamp: Date.now()
443
+ };
444
+ setMessages((prev) => [...prev, userMessage]);
445
+ setUserInput("");
446
+ setIsLoading(true);
447
+ const loadingMessageId = `loading-${Date.now()}`;
448
+ const loadingMessage = {
449
+ id: loadingMessageId,
450
+ role: "assistant",
451
+ content: "",
452
+ timestamp: Date.now(),
453
+ isLoading: true
454
+ };
455
+ setMessages((prev) => [...prev, loadingMessage]);
456
+ const request = {
457
+ prompt: `The component selected by the user: ${props.editorUrl}
458
+ User request: ${input}
459
+ Update multiple files (if necessary) to achieve the user's request.`,
460
+ sessionId
461
+ };
462
+ try {
463
+ const result = await sendChatPrompt(
464
+ request,
465
+ props.apiEndpoint
466
+ );
467
+ if (result.sessionId && !sessionId) {
468
+ setSessionId(result.sessionId);
469
+ }
470
+ setMessages((prev) => {
471
+ const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
472
+ const assistantMessage = {
473
+ id: `assistant-${Date.now()}`,
474
+ role: "assistant",
475
+ content: result.ok ? result.message : result.error || "Request failed",
476
+ timestamp: Date.now(),
477
+ error: !result.ok ? result.error : void 0
478
+ };
479
+ return [...filtered, assistantMessage];
480
+ });
481
+ } catch (err) {
482
+ setMessages((prev) => {
483
+ const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
484
+ const errorMessage = {
485
+ id: `error-${Date.now()}`,
486
+ role: "assistant",
487
+ content: err instanceof Error ? err.message : "Unknown error occurred",
488
+ timestamp: Date.now(),
489
+ error: err instanceof Error ? err.message : "Unknown error occurred"
490
+ };
491
+ return [...filtered, errorMessage];
492
+ });
493
+ } finally {
494
+ setIsLoading(false);
495
+ }
496
+ };
497
+ const handleKeyDown = (e) => {
498
+ if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
499
+ e.preventDefault();
500
+ handleSubmit();
501
+ }
502
+ };
503
+ const handleSendToDeveloper = async () => {
504
+ if (!sessionId || isCreatingPR)
505
+ return;
506
+ setIsCreatingPR(true);
507
+ setPrUrl(null);
508
+ try {
509
+ const result = await sendToDeveloper(
510
+ { sessionId },
511
+ props.apiEndpoint
512
+ );
513
+ if (result.ok && result.prUrl) {
514
+ setPrUrl(result.prUrl);
515
+ const successMessage = {
516
+ id: `pr-success-${Date.now()}`,
517
+ role: "assistant",
518
+ content: `Pull request created successfully!`,
519
+ timestamp: Date.now()
520
+ };
521
+ setMessages((prev) => [...prev, successMessage]);
522
+ } else {
523
+ const errorMessage = {
524
+ id: `pr-error-${Date.now()}`,
525
+ role: "assistant",
526
+ content: result.error || "Failed to create pull request",
527
+ timestamp: Date.now(),
528
+ error: result.error || "Failed to create pull request"
529
+ };
530
+ setMessages((prev) => [...prev, errorMessage]);
531
+ }
532
+ } catch (err) {
533
+ const errorMessage = {
534
+ id: `pr-error-${Date.now()}`,
535
+ role: "assistant",
536
+ content: err instanceof Error ? err.message : "Unknown error occurred",
537
+ timestamp: Date.now(),
538
+ error: err instanceof Error ? err.message : "Unknown error occurred"
539
+ };
540
+ setMessages((prev) => [...prev, errorMessage]);
541
+ } finally {
542
+ setIsCreatingPR(false);
543
+ }
544
+ };
545
+ const handleRetry = async (messageId) => {
546
+ const errorIndex = messages.findIndex((msg) => msg.id === messageId);
547
+ if (errorIndex === -1)
548
+ return;
549
+ let userMessageIndex = -1;
550
+ for (let i = errorIndex - 1; i >= 0; i--) {
551
+ if (messages[i].role === "user") {
552
+ userMessageIndex = i;
553
+ break;
554
+ }
555
+ }
556
+ if (userMessageIndex === -1)
557
+ return;
558
+ const userMessage = messages[userMessageIndex];
559
+ const input = userMessage.content;
560
+ setMessages((prev) => prev.filter((msg) => msg.id !== messageId));
561
+ setIsLoading(true);
562
+ const loadingMessageId = `loading-${Date.now()}`;
563
+ const loadingMessage = {
564
+ id: loadingMessageId,
565
+ role: "assistant",
566
+ content: "",
567
+ timestamp: Date.now(),
568
+ isLoading: true
569
+ };
570
+ setMessages((prev) => [...prev, loadingMessage]);
571
+ const request = {
572
+ prompt: `The component selected by the user: ${props.editorUrl}
573
+ User request: ${input}
574
+ Update multiple files (if necessary) to achieve the user's request.`,
575
+ sessionId
576
+ };
577
+ try {
578
+ const result = await sendChatPrompt(
579
+ request,
580
+ props.apiEndpoint
581
+ );
582
+ if (result.sessionId && !sessionId) {
583
+ setSessionId(result.sessionId);
584
+ }
585
+ setMessages((prev) => {
586
+ const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
587
+ const assistantMessage = {
588
+ id: `assistant-${Date.now()}`,
589
+ role: "assistant",
590
+ content: result.ok ? result.message : result.error || "Request failed",
591
+ timestamp: Date.now(),
592
+ error: !result.ok ? result.error : void 0
593
+ };
594
+ return [...filtered, assistantMessage];
595
+ });
596
+ } catch (err) {
597
+ setMessages((prev) => {
598
+ const filtered = prev.filter((msg) => msg.id !== loadingMessageId);
599
+ const errorMessage = {
600
+ id: `error-${Date.now()}`,
601
+ role: "assistant",
602
+ content: err instanceof Error ? err.message : "Unknown error occurred",
603
+ timestamp: Date.now(),
604
+ error: err instanceof Error ? err.message : "Unknown error occurred"
605
+ };
606
+ return [...filtered, errorMessage];
607
+ });
608
+ } finally {
609
+ setIsLoading(false);
610
+ }
611
+ };
612
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
613
+ /* @__PURE__ */ jsxs2("div", { className: "uidog-messages-container", children: [
614
+ messages.length === 0 && /* @__PURE__ */ jsx2("div", { className: "uidog-empty-state", children: /* @__PURE__ */ jsx2("div", { className: "uidog-empty-state-text", children: "What changes would you like to make?" }) }),
615
+ messages.map((message) => /* @__PURE__ */ jsx2(
616
+ "div",
617
+ {
618
+ className: `uidog-message uidog-message-${message.role}`,
619
+ children: /* @__PURE__ */ jsx2("div", { className: "uidog-message-bubble", children: message.isLoading ? /* @__PURE__ */ jsxs2("div", { className: "uidog-message-loading", children: [
620
+ /* @__PURE__ */ jsx2("div", { className: "uidog-spinner" }),
621
+ /* @__PURE__ */ jsx2("span", { children: "Processing your request..." })
622
+ ] }) : message.error ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
623
+ /* @__PURE__ */ jsx2("div", { className: "uidog-message-content uidog-message-error", children: message.content }),
624
+ /* @__PURE__ */ jsx2(
625
+ "button",
626
+ {
627
+ className: "uidog-retry-btn",
628
+ onClick: () => handleRetry(message.id),
629
+ children: "Retry"
630
+ }
631
+ )
632
+ ] }) : /* @__PURE__ */ jsx2("div", { className: "uidog-message-content", children: message.content }) })
633
+ },
634
+ message.id
635
+ )),
636
+ /* @__PURE__ */ jsx2("div", { ref: messagesEndRef })
637
+ ] }),
638
+ /* @__PURE__ */ jsxs2("div", { className: "uidog-input-footer-fixed", children: [
639
+ /* @__PURE__ */ jsxs2("div", { className: "uidog-input-wrapper", children: [
640
+ /* @__PURE__ */ jsx2(
641
+ "textarea",
642
+ {
643
+ id: "uidog-textarea",
644
+ ref: textareaRef,
645
+ className: "uidog-textarea",
646
+ placeholder: "Describe the changes you want...",
647
+ value: userInput,
648
+ onChange: (e) => setUserInput(e.target.value),
649
+ onKeyDown: handleKeyDown,
650
+ disabled: isLoading
651
+ }
652
+ ),
653
+ /* @__PURE__ */ jsx2(
654
+ "button",
655
+ {
656
+ className: "uidog-submit-btn",
657
+ onClick: handleSubmit,
658
+ disabled: !userInput.trim() || isLoading,
659
+ title: "Send message (Cmd/Ctrl + Enter)",
660
+ children: isLoading ? /* @__PURE__ */ jsx2("div", { className: "uidog-spinner-small" }) : /* @__PURE__ */ jsx2(
661
+ "svg",
662
+ {
663
+ width: "16",
664
+ height: "16",
665
+ viewBox: "0 0 16 16",
666
+ fill: "none",
667
+ xmlns: "http://www.w3.org/2000/svg",
668
+ children: /* @__PURE__ */ jsx2(
669
+ "path",
670
+ {
671
+ d: "M8 2L8 14M8 2L2 8M8 2L14 8",
672
+ stroke: "currentColor",
673
+ strokeWidth: "2",
674
+ strokeLinecap: "round",
675
+ strokeLinejoin: "round"
676
+ }
677
+ )
678
+ }
679
+ )
680
+ }
681
+ )
682
+ ] }),
683
+ /* @__PURE__ */ jsx2("div", { className: "uidog-input-hint", children: "Cmd/Ctrl + Enter to submit" }),
684
+ sessionId && /* @__PURE__ */ jsxs2("div", { className: "uidog-send-to-dev-section", children: [
685
+ /* @__PURE__ */ jsx2(
686
+ "button",
687
+ {
688
+ className: "uidog-send-to-dev-btn",
689
+ onClick: handleSendToDeveloper,
690
+ disabled: isCreatingPR || isLoading,
691
+ title: "Create PR with changes",
692
+ children: isCreatingPR ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
693
+ /* @__PURE__ */ jsx2("div", { className: "uidog-spinner-small" }),
694
+ /* @__PURE__ */ jsx2("span", { children: "Creating PR..." })
695
+ ] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
696
+ /* @__PURE__ */ jsx2(
697
+ "svg",
698
+ {
699
+ width: "16",
700
+ height: "16",
701
+ viewBox: "0 0 16 16",
702
+ fill: "none",
703
+ xmlns: "http://www.w3.org/2000/svg",
704
+ children: /* @__PURE__ */ jsx2(
705
+ "path",
706
+ {
707
+ d: "M8 1L8 15M8 1L1 8M8 1L15 8",
708
+ stroke: "currentColor",
709
+ strokeWidth: "2",
710
+ strokeLinecap: "round",
711
+ strokeLinejoin: "round"
712
+ }
713
+ )
714
+ }
715
+ ),
716
+ /* @__PURE__ */ jsx2("span", { children: "Submit to Developer" })
717
+ ] })
718
+ }
719
+ ),
720
+ prUrl && /* @__PURE__ */ jsx2(
721
+ "a",
722
+ {
723
+ href: prUrl,
724
+ target: "_blank",
725
+ rel: "noopener noreferrer",
726
+ className: "uidog-pr-link",
727
+ children: "View PR \u2192"
728
+ }
729
+ )
730
+ ] })
731
+ ] })
732
+ ] });
733
+ }
734
+
735
+ // src/components/UiDogSidebarReact.tsx
736
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
737
+ function UiDogSidebarReact(props) {
738
+ useEffect2(() => {
739
+ const handleEscapeKey = (e) => {
740
+ if (e.key === "Escape") {
741
+ props.onClose();
742
+ }
743
+ };
744
+ document.addEventListener("keydown", handleEscapeKey);
745
+ return () => {
746
+ document.removeEventListener("keydown", handleEscapeKey);
747
+ };
748
+ }, [props]);
749
+ return /* @__PURE__ */ jsx3("div", { className: "uidog-sidebar-overlay", children: /* @__PURE__ */ jsxs3("div", { className: "uidog-sidebar", children: [
750
+ /* @__PURE__ */ jsx3("div", { className: "uidog-element-info-section", children: /* @__PURE__ */ jsx3(
751
+ ElementInfoDisplayReact,
752
+ {
753
+ elementInfo: props.elementInfo,
754
+ onClose: props.onClose
755
+ }
756
+ ) }),
757
+ /* @__PURE__ */ jsx3("div", { className: "uidog-chat-container", children: /* @__PURE__ */ jsx3(
758
+ ConversationalInputReact,
759
+ {
760
+ elementInfo: props.elementInfo,
761
+ editorUrl: props.editorUrl,
762
+ apiEndpoint: props.apiEndpoint
763
+ }
764
+ ) })
765
+ ] }) });
766
+ }
767
+
768
+ // src/styles/sidebarStyles.ts
769
+ var sidebarStyles = `/* UiDog Sidebar Styles */
770
+
771
+ /* Overlay */
772
+ .uidog-sidebar-overlay {
773
+ position: fixed;
774
+ top: 0;
775
+ right: 0;
776
+ bottom: 0;
777
+ left: 0;
778
+ z-index: 999999;
779
+ pointer-events: none;
780
+ }
781
+
782
+ /* Main Sidebar Container */
783
+ .uidog-sidebar {
784
+ position: fixed;
785
+ right: 0;
786
+ top: 0;
787
+ width: 420px;
788
+ max-width: 100vw;
789
+ height: 100vh;
790
+ background: #13140a;
791
+ box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
792
+ display: flex;
793
+ flex-direction: column;
794
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
795
+ font-size: 14px;
796
+ color: #ffffff;
797
+ pointer-events: auto;
798
+ animation: uidog-slide-in 0.3s ease-out;
799
+ overflow: hidden;
800
+ border-left: 1px solid rgba(255, 255, 255, 0.1);
801
+ }
802
+
803
+ @keyframes uidog-slide-in {
804
+ from {
805
+ transform: translateX(100%);
806
+ }
807
+ to {
808
+ transform: translateX(0);
809
+ }
810
+ }
811
+
812
+ /* Header */
813
+ .uidog-sidebar-header {
814
+ display: flex;
815
+ align-items: center;
816
+ justify-content: flex-end;
817
+ padding: 20px 24px;
818
+ border-bottom: 1px solid rgba(255, 255, 255, 0.15);
819
+ background: rgba(0, 0, 0, 0.3);
820
+ flex-shrink: 0;
821
+ }
822
+
823
+ .uidog-sidebar-title {
824
+ margin: 0;
825
+ font-size: 18px;
826
+ font-weight: 600;
827
+ color: #ffffff;
828
+ letter-spacing: -0.01em;
829
+ }
830
+
831
+ .uidog-close-btn {
832
+ width: 32px;
833
+ height: 32px;
834
+ border: none;
835
+ background: transparent;
836
+ font-size: 28px;
837
+ line-height: 1;
838
+ color: rgba(255, 255, 255, 0.7);
839
+ cursor: pointer;
840
+ border-radius: 4px;
841
+ display: flex;
842
+ align-items: center;
843
+ justify-content: center;
844
+ transition: all 0.2s;
845
+ flex-shrink: 0;
846
+ margin-left: 12px;
847
+ }
848
+
849
+ .uidog-close-btn:hover {
850
+ background: rgba(255, 255, 255, 0.1);
851
+ color: #ffffff;
852
+ }
853
+
854
+ /* Content Area */
855
+ .uidog-sidebar-content {
856
+ flex: 1;
857
+ overflow-y: auto;
858
+ overflow-x: hidden;
859
+ padding: 24px;
860
+ scrollbar-width: thin;
861
+ scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
862
+ }
863
+
864
+ .uidog-sidebar-content::-webkit-scrollbar {
865
+ width: 8px;
866
+ }
867
+
868
+ .uidog-sidebar-content::-webkit-scrollbar-track {
869
+ background: transparent;
870
+ }
871
+
872
+ .uidog-sidebar-content::-webkit-scrollbar-thumb {
873
+ background: rgba(255, 255, 255, 0.2);
874
+ border-radius: 4px;
875
+ }
876
+
877
+ .uidog-sidebar-content::-webkit-scrollbar-thumb:hover {
878
+ background: rgba(255, 255, 255, 0.3);
879
+ }
880
+
881
+ /* Element Info Section */
882
+ .uidog-element-info-section {
883
+ padding: 20px 24px;
884
+ border-bottom: 1px solid rgba(255, 255, 255, 0.15);
885
+ flex-shrink: 0;
886
+ background: rgba(0, 0, 0, 0.2);
887
+ margin-top: 0;
888
+ padding-top: 20px;
889
+ }
890
+
891
+ /* Element Info Section */
892
+ .uidog-element-info {
893
+ margin-bottom: 0;
894
+ }
895
+
896
+ .uidog-element-info-header {
897
+ display: flex;
898
+ align-items: center;
899
+ justify-content: space-between;
900
+ margin-bottom: 12px;
901
+ }
902
+
903
+ .uidog-element-info-title {
904
+ margin: 0;
905
+ font-size: 14px;
906
+ font-weight: 600;
907
+ color: rgba(255, 255, 255, 0.9);
908
+ text-transform: uppercase;
909
+ letter-spacing: 0.05em;
910
+ }
911
+
912
+ .uidog-toggle-view-btn {
913
+ padding: 6px 14px;
914
+ font-size: 12px;
915
+ border: 1px solid rgba(255, 255, 255, 0.2);
916
+ background: rgba(255, 255, 255, 0.1);
917
+ color: #ffffff;
918
+ border-radius: 6px;
919
+ cursor: pointer;
920
+ transition: all 0.2s;
921
+ font-weight: 500;
922
+ }
923
+
924
+ .uidog-toggle-view-btn:hover {
925
+ background: rgba(255, 255, 255, 0.2);
926
+ border-color: rgba(255, 255, 255, 0.3);
927
+ }
928
+
929
+ .uidog-element-info-content {
930
+ background: rgba(0, 0, 0, 0.3);
931
+ border: 1px solid rgba(255, 255, 255, 0.15);
932
+ border-radius: 8px;
933
+ padding: 16px;
934
+ display: flex;
935
+ align-items: center;
936
+ justify-content: space-between;
937
+ position: relative;
938
+ }
939
+
940
+ .uidog-file-location {
941
+ font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
942
+ font-size: 13px;
943
+ color: #ffffff;
944
+ word-break: break-word;
945
+ }
946
+
947
+ .uidog-info-row {
948
+ display: flex;
949
+ margin-bottom: 12px;
950
+ line-height: 1.6;
951
+ }
952
+
953
+ .uidog-info-row:last-of-type {
954
+ margin-bottom: 0;
955
+ }
956
+
957
+ .uidog-info-row:last-child {
958
+ margin-bottom: 0;
959
+ }
960
+
961
+ .uidog-info-label {
962
+ flex-shrink: 0;
963
+ width: 100px;
964
+ font-weight: 500;
965
+ color: rgba(255, 255, 255, 0.75);
966
+ font-size: 13px;
967
+ }
968
+
969
+ .uidog-info-value {
970
+ flex: 1;
971
+ color: #ffffff;
972
+ word-break: break-word;
973
+ font-size: 13px;
974
+ }
975
+
976
+ .uidog-component-name {
977
+ font-weight: 600;
978
+ color: #60a5fa;
979
+ }
980
+
981
+ .uidog-file-path {
982
+ font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
983
+ font-size: 12px;
984
+ }
985
+
986
+ .uidog-dom-snapshot {
987
+ margin-top: 16px;
988
+ background: rgba(255, 255, 255, 0.03);
989
+ border: 1px solid rgba(255, 255, 255, 0.08);
990
+ border-radius: 8px;
991
+ padding: 12px;
992
+ display: flex;
993
+ flex-direction: column;
994
+ gap: 8px;
995
+ }
996
+
997
+ .uidog-dom-label {
998
+ color: rgba(255, 255, 255, 0.7);
999
+ font-size: 12px;
1000
+ text-transform: uppercase;
1001
+ letter-spacing: 0.05em;
1002
+ }
1003
+
1004
+ .uidog-dom-snippet {
1005
+ margin: 0;
1006
+ background: rgba(0, 0, 0, 0.4);
1007
+ border: 1px solid rgba(255, 255, 255, 0.08);
1008
+ border-radius: 6px;
1009
+ padding: 10px;
1010
+ color: rgba(255, 255, 255, 0.85);
1011
+ font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
1012
+ font-size: 12px;
1013
+ white-space: pre-wrap;
1014
+ word-break: break-word;
1015
+ }
1016
+
1017
+ .uidog-dom-attributes ul {
1018
+ margin: 6px 0 0 0;
1019
+ padding-left: 16px;
1020
+ color: rgba(255, 255, 255, 0.85);
1021
+ font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
1022
+ font-size: 12px;
1023
+ word-break: break-word;
1024
+ }
1025
+
1026
+ .uidog-dom-attributes code {
1027
+ background: rgba(255, 255, 255, 0.08);
1028
+ padding: 2px 4px;
1029
+ border-radius: 4px;
1030
+ }
1031
+
1032
+ .uidog-dom-hint {
1033
+ color: rgba(255, 255, 255, 0.6);
1034
+ font-size: 12px;
1035
+ line-height: 1.5;
1036
+ }
1037
+
1038
+ .uidog-mono {
1039
+ font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
1040
+ font-size: 12px;
1041
+ }
1042
+
1043
+ .uidog-detailed-section {
1044
+ margin-top: 12px;
1045
+ padding-top: 12px;
1046
+ border-top: 1px solid rgba(255, 255, 255, 0.1);
1047
+ }
1048
+
1049
+ .uidog-code-preview {
1050
+ flex-direction: column;
1051
+ }
1052
+
1053
+ .uidog-code-placeholder {
1054
+ margin-top: 6px;
1055
+ padding: 8px;
1056
+ background: rgba(0, 0, 0, 0.3);
1057
+ color: rgba(255, 255, 255, 0.8);
1058
+ border-radius: 4px;
1059
+ font-family: "SF Mono", Monaco, Menlo, Consolas, monospace;
1060
+ font-size: 12px;
1061
+ white-space: pre-wrap;
1062
+ word-break: break-word;
1063
+ }
1064
+
1065
+ /* Chat Container */
1066
+ .uidog-chat-container {
1067
+ flex: 1;
1068
+ display: flex;
1069
+ flex-direction: column;
1070
+ overflow: hidden;
1071
+ min-height: 0;
1072
+ }
1073
+
1074
+ /* Messages Container */
1075
+ .uidog-messages-container {
1076
+ flex: 1;
1077
+ overflow-y: auto;
1078
+ overflow-x: hidden;
1079
+ padding: 20px 24px;
1080
+ scrollbar-width: thin;
1081
+ scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
1082
+ }
1083
+
1084
+ .uidog-dom-banner {
1085
+ margin-bottom: 12px;
1086
+ padding: 12px 14px;
1087
+ background: rgba(255, 255, 255, 0.08);
1088
+ border: 1px solid rgba(255, 255, 255, 0.15);
1089
+ border-radius: 8px;
1090
+ color: rgba(255, 255, 255, 0.85);
1091
+ font-size: 13px;
1092
+ line-height: 1.5;
1093
+ }
1094
+
1095
+ .uidog-messages-container::-webkit-scrollbar {
1096
+ width: 8px;
1097
+ }
1098
+
1099
+ .uidog-messages-container::-webkit-scrollbar-track {
1100
+ background: transparent;
1101
+ }
1102
+
1103
+ .uidog-messages-container::-webkit-scrollbar-thumb {
1104
+ background: rgba(255, 255, 255, 0.2);
1105
+ border-radius: 4px;
1106
+ }
1107
+
1108
+ .uidog-messages-container::-webkit-scrollbar-thumb:hover {
1109
+ background: rgba(255, 255, 255, 0.3);
1110
+ }
1111
+
1112
+ /* Empty State */
1113
+ .uidog-empty-state {
1114
+ display: flex;
1115
+ align-items: center;
1116
+ justify-content: center;
1117
+ height: 100%;
1118
+ min-height: 200px;
1119
+ }
1120
+
1121
+ .uidog-empty-state-text {
1122
+ color: rgba(255, 255, 255, 0.6);
1123
+ font-size: 14px;
1124
+ text-align: center;
1125
+ }
1126
+
1127
+ /* Messages */
1128
+ .uidog-message {
1129
+ margin-bottom: 16px;
1130
+ display: flex;
1131
+ animation: uidog-message-fade-in 0.2s ease-out;
1132
+ }
1133
+
1134
+ @keyframes uidog-message-fade-in {
1135
+ from {
1136
+ opacity: 0;
1137
+ transform: translateY(4px);
1138
+ }
1139
+ to {
1140
+ opacity: 1;
1141
+ transform: translateY(0);
1142
+ }
1143
+ }
1144
+
1145
+ .uidog-message-user {
1146
+ justify-content: flex-end;
1147
+ }
1148
+
1149
+ .uidog-message-assistant {
1150
+ justify-content: flex-start;
1151
+ }
1152
+
1153
+ /* Message Bubbles */
1154
+ .uidog-message-bubble {
1155
+ max-width: 80%;
1156
+ padding: 12px 16px;
1157
+ border-radius: 12px;
1158
+ word-wrap: break-word;
1159
+ overflow-wrap: break-word;
1160
+ }
1161
+
1162
+ .uidog-message-user .uidog-message-bubble {
1163
+ background: rgba(59, 130, 246, 0.2);
1164
+ border: 1px solid rgba(59, 130, 246, 0.3);
1165
+ color: #93c5fd;
1166
+ }
1167
+
1168
+ .uidog-message-assistant .uidog-message-bubble {
1169
+ background: rgba(255, 255, 255, 0.08);
1170
+ border: 1px solid rgba(255, 255, 255, 0.15);
1171
+ color: rgba(255, 255, 255, 0.9);
1172
+ }
1173
+
1174
+ .uidog-message-content {
1175
+ line-height: 1.6;
1176
+ white-space: pre-wrap;
1177
+ word-break: break-word;
1178
+ font-size: 14px;
1179
+ }
1180
+
1181
+ .uidog-message-content.uidog-message-error {
1182
+ color: #fca5a5;
1183
+ }
1184
+
1185
+ /* Loading Message */
1186
+ .uidog-message-loading {
1187
+ display: flex;
1188
+ align-items: center;
1189
+ gap: 10px;
1190
+ color: rgba(255, 255, 255, 0.7);
1191
+ font-size: 14px;
1192
+ }
1193
+
1194
+ .uidog-spinner {
1195
+ width: 16px;
1196
+ height: 16px;
1197
+ border: 2px solid rgba(255, 255, 255, 0.2);
1198
+ border-top-color: rgba(255, 255, 255, 0.8);
1199
+ border-radius: 50%;
1200
+ animation: uidog-spin 0.8s linear infinite;
1201
+ }
1202
+
1203
+ .uidog-spinner-small {
1204
+ width: 14px;
1205
+ height: 14px;
1206
+ border: 2px solid rgba(255, 255, 255, 0.3);
1207
+ border-top-color: #ffffff;
1208
+ border-radius: 50%;
1209
+ animation: uidog-spin 0.8s linear infinite;
1210
+ }
1211
+
1212
+ @keyframes uidog-spin {
1213
+ to {
1214
+ transform: rotate(360deg);
1215
+ }
1216
+ }
1217
+
1218
+ /* Fixed Input Footer */
1219
+ .uidog-input-footer-fixed {
1220
+ flex-shrink: 0;
1221
+ padding: 16px 24px;
1222
+ border-top: 1px solid rgba(255, 255, 255, 0.15);
1223
+ background: rgba(0, 0, 0, 0.3);
1224
+ }
1225
+
1226
+ .uidog-input-wrapper {
1227
+ position: relative;
1228
+ margin-bottom: 8px;
1229
+ }
1230
+
1231
+ .uidog-textarea {
1232
+ width: 100%;
1233
+ padding: 10px 60px 10px 14px;
1234
+ border: 1px solid rgba(255, 255, 255, 0.2);
1235
+ border-radius: 8px;
1236
+ font-family: inherit;
1237
+ font-size: 14px;
1238
+ line-height: 1.5;
1239
+ resize: none;
1240
+ min-height: 44px;
1241
+ max-height: 200px;
1242
+ background: rgba(0, 0, 0, 0.4);
1243
+ color: #ffffff;
1244
+ transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
1245
+ box-sizing: border-box;
1246
+ overflow-wrap: break-word;
1247
+ word-wrap: break-word;
1248
+ overflow-y: auto;
1249
+ }
1250
+
1251
+ .uidog-textarea::placeholder {
1252
+ color: rgba(255, 255, 255, 0.5);
1253
+ }
1254
+
1255
+ .uidog-textarea:focus {
1256
+ outline: none;
1257
+ border-color: #60a5fa;
1258
+ background: rgba(0, 0, 0, 0.5);
1259
+ box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
1260
+ }
1261
+
1262
+ .uidog-textarea:disabled {
1263
+ background: rgba(0, 0, 0, 0.2);
1264
+ color: rgba(255, 255, 255, 0.5);
1265
+ cursor: not-allowed;
1266
+ }
1267
+
1268
+ .uidog-submit-btn {
1269
+ position: absolute;
1270
+ bottom: 10px;
1271
+ right: 6px;
1272
+ width: 32px;
1273
+ height: 32px;
1274
+ display: flex;
1275
+ align-items: center;
1276
+ justify-content: center;
1277
+ padding: 0;
1278
+ font-size: 14px;
1279
+ font-weight: 500;
1280
+ color: #ffffff;
1281
+ background: #3b82f6;
1282
+ border: none;
1283
+ border-radius: 6px;
1284
+ cursor: pointer;
1285
+ transition: all 0.2s;
1286
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
1287
+ }
1288
+
1289
+ .uidog-submit-btn:active {
1290
+ transform: translateY(1px);
1291
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
1292
+ }
1293
+
1294
+ .uidog-submit-btn:hover:not(:disabled) {
1295
+ background: #2563eb;
1296
+ }
1297
+
1298
+ .uidog-submit-btn:disabled {
1299
+ background: rgba(255, 255, 255, 0.1);
1300
+ color: rgba(255, 255, 255, 0.3);
1301
+ cursor: not-allowed;
1302
+ }
1303
+
1304
+ .uidog-submit-btn svg {
1305
+ stroke: currentColor;
1306
+ }
1307
+
1308
+ .uidog-input-hint {
1309
+ font-size: 11px;
1310
+ color: rgba(255, 255, 255, 0.5);
1311
+ text-align: center;
1312
+ margin-top: 4px;
1313
+ }
1314
+
1315
+ .uidog-retry-btn {
1316
+ margin-top: 8px;
1317
+ padding: 6px 12px;
1318
+ font-size: 12px;
1319
+ font-weight: 500;
1320
+ color: #ffffff;
1321
+ background: #ef4444;
1322
+ border: none;
1323
+ border-radius: 6px;
1324
+ cursor: pointer;
1325
+ transition: background 0.2s;
1326
+ }
1327
+
1328
+ .uidog-retry-btn:hover {
1329
+ background: #dc2626;
1330
+ }
1331
+
1332
+ /* Footer */
1333
+ .uidog-sidebar-footer {
1334
+ padding: 16px 24px;
1335
+ border-top: 1px solid rgba(255, 255, 255, 0.15);
1336
+ background: rgba(0, 0, 0, 0.3);
1337
+ text-align: center;
1338
+ flex-shrink: 0;
1339
+ }
1340
+
1341
+ .uidog-footer-text {
1342
+ font-size: 12px;
1343
+ color: rgba(255, 255, 255, 0.7);
1344
+ }
1345
+
1346
+ .uidog-footer-link {
1347
+ color: #60a5fa;
1348
+ text-decoration: none;
1349
+ font-weight: 500;
1350
+ }
1351
+
1352
+ .uidog-footer-link:hover {
1353
+ text-decoration: underline;
1354
+ color: #93c5fd;
1355
+ }
1356
+
1357
+ /* Mobile Responsive */
1358
+ @media (max-width: 768px) {
1359
+ .uidog-sidebar {
1360
+ width: 100vw;
1361
+ }
1362
+ }`;
1363
+ var sidebarStyles_default = sidebarStyles;
1364
+
1365
+ // src/sidebar-initializer.ts
1366
+ var sidebarRoot = null;
1367
+ var sidebarContainer = null;
1368
+ var shadowRoot = null;
1369
+ var config = { apiEndpoint: "https://api.ui.dog" };
1370
+ var currentState = {
1371
+ isOpen: false,
1372
+ elementInfo: null,
1373
+ editorUrl: ""
1374
+ };
1375
+ function initializeSidebar(sidebarConfig) {
1376
+ if (typeof window === "undefined")
1377
+ return;
1378
+ config = sidebarConfig;
1379
+ if (document.getElementById("uidog-next-sidebar-root")) {
1380
+ return;
1381
+ }
1382
+ sidebarContainer = document.createElement("div");
1383
+ sidebarContainer.id = "uidog-next-sidebar-root";
1384
+ document.body.appendChild(sidebarContainer);
1385
+ shadowRoot = sidebarContainer.attachShadow({ mode: "open" });
1386
+ const styleElement = document.createElement("style");
1387
+ styleElement.textContent = sidebarStyles_default;
1388
+ shadowRoot.appendChild(styleElement);
1389
+ const mountPoint = document.createElement("div");
1390
+ mountPoint.id = "uidog-sidebar-mount";
1391
+ shadowRoot.appendChild(mountPoint);
1392
+ sidebarRoot = createRoot(mountPoint);
1393
+ render();
1394
+ }
1395
+ function render() {
1396
+ if (!sidebarRoot)
1397
+ return;
1398
+ const { isOpen, elementInfo, editorUrl } = currentState;
1399
+ if (!isOpen || !elementInfo) {
1400
+ sidebarRoot.render(null);
1401
+ return;
1402
+ }
1403
+ sidebarRoot.render(
1404
+ createElement(UiDogSidebarReact, {
1405
+ elementInfo,
1406
+ editorUrl,
1407
+ onClose: closeSidebar,
1408
+ apiEndpoint: config.apiEndpoint
1409
+ })
1410
+ );
1411
+ }
1412
+ function openSidebar(elementInfo, editorUrl) {
1413
+ currentState = {
1414
+ isOpen: true,
1415
+ elementInfo,
1416
+ editorUrl
1417
+ };
1418
+ if (typeof window !== "undefined") {
1419
+ window.__UIDOG_SIDEBAR__ = {
1420
+ isOpen: true,
1421
+ elementInfo,
1422
+ editorUrl
1423
+ };
1424
+ }
1425
+ render();
1426
+ }
1427
+ function closeSidebar() {
1428
+ currentState = {
1429
+ isOpen: false,
1430
+ elementInfo: null,
1431
+ editorUrl: ""
1432
+ };
1433
+ if (typeof window !== "undefined") {
1434
+ window.__UIDOG_SIDEBAR__ = {
1435
+ isOpen: false,
1436
+ elementInfo: null,
1437
+ editorUrl: null
1438
+ };
1439
+ }
1440
+ render();
1441
+ }
1442
+
1443
+ // src/index.ts
1444
+ var isInitialized = false;
1445
+ function initializeUiDogNext(options = {}) {
1446
+ if (typeof window === "undefined")
1447
+ return;
1448
+ if (isInitialized) {
1449
+ console.warn("[UiDog Next] Already initialized");
1450
+ return;
1451
+ }
1452
+ if (process.env.NODE_ENV === "production") {
1453
+ console.warn(
1454
+ "[UiDog Next] Running in production mode. Element source detection may not work as _debugSource is stripped in production builds."
1455
+ );
1456
+ }
1457
+ const {
1458
+ editor = "cursor",
1459
+ projectPath = "",
1460
+ modifier = "alt",
1461
+ enableSidebar = true,
1462
+ apiEndpoint = "https://api.ui.dog"
1463
+ } = options;
1464
+ isInitialized = true;
1465
+ window.__UIDOG_NEXT_INITIALIZED__ = true;
1466
+ setupBippyInstrumentation();
1467
+ if (enableSidebar) {
1468
+ initializeSidebar({ apiEndpoint });
1469
+ }
1470
+ setupElementDetector({
1471
+ modifier,
1472
+ onElementSelected: (source, element) => {
1473
+ const rect = element.getBoundingClientRect ? element.getBoundingClientRect() : null;
1474
+ const buildDomSnapshot = () => {
1475
+ const outerHTML = element.outerHTML || "";
1476
+ const text = (element.textContent || "").trim();
1477
+ const attributes = {};
1478
+ Array.from(element.attributes || []).forEach((attr) => {
1479
+ attributes[attr.name] = attr.value;
1480
+ });
1481
+ return {
1482
+ outerHTML: outerHTML.length > 4e3 ? `${outerHTML.slice(0, 4e3)}\u2026` : outerHTML,
1483
+ text: text.length > 1e3 ? `${text.slice(0, 1e3)}\u2026` : text,
1484
+ attributes
1485
+ };
1486
+ };
1487
+ if (source) {
1488
+ const editorUrl = buildEditorUrl(source, editor, projectPath);
1489
+ console.info(
1490
+ "[UiDog Next] Source detected:",
1491
+ normalizeFileName(source.fileName),
1492
+ "line",
1493
+ source.lineNumber,
1494
+ "column",
1495
+ source.columnNumber
1496
+ );
1497
+ if (enableSidebar) {
1498
+ const elementInfo = {
1499
+ kind: "source",
1500
+ componentName: source.functionName || "Unknown",
1501
+ filePath: normalizeFileName(source.fileName),
1502
+ line: source.lineNumber,
1503
+ column: source.columnNumber,
1504
+ box: rect ? {
1505
+ x: rect.x,
1506
+ y: rect.y,
1507
+ width: rect.width,
1508
+ height: rect.height
1509
+ } : void 0
1510
+ };
1511
+ openSidebar(elementInfo, editorUrl);
1512
+ } else {
1513
+ console.log("[UiDog Next] Element selected:");
1514
+ console.log(" Component:", source.functionName || "Unknown");
1515
+ console.log(" File:", source.fileName);
1516
+ console.log(" Line:", source.lineNumber);
1517
+ console.log(" Column:", source.columnNumber);
1518
+ console.log(" Editor URL:", editorUrl);
1519
+ }
1520
+ } else {
1521
+ const domSnapshot = buildDomSnapshot();
1522
+ console.info("[UiDog Next] DOM snapshot (no source):", {
1523
+ outerHTML: domSnapshot.outerHTML,
1524
+ text: domSnapshot.text,
1525
+ attributes: domSnapshot.attributes,
1526
+ box: rect ? {
1527
+ x: rect.x,
1528
+ y: rect.y,
1529
+ width: rect.width,
1530
+ height: rect.height
1531
+ } : void 0
1532
+ });
1533
+ const elementInfo = {
1534
+ kind: "dom",
1535
+ componentName: "Server-rendered element",
1536
+ domSnapshot,
1537
+ box: rect ? {
1538
+ x: rect.x,
1539
+ y: rect.y,
1540
+ width: rect.width,
1541
+ height: rect.height
1542
+ } : void 0
1543
+ };
1544
+ if (enableSidebar) {
1545
+ openSidebar(elementInfo, "");
1546
+ } else {
1547
+ console.log("[UiDog Next] Element selected (DOM snapshot):");
1548
+ console.log(" outerHTML:", domSnapshot.outerHTML);
1549
+ console.log(" text:", domSnapshot.text);
1550
+ }
1551
+ }
1552
+ }
1553
+ });
1554
+ console.log(
1555
+ `[UiDog Next] Initialized (${modifier}+click to select elements)`
1556
+ );
1557
+ }
1558
+ function isUiDogNextInitialized() {
1559
+ return isInitialized;
1560
+ }
1561
+
1562
+ // src/client/init.tsx
1563
+ import { Fragment as Fragment3, jsx as jsx4 } from "react/jsx-runtime";
1564
+ function UiDogProvider({
1565
+ children,
1566
+ editor = "cursor",
1567
+ projectPath = "",
1568
+ modifier = "alt",
1569
+ enableSidebar = true,
1570
+ apiEndpoint = "https://api.ui.dog"
1571
+ }) {
1572
+ useEffect3(() => {
1573
+ if (process.env.NODE_ENV !== "development") {
1574
+ return;
1575
+ }
1576
+ if (isUiDogNextInitialized()) {
1577
+ return;
1578
+ }
1579
+ initializeUiDogNext({
1580
+ editor,
1581
+ projectPath,
1582
+ modifier,
1583
+ enableSidebar,
1584
+ apiEndpoint
1585
+ });
1586
+ return () => {
1587
+ };
1588
+ }, [editor, projectPath, modifier, enableSidebar, apiEndpoint]);
1589
+ return /* @__PURE__ */ jsx4(Fragment3, { children });
1590
+ }
1591
+ export {
1592
+ UiDogProvider
1593
+ };