UNPKG

@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 63.8 kB
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var fs=_interopDefault(require("fs")),BlobStream=_interopDefault(require("blob-stream")),ReactFiberReconciler=_interopDefault(require("react-reconciler")),PDFDocument=require("@react-pdf/pdfkit"),PDFDocument__default=_interopDefault(PDFDocument),react=require("react"),Yoga=_interopDefault(require("yoga-layout-prebuilt")),ramda=require("ramda"),matchMedia=_interopDefault(require("media-engine")),PDFRenderer$1=_interopDefault(require("@react-pdf/textkit/renderers/pdf")),AttributedString=_interopDefault(require("@react-pdf/textkit/attributedString")),isUrl=_interopDefault(require("is-url")),fontkit=_interopDefault(require("@react-pdf/fontkit")),fetch=_interopDefault(require("cross-fetch")),layoutEngine=_interopDefault(require("@react-pdf/textkit/layout")),linebreaker=_interopDefault(require("@react-pdf/textkit/engines/linebreaker")),justification=_interopDefault(require("@react-pdf/textkit/engines/justification")),textDecoration=_interopDefault(require("@react-pdf/textkit/engines/textDecoration")),scriptItemizer=_interopDefault(require("@react-pdf/textkit/engines/scriptItemizer")),wordHyphenation=_interopDefault(require("@react-pdf/textkit/engines/wordHyphenation")),emojiRegex=_interopDefault(require("emoji-regex")),url=_interopDefault(require("url")),path=_interopDefault(require("path")),PNG=_interopDefault(require("@react-pdf/png-js")),wrapPages=_interopDefault(require("page-wrapping"));class Root{constructor(){this.isDirty=!1,this.document=null,this.instance=null}get name(){return"Root"}appendChild(t){this.document=t}removeChild(){this.document.cleanup(),this.document=null}markDirty(){this.isDirty=!0}cleanup(){this.document.cleanup()}finish(){this.document.finish()}async render(){this.instance=new PDFDocument__default({autoFirstPage:!1}),await this.document.render(),this.cleanup(),this.isDirty=!1}}const upperFirst=t=>t.charAt(0).toUpperCase()+t.slice(1),isPercent=t=>/((-)?\d+\.?\d*)%/g.exec(t),matchPercent=t=>{const e=isPercent(t);if(e){const t=parseFloat(e[1],10),r=t/100;return{value:t,percent:r,absValue:Math.abs(t),absPercent:Math.abs(r)}}return null};class Node{constructor(){this.parent=null,this.children=[],this.computed=!1,this.layout=Yoga.Node.createDefault()}appendChild(t){t&&(t.parent=this,this.children.push(t),this.layout.insertChild(t.layout,this.layout.getChildCount()))}appendChildBefore(t,e){const r=this.children.indexOf(e);-1!==r&&t&&(t.parent=this,this.children.splice(r,0,t),this.layout.insertChild(t.layout,r))}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 r=`set${upperFirst(t)}`,i=`${r}Percent`,o=matchPercent(e);o?this.layout[i](o.value):this.layout[r](e)}setPosition(t,e){const r=matchPercent(e);r?this.layout.setPositionPercent(t,r.value):this.layout.setPosition(t,e)}setPadding(t,e){const r=matchPercent(e);r?this.layout.setPaddingPercent(t,r.value):this.layout.setPadding(t,e)}setMargin(t,e){const r=matchPercent(e);r?this.layout.setMarginPercent(t,r.value):this.layout.setMargin(t,e)}setBorder(t,e){if(matchPercent(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(),Yoga.Node.destroy(this.layout)}get position(){return this.layout.getPositionType()===Yoga.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(Yoga.EDGE_TOP)||0}get paddingRight(){return this.layout.getComputedPadding(Yoga.EDGE_RIGHT)||0}get paddingBottom(){return this.layout.getComputedPadding(Yoga.EDGE_BOTTOM)||0}get paddingLeft(){return this.layout.getComputedPadding(Yoga.EDGE_LEFT)||0}get marginTop(){return this.layout.getComputedMargin(Yoga.EDGE_TOP)||0}get marginRight(){return this.layout.getComputedMargin(Yoga.EDGE_RIGHT)||0}get marginBottom(){return this.layout.getComputedMargin(Yoga.EDGE_BOTTOM)||0}get marginLeft(){return this.layout.getComputedMargin(Yoga.EDGE_LEFT)||0}get borderTopWidth(){return this.layout.getComputedBorder(Yoga.EDGE_TOP)||0}get borderRightWidth(){return this.layout.getComputedBorder(Yoga.EDGE_RIGHT)||0}get borderBottomWidth(){return this.layout.getComputedBorder(Yoga.EDGE_BOTTOM)||0}get borderLeftWidth(){return this.layout.getComputedBorder(Yoga.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?Yoga.POSITION_TYPE_ABSOLUTE:Yoga.POSITION_TYPE_RELATIVE)}set top(t){this.setPosition(Yoga.EDGE_TOP,t)}set left(t){this.setPosition(Yoga.EDGE_LEFT,t)}set right(t){this.setPosition(Yoga.EDGE_RIGHT,t)}set bottom(t){this.setPosition(Yoga.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(Yoga.EDGE_TOP,t)}set paddingRight(t){this.setPadding(Yoga.EDGE_RIGHT,t)}set paddingBottom(t){this.setPadding(Yoga.EDGE_BOTTOM,t)}set paddingLeft(t){this.setPadding(Yoga.EDGE_LEFT,t)}set marginTop(t){this.setMargin(Yoga.EDGE_TOP,t)}set marginRight(t){this.setMargin(Yoga.EDGE_RIGHT,t)}set marginBottom(t){this.setMargin(Yoga.EDGE_BOTTOM,t)}set marginLeft(t){this.setMargin(Yoga.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(Yoga.EDGE_TOP,t)}set borderRightWidth(t){this.setBorder(Yoga.EDGE_RIGHT,t)}set borderBottomWidth(t){this.setBorder(Yoga.EDGE_BOTTOM,t)}set borderLeftWidth(t){this.setBorder(Yoga.EDGE_LEFT,t)}}const yogaValue=(t,e)=>{const r=t=>"alignItems"===t||"alignContent"===t||"alignSelf"===t;switch(e){case"auto":if("alignSelf"===t)return Yoga.ALIGN_AUTO;break;case"flex":return Yoga.DISPLAY_FLEX;case"none":return Yoga.DISPLAY_NONE;case"row":return Yoga.FLEX_DIRECTION_ROW;case"row-reverse":return Yoga.FLEX_DIRECTION_ROW_REVERSE;case"column":return Yoga.FLEX_DIRECTION_COLUMN;case"column-reverse":return Yoga.FLEX_DIRECTION_COLUMN_REVERSE;case"stretch":return Yoga.ALIGN_STRETCH;case"baseline":return Yoga.ALIGN_BASELINE;case"space-around":if("justifyContent"===t)return Yoga.JUSTIFY_SPACE_AROUND;if(r(t))return Yoga.ALIGN_SPACE_AROUND;break;case"space-between":if("justifyContent"===t)return Yoga.JUSTIFY_SPACE_BETWEEN;if(r(t))return Yoga.ALIGN_SPACE_BETWEEN;break;case"around":return Yoga.JUSTIFY_SPACE_AROUND;case"between":return Yoga.JUSTIFY_SPACE_BETWEEN;case"wrap":return Yoga.WRAP_WRAP;case"wrap-reverse":return Yoga.WRAP_WRAP_REVERSE;case"nowrap":return Yoga.WRAP_NO_WRAP;case"flex-start":if("justifyContent"===t)return Yoga.JUSTIFY_FLEX_START;if(r(t))return Yoga.ALIGN_FLEX_START;break;case"flex-end":if("justifyContent"===t)return Yoga.JUSTIFY_FLEX_END;if(r(t))return Yoga.ALIGN_FLEX_END;break;case"center":if("justifyContent"===t)return Yoga.JUSTIFY_CENTER;if(r(t))return Yoga.ALIGN_CENTER;break;default:return e}},DPI=72,parseValue=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}},parseScalar=(t,e)=>{const r=parseValue(t);switch(r.unit){case"in":return 72*r.value;case"mm":return r.value*(1/25.4)*72;case"cm":return r.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 r.value*(e.height/100);case"vw":return r.value*(e.width/100);default:return r.value}},isBorderStyle=(t,e)=>t.match(/^border/)&&"string"==typeof e,matchBorderShorthand=t=>t.match(/(\d+(px|in|mm|cm|pt|vw|vh)?)\s(\S+)\s(\S+)/),processBorders=(t,e)=>{const r=matchBorderShorthand(e);if(r){if(t.match(/.Color/))return r[4];if(t.match(/.Style/))return r[3];if(t.match(/.Width/))return r[1];throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`)}return e},isBoxModelStyle=(t,e)=>t.match(/^(margin)|(padding)/)&&"string"==typeof e,matchBoxModel=t=>t.match(/\d+(px|in|mm|cm|pt|%|vw|vh)?/g),processBoxModel=(t,e)=>{const r=matchBoxModel(e);if(r){if(t.match(/.Top/))return r[0];if(t.match(/.Right/))return r[1]||r[0];if(t.match(/.Bottom/))return r[2]||r[0];if(t.match(/.Left/))return r[3]||r[1]||r[0];throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`)}return e},FONT_WEIGHTS={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},isFontWeightStyle=t=>t.match(/^fontWeight/),processFontWeight=t=>t?"number"==typeof t?t:FONT_WEIGHTS[t.toLowerCase()]:FONT_WEIGHTS.normal,isObjectPositionStyle=(t,e)=>t.match(/^objectPosition/)&&"string"==typeof e,matchObjectPosition=t=>t.match(/\d+(px|in|mm|cm|pt|%|vw|vh)?/g),processObjectPosition=(t,e)=>{const r=matchObjectPosition(e);if(r){if(t.match(/.X/))return r[0];if(t.match(/.Y/))return r[1];throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`)}return e},isTransformOriginStyle=(t,e)=>t.match(/^transformOrigin/)&&"string"==typeof e,matchTransformOrigin=t=>t.match(/(-?\d+(px|in|mm|cm|pt|%|vw|vh)?)|top|right|bottom|left|center/g),transformOffsetKeywords=t=>{switch(t){case"top":case"left":return"0%";case"right":case"bottom":return"100%";case"center":return"50%";default:return t}},processTransformOrigin=(t,e)=>{const r=matchTransformOrigin(e);if(r){let i;if(t.match(/.X/))i=r[0];else{if(!t.match(/.Y/))throw new Error(`StyleSheet: Invalid '${e}' for '${t}'`);i=r[1]||r[0]}return transformOffsetKeywords(i)}return e},hasOwnProperty=Object.prototype.hasOwnProperty,styleShorthands={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}},expandStyles=t=>{if(!t)return t;const e=Object.keys(t),r={};for(let i=0;i<e.length;i++){const o=e[i],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":r[o]=yogaValue(o,s);break;case"textAlignVertical":r.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=styleShorthands[o];for(const e in t)hasOwnProperty.call(t,e)&&(r[e]=s)}break;default:r[o]=s}}return r},transformStyles=(t,e)=>{const r=expandStyles(t),i=Object.keys(r),o={};for(let t=0;t<i.length;t++){const s=i[t],n=r[s];let a;a=isBorderStyle(s,n)?processBorders(s,n):isBoxModelStyle(s,n)?processBoxModel(s,n):isObjectPositionStyle(s,n)?processObjectPosition(s,n):isTransformOriginStyle(s,n)?processTransformOrigin(s,n):isFontWeightStyle(s)?processFontWeight(n):n,o[s]=parseScalar(a,e)}return o},create=t=>t,flatten=t=>{return Array.isArray(t)||(t=[t]),t.reduce((t,e)=>{if(e){const r=Array.isArray(e)?flatten(e):e;Object.keys(r).forEach(e=>{null!==r[e]&&void 0!==r[e]&&(t[e]=r[e])})}return t},{})},resolveMediaQueries=(t,e)=>{return Object.keys(t).reduce((r,i)=>/@media/.test(i)?{...r,...matchMedia({[i]:t[i]},e)}:{...r,[i]:t[i]},{})},resolve=(t,e)=>t?(t=flatten(t),t=resolveMediaQueries(t,e),t=transformStyles(t,e)):null,absoluteFillObject={position:"absolute",top:0,left:0,bottom:0,right:0};var StyleSheet={hairlineWidth:1,create:create,resolve:resolve,flatten:flatten,absoluteFillObject:absoluteFillObject};const Debug={debug(){const t=this.getAbsoluteLayout(),e=this.padding,r=this.margin;this.root.instance.save(),this.debugContent(t,r,e),this.debugPadding(t,r,e),this.debugMargin(t,r),this.debugText(t,r),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 r=Math.round(this.width+e.left+e.right),i=Math.round(this.height+e.top+e.bottom);this.root.instance.fontSize(4).opacity(1).fillColor("black").text(`${r} x ${i}`,t.left-e.left,Math.max(t.top-e.top-4,1))},debugContent(t,e,r){this.root.instance.fillColor("#a1c6e7").opacity(.5).rect(t.left+r.left,t.top+r.top,t.width-r.left-r.right,t.height-r.top-r.bottom).fill()},debugPadding(t,e,r){this.root.instance.fillColor("#c4deb9").opacity(.5),this.root.instance.rect(t.left+r.left,t.top,t.width-r.right-r.left,r.top).fill(),this.root.instance.rect(t.left,t.top,r.left,t.height).fill(),this.root.instance.rect(t.left+t.width-r.right,t.top,r.right,t.height).fill(),this.root.instance.rect(t.left+r.left,t.top+t.height-r.bottom,t.width-r.right-r.left,r.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()}},KAPPA=(Math.sqrt(2)-1)/3*4;function drawBorders(){const{instance:t}=this.root,e=this.getAbsoluteLayout(),{borderTopWidth:r,borderLeftWidth:i,borderRightWidth:o,borderBottomWidth:s}=this,{opacity:n,borderTopLeftRadius:a=0,borderTopRightRadius:h=0,borderBottomLeftRadius:l=0,borderBottomRightRadius:c=0,borderTopColor:d="black",borderTopStyle:g="solid",borderLeftColor:u="black",borderLeftStyle:p="solid",borderRightColor:m="black",borderRightStyle:f="solid",borderBottomColor:b="black",borderBottomStyle:y="solid"}=this.style,T={borderTopColor:d,borderTopWidth:r,borderTopStyle:g,borderLeftColor:u,borderLeftWidth:i,borderLeftStyle:p,borderRightColor:m,borderRightWidth:o,borderRightStyle:f,borderBottomColor:b,borderBottomWidth:s,borderBottomStyle:y,borderTopLeftRadius:a,borderTopRightRadius:h,borderBottomLeftRadius:l,borderBottomRightRadius:c},{width:P,height:E}=e,w=Math.min(h,.5*P,.5*E),C=Math.min(a,.5*P,.5*E),S=Math.min(c,.5*P,.5*E),A=Math.min(l,.5*P,.5*E);t.save(),t.strokeOpacity(n),r&&(t.save(),clipBorderTop(t,e,T,w,C),fillBorderTop(t,e,T,w,C),t.restore()),o&&(t.save(),clipBorderRight(t,e,T,w,S),fillBorderRight(t,e,T,w,S),t.restore()),s&&(t.save(),clipBorderBottom(t,e,T,A,S),fillBorderBottom(t,e,T,A,S),t.restore()),i&&(t.save(),clipBorderLeft(t,e,T,A,C),fillBorderLeft(t,e,T,A,C),t.restore()),t.restore()}const clipBorderTop=(t,e,r,i,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderTopWidth:l,borderRightWidth:c,borderLeftWidth:d}=r;t.moveTo(n+o,s),t.lineTo(n+a-i,s);const g=i*(1-KAPPA);t.bezierCurveTo(n+a-g,s,n+a,s+g,n+a,s+i);const u=s+Math.max(l,i);t.lineTo(n+a,u),t.lineTo(n+a-c,u);const p=Math.max(i-c,0),m=Math.max(i-l,0),f=p*(1-KAPPA),b=m*(1-KAPPA);t.bezierCurveTo(n+a-c,s+l+b,n+a-c-f,s+l,n+a-c-p,s+l),t.lineTo(n+Math.max(o,d),s+l);const y=Math.max(o-d,0),T=Math.max(o-l,0),P=y*(1-KAPPA),E=T*(1-KAPPA),w=s+Math.max(l,o);t.bezierCurveTo(n+d+P,s+l,n+d,s+l+E,n+d,w),t.lineTo(n,w),t.lineTo(n,s+o);const C=o*(1-KAPPA);if(t.bezierCurveTo(n,s+C,n+C,s,n+o,s),t.closePath(),t.clip(),c){const e=-l/c;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(d){const e=-l/d;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()}},fillBorderTop=(t,e,r,i,o)=>{const{top:s,left:n,width:a}=e,{borderTopColor:h,borderTopWidth:l,borderTopStyle:c,borderRightWidth:d,borderLeftWidth:g}=r,u=o*(1-KAPPA),p=i*(1-KAPPA);t.moveTo(n,s+Math.max(o,l)),t.bezierCurveTo(n,s+u,n+u,s,n+o,s),t.lineTo(n+a-i,s),t.bezierCurveTo(n+a-p,s,n+a,s+p,n+a,s+i),t.strokeColor(h),t.lineWidth(2*Math.max(d,l,g)),"dashed"===c?t.dash(2*l,{space:1.2*l}):"dotted"===c&&t.dash(l,{space:1.2*l}),t.stroke(),t.undash()},clipBorderRight=(t,e,r,i,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderTopWidth:l,borderRightWidth:c,borderBottomWidth:d}=r;t.moveTo(n+a,s+i),t.lineTo(n+a,s+h-o);const g=o*(1-KAPPA);t.bezierCurveTo(n+a,s+h-g,n+a-g,s+h,n+a-o,s+h);const u=n+a-Math.max(c,o);t.lineTo(u,s+h),t.lineTo(u,s+h-d);const p=Math.max(o-c,0),m=Math.max(o-d,0),f=p*(1-KAPPA),b=m*(1-KAPPA);t.bezierCurveTo(n+a-c-f,s+h-d,n+a-c,s+h-d-b,n+a-c,s+h-Math.max(o,d)),t.lineTo(n+a-c,s+Math.max(i,l));const y=Math.max(i-c,0),T=Math.max(i-l,0),P=y*(1-KAPPA),E=T*(1-KAPPA),w=n+a-Math.max(i,c);t.bezierCurveTo(n+a-c,s+l+E,n+a-c-P,s+l,w,s+l),t.lineTo(w,s),t.lineTo(n+a-i,s);const C=i*(1-KAPPA);if(t.bezierCurveTo(n+a-C,s,n+a,s+C,n+a,s+i),t.closePath(),t.clip(),l){const e=-l/c;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(d){const e=d/c;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()}},fillBorderRight=(t,e,r,i,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderRightColor:l,borderRightStyle:c,borderRightWidth:d,borderTopWidth:g,borderBottomWidth:u}=r,p=o*(1-KAPPA),m=i*(1-KAPPA);t.moveTo(n+a-i,s),t.bezierCurveTo(n+a-m,s,n+a,s+m,n+a,s+i),t.lineTo(n+a,s+h-o),t.bezierCurveTo(n+a,s+h-p,n+a-p,s+h,n+a-o,s+h),t.strokeColor(l),t.lineWidth(2*Math.max(d,g,u)),"dashed"===c?t.dash(2*d,{space:1.2*d}):"dotted"===c&&t.dash(d,{space:1.2*d}),t.stroke(),t.undash()},clipBorderBottom=(t,e,r,i,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderBottomWidth:l,borderRightWidth:c,borderLeftWidth:d}=r;t.moveTo(n+a-o,s+h),t.lineTo(n+i,s+h);const g=i*(1-KAPPA);t.bezierCurveTo(n+g,s+h,n,s+h-g,n,s+h-i);const u=s+h-Math.max(l,i);t.lineTo(n,u),t.lineTo(n+d,u);const p=Math.max(i-d,0),m=Math.max(i-l,0),f=p*(1-KAPPA),b=m*(1-KAPPA);t.bezierCurveTo(n+d,s+h-l-b,n+d+f,s+h-l,n+d+p,s+h-l),t.lineTo(n+a-Math.max(o,c),s+h-l);const y=Math.max(o-c,0),T=Math.max(o-l,0),P=y*(1-KAPPA),E=T*(1-KAPPA),w=s+h-Math.max(l,o);t.bezierCurveTo(n+a-c-P,s+h-l,n+a-c,s+h-l-E,n+a-c,w),t.lineTo(n+a,w),t.lineTo(n+a,s+h-o);const C=o*(1-KAPPA);if(t.bezierCurveTo(n+a,s+h-C,n+a-C,s+h,n+a-o,s+h),t.closePath(),t.clip(),c){const e=l/c;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(d){const e=-l/d;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()}},fillBorderBottom=(t,e,r,i,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderBottomColor:l,borderBottomStyle:c,borderBottomWidth:d,borderRightWidth:g,borderLeftWidth:u}=r,p=i*(1-KAPPA),m=o*(1-KAPPA);t.moveTo(n+a,s+h-o),t.bezierCurveTo(n+a,s+h-m,n+a-m,s+h,n+a-o,s+h),t.lineTo(n+i,s+h),t.bezierCurveTo(n+p,s+h,n,s+h-p,n,s+h-i),t.strokeColor(l),t.lineWidth(2*Math.max(d,g,u)),"dashed"===c?t.dash(2*d,{space:1.2*d}):"dotted"===c&&t.dash(d,{space:1.2*d}),t.stroke(),t.undash()},clipBorderLeft=(t,e,r,i,o)=>{const{top:s,left:n,width:a,height:h}=e,{borderTopWidth:l,borderLeftWidth:c,borderBottomWidth:d}=r;t.moveTo(n,s+h-i),t.lineTo(n,s+o);const g=o*(1-KAPPA);t.bezierCurveTo(n,s+g,n+g,s,n+o,s);const u=n+Math.max(c,o);t.lineTo(u,s),t.lineTo(u,s+l);const p=Math.max(o-c,0),m=Math.max(o-l,0),f=p*(1-KAPPA),b=m*(1-KAPPA);t.bezierCurveTo(n+c+f,s+l,n+c,s+l+b,n+c,s+Math.max(o,l)),t.lineTo(n+c,s+h-Math.max(i,d));const y=Math.max(i-c,0),T=Math.max(i-d,0),P=y*(1-KAPPA),E=T*(1-KAPPA),w=n+Math.max(i,c);t.bezierCurveTo(n+c,s+h-d-E,n+c+P,s+h-d,w,s+h-d),t.lineTo(w,s+h),t.lineTo(n+i,s+h);const C=i*(1-KAPPA);if(t.bezierCurveTo(n+C,s+h,n,s+h-C,n,s+h-i),t.closePath(),t.clip(),d){const e=-d/c;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(d){const e=-l/c;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()}},fillBorderLeft=(t,e,r,i,o)=>{const{top:s,left:n,height:a}=e,{borderLeftColor:h,borderLeftStyle:l,borderLeftWidth:c,borderTopWidth:d,borderBottomWidth:g}=r,u=i*(1-KAPPA),p=o*(1-KAPPA);t.moveTo(n+i,s+a),t.bezierCurveTo(n+u,s+a,n,s+a-u,n,s+a-i),t.lineTo(n,s+o),t.bezierCurveTo(n,s+p,n+p,s,n+o,s),t.strokeColor(h),t.lineWidth(2*Math.max(c,d,g)),"dashed"===l?t.dash(2*c,{space:1.2*c}):"dotted"===l&&t.dash(c,{space:1.2*c}),t.stroke(),t.undash()};var Borders={drawBorders:drawBorders};const KAPPA$1=(Math.sqrt(2)-1)/3*4,Clipping={clip(){const{top:t,left:e,width:r,height:i}=this.getAbsoluteLayout(),{borderTopLeftRadius:o=0,borderTopRightRadius:s=0,borderBottomRightRadius:n=0,borderBottomLeftRadius:a=0}=this.style,h=Math.min(s,.5*r,.5*i),l=h*(1-KAPPA$1);this.root.instance.moveTo(e+h,t),this.root.instance.lineTo(e+r-h,t),this.root.instance.bezierCurveTo(e+r-l,t,e+r,t+l,e+r,t+h);const c=Math.min(n,.5*r,.5*i),d=c*(1-KAPPA$1);this.root.instance.lineTo(e+r,t+i-c),this.root.instance.bezierCurveTo(e+r,t+i-d,e+r-d,t+i,e+r-c,t+i);const g=Math.min(a,.5*r,.5*i),u=g*(1-KAPPA$1);this.root.instance.lineTo(e+g,t+i),this.root.instance.bezierCurveTo(e+u,t+i,e,t+i-u,e,t+i-g);const p=Math.min(o,.5*r,.5*i),m=p*(1-KAPPA$1);this.root.instance.lineTo(e,t+p),this.root.instance.bezierCurveTo(e,t+m,e+m,t,e+p,t),this.root.instance.closePath(),this.root.instance.clip()}},getRotation=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},getTranslateX=t=>{const e=/translateX\((-?\d+\.?d*)\)/g.exec(t),r=/translate\((-?\d+\.?d*).*,\s*(-?\d+\.?d*).*\)/g.exec(t);return e&&e[1]?e[1]:r&&r[1]?r[1]:0},getTranslateY=t=>{const e=/translateY\((-?\d+\.?\d*)\)/g.exec(t),r=/translate\((-?\d+\.?\d*).*,\s*(-?\d+\.?\d*).*\)/g.exec(t);return e&&e[1]?e[1]:r&&r[2]?r[2]:0},getScaleX=t=>{const e=/scaleX\((-?\d+\.?\d*)\)/g.exec(t),r=/scale\((-?\d+\.?\d*).*,\s*(-?\d+\.?\d*).*\)/g.exec(t);return e&&e[1]?e[1]:r&&r[1]?r[1]:1},getScaleY=t=>{const e=/scaleY\((-?\d+\.?\d*)\)/g.exec(t),r=/scale\((-?\d+\.?\d*).*,\s*(-?\d+\.?\d*).*\)/g.exec(t);return e&&e[1]?e[1]:r&&r[2]?r[2]:1},getMatrix=t=>{const e=/matrix\(([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)\)/g.exec(t);return e?e.slice(1,7):null},applySingleTransformation=(t,e,r)=>{/rotate/g.test(e)?t.root.instance.rotate(getRotation(e),{origin:r}):/scaleX/g.test(e)?t.root.instance.scale(getScaleX(e),1,{origin:r}):/scaleY/g.test(e)?t.root.instance.scale(1,getScaleY(e),{origin:r}):/scale/g.test(e)?t.root.instance.scale(getScaleX(e),getScaleY(e),{origin:r}):/translateX/g.test(e)?t.root.instance.translate(getTranslateX(e),1,{origin:r}):/translateY/g.test(e)?t.root.instance.translate(1,getTranslateY(e),{origin:r}):/translate/g.test(e)?t.root.instance.translate(getTranslateX(e),getTranslateY(e),{origin:r}):/matrix/g.test(e)&&t.root.instance.transform(...getMatrix(e))},Transformations={applyTransformations(){let t;const e=/[a-zA-Z]+\([^)]+\)/g,r=this.origin,i=this.style&&this.style.transform||"";for(;null!=(t=e.exec(i));)applySingleTransformation(this,t[0],r)}};function printWarning(t,...e){let r=0;const i="Warning: "+t.replace(/%s/g,()=>e[r++]);"undefined"!=typeof console&&console.error(i);try{throw new Error(i)}catch(t){}}const __DEV__="production"!==process.env.NODE_ENV,warning=__DEV__?(t,e,...r)=>{if(void 0===e)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");t||printWarning(e,...r)}:()=>{},merge=(t,e)=>ramda.isNil(e)?t:e,deepMerge=t=>t.reduce((t,e)=>ramda.mergeDeepWith(merge,t,e),{}),isFunction=ramda.compose(ramda.equals("Function"),ramda.type),inheritedProperties=["color","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","opacity","textDecoration","lineHeight","textAlign","visibility","wordSpacing"];class Base extends Node{constructor(t,e){super(),this.root=t,this.style={},this.props=deepMerge([this.constructor.defaultProps,Base.defaultProps,e]),warning(!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:r,top:i,width:o,height:s}=this.getAbsoluteLayout(),n=matchPercent(t),a=matchPercent(e);return[r+(n?o*n.percent:t),i+(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=deepMerge([this.constructor.defaultProps,Base.defaultProps,t]),this.root.markDirty()}applyProps(){this.style=this.resolveStyles(),ramda.toPairsIn(this.style).map(([t,e])=>{this.applyStyle(t,e)}),this.children.forEach(t=>{t.applyProps&&t.applyProps()})}resolveStyles(){const{size:t,orientation:e,isAutoHeight:r}=this.page,i={orientation:e,isAutoHeight:r,width:t.width,height:t.height},o=StyleSheet.resolve(this.props.style,i);return{...this.parent?ramda.pick(inheritedProperties,this.parent.style):{},...o}}applyStyle(t,e){if(void 0===e)return;const r=`set${upperFirst(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:isFunction(this.layout[r])&&this.layout[r](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:r,top:i,width:o,height:s}=this.getAbsoluteLayout();t&&(this.root.instance.save(),this.clip(),this.root.instance.fillOpacity(e).fillColor(t).rect(r,i,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()}}Base.defaultProps={style:{borderTopLeftRadius:0,borderTopRightRadius:0,borderBottomRightRadius:0,borderBottomLeftRadius:0,transformOriginX:"50%",transformOriginY:"50%"},minPresenceAhead:0},Object.assign(Base.prototype,Debug),Object.assign(Base.prototype,Borders),Object.assign(Base.prototype,Clipping),Object.assign(Base.prototype,Transformations);const RULER_WIDTH=13,RULER_COLOR="white",RULER_FONT_SIZE=5,DEFAULT_RULER_STEPS=50,LINE_WIDTH=.5,LINE_COLOR="gray",GRID_COLOR="#ababab",range=(t,e)=>Array.from({length:Math.ceil(t/e)},(t,r)=>r*e),matchPercentage=t=>{const e=matchPercent(t);return e?100/e.value:null},Ruler={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=matchPercentage(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=matchPercentage(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=range(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=range(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 TextInstance{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 PAGE_SIZES={"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]},getPageSize=(t,e="portrait")=>{let r;if("string"==typeof t)r=PAGE_SIZES[t.toUpperCase()];else if(Array.isArray(t))r=t;else if("number"==typeof t)r=[t];else{if("object"!=typeof t||!t.width)throw new Error(`Invalid Page size: ${t}`);r=[t.width,t.height]}return"portrait"===e?{width:r[0],height:r[1]}:{width:r[1],height:r[0]}};class Page extends Base{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=getPageSize(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)&&(warning(!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 r=t===Yoga.EDGE_TOP||t===Yoga.EDGE_BOTTOM?this.size.height:this.size.width,i=matchPercent(e);i?this.layout.setPadding(t,r*i.percent):this.layout.setPadding(t,e)}async addDynamicChild(t,e){if(!e)return;const r=Array.isArray(e)?e:[e];for(let e=0;e<r.length;e++){const i=r[e],{type:o,props:s}=i;if("string"==typeof i){const e=new TextInstance(this.root,i);t.appendChild(e)}else if(o!==react.Fragment){const e=createInstance(i,this.root);await e.onAppendDynamically(),t.appendChild(e),e.applyProps(),await this.addDynamicChild(e,s.children)}else await this.addDynamicChild(t,s.children)}}async renderDynamicNodes(t,e){const r=this.children.slice(0);for(;r.length>0;){const i=r.shift();if((!e||e(i))&&i.props.render){i.removeAllChilds();const e=i.props.render(t);await this.addDynamicChild(i,e),i.fixed||(i.props.render=null)}else i.children&&r.push(...i.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()}}Page.defaultProps={size:"A4",wrap:!0,orientation:"portrait"},Object.assign(Page.prototype,Ruler);class View extends Base{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()}}View.defaultProps={wrap:!0};const fetchFont=async(t,e)=>{const r=await fetch(t,e),i=await(r.buffer?r.buffer():r.arrayBuffer());return"Buffer"===i.constructor.name?i:Buffer.from(i)};class FontSource{constructor(t,e,r,i,o){this.src=t,this.fontFamily=e,this.fontStyle=r||"normal",this.fontWeight=processFontWeight(i)||400,this.data=null,this.loading=!1,this.options=o}async load(){if(this.loading=!0,isUrl(this.src)){const{headers:t,body:e,method:r="GET"}=this.options,i=await fetchFont(this.src,{method:r,body:e,headers:t});this.data=fontkit.create(i)}else this.data=await new Promise((t,e)=>fontkit.open(this.src,(r,i)=>r?e(r):t(i)));this.loading=!1}}class Font{static create(t){return new Font(t)}constructor(t){this.family=t,this.sources=[]}register({src:t,fontWeight:e,fontStyle:r,...i}){this.sources.push(new FontSource(t,this.fontFamily,r,e,i))}resolve(t){const{fontWeight:e=400,fontStyle:r="normal"}=t,i=this.sources.filter(t=>t.fontStyle===r),o=i.find(t=>t.fontWeight===e);if(o)return o;let s;if(e>=400&&e<=500){const t=i.filter(t=>t.fontWeight<=e),r=i.filter(t=>t.fontWeight>500);s=i.filter(t=>t.fontWeight>=e&&t.fontWeight<500)[0]||t[t.length-1]||r[0]}const n=i.filter(t=>t.fontWeight<e),a=i.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 emojiSource;const registerEmojiSource=({url:t,format:e="png"})=>{emojiSource={url:t,format:e}},getEmojiSource=()=>emojiSource;var emoji={registerEmojiSource:registerEmojiSource,getEmojiSource:getEmojiSource},standardFonts=["Courier","Courier-Bold","Courier-Oblique","Helvetica","Helvetica-Bold","Helvetica-Oblique","Times-Roman","Times-Bold","Times-Italic"];let hyphenationCallback;const registerHyphenationCallback=t=>{hyphenationCallback=t},getHyphenationCallback=()=>hyphenationCallback;var hyphenation={registerHyphenationCallback:registerHyphenationCallback,getHyphenationCallback:getHyphenationCallback};let fonts={};const register=(t,e)=>{"object"==typeof t?e=t:(warning(!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:r}=e;if(fonts[r]||(fonts[r]=Font.create(r)),e.fonts)for(let t=0;t<e.fonts.length;t++)fonts[r].register({family:r,...e.fonts[t]});else fonts[r].register(e)},getRegisteredFonts=()=>fonts,getRegisteredFontFamilies=()=>Object.keys(fonts),getFont=t=>{const{fontFamily:e}=t;if(standardFonts.includes(e))return null;if(!fonts[e])throw new Error(`Font family not registered: ${e}. Please register it calling Font.register() method.`);return fonts[e].resolve(t)},load=async function(t,e){const{fontFamily:r}=t;if(standardFonts.includes(r))return;const i=getFont(t);i.data||i.loading||await i.load()},reset=function(){for(const t in fonts)fonts.hasOwnProperty(t)&&(fonts[t].data=null)},clear=function(){fonts={}};var Font$1={register:register,getRegisteredFonts:getRegisteredFonts,getRegisteredFontFamilies:getRegisteredFontFamilies,getFont:getFont,load:load,clear:clear,reset:reset,...emoji,...hyphenation};class StandardFont{constructor(t){this.name=t,this.src=PDFDocument.PDFFont.open(null,t)}layout(t){const[e,r]=this.src.encode(t);return{positions:r,stringIndices:r.map((t,e)=>e),glyphs:e.map((t,e)=>{const i=this.getGlyph(parseInt(t,16));return i.advanceWidth=r[e].advanceWidth,i})}}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 fontCache={},IGNORED_CODE_POINTS=[173],getFontSize=ramda.pathOr(12,["attributes","fontSize"]),getFallbackFont=()=>getOrCreateFont("Helvetica"),getOrCreateFont=t=>{if(fontCache[t])return fontCache[t];const e=new StandardFont(t);return fontCache[t]=e,e},shouldFallbackToFont=(t,e)=>!IGNORED_CODE_POINTS.includes(t)&&!e.hasGlyphForCodePoint(t)&&getFallbackFont().hasGlyphForCodePoint(t),fontSubstitution=()=>({string:t,runs:e})=>{let r=null,i=0,o=0;const s=[];for(const n of e){const e=getFontSize(n),a="string"==typeof n.attributes.font?getOrCreateFont(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=shouldFallbackToFont(t,a)?getFallbackFont():a;n!==r&&(r&&s.push({start:i,end:o,attributes:{font:r,scale:r?e/r.unitsPerEm:0}}),r=n,i=o),o+=h.length}}if(i<t.length){const o=getFontSize(ramda.last(e));s.push({start:i,end:t.length,attributes:{font:r,scale:r?o/r.unitsPerEm:0}})}return{string:t,runs:s}},engines={linebreaker:linebreaker,justification:justification,textDecoration:textDecoration,scriptItemizer:scriptItemizer,wordHyphenation:wordHyphenation,fontSubstitution:fontSubstitution},engine=layoutEngine(engines),PROTOCOL_REGEXP=/^([a-z]+\:(\/\/)?)/i,getURL=t=>t?"string"!=typeof t||t.match(PROTOCOL_REGEXP)?t:`http://${t}`:"";PNG.isValid=function(t){try{return!!new PNG(t)}catch(t){return!1}};const MARKERS=[65472,65473,65474,65475,65477,65478,65479,65480,65481,65482,65483,65484,65485,65486,65487];class JPEG{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,r=2;for(;r<t.length&&(e=t.readUInt16BE(r),r+=2,!MARKERS.includes(e));)r+=t.readUInt16BE(r);if(!MARKERS.includes(e))throw new Error("Invalid JPEG.");r+=3,this.height=t.readUInt16BE(r),r+=2,this.width=t.readUInt16BE(r)}}JPEG.isValid=function(t){if(!t||!Buffer.isBuffer(t)||65496!==t.readUInt16BE(0))return!1;let e,r=2;for(;r<t.length&&(e=t.readUInt16BE(r),r+=2,!MARKERS.includes(e));)r+=t.readUInt16BE(r);return!!MARKERS.includes(e)};const createCache=({limit:t=100}={})=>{let e={},r=[];return{get:t=>e[t],set:(i,o)=>{r.push(i),r.length>t&&delete e[r.shift()],e[i]=o},reset:()=>{e={},r=[]},length:()=>r.length}},IMAGE_CACHE=createCache({limit:30}),getAbsoluteLocalPath=t=>{const{protocol:e,auth:r,host:i,port:o,hostname:s,path:n}=url.parse(t),a=path.resolve(n);if(!(e&&"file:"!==e||r||i||o||s))return a},isDangerousLocalPath=(t,{safePath:e="./public"}={})=>{const r=path.resolve(e);return!path.resolve(t).startsWith(r)},fetchLocalFile=(t,{safePath:e,allowDangerousPaths:r=!1}={})=>new Promise((i,o)=>{try{0;const s=getAbsoluteLocalPath(t);if(!s)return o(new Error(`Cannot fetch non-local path: ${t}`));if(!r&&isDangerousLocalPath(s,{safePath:e}))return o(new Error(`Cannot fetch dangerous local path: ${t}`));fs.readFile(s,(t,e)=>t?o(t):i(e))}catch(t){o(t)}}),fetchRemoteFile=async(t,e)=>{const r=await fetch(t,e),i=await(r.buffer?r.buffer():r.arrayBuffer());return"Buffer"===i.constructor.name?i:Buffer.from(i)},isValidFormat=t=>{const e=t.toLowerCase();return"jpg"===e||"jpeg"===e||"png"===e},guessFormat=t=>{let e;return JPEG.isValid(t)?e="jpg":PNG.isValid(t)&&(e="png"),e},isCompatibleBase64=({uri:t})=>/^data:image\/[a-zA-Z]*;base64,[^"]*/g.test(t);function getImage(t,e){switch(e.toLowerCase()){case"jpg":case"jpeg":return new JPEG(t);case"png":return new PNG(t);default:return null}}const resolveBase64Image=({uri:t})=>{const e=/^data:image\/([a-zA-Z]*);base64,([^"]*)/g.exec(t),r=e[1],i=e[2];if(!isValidFormat(r))throw new Error(`Base64 image invalid format: ${r}`);return new Promise(t=>t(getImage(Buffer.from(i,"base64"),r)))},resolveImageFromData=t=>{if(t.data&&t.format)return new Promise(e=>e(getImage(t.data,t.format)));throw new Error(`Invalid data given for local file: ${JSON.stringify(t)}`)},resolveBufferImage=t=>{const e=guessFormat(t);if(e)return new Promise(r=>r(getImage(t,e)))},getImageFormat=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],r=255===t[0]&&216===t[1]&&255===t[2];let i="";if(e)i="png";else{if(!r)throw new Error("Not valid image extension");i="jpg"}return i},resolveImageFromUrl=async(t,e)=>{const{uri:r,body:i,headers:o,method:s="GET"}=t,n=getAbsoluteLocalPath(r)?await fetchLocalFile(r,e):await fetchRemoteFile(r,{body:i,headers:o,method:s});return getImage(n,getImageFormat(n))},resolveImage=(t,{cache:e=!0,...r}={})=>{const i=t.data?t.data.toString():t.uri;if(e&&IMAGE_CACHE.get(i))return IMAGE_CACHE.get(i);let o;if(!(o=isCompatibleBase64(t)?resolveBase64Image(t):Buffer.isBuffer(t)?resolveBufferImage(t):"object"==typeof t&&t.data?resolveImageFromData(t):resolveImageFromUrl(t,r)))throw new Error("Cannot resolve image");return e&&IMAGE_CACHE.set(i,o),o},emojis={},regex=emojiRegex(),reflect=t=>(...e)=>t(...e).then(t=>t,t=>t),makeFetchEmojiImage=()=>reflect(resolveImage),_removeNoColor=t=>"️"!==t,getCodePoints=t=>Array.from(t).filter(_removeNoColor).map(t=>t.codePointAt(0).toString(16)).join("-"),buildEmojiUrl=t=>{const{url:e,format:r}=Font$1.getEmojiSource();return`${e}${getCodePoints(t)}.${r}`},fetchEmojis=t=>{const e=Font$1.getEmojiSource();if(!e||!e.url)return[];const r=[];let i;for(;i=regex.exec(t);){const t=i[0];if(!emojis[t]||emojis[t].loading){const e=buildEmojiUrl(t);emojis[t]={loading:!0};const i=makeFetchEmojiImage();r.push(i({uri:e}).then(e=>{emojis[t].loading=!1,emojis[t].data=e.data}))}}return r},embedEmojis=t=>{const e=[];for(let r=0;r<t.length;r++){const i=t[r];let o,s=0;for(;o=regex.exec(i.string);){const t=o.index,r=o[0],n=i.attributes.fontSize,a=i.string.slice(s,t+o[0].length);emojis[r]&&emojis[r].data?e.push({string:a.replace(o,String.fromCharCode(65532)),attributes:{...i.attributes,attachment:{width:n,height:n,yOffset:Math.floor(.1*n),image:emojis[r].data}}}):e.push({string:a.replace(o,String.fromCharCode(0)),attributes:i.attributes}),s=t+r.length}s<i.string.length&&e.push({string:i.string.slice(s),attributes:i.attributes})}return e},IGNORABLE_CODEPOINTS=[8232,8233],buildSubsetForFont=t=>IGNORABLE_CODEPOINTS.reduce((e,r)=>t.hasGlyphForCodePoint&&t.hasGlyphForCodePoint(r)?e:[...e,String.fromCharCode(r)],[]),ignoreChars=t=>t.map(t=>{const e=buildSubsetForFont(t.attributes.font),r=new RegExp(e.join("|"));return{string:t.string.replace(r,""),attributes:t.attributes}}),PREPROCESSORS=[ignoreChars,embedEmojis],capitalize=t=>t.replace(/(^|\s)\S/g,t=>t.toUpperCase()),isImage=ramda.propEq("name","Image"),isTextInstance=ramda.compose(ramda.complement(ramda.isNil),ramda.prop("value")),transformText=(t,e)=>{switch(e){case"uppercase":return t.toUpperCase();case"lowercase":return t.toLowerCase();case"capitalize":return capitalize(t);default:return t}},getFragments=t=>{if(!t)return[{string:""}];let e=[];const{color:r="black",backgroundColor:i,fontFamily:o="Helvetica",fontWeight:s,fontStyle:n,fontSize:a=18,textAlign:h="left",lineHeight:l,textDecoration:c,textDecorationColor:d,textDecorationStyle:g,textTransform:u,letterSpacing:p,textIndent:m,opacity:f}=t.style,b=Font$1.getFont({fontFamily:o,fontWeight:s,fontStyle:n}),y={font:b?b.data:o,color:r,opacity:f,fontSize:a,backgroundColor:i,align:h,indent:m,link:t.src,characterSpacing:p,underlineStyle:g,underline:"underline"===c,underlineColor:d||r,strike:"line-through"===c,strikeStyle:g,strikeColor:d||r,lineHeight:l?l*a:null};t.children.forEach(t=>{isImage(t)?e.push({string:String.fromCharCode(65532),attributes:{...y,attachment:{width:t.style.width||a,height:t.style.height||a,image:t.image.data}}}):isTextInstance(t)?e.push({string:transformText(t.value,u),attributes:y}):t&&e.push(...getFragments(t))});for(const t of PREPROCESSORS)e=t(e);return e},getAttributedString=t=>AttributedString.fromFragments(getFragments(t));class Text extends Base{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:Font$1.getHyphenationCallback(),shrinkWhitespaceFactor:{before:-.5,after:-.5}},this.layout.setMeasureFunc(this.measureText.bind(this))}get name(){return"Text"}get src(){return getURL(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=>AttributedString.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 r=0;r<this.lines.length;r++){const i=this.lines[r];if(e+i.box.height>t)return r;e+=i.box.height}return this.lines.length}heightAtLineIndex(t){let e=0;for(let r=0;r<t;r++){e+=this.lines[r].box.height}return e}layoutText(t,e){if(this.attributedString=getAttributedString(this),!this.blocks||this.props.render){const r={x:0,y:0,width:t,height:e||1/0,maxLines:this.style.maxLines,truncateMode:this.style.textOverflow};this.blocks=engine(this.attributedString,r,this.layoutOptions)}const r=this.blocks.reduce((t,e)=>t+e.length,0);this.end=r+1,this.computed=!0}measureText(t,e,r,i){return e===Yoga.MEASURE_MODE_EXACTLY?(this.layoutText(t,r),{height:this.linesHeight}):e===Yoga.MEASURE_MODE_AT_MOST?(this.layoutText(t,r),{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{