@unana_dev/doxen 0.2.1 → 0.2.3

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.
package/client/app.js CHANGED
@@ -25,7 +25,7 @@ function highlight(root, query) {
25
25
  clearMarks(root);
26
26
  const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
27
27
  acceptNode(node) {
28
- return node.parentElement.closest(".section-tools, script, style, [hidden]")
28
+ return node.parentElement.closest(".section-tools, pre, .diagram, script, style, [hidden]")
29
29
  ? NodeFilter.FILTER_REJECT
30
30
  : NodeFilter.FILTER_ACCEPT;
31
31
  },
@@ -54,63 +54,51 @@ function highlight(root, query) {
54
54
  return hits;
55
55
  }
56
56
 
57
- let finders = [];
58
- function attachFinder(input, root, count, prev, next) {
59
- const rows = [...root.querySelectorAll("tbody tr")];
60
- let hits = [];
61
- let index = -1;
62
- const state = {
63
- input,
64
- reset() {
65
- for (const row of rows) row.hidden = false;
66
- hits = [];
67
- index = -1;
68
- count.textContent = "";
69
- prev.disabled = next.disabled = true;
70
- },
71
- };
72
- finders.push(state);
73
- const update = () => {
74
- count.textContent = input.value
75
- ? `${index < 0 ? 0 : index + 1} / ${hits.length}`
76
- : "";
77
- prev.disabled = next.disabled = !hits.length;
78
- };
79
- const move = (direction) => {
80
- if (!hits.length) return;
81
- hits[index]?.classList.remove("active-hit");
82
- index = (index + direction + hits.length) % hits.length;
83
- hits[index].classList.add("active-hit");
84
- hits[index].scrollIntoView({ block: "center", behavior: "smooth" });
85
- update();
86
- };
87
- input.oninput = () => {
88
- for (const finder of finders)
89
- if (finder !== state) {
90
- finder.input.value = "";
91
- finder.reset();
92
- }
93
- clearMarks($("#article"));
94
- for (const row of rows) {
95
- row.hidden = !matchesRow([...row.cells].map((cell) => cell.textContent).join(" "), input.value);
96
- }
97
- hits = highlight(root, input.value);
98
- index = -1;
99
- if (hits.length) move(1);
100
- else update();
101
- };
102
- input.onkeydown = (event) => {
103
- if (event.key === "Enter") {
104
- event.preventDefault();
105
- move(event.shiftKey ? -1 : 1);
57
+ function attachTableSearches() {
58
+ const article = $("#article");
59
+ const labels = new Map();
60
+ for (const section of article.querySelectorAll(".search-section")) {
61
+ labels.set(section, section.querySelector(".section-tools label")?.textContent);
62
+ section.querySelector(".section-tools")?.remove();
63
+ }
64
+ let heading = current.title;
65
+ let index = 0;
66
+ for (const node of article.querySelectorAll("h1, h2, h3, h4, h5, h6, table")) {
67
+ if (node.tagName !== "TABLE") {
68
+ heading = node.textContent;
69
+ continue;
106
70
  }
107
- };
108
- prev.onclick = () => move(-1);
109
- next.onclick = () => move(1);
110
- state.reset();
71
+ const table = node;
72
+ const tools = el("div", undefined, "section-tools");
73
+ const id = `table-search-${index++}`;
74
+ const label = el(
75
+ "label",
76
+ labels.get(table.closest(".search-section")) || `${heading} 표 검색`,
77
+ );
78
+ label.htmlFor = id;
79
+ const input = el("input");
80
+ input.id = id;
81
+ input.type = "search";
82
+ input.dataset.tableSearch = "";
83
+ input.placeholder = "표 안에서 검색";
84
+ const rows = [...table.querySelectorAll("tbody tr")];
85
+ input.oninput = () => {
86
+ clearMarks(table);
87
+ for (const row of rows)
88
+ row.hidden = !matchesRow(
89
+ [...row.cells].map((cell) => cell.textContent).join(" "),
90
+ input.value,
91
+ );
92
+ };
93
+ tools.append(label, input);
94
+ table.before(tools);
95
+ }
111
96
  }
112
97
 
113
- function renderNavigation() {
98
+ function renderNavigation(folderPath) {
99
+ $(".sidebar .eyebrow").textContent = site.tabs.find(
100
+ (tab) => tab.slug === activeTab,
101
+ ).title;
114
102
  $("#tabs").replaceChildren();
115
103
  for (const tab of site.tabs) {
116
104
  const first = site.documents.find((doc) => doc.tab === tab.slug);
@@ -128,8 +116,13 @@ function renderNavigation() {
128
116
  key += `${part}/`;
129
117
  if (!folders.has(key)) {
130
118
  const group = el("details", undefined, "folder-group");
131
- group.open = current?.path.startsWith(key) || false;
132
- group.append(el("summary", part));
119
+ group.open = (current?.path || folderPath || "").startsWith(key);
120
+ const summary = el("summary");
121
+ const link = el("a", part, key === folderPath ? "selected" : "");
122
+ link.href = route(`${activeTab}/${key}`);
123
+ if (key === folderPath) link.setAttribute("aria-current", "page");
124
+ summary.append(link);
125
+ group.append(summary);
133
126
  const children = el("div", undefined, "folder-children");
134
127
  group.append(children);
135
128
  parent.append(group);
@@ -144,6 +137,58 @@ function renderNavigation() {
144
137
  }
145
138
  }
146
139
 
140
+ function renderBreadcrumb(parts = [], currentItem) {
141
+ const tab = site.tabs.find((item) => item.slug === activeTab);
142
+ const first = site.documents.find((doc) => doc.tab === activeTab);
143
+ const items = [
144
+ { title: tab.title, id: first?.id || `${activeTab}/` },
145
+ ...parts.map((title, index) => ({
146
+ title,
147
+ id: `${activeTab}/${parts.slice(0, index + 1).join("/")}/`,
148
+ })),
149
+ ];
150
+ if (currentItem) items.push(currentItem);
151
+ const list = el("ol");
152
+ for (const item of items) {
153
+ const entry = el("li");
154
+ const link = el("a", item.title);
155
+ link.href = route(item.id);
156
+ if (item === currentItem) link.setAttribute("aria-current", "page");
157
+ entry.append(link);
158
+ list.append(entry);
159
+ }
160
+ $("#breadcrumb").replaceChildren(list);
161
+ }
162
+
163
+ function renderFolder(folderPath) {
164
+ const title = folderPath.split("/").at(-2);
165
+ document.title = `${title} · ${site.title}`;
166
+ renderBreadcrumb(folderPath.split("/").slice(0, -2), {
167
+ title,
168
+ id: `${activeTab}/${folderPath}`,
169
+ });
170
+ const cards = el("nav", undefined, "folder-cards");
171
+ cards.setAttribute("aria-label", "하위 폴더 및 문서");
172
+ const children = new Map();
173
+ for (const doc of site.documents.filter(
174
+ (item) => item.tab === activeTab && item.path.startsWith(folderPath),
175
+ )) {
176
+ const relative = doc.path.slice(folderPath.length);
177
+ const nested = relative.includes("/");
178
+ const name = relative.split("/")[0];
179
+ const id = nested ? `${activeTab}/${folderPath}${name}/` : doc.id;
180
+ if (!children.has(id)) children.set(id, nested ? name : doc.title);
181
+ }
182
+ for (const [id, name] of children) {
183
+ const link = el("a", name);
184
+ link.href = route(id);
185
+ cards.append(link);
186
+ }
187
+ $("#article").replaceChildren(el("h1", title), cards);
188
+ pendingQuery = "";
189
+ window.scrollTo(0, 0);
190
+ }
191
+
147
192
  function render() {
148
193
  let id, anchor;
149
194
  try {
@@ -158,12 +203,21 @@ function render() {
158
203
  current?.tab ||
159
204
  site.tabs.find((tab) => id?.startsWith(`${tab.slug}/`))?.slug ||
160
205
  site.tabs[0].slug;
161
- renderNavigation();
206
+ const folderPath = !current && id?.startsWith(`${activeTab}/`) && id.endsWith("/")
207
+ ? id.slice(activeTab.length + 1)
208
+ : null;
209
+ const isFolder = folderPath && site.documents.some(
210
+ (doc) => doc.tab === activeTab && doc.path.startsWith(folderPath),
211
+ );
212
+ renderNavigation(isFolder ? folderPath : null);
162
213
  $("#toc").replaceChildren();
163
214
  $("#pagination").replaceChildren();
164
- $("#page-search").value = "";
165
- finders = [];
166
- $(".document-find").open = false;
215
+ $(".toc").hidden = !current;
216
+ $("#pagination").hidden = !current;
217
+ if (isFolder) {
218
+ renderFolder(folderPath);
219
+ return;
220
+ }
167
221
  if (!current) {
168
222
  $("#article").replaceChildren(
169
223
  el(
@@ -177,18 +231,20 @@ function render() {
177
231
  "설정된 폴더에 Markdown 파일을 추가하거나 왼쪽 목록에서 문서를 선택하세요.",
178
232
  ),
179
233
  );
180
- $(".document-tools").hidden = true;
181
- $("#breadcrumb").textContent = site.tabs.find(
182
- (tab) => tab.slug === activeTab,
183
- ).title;
234
+ renderBreadcrumb();
184
235
  return;
185
236
  }
186
- $(".document-tools").hidden = false;
187
237
  document.title = `${current.title} · ${site.title}`;
188
- $("#breadcrumb").textContent =
189
- `${site.tabs.find((tab) => tab.slug === current.tab).title} / ${current.path}`;
238
+ renderBreadcrumb(current.path.split("/").slice(0, -1), {
239
+ title: current.path.split("/").at(-1).replace(/\.md$/i, ""),
240
+ id: current.id,
241
+ });
190
242
  $("#article").innerHTML = current.html;
191
243
  if (!$("#article h1")) $("#article").prepend(el("h1", current.title));
244
+ for (const heading of $("#article").querySelectorAll("h2, h3, h4, h5, h6")) {
245
+ if (/^version\s*:\s*\S+/i.test(heading.textContent.trim()))
246
+ heading.classList.add("document-version");
247
+ }
192
248
  // Existing containers with a leading heading also display the search below it.
193
249
  for (const section of document.querySelectorAll(".search-section")) {
194
250
  const heading =
@@ -216,25 +272,18 @@ function render() {
216
272
  link.append(el("small", label), el("strong", doc.title));
217
273
  $("#pagination").append(link);
218
274
  }
219
- attachFinder(
220
- $("#page-search"),
221
- $("#article"),
222
- $("#page-count"),
223
- $("#page-prev"),
224
- $("#page-next"),
275
+ attachTableSearches();
276
+ const diagrams = [...$("#article").querySelectorAll("pre > code")].filter(
277
+ (code) => code.classList.contains("language-mermaid") ||
278
+ (!code.className && /^\s*sequenceDiagram\b/.test(code.textContent)),
225
279
  );
226
- for (const section of document.querySelectorAll(".search-section"))
227
- attachFinder(
228
- section.querySelector("[data-section-search]"),
229
- section.querySelector(".section-content"),
230
- section.querySelector(".match-count"),
231
- section.querySelector("[data-find-prev]"),
232
- section.querySelector("[data-find-next]"),
233
- );
280
+ if (diagrams.length) {
281
+ import("./diagrams.js").then(({ renderDiagrams }) => renderDiagrams(diagrams)).catch(() => {
282
+ // Keep the original code readable if the renderer cannot be loaded.
283
+ });
284
+ }
234
285
  if (pendingQuery) {
235
- $(".document-find").open = true;
236
- $("#page-search").value = pendingQuery;
237
- $("#page-search").oninput();
286
+ highlight($("#article"), pendingQuery);
238
287
  pendingQuery = "";
239
288
  }
240
289
  if (anchor) {
@@ -0,0 +1,35 @@
1
+ import mermaid from "mermaid";
2
+
3
+ mermaid.initialize({
4
+ startOnLoad: false,
5
+ securityLevel: "strict",
6
+ suppressErrorRendering: true,
7
+ theme: "default",
8
+ fontFamily: '"Noto Sans KR Variable", sans-serif',
9
+ });
10
+
11
+ let diagramId = 0;
12
+
13
+ export async function renderDiagrams(blocks) {
14
+ await document.fonts.ready;
15
+ for (const code of blocks) {
16
+ if (!code.isConnected) continue;
17
+ const source = code.textContent;
18
+ const pre = code.parentElement;
19
+ const figure = document.createElement("figure");
20
+ figure.className = "diagram";
21
+ figure.setAttribute("aria-label", "문서 다이어그램");
22
+ try {
23
+ const { svg } = await mermaid.render(`diagram-${++diagramId}`, source);
24
+ if (!pre.isConnected) continue;
25
+ figure.innerHTML = svg;
26
+ pre.replaceWith(figure);
27
+ } catch {
28
+ if (!pre.isConnected) continue;
29
+ const message = document.createElement("p");
30
+ message.className = "diagram-error";
31
+ message.textContent = "다이어그램 문법을 확인해주세요. 원본 코드를 표시합니다.";
32
+ pre.before(message);
33
+ }
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ @import "@fontsource-variable/noto-sans-kr";
package/client/index.html CHANGED
@@ -6,40 +6,28 @@
6
6
  <meta name="color-scheme" content="light" />
7
7
  <title>Doxen</title>
8
8
  <link rel="icon" type="image/svg+xml" href="./favicon.svg" />
9
+ <link rel="stylesheet" href="./fonts.css" />
9
10
  <link rel="stylesheet" href="./style.css" />
10
11
  </head>
11
12
  <body>
12
13
  <a class="skip-link" href="#content">본문으로 이동</a>
13
14
  <header>
14
15
  <a class="brand" href="#/" aria-label="문서 홈"
15
- ><span class="brand-icon">S</span
16
+ ><span class="brand-icon">D</span
16
17
  ><span id="site-title">Doxen</span></a
17
18
  ><button id="open-search" class="search-trigger">
18
- <span>⌕ &nbsp; 검색...</span><kbd>⌘ / Ctrl K</kbd></button
19
+ <span class="search-label">검색...</span><kbd>⌘ / Ctrl K</kbd></button
19
20
  ><span class="header-label"></span>
20
21
  </header>
21
22
  <nav id="tabs" aria-label="문서 탭"></nav>
22
23
  <div class="layout">
23
24
  <aside class="sidebar">
24
- <div class="eyebrow">DOCUMENTATION</div>
25
+ <div class="eyebrow"></div>
25
26
  <nav id="documents" aria-label="문서 목록"></nav>
26
27
  <div class="powered">Made with <strong>Doxen</strong></div>
27
28
  </aside>
28
29
  <main id="content" tabindex="-1">
29
- <div id="breadcrumb"></div>
30
- <details class="document-find">
31
- <summary>이 문서에서 찾기</summary>
32
- <div class="document-tools">
33
- <label for="page-search">이 문서에서 찾기</label
34
- ><input
35
- id="page-search"
36
- type="search"
37
- placeholder="검색어 입력"
38
- /><span id="page-count" aria-live="polite"></span
39
- ><button id="page-prev" aria-label="이전 일치">↑</button
40
- ><button id="page-next" aria-label="다음 일치">↓</button>
41
- </div>
42
- </details>
30
+ <nav id="breadcrumb" aria-label="문서 경로"></nav>
43
31
  <article id="article"></article>
44
32
  <nav id="pagination" aria-label="이전 다음 문서"></nav>
45
33
  </main>