@unana_dev/doxen 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ <!doctype html>
2
+ <html lang="ko">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <meta name="color-scheme" content="light" />
7
+ <title>Doxen</title>
8
+ <link rel="icon" type="image/svg+xml" href="./favicon.svg" />
9
+ <link rel="stylesheet" href="./style.css" />
10
+ </head>
11
+ <body>
12
+ <a class="skip-link" href="#content">본문으로 이동</a>
13
+ <header>
14
+ <a class="brand" href="#/" aria-label="문서 홈"
15
+ ><span class="brand-icon">S</span
16
+ ><span id="site-title">Doxen</span></a
17
+ ><button id="open-search" class="search-trigger">
18
+ <span>⌕ &nbsp; 검색...</span><kbd>⌘ / Ctrl K</kbd></button
19
+ ><span class="header-label"></span>
20
+ </header>
21
+ <nav id="tabs" aria-label="문서 탭"></nav>
22
+ <div class="layout">
23
+ <aside class="sidebar">
24
+ <div class="eyebrow">DOCUMENTATION</div>
25
+ <nav id="documents" aria-label="문서 목록"></nav>
26
+ <div class="powered">Made with <strong>Doxen</strong></div>
27
+ </aside>
28
+ <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>
43
+ <article id="article"></article>
44
+ <nav id="pagination" aria-label="이전 다음 문서"></nav>
45
+ </main>
46
+ <aside class="toc">
47
+ <div class="eyebrow">이 페이지에서</div>
48
+ <nav id="toc" aria-label="목차"></nav>
49
+ </aside>
50
+ </div>
51
+ <dialog id="search-dialog" aria-labelledby="search-title">
52
+ <div class="dialog-head">
53
+ <label id="search-title" for="global-search">전체 문서 검색</label
54
+ ><button id="close-search" aria-label="검색 닫기">
55
+ 닫기 <kbd>Esc</kbd>
56
+ </button>
57
+ </div>
58
+ <input
59
+ id="global-search"
60
+ type="search"
61
+ placeholder="제목, 내용 또는 용어를 검색하세요"
62
+ autocomplete="off"
63
+ />
64
+ <p id="search-count" aria-live="polite"></p>
65
+ <div id="results"></div>
66
+ </dialog>
67
+ <script type="module" src="./app.js"></script>
68
+ </body>
69
+ </html>
@@ -0,0 +1,61 @@
1
+ export const normalize = (text) =>
2
+ text.normalize("NFKC").toLocaleLowerCase("ko");
3
+ export function matchesRow(text, query) {
4
+ return normalize(text).includes(normalize(query).trim());
5
+ }
6
+ export const terms = (query) => [
7
+ ...new Set(normalize(query).trim().split(/\s+/).filter(Boolean)),
8
+ ];
9
+
10
+ export function searchDocuments(documents, query, limit = 80) {
11
+ const words = terms(query);
12
+ if (!words.length) return [];
13
+ const results = [];
14
+ for (const doc of documents) {
15
+ for (const section of doc.sections) {
16
+ const title = normalize(`${doc.title} ${section.title}`);
17
+ const text = normalize(section.text);
18
+ if (!words.every((word) => title.includes(word) || text.includes(word)))
19
+ continue;
20
+ const score = words.reduce(
21
+ (sum, word) =>
22
+ sum + (title.includes(word) ? 10 : 0) + (text.includes(word) ? 1 : 0),
23
+ 0,
24
+ );
25
+ results.push({ doc, section, score });
26
+ }
27
+ }
28
+ return results.sort((a, b) => b.score - a.score).slice(0, limit);
29
+ }
30
+
31
+ // Map normalized characters back to UTF-16 offsets, including decomposed Hangul.
32
+ export function matchRanges(text, query) {
33
+ const words = terms(query);
34
+ if (!words.length) return [];
35
+ let normalized = "";
36
+ const positions = [];
37
+ for (const { segment, index } of new Intl.Segmenter("ko", {
38
+ granularity: "grapheme",
39
+ }).segment(text)) {
40
+ const value = normalize(segment);
41
+ normalized += value;
42
+ for (let i = 0; i < value.length; i++)
43
+ positions.push([index, index + segment.length]);
44
+ }
45
+ const ranges = [];
46
+ for (const word of words) {
47
+ let index = normalized.indexOf(word);
48
+ while (index !== -1) {
49
+ ranges.push([positions[index][0], positions[index + word.length - 1][1]]);
50
+ index = normalized.indexOf(word, index + word.length);
51
+ }
52
+ }
53
+ ranges.sort((a, b) => a[0] - b[0]);
54
+ const merged = [];
55
+ for (const range of ranges) {
56
+ if (merged.length && range[0] <= merged.at(-1)[1])
57
+ merged.at(-1)[1] = Math.max(range[1], merged.at(-1)[1]);
58
+ else merged.push([...range]);
59
+ }
60
+ return merged;
61
+ }