@ox-content/napi 2.8.0 → 2.10.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 (3) hide show
  1. package/index.d.ts +222 -13
  2. package/index.js +20 -0
  3. package/package.json +6 -6
package/index.d.ts CHANGED
@@ -7,6 +7,12 @@
7
7
  */
8
8
  export declare function buildSearchIndex(documents: Array<JsSearchDocument>): string
9
9
 
10
+ /** Builds SSG navigation groups from markdown files. */
11
+ export declare function buildSsgNavItems(markdownFiles: Array<string>, srcDir: string, base: string, extension: string): Array<JsSsgNavGroup>
12
+
13
+ /** Builds SSG navigation groups from an explicit theme sidebar tree. */
14
+ export declare function buildSsgThemeNavItems(sidebar: Array<JsSsgSidebarItem>, base: string, extension: string): Array<JsSsgNavGroup>
15
+
10
16
  /**
11
17
  * Runs i18n checks on dictionaries against used translation keys.
12
18
  *
@@ -15,6 +21,12 @@ export declare function buildSearchIndex(documents: Array<JsSearchDocument>): st
15
21
  */
16
22
  export declare function checkI18n(dictDir: string, usedKeys: Array<string>): I18NCheckResult
17
23
 
24
+ /** Extracts shared CSS and JavaScript assets from generated SSG pages. */
25
+ export declare function externalizeSsgAssets(pages: Array<JsSsgGeneratedHtmlPage>, outDir: string, base: string): JsSsgExternalizedAssets
26
+
27
+ /** Extracts normalized documentation entries from a JavaScript/TypeScript file using Oxc. */
28
+ export declare function extractFileDocEntries(filePath: string, includePrivate?: boolean | undefined | null): Array<JsDocEntry>
29
+
18
30
  /** Extracts documented declarations from a JavaScript/TypeScript file using Oxc. */
19
31
  export declare function extractFileDocs(filePath: string, includePrivate?: boolean | undefined | null): Array<JsSourceDocItem>
20
32
 
@@ -25,6 +37,9 @@ export declare function extractFileDocs(filePath: string, includePrivate?: boole
25
37
  */
26
38
  export declare function extractSearchContent(source: string, id: string, url: string, options?: JsParserOptions | undefined | null): JsSearchDocument
27
39
 
40
+ /** Extracts a page title from frontmatter title or rendered HTML. */
41
+ export declare function extractSsgTitle(content: string, frontmatterTitle?: string | undefined | null): string
42
+
28
43
  /**
29
44
  * Extracts translation keys from a TypeScript/JavaScript source string.
30
45
  *
@@ -32,6 +47,18 @@ export declare function extractSearchContent(source: string, id: string, url: st
32
47
  */
33
48
  export declare function extractTranslationKeys(source: string, filePath: string, functionNames?: Array<string> | undefined | null): Array<I18NKeyUsage>
34
49
 
50
+ /** Formats a file or directory segment as an SSG title. */
51
+ export declare function formatSsgTitle(name: string): string
52
+
53
+ /** Generates TypeScript source code for documentation navigation metadata. */
54
+ export declare function generateDocsNavCode(navItems: Array<JsDocsNavItem>, exportName?: string | undefined | null): string
55
+
56
+ /** Generates sidebar navigation metadata from documentation file paths. */
57
+ export declare function generateDocsNavMetadata(files: Array<string>, basePath?: string | undefined | null): Array<JsDocsNavItem>
58
+
59
+ /** Generates the `virtual:ox-content/i18n` runtime module. */
60
+ export declare function generateI18nModule(dictDir: string, config: JsI18NRuntimeConfig): string
61
+
35
62
  /**
36
63
  * Generates an OG image as SVG.
37
64
  *
@@ -40,12 +67,30 @@ export declare function extractTranslationKeys(source: string, filePath: string,
40
67
  */
41
68
  export declare function generateOgImageSvg(data: JsOgImageData, config?: JsOgImageConfig | undefined | null): string
42
69
 
70
+ /** Generates the client-side search runtime module. */
71
+ export declare function generateSearchModule(optionsJson: string, indexPath: string): string
72
+
43
73
  /** Generates SSG HTML page with navigation and search. */
44
74
  export declare function generateSsgHtml(pageData: JsSsgPageData, navGroups: Array<JsSsgNavGroup>, config: JsSsgConfig): string
45
75
 
46
76
  /** Returns the last git commit timestamp for a file in milliseconds. */
47
77
  export declare function getGitLastUpdated(filePath: string, root?: string | undefined | null): number | null
48
78
 
79
+ /** Derives hierarchical search scopes from a document id or URL. */
80
+ export declare function getSearchDocumentScopes(id: string, url: string): Array<string>
81
+
82
+ /** Converts a markdown file path to an SSG href. */
83
+ export declare function getSsgHref(inputPath: string, srcDir: string, base: string, extension: string): string
84
+
85
+ /** Converts a markdown file path to its corresponding SSG HTML output path. */
86
+ export declare function getSsgOutputPath(inputPath: string, srcDir: string, outDir: string, extension: string): string
87
+
88
+ /** Resolves a page locale from an SSG URL path and configured locale codes. */
89
+ export declare function getSsgPageLocale(urlPath: string, defaultLocale: string, localeCodes: Array<string>): string | null
90
+
91
+ /** Converts a markdown file path to a relative SSG URL path. */
92
+ export declare function getSsgUrlPath(inputPath: string, srcDir: string): string
93
+
49
94
  /** Result of i18n checking. */
50
95
  export interface I18NCheckResult {
51
96
  /** All diagnostics. */
@@ -92,6 +137,44 @@ export interface I18NLoadResult {
92
137
  errors: Array<string>
93
138
  }
94
139
 
140
+ /** Normalized documentation entry used by generated API docs. */
141
+ export interface JsDocEntry {
142
+ name: string
143
+ kind: string
144
+ description: string
145
+ params?: Array<JsDocParam>
146
+ returns?: JsDocReturn
147
+ examples?: Array<string>
148
+ tags?: Record<string, string>
149
+ private: boolean
150
+ file: string
151
+ line: number
152
+ endLine: number
153
+ signature?: string
154
+ }
155
+
156
+ /** Normalized parameter documentation used by generated API docs. */
157
+ export interface JsDocParam {
158
+ name: string
159
+ type: string
160
+ description: string
161
+ optional?: boolean
162
+ default?: string
163
+ }
164
+
165
+ /** Normalized return documentation used by generated API docs. */
166
+ export interface JsDocReturn {
167
+ type: string
168
+ description: string
169
+ }
170
+
171
+ /** Navigation item emitted for generated documentation. */
172
+ export interface JsDocsNavItem {
173
+ title: string
174
+ path: string
175
+ children?: Array<JsDocsNavItem>
176
+ }
177
+
95
178
  /** Entry page configuration. */
96
179
  export interface JsEntryPageConfig {
97
180
  /** Hero section. */
@@ -164,6 +247,26 @@ export interface JsHeroNotice {
164
247
  body?: Array<string>
165
248
  }
166
249
 
250
+ /** Configuration for generated i18n runtime modules. */
251
+ export interface JsI18NRuntimeConfig {
252
+ /** Default locale tag. */
253
+ defaultLocale: string
254
+ /** Available locales. */
255
+ locales: Array<JsI18NRuntimeLocale>
256
+ /** Whether URLs should omit the default locale prefix. */
257
+ hideDefaultLocale: boolean
258
+ }
259
+
260
+ /** Locale metadata for generated i18n runtime modules. */
261
+ export interface JsI18NRuntimeLocale {
262
+ /** BCP 47 locale tag. */
263
+ code: string
264
+ /** Display name for this locale. */
265
+ name: string
266
+ /** Text direction. */
267
+ dir?: string
268
+ }
269
+
167
270
  /** Locale information for the locale switcher. */
168
271
  export interface JsLocaleInfo {
169
272
  /** BCP 47 locale tag. */
@@ -265,6 +368,14 @@ export interface JsParserOptions {
265
368
  autolinks?: boolean
266
369
  }
267
370
 
371
+ /** Search query split into free text and scope prefixes. */
372
+ export interface JsScopedSearchQuery {
373
+ /** Free-text terms after removing scope prefixes. */
374
+ text: string
375
+ /** Deduplicated lowercase scopes. */
376
+ scopes: Array<string>
377
+ }
378
+
268
379
  /** Search document for JavaScript. */
269
380
  export interface JsSearchDocument {
270
381
  /** Unique document identifier. */
@@ -309,18 +420,6 @@ export interface JsSearchResult {
309
420
  snippet: string
310
421
  }
311
422
 
312
- /** Social links for JavaScript. */
313
- export interface JsSocialLinks {
314
- /** GitHub URL. */
315
- github?: string
316
- /** Twitter/X URL. */
317
- twitter?: string
318
- /** Discord URL. */
319
- discord?: string
320
- /** Custom social links. */
321
- links?: Array<JsSocialLink>
322
- }
323
-
324
423
  /** Custom social link for JavaScript. */
325
424
  export interface JsSocialLink {
326
425
  /** Icon label. */
@@ -333,6 +432,18 @@ export interface JsSocialLink {
333
432
  ariaLabel?: string
334
433
  }
335
434
 
435
+ /** Social links for JavaScript. */
436
+ export interface JsSocialLinks {
437
+ /** GitHub URL. */
438
+ github?: string
439
+ /** Twitter/X URL. */
440
+ twitter?: string
441
+ /** Discord URL. */
442
+ discord?: string
443
+ /** Custom social links. */
444
+ links?: Array<JsSocialLink>
445
+ }
446
+
336
447
  /** Source documentation item extracted from a JS/TS file. */
337
448
  export interface JsSourceDocItem {
338
449
  name: string
@@ -364,6 +475,12 @@ export interface JsSourceDocTag {
364
475
  value: string
365
476
  }
366
477
 
478
+ /** Source preparation options for JavaScript. */
479
+ export interface JsSourceOptions {
480
+ /** Parse YAML frontmatter before returning the content payload. */
481
+ frontmatter?: boolean
482
+ }
483
+
367
484
  /** SSG configuration. */
368
485
  export interface JsSsgConfig {
369
486
  /** Site name. */
@@ -380,6 +497,24 @@ export interface JsSsgConfig {
380
497
  availableLocales?: Array<JsLocaleInfo>
381
498
  }
382
499
 
500
+ /** Result of SSG shared asset extraction. */
501
+ export interface JsSsgExternalizedAssets {
502
+ /** HTML pages with inline assets replaced. */
503
+ pages: Array<JsSsgGeneratedHtmlPage>
504
+ /** Extracted shared assets. */
505
+ assets: Array<JsSsgSharedAsset>
506
+ }
507
+
508
+ /** Generated SSG HTML page for shared asset extraction. */
509
+ export interface JsSsgGeneratedHtmlPage {
510
+ /** Source Markdown path. */
511
+ inputPath: string
512
+ /** Output HTML path. */
513
+ outputPath: string
514
+ /** HTML content. */
515
+ html: string
516
+ }
517
+
383
518
  /** Navigation group for SSG. */
384
519
  export interface JsSsgNavGroup {
385
520
  /** Group title. */
@@ -419,6 +554,42 @@ export interface JsSsgPageData {
419
554
  entryPage?: JsEntryPageConfig
420
555
  }
421
556
 
557
+ /** Resolved SSG output and public route paths. */
558
+ export interface JsSsgRoutePaths {
559
+ /** HTML output file path. */
560
+ outputPath: string
561
+ /** Route path without extension. */
562
+ urlPath: string
563
+ /** Public HTML href. */
564
+ href: string
565
+ /** OG image output file path. */
566
+ ogImagePath: string
567
+ /** OG image public URL. */
568
+ ogImageUrl: string
569
+ }
570
+
571
+ /** Shared SSG asset extracted from generated pages. */
572
+ export interface JsSsgSharedAsset {
573
+ /** Output file path. */
574
+ outputPath: string
575
+ /** Public URL path used from HTML. */
576
+ publicPath: string
577
+ /** Asset content. */
578
+ content: string
579
+ }
580
+
581
+ /** Theme sidebar item for SSG navigation generation. */
582
+ export interface JsSsgSidebarItem {
583
+ /** Display text. */
584
+ text?: string
585
+ /** Link URL or route path. */
586
+ link?: string
587
+ /** Child sidebar items. */
588
+ items?: Array<JsSsgSidebarItem>
589
+ /** Whether this group is collapsed by default. */
590
+ collapsed?: boolean
591
+ }
592
+
422
593
  /** Theme colors for JavaScript. */
423
594
  export interface JsThemeColors {
424
595
  /** Primary accent color. */
@@ -551,6 +722,8 @@ export interface JsTransformOptions {
551
722
  strikethrough?: boolean
552
723
  /** Enable autolinks. */
553
724
  autolinks?: boolean
725
+ /** Parse YAML frontmatter before transforming. */
726
+ frontmatter?: boolean
554
727
  /** Maximum TOC depth (1-6). */
555
728
  tocMaxDepth?: number
556
729
  /** Convert `.md` links to `.html` links for SSG output. */
@@ -589,6 +762,9 @@ export declare function loadDictionaries(dir: string): I18NLoadResult
589
762
  */
590
763
  export declare function loadDictionariesFlat(dir: string): Record<string, Record<string, string>>
591
764
 
765
+ /** Returns true when a document belongs to at least one requested search scope. */
766
+ export declare function matchesSearchScopes(id: string, url: string, scopes: Array<string>): boolean
767
+
592
768
  /** Restores code block metadata after JavaScript-side syntax highlighting. */
593
769
  export declare function mergeHighlightedCodeBlocks(originalHtml: string, highlightedHtml: string): string
594
770
 
@@ -613,7 +789,7 @@ export interface Mf2ValidateResult {
613
789
  /**
614
790
  * Parses Markdown source into an AST.
615
791
  *
616
- * Returns the AST as a JSON string for zero-copy transfer to JavaScript.
792
+ * Returns the AST as a JSON string for compatibility-oriented JavaScript consumers.
617
793
  */
618
794
  export declare function parse(source: string, options?: JsParserOptions | undefined | null): ParseResult
619
795
 
@@ -623,6 +799,9 @@ export declare function parseAndRender(source: string, options?: JsParserOptions
623
799
  /** Parses Markdown and renders to HTML asynchronously (runs on worker thread). */
624
800
  export declare function parseAndRenderAsync(source: string, options?: JsParserOptions | undefined | null): Promise<unknown>
625
801
 
802
+ /** Parses Markdown source into a raw mdast memory block for JavaScript-side deserialization. */
803
+ export declare function parseMdastRaw(source: string, options?: JsParserOptions | undefined | null): Uint8Array
804
+
626
805
  /** Parse result containing the AST as JSON. */
627
806
  export interface ParseResult {
628
807
  /** The AST as a JSON string. */
@@ -631,6 +810,25 @@ export interface ParseResult {
631
810
  errors: Array<string>
632
811
  }
633
812
 
813
+ /** Splits a search query into free-text terms and `@scope` prefixes. */
814
+ export declare function parseScopedSearchQuery(query: string): JsScopedSearchQuery
815
+
816
+ /**
817
+ * Parses Markdown source into a transfer buffer identified by payload kind.
818
+ *
819
+ * Today `mdast` is the primary supported payload. Future payload kinds such as
820
+ * markdown-it token streams will share the same transfer envelope.
821
+ */
822
+ export declare function parseTransferRaw(source: string, kind: string, options?: JsParserOptions | undefined | null): Uint8Array
823
+
824
+ /**
825
+ * Splits Markdown source into content and frontmatter in a raw transfer buffer.
826
+ *
827
+ * This is used by JavaScript-side markdown-it and custom unified parser paths so
828
+ * frontmatter stripping can stay on the Rust side even when parsing continues in JS.
829
+ */
830
+ export declare function prepareSourceRaw(source: string, options?: JsSourceOptions | undefined | null): Uint8Array
831
+
634
832
  /** Renders an AST (provided as JSON) to HTML. */
635
833
  export declare function render(astJson: string): RenderResult
636
834
 
@@ -642,6 +840,9 @@ export interface RenderResult {
642
840
  errors: Array<string>
643
841
  }
644
842
 
843
+ /** Resolves all output and public route paths for an SSG page. */
844
+ export declare function resolveSsgRoutePaths(inputPath: string, srcDir: string, outDir: string, base: string, extension: string, siteUrl?: string | undefined | null): JsSsgRoutePaths
845
+
645
846
  /**
646
847
  * Searches a serialized index.
647
848
  *
@@ -670,6 +871,14 @@ export declare function transform(source: string, options?: JsTransformOptions |
670
871
  /** Transforms Markdown source asynchronously (runs on worker thread). */
671
872
  export declare function transformAsync(source: string, options?: JsTransformOptions | undefined | null): Promise<unknown>
672
873
 
874
+ /**
875
+ * Transforms Markdown into a raw mdast transfer buffer.
876
+ *
877
+ * This keeps frontmatter parsing and mdast generation on the Rust side and
878
+ * transfers a single external memory block to JavaScript for deserialization.
879
+ */
880
+ export declare function transformMdastRaw(source: string, options?: JsTransformOptions | undefined | null): Uint8Array
881
+
673
882
  /**
674
883
  * Transforms mermaid code blocks in HTML to rendered SVG diagrams.
675
884
  *
package/index.js CHANGED
@@ -70,6 +70,8 @@ const binding = loadBinding();
70
70
  // Export individual functions for ESM compatibility
71
71
  module.exports = binding;
72
72
  module.exports.parse = binding.parse;
73
+ module.exports.parseTransferRaw = binding.parseTransferRaw;
74
+ module.exports.parseMdastRaw = binding.parseMdastRaw;
73
75
  module.exports.parseAndRender = binding.parseAndRender;
74
76
  module.exports.parseAndRenderAsync = binding.parseAndRenderAsync;
75
77
  module.exports.lintMarkdown = binding.lintMarkdown;
@@ -79,14 +81,32 @@ module.exports.transform = binding.transform;
79
81
  module.exports.transformAsync = binding.transformAsync;
80
82
  module.exports.version = binding.version;
81
83
  module.exports.extractFileDocs = binding.extractFileDocs;
84
+ module.exports.extractFileDocEntries = binding.extractFileDocEntries;
85
+ module.exports.generateDocsNavMetadata = binding.generateDocsNavMetadata;
86
+ module.exports.generateDocsNavCode = binding.generateDocsNavCode;
82
87
  module.exports.generateOgImageSvg = binding.generateOgImageSvg;
83
88
  module.exports.buildSearchIndex = binding.buildSearchIndex;
84
89
  module.exports.searchIndex = binding.searchIndex;
85
90
  module.exports.extractSearchContent = binding.extractSearchContent;
91
+ module.exports.parseScopedSearchQuery = binding.parseScopedSearchQuery;
92
+ module.exports.getSearchDocumentScopes = binding.getSearchDocumentScopes;
93
+ module.exports.matchesSearchScopes = binding.matchesSearchScopes;
94
+ module.exports.generateSearchModule = binding.generateSearchModule;
86
95
  module.exports.generateSsgHtml = binding.generateSsgHtml;
96
+ module.exports.resolveSsgRoutePaths = binding.resolveSsgRoutePaths;
97
+ module.exports.getSsgOutputPath = binding.getSsgOutputPath;
98
+ module.exports.getSsgUrlPath = binding.getSsgUrlPath;
99
+ module.exports.getSsgHref = binding.getSsgHref;
100
+ module.exports.getSsgPageLocale = binding.getSsgPageLocale;
101
+ module.exports.extractSsgTitle = binding.extractSsgTitle;
102
+ module.exports.formatSsgTitle = binding.formatSsgTitle;
103
+ module.exports.buildSsgNavItems = binding.buildSsgNavItems;
104
+ module.exports.buildSsgThemeNavItems = binding.buildSsgThemeNavItems;
105
+ module.exports.externalizeSsgAssets = binding.externalizeSsgAssets;
87
106
  module.exports.transformMermaid = binding.transformMermaid;
88
107
  module.exports.loadDictionaries = binding.loadDictionaries;
89
108
  module.exports.loadDictionariesFlat = binding.loadDictionariesFlat;
109
+ module.exports.generateI18nModule = binding.generateI18nModule;
90
110
  module.exports.validateMf2 = binding.validateMf2;
91
111
  module.exports.checkI18n = binding.checkI18n;
92
112
  module.exports.extractTranslationKeys = binding.extractTranslationKeys;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ox-content/napi",
3
- "version": "2.8.0",
3
+ "version": "2.10.0",
4
4
  "description": "Node.js bindings for Ox Content - High-performance Markdown parser",
5
5
  "keywords": [
6
6
  "markdown",
@@ -45,10 +45,10 @@
45
45
  ]
46
46
  },
47
47
  "optionalDependencies": {
48
- "@ox-content/binding-darwin-x64": "2.8.0",
49
- "@ox-content/binding-darwin-arm64": "2.8.0",
50
- "@ox-content/binding-linux-x64-gnu": "2.8.0",
51
- "@ox-content/binding-linux-arm64-gnu": "2.8.0",
52
- "@ox-content/binding-win32-x64-msvc": "2.8.0"
48
+ "@ox-content/binding-darwin-x64": "2.10.0",
49
+ "@ox-content/binding-darwin-arm64": "2.10.0",
50
+ "@ox-content/binding-linux-x64-gnu": "2.10.0",
51
+ "@ox-content/binding-linux-arm64-gnu": "2.10.0",
52
+ "@ox-content/binding-win32-x64-msvc": "2.10.0"
53
53
  }
54
54
  }