-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_unified.html
More file actions
751 lines (733 loc) · 29.4 KB
/
graph_unified.html
File metadata and controls
751 lines (733 loc) · 29.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Spellbook + Stars — unified</title>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="./readme_render.js"></script>
<style>
:root {
--bg: #0f0f1a; --bg2: #1a1a2e; --border: #2a2a4e; --text: #e0e0e0; --text2: #ccc; --muted: #888; --accent: #2563eb;
--hover: rgba(255, 255, 255, 0.06);
--detail-open: min(520px, 46vw);
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; }
.layout { display: flex; height: 100vh; min-height: 0; max-height: 100vh; overflow: hidden; }
/* Left hideaway: view switcher */
.view-dock {
flex-shrink: 0;
display: flex;
flex-direction: row;
align-items: stretch;
min-height: 0;
background: var(--bg2);
border-right: none;
position: relative;
overflow: visible;
}
.view-dock-inner {
overflow: hidden;
transition: width 0.2s ease, min-width 0.2s ease, opacity 0.15s ease;
min-width: 0;
}
.view-dock.expanded .view-dock-inner {
width: min(152px, 22vw);
min-width: min(152px, 22vw);
opacity: 1;
border-right: 1px solid var(--border);
}
.view-dock.collapsed .view-dock-inner {
width: 0;
min-width: 0;
opacity: 0;
pointer-events: none;
border-right: none;
}
.tabs {
display: flex;
flex-direction: column;
gap: 8px;
padding: 10px 8px;
height: 100%;
border-right: none;
}
.dock-tools {
margin-top: 8px;
border-top: 1px solid var(--border);
padding-top: 8px;
display: flex;
flex-direction: column;
gap: 6px;
min-height: 0;
}
.dock-tools .title { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.dock-tools label { font-size: 10px; color: var(--text2); display: flex; align-items: center; gap: 5px; }
.dock-tools .row { display: flex; gap: 6px; }
.dock-tools .row button {
flex: 1;
padding: 4px 5px;
border-radius: 6px;
border: 1px solid var(--border);
background: #1a1a2e;
color: var(--text2);
font-size: 9px;
cursor: pointer;
}
.dock-tools .status { font-size: 9px; color: var(--muted); min-height: 1.2em; }
.dock-groups {
max-height: 34vh;
overflow-y: auto;
border: 1px solid var(--border);
border-radius: 8px;
padding: 6px;
background: rgba(15,15,26,0.55);
font-size: 9px;
}
.dock-group-item {
width: 100%;
display: flex;
align-items: center;
gap: 6px;
border: none;
background: transparent;
color: var(--text2);
padding: 3px 2px;
border-radius: 4px;
cursor: pointer;
text-align: left;
font-size: 9px;
}
.dock-group-item:hover { background: var(--hover); }
.dock-group-item .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dock-group-item .nm { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dock-group-item .ct { color: var(--muted); }
.tabs button {
width: 100%;
padding: 8px 8px;
border-radius: 8px;
border: 1px solid var(--border);
background: #2a2a4e;
color: var(--text);
font-size: 11px;
cursor: pointer;
text-align: center;
line-height: 1.25;
}
.tabs button[aria-selected="true"] {
background: var(--accent);
border-color: var(--accent);
color: #fff;
font-weight: 600;
}
.dock-toggle {
width: 20px;
height: 44px;
border: 1px solid var(--border);
background: var(--bg2);
color: var(--muted);
cursor: pointer;
font-size: 16px;
line-height: 1;
transition: background 0.15s, color 0.15s, border-color 0.15s;
user-select: none;
display: flex;
align-items: center;
justify-content: center;
}
.dock-toggle:hover { background: #252540; color: var(--text); border-color: #3a3a5e; }
/* Right hideaway: spellbook + README (mirror of left dock) */
.detail-dock {
flex-shrink: 0;
display: flex;
flex-direction: row;
align-items: stretch;
min-height: 0;
max-height: 100%;
align-self: stretch;
background: var(--bg2);
border-left: 1px solid var(--border);
}
.detail-dock-inner {
display: flex;
flex-direction: column;
min-height: 0;
min-width: 0;
overflow: hidden;
transition: width 0.2s ease, min-width 0.2s ease, opacity 0.15s ease;
background: var(--bg2);
}
.detail-dock.expanded .detail-dock-inner {
width: var(--detail-open);
min-width: var(--detail-open);
opacity: 1;
}
.detail-dock.collapsed .detail-dock-inner {
width: 0;
min-width: 0;
opacity: 0;
pointer-events: none;
}
#dock-toggle {
position: absolute;
top: 50%;
right: -20px;
transform: translateY(-50%);
z-index: 40;
border-left: none;
border-radius: 0 6px 6px 0;
margin-right: 0;
}
#detail-toggle {
border-right: none;
border-radius: 6px 0 0 6px;
margin-left: 0;
position: fixed;
top: 50%;
transform: translateY(-50%);
right: 0;
z-index: 40;
}
.graph-slot { flex: 1; min-width: 0; position: relative; background: var(--bg); }
.graph-slot iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; display: none; }
.graph-slot iframe.on { display: block; }
.panel {
flex: 1 1 auto;
min-height: 0;
overflow-x: hidden;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
overscroll-behavior: contain;
padding: 12px 14px;
font-size: 12px;
line-height: 1.45;
width: 100%;
max-width: none;
}
.panel h2 { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }
.panel a { color: #60a5fa; word-break: break-word; }
#spell-hint { color: var(--muted); font-size: 11px; }
#star-detail { display: none; }
#star-detail.on { display: block; }
#star-head { margin-bottom: 10px; }
#star-readme {
font-size: 12px; color: #ccc; width: 100%; min-width: 0; max-width: none;
overflow-wrap: anywhere;
}
#star-readme.readme-prose { max-width: none; width: 100%; }
/* README HTML often ships max-width / centered columns — fill the panel */
#star-readme.readme-prose > * { max-width: 100% !important; }
#star-readme.readme-prose div[style*="max-width"],
#star-readme.readme-prose article,
#star-readme.readme-prose section {
max-width: 100% !important;
width: 100% !important;
margin-left: 0 !important;
margin-right: 0 !important;
box-sizing: border-box;
}
#star-readme pre, #star-readme code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }
#star-readme pre { overflow-x: auto; max-width: 100%; }
#star-readme h1 { font-size: 15px; margin: 0.5em 0 0.25em; color: #f0f0f0; }
#star-readme h2, #star-readme h3 { font-size: 13px; margin: 0.6em 0 0.25em; color: #e8e8e8; }
#star-readme p { margin: 0.45em 0; max-width: none; }
#star-readme img { max-width: 100% !important; height: auto !important; }
#star-readme table { display: block; overflow-x: auto; max-width: 100%; }
#star-readme ul, #star-readme ol { padding-left: 1.2em; margin: 0.35em 0; }
.loading { color: var(--muted); }
.star-detail-grid {
display: grid;
grid-template-columns: 1fr min(220px, 34vw);
gap: 0;
min-height: 0;
align-items: stretch;
}
.star-detail-main { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.star-communities {
border-left: 1px solid var(--border);
padding: 10px 12px;
overflow-y: auto;
font-size: 11px;
color: var(--text2);
min-height: 0;
}
.star-communities h2 { margin-top: 0; }
.star-comm-hint { color: var(--muted); font-size: 10px; line-height: 1.35; margin-bottom: 8px; }
.star-communities input, .star-communities textarea {
width: 100%; margin: 4px 0; padding: 5px 7px; border-radius: 6px;
border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 11px;
}
.star-communities textarea { min-height: 52px; resize: vertical; font-family: inherit; }
.star-communities button {
margin: 4px 4px 4px 0; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border);
background: var(--bg2); color: var(--text2); cursor: pointer; font-size: 11px;
}
.star-communities button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.star-comm-row {
display: flex; align-items: center; justify-content: space-between; gap: 6px;
padding: 5px 0; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 11px;
}
.star-comm-row:hover { background: var(--hover); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 4px; }
.star-comm-row .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.star-comm-row small { color: var(--muted); display: block; font-size: 9px; margin-top: 2px; word-break: break-word; }
.layout.spell-mode #detail-dock { display: none !important; }
.star-filter-bar {
display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 12px;
padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 11px;
}
.star-filter-bar label { color: var(--muted); margin-right: 4px; }
.star-filter-bar input { flex: 1; min-width: 140px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); font-size: 12px; }
.star-filter-bar button { padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text2); cursor: pointer; font-size: 11px; }
.star-filter-bar button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
</style>
</head>
<body>
<div class="layout spell-mode">
<div id="view-dock" class="view-dock expanded" aria-label="Graph view switcher">
<div class="view-dock-inner">
<div class="tabs" role="tablist" aria-label="Graph view">
<button type="button" id="tab-spell" role="tab" aria-selected="true" aria-controls="panel">Spellbook map</button>
<button type="button" id="tab-stars" role="tab" aria-selected="false" aria-controls="panel">Stars nebula</button>
<button type="button" id="unified-reload-iframes" title="Reload both graphs (after refresh_graphs_from_github.sh or disk edits)">Reload graphs</button>
<button type="button" id="unified-export-links" title="Export custom links from both graphs">Export links</button>
<div id="dock-tools" class="dock-tools">
<div class="title">Link mode</div>
<label><input type="checkbox" id="dock-link-mode"/> Link mode</label>
<div id="dock-link-status" class="status">Off</div>
<div class="row">
<button type="button" id="dock-link-cancel">Cancel</button>
<button type="button" id="dock-link-clear">Clear</button>
</div>
<div class="title">Communities</div>
<div id="dock-groups" class="dock-groups"></div>
</div>
</div>
</div>
<button type="button" id="dock-toggle" class="dock-toggle" aria-expanded="true" title="Hide view switcher">‹</button>
</div>
<div class="graph-slot">
<iframe id="if-spell" class="on" title="Spellbook graph" src="./graph.html?embed=1"></iframe>
<iframe id="if-stars" title="Stars nebula" src="./github_stars_mirror.html?embed=1"></iframe>
</div>
<div id="detail-dock" class="detail-dock expanded" aria-label="Details panel">
<button type="button" id="detail-toggle" class="dock-toggle" aria-expanded="true" title="Hide details panel">›</button>
<div class="detail-dock-inner">
<div class="panel" id="panel">
<div id="spell-pane">
<h2>Spellbook</h2>
<p id="spell-hint">Use the graph sidebar for search and communities. <strong>Stars nebula</strong> pulls your public starred repos from GitHub on every refresh (optional: set <code>localStorage SPELLBOOK_GH_TOKEN</code> for higher rate limits). To refresh the Spellbook map files on disk, run <code>refresh_graphs_from_github.sh</code> in this folder.</p>
<div id="rebuild-health" style="margin-top:10px;padding:8px 10px;border:1px solid var(--border);border-radius:8px;background:var(--bg);font-size:11px;color:var(--text2)">
<div style="font-size:10px;color:var(--muted);text-transform:uppercase;letter-spacing:0.05em;margin-bottom:4px">Rebuild health</div>
<div id="health-spell">Spellbook: waiting…</div>
<div id="health-stars">Stars: waiting…</div>
</div>
</div>
<div id="star-detail">
<div class="star-detail-main">
<h2>Selected repo</h2>
<div class="star-filter-bar" aria-label="Highlight repos in nebula">
<label for="star-highlight-kws">Highlight</label>
<input type="text" id="star-highlight-kws" placeholder="Keywords: openclaw, mcp, karpathy…" autocomplete="off"/>
<button type="button" class="primary" id="star-highlight-go">Apply</button>
<button type="button" id="star-highlight-clear">Clear</button>
</div>
<div id="star-head" class="loading">Click a colored node in the nebula…</div>
<div id="star-readme"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
(function () {
function escapeHtml(s) {
const d = document.createElement('div');
d.textContent = s == null ? '' : String(s);
return d.innerHTML;
}
const DOCK_KEY = 'graphUnifiedDockExpanded';
const DETAIL_KEY = 'graphUnifiedDetailExpanded';
const TAB_KEY = 'graphUnifiedActiveTab';
const STARS_DETAIL_KEY = 'graphUnifiedStarsDetailExpanded';
const STAR_HIGHLIGHT_KEY = 'spellbookStarsLastHighlight';
const SPELL_LINKS_KEY = 'spellbookCustomLinks_v1';
const STARS_LINKS_KEY = 'starsCustomLinks_v1';
const healthSpell = document.getElementById('health-spell');
const healthStars = document.getElementById('health-stars');
const __readmeCache = new Map();
let __readmeReqSeq = 0;
const layoutRoot = document.querySelector('.layout');
const ifSpell = document.getElementById('if-spell');
const ifStars = document.getElementById('if-stars');
const tabSpell = document.getElementById('tab-spell');
const tabStars = document.getElementById('tab-stars');
const spellPane = document.getElementById('spell-pane');
const starDetail = document.getElementById('star-detail');
const starHead = document.getElementById('star-head');
const starReadme = document.getElementById('star-readme');
const starHighlightKws = document.getElementById('star-highlight-kws');
const viewDock = document.getElementById('view-dock');
const dockToggle = document.getElementById('dock-toggle');
const detailDock = document.getElementById('detail-dock');
const detailToggle = document.getElementById('detail-toggle');
const dockLinkMode = document.getElementById('dock-link-mode');
const dockLinkStatus = document.getElementById('dock-link-status');
const dockGroups = document.getElementById('dock-groups');
function postStarsShuffle() {
// Disabled: avoid heavy lag / magnetic jump-back on large star graphs.
}
function postStarsRefit() {
try {
if (ifStars.contentWindow) ifStars.contentWindow.postMessage({ type: 'stars-refit' }, '*');
} catch (e) {}
}
function setHealthLine(el, text) {
if (el) el.textContent = text;
}
function activeFrame() {
return tabStars.getAttribute('aria-selected') === 'true' ? ifStars : ifSpell;
}
function postToActive(type, extra) {
try {
var frm = activeFrame();
if (frm && frm.contentWindow) frm.contentWindow.postMessage(Object.assign({ type: type }, extra || {}), '*');
} catch (e) {}
}
function renderDockGroups(rows, kind) {
if (!dockGroups) return;
dockGroups.innerHTML = '';
if (!rows || !rows.length) {
dockGroups.innerHTML = '<div style="color:var(--muted)">No items</div>';
return;
}
rows.forEach(function (r) {
var b = document.createElement('button');
b.type = 'button';
b.className = 'dock-group-item';
b.innerHTML = '<span class="dot" style="background:' + (r.color || '#666') + '"></span>' +
'<span class="nm">' + (r.label || r.id || 'item') + '</span>' +
'<span class="ct">' + (r.count || 0) + '</span>';
b.addEventListener('click', function () {
if (kind === 'stars') postToActive('stars-group-focus', { group: r.id || '' });
if (kind === 'spell') postToActive('spell-community-focus', { cid: r.cid });
});
dockGroups.appendChild(b);
});
}
function downloadJson(filename, data) {
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
}
function setDockExpanded(expanded) {
viewDock.classList.toggle('expanded', expanded);
viewDock.classList.toggle('collapsed', !expanded);
dockToggle.setAttribute('aria-expanded', expanded ? 'true' : 'false');
dockToggle.textContent = expanded ? '‹' : '›';
dockToggle.title = expanded ? 'Hide view switcher' : 'Show view switcher';
try { localStorage.setItem(DOCK_KEY, expanded ? '1' : '0'); } catch (e) {}
}
function setDetailExpanded(expanded) {
detailDock.classList.toggle('expanded', expanded);
detailDock.classList.toggle('collapsed', !expanded);
detailToggle.setAttribute('aria-expanded', expanded ? 'true' : 'false');
detailToggle.textContent = expanded ? '›' : '‹';
detailToggle.title = expanded ? 'Hide details panel' : 'Show details panel';
detailToggle.style.right = expanded ? 'var(--detail-open)' : '0px';
try {
localStorage.setItem(DETAIL_KEY, expanded ? '1' : '0');
} catch (e) {}
}
try {
if (localStorage.getItem(DOCK_KEY) === '0') setDockExpanded(false);
} catch (e) {}
dockToggle.addEventListener('click', function () {
setDockExpanded(!viewDock.classList.contains('expanded'));
});
if (dockLinkMode) {
dockLinkMode.addEventListener('change', function () {
postToActive('link-mode-set', { enabled: !!dockLinkMode.checked });
if (dockLinkStatus) dockLinkStatus.textContent = dockLinkMode.checked ? 'Pick first…' : 'Off';
});
}
var dockCancel = document.getElementById('dock-link-cancel');
if (dockCancel) dockCancel.addEventListener('click', function () { postToActive('link-mode-cancel'); });
var dockClear = document.getElementById('dock-link-clear');
if (dockClear) dockClear.addEventListener('click', function () { postToActive('link-mode-clear'); });
detailToggle.addEventListener('click', function () {
const next = !detailDock.classList.contains('expanded');
setDetailExpanded(next);
try {
if (tabStars.getAttribute('aria-selected') === 'true') {
localStorage.setItem(STARS_DETAIL_KEY, next ? '1' : '0');
}
} catch (e) {}
});
function postStarHighlightFromInput() {
var raw = (starHighlightKws && starHighlightKws.value || '').trim();
try {
localStorage.setItem(STAR_HIGHLIGHT_KEY, raw);
} catch (e) {}
var parts = raw.split(',').map(function (s) { return s.trim(); }).filter(Boolean);
try {
if (ifStars.contentWindow) {
if (parts.length) {
ifStars.contentWindow.postMessage({ type: 'stars-community-apply', keywords: parts }, '*');
} else {
ifStars.contentWindow.postMessage({ type: 'stars-community-clear' }, '*');
}
}
} catch (e2) {}
}
document.getElementById('star-highlight-go').addEventListener('click', postStarHighlightFromInput);
document.getElementById('star-highlight-clear').addEventListener('click', function () {
if (starHighlightKws) starHighlightKws.value = '';
try {
localStorage.removeItem(STAR_HIGHLIGHT_KEY);
} catch (e) {}
try {
if (ifStars.contentWindow) ifStars.contentWindow.postMessage({ type: 'stars-community-clear' }, '*');
} catch (e2) {}
postStarsRefit();
});
if (starHighlightKws) {
starHighlightKws.addEventListener('keydown', function (ev) {
if (ev.key === 'Enter') {
ev.preventDefault();
postStarHighlightFromInput();
}
});
}
function setView(which) {
const stars = which === 'stars';
if (layoutRoot) {
layoutRoot.classList.toggle('spell-mode', !stars);
layoutRoot.classList.toggle('stars-mode', stars);
}
tabSpell.setAttribute('aria-selected', !stars);
tabStars.setAttribute('aria-selected', stars);
ifSpell.classList.toggle('on', !stars);
ifStars.classList.toggle('on', stars);
spellPane.style.display = stars ? 'none' : 'block';
starDetail.classList.toggle('on', stars);
try {
sessionStorage.setItem(TAB_KEY, stars ? 'stars' : 'spell');
} catch (e) {}
if (stars) {
var dOpen = true;
try {
dOpen = localStorage.getItem(STARS_DETAIL_KEY) !== '0';
} catch (e2) {}
setDetailExpanded(dOpen);
try {
if (ifStars.contentWindow) ifStars.contentWindow.postMessage({ type: 'stars-reset-view' }, '*');
} catch (e3) {}
postStarsRefit();
setTimeout(postStarHighlightFromInput, 120);
postToActive('request-groups');
} else {
setDetailExpanded(false);
postToActive('request-groups');
}
}
tabSpell.addEventListener('click', function () { setView('spell'); });
tabStars.addEventListener('click', function () { setView('stars'); });
ifStars.addEventListener('load', function () {
try {
if (sessionStorage.getItem(TAB_KEY) === 'stars') {
postStarsRefit();
}
} catch (e) {}
setTimeout(function () {
try {
var raw = localStorage.getItem(STAR_HIGHLIGHT_KEY) || '';
if (starHighlightKws && raw.trim()) {
starHighlightKws.value = raw;
postStarHighlightFromInput();
}
} catch (e2) {}
}, 220);
});
var reloadIfr = document.getElementById('unified-reload-iframes');
if (reloadIfr) {
reloadIfr.addEventListener('click', function () {
var spellBase = './graph.html';
try {
spellBase = (ifSpell.getAttribute('src') || spellBase).replace(/[?#].*$/, '');
} catch (e) {}
ifSpell.src = spellBase + '?embed=1&t=' + Date.now();
var starsBase = './github_stars_mirror.html';
try {
starsBase = (ifStars.getAttribute('src') || starsBase).replace(/[?#].*$/, '');
} catch (e2) {}
var starsNext = starsBase + '?embed=1&t=' + Date.now();
try {
var um = String(ifStars.src || '').match(/[?&]user=([^&]+)/);
if (um) starsNext += '&user=' + um[1];
} catch (e3) {}
ifStars.src = starsNext;
});
}
var exportLinksBtn = document.getElementById('unified-export-links');
if (exportLinksBtn) {
exportLinksBtn.addEventListener('click', function () {
var spell = [];
var stars = [];
try { spell = JSON.parse(localStorage.getItem(SPELL_LINKS_KEY) || '[]'); } catch (e) {}
try { stars = JSON.parse(localStorage.getItem(STARS_LINKS_KEY) || '[]'); } catch (e2) {}
downloadJson('graph-custom-links.json', {
exported_at: new Date().toISOString(),
spellbook_links: spell,
stars_links: stars
});
});
}
window.addEventListener('keydown', function (ev) {
if (ev.target && (ev.target.tagName === 'INPUT' || ev.target.tagName === 'TEXTAREA' || ev.target.isContentEditable)) return;
if (ev.key === '1') { ev.preventDefault(); setView('spell'); }
if (ev.key === '2') { ev.preventDefault(); setView('stars'); }
if (tabStars.getAttribute('aria-selected') !== 'true') return;
if (ev.key === '[') { ev.preventDefault(); setDetailExpanded(false); }
if (ev.key === ']') {
ev.preventDefault();
setDetailExpanded(true);
try {
localStorage.setItem(STARS_DETAIL_KEY, '1');
} catch (e) {}
}
});
async function fetchReadme(owner, repo) {
var key = String(owner || '') + '/' + String(repo || '');
if (__readmeCache.has(key)) return __readmeCache.get(key);
try {
const r = await fetch(
'https://api.github.com/repos/' + encodeURIComponent(owner) + '/' + encodeURIComponent(repo) + '/readme',
{ headers: { Accept: 'application/vnd.github.raw' } }
);
if (r.ok) {
const txt = await r.text();
__readmeCache.set(key, txt);
return txt;
}
} catch (e) {}
try {
const r = await fetch(
'https://raw.githubusercontent.com/' + owner + '/' + repo + '/HEAD/README.md'
);
if (r.ok) {
const txt = await r.text();
__readmeCache.set(key, txt);
return txt;
}
} catch (e) {}
__readmeCache.set(key, null);
return null;
}
try {
var savedK = localStorage.getItem(STAR_HIGHLIGHT_KEY) || '';
if (starHighlightKws && savedK) starHighlightKws.value = savedK;
} catch (e) {}
try {
var initial = sessionStorage.getItem(TAB_KEY);
if (initial === 'stars') setView('stars');
else setView('spell');
} catch (e) {
setView('spell');
}
try {
if (sessionStorage.getItem(TAB_KEY) === 'stars' && starHighlightKws && starHighlightKws.value.trim()) {
setTimeout(postStarHighlightFromInput, 120);
}
} catch (e2) {}
window.addEventListener('message', async function (ev) {
const d = ev.data;
if (!d) return;
if (d.type === 'unified-spellbook-keywords' && Array.isArray(d.keywords)) {
var parts = d.keywords.map(function (k) { return String(k).trim(); }).filter(Boolean);
var joined = parts.length ? parts.join(', ') : '';
if (starHighlightKws) starHighlightKws.value = joined;
try {
if (parts.length) localStorage.setItem(STAR_HIGHLIGHT_KEY, joined);
else localStorage.removeItem(STAR_HIGHLIGHT_KEY);
} catch (e) {}
postStarHighlightFromInput();
return;
}
if (d.type === 'spellbook-stats') {
var n = Number(d.nodes || 0);
var e = Number(d.edges || 0);
var ts = d.builtAt ? (' · built ' + new Date(d.builtAt).toLocaleString()) : '';
setHealthLine(healthSpell, 'Spellbook: ' + n + ' nodes, ' + e + ' edges' + ts);
return;
}
if (d.type === 'dock-link-status' && typeof d.text === 'string') {
if (dockLinkStatus) dockLinkStatus.textContent = d.text;
return;
}
if (d.type === 'dock-groups-data' && Array.isArray(d.items)) {
renderDockGroups(d.items, d.kind || 'spell');
return;
}
if (d.type === 'stars-data-ready') {
setTimeout(postStarHighlightFromInput, 80);
if (typeof d.count === 'number') {
setHealthLine(healthStars, 'Stars: ' + d.count + ' repos loaded');
}
return;
}
if (d.type !== 'stars-node') return;
setView('stars');
const fn = d.fullName || '';
const url = d.url || '';
const label = d.label || fn;
if (!fn || fn.indexOf('/') === -1) {
starHead.innerHTML = '<code>' + (d.id || '') + '</code> — hub (no README)';
starReadme.innerHTML = '';
return;
}
var enrich = d.enrich && typeof d.enrich === 'object' ? d.enrich : null;
var enrichBits = '';
if (enrich) {
var src = String(enrich.source || '').trim();
var ic = Number(enrich.insightCount || 0);
var kws = Array.isArray(enrich.keywords) ? enrich.keywords.filter(Boolean).slice(0, 8) : [];
var srcLabel = src ? ('deep: ' + escapeHtml(src)) : 'deep: fallback';
enrichBits =
'<div style="margin-top:6px;font-size:11px;color:#9aa0be">' +
srcLabel + ' · insights: ' + (isFinite(ic) ? ic : 0) +
(kws.length ? '<br/><span style="color:#7f89ad">kws:</span> ' + escapeHtml(kws.join(', ')) : '') +
'</div>';
}
starHead.innerHTML =
'<div><b>' + escapeHtml(label) + '</b></div>' +
(url ? '<p><a href="' + url + '" target="_blank" rel="noopener">Open on GitHub</a></p>' : '') +
enrichBits;
const reqId = ++__readmeReqSeq;
starReadme.innerHTML = '<p class="loading">Loading README…</p>';
const nameParts = fn.split('/');
const owner = nameParts[0];
const repo = nameParts.slice(1).join('/');
const md = await fetchReadme(owner, repo);
if (reqId !== __readmeReqSeq) return;
if (md && typeof ReadmeSkin !== 'undefined' && typeof marked !== 'undefined') {
ReadmeSkin.render(md, starReadme, marked);
} else if (md) {
starReadme.innerHTML = '<pre style="white-space:pre-wrap;word-break:break-word">' + escapeHtml(md) + '</pre>';
} else {
starReadme.innerHTML =
'<p style="color:#888">Could not load README (private, rate limit, or CORS). ' +
'<a href="' + (url || 'https://github.com/' + fn) + '" target="_blank" rel="noopener">View on GitHub</a></p>';
}
});
})();
</script>
</body>
</html>