for-humanity 0.4.4 → 0.5.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +5 -5
  3. package/dist/browser.js +39 -0
  4. package/dist/cli.css +350 -262
  5. package/dist/cli.js +1123 -363
  6. package/package.json +8 -11
  7. package/src/component/widget/{shell → cursor-face}/_constant/cursor-face.ts +5 -0
  8. package/src/component/widget/cursor-face/wg-cursor-face.css +15 -0
  9. package/src/component/widget/cursor-face/wg-cursor-face.tsx +153 -0
  10. package/src/component/widget/navigation/_constant/navigation-data-schema.ts +35 -0
  11. package/src/component/widget/navigation/_constant/navigation.ts +9 -0
  12. package/src/component/widget/navigation/_function/restore-navigation-scroll.ts +59 -0
  13. package/src/{content → component/widget/navigation/_function}/to-doc-groups/_to-doc-branches.ts +2 -2
  14. package/src/{content → component/widget/navigation/_function}/to-doc-groups/_to-doc-group-branches.ts +3 -3
  15. package/src/{content → component/widget/navigation/_function}/to-doc-groups/to-doc-groups.ts +1 -1
  16. package/src/component/widget/navigation/_function/to-navigation-branch-id.ts +6 -0
  17. package/src/component/widget/navigation/_function/to-navigation-data/_to-navigation-document.ts +14 -0
  18. package/src/component/widget/navigation/_function/to-navigation-data/_to-navigation-group.ts +14 -0
  19. package/src/component/widget/navigation/_function/to-navigation-data/to-navigation-data.ts +25 -0
  20. package/src/component/widget/navigation/_function/to-navigation-json.ts +8 -0
  21. package/src/component/widget/{shell → navigation}/_function/to-toc-groups.ts +2 -2
  22. package/src/{type → component/widget/navigation/_type}/doc-group.ts +1 -1
  23. package/src/component/widget/navigation/_type/navigation-data.ts +83 -0
  24. package/src/component/widget/navigation/_type/navigation-focus-snapshot.ts +21 -0
  25. package/src/component/widget/navigation/_wg-navigation-branch-toggle.css +28 -0
  26. package/src/component/widget/navigation/_wg-navigation-branch-toggle.tsx +48 -0
  27. package/src/component/widget/{shell/_wg-shell-nav-list.css → navigation/_wg-navigation-nav-list.css} +24 -16
  28. package/src/component/widget/navigation/_wg-navigation-nav-list.tsx +106 -0
  29. package/src/component/widget/{shell/_wg-shell-nav.css → navigation/_wg-navigation-nav.css} +9 -3
  30. package/src/component/widget/navigation/_wg-navigation-nav.tsx +43 -0
  31. package/src/component/widget/navigation/_wg-navigation-scroll.tsx +117 -0
  32. package/src/component/widget/{shell/_wg-shell-toc.css → navigation/_wg-navigation-toc.css} +39 -24
  33. package/src/component/widget/navigation/_wg-navigation-toc.tsx +155 -0
  34. package/src/component/widget/navigation/wg-navigation.css +282 -0
  35. package/src/component/widget/navigation/wg-navigation.tsx +479 -0
  36. package/src/component/widget/prose/_function/rehype-sections/rehype-sections.ts +1 -1
  37. package/src/component/widget/shell/wg-shell.css +13 -269
  38. package/src/component/widget/shell/wg-shell.tsx +16 -97
  39. package/src/component/widget/shell-controls/wg-shell-controls.css +4 -0
  40. package/src/component/widget/shell-controls/wg-shell-controls.tsx +170 -0
  41. package/src/constant/asset.ts +0 -5
  42. package/src/entry/browser/browser.tsx +22 -0
  43. package/src/{app.tsx → entry/cli/_function/create-app.tsx} +6 -6
  44. package/src/{content → entry/cli/_function/create-processor}/create-processor.ts +3 -3
  45. package/src/{content → entry/cli/_function}/read-docs.ts +1 -1
  46. package/src/{content → entry/cli/_function}/read-home.ts +1 -1
  47. package/src/{content/read-docs.test.ts → entry/cli/cli.test.ts} +105 -30
  48. package/src/{cli.ts → entry/cli/cli.ts} +10 -11
  49. package/src/store/navigation/_constant/tree.ts +6 -0
  50. package/src/store/navigation/create-navigation-stores.test.ts +92 -0
  51. package/src/store/navigation/create-navigation-stores.ts +73 -0
  52. package/src/store/navigation/navigation-state.ts +46 -0
  53. package/src/store/navigation/navigation-storage.ts +14 -0
  54. package/src/store/navigation/to-navigation-scroll-state.ts +42 -0
  55. package/src/store/navigation/to-navigation-tree-state.ts +19 -0
  56. package/src/store/navigation/use-navigation-tree-store.ts +12 -0
  57. package/src/style/token.css +3 -2
  58. package/src/type/doc-content.ts +1 -1
  59. package/src/type/doc-file-data.ts +1 -1
  60. package/src/{component/widget/shell/_type → type}/doc-outline.ts +1 -1
  61. package/src/type/site-assets.ts +2 -2
  62. package/dist/client.js +0 -7
  63. package/src/client.ts +0 -335
  64. package/src/component/widget/shell/_constant/navigation.ts +0 -9
  65. package/src/component/widget/shell/_function/bind-mobile-navigation.ts +0 -147
  66. package/src/component/widget/shell/_function/bind-navigation-overflow.ts +0 -47
  67. package/src/component/widget/shell/_function/bind-navigation-scroll.ts +0 -84
  68. package/src/component/widget/shell/_function/restore-navigation-scroll.ts +0 -47
  69. package/src/component/widget/shell/_wg-shell-nav-list.tsx +0 -87
  70. package/src/component/widget/shell/_wg-shell-nav.tsx +0 -49
  71. package/src/component/widget/shell/_wg-shell-toc.tsx +0 -57
  72. /package/src/{constant → component/widget/navigation/_constant}/locale.ts +0 -0
  73. /package/src/component/widget/{shell → navigation}/_constant/reading-line.ts +0 -0
  74. /package/src/{type → component/widget/navigation/_type}/doc-branch.ts +0 -0
  75. /package/src/component/widget/{shell → navigation}/_type/toc-group.ts +0 -0
  76. /package/src/{constant → entry/cli/_constant}/cli.ts +0 -0
  77. /package/src/{dev.ts → entry/cli/_function/create-dev-app.ts} +0 -0
  78. /package/src/{content/rehype-assets.ts → entry/cli/_function/create-processor/_rehype-assets.ts} +0 -0
  79. /package/src/{content/rehype-heading-ids.ts → entry/cli/_function/create-processor/_rehype-heading-ids.ts} +0 -0
  80. /package/src/{content/remark-report.ts → entry/cli/_function/create-processor/_remark-report.ts} +0 -0
  81. /package/src/{component/widget/prose/_type → type}/doc-section.ts +0 -0
@@ -0,0 +1,155 @@
1
+ import clsx from "clsx";
2
+ import {useLayoutEffect, useState} from "hono/jsx";
3
+ import {reading_line_slack_px} from "@/component/widget/navigation/_constant/reading-line";
4
+ import {toNavigationBranchId} from "@/component/widget/navigation/_function/to-navigation-branch-id";
5
+ import type {TocGroup} from "@/component/widget/navigation/_type/toc-group";
6
+ import {WgNavigationBranchToggle} from "@/component/widget/navigation/_wg-navigation-branch-toggle";
7
+ import {copy_nav_toc_label} from "@/constant/copy";
8
+ import {findHashTarget} from "@/util/dom/find-hash-target";
9
+ import "./_wg-navigation-toc.css";
10
+
11
+ /**
12
+ * 현재 문서의 목차 · 읽는 제목 한 항목과 조상 트리선 구분
13
+ */
14
+ export interface WgNavigationTocProps {
15
+ /**
16
+ * 본문 순서의 가름·절·소제목
17
+ */
18
+ groups: TocGroup[];
19
+ /**
20
+ * 문서별 접힘 상태의 키
21
+ */
22
+ pageId: string;
23
+ /**
24
+ * 사용자가 접은 가지
25
+ */
26
+ collapsed: Record<string, boolean>;
27
+ /**
28
+ * 브라우저에서만 제공하는 가지 변경 동작
29
+ */
30
+ onToggle?: (key: string) => void;
31
+ }
32
+
33
+ export const WgNavigationToc = (props: WgNavigationTocProps) => {
34
+ const [currentSlug, setCurrentSlug] = useState<string>();
35
+
36
+ /**
37
+ * 구독은 연결마다 한 번 설치 · 초기 갱신은 본문 파싱 이후로 미룸
38
+ */
39
+ useLayoutEffect(() => {
40
+ const sections = props.groups.flatMap((group) => group.sections);
41
+ const headings = sections.flatMap((section) => [section.heading, ...section.subs.map((sub) => sub.heading)]);
42
+ const frame = {id: 0};
43
+
44
+ /**
45
+ * 접힌 본문 제목은 제외하고 읽는 선을 통과한 마지막 제목 선택
46
+ */
47
+ const updateCurrentHeading = () => {
48
+ frame.id = 0;
49
+ const visible = headings.flatMap((heading) => {
50
+ const target = findHashTarget(`#${heading.slug}`);
51
+ return target?.checkVisibility()
52
+ ? [{slug: heading.slug, top: target.getBoundingClientRect().top - Number.parseFloat(getComputedStyle(target).scrollMarginTop)}]
53
+ : [];
54
+ });
55
+ setCurrentSlug(visible.findLast((heading) => heading.top <= reading_line_slack_px)?.slug ?? visible[0]?.slug);
56
+ };
57
+
58
+ /**
59
+ * 연속 스크롤은 프레임당 한 번만 읽음
60
+ */
61
+ const handleReadingPositionChange = () => {
62
+ if (frame.id === 0) frame.id = requestAnimationFrame(updateCurrentHeading);
63
+ };
64
+
65
+ addEventListener("scroll", handleReadingPositionChange, {passive: true});
66
+ addEventListener("resize", handleReadingPositionChange);
67
+ addEventListener("toggle", handleReadingPositionChange, true);
68
+ addEventListener("pageshow", handleReadingPositionChange);
69
+ document.addEventListener("DOMContentLoaded", handleReadingPositionChange);
70
+ if (document.readyState !== "loading") updateCurrentHeading();
71
+
72
+ return () => {
73
+ cancelAnimationFrame(frame.id);
74
+ removeEventListener("scroll", handleReadingPositionChange);
75
+ removeEventListener("resize", handleReadingPositionChange);
76
+ removeEventListener("toggle", handleReadingPositionChange, true);
77
+ removeEventListener("pageshow", handleReadingPositionChange);
78
+ document.removeEventListener("DOMContentLoaded", handleReadingPositionChange);
79
+ };
80
+ }, [props.groups]);
81
+
82
+ return (
83
+ <nav className={clsx("wg_navigationToc__root")} aria-label={copy_nav_toc_label}>
84
+ <div className={clsx("wg_navigationToc__label")}>{copy_nav_toc_label}</div>
85
+ {/**
86
+ * 가름별 제목 이동 · 하위 제목이 현재 위치여도 부모 글씨는 강조하지 않음
87
+ */}
88
+ {props.groups.map((group) => {
89
+ const currentIndex = group.sections.findIndex((section) => section.heading.slug === currentSlug || section.subs.some((sub) => sub.heading.slug === currentSlug));
90
+ const partKey = `outline:${props.pageId}:part:${group.sections[0].heading.slug}`;
91
+ return (
92
+ <div
93
+ className={clsx("wg_navigationToc__groupSection", {"wg_navigationToc__groupSection--named": group.part !== undefined})}
94
+ key={group.sections[0].heading.slug}
95
+ >
96
+ {group.part !== undefined && <div className={clsx("wg_navigationToc__group")}>{group.part}</div>}
97
+ {group.part !== undefined && <WgNavigationBranchToggle branchKey={partKey} label={group.part} collapsed={props.collapsed} onToggle={props.onToggle} />}
98
+ <ul className={clsx("wg_navigationToc__list")} id={toNavigationBranchId(partKey)} hidden={props.collapsed[partKey] === true}>
99
+ {group.sections.map((section, index) => {
100
+ const currentSubIndex = section.subs.findIndex((sub) => sub.heading.slug === currentSlug);
101
+ const sectionKey = `outline:${props.pageId}:heading:${section.heading.slug}`;
102
+ return (
103
+ <li
104
+ className={clsx("wg_navigationToc__item", {
105
+ "wg_navigationToc__item--trail": index < currentIndex,
106
+ "wg_navigationToc__item--current": index === currentIndex,
107
+ })}
108
+ key={section.heading.slug}
109
+ >
110
+ <a
111
+ className={clsx("wg_navigationToc__link", {"wg_navigationToc__link--active": section.heading.slug === currentSlug})}
112
+ href={`#${section.heading.slug}`}
113
+ data-toc-link=""
114
+ aria-current={section.heading.slug === currentSlug ? "location" : undefined}
115
+ >
116
+ {section.heading.text}
117
+ </a>
118
+ {section.subs.length > 0 && (
119
+ <WgNavigationBranchToggle branchKey={sectionKey} label={section.heading.text} collapsed={props.collapsed} onToggle={props.onToggle} />
120
+ )}
121
+ {/**
122
+ * 조상과 이전 형제의 트리선은 연결 · 활성 링크는 한 제목만
123
+ */}
124
+ {section.subs.length > 0 && (
125
+ <ul className={clsx("wg_navigationToc__sub")} id={toNavigationBranchId(sectionKey)} hidden={props.collapsed[sectionKey] === true}>
126
+ {section.subs.map((sub, subIndex) => (
127
+ <li
128
+ className={clsx("wg_navigationToc__subItem", {
129
+ "wg_navigationToc__subItem--trail": subIndex < currentSubIndex,
130
+ "wg_navigationToc__subItem--current": subIndex === currentSubIndex,
131
+ })}
132
+ key={sub.heading.slug}
133
+ >
134
+ <a
135
+ className={clsx("wg_navigationToc__subLink", {"wg_navigationToc__subLink--active": sub.heading.slug === currentSlug})}
136
+ href={`#${sub.heading.slug}`}
137
+ data-toc-sub-link=""
138
+ aria-current={sub.heading.slug === currentSlug ? "location" : undefined}
139
+ >
140
+ {sub.heading.text}
141
+ </a>
142
+ </li>
143
+ ))}
144
+ </ul>
145
+ )}
146
+ </li>
147
+ );
148
+ })}
149
+ </ul>
150
+ </div>
151
+ );
152
+ })}
153
+ </nav>
154
+ );
155
+ };
@@ -0,0 +1,282 @@
1
+ .wg_navigation__brandRow {
2
+ display: flex;
3
+
4
+ /* 두 스크롤 영역 바깥 · 목록과 목차 위에서 이름 고정 */
5
+ position: sticky;
6
+ top: 0;
7
+ z-index: var(--app-z-index-sticky);
8
+ align-self: start;
9
+ min-width: 0;
10
+ height: var(--app-size-brand);
11
+ padding-block: var(--app-space-page-top) var(--app-space-group);
12
+ background: var(--app-color-ground);
13
+ gap: var(--app-space-inline);
14
+ align-items: start;
15
+ }
16
+
17
+ .wg_navigation__brand {
18
+ display: block;
19
+ flex: 1;
20
+ min-width: 0;
21
+ overflow: hidden;
22
+ color: var(--app-color-text-strong);
23
+ font-family: var(--app-font-brand);
24
+ font-size: var(--app-font-size-title);
25
+ font-weight: var(--app-font-weight-mark);
26
+ line-height: var(--app-line-height-title);
27
+ letter-spacing: var(--app-letter-spacing-brand);
28
+ text-decoration: none;
29
+ text-overflow: ellipsis;
30
+ white-space: nowrap;
31
+
32
+ &:hover {
33
+ text-decoration: underline;
34
+ }
35
+
36
+ &:focus-visible {
37
+ /* 브랜드도 hover와 같은 밑줄로 키보드 위치 표시 */
38
+ outline: none;
39
+ text-decoration: underline;
40
+ }
41
+ }
42
+
43
+ .wg_navigation__menuIcon {
44
+ width: 20px;
45
+ height: 20px;
46
+ fill: none;
47
+ stroke: currentcolor;
48
+ stroke-linecap: round;
49
+ stroke-width: 1.5;
50
+ }
51
+
52
+ .wg_navigation__menuToggle {
53
+ display: none;
54
+ align-items: center;
55
+ justify-content: center;
56
+ flex: none;
57
+ width: var(--app-size-menu-button);
58
+ height: var(--app-size-menu-button);
59
+ padding: 0;
60
+ border: 0;
61
+ border-radius: var(--app-radius-box);
62
+ background: transparent;
63
+ color: var(--app-color-text-strong);
64
+ cursor: pointer;
65
+
66
+ &:hover {
67
+ background: var(--app-color-accent-soft);
68
+ }
69
+
70
+ &:focus-visible {
71
+ outline: var(--app-outline-focus);
72
+ outline-offset: var(--app-outline-focus-offset);
73
+ }
74
+ }
75
+
76
+ .wg_navigation__menuToggle--visible {
77
+ display: flex;
78
+ }
79
+
80
+ /* sticky 틀 안에서 문서 목록과 목차의 스크롤 높이를 독립 유지 */
81
+ .wg_navigation__sidebar {
82
+ grid-area: nav;
83
+ position: sticky;
84
+ top: 0;
85
+ align-self: start;
86
+ min-width: 0;
87
+ height: 100dvh;
88
+ margin-inline-end: var(--app-space-sidebar-gap);
89
+ }
90
+
91
+ .wg_navigation__documents {
92
+ /* 모든 배치에서 남은 탐색 높이를 문서 목록 전체에 사용 */
93
+ flex: 1;
94
+ min-height: 0;
95
+ }
96
+
97
+ .wg_navigation__outline {
98
+ display: flex;
99
+ flex-direction: column;
100
+ flex: 1;
101
+ min-height: 0;
102
+
103
+ &:where(:has(.wg_navigation__headings:empty)) {
104
+ display: none;
105
+ }
106
+ }
107
+
108
+ .wg_navigation__headings {
109
+ flex: 1;
110
+ min-height: 0;
111
+ }
112
+
113
+ .wg_navigation__navigation {
114
+ display: flex;
115
+ flex-direction: column;
116
+ height: calc(100dvh - var(--app-size-brand));
117
+ min-width: 0;
118
+ min-height: 0;
119
+ }
120
+
121
+ .wg_navigation__tocRail {
122
+ /* body의 오른쪽 grid 열 · 문서 스크롤과 독립된 뷰포트 기준 sticky */
123
+ grid-area: outline;
124
+ position: sticky;
125
+ top: 0;
126
+ align-self: start;
127
+ min-width: 0;
128
+ height: 100dvh;
129
+ margin-inline-start: var(--app-space-sidebar-gap);
130
+ padding-top: var(--app-size-brand);
131
+
132
+ & > .wg_navigation__outline {
133
+ height: 100%;
134
+ }
135
+
136
+ &:where(:has(.wg_navigation__headings:empty)) {
137
+ display: none;
138
+ }
139
+ }
140
+
141
+ .wg_navigation__scroll {
142
+ overflow-y: auto;
143
+ overscroll-behavior-y: contain;
144
+ scroll-padding-block: var(--app-size-navigation-fade);
145
+ }
146
+
147
+ .wg_navigation__scroll--ready {
148
+ /* 흐림으로 넘침을 알릴 때만 손잡이 숨김 · JS 없으면 네이티브 손잡이 유지 */
149
+ scrollbar-width: none;
150
+ }
151
+
152
+ .wg_navigation__scroll--above {
153
+ mask-image: linear-gradient(to bottom, transparent, #000 var(--app-size-navigation-fade));
154
+ }
155
+
156
+ .wg_navigation__scroll--below {
157
+ mask-image: linear-gradient(to bottom, #000 calc(100% - var(--app-size-navigation-fade)), transparent);
158
+ }
159
+
160
+ .wg_navigation__scroll--above.wg_navigation__scroll--below {
161
+ mask-image: linear-gradient(to bottom, transparent, #000 var(--app-size-navigation-fade), #000 calc(100% - var(--app-size-navigation-fade)), transparent);
162
+ }
163
+
164
+ .wg_navigation__drawer {
165
+ /* 네이티브 모달의 top layer · 뷰포트 왼쪽에 고정 */
166
+ position: fixed;
167
+ inset: 0 auto 0 0;
168
+ width: min(var(--app-size-drawer), calc(100% - var(--app-space-gutter) * 2));
169
+ max-width: none;
170
+ height: 100dvh;
171
+ max-height: 100dvh;
172
+ margin: 0;
173
+ padding: 0 var(--app-space-gutter) var(--app-space-group);
174
+ border: 0;
175
+ border-right: 1px solid var(--app-color-border-layout);
176
+ background: var(--app-color-ground);
177
+ color: var(--app-color-text);
178
+ overflow: hidden;
179
+
180
+ &::backdrop {
181
+ background: var(--app-color-backdrop);
182
+ }
183
+ }
184
+
185
+ .wg_navigation__drawerHeader {
186
+ /* 두 스크롤 영역 바깥에서 닫기 버튼 유지 */
187
+ display: flex;
188
+ align-items: center;
189
+ justify-content: space-between;
190
+ gap: var(--app-space-inline);
191
+ min-height: var(--app-size-mobile-header);
192
+ margin-bottom: var(--app-space-block);
193
+ background: var(--app-color-ground);
194
+ }
195
+
196
+ .wg_navigation__drawerTitle {
197
+ margin: 0;
198
+ font-size: var(--app-font-size-part);
199
+ font-weight: var(--app-font-weight-strong);
200
+ }
201
+
202
+ .wg_navigation__drawerClose {
203
+ display: flex;
204
+ align-items: center;
205
+ justify-content: center;
206
+ flex: none;
207
+ width: var(--app-size-menu-button);
208
+ height: var(--app-size-menu-button);
209
+ padding: 0;
210
+ border: 0;
211
+ border-radius: var(--app-radius-box);
212
+ background: transparent;
213
+ color: var(--app-color-text-strong);
214
+ cursor: pointer;
215
+
216
+ &:hover {
217
+ background: var(--app-color-accent-soft);
218
+ }
219
+
220
+ &:focus-visible {
221
+ outline: var(--app-outline-focus);
222
+ outline-offset: var(--app-outline-focus-offset);
223
+ }
224
+ }
225
+
226
+ .wg_navigation__drawerContent {
227
+ min-width: 0;
228
+ height: calc(100% - var(--app-size-mobile-header) - var(--app-space-block));
229
+
230
+ & > .wg_navigation__navigation {
231
+ height: 100%;
232
+ }
233
+ }
234
+
235
+ /* 강제 색상 환경은 흐림 대신 시스템 손잡이로 넘침 표시 */
236
+ @media (forced-colors: active) {
237
+ .wg_navigation__scroll {
238
+ mask-image: none;
239
+ scrollbar-width: thin;
240
+ scrollbar-color: auto;
241
+ }
242
+ }
243
+
244
+ /* 와이드 화면에서만 현재 문서 목차 표시 */
245
+ @media (width < 1536px) {
246
+ .wg_navigation__tocRail {
247
+ display: none;
248
+ }
249
+ }
250
+
251
+ @media (width < 1024px) {
252
+ .wg_navigation__sidebar {
253
+ position: static;
254
+ height: auto;
255
+ margin-block-end: var(--app-space-block);
256
+ margin-inline-end: 0;
257
+ border-bottom: 1px solid var(--app-color-border-layout);
258
+ }
259
+
260
+ .wg_navigation__sidebar > .wg_navigation__navigation {
261
+ height: auto;
262
+ }
263
+
264
+ .wg_navigation__sidebar > .wg_navigation__navigation > .wg_navigation__documents {
265
+ max-height: none;
266
+ }
267
+
268
+ .wg_navigation__sidebar--navigationReady {
269
+ /* 본문을 스크롤해도 메뉴 진입 유지 · 스크립트 없는 긴 목록에는 적용하지 않음 */
270
+ position: sticky;
271
+ top: 0;
272
+ z-index: var(--app-z-index-sticky);
273
+ background: var(--app-color-ground);
274
+ }
275
+
276
+ .wg_navigation__brandRow {
277
+ position: static;
278
+ height: var(--app-size-mobile-header);
279
+ padding-block: 0;
280
+ align-items: center;
281
+ }
282
+ }