UNPKG

sone

Version:

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

3 lines (2 loc) 43.3 kB
import{Buffer as Bt}from"buffer";import E,{FontLibrary as qt}from"skia-canvas";var U=null,Ae="\u17D4\u17D5)]?!\xBB\u17D6",Me="([\xAB";function*he(e){U==null&&(U=new Intl.Segmenter(void 0,{granularity:"word"}));for(let t of U.segment(e)){if(t.segment.endsWith("\u17D2"))continue;let o=e[t.index];if(o!==void 0&&Ae.indexOf(o)!==-1)continue;let r=e[t.index-1];r!==void 0&&Me.indexOf(r)!==-1||(yield t.index)}}import{parse as ie}from"gradient-parser";import{klona as ke}from"klona";import ct from"object.pick";import mt from"p-memoize";import bt from"svg-path-bounds";import{Edge as D,loadYoga as Tt,MeasureMode as Re}from"yoga-layout/load";var pe={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 De=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,He=/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/,Ie=/^hsl\(\s*(\d+)\s*,\s*(\d*(?:\.\d+)?%)\s*,\s*(\d*(?:\.\d+)?%)\)$/,ze=/^hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*(\d*(?:\.\d+)?)\)$/,$e=/^#([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 pe?!0:De.test(e)||He.test(e)||Ie.test(e)||ze.test(e)||$e.test(e)}function Ee(e){switch(e.type){case"hex":return`#${e.value}`;case"literal":return e.value;default:return`${e.type}(${e.value.join(",")})`}}function Oe(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,Ee(r)];let s=Oe(r,e.length,a,t);return o.locations=[...o.locations,s],o},{colors:[],locations:[]})}function Ge(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 p=0;p<u;p++)for(let h of a)l.push(h/o+n*p);return{colors:l.map((p,h)=>r[h%r.length]),locations:l}}function Fe(e){return Math.round(e*1e4)/1e4}function Ve(e){return e*Math.PI/180}var Ye=e=>e==null?A(180):e.type==="directional"?je(e.value):A(Number(e.value));function A(e){let t=Ve(e),o=Fe(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 je(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 Xe(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):Ge(a,t),n=Ye(s),u={...i,...n};o.push(u)}return o}function F(e,t,o,r,a,s){let i=Xe(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 p=u.colors[d],h=u.locations[d];h<0&&(h=0),h>1&&(h=1),l.addColorStop(h,p)}n.push(l)}return n}import{Edge as V}from"yoga-layout/load";function Y(e,t,o,r,a,s){let i=t.getComputedBorder(V.Left),n=t.getComputedBorder(V.Top),u=t.getComputedBorder(V.Right),l=t.getComputedBorder(V.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())}import{getSvgPath as _e}from"figma-squircle";function j(e,t){for(let o=0;o<e.length;o++)e[o]=Math.max(0,Math.min(e[o],t/2));return e}function X(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=_e({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 Q(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",p=n.width,h=n.height,b=a,g=s,c=u,m=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;p=n.width,h=n.height,c=k,m=l,b=a+(u-k)*R}else{let k=n.height*u/n.width;p=n.width,h=n.height,c=u,m=k,g=s+(l-k)*R}break;case"contain":w>P?(c=u,m=u/w,g=s+(l-m)*R):(m=l,c=l*w,b=a+(u-c)*R);break}t.save();let y=X(e,u,l,j(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=b+c/2,C=g+m/2;t.translate(k,C),t.scale(x?-1:1,q?-1:1),t.translate(-k,-C)}t.drawImage(n,0,0,p,h,b,g,c,m),t.restore(),(i.borderWidth!=null||i.borderTopWidth!=null||i.borderLeftWidth!=null||i.borderRightWidth!=null||i.borderBottomWidth!=null)&&Y(t,r,i,y,a,s)}import{Align as W,BoxSizing as ce,Direction as me,Display as K,Edge as T,FlexDirection as _,Gutter as Z,Justify as z,Overflow as ee,PositionType as te,Wrap as re}from"yoga-layout/load";function Te(e,t){for(let o of Object.keys(e))switch(o){case"alignContent":t.setAlignContent(Je(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(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(Ue(e.boxSizing));break;case"direction":t.setDirection(Qe(e.direction));break;case"display":t.setDisplay(Ke(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(Ze(e.flexDirection));break;case"rowGap":t.setGap(Z.Row,e.rowGap);break;case"gap":t.setGap(Z.All,e.gap);break;case"columnGap":t.setGap(Z.Column,e.columnGap);break;case"flexGrow":t.setFlexGrow(e.flexGrow);break;case"flexShrink":t.setFlexShrink(e.flexShrink);break;case"flexWrap":t.setFlexWrap(et(e.flexWrap));break;case"height":t.setHeight(e.height);break;case"justifyContent":t.setJustifyContent(tt(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(rt(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(nt(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 Je(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 be(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 Ue(e){switch(e){case"border-box":return ce.BorderBox;case"content-box":return ce.ContentBox}}function Qe(e){switch(e){case"ltr":return me.LTR;case"rtl":return me.RTL}}function Ke(e){switch(e){case"none":return K.None;case"flex":return K.Flex;case"contents":return K.Contents}}function Ze(e){switch(e){case"row":return _.Row;case"column":return _.Column;case"row-reverse":return _.RowReverse;case"column-reverse":return _.ColumnReverse}}function et(e){switch(e){case"wrap":return re.Wrap;case"nowrap":return re.NoWrap;case"wrap-reverse":return re.WrapReverse}}function tt(e){switch(e){case"flex-start":return z.FlexStart;case"flex-end":return z.FlexEnd;case"center":return z.Center;case"space-between":return z.SpaceBetween;case"space-around":return z.SpaceAround;case"space-evenly":return z.SpaceEvenly}}function rt(e){switch(e){case"visible":return ee.Visible;case"hidden":return ee.Hidden;case"scroll":return ee.Scroll}}function nt(e){switch(e){case"absolute":return te.Absolute;case"relative":return te.Relative;case"static":return te.Static}}var ot=/,(?![^(]*\))/,it=/\s(?![^(]*\))/,at=/^[0-9]+[a-zA-Z%]+?$/;function st(e){let t=e.split(it),o=t.includes("inset"),r=t.slice(-1)[0],a=ut(r)?void 0:r,s=t.filter(d=>d!=="inset").filter(d=>d!==a).map(lt),[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 ut(e){return e==="0"||at.test(e)}function lt(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(ot).map(t=>t.trim()).map(st);import{dequal as ft}from"dequal";import{klona as ht}from"klona";import{Edge as M}from"yoga-layout/load";function ye(e){let t=e.font!=null?e.font?.join(", "):"",o=e.size??"",r=e.weight??"";return`${e.style??""} ${r} ${o}px ${t}`.trim()}function $(e,t){e.font=ye(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 we(e,t){let o=[],r=e.indexOf(t);for(;r!==-1;)o.push(r),r=e.indexOf(t,r+1);return o}var dt=/^\s+$/;function ne(e){return e.length===0?!1:dt.test(e)}function pt(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 h=0;h<e.length;h++){let b=e[h],g=typeof b=="string"?r:b.props,c=typeof b=="string"?b:b.children,m=t[h]||[];if(m.length===0){let P=a(c,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=c.trimStart();if(q!==c){let k=a(q,g);R=k.width,y=k.fontBoundingBoxAscent+k.fontBoundingBoxDescent;let C={metrics:k,props:g,text:q,width:R,height:y};n.segments.push(C),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:c,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=c.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 S=n.segments[n.segments.length-1],L=S.text.trimEnd();if(L!==S.text&&L.length>0){let v=a(L,S.props),N=v.width,I=v.fontBoundingBoxAscent+v.fontBoundingBoxDescent;S.text=L,S.metrics=v,S.width=N,S.height=I,n.width=n.segments.reduce((fe,B)=>fe+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 S=a(f,g),L=S.width,v=S.fontBoundingBoxAscent+S.fontBoundingBoxDescent,N={metrics:S,props:g,text:f,width:L,height:v};n.segments.push(N),n.width+=L,n.height=Math.max(n.height,v),n.baseline=Math.max(n.baseline,S.fontBoundingBoxAscent),w=R;continue}}let C={metrics:x,props:g,text:y,width:q,height:k};n.segments.push(C),n.width+=q,n.height=Math.max(n.height,k),n.baseline=Math.max(n.baseline,x.fontBoundingBoxAscent),w=R}if(w<c.length){let P=c.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 C=n.segments[n.segments.length-1],f=C.text.trimEnd();if(f!==C.text&&f.length>0){let S=a(f,C.props),L=S.width,v=S.fontBoundingBoxAscent+S.fontBoundingBoxDescent;C.text=f,C.metrics=S,C.width=L,C.height=v,n.width=n.segments.reduce((N,I)=>N+I.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 C=a(k,g),f=C.width,S=C.fontBoundingBoxAscent+C.fontBoundingBoxDescent,L={metrics:C,props:g,text:k,width:f,height:S};n.segments.push(L),n.width+=f,n.height=Math.max(n.height,S),n.baseline=Math.max(n.baseline,C.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 h of i){let b=[];for(let g=0;g<h.segments.length;g++){let c=h.segments[g];if(ne(c.text)&&(g===h.segments.length-1||g===0)){h.width-=c.width;continue}b.push(c)}h.segments=b}let u=0;for(let h of i){h.baseline*=s,h.height*=s;let b=0,g=Number.POSITIVE_INFINITY;for(let c of h.segments){let m=c.props.offsetY??0;m>b&&(b=m),m<g&&(g=m)}if(h.baseline-=g,h.height-=g,h.height+=b,u<i.length-1)for(let c of h.segments){let m=c.text.match(/[ ]/);m&&(h.spacesCount+=m.length)}u++}let l=0,d=0;for(let h of i)l+=h.height,d=Math.max(d,h.width);let p=0;if(i.length>0&&r.lineHeight!=null&&!Number.isNaN(r.lineHeight)){let h=Math.max(0,r.lineHeight-1);for(let b of i[0].segments){let g=b.metrics,c=-((g.fontBoundingBoxAscent-g.fontBoundingBoxDescent)/2)*h;c<p&&(p=c)}}return{width:d,height:l,lines:i,offsetY:p}}function gt(e,t){let o=[[]];for(let a of e){let s=typeof a=="string"?a:a.children,i=we(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 p=ht(a);p.children=d,o[o.length-1].push(p)}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 oe(e,t,o,r,a){let[s,i]=gt(e,a),n=[];for(let u=0;u<s.length;u++){let l=i[u],d=s[u],p=pt(d,l,t,o,r);for(let h of p.lines){let b=[[]];for(let c of h.segments){let m=b[b.length-1];if(m.length>0){let w=m[m.length-1];if(o.align==="justify"&&ne(c.text)){b.push([c]),b.push([]);continue}if(!ft(w.props,c.props)){b.push([c]);continue}}m.push(c)}let g=[];for(let c of b){if(c.length===0)continue;if(c.length===1){g.push(c[0]);continue}let m=c.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}),c[0]);g.push(m)}h.segments=g}n.push({paragraph:p})}return n}function Pe(e,t,o,r,a,s){let{props:i}=o,{blocks:n}=i;if(n==null)return;let u=r.getComputedBorder(M.Left)+r.getComputedBorder(M.Right)+r.getComputedPadding(M.Left)+r.getComputedPadding(M.Right),l=0;for(let{paragraph:d}of n){d.width=Math.max(r.getComputedWidth(),d.width)-u;let p=i.boxSizing==="content-box"?r.getComputedPadding(M.Left):0,h=i.boxSizing==="content-box"?r.getComputedPadding(M.Top):0,b=r.getComputedBorder(M.Left),g=r.getComputedBorder(M.Top),c=p+b,m=h+g,w=i.align;$(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 C=0;C<y.segments.length;C++){let f=y.segments[C],S=f.props.offsetY??0,L=f.width;w==="justify"&&/[ ]/.test(f.text)&&(L+=q);let v=a+c+k,N=s+y.baseline+m+P+S;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,N+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,N-f.metrics.fontBoundingBoxAscent,L,B)}let I=N-f.height+f.metrics.fontBoundingBoxDescent;if(f.props.highlightColor!=null&&(t.fillStyle=f.props.highlightColor,t.fillRect(v,I,L,f.height)),$(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,N),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,N)),typeof f.props.color!="string"&&Array.isArray(f.props.color))for(let B of f.props.color){let[We]=F(t,[B],a,s,f.width,f.height);t.fillStyle=We}if(t.fillText(f.text,v,N),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,N-(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,I,L,f.height),t.restore()),k+=L}P+=y.height}}}var yt=Tt();async function wt(){return yt}var xe={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 ae(e){return Object.fromEntries(Object.entries(e).filter(([t,o])=>o!=null))}function se(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 le(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(...J(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=ie(n);i.push(...u);continue}}else n.type==="photo"&&(typeof n.props.src=="string"||Buffer.isBuffer(n.props.src))&&se(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,...ae(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(...J(n)):i.push(n);e.props.dropShadows=i}return typeof e.props.color=="string"&&(G(e.props.color)||(e.props.color=ie(e.props.color))),e.children.map(i=>{if(typeof i=="string")return i;let n=ct(e.props,["size","color","font","style","weight","letterSpacing","wordSpacing","strokeColor","strokeWidth","underline","underlineColor","overline","overlineColor","lineThrough","lineThroughColor","highlightColor","dropShadows"]);if(i.props={...ae(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(...J(l)):u.push(l);i.props.dropShadows=u}return typeof i.props.color=="string"&&(G(i.props.color)||(i.props.color=ie(i.props.color))),i}),e}if(e.type==="photo")return typeof e.props.src=="string"||Buffer.isBuffer(e.props.src)?(se(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 se(i,await o(i.props.src)),e}if(e.type==="path")return e.props.d&&(e.props.bounds=bt(e.props.d)),e;let s=[];for(let i of e.children)if(i!=null){if(i.type==="text-default"){let n={...t,...ae(i.props)};for(let u of i.children)u!=null&&s.push(await le(u,{defaultTextProps:n,loadImage:o,breakIterator:r,createId:a}));continue}s.push(await le(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 Ce(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=Ce(o);if(r!=null)for(let a of r)t.add(a)}return t}function Se(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,p=0,h=0,b=ke(l),g=m=>{let w={...b,size:m},P=oe(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}},c=oe(d,s,b,t.measureText,t.breakIterator);for(let{paragraph:m}of c)m.width>p&&(p=m.width),h+=m.height;if(l.autofit&&!Number.isNaN(n)&&u===Re.Exactly){let m=1,w=200,P=b.size||12;if(g(P).height<=n)for(;w-m>1;){let x=Math.floor((m+w)/2);g(x).height<=n?(m=x,P=x):w=x}else for(w=P;w-m>1;){let x=Math.floor((m+w)/2);g(x).height<=n?(m=x,P=x):w=x}let y=g(P);c=y.blocks,p=y.width,h=y.height,b.size=P}return i===Re.AtMost&&(p=Math.min(s,p)),e.props.blocks=c,{width:p,height:h}};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=Se(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 Le(e,t,o){let r=await wt(),a=Ce(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 le(ke(e),{defaultTextProps:t.getDefaultTextProps(),loadImage:mt(t.loadImage,{cache:s}),breakIterator:t.breakIterator,createId:n});(o==null||o.cache==null)&&s.clear();let l=Se(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 ve(e,t,o){let{compiledNode:r,layout:a}=await Le(e,t,o),s=t.createCanvas(a.getComputedWidth(),a.getComputedHeight());Be(s,r,t,a,o);let i=Pt(r,a);return{canvas:s,metadata:i}}function Be(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"&&Ne(s,n,u,l,d),n.type==="text-default")return;if(n.type==="text"){ue(o,s,n,u,l,d),Pe(o,s,n,u,l,d);return}if(n.type==="photo"){Q(o,s,n,u,l,d);return}if(n.type==="path"){ue(o,s,n,u,l,d),kt(o,s,n,l,d);return}ue(o,s,n,u,l,d);for(let p=0;p<n.children.length;p++){let h=u.getChild(p),b=n.children[p];i(b,h,l+h.getComputedLeft(),d+h.getComputedTop())}n.type==="table"&&xt(o,s,n,u,l,d)}finally{s.restore(),o.debug().layout&&Rt(o,s,n,u,l,d)}}i(t,r,0,0)}function Pt(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(D.Top),left:a.getComputedPadding(D.Left),right:a.getComputedPadding(D.Right),bottom:a.getComputedPadding(D.Bottom)},margin:{top:a.getComputedMargin(D.Top),left:a.getComputedMargin(D.Left),right:a.getComputedMargin(D.Right),bottom:a.getComputedMargin(D.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 h=a.getChild(p),b=r.children[p];if(b==null)continue;let g=o(b,h,s+h.getComputedLeft(),i+h.getComputedTop());g!=null&&d.push(g)}return{type:u,props:n,children:d,...l}}return o(e,t,0,0)}async function qe(e,t,o){let{layout:r,compiledNode:a}=await Le(e,t,o),s=t.createCanvas(r.getComputedWidth(),r.getComputedHeight());return Be(s,a,t,r,o),r.freeRecursive(),s}function ue(e,t,o,r,a,s){let i=r.getComputedWidth(),n=r.getComputedHeight(),u=o.props,l=X(e,i,n,j(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(),Ne(t,d,r,a,s),Q(e,t,d,r,a,s),t.restore();continue}let[p]=F(t,[d],a,s,i,n);t.fillStyle=p,t.fillRect(a,s,i,n)}return t.restore(),Y(t,r,u,l,a,s),l}function Ne(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 p=t.props.filters.join(" ");e.filter=p}}function Rt(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 kt(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 xt(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 p=0;p<l.getChildCount();p++){let h=l.getChild(p);p>0&&(t.moveTo(a+d+i,s),t.lineTo(a+d+i,s+r.getComputedHeight())),d+=h.getComputedWidth()}}t.stroke(),t.restore()}function H(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 de(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 Ct(e={}){return{...H(e),...de(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 pr(e){return{type:"span",children:e,...de()}}function St(e){return{...de(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 gr(...e){return{type:"text-default",children:e,...St({})}}function cr(...e){return{id:-1,type:"text",children:e.filter(t=>t!=null),...Ct()}}function mr(...e){return{id:-1,type:"column",children:e,...H()}}function br(...e){return{id:-1,type:"row",children:e,...H()}}function Tr(e){let t={src:e};return{id:-1,type:"photo",...H(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 Lt(e){return{...H(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 yr(e){let t={d:e};return{id:-1,type:"path",...Lt(t),props:t}}function wr(...e){let t={};return{id:-1,type:"table",children:e,...H(t),spacing(...o){return t.spacing=o,this}}}function Pr(...e){return{id:-1,type:"table-row",children:e,...H({})}}function Rr(...e){let t={};return{id:-1,type:"table-cell",children:e,...H(t),colspan(o){return t.colspan=o,this},rowspan(o){return t.rowspan=o,this},props:t}}import{encode as vt}from"uqr";function Cr(e,t={}){let o=vt(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 p=0;p<o.size;p++){let h=p*r,b=d*r;o.data[d][p]&&l.push(`M${h},${b}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 Nt=new E.Canvas(1,1),O={debug(){return{layout:!1,text:!1}},hasFont:e=>qt.has(e),Path2D:E.Path2D,breakIterator:he,createCanvas(e,t){return new E.Canvas(e,t)},measureText(e,t){let o=Nt.getContext("2d");return $(o,t),o.measureText(e)},async registerFont(e,t){E.FontLibrary.use(e,t)},async unregisterFont(){},resetFonts(){E.FontLibrary.reset()},async loadImage(e){return E.loadImage(typeof e=="string"?e:Bt.from(e))},getDefaultTextProps(){return xe},dpr(){return 1}};function Ar(e,t){let o=async()=>qe(e,O,t);return{jpg:async(r=1,a)=>(await o()).toBuffer("jpg",{quality:r,...a}),png:async r=>(await o()).toBuffer("png",r),svg:async r=>(await o()).toBuffer("svg",r),pdf:async r=>(await o()).toBuffer("pdf",r),webp:async r=>(await o()).toBuffer("webp",r),raw:async r=>(await o()).toBuffer("raw",r),canvas:async()=>o(),canvasWithMetadata:async()=>ve(e,O,t)}}var Mr={async load(e,t){return O.registerFont(e,t)},async unload(e){return O.unregisterFont(e)},has(e){return O.hasFont(e)}};export{mr as Column,xe as DEFAULT_TEXT_PROPS,Mr as Font,yr as Path,Tr as Photo,br as Row,pr as Span,wr as Table,Rr as TableCell,Pr as TableRow,cr as Text,gr as TextDefault,$ as applySpanProps,Le as calculateLayout,le as compile,Se as createLayoutNode,Pt as createMetadata,he as defaultLineBreakerIterator,Rt as drawDebugBBox,ue as drawLayoutNode,Be as drawOnCanvas,kt as drawPathNode,xt as drawTableNode,Ce as findFonts,ye as fontBuilder,wt as getYogaLayout,Ne as makeTransforms,Lt as pathPropsBuilder,Cr as qrcode,qe as render,ve as renderWithMetadata,O as renderer,Ar as sone};