satori 0.0.6 → 0.0.8-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  Satori
3
3
  </h1>
4
4
 
5
- ## Quick Start
5
+ ## API
6
6
 
7
7
  `satori` is a function that takes a JSX element and returns a SVG string:
8
8
 
@@ -21,6 +21,8 @@ satori(
21
21
  },
22
22
  ...
23
23
  ],
24
+ embedFont: true, // Embed the font in SVG as path data
25
+ debug: false, // Show/hide the bounding box
24
26
  }
25
27
  )
26
28
  ```
@@ -101,7 +103,8 @@ For example, the `<input>` HTML element, the `cursor` CSS property are not in co
101
103
  Note:
102
104
 
103
105
  1. Three-dimensional transforms are not supported.
104
- 2. There is no `z-index` support in SVG. Elements that come later in the document will be drawn on top.
106
+ 2. There is no `z-index` support in SVG. Elements that come later in the document will be painted on top.
107
+ 3. `box-sizing` is set to `border-box` for all elements.
105
108
 
106
109
  ## Contribute
107
110
 
@@ -118,6 +121,10 @@ cd playground
118
121
  pnpm dev
119
122
  ```
120
123
 
124
+ And visit localhost:3000/test.
125
+
126
+ To start the development mode, run `pnpm dev` in the root directory (can be used together with the playground to view it in live).
127
+
121
128
  To start and live-watch the tests, run:
122
129
 
123
130
  ```bash
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- var at=Object.defineProperty,st=Object.defineProperties;var ft=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var ut=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable;var K=(t,n,e)=>n in t?at(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,I=(t,n)=>{for(var e in n||(n={}))ut.call(n,e)&&K(t,e,n[e]);if(q)for(var e of q(n))lt.call(n,e)&&K(t,e,n[e]);return t},Q=(t,n)=>st(t,ft(n));import v from"yoga-layout-prebuilt";import _t from"yoga-layout-prebuilt";function D(t){let n=typeof t;return!(n==="number"||n==="bigint"||n==="string"||n==="boolean")}function Z(t){return/^class\s/.test(Function.prototype.toString.call(t))}function L(t,n){return[t[0]*n[0]+t[2]*n[1],t[1]*n[0]+t[3]*n[1],t[0]*n[2]+t[2]*n[3],t[1]*n[2]+t[3]*n[3],t[0]*n[4]+t[2]*n[5]+t[4],t[1]*n[4]+t[3]*n[5]+t[5]]}import a from"yoga-layout-prebuilt";var tt={p:{display:"block",marginTop:"1em",marginBottom:"1em"},div:{display:"block"},blockquote:{display:"block",marginTop:"1em",marginBottom:"1em",marginLeft:40,marginRight:40},center:{display:"block",textAlign:"center"},hr:{display:"block",marginTop:"0.5em",marginBottom:"0.5em",marginLeft:"auto",marginRight:"auto",borderWidth:1,borderStyle:"inset"},h1:{display:"block",fontSize:"2em",marginTop:"0.67em",marginBottom:"0.67em",marginLeft:0,marginRight:0,fontWeight:"bold"},h2:{display:"block",fontSize:"1.5em",marginTop:"0.83em",marginBottom:"0.83em",marginLeft:0,marginRight:0,fontWeight:"bold"},h3:{display:"block",fontSize:"1.17em",marginTop:"1em",marginBottom:"1em",marginLeft:0,marginRight:0,fontWeight:"bold"},h4:{display:"block",marginTop:"1.33em",marginBottom:"1.33em",marginLeft:0,marginRight:0,fontWeight:"bold"},h5:{display:"block",fontSize:"0.83em",marginTop:"1.67em",marginBottom:"1.67em",marginLeft:0,marginRight:0,fontWeight:"bold"},h6:{display:"block",fontSize:"0.67em",marginTop:"2.33em",marginBottom:"2.33em",marginLeft:0,marginRight:0,fontWeight:"bold"},u:{textDecoration:"underline"},strong:{fontWeight:"bold"},b:{fontWeight:"bold"},i:{fontStyle:"italic"},em:{fontStyle:"italic"},code:{fontFamily:"monospace"},kbd:{fontFamily:"monospace"},pre:{display:"block",fontFamily:"monospace",whiteSpace:"pre",marginTop:"1em",marginBottom:"1em"},mark:{backgroundColor:"yellow",color:"black"},big:{fontSize:"larger"},small:{fontSize:"smaller"},s:{textDecoration:"line-through"}};var ct=new Set(["color","font","fontFamily","fontSize","fontStyle","fontWeight","lineHeight","textAlign","textTransform","whiteSpace","letterSpacing","transform","opacity"]);function M(t){let n={};for(let e in t)ct.has(e)&&(n[e]=t[e]);return n}import mt,{getPropertyName as pt}from"css-to-react-native";import nt from"parse-css-dimension";import{parseElementStyle as dt}from"css-background-parser";var gt=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),et=[1,0,0,1,0,0];function ht(t,n){return typeof n=="number"?gt.has(t)?String(n):n+"px":n}function rt(t,n){if(typeof t=="number")return t;try{let e=new nt(t);if(e.type==="length")switch(e.unit){case"em":return e.value*n;case"rem":return e.value*16;default:return e.value}else if(e.type==="angle")switch(e.unit){case"deg":return e.value;case"rad":return e.value*180/Math.PI;default:return e.value}}catch{}}function G(t,n){let e=[];for(let r in t){let i=pt(r);e.push([i,ht(i,t[r])])}let o=mt(e);if(o.backgroundImage){let{backgrounds:r}=dt(o);o.backgroundImage=r}let s=o.fontSize||n.fontSize;if(typeof s=="string")try{let r=new nt(s);switch(r.unit){case"em":s=r.value*n.fontSize;break;case"rem":s=r.value*16;break}}catch{s=16}o.fontSize=s;for(let r in o){let i=o[r];if(typeof i=="string"){let f=rt(i,s);typeof f!="undefined"&&(o[r]=f),i=o[r]}if(r==="opacity"&&(i=o[r]=i*n.opacity),r==="transform"){let f=[...et],c=i;for(let l of c){let d=Object.keys(l)[0],p=l[d],m=typeof p=="string"?rt(p,s):p,u=[...et];switch(d){case"translateX":u[4]=m;break;case"translateY":u[5]=m;break;case"scaleX":u[0]=m;break;case"scaleY":u[3]=m;break;case"rotate":let g=m*Math.PI/180,h=Math.cos(g),E=Math.sin(g);u[0]=h,u[1]=E,u[2]=-E,u[3]=h;break;case"skewX":u[2]=Math.tan(m*Math.PI/180);break;case"skewY":u[1]=Math.tan(m*Math.PI/180);break}f=L(u,f)}o.transform=f}}return o}function T(t,n,e){let o=n[t];return typeof o=="undefined"?e:o}function w(t,n,e,o,s){let r=I(I(I({},e),G(tt[n],e)),G(o,e));if(n==="img"){let i=parseInt(s.width),c=parseInt(s.height)/i;r.width||(r.width=i),r.height||(r.height=c*r.width)}return t.setDisplay(T(r.display,{flex:a.DISPLAY_FLEX,none:a.DISPLAY_NONE},a.DISPLAY_FLEX)),t.setAlignContent(T(r.alignContent,{stretch:a.ALIGN_STRETCH,center:a.ALIGN_CENTER,"flex-start":a.ALIGN_FLEX_START,"flex-end":a.ALIGN_FLEX_END,"space-between":a.ALIGN_SPACE_BETWEEN,"space-around":a.ALIGN_SPACE_AROUND,baseline:a.ALIGN_BASELINE,normal:a.ALIGN_AUTO},a.ALIGN_AUTO)),t.setAlignItems(T(r.alignItems,{stretch:a.ALIGN_STRETCH,center:a.ALIGN_CENTER,"flex-start":a.ALIGN_FLEX_START,"flex-end":a.ALIGN_FLEX_END,baseline:a.ALIGN_BASELINE,normal:a.ALIGN_AUTO},a.ALIGN_FLEX_START)),t.setAlignSelf(T(r.alignSelf,{stretch:a.ALIGN_STRETCH,center:a.ALIGN_CENTER,"flex-start":a.ALIGN_FLEX_START,"flex-end":a.ALIGN_FLEX_END,baseline:a.ALIGN_BASELINE,normal:a.ALIGN_AUTO},a.ALIGN_AUTO)),t.setJustifyContent(T(r.justifyContent,{center:a.JUSTIFY_CENTER,"flex-start":a.JUSTIFY_FLEX_START,"flex-end":a.JUSTIFY_FLEX_END,"space-between":a.JUSTIFY_SPACE_BETWEEN,"space-around":a.JUSTIFY_SPACE_AROUND},a.JUSTIFY_FLEX_START)),typeof r.flexBasis!="undefined"?t.setFlexBasis(r.flexBasis):r.display==="block"&&(typeof r.width=="undefined"||r.width==="auto")&&(typeof r.maxWidth=="undefined"||r.maxWidth==="auto")&&t.setFlexBasisPercent(100),t.setFlexDirection(T(r.flexDirection,{row:a.FLEX_DIRECTION_ROW,column:a.FLEX_DIRECTION_COLUMN,"row-reverse":a.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":a.FLEX_DIRECTION_COLUMN_REVERSE},a.FLEX_DIRECTION_ROW)),t.setFlexGrow(r.flexGrow||0),t.setFlexShrink(r.flexShrink||1),t.setFlexWrap(T(r.flexWrap,{wrap:a.WRAP_WRAP,nowrap:a.WRAP_NO_WRAP,"wrap-reverse":a.WRAP_WRAP_REVERSE},a.WRAP_WRAP)),typeof r.maxHeight!="undefined"&&t.setMaxHeight(r.maxHeight),typeof r.maxWidth!="undefined"&&t.setMaxWidth(r.maxWidth),typeof r.minHeight!="undefined"&&t.setMinHeight(r.minHeight),typeof r.minWidth!="undefined"&&t.setMinWidth(r.minWidth),t.setOverflow(T(r.overflow,{visible:a.OVERFLOW_VISIBLE,hidden:a.OVERFLOW_HIDDEN},a.OVERFLOW_VISIBLE)),t.setMargin(a.EDGE_TOP,r.marginTop||0),t.setMargin(a.EDGE_BOTTOM,r.marginBottom||0),t.setMargin(a.EDGE_LEFT,r.marginLeft||0),t.setMargin(a.EDGE_RIGHT,r.marginRight||0),t.setBorder(a.EDGE_TOP,r.borderWidth||0),t.setBorder(a.EDGE_BOTTOM,r.borderWidth||0),t.setBorder(a.EDGE_LEFT,r.borderWidth||0),t.setBorder(a.EDGE_RIGHT,r.borderWidth||0),t.setPadding(a.EDGE_TOP,r.paddingTop||0),t.setPadding(a.EDGE_BOTTOM,r.paddingBottom||0),t.setPadding(a.EDGE_LEFT,r.paddingLeft||0),t.setPadding(a.EDGE_RIGHT,r.paddingRight||0),t.setPositionType((r.position,a.POSITION_TYPE_ABSOLUTE,a.POSITION_TYPE_RELATIVE,a.POSITION_TYPE_RELATIVE)),typeof r.top!="undefined"&&t.setPosition(a.EDGE_TOP,r.top),typeof r.bottom!="undefined"&&t.setPosition(a.EDGE_BOTTOM,r.bottom),typeof r.left!="undefined"&&t.setPosition(a.EDGE_LEFT,r.left),typeof r.right!="undefined"&&t.setPosition(a.EDGE_RIGHT,r.right),typeof r.height!="undefined"?t.setHeight(r.height):t.setHeightAuto(),typeof r.width!="undefined"?t.setWidth(r.width):t.setWidthAuto(),[r,M(r)]}import x from"yoga-layout-prebuilt";import{LineBreaker as bt}from"css-line-break";function N({left:t,top:n,width:e,height:o},s,r){let i;if(r)i=s;else{let f=t+e/2,c=n+o/2;i=L([1,0,0,1,f,c],L(s,[1,0,0,1,-f,-c])),s.__parent&&(i=L(s.__parent,i)),s.splice(0,6,...i)}return`matrix(${i.join(",")})`}function Y({left:t,top:n,width:e,height:o,isInheritingTransform:s,path:r},i){let f="",c=1;return i.transform&&(f=N({left:t,top:n,width:e,height:o},i.transform,s)),i.opacity&&(c=+i.opacity),`<path fill="${i.color}" ${f?`transform="${f}"`:""} ${c!==1?`opacity="${c}"`:""} d="${r}"></path>`}function*X(t,n){let{parentStyle:e,parent:o,font:s,id:r,isInheritingTransform:i}=n,f=bt(t,{lineBreak:"strict",wordBreak:"normal"}),c=[];for(let u;!(u=f.next()).done;)c.push(u.value.slice());let l=[];o.setAlignItems(x.ALIGN_BASELINE),e.textAlign==="left"?o.setJustifyContent(x.JUSTIFY_FLEX_START):e.textAlign==="center"?o.setJustifyContent(x.JUSTIFY_CENTER):e.textAlign==="right"?o.setJustifyContent(x.JUSTIFY_FLEX_END):e.textAlign==="justify"&&o.setJustifyContent(x.JUSTIFY_SPACE_BETWEEN);for(let u of c){let g=x.Node.create();o.insertChild(g,o.getChildCount());let h=s.measure(u,e),E=(e.letterSpacing||0)*u.length;g.setWidth(h.width+E),g.setHeight(h.ascent*1.2),g.setMargin(x.EDGE_BOTTOM,h.descent*1.2),l.push(g)}let[d,p]=yield,m="";for(let u=0;u<l.length;u++){let g=l[u],h=c[u];e.position==="absolute"&&g.calculateLayout();let{left:E,top:_,width:A,height:S}=g.getComputedLayout();E+=d,_+=p;let $=s.getSVG(h,Q(I({},e),{top:_,left:E,letterSpacing:e.letterSpacing}));m+=Y({id:r,left:E,top:_,width:A,height:S,isInheritingTransform:i,path:$},e)}return m}import yt from"gradient-parser";function Et(t){return t.type==="literal"?t.value:t.type==="hex"?`#${t.value}`:t.type==="rgb"?`rgb(${t.value.join(",")})`:t.type==="rgba"?`rgba(${t.value.join(",")})`:"transparent"}function H({id:t,width:n},{image:e}){if(e.startsWith("linear-gradient(")){let o=yt.parse(e)[0],s,r,i,f;if(o.orientation.type==="directional")[s,r,i,f]={top:[0,1,0,0],bottom:[0,0,0,1],left:[1,0,0,0],right:[0,0,1,0]}[o.orientation.value];else if(o.orientation.type==="angular"){let u=+o.orientation.value/180*Math.PI-Math.PI/2,g=Math.cos(u),h=Math.sin(u);s=0,r=0,i=g,f=h,i<0&&(s-=i,i=0),f<0&&(r-=f,f=0)}let c=n,l=[];for(let u of o.colorStops){let g=Et(u);if(!l.length&&(l.push({offset:0,color:g}),typeof u.length=="undefined"||u.length.value==="0"))continue;let h=typeof u.length=="undefined"?void 0:u.length.type==="%"?u.length.value/100:u.length.value/c;l.push({offset:h,color:g})}l.length||l.push({offset:0,color:"transparent"});let d=l[l.length-1];d.offset!==1&&(typeof d.offset=="undefined"?d.offset=1:l.push({offset:1,color:d.color}));let p=0,m=1;for(let u=0;u<l.length;u++)if(typeof l[u].offset=="undefined"){for(m<u&&(m=u);typeof l[m].offset=="undefined";)m++;l[u].offset=(l[m].offset-l[p].offset)/(m-p)*(u-p)+l[p].offset}else p=u;return[`satori_bi${t}`,`<linearGradient id="satori_bi${t}" x1="${s}" y1="${r}" x2="${i}" y2="${f}">${l.map(u=>`<stop offset="${u.offset*100}%" stop-color="${u.color}"/>`).join("")}</linearGradient>`]}if(e.startsWith("url(")){let o=e.slice(4,-1);return[`satori_bi${t}`,`<pattern id="satori_bi${t}" patternContentUnits="objectBoundingBox" width="1" height="1"><image href="${o}" x="0" y="0" width="1" height="1"/></pattern>`]}}function P(t,n,e){return e<t+n&&(e/2<t&&e/2<n?t=n=e/2:e/2<t?t=e-n:e/2<n&&(n=e-t)),[t,n]}function F({left:t,top:n,width:e,height:o},s){let{borderTopLeftRadius:r,borderTopRightRadius:i,borderBottomLeftRadius:f,borderBottomRightRadius:c}=s;return r=Math.min(r||0,e,o),i=Math.min(i||0,e,o),f=Math.min(f||0,e,o),c=Math.min(c||0,e,o),!r&&!i&&!f&&!c?"":([r,i]=P(r,i,e),[r,f]=P(r,f,o),[i,c]=P(i,c,o),[f,c]=P(f,c,e),`M${t+r},${n} h${e-r-i} a${i},${i} 0 0 1 ${i},${i} v${o-i-c} a${c},${c} 0 0 1 ${-c},${c} h${c+f-e} a${f},${f} 0 0 1 ${-f},${-f} v${f+r-o} a${r},${r} 0 0 1 ${r},${-r}`)}function W({id:t,width:n,height:e},o){if(!o.shadowColor||!o.shadowOffset||typeof o.shadowRadius=="undefined")return"";let s=Math.min(o.shadowOffset.width-o.shadowRadius*2,0),r=Math.max(o.shadowOffset.width+o.shadowRadius*2+n,n),i=Math.min(o.shadowOffset.height-o.shadowRadius*2,0),f=Math.max(o.shadowOffset.height+o.shadowRadius*2+e,e);return`<defs><filter id="satori_s-${t}" x="${s/n*100}%" y="${i/e*100}%" width="${(r-s)/n*100}%" height="${(f-i)/e*100}%"><feDropShadow dx="${o.shadowOffset.width}" dy="${o.shadowOffset.height}" stdDeviation="${o.shadowRadius}" flood-color="${o.shadowColor}" flood-opacity="1"/></filter></defs>`}function U({id:t,left:n,top:e,width:o,height:s,isInheritingTransform:r},i){if(i.display==="none")return"";let f="rect",c="transparent",l=0,d="",p="",m=[],u=1;if(i.backgroundColor&&m.push(i.backgroundColor),i.borderWidth&&(l=i.borderWidth,c=i.borderColor),i.opacity&&(u=+i.opacity),i.transform&&(d=N({left:n,top:e,width:o,height:s},i.transform,r)),i.backgroundImage){let E=i.backgroundImage.map((_,A)=>H({id:t+"_"+A,width:o,height:s},_)).filter(Boolean);for(let _ of E)p+=_[1],m.push(`url(#${_[0]})`)}let g=F({left:n,top:e,width:o,height:s},i);g&&(f="path");let h=W({width:o,height:s,id:t},i);return m.length||m.push("transparent"),`${p?`<defs>${p}</defs>`:""}${h?`${h}<g filter="url(#satori_s-${t})">`:""}${u!==1?`<g opacity="${u}">`:""}${m.map((E,_)=>E==="transparent"&&!(_===m.length-1&&l)?"":`<${f} x="${n}" y="${e}" width="${o}" height="${s}" fill="${E}" ${_===m.length-1&&l?`stroke="${c}" stroke-width="${l}"`:""} ${g?`d="${g}"`:""} ${d?`transform="${d}"`:""}></${f}>`).join("")}${u!==1?"</g>":""}${h?"</g>":""}`}function z({id:t,left:n,top:e,width:o,height:s,src:r},i){if(i.display==="none")return"";let f="",c=1,l=i.objectFit==="contain"?"xMidYMid":i.objectFit==="cover"?"xMidYMid slice":"none",d=F({left:n,top:e,width:o,height:s},i);d&&(f=`<clipPath id="satori_c-${t}"><path x="${n}" y="${e}" width="${o}" height="${s}" d="${d}"></path></clipPath>`),i.opacity&&(c=+i.opacity);let p=W({width:o,height:s,id:t},i);return`${p}${p?`<g filter="url(#satori_s-${t})">`:""}${f}<image href="${r}" x="${n}" y="${e}" width="${o}" height="${s}" preserveAspectRatio="${l}" ${f?`clip-path="url(#satori_c-${t})"`:""} ${c!==1?`opacity="${c}"`:""}></image>${p?"</g>":""}`}function*O(t,n){let{id:e,inheritedStyle:o,parent:s,font:r}=n;if(t===null||typeof t=="undefined")return yield,"";if(!D(t)||typeof t.type=="function"){let R;if(!D(t))R=X(String(t),n);else{if(Z(t.type))throw new Error("Class component is not supported.");R=O(t.type(t.props),n)}R.next();let C=yield;return R.next(C).value}let{type:i,props:f}=t,{style:c,children:l}=f,d=_t.Node.create();s.insertChild(d,s.getChildCount());let[p,m]=w(d,i,o,c,f),u=p.transform===o.transform;u||(p.transform.__parent=o.transform);let g=typeof l=="undefined"?[]:[].concat(l),h=[],E=0;for(let R of g){let C=O(R,{id:e*g.length+ ++E,parentStyle:p,inheritedStyle:m,isInheritingTransform:!0,parent:d,font:r});C.next(),h.push(C)}let[_,A]=yield;p.position==="absolute"&&d.calculateLayout();let{left:S,top:$,width:V,height:j}=d.getComputedLayout();S+=_,$+=A;let k="";i==="img"?k=z({id:e,left:S,top:$,width:V,height:j,src:f.src,isInheritingTransform:u},p):k=U({id:e,left:S,top:$,width:V,height:j,isInheritingTransform:u},p);for(let R of h)k+=R.next([S,$]).value;return k}import ot from"opentype.js";var B=class{constructor(n){this.fonts=new Map;for(let e of n){let o=e.data,s="buffer"in o?ot.parse(o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)):ot.parse(o);this.defaultFont||(this.defaultFont=s),this.fonts.has(e.name)||this.fonts.set(e.name,[]),this.fonts.get(e.name).push([s,e.weight,e.style])}}get({name:n,weight:e,style:o}){if(!this.fonts.has(n))return this.defaultFont;e==="normal"&&(e=400),e==="bold"&&(e=700);let s=[...this.fonts.get(n)];return s.sort(([r,i,f],[c,l,d])=>{if(i!==l)return i?!l||i===e?-1:l===e?1:e===400&&i===500||e===500&&i===400?-1:e===400&&l===500||e===500&&l===400?1:e<400?i<e&&l<e?l-i:i<e?-1:l<e?1:i-l:e<i&&e<l?i-l:e<i?-1:e<l?1:l-i:1;if(f!==d){if(f===o)return-1;if(d===o)return 1}return-1}),s[0][0]}measure(n,{fontFamily:e,fontSize:o,fontWeight:s=400,fontStyle:r="normal"}){let i=this.get({name:e,weight:s,style:r});return{width:i.getAdvanceWidth(n,o),ascent:i.ascender/i.unitsPerEm*o,descent:-(i.descender/i.unitsPerEm)*o}}getSVG(n,{fontFamily:e,fontSize:o,fontWeight:s=400,fontStyle:r="normal",top:i,left:f,letterSpacing:c=0}){let l=this.get({name:e,weight:s,style:r});return i+=l.ascender/l.unitsPerEm*o,l.getPath(n,f,i,o,{letterSpacing:c/o}).toPathData(3)}};function J({width:t,height:n,content:e},o){return`<svg width="${t}" height="${n}" viewBox="0 0 ${t} ${n}" xmlns="http://www.w3.org/2000/svg">${e}</svg>`}function it(t,n){let e=new B(n.fonts),o=v.Node.create();o.setWidth(n.width),o.setHeight(n.height),o.setFlexDirection(v.FLEX_DIRECTION_ROW),o.setFlexWrap(v.WRAP_WRAP);let s=O(t,{id:1,parentStyle:{},inheritedStyle:{fontSize:16,fontWeight:"normal",fontFamily:"serif",fontStyle:"normal",lineHeight:1.2,color:"black",opacity:1},parent:o,font:e});s.next(),o.calculateLayout(n.width,n.height,v.DIRECTION_LTR);let r=s.next([0,0]).value;return J({width:n.width,height:n.height,content:r})}export{it as default};
1
+ var ft=Object.defineProperty,ut=Object.defineProperties;var lt=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var mt=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var Q=(t,o,e)=>o in t?ft(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,A=(t,o)=>{for(var e in o||(o={}))mt.call(o,e)&&Q(t,e,o[e]);if(K)for(var e of K(o))ct.call(o,e)&&Q(t,e,o[e]);return t},Z=(t,o)=>ut(t,lt(o));var tt;function dt(t){tt=t}function pt(){return tt}var R=pt;function D(t){let o=typeof t;return!(o==="number"||o==="bigint"||o==="string"||o==="boolean")}function et(t){return/^class\s/.test(Function.prototype.toString.call(t))}function F(t,o){return[t[0]*o[0]+t[2]*o[1],t[1]*o[0]+t[3]*o[1],t[0]*o[2]+t[2]*o[3],t[1]*o[2]+t[3]*o[3],t[0]*o[4]+t[2]*o[5]+t[4],t[1]*o[4]+t[3]*o[5]+t[5]]}var nt={p:{display:"block",marginTop:"1em",marginBottom:"1em"},div:{display:"block"},blockquote:{display:"block",marginTop:"1em",marginBottom:"1em",marginLeft:40,marginRight:40},center:{display:"block",textAlign:"center"},hr:{display:"block",marginTop:"0.5em",marginBottom:"0.5em",marginLeft:"auto",marginRight:"auto",borderWidth:1,borderStyle:"inset"},h1:{display:"block",fontSize:"2em",marginTop:"0.67em",marginBottom:"0.67em",marginLeft:0,marginRight:0,fontWeight:"bold"},h2:{display:"block",fontSize:"1.5em",marginTop:"0.83em",marginBottom:"0.83em",marginLeft:0,marginRight:0,fontWeight:"bold"},h3:{display:"block",fontSize:"1.17em",marginTop:"1em",marginBottom:"1em",marginLeft:0,marginRight:0,fontWeight:"bold"},h4:{display:"block",marginTop:"1.33em",marginBottom:"1.33em",marginLeft:0,marginRight:0,fontWeight:"bold"},h5:{display:"block",fontSize:"0.83em",marginTop:"1.67em",marginBottom:"1.67em",marginLeft:0,marginRight:0,fontWeight:"bold"},h6:{display:"block",fontSize:"0.67em",marginTop:"2.33em",marginBottom:"2.33em",marginLeft:0,marginRight:0,fontWeight:"bold"},u:{textDecoration:"underline"},strong:{fontWeight:"bold"},b:{fontWeight:"bold"},i:{fontStyle:"italic"},em:{fontStyle:"italic"},code:{fontFamily:"monospace"},kbd:{fontFamily:"monospace"},pre:{display:"block",fontFamily:"monospace",whiteSpace:"pre",marginTop:"1em",marginBottom:"1em"},mark:{backgroundColor:"yellow",color:"black"},big:{fontSize:"larger"},small:{fontSize:"smaller"},s:{textDecoration:"line-through"}};var gt=new Set(["color","font","fontFamily","fontSize","fontStyle","fontWeight","lineHeight","textAlign","textTransform","whiteSpace","letterSpacing","transform","opacity"]);function M(t){let o={};for(let e in t)gt.has(e)&&(o[e]=t[e]);return o}import ht,{getPropertyName as bt}from"css-to-react-native";import it from"parse-css-dimension";import{parseElementStyle as yt}from"css-background-parser";var Et=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),rt=[1,0,0,1,0,0];function $t(t,o){return typeof o=="number"?Et.has(t)?String(o):o+"px":o}function ot(t,o){if(typeof t=="number")return t;try{let e=new it(t);if(e.type==="length")switch(e.unit){case"em":return e.value*o;case"rem":return e.value*16;default:return e.value}else if(e.type==="angle")switch(e.unit){case"deg":return e.value;case"rad":return e.value*180/Math.PI;default:return e.value}}catch{}}function P(t,o){let e=[];for(let r in t){let n=bt(r);e.push([n,$t(n,t[r])])}let i=ht(e);if(i.backgroundImage){let{backgrounds:r}=yt(i);i.backgroundImage=r}let a=i.fontSize||o.fontSize;if(typeof a=="string")try{let r=new it(a);switch(r.unit){case"em":a=r.value*o.fontSize;break;case"rem":a=r.value*16;break}}catch{a=16}i.fontSize=a;for(let r in i){let n=i[r];if(typeof n=="string"){let s=ot(n,a);typeof s!="undefined"&&(i[r]=s),n=i[r]}if(r==="opacity"&&(n=i[r]=n*o.opacity),r==="transform"){let s=[...rt],l=n;for(let f of l){let m=Object.keys(f)[0],d=f[m],c=typeof d=="string"?ot(d,a):d,u=[...rt];switch(m){case"translateX":u[4]=c;break;case"translateY":u[5]=c;break;case"scaleX":u[0]=c;break;case"scaleY":u[3]=c;break;case"rotate":let p=c*Math.PI/180,$=Math.cos(p),g=Math.sin(p);u[0]=$,u[1]=g,u[2]=-g,u[3]=$;break;case"skewX":u[2]=Math.tan(c*Math.PI/180);break;case"skewY":u[1]=Math.tan(c*Math.PI/180);break}s=F(u,s)}i.transform=s}}return i}function S(t,o,e){let i=o[t];return typeof i=="undefined"?e:i}function Y(t,o,e,i,a){let r=R(),n=A(A(A({},e),P(nt[o],e)),P(i,e));if(o==="img"){let s=parseInt(a.width),f=parseInt(a.height)/s;n.width||(n.width=s),n.height||(n.height=f*n.width)}return t.setDisplay(S(n.display,{flex:r.DISPLAY_FLEX,none:r.DISPLAY_NONE},r.DISPLAY_FLEX)),t.setAlignContent(S(n.alignContent,{stretch:r.ALIGN_STRETCH,center:r.ALIGN_CENTER,"flex-start":r.ALIGN_FLEX_START,"flex-end":r.ALIGN_FLEX_END,"space-between":r.ALIGN_SPACE_BETWEEN,"space-around":r.ALIGN_SPACE_AROUND,baseline:r.ALIGN_BASELINE,normal:r.ALIGN_AUTO},r.ALIGN_AUTO)),t.setAlignItems(S(n.alignItems,{stretch:r.ALIGN_STRETCH,center:r.ALIGN_CENTER,"flex-start":r.ALIGN_FLEX_START,"flex-end":r.ALIGN_FLEX_END,baseline:r.ALIGN_BASELINE,normal:r.ALIGN_AUTO},r.ALIGN_FLEX_START)),t.setAlignSelf(S(n.alignSelf,{stretch:r.ALIGN_STRETCH,center:r.ALIGN_CENTER,"flex-start":r.ALIGN_FLEX_START,"flex-end":r.ALIGN_FLEX_END,baseline:r.ALIGN_BASELINE,normal:r.ALIGN_AUTO},r.ALIGN_AUTO)),t.setJustifyContent(S(n.justifyContent,{center:r.JUSTIFY_CENTER,"flex-start":r.JUSTIFY_FLEX_START,"flex-end":r.JUSTIFY_FLEX_END,"space-between":r.JUSTIFY_SPACE_BETWEEN,"space-around":r.JUSTIFY_SPACE_AROUND},r.JUSTIFY_FLEX_START)),t.setFlexDirection(S(n.flexDirection,{row:r.FLEX_DIRECTION_ROW,column:r.FLEX_DIRECTION_COLUMN,"row-reverse":r.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":r.FLEX_DIRECTION_COLUMN_REVERSE},r.FLEX_DIRECTION_ROW)),t.setFlexWrap(S(n.flexWrap,{wrap:r.WRAP_WRAP,nowrap:r.WRAP_NO_WRAP,"wrap-reverse":r.WRAP_WRAP_REVERSE},r.WRAP_WRAP)),typeof n.flexBasis!="undefined"&&t.setFlexBasis(n.flexBasis),t.setFlexGrow(typeof n.flexGrow=="undefined"?0:n.flexGrow),t.setFlexShrink(typeof n.flexShrink=="undefined"?1:n.flexShrink),typeof n.maxHeight!="undefined"&&t.setMaxHeight(n.maxHeight),typeof n.maxWidth!="undefined"&&t.setMaxWidth(n.maxWidth),typeof n.minHeight!="undefined"&&t.setMinHeight(n.minHeight),typeof n.minWidth!="undefined"&&t.setMinWidth(n.minWidth),t.setOverflow(S(n.overflow,{visible:r.OVERFLOW_VISIBLE,hidden:r.OVERFLOW_HIDDEN},r.OVERFLOW_VISIBLE)),t.setMargin(r.EDGE_TOP,n.marginTop||0),t.setMargin(r.EDGE_BOTTOM,n.marginBottom||0),t.setMargin(r.EDGE_LEFT,n.marginLeft||0),t.setMargin(r.EDGE_RIGHT,n.marginRight||0),t.setBorder(r.EDGE_TOP,n.borderWidth||0),t.setBorder(r.EDGE_BOTTOM,n.borderWidth||0),t.setBorder(r.EDGE_LEFT,n.borderWidth||0),t.setBorder(r.EDGE_RIGHT,n.borderWidth||0),t.setPadding(r.EDGE_TOP,n.paddingTop||0),t.setPadding(r.EDGE_BOTTOM,n.paddingBottom||0),t.setPadding(r.EDGE_LEFT,n.paddingLeft||0),t.setPadding(r.EDGE_RIGHT,n.paddingRight||0),t.setPositionType(S(n.position,{absolute:r.POSITION_TYPE_ABSOLUTE,relative:r.POSITION_TYPE_RELATIVE},r.POSITION_TYPE_RELATIVE)),typeof n.top!="undefined"&&t.setPosition(r.EDGE_TOP,n.top),typeof n.bottom!="undefined"&&t.setPosition(r.EDGE_BOTTOM,n.bottom),typeof n.left!="undefined"&&t.setPosition(r.EDGE_LEFT,n.left),typeof n.right!="undefined"&&t.setPosition(r.EDGE_RIGHT,n.right),typeof n.height!="undefined"?t.setHeight(n.height):t.setHeightAuto(),typeof n.width!="undefined"?t.setWidth(n.width):t.setWidthAuto(),[n,M(n)]}import{LineBreaker as _t}from"css-line-break";function N({left:t,top:o,width:e,height:i},a,r){let n;if(r)n=a;else{let s=t+e/2,l=o+i/2;n=F([1,0,0,1,s,l],F(a,[1,0,0,1,-s,-l])),a.__parent&&(n=F(a.__parent,n)),a.splice(0,6,...n)}return`matrix(${n.join(",")})`}function X({content:t,left:o,top:e,width:i,height:a,isInheritingTransform:r,path:n,debug:s},l){let f="",m=1,d="";return l.transform&&(f=N({left:o,top:e,width:i,height:a},l.transform,r)),l.opacity&&(m=+l.opacity),s&&(d=`<rect x="${o}" y="${e}" width="${i}" height="${n===null?.5:a}" fill="transparent" stroke="#575eff" stroke-width="1" ${f?`transform="${f}"`:""}></rect>`),n===null?`<text x="${o}" y="${e}" width="${i}" height="${a}" fill="${l.color}" font-weight="${l.fontWeight}" font-style="${l.fontStyle}" font-size="${l.fontSize}" font-family="${l.fontFamily}" ${l.letterSpacing?`letter-spacing="${l.letterSpacing}"`:""} ${f?`transform="${f}"`:""} ${m!==1?`opacity="${m}"`:""}>${t}</text>${d}`:`<path fill="${l.color}" ${f?`transform="${f}"`:""} ${m!==1?`opacity="${m}"`:""} d="${n}"></path>${d}`}function*U(t,o){let e=R(),{parentStyle:i,parent:a,font:r,id:n,isInheritingTransform:s,debug:l,embedFont:f}=o,m=_t(t,{lineBreak:"strict",wordBreak:"normal"}),d=[];for(let g;!(g=m.next()).done;)d.push(g.value.slice());let c=[];a.setAlignItems(e.ALIGN_BASELINE),i.textAlign==="left"?a.setJustifyContent(e.JUSTIFY_FLEX_START):i.textAlign==="center"?a.setJustifyContent(e.JUSTIFY_CENTER):i.textAlign==="right"?a.setJustifyContent(e.JUSTIFY_FLEX_END):i.textAlign==="justify"&&a.setJustifyContent(e.JUSTIFY_SPACE_BETWEEN);for(let g of d){let y=e.Node.create();a.insertChild(y,a.getChildCount());let _=r.measure(g,i),E=(i.letterSpacing||0)*g.length;y.setWidth(_.width+E),y.setHeight(_.ascent*1.2),y.setMargin(e.EDGE_BOTTOM,_.descent*1.2),c.push(y)}let[u,p]=yield,$="";for(let g=0;g<c.length;g++){let y=c[g],_=d[g];i.position==="absolute"&&y.calculateLayout();let{left:E,top:x,width:v,height:L}=y.getComputedLayout();E+=u,x+=p;let I=null;f?I=r.getSVG(_,Z(A({},i),{top:x,left:E,letterSpacing:i.letterSpacing})):x+=r.getAscent(i),$+=X({content:_,id:n,left:E,top:x,width:v,height:L,isInheritingTransform:s,path:I,debug:l},i)}return $}import St from"gradient-parser";function xt(t){return t.type==="literal"?t.value:t.type==="hex"?`#${t.value}`:t.type==="rgb"?`rgb(${t.value.join(",")})`:t.type==="rgba"?`rgba(${t.value.join(",")})`:"transparent"}function H({id:t,width:o},{image:e}){if(e.startsWith("linear-gradient(")){let i=St.parse(e)[0],a,r,n,s;if(i.orientation.type==="directional")[a,r,n,s]={top:[0,1,0,0],bottom:[0,0,0,1],left:[1,0,0,0],right:[0,0,1,0]}[i.orientation.value];else if(i.orientation.type==="angular"){let u=+i.orientation.value/180*Math.PI-Math.PI/2,p=Math.cos(u),$=Math.sin(u);a=0,r=0,n=p,s=$,n<0&&(a-=n,n=0),s<0&&(r-=s,s=0)}let l=o,f=[];for(let u of i.colorStops){let p=xt(u);if(!f.length&&(f.push({offset:0,color:p}),typeof u.length=="undefined"||u.length.value==="0"))continue;let $=typeof u.length=="undefined"?void 0:u.length.type==="%"?u.length.value/100:u.length.value/l;f.push({offset:$,color:p})}f.length||f.push({offset:0,color:"transparent"});let m=f[f.length-1];m.offset!==1&&(typeof m.offset=="undefined"?m.offset=1:f.push({offset:1,color:m.color}));let d=0,c=1;for(let u=0;u<f.length;u++)if(typeof f[u].offset=="undefined"){for(c<u&&(c=u);typeof f[c].offset=="undefined";)c++;f[u].offset=(f[c].offset-f[d].offset)/(c-d)*(u-d)+f[d].offset}else d=u;return[`satori_bi${t}`,`<linearGradient id="satori_bi${t}" x1="${a}" y1="${r}" x2="${n}" y2="${s}">${f.map(u=>`<stop offset="${u.offset*100}%" stop-color="${u.color}"/>`).join("")}</linearGradient>`]}if(e.startsWith("url(")){let i=e.slice(4,-1);return[`satori_bi${t}`,`<pattern id="satori_bi${t}" patternContentUnits="objectBoundingBox" width="1" height="1"><image href="${i}" x="0" y="0" width="1" height="1"/></pattern>`]}}function w(t,o,e){return e<t+o&&(e/2<t&&e/2<o?t=o=e/2:e/2<t?t=e-o:e/2<o&&(o=e-t)),[t,o]}function W({left:t,top:o,width:e,height:i},a){let{borderTopLeftRadius:r,borderTopRightRadius:n,borderBottomLeftRadius:s,borderBottomRightRadius:l}=a;return r=Math.min(r||0,e,i),n=Math.min(n||0,e,i),s=Math.min(s||0,e,i),l=Math.min(l||0,e,i),!r&&!n&&!s&&!l?"":([r,n]=w(r,n,e),[r,s]=w(r,s,i),[n,l]=w(n,l,i),[s,l]=w(s,l,e),`M${t+r},${o} h${e-r-n} a${n},${n} 0 0 1 ${n},${n} v${i-n-l} a${l},${l} 0 0 1 ${-l},${l} h${l+s-e} a${s},${s} 0 0 1 ${-s},${-s} v${s+r-i} a${r},${r} 0 0 1 ${r},${-r}`)}function O({id:t,width:o,height:e},i){if(!i.shadowColor||!i.shadowOffset||typeof i.shadowRadius=="undefined")return"";let a=Math.min(i.shadowOffset.width-i.shadowRadius*2,0),r=Math.max(i.shadowOffset.width+i.shadowRadius*2+o,o),n=Math.min(i.shadowOffset.height-i.shadowRadius*2,0),s=Math.max(i.shadowOffset.height+i.shadowRadius*2+e,e);return`<defs><filter id="satori_s-${t}" x="${a/o*100}%" y="${n/e*100}%" width="${(r-a)/o*100}%" height="${(s-n)/e*100}%"><feDropShadow dx="${i.shadowOffset.width}" dy="${i.shadowOffset.height}" stdDeviation="${i.shadowRadius}" flood-color="${i.shadowColor}" flood-opacity="1"/></filter></defs>`}function z({id:t,left:o,top:e,width:i,height:a,isInheritingTransform:r,debug:n},s){if(s.display==="none")return"";let l="rect",f="transparent",m=0,d="",c="",u=[],p=1,$="";if(s.backgroundColor&&u.push(s.backgroundColor),s.borderWidth&&(m=s.borderWidth,f=s.borderColor),s.opacity&&(p=+s.opacity),s.transform&&(d=N({left:o,top:e,width:i,height:a},s.transform,r)),s.backgroundImage){let _=s.backgroundImage.map((E,x)=>H({id:t+"_"+x,width:i,height:a},E)).filter(Boolean);for(let E of _)c+=E[1],u.push(`url(#${E[0]})`)}let g=W({left:o,top:e,width:i,height:a},s);g&&(l="path");let y=O({width:i,height:a,id:t},s);return u.length||u.push("transparent"),n&&($=`<rect x="${o}" y="${e}" width="${i}" height="${a}" fill="transparent" stroke="#ff5757" stroke-width="1" ${d?`transform="${d}"`:""}></rect>`),`${c?`<defs>${c}</defs>`:""}${y?`${y}<g filter="url(#satori_s-${t})">`:""}${p!==1?`<g opacity="${p}">`:""}${u.map((_,E)=>_==="transparent"&&!(E===u.length-1&&m)?"":`<${l} x="${o}" y="${e}" width="${i}" height="${a}" fill="${_}" ${E===u.length-1&&m?`stroke="${f}" stroke-width="${m}"`:""} ${g?`d="${g}"`:""} ${d?`transform="${d}"`:""}></${l}>`).join("")}${p!==1?"</g>":""}${y?"</g>":""}${$}`}function J({id:t,left:o,top:e,width:i,height:a,src:r,debug:n},s){if(s.display==="none")return"";let l="",f=1,m=s.objectFit==="contain"?"xMidYMid":s.objectFit==="cover"?"xMidYMid slice":"none",d=W({left:o,top:e,width:i,height:a},s);d&&(l=`<clipPath id="satori_c-${t}"><path x="${o}" y="${e}" width="${i}" height="${a}" d="${d}"></path></clipPath>`),s.opacity&&(f=+s.opacity);let c=O({width:i,height:a,id:t},s);return`${c}${c?`<g filter="url(#satori_s-${t})">`:""}${l}<image href="${r}" x="${o}" y="${e}" width="${i}" height="${a}" preserveAspectRatio="${m}" ${l?`clip-path="url(#satori_c-${t})"`:""} ${f!==1?`opacity="${f}"`:""}></image>${c?"</g>":""}`}function*k(t,o){let e=R(),{id:i,inheritedStyle:a,parent:r,font:n,debug:s,embedFont:l=!0}=o;if(t===null||typeof t=="undefined")return yield,"";if(!D(t)||typeof t.type=="function"){let T;if(!D(t))T=U(String(t),o);else{if(et(t.type))throw new Error("Class component is not supported.");T=k(t.type(t.props),o)}T.next();let G=yield;return T.next(G).value}let{type:f,props:m}=t,{style:d,children:c}=m,u=e.Node.create();r.insertChild(u,r.getChildCount());let[p,$]=Y(u,f,a,d,m),g=p.transform===a.transform;g||(p.transform.__parent=a.transform);let y=typeof c=="undefined"?[]:[].concat(c),_=[],E=0;for(let T of y){let G=k(T,{id:i*y.length+ ++E,parentStyle:p,inheritedStyle:$,isInheritingTransform:!0,parent:u,font:n,embedFont:l,debug:s});G.next(),_.push(G)}let[x,v]=yield;p.position==="absolute"&&u.calculateLayout();let{left:L,top:I,width:j,height:q}=u.getComputedLayout();L+=x,I+=v;let C="";f==="img"?C=J({id:i,left:L,top:I,width:j,height:q,src:m.src,isInheritingTransform:g,debug:s},p):C=z({id:i,left:L,top:I,width:j,height:q,isInheritingTransform:g,debug:s},p);for(let T of _)C+=T.next([L,I]).value;return C}import at from"opentype.js";var B=class{constructor(o){this.fonts=new Map;for(let e of o){let i=e.data,a="buffer"in i?at.parse(i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)):at.parse(i);this.defaultFont||(this.defaultFont=a),this.fonts.has(e.name)||this.fonts.set(e.name,[]),this.fonts.get(e.name).push([a,e.weight,e.style])}}get({name:o,weight:e,style:i}){if(!this.fonts.has(o))return this.defaultFont;e==="normal"&&(e=400),e==="bold"&&(e=700);let a=[...this.fonts.get(o)];return a.sort(([r,n,s],[l,f,m])=>{if(n!==f)return n?!f||n===e?-1:f===e?1:e===400&&n===500||e===500&&n===400?-1:e===400&&f===500||e===500&&f===400?1:e<400?n<e&&f<e?f-n:n<e?-1:f<e?1:n-f:e<n&&e<f?n-f:e<n?-1:e<f?1:f-n:1;if(s!==m){if(s===i)return-1;if(m===i)return 1}return-1}),a[0][0]}measure(o,{fontFamily:e,fontSize:i,fontWeight:a=400,fontStyle:r="normal"}){let n=this.get({name:e,weight:a,style:r});return{width:n.getAdvanceWidth(o,i),ascent:n.ascender/n.unitsPerEm*i,descent:-(n.descender/n.unitsPerEm)*i}}getSVG(o,{fontFamily:e,fontSize:i,fontWeight:a=400,fontStyle:r="normal",top:n,left:s,letterSpacing:l=0}){let f=this.get({name:e,weight:a,style:r});return n+=f.ascender/f.unitsPerEm*i,f.getPath(o,s,n,i,{letterSpacing:l/i}).toPathData(2)}getAscent({fontFamily:o,fontSize:e,fontWeight:i=400,fontStyle:a="normal"}){let r=this.get({name:o,weight:i,style:a});return r.ascender/r.unitsPerEm*e}};function V({width:t,height:o,content:e},i){return`<svg width="${t}" height="${o}" viewBox="0 0 ${t} ${o}" xmlns="http://www.w3.org/2000/svg">${e}</svg>`}function st(t,o){let e=R();if(!e)throw new Error("Satori is not initialized.");let i=new B(o.fonts),a=e.Node.create();a.setWidth(o.width),a.setHeight(o.height),a.setFlexDirection(e.FLEX_DIRECTION_ROW),a.setFlexWrap(e.WRAP_WRAP),a.setAlignContent(e.ALIGN_AUTO),a.setAlignItems(e.ALIGN_FLEX_START),a.setJustifyContent(e.JUSTIFY_FLEX_START);let r=k(t,{id:1,parentStyle:{},inheritedStyle:{fontSize:16,fontWeight:"normal",fontFamily:"serif",fontStyle:"normal",lineHeight:1.2,color:"black",opacity:1},parent:a,font:i,embedFont:o.embedFont,debug:o.debug});r.next(),a.calculateLayout(o.width,o.height,e.DIRECTION_LTR);let n=r.next([0,0]).value;return V({width:o.width,height:o.height,content:n})}export{st as default,dt as init};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
+ import * as yoga_layout from 'yoga-layout';
3
+
4
+ declare function init(yoga: typeof yoga_layout): void;
2
5
 
3
6
  /**
4
7
  * This class handles everything related to fonts.
@@ -17,7 +20,10 @@ interface SatoriOptions {
17
20
  width: number;
18
21
  height: number;
19
22
  fonts: FontOptions[];
23
+ embedFont?: boolean;
24
+ debug?: boolean;
20
25
  }
26
+
21
27
  declare function satori(element: ReactNode, options: SatoriOptions): string;
22
28
 
23
- export { SatoriOptions, satori as default };
29
+ export { SatoriOptions, satori as default, init };
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "satori",
3
- "version": "0.0.6",
3
+ "version": "0.0.8-beta.2",
4
4
  "description": "A lightweight library to convert HTML JSX to SVG string.",
5
- "main": "./dist/index.js",
6
5
  "module": "./dist/esm/index.js",
7
6
  "types": "./dist/index.d.ts",
7
+ "type": "module",
8
8
  "files": [
9
9
  "dist/**"
10
10
  ],
11
11
  "scripts": {
12
- "dev:test": "vitest",
12
+ "dev": "tsup src/index.ts --watch --format esm --legacy-output --ignore-watch playground",
13
+ "build": "tsup src/index.ts --dts --minify --format esm --legacy-output",
13
14
  "test": "vitest run",
14
- "build": "tsup src/index.ts --dts --minify --format cjs,esm --legacy-output"
15
+ "dev:test": "vitest"
15
16
  },
16
17
  "repository": {
17
18
  "type": "git",
@@ -34,6 +35,7 @@
34
35
  "@types/node": "^17.0.13",
35
36
  "@types/opentype.js": "^1.3.3",
36
37
  "@types/react": "^17.0.38",
38
+ "@types/yoga-layout": "^1.9.4",
37
39
  "react": "^17.0.2",
38
40
  "tsup": "^5.11.13",
39
41
  "typescript": "^4.5.5",
@@ -45,7 +47,6 @@
45
47
  "css-to-react-native": "^3.0.0",
46
48
  "gradient-parser": "^1.0.2",
47
49
  "opentype.js": "^1.3.4",
48
- "parse-css-dimension": "^1.1.0",
49
- "yoga-layout-prebuilt": "^1.10.0"
50
+ "parse-css-dimension": "^1.1.0"
50
51
  }
51
52
  }
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- var gt=Object.create;var N=Object.defineProperty,ht=Object.defineProperties,bt=Object.getOwnPropertyDescriptor,yt=Object.getOwnPropertyDescriptors,Et=Object.getOwnPropertyNames,et=Object.getOwnPropertySymbols,_t=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable;var rt=(t,r,e)=>r in t?N(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,I=(t,r)=>{for(var e in r||(r={}))nt.call(r,e)&&rt(t,e,r[e]);if(et)for(var e of et(r))Rt.call(r,e)&&rt(t,e,r[e]);return t},ot=(t,r)=>ht(t,yt(r)),it=t=>N(t,"__esModule",{value:!0});var Tt=(t,r)=>{for(var e in r)N(t,e,{get:r[e],enumerable:!0})},at=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of Et(r))!nt.call(t,a)&&(e||a!=="default")&&N(t,a,{get:()=>r[a],enumerable:!(o=bt(r,a))||o.enumerable});return t},R=(t,r)=>at(it(N(t!=null?gt(_t(t)):{},"default",!r&&t&&t.__esModule?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t),xt=(t=>(r,e)=>t&&t.get(r)||(e=at(it({}),r,1),t&&t.set(r,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var At={};Tt(At,{default:()=>Q});var C=R(require("yoga-layout-prebuilt"));var dt=R(require("yoga-layout-prebuilt"));function w(t){let r=typeof t;return!(r==="number"||r==="bigint"||r==="string"||r==="boolean")}function st(t){return/^class\s/.test(Function.prototype.toString.call(t))}function L(t,r){return[t[0]*r[0]+t[2]*r[1],t[1]*r[0]+t[3]*r[1],t[0]*r[2]+t[2]*r[3],t[1]*r[2]+t[3]*r[3],t[0]*r[4]+t[2]*r[5]+t[4],t[1]*r[4]+t[3]*r[5]+t[5]]}var s=R(require("yoga-layout-prebuilt"));var ft={p:{display:"block",marginTop:"1em",marginBottom:"1em"},div:{display:"block"},blockquote:{display:"block",marginTop:"1em",marginBottom:"1em",marginLeft:40,marginRight:40},center:{display:"block",textAlign:"center"},hr:{display:"block",marginTop:"0.5em",marginBottom:"0.5em",marginLeft:"auto",marginRight:"auto",borderWidth:1,borderStyle:"inset"},h1:{display:"block",fontSize:"2em",marginTop:"0.67em",marginBottom:"0.67em",marginLeft:0,marginRight:0,fontWeight:"bold"},h2:{display:"block",fontSize:"1.5em",marginTop:"0.83em",marginBottom:"0.83em",marginLeft:0,marginRight:0,fontWeight:"bold"},h3:{display:"block",fontSize:"1.17em",marginTop:"1em",marginBottom:"1em",marginLeft:0,marginRight:0,fontWeight:"bold"},h4:{display:"block",marginTop:"1.33em",marginBottom:"1.33em",marginLeft:0,marginRight:0,fontWeight:"bold"},h5:{display:"block",fontSize:"0.83em",marginTop:"1.67em",marginBottom:"1.67em",marginLeft:0,marginRight:0,fontWeight:"bold"},h6:{display:"block",fontSize:"0.67em",marginTop:"2.33em",marginBottom:"2.33em",marginLeft:0,marginRight:0,fontWeight:"bold"},u:{textDecoration:"underline"},strong:{fontWeight:"bold"},b:{fontWeight:"bold"},i:{fontStyle:"italic"},em:{fontStyle:"italic"},code:{fontFamily:"monospace"},kbd:{fontFamily:"monospace"},pre:{display:"block",fontFamily:"monospace",whiteSpace:"pre",marginTop:"1em",marginBottom:"1em"},mark:{backgroundColor:"yellow",color:"black"},big:{fontSize:"larger"},small:{fontSize:"smaller"},s:{textDecoration:"line-through"}};var St=new Set(["color","font","fontFamily","fontSize","fontStyle","fontWeight","lineHeight","textAlign","textTransform","whiteSpace","letterSpacing","transform","opacity"]);function Y(t){let r={};for(let e in t)St.has(e)&&(r[e]=t[e]);return r}var B=R(require("css-to-react-native")),X=R(require("parse-css-dimension")),ct=require("css-background-parser");var $t=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),ut=[1,0,0,1,0,0];function It(t,r){return typeof r=="number"?$t.has(t)?String(r):r+"px":r}function lt(t,r){if(typeof t=="number")return t;try{let e=new X.default(t);if(e.type==="length")switch(e.unit){case"em":return e.value*r;case"rem":return e.value*16;default:return e.value}else if(e.type==="angle")switch(e.unit){case"deg":return e.value;case"rad":return e.value*180/Math.PI;default:return e.value}}catch{}}function v(t,r){let e=[];for(let n in t){let i=(0,B.getPropertyName)(n);e.push([i,It(i,t[n])])}let o=(0,B.default)(e);if(o.backgroundImage){let{backgrounds:n}=(0,ct.parseElementStyle)(o);o.backgroundImage=n}let a=o.fontSize||r.fontSize;if(typeof a=="string")try{let n=new X.default(a);switch(n.unit){case"em":a=n.value*r.fontSize;break;case"rem":a=n.value*16;break}}catch{a=16}o.fontSize=a;for(let n in o){let i=o[n];if(typeof i=="string"){let f=lt(i,a);typeof f!="undefined"&&(o[n]=f),i=o[n]}if(n==="opacity"&&(i=o[n]=i*r.opacity),n==="transform"){let f=[...ut],c=i;for(let l of c){let d=Object.keys(l)[0],p=l[d],m=typeof p=="string"?lt(p,a):p,u=[...ut];switch(d){case"translateX":u[4]=m;break;case"translateY":u[5]=m;break;case"scaleX":u[0]=m;break;case"scaleY":u[3]=m;break;case"rotate":let g=m*Math.PI/180,h=Math.cos(g),y=Math.sin(g);u[0]=h,u[1]=y,u[2]=-y,u[3]=h;break;case"skewX":u[2]=Math.tan(m*Math.PI/180);break;case"skewY":u[1]=Math.tan(m*Math.PI/180);break}f=L(u,f)}o.transform=f}}return o}function T(t,r,e){let o=r[t];return typeof o=="undefined"?e:o}function H(t,r,e,o,a){let n=I(I(I({},e),v(ft[r],e)),v(o,e));if(r==="img"){let i=parseInt(a.width),c=parseInt(a.height)/i;n.width||(n.width=i),n.height||(n.height=c*n.width)}return t.setDisplay(T(n.display,{flex:s.default.DISPLAY_FLEX,none:s.default.DISPLAY_NONE},s.default.DISPLAY_FLEX)),t.setAlignContent(T(n.alignContent,{stretch:s.default.ALIGN_STRETCH,center:s.default.ALIGN_CENTER,"flex-start":s.default.ALIGN_FLEX_START,"flex-end":s.default.ALIGN_FLEX_END,"space-between":s.default.ALIGN_SPACE_BETWEEN,"space-around":s.default.ALIGN_SPACE_AROUND,baseline:s.default.ALIGN_BASELINE,normal:s.default.ALIGN_AUTO},s.default.ALIGN_AUTO)),t.setAlignItems(T(n.alignItems,{stretch:s.default.ALIGN_STRETCH,center:s.default.ALIGN_CENTER,"flex-start":s.default.ALIGN_FLEX_START,"flex-end":s.default.ALIGN_FLEX_END,baseline:s.default.ALIGN_BASELINE,normal:s.default.ALIGN_AUTO},s.default.ALIGN_FLEX_START)),t.setAlignSelf(T(n.alignSelf,{stretch:s.default.ALIGN_STRETCH,center:s.default.ALIGN_CENTER,"flex-start":s.default.ALIGN_FLEX_START,"flex-end":s.default.ALIGN_FLEX_END,baseline:s.default.ALIGN_BASELINE,normal:s.default.ALIGN_AUTO},s.default.ALIGN_AUTO)),t.setJustifyContent(T(n.justifyContent,{center:s.default.JUSTIFY_CENTER,"flex-start":s.default.JUSTIFY_FLEX_START,"flex-end":s.default.JUSTIFY_FLEX_END,"space-between":s.default.JUSTIFY_SPACE_BETWEEN,"space-around":s.default.JUSTIFY_SPACE_AROUND},s.default.JUSTIFY_FLEX_START)),typeof n.flexBasis!="undefined"?t.setFlexBasis(n.flexBasis):n.display==="block"&&(typeof n.width=="undefined"||n.width==="auto")&&(typeof n.maxWidth=="undefined"||n.maxWidth==="auto")&&t.setFlexBasisPercent(100),t.setFlexDirection(T(n.flexDirection,{row:s.default.FLEX_DIRECTION_ROW,column:s.default.FLEX_DIRECTION_COLUMN,"row-reverse":s.default.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":s.default.FLEX_DIRECTION_COLUMN_REVERSE},s.default.FLEX_DIRECTION_ROW)),t.setFlexGrow(n.flexGrow||0),t.setFlexShrink(n.flexShrink||1),t.setFlexWrap(T(n.flexWrap,{wrap:s.default.WRAP_WRAP,nowrap:s.default.WRAP_NO_WRAP,"wrap-reverse":s.default.WRAP_WRAP_REVERSE},s.default.WRAP_WRAP)),typeof n.maxHeight!="undefined"&&t.setMaxHeight(n.maxHeight),typeof n.maxWidth!="undefined"&&t.setMaxWidth(n.maxWidth),typeof n.minHeight!="undefined"&&t.setMinHeight(n.minHeight),typeof n.minWidth!="undefined"&&t.setMinWidth(n.minWidth),t.setOverflow(T(n.overflow,{visible:s.default.OVERFLOW_VISIBLE,hidden:s.default.OVERFLOW_HIDDEN},s.default.OVERFLOW_VISIBLE)),t.setMargin(s.default.EDGE_TOP,n.marginTop||0),t.setMargin(s.default.EDGE_BOTTOM,n.marginBottom||0),t.setMargin(s.default.EDGE_LEFT,n.marginLeft||0),t.setMargin(s.default.EDGE_RIGHT,n.marginRight||0),t.setBorder(s.default.EDGE_TOP,n.borderWidth||0),t.setBorder(s.default.EDGE_BOTTOM,n.borderWidth||0),t.setBorder(s.default.EDGE_LEFT,n.borderWidth||0),t.setBorder(s.default.EDGE_RIGHT,n.borderWidth||0),t.setPadding(s.default.EDGE_TOP,n.paddingTop||0),t.setPadding(s.default.EDGE_BOTTOM,n.paddingBottom||0),t.setPadding(s.default.EDGE_LEFT,n.paddingLeft||0),t.setPadding(s.default.EDGE_RIGHT,n.paddingRight||0),t.setPositionType((n.position,s.default.POSITION_TYPE_ABSOLUTE,s.default.POSITION_TYPE_RELATIVE,s.default.POSITION_TYPE_RELATIVE)),typeof n.top!="undefined"&&t.setPosition(s.default.EDGE_TOP,n.top),typeof n.bottom!="undefined"&&t.setPosition(s.default.EDGE_BOTTOM,n.bottom),typeof n.left!="undefined"&&t.setPosition(s.default.EDGE_LEFT,n.left),typeof n.right!="undefined"&&t.setPosition(s.default.EDGE_RIGHT,n.right),typeof n.height!="undefined"?t.setHeight(n.height):t.setHeightAuto(),typeof n.width!="undefined"?t.setWidth(n.width):t.setWidthAuto(),[n,Y(n)]}var x=R(require("yoga-layout-prebuilt")),mt=require("css-line-break");function F({left:t,top:r,width:e,height:o},a,n){let i;if(n)i=a;else{let f=t+e/2,c=r+o/2;i=L([1,0,0,1,f,c],L(a,[1,0,0,1,-f,-c])),a.__parent&&(i=L(a.__parent,i)),a.splice(0,6,...i)}return`matrix(${i.join(",")})`}function U({left:t,top:r,width:e,height:o,isInheritingTransform:a,path:n},i){let f="",c=1;return i.transform&&(f=F({left:t,top:r,width:e,height:o},i.transform,a)),i.opacity&&(c=+i.opacity),`<path fill="${i.color}" ${f?`transform="${f}"`:""} ${c!==1?`opacity="${c}"`:""} d="${n}"></path>`}function*z(t,r){let{parentStyle:e,parent:o,font:a,id:n,isInheritingTransform:i}=r,f=(0,mt.LineBreaker)(t,{lineBreak:"strict",wordBreak:"normal"}),c=[];for(let u;!(u=f.next()).done;)c.push(u.value.slice());let l=[];o.setAlignItems(x.default.ALIGN_BASELINE),e.textAlign==="left"?o.setJustifyContent(x.default.JUSTIFY_FLEX_START):e.textAlign==="center"?o.setJustifyContent(x.default.JUSTIFY_CENTER):e.textAlign==="right"?o.setJustifyContent(x.default.JUSTIFY_FLEX_END):e.textAlign==="justify"&&o.setJustifyContent(x.default.JUSTIFY_SPACE_BETWEEN);for(let u of c){let g=x.default.Node.create();o.insertChild(g,o.getChildCount());let h=a.measure(u,e),y=(e.letterSpacing||0)*u.length;g.setWidth(h.width+y),g.setHeight(h.ascent*1.2),g.setMargin(x.default.EDGE_BOTTOM,h.descent*1.2),l.push(g)}let[d,p]=yield,m="";for(let u=0;u<l.length;u++){let g=l[u],h=c[u];e.position==="absolute"&&g.calculateLayout();let{left:y,top:E,width:A,height:S}=g.getComputedLayout();y+=d,E+=p;let $=a.getSVG(h,ot(I({},e),{top:E,left:y,letterSpacing:e.letterSpacing}));m+=U({id:n,left:y,top:E,width:A,height:S,isInheritingTransform:i,path:$},e)}return m}var pt=R(require("gradient-parser"));function Lt(t){return t.type==="literal"?t.value:t.type==="hex"?`#${t.value}`:t.type==="rgb"?`rgb(${t.value.join(",")})`:t.type==="rgba"?`rgba(${t.value.join(",")})`:"transparent"}function J({id:t,width:r},{image:e}){if(e.startsWith("linear-gradient(")){let o=pt.default.parse(e)[0],a,n,i,f;if(o.orientation.type==="directional")[a,n,i,f]={top:[0,1,0,0],bottom:[0,0,0,1],left:[1,0,0,0],right:[0,0,1,0]}[o.orientation.value];else if(o.orientation.type==="angular"){let u=+o.orientation.value/180*Math.PI-Math.PI/2,g=Math.cos(u),h=Math.sin(u);a=0,n=0,i=g,f=h,i<0&&(a-=i,i=0),f<0&&(n-=f,f=0)}let c=r,l=[];for(let u of o.colorStops){let g=Lt(u);if(!l.length&&(l.push({offset:0,color:g}),typeof u.length=="undefined"||u.length.value==="0"))continue;let h=typeof u.length=="undefined"?void 0:u.length.type==="%"?u.length.value/100:u.length.value/c;l.push({offset:h,color:g})}l.length||l.push({offset:0,color:"transparent"});let d=l[l.length-1];d.offset!==1&&(typeof d.offset=="undefined"?d.offset=1:l.push({offset:1,color:d.color}));let p=0,m=1;for(let u=0;u<l.length;u++)if(typeof l[u].offset=="undefined"){for(m<u&&(m=u);typeof l[m].offset=="undefined";)m++;l[u].offset=(l[m].offset-l[p].offset)/(m-p)*(u-p)+l[p].offset}else p=u;return[`satori_bi${t}`,`<linearGradient id="satori_bi${t}" x1="${a}" y1="${n}" x2="${i}" y2="${f}">${l.map(u=>`<stop offset="${u.offset*100}%" stop-color="${u.color}"/>`).join("")}</linearGradient>`]}if(e.startsWith("url(")){let o=e.slice(4,-1);return[`satori_bi${t}`,`<pattern id="satori_bi${t}" patternContentUnits="objectBoundingBox" width="1" height="1"><image href="${o}" x="0" y="0" width="1" height="1"/></pattern>`]}}function D(t,r,e){return e<t+r&&(e/2<t&&e/2<r?t=r=e/2:e/2<t?t=e-r:e/2<r&&(r=e-t)),[t,r]}function W({left:t,top:r,width:e,height:o},a){let{borderTopLeftRadius:n,borderTopRightRadius:i,borderBottomLeftRadius:f,borderBottomRightRadius:c}=a;return n=Math.min(n||0,e,o),i=Math.min(i||0,e,o),f=Math.min(f||0,e,o),c=Math.min(c||0,e,o),!n&&!i&&!f&&!c?"":([n,i]=D(n,i,e),[n,f]=D(n,f,o),[i,c]=D(i,c,o),[f,c]=D(f,c,e),`M${t+n},${r} h${e-n-i} a${i},${i} 0 0 1 ${i},${i} v${o-i-c} a${c},${c} 0 0 1 ${-c},${c} h${c+f-e} a${f},${f} 0 0 1 ${-f},${-f} v${f+n-o} a${n},${n} 0 0 1 ${n},${-n}`)}function O({id:t,width:r,height:e},o){if(!o.shadowColor||!o.shadowOffset||typeof o.shadowRadius=="undefined")return"";let a=Math.min(o.shadowOffset.width-o.shadowRadius*2,0),n=Math.max(o.shadowOffset.width+o.shadowRadius*2+r,r),i=Math.min(o.shadowOffset.height-o.shadowRadius*2,0),f=Math.max(o.shadowOffset.height+o.shadowRadius*2+e,e);return`<defs><filter id="satori_s-${t}" x="${a/r*100}%" y="${i/e*100}%" width="${(n-a)/r*100}%" height="${(f-i)/e*100}%"><feDropShadow dx="${o.shadowOffset.width}" dy="${o.shadowOffset.height}" stdDeviation="${o.shadowRadius}" flood-color="${o.shadowColor}" flood-opacity="1"/></filter></defs>`}function V({id:t,left:r,top:e,width:o,height:a,isInheritingTransform:n},i){if(i.display==="none")return"";let f="rect",c="transparent",l=0,d="",p="",m=[],u=1;if(i.backgroundColor&&m.push(i.backgroundColor),i.borderWidth&&(l=i.borderWidth,c=i.borderColor),i.opacity&&(u=+i.opacity),i.transform&&(d=F({left:r,top:e,width:o,height:a},i.transform,n)),i.backgroundImage){let y=i.backgroundImage.map((E,A)=>J({id:t+"_"+A,width:o,height:a},E)).filter(Boolean);for(let E of y)p+=E[1],m.push(`url(#${E[0]})`)}let g=W({left:r,top:e,width:o,height:a},i);g&&(f="path");let h=O({width:o,height:a,id:t},i);return m.length||m.push("transparent"),`${p?`<defs>${p}</defs>`:""}${h?`${h}<g filter="url(#satori_s-${t})">`:""}${u!==1?`<g opacity="${u}">`:""}${m.map((y,E)=>y==="transparent"&&!(E===m.length-1&&l)?"":`<${f} x="${r}" y="${e}" width="${o}" height="${a}" fill="${y}" ${E===m.length-1&&l?`stroke="${c}" stroke-width="${l}"`:""} ${g?`d="${g}"`:""} ${d?`transform="${d}"`:""}></${f}>`).join("")}${u!==1?"</g>":""}${h?"</g>":""}`}function j({id:t,left:r,top:e,width:o,height:a,src:n},i){if(i.display==="none")return"";let f="",c=1,l=i.objectFit==="contain"?"xMidYMid":i.objectFit==="cover"?"xMidYMid slice":"none",d=W({left:r,top:e,width:o,height:a},i);d&&(f=`<clipPath id="satori_c-${t}"><path x="${r}" y="${e}" width="${o}" height="${a}" d="${d}"></path></clipPath>`),i.opacity&&(c=+i.opacity);let p=O({width:o,height:a,id:t},i);return`${p}${p?`<g filter="url(#satori_s-${t})">`:""}${f}<image href="${n}" x="${r}" y="${e}" width="${o}" height="${a}" preserveAspectRatio="${l}" ${f?`clip-path="url(#satori_c-${t})"`:""} ${c!==1?`opacity="${c}"`:""}></image>${p?"</g>":""}`}function*k(t,r){let{id:e,inheritedStyle:o,parent:a,font:n}=r;if(t===null||typeof t=="undefined")return yield,"";if(!w(t)||typeof t.type=="function"){let _;if(!w(t))_=z(String(t),r);else{if(st(t.type))throw new Error("Class component is not supported.");_=k(t.type(t.props),r)}_.next();let P=yield;return _.next(P).value}let{type:i,props:f}=t,{style:c,children:l}=f,d=dt.default.Node.create();a.insertChild(d,a.getChildCount());let[p,m]=H(d,i,o,c,f),u=p.transform===o.transform;u||(p.transform.__parent=o.transform);let g=typeof l=="undefined"?[]:[].concat(l),h=[],y=0;for(let _ of g){let P=k(_,{id:e*g.length+ ++y,parentStyle:p,inheritedStyle:m,isInheritingTransform:!0,parent:d,font:n});P.next(),h.push(P)}let[E,A]=yield;p.position==="absolute"&&d.calculateLayout();let{left:S,top:$,width:Z,height:tt}=d.getComputedLayout();S+=E,$+=A;let G="";i==="img"?G=j({id:e,left:S,top:$,width:Z,height:tt,src:f.src,isInheritingTransform:u},p):G=V({id:e,left:S,top:$,width:Z,height:tt,isInheritingTransform:u},p);for(let _ of h)G+=_.next([S,$]).value;return G}var q=R(require("opentype.js")),M=class{constructor(r){this.fonts=new Map;for(let e of r){let o=e.data,a="buffer"in o?q.default.parse(o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)):q.default.parse(o);this.defaultFont||(this.defaultFont=a),this.fonts.has(e.name)||this.fonts.set(e.name,[]),this.fonts.get(e.name).push([a,e.weight,e.style])}}get({name:r,weight:e,style:o}){if(!this.fonts.has(r))return this.defaultFont;e==="normal"&&(e=400),e==="bold"&&(e=700);let a=[...this.fonts.get(r)];return a.sort(([n,i,f],[c,l,d])=>{if(i!==l)return i?!l||i===e?-1:l===e?1:e===400&&i===500||e===500&&i===400?-1:e===400&&l===500||e===500&&l===400?1:e<400?i<e&&l<e?l-i:i<e?-1:l<e?1:i-l:e<i&&e<l?i-l:e<i?-1:e<l?1:l-i:1;if(f!==d){if(f===o)return-1;if(d===o)return 1}return-1}),a[0][0]}measure(r,{fontFamily:e,fontSize:o,fontWeight:a=400,fontStyle:n="normal"}){let i=this.get({name:e,weight:a,style:n});return{width:i.getAdvanceWidth(r,o),ascent:i.ascender/i.unitsPerEm*o,descent:-(i.descender/i.unitsPerEm)*o}}getSVG(r,{fontFamily:e,fontSize:o,fontWeight:a=400,fontStyle:n="normal",top:i,left:f,letterSpacing:c=0}){let l=this.get({name:e,weight:a,style:n});return i+=l.ascender/l.unitsPerEm*o,l.getPath(r,f,i,o,{letterSpacing:c/o}).toPathData(3)}};function K({width:t,height:r,content:e},o){return`<svg width="${t}" height="${r}" viewBox="0 0 ${t} ${r}" xmlns="http://www.w3.org/2000/svg">${e}</svg>`}function Q(t,r){let e=new M(r.fonts),o=C.default.Node.create();o.setWidth(r.width),o.setHeight(r.height),o.setFlexDirection(C.default.FLEX_DIRECTION_ROW),o.setFlexWrap(C.default.WRAP_WRAP);let a=k(t,{id:1,parentStyle:{},inheritedStyle:{fontSize:16,fontWeight:"normal",fontFamily:"serif",fontStyle:"normal",lineHeight:1.2,color:"black",opacity:1},parent:o,font:e});a.next(),o.calculateLayout(r.width,r.height,C.default.DIRECTION_LTR);let n=a.next([0,0]).value;return K({width:r.width,height:r.height,content:n})}module.exports=xt(At);0&&(module.exports={});