authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-08-06 18:12:05+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-08-06 18:12:05+02:00
log373e48c9831c44f15c3209a92779a87348f690fd
treec167d4bc0eb612631060625a3212956009d81183
parent1c7798a3cde9e8dad31c276aab4c1affb2043ad2
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

autodoc: new layout (#16715)

* autodoc: init guide TOC work * autodoc: working guides toc navigation * autodoc: more improvements * autodoc: ui refinements * autodoc: new layout and init descriptions for namespaces in std.zig

4 files changed, 849 insertions(+), 294 deletions(-)

lib/docs/commonmark.js+15
...@@ -7831,6 +7831,16 @@...@@ -7831,6 +7831,16 @@
7831 } else {7831 } else {
7832 node._literal = contents;7832 node._literal = contents;
7833 }7833 }
7834 const doc = this.options.autoDoc;
7835 if (doc) {
7836 const decl_hash = doc.detectDeclPath(contents);
7837 if (decl_hash) {
7838 var l = new Node("link");
7839 l.destination = decl_hash;
7840 l.appendChild(node);
7841 node = l;
7842 }
7843 }
7834 block.appendChild(node);7844 block.appendChild(node);
7835 return true;7845 return true;
7836 }7846 }
...@@ -9702,6 +9712,7 @@...@@ -9702,6 +9712,7 @@
97029712
9703 this.buffer = "";9713 this.buffer = "";
9704 this.lastOut = "\n";9714 this.lastOut = "\n";
9715 this.heading_count = 0;
97059716
9706 while ((event = walker.next())) {9717 while ((event = walker.next())) {
9707 type = event.node.type;9718 type = event.node.type;
...@@ -9883,6 +9894,10 @@...@@ -9883,6 +9894,10 @@
9883 var tagname = "h" + node.level,9894 var tagname = "h" + node.level,
9884 attrs = this.attrs(node);9895 attrs = this.attrs(node);
9885 if (entering) {9896 if (entering) {
9897 if (node.level != 1) {
9898 attrs.push(["id", ":" + this.heading_count]);
9899 this.heading_count += 1;
9900 }
9886 this.cr();9901 this.cr();
9887 this.tag(tagname, attrs);9902 this.tag(tagname, attrs);
9888 } else {9903 } else {
lib/docs/index.html+143-77
...@@ -40,15 +40,20 @@...@@ -40,15 +40,20 @@
40 text-decoration: underline;40 text-decoration: underline;
41 }41 }
4242
43 a[href^="src/"] {
44 border-bottom: 2px dotted var(--tx-color);
45 }
46
43 .hidden {47 .hidden {
44 display: none;48 display: none !important;
45 }49 }
4650
47 /* layout */51 /* layout */
48 .canvas {52 .canvas {
53 display:flex;
54 flex-direction: column;
49 width: 100vw;55 width: 100vw;
50 height: 100vh;56 height: 100vh;
51 overflow: hidden;
52 margin: 0;57 margin: 0;
53 padding: 0;58 padding: 0;
54 font-family: var(--ui);59 font-family: var(--ui);
...@@ -58,13 +63,23 @@...@@ -58,13 +63,23 @@
5863
59 .flex-main {64 .flex-main {
60 display: flex;65 display: flex;
61 width: 100%;66 flex-direction: column;
62 height: 100%;
63 justify-content: center;67 justify-content: center;
68 margin: 0 1rem;
69
70 height: 100%;
71 overflow: hidden;
72
6473
65 z-index: 100;74 z-index: 100;
66 }75 }
6776
77 .flex-horizontal {
78 display: flex;
79 flex-direction: row;
80 align-items: center;
81 }
82
68 .flex-filler {83 .flex-filler {
69 flex-grow: 1;84 flex-grow: 1;
70 flex-shrink: 1;85 flex-shrink: 1;
...@@ -104,23 +119,27 @@...@@ -104,23 +119,27 @@
104 z-index: 400;119 z-index: 400;
105 }120 }
106121
107 /* sidebar */122 .understated {
123 color: var(--search-other-results-color);
124 }
125
108 .sidebar {126 .sidebar {
109 font-size: 1rem;
110 background-color: var(--bg-color);127 background-color: var(--bg-color);
111 box-shadow: 0 0 1rem var(--sidebar-sh-color);128 box-shadow: 0 0 1rem var(--sidebar-sh-color);
129 clip-path: inset(0px -15px 0px 0px);
112 }130 }
113131
114 .sidebar .logo {132 .logo {
115 padding: 1rem 0.35rem 0.35rem 0.35rem;133 width: 168px;
134 margin-right: 1rem;
116 }135 }
117136
118 .sidebar .logo > svg {137 .logo > svg {
119 display: block;138 display: block;
120 overflow: visible;139 overflow: visible;
121 }140 }
122141
123 .sidebar ul.guides-api-switch {142 ul.guides-api-switch {
124 display: flex;143 display: flex;
125 flex-direction: row;144 flex-direction: row;
126 justify-content: center;145 justify-content: center;
...@@ -130,7 +149,7 @@...@@ -130,7 +149,7 @@
130 padding: 0;149 padding: 0;
131 }150 }
132151
133 .sidebar .guides-api-switch a {152 .guides-api-switch a {
134 display: block;153 display: block;
135 padding: 0.5rem 1rem; 154 padding: 0.5rem 1rem;
136 color: var(--sidebar-modlnk-tx-color);155 color: var(--sidebar-modlnk-tx-color);
...@@ -157,11 +176,24 @@...@@ -157,11 +176,24 @@
157 background-color: var(--sidebar-modlnk-bg-color-hover);176 background-color: var(--sidebar-modlnk-bg-color-hover);
158 }177 }
159178
160 .sidebar .guides-api-switch .active {179 .guides-api-switch .active {
161 color: var(--sidebar-modlnk-tx-color-active);180 color: var(--sidebar-modlnk-tx-color-active);
162 background-color: var(--sidebar-modlnk-bg-color-active);181 background-color: var(--sidebar-modlnk-bg-color-active);
163 }182 }
164183
184 #guidesMenu {
185 height: 100%;
186 overflow: hidden;
187 width: 30%;
188 margin-right: 2rem;
189 }
190
191 #activeGuide {
192 overflow-y: scroll;
193 height: 100%;
194 width: 70%;
195 padding-right: 1rem;
196 }
165 .sidebar h2 {197 .sidebar h2 {
166 margin: 0.5rem;198 margin: 0.5rem;
167 padding: 0;199 padding: 0;
...@@ -202,8 +234,16 @@...@@ -202,8 +234,16 @@
202 font-family: var(--mono);234 font-family: var(--mono);
203 }235 }
204236
237 #guideTocList {
238 padding: 0 1rem;
239 }
240
241 #guideTocList ul {
242 padding-left: 1rem;
243 margin: 0;
244 }
245
205 #guides {246 #guides {
206 padding: 0rem 0.7rem 2.4rem 1.4rem;
207 box-sizing: border-box;247 box-sizing: border-box;
208 font-size: 1rem;248 font-size: 1rem;
209 background-color: var(--bg-color);249 background-color: var(--bg-color);
...@@ -212,15 +252,35 @@...@@ -212,15 +252,35 @@
212252
213 /* docs section */253 /* docs section */
214 .docs {254 .docs {
255 flex-grow: 2;
215 padding: 0rem 0.7rem 2.4rem 1.4rem;256 padding: 0rem 0.7rem 2.4rem 1.4rem;
216 font-size: 1rem;257 font-size: 1rem;
217 background-color: var(--bg-color);258 background-color: var(--bg-color);
218 overflow-wrap: break-word;259 overflow-wrap: break-word;
260 height: 100%;
261 overflow-y: scroll;
262 }
263
264 #noDocsNamespaces {
265 margin: 1rem;
266 border: 1px solid var(--search-other-results-color);
267 padding: 0.5rem 1rem;
268 background-color: var(--help-bg-color);
269 }
270
271 .column {
272 flex-basis: 0;
273 flex-grow: 1;
274 min-width: 24rem;
275 }
276
277
278 .search-container {
279 flex-grow: 2;
219 }280 }
220281
221 .docs .search {282 .search {
222 width: 100%;283 width: 100%;
223 margin-bottom: 0.8rem;
224 padding: 0.5rem;284 padding: 0.5rem;
225 font-family: var(--ui);285 font-family: var(--ui);
226 font-size: 1rem;286 font-size: 1rem;
...@@ -238,7 +298,7 @@...@@ -238,7 +298,7 @@
238 -webkit-appearance: none;298 -webkit-appearance: none;
239 }299 }
240300
241 .docs .search:focus {301 .search:focus {
242 background-color: var(--search-bg-color-focus);302 background-color: var(--search-bg-color-focus);
243 border-bottom-color: #ffbb4d;303 border-bottom-color: #ffbb4d;
244 box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color);304 box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color);
...@@ -286,7 +346,6 @@...@@ -286,7 +346,6 @@
286346
287 #sectSearchResults {347 #sectSearchResults {
288 box-sizing: border-box;348 box-sizing: border-box;
289 max-width: 960px;
290 }349 }
291350
292 #searchHelp summary {351 #searchHelp summary {
...@@ -335,15 +394,15 @@...@@ -335,15 +394,15 @@
335 }394 }
336 395
337 396
338 .docs a {397 a {
339 color: var(--link-color);398 color: var(--link-color);
340 }399 }
341400
342 .docs p {401 p {
343 margin: 0.8rem 0;402 margin: 0.8rem 0;
344 }403 }
345404
346 .docs pre {405 pre {
347 font-family: var(--mono);406 font-family: var(--mono);
348 font-size: 1em;407 font-size: 1em;
349 background-color: #F5F5F5;408 background-color: #F5F5F5;
...@@ -351,53 +410,55 @@...@@ -351,53 +410,55 @@
351 overflow-x: auto;410 overflow-x: auto;
352 }411 }
353412
354 .docs pre.inline {413 pre.inline {
355 background-color: var(--bg-color);414 background-color: var(--bg-color);
356 padding: 0;415 padding: 0;
357 display: inline;416 display: inline;
358 }417 }
359418
360419
361 .docs code {420 code {
362 font-family: var(--mono);421 font-family: var(--mono);
363 font-size: 1em;422 font-size: 1em;
364 }423 }
365424
366 .docs h1 {425 h1 {
367 font-size: 1.4em;426 font-size: 1.4em;
368 margin: 0.8em 0;427 margin: 0.8em 0;
369 padding: 0;428 padding: 0;
370 border-bottom: 0.0625rem dashed;429 border-bottom: 0.0625rem dashed;
371 }430 }
372431
373 .docs h2 {432 h2 {
374 font-size: 1.3em;433 font-size: 1.3em;
375 margin: 0.5em 0;434 margin: 0.5em 0;
376 padding: 0;435 padding: 0;
377 border-bottom: 0.0625rem solid;436 border-bottom: 0.0625rem solid;
378 }437 }
379 #listNav {438 .listNav {
380 list-style-type: none;439 list-style-type: none;
381 margin: 0;440 margin: 0;
382 padding: 0;441 padding: 0;
383 overflow: hidden;442 overflow: hidden;
384 background-color: #f1f1f1;443 boackground-color: #f1f1f1;
444 display: flex;
445 flex-direction: row;
385 }446 }
386 #listNav li {447 .listNav li {
387 float:left;448
388 }449 }
389 #listNav li a {450 .listNav li a {
390 display: block;451 display: block;
391 color: #000;452 color: #000;
392 text-align: center;453 text-align: center;
393 padding: .5em .8em;454 padding: .5em .8em;
394 text-decoration: none;455 text-decoration: none;
395 }456 }
396 #listNav li a:hover {457 .listNav li a:hover {
397 background-color: #555;458 background-color: #555;
398 color: #fff;459 color: #fff;
399 }460 }
400 #listNav li a.active {461 .listNav li a.active {
401 background-color: #FFBB4D;462 background-color: #FFBB4D;
402 color: #000;463 color: #000;
403 }464 }
...@@ -595,7 +656,7 @@...@@ -595,7 +656,7 @@
595 --tx-color: #bbb;656 --tx-color: #bbb;
596 --bg-color: #111;657 --bg-color: #111;
597 --link-color: #88f;658 --link-color: #88f;
598 --sidebar-sh-color: rgba(128, 128, 128, 0.09);659 --sidebar-sh-color: rgba(128, 128, 128, 0.5);
599 --sidebar-mod-bg-color: #333;660 --sidebar-mod-bg-color: #333;
600 --sidebar-modlnk-tx-color: #fff;661 --sidebar-modlnk-tx-color: #fff;
601 --sidebar-modlnk-tx-color-hover: #fff;662 --sidebar-modlnk-tx-color-hover: #fff;
...@@ -612,23 +673,23 @@...@@ -612,23 +673,23 @@
612 --warning-popover-bg-color: #600000;673 --warning-popover-bg-color: #600000;
613 }674 }
614675
615 .docs pre {676 pre {
616 background-color:#2A2A2A;677 background-color:#2A2A2A;
617 }678 }
618 .fieldDocs {679 .fieldDocs {
619 border-color:#2A2A2A;680 border-color:#2A2A2A;
620 }681 }
621 #listNav {682 .listNav {
622 background-color: #333;683 background-color: #333;
623 }684 }
624 #listNav li a {685 .listNav li a {
625 color: #fff;686 color: #fff;
626 }687 }
627 #listNav li a:hover {688 .listNav li a:hover {
628 background-color: #555;689 background-color: #555;
629 color: #fff;690 color: #fff;
630 }691 }
631 #listNav li a.active {692 .listNav li a.active {
632 background-color: #FFBB4D;693 background-color: #FFBB4D;
633 color: #000;694 color: #000;
634 }695 }
...@@ -872,9 +933,8 @@...@@ -872,9 +933,8 @@
872 <a href="https://github.com/ziglang/zig/wiki/How-to-read-the-standard-library-source-code">Learn more about stdlib source code</a>.933 <a href="https://github.com/ziglang/zig/wiki/How-to-read-the-standard-library-source-code">Learn more about stdlib source code</a>.
873 </div>934 </div>
874 <div id="main" class="flex-main">935 <div id="main" class="flex-main">
875 <div class="flex-filler"></div>936 <div class="flex-horizontal" style="justify-content: center;padding:0.5rem;">
876 <div class="flex-left sidebar">937 <div class="flex-left">
877 <nav>
878 <div class="logo">938 <div class="logo">
879 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 140">939 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 140">
880 <g fill="#F7A41D">940 <g fill="#F7A41D">
...@@ -915,45 +975,35 @@...@@ -915,45 +975,35 @@
915 </g>975 </g>
916 </svg>976 </svg>
917 </div>977 </div>
918 <div id="sectGudeApiSwitch">978 <div id="sectGuideApiSwitch">
919 <ul class="guides-api-switch">979 <ul class="guides-api-switch">
920 <li><a id="ApiSwitch" class="active" href="#A;">API</a></li>980 <li><a id="ApiSwitch" class="active" href="#A;">API</a></li>
921 <li><a id="guideSwitch" class="" href="#G;">Guides</a></li>981 <li><a id="guideSwitch" class="" href="#G;">Guides</a></li>
922 </ul>982 </ul>
923 </div>983 </div>
924 <div id="guidesMenu" class="hidden">
925 <div id="guidesList"></div>
926 </div>
927 <div id="apiMenu" class="hidden">
928 <div id="sectMainMod" class="hidden">
929 <h2><span>Main Module</span></h2>
930 <ul class="modules">
931 <li><a id="mainMod" class="" href=""></a></li>
932 </ul>
933 </div>
934 <div id="sectMods" class="hidden">
935 <h2><span>Dependencies</span></h2>
936 <ul id="listMods" class="modules"></ul>
937 </div>984 </div>
938 <div id="sectInfo" class="hidden">985 <div class="flex-right" style="padding-top: 0.5rem;overflow:visible;">
939 <h2><span>Zig Version</span></h2>986 <div class="search-container" style="position:relative;">
940 <p class="str" id="tdZigVer"></p>
941 </div>
942 </div>
943 </nav>
944 </div>
945 <div class="flex-right">
946 <div class="wrap">
947 <section class="docs" style="padding-top: 1.5rem; padding-bottom:0;">
948 <div style="position: relative">
949 <span id="searchPlaceholder"><!-- populated by setPrefSlashSearch --></span>987 <span id="searchPlaceholder"><!-- populated by setPrefSlashSearch --></span>
950 <input type="search" class="search" id="search" autocomplete="off" spellcheck="false" disabled>988 <input type="search" class="search" id="search" autocomplete="off" spellcheck="false" disabled>
951 <div id="dotsPopover">989 <div id="dotsPopover">
952 Use spaces instead of dots. See $resource for more info.990 Use spaces instead of dots. See $resource for more info.
953 </div>991 </div>
954 </div>992 </div>
955 </section>993 <div id="sectNavAPI" style="margin-top: 0.5rem;"><ul id="listNavAPI" class="listNav"></ul></div>
994 <div id="sectNavGuides" class="hidden" style="margin-top:0.5rem;background-color:#333;">
995 <ul id="listNavGuides" class="listNav">
996 <li>
997 <a href="#G;" class="active">Index</a>
998 </li>
999 <li style="flex-grow:1;">
1000 <a href="#G;" class="active" onclick="scrollGuidesTop(event);"></a>
1001 </li>
1002 </ul>
1003 </div>
956 </div>1004 </div>
1005 </div>
1006 <div style="height:100%; overflow:hidden; margin: 0 1rem;">
957 <div id="sectSearchResults" class="docs hidden">1007 <div id="sectSearchResults" class="docs hidden">
958 <details id="searchHelp">1008 <details id="searchHelp">
959 <summary id="searchHelpSummary" class="normal">How to search effectively</summary>1009 <summary id="searchHelpSummary" class="normal">How to search effectively</summary>
...@@ -986,7 +1036,7 @@...@@ -986,7 +1036,7 @@
986 </ul> 1036 </ul>
9871037
988 <h3>Multiple terms</h3>1038 <h3>Multiple terms</h3>
989 1039
990 <ul>1040 <ul>
991 <li>When a search query contains multiple terms, order doesn't matter when 1041 <li>When a search query contains multiple terms, order doesn't matter when
992 all terms match within a single decl name (e.g. "map auto" will match <code>AutoHashMap</code>).</li>1042 all terms match within a single decl name (e.g. "map auto" will match <code>AutoHashMap</code>).</li>
...@@ -1016,13 +1066,17 @@...@@ -1016,13 +1066,17 @@
1016 </ul>1066 </ul>
1017 <p>Press <kbd>?</kbd> to see keyboard shortcuts and <kbd>Esc</kbd> to return.</p>1067 <p>Press <kbd>?</kbd> to see keyboard shortcuts and <kbd>Esc</kbd> to return.</p>
1018 </div>1068 </div>
1019 <div id="guides" class="wrap hidden">1069 <div id="guides" class="flex-horizontal hidden" style="align-items:flex-start;height:100%;oveflow:hidden;">
1070 <div id="guidesMenu" class="sidebar">
1071 <h2 id="guidesMenuTitle">Table of Contents</h2>
1072 <div id="guideTocListEmpty" style="margin:0 1rem;"><i>No content to display.</i></div>
1073 <div id="guideTocList" style="height:100%;overflow-y:scroll;"></div>
1074 </div>
1020 <div id="activeGuide" class="hidden"></div>1075 <div id="activeGuide" class="hidden"></div>
1021 </div> 1076 </div>
1022 <div id="docs" class="wrap hidden">1077 <div id="docs" class="hidden" style="align-items:flex-start;height:100%;oveflow:hidden;">
1023 <section class="docs">1078 <section id="docs-scroll" class="docs">
1024 <p id="status">Loading...</p>1079 <p id="status">Loading...</p>
1025 <div id="sectNav" class="hidden"><ul id="listNav"></ul></div>
1026 <div id="fnProto" class="hidden">1080 <div id="fnProto" class="hidden">
1027 <div class="mobile-scroll-container"><pre id="fnProtoCode" class="scroll-item"></pre></div>1081 <div class="mobile-scroll-container"><pre id="fnProtoCode" class="scroll-item"></pre></div>
1028 <div id="fnSourceLink" style="display:flex;flex-direction:row;justify-content:flex-end;"></div>1082 <div id="fnSourceLink" style="display:flex;flex-direction:row;justify-content:flex-end;"></div>
...@@ -1054,13 +1108,25 @@...@@ -1054,13 +1108,25 @@
1054 <h2>Fields</h2>1108 <h2>Fields</h2>
1055 <div id="listFields"></div>1109 <div id="listFields"></div>
1056 </div>1110 </div>
1057 <div id="sectTypes" class="hidden">
1058 <h2>Types</h2>
1059 <ul id="listTypes"></ul>
1060 </div>
1061 <div id="sectNamespaces" class="hidden">1111 <div id="sectNamespaces" class="hidden">
1062 <h2>Namespaces</h2>1112 <div style="position:relative;">
1063 <ul id="listNamespaces"></ul>1113 <h2 style="position:sticky; top:0; background-color:var(--bg-color)">Namespaces</h2>
1114 <div class="flex-horizontal" style="justify-content:space-around;align-items:flex-start;flex-wrap:wrap;">
1115 <ul id="listNamespacesLeft" class="column"></ul>
1116 <ul id="listNamespacesRight" class="column"></ul>
1117 </div>
1118 </div>
1119 <h3>Other Namespaces <span style="font-size:1.1rem; cursor:pointer;" title="This box contains namespaces that are exported without a doc comment.">&#9432;</span></h3>
1120 <div id="noDocsNamespaces"></div>
1121 </div>
1122 <div id="sectTypes" class="hidden">
1123 <div style="position:relative;">
1124 <h2 style="position:sticky; top:0; background-color:var(--bg-color)">Types</h2>
1125 <div class="flex-horizontal" style="justify-content:space-around;align-items:flex-start;flex-wrap:wrap;">
1126 <ul id="listTypesLeft" class="column"></ul>
1127 <ul id="listTypesRight" class="column"></ul>
1128 </div>
1129 </div>
1064 </div>1130 </div>
1065 <div id="sectGlobalVars" class="hidden">1131 <div id="sectGlobalVars" class="hidden">
1066 <h2>Global Variables</h2>1132 <h2>Global Variables</h2>
lib/docs/main.js+612-217
...@@ -1,34 +1,42 @@...@@ -1,34 +1,42 @@
1"use strict";1"use strict";
22
3var zigAnalysis;3var zigAnalysis;
4let skipNextHashChange = null;
45
5const NAV_MODES = {6const NAV_MODES = {
6 API: "#A;",7 API: "#A;",
7 GUIDES: "#G;",8 GUIDES: "#G;",
8};9};
910
11
12var scrollHistory = {};
13
10(function() {14(function() {
11 const domBanner = document.getElementById("banner");15 const domBanner = document.getElementById("banner");
12 const domMain = document.getElementById("main");16 const domMain = document.getElementById("main");
13 const domStatus = document.getElementById("status");17 const domStatus = document.getElementById("status");
14 const domSectNav = document.getElementById("sectNav");18 const domSectNavAPI = document.getElementById("sectNavAPI");
15 const domListNav = document.getElementById("listNav");19 const domListNavAPI = document.getElementById("listNavAPI");
20 const domSectNavGuides = document.getElementById("sectNavGuides");
21 const domListNavGuides = document.getElementById("listNavGuides");
16 const domApiSwitch = document.getElementById("ApiSwitch");22 const domApiSwitch = document.getElementById("ApiSwitch");
17 const domGuideSwitch = document.getElementById("guideSwitch");23 const domGuideSwitch = document.getElementById("guideSwitch");
18 const domGuidesMenu = document.getElementById("guidesMenu");24 const domGuidesMenu = document.getElementById("guidesMenu");
19 const domApiMenu = document.getElementById("apiMenu");25 const domGuidesMenuTitle = document.getElementById("guidesMenuTitle");
20 const domGuidesList = document.getElementById("guidesList");26 const domGuideTocList = document.getElementById("guideTocList");
21 const domSectMainMod = document.getElementById("sectMainMod");27 const domGuideTocListEmtpy = document.getElementById("guideTocListEmpty");
22 const domSectMods = document.getElementById("sectMods");
23 const domListMods = document.getElementById("listMods");28 const domListMods = document.getElementById("listMods");
24 const domSectTypes = document.getElementById("sectTypes");29 const domSectTypes = document.getElementById("sectTypes");
25 const domListTypes = document.getElementById("listTypes");30 const domListTypesLeft = document.getElementById("listTypesLeft");
31 const domListTypesRight = document.getElementById("listTypesRight");
26 const domSectTests = document.getElementById("sectTests");32 const domSectTests = document.getElementById("sectTests");
27 const domListTests = document.getElementById("listTests");33 const domListTests = document.getElementById("listTests");
28 const domSectDocTests = document.getElementById("sectDocTests");34 const domSectDocTests = document.getElementById("sectDocTests");
29 const domDocTestsCode = document.getElementById("docTestsCode");35 const domDocTestsCode = document.getElementById("docTestsCode");
30 const domSectNamespaces = document.getElementById("sectNamespaces");36 const domSectNamespaces = document.getElementById("sectNamespaces");
31 const domListNamespaces = document.getElementById("listNamespaces");37 const domListNamespacesLeft = document.getElementById("listNamespacesLeft");
38 const domListNamespacesRight = document.getElementById("listNamespacesRight");
39 const domNoDocsNamespaces = document.getElementById("noDocsNamespaces");
32 const domSectErrSets = document.getElementById("sectErrSets");40 const domSectErrSets = document.getElementById("sectErrSets");
33 const domListErrSets = document.getElementById("listErrSets");41 const domListErrSets = document.getElementById("listErrSets");
34 const domSectFns = document.getElementById("sectFns");42 const domSectFns = document.getElementById("sectFns");
...@@ -54,16 +62,17 @@ const NAV_MODES = {...@@ -54,16 +62,17 @@ const NAV_MODES = {
54 const domFnNoExamples = document.getElementById("fnNoExamples");62 const domFnNoExamples = document.getElementById("fnNoExamples");
55 const domDeclNoRef = document.getElementById("declNoRef");63 const domDeclNoRef = document.getElementById("declNoRef");
56 const domSearch = document.getElementById("search");64 const domSearch = document.getElementById("search");
65 const domSearchHelp = document.getElementById("searchHelp");
57 const domSearchHelpSummary = document.getElementById("searchHelpSummary");66 const domSearchHelpSummary = document.getElementById("searchHelpSummary");
58 const domSectSearchResults = document.getElementById("sectSearchResults");67 const domSectSearchResults = document.getElementById("sectSearchResults");
59 const domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");68 const domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
60 const domDocs = document.getElementById("docs");69 const domDocs = document.getElementById("docs");
70 const domDocsScroll = document.getElementById("docs-scroll");
61 const domGuidesSection = document.getElementById("guides");71 const domGuidesSection = document.getElementById("guides");
62 const domActiveGuide = document.getElementById("activeGuide");72 const domActiveGuide = document.getElementById("activeGuide");
6373
64 const domListSearchResults = document.getElementById("listSearchResults");74 const domListSearchResults = document.getElementById("listSearchResults");
65 const domSectSearchNoResults = document.getElementById("sectSearchNoResults");75 const domSectSearchNoResults = document.getElementById("sectSearchNoResults");
66 const domSectInfo = document.getElementById("sectInfo");
67 // const domTdTarget = (document.getElementById("tdTarget"));76 // const domTdTarget = (document.getElementById("tdTarget"));
68 const domTdZigVer = document.getElementById("tdZigVer");77 const domTdZigVer = document.getElementById("tdZigVer");
69 const domHdrName = document.getElementById("hdrName");78 const domHdrName = document.getElementById("hdrName");
...@@ -80,6 +89,15 @@ const NAV_MODES = {...@@ -80,6 +89,15 @@ const NAV_MODES = {
8089
81 domPrefSlashSearch.addEventListener("change", () => setPrefSlashSearch(domPrefSlashSearch.checked));90 domPrefSlashSearch.addEventListener("change", () => setPrefSlashSearch(domPrefSlashSearch.checked));
8291
92 const scrollMonitor = [
93 domActiveGuide,
94 domGuideTocList,
95 domDocsScroll,
96 domSectSearchResults,
97 ];
98
99 computeGuideHashes();
100
83 let searchTimer = null;101 let searchTimer = null;
84 let searchTrimResults = true;102 let searchTrimResults = true;
85103
...@@ -107,8 +125,10 @@ const NAV_MODES = {...@@ -107,8 +125,10 @@ const NAV_MODES = {
107 let canonTypeDecls = null; // lazy; use getCanonTypeDecl125 let canonTypeDecls = null; // lazy; use getCanonTypeDecl
108126
109 let curNav = {127 let curNav = {
128 hash: "",
110 mode: NAV_MODES.API,129 mode: NAV_MODES.API,
111 activeGuide: "",130 activeGuide: "",
131 activeGuideScrollTo: null,
112 // each element is a module name, e.g. @import("a") then within there @import("b")132 // each element is a module name, e.g. @import("a") then within there @import("b")
113 // starting implicitly from root module133 // starting implicitly from root module
114 modNames: [],134 modNames: [],
...@@ -423,6 +443,71 @@ const NAV_MODES = {...@@ -423,6 +443,71 @@ const NAV_MODES = {
423 // console.assert(false);443 // console.assert(false);
424 // return ({});444 // return ({});
425 // }445 // }
446 function detectDeclPath(text, context) {
447 let result = "";
448 let separator = ":";
449 const components = text.split(".");
450 let curDeclOrType = undefined;
451
452 let curContext = context;
453 let limit = 10000;
454 while (curContext) {
455 limit -= 1;
456
457 if (limit == 0) {
458 throw "too many iterations";
459 }
460
461 curDeclOrType = findSubDecl(curContext, components[0]);
462
463 if (!curDeclOrType) {
464 if (curContext.parent_container == null) break;
465 curContext = getType(curContext.parent_container);
466 continue;
467 }
468
469 if (curContext == context) {
470 separator = '.';
471 result = location.hash + separator + components[0];
472 } else {
473 // We had to go up, which means we need a new path!
474 const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx);
475 if (!canonPath) return;
476
477 let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
478 let fullPath = lastModName + ":" + canonPath.declNames.join(".");
479
480 separator = '.';
481 result = "#A;" + fullPath;
482 }
483
484 break;
485 }
486
487 if (!curDeclOrType) {
488 for (let i = 0; i < zigAnalysis.modules.length; i += 1){
489 const p = zigAnalysis.modules[i];
490 if (p.name == components[0]) {
491 curDeclOrType = getType(p.main);
492 result += "#A;" + components[0];
493 break;
494 }
495 }
496 }
497
498 if (!curDeclOrType) return null;
499
500 for (let i = 1; i < components.length; i += 1) {
501 curDeclOrType = findSubDecl(curDeclOrType, components[i]);
502 if (!curDeclOrType) return null;
503 result += separator + components[i];
504 separator = '.';
505 }
506
507 return result;
508
509 }
510
426 function renderGuides() {511 function renderGuides() {
427 renderTitle();512 renderTitle();
428513
...@@ -430,46 +515,17 @@ const NAV_MODES = {...@@ -430,46 +515,17 @@ const NAV_MODES = {
430 domGuideSwitch.classList.add("active");515 domGuideSwitch.classList.add("active");
431 domApiSwitch.classList.remove("active");516 domApiSwitch.classList.remove("active");
432 domDocs.classList.add("hidden");517 domDocs.classList.add("hidden");
518 domSectNavAPI.classList.add("hidden");
519 domSectNavGuides.classList.remove("hidden");
433 domGuidesSection.classList.remove("hidden");520 domGuidesSection.classList.remove("hidden");
434 domActiveGuide.classList.add("hidden");521 domActiveGuide.classList.add("hidden");
435 domApiMenu.classList.add("hidden");
436 domSectSearchResults.classList.add("hidden");522 domSectSearchResults.classList.add("hidden");
437 domSectSearchAllResultsLink.classList.add("hidden");523 domSectSearchAllResultsLink.classList.add("hidden");
438 domSectSearchNoResults.classList.add("hidden");524 domSectSearchNoResults.classList.add("hidden");
439
440 // sidebar guides list
441 const section_list = zigAnalysis.guide_sections;
442 resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="modules"></ul></div>');
443 for (let j = 0; j < section_list.length; j += 1) {
444 const section = section_list[j];
445 const domSectionName = domGuidesList.children[j].children[0].children[0];
446 const domGuides = domGuidesList.children[j].children[1];
447 domSectionName.textContent = section.name;
448 resizeDomList(domGuides, section.guides.length, '<li><a href="#"></a></li>');
449 for (let i = 0; i < section.guides.length; i += 1) {
450 const guide = section.guides[i];
451 let liDom = domGuides.children[i];
452 let aDom = liDom.children[0];
453 aDom.textContent = guide.title;
454 aDom.setAttribute("href", NAV_MODES.GUIDES + guide.name);
455 if (guide.name === curNav.activeGuide) {
456 aDom.classList.add("active");
457 } else {
458 aDom.classList.remove("active");
459 }
460 }
461 }
462
463 if (section_list.length > 0) {
464 domGuidesMenu.classList.remove("hidden");
465 }
466
467
468 if (curNavSearch !== "") {525 if (curNavSearch !== "") {
469 return renderSearchGuides();526 return renderSearchGuides();
470 }527 }
471528
472 // main content
473 let activeGuide = undefined;529 let activeGuide = undefined;
474 outer: for (let i = 0; i < zigAnalysis.guide_sections.length; i += 1) {530 outer: for (let i = 0; i < zigAnalysis.guide_sections.length; i += 1) {
475 const section = zigAnalysis.guide_sections[i];531 const section = zigAnalysis.guide_sections[i];
...@@ -482,11 +538,137 @@ const NAV_MODES = {...@@ -482,11 +538,137 @@ const NAV_MODES = {
482 }538 }
483 }539 }
484540
485 if (activeGuide == undefined) {541
542 // navigation bar
543
544 const guideIndexDom = domListNavGuides.children[0].children[0];
545 const guideDom = domListNavGuides.children[1].children[0];
546 if (activeGuide){
547 guideDom.textContent = activeGuide.title;
548 guideDom.setAttribute("href", location.hash);
549 guideDom.classList.remove("hidden");
550 guideIndexDom.classList.remove("active");
551 } else {
552 guideDom.classList.add("hidden");
553 guideIndexDom.classList.add("active");
554 }
555
556 // main content
557 domGuidesMenuTitle.textContent = "Table of Contents";
558 if (activeGuide) {
559 if (activeGuide.toc != "") {
560 domGuideTocList.innerHTML = activeGuide.toc;
561 // add js callbacks to all links
562 function onLinkClick(ev) {
563 const link = ev.target.getAttribute("href");
564 skipNextHashChange = link;
565 location.replace(link);
566 scrollToHeading(":" + link.split(":")[1], true);
567 ev.preventDefault();
568 ev.stopPropagation();
569 }
570 for (let a of domGuideTocList.querySelectorAll("a")) {
571 a.addEventListener('click', onLinkClick, false);
572 }
573 domGuideTocList.classList.remove("hidden");
574 domGuideTocListEmtpy.classList.add("hidden");
575 } else {
576 domGuideTocListEmtpy.classList.remove("hidden");
577 domGuideTocList.classList.add("hidden");
578 }
579
580 let reader = new commonmark.Parser({
581 smart: true,
582 autoDoc: {
583 detectDeclPath: detectDeclPath,
584 }
585 });
586 let ast = reader.parse(activeGuide.body);
587 let writer = new commonmark.HtmlRenderer();
588 let result = writer.render(ast);
589 domActiveGuide.innerHTML = result;
590 if (curNav.activeGuideScrollTo !== null) {
591 scrollToHeading(curNav.activeGuideScrollTo, false);
592 }
593 } else {
594 domGuideTocList.classList.add("hidden");
595 domGuideTocListEmtpy.classList.remove("hidden");
596
597 if (zigAnalysis.guide_sections.length > 1 || (zigAnalysis.guide_sections[0].guides.length > 0)) {
598 renderGuidesIndex();
599 } else {
600 noGuidesAtAll();
601 }
602 }
603
604 domGuidesMenu.classList.remove("hidden");
605 domActiveGuide.classList.remove("hidden");
606 }
607
608 // TODO: ensure unique hashes
609 // TODO: hash also guides and their headings
610 function computeGuideHashes() {
611 for (let i = 1; i < zigAnalysis.guide_sections.length; i += 1) {
612 const section = zigAnalysis.guide_sections[i];
613 section.hash = "section-" + slugify(section.name || i);
614 }
615 }
616
617 function renderGuidesIndex() {
618 // main content
619 {
620 let html = "";
621 for (let i = 0; i < zigAnalysis.guide_sections.length; i += 1) {
622 const section = zigAnalysis.guide_sections[i];
623 if (i != 0) { // first section is the default section
624 html += "<h2 id='"+ section.hash +"'>" + section.name + "</h2>";
625 }
626 for (let guide of section.guides) {
627 html += "<ol><li><a href='"+ NAV_MODES.GUIDES + guide.name +"'>" + (guide.title || guide.name) + "</a></li>";
628 html += guide.toc + "</ol>";
629 }
630 }
631 domActiveGuide.innerHTML = html;
632 }
633
634 // sidebar / fast navigation
635 {
636 domGuidesMenuTitle.textContent = "Sections";
637 if (zigAnalysis.guide_sections.length > 1) {
638 let html = "";
639 for (let i = 1; i < zigAnalysis.guide_sections.length; i += 1) {
640 const section = zigAnalysis.guide_sections[i];
641 html += "<li><a href='"+ NAV_MODES.GUIDES + ":" + section.hash +"'>" + section.name + "</a></li>";
642 }
643 domGuideTocList.innerHTML = "<ul>"+html+"</ul>";
644
645 function onLinkClick(ev) {
646 const link = ev.target.getAttribute("href");
647 skipNextHashChange = link;
648 location.replace(link);
649 scrollToHeading(link.split(":")[1], true);
650 ev.preventDefault();
651 ev.stopPropagation();
652 }
653 for (let a of domGuideTocList.querySelectorAll("a")) {
654 a.addEventListener('click', onLinkClick, false);
655 }
656
657 domGuideTocList.classList.remove("hidden");
658 domGuideTocListEmtpy.classList.add("hidden");
659 } else {
660 domGuideTocList.classList.add("hidden");
661 domGuideTocListEmtpy.classList.remove("hidden");
662 }
663 }
664 }
665
666 function noGuidesAtAll() {
486 const root_file_idx = zigAnalysis.modules[zigAnalysis.rootMod].file;667 const root_file_idx = zigAnalysis.modules[zigAnalysis.rootMod].file;
487 const root_file_name = getFile(root_file_idx).name;668 const root_file_name = getFile(root_file_idx).name;
488 domActiveGuide.innerHTML = markdown(`669 let reader = new commonmark.Parser({smart: true});
489# Zig Guides670 let ast = reader.parse(`
671# No Guides
490These autodocs don't contain any guide.672These autodocs don't contain any guide.
491673
492While the API section is a reference guide autogenerated from Zig source code,674While the API section is a reference guide autogenerated from Zig source code,
...@@ -520,10 +702,11 @@ You can also create sections to group guides together:...@@ -520,10 +702,11 @@ You can also create sections to group guides together:
520702
521Happy writing!703Happy writing!
522`);704`);
523 } else {705
524 domActiveGuide.innerHTML = markdown(activeGuide.body);706 let writer = new commonmark.HtmlRenderer();
525 }707 let result = writer.render(ast);
526 domActiveGuide.classList.remove("hidden");708 domActiveGuide.innerHTML = result;
709
527 }710 }
528711
529 function renderApi() {712 function renderApi() {
...@@ -531,29 +714,28 @@ Happy writing!...@@ -531,29 +714,28 @@ Happy writing!
531 domApiSwitch.classList.add("active");714 domApiSwitch.classList.add("active");
532 domGuideSwitch.classList.remove("active");715 domGuideSwitch.classList.remove("active");
533 domGuidesSection.classList.add("hidden");716 domGuidesSection.classList.add("hidden");
717 domSectNavAPI.classList.remove("hidden");
718 domSectNavGuides.classList.add("hidden");
534 domDocs.classList.remove("hidden");719 domDocs.classList.remove("hidden");
535 domApiMenu.classList.remove("hidden");
536 domGuidesMenu.classList.add("hidden");720 domGuidesMenu.classList.add("hidden");
537
538 domStatus.classList.add("hidden");721 domStatus.classList.add("hidden");
539 domFnProto.classList.add("hidden");722 domFnProto.classList.add("hidden");
540 domSectParams.classList.add("hidden");723 domSectParams.classList.add("hidden");
541 domTldDocs.classList.add("hidden");724 domTldDocs.classList.add("hidden");
542 domSectMainMod.classList.add("hidden");
543 domSectMods.classList.add("hidden");
544 domSectTypes.classList.add("hidden");725 domSectTypes.classList.add("hidden");
545 domSectTests.classList.add("hidden");726 domSectTests.classList.add("hidden");
546 domSectDocTests.classList.add("hidden");727 domSectDocTests.classList.add("hidden");
547 domSectNamespaces.classList.add("hidden");728 domSectNamespaces.classList.add("hidden");
729 domListNamespacesLeft.classList.add("hidden");
730 domListNamespacesRight.classList.add("hidden");
731 domNoDocsNamespaces.classList.add("hidden");
548 domSectErrSets.classList.add("hidden");732 domSectErrSets.classList.add("hidden");
549 domSectFns.classList.add("hidden");733 domSectFns.classList.add("hidden");
550 domSectFields.classList.add("hidden");734 domSectFields.classList.add("hidden");
551 domSectSearchResults.classList.add("hidden");735 domSectSearchResults.classList.add("hidden");
552 domSectSearchAllResultsLink.classList.add("hidden");736 domSectSearchAllResultsLink.classList.add("hidden");
553 domSectSearchNoResults.classList.add("hidden");737 domSectSearchNoResults.classList.add("hidden");
554 domSectInfo.classList.add("hidden");
555 domHdrName.classList.add("hidden");738 domHdrName.classList.add("hidden");
556 domSectNav.classList.add("hidden");
557 domSectFnErrors.classList.add("hidden");739 domSectFnErrors.classList.add("hidden");
558 domFnExamples.classList.add("hidden");740 domFnExamples.classList.add("hidden");
559 domFnNoExamples.classList.add("hidden");741 domFnNoExamples.classList.add("hidden");
...@@ -564,8 +746,6 @@ Happy writing!...@@ -564,8 +746,6 @@ Happy writing!
564 domSectValues.classList.add("hidden");746 domSectValues.classList.add("hidden");
565747
566 renderTitle();748 renderTitle();
567 renderInfo();
568 renderModList();
569749
570 if (curNavSearch !== "") {750 if (curNavSearch !== "") {
571 return renderSearchAPI();751 return renderSearchAPI();
...@@ -870,7 +1050,7 @@ Happy writing!...@@ -870,7 +1050,7 @@ Happy writing!
8701050
871 function renderNav() {1051 function renderNav() {
872 let len = curNav.modNames.length + curNav.declNames.length;1052 let len = curNav.modNames.length + curNav.declNames.length;
873 resizeDomList(domListNav, len, '<li><a href="#"></a></li>');1053 resizeDomList(domListNavAPI, len, '<li><a href="#"></a></li>');
874 let list = [];1054 let list = [];
875 let hrefModNames = [];1055 let hrefModNames = [];
876 let hrefDeclNames = [];1056 let hrefDeclNames = [];
...@@ -891,7 +1071,7 @@ Happy writing!...@@ -891,7 +1071,7 @@ Happy writing!
891 }1071 }
8921072
893 for (let i = 0; i < list.length; i += 1) {1073 for (let i = 0; i < list.length; i += 1) {
894 let liDom = domListNav.children[i];1074 let liDom = domListNavAPI.children[i];
895 let aDom = liDom.children[0];1075 let aDom = liDom.children[0];
896 aDom.textContent = list[i].name;1076 aDom.textContent = list[i].name;
897 aDom.setAttribute("href", list[i].link);1077 aDom.setAttribute("href", list[i].link);
...@@ -902,67 +1082,60 @@ Happy writing!...@@ -902,67 +1082,60 @@ Happy writing!
902 }1082 }
903 }1083 }
9041084
905 domSectNav.classList.remove("hidden");
906 }1085 }
9071086
908 function renderInfo() {
909 domTdZigVer.textContent = zigAnalysis.params.zigVersion;
910 //domTdTarget.textContent = zigAnalysis.params.builds[0].target;
911
912 domSectInfo.classList.remove("hidden");
913 }
9141087
915 function render404() {1088 function render404() {
916 domStatus.textContent = "404 Not Found";1089 domStatus.textContent = "404 Not Found";
917 domStatus.classList.remove("hidden");1090 domStatus.classList.remove("hidden");
918 }1091 }
9191092
920 function renderModList() {1093 // function renderModList() {
921 const rootMod = zigAnalysis.modules[zigAnalysis.rootMod];1094 // const rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
922 let list = [];1095 // let list = [];
923 for (let key in rootMod.table) {1096 // for (let key in rootMod.table) {
924 let modIndex = rootMod.table[key];1097 // let modIndex = rootMod.table[key];
925 if (zigAnalysis.modules[modIndex] == null) continue;1098 // if (zigAnalysis.modules[modIndex] == null) continue;
926 if (key == rootMod.name) continue;1099 // if (key == rootMod.name) continue;
927 list.push({1100 // list.push({
928 name: key,1101 // name: key,
929 mod: modIndex,1102 // mod: modIndex,
930 });1103 // });
931 }1104 // }
9321105
933 {1106 // {
934 let aDom = domSectMainMod.children[1].children[0].children[0];1107 // let aDom = domSectMainMod.children[1].children[0].children[0];
935 aDom.textContent = rootMod.name;1108 // aDom.textContent = rootMod.name;
936 aDom.setAttribute("href", navLinkMod(zigAnalysis.rootMod));1109 // aDom.setAttribute("href", navLinkMod(zigAnalysis.rootMod));
937 if (rootMod.name === curNav.modNames[0]) {1110 // if (rootMod.name === curNav.modNames[0]) {
938 aDom.classList.add("active");1111 // aDom.classList.add("active");
939 } else {1112 // } else {
940 aDom.classList.remove("active");1113 // aDom.classList.remove("active");
941 }1114 // }
942 domSectMainMod.classList.remove("hidden");1115 // domSectMainMod.classList.remove("hidden");
943 }1116 // }
9441117
945 list.sort(function(a, b) {1118 // list.sort(function (a, b) {
946 return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase());1119 // return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase());
947 });1120 // });
9481121
949 if (list.length !== 0) {1122 // if (list.length !== 0) {
950 resizeDomList(domListMods, list.length, '<li><a href="#"></a></li>');1123 // resizeDomList(domListMods, list.length, '<li><a href="#"></a></li>');
951 for (let i = 0; i < list.length; i += 1) {1124 // for (let i = 0; i < list.length; i += 1) {
952 let liDom = domListMods.children[i];1125 // let liDom = domListMods.children[i];
953 let aDom = liDom.children[0];1126 // let aDom = liDom.children[0];
954 aDom.textContent = list[i].name;1127 // aDom.textContent = list[i].name;
955 aDom.setAttribute("href", navLinkMod(list[i].mod));1128 // aDom.setAttribute("href", navLinkMod(list[i].mod));
956 if (list[i].name === curNav.modNames[0]) {1129 // if (list[i].name === curNav.modNames[0]) {
957 aDom.classList.add("active");1130 // aDom.classList.add("active");
958 } else {1131 // } else {
959 aDom.classList.remove("active");1132 // aDom.classList.remove("active");
960 }1133 // }
961 }1134 // }
9621135
963 domSectMods.classList.remove("hidden");1136 // domSectMods.classList.remove("hidden");
964 }1137 // }
965 }1138 // }
9661139
967 function navLink(modNames, declNames, callName) {1140 function navLink(modNames, declNames, callName) {
968 let base = curNav.mode;1141 let base = curNav.mode;
...@@ -2525,7 +2698,8 @@ Happy writing!...@@ -2525,7 +2698,8 @@ Happy writing!
2525 function categorizeDecls(2698 function categorizeDecls(
2526 decls,2699 decls,
2527 typesList,2700 typesList,
2528 namespacesList,2701 namespacesWithDocsList,
2702 namespacesNoDocsList,
2529 errSetsList,2703 errSetsList,
2530 fnsList,2704 fnsList,
2531 varsList,2705 varsList,
...@@ -2562,7 +2736,11 @@ Happy writing!...@@ -2562,7 +2736,11 @@ Happy writing!
2562 if (typeIsErrSet(declValue.expr.type)) {2736 if (typeIsErrSet(declValue.expr.type)) {
2563 errSetsList.push(decl);2737 errSetsList.push(decl);
2564 } else if (typeIsStructWithNoFields(declValue.expr.type)) {2738 } else if (typeIsStructWithNoFields(declValue.expr.type)) {
2565 namespacesList.push(decl);2739 if (getAstNode(decl.src).docs) {
2740 namespacesWithDocsList.push(decl);
2741 } else {
2742 namespacesNoDocsList.push(decl);
2743 }
2566 } else {2744 } else {
2567 typesList.push(decl);2745 typesList.push(decl);
2568 }2746 }
...@@ -2573,7 +2751,11 @@ Happy writing!...@@ -2573,7 +2751,11 @@ Happy writing!
2573 if (typeIsErrSet(declValue.expr.type)) {2751 if (typeIsErrSet(declValue.expr.type)) {
2574 errSetsList.push(decl);2752 errSetsList.push(decl);
2575 } else if (typeIsStructWithNoFields(declValue.expr.type)) {2753 } else if (typeIsStructWithNoFields(declValue.expr.type)) {
2576 namespacesList.push(decl);2754 if (getAstNode(decl.src).docs) {
2755 namespacesWithDocsList.push(decl);
2756 } else {
2757 namespacesNoDocsList.push(decl);
2758 }
2577 } else {2759 } else {
2578 typesList.push(decl);2760 typesList.push(decl);
2579 }2761 }
...@@ -2608,7 +2790,8 @@ Happy writing!...@@ -2608,7 +2790,8 @@ Happy writing!
2608 function renderContainer(container) {2790 function renderContainer(container) {
2609 let typesList = [];2791 let typesList = [];
26102792
2611 let namespacesList = [];2793 let namespacesWithDocsList = [];
2794 let namespacesNoDocsList = [];
26122795
2613 let errSetsList = [];2796 let errSetsList = [];
26142797
...@@ -2625,7 +2808,8 @@ Happy writing!...@@ -2625,7 +2808,8 @@ Happy writing!
2625 categorizeDecls(2808 categorizeDecls(
2626 container.pubDecls,2809 container.pubDecls,
2627 typesList,2810 typesList,
2628 namespacesList,2811 namespacesWithDocsList,
2812 namespacesNoDocsList,
2629 errSetsList,2813 errSetsList,
2630 fnsList,2814 fnsList,
2631 varsList,2815 varsList,
...@@ -2637,7 +2821,8 @@ Happy writing!...@@ -2637,7 +2821,8 @@ Happy writing!
2637 categorizeDecls(2821 categorizeDecls(
2638 container.privDecls,2822 container.privDecls,
2639 typesList,2823 typesList,
2640 namespacesList,2824 namespacesWithDocsList,
2825 namespacesNoDocsList,
2641 errSetsList,2826 errSetsList,
2642 fnsList,2827 fnsList,
2643 varsList,2828 varsList,
...@@ -2655,7 +2840,8 @@ Happy writing!...@@ -2655,7 +2840,8 @@ Happy writing!
2655 categorizeDecls(2840 categorizeDecls(
2656 uns_container.pubDecls,2841 uns_container.pubDecls,
2657 typesList,2842 typesList,
2658 namespacesList,2843 namespacesWithDocsList,
2844 namespacesNoDocsList,
2659 errSetsList,2845 errSetsList,
2660 fnsList,2846 fnsList,
2661 varsList,2847 varsList,
...@@ -2667,7 +2853,8 @@ Happy writing!...@@ -2667,7 +2853,8 @@ Happy writing!
2667 categorizeDecls(2853 categorizeDecls(
2668 uns_container.privDecls,2854 uns_container.privDecls,
2669 typesList,2855 typesList,
2670 namespacesList,2856 namespacesWithDocsList,
2857 namespacesNoDocsList,
2671 errSetsList,2858 errSetsList,
2672 fnsList,2859 fnsList,
2673 varsList,2860 varsList,
...@@ -2678,7 +2865,8 @@ Happy writing!...@@ -2678,7 +2865,8 @@ Happy writing!
2678 }2865 }
26792866
2680 typesList.sort(byNameProperty);2867 typesList.sort(byNameProperty);
2681 namespacesList.sort(byNameProperty);2868 namespacesWithDocsList.sort(byNameProperty);
2869 namespacesNoDocsList.sort(byNameProperty);
2682 errSetsList.sort(byNameProperty);2870 errSetsList.sort(byNameProperty);
2683 fnsList.sort(byNameProperty);2871 fnsList.sort(byNameProperty);
2684 varsList.sort(byNameProperty);2872 varsList.sort(byNameProperty);
...@@ -2694,36 +2882,91 @@ Happy writing!...@@ -2694,36 +2882,91 @@ Happy writing!
2694 }2882 }
26952883
2696 if (typesList.length !== 0) {2884 if (typesList.length !== 0) {
2697 resizeDomList(2885 const splitPoint = Math.ceil(typesList.length / 2);
2698 domListTypes,2886 const template = '<li><a href="#"></a><div></div></li>';
2699 typesList.length,2887 resizeDomList(domListTypesLeft, splitPoint, template);
2700 '<li><a href=""></a></li>'2888 resizeDomList(domListTypesRight, typesList.length - splitPoint, template);
2701 );2889
2890 let activeList = domListTypesLeft;
2891 let offset = 0;
2702 for (let i = 0; i < typesList.length; i += 1) {2892 for (let i = 0; i < typesList.length; i += 1) {
2703 let liDom = domListTypes.children[i];2893 let liDom = activeList.children[i - offset];
2704 let aDom = liDom.children[0];2894 let aDom = liDom.children[0];
2705 let decl = typesList[i];2895 let decl = typesList[i];
2706 aDom.textContent = decl.name;2896 aDom.textContent = decl.name;
2707 aDom.setAttribute("href", navLinkDecl(decl.name));2897 aDom.setAttribute("href", navLinkDecl(decl.name));
2898
2899 let descDom = liDom.children[1];
2900 let docs = getAstNode(decl.src).docs;
2901 if (docs) {
2902 descDom.innerHTML = markdown(shortDesc(getAstNode(decl.src).docs));
2903 } else {
2904 descDom.innerHTML = "<p class='understated'><i>No documentation provided.</i></p>";
2905 }
2906 if (i == splitPoint - 1) {
2907 activeList = domListTypesRight;
2908 offset = splitPoint;
2909 }
2708 }2910 }
2709 domSectTypes.classList.remove("hidden");2911 domSectTypes.classList.remove("hidden");
2710 }2912 }
2711 if (namespacesList.length !== 0) {2913
2914 if (namespacesWithDocsList.length !== 0) {
2915 const splitPoint = Math.ceil(namespacesWithDocsList.length / 2);
2916 const template = '<li><a href="#"></a><div></div></li>';
2917 resizeDomList(domListNamespacesLeft, splitPoint, template);
2918 resizeDomList(domListNamespacesRight,
2919 namespacesWithDocsList.length - splitPoint,
2920 template);
2921
2922 let activeList = domListNamespacesLeft;
2923 let offset = 0;
2924 for (let i = 0; i < namespacesWithDocsList.length; i += 1) {
2925 let liDom = activeList.children[i - offset];
2926 let aDom = liDom.children[0];
2927 let decl = namespacesWithDocsList[i];
2928 aDom.textContent = decl.name;
2929 aDom.setAttribute("href", navLinkDecl(decl.name));
2930
2931 let descDom = liDom.children[1];
2932 descDom.innerHTML = markdown(shortDesc(getAstNode(decl.src).docs));
2933 if (i == splitPoint - 1) {
2934 activeList = domListNamespacesRight;
2935 offset = splitPoint;
2936 }
2937 }
2938
2939 domListNamespacesLeft.classList.remove("hidden");
2940 domListNamespacesRight.classList.remove("hidden");
2941 domSectNamespaces.classList.remove("hidden");
2942 }
2943
2944 if (namespacesNoDocsList.length !== 0) {
2712 resizeDomList(2945 resizeDomList(
2713 domListNamespaces,2946 domNoDocsNamespaces,
2714 namespacesList.length,2947 namespacesNoDocsList.length,
2715 '<li><a href="#"></a></li>'2948 '<span><a href="#"></a><span></span></span>'
2716 );2949 );
2717 for (let i = 0; i < namespacesList.length; i += 1) {2950 for (let i = 0; i < namespacesNoDocsList.length; i += 1) {
2718 let liDom = domListNamespaces.children[i];2951 let aDom = domNoDocsNamespaces.children[i].children[0];
2719 let aDom = liDom.children[0];2952 let decl = namespacesNoDocsList[i];
2720 let decl = namespacesList[i];
2721 aDom.textContent = decl.name;2953 aDom.textContent = decl.name;
2722 aDom.setAttribute("href", navLinkDecl(decl.name));2954 aDom.setAttribute("href", navLinkDecl(decl.name));
2955 let comma = domNoDocsNamespaces.children[i].children[1];
2956 if (i == namespacesNoDocsList.length - 1) {
2957 comma.textContent = "";
2958 } else {
2959 comma.textContent = ", ";
2960 }
2723 }2961 }
2962
2963 domNoDocsNamespaces.classList.remove("hidden");
2724 domSectNamespaces.classList.remove("hidden");2964 domSectNamespaces.classList.remove("hidden");
2725 }2965 }
27262966
2967
2968
2969
2727 if (errSetsList.length !== 0) {2970 if (errSetsList.length !== 0) {
2728 resizeDomList(2971 resizeDomList(
2729 domListErrSets,2972 domListErrSets,
...@@ -2778,7 +3021,7 @@ Happy writing!...@@ -2778,7 +3021,7 @@ Happy writing!
2778 tdDesc.innerHTML = markdown(short, container);3021 tdDesc.innerHTML = markdown(short, container);
2779 }3022 }
2780 } else {3023 } else {
2781 tdDesc.innerHTML = "<p><i>No documentation provided.</i><p>";3024 tdDesc.innerHTML = "<p class='understated'><i>No documentation provided.</i><p>";
2782 }3025 }
2783 }3026 }
2784 domSectFns.classList.remove("hidden");3027 domSectFns.classList.remove("hidden");
...@@ -3013,12 +3256,15 @@ Happy writing!...@@ -3013,12 +3256,15 @@ Happy writing!
30133256
3014 function updateCurNav() {3257 function updateCurNav() {
3015 curNav = {3258 curNav = {
3259 hash: location.hash,
3016 mode: NAV_MODES.API,3260 mode: NAV_MODES.API,
3017 modNames: [],3261 modNames: [],
3018 modObjs: [],3262 modObjs: [],
3019 declNames: [],3263 declNames: [],
3020 declObjs: [],3264 declObjs: [],
3021 callName: null,3265 callName: null,
3266 activeGuide: null,
3267 activeGuideScrollTo: null,
3022 };3268 };
3023 curNavSearch = "";3269 curNavSearch = "";
30243270
...@@ -3039,7 +3285,7 @@ Happy writing!...@@ -3039,7 +3285,7 @@ Happy writing!
3039 case NAV_MODES.API:3285 case NAV_MODES.API:
3040 // #A;MODULE:decl.decl.decl?search-term3286 // #A;MODULE:decl.decl.decl?search-term
3041 curNav.mode = mode;3287 curNav.mode = mode;
30423288 {
3043 let parts = nonSearchPart.split(":");3289 let parts = nonSearchPart.split(":");
3044 if (parts[0] == "") {3290 if (parts[0] == "") {
3045 location.hash = DEFAULT_HASH;3291 location.hash = DEFAULT_HASH;
...@@ -3050,22 +3296,18 @@ Happy writing!...@@ -3050,22 +3296,18 @@ Happy writing!
3050 if (parts[1] != null) {3296 if (parts[1] != null) {
3051 curNav.declNames = decodeURIComponent(parts[1]).split(".");3297 curNav.declNames = decodeURIComponent(parts[1]).split(".");
3052 }3298 }
30533299 }
3054 return;3300 return;
3055 case NAV_MODES.GUIDES:3301 case NAV_MODES.GUIDES:
3302 curNav.mode = mode;
30563303
3057 const sections = zigAnalysis.guide_sections;3304 {
3058 if (sections.length != 0 && sections[0].guides.length != 0 && nonSearchPart == "") {3305 let parts = nonSearchPart.split(":");
3059 location.hash = NAV_MODES.GUIDES + sections[0].guides[0].name;3306 curNav.activeGuide = parts[0];
3060 if (qpos != -1) {3307 if (parts[1] != null) {
3061 location.hash += query.substring(qpos);3308 curNav.activeGuideScrollTo = decodeURIComponent(":" + parts[1]);
3062 }3309 }
3063 return;
3064 }3310 }
3065
3066 curNav.mode = mode;
3067 curNav.activeGuide = nonSearchPart;
3068
3069 return;3311 return;
3070 default:3312 default:
3071 location.hash = DEFAULT_HASH;3313 location.hash = DEFAULT_HASH;
...@@ -3073,8 +3315,18 @@ Happy writing!...@@ -3073,8 +3315,18 @@ Happy writing!
3073 }3315 }
3074 }3316 }
30753317
3076 function onHashChange() {3318 function onHashChange(ev) {
3319 scrollHistory[curNav.hash] = scrollMonitor.map(function (x) {
3320 return [x, x.scrollTop]
3321 });
3322
3323 if (skipNextHashChange == decodeURIComponent(location.hash)) {
3324 skipNextHashChange = null;
3325 return;
3326 }
3327 skipNextHashChange = null;
3077 updateCurNav();3328 updateCurNav();
3329
3078 if (domSearch.value !== curNavSearch) {3330 if (domSearch.value !== curNavSearch) {
3079 domSearch.value = curNavSearch;3331 domSearch.value = curNavSearch;
3080 if (domSearch.value.length == 0)3332 if (domSearch.value.length == 0)
...@@ -3087,6 +3339,22 @@ Happy writing!...@@ -3087,6 +3339,22 @@ Happy writing!
3087 imFeelingLucky = false;3339 imFeelingLucky = false;
3088 activateSelectedResult();3340 activateSelectedResult();
3089 }3341 }
3342
3343 scroll();
3344 }
3345
3346 function scroll() {
3347 const cur = scrollHistory[location.hash];
3348 if (cur) {
3349 for (let [elem, offset] of cur) {
3350 elem.scrollTo(0, offset);
3351 }
3352 } else {
3353 if (curNav.activeGuideScrollTo) return;
3354 for (let elem of scrollMonitor) {
3355 elem.scrollTo(0, 0);
3356 }
3357 }
3090 }3358 }
30913359
3092 function findSubDecl(parentTypeOrDecl, childName) {3360 function findSubDecl(parentTypeOrDecl, childName) {
...@@ -3384,9 +3652,9 @@ Happy writing!...@@ -3384,9 +3652,9 @@ Happy writing!
3384 let index = trimmed_docs.indexOf("\n\n");3652 let index = trimmed_docs.indexOf("\n\n");
3385 let cut = false;3653 let cut = false;
33863654
3387 if (index < 0 || index > 80) {3655 if (index < 0 || index > 130) {
3388 if (trimmed_docs.length > 80) {3656 if (trimmed_docs.length > 130) {
3389 index = 80;3657 index = 130;
3390 cut = true;3658 cut = true;
3391 } else {3659 } else {
3392 index = trimmed_docs.length;3660 index = trimmed_docs.length;
...@@ -3408,31 +3676,118 @@ Happy writing!...@@ -3408,31 +3676,118 @@ Happy writing!
3408 for (let i = 0; i < section.guides.length; i += 1) {3676 for (let i = 0; i < section.guides.length; i += 1) {
3409 let reader = new commonmark.Parser({ smart: true });3677 let reader = new commonmark.Parser({ smart: true });
3410 const guide = section.guides[i];3678 const guide = section.guides[i];
3411 const ast = reader.parse(guide.body);
34123679
3413 // Find the first text thing to use as a sidebar title3680 // Find the first text thing to use as a sidebar title
3414 guide.title = "[empty guide]";3681 guide.title = null;
3682 guide.toc = "";
3683
3684 // Discover Title & TOC for this guide
3415 {3685 {
3686 let reader = new commonmark.Parser({smart: true});
3687 let ast = reader.parse(guide.body);
3416 let walker = ast.walker();3688 let walker = ast.walker();
3417 let event, node;3689 let heading_idx = 0;
3690 let event, node, doc, last, last_ul;
3418 while ((event = walker.next())) {3691 while ((event = walker.next())) {
3419 node = event.node;3692 node = event.node;
3420 if (node.type === 'text') {3693 if (event.entering) {
3421 guide.title = node.literal;3694 if (node.type === 'document') {
3422 break;3695 doc = node;
3696 continue;
3697 }
3698
3699
3700 if (node.next) {
3701 walker.resumeAt(node.next, true);
3702 } else {
3703 walker.resumeAt(node, false);
3704 }
3705 node.unlink();
3706
3707 if (node.type === 'heading') {
3708 if (node.level == 1) {
3709 if (guide.title == null) {
3710 let doc_node = new commonmark.Node("document", node.sourcepos);
3711 while (node.firstChild) {
3712 doc_node.appendChild(node.firstChild);
3713 }
3714 let writer = new commonmark.HtmlRenderer();
3715 let result = writer.render(doc_node);
3716 guide.title = result;
3717 }
3718
3719 continue; // don't index H1
3720 }
3721
3722 // turn heading node into list item & add link node to it
3723 {
3724 node._type = "link";
3725 node.destination = NAV_MODES.GUIDES + guide.name + ":" + heading_idx;
3726 heading_idx += 1;
3727 let listItem = new commonmark.Node("item", node.sourcepos);
3728 // TODO: strip links from inside node
3729 listItem.appendChild(node);
3730 listItem.level = node.level;
3731 node = listItem;
3732 }
3733
3734 if (last_ul) {
3735 // are we inside or outside of it?
3736
3737 let target_ul = last_ul;
3738 while(target_ul.level > node.level) {
3739 target_ul = target_ul.parent;
3740 }
3741 while(target_ul.level < node.level) {
3742 let ul_node = new commonmark.Node("list", node.sourcepos);
3743 ul_node.level = target_ul.level + 1;
3744 ul_node.listType = "bullet";
3745 ul_node.listStart = null;
3746 target_ul.appendChild(ul_node);
3747 target_ul = ul_node;
3748 }
3749
3750 target_ul.appendChild(node);
3751 last_ul = target_ul;
3752 } else {
3753 let ul_node = new commonmark.Node("list", node.sourcepos);
3754 ul_node.level = 2;
3755 ul_node.listType = "bullet";
3756 ul_node.listStart = null;
3757 doc.prependChild(ul_node);
3758
3759 while (ul_node.level < node.level) {
3760 let current_ul_node = new commonmark.Node("list", node.sourcepos);
3761 current_ul_node.level = ul_node.level + 1;
3762 current_ul_node.listType = "bullet";
3763 current_ul_node.listStart = null;
3764 ul_node.appendChild(current_ul_node);
3765 ul_node = current_ul_node;
3766 }
3767
3768 last_ul = ul_node;
3769
3770 ul_node.appendChild(node);
3423 }3771 }
3424 }3772 }
3425 }3773 }
3774 }
3775
3776 let writer = new commonmark.HtmlRenderer();
3777 let result = writer.render(ast);
3778 guide.toc = result;
3779 }
3780
3426 // Index this guide3781 // Index this guide
3427 {3782 {
3428 let walker = ast.walker();3783 // let walker = guide.ast.walker();
3429 let event, node;3784 // let event, node;
3430 while ((event = walker.next())) {3785 // while ((event = walker.next())) {
3431 node = event.node;3786 // node = event.node;
3432 if (event.entering == true && node.type === 'text') {3787 // if (event.entering == true && node.type === 'text') {
3433 indexTextForGuide(j, i, node);3788 // indexTextForGuide(j, i, node);
3434 }3789 // }
3435 }3790 // }
3436 }3791 }
3437 }3792 }
3438 }3793 }
...@@ -3474,70 +3829,70 @@ Happy writing!...@@ -3474,70 +3829,70 @@ Happy writing!
34743829
34753830
34763831
3477 function detectDeclPath(text, context) {3832 // function detectDeclPath(text, context) {
3478 let result = "";3833 // let result = "";
3479 let separator = ":";3834 // let separator = ":";
3480 const components = text.split(".");3835 // const components = text.split(".");
3481 let curDeclOrType = undefined;3836 // let curDeclOrType = undefined;
34823837
3483 let curContext = context;3838 // let curContext = context;
3484 let limit = 10000;3839 // let limit = 10000;
3485 while (curContext) {3840 // while (curContext) {
3486 limit -= 1;3841 // limit -= 1;
34873842
3488 if (limit == 0) {3843 // if (limit == 0) {
3489 throw "too many iterations";3844 // throw "too many iterations";
3490 }3845 // }
3491
3492 curDeclOrType = findSubDecl(curContext, components[0]);
34933846
3494 if (!curDeclOrType) {3847 // curDeclOrType = findSubDecl(curContext, components[0]);
3495 if (curContext.parent_container == null) break;
3496 curContext = getType(curContext.parent_container);
3497 continue;
3498 }
34993848
3500 if (curContext == context) {3849 // if (!curDeclOrType) {
3501 separator = '.';3850 // if (curContext.parent_container == null) break;
3502 result = location.hash + separator + components[0];3851 // curContext = getType(curContext.parent_container);
3503 } else {3852 // continue;
3504 // We had to go up, which means we need a new path!3853 // }
3505 const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx);
3506 if (!canonPath) return;
35073854
3508 let lastModName = canonPath.modNames[canonPath.modNames.length - 1];3855 // if (curContext == context) {
3509 let fullPath = lastModName + ":" + canonPath.declNames.join(".");3856 // separator = '.';
3857 // result = location.hash + separator + components[0];
3858 // } else {
3859 // // We had to go up, which means we need a new path!
3860 // const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx);
3861 // if (!canonPath) return;
35103862
3511 separator = '.';3863 // let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
3512 result = "#A;" + fullPath;3864 // let fullPath = lastModName + ":" + canonPath.declNames.join(".");
3513 }
35143865
3515 break;3866 // separator = '.';
3516 }3867 // result = "#A;" + fullPath;
3868 // }
35173869
3518 if (!curDeclOrType) {3870 // break;
3519 for (let i = 0; i < zigAnalysis.modules.length; i += 1) {3871 // }
3520 const p = zigAnalysis.modules[i];3872
3521 if (p.name == components[0]) {3873 // if (!curDeclOrType) {
3522 curDeclOrType = getType(p.main);3874 // for (let i = 0; i < zigAnalysis.modules.length; i += 1) {
3523 result += "#A;" + components[0];3875 // const p = zigAnalysis.modules[i];
3524 break;3876 // if (p.name == components[0]) {
3525 }3877 // curDeclOrType = getType(p.main);
3526 }3878 // result += "#A;" + components[0];
3527 }3879 // break;
3880 // }
3881 // }
3882 // }
35283883
3529 if (!curDeclOrType) return null;3884 // if (!curDeclOrType) return null;
35303885
3531 for (let i = 1; i < components.length; i += 1) {3886 // for (let i = 1; i < components.length; i += 1) {
3532 curDeclOrType = findSubDecl(curDeclOrType, components[i]);3887 // curDeclOrType = findSubDecl(curDeclOrType, components[i]);
3533 if (!curDeclOrType) return null;3888 // if (!curDeclOrType) return null;
3534 result += separator + components[i];3889 // result += separator + components[i];
3535 separator = '.';3890 // separator = '.';
3536 }3891 // }
35373892
3538 return result;3893 // return result;
35393894
3540 }3895 // }
35413896
3542 function activateSelectedResult() {3897 function activateSelectedResult() {
3543 if (domSectSearchResults.classList.contains("hidden")) {3898 if (domSectSearchResults.classList.contains("hidden")) {
...@@ -3618,9 +3973,10 @@ Happy writing!...@@ -3618,9 +3973,10 @@ Happy writing!
3618 function onSearchInput(ev) {3973 function onSearchInput(ev) {
3619 curSearchIndex = -1;3974 curSearchIndex = -1;
3620 3975
3621 let replaced = domSearch.value.replaceAll(".", " ");3976 let replaced = domSearch.value.replaceAll(".", " ")
3977
3978 // Ping red the help text if the user typed a dot.
3622 if (replaced != domSearch.value) {3979 if (replaced != domSearch.value) {
3623 domSearch.value = replaced;
3624 domSearchHelpSummary.classList.remove("normal");3980 domSearchHelpSummary.classList.remove("normal");
3625 if (domDotsToggleTimeout != null) {3981 if (domDotsToggleTimeout != null) {
3626 clearTimeout(domDotsToggleTimeout);3982 clearTimeout(domDotsToggleTimeout);
...@@ -3629,7 +3985,13 @@ Happy writing!...@@ -3629,7 +3985,13 @@ Happy writing!
3629 domDotsToggleTimeout = setTimeout(function () { 3985 domDotsToggleTimeout = setTimeout(function () {
3630 domSearchHelpSummary.classList.add("normal"); 3986 domSearchHelpSummary.classList.add("normal");
3631 }, 1000);3987 }, 1000);
3988 }
3989
3990 replaced = replaced.replace(/ +/g, ' ');
3991 if (replaced != domSearch.value) {
3992 domSearch.value = replaced;
3632 } 3993 }
3994
3633 startAsyncSearch();3995 startAsyncSearch();
3634 }3996 }
36353997
...@@ -3832,6 +4194,9 @@ Happy writing!...@@ -3832,6 +4194,9 @@ Happy writing!
3832 }4194 }
38334195
3834 function renderSearchAPI() {4196 function renderSearchAPI() {
4197 domSectSearchResults.prepend(
4198 domSearchHelp.parentElement.removeChild(domSearchHelp)
4199 );
3835 if (canonDeclPaths == null) {4200 if (canonDeclPaths == null) {
3836 canonDeclPaths = computeCanonDeclPaths();4201 canonDeclPaths = computeCanonDeclPaths();
3837 }4202 }
...@@ -3845,7 +4210,11 @@ Happy writing!...@@ -3845,7 +4210,11 @@ Happy writing!
3845 let term = term_list[i];4210 let term = term_list[i];
3846 let result = declSearchIndex.search(term.toLowerCase());4211 let result = declSearchIndex.search(term.toLowerCase());
3847 if (result == null) {4212 if (result == null) {
4213 domSectSearchNoResults.prepend(
4214 domSearchHelp.parentElement.removeChild(domSearchHelp)
4215 );
3848 domSectSearchNoResults.classList.remove("hidden");4216 domSectSearchNoResults.classList.remove("hidden");
4217
3849 domSectSearchResults.classList.add("hidden");4218 domSectSearchResults.classList.add("hidden");
3850 return;4219 return;
3851 }4220 }
...@@ -3992,6 +4361,27 @@ Happy writing!...@@ -3992,6 +4361,27 @@ Happy writing!
3992 }4361 }
3993 }4362 }
39944363
4364 function scrollGuidesTop(ev) {
4365 document.getElementById("activeGuide").children[0].scrollIntoView({
4366 behavior: "smooth",
4367 });
4368 ev.preventDefault();
4369 ev.stopPropagation();
4370 }
4371 document.scrollGuidesTop = scrollGuidesTop;
4372
4373 function scrollToHeading(id, alreadyThere) {
4374 // Don't scroll if the current location has a scrolling history.
4375 if (scrollHistory[location.hash]) return;
4376
4377 const c = document.getElementById(id);
4378 if (c && alreadyThere) {
4379 requestAnimationFrame(() => c.scrollIntoView({behavior: "smooth"}));
4380 } else {
4381 requestAnimationFrame(() => c.scrollIntoView());
4382 }
4383 return;
4384 }
3995 // function indexNodesToCalls() {4385 // function indexNodesToCalls() {
3996 // let map = {};4386 // let map = {};
3997 // for (let i = 0; i < zigAnalysis.calls.length; i += 1) {4387 // for (let i = 0; i < zigAnalysis.calls.length; i += 1) {
...@@ -4473,3 +4863,8 @@ function RadixTree() {...@@ -4473,3 +4863,8 @@ function RadixTree() {
4473 }4863 }
4474}4864}
44754865
4866
4867function slugify(str) {
4868 return str.toLowerCase().trim().replace(/[^\w\s-]/g, '').replace(/[\s_-]+/g, '-').replace(/^-+|-+$/g, '');
4869}
4870
lib/std/std.zig+79
...@@ -51,52 +51,130 @@ pub const Tz = tz.Tz;...@@ -51,52 +51,130 @@ pub const Tz = tz.Tz;
51pub const Uri = @import("Uri.zig");51pub const Uri = @import("Uri.zig");
5252
53pub const array_hash_map = @import("array_hash_map.zig");53pub const array_hash_map = @import("array_hash_map.zig");
54
55/// Memory ordering, atomic data structures and operations.
54pub const atomic = @import("atomic.zig");56pub const atomic = @import("atomic.zig");
57
58/// Base64 encoding / decoding.
55pub const base64 = @import("base64.zig");59pub const base64 = @import("base64.zig");
60
61/// Bit-fiddling data structures.
56pub const bit_set = @import("bit_set.zig");62pub const bit_set = @import("bit_set.zig");
63
64/// Comptime-available information about the target machine and build mode.
57pub const builtin = @import("builtin.zig");65pub const builtin = @import("builtin.zig");
66
58pub const c = @import("c.zig");67pub const c = @import("c.zig");
59pub const coff = @import("coff.zig");68pub const coff = @import("coff.zig");
69
70/// Compression algorithms such as zlib, zstd, etc.
60pub const compress = @import("compress.zig");71pub const compress = @import("compress.zig");
72
73/// Cryptography.
61pub const crypto = @import("crypto.zig");74pub const crypto = @import("crypto.zig");
75
62pub const cstr = @import("cstr.zig");76pub const cstr = @import("cstr.zig");
77
78/// Debug printing, allocation and other debug helpers.
63pub const debug = @import("debug.zig");79pub const debug = @import("debug.zig");
64pub const dwarf = @import("dwarf.zig");80pub const dwarf = @import("dwarf.zig");
65pub const elf = @import("elf.zig");81pub const elf = @import("elf.zig");
82
83/// Enum-related metaprogramming helpers.
66pub const enums = @import("enums.zig");84pub const enums = @import("enums.zig");
85
86/// Evented I/O data structures.
67pub const event = @import("event.zig");87pub const event = @import("event.zig");
88
68pub const fifo = @import("fifo.zig");89pub const fifo = @import("fifo.zig");
90
91/// String formatting and parsing (eg parsing numbers out of strings).
69pub const fmt = @import("fmt.zig");92pub const fmt = @import("fmt.zig");
93
94/// File-system related types.
70pub const fs = @import("fs.zig");95pub const fs = @import("fs.zig");
96
97/// Fast hashing functions (i.e. not cryptographically secure)
71pub const hash = @import("hash.zig");98pub const hash = @import("hash.zig");
72pub const hash_map = @import("hash_map.zig");99pub const hash_map = @import("hash_map.zig");
100
101/// Allocator implementations.
73pub const heap = @import("heap.zig");102pub const heap = @import("heap.zig");
103
104/// HTTP client and server.
74pub const http = @import("http.zig");105pub const http = @import("http.zig");
106
107/// I/O Streams, Reader/Writer interfaces and common helpers.
75pub const io = @import("io.zig");108pub const io = @import("io.zig");
109
110/// JSON parsing and serialization.
76pub const json = @import("json.zig");111pub const json = @import("json.zig");
77pub const leb = @import("leb128.zig");112pub const leb = @import("leb128.zig");
113
114/// A standardized interface for logging.
78pub const log = @import("log.zig");115pub const log = @import("log.zig");
79pub const macho = @import("macho.zig");116pub const macho = @import("macho.zig");
117
118/// Mathematical constants and operations.
80pub const math = @import("math.zig");119pub const math = @import("math.zig");
120
121/// Functions for comparing, searching and manipulating memory.
81pub const mem = @import("mem.zig");122pub const mem = @import("mem.zig");
123
124/// Metaprogramming helpers.
82pub const meta = @import("meta.zig");125pub const meta = @import("meta.zig");
126
127/// Networking.
83pub const net = @import("net.zig");128pub const net = @import("net.zig");
129
130/// Wrappers around OS-specific APIs.
84pub const os = @import("os.zig");131pub const os = @import("os.zig");
132
85pub const once = @import("once.zig").once;133pub const once = @import("once.zig").once;
134
135/// A set of array and slice types that bit-pack integer elements.
86pub const packed_int_array = @import("packed_int_array.zig");136pub const packed_int_array = @import("packed_int_array.zig");
137
87pub const pdb = @import("pdb.zig");138pub const pdb = @import("pdb.zig");
139
140/// Accessors for process-related info (e.g. command line arguments)
141/// aand spawning of child processes.
88pub const process = @import("process.zig");142pub const process = @import("process.zig");
143
144/// Fast pseudo-random number generators (i.e. non-cryptographically secure).
89pub const rand = @import("rand.zig");145pub const rand = @import("rand.zig");
146
147/// Sorting.
90pub const sort = @import("sort.zig");148pub const sort = @import("sort.zig");
149
150/// Single Instruction Multiple Data (SIMD) helpers.
91pub const simd = @import("simd.zig");151pub const simd = @import("simd.zig");
152
153/// ASCII text manipulation.
92pub const ascii = @import("ascii.zig");154pub const ascii = @import("ascii.zig");
155
156/// Tar archive format compression / decompression.
93pub const tar = @import("tar.zig");157pub const tar = @import("tar.zig");
158
159/// Testing allocator, testing assertions, and other helpers for testing code.
94pub const testing = @import("testing.zig");160pub const testing = @import("testing.zig");
161
162/// Sleep, obtaining the current time and constants for conversions.
95pub const time = @import("time.zig");163pub const time = @import("time.zig");
164
165/// Timezones.
96pub const tz = @import("tz.zig");166pub const tz = @import("tz.zig");
167
168/// UTF8 and UTF16LE ecoding / decoding.
97pub const unicode = @import("unicode.zig");169pub const unicode = @import("unicode.zig");
170
171/// Helpers for integrating with Valgrind.
98pub const valgrind = @import("valgrind.zig");172pub const valgrind = @import("valgrind.zig");
173
174/// Constants and types representing the WASM binary format.
99pub const wasm = @import("wasm.zig");175pub const wasm = @import("wasm.zig");
176
177/// Tokenizing and parsing of Zig code and other Zig-specific language tooling.
100pub const zig = @import("zig.zig");178pub const zig = @import("zig.zig");
101pub const start = @import("start.zig");179pub const start = @import("start.zig");
102180
...@@ -106,6 +184,7 @@ pub const build = Build;...@@ -106,6 +184,7 @@ pub const build = Build;
106const root = @import("root");184const root = @import("root");
107const options_override = if (@hasDecl(root, "std_options")) root.std_options else struct {};185const options_override = if (@hasDecl(root, "std_options")) root.std_options else struct {};
108186
187/// Stdlib-wide options that can be overridden by the root file.
109pub const options = struct {188pub const options = struct {
110 pub const enable_segfault_handler: bool = if (@hasDecl(options_override, "enable_segfault_handler"))189 pub const enable_segfault_handler: bool = if (@hasDecl(options_override, "enable_segfault_handler"))
111 options_override.enable_segfault_handler190 options_override.enable_segfault_handler