@shivaedev/work-board 0.2.0 → 0.3.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 (358) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +141 -3
  3. package/dist/board.d.ts +9 -3
  4. package/dist/board.d.ts.map +1 -1
  5. package/dist/board.js +17 -9
  6. package/dist/board.js.map +1 -1
  7. package/dist/cli.js +3 -3
  8. package/dist/cli.js.map +1 -1
  9. package/dist/files/changes.d.ts +4 -3
  10. package/dist/files/changes.d.ts.map +1 -1
  11. package/dist/files/changes.js +2 -2
  12. package/dist/files/changes.js.map +1 -1
  13. package/dist/files/list.d.ts +1 -1
  14. package/dist/files/list.d.ts.map +1 -1
  15. package/dist/files/list.js +1 -1
  16. package/dist/files/list.js.map +1 -1
  17. package/dist/files/url.d.ts +2 -0
  18. package/dist/files/url.d.ts.map +1 -0
  19. package/dist/files/url.js +4 -0
  20. package/dist/files/url.js.map +1 -0
  21. package/dist/http/assets.d.ts.map +1 -1
  22. package/dist/http/assets.js +21 -6
  23. package/dist/http/assets.js.map +1 -1
  24. package/dist/http/events.d.ts +1 -1
  25. package/dist/http/events.d.ts.map +1 -1
  26. package/dist/http/events.js +1 -1
  27. package/dist/http/events.js.map +1 -1
  28. package/dist/http/identity.d.ts +7 -0
  29. package/dist/http/identity.d.ts.map +1 -0
  30. package/dist/http/identity.js +38 -0
  31. package/dist/http/identity.js.map +1 -0
  32. package/dist/http/loopback.js +2 -2
  33. package/dist/http/loopback.js.map +1 -1
  34. package/dist/http/page.d.ts +4 -3
  35. package/dist/http/page.d.ts.map +1 -1
  36. package/dist/http/page.js +37 -15
  37. package/dist/http/page.js.map +1 -1
  38. package/dist/http/search.d.ts +5 -0
  39. package/dist/http/search.d.ts.map +1 -0
  40. package/dist/http/search.js +11 -0
  41. package/dist/http/search.js.map +1 -0
  42. package/dist/http/work.d.ts +6 -0
  43. package/dist/http/work.d.ts.map +1 -0
  44. package/dist/http/work.js +22 -0
  45. package/dist/http/work.js.map +1 -0
  46. package/dist/metadata/backlinks.d.ts +8 -0
  47. package/dist/metadata/backlinks.d.ts.map +1 -0
  48. package/dist/metadata/backlinks.js +29 -0
  49. package/dist/metadata/backlinks.js.map +1 -0
  50. package/dist/metadata/fields.d.ts +29 -0
  51. package/dist/metadata/fields.d.ts.map +1 -0
  52. package/dist/metadata/fields.js +25 -0
  53. package/dist/metadata/fields.js.map +1 -0
  54. package/dist/metadata/links.d.ts +4 -0
  55. package/dist/metadata/links.d.ts.map +1 -0
  56. package/dist/metadata/links.js +18 -0
  57. package/dist/metadata/links.js.map +1 -0
  58. package/dist/metadata/locations.d.ts +3 -0
  59. package/dist/metadata/locations.d.ts.map +1 -0
  60. package/dist/metadata/locations.js +35 -0
  61. package/dist/metadata/locations.js.map +1 -0
  62. package/dist/metadata/model.d.ts +15 -0
  63. package/dist/metadata/model.d.ts.map +1 -0
  64. package/dist/metadata/model.js +13 -0
  65. package/dist/metadata/model.js.map +1 -0
  66. package/dist/metadata/parse.d.ts +16 -0
  67. package/dist/metadata/parse.d.ts.map +1 -0
  68. package/dist/metadata/parse.js +48 -0
  69. package/dist/metadata/parse.js.map +1 -0
  70. package/dist/metadata/problems.d.ts +4 -0
  71. package/dist/metadata/problems.d.ts.map +1 -0
  72. package/dist/metadata/problems.js +57 -0
  73. package/dist/metadata/problems.js.map +1 -0
  74. package/dist/metadata/relationshipLabel.d.ts +2 -0
  75. package/dist/metadata/relationshipLabel.d.ts.map +1 -0
  76. package/dist/metadata/relationshipLabel.js +13 -0
  77. package/dist/metadata/relationshipLabel.js.map +1 -0
  78. package/dist/metadata/schema.d.ts +34 -0
  79. package/dist/metadata/schema.d.ts.map +1 -0
  80. package/dist/metadata/schema.js +27 -0
  81. package/dist/metadata/schema.js.map +1 -0
  82. package/dist/metadata/sourceLinks.d.ts +5 -0
  83. package/dist/metadata/sourceLinks.d.ts.map +1 -0
  84. package/dist/metadata/sourceLinks.js +44 -0
  85. package/dist/metadata/sourceLinks.js.map +1 -0
  86. package/dist/page/backlinksHtml.d.ts +3 -0
  87. package/dist/page/backlinksHtml.d.ts.map +1 -0
  88. package/dist/page/backlinksHtml.js +16 -0
  89. package/dist/page/backlinksHtml.js.map +1 -0
  90. package/dist/page/board.d.ts +2 -2
  91. package/dist/page/board.d.ts.map +1 -1
  92. package/dist/page/board.js +16 -6
  93. package/dist/page/board.js.map +1 -1
  94. package/dist/page/client.d.ts +2 -1
  95. package/dist/page/client.d.ts.map +1 -1
  96. package/dist/page/client.js +65 -7
  97. package/dist/page/client.js.map +1 -1
  98. package/dist/page/criteriaEvidence.d.ts +4 -0
  99. package/dist/page/criteriaEvidence.d.ts.map +1 -0
  100. package/dist/page/criteriaEvidence.js +27 -0
  101. package/dist/page/criteriaEvidence.js.map +1 -0
  102. package/dist/page/diagrams.d.ts +1 -1
  103. package/dist/page/diagrams.d.ts.map +1 -1
  104. package/dist/page/diagrams.js +12 -4
  105. package/dist/page/diagrams.js.map +1 -1
  106. package/dist/page/document.d.ts +2 -2
  107. package/dist/page/document.d.ts.map +1 -1
  108. package/dist/page/document.js +7 -4
  109. package/dist/page/document.js.map +1 -1
  110. package/dist/page/escape.d.ts.map +1 -1
  111. package/dist/page/escape.js +2 -2
  112. package/dist/page/escape.js.map +1 -1
  113. package/dist/page/libraryScript.d.ts +2 -0
  114. package/dist/page/libraryScript.d.ts.map +1 -0
  115. package/dist/page/libraryScript.js +73 -0
  116. package/dist/page/libraryScript.js.map +1 -0
  117. package/dist/page/metadata.d.ts +5 -0
  118. package/dist/page/metadata.d.ts.map +1 -0
  119. package/dist/page/metadata.js +34 -0
  120. package/dist/page/metadata.js.map +1 -0
  121. package/dist/page/metadataDetails.d.ts +4 -0
  122. package/dist/page/metadataDetails.d.ts.map +1 -0
  123. package/dist/page/metadataDetails.js +21 -0
  124. package/dist/page/metadataDetails.js.map +1 -0
  125. package/dist/page/metadataLinks.d.ts +6 -0
  126. package/dist/page/metadataLinks.d.ts.map +1 -0
  127. package/dist/page/metadataLinks.js +31 -0
  128. package/dist/page/metadataLinks.js.map +1 -0
  129. package/dist/page/nav.d.ts +2 -2
  130. package/dist/page/nav.d.ts.map +1 -1
  131. package/dist/page/nav.js +4 -4
  132. package/dist/page/nav.js.map +1 -1
  133. package/dist/page/navigationScript.d.ts +2 -0
  134. package/dist/page/navigationScript.d.ts.map +1 -0
  135. package/dist/page/navigationScript.js +104 -0
  136. package/dist/page/navigationScript.js.map +1 -0
  137. package/dist/page/readingStateScript.d.ts +2 -0
  138. package/dist/page/readingStateScript.d.ts.map +1 -0
  139. package/dist/page/readingStateScript.js +62 -0
  140. package/dist/page/readingStateScript.js.map +1 -0
  141. package/dist/page/readingStyles.d.ts +2 -0
  142. package/dist/page/readingStyles.d.ts.map +1 -0
  143. package/dist/page/readingStyles.js +29 -0
  144. package/dist/page/readingStyles.js.map +1 -0
  145. package/dist/page/readingTools.d.ts +3 -0
  146. package/dist/page/readingTools.d.ts.map +1 -0
  147. package/dist/page/readingTools.js +10 -0
  148. package/dist/page/readingTools.js.map +1 -0
  149. package/dist/page/recordedEvidence.d.ts +4 -0
  150. package/dist/page/recordedEvidence.d.ts.map +1 -0
  151. package/dist/page/recordedEvidence.js +10 -0
  152. package/dist/page/recordedEvidence.js.map +1 -0
  153. package/dist/page/searchDialog.d.ts +3 -0
  154. package/dist/page/searchDialog.d.ts.map +1 -0
  155. package/dist/page/searchDialog.js +16 -0
  156. package/dist/page/searchDialog.js.map +1 -0
  157. package/dist/page/searchResultsScript.d.ts +2 -0
  158. package/dist/page/searchResultsScript.d.ts.map +1 -0
  159. package/dist/page/searchResultsScript.js +64 -0
  160. package/dist/page/searchResultsScript.js.map +1 -0
  161. package/dist/page/searchScript.d.ts +2 -0
  162. package/dist/page/searchScript.d.ts.map +1 -0
  163. package/dist/page/searchScript.js +73 -0
  164. package/dist/page/searchScript.js.map +1 -0
  165. package/dist/page/shell.d.ts +1 -1
  166. package/dist/page/shell.d.ts.map +1 -1
  167. package/dist/page/shell.js +23 -5
  168. package/dist/page/shell.js.map +1 -1
  169. package/dist/page/stateScript.d.ts +2 -0
  170. package/dist/page/stateScript.d.ts.map +1 -0
  171. package/dist/page/stateScript.js +49 -0
  172. package/dist/page/stateScript.js.map +1 -0
  173. package/dist/page/style.d.ts.map +1 -1
  174. package/dist/page/style.js +14 -34
  175. package/dist/page/style.js.map +1 -1
  176. package/dist/page/swap.d.ts +1 -1
  177. package/dist/page/swap.d.ts.map +1 -1
  178. package/dist/page/swap.js +4 -1
  179. package/dist/page/swap.js.map +1 -1
  180. package/dist/page/workspaceStyles.d.ts +3 -0
  181. package/dist/page/workspaceStyles.d.ts.map +1 -0
  182. package/dist/page/workspaceStyles.js +79 -0
  183. package/dist/page/workspaceStyles.js.map +1 -0
  184. package/dist/render/board.d.ts +8 -8
  185. package/dist/render/board.d.ts.map +1 -1
  186. package/dist/render/board.js +7 -7
  187. package/dist/render/board.js.map +1 -1
  188. package/dist/render/code.d.ts +1 -1
  189. package/dist/render/code.js +5 -5
  190. package/dist/render/code.js.map +1 -1
  191. package/dist/render/documentHeadings.d.ts +667 -0
  192. package/dist/render/documentHeadings.d.ts.map +1 -0
  193. package/dist/render/documentHeadings.js +45 -0
  194. package/dist/render/documentHeadings.js.map +1 -0
  195. package/dist/render/documentLinks.d.ts +659 -0
  196. package/dist/render/documentLinks.d.ts.map +1 -0
  197. package/dist/render/documentLinks.js +19 -0
  198. package/dist/render/documentLinks.js.map +1 -0
  199. package/dist/render/footnotes.d.ts +1 -1
  200. package/dist/render/footnotes.js +2 -2
  201. package/dist/render/footnotes.js.map +1 -1
  202. package/dist/render/highlighter.d.ts +1 -1
  203. package/dist/render/highlighter.js +2 -2
  204. package/dist/render/highlighter.js.map +1 -1
  205. package/dist/render/markdown.d.ts +7 -1
  206. package/dist/render/markdown.d.ts.map +1 -1
  207. package/dist/render/markdown.js +13 -2
  208. package/dist/render/markdown.js.map +1 -1
  209. package/dist/search/collector.d.ts +13 -0
  210. package/dist/search/collector.d.ts.map +1 -0
  211. package/dist/search/collector.js +40 -0
  212. package/dist/search/collector.js.map +1 -0
  213. package/dist/search/entries.d.ts +10 -0
  214. package/dist/search/entries.d.ts.map +1 -0
  215. package/dist/search/entries.js +37 -0
  216. package/dist/search/entries.js.map +1 -0
  217. package/dist/search/linkCollector.d.ts +8 -0
  218. package/dist/search/linkCollector.d.ts.map +1 -0
  219. package/dist/search/linkCollector.js +16 -0
  220. package/dist/search/linkCollector.js.map +1 -0
  221. package/dist/search/match.d.ts +14 -0
  222. package/dist/search/match.d.ts.map +1 -0
  223. package/dist/search/match.js +26 -0
  224. package/dist/search/match.js.map +1 -0
  225. package/dist/search/metadataEntries.d.ts +4 -0
  226. package/dist/search/metadataEntries.d.ts.map +1 -0
  227. package/dist/search/metadataEntries.js +40 -0
  228. package/dist/search/metadataEntries.js.map +1 -0
  229. package/dist/search/snapshot.d.ts +13 -0
  230. package/dist/search/snapshot.d.ts.map +1 -0
  231. package/dist/search/snapshot.js +50 -0
  232. package/dist/search/snapshot.js.map +1 -0
  233. package/dist/serve.d.ts +1 -1
  234. package/dist/serve.d.ts.map +1 -1
  235. package/dist/serve.js +1 -1
  236. package/dist/serve.js.map +1 -1
  237. package/dist/views/items.d.ts +11 -0
  238. package/dist/views/items.d.ts.map +1 -0
  239. package/dist/views/items.js +48 -0
  240. package/dist/views/items.js.map +1 -0
  241. package/dist/views/projection.d.ts +15 -0
  242. package/dist/views/projection.d.ts.map +1 -0
  243. package/dist/views/projection.js +47 -0
  244. package/dist/views/projection.js.map +1 -0
  245. package/dist/views/savedScript.d.ts +2 -0
  246. package/dist/views/savedScript.d.ts.map +1 -0
  247. package/dist/views/savedScript.js +89 -0
  248. package/dist/views/savedScript.js.map +1 -0
  249. package/dist/views/state.d.ts +15 -0
  250. package/dist/views/state.d.ts.map +1 -0
  251. package/dist/views/state.js +45 -0
  252. package/dist/views/state.js.map +1 -0
  253. package/dist/views/tools.d.ts +3 -0
  254. package/dist/views/tools.d.ts.map +1 -0
  255. package/dist/views/tools.js +11 -0
  256. package/dist/views/tools.js.map +1 -0
  257. package/dist/views/workCards.d.ts +4 -0
  258. package/dist/views/workCards.d.ts.map +1 -0
  259. package/dist/views/workCards.js +23 -0
  260. package/dist/views/workCards.js.map +1 -0
  261. package/dist/views/workControls.d.ts +4 -0
  262. package/dist/views/workControls.d.ts.map +1 -0
  263. package/dist/views/workControls.js +32 -0
  264. package/dist/views/workControls.js.map +1 -0
  265. package/dist/views/workDetail.d.ts +13 -0
  266. package/dist/views/workDetail.d.ts.map +1 -0
  267. package/dist/views/workDetail.js +26 -0
  268. package/dist/views/workDetail.js.map +1 -0
  269. package/dist/views/workHtml.d.ts +15 -0
  270. package/dist/views/workHtml.d.ts.map +1 -0
  271. package/dist/views/workHtml.js +35 -0
  272. package/dist/views/workHtml.js.map +1 -0
  273. package/dist/views/workStyle.d.ts +2 -0
  274. package/dist/views/workStyle.d.ts.map +1 -0
  275. package/dist/views/workStyle.js +18 -0
  276. package/dist/views/workStyle.js.map +1 -0
  277. package/dist/views/workTable.d.ts +4 -0
  278. package/dist/views/workTable.d.ts.map +1 -0
  279. package/dist/views/workTable.js +19 -0
  280. package/dist/views/workTable.js.map +1 -0
  281. package/package.json +42 -33
  282. package/src/board.ts +25 -12
  283. package/src/cli.ts +3 -3
  284. package/src/files/changes.ts +7 -6
  285. package/src/files/list.ts +3 -3
  286. package/src/files/url.ts +3 -0
  287. package/src/http/assets.ts +21 -6
  288. package/src/http/events.ts +2 -2
  289. package/src/http/identity.ts +62 -0
  290. package/src/http/loopback.ts +2 -2
  291. package/src/http/page.ts +56 -19
  292. package/src/http/search.ts +13 -0
  293. package/src/http/work.ts +41 -0
  294. package/src/metadata/backlinks.ts +39 -0
  295. package/src/metadata/fields.ts +26 -0
  296. package/src/metadata/links.ts +19 -0
  297. package/src/metadata/locations.ts +34 -0
  298. package/src/metadata/model.ts +27 -0
  299. package/src/metadata/parse.ts +62 -0
  300. package/src/metadata/problems.ts +62 -0
  301. package/src/metadata/relationshipLabel.ts +13 -0
  302. package/src/metadata/schema.ts +36 -0
  303. package/src/metadata/sourceLinks.ts +46 -0
  304. package/src/page/backlinksHtml.ts +18 -0
  305. package/src/page/board.ts +16 -6
  306. package/src/page/client.ts +65 -7
  307. package/src/page/criteriaEvidence.ts +36 -0
  308. package/src/page/diagrams.ts +12 -4
  309. package/src/page/document.ts +8 -5
  310. package/src/page/escape.ts +2 -2
  311. package/src/page/libraryScript.ts +72 -0
  312. package/src/page/metadata.ts +40 -0
  313. package/src/page/metadataDetails.ts +24 -0
  314. package/src/page/metadataLinks.ts +35 -0
  315. package/src/page/nav.ts +9 -8
  316. package/src/page/navigationScript.ts +103 -0
  317. package/src/page/readingStateScript.ts +61 -0
  318. package/src/page/readingStyles.ts +28 -0
  319. package/src/page/readingTools.ts +12 -0
  320. package/src/page/recordedEvidence.ts +12 -0
  321. package/src/page/searchDialog.ts +16 -0
  322. package/src/page/searchResultsScript.ts +63 -0
  323. package/src/page/searchScript.ts +72 -0
  324. package/src/page/shell.ts +24 -5
  325. package/src/page/stateScript.ts +48 -0
  326. package/src/page/style.ts +14 -35
  327. package/src/page/swap.ts +4 -1
  328. package/src/page/workspaceStyles.ts +79 -0
  329. package/src/render/board.ts +19 -19
  330. package/src/render/code.ts +5 -5
  331. package/src/render/documentHeadings.ts +52 -0
  332. package/src/render/documentLinks.ts +19 -0
  333. package/src/render/footnotes.ts +2 -2
  334. package/src/render/highlighter.ts +2 -2
  335. package/src/render/markdown.ts +21 -4
  336. package/src/search/collector.ts +44 -0
  337. package/src/search/entries.ts +51 -0
  338. package/src/search/linkCollector.ts +16 -0
  339. package/src/search/match.ts +28 -0
  340. package/src/search/metadataEntries.ts +42 -0
  341. package/src/search/snapshot.ts +60 -0
  342. package/src/serve.ts +1 -1
  343. package/src/views/items.ts +55 -0
  344. package/src/views/projection.ts +59 -0
  345. package/src/views/savedScript.ts +88 -0
  346. package/src/views/state.ts +47 -0
  347. package/src/views/tools.ts +11 -0
  348. package/src/views/workCards.ts +26 -0
  349. package/src/views/workControls.ts +38 -0
  350. package/src/views/workDetail.ts +28 -0
  351. package/src/views/workHtml.ts +39 -0
  352. package/src/views/workStyle.ts +17 -0
  353. package/src/views/workTable.ts +21 -0
  354. package/dist/index.d.ts +0 -2
  355. package/dist/index.d.ts.map +0 -1
  356. package/dist/index.js +0 -2
  357. package/dist/index.js.map +0 -1
  358. package/src/index.ts +0 -1
package/src/page/style.ts CHANGED
@@ -1,36 +1,12 @@
1
- const tokens = `
2
- :root {
3
- color-scheme: light dark;
4
- --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
5
- --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
6
- --bg: #ffffff; --surface: #f6f8fa; --text: #1f2328; --muted: #59636e; --border: #d1d9e0; --link: #0969da; --danger: #b3261e;
7
- }
8
- @media (prefers-color-scheme: dark) {
9
- :root { --bg: #1e1e1e; --surface: #272727; --text: #e8e8e8; --muted: #a8a8a8; --border: #3d3d3d; --link: #58a6ff; --danger: #ff8a80; }
10
- }
11
- `;
12
-
13
- const page = `
14
- body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.65 var(--sans); }
15
- a { color: var(--link); }
16
- .page { box-sizing: content-box; max-width: 72ch; margin: 0 auto; padding: 0 16px 64px; }
17
- .bar { display: flex; align-items: flex-start; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
18
- .files { flex: 1; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; }
19
- .files a { color: var(--text); text-decoration: none; }
20
- .files a:hover, .files a[aria-current="page"] { color: var(--link); text-decoration: underline; }
21
- .files details[open] { flex-basis: 100%; }
22
- .files summary { cursor: pointer; color: var(--muted); }
23
- .files ul { list-style: none; margin: 4px 0 8px; padding: 0 0 0 12px; border-left: 1px solid var(--border); }
24
- .age { color: var(--muted); font: 12px var(--mono); margin-left: 6px; }
25
- .live { color: var(--muted); font: 12px/1.9 var(--mono); }
26
- .live[data-state="down"], .live[data-state="stale"] { color: var(--danger); }
27
- .meta { color: var(--muted); font-size: 14px; margin: 0; }
28
- .meta .age { margin: 0; }
29
- `;
1
+ import { workStyle } from "#views/workStyle.ts";
2
+ import { metadataStyles } from "./metadata.ts";
3
+ import { readingStyles } from "./readingStyles.ts";
4
+ import { searchStyles } from "./searchDialog.ts";
5
+ import { layout, theme } from "./workspaceStyles.ts";
30
6
 
31
7
  const prose = `
32
8
  h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; margin: 1.6em 0 0.5em; }
33
- h1 { font-size: 1.9em; margin-top: 1em; }
9
+ h1 { overflow-wrap: anywhere; font-size: 1.9em; margin-top: 1em; }
34
10
  h2 { font-size: 1.45em; }
35
11
  h3 { font-size: 1.15em; }
36
12
  h1 strong, h2 strong, h3 strong { font-weight: inherit; }
@@ -43,7 +19,8 @@ code { font: 0.875em var(--mono); background: var(--surface); padding: 0.1em 0.3
43
19
  pre { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
44
20
  pre code { background: none; padding: 0; font-size: 0.85em; }
45
21
  .shiki span { color: var(--shiki-light); }
46
- @media (prefers-color-scheme: dark) { .shiki span { color: var(--shiki-dark); } }
22
+ @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .shiki span { color: var(--shiki-dark); } }
23
+ :root[data-theme="dark"] .shiki span { color: var(--shiki-dark); }
47
24
  table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.925em; }
48
25
  th, td { text-align: left; vertical-align: top; padding: 6px 10px; border: 1px solid var(--border); }
49
26
  tr:nth-child(2n) td { background: var(--surface); }
@@ -59,9 +36,11 @@ const board = `
59
36
  .board-head .intro { color: var(--muted); }
60
37
  .counts { margin: 0; }
61
38
  .counts b { font-variant-numeric: tabular-nums; }
62
- .board section { margin-top: 2.2em; }
63
- .board section > h2 { margin: 0 0 0.2em; }
64
- .item, .notes { padding: 0.9em 0 0.1em; border-top: 1px solid var(--border); }
39
+ .board { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: var(--space); margin-top: 2em; align-items: start; }
40
+ .board section { min-width: 0; }
41
+ .board section > h2 { margin: 0 0 0.8em; font-size: 1.1em; overflow-wrap: anywhere; }
42
+ .item, .notes { padding: var(--card-space); margin-bottom: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); overflow-wrap: anywhere; }
43
+ .item > :last-child, .notes > :last-child { margin-bottom: 0; }
65
44
  .item > h3 { margin: 0 0 0.4em; }
66
45
  .item > h3 > code:first-child { background: none; padding: 0; margin-right: 0.6em; color: var(--muted); font-weight: 400; }
67
46
  footer { margin-top: 2.5em; padding-top: 1em; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.925em; }
@@ -76,4 +55,4 @@ figure.diagram[data-state="failed"]::after { content: attr(data-error); color: v
76
55
  @media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
77
56
  `;
78
57
 
79
- export const style = tokens + page + prose + board + diagrams;
58
+ export const style = theme + layout + prose + board + diagrams + readingStyles() + searchStyles + metadataStyles + workStyle();
package/src/page/swap.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const swap = `
2
- const containers = new Set(["DIV", "SECTION", "ARTICLE", "HEADER", "FOOTER", "MAIN", "NAV"]);
2
+ const containers = new Set(["DIV", "SECTION", "ARTICLE", "HEADER", "FOOTER", "MAIN", "NAV", "FORM", "SELECT", "LABEL", "ASIDE"]);
3
3
 
4
4
  const structural = (element) => [...element.childNodes].every((node) => node.nodeType === 1 || node.textContent.trim() === "");
5
5
 
@@ -56,6 +56,8 @@ const matches = (a, b) => {
56
56
  };
57
57
 
58
58
  const patch = (current, incoming) => {
59
+ const selected = current.tagName === "SELECT" ? current.value : null;
60
+ const fallback = incoming.tagName === "SELECT" ? incoming.value : null;
59
61
  if (!structural(current) || !structural(incoming)) {
60
62
  current.replaceChildren(...incoming.childNodes);
61
63
  for (const child of current.children) remember(child);
@@ -83,6 +85,7 @@ const patch = (current, incoming) => {
83
85
  i++;
84
86
  j++;
85
87
  }
88
+ if (selected !== null) current.value = [...current.options].some((option) => option.value === selected) ? selected : fallback;
86
89
  };
87
90
 
88
91
  const keysOf = (root) => {
@@ -0,0 +1,79 @@
1
+ export const layout = `
2
+ * { box-sizing: border-box; }
3
+ body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.65 var(--sans); }
4
+ a { color: var(--link); }
5
+ button, select { font: inherit; color: inherit; }
6
+ button, select, summary { cursor: pointer; }
7
+ button, select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); }
8
+ :focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
9
+ .skip { position: fixed; top: -100px; left: 16px; z-index: 5; padding: 8px 16px; background: var(--card); }
10
+ .skip:focus { top: 8px; }
11
+ .workspace { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
12
+ :root[data-sidebar="closed"] .workspace { grid-template-columns: minmax(0, 1fr); }
13
+ .sidebar { --focus: #e2bc79; position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto; padding: var(--space) 16px; background: var(--sidebar); color: var(--sidebar-text); }
14
+ .sidebar[hidden] { display: none; }
15
+ .brand { display: block; padding: 0 12px 28px; font-size: 24px; font-weight: 600; letter-spacing: -0.8px; text-decoration: none; color: var(--sidebar-text); }
16
+ .brand span { display: block; margin-top: 4px; font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--sidebar-muted); }
17
+ .sidebar .nav-heading { margin: 0 12px 12px; font: 600 12px var(--sans); color: var(--sidebar-muted); }
18
+ .files { font-size: 14px; }
19
+ .files ul { list-style: none; margin: 0 0 10px; padding: 0; }
20
+ .files li { display: flex; align-items: baseline; gap: 8px; margin: 0; padding: 4px 10px; border-radius: 5px; }
21
+ .files li:has(a[aria-current="page"]) { background: #385242; }
22
+ .files a { flex: 1; min-width: 0; color: var(--sidebar-text); text-decoration: none; overflow-wrap: anywhere; }
23
+ .files a:hover, .files a[aria-current="page"] { text-decoration: underline; text-underline-offset: 4px; }
24
+ .files details { margin: 8px 0; }
25
+ .files summary { padding: 6px 10px; color: var(--sidebar-muted); overflow-wrap: anywhere; }
26
+ .files details ul { margin-left: 14px; border-left: 1px solid var(--sidebar-border); }
27
+ .age { color: var(--muted); font: 12px var(--mono); margin-left: 6px; white-space: nowrap; }
28
+ .files .age { color: var(--sidebar-muted); margin: 0; flex-shrink: 0; }
29
+ .page { min-width: 0; }
30
+ .bar { display: flex; align-items: center; gap: 16px; padding: 16px var(--space); border-bottom: 1px solid var(--border); font-size: 13px; }
31
+ .bar button { flex-shrink: 0; }
32
+ .breadcrumbs { display: flex; flex-wrap: wrap; gap: 6px 10px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
33
+ .breadcrumbs > span:not(.separator) { min-width: 0; }
34
+ .separator { color: var(--muted); }
35
+ .live { color: var(--muted); font: 12px/1.9 var(--mono); }
36
+ .live[data-state="down"], .live[data-state="stale"] { color: var(--danger); }
37
+ .preferences { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 12px; align-items: center; padding: 14px var(--space) 0; color: var(--muted); font-size: 12px; }
38
+ .preference { display: flex; gap: 8px; align-items: center; }
39
+ #preference-status:empty { display: none; }
40
+ #doc { padding: var(--space) var(--space) 64px; min-width: 0; }
41
+ .document-view { max-width: calc(72ch + 2 * var(--space)); margin-inline: auto; }
42
+ .board-view { max-width: 1600px; margin-inline: auto; }
43
+ .meta { color: var(--muted); font-size: 13px; margin: 0; overflow-wrap: anywhere; }
44
+ .meta .age { margin: 0; }
45
+ @media (max-width: 760px) {
46
+ .workspace { grid-template-columns: minmax(0, 1fr); }
47
+ .sidebar { position: static; height: auto; max-height: 42vh; border-bottom: 1px solid var(--border); }
48
+ .brand { padding-bottom: 16px; }
49
+ .bar { flex-wrap: wrap; gap: 12px; }
50
+ .breadcrumbs { flex-basis: calc(100% - 100px); }
51
+ .live { margin-left: auto; }
52
+ .preferences { justify-content: flex-start; }
53
+ :root { --space: 18px; }
54
+ }
55
+ `;
56
+ const light = `
57
+ color-scheme: light;
58
+ --bg: #f7f8f4; --surface: #edf1e7; --card: #ffffff; --text: #263c34; --muted: #596957;
59
+ --border: #d5dfd0; --link: #315f45; --danger: #a03024; --focus: #976323;
60
+ --sidebar: #203a30; --sidebar-text: #e7eee2; --sidebar-muted: #b6c8ad; --sidebar-border: #4a624c;
61
+ `;
62
+ const dark = `
63
+ color-scheme: dark;
64
+ --bg: #18251f; --surface: #26382d; --card: #203027; --text: #e7eee2; --muted: #b0c1a6;
65
+ --border: #455a48; --link: #b1d4a1; --danger: #ffafa2; --focus: #e2bc79;
66
+ --sidebar: #142219; --sidebar-text: #e7eee2; --sidebar-muted: #b6c8ad; --sidebar-border: #455a48;
67
+ `;
68
+
69
+ export const theme = `
70
+ :root {
71
+ --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
72
+ --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
73
+ --space: 24px; --card-space: 20px;
74
+ ${light}
75
+ }
76
+ @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { ${dark} } }
77
+ :root[data-theme="dark"] { ${dark} }
78
+ :root[data-density="compact"] { --space: 16px; --card-space: 12px; }
79
+ `;
@@ -2,26 +2,26 @@ import type { RootContent } from "mdast";
2
2
  import { markdownToMdast } from "satteri";
3
3
 
4
4
  export interface Section {
5
- readonly title: string;
6
5
  readonly heading: string;
6
+ readonly items: readonly string[];
7
7
  readonly notes: string;
8
- readonly items: ReadonlyArray<string>;
8
+ readonly title: string;
9
9
  }
10
10
 
11
11
  export interface Board {
12
- readonly title: string;
13
- readonly intro: string;
14
- readonly sections: ReadonlyArray<Section>;
15
- readonly footer: string;
16
12
  readonly definitions: string;
13
+ readonly footer: string;
14
+ readonly intro: string;
15
+ readonly sections: readonly Section[];
16
+ readonly title: string;
17
17
  }
18
18
 
19
19
  interface Draft {
20
- title: string;
20
+ definitions: string[];
21
+ footer: string[] | undefined;
21
22
  intro: string[];
22
23
  sections: Array<{ title: string; heading: string; notes: string[]; items: string[][] }>;
23
- footer: string[] | undefined;
24
- definitions: string[];
24
+ title: string;
25
25
  }
26
26
 
27
27
  const textOf = (node: RootContent): string => {
@@ -42,7 +42,7 @@ const place = (draft: Draft, node: RootContent, source: string, closing: boolean
42
42
  } else if (node.type === "heading" && node.depth === 1 && draft.title === "") {
43
43
  draft.title = source;
44
44
  } else if (isSection(node)) {
45
- draft.sections.push({ title: textOf(node), heading: source, notes: [], items: [] });
45
+ draft.sections.push({ heading: source, items: [], notes: [], title: textOf(node) });
46
46
  } else if (section === undefined) {
47
47
  draft.intro.push(source);
48
48
  } else if (node.type === "heading" && node.depth === 3) {
@@ -54,10 +54,10 @@ const place = (draft: Draft, node: RootContent, source: string, closing: boolean
54
54
  }
55
55
  };
56
56
 
57
- const joined = (blocks: ReadonlyArray<string>): string => blocks.join("\n\n");
57
+ const joined = (blocks: readonly string[]): string => blocks.join("\n\n");
58
58
 
59
59
  export const boardOf = (source: string): Board => {
60
- const draft: Draft = { title: "", intro: [], sections: [], footer: undefined, definitions: [] };
60
+ const draft: Draft = { definitions: [], footer: undefined, intro: [], sections: [], title: "" };
61
61
  const root = markdownToMdast(source);
62
62
  const nodes = root.type === "root" ? root.children : [];
63
63
  const lastHeading = nodes.findLastIndex((node) => node.type === "heading");
@@ -65,18 +65,18 @@ export const boardOf = (source: string): Board => {
65
65
  place(draft, node, source.slice(node.position?.start.offset, node.position?.end.offset), index > lastHeading);
66
66
  });
67
67
  return {
68
- title: draft.title,
69
- intro: joined(draft.intro),
70
- sections: draft.sections.map((section) => ({ ...section, notes: joined(section.notes), items: section.items.map(joined) })),
71
- footer: joined(draft.footer ?? []),
72
68
  definitions: joined(draft.definitions),
69
+ footer: joined(draft.footer ?? []),
70
+ intro: joined(draft.intro),
71
+ sections: draft.sections.map((section) => ({ ...section, items: section.items.map(joined), notes: joined(section.notes) })),
72
+ title: draft.title,
73
73
  };
74
74
  };
75
75
 
76
76
  export interface Count {
77
- readonly title: string;
78
77
  readonly count: number;
78
+ readonly title: string;
79
79
  }
80
80
 
81
- export const countsOf = (board: Board): ReadonlyArray<Count> =>
82
- board.sections.flatMap((section) => (section.items.length === 0 ? [] : [{ title: section.title, count: section.items.length }]));
81
+ export const countsOf = (board: Board): readonly Count[] =>
82
+ board.sections.flatMap((section) => (section.items.length === 0 ? [] : [{ count: section.items.length, title: section.title }]));
@@ -17,10 +17,10 @@ const textOf = (node: ElementContent): string => {
17
17
  };
18
18
 
19
19
  const diagram = (source: string): Element => ({
20
- type: "element",
21
- tagName: "figure",
20
+ children: [{ children: [{ type: "text", value: source }], properties: { className: ["diagram-source"] }, tagName: "pre", type: "element" }],
22
21
  properties: { className: ["diagram"], dataState: "pending" },
23
- children: [{ type: "element", tagName: "pre", properties: { className: ["diagram-source"] }, children: [{ type: "text", value: source }] }],
22
+ tagName: "figure",
23
+ type: "element",
24
24
  });
25
25
 
26
26
  const isBundled = (language: string): language is BundledLanguage => Object.hasOwn(bundledLanguages, language);
@@ -30,12 +30,11 @@ const highlighted = async (highlighter: Shiki, source: string, language: string)
30
30
  return undefined;
31
31
  }
32
32
  await highlighter.loadLanguage(language);
33
- return highlighter.codeToHast(source, { lang: language, themes: THEMES, defaultColor: false }).children[0];
33
+ return highlighter.codeToHast(source, { defaultColor: false, lang: language, themes: THEMES }).children.at(0);
34
34
  };
35
35
 
36
36
  export const codeBlocks = (highlighter: Shiki) =>
37
37
  defineHastPlugin({
38
- name: "work-board-code",
39
38
  element: {
40
39
  filter: ["pre"],
41
40
  visit: async (pre) => {
@@ -51,4 +50,5 @@ export const codeBlocks = (highlighter: Shiki) =>
51
50
  return language === undefined ? undefined : await highlighted(highlighter, source, language);
52
51
  },
53
52
  },
53
+ name: "work-board-code",
54
54
  });
@@ -0,0 +1,52 @@
1
+ import { defineHastPlugin } from "satteri";
2
+
3
+ export interface Heading {
4
+ readonly depth: number;
5
+ readonly id: string;
6
+ readonly title: string;
7
+ }
8
+
9
+ export function documentHeadings() {
10
+ const entries: Heading[] = [];
11
+ const used = new Set<string>();
12
+ const plugin = defineHastPlugin({
13
+ element: {
14
+ filter: ["h1", "h2", "h3", "h4", "h5", "h6"],
15
+ visit: (element, context) => {
16
+ if (element.properties.id !== undefined) {
17
+ return;
18
+ }
19
+ const title = context.textContent(element).trim();
20
+ const slug =
21
+ title
22
+ .normalize("NFKC")
23
+ .toLowerCase()
24
+ .replace(/[^\p{Letter}\p{Number}\s_-]/gu, "")
25
+ .trim()
26
+ .replace(/\s+/gu, "-") || "section";
27
+ const base = `heading-${slug}`;
28
+ let id = base;
29
+ for (let suffix = 2; used.has(id); suffix += 1) {
30
+ id = `${base}-${suffix}`;
31
+ }
32
+ used.add(id);
33
+ entries.push({ depth: Number(element.tagName.slice(1)), id, title });
34
+ return {
35
+ ...element,
36
+ children: [
37
+ ...element.children,
38
+ {
39
+ children: [],
40
+ properties: { ariaLabel: `Link to ${title || "section"}`, className: ["heading-anchor"], href: `#${id}` },
41
+ tagName: "a",
42
+ type: "element" as const,
43
+ },
44
+ ],
45
+ properties: { ...element.properties, id, tabIndex: -1 },
46
+ };
47
+ },
48
+ },
49
+ name: "work-board-headings",
50
+ });
51
+ return { entries, plugin };
52
+ }
@@ -0,0 +1,19 @@
1
+ import { defineHastPlugin } from "satteri";
2
+ import { fileUrl } from "#files/url.ts";
3
+
4
+ export function documentLinks(file: string) {
5
+ return defineHastPlugin({
6
+ element: {
7
+ filter: ["a"],
8
+ visit: (element) => {
9
+ const href = element.properties.href;
10
+ if (typeof href !== "string" || href.startsWith("#") || href.startsWith("/") || /^[a-z][a-z\d+.-]*:/iu.exec(href) !== null) {
11
+ return;
12
+ }
13
+ const target = new URL(href, `http://work-board.local${fileUrl(file)}`);
14
+ return { ...element, properties: { ...element.properties, href: target.pathname + target.search + target.hash } };
15
+ },
16
+ },
17
+ name: "work-board-document-links",
18
+ });
19
+ }
@@ -1,7 +1,7 @@
1
1
  import type { Element } from "hast";
2
2
  import { defineHastPlugin } from "satteri";
3
3
 
4
- const FOOTNOTE_IDS = /^(?:user-content-fn|footnote-label)/;
4
+ const FOOTNOTE_IDS = /^(?:user-content-fn|footnote-label)/u;
5
5
 
6
6
  type Value = Element["properties"][string];
7
7
 
@@ -19,7 +19,6 @@ const scoped = (prefix: string, value: Value): Value => {
19
19
 
20
20
  export const footnoteIds = (prefix: string) =>
21
21
  defineHastPlugin({
22
- name: "work-board-footnote-ids",
23
22
  element: {
24
23
  filter: ["a", "h2", "li"],
25
24
  visit: (element) => ({
@@ -29,4 +28,5 @@ export const footnoteIds = (prefix: string) =>
29
28
  ),
30
29
  }),
31
30
  },
31
+ name: "work-board-footnote-ids",
32
32
  });
@@ -2,14 +2,14 @@ import { Context, Effect, Layer } from "effect";
2
2
  import { createHighlighter, type Highlighter as Shiki } from "shiki";
3
3
  import { RenderFailed } from "./failed.ts";
4
4
 
5
- export const THEMES = { light: "github-light", dark: "github-dark" } as const;
5
+ export const THEMES = { dark: "github-dark", light: "github-light" } as const;
6
6
 
7
7
  export class Highlighter extends Context.Service<Highlighter, Shiki>()("WorkBoard/Highlighter") {
8
8
  static readonly layer = Layer.effect(Highlighter)(
9
9
  Effect.acquireRelease(
10
10
  Effect.tryPromise({
11
- try: () => createHighlighter({ themes: Object.values(THEMES), langs: [] }),
12
11
  catch: (cause) => new RenderFailed({ cause }),
12
+ try: () => createHighlighter({ langs: [], themes: Object.values(THEMES) }),
13
13
  }),
14
14
  (highlighter) => Effect.sync(() => highlighter.dispose()),
15
15
  ),
@@ -1,16 +1,33 @@
1
1
  import { Effect } from "effect";
2
- import { markdownToHtml } from "satteri";
2
+ import { type HastPluginInput, markdownToHtml } from "satteri";
3
3
  import { codeBlocks } from "./code.ts";
4
+ import type { documentHeadings } from "./documentHeadings.ts";
5
+ import { documentLinks } from "./documentLinks.ts";
4
6
  import { RenderFailed } from "./failed.ts";
5
7
  import { footnoteIds } from "./footnotes.ts";
6
8
  import { Highlighter } from "./highlighter.ts";
7
9
 
8
- export const renderMarkdown = Effect.fn("WorkBoard.renderMarkdown")(function* (source: string, idPrefix = "") {
10
+ export interface RenderOptions {
11
+ readonly file?: string;
12
+ readonly headings?: ReturnType<typeof documentHeadings>;
13
+ readonly idPrefix?: string;
14
+ }
15
+
16
+ export const renderMarkdown = Effect.fn("WorkBoard.renderMarkdown")(function* (source: string, options: RenderOptions = {}) {
9
17
  const highlighter = yield* Highlighter;
18
+ const plugins: HastPluginInput[] = [codeBlocks(highlighter)];
19
+ if (options.idPrefix !== undefined) {
20
+ plugins.push(footnoteIds(options.idPrefix));
21
+ }
22
+ if (options.file !== undefined) {
23
+ plugins.push(documentLinks(options.file));
24
+ }
25
+ if (options.headings !== undefined) {
26
+ plugins.push(options.headings.plugin);
27
+ }
10
28
  const { html } = yield* Effect.tryPromise({
11
- try: async () =>
12
- markdownToHtml(source, { hastPlugins: idPrefix === "" ? [codeBlocks(highlighter)] : [codeBlocks(highlighter), footnoteIds(idPrefix)] }),
13
29
  catch: (cause) => new RenderFailed({ cause }),
30
+ try: async () => markdownToHtml(source, { hastPlugins: plugins }),
14
31
  });
15
32
  return html;
16
33
  });
@@ -0,0 +1,44 @@
1
+ import type { Element } from "hast";
2
+ import { defineHastPlugin } from "satteri";
3
+ import { fileUrl } from "#files/url.ts";
4
+ import type { Entry } from "./entries.ts";
5
+
6
+ function sourceLine(element: Element, first: number | undefined, length: number): { readonly line?: number } {
7
+ if (!element.position || first === undefined || element.position.start.line > length) {
8
+ return {};
9
+ }
10
+ return { line: first + element.position.start.line - 1 };
11
+ }
12
+
13
+ export function searchCollector(file: string, startLine: () => number | undefined, length: () => number) {
14
+ const entries: Entry[] = [];
15
+ let passage = "";
16
+ let label = file;
17
+ const plugin = defineHastPlugin({
18
+ element: {
19
+ filter: ["h1", "h2", "h3", "h4", "h5", "h6", "p", "pre", "li", "td", "th"],
20
+ visit: (element, context) => {
21
+ const text = context.textContent(element).replace(/\s+/gu, " ").trim();
22
+ if (!text || element.properties.id === "footnote-label") {
23
+ return;
24
+ }
25
+ const heading = element.tagName.startsWith("h") && element.tagName !== "th";
26
+ if (heading && typeof element.properties.id === "string") {
27
+ passage = element.properties.id;
28
+ label = text;
29
+ }
30
+ entries.push({
31
+ file,
32
+ href: fileUrl(file) + (passage ? `#${encodeURIComponent(passage)}` : ""),
33
+ kind: heading ? "heading" : "passage",
34
+ ...sourceLine(element, startLine(), length()),
35
+ text,
36
+ title: label,
37
+ });
38
+ },
39
+ },
40
+ name: "work-board-search-text",
41
+ });
42
+
43
+ return { entries, plugin };
44
+ }
@@ -0,0 +1,51 @@
1
+ import { markdownToHtml } from "satteri";
2
+ import { fileUrl } from "#files/url.ts";
3
+ import { boardOf } from "#render/board.ts";
4
+ import { documentHeadings } from "#render/documentHeadings.ts";
5
+ import { searchCollector } from "./collector.ts";
6
+ import { linkCollector } from "./linkCollector.ts";
7
+
8
+ export interface Entry {
9
+ readonly file: string;
10
+ readonly href: string;
11
+ readonly kind: "document" | "heading" | "passage";
12
+ readonly line?: number;
13
+ readonly text: string;
14
+ readonly title: string;
15
+ }
16
+
17
+ function fragmentLocation(source: string, fragment: string, bodyLine: number, seen: Map<string, number>): number | undefined {
18
+ const start = source.indexOf(fragment, seen.get(fragment) ?? 0);
19
+ if (start < 0) {
20
+ return undefined;
21
+ }
22
+ seen.set(fragment, start + fragment.length);
23
+ return bodyLine + source.slice(0, start).split("\n").length - 1;
24
+ }
25
+
26
+ export async function entriesOf(source: string, file: string, home: boolean, bodyLine = 1, links = new Set<string>()): Promise<readonly Entry[]> {
27
+ const headings = documentHeadings();
28
+ let fragmentLine: number | undefined = bodyLine;
29
+ let fragmentLength = 0;
30
+ const seenFragments = new Map<string, number>();
31
+ const { entries, plugin } = searchCollector(
32
+ file,
33
+ () => fragmentLine,
34
+ () => fragmentLength,
35
+ );
36
+ const board = home ? boardOf(source) : undefined;
37
+ const fragments = board
38
+ ? [board.title, board.intro, ...board.sections.flatMap((section) => [section.heading, section.notes, ...section.items]), board.footer]
39
+ : [source];
40
+ for (const fragment of fragments) {
41
+ if (fragment) {
42
+ fragmentLength = fragment.split("\n").length;
43
+ fragmentLine = board ? fragmentLocation(source, fragment, bodyLine, seenFragments) : bodyLine;
44
+ await markdownToHtml(board?.definitions ? `${fragment}\n\n${board.definitions}` : fragment, {
45
+ hastPlugins: [headings.plugin, plugin, linkCollector(links)],
46
+ });
47
+ }
48
+ }
49
+ const title = headings.entries.find((heading) => heading.depth === 1)?.title || file;
50
+ return [{ file, href: fileUrl(file), kind: "document", line: bodyLine, text: `${file} ${title}`, title }, ...entries];
51
+ }
@@ -0,0 +1,16 @@
1
+ import { defineHastPlugin } from "satteri";
2
+
3
+ export function linkCollector(links: Set<string>) {
4
+ return defineHastPlugin({
5
+ element: {
6
+ filter: ["a"],
7
+ visit: (element) => {
8
+ const href = element.properties.href;
9
+ if (typeof href === "string" && !href.startsWith("#")) {
10
+ links.add(href);
11
+ }
12
+ },
13
+ },
14
+ name: "work-board-link-collector",
15
+ });
16
+ }
@@ -0,0 +1,28 @@
1
+ import type { Entry } from "./entries.ts";
2
+
3
+ function normalize(text: string): string {
4
+ return text.normalize("NFKC").toLowerCase().replace(/\s+/gu, " ").trim();
5
+ }
6
+
7
+ export function searchMatch(entries: readonly Entry[], query: string) {
8
+ const phrase = normalize(query.slice(0, 200));
9
+ const terms = phrase.split(" ").filter(Boolean).slice(0, 8);
10
+ if (terms.length === 0) {
11
+ return { results: [], total: 0 };
12
+ }
13
+ const matches = entries
14
+ .flatMap((entry, order) => {
15
+ const text = normalize(entry.text);
16
+ if (!terms.every((term) => text.includes(term))) {
17
+ return [];
18
+ }
19
+ const at = Math.max(0, entry.text.toLowerCase().indexOf(terms[0] ?? ""));
20
+ const start = Math.max(0, at - 50);
21
+ const snippet = (start ? "…" : "") + entry.text.slice(start, start + 180) + (entry.text.length > start + 180 ? "…" : "");
22
+ const ranks = { document: 0, heading: 2, passage: 4 };
23
+ const rank = ranks[entry.kind] + (text.includes(phrase) ? 0 : 1);
24
+ return [{ entry: { ...entry, snippet }, order, rank }];
25
+ })
26
+ .sort((left, right) => left.rank - right.rank || left.order - right.order);
27
+ return { results: matches.slice(0, 40).map((match) => match.entry), total: matches.length };
28
+ }
@@ -0,0 +1,42 @@
1
+ import { fileUrl } from "#files/url.ts";
2
+ import { identityUrl } from "#metadata/links.ts";
3
+ import type { MetadataDocument, MetadataModel } from "#metadata/model.ts";
4
+ import type { Entry } from "./entries.ts";
5
+
6
+ function itemUrl(document: MetadataDocument, model: MetadataModel): string {
7
+ const id = document.parsed.fields.id;
8
+ return model.unavailable.length === 0 && id && model.ids.get(id)?.length === 1 ? identityUrl(id) : fileUrl(document.file);
9
+ }
10
+ export function metadataEntries(entries: readonly Entry[], documents: readonly MetadataDocument[], model: MetadataModel): readonly Entry[] {
11
+ const sources = new Map(documents.map((document) => [document.file, document]));
12
+ const enriched = entries.map((entry) => {
13
+ const document = sources.get(entry.file);
14
+ if (entry.kind !== "document" || !document) {
15
+ return entry;
16
+ }
17
+ const fields = document.parsed.fields;
18
+ return {
19
+ ...entry,
20
+ href: itemUrl(document, model),
21
+ text: [entry.text, fields.id, fields.kind, fields.status, fields.owner, fields.nextAction].filter(Boolean).join(" "),
22
+ };
23
+ });
24
+ for (const document of documents) {
25
+ const criteria = document.parsed.fields.criteria ?? [];
26
+ for (const [index, criterion] of criteria.entries()) {
27
+ if (criteria.filter((item) => item.id === criterion.id).length !== 1) {
28
+ continue;
29
+ }
30
+ const line = document.parsed.lines[`criteria.${index}`] ?? document.parsed.lines.criteria;
31
+ enriched.push({
32
+ file: document.file,
33
+ href: `${itemUrl(document, model)}#criterion-${encodeURIComponent(criterion.id)}`,
34
+ kind: "passage",
35
+ ...(line === undefined ? {} : { line }),
36
+ text: criterion.text,
37
+ title: criterion.text,
38
+ });
39
+ }
40
+ }
41
+ return enriched;
42
+ }