sone
Version:
A declarative Canvas layout engine for JavaScript with advanced rich text support.
3 lines (2 loc) • 40.8 kB
JavaScript
"use strict";var ke=Object.create;var $=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Ce=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty;var ve=(e,t)=>{for(var i in t)$(e,i,{get:t[i],enumerable:!0})},oe=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Se(t))!Le.call(e,s)&&s!==i&&$(e,s,{get:()=>t[s],enumerable:!(r=xe(t,s))||r.enumerable});return e};var _=(e,t,i)=>(i=e!=null?ke(Ce(e)):{},oe(t||!e||!e.__esModule?$(i,"default",{value:e,enumerable:!0}):i,e)),qe=e=>oe($({},"__esModule",{value:!0}),e);var Lt={};ve(Lt,{Column:()=>Me,DEFAULT_TEXT_PROPS:()=>Rt,Path:()=>ze,Photo:()=>$e,Row:()=>He,Span:()=>Ne,Table:()=>Ie,TableCell:()=>Oe,TableRow:()=>Ge,Text:()=>De,TextDefault:()=>Ae,compile:()=>j,createLayoutNode:()=>re,drawLayoutNode:()=>Y,findFonts:()=>te,pathPropsBuilder:()=>ie,qrcode:()=>Ee,render:()=>kt});module.exports=qe(Lt);function D(e={}){let t=r=>{e.filters==null&&(e.filters=[]),e.filters.push(r)},i=(...r)=>{e.background==null&&(e.background=[]),e.background.push(...r)};return{props:e,tag(r){return e.tag=r,this},apply(r){return Object.assign(e,r),this},alignContent(r){return e.alignContent=r,this},alignItems(r){return e.alignItems=r,this},alignSelf(r){return e.alignSelf=r,this},aspectRatio(r){return e.aspectRatio=r,this},corner(r){return e.corner=r,this},borderWidth(r,s,n,a){return s==null&&n==null&&a==null?(e.borderWidth=r,this):s!=null&&n==null&&a==null?(e.borderTopWidth=r,e.borderBottomWidth=r,e.borderLeftWidth=s,e.borderRightWidth=s,this):s!=null&&n!=null&&a==null?(e.borderTopWidth=r,e.borderBottomWidth=n,e.borderLeftWidth=s,e.borderRightWidth=s,this):(e.borderTopWidth=r,e.borderBottomWidth=n,e.borderLeftWidth=a,e.borderRightWidth=s,this)},borderColor(r){return e.borderColor=r,this},margin(r,s,n,a){return s==null&&n==null&&a==null?(e.margin=r,this):s!=null&&n==null&&a==null?(e.marginTop=r,e.marginBottom=r,e.marginLeft=s,e.marginRight=s,this):s!=null&&n!=null&&a==null?(e.marginTop=r,e.marginLeft=s,e.marginRight=s,e.marginBottom=n,this):(e.marginTop=r,e.marginLeft=a,e.marginRight=s,e.marginBottom=n,this)},marginTop(r){return e.marginTop=r,this},marginBottom(r){return e.marginBottom=r,this},marginLeft(r){return e.marginLeft=r,this},marginRight(r){return e.marginRight=r,this},padding(r,s,n,a){return s==null&&n==null&&a==null?(e.padding=r,this):s!=null&&n==null&&a==null?(e.paddingTop=r,e.paddingBottom=r,e.paddingLeft=s,e.paddingRight=s,this):s!=null&&n!=null&&a==null?(e.paddingTop=r,e.paddingLeft=s,e.paddingRight=s,e.paddingBottom=n,this):(e.paddingTop=r,e.paddingLeft=a,e.paddingRight=s,e.paddingBottom=n,this)},paddingTop(r){return e.paddingTop=r,this},paddingBottom(r){return e.paddingBottom=r,this},paddingLeft(r){return e.paddingLeft=r,this},paddingRight(r){return e.paddingRight=r,this},boxSizing(r){return e.boxSizing=r,this},display(r){return e.display=r,this},flex(r){return e.flex=r,this},basis(r){return e.flexBasis=r,this},direction(r){return e.flexDirection=r,this},rowGap(r){return e.rowGap=r,this},gap(r){return e.gap=r,this},columnGap(r){return e.columnGap=r,this},grow(r){return e.flexGrow=r,this},shrink(r){return e.flexShrink=r,this},wrap(r){return e.flexWrap=r,this},justifyContent(r){return e.justifyContent=r,this},left(r){return e.left=r,this},right(r){return e.right=r,this},bottom(r){return e.bottom=r,this},top(r){return e.top=r,this},start(r){return e.start=r,this},end(r){return e.end=r,this},size(r,s){return e.width=r,e.height=s??r,this},width(r){return e.width=r,this},height(r){return e.height=r,this},maxWidth(r){return e.maxWidth=r,this},maxHeight(r){return e.maxHeight=r,this},minWidth(r){return e.minWidth=r,this},minHeight(r){return e.minHeight=r,this},position(r){return e.position=r,this},inset(r){return e.inset=r,this},overflow(r){return e.overflow=r,this},rotate(r){return e.rotation=r,this},scale(r,s){return e.scale=[r,s??r],this},translateX(r){return e.translateX=r,this},translateY(r){return e.translateY=r,this},bg(...r){return i(...r),this},background(...r){return i(...r),this},opacity(r){return e.opacity=r,this},borderRadius(...r){return e.cornerRadius=r,this},borderSmoothing(r){return e.cornerSmoothing=r,this},rounded(...r){return e.cornerRadius=r,this},cornerRadius(...r){return e.cornerRadius=r,this},cornerSmoothing(r){return e.cornerSmoothing=r,this},shadow(...r){return e.shadows==null&&(e.shadows=[]),e.shadows.push(...r),this},blur(r){return t(`blur(${r}px)`),this},brightness(r){return t(`brightness(${r})`),this},contrast(r){return t(`contrast(${r})`),this},grayscale(r){return t(`grayscale(${r})`),this},huerotate(r){return t(`hue-rotate(${r})`),this},invert(r){return t(`invert(${r})`),this},saturate(r){return t(`saturate(${r})`),this},sepia(r){return t(`sepia(${r})`),this}}}function J(e={}){return{props:e,underline(t){return e.underline=t??1,this},underlineColor(t){return e.underlineColor=t,this},overline(t){return e.overline=t??1,this},overlineColor(t){return e.overlineColor=t,this},lineThrough(t){return e.lineThrough=t??1,this},lineThroughColor(t){return e.lineThroughColor=t,this},highlight(t){return e.highlightColor=t,this},offsetY(t){return e.offsetY=t,this},color(t){return e.color=t,this},size(t){return e.size=t,this},font(...t){return e.font=t,this},style(t){return e.style=t,this},weight(t){return e.weight=t,this},letterSpacing(t){return e.letterSpacing=t,this},wordSpacing(t){return e.wordSpacing=t,this},strokeColor(t){return e.strokeColor=t,this},strokeWidth(t){return e.strokeWidth=t,this},dropShadow(...t){return e.dropShadows==null&&(e.dropShadows=[]),e.dropShadows.push(...t),this}}}function Be(e={}){return{...D(e),...J(e),nowrap(){return e.nowrap=!0,this},wrap(t){return e.nowrap=!t,this},lineHeight(t){return e.lineHeight=t,this},align(t){return e.align=t,this},indent(t){return e.indentSize=t,this},hangingIndent(t){return e.hangingIndentSize=t,this},props:e}}function Ne(e){return{type:"span",children:e,...J()}}function We(e){return{...J(e),nowrap(){return e.nowrap=!0,this},wrap(t){return e.nowrap=!t,this},lineHeight(t){return e.lineHeight=t,this},align(t){return e.align=t,this},indent(t){return e.indentSize=t,this},props:e}}function Ae(...e){return{type:"text-default",children:e,...We({})}}function De(...e){return{type:"text",children:e.filter(t=>t!=null),...Be()}}function Me(...e){return{type:"column",children:e,...D()}}function He(...e){return{type:"row",children:e,...D()}}function $e(e){let t={src:e};return{type:"photo",...D(t),scaleType(i,r){if(t.scaleType=i,typeof r=="string")switch(r){case"center":t.scaleAlignment=1/2;break;case"end":t.scaleAlignment=1;break;case"start":t.scaleAlignment=0;break}else t.scaleAlignment=r;return this},preserveAspectRatio(i=!0){return t.preserveAspectRatio=i,this},flipVertical(i=!0){return t.flipVertical=i,this},flipHorizontal(i=!0){return t.flipHorizontal=i,this},fill(i){return t.fill=i,this}}}function ie(e){return{...D(e),props:e,stroke(t){return e.stroke=t,this},strokeWidth(t){return e.strokeWidth=t,this},strokeLineCap(t){return e.strokeLineCap=t,this},strokeLineJoin(t){return e.strokeLineJoin=t,this},strokeMiterLimit(t){return e.strokeMiterLimit=t,this},strokeDashArray(...t){return e.strokeDashArray=t,this},strokeDashOffset(t){return e.strokeDashOffset=t,this},fill(t){return e.fill=t,this},fillOpacity(t){return e.fillOpacity=t,this},fillRule(t){return e.fillRule=t,this},scalePath(t){return e.scalePath=t,this}}}function ze(e){let t={d:e};return{type:"path",...ie(t),props:t}}function Ie(...e){let t={};return{type:"table",children:e,...D(t),spacing(...i){return t.spacing=i,this}}}function Ge(...e){return{type:"table-row",children:e,...D({})}}function Oe(...e){let t={};return{type:"table-cell",children:e,...D(t),colspan(i){return t.colspan=i,this},rowspan(i){return t.rowspan=i,this},props:t}}var ae=require("uqr");function Ee(e,t={}){let i=(0,ae.encode)(e,t),{pixelSize:r=10,whiteColor:s="white",blackColor:n="black"}=t,a=i.size*r,o=i.size*r,u=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${o} ${a}" width="${o}" height="${a}">`,d=[];for(let h=0;h<i.size;h++)for(let f=0;f<i.size;f++){let g=f*r,b=h*r;i.data[h][f]&&d.push(`M${g},${b}h${r}v${r}h-${r}z`)}return u+=`<rect fill="${s}" width="${o}" height="${a}"/>`,u+=`<path fill="${n}" d="${d.join("")}"/>`,u+="</svg>",Buffer.from(u)}var F=require("gradient-parser"),be=require("klona"),Te=_(require("object.pick")),ye=_(require("p-memoize")),Pe=_(require("svg-path-bounds")),X=require("yoga-layout/load");var se={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",goldenrod:"#daa520",gold:"#ffd700",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavenderblush:"#fff0f5",lavender:"#e6e6fa",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};var Ve=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,Fe=/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/,Ye=/^hsl\(\s*(\d+)\s*,\s*(\d*(?:\.\d+)?%)\s*,\s*(\d*(?:\.\d+)?%)\)$/,je=/^hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*(\d*(?:\.\d+)?)\)$/,Xe=/^#([a-f0-9]{3,4}|[a-f0-9]{4}(?:[a-f0-9]{2}){1,2})\b$/i;function z(e){return e==="transparent"||e in se?!0:Ve.test(e)||Fe.test(e)||Ye.test(e)||je.test(e)||Xe.test(e)}function _e(e){switch(e.type){case"hex":return`#${e.value}`;case"literal":return e.value;default:return`${e.type}(${e.value.join(",")})`}}function Je(e,t,i,r){let{length:s}=e;if(!s)return 1/(t-1)*i;if(s.type==="px")return Number.parseFloat(s.value);if(s.type==="%")return r?Number.parseFloat(s.value)*r/100:Number(s.value)/100}function ue(e,t){return e.reduce((i,r,s)=>{i.colors=[...i.colors,_e(r)];let n=Je(r,e.length,s,t);return i.locations=[...i.locations,n],i},{colors:[],locations:[]})}function Ue(e,t){let{width:i}=t,{colors:r,locations:s}=ue(e,i),n=s.slice(-1)[0],a=typeof n=="number"?n:Number.parseFloat(n),o=a/i,u=Math.round(i/a),d=[];for(let f=0;f<u;f++)for(let g of s)d.push(g/i+o*f);return{colors:d.map((f,g)=>r[g%r.length]),locations:d}}function Qe(e){return Math.round(e*1e4)/1e4}function Ke(e){return e*Math.PI/180}var Ze=e=>e==null?W(180):e.type==="directional"?et(e.value):W(Number(e.value));function W(e){let t=Ke(e),i=Qe(Math.abs(Math.sin(t))+Math.abs(Math.cos(t))),r={x:.5,y:.5},s=Math.sin(t-Math.PI/2)*i/2,n=Math.cos(t-Math.PI/2)*i/2;return{start:{x:r.x-n,y:r.y-s},end:{x:r.x+n,y:r.y+s}}}function et(e){switch(e){case"top":return W(0);case"right":return W(90);case"bottom":return W(180);case"left":return W(270);case"left top":return W(315);case"left bottom":return W(225);case"right top":return W(45);case"right bottom":return W(135)}}function tt(e,t){let i=[];for(let{type:r,colorStops:s,orientation:n}of e){if(r==="radial-gradient"||r==="repeating-radial-gradient")continue;let a=r==="linear-gradient"?ue(s):Ue(s,t),o=Ze(n),u={...a,...o};i.push(u)}return i}function I(e,t,i,r,s,n){let a=tt(t,{width:s,height:n}),o=[];for(let u of a){let d=e.createLinearGradient(i+u.start.x*s,r+u.start.y*n,i+u.end.x*s,r+u.end.y*n);for(let h=0;h<u.colors.length;h++){let f=u.colors[h],g=u.locations[h];g<0&&(g=0),g>1&&(g=1),d.addColorStop(g,f)}o.push(d)}return o}var H=require("yoga-layout/load");function G(e,t,i,r,s,n){let a=t.getComputedBorder(H.Edge.Left),o=t.getComputedBorder(H.Edge.Top),u=t.getComputedBorder(H.Edge.Right),d=t.getComputedBorder(H.Edge.Bottom);a===o&&o===u&&u===d&&a>0&&(e.save(),e.translate(s,n),e.strokeStyle=i.borderColor,e.lineJoin="round",e.lineWidth=a*2,e.clip(r),e.stroke(r),e.translate(-s,-n),e.restore())}var le=require("figma-squircle");function O(e,t){for(let i=0;i<e.length;i++)e[i]=Math.max(0,Math.min(e[i],t/2));return e}function E(e,t,i,r,s=0,n="round"){let a=s;a>1&&(a=1),a<0&&(a=0);let o={topLeftCornerRadius:0,topRightCornerRadius:0,bottomRightCornerRadius:0,bottomLeftCornerRadius:0};if(r.length===1&&(o.topLeftCornerRadius=r[0],o.topRightCornerRadius=r[0],o.bottomRightCornerRadius=r[0],o.bottomLeftCornerRadius=r[0]),r.length===2&&(o.topLeftCornerRadius=r[0],o.bottomRightCornerRadius=r[0],o.topRightCornerRadius=r[1],o.bottomLeftCornerRadius=r[1]),r.length>2&&(o.topLeftCornerRadius=r[0],o.topRightCornerRadius=r[1]??0,o.bottomRightCornerRadius=r[2]??0,o.bottomLeftCornerRadius=r[3]??0),n==="round"){let d=(0,le.getSvgPath)({cornerSmoothing:a,width:t,height:i,preserveSmoothing:!0,...o});return new e.Path2D(d)}let u=new e.Path2D;return u.moveTo(o.topLeftCornerRadius,0),u.lineTo(t-o.topRightCornerRadius,0),u.lineTo(t,o.topRightCornerRadius),u.lineTo(t,i-o.bottomRightCornerRadius),u.lineTo(t-o.bottomRightCornerRadius,i),u.lineTo(o.bottomLeftCornerRadius,i),u.lineTo(0,i-o.bottomLeftCornerRadius),u.lineTo(0,o.topLeftCornerRadius),u.closePath(),u}function U(e,t,i,r,s,n){let a=i.props;if(a.image==null)return;let o=a.image,u=r.getComputedWidth(),d=r.getComputedHeight(),h=i.props.scaleType??"fill",f=o.width,g=o.height,b=s,c=n,m=u,T=d,R=o.width/o.height,k=u/d,P=a.scaleAlignment??1/2;switch(h){case"cover":if(R>k){let y=o.width*d/o.height;f=o.width,g=o.height,m=y,T=d,b=s+(u-y)*P}else{let y=o.height*u/o.width;f=o.width,g=o.height,m=u,T=y,c=n+(d-y)*P}break;case"contain":R>k?(m=u,T=u/R,c=n+(d-T)*P):(T=d,m=d*R,b=s+(u-m)*P);break}t.save();let w=E(e,u,d,O(a.cornerRadius??[0],Math.min(u,d)),a.cornerSmoothing);if(t.translate(s,n),t.clip(w),t.translate(-s,-n),a.background)for(let y of a.background)typeof y=="string"&&(t.fillStyle=y,t.fillRect(s,n,u,d));let q=a.flipHorizontal??!1,B=a.flipVertical??!1;if(q||B){let y=b+m/2,x=c+T/2;t.translate(y,x),t.scale(q?-1:1,B?-1:1),t.translate(-y,-x)}t.drawImage(o,0,0,f,g,b,c,m,T),t.restore(),(a.borderWidth!=null||a.borderTopWidth!=null||a.borderLeftWidth!=null||a.borderRightWidth!=null||a.borderBottomWidth!=null)&&G(t,r,a,w,s,n)}var l=require("yoga-layout/load");function he(e,t){for(let i of Object.keys(e))switch(i){case"alignContent":t.setAlignContent(rt(e.alignContent));break;case"alignItems":t.setAlignItems(de(e.alignItems));break;case"alignSelf":t.setAlignSelf(de(e.alignSelf));break;case"aspectRatio":t.setAspectRatio(e.aspectRatio);break;case"borderBottomWidth":t.setBorder(l.Edge.Bottom,e.borderBottomWidth);break;case"borderEndWidth":t.setBorder(l.Edge.End,e.borderEndWidth);break;case"borderLeftWidth":t.setBorder(l.Edge.Left,e.borderLeftWidth);break;case"borderRightWidth":t.setBorder(l.Edge.Right,e.borderRightWidth);break;case"borderStartWidth":t.setBorder(l.Edge.Start,e.borderStartWidth);break;case"borderTopWidth":t.setBorder(l.Edge.Top,e.borderTopWidth);break;case"borderWidth":t.setBorder(l.Edge.All,e.borderWidth);break;case"borderInlineWidth":t.setBorder(l.Edge.Horizontal,e.borderInlineWidth);break;case"borderBlockWidth":t.setBorder(l.Edge.Vertical,e.borderBlockWidth);break;case"bottom":t.setPosition(l.Edge.Bottom,e.bottom);break;case"boxSizing":t.setBoxSizing(nt(e.boxSizing));break;case"direction":t.setDirection(ot(e.direction));break;case"display":t.setDisplay(it(e.display));break;case"end":t.setPosition(l.Edge.End,e.end);break;case"flex":t.setFlex(e.flex);break;case"flexBasis":t.setFlexBasis(e.flexBasis);break;case"flexDirection":t.setFlexDirection(at(e.flexDirection));break;case"rowGap":t.setGap(l.Gutter.Row,e.rowGap);break;case"gap":t.setGap(l.Gutter.All,e.gap);break;case"columnGap":t.setGap(l.Gutter.Column,e.columnGap);break;case"flexGrow":t.setFlexGrow(e.flexGrow);break;case"flexShrink":t.setFlexShrink(e.flexShrink);break;case"flexWrap":t.setFlexWrap(st(e.flexWrap));break;case"height":t.setHeight(e.height);break;case"justifyContent":t.setJustifyContent(ut(e.justifyContent));break;case"left":t.setPosition(l.Edge.Left,e.left);break;case"margin":t.setMargin(l.Edge.All,e.margin);break;case"marginBottom":t.setMargin(l.Edge.Bottom,e.marginBottom);break;case"marginEnd":t.setMargin(l.Edge.End,e.marginEnd);break;case"marginLeft":t.setMargin(l.Edge.Left,e.marginLeft);break;case"marginRight":t.setMargin(l.Edge.Right,e.marginRight);break;case"marginStart":t.setMargin(l.Edge.Start,e.marginStart);break;case"marginTop":t.setMargin(l.Edge.Top,e.marginTop);break;case"marginInline":t.setMargin(l.Edge.Horizontal,e.marginInline);break;case"marginBlock":t.setMargin(l.Edge.Vertical,e.marginBlock);break;case"maxHeight":t.setMaxHeight(e.maxHeight);break;case"maxWidth":t.setMaxWidth(e.maxWidth);break;case"minHeight":t.setMinHeight(e.minHeight);break;case"minWidth":t.setMinWidth(e.minWidth);break;case"overflow":t.setOverflow(lt(e.overflow));break;case"padding":t.setPadding(l.Edge.All,e.padding);break;case"paddingBottom":t.setPadding(l.Edge.Bottom,e.paddingBottom);break;case"paddingEnd":t.setPadding(l.Edge.End,e.paddingEnd);break;case"paddingLeft":t.setPadding(l.Edge.Left,e.paddingLeft);break;case"paddingRight":t.setPadding(l.Edge.Right,e.paddingRight);break;case"paddingStart":t.setPadding(l.Edge.Start,e.paddingStart);break;case"paddingTop":t.setPadding(l.Edge.Top,e.paddingTop);break;case"paddingInline":t.setPadding(l.Edge.Horizontal,e.paddingInline);break;case"paddingBlock":t.setPadding(l.Edge.Vertical,e.paddingBlock);break;case"position":t.setPositionType(dt(e.position));break;case"right":t.setPosition(l.Edge.Right,e.right);break;case"start":t.setPosition(l.Edge.Start,e.start);break;case"top":t.setPosition(l.Edge.Top,e.top);break;case"insetInline":t.setPosition(l.Edge.Horizontal,e.insetInline);break;case"insetBlock":t.setPosition(l.Edge.Vertical,e.insetBlock);break;case"inset":t.setPosition(l.Edge.All,e.inset);break;case"width":t.setWidth(e.width);break}return t}function rt(e){switch(e){case"flex-start":return l.Align.FlexStart;case"flex-end":return l.Align.FlexEnd;case"center":return l.Align.Center;case"stretch":return l.Align.Stretch;case"space-between":return l.Align.SpaceBetween;case"space-around":return l.Align.SpaceAround;case"space-evenly":return l.Align.SpaceEvenly}}function de(e){switch(e){case"flex-start":return l.Align.FlexStart;case"flex-end":return l.Align.FlexEnd;case"center":return l.Align.Center;case"stretch":return l.Align.Stretch;case"baseline":return l.Align.Baseline}}function nt(e){switch(e){case"border-box":return l.BoxSizing.BorderBox;case"content-box":return l.BoxSizing.ContentBox}}function ot(e){switch(e){case"ltr":return l.Direction.LTR;case"rtl":return l.Direction.RTL}}function it(e){switch(e){case"none":return l.Display.None;case"flex":return l.Display.Flex;case"contents":return l.Display.Contents}}function at(e){switch(e){case"row":return l.FlexDirection.Row;case"column":return l.FlexDirection.Column;case"row-reverse":return l.FlexDirection.RowReverse;case"column-reverse":return l.FlexDirection.ColumnReverse}}function st(e){switch(e){case"wrap":return l.Wrap.Wrap;case"nowrap":return l.Wrap.NoWrap;case"wrap-reverse":return l.Wrap.WrapReverse}}function ut(e){switch(e){case"flex-start":return l.Justify.FlexStart;case"flex-end":return l.Justify.FlexEnd;case"center":return l.Justify.Center;case"space-between":return l.Justify.SpaceBetween;case"space-around":return l.Justify.SpaceAround;case"space-evenly":return l.Justify.SpaceEvenly}}function lt(e){switch(e){case"visible":return l.Overflow.Visible;case"hidden":return l.Overflow.Hidden;case"scroll":return l.Overflow.Scroll}}function dt(e){switch(e){case"absolute":return l.PositionType.Absolute;case"relative":return l.PositionType.Relative;case"static":return l.PositionType.Static}}var ht=/,(?![^(]*\))/,ft=/\s(?![^(]*\))/,pt=/^[0-9]+[a-zA-Z%]+?$/;function gt(e){let t=e.split(ft),i=t.includes("inset"),r=t.slice(-1)[0],s=ct(r)?void 0:r,n=t.filter(h=>h!=="inset").filter(h=>h!==s).map(mt),[a,o,u,d]=n;return{inset:i,offsetX:Number(a),offsetY:Number(o),blurRadius:Number(u),spreadRadius:d==null?void 0:Number(d),color:s}}function ct(e){return e==="0"||pt.test(e)}function mt(e){if(!/px$/.test(e)&&e!=="0")return e;let t=Number.parseFloat(e);return Number.isNaN(t)?e:t}var V=e=>e.split(ht).map(t=>t.trim()).map(gt);var pe=require("dequal"),ge=require("klona"),A=require("yoga-layout/load");function bt(e){let t=e.font!=null?e.font?.join(", "):"",i=e.size??"",r=e.weight??"";return`${e.style??""} ${r} ${i}px ${t}`.trim()}function Q(e,t){e.font=bt(t),t.letterSpacing!=null&&(e.letterSpacing=`${t.letterSpacing}px`),t.wordSpacing!=null&&(e.wordSpacing=`${t.wordSpacing}px`),t.color!=null&&typeof t.color=="string"&&(e.fillStyle=t.color)}function fe(e,t){let i=[],r=e.indexOf(t);for(;r!==-1;)i.push(r),r=e.indexOf(t,r+1);return i}var Tt=/^\s+$/;function K(e){return e.length===0?!1:Tt.test(e)}function yt(e,t,i,r,s){let n=r.lineHeight==null||Number.isNaN(r.lineHeight)?1:r.lineHeight,a=[],o={baseline:0,height:0,width:r.indentSize??0,segments:[],spacesCount:0};a.push(o);for(let g=0;g<e.length;g++){let b=e[g],c=typeof b=="string"?r:b.props,m=typeof b=="string"?b:b.children,T=t[g]||[];if(T.length===0){let k=s(m,c),P=k.width,w=k.fontBoundingBoxAscent+k.fontBoundingBoxDescent;if(o.width+P>i&&o.segments.length>0){o={baseline:0,height:0,width:0,segments:[],spacesCount:0},a.push(o);let B=m.trimStart();if(B!==m){let y=s(B,c);P=y.width,w=y.fontBoundingBoxAscent+y.fontBoundingBoxDescent;let x={metrics:y,props:c,text:B,width:P,height:w};o.segments.push(x),o.width+=P,o.height=Math.max(o.height,w),o.baseline=Math.max(o.baseline,y.fontBoundingBoxAscent);continue}}let q={metrics:k,props:c,text:m,width:P,height:w};o.segments.push(q),o.width+=P,o.height=Math.max(o.height,w),o.baseline=Math.max(o.baseline,k.fontBoundingBoxAscent);continue}let R=0;for(let k=0;k<T.length;k++){let P=T[k],w=m.substring(R,P);if(w.length===0){R=P;continue}let q=s(w,c),B=q.width,y=q.fontBoundingBoxAscent+q.fontBoundingBoxDescent;if(o.width+B>i&&o.segments.length>0){if(o.segments.length>0){let S=o.segments[o.segments.length-1],C=S.text.trimEnd();if(C!==S.text&&C.length>0){let L=s(C,S.props),N=L.width,M=L.fontBoundingBoxAscent+L.fontBoundingBoxDescent;S.text=C,S.metrics=L,S.width=N,S.height=M,o.width=o.segments.reduce((ne,v)=>ne+v.width,0)}}o={baseline:0,height:0,width:r.hangingIndentSize??0,segments:[],spacesCount:0},a.push(o);let p=w.trimStart();if(p!==w){if(p.length===0){R=P;continue}let S=s(p,c),C=S.width,L=S.fontBoundingBoxAscent+S.fontBoundingBoxDescent,N={metrics:S,props:c,text:p,width:C,height:L};o.segments.push(N),o.width+=C,o.height=Math.max(o.height,L),o.baseline=Math.max(o.baseline,S.fontBoundingBoxAscent),R=P;continue}}let x={metrics:q,props:c,text:w,width:B,height:y};o.segments.push(x),o.width+=B,o.height=Math.max(o.height,y),o.baseline=Math.max(o.baseline,q.fontBoundingBoxAscent),R=P}if(R<m.length){let k=m.substring(R),P=s(k,c),w=P.width,q=P.fontBoundingBoxAscent+P.fontBoundingBoxDescent;if(o.width+w>i&&o.segments.length>0){if(o.segments.length>0){let x=o.segments[o.segments.length-1],p=x.text.trimEnd();if(p!==x.text&&p.length>0){let S=s(p,x.props),C=S.width,L=S.fontBoundingBoxAscent+S.fontBoundingBoxDescent;x.text=p,x.metrics=S,x.width=C,x.height=L,o.width=o.segments.reduce((N,M)=>N+M.width,0)}}o={baseline:0,height:0,width:0,segments:[],spacesCount:0},a.push(o);let y=k.trimStart();if(y!==k){if(y.length===0)continue;let x=s(y,c),p=x.width,S=x.fontBoundingBoxAscent+x.fontBoundingBoxDescent,C={metrics:x,props:c,text:y,width:p,height:S};o.segments.push(C),o.width+=p,o.height=Math.max(o.height,S),o.baseline=Math.max(o.baseline,x.fontBoundingBoxAscent);continue}}let B={metrics:P,props:c,text:k,width:w,height:q};o.segments.push(B),o.width+=w,o.height=Math.max(o.height,q),o.baseline=Math.max(o.baseline,P.fontBoundingBoxAscent)}}for(let g of a){let b=[];for(let c=0;c<g.segments.length;c++){let m=g.segments[c];if(K(m.text)&&(c===g.segments.length-1||c===0)){g.width-=m.width;continue}b.push(m)}g.segments=b}let u=0;for(let g of a){g.baseline*=n,g.height*=n;let b=0,c=Number.POSITIVE_INFINITY;for(let m of g.segments){let T=m.props.offsetY??0;T>b&&(b=T),T<c&&(c=T)}if(g.baseline-=c,g.height-=c,g.height+=b,u<a.length-1)for(let m of g.segments){let T=m.text.match(/[ ]/);T&&(g.spacesCount+=T.length)}u++}let d=0,h=0;for(let g of a)d+=g.height,h=Math.max(h,g.width);let f=0;if(a.length>0&&r.lineHeight!=null&&!Number.isNaN(r.lineHeight)){let g=Math.max(0,r.lineHeight-1);for(let b of a[0].segments){let c=b.metrics,m=-((c.fontBoundingBoxAscent-c.fontBoundingBoxDescent)/2)*g;m<f&&(f=m)}}return{width:h,height:d,lines:a,offsetY:f}}function Pt(e,t){let i=[[]];for(let s of e){let n=typeof s=="string"?s:s.children,a=fe(n,`
`);if(a.length===0){i[i.length-1].push(s);continue}a.length>0&&a[a.length-1]!==n.length&&a.push(n.length);let o=0;for(let u=0;u<a.length;u++){let d=a[u],h=n.slice(o,d);if(typeof s=="string")i[i.length-1].push(h);else{let f=(0,ge.klona)(s);f.children=h,i[i.length-1].push(f)}u<a.length-1&&i.push([]),o=d+1}}let r=[];for(let s of i){let n=[];for(let a of s){let o=typeof a=="string"?a:a.children;n.push(Array.from(t(o)))}r.push(n)}return[i,r]}function ce(e,t,i,r,s){let[n,a]=Pt(e,s),o=[];for(let u=0;u<n.length;u++){let d=a[u],h=n[u],f=yt(h,d,t,i,r);for(let g of f.lines){let b=[[]];for(let m of g.segments){let T=b[b.length-1];if(T.length>0){let R=T[T.length-1];if(i.align==="justify"&&K(m.text)){b.push([m]),b.push([]);continue}if(!(0,pe.dequal)(R.props,m.props)){b.push([m]);continue}}T.push(m)}let c=[];for(let m of b){if(m.length===0)continue;if(m.length===1){c.push(m[0]);continue}let T=m.slice(1).reduce((R,k)=>({metrics:R.metrics,text:R.text+k.text,height:Math.max(R.height,k.height),width:R.width+k.width,props:R.props}),m[0]);c.push(T)}g.segments=c}o.push({paragraph:f})}return o}function me(e,t,i,r,s,n){let{props:a}=i,{blocks:o}=a;if(o==null)return;let u=r.getComputedBorder(A.Edge.Left)+r.getComputedBorder(A.Edge.Right)+r.getComputedPadding(A.Edge.Left)+r.getComputedPadding(A.Edge.Right),d=0;for(let{paragraph:h}of o){h.width=Math.max(r.getComputedWidth(),h.width)-u;let f=a.boxSizing==="content-box"?r.getComputedPadding(A.Edge.Left):0,g=a.boxSizing==="content-box"?r.getComputedPadding(A.Edge.Top):0,b=r.getComputedBorder(A.Edge.Left),c=r.getComputedBorder(A.Edge.Top),m=f+b,T=g+c,R=a.align;Q(t,a);let k=h.offsetY+d;d+=h.height;for(let P=0;P<h.lines.length;P++){let w=h.lines[P],q=h.width-w.width,B=R==="justify"&&q>0&&w.spacesCount>0?q/w.spacesCount:0,y=0;switch(R){case"center":y=(h.width-w.width)/2;break;case"right":y=h.width-w.width;break;case"left":case"justify":P===0&&a.indentSize!=null&&(y+=a.indentSize),P>0&&a.hangingIndentSize!=null&&(y+=a.hangingIndentSize);break}for(let x=0;x<w.segments.length;x++){let p=w.segments[x],S=p.props.offsetY??0,C=p.width;R==="justify"&&/[ ]/.test(p.text)&&(C+=B);let L=s+m+y,N=n+w.baseline+T+k+S;if(typeof p.props.underline=="number"&&p.props.underline!==0){typeof p.props.color=="string"&&(t.fillStyle=p.props.underlineColor??p.props.color);let v=p.height*p.props.underline/18;t.fillRect(L,N+v,C,v)}if(typeof p.props.overline=="number"&&p.props.overline!==0){typeof p.props.color=="string"&&(t.fillStyle=p.props.overlineColor??p.props.color);let v=p.height*p.props.overline/18;t.fillRect(L,N-p.metrics.fontBoundingBoxAscent,C,v)}let M=N-p.height+p.metrics.fontBoundingBoxDescent;if(p.props.highlightColor!=null&&(t.fillStyle=p.props.highlightColor,t.fillRect(L,M,C,p.height)),Q(t,p.props),p.props.dropShadows)for(let v of p.props.dropShadows)typeof v!="string"&&(t.save(),t.shadowOffsetX=v.offsetX,t.shadowOffsetY=v.offsetY,t.shadowBlur=v.blurRadius,v.color&&(t.shadowColor=v.color,t.fillStyle=v.color),t.fillText(p.text,L,N),t.restore());if(t.save(),p.props.strokeColor!=null&&p.props.strokeWidth!=null&&p.props.strokeWidth!==0&&(t.strokeStyle=p.props.strokeColor,t.lineJoin="round",t.miterLimit=2,t.lineWidth=p.props.strokeWidth,t.strokeText(p.text,L,N)),typeof p.props.color!="string"&&Array.isArray(p.props.color))for(let v of p.props.color){let[Re]=I(t,[v],s,n,p.width,p.height);t.fillStyle=Re}if(t.fillText(p.text,L,N),t.restore(),typeof p.props.lineThrough=="number"&&p.props.lineThrough!==0){typeof p.props.color=="string"&&(t.fillStyle=p.props.lineThroughColor??p.props.color);let v=p.height*p.props.lineThrough/18;t.fillRect(L,N-(p.metrics.fontBoundingBoxAscent-p.metrics.fontBoundingBoxDescent)/2,C,v)}e.debug().text&&(t.save(),t.lineWidth=e.dpr()*2,t.strokeStyle="cyan",t.strokeRect(L,M,C,p.height),t.restore()),y+=C}k+=w.height}}}var wt=(0,X.loadYoga)(),Rt={size:11,color:"black",font:["sans-serif"],style:"normal",weight:400,letterSpacing:0,nowrap:!1,lineHeight:Number.NaN,indentSize:0,hangingIndentSize:0,align:"left",strokeColor:"black",strokeWidth:0,wordSpacing:0,blocks:[],offsetY:0,underline:0,underlineColor:null,overline:0,overlineColor:null,lineThrough:0,lineThroughColor:null,highlightColor:null,dropShadows:[]};function Z(e){return Object.fromEntries(Object.entries(e).filter(([t,i])=>i!=null))}function ee(e,t){let i=e.props,r=t.width/t.height;i.preserveAspectRatio&&(typeof i.width=="number"&&typeof i.height!="number"&&(i.height=Math.round(i.width/r)),typeof i.height=="number"&&typeof i.width!="number"&&(i.width=Math.round(i.height*r))),i.width==null&&(i.width=t.width),i.height==null&&(i.height=t.height),i.image=t}async function j(e,{defaultTextProps:t,loadImage:i,breakIterator:r}){if(e==null)return;if(e.type!=="text-default"){if(e.props.shadows!=null&&Array.isArray(e.props.shadows)){let n=[];for(let a of e.props.shadows)typeof a=="string"?n.push(...V(a)):n.push(a);e.props.shadows=n}if(e.props.background!=null&&Array.isArray(e.props.background)){let n=[];for(let a of e.props.background){if(typeof a=="string"){if(!z(a)){let o=(0,F.parse)(a);n.push(...o);continue}}else a.type==="photo"&&(typeof a.props.src=="string"||Buffer.isBuffer(a.props.src))&&ee(a,await i(a.props.src));n.push(a)}e.props.background=n}}if(e.type==="table-row"&&e.props.flexDirection==null&&(e.props.flexDirection="row"),e.type==="text"){if(e.props.flexShrink==null&&(e.props.flexShrink=1),e.props.boxSizing==null&&(e.props.boxSizing="content-box"),e.props={...t,...Z(e.props)},e.props.dropShadows!=null&&Array.isArray(e.props.dropShadows)){let n=[];for(let a of e.props.dropShadows)typeof a=="string"?n.push(...V(a)):n.push(a);e.props.dropShadows=n}return typeof e.props.color=="string"&&(z(e.props.color)||(e.props.color=(0,F.parse)(e.props.color))),e.children.map(n=>{if(typeof n=="string")return n;let a=(0,Te.default)(e.props,["size","color","font","style","weight","letterSpacing","wordSpacing","strokeColor","strokeWidth","underline","underlineColor","overline","overlineColor","lineThrough","lineThroughColor","highlightColor","dropShadows"]);if(n.props={...Z(a),...n.props},n.props.dropShadows!=null&&Array.isArray(n.props.dropShadows)){let o=[];for(let u of n.props.dropShadows)typeof u=="string"?o.push(...V(u)):o.push(u);n.props.dropShadows=o}return typeof n.props.color=="string"&&(z(n.props.color)||(n.props.color=(0,F.parse)(n.props.color))),n}),e}if(e.type==="photo")return typeof e.props.src=="string"||Buffer.isBuffer(e.props.src)?(ee(e,await i(e.props.src)),e):void 0;if(e.type==="row"&&e.props.flexDirection==null&&(e.props.flexDirection="row"),e.type!=="text-default"&&e.props.background!=null){for(let n of e.props.background)if(typeof n!="string"&&n.type==="photo"&&(typeof n.props.src=="string"||Buffer.isBuffer(n.props.src)))return ee(n,await i(n.props.src)),e}if(e.type==="path")return e.props.d&&(e.props.bounds=(0,Pe.default)(e.props.d)),e;let s=[];for(let n of e.children)if(n!=null){if(n.type==="text-default"){let a={...t,...Z(n.props)};for(let o of n.children)o!=null&&s.push(await j(o,{defaultTextProps:a,loadImage:i,breakIterator:r}));continue}s.push(await j(n,{defaultTextProps:t,loadImage:i,breakIterator:r}))}if(e.children=s.filter(n=>n!=null),e.type==="table"&&e.props.spacing!=null&&Array.isArray(e.props.spacing)){let[n,a]=e.props.spacing;a=a??n;for(let o of e.children)if(o!=null)for(let u of o.children){if(u==null)return;u.type!=="text-default"&&(u.props.paddingLeft==null&&(u.props.paddingLeft=n),u.props.paddingRight==null&&(u.props.paddingRight=n),u.props.paddingTop==null&&(u.props.paddingTop=a),u.props.paddingBottom==null&&(u.props.paddingBottom=a))}}return e}function te(e){if(e==null||e.type==="photo"||e.type==="path")return;if(e.type==="text"){let i=new Set;for(let r of e.children)if(typeof r!="string"&&r.props.font!=null)for(let s of r.props.font)i.add(s);if(e.props.font!=null)for(let r of e.props.font)i.add(r);return i}let t=new Set;for(let i of e.children){let r=te(i);if(r!=null)for(let s of r)t.add(s)}return t}function re(e,t,i){if(e==null)return;if(e.type==="text-default")throw new Error("The layout includes TextDefaut node which is illegal!");let r=i.Node.create();if(he(e.props,r),e.type==="photo")return r;if(e.type==="text"){let s=(n,a)=>{let{props:o,children:u}=e,d=ce(u,n,o,t.measureText,t.breakIterator);e.props.blocks=d;let h=0,f=0;for(let{paragraph:g}of d)g.width>h&&(h=g.width),f+=g.height;return a===X.MeasureMode.AtMost&&(h=Math.min(n,h)),{width:h,height:f}};return r.setMeasureFunc(s),r}if(e.type==="path"){if(e.props.bounds!=null){let[s,n,a,o]=e.props.bounds,u=e.props.scalePath??1;if(e.props.width==null){let d=a-s;r.setWidth(d*u)}if(e.props.height==null){let d=o-n;r.setHeight(d*u)}}return r}for(let s of e.children){if(s==null)continue;let n=re(s,t,i);n!=null&&r.insertChild(n,r.getChildCount())}if(e.type==="table"){let s=[];for(let n=0;n<r.getChildCount();n++){let a=0;for(let o=0;o<r.getChild(n).getChildCount();o++){s.length-1<o&&s.push(0);let u=r.getChild(n).getChild(o);u.calculateLayout(void 0,void 0);let d=u.getComputedWidth(),h=u.getComputedHeight();a<h&&(a=h),s[o]<d&&(s[o]=d)}for(let o=0;o<r.getChild(n).getChildCount();o++)r.getChild(n).getChild(o).setMinHeight(a)}for(let n=0;n<r.getChildCount();n++)for(let a=0;a<r.getChild(n).getChildCount();a++)r.getChild(n).getChild(a).setMinWidth(s[a])}return r}async function kt(e,t,i){let r=await wt,s=te(e);if(s!=null)for(let f of s)f!=="serif"&&f!=="sans-serif"&&f!=="monospace"&&(t.hasFont(f)||console.warn(`${JSON.stringify(f)} font has not been registered!`));let n=i==null||i.cache==null?new Map:i.cache,a=await j((0,be.klona)(e),{defaultTextProps:t.getDefaultTextProps(),loadImage:(0,ye.default)(t.loadImage,{cache:n}),breakIterator:t.breakIterator});(i==null||i.cache==null)&&n.clear();let o=re(a,t,r);if(o==null)throw new Error("Unable to create canvas!");o.calculateLayout(i?.width,i?.height);let u=t.createCanvas(o.getComputedWidth(),o.getComputedHeight()),d=u.getContext("2d");i?.background&&(d.fillStyle=i.background,d.fillRect(0,0,u.width,u.height));function h(f,g,b,c){if(f!=null)try{if(d.save(),f.type!=="text-default"&&we(d,f,g,b,c),f.type==="text-default")return;if(f.type==="text"){Y(t,d,f,g,b,c),me(t,d,f,g,b,c);return}if(f.type==="photo"){U(t,d,f,g,b,c);return}if(f.type==="path"){Y(t,d,f,g,b,c),St(t,d,f,b,c);return}Y(t,d,f,g,b,c);for(let m=0;m<f.children.length;m++){let T=g.getChild(m),R=f.children[m];h(R,T,b+T.getComputedLeft(),c+T.getComputedTop())}f.type==="table"&&Ct(t,d,f,g,b,c)}finally{d.restore(),t.debug().layout&&xt(t,d,f,g,b,c)}}return h(a,o,0,0),o.freeRecursive(),u}function Y(e,t,i,r,s,n){let a=r.getComputedWidth(),o=r.getComputedHeight(),u=i.props,d=E(e,a,o,O(u.cornerRadius??[0],Math.min(a,o)),u.cornerSmoothing,u.corner);if(u.background!=null&&u.shadows)for(let h of u.shadows)typeof h!="string"&&(t.save(),t.shadowOffsetX=h.offsetX,t.shadowOffsetY=h.offsetY,t.shadowBlur=h.blurRadius,h.color&&(t.shadowColor=h.color,t.fillStyle=h.color),t.translate(s,n),t.fill(d),t.restore());if(t.save(),t.translate(s,n),t.clip(d),t.translate(-s,-n),u.background!=null)for(let h of u.background){if(typeof h=="string"){t.fillStyle=h,t.fillRect(s,n,a,o);continue}if(h.type==="photo"){t.save(),we(t,h,r,s,n),U(e,t,h,r,s,n),t.restore();continue}let[f]=I(t,[h],s,n,a,o);t.fillStyle=f,t.fillRect(s,n,a,o)}return t.restore(),G(t,r,u,d,s,n),d}function we(e,t,i,r,s){if(t==null||t.type==="text-default")return;typeof t.props.opacity=="number"&&(e.globalAlpha=t.props.opacity);let{translateX:n,translateY:a}=t.props;e.translate(n??0,a??0);let o=r+i.getComputedWidth()/2,u=s+i.getComputedHeight()/2,d=t.props.rotation;typeof d=="number"&&d!==0&&(e.translate(o,u),e.rotate(d*Math.PI/180),e.translate(-o,-u));let h=t.props.scale;if(h!=null&&Array.isArray(h)&&(e.translate(o,u),e.scale(h[0],h[1]),e.translate(-o,-u)),t.props.filters!=null&&Array.isArray(t.props.filters)){let f=t.props.filters.join(" ");e.filter=f}}function xt(e,t,i,r,s,n){if(i==null||i.type==="text-default")return;t.save(),t.lineWidth=2,t.strokeStyle="cyan",t.strokeRect(s,n,r.getComputedWidth(),r.getComputedHeight());let a=i.props.tag!=null?`${i.type}:${i.props.tag}`:i.type;t.font=`${20*e.dpr()}px monospace`;let o=t.measureText(a);t.fillStyle="rgba(0,255,255,.6)",t.fillRect(s,n,o.width,o.fontBoundingBoxAscent+o.fontBoundingBoxDescent),t.strokeStyle="cyan",t.strokeRect(s,n,o.width,o.fontBoundingBoxAscent+o.fontBoundingBoxDescent),t.fillStyle="black",t.textBaseline="top",t.fillText(a,s,n),t.restore()}function St(e,t,i,r,s){t.save();let{props:n}=i,{d:a}=n;if(!a){t.restore();return}let o=new e.Path2D(a);if(t.translate(r,s),n.bounds){let[u,d]=n.bounds;t.scale(n.scalePath??1,n.scalePath??1),t.translate(-u,-d)}if(n.fill!=null){if(t.fillStyle=n.fill,n.fillOpacity!=null){let u=t.globalAlpha;t.globalAlpha=u*n.fillOpacity}n.fillRule?t.fill(o,n.fillRule):t.fill(o),n.fillOpacity!=null&&(t.globalAlpha=t.globalAlpha/n.fillOpacity)}n.stroke!=null&&(t.strokeStyle=n.stroke,n.strokeWidth!=null&&(t.lineWidth=n.strokeWidth),n.strokeLineCap&&(t.lineCap=n.strokeLineCap),n.strokeLineJoin&&(t.lineJoin=n.strokeLineJoin),n.strokeMiterLimit!=null&&(t.miterLimit=n.strokeMiterLimit),n.strokeDashArray!=null&&t.setLineDash(n.strokeDashArray),n.strokeDashOffset!=null&&(t.lineDashOffset=n.strokeDashOffset),t.stroke(o)),t.restore()}function Ct(e,t,i,r,s,n){t.save();let a=0;i.props.borderColor!=null&&(t.strokeStyle=i.props.borderColor),i.props.borderWidth!=null&&(t.lineWidth=i.props.borderWidth,a=i.props.borderWidth);let o=0,u=-1;t.beginPath();for(let d=0;d<r.getChildCount();d++){let h=r.getChild(d);(u===-1||h.getChildCount()>r.getChild(u).getChildCount())&&(u=d),d!==r.getChildCount()-1&&(t.moveTo(s,n+h.getComputedHeight()+o+a),t.lineTo(s+r.getComputedWidth(),n+h.getComputedHeight()+o+a),o+=h.getComputedHeight())}if(u!==-1){let d=r.getChild(u),h=0;for(let f=0;f<d.getChildCount();f++){let g=d.getChild(f);f>0&&(t.moveTo(s+h+a,n),t.lineTo(s+h+a,n+r.getComputedHeight())),h+=g.getComputedWidth()}}t.stroke(),t.restore()}0&&(module.exports={Column,DEFAULT_TEXT_PROPS,Path,Photo,Row,Span,Table,TableCell,TableRow,Text,TextDefault,compile,createLayoutNode,drawLayoutNode,findFonts,pathPropsBuilder,qrcode,render});