///
import type {
DocxCapability,
DocxExportDiagnostics,
DocxExportErrorCode,
DocxExportRequestInput,
DocxGenerationTimings,
DocxMediaCapturePlan,
PagedDocumentPayload,
PagedDocumentRenderResult,
RenderedMarkdownDocument,
ThemeCategory,
DocumentProfileName
} from "@md-to-pdf/core";
declare global {
const __APP_VERSION__: string;
const __APP_DISPLAY_NAME__: string;
const __APP_WINDOW_TITLE__: string;
const __APP_SLOGAN__: string;
const __APP_DESCRIPTION__: string;
interface DesktopPdfResult {
pdf: Uint8Array;
pageCount: number;
echartsErrors: string[];
mermaidErrors: string[];
}
type DesktopDocxExportOutcome =
| {
ok: true;
saved: boolean;
fileName: string;
diagnostics: DocxExportDiagnostics;
timings: DocxGenerationTimings;
}
| {
ok: false;
error: DocxExportErrorCode;
message: string;
retryable: boolean;
};
interface DesktopApplicationBridge {
openMarkdown(): Promise<
| {
markdown: string;
fileName: string;
}
| undefined
>;
consumePendingMarkdown(): Promise<
| {
markdown: string;
fileName: string;
}
| undefined
>;
discardPendingMarkdown(): Promise;
onMarkdownOpened(
listener: (reason: "open" | "reload" | "replace") => void
): () => void;
startNewMarkdown(): Promise;
createNewWindow(): Promise;
resolveWindowClose(close: boolean): Promise;
onWindowCloseRequested(listener: () => void): () => void;
setDocumentDirty(dirty: boolean): Promise;
openDocumentLink(href: string): Promise;
saveMarkdown(
fileName: string,
markdown: string
): Promise<{ fileName: string } | undefined>;
saveMarkdownAs(
fileName: string,
markdown: string
): Promise<{ fileName: string } | undefined>;
openThemeDirectory(): Promise;
refreshThemes(): Promise;
renderMarkdown(input: {
markdown: string;
language: string;
resources?: Array<{
path: string;
data: string;
}>;
}): Promise;
listThemes(): Promise<{
themes: Array<{
id: string;
name: string;
version: string;
description: string;
category: ThemeCategory;
compatibleProfiles: DocumentProfileName[];
bundled: boolean;
source: "bundled" | "local";
}>;
}>;
getThemeCss(themeId: string): Promise;
generatePdf(payload: PagedDocumentPayload): Promise;
savePdf(fileName: string, pdf: Uint8Array): Promise;
getDocxCapability(): Promise;
exportDocx(
request: DocxExportRequestInput
): Promise;
}
interface DesktopPdfRuntimeBridge {
ready(): void;
onRender(
listener: (
requestId: number,
payload: PagedDocumentPayload
) => Promise | void
): () => void;
complete(
requestId: number,
result: PagedDocumentRenderResult
): void;
fail(requestId: number, message: string): void;
}
interface Window {
mdToPdfDesktop?: DesktopApplicationBridge;
__mdToPdfDesktopPdf?: DesktopPdfRuntimeBridge;
__mdToPdfRenderDocxMedia?: (
payload: PagedDocumentPayload,
dimensions: {
contentWidthPx: number;
contentHeightPx: number;
}
) => Promise;
}
}