mdast2docx 0.1.0 → 0.2.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.
Files changed (53) hide show
  1. package/dist/{chunk-7LR5HC5O.mjs → chunk-35E6UZDH.mjs} +3 -3
  2. package/dist/{chunk-7W4N3GRD.mjs → chunk-ALSMH2CW.mjs} +1 -1
  3. package/dist/chunk-CRVVOUD7.mjs +1 -0
  4. package/dist/chunk-ECHPYCZC.mjs +2 -0
  5. package/dist/chunk-I5QUWH2X.mjs +1 -0
  6. package/dist/{chunk-Z5DPYROV.mjs → chunk-JOIHCSIR.mjs} +1 -1
  7. package/dist/chunk-LXTXD4UG.mjs +1 -0
  8. package/dist/chunk-MSGIMOZN.mjs +1 -0
  9. package/dist/chunk-Q6Q2NBIZ.mjs +1 -0
  10. package/dist/chunk-X6PWMGYB.mjs +5 -0
  11. package/dist/{chunk-ZKNVKZAF.mjs → chunk-Z2MODMIK.mjs} +1 -1
  12. package/dist/index.d.ts +2 -3
  13. package/dist/index.js +2 -2
  14. package/dist/index.mjs +1 -1
  15. package/dist/{multipart-parser-WKN2UV32.mjs → multipart-parser-ECCTUILZ.mjs} +1 -1
  16. package/dist/plugins/html.d.ts +9 -0
  17. package/dist/plugins/html.js +5 -1
  18. package/dist/plugins/html.mjs +1 -0
  19. package/dist/plugins/image.d.ts +9 -5
  20. package/dist/plugins/image.js +1 -1
  21. package/dist/plugins/image.mjs +1 -1
  22. package/dist/plugins/index.d.ts +1 -0
  23. package/dist/plugins/index.js +70 -66
  24. package/dist/plugins/index.mjs +1 -1
  25. package/dist/plugins/list.d.ts +1 -1
  26. package/dist/plugins/list.js +1 -1
  27. package/dist/plugins/list.mjs +1 -1
  28. package/dist/plugins/math.d.ts +1 -1
  29. package/dist/plugins/math.mjs +1 -1
  30. package/dist/plugins/{node.js → node/index.js} +1 -1
  31. package/dist/plugins/node/index.mjs +1 -0
  32. package/dist/plugins/{node-image.d.ts → node/node-image.d.ts} +10 -6
  33. package/dist/plugins/{node-image.js → node/node-image.js} +1 -1
  34. package/dist/plugins/node/node-image.mjs +1 -0
  35. package/dist/plugins/table.d.ts +1 -1
  36. package/dist/plugins/table.js +1 -1
  37. package/dist/plugins/table.mjs +1 -1
  38. package/dist/section.d.ts +3 -8
  39. package/dist/section.js +2 -2
  40. package/dist/section.mjs +1 -1
  41. package/dist/utils.d.ts +13 -10
  42. package/dist/utils.js +1 -1
  43. package/dist/utils.mjs +1 -1
  44. package/package.json +4 -2
  45. package/dist/chunk-3ZZBJC3M.mjs +0 -1
  46. package/dist/chunk-GM6UUFDK.mjs +0 -2
  47. package/dist/chunk-TASCVLMX.mjs +0 -1
  48. package/dist/chunk-UXY5TDOP.mjs +0 -1
  49. package/dist/chunk-XIRSNIMN.mjs +0 -1
  50. package/dist/chunk-YKZOUIFR.mjs +0 -1
  51. package/dist/plugins/node-image.mjs +0 -1
  52. package/dist/plugins/node.mjs +0 -1
  53. /package/dist/plugins/{node.d.ts → node/index.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ import{a}from"../chunk-X6PWMGYB.mjs";import"../chunk-MSGIMOZN.mjs";import"../chunk-I5QUWH2X.mjs";export{a as htmlPlugin};
@@ -1,9 +1,13 @@
1
- import type { IImageOptions } from "@mayank1513/docx";
1
+ import type { IImageOptions } from "docx";
2
2
  import { IPlugin } from "../utils";
3
3
  /**
4
4
  * List of image types fully supported by docx. SVG requires fallback thus we do not include that here.
5
5
  */
6
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>;
7
11
  /**
8
12
  * Options for the image plugin.
9
13
  */
@@ -18,11 +22,11 @@ export interface IImagePluginOptions {
18
22
  * @default "png"
19
23
  */
20
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;
21
29
  }
22
- /**
23
- * Resolves an image source URL into the appropriate image options for DOCX conversion.
24
- */
25
- export type ImageResolver = (src: string, options?: IImagePluginOptions) => Promise<IImageOptions>;
26
30
  /**
27
31
  * Determines the MIME type of an image based on its binary signature.
28
32
  *
@@ -1 +1 @@
1
- "use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var a in e)p(t,a,{get:e[a],enumerable:!0})},x=(t,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of w(e))!F.call(t,n)&&n!==a&&p(t,n,{get:()=>e[n],enumerable:!(i=y(e,n))||i.enumerable});return t};var v=t=>x(p({},"__esModule",{value:!0}),t);var D={};P(D,{SUPPORTED_IMAGE_TYPES:()=>h,getImageMimeType:()=>f,imagePlugin:()=>T});module.exports=v(D);var h=["jpeg","jpg","bmp","gif","png"],f=t=>{let e=new Uint8Array(t).slice(0,4);if(e[0]===66&&e[1]===77)return"bmp";switch(e.reduce((i,n)=>i+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(t,e)=>{var u,I;let a=(u=e==null?void 0:e.scale)!=null?u:E,i=document.createElement("canvas"),n=i.getContext("2d");if(!n)throw new Error("Canvas context not available");let r=new Image;r.src=t,await new Promise(d=>r.onload=d);let s=r.width*a,g=r.height*a;i.width=s,i.height=g,n.drawImage(r,0,0,s,g);let o=t.split(";")[0].split("/")[1];if(h.includes(o))return{data:t,type:o,transformation:{width:s/a,height:g/a}};let c=(I=e==null?void 0:e.fallbackImageType)!=null?I:"png",m={data:i.toDataURL(`image/${c}`),type:c,transformation:{width:s/a,height:g/a}};return t.includes("svg")?{...m,type:"svg",data:t,fallback:{type:c,data:m.data}}:m},b=async(t,e)=>{var s;let a=await fetch(t.startsWith("http")?t:`${window.location.origin}/${t.replace(/^\/+/,"")}`);if(/(svg|xml)/.test((s=a.headers.get("content-type"))!=null?s:"")||t.endsWith(".svg")){let g=await a.text();return l(`data:image/svg+xml;base64,${btoa(g)}`,e)}let i=await a.arrayBuffer(),n=f(i)||"png",r=await createImageBitmap(new Blob([i],{type:n}));return h.includes(n)?{type:n,data:i,transformation:{width:r.width,height:r.height}}:(console.warn(`${n} not supported by docx. Using one of the supported mime types.`),l(t,e))},O=async(t,e)=>{try{return t.startsWith("data:")?await l(t,e):await b(t,e)}catch(a){return console.error(`Error resolving image: ${t}`,a),{type:"png",data:Buffer.from([]),transformation:{width:100,height:100}}}},T=t=>({inline:async(e,a,i,n)=>{var r,s,g;if(/^image/.test(a.type)){let o=(s=a.url)!=null?s:n[(r=a.identifier)==null?void 0:r.toUpperCase()],c=(g=a.alt)!=null?g:o==null?void 0:o.split("/").pop();return a.type="",[new e.ImageRun({...await O(o,t),altText:{description:c,name:c,title:c}})]}return[]}});0&&(module.exports={SUPPORTED_IMAGE_TYPES,getImageMimeType,imagePlugin});
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});
@@ -1 +1 @@
1
- import{a,b,c}from"../chunk-XIRSNIMN.mjs";import"../chunk-3ZZBJC3M.mjs";export{a as SUPPORTED_IMAGE_TYPES,b as getImageMimeType,c as imagePlugin};
1
+ import{a,b,c}from"../chunk-LXTXD4UG.mjs";import"../chunk-I5QUWH2X.mjs";export{a as SUPPORTED_IMAGE_TYPES,b as getImageMimeType,c as imagePlugin};
@@ -2,3 +2,4 @@ export * from "./image";
2
2
  export * from "./table";
3
3
  export * from "./list";
4
4
  export * from "./math";
5
+ export * from "./html";