Spaces:
Running
Running
Update index.html
Browse files- index.html +449 -219
index.html
CHANGED
@@ -3,316 +3,541 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>AI μ½λ©
|
7 |
<!-- Monaco Editor λ‘λ CSS -->
|
8 |
<link rel="stylesheet" data-name="vs/editor/editor.main" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/editor/editor.main.min.css">
|
|
|
|
|
|
|
|
|
9 |
<style>
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
body {
|
12 |
-
font-family:
|
13 |
margin: 0;
|
14 |
-
background-color:
|
15 |
-
color:
|
|
|
|
|
|
|
|
|
16 |
padding: 20px;
|
|
|
17 |
}
|
18 |
|
19 |
-
.container {
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
|
34 |
-
.
|
35 |
display: flex;
|
36 |
-
flex-
|
37 |
-
|
38 |
-
margin-bottom: 20px;
|
39 |
}
|
40 |
|
41 |
-
.
|
42 |
flex: 1;
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
border-
|
47 |
-
|
48 |
}
|
49 |
|
50 |
-
.
|
51 |
-
|
52 |
-
|
|
|
|
|
53 |
}
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
margin-bottom: 10px;
|
60 |
-
border: 1px solid #ccc;
|
61 |
-
border-radius: 4px;
|
62 |
-
font-size: 14px;
|
63 |
-
box-sizing: border-box; /* λλΉ κ³μ°μ padding, border ν¬ν¨ */
|
64 |
}
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
71 |
color: white;
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
75 |
font-size: 16px;
|
76 |
-
margin-
|
77 |
-
|
78 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
background-color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
83 |
|
84 |
-
|
85 |
-
|
86 |
display: flex;
|
87 |
-
gap: 10px;
|
88 |
align-items: center;
|
|
|
|
|
89 |
}
|
90 |
|
91 |
-
.
|
92 |
-
width: auto;
|
93 |
flex-grow: 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
}
|
|
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
border:
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
|
|
|
|
103 |
|
104 |
-
.preview-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
background-color: #f9f9f9;
|
110 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
#html-preview {
|
|
|
113 |
width: 100%;
|
114 |
-
|
115 |
-
border:
|
116 |
-
background-color:
|
117 |
}
|
118 |
-
|
|
|
119 |
.loader {
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
animation: spin 1s linear infinite;
|
126 |
-
margin: 10px auto;
|
127 |
-
display: none; /* κΈ°λ³Έ μ¨κΉ */
|
128 |
}
|
|
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
</style>
|
135 |
</head>
|
136 |
<body>
|
137 |
-
<div class="container">
|
138 |
-
<
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
<
|
153 |
-
|
|
|
|
|
|
|
|
|
154 |
</div>
|
155 |
-
</div>
|
156 |
-
|
157 |
-
<div class="control-pane">
|
158 |
-
<h2>HTML μμ± (λνν)</h2>
|
159 |
-
<textarea id="html-prompt" placeholder="μ: 'λΉ¨κ°μ λ°°κ²½μ νμ λ©μμ§ νμ΄μ§ λ§λ€μ΄μ€'"></textarea>
|
160 |
-
<button id="generateHtmlBtn">HTML μμ± λ° λ―Έλ¦¬λ³΄κΈ°</button>
|
161 |
-
<div id="htmlLoader" class="loader"></div>
|
162 |
|
163 |
-
<
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
</div>
|
168 |
</div>
|
169 |
-
<div id="completionLoader" class="loader" style="text-align: center; width: 100%;"></div>
|
170 |
-
|
171 |
-
|
172 |
-
<div class="preview-pane">
|
173 |
-
<h2>HTML 미리보기</h2>
|
174 |
-
<iframe id="html-preview" sandbox="allow-scripts allow-same-origin"></iframe>
|
175 |
-
</div>
|
176 |
-
|
177 |
</div>
|
178 |
|
179 |
-
<!-- Monaco Editor λ‘λ JS -->
|
180 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/loader.min.js"></script>
|
181 |
<script>
|
182 |
-
// μ΄μ script.js λ΄μ© μ 체λ₯Ό μ¬κΈ°μ λΆμ¬λ£μ΅λλ€.
|
183 |
let editor;
|
184 |
-
|
185 |
-
|
186 |
-
const
|
187 |
-
const
|
|
|
|
|
|
|
188 |
const completionLoader = document.getElementById('completionLoader');
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
}
|
193 |
-
|
194 |
-
function hideLoader(loaderElement) {
|
195 |
-
if (loaderElement) loaderElement.style.display = 'none';
|
196 |
-
}
|
197 |
-
|
198 |
|
|
|
199 |
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs' }});
|
200 |
require(['vs/editor/editor.main'], function() {
|
201 |
editor = monaco.editor.create(document.getElementById('editor-container'), {
|
202 |
-
value:
|
203 |
-
|
204 |
-
|
205 |
-
].join('\n'),
|
206 |
-
language: 'javascript', // κΈ°λ³Έ μΈμ΄
|
207 |
-
theme: 'vs-dark',
|
208 |
automaticLayout: true,
|
209 |
-
wordWrap: 'on',
|
210 |
-
minimap: { enabled:
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
});
|
212 |
-
});
|
213 |
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
const getCompletionBtn = document.getElementById('getCompletionBtn');
|
219 |
-
const languageSelect = document.getElementById('languageSelect');
|
220 |
-
const htmlPreviewEl = document.getElementById('html-preview');
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
monaco.editor.setModelLanguage(editor.getModel(), event.target.value);
|
225 |
-
}
|
226 |
});
|
227 |
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
}
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
});
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
return;
|
270 |
}
|
271 |
-
|
272 |
-
generateCodeBtn.disabled = true;
|
273 |
|
274 |
try {
|
275 |
-
const response = await fetch(
|
276 |
method: 'POST',
|
277 |
headers: { 'Content-Type': 'application/json' },
|
278 |
-
body: JSON.stringify(
|
279 |
});
|
|
|
280 |
if (!response.ok) {
|
281 |
const errorData = await response.json();
|
282 |
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
283 |
}
|
284 |
const data = await response.json();
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
}
|
|
|
289 |
} catch (error) {
|
290 |
-
console.error('
|
291 |
-
|
292 |
-
if (editor) editor.setValue(`// μ½λ μμ± μ€λ₯: ${error.message}`);
|
293 |
} finally {
|
294 |
-
hideLoader(
|
295 |
-
|
296 |
}
|
297 |
-
}
|
298 |
|
299 |
-
|
|
|
300 |
if (!editor) return;
|
301 |
|
302 |
const model = editor.getModel();
|
303 |
const position = editor.getPosition();
|
304 |
const fullCode = model.getValue();
|
305 |
-
// FIM APIλ λΉ prefix/suffixλ νμ©νλ―λ‘, 컀μ μμΉ κΈ°μ€μΌλ‘ λλ
|
306 |
const offset = model.getOffsetAt(position);
|
307 |
const prefix = fullCode.substring(0, offset);
|
308 |
const suffix = fullCode.substring(offset);
|
309 |
-
const language = languageSelect.value;
|
310 |
|
311 |
-
// FIMμ λΉ λ΄μ©μμλ μλν μ μμΌλ, μ¬μ©μκ° νΌλμ€λ¬μΈ μ μμΌλ―λ‘ μ΅μνμ μ
λ ₯ μ λ (μ νμ¬ν)
|
312 |
-
// if (prefix.trim() === '' && suffix.trim() === '') {
|
313 |
-
// alert('μλμμ±μ μν΄ μ½λ μΌλΆλ₯Ό μ
λ ₯νκ±°λ 컀μλ₯Ό νΉμ μμΉμ λμΈμ.');
|
314 |
-
// return;
|
315 |
-
// }
|
316 |
showLoader(completionLoader);
|
317 |
getCompletionBtn.disabled = true;
|
318 |
|
@@ -320,7 +545,7 @@
|
|
320 |
const response = await fetch('/api/complete-code', {
|
321 |
method: 'POST',
|
322 |
headers: { 'Content-Type': 'application/json' },
|
323 |
-
body: JSON.stringify({ prefix, suffix, language })
|
324 |
});
|
325 |
if (!response.ok) {
|
326 |
const errorData = await response.json();
|
@@ -328,22 +553,27 @@
|
|
328 |
}
|
329 |
const data = await response.json();
|
330 |
|
331 |
-
|
332 |
-
editor.executeEdits("api-completion", [{
|
333 |
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
334 |
text: data.completion
|
335 |
}]);
|
336 |
-
|
337 |
-
// editor.setPosition(editor.getModel().getFullModelRange().getEndPosition());
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
|
|
|
|
|
|
342 |
} finally {
|
343 |
hideLoader(completionLoader);
|
344 |
getCompletionBtn.disabled = false;
|
345 |
}
|
346 |
-
}
|
|
|
|
|
|
|
|
|
347 |
</script>
|
348 |
</body>
|
349 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>AI μ½λ© ννΈλ</title>
|
7 |
<!-- Monaco Editor λ‘λ CSS -->
|
8 |
<link rel="stylesheet" data-name="vs/editor/editor.main" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/editor/editor.main.min.css">
|
9 |
+
<!-- Google Fonts (macOS λλ ν°νΈ) -->
|
10 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
11 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
12 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
13 |
<style>
|
14 |
+
:root {
|
15 |
+
--bg-color: #f0f2f5; /* λ°μ νμ λ°°κ²½ */
|
16 |
+
--app-bg-color: #ffffff; /* μ± λ°°κ²½ */
|
17 |
+
--sidebar-bg-color: #e8e8e8; /* μ¬μ΄λλ° λ°°κ²½ (λ λ°κ²) */
|
18 |
+
--text-color: #1c1e21; /* κΈ°λ³Έ ν
μ€νΈ */
|
19 |
+
--text-secondary-color: #606770; /* 보쑰 ν
μ€νΈ */
|
20 |
+
--accent-color: #007aff; /* macOS λΈλ£¨ */
|
21 |
+
--border-color: #d1d1d7;
|
22 |
+
--editor-bg: #282c34; /* μ΄λμ΄ μλν° λ°°κ²½ */
|
23 |
+
--font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
24 |
+
--border-radius: 12px;
|
25 |
+
--box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
26 |
+
--box-shadow-light: 0 1px 3px rgba(0,0,0,0.05);
|
27 |
+
}
|
28 |
+
|
29 |
+
/* μ€ν¬λ‘€λ° μ€νμΌ (μ ν μ¬ν) */
|
30 |
+
::-webkit-scrollbar { width: 8px; height: 8px; }
|
31 |
+
::-webkit-scrollbar-track { background: transparent; }
|
32 |
+
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; }
|
33 |
+
::-webkit-scrollbar-thumb:hover { background: #a1a1a1; }
|
34 |
+
|
35 |
body {
|
36 |
+
font-family: var(--font-family);
|
37 |
margin: 0;
|
38 |
+
background-color: var(--bg-color);
|
39 |
+
color: var(--text-color);
|
40 |
+
display: flex;
|
41 |
+
justify-content: center;
|
42 |
+
align-items: center;
|
43 |
+
min-height: 100vh;
|
44 |
padding: 20px;
|
45 |
+
box-sizing: border-box;
|
46 |
}
|
47 |
|
48 |
+
.app-container {
|
49 |
+
display: flex;
|
50 |
+
width: 95%;
|
51 |
+
max-width: 1400px;
|
52 |
+
height: 90vh;
|
53 |
+
max-height: 800px;
|
54 |
+
background-color: var(--app-bg-color);
|
55 |
+
border-radius: var(--border-radius);
|
56 |
+
box-shadow: var(--box-shadow);
|
57 |
+
overflow: hidden;
|
58 |
}
|
59 |
|
60 |
+
/* μ¬μ΄λλ° (μ ν μ¬ν - μ¬κΈ°μλ μ±ν
, μλν°, 미리보기λ₯Ό μ£Ό μμμΌλ‘) */
|
61 |
+
/* .sidebar { flex: 0 0 280px; background-color: var(--sidebar-bg-color); padding: 20px; border-right: 1px solid var(--border-color); display: flex; flex-direction: column; } */
|
62 |
+
|
63 |
+
.main-content {
|
64 |
+
flex-grow: 1;
|
65 |
+
display: flex;
|
66 |
+
flex-direction: column;
|
67 |
+
overflow: hidden;
|
68 |
}
|
69 |
|
70 |
+
.chat-editor-area {
|
71 |
display: flex;
|
72 |
+
flex-grow: 1;
|
73 |
+
overflow: hidden; /* λ΄λΆ μ€ν¬λ‘€ κ΄λ¦¬ */
|
|
|
74 |
}
|
75 |
|
76 |
+
.chat-panel {
|
77 |
flex: 1;
|
78 |
+
display: flex;
|
79 |
+
flex-direction: column;
|
80 |
+
padding: 20px;
|
81 |
+
border-right: 1px solid var(--border-color);
|
82 |
+
overflow-y: auto; /* μ±ν
μ€ν¬λ‘€ */
|
83 |
}
|
84 |
|
85 |
+
.chat-messages {
|
86 |
+
flex-grow: 1;
|
87 |
+
margin-bottom: 15px;
|
88 |
+
overflow-y: auto;
|
89 |
+
padding-right: 10px; /* μ€ν¬λ‘€λ° κ³΅κ° */
|
90 |
}
|
91 |
|
92 |
+
.message {
|
93 |
+
display: flex;
|
94 |
+
margin-bottom: 15px;
|
95 |
+
max-width: 90%;
|
|
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
|
98 |
+
.message.user {
|
99 |
+
margin-left: auto; /* μ¬μ©μ λ©μμ§λ μ€λ₯Έμͺ½ μ λ ¬ */
|
100 |
+
flex-direction: row-reverse;
|
101 |
+
}
|
102 |
+
|
103 |
+
.avatar {
|
104 |
+
width: 36px;
|
105 |
+
height: 36px;
|
106 |
+
border-radius: 50%;
|
107 |
+
background-color: var(--accent-color);
|
108 |
color: white;
|
109 |
+
display: flex;
|
110 |
+
align-items: center;
|
111 |
+
justify-content: center;
|
112 |
+
font-weight: 500;
|
113 |
font-size: 16px;
|
114 |
+
margin-right: 10px;
|
115 |
+
flex-shrink: 0;
|
116 |
}
|
117 |
+
.message.user .avatar { margin-left: 10px; margin-right: 0; background-color: #6c757d; }
|
118 |
+
|
119 |
+
.message-content {
|
120 |
+
padding: 10px 15px;
|
121 |
+
border-radius: 18px;
|
122 |
+
background-color: #e4e6eb; /* AI λ©μμ§ λ°°κ²½ */
|
123 |
+
color: var(--text-color);
|
124 |
+
word-wrap: break-word; /* κΈ΄ λ¨μ΄ μ€λ°κΏ */
|
125 |
+
}
|
126 |
+
.message.user .message-content { background-color: var(--accent-color); color: white; }
|
127 |
|
128 |
+
.message-content pre { /* μ½λ λΈλ‘ μ€νμΌ */
|
129 |
+
background-color: var(--editor-bg) !important; /* Monaco ν
λ§μ μ μ¬νκ² */
|
130 |
+
color: #abb2bf !important; /* Monaco κΈ°λ³Έ ν
μ€νΈ μμ */
|
131 |
+
padding: 10px;
|
132 |
+
border-radius: 8px;
|
133 |
+
overflow-x: auto;
|
134 |
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
135 |
+
font-size: 0.9em;
|
136 |
+
white-space: pre-wrap; /* μλ μ€λ°κΏ */
|
137 |
+
word-break: break-all; /* κΈ΄ μ½λ μ€λ°κΏ */
|
138 |
+
}
|
139 |
+
/* Monaco μλν°κ° λ λλ§ν μ½λ λΈλ‘μ λν μ€νμΌ (νμ μ) */
|
140 |
+
.monaco-editor-code-block {
|
141 |
+
border-radius: 8px !important;
|
142 |
+
box-shadow: var(--box-shadow-light);
|
143 |
}
|
144 |
|
145 |
+
|
146 |
+
.chat-input-area {
|
147 |
display: flex;
|
|
|
148 |
align-items: center;
|
149 |
+
padding-top: 15px;
|
150 |
+
border-top: 1px solid var(--border-color);
|
151 |
}
|
152 |
|
153 |
+
.chat-input-area textarea {
|
|
|
154 |
flex-grow: 1;
|
155 |
+
padding: 10px 15px;
|
156 |
+
border: 1px solid var(--border-color);
|
157 |
+
border-radius: 18px;
|
158 |
+
resize: none;
|
159 |
+
font-family: var(--font-family);
|
160 |
+
font-size: 15px;
|
161 |
+
min-height: 22px; /* 1μ€ λμ΄ */
|
162 |
+
max-height: 100px; /* μ΅λ λμ΄ */
|
163 |
+
line-height: 1.4;
|
164 |
+
margin-right: 10px;
|
165 |
+
box-sizing: border-box;
|
166 |
+
overflow-y: auto; /* λ΄μ© λ§μμ§λ©΄ μ€ν¬λ‘€ */
|
167 |
}
|
168 |
+
.chat-input-area textarea:focus { border-color: var(--accent-color); outline: none; box-shadow: 0 0 0 2px rgba(0,122,255,0.2); }
|
169 |
|
170 |
+
.chat-input-area button {
|
171 |
+
background-color: var(--accent-color);
|
172 |
+
color: white;
|
173 |
+
border: none;
|
174 |
+
border-radius: 50%; /* μν λ²νΌ */
|
175 |
+
width: 40px;
|
176 |
+
height: 40px;
|
177 |
+
font-size: 20px;
|
178 |
+
cursor: pointer;
|
179 |
+
display: flex;
|
180 |
+
align-items: center;
|
181 |
+
justify-content: center;
|
182 |
+
transition: background-color 0.2s;
|
183 |
}
|
184 |
+
.chat-input-area button:hover { background-color: #0056b3; }
|
185 |
+
.chat-input-area button:disabled { background-color: #b0c4de; cursor: not-allowed; }
|
186 |
|
187 |
+
.editor-preview-area {
|
188 |
+
flex: 2; /* μλν°μ 미리보기 μμμ λ λκ² */
|
189 |
+
display: flex;
|
190 |
+
flex-direction: column;
|
191 |
+
overflow: hidden;
|
|
|
192 |
}
|
193 |
+
|
194 |
+
.editor-wrapper {
|
195 |
+
flex-basis: 60%; /* μλν°κ° μ°¨μ§ν κΈ°λ³Έ λμ΄ λΉμ¨ */
|
196 |
+
min-height: 200px; /* μ΅μ λμ΄ */
|
197 |
+
padding: 10px; /* μλν° μ£Όλ³ μ¬λ°± */
|
198 |
+
background-color: #f9f9f9; /* μλν° μμ λ°°κ²½ */
|
199 |
+
display: flex;
|
200 |
+
flex-direction: column;
|
201 |
+
}
|
202 |
+
#editor-container {
|
203 |
+
width: 100% !important;
|
204 |
+
height: 100% !important; /* λΆλͺ¨ λμ΄μ λ§οΏ½οΏ½ */
|
205 |
+
border: 1px solid var(--border-color);
|
206 |
+
border-radius: var(--border-radius);
|
207 |
+
overflow: hidden; /* Monaco μλν°μ μ체 μ€ν¬λ‘€ μ¬μ© */
|
208 |
+
}
|
209 |
+
.editor-controls {
|
210 |
+
display: flex;
|
211 |
+
justify-content: space-between;
|
212 |
+
align-items: center;
|
213 |
+
padding: 8px 0;
|
214 |
+
}
|
215 |
+
.editor-controls select, .editor-controls button {
|
216 |
+
padding: 6px 12px;
|
217 |
+
border-radius: 6px;
|
218 |
+
border: 1px solid var(--border-color);
|
219 |
+
background-color: white;
|
220 |
+
font-family: var(--font-family);
|
221 |
+
font-size: 13px;
|
222 |
+
cursor: pointer;
|
223 |
+
}
|
224 |
+
.editor-controls button { background-color: #e9ecef; color: var(--text-color); }
|
225 |
+
.editor-controls button:hover { background-color: #d1d5db; }
|
226 |
|
227 |
+
|
228 |
+
.preview-wrapper {
|
229 |
+
flex-basis: 40%; /* λ―Έλ¦¬λ³΄κΈ°κ° μ°¨μ§ν κΈ°λ³Έ λμ΄ λΉμ¨ */
|
230 |
+
min-height: 150px;
|
231 |
+
border-top: 1px solid var(--border-color);
|
232 |
+
padding: 10px;
|
233 |
+
background-color: #f9f9f9; /* 미리보기 μμ λ°°κ²½ */
|
234 |
+
display: flex; /* λ΄λΆ iframe ν¬κΈ° μ‘°μ μν΄ */
|
235 |
+
flex-direction: column;
|
236 |
+
}
|
237 |
+
.preview-wrapper h3 {
|
238 |
+
margin: 0 0 8px 0;
|
239 |
+
font-size: 14px;
|
240 |
+
font-weight: 500;
|
241 |
+
color: var(--text-secondary-color);
|
242 |
+
}
|
243 |
#html-preview {
|
244 |
+
flex-grow: 1; /* λ¨μ κ³΅κ° λͺ¨λ μ°¨μ§ */
|
245 |
width: 100%;
|
246 |
+
border: 1px solid var(--border-color);
|
247 |
+
border-radius: var(--border-radius);
|
248 |
+
background-color: white;
|
249 |
}
|
250 |
+
|
251 |
+
/* λ‘λ© μ€νΌλ */
|
252 |
.loader {
|
253 |
+
display: flex;
|
254 |
+
align-items: center;
|
255 |
+
font-size: 13px;
|
256 |
+
color: var(--text-secondary-color);
|
257 |
+
margin-left: 10px; /* μ
λ ₯μ°½ μμ νμλ λ */
|
|
|
|
|
|
|
258 |
}
|
259 |
+
.loader.inline-editor { margin-top: 5px; justify-content: center; }
|
260 |
|
261 |
+
.spinner {
|
262 |
+
width: 16px;
|
263 |
+
height: 16px;
|
264 |
+
border: 2px solid var(--accent-color);
|
265 |
+
border-top-color: transparent;
|
266 |
+
border-radius: 50%;
|
267 |
+
animation: spin 0.8s linear infinite;
|
268 |
+
margin-right: 8px;
|
269 |
+
}
|
270 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
271 |
+
|
272 |
+
/* λ°μν μ‘°μ */
|
273 |
+
@media (max-width: 1024px) {
|
274 |
+
.app-container { flex-direction: column; height: auto; max-height: none; }
|
275 |
+
.chat-editor-area { flex-direction: column; }
|
276 |
+
.chat-panel { border-right: none; border-bottom: 1px solid var(--border-color); max-height: 50vh; }
|
277 |
+
.editor-preview-area { flex: 1; } /* λ¨μ κ³΅κ° λͺ¨λ μ°¨μ§ */
|
278 |
}
|
279 |
+
@media (max-width: 768px) {
|
280 |
+
body { padding: 0; }
|
281 |
+
.app-container { width: 100%; height: 100vh; border-radius: 0; }
|
282 |
+
.chat-panel { padding: 15px; }
|
283 |
+
.editor-wrapper, .preview-wrapper { padding: 8px; }
|
284 |
+
.chat-input-area textarea { font-size: 14px; }
|
285 |
+
.chat-input-area button { width: 36px; height: 36px; font-size: 18px; }
|
286 |
+
}
|
287 |
+
|
288 |
</style>
|
289 |
</head>
|
290 |
<body>
|
291 |
+
<div class="app-container">
|
292 |
+
<!-- <div class="sidebar">Sidebar Content (Optional)</div> -->
|
293 |
+
<div class="main-content">
|
294 |
+
<div class="chat-editor-area">
|
295 |
+
<div class="chat-panel">
|
296 |
+
<div class="chat-messages" id="chatMessages">
|
297 |
+
<!-- AI μμ λ©μμ§ -->
|
298 |
+
<div class="message ai">
|
299 |
+
<div class="avatar">AI</div>
|
300 |
+
<div class="message-content">
|
301 |
+
μλ
νμΈμ! 무μμ λμλ릴κΉμ? HTML μμ±, μ½λ μμ±, λλ κΈ°μ‘΄ μ½λ μλ μμ±μ μμ²νμ€ μ μμ΅λλ€.
|
302 |
+
</div>
|
303 |
+
</div>
|
304 |
+
</div>
|
305 |
+
<div class="chat-input-area">
|
306 |
+
<textarea id="chatInput" placeholder="μ¬κΈ°μ λ©μμ§λ₯Ό μ
λ ₯νμΈμ..." rows="1"></textarea>
|
307 |
+
<button id="sendButton" title="μ μ‘">
|
308 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>
|
309 |
+
</button>
|
310 |
+
<div class="loader" id="chatLoader" style="display: none;"><div class="spinner"></div>μ²λ¦¬ μ€...</div>
|
311 |
+
</div>
|
312 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
|
314 |
+
<div class="editor-preview-area">
|
315 |
+
<div class="editor-wrapper">
|
316 |
+
<div class="editor-controls">
|
317 |
+
<select id="languageSelect">
|
318 |
+
<option value="html">HTML</option>
|
319 |
+
<option value="css">CSS</option>
|
320 |
+
<option value="javascript" selected>JavaScript</option>
|
321 |
+
<option value="python">Python</option>
|
322 |
+
<option value="java">Java</option>
|
323 |
+
<option value="csharp">C#</option>
|
324 |
+
</select>
|
325 |
+
<button id="getCompletionBtn">AI μ½λ μ±μ°κΈ° (FIM)</button>
|
326 |
+
</div>
|
327 |
+
<div id="editor-container"></div>
|
328 |
+
<div class="loader inline-editor" id="completionLoader" style="display: none;"><div class="spinner"></div>AIκ° μ½λλ₯Ό μ±μ°λ μ€...</div>
|
329 |
+
</div>
|
330 |
+
<div class="preview-wrapper">
|
331 |
+
<h3>HTML 미리보기</h3>
|
332 |
+
<iframe id="html-preview" sandbox="allow-scripts allow-same-origin"></iframe>
|
333 |
+
</div>
|
334 |
+
</div>
|
335 |
</div>
|
336 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
</div>
|
338 |
|
|
|
339 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/loader.min.js"></script>
|
340 |
<script>
|
|
|
341 |
let editor;
|
342 |
+
const chatMessages = document.getElementById('chatMessages');
|
343 |
+
const chatInput = document.getElementById('chatInput');
|
344 |
+
const sendButton = document.getElementById('sendButton');
|
345 |
+
const languageSelect = document.getElementById('languageSelect');
|
346 |
+
const getCompletionBtn = document.getElementById('getCompletionBtn');
|
347 |
+
const htmlPreviewEl = document.getElementById('html-preview');
|
348 |
+
const chatLoader = document.getElementById('chatLoader');
|
349 |
const completionLoader = document.getElementById('completionLoader');
|
350 |
|
351 |
+
// --- λ‘λ νμ/μ¨κΉ ν¨μ ---
|
352 |
+
function showLoader(loaderElement) { if (loaderElement) loaderElement.style.display = 'flex'; }
|
353 |
+
function hideLoader(loaderElement) { if (loaderElement) loaderElement.style.display = 'none'; }
|
|
|
|
|
|
|
|
|
|
|
354 |
|
355 |
+
// --- Monaco Editor μ΄κΈ°ν ---
|
356 |
require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs' }});
|
357 |
require(['vs/editor/editor.main'], function() {
|
358 |
editor = monaco.editor.create(document.getElementById('editor-container'), {
|
359 |
+
value: '// μ½λλ₯Ό μμ±νκ±°λ AIμκ² μμ²νμΈμ.\n// μ±ν
μ°½μ "μ¬κ°ν λ²νΌ λ§λ€μ΄μ€" κ°μ΄ μ
λ ₯ν΄λ³΄μΈμ.',
|
360 |
+
language: languageSelect.value,
|
361 |
+
theme: 'vs-dark', // μ΄λμ΄ ν
λ§
|
|
|
|
|
|
|
362 |
automaticLayout: true,
|
363 |
+
wordWrap: 'on',
|
364 |
+
minimap: { enabled: true, scale: 1 },
|
365 |
+
fontSize: 14,
|
366 |
+
lineNumbers: 'on',
|
367 |
+
roundedSelection: false,
|
368 |
+
scrollBeyondLastLine: false,
|
369 |
+
readOnly: false, // μ¬μ©μκ° μ§μ νΈμ§ κ°λ₯νλλ‘
|
370 |
+
padding: { top: 10, bottom: 10 }
|
371 |
});
|
|
|
372 |
|
373 |
+
// μΈμ΄ μ ν μ μλν° μΈμ΄ λ³κ²½
|
374 |
+
languageSelect.addEventListener('change', () => {
|
375 |
+
monaco.editor.setModelLanguage(editor.getModel(), languageSelect.value);
|
376 |
+
});
|
|
|
|
|
|
|
377 |
|
378 |
+
// FIM λ²νΌ ν΄λ¦ μ΄λ²€νΈ
|
379 |
+
getCompletionBtn.addEventListener('click', handleFIMRequest);
|
|
|
|
|
380 |
});
|
381 |
|
382 |
+
// --- μ±ν
λ©μμ§ μ²λ¦¬ ---
|
383 |
+
function addMessage(text, sender, isCode = false, lang = 'plaintext') {
|
384 |
+
const messageDiv = document.createElement('div');
|
385 |
+
messageDiv.classList.add('message', sender);
|
386 |
+
|
387 |
+
const avatarDiv = document.createElement('div');
|
388 |
+
avatarDiv.classList.add('avatar');
|
389 |
+
avatarDiv.textContent = sender === 'user' ? 'λ' : 'AI';
|
390 |
+
messageDiv.appendChild(avatarDiv);
|
391 |
+
|
392 |
+
const contentDiv = document.createElement('div');
|
393 |
+
contentDiv.classList.add('message-content');
|
394 |
+
|
395 |
+
if (isCode) {
|
396 |
+
// μ½λλ₯Ό Monaco Editorλ₯Ό μ¬μ©ν΄ λ λλ§ (μ½κΈ° μ μ©)
|
397 |
+
const pre = document.createElement('pre');
|
398 |
+
// κ°λ¨ν ν
μ€νΈλ‘ λ£κ±°λ, μλ‘μ΄ Monaco μΈμ€ν΄μ€λ₯Ό λ§λ€ μ μμ.
|
399 |
+
// μ¬κΈ°μλ κ°λ¨ν pre νκ·Έλ‘ μ²λ¦¬νκ³ , CSSλ‘ μ€νμΌλ§.
|
400 |
+
// μ€μ λ‘λ AI μλ΅μμ ```html ... ``` κ°μ λ§ν¬λ€μ΄ μ½λλΈλ‘ νμ± νμ
|
401 |
+
let codeContent = text;
|
402 |
+
const codeBlockMatch = text.match(/```(\w*)\n([\s\S]*?)```/);
|
403 |
+
if (codeBlockMatch) {
|
404 |
+
lang = codeBlockMatch[1] || lang;
|
405 |
+
codeContent = codeBlockMatch[2];
|
406 |
}
|
407 |
+
pre.textContent = codeContent; // μ€μ λ‘λ highlight.js λ±μΌλ‘ νμ΄λΌμ΄ν
μ μ©
|
408 |
+
contentDiv.appendChild(pre);
|
409 |
+
|
410 |
+
// μ½λ μλν°μ μ½λ μ½μ
λ²νΌ μΆκ° (μ ν μ¬ν)
|
411 |
+
const insertButton = document.createElement('button');
|
412 |
+
insertButton.textContent = 'μλν°μ μ½μ
';
|
413 |
+
insertButton.style.marginTop = '8px';
|
414 |
+
insertButton.style.padding = '5px 10px';
|
415 |
+
insertButton.style.fontSize = '12px';
|
416 |
+
insertButton.style.backgroundColor = '#f0f0f0';
|
417 |
+
insertButton.style.color = '#333';
|
418 |
+
insertButton.style.border = '1px solid #ccc';
|
419 |
+
insertButton.style.borderRadius = '4px';
|
420 |
+
insertButton.style.cursor = 'pointer';
|
421 |
+
insertButton.onclick = () => {
|
422 |
+
if (editor) {
|
423 |
+
editor.setValue(codeContent);
|
424 |
+
monaco.editor.setModelLanguage(editor.getModel(), lang);
|
425 |
+
if (lang.toLowerCase() === 'html') {
|
426 |
+
htmlPreviewEl.srcdoc = codeContent;
|
427 |
+
}
|
428 |
+
}
|
429 |
+
};
|
430 |
+
contentDiv.appendChild(insertButton);
|
431 |
+
|
432 |
+
} else {
|
433 |
+
contentDiv.textContent = text;
|
434 |
}
|
435 |
+
|
436 |
+
messageDiv.appendChild(contentDiv);
|
437 |
+
chatMessages.appendChild(messageDiv);
|
438 |
+
chatMessages.scrollTop = chatMessages.scrollHeight; // νμ μ΅μ λ©μμ§ λ³΄μ΄λλ‘ μ€ν¬λ‘€
|
439 |
+
}
|
440 |
+
|
441 |
+
// --- μ±ν
μ
λ ₯ μ²λ¦¬ ---
|
442 |
+
chatInput.addEventListener('input', () => { // textarea λμ΄ μλ μ‘°μ
|
443 |
+
chatInput.style.height = 'auto';
|
444 |
+
chatInput.style.height = (chatInput.scrollHeight) + 'px';
|
445 |
});
|
446 |
|
447 |
+
chatInput.addEventListener('keypress', (e) => {
|
448 |
+
if (e.key === 'Enter' && !e.shiftKey) { // Shift+Enterλ μ€λ°κΏ
|
449 |
+
e.preventDefault();
|
450 |
+
handleSendMessage();
|
451 |
+
}
|
452 |
+
});
|
453 |
+
sendButton.addEventListener('click', handleSendMessage);
|
454 |
+
|
455 |
+
async function handleSendMessage() {
|
456 |
+
const messageText = chatInput.value.trim();
|
457 |
+
if (!messageText) return;
|
458 |
+
|
459 |
+
addMessage(messageText, 'user');
|
460 |
+
chatInput.value = '';
|
461 |
+
chatInput.style.height = 'auto'; // λμ΄ μ΄κΈ°ν
|
462 |
+
sendButton.disabled = true;
|
463 |
+
showLoader(chatLoader);
|
464 |
+
|
465 |
+
// AI μλ΅ μ²λ¦¬ (κ°λ¨ν κ·μΉ κΈ°λ°μΌλ‘ μ΄λ€ API νΈμΆν μ§ κ²°μ )
|
466 |
+
let endpoint = '/api/generate-code'; // κΈ°λ³Έμ μ½λ μμ±
|
467 |
+
let payload = { prompt: messageText, language: languageSelect.value };
|
468 |
+
let responseIsCode = true;
|
469 |
+
let responseLang = languageSelect.value;
|
470 |
+
|
471 |
+
if (messageText.toLowerCase().includes('html λ§λ€μ΄μ€') || messageText.toLowerCase().includes('μΉνμ΄μ§ λ§λ€μ΄μ€') || messageText.toLowerCase().includes('htmlλ‘')) {
|
472 |
+
endpoint = '/api/generate-html';
|
473 |
+
payload = { prompt: messageText };
|
474 |
+
responseLang = 'html';
|
475 |
+
} else if (messageText.toLowerCase().includes('λ€μ μ½λ μμ±ν΄μ€') || messageText.toLowerCase().includes('μ½λ μ±μμ€')) {
|
476 |
+
// μ΄ κ²½μ°λ FIM λ²νΌμ μ¬μ©νλλ‘ μ λνκ±°λ, μλν° λ΄μ©μ κ°μ ΈμμΌ ν¨.
|
477 |
+
// μ¬κΈ°μλ μΌλ° μ½λ μμ±μΌλ‘ μ²λ¦¬.
|
478 |
+
addMessage("AI: μ½λ μλ μμ±(FIM)μ μλν° μμ 'AI μ½λ μ±μ°κΈ°' λ²νΌμ μ¬μ©ν΄μ£ΌμΈμ.", 'ai');
|
479 |
+
hideLoader(chatLoader);
|
480 |
+
sendButton.disabled = false;
|
481 |
return;
|
482 |
}
|
483 |
+
|
|
|
484 |
|
485 |
try {
|
486 |
+
const response = await fetch(endpoint, {
|
487 |
method: 'POST',
|
488 |
headers: { 'Content-Type': 'application/json' },
|
489 |
+
body: JSON.stringify(payload)
|
490 |
});
|
491 |
+
|
492 |
if (!response.ok) {
|
493 |
const errorData = await response.json();
|
494 |
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
|
495 |
}
|
496 |
const data = await response.json();
|
497 |
+
|
498 |
+
let aiResponseText = '';
|
499 |
+
if (endpoint === '/api/generate-html') {
|
500 |
+
aiResponseText = data.html;
|
501 |
+
addMessage("AI: μμ²νμ HTML μ½λμ
λλ€.", 'ai');
|
502 |
+
addMessage(aiResponseText, 'ai', true, 'html');
|
503 |
+
if (editor && confirm("μμ±λ HTMLμ μλν°μ νμνκ³ λ―Έλ¦¬λ³΄κΈ°λ₯Ό μ
λ°μ΄νΈν κΉμ?")) {
|
504 |
+
editor.setValue(aiResponseText);
|
505 |
+
monaco.editor.setModelLanguage(editor.getModel(), 'html');
|
506 |
+
htmlPreviewEl.srcdoc = aiResponseText;
|
507 |
+
} else {
|
508 |
+
htmlPreviewEl.srcdoc = aiResponseText; // 미리보기λ νμ μ
λ°μ΄νΈ
|
509 |
+
}
|
510 |
+
} else if (endpoint === '/api/generate-code') {
|
511 |
+
aiResponseText = data.code;
|
512 |
+
addMessage(`AI: μμ²νμ ${responseLang} μ½λμ
λλ€.`, 'ai');
|
513 |
+
addMessage(aiResponseText, 'ai', true, responseLang);
|
514 |
+
if (editor && confirm(`μμ±λ ${responseLang} μ½λλ₯Ό μλν°μ νμν κΉμ?`)) {
|
515 |
+
editor.setValue(aiResponseText);
|
516 |
+
monaco.editor.setModelLanguage(editor.getModel(), responseLang);
|
517 |
+
}
|
518 |
}
|
519 |
+
|
520 |
} catch (error) {
|
521 |
+
console.error('API Error:', error);
|
522 |
+
addMessage(`AI: μ£μ‘ν©λλ€. μμ² μ²λ¦¬ μ€ μ€λ₯κ° λ°μνμ΅λλ€: ${error.message}`, 'ai');
|
|
|
523 |
} finally {
|
524 |
+
hideLoader(chatLoader);
|
525 |
+
sendButton.disabled = false;
|
526 |
}
|
527 |
+
}
|
528 |
|
529 |
+
// --- FIM μμ² μ²λ¦¬ ---
|
530 |
+
async function handleFIMRequest() {
|
531 |
if (!editor) return;
|
532 |
|
533 |
const model = editor.getModel();
|
534 |
const position = editor.getPosition();
|
535 |
const fullCode = model.getValue();
|
|
|
536 |
const offset = model.getOffsetAt(position);
|
537 |
const prefix = fullCode.substring(0, offset);
|
538 |
const suffix = fullCode.substring(offset);
|
539 |
+
const language = languageSelect.value;
|
540 |
|
|
|
|
|
|
|
|
|
|
|
541 |
showLoader(completionLoader);
|
542 |
getCompletionBtn.disabled = true;
|
543 |
|
|
|
545 |
const response = await fetch('/api/complete-code', {
|
546 |
method: 'POST',
|
547 |
headers: { 'Content-Type': 'application/json' },
|
548 |
+
body: JSON.stringify({ prefix, suffix, language })
|
549 |
});
|
550 |
if (!response.ok) {
|
551 |
const errorData = await response.json();
|
|
|
553 |
}
|
554 |
const data = await response.json();
|
555 |
|
556 |
+
editor.executeEdits("api-fim-completion", [{
|
|
|
557 |
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
558 |
text: data.completion
|
559 |
}]);
|
560 |
+
addMessage(`AI: μ½λλ₯Ό μ±μ λ£μμ΅λλ€. (μλν° νμΈ)`, 'ai');
|
|
|
561 |
|
562 |
+
|
563 |
+
} catch (error)
|
564 |
+
{
|
565 |
+
console.error('FIM Error:', error);
|
566 |
+
addMessage(`AI: μ½λ μλ μμ± μ€ μ€λ₯: ${error.message}`, 'ai');
|
567 |
+
alert(`μ½λ μλ μμ± μ€ μ€λ₯: ${error.message}`);
|
568 |
} finally {
|
569 |
hideLoader(completionLoader);
|
570 |
getCompletionBtn.disabled = false;
|
571 |
}
|
572 |
+
}
|
573 |
+
|
574 |
+
// μ΄κΈ° λ©μμ§ μ΄ν 첫 μ
λ ₯ μ μλ΄ (μ ν)
|
575 |
+
// chatInput.addEventListener('focus', () => { ... }, { once: true });
|
576 |
+
|
577 |
</script>
|
578 |
</body>
|
579 |
</html>
|