jspdf-md-renderer 1.8.0 → 1.8.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/dist/index.js +1 -1
- package/dist/index.mjs +75 -77
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("marked");var o=(t=>(t.Heading="heading",t.Paragraph="paragraph",t.List="list",t.ListItem="list_item",t.Blockquote="blockquote",t.Code="code",t.CodeSpan="codespan",t.Table="table",t.Html="html",t.Hr="hr",t.Image="image",t.Link="link",t.Strong="strong",t.Em="em",t.TableHeader="table_header",t.TableCell="table_cell",t.Raw="raw",t.Text="text",t))(o||{});const z=async t=>{const i=await I.marked.lexer(t,{async:!0});return W(i)},W=t=>{const i=[];return t.forEach(s=>{try{const x=k[s.type];x?i.push(x(s)):i.push({type:o.Raw,content:s.raw})}catch(x){console.error("Failed to handle token ==>",s,x)}}),i},k={[o.Heading]:t=>({type:o.Heading,depth:t.depth,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Paragraph]:t=>({type:o.Paragraph,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.List]:t=>({type:o.List,ordered:t.ordered,start:t.start,items:t.items?W(t.items):[]}),[o.ListItem]:t=>({type:o.ListItem,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Code]:t=>({type:o.Code,lang:t.lang,code:t.text}),[o.Table]:t=>({type:o.Table,header:t.header.map(i=>({type:o.TableHeader,content:i})),rows:t.rows.map(i=>i.map(s=>({type:o.TableCell,content:s})))}),[o.Image]:t=>({type:o.Image,src:t.href,alt:t.text}),[o.Link]:t=>({type:o.Link,href:t.href,text:t.text,items:t.tokens?W(t.tokens):[]}),[o.Strong]:t=>({type:o.Strong,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Em]:t=>({type:o.Em,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Text]:t=>({type:o.Text,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Hr]:t=>({type:o.Hr,content:t.raw,items:t.tokens?W(t.tokens):[]}),[o.CodeSpan]:t=>({type:o.CodeSpan,content:t.text,items:t.tokens?W(t.tokens):[]})},L=class L{static initialize(i){this.options_=i,this.cursor={x:i.cursor.x,y:i.cursor.y}}static getCursor(){return this.cursor}static setCursor(i){this.cursor=i}static get options(){return this.options_}static get isInlineLockActive(){return this.inlineLock}static activateInlineLock(){this.inlineLock=!0}static deactivateInlineLock(){this.inlineLock=!1}static updateX(i,s="set"){s==="set"?this.cursor.x=i:s==="add"&&(this.cursor.x+=i)}static updateY(i,s="set"){s==="set"?this.cursor.y=i:s==="add"&&(this.cursor.y+=i)}static get X(){return this.cursor.x}static get Y(){return this.cursor.y}};L.cursor={x:0,y:0},L.inlineLock=!1;let e=L;const C=t=>{var i,s;typeof e.options.pageBreakHandler=="function"?e.options.pageBreakHandler():t.addPage((i=e.options.page)==null?void 0:i.format,(s=e.options.page)==null?void 0:s.orientation),e.updateY(e.options.page.topmargin),e.updateX(e.options.page.xpading)},d=t=>t.getTextDimensions("H").h*e.options.page.defaultLineHeightFactor,y=t=>t.getTextDimensions("H").w*e.options.page.defaultLineHeightFactor,E=(t,i,s,x)=>{const h=6-((i==null?void 0:i.depth)??0)>0?6-((i==null?void 0:i.depth)??0):1;if(t.setFontSize(e.options.page.defaultFontSize+h),e.updateY(h*.2*d(t),"add"),i!=null&&i.items&&(i==null?void 0:i.items.length)>0)for(const p of(i==null?void 0:i.items)??[])x(p,s,!1);else t.text((i==null?void 0:i.content)??"",e.X+s,e.Y,{align:"left",maxWidth:e.options.page.maxContentWidth-s});t.setFontSize(e.options.page.defaultFontSize),e.updateX(e.options.page.xpading)},D=(t,i,s,x,h,p,c,g,a)=>{const l=(g-s)/(i.length-1);let n=h;const r=p+x*c;for(const u of i)t.text(u.text,n,r,{align:"justify",lineHeightFactor:a,maxWidth:g}),n+=u.wordLength+l},P=(t,i,s,x,h,p,c,g)=>{const a=t.map(l=>l.text).join(" ");i.text(a,s,x+h*p,{align:"justify",lineHeightFactor:g,maxWidth:c})},F=(t,i,s,x,h,p)=>{const c={x:s,y:x},g=t.getTextDimensions("A").h*p,a=i.split(" ");let l=0,n=[],r=0;for(const u of a){const b=t.getTextWidth(u+"a");b+r>=h&&(D(t,n,r,l++,s,x,g,h,p),n=[],r=0),n.push({text:u,wordLength:b}),r+=b}return n.length>0&&P(n,t,s,x,l,g,h,p),c.y=x+l*g,c.x=t.getTextWidth(i)+s,c},S=(t,i,s)=>{const x=t.getFont().fontName,h=t.getFont().fontStyle,p=t.getFontSize(),c=a=>{switch(a){case"normal":return 0;case"bold":return 1;case"italic":return 1.5;case"bolditalic":return 1.5;default:return 0}},g=(a,l)=>{var u;l==="bold"?t.setFont(e.options.font.bold.name&&e.options.font.bold.name!==""?e.options.font.bold.name:x,e.options.font.bold.style||"bold"):l==="italic"?t.setFont(e.options.font.regular.name,"italic"):l==="bolditalic"?t.setFont(e.options.font.bold.name&&e.options.font.bold.name!==""?e.options.font.bold.name:x,"bolditalic"):t.setFont(e.options.font.regular.name,h);const n=e.options.page.maxContentWidth-s-e.X,r=t.splitTextToSize(a,n);if(e.isInlineLockActive)for(let b=0;b<r.length;b++)t.text(r[b],e.X+s,e.Y,{baseline:"top",maxWidth:n}),e.updateX(t.getTextDimensions(r[b]).w+1,"add"),b<r.length-1&&(e.updateY(d(t),"add"),e.updateX(e.options.page.xpading+s,"set"));else if(r.length>1){const b=r[0],f=(u=r==null?void 0:r.slice(1))==null?void 0:u.join(" ");t.text(b,e.X+(s>=2?s+2*c(l):0),e.Y,{baseline:"top",maxWidth:n}),e.updateX(e.options.page.xpading+s),e.updateY(d(t),"add");const Y=e.options.page.maxContentWidth-s-e.options.page.xpading;t.splitTextToSize(f,Y).forEach(m=>{t.text(m,e.X+y(t),e.Y,{baseline:"top",maxWidth:Y})})}else t.text(a,e.X+s,e.Y,{baseline:"top",maxWidth:n}),e.updateX(t.getTextDimensions(a).w+(s>=2?a.split(" ").length+2:2)*c(l)*.5,"add")};if(i.type==="text"&&i.items&&i.items.length>0)for(const a of i.items)if(a.type==="em"||a.type==="strong"){const l=a.type==="em"?"italic":"bold";if(a.items&&a.items.length>0)for(const n of a.items)n.type==="strong"&&l==="italic"||n.type==="em"&&l==="bold"?g(n.content||"","bolditalic"):g(n.content||"",l);else g(a.content||"",l)}else g(a.content||"","normal");else i.type==="em"?g(i.content||"","italic"):i.type==="strong"?g(i.content||"","bold"):g(i.content||"","normal");t.setFont(x,h),t.setFontSize(p)},j=(t,i,s,x)=>{e.activateInlineLock(),t.setFontSize(e.options.page.defaultFontSize);let h=i.content;const p=t.getTextDimensions("A").h*e.options.page.defaultLineHeightFactor;if(i!=null&&i.items&&(i==null?void 0:i.items.length)>0){let c=0;for(const g of(i==null?void 0:i.items)??[])["strong","em","text"].includes(g.type)?(g.type!=="text"&&c!=0&&e.updateX(y(t)*1.5,"add"),S(t,g,s),g.type!=="text"&&c!=0&&e.updateX(y(t),"add")):x(g,s,!1),c++}else{if(e.Y+t.splitTextToSize(h??"",e.options.page.maxContentWidth-s).length*p-3*p>=e.options.page.maxContentHeight){const g=t.splitTextToSize(h??"",e.options.page.maxContentWidth-s),a=[],l=e.Y;for(let n=0;n<g.length;n++)if(e.Y-2*p<e.options.page.maxContentHeight)a.push(g[n]),e.updateY(e.options.page.lineSpace,"add");else{n<=g.length-1&&(h=g.slice(n).join(""));break}if(a.length>0){const n=F(t,a.join(" "),e.X+s,l,e.options.page.maxContentWidth-s,e.options.page.defaultLineHeightFactor);e.setCursor(n)}C(t)}const c=F(t,h??"",e.X+s,e.Y,e.options.page.maxContentWidth-s,e.options.page.defaultLineHeightFactor).y+d(t);e.updateY(c)}e.updateY(p,"add"),e.updateX(e.options.page.xpading),e.deactivateInlineLock()},v=(t,i,s,x)=>{var h;t.setFontSize(e.options.page.defaultFontSize);for(const[p,c]of((h=i==null?void 0:i.items)==null?void 0:h.entries())??[]){const g=i.ordered?(i.start??0)+p:i.start;x(c,s+1,!0,g,i.ordered)}},A=(t,i,s,x,h,p)=>{const c=s*e.options.page.indent,g=p?`${h}. `:"• ";e.Y+d(t)>=e.options.page.maxContentHeight&&C(t),t.setFont(e.options.font.regular.name,e.options.font.regular.style),t.text(g,e.X+c,e.Y,{baseline:"top"});const a=t.getTextWidth(g);if(e.updateX(a,"add"),i.items&&i.items.length>0)for(const l of i.items){if(e.Y+d(t)>=e.options.page.maxContentHeight&&C(t),l.type===o.List)x(l,s+1,!0,h,l.ordered??!1);else if(l.type===o.ListItem){const n=i.type===o.List?s:s+1;x(l,n,!0,h,p)}else S(t,l,c);e.updateX(e.options.page.xpading),e.updateY(d(t),"add")}else if(i.content){const l=e.X+c,n=t.getTextWidth(g),r=e.options.page.maxContentWidth-c-n,u=t.splitTextToSize(i.content,r);if(u.length>0){t.text(u[0],l+n,e.Y,{baseline:"top",maxWidth:r});for(let f=1;f<u.length;f++)e.updateY(d(t),"add"),t.text(u[f],l+n,e.Y,{baseline:"top",maxWidth:r});e.updateX(e.options.page.xmargin+c),e.updateY(d(t),"add");const b=t.getTextWidth(i.content);e.updateX(b,"add")}}},R=(t,i,s,x,h,p,c,g=!0)=>{if(i!=null&&i.items&&(i==null?void 0:i.items.length)>0)for(const a of(i==null?void 0:i.items)??[])h(a,s,x,p,c,g);else{const a=s*e.options.page.indent,l=x?c?`${p}. `:"• ":"";if(x&&l){const n=t.getTextWidth(l),r=e.options.page.maxContentWidth-a-n,u=t.splitTextToSize(i.content||"",r);if(u.length>0){t.text(l,e.X+a,e.Y,{baseline:"top"}),t.text(u[0],e.X+a+n,e.Y,{baseline:"top",maxWidth:r});for(let f=1;f<u.length;f++)e.updateX(e.options.page.xpading),e.updateY(d(t),"add"),t.text(u[f],e.X+a+n,e.Y,{baseline:"top",maxWidth:r-a-n});e.updateY(d(t),"add"),e.updateX(e.options.page.xpading+a);const b=t.getTextWidth(i.content||"");e.updateX(b,"add")}}else{const n=t.splitTextToSize(i.content||"",e.options.page.maxContentWidth-a);if(e.Y+n.length*d(t)>=e.options.page.maxContentHeight&&C(t),g){const r=F(t,i.content||"",e.X+a,e.Y,e.options.page.maxContentWidth-a,e.options.page.defaultLineHeightFactor).y+d(t)*.5;e.updateY(r),e.updateX(e.options.page.xpading)}else t.text(n||"",e.X+a,e.Y,{baseline:"top"}),e.updateX(t.getTextWidth(i.content||""),"add"),e.X>=e.options.page.xpading+e.options.page.maxContentWidth&&C(t)}}},B=t=>{const i=t.internal.pageSize.getWidth();t.setLineDashPattern([1,1],0),t.setLineWidth(.1),t.line(e.options.page.xpading,e.Y,i-e.options.page.xpading,e.Y),t.setLineWidth(.1),t.setLineDashPattern([],0),e.updateY(d(t),"add")},_=(t,i,s,x)=>{const h=s*e.options.page.indent;e.Y+t.splitTextToSize(i.code??"",e.options.page.maxContentWidth-h).length*d(t)-2*d(t)>=e.options.page.maxContentHeight&&C(t);const p=t.splitTextToSize(i.code??"",e.options.page.maxContentWidth-h).length*d(t);e.updateY(e.options.page.lineSpace,"add"),t.setFillColor("#EEEEEE"),t.setDrawColor("#eee"),t.roundedRect(e.X,e.Y-e.options.page.lineSpace,e.options.page.maxContentWidth,p,2,2,"FD"),t.setFontSize(10),t.text(i.lang??"",e.X+e.options.page.maxContentWidth-t.getTextWidth(i.lang??"")-e.options.page.lineSpace/2,e.Y),t.setFontSize(e.options.page.defaultFontSize),t.text(i.code??"",e.X+4,e.Y),e.updateY(p,"add")},q=(t,i,s)=>{var u,b;const x=t.getFont().fontName,h=t.getFont().fontStyle,p=t.getFontSize(),c=t.getTextColor(),g=((u=e.options.link)==null?void 0:u.linkColor)||[0,0,255];t.setTextColor(...g);const a=e.options.page.maxContentWidth-s-e.X,l=i.text||i.content||"",n=i.href||"",r=t.splitTextToSize(l,a);if(e.isInlineLockActive)for(let f=0;f<r.length;f++){const Y=t.getTextDimensions(r[f]).w,X=d(t)/2;t.link(e.X+s,e.Y,Y,X,{url:n}),t.text(r[f],e.X+s,e.Y,{baseline:"top",maxWidth:a}),e.updateX(Y+1,"add"),e.X+Y>e.options.page.maxContentWidth-s&&(e.updateY(X,"add"),e.updateX(e.options.page.xpading+s,"set")),f<r.length-1&&(e.updateY(X,"add"),e.updateX(e.options.page.xpading+s,"set"))}else if(r.length>1){const f=r[0],Y=(b=r==null?void 0:r.slice(1))==null?void 0:b.join(" "),X=t.getTextDimensions(f).w,m=d(t)/2;t.link(e.X+s,e.Y,X,m,{url:n}),t.text(f,e.X+s,e.Y,{baseline:"top",maxWidth:a}),e.updateX(e.options.page.xpading+s),e.updateY(m,"add");const H=e.options.page.maxContentWidth-s-e.options.page.xpading;t.splitTextToSize(Y,H).forEach(T=>{const w=t.getTextDimensions(T).w;t.link(e.X+y(t),e.Y,w,m,{url:n}),t.text(T,e.X+y(t),e.Y,{baseline:"top",maxWidth:H})})}else{const f=t.getTextDimensions(l).w,Y=d(t)/2;t.link(e.X+s,e.Y,f,Y,{url:n}),t.text(l,e.X+s,e.Y,{baseline:"top",maxWidth:a}),e.updateX(f+2,"add")}t.setFont(x,h),t.setFontSize(p),t.setTextColor(c)},J=async(t,i,s)=>{e.initialize(s);const x=await z(i);console.log(x);const h=(p,c=0,g=!1,a=0,l=!1,n=!0)=>{const r=c*s.page.indent;switch(e.Y+t.splitTextToSize(p.content??"",s.page.maxContentWidth-r).length*d(t)>=s.page.maxContentHeight&&C(t),p.type){case o.Heading:E(t,p,r,h);break;case o.Paragraph:j(t,p,r,h);break;case o.List:v(t,p,c,h);break;case o.ListItem:A(t,p,c,h,a,l);break;case o.Hr:B(t);break;case o.Code:_(t,p,c);break;case o.Strong:case o.Em:S(t,p,r);break;case o.Link:q(t,p,r);break;case o.Raw:case o.Text:R(t,p,c,g,h,a,l,n);break;default:console.warn(`Warning: Unsupported element type encountered: ${p.type}.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("marked");var o=(t=>(t.Heading="heading",t.Paragraph="paragraph",t.List="list",t.ListItem="list_item",t.Blockquote="blockquote",t.Code="code",t.CodeSpan="codespan",t.Table="table",t.Html="html",t.Hr="hr",t.Image="image",t.Link="link",t.Strong="strong",t.Em="em",t.TableHeader="table_header",t.TableCell="table_cell",t.Raw="raw",t.Text="text",t))(o||{});const z=async t=>{const i=await I.marked.lexer(t,{async:!0});return W(i)},W=t=>{const i=[];return t.forEach(s=>{try{const x=k[s.type];x?i.push(x(s)):i.push({type:o.Raw,content:s.raw})}catch(x){console.error("Failed to handle token ==>",s,x)}}),i},k={[o.Heading]:t=>({type:o.Heading,depth:t.depth,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Paragraph]:t=>({type:o.Paragraph,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.List]:t=>({type:o.List,ordered:t.ordered,start:t.start,items:t.items?W(t.items):[]}),[o.ListItem]:t=>({type:o.ListItem,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Code]:t=>({type:o.Code,lang:t.lang,code:t.text}),[o.Table]:t=>({type:o.Table,header:t.header.map(i=>({type:o.TableHeader,content:i})),rows:t.rows.map(i=>i.map(s=>({type:o.TableCell,content:s})))}),[o.Image]:t=>({type:o.Image,src:t.href,alt:t.text}),[o.Link]:t=>({type:o.Link,href:t.href,text:t.text,items:t.tokens?W(t.tokens):[]}),[o.Strong]:t=>({type:o.Strong,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Em]:t=>({type:o.Em,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Text]:t=>({type:o.Text,content:t.text,items:t.tokens?W(t.tokens):[]}),[o.Hr]:t=>({type:o.Hr,content:t.raw,items:t.tokens?W(t.tokens):[]}),[o.CodeSpan]:t=>({type:o.CodeSpan,content:t.text,items:t.tokens?W(t.tokens):[]})},L=class L{static initialize(i){this.options_=i,this.cursor={x:i.cursor.x,y:i.cursor.y}}static getCursor(){return this.cursor}static setCursor(i){this.cursor=i}static get options(){return this.options_}static get isInlineLockActive(){return this.inlineLock}static activateInlineLock(){this.inlineLock=!0}static deactivateInlineLock(){this.inlineLock=!1}static updateX(i,s="set"){s==="set"?this.cursor.x=i:s==="add"&&(this.cursor.x+=i)}static updateY(i,s="set"){s==="set"?this.cursor.y=i:s==="add"&&(this.cursor.y+=i)}static get X(){return this.cursor.x}static get Y(){return this.cursor.y}};L.cursor={x:0,y:0},L.inlineLock=!1;let e=L;const C=t=>{var i,s;typeof e.options.pageBreakHandler=="function"?e.options.pageBreakHandler():t.addPage((i=e.options.page)==null?void 0:i.format,(s=e.options.page)==null?void 0:s.orientation),e.updateY(e.options.page.topmargin),e.updateX(e.options.page.xpading)},d=t=>t.getTextDimensions("H").h*e.options.page.defaultLineHeightFactor,y=t=>t.getTextDimensions("H").w*e.options.page.defaultLineHeightFactor,E=(t,i,s,x)=>{const h=6-((i==null?void 0:i.depth)??0)>0?6-((i==null?void 0:i.depth)??0):1;if(t.setFontSize(e.options.page.defaultFontSize+h),e.updateY(h*.2*d(t),"add"),i!=null&&i.items&&(i==null?void 0:i.items.length)>0)for(const p of(i==null?void 0:i.items)??[])x(p,s,!1);else t.text((i==null?void 0:i.content)??"",e.X+s,e.Y,{align:"left",maxWidth:e.options.page.maxContentWidth-s});t.setFontSize(e.options.page.defaultFontSize),e.updateX(e.options.page.xpading)},D=(t,i,s,x,h,p,c,g,a)=>{const l=(g-s)/(i.length-1);let n=h;const r=p+x*c;for(const u of i)t.text(u.text,n,r,{align:"justify",lineHeightFactor:a,maxWidth:g}),n+=u.wordLength+l},P=(t,i,s,x,h,p,c,g)=>{const a=t.map(l=>l.text).join(" ");i.text(a,s,x+h*p,{align:"justify",lineHeightFactor:g,maxWidth:c})},F=(t,i,s,x,h,p)=>{const c={x:s,y:x},g=t.getTextDimensions("A").h*p,a=i.split(" ");let l=0,n=[],r=0;for(const u of a){const b=t.getTextWidth(u+"a");b+r>=h&&(D(t,n,r,l++,s,x,g,h,p),n=[],r=0),n.push({text:u,wordLength:b}),r+=b}return n.length>0&&P(n,t,s,x,l,g,h,p),c.y=x+l*g,c.x=t.getTextWidth(i)+s,c},S=(t,i,s)=>{const x=t.getFont().fontName,h=t.getFont().fontStyle,p=t.getFontSize(),c=a=>{switch(a){case"normal":return 0;case"bold":return 1;case"italic":return 1.5;case"bolditalic":return 1.5;default:return 0}},g=(a,l)=>{var u;l==="bold"?t.setFont(e.options.font.bold.name&&e.options.font.bold.name!==""?e.options.font.bold.name:x,e.options.font.bold.style||"bold"):l==="italic"?t.setFont(e.options.font.regular.name,"italic"):l==="bolditalic"?t.setFont(e.options.font.bold.name&&e.options.font.bold.name!==""?e.options.font.bold.name:x,"bolditalic"):t.setFont(e.options.font.regular.name,h);const n=e.options.page.maxContentWidth-s-e.X,r=t.splitTextToSize(a,n);if(e.isInlineLockActive)for(let b=0;b<r.length;b++)t.text(r[b],e.X+s,e.Y,{baseline:"top",maxWidth:n}),e.updateX(t.getTextDimensions(r[b]).w+1,"add"),b<r.length-1&&(e.updateY(d(t),"add"),e.updateX(e.options.page.xpading+s,"set"));else if(r.length>1){const b=r[0],f=(u=r==null?void 0:r.slice(1))==null?void 0:u.join(" ");t.text(b,e.X+(s>=2?s+2*c(l):0),e.Y,{baseline:"top",maxWidth:n}),e.updateX(e.options.page.xpading+s),e.updateY(d(t),"add");const Y=e.options.page.maxContentWidth-s-e.options.page.xpading;t.splitTextToSize(f,Y).forEach(m=>{t.text(m,e.X+y(t),e.Y,{baseline:"top",maxWidth:Y})})}else t.text(a,e.X+s,e.Y,{baseline:"top",maxWidth:n}),e.updateX(t.getTextDimensions(a).w+(s>=2?a.split(" ").length+2:2)*c(l)*.5,"add")};if(i.type==="text"&&i.items&&i.items.length>0)for(const a of i.items)if(a.type==="em"||a.type==="strong"){const l=a.type==="em"?"italic":"bold";if(a.items&&a.items.length>0)for(const n of a.items)n.type==="strong"&&l==="italic"||n.type==="em"&&l==="bold"?g(n.content||"","bolditalic"):g(n.content||"",l);else g(a.content||"",l)}else g(a.content||"","normal");else i.type==="em"?g(i.content||"","italic"):i.type==="strong"?g(i.content||"","bold"):g(i.content||"","normal");t.setFont(x,h),t.setFontSize(p)},j=(t,i,s,x)=>{e.activateInlineLock(),t.setFontSize(e.options.page.defaultFontSize);let h=i.content;const p=t.getTextDimensions("A").h*e.options.page.defaultLineHeightFactor;if(i!=null&&i.items&&(i==null?void 0:i.items.length)>0){let c=0;for(const g of(i==null?void 0:i.items)??[])["strong","em","text"].includes(g.type)?(g.type!=="text"&&c!=0&&e.updateX(y(t)*1.5,"add"),S(t,g,s),g.type!=="text"&&c!=0&&e.updateX(y(t),"add")):x(g,s,!1),c++}else{if(e.Y+t.splitTextToSize(h??"",e.options.page.maxContentWidth-s).length*p-3*p>=e.options.page.maxContentHeight){const g=t.splitTextToSize(h??"",e.options.page.maxContentWidth-s),a=[],l=e.Y;for(let n=0;n<g.length;n++)if(e.Y-2*p<e.options.page.maxContentHeight)a.push(g[n]),e.updateY(e.options.page.lineSpace,"add");else{n<=g.length-1&&(h=g.slice(n).join(""));break}if(a.length>0){const n=F(t,a.join(" "),e.X+s,l,e.options.page.maxContentWidth-s,e.options.page.defaultLineHeightFactor);e.setCursor(n)}C(t)}const c=F(t,h??"",e.X+s,e.Y,e.options.page.maxContentWidth-s,e.options.page.defaultLineHeightFactor).y+d(t);e.updateY(c)}e.updateY(p,"add"),e.updateX(e.options.page.xpading),e.deactivateInlineLock()},v=(t,i,s,x)=>{var h;t.setFontSize(e.options.page.defaultFontSize);for(const[p,c]of((h=i==null?void 0:i.items)==null?void 0:h.entries())??[]){const g=i.ordered?(i.start??0)+p:i.start;x(c,s+1,!0,g,i.ordered)}},A=(t,i,s,x,h,p)=>{const c=s*e.options.page.indent,g=p?`${h}. `:"• ";e.Y+d(t)>=e.options.page.maxContentHeight&&C(t),t.setFont(e.options.font.regular.name,e.options.font.regular.style),t.text(g,e.X+c,e.Y,{baseline:"top"});const a=t.getTextWidth(g);if(e.updateX(a,"add"),i.items&&i.items.length>0)for(const l of i.items){if(e.Y+d(t)>=e.options.page.maxContentHeight&&C(t),l.type===o.List)x(l,s+1,!0,h,l.ordered??!1);else if(l.type===o.ListItem){const n=i.type===o.List?s:s+1;x(l,n,!0,h,p)}else S(t,l,c);e.updateX(e.options.page.xpading),e.updateY(d(t),"add")}else if(i.content){const l=e.X+c,n=t.getTextWidth(g),r=e.options.page.maxContentWidth-c-n,u=t.splitTextToSize(i.content,r);if(u.length>0){t.text(u[0],l+n,e.Y,{baseline:"top",maxWidth:r});for(let f=1;f<u.length;f++)e.updateY(d(t),"add"),t.text(u[f],l+n,e.Y,{baseline:"top",maxWidth:r});e.updateX(e.options.page.xmargin+c),e.updateY(d(t),"add");const b=t.getTextWidth(i.content);e.updateX(b,"add")}}},R=(t,i,s,x,h,p,c,g=!0)=>{if(i!=null&&i.items&&(i==null?void 0:i.items.length)>0)for(const a of(i==null?void 0:i.items)??[])h(a,s,x,p,c,g);else{const a=s*e.options.page.indent,l=x?c?`${p}. `:"• ":"";if(x&&l){const n=t.getTextWidth(l),r=e.options.page.maxContentWidth-a-n,u=t.splitTextToSize(i.content||"",r);if(u.length>0){t.text(l,e.X+a,e.Y,{baseline:"top"}),t.text(u[0],e.X+a+n,e.Y,{baseline:"top",maxWidth:r});for(let f=1;f<u.length;f++)e.updateX(e.options.page.xpading),e.updateY(d(t),"add"),t.text(u[f],e.X+a+n,e.Y,{baseline:"top",maxWidth:r-a-n});e.updateY(d(t),"add"),e.updateX(e.options.page.xpading+a);const b=t.getTextWidth(i.content||"");e.updateX(b,"add")}}else{const n=t.splitTextToSize(i.content||"",e.options.page.maxContentWidth-a);if(e.Y+n.length*d(t)>=e.options.page.maxContentHeight&&C(t),g){const r=F(t,i.content||"",e.X+a,e.Y,e.options.page.maxContentWidth-a,e.options.page.defaultLineHeightFactor).y+d(t)*.5;e.updateY(r),e.updateX(e.options.page.xpading)}else t.text(n||"",e.X+a,e.Y,{baseline:"top"}),e.updateX(t.getTextWidth(i.content||""),"add"),e.X>=e.options.page.xpading+e.options.page.maxContentWidth&&C(t)}}},B=t=>{const i=t.internal.pageSize.getWidth();t.setLineDashPattern([1,1],0),t.setLineWidth(.1),t.line(e.options.page.xpading,e.Y,i-e.options.page.xpading,e.Y),t.setLineWidth(.1),t.setLineDashPattern([],0),e.updateY(d(t),"add")},_=(t,i,s,x)=>{const h=s*e.options.page.indent;e.Y+t.splitTextToSize(i.code??"",e.options.page.maxContentWidth-h).length*d(t)-2*d(t)>=e.options.page.maxContentHeight&&C(t);const p=t.splitTextToSize(i.code??"",e.options.page.maxContentWidth-h).length*d(t);e.updateY(e.options.page.lineSpace,"add"),t.setFillColor("#EEEEEE"),t.setDrawColor("#eee"),t.roundedRect(e.X,e.Y-e.options.page.lineSpace,e.options.page.maxContentWidth,p,2,2,"FD"),t.setFontSize(10),t.text(i.lang??"",e.X+e.options.page.maxContentWidth-t.getTextWidth(i.lang??"")-e.options.page.lineSpace/2,e.Y),t.setFontSize(e.options.page.defaultFontSize),t.text(i.code??"",e.X+4,e.Y),e.updateY(p,"add")},q=(t,i,s)=>{var u,b;const x=t.getFont().fontName,h=t.getFont().fontStyle,p=t.getFontSize(),c=t.getTextColor(),g=((u=e.options.link)==null?void 0:u.linkColor)||[0,0,255];t.setTextColor(...g);const a=e.options.page.maxContentWidth-s-e.X,l=i.text||i.content||"",n=i.href||"",r=t.splitTextToSize(l,a);if(e.isInlineLockActive)for(let f=0;f<r.length;f++){const Y=t.getTextDimensions(r[f]).w,X=d(t)/2;t.link(e.X+s,e.Y,Y,X,{url:n}),t.text(r[f],e.X+s,e.Y,{baseline:"top",maxWidth:a}),e.updateX(Y+1,"add"),e.X+Y>e.options.page.maxContentWidth-s&&(e.updateY(X,"add"),e.updateX(e.options.page.xpading+s,"set")),f<r.length-1&&(e.updateY(X,"add"),e.updateX(e.options.page.xpading+s,"set"))}else if(r.length>1){const f=r[0],Y=(b=r==null?void 0:r.slice(1))==null?void 0:b.join(" "),X=t.getTextDimensions(f).w,m=d(t)/2;t.link(e.X+s,e.Y,X,m,{url:n}),t.text(f,e.X+s,e.Y,{baseline:"top",maxWidth:a}),e.updateX(e.options.page.xpading+s),e.updateY(m,"add");const H=e.options.page.maxContentWidth-s-e.options.page.xpading;t.splitTextToSize(Y,H).forEach(T=>{const w=t.getTextDimensions(T).w;t.link(e.X+y(t),e.Y,w,m,{url:n}),t.text(T,e.X+y(t),e.Y,{baseline:"top",maxWidth:H})})}else{const f=t.getTextDimensions(l).w,Y=d(t)/2;t.link(e.X+s,e.Y,f,Y,{url:n}),t.text(l,e.X+s,e.Y,{baseline:"top",maxWidth:a}),e.updateX(f+2,"add")}t.setFont(x,h),t.setFontSize(p),t.setTextColor(c)},J=async(t,i,s)=>{e.initialize(s);const x=await z(i),h=(p,c=0,g=!1,a=0,l=!1,n=!0)=>{const r=c*s.page.indent;switch(e.Y+t.splitTextToSize(p.content??"",s.page.maxContentWidth-r).length*d(t)>=s.page.maxContentHeight&&C(t),p.type){case o.Heading:E(t,p,r,h);break;case o.Paragraph:j(t,p,r,h);break;case o.List:v(t,p,c,h);break;case o.ListItem:A(t,p,c,h,a,l);break;case o.Hr:B(t);break;case o.Code:_(t,p,c);break;case o.Strong:case o.Em:S(t,p,r);break;case o.Link:q(t,p,r);break;case o.Raw:case o.Text:R(t,p,c,g,h,a,l,n);break;default:console.warn(`Warning: Unsupported element type encountered: ${p.type}.
|
|
2
2
|
If you believe this element type should be supported, please create an issue at:
|
|
3
3
|
https://github.com/JeelGajera/jspdf-md-renderer/issues
|
|
4
4
|
with details of the element and expected behavior. Thanks for helping to improve this library!`);break}};for(const p of x)h(p);s.endCursorYHandler(e.Y)};exports.MdTextParser=z;exports.MdTextRender=J;
|
package/dist/index.mjs
CHANGED
|
@@ -147,8 +147,8 @@ const C = (t) => {
|
|
|
147
147
|
var i, s;
|
|
148
148
|
typeof e.options.pageBreakHandler == "function" ? e.options.pageBreakHandler() : t.addPage((i = e.options.page) == null ? void 0 : i.format, (s = e.options.page) == null ? void 0 : s.orientation), e.updateY(e.options.page.topmargin), e.updateX(e.options.page.xpading);
|
|
149
149
|
}, d = (t) => t.getTextDimensions("H").h * e.options.page.defaultLineHeightFactor, L = (t) => t.getTextDimensions("H").w * e.options.page.defaultLineHeightFactor, E = (t, i, s, x) => {
|
|
150
|
-
const
|
|
151
|
-
if (t.setFontSize(e.options.page.defaultFontSize +
|
|
150
|
+
const l = 6 - ((i == null ? void 0 : i.depth) ?? 0) > 0 ? 6 - ((i == null ? void 0 : i.depth) ?? 0) : 1;
|
|
151
|
+
if (t.setFontSize(e.options.page.defaultFontSize + l), e.updateY(l * 0.2 * d(t), "add"), i != null && i.items && (i == null ? void 0 : i.items.length) > 0)
|
|
152
152
|
for (const p of (i == null ? void 0 : i.items) ?? [])
|
|
153
153
|
x(p, s, !1);
|
|
154
154
|
else
|
|
@@ -162,40 +162,40 @@ const C = (t) => {
|
|
|
162
162
|
}
|
|
163
163
|
);
|
|
164
164
|
t.setFontSize(e.options.page.defaultFontSize), e.updateX(e.options.page.xpading);
|
|
165
|
-
}, D = (t, i, s, x,
|
|
166
|
-
const
|
|
167
|
-
let n =
|
|
165
|
+
}, D = (t, i, s, x, l, p, c, g, a) => {
|
|
166
|
+
const h = (g - s) / (i.length - 1);
|
|
167
|
+
let n = l;
|
|
168
168
|
const r = p + x * c;
|
|
169
169
|
for (const u of i)
|
|
170
170
|
t.text(u.text, n, r, {
|
|
171
171
|
align: "justify",
|
|
172
172
|
lineHeightFactor: a,
|
|
173
173
|
maxWidth: g
|
|
174
|
-
}), n += u.wordLength +
|
|
175
|
-
}, P = (t, i, s, x,
|
|
176
|
-
const a = t.map((
|
|
177
|
-
i.text(a, s, x +
|
|
174
|
+
}), n += u.wordLength + h;
|
|
175
|
+
}, P = (t, i, s, x, l, p, c, g) => {
|
|
176
|
+
const a = t.map((h) => h.text).join(" ");
|
|
177
|
+
i.text(a, s, x + l * p, {
|
|
178
178
|
align: "justify",
|
|
179
179
|
lineHeightFactor: g,
|
|
180
180
|
maxWidth: c
|
|
181
181
|
});
|
|
182
|
-
}, F = (t, i, s, x,
|
|
182
|
+
}, F = (t, i, s, x, l, p) => {
|
|
183
183
|
const c = {
|
|
184
184
|
x: s,
|
|
185
185
|
y: x
|
|
186
186
|
}, g = t.getTextDimensions("A").h * p, a = i.split(" ");
|
|
187
|
-
let
|
|
187
|
+
let h = 0, n = [], r = 0;
|
|
188
188
|
for (const u of a) {
|
|
189
189
|
const b = t.getTextWidth(u + "a");
|
|
190
|
-
b + r >=
|
|
190
|
+
b + r >= l && (D(
|
|
191
191
|
t,
|
|
192
192
|
n,
|
|
193
193
|
r,
|
|
194
|
-
|
|
194
|
+
h++,
|
|
195
195
|
s,
|
|
196
196
|
x,
|
|
197
197
|
g,
|
|
198
|
-
|
|
198
|
+
l,
|
|
199
199
|
p
|
|
200
200
|
), n = [], r = 0), n.push({ text: u, wordLength: b }), r += b;
|
|
201
201
|
}
|
|
@@ -204,13 +204,13 @@ const C = (t) => {
|
|
|
204
204
|
t,
|
|
205
205
|
s,
|
|
206
206
|
x,
|
|
207
|
-
l,
|
|
208
|
-
g,
|
|
209
207
|
h,
|
|
208
|
+
g,
|
|
209
|
+
l,
|
|
210
210
|
p
|
|
211
|
-
), c.y = x +
|
|
211
|
+
), c.y = x + h * g, c.x = t.getTextWidth(i) + s, c;
|
|
212
212
|
}, H = (t, i, s) => {
|
|
213
|
-
const x = t.getFont().fontName,
|
|
213
|
+
const x = t.getFont().fontName, l = t.getFont().fontStyle, p = t.getFontSize(), c = (a) => {
|
|
214
214
|
switch (a) {
|
|
215
215
|
case "normal":
|
|
216
216
|
return 0;
|
|
@@ -223,17 +223,17 @@ const C = (t) => {
|
|
|
223
223
|
default:
|
|
224
224
|
return 0;
|
|
225
225
|
}
|
|
226
|
-
}, g = (a,
|
|
226
|
+
}, g = (a, h) => {
|
|
227
227
|
var u;
|
|
228
|
-
|
|
228
|
+
h === "bold" ? t.setFont(
|
|
229
229
|
e.options.font.bold.name && e.options.font.bold.name !== "" ? e.options.font.bold.name : x,
|
|
230
230
|
e.options.font.bold.style || "bold"
|
|
231
|
-
) :
|
|
231
|
+
) : h === "italic" ? t.setFont(e.options.font.regular.name, "italic") : h === "bolditalic" ? t.setFont(
|
|
232
232
|
e.options.font.bold.name && e.options.font.bold.name !== "" ? e.options.font.bold.name : x,
|
|
233
233
|
"bolditalic"
|
|
234
234
|
) : t.setFont(
|
|
235
235
|
e.options.font.regular.name,
|
|
236
|
-
|
|
236
|
+
l
|
|
237
237
|
);
|
|
238
238
|
const n = e.options.page.maxContentWidth - s - e.X, r = t.splitTextToSize(a, n);
|
|
239
239
|
if (e.isInlineLockActive)
|
|
@@ -254,7 +254,7 @@ const C = (t) => {
|
|
|
254
254
|
const b = r[0], f = (u = r == null ? void 0 : r.slice(1)) == null ? void 0 : u.join(" ");
|
|
255
255
|
t.text(
|
|
256
256
|
b,
|
|
257
|
-
e.X + (s >= 2 ? s + 2 * c(
|
|
257
|
+
e.X + (s >= 2 ? s + 2 * c(h) : 0),
|
|
258
258
|
e.Y,
|
|
259
259
|
{
|
|
260
260
|
baseline: "top",
|
|
@@ -273,32 +273,32 @@ const C = (t) => {
|
|
|
273
273
|
baseline: "top",
|
|
274
274
|
maxWidth: n
|
|
275
275
|
}), e.updateX(
|
|
276
|
-
t.getTextDimensions(a).w + (s >= 2 ? a.split(" ").length + 2 : 2) * c(
|
|
276
|
+
t.getTextDimensions(a).w + (s >= 2 ? a.split(" ").length + 2 : 2) * c(h) * 0.5,
|
|
277
277
|
"add"
|
|
278
278
|
);
|
|
279
279
|
};
|
|
280
280
|
if (i.type === "text" && i.items && i.items.length > 0)
|
|
281
281
|
for (const a of i.items)
|
|
282
282
|
if (a.type === "em" || a.type === "strong") {
|
|
283
|
-
const
|
|
283
|
+
const h = a.type === "em" ? "italic" : "bold";
|
|
284
284
|
if (a.items && a.items.length > 0)
|
|
285
285
|
for (const n of a.items)
|
|
286
|
-
n.type === "strong" &&
|
|
286
|
+
n.type === "strong" && h === "italic" || n.type === "em" && h === "bold" ? g(
|
|
287
287
|
n.content || "",
|
|
288
288
|
"bolditalic"
|
|
289
289
|
) : g(
|
|
290
290
|
n.content || "",
|
|
291
|
-
|
|
291
|
+
h
|
|
292
292
|
);
|
|
293
293
|
else
|
|
294
|
-
g(a.content || "",
|
|
294
|
+
g(a.content || "", h);
|
|
295
295
|
} else
|
|
296
296
|
g(a.content || "", "normal");
|
|
297
297
|
else i.type === "em" ? g(i.content || "", "italic") : i.type === "strong" ? g(i.content || "", "bold") : g(i.content || "", "normal");
|
|
298
|
-
t.setFont(x,
|
|
298
|
+
t.setFont(x, l), t.setFontSize(p);
|
|
299
299
|
}, j = (t, i, s, x) => {
|
|
300
300
|
e.activateInlineLock(), t.setFontSize(e.options.page.defaultFontSize);
|
|
301
|
-
let
|
|
301
|
+
let l = i.content;
|
|
302
302
|
const p = t.getTextDimensions("A").h * e.options.page.defaultLineHeightFactor;
|
|
303
303
|
if (i != null && i.items && (i == null ? void 0 : i.items.length) > 0) {
|
|
304
304
|
let c = 0;
|
|
@@ -306,13 +306,13 @@ const C = (t) => {
|
|
|
306
306
|
["strong", "em", "text"].includes(g.type) ? (g.type !== "text" && c != 0 && e.updateX(L(t) * 1.5, "add"), H(t, g, s), g.type !== "text" && c != 0 && e.updateX(L(t), "add")) : x(g, s, !1), c++;
|
|
307
307
|
} else {
|
|
308
308
|
if (e.Y + t.splitTextToSize(
|
|
309
|
-
|
|
309
|
+
l ?? "",
|
|
310
310
|
e.options.page.maxContentWidth - s
|
|
311
311
|
).length * p - 3 * p >= e.options.page.maxContentHeight) {
|
|
312
312
|
const g = t.splitTextToSize(
|
|
313
|
-
|
|
313
|
+
l ?? "",
|
|
314
314
|
e.options.page.maxContentWidth - s
|
|
315
|
-
), a = [],
|
|
315
|
+
), a = [], h = e.Y;
|
|
316
316
|
for (let n = 0; n < g.length; n++)
|
|
317
317
|
if (e.Y - 2 * p < e.options.page.maxContentHeight)
|
|
318
318
|
a.push(g[n]), e.updateY(
|
|
@@ -320,7 +320,7 @@ const C = (t) => {
|
|
|
320
320
|
"add"
|
|
321
321
|
);
|
|
322
322
|
else {
|
|
323
|
-
n <= g.length - 1 && (
|
|
323
|
+
n <= g.length - 1 && (l = g.slice(n).join(""));
|
|
324
324
|
break;
|
|
325
325
|
}
|
|
326
326
|
if (a.length > 0) {
|
|
@@ -328,7 +328,7 @@ const C = (t) => {
|
|
|
328
328
|
t,
|
|
329
329
|
a.join(" "),
|
|
330
330
|
e.X + s,
|
|
331
|
-
|
|
331
|
+
h,
|
|
332
332
|
e.options.page.maxContentWidth - s,
|
|
333
333
|
e.options.page.defaultLineHeightFactor
|
|
334
334
|
);
|
|
@@ -338,7 +338,7 @@ const C = (t) => {
|
|
|
338
338
|
}
|
|
339
339
|
const c = F(
|
|
340
340
|
t,
|
|
341
|
-
|
|
341
|
+
l ?? "",
|
|
342
342
|
e.X + s,
|
|
343
343
|
e.Y,
|
|
344
344
|
e.options.page.maxContentWidth - s,
|
|
@@ -348,9 +348,9 @@ const C = (t) => {
|
|
|
348
348
|
}
|
|
349
349
|
e.updateY(p, "add"), e.updateX(e.options.page.xpading), e.deactivateInlineLock();
|
|
350
350
|
}, v = (t, i, s, x) => {
|
|
351
|
-
var
|
|
351
|
+
var l;
|
|
352
352
|
t.setFontSize(e.options.page.defaultFontSize);
|
|
353
|
-
for (const [p, c] of ((
|
|
353
|
+
for (const [p, c] of ((l = i == null ? void 0 : i.items) == null ? void 0 : l.entries()) ?? []) {
|
|
354
354
|
const g = i.ordered ? (i.start ?? 0) + p : i.start;
|
|
355
355
|
x(
|
|
356
356
|
c,
|
|
@@ -360,8 +360,8 @@ const C = (t) => {
|
|
|
360
360
|
i.ordered
|
|
361
361
|
);
|
|
362
362
|
}
|
|
363
|
-
}, A = (t, i, s, x,
|
|
364
|
-
const c = s * e.options.page.indent, g = p ? `${
|
|
363
|
+
}, A = (t, i, s, x, l, p) => {
|
|
364
|
+
const c = s * e.options.page.indent, g = p ? `${l}. ` : "• ";
|
|
365
365
|
e.Y + d(t) >= e.options.page.maxContentHeight && C(t), t.setFont(
|
|
366
366
|
e.options.font.regular.name,
|
|
367
367
|
e.options.font.regular.style
|
|
@@ -370,37 +370,37 @@ const C = (t) => {
|
|
|
370
370
|
});
|
|
371
371
|
const a = t.getTextWidth(g);
|
|
372
372
|
if (e.updateX(a, "add"), i.items && i.items.length > 0)
|
|
373
|
-
for (const
|
|
374
|
-
if (e.Y + d(t) >= e.options.page.maxContentHeight && C(t),
|
|
373
|
+
for (const h of i.items) {
|
|
374
|
+
if (e.Y + d(t) >= e.options.page.maxContentHeight && C(t), h.type === o.List)
|
|
375
375
|
x(
|
|
376
|
-
|
|
376
|
+
h,
|
|
377
377
|
s + 1,
|
|
378
378
|
!0,
|
|
379
|
-
|
|
380
|
-
|
|
379
|
+
l,
|
|
380
|
+
h.ordered ?? !1
|
|
381
381
|
);
|
|
382
|
-
else if (
|
|
382
|
+
else if (h.type === o.ListItem) {
|
|
383
383
|
const n = i.type === o.List ? s : s + 1;
|
|
384
384
|
x(
|
|
385
|
-
|
|
385
|
+
h,
|
|
386
386
|
n,
|
|
387
387
|
!0,
|
|
388
|
-
|
|
388
|
+
l,
|
|
389
389
|
p
|
|
390
390
|
);
|
|
391
391
|
} else
|
|
392
|
-
H(t,
|
|
392
|
+
H(t, h, c);
|
|
393
393
|
e.updateX(e.options.page.xpading), e.updateY(d(t), "add");
|
|
394
394
|
}
|
|
395
395
|
else if (i.content) {
|
|
396
|
-
const
|
|
396
|
+
const h = e.X + c, n = t.getTextWidth(g), r = e.options.page.maxContentWidth - c - n, u = t.splitTextToSize(i.content, r);
|
|
397
397
|
if (u.length > 0) {
|
|
398
|
-
t.text(u[0],
|
|
398
|
+
t.text(u[0], h + n, e.Y, {
|
|
399
399
|
baseline: "top",
|
|
400
400
|
maxWidth: r
|
|
401
401
|
});
|
|
402
402
|
for (let f = 1; f < u.length; f++)
|
|
403
|
-
e.updateY(d(t), "add"), t.text(u[f],
|
|
403
|
+
e.updateY(d(t), "add"), t.text(u[f], h + n, e.Y, {
|
|
404
404
|
baseline: "top",
|
|
405
405
|
maxWidth: r
|
|
406
406
|
});
|
|
@@ -409,10 +409,10 @@ const C = (t) => {
|
|
|
409
409
|
e.updateX(b, "add");
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
}, B = (t, i, s, x,
|
|
412
|
+
}, B = (t, i, s, x, l, p, c, g = !0) => {
|
|
413
413
|
if (i != null && i.items && (i == null ? void 0 : i.items.length) > 0)
|
|
414
414
|
for (const a of (i == null ? void 0 : i.items) ?? [])
|
|
415
|
-
|
|
415
|
+
l(
|
|
416
416
|
a,
|
|
417
417
|
s,
|
|
418
418
|
x,
|
|
@@ -421,14 +421,14 @@ const C = (t) => {
|
|
|
421
421
|
g
|
|
422
422
|
);
|
|
423
423
|
else {
|
|
424
|
-
const a = s * e.options.page.indent,
|
|
425
|
-
if (x &&
|
|
426
|
-
const n = t.getTextWidth(
|
|
424
|
+
const a = s * e.options.page.indent, h = x ? c ? `${p}. ` : "• " : "";
|
|
425
|
+
if (x && h) {
|
|
426
|
+
const n = t.getTextWidth(h), r = e.options.page.maxContentWidth - a - n, u = t.splitTextToSize(
|
|
427
427
|
i.content || "",
|
|
428
428
|
r
|
|
429
429
|
);
|
|
430
430
|
if (u.length > 0) {
|
|
431
|
-
t.text(
|
|
431
|
+
t.text(h, e.X + a, e.Y, {
|
|
432
432
|
baseline: "top"
|
|
433
433
|
}), t.text(
|
|
434
434
|
u[0],
|
|
@@ -497,14 +497,14 @@ const C = (t) => {
|
|
|
497
497
|
e.Y
|
|
498
498
|
), t.setLineWidth(0.1), t.setLineDashPattern([], 0), e.updateY(d(t), "add");
|
|
499
499
|
}, _ = (t, i, s, x) => {
|
|
500
|
-
const
|
|
500
|
+
const l = s * e.options.page.indent;
|
|
501
501
|
e.Y + t.splitTextToSize(
|
|
502
502
|
i.code ?? "",
|
|
503
|
-
e.options.page.maxContentWidth -
|
|
503
|
+
e.options.page.maxContentWidth - l
|
|
504
504
|
).length * d(t) - 2 * d(t) >= e.options.page.maxContentHeight && C(t);
|
|
505
505
|
const p = t.splitTextToSize(
|
|
506
506
|
i.code ?? "",
|
|
507
|
-
e.options.page.maxContentWidth -
|
|
507
|
+
e.options.page.maxContentWidth - l
|
|
508
508
|
).length * d(t);
|
|
509
509
|
e.updateY(e.options.page.lineSpace, "add"), t.setFillColor("#EEEEEE"), t.setDrawColor("#eee"), t.roundedRect(
|
|
510
510
|
e.X,
|
|
@@ -521,9 +521,9 @@ const C = (t) => {
|
|
|
521
521
|
), t.setFontSize(e.options.page.defaultFontSize), t.text(i.code ?? "", e.X + 4, e.Y), e.updateY(p, "add");
|
|
522
522
|
}, J = (t, i, s) => {
|
|
523
523
|
var u, b;
|
|
524
|
-
const x = t.getFont().fontName,
|
|
524
|
+
const x = t.getFont().fontName, l = t.getFont().fontStyle, p = t.getFontSize(), c = t.getTextColor(), g = ((u = e.options.link) == null ? void 0 : u.linkColor) || [0, 0, 255];
|
|
525
525
|
t.setTextColor(...g);
|
|
526
|
-
const a = e.options.page.maxContentWidth - s - e.X,
|
|
526
|
+
const a = e.options.page.maxContentWidth - s - e.X, h = i.text || i.content || "", n = i.href || "", r = t.splitTextToSize(h, a);
|
|
527
527
|
if (e.isInlineLockActive)
|
|
528
528
|
for (let f = 0; f < r.length; f++) {
|
|
529
529
|
const Y = t.getTextDimensions(r[f]).w, X = d(t) / 2;
|
|
@@ -589,7 +589,7 @@ const C = (t) => {
|
|
|
589
589
|
);
|
|
590
590
|
});
|
|
591
591
|
} else {
|
|
592
|
-
const f = t.getTextDimensions(
|
|
592
|
+
const f = t.getTextDimensions(h).w, Y = d(t) / 2;
|
|
593
593
|
t.link(
|
|
594
594
|
e.X + s,
|
|
595
595
|
e.Y,
|
|
@@ -597,7 +597,7 @@ const C = (t) => {
|
|
|
597
597
|
Y,
|
|
598
598
|
{ url: n }
|
|
599
599
|
), t.text(
|
|
600
|
-
|
|
600
|
+
h,
|
|
601
601
|
e.X + s,
|
|
602
602
|
e.Y,
|
|
603
603
|
{
|
|
@@ -606,34 +606,32 @@ const C = (t) => {
|
|
|
606
606
|
}
|
|
607
607
|
), e.updateX(f + 2, "add");
|
|
608
608
|
}
|
|
609
|
-
t.setFont(x,
|
|
609
|
+
t.setFont(x, l), t.setFontSize(p), t.setTextColor(c);
|
|
610
610
|
}, q = async (t, i, s) => {
|
|
611
611
|
e.initialize(s);
|
|
612
|
-
const x = await I(i)
|
|
613
|
-
console.log(x);
|
|
614
|
-
const h = (p, c = 0, g = !1, a = 0, l = !1, n = !0) => {
|
|
612
|
+
const x = await I(i), l = (p, c = 0, g = !1, a = 0, h = !1, n = !0) => {
|
|
615
613
|
const r = c * s.page.indent;
|
|
616
614
|
switch (e.Y + t.splitTextToSize(
|
|
617
615
|
p.content ?? "",
|
|
618
616
|
s.page.maxContentWidth - r
|
|
619
617
|
).length * d(t) >= s.page.maxContentHeight && C(t), p.type) {
|
|
620
618
|
case o.Heading:
|
|
621
|
-
E(t, p, r,
|
|
619
|
+
E(t, p, r, l);
|
|
622
620
|
break;
|
|
623
621
|
case o.Paragraph:
|
|
624
|
-
j(t, p, r,
|
|
622
|
+
j(t, p, r, l);
|
|
625
623
|
break;
|
|
626
624
|
case o.List:
|
|
627
|
-
v(t, p, c,
|
|
625
|
+
v(t, p, c, l);
|
|
628
626
|
break;
|
|
629
627
|
case o.ListItem:
|
|
630
628
|
A(
|
|
631
629
|
t,
|
|
632
630
|
p,
|
|
633
631
|
c,
|
|
634
|
-
|
|
632
|
+
l,
|
|
635
633
|
a,
|
|
636
|
-
|
|
634
|
+
h
|
|
637
635
|
);
|
|
638
636
|
break;
|
|
639
637
|
case o.Hr:
|
|
@@ -656,9 +654,9 @@ const C = (t) => {
|
|
|
656
654
|
p,
|
|
657
655
|
c,
|
|
658
656
|
g,
|
|
659
|
-
h,
|
|
660
|
-
a,
|
|
661
657
|
l,
|
|
658
|
+
a,
|
|
659
|
+
h,
|
|
662
660
|
n
|
|
663
661
|
);
|
|
664
662
|
break;
|
|
@@ -673,7 +671,7 @@ const C = (t) => {
|
|
|
673
671
|
}
|
|
674
672
|
};
|
|
675
673
|
for (const p of x)
|
|
676
|
-
|
|
674
|
+
l(p);
|
|
677
675
|
s.endCursorYHandler(e.Y);
|
|
678
676
|
};
|
|
679
677
|
export {
|