-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1166 lines (1069 loc) · 43.5 KB
/
index.html
File metadata and controls
1166 lines (1069 loc) · 43.5 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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>rt-meta-kit · Rethink JS</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
rel="stylesheet"
/>
<script>
(function () {
function applyConfig() {
if (typeof tailwind === "undefined") {
setTimeout(applyConfig, 10);
return;
}
tailwind.config = {
darkMode: "class",
theme: {
extend: {
fontFamily: {
sans: ["Inter", "sans-serif"],
mono: ["JetBrains Mono", "monospace"],
},
colors: {
slate: {
850: "#151e2e",
900: "#0f172a",
950: "#020617",
},
brand: {
DEFAULT: "#FFD632",
dim: "#b39005",
glow: "rgba(255, 214, 50, 0.15)",
},
},
animation: {
"fade-in": "fadeIn 0.5s ease-out forwards",
},
keyframes: {
fadeIn: {
"0%": { opacity: "0", transform: "translateY(10px)" },
"100%": { opacity: "1", transform: "translateY(0)" },
},
},
},
},
};
}
applyConfig();
})();
</script>
<style>
::selection {
background-color: rgba(255, 214, 50, 0.3);
color: #fff;
}
.canvas-bg {
background-color: #0f172a;
background-image:
linear-gradient(45deg, #1e293b 25%, transparent 25%),
linear-gradient(-45deg, #1e293b 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #1e293b 75%),
linear-gradient(-45deg, transparent 75%, #1e293b 75%);
background-size: 20px 20px;
background-position:
0 0,
0 10px,
10px -10px,
-10px 0px;
}
input[type="color"]::-webkit-color-swatch-wrapper {
padding: 0;
}
input[type="color"]::-webkit-color-swatch {
border: none;
border-radius: 4px;
}
.drag-active {
border-color: #ffd632 !important;
background-color: rgba(255, 214, 50, 0.05) !important;
}
/* Custom Scrollbar */
.custom-scroll::-webkit-scrollbar {
height: 6px;
width: 6px;
}
.custom-scroll::-webkit-scrollbar-track {
background: #0f172a;
border-radius: 3px;
}
.custom-scroll::-webkit-scrollbar-thumb {
background: #334155;
border-radius: 3px;
}
.custom-scroll::-webkit-scrollbar-thumb:hover {
background: #475569;
}
.manifest-active-border {
border-color: #ffd632 !important; /* Brand color */
box-shadow: 0 0 0 1px #ffd632 !important;
}
</style>
</head>
<body
class="bg-slate-950 text-slate-300 min-h-screen flex flex-col font-sans antialiased"
>
<header
class="border-b border-slate-800 bg-slate-950/50 backdrop-blur-md sticky top-0 z-20"
>
<div
class="max-w-6xl mx-auto px-6 py-4 flex items-center justify-between"
>
<div class="flex items-center gap-3">
<img
src="https://avatars.githubusercontent.com/u/245584241?s=256"
alt="Rethink JS Logo"
class="w-8 h-8 rounded-lg border border-slate-700"
/>
<h1 class="font-semibold text-slate-100 tracking-tight">
rt-meta-kit
<span class="text-slate-500 font-normal ml-1">Icon Assets</span>
</h1>
</div>
<a
href="https://github.com/Rethink-JS/rt-meta-kit"
target="_blank"
class="flex items-center gap-2 text-xs font-medium bg-slate-800 hover:bg-slate-700 text-slate-300 px-3 py-2 rounded-full transition-colors group"
>
<svg
viewBox="0 0 24 24"
aria-hidden="true"
class="w-4 h-4 fill-current group-hover:text-brand transition-colors"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M12 2C6.477 2 2 6.463 2 11.97c0 4.404 2.865 8.14 6.839 9.458.5.092.682-.216.682-.48 0-.236-.008-.864-.013-1.695-2.782.602-3.369-1.337-3.369-1.337-.454-1.151-1.11-1.462-1.11-1.462-.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.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.11-4.555-4.943 0-1.091.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.269 2.75 1.025A9.578 9.578 0 0112 6.836c.85.004 1.705.114 2.504.336 1.909-1.294 2.747-1.025 2.747-1.025.546 1.379.203 2.398.1 2.651.64.699 1.028 1.597 1.028 2.688 0 3.848-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.577.688.48 3.97-1.32 6.833-5.054 6.833-9.458C22 6.463 17.522 2 12 2z"
></path>
</svg>
<span>View on GitHub</span>
</a>
</div>
</header>
<main class="flex-1 max-w-6xl mx-auto px-6 py-10 w-full">
<section class="mb-10 text-center lg:text-left">
<h2 class="text-2xl font-bold text-slate-100 mb-2">
Project Icon Generator
</h2>
<p class="text-slate-400">Upload an SVG to generate all sizes.</p>
</section>
<div class="grid grid-cols-1 lg:grid-cols-12 gap-10">
<div class="lg:col-span-7 space-y-8">
<div class="space-y-3">
<div class="flex items-center gap-2">
<span
class="w-6 h-6 rounded-full bg-slate-800 border border-slate-700 text-slate-400 text-xs flex items-center justify-center font-mono"
>1</span
>
<h3
class="text-sm font-bold text-slate-200 uppercase tracking-wide"
>
Upload Main Logo
</h3>
</div>
<div
id="dropZone"
onclick="triggerFileSelect()"
class="group border-2 border-dashed border-slate-700 bg-slate-900/30 rounded-2xl p-8 text-center transition-all duration-200 cursor-pointer hover:border-brand hover:bg-slate-900/50 hover:shadow-[0_0_20px_-5px_rgba(255,214,50,0.1)]"
>
<input type="file" id="fileInput" accept=".svg" class="hidden" />
<div class="pointer-events-none space-y-3">
<div
class="w-12 h-12 bg-slate-800 rounded-full flex items-center justify-center mx-auto text-brand group-hover:scale-110 transition-transform duration-200"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"
/>
</svg>
</div>
<div>
<h3
id="dropText"
class="text-slate-200 font-medium group-hover:text-brand transition-colors"
>
Click to upload Main SVG
</h3>
<p class="text-slate-500 text-xs mt-1">
This will be used for all icons by default.
</p>
</div>
</div>
</div>
</div>
<div
id="step2"
class="space-y-3 opacity-50 pointer-events-none transition-opacity"
>
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<span
class="w-6 h-6 rounded-full bg-slate-800 border border-slate-700 text-slate-400 text-xs flex items-center justify-center font-mono"
>2</span
>
<h3
class="text-sm font-bold text-slate-200 uppercase tracking-wide"
>
Review & Customize
</h3>
</div>
<span
class="text-[10px] text-slate-500 bg-slate-900 border border-slate-800 px-2 py-0.5 rounded"
>Pro Tip: Swap individual files below</span
>
</div>
<div
class="bg-slate-900/50 border border-slate-800 rounded-2xl p-6"
>
<div
id="previewGrid"
class="flex gap-4 mb-6 overflow-x-auto py-2 custom-scroll"
></div>
<button
id="downloadBtn"
onclick="downloadZip()"
class="w-full bg-brand hover:bg-[#ffe16b] text-slate-950 font-bold py-3 px-4 rounded-lg shadow-[0_0_25px_-5px_rgba(255,214,50,0.3)] transition-all transform active:scale-[0.98] flex items-center justify-center gap-2"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"
/>
</svg>
Download Assets (.zip)
</button>
</div>
</div>
<div
id="step3"
class="space-y-3 opacity-50 pointer-events-none transition-opacity"
>
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<span
class="w-6 h-6 rounded-full bg-slate-800 border border-slate-700 text-slate-400 text-xs flex items-center justify-center font-mono"
>3</span
>
<h3
class="text-sm font-bold text-slate-200 uppercase tracking-wide"
>
Configure Locations
</h3>
</div>
</div>
<div
class="bg-slate-900/50 border border-slate-800 rounded-2xl p-6 space-y-6"
>
<div class="space-y-4">
<p
class="text-xs text-slate-500 uppercase font-bold tracking-wider flex justify-between"
>
Asset Paths
<span
class="text-brand opacity-80 normal-case font-normal text-[10px]"
>Accepts CDN / Absolute URLs</span
>
</p>
<div id="urlList" class="space-y-3"></div>
</div>
<div class="h-px bg-slate-800 w-full"></div>
<div class="space-y-4">
<div class="flex items-center justify-between">
<p
class="text-xs text-slate-500 uppercase font-bold tracking-wider"
>
Browser UI Colors
</p>
<span
id="colorStatus"
class="text-[10px] text-brand opacity-0 transition-opacity"
>✨ Auto-detected from logo</span
>
</div>
<div class="space-y-1">
<label class="text-xs text-slate-400"
>Theme Color (Browser Bar)</label
>
<div class="flex gap-2">
<input
type="color"
id="manTheme"
value="#0f172a"
class="h-9 w-12 bg-transparent cursor-pointer"
/>
<input
type="text"
id="manThemeText"
value="#0f172a"
class="flex-1 bg-slate-900 border border-slate-800 rounded px-3 py-2 text-sm text-slate-200 font-mono focus:border-brand/50 focus:outline-none uppercase"
/>
</div>
</div>
</div>
<div class="h-px bg-slate-800 w-full"></div>
<div class="space-y-4">
<div class="flex items-center justify-between">
<p
class="text-xs text-slate-500 uppercase font-bold tracking-wider"
>
Manifest Details
</p>
<span
class="text-[10px] bg-slate-800 text-slate-400 px-2 py-0.5 rounded"
>Required for PWA</span
>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="space-y-1">
<label class="text-xs text-slate-400">App Name</label>
<input
type="text"
id="manName"
placeholder="My App"
class="w-full bg-slate-900 border border-slate-800 rounded px-3 py-2 text-sm text-slate-200 focus:border-brand/50 focus:outline-none"
/>
</div>
<div class="space-y-1">
<label class="text-xs text-slate-400">Short Name</label>
<input
type="text"
id="manShort"
placeholder="MyApp"
class="w-full bg-slate-900 border border-slate-800 rounded px-3 py-2 text-sm text-slate-200 focus:border-brand/50 focus:outline-none"
/>
</div>
</div>
<div class="space-y-1">
<label class="text-xs text-slate-400">Description</label>
<input
type="text"
id="manDesc"
placeholder="App description"
class="w-full bg-slate-900 border border-slate-800 rounded px-3 py-2 text-sm text-slate-200 focus:border-brand/50 focus:outline-none"
/>
</div>
<div class="space-y-1">
<label class="text-xs text-slate-400"
>Background Color (Splash Screen)</label
>
<div class="flex gap-2">
<input
type="color"
id="manBg"
value="#020617"
class="h-9 w-12 bg-transparent cursor-pointer"
/>
<input
type="text"
id="manBgText"
value="#020617"
class="flex-1 bg-slate-900 border border-slate-800 rounded px-3 py-2 text-sm text-slate-200 font-mono focus:border-brand/50 focus:outline-none uppercase"
/>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="lg:col-span-5 space-y-6 sticky top-24 h-fit">
<div
class="bg-slate-900 rounded-xl border border-slate-800 overflow-hidden shadow-2xl shadow-black/50 flex flex-col"
>
<div
class="bg-slate-850 px-2 py-2 border-b border-slate-800 flex items-center justify-between"
>
<div class="flex gap-1 ml-2">
<div class="w-3 h-3 rounded-full bg-slate-700"></div>
<div class="w-3 h-3 rounded-full bg-slate-700"></div>
<div class="w-3 h-3 rounded-full bg-slate-700"></div>
</div>
<div
class="flex bg-slate-900 rounded-lg p-1 border border-slate-800"
>
<button
onclick="switchTab('head')"
id="tabHead"
class="px-3 py-1 rounded text-xs font-medium text-slate-950 bg-brand shadow-sm transition-all"
>
HTML <head>
</button>
<button
onclick="switchTab('json')"
id="tabJson"
class="px-3 py-1 rounded text-xs font-medium text-slate-400 hover:text-slate-200 transition-all"
>
Manifest
</button>
</div>
</div>
<div class="relative group">
<div
id="viewHead"
class="p-4 overflow-x-auto min-h-[400px] max-h-[600px] text-xs font-mono leading-relaxed custom-scroll"
>
<div class="text-slate-500 select-none mb-2">
<!-- Paste this in your <head> -->
</div>
<pre
class="text-slate-300"
><code id="codeHead" class="language-html"></code></pre>
</div>
<div
id="viewJson"
class="hidden p-4 min-h-[400px] max-h-[600px] flex flex-col relative"
>
<div
class="text-slate-500 select-none mb-2 text-xs font-mono flex justify-between items-center"
>
<span>// Preview</span>
<button
onclick="downloadManifest()"
class="text-brand hover:underline flex items-center gap-1"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-3 w-3"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"
/>
</svg>
Download File
</button>
</div>
<div class="overflow-x-auto custom-scroll flex-1">
<pre
class="text-brand text-xs font-mono leading-relaxed"
><code id="codeJson"></code></pre>
</div>
</div>
<button
onclick="copyCode()"
class="absolute top-12 right-4 bg-slate-800/80 backdrop-blur hover:bg-slate-700 p-2 rounded-lg border border-slate-700 text-slate-300 transition-colors opacity-0 group-hover:opacity-100 z-10"
title="Copy Code"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-4 w-4"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"
/>
</svg>
</button>
</div>
</div>
<div
class="bg-amber-500/10 border border-amber-500/20 rounded-lg p-4 flex items-start gap-3"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5 text-amber-500 shrink-0 mt-0.5"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
clip-rule="evenodd"
/>
</svg>
<div>
<h3 class="text-amber-500 font-semibold text-sm">
Deployment Tip
</h3>
<p class="text-amber-500/80 text-xs mt-1 leading-relaxed">
Serve the manifest file as
<code>application/manifest+json</code>. <br />We only included
icon-related tags. Don't forget your
<code><title></code> and <code>meta description</code>!
</p>
</div>
</div>
</div>
</div>
</main>
<footer class="border-t border-slate-900 py-10 text-center">
<div
class="inline-flex items-center gap-2 bg-slate-900/50 border border-slate-800 rounded-full px-4 py-1.5 mb-6 shadow-sm"
>
<svg
class="w-3 h-3 text-green-500"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"
/>
</svg>
<span class="text-xs text-slate-400 font-medium"
>100% Client-Side & Secure</span
>
</div>
<p
class="text-slate-500 text-xs max-w-2xl mx-auto leading-relaxed mb-6 px-4"
>
<span class="font-semibold text-slate-400"
>Privacy & Security Notice:</span
>
This tool operates entirely within your browser (Client-Side). No logos,
SVGs, or generated assets are ever uploaded to a server or stored
remotely. All processing happens locally on your machine.
</p>
<p
class="mt-2 text-xs flex items-center justify-center gap-1.5 text-slate-500"
>
Powered by
<a
href="https://github.com/Rethink-JS"
target="_blank"
class="font-bold text-slate-400 hover:text-brand transition-colors duration-200"
>
Rethink JS
</a>
</p>
</footer>
<script>
// CONFIGURATION
const assetsConfig = [
{ name: "favicon.ico", size: 32, type: "ico", label: "Legacy Favicon" },
{
name: "favicon-16x16.png",
size: 16,
type: "png",
label: "Browser Icon 16px",
},
{
name: "favicon-32x32.png",
size: 32,
type: "png",
label: "Browser Icon 32px",
},
{
name: "apple-touch-icon.png",
size: 180,
type: "png",
label: "Apple / iOS Icon",
},
{
name: "android-chrome-192x192.png",
size: 192,
type: "png",
label: "PWA / Android Icon",
},
{
name: "android-chrome-512x512.png",
size: 512,
type: "png",
label: "PWA Splash Icon",
},
];
// STATE
let generatedBlobs = {};
let fileURLMap = {};
let currentTab = "head";
let activeManifest = "manifest.json"; // Set default to manifest.json
// DRAG & DROP
const dropZone = document.getElementById("dropZone");
const fileInput = document.getElementById("fileInput");
function triggerFileSelect() {
fileInput.click();
}
fileInput.addEventListener("change", (e) => handleFiles(e.target.files));
["dragenter", "dragover", "dragleave", "drop"].forEach((name) => {
dropZone.addEventListener(name, (e) => {
e.preventDefault();
e.stopPropagation();
});
});
["dragenter", "dragover"].forEach((name) =>
dropZone.addEventListener(name, () =>
dropZone.classList.add("drag-active"),
),
);
["dragleave", "drop"].forEach((name) =>
dropZone.addEventListener(name, () =>
dropZone.classList.remove("drag-active"),
),
);
dropZone.addEventListener("drop", (e) =>
handleFiles(e.dataTransfer.files),
);
function handleFiles(files) {
if (files.length && files[0].type.includes("svg")) {
processSVG(files[0]);
} else {
alert("Please upload an SVG file.");
}
}
// PROCESSING
function processSVG(file) {
const url = URL.createObjectURL(file);
const img = new Image();
img.onload = async () => {
// Reset
generatedBlobs = {};
const previewGrid = document.getElementById("previewGrid");
previewGrid.innerHTML = "";
const urlList = document.getElementById("urlList");
urlList.innerHTML = "";
// Init defaults
fileURLMap = {};
// Auto Detect Color from Canvas
const detectedColor = getDominantColor(img);
if (detectedColor) {
updateColorInputs(detectedColor);
}
// Process Each Asset
for (const asset of assetsConfig) {
await generateAndRenderAsset(img, asset, previewGrid, urlList);
}
// Render Manifest Inputs (Both .webmanifest and .json)
renderManifestInputs(urlList);
// UI Transitions
document.getElementById("dropText").innerText =
"Main Logo Processed!";
dropZone.classList.add("border-brand", "bg-brand/5");
const step2 = document.getElementById("step2");
const step3 = document.getElementById("step3");
step2.classList.remove("opacity-50", "pointer-events-none");
step3.classList.remove("opacity-50", "pointer-events-none");
updateCode();
};
img.src = url;
}
// COLOR DETECTION LOGIC
function getDominantColor(sourceImg) {
const canvas = document.createElement("canvas");
canvas.width = 100;
canvas.height = 100;
const ctx = canvas.getContext("2d");
ctx.drawImage(sourceImg, 0, 0, 100, 100);
const imageData = ctx.getImageData(0, 0, 100, 100).data;
const colorCounts = {};
let maxCount = 0;
let dominantColor = null;
for (let i = 0; i < imageData.length; i += 4) {
const r = imageData[i];
const g = imageData[i + 1];
const b = imageData[i + 2];
const a = imageData[i + 3];
// Skip transparent
if (a < 128) continue;
const key = `${r},${g},${b}`;
colorCounts[key] = (colorCounts[key] || 0) + 1;
if (colorCounts[key] > maxCount) {
maxCount = colorCounts[key];
dominantColor = { r, g, b };
}
}
if (dominantColor) {
return rgbToHex(dominantColor.r, dominantColor.g, dominantColor.b);
}
return null;
}
function rgbToHex(r, g, b) {
return (
"#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
);
}
function updateColorInputs(hex) {
document.getElementById("manTheme").value = hex;
document.getElementById("manThemeText").value = hex;
document.getElementById("manBg").value = hex;
document.getElementById("manBgText").value = hex;
// Show status
const status = document.getElementById("colorStatus");
status.classList.remove("opacity-0");
setTimeout(() => status.classList.add("opacity-0"), 5000);
}
// RENDER ASSET CARD
async function generateAndRenderAsset(
sourceImg,
asset,
previewGrid,
urlList,
isUpdate = false,
) {
let blob;
if (asset.type === "ico") {
blob = await generateIcoBlob(sourceImg, asset.size);
} else {
blob = await generatePngBlob(sourceImg, asset.size);
}
generatedBlobs[asset.name] = blob;
const blobUrl = URL.createObjectURL(blob);
// If updating, just update the image tag in existing grid
if (isUpdate) {
const imgEl = document.getElementById(`preview-img-${asset.name}`);
if (imgEl) imgEl.src = blobUrl;
return;
}
// Preview Card
const div = document.createElement("div");
div.className =
"shrink-0 flex flex-col items-center gap-3 bg-slate-900/50 p-3 rounded-xl border border-slate-800 w-28";
div.innerHTML = `
<div class="w-16 h-16 bg-slate-800 rounded-lg flex items-center justify-center p-2 border border-slate-700 relative group overflow-hidden">
<img id="preview-img-${asset.name}" src="${blobUrl}" class="max-w-full max-h-full transition-opacity group-hover:opacity-50">
<div class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
<button onclick="document.getElementById('swap-${asset.name}').click()" class="bg-brand text-slate-950 rounded-full p-1.5 shadow-lg hover:scale-110 transition-transform" title="Replace this icon">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
</svg>
</button>
</div>
</div>
<div class="text-center w-full">
<div class="text-[10px] font-mono text-slate-400 truncate w-full" title="${asset.name}">${asset.name}</div>
<input type="file" id="swap-${asset.name}" accept=".svg, .png, .jpg, .gif, .webp" class="hidden" onchange="swapAsset('${asset.name}', this)">
<button onclick="document.getElementById('swap-${asset.name}').click()" class="text-[10px] text-brand hover:text-white underline mt-1">Replace</button>
</div>
`;
previewGrid.appendChild(div);
// Input Row
const row = document.createElement("div");
row.className = "flex items-center gap-3";
const defaultPath = `/${asset.name}`;
fileURLMap[asset.name] = defaultPath;
row.innerHTML = `
<div class="w-8 h-8 bg-slate-800 rounded flex items-center justify-center shrink-0 border border-slate-700">
<img src="${blobUrl}" class="w-4 h-4 object-contain">
</div>
<div class="flex-1 space-y-1">
<div class="flex justify-between">
<label class="text-[10px] text-slate-400 uppercase font-bold">${asset.label}</label>
<span class="text-[10px] text-slate-600 font-mono">${asset.name}</span>
</div>
<input type="text"
data-file="${asset.name}"
value="${defaultPath}"
oninput="updateUrl('${asset.name}', this.value)"
class="w-full bg-slate-900 border border-slate-800 rounded px-2 py-1.5 text-xs text-brand font-mono focus:border-brand/50 focus:outline-none placeholder:text-slate-700"
placeholder="https://your-site.com/assets/${asset.name}"
>
</div>
`;
urlList.appendChild(row);
}
function renderManifestInputs(urlList) {
// Create a header for Manifest URL section
const header = document.createElement("div");
header.className = "mt-4 pt-4 border-t border-slate-800 pb-2";
header.innerHTML = `
<p class="text-[10px] text-slate-500 uppercase font-bold tracking-wider mb-2">Manifest Strategy</p>
`;
urlList.appendChild(header);
// SEGMENTED CONTROL FOR MANIFEST TOGGLE
const toggleContainer = document.createElement("div");
toggleContainer.className =
"bg-slate-900 p-1 rounded-lg flex mb-4 border border-slate-800";
toggleContainer.innerHTML = `
<button onclick="setActiveManifest('manifest.json')" id="btn-json" class="flex-1 py-1.5 text-xs font-medium rounded-md bg-brand text-slate-950 shadow-sm transition-all">
manifest.json
</button>
<button onclick="setActiveManifest('site.webmanifest')" id="btn-webmanifest" class="flex-1 py-1.5 text-xs font-medium rounded-md text-slate-400 hover:text-slate-200 transition-all">
site.webmanifest
</button>
`;
urlList.appendChild(toggleContainer);
// Helper to create row
const createManifestRow = (filename, label) => {
const row = document.createElement("div");
row.id = `row-${filename}`;
row.className = "flex items-center gap-3 mb-3";
fileURLMap[filename] = `/${filename}`;
row.innerHTML = `
<div class="w-8 h-8 bg-slate-800 rounded flex items-center justify-center shrink-0 border border-slate-700 text-slate-400 font-mono text-xs">{}</div>
<div class="flex-1 space-y-1">
<div class="flex justify-between items-center">
<label class="text-[10px] text-slate-400 uppercase font-bold">${label}</label>
<span class="text-[10px] text-slate-600 font-mono">${filename}</span>
</div>
<input type="text"
id="input-${filename}"
data-file="${filename}"
value="/${filename}"
oninput="updateUrl('${filename}', this.value)"
class="w-full bg-slate-900 border border-slate-800 rounded px-2 py-1.5 text-xs text-brand font-mono focus:border-brand/50 focus:outline-none transition-all"
>
</div>
`;
urlList.appendChild(row);
};
createManifestRow("manifest.json", "JSON Path");
createManifestRow("site.webmanifest", "Web Manifest Path");
// Trigger initial state visual update
updateManifestVisuals(activeManifest);
}
function setActiveManifest(val) {
activeManifest = val;
updateManifestVisuals(val);
updateCode();
}
function updateManifestVisuals(activeVal) {
// Update Toggle Buttons
const btnWeb = document.getElementById("btn-webmanifest");
const btnJson = document.getElementById("btn-json");
if (activeVal === "site.webmanifest") {
btnWeb.className =
"flex-1 py-1.5 text-xs font-medium rounded-md bg-brand text-slate-950 shadow-sm transition-all";
btnJson.className =
"flex-1 py-1.5 text-xs font-medium rounded-md text-slate-400 hover:text-slate-200 transition-all";
} else {
btnJson.className =
"flex-1 py-1.5 text-xs font-medium rounded-md bg-brand text-slate-950 shadow-sm transition-all";
btnWeb.className =
"flex-1 py-1.5 text-xs font-medium rounded-md text-slate-400 hover:text-slate-200 transition-all";
}
// Show only active input
const fileNames = ["site.webmanifest", "manifest.json"];
fileNames.forEach((name) => {
const row = document.getElementById(`row-${name}`);
if (name === activeVal) {
row.classList.remove("hidden");
} else {
row.classList.add("hidden");
}
});
}
// SWAP ASSET LOGIC
function swapAsset(assetName, input) {
const file = input.files[0];
if (!file) return;
const url = URL.createObjectURL(file);
const img = new Image();
img.onload = async () => {
const asset = assetsConfig.find((a) => a.name === assetName);
// Validate dimensions
if (img.width < asset.size || img.height < asset.size) {
alert(
`Error: The uploaded image (${img.width}x${img.height}) is smaller than the required size (${asset.size}x${asset.size}). Please upload a larger image.`,
);
URL.revokeObjectURL(url);
input.value = ""; // Reset input
return;
}
let blob;
// Check for animated format (GIF/WebP) to preserve animation
if (file.type === "image/gif" || file.type === "image/webp") {
// Use the raw file blob to preserve animation
blob = file;
} else {
// For static images (PNG, JPG, SVG), resize via canvas
if (asset.type === "ico") {
blob = await generateIcoBlob(img, asset.size);
} else {
blob = await generatePngBlob(img, asset.size);
}
}
generatedBlobs[asset.name] = blob;
// Update Preview Image
const imgEl = document.getElementById(`preview-img-${asset.name}`);
if (imgEl) imgEl.src = URL.createObjectURL(blob);
URL.revokeObjectURL(url);
};
img.src = url;
}
// GRAPHICS GENERATION
function generatePngBlob(img, size) {
return new Promise((resolve) => {
const canvas = document.createElement("canvas");
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, size, size); // Clear just in case
ctx.drawImage(img, 0, 0, size, size);
canvas.toBlob(resolve, "image/png");
});
}
async function generateIcoBlob(img, size) {
const canvas = document.createElement("canvas");
canvas.width = size;