-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathcss-variable-explorer.html
More file actions
386 lines (322 loc) · 9.78 KB
/
Copy pathcss-variable-explorer.html
File metadata and controls
386 lines (322 loc) · 9.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSS Variable Explorer & Theme Generator</title>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Inter:wght@400;500;600&display=swap" rel="stylesheet" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg: #0a0e1a;
--surface: #111827;
--surface2: #161d2e;
--border: #1f2d45;
--text: #e8edf5;
--cyan: #00d4c8;
--violet: #7c5cfc;
--radius: 8px;
--mono: "JetBrains Mono", monospace;
--sans: "Inter", sans-serif;
}
body {
background: var(--bg);
color: var(--text);
font-family: var(--sans);
padding: 30px;
}
.app {
max-width: 1200px;
margin: auto;
}
h1 {
font-family: var(--mono);
color: var(--cyan);
font-size: 32px;
margin-bottom: 25px;
}
h1 span {
color: var(--violet);
}
.layout {
display: grid;
grid-template-columns: 320px 320px 1fr;
gap: 20px;
align-items: start;
}
@media (max-width: 900px) {
.layout {
grid-template-columns: 1fr;
}
}
.left-panel,
.right-panel {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 20px;
}
h2 {
font-size: 18px;
margin-bottom: 15px;
color: var(--cyan);
}
textarea {
width: 100%;
height: 250px;
background: var(--surface2);
border: 1px solid var(--border);
color: white;
padding: 15px;
resize: none;
border-radius: 6px;
font-family: var(--mono);
}
button {
margin-top: 15px;
background: var(--cyan);
color: black;
border: none;
padding: 12px 20px;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
}
.preview-box {
background: var(--surface2);
border-radius: 6px;
padding: 20px;
min-height: 250px;
}
.demo-btn {
margin-bottom: 20px;
background: var(--demo-primary, #3498db);
color: white;
padding: 12px 20px;
border: none;
border-radius: var(--demo-radius, 6px);
}
.demo-card {
background: var(--demo-secondary, white);
color: var(--demo-text, black);
padding: 20px;
border-radius: var(--demo-radius, 8px);
border-left: 6px solid var(--demo-primary, #3498db);
}
input[type="text"] {
width: 100%;
padding: 12px;
margin-bottom: 15px;
background: var(--surface2);
border: 1px solid var(--border);
color: white;
border-radius: 6px;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
border: 1px solid var(--border);
padding: 12px;
text-align: left;
}
th {
background: var(--surface2);
color: var(--cyan);
}
.valueInput {
width: 100%;
padding: 8px;
background: var(--surface2);
color: white;
border: 1px solid var(--border);
border-radius: 4px;
font-family: var(--mono);
}
.colorPicker {
width: 40px;
height: 40px;
border: none;
background: none;
cursor: pointer;
padding: 0;
margin-right: 10px;
}
.button-group {
display: flex;
gap: 10px;
margin-top: 15px;
}
.button-group button {
margin-top: 0;
}
#variableTable {
width: 100%;
}
#variableTable tbody {
display: block;
max-height: 350px;
overflow-y: auto;
}
#variableTable thead,
#variableTable tbody tr {
display: table;
width: 100%;
table-layout: fixed;
}
.left-panel button {
margin-right: 10px;
}
</style>
</head>
<body>
<div class="app">
<h1>CSS <span>Variable Explorer</span></h1>
<div class="layout">
<!-- Paste CSS -->
<div class="left-panel">
<h2>Paste CSS</h2>
<textarea id="cssInput" placeholder="Paste your CSS here..."></textarea>
<div class="button-group">
<button id="extractBtn">Extract Variables</button>
<button id="copyBtn">Copy CSS</button>
<button id="downloadBtn">Download CSS</button>
</div>
</div>
<!-- Variables -->
<div class="left-panel">
<h2>Variables</h2>
<input type="text" id="searchBox" placeholder="Search variable..." />
<table id="variableTable">
<thead>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<!-- Live Preview -->
<div class="right-panel">
<h2>Live Preview</h2>
<div class="preview-box" id="previewBox">
<button class="demo-btn" id="demoBtn">Sample Button</button>
<div class="demo-card" id="demoCard">
<h3 id="cardTitle">Sample Card</h3>
<p id="cardText">Your theme preview will appear here.</p>
</div>
</div>
</div>
<!-- .right-panel -->
</div>
<!-- .layout -->
</div>
<!-- .app -->
<script>
const downloadBtn = document.getElementById("downloadBtn");
const copyBtn = document.getElementById("copyBtn");
const previewBox = document.getElementById("previewBox");
const cardTitle = document.getElementById("cardTitle");
const cardText = document.getElementById("cardText");
const demoBtn = document.getElementById("demoBtn");
const demoCard = document.getElementById("demoCard");
const searchBox = document.getElementById("searchBox");
const cssInput = document.getElementById("cssInput");
const extractBtn = document.getElementById("extractBtn");
const tableBody = document.querySelector("#variableTable tbody");
function isHexColor(value) {
return /^#([0-9a-f]{3,8})$/i.test(value.trim());
}
function escapeHTML(str) {
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
}
extractBtn.addEventListener("click", () => {
const css = cssInput.value;
const regex = /--([\w-]+)\s*:\s*([^;]+);/g;
let html = "";
let match;
while ((match = regex.exec(css)) !== null) {
const variable = "--" + match[1];
const value = match[2].trim();
const hex = isHexColor(value);
html += `<tr>
<td>${escapeHTML(variable)}</td>
<td>
${hex ? `<input type="color" value="${escapeHTML(value)}" class="colorPicker">` : ""}
<input type="text" class="valueInput" value="${escapeHTML(value)}">
</td>
</tr>`;
}
tableBody.innerHTML = html || `<tr><td colspan="2">No CSS variables found.</td></tr>`;
});
// Search Variables
searchBox.addEventListener("input", () => {
const rows = tableBody.querySelectorAll("tr");
rows.forEach((row) => {
const variable = row.cells[0].textContent.toLowerCase();
const search = searchBox.value.toLowerCase();
row.style.display = variable.includes(search) ? "" : "none";
});
});
tableBody.addEventListener("input", (e) => {
const row = e.target.closest("tr");
if (!row) return;
const variable = row.cells[0].textContent.trim();
const textInput = row.querySelector(".valueInput");
const colorPicker = row.querySelector(".colorPicker");
if (e.target.classList.contains("colorPicker")) {
textInput.value = colorPicker.value;
}
if (e.target.classList.contains("valueInput") && colorPicker && isHexColor(textInput.value)) {
colorPicker.value = textInput.value;
}
const value = textInput.value;
previewBox.style.setProperty("--demo-" + variable.slice(2), value);
});
copyBtn.addEventListener("click", () => {
let css = ":root {\n";
const rows = tableBody.querySelectorAll("tr");
rows.forEach((row) => {
const variable = row.cells[0].textContent.trim();
const value = row.querySelector(".valueInput").value;
css += ` ${variable}: ${value};\n`;
});
css += "}";
navigator.clipboard
.writeText(css)
.then(() => {
alert("CSS Copied!");
})
.catch(() => {
alert("Copy failed!");
});
});
downloadBtn.addEventListener("click", () => {
let css = ":root {\n";
const rows = tableBody.querySelectorAll("tr");
rows.forEach((row) => {
const variable = row.cells[0].textContent.trim();
const value = row.querySelector(".valueInput").value;
css += ` ${variable}: ${value};\n`;
});
css += "}";
const blob = new Blob([css], { type: "text/css" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "theme.css";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
</script>
</body>
</html>