-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrickmuster.html
More file actions
2448 lines (2182 loc) · 104 KB
/
Copy pathstrickmuster.html
File metadata and controls
2448 lines (2182 loc) · 104 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
<!--
Julia's Strickmuster Editor
Copyright (C) 2026 heino17
https://github.com/heino17/Knitting-Pattern-Editor
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="copyright" content="2026 - heino17" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title data-i18n="meta_title">Julia's Strickmuster Editor</title>
<link rel="stylesheet" href="strickmuster.css">
<script src="lang.js"></script>
</head>
<body>
<header class="app-header" id="appHeader">
<button type="button" id="headerToggle" class="header-toggle" data-i18n-aria-label="header_toggle_collapse" aria-expanded="true" aria-label="Kopfbereich einklappen">
<svg viewBox="0 0 24 24" class="chevron-icon chevron-icon--down" aria-hidden="true"><path d="M5 9l7 7 7-7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<button type="button" id="addNoteBtn" class="header-note-btn" title="Neue Notiz erstellen" data-i18n-title="note_add_title" aria-label="Neue Notiz erstellen" data-i18n-aria-label="note_add_title">
<span aria-hidden="true">📝</span>
</button>
<div class="header-bg-menu-wrap">
<button type="button" id="bgImageBtn" class="header-note-btn header-bg-btn" title="Hintergrundbild" data-i18n-title="bgimage_btn_title" aria-label="Hintergrundbild" data-i18n-aria-label="bgimage_btn_title" aria-haspopup="true" aria-expanded="false">
<span aria-hidden="true">🖼️</span>
</button>
<div class="header-bg-menu" id="bgImageMenu" hidden>
<label class="header-bg-menu__item">
<span data-i18n="bgimage_choose">Bild wählen …</span>
<input type="file" id="bgImageInput" accept="image/*" hidden>
</label>
<button type="button" id="bgImageToggleBtn" class="header-bg-menu__item header-bg-menu__item--btn" disabled data-i18n="bgimage_hide">Bild ausblenden</button>
<button type="button" id="bgImageRemoveBtn" class="header-bg-menu__item header-bg-menu__item--btn" data-i18n="bgimage_remove">Bild entfernen</button>
</div>
</div>
<div class="header-undo-redo" id="headerSaveLoad" role="group" aria-label="Muster speichern / laden" data-i18n-aria-label="header_saveload_aria">
<button type="button" id="headerSaveBtn" class="header-undo-redo__btn" title="Muster speichern" data-i18n-title="export_json_btn" aria-label="Muster speichern" data-i18n-aria-label="export_json_btn">
<span aria-hidden="true">💾</span>
</button>
<label class="header-undo-redo__btn header-undo-redo__btn--file" id="headerLoadBtn" title="Muster laden" data-i18n-title="import_json_btn" aria-label="Muster laden" data-i18n-aria-label="import_json_btn">
<span aria-hidden="true">📂</span>
<input type="file" id="headerLoadInput" accept="application/json" hidden>
</label>
</div>
<div class="page-zoom" id="pageZoom" role="group" aria-label="Seiten-Zoom" data-i18n-aria-label="page_zoom_aria">
<button type="button" id="pageZoomOutBtn" class="page-zoom__btn" title="Verkleinern" data-i18n-title="page_zoom_out_title" aria-label="Seite verkleinern" data-i18n-aria-label="page_zoom_out_title">−</button>
<button type="button" id="pageZoomInBtn" class="page-zoom__btn" title="Vergrößern" data-i18n-title="page_zoom_in_title" aria-label="Seite vergrößern" data-i18n-aria-label="page_zoom_in_title">+</button>
</div>
<label class="lang-select-wrap">
<span class="sr-only" data-i18n="lang_select_aria">Sprache wählen</span>
<select id="langSelect" class="lang-select" data-i18n-aria-label="lang_select_aria" aria-label="Sprache wählen">
<option value="de">🇩🇪 Deutsch</option>
<option value="en">🇺🇸 American</option>
<option value="ru">🇷🇺 Русский</option>
<option value="es">🇪🇸 Español</option>
<option value="fr">🇫🇷 Français</option>
<option value="ja">🇯🇵 日本語</option>
<option value="ko">🇰🇷 한국어</option>
<option value="zh_CN">🇨🇳 中文(简体)</option>
</select>
</label>
<div class="app-header__title">
<span class="app-header__eyebrow" data-i18n="eyebrow">Maschenraster</span>
<h1 id="appTitle" data-i18n="app_title">Julia's Strickmuster Editor</h1>
</div>
<p class="app-header__hint" data-i18n="header_hint">Raster aufziehen, Maschen einfärben, Muster als Bild oder Datei sichern</p>
<div class="header-palette" id="headerPalette" aria-label="Farbtabelle" data-i18n-aria-label="palette_grid_aria"></div>
<div class="header-tools-row" id="headerToolsRow" role="group" aria-label="Werkzeuge" data-i18n-aria-label="header_tools_row_aria">
<div class="header-tools-row__inner">
<button type="button" class="header-tools-row__btn tool-btn is-active" id="headerToolPaint" data-tool="paint" title="Stift (freihand malen)" data-i18n-title="tool_paint_title" aria-label="Stift" data-i18n-aria-label="tool_paint_label">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 20l1-4.5L15.5 5 19 8.5 8.5 19 4 20z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
</button>
<button type="button" class="header-tools-row__btn tool-btn" id="headerToolArea" data-tool="area" title="Bereich auswählen und füllen" data-i18n-title="tool_area_title" aria-label="Bereich" data-i18n-aria-label="tool_area_label">
<svg viewBox="0 0 24 24" aria-hidden="true"><rect x="4" y="4" width="16" height="16" rx="1.5" fill="none" stroke="currentColor" stroke-width="1.6" stroke-dasharray="3 2.5"/></svg>
</button>
<button type="button" class="header-tools-row__btn tool-btn" id="headerToolPipette" data-tool="pipette" title="Pipette (Farbe aus dem Muster aufnehmen)" data-i18n-title="tool_pipette_title" aria-label="Pipette" data-i18n-aria-label="tool_pipette_label">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M14.5 3.5l6 6-3 3-1.5-1.5L9 18l-4 1 1-4 7-7L11.5 6.5l3-3z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round"/></svg>
</button>
<button type="button" class="header-tools-row__btn" id="headerEraserBtn" data-active="false" title="Radiergummi" data-i18n-title="eraser_btn" aria-label="Radiergummi" data-i18n-aria-label="eraser_btn">
<span class="eraser-icon" aria-hidden="true"></span>
</button>
<button type="button" class="header-tools-row__btn" id="headerToolsUndoBtn" disabled title="Strg+Z" data-i18n-title="undo_title" aria-label="Rückgängig" data-i18n-aria-label="undo_btn">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 7L4 12l5 5M4 12h11a5 5 0 010 10h-1" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<button type="button" class="header-tools-row__btn" id="headerToolsRedoBtn" disabled title="Strg+Y" data-i18n-title="redo_title" aria-label="Wiederherstellen" data-i18n-aria-label="redo_btn">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M15 7l5 5-5 5M20 12H9a5 5 0 000 10h1" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
</div>
</div>
</header>
<main class="layout">
<aside class="panel" aria-label="Einstellungen" data-i18n-aria-label="sidebar_aria" id="panel">
<button type="button" id="sidebarToggle" class="sidebar-toggle" data-i18n-aria-label="sidebar_toggle_collapse" aria-expanded="true" aria-label="Seitenleiste einklappen">
<svg viewBox="0 0 24 24" class="chevron-icon" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<div class="panel__scroll" id="panelScroll">
<nav class="panel__icons" id="panelIcons" aria-label="Eingeklappte Seitenleiste" data-i18n-aria-label="panel_icons_aria">
<button type="button" class="icon-btn" data-target="group-werkzeuge" title="Werkzeuge" data-i18n-title="icon_werkzeuge_title" aria-label="Werkzeuge anzeigen" data-i18n-aria-label="icon_werkzeuge_aria">
<svg viewBox="0 0 24 24"><path d="M4 20l1-4.5L15.5 5 19 8.5 8.5 19 4 20z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
</button>
<button type="button" class="icon-btn" data-target="group-raster" title="Raster" data-i18n-title="icon_raster_title" aria-label="Raster-Einstellungen anzeigen" data-i18n-aria-label="icon_raster_aria">
<svg viewBox="0 0 24 24"><path d="M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
</button>
<button type="button" class="icon-btn" data-target="group-farbe" title="Farbe" data-i18n-title="icon_farbe_title" aria-label="Farb-Einstellungen anzeigen" data-i18n-aria-label="icon_farbe_aria">
<svg viewBox="0 0 24 24"><path d="M12 2C7 8 4 11.5 4 15a8 8 0 0016 0c0-3.5-3-7-8-13z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
</button>
<button type="button" class="icon-btn" data-target="group-farbtabelle" title="Farbtabelle" data-i18n-title="icon_farbtabelle_title" aria-label="Farbtabelle anzeigen" data-i18n-aria-label="icon_farbtabelle_aria">
<svg viewBox="0 0 24 24"><rect x="3" y="3" width="6" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.6"/><rect x="9.5" y="3" width="6" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.6"/><rect x="16" y="3" width="5" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.6"/><rect x="3" y="9.5" width="6" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.6"/><rect x="9.5" y="9.5" width="6" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.6"/><rect x="16" y="9.5" width="5" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.6"/></svg>
</button>
<button type="button" class="icon-btn" data-target="group-muster" title="Muster" data-i18n-title="icon_muster_title" aria-label="Muster-Aktionen anzeigen" data-i18n-aria-label="icon_muster_aria">
<svg viewBox="0 0 24 24"><path d="M5 4h11l3 3v13H5V4z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/><path d="M8 4v5h7V4" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
</button>
<button type="button" class="icon-btn" data-target="group-ansicht" title="Ansicht" data-i18n-title="icon_ansicht_title" aria-label="Ansicht-Einstellungen anzeigen" data-i18n-aria-label="icon_ansicht_aria">
<svg viewBox="0 0 24 24"><path d="M1 12s4-7 11-7 11 7 11 7-4 7-11 7-11-7-11-7z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/><circle cx="12" cy="12" r="2.8" fill="none" stroke="currentColor" stroke-width="1.6"/></svg>
</button>
</nav>
<div class="panel__body" id="panelBody">
<section class="panel__group panel__group--pinned panel__group--current-color" id="group-aktuelle-farbe">
<label class="field field--inline field--current-color">
<span data-i18n="current_color_label">Aktuelle Farbe</span>
<input type="color" id="colorPicker" value="#effcff">
</label>
<label class="field">
<span><span data-i18n="cellsize_label">Zellgröße</span> <output id="cellSizeOut">20</output> px</span>
<input type="range" id="cellSize" min="10" max="36" value="20">
</label>
</section>
<section class="panel__group panel__group--pinned" id="group-werkzeuge">
<h2 data-i18n="group_werkzeuge_h2">Werkzeuge</h2>
<div class="field-label" data-i18n="tool_label">Werkzeug</div>
<div class="tool-toggle" id="toolToggle" role="group" aria-label="Werkzeug wählen" data-i18n-aria-label="tooltoggle_aria">
<button type="button" class="tool-btn is-active" data-tool="paint" title="Stift (freihand malen)" data-i18n-title="tool_paint_title">
<svg viewBox="0 0 24 24"><path d="M4 20l1-4.5L15.5 5 19 8.5 8.5 19 4 20z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
<span data-i18n="tool_paint_label">Stift</span>
</button>
<button type="button" class="tool-btn" data-tool="area" title="Bereich auswählen und füllen" data-i18n-title="tool_area_title">
<svg viewBox="0 0 24 24"><rect x="4" y="4" width="16" height="16" rx="1.5" fill="none" stroke="currentColor" stroke-width="1.6" stroke-dasharray="3 2.5"/></svg>
<span data-i18n="tool_area_label">Bereich</span>
</button>
<button type="button" class="tool-btn" data-tool="pipette" title="Pipette (Farbe aus dem Muster aufnehmen)" data-i18n-title="tool_pipette_title">
<svg viewBox="0 0 24 24"><path d="M14.5 3.5l6 6-3 3-1.5-1.5L9 18l-4 1 1-4 7-7L11.5 6.5l3-3z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round"/></svg>
<span data-i18n="tool_pipette_label">Pipette</span>
</button>
</div>
<p class="panel__note" data-i18n="werkzeug_note">Im Bereich-Modus: Ecke anklicken, Rechteck aufziehen, loslassen zum Füllen. Mit der Pipette eine Zelle anklicken, um deren Farbe zu übernehmen.</p>
<button id="eraserBtn" class="btn btn--toggle" data-active="false">
<span class="eraser-icon" aria-hidden="true"></span> <span data-i18n="eraser_btn">Radiergummi</span>
</button>
<div class="btn-row">
<button id="undoBtn" class="btn btn--icon-text" disabled title="Strg+Z" data-i18n-title="undo_title" aria-label="Rückgängig" data-i18n-aria-label="undo_btn">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 7L4 12l5 5M4 12h11a5 5 0 010 10h-1" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<button id="redoBtn" class="btn btn--icon-text" disabled title="Strg+Y" data-i18n-title="redo_title" aria-label="Wiederherstellen" data-i18n-aria-label="redo_btn">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M15 7l5 5-5 5M20 12H9a5 5 0 000 10h1" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
</div>
</section>
<section class="panel__group" id="group-farbtabelle">
<h2>
<button type="button" class="panel__group-toggle" aria-expanded="true" aria-controls="group-farbtabelle-body">
<svg class="section-toggle-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span data-i18n="group_farbtabelle_h2">Farbtabelle</span>
</button>
</h2>
<div class="panel__group-body" id="group-farbtabelle-body">
<p class="panel__note" data-i18n="palette_intro_note">Feste, dauerhafte Farbsammlung (bis zu 49 Farben) - unabhängig von "Zuletzt verwendet". Wird mit in eine eigene Datei gespeichert.</p>
<div class="replace-row">
<label class="field field--inline replace-field">
<span data-i18n="palette_add_color_label">Neue Farbe</span>
<input type="color" id="paletteNewColor" value="#effcff">
</label>
<button type="button" id="palettePickBtn" class="btn btn--icon" title="Aus Raster aufnehmen" data-i18n-title="palette_pick_title" aria-label="Farbe aus Raster aufnehmen" data-i18n-aria-label="palette_pick_title">
<svg viewBox="0 0 24 24"><path d="M14.5 3.5l6 6-3 3-1.5-1.5L9 18l-4 1 1-4 7-7L11.5 6.5l3-3z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round"/></svg>
</button>
</div>
<button type="button" id="paletteAddBtn" class="btn" data-i18n="palette_add_btn">Zur Farbtabelle hinzufügen</button>
<div class="field-label" id="paletteCountLabel">Farbtabelle (0 / 49)</div>
<div class="palette-grid" id="paletteGrid" aria-label="Farbtabelle" data-i18n-aria-label="palette_grid_aria"></div>
<p class="panel__note" data-i18n="palette_usage_note">Klick auf eine Farbe aktiviert sie im Stift. Klick auf das "×" entfernt sie aus der Tabelle.</p>
<div class="btn-row">
<button type="button" id="paletteExportBtn" class="btn" data-i18n="palette_export_btn">Farbtabelle speichern</button>
<label class="btn btn--file">
<span data-i18n="palette_import_btn">Farbtabelle laden</span>
<input type="file" id="paletteImportInput" accept="application/json" hidden>
</label>
</div>
<button type="button" id="paletteClearBtn" class="btn" data-i18n="palette_clear_btn">Farbtabelle leeren</button>
</div>
</section>
<section class="panel__group" id="group-muster">
<h2>
<button type="button" class="panel__group-toggle" aria-expanded="false" aria-controls="group-muster-body">
<svg class="section-toggle-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span data-i18n="group_muster_h2">Muster</span>
</button>
</h2>
<div class="panel__group-body is-collapsed" id="group-muster-body">
<div class="btn-row">
<button id="clearBtn" class="btn" data-i18n="clear_btn">Alles leeren</button>
</div>
<div class="btn-row">
<label class="btn btn--file">
<span data-i18n="import_image_btn">Bild ins Raster laden</span>
<input type="file" id="importImageInput" accept="image/*" hidden>
</label>
</div>
<label class="field">
<span><span data-i18n="import_levels_label">Farbstufen je Kanal</span> <output id="importLevelsOut">Aus</output></span>
<input type="range" id="importLevels" min="0" max="8" value="0">
</label>
<p class="panel__note" data-i18n="import_levels_note">Reduziert die Farbtiefe auf wenige, klar unterscheidbare Farbstufen statt vieler feiner Zwischentöne - je weniger Stufen, desto gröber.</p>
<label class="field field--checkbox">
<input type="checkbox" id="importSnapPalette">
<span data-i18n="import_snap_palette_label">Auf meine Farbtabelle einrasten</span>
</label>
<p class="panel__note" data-i18n="import_snap_palette_note">Jede Masche bekommt die ähnlichste Farbe aus deiner gespeicherten Farbtabelle statt einer frei berechneten Farbe. Wird zusätzlich zu den Farbstufen angewendet.</p>
<p class="panel__note"><span data-i18n="import_note_before">Das Bild wird auf das aktuelle Raster (</span><span id="importSizeHint">50 × 50</span><span data-i18n="import_note_after">, Breite × Höhe) gestreckt und in Pixelfarben umgesetzt.</span></p>
<div class="btn-row">
<button id="exportJsonBtn" class="btn" data-i18n="export_json_btn">Muster speichern</button>
<label class="btn btn--file">
<span data-i18n="import_json_btn">Muster laden</span>
<input type="file" id="importJsonInput" accept="application/json" hidden>
</label>
</div>
<button id="exportPngBtn" class="btn btn--primary" data-i18n="export_png_btn">Als PNG exportieren</button>
</div>
</section>
<section class="panel__group" id="group-farbe">
<h2>
<button type="button" class="panel__group-toggle" aria-expanded="false" aria-controls="group-farbe-body">
<svg class="section-toggle-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span data-i18n="group_farbe_h2">Farbe</span>
</button>
</h2>
<div class="panel__group-body is-collapsed" id="group-farbe-body">
<label class="field field--inline replace-field">
<span data-i18n="cell_bg_label">Standard Zell-Hintergrund</span>
<input type="color" id="cellBgColor" value="#f7f5f0">
</label>
<p class="panel__note" data-i18n="cell_bg_note">Hintergrundfarbe für noch nicht bemalte Zellen. So bleibt bewusst „weiß“ gefärbtes Muster von leeren Zellen unterscheidbar. Wird dauerhaft gemerkt.</p>
<div class="field-label" data-i18n="replace_label">Farbe im Muster austauschen</div>
<div class="replace-row">
<label class="field field--inline replace-field">
<span data-i18n="replace_old_label">Alte Farbe</span>
<input type="color" id="replaceOldColor" value="#effcff">
</label>
<button type="button" id="pickOldColorBtn" class="btn btn--icon" title="Aus Raster aufnehmen" data-i18n-title="replace_pick_title" aria-label="Farbe aus Raster aufnehmen" data-i18n-aria-label="replace_pick_title">
<svg viewBox="0 0 24 24"><path d="M14.5 3.5l6 6-3 3-1.5-1.5L9 18l-4 1 1-4 7-7L11.5 6.5l3-3z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round"/></svg>
</button>
</div>
<label class="field field--inline replace-field">
<span data-i18n="replace_new_label">Neue Farbe</span>
<input type="color" id="replaceNewColor" value="#ffffff">
</label>
<label class="field field--checkbox">
<input type="checkbox" id="replaceWithEraser">
<span data-i18n="replace_eraser_label">Neue Farbe = Radiergummi (leer)</span>
</label>
<button id="replaceColorBtn" class="btn" data-i18n="replace_btn">Farbe austauschen</button>
<p class="panel__note" data-i18n="replace_note">Ersetzt im gesamten Raster jede Masche mit der „Alten Farbe“ durch die „Neue Farbe“ (oder leert sie, wenn „Radiergummi“ aktiviert ist).</p>
</div>
</section>
<section class="panel__group" id="group-raster">
<h2>
<button type="button" class="panel__group-toggle" aria-expanded="false" aria-controls="group-raster-body">
<svg class="section-toggle-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span data-i18n="group_raster_h2">Raster</span>
</button>
</h2>
<div class="panel__group-body is-collapsed" id="group-raster-body">
<label class="field">
<span data-i18n="rows_label">Reihen (Höhe)</span>
<input type="number" id="rows" min="50" max="200" value="50">
</label>
<label class="field">
<span data-i18n="cols_label">Maschen (Breite)</span>
<input type="number" id="cols" min="50" max="200" value="50">
</label>
<button id="buildBtn" class="btn btn--primary" data-i18n="build_btn">Raster erstellen</button>
<p class="panel__note" data-i18n="raster_note">Achtung: Ändert das Raster, werden bereits gesetzte Farben zurückgesetzt.</p>
</div>
</section>
<section class="panel__group" id="group-ansicht">
<h2>
<button type="button" class="panel__group-toggle" aria-expanded="false" aria-controls="group-ansicht-body">
<svg class="section-toggle-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span data-i18n="group_ansicht_h2">Ansicht</span>
</button>
</h2>
<div class="panel__group-body is-collapsed" id="group-ansicht-body">
<label class="field field--checkbox">
<input type="checkbox" id="showRgbValues" checked>
<span data-i18n="rgb_values_label">Farbwerte als RGB anzeigen</span>
</label>
<label class="field field--checkbox">
<input type="checkbox" id="showGrid10" checked>
<span data-i18n="grid10_label">Jede 10. Linie hervorheben</span>
</label>
<label class="field field--checkbox">
<input type="checkbox" id="showNumbers" checked>
<span data-i18n="numbers_label">Zeilen-/Spaltenzahlen anzeigen</span>
</label>
<label class="field field--checkbox">
<input type="checkbox" id="showGridLines" checked>
<span data-i18n="gridlines_label">Gitterlinien anzeigen</span>
</label>
<p class="panel__note" data-i18n="ansicht_note">Einstellungen gelten auch für den PNG-Export.</p>
</div>
</section>
</div>
</div>
<div class="panel__bottom-toggle-wrap">
<button type="button" id="sidebarToggleBottom" class="round-toggle-btn" aria-label="Seitenleiste ein-/ausklappen">
<svg viewBox="0 0 24 24" class="chevron-icon" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
</div>
</aside>
<section class="board-wrap" aria-label="Strickraster" data-i18n-aria-label="board_aria">
<div class="board-scroll" id="boardScroll">
<div class="board" id="board"></div>
</div>
</section>
</main>
<footer class="app-footer">
<span><span data-i18n="footer_before">(C) 2026</span> <a style="color: #000 !important;" target="_blank" href="https://github.com/heino17/Knitting-Pattern-Editor">heino17</a> <span id="appVersionTag" style="opacity: 0.65; font-size: 0.85em;"></span> <span data-i18n="footer_after">· strickmuster.html · lokal im Browser, keine Serververbindung nötig</span></span>
</footer>
<script>
(() => {
// --- App-Version ---
// Bei jedem inhaltlichen Update hochzählen (SemVer: MAJOR.MINOR.PATCH).
// Wird im Footer neben "heino17" angezeigt.
const APP_VERSION = '1.0.0';
document.getElementById('appVersionTag').textContent = 'v' + APP_VERSION;
// --- i18n ---
const LANG_KEY = 'strickmuster-lang';
const langSelect = document.getElementById('langSelect');
function detectInitialLang() {
// 1. Hat der Nutzer die Sprache schon einmal manuell gewechselt? -> diese Wahl gewinnt.
const saved = localStorage.getItem(LANG_KEY);
if (saved && I18N_AVAILABLE.includes(saved)) return saved;
// 2. Sonst gilt die in lang.js festgelegte Start-Sprache.
if (typeof APPLICATION_STARTUP_LANGUAGE_CODE !== 'undefined' && I18N_AVAILABLE.includes(APPLICATION_STARTUP_LANGUAGE_CODE)) {
return APPLICATION_STARTUP_LANGUAGE_CODE;
}
// 3. Absoluter Notfall-Fallback, falls die Konstante fehlt oder ungültig ist.
return 'de';
}
let currentLang = detectInitialLang();
function t(key) {
const dict = I18N[currentLang] || I18N.de;
return (key in dict) ? dict[key] : (I18N.de[key] || key);
}
function applyLang() {
document.documentElement.lang = currentLang;
document.title = t('meta_title');
document.querySelectorAll('[data-i18n]').forEach((el) => {
el.textContent = t(el.dataset.i18n);
});
document.querySelectorAll('[data-i18n-title]').forEach((el) => {
el.title = t(el.dataset.i18nTitle);
});
document.querySelectorAll('[data-i18n-aria-label]').forEach((el) => {
el.setAttribute('aria-label', t(el.dataset.i18nAriaLabel));
});
document.querySelectorAll('[data-i18n-placeholder]').forEach((el) => {
el.setAttribute('placeholder', t(el.dataset.i18nPlaceholder));
});
// Header-/Sidebar-Toggle-Aria-Labels hängen zusätzlich vom eingeklappt/ausgeklappt-Status ab,
// die werden separat unten in ihren jeweiligen set...Collapsed()-Funktionen aktualisiert.
if (typeof refreshCollapseLabels === 'function') refreshCollapseLabels();
// Farbtabelle enthält dynamisch erzeugte Texte (Zähler, Lösch-Titel, Leer-Hinweis),
// die von den obigen data-i18n-Selektoren nicht erfasst werden.
if (typeof renderPalette === 'function') renderPalette();
// Ebenso die Farbstufen-Anzeige beim Bild-Import - deren Text hängt vom
// aktuellen Reglerstand ab und darf nicht pauschal überschrieben werden.
if (typeof refreshImportLevelsOut === 'function') refreshImportLevelsOut();
// Hintergrundbild-Sichtbarkeits-Button zeigt "Bild ausblenden" ODER
// "Bild einblenden", je nach Zustand - kein fixer data-i18n-Text.
if (typeof updateBgImageToggleBtnLabel === 'function') updateBgImageToggleBtnLabel();
}
if (langSelect) {
langSelect.value = currentLang;
langSelect.addEventListener('change', () => {
currentLang = I18N_AVAILABLE.includes(langSelect.value) ? langSelect.value : 'de';
localStorage.setItem(LANG_KEY, currentLang);
applyLang();
});
}
// --- Seiten-Zoom (wie Strg +/- im Browser, aber nur für diese Seite) ---
const PAGE_ZOOM_KEY = 'strickmuster-page-zoom';
const PAGE_ZOOM_STEPS = [0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3];
const PAGE_ZOOM_DEFAULT_INDEX = 3; // entspricht 1.0 / 100%
const pageZoomOutBtn = document.getElementById('pageZoomOutBtn');
const pageZoomInBtn = document.getElementById('pageZoomInBtn');
function loadPageZoomIndex() {
const saved = parseInt(localStorage.getItem(PAGE_ZOOM_KEY), 10);
if (Number.isInteger(saved) && saved >= 0 && saved < PAGE_ZOOM_STEPS.length) return saved;
return PAGE_ZOOM_DEFAULT_INDEX;
}
let pageZoomIndex = loadPageZoomIndex();
function applyPageZoom() {
document.documentElement.style.zoom = PAGE_ZOOM_STEPS[pageZoomIndex];
if (pageZoomOutBtn) pageZoomOutBtn.disabled = pageZoomIndex === 0;
if (pageZoomInBtn) pageZoomInBtn.disabled = pageZoomIndex === PAGE_ZOOM_STEPS.length - 1;
}
if (pageZoomOutBtn && pageZoomInBtn) {
pageZoomOutBtn.addEventListener('click', () => {
if (pageZoomIndex === 0) return;
pageZoomIndex -= 1;
localStorage.setItem(PAGE_ZOOM_KEY, String(pageZoomIndex));
applyPageZoom();
});
pageZoomInBtn.addEventListener('click', () => {
if (pageZoomIndex === PAGE_ZOOM_STEPS.length - 1) return;
pageZoomIndex += 1;
localStorage.setItem(PAGE_ZOOM_KEY, String(pageZoomIndex));
applyPageZoom();
});
applyPageZoom();
}
const board = document.getElementById('board');
const boardScroll = document.getElementById('boardScroll');
const rowsInput = document.getElementById('rows');
const colsInput = document.getElementById('cols');
const cellSizeInput = document.getElementById('cellSize');
const cellSizeOut = document.getElementById('cellSizeOut');
const buildBtn = document.getElementById('buildBtn');
const colorPicker = document.getElementById('colorPicker');
const eraserBtn = document.getElementById('eraserBtn');
const toolToggle = document.getElementById('toolToggle');
const undoBtn = document.getElementById('undoBtn');
const redoBtn = document.getElementById('redoBtn');
const headerSaveBtn = document.getElementById('headerSaveBtn');
const headerLoadInput = document.getElementById('headerLoadInput');
const headerToolsRow = document.getElementById('headerToolsRow');
const headerEraserBtn = document.getElementById('headerEraserBtn');
const headerToolsUndoBtn = document.getElementById('headerToolsUndoBtn');
const headerToolsRedoBtn = document.getElementById('headerToolsRedoBtn');
const clearBtn = document.getElementById('clearBtn');
const exportJsonBtn = document.getElementById('exportJsonBtn');
const importJsonInput = document.getElementById('importJsonInput');
const importImageInput = document.getElementById('importImageInput');
const importLevels = document.getElementById('importLevels');
const importLevelsOut = document.getElementById('importLevelsOut');
const importSnapPalette = document.getElementById('importSnapPalette');
const importSizeHint = document.getElementById('importSizeHint');
const exportPngBtn = document.getElementById('exportPngBtn');
const showGrid10 = document.getElementById('showGrid10');
const showRgbValues = document.getElementById('showRgbValues');
const showNumbers = document.getElementById('showNumbers');
const showGridLines = document.getElementById('showGridLines');
const swatchesEl = document.getElementById('swatches');
const replaceOldColor = document.getElementById('replaceOldColor');
const replaceNewColor = document.getElementById('replaceNewColor');
const cellBgColor = document.getElementById('cellBgColor');
const replaceWithEraser = document.getElementById('replaceWithEraser');
const pickOldColorBtn = document.getElementById('pickOldColorBtn');
const replaceColorBtn = document.getElementById('replaceColorBtn');
const addNoteBtn = document.getElementById('addNoteBtn');
const paletteNewColor = document.getElementById('paletteNewColor');
const palettePickBtn = document.getElementById('palettePickBtn');
const paletteAddBtn = document.getElementById('paletteAddBtn');
const paletteCountLabel = document.getElementById('paletteCountLabel');
const paletteGrid = document.getElementById('paletteGrid');
const paletteExportBtn = document.getElementById('paletteExportBtn');
const paletteImportInput = document.getElementById('paletteImportInput');
const paletteClearBtn = document.getElementById('paletteClearBtn');
const headerPalette = document.getElementById('headerPalette');
const bgImageBtn = document.getElementById('bgImageBtn');
const bgImageMenu = document.getElementById('bgImageMenu');
const bgImageInput = document.getElementById('bgImageInput');
const bgImageRemoveBtn = document.getElementById('bgImageRemoveBtn');
const bgImageToggleBtn = document.getElementById('bgImageToggleBtn');
const EMPTY = '#ffffff';
// Liefert die tatsächlich zu setzende Hintergrundfarbe für eine Zelle: bei
// gesetztem Hintergrundbild werden unberührte (nie bemalte) Maschen
// transparent dargestellt, damit das Bild durchscheint. Eine unberührte
// Zelle ohne Hintergrundbild bekommt keinen Inline-Wert (leerer String),
// damit die CSS-Regel mit var(--cell-empty) greift - so bleibt die
// einstellbare Zell-Hintergrundfarbe von bewusst weiß gefärbten Zellen
// unterscheidbar. Jede berührte (bewusst bemalte) Zelle - auch wenn sie
// zufällig #ffffff ist - wird immer mit ihrem echten Farbwert gesetzt.
function cellBg(color, touched) {
if (!touched) {
return (state.backgroundImage && state.backgroundImageVisible) ? 'transparent' : '';
}
return color;
}
const RECENT_KEY = 'strickmuster-recent-colors-v1';
const PALETTE_KEY = 'strickmuster-farbtabelle-v1';
const PALETTE_MAX = 49; // 7 x 7 Raster in der Sidebar
const RGB_DISPLAY_KEY = 'strickmuster-rgb-display';
const CELL_BG_KEY = 'strickmuster-cell-bg-color';
const CELL_BG_DEFAULT = '#f7f5f0';
// Wandelt einen Hex-Farbcode (#rrggbb) in eine lesbare "rgb(r,g,b)"-Zeichenkette um.
// Bei ungültigem Format wird der Hex-Wert unverändert zurückgegeben.
function hexToRgbString(hex) {
const m = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);
if (!m) return hex;
const r = parseInt(m[1], 16);
const g = parseInt(m[2], 16);
const b = parseInt(m[3], 16);
return 'rgb(' + r + ',' + g + ',' + b + ')';
}
// Liefert den für Tooltips anzuzeigenden Farbwert, abhängig von der
// "Farbwerte als RGB anzeigen"-Einstellung.
function colorDisplayValue(hex) {
return showRgbValues.checked ? hexToRgbString(hex) : hex;
}
let state = { rows: 50, cols: 50, colors: [], touched: [], notes: [], backgroundImage: null, backgroundImageVisible: true };
let cellEls = [];
let isPainting = false;
let paintValue = null; // Farbe, die während des Ziehens verwendet wird
let toolMode = 'paint'; // 'paint' oder 'area'
let isSelecting = false;
let selStart = null;
let selEnd = null;
let selectionOverlayEl = null;
let pickingOldColor = false; // true, während per Klick im Raster die "Alte Farbe" für den Farbtausch aufgenommen wird
const HEAD_COL_WIDTH = 24;
const HEAD_ROW_HEIGHT = 16;
let undoStack = [];
let redoStack = [];
const UNDO_LIMIT = 30;
let recentColors = JSON.parse(localStorage.getItem(RECENT_KEY) || '[]');
let paletteColors = loadPaletteFromStorage();
let pickingPaletteColor = false; // true, während per Klick im Raster eine Farbe für die Farbtabelle aufgenommen wird
function loadPaletteFromStorage() {
try {
const raw = JSON.parse(localStorage.getItem(PALETTE_KEY) || '[]');
if (!Array.isArray(raw)) return [];
return raw.filter(c => typeof c === 'string').slice(0, PALETTE_MAX);
} catch (e) {
return [];
}
}
function savePaletteToStorage() {
localStorage.setItem(PALETTE_KEY, JSON.stringify(paletteColors));
}
function clamp(n, min, max) { return Math.max(min, Math.min(max, n)); }
function newColorArray(rows, cols) {
return new Array(rows * cols).fill(EMPTY);
}
// "Berührt"-Marker pro Zelle: unterscheidet eine nie bemalte (leere) Zelle
// von einer bewusst mit Weiß (#ffffff) bemalten Zelle - beide haben denselben
// Farbwert, aber nur unbemalte Zellen sollen die einstellbare
// Zell-Hintergrundfarbe (--cell-empty) zeigen. Radiergummi setzt eine Zelle
// zurück auf "nicht berührt" (= wirklich leer).
function newTouchedArray(rows, cols) {
return new Array(rows * cols).fill(false);
}
// --- Undo / Redo ---
let hasUnsavedChanges = false;
function snapshot() {
return { rows: state.rows, cols: state.cols, colors: state.colors.slice(), touched: state.touched.slice(), notes: state.notes.map(n => ({ ...n })) };
}
function pushUndo() {
hasUnsavedChanges = true;
undoStack.push(snapshot());
if (undoStack.length > UNDO_LIMIT) undoStack.shift();
redoStack = []; // neue Aktion macht den bisherigen Wiederherstellen-Verlauf ungültig
updateUndoRedoBtnState();
}
function undo() {
if (!undoStack.length) return;
redoStack.push(snapshot());
if (redoStack.length > UNDO_LIMIT) redoStack.shift();
const prev = undoStack.pop();
buildBoard(prev.rows, prev.cols, prev.colors, prev.notes, prev.touched);
rowsInput.value = prev.rows;
colsInput.value = prev.cols;
updateUndoRedoBtnState();
}
function redo() {
if (!redoStack.length) return;
undoStack.push(snapshot());
if (undoStack.length > UNDO_LIMIT) undoStack.shift();
const next = redoStack.pop();
buildBoard(next.rows, next.cols, next.colors, next.notes, next.touched);
rowsInput.value = next.rows;
colsInput.value = next.cols;
updateUndoRedoBtnState();
}
function updateUndoRedoBtnState() {
undoBtn.disabled = undoStack.length === 0;
redoBtn.disabled = redoStack.length === 0;
if (headerToolsUndoBtn) headerToolsUndoBtn.disabled = undoStack.length === 0;
if (headerToolsRedoBtn) headerToolsRedoBtn.disabled = redoStack.length === 0;
}
function buildBoard(rows, cols, colors, notes, touched) {
state.rows = rows;
state.cols = cols;
state.colors = colors || newColorArray(rows, cols);
// touched nur übernehmen, wenn ein passend langes Array mitgegeben wurde.
// Fehlt es (z.B. beim Öffnen einer älteren, vor dieser Funktion
// gespeicherten Musterdatei, oder nach Bild-Import/Größenänderung), wird
// es aus den Farben rekonstruiert: alles außer dem reinen Leer-Wert gilt
// dann automatisch als "berührt" (sichere Annahme für Altbestände).
if (Array.isArray(touched) && touched.length === state.colors.length) {
state.touched = touched;
} else {
state.touched = state.colors.map(c => c !== EMPTY);
}
// notes nur ersetzen, wenn explizit übergeben (z.B. bei Undo/Redo/Import) -
// beim reinen Raster-Größe-ändern (buildBtn) bleiben bestehende Notizen sonst erhalten,
// dort wird "notes" nicht mitgegeben, daher expliziter Parameter-Check:
if (notes !== undefined) state.notes = notes;
else if (!state.notes) state.notes = [];
cellEls = new Array(rows * cols);
board.style.setProperty('--cols', cols);
board.style.setProperty('--rows', rows);
applyCellSize();
board.classList.toggle('board--grid10', showGrid10.checked);
board.classList.toggle('board--numbers', showNumbers.checked);
board.classList.toggle('board--hide-gridlines', !showGridLines.checked);
board.innerHTML = '';
const frag = document.createDocumentFragment();
renderBackgroundImage();
// Obere Zeile: Ecke oben links, Spaltenköpfe, Ecke oben rechts
frag.appendChild(makeCorner('tl'));
for (let c = 0; c < cols; c++) {
const label = (c + 1) % 10 === 0 ? String(c + 1) : '';
frag.appendChild(makeHeaderCell(label, 'col-head--top'));
}
frag.appendChild(makeCorner('tr'));
// Datenzeilen: Zeilenkopf links, Zellen, Zeilenkopf rechts
for (let r = 0; r < rows; r++) {
const rowLabel = (r + 1) % 10 === 0 ? String(r + 1) : '';
frag.appendChild(makeHeaderCell(rowLabel, 'row-head--left'));
for (let c = 0; c < cols; c++) {
const idx = r * cols + c;
const cell = document.createElement('div');
cell.className = 'cell';
cell.dataset.idx = idx;
cell.style.background = cellBg(state.colors[idx], state.touched[idx]);
if ((c + 1) % 10 === 0) cell.classList.add('cell--edge-v');
if ((r + 1) % 10 === 0) cell.classList.add('cell--edge-h');
frag.appendChild(cell);
cellEls[idx] = cell;
}
frag.appendChild(makeHeaderCell(rowLabel, 'row-head--right'));
}
// Untere Zeile: Ecke unten links, Spaltenköpfe, Ecke unten rechts
frag.appendChild(makeCorner('bl'));
for (let c = 0; c < cols; c++) {
const label = (c + 1) % 10 === 0 ? String(c + 1) : '';
frag.appendChild(makeHeaderCell(label, 'col-head--bottom'));
}
frag.appendChild(makeCorner('br'));
board.appendChild(frag);
selectionOverlayEl = document.createElement('div');
selectionOverlayEl.className = 'selection-overlay';
board.appendChild(selectionOverlayEl);
if (importSizeHint) importSizeHint.textContent = cols + ' × ' + rows;
renderNotes();
}
function makeCorner(variant) {
const d = document.createElement('div');
d.className = 'head-corner head-corner--' + variant;
return d;
}
function makeHeaderCell(text, cls) {
const d = document.createElement('div');
d.className = 'head-cell ' + cls;
d.textContent = text;
return d;
}
let lastCellSize = Number(cellSizeInput.value); // Referenzwert, um Notizzettel beim Zoomen proportional mitzuskalieren
function applyCellSize() {
const size = cellSizeInput.value + 'px';
board.style.setProperty('--cell-size', size);
const newSize = Number(cellSizeInput.value);
if (newSize !== lastCellSize && lastCellSize > 0) {
scaleNotes(newSize / lastCellSize);
}
lastCellSize = newSize;
}
// Skaliert Position, Boxgröße UND Schriftgröße aller Notizzettel gemeinsam
// um denselben Faktor, damit sie beim Zoomen des Rasters (Zellgröße ändern)
// an ihrem relativen Platz bleiben UND ihre Zellenzahl (z.B. "10x10 Zellen")
// beibehalten - wie aus einem Guss, analog zum Gartenplaner. Die Schrift
// bleibt dabei immer im selben Verhältnis zur Box, statt an einer eigenen
// min/max-Pixelgrenze festzuhängen.
function scaleNotes(factor) {
if (!state.notes.length || factor === 1) return;
state.notes.forEach(n => {
n.x *= factor;
n.y *= factor;
n.w = Math.max(1, n.w * factor);
n.h = Math.max(1, n.h * factor);
n.fontSize = Math.max(1, n.fontSize * factor);
});
renderNotes();
}
function paintCell(cell, color, erasing) {
const idx = Number(cell.dataset.idx);
state.colors[idx] = color;
state.touched[idx] = !erasing;
cell.style.background = cellBg(color, state.touched[idx]);
}
function getActiveColor() {
return eraserBtn.dataset.active === 'true' ? EMPTY : colorPicker.value;
}
function addRecentColor(hex) {
if (hex === EMPTY) return;
recentColors = [hex, ...recentColors.filter(c => c !== hex)].slice(0, 12);
localStorage.setItem(RECENT_KEY, JSON.stringify(recentColors));
renderSwatches();
}
function renderSwatches() {
// "Zuletzt verwendete Farben"-Swatches wurden aus der Sidebar entfernt
// (die Farbtabelle deckt diesen Bedarf bereits ab).
if (!swatchesEl) return;
swatchesEl.innerHTML = '';
recentColors.forEach(hex => {
const b = document.createElement('button');
b.type = 'button';
b.className = 'swatch';
b.style.background = hex;
b.title = hex;
b.addEventListener('click', () => {
colorPicker.value = hex;
setEraserActive(false);
});
swatchesEl.appendChild(b);
});
}
// --- Farbtabelle: dauerhafte, separat speicherbare Palette (bis zu 50 Farben) ---
function activatePaletteColor(hex) {
colorPicker.value = hex;
setEraserActive(false);
if (toolMode !== 'paint') setToolMode('paint');
}
function addToPalette(hex) {
if (!hex) return;
const normalized = hex.toLowerCase();
if (paletteColors.some(c => c.toLowerCase() === normalized)) return; // schon enthalten
if (paletteColors.length >= PALETTE_MAX) {
alert(t('palette_full_msg'));
return;
}
paletteColors.push(hex);
savePaletteToStorage();
renderPalette();
}
function removeFromPalette(hex) {
paletteColors = paletteColors.filter(c => c !== hex);
savePaletteToStorage();
renderPalette();
}
// --- Farbtabelle: manuelles Umsortieren per Ziehen (Pointer Events, wie
// beim Verschieben der Notizzettel - funktioniert auch per Touch). Ein
// Klick ohne nennenswerte Bewegung wählt weiterhin ganz normal die Farbe
// aus; erst ab einer kleinen Zieh-Schwelle wird umsortiert. Wirkt sich auf
// headerPalette UND paletteGrid gleichermaßen aus, da beide dieselbe
// paletteColors-Reihenfolge anzeigen.
const PALETTE_DRAG_THRESHOLD = 5; // px
let paletteDropTargetEl = null;
function clearPaletteDropTarget() {
if (paletteDropTargetEl) {
paletteDropTargetEl.classList.remove('is-drop-target');
paletteDropTargetEl = null;
}
}
function attachPaletteDrag(swatchEl, hex) {
swatchEl.addEventListener('pointerdown', (e) => {
if (e.button !== 0) return; // nur linke Maustaste bzw. primärer Touch-Punkt
const startX = e.clientX;
const startY = e.clientY;
let moved = false;
const onMove = (e2) => {
if (!moved) {
if (Math.hypot(e2.clientX - startX, e2.clientY - startY) < PALETTE_DRAG_THRESHOLD) return;
moved = true;
swatchEl.classList.add('is-dragging');
document.body.style.cursor = 'move'; // gilt für den ganzen Bildschirm, nicht nur übers Swatch
}
const overEl = document.elementFromPoint(e2.clientX, e2.clientY);
const targetSwatch = overEl ? overEl.closest('.palette-swatch') : null;
const validTarget = targetSwatch && targetSwatch !== swatchEl && targetSwatch.parentElement === swatchEl.parentElement;
if (validTarget) {
if (paletteDropTargetEl !== targetSwatch) {
clearPaletteDropTarget();
targetSwatch.classList.add('is-drop-target');
paletteDropTargetEl = targetSwatch;
}
} else {
clearPaletteDropTarget();
}
};
const onUp = () => {
window.removeEventListener('pointermove', onMove);
window.removeEventListener('pointerup', onUp);
swatchEl.classList.remove('is-dragging');
document.body.style.cursor = '';
const dropHex = paletteDropTargetEl ? paletteDropTargetEl.dataset.hex : null;
clearPaletteDropTarget();
if (moved && dropHex && dropHex !== hex) {
const fromIdx = paletteColors.indexOf(hex);
const toIdx = paletteColors.indexOf(dropHex);
if (fromIdx !== -1 && toIdx !== -1) {
paletteColors.splice(fromIdx, 1);
paletteColors.splice(toIdx, 0, hex);
savePaletteToStorage();
renderPalette();
}
}
};
window.addEventListener('pointermove', onMove);
window.addEventListener('pointerup', onUp);
});
}
function makePaletteSwatch(hex, forHeader) {
const b = document.createElement('button');
b.type = 'button';
b.className = 'palette-swatch';
b.style.background = hex;
b.title = colorDisplayValue(hex);
b.dataset.hex = hex;
b.classList.toggle('is-active', !forHeader && colorPicker.value.toLowerCase() === hex.toLowerCase() && eraserBtn.dataset.active !== 'true');
b.addEventListener('click', () => activatePaletteColor(hex));
attachPaletteDrag(b, hex);
if (!forHeader) {
const del = document.createElement('button');
del.type = 'button';
del.className = 'palette-swatch__del';
del.setAttribute('aria-label', t('palette_remove_title'));
del.title = t('palette_remove_title');
del.textContent = '×';
del.addEventListener('click', (e) => {
e.stopPropagation();
removeFromPalette(hex);
});
b.appendChild(del);
}
return b;
}
function renderPalette() {
paletteGrid.innerHTML = '';
if (!paletteColors.length) {
const hint = document.createElement('p');
hint.className = 'palette-empty-hint';
hint.textContent = t('palette_empty_hint');
paletteGrid.appendChild(hint);
} else {
paletteColors.forEach(hex => paletteGrid.appendChild(makePaletteSwatch(hex, false)));
}
paletteCountLabel.textContent = t('palette_count_label') + ' (' + paletteColors.length + ' / ' + PALETTE_MAX + ')';
headerPalette.innerHTML = '';
paletteColors.forEach(hex => headerPalette.appendChild(makePaletteSwatch(hex, true)));
// "Auf Palette einrasten" beim Bild-Import ergibt ohne gespeicherte
// Farben keinen Sinn - Checkbox so lange deaktivieren.
const hasPalette = paletteColors.length > 0;
importSnapPalette.disabled = !hasPalette;
if (!hasPalette) importSnapPalette.checked = false;
importSnapPalette.title = hasPalette ? '' : t('import_snap_palette_empty_title');
}
paletteAddBtn.addEventListener('click', () => addToPalette(paletteNewColor.value));
palettePickBtn.addEventListener('click', () => {
pickingPaletteColor = !pickingPaletteColor;
palettePickBtn.classList.toggle('is-active', pickingPaletteColor);
if (pickingPaletteColor) {
board.classList.add('board--tool-pipette');
} else {
board.classList.toggle('board--tool-pipette', toolMode === 'pipette');
}
});
paletteClearBtn.addEventListener('click', () => {
if (!paletteColors.length) return;
if (!confirm(t('palette_confirm_clear'))) return;
paletteColors = [];
savePaletteToStorage();
renderPalette();
});
// Merkt sich den zuletzt geladenen Farbtabelle-Dateinamen, analog zum
// Muster-Dateinamen oben.
let lastPaletteFileName = 'Farbtabelle.json';
paletteExportBtn.addEventListener('click', () => {
const blob = new Blob([JSON.stringify({ colors: paletteColors }, null, 2)], { type: 'application/json' });