-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneFileSheet.html
More file actions
2536 lines (2340 loc) · 85.6 KB
/
Copy pathOneFileSheet.html
File metadata and controls
2536 lines (2340 loc) · 85.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
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="ja" translate="no">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="google" content="notranslate">
<title>OneFileSheet</title>
<style>
:root {
--bg: #ffffff;
--fg: #1a1a1a;
--border: #d9d9de;
--accent: #2563eb;
--head-bg: #f4f4f5;
--coord-bg: #ececef;
--coord-fg: #6b6b74;
--hover: rgba(37, 99, 235, 0.06);
--status: #555;
--ok: #15803d;
--warn: #b45309;
--btn-bg: #ffffff;
--btn-border: #c8c8cd;
--menu-shadow: rgba(0, 0, 0, 0.15);
/* スクロールバーもテーマ色に追従させる(CSS変数経由なのでJS側の
テーマ切替でそのまま更新される) */
scrollbar-color: color-mix(in srgb, var(--accent) 45%, var(--coord-bg)) var(--coord-bg);
}
/* テーマの実体は app-code の THEME_LIST から JS がCSS変数を導出して適用する。
以下はJS実行前の初期描画用フォールバック */
@media (prefers-color-scheme: dark) {
:root {
--bg: #1e1e1e;
--fg: #e6e6e6;
--border: #3a3a3a;
--accent: #60a5fa;
--head-bg: #2a2a2a;
--coord-bg: #262626;
--coord-fg: #9a9aa2;
--hover: rgba(96, 165, 250, 0.08);
--status: #aaa;
--ok: #4ade80;
--warn: #fbbf24;
--btn-bg: #2a2a2a;
--btn-border: #454545;
--menu-shadow: rgba(0, 0, 0, 0.5);
}
}
html, body { height: 100%; }
body {
font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
margin: 0;
padding: 10px 14px;
box-sizing: border-box;
display: flex;
flex-direction: column;
background: var(--bg);
color: var(--fg);
}
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.topbar .sep { width: 6px; }
#doc-title {
margin: 0 8px 0 0;
font-size: 17px;
font-weight: 700;
padding: 3px 6px;
border-radius: 4px;
cursor: text;
white-space: pre;
}
#doc-title:hover { background: var(--hover); }
#doc-title:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
#file-path {
margin-left: auto;
color: var(--status);
font-size: 12px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 38%;
}
#help-pop {
position: fixed;
z-index: 10;
max-width: 440px;
padding: 10px 14px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
box-shadow: 0 4px 16px var(--menu-shadow);
font-size: 13px;
}
#help-pop[hidden] { display: none; }
#help-pop ul { margin: 6px 0 0; padding-left: 18px; }
#help-pop li { margin: 4px 0; }
button {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 6px 12px;
border: 1px solid var(--btn-border);
background: var(--btn-bg);
color: var(--fg);
border-radius: 6px;
cursor: pointer;
font-size: 13px;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button svg { display: block; }
button svg[hidden] { display: none; }
.topbar button { padding: 7px 9px; }
#theme-pop {
position: fixed;
z-index: 10;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 2px;
width: 420px;
max-width: calc(100vw - 24px);
max-height: 70vh;
overflow: auto;
padding: 8px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
box-shadow: 0 4px 16px var(--menu-shadow);
}
#theme-pop[hidden] { display: none; }
#theme-pop .theme-item {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 6px;
padding: 5px 8px;
border: 1px solid transparent;
background: none;
border-radius: 6px;
font-size: 12px;
color: var(--fg);
}
#theme-pop .theme-item:hover { background: var(--hover); }
#theme-pop .theme-item.active { border-color: var(--accent); }
#theme-pop .swatch {
width: 14px;
height: 14px;
border-radius: 50%;
border: 2px solid;
flex: none;
}
#save-status { margin-left: 6px; color: var(--status); font-size: 13px; }
#save-status.hint {
cursor: pointer;
text-decoration: underline dotted;
text-underline-offset: 3px;
}
#lang-btn { font-size: 11px; font-weight: 700; letter-spacing: 0.5px; min-width: 34px; }
#sheet-tabs .tab[contenteditable] { cursor: text; outline: 2px solid var(--accent); outline-offset: -2px; }
#save-status.ok { color: var(--ok); }
#save-status.warn { color: var(--warn); }
.sheet-wrap {
overflow: auto;
/* 仮想スクロールがスペーサー高さを調整するため、ブラウザの
スクロールアンカリングと干渉しないよう無効化する */
overflow-anchor: none;
flex: 1 1 auto;
min-height: 0;
border: 1px solid var(--border);
border-radius: 6px;
}
/* 列幅は JS が colgroup で与える。fixed にしないと1セルの編集で
表全体の再レイアウトが走り、大きなシートで固まる */
table { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.v-pad td { padding: 0; border: none; height: 0; }
td, th {
border-right: 1px solid var(--border);
border-bottom: 1px solid var(--border);
padding: 4px 6px;
font-size: 14px;
text-align: left;
}
tr:last-child td, tr:last-child th { border-bottom: none; }
td:last-child, th:last-child { border-right: none; }
.cell {
min-width: 120px;
max-width: 360px;
height: 28px;
cursor: text;
white-space: pre-wrap;
overflow-wrap: anywhere;
}
th.cell { background: var(--head-bg); font-weight: 600; }
.cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
tr:hover td.cell { background: var(--hover); }
th.coord {
background: var(--coord-bg);
color: var(--coord-fg);
font-weight: 500;
font-size: 12px;
text-align: center;
padding: 2px 8px;
cursor: pointer;
user-select: none;
min-width: 28px;
}
th.coord:hover { color: var(--accent); }
th.col-head, th.corner { position: sticky; top: 0; z-index: 2; }
th.row-head, th.corner { position: sticky; left: 0; }
th.corner { z-index: 3; cursor: default; }
th.row-head { z-index: 1; }
.stat-btn { cursor: pointer; }
.stat-btn:hover { color: var(--accent); }
.stat-btn.active { color: var(--accent); }
.stat-btn svg { display: inline-block; vertical-align: middle; }
th.stat-row-btn { min-width: 24px; padding: 2px 6px; text-align: center; position: sticky; right: 0; z-index: 1; }
/* position は上の sticky 指定を上書きしない(sticky でも .head-stat の
絶対配置の基準になるため relative は不要) */
th.col-head, th.row-head { padding-right: 18px; }
.head-stat {
position: absolute;
right: 3px;
top: 50%;
transform: translateY(-50%);
display: inline-flex;
color: var(--coord-fg);
}
th.corner-tr { position: sticky; top: 0; right: 0; z-index: 3; cursor: default; }
#sheet-tabs {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 2px;
margin-top: 12px;
margin-bottom: -1px;
padding: 0 6px;
position: relative;
z-index: 1;
}
#sheet-tabs .tab {
padding: 5px 16px;
background: var(--coord-bg);
color: var(--status);
border: 1px solid var(--border);
border-bottom: none;
border-radius: 8px 8px 0 0;
}
#sheet-tabs .tab.active {
background: var(--bg);
color: var(--fg);
font-weight: 600;
box-shadow: 0 1px 0 var(--bg);
}
#sheet-tabs .add-sheet {
padding: 4px 10px;
margin-left: 4px;
border-bottom: none;
border-radius: 8px 8px 0 0;
}
#ctx-menu {
position: fixed;
z-index: 10;
display: flex;
flex-direction: column;
min-width: 150px;
padding: 4px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
box-shadow: 0 4px 16px var(--menu-shadow);
}
#ctx-menu[hidden] { display: none; }
#ctx-menu button {
border: none;
background: none;
border-radius: 5px;
padding: 6px 10px;
justify-content: flex-start;
text-align: left;
font-size: 13px;
color: var(--fg);
}
#ctx-menu button:hover { background: var(--hover); color: var(--accent); }
/* 発光系テーマ(THEME_LIST の glow: true)でのみ有効になるグロー */
:root[data-glow] body { text-shadow: 0 0 8px currentColor; }
:root[data-glow] button svg { filter: drop-shadow(0 0 4px currentColor); }
:root[data-glow] #doc-title { text-shadow: 0 0 8px currentColor, 0 0 22px var(--glow-soft); }
:root[data-glow] .sheet-wrap {
border-color: var(--accent);
box-shadow: 0 0 8px var(--glow-soft), 0 0 26px var(--glow-soft), inset 0 0 14px var(--glow-faint);
}
:root[data-glow] td, :root[data-glow] th { border-color: color-mix(in srgb, var(--accent) 35%, var(--bg)); }
:root[data-glow] .cell:focus { box-shadow: 0 0 8px var(--glow-soft), 0 0 22px var(--glow-soft); }
:root[data-glow] button { border-color: color-mix(in srgb, var(--accent) 45%, var(--btn-bg)); }
:root[data-glow] button:hover { box-shadow: 0 0 14px var(--glow-soft); }
:root[data-glow] #sheet-tabs .tab { border-color: color-mix(in srgb, var(--accent) 35%, var(--bg)); }
:root[data-glow] #sheet-tabs .tab.active {
border-color: var(--accent);
box-shadow: 0 1px 0 var(--bg), 0 0 16px var(--glow-soft);
}
:root[data-glow] #ctx-menu,
:root[data-glow] #help-pop,
:root[data-glow] #theme-pop,
:root[data-glow] #stats-pop {
border-color: var(--accent);
box-shadow: 0 4px 16px var(--menu-shadow), 0 0 20px var(--glow-soft);
}
#stats-pop {
position: fixed;
z-index: 10;
min-width: 190px;
padding: 10px 14px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
box-shadow: 0 4px 16px var(--menu-shadow);
font-size: 13px;
}
#stats-pop[hidden] { display: none; }
#stats-pop b { display: block; margin-bottom: 6px; }
#stats-pop .stat-row { display: flex; justify-content: space-between; gap: 16px; margin: 3px 0; }
#stats-pop .stat-row span:first-child { color: var(--status); }
#drop-overlay {
position: fixed;
inset: 0;
z-index: 20;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.35);
pointer-events: none;
}
#drop-overlay[hidden] { display: none; }
#drop-overlay .drop-box {
padding: 24px 48px;
border: 2px dashed var(--accent);
border-radius: 12px;
background: var(--bg);
color: var(--fg);
font-size: 16px;
font-weight: 600;
}
</style>
</head>
<body>
<div class="topbar">
<h2 id="doc-title" title="クリックでタイトルを編集">OneFileSheet</h2>
<button id="save-btn" onclick="saveToSameFile()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
</button>
<button id="reload-btn" onclick="reloadFromFile()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36L21 8"/><polyline points="21 3 21 8 16 8"/></svg>
</button>
<span class="sep"></span>
<button id="undo-btn" onclick="undo()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/></svg>
</button>
<button id="redo-btn" onclick="redo()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m15 14 5-5-5-5"/><path d="M20 9H9.5a5.5 5.5 0 0 0 0 11H13"/></svg>
</button>
<span class="sep"></span>
<button id="addrow-btn" onclick="addRow()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M3 12h18"/><path d="M3 18h7"/><path d="M17.5 14.5v7"/><path d="M14 18h7"/></svg>
</button>
<button id="addcol-btn" onclick="addCol()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3v18"/><path d="M12 3v18"/><path d="M18 3v7"/><path d="M18 14v7"/><path d="M14.5 17.5h7"/></svg>
</button>
<span class="sep"></span>
<span id="save-status">保存先未設定</span>
<span id="file-path"></span>
<button id="export-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<button id="help-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
</button>
<button id="lang-btn"></button>
<button id="theme-btn">
<svg id="theme-icon-sun" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>
<svg id="theme-icon-moon" hidden width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z"/></svg>
</button>
</div>
<div id="help-pop" hidden></div>
<div id="theme-pop" hidden></div>
<div id="stats-pop" hidden></div>
<div id="drop-overlay" hidden><div class="drop-box"></div></div>
<div id="sheet-tabs"></div>
<div class="sheet-wrap">
<table id="sheet"></table>
</div>
<div id="ctx-menu" hidden></div>
<!--
AGENT NOTES — contract for AI/coding agents editing this file:
- The spreadsheet document lives ONLY in the JSON block directly below this
comment: the script element with id "sheet-data" (type application/json).
Everything else in this file is application code/UI.
- Document format (v2):
{ "title": string, "theme": "auto" or a theme id from THEME_LIST in the
app code (43 built-in themes),
"lang": "auto"|"en"|"ja" (UI language; "auto" follows the browser),
"activeSheet": number, "sheets": [ { "name": string, "data": [[...]] } ] }
Each sheet's data is a JSON 2D array of strings; data[0] is that sheet's
header row. All rows in a sheet have equal length (the app pads ragged rows
on load). Cells are plain strings; numbers are coerced to strings.
A legacy bare 2D array is still accepted on load and migrates to v2 on the
next save.
- Keep the formatting produced by JSON.stringify(doc, null, 2): 2-space
indent, LF line endings. This keeps saves diff-stable.
- Do NOT rename, duplicate, or reformat the opening tag of the sheet-data
block. The app locates the block with a regex keyed on id="sheet-data";
extra attributes are tolerated but the id must stay.
- If a cell value contains "<", write it as \u003c in the JSON so the block
cannot terminate early. Cell newlines are stored as \n. The in-app save
applies this escaping automatically.
- Co-editing semantics: the browser app keeps the document in memory. Saving
from the browser re-reads this file from disk and rewrites ONLY the
sheet-data block, so code edits elsewhere in the file survive a user save.
If you change the JSON while the file is open in a browser, the user should
press 再読み込み before saving; the app also warns when the on-disk block
changed after load.
- App code lives in the script element with id "app-code" at the end of body.
Entry points: render(), reloadFromFile(), saveToSameFile(), exportHtml(),
exportCsv(), initialize(). UI strings live in the MESSAGES catalog (en/ja);
keep identifiers English.
-->
<script id="sheet-data" type="application/json">
{
"title": "OneFileSheet",
"theme": "auto",
"lang": "auto",
"activeSheet": 0,
"sheets": [
{
"name": "Sheet1",
"data": [
[
"Item",
"Category",
"Amount",
"Memo"
],
[
"Coffee beans",
"Food",
"1,280",
""
],
[
"Notebook",
"Office",
"350",
""
],
[
"JavaScript guide",
"Study",
"3,200",
"tech book"
],
[
"Lunch",
"Food",
"850",
""
],
[
"USB-C cable",
"Gadgets",
"1,499",
""
],
[
"Train fare",
"Transport",
"420",
"IC card"
],
[
"Sticker",
"Other",
"free",
"promo"
]
]
}
]
}
</script>
<script id="app-code">
"use strict";
const table = document.getElementById("sheet");
const wrapEl = document.querySelector(".sheet-wrap");
const statusEl = document.getElementById("save-status");
const menuEl = document.getElementById("ctx-menu");
const titleEl = document.getElementById("doc-title");
const pathEl = document.getElementById("file-path");
const tabsEl = document.getElementById("sheet-tabs");
const helpBtn = document.getElementById("help-btn");
const helpEl = document.getElementById("help-pop");
const langBtn = document.getElementById("lang-btn");
const statsPop = document.getElementById("stats-pop");
const themeBtn = document.getElementById("theme-btn");
const themePop = document.getElementById("theme-pop");
const themeIconSun = document.getElementById("theme-icon-sun");
const themeIconMoon = document.getElementById("theme-icon-moon");
// HTMLエクスポート用に、JSがDOMへ手を入れる前の素のドキュメントを控えておく。
// 自己解凍版(build.js製)ではブートストラップが控えた圧縮シェルを使う
const BOOT_HTML = window.__PACKED_HTML__ || "<!DOCTYPE html>\n" + document.documentElement.outerHTML;
const DB_NAME = "one-file-sheet";
const DB_STORE = "handles";
const HANDLE_KEY = "self-file:" + location.href;
const LAST_HANDLE_KEY = "last-picked";
// テーマは bg / fg / accent の3色だけ定義し、残りのCSS変数は themeVars() が導出する
const THEME_LIST = [
{ id: "light", name: "Light", bg: "#ffffff", fg: "#1a1a1a", accent: "#2563eb" },
{ id: "dark", name: "Dark", bg: "#1e1e1e", fg: "#e6e6e6", accent: "#60a5fa" },
{ id: "sepia", name: "Sepia", bg: "#f5ecd9", fg: "#4a3a26", accent: "#9a6b2f" },
{ id: "ocean", name: "Ocean", bg: "#0e1a2b", fg: "#d7e4f2", accent: "#4cc3ff" },
{ id: "forest", name: "Forest", bg: "#f1f7f0", fg: "#233a28", accent: "#2f855a" },
{ id: "paper", name: "Paper", bg: "#fafaf7", fg: "#33322e", accent: "#d97706" },
{ id: "snow", name: "Snow", bg: "#f7fafd", fg: "#26323f", accent: "#3b82f6" },
{ id: "mint", name: "Mint", bg: "#effaf5", fg: "#1f3d33", accent: "#0d9488" },
{ id: "sky", name: "Sky", bg: "#eef6ff", fg: "#1e3a5f", accent: "#0284c7" },
{ id: "sand", name: "Sand", bg: "#f6f1e7", fg: "#43382a", accent: "#b45309" },
{ id: "rose", name: "Rose", bg: "#fdf2f6", fg: "#4a2333", accent: "#db2777" },
{ id: "lavender", name: "Lavender", bg: "#f5f2fc", fg: "#372f4d", accent: "#7c3aed" },
{ id: "sakura", name: "Sakura", bg: "#fdf3f4", fg: "#502b33", accent: "#e11d48" },
{ id: "lemon", name: "Lemon", bg: "#fdfbe8", fg: "#3f3a1a", accent: "#ca8a04" },
{ id: "peach", name: "Peach", bg: "#fef3ee", fg: "#4d2f24", accent: "#ea580c" },
{ id: "linen", name: "Linen", bg: "#faf6f0", fg: "#3f3a34", accent: "#a16207" },
{ id: "aqua", name: "Aqua", bg: "#ecfcfb", fg: "#134e4a", accent: "#0891b2" },
{ id: "pearl", name: "Pearl", bg: "#f4f4f6", fg: "#2f2f36", accent: "#6d28d9" },
{ id: "midnight", name: "Midnight", bg: "#0f1115", fg: "#d5d9e0", accent: "#818cf8" },
{ id: "charcoal", name: "Charcoal", bg: "#26282b", fg: "#dcdcdc", accent: "#f59e0b" },
{ id: "slate", name: "Slate", bg: "#1f2937", fg: "#e2e8f0", accent: "#38bdf8" },
{ id: "ink", name: "Ink", bg: "#101418", fg: "#c9d4de", accent: "#22d3ee" },
{ id: "dracula", name: "Dracula", bg: "#282a36", fg: "#f8f8f2", accent: "#bd93f9" },
{ id: "nord", name: "Nord", bg: "#2e3440", fg: "#eceff4", accent: "#88c0d0" },
{ id: "solarized", name: "Solarized", bg: "#fdf6e3", fg: "#586e75", accent: "#268bd2" },
{ id: "solarized-dark", name: "Solarized Dark", bg: "#002b36", fg: "#93a1a1", accent: "#2aa198" },
{ id: "espresso", name: "Espresso", bg: "#2b211c", fg: "#e8d9cf", accent: "#d97706" },
{ id: "wine", name: "Wine", bg: "#2a1520", fg: "#f1dae4", accent: "#f472b6" },
{ id: "plum", name: "Plum", bg: "#241b2e", fg: "#e8ddf5", accent: "#c084fc" },
{ id: "pine", name: "Pine", bg: "#12211a", fg: "#d2e8dc", accent: "#34d399" },
{ id: "ember", name: "Ember", bg: "#1c1210", fg: "#f3ddd4", accent: "#f97316" },
{ id: "pop-cyan", name: "Pop Cyan", bg: "#00a7d0", fg: "#ffef00", accent: "#ffffff" },
{ id: "pop-red", name: "Pop Red", bg: "#d92121", fg: "#ffe600", accent: "#ffffff" },
{ id: "pop-blue", name: "Pop Blue", bg: "#2334e0", fg: "#ffffff", accent: "#ffe600" },
{ id: "pop-green", name: "Pop Green", bg: "#0fa33c", fg: "#ffffff", accent: "#ffe600" },
{ id: "pop-purple", name: "Pop Purple", bg: "#8a1fd6", fg: "#ffee55", accent: "#00e5ff" },
{ id: "pop-orange", name: "Pop Orange", bg: "#f57b00", fg: "#ffffff", accent: "#2020dd" },
{ id: "pop-yellow", name: "Pop Yellow", bg: "#ffdf00", fg: "#d8231f", accent: "#1330d6" },
{ id: "pop-pink", name: "Pop Pink", bg: "#f5379f", fg: "#ffffff", accent: "#ffe600" },
{ id: "neon", name: "Neon", bg: "#0b0b14", fg: "#ff8fe0", accent: "#ff2ec4", glow: true },
{ id: "cyberpunk", name: "Cyberpunk", bg: "#120e26", fg: "#ffe95e", accent: "#fcee0a", glow: true },
{ id: "synthwave", name: "Synthwave", bg: "#1a0f2e", fg: "#7deff2", accent: "#2de2e6", glow: true },
{ id: "matrix", name: "Matrix", bg: "#020a04", fg: "#3dff7c", accent: "#00ff66", glow: true },
{ id: "hologram", name: "Hologram", bg: "#03101f", fg: "#7cd6ff", accent: "#00a8ff", glow: true },
{ id: "crimson", name: "Crimson", bg: "#160404", fg: "#ff8a80", accent: "#ff2b2b", glow: true },
// 高級CRTの琥珀色蛍光体(P3, ほぼ色温度3000K)。緑(Terminal)と切替できた時代へのオマージュ
{ id: "amber", name: "Amber", bg: "#140d03", fg: "#ffb000", accent: "#ff8c00", glow: true },
{ id: "terminal", name: "Terminal", bg: "#0a0f0a", fg: "#86efac", accent: "#22c55e" },
];
const THEME_MAP = {};
THEME_LIST.forEach(t => { THEME_MAP[t.id] = t; });
// UI文字列カタログ。doc.lang が "auto" のときはブラウザ言語に従う
const MESSAGES = {
en: {
btnSave: "Save (Ctrl+S)",
btnReload: "Reload from file",
btnUndo: "Undo (Ctrl+Z)",
btnRedo: "Redo (Ctrl+Y)",
btnAddRow: "Add row",
btnAddCol: "Add column",
btnExport: "Export (HTML / CSV)",
btnHelp: "Help",
btnLang: "Language (saved in this file)",
themePrefix: "Theme: ",
titleEdit: "Click to edit the title",
noTarget: "No save target",
noTargetTip: "Two ways to enable saving:\n・ Drag & drop the currently open file here\n・ Pick the currently open file when saving (Ctrl+S)\nOnce allowed, the browser remembers it - next time it just saves.",
target: "Save to: ",
unsaved: " ●unsaved",
colMenuTitle: "Click for column insert/delete menu",
rowMenuTitle: "Click for row insert/delete menu",
tabTitle: "Double-click to rename / right-click for menu",
addSheetTitle: "Add sheet",
insRowAbove: "Insert row above",
insRowBelow: "Insert row below",
delRow: "Delete row",
insColLeft: "Insert column left",
insColRight: "Insert column right",
delCol: "Delete column",
statsRow: "Row ",
statsCount: "Count",
statsExcluded: "Excluded (non-numeric)",
statsSum: "Sum",
statsAvg: "Average",
statsMax: "Max",
statsMin: "Min",
statsNoNumbers: "No numeric cells",
sheetRename: "Rename",
sheetLeft: "Move left",
sheetRight: "Move right",
sheetDelete: "Delete sheet",
exportHtmlItem: "Export HTML (app + all sheets)",
exportCsvItem: "Export CSV (current sheet)",
langAuto: "Auto (browser language)",
toastSaved: "✓ Saved: ",
toastLoaded: "Loaded: ",
toastReloaded: "Reloaded: ",
toastCsv: "CSV exported: ",
toastHtml: "HTML exported",
toastSaveExported: "This browser can't save in place — downloaded the HTML instead",
lastRow: "Cannot delete the last row",
lastCol: "Cannot delete the last column",
lastSheet: "Cannot delete the last sheet",
helpTitle: "How to use",
help1: "Click the title to edit it",
help2: "Enter / Tab / arrow keys: move between cells (Enter on the last row adds a row)",
help3: "Alt+Enter: line break inside a cell",
help4: "Ctrl+S: save (the first save asks you to pick this file itself; on unsupported browsers it downloads the HTML)",
help5: "Ctrl+Z / Ctrl+Y: undo / redo",
help6: "Click a row number / column letter: insert & delete menu. Chart icons on the headers and at row ends: quick stats (hover to peek, click to pin)",
help7: "Sheet tabs: click to switch, double-click to rename, right-click for menu",
help8: "Paste ranges from Excel / Google Sheets",
help9: "Download button: export HTML (app + all sheets) or CSV",
help10: "Pick a theme with the top-right button (47 themes + auto)",
help11: "Title, theme and all sheets are stored inside this single HTML file",
help12: "Drop an HTML file onto the page to open it (it becomes the save target)",
dropHint: "Drop here to open the file",
confirmDropDirty: "You have unsaved edits. Discard them and open the dropped file?",
confirmTargetDiffers: "The selected file's content differs from this sheet's source. Use it as the save target and overwrite it?",
noFsApi: "This browser does not support the File System Access API. Please use Chrome or Edge. (Export HTML still works for saving your data.)",
pickFail: "Failed to pick a file: ",
noBlockInFile: "No sheet-data block found in the selected file.",
brokenJsonAdopt1: "The sheet-data JSON is broken: ",
brokenJsonAdopt2: "\nKeep the current table and only set this file as the save target?",
bootBroken1: "The sheet-data JSON is invalid: ",
bootBroken2: "\nStarting with an empty sheet.",
reloadNoTarget: "No save target yet. Use Save to pick the file first.",
confirmDiscardReload: "You have unsaved edits. Discard them and reload from the file?",
noReadPerm: "No permission to read the file.",
reloadFail: "Failed to reload: ",
checkFileMoved: "\nCheck that the file was not moved or deleted.",
noWritePerm: "No permission to save. Try saving again and allow access.",
saveNoBlock: "Save aborted: no sheet-data block found in the target file.",
confirmNullBaseline: "The current data in the target file could not be read (its JSON may be broken). Overwrite the file with this table?",
confirmConflict: "The data in the target file has changed since it was loaded (possibly edited by an AI agent). Overwrite?\nYou can cancel and use Reload to inspect the file's content.",
saveFail1: "Failed to save: ",
saveFail2: "\nCheck that the file was not moved or deleted. If it moved, drop it onto the page to open it again.",
loadFail: "Failed to read the file: ",
},
ja: {
btnSave: "上書き保存 (Ctrl+S)",
btnReload: "再読み込み",
btnUndo: "元に戻す (Ctrl+Z)",
btnRedo: "やり直し (Ctrl+Y)",
btnAddRow: "行追加",
btnAddCol: "列追加",
btnExport: "エクスポート(HTML / CSV)",
btnHelp: "使い方",
btnLang: "言語(ファイルに保存されます)",
themePrefix: "テーマ: ",
titleEdit: "クリックでタイトルを編集",
noTarget: "保存先未設定",
noTargetTip: "保存を有効にする2つの方法:\n・今開いているファイルをここにD&D\n・保存(Ctrl+S)のときに今開いているファイルを指定\n一度許可すればブラウザが記憶し、次回からはそのまま保存できます。",
target: "保存先: ",
unsaved: " ●未保存",
colMenuTitle: "クリックで列の挿入・削除",
rowMenuTitle: "クリックで行の挿入・削除",
tabTitle: "ダブルクリックで名前変更 / 右クリックでメニュー",
addSheetTitle: "シートを追加",
insRowAbove: "上に行を挿入",
insRowBelow: "下に行を挿入",
delRow: "行を削除",
insColLeft: "左に列を挿入",
insColRight: "右に列を挿入",
delCol: "列を削除",
statsRow: "行 ",
statsCount: "件数",
statsExcluded: "除外(数値以外)",
statsSum: "合計",
statsAvg: "平均",
statsMax: "最大",
statsMin: "最小",
statsNoNumbers: "数値セルがありません",
sheetRename: "名前を変更",
sheetLeft: "左へ移動",
sheetRight: "右へ移動",
sheetDelete: "シートを削除",
exportHtmlItem: "HTML をエクスポート(アプリ+全シート)",
exportCsvItem: "CSV を書き出し(現在のシート)",
langAuto: "Auto(ブラウザの言語)",
toastSaved: "✓ 保存しました: ",
toastLoaded: "読み込みました: ",
toastReloaded: "再読み込みしました: ",
toastCsv: "CSVを書き出しました: ",
toastHtml: "HTMLをエクスポートしました",
toastSaveExported: "直接保存に非対応のブラウザのため、HTMLをダウンロードしました",
lastRow: "最後の行は削除できません",
lastCol: "最後の列は削除できません",
lastSheet: "最後のシートは削除できません",
helpTitle: "使い方",
help1: "タイトルをクリックすると編集できます",
help2: "Enter / Tab / 矢印キー: セル移動(最終行で Enter を押すと行を追加)",
help3: "Alt+Enter: セル内改行",
help4: "Ctrl+S: 上書き保存(初回はダイアログでこのファイル自身を選択。非対応ブラウザではHTMLダウンロードになります)",
help5: "Ctrl+Z / Ctrl+Y: 元に戻す / やり直し",
help6: "行番号・列名をクリック: 行/列の挿入・削除メニュー。ヘッダーと行末のグラフアイコン: クイック統計(ホバーで表示、クリックで固定)",
help7: "シートタブ: クリックで切替、ダブルクリックで名前変更、右クリックでメニュー",
help8: "Excel / Google スプレッドシートからの範囲貼り付けに対応",
help9: "ダウンロードボタン: HTML(アプリ+全シート)または CSV をエクスポート",
help10: "右上のボタンでテーマを選択(47種類 + 自動)",
help11: "タイトル・テーマ・全シートは1つのHTMLファイル内に保存されます",
help12: "HTMLファイルをページにドロップすると開きます(そのファイルが保存先になります)",
dropHint: "ここにドロップして開く",
confirmDropDirty: "未保存の編集があります。破棄してドロップしたファイルを読み込みますか?",
confirmTargetDiffers: "選択したファイルの内容は、この表の読み込み元と異なります。このファイルを保存先にして上書きしますか?",
noFsApi: "このブラウザはFile System Access APIに対応していません。ChromeかEdgeで開いてください。(HTMLエクスポートでの保存は可能です)",
pickFail: "ファイル選択に失敗しました: ",
noBlockInFile: "選択したファイルに sheet-data ブロックが見つかりません。",
brokenJsonAdopt1: "sheet-data のJSONが壊れています: ",
brokenJsonAdopt2: "\n現在の表を保持したまま、このファイルを保存先として設定だけ行いますか?",
bootBroken1: "sheet-data のJSONが不正です: ",
bootBroken2: "\n空の表で開始します。",
reloadNoTarget: "保存先が未設定です。「上書き保存」からファイルを選んでください。",
confirmDiscardReload: "未保存の編集があります。破棄してファイルから読み込み直しますか?",
noReadPerm: "ファイルを読み込む権限がありません。",
reloadFail: "再読み込みに失敗しました: ",
checkFileMoved: "\nファイルが移動・削除されていないか確認してください。",
noWritePerm: "保存する権限がありません。もう一度保存を実行して許可してください。",
saveNoBlock: "保存先ファイルに sheet-data ブロックが見つからないため、保存を中止しました。",
confirmNullBaseline: "保存先ファイルの現在のデータを読み込めていません(JSONが壊れている可能性があります)。ファイルのデータをこの表の内容で上書きしますか?",
confirmConflict: "保存先ファイルのデータが読み込み後に変更されています(AIエージェント等による編集の可能性)。上書きしますか?\nキャンセル後に「再読み込み」でファイル側の内容を確認できます。",
saveFail1: "保存に失敗しました: ",
saveFail2: "\nファイルが移動・削除されていないか確認してください。移動した場合は、ファイルをページにドロップして開き直してください。",
loadFail: "ファイルの読み込みに失敗しました: ",
},
};
function effLang() {
const chosen = typeof doc !== "undefined" && doc ? doc.lang : "auto";
if (chosen === "en" || chosen === "ja") return chosen;
return (navigator.language || "en").toLowerCase().startsWith("ja") ? "ja" : "en";
}
function t(key) {
const lang = effLang();
return (MESSAGES[lang] && MESSAGES[lang][key]) || MESSAGES.en[key] || key;
}
// id で照合するので属性の順序変更や追加には耐える。アプリ本体のソースには
// このパターンに一致するタグ列が現れないよう、生成側はタグを分割して持つ。
const SHEET_DATA_RE = /<script\b[^>]*\bid=["']sheet-data["'][^>]*>([\s\S]*?)<\/script>/;
const OPEN_TAG = '<scr' + 'ipt id="sheet-data" type="application/json">';
const CLOSE_TAG = "<\/script>";
let fileHandle = null;
let dirty = false;
let lastLoadedJson = null;
let undoStack = [];
let redoStack = [];
let activePos = null;
let cellEdited = false;
let toastTimer = null;
let saving = false;
let pinnedStat = null;
let editMode = "plaintext-only";
try {
document.createElement("div").contentEditable = "plaintext-only";
} catch (error) {
editMode = "true";
}
// File System Access API 非対応(スマホ各ブラウザ・Firefox・Safari)では
// ファイルへの直接保存ができないため、保存はHTMLダウンロードへフォールバックする
const FS_SUPPORTED = !!window.showOpenFilePicker;
let doc;
try {
const raw = document.getElementById("sheet-data").textContent.trim();
doc = normalizeDoc(JSON.parse(raw));
lastLoadedJson = raw;
} catch (error) {
alert(t("bootBroken1") + error.message + t("bootBroken2"));
doc = normalizeDoc([[""]]);
}
let data = doc.sheets[doc.activeSheet].data;
function normalizeData(value) {
if (!Array.isArray(value) || value.length === 0) return [[""]];
const rows = value.map(row => (Array.isArray(row) ? row : [row]));
const width = Math.max(1, ...rows.map(row => row.length));
return rows.map(row =>
Array.from({ length: width }, (_, i) => (row[i] == null ? "" : String(row[i])))
);
}
function normalizeDoc(parsed) {
let title = "OneFileSheet";
let theme = "auto";
let lang = "auto";
let activeSheet = 0;
let sheets;
if (Array.isArray(parsed)) {
sheets = [{ name: "Sheet1", data: parsed }];
} else if (parsed && typeof parsed === "object" && Array.isArray(parsed.sheets)) {
if (typeof parsed.title === "string" && parsed.title.trim()) title = parsed.title.trim();
if (parsed.theme === "auto" || THEME_MAP[parsed.theme]) theme = parsed.theme;
if (parsed.lang === "en" || parsed.lang === "ja") lang = parsed.lang;
sheets = parsed.sheets;
activeSheet = parsed.activeSheet;
} else {
throw new Error("not a sheet document");
}
if (sheets.length === 0) sheets = [{ name: "Sheet1", data: [[""]] }];
const normSheets = sheets.map((s, i) => ({
name: s && typeof s.name === "string" && s.name.trim() ? s.name.trim() : "Sheet" + (i + 1),
data: normalizeData(s ? s.data : null),
}));
if (!Number.isInteger(activeSheet) || activeSheet < 0 || activeSheet >= normSheets.length) {
activeSheet = 0;
}
return { title: title, theme: theme, lang: lang, activeSheet: activeSheet, sheets: normSheets };
}
function syncData() {
data = doc.sheets[doc.activeSheet].data;
}
// ---- 仮想スクロール ----
// 大きなシートでも固まらないよう、DOMには可視範囲±OVERSCAN行だけを置く。
// 行の実高さは描画時に計測して控え、スペーサー行で全体の高さを再現する
const ROW_H = 29;
const OVERSCAN = 12;
const COL_MIN = 120;
const COL_MAX = 360;
let rowHeights = [];
let rowEls = new Map();
let vStart = 0;
let vEnd = 0;
let topSpacer = null;
let botSpacer = null;
let dataCols = [];
let colWidths = [];
const measureCtx = document.createElement("canvas").getContext("2d");
function cellFont() {
return "14px " + getComputedStyle(document.body).fontFamily;
}
function textWidth(value) {
let w = 0;
const lines = value.includes("\n") ? value.split("\n") : [value];
for (const line of lines) {
const m = measureCtx.measureText(line).width;
if (m > w) w = m;
}
return w;
}
// 1行の実高と1行あたりの増分を、不可視のプローブ行を実レンダリングして測る。
// CSSからの机上計算はフォント・ズーム・OSごとにズレるため、実測が唯一正確
let probeRowH = ROW_H;
let probeLineH = 19;
function measureProbe() {
const probe = document.createElement("table");
probe.style.cssText = "position:absolute;left:-9999px;top:0;visibility:hidden;border-collapse:separate;border-spacing:0;table-layout:fixed;width:260px";
const makeRow = text => {
const tr = document.createElement("tr");
const head = document.createElement("th");
head.className = "coord row-head";
head.textContent = "888";
tr.appendChild(head);
const td = document.createElement("td");
td.className = "cell";
td.textContent = text;
tr.appendChild(td);
const stat = document.createElement("th");
stat.className = "coord stat-btn stat-row-btn";
stat.innerHTML = STAT_ICON;
tr.appendChild(stat);
return tr;
};
const one = makeRow("x");
const three = makeRow("x\nx\nx");
probe.appendChild(one);
probe.appendChild(three);
probe.appendChild(makeRow("x")); // 最終行は border-bottom が消えるルールの受け皿
document.body.appendChild(probe);
const h1 = one.getBoundingClientRect().height;
const h3 = three.getBoundingClientRect().height;
probe.remove();
if (h1 > 0) probeRowH = h1;
if (h3 > h1) probeLineH = (h3 - h1) / 2;
}
// 列幅と行高の見積もりを全データから一度に算出する(canvas計測なので
// DOMより桁違いに速い)。列幅はスクロールで揺れないようデータ全体を測る。
// 行高は「スクロールバーの長さ・位置」を全行描画なしで実際と一致させる
// ための見積もりで、改行や折り返しを含む行だけ2パス目で行数を数える
function computeLayout() {
measureProbe();
const family = getComputedStyle(document.body).fontFamily;
const widths = new Array(colCount()).fill(0);
const complexRows = [];
const scanRow = r => {
const row = data[r];
let complex = false;
for (let c = 0; c < row.length; c++) {
const v = row[c];
if (!v) continue;
const w = textWidth(v);
if (w > widths[c]) widths[c] = w;
if (w > COL_MAX - 20 || v.includes("\n")) complex = true;
}
if (complex) complexRows.push(r);
};
measureCtx.font = "600 14px " + family;
scanRow(0);
measureCtx.font = "14px " + family;
for (let r = 1; r < data.length; r++) scanRow(r);
const colW = widths.map(w => Math.min(COL_MAX, Math.max(COL_MIN, Math.ceil(w) + 20)));
const heights = new Array(data.length).fill(probeRowH);
for (const r of complexRows) {
measureCtx.font = (r === 0 ? "600 14px " : "14px ") + family;
const row = data[r];
let lines = 1;
for (let c = 0; c < row.length; c++) {
const v = row[c];
if (!v) continue;
const avail = Math.max(24, colW[c] - 14);
let n = 0;
for (const line of v.split("\n")) {
n += Math.max(1, Math.ceil(measureCtx.measureText(line).width / avail));
}
if (n > lines) lines = n;
}
heights[r] = probeRowH + (lines - 1) * probeLineH;
}
return { colW: colW, heights: heights };
}
function rowHeadWidth() {
return String(data.length).length * 8 + 30;
}
function rowTop(r) {
let y = 0;
for (let i = 0; i < r; i++) y += rowHeights[i];
return y;
}
function spacerRow() {
const tr = document.createElement("tr");
tr.className = "v-pad";
const td = document.createElement("td");
td.colSpan = colCount() + 2;
tr.appendChild(td);
return tr;
}
function buildRow(r) {
const row = data[r];
const tr = document.createElement("tr");
const rowHead = document.createElement("th");
rowHead.className = "coord row-head";
rowHead.dataset.r = r;
rowHead.textContent = r + 1;
rowHead.title = t("rowMenuTitle");
rowHead.appendChild(makeHeadStatIcon("row", r));
tr.appendChild(rowHead);
row.forEach((cell, c) => {
const el = document.createElement(r === 0 ? "th" : "td");
el.className = "cell";
el.setAttribute("contenteditable", editMode);
el.dataset.r = r;
el.dataset.c = c;
el.textContent = cell;