UNPKG

sone

Version:

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

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