dommief 0.0.0-stage → 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.
@@ -0,0 +1,326 @@
1
+ import { z } from 'zod';
2
+ import { R as Route, a as RouteConfig, b as RouteTable, c as ResolvedLocale } from './types-zwMRCGy9.js';
3
+ import { NavItem, SidebarGroup } from './theme-api.js';
4
+ export { d as SiteData } from './types-zwMRCGy9.js';
5
+
6
+ interface BuildEndContext {
7
+ config: ResolvedConfig;
8
+ outDir: string;
9
+ routes?: Route[];
10
+ }
11
+ type DommiefPluginObject = {
12
+ name?: string;
13
+ /** Đồng bộ: hook phải được `tap` xong trước khi hàm trả về. */
14
+ setup?: (hooks: PluginHookHost) => void;
15
+ modifyConfig?: (config: unknown) => unknown;
16
+ modifyRoutes?: (routes: Route[]) => Route[] | void;
17
+ addRemarkPlugins?: () => unknown | unknown[];
18
+ addRehypePlugins?: () => unknown | unknown[];
19
+ addHtmlHeadTags?: () => string | string[] | void;
20
+ onBuildEnd?: (ctx: BuildEndContext) => void | Promise<void>;
21
+ };
22
+ type PluginSetup = (hooks: PluginHookHost) => void;
23
+ type DommiefPlugin = DommiefPluginObject | PluginSetup;
24
+ declare class Hook<TArg = unknown, TResult = unknown> {
25
+ name: string;
26
+ constructor(name?: string);
27
+ taps: {
28
+ name: string;
29
+ fn: (arg: TArg) => TResult | void | Promise<TResult | void>;
30
+ }[];
31
+ tap(name: string, fn: (arg: TArg) => TResult | void | Promise<TResult | void>): void;
32
+ call(arg: TArg): TArg;
33
+ callAsync(arg: TArg): Promise<TArg>;
34
+ }
35
+ declare class PluginHookHost {
36
+ modifyConfig: Hook<unknown, unknown>;
37
+ modifyRoutes: Hook<Route[], Route[]>;
38
+ addRemarkPlugins: Hook<void, unknown[]>;
39
+ addRehypePlugins: Hook<void, unknown[]>;
40
+ addHtmlHeadTags: Hook<void, string | string[]>;
41
+ onBuildEnd: Hook<BuildEndContext, void>;
42
+ applyModifyConfig(config: unknown): Record<string, unknown>;
43
+ applyModifyRoutes(routes: Route[]): Route[];
44
+ collectRemarkPlugins(): unknown[];
45
+ collectRehypePlugins(): unknown[];
46
+ collectHtmlHeadTags(): string[];
47
+ runBuildEnd(ctx: BuildEndContext): Promise<void>;
48
+ }
49
+ declare function registerPlugin(host: PluginHookHost, plugin: DommiefPlugin | null | undefined): void;
50
+ declare function createPluginHost(plugins?: unknown[]): PluginHookHost;
51
+ declare function definePlugin(plugin: DommiefPlugin): DommiefPlugin;
52
+
53
+ declare const ConfigSchema: z.ZodObject<{
54
+ title: z.ZodDefault<z.ZodString>;
55
+ description: z.ZodOptional<z.ZodString>;
56
+ base: z.ZodDefault<z.ZodString>;
57
+ outDir: z.ZodDefault<z.ZodString>;
58
+ srcDir: z.ZodDefault<z.ZodString>;
59
+ preset: z.ZodDefault<z.ZodEnum<{
60
+ docs: "docs";
61
+ library: "library";
62
+ }>>;
63
+ docDirs: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
64
+ dir: z.ZodString;
65
+ }, z.core.$strip>]>>>;
66
+ forceKebabCase: z.ZodDefault<z.ZodBoolean>;
67
+ locales: z.ZodDefault<z.ZodArray<z.ZodObject<{
68
+ id: z.ZodString;
69
+ name: z.ZodOptional<z.ZodString>;
70
+ base: z.ZodOptional<z.ZodString>;
71
+ suffix: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$strip>>>;
73
+ themeConfig: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
74
+ theme: z.ZodDefault<z.ZodString>;
75
+ ssg: z.ZodDefault<z.ZodObject<{
76
+ concurrency: z.ZodDefault<z.ZodNumber>;
77
+ exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
78
+ noEmit: z.ZodDefault<z.ZodArray<z.ZodString>>;
79
+ }, z.core.$strip>>;
80
+ cache: z.ZodDefault<z.ZodBoolean>;
81
+ linkCheck: z.ZodDefault<z.ZodBoolean>;
82
+ dev: z.ZodDefault<z.ZodObject<{
83
+ port: z.ZodDefault<z.ZodNumber>;
84
+ }, z.core.$strip>>;
85
+ sitemap: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
86
+ hostname: z.ZodString;
87
+ exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
88
+ }, z.core.$strip>]>>;
89
+ robots: z.ZodOptional<z.ZodBoolean>;
90
+ markdown: z.ZodDefault<z.ZodObject<{
91
+ shiki: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
92
+ themes: z.ZodObject<{
93
+ light: z.ZodString;
94
+ dark: z.ZodString;
95
+ }, z.core.$strip>;
96
+ }, z.core.$strip>]>>;
97
+ lineNumbers: z.ZodDefault<z.ZodBoolean>;
98
+ }, z.core.$strip>>;
99
+ search: z.ZodDefault<z.ZodObject<{
100
+ enabled: z.ZodDefault<z.ZodBoolean>;
101
+ }, z.core.$strip>>;
102
+ plugins: z.ZodDefault<z.ZodArray<z.ZodAny>>;
103
+ }, z.core.$strict>;
104
+ /** What the user writes in dommief.config.ts (input type: optional fields, locale union fields). */
105
+ type UserConfig = z.input<typeof ConfigSchema>;
106
+ interface ResolvedConfig extends RouteConfig {
107
+ /** Absolute cwd the config was resolved against. */
108
+ root: string;
109
+ title: string;
110
+ description?: string;
111
+ base: string;
112
+ outDir: string;
113
+ themeConfig: Record<string, unknown>;
114
+ theme: string;
115
+ ssg: {
116
+ concurrency: number;
117
+ exclude: string[];
118
+ noEmit: string[];
119
+ };
120
+ cache: boolean;
121
+ linkCheck: boolean;
122
+ dev: {
123
+ port: number;
124
+ };
125
+ sitemap: false | {
126
+ hostname: string;
127
+ exclude: string[];
128
+ };
129
+ robots: boolean;
130
+ search: {
131
+ enabled: boolean;
132
+ };
133
+ markdown: {
134
+ shiki: false | {
135
+ themes: {
136
+ light: string;
137
+ dark: string;
138
+ };
139
+ };
140
+ lineNumbers: boolean;
141
+ };
142
+ plugins?: DommiefPlugin[];
143
+ }
144
+ interface ResolveOptions {
145
+ cwd: string;
146
+ cli?: {
147
+ base?: string | undefined;
148
+ outDir?: string | undefined;
149
+ cache?: boolean | undefined;
150
+ linkCheck?: boolean | undefined;
151
+ };
152
+ env?: Record<string, string | undefined>;
153
+ /** Path of the loaded config file; only used to name the source in errors. */
154
+ configFile?: string | undefined;
155
+ }
156
+ declare function defineConfig(config: UserConfig): UserConfig;
157
+ declare function loadConfigFile(opts: {
158
+ cwd: string;
159
+ configPath?: string;
160
+ }): Promise<{
161
+ path: string;
162
+ config: UserConfig;
163
+ } | null>;
164
+ declare function resolveConfig(userConfig: UserConfig, opts: ResolveOptions): ResolvedConfig;
165
+ /** Load file at `root` + resolve with process env (and optional CLI flags). */
166
+ declare function loadConfig(root: string, cli?: ResolveOptions['cli']): Promise<ResolvedConfig>;
167
+
168
+ /** Điểm vào duy nhất của tầng route: scan → normalize → sort → map tra cứu. JSON-safe. */
169
+ declare function buildRouteTable({ cwd, config, hooks, plugins }: {
170
+ cwd: string;
171
+ config: RouteConfig;
172
+ hooks?: PluginHookHost;
173
+ plugins?: unknown[];
174
+ }): RouteTable;
175
+
176
+ type FrontmatterMap = Record<string, Record<string, unknown>>;
177
+ declare function buildNav(routes: Route[], frontmatter?: FrontmatterMap, locales?: ResolvedLocale[]): Record<string, NavItem[]>;
178
+ declare function buildSidebar(routes: Route[], frontmatter?: FrontmatterMap, locales?: ResolvedLocale[]): Record<string, SidebarGroup[]>;
179
+ interface PaginationResult {
180
+ prev?: Route;
181
+ next?: Route;
182
+ }
183
+ declare function paginate(routes: Route[], currentPath: string): PaginationResult;
184
+ /** @deprecated dùng `parseFrontmatterYaml` (yaml thật). Giữ lại cho tương thích export cũ, cùng chung một parser (#12). */
185
+ declare function parseFrontmatter(fileContent: string): Record<string, unknown>;
186
+
187
+ interface ShikiOptions {
188
+ themes: {
189
+ light: string;
190
+ dark: string;
191
+ };
192
+ }
193
+ interface RehypeCodeOptions {
194
+ /** `false` = tắt Shiki (code block giữ `<pre><code>` thô). */
195
+ shiki?: ShikiOptions | false;
196
+ lineNumbers?: boolean;
197
+ }
198
+
199
+ interface TocItem {
200
+ id: string;
201
+ depth: number;
202
+ title: string;
203
+ }
204
+ interface TextFragment {
205
+ type?: 'content' | 'title';
206
+ value: string;
207
+ paraId?: number;
208
+ tocIndex?: number;
209
+ }
210
+ interface PageMeta {
211
+ frontmatter: Record<string, unknown>;
212
+ toc: TocItem[];
213
+ texts: TextFragment[];
214
+ }
215
+ interface TransformMarkdownOptions {
216
+ remarkPlugins?: unknown[];
217
+ rehypePlugins?: unknown[];
218
+ hooks?: PluginHookHost;
219
+ plugins?: unknown[];
220
+ /** file md tuyệt đối → route; để `rehypeLink` đổi `./x.md` thành path route thật. */
221
+ byFile?: Record<string, {
222
+ path: string;
223
+ }>;
224
+ /** `config.base` để gắn tiền tố cho link nội bộ. */
225
+ base?: string;
226
+ /** `config.markdown` (shiki + lineNumbers), DM-706. */
227
+ code?: RehypeCodeOptions;
228
+ }
229
+ declare function transformMarkdown(source: string, file: string, opts?: TransformMarkdownOptions): Promise<{
230
+ code: string;
231
+ meta: PageMeta;
232
+ warnings: string[];
233
+ apiSrcFiles: string[];
234
+ demos: {
235
+ id: string;
236
+ source: string;
237
+ }[];
238
+ }>;
239
+
240
+ interface ApiProp {
241
+ name: string;
242
+ type?: string;
243
+ required?: boolean;
244
+ description?: string;
245
+ defaultValue?: any;
246
+ }
247
+ interface ApiEntry {
248
+ displayName: string;
249
+ description?: string;
250
+ props: ApiProp[];
251
+ src: string;
252
+ hash: string;
253
+ }
254
+ declare function clearApiCache(): void;
255
+ declare function hashFileContent(content: string): string;
256
+ declare function buildApiTable(src: string, filePath?: string): ApiEntry[] | null;
257
+ declare function rehypeApi(): (tree: any, file: any) => void;
258
+
259
+ declare class DommiefError extends Error {
260
+ file: string;
261
+ line?: number | undefined;
262
+ col?: number | undefined;
263
+ code?: string | undefined;
264
+ layout?: string | undefined;
265
+ constructor(message: string, opts?: {
266
+ file?: string;
267
+ line?: number;
268
+ col?: number;
269
+ code?: string;
270
+ layout?: string;
271
+ });
272
+ format(): string;
273
+ toString(): string;
274
+ }
275
+ declare function formatError(err: unknown): string;
276
+
277
+ interface Logger {
278
+ verbose: boolean;
279
+ info(msg: string): void;
280
+ debug(msg: string): void;
281
+ warn(msg: string): void;
282
+ error(msg: string): void;
283
+ }
284
+ declare function createLogger(verbose?: boolean): Logger;
285
+
286
+ interface MiniSearchConfig {
287
+ tokenize: (text: string) => string[];
288
+ processTerm: (term: string) => string | null;
289
+ }
290
+ declare function createMiniSearchConfig(): MiniSearchConfig;
291
+
292
+ declare const INDEX_BUDGET_BYTES_PER_PAGE: number;
293
+
294
+ interface SearchDocument {
295
+ id: string;
296
+ routeId: string;
297
+ path: string;
298
+ pageTitle: string;
299
+ sectionTitle: string;
300
+ paraId: number;
301
+ value: string;
302
+ pageKey: string;
303
+ sectionKey: string;
304
+ }
305
+ interface BuildSearchIndexOptions {
306
+ routes: Route[];
307
+ loadPageMeta: (route: Route) => PageMeta | Promise<PageMeta>;
308
+ config: {
309
+ locales: ResolvedLocale[];
310
+ };
311
+ }
312
+ interface BuildSearchIndexResult {
313
+ locales: Record<string, unknown>;
314
+ stats: Record<string, {
315
+ docs: number;
316
+ bytes: number;
317
+ pages: number;
318
+ }>;
319
+ manifest: {
320
+ locales: Record<string, string>;
321
+ };
322
+ }
323
+ declare function buildSearchIndex(opts: BuildSearchIndexOptions): Promise<BuildSearchIndexResult>;
324
+
325
+ export { DommiefError, Hook, INDEX_BUDGET_BYTES_PER_PAGE, PluginHookHost, PluginHookHost as PluginHooks, ResolvedLocale, Route, RouteConfig, RouteTable, buildApiTable, buildNav, buildRouteTable, buildSearchIndex, buildSidebar, clearApiCache, createLogger, createMiniSearchConfig, createPluginHost, defineConfig, definePlugin, formatError, hashFileContent, loadConfig, loadConfigFile, paginate, parseFrontmatter, registerPlugin, rehypeApi, resolveConfig, transformMarkdown };
326
+ export type { ApiEntry, ApiProp, BuildEndContext, BuildSearchIndexOptions, BuildSearchIndexResult, DommiefPlugin, DommiefPluginObject, FrontmatterMap, Logger, MiniSearchConfig, PageMeta, PaginationResult, PluginSetup, ResolvedConfig, SearchDocument, TextFragment, TocItem, UserConfig };