-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-tech.js
209 lines (193 loc) · 6.16 KB
/
load-tech.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
function ArrowClicked(arrow) {
let curr = arrow.parentNode;
if (Array.from(curr.children).find(e => e.classList.contains('expand-region')) === undefined
&& Array.from(curr.children).find(e => e.classList.contains('expand-region-visible')) === undefined) {
curr = curr.parentNode;
}
let expand = Array.from(curr.children).find(e => e.classList.contains('expand-region'));
if (expand === undefined) {
expand = Array.from(curr.children).find(e => e.classList.contains('expand-region-visible'));
expand.classList.remove("expand-region-visible");
expand.classList.add("expand-region");
arrow.innerHTML = "→"
}
else {
expand.classList.remove("expand-region");
expand.classList.add("expand-region-visible");
arrow.innerHTML = "↓"
}
}
function GetExpandButton(className) {
return `
<span class="${className}" onclick="ArrowClicked(this)">→</span>
`;
}
function GetCommentElement(comment, defaultElement) {
let commentRegion = "";
if (comment.summary !== ""
|| comment.returns !== ""
|| comment.remarks !== ""
|| Object.keys(comment.params).length > 0
|| Object.keys(comment.typeParams).length > 0) {
let returnComment = "";
if (comment.returns !== "") {
returnComment = `
<div class="comment-region special-comment">
<div class="main-line-subinfo special-comment-start">Returns:</div>
<div>${comment.returns}</div>
</div>
`;
}
let remarkComment = "";
if (comment.remarks !== "") {
remarkComment = `
<div class="comment-region special-comment">
<div class="main-line-subinfo special-comment-start">Remarks:</div>
<div>${comment.remarks}</div>
</div>
`;
}
let paramsList = [];
for (const [paramId, paramComment] of Object.entries(comment.typeParams)) {
paramsList.push(`
<div class="comment-region special-comment">
<div class="main-line-subinfo special-comment-start">
<span class="declaration-kind">type-param</span> ${paramId}:
</div>
<div>${paramComment}</div>
</div>
`);
}
for (const [paramId, paramComment] of Object.entries(comment.params)) {
paramsList.push(`
<div class="comment-region special-comment">
<div class="main-line-subinfo special-comment-start">
<span class="declaration-kind">param</span> ${paramId}:
</div>
<div>${paramComment}</div>
</div>
`);
}
let examplesList = [];
for (const example of comment.examples) {
examplesList.push(`
<div class="comment-region special-comment">
<div class="main-line-subinfo special-comment-start">Example:</div>
<div>${example}</div>
</div>
`);
}
commentRegion = `
<div class="comment-region">
${comment.summary}
${paramsList.join("")}
${returnComment}
${examplesList.join("")}
${remarkComment}
</div>
`;
}
return commentRegion;
}
function GetClassElement(classId, classData) {
let commentRegion = GetCommentElement(classData.comment, "<br /><br />");
let baseList = "";
if (classData.bases.length > 0) {
baseList = `<span class="main-line-subinfo">: ${classData.bases.join(", ")}</span>`;
}
let declarationList = [];
for (const dec of classData.declarations) {
let commentRegion = GetCommentElement(dec.comment, "");
let kindString = `${dec.kind}`;
if (dec.mainType !== "") {
kindString = `${dec.kind} • ${dec.mainType}`
}
if (dec["static"] === true && dec.kind !== "const") {
kindString = "static " + kindString;
}
let subInfo = "";
if (dec.defaultValue !== "") {
if (dec.defaultValue.length >= 200) {
subInfo = `<span class="main-line-subinfo">= (very long default value not shown.)</span>`;
}
else {
subInfo = `<span class="main-line-subinfo">= ${dec.defaultValue}</span>`;
}
}
let methodInfo = "";
if (dec.kind === "method") {
let mparamList = [];
for (const [mpname, mparam] of Object.entries(dec.methodParams)) {
let subInfo = "";
if (mparam.defaultValue !== "") {
subInfo = ` <span class="main-line-subinfo">= ${mparam.defaultValue}</span>`;
}
let refInfo = "";
if (mparam.modifierString !== "") {
refInfo = `${mparam.modifierString} `;
}
mparamList.push(`<span class="declaration-kind">${refInfo}${mparam.paramType}</span> ${mpname}${subInfo}`);
}
methodInfo = `(${mparamList.join(", ")})`;
}
declarationList.push(`
<div class="yellow-container declaration-element">
<span class="declaration-kind">${kindString}</span> <span>${dec.id}${methodInfo}</span> ${subInfo}
${commentRegion}
</div>
`);
}
let innerList = [];
for (const [innerId, innerData] of Object.entries(classData.inners).sort((a, b) => a[0].localeCompare(b[0]))) {
innerList.push(GetClassElement(innerId, innerData));
}
let kindStr = classData.kind;
if (classData["abstract"] === true) {
kindStr = "abstract " + kindStr;
}
return `
<div class="red-container class-element">
${GetExpandButton("yellow-expand-button")}
<span class="declaration-kind">${kindStr}</span>
<span class="class-title">${classId}</span>
${baseList}
<div class="expand-region">
${commentRegion}
${innerList.join("")}
${declarationList.join("")}
</div>
</div>
`;
}
function HandleData(data) {
console.log(data);
window.document.getElementById("updated-time").innerHTML = data.date;
for (const [namespaceId, namespaceData] of Object.entries(data.namespaces).sort((a, b) => a[0].localeCompare(b[0]))) {
let techElement = window.document.getElementById("tech");
let classElementList = [];
for (const [classId, classData] of Object.entries(namespaceData.classes).sort((a, b) => a[0].localeCompare(b[0]))) {
classElementList.push(GetClassElement(classId, classData));
}
techElement.insertAdjacentHTML("beforeend",
`
<div class="primary-container">
<div class="namespace-block">
${GetExpandButton("red-expand-button")}
<span class="declaration-kind">namespace</span> <span class="namespace-title">${namespaceId}</span>
</div>
<div class="expand-region">
${classElementList.join("")}
</div>
</div>
`);
}
}
let load = false;
function LoadData() {
if (load) { return; }
load = true;
fetch('./docgen.json')
.then((response) => response.json())
.then(HandleData);
}
document.addEventListener("DOMContentLoaded", LoadData);