@takazudo/zudo-doc 1.3.0 → 2.0.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 (49) hide show
  1. package/dist/chrome/derive.d.ts +68 -0
  2. package/dist/chrome/derive.js +231 -0
  3. package/dist/chrome/index.d.ts +37 -0
  4. package/dist/chrome/index.js +43 -0
  5. package/dist/doc-body-end/index.d.ts +9 -11
  6. package/dist/doc-body-end/index.js +4 -2
  7. package/dist/doc-content-header/index.d.ts +10 -2
  8. package/dist/doc-content-header/index.js +8 -8
  9. package/dist/doc-history-area/index.d.ts +10 -25
  10. package/dist/doc-history-area/index.js +14 -10
  11. package/dist/doc-metainfo-area/index.d.ts +9 -15
  12. package/dist/doc-metainfo-area/index.js +6 -2
  13. package/dist/doc-page-renderer/index.d.ts +11 -2
  14. package/dist/doc-page-renderer/index.js +22 -15
  15. package/dist/doc-page-shell/index.d.ts +11 -3
  16. package/dist/doc-page-shell/index.js +21 -14
  17. package/dist/doc-pager/index.d.ts +6 -7
  18. package/dist/doc-pager/index.js +2 -2
  19. package/dist/doc-route-entries/index.d.ts +22 -46
  20. package/dist/doc-route-entries/index.js +15 -10
  21. package/dist/doc-tags-area/index.d.ts +9 -19
  22. package/dist/doc-tags-area/index.js +12 -2
  23. package/dist/factory-context/index.d.ts +163 -1
  24. package/dist/footer-with-defaults/index.d.ts +12 -13
  25. package/dist/footer-with-defaults/index.js +8 -10
  26. package/dist/head-with-defaults/index.d.ts +12 -16
  27. package/dist/head-with-defaults/index.js +7 -9
  28. package/dist/header-with-defaults/index.d.ts +10 -31
  29. package/dist/header-with-defaults/index.js +15 -18
  30. package/dist/nav-source-docs/index.d.ts +20 -54
  31. package/dist/nav-source-docs/index.js +9 -10
  32. package/dist/route-context/index.d.ts +24 -0
  33. package/dist/route-context/index.js +147 -0
  34. package/dist/route-enumerators/index.d.ts +25 -74
  35. package/dist/route-enumerators/index.js +17 -18
  36. package/dist/routes/_chrome.d.ts +6 -25
  37. package/dist/routes/_chrome.js +14 -387
  38. package/dist/routes/_context.d.ts +10 -43
  39. package/dist/routes/_context.js +29 -157
  40. package/dist/sidebar-with-defaults/index.d.ts +8 -15
  41. package/dist/sidebar-with-defaults/index.js +6 -10
  42. package/dist/tag-pages/index.d.ts +12 -3
  43. package/dist/tag-pages/index.js +24 -19
  44. package/dist/versions-page/index.d.ts +10 -3
  45. package/dist/versions-page/index.js +18 -14
  46. package/eject/doc-pager/index.tsx +8 -10
  47. package/package.json +9 -1
  48. package/routes-src/_chrome.tsx +31 -552
  49. package/routes-src/_context.ts +37 -269
@@ -1,32 +1,19 @@
1
- // routes/_context — the route-context reconstruction seam (epic Package-First
2
- // Finale #2356, A1 #2361; ADR docs/adr/route-injection-seam.md, Decision 1).
1
+ // routes/_context — thin route-context shim for the package-owned route
2
+ // entrypoints (epic Package-First Finale #2356, A1 #2361; ADR
3
+ // docs/adr/route-injection-seam.md, Decision 1).
3
4
  //
4
- // Every package route entrypoint imports `{ routeContext }` from the virtual
5
- // module `virtual:zudo-doc-route-context` (SERIALIZABLE DATA ONLY: `settings`,
6
- // `translations`, `tagVocabulary`) and rebuilds the full injected context by
7
- // calling the ALREADY-EXISTING package factories with importable package
8
- // subpaths never raw host functions, never `@/` aliases. This module does
9
- // that reconstruction ONCE and exposes the wired runtime context so each
10
- // entrypoint stays a thin `paths()` + default-export shell (mirroring the kept
11
- // `pages/*.tsx` stubs).
5
+ // The reconstruction logic was PROMOTED to the public, shared
6
+ // `createRouteContext(payload)` builder (`@takazudo/zudo-doc/route-context`,
7
+ // CTX #2423). This module is now just the seam that:
8
+ // 1. imports the SERIALIZABLE payload from the virtual module
9
+ // `virtual:zudo-doc-route-context` (resolved by the routes plugin),
10
+ // 2. calls `createRouteContext` ONCE (the entrypoints share this singleton,
11
+ // preserving the per-build memo / array-identity stability), and
12
+ // 3. re-exports the named bindings each entrypoint imports.
12
13
  //
13
- // The host-dep package-subpath map this wires (ADR table):
14
- // buildNavTree/collectAutoIndexNodes/groupSatelliteNodes/isNavVisible/
15
- // findNode/firstRoutedHref/buildBreadcrumbs ... ./routes/_docs-helpers
16
- // (the package `docs` helpers, on `@takazudo/zudo-doc/sidebar-tree`)
17
- // loadCategoryMeta ........................... @takazudo/zudo-doc/sidebar-tree
18
- // extractHeadings ............................ @takazudo/zudo-doc/extract-headings
19
- // toRouteSlug/toSlugParams/toTitleCase/toHistorySlug ... @takazudo/zudo-doc/slug
20
- // resolveTag / collectTags ................... @takazudo/zudo-doc/tag-helpers
21
- // getNavSectionForSlug/getNavSubtree/getCategoryOrder .. @takazudo/zudo-doc/nav-scope
22
- // url helpers ................................ @takazudo/zudo-doc/url-helpers
23
- // mergeLocaleDocs ............................ @takazudo/zudo-doc/locale-merge
24
- // stableDocs (content bridge) ................ ./routes/_docs-helpers (zfb/content)
25
- // resolveNavSource/… ......................... @takazudo/zudo-doc/nav-source-docs
26
- // buildDocRouteEntries ....................... @takazudo/zudo-doc/doc-route-entries
27
- // route enumeration .......................... @takazudo/zudo-doc/route-enumerators
28
- // i18n (t/getLocaleLabel/defaultLocale/locales) reconstructed from settings +
29
- // translations as a FactoryI18n.
14
+ // The default content bridge (`stableDocs` reading `@takazudo/zfb/content`) is
15
+ // supplied by `createRouteContext`; this shim passes no override, so the
16
+ // injected package-routes path stays byte-identical.
30
17
 
31
18
  // Virtual module, resolved by the routes plugin at build via
32
19
  // addVirtualModule("virtual:zudo-doc-route-context", …). Not present on disk;
@@ -35,104 +22,35 @@ import { routeContext } from "virtual:zudo-doc-route-context";
35
22
 
36
23
  import type { Settings } from "@takazudo/zudo-doc/settings";
37
24
  import type { ColorScheme } from "@takazudo/zudo-doc/color-scheme-utils";
38
- import type { FactoryI18n } from "@takazudo/zudo-doc/factory-context";
39
- import { makeUrlHelpers, type UrlHelpers } from "@takazudo/zudo-doc/url-helpers";
40
25
  import {
41
- loadCategoryMeta,
42
- type CategoryMeta,
43
- } from "@takazudo/zudo-doc/sidebar-tree";
44
- import { extractHeadings as extractHeadingsBase } from "@takazudo/zudo-doc/extract-headings";
45
- import { toRouteSlug, toSlugParams } from "@takazudo/zudo-doc/slug";
46
- import { resolveTag, type TagVocabularyEntry } from "@takazudo/zudo-doc/tag-helpers";
47
- import {
48
- getCategoryOrder as getCategoryOrderBase,
49
- getNavSectionForSlug as getNavSectionForSlugBase,
50
- getNavSubtree as getNavSubtreeBase,
51
- } from "@takazudo/zudo-doc/nav-scope";
52
- import { mergeLocaleDocs } from "@takazudo/zudo-doc/locale-merge";
53
- import {
54
- createNavSourceDocs,
55
- type NavSourceDocsAPI,
56
- } from "@takazudo/zudo-doc/nav-source-docs";
57
- import {
58
- createDocRouteEntries,
59
- type DocRouteEntriesAPI,
60
- } from "@takazudo/zudo-doc/doc-route-entries";
61
- import {
62
- createRouteEnumerators,
63
- type RouteEnumeratorsAPI,
64
- type DocsEntryForTags,
65
- type TagInfoForEnum,
66
- } from "@takazudo/zudo-doc/route-enumerators";
67
- import type { DocNavNode, DocPageEntry } from "@takazudo/zudo-doc/doc-page-props";
68
- import type { HeadingItem } from "@takazudo/zudo-doc/extract-headings";
69
- import {
70
- stableDocs,
71
- isNavVisible,
72
- buildNavTree,
73
- buildBreadcrumbs,
74
- collectAutoIndexNodes,
75
- groupSatelliteNodes,
76
- findNode,
77
- firstRoutedHref,
78
- } from "./_docs-helpers.js";
79
-
80
- // ---------------------------------------------------------------------------
81
- // The serializable route-context payload (re-exported for entrypoints).
82
- // ---------------------------------------------------------------------------
26
+ createRouteContext,
27
+ type RouteContextPayload,
28
+ } from "@takazudo/zudo-doc/route-context";
83
29
 
84
- export interface RouteContextPayload {
85
- settings: Settings;
86
- translations: Record<string, Record<string, string>>;
87
- tagVocabulary: readonly TagVocabularyEntry[];
88
- colorSchemes: Record<string, ColorScheme> | null;
89
- }
30
+ export type { RouteContextPayload, TagInfo } from "@takazudo/zudo-doc/route-context";
90
31
 
91
- /** The serializable route-context (from the virtual module). */
32
+ /** The serializable route-context payload (from the virtual module). */
92
33
  export const ctx = routeContext as unknown as RouteContextPayload;
93
- export const settings: Settings = ctx.settings;
94
- const translations = ctx.translations;
95
- const tagVocabulary = ctx.tagVocabulary;
96
- /** Host color-scheme palette map. `null` when not supplied — `_chrome.tsx`
97
- * falls back to `DEFAULT_SCHEME` in that case. */
98
- export const colorSchemes: Record<string, ColorScheme> | null = ctx.colorSchemes;
99
34
 
100
- // ---------------------------------------------------------------------------
101
- // i18n reconstruct a FactoryI18n from settings + translations (Decision 1).
102
- // ---------------------------------------------------------------------------
103
-
104
- export const defaultLocale: string = settings.defaultLocale;
105
- export const locales: readonly string[] = [
106
- defaultLocale,
107
- ...Object.keys(settings.locales),
108
- ];
35
+ // Reconstruct the full runtime context ONCE — the entrypoints all import from
36
+ // this module, so they share the same memoized closures + stable arrays.
37
+ const routeCtx = createRouteContext(ctx);
109
38
 
110
- export function getLocaleConfig(locale: string): { label: string; dir: string } | undefined {
111
- return (settings.locales as Record<string, { label: string; dir: string } | undefined>)[locale];
112
- }
39
+ export { routeCtx };
113
40
 
114
- export function getLocaleLabel(locale: string): string {
115
- if (locale === defaultLocale) return defaultLocale.toUpperCase();
116
- return getLocaleConfig(locale)?.label ?? locale.toUpperCase();
117
- }
118
-
119
- export function t(key: string, locale: string = defaultLocale): string {
120
- return translations[locale]?.[key] ?? translations[defaultLocale]?.[key] ?? key;
121
- }
41
+ export const settings: Settings = routeCtx.settings;
42
+ /** Host color-scheme palette map. `null` when not supplied — `_chrome.tsx`
43
+ * falls back to `DEFAULT_SCHEME` in that case. */
44
+ export const colorSchemes: Record<string, ColorScheme> | null = routeCtx.colorSchemes;
122
45
 
123
- export const i18n: FactoryI18n = {
46
+ export const {
47
+ i18n,
124
48
  defaultLocale,
125
49
  locales,
50
+ getLocaleConfig,
126
51
  getLocaleLabel,
127
52
  t,
128
- };
129
-
130
- // ---------------------------------------------------------------------------
131
- // URL helpers (@takazudo/zudo-doc/url-helpers).
132
- // ---------------------------------------------------------------------------
133
-
134
- export const urlHelpers: UrlHelpers = makeUrlHelpers(settings, i18n);
135
- export const {
53
+ urlHelpers,
136
54
  withBase,
137
55
  stripBase,
138
56
  docsUrl,
@@ -143,170 +61,20 @@ export const {
143
61
  isExternal,
144
62
  resolveHref,
145
63
  buildLocaleLinks,
146
- } = urlHelpers;
147
-
148
- // ---------------------------------------------------------------------------
149
- // nav-scope (@takazudo/zudo-doc/nav-scope) — parameterized by settings.headerNav.
150
- // ---------------------------------------------------------------------------
151
-
152
- export function getCategoryOrder(): string[] {
153
- return getCategoryOrderBase(settings.headerNav);
154
- }
155
- export function getNavSectionForSlug(slug: string): string | undefined {
156
- return getNavSectionForSlugBase(slug, settings.headerNav);
157
- }
158
- export function getNavSubtree(tree: DocNavNode[], categoryMatch?: string): DocNavNode[] {
159
- return getNavSubtreeBase(tree, categoryMatch, settings.headerNav);
160
- }
161
-
162
- // ---------------------------------------------------------------------------
163
- // extract-headings — bound to settings depth window + id strategy.
164
- // ---------------------------------------------------------------------------
165
-
166
- export function extractHeadings(body: string): HeadingItem[] {
167
- return extractHeadingsBase(body, {
168
- tocMinDepth: settings.tocMinDepth,
169
- tocMaxDepth: settings.tocMaxDepth,
170
- strategy: settings.headingIdStrategy,
171
- });
172
- }
173
-
174
- // ---------------------------------------------------------------------------
175
- // tag-helpers — collectTags reconstructed package-side (the host version lives
176
- // in src/utils/tags.ts because it depends on the host DocsEntry; here it is
177
- // parameterized by the virtual-module tagVocabulary + settings.tagGovernance).
178
- // ---------------------------------------------------------------------------
179
-
180
- export interface TagInfo {
181
- tag: string;
182
- count: number;
183
- docs: { slug: string; title: string; description?: string }[];
184
- }
185
-
186
- function getVocab(): readonly TagVocabularyEntry[] | false {
187
- return settings.tagVocabulary ? tagVocabulary : false;
188
- }
189
-
190
- export function resolveTagBound(raw: string) {
191
- return resolveTag(raw, getVocab(), settings.tagGovernance);
192
- }
193
-
194
- export function collectTags(
195
- entries: ReadonlyArray<{ id: string; data: { slug?: string; title?: string; description?: string; tags?: string[] } }>,
196
- slugFn: (id: string, data: { slug?: string }) => string,
197
- ): Map<string, TagInfo> {
198
- const tagMap = new Map<string, TagInfo>();
199
- for (const entry of entries) {
200
- const rawTags = entry.data.tags ?? [];
201
- const slug = slugFn(entry.id, entry.data);
202
- const seen = new Set<string>();
203
- for (const raw of rawTags) {
204
- const resolved = resolveTagBound(raw);
205
- if (resolved.deprecated) continue;
206
- if (seen.has(resolved.canonical)) continue;
207
- seen.add(resolved.canonical);
208
- if (!tagMap.has(resolved.canonical)) {
209
- tagMap.set(resolved.canonical, { tag: resolved.canonical, count: 0, docs: [] });
210
- }
211
- const info = tagMap.get(resolved.canonical)!;
212
- info.count++;
213
- info.docs.push({
214
- slug,
215
- title: entry.data.title ?? "",
216
- description: entry.data.description,
217
- });
218
- }
219
- }
220
- return tagMap;
221
- }
222
-
223
- // ---------------------------------------------------------------------------
224
- // Nav-source resolver (@takazudo/zudo-doc/nav-source-docs).
225
- // ---------------------------------------------------------------------------
226
-
227
- const navSourceDocs: NavSourceDocsAPI = createNavSourceDocs({
228
- defaultLocale,
229
- docsDir: settings.docsDir,
230
- getVersions: () => settings.versions,
231
- getLocaleConfig,
232
- loadCategoryMeta: loadCategoryMeta as (dir: string) => Map<string, CategoryMeta>,
233
- isNavVisible,
234
- isDefaultLocaleOnlyPath,
235
- stableDocs,
236
- });
237
-
238
- export const {
239
- resolveNavSource,
240
- resolveVersionedLocaleSource,
241
- loadNavSourceDocs,
242
- } = navSourceDocs;
243
-
244
- // ---------------------------------------------------------------------------
245
- // doc-route-entries (@takazudo/zudo-doc/doc-route-entries).
246
- // ---------------------------------------------------------------------------
247
-
248
- const docRouteEntries: DocRouteEntriesAPI = createDocRouteEntries({
249
- buildNavTree: (docs: DocPageEntry[], locale: string, categoryMeta: Map<string, unknown>) =>
250
- buildNavTree(
251
- docs,
252
- locale,
253
- categoryMeta as Map<string, CategoryMeta>,
254
- (slug, loc) => docsUrl(slug, loc),
255
- ),
256
- buildBreadcrumbs: (tree: DocNavNode[], slug: string, locale: string, urlFor?: (slug: string) => string) =>
257
- buildBreadcrumbs(
258
- tree,
259
- slug,
260
- locale === defaultLocale ? withBase("/") : withBase(`/${locale}/`),
261
- urlFor,
262
- ),
263
- collectAutoIndexNodes,
64
+ getCategoryOrder,
264
65
  getNavSectionForSlug,
265
66
  getNavSubtree,
266
- toRouteSlug,
267
- toSlugParams,
268
67
  extractHeadings,
269
- });
270
-
271
- export const { buildDocRouteEntries } = docRouteEntries;
272
-
273
- // ---------------------------------------------------------------------------
274
- // route-enumerators (@takazudo/zudo-doc/route-enumerators).
275
- // ---------------------------------------------------------------------------
276
-
277
- const routeEnumerators: RouteEnumeratorsAPI = createRouteEnumerators({
278
- defaultLocale,
279
- getLocaleKeys: () => Object.keys(settings.locales),
280
- getVersions: () => settings.versions,
281
- getDocTags: () => settings.docTags,
282
- docsUrl,
283
- versionedDocsUrl,
284
- withBase,
285
- loadDocs: (collectionName: string) => stableDocs(collectionName) as unknown as DocsEntryForTags[],
286
- isDefaultLocaleOnlyPath,
287
- collectTags: (docs: DocsEntryForTags[], slugFn): Map<string, TagInfoForEnum> =>
288
- collectTags(docs as unknown as Array<{ id: string; data: { slug?: string; title?: string; description?: string; tags?: string[] } }>, slugFn) as unknown as Map<string, TagInfoForEnum>,
289
- toRouteSlug,
290
- buildNavTree: (docs: DocPageEntry[], locale: string, categoryMeta: Map<string, unknown>) =>
291
- buildNavTree(docs, locale, categoryMeta as Map<string, CategoryMeta>, (slug, loc) => docsUrl(slug, loc)),
292
- collectAutoIndexNodes,
68
+ resolveTagBound,
69
+ collectTags,
293
70
  resolveNavSource,
294
71
  resolveVersionedLocaleSource,
295
- mergeLocaleDocs: mergeLocaleDocs as RouteEnumeratorsAPIDeps["mergeLocaleDocs"],
296
- });
297
-
298
- // Local alias so the `mergeLocaleDocs` cast above reads clearly.
299
- type RouteEnumeratorsAPIDeps = Parameters<typeof createRouteEnumerators>[0];
300
-
301
- export const {
72
+ loadNavSourceDocs,
73
+ buildDocRouteEntries,
302
74
  enumerateDocsRoutes,
303
75
  enumerateTagsRoutes,
304
76
  enumerateVersionedRoutes,
305
77
  enumerateAllRoutes,
306
- } = routeEnumerators;
307
-
308
- // Re-export the pure nav-tree helpers entrypoints reach for directly.
309
- export {
310
78
  buildNavTree,
311
79
  groupSatelliteNodes,
312
80
  findNode,
@@ -316,4 +84,4 @@ export {
316
84
  stableDocs,
317
85
  toRouteSlug,
318
86
  toSlugParams,
319
- };
87
+ } = routeCtx;