-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
569 lines (503 loc) · 17.3 KB
/
Copy pathindex.html
File metadata and controls
569 lines (503 loc) · 17.3 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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
<!doctype html>
<html lang="en" class="h-full">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>paste-to-file</title>
<style>
@font-face {
font-family: "Alliance No.1";
src: url("./assets/fonts/alliance-no1-regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Alliance No.1";
src: url("./assets/fonts/alliance-no1-light.woff2") format("woff2");
font-weight: 300;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Alliance No.2";
src: url("./assets/fonts/alliance-no2-light.woff2") format("woff2");
font-weight: 300;
font-style: normal;
font-display: swap;
}
:root {
--bg: #05080d;
--panel: #070b12;
--input: #121a26;
--input-strong: #182233;
--line: rgba(34, 211, 238, 0.28);
--line-strong: rgba(34, 211, 238, 0.55);
--cyan: #22d3ee;
--cyan-soft: rgba(34, 211, 238, 0.12);
--text: #d7e6ef;
--muted: #5f7384;
--font-1: "Alliance No.1", sans-serif;
--font-2: "Alliance No.2", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--text);
font-family: var(--font-1);
background:
radial-gradient(900px 500px at 50% -20%, rgba(34, 211, 238, 0.07), transparent 60%),
var(--bg);
}
.shell {
height: 100%;
width: min(980px, 100%);
margin: 0 auto;
padding: 3.5rem 1.25rem;
display: flex;
flex-direction: column;
justify-content: center;
gap: 1rem;
}
@media (min-width: 640px) {
.shell {
padding: 4.5rem 1.5rem;
}
}
.bottom {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 1rem;
border-top: 1px solid var(--line);
padding-top: 0.75rem;
}
.github-link {
display: inline-flex;
align-items: center;
gap: 0.45rem;
font-family: var(--font-1);
font-size: 0.68rem;
letter-spacing: 0.16em;
text-transform: uppercase;
color: rgba(34, 211, 238, 0.55);
text-decoration: none;
transition: color 140ms ease;
}
.github-link:hover {
color: var(--cyan);
}
.github-link svg {
width: 1.1rem;
height: 1.1rem;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.85rem;
height: min(420px, calc(100vh - 10rem));
min-height: 280px;
}
@media (max-width: 860px) {
.grid {
grid-template-columns: 1fr;
height: min(560px, calc(100vh - 10rem));
}
}
.panel {
position: relative;
min-height: 0;
height: 100%;
background: var(--panel);
border: 1px solid var(--line);
box-shadow:
inset 0 0 0 1px rgba(34, 211, 238, 0.04),
0 0 24px rgba(34, 211, 238, 0.05);
}
.panel::before,
.panel::after {
display: none;
}
.editor {
height: 100%;
background: transparent;
}
#contentInput {
width: 100%;
height: 100%;
min-height: 0;
resize: none;
border: 0;
outline: none;
background: transparent;
color: var(--text);
font-family: var(--font-1);
font-weight: 300;
font-size: 1rem;
line-height: 1.65;
padding: 1.1rem 1.15rem;
}
#contentInput::placeholder {
color: var(--muted);
font-family: var(--font-2);
}
.editor:focus-within {
border-color: var(--line-strong);
box-shadow:
inset 0 0 0 1px rgba(34, 211, 238, 0.08),
0 0 28px rgba(34, 211, 238, 0.12);
}
.rail {
display: flex;
flex-direction: column;
gap: 0.85rem;
min-height: 0;
height: 100%;
background: transparent;
border: 0;
box-shadow: none;
}
.rail::before,
.rail::after {
display: none;
}
.contents {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
background: transparent;
border: 0;
box-shadow: none;
padding: 0;
}
.filename {
flex-shrink: 0;
display: flex;
flex-direction: column;
gap: 0.7rem;
height: auto;
background: transparent;
border: 0;
box-shadow: none;
padding: 0;
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: auto auto 1fr;
gap: 0;
flex: 1;
min-height: 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.stat {
display: flex;
flex-direction: column;
justify-content: flex-start;
gap: 0.15rem;
border-right: 1px solid var(--line);
border-bottom: 1px solid var(--line);
padding: 0.85rem 0.6rem;
}
.stat:nth-child(2n) {
border-right: 0;
}
.stat:nth-last-child(-n + 2) {
border-bottom: 0;
}
.stat-value {
font-family: var(--font-1);
font-size: 1.15rem;
color: var(--cyan);
text-shadow: 0 0 12px rgba(34, 211, 238, 0.35);
line-height: 1.1;
}
.stat-label {
font-family: var(--font-2);
font-size: 0.62rem;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--muted);
}
#filenameInput {
width: 100%;
height: 2.75rem;
border: 1px solid var(--line);
background: transparent;
color: var(--text);
font-family: var(--font-2);
font-weight: 300;
font-size: 0.9rem;
padding: 0 0.8rem;
outline: none;
transition: border-color 140ms ease, box-shadow 140ms ease;
}
#filenameInput:focus {
border-color: var(--line-strong);
background: transparent;
box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.2), 0 0 16px rgba(34, 211, 238, 0.15);
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 0.55rem;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.4rem;
height: 2.75rem;
width: 100%;
border: 1px solid var(--line-strong);
background: transparent;
color: var(--cyan);
font-family: var(--font-1);
font-size: 0.9rem;
letter-spacing: 0.04em;
cursor: pointer;
box-shadow: 0 0 16px rgba(34, 211, 238, 0.12);
transition: border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}
.btn svg {
width: 0.95rem;
height: 0.95rem;
}
.btn:hover {
border-color: var(--cyan);
box-shadow: 0 0 22px rgba(34, 211, 238, 0.28);
color: #a5f3fc;
}
.btn:active {
color: var(--cyan);
}
.btn:focus-visible {
outline: 1px solid var(--cyan);
outline-offset: 2px;
}
</style>
</head>
<body>
<main class="shell">
<section class="grid">
<div class="panel editor">
<textarea
id="contentInput"
placeholder="Paste your content here..."
spellcheck="false"
></textarea>
</div>
<aside class="rail">
<div class="contents">
<div class="stats">
<div class="stat">
<span id="statWords" class="stat-value">0</span>
<span class="stat-label">Words</span>
</div>
<div class="stat">
<span id="statChars" class="stat-value">0</span>
<span class="stat-label">Characters</span>
</div>
<div class="stat">
<span id="statRows" class="stat-value">0</span>
<span class="stat-label">Rows</span>
</div>
<div class="stat">
<span id="statCols" class="stat-value">—</span>
<span class="stat-label">Columns</span>
</div>
<div class="stat">
<span id="statSize" class="stat-value">0 B</span>
<span id="statSizeLabel" class="stat-label">Size</span>
</div>
<div class="stat">
<span id="statDelimiter" class="stat-value">—</span>
<span class="stat-label">Delimiter</span>
</div>
</div>
</div>
<div class="filename">
<input
id="filenameInput"
type="text"
value="my_converted_file"
placeholder="filename"
aria-label="Filename"
/>
<div class="actions">
<button id="downloadCsv" class="btn" type="button" aria-label="Download CSV file" title="Download CSV">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
<path d="M12 3v12"></path>
<path d="m7 10 5 5 5-5"></path>
<path d="M5 20h14"></path>
</svg>
.csv
</button>
<button id="downloadMd" class="btn" type="button" aria-label="Download Markdown file" title="Download Markdown">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
<path d="M12 3v12"></path>
<path d="m7 10 5 5 5-5"></path>
<path d="M5 20h14"></path>
</svg>
.md
</button>
<button id="downloadTxt" class="btn" type="button" aria-label="Download TXT file" title="Download TXT">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
<path d="M12 3v12"></path>
<path d="m7 10 5 5 5-5"></path>
<path d="M5 20h14"></path>
</svg>
.txt
</button>
</div>
</div>
</aside>
</section>
<footer class="bottom">
<a href="https://github.com/nickgreengithub/paste-to-file" target="_blank" class="github-link">
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 2C6.477 2 2 6.477 2 12c0 4.42 2.865 8.166 6.839 9.489.5.092.682-.217.682-.482 0-.237-.009-.866-.013-1.7-2.782.604-3.369-1.34-3.369-1.34-.454-1.156-1.11-1.463-1.11-1.463-.908-.62.069-.608.069-.608 1.003.07 1.531 1.03 1.531 1.03.892 1.529 2.341 1.087 2.91.831.092-.646.35-1.086.636-1.337-2.22-.253-4.555-1.11-4.555-4.943 0-1.091.39-1.984 1.029-2.683-.103-.253-.446-1.27.098-2.647 0 0 .84-.268 2.75 1.026A9.578 9.578 0 0 1 12 6.844a9.58 9.58 0 0 1 2.508.337c1.909-1.294 2.747-1.026 2.747-1.026.546 1.377.203 2.394.1 2.647.64.699 1.028 1.592 1.028 2.683 0 3.842-2.339 4.687-4.566 4.935.359.309.678.919.678 1.852 0 1.336-.012 2.415-.012 2.743 0 .267.18.578.688.48C19.138 20.163 22 16.418 22 12c0-5.523-4.477-10-10-10Z"/></svg>
GitHub
</a>
</footer>
</main>
<script>
const contentInput = document.getElementById("contentInput");
const filenameInput = document.getElementById("filenameInput");
const downloadCsv = document.getElementById("downloadCsv");
const downloadMd = document.getElementById("downloadMd");
const downloadTxt = document.getElementById("downloadTxt");
const statWords = document.getElementById("statWords");
const statChars = document.getElementById("statChars");
const statRows = document.getElementById("statRows");
const statCols = document.getElementById("statCols");
const statSize = document.getElementById("statSize");
const statSizeLabel = document.getElementById("statSizeLabel");
const statDelimiter = document.getElementById("statDelimiter");
const formatSize = (bytes) => {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
};
const byteSize = (value) => new TextEncoder().encode(value).length;
const delimiterChar = (delim) => {
if (delim === "tab") return "\t";
if (delim === "pipe") return "|";
return ",";
};
const detectDelimiter = (text) => {
if (!text) return null;
const lines = text.split(/\r\n|\n|\r/).filter((l) => l.length > 0);
if (lines.length === 0) return null;
const sample = lines.slice(0, 20);
const commaHits = sample.reduce((n, l) => n + (l.match(/,/g) || []).length, 0);
const tabHits = sample.reduce((n, l) => n + (l.match(/\t/g) || []).length, 0);
const pipeHits = sample.reduce((n, l) => n + (l.match(/\|/g) || []).length, 0);
const max = Math.max(commaHits, tabHits, pipeHits);
if (max === 0) return null;
if (tabHits === max) return "tab";
if (pipeHits === max) return "pipe";
return "comma";
};
const isCsvSuited = (text, delim) => {
if (!delim || !text.trim()) return false;
const lines = text.split(/\r\n|\n|\r/).filter((l) => l.trim().length > 0);
if (lines.length === 0) return false;
const d = delimiterChar(delim);
const counts = lines.map((line) => line.split(d).length);
const maxCols = Math.max(...counts);
if (maxCols < 2) return false;
const matching = counts.filter((count) => count === maxCols).length;
return matching / counts.length >= 0.8;
};
const escapeCsvField = (field) => {
if (/[",\r\n]/.test(field)) return `"${field.replace(/"/g, '""')}"`;
return field;
};
const csvByteSize = (text, delim) => {
const d = delimiterChar(delim);
const lines = text.split(/\r\n|\n|\r/).filter((l) => l.length > 0);
const csv = lines
.map((line) => line.split(d).map(escapeCsvField).join(","))
.join("\n");
return byteSize(csv);
};
const hasMarkdownIndicators = (text) => {
if (!text.trim()) return false;
const lines = text.split(/\r\n|\n|\r/);
return lines.some((line) => /^\s*#/.test(line));
};
const detectSizeFormat = (text) => {
if (!text.trim()) {
return { label: "Size", bytes: 0 };
}
const delim = detectDelimiter(text);
if (isCsvSuited(text, delim)) {
return { label: "CSV-Size", bytes: csvByteSize(text, delim) };
}
if (hasMarkdownIndicators(text)) {
return { label: "MD-Size", bytes: byteSize(text) };
}
return { label: "TXT-Size", bytes: byteSize(text) };
};
const countCsvColumns = (text, delim) => {
const d = delimiterChar(delim);
const lines = text.split(/\r\n|\n|\r/).filter((l) => l.trim().length > 0);
return lines.reduce((max, line) => {
const cols = line.split(d).length;
return cols > max ? cols : max;
}, 0);
};
const updateStats = () => {
const text = contentInput.value ?? "";
const trimmed = text.trim();
const words = trimmed ? trimmed.split(/\s+/).length : 0;
const chars = text.length;
const rows = text === "" ? 0 : text.split(/\r\n|\n|\r/).length;
const delim = detectDelimiter(text);
const csvSuited = isCsvSuited(text, delim);
const sizeFormat = detectSizeFormat(text);
statWords.textContent = String(words);
statChars.textContent = String(chars);
statRows.textContent = String(rows);
statCols.textContent = csvSuited ? String(countCsvColumns(text, delim)) : "—";
statSize.textContent = formatSize(sizeFormat.bytes);
statSizeLabel.textContent = sizeFormat.label;
statDelimiter.textContent = csvSuited ? delim : "—";
};
const downloadFile = (extension, mimeType) => {
const text = contentInput.value ?? "";
const blob = new Blob([text], { type: `${mimeType};charset=utf-8` });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
const baseName = (filenameInput.value || "my_converted_file").trim();
const safeName = baseName.replace(/[<>:"/\\|?*\u0000-\u001f]/g, "_");
link.href = url;
link.download = `${safeName || "my_converted_file"}.${extension}`;
document.body.appendChild(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
};
contentInput.addEventListener("input", updateStats);
updateStats();
downloadCsv.addEventListener("click", () => {
downloadFile("csv", "text/csv");
});
downloadMd.addEventListener("click", () => {
downloadFile("md", "text/markdown");
});
downloadTxt.addEventListener("click", () => {
downloadFile("txt", "text/plain");
});
</script>
</body>
</html>