-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathuuid-generator.html
More file actions
395 lines (351 loc) · 10.9 KB
/
Copy pathuuid-generator.html
File metadata and controls
395 lines (351 loc) · 10.9 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
387
388
389
390
391
392
393
394
395
<!--
UUID Generator
Single-file UUID v4 generator.
Built for One File Tools.
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>UUID Generator - One File Tools</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet" />
<style>
:root {
--bg: #0e1a2b;
--grid-line: #16263d;
--panel: #142440;
--panel-border: #23385c;
--accent: #ff6b35;
--accent-dim: #c2410c;
--cyan: #5eead4;
--text: #e9eff7;
--text-muted: #8aa0c2;
--text-dim: #4f6388;
--radius-sm: 8px;
--radius-md: 14px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Inter", system-ui, sans-serif;
background-color: var(--bg);
background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
background-size: 28px 28px;
color: var(--text);
padding: 48px 20px 64px;
min-height: 100vh;
}
.app {
max-width: 680px;
margin: 0 auto;
}
.hero {
text-align: center;
margin-bottom: 40px;
}
.eyebrow {
font-family: "JetBrains Mono", monospace;
font-size: 11px;
letter-spacing: 0.18em;
color: var(--cyan);
text-transform: uppercase;
margin-bottom: 14px;
}
.wordmark {
font-family: "Space Grotesk", sans-serif;
font-weight: 700;
font-size: clamp(40px, 7vw, 58px);
letter-spacing: -0.01em;
line-height: 1;
}
.tagline {
color: var(--text-muted);
font-size: 15px;
margin-top: 10px;
}
.studio {
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: var(--radius-md);
padding: 32px;
box-shadow: 0 24px 48px -14px rgba(0, 0, 0, 0.5);
}
.output-area {
position: relative;
margin-bottom: 24px;
}
.output-area textarea {
width: 100%;
min-height: 140px;
background: var(--bg);
border: 1px solid var(--panel-border);
border-radius: var(--radius-sm);
padding: 20px;
font-family: "JetBrains Mono", monospace;
font-size: 18px;
color: var(--cyan);
line-height: 1.6;
resize: vertical;
outline: none;
transition:
border-color 0.2s,
box-shadow 0.2s;
}
.output-area textarea:focus {
border-color: var(--cyan);
box-shadow: 0 0 0 2px rgba(94, 234, 212, 0.2);
}
.error-msg {
font-family: "JetBrains Mono", monospace;
font-size: 13px;
color: var(--accent);
min-height: 18px;
margin-bottom: 8px;
}
.output-area textarea.error {
border-color: var(--accent);
color: var(--accent);
}
.output-area textarea.error:focus {
box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.2);
}
.controls {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 16px;
padding-top: 24px;
border-top: 1px solid var(--panel-border);
}
.count-selector {
display: flex;
align-items: center;
gap: 12px;
}
.count-label {
font-family: "JetBrains Mono", monospace;
font-size: 12px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 0.1em;
}
.unit-toggle {
display: inline-flex;
background: var(--bg);
border: 1px solid var(--panel-border);
border-radius: 999px;
padding: 3px;
}
.unit-btn {
font-family: "JetBrains Mono", monospace;
font-size: 13px;
font-weight: 500;
border: none;
background: transparent;
color: var(--text-muted);
padding: 7px 16px;
border-radius: 999px;
cursor: pointer;
transition: all 0.2s;
}
.unit-btn.active {
background: var(--panel-border);
color: var(--text);
}
.unit-btn:hover:not(.active) {
color: var(--text);
}
.actions {
display: flex;
gap: 12px;
}
.btn {
display: inline-flex;
align-items: center;
gap: 8px;
font-family: "Inter", sans-serif;
font-size: 14px;
font-weight: 600;
border: none;
border-radius: var(--radius-sm);
padding: 12px 20px;
cursor: pointer;
transition: all 0.2s;
}
.btn-primary {
background: var(--accent);
color: #1a0f08;
}
.btn-primary:hover {
background: #ff7a4a;
transform: translateY(-1px);
}
.btn-secondary {
background: var(--bg);
color: var(--text);
border: 1px solid var(--panel-border);
}
.btn-secondary:hover {
border-color: var(--text-muted);
}
.btn svg {
width: 16px;
height: 16px;
}
/* Animations */
.hero,
.studio {
animation: rise 0.5s ease both;
}
.studio {
animation-delay: 0.1s;
}
@keyframes rise {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 600px) {
.controls {
flex-direction: column;
align-items: stretch;
}
.actions {
flex-direction: column;
}
.btn {
justify-content: center;
}
.count-selector {
justify-content: center;
}
}
</style>
</head>
<body>
<div class="app">
<header class="hero">
<div class="eyebrow">Developer Utility</div>
<h1 class="wordmark">UUID Gen</h1>
<p class="tagline">Generate random v4 UUIDs instantly, offline.</p>
</header>
<main class="studio">
<div class="output-area">
<p class="error-msg" id="errorMsg" role="alert" aria-live="polite"></p>
<textarea id="output" readonly aria-label="Generated UUIDs"></textarea>
</div>
<div class="controls">
<div class="count-selector">
<span class="count-label">Quantity</span>
<div class="unit-toggle" id="countToggle">
<button class="unit-btn active" data-count="1">1</button>
<button class="unit-btn" data-count="5">5</button>
<button class="unit-btn" data-count="10">10</button>
<button class="unit-btn" data-count="50">50</button>
</div>
</div>
<div class="actions">
<button class="btn btn-secondary" id="copyBtn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="11" height="11" rx="2" />
<path d="M5 15H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1" />
</svg>
<span id="copyLabel">Copy</span>
</button>
<button class="btn btn-primary" id="generateBtn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.2" />
</svg>
<span>Generate</span>
</button>
</div>
</div>
</main>
</div>
<script>
const outputEl = document.getElementById("output");
const errorMsg = document.getElementById("errorMsg");
const generateBtn = document.getElementById("generateBtn");
const copyBtn = document.getElementById("copyBtn");
const copyLabel = document.getElementById("copyLabel");
const countBtns = document.querySelectorAll(".unit-btn");
let currentCount = 1;
// Cache feature detection at initialization
const generateUUID =
typeof crypto !== "undefined" && typeof crypto.randomUUID === "function"
? () => crypto.randomUUID()
: typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function"
? () => {
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
bytes[8] = (bytes[8] & 0x3f) | 0x80; // RFC 4122 variant
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
}
: () => {
throw new Error("No cryptographic RNG available — UUID generation disabled.");
};
function updateOutput() {
try {
const uuids = [];
for (let i = 0; i < currentCount; i++) {
uuids.push(generateUUID());
}
outputEl.value = uuids.join("\n");
if (errorMsg.textContent) {
outputEl.classList.remove("error");
errorMsg.textContent = "";
}
} catch (err) {
outputEl.value = "";
outputEl.classList.add("error");
errorMsg.textContent = err.message;
}
}
countBtns.forEach((btn) => {
btn.addEventListener("click", () => {
countBtns.forEach((b) => b.classList.remove("active"));
btn.classList.add("active");
currentCount = parseInt(btn.dataset.count, 10);
updateOutput();
});
});
generateBtn.addEventListener("click", () => {
const icon = generateBtn.querySelector("svg");
icon.style.transition = "transform 0.3s ease";
icon.style.transform = `rotate(180deg)`;
setTimeout(() => {
icon.style.transition = "none";
icon.style.transform = `rotate(0deg)`;
}, 300);
updateOutput();
});
copyBtn.addEventListener("click", async () => {
try {
await navigator.clipboard.writeText(outputEl.value);
copyLabel.textContent = "Copied!";
} catch (err) {
copyLabel.textContent = "Error";
}
setTimeout(() => {
copyLabel.textContent = "Copy";
}, 2000);
});
// Initial generation
updateOutput();
</script>
</body>
</html>