@clarusjs/theme-docs 0.0.1 → 0.1.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.
package/src/theme.css ADDED
@@ -0,0 +1,340 @@
1
+ /* @clarusjs/theme-docs: a quiet reading layout. Every colour, font and size is a custom property on :root (tokens). */
2
+ :root {
3
+ --header-height: 64px;
4
+ --sidebar-width: 260px;
5
+ --toc-width: 220px;
6
+ --bg: #fbfcfc;
7
+ --surface: #f1f5f5;
8
+ --fg: #1a2526;
9
+ --muted: #566768;
10
+ --rule: #dbe4e4;
11
+ --accent: #0b6e70;
12
+ --accent-soft: rgba(11, 110, 112, 0.1);
13
+ --code-bg: #f1f5f5;
14
+ /* Highlighted code: the theme's own background, and line tints light enough that every token keeps WCAG AA. */
15
+ --shiki-bg: #ffffff;
16
+ --line-highlight: rgba(11, 110, 112, 0.07);
17
+ --line-add: rgba(47, 158, 110, 0.1);
18
+ --line-remove: rgba(208, 69, 59, 0.08);
19
+ --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
20
+ --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
21
+ color-scheme: light;
22
+ }
23
+ /* Dark: when the system is dark and light wasn't chosen, or when dark was chosen (theme toggle). */
24
+ @media (prefers-color-scheme: dark) {
25
+ :root:not([data-theme='light']) {
26
+ --bg: #0c1213;
27
+ --surface: #121b1c;
28
+ --fg: #e3eded;
29
+ --muted: #93a6a7;
30
+ --rule: #223031;
31
+ --accent: #4cc9cb;
32
+ --accent-soft: rgba(76, 201, 203, 0.12);
33
+ --code-bg: #121b1c;
34
+ --shiki-bg: var(--code-bg);
35
+ --line-highlight: rgba(76, 201, 203, 0.12);
36
+ --line-add: rgba(47, 158, 110, 0.14);
37
+ --line-remove: rgba(208, 69, 59, 0.14);
38
+ color-scheme: dark;
39
+ }
40
+ }
41
+ :root[data-theme='dark'] {
42
+ --bg: #0c1213;
43
+ --surface: #121b1c;
44
+ --fg: #e3eded;
45
+ --muted: #93a6a7;
46
+ --rule: #223031;
47
+ --accent: #4cc9cb;
48
+ --accent-soft: rgba(76, 201, 203, 0.12);
49
+ --code-bg: #121b1c;
50
+ --shiki-bg: var(--code-bg);
51
+ --line-highlight: rgba(76, 201, 203, 0.12);
52
+ --line-add: rgba(47, 158, 110, 0.14);
53
+ --line-remove: rgba(208, 69, 59, 0.14);
54
+ color-scheme: dark;
55
+ }
56
+ :root[data-theme='light'] { color-scheme: light; }
57
+
58
+ * { box-sizing: border-box; }
59
+ html { -webkit-text-size-adjust: 100%; }
60
+ body {
61
+ margin: 0;
62
+ background: var(--bg);
63
+ color: var(--fg);
64
+ font: 16px/1.65 var(--sans);
65
+ }
66
+ a { color: var(--accent); text-underline-offset: 3px; }
67
+ /* Skip link: off screen until it has keyboard focus. */
68
+ .skip-link { position: absolute; left: 12px; top: -48px; z-index: 100; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: var(--bg); font-weight: 600; text-decoration: none; }
69
+ .skip-link:focus { top: 12px; }
70
+ /* Focused by the skip link and after navigation (the new page's heading or <main>), not controls: no ring after a
71
+ click; keyboard users keep it so they can see where they are. */
72
+ [tabindex="-1"]:focus:not(:focus-visible) { outline: none; } /* keyboard focus (the skip link) keeps its ring */
73
+ a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
74
+
75
+ .site-header {
76
+ position: sticky;
77
+ top: 0;
78
+ z-index: 10;
79
+ display: flex;
80
+ align-items: center;
81
+ gap: 12px 24px;
82
+ background: var(--bg);
83
+ padding: 14px max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
84
+ border-bottom: 1px solid var(--rule);
85
+ }
86
+ .brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; font-weight: 650; font-size: 18px; }
87
+ .js { color: var(--accent); font-weight: 500; }
88
+ .site-header nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
89
+ .site-header nav a { color: var(--muted); text-decoration: none; font-size: 15px; }
90
+ .site-header nav a:hover { color: var(--fg); }
91
+ .site-header nav a[aria-current] { color: var(--accent); font-weight: 600; }
92
+
93
+ .content {
94
+ max-width: 760px;
95
+ margin: 0 auto;
96
+ padding: 32px max(16px, env(safe-area-inset-right, 0px)) 56px max(16px, env(safe-area-inset-left, 0px));
97
+ }
98
+ h1, h2 { line-height: 1.2; text-wrap: balance; }
99
+ h1 { font-size: clamp(30px, 5vw, 40px); margin: 0 0 16px; letter-spacing: -0.01em; }
100
+ h2 { font-size: 22px; margin: 40px 0 12px; }
101
+ p, ul, ol { margin: 0 0 16px; }
102
+ li { margin-bottom: 6px; }
103
+
104
+ code { font: 0.9em var(--mono); background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; }
105
+ pre {
106
+ background: var(--code-bg);
107
+ border: 1px solid var(--rule);
108
+ border-radius: 8px;
109
+ padding: 14px 16px;
110
+ overflow-x: auto;
111
+ margin: 0 0 20px;
112
+ }
113
+ pre code { background: none; padding: 0; font-size: 14px; line-height: 1.55; }
114
+
115
+
116
+ .site-footer {
117
+ border-top: 1px solid var(--rule);
118
+ color: var(--muted);
119
+ font-size: 14px;
120
+ text-align: center;
121
+ padding: 20px max(16px, env(safe-area-inset-right, 0px)) 28px max(16px, env(safe-area-inset-left, 0px));
122
+ }
123
+
124
+ .sample { position: relative; }
125
+ .sample pre { padding-right: 72px; }
126
+ .copy {
127
+ position: absolute; top: 8px; right: 8px;
128
+ font: 600 12px var(--sans); padding: 4px 10px; border-radius: 6px;
129
+ border: 1px solid var(--rule); background: var(--bg); color: var(--muted); cursor: pointer;
130
+ }
131
+ .copy:hover { color: var(--accent); border-color: var(--accent); }
132
+ .theme-toggle {
133
+ font-size: 16px; line-height: 1; width: 30px; height: 30px; border-radius: 8px;
134
+ border: 1px solid var(--rule); background: transparent; color: var(--fg); cursor: pointer;
135
+ }
136
+ .theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
137
+ .site-header nav { align-items: center; }
138
+
139
+ /* Docs pages: sidebar, content and "On this page" (from 1280px a column, below that a box above the content). */
140
+ .docs { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width); max-width: 1440px; margin: 0 auto; }
141
+ .docs .content { margin: 0; max-width: 760px; min-width: 0; }
142
+ .sidebar { position: sticky; top: 0; align-self: start; max-height: 100vh; overflow-y: auto; padding: 28px 16px 40px max(16px, env(safe-area-inset-left, 0px)); border-right: 1px solid var(--rule); }
143
+ .sidebar .group { margin: 20px 0 6px; font-size: 13px; font-weight: 650; color: var(--fg); }
144
+ .sidebar .group:first-child { margin-top: 0; }
145
+ .sidebar ul { list-style: none; padding: 0; margin: 0; }
146
+ .sidebar li { margin: 0; }
147
+ .sidebar a { display: block; padding: 4px 8px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 14px; }
148
+ .sidebar a:hover { color: var(--fg); }
149
+ .sidebar a[aria-current='page'] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
150
+ .crumb { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: 0.04em; color: var(--accent); }
151
+ .lead { font-size: 18px; color: var(--muted); }
152
+ .page-footer { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--rule); }
153
+ .edit { font-size: 14px; }
154
+ .updated { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
155
+ .pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
156
+ .pager a { display: block; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 8px; text-decoration: none; font-weight: 600; }
157
+ .pager a:hover { border-color: var(--accent); }
158
+ .pager small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
159
+ .pager .next { grid-column: 2; text-align: right; }
160
+ table { width: 100%; border-collapse: collapse; margin: 0 0 16px; font-size: 15px; }
161
+ th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
162
+ .content table { display: block; overflow-x: auto; }
163
+
164
+
165
+ .persist { display: contents; }
166
+
167
+ /* Header: section links, then (pushed right) social icons, the ⋯ overflow menu and the theme toggle. */
168
+ .top-nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
169
+ .header-end { margin-left: auto; display: flex; align-items: center; gap: 6px; }
170
+ .social { display: flex; align-items: center; gap: 2px; }
171
+ .social a, .more-button, .menu-button { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; padding: 0 6px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none; }
172
+ .social a:hover, .more-button:hover, .menu-button:hover { color: var(--fg); background: var(--accent-soft); }
173
+ .npm { padding: 1px 5px; border: 1.8px solid currentColor; border-radius: 4px; font: 700 11px/1.3 var(--mono); }
174
+ .more-button, .menu-button { display: none; }
175
+ .more { inset: auto; margin: 0; padding: 6px; min-width: 200px; border: 1px solid var(--rule); border-radius: 12px; background: var(--bg); color: var(--fg); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18); position-area: bottom span-left; }
176
+ .more a { display: flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px; color: var(--fg); text-decoration: none; }
177
+ .more a:hover { background: var(--accent-soft); }
178
+
179
+ /* Search: a button in the header, a modal dialog with the results. */
180
+ .search-button { display: inline-flex; align-items: center; gap: 8px; height: 40px; min-width: 40px; padding: 0 10px; border: 1px solid var(--rule); border-radius: 10px; background: var(--bg); color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; }
181
+ .search-button:hover { color: var(--fg); border-color: var(--accent); }
182
+ .search-button kbd { padding: 1px 6px; border: 1px solid var(--rule); border-radius: 6px; font: 12px var(--mono); }
183
+ .search-dialog { width: min(640px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 96px)); margin: 72px auto auto; padding: 0; border: 1px solid var(--rule); border-radius: 14px; background: var(--bg); color: var(--fg); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3); }
184
+ .search-dialog::backdrop { background: rgba(15, 23, 25, 0.45); }
185
+ .search-box { display: flex; flex-direction: column; max-height: inherit; }
186
+ .search-box input { height: 52px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--rule); background: transparent; color: inherit; font: inherit; font-size: 17px; }
187
+ .search-box input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
188
+ .search-status { margin: 0; padding: 8px 16px 0; font-size: 13px; color: var(--muted); }
189
+ .search-status:empty { display: none; }
190
+ #search-results { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
191
+ #search-results a { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; color: var(--fg); text-decoration: none; }
192
+ #search-results [aria-selected="true"] a, #search-results a:hover { background: var(--accent-soft); }
193
+ .search-heading { font-weight: 650; }
194
+ .search-page { font-size: 13px; color: var(--accent); }
195
+ .search-text { font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
196
+
197
+ /* The sidebar is a popover (so it can be a drawer on small screens): shown in place from 1024px. */
198
+ .sidebar[popover] { display: block; position: sticky; top: var(--header-height); inset: auto; width: auto; height: auto; max-height: calc(100vh - var(--header-height)); margin: 0; border: 0; border-right: 1px solid var(--rule); background: transparent; color: inherit; overflow-y: auto; }
199
+ .sidebar-head, .sidebar-links { display: none; }
200
+
201
+ /* On this page */
202
+ .toc { position: sticky; top: var(--header-height); align-self: start; max-height: calc(100vh - var(--header-height)); overflow-y: auto; padding: 36px 16px; font-size: 14px; }
203
+ .toc p { margin: 0 0 8px; font-weight: 650; }
204
+ .toc ul, .toc-inline ul { list-style: none; margin: 0; padding: 0; }
205
+ .toc li, .toc-inline li { margin: 0 0 6px; }
206
+ .toc li.sub, .toc-inline li.sub { padding-left: 14px; }
207
+ .toc a, .toc-inline a { color: var(--muted); text-decoration: none; }
208
+ .toc a:hover, .toc-inline a:hover { color: var(--accent); }
209
+ .toc-inline { display: none; margin: 0 0 24px; border: 1px solid var(--rule); border-radius: 10px; }
210
+ .toc-inline > summary { min-height: 44px; display: flex; align-items: center; padding: 0 14px; font-size: 14px; font-weight: 650; cursor: pointer; }
211
+ .toc-inline ul { padding: 0 14px 12px; font-size: 14px; }
212
+
213
+ /* Below 1280px: no room for the column; "On this page" is a box above the content, social links fold into ⋯. */
214
+ @media (max-width: 1279px) {
215
+ .docs { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
216
+ .toc { display: none; }
217
+ .toc-inline { display: block; }
218
+ .social { display: none; }
219
+ .more-button { display: inline-flex; }
220
+ }
221
+
222
+ /* Below 1024px: the sidebar is a drawer from the ☰ button; the page takes the full width. */
223
+ @media (max-width: 1023px) {
224
+ .docs { display: block; }
225
+ .menu-button { display: inline-flex; }
226
+ .sidebar[popover] { display: none; }
227
+ .sidebar[popover]:popover-open { display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: min(340px, 86vw); height: 100%; max-height: none; padding: 0 12px 16px; border-right: 1px solid var(--rule); background: var(--bg); box-shadow: 8px 0 32px rgba(0, 0, 0, 0.25); }
228
+ .sidebar[popover]::backdrop { background: rgba(15, 23, 25, 0.45); }
229
+ .sidebar-head { display: flex; align-items: center; justify-content: space-between; min-height: 60px; font-weight: 700; border-bottom: 1px solid var(--rule); margin: 0 -12px 8px; padding: 0 8px 0 16px; }
230
+ .sidebar-head button { width: 44px; height: 44px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
231
+ .sidebar a { padding: 9px 10px; font-size: 15px; }
232
+ .sidebar-links { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--rule); }
233
+ .more-button, .social { display: none; }
234
+ .search-label, .search-button kbd { display: none; }
235
+ }
236
+
237
+ /* Phones: the section links move into the drawer. */
238
+ @media (max-width: 699px) {
239
+ .site-header .top-nav { display: none; }
240
+ }
241
+
242
+ /* ::: details blocks from Markdown: a native <details>. */
243
+ details.custom-block { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px; margin: 20px 0; }
244
+ details.custom-block > summary { cursor: pointer; font-weight: 600; }
245
+ details.custom-block[open] > summary { margin-bottom: 8px; }
246
+
247
+ /* Highlighted code from Markdown (Shiki, build time). Tokens carry both themes as variables; the page picks one. */
248
+ .code-block { position: relative; margin: 0 0 20px; }
249
+ .code-block pre { margin: 0; padding-right: 72px; }
250
+ .code-block .lang { position: absolute; top: 8px; right: 64px; font: 12px var(--mono); color: var(--muted); pointer-events: none; }
251
+ .code-block .code-title { margin: 0; padding: 6px 12px; font: 600 13px/20px var(--mono); border: 1px solid var(--rule); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--code-bg); }
252
+ .code-block .code-title + .lang + pre { border-top-left-radius: 0; border-top-right-radius: 0; }
253
+ .shiki span { color: var(--shiki-light); }
254
+ .shiki { background: var(--shiki-bg); border: 1px solid var(--rule); }
255
+ @media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .shiki span { color: var(--shiki-dark); } }
256
+ :root[data-theme='dark'] .shiki span { color: var(--shiki-dark); }
257
+ .shiki code { display: block; }
258
+ .shiki .line { display: inline-block; width: 100%; }
259
+ .shiki .line.highlighted { background: var(--line-highlight); }
260
+ .shiki .line.diff.add { background: var(--line-add); }
261
+ .shiki .line.diff.remove { background: var(--line-remove); }
262
+ .shiki .line.diff.add::before { content: '+ '; }
263
+ .shiki .line.diff.remove::before { content: '- '; }
264
+ .shiki.has-focused .line:not(.focused) { opacity: 0.45; filter: blur(0.5px); }
265
+ .shiki.has-focused:hover .line { opacity: 1; filter: none; }
266
+ .code-block.line-numbers pre { padding-left: 44px; }
267
+ .line-numbers-column { position: absolute; top: 14px; left: 0; width: 32px; display: flex; flex-direction: column; text-align: right; font: 14px/1.55 var(--mono); color: var(--muted); }
268
+ /* Below a title (6 + 20 + 6 px, and its 1px top border) the code, and so the numbers, start lower. */
269
+ .code-block .code-title ~ .line-numbers-column { top: calc(14px + 33px); }
270
+
271
+ /* ::: code-group: radio tabs, no JavaScript. The checked tab's label is followed by its block. */
272
+ .code-group { display: flex; flex-wrap: wrap; margin: 0 0 20px; }
273
+ .code-group > input { position: absolute; opacity: 0; pointer-events: none; }
274
+ .code-group > label { order: 0; font: 600 13px var(--mono); padding: 6px 12px; border: 1px solid var(--rule); border-bottom: 0; border-radius: 8px 8px 0 0; color: var(--muted); cursor: pointer; }
275
+ .code-group > input:checked + label { color: var(--accent); background: var(--code-bg); }
276
+ .code-group > input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
277
+ .code-group > .code-block { order: 1; width: 100%; display: none; margin: 0; }
278
+ .code-group > input:checked + label + .code-block { display: block; }
279
+ .code-group > .code-block pre { border-top-left-radius: 0; }
280
+
281
+ /* Visitors who ask for less motion get none: transitions and animations end at once, scrolling jumps. */
282
+ @media (prefers-reduced-motion: reduce) {
283
+ *, *::before, *::after {
284
+ animation-duration: 0.01ms !important;
285
+ animation-iteration-count: 1 !important;
286
+ transition-duration: 0.01ms !important;
287
+ scroll-behavior: auto !important;
288
+ }
289
+ }
290
+
291
+ /* Right and wrong (quizzes, the lesson bar): green and red that keep their contrast in both themes. */
292
+ :root { --ok: #17703c; --ok-soft: rgba(23, 112, 60, 0.1); --bad: #b42318; --bad-soft: rgba(180, 35, 24, 0.08); }
293
+ @media (prefers-color-scheme: dark) {
294
+ :root:not([data-theme='light']) { --ok: #4ade80; --ok-soft: rgba(74, 222, 128, 0.12); --bad: #f87171; --bad-soft: rgba(248, 113, 113, 0.12); }
295
+ }
296
+ :root[data-theme='dark'] { --ok: #4ade80; --ok-soft: rgba(74, 222, 128, 0.12); --bad: #f87171; --bad-soft: rgba(248, 113, 113, 0.12); }
297
+
298
+ /* Quizzes: big options to tap, then the right one green and a wrong pick red. */
299
+ .quiz { margin: 24px 0; padding: 18px; border: 1px solid var(--rule); border-radius: 14px; background: var(--surface); }
300
+ .quiz-question { font-weight: 650; margin: 0 0 12px; }
301
+ .quiz-options { display: grid; gap: 8px; }
302
+ .quiz-options label { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; border: 1.5px solid var(--rule); border-radius: 12px; background: var(--bg); cursor: pointer; }
303
+ .quiz-options label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
304
+ .quiz-options label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
305
+ .quiz .quiz-options label.right { border-color: var(--ok); background: var(--ok-soft); }
306
+ .quiz .quiz-options label.wrong { border-color: var(--bad); background: var(--bad-soft); }
307
+ .quiz-options .mark { margin-left: auto; font-size: 13px; font-weight: 700; }
308
+ .quiz-options .right .mark { color: var(--ok); }
309
+ .quiz-options .wrong .mark { color: var(--bad); }
310
+ .quiz-options input { accent-color: var(--accent); width: 18px; height: 18px; }
311
+ .quiz-check { margin-top: 12px; min-height: 44px; padding: 0 18px; border: 0; border-radius: 10px; background: var(--accent); color: var(--bg); font: inherit; font-weight: 700; cursor: pointer; }
312
+ .quiz-check:disabled { opacity: 0.5; cursor: default; }
313
+ .quiz-status { margin: 8px 0 0; font-size: 14px; }
314
+ .quiz-status:empty { display: none; }
315
+ .quiz-answer { margin-top: 12px; font-size: 15px; }
316
+ .quiz-answer > summary { cursor: pointer; color: var(--muted); }
317
+ .quiz-correct { font-weight: 650; margin: 8px 0; }
318
+
319
+ /* Learn: the XP chip, lesson states in the sidebar (a hint: every lesson stays open), the progress page. */
320
+ .xp-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 999px; background: var(--bg); color: var(--fg); font-size: 14px; font-weight: 700; text-decoration: none; white-space: nowrap; }
321
+ .xp-chip[hidden] { display: none; }
322
+ .xp-chip svg { color: #c99400; }
323
+ .xp-chip:hover { border-color: var(--accent); }
324
+ .sidebar a[data-status]::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; border: 2px solid var(--rule); vertical-align: -1px; }
325
+ .sidebar a[data-status="done"]::before { background: var(--ok); border-color: var(--ok); }
326
+ .sidebar a[data-status="current"]::before { border-color: var(--accent); }
327
+ .sidebar a[data-status="locked"] { color: var(--muted); }
328
+ .status-note { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
329
+ .progress-board .status-note { position: static; width: auto; height: auto; clip-path: none; color: var(--muted); font-size: 14px; }
330
+ .progress-note { padding: 12px 14px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); }
331
+ .progress-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 0 0 24px; }
332
+ .progress-stats div { padding: 14px 16px; border: 1px solid var(--rule); border-radius: 12px; background: var(--surface); }
333
+ .progress-stats dt { font-size: 13px; color: var(--muted); }
334
+ .progress-stats dd { margin: 4px 0 0; font-size: 22px; font-weight: 800; }
335
+ .badges { display: grid; gap: 8px; padding: 0; list-style: none; }
336
+ .badges li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; padding: 12px 14px; border: 1px dashed var(--rule); border-radius: 12px; color: var(--muted); }
337
+ .badges li.earned { border-style: solid; border-color: var(--ok); color: var(--fg); background: var(--ok-soft); }
338
+ .badges em { margin-left: auto; font-style: normal; font-size: 13px; font-weight: 700; }
339
+ .progress-lessons li[data-status="done"] a::after { content: ' ✓'; color: var(--ok); }
340
+ .progress-reset { margin-top: 16px; min-height: 44px; padding: 0 16px; border: 1px solid var(--bad); border-radius: 10px; background: transparent; color: var(--bad); font: inherit; font-weight: 600; cursor: pointer; }
package/src/vite.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ export type Options = {
2
+ /**
3
+ * the pages folder, from the Vite root (default src/pages)
4
+ */
5
+ pages?: string;
6
+ /**
7
+ * false: no search index (it's written to the client output's search/ after the build)
8
+ */
9
+ search?: boolean;
10
+ };
11
+ /**
12
+ * @typedef {object} Options
13
+ * @property {string} [pages] the pages folder, from the Vite root (default src/pages)
14
+ * @property {boolean} [search] false: no search index (it's written to the client output's search/ after the build)
15
+ */
16
+ /**
17
+ * Reads the pages for the sidebar (served as `virtual:theme-docs/pages`) and writes the search index after the build.
18
+ * @param {Options} [options]
19
+ * @returns {import('vite').Plugin}
20
+ */
21
+ export declare function themeDocs(options?: Options): import('vite').Plugin;
22
+ /**
23
+ * Every page under `dir` with its source `file`, its last commit time (`updated`, from one `git log`) and its sidebar
24
+ * entry: frontmatter `title` (else the first `# ` heading, or a .tscl page's `[title]="'…'"`, else the file name),
25
+ * `group` (else the subfolder inside its section), `order`. `hidden` (not in the sidebar): `sidebar: false` and
26
+ * dynamic routes (`[step]`). Files or folders starting with `_` aren't pages.
27
+ * @param {string} dir
28
+ * @returns {import('./nav.ts').PageInfo[]}
29
+ */
30
+ export declare function readPages(dir: string): import('./nav.ts').PageInfo[];
31
+ /**
32
+ * A built page's search sections: its main content (main#content, without the theme's crumb, inline contents and
33
+ * footer) split at each h1-h3 with an id. None for pages without one, noindex pages and pages with
34
+ * data-search="false" in their content.
35
+ * ponytail: regular expressions over our own prerendered HTML, not an HTML parser; enough for what the theme emits.
36
+ * @param {string} html
37
+ * @param {string} url
38
+ * @returns {import('./search.js').Section[]}
39
+ */
40
+ export declare function sectionsOf(html: string, url: string): import('./search.js').Section[];
41
+ /**
42
+ * The index files for some sections (name to JSON): words sharded by their first two letters, sections in chunks
43
+ * of CHUNK, their text cut to 240 characters (the words are indexed in full).
44
+ * @param {import('./search.js').Section[]} sections
45
+ * @returns {Map<string, string>}
46
+ */
47
+ export declare function buildIndex(sections: import('./search.js').Section[]): Map<string, string>;
package/src/vite.js ADDED
@@ -0,0 +1,203 @@
1
+ // themeDocs(): the Vite plugin that reads src/pages for the sidebar, in Node, and serves the result as
2
+ // `virtual:theme-docs/pages`, so the sidebar data (not the files) reaches pages rendered in the browser too.
3
+ // Plain JavaScript: vite.config loads it from node_modules, where Node doesn't strip types. Types are the JSDoc here;
4
+ // vite.d.ts is generated from it (pnpm types; typecheck and prepack run it).
5
+ import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
6
+ import { join, resolve } from 'node:path'
7
+ import { gitDates } from 'clarusjs/vite'
8
+ import { CHUNK, termFile, tokens } from './search.js'
9
+
10
+ const ID = 'virtual:theme-docs/pages'
11
+
12
+ /**
13
+ * @typedef {object} Options
14
+ * @property {string} [pages] the pages folder, from the Vite root (default src/pages)
15
+ * @property {boolean} [search] false: no search index (it's written to the client output's search/ after the build)
16
+ */
17
+
18
+ /**
19
+ * Reads the pages for the sidebar (served as `virtual:theme-docs/pages`) and writes the search index after the build.
20
+ * @param {Options} [options]
21
+ * @returns {import('vite').Plugin}
22
+ */
23
+ export function themeDocs(options = {}) {
24
+ let dir = resolve(options.pages ?? 'src/pages')
25
+ return {
26
+ name: 'clarusjs:theme-docs',
27
+ /** @param {{ root: string }} config */
28
+ configResolved(config) {
29
+ dir = resolve(config.root, options.pages ?? 'src/pages')
30
+ },
31
+ /** @param {string} id */
32
+ resolveId(id) {
33
+ return id === ID ? '\0' + ID : undefined
34
+ },
35
+ /** @param {string} id */
36
+ load(id) {
37
+ return id === '\0' + ID ? `export default ${JSON.stringify(readPages(dir))}\n` : undefined
38
+ },
39
+ // After clarusjs has prerendered the site: the search index, from the built pages.
40
+ buildApp: {
41
+ order: 'post',
42
+ /** @param {any} builder */
43
+ async handler(builder) {
44
+ if (options.search === false) return
45
+ const out = resolve(builder.config.root, builder.environments.client.config.build.outDir)
46
+ const base = builder.config.base.replace(/\/$/, '')
47
+ /** @type {import('./search.js').Section[]} */
48
+ const sections = []
49
+ for (const file of readdirSync(out, { recursive: true, encoding: 'utf8' }).map((f) => f.replaceAll('\\', '/')).sort()) {
50
+ if (!file.endsWith('.html') || file.endsWith('.frag.html') || /^404(\/index)?\.html$/.test(file)) continue
51
+ const url = base + ('/' + file.replace(/\.html$/, '')).replace(/\/index$/, '') || '/'
52
+ sections.push(...sectionsOf(readFileSync(join(out, file), 'utf8'), url || '/'))
53
+ }
54
+ rmSync(join(out, 'search'), { recursive: true, force: true })
55
+ mkdirSync(join(out, 'search'), { recursive: true })
56
+ for (const [name, json] of buildIndex(sections)) writeFileSync(join(out, 'search', name), json)
57
+ },
58
+ },
59
+ // A page added, removed or edited in dev: the sidebar is read again.
60
+ /** @param {any} server */
61
+ configureServer(server) {
62
+ server.watcher.on('all', (/** @type {string} */ _event, /** @type {string} */ file) => {
63
+ if (!file.startsWith(dir) || !/\.(md|tscl)$/.test(file)) return
64
+ for (const env of Object.values(server.environments)) {
65
+ const mod = env.moduleGraph.getModuleById('\0' + ID)
66
+ if (mod) env.reloadModule(mod)
67
+ }
68
+ })
69
+ },
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Every page under `dir` with its source `file`, its last commit time (`updated`, from one `git log`) and its sidebar
75
+ * entry: frontmatter `title` (else the first `# ` heading, or a .tscl page's `[title]="'…'"`, else the file name),
76
+ * `group` (else the subfolder inside its section), `order`. `hidden` (not in the sidebar): `sidebar: false` and
77
+ * dynamic routes (`[step]`). Files or folders starting with `_` aren't pages.
78
+ * @param {string} dir
79
+ * @returns {import('./nav.ts').PageInfo[]}
80
+ */
81
+ export function readPages(dir) {
82
+ /** @type {string[]} */
83
+ let files
84
+ try {
85
+ files = readdirSync(dir, { recursive: true, encoding: 'utf8' })
86
+ } catch {
87
+ return []
88
+ }
89
+ const dates = gitDates(dir, '.')
90
+ /** @type {import('./nav.ts').PageInfo[]} */
91
+ const pages = []
92
+ for (const file of files.map((f) => f.replaceAll('\\', '/')).sort()) {
93
+ const m = /^(.+)\.(md|tscl)$/.exec(file)
94
+ if (!m || m[1].split('/').some((part) => part.startsWith('_'))) continue
95
+ const text = readFileSync(join(dir, file), 'utf8')
96
+ const data = m[2] === 'md' ? frontmatter(text) : {}
97
+ const parts = m[1].split('/')
98
+ const href = ('/' + m[1]).replace(/\/index$/, '') || '/'
99
+ /** @type {import('./nav.ts').PageInfo} */
100
+ const page = { href, title: data.title ?? /^# (.+)$/m.exec(text)?.[1]?.trim() ?? /\[title\]="'([^']*)'"/.exec(text)?.[1] ?? words(parts.at(-1) ?? ''), file }
101
+ const group = data.group ?? (parts.length > 2 ? words(parts[1]) : undefined)
102
+ if (group) page.group = group
103
+ if (data.order !== undefined && Number.isFinite(Number(data.order))) page.order = Number(data.order)
104
+ const updated = dates.get(resolve(dir, file))
105
+ if (updated !== undefined) page.updated = updated
106
+ if (data.sidebar === 'false' || parts.some((part) => part.startsWith('['))) page.hidden = true
107
+ pages.push(page)
108
+ }
109
+ return pages
110
+ }
111
+
112
+ const BLOCK = /^<\/?(p|div|li|ul|ol|h\d|br|tr|td|th|table|pre|blockquote|section|aside|details|summary|dl|dt|dd|figure|figcaption|hr)\b/i
113
+ const ENTITIES = /** @type {Record<string, string>} */ ({ amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' })
114
+ /** @param {string} html */
115
+ const plain = (html) => html.replace(/<[^>]*>/g, (tag) => (BLOCK.test(tag) ? ' ' : ''))
116
+ .replace(/&(#x[0-9a-f]+|#\d+|\w+);/gi, (all, e) => e[0] !== '#' ? ENTITIES[e.toLowerCase()] ?? all : String.fromCodePoint(e[1] === 'x' || e[1] === 'X' ? parseInt(e.slice(2), 16) : Number(e.slice(1))))
117
+ .replace(/\s+/g, ' ').trim()
118
+
119
+ /**
120
+ * A built page's search sections: its main content (main#content, without the theme's crumb, inline contents and
121
+ * footer) split at each h1-h3 with an id. None for pages without one, noindex pages and pages with
122
+ * data-search="false" in their content.
123
+ * ponytail: regular expressions over our own prerendered HTML, not an HTML parser; enough for what the theme emits.
124
+ * @param {string} html
125
+ * @param {string} url
126
+ * @returns {import('./search.js').Section[]}
127
+ */
128
+ export function sectionsOf(html, url) {
129
+ if (/<meta\b(?=[^>]*\bname=["']?robots\b)(?=[^>]*noindex)[^>]*>/i.test(html)) return []
130
+ const main = /<main\b[^>]*\bid="content"[^>]*>([\s\S]*)<\/main>/i.exec(html)?.[1]
131
+ if (main === undefined || /\bdata-search="false"/.test(main)) return []
132
+ const body = main.replace(/<!--[\s\S]*?-->/g, '')
133
+ .replace(/<(script|style|template)\b[\s\S]*?<\/\1>/gi, '')
134
+ .replace(/<p class="crumb">[\s\S]*?<\/p>/, '')
135
+ .replace(/<details class="toc-inline">[\s\S]*?<\/details>/, '')
136
+ .replace(/<footer class="page-footer">[\s\S]*?<\/footer>/, '')
137
+ .replace(/<a class="header-anchor"[\s\S]*?<\/a>/g, '')
138
+ const parts = body.split(/(<h[1-3]\b[^>]*\bid="[^"]*"[^>]*>[\s\S]*?<\/h[1-3]>)/i)
139
+ const page = plain(/<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(body)?.[1] ?? /<title>([\s\S]*?)<\/title>/i.exec(html)?.[1] ?? '')
140
+ /** @type {import('./search.js').Section[]} */
141
+ const sections = []
142
+ if (plain(parts[0])) sections.push({ u: url, p: page, h: page, t: plain(parts[0]) })
143
+ for (let i = 1; i < parts.length; i += 2) {
144
+ const [, level, id] = /** @type {RegExpExecArray} */ (/<h([1-3])\b[^>]*\bid="([^"]*)"/i.exec(parts[i]))
145
+ sections.push({ u: level === '1' ? url : `${url}#${id}`, p: page, h: plain(parts[i]), t: plain(parts[i + 1] ?? '') })
146
+ }
147
+ return sections
148
+ }
149
+
150
+ /**
151
+ * The index files for some sections (name to JSON): words sharded by their first two letters, sections in chunks
152
+ * of CHUNK, their text cut to 240 characters (the words are indexed in full).
153
+ * @param {import('./search.js').Section[]} sections
154
+ * @returns {Map<string, string>}
155
+ */
156
+ export function buildIndex(sections) {
157
+ /** @type {Map<string, Record<string, number[]>>} */
158
+ const shards = new Map()
159
+ for (const [id, section] of sections.entries()) {
160
+ /** @type {Map<string, number>} */
161
+ const weights = new Map()
162
+ /** @type {Map<string, number>} */
163
+ const uses = new Map()
164
+ for (const word of tokens(section.t)) uses.set(word, (uses.get(word) ?? 0) + 1)
165
+ // In the text a word counts at most 3 times: a long page repeating it doesn't outrank a heading.
166
+ for (const [word, n] of uses) weights.set(word, Math.min(n, 3))
167
+ for (const word of tokens(section.h)) weights.set(word, (weights.get(word) ?? 0) + 10)
168
+ for (const [word, weight] of weights) {
169
+ const shard = shards.get(termFile(word)) ?? shards.set(termFile(word), {}).get(termFile(word))
170
+ ;(/** @type {Record<string, number[]>} */ (shard)[word] ??= []).push(id, weight)
171
+ }
172
+ }
173
+ /** @type {Map<string, string>} */
174
+ const files = new Map([...shards].map(([name, terms]) => [name, JSON.stringify(terms)]))
175
+ for (let n = 0; n * CHUNK < sections.length; n++) {
176
+ const chunk = sections.slice(n * CHUNK, (n + 1) * CHUNK).map((s) => ({ ...s, t: s.t.length > 240 ? s.t.slice(0, 239) + '…' : s.t }))
177
+ files.set(`s-${n}.json`, JSON.stringify(chunk))
178
+ }
179
+ return files
180
+ }
181
+
182
+ // ponytail: flat `key: value` lines only (all the sidebar needs); the page itself is compiled with a real YAML parser.
183
+ /** @param {string} text @returns {Record<string, string>} */
184
+ function frontmatter(text) {
185
+ const block = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1] ?? ''
186
+ /** @type {Record<string, string>} */
187
+ const data = {}
188
+ for (const line of block.split(/\r?\n/)) {
189
+ const m = /^(\w+):\s*(.*?)\s*$/.exec(line)
190
+ if (!m) continue
191
+ // A quoted value ends at its closing quote; otherwise a ` #` starts a comment.
192
+ const double = /^"((?:[^"\\]|\\.)*)"/.exec(m[2])
193
+ const single = /^'((?:[^']|'')*)'/.exec(m[2])
194
+ if (double) {
195
+ try { data[m[1]] = JSON.parse(double[0]) } catch { data[m[1]] = double[1] }
196
+ } else if (single) data[m[1]] = single[1].replaceAll("''", "'")
197
+ else data[m[1]] = m[2].replace(/\s+#.*$/, '')
198
+ }
199
+ return data
200
+ }
201
+
202
+ /** @param {string} name */
203
+ const words = (name) => name.replace(/[-_]+/g, ' ').replace(/^\w/, (c) => c.toUpperCase())