@knoopx/react-pdf
Version:
<p align="center"> <img src="https://user-images.githubusercontent.com/5600341/27505816-c8bc37aa-587f-11e7-9a86-08a2d081a8b9.png" height="280px"> <p align="center">React renderer for creating PDF files on the browser and server<p> <p align="center">
1 lines • 57.3 kB
JavaScript
import t from"fs";import e from"blob-stream";import i from"react-reconciler";import r,{PDFFont as o}from"@react-pdf/pdfkit";import{Fragment as s}from"react";import n from"yoga-layout-prebuilt";import{mergeDeepWith as a,isNil as h,compose as l,equals as d,type as c,toPairsIn as u,pick as p,pathOr as g,last as f,propEq as m,complement as y,prop as b}from"ramda";import T from"media-engine";import w from"@react-pdf/textkit/renderers/pdf";import C from"@react-pdf/textkit/attributedString";import E from"is-url";import v from"@react-pdf/fontkit";import R from"cross-fetch";import x from"@react-pdf/textkit/layout";import P from"@react-pdf/textkit/engines/linebreaker";import S from"@react-pdf/textkit/engines/justification";import A from"@react-pdf/textkit/engines/textDecoration";import L from"@react-pdf/textkit/engines/scriptItemizer";import B from"@react-pdf/textkit/engines/wordHyphenation";import O from"emoji-regex";import M from"url";import D from"path";import W from"@react-pdf/png-js";import _ from"page-wrapping";const I=t=>t.charAt(0).toUpperCase()+t.slice(1),k=t=>{const e=(t=>/((-)?\d+\.?\d*)%/g.exec(t))(t);if(e){const t=parseFloat(e[1],10),i=t/100;return{value:t,percent:i,absValue:Math.abs(t),absPercent:Math.abs(i)}}return null};class z{constructor(){this.parent=null,this.children=[],this.computed=!1,this.layout=n.Node.createDefault()}appendChild(t){t&&(t.parent=this,this.children.push(t),this.layout.insertChild(t.layout,this.layout.getChildCount()))}appendChildBefore(t,e){const i=this.children.indexOf(e);-1!==i&&t&&(t.parent=this,this.children.splice(i,0,t),this.layout.insertChild(t.layout,i))}removeChild(t){const e=this.children.indexOf(t);-1!==e&&(t.parent=null,this.children.splice(e,1),this.layout.removeChild(t.layout)),t.cleanup()}removeAllChilds(){const t=[...this.children];for(let e=0;e<t.length;e++)t[e].remove()}remove(){this.parent.removeChild(this)}setDimension(t,e){const i=`set${I(t)}`,r=`${i}Percent`,o=k(e);o?this.layout[r](o.value):this.layout[i](e)}setPosition(t,e){const i=k(e);i?this.layout.setPositionPercent(t,i.value):this.layout.setPosition(t,e)}setPadding(t,e){const i=k(e);i?this.layout.setPaddingPercent(t,i.value):this.layout.setPadding(t,e)}setMargin(t,e){const i=k(e);i?this.layout.setMarginPercent(t,i.value):this.layout.setMargin(t,e)}setBorder(t,e){if(k(e))throw new Error("Node: You cannot set percentage border widths");this.layout.setBorder(t,e)}getAbsoluteLayout(){const t=this.parent,e=t&&t.getAbsoluteLayout?t.getAbsoluteLayout():{left:0,top:0};return{left:this.left+e.left,top:this.top+e.top,height:this.height,width:this.width}}copyStyle(t){this.layout.copyStyle(t.layout)}calculateLayout(){this.layout.calculateLayout(),this.computed=!0}isEmpty(){return 0===this.children.length}markDirty(){return this.layout.markDirty()}onAppendDynamically(){}cleanup(){this.children.forEach(t=>t.cleanup()),this.layout.unsetMeasureFunc(),n.Node.destroy(this.layout)}get position(){return this.layout.getPositionType()===n.POSITION_TYPE_ABSOLUTE?"absolute":"relative"}get top(){return this.layout.getComputedTop()||0}get left(){return this.layout.getComputedLeft()||0}get right(){return this.layout.getComputedRight()||0}get bottom(){return this.layout.getComputedBottom()||0}get width(){return this.layout.getComputedWidth()}get minWidth(){return this.layout.getMinWidth().value}get maxWidth(){return this.layout.getMaxWidth().value}get height(){return this.layout.getComputedHeight()}get minHeight(){return this.layout.getMinHeight().value}get maxHeight(){return this.layout.getMaxHeight().value}get paddingTop(){return this.layout.getComputedPadding(n.EDGE_TOP)||0}get paddingRight(){return this.layout.getComputedPadding(n.EDGE_RIGHT)||0}get paddingBottom(){return this.layout.getComputedPadding(n.EDGE_BOTTOM)||0}get paddingLeft(){return this.layout.getComputedPadding(n.EDGE_LEFT)||0}get marginTop(){return this.layout.getComputedMargin(n.EDGE_TOP)||0}get marginRight(){return this.layout.getComputedMargin(n.EDGE_RIGHT)||0}get marginBottom(){return this.layout.getComputedMargin(n.EDGE_BOTTOM)||0}get marginLeft(){return this.layout.getComputedMargin(n.EDGE_LEFT)||0}get borderTopWidth(){return this.layout.getComputedBorder(n.EDGE_TOP)||0}get borderRightWidth(){return this.layout.getComputedBorder(n.EDGE_RIGHT)||0}get borderBottomWidth(){return this.layout.getComputedBorder(n.EDGE_BOTTOM)||0}get borderLeftWidth(){return this.layout.getComputedBorder(n.EDGE_LEFT)||0}get padding(){return{top:this.paddingTop,right:this.paddingRight,bottom:this.paddingBottom,left:this.paddingLeft}}get margin(){return{top:this.marginTop,right:this.marginRight,bottom:this.marginBottom,left:this.marginLeft}}set position(t){this.layout.setPositionType("absolute"===t?n.POSITION_TYPE_ABSOLUTE:n.POSITION_TYPE_RELATIVE)}set top(t){this.setPosition(n.EDGE_TOP,t)}set left(t){this.setPosition(n.EDGE_LEFT,t)}set right(t){this.setPosition(n.EDGE_RIGHT,t)}set bottom(t){this.setPosition(n.EDGE_BOTTOM,t)}set width(t){this.setDimension("width",t)}set minWidth(t){this.setDimension("minWidth",t)}set maxWidth(t){this.setDimension("maxWidth",t)}set height(t){this.setDimension("height",t)}set minHeight(t){this.setDimension("minHeight",t)}set maxHeight(t){this.setDimension("maxHeight",t)}set paddingTop(t){this.setPadding(n.EDGE_TOP,t)}set paddingRight(t){this.setPadding(n.EDGE_RIGHT,t)}set paddingBottom(t){this.setPadding(n.EDGE_BOTTOM,t)}set paddingLeft(t){this.setPadding(n.EDGE_LEFT,t)}set marginTop(t){this.setMargin(n.EDGE_TOP,t)}set marginRight(t){this.setMargin(n.EDGE_RIGHT,t)}set marginBottom(t){this.setMargin(n.EDGE_BOTTOM,t)}set marginLeft(t){this.setMargin(n.EDGE_LEFT,t)}set padding(t){this.paddingTop=t,this.paddingRight=t,this.paddingBottom=t,this.paddingLeft=t}set margin(t){this.marginTop=t,this.marginRight=t,this.marginBottom=t,this.marginLeft=t}set borderTopWidth(t){this.setBorder(n.EDGE_TOP,t)}set borderRightWidth(t){this.setBorder(n.EDGE_RIGHT,t)}set borderBottomWidth(t){this.setBorder(n.EDGE_BOTTOM,t)}set borderLeftWidth(t){this.setBorder(n.EDGE_LEFT,t)}}const F=(t,e)=>{const i=t=>"alignItems"===t||"alignContent"===t||"alignSelf"===t;switch(e){case"auto":if("alignSelf"===t)return n.ALIGN_AUTO;break;case"flex":return n.DISPLAY_FLEX;case"none":return n.DISPLAY_NONE;case"row":return n.FLEX_DIRECTION_ROW;case"row-reverse":return n.FLEX_DIRECTION_ROW_REVERSE;case"column":return n.FLEX_DIRECTION_COLUMN;case"column-reverse":return n.FLEX_DIRECTION_COLUMN_REVERSE;case"stretch":return n.ALIGN_STRETCH;case"baseline":return n.ALIGN_BASELINE;case"space-around":if("justifyContent"===t)return n.JUSTIFY_SPACE_AROUND;if(i(t))return n.ALIGN_SPACE_AROUND;break;case"space-between":if("justifyContent"===t)return n.JUSTIFY_SPACE_BETWEEN;if(i(t))return n.ALIGN_SPACE_BETWEEN;break;case"around":return n.JUSTIFY_SPACE_AROUND;case"between":return n.JUSTIFY_SPACE_BETWEEN;case"wrap":return n.WRAP_WRAP;case"wrap-reverse":return n.WRAP_WRAP_REVERSE;case"nowrap":return n.WRAP_NO_WRAP;case"flex-start":if("justifyContent"===t)return n.JUSTIFY_FLEX_START;if(i(t))return n.ALIGN_FLEX_START;break;case"flex-end":if("justifyContent"===t)return n.JUSTIFY_FLEX_END;if(i(t))return n.ALIGN_FLEX_END;break;case"center":if("justifyContent"===t)return n.JUSTIFY_CENTER;if(i(t))return n.ALIGN_CENTER;break;default:return e}},N=(t,e)=>{const i=(t=>{const e=/^(-?\d*\.?\d+)(in|mm|cm|pt|vh|vw)?$/g.exec(t);return e?{value:parseFloat(e[1],10),unit:e[2]||"pt"}:{value:t,unit:void 0}})(t);switch(i.unit){case"in":return 72*i.value;case"mm":return i.value*(1/25.4)*72;case"cm":return i.value*(1/2.54)*72;case"vh":if(e.isAutoHeight)throw new Error("vh unit not supported in auto-height pages. Please specify page height if you want to use vh.");return i.value*(e.height/100);case"vw":return i.value*(e.width/100);default:return i.value}},G=(t,e)=>t.match(/^border/)&&"string"==typeof e,H=(t,e)=>{const i=(t=>t.match(/(\d+(px|in|mm|cm|pt|vw|vh)?)\s(\S+)\s(\S+)/))(e);if(i){if(t.match(/.Color/))return i[4];if(t.match(/.Style/))return i[3];if(t.match(/.Width/))return i[1];throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`)}return e},j=(t,e)=>t.match(/^(margin)|(padding)/)&&"string"==typeof e,U=(t,e)=>{const i=(t=>t.match(/\d+(px|in|mm|cm|pt|%|vw|vh)?/g))(e);if(i){if(t.match(/.Top/))return i[0];if(t.match(/.Right/))return i[1]||i[0];if(t.match(/.Bottom/))return i[2]||i[0];if(t.match(/.Left/))return i[3]||i[1]||i[0];throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`)}return e},V={thin:100,hairline:100,ultralight:200,extralight:200,light:300,normal:400,medium:500,semibold:600,demibold:600,bold:700,ultrabold:800,extrabold:800,heavy:900,black:900},X=t=>t.match(/^fontWeight/),$=t=>t?"number"==typeof t?t:V[t.toLowerCase()]:V.normal,Y=(t,e)=>t.match(/^objectPosition/)&&"string"==typeof e,J=(t,e)=>{const i=(t=>t.match(/\d+(px|in|mm|cm|pt|%|vw|vh)?/g))(e);if(i){if(t.match(/.X/))return i[0];if(t.match(/.Y/))return i[1];throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`)}return e},q=(t,e)=>t.match(/^transformOrigin/)&&"string"==typeof e,K=(t,e)=>{const i=(t=>t.match(/(-?\d+(px|in|mm|cm|pt|%|vw|vh)?)|top|right|bottom|left|center/g))(e);if(i){let r;if(t.match(/.X/))r=i[0];else{if(!t.match(/.Y/))throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`);r=i[1]||i[0]}return(t=>{switch(t){case"top":case"left":return"0%";case"right":case"bottom":return"100%";case"center":return"50%";default:return t}})(r)}return e},Z=Object.prototype.hasOwnProperty,Q={margin:{marginTop:!0,marginRight:!0,marginBottom:!0,marginLeft:!0},marginHorizontal:{marginLeft:!0,marginRight:!0},marginVertical:{marginTop:!0,marginBottom:!0},padding:{paddingTop:!0,paddingRight:!0,paddingBottom:!0,paddingLeft:!0},paddingHorizontal:{paddingLeft:!0,paddingRight:!0},paddingVertical:{paddingTop:!0,paddingBottom:!0},border:{borderTopColor:!0,borderTopStyle:!0,borderTopWidth:!0,borderRightColor:!0,borderRightStyle:!0,borderRightWidth:!0,borderBottomColor:!0,borderBottomStyle:!0,borderBottomWidth:!0,borderLeftColor:!0,borderLeftStyle:!0,borderLeftWidth:!0},borderTop:{borderTopColor:!0,borderTopStyle:!0,borderTopWidth:!0},borderRight:{borderRightColor:!0,borderRightStyle:!0,borderRightWidth:!0},borderBottom:{borderBottomColor:!0,borderBottomStyle:!0,borderBottomWidth:!0},borderLeft:{borderLeftColor:!0,borderLeftStyle:!0,borderLeftWidth:!0},borderColor:{borderTopColor:!0,borderRightColor:!0,borderBottomColor:!0,borderLeftColor:!0},borderRadius:{borderTopLeftRadius:!0,borderTopRightRadius:!0,borderBottomRightRadius:!0,borderBottomLeftRadius:!0},borderStyle:{borderTopStyle:!0,borderRightStyle:!0,borderBottomStyle:!0,borderLeftStyle:!0},borderWidth:{borderTopWidth:!0,borderRightWidth:!0,borderBottomWidth:!0,borderLeftWidth:!0},objectPosition:{objectPositionX:!0,objectPositionY:!0},transformOrigin:{transformOriginX:!0,transformOriginY:!0}},tt=(t,e)=>{const i=(t=>{if(!t)return t;const e=Object.keys(t),i={};for(let r=0;r<e.length;r++){const o=e[r],s=t[o];switch(o){case"display":case"flex":case"flexDirection":case"flexWrap":case"flexFlow":case"flexGrow":case"flexShrink":case"flexBasis":case"justifyContent":case"alignSelf":case"alignItems":case"alignContent":case"order":i[o]=F(o,s);break;case"textAlignVertical":i.verticalAlign="center"===s?"middle":s;break;case"margin":case"marginHorizontal":case"marginVertical":case"padding":case"paddingHorizontal":case"paddingVertical":case"border":case"borderTop":case"borderRight":case"borderBottom":case"borderLeft":case"borderColor":case"borderRadius":case"borderStyle":case"borderWidth":case"objectPosition":case"transformOrigin":{const t=Q[o];for(const e in t)Z.call(t,e)&&(i[e]=s)}break;default:i[o]=s}}return i})(t),r=Object.keys(i),o={};for(let t=0;t<r.length;t++){const s=r[t],n=i[s];let a;a=G(s,n)?H(s,n):j(s,n)?U(s,n):Y(s,n)?J(s,n):q(s,n)?K(s,n):X(s)?$(n):n,o[s]=N(a,e)}return o},et=t=>{return Array.isArray(t)||(t=[t]),t.reduce((t,e)=>{if(e){const i=Array.isArray(e)?et(e):e;Object.keys(i).forEach(e=>{null!==i[e]&&void 0!==i[e]&&(t[e]=i[e])})}return t},{})};var it={hairlineWidth:1,create:t=>t,resolve:(t,e)=>t?(t=((t,e)=>Object.keys(t).reduce((i,r)=>/@media/.test(r)?{...i,...T({[r]:t[r]},e)}:{...i,[r]:t[r]},{}))(t=et(t),e),t=tt(t,e)):null,flatten:et,absoluteFillObject:{position:"absolute",top:0,left:0,bottom:0,right:0}};const rt={debug(){const t=this.getAbsoluteLayout(),e=this.padding,i=this.margin;this.root.instance.save(),this.debugContent(t,i,e),this.debugPadding(t,i,e),this.debugMargin(t,i),this.debugText(t,i),this.debugOrigin(),this.root.instance.restore()},debugOrigin(){if(this.style.transform){const t=this.origin;this.root.instance.circle(t[0],t[1],3).fill("red").circle(t[0],t[1],5).stroke("red")}},debugText(t,e){const i=Math.round(this.width+e.left+e.right),r=Math.round(this.height+e.top+e.bottom);this.root.instance.fontSize(4).opacity(1).fillColor("black").text(`${i} x ${r}`,t.left-e.left,Math.max(t.top-e.top-4,1))},debugContent(t,e,i){this.root.instance.fillColor("#a1c6e7").opacity(.5).rect(t.left+i.left,t.top+i.top,t.width-i.left-i.right,t.height-i.top-i.bottom).fill()},debugPadding(t,e,i){this.root.instance.fillColor("#c4deb9").opacity(.5),this.root.instance.rect(t.left+i.left,t.top,t.width-i.right-i.left,i.top).fill(),this.root.instance.rect(t.left,t.top,i.left,t.height).fill(),this.root.instance.rect(t.left+t.width-i.right,t.top,i.right,t.height).fill(),this.root.instance.rect(t.left+i.left,t.top+t.height-i.bottom,t.width-i.right-i.left,i.bottom).fill()},debugMargin(t,e){this.root.instance.fillColor("#f8cca1").opacity(.5),this.root.instance.rect(t.left,t.top-e.top,t.width,e.top).fill(),this.root.instance.rect(t.left-e.left,t.top-e.top,e.left,t.height+e.top+e.bottom).fill(),this.root.instance.rect(t.left+t.width,t.top-e.top,e.right,t.height+e.top+e.bottom).fill(),this.root.instance.rect(t.left,t.top+t.height,t.width,e.bottom).fill()}},ot=(Math.sqrt(2)-1)/3*4;const st=(t,e,i,r,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderTopWidth:l,borderRightWidth:d,borderLeftWidth:c}=i;t.moveTo(n+o,s),t.lineTo(n+a-r,s);const u=r*(1-ot);t.bezierCurveTo(n+a-u,s,n+a,s+u,n+a,s+r);const p=s+Math.max(l,r);t.lineTo(n+a,p),t.lineTo(n+a-d,p);const g=Math.max(r-d,0),f=Math.max(r-l,0),m=g*(1-ot),y=f*(1-ot);t.bezierCurveTo(n+a-d,s+l+y,n+a-d-m,s+l,n+a-d-g,s+l),t.lineTo(n+Math.max(o,c),s+l);const b=Math.max(o-c,0),T=Math.max(o-l,0),w=b*(1-ot),C=T*(1-ot),E=s+Math.max(l,o);t.bezierCurveTo(n+c+w,s+l,n+c,s+l+C,n+c,E),t.lineTo(n,E),t.lineTo(n,s+o);const v=o*(1-ot);if(t.bezierCurveTo(n,s+v,n+v,s,n+o,s),t.closePath(),t.clip(),d){const e=-l/d;t.moveTo(n+a/2,e*(-a/2)+s),t.lineTo(n+a,s),t.lineTo(n,s),t.lineTo(n,s+h),t.closePath(),t.clip()}if(c){const e=-l/c;t.moveTo(n+a/2,e*(-a/2)+s),t.lineTo(n,s),t.lineTo(n+a,s),t.lineTo(n+a,s+h),t.closePath(),t.clip()}},nt=(t,e,i,r,o)=>{const{top:s,left:n,width:a}=e,{borderTopColor:h,borderTopWidth:l,borderTopStyle:d,borderRightWidth:c,borderLeftWidth:u}=i,p=o*(1-ot),g=r*(1-ot);t.moveTo(n,s+Math.max(o,l)),t.bezierCurveTo(n,s+p,n+p,s,n+o,s),t.lineTo(n+a-r,s),t.bezierCurveTo(n+a-g,s,n+a,s+g,n+a,s+r),t.strokeColor(h),t.lineWidth(2*Math.max(c,l,u)),"dashed"===d?t.dash(2*l,{space:1.2*l}):"dotted"===d&&t.dash(l,{space:1.2*l}),t.stroke(),t.undash()},at=(t,e,i,r,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderTopWidth:l,borderRightWidth:d,borderBottomWidth:c}=i;t.moveTo(n+a,s+r),t.lineTo(n+a,s+h-o);const u=o*(1-ot);t.bezierCurveTo(n+a,s+h-u,n+a-u,s+h,n+a-o,s+h);const p=n+a-Math.max(d,o);t.lineTo(p,s+h),t.lineTo(p,s+h-c);const g=Math.max(o-d,0),f=Math.max(o-c,0),m=g*(1-ot),y=f*(1-ot);t.bezierCurveTo(n+a-d-m,s+h-c,n+a-d,s+h-c-y,n+a-d,s+h-Math.max(o,c)),t.lineTo(n+a-d,s+Math.max(r,l));const b=Math.max(r-d,0),T=Math.max(r-l,0),w=b*(1-ot),C=T*(1-ot),E=n+a-Math.max(r,d);t.bezierCurveTo(n+a-d,s+l+C,n+a-d-w,s+l,E,s+l),t.lineTo(E,s),t.lineTo(n+a-r,s);const v=r*(1-ot);if(t.bezierCurveTo(n+a-v,s,n+a,s+v,n+a,s+r),t.closePath(),t.clip(),l){const e=-l/d;t.moveTo(n+a/2,e*(-a/2)+s),t.lineTo(n+a,s),t.lineTo(n+a,s+h),t.lineTo(n,s+h),t.closePath(),t.clip()}if(c){const e=c/d;t.moveTo(n+a/2,e*(-a/2)+s+h),t.lineTo(n+a,s+h),t.lineTo(n+a,s),t.lineTo(n,s),t.closePath(),t.clip()}},ht=(t,e,i,r,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderRightColor:l,borderRightStyle:d,borderRightWidth:c,borderTopWidth:u,borderBottomWidth:p}=i,g=o*(1-ot),f=r*(1-ot);t.moveTo(n+a-r,s),t.bezierCurveTo(n+a-f,s,n+a,s+f,n+a,s+r),t.lineTo(n+a,s+h-o),t.bezierCurveTo(n+a,s+h-g,n+a-g,s+h,n+a-o,s+h),t.strokeColor(l),t.lineWidth(2*Math.max(c,u,p)),"dashed"===d?t.dash(2*c,{space:1.2*c}):"dotted"===d&&t.dash(c,{space:1.2*c}),t.stroke(),t.undash()},lt=(t,e,i,r,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderBottomWidth:l,borderRightWidth:d,borderLeftWidth:c}=i;t.moveTo(n+a-o,s+h),t.lineTo(n+r,s+h);const u=r*(1-ot);t.bezierCurveTo(n+u,s+h,n,s+h-u,n,s+h-r);const p=s+h-Math.max(l,r);t.lineTo(n,p),t.lineTo(n+c,p);const g=Math.max(r-c,0),f=Math.max(r-l,0),m=g*(1-ot),y=f*(1-ot);t.bezierCurveTo(n+c,s+h-l-y,n+c+m,s+h-l,n+c+g,s+h-l),t.lineTo(n+a-Math.max(o,d),s+h-l);const b=Math.max(o-d,0),T=Math.max(o-l,0),w=b*(1-ot),C=T*(1-ot),E=s+h-Math.max(l,o);t.bezierCurveTo(n+a-d-w,s+h-l,n+a-d,s+h-l-C,n+a-d,E),t.lineTo(n+a,E),t.lineTo(n+a,s+h-o);const v=o*(1-ot);if(t.bezierCurveTo(n+a,s+h-v,n+a-v,s+h,n+a-o,s+h),t.closePath(),t.clip(),d){const e=l/d;t.moveTo(n+a/2,e*(-a/2)+s+h),t.lineTo(n+a,s+h),t.lineTo(n,s+h),t.lineTo(n,s),t.closePath(),t.clip()}if(c){const e=-l/c;t.moveTo(n+a/2,e*(a/2)+s+h),t.lineTo(n,s+h),t.lineTo(n+a,s+h),t.lineTo(n+a,s),t.closePath(),t.clip()}},dt=(t,e,i,r,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderBottomColor:l,borderBottomStyle:d,borderBottomWidth:c,borderRightWidth:u,borderLeftWidth:p}=i,g=r*(1-ot),f=o*(1-ot);t.moveTo(n+a,s+h-o),t.bezierCurveTo(n+a,s+h-f,n+a-f,s+h,n+a-o,s+h),t.lineTo(n+r,s+h),t.bezierCurveTo(n+g,s+h,n,s+h-g,n,s+h-r),t.strokeColor(l),t.lineWidth(2*Math.max(c,u,p)),"dashed"===d?t.dash(2*c,{space:1.2*c}):"dotted"===d&&t.dash(c,{space:1.2*c}),t.stroke(),t.undash()},ct=(t,e,i,r,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderTopWidth:l,borderLeftWidth:d,borderBottomWidth:c}=i;t.moveTo(n,s+h-r),t.lineTo(n,s+o);const u=o*(1-ot);t.bezierCurveTo(n,s+u,n+u,s,n+o,s);const p=n+Math.max(d,o);t.lineTo(p,s),t.lineTo(p,s+l);const g=Math.max(o-d,0),f=Math.max(o-l,0),m=g*(1-ot),y=f*(1-ot);t.bezierCurveTo(n+d+m,s+l,n+d,s+l+y,n+d,s+Math.max(o,l)),t.lineTo(n+d,s+h-Math.max(r,c));const b=Math.max(r-d,0),T=Math.max(r-c,0),w=b*(1-ot),C=T*(1-ot),E=n+Math.max(r,d);t.bezierCurveTo(n+d,s+h-c-C,n+d+w,s+h-c,E,s+h-c),t.lineTo(E,s+h),t.lineTo(n+r,s+h);const v=r*(1-ot);if(t.bezierCurveTo(n+v,s+h,n,s+h-v,n,s+h-r),t.closePath(),t.clip(),c){const e=-c/d;t.moveTo(n+a/2,e*(a/2)+s+h),t.lineTo(n,s+h),t.lineTo(n,s),t.lineTo(n+a,s),t.closePath(),t.clip()}if(c){const e=-l/d;t.moveTo(n+a/2,e*(-a/2)+s),t.lineTo(n,s),t.lineTo(n,s+h),t.lineTo(n+a,s+h),t.closePath(),t.clip()}},ut=(t,e,i,r,o)=>{const{top:s,left:n,height:a}=e,{borderLeftColor:h,borderLeftStyle:l,borderLeftWidth:d,borderTopWidth:c,borderBottomWidth:u}=i,p=r*(1-ot),g=o*(1-ot);t.moveTo(n+r,s+a),t.bezierCurveTo(n+p,s+a,n,s+a-p,n,s+a-r),t.lineTo(n,s+o),t.bezierCurveTo(n,s+g,n+g,s,n+o,s),t.strokeColor(h),t.lineWidth(2*Math.max(d,c,u)),"dashed"===l?t.dash(2*d,{space:1.2*d}):"dotted"===l&&t.dash(d,{space:1.2*d}),t.stroke(),t.undash()};var pt={drawBorders:function(){const{instance:t}=this.root,e=this.getAbsoluteLayout(),{borderTopWidth:i,borderLeftWidth:r,borderRightWidth:o,borderBottomWidth:s}=this,{opacity:n,borderTopLeftRadius:a=0,borderTopRightRadius:h=0,borderBottomLeftRadius:l=0,borderBottomRightRadius:d=0,borderTopColor:c="black",borderTopStyle:u="solid",borderLeftColor:p="black",borderLeftStyle:g="solid",borderRightColor:f="black",borderRightStyle:m="solid",borderBottomColor:y="black",borderBottomStyle:b="solid"}=this.style,T={borderTopColor:c,borderTopWidth:i,borderTopStyle:u,borderLeftColor:p,borderLeftWidth:r,borderLeftStyle:g,borderRightColor:f,borderRightWidth:o,borderRightStyle:m,borderBottomColor:y,borderBottomWidth:s,borderBottomStyle:b,borderTopLeftRadius:a,borderTopRightRadius:h,borderBottomLeftRadius:l,borderBottomRightRadius:d},{width:w,height:C}=e,E=Math.min(h,.5*w,.5*C),v=Math.min(a,.5*w,.5*C),R=Math.min(d,.5*w,.5*C),x=Math.min(l,.5*w,.5*C);t.save(),t.strokeOpacity(n),i&&(t.save(),st(t,e,T,E,v),nt(t,e,T,E,v),t.restore()),o&&(t.save(),at(t,e,T,E,R),ht(t,e,T,E,R),t.restore()),s&&(t.save(),lt(t,e,T,x,R),dt(t,e,T,x,R),t.restore()),r&&(t.save(),ct(t,e,T,x,v),ut(t,e,T,x,v),t.restore()),t.restore()}};const gt=(Math.sqrt(2)-1)/3*4,ft={clip(){const{top:t,left:e,width:i,height:r}=this.getAbsoluteLayout(),{borderTopLeftRadius:o=0,borderTopRightRadius:s=0,borderBottomRightRadius:n=0,borderBottomLeftRadius:a=0}=this.style,h=Math.min(s,.5*i,.5*r),l=h*(1-gt);this.root.instance.moveTo(e+h,t),this.root.instance.lineTo(e+i-h,t),this.root.instance.bezierCurveTo(e+i-l,t,e+i,t+l,e+i,t+h);const d=Math.min(n,.5*i,.5*r),c=d*(1-gt);this.root.instance.lineTo(e+i,t+r-d),this.root.instance.bezierCurveTo(e+i,t+r-c,e+i-c,t+r,e+i-d,t+r);const u=Math.min(a,.5*i,.5*r),p=u*(1-gt);this.root.instance.lineTo(e+u,t+r),this.root.instance.bezierCurveTo(e+p,t+r,e,t+r-p,e,t+r-u);const g=Math.min(o,.5*i,.5*r),f=g*(1-gt);this.root.instance.lineTo(e,t+g),this.root.instance.bezierCurveTo(e,t+f,e+f,t,e+g,t),this.root.instance.closePath(),this.root.instance.clip()}},mt=t=>{const e=/translateX\((-?\d+\.?d*)\)/g.exec(t),i=/translate\((-?\d+\.?d*).*,\s*(-?\d+\.?d*).*\)/g.exec(t);return e&&e[1]?e[1]:i&&i[1]?i[1]:0},yt=t=>{const e=/translateY\((-?\d+\.?\d*)\)/g.exec(t),i=/translate\((-?\d+\.?\d*).*,\s*(-?\d+\.?\d*).*\)/g.exec(t);return e&&e[1]?e[1]:i&&i[2]?i[2]:0},bt=t=>{const e=/scaleX\((-?\d+\.?\d*)\)/g.exec(t),i=/scale\((-?\d+\.?\d*).*,\s*(-?\d+\.?\d*).*\)/g.exec(t);return e&&e[1]?e[1]:i&&i[1]?i[1]:1},Tt=t=>{const e=/scaleY\((-?\d+\.?\d*)\)/g.exec(t),i=/scale\((-?\d+\.?\d*).*,\s*(-?\d+\.?\d*).*\)/g.exec(t);return e&&e[1]?e[1]:i&&i[2]?i[2]:1},wt=(t,e,i)=>{/rotate/g.test(e)?t.root.instance.rotate((t=>{const e=/rotate\((-?\d+.?\d+)(.+)\)/g.exec(t);if(e&&e[1]&&e[2]){const t=e[1];return"rad"===e[2]?180*t/Math.PI:t}return 0})(e),{origin:i}):/scaleX/g.test(e)?t.root.instance.scale(bt(e),1,{origin:i}):/scaleY/g.test(e)?t.root.instance.scale(1,Tt(e),{origin:i}):/scale/g.test(e)?t.root.instance.scale(bt(e),Tt(e),{origin:i}):/translateX/g.test(e)?t.root.instance.translate(mt(e),1,{origin:i}):/translateY/g.test(e)?t.root.instance.translate(1,yt(e),{origin:i}):/translate/g.test(e)?t.root.instance.translate(mt(e),yt(e),{origin:i}):/matrix/g.test(e)&&t.root.instance.transform(...(t=>{const e=/matrix\(([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)\)/g.exec(t);return e?e.slice(1,7):null})(e))},Ct={applyTransformations(){let t;const e=/[a-zA-Z]+\([^)]+\)/g,i=this.origin,r=this.style&&this.style.transform||"";for(;null!=(t=e.exec(r));)wt(this,t[0],i)}};const Et="production"!==process.env.NODE_ENV?(t,e,...i)=>{if(void 0===e)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");t||function(t,...e){let i=0;const r="Warning: "+t.replace(/%s/g,()=>e[i++]);"undefined"!=typeof console&&console.error(r);try{throw new Error(r)}catch(t){}}(e,...i)}:()=>{},vt=(t,e)=>h(e)?t:e,Rt=t=>t.reduce((t,e)=>a(vt,t,e),{}),xt=l(d("Function"),c),Pt=["color","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","opacity","textDecoration","lineHeight","textAlign","visibility","wordSpacing"];class St extends z{constructor(t,e){super(),this.root=t,this.style={},this.props=Rt([this.constructor.defaultProps,St.defaultProps,e]),Et(!this.props.styles,'"styles" prop passed instead of "style" prop')}get page(){return this.parent.page}get wrap(){return this.props.wrap}get break(){return this.props.break}get fixed(){return this.props.fixed}get minPresenceAhead(){return this.props.minPresenceAhead}get absolute(){return"absolute"===this.props.style.position}get origin(){const{transformOriginX:t,transformOriginY:e}=this.style,{left:i,top:r,width:o,height:s}=this.getAbsoluteLayout(),n=k(t),a=k(e);return[i+(n?o*n.percent:t),r+(a?s*a.percent:e)]}set break(t){this.props.break=t}appendChild(t){super.appendChild(t),this.root.markDirty()}appendChildBefore(t,e){super.appendChildBefore(t,e),this.root.markDirty()}removeChild(t){super.removeChild(t),this.root.markDirty()}update(t){this.props=Rt([this.constructor.defaultProps,St.defaultProps,t]),this.root.markDirty()}applyProps(){this.style=this.resolveStyles(),u(this.style).map(([t,e])=>{this.applyStyle(t,e)}),this.children.forEach(t=>{t.applyProps&&t.applyProps()})}resolveStyles(){const{size:t,orientation:e,isAutoHeight:i}=this.page,r={orientation:e,isAutoHeight:i,width:t.width,height:t.height},o=it.resolve(this.props.style,r);return{...this.parent?p(Pt,this.parent.style):{},...o}}applyStyle(t,e){if(void 0===e)return;const i=`set${I(t)}`;switch(t){case"marginTop":case"marginRight":case"marginBottom":case"marginLeft":case"paddingTop":case"paddingRight":case"paddingBottom":case"paddingLeft":case"borderTopWidth":case"borderRightWidth":case"borderBottomWidth":case"borderLeftWidth":case"position":case"top":case"right":case"bottom":case"left":case"width":case"height":case"minHeight":case"maxHeight":case"minWidth":case"maxWidth":this[t]=e;break;default:xt(this.layout[i])&&this.layout[i](e)}}getLayoutData(){const t=this.getAbsoluteLayout();return{type:this.name,top:t.top,left:t.left,width:t.width,style:this.style,height:t.height,children:this.children.map(t=>t.getLayoutData())}}drawBackgroundColor(){const{backgroundColor:t,opacity:e=1}=this.style,{left:i,top:r,width:o,height:s}=this.getAbsoluteLayout();t&&(this.root.instance.save(),this.clip(),this.root.instance.fillOpacity(e).fillColor(t).rect(i,r,o,s).fill().restore())}clone(){const t=new this.constructor(this.root,this.props);return t.copyStyle(this),t.style=this.style,t}onNodeSplit(t,e){this.calculateLayout(),e.marginTop=0,e.paddingTop=0,e.style.height&&(e.height=this.height-t),this.height=t,this.marginBottom=0,this.paddingBottom=0}async renderChildren(){for(let t=0;t<this.children.length;t++)await this.children[t].render()}}St.defaultProps={style:{borderTopLeftRadius:0,borderTopRightRadius:0,borderBottomRightRadius:0,borderBottomLeftRadius:0,transformOriginX:"50%",transformOriginY:"50%"},minPresenceAhead:0},Object.assign(St.prototype,rt),Object.assign(St.prototype,pt),Object.assign(St.prototype,ft),Object.assign(St.prototype,Ct);const At=(t,e)=>Array.from({length:Math.ceil(t/e)},(t,i)=>i*e),Lt=t=>{const e=k(t);return e?100/e.value:null},Bt={getRulerWidth:()=>13,hasHorizontalRuler(){return this.props.ruler||this.props.horizontalRuler},hasVerticalRuler(){return this.props.ruler||this.props.verticalRuler},getHorizontalSteps(){const t=this.props.horizontalRulerSteps||this.props.rulerSteps||50;if("string"==typeof t){const e=Lt(t);if(e){return(this.width-(this.hasVerticalRuler()?13:0))/e}throw new Error("Page: Invalid horizontal steps value")}return t},getVerticalSteps(){const t=this.props.verticalRulerSteps||this.props.rulerSteps||50;if("string"==typeof t){const e=Lt(t);if(e){return(this.height-(this.hasHorizontalRuler()?13:0))/e}throw new Error("Page: Invalid horizontal steps value")}return t},renderRuler(){const t=this.hasHorizontalRuler(),e=this.hasVerticalRuler();(t||e)&&(this.root.instance.save().lineWidth(.5).fontSize(5).opacity(1),t&&this.drawHorizontalRuler(),e&&this.drawVerticalRuler(),t&&e&&this.root.instance.rect(0,0,12.5,12.5).fill("white"),this.root.instance.restore())},drawHorizontalRuler(){const t=this.hasVerticalRuler()?13:0;this.root.instance.rect(t,0,this.width,13).fill("white").moveTo(this.hasVerticalRuler()?13:0,13).lineTo(this.width,13).stroke("gray");const e=At(this.width,this.getHorizontalSteps());e.map(e=>{this.root.instance.moveTo(t+e,0).lineTo(t+e,13).stroke("gray").fillColor("black").text(`${Math.round(e)}`,t+e+1,1)}),e.map(e=>{0!==e&&this.root.instance.moveTo(t+e,13).lineTo(t+e,this.height).stroke("#ababab")})},drawVerticalRuler(){const t=this.hasHorizontalRuler()?13:0;this.root.instance.rect(0,t,13,this.height).fill("white").moveTo(13,this.hasHorizontalRuler()?13:0).lineTo(13,this.height).stroke("gray");const e=At(this.height,this.getVerticalSteps());e.map(e=>{this.root.instance.moveTo(0,t+e).lineTo(13,t+e).stroke("gray").fillColor("black").text(`${Math.round(e)}`,1,t+e+1)}),e.map(e=>{0!==e&&this.root.instance.moveTo(13,t+e).lineTo(this.width,t+e).stroke("#ababab")})}};class Ot{constructor(t,e){this.root=t,this.value=e,this.parent=null,this.props={}}get name(){return"TextInstance"}getLayoutData(){return this.value}remove(){this.parent.removeChild(this)}clone(){return new this.constructor(this.root,this.value)}cleanup(){}update(t){this.value=t,this.parent.computed=!1,this.parent.container=null,this.root.markDirty()}}const Mt={"4A0":[4767.87,6740.79],"2A0":[3370.39,4767.87],A0:[2383.94,3370.39],A1:[1683.78,2383.94],A2:[1190.55,1683.78],A3:[841.89,1190.55],A4:[595.28,841.89],A5:[419.53,595.28],A6:[297.64,419.53],A7:[209.76,297.64],A8:[147.4,209.76],A9:[104.88,147.4],A10:[73.7,104.88],B0:[2834.65,4008.19],B1:[2004.09,2834.65],B2:[1417.32,2004.09],B3:[1000.63,1417.32],B4:[708.66,1000.63],B5:[498.9,708.66],B6:[354.33,498.9],B7:[249.45,354.33],B8:[175.75,249.45],B9:[124.72,175.75],B10:[87.87,124.72],C0:[2599.37,3676.54],C1:[1836.85,2599.37],C2:[1298.27,1836.85],C3:[918.43,1298.27],C4:[649.13,918.43],C5:[459.21,649.13],C6:[323.15,459.21],C7:[229.61,323.15],C8:[161.57,229.61],C9:[113.39,161.57],C10:[79.37,113.39],RA0:[2437.8,3458.27],RA1:[1729.13,2437.8],RA2:[1218.9,1729.13],RA3:[864.57,1218.9],RA4:[609.45,864.57],SRA0:[2551.18,3628.35],SRA1:[1814.17,2551.18],SRA2:[1275.59,1814.17],SRA3:[907.09,1275.59],SRA4:[637.8,907.09],EXECUTIVE:[521.86,756],FOLIO:[612,936],LEGAL:[612,1008],LETTER:[612,792],TABLOID:[792,1224]},Dt=(t,e="portrait")=>{let i;if("string"==typeof t)i=Mt[t.toUpperCase()];else if(Array.isArray(t))i=t;else if("number"==typeof t)i=[t];else{if("object"!=typeof t||!t.width)throw new Error(`Invalid Page size: ${t}`);i=[t.width,t.height]}return"portrait"===e?{width:i[0],height:i[1]}:{width:i[1],height:i[0]}};class Wt extends St{constructor(t,e){super(t,e),this._size=null}get name(){return"Page"}get document(){return this.parent}get page(){return this}get orientation(){return this.props.orientation}get size(){return this._size?this._size:(this._size=Dt(this.props.size,this.orientation),this.hasHorizontalRuler()&&(this._size.width+=this.getRulerWidth()),this.hasVerticalRuler()&&(this._size.height+=this.getRulerWidth()),this._size)}get isAutoHeight(){return void 0===this.size.height}resetMargins(){(this.marginTop||this.marginBottom||this.marginLeft||this.marginRight)&&(Et(!1,"Margin values are not allowed on Page element. Use padding instead."),this.marginTop=0,this.marginBottom=0,this.marginLeft=0,this.marginRight=0)}applyProps(){super.applyProps(),this.top=0,this.left=0,this.width=this.size.width,this.resetMargins();const t=this.getRulerWidth();this.hasHorizontalRuler()&&(this.paddingTop=this.paddingTop+t),this.hasVerticalRuler()&&(this.paddingLeft=this.paddingLeft+t)}setPadding(t,e){const i=t===n.EDGE_TOP||t===n.EDGE_BOTTOM?this.size.height:this.size.width,r=k(e);r?this.layout.setPadding(t,i*r.percent):this.layout.setPadding(t,e)}async addDynamicChild(t,e){if(!e)return;const i=Array.isArray(e)?e:[e];for(let e=0;e<i.length;e++){const r=i[e],{type:o,props:n}=r;if("string"==typeof r){const e=new Ot(this.root,r);t.appendChild(e)}else if(o!==s){const e=Ie(r,this.root);await e.onAppendDynamically(),t.appendChild(e),e.applyProps(),await this.addDynamicChild(e,n.children)}else await this.addDynamicChild(t,n.children)}}async renderDynamicNodes(t,e){const i=this.children.slice(0);for(;i.length>0;){const r=i.shift();if((!e||e(r))&&r.props.render){r.removeAllChilds();const e=r.props.render(t);await this.addDynamicChild(r,e),r.fixed||(r.props.render=null)}else r.children&&i.push(...r.children)}}async nodeWillWrap(t){await this.renderDynamicNodes(t),this.calculateLayout()}onNodeSplit(t,e){e.marginTop=0,this.marginBottom=0,this.calculateLayout()}clone(){const t=super.clone();return t._size=this.size,t}update(t){super.update(t),this._size=null}async render(){const{instance:t}=this.root;this.isAutoHeight||(this.height=this.size.height),this.calculateLayout();const e=this.isAutoHeight?this.height:this.size.height;t.addPage({size:[this.size.width,e],margin:0}),this.style.backgroundColor&&t.fillColor(this.style.backgroundColor).rect(0,0,this.size.width,e).fill(),await this.renderChildren(),this.props.debug&&this.debug(),this.renderRuler()}}Wt.defaultProps={size:"A4",wrap:!0,orientation:"portrait"},Object.assign(Wt.prototype,Bt);class _t extends St{get name(){return"View"}async render(){this.root.instance.save(),this.applyTransformations(),this.drawBackgroundColor(),this.drawBorders(),this.props.onRender&&this.props.onRender(this),await this.renderChildren(),this.props.debug&&this.debug(),this.root.instance.restore()}}_t.defaultProps={wrap:!0};const It=async(t,e)=>{const i=await R(t,e),r=await(i.buffer?i.buffer():i.arrayBuffer());return"Buffer"===r.constructor.name?r:Buffer.from(r)};class kt{constructor(t,e,i,r,o){this.src=t,this.fontFamily=e,this.fontStyle=i||"normal",this.fontWeight=$(r)||400,this.data=null,this.loading=!1,this.options=o}async load(){if(this.loading=!0,E(this.src)){const{headers:t,body:e,method:i="GET"}=this.options,r=await It(this.src,{method:i,body:e,headers:t});this.data=v.create(r)}else this.data=await new Promise((t,e)=>v.open(this.src,(i,r)=>i?e(i):t(r)));this.loading=!1}}class zt{static create(t){return new zt(t)}constructor(t){this.family=t,this.sources=[]}register({src:t,fontWeight:e,fontStyle:i,...r}){this.sources.push(new kt(t,this.fontFamily,i,e,r))}resolve(t){const{fontWeight:e=400,fontStyle:i="normal"}=t,r=this.sources.filter(t=>t.fontStyle===i),o=r.find(t=>t.fontWeight===e);if(o)return o;let s;if(e>=400&&e<=500){const t=r.filter(t=>t.fontWeight<=e),i=r.filter(t=>t.fontWeight>500);s=r.filter(t=>t.fontWeight>=e&&t.fontWeight<500)[0]||t[t.length-1]||i[0]}const n=r.filter(t=>t.fontWeight<e),a=r.filter(t=>t.fontWeight>e);if(e<400&&(s=n[n.length-1]||a[0]),e>500&&(s=a[0]||n[n.length-1]),!s)throw new Error(`Could not resolve font for ${this.fontFamily}, fontWeight ${e}`);return s}}let Ft;var Nt=["Courier","Courier-Bold","Courier-Oblique","Helvetica","Helvetica-Bold","Helvetica-Oblique","Times-Roman","Times-Bold","Times-Italic"];let Gt;let Ht={};const jt=t=>{const{fontFamily:e}=t;if(Nt.includes(e))return null;if(!Ht[e])throw new Error(`Font family not registered: ${e}. Please register it calling Font.register() method.`);return Ht[e].resolve(t)};var Ut={register:(t,e)=>{"object"==typeof t?e=t:(Et(!1,"Font.register will not longer accept the font source as first argument. Please move it into the data object. For more info refer to https://react-pdf.org/fonts"),e.src=t);const{family:i}=e;if(Ht[i]||(Ht[i]=zt.create(i)),e.fonts)for(let t=0;t<e.fonts.length;t++)Ht[i].register({family:i,...e.fonts[t]});else Ht[i].register(e)},getRegisteredFonts:()=>Ht,getRegisteredFontFamilies:()=>Object.keys(Ht),getFont:jt,load:async function(t,e){const{fontFamily:i}=t;if(Nt.includes(i))return;const r=jt(t);r.data||r.loading||await r.load()},clear:function(){Ht={}},reset:function(){for(const t in Ht)Ht.hasOwnProperty(t)&&(Ht[t].data=null)},...{registerEmojiSource:({url:t,format:e="png"})=>{Ft={url:t,format:e}},getEmojiSource:()=>Ft},...{registerHyphenationCallback:t=>{Gt=t},getHyphenationCallback:()=>Gt}};class Vt{constructor(t){this.name=t,this.src=o.open(null,t)}layout(t){const[e,i]=this.src.encode(t);return{positions:i,stringIndices:i.map((t,e)=>e),glyphs:e.map((t,e)=>{const r=this.getGlyph(parseInt(t,16));return r.advanceWidth=i[e].advanceWidth,r})}}glyphForCodePoint(t){const e=this.getGlyph(t);return e.advanceWidth=400,e}getGlyph(t){return{id:t,_font:this.src,codePoints:[t],isLigature:!1,name:this.src.font.characterToGlyph(t)}}hasGlyphForCodePoint(t){return".notdef"!==this.src.font.characterToGlyph(t)}get ascent(){return 900}get descent(){switch(this.name){case"Times-Roman":case"Times-Bold":case"Times-Italic":return-220;case"Courier":case"Courier-Bold":case"Courier-Oblique":return-230;default:return-200}}get lineGap(){return 0}get unitsPerEm(){return 1e3}}const Xt={},$t=[173],Yt=g(12,["attributes","fontSize"]),Jt=()=>qt("Helvetica"),qt=t=>{if(Xt[t])return Xt[t];const e=new Vt(t);return Xt[t]=e,e},Kt=(t,e)=>!$t.includes(t)&&!e.hasGlyphForCodePoint(t)&&Jt().hasGlyphForCodePoint(t),Zt=x({linebreaker:P,justification:S,textDecoration:A,scriptItemizer:L,wordHyphenation:B,fontSubstitution:()=>({string:t,runs:e})=>{let i=null,r=0,o=0;const s=[];for(const n of e){const e=Yt(n),a="string"==typeof n.attributes.font?qt(n.attributes.font):n.attributes.font;if(0===t.length){s.push({start:0,end:0,attributes:{font:a}});break}for(const h of t.slice(n.start,n.end)){const t=h.codePointAt(),n=Kt(t,a)?Jt():a;n!==i&&(i&&s.push({start:r,end:o,attributes:{font:i,scale:i?e/i.unitsPerEm:0}}),i=n,r=o),o+=h.length}}if(r<t.length){const o=Yt(f(e));s.push({start:r,end:t.length,attributes:{font:i,scale:i?o/i.unitsPerEm:0}})}return{string:t,runs:s}}}),Qt=/^([a-z]+\:(\/\/)?)/i,te=t=>t?"string"!=typeof t||t.match(Qt)?t:`http://${t}`:"";W.isValid=function(t){try{return!!new W(t)}catch(t){return!1}};const ee=[65472,65473,65474,65475,65477,65478,65479,65480,65481,65482,65483,65484,65485,65486,65487];class ie{constructor(t){if(this.data=null,this.width=null,this.height=null,this.data=t,65496!==t.readUInt16BE(0))throw new Error("SOI not found in JPEG");let e,i=2;for(;i<t.length&&(e=t.readUInt16BE(i),i+=2,!ee.includes(e));)i+=t.readUInt16BE(i);if(!ee.includes(e))throw new Error("Invalid JPEG.");i+=3,this.height=t.readUInt16BE(i),i+=2,this.width=t.readUInt16BE(i)}}ie.isValid=function(t){if(!t||!Buffer.isBuffer(t)||65496!==t.readUInt16BE(0))return!1;let e,i=2;for(;i<t.length&&(e=t.readUInt16BE(i),i+=2,!ee.includes(e));)i+=t.readUInt16BE(i);return!!ee.includes(e)};const re=(({limit:t=100}={})=>{let e={},i=[];return{get:t=>e[t],set:(r,o)=>{i.push(r),i.length>t&&delete e[i.shift()],e[r]=o},reset:()=>{e={},i=[]},length:()=>i.length}})({limit:30}),oe=t=>{const{protocol:e,auth:i,host:r,port:o,hostname:s,path:n}=M.parse(t),a=D.resolve(n);if(!(e&&"file:"!==e||i||r||o||s))return a},se=(e,{safePath:i,allowDangerousPaths:r=!1}={})=>new Promise((o,s)=>{try{0;const n=oe(e);if(!n)return s(new Error(`Cannot fetch non-local path: ${e}`));if(!r&&((t,{safePath:e="./public"}={})=>{const i=D.resolve(e);return!D.resolve(t).startsWith(i)})(n,{safePath:i}))return s(new Error(`Cannot fetch dangerous local path: ${e}`));t.readFile(n,(t,e)=>t?s(t):o(e))}catch(t){s(t)}});function ne(t,e){switch(e.toLowerCase()){case"jpg":case"jpeg":return new ie(t);case"png":return new W(t);default:return null}}const ae=t=>{const e=(t=>{let e;return ie.isValid(t)?e="jpg":W.isValid(t)&&(e="png"),e})(t);if(e)return new Promise(i=>i(ne(t,e)))},he=async(t,e)=>{const{uri:i,body:r,headers:o,method:s="GET"}=t,n=oe(i)?await se(i,e):await(async(t,e)=>{const i=await R(t,e),r=await(i.buffer?i.buffer():i.arrayBuffer());return"Buffer"===r.constructor.name?r:Buffer.from(r)})(i,{body:r,headers:o,method:s});return ne(n,(t=>{const e=137===t[0]&&80===t[1]&&78===t[2]&&71===t[3]&&13===t[4]&&10===t[5]&&26===t[6]&&10===t[7],i=255===t[0]&&216===t[1]&&255===t[2];let r="";if(e)r="png";else{if(!i)throw new Error("Not valid image extension");r="jpg"}return r})(n))},le=(t,{cache:e=!0,...i}={})=>{const r=t.data?t.data.toString():t.uri;if(e&&re.get(r))return re.get(r);let o;if(!(o=(({uri:t})=>/^data:image\/[a-zA-Z]*;base64,[^"]*/g.test(t))(t)?(({uri:t})=>{const e=/^data:image\/([a-zA-Z]*);base64,([^"]*)/g.exec(t),i=e[1],r=e[2];if(!(t=>{const e=t.toLowerCase();return"jpg"===e||"jpeg"===e||"png"===e})(i))throw new Error(`Base64 image invalid format: ${i}`);return new Promise(t=>t(ne(Buffer.from(r,"base64"),i)))})(t):Buffer.isBuffer(t)?ae(t):"object"==typeof t&&t.data?(t=>{if(t.data&&t.format)return new Promise(e=>e(ne(t.data,t.format)));throw new Error(`Invalid data given for local file: ${JSON.stringify(t)}`)})(t):he(t,i)))throw new Error("Cannot resolve image");return e&&re.set(r,o),o},de={},ce=O(),ue=()=>(t=>(...e)=>t(...e).then(t=>t,t=>t))(le),pe=t=>"️"!==t,ge=t=>{const{url:e,format:i}=Ut.getEmojiSource();return`${e}${(t=>Array.from(t).filter(pe).map(t=>t.codePointAt(0).toString(16)).join("-"))(t)}.${i}`},fe=t=>{const e=Ut.getEmojiSource();if(!e||!e.url)return[];const i=[];let r;for(;r=ce.exec(t);){const t=r[0];if(!de[t]||de[t].loading){const e=ge(t);de[t]={loading:!0};const r=ue();i.push(r({uri:e}).then(e=>{de[t].loading=!1,de[t].data=e.data}))}}return i},me=[8232,8233],ye=[t=>t.map(t=>{const e=(t=>me.reduce((e,i)=>t.hasGlyphForCodePoint&&t.hasGlyphForCodePoint(i)?e:[...e,String.fromCharCode(i)],[]))(t.attributes.font),i=new RegExp(e.join("|"));return{string:t.string.replace(i,""),attributes:t.attributes}}),t=>{const e=[];for(let i=0;i<t.length;i++){const r=t[i];let o,s=0;for(;o=ce.exec(r.string);){const t=o.index,i=o[0],n=r.attributes.fontSize,a=r.string.slice(s,t+o[0].length);de[i]&&de[i].data?e.push({string:a.replace(o,String.fromCharCode(65532)),attributes:{...r.attributes,attachment:{width:n,height:n,yOffset:Math.floor(.1*n),image:de[i].data}}}):e.push({string:a.replace(o,String.fromCharCode(0)),attributes:r.attributes}),s=t+i.length}s<r.string.length&&e.push({string:r.string.slice(s),attributes:r.attributes})}return e}],be=m("name","Image"),Te=l(y(h),b("value")),we=(t,e)=>{switch(e){case"uppercase":return t.toUpperCase();case"lowercase":return t.toLowerCase();case"capitalize":return(t=>t.replace(/(^|\s)\S/g,t=>t.toUpperCase()))(t);default:return t}},Ce=t=>{if(!t)return[{string:""}];let e=[];const{color:i="black",backgroundColor:r,fontFamily:o="Helvetica",fontWeight:s,fontStyle:n,fontSize:a=18,textAlign:h="left",lineHeight:l,textDecoration:d,textDecorationColor:c,textDecorationStyle:u,textTransform:p,letterSpacing:g,textIndent:f,opacity:m}=t.style,y=Ut.getFont({fontFamily:o,fontWeight:s,fontStyle:n}),b={font:y?y.data:o,color:i,opacity:m,fontSize:a,backgroundColor:r,align:h,indent:f,link:t.src,characterSpacing:g,underlineStyle:u,underline:"underline"===d,underlineColor:c||i,strike:"line-through"===d,strikeStyle:u,strikeColor:c||i,lineHeight:l?l*a:null};t.children.forEach(t=>{be(t)?e.push({string:String.fromCharCode(65532),attributes:{...b,attachment:{width:t.style.width||a,height:t.style.height||a,image:t.image.data}}}):Te(t)?e.push({string:we(t.value,p),attributes:b}):t&&e.push(...Ce(t))});for(const t of ye)e=t(e);return e},Ee=t=>C.fromFragments(Ce(t));class ve extends St{constructor(t,e){super(t,e),this.start=0,this.end=0,this.blocks=null,this.computed=!1,this.attributedString=null,this.layoutOptions={hyphenationPenalty:e.hyphenationPenalty,hyphenationCallback:Ut.getHyphenationCallback(),shrinkWhitespaceFactor:{before:-.5,after:-.5}},this.layout.setMeasureFunc(this.measureText.bind(this))}get name(){return"Text"}get src(){return te(this.props.src||this.props.href)}get lines(){return this.blocks?this.blocks.reduce((t,e)=>[...t,...e],[]).splice(this.start,this.end):[]}get linesHeight(){return this.blocks?this.lines.reduce((t,e)=>t+e.box.height,0):-1}get linesWidth(){return this.blocks?Math.max(...this.lines.map(t=>C.advanceWidth(t))):-1}appendChild(t){t&&(t.parent=this,this.children.push(t),this.computed=!1,this.attributedString=null,this.markDirty())}removeChild(t){const e=this.children.indexOf(t);-1!==e&&(t.parent=null,this.children.splice(e,1),this.computed=!1,this.attributedString=null,this.markDirty(),t.cleanup())}lineIndexAtHeight(t){let e=0;for(let i=0;i<this.lines.length;i++){const r=this.lines[i];if(e+r.box.height>t)return i;e+=r.box.height}return this.lines.length}heightAtLineIndex(t){let e=0;for(let i=0;i<t;i++){e+=this.lines[i].box.height}return e}layoutText(t,e){if(this.attributedString=Ee(this),!this.blocks||this.props.render){const i={x:0,y:0,width:t,height:e||1/0,maxLines:this.style.maxLines,truncateMode:this.style.textOverflow};this.blocks=Zt(this.attributedString,i,this.layoutOptions)}const i=this.blocks.reduce((t,e)=>t+e.length,0);this.end=i+1,this.computed=!0}measureText(t,e,i,r){return e===n.MEASURE_MODE_EXACTLY?(this.layoutText(t,i),{height:this.linesHeight}):e===n.MEASURE_MODE_AT_MOST?(this.layoutText(t,i),{height:this.linesHeight,width:Math.min(t,this.linesWidth)}):{}}resolveStyles(){const t=super.resolveStyles();return this.parent&&"Text"===this.parent.name&&"relative"===this.parent.style.position&&(t.top=t.top||this.parent.style.top,t.bottom=t.bottom||this.parent.style.bottom,t.position=t.position||"relative"),this.src&&(t.color=t.color||"blue",t.textDecoration=t.textDecoration||"underline"),t}wrapHeight(t){const{orphans:e,widows:i}=this.props,r=this.lines.length,o=t-this.paddingTop,s=this.lineIndexAtHeight(o);return r<e?t:s<e||r<e+i?0:r===e+i?this.heightAtLineIndex(e):r-s<i?t-this.heightAtLineIndex(i-1):t}onNodeSplit(t,e){const i=this.wrapHeight(t),r=this.lineIndexAtHeight(i);e.marginTop=0,e.paddingTop=0,e.start=r,e.attributedString=this.attributedString,this.height=i,this.marginBottom=0,this.paddingBottom=0,this.end=r}clone(){const t=super.clone();return t.layoutEngine=this.layoutEngine,this.blocks&&!this.props.render&&(t.blocks=[...this.blocks]),t}renderText(){const{top:t,left:e}=this.getAbsoluteLayout(),i=this.lines[0]?this.lines[0].box.y:0;this.root.instance.save(),this.root.instance.translate(e+this.padding.left,t+this.padding.top-i),w.render(this.root.instance,[this.lines]),this.root.instance.restore()}async render(){this.root.instance.save(),this.applyTransformations(),this.drawBackgroundColor(),this.drawBorders(),this.computed||this.layoutText(this.width-this.padding.left-this.padding.right,this.height-this.padding.top-this.padding.bottom),this.renderText(),this.props.debug&&this.debug(),this.root.instance.restore()}}ve.defaultProps={wrap:!0,widows:2,orphans:2};class Re extends St{get name(){return"Note"}appendChild(t){if("TextInstance"!==t.name)throw new Error("Note only accepts string children");t&&(t.parent=this,this.children.push(t))}removeChild(t){const e=this.children.indexOf(t);-1!==e&&(t.parent=null,this.children.splice(e,1)),t.cleanup()}applyProps(){super.applyProps(),this.height=0,this.width=0}async render(){const{top:t,left:e}=this.getAbsoluteLayout(),i=this.children[0]?this.children[0].value:"";this.root.instance.note(e,t,0,0,i)}}Re.defaultProps={};const xe=t=>!isNaN(parseFloat(t))&&isFinite(t),Pe=(t,e,i,r,o,s)=>{const n=t/e,a=i/r,h=k(o),l=k(s),d=h?h.percent:.5,c=l?l.percent:.5;if(n>a){const i=e,r=i*a,n=xe(s)?s:0;return{width:r,height:i,xOffset:xe(o)?o:(t-r)*d,yOffset:n}}{const i=t,r=i/a,n=xe(o)?o:0;return{width:i,height:r,yOffset:xe(s)?s:(e-r)*c,xOffset:n}}},Se=(t,e,i,r,o,s)=>{const n=i,a=r,h=k(o),l=k(s),d=h?h.percent:.5,c=l?l.percent:.5;return{width:n,height:a,xOffset:xe(o)?o:(t-n)*d,yOffset:xe(s)?s:(e-a)*c}},Ae=(t="fill",e,i,r,o,s,n)=>{switch(t){case"contain":return Pe(e,i,r,o,s,n);case"cover":return((t,e,i,r,o,s)=>{const n=i/r,a=t/e,h=k(o),l=k(s),d=h?h.percent:.5,c=l?l.percent:.5;if(a>n){const i=t,r=i/n,a=xe(o)?o:0;return{width:i,height:r,yOffset:xe(s)?s:(e-r)*c,xOffset:a}}{const i=e*n;return{width:i,height:e,xOffset:xe(o)?o:(t-i)*d,yOffset:xe(s)?s:0}}})(e,i,r,o,s,n);case"none":return Se(e,i,r,o,s,n);case"scale-down":return((t,e,i,r,o,s)=>{const n=Pe(t,e,i,r,o,s),a=Se(t,e,i,r,o,s);return n.width<a.width?n:a})(e,i,r,o,s,n);default:return((t,e,i,r)=>({width:t,height:e,xOffset:k(i)?0:i||0,yOffset:k(r)?0:r||0}))(e,i,s,n)}},Le=10;class Be extends St{constructor(t,e){super(t,e),this.image=null,this.layout.setMeasureFunc(this.measureImage.bind(this))}get name(){return"Image"}shouldGrow(){return!!this.style.flexGrow}measureImage(t,e,i,r){const o=this.margin,s=this.page.padding,a=this.page.isAutoHeight?1/0:this.page.size.height-s.top-s.bottom-o.top-o.bottom-Le;if(!this.image)return{width:0,height:0};if(e===n.MEASURE_MODE_EXACTLY&&r===n.MEASURE_MODE_UNDEFINED){const e=t/this.ratio;return{height:Math.min(a,e)}}if(r===n.MEASURE_MODE_EXACTLY&&(e===n.MEASURE_MODE_AT_MOST||e===n.MEASURE_MODE_UNDEFINED))return{width:Math.min(i*this.ratio,t)};if(e===n.MEASURE_MODE_EXACTLY&&r===n.MEASURE_MODE_AT_MOST){const e=t/this.ratio;return{height:Math.min(i,a,e)}}return e===n.MEASURE_MODE_AT_MOST&&r===n.MEASURE_MODE_AT_MOST?this.ratio>1?{width:t,height:Math.min(t/this.ratio,i)}:{width:Math.min(i*this.ratio,t),height:i}:{height:i,width:t}}get ratio(){return this.image.data?this.image.width/this.image.height:1}get src(){const t=this.props.src||this.props.source;return"string"==typeof t?{uri:t}:t}async fetch(){const{cache:t,safePath:e,allowDangerousPaths:i}=this.props;if(this.src)try{this.image=await le(this.src,{cache:t,safePath:e,allowDangerousPaths:i})}catch(t){this.image={width:0,height:0},console.warn(t.message)}else Et(!1,'Image should receive either a "src" or "source" prop')}clone(){const t=super.clone();return t.image=this.image,t}async onAppendDynamically(){await this.fetch()}renderImage(){const t=this.padding,{left:e,top:i}=this.getAbsoluteLayout(),{opacity:r,objectPositionX:o,objectPositionY:s}=this.style;if(this.root.instance.save(),this.clip(),this.image.data){const{width:n,height:a,xOffset:h,yOffset:l}=Ae(this.style.objectFit,this.width-t.left-t.right,this.height-t.top-t.bottom,this.image.width,this.image.height,o,s);0!==n&&0!==a?this.root.instance.fillOpacity(r).image(this.image.data,e+t.left+h,i+t.top+l,{width:n,height:a}):Et(!1,`Image with src '${this.props.src}' skipped due to invalid dimensions`)}this.root.instance.restore()}async render(){this.root.instance.save(),this.applyTransformations(),this.drawBackgroundColor(),this.renderImage(),this.drawBorders(),this.props.debug&&this.debug(),this.root.instance.restore()}}Be.defaultProps={wrap:!1,cache:!0,style:{}};class Oe{constructor(t,e){this.root=t,this.style={},this.props=e,this.children=[],this.subpages=[]}get name(){return"Document"}appendChild(t){t.parent=this,this.children.push(t)}removeChild(t){const e=this.children.indexOf(t);-1!==e&&(t.parent=null,this.children.splice(e,1)),t.cleanup()}addMetaData(){const{title:t,author:e,subject:i,keywords:r,creator:o,producer:s}=this.props;t&&(this.root.instance.info.Title=