@pyreon/document 0.0.1
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.
- package/LICENSE +21 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/chunk-ErZ26oRB.js +48 -0
- package/lib/confluence-Va8e7RxQ.js +192 -0
- package/lib/confluence-Va8e7RxQ.js.map +1 -0
- package/lib/csv-2c38ub-Y.js +32 -0
- package/lib/csv-2c38ub-Y.js.map +1 -0
- package/lib/discord-DAoUZqvE.js +134 -0
- package/lib/discord-DAoUZqvE.js.map +1 -0
- package/lib/dist-BsqdI2nY.js +20179 -0
- package/lib/dist-BsqdI2nY.js.map +1 -0
- package/lib/docx-CorFwEH9.js +450 -0
- package/lib/docx-CorFwEH9.js.map +1 -0
- package/lib/email-Bn_Brjdp.js +131 -0
- package/lib/email-Bn_Brjdp.js.map +1 -0
- package/lib/exceljs-BoIDUUaw.js +34377 -0
- package/lib/exceljs-BoIDUUaw.js.map +1 -0
- package/lib/google-chat-B6I017I1.js +125 -0
- package/lib/google-chat-B6I017I1.js.map +1 -0
- package/lib/html-De_iS_f0.js +151 -0
- package/lib/html-De_iS_f0.js.map +1 -0
- package/lib/index.js +619 -0
- package/lib/index.js.map +1 -0
- package/lib/markdown-BYC_3C9i.js +75 -0
- package/lib/markdown-BYC_3C9i.js.map +1 -0
- package/lib/notion-DHaQHO6P.js +187 -0
- package/lib/notion-DHaQHO6P.js.map +1 -0
- package/lib/pdf-CDPc5Itc.js +419 -0
- package/lib/pdf-CDPc5Itc.js.map +1 -0
- package/lib/pdfmake-DnmLxK4Q.js +55511 -0
- package/lib/pdfmake-DnmLxK4Q.js.map +1 -0
- package/lib/pptx-DKQU6bjq.js +252 -0
- package/lib/pptx-DKQU6bjq.js.map +1 -0
- package/lib/pptxgen.es-COcgXsyx.js +5697 -0
- package/lib/pptxgen.es-COcgXsyx.js.map +1 -0
- package/lib/slack-CJRJgkag.js +139 -0
- package/lib/slack-CJRJgkag.js.map +1 -0
- package/lib/svg-BM8biZmL.js +187 -0
- package/lib/svg-BM8biZmL.js.map +1 -0
- package/lib/teams-S99tonRG.js +176 -0
- package/lib/teams-S99tonRG.js.map +1 -0
- package/lib/telegram-CbEO_2PN.js +77 -0
- package/lib/telegram-CbEO_2PN.js.map +1 -0
- package/lib/text-B5U8ucRr.js +75 -0
- package/lib/text-B5U8ucRr.js.map +1 -0
- package/lib/types/index.d.ts +528 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/vfs_fonts-Df1kkZ4Y.js +19 -0
- package/lib/vfs_fonts-Df1kkZ4Y.js.map +1 -0
- package/lib/whatsapp-DJ2D1jGG.js +64 -0
- package/lib/whatsapp-DJ2D1jGG.js.map +1 -0
- package/lib/xlsx-D47x-gZ5.js +199 -0
- package/lib/xlsx-D47x-gZ5.js.map +1 -0
- package/package.json +62 -0
- package/src/builder.ts +266 -0
- package/src/download.ts +76 -0
- package/src/env.d.ts +17 -0
- package/src/index.ts +98 -0
- package/src/nodes.ts +315 -0
- package/src/render.ts +222 -0
- package/src/renderers/confluence.ts +231 -0
- package/src/renderers/csv.ts +67 -0
- package/src/renderers/discord.ts +192 -0
- package/src/renderers/docx.ts +612 -0
- package/src/renderers/email.ts +230 -0
- package/src/renderers/google-chat.ts +211 -0
- package/src/renderers/html.ts +225 -0
- package/src/renderers/markdown.ts +144 -0
- package/src/renderers/notion.ts +264 -0
- package/src/renderers/pdf.ts +427 -0
- package/src/renderers/pptx.ts +353 -0
- package/src/renderers/slack.ts +192 -0
- package/src/renderers/svg.ts +254 -0
- package/src/renderers/teams.ts +234 -0
- package/src/renderers/telegram.ts +137 -0
- package/src/renderers/text.ts +154 -0
- package/src/renderers/whatsapp.ts +121 -0
- package/src/renderers/xlsx.ts +342 -0
- package/src/tests/document.test.ts +2920 -0
- package/src/types.ts +291 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-CbEO_2PN.js","names":[],"sources":["../src/renderers/telegram.ts"],"sourcesContent":["import type {\n DocChild,\n DocNode,\n DocumentRenderer,\n RenderOptions,\n TableColumn,\n} from '../types'\n\n/**\n * Telegram renderer — outputs HTML using Telegram's supported subset.\n * Telegram Bot API supports: <b>, <i>, <u>, <s>, <a>, <code>, <pre>, <blockquote>.\n * No tables, no images inline — images sent separately via sendPhoto.\n */\n\nfunction resolveColumn(col: string | TableColumn): TableColumn {\n return typeof col === 'string' ? { header: col } : col\n}\n\nfunction esc(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n}\n\nfunction getTextContent(children: DocChild[]): string {\n return children\n .map((c) =>\n typeof c === 'string' ? c : getTextContent((c as DocNode).children),\n )\n .join('')\n}\n\nfunction renderNode(node: DocNode): string {\n const p = node.props\n\n switch (node.type) {\n case 'document':\n case 'page':\n case 'section':\n case 'row':\n case 'column':\n return node.children\n .map((c) => (typeof c === 'string' ? esc(c) : renderNode(c)))\n .join('')\n\n case 'heading': {\n const text = esc(getTextContent(node.children))\n return `<b>${text}</b>\\n\\n`\n }\n\n case 'text': {\n let text = esc(getTextContent(node.children))\n if (p.bold) text = `<b>${text}</b>`\n if (p.italic) text = `<i>${text}</i>`\n if (p.underline) text = `<u>${text}</u>`\n if (p.strikethrough) text = `<s>${text}</s>`\n return `${text}\\n\\n`\n }\n\n case 'link': {\n const href = p.href as string\n const text = esc(getTextContent(node.children))\n return `<a href=\"${esc(href)}\">${text}</a>\\n\\n`\n }\n\n case 'image':\n // Telegram doesn't support inline images in HTML\n // Images need to be sent separately via sendPhoto\n return ''\n\n case 'table': {\n const columns = ((p.columns ?? []) as (string | TableColumn)[]).map(\n resolveColumn,\n )\n const rows = (p.rows ?? []) as (string | number)[][]\n\n // Render as preformatted text since Telegram has no table support\n const header = columns.map((c) => c.header).join(' | ')\n const separator = columns.map(() => '---').join('-+-')\n const body = rows\n .map((row) => row.map((c) => String(c ?? '')).join(' | '))\n .join('\\n')\n\n return `<pre>${esc(header)}\\n${esc(separator)}\\n${esc(body)}</pre>\\n\\n`\n }\n\n case 'list': {\n const ordered = p.ordered as boolean | undefined\n const items = node.children\n .filter((c): c is DocNode => typeof c !== 'string')\n .map((item, i) => {\n const prefix = ordered ? `${i + 1}.` : '•'\n return `${prefix} ${esc(getTextContent(item.children))}`\n })\n .join('\\n')\n return `${items}\\n\\n`\n }\n\n case 'code': {\n const lang = (p.language as string) ?? ''\n const text = esc(getTextContent(node.children))\n if (lang) {\n return `<pre><code class=\"language-${esc(lang)}\">${text}</code></pre>\\n\\n`\n }\n return `<pre>${text}</pre>\\n\\n`\n }\n\n case 'divider':\n case 'page-break':\n return '───────────\\n\\n'\n\n case 'spacer':\n return '\\n'\n\n case 'button': {\n const href = p.href as string\n const text = esc(getTextContent(node.children))\n return `<a href=\"${esc(href)}\">${text}</a>\\n\\n`\n }\n\n case 'quote': {\n const text = esc(getTextContent(node.children))\n return `<blockquote>${text}</blockquote>\\n\\n`\n }\n\n default:\n return ''\n }\n}\n\nexport const telegramRenderer: DocumentRenderer = {\n async render(node: DocNode, _options?: RenderOptions): Promise<string> {\n return renderNode(node).trim()\n },\n}\n"],"mappings":";;;;;;AAcA,SAAS,cAAc,KAAwC;AAC7D,QAAO,OAAO,QAAQ,WAAW,EAAE,QAAQ,KAAK,GAAG;;AAGrD,SAAS,IAAI,KAAqB;AAChC,QAAO,IACJ,QAAQ,MAAM,QAAQ,CACtB,QAAQ,MAAM,OAAO,CACrB,QAAQ,MAAM,OAAO,CACrB,QAAQ,MAAM,SAAS;;AAG5B,SAAS,eAAe,UAA8B;AACpD,QAAO,SACJ,KAAK,MACJ,OAAO,MAAM,WAAW,IAAI,eAAgB,EAAc,SAAS,CACpE,CACA,KAAK,GAAG;;AAGb,SAAS,WAAW,MAAuB;CACzC,MAAM,IAAI,KAAK;AAEf,SAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,QAAO,KAAK,SACT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K,SAAS,CAAC;KACtD,CACD,KAAK,KAAK,CACG;;EAGlB,KAAK,QAAQ;GACX,MAAM,OAAQ,EAAE,YAAuB;GACvC,MAAM,OAAO,IAAI,eAAe,KAAK,SAAS,CAAC;AAC/C,OAAI,KACF,QAAO,8BAA8B,IAAI,KAAK,CAAC,IAAI,KAAK;AAE1D,UAAO,QAAQ,KAAK;;EAGtB,KAAK;EACL,KAAK,aACH,QAAO;EAET,KAAK,SACH,QAAO;EAET,KAAK,UAAU;GACb,MAAM,OAAO,EAAE;GACf,MAAM,OAAO,IAAI,eAAe,KAAK,SAAS,CAAC;AAC/C,UAAO,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK;;EAGxC,KAAK,QAEH,QAAO,eADM,IAAI,eAAe,KAAK,SAAS,CAAC,CACpB;EAG7B,QACE,QAAO;;;AAIb,MAAa,mBAAqC,EAChD,MAAM,OAAO,MAAe,UAA2C;AACrE,QAAO,WAAW,KAAK,CAAC,MAAM;GAEjC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/renderers/text.ts
|
|
2
|
+
function resolveColumn(col) {
|
|
3
|
+
return typeof col === "string" ? { header: col } : col;
|
|
4
|
+
}
|
|
5
|
+
function renderChild(child) {
|
|
6
|
+
if (typeof child === "string") return child;
|
|
7
|
+
return renderNode(child);
|
|
8
|
+
}
|
|
9
|
+
function renderChildren(children) {
|
|
10
|
+
return children.map(renderChild).join("");
|
|
11
|
+
}
|
|
12
|
+
function pad(str, width, align = "left") {
|
|
13
|
+
if (str.length >= width) return str.slice(0, width);
|
|
14
|
+
const diff = width - str.length;
|
|
15
|
+
if (align === "center") {
|
|
16
|
+
const left = Math.floor(diff / 2);
|
|
17
|
+
return " ".repeat(left) + str + " ".repeat(diff - left);
|
|
18
|
+
}
|
|
19
|
+
if (align === "right") return " ".repeat(diff) + str;
|
|
20
|
+
return str + " ".repeat(diff);
|
|
21
|
+
}
|
|
22
|
+
function renderNode(node) {
|
|
23
|
+
const p = node.props;
|
|
24
|
+
switch (node.type) {
|
|
25
|
+
case "document": return renderChildren(node.children);
|
|
26
|
+
case "page": return renderChildren(node.children);
|
|
27
|
+
case "section":
|
|
28
|
+
case "row":
|
|
29
|
+
case "column": return renderChildren(node.children);
|
|
30
|
+
case "heading": {
|
|
31
|
+
const text = renderChildren(node.children);
|
|
32
|
+
const level = p.level ?? 1;
|
|
33
|
+
if (level === 1) return `${text.toUpperCase()}\n${"=".repeat(text.length)}\n\n`;
|
|
34
|
+
if (level === 2) return `${text}\n${"-".repeat(text.length)}\n\n`;
|
|
35
|
+
return `${text}\n\n`;
|
|
36
|
+
}
|
|
37
|
+
case "text": return `${renderChildren(node.children)}\n\n`;
|
|
38
|
+
case "link": return `${renderChildren(node.children)} (${p.href})`;
|
|
39
|
+
case "image": return `[${p.alt ?? "Image"}${p.caption ? ` — ${p.caption}` : ""}]\n\n`;
|
|
40
|
+
case "table": {
|
|
41
|
+
const columns = (p.columns ?? []).map(resolveColumn);
|
|
42
|
+
const rows = p.rows ?? [];
|
|
43
|
+
if (columns.length === 0) return "";
|
|
44
|
+
const widths = columns.map((col, i) => {
|
|
45
|
+
const headerLen = col.header.length;
|
|
46
|
+
const maxDataLen = rows.reduce((max, row) => Math.max(max, String(row[i] ?? "").length), 0);
|
|
47
|
+
return Math.max(headerLen, maxDataLen, 3);
|
|
48
|
+
});
|
|
49
|
+
let result = `${columns.map((col, i) => pad(col.header, widths[i] ?? 3, col.align)).join(" | ")}\n${widths.map((w) => "-".repeat(w ?? 3)).join("-+-")}\n${rows.map((row) => columns.map((col, i) => pad(String(row[i] ?? ""), widths[i] ?? 3, col.align)).join(" | ")).join("\n")}\n\n`;
|
|
50
|
+
if (p.caption) result = `${p.caption}\n\n${result}`;
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
case "list": {
|
|
54
|
+
const ordered = p.ordered;
|
|
55
|
+
return `${node.children.filter((c) => typeof c !== "string").map((item, i) => {
|
|
56
|
+
return ` ${ordered ? `${i + 1}.` : "*"} ${renderChildren(item.children)}`;
|
|
57
|
+
}).join("\n")}\n\n`;
|
|
58
|
+
}
|
|
59
|
+
case "list-item": return renderChildren(node.children);
|
|
60
|
+
case "code": return `${renderChildren(node.children)}\n\n`;
|
|
61
|
+
case "divider": return `${"─".repeat(40)}\n\n`;
|
|
62
|
+
case "page-break": return `\n${"═".repeat(40)}\n\n`;
|
|
63
|
+
case "spacer": return "\n";
|
|
64
|
+
case "button": return `[${renderChildren(node.children)}] → ${p.href}\n\n`;
|
|
65
|
+
case "quote": return ` "${renderChildren(node.children)}"\n\n`;
|
|
66
|
+
default: return renderChildren(node.children);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const textRenderer = { async render(node, _options) {
|
|
70
|
+
return `${renderNode(node).trim()}\n`;
|
|
71
|
+
} };
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { textRenderer };
|
|
75
|
+
//# sourceMappingURL=text-B5U8ucRr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-B5U8ucRr.js","names":[],"sources":["../src/renderers/text.ts"],"sourcesContent":["import type {\n DocChild,\n DocNode,\n DocumentRenderer,\n RenderOptions,\n TableColumn,\n} from '../types'\n\nfunction resolveColumn(col: string | TableColumn): TableColumn {\n return typeof col === 'string' ? { header: col } : col\n}\n\nfunction renderChild(child: DocChild): string {\n if (typeof child === 'string') return child\n return renderNode(child)\n}\n\nfunction renderChildren(children: DocChild[]): string {\n return children.map(renderChild).join('')\n}\n\nfunction pad(\n str: string,\n width: number,\n align: 'left' | 'center' | 'right' = 'left',\n): string {\n if (str.length >= width) return str.slice(0, width)\n const diff = width - str.length\n if (align === 'center') {\n const left = Math.floor(diff / 2)\n return ' '.repeat(left) + str + ' '.repeat(diff - left)\n }\n if (align === 'right') return ' '.repeat(diff) + str\n return str + ' '.repeat(diff)\n}\n\nfunction renderNode(node: DocNode): string {\n const p = node.props\n\n switch (node.type) {\n case 'document':\n return renderChildren(node.children)\n\n case 'page':\n return renderChildren(node.children)\n\n case 'section':\n case 'row':\n case 'column':\n return renderChildren(node.children)\n\n case 'heading': {\n const text = renderChildren(node.children)\n const level = (p.level as number) ?? 1\n if (level === 1)\n return `${text.toUpperCase()}\\n${'='.repeat(text.length)}\\n\\n`\n if (level === 2) return `${text}\\n${'-'.repeat(text.length)}\\n\\n`\n return `${text}\\n\\n`\n }\n\n case 'text':\n return `${renderChildren(node.children)}\\n\\n`\n\n case 'link':\n return `${renderChildren(node.children)} (${p.href})`\n\n case 'image': {\n const alt = (p.alt as string) ?? 'Image'\n const caption = p.caption ? ` — ${p.caption}` : ''\n return `[${alt}${caption}]\\n\\n`\n }\n\n case 'table': {\n const columns = ((p.columns ?? []) as (string | TableColumn)[]).map(\n resolveColumn,\n )\n const rows = (p.rows ?? []) as (string | number)[][]\n\n if (columns.length === 0) return ''\n\n // Calculate column widths\n const widths = columns.map((col, i) => {\n const headerLen = col.header.length\n const maxDataLen = rows.reduce(\n (max, row) => Math.max(max, String(row[i] ?? '').length),\n 0,\n )\n return Math.max(headerLen, maxDataLen, 3)\n })\n\n // Header\n const header = columns\n .map((col, i) => pad(col.header, widths[i] ?? 3, col.align))\n .join(' | ')\n const separator = widths.map((w) => '-'.repeat(w ?? 3)).join('-+-')\n\n // Rows\n const body = rows\n .map((row) =>\n columns\n .map((col, i) =>\n pad(String(row[i] ?? ''), widths[i] ?? 3, col.align),\n )\n .join(' | '),\n )\n .join('\\n')\n\n let result = `${header}\\n${separator}\\n${body}\\n\\n`\n if (p.caption) result = `${p.caption}\\n\\n${result}`\n return result\n }\n\n case 'list': {\n const ordered = p.ordered as boolean | undefined\n return `${node.children\n .filter((c): c is DocNode => typeof c !== 'string')\n .map((item, i) => {\n const prefix = ordered ? `${i + 1}.` : '*'\n return ` ${prefix} ${renderChildren(item.children)}`\n })\n .join('\\n')}\\n\\n`\n }\n\n case 'list-item':\n return renderChildren(node.children)\n\n case 'code':\n return `${renderChildren(node.children)}\\n\\n`\n\n case 'divider':\n return `${'─'.repeat(40)}\\n\\n`\n\n case 'page-break':\n return `\\n${'═'.repeat(40)}\\n\\n`\n\n case 'spacer':\n return '\\n'\n\n case 'button':\n return `[${renderChildren(node.children)}] → ${p.href}\\n\\n`\n\n case 'quote':\n return ` \"${renderChildren(node.children)}\"\\n\\n`\n\n default:\n return renderChildren(node.children)\n }\n}\n\nexport const textRenderer: DocumentRenderer = {\n async render(node: DocNode, _options?: RenderOptions): Promise<string> {\n return `${renderNode(node).trim()}\\n`\n },\n}\n"],"mappings":";AAQA,SAAS,cAAc,KAAwC;AAC7D,QAAO,OAAO,QAAQ,WAAW,EAAE,QAAQ,KAAK,GAAG;;AAGrD,SAAS,YAAY,OAAyB;AAC5C,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAO,WAAW,MAAM;;AAG1B,SAAS,eAAe,UAA8B;AACpD,QAAO,SAAS,IAAI,YAAY,CAAC,KAAK,GAAG;;AAG3C,SAAS,IACP,KACA,OACA,QAAqC,QAC7B;AACR,KAAI,IAAI,UAAU,MAAO,QAAO,IAAI,MAAM,GAAG,MAAM;CACnD,MAAM,OAAO,QAAQ,IAAI;AACzB,KAAI,UAAU,UAAU;EACtB,MAAM,OAAO,KAAK,MAAM,OAAO,EAAE;AACjC,SAAO,IAAI,OAAO,KAAK,GAAG,MAAM,IAAI,OAAO,OAAO,KAAK;;AAEzD,KAAI,UAAU,QAAS,QAAO,IAAI,OAAO,KAAK,GAAG;AACjD,QAAO,MAAM,IAAI,OAAO,KAAK;;AAG/B,SAAS,WAAW,MAAuB;CACzC,MAAM,IAAI,KAAK;AAEf,SAAQ,KAAK,MAAb;EACE,KAAK,WACH,QAAO,eAAe,KAAK,SAAS;EAEtC,KAAK,OACH,QAAO,eAAe,KAAK,SAAS;EAEtC,KAAK;EACL,KAAK;EACL,KAAK,SACH,QAAO,eAAe,KAAK,SAAS;EAEtC,KAAK,WAAW;GACd,MAAM,OAAO,eAAe,KAAK,SAAS;GAC1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E,QAAQ,MAAM;AAC3C,UAAO;;EAGT,KAAK,QAAQ;GACX,MAAM,UAAU,EAAE;AAClB,UAAO,GAAG,KAAK,SACZ,QAAQ,MAAoB,OAAO,MAAM,SAAS,CAClD,KAAK,MAAM,MAAM;AAEhB,WAAO,KADQ,UAAU,GAAG,IAAI,EAAE,KAAK,IACpB,GAAG,eAAe,KAAK,SAAS;KACnD,CACD,KAAK,KAAK,CAAC;;EAGhB,KAAK,YACH,QAAO,eAAe,KAAK,SAAS;EAEtC,KAAK,OACH,QAAO,GAAG,eAAe,KAAK,SAAS,CAAC;EAE1C,KAAK,UACH,QAAO,GAAG,IAAI,OAAO,GAAG,CAAC;EAE3B,KAAK,aACH,QAAO,KAAK,IAAI,OAAO,GAAG,CAAC;EAE7B,KAAK,SACH,QAAO;EAET,KAAK,SACH,QAAO,IAAI,eAAe,KAAK,SAAS,CAAC,MAAM,EAAE,KAAK;EAExD,KAAK,QACH,QAAO,MAAM,eAAe,KAAK,SAAS,CAAC;EAE7C,QACE,QAAO,eAAe,KAAK,SAAS;;;AAI1C,MAAa,eAAiC,EAC5C,MAAM,OAAO,MAAe,UAA2C;AACrE,QAAO,GAAG,WAAW,KAAK,CAAC,MAAM,CAAC;GAErC"}
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type NodeType = 'document' | 'page' | 'section' | 'row' | 'column' | 'heading' | 'text' | 'link' | 'image' | 'table' | 'list' | 'list-item' | 'page-break' | 'code' | 'divider' | 'spacer' | 'button' | 'quote';
|
|
3
|
+
/** A format-agnostic document node. */
|
|
4
|
+
interface DocNode {
|
|
5
|
+
type: NodeType;
|
|
6
|
+
props: Record<string, unknown>;
|
|
7
|
+
children: DocChild[];
|
|
8
|
+
/** Resolved styles from ui-system connector (optional). */
|
|
9
|
+
styles?: ResolvedStyles;
|
|
10
|
+
}
|
|
11
|
+
type DocChild = DocNode | string;
|
|
12
|
+
interface ResolvedStyles {
|
|
13
|
+
fontSize?: number;
|
|
14
|
+
fontFamily?: string;
|
|
15
|
+
fontWeight?: 'normal' | 'bold' | number;
|
|
16
|
+
fontStyle?: 'normal' | 'italic';
|
|
17
|
+
textDecoration?: 'none' | 'underline' | 'line-through';
|
|
18
|
+
color?: string;
|
|
19
|
+
backgroundColor?: string;
|
|
20
|
+
textAlign?: 'left' | 'center' | 'right' | 'justify';
|
|
21
|
+
lineHeight?: number;
|
|
22
|
+
letterSpacing?: number;
|
|
23
|
+
padding?: number | [number, number] | [number, number, number, number];
|
|
24
|
+
margin?: number | [number, number] | [number, number, number, number];
|
|
25
|
+
borderRadius?: number;
|
|
26
|
+
borderWidth?: number;
|
|
27
|
+
borderColor?: string;
|
|
28
|
+
borderStyle?: 'solid' | 'dashed' | 'dotted';
|
|
29
|
+
width?: number | string;
|
|
30
|
+
height?: number | string;
|
|
31
|
+
maxWidth?: number | string;
|
|
32
|
+
opacity?: number;
|
|
33
|
+
}
|
|
34
|
+
interface DocumentProps {
|
|
35
|
+
title?: string;
|
|
36
|
+
author?: string;
|
|
37
|
+
subject?: string;
|
|
38
|
+
keywords?: string[];
|
|
39
|
+
language?: string;
|
|
40
|
+
children?: unknown;
|
|
41
|
+
}
|
|
42
|
+
type PageSize = 'A4' | 'A3' | 'A5' | 'letter' | 'legal' | 'tabloid';
|
|
43
|
+
type PageOrientation = 'portrait' | 'landscape';
|
|
44
|
+
interface PageProps {
|
|
45
|
+
size?: PageSize;
|
|
46
|
+
orientation?: PageOrientation;
|
|
47
|
+
margin?: number | [number, number] | [number, number, number, number];
|
|
48
|
+
children?: unknown;
|
|
49
|
+
/** Header content for this page (PDF/DOCX). */
|
|
50
|
+
header?: DocNode;
|
|
51
|
+
/** Footer content for this page (PDF/DOCX). */
|
|
52
|
+
footer?: DocNode;
|
|
53
|
+
}
|
|
54
|
+
interface SectionProps {
|
|
55
|
+
direction?: 'column' | 'row';
|
|
56
|
+
gap?: number;
|
|
57
|
+
padding?: number | [number, number] | [number, number, number, number];
|
|
58
|
+
background?: string;
|
|
59
|
+
borderRadius?: number;
|
|
60
|
+
border?: string;
|
|
61
|
+
children?: unknown;
|
|
62
|
+
}
|
|
63
|
+
interface RowProps {
|
|
64
|
+
gap?: number;
|
|
65
|
+
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
66
|
+
children?: unknown;
|
|
67
|
+
}
|
|
68
|
+
interface ColumnProps {
|
|
69
|
+
width?: number | string;
|
|
70
|
+
align?: 'start' | 'center' | 'end';
|
|
71
|
+
children?: unknown;
|
|
72
|
+
}
|
|
73
|
+
interface HeadingProps {
|
|
74
|
+
level?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
75
|
+
color?: string;
|
|
76
|
+
align?: 'left' | 'center' | 'right';
|
|
77
|
+
children?: unknown;
|
|
78
|
+
}
|
|
79
|
+
interface TextProps {
|
|
80
|
+
size?: number;
|
|
81
|
+
color?: string;
|
|
82
|
+
bold?: boolean;
|
|
83
|
+
italic?: boolean;
|
|
84
|
+
underline?: boolean;
|
|
85
|
+
strikethrough?: boolean;
|
|
86
|
+
align?: 'left' | 'center' | 'right' | 'justify';
|
|
87
|
+
lineHeight?: number;
|
|
88
|
+
children?: unknown;
|
|
89
|
+
}
|
|
90
|
+
interface LinkProps {
|
|
91
|
+
href: string;
|
|
92
|
+
color?: string;
|
|
93
|
+
children?: unknown;
|
|
94
|
+
}
|
|
95
|
+
interface ImageProps {
|
|
96
|
+
src: string;
|
|
97
|
+
width?: number;
|
|
98
|
+
height?: number;
|
|
99
|
+
alt?: string;
|
|
100
|
+
align?: 'left' | 'center' | 'right';
|
|
101
|
+
caption?: string;
|
|
102
|
+
}
|
|
103
|
+
interface TableColumn {
|
|
104
|
+
header: string;
|
|
105
|
+
width?: number | string;
|
|
106
|
+
align?: 'left' | 'center' | 'right';
|
|
107
|
+
}
|
|
108
|
+
interface TableProps {
|
|
109
|
+
columns: (string | TableColumn)[];
|
|
110
|
+
rows: (string | number)[][];
|
|
111
|
+
headerStyle?: {
|
|
112
|
+
background?: string;
|
|
113
|
+
color?: string;
|
|
114
|
+
bold?: boolean;
|
|
115
|
+
};
|
|
116
|
+
striped?: boolean;
|
|
117
|
+
bordered?: boolean;
|
|
118
|
+
caption?: string;
|
|
119
|
+
/** Keep table together on one page — avoid page breaks within table (PDF/DOCX). */
|
|
120
|
+
keepTogether?: boolean;
|
|
121
|
+
}
|
|
122
|
+
interface ListProps {
|
|
123
|
+
ordered?: boolean;
|
|
124
|
+
children?: unknown;
|
|
125
|
+
}
|
|
126
|
+
interface ListItemProps {
|
|
127
|
+
children?: unknown;
|
|
128
|
+
}
|
|
129
|
+
interface CodeProps {
|
|
130
|
+
language?: string;
|
|
131
|
+
children?: unknown;
|
|
132
|
+
}
|
|
133
|
+
interface DividerProps {
|
|
134
|
+
color?: string;
|
|
135
|
+
thickness?: number;
|
|
136
|
+
}
|
|
137
|
+
interface SpacerProps {
|
|
138
|
+
height: number;
|
|
139
|
+
}
|
|
140
|
+
interface ButtonProps {
|
|
141
|
+
href: string;
|
|
142
|
+
background?: string;
|
|
143
|
+
color?: string;
|
|
144
|
+
borderRadius?: number;
|
|
145
|
+
padding?: number | [number, number];
|
|
146
|
+
align?: 'left' | 'center' | 'right';
|
|
147
|
+
children?: unknown;
|
|
148
|
+
}
|
|
149
|
+
interface QuoteProps {
|
|
150
|
+
borderColor?: string;
|
|
151
|
+
children?: unknown;
|
|
152
|
+
}
|
|
153
|
+
type OutputFormat = 'html' | 'pdf' | 'docx' | 'pptx' | 'email' | 'xlsx' | 'md' | 'text' | 'csv' | 'svg' | 'slack' | 'teams' | 'discord' | 'telegram' | 'notion' | 'confluence' | 'whatsapp' | 'google-chat';
|
|
154
|
+
interface RenderOptions {
|
|
155
|
+
/** Custom styles to apply (overrides component styles). */
|
|
156
|
+
styles?: Record<string, ResolvedStyles>;
|
|
157
|
+
/** Base URL for relative image sources. */
|
|
158
|
+
baseUrl?: string;
|
|
159
|
+
/** Text direction — 'ltr' (default) or 'rtl'. */
|
|
160
|
+
direction?: 'ltr' | 'rtl';
|
|
161
|
+
/** Custom font configuration for PDF. */
|
|
162
|
+
fonts?: Record<string, {
|
|
163
|
+
normal?: string;
|
|
164
|
+
bold?: string;
|
|
165
|
+
italics?: string;
|
|
166
|
+
bolditalics?: string;
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
type RenderResult = string | Uint8Array;
|
|
170
|
+
/** A document renderer that converts a node tree to a specific format. */
|
|
171
|
+
interface DocumentRenderer {
|
|
172
|
+
render(node: DocNode, options?: RenderOptions): Promise<RenderResult>;
|
|
173
|
+
}
|
|
174
|
+
interface DocumentBuilder {
|
|
175
|
+
heading(text: string, props?: Omit<HeadingProps, 'children'>): DocumentBuilder;
|
|
176
|
+
text(text: string, props?: Omit<TextProps, 'children'>): DocumentBuilder;
|
|
177
|
+
paragraph(text: string, props?: Omit<TextProps, 'children'>): DocumentBuilder;
|
|
178
|
+
image(src: string, props?: Omit<ImageProps, 'src'>): DocumentBuilder;
|
|
179
|
+
table(props: TableProps): DocumentBuilder;
|
|
180
|
+
list(items: string[], props?: Omit<ListProps, 'children'>): DocumentBuilder;
|
|
181
|
+
code(text: string, props?: Omit<CodeProps, 'children'>): DocumentBuilder;
|
|
182
|
+
divider(props?: DividerProps): DocumentBuilder;
|
|
183
|
+
spacer(height: number): DocumentBuilder;
|
|
184
|
+
quote(text: string, props?: Omit<QuoteProps, 'children'>): DocumentBuilder;
|
|
185
|
+
button(text: string, props: Omit<ButtonProps, 'children'>): DocumentBuilder;
|
|
186
|
+
link(text: string, props: Omit<LinkProps, 'children'>): DocumentBuilder;
|
|
187
|
+
pageBreak(): DocumentBuilder;
|
|
188
|
+
/** Add a chart snapshot from a @pyreon/charts instance. */
|
|
189
|
+
chart(instance: unknown, props?: {
|
|
190
|
+
width?: number;
|
|
191
|
+
height?: number;
|
|
192
|
+
caption?: string;
|
|
193
|
+
}): DocumentBuilder;
|
|
194
|
+
/** Add a flow diagram snapshot from a @pyreon/flow instance. */
|
|
195
|
+
flow(instance: unknown, props?: {
|
|
196
|
+
width?: number;
|
|
197
|
+
height?: number;
|
|
198
|
+
caption?: string;
|
|
199
|
+
}): DocumentBuilder;
|
|
200
|
+
/** Build the document node tree. */
|
|
201
|
+
build(): DocNode;
|
|
202
|
+
/** Render to a specific format. */
|
|
203
|
+
toHtml(options?: RenderOptions): Promise<string>;
|
|
204
|
+
toPdf(options?: RenderOptions): Promise<Uint8Array>;
|
|
205
|
+
toDocx(options?: RenderOptions): Promise<Uint8Array>;
|
|
206
|
+
toPptx(options?: RenderOptions): Promise<Uint8Array>;
|
|
207
|
+
toEmail(options?: RenderOptions): Promise<string>;
|
|
208
|
+
toXlsx(options?: RenderOptions): Promise<Uint8Array>;
|
|
209
|
+
toMarkdown(options?: RenderOptions): Promise<string>;
|
|
210
|
+
toText(options?: RenderOptions): Promise<string>;
|
|
211
|
+
toCsv(options?: RenderOptions): Promise<string>;
|
|
212
|
+
toSlack(options?: RenderOptions): Promise<string>;
|
|
213
|
+
toSvg(options?: RenderOptions): Promise<string>;
|
|
214
|
+
toTeams(options?: RenderOptions): Promise<string>;
|
|
215
|
+
toDiscord(options?: RenderOptions): Promise<string>;
|
|
216
|
+
toTelegram(options?: RenderOptions): Promise<string>;
|
|
217
|
+
toNotion(options?: RenderOptions): Promise<string>;
|
|
218
|
+
toConfluence(options?: RenderOptions): Promise<string>;
|
|
219
|
+
toWhatsApp(options?: RenderOptions): Promise<string>;
|
|
220
|
+
toGoogleChat(options?: RenderOptions): Promise<string>;
|
|
221
|
+
/** Download the document (browser only). */
|
|
222
|
+
download(filename: string, options?: RenderOptions): Promise<void>;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/builder.d.ts
|
|
226
|
+
/**
|
|
227
|
+
* Create a document using the builder pattern — no JSX needed.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const doc = createDocument({ title: 'Report' })
|
|
232
|
+
* .heading('Sales Report')
|
|
233
|
+
* .text('Q4 performance summary.')
|
|
234
|
+
* .table({ columns: ['Region', 'Revenue'], rows: [['US', '$1M']] })
|
|
235
|
+
*
|
|
236
|
+
* await doc.toPdf()
|
|
237
|
+
* await doc.download('report.pdf')
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
declare function createDocument(props?: DocumentProps): DocumentBuilder;
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/nodes.d.ts
|
|
243
|
+
/** Type guard — checks if a value is a DocNode. */
|
|
244
|
+
declare function isDocNode(value: unknown): value is DocNode;
|
|
245
|
+
/**
|
|
246
|
+
* Root document container. Holds metadata and pages.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```tsx
|
|
250
|
+
* <Document title="Invoice #1234" author="Acme Corp">
|
|
251
|
+
* <Page>...</Page>
|
|
252
|
+
* </Document>
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
declare function Document(props: DocumentProps): DocNode;
|
|
256
|
+
declare namespace Document {
|
|
257
|
+
var _documentType: "document";
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Page container. Maps to a PDF page, DOCX section, or email block.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```tsx
|
|
264
|
+
* <Page size="A4" margin={40}>
|
|
265
|
+
* <Heading>Title</Heading>
|
|
266
|
+
* </Page>
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function Page(props: PageProps): DocNode;
|
|
270
|
+
declare namespace Page {
|
|
271
|
+
var _documentType: "page";
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Layout section — groups content with optional direction, padding, background.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```tsx
|
|
278
|
+
* <Section background="#f5f5f5" padding={20} direction="row" gap={12}>
|
|
279
|
+
* <Text>Left</Text>
|
|
280
|
+
* <Text>Right</Text>
|
|
281
|
+
* </Section>
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
declare function Section(props: SectionProps): DocNode;
|
|
285
|
+
declare namespace Section {
|
|
286
|
+
var _documentType: "section";
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Horizontal layout container.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```tsx
|
|
293
|
+
* <Row gap={20}>
|
|
294
|
+
* <Column width="60%"><Text>Main</Text></Column>
|
|
295
|
+
* <Column width="40%"><Text>Side</Text></Column>
|
|
296
|
+
* </Row>
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
declare function Row(props: RowProps): DocNode;
|
|
300
|
+
declare namespace Row {
|
|
301
|
+
var _documentType: "row";
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Column within a Row.
|
|
305
|
+
*/
|
|
306
|
+
declare function Column(props: ColumnProps): DocNode;
|
|
307
|
+
declare namespace Column {
|
|
308
|
+
var _documentType: "column";
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Heading text (h1–h6).
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```tsx
|
|
315
|
+
* <Heading level={1}>Invoice #1234</Heading>
|
|
316
|
+
* <Heading level={2} color="#666">Details</Heading>
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
declare function Heading(props: HeadingProps): DocNode;
|
|
320
|
+
declare namespace Heading {
|
|
321
|
+
var _documentType: "heading";
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Text paragraph with optional formatting.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```tsx
|
|
328
|
+
* <Text bold size={14} color="#333">Hello World</Text>
|
|
329
|
+
* <Text italic align="right">Subtotal: $100</Text>
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
declare function Text(props: TextProps): DocNode;
|
|
333
|
+
declare namespace Text {
|
|
334
|
+
var _documentType: "text";
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Hyperlink.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```tsx
|
|
341
|
+
* <Link href="https://example.com">Visit site</Link>
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
declare function Link(props: LinkProps): DocNode;
|
|
345
|
+
declare namespace Link {
|
|
346
|
+
var _documentType: "link";
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Image with optional sizing and caption.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```tsx
|
|
353
|
+
* <Image src="/logo.png" width={120} alt="Company Logo" />
|
|
354
|
+
* <Image src={chartDataUrl} width={500} caption="Revenue Chart" />
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
declare function Image(props: ImageProps): DocNode;
|
|
358
|
+
declare namespace Image {
|
|
359
|
+
var _documentType: "image";
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Data table with columns and rows.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```tsx
|
|
366
|
+
* <Table
|
|
367
|
+
* columns={['Name', 'Price', 'Qty']}
|
|
368
|
+
* rows={[['Widget', '$10', '5'], ['Gadget', '$20', '3']]}
|
|
369
|
+
* striped
|
|
370
|
+
* headerStyle={{ background: '#1a1a2e', color: '#fff' }}
|
|
371
|
+
* />
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
declare function Table(props: TableProps): DocNode;
|
|
375
|
+
declare namespace Table {
|
|
376
|
+
var _documentType: "table";
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Ordered or unordered list.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```tsx
|
|
383
|
+
* <List ordered>
|
|
384
|
+
* <ListItem>First item</ListItem>
|
|
385
|
+
* <ListItem>Second item</ListItem>
|
|
386
|
+
* </List>
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
declare function List(props: ListProps): DocNode;
|
|
390
|
+
declare namespace List {
|
|
391
|
+
var _documentType: "list";
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Single list item within a List.
|
|
395
|
+
*/
|
|
396
|
+
declare function ListItem(props: ListItemProps): DocNode;
|
|
397
|
+
declare namespace ListItem {
|
|
398
|
+
var _documentType: "list-item";
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Code block with optional language hint.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```tsx
|
|
405
|
+
* <Code language="typescript">const x = 42</Code>
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare function Code(props: CodeProps): DocNode;
|
|
409
|
+
declare namespace Code {
|
|
410
|
+
var _documentType: "code";
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Horizontal divider line.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```tsx
|
|
417
|
+
* <Divider color="#ddd" thickness={2} />
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare function Divider(props?: DividerProps): DocNode;
|
|
421
|
+
declare namespace Divider {
|
|
422
|
+
var _documentType: "divider";
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Page break — forces content after this point to the next page (PDF/DOCX)
|
|
426
|
+
* or inserts a visual separator (HTML/email).
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```tsx
|
|
430
|
+
* <PageBreak />
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
declare function PageBreak(): DocNode;
|
|
434
|
+
declare namespace PageBreak {
|
|
435
|
+
var _documentType: "page-break";
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Vertical spacer.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```tsx
|
|
442
|
+
* <Spacer height={20} />
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
declare function Spacer(props: SpacerProps): DocNode;
|
|
446
|
+
declare namespace Spacer {
|
|
447
|
+
var _documentType: "spacer";
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* CTA button — renders as a bulletproof button in email, styled link in PDF/DOCX.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```tsx
|
|
454
|
+
* <Button href="https://acme.com/pay" background="#4f46e5" color="#fff">
|
|
455
|
+
* Pay Now
|
|
456
|
+
* </Button>
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
declare function Button(props: ButtonProps): DocNode;
|
|
460
|
+
declare namespace Button {
|
|
461
|
+
var _documentType: "button";
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Block quote.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```tsx
|
|
468
|
+
* <Quote borderColor="#4f46e5">This is a quote.</Quote>
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
declare function Quote(props: QuoteProps): DocNode;
|
|
472
|
+
declare namespace Quote {
|
|
473
|
+
var _documentType: "quote";
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/download.d.ts
|
|
477
|
+
/**
|
|
478
|
+
* Download a document in the browser.
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```tsx
|
|
482
|
+
* await download(doc, 'report.pdf')
|
|
483
|
+
* await download(doc, 'report.docx')
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
declare function download(node: DocNode, filename: string, options?: RenderOptions): Promise<void>;
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/render.d.ts
|
|
489
|
+
/**
|
|
490
|
+
* Register a custom renderer for a format.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```ts
|
|
494
|
+
* registerRenderer('thermal', {
|
|
495
|
+
* render(node, options) {
|
|
496
|
+
* // Walk nodes → ESC/POS commands
|
|
497
|
+
* return escPosBuffer
|
|
498
|
+
* },
|
|
499
|
+
* })
|
|
500
|
+
*
|
|
501
|
+
* await render(receipt, 'thermal')
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
declare function registerRenderer(format: string, renderer: DocumentRenderer | (() => Promise<DocumentRenderer>)): void;
|
|
505
|
+
/**
|
|
506
|
+
* Remove a registered renderer.
|
|
507
|
+
*/
|
|
508
|
+
declare function unregisterRenderer(format: string): void;
|
|
509
|
+
/**
|
|
510
|
+
* Render a document node tree to the specified format.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```tsx
|
|
514
|
+
* const doc = <Document title="Report"><Page>...</Page></Document>
|
|
515
|
+
*
|
|
516
|
+
* const html = await render(doc, 'html') // → HTML string
|
|
517
|
+
* const pdf = await render(doc, 'pdf') // → PDF Uint8Array
|
|
518
|
+
* const docx = await render(doc, 'docx') // → DOCX Uint8Array
|
|
519
|
+
* const email = await render(doc, 'email') // → email-safe HTML string
|
|
520
|
+
* const md = await render(doc, 'md') // → Markdown string
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
declare function render(node: DocNode, format: OutputFormat | string, options?: RenderOptions): Promise<RenderResult>;
|
|
524
|
+
/** @internal For testing — reset renderer registry to defaults. */
|
|
525
|
+
declare function _resetRenderers(): void;
|
|
526
|
+
//#endregion
|
|
527
|
+
export { Button, type ButtonProps, Code, type CodeProps, Column, type ColumnProps, Divider, type DividerProps, type DocChild, type DocNode, Document, type DocumentBuilder, type DocumentProps, type DocumentRenderer, Heading, type HeadingProps, Image, type ImageProps, Link, type LinkProps, List, ListItem, type ListItemProps, type ListProps, type NodeType, type OutputFormat, Page, PageBreak, type PageOrientation, type PageProps, type PageSize, Quote, type QuoteProps, type RenderOptions, type RenderResult, type ResolvedStyles, Row, type RowProps, Section, type SectionProps, Spacer, type SpacerProps, Table, type TableColumn, type TableProps, Text, type TextProps, _resetRenderers, createDocument, download, isDocNode, registerRenderer, render, unregisterRenderer };
|
|
528
|
+
//# sourceMappingURL=index2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../../src/types.ts","../../../src/builder.ts","../../../src/nodes.ts","../../../src/download.ts","../../../src/render.ts"],"mappings":";KAEY,QAAA;AAAZ;AAAA,UAqBiB,OAAA;EACf,IAAA,EAAM,QAAA;EACN,KAAA,EAAO,MAAA;EACP,QAAA,EAAU,QAAA;EAHK;EAKf,MAAA,GAAS,cAAA;AAAA;AAAA,KAGC,QAAA,GAAW,OAAA;AAAA,UAIN,cAAA;EACf,QAAA;EACA,UAAA;EACA,UAAA;EACA,SAAA;EACA,cAAA;EACA,KAAA;EACA,eAAA;EACA,SAAA;EACA,UAAA;EACA,aAAA;EACA,OAAA;EACA,MAAA;EACA,YAAA;EACA,WAAA;EACA,WAAA;EACA,WAAA;EACA,KAAA;EACA,MAAA;EACA,QAAA;EACA,OAAA;AAAA;AAAA,UAKe,aAAA;EACf,KAAA;EACA,MAAA;EACA,OAAA;EACA,QAAA;EACA,QAAA;EACA,QAAA;AAAA;AAAA,KAGU,QAAA;AAAA,KACA,eAAA;AAAA,UAEK,SAAA;EACf,IAAA,GAAO,QAAA;EACP,WAAA,GAAc,eAAA;EACd,MAAA;EACA,QAAA;EA3BA;EA6BA,MAAA,GAAS,OAAA;EA3BT;EA6BA,MAAA,GAAS,OAAA;AAAA;AAAA,UAGM,YAAA;EACf,SAAA;EACA,GAAA;EACA,OAAA;EACA,UAAA;EACA,YAAA;EACA,MAAA;EACA,QAAA;AAAA;AAAA,UAGe,QAAA;EACf,GAAA;EACA,KAAA;EACA,QAAA;AAAA;AAAA,UAGe,WAAA;EACf,KAAA;EACA,KAAA;EACA,QAAA;AAAA;AAAA,UAGe,YAAA;EACf,KAAA;EACA,KAAA;EACA,KAAA;EACA,QAAA;AAAA;AAAA,UAGe,SAAA;EACf,IAAA;EACA,KAAA;EACA,IAAA;EACA,MAAA;EACA,SAAA;EACA,aAAA;EACA,KAAA;EAC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