mdast2docx 0.3.0 → 0.3.2

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 (46) hide show
  1. package/README.md +242 -242
  2. package/dist/chunk-KWOFOD3W.mjs +31 -0
  3. package/dist/{chunk-M5XHL7AG.mjs → chunk-NMFJ4KIZ.mjs} +2 -2
  4. package/dist/index.d.ts +1 -23
  5. package/dist/index.js +1 -3
  6. package/dist/index.mjs +1 -1
  7. package/dist/{multipart-parser-WKN2UV32.mjs → multipart-parser-I4OTWNXG.mjs} +1 -1
  8. package/dist/plugins/index.d.ts +5 -5
  9. package/dist/plugins/index.js +1 -3
  10. package/dist/plugins/index.mjs +1 -1
  11. package/dist/plugins/node/index.mjs +1 -1
  12. package/dist/plugins/node/node-image.d.ts +1 -1
  13. package/dist/plugins/node/node-image.mjs +1 -1
  14. package/package.json +99 -95
  15. package/dist/chunk-3ZZBJC3M.mjs +0 -1
  16. package/dist/chunk-GP6KO6J3.mjs +0 -3
  17. package/dist/chunk-GS5L4UWU.mjs +0 -1
  18. package/dist/chunk-IW743AEN.mjs +0 -1
  19. package/dist/chunk-LXTXD4UG.mjs +0 -1
  20. package/dist/chunk-Q6Q2NBIZ.mjs +0 -1
  21. package/dist/chunk-QR3NYQYH.mjs +0 -1
  22. package/dist/chunk-YNJKJBFY.mjs +0 -3
  23. package/dist/chunk-Z5DPYROV.mjs +0 -31
  24. package/dist/mdast.d.ts +0 -1076
  25. package/dist/mdast.js +0 -1
  26. package/dist/plugins/html.d.ts +0 -9
  27. package/dist/plugins/html.js +0 -3
  28. package/dist/plugins/html.mjs +0 -1
  29. package/dist/plugins/image.d.ts +0 -41
  30. package/dist/plugins/image.js +0 -1
  31. package/dist/plugins/image.mjs +0 -1
  32. package/dist/plugins/list.d.ts +0 -57
  33. package/dist/plugins/list.js +0 -1
  34. package/dist/plugins/list.mjs +0 -1
  35. package/dist/plugins/math.d.ts +0 -11
  36. package/dist/plugins/math.js +0 -1
  37. package/dist/plugins/math.mjs +0 -1
  38. package/dist/plugins/table.d.ts +0 -26
  39. package/dist/plugins/table.js +0 -1
  40. package/dist/plugins/table.mjs +0 -1
  41. package/dist/section.d.ts +0 -26
  42. package/dist/section.js +0 -3
  43. package/dist/section.mjs +0 -1
  44. package/dist/utils.d.ts +0 -123
  45. package/dist/utils.js +0 -1
  46. package/dist/utils.mjs +0 -1
package/dist/index.d.ts CHANGED
@@ -1,23 +1 @@
1
- import { OutputType } from "docx";
2
- import type { Root } from "mdast";
3
- import { type IDocxProps, type ISectionProps } from "./utils";
4
- /**
5
- * Represents the input Markdown AST tree(s) for conversion.
6
- * Supports either:
7
- * - A single `Root` node (direct conversion)
8
- * - An array of objects `{ ast: Root, props?: ISectionProps }` for fine-grained section-level control.
9
- */
10
- type IInputMDAST = Root | {
11
- ast: Root;
12
- props?: ISectionProps;
13
- }[];
14
- /**
15
- * Converts an MDAST (Markdown Abstract Syntax Tree) into a DOCX document.
16
- * @param astInputs - A single or multiple MDAST trees with optional section properties.
17
- * @param docxProps - General document properties. @see https://docx.js.org/#/usage/document
18
- * @param defaultSectionProps - Default properties for each document section. @see https://docx.js.org/#/usage/sections
19
- * @param outputType - The desired output format (default: `"blob"`). @see https://docx.js.org/#/usage/packers
20
- * @returns A DOCX document in the specified format.
21
- */
22
- export declare const toDocx: (astInputs: IInputMDAST, docxProps?: IDocxProps, defaultSectionProps?: ISectionProps, outputType?: OutputType) => Promise<string | readonly number[] | ArrayBuffer | Uint8Array<ArrayBufferLike> | Blob | Buffer<ArrayBufferLike>>;
23
- export type { ISectionProps, IDocxProps, IInputMDAST };
1
+ export * from "@m2d/core";
package/dist/index.js CHANGED
@@ -1,3 +1 @@
1
- "use strict";var E=Object.create;var D=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var z=(o,n)=>{for(var c in n)D(o,c,{get:n[c],enumerable:!0})},R=(o,n,c,h)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of B(n))!H.call(o,a)&&a!==c&&D(o,a,{get:()=>n[a],enumerable:!(h=v(n,a))||h.enumerable});return o};var A=(o,n,c)=>(c=o!=null?E(F(o)):{},R(n||!o||!o.__esModule?D(c,"default",{value:o,enumerable:!0}):c,o)),j=o=>R(D({},"__esModule",{value:!0}),o);var G={};z(G,{toDocx:()=>X});module.exports=j(G);var g=require("docx");var w=o=>{let n={},c={};return o.forEach(h=>{var a;h.type==="definition"?n[h.identifier.toUpperCase()]=h.url:h.type==="footnoteDefinition"?c[h.identifier.toUpperCase()]={children:h.children}:(a=h.children)!=null&&a.length&&Object.assign(n,w(h.children))}),{definitions:n,footnoteDefinitions:c}},k=o=>{var n,c;return(n=o.children)!=null&&n.length?o.children.map(k).join(""):(c=o.value)!=null?c:""};var O={useTitle:!0,plugins:[]},M={styles:{default:{document:{paragraph:{spacing:{before:175,line:300},alignment:"thaiDistribute"},run:{size:24}},heading1:{paragraph:{spacing:{before:350}}},heading2:{paragraph:{spacing:{before:350}}},heading3:{paragraph:{spacing:{before:350}}},heading4:{paragraph:{spacing:{before:350}}},heading5:{paragraph:{spacing:{before:350}}},heading6:{paragraph:{spacing:{before:350}}}}}};var S=A(require("docx")),L=(o,n,c)=>{let h=async(s,f)=>{var t,d,e;let l=(await Promise.all(c.map(i=>{var P,x;return(x=(P=i.inline)==null?void 0:P.call(i,S,s,f,o,n,a))!=null?x:[]}))).flat(),p=Object.assign({},f,s.data),u=(d=s.url)!=null?d:o[(t=s.identifier)==null?void 0:t.toUpperCase()];switch(s.type){case"text":return[...l,...p.pre?s.value.split(`
2
- `).map(i=>new g.TextRun({text:i,...p,break:1})):[new g.TextRun({text:s.value,...p})]];case"checkbox":return[...l,new g.CheckBox({checked:!!s.checked})];case"break":return[...l,new g.TextRun({break:1})];case"inlineCode":return[...l,new g.TextRun({text:s.value,...p,style:"code",font:{name:"Consolas"}})];case"emphasis":return p.italics=!0,[...l,...await a(s,p)];case"strong":return p.bold=!0,[...l,...await a(s,p)];case"delete":return p.strike=!0,[...l,...await a(s,p)];case"link":case"linkReference":return p.underline={},[...l,u.startsWith("#")?new g.InternalHyperlink({anchor:u.slice(1),children:await a(s,p)}):new g.ExternalHyperlink({link:u,children:await a(s,p)})];case"footnoteReference":return[...l,new g.FootnoteReferenceRun((e=n[s.identifier].id)!=null?e:0)];case"fragment":return[...l,...await a(s,p)];case"":return[...l];default:return console.warn(`Unsupported inline node type: ${s.type}`),[...l]}},a=async(s,f={})=>{var l,p;return(await Promise.all((p=(l=s.children)==null?void 0:l.map(u=>h(u,f)))!=null?p:[])).flat()};return a},C=async(o,n,c,h)=>{let{plugins:a,useTitle:s,...f}={...O,...h};a.forEach(t=>{var d;return(d=t==null?void 0:t.preprocess)==null?void 0:d.call(t,o)});let l=L(n,c,a),p=async(t,d)=>{var P,x,m,I;let e={...d},i=(await Promise.all(a.map(y=>{var b,T;return(T=(b=y.block)==null?void 0:b.call(y,S,t,e,u,l))!=null?T:[]}))).flat();switch(Object.assign(e,t.data),t.type){case"paragraph":{let y=e.pre?{alignment:"left"}:{},b=typeof e.checked=="boolean"?[new g.CheckBox({checked:e.checked,checkedState:{value:"2611"},uncheckedState:{value:"2610"}}),new g.TextRun(" ")]:[];return[...i,new g.Paragraph({...y,...e,children:[...b,...await l(t,e)]})]}case"heading":return[new g.Paragraph({...e,...i,heading:s?t.depth===1?"Title":`Heading${t.depth-1}`:`Heading${t.depth}`,children:[new g.Bookmark({id:k(t).replace(/[. ]+/g,"-").toLowerCase(),children:await l(t,e)})]})];case"code":return[...i,new g.Paragraph({border:{bottom:{style:g.BorderStyle.SINGLE,space:5,size:1},left:{style:g.BorderStyle.SINGLE,space:10,size:1},right:{style:g.BorderStyle.SINGLE,space:5,size:1},top:{style:g.BorderStyle.SINGLE,space:6,size:1}},...e,alignment:"left",style:"blockCode",children:t.value.split(`
3
- `).map((y,b)=>new g.TextRun({...e,text:y,break:b===0?0:1,style:"code",font:{name:"Consolas"}}))})];case"list":return t.ordered?(e.bullet={level:((x=(P=e.bullet)==null?void 0:P.level)!=null?x:-1)+1},console.warn("Please add numbering plugin to support ordered lists. For now, we use only bullets for both the ordered and the unordered list.")):e.bullet={level:((I=(m=e.bullet)==null?void 0:m.level)!=null?I:-1)+1},[...i,...await u(t,e)];case"blockquote":return[...i,...await u(t,e)];case"listItem":return e.checked=t.checked,[...i,...await u(t,e)];case"thematicBreak":return[...i,new g.Paragraph({...t.data,border:{top:{style:g.BorderStyle.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return i;case"table":return console.warn("Please add table plugin to support tables."),i;case"fragment":return[...i,...await u(t,e)];case"":return i;case"yaml":case"html":default:return console.warn(`May be an unsupported node type: ${t.type}`,t),i}},u=async(t,d)=>{var e;return(await Promise.all((e=t.children)==null?void 0:e.map(i=>p(i,d)))).flat()};return{...f,children:await u(o,{})}};var X=async(o,n={},c={},h="blob")=>{var t;let a=1,s={},f={...M,...n};(t=c==null?void 0:c.plugins)==null||t.forEach(d=>{var e;return(e=d.root)==null?void 0:e.call(d,f)});let l=await Promise.all((Array.isArray(o)?o:[{ast:o}]).map(async({ast:d,props:e})=>{var x;let{definitions:i,footnoteDefinitions:P}=w(d.children);return await Promise.all(Object.values(P).map(async m=>{m.id=a,s[a]=await C({type:"root",children:m.children},i,{}),a++})),(x=e==null?void 0:e.plugins)==null||x.forEach(m=>{var I;return(I=m.root)==null?void 0:I.call(m,f)}),{ast:d,props:{...c,...e},definitions:i,footnoteDefinitions:P}})),p=await Promise.all(l.map(({ast:d,props:e,definitions:i,footnoteDefinitions:P})=>C(d,i,P,e))),u=new g.Document({...f,footnotes:s,sections:p});return g.Packer.pack(u,h)};0&&(module.exports={toDocx});
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,o,f,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==f&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},t=(r,o,f)=>(p(r,o,"default"),f&&p(f,o,"default"));var g=r=>p(a({},"__esModule",{value:!0}),r);var m={};module.exports=g(m);t(m,require("@m2d/core"),module.exports);0&&(module.exports={...require("@m2d/core")});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as p}from"./chunk-YNJKJBFY.mjs";import{a as P,e as h}from"./chunk-IW743AEN.mjs";import"./chunk-3ZZBJC3M.mjs";import{Document as w,Packer as T}from"docx";var k=async(n,d={},e={},x="blob")=>{var y;let s=1,m={},i={...h,...d};(y=e==null?void 0:e.plugins)==null||y.forEach(t=>{var o;return(o=t.root)==null?void 0:o.call(t,i)});let f=await Promise.all((Array.isArray(n)?n:[{ast:n}]).map(async({ast:t,props:o})=>{var I;let{definitions:c,footnoteDefinitions:a}=P(t.children);return await Promise.all(Object.values(a).map(async r=>{r.id=s,m[s]=await p({type:"root",children:r.children},c,{}),s++})),(I=o==null?void 0:o.plugins)==null||I.forEach(r=>{var D;return(D=r.root)==null?void 0:D.call(r,i)}),{ast:t,props:{...e,...o},definitions:c,footnoteDefinitions:a}})),A=await Promise.all(f.map(({ast:t,props:o,definitions:c,footnoteDefinitions:a})=>p(t,c,a,o))),l=new w({...i,footnotes:m,sections:A});return T.pack(l,x)};export{k as toDocx};
1
+ export*from"@m2d/core";
@@ -1,2 +1,2 @@
1
- import{b as F,c as U}from"./chunk-Z5DPYROV.mjs";import"./chunk-3ZZBJC3M.mjs";var f=0,t={START_BOUNDARY:f++,HEADER_FIELD_START:f++,HEADER_FIELD:f++,HEADER_VALUE_START:f++,HEADER_VALUE:f++,HEADER_VALUE_ALMOST_DONE:f++,HEADERS_ALMOST_DONE:f++,PART_DATA_START:f++,PART_DATA:f++,END:f++},w=1,_={PART_BOUNDARY:w,LAST_BOUNDARY:w*=2},O=10,g=13,B=32,m=45,V=58,Y=97,x=122,C=u=>u|32,R=()=>{},y=class{constructor(o){this.index=0,this.flags=0,this.onHeaderEnd=R,this.onHeaderField=R,this.onHeadersEnd=R,this.onHeaderValue=R,this.onPartBegin=R,this.onPartData=R,this.onPartEnd=R,this.boundaryChars={},o=`\r
1
+ import{e as F,f as U}from"./chunk-KWOFOD3W.mjs";var f=0,t={START_BOUNDARY:f++,HEADER_FIELD_START:f++,HEADER_FIELD:f++,HEADER_VALUE_START:f++,HEADER_VALUE:f++,HEADER_VALUE_ALMOST_DONE:f++,HEADERS_ALMOST_DONE:f++,PART_DATA_START:f++,PART_DATA:f++,END:f++},w=1,_={PART_BOUNDARY:w,LAST_BOUNDARY:w*=2},O=10,g=13,B=32,m=45,V=58,Y=97,x=122,C=u=>u|32,R=()=>{},y=class{constructor(o){this.index=0,this.flags=0,this.onHeaderEnd=R,this.onHeaderField=R,this.onHeadersEnd=R,this.onHeaderValue=R,this.onPartBegin=R,this.onPartData=R,this.onPartEnd=R,this.boundaryChars={},o=`\r
2
2
  --`+o;let n=new Uint8Array(o.length);for(let r=0;r<o.length;r++)n[r]=o.charCodeAt(r),this.boundaryChars[n[r]]=!0;this.boundary=n,this.lookbehind=new Uint8Array(this.boundary.length+8),this.state=t.START_BOUNDARY}write(o){let n=0,r=o.length,E=this.index,{lookbehind:l,boundary:d,boundaryChars:H,index:e,state:i,flags:A}=this,b=this.boundary.length,p=b-1,N=o.length,a,S,h=c=>{this[c+"Mark"]=n},s=c=>{delete this[c+"Mark"]},D=(c,P,T,k)=>{(P===void 0||P!==T)&&this[c](k&&k.subarray(P,T))},L=(c,P)=>{let T=c+"Mark";T in this&&(P?(D(c,this[T],n,o),delete this[T]):(D(c,this[T],o.length,o),this[T]=0))};for(n=0;n<r;n++)switch(a=o[n],i){case t.START_BOUNDARY:if(e===d.length-2){if(a===m)A|=_.LAST_BOUNDARY;else if(a!==g)return;e++;break}else if(e-1===d.length-2){if(A&_.LAST_BOUNDARY&&a===m)i=t.END,A=0;else if(!(A&_.LAST_BOUNDARY)&&a===O)e=0,D("onPartBegin"),i=t.HEADER_FIELD_START;else return;break}a!==d[e+2]&&(e=-2),a===d[e+2]&&e++;break;case t.HEADER_FIELD_START:i=t.HEADER_FIELD,h("onHeaderField"),e=0;case t.HEADER_FIELD:if(a===g){s("onHeaderField"),i=t.HEADERS_ALMOST_DONE;break}if(e++,a===m)break;if(a===V){if(e===1)return;L("onHeaderField",!0),i=t.HEADER_VALUE_START;break}if(S=C(a),S<Y||S>x)return;break;case t.HEADER_VALUE_START:if(a===B)break;h("onHeaderValue"),i=t.HEADER_VALUE;case t.HEADER_VALUE:a===g&&(L("onHeaderValue",!0),D("onHeaderEnd"),i=t.HEADER_VALUE_ALMOST_DONE);break;case t.HEADER_VALUE_ALMOST_DONE:if(a!==O)return;i=t.HEADER_FIELD_START;break;case t.HEADERS_ALMOST_DONE:if(a!==O)return;D("onHeadersEnd"),i=t.PART_DATA_START;break;case t.PART_DATA_START:i=t.PART_DATA,h("onPartData");case t.PART_DATA:if(E=e,e===0){for(n+=p;n<N&&!(o[n]in H);)n+=b;n-=p,a=o[n]}if(e<d.length)d[e]===a?(e===0&&L("onPartData",!0),e++):e=0;else if(e===d.length)e++,a===g?A|=_.PART_BOUNDARY:a===m?A|=_.LAST_BOUNDARY:e=0;else if(e-1===d.length)if(A&_.PART_BOUNDARY){if(e=0,a===O){A&=~_.PART_BOUNDARY,D("onPartEnd"),D("onPartBegin"),i=t.HEADER_FIELD_START;break}}else A&_.LAST_BOUNDARY&&a===m?(D("onPartEnd"),i=t.END,A=0):e=0;if(e>0)l[e-1]=a;else if(E>0){let c=new Uint8Array(l.buffer,l.byteOffset,l.byteLength);D("onPartData",0,E,c),E=0,h("onPartData"),n--}break;case t.END:break;default:throw new Error(`Unexpected state entered: ${i}`)}L("onHeaderField"),L("onHeaderValue"),L("onPartData"),this.index=e,this.state=i,this.flags=A}end(){if(this.state===t.HEADER_FIELD_START&&this.index===0||this.state===t.PART_DATA&&this.index===this.boundary.length)this.onPartEnd();else if(this.state!==t.END)throw new Error("MultipartParser.end(): stream ended unexpectedly")}};function I(u){let o=u.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);if(!o)return;let n=o[2]||o[3]||"",r=n.slice(n.lastIndexOf("\\")+1);return r=r.replace(/%22/g,'"'),r=r.replace(/&#(\d{4});/g,(E,l)=>String.fromCharCode(l)),r}async function v(u,o){if(!/multipart/i.test(o))throw new TypeError("Failed to fetch");let n=o.match(/boundary=(?:"([^"]+)"|([^;]+))/i);if(!n)throw new TypeError("no or bad content-type header, no multipart boundary");let r=new y(n[1]||n[2]),E,l,d,H,e,i,A=[],b=new U,p=s=>{d+=h.decode(s,{stream:!0})},N=s=>{A.push(s)},a=()=>{let s=new F(A,i,{type:e});b.append(H,s)},S=()=>{b.append(H,d)},h=new TextDecoder("utf-8");h.decode(),r.onPartBegin=function(){r.onPartData=p,r.onPartEnd=S,E="",l="",d="",H="",e="",i=null,A.length=0},r.onHeaderField=function(s){E+=h.decode(s,{stream:!0})},r.onHeaderValue=function(s){l+=h.decode(s,{stream:!0})},r.onHeaderEnd=function(){if(l+=h.decode(),E=E.toLowerCase(),E==="content-disposition"){let s=l.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);s&&(H=s[2]||s[3]||""),i=I(l),i&&(r.onPartData=N,r.onPartEnd=a)}else E==="content-type"&&(e=l);l="",E=""};for await(let s of u)r.write(s);return r.end(),b}export{v as toFormData};
@@ -1,5 +1,5 @@
1
- export * from "./image";
2
- export * from "./table";
3
- export * from "./list";
4
- export * from "./math";
5
- export * from "./html";
1
+ export * from "@m2d/image";
2
+ export * from "@m2d/table";
3
+ export * from "@m2d/list";
4
+ export * from "@m2d/math";
5
+ export * from "@m2d/html";
@@ -1,3 +1 @@
1
- "use strict";var k=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var te=(e,n)=>{for(var t in n)k(e,t,{get:n[t],enumerable:!0})},ne=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of Z(n))!ee.call(e,a)&&a!==t&&k(e,a,{get:()=>n[a],enumerable:!(r=Q(n,a))||r.enumerable});return e};var re=e=>ne(k({},"__esModule",{value:!0}),e);var Me={};te(Me,{SUPPORTED_IMAGE_TYPES:()=>N,createLevels:()=>V,defaultTableOptions:()=>U,getImageMimeType:()=>_,htmlPlugin:()=>Oe,imagePlugin:()=>ie,listPlugin:()=>me,mathPlugin:()=>fe,parseLatex:()=>F,tablePlugin:()=>le});module.exports=re(Me);var N=["jpeg","jpg","bmp","gif","png"],_=e=>{let n=new Uint8Array(e).slice(0,4);if(n[0]===66&&n[1]===77)return"bmp";switch(n.reduce((r,a)=>r+a.toString(16).padStart(2,"0"),"")){case"89504E47":return"png";case"47494638":return"gif";case"FFD8FFE0":case"FFD8FFE1":case"FFD8FFE2":case"FFD8FFE3":case"FFD8FFE8":return"jpg"}},ae=3,L=async(e,n)=>{var d,u;let t=(d=n==null?void 0:n.scale)!=null?d:ae,r=document.createElement("canvas"),a=r.getContext("2d");if(!a)throw new Error("Canvas context not available");let o=new Image;o.src=e,await new Promise(y=>o.onload=y);let l=o.width*t,p=o.height*t;r.width=l,r.height=p,a.drawImage(o,0,0,l,p);let g=e.split(";")[0].split("/")[1];if(N.includes(g))return{data:e,type:g,transformation:{width:l/t,height:p/t}};let i=(u=n==null?void 0:n.fallbackImageType)!=null?u:"png",c={data:r.toDataURL(`image/${i}`),type:i,transformation:{width:l/t,height:p/t}};return e.includes("svg")?{...c,type:"svg",data:e,fallback:{type:i,data:c.data}}:c},oe=async(e,n)=>{var l;let t=await fetch(e.startsWith("http")?e:`${window.location.origin}/${e.replace(/^\/+/,"")}`);if(/(svg|xml)/.test((l=t.headers.get("content-type"))!=null?l:"")||e.endsWith(".svg")){let p=await t.text();return L(`data:image/svg+xml;base64,${btoa(p)}`,n)}let r=await t.arrayBuffer(),a=_(r)||"png",o=await createImageBitmap(new Blob([r],{type:a}));return N.includes(a)?{type:a,data:r,transformation:{width:o.width,height:o.height}}:(console.warn(`${a} not supported by docx. Using one of the supported mime types.`),L(e,n))},se=async(e,n)=>{try{return e.startsWith("data:")?await L(e,n):await oe(e,n)}catch(t){return console.error(`Error resolving image: ${e}`,t),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},ie=e=>({inline:async(n,t,r,a)=>{var o,l,p,g;if(/^image/.test(t.type)){let i=(l=t.url)!=null?l:a[(o=t.identifier)==null?void 0:o.toUpperCase()],c=(p=t.alt)!=null?p:i==null?void 0:i.split("/").pop();return t.type="",[new n.ImageRun({...await((g=e==null?void 0:e.imageResolver)!=null?g:se)(i,e),altText:{description:c,name:c,title:c}})]}return[]}});var f=require("docx"),E={style:f.BorderStyle.SINGLE,color:"auto",size:1},U={tableProps:{width:{size:100,type:f.WidthType.PERCENTAGE},margins:{top:(0,f.convertMillimetersToTwip)(2),right:(0,f.convertMillimetersToTwip)(4),bottom:(0,f.convertMillimetersToTwip)(2),left:(0,f.convertMillimetersToTwip)(4)},borders:{top:E,right:E,bottom:E,left:E,insideHorizontal:E,insideVertical:E}},rowProps:{},cellProps:{},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:f.ShadingType.SOLID,fill:"b79c2f"}},alignments:{defaultVerticalAlign:f.VerticalAlign.CENTER,defaultHorizontalAlign:f.AlignmentType.CENTER,preferMdData:!0}},le=e=>({block:async(n,t,r,a,o)=>{var s;if(t.type!=="table")return[];let{Table:l,TableRow:p,TableCell:g,Paragraph:i}=n,{tableProps:c,firstRowProps:d,firstRowCellProps:u,rowProps:y,cellProps:O,alignments:R}={...U,...e},D=(s=t.align)==null?void 0:s.map(h=>{switch(h){case"left":return n.AlignmentType.LEFT;case"right":return n.AlignmentType.RIGHT;case"center":return n.AlignmentType.CENTER;default:return}}),C=async(h,I)=>new p({...y,...I===0?d:{},children:await Promise.all(h.children.map(async(T,J)=>new g({verticalAlign:R.defaultVerticalAlign,...O,...I===0?u:{},children:[new i({children:await o(T),alignment:R.preferMdData?D==null?void 0:D[J]:R.defaultHorizontalAlign})]})))}),S=await Promise.all(t.children.map(C));return t.type="",[new l({...c,rows:S})]}});var G=()=>Math.random().toString(16).slice(2);var B=e=>{let n=document.createElement("canvas").getContext("2d");return n?(n.fillStyle=e,n.fillStyle.slice(1)):e.startsWith("#")?e.slice(1):"auto"};var pe=[f.LevelFormat.DECIMAL,f.LevelFormat.DECIMAL,f.LevelFormat.DECIMAL,f.LevelFormat.DECIMAL,f.LevelFormat.UPPER_LETTER,f.LevelFormat.LOWER_LETTER,f.LevelFormat.LOWER_ROMAN,f.LevelFormat.UPPER_ROMAN],V=(e,n=.4,t=.25)=>e.map((r,a)=>({level:a,format:r,text:(r===f.LevelFormat.DECIMAL?Array(a+1).fill(`%${a+1}`).join("."):`%${a+1}`)+".",alignment:f.AlignmentType.START,style:{paragraph:{indent:{left:(0,f.convertInchesToTwip)(n+a*t)}}}})),ce=V(pe),ue=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],ge={levels:ce,bullets:ue,defaultBullets:!1},me=e=>{let n=G(),t=`numbering-${n}`,r=`bullet-${n}`,{levels:a,bulletLevels:o,bullets:l,defaultBullets:p}={...ge,...e};return{block:async(g,i,c,d)=>{var y,O;if(i.type!=="list")return[];let u=((O=(y=c.bullet)==null?void 0:y.level)!=null?O:-1)+1;return c.numbering=p?void 0:{level:u,reference:i.ordered?t:r},c.bullet={level:u},i.type="",await d(i,c)},root:g=>{var i,c;g.numbering={config:[...(c=(i=g.numbering)==null?void 0:i.config)!=null?c:[],{reference:t,levels:a},{reference:r,levels:o!=null?o:a.map((d,u)=>{var y;return{...d,text:(y=l[u])!=null?y:"\u2022",format:f.LevelFormat.BULLET}})}]}}}};var $=require("latex-math"),x=e=>!!(e&&e.openMark==="{"&&e.closeMark==="}"),H=(e,n)=>new e.MathRun(n),de={textasciitilde:"~",textasciicircum:"^",textbackslash:"\u2216",textbar:"|",textless:"<",textgreater:">",neq:"\u2260",sim:"\u223C",simeq:"\u2243",approx:"\u2248",fallingdotseq:"\u2252",risingdotseq:"\u2253",equiv:"\u2261",geq:"\u2265",geqq:"\u2267",leq:"\u2264",leqq:"\u2266",gg:"\u226B",ll:"\u226A",times:"\xD7",div:"\xF7",pm:"\xB1",mp:"\u2213",oplus:"\u2295",ominus:"\u2296",otimes:"\u2297",oslash:"\u2298",circ:"\u2218",cdot:"\u22C5",bullet:"\u2219",ltimes:"\u22C9",rtimes:"\u22CA",in:"\u2208",ni:"\u220B",notin:"\u2209",subset:"\u2282",supset:"\u2283",subseteq:"\u2286",supseteq:"\u2287",nsubseteq:"\u2288",nsupseteq:"\u2289",subsetneq:"\u228A",supsetneq:"\u228B",cap:"\u2229",cup:"\u222A",emptyset:"\u2205",infty:"\u221E",partial:"\u2202",aleph:"\u2135",hbar:"\u210F",wp:"\u2118",Re:"\u211C",Im:"\u2111",alpha:"\u03B1",beta:"\u03B2",gamma:"\u03B3",delta:"\u03B4",epsilon:"\u03F5",zeta:"\u03B6",eta:"\u03B7",theta:"\u03B8",iota:"\u03B9",kappa:"\u03BA",lambda:"\u03BB",mu:"\u03BC",nu:"\u03BD",xi:"\u03BE",pi:"\u03C0",rho:"\u03C1",sigma:"\u03C3",tau:"\u03C4",upsilon:"\u03C5",phi:"\u03D5",chi:"\u03C7",psi:"\u03C8",omega:"\u03C9",varepsilon:"\u03B5",vartheta:"\u03D1",varrho:"\u03F1",varsigma:"\u03C2",varphi:"\u03C6",Gamma:"\u0393",Delta:"\u0394",Theta:"\u0398",Lambda:"\u039B",Xi:"\u039E",Pi:"\u03A0",Sigma:"\u03A3",Upsilon:"\u03A5",Phi:"\u03A6",Psi:"\u03A8",Omega:"\u03A9",int:"\u222B",oint:"\u222E",prod:"\u220F",coprod:"\u2210",sum:"\u2211",log:"log",exp:"exp",lim:"lim",inf:"\u221E",perp:"\u22A5",and:"\u2227",or:"\u2228",not:"\xAC",to:"\u2192",gets:"\u27F9",implies:"\u27F9",impliedby:"\u27F8",forall:"\u2200",exists:"\u2203",empty:"\u2205",nabla:"\u2207",top:"\u22A4",bot:"\u22A5",angle:"\u2220",backslash:"\u2216",neg:"\xAC",lnot:"\xAC",flat:"\u266D",natural:"\u266E",sharp:"\u266F",clubsuit:"\u2663",diamondsuit:"\u2666",heartsuit:"\u2665",spadesuit:"\u2660",varnothing:"\u2205",S:"\u2216",P:"\u220F",bigcap:"\u22C0",bigcup:"\u22C1",bigwedge:"\u2293",bigvee:"\u2294",bigsqcap:"\u2293",bigsqcup:"\u2294",biguplus:"\u2295",bigoplus:"\u2295",bigotimes:"\u2297",bigodot:"\u2299",biginterleave:"\u22BA",bigtimes:"\u2A2F"},P=(e,n)=>{let t=[];for(let r of n)t.push(...j(e,r,t)||[]);return t},he=(e,n,t)=>{var a,o,l,p,g,i,c,d,u,y,O,R,D,C,S;let r=null;switch(n.content){case"newline":case"\\":return null;case"textcolor":{let s=(a=n.args)!=null?a:[];x(s[2])&&(r=P(e,s[2].content));break}case"text":{let s=(o=n.args)!=null?o:[];x(s[0])&&(r=P(e,s[0].content));break}case"^":{let s=t.pop();if(!s)break;let h=P(e,(g=(p=(l=n.args)==null?void 0:l[0])==null?void 0:p.content)!=null?g:[]);if(s.isSum){let T=new e.MathSum({children:[],superScript:h,subScript:s.sub});return T.sub=s.sub,T.sup=h,T.isSum=1,T}else if(s.sub)return new e.MathSubSuperScript({subScript:s.sub,superScript:h,children:[s.prev]});let I=new e.MathSuperScript({children:[s],superScript:h});return I.sup=h,I.prev=s,I}case"_":{let s=t.pop();if(!s)break;let h=P(e,(d=(c=(i=n.args)==null?void 0:i[0])==null?void 0:c.content)!=null?d:[]);if(s.isSum){let T=new e.MathSum({children:[],subScript:h,superScript:s.sup});return T.sup=s.sup,T.sub=h,T.isSum=1,T}else if(s.sup)return new e.MathSubSuperScript({subScript:h,superScript:s.sup,children:[s.prev]});let I=new e.MathSubScript({children:[s],subScript:h});return I.sub=h,I.prev=s,I}case"hat":case"widehat":r=new e.MathAccentCharacter("^");break;case"sum":{let s=new e.MathSum({children:[]});return s.isSum=1,s}case"frac":case"tfrac":case"dfrac":{let s=(u=n.args)!=null?u:[];s.length===2&&x(s[0])&&x(s[1])&&(r=new e.MathFraction({numerator:P(e,s[0].content),denominator:P(e,s[1].content)}));break}case"sqrt":{let s=(y=n.args)!=null?y:[];s.length===1?r=new e.MathRadical({children:P(e,s[0].content)}):s.length===2&&(r=new e.MathRadical(s[0].content?{children:P(e,s[1].content),degree:P(e,s[0].content)}:{children:P(e,s[1].content)}));break}case"left":case"right":case"vec":return[];case"mathbf":return P(e,(D=(R=(O=n.args)==null?void 0:O[0])==null?void 0:R.content)!=null?D:[]);default:r=H(e,(C=de[n.content])!=null?C:n.content)}if((S=t[t.length-1])!=null&&S.isSum&&r){let s=t.pop();return[new e.MathSum({children:Array.isArray(r)?r:[r],superScript:s.sup,subScript:s.sub})]}return r},j=(e,n,t)=>{var a;let r=[];switch(n.type){case"string":r=[H(e,n.content)];break;case"whitespace":r=[H(e," ")];break;case"macro":{let o=he(e,n,t);if(o)r=Array.isArray(o)?o:[o];else return!1;break}case"group":r=P(e,n.content);break;case"environment":break;default:}if(n.type!=="macro"&&((a=t[t.length-1])!=null&&a.isSum)){let o=t.pop();return[new e.MathSum({children:r,superScript:o.sup,subScript:o.sub})]}return r},F=(e,n)=>{let t=(0,$.parseMath)(n),r=[[]],a=r[0];for(let o of t){let l=j(e,o,a);l?a.push(...l):r.push(a=[])}return r},fe=()=>({inline:async(e,n)=>{var t;return n.type!=="inlineMath"&&n.type!=="math"?[]:(n.type="",[new e.Math({children:await F(e,(t=n.value)!=null?t:"").flat()})])},block:async(e,n)=>{var t;return n.type!=="math"&&n.type!=="inlineMath"?[]:(n.type="",await F(e,(t=n.value)!=null?t:"").map(r=>new e.Paragraph({children:[new e.Math({children:r})]})))}});var be=["BR","IMG","EM","I","STRONG","B","DEL","S","A","SUP","SUB","IMG"],ye={BR:"break",IMG:"image",EM:"emphasis",I:"emphasis",STRONG:"strong",B:"strong",DEL:"delete",S:"delete",A:"link"},z=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],Pe=e=>{var r;if(!e)return{};let n={},t=e.match(/border(-\w+)?:\s*[^;]+/gi);if(!t)return{};for(let a of t){let[o,l]=a.split(":").map(u=>u.trim()),p=l.split(/\s+/),g=(r=p.find(u=>u.endsWith("px")))==null?void 0:r.replace("px",""),i=p.find(u=>z.includes(u.toLowerCase())),c=p.find(u=>!u.endsWith("px")&&!z.includes(u.toLowerCase())),d=o==="border"?"border":o.replace("border-","");n[d]={...g?{width:parseInt(g,1)}:{},...i?{style:i}:{},...c?{color:c}:{}}}return n},Te={solid:f.BorderStyle.SINGLE,dashed:f.BorderStyle.DASHED,dotted:f.BorderStyle.DOTTED,double:f.BorderStyle.DOUBLE,none:f.BorderStyle.NONE,ridge:f.BorderStyle.THREE_D_EMBOSS,groove:f.BorderStyle.THREE_D_ENGRAVE,inset:f.BorderStyle.INSET,outset:f.BorderStyle.OUTSET},w=e=>{if(!e||!Object.keys(e).length)return;let{width:n,color:t,style:r}=e,a={style:r?Te[r]:f.BorderStyle.SINGLE};return n&&(a.size=n),t&&(a.color=B(t)),a},X=(e,n=!0)=>{let t={};if(!(e instanceof HTMLElement||e instanceof SVGElement))return t;let{textAlign:r,fontWeight:a,fontStyle:o,textDecoration:l,textTransform:p,color:g}=e.style,i=Pe(e.getAttribute("style"));if(n&&i.border)t.border=w(i.border);else if(Object.keys(i).length){let c={...i.border,...i.left},d={...i.border,...i.right},u={...i.border,...i.top},y={...i.border,...i.bottom};t.border={left:w(c),right:w(d),top:w(u),bottom:w(y)}}switch(r&&(Object.keys(f.AlignmentType).includes(r)?t.alignment=r:r==="justify"&&(t.alignment=f.AlignmentType.JUSTIFIED)),(/bold/.test(a)||parseInt(a)>=500)&&(t.bold=!0),/(italic|oblique)/.test(o)&&(t.italics=!0),l){case"underline":t.underline={};break;case"overline":t.emphasisMark={};break;case"line-through":t.strike=!0;break}return p==="uppercase"&&(t.allCaps=!0),p==="lowercase"&&(t.smallCaps=!0),g&&(t.color=B(g)),e.tagName==="SUP"?t.superScript=!0:e.tagName==="SUB"?t.subScript=!0:["STRONG","B"].includes(e.tagName)?t.bold=!0:["EM","I"].includes(e.tagName)?t.italics=!0:["DEL","S"].includes(e.tagName)?t.strike=!0:["U","INS"].includes(e.tagName)?t.underline={}:e.tagName==="MARK"?(t.highlight="yellow",t.emphasisMark={}):e.tagName==="PRE"&&(t.pre=!0),t},M=e=>{var a,o,l,p;if(!(e instanceof HTMLElement||e instanceof SVGElement))return{type:"text",value:(a=e.textContent)!=null?a:""};let n=Array.from(e.childNodes).map(M),t=X(e),r=e.getAttributeNames().reduce((g,i)=>({...g,[i]:e.getAttribute(i)}),{});switch(e.tagName){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(o=r.src)!=null?o:"",alt:(l=r.alt)!=null?l:"",data:{...t,...r}};case"SVG":return{type:"image",url:`data:image/svg+xml;base64,${e.outerHTML}`,data:t};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:ye[e.tagName],children:n,data:t};case"A":return{type:"link",url:(p=r.href)!=null?p:"",children:n,data:t};case"INPUT":if(/(radio|checkbox)/.test(e.type))return{type:"checkbox"}}return{type:"fragment",children:n,data:t}},K=(e,n)=>Array.from(e.children).map(t=>{let r={...n,...X(t)};return t instanceof HTMLTableRowElement?{type:"tableRow",children:Array.from(t.children).map(a=>({type:"tableCell",children:[M(a)]})),data:r}:K(t,r)}).flat(),v={style:"single"},W={left:v,right:v,top:v,bottom:v},Ie=e=>{let n=X(e);switch(e.tagName){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return{type:"heading",depth:parseInt(e.tagName[1]),children:Array.from(e.childNodes).map(M),data:n};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return A(e,n);case"UL":case"OL":return{type:"list",ordered:e.tagName==="OL",children:Array.from(e.childNodes).map(t=>({type:"listItem",children:[A(t)],data:n}))};case"HR":return{type:"thematicBreak",data:n};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(e.childNodes).map(t=>A(t)),data:n};case"TABLE":return{type:"table",children:K(e),data:n};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet!
2
-
3
- ${e.textContent}`}],data:{...n,pre:!0,border:W}};case"INPUT":if(!/(radio|checkbox)/.test(e.type))return{type:"paragraph",children:[],data:{...n,frame:{width:5e3,height:90,alignment:{x:f.HorizontalPositionAlign.LEFT,y:f.VerticalPositionAlign.CENTER},anchor:{horizontal:f.FrameAnchorType.TEXT,vertical:f.FrameAnchorType.TEXT},type:"alignment"},border:W}}}return{type:"paragraph",children:[M(e)],data:n}},A=(e,n)=>{let t=Array.from(e.childNodes),r=[],a=[];for(let o of t)(o instanceof HTMLElement||o instanceof SVGElement)&&!be.includes(o.tagName)?(a.length&&(r.push({type:"paragraph",children:a.map(M)}),a.length=0),r.push(Ie(o))):a.push(o);return a.length&&r.push({type:"paragraph",children:a.map(M)}),r.length===1?{...r[0],data:{...n,...r[0].data}}:{type:"fragment",children:r,data:n}},Y=e=>{var r,a;let n=[],t=[];for(let o of e.children)if((r=o.children)!=null&&r.length&&Y(o),o.type==="html"&&/^<[^>]*[^/]>$/.test(o.value)){let l=o.value.split(" ")[0].slice(1);l[0]==="/"?((a=t[0])==null?void 0:a.tag)===l.slice(1,-1)&&n.push(t.shift()):t.unshift({...o,children:[],tag:l})}else t.length?t[0].children.push(o):n.push(o);e.children=n},Oe=()=>({block:async(e,n)=>{if(n.type==="html"){let t=document.createElement("div");t.innerHTML=n.value,Object.assign(n,A(t))}return[]},inline:async(e,n)=>{var t,r;if(n.type==="html"){let a=(r=(t=n.value)==null?void 0:t.trim())!=null?r:"",o=a.split(" ")[0].slice(1),l=document.createElement("div");l.innerHTML=a.endsWith("/>")?a:`${a}</${o}>`,Object.assign(n,{...M(l.children[0]),children:n.children})}return[]},preprocess:Y});0&&(module.exports={SUPPORTED_IMAGE_TYPES,createLevels,defaultTableOptions,getImageMimeType,htmlPlugin,imagePlugin,listPlugin,mathPlugin,parseLatex,tablePlugin});
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,e,p,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of c(e))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>e[m],enumerable:!(x=b(e,m))||x.enumerable});return f},r=(f,e,p)=>(t(f,e,"default"),p&&t(p,e,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);r(o,require("@m2d/image"),module.exports);r(o,require("@m2d/table"),module.exports);r(o,require("@m2d/list"),module.exports);r(o,require("@m2d/math"),module.exports);r(o,require("@m2d/html"),module.exports);0&&(module.exports={...require("@m2d/image"),...require("@m2d/table"),...require("@m2d/list"),...require("@m2d/math"),...require("@m2d/html")});
@@ -1 +1 @@
1
- import{a,b}from"../chunk-QR3NYQYH.mjs";import{a as m,b as p}from"../chunk-Q6Q2NBIZ.mjs";import{a as o}from"../chunk-GP6KO6J3.mjs";import{a as r,b as e,c as f}from"../chunk-LXTXD4UG.mjs";import{a as t,b as x}from"../chunk-GS5L4UWU.mjs";import"../chunk-IW743AEN.mjs";import"../chunk-3ZZBJC3M.mjs";export{r as SUPPORTED_IMAGE_TYPES,t as createLevels,m as defaultTableOptions,e as getImageMimeType,o as htmlPlugin,f as imagePlugin,x as listPlugin,b as mathPlugin,a as parseLatex,p as tablePlugin};
1
+ export*from"@m2d/image";export*from"@m2d/table";export*from"@m2d/list";export*from"@m2d/math";export*from"@m2d/html";
@@ -1 +1 @@
1
- import{a as o,b as r}from"../../chunk-M5XHL7AG.mjs";import"../../chunk-Z5DPYROV.mjs";import"../../chunk-3ZZBJC3M.mjs";export{o as SUPPORTED_IMAGE_TYPES,r as nodeImagePlugin};
1
+ import{a as o,b as r}from"../../chunk-NMFJ4KIZ.mjs";import"../../chunk-KWOFOD3W.mjs";export{o as SUPPORTED_IMAGE_TYPES,r as nodeImagePlugin};
@@ -2,7 +2,7 @@
2
2
  * This plugin is not working at the moment because of issues in installing sharp or canvas
3
3
  */
4
4
  import { IImageOptions } from "docx";
5
- import { IPlugin } from "../../utils";
5
+ import { IPlugin } from "@m2d/core";
6
6
  export declare const SUPPORTED_IMAGE_TYPES: readonly ["jpg", "gif", "png"];
7
7
  /**
8
8
  * Resolves an image source URL into the appropriate image options for DOCX conversion.
@@ -1 +1 @@
1
- import{a,b}from"../../chunk-M5XHL7AG.mjs";import"../../chunk-Z5DPYROV.mjs";import"../../chunk-3ZZBJC3M.mjs";export{a as SUPPORTED_IMAGE_TYPES,b as nodeImagePlugin};
1
+ import{a,b}from"../../chunk-NMFJ4KIZ.mjs";import"../../chunk-KWOFOD3W.mjs";export{a as SUPPORTED_IMAGE_TYPES,b as nodeImagePlugin};
package/package.json CHANGED
@@ -1,95 +1,99 @@
1
- {
2
- "name": "mdast2docx",
3
- "author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
4
- "private": false,
5
- "version": "0.3.0",
6
- "description": "Convert Markdown Abstract Syntax Tree (MDAST) to DOCX seamlessly. Supports footnotes, images, links, and customizable document properties.",
7
- "license": "MPL-2.0",
8
- "main": "./dist/index.js",
9
- "module": "./dist/index.mjs",
10
- "types": "./dist/index.d.ts",
11
- "repository": "github:tiny-md/mdast2docx",
12
- "bugs": "https://github.com/tiny-md/mdast2docx/issues",
13
- "homepage": "https://github.com/tiny-md/mdast2docx/#readme",
14
- "sideEffects": false,
15
- "files": [
16
- "dist/**"
17
- ],
18
- "scripts": {
19
- "build": "tsup && tsc -p tsconfig-build.json && gzip -c dist/index.js | wc -c",
20
- "clean": "rm -rf dist",
21
- "dev": "tsup --watch && tsc -p tsconfig-build.json -w",
22
- "typecheck": "tsc --noEmit",
23
- "lint": "eslint src/",
24
- "lint:fix": "eslint src/ --fix",
25
- "test": "vitest run --coverage"
26
- },
27
- "devDependencies": {
28
- "@repo/eslint-config": "workspace:*",
29
- "@repo/typescript-config": "workspace:*",
30
- "@types/mdast": "^4.0.4",
31
- "@types/node": "^22.13.11",
32
- "@unified-latex/unified-latex-types": "^1.8.0",
33
- "@vitest/coverage-v8": "^3.0.9",
34
- "esbuild-plugin-rdi": "^0.0.0",
35
- "jsdom": "^26.0.0",
36
- "node-fetch": "^3.3.2",
37
- "remark-gfm": "^4.0.1",
38
- "remark-parse": "^11.0.0",
39
- "sharp": "0.33.5",
40
- "tsup": "^8.4.0",
41
- "typescript": "^5.8.2",
42
- "unified": "^11.0.5",
43
- "unist": "^0.0.1",
44
- "vite-tsconfig-paths": "^5.1.4",
45
- "vitest": "^3.0.9"
46
- },
47
- "dependencies": {
48
- "latex-math": "^0.0.1"
49
- },
50
- "peerDependencies": {
51
- "docx": "^9.3.0"
52
- },
53
- "funding": [
54
- {
55
- "type": "github",
56
- "url": "https://github.com/sponsors/tiny-md"
57
- },
58
- {
59
- "type": "github",
60
- "url": "https://github.com/sponsors/mayank1513"
61
- }
62
- ],
63
- "keywords": [
64
- "mdast",
65
- "markdown",
66
- "generative-ai",
67
- "docx",
68
- "markdown-to-docx",
69
- "mdast-to-docx",
70
- "converter",
71
- "remark",
72
- "unified",
73
- "footnotes",
74
- "images",
75
- "hyperlinks",
76
- "text-processing",
77
- "document-generator",
78
- "typescript",
79
- "open-source",
80
- "modern",
81
- "customizable",
82
- "seamless-integration",
83
- "cutting-edge",
84
- "compatibility",
85
- "progressive",
86
- "frontend",
87
- "web-development",
88
- "document-generation",
89
- "rich-text",
90
- "export",
91
- "ms-word",
92
- "automation",
93
- "mayank1513"
94
- ]
95
- }
1
+ {
2
+ "name": "mdast2docx",
3
+ "author": "Mayank Kumar Chaudhari (https://mayank-chaudhari.vercel.app)",
4
+ "private": false,
5
+ "version": "0.3.2",
6
+ "description": "Convert Markdown Abstract Syntax Tree (MDAST) to DOCX seamlessly. Supports footnotes, images, links, and customizable document properties.",
7
+ "license": "MPL-2.0",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "repository": "github:tiny-md/mdast2docx",
12
+ "bugs": "https://github.com/tiny-md/mdast2docx/issues",
13
+ "homepage": "https://github.com/tiny-md/mdast2docx/#readme",
14
+ "sideEffects": false,
15
+ "files": [
16
+ "dist/**"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup && tsc -p tsconfig-build.json && gzip -c dist/index.js | wc -c",
20
+ "clean": "rm -rf dist",
21
+ "dev": "tsup --watch && tsc -p tsconfig-build.json -w",
22
+ "typecheck": "tsc --noEmit",
23
+ "lint": "eslint src/",
24
+ "lint:fix": "eslint src/ --fix",
25
+ "test": "vitest run --coverage"
26
+ },
27
+ "devDependencies": {
28
+ "@repo/eslint-config": "workspace:*",
29
+ "@repo/typescript-config": "workspace:*",
30
+ "@types/node": "^22.13.11",
31
+ "@types/unist": "^3.0.3",
32
+ "@vitest/coverage-v8": "^3.0.9",
33
+ "esbuild-plugin-rdi": "^0.0.0",
34
+ "jsdom": "^26.0.0",
35
+ "node-fetch": "^3.3.2",
36
+ "remark-gfm": "^4.0.1",
37
+ "remark-parse": "^11.0.0",
38
+ "sharp": "0.33.5",
39
+ "tsup": "^8.4.0",
40
+ "typescript": "^5.8.2",
41
+ "unified": "^11.0.5",
42
+ "vite-tsconfig-paths": "^5.1.4",
43
+ "vitest": "^3.0.9"
44
+ },
45
+ "dependencies": {
46
+ "@m2d/core": "^0.0.0",
47
+ "@m2d/html": "^0.0.0",
48
+ "@m2d/image": "^0.0.0",
49
+ "@m2d/list": "^0.0.0",
50
+ "@m2d/math": "^0.0.0",
51
+ "@m2d/table": "^0.0.0"
52
+ },
53
+ "peerDependencies": {
54
+ "docx": "^9.3.0"
55
+ },
56
+ "funding": [
57
+ {
58
+ "type": "github",
59
+ "url": "https://github.com/sponsors/tiny-md"
60
+ },
61
+ {
62
+ "type": "github",
63
+ "url": "https://github.com/sponsors/mayank1513"
64
+ }
65
+ ],
66
+ "keywords": [
67
+ "mdast",
68
+ "markdown",
69
+ "generative-ai",
70
+ "docx",
71
+ "markdown-to-docx",
72
+ "mdast-to-docx",
73
+ "converter",
74
+ "remark",
75
+ "unified",
76
+ "footnotes",
77
+ "images",
78
+ "hyperlinks",
79
+ "text-processing",
80
+ "document-generator",
81
+ "typescript",
82
+ "open-source",
83
+ "modern",
84
+ "customizable",
85
+ "seamless-integration",
86
+ "cutting-edge",
87
+ "compatibility",
88
+ "progressive",
89
+ "frontend",
90
+ "web-development",
91
+ "document-generation",
92
+ "rich-text",
93
+ "export",
94
+ "google-sheets",
95
+ "ms-word",
96
+ "automation",
97
+ "mayank1513"
98
+ ]
99
+ }
@@ -1 +0,0 @@
1
- var i=Object.create;var f=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var g=a=>{throw TypeError(a)};var o=(a=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(a,{get:(b,c)=>(typeof require!="undefined"?require:b)[c]}):a)(function(a){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var p=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var n=(a,b,c,d)=>{if(b&&typeof b=="object"||typeof b=="function")for(let e of k(b))!m.call(a,e)&&e!==c&&f(a,e,{get:()=>b[e],enumerable:!(d=j(b,e))||d.enumerable});return a};var q=(a,b,c)=>(c=a!=null?i(l(a)):{},n(b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c,a));var h=(a,b,c)=>b.has(a)||g("Cannot "+c);var r=(a,b,c)=>(h(a,b,"read from private field"),c?c.call(a):b.get(a)),s=(a,b,c)=>b.has(a)?g("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(a):b.set(a,c),t=(a,b,c,d)=>(h(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);export{o as a,p as b,q as c,r as d,s as e,t as f};
@@ -1,3 +0,0 @@
1
- import{f as b}from"./chunk-IW743AEN.mjs";import{AlignmentType as T,BorderStyle as l,FrameAnchorType as N,HorizontalPositionAlign as A,VerticalPositionAlign as R}from"docx";var k=["BR","IMG","EM","I","STRONG","B","DEL","S","A","SUP","SUB","IMG"],C={BR:"break",IMG:"image",EM:"emphasis",I:"emphasis",STRONG:"strong",B:"strong",DEL:"delete",S:"delete",A:"link"},S=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],H=t=>{var n;if(!t)return{};let r={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let s of e){let[a,i]=s.split(":").map(c=>c.trim()),d=i.split(/\s+/),p=(n=d.find(c=>c.endsWith("px")))==null?void 0:n.replace("px",""),o=d.find(c=>S.includes(c.toLowerCase())),m=d.find(c=>!c.endsWith("px")&&!S.includes(c.toLowerCase())),y=a==="border"?"border":a.replace("border-","");r[y]={...p?{width:parseInt(p,1)}:{},...o?{style:o}:{},...m?{color:m}:{}}}return r},O={solid:l.SINGLE,dashed:l.DASHED,dotted:l.DOTTED,double:l.DOUBLE,none:l.NONE,ridge:l.THREE_D_EMBOSS,groove:l.THREE_D_ENGRAVE,inset:l.INSET,outset:l.OUTSET},u=t=>{if(!t||!Object.keys(t).length)return;let{width:r,color:e,style:n}=t,s={style:n?O[n]:l.SINGLE};return r&&(s.size=r),e&&(s.color=b(e)),s},E=(t,r=!0)=>{let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:n,fontWeight:s,fontStyle:a,textDecoration:i,textTransform:d,color:p}=t.style,o=H(t.getAttribute("style"));if(r&&o.border)e.border=u(o.border);else if(Object.keys(o).length){let m={...o.border,...o.left},y={...o.border,...o.right},c={...o.border,...o.top},B={...o.border,...o.bottom};e.border={left:u(m),right:u(y),top:u(c),bottom:u(B)}}switch(n&&(Object.keys(T).includes(n)?e.alignment=n:n==="justify"&&(e.alignment=T.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(e.bold=!0),/(italic|oblique)/.test(a)&&(e.italics=!0),i){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}return d==="uppercase"&&(e.allCaps=!0),d==="lowercase"&&(e.smallCaps=!0),p&&(e.color=b(p)),t.tagName==="SUP"?e.superScript=!0:t.tagName==="SUB"?e.subScript=!0:["STRONG","B"].includes(t.tagName)?e.bold=!0:["EM","I"].includes(t.tagName)?e.italics=!0:["DEL","S"].includes(t.tagName)?e.strike=!0:["U","INS"].includes(t.tagName)?e.underline={}:t.tagName==="MARK"?(e.highlight="yellow",e.emphasisMark={}):t.tagName==="PRE"&&(e.pre=!0),e},h=t=>{var s,a,i,d;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(s=t.textContent)!=null?s:""};let r=Array.from(t.childNodes).map(h),e=E(t),n=t.getAttributeNames().reduce((p,o)=>({...p,[o]:t.getAttribute(o)}),{});switch(t.tagName){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(a=n.src)!=null?a:"",alt:(i=n.alt)!=null?i:"",data:{...e,...n}};case"SVG":return{type:"image",url:`data:image/svg+xml;base64,${t.outerHTML}`,data:e};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:C[t.tagName],children:r,data:e};case"A":return{type:"link",url:(d=n.href)!=null?d:"",children:r,data:e};case"INPUT":if(/(radio|checkbox)/.test(t.type))return{type:"checkbox"}}return{type:"fragment",children:r,data:e}},I=(t,r)=>Array.from(t.children).map(e=>{let n={...r,...E(e)};return e instanceof HTMLTableRowElement?{type:"tableRow",children:Array.from(e.children).map(s=>({type:"tableCell",children:[h(s)]})),data:n}:I(e,n)}).flat(),g={style:"single"},M={left:g,right:g,top:g,bottom:g},D=t=>{let r=E(t);switch(t.tagName){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return{type:"heading",depth:parseInt(t.tagName[1]),children:Array.from(t.childNodes).map(h),data:r};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return f(t,r);case"UL":case"OL":return{type:"list",ordered:t.tagName==="OL",children:Array.from(t.childNodes).map(e=>({type:"listItem",children:[f(e)],data:r}))};case"HR":return{type:"thematicBreak",data:r};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(t.childNodes).map(e=>f(e)),data:r};case"TABLE":return{type:"table",children:I(t),data:r};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet!
2
-
3
- ${t.textContent}`}],data:{...r,pre:!0,border:M}};case"INPUT":if(!/(radio|checkbox)/.test(t.type))return{type:"paragraph",children:[],data:{...r,frame:{width:5e3,height:90,alignment:{x:A.LEFT,y:R.CENTER},anchor:{horizontal:N.TEXT,vertical:N.TEXT},type:"alignment"},border:M}}}return{type:"paragraph",children:[h(t)],data:r}},f=(t,r)=>{let e=Array.from(t.childNodes),n=[],s=[];for(let a of e)(a instanceof HTMLElement||a instanceof SVGElement)&&!k.includes(a.tagName)?(s.length&&(n.push({type:"paragraph",children:s.map(h)}),s.length=0),n.push(D(a))):s.push(a);return s.length&&n.push({type:"paragraph",children:s.map(h)}),n.length===1?{...n[0],data:{...r,...n[0].data}}:{type:"fragment",children:n,data:r}},L=t=>{var n,s;let r=[],e=[];for(let a of t.children)if((n=a.children)!=null&&n.length&&L(a),a.type==="html"&&/^<[^>]*[^/]>$/.test(a.value)){let i=a.value.split(" ")[0].slice(1);i[0]==="/"?((s=e[0])==null?void 0:s.tag)===i.slice(1,-1)&&r.push(e.shift()):e.unshift({...a,children:[],tag:i})}else e.length?e[0].children.push(a):r.push(a);t.children=r},_=()=>({block:async(t,r)=>{if(r.type==="html"){let e=document.createElement("div");e.innerHTML=r.value,Object.assign(r,f(e))}return[]},inline:async(t,r)=>{var e,n;if(r.type==="html"){let s=(n=(e=r.value)==null?void 0:e.trim())!=null?n:"",a=s.split(" ")[0].slice(1),i=document.createElement("div");i.innerHTML=s.endsWith("/>")?s:`${s}</${a}>`,Object.assign(r,{...h(i.children[0]),children:r.children})}return[]},preprocess:L});export{_ as a};
@@ -1 +0,0 @@
1
- import{c as g}from"./chunk-IW743AEN.mjs";import{AlignmentType as v,convertInchesToTwip as O,LevelFormat as e}from"docx";var E=[e.DECIMAL,e.DECIMAL,e.DECIMAL,e.DECIMAL,e.UPPER_LETTER,e.LOWER_LETTER,e.LOWER_ROMAN,e.UPPER_ROMAN],b=(c,o=.4,u=.25)=>c.map((i,t)=>({level:t,format:i,text:(i===e.DECIMAL?Array(t+1).fill(`%${t+1}`).join("."):`%${t+1}`)+".",alignment:v.START,style:{paragraph:{indent:{left:O(o+t*u)}}}})),R=b(E),y=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],A={levels:R,bullets:y,defaultBullets:!1},x=c=>{let o=g(),u=`numbering-${o}`,i=`bullet-${o}`,{levels:t,bulletLevels:f,bullets:m,defaultBullets:I}={...A,...c};return{block:async(L,l,n,a)=>{var s,p;if(l.type!=="list")return[];let r=((p=(s=n.bullet)==null?void 0:s.level)!=null?p:-1)+1;return n.numbering=I?void 0:{level:r,reference:l.ordered?u:i},n.bullet={level:r},l.type="",await a(l,n)},root:L=>{var l,n;L.numbering={config:[...(n=(l=L.numbering)==null?void 0:l.config)!=null?n:[],{reference:u,levels:t},{reference:i,levels:f!=null?f:t.map((a,r)=>{var s;return{...a,text:(s=m[r])!=null?s:"\u2022",format:e.BULLET}})}]}}}};export{b as a,x as b};
@@ -1 +0,0 @@
1
- import{convertInchesToTwip as f,convertMillimetersToTwip as P}from"docx";var i=t=>{let e={},n={};return t.forEach(o=>{var r;o.type==="definition"?e[o.identifier.toUpperCase()]=o.url:o.type==="footnoteDefinition"?n[o.identifier.toUpperCase()]={children:o.children}:(r=o.children)!=null&&r.length&&Object.assign(e,i(o.children))}),{definitions:e,footnoteDefinitions:n}},a=t=>{var e,n;return(e=t.children)!=null&&e.length?t.children.map(a).join(""):(n=t.value)!=null?n:""},s=()=>Math.random().toString(16).slice(2),p={useTitle:!0,plugins:[]},l={styles:{default:{document:{paragraph:{spacing:{before:175,line:300},alignment:"thaiDistribute"},run:{size:24}},heading1:{paragraph:{spacing:{before:350}}},heading2:{paragraph:{spacing:{before:350}}},heading3:{paragraph:{spacing:{before:350}}},heading4:{paragraph:{spacing:{before:350}}},heading5:{paragraph:{spacing:{before:350}}},heading6:{paragraph:{spacing:{before:350}}}}}},c=t=>{let e=document.createElement("canvas").getContext("2d");return e?(e.fillStyle=t,e.fillStyle.slice(1)):t.startsWith("#")?t.slice(1):"auto"};export{i as a,a as b,s as c,p as d,l as e,c as f,f as g,P as h};
@@ -1 +0,0 @@
1
- var I=["jpeg","jpg","bmp","gif","png"],f=e=>{let a=new Uint8Array(e).slice(0,4);if(a[0]===66&&a[1]===77)return"bmp";switch(a.reduce((n,r)=>n+r.toString(16).padStart(2,"0"),"")){case"89504E47":return"png";case"47494638":return"gif";case"FFD8FFE0":case"FFD8FFE1":case"FFD8FFE2":case"FFD8FFE3":case"FFD8FFE8":return"jpg"}},d=3,p=async(e,a)=>{var l,h;let t=(l=a==null?void 0:a.scale)!=null?l:d,n=document.createElement("canvas"),r=n.getContext("2d");if(!r)throw new Error("Canvas context not available");let i=new Image;i.src=e,await new Promise(u=>i.onload=u);let s=i.width*t,g=i.height*t;n.width=s,n.height=g,r.drawImage(i,0,0,s,g);let m=e.split(";")[0].split("/")[1];if(I.includes(m))return{data:e,type:m,transformation:{width:s/t,height:g/t}};let o=(h=a==null?void 0:a.fallbackImageType)!=null?h:"png",c={data:n.toDataURL(`image/${o}`),type:o,transformation:{width:s/t,height:g/t}};return e.includes("svg")?{...c,type:"svg",data:e,fallback:{type:o,data:c.data}}:c},y=async(e,a)=>{var s;let t=await fetch(e.startsWith("http")?e:`${window.location.origin}/${e.replace(/^\/+/,"")}`);if(/(svg|xml)/.test((s=t.headers.get("content-type"))!=null?s:"")||e.endsWith(".svg")){let g=await t.text();return p(`data:image/svg+xml;base64,${btoa(g)}`,a)}let n=await t.arrayBuffer(),r=f(n)||"png",i=await createImageBitmap(new Blob([n],{type:r}));return I.includes(r)?{type:r,data:n,transformation:{width:i.width,height:i.height}}:(console.warn(`${r} not supported by docx. Using one of the supported mime types.`),p(e,a))},w=async(e,a)=>{try{return e.startsWith("data:")?await p(e,a):await y(e,a)}catch(t){return console.error(`Error resolving image: ${e}`,t),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},F=e=>({inline:async(a,t,n,r)=>{var i,s,g,m;if(/^image/.test(t.type)){let o=(s=t.url)!=null?s:r[(i=t.identifier)==null?void 0:i.toUpperCase()],c=(g=t.alt)!=null?g:o==null?void 0:o.split("/").pop();return t.type="",[new a.ImageRun({...await((m=e==null?void 0:e.imageResolver)!=null?m:w)(o,e),altText:{description:c,name:c,title:c}})]}return[]}});export{I as a,f as b,F as c};
@@ -1 +0,0 @@
1
- import{BorderStyle as I,ShadingType as C,WidthType as O,AlignmentType as E,VerticalAlign as D,convertMillimetersToTwip as r}from"docx";var e={style:I.SINGLE,color:"auto",size:1},V={tableProps:{width:{size:100,type:O.PERCENTAGE},margins:{top:r(2),right:r(4),bottom:r(2),left:r(4)},borders:{top:e,right:e,bottom:e,left:e,insideHorizontal:e,insideVertical:e}},rowProps:{},cellProps:{},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:C.SOLID,fill:"b79c2f"}},alignments:{defaultVerticalAlign:D.CENTER,defaultHorizontalAlign:E.CENTER,preferMdData:!0}},N=s=>({block:async(l,t,z,H,P)=>{var a;if(t.type!=="table")return[];let{Table:c,TableRow:f,TableCell:g,Paragraph:T}=l,{tableProps:b,firstRowProps:u,firstRowCellProps:m,rowProps:w,cellProps:y,alignments:o}={...V,...s},i=(a=t.align)==null?void 0:a.map(n=>{switch(n){case"left":return l.AlignmentType.LEFT;case"right":return l.AlignmentType.RIGHT;case"center":return l.AlignmentType.CENTER;default:return}}),d=async(n,p)=>new f({...w,...p===0?u:{},children:await Promise.all(n.children.map(async(A,h)=>new g({verticalAlign:o.defaultVerticalAlign,...y,...p===0?m:{},children:[new T({children:await P(A),alignment:o.preferMdData?i==null?void 0:i[h]:o.defaultHorizontalAlign})]})))}),R=await Promise.all(t.children.map(d));return t.type="",[new c({...b,rows:R})]}});export{V as a,N as b};
@@ -1 +0,0 @@
1
- import{parseMath as R}from"latex-math";var h=t=>!!(t&&t.openMark==="{"&&t.closeMark==="}"),m=(t,a)=>new t.MathRun(a),d={textasciitilde:"~",textasciicircum:"^",textbackslash:"\u2216",textbar:"|",textless:"<",textgreater:">",neq:"\u2260",sim:"\u223C",simeq:"\u2243",approx:"\u2248",fallingdotseq:"\u2252",risingdotseq:"\u2253",equiv:"\u2261",geq:"\u2265",geqq:"\u2267",leq:"\u2264",leqq:"\u2266",gg:"\u226B",ll:"\u226A",times:"\xD7",div:"\xF7",pm:"\xB1",mp:"\u2213",oplus:"\u2295",ominus:"\u2296",otimes:"\u2297",oslash:"\u2298",circ:"\u2218",cdot:"\u22C5",bullet:"\u2219",ltimes:"\u22C9",rtimes:"\u22CA",in:"\u2208",ni:"\u220B",notin:"\u2209",subset:"\u2282",supset:"\u2283",subseteq:"\u2286",supseteq:"\u2287",nsubseteq:"\u2288",nsupseteq:"\u2289",subsetneq:"\u228A",supsetneq:"\u228B",cap:"\u2229",cup:"\u222A",emptyset:"\u2205",infty:"\u221E",partial:"\u2202",aleph:"\u2135",hbar:"\u210F",wp:"\u2118",Re:"\u211C",Im:"\u2111",alpha:"\u03B1",beta:"\u03B2",gamma:"\u03B3",delta:"\u03B4",epsilon:"\u03F5",zeta:"\u03B6",eta:"\u03B7",theta:"\u03B8",iota:"\u03B9",kappa:"\u03BA",lambda:"\u03BB",mu:"\u03BC",nu:"\u03BD",xi:"\u03BE",pi:"\u03C0",rho:"\u03C1",sigma:"\u03C3",tau:"\u03C4",upsilon:"\u03C5",phi:"\u03D5",chi:"\u03C7",psi:"\u03C8",omega:"\u03C9",varepsilon:"\u03B5",vartheta:"\u03D1",varrho:"\u03F1",varsigma:"\u03C2",varphi:"\u03C6",Gamma:"\u0393",Delta:"\u0394",Theta:"\u0398",Lambda:"\u039B",Xi:"\u039E",Pi:"\u03A0",Sigma:"\u03A3",Upsilon:"\u03A5",Phi:"\u03A6",Psi:"\u03A8",Omega:"\u03A9",int:"\u222B",oint:"\u222E",prod:"\u220F",coprod:"\u2210",sum:"\u2211",log:"log",exp:"exp",lim:"lim",inf:"\u221E",perp:"\u22A5",and:"\u2227",or:"\u2228",not:"\xAC",to:"\u2192",gets:"\u27F9",implies:"\u27F9",impliedby:"\u27F8",forall:"\u2200",exists:"\u2203",empty:"\u2205",nabla:"\u2207",top:"\u22A4",bot:"\u22A5",angle:"\u2220",backslash:"\u2216",neg:"\xAC",lnot:"\xAC",flat:"\u266D",natural:"\u266E",sharp:"\u266F",clubsuit:"\u2663",diamondsuit:"\u2666",heartsuit:"\u2665",spadesuit:"\u2660",varnothing:"\u2205",S:"\u2216",P:"\u220F",bigcap:"\u22C0",bigcup:"\u22C1",bigwedge:"\u2293",bigvee:"\u2294",bigsqcap:"\u2293",bigsqcup:"\u2294",biguplus:"\u2295",bigoplus:"\u2295",bigotimes:"\u2297",bigodot:"\u2299",biginterleave:"\u22BA",bigtimes:"\u2A2F"},i=(t,a)=>{let s=[];for(let r of a)s.push(...k(t,r,s)||[]);return s},N=(t,a,s)=>{var p,n,o,g,b,f,M,S,y,w,v,C,O,X,D;let r=null;switch(a.content){case"newline":case"\\":return null;case"textcolor":{let e=(p=a.args)!=null?p:[];h(e[2])&&(r=i(t,e[2].content));break}case"text":{let e=(n=a.args)!=null?n:[];h(e[0])&&(r=i(t,e[0].content));break}case"^":{let e=s.pop();if(!e)break;let u=i(t,(b=(g=(o=a.args)==null?void 0:o[0])==null?void 0:g.content)!=null?b:[]);if(e.isSum){let c=new t.MathSum({children:[],superScript:u,subScript:e.sub});return c.sub=e.sub,c.sup=u,c.isSum=1,c}else if(e.sub)return new t.MathSubSuperScript({subScript:e.sub,superScript:u,children:[e.prev]});let l=new t.MathSuperScript({children:[e],superScript:u});return l.sup=u,l.prev=e,l}case"_":{let e=s.pop();if(!e)break;let u=i(t,(S=(M=(f=a.args)==null?void 0:f[0])==null?void 0:M.content)!=null?S:[]);if(e.isSum){let c=new t.MathSum({children:[],subScript:u,superScript:e.sup});return c.sup=e.sup,c.sub=u,c.isSum=1,c}else if(e.sup)return new t.MathSubSuperScript({subScript:u,superScript:e.sup,children:[e.prev]});let l=new t.MathSubScript({children:[e],subScript:u});return l.sub=u,l.prev=e,l}case"hat":case"widehat":r=new t.MathAccentCharacter("^");break;case"sum":{let e=new t.MathSum({children:[]});return e.isSum=1,e}case"frac":case"tfrac":case"dfrac":{let e=(y=a.args)!=null?y:[];e.length===2&&h(e[0])&&h(e[1])&&(r=new t.MathFraction({numerator:i(t,e[0].content),denominator:i(t,e[1].content)}));break}case"sqrt":{let e=(w=a.args)!=null?w:[];e.length===1?r=new t.MathRadical({children:i(t,e[0].content)}):e.length===2&&(r=new t.MathRadical(e[0].content?{children:i(t,e[1].content),degree:i(t,e[0].content)}:{children:i(t,e[1].content)}));break}case"left":case"right":case"vec":return[];case"mathbf":return i(t,(O=(C=(v=a.args)==null?void 0:v[0])==null?void 0:C.content)!=null?O:[]);default:r=m(t,(X=d[a.content])!=null?X:a.content)}if((D=s[s.length-1])!=null&&D.isSum&&r){let e=s.pop();return[new t.MathSum({children:Array.isArray(r)?r:[r],superScript:e.sup,subScript:e.sub})]}return r},k=(t,a,s)=>{var p;let r=[];switch(a.type){case"string":r=[m(t,a.content)];break;case"whitespace":r=[m(t," ")];break;case"macro":{let n=N(t,a,s);if(n)r=Array.isArray(n)?n:[n];else return!1;break}case"group":r=i(t,a.content);break;case"environment":break;default:}if(a.type!=="macro"&&((p=s[s.length-1])!=null&&p.isSum)){let n=s.pop();return[new t.MathSum({children:r,superScript:n.sup,subScript:n.sub})]}return r},q=(t,a)=>{let s=R(a),r=[[]],p=r[0];for(let n of s){let o=k(t,n,p);o?p.push(...o):r.push(p=[])}return r},P=()=>({inline:async(t,a)=>{var s;return a.type!=="inlineMath"&&a.type!=="math"?[]:(a.type="",[new t.Math({children:await q(t,(s=a.value)!=null?s:"").flat()})])},block:async(t,a)=>{var s;return a.type!=="math"&&a.type!=="inlineMath"?[]:(a.type="",await q(t,(s=a.value)!=null?s:"").map(r=>new t.Paragraph({children:[new t.Math({children:r})]})))}});export{q as a,P as b};
@@ -1,3 +0,0 @@
1
- import{b as C,d as S}from"./chunk-IW743AEN.mjs";import{Bookmark as g,BorderStyle as m,CheckBox as v,ExternalHyperlink as D,FootnoteReferenceRun as R,InternalHyperlink as E,Paragraph as y,TextRun as h}from"docx";import*as B from"docx";var L=(u,k,b)=>{let P=async(r,p)=>{var e,l,t;let s=(await Promise.all(b.map(a=>{var w,f;return(f=(w=a.inline)==null?void 0:w.call(a,B,r,p,u,k,o))!=null?f:[]}))).flat(),n=Object.assign({},p,r.data),c=(l=r.url)!=null?l:u[(e=r.identifier)==null?void 0:e.toUpperCase()];switch(r.type){case"text":return[...s,...n.pre?r.value.split(`
2
- `).map(a=>new h({text:a,...n,break:1})):[new h({text:r.value,...n})]];case"checkbox":return[...s,new v({checked:!!r.checked})];case"break":return[...s,new h({break:1})];case"inlineCode":return[...s,new h({text:r.value,...n,style:"code",font:{name:"Consolas"}})];case"emphasis":return n.italics=!0,[...s,...await o(r,n)];case"strong":return n.bold=!0,[...s,...await o(r,n)];case"delete":return n.strike=!0,[...s,...await o(r,n)];case"link":case"linkReference":return n.underline={},[...s,c.startsWith("#")?new E({anchor:c.slice(1),children:await o(r,n)}):new D({link:c,children:await o(r,n)})];case"footnoteReference":return[...s,new R((t=k[r.identifier].id)!=null?t:0)];case"fragment":return[...s,...await o(r,n)];case"":return[...s];default:return console.warn(`Unsupported inline node type: ${r.type}`),[...s]}},o=async(r,p={})=>{var s,n;return(await Promise.all((n=(s=r.children)==null?void 0:s.map(c=>P(c,p)))!=null?n:[])).flat()};return o},H=async(u,k,b,P)=>{let{plugins:o,useTitle:r,...p}={...S,...P};o.forEach(e=>{var l;return(l=e==null?void 0:e.preprocess)==null?void 0:l.call(e,u)});let s=L(k,b,o),n=async(e,l)=>{var w,f,I,N;let t={...l},a=(await Promise.all(o.map(i=>{var d,x;return(x=(d=i.block)==null?void 0:d.call(i,B,e,t,c,s))!=null?x:[]}))).flat();switch(Object.assign(t,e.data),e.type){case"paragraph":{let i=t.pre?{alignment:"left"}:{},d=typeof t.checked=="boolean"?[new v({checked:t.checked,checkedState:{value:"2611"},uncheckedState:{value:"2610"}}),new h(" ")]:[];return[...a,new y({...i,...t,children:[...d,...await s(e,t)]})]}case"heading":return[new y({...t,...a,heading:r?e.depth===1?"Title":`Heading${e.depth-1}`:`Heading${e.depth}`,children:[new g({id:C(e).replace(/[. ]+/g,"-").toLowerCase(),children:await s(e,t)})]})];case"code":return[...a,new y({border:{bottom:{style:m.SINGLE,space:5,size:1},left:{style:m.SINGLE,space:10,size:1},right:{style:m.SINGLE,space:5,size:1},top:{style:m.SINGLE,space:6,size:1}},...t,alignment:"left",style:"blockCode",children:e.value.split(`
3
- `).map((i,d)=>new h({...t,text:i,break:d===0?0:1,style:"code",font:{name:"Consolas"}}))})];case"list":return e.ordered?(t.bullet={level:((f=(w=t.bullet)==null?void 0:w.level)!=null?f:-1)+1},console.warn("Please add numbering plugin to support ordered lists. For now, we use only bullets for both the ordered and the unordered list.")):t.bullet={level:((N=(I=t.bullet)==null?void 0:I.level)!=null?N:-1)+1},[...a,...await c(e,t)];case"blockquote":return[...a,...await c(e,t)];case"listItem":return t.checked=e.checked,[...a,...await c(e,t)];case"thematicBreak":return[...a,new y({...e.data,border:{top:{style:m.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return a;case"table":return console.warn("Please add table plugin to support tables."),a;case"fragment":return[...a,...await c(e,t)];case"":return a;case"yaml":case"html":default:return console.warn(`May be an unsupported node type: ${e.type}`,e),a}},c=async(e,l)=>{var t;return(await Promise.all((t=e.children)==null?void 0:t.map(a=>n(a,l)))).flat()};return{...p,children:await c(u,{})}};export{H as a};