treespeak 0.8.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tree_watch.html ADDED
@@ -0,0 +1,502 @@
1
+ <!doctype html><meta charset="utf-8"><title>Treespeak</title><meta name="viewport" content="width=device-width, initial-scale=1">
2
+ <style>
3
+ :root{--bg:#fff;--wm:.45;--surface:#f7f7f9;--ink:#1d1d1f;--muted:#6b7280;--line:#e5e7eb;--wood:#8a6a4a;--orange:#f07a1d;--frozen:#c7cbd1;--added:#2f9e5f;--mod:#d98b13;--ren:#4b78c9;--del:#c0392b;--flight:#f07a1d;--tipbg:rgba(247,247,249,.9)}
4
+ @media (prefers-color-scheme: dark){:root:not([data-theme="light"]){--bg:#121214;--wm:.38;--surface:#1b1b1f;--ink:#f2f2f4;--muted:#9a9ea8;--line:#2a2a30;--wood:#b08a5e;--orange:#ff9340;--frozen:#4a4d55;--added:#5ec98a;--mod:#f0b04a;--ren:#7ea2e8;--del:#ef7d70;--flight:#ff9340;--tipbg:rgba(27,27,31,.9)}}
5
+ :root[data-theme="dark"]{--bg:#121214;--wm:.38;--surface:#1b1b1f;--ink:#f2f2f4;--muted:#9a9ea8;--line:#2a2a30;--wood:#b08a5e;--orange:#ff9340;--frozen:#4a4d55;--added:#5ec98a;--mod:#f0b04a;--ren:#7ea2e8;--del:#ef7d70;--flight:#ff9340;--tipbg:rgba(27,27,31,.9)}
6
+ *{box-sizing:border-box} body{background:var(--bg);color:var(--ink);font:14px/1.4 -apple-system,system-ui,sans-serif;margin:0;font-variant-numeric:tabular-nums} .wrap{max-width:1320px;margin:0 auto;padding:20px 22px 40px} header{display:flex;flex-wrap:wrap;align-items:baseline;gap:10px 24px;border-bottom:1px solid var(--line);padding-bottom:12px;margin-bottom:12px} h1{font-size:19px;font-weight:600;margin:0} .sub{color:var(--muted);font-size:13px}
7
+ nav.crumb{margin:0 0 8px;font-size:13px;color:var(--muted)} nav.crumb button{font:inherit;border:none;background:none;color:var(--ink);cursor:pointer;padding:2px 5px;border-radius:4px} nav.crumb button:hover{background:var(--surface)}
8
+ .treestats{margin:0 0 8px;font-size:12px;color:var(--muted)}
9
+ .legend-note{margin-top:6px;font-size:11px;color:var(--muted)}
10
+ .connlost{margin:0 0 8px;font-size:12px;color:var(--muted)}
11
+ .layout{display:grid;grid-template-columns:minmax(0,1fr) 290px;gap:20px} @media (max-width:900px){.layout{grid-template-columns:1fr}} #cv{width:100%;height:78vh;display:block;background:var(--surface);border:1px solid var(--line);border-radius:12px;touch-action:none;transition:opacity .2s;cursor:grab} #cv.dim{opacity:.6} #cv:focus{outline:none} #cv:focus-visible{outline:2px solid var(--orange);outline-offset:2px} .cvwrap{position:relative} .zoomctl{position:absolute;top:10px;right:10px;display:flex;flex-direction:column;gap:6px} .zoomctl button{width:28px;height:28px;border-radius:50%;border:1px solid var(--line);background:var(--bg);color:var(--ink);cursor:pointer;font:15px/1 sans-serif;padding:0;line-height:1}
12
+ .tip{position:fixed;z-index:9;display:none;width:300px;box-sizing:border-box;background:var(--tipbg);backdrop-filter:blur(7px);border:1px solid var(--line);border-radius:8px;padding:10px 12px;pointer-events:none;box-shadow:0 6px 18px rgba(0,0,0,.16);text-align:left} .tip .name{font-size:13px;font-weight:700;overflow-wrap:anywhere} .tip canvas.tipicon{float:left;width:22px;height:22px;margin:1px 8px 4px 0} .tip .path{font-size:11px;color:var(--muted);font-family:ui-monospace,monospace;overflow-wrap:anywhere;margin-top:2px} .tip .state{display:flex;align-items:baseline;justify-content:space-between;gap:8px;margin-top:5px;font-size:12px} .tip .dot{width:8px;height:8px;border-radius:50%;display:inline-block;margin-right:5px} .tip .when{color:var(--muted)} .tip .subject{font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:5px} .tip .files{font-size:12px;margin-top:5px} .tip .tally{font-size:12px;margin-top:5px} .tip .tally span{margin-right:8px}
13
+ .crumbrow{display:flex;align-items:center;gap:10px;margin:0 0 8px} .crumbrow nav.crumb{margin:0;flex:1} #treelist-toggle{margin-left:auto;opacity:1} #treelist-toggle[aria-pressed="true"]{border-color:var(--orange);color:var(--orange)} .cvwrap.listing #cv{opacity:var(--wm)} #treelist .row{text-shadow:0 0 3px var(--bg),0 0 3px var(--bg),0 0 6px var(--bg)}
14
+ #treelist{position:absolute;top:10px;left:10px;bottom:10px;width:max-content;max-width:45%;overflow:auto;padding:4px 8px 4px 2px;font-size:12.5px;line-height:1.5;z-index:2;pointer-events:none} #treelist .row{display:flex;align-items:center;gap:4px;padding:1px 6px 1px calc(6px + var(--depth)*14px);border-radius:6px;white-space:nowrap;pointer-events:auto} #treelist .row.f{padding-left:calc(6px + var(--depth)*14px + 4px)} #treelist .disc{width:14px;height:14px;flex:none;border:none;background:none;padding:0;cursor:pointer;color:var(--muted);position:relative} #treelist .disc::before{content:"";position:absolute;left:4px;top:3px;border:4px solid transparent;border-left:6px solid currentColor;transition:transform .12s} #treelist .disc[aria-expanded="true"]::before{transform:rotate(90deg)} #treelist .disc.root{cursor:default} #treelist .disc.root::before{display:none} #treelist .dot{width:8px;height:8px;border-radius:50%;flex:none;margin:0 2px 0 4px} #treelist .name{font:inherit;border:none;background:none;color:var(--ink);cursor:pointer;padding:0 3px;border-radius:4px;overflow:hidden;text-overflow:ellipsis;min-width:0;text-align:left} #treelist .name:hover{text-decoration:underline} #treelist .name:focus-visible{outline:2px solid var(--orange);outline-offset:1px} #treelist .fig{margin-left:auto;color:var(--muted);font-size:11px;padding-left:8px} #treelist .name,#treelist .fig{text-shadow:0 0 2px var(--surface),0 0 2px var(--surface),0 0 4px var(--surface),0 0 4px var(--surface)} #treelist .row.hl{background:var(--bg);box-shadow:inset 0 0 0 1.5px var(--orange)} #treelist .row.focus>.name{font-weight:700;color:var(--wood)} #treelist .row.off{opacity:.45} #treelist .row.dim>.name{color:var(--muted)} #treelist .row.hollow>.dot{background:transparent!important;border:1px solid var(--muted)} @media (prefers-reduced-motion: reduce){#treelist .disc::before{transition:none}}
15
+ aside{position:sticky;top:12px;align-self:start;display:flex;flex-direction:column;gap:12px} .card{background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:12px 14px} .card h2{font-size:11.5px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);margin:0 0 8px;font-weight:600} .kv{display:grid;grid-template-columns:1fr auto;gap:3px 10px} .kv canvas.mini{width:20px;height:20px;vertical-align:-5px;margin-right:4px} .kv b{font-weight:600}
16
+ .recent{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px} .recent li{display:flex;gap:6px;align-items:baseline;font-size:12px} .recent button{font:inherit;border:none;background:none;color:var(--ink);cursor:pointer;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:1px 0;flex:1} .recent button:hover{text-decoration:underline} .recent .age{color:var(--muted);font-size:11px;flex:none}
17
+ .ctl{display:flex;flex-wrap:wrap;gap:6px} button.pill{font:inherit;font-size:12px;padding:3px 9px;border:1px solid var(--line);border-radius:999px;background:var(--bg);color:var(--ink);cursor:pointer;display:inline-flex;align-items:center;gap:5px} button.pill[aria-pressed="false"]{opacity:.45} .sw{width:9px;height:9px;border-radius:50%;display:inline-block} .foot{color:var(--muted);font-size:11.5px;margin-top:16px}
18
+ .zoomctl button[data-x]{font:600 8.5px/1 sans-serif}
19
+ html.bare,html.bare body{background:transparent} html.bare .wrap{max-width:none;padding:0} html.bare header,html.bare .crumbrow,html.bare .treestats,html.bare .connlost,html.bare aside,html.bare .foot,html.bare .zoomctl{display:none} html.bare .layout{display:block} html.bare #cv{height:100vh;background:transparent;border:none;border-radius:0}
20
+ </style>
21
+ <div class="wrap"><header><h1 id="title"></h1><span class="sub" id="stamp"></span></header>
22
+ <div class="layout"><div><div class="crumbrow"><nav class="crumb" id="crumb"></nav><button id="treelist-toggle" class="pill" aria-pressed="false">file tree</button></div><div class="treestats" id="treestats"></div><div class="connlost" id="connlost" hidden>connection lost, retrying</div><div class="cvwrap"><canvas id="cv" tabindex="0"></canvas><div class="zoomctl" id="zoomctl"><button aria-label="zoom in" data-z="in">+</button><button aria-label="zoom out" data-z="out">&minus;</button><button aria-label="fit" data-z="fit">&#8862;</button><button aria-label="download PNG" data-x="png">PNG</button></div></div></div>
23
+ <aside><div class="card"><h2>Counts</h2><div class="kv" id="counts"></div></div><div class="card"><h2>Since start</h2><div class="kv" id="since"></div></div><div class="card"><h2>Last 60 s</h2><ul class="recent" id="recent"></ul></div><div class="card"><h2>Show</h2><div class="ctl" id="ctl"></div><div class="legend-note" id="legendnote"></div></div><div class="card"><h2>Made of</h2><div class="kv" id="madeof"></div></div></aside></div>
24
+ <div class="foot">Hover a leaf, branch or twig for its name. Click a branch or twig to zoom in, Escape to go up. The file tree button lists the same files beside the drawing; hover either side.</div></div>
25
+ <div class="tip" id="tip"></div>
26
+ <script>
27
+ const NAMES={F:'frozen',A:'added',M:'modified',R:'moved',D:'deleted',U:'in flight'},ORDER=['A','M','R','D','U','F'],KEY={F:'frozen',A:'added',M:'mod',R:'ren',D:'del',U:'flight'},filters={F:1,A:1,M:1,R:1,D:1,U:1},TROPISM=0.15;
28
+ let LEAF_CAP=24,WARN_LINES=400;
29
+ const LEAF_LEN_MIN=8,LEAF_LEN_MAX=34,LEAF_WID_RATIO=0.42,LEAF_GAP_MIN=3,LEAF_ZONE_START=0.4,LEAF_ZONE_CAP=2,PETIOLE_LEN=3,SCALE_SEED=1.5,SCALE_SLACK=0.92;
30
+ const LEN_LO=0.7,LEN_HI=1.4,LEN_PASSES=4,TIP_ANG=30*Math.PI/180,TIP_ZONE=0.7,TRUNK_W=18,TAP_DRIFT=18,TAP_REACH=12;
31
+ let DATA=null,OFFSET=0,FOCUS=null,SCALE_KEPT=0,HITS=[],BASE=null,HOVER=null,TREE=null,HIT_AT=new Map(),TWIG_OF=new Map(),FILE_AT=new Map(),TABI=-1,CC={},VIEW={s:1,x:0,y:0},DPR=1,W=0,H=0,drag=null,pts=new Map(),pinchD=0,pinchS=1,wasDrag=false,LCACHE=new Map(),LENF=new Map(),COUNTL=false,LSTAT={hit:0,total:0},WRITTEN=true,CAPCOUNT=0;window.__view=VIEW;
32
+ const cv=document.getElementById('cv'),X=cv.getContext('2d'),tip=document.getElementById('tip'),connlost=document.getElementById('connlost'),RM=matchMedia('(prefers-reduced-motion: reduce)').matches;
33
+ const QS=new URLSearchParams(location.search),BARE=QS.get('bare')==='1';if(BARE)document.documentElement.classList.add('bare');if(/^(light|dark)$/.test(QS.get('theme')||''))document.documentElement.dataset.theme=QS.get('theme');
34
+ const HOST=(h=>{if(!h)return null;try{return new URL(h).origin;}catch(e){return h==='null'?'null':null;}})(QS.get('host')),HOST_TO=HOST==='null'?'*':HOST;
35
+ const toHost=m=>{if(HOST&&window.parent!==window)window.parent.postMessage(Object.assign({type:'treespeak'},m),HOST_TO);};
36
+ const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
37
+ const nowSrv=()=>Date.now()/1000-OFFSET,cssv=k=>getComputedStyle(document.body).getPropertyValue('--'+k).trim(),TAU=Math.PI*2;
38
+ const age=f=>(f.s==='D'||!f.mt)?1e9:Math.max(0,nowSrv()-f.mt);
39
+ const ago=a=>a>1e8?'--':a<60?Math.round(a)+' s':a<3600?Math.round(a/60)+' min':Math.round(a/3600)+' h';
40
+ const dirOf=p=>p.includes('/')?p.slice(0,p.lastIndexOf('/')):'';
41
+ const fmt=t=>t?new Date(t*1000).toLocaleString('en-GB',{day:'2-digit',month:'short',hour:'2-digit',minute:'2-digit'}):'';
42
+ const baseName=p=>p.split('/').pop(),stemOf=p=>baseName(p).replace(/\.[^.]+$/,'');
43
+ function hash(s){let h=2166136261;for(let i=0;i<s.length;i++){h^=s.charCodeAt(i);h=Math.imul(h,16777619);}return (h>>>0)/4294967296;}
44
+ function wln(f){return f.kind==='authored'?(f.ln||0):0;}function wln0(f){return f.kind==='authored'?(f.ln0||0):0;}
45
+ function build(files){const root={n:'root',p:'',d:{},f:[],c:0,h:0,st:{},ln:0,ln0:0,nw:0,cl:0,tl:{}};for(const f of files){const parts=f.p.split('/');let node=root;const chain=[root];for(let i=0;i<parts.length-1;i++){const k=parts[i];node=node.d[k]||(node.d[k]={n:k,p:parts.slice(0,i+1).join('/'),d:{},f:[],c:0,h:0,st:{},ln:0,ln0:0,nw:0,cl:0,tl:{}});chain.push(node);}node.f.push(f);const tt=techOf(f),tn=tt?tt.name:'',tw=wln(f);for(const up of chain){up.c++;if(f.s!=='F')up.h=1;up.st[f.s]=(up.st[f.s]||0)+1;up.ln+=tw;up.ln0+=wln0(f);if(f.nw)up.nw++;if(f.s!=='D')up.cl++;if(tw)up.tl[tn]=(up.tl[tn]||0)+tw;}}return root;}
46
+ function sub(root,path){if(!path)return root;let n=root;for(const k of path.split('/')){n=n.d[k];if(!n)return null;}return n;}
47
+ function extOf(name){const i=name.lastIndexOf('.');return i>0?name.slice(i+1):'';}
48
+ function splitRuns(files){const total=files.length,runCount=Math.ceil(total/LEAF_CAP),base=Math.floor(total/runCount),extra=total-base*runCount,out=[];let idx=0;
49
+ for(let g=0;g<runCount;g++){const size=base+(g<extra?1:0);out.push(files.slice(idx,idx+size));idx+=size;}return out;}
50
+ function rangeLabel(dirBase,run,ext){const label=stemOf(run[0].p)+' – '+stemOf(run[run.length-1].p);return dirBase+' · '+(ext?ext+' · '+label:label);}
51
+ function groupLeaves(dirBase,files){if(files.length<=LEAF_CAP)return null;
52
+ const byExt={};for(const f of files){const ext=extOf(baseName(f.p));(byExt[ext]=byExt[ext]||[]).push(f);}
53
+ const exts=Object.keys(byExt),groups=[];
54
+ if(exts.length>1){for(const ext of exts.sort()){const list=byExt[ext];
55
+ if(list.length>LEAF_CAP)splitRuns(list).forEach((run,i)=>groups.push({key:ext+':'+i,label:rangeLabel(dirBase,run,ext),files:run}));
56
+ else groups.push({key:ext+':0',label:dirBase+' · '+(ext||'no-ext'),files:list});}}
57
+ else splitRuns(files).forEach((run,i)=>groups.push({key:exts[0]+':'+i,label:rangeLabel(dirBase,run,''),files:run}));
58
+ return groups;}
59
+ function groupState(files){const st={},tl={};let hot=false,ln=0,ln0=0;for(const f of files){st[f.s]=(st[f.s]||0)+1;if(f.s!=='F')hot=true;const w=wln(f);ln+=w;ln0+=wln0(f);if(w){const tt=techOf(f),k=tt?tt.name:'';tl[k]=(tl[k]||0)+w;}}return{st,hot,ln,ln0,tl};}
60
+ // Foliage habit: the technology a file is written in, read from its name, decides how its leaf sits on the twig — the angle it
61
+ // leaves at, how narrow it is, how far the petiole holds it, how tight the row runs and whether leaves come in opposite pairs
62
+ // (a ladder) or alternate (a zigzag, the second row starting half a step in). Length carries lines in every habit, so a needle
63
+ // of 300 lines is as long as a broad leaf of 300 (Niv, 2026-10-08)
64
+ const HABITS={broad:{name:'broad leaves',ang:35,spread:20,ratio:null,petiole:1,gap:1,pair:false},
65
+ needle:{name:'needles',ang:16,spread:10,ratio:0.22,petiole:0.4,gap:0.35,pair:false},
66
+ paired:{name:'paired leaves',ang:50,spread:12,ratio:0.42,petiole:0.8,gap:1.2,pair:true},
67
+ frond:{name:'fronds',ang:72,spread:10,ratio:0.28,petiole:0.3,gap:0.3,pair:true},
68
+ scale:{name:'scales',ang:12,spread:8,ratio:0.6,petiole:0,gap:0.15,pair:true},
69
+ droop:{name:'drooping leaves',ang:108,spread:14,ratio:0.36,petiole:2.2,gap:1,pair:false}};
70
+ const TECH={};
71
+ for(const [habit,techs] of Object.entries({
72
+ broad:{Python:'py pyi',Ruby:'rb rake gemspec',PHP:'php',Shell:'sh bash zsh fish',Perl:'pl pm',Lua:'lua',R:'r',Julia:'jl',Elixir:'ex exs',Erlang:'erl',PowerShell:'ps1',SQL:'sql'},
73
+ needle:{C:'c','C/C++':'h','C++':'cc cpp cxx hpp hh hxx',Rust:'rs',Go:'go',Zig:'zig','Objective-C':'m mm',Assembly:'s asm',Fortran:'f f90 f95',CUDA:'cu cuh'},
74
+ paired:{Java:'java',Kotlin:'kt kts','C#':'cs',Swift:'swift',Scala:'scala',Groovy:'groovy','F#':'fs',Dart:'dart'},
75
+ frond:{JavaScript:'js mjs cjs',TypeScript:'ts mts cts',React:'jsx tsx',HTML:'html htm',CSS:'css',Vue:'vue',Svelte:'svelte',Astro:'astro',Sass:'scss sass',Less:'less'},
76
+ scale:{JSON:'json jsonc json5',YAML:'yml yaml',TOML:'toml',XML:'xml xsd xsl plist',Config:'ini cfg conf env properties editorconfig',Lockfile:'lock',Gradle:'gradle',CMake:'cmake',Protobuf:'proto',GraphQL:'graphql gql',Data:'csv tsv'},
77
+ droop:{Markdown:'md markdown mdx',reStructuredText:'rst',Text:'txt',AsciiDoc:'adoc asciidoc',LaTeX:'tex bib',Org:'org'}}))
78
+ for(const [name,exts] of Object.entries(techs))for(const e of exts.split(' '))TECH[e]={name,habit};
79
+ const TECH_BY_NAME={Angular:'frond'};for(const e in TECH)TECH_BY_NAME[TECH[e].name]=TECH[e].habit;
80
+ // Each technology keeps the colour developers already know it by, GitHub's language colour: Python blue, JavaScript yellow,
81
+ // C++ pink, Rust tan, Go cyan, Java brown, Ruby dark red. A limb's wood is the colour of what it is mostly made of and a
82
+ // leaf's outline is its own file's colour; the fill stays with git state (Niv, 2026-10-08)
83
+ const BRAND={Python:'#3572A5',Ruby:'#701516',PHP:'#4F5D95',Shell:'#89e051',Perl:'#0298c3',Lua:'#000080',R:'#198CE7',Julia:'#a270ba',Elixir:'#6e4a7e',Erlang:'#B83998',PowerShell:'#012456',SQL:'#e38c00',
84
+ C:'#555555','C/C++':'#555555','C++':'#f34b7d',Rust:'#dea584',Go:'#00ADD8',Zig:'#ec915c','Objective-C':'#438eff',Assembly:'#6E4C13',Fortran:'#4d41b1',CUDA:'#3A4E3A',
85
+ Java:'#b07219',Kotlin:'#A97BFF','C#':'#178600',Swift:'#F05138',Scala:'#c22d40',Groovy:'#4298b8','F#':'#b845fc',Dart:'#00B4AB',
86
+ JavaScript:'#f1e05a',TypeScript:'#3178c6',HTML:'#e34c26',CSS:'#563d7c',Vue:'#41b883',Svelte:'#ff3e00',Astro:'#ff5a03',Sass:'#a53b70',Less:'#1d365d',
87
+ JSON:'#292929',YAML:'#cb171e',TOML:'#9c4221',XML:'#0060ac',Config:'#6d8086',Lockfile:'#6d8086',Gradle:'#02303a',CMake:'#DA3434',Protobuf:'#4a6f8a',GraphQL:'#e10098',Data:'#237346',
88
+ Markdown:'#083fa1',reStructuredText:'#141414',Text:'#6d8086',AsciiDoc:'#73a0c5',LaTeX:'#3D6117',Org:'#77aa99',
89
+ Make:'#427819',Docker:'#384d54',Bundler:'#701516',CocoaPods:'#F05138',Just:'#6d8086',Vagrant:'#1563FF'};
90
+ // A leaf is the technology's own icon, the way its brand draws it: Angular's red shield with the A, TypeScript's blue TS
91
+ // square, JavaScript's yellow JS, Python's blue and yellow pair, the C family's hexagons, Rust's gear, Java's cup, Ruby's
92
+ // gem, React's atom, Vue's V. The icon's colour is also the wood of a limb mostly made of it (Niv, 2026-10-08)
93
+ const BADGE={Python:{mark:'snakes',bg:'#3776ab',half:'#ffd43b',fg:'#fff'},
94
+ JavaScript:{bg:'#f7df1e',fg:'#000',text:'JS'},TypeScript:{bg:'#3178c6',fg:'#fff',text:'TS'},
95
+ Angular:{blade:'shield',bg:'#dd0031',half:'#c3002f',fg:'#fff',text:'A'},React:{mark:'atom',bg:'#20232a',fg:'#61dafb'},Vue:{blade:'chevron',mark:'chevron',bg:'#41b883',bg2:'#35495e'},
96
+ Svelte:{bg:'#ff3e00',fg:'#fff',text:'S'},Astro:{bg:'#ff5a03',fg:'#fff',text:'A'},
97
+ HTML:{blade:'shield',bg:'#e44d26',half:'#f16529',fg:'#fff',text:'5'},CSS:{blade:'shield',bg:'#1572b6',half:'#33a9dc',fg:'#fff',text:'3'},Sass:{bg:'#cc6699',fg:'#fff',text:'S'},Less:{bg:'#1d365d',fg:'#fff',text:'L'},
98
+ C:{bg:'#659ad2',fg:'#fff',text:'C'},'C/C++':{bg:'#659ad2',fg:'#fff',text:'.h'},'C++':{bg:'#00599c',fg:'#fff',text:'C++'},'C#':{bg:'#512bd4',fg:'#fff',text:'C#'},
99
+ Rust:{mark:'gear',bg:'#b7410e',fg:'#fff',text:'R'},Go:{bg:'#00add8',fg:'#fff',text:'Go'},Zig:{bg:'#f7a41d',fg:'#000',text:'Z'},
100
+ 'Objective-C':{bg:'#438eff',fg:'#fff',text:'[C]'},Assembly:{bg:'#6e4c13',fg:'#fff',text:'asm'},Fortran:{bg:'#734f96',fg:'#fff',text:'F'},CUDA:{bg:'#76b900',fg:'#fff',text:'CU'},
101
+ Java:{mark:'cup',bg:'#5382a1',bg2:'#f8981d',fg:'#fff'},Kotlin:{bg:'#7f52ff',fg:'#fff',text:'K'},Swift:{bg:'#f05138',fg:'#fff',text:'S'},
102
+ Scala:{bg:'#dc322f',fg:'#fff',text:'Sc'},Groovy:{bg:'#4298b8',fg:'#fff',text:'G'},'F#':{bg:'#378bba',fg:'#fff',text:'F#'},Dart:{bg:'#0175c2',fg:'#fff',text:'D'},
103
+ Ruby:{blade:'gem',mark:'gem',bg:'#cc342d',fg:'#fff'},PHP:{bg:'#777bb4',fg:'#fff',text:'php'},Shell:{bg:'#1e1e1e',fg:'#4eaa25',text:'$_'},
104
+ Perl:{bg:'#39457e',fg:'#fff',text:'P'},Lua:{bg:'#000080',fg:'#fff',text:'L'},R:{bg:'#276dc3',fg:'#fff',text:'R'},Julia:{bg:'#9558b2',fg:'#fff',text:'jl'},
105
+ Elixir:{bg:'#6e4a7e',fg:'#fff',text:'Ex'},Erlang:{bg:'#a90533',fg:'#fff',text:'Erl'},PowerShell:{bg:'#012456',fg:'#fff',text:'>_'},SQL:{bg:'#e38c00',fg:'#fff',text:'SQL'},
106
+ JSON:{bg:'#292929',fg:'#fff',text:'{ }'},YAML:{bg:'#cb171e',fg:'#fff',text:'Y'},TOML:{bg:'#9c4221',fg:'#fff',text:'T'},XML:{bg:'#0060ac',fg:'#fff',text:'<>'},
107
+ Config:{bg:'#6d8086',fg:'#fff',text:'cfg'},Lockfile:{bg:'#6d8086',fg:'#fff',text:'lock'},Gradle:{bg:'#02303a',fg:'#fff',text:'G'},CMake:{bg:'#da3434',fg:'#fff',text:'CM'},
108
+ Protobuf:{bg:'#4a6f8a',fg:'#fff',text:'pb'},GraphQL:{bg:'#e10098',fg:'#fff',text:'Q'},Data:{bg:'#237346',fg:'#fff',text:'csv'},
109
+ Markdown:{bg:'#24292e',fg:'#fff',text:'M\u2193'},reStructuredText:{bg:'#141414',fg:'#fff',text:'rst'},Text:{bg:'#6d8086',fg:'#fff',text:'\u2261'},
110
+ AsciiDoc:{bg:'#73a0c5',fg:'#fff',text:'AD'},LaTeX:{bg:'#3d6117',fg:'#fff',text:'TeX'},Org:{bg:'#77aa99',fg:'#fff',text:'org'},
111
+ Make:{bg:'#427819',fg:'#fff',text:'Mk'},Docker:{bg:'#2496ed',fg:'#fff',text:'D'},Bundler:{bg:'#cc342d',fg:'#fff',text:'B'},
112
+ CocoaPods:{bg:'#ee3322',fg:'#fff',text:'CP'},Just:{bg:'#6d8086',fg:'#fff',text:'J'},Vagrant:{bg:'#1563ff',fg:'#fff',text:'V'}};
113
+ let DRAW_ZOOM=1;
114
+ function alpha(hex,a){const m=/^#?([0-9a-f]{6})$/i.exec(String(hex).trim());if(!m)return hex;const n=parseInt(m[1],16);return 'rgba('+((n>>16)&255)+','+((n>>8)&255)+','+(n&255)+','+a+')';}
115
+ function drawMark(b,badge,s){const h=s/2,mk=badge.mark;b.fillStyle=badge.fg;b.strokeStyle=badge.fg;
116
+ if(mk==='gear'){for(let i=0;i<8;i++){b.save();b.rotate(i*Math.PI/4);b.fillRect(h*0.5,-s*0.08,s*0.32,s*0.16);b.restore();}b.beginPath();b.arc(0,0,h*0.58,0,TAU);b.fill();b.fillStyle=badge.bg;b.beginPath();b.arc(0,0,h*0.22,0,TAU);b.fill();}
117
+ else if(mk==='atom'){b.lineWidth=Math.max(0.6,s*0.07);for(let i=0;i<3;i++){b.beginPath();b.ellipse(0,0,h,h*0.36,i*Math.PI/3,0,TAU);b.stroke();}b.beginPath();b.arc(0,0,s*0.1,0,TAU);b.fill();}
118
+ else if(mk==='chevron'){b.fillStyle=badge.bg2;b.beginPath();b.moveTo(-h,-h);b.lineTo(-h*0.5,-h);b.lineTo(0,h*0.05);b.lineTo(h*0.5,-h);b.lineTo(h,-h);b.lineTo(0,h);b.closePath();b.fill();b.fillStyle='#fff';b.beginPath();b.moveTo(-h*0.5,-h);b.lineTo(-h*0.2,-h);b.lineTo(0,-h*0.45);b.lineTo(h*0.2,-h);b.lineTo(h*0.5,-h);b.lineTo(0,h*0.05);b.closePath();b.fill();}
119
+ else if(mk==='cup'){b.strokeStyle=badge.bg2;b.lineWidth=Math.max(0.8,s*0.09);b.beginPath();b.moveTo(-h*0.2,-h);b.quadraticCurveTo(h*0.2,-h*0.6,-h*0.2,-h*0.2);b.moveTo(h*0.25,-h);b.quadraticCurveTo(h*0.65,-h*0.6,h*0.25,-h*0.2);b.stroke();
120
+ b.fillStyle=badge.fg;b.fillRect(-h*0.7,0,s*0.7,h*0.7);b.strokeStyle=badge.fg;b.lineWidth=Math.max(0.8,s*0.08);b.beginPath();b.arc(h*0.05,h*0.35,h*0.32,-Math.PI/2,Math.PI/2);b.stroke();}
121
+ else if(mk==='gem'){b.strokeStyle='rgba(255,255,255,.85)';b.lineWidth=Math.max(0.6,s*0.06);b.beginPath();b.moveTo(-h*0.5,-h);b.lineTo(h*0.5,-h);b.lineTo(h,-h*0.4);b.lineTo(0,h);b.lineTo(-h,-h*0.4);b.closePath();b.moveTo(-h,-h*0.4);b.lineTo(h,-h*0.4);b.moveTo(-h*0.5,-h);b.lineTo(0,h);b.moveTo(h*0.5,-h);b.lineTo(0,h);b.stroke();}}
122
+ const BLADE_WR={shield:0.85,chevron:0.9,gem:0.8};
123
+ function bladePath(b,badge,g,len,halfW,px,py){const shape=badge&&badge.blade;if(!shape)return leafPath(b,g,len,halfW*2,px,py);
124
+ const L=len+px,W=halfW+py,cut=shape==='shield'&&roleOf(g.f).role==='interface';b.beginPath();
125
+ if(shape==='shield'){if(cut){b.moveTo(-px,-W*0.45);b.lineTo(-px,W);}else{b.moveTo(-px,-W);b.lineTo(-px,W);}b.lineTo(L*0.675,W*0.9);b.lineTo(L,0);b.lineTo(L*0.675,-W*0.9);if(cut)b.lineTo(L*0.3,-W);}
126
+ else if(shape==='chevron'){b.moveTo(-px,-W);b.lineTo(-px,-W*0.5);b.lineTo(L*0.525,0);b.lineTo(-px,W*0.5);b.lineTo(-px,W);b.lineTo(L,0);}
127
+ else{b.moveTo(-px,-W*0.5);b.lineTo(-px,W*0.5);b.lineTo(L*0.3,W);b.lineTo(L,0);b.lineTo(L*0.3,-W);}
128
+ b.closePath();}
129
+ function brandBlade(b,badge,g,len,halfW,hollow,ang){const poly=!!badge.blade;bladePath(b,badge,g,len,halfW,0,0);
130
+ if(hollow){b.lineWidth=1;b.strokeStyle=badge.bg;b.stroke();return;}
131
+ const iface=!poly&&roleOf(g.f).role==='interface';b.fillStyle=badge.bg;b.fill();
132
+ if(badge.half&&!iface){b.save();b.clip();b.fillStyle=badge.half;b.fillRect(0,poly?-len:0,len,len);b.restore();}
133
+ if(!poly){b.strokeStyle=alpha(badge.fg,0.35);b.lineWidth=Math.max(0.6,halfW*0.08);b.beginPath();b.moveTo(0,0);b.lineTo(len*0.96,0);b.stroke();}
134
+ const cx=poly?len*0.42:len*0.47,cy=iface?halfW*0.5:0,across=iface?halfW*0.8:halfW*1.5,side=Math.min(len,halfW*2);
135
+ if(badge.mark==='snakes'){const r=Math.max(0.6,halfW*0.16);b.fillStyle='#fff';b.beginPath();b.arc(cx,iface?cy:-halfW*0.45,r,0,TAU);b.fill();if(!iface){b.fillStyle=badge.bg;b.beginPath();b.arc(cx,halfW*0.45,r,0,TAU);b.fill();}}
136
+ else if(badge.mark){const ms=poly?side*0.8:Math.min(across,len*0.5);if(ms*DRAW_ZOOM>=4){b.save();b.translate(cx,cy);b.rotate(poly?-Math.PI/2:-ang);drawMark(b,badge,ms);b.restore();}}
137
+ else if(badge.text){const n=badge.text.length,px=poly?Math.min(side*0.7,side*0.62/Math.max(1,n*0.55)):Math.min(across,len*0.5/(n*0.6));
138
+ if(px*DRAW_ZOOM>=5.5){b.save();b.translate(cx,cy);if(poly){b.rotate(-Math.PI/2);if(Math.sin(ang)<0)b.rotate(Math.PI);}else if(Math.cos(ang)<0)b.rotate(Math.PI);b.fillStyle=badge.fg;b.font='bold '+px.toFixed(1)+'px system-ui,-apple-system,sans-serif';b.textAlign='center';b.textBaseline='middle';b.fillText(badge.text,0,0);b.restore();}}}
139
+ function drawBrandMini(x,badge,box){const g={f:{p:'a'}},poly=!!badge.blade,len=box*(poly?0.75:0.95),hw=len*(poly?BLADE_WR[badge.blade]:0.44)/2,ang=Math.PI/4,o=box*(poly?0.3:0.18);x.translate(o,o);x.rotate(ang);x.strokeStyle=badge.bg;x.lineWidth=1;x.beginPath();x.moveTo(-len*0.2,0);x.lineTo(0,0);x.stroke();
140
+ DRAW_ZOOM=2;brandBlade(x,badge,g,len,hw,false,ang);DRAW_ZOOM=1;bladePath(x,badge,g,len,hw,0,0);x.strokeStyle=darken(badge.bg,0.72);x.lineWidth=0.8;x.stroke();}
141
+ function badgeOf(f){const t=techOf(f);return t?BADGE[t.name]||null:null;}
142
+ const BRAND_AT={};
143
+ function hexHsl(hex){const n=parseInt(hex.slice(1),16),r=((n>>16)&255)/255,g=((n>>8)&255)/255,b=(n&255)/255,mx=Math.max(r,g,b),mn=Math.min(r,g,b),l=(mx+mn)/2;
144
+ if(mx===mn)return[0,0,l];const d=mx-mn,s=l>0.5?d/(2-mx-mn):d/(mx+mn);let h=mx===r?(g-b)/d+(g<b?6:0):mx===g?(b-r)/d+2:(r-g)/d+4;return[h/6,s,l];}
145
+ function hslHex(h,s,l){const q=l<0.5?l*(1+s):l+s-l*s,p=2*l-q,f=t=>{t=(t+1)%1;return t<1/6?p+(q-p)*6*t:t<1/2?q:t<2/3?p+(q-p)*(2/3-t)*6:p;};
146
+ return '#'+[f(h+1/3),f(h),f(h-1/3)].map(v=>Math.round(v*255).toString(16).padStart(2,'0')).join('');}
147
+ // GitHub's colours sit on white: on the dark theme the darkest are lifted, on the light theme the brightest are brought down
148
+ function brandOf(name){const own=name&&((BADGE[name]&&BADGE[name].bg)||BRAND[name]);if(!own)return null;const key=name+'|'+(CC.dark?'d':'l');if(BRAND_AT[key])return BRAND_AT[key];
149
+ const [h,s,l]=hexHsl(own),L=CC.dark?Math.max(l,0.52):Math.min(l,0.56);return BRAND_AT[key]=hslHex(h,s,L);}
150
+ function leafStroke(f,base){return brandOf((techOf(f)||{}).name)||darken(base,0.58);}
151
+ // A limb takes the form of its main technology, by authored lines: a conifer limb fans narrowly, a palm or a willow fans
152
+ // wide or lets its branches fall, and the bark takes that technology's tint (Niv, 2026-10-08)
153
+ const FORM={broad:{fan:1,tilt:0},needle:{fan:0.65,tilt:0},paired:{fan:1,tilt:0},frond:{fan:1.2,tilt:0.15},scale:{fan:0.8,tilt:0},droop:{fan:1,tilt:0.35}};
154
+ function dominant(tl){let best=null,most=0;for(const k of Object.keys(tl||{}).sort()){if(tl[k]>most){most=tl[k];best=k;}}
155
+ const h=best&&TECH_BY_NAME[best];return h?{name:best,habit:h}:null;}
156
+ // Within a technology a file has a role, read from its name: a header or a declaration is a flat-sided leaf, a test a toothed one
157
+ const IFACE_EXT={h:'header',hpp:'header',hh:'header',hxx:'header',pyi:'declaration',proto:'declaration',graphql:'declaration',gql:'declaration',idl:'declaration',thrift:'declaration',xsd:'declaration',wsdl:'declaration'};
158
+ const TEST_DIRS=new Set(['test','tests','spec','specs','__tests__','testing']);
159
+ const TEST_NAME=/^(test_.*\.py|.*_test\.(py|go|rb|exs|dart|c|cc|cpp|cxx)|.*_spec\.rb|.*\.(test|spec)\.(js|jsx|mjs|cjs|ts|tsx)|.*(Test|Tests|IT|Spec)\.(java|kt|scala|groovy)|.*Tests?\.(cs|swift)|.*Test\.php|tests?\.rs)$/;
160
+ function roleOf(f){const parts=f.p.split('/'),name=parts[parts.length-1];
161
+ if(parts.slice(0,-1).some(s=>TEST_DIRS.has(s.toLowerCase()))||TEST_NAME.test(name))return{role:'test',word:'test'};
162
+ if(/\.d\.ts$/i.test(name))return{role:'interface',word:'declaration'};
163
+ const w=IFACE_EXT[extOf(name).toLowerCase()];return w?{role:'interface',word:w}:{role:'source',word:''};}
164
+ function leafPath(b,g,len,halfW,px,py){const role=roleOf(g.f).role,w=halfW+py,L=len+px;b.beginPath();
165
+ if(role==='interface'){b.moveTo(-px,0);b.quadraticCurveTo(len*0.4,w,L,0);b.closePath();return;}
166
+ if(role==='test'){const N=10,tooth=Math.max(1.6,w*0.45),P=(t,s)=>{const u=1-t;return[u*u*(-px)+2*u*t*len*0.4+t*t*L,s*2*u*t*w];};
167
+ b.moveTo(-px,0);for(let i=1;i<N;i++){const [x,y]=P(i/N,1);b.lineTo(x,y+(i%2?tooth:0));}b.lineTo(L,0);
168
+ for(let i=N-1;i>=1;i--){const [x,y]=P(i/N,-1);b.lineTo(x,y-(i%2?tooth:0));}b.closePath();return;}
169
+ b.moveTo(-px,0);b.quadraticCurveTo(len*0.4,w,L,0);b.quadraticCurveTo(len*0.4,-w,-px,0);b.closePath();}
170
+ const TECH_NAMES={Makefile:['Make','scale'],GNUmakefile:['Make','scale'],Dockerfile:['Docker','scale'],Containerfile:['Docker','scale'],'CMakeLists.txt':['CMake','scale'],
171
+ Gemfile:['Bundler','scale'],Rakefile:['Ruby','broad'],Podfile:['CocoaPods','scale'],Procfile:['Config','scale'],Justfile:['Just','scale'],Vagrantfile:['Vagrant','scale']};
172
+ const ANGULAR=/\.(component|module|service|directive|pipe|guard|resolver|interceptor)(\.spec)?\.ts$/i;
173
+ function techOf(f){const name=baseName(f.p),own=TECH_NAMES[name];if(own)return{name:own[0],habit:own[1]};
174
+ if(ANGULAR.test(name)||name==='angular.json')return{name:'Angular',habit:'frond'};return TECH[extOf(name).toLowerCase()]||null;}
175
+ function habitOf(f){const t=techOf(f);return HABITS[t?t.habit:'broad'];}
176
+ for(const n in TECH_NAMES)TECH_BY_NAME[TECH_NAMES[n][0]]=TECH_NAMES[n][1];
177
+ const ratioOf=h=>h.ratio==null?LEAF_WID_RATIO:h.ratio;
178
+ function habitLegend(){const by={};for(const e in TECH){const t=TECH[e];(by[t.habit]=by[t.habit]||[]).push(t.name);}
179
+ const few=h=>[...new Set(by[h])].filter(n=>!n.includes('/')).slice(0,4).join(', ');
180
+ return 'a leaf wears its technology\'s brand: Angular\'s red A, TypeScript\'s blue TS, JavaScript\'s yellow JS, Python\'s blue and yellow, the C family\'s blues; a brand with a leaf-like shape of its own keeps it, hung by its flat edge: Angular\'s, HTML5\'s and CSS3\'s shields, Vue\'s V, Ruby\'s gem · wood = the brand colour of what a limb is mostly made of · outline = git state, faded = untouched · half leaf = header or declaration, toothed = test<br>twig habits: needles = '+few('needle')+' · pairs = '+few('paired')+' · fronds = '+few('frond')+' · scales = '+few('scale')+', config · drooping = '+few('droop')+' · broad = '+few('broad')+' and the rest';}
181
+ const BRAND_WID_MIN=0.42;
182
+ function leafSize(f){const r=ratioOf(habitOf(f)),bd=badgeOf(f),wr=bd?(bd.blade?BLADE_WR[bd.blade]:Math.max(r,BRAND_WID_MIN)):r;if(f.kind!=='authored')return{len:LEAF_LEN_MIN,wid:LEAF_LEN_MIN*wr,wr};
183
+ const len=Math.max(LEAF_LEN_MIN,Math.min(LEAF_LEN_MAX,Math.sqrt(f.ln||0)));return{len,wid:len*wr,wr};}
184
+ function visLeaves(files){return WRITTEN?files.filter(f=>f.kind==='authored'):files;}
185
+ function leafJitter(f){const h=habitOf(f);return (h.ang+hash(f.p)*h.spread)*Math.PI/180;}
186
+ function leafFootprint(f,wu){const sz=leafSize(f),h=habitOf(f);
187
+ const a=sz.len/2*wu+PETIOLE_LEN*wu*h.petiole,b=sz.wid/2*wu,jit=leafJitter(f);
188
+ return 2*Math.sqrt((a*Math.cos(jit))**2+(b*Math.sin(jit))**2);}
189
+ function gapOf(f,h){return LEAF_GAP_MIN*h.gap;}
190
+ function leafZoneNeed(vis,wu){const side=[0,0],cnt=[0,0],gaps=[0,0];
191
+ vis.forEach((f,i)=>{const sd=i%2,h=habitOf(f),fp=leafFootprint(f,wu),gw=gapOf(f,h)*wu;side[sd]+=fp;
192
+ if(cnt[sd])gaps[sd]+=gw;else if(sd&&!h.pair)gaps[sd]+=(fp+gw)/2;cnt[sd]++;});
193
+ return Math.max(side[0]+gaps[0],side[1]+gaps[1]);}
194
+ function fitLeafZone(Lbase,need){const zoneBase=Lbase*(1-LEAF_ZONE_START);if(need<=zoneBase)return{L:Lbase,capped:false};
195
+ const want=need/(1-LEAF_ZONE_START),cap=Lbase*LEAF_ZONE_CAP;return want<=cap?{L:want,capped:false}:{L:cap,capped:true};}
196
+ function strandLen(Lbase,need,key){const fz=fitLeafZone(Lbase,need);if(fz.capped)CAPCOUNT++;
197
+ const f=LENF.get(key)||1;return f===1?fz.L:Math.max(Math.min(fz.L,need/(1-LEAF_ZONE_START)),fz.L*f);}
198
+ function placeLeaves(files,x,y,ang,L,out,wu,ok){const vis=visLeaves(files),m=vis.length;if(!m)return;
199
+ const zoneStart=L*LEAF_ZONE_START,zoneLen=L*(1-LEAF_ZONE_START),cum=[0,0];
200
+ const fps=vis.map(f=>leafFootprint(f,wu)),hs=vis.map(habitOf),sumFP=[0,0],sumGap=[0,0],cnt=[0,0];
201
+ vis.forEach((f,i)=>{const sd=i%2,gw=gapOf(f,hs[i])*wu;sumFP[sd]+=fps[i];if(cnt[sd])sumGap[sd]+=gw;else if(sd&&!hs[i].pair)sumGap[sd]+=(fps[i]+gw)/2;cnt[sd]++;});
202
+ const gapScale=[0,1].map(sd=>sumGap[sd]>0?Math.min(1,(zoneLen-sumFP[sd])/sumGap[sd]):1);
203
+ let pairAt=null;
204
+ for(let i=0;i<m;i++){const f=vis[i],h=hs[i],sd=i%2,sz=leafSize(f),lenW=sz.len*wu,widW=sz.wid*wu,fp=fps[i],gapW=gapOf(f,h)*wu*gapScale[sd];
205
+ if(cum[sd]>0)cum[sd]+=gapW;else if(sd&&!h.pair)cum[sd]=(fp+gapW)/2;let posAlong=zoneStart+cum[sd]+fp/2;cum[sd]+=fp;
206
+ if(sd&&h.pair&&pairAt!==null){posAlong=pairAt;cum[sd]=Math.max(cum[sd],pairAt-zoneStart+fp/2);}
207
+ pairAt=(!sd&&h.pair)?posAlong:null;
208
+ const t=Math.min(0.995,Math.max(0.05,posAlong/Math.max(1e-6,L))),ax=x+L*t*Math.cos(ang),ay=y+L*t*Math.sin(ang);
209
+ const rad=leafJitter(f),leafAng=ang+(sd?-1:1)*rad,petW=PETIOLE_LEN*wu*h.petiole;
210
+ const px=ax+petW*Math.cos(leafAng),py=ay+petW*Math.sin(leafAng);
211
+ const cx=px+(lenW/2)*Math.cos(leafAng),cy=py+(lenW/2)*Math.sin(leafAng);
212
+ out.push({t:'l',o:ok,p:f.p,f,x:cx,y:cy,ax,ay,px,py,ang:leafAng,len:lenW,wid:widW,wr:sz.wr,r:Math.max(lenW,widW)/2});}}
213
+ function drawTwig(group,dirPath,key,bx,by,ang,parentLen,out,wu){const Lbase=Math.max(10,parentLen*0.55),{st,hot,ln,ln0,tl}=groupState(group.files),dom=dominant(tl);
214
+ const vis=visLeaves(group.files),L=strandLen(Lbase,leafZoneNeed(vis,wu),key);
215
+ const ex=bx+L*Math.cos(ang),ey=by+L*Math.sin(ang);
216
+ out.push({t:'g',k:key,p:dirPath,n:group.label,c:group.files.length,st,hot,ln,ln0,lb:ln,lt:0,files:group.files,tech:dom?dom.name:null,hb:dom?dom.habit:'broad',x1:bx,y1:by,x2:ex,y2:ey,w:1,w2:1});
217
+ placeLeaves(group.files,bx,by,ang,L,out,wu,key);}
218
+ function sameKeys(a,b){if(a.length!==b.length)return false;const s=new Set(a);for(const k of b)if(!s.has(k))return false;return true;}
219
+ function fanOrder(items){const left=[],right=[];items.forEach((it,i)=>{if(i)(i%2?right:left).push(it);});return left.reverse().concat(items.length?[items[0]]:[],right);}
220
+ function fanFractions(order){const fan=fanOrder(order),sum=fan.reduce((a,it)=>a+it.w,0)||1,fr={};let acc=-0.5;for(const it of fan){const sec=it.w/sum;fr[it.key]=acc+sec/2;acc+=sec;}return fr;}
221
+ function outerEdge(fr){const xs=Object.values(fr),left=xs.filter(x=>x<0),right=xs.filter(x=>x>0),side=left.length<right.length?-1:1,far=side<0?Math.min(0,...left):Math.max(0,...right);return (far+side*0.5)/2;}
222
+ function orderItems(path,items,lnTotal){if(COUNTL)LSTAT.total++;const cached=LCACHE.get(path);
223
+ if(cached){const lnChanged=cached.ln>0?Math.abs(lnTotal-cached.ln)/cached.ln>0.1:lnTotal>0;
224
+ if(!lnChanged){if(COUNTL)LSTAT.hit++;const fr=Object.assign({},cached.fr);for(const it of items)if(!(it.key in fr))fr[it.key]=outerEdge(fr);
225
+ LCACHE.set(path,{ln:cached.ln,fr});for(const it of items)it.fr=fr[it.key];return items;}}
226
+ const order=items.slice().sort((a,b)=>b.size-a.size||hash(a.key)-hash(b.key));for(const it of order)it.w=Math.sqrt(1+it.breadth);
227
+ const fr=fanFractions(order);LCACHE.set(path,{ln:lnTotal,fr});for(const it of items)it.fr=fr[it.key];return items;}
228
+
229
+ function wrapAng(a){return a-TAU*Math.round(a/TAU);}
230
+ function layout(n,x,y,ang,depth,out,wu){
231
+ const Lbase=Math.max(12,30*Math.pow(0.8,depth)*Math.log2(n.c+1));
232
+ const fs=n.f.slice().sort((a,b)=>a.p<b.p?-1:1),dirBase=n.n==='root'?DATA.name:n.n,groups=groupLeaves(dirBase,fs);
233
+ const leafFiles=groups?[]:fs,L=strandLen(Lbase,leafZoneNeed(visLeaves(leafFiles),wu),n.p);
234
+ const tx=x+L*Math.cos(ang),ty=y+L*Math.sin(ang);
235
+ const kids=Object.keys(n.d).map(k=>({kind:'d',node:n.d[k],size:n.d[k].ln||0,breadth:n.d[k].c,key:n.d[k].p})),twigs=(groups||[]).map(g=>({kind:'g',group:g,size:groupState(g.files).ln,breadth:g.files.length,key:n.p+'::'+g.key}));
236
+ const dom=dominant(n.tl),hb=dom?dom.habit:'broad',form=FORM[hb];
237
+ const items=orderItems(n.p,kids.concat(twigs),n.ln||0),SP=(depth===0?150:depth===1?90:60)*Math.PI/180*form.fan;
238
+ out.push({t:'b',k:n.p,p:n.p,n:n.n,c:n.c,st:n.st,hot:!!n.h,ln:n.ln,ln0:n.ln0,nw:n.nw,lb:n.ln||0,lt:items.reduce((a,it)=>a+it.size,0),tech:dom?dom.name:null,hb,x1:x,y1:y,x2:tx,y2:ty,w:1,w2:1});
239
+ placeLeaves(leafFiles,x,y,ang,L,out,wu,n.p);
240
+ for(const it of items){let a2=ang+it.fr*SP;a2+=form.tilt*Math.sign(a2-ang);a2+=TROPISM*wrapAng(-Math.PI/2-a2);
241
+ if(it.kind==='d')layout(it.node,tx,ty,a2,depth+1,out,wu);else drawTwig(it.group,n.p,it.key,tx,ty,a2,L,out,wu);}}
242
+ const dpart=k=>k.split('::')[0];
243
+ function related(a,b){if(a===b)return true;const A=dpart(a),B=dpart(b);if(A===B)return a===A||b===B;
244
+ return A===''||B===''||B.indexOf(A+'/')===0||A.indexOf(B+'/')===0;}
245
+ function alongT(d,g){const dx=d.g.x2-d.g.x1,dy=d.g.y2-d.g.y1,L=dx*dx+dy*dy;
246
+ return L?((g.ax-d.g.x1)*dx+(g.ay-d.g.y1)*dy)/L:1;}
247
+ function foliage(out){const m=new Map();
248
+ for(const g of out)if(g.t!=='l')m.set(g.k,{g,n:0,cx:0,cy:0,r:0});
249
+ for(const g of out)if(g.t==='l'){const d=m.get(g.o);if(d&&alongT(d,g)>=TIP_ZONE){d.n++;d.cx+=g.x;d.cy+=g.y;}}
250
+ for(const d of m.values())if(d.n){d.cx/=d.n;d.cy/=d.n;}
251
+ for(const g of out)if(g.t==='l'){const d=m.get(g.o);if(d&&d.n&&alongT(d,g)>=TIP_ZONE)d.r=Math.max(d.r,Math.hypot(g.x-d.cx,g.y-d.cy)+g.r);}
252
+ return [...m.values()].filter(d=>d.n>0);}
253
+ // a pair only survives when the two circles overlap, so sweeping by left edge finds every one
254
+ // of them; the full pairwise scan was 56% of relayout on a 7,000-file repo (2026-09-13)
255
+ function nearPairs(list){const n=list.length,out=[],ang=new Array(n),order=new Array(n),live=[];
256
+ for(let i=0;i<n;i++){const g=list[i].g;ang[i]=Math.atan2(g.y2-g.y1,g.x2-g.x1);order[i]=i;}
257
+ order.sort((p,q)=>(list[p].cx-list[p].r)-(list[q].cx-list[q].r));
258
+ for(const j of order){const lo=list[j].cx-list[j].r;let w=0;
259
+ for(let k=0;k<live.length;k++){const i=live[k];if(list[i].cx+list[i].r>=lo)live[w++]=i;}
260
+ live.length=w;
261
+ for(let k=0;k<w;k++){const i=live[k],ai=i<j?i:j,bi=i<j?j:i,a=list[ai],b=list[bi];
262
+ if(related(a.g.k,b.g.k))continue;
263
+ let dd=Math.abs(ang[ai]-ang[bi])%TAU;if(dd>Math.PI)dd=TAU-dd;if(dd>TIP_ANG)continue;
264
+ const gap=a.r+b.r-Math.hypot(a.cx-b.cx,a.cy-b.cy);if(gap<=0)continue;
265
+ out.push({a,b,aa:ang[ai],ab:ang[bi],gap});}
266
+ live.push(j);}
267
+ return out.sort((p,q)=>q.gap-p.gap||(p.a.g.k<q.a.g.k?-1:p.a.g.k>q.a.g.k?1:p.b.g.k<q.b.g.k?-1:1));}
268
+ function stagger(out){const seen=new Set();let changed=false;
269
+ for(const P of nearPairs(foliage(out))){const aLight=P.a.g.lb<P.b.g.lb||(P.a.g.lb===P.b.g.lb&&P.a.g.k>P.b.g.k);
270
+ const lt=aLight?P.a:P.b,hv=aLight?P.b:P.a,ang=aLight?P.aa:P.ab;
271
+ if(seen.has(lt.g.k))continue;
272
+ const ux=Math.cos(ang),uy=Math.sin(ang),vx=lt.cx-hv.cx,vy=lt.cy-hv.cy;
273
+ const len=Math.hypot(lt.g.x2-lt.g.x1,lt.g.y2-lt.g.y1)||1,f0=LENF.get(lt.g.k)||1;
274
+ const R=lt.r+hv.r,q=vx*ux+vy*uy,root=Math.sqrt(Math.max(0,q*q-(vx*vx+vy*vy)+R*R));
275
+ const cl=f=>Math.max(LEN_LO,Math.min(LEN_HI,f)),sep=f=>{const d=len*(f/f0-1);return Math.hypot(vx+d*ux,vy+d*uy);};
276
+ const up=cl(f0*(1+(root-q)/len)),dn=cl(f0*(1-(root+q)/len)),f=sep(up)>=sep(dn)?up:dn;
277
+ seen.add(lt.g.k);
278
+ if(Math.abs(f-f0)>1e-3){LENF.set(lt.g.k,f);changed=true;}}
279
+ return changed;}
280
+ // a pairwise scan of every leaf, for two counters the page never draws: 38% of relayout on a
281
+ // 7,000-file repo, so the lab asks for it by setting window.__tally (2026-09-13)
282
+ function tally(){if(!window.__tally)return;const leaves=HITS.filter(g=>g.t==='l');let lh=0;
283
+ const rad=(g,phi)=>{const a=Math.max(0.5,g.len/2),b=Math.max(0.5,g.wid/2),c=Math.cos(phi-g.ang),s=Math.sin(phi-g.ang);return a*b/Math.sqrt(Math.pow(b*c,2)+Math.pow(a*s,2));};
284
+ for(let i=0;i<leaves.length;i++)for(let j=i+1;j<leaves.length;j++){const A=leaves[i],B=leaves[j];if(A.o===B.o)continue;
285
+ const dx=B.x-A.x,dy=B.y-A.y,d=Math.hypot(dx,dy);if(d>A.len+B.len)continue;const phi=Math.atan2(dy,dx);
286
+ if(d<rad(A,phi)+rad(B,phi+Math.PI))lh++;}
287
+ window.__leafHits=lh;window.__tipHits=nearPairs(foliage(HITS)).length;}
288
+ function bboxOf(out){let x0=1e9,y0=1e9,x1=-1e9,y1=-1e9;
289
+ for(const g of out)for(const q of (g.t==='l'?[[g.x,g.y]]:[[g.x1,g.y1],[g.x2,g.y2]])){x0=Math.min(x0,q[0]);x1=Math.max(x1,q[0]);y0=Math.min(y0,q[1]);y1=Math.max(y1,q[1]);}
290
+ return{x0,y0,x1,y1};}
291
+ function scaleFor(box,W,H){const pad=22;return Math.min(2.5,(W-2*pad)/Math.max(1,box.x1-box.x0),(H-2*pad)/Math.max(1,box.y1-box.y0));}
292
+ function fitBox(out,W,H,s){const box=bboxOf(out),pad=22,bw=(box.x1-box.x0)*s,ox=Math.max((W-bw)/2,W-pad-bw)-box.x0*s,oy=H-pad-box.y1*s;
293
+ let trunk=0;for(const g of out)if(g.t!=='l')trunk=Math.max(trunk,g.lb||0);const cw=(TRUNK_W-1)/Math.sqrt(Math.max(1,trunk));
294
+ for(const g of out){if(g.t==='l'){g.ax=g.ax*s+ox;g.ay=g.ay*s+oy;g.px=g.px*s+ox;g.py=g.py*s+oy;
295
+ g.len=Math.max(LEAF_LEN_MIN,Math.min(LEAF_LEN_MAX,g.len*s));g.wid=g.len*g.wr;g.r=Math.max(g.len,g.wid)/2;
296
+ g.x=g.px+g.len/2*Math.cos(g.ang);g.y=g.py+g.len/2*Math.sin(g.ang);
297
+ }else{g.x1=g.x1*s+ox;g.y1=g.y1*s+oy;g.x2=g.x2*s+ox;g.y2=g.y2*s+oy;g.w=1+cw*Math.sqrt(Math.max(0,g.lb));g.w2=1+cw*Math.sqrt(Math.max(0,g.lt));}}}
298
+ function darken(hex,f){const m=/^#?([0-9a-f]{6})$/i.exec(String(hex).trim());if(!m)return hex;const n=parseInt(m[1],16);
299
+ return 'rgb('+Math.round(((n>>16)&255)*f)+','+Math.round(((n>>8)&255)*f)+','+Math.round((n&255)*f)+')';}
300
+ function leafDim(f){const authored=f.kind==='authored',grow=authored&&(f.ln>(f.ln0||0)||(f.ln0||0)===0);return !authored||((f.s==='D'||f.s==='F'||!filters[f.s])&&!grow);}
301
+ function drawBrandLeaf(b,g,badge){const f=g.f,s=f.s,authored=f.kind==='authored',len=g.len,halfW=g.wid/2;
302
+ const grow=authored&&(f.ln>(f.ln0||0)||(f.ln0||0)===0),dim=leafDim(f),stale=authored&&s!=='F'&&age(f)>86400&&(f.ln0||0)>0;
303
+ b.save();b.globalAlpha=(dim?0.5:1)*(stale?0.7:1);
304
+ b.strokeStyle=brandOf(techOf(f).name)||'#888';b.lineWidth=1;b.beginPath();b.moveTo(g.ax,g.ay);b.lineTo(g.px,g.py);b.stroke();
305
+ b.translate(g.px,g.py);b.rotate(g.ang);
306
+ brandBlade(b,badge,g,len,halfW,!authored,g.ang);
307
+ if(authored){bladePath(b,badge,g,len,halfW,0,0);if(dim){b.strokeStyle=darken(badge.bg,0.72);b.lineWidth=0.8;}else{b.strokeStyle=grow?CC.A:CC[s];b.lineWidth=Math.max(1,len*0.05);}b.stroke();}
308
+ if(badge.blade&&authored&&len>=12&&roleOf(f).role==='test'){b.strokeStyle=badge.fg||'#fff';b.lineWidth=Math.max(1,len*0.06);b.beginPath();b.moveTo(len*0.7,halfW*0.05);b.lineTo(len*0.78,halfW*0.35);b.lineTo(len*0.92,-halfW*0.15);b.stroke();}
309
+ if(authored&&(f.ln||0)>WARN_LINES){bladePath(b,badge,g,len,halfW,2,1);b.lineWidth=1.2;b.strokeStyle=CC.D;b.stroke();}
310
+ if(g.hotspot){b.setLineDash([2.2,2.2]);b.lineWidth=1.2;b.strokeStyle=CC.U;bladePath(b,badge,g,len,halfW,4,2);b.stroke();b.setLineDash([]);}
311
+ b.restore();}
312
+ function drawLeaf(b,g){const f=g.f,s=f.s,len=g.len,halfW=g.wid/2,authored=f.kind==='authored',badge=badgeOf(f);if(badge)return drawBrandLeaf(b,g,badge);
313
+ const grow=authored&&(f.ln>(f.ln0||0)||(f.ln0||0)===0),base=authored?(grow?CC.A:CC[s]):CC[s],dark=leafStroke(f,base);
314
+ const dim=leafDim(f),w1=!authored?1:(s==='F'?0.8:1.2);
315
+ const stale=authored&&s!=='F'&&age(f)>86400&&(f.ln0||0)>0,op=stale?0.55:1;
316
+ b.save();b.globalAlpha=op;b.strokeStyle=dark;b.lineWidth=w1;
317
+ b.beginPath();b.moveTo(g.ax,g.ay);b.lineTo(g.px,g.py);b.stroke();
318
+ b.translate(g.px,g.py);b.rotate(g.ang);
319
+ leafPath(b,g,len,halfW,0,0);
320
+ if(!dim){b.fillStyle=base;b.fill();}
321
+ b.lineWidth=dim?w1:1;b.stroke();
322
+ b.beginPath();b.moveTo(0,0);b.lineTo(len,0);b.lineWidth=1;b.stroke();
323
+ if(authored){const ln=f.ln||0;if(ln>WARN_LINES){leafPath(b,g,len,halfW,0,0);b.lineWidth=2;b.strokeStyle=CC.D;b.stroke();}}
324
+ if(g.hotspot){b.setLineDash([2.2,2.2]);b.lineWidth=1.2;b.strokeStyle=CC.U;leafPath(b,g,len,halfW,2,3);b.stroke();b.setLineDash([]);}
325
+ b.restore();}
326
+ function markHotspots(){const cand=HITS.filter(g=>g.t==='l'&&g.f.kind==='authored'&&(g.f.ch||0)>=2).sort((a,b)=>(b.f.ch*b.f.ln)-(a.f.ch*a.f.ln));
327
+ const cut=cand.length?Math.min(cand.length,Math.max(3,Math.ceil(cand.length*0.05))):0,hot=cand.slice(0,cut);
328
+ for(let i=0;i<cut;i++)hot[i].hotspot=true;
329
+ for(const g of HITS){if(g.t==='b'){const h=hot.find(l=>l.f.p.startsWith(g.p?g.p+'/':''));g.hottest=h?baseName(h.f.p):null;}
330
+ else if(g.t==='g'){const h=hot.find(l=>g.files&&g.files.includes(l.f));g.hottest=h?baseName(h.f.p):null;}}}
331
+ function blend(a,c,f){const A=parseInt(a.slice(1),16),C=parseInt(c.slice(1),16),m=(x,y)=>Math.round(x*(1-f)+y*f);
332
+ return '#'+[16,8,0].map(sh=>m((A>>sh)&255,(C>>sh)&255).toString(16).padStart(2,'0')).join('');}
333
+ function woodOf(tech){const own=brandOf(tech);return own?blend(own,CC.wood,0.3):CC.wood;}
334
+ function segGeom(g){const a=Math.atan2(g.y2-g.y1,g.x2-g.x1),nx=-Math.sin(a)/2,ny=Math.cos(a)/2;return{a,nx,ny};}
335
+ function segPath(b,g){const {a,nx,ny}=segGeom(g),h=Math.PI/2;b.moveTo(g.x1+nx*g.w,g.y1+ny*g.w);b.lineTo(g.x2+nx*g.w2,g.y2+ny*g.w2);
336
+ b.arc(g.x2,g.y2,g.w2/2,a+h,a-h,true);b.lineTo(g.x1-nx*g.w,g.y1-ny*g.w);b.arc(g.x1,g.y1,g.w/2,a-h,a+h,true);b.closePath();}
337
+ function segSides(b,g){const {nx,ny}=segGeom(g);b.moveTo(g.x1+nx*g.w,g.y1+ny*g.w);b.lineTo(g.x2+nx*g.w2,g.y2+ny*g.w2);b.moveTo(g.x2-nx*g.w2,g.y2-ny*g.w2);b.lineTo(g.x1-nx*g.w,g.y1-ny*g.w);}
338
+ function drawBase(b){b.lineCap='round';b.lineJoin='round';const groups=new Map();
339
+ for(const g of HITS){if(g.t!=='b'&&g.t!=='g')continue;const key=woodOf(g.tech)+'|'+((g.hot?1:0.38)*(g.t==='g'?0.7:1));if(!groups.has(key))groups.set(key,[]);groups.get(key).push(g);}
340
+ for(const [key,segs] of groups){const [wood,alpha]=key.split('|');b.globalAlpha=+alpha;b.fillStyle=wood;b.beginPath();for(const g of segs)segPath(b,g);b.fill();
341
+ b.strokeStyle=darken(wood,0.72);b.lineWidth=0.6;b.beginPath();for(const g of segs)if(g.w>2.5)segSides(b,g);b.stroke();}
342
+ b.globalAlpha=1;const leaves=HITS.filter(g=>g.t==='l').sort((p,q)=>q.len-p.len);for(const g of leaves)drawLeaf(b,g);}
343
+ function halos(){const t=Date.now()/1000;
344
+ for(const g of HITS){if(g.t!=='l'||g.f.kind!=='authored')continue;const a=age(g.f);if(a>60)continue;
345
+ const osc=RM?0.6:0.5+0.5*Math.sin(t*3.2+g.x*0.07);const rad=a<10?g.r*(2.1+osc*1.3):g.r*2.1;
346
+ X.globalAlpha=a<10?0.45:Math.max(0.08,0.42*(1-(a-10)/50));X.fillStyle=CC[g.f.s];X.beginPath();X.arc(g.x*VIEW.s+VIEW.x,g.y*VIEW.s+VIEW.y,rad,0,TAU);X.fill();}X.globalAlpha=1;}
347
+ function hilite(){if(!HOVER)return;const rp=FOCUS||'',tp=HOVER.t==='l'?dirOf(HOVER.p):HOVER.p;X.strokeStyle=CC.accent;X.lineCap='round';
348
+ for(const g of HITS)if(g.t==='b'&&(g.p===rp||tp===g.p||tp.startsWith(g.p+'/'))){const x1=g.x1*VIEW.s+VIEW.x,y1=g.y1*VIEW.s+VIEW.y,x2=g.x2*VIEW.s+VIEW.x,y2=g.y2*VIEW.s+VIEW.y;X.beginPath();X.moveTo(x1,y1);X.lineTo(x2,y2);X.globalAlpha=0.3;X.lineWidth=(g.w+6)*VIEW.s;X.stroke();X.globalAlpha=1;X.lineWidth=Math.min(2.2,g.w*0.5+0.6)*VIEW.s;X.stroke();}
349
+ X.lineWidth=1.6*VIEW.s;X.beginPath();const hx=HOVER.t==='l'?HOVER.x:HOVER.x2,hy=HOVER.t==='l'?HOVER.y:HOVER.y2;X.arc(hx*VIEW.s+VIEW.x,hy*VIEW.s+VIEW.y,(HOVER.t==='l'?HOVER.r*2.4:5)*VIEW.s,0,TAU);X.stroke();}
350
+ const VECTOR_ZOOM=1.4,VECTOR_HITS=2500;
351
+ function paint(){const r=cv.getBoundingClientRect();X.setTransform(DPR,0,0,DPR,0,0);X.clearRect(0,0,r.width,r.height);
352
+ if(BASE){X.setTransform(DPR*VIEW.s,0,0,DPR*VIEW.s,DPR*VIEW.x,DPR*VIEW.y);
353
+ if(VIEW.s>VECTOR_ZOOM&&HITS.length<=VECTOR_HITS){DRAW_ZOOM=VIEW.s;drawBase(X);DRAW_ZOOM=1;}else X.drawImage(BASE,0,0,r.width,r.height);
354
+ X.setTransform(DPR,0,0,DPR,0,0);}
355
+ halos();hilite();}
356
+ // stagger's factors are scratch for one layout, and reflow already threw them away; a direct
357
+ // relayout did not, so it resumed a relaxation the cap had left unfinished and the same snapshot
358
+ // drew differently every pass (2026-09-14)
359
+ function relayout(){if(!DATA)return;LENF=new Map();const r=cv.getBoundingClientRect();W=Math.max(240,r.width);H=Math.max(240,r.height);DPR=devicePixelRatio||1;
360
+ cv.width=W*DPR;cv.height=H*DPR;CC={wood:cssv('wood'),accent:cssv('orange'),dark:matchMedia('(prefers-color-scheme: dark)').matches?document.documentElement.dataset.theme!=='light':document.documentElement.dataset.theme==='dark'};CC.edge=CC.dark?'rgba(255,255,255,.45)':'#fff';for(const k in KEY)CC[k]=cssv(KEY[k]);
361
+ TREE=build(DATA.files);let root=sub(TREE,FOCUS);if(!root){FOCUS=null;root=TREE;}
362
+ LSTAT={hit:0,total:0};let s=SCALE_SEED,out=[];
363
+ const place=()=>{CAPCOUNT=0;out=[];layout(root,0,0,-Math.PI/2,0,out,1/s);COUNTL=false;},run=()=>{place();s=scaleFor(bboxOf(out),W,H);};
364
+ COUNTL=true;for(let it=0;it<3;it++)run();
365
+ for(let it=0;it<LEN_PASSES&&stagger(out);it++)run();
366
+ const want=s*SCALE_SLACK;s=(SCALE_KEPT&&SCALE_KEPT<=s&&SCALE_KEPT>=want*0.85)?SCALE_KEPT:want;SCALE_KEPT=s;place();
367
+ HITS=out;fitBox(HITS,W,H,s);markHotspots();tally();window.__hits=HITS;window.__leafCap=CAPCOUNT;
368
+ BASE=document.createElement('canvas');BASE.width=W*DPR;BASE.height=H*DPR;const b=BASE.getContext('2d');b.setTransform(DPR,0,0,DPR,0,0);drawBase(b);indexHits();HOVER=resolveHover(HOVER);if(!HOVER)showTip(null);crumb(root);treelist.render();paint();}
369
+ function segd(mx,my,g){const dx=g.x2-g.x1,dy=g.y2-g.y1,L=dx*dx+dy*dy;let t=L?((mx-g.x1)*dx+(my-g.y1)*dy)/L:0;t=Math.max(0,Math.min(1,t));return Math.hypot(mx-(g.x1+t*dx),my-(g.y1+t*dy));}
370
+ function leafHitD(lx,ly,g){const dx=lx-g.x,dy=ly-g.y,ca=Math.cos(-g.ang),sa=Math.sin(-g.ang),rx=dx*ca-dy*sa,ry=dx*sa+dy*ca,a=Math.max(1,g.len/2),bb=Math.max(1,g.wid/2),nd=Math.hypot(rx/a,ry/bb);return(nd-1)*Math.min(a,bb);}
371
+ function hitTest(mx,my,reach){const lx=(mx-VIEW.x)/VIEW.s,ly=(my-VIEW.y)/VIEW.s;let best=null,bd=6+(reach||0)/VIEW.s,bt=1;for(const g of HITS){const d=g.t==='l'?leafHitD(lx,ly,g):segd(lx,ly,g)-g.w/2,t=g.t==='l'&&d<0?0:1;if(t<bt||(t===bt&&d<bd)){bt=t;bd=d;best=g;}}return best;}
372
+ function subjectLine(f){let s=f.m||'';if(!s)return '';const dir=dirOf(f.p),pfx=s.startsWith(f.p+': ')?f.p+': ':(dir&&s.startsWith(dir+': ')?dir+': ':null);return pfx?s.slice(pfx.length):s;}
373
+ function tallyHTML(st){return ORDER.filter(k=>k!=='F'&&st[k]).map(k=>'<span><i class="dot" style="background:'+CC[k]+'"></i>'+st[k]+'</span>').join('');}
374
+ function lineNote(f){const ln=f.ln||0,ln0=f.ln0||0;if(f.s==='D')return'';
375
+ const c=f.ch?' · '+f.ch+(f.ch===1?' commit':' commits'):'',k=f.kind&&f.kind!=='authored'?' · '+f.kind:'',tech=techOf(f),role=roleOf(f).word,tn=(tech||role)?' · '+[tech?tech.name:'',role].filter(Boolean).join(' '):'';
376
+ if(ln0===0)return' · '+ln.toLocaleString()+' lines (+'+ln.toLocaleString()+' since start)'+tn+k+c;
377
+ const d=ln-ln0;return' · '+ln.toLocaleString()+' lines ('+(d>=0?'+':'')+d.toLocaleString()+')'+tn+k+c;}
378
+ function showTip(g,px,py){if(!g){tip.style.display='none';return;}
379
+ let html;
380
+ if(g.t==='l'){const f=g.f,dir=dirOf(f.p),name=f.p.split('/').pop(),subject=subjectLine(f);
381
+ html='<div class="name">'+esc(name)+'</div><div class="path">'+esc(dir)+'</div><div class="state"><span><i class="dot" style="background:'+CC[f.s]+'"></i>'+NAMES[f.s]+lineNote(f)+'</span>'+(f.s==='F'?'':'<span class="when">'+ago(age(f))+'</span>')+'</div>'+(subject?'<div class="subject">'+esc(subject)+'</div>':'');
382
+ }else{const label=g.t==='g'?g.n:(g.p?g.n:DATA.name),L=g.ln||0,G=L-(g.ln0||0);
383
+ html='<div class="name">'+esc(label)+'</div><div class="path">'+esc(g.p)+'</div><div class="files">'+g.c+' files · '+L.toLocaleString()+' authored lines ('+(G>=0?'+':'')+G.toLocaleString()+' since start)'+(g.tech?' · mostly '+esc(g.tech):'')+(g.hottest?' · hottest: '+esc(g.hottest):'')+'</div><div class="tally">'+tallyHTML(g.st||{})+'</div>';}
384
+ const tb=g.t==='l'?badgeOf(g.f):(g.tech&&BADGE[g.tech]);
385
+ tip.innerHTML=(tb?'<canvas class="tipicon" width="44" height="44"></canvas>':'')+html;tip.style.display='block';
386
+ if(tb){const c=tip.querySelector('canvas.tipicon'),x=c.getContext('2d');x.setTransform(2,0,0,2,0,0);drawBrandMini(x,tb,22);}
387
+ const r=cv.getBoundingClientRect();let left=px+14,top=py+14;tip.style.left=left+'px';tip.style.top=top+'px';
388
+ const tw=tip.offsetWidth,th=tip.offsetHeight;if(left+tw>r.right)left=px-14-tw;if(top+th>r.bottom)top=py-14-th;
389
+ tip.style.width=Math.min(300,r.width-24)+'px';const w=tip.offsetWidth,h=tip.offsetHeight;
390
+ tip.style.left=Math.max(r.left+8,Math.min(left,r.right-w-8))+'px';tip.style.top=Math.max(r.top+8,Math.min(top,r.bottom-h-8))+'px';}
391
+ function crumb(node){const parts=FOCUS?FOCUS.split('/'):[];let h='<button data-p="">'+esc(DATA.name)+'</button>',acc='';for(const p of parts){acc=acc?acc+'/'+p:p;h+=' › <button data-p="'+esc(acc)+'">'+esc(p)+'</button>';}document.getElementById('crumb').innerHTML=h;
392
+ const L=node.ln||0,G=L-(node.ln0||0);
393
+ document.getElementById('treestats').textContent=(node.cl||0)+' files · '+L.toLocaleString()+' authored lines · +'+(node.nw||0)+' files '+(G>=0?'+':'')+G.toLocaleString()+' authored lines since '+fmt(DATA.start)+' · layout: '+LSTAT.hit+' of '+LSTAT.total+' kept';}
394
+ function stats(list){const s={};for(const f of list)s[f.s]=(s[f.s]||0)+1;return s;}
395
+ function aside(){const s=stats(DATA.files);let h='';for(const k of ORDER)if(k in s)h+='<span>'+NAMES[k]+'</span><b>'+s[k]+'</b>';
396
+ document.getElementById('counts').innerHTML=h;
397
+ document.getElementById('since').innerHTML='<span>added</span><b>'+DATA.files.filter(f=>f.nw).length+'</b><span>modified</span><b>'+(s.M||0)+'</b><span>deleted</span><b>'+(s.D||0)+'</b><span>tree</span><b>'+DATA.files.filter(f=>f.s!=='D').length+' files, was '+DATA.start_tracked+'</b>';
398
+ document.getElementById('recent').innerHTML=DATA.files.filter(f=>age(f)<60).sort((a,b)=>b.mt-a.mt).slice(0,12).map(f=>'<li><button data-p="'+esc(dirOf(f.p))+'" title="'+esc(f.p)+'">'+esc(f.p.split('/').pop())+'</button><span class="age">'+ago(age(f))+'</span></li>').join('');
399
+ document.getElementById('stamp').textContent='snapshot '+fmt(DATA.generated)+' · '+DATA.tracked+' tracked · '+DATA.changed+' touched since '+fmt(DATA.start);
400
+ madeOf();}
401
+ function madeOf(){const node=(TREE&&sub(TREE,FOCUS))||TREE;if(!node)return;const tl=node.tl||{},total=Object.values(tl).reduce((a,b)=>a+b,0)||1;
402
+ const rows=Object.keys(tl).filter(k=>k).sort((a,b)=>tl[b]-tl[a]).slice(0,8);
403
+ const box=document.getElementById('madeof');
404
+ box.innerHTML=rows.map(k=>'<span><canvas class="mini" width="40" height="40" data-tech="'+esc(k)+'"></canvas>'+esc(k)+'</span><b>'+Math.round(100*tl[k]/total)+'%</b>').join('')||'<span>nothing authored yet</span><b></b>';
405
+ for(const c of box.querySelectorAll('canvas.mini')){const k=c.dataset.tech,x=c.getContext('2d');x.setTransform(2,0,0,2,0,0);
406
+ if(BADGE[k])drawBrandMini(x,BADGE[k],20);else{x.setTransform(2,0,0,2,10,10);x.fillStyle=brandOf(k)||'#888';x.beginPath();x.arc(0,0,4.5,0,TAU);x.fill();}}}
407
+ function setFocus(p){const was=FOCUS;FOCUS=p||null;if(FOCUS!==was)toHost({event:'focus',path:FOCUS});TABI=-1;hover(null);VIEW.s=1;VIEW.x=0;VIEW.y=0;LCACHE=new Map();SCALE_KEPT=0;relayout();}
408
+ const ZOOM_MIN=0.5,ZOOM_MAX=8,ZOOM_STEP=1.25;
409
+ function zoomTo(ns,sx,sy){ns=Math.max(ZOOM_MIN,Math.min(ZOOM_MAX,ns));const s0=VIEW.s;VIEW.x=sx-(sx-VIEW.x)/s0*ns;VIEW.y=sy-(sy-VIEW.y)/s0*ns;VIEW.s=ns;paint();}
410
+ function zoomBy(f,sx,sy){zoomTo(VIEW.s*f,sx,sy);}
411
+ function wheelFactor(e){let d=e.deltaY;if(e.deltaMode===1)d*=16;else if(e.deltaMode===2)d*=H;d=Math.max(-100,Math.min(100,d));return Math.exp(-d*(e.ctrlKey?0.01:0.0025));}
412
+ function resetView(){VIEW.s=1;VIEW.x=0;VIEW.y=0;paint();}
413
+ cv.addEventListener('pointerdown',e=>{COARSE=e.pointerType!=='mouse';TAPFROM=[e.clientX,e.clientY];cv.setPointerCapture(e.pointerId);pts.set(e.pointerId,[e.clientX,e.clientY]);if(pts.size===1){drag={x:e.clientX,y:e.clientY,vx:VIEW.x,vy:VIEW.y,moved:0};cv.style.cursor='grabbing';}else if(pts.size===2){const v=[...pts.values()];pinchD=Math.hypot(v[0][0]-v[1][0],v[0][1]-v[1][1])||1;pinchS=VIEW.s;drag=null;}});
414
+ cv.addEventListener('pointermove',e=>{const r=cv.getBoundingClientRect();if(!pts.has(e.pointerId)){hover(hitTest(e.clientX-r.left,e.clientY-r.top),e.clientX,e.clientY);cv.style.cursor=HOVER&&HOVER.t!=='l'?'pointer':'grab';return;}
415
+ pts.set(e.pointerId,[e.clientX,e.clientY]);if(pts.size>=2){const v=[...pts.values()],d=Math.hypot(v[0][0]-v[1][0],v[0][1]-v[1][1])||1,cx=(v[0][0]+v[1][0])/2-r.left,cy=(v[0][1]+v[1][1])/2-r.top;zoomTo(pinchS*d/pinchD,cx,cy);return;}
416
+ if(drag){const dx=e.clientX-drag.x,dy=e.clientY-drag.y;drag.moved=Math.max(drag.moved,Math.hypot(dx,dy));VIEW.x=drag.vx+dx;VIEW.y=drag.vy+dy;paint();}});
417
+ function endPointer(e){pts.delete(e.pointerId);if(drag){wasDrag=drag.moved>4;drag=null;cv.style.cursor='grab';}}
418
+ cv.addEventListener('pointerup',endPointer);cv.addEventListener('pointercancel',endPointer);
419
+ // wasDrag is set so the click handler below consumes the tap: one tap reveals, the next acts (2026-09-12)
420
+ cv.addEventListener('pointerup',e=>{if(e.pointerType==='mouse'||pts.size||!TAPFROM)return;
421
+ if(Math.hypot(e.clientX-TAPFROM[0],e.clientY-TAPFROM[1])>TAP_DRIFT)return;
422
+ const r=cv.getBoundingClientRect(),g=hitTest(e.clientX-r.left,e.clientY-r.top,TAP_REACH);
423
+ TAPOWN=true;if(g&&g.t!=='l'&&sameHit(g,HOVER))setFocus(g.p);else hover(g,e.clientX,e.clientY);TAPOWN=false;wasDrag=true;});
424
+ cv.addEventListener('pointerleave',()=>{if(!pts.size){hover(null);cv.style.cursor='grab';}});
425
+ cv.addEventListener('wheel',e=>{e.preventDefault();const r=cv.getBoundingClientRect();zoomBy(wheelFactor(e),e.clientX-r.left,e.clientY-r.top);},{passive:false});
426
+ cv.addEventListener('dblclick',e=>{const r=cv.getBoundingClientRect();if(!hitTest(e.clientX-r.left,e.clientY-r.top))resetView();});
427
+ cv.addEventListener('click',()=>{if(wasDrag){wasDrag=false;return;}if(HOVER&&HOVER.t!=='l')setFocus(HOVER.p);});
428
+ document.getElementById('zoomctl').addEventListener('click',e=>{const b=e.target.closest('button[data-z]');if(!b)return;if(b.dataset.z==='in')zoomBy(ZOOM_STEP,W/2,H/2);else if(b.dataset.z==='out')zoomBy(1/ZOOM_STEP,W/2,H/2);else resetView();});
429
+ document.querySelector('#zoomctl [data-x="png"]').addEventListener('click',()=>{if(DATA)exportCanvas(QS.get('scale')).toBlob(b=>{const a=document.createElement('a');a.href=URL.createObjectURL(b);a.download=DATA.name+'.png';a.click();setTimeout(()=>URL.revokeObjectURL(a.href),1000);},'image/png');});
430
+ document.addEventListener('click',e=>{const b=e.target.closest('nav.crumb [data-p], .recent [data-p]');if(b)setFocus(b.dataset.p);});
431
+ addEventListener('keydown',e=>{if(e.key==='Escape'){setFocus(FOCUS?dirOf(FOCUS):null);}
432
+ else if(e.key==='Tab'){const bs=HITS.filter(g=>g.t==='b'||g.t==='g');if(!bs.length)return;e.preventDefault();TABI=(TABI+(e.shiftKey?-1:1)+bs.length)%bs.length;const a=anchorOf(bs[TABI]);hover(bs[TABI],a.x,a.y);}
433
+ else if(document.activeElement===cv&&(e.key==='+'||e.key==='=')){zoomBy(ZOOM_STEP,W/2,H/2);}else if(document.activeElement===cv&&e.key==='-'){zoomBy(1/ZOOM_STEP,W/2,H/2);}else if(document.activeElement===cv&&e.key==='0'){resetView();}});
434
+ function reflow(){LCACHE=new Map();relayout();}
435
+ addEventListener('resize',reflow);
436
+ function indexHits(){HIT_AT=new Map();TWIG_OF=new Map();FILE_AT=new Map(DATA.files.map(f=>[f.p,f]));
437
+ for(const g of HITS){if(g.t==='g')for(const f of g.files)TWIG_OF.set(f.p,g);else HIT_AT.set(g.p,g);}}
438
+ function resolveHover(h){if(!h)return null;return h.t==='g'?HITS.find(g=>g.t==='g'&&g.k===h.k)||null:HIT_AT.get(h.p)||null;}
439
+ function anchorOf(g){const r=cv.getBoundingClientRect(),x=g.t==='l'?g.x:(g.x1+g.x2)/2,y=g.t==='l'?g.y:(g.y1+g.y2)/2;return{x:r.left+x*VIEW.s+VIEW.x,y:r.top+y*VIEW.s+VIEW.y};}
440
+ let COARSE=false,TAPFROM=null,TAPOWN=false;
441
+ const sameHit=(a,b)=>!!a&&!!b&&(a.t==='l'?b.t==='l'&&a.f.p===b.f.p:a.p===b.p);
442
+ // touch has no leaving the element: the lift fires pointerleave, and its hover(null) wiped the tap (2026-09-12)
443
+ let TOLD='null|null';
444
+ function hover(g,px,py){if(g===null&&COARSE&&!TAPOWN)return;HOVER=g;const kind=g?(g.t==='l'?'leaf':g.t==='g'?'twig':'branch'):null,told=kind+'|'+(g?g.p:null);if(told!==TOLD){TOLD=told;toHost({event:'hover',path:g?g.p:null,kind});}showTip(g,px,py);paint();treelist.mark(g);}
445
+ const treelist={el:null,mounted:false,expanded:new Set(['']),last:null,
446
+ init(){document.getElementById('treelist-toggle').addEventListener('click',()=>this.toggle(!this.mounted));let on=false;try{on=localStorage.getItem('treespeak.treelist')==='1';}catch(e){}if(on&&!BARE)this.toggle(true);},
447
+ toggle(on){if(on)this.mount();else this.unmount();document.getElementById('treelist-toggle').setAttribute('aria-pressed',String(this.mounted));try{localStorage.setItem('treespeak.treelist',this.mounted?'1':'0');}catch(e){}},
448
+ mount(){if(this.mounted)return;const wrap=document.querySelector('.cvwrap');this.el=document.createElement('nav');this.el.id='treelist';this.el.setAttribute('aria-label','file tree');this.bind();wrap.insertBefore(this.el,wrap.firstChild);wrap.classList.add('listing');this.mounted=true;this.render();relayout();},
449
+ unmount(){if(!this.mounted)return;this.el.closest('.cvwrap').classList.remove('listing');this.el.remove();this.el=null;this.last=null;this.mounted=false;relayout();},
450
+ inside(p){return !FOCUS||p===FOCUS||p.startsWith(FOCUS+'/');},
451
+ onPath(p){return !!FOCUS&&(p===''||FOCUS.startsWith(p+'/'));},
452
+ rows(node,depth,out){const p=node.p,open=this.expanded.has(p),cls=(FOCUS&&p===FOCUS?' focus':'')+(!this.inside(p)&&!this.onPath(p)?' off':'');
453
+ out.push('<div class="row d'+cls+'" data-p="'+esc(p)+'" data-kind="d" style="--depth:'+depth+'">'+(p===''?'<span class="disc root"></span>':'<button class="disc" aria-expanded="'+open+'" aria-label="'+(open?'collapse':'expand')+'"></button>')+'<button class="name">'+esc(p?node.n:DATA.name)+'</button><span class="fig">'+node.c+'</span></div>');
454
+ if(!open)return;
455
+ for(const k of Object.keys(node.d).sort())this.rows(node.d[k],depth+1,out);
456
+ for(const f of node.f.slice().sort((a,b)=>a.p<b.p?-1:1)){const authored=f.kind==='authored',fc=(authored?'':' hollow')+(authored&&leafDim(f)?' dim':'')+(this.inside(p)?'':' off');
457
+ out.push('<div class="row f'+fc+'" data-p="'+esc(f.p)+'" data-kind="f" style="--depth:'+(depth+1)+'"><i class="dot" style="background:'+CC[f.s]+'"></i><button class="name">'+esc(baseName(f.p))+'</button><span class="fig">'+(authored?(f.ln||0):'')+'</span></div>');}},
458
+ render(){if(!this.mounted||!TREE)return;const top=this.el.scrollTop,out=[],had=document.activeElement,keep=had&&this.el.contains(had)?{p:had.closest('.row').dataset.p,cls:had.className}:null;
459
+ this.rows(TREE,0,out);this.el.innerHTML=out.join('');this.el.scrollTop=top;this.last=null;this.applyMarks(HOVER);
460
+ if(keep){const b=this.rowEl(keep.p)?.querySelector('.'+keep.cls);if(b)b.focus({preventScroll:true});}},
461
+ rowEl(p){return this.el.querySelector('.row[data-p="'+CSS.escape(p)+'"]');},
462
+ ancestors(g){const dirs=p=>{const a=[];for(let d=p;d;d=dirOf(d))a.push(d);a.push('');return a;};
463
+ return g.t==='l'?dirs(dirOf(g.p)):g.t==='g'?dirs(g.p):dirs(dirOf(g.p));},
464
+ reveal(paths){let grew=false;for(const p of paths)if(!this.expanded.has(p)){this.expanded.add(p);grew=true;}if(grew)this.render();},
465
+ applyMarks(g){for(const r of this.el.querySelectorAll('.row.hl'))r.classList.remove('hl');if(!g)return null;
466
+ const paths=g.t==='g'?[g.p,...g.files.map(f=>f.p)]:[g.p];let first=null;
467
+ for(const p of paths){const r=this.rowEl(p);if(r){r.classList.add('hl');if(!first)first=r;}}return first;},
468
+ mark(g){if(!this.mounted)return;if(g)this.reveal(this.ancestors(g));const row=this.applyMarks(g);if(row)this.scrollTo(row);},
469
+ scrollTo(row){const el=this.el,er=el.getBoundingClientRect(),rr=row.getBoundingClientRect(),top=rr.top-er.top+el.scrollTop,bot=top+rr.height;
470
+ if(top<el.scrollTop)el.scrollTop=top;else if(bot>el.scrollTop+el.clientHeight)el.scrollTop=bot-el.clientHeight;},
471
+ tipNode(p){const f=FILE_AT.get(p);return f?{t:'l',f}:sub(TREE,p);},
472
+ hoverRow(p){const g=HIT_AT.get(p)||TWIG_OF.get(p);if(g){const a=anchorOf(g);hover(g,a.x,a.y);return;}
473
+ HOVER=null;paint();this.applyMarks(null);showTip(null);const row=this.rowEl(p);if(!row)return;row.classList.add('hl');const rr=row.getBoundingClientRect(),n=this.tipNode(p);if(n)showTip(n,rr.right+8,rr.top);},
474
+ bind(){const el=this.el;
475
+ el.addEventListener('pointerover',e=>{const row=e.target.closest('.row');if(!row||row.dataset.p===this.last)return;this.last=row.dataset.p;this.hoverRow(row.dataset.p);});
476
+ el.addEventListener('pointerleave',()=>{this.last=null;hover(null);});
477
+ el.addEventListener('focusin',e=>{const row=e.target.closest('.row');if(row)this.hoverRow(row.dataset.p);});
478
+ el.addEventListener('click',e=>{const row=e.target.closest('.row');if(!row)return;const p=row.dataset.p;
479
+ if(e.target.closest('button.disc')){if(this.expanded.has(p))this.expanded.delete(p);else this.expanded.add(p);this.render();return;}
480
+ if(e.target.closest('.name'))setFocus(row.dataset.kind==='d'?p:dirOf(p));});}};
481
+ function controls(){const c=document.getElementById('ctl');c.innerHTML='<button class="pill" aria-pressed="true" data-w="1"><i class="sw" style="background:var(--wood)"></i>written only</button>'+ORDER.map(k=>'<button class="pill" aria-pressed="true" data-k="'+k+'"><i class="sw" style="background:var(--'+KEY[k]+')"></i>'+NAMES[k]+'</button>').join('');
482
+ c.addEventListener('click',e=>{const w=e.target.closest('button[data-w]');if(w){WRITTEN=!WRITTEN;w.setAttribute('aria-pressed',String(WRITTEN));relayout();return;}
483
+ const b=e.target.closest('button[data-k]');if(!b)return;filters[b.dataset.k]=!filters[b.dataset.k];b.setAttribute('aria-pressed',String(!!filters[b.dataset.k]));relayout();});}
484
+ function receive(d){connlost.hidden=true;cv.classList.remove('dim');DATA=d;
485
+ if(d.cfg){LEAF_CAP=d.cfg.leaf_cap||LEAF_CAP;WARN_LINES=d.cfg.warn_lines||WARN_LINES;}
486
+ document.title=d.name+' · Treespeak';document.getElementById('title').textContent=d.name+' · the tree, growing';
487
+ document.getElementById('legendnote').innerHTML='red rim = over '+WARN_LINES+' lines<br>orange dashes = hotspot, changed often and large<br>'+habitLegend();
488
+ OFFSET=Date.now()/1000-d.generated;relayout();aside();
489
+ if(!document.documentElement.dataset.ready){document.documentElement.dataset.ready='1';toHost({event:'ready',name:d.name,tracked:d.tracked});}}
490
+ // the export swaps the backing store and the base for one synchronous pass, so no frame shows it; toBlob copies the bitmap before it returns (2026-10-16)
491
+ function exportCanvas(scale){const s=+scale>0?+scale:(devicePixelRatio||1),dpr=DPR,base=BASE,hov=HOVER;HOVER=null;DPR=s;cv.width=W*s;cv.height=H*s;
492
+ if(base){BASE=document.createElement('canvas');BASE.width=W*s;BASE.height=H*s;const b=BASE.getContext('2d');b.setTransform(s,0,0,s,0,0);drawBase(b);}paint();
493
+ const out=document.createElement('canvas');out.width=cv.width;out.height=cv.height;const o=out.getContext('2d');if(!BARE){o.fillStyle=cssv('surface');o.fillRect(0,0,out.width,out.height);}o.drawImage(cv,0,0);
494
+ DPR=dpr;BASE=base;HOVER=hov;cv.width=W*dpr;cv.height=H*dpr;paint();return out;}
495
+ function hostLight(path){const g=path==null?null:HIT_AT.get(path)||TWIG_OF.get(path)||null;if(g){const a=anchorOf(g);hover(g,a.x,a.y);}else{TAPOWN=true;hover(null);TAPOWN=false;}}
496
+ addEventListener('message',e=>{const m=e.data;if(!HOST||e.origin!==HOST||!m||m.type!=='treespeak'||!m.action)return;
497
+ if(m.action==='hover')hostLight(m.path);else if(m.action==='clear')hostLight(null);else if(m.action==='focus')setFocus(m.path);
498
+ else if(m.action==='export'&&e.source&&DATA)e.source.postMessage({type:'treespeak',event:'export',dataURL:exportCanvas(m.scale).toDataURL('image/png')},HOST_TO);});
499
+ controls();treelist.init();if(QS.get('focus'))setFocus(QS.get('focus'));fetch('/data').then(r=>r.json()).then(receive);const es=new EventSource('/events');es.onmessage=e=>receive(JSON.parse(e.data));
500
+ es.onerror=()=>{connlost.hidden=false;cv.classList.add('dim');};
501
+ setInterval(paint,250);setInterval(()=>{if(DATA)aside();},1000);
502
+ </script>