mdast2docx 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -242
- package/dist/chunk-KWOFOD3W.mjs +31 -0
- package/dist/{chunk-M5XHL7AG.mjs → chunk-NMFJ4KIZ.mjs} +2 -2
- package/dist/index.d.ts +1 -23
- package/dist/index.js +1 -3
- package/dist/index.mjs +1 -1
- package/dist/{multipart-parser-WKN2UV32.mjs → multipart-parser-I4OTWNXG.mjs} +1 -1
- package/dist/plugins/index.d.ts +5 -5
- package/dist/plugins/index.js +1 -3
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/node/index.mjs +1 -1
- package/dist/plugins/node/node-image.d.ts +1 -1
- package/dist/plugins/node/node-image.mjs +1 -1
- package/package.json +98 -95
- package/dist/chunk-3ZZBJC3M.mjs +0 -1
- package/dist/chunk-GP6KO6J3.mjs +0 -3
- package/dist/chunk-GS5L4UWU.mjs +0 -1
- package/dist/chunk-IW743AEN.mjs +0 -1
- package/dist/chunk-LXTXD4UG.mjs +0 -1
- package/dist/chunk-Q6Q2NBIZ.mjs +0 -1
- package/dist/chunk-QR3NYQYH.mjs +0 -1
- package/dist/chunk-YNJKJBFY.mjs +0 -3
- package/dist/chunk-Z5DPYROV.mjs +0 -31
- package/dist/mdast.d.ts +0 -1076
- package/dist/mdast.js +0 -1
- package/dist/plugins/html.d.ts +0 -9
- package/dist/plugins/html.js +0 -3
- package/dist/plugins/html.mjs +0 -1
- package/dist/plugins/image.d.ts +0 -41
- package/dist/plugins/image.js +0 -1
- package/dist/plugins/image.mjs +0 -1
- package/dist/plugins/list.d.ts +0 -57
- package/dist/plugins/list.js +0 -1
- package/dist/plugins/list.mjs +0 -1
- package/dist/plugins/math.d.ts +0 -11
- package/dist/plugins/math.js +0 -1
- package/dist/plugins/math.mjs +0 -1
- package/dist/plugins/table.d.ts +0 -26
- package/dist/plugins/table.js +0 -1
- package/dist/plugins/table.mjs +0 -1
- package/dist/section.d.ts +0 -26
- package/dist/section.js +0 -3
- package/dist/section.mjs +0 -1
- package/dist/utils.d.ts +0 -123
- package/dist/utils.js +0 -1
- package/dist/utils.mjs +0 -1
package/dist/mdast.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var s=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of p(e))!l.call(t,n)&&n!==r&&o(t,n,{get:()=>e[n],enumerable:!(a=i(e,n))||a.enumerable});return t};var d=t=>s(o({},"__esModule",{value:!0}),t);var c={};module.exports=d(c);
|
package/dist/plugins/html.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { IPlugin } from "../utils";
|
|
2
|
-
/**
|
|
3
|
-
* @beta
|
|
4
|
-
* htmlPlugin is in beta and is subject to change or removal without notice.
|
|
5
|
-
* This plugin is a placeholder for future implementation of HTML conversion.
|
|
6
|
-
*
|
|
7
|
-
* Keep this before image and other plugins to ensure html images, tables, checkboxes, etc. are processed.
|
|
8
|
-
*/
|
|
9
|
-
export declare const htmlPlugin: () => IPlugin;
|
package/dist/plugins/html.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var S=(e,n)=>{for(var t in n)b(e,t,{get:n[t],enumerable:!0})},k=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of N(n))!R.call(e,o)&&o!==t&&b(e,o,{get:()=>n[o],enumerable:!(r=O(n,o))||r.enumerable});return e};var B=e=>k(b({},"__esModule",{value:!0}),e);var U={};S(U,{htmlPlugin:()=>G});module.exports=B(U);var x=require("docx");var T=e=>{let n=document.createElement("canvas").getContext("2d");return n?(n.fillStyle=e,n.fillStyle.slice(1)):e.startsWith("#")?e.slice(1):"auto"};var L=["BR","IMG","EM","I","STRONG","B","DEL","S","A","SUP","SUB","IMG"],A={BR:"break",IMG:"image",EM:"emphasis",I:"emphasis",STRONG:"strong",B:"strong",DEL:"delete",S:"delete",A:"link"},E=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],H=e=>{var r;if(!e)return{};let n={},t=e.match(/border(-\w+)?:\s*[^;]+/gi);if(!t)return{};for(let o of t){let[s,c]=o.split(":").map(l=>l.trim()),p=c.split(/\s+/),d=(r=p.find(l=>l.endsWith("px")))==null?void 0:r.replace("px",""),i=p.find(l=>E.includes(l.toLowerCase())),f=p.find(l=>!l.endsWith("px")&&!E.includes(l.toLowerCase())),y=s==="border"?"border":s.replace("border-","");n[y]={...d?{width:parseInt(d,1)}:{},...i?{style:i}:{},...f?{color:f}:{}}}return n},v={solid:x.BorderStyle.SINGLE,dashed:x.BorderStyle.DASHED,dotted:x.BorderStyle.DOTTED,double:x.BorderStyle.DOUBLE,none:x.BorderStyle.NONE,ridge:x.BorderStyle.THREE_D_EMBOSS,groove:x.BorderStyle.THREE_D_ENGRAVE,inset:x.BorderStyle.INSET,outset:x.BorderStyle.OUTSET},h=e=>{if(!e||!Object.keys(e).length)return;let{width:n,color:t,style:r}=e,o={style:r?v[r]:x.BorderStyle.SINGLE};return n&&(o.size=n),t&&(o.color=T(t)),o},P=(e,n=!0)=>{let t={};if(!(e instanceof HTMLElement||e instanceof SVGElement))return t;let{textAlign:r,fontWeight:o,fontStyle:s,textDecoration:c,textTransform:p,color:d}=e.style,i=H(e.getAttribute("style"));if(n&&i.border)t.border=h(i.border);else if(Object.keys(i).length){let f={...i.border,...i.left},y={...i.border,...i.right},l={...i.border,...i.top},C={...i.border,...i.bottom};t.border={left:h(f),right:h(y),top:h(l),bottom:h(C)}}switch(r&&(Object.keys(x.AlignmentType).includes(r)?t.alignment=r:r==="justify"&&(t.alignment=x.AlignmentType.JUSTIFIED)),(/bold/.test(o)||parseInt(o)>=500)&&(t.bold=!0),/(italic|oblique)/.test(s)&&(t.italics=!0),c){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),d&&(t.color=T(d)),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},u=e=>{var o,s,c,p;if(!(e instanceof HTMLElement||e instanceof SVGElement))return{type:"text",value:(o=e.textContent)!=null?o:""};let n=Array.from(e.childNodes).map(u),t=P(e),r=e.getAttributeNames().reduce((d,i)=>({...d,[i]:e.getAttribute(i)}),{});switch(e.tagName){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(s=r.src)!=null?s:"",alt:(c=r.alt)!=null?c:"",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:A[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}},D=(e,n)=>Array.from(e.children).map(t=>{let r={...n,...P(t)};return t instanceof HTMLTableRowElement?{type:"tableRow",children:Array.from(t.children).map(o=>({type:"tableCell",children:[u(o)]})),data:r}:D(t,r)}).flat(),g={style:"single"},I={left:g,right:g,top:g,bottom:g},w=e=>{let n=P(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(u),data:n};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return m(e,n);case"UL":case"OL":return{type:"list",ordered:e.tagName==="OL",children:Array.from(e.childNodes).map(t=>({type:"listItem",children:[m(t)],data:n}))};case"HR":return{type:"thematicBreak",data:n};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(e.childNodes).map(t=>m(t)),data:n};case"TABLE":return{type:"table",children:D(e),data:n};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet!
|
|
2
|
-
|
|
3
|
-
${e.textContent}`}],data:{...n,pre:!0,border:I}};case"INPUT":if(!/(radio|checkbox)/.test(e.type))return{type:"paragraph",children:[],data:{...n,frame:{width:5e3,height:90,alignment:{x:x.HorizontalPositionAlign.LEFT,y:x.VerticalPositionAlign.CENTER},anchor:{horizontal:x.FrameAnchorType.TEXT,vertical:x.FrameAnchorType.TEXT},type:"alignment"},border:I}}}return{type:"paragraph",children:[u(e)],data:n}},m=(e,n)=>{let t=Array.from(e.childNodes),r=[],o=[];for(let s of t)(s instanceof HTMLElement||s instanceof SVGElement)&&!L.includes(s.tagName)?(o.length&&(r.push({type:"paragraph",children:o.map(u)}),o.length=0),r.push(w(s))):o.push(s);return o.length&&r.push({type:"paragraph",children:o.map(u)}),r.length===1?{...r[0],data:{...n,...r[0].data}}:{type:"fragment",children:r,data:n}},M=e=>{var r,o;let n=[],t=[];for(let s of e.children)if((r=s.children)!=null&&r.length&&M(s),s.type==="html"&&/^<[^>]*[^/]>$/.test(s.value)){let c=s.value.split(" ")[0].slice(1);c[0]==="/"?((o=t[0])==null?void 0:o.tag)===c.slice(1,-1)&&n.push(t.shift()):t.unshift({...s,children:[],tag:c})}else t.length?t[0].children.push(s):n.push(s);e.children=n},G=()=>({block:async(e,n)=>{if(n.type==="html"){let t=document.createElement("div");t.innerHTML=n.value,Object.assign(n,m(t))}return[]},inline:async(e,n)=>{var t,r;if(n.type==="html"){let o=(r=(t=n.value)==null?void 0:t.trim())!=null?r:"",s=o.split(" ")[0].slice(1),c=document.createElement("div");c.innerHTML=o.endsWith("/>")?o:`${o}</${s}>`,Object.assign(n,{...u(c.children[0]),children:n.children})}return[]},preprocess:M});0&&(module.exports={htmlPlugin});
|
package/dist/plugins/html.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"../chunk-GP6KO6J3.mjs";import"../chunk-IW743AEN.mjs";import"../chunk-3ZZBJC3M.mjs";export{a as htmlPlugin};
|
package/dist/plugins/image.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { IImageOptions } from "docx";
|
|
2
|
-
import { IPlugin } from "../utils";
|
|
3
|
-
/**
|
|
4
|
-
* List of image types fully supported by docx. SVG requires fallback thus we do not include that here.
|
|
5
|
-
*/
|
|
6
|
-
export declare const SUPPORTED_IMAGE_TYPES: readonly ["jpeg", "jpg", "bmp", "gif", "png"];
|
|
7
|
-
/**
|
|
8
|
-
* Resolves an image source URL into the appropriate image options for DOCX conversion.
|
|
9
|
-
*/
|
|
10
|
-
export type ImageResolver = (src: string, options?: IImagePluginOptions) => Promise<IImageOptions>;
|
|
11
|
-
/**
|
|
12
|
-
* Options for the image plugin.
|
|
13
|
-
*/
|
|
14
|
-
export interface IImagePluginOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Scaling factor for base64-encoded images.
|
|
17
|
-
* @default 3
|
|
18
|
-
*/
|
|
19
|
-
scale?: number;
|
|
20
|
-
/**
|
|
21
|
-
* Fallback image type if the image type cannot be determined or is not supported.
|
|
22
|
-
* @default "png"
|
|
23
|
-
*/
|
|
24
|
-
fallbackImageType?: "png" | "jpg" | "bmp" | "gif";
|
|
25
|
-
/**
|
|
26
|
-
* Custom image resolver to resolve an image source URL into the appropriate image options for DOCX conversion.
|
|
27
|
-
*/
|
|
28
|
-
imageResolver?: ImageResolver;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Determines the MIME type of an image based on its binary signature.
|
|
32
|
-
*
|
|
33
|
-
* @param buffer - The image buffer (ArrayBuffer or Buffer).
|
|
34
|
-
* @returns The detected MIME type as a string.
|
|
35
|
-
*/
|
|
36
|
-
export declare const getImageMimeType: (buffer: Buffer | ArrayBuffer) => "jpg" | "bmp" | "gif" | "png" | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Image plugin for processing inline image nodes in Markdown AST.
|
|
39
|
-
* This plugin is designed for client-side (web) environments.
|
|
40
|
-
*/
|
|
41
|
-
export declare const imagePlugin: (options?: IImagePluginOptions) => IPlugin;
|
package/dist/plugins/image.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var a in t)p(e,a,{get:t[a],enumerable:!0})},P=(e,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!F.call(e,n)&&n!==a&&p(e,n,{get:()=>t[n],enumerable:!(r=y(t,n))||r.enumerable});return e};var x=e=>P(p({},"__esModule",{value:!0}),e);var D={};v(D,{SUPPORTED_IMAGE_TYPES:()=>h,getImageMimeType:()=>f,imagePlugin:()=>T});module.exports=x(D);var h=["jpeg","jpg","bmp","gif","png"],f=e=>{let t=new Uint8Array(e).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"}},E=3,l=async(e,t)=>{var I,u;let a=(I=t==null?void 0:t.scale)!=null?I:E,r=document.createElement("canvas"),n=r.getContext("2d");if(!n)throw new Error("Canvas context not available");let i=new Image;i.src=e,await new Promise(d=>i.onload=d);let s=i.width*a,g=i.height*a;r.width=s,r.height=g,n.drawImage(i,0,0,s,g);let m=e.split(";")[0].split("/")[1];if(h.includes(m))return{data:e,type:m,transformation:{width:s/a,height:g/a}};let o=(u=t==null?void 0:t.fallbackImageType)!=null?u:"png",c={data:r.toDataURL(`image/${o}`),type:o,transformation:{width:s/a,height:g/a}};return e.includes("svg")?{...c,type:"svg",data:e,fallback:{type:o,data:c.data}}:c},b=async(e,t)=>{var s;let a=await fetch(e.startsWith("http")?e:`${window.location.origin}/${e.replace(/^\/+/,"")}`);if(/(svg|xml)/.test((s=a.headers.get("content-type"))!=null?s:"")||e.endsWith(".svg")){let g=await a.text();return l(`data:image/svg+xml;base64,${btoa(g)}`,t)}let r=await a.arrayBuffer(),n=f(r)||"png",i=await createImageBitmap(new Blob([r],{type:n}));return h.includes(n)?{type:n,data:r,transformation:{width:i.width,height:i.height}}:(console.warn(`${n} not supported by docx. Using one of the supported mime types.`),l(e,t))},O=async(e,t)=>{try{return e.startsWith("data:")?await l(e,t):await b(e,t)}catch(a){return console.error(`Error resolving image: ${e}`,a),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},T=e=>({inline:async(t,a,r,n)=>{var i,s,g,m;if(/^image/.test(a.type)){let o=(s=a.url)!=null?s:n[(i=a.identifier)==null?void 0:i.toUpperCase()],c=(g=a.alt)!=null?g:o==null?void 0:o.split("/").pop();return a.type="",[new t.ImageRun({...await((m=e==null?void 0:e.imageResolver)!=null?m:O)(o,e),altText:{description:c,name:c,title:c}})]}return[]}});0&&(module.exports={SUPPORTED_IMAGE_TYPES,getImageMimeType,imagePlugin});
|
package/dist/plugins/image.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c}from"../chunk-LXTXD4UG.mjs";import"../chunk-3ZZBJC3M.mjs";export{a as SUPPORTED_IMAGE_TYPES,b as getImageMimeType,c as imagePlugin};
|
package/dist/plugins/list.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ILevelsOptions, LevelFormat } from "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 {};
|
package/dist/plugins/list.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var O=(o,t)=>{for(var i in t)f(o,i,{get:t[i],enumerable:!0})},T=(o,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of y(t))!D.call(o,n)&&n!==i&&f(o,n,{get:()=>t[n],enumerable:!(r=m(t,n))||r.enumerable});return o};var C=o=>T(f({},"__esModule",{value:!0}),o);var k={};O(k,{createLevels:()=>h,listPlugin:()=>v});module.exports=C(k);var e=require("docx");var P=()=>Math.random().toString(16).slice(2);var R=[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],h=(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=h(R),E=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],L={levels:M,bullets:E,defaultBullets:!1},v=o=>{let t=P(),i=`numbering-${t}`,r=`bullet-${t}`,{levels:n,bulletLevels:c,bullets:b,defaultBullets:I}={...L,...o};return{block:async(u,s,l,d)=>{var a,g;if(s.type!=="list")return[];let p=((g=(a=l.bullet)==null?void 0:a.level)!=null?g:-1)+1;return l.numbering=I?void 0:{level:p,reference:s.ordered?i:r},l.bullet={level:p},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,p)=>{var a;return{...d,text:(a=b[p])!=null?a:"\u2022",format:e.LevelFormat.BULLET}})}]}}}};0&&(module.exports={createLevels,listPlugin});
|
package/dist/plugins/list.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b}from"../chunk-GS5L4UWU.mjs";import"../chunk-IW743AEN.mjs";import"../chunk-3ZZBJC3M.mjs";export{a as createLevels,b as listPlugin};
|
package/dist/plugins/math.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IPlugin } from "../utils";
|
|
2
|
-
import * as DOCX from "docx";
|
|
3
|
-
/** Parse latex and convert to DOCX MathRun nodes */
|
|
4
|
-
export declare const parseLatex: (docx: typeof DOCX, value: string) => DOCX.MathRun[][];
|
|
5
|
-
/**
|
|
6
|
-
* Math Plugin
|
|
7
|
-
*/
|
|
8
|
-
export declare const mathPlugin: () => IPlugin<{
|
|
9
|
-
type: "" | "math" | "inlineMath";
|
|
10
|
-
value?: string;
|
|
11
|
-
}>;
|
package/dist/plugins/math.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var L=(t,a)=>{for(var s in a)m(t,s,{get:a[s],enumerable:!0})},B=(t,a,s,r)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of A(a))!P.call(t,n)&&n!==s&&m(t,n,{get:()=>a[n],enumerable:!(r=N(a,n))||r.enumerable});return t};var I=t=>B(m({},"__esModule",{value:!0}),t);var z={};L(z,{mathPlugin:()=>_,parseLatex:()=>b});module.exports=I(z);var R=require("latex-math"),h=t=>!!(t&&t.openMark==="{"&&t.closeMark==="}"),g=(t,a)=>new t.MathRun(a),G={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"},u=(t,a)=>{let s=[];for(let r of a)s.push(...d(t,r,s)||[]);return s},T=(t,a,s)=>{var n,i,o,f,M,S,y,w,v,C,O,X,D,q,k;let r=null;switch(a.content){case"newline":case"\\":return null;case"textcolor":{let e=(n=a.args)!=null?n:[];h(e[2])&&(r=u(t,e[2].content));break}case"text":{let e=(i=a.args)!=null?i:[];h(e[0])&&(r=u(t,e[0].content));break}case"^":{let e=s.pop();if(!e)break;let p=u(t,(M=(f=(o=a.args)==null?void 0:o[0])==null?void 0:f.content)!=null?M:[]);if(e.isSum){let c=new t.MathSum({children:[],superScript:p,subScript:e.sub});return c.sub=e.sub,c.sup=p,c.isSum=1,c}else if(e.sub)return new t.MathSubSuperScript({subScript:e.sub,superScript:p,children:[e.prev]});let l=new t.MathSuperScript({children:[e],superScript:p});return l.sup=p,l.prev=e,l}case"_":{let e=s.pop();if(!e)break;let p=u(t,(w=(y=(S=a.args)==null?void 0:S[0])==null?void 0:y.content)!=null?w:[]);if(e.isSum){let c=new t.MathSum({children:[],subScript:p,superScript:e.sup});return c.sup=e.sup,c.sub=p,c.isSum=1,c}else if(e.sup)return new t.MathSubSuperScript({subScript:p,superScript:e.sup,children:[e.prev]});let l=new t.MathSubScript({children:[e],subScript:p});return l.sub=p,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=(v=a.args)!=null?v:[];e.length===2&&h(e[0])&&h(e[1])&&(r=new t.MathFraction({numerator:u(t,e[0].content),denominator:u(t,e[1].content)}));break}case"sqrt":{let e=(C=a.args)!=null?C:[];e.length===1?r=new t.MathRadical({children:u(t,e[0].content)}):e.length===2&&(r=new t.MathRadical(e[0].content?{children:u(t,e[1].content),degree:u(t,e[0].content)}:{children:u(t,e[1].content)}));break}case"left":case"right":case"vec":return[];case"mathbf":return u(t,(D=(X=(O=a.args)==null?void 0:O[0])==null?void 0:X.content)!=null?D:[]);default:r=g(t,(q=G[a.content])!=null?q:a.content)}if((k=s[s.length-1])!=null&&k.isSum&&r){let e=s.pop();return[new t.MathSum({children:Array.isArray(r)?r:[r],superScript:e.sup,subScript:e.sub})]}return r},d=(t,a,s)=>{var n;let r=[];switch(a.type){case"string":r=[g(t,a.content)];break;case"whitespace":r=[g(t," ")];break;case"macro":{let i=T(t,a,s);if(i)r=Array.isArray(i)?i:[i];else return!1;break}case"group":r=u(t,a.content);break;case"environment":break;default:}if(a.type!=="macro"&&((n=s[s.length-1])!=null&&n.isSum)){let i=s.pop();return[new t.MathSum({children:r,superScript:i.sup,subScript:i.sub})]}return r},b=(t,a)=>{let s=(0,R.parseMath)(a),r=[[]],n=r[0];for(let i of s){let o=d(t,i,n);o?n.push(...o):r.push(n=[])}return r},_=()=>({inline:async(t,a)=>{var s;return a.type!=="inlineMath"&&a.type!=="math"?[]:(a.type="",[new t.Math({children:await b(t,(s=a.value)!=null?s:"").flat()})])},block:async(t,a)=>{var s;return a.type!=="math"&&a.type!=="inlineMath"?[]:(a.type="",await b(t,(s=a.value)!=null?s:"").map(r=>new t.Paragraph({children:[new t.Math({children:r})]})))}});0&&(module.exports={mathPlugin,parseLatex});
|
package/dist/plugins/math.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b}from"../chunk-QR3NYQYH.mjs";import"../chunk-3ZZBJC3M.mjs";export{b as mathPlugin,a as parseLatex};
|
package/dist/plugins/table.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { AlignmentType, type ITableCellOptions, type ITableOptions, type ITableRowOptions, VerticalAlign } from "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 {};
|
package/dist/plugins/table.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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});
|
package/dist/plugins/table.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b}from"../chunk-Q6Q2NBIZ.mjs";import"../chunk-3ZZBJC3M.mjs";export{a as defaultTableOptions,b as tablePlugin};
|
package/dist/section.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Root } from "./mdast";
|
|
2
|
-
import type { Definitions, FootnoteDefinitions, ISectionProps } from "./utils";
|
|
3
|
-
import { Paragraph } from "docx";
|
|
4
|
-
import * as docx from "docx";
|
|
5
|
-
/**
|
|
6
|
-
* Converts an MDAST tree to a DOCX document section.
|
|
7
|
-
* @param node - The root MDAST node
|
|
8
|
-
* @param definitions - Definitions mapping
|
|
9
|
-
* @param footnoteDefinitions - Footnote definitions mapping
|
|
10
|
-
* @param props - Section properties (optional)
|
|
11
|
-
* @returns A DOCX section representation
|
|
12
|
-
*/
|
|
13
|
-
export declare const toSection: (node: Root, definitions: Definitions, footnoteDefinitions: FootnoteDefinitions, props?: ISectionProps) => Promise<{
|
|
14
|
-
children: (Paragraph | docx.Table)[];
|
|
15
|
-
headers?: {
|
|
16
|
-
readonly default?: docx.Header;
|
|
17
|
-
readonly first?: docx.Header;
|
|
18
|
-
readonly even?: docx.Header;
|
|
19
|
-
};
|
|
20
|
-
footers?: {
|
|
21
|
-
readonly default?: docx.Footer;
|
|
22
|
-
readonly first?: docx.Footer;
|
|
23
|
-
readonly even?: docx.Footer;
|
|
24
|
-
};
|
|
25
|
-
properties?: docx.ISectionPropertiesOptions;
|
|
26
|
-
}>;
|
package/dist/section.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";var R=Object.create;var b=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var E=(n,i)=>{for(var p in i)b(n,p,{get:i[p],enumerable:!0})},w=(n,i,p,f)=>{if(i&&typeof i=="object"||typeof i=="function")for(let c of M(i))!v.call(n,c)&&c!==p&&b(n,c,{get:()=>i[c],enumerable:!(f=N(i,c))||f.enumerable});return n};var B=(n,i,p)=>(p=n!=null?R(S(n)):{},w(i||!n||!n.__esModule?b(p,"default",{value:n,enumerable:!0}):p,n)),F=n=>w(b({},"__esModule",{value:!0}),n);var L={};E(L,{toSection:()=>z});module.exports=F(L);var T=require("docx");var g=n=>{var i,p;return(i=n.children)!=null&&i.length?n.children.map(g).join(""):(p=n.value)!=null?p:""};var D={useTitle:!0,plugins:[]};var O=B(require("docx")),H=(n,i,p)=>{let f=async(r,P)=>{var e,u,o;let s=(await Promise.all(p.map(a=>{var m,y;return(y=(m=a.inline)==null?void 0:m.call(a,O,r,P,n,i,c))!=null?y:[]}))).flat(),l=Object.assign({},P,r.data),d=(u=r.url)!=null?u:n[(e=r.identifier)==null?void 0:e.toUpperCase()];switch(r.type){case"text":return[...s,...l.pre?r.value.split(`
|
|
2
|
-
`).map(a=>new T.TextRun({text:a,...l,break:1})):[new T.TextRun({text:r.value,...l})]];case"checkbox":return[...s,new T.CheckBox({checked:!!r.checked})];case"break":return[...s,new T.TextRun({break:1})];case"inlineCode":return[...s,new T.TextRun({text:r.value,...l,style:"code",font:{name:"Consolas"}})];case"emphasis":return l.italics=!0,[...s,...await c(r,l)];case"strong":return l.bold=!0,[...s,...await c(r,l)];case"delete":return l.strike=!0,[...s,...await c(r,l)];case"link":case"linkReference":return l.underline={},[...s,d.startsWith("#")?new T.InternalHyperlink({anchor:d.slice(1),children:await c(r,l)}):new T.ExternalHyperlink({link:d,children:await c(r,l)})];case"footnoteReference":return[...s,new T.FootnoteReferenceRun((o=i[r.identifier].id)!=null?o:0)];case"fragment":return[...s,...await c(r,l)];case"":return[...s];default:return console.warn(`Unsupported inline node type: ${r.type}`),[...s]}},c=async(r,P={})=>{var s,l;return(await Promise.all((l=(s=r.children)==null?void 0:s.map(d=>f(d,P)))!=null?l:[])).flat()};return c},z=async(n,i,p,f)=>{let{plugins:c,useTitle:r,...P}={...D,...f};c.forEach(e=>{var u;return(u=e==null?void 0:e.preprocess)==null?void 0:u.call(e,n)});let s=H(i,p,c),l=async(e,u)=>{var m,y,I,k;let o={...u},a=(await Promise.all(c.map(h=>{var x,C;return(C=(x=h.block)==null?void 0:x.call(h,O,e,o,d,s))!=null?C:[]}))).flat();switch(Object.assign(o,e.data),e.type){case"paragraph":{let h=o.pre?{alignment:"left"}:{},x=typeof o.checked=="boolean"?[new T.CheckBox({checked:o.checked,checkedState:{value:"2611"},uncheckedState:{value:"2610"}}),new T.TextRun(" ")]:[];return[...a,new T.Paragraph({...h,...o,children:[...x,...await s(e,o)]})]}case"heading":return[new T.Paragraph({...o,...a,heading:r?e.depth===1?"Title":`Heading${e.depth-1}`:`Heading${e.depth}`,children:[new T.Bookmark({id:g(e).replace(/[. ]+/g,"-").toLowerCase(),children:await s(e,o)})]})];case"code":return[...a,new T.Paragraph({border:{bottom:{style:T.BorderStyle.SINGLE,space:5,size:1},left:{style:T.BorderStyle.SINGLE,space:10,size:1},right:{style:T.BorderStyle.SINGLE,space:5,size:1},top:{style:T.BorderStyle.SINGLE,space:6,size:1}},...o,alignment:"left",style:"blockCode",children:e.value.split(`
|
|
3
|
-
`).map((h,x)=>new T.TextRun({...o,text:h,break:x===0?0:1,style:"code",font:{name:"Consolas"}}))})];case"list":return e.ordered?(o.bullet={level:((y=(m=o.bullet)==null?void 0:m.level)!=null?y:-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.")):o.bullet={level:((k=(I=o.bullet)==null?void 0:I.level)!=null?k:-1)+1},[...a,...await d(e,o)];case"blockquote":return[...a,...await d(e,o)];case"listItem":return o.checked=e.checked,[...a,...await d(e,o)];case"thematicBreak":return[...a,new T.Paragraph({...e.data,border:{top:{style:T.BorderStyle.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 d(e,o)];case"":return a;case"yaml":case"html":default:return console.warn(`May be an unsupported node type: ${e.type}`,e),a}},d=async(e,u)=>{var o;return(await Promise.all((o=e.children)==null?void 0:o.map(a=>l(a,u)))).flat()};return{...P,children:await d(n,{})}};0&&(module.exports={toSection});
|
package/dist/section.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-YNJKJBFY.mjs";import"./chunk-IW743AEN.mjs";import"./chunk-3ZZBJC3M.mjs";export{a as toSection};
|
package/dist/utils.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { ExternalHyperlink, ImageRun, InternalHyperlink, IParagraphOptions, TextRun, Table, Paragraph, IRunOptions, IPropertiesOptions, Math as DOCXMath } from "docx";
|
|
2
|
-
import * as DOCX from "docx";
|
|
3
|
-
import { BlockContent, Data, DefinitionContent, Parent, Root, RootContent } from "./mdast";
|
|
4
|
-
export { convertInchesToTwip, convertMillimetersToTwip } from "docx";
|
|
5
|
-
export type Optional<T> = {
|
|
6
|
-
[K in keyof T]?: T[K];
|
|
7
|
-
};
|
|
8
|
-
export type Mutable<T> = {
|
|
9
|
-
-readonly [K in keyof T]: T[K] extends object ? Mutable<T> : T[K];
|
|
10
|
-
};
|
|
11
|
-
/** Type representing definition mappings */
|
|
12
|
-
export type Definitions = Record<string, string>;
|
|
13
|
-
/** Type representing footnote definitions */
|
|
14
|
-
export type FootnoteDefinitions = Record<string, {
|
|
15
|
-
children: (BlockContent | DefinitionContent)[];
|
|
16
|
-
id?: number;
|
|
17
|
-
}>;
|
|
18
|
-
/**
|
|
19
|
-
* Extracts definitions and footnote definitions from a list of MDAST nodes.
|
|
20
|
-
*
|
|
21
|
-
* @param nodes - Array of MDAST nodes.
|
|
22
|
-
* @returns An object containing `definitions` and `footnoteDefinitions`.
|
|
23
|
-
*/
|
|
24
|
-
export declare const getDefinitions: (nodes: RootContent[]) => {
|
|
25
|
-
definitions: Definitions;
|
|
26
|
-
footnoteDefinitions: FootnoteDefinitions;
|
|
27
|
-
};
|
|
28
|
-
/** Type representing an extended RootContent node
|
|
29
|
-
* - this type is used to avoid type errors when setting type to empty string (in case you want to avoid reprocessing that node.) in plugins
|
|
30
|
-
*/
|
|
31
|
-
type ExtendedRootContent<T extends {
|
|
32
|
-
type: string;
|
|
33
|
-
data?: Data;
|
|
34
|
-
} = {
|
|
35
|
-
type: "";
|
|
36
|
-
data: {};
|
|
37
|
-
}> = RootContent | T;
|
|
38
|
-
/**
|
|
39
|
-
* Extracts the textual content from a given MDAST node.
|
|
40
|
-
* Recursively processes child nodes if present.
|
|
41
|
-
*
|
|
42
|
-
* @param node - The MDAST node to extract text from.
|
|
43
|
-
* @returns The combined text content of the node and its children.
|
|
44
|
-
*/
|
|
45
|
-
export declare const getTextContent: (node: ExtendedRootContent) => string;
|
|
46
|
-
/**
|
|
47
|
-
* Creates a random string - used to add as a random suffix to make style/numbering reference names unique
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
export declare const uuid: () => string;
|
|
51
|
-
/**
|
|
52
|
-
* Default configuration for converting MDAST to DOCX, including title handling and plugin extensions.
|
|
53
|
-
*/
|
|
54
|
-
interface IDefaultMdastToDocxSectionProps extends Omit<DOCX.ISectionOptions, "children"> {
|
|
55
|
-
/**
|
|
56
|
-
* If true, H1 corresponds to the title, H2 to Heading1, etc.
|
|
57
|
-
* @default true
|
|
58
|
-
*/
|
|
59
|
-
useTitle: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* List of plugins to extend conversion functionality.
|
|
62
|
-
*/
|
|
63
|
-
plugins: Array<IPlugin>;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Defines properties for a document section, omitting the "children" property from ISectionOptions.
|
|
67
|
-
* Also defining properties for MDAST to DOCX conversion
|
|
68
|
-
*/
|
|
69
|
-
export type ISectionProps = Optional<IDefaultMdastToDocxSectionProps>;
|
|
70
|
-
export declare const defaultSectionProps: IDefaultMdastToDocxSectionProps;
|
|
71
|
-
/**
|
|
72
|
-
* Defines document properties, excluding sections and footnotes (which are managed internally).
|
|
73
|
-
*/
|
|
74
|
-
export type IDocxProps = Omit<Mutable<IPropertiesOptions>, "sections" | "footnotes">;
|
|
75
|
-
export declare const defaultDocxProps: IDocxProps;
|
|
76
|
-
/**
|
|
77
|
-
* Mutable version of IRunOptions where all properties are writable.
|
|
78
|
-
*/
|
|
79
|
-
export type MutableRunOptions = Mutable<Omit<IRunOptions, "children">> & {
|
|
80
|
-
pre?: boolean;
|
|
81
|
-
};
|
|
82
|
-
export type InlineDocxNodes = TextRun | ImageRun | InternalHyperlink | ExternalHyperlink | DOCXMath;
|
|
83
|
-
export type InlineProcessor = (node: ExtendedRootContent, runProps: MutableRunOptions) => Promise<InlineDocxNodes[]>;
|
|
84
|
-
export type InlineChildrenProcessor = (node: Parent, runProps?: MutableRunOptions) => Promise<InlineDocxNodes[]>;
|
|
85
|
-
/**
|
|
86
|
-
* Mutable version of IParagraphOptions where all properties are writable.
|
|
87
|
-
*/
|
|
88
|
-
export type MutableParaOptions = Omit<Mutable<IParagraphOptions>, "children"> & {
|
|
89
|
-
checked?: boolean | null;
|
|
90
|
-
pre?: boolean;
|
|
91
|
-
};
|
|
92
|
-
export type BlockNodeProcessor = (node: ExtendedRootContent, paraProps: MutableParaOptions) => Promise<(Paragraph | Table)[]>;
|
|
93
|
-
export type BlockNodeChildrenProcessor = (node: Parent | Root, paraProps: MutableParaOptions) => Promise<(Paragraph | Table)[]>;
|
|
94
|
-
/**
|
|
95
|
-
* Interface for extending MDAST to DOCX conversion using plugins.
|
|
96
|
-
*/
|
|
97
|
-
export interface IPlugin<T extends {
|
|
98
|
-
type: string;
|
|
99
|
-
} = {
|
|
100
|
-
type: "";
|
|
101
|
-
}> {
|
|
102
|
-
/**
|
|
103
|
-
* Processes block-level nodes.
|
|
104
|
-
*/
|
|
105
|
-
block?: (docx: typeof DOCX, node: ExtendedRootContent<T>, paraProps: MutableParaOptions, blockChildrenProcessor: BlockNodeChildrenProcessor, inlineChildrenProcessor: InlineChildrenProcessor) => Promise<(Paragraph | Table)[]>;
|
|
106
|
-
/**
|
|
107
|
-
* Processes inline-level nodes.
|
|
108
|
-
*/
|
|
109
|
-
inline?: (docx: typeof DOCX, node: ExtendedRootContent<T>, runProps: MutableRunOptions, definitions: Definitions, footnoteDefinitions: FootnoteDefinitions, inlineChildrenProcessor: InlineChildrenProcessor) => Promise<InlineDocxNodes[]>;
|
|
110
|
-
/**
|
|
111
|
-
* Allows plugins to modify document-level DOCX properties, such as styles, numbering, headers, and footers. This is useful for global formatting customizations.
|
|
112
|
-
*/
|
|
113
|
-
root?: (props: IDocxProps) => void;
|
|
114
|
-
/**
|
|
115
|
-
* Preprocess mdast tree before conversion
|
|
116
|
-
*/
|
|
117
|
-
preprocess?: (tree: Root) => void;
|
|
118
|
-
}
|
|
119
|
-
export declare const standardizeColor: (str: string) => string;
|
|
120
|
-
/**
|
|
121
|
-
* @mayank/docx is a fork of the `docx` library with minor modifications,
|
|
122
|
-
* primarily adding exports for additional types missing from the original `docx` library.
|
|
123
|
-
*/
|
package/dist/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var u=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},f=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!d.call(t,r)&&r!==n&&a(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var P=t=>f(a({},"__esModule",{value:!0}),t);var b={};u(b,{convertInchesToTwip:()=>i.convertInchesToTwip,convertMillimetersToTwip:()=>i.convertMillimetersToTwip,defaultDocxProps:()=>h,defaultSectionProps:()=>g,getDefinitions:()=>s,getTextContent:()=>p,standardizeColor:()=>D,uuid:()=>x});module.exports=P(b);var i=require("docx"),s=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,s(o.children))}),{definitions:e,footnoteDefinitions:n}},p=t=>{var e,n;return(e=t.children)!=null&&e.length?t.children.map(p).join(""):(n=t.value)!=null?n:""},x=()=>Math.random().toString(16).slice(2),g={useTitle:!0,plugins:[]},h={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}}}}}},D=t=>{let e=document.createElement("canvas").getContext("2d");return e?(e.fillStyle=t,e.fillStyle.slice(1)):t.startsWith("#")?t.slice(1):"auto"};0&&(module.exports={convertInchesToTwip,convertMillimetersToTwip,defaultDocxProps,defaultSectionProps,getDefinitions,getTextContent,standardizeColor,uuid});
|
package/dist/utils.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h}from"./chunk-IW743AEN.mjs";import"./chunk-3ZZBJC3M.mjs";export{g as convertInchesToTwip,h as convertMillimetersToTwip,e as defaultDocxProps,d as defaultSectionProps,a as getDefinitions,b as getTextContent,f as standardizeColor,c as uuid};
|