UNPKG

sone

Version:

A declarative Canvas layout engine for JavaScript with advanced rich text support.

3 lines (2 loc) 43.7 kB
"use strict";var We=Object.create;var $=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var ze=(e,t)=>{for(var o in t)$(e,o,{get:t[o],enumerable:!0})},he=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Me(t))!He.call(e,a)&&a!==o&&$(e,a,{get:()=>t[a],enumerable:!(r=Ae(t,a))||r.enumerable});return e};var J=(e,t,o)=>(o=e!=null?We(De(e)):{},he(t||!e||!e.__esModule?$(o,"default",{value:e,enumerable:!0}):o,e)),Ie=e=>he($({},"__esModule",{value:!0}),e);var Ht={};ze(Ht,{Column:()=>Ve,DEFAULT_TEXT_PROPS:()=>At,Path:()=>Xe,Photo:()=>je,Row:()=>Ye,Span:()=>Ge,Table:()=>_e,TableCell:()=>Ue,TableRow:()=>Je,Text:()=>Fe,TextDefault:()=>Ee,applySpanProps:()=>I,calculateLayout:()=>se,compile:()=>_,createLayoutNode:()=>ae,createMetadata:()=>Le,defaultLineBreakerIterator:()=>Ze,drawDebugBBox:()=>ve,drawLayoutNode:()=>X,drawOnCanvas:()=>ue,drawPathNode:()=>Be,drawTableNode:()=>qe,findFonts:()=>ie,fontBuilder:()=>Z,getYogaLayout:()=>Ce,makeTransforms:()=>le,pathPropsBuilder:()=>fe,qrcode:()=>et,render:()=>Dt,renderWithMetadata:()=>Mt});module.exports=Ie(Ht);function D(e={}){let t=r=>{e.filters==null&&(e.filters=[]),e.filters.push(r)},o=(...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,a,s,i){return a==null&&s==null&&i==null?(e.borderWidth=r,this):a!=null&&s==null&&i==null?(e.borderTopWidth=r,e.borderBottomWidth=r,e.borderLeftWidth=a,e.borderRightWidth=a,this):a!=null&&s!=null&&i==null?(e.borderTopWidth=r,e.borderBottomWidth=s,e.borderLeftWidth=a,e.borderRightWidth=a,this):(e.borderTopWidth=r,e.borderBottomWidth=s,e.borderLeftWidth=i,e.borderRightWidth=a,this)},borderColor(r){return e.borderColor=r,this},margin(r,a,s,i){return a==null&&s==null&&i==null?(e.margin=r,this):a!=null&&s==null&&i==null?(e.marginTop=r,e.marginBottom=r,e.marginLeft=a,e.marginRight=a,this):a!=null&&s!=null&&i==null?(e.marginTop=r,e.marginLeft=a,e.marginRight=a,e.marginBottom=s,this):(e.marginTop=r,e.marginLeft=i,e.marginRight=a,e.marginBottom=s,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,a,s,i){return a==null&&s==null&&i==null?(e.padding=r,this):a!=null&&s==null&&i==null?(e.paddingTop=r,e.paddingBottom=r,e.paddingLeft=a,e.paddingRight=a,this):a!=null&&s!=null&&i==null?(e.paddingTop=r,e.paddingLeft=a,e.paddingRight=a,e.paddingBottom=s,this):(e.paddingTop=r,e.paddingLeft=i,e.paddingRight=a,e.paddingBottom=s,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,a){return e.width=r,e.height=a??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,a){return e.scale=[r,a??r],this},translateX(r){return e.translateX=r,this},translateY(r){return e.translateY=r,this},bg(...r){return o(...r),this},background(...r){return o(...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 U(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 $e(e={}){return{...D(e),...U(e),nowrap(){return e.nowrap=!0,this},autofit(t){return e.autofit=t??!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 Ge(e){return{type:"span",children:e,...U()}}function Oe(e){return{...U(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 Ee(...e){return{type:"text-default",children:e,...Oe({})}}function Fe(...e){return{id:-1,type:"text",children:e.filter(t=>t!=null),...$e()}}function Ve(...e){return{id:-1,type:"column",children:e,...D()}}function Ye(...e){return{id:-1,type:"row",children:e,...D()}}function je(e){let t={src:e};return{id:-1,type:"photo",...D(t),scaleType(o,r){if(t.scaleType=o,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(o=!0){return t.preserveAspectRatio=o,this},flipVertical(o=!0){return t.flipVertical=o,this},flipHorizontal(o=!0){return t.flipHorizontal=o,this},fill(o){return t.fill=o,this}}}function fe(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 Xe(e){let t={d:e};return{id:-1,type:"path",...fe(t),props:t}}function _e(...e){let t={};return{id:-1,type:"table",children:e,...D(t),spacing(...o){return t.spacing=o,this}}}function Je(...e){return{id:-1,type:"table-row",children:e,...D({})}}function Ue(...e){let t={};return{id:-1,type:"table-cell",children:e,...D(t),colspan(o){return t.colspan=o,this},rowspan(o){return t.rowspan=o,this},props:t}}var Q=null,Qe="\u17D4\u17D5)]?!\xBB\u17D6",Ke="([\xAB";function*Ze(e){Q==null&&(Q=new Intl.Segmenter(void 0,{granularity:"word"}));for(let t of Q.segment(e)){if(t.segment.endsWith("\u17D2"))continue;let o=e[t.index];if(o!==void 0&&Qe.indexOf(o)!==-1)continue;let r=e[t.index-1];r!==void 0&&Ke.indexOf(r)!==-1||(yield t.index)}}var pe=require("uqr");function et(e,t={}){let o=(0,pe.encode)(e,t),{pixelSize:r=10,whiteColor:a="white",blackColor:s="black"}=t,i=o.size*r,n=o.size*r,u=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${n} ${i}" width="${n}" height="${i}">`,l=[];for(let d=0;d<o.size;d++)for(let c=0;c<o.size;c++){let p=c*r,T=d*r;o.data[d][c]&&l.push(`M${p},${T}h${r}v${r}h-${r}z`)}return u+=`<rect fill="${a}" width="${n}" height="${i}"/>`,u+=`<path fill="${s}" d="${l.join("")}"/>`,u+="</svg>",Buffer.from(u)}var j=require("gradient-parser"),oe=require("klona"),ke=J(require("object.pick")),xe=J(require("p-memoize")),Se=J(require("svg-path-bounds")),N=require("yoga-layout/load");var ce={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 tt=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,rt=/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/,nt=/^hsl\(\s*(\d+)\s*,\s*(\d*(?:\.\d+)?%)\s*,\s*(\d*(?:\.\d+)?%)\)$/,ot=/^hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*(\d*(?:\.\d+)?)\)$/,it=/^#([a-f0-9]{3,4}|[a-f0-9]{4}(?:[a-f0-9]{2}){1,2})\b$/i;function G(e){return e==="transparent"||e in ce?!0:tt.test(e)||rt.test(e)||nt.test(e)||ot.test(e)||it.test(e)}function at(e){switch(e.type){case"hex":return`#${e.value}`;case"literal":return e.value;default:return`${e.type}(${e.value.join(",")})`}}function st(e,t,o,r){let{length:a}=e;if(!a)return 1/(t-1)*o;if(a.type==="px")return Number.parseFloat(a.value);if(a.type==="%")return r?Number.parseFloat(a.value)*r/100:Number(a.value)/100}function ge(e,t){return e.reduce((o,r,a)=>{o.colors=[...o.colors,at(r)];let s=st(r,e.length,a,t);return o.locations=[...o.locations,s],o},{colors:[],locations:[]})}function ut(e,t){let{width:o}=t,{colors:r,locations:a}=ge(e,o),s=a.slice(-1)[0],i=typeof s=="number"?s:Number.parseFloat(s),n=i/o,u=Math.round(o/i),l=[];for(let c=0;c<u;c++)for(let p of a)l.push(p/o+n*c);return{colors:l.map((c,p)=>r[p%r.length]),locations:l}}function lt(e){return Math.round(e*1e4)/1e4}function dt(e){return e*Math.PI/180}var ht=e=>e==null?A(180):e.type==="directional"?ft(e.value):A(Number(e.value));function A(e){let t=dt(e),o=lt(Math.abs(Math.sin(t))+Math.abs(Math.cos(t))),r={x:.5,y:.5},a=Math.sin(t-Math.PI/2)*o/2,s=Math.cos(t-Math.PI/2)*o/2;return{start:{x:r.x-s,y:r.y-a},end:{x:r.x+s,y:r.y+a}}}function ft(e){switch(e){case"top":return A(0);case"right":return A(90);case"bottom":return A(180);case"left":return A(270);case"left top":return A(315);case"left bottom":return A(225);case"right top":return A(45);case"right bottom":return A(135)}}function pt(e,t){let o=[];for(let{type:r,colorStops:a,orientation:s}of e){if(r==="radial-gradient"||r==="repeating-radial-gradient")continue;let i=r==="linear-gradient"?ge(a):ut(a,t),n=ht(s),u={...i,...n};o.push(u)}return o}function O(e,t,o,r,a,s){let i=pt(t,{width:a,height:s}),n=[];for(let u of i){let l=e.createLinearGradient(o+u.start.x*a,r+u.start.y*s,o+u.end.x*a,r+u.end.y*s);for(let d=0;d<u.colors.length;d++){let c=u.colors[d],p=u.locations[d];p<0&&(p=0),p>1&&(p=1),l.addColorStop(p,c)}n.push(l)}return n}var z=require("yoga-layout/load");function E(e,t,o,r,a,s){let i=t.getComputedBorder(z.Edge.Left),n=t.getComputedBorder(z.Edge.Top),u=t.getComputedBorder(z.Edge.Right),l=t.getComputedBorder(z.Edge.Bottom);i===n&&n===u&&u===l&&i>0&&(e.save(),e.translate(a,s),e.strokeStyle=o.borderColor,e.lineJoin="round",e.lineWidth=i*2,e.clip(r),e.stroke(r),e.translate(-a,-s),e.restore())}var me=require("figma-squircle");function F(e,t){for(let o=0;o<e.length;o++)e[o]=Math.max(0,Math.min(e[o],t/2));return e}function V(e,t,o,r,a=0,s="round"){let i=a;i>1&&(i=1),i<0&&(i=0);let n={topLeftCornerRadius:0,topRightCornerRadius:0,bottomRightCornerRadius:0,bottomLeftCornerRadius:0};if(r.length===1&&(n.topLeftCornerRadius=r[0],n.topRightCornerRadius=r[0],n.bottomRightCornerRadius=r[0],n.bottomLeftCornerRadius=r[0]),r.length===2&&(n.topLeftCornerRadius=r[0],n.bottomRightCornerRadius=r[0],n.topRightCornerRadius=r[1],n.bottomLeftCornerRadius=r[1]),r.length>2&&(n.topLeftCornerRadius=r[0],n.topRightCornerRadius=r[1]??0,n.bottomRightCornerRadius=r[2]??0,n.bottomLeftCornerRadius=r[3]??0),s==="round"){let l=(0,me.getSvgPath)({cornerSmoothing:i,width:t,height:o,preserveSmoothing:!0,...n});return new e.Path2D(l)}let u=new e.Path2D;return u.moveTo(n.topLeftCornerRadius,0),u.lineTo(t-n.topRightCornerRadius,0),u.lineTo(t,n.topRightCornerRadius),u.lineTo(t,o-n.bottomRightCornerRadius),u.lineTo(t-n.bottomRightCornerRadius,o),u.lineTo(n.bottomLeftCornerRadius,o),u.lineTo(0,o-n.bottomLeftCornerRadius),u.lineTo(0,n.topLeftCornerRadius),u.closePath(),u}function K(e,t,o,r,a,s){let i=o.props;if(i.image==null)return;let n=i.image,u=r.getComputedWidth(),l=r.getComputedHeight(),d=o.props.scaleType??"fill",c=n.width,p=n.height,T=a,g=s,m=u,b=l,w=n.width/n.height,P=u/l,R=i.scaleAlignment??1/2;switch(d){case"cover":if(w>P){let k=n.width*l/n.height;c=n.width,p=n.height,m=k,b=l,T=a+(u-k)*R}else{let k=n.height*u/n.width;c=n.width,p=n.height,m=u,b=k,g=s+(l-k)*R}break;case"contain":w>P?(m=u,b=u/w,g=s+(l-b)*R):(b=l,m=l*w,T=a+(u-m)*R);break}t.save();let y=V(e,u,l,F(i.cornerRadius??[0],Math.min(u,l)),i.cornerSmoothing);if(t.translate(a,s),t.clip(y),t.translate(-a,-s),i.background)for(let k of i.background)typeof k=="string"&&(t.fillStyle=k,t.fillRect(a,s,u,l));let x=i.flipHorizontal??!1,q=i.flipVertical??!1;if(x||q){let k=T+m/2,S=g+b/2;t.translate(k,S),t.scale(x?-1:1,q?-1:1),t.translate(-k,-S)}t.drawImage(n,0,0,c,p,T,g,m,b),t.restore(),(i.borderWidth!=null||i.borderTopWidth!=null||i.borderLeftWidth!=null||i.borderRightWidth!=null||i.borderBottomWidth!=null)&&E(t,r,i,y,a,s)}var h=require("yoga-layout/load");function Te(e,t){for(let o of Object.keys(e))switch(o){case"alignContent":t.setAlignContent(ct(e.alignContent));break;case"alignItems":t.setAlignItems(be(e.alignItems));break;case"alignSelf":t.setAlignSelf(be(e.alignSelf));break;case"aspectRatio":t.setAspectRatio(e.aspectRatio);break;case"borderBottomWidth":t.setBorder(h.Edge.Bottom,e.borderBottomWidth);break;case"borderEndWidth":t.setBorder(h.Edge.End,e.borderEndWidth);break;case"borderLeftWidth":t.setBorder(h.Edge.Left,e.borderLeftWidth);break;case"borderRightWidth":t.setBorder(h.Edge.Right,e.borderRightWidth);break;case"borderStartWidth":t.setBorder(h.Edge.Start,e.borderStartWidth);break;case"borderTopWidth":t.setBorder(h.Edge.Top,e.borderTopWidth);break;case"borderWidth":t.setBorder(h.Edge.All,e.borderWidth);break;case"borderInlineWidth":t.setBorder(h.Edge.Horizontal,e.borderInlineWidth);break;case"borderBlockWidth":t.setBorder(h.Edge.Vertical,e.borderBlockWidth);break;case"bottom":t.setPosition(h.Edge.Bottom,e.bottom);break;case"boxSizing":t.setBoxSizing(gt(e.boxSizing));break;case"direction":t.setDirection(mt(e.direction));break;case"display":t.setDisplay(bt(e.display));break;case"end":t.setPosition(h.Edge.End,e.end);break;case"flex":t.setFlex(e.flex);break;case"flexBasis":t.setFlexBasis(e.flexBasis);break;case"flexDirection":t.setFlexDirection(Tt(e.flexDirection));break;case"rowGap":t.setGap(h.Gutter.Row,e.rowGap);break;case"gap":t.setGap(h.Gutter.All,e.gap);break;case"columnGap":t.setGap(h.Gutter.Column,e.columnGap);break;case"flexGrow":t.setFlexGrow(e.flexGrow);break;case"flexShrink":t.setFlexShrink(e.flexShrink);break;case"flexWrap":t.setFlexWrap(yt(e.flexWrap));break;case"height":t.setHeight(e.height);break;case"justifyContent":t.setJustifyContent(wt(e.justifyContent));break;case"left":t.setPosition(h.Edge.Left,e.left);break;case"margin":t.setMargin(h.Edge.All,e.margin);break;case"marginBottom":t.setMargin(h.Edge.Bottom,e.marginBottom);break;case"marginEnd":t.setMargin(h.Edge.End,e.marginEnd);break;case"marginLeft":t.setMargin(h.Edge.Left,e.marginLeft);break;case"marginRight":t.setMargin(h.Edge.Right,e.marginRight);break;case"marginStart":t.setMargin(h.Edge.Start,e.marginStart);break;case"marginTop":t.setMargin(h.Edge.Top,e.marginTop);break;case"marginInline":t.setMargin(h.Edge.Horizontal,e.marginInline);break;case"marginBlock":t.setMargin(h.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(Pt(e.overflow));break;case"padding":t.setPadding(h.Edge.All,e.padding);break;case"paddingBottom":t.setPadding(h.Edge.Bottom,e.paddingBottom);break;case"paddingEnd":t.setPadding(h.Edge.End,e.paddingEnd);break;case"paddingLeft":t.setPadding(h.Edge.Left,e.paddingLeft);break;case"paddingRight":t.setPadding(h.Edge.Right,e.paddingRight);break;case"paddingStart":t.setPadding(h.Edge.Start,e.paddingStart);break;case"paddingTop":t.setPadding(h.Edge.Top,e.paddingTop);break;case"paddingInline":t.setPadding(h.Edge.Horizontal,e.paddingInline);break;case"paddingBlock":t.setPadding(h.Edge.Vertical,e.paddingBlock);break;case"position":t.setPositionType(Rt(e.position));break;case"right":t.setPosition(h.Edge.Right,e.right);break;case"start":t.setPosition(h.Edge.Start,e.start);break;case"top":t.setPosition(h.Edge.Top,e.top);break;case"insetInline":t.setPosition(h.Edge.Horizontal,e.insetInline);break;case"insetBlock":t.setPosition(h.Edge.Vertical,e.insetBlock);break;case"inset":t.setPosition(h.Edge.All,e.inset);break;case"width":t.setWidth(e.width);break}return t}function ct(e){switch(e){case"flex-start":return h.Align.FlexStart;case"flex-end":return h.Align.FlexEnd;case"center":return h.Align.Center;case"stretch":return h.Align.Stretch;case"space-between":return h.Align.SpaceBetween;case"space-around":return h.Align.SpaceAround;case"space-evenly":return h.Align.SpaceEvenly}}function be(e){switch(e){case"flex-start":return h.Align.FlexStart;case"flex-end":return h.Align.FlexEnd;case"center":return h.Align.Center;case"stretch":return h.Align.Stretch;case"baseline":return h.Align.Baseline}}function gt(e){switch(e){case"border-box":return h.BoxSizing.BorderBox;case"content-box":return h.BoxSizing.ContentBox}}function mt(e){switch(e){case"ltr":return h.Direction.LTR;case"rtl":return h.Direction.RTL}}function bt(e){switch(e){case"none":return h.Display.None;case"flex":return h.Display.Flex;case"contents":return h.Display.Contents}}function Tt(e){switch(e){case"row":return h.FlexDirection.Row;case"column":return h.FlexDirection.Column;case"row-reverse":return h.FlexDirection.RowReverse;case"column-reverse":return h.FlexDirection.ColumnReverse}}function yt(e){switch(e){case"wrap":return h.Wrap.Wrap;case"nowrap":return h.Wrap.NoWrap;case"wrap-reverse":return h.Wrap.WrapReverse}}function wt(e){switch(e){case"flex-start":return h.Justify.FlexStart;case"flex-end":return h.Justify.FlexEnd;case"center":return h.Justify.Center;case"space-between":return h.Justify.SpaceBetween;case"space-around":return h.Justify.SpaceAround;case"space-evenly":return h.Justify.SpaceEvenly}}function Pt(e){switch(e){case"visible":return h.Overflow.Visible;case"hidden":return h.Overflow.Hidden;case"scroll":return h.Overflow.Scroll}}function Rt(e){switch(e){case"absolute":return h.PositionType.Absolute;case"relative":return h.PositionType.Relative;case"static":return h.PositionType.Static}}var kt=/,(?![^(]*\))/,xt=/\s(?![^(]*\))/,St=/^[0-9]+[a-zA-Z%]+?$/;function Ct(e){let t=e.split(xt),o=t.includes("inset"),r=t.slice(-1)[0],a=Lt(r)?void 0:r,s=t.filter(d=>d!=="inset").filter(d=>d!==a).map(vt),[i,n,u,l]=s;return{inset:o,offsetX:Number(i),offsetY:Number(n),blurRadius:Number(u),spreadRadius:l==null?void 0:Number(l),color:a}}function Lt(e){return e==="0"||St.test(e)}function vt(e){if(!/px$/.test(e)&&e!=="0")return e;let t=Number.parseFloat(e);return Number.isNaN(t)?e:t}var Y=e=>e.split(kt).map(t=>t.trim()).map(Ct);var we=require("dequal"),Pe=require("klona"),M=require("yoga-layout/load");function Z(e){let t=e.font!=null?e.font?.join(", "):"",o=e.size??"",r=e.weight??"";return`${e.style??""} ${r} ${o}px ${t}`.trim()}function I(e,t){e.font=Z(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 ye(e,t){let o=[],r=e.indexOf(t);for(;r!==-1;)o.push(r),r=e.indexOf(t,r+1);return o}var Bt=/^\s+$/;function ee(e){return e.length===0?!1:Bt.test(e)}function qt(e,t,o,r,a){let s=r.lineHeight==null||Number.isNaN(r.lineHeight)?1:r.lineHeight,i=[],n={baseline:0,height:0,width:r.indentSize??0,segments:[],spacesCount:0};i.push(n);for(let p=0;p<e.length;p++){let T=e[p],g=typeof T=="string"?r:T.props,m=typeof T=="string"?T:T.children,b=t[p]||[];if(b.length===0){let P=a(m,g),R=P.width,y=P.fontBoundingBoxAscent+P.fontBoundingBoxDescent;if(n.width+R>o&&n.segments.length>0){n={baseline:0,height:0,width:0,segments:[],spacesCount:0},i.push(n);let q=m.trimStart();if(q!==m){let k=a(q,g);R=k.width,y=k.fontBoundingBoxAscent+k.fontBoundingBoxDescent;let S={metrics:k,props:g,text:q,width:R,height:y};n.segments.push(S),n.width+=R,n.height=Math.max(n.height,y),n.baseline=Math.max(n.baseline,k.fontBoundingBoxAscent);continue}}let x={metrics:P,props:g,text:m,width:R,height:y};n.segments.push(x),n.width+=R,n.height=Math.max(n.height,y),n.baseline=Math.max(n.baseline,P.fontBoundingBoxAscent);continue}let w=0;for(let P=0;P<b.length;P++){let R=b[P],y=m.substring(w,R);if(y.length===0){w=R;continue}let x=a(y,g),q=x.width,k=x.fontBoundingBoxAscent+x.fontBoundingBoxDescent;if(n.width+q>o&&n.segments.length>0){if(n.segments.length>0){let C=n.segments[n.segments.length-1],L=C.text.trimEnd();if(L!==C.text&&L.length>0){let v=a(L,C.props),W=v.width,H=v.fontBoundingBoxAscent+v.fontBoundingBoxDescent;C.text=L,C.metrics=v,C.width=W,C.height=H,n.width=n.segments.reduce((de,B)=>de+B.width,0)}}n={baseline:0,height:0,width:r.hangingIndentSize??0,segments:[],spacesCount:0},i.push(n);let f=y.trimStart();if(f!==y){if(f.length===0){w=R;continue}let C=a(f,g),L=C.width,v=C.fontBoundingBoxAscent+C.fontBoundingBoxDescent,W={metrics:C,props:g,text:f,width:L,height:v};n.segments.push(W),n.width+=L,n.height=Math.max(n.height,v),n.baseline=Math.max(n.baseline,C.fontBoundingBoxAscent),w=R;continue}}let S={metrics:x,props:g,text:y,width:q,height:k};n.segments.push(S),n.width+=q,n.height=Math.max(n.height,k),n.baseline=Math.max(n.baseline,x.fontBoundingBoxAscent),w=R}if(w<m.length){let P=m.substring(w),R=a(P,g),y=R.width,x=R.fontBoundingBoxAscent+R.fontBoundingBoxDescent;if(n.width+y>o&&n.segments.length>0){if(n.segments.length>0){let S=n.segments[n.segments.length-1],f=S.text.trimEnd();if(f!==S.text&&f.length>0){let C=a(f,S.props),L=C.width,v=C.fontBoundingBoxAscent+C.fontBoundingBoxDescent;S.text=f,S.metrics=C,S.width=L,S.height=v,n.width=n.segments.reduce((W,H)=>W+H.width,0)}}n={baseline:0,height:0,width:0,segments:[],spacesCount:0},i.push(n);let k=P.trimStart();if(k!==P){if(k.length===0)continue;let S=a(k,g),f=S.width,C=S.fontBoundingBoxAscent+S.fontBoundingBoxDescent,L={metrics:S,props:g,text:k,width:f,height:C};n.segments.push(L),n.width+=f,n.height=Math.max(n.height,C),n.baseline=Math.max(n.baseline,S.fontBoundingBoxAscent);continue}}let q={metrics:R,props:g,text:P,width:y,height:x};n.segments.push(q),n.width+=y,n.height=Math.max(n.height,x),n.baseline=Math.max(n.baseline,R.fontBoundingBoxAscent)}}for(let p of i){let T=[];for(let g=0;g<p.segments.length;g++){let m=p.segments[g];if(ee(m.text)&&(g===p.segments.length-1||g===0)){p.width-=m.width;continue}T.push(m)}p.segments=T}let u=0;for(let p of i){p.baseline*=s,p.height*=s;let T=0,g=Number.POSITIVE_INFINITY;for(let m of p.segments){let b=m.props.offsetY??0;b>T&&(T=b),b<g&&(g=b)}if(p.baseline-=g,p.height-=g,p.height+=T,u<i.length-1)for(let m of p.segments){let b=m.text.match(/[ ]/);b&&(p.spacesCount+=b.length)}u++}let l=0,d=0;for(let p of i)l+=p.height,d=Math.max(d,p.width);let c=0;if(i.length>0&&r.lineHeight!=null&&!Number.isNaN(r.lineHeight)){let p=Math.max(0,r.lineHeight-1);for(let T of i[0].segments){let g=T.metrics,m=-((g.fontBoundingBoxAscent-g.fontBoundingBoxDescent)/2)*p;m<c&&(c=m)}}return{width:d,height:l,lines:i,offsetY:c}}function Nt(e,t){let o=[[]];for(let a of e){let s=typeof a=="string"?a:a.children,i=ye(s,` `);if(i.length===0){o[o.length-1].push(a);continue}i.length>0&&i[i.length-1]!==s.length&&i.push(s.length);let n=0;for(let u=0;u<i.length;u++){let l=i[u],d=s.slice(n,l);if(typeof a=="string")o[o.length-1].push(d);else{let c=(0,Pe.klona)(a);c.children=d,o[o.length-1].push(c)}u<i.length-1&&o.push([]),n=l+1}}let r=[];for(let a of o){let s=[];for(let i of a){let n=typeof i=="string"?i:i.children;s.push(Array.from(t(n)))}r.push(s)}return[o,r]}function te(e,t,o,r,a){let[s,i]=Nt(e,a),n=[];for(let u=0;u<s.length;u++){let l=i[u],d=s[u],c=qt(d,l,t,o,r);for(let p of c.lines){let T=[[]];for(let m of p.segments){let b=T[T.length-1];if(b.length>0){let w=b[b.length-1];if(o.align==="justify"&&ee(m.text)){T.push([m]),T.push([]);continue}if(!(0,we.dequal)(w.props,m.props)){T.push([m]);continue}}b.push(m)}let g=[];for(let m of T){if(m.length===0)continue;if(m.length===1){g.push(m[0]);continue}let b=m.slice(1).reduce((w,P)=>({metrics:w.metrics,text:w.text+P.text,height:Math.max(w.height,P.height),width:w.width+P.width,props:w.props}),m[0]);g.push(b)}p.segments=g}n.push({paragraph:c})}return n}function Re(e,t,o,r,a,s){let{props:i}=o,{blocks:n}=i;if(n==null)return;let u=r.getComputedBorder(M.Edge.Left)+r.getComputedBorder(M.Edge.Right)+r.getComputedPadding(M.Edge.Left)+r.getComputedPadding(M.Edge.Right),l=0;for(let{paragraph:d}of n){d.width=Math.max(r.getComputedWidth(),d.width)-u;let c=i.boxSizing==="content-box"?r.getComputedPadding(M.Edge.Left):0,p=i.boxSizing==="content-box"?r.getComputedPadding(M.Edge.Top):0,T=r.getComputedBorder(M.Edge.Left),g=r.getComputedBorder(M.Edge.Top),m=c+T,b=p+g,w=i.align;I(t,i);let P=d.offsetY+l;l+=d.height;for(let R=0;R<d.lines.length;R++){let y=d.lines[R],x=d.width-y.width,q=w==="justify"&&x>0&&y.spacesCount>0?x/y.spacesCount:0,k=0;switch(w){case"center":k=(d.width-y.width)/2;break;case"right":k=d.width-y.width;break;case"left":case"justify":R===0&&i.indentSize!=null&&(k+=i.indentSize),R>0&&i.hangingIndentSize!=null&&(k+=i.hangingIndentSize);break}for(let S=0;S<y.segments.length;S++){let f=y.segments[S],C=f.props.offsetY??0,L=f.width;w==="justify"&&/[ ]/.test(f.text)&&(L+=q);let v=a+m+k,W=s+y.baseline+b+P+C;if(typeof f.props.underline=="number"&&f.props.underline!==0){typeof f.props.color=="string"&&(t.fillStyle=f.props.underlineColor??f.props.color);let B=f.height*f.props.underline/18;t.fillRect(v,W+B,L,B)}if(typeof f.props.overline=="number"&&f.props.overline!==0){typeof f.props.color=="string"&&(t.fillStyle=f.props.overlineColor??f.props.color);let B=f.height*f.props.overline/18;t.fillRect(v,W-f.metrics.fontBoundingBoxAscent,L,B)}let H=W-f.height+f.metrics.fontBoundingBoxDescent;if(f.props.highlightColor!=null&&(t.fillStyle=f.props.highlightColor,t.fillRect(v,H,L,f.height)),I(t,f.props),f.props.dropShadows)for(let B of f.props.dropShadows)typeof B!="string"&&(t.save(),t.shadowOffsetX=B.offsetX,t.shadowOffsetY=B.offsetY,t.shadowBlur=B.blurRadius,B.color&&(t.shadowColor=B.color,t.fillStyle=B.color),t.fillText(f.text,v,W),t.restore());if(t.save(),f.props.strokeColor!=null&&f.props.strokeWidth!=null&&f.props.strokeWidth!==0&&(t.strokeStyle=f.props.strokeColor,t.lineJoin="round",t.miterLimit=2,t.lineWidth=f.props.strokeWidth,t.strokeText(f.text,v,W)),typeof f.props.color!="string"&&Array.isArray(f.props.color))for(let B of f.props.color){let[Ne]=O(t,[B],a,s,f.width,f.height);t.fillStyle=Ne}if(t.fillText(f.text,v,W),t.restore(),typeof f.props.lineThrough=="number"&&f.props.lineThrough!==0){typeof f.props.color=="string"&&(t.fillStyle=f.props.lineThroughColor??f.props.color);let B=f.height*f.props.lineThrough/18;t.fillRect(v,W-(f.metrics.fontBoundingBoxAscent-f.metrics.fontBoundingBoxDescent)/2,L,B)}e.debug().text&&(t.save(),t.lineWidth=e.dpr()*2,t.strokeStyle="cyan",t.strokeRect(v,H,L,f.height),t.restore()),k+=L}P+=y.height}}}var Wt=(0,N.loadYoga)();async function Ce(){return Wt}var At={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:[],autofit:!1};function re(e){return Object.fromEntries(Object.entries(e).filter(([t,o])=>o!=null))}function ne(e,t){let o=e.props,r=t.width/t.height;o.preserveAspectRatio&&(typeof o.width=="number"&&typeof o.height!="number"&&(o.height=Math.round(o.width/r)),typeof o.height=="number"&&typeof o.width!="number"&&(o.width=Math.round(o.height*r))),o.width==null&&(o.width=t.width),o.height==null&&(o.height=t.height),o.image=t}async function _(e,{defaultTextProps:t,loadImage:o,breakIterator:r,createId:a}){if(e==null)return;if(e.type!=="text-default"){if(e.id===-1&&(e.id=a()),e.props.shadows!=null&&Array.isArray(e.props.shadows)){let i=[];for(let n of e.props.shadows)typeof n=="string"?i.push(...Y(n)):i.push(n);e.props.shadows=i}if(e.props.background!=null&&Array.isArray(e.props.background)){let i=[];for(let n of e.props.background){if(typeof n=="string"){if(!G(n)){let u=(0,j.parse)(n);i.push(...u);continue}}else n.type==="photo"&&(typeof n.props.src=="string"||Buffer.isBuffer(n.props.src))&&ne(n,await o(n.props.src));i.push(n)}e.props.background=i}}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,...re(e.props)},e.props.dropShadows!=null&&Array.isArray(e.props.dropShadows)){let i=[];for(let n of e.props.dropShadows)typeof n=="string"?i.push(...Y(n)):i.push(n);e.props.dropShadows=i}return typeof e.props.color=="string"&&(G(e.props.color)||(e.props.color=(0,j.parse)(e.props.color))),e.children.map(i=>{if(typeof i=="string")return i;let n=(0,ke.default)(e.props,["size","color","font","style","weight","letterSpacing","wordSpacing","strokeColor","strokeWidth","underline","underlineColor","overline","overlineColor","lineThrough","lineThroughColor","highlightColor","dropShadows"]);if(i.props={...re(n),...i.props},i.props.dropShadows!=null&&Array.isArray(i.props.dropShadows)){let u=[];for(let l of i.props.dropShadows)typeof l=="string"?u.push(...Y(l)):u.push(l);i.props.dropShadows=u}return typeof i.props.color=="string"&&(G(i.props.color)||(i.props.color=(0,j.parse)(i.props.color))),i}),e}if(e.type==="photo")return typeof e.props.src=="string"||Buffer.isBuffer(e.props.src)?(ne(e,await o(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 i of e.props.background)if(typeof i!="string"&&i.type==="photo"&&(typeof i.props.src=="string"||Buffer.isBuffer(i.props.src)))return ne(i,await o(i.props.src)),e}if(e.type==="path")return e.props.d&&(e.props.bounds=(0,Se.default)(e.props.d)),e;let s=[];for(let i of e.children)if(i!=null){if(i.type==="text-default"){let n={...t,...re(i.props)};for(let u of i.children)u!=null&&s.push(await _(u,{defaultTextProps:n,loadImage:o,breakIterator:r,createId:a}));continue}s.push(await _(i,{defaultTextProps:t,loadImage:o,breakIterator:r,createId:a}))}if(e.children=s.filter(i=>i!=null),e.type==="table"&&e.props.spacing!=null&&Array.isArray(e.props.spacing)){let[i,n]=e.props.spacing;n=n??i;for(let u of e.children)if(u!=null)for(let l of u.children){if(l==null)return;l.type!=="text-default"&&(l.props.paddingLeft==null&&(l.props.paddingLeft=i),l.props.paddingRight==null&&(l.props.paddingRight=i),l.props.paddingTop==null&&(l.props.paddingTop=n),l.props.paddingBottom==null&&(l.props.paddingBottom=n))}}return e}function ie(e){if(e==null||e.type==="photo"||e.type==="path")return;if(e.type==="text"){let o=new Set;for(let r of e.children)if(typeof r!="string"&&r.props.font!=null)for(let a of r.props.font)o.add(a);if(e.props.font!=null)for(let r of e.props.font)o.add(r);return o}let t=new Set;for(let o of e.children){let r=ie(o);if(r!=null)for(let a of r)t.add(a)}return t}function ae(e,t,o){if(e==null)return;if(e.type==="text-default")throw new Error("The layout includes TextDefaut node which is illegal!");let r=o.Node.create();if(Te(e.props,r),e.type==="photo")return r;if(e.type==="text"){let a=(s,i,n,u)=>{let{props:l,children:d}=e,c=0,p=0,T=(0,oe.klona)(l),g=b=>{let w={...T,size:b},P=te(d,s,w,t.measureText,t.breakIterator),R=0,y=0;for(let{paragraph:x}of P)x.width>R&&(R=x.width),y+=x.height;return{blocks:P,width:R,height:y}},m=te(d,s,T,t.measureText,t.breakIterator);for(let{paragraph:b}of m)b.width>c&&(c=b.width),p+=b.height;if(l.autofit&&!Number.isNaN(n)&&u===N.MeasureMode.Exactly){let b=1,w=200,P=T.size||12;if(g(P).height<=n)for(;w-b>1;){let x=Math.floor((b+w)/2);g(x).height<=n?(b=x,P=x):w=x}else for(w=P;w-b>1;){let x=Math.floor((b+w)/2);g(x).height<=n?(b=x,P=x):w=x}let y=g(P);m=y.blocks,c=y.width,p=y.height,T.size=P}return i===N.MeasureMode.AtMost&&(c=Math.min(s,c)),e.props.blocks=m,{width:c,height:p}};return r.setMeasureFunc(a),r}if(e.type==="path"){if(e.props.bounds!=null){let[a,s,i,n]=e.props.bounds,u=e.props.scalePath??1;if(e.props.width==null){let l=i-a;r.setWidth(l*u)}if(e.props.height==null){let l=n-s;r.setHeight(l*u)}}return r}for(let a of e.children){if(a==null)continue;let s=ae(a,t,o);s!=null&&r.insertChild(s,r.getChildCount())}if(e.type==="table"){let a=[];for(let s=0;s<r.getChildCount();s++){let i=0;for(let n=0;n<r.getChild(s).getChildCount();n++){a.length-1<n&&a.push(0);let u=r.getChild(s).getChild(n);u.calculateLayout(void 0,void 0);let l=u.getComputedWidth(),d=u.getComputedHeight();i<d&&(i=d),a[n]<l&&(a[n]=l)}for(let n=0;n<r.getChild(s).getChildCount();n++)r.getChild(s).getChild(n).setMinHeight(i)}for(let s=0;s<r.getChildCount();s++)for(let i=0;i<r.getChild(s).getChildCount();i++)r.getChild(s).getChild(i).setMinWidth(a[i])}return r}async function se(e,t,o){let r=await Ce(),a=ie(e);if(a!=null)for(let d of a)d!=="serif"&&d!=="sans-serif"&&d!=="monospace"&&d!=="cursive"&&d!=="fantasy"&&d!=="system-ui"&&(t.hasFont(d)||console.warn(`${JSON.stringify(d)} font has not been registered!`));let s=o==null||o.cache==null?new Map:o.cache,i=0,n=()=>i++,u=await _((0,oe.klona)(e),{defaultTextProps:t.getDefaultTextProps(),loadImage:(0,xe.default)(t.loadImage,{cache:s}),breakIterator:t.breakIterator,createId:n});(o==null||o.cache==null)&&s.clear();let l=ae(u,t,r);if(l==null)throw new Error("Unable to create canvas!");return l.calculateLayout(o?.width,o?.height),{layout:l,compiledNode:u}}async function Mt(e,t,o){let{compiledNode:r,layout:a}=await se(e,t,o),s=t.createCanvas(a.getComputedWidth(),a.getComputedHeight());ue(s,r,t,a,o);let i=Le(r,a);return{canvas:s,metadata:i}}function ue(e,t,o,r,a){let s=e.getContext("2d");a?.background&&(s.fillStyle=a.background,s.fillRect(0,0,e.width,e.height));function i(n,u,l,d){if(n!=null)try{if(s.save(),n.type!=="text-default"&&le(s,n,u,l,d),n.type==="text-default")return;if(n.type==="text"){X(o,s,n,u,l,d),Re(o,s,n,u,l,d);return}if(n.type==="photo"){K(o,s,n,u,l,d);return}if(n.type==="path"){X(o,s,n,u,l,d),Be(o,s,n,l,d);return}X(o,s,n,u,l,d);for(let c=0;c<n.children.length;c++){let p=u.getChild(c),T=n.children[c];i(T,p,l+p.getComputedLeft(),d+p.getComputedTop())}n.type==="table"&&qe(o,s,n,u,l,d)}finally{s.restore(),o.debug().layout&&ve(o,s,n,u,l,d)}}i(t,r,0,0)}function Le(e,t){function o(r,a,s,i){if(r==null||r.type==="text-default")return;let n=r.props,u=r.type,l={x:s,y:i,width:a.getComputedWidth(),height:a.getComputedHeight(),position:{top:a.getComputedTop(),bottom:a.getComputedBottom(),left:a.getComputedLeft(),right:a.getComputedRight()},padding:{top:a.getComputedPadding(N.Edge.Top),left:a.getComputedPadding(N.Edge.Left),right:a.getComputedPadding(N.Edge.Right),bottom:a.getComputedPadding(N.Edge.Bottom)},margin:{top:a.getComputedMargin(N.Edge.Top),left:a.getComputedMargin(N.Edge.Left),right:a.getComputedMargin(N.Edge.Right),bottom:a.getComputedMargin(N.Edge.Bottom)}};if(u==="text")return{type:u,children:r.children,props:r.props,...l};let d=[];if(u==="column"||u==="row"||u==="table"||u==="table-row"||u==="table-cell")for(let c=0;c<r.children.length;c++){let p=a.getChild(c),T=r.children[c];if(T==null)continue;let g=o(T,p,s+p.getComputedLeft(),i+p.getComputedTop());g!=null&&d.push(g)}return{type:u,props:n,children:d,...l}}return o(e,t,0,0)}async function Dt(e,t,o){let{layout:r,compiledNode:a}=await se(e,t,o),s=t.createCanvas(r.getComputedWidth(),r.getComputedHeight());return ue(s,a,t,r,o),r.freeRecursive(),s}function X(e,t,o,r,a,s){let i=r.getComputedWidth(),n=r.getComputedHeight(),u=o.props,l=V(e,i,n,F(u.cornerRadius??[0],Math.min(i,n)),u.cornerSmoothing,u.corner);if(u.background!=null&&u.shadows)for(let d of u.shadows)typeof d!="string"&&(t.save(),t.shadowOffsetX=d.offsetX,t.shadowOffsetY=d.offsetY,t.shadowBlur=d.blurRadius,d.color&&(t.shadowColor=d.color,t.fillStyle=d.color),t.translate(a,s),t.fill(l),t.restore());if(t.save(),t.translate(a,s),t.clip(l),t.translate(-a,-s),u.background!=null)for(let d of u.background){if(typeof d=="string"){t.fillStyle=d,t.fillRect(a,s,i,n);continue}if(d.type==="photo"){t.save(),le(t,d,r,a,s),K(e,t,d,r,a,s),t.restore();continue}let[c]=O(t,[d],a,s,i,n);t.fillStyle=c,t.fillRect(a,s,i,n)}return t.restore(),E(t,r,u,l,a,s),l}function le(e,t,o,r,a){if(t==null||t.type==="text-default")return;typeof t.props.opacity=="number"&&(e.globalAlpha=t.props.opacity);let{translateX:s,translateY:i}=t.props;e.translate(s??0,i??0);let n=r+o.getComputedWidth()/2,u=a+o.getComputedHeight()/2,l=t.props.rotation;typeof l=="number"&&l!==0&&(e.translate(n,u),e.rotate(l*Math.PI/180),e.translate(-n,-u));let d=t.props.scale;if(d!=null&&Array.isArray(d)&&(e.translate(n,u),e.scale(d[0],d[1]),e.translate(-n,-u)),t.props.filters!=null&&Array.isArray(t.props.filters)){let c=t.props.filters.join(" ");e.filter=c}}function ve(e,t,o,r,a,s){if(o==null||o.type==="text-default")return;t.save(),t.lineWidth=2,t.strokeStyle="cyan",t.strokeRect(a,s,r.getComputedWidth(),r.getComputedHeight());let i=o.props.tag!=null?`${o.type}:${o.props.tag}`:o.type;t.font=`${20*e.dpr()}px monospace`;let n=t.measureText(i);t.fillStyle="rgba(0,255,255,.6)",t.fillRect(a,s,n.width,n.fontBoundingBoxAscent+n.fontBoundingBoxDescent),t.strokeStyle="cyan",t.strokeRect(a,s,n.width,n.fontBoundingBoxAscent+n.fontBoundingBoxDescent),t.fillStyle="black",t.textBaseline="top",t.fillText(i,a,s),t.restore()}function Be(e,t,o,r,a){t.save();let{props:s}=o,{d:i}=s;if(!i){t.restore();return}let n=new e.Path2D(i);if(t.translate(r,a),s.bounds){let[u,l]=s.bounds;t.scale(s.scalePath??1,s.scalePath??1),t.translate(-u,-l)}if(s.fill!=null){if(t.fillStyle=s.fill,s.fillOpacity!=null){let u=t.globalAlpha;t.globalAlpha=u*s.fillOpacity}s.fillRule?t.fill(n,s.fillRule):t.fill(n),s.fillOpacity!=null&&(t.globalAlpha=t.globalAlpha/s.fillOpacity)}s.stroke!=null&&(t.strokeStyle=s.stroke,s.strokeWidth!=null&&(t.lineWidth=s.strokeWidth),s.strokeLineCap&&(t.lineCap=s.strokeLineCap),s.strokeLineJoin&&(t.lineJoin=s.strokeLineJoin),s.strokeMiterLimit!=null&&(t.miterLimit=s.strokeMiterLimit),s.strokeDashArray!=null&&t.setLineDash(s.strokeDashArray),s.strokeDashOffset!=null&&(t.lineDashOffset=s.strokeDashOffset),t.stroke(n)),t.restore()}function qe(e,t,o,r,a,s){t.save();let i=0;o.props.borderColor!=null&&(t.strokeStyle=o.props.borderColor),o.props.borderWidth!=null&&(t.lineWidth=o.props.borderWidth,i=o.props.borderWidth);let n=0,u=-1;t.beginPath();for(let l=0;l<r.getChildCount();l++){let d=r.getChild(l);(u===-1||d.getChildCount()>r.getChild(u).getChildCount())&&(u=l),l!==r.getChildCount()-1&&(t.moveTo(a,s+d.getComputedHeight()+n+i),t.lineTo(a+r.getComputedWidth(),s+d.getComputedHeight()+n+i),n+=d.getComputedHeight())}if(u!==-1){let l=r.getChild(u),d=0;for(let c=0;c<l.getChildCount();c++){let p=l.getChild(c);c>0&&(t.moveTo(a+d+i,s),t.lineTo(a+d+i,s+r.getComputedHeight())),d+=p.getComputedWidth()}}t.stroke(),t.restore()}0&&(module.exports={Column,DEFAULT_TEXT_PROPS,Path,Photo,Row,Span,Table,TableCell,TableRow,Text,TextDefault,applySpanProps,calculateLayout,compile,createLayoutNode,createMetadata,defaultLineBreakerIterator,drawDebugBBox,drawLayoutNode,drawOnCanvas,drawPathNode,drawTableNode,findFonts,fontBuilder,getYogaLayout,makeTransforms,pathPropsBuilder,qrcode,render,renderWithMetadata});