mdast2docx 0.0.0 → 0.1.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.
Files changed (47) hide show
  1. package/dist/chunk-3ZZBJC3M.mjs +1 -0
  2. package/dist/chunk-7LR5HC5O.mjs +4 -0
  3. package/dist/chunk-7W4N3GRD.mjs +75 -0
  4. package/dist/chunk-AHXJDPOO.mjs +2 -0
  5. package/dist/chunk-D4MVNKG6.mjs +1 -0
  6. package/dist/chunk-IBVI6OKS.mjs +1 -0
  7. package/dist/chunk-Q6Q2NBIZ.mjs +1 -0
  8. package/dist/chunk-XIRSNIMN.mjs +1 -0
  9. package/dist/chunk-Z5DPYROV.mjs +31 -0
  10. package/dist/chunk-ZKNVKZAF.mjs +1 -0
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/index.mjs +1 -1
  14. package/dist/multipart-parser-WKN2UV32.mjs +2 -0
  15. package/dist/plugins/image.d.ts +20 -12
  16. package/dist/plugins/image.js +1 -1
  17. package/dist/plugins/image.mjs +1 -1
  18. package/dist/plugins/index.js +75 -1
  19. package/dist/plugins/index.mjs +1 -1
  20. package/dist/plugins/list.d.ts +1 -1
  21. package/dist/plugins/list.js +1 -1
  22. package/dist/plugins/list.mjs +1 -1
  23. package/dist/plugins/math.d.ts +6 -0
  24. package/dist/plugins/math.js +75 -1
  25. package/dist/plugins/math.mjs +1 -1
  26. package/dist/plugins/node-image.d.ts +27 -0
  27. package/dist/plugins/node-image.js +35 -0
  28. package/dist/plugins/node-image.mjs +1 -0
  29. package/dist/plugins/node.d.ts +1 -0
  30. package/dist/plugins/node.js +35 -0
  31. package/dist/plugins/node.mjs +1 -0
  32. package/dist/plugins/table.d.ts +1 -1
  33. package/dist/plugins/table.js +1 -1
  34. package/dist/plugins/table.mjs +1 -1
  35. package/dist/section.d.ts +3 -3
  36. package/dist/section.js +2 -2
  37. package/dist/section.mjs +1 -1
  38. package/dist/utils.d.ts +4 -4
  39. package/dist/utils.js +1 -1
  40. package/dist/utils.mjs +1 -1
  41. package/package.json +7 -3
  42. package/dist/chunk-KPLOM3EF.mjs +0 -2
  43. package/dist/chunk-RFHTB4AU.mjs +0 -1
  44. package/dist/chunk-TASCVLMX.mjs +0 -1
  45. package/dist/chunk-UXY5TDOP.mjs +0 -1
  46. package/dist/chunk-XY2A2A66.mjs +0 -1
  47. package/dist/chunk-YKZOUIFR.mjs +0 -1
@@ -1 +1 @@
1
- "use strict";var P=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var H=(t,l)=>{for(var r in l)P(t,r,{get:l[r],enumerable:!0})},M=(t,l,r,n)=>{if(l&&typeof l=="object"||typeof l=="function")for(let o of V(l))!z.call(t,o)&&o!==r&&P(t,o,{get:()=>l[o],enumerable:!(n=D(l,o))||n.enumerable});return t};var N=t=>M(P({},"__esModule",{value:!0}),t);var S={};H(S,{defaultTableOptions:()=>g,tablePlugin:()=>k});module.exports=N(S);var e=require("@mayank1513/docx"),i={style:e.BorderStyle.SINGLE,color:"auto",size:1},g={tableProps:{width:{size:100,type:e.WidthType.PERCENTAGE},margins:{top:(0,e.convertMillimetersToTwip)(2),right:(0,e.convertMillimetersToTwip)(4),bottom:(0,e.convertMillimetersToTwip)(2),left:(0,e.convertMillimetersToTwip)(4)},borders:{top:i,right:i,bottom:i,left:i,insideHorizontal:i,insideVertical:i}},rowProps:{},cellProps:{},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:e.ShadingType.SOLID,fill:"b79c2f"}},alignments:{defaultVerticalAlign:e.VerticalAlign.CENTER,defaultHorizontalAlign:e.AlignmentType.CENTER,preferMdData:!0}},k=t=>({block:async(l,r,n,o,T)=>{var c;if(r.type!=="table")return[];let{Table:b,TableRow:u,TableCell:m,Paragraph:w}=l,{tableProps:y,firstRowProps:d,firstRowCellProps:R,rowProps:A,cellProps:h,alignments:a}={...g,...t},p=(c=r.align)==null?void 0:c.map(s=>{switch(s){case"left":return l.AlignmentType.LEFT;case"right":return l.AlignmentType.RIGHT;case"center":return l.AlignmentType.CENTER;default:return}}),I=async(s,f)=>new u({...A,...f===0?d:{},children:await Promise.all(s.children.map(async(O,E)=>new m({verticalAlign:a.defaultVerticalAlign,...h,...f===0?R:{},children:[new w({children:await T(O),alignment:a.preferMdData?p==null?void 0:p[E]:a.defaultHorizontalAlign})]})))}),C=await Promise.all(r.children.map(I));return r.type="",[new b({...y,rows:C})]}});0&&(module.exports={defaultTableOptions,tablePlugin});
1
+ "use strict";var P=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var H=(t,l)=>{for(var r in l)P(t,r,{get:l[r],enumerable:!0})},M=(t,l,r,n)=>{if(l&&typeof l=="object"||typeof l=="function")for(let o of V(l))!z.call(t,o)&&o!==r&&P(t,o,{get:()=>l[o],enumerable:!(n=D(l,o))||n.enumerable});return t};var N=t=>M(P({},"__esModule",{value:!0}),t);var S={};H(S,{defaultTableOptions:()=>g,tablePlugin:()=>k});module.exports=N(S);var e=require("docx"),i={style:e.BorderStyle.SINGLE,color:"auto",size:1},g={tableProps:{width:{size:100,type:e.WidthType.PERCENTAGE},margins:{top:(0,e.convertMillimetersToTwip)(2),right:(0,e.convertMillimetersToTwip)(4),bottom:(0,e.convertMillimetersToTwip)(2),left:(0,e.convertMillimetersToTwip)(4)},borders:{top:i,right:i,bottom:i,left:i,insideHorizontal:i,insideVertical:i}},rowProps:{},cellProps:{},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:e.ShadingType.SOLID,fill:"b79c2f"}},alignments:{defaultVerticalAlign:e.VerticalAlign.CENTER,defaultHorizontalAlign:e.AlignmentType.CENTER,preferMdData:!0}},k=t=>({block:async(l,r,n,o,T)=>{var c;if(r.type!=="table")return[];let{Table:b,TableRow:u,TableCell:m,Paragraph:w}=l,{tableProps:y,firstRowProps:d,firstRowCellProps:R,rowProps:A,cellProps:h,alignments:a}={...g,...t},p=(c=r.align)==null?void 0:c.map(s=>{switch(s){case"left":return l.AlignmentType.LEFT;case"right":return l.AlignmentType.RIGHT;case"center":return l.AlignmentType.CENTER;default:return}}),I=async(s,f)=>new u({...A,...f===0?d:{},children:await Promise.all(s.children.map(async(O,E)=>new m({verticalAlign:a.defaultVerticalAlign,...h,...f===0?R:{},children:[new w({children:await T(O),alignment:a.preferMdData?p==null?void 0:p[E]:a.defaultHorizontalAlign})]})))}),C=await Promise.all(r.children.map(I));return r.type="",[new b({...y,rows:C})]}});0&&(module.exports={defaultTableOptions,tablePlugin});
@@ -1 +1 @@
1
- import{a,b}from"../chunk-UXY5TDOP.mjs";export{a as defaultTableOptions,b as tablePlugin};
1
+ import{a,b}from"../chunk-Q6Q2NBIZ.mjs";import"../chunk-3ZZBJC3M.mjs";export{a as defaultTableOptions,b as tablePlugin};
package/dist/section.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { Root } from "mdast";
2
2
  import type { Definitions, FootnoteDefinitions, IMdastToDocxSectionProps } from "./utils";
3
- import { Paragraph } from "@mayank1513/docx";
4
- import type { ISectionOptions } from "@mayank1513/docx";
5
- import * as docx from "@mayank1513/docx";
3
+ import { Paragraph } from "docx";
4
+ import type { ISectionOptions } from "docx";
5
+ import * as docx from "docx";
6
6
  /**
7
7
  * Defines properties for a document section, omitting the "children" property from ISectionOptions.
8
8
  */
package/dist/section.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var O=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var v=(e,n)=>{for(var l in n)y(e,l,{get:n[l],enumerable:!0})},T=(e,n,l,P)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of N(n))!B.call(e,s)&&s!==l&&y(e,s,{get:()=>n[s],enumerable:!(P=M(n,s))||P.enumerable});return e};var E=(e,n,l)=>(l=e!=null?O(S(e)):{},T(n||!e||!e.__esModule?y(l,"default",{value:e,enumerable:!0}):l,e)),F=e=>T(y({},"__esModule",{value:!0}),e);var K={};v(K,{toSection:()=>j});module.exports=F(K);var k=require("@mayank1513/docx");var I=e=>{var n,l;return(n=e.children)!=null&&n.length?e.children.map(I).join(""):(l=e.value)!=null?l:""};var g={useTitle:!0,plugins:[]};var R=E(require("@mayank1513/docx")),H=(e,n,l)=>{let P=async(a,f)=>{var t,u,c;let r=Object.assign({},f),p=(await Promise.all(l.map(i=>{var h,x;return(x=(h=i.inline)==null?void 0:h.call(i,R,a,r,e,n,s))!=null?x:[]}))).flat(),d=(u=a.url)!=null?u:e[(t=a.identifier)==null?void 0:t.toUpperCase()];switch(a.type){case"text":return[...p,new k.TextRun({text:a.value,...r})];case"break":return[...p,new k.TextRun({break:1})];case"inlineCode":return[...p,new k.TextRun({text:a.value,...r,style:"code",font:{name:"Consolas"}})];case"emphasis":return r.italics=!0,[...p,...await s(a,r)];case"strong":return r.bold=!0,[...p,...await s(a,r)];case"delete":return r.strike=!0,[...p,...await s(a,r)];case"link":case"linkReference":return[...p,d.startsWith("#")?new k.InternalHyperlink({anchor:d.slice(1),children:await s(a,r)}):new k.ExternalHyperlink({link:d,children:await s(a,r)})];case"footnoteReference":return[...p,new k.FootnoteReferenceRun((c=n[a.identifier].id)!=null?c:0)];default:return[...p]}},s=async(a,f=new Set)=>{var r;return(await Promise.all((r=a.children)==null?void 0:r.map(p=>P(p,f)))).flat()};return s},j=async(e,n,l,P)=>{let{plugins:s,useTitle:a,...f}={...g,...P},r=H(n,l,s),p=async(t,u)=>{var h,x,b,C;let c=Object.assign({},u),i=(await Promise.all(s.map(m=>{var w,D;return(D=(w=m.block)==null?void 0:w.call(m,R,t,c,d,r))!=null?D:[]}))).flat();switch(t.type){case"paragraph":return[...i,new k.Paragraph({...u,children:await r(t)})];case"heading":return[new k.Paragraph({...i,heading:a?t.depth===1?"Title":`Heading${t.depth-1}`:`Heading${t.depth}`,children:[new k.Bookmark({id:I(t).replace(/[. ]+/g,"-").toLowerCase(),children:await r(t)})]})];case"code":return[...i,new k.Paragraph({alignment:"start",style:"blockCode",children:t.value.split(`
2
- `).map(m=>new k.TextRun({text:m,break:1,style:"code",font:{name:"Consolas"}}))})];case"list":return t.ordered?(c.bullet={level:((x=(h=c.bullet)==null?void 0:h.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.")):c.bullet={level:((C=(b=c.bullet)==null?void 0:b.level)!=null?C:-1)+1},[...i,...await d(t,c)];case"blockquote":return[...i,...await d(t,c)];case"listItem":return[...i,...await d(t,c)];case"thematicBreak":return[...i,new k.Paragraph({border:{top:{style:k.BorderStyle.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return i;case"table":return console.warn("Please add table plugin to support tables."),i;case"":return i;case"yaml":case"html":default:return console.warn(`Unsupported node type: ${t.type}`,t),i}},d=async(t,u)=>{var c;return(await Promise.all((c=t.children)==null?void 0:c.map(i=>p(i,u)))).flat()};return{...f,children:await d(e,{})}};0&&(module.exports={toSection});
1
+ "use strict";var O=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var v=(e,n)=>{for(var l in n)y(e,l,{get:n[l],enumerable:!0})},T=(e,n,l,P)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of N(n))!B.call(e,s)&&s!==l&&y(e,s,{get:()=>n[s],enumerable:!(P=M(n,s))||P.enumerable});return e};var E=(e,n,l)=>(l=e!=null?O(S(e)):{},T(n||!e||!e.__esModule?y(l,"default",{value:e,enumerable:!0}):l,e)),F=e=>T(y({},"__esModule",{value:!0}),e);var K={};v(K,{toSection:()=>j});module.exports=F(K);var k=require("docx");var I=e=>{var n,l;return(n=e.children)!=null&&n.length?e.children.map(I).join(""):(l=e.value)!=null?l:""};var g={useTitle:!0,plugins:[]};var R=E(require("docx")),H=(e,n,l)=>{let P=async(a,f)=>{var t,u,c;let r=Object.assign({},f),p=(await Promise.all(l.map(i=>{var h,x;return(x=(h=i.inline)==null?void 0:h.call(i,R,a,r,e,n,s))!=null?x:[]}))).flat(),d=(u=a.url)!=null?u:e[(t=a.identifier)==null?void 0:t.toUpperCase()];switch(a.type){case"text":return[...p,new k.TextRun({text:a.value,...r})];case"break":return[...p,new k.TextRun({break:1})];case"inlineCode":return[...p,new k.TextRun({text:a.value,...r,style:"code",font:{name:"Consolas"}})];case"emphasis":return r.italics=!0,[...p,...await s(a,r)];case"strong":return r.bold=!0,[...p,...await s(a,r)];case"delete":return r.strike=!0,[...p,...await s(a,r)];case"link":case"linkReference":return[...p,d.startsWith("#")?new k.InternalHyperlink({anchor:d.slice(1),children:await s(a,r)}):new k.ExternalHyperlink({link:d,children:await s(a,r)})];case"footnoteReference":return[...p,new k.FootnoteReferenceRun((c=n[a.identifier].id)!=null?c:0)];default:return[...p]}},s=async(a,f=new Set)=>{var r;return(await Promise.all((r=a.children)==null?void 0:r.map(p=>P(p,f)))).flat()};return s},j=async(e,n,l,P)=>{let{plugins:s,useTitle:a,...f}={...g,...P},r=H(n,l,s),p=async(t,u)=>{var h,x,b,C;let c=Object.assign({},u),i=(await Promise.all(s.map(m=>{var w,D;return(D=(w=m.block)==null?void 0:w.call(m,R,t,c,d,r))!=null?D:[]}))).flat();switch(t.type){case"paragraph":return[...i,new k.Paragraph({...u,children:await r(t)})];case"heading":return[new k.Paragraph({...i,heading:a?t.depth===1?"Title":`Heading${t.depth-1}`:`Heading${t.depth}`,children:[new k.Bookmark({id:I(t).replace(/[. ]+/g,"-").toLowerCase(),children:await r(t)})]})];case"code":return[...i,new k.Paragraph({alignment:"start",style:"blockCode",children:t.value.split(`
2
+ `).map(m=>new k.TextRun({text:m,break:1,style:"code",font:{name:"Consolas"}}))})];case"list":return t.ordered?(c.bullet={level:((x=(h=c.bullet)==null?void 0:h.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.")):c.bullet={level:((C=(b=c.bullet)==null?void 0:b.level)!=null?C:-1)+1},[...i,...await d(t,c)];case"blockquote":return[...i,...await d(t,c)];case"listItem":return[...i,...await d(t,c)];case"thematicBreak":return[...i,new k.Paragraph({border:{top:{style:k.BorderStyle.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return i;case"table":return console.warn("Please add table plugin to support tables."),i;case"":return i;case"yaml":case"html":default:return console.warn(`May be an unsupported node type: ${t.type}`,t),i}},d=async(t,u)=>{var c;return(await Promise.all((c=t.children)==null?void 0:c.map(i=>p(i,u)))).flat()};return{...f,children:await d(e,{})}};0&&(module.exports={toSection});
package/dist/section.mjs CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-KPLOM3EF.mjs";import"./chunk-YKZOUIFR.mjs";export{a as toSection};
1
+ import{a}from"./chunk-AHXJDPOO.mjs";import"./chunk-IBVI6OKS.mjs";import"./chunk-3ZZBJC3M.mjs";export{a as toSection};
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ExternalHyperlink, ImageRun, InternalHyperlink, IParagraphOptions, TextRun, Table, Paragraph, IRunOptions, IPropertiesOptions, MathRun } from "@mayank1513/docx";
2
- import * as DOCX from "@mayank1513/docx";
1
+ import { ExternalHyperlink, ImageRun, InternalHyperlink, IParagraphOptions, TextRun, Table, Paragraph, IRunOptions, IPropertiesOptions, Math as DOCXMath } from "docx";
2
+ import * as DOCX from "docx";
3
3
  import { BlockContent, DefinitionContent, Parent, Root, RootContent } from "mdast";
4
- export { convertInchesToTwip, convertMillimetersToTwip } from "@mayank1513/docx";
4
+ export { convertInchesToTwip, convertMillimetersToTwip } from "docx";
5
5
  export type Optional<T> = {
6
6
  [K in keyof T]?: T[K];
7
7
  };
@@ -74,7 +74,7 @@ export type IDocxProps = Omit<Mutable<IPropertiesOptions>, "sections" | "footnot
74
74
  */
75
75
  export type MutableRunOptions = Mutable<Omit<IRunOptions, "children">>;
76
76
  export type InlineParentType = "strong" | "emphasis" | "delete" | "link";
77
- export type InlineDocxNodes = TextRun | ImageRun | InternalHyperlink | ExternalHyperlink | MathRun;
77
+ export type InlineDocxNodes = TextRun | ImageRun | InternalHyperlink | ExternalHyperlink | DOCXMath;
78
78
  export type InlineProcessor = (node: ExtendedRootContent, runProps: MutableRunOptions) => Promise<InlineDocxNodes[]>;
79
79
  export type InlineChildrenProcessor = (node: Parent, runProps?: MutableRunOptions) => Promise<InlineDocxNodes[]>;
80
80
  /**
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- "use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},u=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!d.call(t,r)&&r!==n&&s(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var x=t=>u(s({},"__esModule",{value:!0}),t);var h={};P(h,{convertInchesToTwip:()=>i.convertInchesToTwip,convertMillimetersToTwip:()=>i.convertMillimetersToTwip,defaultProps:()=>y,getDefinitions:()=>p,getTextContent:()=>a,uuid:()=>f});module.exports=x(h);var i=require("@mayank1513/docx"),p=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,p(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:""},f=()=>Math.random().toString(16).slice(2),y={useTitle:!0,plugins:[]};0&&(module.exports={convertInchesToTwip,convertMillimetersToTwip,defaultProps,getDefinitions,getTextContent,uuid});
1
+ "use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var n in e)s(t,n,{get:e[n],enumerable:!0})},x=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!d.call(t,r)&&r!==n&&s(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var u=t=>x(s({},"__esModule",{value:!0}),t);var y={};P(y,{convertInchesToTwip:()=>i.convertInchesToTwip,convertMillimetersToTwip:()=>i.convertMillimetersToTwip,defaultProps:()=>h,getDefinitions:()=>p,getTextContent:()=>a,uuid:()=>f});module.exports=u(y);var i=require("docx"),p=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,p(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:""},f=()=>Math.random().toString(16).slice(2),h={useTitle:!0,plugins:[]};0&&(module.exports={convertInchesToTwip,convertMillimetersToTwip,defaultProps,getDefinitions,getTextContent,uuid});
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- import{a,b,c,d,e,f}from"./chunk-YKZOUIFR.mjs";export{e as convertInchesToTwip,f as convertMillimetersToTwip,d as defaultProps,a as getDefinitions,b as getTextContent,c as uuid};
1
+ import{a,b,c,d,e,f}from"./chunk-IBVI6OKS.mjs";import"./chunk-3ZZBJC3M.mjs";export{e as convertInchesToTwip,f as convertMillimetersToTwip,d as defaultProps,a as getDefinitions,b as getTextContent,c as uuid};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mdast2docx",
3
3
  "author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
4
4
  "private": false,
5
- "version": "0.0.0",
5
+ "version": "0.1.1",
6
6
  "description": "Convert Markdown Abstract Syntax Tree (MDAST) to DOCX seamlessly. Supports footnotes, images, links, and customizable document properties.",
7
7
  "license": "MPL-2.0",
8
8
  "main": "./dist/index.js",
@@ -30,19 +30,23 @@
30
30
  "@testing-library/react": "^16.2.0",
31
31
  "@types/mdast": "^4.0.4",
32
32
  "@types/node": "^22.13.10",
33
+ "@unified-latex/unified-latex-types": "^1.8.0",
34
+ "@unified-latex/unified-latex-util-parse": "^1.8.2",
33
35
  "@vitest/coverage-v8": "^3.0.8",
34
36
  "esbuild-plugin-rdi": "^0.0.0",
35
37
  "jsdom": "^26.0.0",
38
+ "node-fetch": "^3.3.2",
36
39
  "remark-gfm": "^4.0.1",
37
40
  "remark-parse": "^11.0.0",
41
+ "sharp": "0.33.5",
38
42
  "tsup": "^8.4.0",
39
43
  "typescript": "^5.8.2",
40
44
  "unified": "^11.0.5",
41
45
  "vite-tsconfig-paths": "^5.1.4",
42
46
  "vitest": "^3.0.8"
43
47
  },
44
- "dependencies": {
45
- "@mayank1513/docx": "^9.2.0"
48
+ "peerDependencies": {
49
+ "docx": "^9.3.0"
46
50
  },
47
51
  "funding": [
48
52
  {
@@ -1,2 +0,0 @@
1
- import{b as C,d as N}from"./chunk-YKZOUIFR.mjs";import{Bookmark as D,BorderStyle as S,ExternalHyperlink as B,FootnoteReferenceRun as R,InternalHyperlink as v,Paragraph as m,TextRun as f}from"@mayank1513/docx";import*as g from"@mayank1513/docx";var T=(w,h,P)=>{let y=async(o,c)=>{var e,l,n;let t=Object.assign({},c),s=(await Promise.all(P.map(r=>{var d,p;return(p=(d=r.inline)==null?void 0:d.call(r,g,o,t,w,h,a))!=null?p:[]}))).flat(),i=(l=o.url)!=null?l:w[(e=o.identifier)==null?void 0:e.toUpperCase()];switch(o.type){case"text":return[...s,new f({text:o.value,...t})];case"break":return[...s,new f({break:1})];case"inlineCode":return[...s,new f({text:o.value,...t,style:"code",font:{name:"Consolas"}})];case"emphasis":return t.italics=!0,[...s,...await a(o,t)];case"strong":return t.bold=!0,[...s,...await a(o,t)];case"delete":return t.strike=!0,[...s,...await a(o,t)];case"link":case"linkReference":return[...s,i.startsWith("#")?new v({anchor:i.slice(1),children:await a(o,t)}):new B({link:i,children:await a(o,t)})];case"footnoteReference":return[...s,new R((n=h[o.identifier].id)!=null?n:0)];default:return[...s]}},a=async(o,c=new Set)=>{var t;return(await Promise.all((t=o.children)==null?void 0:t.map(s=>y(s,c)))).flat()};return a},H=async(w,h,P,y)=>{let{plugins:a,useTitle:o,...c}={...N,...y},t=T(h,P,a),s=async(e,l)=>{var d,p,k,I;let n=Object.assign({},l),r=(await Promise.all(a.map(u=>{var b,x;return(x=(b=u.block)==null?void 0:b.call(u,g,e,n,i,t))!=null?x:[]}))).flat();switch(e.type){case"paragraph":return[...r,new m({...l,children:await t(e)})];case"heading":return[new m({...r,heading:o?e.depth===1?"Title":`Heading${e.depth-1}`:`Heading${e.depth}`,children:[new D({id:C(e).replace(/[. ]+/g,"-").toLowerCase(),children:await t(e)})]})];case"code":return[...r,new m({alignment:"start",style:"blockCode",children:e.value.split(`
2
- `).map(u=>new f({text:u,break:1,style:"code",font:{name:"Consolas"}}))})];case"list":return e.ordered?(n.bullet={level:((p=(d=n.bullet)==null?void 0:d.level)!=null?p:-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.")):n.bullet={level:((I=(k=n.bullet)==null?void 0:k.level)!=null?I:-1)+1},[...r,...await i(e,n)];case"blockquote":return[...r,...await i(e,n)];case"listItem":return[...r,...await i(e,n)];case"thematicBreak":return[...r,new m({border:{top:{style:S.SINGLE,size:6}}})];case"definition":case"footnoteDefinition":return r;case"table":return console.warn("Please add table plugin to support tables."),r;case"":return r;case"yaml":case"html":default:return console.warn(`Unsupported node type: ${e.type}`,e),r}},i=async(e,l)=>{var n;return(await Promise.all((n=e.children)==null?void 0:n.map(r=>s(r,l)))).flat()};return{...c,children:await i(w,{})}};export{H as a};
@@ -1 +0,0 @@
1
- var r=()=>({inline:async(t,n)=>{var e;return n.type!=="inlineMath"?[]:(console.log("inline math",n.value),[new t.MathRun((e=n.value)!=null?e:"")])},block:async(t,n,e)=>{var a;return n.type!=="math"?[]:[new t.Paragraph({...e,children:[new t.MathRun((a=n.value)!=null?a:"")]})]}});export{r as a};
@@ -1 +0,0 @@
1
- import{c as g}from"./chunk-YKZOUIFR.mjs";import{AlignmentType as v,convertInchesToTwip as O,LevelFormat as e}from"@mayank1513/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{BorderStyle as I,ShadingType as C,WidthType as O,AlignmentType as E,VerticalAlign as D,convertMillimetersToTwip as r}from"@mayank1513/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
- var c=a=>{let e=new Uint8Array(a).slice(0,4);if(e[0]===66&&e[1]===77)return"bmp";switch(e.reduce((r,n)=>r+n.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"}},p=3,u=async(a,e)=>{let t=document.createElement("canvas"),r=t.getContext("2d");if(!r)throw new Error("Canvas context not available");let n=new Image;n.src=a,await new Promise(o=>n.onload=o);let i=n.width*e,s=n.height*e;return t.width=i,t.height=s,r.drawImage(n,0,0,i,s),{data:t.toDataURL("image/png"),type:"png",transformation:{width:i/e,height:s/e}}},h=async a=>{let t=await(await fetch(a)).arrayBuffer(),r=c(t)||"png",n=await createImageBitmap(new Blob([t],{type:r}));return{type:r,data:t,transformation:{width:n.width,height:n.height}}},l=async(a,e)=>{var t;try{return a.startsWith("data:")?await u(a,(t=e==null?void 0:e.scale)!=null?t:p):await h(a)}catch(r){return console.error(`Error resolving image: ${a}`,r),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},I=a=>({inline:async(e,t,r,n)=>{var i,s,o;if(/^image/.test(t.type)){let g=(s=t.url)!=null?s:n[(i=t.identifier)==null?void 0:i.toUpperCase()],m=(o=t.alt)!=null?o:g==null?void 0:g.split("/").pop();return t.type="",[new e.ImageRun({...await l(g,a),altText:{description:m,name:m,title:m}})]}return[]}});export{c as a,I as b};
@@ -1 +0,0 @@
1
- import{convertInchesToTwip as d,convertMillimetersToTwip as P}from"@mayank1513/docx";var i=o=>{let t={},n={};return o.forEach(e=>{var r;e.type==="definition"?t[e.identifier.toUpperCase()]=e.url:e.type==="footnoteDefinition"?n[e.identifier.toUpperCase()]={children:e.children}:(r=e.children)!=null&&r.length&&Object.assign(t,i(e.children))}),{definitions:t,footnoteDefinitions:n}},s=o=>{var t,n;return(t=o.children)!=null&&t.length?o.children.map(s).join(""):(n=o.value)!=null?n:""},p=()=>Math.random().toString(16).slice(2),a={useTitle:!0,plugins:[]};export{i as a,s as b,p as c,a as d,d as e,P as f};