mdast2docx 0.0.0-beta.0 → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -170
- package/dist/chunk-KPLOM3EF.mjs +2 -0
- package/dist/chunk-RFHTB4AU.mjs +1 -0
- package/dist/chunk-TASCVLMX.mjs +1 -0
- package/dist/chunk-UXY5TDOP.mjs +1 -0
- package/dist/chunk-XY2A2A66.mjs +1 -0
- package/dist/chunk-YKZOUIFR.mjs +1 -0
- package/dist/index.d.ts +7 -8
- package/dist/index.js +2 -38
- package/dist/index.mjs +1 -1
- package/dist/plugins/html.d.ts +0 -0
- package/dist/plugins/html.js +1 -0
- package/dist/plugins/image.d.ts +29 -0
- package/dist/plugins/image.js +1 -0
- package/dist/plugins/image.mjs +1 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/index.mjs +1 -0
- package/dist/plugins/list.d.ts +57 -0
- package/dist/plugins/list.js +1 -0
- package/dist/plugins/list.mjs +1 -0
- package/dist/plugins/math.d.ts +5 -0
- package/dist/plugins/math.js +1 -0
- package/dist/plugins/math.mjs +1 -0
- package/dist/plugins/table.d.ts +26 -0
- package/dist/plugins/table.js +1 -0
- package/dist/plugins/table.mjs +1 -0
- package/dist/section.d.ts +9 -8
- package/dist/section.js +2 -38
- package/dist/section.mjs +1 -1
- package/dist/utils.d.ts +75 -20
- package/dist/utils.js +1 -37
- package/dist/utils.mjs +1 -1
- package/package.json +2 -20
- package/dist/chunk-KRMGJ4HN.mjs +0 -2
- package/dist/chunk-O6BHSWEF.mjs +0 -37
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as m}from"./chunk-KPLOM3EF.mjs";import{a as D}from"./chunk-YKZOUIFR.mjs";import{Document as w,Packer as T}from"@mayank1513/docx";var S=async(n,i={},e={},P="blob")=>{var I;let s=1,p={};(I=e==null?void 0:e.plugins)==null||I.forEach(t=>{var o;return(o=t.root)==null?void 0:o.call(t,i)});let A=await Promise.all((Array.isArray(n)?n:[{ast:n}]).map(async({ast:t,props:o})=>{var y;let{definitions:a,footnoteDefinitions:c}=D(t.children);return await Promise.all(Object.values(c).map(async r=>{r.id=s,p[s]=await m({type:"root",children:r.children},a,{}),s++})),(y=o==null?void 0:o.plugins)==null||y.forEach(r=>{var h;return(h=r.root)==null?void 0:h.call(r,i)}),{ast:t,props:{...e,...o},definitions:a,footnoteDefinitions:c}})),d=await Promise.all(A.map(({ast:t,props:o,definitions:a,footnoteDefinitions:c})=>m(t,a,c,o))),f=new w({...i,footnotes:p,sections:d});return T.pack(f,P)};export{S as toDocx};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IImageOptions } from "@mayank1513/docx";
|
|
2
|
+
import { IPlugin } from "../utils";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves an image source URL into the appropriate image options for DOCX conversion.
|
|
5
|
+
*/
|
|
6
|
+
export type ImageResolver = (src: string, options?: IImagePluginOptions) => Promise<IImageOptions>;
|
|
7
|
+
/**
|
|
8
|
+
* Determines the MIME type of an image based on its binary signature.
|
|
9
|
+
*
|
|
10
|
+
* @param buffer - The image buffer (ArrayBuffer or Buffer).
|
|
11
|
+
* @returns The detected MIME type as a string.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getImageMimeType: (buffer: Buffer | ArrayBuffer) => "jpg" | "png" | "gif" | "bmp" | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Options for the image plugin.
|
|
16
|
+
*/
|
|
17
|
+
interface IImagePluginOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Scaling factor for base64-encoded images.
|
|
20
|
+
* @default 3
|
|
21
|
+
*/
|
|
22
|
+
scale?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Image plugin for processing inline image nodes in Markdown AST.
|
|
26
|
+
* This plugin is designed for client-side (web) environments.
|
|
27
|
+
*/
|
|
28
|
+
export declare const imagePlugin: (options?: IImagePluginOptions) => IPlugin;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var I=(a,t)=>{for(var e in t)c(a,e,{get:t[e],enumerable:!0})},f=(a,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of h(t))!l.call(a,n)&&n!==e&&c(a,n,{get:()=>t[n],enumerable:!(r=u(t,n))||r.enumerable});return a};var w=a=>f(c({},"__esModule",{value:!0}),a);var D={};I(D,{getImageMimeType:()=>p,imagePlugin:()=>P});module.exports=w(D);var p=a=>{let t=new Uint8Array(a).slice(0,4);if(t[0]===66&&t[1]===77)return"bmp";switch(t.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"}},y=3,F=async(a,t)=>{let e=document.createElement("canvas"),r=e.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*t,s=n.height*t;return e.width=i,e.height=s,r.drawImage(n,0,0,i,s),{data:e.toDataURL("image/png"),type:"png",transformation:{width:i/t,height:s/t}}},d=async a=>{let e=await(await fetch(a)).arrayBuffer(),r=p(e)||"png",n=await createImageBitmap(new Blob([e],{type:r}));return{type:r,data:e,transformation:{width:n.width,height:n.height}}},E=async(a,t)=>{var e;try{return a.startsWith("data:")?await F(a,(e=t==null?void 0:t.scale)!=null?e:y):await d(a)}catch(r){return console.error(`Error resolving image: ${a}`,r),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},P=a=>({inline:async(t,e,r,n)=>{var i,s,o;if(/^image/.test(e.type)){let g=(s=e.url)!=null?s:n[(i=e.identifier)==null?void 0:i.toUpperCase()],m=(o=e.alt)!=null?o:g==null?void 0:g.split("/").pop();return e.type="",[new t.ImageRun({...await E(g,a),altText:{description:m,name:m,title:m}})]}return[]}});0&&(module.exports={getImageMimeType,imagePlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"../chunk-XY2A2A66.mjs";export{a as getImageMimeType,b as imagePlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var b=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var t in e)b(n,t,{get:e[t],enumerable:!0})},S=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!B.call(n,o)&&o!==t&&b(n,o,{get:()=>e[o],enumerable:!(r=F(e,o))||r.enumerable});return n};var U=n=>S(b({},"__esModule",{value:!0}),n);var Q={};N(Q,{createLevels:()=>E,defaultTableOptions:()=>O,getImageMimeType:()=>w,imagePlugin:()=>j,listPlugin:()=>q,mathPlugin:()=>J,tablePlugin:()=>K});module.exports=U(Q);var w=n=>{let e=new Uint8Array(n).slice(0,4);if(e[0]===66&&e[1]===77)return"bmp";switch(e.reduce((r,o)=>r+o.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"}},H=3,_=async(n,e)=>{let t=document.createElement("canvas"),r=t.getContext("2d");if(!r)throw new Error("Canvas context not available");let o=new Image;o.src=n,await new Promise(g=>o.onload=g);let s=o.width*e,p=o.height*e;return t.width=s,t.height=p,r.drawImage(o,0,0,s,p),{data:t.toDataURL("image/png"),type:"png",transformation:{width:s/e,height:p/e}}},V=async n=>{let t=await(await fetch(n)).arrayBuffer(),r=w(t)||"png",o=await createImageBitmap(new Blob([t],{type:r}));return{type:r,data:t,transformation:{width:o.width,height:o.height}}},z=async(n,e)=>{var t;try{return n.startsWith("data:")?await _(n,(t=e==null?void 0:e.scale)!=null?t:H):await V(n)}catch(r){return console.error(`Error resolving image: ${n}`,r),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},j=n=>({inline:async(e,t,r,o)=>{var s,p,g;if(/^image/.test(t.type)){let c=(p=t.url)!=null?p:o[(s=t.identifier)==null?void 0:s.toUpperCase()],a=(g=t.alt)!=null?g:c==null?void 0:c.split("/").pop();return t.type="",[new e.ImageRun({...await z(c,n),altText:{description:a,name:a,title:a}})]}return[]}});var i=require("@mayank1513/docx"),P={style:i.BorderStyle.SINGLE,color:"auto",size:1},O={tableProps:{width:{size:100,type:i.WidthType.PERCENTAGE},margins:{top:(0,i.convertMillimetersToTwip)(2),right:(0,i.convertMillimetersToTwip)(4),bottom:(0,i.convertMillimetersToTwip)(2),left:(0,i.convertMillimetersToTwip)(4)},borders:{top:P,right:P,bottom:P,left:P,insideHorizontal:P,insideVertical:P}},rowProps:{},cellProps:{},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:i.ShadingType.SOLID,fill:"b79c2f"}},alignments:{defaultVerticalAlign:i.VerticalAlign.CENTER,defaultHorizontalAlign:i.AlignmentType.CENTER,preferMdData:!0}},K=n=>({block:async(e,t,r,o,s)=>{var x;if(t.type!=="table")return[];let{Table:p,TableRow:g,TableCell:c,Paragraph:a}=e,{tableProps:u,firstRowProps:d,firstRowCellProps:m,rowProps:f,cellProps:y,alignments:I}={...O,...n},h=(x=t.align)==null?void 0:x.map(T=>{switch(T){case"left":return e.AlignmentType.LEFT;case"right":return e.AlignmentType.RIGHT;case"center":return e.AlignmentType.CENTER;default:return}}),M=async(T,R)=>new g({...f,...R===0?d:{},children:await Promise.all(T.children.map(async(v,L)=>new c({verticalAlign:I.defaultVerticalAlign,...y,...R===0?m:{},children:[new a({children:await s(v),alignment:I.preferMdData?h==null?void 0:h[L]:I.defaultHorizontalAlign})]})))}),A=await Promise.all(t.children.map(M));return t.type="",[new p({...u,rows:A})]}});var D=()=>Math.random().toString(16).slice(2);var $=[i.LevelFormat.DECIMAL,i.LevelFormat.DECIMAL,i.LevelFormat.DECIMAL,i.LevelFormat.DECIMAL,i.LevelFormat.UPPER_LETTER,i.LevelFormat.LOWER_LETTER,i.LevelFormat.LOWER_ROMAN,i.LevelFormat.UPPER_ROMAN],E=(n,e=.4,t=.25)=>n.map((r,o)=>({level:o,format:r,text:(r===i.LevelFormat.DECIMAL?Array(o+1).fill(`%${o+1}`).join("."):`%${o+1}`)+".",alignment:i.AlignmentType.START,style:{paragraph:{indent:{left:(0,i.convertInchesToTwip)(e+o*t)}}}})),W=E($),G=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],X={levels:W,bullets:G,defaultBullets:!1},q=n=>{let e=D(),t=`numbering-${e}`,r=`bullet-${e}`,{levels:o,bulletLevels:s,bullets:p,defaultBullets:g}={...X,...n};return{block:async(c,a,u,d)=>{var f,y;if(a.type!=="list")return[];let m=((y=(f=u.bullet)==null?void 0:f.level)!=null?y:-1)+1;return u.numbering=g?void 0:{level:m,reference:a.ordered?t:r},u.bullet={level:m},a.type="",await d(a,u)},root:c=>{var a,u;c.numbering={config:[...(u=(a=c.numbering)==null?void 0:a.config)!=null?u:[],{reference:t,levels:o},{reference:r,levels:s!=null?s:o.map((d,m)=>{var f;return{...d,text:(f=p[m])!=null?f:"\u2022",format:i.LevelFormat.BULLET}})}]}}}};var J=()=>({inline:async(n,e)=>{var t;return e.type!=="inlineMath"?[]:(console.log("inline math",e.value),[new n.MathRun((t=e.value)!=null?t:"")])},block:async(n,e,t)=>{var r;return e.type!=="math"?[]:[new n.Paragraph({...t,children:[new n.MathRun((r=e.value)!=null?r:"")]})]}});0&&(module.exports={createLevels,defaultTableOptions,getImageMimeType,imagePlugin,listPlugin,mathPlugin,tablePlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,b as f}from"../chunk-UXY5TDOP.mjs";import{a as o,b as r}from"../chunk-XY2A2A66.mjs";import{a as m,b as p}from"../chunk-TASCVLMX.mjs";import"../chunk-YKZOUIFR.mjs";import{a as t}from"../chunk-RFHTB4AU.mjs";export{m as createLevels,e as defaultTableOptions,o as getImageMimeType,r as imagePlugin,p as listPlugin,t as mathPlugin,f as tablePlugin};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ILevelsOptions, LevelFormat } from "@mayank1513/docx";
|
|
2
|
+
import { IPlugin, Optional } from "../utils";
|
|
3
|
+
/**
|
|
4
|
+
* Default options for the list plugin.
|
|
5
|
+
*/
|
|
6
|
+
interface IDefaultListPluginOptions {
|
|
7
|
+
/** Defines the numbering styles for ordered lists. */
|
|
8
|
+
levels: ILevelsOptions[];
|
|
9
|
+
/** Defines the numbering styles for bullet lists (optional). */
|
|
10
|
+
bulletLevels?: ILevelsOptions[];
|
|
11
|
+
/**
|
|
12
|
+
* Bullet characters used for unordered lists.
|
|
13
|
+
* These closely match the default bullets in Microsoft Word.
|
|
14
|
+
*/
|
|
15
|
+
bullets: string[];
|
|
16
|
+
/** If true, uses Word's default bullet styles instead of custom ones. */
|
|
17
|
+
defaultBullets: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Type representing optional list plugin options. */
|
|
20
|
+
export type IListPluginOptions = Optional<IDefaultListPluginOptions>;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a list of numbering levels for ordered lists.
|
|
23
|
+
*
|
|
24
|
+
* @param levelFormats - An array of level formats defining the numbering style at each level.
|
|
25
|
+
* @param indent - The starting indentation in inches for the first level.
|
|
26
|
+
* @param indentStep - The incremental indentation added for each subsequent level.
|
|
27
|
+
* @returns An array of `ILevelsOptions` defining the hierarchical numbering style.
|
|
28
|
+
*
|
|
29
|
+
* Example:
|
|
30
|
+
* - Level 1: "1."
|
|
31
|
+
* - Level 2: "1.1."
|
|
32
|
+
* - Level 3: "1.1.1."
|
|
33
|
+
* - Level 4: "A."
|
|
34
|
+
* - Level 5: "a."
|
|
35
|
+
*/
|
|
36
|
+
export declare const createLevels: (levelFormats: (typeof LevelFormat)[keyof typeof LevelFormat][], indent?: number, // Base indentation for the first level (in inches)
|
|
37
|
+
indentStep?: number) => {
|
|
38
|
+
level: number;
|
|
39
|
+
format: "bullet" | "none" | "decimal" | "upperLetter" | "lowerLetter" | "lowerRoman" | "upperRoman" | "ordinal" | "cardinalText" | "ordinalText" | "hex" | "chicago" | "ideographDigital" | "japaneseCounting" | "aiueo" | "iroha" | "decimalFullWidth" | "decimalHalfWidth" | "japaneseLegal" | "japaneseDigitalTenThousand" | "decimalEnclosedCircle" | "decimalFullWidth2" | "aiueoFullWidth" | "irohaFullWidth" | "decimalZero" | "ganada" | "chosung" | "decimalEnclosedFullstop" | "decimalEnclosedParen" | "decimalEnclosedCircleChinese" | "ideographEnclosedCircle" | "ideographTraditional" | "ideographZodiac" | "ideographZodiacTraditional" | "taiwaneseCounting" | "ideographLegalTraditional" | "taiwaneseCountingThousand" | "taiwaneseDigital" | "chineseCounting" | "chineseLegalSimplified" | "chineseCountingThousand" | "koreanDigital" | "koreanCounting" | "koreanLegal" | "koreanDigital2" | "vietnameseCounting" | "russianLower" | "russianUpper" | "numberInDash" | "hebrew1" | "hebrew2" | "arabicAlpha" | "arabicAbjad" | "hindiVowels" | "hindiConsonants" | "hindiNumbers" | "hindiCounting" | "thaiLetters" | "thaiNumbers" | "thaiCounting" | "bahtText" | "dollarText" | "custom";
|
|
40
|
+
text: string;
|
|
41
|
+
alignment: "start";
|
|
42
|
+
style: {
|
|
43
|
+
paragraph: {
|
|
44
|
+
indent: {
|
|
45
|
+
left: number;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}[];
|
|
50
|
+
/**
|
|
51
|
+
* A plugin that enables support for ordered and unordered lists in DOCX.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Optional configuration for customizing lists.
|
|
54
|
+
* @returns An `IPlugin` instance for handling lists in the document.
|
|
55
|
+
*/
|
|
56
|
+
export declare const listPlugin: (options?: IListPluginOptions) => IPlugin;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var f=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var D=(o,t)=>{for(var i in t)f(o,i,{get:t[i],enumerable:!0})},R=(o,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of O(t))!b.call(o,n)&&n!==i&&f(o,n,{get:()=>t[n],enumerable:!(r=m(t,n))||r.enumerable});return o};var h=o=>R(f({},"__esModule",{value:!0}),o);var k={};D(k,{createLevels:()=>I,listPlugin:()=>v});module.exports=h(k);var e=require("@mayank1513/docx");var x=()=>Math.random().toString(16).slice(2);var C=[e.LevelFormat.DECIMAL,e.LevelFormat.DECIMAL,e.LevelFormat.DECIMAL,e.LevelFormat.DECIMAL,e.LevelFormat.UPPER_LETTER,e.LevelFormat.LOWER_LETTER,e.LevelFormat.LOWER_ROMAN,e.LevelFormat.UPPER_ROMAN],I=(o,t=.4,i=.25)=>o.map((r,n)=>({level:n,format:r,text:(r===e.LevelFormat.DECIMAL?Array(n+1).fill(`%${n+1}`).join("."):`%${n+1}`)+".",alignment:e.AlignmentType.START,style:{paragraph:{indent:{left:(0,e.convertInchesToTwip)(t+n*i)}}}})),M=I(C),L=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],E={levels:M,bullets:L,defaultBullets:!1},v=o=>{let t=x(),i=`numbering-${t}`,r=`bullet-${t}`,{levels:n,bulletLevels:c,bullets:y,defaultBullets:T}={...E,...o};return{block:async(u,s,l,d)=>{var p,P;if(s.type!=="list")return[];let a=((P=(p=l.bullet)==null?void 0:p.level)!=null?P:-1)+1;return l.numbering=T?void 0:{level:a,reference:s.ordered?i:r},l.bullet={level:a},s.type="",await d(s,l)},root:u=>{var s,l;u.numbering={config:[...(l=(s=u.numbering)==null?void 0:s.config)!=null?l:[],{reference:i,levels:n},{reference:r,levels:c!=null?c:n.map((d,a)=>{var p;return{...d,text:(p=y[a])!=null?p:"\u2022",format:e.LevelFormat.BULLET}})}]}}}};0&&(module.exports={createLevels,listPlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"../chunk-TASCVLMX.mjs";import"../chunk-YKZOUIFR.mjs";export{a as createLevels,b as listPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var g=(t,n)=>{for(var e in n)i(t,e,{get:n[e],enumerable:!0})},m=(t,n,e,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of u(n))!h.call(t,r)&&r!==e&&i(t,r,{get:()=>n[r],enumerable:!(a=l(n,r))||a.enumerable});return t};var p=t=>m(i({},"__esModule",{value:!0}),t);var s={};g(s,{mathPlugin:()=>c});module.exports=p(s);var c=()=>({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:"")]})]}});0&&(module.exports={mathPlugin});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../chunk-RFHTB4AU.mjs";export{a as mathPlugin};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AlignmentType, type ITableCellOptions, type ITableOptions, type ITableRowOptions, VerticalAlign } from "@mayank1513/docx";
|
|
2
|
+
import { IPlugin, Optional } from "../utils";
|
|
3
|
+
export type RowProps = Omit<ITableRowOptions, "children">;
|
|
4
|
+
export type TableProps = Omit<ITableOptions, "rows">;
|
|
5
|
+
export type CellProps = Omit<ITableCellOptions, "children">;
|
|
6
|
+
export interface ITableAlignments {
|
|
7
|
+
defaultVerticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
|
|
8
|
+
defaultHorizontalAlign?: (typeof AlignmentType)[keyof typeof AlignmentType];
|
|
9
|
+
/**
|
|
10
|
+
* Use MDAST data for horizontal aligning columns
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
preferMdData?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface IDefaultTablePluginProps {
|
|
16
|
+
tableProps: TableProps;
|
|
17
|
+
rowProps: RowProps;
|
|
18
|
+
cellProps: CellProps;
|
|
19
|
+
firstRowProps: RowProps;
|
|
20
|
+
firstRowCellProps: CellProps;
|
|
21
|
+
alignments: ITableAlignments;
|
|
22
|
+
}
|
|
23
|
+
type ITablePluginProps = Optional<IDefaultTablePluginProps>;
|
|
24
|
+
export declare const defaultTableOptions: IDefaultTablePluginProps;
|
|
25
|
+
export declare const tablePlugin: (options?: ITablePluginProps) => IPlugin;
|
|
26
|
+
export {};
|
|
@@ -0,0 +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});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"../chunk-UXY5TDOP.mjs";export{a as defaultTableOptions,b as tablePlugin};
|
package/dist/section.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Root } from "mdast";
|
|
|
2
2
|
import type { Definitions, FootnoteDefinitions, IMdastToDocxSectionProps } from "./utils";
|
|
3
3
|
import { Paragraph } from "@mayank1513/docx";
|
|
4
4
|
import type { ISectionOptions } from "@mayank1513/docx";
|
|
5
|
+
import * as docx from "@mayank1513/docx";
|
|
5
6
|
/**
|
|
6
7
|
* Defines properties for a document section, omitting the "children" property from ISectionOptions.
|
|
7
8
|
*/
|
|
@@ -15,16 +16,16 @@ export type ISectionProps = Omit<ISectionOptions, "children"> & IMdastToDocxSect
|
|
|
15
16
|
* @returns A DOCX section representation
|
|
16
17
|
*/
|
|
17
18
|
export declare const toSection: (node: Root, definitions: Definitions, footnoteDefinitions: FootnoteDefinitions, props?: ISectionProps) => Promise<{
|
|
18
|
-
children: Paragraph[];
|
|
19
|
+
children: (Paragraph | docx.Table)[];
|
|
19
20
|
headers?: {
|
|
20
|
-
readonly default?:
|
|
21
|
-
readonly first?:
|
|
22
|
-
readonly even?:
|
|
21
|
+
readonly default?: docx.Header;
|
|
22
|
+
readonly first?: docx.Header;
|
|
23
|
+
readonly even?: docx.Header;
|
|
23
24
|
};
|
|
24
25
|
footers?: {
|
|
25
|
-
readonly default?:
|
|
26
|
-
readonly first?:
|
|
27
|
-
readonly even?:
|
|
26
|
+
readonly default?: docx.Footer;
|
|
27
|
+
readonly first?: docx.Footer;
|
|
28
|
+
readonly even?: docx.Footer;
|
|
28
29
|
};
|
|
29
|
-
properties?:
|
|
30
|
+
properties?: docx.ISectionPropertiesOptions;
|
|
30
31
|
}>;
|