ai-first-os 1.9.0

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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -0
  3. package/bin/ai-first-os.js +72 -0
  4. package/core/CLAUDE.md +148 -0
  5. package/core/VERSION +1 -0
  6. package/core/agents/ambiguous-spec.md +39 -0
  7. package/core/agents/complete-spec.md +36 -0
  8. package/core/agents/scout.md +25 -0
  9. package/core/install.sh +243 -0
  10. package/core/lib/archive.sh +347 -0
  11. package/core/lib/bootstrap.sh +276 -0
  12. package/core/lib/capture.sh +188 -0
  13. package/core/lib/check-resolvable.sh +172 -0
  14. package/core/lib/close-session.sh +741 -0
  15. package/core/lib/common.sh +1773 -0
  16. package/core/lib/focus-read.sh +282 -0
  17. package/core/lib/manual-link.sh +111 -0
  18. package/core/lib/markdown.py +304 -0
  19. package/core/lib/migrate-backlogs.sh +207 -0
  20. package/core/lib/migrate-canonicals.sh +523 -0
  21. package/core/lib/mount-repo.sh +543 -0
  22. package/core/lib/my-wiki-gates.sh +137 -0
  23. package/core/lib/my-wiki.sh +202 -0
  24. package/core/lib/my_wiki_build.py +548 -0
  25. package/core/lib/my_wiki_graph.py +137 -0
  26. package/core/lib/my_wiki_overview.py +392 -0
  27. package/core/lib/new-memory.sh +160 -0
  28. package/core/lib/new-product.sh +122 -0
  29. package/core/lib/new-workspace.sh +105 -0
  30. package/core/lib/pack-install.sh +114 -0
  31. package/core/lib/recall.sh +235 -0
  32. package/core/lib/recall_index.py +295 -0
  33. package/core/lib/remote-backup.sh +84 -0
  34. package/core/lib/rename-heads.sh +354 -0
  35. package/core/lib/rename-workspaces.sh +271 -0
  36. package/core/lib/session-read.sh +203 -0
  37. package/core/lib/session-start.sh +854 -0
  38. package/core/lib/supersede.sh +436 -0
  39. package/core/lib/sweep.sh +473 -0
  40. package/core/manual/COMO-FUNCIONA.md +251 -0
  41. package/core/manual/HOW-IT-WORKS.md +250 -0
  42. package/core/resolver.md +30 -0
  43. package/core/skills/archive.md +95 -0
  44. package/core/skills/bootstrap.md +226 -0
  45. package/core/skills/capture.md +65 -0
  46. package/core/skills/check-resolvable.md +38 -0
  47. package/core/skills/close-session.md +108 -0
  48. package/core/skills/grill.md +74 -0
  49. package/core/skills/mount-repo.md +97 -0
  50. package/core/skills/my-wiki.md +103 -0
  51. package/core/skills/new-memory.md +76 -0
  52. package/core/skills/new-product.md +55 -0
  53. package/core/skills/new-spec.md +114 -0
  54. package/core/skills/new-workspace.md +53 -0
  55. package/core/skills/recall.md +64 -0
  56. package/core/skills/rename-heads.md +72 -0
  57. package/core/skills/rename-workspaces.md +43 -0
  58. package/core/skills/supersede.md +83 -0
  59. package/core/skills/sweep.md +40 -0
  60. package/core/templates/my-wiki-graph.js +431 -0
  61. package/core/templates/my-wiki-overview.js +174 -0
  62. package/core/templates/my-wiki.html +1017 -0
  63. package/core/templates/node-folder/README.md +11 -0
  64. package/core/templates/node-folder/resolver.md +9 -0
  65. package/core/templates/node-light.md +22 -0
  66. package/core/templates/node-product/README.md +8 -0
  67. package/core/templates/node-repo/README.md +14 -0
  68. package/core/templates/node-repo/context/README.md +22 -0
  69. package/core/templates/node-repo/context/competitors.md +8 -0
  70. package/core/templates/node-repo/context/glossary.md +8 -0
  71. package/core/templates/node-repo/context/open-questions.md +9 -0
  72. package/core/templates/node-repo/context/opportunities.md +9 -0
  73. package/core/templates/node-repo/context/problem.md +8 -0
  74. package/core/templates/node-repo/context/scope.md +8 -0
  75. package/core/templates/node-repo/context/users.md +8 -0
  76. package/core/templates/node-repo/context/vision.md +8 -0
  77. package/core/templates/node-repo/resolver.md +14 -0
  78. package/core/templates/operator.md +17 -0
  79. package/core/templates/person.md +10 -0
  80. package/core/templates/repo-scaffold/ARCHITECTURE.md +3 -0
  81. package/core/templates/repo-scaffold/CLAUDE.md +23 -0
  82. package/core/templates/repo-scaffold/decisions.md +3 -0
  83. package/core/templates/repo-scaffold/evals-run.sh +14 -0
  84. package/core/templates/repo-scaffold/gitignore +3 -0
  85. package/core/templates/repo-scaffold/settings.json +8 -0
  86. package/core/templates/root-resolver.md +5 -0
  87. package/core/templates/strings.md +1361 -0
  88. package/core/templates/tree.md +59 -0
  89. package/core/templates/voice.md +5 -0
  90. package/package.json +23 -0
@@ -0,0 +1,1017 @@
1
+ <meta charset="utf-8">
2
+ <title>{{TITLE}}</title>
3
+ <!-- The page is written as the CONTENT of a document, not as a document: the publisher wraps it
4
+ in its own `<!doctype>…<head>…<body>` skeleton, and a second document nested inside that one
5
+ is invalid. Opened straight from disk it still renders — a browser wraps a fragment on its
6
+ own — which is how the suite reads it. The charset stays declared, and first: opened from
7
+ disk there is no header to say it, and a duplicate of the publisher's own is harmless. -->
8
+ <style>
9
+ :root{--accent:#4b5563;--accent-soft:#4b556322;--font:-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;--font-head:var(--font);--fs:14.5px;--bg:#fbfbfc;--panel:#f6f6f7;--border:#e5e5e8;--text:#1c1b22;--muted:#6b6a75;--card:#ffffff;--sel:#e1e1e6;--ok-bg:#e3f3ea;--ok-fg:#1f7a4d;--wait-bg:#fff3d6;--wait-fg:#9a6300;--wait-bd:#f3dfb6;--hot-bg:#fee4e2;--hot-fg:#b42318}
10
+ html[data-dark="1"]{--bg:#141318;--panel:#1a1a1d;--border:#2a2a2e;--text:#ececf1;--muted:#9a99a6;--card:#1f1f23;--sel:#34343b;--ok-bg:rgba(47,164,107,.18);--ok-fg:#6fd39a;--wait-bg:rgba(245,166,35,.16);--wait-fg:#f2c069;--wait-bd:rgba(245,166,35,.35);--hot-bg:rgba(240,68,56,.18);--hot-fg:#ff8a80}
11
+ *{box-sizing:border-box}
12
+ body{margin:0;font-family:var(--font);background:var(--bg);color:var(--text);font-size:var(--fs);line-height:1.55}
13
+ a{color:var(--accent);text-decoration:none}a:hover{opacity:.8}
14
+ .app{display:flex;min-height:100vh;background:var(--bg);color:var(--text)}
15
+ .side{width:280px;background:var(--panel);border-right:1px solid var(--border);display:flex;flex-direction:column;padding:16px 12px 12px;flex-shrink:0;position:sticky;top:0;height:100vh;overflow:auto}
16
+ .side .ws{position:relative}
17
+ .side .ws select{width:100%;appearance:none;font:inherit;font-weight:600;color:var(--text);padding:8px 10px 8px 38px;border:1px solid var(--border);background:var(--card);border-radius:8px;cursor:pointer}
18
+ .side .ws .sq{position:absolute;left:9px;top:9px;width:22px;height:22px;border-radius:6px;background:var(--accent);color:#fff;font-size:11px;display:flex;align-items:center;justify-content:center;font-weight:700;pointer-events:none}
19
+ .side .it{display:flex;align-items:center;gap:10px;padding:7px 10px;border-radius:7px;color:var(--text);cursor:pointer;width:100%;background:none;border:0;font:inherit;text-align:left}
20
+ .side .it.on{background:var(--sel);color:var(--text);font-weight:600}
21
+ .side .nav{margin-top:12px;display:flex;flex-direction:column;gap:1px}
22
+ .side .pages{flex:1;margin-top:6px;border-top:1px solid var(--border);padding-top:2px;display:flex;flex-direction:column;gap:1px}
23
+ .side .p{padding:5px 10px;border-radius:7px;color:var(--text);display:flex;gap:6px;align-items:flex-start;font-size:calc(var(--fs) - 1px);min-width:0;cursor:pointer;background:none;border:0;font-family:inherit;text-align:left;width:100%}
24
+ .side .p span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
25
+ .side .it span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
26
+ .side .p.on{background:var(--sel);color:var(--text);font-weight:600}
27
+ .side .p.sub{padding-left:26px;color:var(--muted)}
28
+ .side .grp{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.7px;padding:10px 10px 3px}
29
+ .side .ent{display:flex;align-items:center;gap:0;min-width:0}
30
+ .side .ent .p{flex:1;min-width:0}
31
+ .side .chev-gap{display:inline-block;width:20px;flex-shrink:0}
32
+ .side .chev{flex-shrink:0;width:20px;height:26px;display:flex;align-items:center;justify-content:center;background:none;border:0;color:var(--muted);cursor:pointer;padding:0;border-radius:6px}
33
+ .side .chev svg{transition:transform .12s ease}
34
+ .side .chev.open svg{transform:rotate(90deg)}
35
+ .side .chev:hover{background:var(--sel)}
36
+ .side .p.muted{color:var(--muted);cursor:default}
37
+ .top .navbtn{display:flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:7px;border:1px solid var(--border);background:var(--card);color:var(--text);cursor:pointer;flex-shrink:0;padding:0}
38
+ .top .navbtn:disabled{opacity:.35;cursor:default}
39
+ .top .navbtn:not(:disabled):hover{background:var(--sel)}
40
+ .top .crumb a{color:var(--muted)}
41
+ .top .crumb a:hover{color:var(--accent);opacity:1}
42
+ .top .crumb .sep{color:var(--muted);padding:0 2px}
43
+ .appear{border-top:1px solid var(--border);padding-top:6px;margin-top:8px}
44
+ .appear .appear-toggle{cursor:pointer;color:var(--muted)}
45
+ .appear.open .appear-toggle{color:var(--text)}
46
+ .appear .r{display:flex;align-items:center;gap:6px;padding:4px 10px;font-size:13px;color:var(--muted)}
47
+ .appear .r > span:first-child{width:52px;flex-shrink:0}
48
+ .sw{width:16px;height:16px;border-radius:999px;border:2px solid transparent;cursor:pointer;padding:0}
49
+ .sw.on{border-color:var(--text)}
50
+ .seg{display:flex;border:1px solid var(--border);border-radius:6px;overflow:hidden}
51
+ .seg button{padding:2px 8px;color:var(--muted);background:none;border:0;font:inherit;cursor:pointer}
52
+ .seg button.on{background:var(--sel);color:var(--accent);font-weight:600}
53
+ .main{flex:1;display:flex;flex-direction:column;min-width:0}
54
+ .top{height:48px;display:flex;align-items:center;gap:10px;padding:0 24px;border-bottom:1px solid var(--border);color:var(--muted);position:sticky;top:0;background:var(--bg);z-index:2}
55
+ .top .crumb{min-width:0;display:flex;align-items:center;gap:6px;flex:1;margin:0;font-size:12.5px;color:var(--muted);font-weight:400}
56
+ .top .crumb .bc{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;flex:0 1 auto;max-width:34%;color:var(--muted);text-decoration:none;background:none;border:0;padding:0}
57
+ .top .crumb a.bc:hover{color:var(--text)}
58
+ .top .crumb .bc-cur{flex:1 1 auto;max-width:none;color:var(--text);font-weight:500}
59
+ .top .crumb .bc-fold{flex:0 0 auto;cursor:default}
60
+ .top .crumb .sep{flex:0 0 auto;color:var(--muted);opacity:.7;padding:0}
61
+ #toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%) translateY(20px);background:var(--text);color:var(--bg);padding:10px 14px;border-radius:10px;font-size:13px;opacity:0;pointer-events:none;transition:all .2s;max-width:80vw;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;z-index:9}
62
+ #toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
63
+ .top form{margin-left:auto;flex-shrink:0;width:360px;height:32px;border:1px solid var(--border);background:var(--card);border-radius:8px;display:flex;align-items:center;gap:8px;padding:0 10px;color:var(--muted);font-size:13px}
64
+ .top input{flex:1;border:0;background:none;font:inherit;color:var(--text);outline:none;min-width:0}
65
+ .content{flex:1;padding:26px 48px 60px;max-width:900px}
66
+ .crumb{color:var(--muted);font-size:13px;display:flex;gap:6px;align-items:center;margin-bottom:6px}
67
+ .crumb b{color:var(--text);font-weight:600}
68
+ .actions{float:right;display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end;max-width:52%;margin-top:22px;margin-left:16px}
69
+ .btn{display:inline-flex;align-items:center;gap:6px;height:30px;padding:0 12px;border-radius:8px;border:1px solid var(--border);background:var(--card);font-size:13px;color:var(--text);white-space:nowrap;cursor:pointer;font-family:inherit}
70
+ h1{font-family:var(--font-head);font-size:calc(var(--fs) * 2.1);font-weight:700;margin:14px 0 4px;letter-spacing:-.3px}
71
+ .meta{color:var(--muted);font-size:13px;margin-bottom:18px;display:flex;gap:10px 14px;align-items:center;flex-wrap:wrap;min-width:0}
72
+ .lede{font-size:calc(var(--fs) + 1.5px);line-height:1.6;margin:0 0 16px}
73
+ .lede p{margin:0 0 10px}
74
+ .toc{display:flex;gap:16px;border-left:2px solid var(--border);padding-left:14px;margin:0 0 22px;font-size:13px;color:var(--muted);flex-wrap:wrap}
75
+ .toc a{color:var(--muted)}
76
+ h2{font-family:var(--font-head);font-size:calc(var(--fs) * 1.3);font-weight:700;margin:22px 0 10px;display:flex;align-items:center;gap:8px}
77
+ h2 svg{color:var(--accent);flex-shrink:0}
78
+ .chip{display:inline-flex;align-items:center;height:22px;padding:0 9px;border-radius:999px;font-size:12px;font-weight:500;background:var(--sel);color:var(--muted);max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;vertical-align:middle}
79
+ .chip.ok{background:var(--ok-bg);color:var(--ok-fg)}.chip.wait{background:var(--wait-bg);color:var(--wait-fg)}.chip.hot{background:var(--hot-bg);color:var(--hot-fg)}.chip.vio{background:var(--accent-soft);color:var(--accent)}
80
+ .li{display:flex;gap:12px;padding:12px 0;border-top:1px solid var(--border);align-items:flex-start;min-width:0}
81
+ .li:first-child{border-top:0}
82
+ .li > div:first-child{min-width:0;flex:1}
83
+ .li .t{font-weight:600;overflow-wrap:anywhere}
84
+ .li .d{color:var(--muted);font-size:calc(var(--fs) - 1px);margin-top:2px;overflow-wrap:anywhere}
85
+ .li .arrow{margin-left:auto;color:var(--muted);flex-shrink:0}
86
+ .cards{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
87
+ .card{border:1px solid var(--border);background:var(--card);border-radius:12px;padding:14px 16px}
88
+ .card .t{font-weight:600;font-size:calc(var(--fs) + .5px)}
89
+ .muted{color:var(--muted)}
90
+ .hl{background:var(--wait-bg);border-radius:3px;padding:0 2px}
91
+ .tbl{overflow-x:auto;margin:10px 0}
92
+ .tbl table{border-collapse:collapse;width:100%;font-size:calc(var(--fs) - 1px)}
93
+ .tbl th,.tbl td{border:1px solid var(--border);padding:6px 10px;text-align:left;vertical-align:top}
94
+ .tbl th{background:var(--panel);font-weight:600}
95
+ pre{background:var(--panel);border:1px solid var(--border);border-radius:8px;padding:10px 12px;overflow-x:auto;font-size:12.5px}
96
+ .meta .chip{max-width:min(480px,100%)}
97
+ .doc p{margin:0 0 12px;font-size:calc(var(--fs) + .5px);line-height:1.65}
98
+ .doc h3{font-family:var(--font-head);font-size:calc(var(--fs) + 1.5px);margin:16px 0 6px}
99
+ .doc ul{margin:0 0 12px;padding-left:20px}
100
+ .doc code{background:var(--sel);border-radius:4px;padding:1px 5px;font-size:.9em}
101
+ .doc .quote{border-left:3px solid var(--border);padding-left:12px;color:var(--muted)}
102
+ .task{display:flex;gap:10px;align-items:flex-start;padding:7px 0;border-top:1px solid var(--border)}
103
+ .task:first-child{border-top:0}
104
+ .task .box{width:15px;height:15px;border:1.6px solid var(--muted);border-radius:4px;margin-top:3px;flex-shrink:0;display:flex;align-items:center;justify-content:center}
105
+ .task.done .box{background:var(--ok-fg);border-color:var(--ok-fg);color:#fff}
106
+ .task.done .txt{color:var(--muted);text-decoration:line-through}
107
+ .note{background:var(--wait-bg);border:1px solid var(--wait-bd);border-radius:10px;padding:10px 12px;font-size:13px;color:var(--text)}
108
+ @media (max-width:820px){.app{flex-direction:column}.side{width:auto;height:auto;position:static}.content{padding:20px}.actions{float:none;max-width:100%;justify-content:flex-start;margin-bottom:10px}}
109
+ </style>
110
+ <div class="app" id="app"></div>
111
+ <script type="application/json" id="wiki-data">{{DATA}}</script>
112
+ <script id="wiki-core">
113
+ /* The page's own logic, with no DOM in it: search and appearance. It is a separate block on
114
+ purpose — this is what the suite runs headlessly, so the eval exercises the code that ships
115
+ instead of a copy of it. */
116
+ var WIKI = (function () {
117
+ var STORE_KEY = 'my-wiki:appearance';
118
+ var DEFAULTS = {accent: '#4b5563', font: 'sans', size: 'M', dark: false};
119
+
120
+ function readAppearance(store) {
121
+ var out = {accent: DEFAULTS.accent, font: DEFAULTS.font, size: DEFAULTS.size, dark: DEFAULTS.dark};
122
+ try {
123
+ var raw = store && store.getItem(STORE_KEY);
124
+ if (raw) {
125
+ var got = JSON.parse(raw);
126
+ for (var k in out) { if (Object.prototype.hasOwnProperty.call(got, k)) out[k] = got[k]; }
127
+ }
128
+ } catch (e) { /* a browser with site data blocked reads as no preference, never as a failure */ }
129
+ return out;
130
+ }
131
+
132
+ function writeAppearance(store, patch) {
133
+ var next = readAppearance(store);
134
+ for (var k in patch) { if (Object.prototype.hasOwnProperty.call(patch, k)) next[k] = patch[k]; }
135
+ try { store && store.setItem(STORE_KEY, JSON.stringify(next)); } catch (e) {}
136
+ return next;
137
+ }
138
+
139
+ function pageText(page) {
140
+ var parts = [page.title || ''];
141
+ if (page.summary) parts.push(page.summary);
142
+ var s = page.sections || [];
143
+ for (var i = 0; i < s.length; i++) {
144
+ parts.push(s[i].name || '');
145
+ parts.push(s[i].text || '');
146
+ }
147
+ return parts.join('\n');
148
+ }
149
+
150
+ /* Accent-insensitive, and character for character: the folded string has to keep the same
151
+ length as the raw one, because the index of a match in the folded text is what cuts the
152
+ fragment out of the raw text. A plain NFD normalise moves every index after the first accent. */
153
+ function fold(s) {
154
+ s = (s || '').toLowerCase();
155
+ if (!s.normalize) return s;
156
+ return s.replace(/[^\u0000-\u007F]/g, function (c) {
157
+ var d = c.normalize('NFD');
158
+ return d.length ? d.charAt(0) : c;
159
+ });
160
+ }
161
+
162
+ function index(data) {
163
+ var rows = [];
164
+ for (var path in data.pages) {
165
+ var p = data.pages[path];
166
+ rows.push({path: path, page: p, hay: fold(pageText(p)), title: fold(p.title || '')});
167
+ }
168
+ return rows;
169
+ }
170
+
171
+ function fragment(hay, raw, at) {
172
+ var start = Math.max(0, at - 60), end = Math.min(raw.length, at + 140);
173
+ var frag = raw.slice(start, end).replace(/\s+/g, ' ').trim();
174
+ return (start > 0 ? '…' : '') + frag + (end < raw.length ? '…' : '');
175
+ }
176
+
177
+ /* One result per page, with the fragment of its first match. Title matches rank first, then
178
+ matches in the body, then how early in the page the match sits. */
179
+ function search(rows, query, ws) {
180
+ var q = fold(query).trim();
181
+ if (!q) return [];
182
+ var terms = q.split(/\s+/), out = [];
183
+ for (var i = 0; i < rows.length; i++) {
184
+ var r = rows[i];
185
+ if (ws && r.page.ws !== ws) continue;
186
+ /* The fragment is cut around the LONGEST term, not the first one: with "historia de Orca",
187
+ "de" matches in the second line of every page and would show a fragment about nothing. */
188
+ var ok = true, at = -1, pick = terms[0], picked = -1;
189
+ for (var t = 0; t < terms.length; t++) {
190
+ var k = r.hay.indexOf(terms[t]);
191
+ if (k < 0) { ok = false; break; }
192
+ if (at < 0 || k < at) at = k;
193
+ if (terms[t].length > pick.length || picked < 0) { pick = terms[t]; picked = k; }
194
+ }
195
+ if (!ok) continue;
196
+ var raw = pageText(r.page);
197
+ out.push({
198
+ path: r.path, page: r.page, at: at,
199
+ inTitle: r.title.indexOf(pick) >= 0,
200
+ fragment: fragment(r.hay, raw, picked < 0 ? at : picked),
201
+ term: pick
202
+ });
203
+ }
204
+ out.sort(function (a, b) {
205
+ if (a.inTitle !== b.inTitle) return a.inTitle ? -1 : 1;
206
+ if (a.at !== b.at) return a.at - b.at;
207
+ return a.path < b.path ? -1 : 1;
208
+ });
209
+ return out;
210
+ }
211
+
212
+ /* Navigation (spec 063 C1) ---------------------------------------------------- */
213
+ /* A tiny history stack of the app's own — a route string per stop, and a pointer into it.
214
+ `wiki-view` drives the real `window.history` off this same shape (a route pushed here is a
215
+ route pushed there too), but the shape itself is DOM-free on purpose: it is what the suite
216
+ runs headlessly, the same way it already does for search and appearance. */
217
+ function navCreate(route) { return {stack: [route], pos: 0}; }
218
+ function navGo(nav, route) {
219
+ if (nav.stack[nav.pos] === route) return nav;
220
+ var stack = nav.stack.slice(0, nav.pos + 1);
221
+ stack.push(route);
222
+ return {stack: stack, pos: stack.length - 1};
223
+ }
224
+ function navBack(nav) { return nav.pos > 0 ? {stack: nav.stack, pos: nav.pos - 1} : nav; }
225
+ function navForward(nav) {
226
+ return nav.pos < nav.stack.length - 1 ? {stack: nav.stack, pos: nav.pos + 1} : nav;
227
+ }
228
+ function navCurrent(nav) { return nav.stack[nav.pos]; }
229
+ function navCanBack(nav) { return nav.pos > 0; }
230
+ function navCanForward(nav) { return nav.pos < nav.stack.length - 1; }
231
+
232
+ /* Collapse state (spec 063 C4), one workspace at a time so switching workspaces never mixes
233
+ one's entities into another's. Missing entirely reads as "everything collapsed": the caller
234
+ decides which entity opens by default (the active one) rather than this module guessing. */
235
+ function collapseKey(wsSlug) { return 'my-wiki:collapse:' + wsSlug; }
236
+ function readCollapse(store, wsSlug) {
237
+ try {
238
+ var raw = store && store.getItem(collapseKey(wsSlug));
239
+ if (raw) return JSON.parse(raw);
240
+ } catch (e) { /* blocked site data reads as nothing stored, never as a failure */ }
241
+ return {};
242
+ }
243
+ function writeCollapse(store, wsSlug, patch) {
244
+ var next = readCollapse(store, wsSlug);
245
+ for (var k in patch) { if (Object.prototype.hasOwnProperty.call(patch, k)) next[k] = patch[k]; }
246
+ try { store && store.setItem(collapseKey(wsSlug), JSON.stringify(next)); } catch (e) {}
247
+ return next;
248
+ }
249
+
250
+ /* The tree of the sidebar (spec 063 C2, C3) ------------------------------------ */
251
+ var ORPHANS_KEY = '__orphans__';
252
+ var DOC_INLINE_CAP = 12;
253
+
254
+ /* Which entity a page hangs from, for expanding it when that page is the one open. An entity
255
+ names itself; an initiative names it through `about`; a document names it through `owner`,
256
+ one hop further if that owner is itself an initiative. Anything else — a workspace home, a
257
+ person, an initiative or document with no entity above it — expands nothing. */
258
+ function activeEntityFor(data, path) {
259
+ var p = path && data.pages[path];
260
+ if (!p) return '';
261
+ if (p.kind === 'entity') return path;
262
+ if (p.kind === 'initiative') return p.about || '';
263
+ if (p.kind === 'document' && p.owner) {
264
+ var owner = data.pages[p.owner];
265
+ if (!owner) return '';
266
+ if (owner.kind === 'entity') return p.owner;
267
+ if (owner.kind === 'initiative') return owner.about || '';
268
+ }
269
+ return '';
270
+ }
271
+
272
+ /* One entry per entity, never one per initiative or document (C2): the shape a shelf's `pages`
273
+ already has from the builder (spec 060) IS the entity list, so nothing here invents a level —
274
+ it only decides what shows open, and whether an entity's own documents list inline or as a
275
+ count. A shelf, an entity, and the orphans group are each collapsed unless the map says
276
+ otherwise or they are the one the active page hangs from. */
277
+ function sidebarTree(data, wsSlug, activePath, collapse) {
278
+ collapse = collapse || {};
279
+ var ws = null;
280
+ for (var i = 0; i < data.workspaces.length; i++) {
281
+ if (data.workspaces[i].slug === wsSlug) ws = data.workspaces[i];
282
+ }
283
+ if (!ws) return {shelves: [], orphans: null};
284
+ var activeEntity = activeEntityFor(data, activePath);
285
+ function isOpen(key) {
286
+ // The active page's entity is expanded once, when the page opens (ensureExpanded); after
287
+ // that the reader can fold it like any other group. Forcing it open here made it unfoldable.
288
+ if (Object.prototype.hasOwnProperty.call(collapse, key)) return !collapse[key];
289
+ return key === activeEntity;
290
+ }
291
+ var shelves = ws.shelves.map(function (shelf) {
292
+ return {
293
+ type: shelf.type,
294
+ label: shelf.label,
295
+ entities: shelf.pages.map(function (path) {
296
+ var e = data.pages[path];
297
+ var docCount = (e.docs || []).length;
298
+ return {
299
+ path: path,
300
+ title: e.title,
301
+ open: isOpen(path),
302
+ active: path === activePath,
303
+ initiatives: e.children.slice(),
304
+ docs: docCount > 0 && docCount < DOC_INLINE_CAP ? e.docs.slice() : [],
305
+ docCount: docCount
306
+ };
307
+ })
308
+ };
309
+ });
310
+ var orphans = ws.orphans.length ? {
311
+ key: ORPHANS_KEY,
312
+ open: isOpen(ORPHANS_KEY),
313
+ count: ws.orphans.length,
314
+ paths: ws.orphans.slice()
315
+ } : null;
316
+ return {shelves: shelves, orphans: orphans};
317
+ }
318
+
319
+ return {
320
+ STORE_KEY: STORE_KEY, DEFAULTS: DEFAULTS,
321
+ readAppearance: readAppearance, writeAppearance: writeAppearance,
322
+ index: index, search: search, pageText: pageText, fold: fold,
323
+ navCreate: navCreate, navGo: navGo, navBack: navBack, navForward: navForward,
324
+ navCurrent: navCurrent, navCanBack: navCanBack, navCanForward: navCanForward,
325
+ collapseKey: collapseKey, readCollapse: readCollapse, writeCollapse: writeCollapse,
326
+ activeEntityFor: activeEntityFor, sidebarTree: sidebarTree,
327
+ ORPHANS_KEY: ORPHANS_KEY, DOC_INLINE_CAP: DOC_INLINE_CAP
328
+ };
329
+ })();
330
+ if (typeof module !== 'undefined' && module.exports) { module.exports = WIKI; }
331
+ </script>
332
+ {{GRAPH_JS}}
333
+ <script id="wiki-overview">{{OVERVIEW_JS}}</script>
334
+ <script id="wiki-view">
335
+ (function () {
336
+ var DATA = JSON.parse(document.getElementById('wiki-data').textContent);
337
+ var S = DATA.strings || {};
338
+ var T = function (k, d) { return S[k] || d || k; };
339
+ var ROWS = WIKI.index(DATA);
340
+ var app = document.getElementById('app');
341
+ var state = {appearOpen: false,
342
+ ws: DATA.workspaces.length ? DATA.workspaces[0].slug : '', route: '', query: '',
343
+ nav: null, preSearch: ''
344
+ };
345
+
346
+ var ICONS = {
347
+ dot: '<circle cx="12" cy="12" r="4"/>',
348
+ check: '<path d="M20 6L9 17l-5-5"/>',
349
+ gavel: '<path d="M4 12.5l5 5L20 6.5"/>',
350
+ bulb: '<path d="M9 18h6"/><path d="M10 22h4"/><path d="M12 2a6 6 0 0 0-4 10.5V15h8v-2.5A6 6 0 0 0 12 2z"/>',
351
+ people: '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.9"/><path d="M16 3.1a4 4 0 0 1 0 7.8"/>',
352
+ question: '<circle cx="12" cy="12" r="9"/><path d="M9.5 9.5a2.5 2.5 0 1 1 3 2.4V14"/><path d="M12 17.5v.01"/>',
353
+ code: '<path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>',
354
+ compass: '<circle cx="12" cy="12" r="9"/><path d="M15.5 8.5l-2 5-5 2 2-5z"/>',
355
+ flag: '<path d="M4 21V4h9l1 2h6v9h-7l-1-2H4"/>',
356
+ doc: '<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/>',
357
+ book: '<path d="M2 4h6a3 3 0 0 1 3 3v13a2 2 0 0 0-2-2H2z"/><path d="M22 4h-6a3 3 0 0 0-3 3v13a2 2 0 0 1 2-2h7z"/>',
358
+ bolt: '<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>',
359
+ search: '<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.5-3.5"/>',
360
+ edit: '<path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/>',
361
+ chevron: '<path d="M9 6l6 6-6 6"/>',
362
+ sliders: '<path d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3"/><path d="M1 14h6M9 8h6M17 16h6"/>',
363
+ link: '<path d="M10 13a5 5 0 0 0 7 0l2-2a5 5 0 0 0-7-7l-1 1"/><path d="M14 11a5 5 0 0 0-7 0l-2 2a5 5 0 0 0 7 7l1-1"/>',
364
+ graph: '<circle cx="5" cy="6" r="2.5"/><circle cx="19" cy="6" r="2.5"/><circle cx="12" cy="18" r="2.5"/><path d="M7 7l4 9M17 7l-4 9M7.5 6h9"/>',
365
+ arrowLeft: '<path d="M19 12H5"/><path d="M11 18l-6-6 6-6"/>',
366
+ arrowRight: '<path d="M5 12h14"/><path d="M13 6l6 6-6 6"/>'
367
+ };
368
+ function icon(name, size) {
369
+ var body = ICONS[name] || ICONS.dot;
370
+ return '<svg width="' + (size || 16) + '" height="' + (size || 16) + '" viewBox="0 0 24 24" fill="none" ' +
371
+ 'stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">' + body + '</svg>';
372
+ }
373
+ function esc(s) {
374
+ return String(s == null ? '' : s).replace(/&/g, '&amp;').replace(/</g, '&lt;')
375
+ .replace(/>/g, '&gt;').replace(/"/g, '&quot;');
376
+ }
377
+ function page(path) { return DATA.pages[path]; }
378
+ function href(path) { return '#/' + path; }
379
+
380
+ /* The breadcrumb (spec 063 C5): workspace, then the entity a page hangs from — an initiative's
381
+ `about`, or a document's owner one hop further if that owner is itself an initiative — then
382
+ the page itself, never a link. Used both by the header and by a page's own crumb line. */
383
+ function crumbTrail(path) {
384
+ var p = page(path), trail = [];
385
+ if (!p) return trail;
386
+ var w = null;
387
+ for (var i = 0; i < DATA.workspaces.length; i++) { if (DATA.workspaces[i].slug === p.ws) w = DATA.workspaces[i]; }
388
+ if (w) trail.push({title: w.title, path: w.home});
389
+ if (path === (w && w.home)) { trail[0].current = true; return trail; }
390
+ var ent = WIKI.activeEntityFor(DATA, path);
391
+ if (ent && ent !== path) {
392
+ var ep = page(ent);
393
+ trail.push({title: ep.title, path: ent});
394
+ if (p.kind === 'document' && p.owner && p.owner !== ent) {
395
+ var op = page(p.owner);
396
+ if (op) trail.push({title: op.title, path: p.owner});
397
+ }
398
+ }
399
+ trail.push({title: p.title, path: path, current: true});
400
+ return trail;
401
+ }
402
+ function crumbHtml(path) {
403
+ // One breadcrumb, in the header. Every segment shortens with an ellipsis on its own; with more
404
+ // than three segments the middle ones fold into "…" that shows them on hover.
405
+ var trail = crumbTrail(path), parts = [];
406
+ if (trail.length > 3) {
407
+ var folded = trail.slice(1, trail.length - 2);
408
+ trail = [trail[0], {folded: folded}, trail[trail.length - 2], trail[trail.length - 1]];
409
+ }
410
+ trail.forEach(function (c) {
411
+ if (c.folded) {
412
+ parts.push('<span class="bc bc-fold" title="' + esc(c.folded.map(function (f) { return f.title; }).join(' › ')) + '">…</span>');
413
+ } else if (c.current) {
414
+ parts.push('<span class="bc bc-cur" title="' + esc(c.title) + '">' + esc(c.title) + '</span>');
415
+ } else {
416
+ parts.push('<a class="bc" href="' + href(c.path) + '" title="' + esc(c.title) + '">' + esc(c.title) + '</a>');
417
+ }
418
+ });
419
+ return parts.join('<span class="sep">›</span>');
420
+ }
421
+
422
+ /* Appearance ------------------------------------------------------------------ */
423
+ var store = null;
424
+ try { store = window.localStorage; } catch (e) { store = null; }
425
+ var look = WIKI.readAppearance(store);
426
+ var SIZES = {S: '13px', M: '14.5px', L: '16.5px'};
427
+ var SERIF = "'Iowan Old Style','Palatino Linotype',Palatino,Georgia,serif";
428
+ function applyLook() {
429
+ var r = document.documentElement;
430
+ r.style.setProperty('--accent', look.accent);
431
+ r.style.setProperty('--accent-soft', look.accent + '22');
432
+ r.style.setProperty('--fs', SIZES[look.size] || SIZES.M);
433
+ r.style.setProperty('--font-head', look.font === 'serif' ? SERIF :
434
+ "-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif");
435
+ r.setAttribute('data-dark', look.dark ? '1' : '0');
436
+ }
437
+ function setLook(patch) { look = WIKI.writeAppearance(store, patch); applyLook(); render(); }
438
+
439
+ /* Collapse state (spec 063 C4) -------------------------------------------------- */
440
+ function collapse() { return WIKI.readCollapse(store, ws().slug); }
441
+ function toggleCollapse(key) {
442
+ // The map stores "collapsed?": absent or true is collapsed, false is open. Toggling writes
443
+ // the opposite of the current state — open becomes collapsed, collapsed becomes open.
444
+ var cur = collapse();
445
+ var openNow = Object.prototype.hasOwnProperty.call(cur, key) && cur[key] === false;
446
+ WIKI.writeCollapse(store, ws().slug, mkPatch(key, openNow));
447
+ render();
448
+ }
449
+ function mkPatch(key, val) { var p = {}; p[key] = val; return p; }
450
+ /* Opening a page always expands the entity it hangs from — never leaves the active page hidden
451
+ behind a collapsed row (C4) — and that expansion sticks, the same as a manual one would. */
452
+ function ensureExpanded(path) {
453
+ var ent = WIKI.activeEntityFor(DATA, path);
454
+ if (!ent) return;
455
+ var cur = collapse();
456
+ if (cur[ent] === false) return;
457
+ WIKI.writeCollapse(store, ws().slug, mkPatch(ent, false));
458
+ }
459
+
460
+ /* Sidebar --------------------------------------------------------------------- */
461
+ function ws() {
462
+ for (var i = 0; i < DATA.workspaces.length; i++) {
463
+ if (DATA.workspaces[i].slug === state.ws) return DATA.workspaces[i];
464
+ }
465
+ return DATA.workspaces[0];
466
+ }
467
+ function initials(t) {
468
+ var w = (t || '?').split(/\s+/), s = w[0].charAt(0);
469
+ if (w.length > 1) s += w[1].charAt(0);
470
+ return s.toUpperCase();
471
+ }
472
+ function sidebar() {
473
+ var w = ws(), h = [];
474
+ if (!w) return '<div class="side"></div>';
475
+ h.push('<div class="side"><div class="ws"><span class="sq">' + esc(initials(w.title)) + '</span><select id="ws-pick">');
476
+ DATA.workspaces.forEach(function (x) {
477
+ h.push('<option value="' + esc(x.slug) + '"' + (x.slug === w.slug ? ' selected' : '') + '>' + esc(x.title) + '</option>');
478
+ });
479
+ h.push('</select></div><div class="nav">');
480
+ // Which section the reader is in: Overview, People (the list or a person), or the wiki
481
+ // (the workspace's home and every entity, initiative and document page).
482
+ var curPath = state.route.charAt(0) === '/' ? state.route.slice(1) : '';
483
+ var curPage = curPath ? page(curPath) : null;
484
+ var inPeople = state.route === 'people' || (curPage && curPage.kind === 'person');
485
+ var inWiki = !inPeople && state.route !== 'overview' && state.route !== 'search' && state.route !== 'graph';
486
+ var isHome = inWiki;
487
+ h.push('<a class="it' + (state.route === 'overview' ? ' on' : '') + '" href="#overview">' + WIKI_OVERVIEW.icon('grid', 16) + '<span>' + esc(T('WIKI_OVERVIEW', 'Overview')) + '</span></a>');
488
+ h.push('<a class="it' + (isHome ? ' on' : '') + '" href="' + href(w.home) + '">' + icon('book') + '<span>' + esc(T('WIKI_TITLE', 'My Wiki')) + '</span></a>');
489
+ h.push('<a class="it' + (inPeople ? ' on' : '') + '" href="#people">' + icon('people') + '<span>' + esc(T('WIKI_PEOPLE', 'People')) + '</span></a>');
490
+ h.push('<a class="it' + (state.route === 'graph' ? ' on' : '') + '" href="#graph">' + icon('graph') + '<span>' + esc(T('WIKI_GRAPH', 'Graph')) + '</span></a>');
491
+ h.push('</div><div class="pages">');
492
+ var activePath = state.route.charAt(0) === '/' ? state.route.slice(1) : '';
493
+ if (inPeople) {
494
+ // In People the tree is the people of this workspace, the open one marked.
495
+ var folks = [];
496
+ for (var pk in DATA.pages) { if (DATA.pages[pk].kind === 'person' && DATA.pages[pk].ws === w.slug) folks.push(DATA.pages[pk]); }
497
+ folks.sort(function (x, y) { return x.title.localeCompare(y.title); });
498
+ h.push('<div class="grp">' + esc(T('WIKI_PEOPLE', 'People')) + '</div>');
499
+ if (!folks.length) h.push('<span class="p sub muted">' + esc(T('WIKI_NO_PEOPLE', 'No people yet')) + '</span>');
500
+ folks.forEach(function (f) {
501
+ h.push('<div class="ent leaf"><span class="chev-gap"></span><a class="p' + (activePath === f.path ? ' on' : '') + '" href="' + href(f.path) + '"><span>' + esc(f.title) + '</span></a></div>');
502
+ });
503
+ h.push('</div>');
504
+ return h.join('') + sidebarFoot();
505
+ }
506
+ var tree = WIKI.sidebarTree(DATA, w.slug, activePath, collapse());
507
+ tree.shelves.forEach(function (shelf) {
508
+ h.push('<div class="grp">' + esc(shelf.label) + '</div>');
509
+ shelf.entities.forEach(function (ent) {
510
+ // An entity with nothing hanging from it —no initiatives, no documents— is a plain link:
511
+ // no chevron, nothing to open, nothing that can get stuck open.
512
+ var hasKids = ent.initiatives.length > 0 || ent.docs.length > 0 || ent.docCount > 0;
513
+ h.push('<div class="ent' + (hasKids ? '' : ' leaf') + '">');
514
+ if (hasKids) {
515
+ h.push('<button class="chev' + (ent.open ? ' open' : '') + '" data-toggle="' + esc(ent.path) + '" ' +
516
+ 'aria-expanded="' + (ent.open ? 'true' : 'false') + '">' + icon('chevron', 13) + '</button>');
517
+ } else {
518
+ h.push('<span class="chev-gap"></span>');
519
+ }
520
+ h.push('<a class="p' + (ent.active ? ' on' : '') + '" href="' + href(ent.path) + '"><span>' + esc(ent.title) + '</span></a>');
521
+ h.push('</div>');
522
+ if (!ent.open || !hasKids) return;
523
+ ent.initiatives.forEach(function (c) {
524
+ h.push('<a class="p sub' + (state.route === '/' + c ? ' on' : '') + '" href="' + href(c) + '"><span>' + esc(page(c).title) + '</span></a>');
525
+ });
526
+ if (ent.docs.length) {
527
+ ent.docs.forEach(function (d) {
528
+ h.push('<a class="p sub" href="' + href(d.path) + '"' + (state.route === '/' + d.path ? ' data-on="1"' : '') + '><span>' + esc(page(d.path).title) + '</span></a>');
529
+ });
530
+ } else if (ent.docCount > 0) {
531
+ h.push('<span class="p sub muted">' + ent.docCount + ' ' + esc(T('WIKI_DOCUMENTS', 'Documents')) + '</span>');
532
+ }
533
+ });
534
+ });
535
+ if (tree.orphans) {
536
+ h.push('<div class="ent">');
537
+ h.push('<button class="chev' + (tree.orphans.open ? ' open' : '') + '" data-toggle="' + WIKI.ORPHANS_KEY + '" ' +
538
+ 'aria-expanded="' + (tree.orphans.open ? 'true' : 'false') + '">' + icon('chevron', 13) + '</button>');
539
+ h.push('<span class="p muted"><span>' + esc(T('WIKI_NO_ENTITY', 'No entity')) + ' · ' + tree.orphans.count + '</span></span>');
540
+ h.push('</div>');
541
+ if (tree.orphans.open) {
542
+ tree.orphans.paths.forEach(function (c) {
543
+ h.push('<a class="p sub' + (state.route === '/' + c ? ' on' : '') + '" href="' + href(c) + '"><span>' + esc(page(c).title) + '</span></a>');
544
+ });
545
+ }
546
+ }
547
+ if (!tree.shelves.length && !tree.orphans) {
548
+ h.push('<div class="grp">' + esc(T('WIKI_EMPTY', 'Nothing here yet')) + '</div>');
549
+ }
550
+ h.push('</div>');
551
+ return h.join('') + sidebarFoot();
552
+ }
553
+ function sidebarFoot() {
554
+ // Appearance folds into one row at the foot of the sidebar; opened, its options unfold
555
+ // above the row, so the row stays where the hand already is.
556
+ var h = ['<div class="appear' + (state.appearOpen ? ' open' : '') + '">'];
557
+ var hRows = h; h = [];
558
+ h.push('<div class="r"><span>' + esc(T('WIKI_ACCENT', 'Accent')) + '</span>');
559
+ ['#4b5563', '#0f8b8d', '#2563eb', '#d97706', '#db2777'].forEach(function (c) {
560
+ h.push('<button class="sw' + (look.accent === c ? ' on' : '') + '" data-accent="' + c + '" style="background:' + c + '" title="' + c + '"></button>');
561
+ });
562
+ h.push('</div>');
563
+ h.push('<div class="r"><span>' + esc(T('WIKI_TYPE', 'Type')) + '</span><span class="seg">' +
564
+ ['sans', 'serif'].map(function (f) {
565
+ return '<button data-font="' + f + '" class="' + (look.font === f ? 'on' : '') + '">' + f + '</button>';
566
+ }).join('') + '</span></div>');
567
+ h.push('<div class="r"><span>' + esc(T('WIKI_SIZE', 'Size')) + '</span><span class="seg">' +
568
+ ['S', 'M', 'L'].map(function (f) {
569
+ return '<button data-size="' + f + '" class="' + (look.size === f ? 'on' : '') + '">' + f + '</button>';
570
+ }).join('') + '</span></div>');
571
+ h.push('<div class="r"><span>' + esc(T('WIKI_THEME', 'Theme')) + '</span><span class="seg">' +
572
+ '<button data-dark="0" class="' + (look.dark ? '' : 'on') + '">' + esc(T('WIKI_LIGHT', 'Light')) + '</button>' +
573
+ '<button data-dark="1" class="' + (look.dark ? 'on' : '') + '">' + esc(T('WIKI_DARK', 'Dark')) + '</button>' +
574
+ '</span></div>');
575
+ // rows collected; now the row itself, and the fold: rows above, the toggle below
576
+ var rowsHtml = state.appearOpen ? h.join('') : '';
577
+ h = hRows;
578
+ h.push(rowsHtml);
579
+ h.push('<button class="it appear-toggle" id="appear-toggle" aria-expanded="' + (state.appearOpen ? 'true' : 'false') + '">' + icon('sliders') + '<span>' + esc(T('WIKI_APPEARANCE', 'Appearance')) + '</span><span class="sw" style="margin-left:auto;background:var(--accent);border-color:transparent"></span></button>');
580
+ h.push('</div></div>');
581
+ return h.join('');
582
+ }
583
+
584
+ /* Pieces ---------------------------------------------------------------------- */
585
+ function editButton(path) {
586
+ // Obsidian's own URI. Opened from a local file or a desktop app it launches Obsidian on that
587
+ // note; inside a sandboxed viewer (an artifact) the browser refuses external protocols, so
588
+ // the click also copies the path and says so — the reader never gets a dead button.
589
+ var file = path.replace(/\.md$/, '');
590
+ var url = 'obsidian://open?vault=' + encodeURIComponent(DATA.vault) + '&file=' + encodeURIComponent(file);
591
+ return '<a class="btn" id="edit-md" href="' + esc(url) + '" data-obsidian="' + esc(url) + '" data-copy="' + esc(path) + '">' + icon('edit', 14) + ' ' + esc(T('WIKI_EDIT', 'Edit markdown')) + '</a>';
592
+ }
593
+ function toast(text) {
594
+ var t = document.getElementById('toast');
595
+ if (!t) { t = document.createElement('div'); t.id = 'toast'; document.body.appendChild(t); }
596
+ t.textContent = text; t.className = 'show';
597
+ clearTimeout(toast.timer); toast.timer = setTimeout(function () { t.className = ''; }, 3200);
598
+ }
599
+ function chips(fm) {
600
+ var out = [], skip = {about: 1, repo: 1};
601
+ for (var k in fm) {
602
+ if (skip[k] || !fm[k]) continue;
603
+ var cls = 'chip';
604
+ if (k === 'status') cls += fm[k] === 'active' ? ' ok' : (fm[k] === 'blocked' ? ' hot' : '');
605
+ if (k === 'waiting_on' || k === 'blocked') cls += ' wait';
606
+ var full = k + ': ' + String(fm[k]);
607
+ out.push('<span class="' + cls + '" title="' + esc(full) + '">' + esc(k === 'status' || k === 'owner' ? fm[k] : k + ': ' + fm[k]) + '</span>');
608
+ }
609
+ return out.join('');
610
+ }
611
+ function listItem(title, detail, tail) {
612
+ return '<div class="li"><div><div class="t">' + title + '</div>' +
613
+ (detail ? '<div class="d">' + detail + '</div>' : '') + '</div>' +
614
+ '<div class="arrow">' + (tail || icon('chevron')) + '</div></div>';
615
+ }
616
+ function sectionHtml(s) {
617
+ var h = ['<h2 id="s-' + esc(s.name.replace(/\s+/g, '-')) + '">' + icon(s.icon, 18) + ' ' + esc(s.name) + '</h2>'];
618
+ if (s.form === 'tasks') {
619
+ s.items.forEach(function (i) {
620
+ h.push('<div class="task' + (i.done ? ' done' : '') + '"><span class="box">' + (i.done ? icon('check', 11) : '') + '</span>' +
621
+ '<span class="txt">' + esc(i.text) + (i.date ? ' <span class="chip">' + esc(i.date) + '</span>' : '') + '</span></div>');
622
+ });
623
+ } else if (s.form === 'decisions') {
624
+ s.items.forEach(function (i) {
625
+ h.push(listItem(esc(i.text), i.date ? esc(i.date) : '', '<span class="chip">' + esc(T('WIKI_DECISION', 'decision')) + '</span>'));
626
+ });
627
+ } else if (s.form === 'people') {
628
+ s.items.forEach(function (i) {
629
+ var target = null;
630
+ for (var p in DATA.pages) { if (DATA.pages[p].kind === 'person' && p.indexOf(i.person) >= 0) { target = p; break; } }
631
+ var label = esc(i.text);
632
+ h.push(listItem(target ? '<a href="' + href(target) + '">' + label + '</a>' : label, '',
633
+ '<span class="chip">' + esc(T('WIKI_PERSON', 'person')) + '</span>'));
634
+ });
635
+ } else {
636
+ h.push('<div class="doc">' + s.html + '</div>');
637
+ }
638
+ return h.join('');
639
+ }
640
+ /* A node's documents come out grouped by the folder they live in — `decisions/`, `research/`,
641
+ `context/` — because that folder is the only thing that says what they are. A group with more
642
+ than DOC_CAP shows the newest ones and says how many there are. */
643
+ var DOC_CAP = 25;
644
+ function docGroups(p) {
645
+ var by = {}, order = [];
646
+ (p.docs || []).forEach(function (d) {
647
+ var g = d.group || T('WIKI_DOCUMENTS', 'Documents');
648
+ if (!by[g]) { by[g] = []; order.push(g); }
649
+ by[g].push(d);
650
+ });
651
+ order.sort();
652
+ return order.map(function (g) {
653
+ var items = by[g].slice().sort(function (a, b) { return a.path < b.path ? 1 : -1; });
654
+ return {name: g, label: g.charAt(0).toUpperCase() + g.slice(1), items: items};
655
+ });
656
+ }
657
+ function sectionIcon(name) {
658
+ // The same rule as the builder's `section_icon`: lowercase, accents off, final "s" off, then
659
+ // the table in DATA.icons. One table, two readers, no drift.
660
+ var n = String(name || '').toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[\s_-]+/g, ' ').trim();
661
+ var tbl = DATA.icons || {};
662
+ var cands = [n, n.split(/\s+[—–-]\s+|:|\(/)[0].trim(), n.split(' ')[0]];
663
+ for (var i = 0; i < cands.length; i++) {
664
+ var c = cands[i], c1 = c.charAt(c.length - 1) === 's' ? c.slice(0, -1) : c;
665
+ var k = tbl[c] || tbl[c1];
666
+ if (k && ICONS[k]) return k;
667
+ }
668
+ return 'dot';
669
+ }
670
+ function docSections(p) {
671
+ var h = [];
672
+ docGroups(p).forEach(function (g) {
673
+ h.push('<h2 id="s-' + esc(g.label.replace(/\s+/g, '-')) + '">' +
674
+ icon(sectionIcon(g.name), 18) + ' ' + esc(g.label) +
675
+ (g.items.length > DOC_CAP ? ' <span class="muted" style="font-weight:400;font-size:13px">' + g.items.length + '</span>' : '') +
676
+ '</h2>');
677
+ g.items.slice(0, DOC_CAP).forEach(function (d) {
678
+ var e = page(d.path);
679
+ h.push(listItem('<a href="' + href(d.path) + '">' + esc(e.title) + '</a>', esc(e.summary || '')));
680
+ });
681
+ });
682
+ return h.join('');
683
+ }
684
+
685
+ function toc(names) {
686
+ if (!names.length) return '';
687
+ return '<div class="toc">' + names.map(function (n, i) {
688
+ // In-page anchors never touch the hash: the hash is the router's, and a section id in it
689
+ // would read as a route. The click scrolls to the heading under the sticky header instead.
690
+ return '<a href="#" class="anchor" data-anchor="s-' + esc(n.replace(/\s+/g, '-')) + '">' + (i === 0 ? '<b>' + esc(n) + '</b>' : esc(n)) + '</a>';
691
+ }).join('') + '</div>';
692
+ }
693
+ function devHtml(dev) {
694
+ var h = ['<h2>' + icon('code', 18) + ' ' + esc(T('WIKI_DEVELOPMENT', 'Development')) +
695
+ ' <span class="muted" style="font-weight:400;font-size:13px">' + esc(dev.repo) + '</span></h2>'];
696
+ if (!dev.mounted) {
697
+ h.push('<div class="note">' + esc(T('WIKI_REPO_UNMOUNTED', 'Repo not mounted on this machine.')) + '</div>');
698
+ return h.join('');
699
+ }
700
+ if (!dev.specs.length) {
701
+ h.push('<div class="note">' + esc(T('WIKI_NO_SPECS', 'No specs in this repo yet.')) + '</div>');
702
+ } else {
703
+ h.push('<div class="cards" style="grid-template-columns:repeat(3,minmax(0,1fr))">');
704
+ dev.specs.forEach(function (s) {
705
+ h.push('<div class="card"><div class="t"><span class="chip">' + esc(s.count + ' ' + s.status) + '</span></div></div>');
706
+ });
707
+ h.push('</div>');
708
+ }
709
+ if (dev.merge) {
710
+ h.push('<div class="meta" style="margin-top:10px"><span>' + esc(T('WIKI_LAST_MERGE', 'last merge')) + ' ' + esc(dev.merge) + '</span></div>');
711
+ }
712
+ return h.join('');
713
+ }
714
+
715
+ /* Views ----------------------------------------------------------------------- */
716
+ function viewPage(path) {
717
+ var p = page(path);
718
+ if (!p) return '<h1>' + esc(T('WIKI_NOT_FOUND', 'Nothing here')) + '</h1>';
719
+ var h = ['<div class="actions">' + editButton(path) + '</div>'];
720
+ h.push('<h1>' + esc(p.title) + '</h1>');
721
+ var meta = chips(p.fm);
722
+ if (meta) h.push('<div class="meta">' + meta + '</div>');
723
+ if (p.lede) h.push('<div class="lede">' + p.lede + '</div>');
724
+
725
+ var names = [];
726
+ if (p.children.length) names.push(T('WIKI_INITIATIVES', 'Initiatives'));
727
+ p.sections.forEach(function (s) { names.push(s.name); });
728
+ if (p.dev) names.push(T('WIKI_DEVELOPMENT', 'Development'));
729
+ docGroups(p).forEach(function (g) { names.push(g.label); });
730
+ if (p.kind === 'person') names.push(T('WIKI_MENTIONS', 'Mentions'));
731
+ h.push(toc(names));
732
+
733
+ if (p.children.length) {
734
+ h.push('<h2 id="s-' + esc(T('WIKI_INITIATIVES', 'Initiatives').replace(/\s+/g, '-')) + '">' + icon('flag', 18) + ' ' + esc(T('WIKI_INITIATIVES', 'Initiatives')) + '</h2>');
735
+ p.children.forEach(function (c) {
736
+ var e = page(c);
737
+ h.push(listItem('<a href="' + href(c) + '">' + esc(e.title) + '</a>' +
738
+ (e.fm.status ? ' <span class="chip ' + (e.fm.status === 'active' ? 'ok' : '') + '" style="margin-left:6px">' + esc(e.fm.status) + '</span>' : ''),
739
+ esc(e.summary || '')));
740
+ });
741
+ }
742
+ p.sections.forEach(function (s) { h.push(sectionHtml(s)); });
743
+ if (p.dev) h.push(devHtml(p.dev));
744
+ h.push(docSections(p));
745
+ if (p.kind === 'person') {
746
+ h.push('<h2 id="s-' + esc(T('WIKI_MENTIONS', 'Mentions').replace(/\s+/g, '-')) + '">' + icon('link', 18) + ' ' + esc(T('WIKI_MENTIONS', 'Mentions')) + '</h2>');
747
+ if (!p.mentions.length) h.push('<div class="note">' + esc(T('WIKI_NO_MENTIONS', 'Nobody mentions this page yet.')) + '</div>');
748
+ p.mentions.forEach(function (m) {
749
+ h.push(listItem('<a href="' + href(m.path) + '">' + esc(m.title) + '</a>', '',
750
+ '<span class="chip">' + esc(m.kind) + '</span>'));
751
+ });
752
+ }
753
+ return h.join('');
754
+ }
755
+
756
+ function viewWorkspace(path) {
757
+ var w = ws(), p = page(path);
758
+ var h = ['<div class="actions">' + editButton(path) + '</div>'];
759
+ h.push('<h1>' + esc(p.title) + '</h1>');
760
+ var count = 0;
761
+ w.shelves.forEach(function (s) { count += s.pages.length; });
762
+ h.push('<div class="meta"><span>' + esc(DATA.generated) + '</span><span>·</span><span>' +
763
+ count + ' ' + esc(T('WIKI_ENTITIES', 'entities')) + '</span></div>');
764
+ if (p.lede) h.push('<div class="lede">' + p.lede + '</div>');
765
+ h.push(toc(w.shelves.map(function (s) { return s.label; })
766
+ .concat(docGroups(p).map(function (g) { return g.label; }))));
767
+ if (!w.shelves.length) {
768
+ h.push('<div class="note">' + esc(T('WIKI_EMPTY', 'Nothing here yet')) + '</div>');
769
+ }
770
+ w.shelves.forEach(function (shelf) {
771
+ h.push('<h2 id="s-' + esc(shelf.label.replace(/\s+/g, '-')) + '">' + icon(shelf.icon && ICONS[shelf.icon] ? shelf.icon : sectionIcon(shelf.type || shelf.label), 18) + ' ' + esc(shelf.label) + '</h2>');
772
+ shelf.pages.forEach(function (pp) {
773
+ var e = page(pp);
774
+ h.push(listItem('<a href="' + href(pp) + '">' + esc(e.title) + '</a>' +
775
+ (e.children.length ? ' <span class="chip vio" style="margin-left:6px">' + e.children.length + '</span>' : ''),
776
+ esc(e.summary || '')));
777
+ });
778
+ });
779
+ if (w.orphans.length) {
780
+ h.push('<h2>' + icon('flag', 18) + ' ' + esc(T('WIKI_NO_ENTITY', 'No entity')) + '</h2>');
781
+ w.orphans.forEach(function (c) {
782
+ var e = page(c);
783
+ h.push(listItem('<a href="' + href(c) + '">' + esc(e.title) + '</a>', esc(e.summary || '')));
784
+ });
785
+ }
786
+ p.sections.forEach(function (s) { h.push(sectionHtml(s)); });
787
+ h.push(docSections(p));
788
+ return h.join('');
789
+ }
790
+
791
+ function viewPeople() {
792
+ var w = ws();
793
+ var h = ['<h1>' + esc(T('WIKI_PEOPLE', 'People')) + '</h1>'];
794
+ h.push('<div class="meta"><span>' + w.people.length + '</span></div>');
795
+ if (!w.people.length) h.push('<div class="note">' + esc(T('WIKI_NO_PEOPLE', 'No people in this workspace yet.')) + '</div>');
796
+ w.people.forEach(function (p) {
797
+ var e = page(p);
798
+ h.push(listItem('<a href="' + href(p) + '">' + esc(e.title) + '</a>', esc(e.summary || ''),
799
+ '<span class="chip">' + e.mentions.length + '</span>'));
800
+ });
801
+ return h.join('');
802
+ }
803
+
804
+ function mark(text, term) {
805
+ var i = WIKI.fold(text).indexOf(term);
806
+ if (i < 0) return esc(text);
807
+ return esc(text.slice(0, i)) + '<span class="hl">' + esc(text.slice(i, i + term.length)) + '</span>' + esc(text.slice(i + term.length));
808
+ }
809
+
810
+ function viewSearch() {
811
+ var w = ws();
812
+ var res = WIKI.search(ROWS, state.query, w.slug);
813
+ var h = ['<h1>' + esc(state.query) + '</h1>'];
814
+ h.push('<div class="meta"><span>' + res.length + ' ' + esc(T('WIKI_RESULTS', 'results')) + '</span></div>');
815
+ if (!res.length) h.push('<div class="note">' + esc(T('WIKI_NO_RESULTS', 'No results.')) + '</div>');
816
+ res.slice(0, 60).forEach(function (r) {
817
+ h.push(listItem('<a href="' + href(r.path) + '">' + esc(r.page.title) + '</a>',
818
+ mark(r.fragment, r.term), '<span class="chip">' + esc(r.page.kind) + '</span>'));
819
+ });
820
+ return h.join('');
821
+ }
822
+
823
+ /* Shell ----------------------------------------------------------------------- */
824
+ function body() {
825
+ if (state.route === 'overview') return WIKI_OVERVIEW.view(DATA, ws(), T, esc, href);
826
+ if (state.route === 'people') return viewPeople();
827
+ if (state.route === 'graph') return '<h1>' + esc(T('WIKI_GRAPH', 'Graph')) + '</h1><div id="graph-root"></div>';
828
+ if (state.route === 'search') return viewSearch();
829
+ var path = state.route.charAt(0) === '/' ? state.route.slice(1) : '';
830
+ var p = page(path);
831
+ if (!p) return viewWorkspace(ws().home);
832
+ if (p.kind === 'workspace') return viewWorkspace(path);
833
+ return viewPage(path);
834
+ }
835
+
836
+ /* Header ------------------------------------------------------------------------ */
837
+ function activePath() { return state.route.charAt(0) === '/' ? state.route.slice(1) : ''; }
838
+ function topCrumb() {
839
+ var p = activePath();
840
+ if (state.route === 'people') return '<b>' + esc(T('WIKI_PEOPLE', 'People')) + '</b>';
841
+ if (state.route === 'search') return '<b>' + esc(state.query) + '</b>';
842
+ if (p && page(p)) return crumbHtml(p);
843
+ return '<b>' + esc(ws().title) + '</b>';
844
+ }
845
+
846
+ function render() {
847
+ var w = ws();
848
+ if (!w) { app.innerHTML = '<div class="content"><h1>' + esc(T('WIKI_EMPTY', 'Nothing here yet')) + '</h1></div>'; return; }
849
+ var canBack = state.nav ? WIKI.navCanBack(state.nav) : false;
850
+ var canFwd = state.nav ? WIKI.navCanForward(state.nav) : false;
851
+ // Re-rendering rebuilds the whole shell. A click on the sidebar (collapse, appearance) must
852
+ // not move the reader: keep the sidebar's scroll always, and the page's scroll when the
853
+ // route did not change. A new page starts at the top, as a page should.
854
+ var prevSide = app.querySelector('.side');
855
+ var sideTop = prevSide ? prevSide.scrollTop : 0;
856
+ var sameRoute = (render.lastRoute === state.route);
857
+ var pageY = sameRoute ? (window.pageYOffset || document.documentElement.scrollTop || 0) : 0;
858
+ render.lastRoute = state.route;
859
+ app.innerHTML = sidebar() +
860
+ '<div class="main"><div class="top">' +
861
+ '<button class="navbtn" id="nav-back" title="' + esc(T('WIKI_BACK', 'Back')) + '" aria-label="' + esc(T('WIKI_BACK', 'Back')) + '"' + (canBack ? '' : ' disabled') + '>' + icon('arrowLeft', 15) + '</button>' +
862
+ '<button class="navbtn" id="nav-fwd" title="' + esc(T('WIKI_FORWARD', 'Forward')) + '" aria-label="' + esc(T('WIKI_FORWARD', 'Forward')) + '"' + (canFwd ? '' : ' disabled') + '>' + icon('arrowRight', 15) + '</button>' +
863
+ '<span class="crumb">' + topCrumb() + '</span>' +
864
+ '<form id="q-form">' + icon('search', 14) +
865
+ '<input id="q" placeholder="' + esc(T('WIKI_SEARCH', 'Search your brain…')) + '" value="' + esc(state.route === 'search' ? state.query : '') + '"></form></div>' +
866
+ '<div class="content">' + body() + '</div></div>';
867
+ wire();
868
+ var newSide = app.querySelector('.side');
869
+ if (newSide) newSide.scrollTop = sideTop;
870
+ if (sameRoute) window.scrollTo(0, pageY);
871
+ if (state.route === 'graph') {
872
+ var gr = document.getElementById('graph-root');
873
+ if (gr) WIKIGRAPH.mount(gr, DATA, T, href, {ws: w.slug});
874
+ }
875
+ try {
876
+ var on = app.querySelector('.side .p.on');
877
+ // Bring the active entry into the sidebar's own view without touching the page's scroll:
878
+ // scrollIntoView would drag the window along and open every page half-scrolled.
879
+ var sideEl = on ? on.closest('.side') : null;
880
+ if (on && sideEl) {
881
+ var r = on.getBoundingClientRect(), sr = sideEl.getBoundingClientRect();
882
+ if (r.top < sr.top || r.bottom > sr.bottom) sideEl.scrollTop += r.top - sr.top - sr.height / 2;
883
+ }
884
+ } catch (e) {}
885
+ }
886
+
887
+ function wire() {
888
+ var pick = document.getElementById('ws-pick');
889
+ if (pick) pick.onchange = function () {
890
+ state.ws = pick.value;
891
+ var w = ws();
892
+ // Overview is a screen of the workspace on screen: switching the workspace stays on it,
893
+ // and does not throw the reader back to a page they did not ask for.
894
+ location.hash = state.route === 'overview' ? '#overview' : '#/' + w.home;
895
+ if (state.route === 'overview') render();
896
+ };
897
+ var form = document.getElementById('q-form');
898
+ if (form) form.onsubmit = function (e) {
899
+ e.preventDefault();
900
+ if (state.route !== 'search') state.preSearch = state.route;
901
+ state.query = document.getElementById('q').value;
902
+ location.hash = '#search';
903
+ };
904
+ var back = document.getElementById('nav-back');
905
+ if (back) back.onclick = function () { history.back(); };
906
+ var fwd = document.getElementById('nav-fwd');
907
+ if (fwd) fwd.onclick = function () { history.forward(); };
908
+ Array.prototype.forEach.call(app.querySelectorAll('a.resume[data-resume]'), function (a) {
909
+ a.onclick = function (e) {
910
+ e.preventDefault();
911
+ var cmd = a.getAttribute('data-resume');
912
+ try { navigator.clipboard.writeText(cmd); } catch (err) {}
913
+ toast(esc(T('WIKI_THREAD_COPIED', 'Copied — paste it in a terminal:')) + ' ' + cmd);
914
+ };
915
+ });
916
+ Array.prototype.forEach.call(app.querySelectorAll('a.anchor[data-anchor]'), function (a) {
917
+ a.onclick = function (e) {
918
+ e.preventDefault();
919
+ var target = document.getElementById(a.getAttribute('data-anchor'));
920
+ if (!target) return;
921
+ var top = target.getBoundingClientRect().top + (window.pageYOffset || 0) - 64;
922
+ window.scrollTo(0, top);
923
+ };
924
+ });
925
+ var at = document.getElementById('appear-toggle');
926
+ if (at) at.onclick = function () { state.appearOpen = !state.appearOpen; render(); };
927
+ var edit = document.getElementById('edit-md');
928
+ if (edit) edit.onclick = function (e) {
929
+ e.preventDefault();
930
+ var url = edit.getAttribute('data-obsidian'), path = edit.getAttribute('data-copy');
931
+ var copied = false;
932
+ try { navigator.clipboard.writeText(path); copied = true; } catch (err) {}
933
+ var left = false;
934
+ window.addEventListener('blur', function () { left = true; }, {once: true});
935
+ try { window.location.href = url; } catch (err) {}
936
+ setTimeout(function () {
937
+ if (!left) toast((copied ? esc(T('WIKI_EDIT_COPIED', 'Obsidian could not be opened from here; the path is copied:')) : esc(T('WIKI_EDIT_PATH', 'Open in Obsidian:'))) + ' ' + path);
938
+ }, 900);
939
+ };
940
+ Array.prototype.forEach.call(app.querySelectorAll('[data-toggle]'), function (b) {
941
+ b.onclick = function () { toggleCollapse(b.getAttribute('data-toggle')); };
942
+ });
943
+ Array.prototype.forEach.call(app.querySelectorAll('[data-accent]'), function (b) {
944
+ b.onclick = function () { setLook({accent: b.getAttribute('data-accent')}); };
945
+ });
946
+ Array.prototype.forEach.call(app.querySelectorAll('[data-font]'), function (b) {
947
+ b.onclick = function () { setLook({font: b.getAttribute('data-font')}); };
948
+ });
949
+ Array.prototype.forEach.call(app.querySelectorAll('[data-size]'), function (b) {
950
+ b.onclick = function () { setLook({size: b.getAttribute('data-size')}); };
951
+ });
952
+ Array.prototype.forEach.call(app.querySelectorAll('[data-dark]'), function (b) {
953
+ b.onclick = function () { setLook({dark: b.getAttribute('data-dark') === '1'}); };
954
+ });
955
+ /* The sandbox of a published page may refuse the vault scheme. The click is not trusted to
956
+ land: the path goes to the clipboard as well, and the button says so. */
957
+ Array.prototype.forEach.call(app.querySelectorAll('[data-copy]:not(#edit-md)'), function (a) {
958
+ a.onclick = function () {
959
+ try { navigator.clipboard.writeText(a.getAttribute('data-copy')); } catch (e) {}
960
+ };
961
+ });
962
+ }
963
+
964
+ /* Routing and history (spec 063 C1) --------------------------------------------------------
965
+ Every page change lands on a route in the hash, so the browser's own back/forward can retrace
966
+ it. `history` state carries `navPos`, our own stack's pointer: the header's ← → buttons and
967
+ the physical back/forward button both end up in the same place, because both drive the same
968
+ `state.nav`.
969
+
970
+ A browser fires BOTH `hashchange` and `popstate` for every fragment navigation — a link click
971
+ as much as an actual back/forward — so neither event on its own says which one happened.
972
+ `history.state` does: an entry we have already stamped with `replaceState({navPos})` carries
973
+ that stamp back on a real traversal, and a brand-new entry (a click) carries none. `lastHash`
974
+ only keeps the two events from processing the same landing twice, whichever fires first. */
975
+ var lastHash = null;
976
+
977
+ function routeOf(hash) {
978
+ var h = (hash || '').replace(/^#/, '');
979
+ if (!h) return 'overview';
980
+ return h;
981
+ }
982
+
983
+ function applyRoute(r) {
984
+ state.route = r;
985
+ var p = page(r.replace(/^\//, ''));
986
+ if (p && p.ws) state.ws = p.ws;
987
+ if (r.charAt(0) === '/') ensureExpanded(r.slice(1));
988
+ render();
989
+ }
990
+
991
+ function handleRoute(evState) {
992
+ var r = routeOf(location.hash);
993
+ if (r === lastHash) return;
994
+ lastHash = r;
995
+ var st = evState !== undefined ? evState : history.state;
996
+ if (st && typeof st.navPos === 'number' && state.nav && state.nav.stack[st.navPos] === r) {
997
+ state.nav = {stack: state.nav.stack, pos: st.navPos};
998
+ } else {
999
+ state.nav = state.nav ? WIKI.navGo(state.nav, r) : WIKI.navCreate(r);
1000
+ try { history.replaceState({navPos: state.nav.pos}, '', location.href); } catch (e) {}
1001
+ }
1002
+ applyRoute(r);
1003
+ }
1004
+
1005
+ window.addEventListener('hashchange', function () { handleRoute(undefined); });
1006
+ window.addEventListener('popstate', function (e) { handleRoute(e.state); });
1007
+ document.addEventListener('keydown', function (e) {
1008
+ if (e.key !== 'Escape' || state.route !== 'search') return;
1009
+ var target = state.preSearch || (ws() ? '/' + ws().home : '');
1010
+ if (state.nav && WIKI.navCanBack(state.nav)) { history.back(); return; }
1011
+ location.hash = target;
1012
+ });
1013
+
1014
+ applyLook();
1015
+ handleRoute(undefined);
1016
+ })();
1017
+ </script>