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