-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor-scheme-editor.html
More file actions
844 lines (734 loc) · 30.6 KB
/
Copy pathcolor-scheme-editor.html
File metadata and controls
844 lines (734 loc) · 30.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PPR Color Scheme Editor</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #1a1a1a;
color: #ffffff;
padding: 20px;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
h1 {
text-align: center;
margin-bottom: 30px;
color: #ffffff;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-bottom: 30px;
}
.color-card {
background: #2a2a2a;
border-radius: 12px;
padding: 20px;
border: 2px solid #3a3a3a;
transition: all 0.2s ease;
}
.color-card:hover {
border-color: #4a4a4a;
transform: translateY(-2px);
}
.color-swatch {
width: 100%;
height: 80px;
border-radius: 8px;
margin-bottom: 15px;
border: 2px solid #3a3a3a;
cursor: pointer;
transition: all 0.2s ease;
}
.color-swatch:hover {
transform: scale(1.02);
}
.color-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.color-label {
font-weight: 600;
font-size: 14px;
color: #ffffff;
}
.color-value {
font-family: 'Monaco', 'Consolas', monospace;
font-size: 12px;
color: #aaaaaa;
background: #1a1a1a;
padding: 4px 8px;
border-radius: 4px;
}
.color-description {
font-size: 12px;
color: #888888;
line-height: 1.4;
}
.color-input {
width: 100%;
height: 40px;
border: none;
border-radius: 6px;
cursor: pointer;
margin-top: 10px;
}
.controls {
display: flex;
gap: 15px;
justify-content: center;
flex-wrap: wrap;
margin-bottom: 30px;
}
button {
background: #0066cc;
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: all 0.2s ease;
}
button:hover {
background: #0052a3;
transform: translateY(-1px);
}
button.secondary {
background: #4a4a4a;
}
button.secondary:hover {
background: #5a5a5a;
}
.export-section {
background: #2a2a2a;
border-radius: 12px;
padding: 20px;
border: 2px solid #3a3a3a;
}
.export-section h3 {
margin-bottom: 15px;
color: #ffffff;
}
textarea {
width: 100%;
height: 200px;
background: #1a1a1a;
color: #ffffff;
border: 1px solid #3a3a3a;
border-radius: 6px;
padding: 15px;
font-family: 'Monaco', 'Consolas', monospace;
font-size: 12px;
resize: vertical;
}
.instructions {
background: #2a2a2a;
border-radius: 12px;
padding: 20px;
margin-bottom: 30px;
border: 2px solid #3a3a3a;
}
.instructions h3 {
margin-bottom: 15px;
color: #ffffff;
}
.instructions ol {
margin-left: 20px;
color: #cccccc;
}
.instructions li {
margin-bottom: 8px;
line-height: 1.5;
}
.instructions code {
background: #1a1a1a;
padding: 2px 6px;
border-radius: 4px;
font-family: 'Monaco', 'Consolas', monospace;
color: #88cc88;
}
.preset-buttons {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-bottom: 20px;
}
.preset-buttons button {
padding: 8px 16px;
font-size: 12px;
}
.mode-toggle {
text-align: center;
margin-bottom: 20px;
}
.mode-toggle button {
margin: 0 5px;
}
.mode-toggle button.active {
background: #0088ff;
}
.base24-section {
border-top: 2px solid #3a3a3a;
margin-top: 20px;
padding-top: 20px;
}
.base24-section h3 {
text-align: center;
margin-bottom: 15px;
color: #ffffff;
}
.image-picker-section {
background: #2a2a2a;
border-radius: 12px;
padding: 20px;
margin-bottom: 30px;
border: 2px solid #3a3a3a;
}
.image-picker-section h3 {
margin-bottom: 15px;
color: #ffffff;
text-align: center;
}
.image-upload {
display: flex;
flex-direction: column;
align-items: center;
gap: 15px;
margin-bottom: 20px;
}
.image-upload input[type="file"] {
background: #1a1a1a;
color: #ffffff;
border: 1px solid #3a3a3a;
border-radius: 6px;
padding: 10px;
}
.image-canvas-container {
position: relative;
max-width: 100%;
margin: 0 auto;
border: 2px solid #3a3a3a;
border-radius: 8px;
overflow: hidden;
}
.image-canvas {
display: block;
max-width: 100%;
height: auto;
}
.color-picker {
position: absolute;
width: 20px;
height: 20px;
border: 3px solid #ffffff;
border-radius: 50%;
cursor: move;
box-shadow: 0 0 0 2px rgba(0,0,0,0.5);
z-index: 10;
}
.color-picker:hover {
transform: scale(1.2);
z-index: 20;
}
.color-picker.dragging {
z-index: 30;
transform: scale(1.3);
}
.picker-controls {
display: flex;
gap: 10px;
justify-content: center;
flex-wrap: wrap;
margin-top: 15px;
}
.image-instructions {
font-size: 12px;
color: #888888;
text-align: center;
margin-top: 10px;
line-height: 1.4;
}
</style>
</head>
<body>
<div class="container">
<h1>PPR Color Scheme Editor</h1>
<div class="instructions">
<h3>How to Use</h3>
<ol>
<li>Choose Base16 (16 colors) or Base24 (24 colors) mode</li>
<li>Click on any color swatch to change it</li>
<li>Try preset color schemes or create your own</li>
<li>Click "Generate Theme YAML" to create the theme file</li>
<li>Copy the YAML and save it as <code>your-theme.yaml</code> in <code>~/.config/themes/base16/</code> or <code>~/.config/themes/base24/</code></li>
<li>Use your theme: <code>ppr generate -t your-theme -s shapes --set-wallpaper</code></li>
</ol>
</div>
<div class="mode-toggle">
<button id="base16Btn" class="active" onclick="setMode('base16')">Base16 (16 colors)</button>
<button id="base24Btn" onclick="setMode('base24')">Base24 (24 colors)</button>
</div>
<div class="preset-buttons">
<button onclick="loadPreset('nord')">Nord</button>
<button onclick="loadPreset('gruvbox')">Gruvbox Dark</button>
<button onclick="loadPreset('catppuccin')">Catppuccin Mocha</button>
<button onclick="loadPreset('dracula')">Dracula</button>
<button onclick="loadPreset('tokyo-night')">Tokyo Night</button>
<button onclick="randomizeColors()">🎲 Random Colors</button>
</div>
<div class="image-picker-section">
<h3>🖼️ Extract Colors from Image</h3>
<div class="image-upload">
<input type="file" id="imageUpload" accept="image/*" onchange="loadImage(this)">
<div class="image-instructions">
Upload an image and drag the color pickers to sample colors from different areas
</div>
</div>
<div id="imageCanvasContainer" class="image-canvas-container" style="display: none;">
<canvas id="imageCanvas" class="image-canvas"></canvas>
</div>
<div class="picker-controls" id="pickerControls" style="display: none;">
<button onclick="resetPickerPositions()">Reset Positions</button>
<button onclick="applyPickedColors()">Apply Colors to Scheme</button>
<button onclick="clearImage()">Clear Image</button>
</div>
</div>
<div class="grid" id="colorGrid"></div>
<div id="base24Section" class="base24-section" style="display: none;">
<h3>Base24 Extended Colors</h3>
<div class="grid" id="base24Grid"></div>
</div>
<div class="controls">
<button onclick="generateTheme()">Generate Theme YAML</button>
<button onclick="generateSVG()" class="secondary">Generate SVG File</button>
<button onclick="copyColors()" class="secondary">Copy All Hex Colors</button>
</div>
<div class="export-section">
<h3>Generated Theme</h3>
<textarea id="output" placeholder="Click 'Generate Theme YAML' to create your theme file..."></textarea>
</div>
</div>
<script>
let currentMode = 'base16';
const colorScheme = {
base00: '#2E3440', base01: '#3B4252', base02: '#434C5E', base03: '#4C566A',
base04: '#D8DEE9', base05: '#E5E9F0', base06: '#ECEFF4', base07: '#8FBCBB',
base08: '#BF616A', base09: '#D08770', base0A: '#EBCB8B', base0B: '#A3BE8C',
base0C: '#88C0D0', base0D: '#81A1C1', base0E: '#B48EAD', base0F: '#5E81AC',
// Base24 extended colors
base10: '#BF616A', base11: '#D08770', base12: '#EBCB8B', base13: '#A3BE8C',
base14: '#88C0D0', base15: '#81A1C1', base16: '#B48EAD', base17: '#5E81AC'
};
const colorDescriptions = {
base00: 'Default Background',
base01: 'Lighter Background',
base02: 'Selection Background',
base03: 'Comments, Invisibles',
base04: 'Dark Foreground',
base05: 'Default Foreground',
base06: 'Light Foreground',
base07: 'Light Background',
base08: 'Red',
base09: 'Orange',
base0A: 'Yellow',
base0B: 'Green',
base0C: 'Cyan',
base0D: 'Blue',
base0E: 'Purple',
base0F: 'Brown',
// Base24 extended descriptions
base10: 'Alt Red',
base11: 'Alt Orange',
base12: 'Alt Yellow',
base13: 'Alt Green',
base14: 'Alt Cyan',
base15: 'Alt Blue',
base16: 'Alt Purple',
base17: 'Alt Brown'
};
const presets = {
nord: {
base00: '#2E3440', base01: '#3B4252', base02: '#434C5E', base03: '#4C566A',
base04: '#D8DEE9', base05: '#E5E9F0', base06: '#ECEFF4', base07: '#8FBCBB',
base08: '#BF616A', base09: '#D08770', base0A: '#EBCB8B', base0B: '#A3BE8C',
base0C: '#88C0D0', base0D: '#81A1C1', base0E: '#B48EAD', base0F: '#5E81AC',
base10: '#B48EAD', base11: '#D08770', base12: '#EBCB8B', base13: '#A3BE8C',
base14: '#88C0D0', base15: '#81A1C1', base16: '#5E81AC', base17: '#BF616A'
},
gruvbox: {
base00: '#282828', base01: '#3c3836', base02: '#504945', base03: '#665c54',
base04: '#bdae93', base05: '#d5c4a1', base06: '#ebdbb2', base07: '#fbf1c7',
base08: '#fb4934', base09: '#fe8019', base0A: '#fabd2f', base0B: '#b8bb26',
base0C: '#8ec07c', base0D: '#83a598', base0E: '#d3869b', base0F: '#d65d0e',
base10: '#cc241d', base11: '#d65d0e', base12: '#d79921', base13: '#98971a',
base14: '#689d6a', base15: '#458588', base16: '#b16286', base17: '#a89984'
},
catppuccin: {
base00: '#1e1e2e', base01: '#181825', base02: '#313244', base03: '#45475a',
base04: '#585b70', base05: '#cdd6f4', base06: '#f5e0dc', base07: '#b4befe',
base08: '#f38ba8', base09: '#fab387', base0A: '#f9e2af', base0B: '#a6e3a1',
base0C: '#94e2d5', base0D: '#89b4fa', base0E: '#cba6f7', base0F: '#f2cdcd',
base10: '#eba0ac', base11: '#f9e2af', base12: '#f38ba8', base13: '#a6e3a1',
base14: '#89b4fa', base15: '#74c7ec', base16: '#cba6f7', base17: '#f2cdcd'
},
dracula: {
base00: '#282a36', base01: '#44475a', base02: '#44475a', base03: '#6272a4',
base04: '#6272a4', base05: '#f8f8f2', base06: '#f8f8f2', base07: '#f8f8f2',
base08: '#ff5555', base09: '#ffb86c', base0A: '#f1fa8c', base0B: '#50fa7b',
base0C: '#8be9fd', base0D: '#bd93f9', base0E: '#ff79c6', base0F: '#bd93f9',
base10: '#ff6e6e', base11: '#ff79c6', base12: '#f1fa8c', base13: '#50fa7b',
base14: '#8be9fd', base15: '#6272a4', base16: '#bd93f9', base17: '#ffb86c'
},
'tokyo-night': {
base00: '#1a1b26', base01: '#16161e', base02: '#2f3549', base03: '#444b6a',
base04: '#787c99', base05: '#a9b1d6', base06: '#cbccd1', base07: '#d5d6db',
base08: '#f7768e', base09: '#ff9e64', base0A: '#e0af68', base0B: '#9ece6a',
base0C: '#73daca', base0D: '#7aa2f7', base0E: '#bb9af7', base0F: '#f7768e',
base10: '#db4b4b', base11: '#ff9e64', base12: '#c0ca33', base13: '#9ece6a',
base14: '#2ac3de', base15: '#7aa2f7', base16: '#ad8ee6', base17: '#449dab'
}
};
function createColorCard(baseKey, color) {
return `
<div class="color-card">
<div class="color-swatch" style="background-color: ${color}" onclick="changeColor('${baseKey}')"></div>
<div class="color-info">
<span class="color-label">${baseKey}</span>
<span class="color-value">${color}</span>
</div>
<div class="color-description">${colorDescriptions[baseKey]}</div>
<input type="color" class="color-input" value="${color}" onchange="updateColor('${baseKey}', this.value)">
</div>
`;
}
function renderColorGrid() {
const grid = document.getElementById('colorGrid');
const base24Grid = document.getElementById('base24Grid');
if (currentMode === 'base16') {
// Show only base00-base0F
const base16Colors = Object.entries(colorScheme)
.filter(([key]) => key.match(/^base0[0-9A-F]$/))
.map(([key, color]) => createColorCard(key, color))
.join('');
grid.innerHTML = base16Colors;
document.getElementById('base24Section').style.display = 'none';
} else {
// Show base00-base0F in main grid
const base16Colors = Object.entries(colorScheme)
.filter(([key]) => key.match(/^base0[0-9A-F]$/))
.map(([key, color]) => createColorCard(key, color))
.join('');
grid.innerHTML = base16Colors;
// Show base10-base17 in extended grid
const base24Colors = Object.entries(colorScheme)
.filter(([key]) => key.match(/^base1[0-7]$/))
.map(([key, color]) => createColorCard(key, color))
.join('');
base24Grid.innerHTML = base24Colors;
document.getElementById('base24Section').style.display = 'block';
}
}
function setMode(mode) {
currentMode = mode;
document.getElementById('base16Btn').classList.toggle('active', mode === 'base16');
document.getElementById('base24Btn').classList.toggle('active', mode === 'base24');
renderColorGrid();
}
function changeColor(baseKey) {
const input = document.querySelector(`input[onchange="updateColor('${baseKey}', this.value)"]`);
input.click();
}
function updateColor(baseKey, newColor) {
colorScheme[baseKey] = newColor.toUpperCase();
renderColorGrid();
}
function loadPreset(presetName) {
Object.assign(colorScheme, presets[presetName]);
renderColorGrid();
}
function randomizeColors() {
const keysToRandomize = currentMode === 'base16'
? Object.keys(colorScheme).filter(key => key.match(/^base0[0-9A-F]$/))
: Object.keys(colorScheme);
keysToRandomize.forEach(key => {
colorScheme[key] = '#' + Math.floor(Math.random()*16777215).toString(16).padStart(6, '0').toUpperCase();
});
renderColorGrid();
}
function generateTheme() {
const themeName = prompt('Enter theme name:', 'my-custom-theme') || 'my-custom-theme';
const system = currentMode;
const themeDir = system;
let yaml = `system: "${system}"
name: "${themeName}"
author: "custom"
variant: "dark"
palette:
base00: "${colorScheme.base00}"
base01: "${colorScheme.base01}"
base02: "${colorScheme.base02}"
base03: "${colorScheme.base03}"
base04: "${colorScheme.base04}"
base05: "${colorScheme.base05}"
base06: "${colorScheme.base06}"
base07: "${colorScheme.base07}"
base08: "${colorScheme.base08}"
base09: "${colorScheme.base09}"
base0A: "${colorScheme.base0A}"
base0B: "${colorScheme.base0B}"
base0C: "${colorScheme.base0C}"
base0D: "${colorScheme.base0D}"
base0E: "${colorScheme.base0E}"
base0F: "${colorScheme.base0F}"`;
if (currentMode === 'base24') {
yaml += `
base10: "${colorScheme.base10}"
base11: "${colorScheme.base11}"
base12: "${colorScheme.base12}"
base13: "${colorScheme.base13}"
base14: "${colorScheme.base14}"
base15: "${colorScheme.base15}"
base16: "${colorScheme.base16}"
base17: "${colorScheme.base17}"`;
}
document.getElementById('output').value = yaml;
// Auto-copy to clipboard
navigator.clipboard.writeText(yaml).then(() => {
alert(`${system.toUpperCase()} theme YAML copied to clipboard! Save it as ${themeName}.yaml in ~/.config/themes/${themeDir}/`);
}).catch(() => {
alert(`Theme generated! Copy the YAML and save it as ${themeName}.yaml in ~/.config/themes/${themeDir}/`);
});
}
function generateSVG() {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="800" height="520" viewBox="0 0 800 520">
<!-- Background -->
<rect width="800" height="520" fill="${colorScheme.base00}"/>
<!-- 16 color swatches in 4x4 grid - ordered as base00 through base0F -->
<!-- Row 1: base00-base03 -->
<rect x="20" y="20" width="180" height="120" rx="8" fill="${colorScheme.base00}"/>
<rect x="220" y="20" width="180" height="120" rx="8" fill="${colorScheme.base01}"/>
<rect x="420" y="20" width="180" height="120" rx="8" fill="${colorScheme.base02}"/>
<rect x="620" y="20" width="160" height="120" rx="8" fill="${colorScheme.base03}"/>
<!-- Row 2: base04-base07 -->
<rect x="20" y="160" width="180" height="120" rx="8" fill="${colorScheme.base04}"/>
<rect x="220" y="160" width="180" height="120" rx="8" fill="${colorScheme.base05}"/>
<rect x="420" y="160" width="180" height="120" rx="8" fill="${colorScheme.base06}"/>
<rect x="620" y="160" width="160" height="120" rx="8" fill="${colorScheme.base07}"/>
<!-- Row 3: base08-base0B -->
<rect x="20" y="300" width="180" height="120" rx="8" fill="${colorScheme.base08}"/>
<rect x="220" y="300" width="180" height="120" rx="8" fill="${colorScheme.base09}"/>
<rect x="420" y="300" width="180" height="120" rx="8" fill="${colorScheme.base0A}"/>
<rect x="620" y="300" width="160" height="120" rx="8" fill="${colorScheme.base0B}"/>
<!-- Row 4: base0C-base0F -->
<rect x="20" y="440" width="180" height="60" rx="8" fill="${colorScheme.base0C}"/>
<rect x="220" y="440" width="180" height="60" rx="8" fill="${colorScheme.base0D}"/>
<rect x="420" y="440" width="180" height="60" rx="8" fill="${colorScheme.base0E}"/>
<rect x="620" y="440" width="160" height="60" rx="8" fill="${colorScheme.base0F}"/>
</svg>`;
document.getElementById('output').value = svg;
alert('SVG generated! You can save this as an .svg file and use with ppr extract-colors.');
}
function copyColors() {
const relevantColors = currentMode === 'base16'
? Object.entries(colorScheme).filter(([key]) => key.match(/^base0[0-9A-F]$/)).map(([,color]) => color)
: Object.values(colorScheme);
const colors = relevantColors.join(', ');
navigator.clipboard.writeText(colors).then(() => {
alert(`All ${currentMode.toUpperCase()} hex colors copied to clipboard!`);
}).catch(() => {
document.getElementById('output').value = colors;
alert('Colors displayed in output area. Copy them manually.');
});
}
// Image picker variables
let canvas, ctx, imageData;
let colorPickers = [];
let isDragging = false;
let draggedPicker = null;
// Default positions for color pickers (percentage of image dimensions)
const defaultPickerPositions = [
// Base16 positions distributed across common color areas
{x: 0.1, y: 0.1}, // base00 - top-left (dark)
{x: 0.2, y: 0.15}, // base01 - dark area
{x: 0.3, y: 0.2}, // base02 - mid-dark
{x: 0.4, y: 0.25}, // base03 - comment area
{x: 0.6, y: 0.3}, // base04 - mid-light
{x: 0.7, y: 0.35}, // base05 - foreground
{x: 0.8, y: 0.4}, // base06 - light
{x: 0.9, y: 0.45}, // base07 - lightest
{x: 0.15, y: 0.6}, // base08 - red accent
{x: 0.25, y: 0.65}, // base09 - orange accent
{x: 0.35, y: 0.7}, // base0A - yellow accent
{x: 0.45, y: 0.75}, // base0B - green accent
{x: 0.55, y: 0.8}, // base0C - cyan accent
{x: 0.65, y: 0.85}, // base0D - blue accent
{x: 0.75, y: 0.9}, // base0E - purple accent
{x: 0.85, y: 0.95}, // base0F - brown accent
// Base24 extended positions
{x: 0.12, y: 0.55}, // base10 - alt red
{x: 0.22, y: 0.6}, // base11 - alt orange
{x: 0.32, y: 0.65}, // base12 - alt yellow
{x: 0.42, y: 0.7}, // base13 - alt green
{x: 0.52, y: 0.75}, // base14 - alt cyan
{x: 0.62, y: 0.8}, // base15 - alt blue
{x: 0.72, y: 0.85}, // base16 - alt purple
{x: 0.82, y: 0.9} // base17 - alt brown
];
function loadImage(input) {
const file = input.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.onload = function() {
setupCanvas(img);
createColorPickers();
document.getElementById('imageCanvasContainer').style.display = 'block';
document.getElementById('pickerControls').style.display = 'flex';
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
function setupCanvas(img) {
canvas = document.getElementById('imageCanvas');
ctx = canvas.getContext('2d');
// Calculate canvas size while maintaining aspect ratio
const maxWidth = 800;
const maxHeight = 600;
let width = img.width;
let height = img.height;
if (width > maxWidth) {
height = (height * maxWidth) / width;
width = maxWidth;
}
if (height > maxHeight) {
width = (width * maxHeight) / height;
height = maxHeight;
}
canvas.width = width;
canvas.height = height;
ctx.drawImage(img, 0, 0, width, height);
// Get image data for color sampling
imageData = ctx.getImageData(0, 0, width, height);
}
function createColorPickers() {
// Clear existing pickers
colorPickers.forEach(picker => picker.element.remove());
colorPickers = [];
const container = document.getElementById('imageCanvasContainer');
const baseKeys = currentMode === 'base16'
? Object.keys(colorScheme).filter(key => key.match(/^base0[0-9A-F]$/))
: Object.keys(colorScheme);
baseKeys.forEach((baseKey, index) => {
const picker = document.createElement('div');
picker.className = 'color-picker';
picker.style.backgroundColor = colorScheme[baseKey];
picker.title = `${baseKey} - ${colorDescriptions[baseKey]}`;
// Position picker
const pos = defaultPickerPositions[index];
const rect = canvas.getBoundingClientRect();
picker.style.left = (pos.x * canvas.width - 10) + 'px';
picker.style.top = (pos.y * canvas.height - 10) + 'px';
// Add drag functionality
picker.addEventListener('mousedown', startDrag);
container.appendChild(picker);
colorPickers.push({
element: picker,
baseKey: baseKey,
x: pos.x * canvas.width,
y: pos.y * canvas.height
});
});
// Add mouse event listeners to container
container.addEventListener('mousemove', drag);
container.addEventListener('mouseup', endDrag);
container.addEventListener('mouseleave', endDrag);
}
function startDrag(e) {
isDragging = true;
draggedPicker = colorPickers.find(p => p.element === e.target);
if (draggedPicker) {
draggedPicker.element.classList.add('dragging');
}
e.preventDefault();
}
function drag(e) {
if (!isDragging || !draggedPicker) return;
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Keep picker within canvas bounds
const clampedX = Math.max(0, Math.min(canvas.width, x));
const clampedY = Math.max(0, Math.min(canvas.height, y));
draggedPicker.x = clampedX;
draggedPicker.y = clampedY;
draggedPicker.element.style.left = (clampedX - 10) + 'px';
draggedPicker.element.style.top = (clampedY - 10) + 'px';
// Sample color at new position
const color = getColorAtPosition(clampedX, clampedY);
draggedPicker.element.style.backgroundColor = color;
}
function endDrag() {
if (draggedPicker) {
draggedPicker.element.classList.remove('dragging');
draggedPicker = null;
}
isDragging = false;
}
function getColorAtPosition(x, y) {
const pixelX = Math.floor(x);
const pixelY = Math.floor(y);
const index = (pixelY * canvas.width + pixelX) * 4;
const r = imageData.data[index];
const g = imageData.data[index + 1];
const b = imageData.data[index + 2];
return '#' + [r, g, b].map(x => x.toString(16).padStart(2, '0')).join('').toUpperCase();
}
function applyPickedColors() {
colorPickers.forEach(picker => {
const color = getColorAtPosition(picker.x, picker.y);
colorScheme[picker.baseKey] = color;
});
renderColorGrid();
alert('Colors applied to scheme! Check the color grid below.');
}
function resetPickerPositions() {
colorPickers.forEach((picker, index) => {
const pos = defaultPickerPositions[index];
picker.x = pos.x * canvas.width;
picker.y = pos.y * canvas.height;
picker.element.style.left = (picker.x - 10) + 'px';
picker.element.style.top = (picker.y - 10) + 'px';
const color = getColorAtPosition(picker.x, picker.y);
picker.element.style.backgroundColor = color;
});
}
function clearImage() {
document.getElementById('imageCanvasContainer').style.display = 'none';
document.getElementById('pickerControls').style.display = 'none';
document.getElementById('imageUpload').value = '';
colorPickers.forEach(picker => picker.element.remove());
colorPickers = [];
}
// Initialize the app
renderColorGrid();
</script>
</body>
</html>