Repository navigation
Expand file tree
/
Copy pathProject tracker
More file actions
825 lines (756 loc) · 35.4 KB
/
Copy pathProject tracker
File metadata and controls
825 lines (756 loc) · 35.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Project Tracker — Map</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Archivo:wght@600;800&family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500&display=swap" rel="stylesheet">
<style>
:root{
--ink:#0E1A22; --ink-2:#14242E; --ink-3:#182C38;
--bone:#E8E3D6; --dim:#8A9BA2;
--amber:#F0A23B; --cyan:#63A9A2;
--line:rgba(232,227,214,.14); --line-2:rgba(232,227,214,.06);
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden}
body{
background:var(--ink); color:var(--bone);
font:400 14px/1.5 "IBM Plex Sans",system-ui,sans-serif;
-webkit-font-smoothing:antialiased;
}
button,input{font-family:inherit}
/* ---------- gate ---------- */
.gate{position:fixed;inset:0;z-index:80;display:grid;place-items:center;padding:20px;
background:rgba(14,26,34,.94);backdrop-filter:blur(14px)}
.gate[hidden]{display:none}
.gate-card{width:100%;max-width:420px;background:var(--ink-2);border:1px solid var(--line);
padding:clamp(22px,4vw,34px);position:relative}
.gate-card::after{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--amber)}
.eyebrow{font:500 11px/1 "IBM Plex Mono",monospace;letter-spacing:.16em;text-transform:uppercase;
color:var(--amber);margin:0 0 14px}
.gate-card h1{font:800 clamp(26px,6vw,34px)/1.02 Archivo,sans-serif;letter-spacing:-.02em;margin:0 0 8px}
.gate-card p.sub{color:var(--dim);margin:0 0 22px;font-size:14px}
.field{display:flex;gap:8px}
input{background:var(--ink);color:var(--bone);border:1px solid var(--line);border-radius:0;
padding:10px 12px;font:400 13px/1 "IBM Plex Mono",monospace;letter-spacing:.04em;min-width:0}
input::placeholder{color:#5C6E76}
input:focus-visible{outline:2px solid var(--amber);outline-offset:2px}
.gate-msg{min-height:20px;margin:12px 0 0;font:400 12px/1.4 "IBM Plex Mono",monospace;color:var(--amber)}
.shake{animation:shake .34s}
@keyframes shake{0%,100%{transform:translateX(0)}20%{transform:translateX(-6px)}
45%{transform:translateX(5px)}70%{transform:translateX(-3px)}}
.btn{background:var(--amber);color:#10202A;border:0;border-radius:0;padding:10px 16px;cursor:pointer;
font:500 12px/1 "IBM Plex Mono",monospace;letter-spacing:.1em;text-transform:uppercase}
.btn:hover{filter:brightness(1.08)}
.btn:focus-visible{outline:2px solid var(--bone);outline-offset:2px}
.btn-s{padding:7px 10px;font-size:10px;letter-spacing:.09em}
.ghost{background:transparent;color:var(--dim);border:1px solid var(--line)}
.ghost:hover{border-color:var(--amber);color:var(--amber);filter:none}
/* ---------- chrome ---------- */
.topbar{position:fixed;z-index:20;top:0;left:0;right:0;display:flex;flex-wrap:wrap;
gap:8px 14px;align-items:center;padding:12px 16px;background:linear-gradient(var(--ink) 62%,transparent);
pointer-events:none}
.topbar > *{pointer-events:auto}
.brand{font:800 18px/1 Archivo,sans-serif;letter-spacing:-.02em;margin-right:4px}
.counts{font:400 11px/1 "IBM Plex Mono",monospace;color:var(--dim);letter-spacing:.08em}
.counts b{color:var(--bone);font-weight:500}
.sp{flex:1}
.save{font:400 11px/1 "IBM Plex Mono",monospace;letter-spacing:.06em;color:var(--dim);white-space:nowrap}
.save.warn{color:var(--amber)}
.save::before{content:"";display:inline-block;width:6px;height:6px;border-radius:50%;
background:var(--cyan);margin-right:7px;vertical-align:1px}
.save.warn::before{background:var(--amber)}
.save.busy::before{background:var(--amber);animation:pulse 1s infinite}
@keyframes pulse{50%{opacity:.25}}
.hint{position:fixed;z-index:20;left:16px;bottom:12px;font:400 10.5px/1.7 "IBM Plex Mono",monospace;
color:#5C6E76;letter-spacing:.06em;pointer-events:none}
.zoombar{position:fixed;z-index:20;right:16px;bottom:12px;display:flex;gap:6px}
/* ---------- canvas ---------- */
.stage{position:fixed;inset:0;overflow:hidden;cursor:grab;touch-action:none;
background:
repeating-linear-gradient(to right,var(--line-2) 0 1px,transparent 1px 72px),
repeating-linear-gradient(to bottom,var(--line-2) 0 1px,transparent 1px 72px)}
.stage[hidden]{display:none}
.stage.drag{cursor:grabbing}
.canvas{position:absolute;top:0;left:0;transform-origin:0 0}
.wires{position:absolute;top:0;left:0;overflow:visible;pointer-events:none}
.wire{fill:none;stroke:var(--line);stroke-width:1.5}
.wire.live{stroke:var(--cyan);opacity:.55}
.wire.gone{stroke:var(--line);opacity:.45;stroke-dasharray:3 4}
.node{position:absolute;background:var(--ink-2);border:1px solid var(--line);padding:10px 12px}
.node.root{background:var(--ink-3);border-color:var(--amber);padding:14px 16px;width:190px}
.node.root h2{font:800 20px/1.05 Archivo,sans-serif;letter-spacing:-.02em;margin:0}
.node.root .rootmeta{margin-top:8px;font:400 10.5px/1.7 "IBM Plex Mono",monospace;color:var(--dim);
letter-spacing:.07em}
.node.sec{width:250px;border-left:2px solid var(--dim)}
.node.sec.live{border-left-color:var(--cyan)}
.node.task{width:270px}
.node.task[data-state=active]{border-color:rgba(240,162,59,.45)}
.sec-top{display:flex;align-items:baseline;gap:8px}
.sec-name{font:600 15px/1.25 Archivo,sans-serif;letter-spacing:-.01em;outline:0;flex:1;word-break:break-word}
.sec-name:focus-visible,.title:focus-visible{box-shadow:inset 0 -2px 0 var(--amber)}
.sec-count{font:400 10px/1 "IBM Plex Mono",monospace;color:var(--dim);letter-spacing:.08em;white-space:nowrap}
.sec-tools{display:flex;gap:5px;margin-top:9px;flex-wrap:wrap}
.repo{width:100%;margin-top:8px;padding:6px 8px;font-size:11.5px}
.task-top{display:flex;gap:10px;align-items:flex-start}
.dot{flex:0 0 auto;margin-top:2px;width:18px;height:18px;border-radius:50%;background:transparent;
cursor:pointer;padding:0;border:2px solid var(--dim)}
.dot:focus-visible{outline:2px solid var(--amber);outline-offset:2px}
.node[data-state=active] .dot{border-color:var(--amber);background:var(--amber)}
.node[data-state=done] .dot{border-color:var(--cyan);background:var(--cyan)}
.title{flex:1;font:400 14px/1.4 "IBM Plex Sans",sans-serif;outline:0;word-break:break-word}
.node[data-state=done] .title{color:var(--dim);text-decoration:line-through}
.sub{display:flex;gap:9px;align-items:center;flex-wrap:wrap;margin:6px 0 0 28px}
.status-txt{font:400 10px/1 "IBM Plex Mono",monospace;letter-spacing:.1em;text-transform:uppercase;color:var(--dim)}
.sub a{font:400 10.5px/1 "IBM Plex Mono",monospace;color:var(--cyan);text-decoration:none;
border-bottom:1px solid transparent;letter-spacing:.05em}
.sub a:hover{border-bottom-color:var(--cyan)}
.sub a.guess{color:var(--dim)}
.sub a.guess:hover{color:var(--cyan);border-bottom-color:var(--cyan)}
button.linkbtn{background:transparent;border:0;color:#5C6E76;cursor:pointer;padding:0;
font:400 10.5px/1 "IBM Plex Mono",monospace;letter-spacing:.05em;border-bottom:1px dashed var(--line)}
button.linkbtn:hover{color:var(--amber);border-bottom-color:var(--amber)}
.kill{background:transparent;border:0;color:#5C6E76;cursor:pointer;font:400 16px/1 "IBM Plex Mono",monospace;
padding:0 2px}
.kill:hover{color:var(--amber)}
.linkedit{display:flex;gap:5px;margin:8px 0 0 28px}
.linkedit[hidden]{display:none}
.linkedit input{flex:1;padding:6px 8px;font-size:11.5px}
/* ---------- backup sheet ---------- */
.sheet{position:fixed;inset:0;z-index:70;display:grid;place-items:center;padding:20px;
background:rgba(14,26,34,.9);backdrop-filter:blur(10px)}
.sheet[hidden]{display:none}
.sheet-card{width:100%;max-width:620px;background:var(--ink-2);border:1px solid var(--line);padding:24px;
position:relative}
.sheet-card::after{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--cyan)}
.sheet-card h2{font:800 24px/1 Archivo,sans-serif;letter-spacing:-.02em;margin:0 0 6px}
.sheet-card p{color:var(--dim);margin:0 0 16px;font-size:13px}
textarea{width:100%;height:200px;background:var(--ink);color:var(--bone);border:1px solid var(--line);
padding:10px;font:400 11.5px/1.5 "IBM Plex Mono",monospace;resize:vertical}
textarea:focus-visible{outline:2px solid var(--cyan);outline-offset:2px}
.sheet-tools{display:flex;gap:8px;flex-wrap:wrap;margin-top:14px}
.sheet-msg{margin:12px 0 0;min-height:18px;font:400 11.5px/1.4 "IBM Plex Mono",monospace;color:var(--amber)}
@media (max-width:620px){
.brand{font-size:16px}
.counts{width:100%;order:9}
.hint{display:none}
}
@media (prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}
</style>
</head>
<body>
<div class="gate" id="gate" role="dialog" aria-modal="true" aria-labelledby="gt">
<div class="gate-card" id="gateCard">
<p class="eyebrow">Restricted</p>
<h1 id="gt">Enter password</h1>
<p class="sub">This tracker is private. Enter the password to open it.</p>
<form class="field" id="gateForm" autocomplete="off">
<input type="password" id="pw" placeholder="••••••••" aria-label="Password" style="flex:1">
<button class="btn" type="submit">Unlock</button>
</form>
<p class="gate-msg" id="gateMsg" role="status" aria-live="polite"></p>
</div>
</div>
<div class="stage" id="stage" hidden>
<div class="canvas" id="canvas">
<svg class="wires" id="wires" aria-hidden="true"></svg>
</div>
</div>
<header class="topbar" id="topbar" hidden>
<span class="brand">Project Tracker</span>
<span class="counts"><b id="cActive">0</b> in progress · <b id="cDone">0</b> done · <b id="cTotal">0</b> total</span>
<span class="sp"></span>
<button class="btn btn-s ghost" id="addSec" type="button">+ Branch</button>
<button class="btn btn-s ghost" id="backupBtn" type="button">Backup</button>
<button class="btn btn-s ghost" id="lockBtn" type="button">Lock</button>
<span class="save" id="saveState">Loading…</span>
</header>
<div class="zoombar" id="zoombar" hidden>
<button class="btn btn-s ghost" id="zOut" type="button" aria-label="Zoom out">−</button>
<button class="btn btn-s ghost" id="zIn" type="button" aria-label="Zoom in">+</button>
<button class="btn btn-s ghost" id="zFit" type="button">Fit</button>
</div>
<p class="hint" id="hint" hidden>Drag to pan · scroll to zoom · click a circle to cycle status · click text to rename</p>
<div class="sheet" id="sheet" hidden role="dialog" aria-modal="true" aria-labelledby="bt">
<div class="sheet-card">
<p class="eyebrow" style="color:var(--cyan)">Safety net</p>
<h2 id="bt">Backup</h2>
<p>Everything below is your map as text. Copy it somewhere safe, or paste an older copy in and restore it.</p>
<textarea id="dump" spellcheck="false" aria-label="Map data as JSON"></textarea>
<div class="sheet-tools">
<button class="btn btn-s" id="copyBtn" type="button">Copy</button>
<button class="btn btn-s ghost" id="dlBtn" type="button">Download file</button>
<button class="btn btn-s ghost" id="restoreBtn" type="button">Restore from text</button>
<span class="sp"></span>
<button class="btn btn-s ghost" id="closeSheet" type="button">Close</button>
</div>
<p class="sheet-msg" id="sheetMsg" role="status" aria-live="polite"></p>
</div>
</div>
<script>
(function(){
"use strict";
/* ============ config ============ */
var PASSWORD = "ikram2004";
var KEY = "tracker:v3";
var BAK = "tracker:v3bak";
var OLD = "tracker:v2";
var ORDER = ["todo","active","done"];
var LABEL = {todo:"To do", active:"In progress", done:"Done"};
var SEED = [
{ name:"pi0.5 core", repo:"", items:[
"#4056 RTC training","#4427 piR2 inference","#4426 Vision speedup",
"#4077 Sampling refactor","#4078 Action time embed"] },
{ name:"Infra support", repo:"", items:[
"#3819 ONNX export (ACT)","#3033 Exo serial fixes","#3024 Trim eps (unused)"] },
{ name:"Glove / teleop", repo:"", items:["#1713 3D hand visualizer"] },
{ name:"SONIC / G1 WBC", repo:"", items:[
"#4090 SONIC decoder","#3885 BeyondMimic ctr","#3984 G1 gripper control",
"#4262 Motor gains","#4264 ONNX sim-lag fix","#4267 Onboard controller"] },
{ name:"OpenArm", repo:"", items:["#4269 EE kinematics"] }
];
/* ============ elements ============ */
var $ = function(id){ return document.getElementById(id); };
var gate=$("gate"), gateCard=$("gateCard"), pw=$("pw"), gateMsg=$("gateMsg"),
stage=$("stage"), canvas=$("canvas"), wires=$("wires"), topbar=$("topbar"),
zoombar=$("zoombar"), hint=$("hint"), saveState=$("saveState"),
sheet=$("sheet"), dump=$("dump"), sheetMsg=$("sheetMsg");
/* ============ state ============ */
var data = [];
var ready = false; // true once we know it is safe to write
var canSave = true; // false when storage is unavailable
var dirty = false, saving = false, again = false, rev = 0, lastSaved = null;
var timer = null, retryIn = 2000;
var view = {x:0, y:0, k:1}, fitted = false;
function uid(){ return "x"+Date.now().toString(36)+Math.random().toString(36).slice(2,6); }
function fresh(){
return SEED.map(function(s){
return {id:uid(), name:s.name, repo:s.repo, collapsed:false,
items:s.items.map(function(t){ return {id:uid(), title:t, url:"", state:"todo"}; })};
});
}
function normalise(arr){
if(!Array.isArray(arr)) return null;
var out = arr.map(function(s){
return {
id: s.id || uid(),
name: String(s.name || "Untitled branch"),
repo: String(s.repo || ""),
collapsed: !!s.collapsed,
items: (Array.isArray(s.items) ? s.items : []).map(function(i){
return {id:i.id||uid(), title:String(i.title||"Untitled task"),
url:String(i.url||""), state:ORDER.indexOf(i.state)>=0?i.state:"todo"};
})
};
});
return out;
}
/* ============ status line ============ */
function status(txt, kind){
saveState.textContent = txt;
saveState.className = "save" + (kind ? " "+kind : "");
}
function stamp(){
return new Date().toLocaleTimeString(undefined,{hour:"2-digit",minute:"2-digit"});
}
/* ============ storage ============ */
function get(key){
return new Promise(function(res, rej){
try{ window.storage.get(key).then(res, rej); }catch(e){ rej(e); }
});
}
function load(){
if(!window.storage){
canSave = false; ready = false; data = fresh();
status("Storage unavailable here \u2014 changes won't be kept","warn");
draw(); return;
}
readEnvelope(KEY)
.catch(function(){ return wait(900).then(function(){ return readEnvelope(KEY); }); })
.catch(function(){ return readEnvelope(BAK); })
.catch(function(){ return readLegacy(); })
.then(function(res){
data = res.data; rev = res.rev || 0;
lastSaved = {rev:rev, savedAt:Date.now(), data:JSON.parse(JSON.stringify(data))};
ready = true;
status(res.note || ("Saved "+stamp()));
draw();
if(res.writeNow){ dirty = true; flush(); }
})
.catch(function(){
// Nothing anywhere: start from the seed map and write it once.
data = fresh(); ready = true; status("New map");
draw(); dirty = true; flush();
});
}
function wait(ms){ return new Promise(function(r){ setTimeout(r, ms); }); }
function readEnvelope(key){
return get(key).then(function(r){
var env = JSON.parse(r.value);
var d = normalise(env && env.data);
if(d && d.length) return {data:d, rev:env.rev||0, note:"Loaded"};
var p = env && env.prev && normalise(env.prev.data);
if(p && p.length) return {data:p, rev:env.rev||0, note:"Loaded previous version", writeNow:true};
throw new Error("empty");
});
}
function readLegacy(){
return get(OLD).then(function(r){
var d = normalise(JSON.parse(r.value));
if(!d || !d.length) throw new Error("empty");
return {data:d, rev:0, note:"Brought over from the old list", writeNow:true};
});
}
function markDirty(){
dirty = true;
if(canSave && ready) status("Saving\u2026","busy");
clearTimeout(timer);
timer = setTimeout(flush, 300);
}
function flush(){
clearTimeout(timer);
if(!dirty || !canSave || !ready) return;
if(saving){ again = true; return; }
saving = true;
var snap = JSON.parse(JSON.stringify(data));
dirty = false;
var env = {
v:3, rev:++rev, savedAt:Date.now(), data:snap,
prev: lastSaved ? {rev:lastSaved.rev, savedAt:lastSaved.savedAt, data:lastSaved.data} : null
};
var payload = JSON.stringify(env);
window.storage.set(KEY, payload).then(function(){
lastSaved = {rev:env.rev, savedAt:env.savedAt, data:snap};
retryIn = 2000;
status("Saved "+stamp());
if(env.rev % 5 === 0){ window.storage.set(BAK, payload).catch(function(){}); }
done();
}).catch(function(){
dirty = true; rev--;
status("Save failed \u2014 retrying","warn");
setTimeout(flush, retryIn);
retryIn = Math.min(retryIn*2, 30000);
done();
});
function done(){
saving = false;
if(again){ again = false; flush(); }
}
}
window.addEventListener("pagehide", flush);
document.addEventListener("visibilitychange", function(){ if(document.hidden) flush(); });
window.addEventListener("beforeunload", function(e){
if(dirty && canSave){ e.preventDefault(); e.returnValue = ""; }
});
/* ============ links ============ */
function prNum(t){ var m=/#(\d+)/.exec(t); return m?m[1]:null; }
function cleanRepo(r){
r = (r||"").trim().replace(/^https?:\/\/(www\.)?github\.com\//i,"").replace(/\/+$/,"");
return /^[\w.-]+\/[\w.-]+$/.test(r) ? r : "";
}
function hostOf(u){
try{
var h = new URL(u), p = h.pathname.split("/").filter(Boolean);
if(/github\.com$/i.test(h.hostname) && p.length>=2) return p[0]+"/"+p[1]+(p[3]?" #"+p[3]:"");
return h.hostname.replace(/^www\./,"");
}catch(e){ return "link"; }
}
function resolve(item, repo){
if(item.url) return {href:item.url, label:hostOf(item.url), guess:false};
var r = cleanRepo(repo), n = prNum(item.title);
if(r && n) return {href:"https://github.com/"+r+"/pull/"+n, label:r+" #"+n, guess:true};
return null;
}
/* ============ build + layout ============ */
var SEC_W=250, TASK_W=270, ROOT_W=190;
var GAP_X=90, GAP_TASK=12, GAP_SEC=34, PAD=90;
function mkBtn(txt, role){
var b=document.createElement("button");
b.type="button"; b.className="btn btn-s ghost"; b.setAttribute("data-role",role);
b.textContent=txt; return b;
}
function draw(){
// clear nodes, keep the svg
Array.prototype.slice.call(canvas.querySelectorAll(".node")).forEach(function(n){ n.remove(); });
wires.textContent = "";
var a=0,d=0,t=0;
data.forEach(function(s){ s.items.forEach(function(i){
t++; if(i.state==="active")a++; if(i.state==="done")d++;
});});
$("cActive").textContent=a; $("cDone").textContent=d; $("cTotal").textContent=t;
// root
var root=document.createElement("div");
root.className="node root";
var h2=document.createElement("h2"); h2.textContent="Working file"; root.appendChild(h2);
var rm=document.createElement("div"); rm.className="rootmeta";
rm.textContent = data.length+" branches / "+(t-d)+" open";
root.appendChild(rm);
canvas.appendChild(root);
var built = data.map(function(sec, idx){
var side = (idx % 2 === 0) ? 1 : -1;
var el = buildSection(sec, side);
canvas.appendChild(el);
var tasks = sec.collapsed ? [] : sec.items.map(function(it){
var te = buildTask(it, sec, side);
canvas.appendChild(te);
return {it:it, el:te};
});
return {sec:sec, el:el, side:side, tasks:tasks};
});
layout(root, built);
}
function buildSection(sec, side){
var el=document.createElement("div");
el.className="node sec"; el.setAttribute("data-sid",sec.id);
var open = sec.items.filter(function(i){return i.state!=="done";}).length;
if(open>0) el.classList.add("live");
var top=document.createElement("div"); top.className="sec-top";
var nm=document.createElement("span");
nm.className="sec-name"; nm.contentEditable="true"; nm.setAttribute("role","textbox");
nm.setAttribute("aria-label","Branch name"); nm.setAttribute("data-role","secname");
nm.textContent=sec.name; top.appendChild(nm);
var cnt=document.createElement("span"); cnt.className="sec-count";
cnt.textContent=open+"/"+sec.items.length; top.appendChild(cnt);
el.appendChild(top);
var repo=document.createElement("input");
repo.type="text"; repo.className="repo"; repo.value=sec.repo||"";
repo.placeholder="owner/repo \u2014 links every #number";
repo.setAttribute("aria-label","Repository for this branch");
repo.setAttribute("data-role","repo");
el.appendChild(repo);
var tools=document.createElement("div"); tools.className="sec-tools";
tools.appendChild(mkBtn("+ Task","additem"));
tools.appendChild(mkBtn(sec.collapsed ? "Show "+sec.items.length : "Hide","fold"));
tools.appendChild(mkBtn("Delete","delsec"));
el.appendChild(tools);
el.setAttribute("data-side", side>0?"r":"l");
return el;
}
function buildTask(it, sec, side){
var el=document.createElement("div");
el.className="node task"; el.setAttribute("data-iid",it.id);
el.setAttribute("data-sid",sec.id); el.setAttribute("data-state",it.state);
var top=document.createElement("div"); top.className="task-top";
var dot=document.createElement("button");
dot.type="button"; dot.className="dot"; dot.setAttribute("data-role","dot");
dot.title=LABEL[it.state]; dot.setAttribute("aria-label",LABEL[it.state]+" \u2014 change status");
top.appendChild(dot);
var ti=document.createElement("span");
ti.className="title"; ti.contentEditable="true"; ti.setAttribute("role","textbox");
ti.setAttribute("aria-label","Task name"); ti.setAttribute("data-role","title");
ti.textContent=it.title; top.appendChild(ti);
var k=document.createElement("button");
k.type="button"; k.className="kill"; k.setAttribute("data-role","delitem");
k.setAttribute("aria-label","Delete task"); k.textContent="\u00d7"; top.appendChild(k);
el.appendChild(top);
var sub=document.createElement("div"); sub.className="sub";
var st=document.createElement("span"); st.className="status-txt"; st.textContent=LABEL[it.state];
sub.appendChild(st);
var link=resolve(it, sec.repo);
if(link){
var a=document.createElement("a");
a.href=link.href; a.target="_blank"; a.rel="noopener"; a.textContent=link.label;
if(link.guess) a.className="guess";
sub.appendChild(a);
}
var lb=document.createElement("button");
lb.type="button"; lb.className="linkbtn"; lb.setAttribute("data-role","linkbtn");
lb.textContent = it.url ? "Change link" : (link ? "Set own link" : "Add link");
sub.appendChild(lb);
el.appendChild(sub);
var le=document.createElement("div"); le.className="linkedit"; le.hidden=true;
var lin=document.createElement("input");
lin.type="url"; lin.value=it.url||""; lin.placeholder="https://\u2026";
lin.setAttribute("aria-label","Link for this task"); lin.setAttribute("data-role","linkinput");
le.appendChild(lin);
le.appendChild(mkBtn("Save","savelink"));
if(it.url) le.appendChild(mkBtn("Clear","clearlink"));
el.appendChild(le);
el.setAttribute("data-side", side>0?"r":"l");
return el;
}
function layout(root, built){
var rootH = root.offsetHeight;
var boxes = []; // {el, x, y, w, h}
var edges = []; // {from:box, to:box, side, cls}
var rootBox = {el:root, x:-ROOT_W/2, y:-rootH/2, w:ROOT_W, h:rootH};
boxes.push(rootBox);
[1,-1].forEach(function(side){
var group = built.filter(function(b){ return b.side===side; });
var blocks = group.map(function(b){
var secH = b.el.offsetHeight;
var tasksH = 0;
b.tasks.forEach(function(t,i){ tasksH += t.el.offsetHeight + (i?GAP_TASK:0); });
return {b:b, secH:secH, tasksH:tasksH, h:Math.max(secH, tasksH)};
});
var total = blocks.reduce(function(s,x,i){ return s + x.h + (i?GAP_SEC:0); }, 0);
var cur = -total/2;
blocks.forEach(function(bl){
var b = bl.b;
var secX = side>0 ? (ROOT_W/2 + GAP_X) : -(ROOT_W/2 + GAP_X + SEC_W);
var secCy = cur + bl.h/2;
var secBox = {el:b.el, x:secX, y:secCy - bl.secH/2, w:SEC_W, h:bl.secH};
boxes.push(secBox);
edges.push({from:rootBox, to:secBox, side:side,
cls: b.sec.items.some(function(i){return i.state!=="done";}) ? "live" : "gone"});
var taskX = side>0 ? (secX + SEC_W + GAP_X) : (secX - GAP_X - TASK_W);
var ty = cur + (bl.h - bl.tasksH)/2;
b.tasks.forEach(function(t){
var th = t.el.offsetHeight;
var tb = {el:t.el, x:taskX, y:ty, w:TASK_W, h:th};
boxes.push(tb);
edges.push({from:secBox, to:tb, side:side,
cls: t.it.state==="done" ? "gone" : (t.it.state==="active" ? "live" : "")});
ty += th + GAP_TASK;
});
cur += bl.h + GAP_SEC;
});
});
var minX=1e9,minY=1e9,maxX=-1e9,maxY=-1e9;
boxes.forEach(function(b){
minX=Math.min(minX,b.x); minY=Math.min(minY,b.y);
maxX=Math.max(maxX,b.x+b.w); maxY=Math.max(maxY,b.y+b.h);
});
var ox = -minX + PAD, oy = -minY + PAD;
var W = (maxX-minX) + PAD*2, H = (maxY-minY) + PAD*2;
boxes.forEach(function(b){
b.px = b.x+ox; b.py = b.y+oy;
b.el.style.left = b.px+"px";
b.el.style.top = b.py+"px";
});
canvas.style.width = W+"px";
canvas.style.height = H+"px";
wires.setAttribute("width", W);
wires.setAttribute("height", H);
wires.setAttribute("viewBox","0 0 "+W+" "+H);
edges.forEach(function(e){
var x1 = e.side>0 ? e.from.px + e.from.w : e.from.px;
var y1 = e.from.py + e.from.h/2;
var x2 = e.side>0 ? e.to.px : e.to.px + e.to.w;
var y2 = e.to.py + e.to.h/2;
var dx = Math.max(28, Math.abs(x2-x1)*0.45) * (e.side>0?1:-1);
var p = document.createElementNS("http://www.w3.org/2000/svg","path");
p.setAttribute("class","wire"+(e.cls?" "+e.cls:""));
p.setAttribute("d","M"+x1+","+y1+" C"+(x1+dx)+","+y1+" "+(x2-dx)+","+y2+" "+x2+","+y2);
wires.appendChild(p);
});
if(!fitted){ fitted = true; fit(W,H); } else { applyView(); }
lastSize = {W:W, H:H};
}
var lastSize = {W:1200, H:800};
/* ============ view transform ============ */
function applyView(){
canvas.style.transform = "translate("+view.x+"px,"+view.y+"px) scale("+view.k+")";
}
function fit(W,H){
W = W || lastSize.W; H = H || lastSize.H;
var vw = stage.clientWidth, vh = stage.clientHeight;
var k = Math.min(1, (vw-24)/W, (vh-24)/H);
view.k = Math.max(0.2, k);
view.x = (vw - W*view.k)/2;
view.y = (vh - H*view.k)/2;
applyView();
}
function zoomAt(cx, cy, factor){
var k2 = Math.min(2.4, Math.max(0.18, view.k*factor));
view.x = cx - (cx - view.x) * (k2/view.k);
view.y = cy - (cy - view.y) * (k2/view.k);
view.k = k2; applyView();
}
var panning=false, pid=null, sx=0, sy=0, ox0=0, oy0=0;
var pts = {};
stage.addEventListener("pointerdown", function(e){
pts[e.pointerId] = {x:e.clientX, y:e.clientY};
if(e.target.closest(".node")) return;
if(Object.keys(pts).length > 1) return;
panning=true; pid=e.pointerId; sx=e.clientX; sy=e.clientY; ox0=view.x; oy0=view.y;
stage.classList.add("drag"); stage.setPointerCapture(e.pointerId);
});
stage.addEventListener("pointermove", function(e){
if(!pts[e.pointerId]) return;
var ids = Object.keys(pts);
if(ids.length === 2){
var before = dist(pts[ids[0]], pts[ids[1]]);
pts[e.pointerId] = {x:e.clientX, y:e.clientY};
var after = dist(pts[ids[0]], pts[ids[1]]);
var mx = (pts[ids[0]].x + pts[ids[1]].x)/2, my = (pts[ids[0]].y + pts[ids[1]].y)/2;
if(before>0) zoomAt(mx, my, after/before);
return;
}
pts[e.pointerId] = {x:e.clientX, y:e.clientY};
if(!panning || e.pointerId!==pid) return;
view.x = ox0 + (e.clientX - sx);
view.y = oy0 + (e.clientY - sy);
applyView();
});
function dist(a,b){ return Math.hypot(a.x-b.x, a.y-b.y); }
function endPointer(e){
delete pts[e.pointerId];
if(e.pointerId===pid){ panning=false; stage.classList.remove("drag"); }
}
stage.addEventListener("pointerup", endPointer);
stage.addEventListener("pointercancel", endPointer);
stage.addEventListener("wheel", function(e){
e.preventDefault();
zoomAt(e.clientX, e.clientY, e.deltaY < 0 ? 1.12 : 1/1.12);
}, {passive:false});
window.addEventListener("resize", function(){ if(fitted) applyView(); });
$("zIn").addEventListener("click", function(){ zoomAt(stage.clientWidth/2, stage.clientHeight/2, 1.2); });
$("zOut").addEventListener("click", function(){ zoomAt(stage.clientWidth/2, stage.clientHeight/2, 1/1.2); });
$("zFit").addEventListener("click", function(){ fit(); });
/* ============ editing ============ */
function findSec(el){
var n = el.closest("[data-sid]"); if(!n) return null;
var id = n.getAttribute("data-sid");
return data.find(function(s){ return s.id===id; });
}
function findItem(el, sec){
var n = el.closest("[data-iid]"); if(!n||!sec) return null;
var id = n.getAttribute("data-iid");
return sec.items.find(function(i){ return i.id===id; });
}
function change(){ markDirty(); draw(); }
canvas.addEventListener("click", function(e){
var role = e.target.getAttribute && e.target.getAttribute("data-role");
if(!role) return;
var sec = findSec(e.target); if(!sec) return;
if(role==="additem"){
sec.items.push({id:uid(), title:"New task", url:"", state:"todo"});
sec.collapsed = false;
change();
var last = canvas.querySelector('[data-sid="'+sec.id+'"][data-iid] .title:last-of-type');
var all = canvas.querySelectorAll('.task[data-sid="'+sec.id+'"] .title');
var el = all[all.length-1];
if(el){ el.focus(); try{ document.getSelection().selectAllChildren(el); }catch(err){} }
return;
}
if(role==="fold"){ sec.collapsed = !sec.collapsed; change(); return; }
if(role==="delsec"){
if(!confirm('Delete the branch "'+sec.name+'" and its '+sec.items.length+' task(s)?')) return;
data = data.filter(function(s){ return s.id!==sec.id; }); change(); return;
}
var it = findItem(e.target, sec);
if(role==="dot" && it){
it.state = ORDER[(ORDER.indexOf(it.state)+1) % ORDER.length]; change(); return;
}
if(role==="delitem" && it){
sec.items = sec.items.filter(function(x){ return x.id!==it.id; }); change(); return;
}
if(role==="linkbtn" && it){
var le = e.target.closest(".node").querySelector(".linkedit");
le.hidden = !le.hidden;
if(!le.hidden) le.querySelector("input").focus();
return;
}
if(role==="savelink" && it){
var v = e.target.closest(".linkedit").querySelector("input").value.trim();
if(v && !/^https?:\/\//i.test(v)) v = "https://"+v;
it.url = v; change(); return;
}
if(role==="clearlink" && it){ it.url=""; change(); return; }
});
canvas.addEventListener("blur", function(e){
var role = e.target.getAttribute && e.target.getAttribute("data-role");
if(role!=="secname" && role!=="title") return;
var sec = findSec(e.target); if(!sec) return;
if(role==="secname"){
var v = e.target.textContent.trim();
if(v && v!==sec.name){ sec.name = v; change(); }
else if(!v){ e.target.textContent = sec.name; }
return;
}
var it = findItem(e.target, sec); if(!it) return;
var tv = e.target.textContent.trim();
if(tv && tv!==it.title){ it.title = tv; change(); }
else if(!tv){ e.target.textContent = it.title; }
}, true);
canvas.addEventListener("change", function(e){
if(!e.target.getAttribute || e.target.getAttribute("data-role")!=="repo") return;
var sec = findSec(e.target); if(!sec) return;
var v = e.target.value.trim();
if(v !== sec.repo){ sec.repo = v; change(); }
});
canvas.addEventListener("keydown", function(e){
var role = e.target.getAttribute && e.target.getAttribute("data-role");
if(e.key!=="Enter" || !role) return;
if(role==="title"||role==="secname"||role==="repo"){ e.preventDefault(); e.target.blur(); }
if(role==="linkinput"){
e.preventDefault();
var b = e.target.parentNode.querySelector('[data-role=savelink]');
if(b) b.click();
}
});
$("addSec").addEventListener("click", function(){
data.push({id:uid(), name:"New branch", repo:"", collapsed:false, items:[]});
change();
});
/* ============ backup sheet ============ */
function openSheet(){
dump.value = JSON.stringify({v:3, savedAt:Date.now(), data:data}, null, 2);
sheetMsg.textContent = "";
sheet.hidden = false;
dump.focus();
}
$("backupBtn").addEventListener("click", openSheet);
$("closeSheet").addEventListener("click", function(){ sheet.hidden = true; });
$("copyBtn").addEventListener("click", function(){
dump.select();
var ok = false;
try{ ok = document.execCommand("copy"); }catch(e){}
if(!ok && navigator.clipboard){
navigator.clipboard.writeText(dump.value).then(function(){ sheetMsg.textContent="Copied."; },
function(){ sheetMsg.textContent="Couldn't copy \u2014 select the text and copy manually."; });
return;
}
sheetMsg.textContent = ok ? "Copied." : "Couldn't copy \u2014 select the text and copy manually.";
});
$("dlBtn").addEventListener("click", function(){
try{
var blob = new Blob([dump.value], {type:"application/json"});
var a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "tracker-"+new Date().toISOString().slice(0,10)+".json";
document.body.appendChild(a); a.click(); a.remove();
setTimeout(function(){ URL.revokeObjectURL(a.href); }, 2000);
sheetMsg.textContent = "File sent to your downloads.";
}catch(e){ sheetMsg.textContent = "Download blocked here \u2014 copy the text instead."; }
});
$("restoreBtn").addEventListener("click", function(){
var parsed;
try{ parsed = JSON.parse(dump.value); }
catch(e){ sheetMsg.textContent = "That isn't valid JSON. Paste a full backup."; return; }
var d = normalise(parsed && parsed.data ? parsed.data : parsed);
if(!d || !d.length){ sheetMsg.textContent = "No branches found in that text."; return; }
if(!confirm("Replace the current map with this backup? The version you're replacing stays recoverable as the previous save.")) return;
data = d; sheet.hidden = true; change();
});
document.addEventListener("keydown", function(e){
if(e.key==="Escape" && !sheet.hidden) sheet.hidden = true;
});
/* ============ gate ============ */
$("gateForm").addEventListener("submit", function(e){
e.preventDefault();
if(pw.value === PASSWORD){
gate.hidden = true;
stage.hidden = false; topbar.hidden = false; zoombar.hidden = false; hint.hidden = false;
load();
}else{
gateMsg.textContent = "That password isn't right. Try again.";
gateCard.classList.remove("shake"); void gateCard.offsetWidth; gateCard.classList.add("shake");
pw.select();
}
});
$("lockBtn").addEventListener("click", function(){
flush();
stage.hidden = true; topbar.hidden = true; zoombar.hidden = true; hint.hidden = true;
sheet.hidden = true;
gate.hidden = false; pw.value = ""; gateMsg.textContent = ""; pw.focus();
});
pw.focus();
})();
</script>
</body>
</html>