md2x 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.
Files changed (127) hide show
  1. package/README.md +43 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.mjs +128069 -0
  4. package/dist/md2x.mjs +128296 -0
  5. package/dist/renderer/puppeteer-render-worker.js +815 -0
  6. package/dist/renderer/puppeteer-render.html +2829 -0
  7. package/dist/themes/code-themes/business-contrast.json +31 -0
  8. package/dist/themes/code-themes/colorful.json +32 -0
  9. package/dist/themes/code-themes/cool-modern.json +31 -0
  10. package/dist/themes/code-themes/high-contrast.json +31 -0
  11. package/dist/themes/code-themes/light-clean.json +31 -0
  12. package/dist/themes/code-themes/warm-book.json +31 -0
  13. package/dist/themes/color-schemes/candy.json +34 -0
  14. package/dist/themes/color-schemes/cool.json +34 -0
  15. package/dist/themes/color-schemes/coral.json +34 -0
  16. package/dist/themes/color-schemes/dino.json +34 -0
  17. package/dist/themes/color-schemes/forest.json +34 -0
  18. package/dist/themes/color-schemes/garden.json +34 -0
  19. package/dist/themes/color-schemes/neutral.json +34 -0
  20. package/dist/themes/color-schemes/ocean.json +34 -0
  21. package/dist/themes/color-schemes/rainbow.json +43 -0
  22. package/dist/themes/color-schemes/sakura.json +34 -0
  23. package/dist/themes/color-schemes/sepia.json +34 -0
  24. package/dist/themes/color-schemes/space.json +34 -0
  25. package/dist/themes/color-schemes/starry.json +34 -0
  26. package/dist/themes/color-schemes/sunset.json +34 -0
  27. package/dist/themes/color-schemes/warm.json +34 -0
  28. package/dist/themes/font-config.json +184 -0
  29. package/dist/themes/layout-schemes/academic.json +40 -0
  30. package/dist/themes/layout-schemes/book.json +40 -0
  31. package/dist/themes/layout-schemes/document.json +40 -0
  32. package/dist/themes/layout-schemes/magazine.json +40 -0
  33. package/dist/themes/layout-schemes/student.json +40 -0
  34. package/dist/themes/layout-schemes/technical.json +40 -0
  35. package/dist/themes/presets/academic.json +24 -0
  36. package/dist/themes/presets/business.json +22 -0
  37. package/dist/themes/presets/candy.json +23 -0
  38. package/dist/themes/presets/century.json +22 -0
  39. package/dist/themes/presets/coral.json +22 -0
  40. package/dist/themes/presets/default.json +22 -0
  41. package/dist/themes/presets/dinosaur.json +23 -0
  42. package/dist/themes/presets/elegant.json +22 -0
  43. package/dist/themes/presets/forest.json +22 -0
  44. package/dist/themes/presets/garamond.json +22 -0
  45. package/dist/themes/presets/garden.json +23 -0
  46. package/dist/themes/presets/handwritten.json +23 -0
  47. package/dist/themes/presets/heiti.json +22 -0
  48. package/dist/themes/presets/magazine.json +24 -0
  49. package/dist/themes/presets/manuscript.json +22 -0
  50. package/dist/themes/presets/minimal.json +22 -0
  51. package/dist/themes/presets/mixed.json +24 -0
  52. package/dist/themes/presets/newspaper.json +24 -0
  53. package/dist/themes/presets/ocean.json +22 -0
  54. package/dist/themes/presets/palatino.json +22 -0
  55. package/dist/themes/presets/rainbow.json +23 -0
  56. package/dist/themes/presets/space.json +23 -0
  57. package/dist/themes/presets/starry.json +23 -0
  58. package/dist/themes/presets/sunset.json +22 -0
  59. package/dist/themes/presets/swiss.json +22 -0
  60. package/dist/themes/presets/technical.json +22 -0
  61. package/dist/themes/presets/typewriter.json +23 -0
  62. package/dist/themes/presets/verdana.json +22 -0
  63. package/dist/themes/presets/water.json +22 -0
  64. package/dist/themes/registry.json +270 -0
  65. package/dist/themes/table-styles/academic.json +30 -0
  66. package/dist/themes/table-styles/borderless.json +26 -0
  67. package/dist/themes/table-styles/compact.json +24 -0
  68. package/dist/themes/table-styles/grid.json +22 -0
  69. package/dist/themes/table-styles/high-contrast.json +22 -0
  70. package/dist/themes/table-styles/minimal-gray.json +26 -0
  71. package/dist/themes/table-styles/modern-tech.json +34 -0
  72. package/dist/themes/table-styles/professional.json +34 -0
  73. package/dist/themes/table-styles/zebra.json +22 -0
  74. package/dist/types/node/src/host/browser-renderer.d.ts +40 -0
  75. package/dist/types/node/src/host/node-exporter.d.ts +63 -0
  76. package/dist/types/node/src/host/node-platform.d.ts +30 -0
  77. package/dist/types/node/src/index.d.ts +8 -0
  78. package/dist/types/src/core/markdown-block-splitter.d.ts +16 -0
  79. package/dist/types/src/core/markdown-document.d.ts +286 -0
  80. package/dist/types/src/core/markdown-processor.d.ts +228 -0
  81. package/dist/types/src/core/viewer/viewer-controller.d.ts +85 -0
  82. package/dist/types/src/exporters/docx-blockquote-converter.d.ts +24 -0
  83. package/dist/types/src/exporters/docx-code-highlighter.d.ts +14 -0
  84. package/dist/types/src/exporters/docx-download.d.ts +27 -0
  85. package/dist/types/src/exporters/docx-exporter.d.ts +77 -0
  86. package/dist/types/src/exporters/docx-image-utils.d.ts +71 -0
  87. package/dist/types/src/exporters/docx-inline-converter.d.ts +124 -0
  88. package/dist/types/src/exporters/docx-list-converter.d.ts +50 -0
  89. package/dist/types/src/exporters/docx-math-converter.d.ts +11 -0
  90. package/dist/types/src/exporters/docx-table-converter.d.ts +22 -0
  91. package/dist/types/src/exporters/mml2omml.d.ts +2 -0
  92. package/dist/types/src/exporters/theme-to-docx.d.ts +144 -0
  93. package/dist/types/src/plugins/base-plugin.d.ts +67 -0
  94. package/dist/types/src/plugins/canvas-plugin.d.ts +9 -0
  95. package/dist/types/src/plugins/dot-plugin.d.ts +9 -0
  96. package/dist/types/src/plugins/html-plugin.d.ts +28 -0
  97. package/dist/types/src/plugins/index.d.ts +56 -0
  98. package/dist/types/src/plugins/infographic-plugin.d.ts +9 -0
  99. package/dist/types/src/plugins/mermaid-plugin.d.ts +9 -0
  100. package/dist/types/src/plugins/plugin-content-utils.d.ts +40 -0
  101. package/dist/types/src/plugins/plugin-html-utils.d.ts +23 -0
  102. package/dist/types/src/plugins/rehype-image-uri.d.ts +13 -0
  103. package/dist/types/src/plugins/remark-super-sub.d.ts +17 -0
  104. package/dist/types/src/plugins/remark-toc-filter.d.ts +10 -0
  105. package/dist/types/src/plugins/svg-plugin.d.ts +51 -0
  106. package/dist/types/src/plugins/vega-plugin.d.ts +10 -0
  107. package/dist/types/src/plugins/vegalite-plugin.d.ts +23 -0
  108. package/dist/types/src/types/cache.d.ts +85 -0
  109. package/dist/types/src/types/core.d.ts +99 -0
  110. package/dist/types/src/types/docx.d.ts +240 -0
  111. package/dist/types/src/types/index.d.ts +18 -0
  112. package/dist/types/src/types/messaging.d.ts +142 -0
  113. package/dist/types/src/types/platform.d.ts +203 -0
  114. package/dist/types/src/types/plugin.d.ts +101 -0
  115. package/dist/types/src/types/render.d.ts +57 -0
  116. package/dist/types/src/types/theme.d.ts +234 -0
  117. package/dist/types/src/types/toolbar.d.ts +53 -0
  118. package/dist/types/src/ui/popup/i18n-helpers.d.ts +21 -0
  119. package/dist/types/src/ui/popup/settings-tab.d.ts +56 -0
  120. package/dist/types/src/ui/popup/storage-helper.d.ts +12 -0
  121. package/dist/types/src/utils/fetch-utils.d.ts +12 -0
  122. package/dist/types/src/utils/hash.d.ts +17 -0
  123. package/dist/types/src/utils/html-sanitizer.d.ts +26 -0
  124. package/dist/types/src/utils/localization.d.ts +49 -0
  125. package/dist/types/src/utils/theme-manager.d.ts +152 -0
  126. package/dist/types/src/utils/theme-to-css.d.ts +171 -0
  127. package/package.json +47 -0
@@ -0,0 +1,77 @@
1
+ import type { PluginRenderer } from '../types/plugin';
2
+ import type { ImageBufferResult, DOCXProgressCallback, DOCXExportResult } from '../types/docx';
3
+ export { convertPluginResultToDOCX } from './docx-image-utils';
4
+ /**
5
+ * Main class for exporting Markdown to DOCX
6
+ */
7
+ declare class DocxExporter {
8
+ private renderer;
9
+ private imageCache;
10
+ private listInstanceCounter;
11
+ private mathJaxInitialized;
12
+ private baseUrl;
13
+ private themeStyles;
14
+ private codeHighlighter;
15
+ private linkDefinitions;
16
+ private progressCallback;
17
+ private totalResources;
18
+ private processedResources;
19
+ private docxHrAsPageBreak;
20
+ private docxEmojiStyle;
21
+ private frontmatterDisplay;
22
+ private tableConverter;
23
+ private blockquoteConverter;
24
+ private listConverter;
25
+ private inlineConverter;
26
+ constructor(renderer?: PluginRenderer | null);
27
+ setBaseUrl(url: string): void;
28
+ /**
29
+ * Get DocumentService from platform
30
+ */
31
+ private getDocumentService;
32
+ initializeMathJax(): Promise<void>;
33
+ /**
34
+ * Initialize all converters with current context
35
+ */
36
+ private initializeConverters;
37
+ exportToDocx(markdown: string, filename?: string, onProgress?: DOCXProgressCallback | null): Promise<DOCXExportResult>;
38
+ private countResources;
39
+ private reportResourceProgress;
40
+ /**
41
+ * Extract frontmatter from markdown text
42
+ * @returns Tuple of [frontmatter content or null, markdown without frontmatter]
43
+ */
44
+ private extractFrontmatter;
45
+ /**
46
+ * Parse frontmatter YAML content (simple key: value parsing)
47
+ */
48
+ private parseFrontmatterData;
49
+ private frontmatterContent;
50
+ private parseMarkdown;
51
+ /**
52
+ * Check if a node is a [toc] marker
53
+ * Detects paragraphs containing only [toc] or [TOC]
54
+ */
55
+ private isTocMarker;
56
+ /**
57
+ * Convert frontmatter to DOCX elements based on display mode
58
+ */
59
+ private convertFrontmatterToDocx;
60
+ private convertAstToDocx;
61
+ private convertNode;
62
+ private convertHeading;
63
+ private convertParagraph;
64
+ private convertCodeBlock;
65
+ private convertHtml;
66
+ private convertThematicBreak;
67
+ private convertMathBlock;
68
+ private toAlignmentType;
69
+ private toDocumentDefaults;
70
+ private toHeadingStyle;
71
+ fetchImageAsBuffer(url: string): Promise<ImageBufferResult>;
72
+ /**
73
+ * Guess content type from URL extension
74
+ */
75
+ private guessContentType;
76
+ }
77
+ export default DocxExporter;
@@ -0,0 +1,71 @@
1
+ import { Paragraph, TextRun, ImageRun } from 'docx';
2
+ import type { UnifiedRenderResult } from '../types/index';
3
+ import type { ImageBufferResult, DOCXImageType } from '../types/docx';
4
+ interface ImageDimensions {
5
+ width: number;
6
+ height: number;
7
+ }
8
+ interface Renderer {
9
+ render(type: string, content: string, options?: Record<string, unknown>): Promise<{
10
+ base64: string;
11
+ width: number;
12
+ height: number;
13
+ }>;
14
+ }
15
+ type FetchImageAsBufferFunction = (url: string) => Promise<ImageBufferResult>;
16
+ /**
17
+ * Calculate appropriate image dimensions for DOCX to fit within page constraints
18
+ * Maximum width: 6 inches (page width with 1 inch margins on letter size)
19
+ * Maximum height: 9.5 inches (page height with 1 inch margins on letter size)
20
+ * @param originalWidth - Original image width in pixels
21
+ * @param originalHeight - Original image height in pixels
22
+ * @returns {width: number, height: number} in pixels
23
+ */
24
+ export declare function calculateImageDimensions(originalWidth: number, originalHeight: number): ImageDimensions;
25
+ /**
26
+ * Convert unified plugin render result to DOCX elements
27
+ * @param renderResult - Unified render result from plugin.renderToCommon()
28
+ * @param pluginType - Plugin type for alt text
29
+ * @returns DOCX Paragraph or ImageRun
30
+ */
31
+ export declare function convertPluginResultToDOCX(renderResult: UnifiedRenderResult, pluginType?: string): Paragraph | TextRun | ImageRun;
32
+ /**
33
+ * Get image dimensions from buffer
34
+ * @param buffer - Image buffer
35
+ * @param contentType - Image content type
36
+ * @returns Promise with width and height
37
+ */
38
+ export declare function getImageDimensions(buffer: Uint8Array, contentType: string): Promise<ImageDimensions>;
39
+ /**
40
+ * Determine image type from content type or URL
41
+ * @param contentType - Image content type
42
+ * @param url - Image URL
43
+ * @returns Image type for docx
44
+ */
45
+ export declare function determineImageType(contentType: string | null, url: string): DOCXImageType;
46
+ /**
47
+ * Check if URL or content type indicates an SVG image
48
+ * @param url - Image URL
49
+ * @param contentType - Content type (optional)
50
+ * @returns True if SVG
51
+ */
52
+ export declare function isSvgImage(url: string, contentType?: string | null): boolean;
53
+ /**
54
+ * Convert SVG content to PNG using renderer
55
+ * @param svgContent - SVG content string
56
+ * @param renderer - Renderer instance with render() method
57
+ * @returns Promise with buffer, width, and height
58
+ */
59
+ export declare function convertSvgToPng(svgContent: string, renderer: Renderer): Promise<{
60
+ buffer: Uint8Array;
61
+ width: number;
62
+ height: number;
63
+ }>;
64
+ /**
65
+ * Get SVG content from URL or data URL
66
+ * @param url - SVG URL or data URL
67
+ * @param fetchImageAsBuffer - Function to fetch image as buffer
68
+ * @returns SVG content string
69
+ */
70
+ export declare function getSvgContent(url: string, fetchImageAsBuffer: FetchImageAsBufferFunction): Promise<string>;
71
+ export {};
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Inline node conversion for DOCX export
3
+ */
4
+ import { TextRun, ImageRun, type IRunOptions, type ParagraphChild } from 'docx';
5
+ import type { DOCXThemeStyles, LinkDefinition, ImageBufferResult, EmojiStyle } from '../types/docx';
6
+ /**
7
+ * Renderer interface for SVG conversion
8
+ */
9
+ interface Renderer {
10
+ render(type: string, content: string, options?: object): Promise<{
11
+ base64: string;
12
+ width: number;
13
+ height: number;
14
+ format: string;
15
+ }>;
16
+ }
17
+ /**
18
+ * Options for creating inline converter
19
+ */
20
+ interface InlineConverterOptions {
21
+ themeStyles: DOCXThemeStyles;
22
+ fetchImageAsBuffer: (url: string) => Promise<ImageBufferResult>;
23
+ reportResourceProgress: () => void;
24
+ linkDefinitions?: Map<string, LinkDefinition>;
25
+ renderer?: Renderer | null;
26
+ emojiStyle?: EmojiStyle;
27
+ linkColor?: string;
28
+ }
29
+ /**
30
+ * Parent style for inline elements
31
+ */
32
+ interface ParentStyle extends Partial<IRunOptions> {
33
+ size?: number;
34
+ bold?: boolean;
35
+ italics?: boolean;
36
+ strike?: boolean;
37
+ }
38
+ /**
39
+ * AST Node types
40
+ */
41
+ interface BaseNode {
42
+ type: string;
43
+ }
44
+ interface TextNode extends BaseNode {
45
+ type: 'text';
46
+ value: string;
47
+ }
48
+ interface StrongNode extends BaseNode {
49
+ type: 'strong';
50
+ children: InlineNode[];
51
+ }
52
+ interface EmphasisNode extends BaseNode {
53
+ type: 'emphasis';
54
+ children: InlineNode[];
55
+ }
56
+ interface DeleteNode extends BaseNode {
57
+ type: 'delete';
58
+ children: InlineNode[];
59
+ }
60
+ interface InlineCodeNode extends BaseNode {
61
+ type: 'inlineCode';
62
+ value: string;
63
+ }
64
+ interface LinkNode extends BaseNode {
65
+ type: 'link';
66
+ url: string;
67
+ title?: string;
68
+ children: InlineNode[];
69
+ }
70
+ interface LinkReferenceNode extends BaseNode {
71
+ type: 'linkReference';
72
+ identifier: string;
73
+ children: InlineNode[];
74
+ }
75
+ interface ImageNode extends BaseNode {
76
+ type: 'image';
77
+ url: string;
78
+ alt?: string;
79
+ title?: string;
80
+ }
81
+ interface InlineMathNode extends BaseNode {
82
+ type: 'inlineMath';
83
+ value: string;
84
+ }
85
+ interface BreakNode extends BaseNode {
86
+ type: 'break';
87
+ }
88
+ interface HtmlNode extends BaseNode {
89
+ type: 'html';
90
+ value?: string;
91
+ }
92
+ interface SuperscriptNode extends BaseNode {
93
+ type: 'superscript';
94
+ children: InlineNode[];
95
+ }
96
+ interface SubscriptNode extends BaseNode {
97
+ type: 'subscript';
98
+ children: InlineNode[];
99
+ }
100
+ export type InlineNode = TextNode | StrongNode | EmphasisNode | DeleteNode | InlineCodeNode | LinkNode | LinkReferenceNode | ImageNode | InlineMathNode | BreakNode | HtmlNode | SuperscriptNode | SubscriptNode;
101
+ /**
102
+ * Inline converter result type
103
+ */
104
+ export type InlineResult = ParagraphChild;
105
+ /**
106
+ * Inline converter interface
107
+ */
108
+ export interface InlineConverter {
109
+ convertInlineNodes(nodes: InlineNode[], parentStyle?: ParentStyle): Promise<InlineResult[]>;
110
+ convertInlineNode(node: InlineNode, parentStyle?: ParentStyle): Promise<InlineResult | InlineResult[] | null>;
111
+ convertImage(node: ImageNode): Promise<ImageRun | TextRun>;
112
+ extractText(node: InlineNode | {
113
+ type: string;
114
+ children?: InlineNode[];
115
+ value?: string;
116
+ }): string;
117
+ }
118
+ /**
119
+ * Create an inline node converter
120
+ * @param options - Configuration options
121
+ * @returns Inline node converter
122
+ */
123
+ export declare function createInlineConverter({ themeStyles, fetchImageAsBuffer, reportResourceProgress, linkDefinitions, renderer, emojiStyle, linkColor }: InlineConverterOptions): InlineConverter;
124
+ export {};
@@ -0,0 +1,50 @@
1
+ import { AlignmentType, LevelFormat, type FileChild } from 'docx';
2
+ import type { DOCXThemeStyles, DOCXListNode, DOCXASTNode } from '../types/docx';
3
+ import type { InlineResult, InlineNode } from './docx-inline-converter';
4
+ interface ListItemNode {
5
+ type: string;
6
+ checked?: boolean | null;
7
+ children: (InlineNode | DOCXListNode | {
8
+ type: string;
9
+ children?: InlineNode[];
10
+ })[];
11
+ }
12
+ type ConvertInlineNodesFunction = (children: InlineNode[], options?: Record<string, unknown>) => Promise<InlineResult[]>;
13
+ type ConvertChildNodeFunction = (node: DOCXASTNode, listLevel?: number) => Promise<FileChild | FileChild[] | null>;
14
+ interface ListConverterOptions {
15
+ themeStyles: DOCXThemeStyles;
16
+ convertInlineNodes: ConvertInlineNodesFunction;
17
+ getListInstanceCounter: () => number;
18
+ incrementListInstanceCounter: () => number;
19
+ }
20
+ interface NumberingLevel {
21
+ level: number;
22
+ format: (typeof LevelFormat)[keyof typeof LevelFormat];
23
+ text: string;
24
+ alignment: typeof AlignmentType.START;
25
+ style: {
26
+ paragraph: {
27
+ indent: {
28
+ left: number;
29
+ hanging: number;
30
+ };
31
+ };
32
+ };
33
+ }
34
+ /**
35
+ * Create numbering levels configuration for ordered lists
36
+ * @returns Numbering levels configuration
37
+ */
38
+ export declare function createNumberingLevels(): NumberingLevel[];
39
+ export interface ListConverter {
40
+ convertList(node: DOCXListNode): Promise<FileChild[]>;
41
+ convertListItem(ordered: boolean, item: ListItemNode, level: number, listInstance: number): Promise<FileChild[]>;
42
+ setConvertChildNode(fn: ConvertChildNodeFunction): void;
43
+ }
44
+ /**
45
+ * Create a list converter
46
+ * @param options - Configuration options
47
+ * @returns List converter
48
+ */
49
+ export declare function createListConverter({ themeStyles, convertInlineNodes, getListInstanceCounter, incrementListInstanceCounter }: ListConverterOptions): ListConverter;
50
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * DOCX Math Converter
3
+ * Converts LaTeX math expressions to DOCX-compatible OMML format
4
+ */
5
+ import { XmlComponent } from 'docx';
6
+ export declare function convertMathMl2Omml(mathMlString: string): string;
7
+ declare function convertOmml2Math(ommlString: string): XmlComponent;
8
+ declare function convertMathMl2Math(mathMlString: string): XmlComponent;
9
+ export declare function mathJaxReady(): Promise<boolean>;
10
+ export declare function convertLatex2Math(latexString: string): XmlComponent;
11
+ export { convertMathMl2Math, convertOmml2Math };
@@ -0,0 +1,22 @@
1
+ import { Table } from 'docx';
2
+ import type { DOCXThemeStyles, DOCXTableNode } from '../types/docx';
3
+ import type { InlineResult, InlineNode } from './docx-inline-converter';
4
+ type ConvertInlineNodesFunction = (children: InlineNode[], options?: {
5
+ bold?: boolean;
6
+ size?: number;
7
+ color?: string;
8
+ }) => Promise<InlineResult[]>;
9
+ interface TableConverterOptions {
10
+ themeStyles: DOCXThemeStyles;
11
+ convertInlineNodes: ConvertInlineNodesFunction;
12
+ }
13
+ export interface TableConverter {
14
+ convertTable(node: DOCXTableNode, listLevel?: number): Promise<Table>;
15
+ }
16
+ /**
17
+ * Create a table converter
18
+ * @param options - Configuration options
19
+ * @returns Table converter
20
+ */
21
+ export declare function createTableConverter({ themeStyles, convertInlineNodes }: TableConverterOptions): TableConverter;
22
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const mml2omml: (mmlString: any, options: any) => any;
2
+ export { mml2omml };
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Theme to DOCX Converter
3
+ * Converts theme configuration to DOCX styles
4
+ */
5
+ import type { DOCXThemeStyles } from '../types/docx';
6
+ import type { ColorScheme } from '../types/index';
7
+ export type { DOCXThemeStyles };
8
+ /**
9
+ * Heading style configuration (font-related properties only)
10
+ */
11
+ interface HeadingConfig {
12
+ fontFamily?: string;
13
+ fontWeight?: string;
14
+ }
15
+ /**
16
+ * Font scheme configuration (font-related properties only)
17
+ * Layout properties (fontSize, lineHeight, spacing) are in LayoutScheme
18
+ * Color properties are in ColorScheme
19
+ */
20
+ interface FontScheme {
21
+ body: {
22
+ fontFamily: string;
23
+ };
24
+ headings: {
25
+ fontFamily: string;
26
+ fontWeight?: string;
27
+ [key: string]: string | HeadingConfig | undefined;
28
+ };
29
+ code: {
30
+ fontFamily: string;
31
+ };
32
+ }
33
+ /**
34
+ * Theme configuration
35
+ */
36
+ interface ThemeConfig {
37
+ fontScheme: FontScheme;
38
+ layoutScheme: string;
39
+ tableStyle: string;
40
+ codeTheme: string;
41
+ }
42
+ /**
43
+ * Layout scheme heading configuration
44
+ */
45
+ interface LayoutHeadingConfig {
46
+ fontSize: string;
47
+ spacingBefore: string;
48
+ spacingAfter: string;
49
+ alignment?: 'left' | 'center' | 'right';
50
+ }
51
+ /**
52
+ * Layout scheme block configuration
53
+ */
54
+ interface LayoutBlockConfig {
55
+ spacingBefore?: string;
56
+ spacingAfter?: string;
57
+ paddingVertical?: string;
58
+ paddingHorizontal?: string;
59
+ }
60
+ /**
61
+ * Layout scheme configuration (absolute pt values)
62
+ */
63
+ interface LayoutScheme {
64
+ id: string;
65
+ name: string;
66
+ name_en: string;
67
+ description: string;
68
+ description_en?: string;
69
+ body: {
70
+ fontSize: string;
71
+ lineHeight: number;
72
+ };
73
+ headings: {
74
+ h1: LayoutHeadingConfig;
75
+ h2: LayoutHeadingConfig;
76
+ h3: LayoutHeadingConfig;
77
+ h4: LayoutHeadingConfig;
78
+ h5: LayoutHeadingConfig;
79
+ h6: LayoutHeadingConfig;
80
+ };
81
+ code: {
82
+ fontSize: string;
83
+ };
84
+ blocks: {
85
+ paragraph: LayoutBlockConfig;
86
+ list: LayoutBlockConfig;
87
+ listItem: LayoutBlockConfig;
88
+ blockquote: LayoutBlockConfig;
89
+ codeBlock: LayoutBlockConfig;
90
+ table: LayoutBlockConfig;
91
+ horizontalRule: LayoutBlockConfig;
92
+ };
93
+ }
94
+ /**
95
+ * Border configuration (layout properties only, color from ColorScheme)
96
+ */
97
+ interface BorderConfig {
98
+ style: string;
99
+ width: string;
100
+ }
101
+ /**
102
+ * Table style configuration (layout properties only, colors from ColorScheme)
103
+ */
104
+ interface TableStyleConfig {
105
+ border?: {
106
+ all?: BorderConfig;
107
+ headerTop?: BorderConfig;
108
+ headerBottom?: BorderConfig;
109
+ rowBottom?: BorderConfig;
110
+ lastRowBottom?: BorderConfig;
111
+ };
112
+ header: {
113
+ fontWeight?: string;
114
+ };
115
+ cell: {
116
+ padding: string;
117
+ };
118
+ zebra?: {
119
+ enabled: boolean;
120
+ };
121
+ }
122
+ /**
123
+ * Code theme configuration (from code theme JSON)
124
+ */
125
+ interface CodeThemeConfig {
126
+ colors: Record<string, string>;
127
+ foreground?: string;
128
+ }
129
+ /**
130
+ * Convert theme configuration to DOCX styles object
131
+ * @param theme - Theme configuration object
132
+ * @param layoutScheme - Layout scheme configuration
133
+ * @param colorScheme - Color scheme configuration
134
+ * @param tableStyle - Table style configuration
135
+ * @param codeTheme - Code highlighting theme
136
+ * @returns DOCX styles configuration
137
+ */
138
+ export declare function themeToDOCXStyles(theme: ThemeConfig, layoutScheme: LayoutScheme, colorScheme: ColorScheme, tableStyle: TableStyleConfig, codeTheme: CodeThemeConfig): DOCXThemeStyles;
139
+ /**
140
+ * Load and prepare complete theme configuration for DOCX export
141
+ * @param themeId - Theme ID to load
142
+ * @returns DOCX styles configuration
143
+ */
144
+ export declare function loadThemeForDOCX(themeId: string): Promise<DOCXThemeStyles>;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Base Plugin Class
3
+ *
4
+ * Abstract base class for diagram plugins.
5
+ * Defines the plugin interface and core rendering logic.
6
+ */
7
+ import type { ASTNode, PluginRenderer, UnifiedRenderResult } from '../types/index';
8
+ export declare class BasePlugin {
9
+ type: string;
10
+ /**
11
+ * @param type - Plugin type identifier (e.g., 'mermaid', 'vega')
12
+ */
13
+ constructor(type: string);
14
+ /**
15
+ * Get AST node selectors for remark visit
16
+ * @returns Array of node types to visit (e.g., ['code'], ['code', 'image'])
17
+ */
18
+ get nodeSelector(): string[];
19
+ /**
20
+ * Get language identifier for code blocks
21
+ * @returns Language identifier or null for non-code nodes
22
+ */
23
+ get language(): string | null;
24
+ /**
25
+ * Extract content from AST node
26
+ * Plugins override this to implement their own node matching logic
27
+ * @param node - AST node
28
+ * @returns Extracted content or null if not applicable
29
+ */
30
+ extractContent(node: ASTNode): string | null;
31
+ /**
32
+ * Create async task data for rendering
33
+ * @param content - Extracted content
34
+ * @returns Task data with code and any extra parameters
35
+ */
36
+ createTaskData(content: string): Record<string, unknown>;
37
+ /**
38
+ * Get extra rendering parameters
39
+ * @returns Extra parameters for renderer
40
+ */
41
+ getRenderParams(): Record<string, unknown>;
42
+ /**
43
+ * Check if this plugin uses inline rendering
44
+ * @returns True for inline (span), false for block (div)
45
+ */
46
+ isInline(): boolean;
47
+ /**
48
+ * Check if extracted content is a URL that needs fetching
49
+ * @param content - Extracted content
50
+ * @returns True if content is a URL
51
+ */
52
+ isUrl(content: string): boolean;
53
+ /**
54
+ * Fetch content from URL
55
+ * @param url - URL to fetch
56
+ * @returns Fetched content
57
+ */
58
+ fetchContent(url: string): Promise<string>;
59
+ /**
60
+ * Render content to unified intermediate format
61
+ * This is the core rendering method that returns a format-agnostic result
62
+ * @param renderer - Renderer instance
63
+ * @param content - Content to render
64
+ * @returns Unified render result
65
+ */
66
+ renderToCommon(renderer: PluginRenderer | null, content: string): Promise<UnifiedRenderResult>;
67
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * JSON Canvas Plugin
3
+ *
4
+ * Handles JSON Canvas processing in content script and DOCX export
5
+ */
6
+ import { BasePlugin } from './base-plugin';
7
+ export declare class JsonCanvasPlugin extends BasePlugin {
8
+ constructor();
9
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * DOT Plugin
3
+ *
4
+ * Handles Graphviz DOT diagram processing in content script and DOCX export
5
+ */
6
+ import { BasePlugin } from './base-plugin';
7
+ export declare class DotPlugin extends BasePlugin {
8
+ constructor();
9
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * HTML Plugin
3
+ *
4
+ * Handles HTML code block processing in content script and DOCX export
5
+ */
6
+ import { BasePlugin } from './base-plugin';
7
+ /**
8
+ * AST node interface for HTML plugin
9
+ */
10
+ interface AstNode {
11
+ type: string;
12
+ value?: string;
13
+ }
14
+ export declare class HtmlPlugin extends BasePlugin {
15
+ constructor();
16
+ /**
17
+ * Get AST node selectors for remark visit
18
+ * @returns Array with 'html' node type
19
+ */
20
+ get nodeSelector(): string[];
21
+ /**
22
+ * Extract content from HTML node
23
+ * @param node - AST node
24
+ * @returns Extracted content or null
25
+ */
26
+ extractContent(node: AstNode): string | null;
27
+ }
28
+ export {};
@@ -0,0 +1,56 @@
1
+ import type { BasePlugin } from './base-plugin';
2
+ import type { Processor } from 'unified';
3
+ import type { Node, Parent } from 'unist';
4
+ import type { AsyncTaskQueueManager, TranslateFunction, EscapeHtmlFunction, PluginRenderer } from '../types/index';
5
+ /**
6
+ * Visit function type from unist-util-visit
7
+ */
8
+ type VisitFn = (tree: Node, test: string, visitor: (node: Node, index: number | undefined, parent: Parent | undefined) => void) => void;
9
+ /**
10
+ * DOCX helper objects
11
+ */
12
+ interface DOCXHelpers {
13
+ [key: string]: unknown;
14
+ }
15
+ export declare const plugins: BasePlugin[];
16
+ /**
17
+ * Register all plugins to a remark processor
18
+ * This creates a single unified plugin that processes all node types in document order
19
+ * @param processor - Unified/remark processor
20
+ * @param renderer - Renderer instance
21
+ * @param asyncTask - Async task creator from AsyncTaskQueueManager
22
+ * @param translate - Translation function
23
+ * @param escapeHtml - HTML escape function
24
+ * @param visit - unist-util-visit function
25
+ * @returns The processor (for chaining)
26
+ */
27
+ export declare function registerRemarkPlugins(processor: Processor, renderer: PluginRenderer, asyncTask: AsyncTaskQueueManager['asyncTask'], translate: TranslateFunction, escapeHtml: EscapeHtmlFunction, visit: VisitFn): Processor;
28
+ /**
29
+ * Get a plugin by type
30
+ * @param type - Plugin type (e.g., 'mermaid', 'svg', 'html')
31
+ * @returns Plugin instance or null if not found
32
+ */
33
+ export declare function getPluginByType(type: string): BasePlugin | null;
34
+ /**
35
+ * Get a plugin that can handle a specific AST node
36
+ * @param node - AST node (e.g., code block or html node)
37
+ * @returns Plugin instance or null if no plugin can handle
38
+ */
39
+ export declare function getPluginForNode(node: Node): BasePlugin | null;
40
+ /**
41
+ * Get all plugin types
42
+ * @returns Array of plugin types
43
+ */
44
+ export declare function getPluginTypes(): string[];
45
+ /**
46
+ * Convert AST node to DOCX element using appropriate plugin
47
+ * High-level wrapper that encapsulates plugin lookup, content extraction, and conversion
48
+ *
49
+ * @param node - AST node to convert
50
+ * @param renderer - Renderer instance for generating images
51
+ * @param docxHelpers - DOCX helper objects and functions
52
+ * @param progressCallback - Optional callback to report progress
53
+ * @returns DOCX element (Paragraph/ImageRun) or null if no plugin handles this node
54
+ */
55
+ export declare function convertNodeToDOCX(node: Node, renderer: PluginRenderer, docxHelpers: DOCXHelpers, progressCallback?: (() => void) | null): Promise<unknown | null>;
56
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Infographic Plugin
3
+ *
4
+ * Handles AntV Infographic syntax processing in content script and DOCX export
5
+ */
6
+ import { BasePlugin } from './base-plugin';
7
+ export declare class InfographicPlugin extends BasePlugin {
8
+ constructor();
9
+ }