md2x 0.7.4 → 0.7.5

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 (135) hide show
  1. package/README.md +12 -6
  2. package/dist/chunks/chunk-54X5GPSM.js +1552 -0
  3. package/dist/chunks/chunk-US45GBOT.js +415 -0
  4. package/dist/chunks/docx-exporter-7C6T4DFB.js +1 -0
  5. package/dist/core-worker.js +1764 -0
  6. package/dist/index.js +1 -1
  7. package/dist/md2x.js +5 -5
  8. package/dist/renderer/core-worker-browser.js +1775 -0
  9. package/dist/renderer/live-runtime-canvas.js +1 -1
  10. package/dist/renderer/live-runtime-dot.js +1 -1
  11. package/dist/renderer/live-runtime-html.js +1 -1
  12. package/dist/renderer/live-runtime-infographic.js +1 -1
  13. package/dist/renderer/live-runtime-md2x.js +4 -4
  14. package/dist/renderer/live-runtime-mermaid.js +1 -1
  15. package/dist/renderer/live-runtime-svg.js +1 -1
  16. package/dist/renderer/live-runtime-vega.js +1 -1
  17. package/dist/types/node/src/host/browser-renderer.d.ts +1 -175
  18. package/dist/types/node/src/host/core.d.ts +59 -0
  19. package/dist/types/node/src/host/index.d.ts +4 -49
  20. package/dist/types/node/src/host/node-exporter.d.ts +1 -90
  21. package/dist/types/node/src/host/node-platform.d.ts +1 -23
  22. package/dist/types/node/src/host/templates-data.d.ts +5 -0
  23. package/dist/types/node/src/host/themes-data.d.ts +2385 -0
  24. package/dist/types/node/src/host/types.d.ts +251 -0
  25. package/dist/types/node/src/index.d.ts +2 -3
  26. package/package.json +10 -2
  27. package/dist/chunks/chunk-2LPNL4GA.js +0 -1
  28. package/dist/chunks/chunk-3P5X57NT.js +0 -262
  29. package/dist/chunks/chunk-3VL755NO.js +0 -1
  30. package/dist/chunks/chunk-5DPTQTJJ.js +0 -1
  31. package/dist/chunks/chunk-AK6TXLWO.js +0 -1
  32. package/dist/chunks/chunk-CN4F5HOV.js +0 -5
  33. package/dist/chunks/chunk-CVKZIRZW.js +0 -5
  34. package/dist/chunks/chunk-DFROP2PD.js +0 -11
  35. package/dist/chunks/chunk-DJGIYXVP.js +0 -3
  36. package/dist/chunks/chunk-EFKQH5UR.js +0 -108
  37. package/dist/chunks/chunk-FXZD57XY.js +0 -532
  38. package/dist/chunks/chunk-IENSDROB.js +0 -1
  39. package/dist/chunks/chunk-LLCWR7UA.js +0 -1
  40. package/dist/chunks/chunk-MHCTK6WW.js +0 -1
  41. package/dist/chunks/chunk-NM6J3ND7.js +0 -1
  42. package/dist/chunks/chunk-PARPCLXM.js +0 -1
  43. package/dist/chunks/chunk-PUOHPY5L.js +0 -16
  44. package/dist/chunks/chunk-R65AQGTF.js +0 -1
  45. package/dist/chunks/chunk-R6G2575A.js +0 -3
  46. package/dist/chunks/chunk-TRGQPVRY.js +0 -2
  47. package/dist/chunks/chunk-URO5RPHJ.js +0 -9
  48. package/dist/chunks/chunk-YFL3W3OS.js +0 -1
  49. package/dist/chunks/chunk-Z4LVGK7Y.js +0 -1
  50. package/dist/chunks/docx-exporter-ZZ76JXFU.js +0 -1
  51. package/dist/chunks/rehype-highlight-Y4Q4RX67.js +0 -1
  52. package/dist/chunks/rehype-katex-FXTCTSUE.js +0 -1
  53. package/dist/chunks/rehype-stringify-4CQSSRDL.js +0 -1
  54. package/dist/chunks/remark-gfm-BUZ4SLP3.js +0 -1
  55. package/dist/chunks/remark-math-HEZQAPFK.js +0 -1
  56. package/dist/chunks/remark-parse-QC7TSXTK.js +0 -1
  57. package/dist/chunks/remark-rehype-C2LX643P.js +0 -1
  58. package/dist/chunks/remark-super-sub-EP2AQS54.js +0 -1
  59. package/dist/chunks/theme-manager-AZBU2SLL.js +0 -1
  60. package/dist/chunks/theme-to-css-GLV3WYDU.js +0 -85
  61. package/dist/chunks/unified-PU53JLVJ.js +0 -1
  62. package/dist/chunks/unist-util-visit-SBSD62C6.js +0 -1
  63. package/dist/templates/html/example.html +0 -35
  64. package/dist/templates/svelte/example.svelte +0 -18
  65. package/dist/templates/vue/PrinterComponent.vue +0 -875
  66. package/dist/templates/vue/example.vue +0 -17
  67. package/dist/templates/vue/mapLibre.vue +0 -371
  68. package/dist/themes/code-themes/business-contrast.json +0 -31
  69. package/dist/themes/code-themes/colorful.json +0 -32
  70. package/dist/themes/code-themes/cool-modern.json +0 -31
  71. package/dist/themes/code-themes/high-contrast.json +0 -31
  72. package/dist/themes/code-themes/light-clean.json +0 -31
  73. package/dist/themes/code-themes/warm-book.json +0 -31
  74. package/dist/themes/color-schemes/candy.json +0 -34
  75. package/dist/themes/color-schemes/cool.json +0 -34
  76. package/dist/themes/color-schemes/coral.json +0 -34
  77. package/dist/themes/color-schemes/dino.json +0 -34
  78. package/dist/themes/color-schemes/forest.json +0 -34
  79. package/dist/themes/color-schemes/garden.json +0 -34
  80. package/dist/themes/color-schemes/neutral.json +0 -34
  81. package/dist/themes/color-schemes/ocean.json +0 -34
  82. package/dist/themes/color-schemes/rainbow.json +0 -43
  83. package/dist/themes/color-schemes/sakura.json +0 -34
  84. package/dist/themes/color-schemes/sepia.json +0 -34
  85. package/dist/themes/color-schemes/space.json +0 -34
  86. package/dist/themes/color-schemes/starry.json +0 -34
  87. package/dist/themes/color-schemes/sunset.json +0 -34
  88. package/dist/themes/color-schemes/warm.json +0 -34
  89. package/dist/themes/font-config.json +0 -184
  90. package/dist/themes/layout-schemes/academic.json +0 -40
  91. package/dist/themes/layout-schemes/book.json +0 -40
  92. package/dist/themes/layout-schemes/document.json +0 -40
  93. package/dist/themes/layout-schemes/magazine.json +0 -40
  94. package/dist/themes/layout-schemes/student.json +0 -40
  95. package/dist/themes/layout-schemes/technical.json +0 -40
  96. package/dist/themes/presets/academic.json +0 -24
  97. package/dist/themes/presets/business.json +0 -22
  98. package/dist/themes/presets/candy.json +0 -23
  99. package/dist/themes/presets/century.json +0 -22
  100. package/dist/themes/presets/coral.json +0 -22
  101. package/dist/themes/presets/default.json +0 -22
  102. package/dist/themes/presets/dinosaur.json +0 -23
  103. package/dist/themes/presets/elegant.json +0 -22
  104. package/dist/themes/presets/forest.json +0 -22
  105. package/dist/themes/presets/garamond.json +0 -22
  106. package/dist/themes/presets/garden.json +0 -23
  107. package/dist/themes/presets/handwritten.json +0 -23
  108. package/dist/themes/presets/heiti.json +0 -22
  109. package/dist/themes/presets/magazine.json +0 -24
  110. package/dist/themes/presets/manuscript.json +0 -22
  111. package/dist/themes/presets/minimal.json +0 -22
  112. package/dist/themes/presets/mixed.json +0 -24
  113. package/dist/themes/presets/newspaper.json +0 -24
  114. package/dist/themes/presets/ocean.json +0 -22
  115. package/dist/themes/presets/palatino.json +0 -22
  116. package/dist/themes/presets/rainbow.json +0 -23
  117. package/dist/themes/presets/space.json +0 -23
  118. package/dist/themes/presets/starry.json +0 -23
  119. package/dist/themes/presets/sunset.json +0 -22
  120. package/dist/themes/presets/swiss.json +0 -22
  121. package/dist/themes/presets/technical.json +0 -22
  122. package/dist/themes/presets/typewriter.json +0 -23
  123. package/dist/themes/presets/verdana.json +0 -22
  124. package/dist/themes/presets/water.json +0 -22
  125. package/dist/themes/registry.json +0 -270
  126. package/dist/themes/table-styles/academic.json +0 -30
  127. package/dist/themes/table-styles/borderless.json +0 -26
  128. package/dist/themes/table-styles/compact.json +0 -24
  129. package/dist/themes/table-styles/grid.json +0 -22
  130. package/dist/themes/table-styles/high-contrast.json +0 -22
  131. package/dist/themes/table-styles/minimal-gray.json +0 -26
  132. package/dist/themes/table-styles/modern-tech.json +0 -34
  133. package/dist/themes/table-styles/professional.json +0 -34
  134. package/dist/themes/table-styles/zebra.json +0 -22
  135. package/dist/types/src/utils/theme-to-css.d.ts +0 -171
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as t,b as r,c as e,d as m,e as p,f as n,h as a,i as d,j as f,k as i,l as s,m as x,n as l,o as u}from"./chunks/chunk-FXZD57XY.js";import"./chunks/chunk-EFKQH5UR.js";import"./chunks/chunk-DFROP2PD.js";import"./chunks/chunk-3P5X57NT.js";import"./chunks/chunk-CVKZIRZW.js";import"./chunks/chunk-DJGIYXVP.js";import"./chunks/chunk-URO5RPHJ.js";import"./chunks/chunk-YFL3W3OS.js";import"./chunks/chunk-3VL755NO.js";import"./chunks/chunk-2LPNL4GA.js";import"./chunks/chunk-MHCTK6WW.js";import"./chunks/chunk-R6G2575A.js";import"./chunks/chunk-AK6TXLWO.js";import"./chunks/chunk-PUOHPY5L.js";import"./chunks/chunk-R65AQGTF.js";import"./chunks/chunk-TRGQPVRY.js";import"./chunks/chunk-CN4F5HOV.js";import"./chunks/chunk-LLCWR7UA.js";import"./chunks/chunk-PARPCLXM.js";import"./chunks/chunk-IENSDROB.js";import"./chunks/chunk-5DPTQTJJ.js";import"./chunks/chunk-Z4LVGK7Y.js";import"./chunks/chunk-NM6J3ND7.js";import*as o from"path";import{fileURLToPath as O}from"url";var _=O(import.meta.url),T=o.dirname(_);globalThis.__md2x_module_dir__=T;export{t as NodeDocxExporter,m as NodeHtmlExporter,e as NodeImageExporter,r as NodePdfExporter,l as convert,u as convertFile,n as frontMatterToOptions,a as markdownToDocxBuffer,i as markdownToHtmlBuffer,f as markdownToHtmlString,s as markdownToImageBuffer,x as markdownToImageBuffers,d as markdownToPdfBuffer,p as parseFrontMatter};
1
+ import{b as t,c as r,e,f as a,g as n,h as m,i as d,j as p,k as i,l as f,m as s,n as l,o as O,p as u,q as x,r as T}from"./chunks/chunk-54X5GPSM.js";import"./chunks/chunk-US45GBOT.js";import*as o from"path";import{fileURLToPath as M}from"url";var g=M(import.meta.url),w=o.dirname(g);globalThis.__md2x_module_dir__=w;export{n as NodeDocxExporter,p as NodeHtmlExporter,d as NodeImageExporter,m as NodePdfExporter,x as convert,T as convertFile,r as frontMatterToOptions,i as markdownToDocxBuffer,e as markdownToHtml,l as markdownToHtmlBuffer,s as markdownToHtmlString,O as markdownToImageBuffer,u as markdownToImageBuffers,f as markdownToPdfBuffer,a as markdownToStandaloneHtml,t as parseFrontMatter};
package/dist/md2x.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{e as _,f as R,g as y,n as j}from"./chunks/chunk-FXZD57XY.js";import"./chunks/chunk-EFKQH5UR.js";import"./chunks/chunk-DFROP2PD.js";import"./chunks/chunk-3P5X57NT.js";import"./chunks/chunk-CVKZIRZW.js";import"./chunks/chunk-DJGIYXVP.js";import"./chunks/chunk-URO5RPHJ.js";import"./chunks/chunk-YFL3W3OS.js";import"./chunks/chunk-3VL755NO.js";import"./chunks/chunk-2LPNL4GA.js";import"./chunks/chunk-MHCTK6WW.js";import"./chunks/chunk-R6G2575A.js";import"./chunks/chunk-AK6TXLWO.js";import"./chunks/chunk-PUOHPY5L.js";import"./chunks/chunk-R65AQGTF.js";import"./chunks/chunk-TRGQPVRY.js";import"./chunks/chunk-CN4F5HOV.js";import"./chunks/chunk-LLCWR7UA.js";import"./chunks/chunk-PARPCLXM.js";import"./chunks/chunk-IENSDROB.js";import"./chunks/chunk-5DPTQTJJ.js";import"./chunks/chunk-Z4LVGK7Y.js";import"./chunks/chunk-NM6J3ND7.js";import*as l from"fs";import*as n from"path";import{fileURLToPath as C}from"url";var I=C(import.meta.url),k=n.dirname(I);globalThis.__md2x_module_dir__=k;function T(){return globalThis.__md2x_module_dir__||k}function B(r){let e=n.extname(r).toLowerCase();return e===".pdf"?"pdf":e===".docx"?"docx":e===".html"||e===".htm"?"html":e===".png"?"png":e===".jpg"?"jpg":e===".jpeg"?"jpeg":e===".webp"?"webp":null}function N(){let r=T(),e=[n.join(r,"themes","presets"),n.resolve(r,"../../src/themes/presets"),n.resolve(process.cwd(),"src/themes/presets")];for(let t of e)try{if(l.existsSync(t)&&l.statSync(t).isDirectory())return t}catch{}return null}function v(){let r=N();if(!r)return["default"];try{let e=l.readdirSync(r,{withFileTypes:!0}).filter(i=>i.isFile()&&i.name.endsWith(".json")).map(i=>i.name.replace(/\.json$/i,"")).filter(i=>i.length>0).sort();return["default",...Array.from(new Set(e)).filter(i=>i!=="default")]}catch{return["default"]}}function O(r){return r.join(", ")}function $(){let r=v();console.log(`
2
+ import{a as k,b as $,c as S,d as T,q as O}from"./chunks/chunk-54X5GPSM.js";import"./chunks/chunk-US45GBOT.js";import*as a from"fs";import*as n from"path";import{fileURLToPath as U,pathToFileURL as q}from"url";var I=U(import.meta.url),P=n.dirname(I);globalThis.__md2x_module_dir__=P;function N(){return globalThis.__md2x_module_dir__||P}function H(o,e){let t={},s=(m=>{let i=String(m||"").trim();if(!i)return"";try{if(i.toLowerCase().startsWith("file://"))return U(i)}catch{}return n.isAbsolute(i)?i:n.join(e,i)})(o);if(!s||!a.existsSync(s))return t;let r=m=>{let i;try{i=a.statSync(m)}catch{return}if(i.isDirectory()){let x=[];try{x=a.readdirSync(m)}catch{return}for(let E of x)r(n.join(m,E));return}if(!i.isFile())return;let u="";try{u=a.readFileSync(m,"utf-8")}catch{return}let h=n.relative(s,m).split(n.sep).join("/"),g=n.basename(m);t[h]=u,t[g]=u,t[`./${h}`]=u;try{t[q(m).href]=u}catch{}};return r(s),t}function W(o,e){let t={};for(let p of o)Object.assign(t,H(p,e));return t}function X(o){let e=n.extname(o).toLowerCase();return e===".pdf"?"pdf":e===".docx"?"docx":e===".html"||e===".htm"?"html":e===".png"?"png":e===".jpg"?"jpg":e===".jpeg"?"jpeg":e===".webp"?"webp":null}function M(){return["default",...k.themes.map(t=>t.id).sort().filter(t=>t!=="default")]}function B(o){return o.join(", ")}function F(){let o=M();console.log(`
3
3
  md2x - Convert Markdown to PDF, DOCX, HTML, or Image
4
4
 
5
5
  Usage:
@@ -34,8 +34,8 @@ Examples:
34
34
  npx md2x --list-themes
35
35
 
36
36
  Available Themes:
37
- ${O(r)}
38
- `)}function H(){let r=T(),e=[n.join(r,"../package.json"),n.join(r,"../../package.json")];for(let t of e)try{let p=JSON.parse(l.readFileSync(t,"utf-8"));if(p?.version){console.log(`md2x v${p.version}`);return}}catch{}console.log("md2x v1.0.0")}function W(){let r=v();console.log(`
37
+ ${B(o)}
38
+ `)}function z(){let o=N(),e=[n.join(o,"../package.json"),n.join(o,"../../package.json")];for(let t of e)try{let p=JSON.parse(a.readFileSync(t,"utf-8"));if(p?.version){console.log(`md2x v${p.version}`);return}}catch{}console.log("md2x v1.0.0")}function J(){let o=M();console.log(`
39
39
  Available Themes:
40
- `),r.forEach(e=>{console.log(` - ${e}`)}),console.log("")}function X(r){let e={input:"",output:"",theme:"default",format:"pdf",help:!1,version:!1,listThemes:!1,diagramMode:"live",templatesDir:[],liveRuntime:void 0,liveRuntimeUrl:void 0,hrPageBreak:null,_explicit:new Set},t=0,p=[];for(;t<r.length;){let i=r[t];if(i==="--"){t++;continue}if(i==="-h"||i==="--help")e.help=!0;else if(i==="-v"||i==="--version")e.version=!0;else if(i==="--list-themes")e.listThemes=!0;else if(i==="--diagram-mode")if(t++,t<r.length){let o=String(r[t]).toLowerCase();o!=="img"&&o!=="live"&&o!=="none"&&(console.error(`Error: Invalid --diagram-mode "${r[t]}". Must be "img", "live", or "none".`),process.exit(1)),e.diagramMode=o,e._explicit.add("diagramMode")}else console.error("Error: --diagram-mode requires a value (img | live | none)"),process.exit(1);else if(i==="-o"||i==="--output")t++,t<r.length?e.output=r[t]:(console.error("Error: --output requires a file path"),process.exit(1));else if(i==="-t"||i==="--theme")t++,t<r.length?(e.theme=r[t],e._explicit.add("theme")):(console.error("Error: --theme requires a theme name"),process.exit(1));else if(i==="-f"||i==="--format")if(t++,t<r.length){let o=r[t].toLowerCase();o!=="pdf"&&o!=="docx"&&o!=="html"&&o!=="png"&&o!=="jpg"&&o!=="jpeg"&&o!=="webp"&&(console.error(`Error: Invalid format "${r[t]}". Must be "pdf", "docx", "html", "png", "jpg/jpeg", or "webp".`),process.exit(1)),e.format=o,e._explicit.add("format")}else console.error("Error: --format requires a format (pdf, docx, html, png, jpg/jpeg, or webp)"),process.exit(1);else if(i==="--hr-page-break")if(t++,t<r.length){let o=r[t].toLowerCase();o!=="true"&&o!=="false"&&(console.error(`Error: Invalid --hr-page-break "${r[t]}". Must be "true" or "false".`),process.exit(1)),e.hrPageBreak=o==="true",e._explicit.add("hrPageBreak")}else console.error("Error: --hr-page-break requires a value (true | false)"),process.exit(1);else if(i==="--templates-dir")if(t++,t<r.length){let o=String(r[t]).trim();o||(console.error("Error: --templates-dir requires a non-empty path"),process.exit(1)),e.templatesDir.push(o),e._explicit.add("templatesDir")}else console.error("Error: --templates-dir requires a path"),process.exit(1);else if(i==="--live-runtime")if(t++,t<r.length){let o=String(r[t]).toLowerCase();o!=="inline"&&o!=="cdn"&&(console.error(`Error: Invalid --live-runtime "${r[t]}". Must be "inline" or "cdn".`),process.exit(1)),e.liveRuntime=o,e._explicit.add("liveRuntime")}else console.error("Error: --live-runtime requires a value (inline | cdn)"),process.exit(1);else if(i==="--live-runtime-url")if(t++,t<r.length){let o=String(r[t]).trim();o||(console.error("Error: --live-runtime-url requires a non-empty URL"),process.exit(1)),e.liveRuntimeUrl=o,e._explicit.add("liveRuntimeUrl")}else console.error("Error: --live-runtime-url requires a URL"),process.exit(1);else i.startsWith("-")?(console.error(`Error: Unknown option: ${i}`),process.exit(1)):p.push(i);t++}return p.length>0&&(e.input=p[0]),p.length>1&&!e.output&&(e.output=p[1]),e}async function z(){let r=process.argv.slice(2),e=X(r);e.help&&($(),process.exit(0)),e.version&&(H(),process.exit(0)),e.listThemes&&(W(),process.exit(0)),e.input||(console.error(`Error: Input file is required
41
- `),$(),process.exit(1));let t=n.resolve(e.input);l.existsSync(t)||(console.error(`Error: Input file not found: ${t}`),process.exit(1));try{l.accessSync(t,l.constants.R_OK)}catch{console.error(`Error: Cannot read input file: ${t}`),process.exit(1)}let p=l.readFileSync(t,"utf-8"),i=_(p),o=i.hasFrontMatter?R(i.data):{},S=!e._explicit.has("format")&&e.output?B(e.output):null,s=e._explicit.has("format")?e.format:o.format??S??e.format,f=e._explicit.has("theme")?e.theme:o.theme??e.theme,b=s==="png"||s==="jpg"||s==="jpeg"||s==="webp",F=s==="docx"?"img":"live",E=e._explicit.has("diagramMode")?e.diagramMode:o.diagramMode??F,P=e._explicit.has("templatesDir")?e.templatesDir:o.templatesDir??e.templatesDir,U=e._explicit.has("liveRuntime")?e.liveRuntime:o.liveRuntime??e.liveRuntime,A=e._explicit.has("liveRuntimeUrl")?e.liveRuntimeUrl:o.liveRuntimeUrl??e.liveRuntimeUrl,D=e._explicit.has("hrPageBreak")?e.hrPageBreak:o.hrAsPageBreak??!(s==="html"||s==="png"||s==="jpg"||s==="jpeg"||s==="webp"),h=v();h.length>0&&!h.includes(f)&&(console.error(`Error: Unknown theme: ${f}`),console.error(`Available themes: ${O(h)}`),console.error("Tip: run `npx md2x --list-themes` to see the full list."),process.exit(1)),console.log(`Converting: ${n.basename(t)}`),console.log(`Format: ${s.toUpperCase()}`),console.log(`Theme: ${f}`),console.log(`HR as page break: ${D}`),(s==="pdf"||s==="html"||s==="png"||s==="jpg"||s==="jpeg"||s==="webp")&&console.log(`Diagram mode: ${E}`);try{let a=e.output,m=y(s);if(a)a=n.resolve(a);else{let u=n.dirname(t),g=n.basename(t,n.extname(t));a=n.join(u,`${g}${m}`)}let w=n.dirname(a);l.existsSync(w)||l.mkdirSync(w,{recursive:!0});let L=b?{...o.image??{},type:s==="jpg"?"jpeg":s,split:o.image?.split??"auto"}:void 0,c=await j(i.content,{format:s,theme:f,diagramMode:E,hrAsPageBreak:D,basePath:n.dirname(t),title:o.title??n.basename(t,n.extname(t)),pdf:o.pdf,standalone:o.standalone,baseTag:o.baseTag,liveRuntime:U,liveRuntimeUrl:A,cdn:o.cdn,templatesDir:P,image:L,skipFrontMatter:!0});if(b){let u=c.buffers&&c.buffers.length>0?c.buffers:[c.buffer];if(u.length<=1){l.writeFileSync(a,u[0]),console.log(`Output: ${a}`),console.log("Done!");return}let g=a.endsWith(m)?a.slice(0,-m.length):a,x=[];for(let d=0;d<u.length;d++){let q=String(d+1).padStart(3,"0"),M=`${g}.part-${q}${m}`;l.writeFileSync(M,u[d]),x.push(M)}console.log(`Output: ${x[0]} (+${x.length-1} parts)`),console.log("Done!");return}l.writeFileSync(a,c.buffer),console.log(`Output: ${a}`),console.log("Done!")}catch(a){let m=a instanceof Error?a.message:String(a);console.error(`Error during conversion: ${m}`),process.exit(1)}}z().catch(r=>{console.error("Unexpected error:",r),process.exit(1)});
40
+ `),o.forEach(e=>{console.log(` - ${e}`)}),console.log("")}function K(o){let e={input:"",output:"",theme:"default",format:"pdf",help:!1,version:!1,listThemes:!1,diagramMode:"live",templatesDir:[],liveRuntime:void 0,liveRuntimeBaseUrl:void 0,hrPageBreak:null,_explicit:new Set},t=0,p=[];for(;t<o.length;){let s=o[t];if(s==="--"){t++;continue}if(s==="-h"||s==="--help")e.help=!0;else if(s==="-v"||s==="--version")e.version=!0;else if(s==="--list-themes")e.listThemes=!0;else if(s==="--diagram-mode")if(t++,t<o.length){let r=String(o[t]).toLowerCase();r!=="img"&&r!=="live"&&r!=="none"&&(console.error(`Error: Invalid --diagram-mode "${o[t]}". Must be "img", "live", or "none".`),process.exit(1)),e.diagramMode=r,e._explicit.add("diagramMode")}else console.error("Error: --diagram-mode requires a value (img | live | none)"),process.exit(1);else if(s==="-o"||s==="--output")t++,t<o.length?e.output=o[t]:(console.error("Error: --output requires a file path"),process.exit(1));else if(s==="-t"||s==="--theme")t++,t<o.length?(e.theme=o[t],e._explicit.add("theme")):(console.error("Error: --theme requires a theme name"),process.exit(1));else if(s==="-f"||s==="--format")if(t++,t<o.length){let r=o[t].toLowerCase();r!=="pdf"&&r!=="docx"&&r!=="html"&&r!=="png"&&r!=="jpg"&&r!=="jpeg"&&r!=="webp"&&(console.error(`Error: Invalid format "${o[t]}". Must be "pdf", "docx", "html", "png", "jpg/jpeg", or "webp".`),process.exit(1)),e.format=r,e._explicit.add("format")}else console.error("Error: --format requires a format (pdf, docx, html, png, jpg/jpeg, or webp)"),process.exit(1);else if(s==="--hr-page-break")if(t++,t<o.length){let r=o[t].toLowerCase();r!=="true"&&r!=="false"&&(console.error(`Error: Invalid --hr-page-break "${o[t]}". Must be "true" or "false".`),process.exit(1)),e.hrPageBreak=r==="true",e._explicit.add("hrPageBreak")}else console.error("Error: --hr-page-break requires a value (true | false)"),process.exit(1);else if(s==="--templates-dir")if(t++,t<o.length){let r=String(o[t]).trim();r||(console.error("Error: --templates-dir requires a non-empty path"),process.exit(1)),e.templatesDir.push(r),e._explicit.add("templatesDir")}else console.error("Error: --templates-dir requires a path"),process.exit(1);else if(s==="--live-runtime")if(t++,t<o.length){let r=String(o[t]).toLowerCase();r!=="inline"&&r!=="cdn"&&(console.error(`Error: Invalid --live-runtime "${o[t]}". Must be "inline" or "cdn".`),process.exit(1)),e.liveRuntime=r,e._explicit.add("liveRuntime")}else console.error("Error: --live-runtime requires a value (inline | cdn)"),process.exit(1);else if(s==="--live-runtime-url")if(t++,t<o.length){let r=String(o[t]).trim();r||(console.error("Error: --live-runtime-url requires a non-empty URL"),process.exit(1)),e.liveRuntimeBaseUrl=r,e._explicit.add("liveRuntimeBaseUrl")}else console.error("Error: --live-runtime-url requires a URL"),process.exit(1);else s.startsWith("-")?(console.error(`Error: Unknown option: ${s}`),process.exit(1)):p.push(s);t++}return p.length>0&&(e.input=p[0]),p.length>1&&!e.output&&(e.output=p[1]),e}async function V(){let o=process.argv.slice(2),e=K(o);e.help&&(F(),process.exit(0)),e.version&&(z(),process.exit(0)),e.listThemes&&(J(),process.exit(0)),e.input||(console.error(`Error: Input file is required
41
+ `),F(),process.exit(1));let t=n.resolve(e.input);a.existsSync(t)||(console.error(`Error: Input file not found: ${t}`),process.exit(1));try{a.accessSync(t,a.constants.R_OK)}catch{console.error(`Error: Cannot read input file: ${t}`),process.exit(1)}let p=a.readFileSync(t,"utf-8"),s=$(p),r=s.hasFrontMatter?S(s.data):{},m=!e._explicit.has("format")&&e.output?X(e.output):null,i=e._explicit.has("format")?e.format:r.format??m??e.format,u=e._explicit.has("theme")?e.theme:r.theme??e.theme,b=i==="png"||i==="jpg"||i==="jpeg"||i==="webp",h=i==="docx"?"img":"live",g=e._explicit.has("diagramMode")?e.diagramMode:r.diagramMode??h,x=e._explicit.has("templatesDir")?{...r.templates??{},...W(e.templatesDir,n.dirname(t))}:r.templates??{},E=e._explicit.has("liveRuntime")?e.liveRuntime:r.liveRuntime??e.liveRuntime,L=e._explicit.has("liveRuntimeBaseUrl")?e.liveRuntimeBaseUrl:r.liveRuntimeBaseUrl??e.liveRuntimeBaseUrl,_=e._explicit.has("hrPageBreak")?e.hrPageBreak:r.hrAsPageBreak??!(i==="html"||i==="png"||i==="jpg"||i==="jpeg"||i==="webp"),D=M();D.length>0&&!D.includes(u)&&(console.error(`Error: Unknown theme: ${u}`),console.error(`Available themes: ${B(D)}`),console.error("Tip: run `npx md2x --list-themes` to see the full list."),process.exit(1)),console.log(`Converting: ${n.basename(t)}`),console.log(`Format: ${i.toUpperCase()}`),console.log(`Theme: ${u}`),console.log(`HR as page break: ${_}`),(i==="pdf"||i==="html"||i==="png"||i==="jpg"||i==="jpeg"||i==="webp")&&console.log(`Diagram mode: ${g}`);try{let l=e.output,c=T(i);if(l)l=n.resolve(l);else{let f=n.dirname(t),R=n.basename(t,n.extname(t));l=n.join(f,`${R}${c}`)}let y=n.dirname(l);a.existsSync(y)||a.mkdirSync(y,{recursive:!0});let A=b?{...r.image??{},type:i==="jpg"?"jpeg":i,split:r.image?.split??"auto"}:void 0,d=await O(s.content,{format:i,theme:u,diagramMode:g,hrAsPageBreak:_,basePath:n.dirname(t),title:r.title??n.basename(t,n.extname(t)),pdf:r.pdf,standalone:r.standalone,baseTag:r.baseTag,liveRuntime:E,liveRuntimeBaseUrl:L,cdn:r.cdn,templates:x,image:A,skipFrontMatter:!0});if(b){let f=d.buffers&&d.buffers.length>0?d.buffers:[d.buffer];if(f.length<=1){a.writeFileSync(l,f[0]),console.log(`Output: ${l}`),console.log("Done!");return}let R=l.endsWith(c)?l.slice(0,-c.length):l,w=[];for(let v=0;v<f.length;v++){let C=String(v+1).padStart(3,"0"),j=`${R}.part-${C}${c}`;a.writeFileSync(j,f[v]),w.push(j)}console.log(`Output: ${w[0]} (+${w.length-1} parts)`),console.log("Done!");return}a.writeFileSync(l,d.buffer),console.log(`Output: ${l}`),console.log("Done!")}catch(l){let c=l instanceof Error?l.message:String(l);console.error(`Error during conversion: ${c}`),process.exit(1)}}V().catch(o=>{console.error("Unexpected error:",o),process.exit(1)});