satori 0.0.7 → 0.0.8-beta.3
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 +7 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +6 -1
- package/package.json +6 -6
- package/dist/index.js +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Satori
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
##
|
|
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
|
```
|
|
@@ -119,6 +121,10 @@ cd playground
|
|
|
119
121
|
pnpm dev
|
|
120
122
|
```
|
|
121
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
|
+
|
|
122
128
|
To start and live-watch the tests, run:
|
|
123
129
|
|
|
124
130
|
```bash
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var st=Object.defineProperty,ft=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var Q=(t,o,e)=>o in t?st(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,N=(t,o)=>{for(var e in o||(o={}))lt.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)=>ft(t,ut(o));import L from"yoga-layout-prebuilt";import $t from"yoga-layout-prebuilt";function w(t){let o=typeof t;return!(o==="number"||o==="bigint"||o==="string"||o==="boolean")}function tt(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]]}import s from"yoga-layout-prebuilt";var et={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 mt=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)mt.has(e)&&(o[e]=t[e]);return o}import dt,{getPropertyName as pt}from"css-to-react-native";import ot from"parse-css-dimension";import{parseElementStyle as gt}from"css-background-parser";var ht=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),rt=[1,0,0,1,0,0];function bt(t,o){return typeof o=="number"?ht.has(t)?String(o):o+"px":o}function nt(t,o){if(typeof t=="number")return t;try{let e=new ot(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 B(t,o){let e=[];for(let r in t){let i=pt(r);e.push([i,bt(i,t[r])])}let n=dt(e);if(n.backgroundImage){let{backgrounds:r}=gt(n);n.backgroundImage=r}let f=n.fontSize||o.fontSize;if(typeof f=="string")try{let r=new ot(f);switch(r.unit){case"em":f=r.value*o.fontSize;break;case"rem":f=r.value*16;break}}catch{f=16}n.fontSize=f;for(let r in n){let i=n[r];if(typeof i=="string"){let a=nt(i,f);typeof a!="undefined"&&(n[r]=a),i=n[r]}if(r==="opacity"&&(i=n[r]=i*o.opacity),r==="transform"){let a=[...rt],c=i;for(let u of c){let d=Object.keys(u)[0],g=u[d],m=typeof g=="string"?nt(g,f):g,l=[...rt];switch(d){case"translateX":l[4]=m;break;case"translateY":l[5]=m;break;case"scaleX":l[0]=m;break;case"scaleY":l[3]=m;break;case"rotate":let p=m*Math.PI/180,h=Math.cos(p),E=Math.sin(p);l[0]=h,l[1]=E,l[2]=-E,l[3]=h;break;case"skewX":l[2]=Math.tan(m*Math.PI/180);break;case"skewY":l[1]=Math.tan(m*Math.PI/180);break}a=F(l,a)}n.transform=a}}return n}function S(t,o,e){let n=o[t];return typeof n=="undefined"?e:n}function Y(t,o,e,n,f){let r=N(N(N({},e),B(et[o],e)),B(n,e));if(o==="img"){let i=parseInt(f.width),c=parseInt(f.height)/i;r.width||(r.width=i),r.height||(r.height=c*r.width)}return t.setDisplay(S(r.display,{flex:s.DISPLAY_FLEX,none:s.DISPLAY_NONE},s.DISPLAY_FLEX)),t.setAlignContent(S(r.alignContent,{stretch:s.ALIGN_STRETCH,center:s.ALIGN_CENTER,"flex-start":s.ALIGN_FLEX_START,"flex-end":s.ALIGN_FLEX_END,"space-between":s.ALIGN_SPACE_BETWEEN,"space-around":s.ALIGN_SPACE_AROUND,baseline:s.ALIGN_BASELINE,normal:s.ALIGN_AUTO},s.ALIGN_AUTO)),t.setAlignItems(S(r.alignItems,{stretch:s.ALIGN_STRETCH,center:s.ALIGN_CENTER,"flex-start":s.ALIGN_FLEX_START,"flex-end":s.ALIGN_FLEX_END,baseline:s.ALIGN_BASELINE,normal:s.ALIGN_AUTO},s.ALIGN_FLEX_START)),t.setAlignSelf(S(r.alignSelf,{stretch:s.ALIGN_STRETCH,center:s.ALIGN_CENTER,"flex-start":s.ALIGN_FLEX_START,"flex-end":s.ALIGN_FLEX_END,baseline:s.ALIGN_BASELINE,normal:s.ALIGN_AUTO},s.ALIGN_AUTO)),t.setJustifyContent(S(r.justifyContent,{center:s.JUSTIFY_CENTER,"flex-start":s.JUSTIFY_FLEX_START,"flex-end":s.JUSTIFY_FLEX_END,"space-between":s.JUSTIFY_SPACE_BETWEEN,"space-around":s.JUSTIFY_SPACE_AROUND},s.JUSTIFY_FLEX_START)),t.setFlexDirection(S(r.flexDirection,{row:s.FLEX_DIRECTION_ROW,column:s.FLEX_DIRECTION_COLUMN,"row-reverse":s.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":s.FLEX_DIRECTION_COLUMN_REVERSE},s.FLEX_DIRECTION_ROW)),t.setFlexWrap(S(r.flexWrap,{wrap:s.WRAP_WRAP,nowrap:s.WRAP_NO_WRAP,"wrap-reverse":s.WRAP_WRAP_REVERSE},s.WRAP_WRAP)),typeof r.flexBasis!="undefined"&&t.setFlexBasis(r.flexBasis),t.setFlexGrow(typeof r.flexGrow=="undefined"?0:r.flexGrow),t.setFlexShrink(typeof r.flexShrink=="undefined"?1:r.flexShrink),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(S(r.overflow,{visible:s.OVERFLOW_VISIBLE,hidden:s.OVERFLOW_HIDDEN},s.OVERFLOW_VISIBLE)),t.setMargin(s.EDGE_TOP,r.marginTop||0),t.setMargin(s.EDGE_BOTTOM,r.marginBottom||0),t.setMargin(s.EDGE_LEFT,r.marginLeft||0),t.setMargin(s.EDGE_RIGHT,r.marginRight||0),t.setBorder(s.EDGE_TOP,r.borderWidth||0),t.setBorder(s.EDGE_BOTTOM,r.borderWidth||0),t.setBorder(s.EDGE_LEFT,r.borderWidth||0),t.setBorder(s.EDGE_RIGHT,r.borderWidth||0),t.setPadding(s.EDGE_TOP,r.paddingTop||0),t.setPadding(s.EDGE_BOTTOM,r.paddingBottom||0),t.setPadding(s.EDGE_LEFT,r.paddingLeft||0),t.setPadding(s.EDGE_RIGHT,r.paddingRight||0),t.setPositionType((r.position,s.POSITION_TYPE_ABSOLUTE,s.POSITION_TYPE_RELATIVE,s.POSITION_TYPE_RELATIVE)),typeof r.top!="undefined"&&t.setPosition(s.EDGE_TOP,r.top),typeof r.bottom!="undefined"&&t.setPosition(s.EDGE_BOTTOM,r.bottom),typeof r.left!="undefined"&&t.setPosition(s.EDGE_LEFT,r.left),typeof r.right!="undefined"&&t.setPosition(s.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 I from"yoga-layout-prebuilt";import{LineBreaker as yt}from"css-line-break";function O({left:t,top:o,width:e,height:n},f,r){let i;if(r)i=f;else{let a=t+e/2,c=o+n/2;i=F([1,0,0,1,a,c],F(f,[1,0,0,1,-a,-c])),f.__parent&&(i=F(f.__parent,i)),f.splice(0,6,...i)}return`matrix(${i.join(",")})`}function X({left:t,top:o,width:e,height:n,isInheritingTransform:f,path:r,debug:i},a){let c="",u=1,d="";return a.transform&&(c=O({left:t,top:o,width:e,height:n},a.transform,f)),a.opacity&&(u=+a.opacity),i&&(d=`<rect x="${t}" y="${o}" width="${e}" height="${n}" fill="transparent" stroke="#575eff" stroke-width="1" ${c?`transform="${c}"`:""}></rect>`),`<path fill="${a.color}" ${c?`transform="${c}"`:""} ${u!==1?`opacity="${u}"`:""} d="${r}"></path>${d}`}function*U(t,o){let{parentStyle:e,parent:n,font:f,id:r,isInheritingTransform:i,debug:a}=o,c=yt(t,{lineBreak:"strict",wordBreak:"normal"}),u=[];for(let p;!(p=c.next()).done;)u.push(p.value.slice());let d=[];n.setAlignItems(I.ALIGN_BASELINE),e.textAlign==="left"?n.setJustifyContent(I.JUSTIFY_FLEX_START):e.textAlign==="center"?n.setJustifyContent(I.JUSTIFY_CENTER):e.textAlign==="right"?n.setJustifyContent(I.JUSTIFY_FLEX_END):e.textAlign==="justify"&&n.setJustifyContent(I.JUSTIFY_SPACE_BETWEEN);for(let p of u){let h=I.Node.create();n.insertChild(h,n.getChildCount());let E=f.measure(p,e),_=(e.letterSpacing||0)*p.length;h.setWidth(E.width+_),h.setHeight(E.ascent*1.2),h.setMargin(I.EDGE_BOTTOM,E.descent*1.2),d.push(h)}let[g,m]=yield,l="";for(let p=0;p<d.length;p++){let h=d[p],E=u[p];e.position==="absolute"&&h.calculateLayout();let{left:_,top:T,width:$,height:R}=h.getComputedLayout();_+=g,T+=m;let A=f.getSVG(E,Z(N({},e),{top:T,left:_,letterSpacing:e.letterSpacing}));l+=X({id:r,left:_,top:T,width:$,height:R,isInheritingTransform:i,path:A,debug:a},e)}return l}import Et from"gradient-parser";function _t(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 n=Et.parse(e)[0],f,r,i,a;if(n.orientation.type==="directional")[f,r,i,a]={top:[0,1,0,0],bottom:[0,0,0,1],left:[1,0,0,0],right:[0,0,1,0]}[n.orientation.value];else if(n.orientation.type==="angular"){let l=+n.orientation.value/180*Math.PI-Math.PI/2,p=Math.cos(l),h=Math.sin(l);f=0,r=0,i=p,a=h,i<0&&(f-=i,i=0),a<0&&(r-=a,a=0)}let c=o,u=[];for(let l of n.colorStops){let p=_t(l);if(!u.length&&(u.push({offset:0,color:p}),typeof l.length=="undefined"||l.length.value==="0"))continue;let h=typeof l.length=="undefined"?void 0:l.length.type==="%"?l.length.value/100:l.length.value/c;u.push({offset:h,color:p})}u.length||u.push({offset:0,color:"transparent"});let d=u[u.length-1];d.offset!==1&&(typeof d.offset=="undefined"?d.offset=1:u.push({offset:1,color:d.color}));let g=0,m=1;for(let l=0;l<u.length;l++)if(typeof u[l].offset=="undefined"){for(m<l&&(m=l);typeof u[m].offset=="undefined";)m++;u[l].offset=(u[m].offset-u[g].offset)/(m-g)*(l-g)+u[g].offset}else g=l;return[`satori_bi${t}`,`<linearGradient id="satori_bi${t}" x1="${f}" y1="${r}" x2="${i}" y2="${a}">${u.map(l=>`<stop offset="${l.offset*100}%" stop-color="${l.color}"/>`).join("")}</linearGradient>`]}if(e.startsWith("url(")){let n=e.slice(4,-1);return[`satori_bi${t}`,`<pattern id="satori_bi${t}" patternContentUnits="objectBoundingBox" width="1" height="1"><image href="${n}" x="0" y="0" width="1" height="1"/></pattern>`]}}function v(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:n},f){let{borderTopLeftRadius:r,borderTopRightRadius:i,borderBottomLeftRadius:a,borderBottomRightRadius:c}=f;return r=Math.min(r||0,e,n),i=Math.min(i||0,e,n),a=Math.min(a||0,e,n),c=Math.min(c||0,e,n),!r&&!i&&!a&&!c?"":([r,i]=v(r,i,e),[r,a]=v(r,a,n),[i,c]=v(i,c,n),[a,c]=v(a,c,e),`M${t+r},${o} h${e-r-i} a${i},${i} 0 0 1 ${i},${i} v${n-i-c} a${c},${c} 0 0 1 ${-c},${c} h${c+a-e} a${a},${a} 0 0 1 ${-a},${-a} v${a+r-n} a${r},${r} 0 0 1 ${r},${-r}`)}function k({id:t,width:o,height:e},n){if(!n.shadowColor||!n.shadowOffset||typeof n.shadowRadius=="undefined")return"";let f=Math.min(n.shadowOffset.width-n.shadowRadius*2,0),r=Math.max(n.shadowOffset.width+n.shadowRadius*2+o,o),i=Math.min(n.shadowOffset.height-n.shadowRadius*2,0),a=Math.max(n.shadowOffset.height+n.shadowRadius*2+e,e);return`<defs><filter id="satori_s-${t}" x="${f/o*100}%" y="${i/e*100}%" width="${(r-f)/o*100}%" height="${(a-i)/e*100}%"><feDropShadow dx="${n.shadowOffset.width}" dy="${n.shadowOffset.height}" stdDeviation="${n.shadowRadius}" flood-color="${n.shadowColor}" flood-opacity="1"/></filter></defs>`}function J({id:t,left:o,top:e,width:n,height:f,isInheritingTransform:r,debug:i},a){if(a.display==="none")return"";let c="rect",u="transparent",d=0,g="",m="",l=[],p=1,h="";if(a.backgroundColor&&l.push(a.backgroundColor),a.borderWidth&&(d=a.borderWidth,u=a.borderColor),a.opacity&&(p=+a.opacity),a.transform&&(g=O({left:o,top:e,width:n,height:f},a.transform,r)),a.backgroundImage){let T=a.backgroundImage.map(($,R)=>H({id:t+"_"+R,width:n,height:f},$)).filter(Boolean);for(let $ of T)m+=$[1],l.push(`url(#${$[0]})`)}let E=W({left:o,top:e,width:n,height:f},a);E&&(c="path");let _=k({width:n,height:f,id:t},a);return l.length||l.push("transparent"),i&&(h=`<rect x="${o}" y="${e}" width="${n}" height="${f}" fill="transparent" stroke="#ff5757" stroke-width="1" ${g?`transform="${g}"`:""}></rect>`),`${m?`<defs>${m}</defs>`:""}${_?`${_}<g filter="url(#satori_s-${t})">`:""}${p!==1?`<g opacity="${p}">`:""}${l.map((T,$)=>T==="transparent"&&!($===l.length-1&&d)?"":`<${c} x="${o}" y="${e}" width="${n}" height="${f}" fill="${T}" ${$===l.length-1&&d?`stroke="${u}" stroke-width="${d}"`:""} ${E?`d="${E}"`:""} ${g?`transform="${g}"`:""}></${c}>`).join("")}${p!==1?"</g>":""}${_?"</g>":""}${h}`}function z({id:t,left:o,top:e,width:n,height:f,src:r,debug:i},a){if(a.display==="none")return"";let c="",u=1,d=a.objectFit==="contain"?"xMidYMid":a.objectFit==="cover"?"xMidYMid slice":"none",g=W({left:o,top:e,width:n,height:f},a);g&&(c=`<clipPath id="satori_c-${t}"><path x="${o}" y="${e}" width="${n}" height="${f}" d="${g}"></path></clipPath>`),a.opacity&&(u=+a.opacity);let m=k({width:n,height:f,id:t},a);return`${m}${m?`<g filter="url(#satori_s-${t})">`:""}${c}<image href="${r}" x="${o}" y="${e}" width="${n}" height="${f}" preserveAspectRatio="${d}" ${c?`clip-path="url(#satori_c-${t})"`:""} ${u!==1?`opacity="${u}"`:""}></image>${m?"</g>":""}`}function*C(t,o){let{id:e,inheritedStyle:n,parent:f,font:r,debug:i}=o;if(t===null||typeof t=="undefined")return yield,"";if(!w(t)||typeof t.type=="function"){let x;if(!w(t))x=U(String(t),o);else{if(tt(t.type))throw new Error("Class component is not supported.");x=C(t.type(t.props),o)}x.next();let P=yield;return x.next(P).value}let{type:a,props:c}=t,{style:u,children:d}=c,g=$t.Node.create();f.insertChild(g,f.getChildCount());let[m,l]=Y(g,a,n,u,c),p=m.transform===n.transform;p||(m.transform.__parent=n.transform);let h=typeof d=="undefined"?[]:[].concat(d),E=[],_=0;for(let x of h){let P=C(x,{id:e*h.length+ ++_,parentStyle:m,inheritedStyle:l,isInheritingTransform:!0,parent:g,font:r,debug:i});P.next(),E.push(P)}let[T,$]=yield;m.position==="absolute"&&g.calculateLayout();let{left:R,top:A,width:j,height:q}=g.getComputedLayout();R+=T,A+=$;let G="";a==="img"?G=z({id:e,left:R,top:A,width:j,height:q,src:c.src,isInheritingTransform:p,debug:i},m):G=J({id:e,left:R,top:A,width:j,height:q,isInheritingTransform:p,debug:i},m);for(let x of E)G+=x.next([R,A]).value;return G}import it from"opentype.js";var D=class{constructor(o){this.fonts=new Map;for(let e of o){let n=e.data,f="buffer"in n?it.parse(n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)):it.parse(n);this.defaultFont||(this.defaultFont=f),this.fonts.has(e.name)||this.fonts.set(e.name,[]),this.fonts.get(e.name).push([f,e.weight,e.style])}}get({name:o,weight:e,style:n}){if(!this.fonts.has(o))return this.defaultFont;e==="normal"&&(e=400),e==="bold"&&(e=700);let f=[...this.fonts.get(o)];return f.sort(([r,i,a],[c,u,d])=>{if(i!==u)return i?!u||i===e?-1:u===e?1:e===400&&i===500||e===500&&i===400?-1:e===400&&u===500||e===500&&u===400?1:e<400?i<e&&u<e?u-i:i<e?-1:u<e?1:i-u:e<i&&e<u?i-u:e<i?-1:e<u?1:u-i:1;if(a!==d){if(a===n)return-1;if(d===n)return 1}return-1}),f[0][0]}measure(o,{fontFamily:e,fontSize:n,fontWeight:f=400,fontStyle:r="normal"}){let i=this.get({name:e,weight:f,style:r});return{width:i.getAdvanceWidth(o,n),ascent:i.ascender/i.unitsPerEm*n,descent:-(i.descender/i.unitsPerEm)*n}}getSVG(o,{fontFamily:e,fontSize:n,fontWeight:f=400,fontStyle:r="normal",top:i,left:a,letterSpacing:c=0}){let u=this.get({name:e,weight:f,style:r});return i+=u.ascender/u.unitsPerEm*n,u.getPath(o,a,i,n,{letterSpacing:c/n}).toPathData(3)}};function V({width:t,height:o,content:e},n){return`<svg width="${t}" height="${o}" viewBox="0 0 ${t} ${o}" xmlns="http://www.w3.org/2000/svg">${e}</svg>`}function at(t,o){let e=new D(o.fonts),n=L.Node.create();n.setWidth(o.width),n.setHeight(o.height),n.setFlexDirection(L.FLEX_DIRECTION_ROW),n.setFlexWrap(L.WRAP_WRAP),n.setAlignContent(L.ALIGN_AUTO),n.setAlignItems(L.ALIGN_FLEX_START),n.setJustifyContent(L.JUSTIFY_FLEX_START);let f=C(t,{id:1,parentStyle:{},inheritedStyle:{fontSize:16,fontWeight:"normal",fontFamily:"serif",fontStyle:"normal",lineHeight:1.2,color:"black",opacity:1},parent:n,font:e,debug:o.debug});f.next(),n.calculateLayout(o.width,o.height,L.DIRECTION_LTR);let r=f.next([0,0]).value;return V({width:o.width,height:o.height,content:r})}export{at as default};
|
|
1
|
+
var xt=Object.defineProperty,$t=Object.defineProperties;var St=Object.getOwnPropertyDescriptors;var st=Object.getOwnPropertySymbols;var _t=Object.prototype.hasOwnProperty,Rt=Object.prototype.propertyIsEnumerable;var ft=(t,o,e)=>o in t?xt(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,G=(t,o)=>{for(var e in o||(o={}))_t.call(o,e)&&ft(t,e,o[e]);if(st)for(var e of st(o))Rt.call(o,e)&&ft(t,e,o[e]);return t},ut=(t,o)=>$t(t,St(o));var lt;function Tt(t){lt=t}function Lt(){return lt}var v=Lt;function J(t){let o=typeof t;return!(o==="number"||o==="bigint"||o==="string"||o==="boolean")}function ct(t){return/^class\s/.test(Function.prototype.toString.call(t))}function w(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 mt={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 It=new Set(["color","font","fontFamily","fontSize","fontStyle","fontWeight","lineHeight","textAlign","textTransform","whiteSpace","letterSpacing","transform","opacity"]);function j(t){let o={};for(let e in t)It.has(e)&&(o[e]=t[e]);return o}import{getPropertyName as dt,getStylesForProperty as At}from"css-to-react-native";import ht from"parse-css-dimension";import{parseElementStyle as Ft}from"css-background-parser";var Nt=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),pt=[1,0,0,1,0,0];function Ct(t,o){return typeof o=="number"?Nt.has(t)?String(o):o+"px":o}function gt(t,o){if(typeof t=="number")return t;try{let e=new ht(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 U(t,o){let e=[];for(let n in t){let r=dt(n);e.push([r,Ct(r,t[n])])}let i=e.reduce((n,r)=>{let s=dt(r[0]),u=r[1];return Object.assign(n,At(s,u,!0))},{});if(i.backgroundImage){let{backgrounds:n}=Ft(i);i.backgroundImage=n}let a=i.fontSize||o.fontSize;if(typeof a=="string")try{let n=new ht(a);switch(n.unit){case"em":a=n.value*o.fontSize;break;case"rem":a=n.value*16;break}}catch{a=16}i.fontSize=a;for(let n in i){let r=i[n];if(typeof r=="string"){let s=gt(r,a);typeof s!="undefined"&&(i[n]=s),r=i[n]}if(n==="opacity"&&(r=i[n]=r*o.opacity),n==="transform"){let s=[...pt],u=r;for(let f of u){let d=Object.keys(f)[0],p=f[d],m=typeof p=="string"?gt(p,a):p,l=[...pt];switch(d){case"translateX":l[4]=m;break;case"translateY":l[5]=m;break;case"scaleX":l[0]=m;break;case"scaleY":l[3]=m;break;case"rotate":let b=m*Math.PI/180,S=Math.cos(b),h=Math.sin(b);l[0]=S,l[1]=h,l[2]=-h,l[3]=S;break;case"skewX":l[2]=Math.tan(m*Math.PI/180);break;case"skewY":l[1]=Math.tan(m*Math.PI/180);break}s=w(l,s)}i.transform=s}}return i}function F(t,o,e){let i=o[t];return typeof i=="undefined"?e:i}function K(t,o,e,i,a){let n=v(),r=G(G(G({},e),U(mt[o],e)),U(i,e));if(o==="img"){let s=parseInt(a.width),f=parseInt(a.height)/s;r.width||(r.width=s),r.height||(r.height=f*r.width)}return t.setDisplay(F(r.display,{flex:n.DISPLAY_FLEX,none:n.DISPLAY_NONE},n.DISPLAY_FLEX)),t.setAlignContent(F(r.alignContent,{stretch:n.ALIGN_STRETCH,center:n.ALIGN_CENTER,"flex-start":n.ALIGN_FLEX_START,"flex-end":n.ALIGN_FLEX_END,"space-between":n.ALIGN_SPACE_BETWEEN,"space-around":n.ALIGN_SPACE_AROUND,baseline:n.ALIGN_BASELINE,normal:n.ALIGN_AUTO},n.ALIGN_AUTO)),t.setAlignItems(F(r.alignItems,{stretch:n.ALIGN_STRETCH,center:n.ALIGN_CENTER,"flex-start":n.ALIGN_FLEX_START,"flex-end":n.ALIGN_FLEX_END,baseline:n.ALIGN_BASELINE,normal:n.ALIGN_AUTO},n.ALIGN_FLEX_START)),t.setAlignSelf(F(r.alignSelf,{stretch:n.ALIGN_STRETCH,center:n.ALIGN_CENTER,"flex-start":n.ALIGN_FLEX_START,"flex-end":n.ALIGN_FLEX_END,baseline:n.ALIGN_BASELINE,normal:n.ALIGN_AUTO},n.ALIGN_AUTO)),t.setJustifyContent(F(r.justifyContent,{center:n.JUSTIFY_CENTER,"flex-start":n.JUSTIFY_FLEX_START,"flex-end":n.JUSTIFY_FLEX_END,"space-between":n.JUSTIFY_SPACE_BETWEEN,"space-around":n.JUSTIFY_SPACE_AROUND},n.JUSTIFY_FLEX_START)),t.setFlexDirection(F(r.flexDirection,{row:n.FLEX_DIRECTION_ROW,column:n.FLEX_DIRECTION_COLUMN,"row-reverse":n.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":n.FLEX_DIRECTION_COLUMN_REVERSE},n.FLEX_DIRECTION_ROW)),t.setFlexWrap(F(r.flexWrap,{wrap:n.WRAP_WRAP,nowrap:n.WRAP_NO_WRAP,"wrap-reverse":n.WRAP_WRAP_REVERSE},n.WRAP_WRAP)),typeof r.flexBasis!="undefined"&&t.setFlexBasis(r.flexBasis),t.setFlexGrow(typeof r.flexGrow=="undefined"?0:r.flexGrow),t.setFlexShrink(typeof r.flexShrink=="undefined"?1:r.flexShrink),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(F(r.overflow,{visible:n.OVERFLOW_VISIBLE,hidden:n.OVERFLOW_HIDDEN},n.OVERFLOW_VISIBLE)),t.setMargin(n.EDGE_TOP,r.marginTop||0),t.setMargin(n.EDGE_BOTTOM,r.marginBottom||0),t.setMargin(n.EDGE_LEFT,r.marginLeft||0),t.setMargin(n.EDGE_RIGHT,r.marginRight||0),t.setBorder(n.EDGE_TOP,r.borderWidth||0),t.setBorder(n.EDGE_BOTTOM,r.borderWidth||0),t.setBorder(n.EDGE_LEFT,r.borderWidth||0),t.setBorder(n.EDGE_RIGHT,r.borderWidth||0),t.setPadding(n.EDGE_TOP,r.paddingTop||0),t.setPadding(n.EDGE_BOTTOM,r.paddingBottom||0),t.setPadding(n.EDGE_LEFT,r.paddingLeft||0),t.setPadding(n.EDGE_RIGHT,r.paddingRight||0),t.setPositionType(F(r.position,{absolute:n.POSITION_TYPE_ABSOLUTE,relative:n.POSITION_TYPE_RELATIVE},n.POSITION_TYPE_RELATIVE)),typeof r.top!="undefined"&&t.setPosition(n.EDGE_TOP,r.top),typeof r.bottom!="undefined"&&t.setPosition(n.EDGE_BOTTOM,r.bottom),typeof r.left!="undefined"&&t.setPosition(n.EDGE_LEFT,r.left),typeof r.right!="undefined"&&t.setPosition(n.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,j(r)]}import{LineBreaker as Ot}from"css-line-break";function B({left:t,top:o,width:e,height:i},a,n){let r;if(n)r=a;else{let s=t+e/2,u=o+i/2;r=w([1,0,0,1,s,u],w(a,[1,0,0,1,-s,-u])),a.__parent&&(r=w(a.__parent,r)),a.splice(0,6,...r)}return`matrix(${r.join(",")})`}function q({content:t,left:o,top:e,width:i,height:a,isInheritingTransform:n,path:r,debug:s},u){let f="",d=1,p="";return u.transform&&(f=B({left:o,top:e,width:i,height:a},u.transform,n)),u.opacity&&(d=+u.opacity),s&&(p=`<rect x="${o}" y="${e}" width="${i}" height="${r===null?.5:a}" fill="transparent" stroke="#575eff" stroke-width="1" ${f?`transform="${f}"`:""}></rect>`),r===null?`<text x="${o}" y="${e}" width="${i}" height="${a}" fill="${u.color}" font-weight="${u.fontWeight}" font-style="${u.fontStyle}" font-size="${u.fontSize}" font-family="${u.fontFamily}" ${u.letterSpacing?`letter-spacing="${u.letterSpacing}"`:""} ${f?`transform="${f}"`:""} ${d!==1?`opacity="${d}"`:""}>${t}</text>${p}`:`<path fill="${u.color}" ${f?`transform="${f}"`:""} ${d!==1?`opacity="${d}"`:""} d="${r}"></path>${p}`}function*Z(t,o){let e=v(),{parentStyle:i,parent:a,font:n,id:r,isInheritingTransform:s,debug:u,embedFont:f}=o,d=Ot(t,{lineBreak:"strict",wordBreak:"normal"}),p=[];for(let h;!(h=d.next()).done;)p.push(h.value.slice());let m=[];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 h of p){let _=e.Node.create();a.insertChild(_,a.getChildCount());let R=n.measure(h,i),y=(i.letterSpacing||0)*h.length;_.setWidth(R.width+y),_.setHeight(R.ascent*1.2),_.setMargin(e.EDGE_BOTTOM,R.descent*1.2),m.push(_)}let[l,b]=yield,S="";for(let h=0;h<m.length;h++){let _=m[h],R=p[h];i.position==="absolute"&&_.calculateLayout();let{left:y,top:I,width:P,height:N}=_.getComputedLayout();y+=l,I+=b;let A=null;f?A=n.getSVG(R,ut(G({},i),{top:I,left:y,letterSpacing:i.letterSpacing})):I+=n.getAscent(i),S+=q({content:R,id:r,left:y,top:I,width:P,height:N,isInheritingTransform:s,path:A,debug:u},i)}return S}var Q=Q||{};Q.parse=function(){var t={linearGradient:/^(\-(webkit|o|ms|moz)\-)?(linear\-gradient)/i,repeatingLinearGradient:/^(\-(webkit|o|ms|moz)\-)?(repeating\-linear\-gradient)/i,radialGradient:/^(\-(webkit|o|ms|moz)\-)?(radial\-gradient)/i,repeatingRadialGradient:/^(\-(webkit|o|ms|moz)\-)?(repeating\-radial\-gradient)/i,sideOrCorner:/^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,extentKeywords:/^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,positionKeywords:/^(left|center|right|top|bottom)/i,pixelValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,percentageValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,emValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,angleValue:/^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,startCall:/^\(/,endCall:/^\)/,comma:/^,/,hexColor:/^\#([0-9a-fA-F]+)/,literalColor:/^([a-zA-Z]+)/,rgbColor:/^rgb/i,rgbaColor:/^rgba/i,number:/^(([0-9]*\.[0-9]+)|([0-9]+\.?))/},o="";function e(c){var g=new Error(o+": "+c);throw g.source=o,g}function i(){var c=a();return o.length>0&&e("Invalid input not EOF"),c}function a(){return y(n)}function n(){return r("linear-gradient",t.linearGradient,u)||r("repeating-linear-gradient",t.repeatingLinearGradient,u)||r("radial-gradient",t.radialGradient,p)||r("repeating-radial-gradient",t.repeatingRadialGradient,p)}function r(c,g,E){return s(g,function(O){var at=E();return at&&(C(t.comma)||e("Missing comma before color stops")),{type:c,orientation:at,colorStops:y(I)}})}function s(c,g){var E=C(c);if(E){C(t.startCall)||e("Missing (");var O=g(E);return C(t.endCall)||e("Missing )"),O}}function u(){return f()||d()}function f(){return L("directional",t.sideOrCorner,1)}function d(){return L("angular",t.angleValue,1)}function p(){var c,g=m(),E;return g&&(c=[],c.push(g),E=o,C(t.comma)&&(g=m(),g?c.push(g):o=E)),c}function m(){var c=l()||b();if(c)c.at=h();else{var g=S();if(g){c=g;var E=h();E&&(c.at=E)}else{var O=_();O&&(c={type:"default-radial",at:O})}}return c}function l(){var c=L("shape",/^(circle)/i,0);return c&&(c.style=ot()||S()),c}function b(){var c=L("shape",/^(ellipse)/i,0);return c&&(c.style=T()||S()),c}function S(){return L("extent-keyword",t.extentKeywords,1)}function h(){if(L("position",/^at/,0)){var c=_();return c||e("Missing positioning value"),c}}function _(){var c=R();if(c.x||c.y)return{type:"position",value:c}}function R(){return{x:T(),y:T()}}function y(c){var g=c(),E=[];if(g)for(E.push(g);C(t.comma);)g=c(),g?E.push(g):e("One extra comma");return E}function I(){var c=P();return c||e("Expected color definition"),c.length=T(),c}function P(){return A()||z()||X()||N()}function N(){return L("literal",t.literalColor,0)}function A(){return L("hex",t.hexColor,1)}function X(){return s(t.rgbColor,function(){return{type:"rgb",value:y(k)}})}function z(){return s(t.rgbaColor,function(){return{type:"rgba",value:y(k)}})}function k(){return C(t.number)[1]}function T(){return L("%",t.percentageValue,1)||W()||ot()}function W(){return L("position-keyword",t.positionKeywords,1)}function ot(){return L("px",t.pixelValue,1)||L("em",t.emValue,1)}function L(c,g,E){var O=C(g);if(O)return{type:c,value:O[E]}}function C(c){var g,E;return E=/^[\n\r\t\s]+/.exec(o),E&&it(E[0].length),g=c.exec(o),g&&it(g[0].length),g}function it(c){o=o.substr(c)}return function(c){return o=c.toString(),i()}}();var bt=Q;function vt(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 tt({id:t,width:o},{image:e}){if(e.startsWith("linear-gradient(")){let i=bt.parse(e)[0],a,n,r,s;if(i.orientation.type==="directional")[a,n,r,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 l=+i.orientation.value/180*Math.PI-Math.PI/2,b=Math.cos(l),S=Math.sin(l);a=0,n=0,r=b,s=S,r<0&&(a-=r,r=0),s<0&&(n-=s,s=0)}let u=o,f=[];for(let l of i.colorStops){let b=vt(l);if(!f.length&&(f.push({offset:0,color:b}),typeof l.length=="undefined"||l.length.value==="0"))continue;let S=typeof l.length=="undefined"?void 0:l.length.type==="%"?l.length.value/100:l.length.value/u;f.push({offset:S,color:b})}f.length||f.push({offset:0,color:"transparent"});let d=f[f.length-1];d.offset!==1&&(typeof d.offset=="undefined"?d.offset=1:f.push({offset:1,color:d.color}));let p=0,m=1;for(let l=0;l<f.length;l++)if(typeof f[l].offset=="undefined"){for(m<l&&(m=l);typeof f[m].offset=="undefined";)m++;f[l].offset=(f[m].offset-f[p].offset)/(m-p)*(l-p)+f[p].offset}else p=l;return[`satori_bi${t}`,`<linearGradient id="satori_bi${t}" x1="${a}" y1="${n}" x2="${r}" y2="${s}">${f.map(l=>`<stop offset="${l.offset*100}%" stop-color="${l.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 H(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 D({left:t,top:o,width:e,height:i},a){let{borderTopLeftRadius:n,borderTopRightRadius:r,borderBottomLeftRadius:s,borderBottomRightRadius:u}=a;return n=Math.min(n||0,e,i),r=Math.min(r||0,e,i),s=Math.min(s||0,e,i),u=Math.min(u||0,e,i),!n&&!r&&!s&&!u?"":([n,r]=H(n,r,e),[n,s]=H(n,s,i),[r,u]=H(r,u,i),[s,u]=H(s,u,e),`M${t+n},${o} h${e-n-r} a${r},${r} 0 0 1 ${r},${r} v${i-r-u} a${u},${u} 0 0 1 ${-u},${u} h${u+s-e} a${s},${s} 0 0 1 ${-s},${-s} v${s+n-i} a${n},${n} 0 0 1 ${n},${-n}`)}function M({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),n=Math.max(i.shadowOffset.width+i.shadowRadius*2+o,o),r=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="${r/e*100}%" width="${(n-a)/o*100}%" height="${(s-r)/e*100}%"><feDropShadow dx="${i.shadowOffset.width}" dy="${i.shadowOffset.height}" stdDeviation="${i.shadowRadius}" flood-color="${i.shadowColor}" flood-opacity="1"/></filter></defs>`}function et({id:t,left:o,top:e,width:i,height:a,isInheritingTransform:n,debug:r},s){if(s.display==="none")return"";let u="rect",f="transparent",d=0,p="",m="",l=[],b=1,S="";if(s.backgroundColor&&l.push(s.backgroundColor),s.borderWidth&&(d=s.borderWidth,f=s.borderColor),s.opacity&&(b=+s.opacity),s.transform&&(p=B({left:o,top:e,width:i,height:a},s.transform,n)),s.backgroundImage){let R=s.backgroundImage.map((y,I)=>tt({id:t+"_"+I,width:i,height:a},y)).filter(Boolean);for(let y of R)m+=y[1],l.push(`url(#${y[0]})`)}let h=D({left:o,top:e,width:i,height:a},s);h&&(u="path");let _=M({width:i,height:a,id:t},s);return l.length||l.push("transparent"),r&&(S=`<rect x="${o}" y="${e}" width="${i}" height="${a}" fill="transparent" stroke="#ff5757" stroke-width="1" ${p?`transform="${p}"`:""}></rect>`),`${m?`<defs>${m}</defs>`:""}${_?`${_}<g filter="url(#satori_s-${t})">`:""}${b!==1?`<g opacity="${b}">`:""}${l.map((R,y)=>R==="transparent"&&!(y===l.length-1&&d)?"":`<${u} x="${o}" y="${e}" width="${i}" height="${a}" fill="${R}" ${y===l.length-1&&d?`stroke="${f}" stroke-width="${d}"`:""} ${h?`d="${h}"`:""} ${p?`transform="${p}"`:""}></${u}>`).join("")}${b!==1?"</g>":""}${_?"</g>":""}${S}`}function rt({id:t,left:o,top:e,width:i,height:a,src:n,debug:r},s){if(s.display==="none")return"";let u="",f=1,d=s.objectFit==="contain"?"xMidYMid":s.objectFit==="cover"?"xMidYMid slice":"none",p=D({left:o,top:e,width:i,height:a},s);p&&(u=`<clipPath id="satori_c-${t}"><path x="${o}" y="${e}" width="${i}" height="${a}" d="${p}"></path></clipPath>`),s.opacity&&(f=+s.opacity);let m=M({width:i,height:a,id:t},s);return`${m}${m?`<g filter="url(#satori_s-${t})">`:""}${u}<image href="${n}" x="${o}" y="${e}" width="${i}" height="${a}" preserveAspectRatio="${d}" ${u?`clip-path="url(#satori_c-${t})"`:""} ${f!==1?`opacity="${f}"`:""}></image>${m?"</g>":""}`}function*Y(t,o){let e=v(),{id:i,inheritedStyle:a,parent:n,font:r,debug:s,embedFont:u=!0}=o;if(t===null||typeof t=="undefined")return yield,"";if(!J(t)||typeof t.type=="function"){let T;if(!J(t))T=Z(String(t),o);else{if(ct(t.type))throw new Error("Class component is not supported.");T=Y(t.type(t.props),o)}T.next();let W=yield;return T.next(W).value}let{type:f,props:d}=t,{style:p,children:m}=d,l=e.Node.create();n.insertChild(l,n.getChildCount());let[b,S]=K(l,f,a,p,d),h=b.transform===a.transform;h||(b.transform.__parent=a.transform);let _=typeof m=="undefined"?[]:[].concat(m),R=[],y=0;for(let T of _){let W=Y(T,{id:i*_.length+ ++y,parentStyle:b,inheritedStyle:S,isInheritingTransform:!0,parent:l,font:r,embedFont:u,debug:s});W.next(),R.push(W)}let[I,P]=yield;b.position==="absolute"&&l.calculateLayout();let{left:N,top:A,width:X,height:z}=l.getComputedLayout();N+=I,A+=P;let k="";f==="img"?k=rt({id:i,left:N,top:A,width:X,height:z,src:d.src,isInheritingTransform:h,debug:s},b):k=et({id:i,left:N,top:A,width:X,height:z,isInheritingTransform:h,debug:s},b);for(let T of R)k+=T.next([N,A]).value;return k}import yt from"opentype.js";var V=class{constructor(o){this.fonts=new Map;for(let e of o){let i=e.data,a="buffer"in i?yt.parse(i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)):yt.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(([n,r,s],[u,f,d])=>{if(r!==f)return r?!f||r===e?-1:f===e?1:e===400&&r===500||e===500&&r===400?-1:e===400&&f===500||e===500&&f===400?1:e<400?r<e&&f<e?f-r:r<e?-1:f<e?1:r-f:e<r&&e<f?r-f:e<r?-1:e<f?1:f-r:1;if(s!==d){if(s===i)return-1;if(d===i)return 1}return-1}),a[0][0]}measure(o,{fontFamily:e,fontSize:i,fontWeight:a=400,fontStyle:n="normal"}){let r=this.get({name:e,weight:a,style:n});return{width:r.getAdvanceWidth(o,i),ascent:r.ascender/r.unitsPerEm*i,descent:-(r.descender/r.unitsPerEm)*i}}getSVG(o,{fontFamily:e,fontSize:i,fontWeight:a=400,fontStyle:n="normal",top:r,left:s,letterSpacing:u=0}){let f=this.get({name:e,weight:a,style:n});return r+=f.ascender/f.unitsPerEm*i,f.getPath(o,s,r,i,{letterSpacing:u/i}).toPathData(2)}getAscent({fontFamily:o,fontSize:e,fontWeight:i=400,fontStyle:a="normal"}){let n=this.get({name:o,weight:i,style:a});return n.ascender/n.unitsPerEm*e}};function nt({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 Et(t,o){let e=v();if(!e)throw new Error("Satori is not initialized.");let i=new V(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 n=Y(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});n.next(),a.calculateLayout(o.width,o.height,e.DIRECTION_LTR);let r=n.next([0,0]).value;return nt({width:o.width,height:o.height,content:r})}export{Et as default,Tt 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,8 +20,10 @@ interface SatoriOptions {
|
|
|
17
20
|
width: number;
|
|
18
21
|
height: number;
|
|
19
22
|
fonts: FontOptions[];
|
|
23
|
+
embedFont?: boolean;
|
|
20
24
|
debug?: boolean;
|
|
21
25
|
}
|
|
26
|
+
|
|
22
27
|
declare function satori(element: ReactNode, options: SatoriOptions): string;
|
|
23
28
|
|
|
24
|
-
export { SatoriOptions, satori as default };
|
|
29
|
+
export { SatoriOptions, satori as default, init };
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "satori",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8-beta.3",
|
|
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": "tsup src/index.ts --watch --format
|
|
13
|
-
"build": "tsup src/index.ts --dts --minify --format
|
|
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",
|
|
14
14
|
"test": "vitest run",
|
|
15
15
|
"dev:test": "vitest"
|
|
16
16
|
},
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"@types/node": "^17.0.13",
|
|
36
36
|
"@types/opentype.js": "^1.3.3",
|
|
37
37
|
"@types/react": "^17.0.38",
|
|
38
|
+
"@types/yoga-layout": "^1.9.4",
|
|
38
39
|
"react": "^17.0.2",
|
|
39
40
|
"tsup": "^5.11.13",
|
|
40
41
|
"typescript": "^4.5.5",
|
|
@@ -46,7 +47,6 @@
|
|
|
46
47
|
"css-to-react-native": "^3.0.0",
|
|
47
48
|
"gradient-parser": "^1.0.2",
|
|
48
49
|
"opentype.js": "^1.3.4",
|
|
49
|
-
"parse-css-dimension": "^1.1.0"
|
|
50
|
-
"yoga-layout-prebuilt": "^1.10.0"
|
|
50
|
+
"parse-css-dimension": "^1.1.0"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var ht=Object.create;var O=Object.defineProperty,bt=Object.defineProperties,yt=Object.getOwnPropertyDescriptor,Et=Object.getOwnPropertyDescriptors,_t=Object.getOwnPropertyNames,rt=Object.getOwnPropertySymbols,$t=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable;var nt=(t,r,e)=>r in t?O(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,N=(t,r)=>{for(var e in r||(r={}))ot.call(r,e)&&nt(t,e,r[e]);if(rt)for(var e of rt(r))Tt.call(r,e)&&nt(t,e,r[e]);return t},it=(t,r)=>bt(t,Et(r)),at=t=>O(t,"__esModule",{value:!0});var Rt=(t,r)=>{for(var e in r)O(t,e,{get:r[e],enumerable:!0})},st=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of _t(r))!ot.call(t,s)&&(e||s!=="default")&&O(t,s,{get:()=>r[s],enumerable:!(o=yt(r,s))||o.enumerable});return t},x=(t,r)=>st(at(O(t!=null?ht($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=st(at({}),r,1),t&&t.set(r,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var Nt={};Rt(Nt,{default:()=>Z});var L=x(require("yoga-layout-prebuilt"));var gt=x(require("yoga-layout-prebuilt"));function Y(t){let r=typeof t;return!(r==="number"||r==="bigint"||r==="string"||r==="boolean")}function ft(t){return/^class\s/.test(Function.prototype.toString.call(t))}function F(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 f=x(require("yoga-layout-prebuilt"));var ut={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 X(t){let r={};for(let e in t)St.has(e)&&(r[e]=t[e]);return r}var v=x(require("css-to-react-native")),U=x(require("parse-css-dimension")),mt=require("css-background-parser");var It=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),lt=[1,0,0,1,0,0];function Lt(t,r){return typeof r=="number"?It.has(t)?String(r):r+"px":r}function ct(t,r){if(typeof t=="number")return t;try{let e=new U.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 D(t,r){let e=[];for(let n in t){let i=(0,v.getPropertyName)(n);e.push([i,Lt(i,t[n])])}let o=(0,v.default)(e);if(o.backgroundImage){let{backgrounds:n}=(0,mt.parseElementStyle)(o);o.backgroundImage=n}let s=o.fontSize||r.fontSize;if(typeof s=="string")try{let n=new U.default(s);switch(n.unit){case"em":s=n.value*r.fontSize;break;case"rem":s=n.value*16;break}}catch{s=16}o.fontSize=s;for(let n in o){let i=o[n];if(typeof i=="string"){let a=ct(i,s);typeof a!="undefined"&&(o[n]=a),i=o[n]}if(n==="opacity"&&(i=o[n]=i*r.opacity),n==="transform"){let a=[...lt],c=i;for(let u of c){let d=Object.keys(u)[0],g=u[d],m=typeof g=="string"?ct(g,s):g,l=[...lt];switch(d){case"translateX":l[4]=m;break;case"translateY":l[5]=m;break;case"scaleX":l[0]=m;break;case"scaleY":l[3]=m;break;case"rotate":let p=m*Math.PI/180,h=Math.cos(p),y=Math.sin(p);l[0]=h,l[1]=y,l[2]=-y,l[3]=h;break;case"skewX":l[2]=Math.tan(m*Math.PI/180);break;case"skewY":l[1]=Math.tan(m*Math.PI/180);break}a=F(l,a)}o.transform=a}}return o}function S(t,r,e){let o=r[t];return typeof o=="undefined"?e:o}function H(t,r,e,o,s){let n=N(N(N({},e),D(ut[r],e)),D(o,e));if(r==="img"){let i=parseInt(s.width),c=parseInt(s.height)/i;n.width||(n.width=i),n.height||(n.height=c*n.width)}return t.setDisplay(S(n.display,{flex:f.default.DISPLAY_FLEX,none:f.default.DISPLAY_NONE},f.default.DISPLAY_FLEX)),t.setAlignContent(S(n.alignContent,{stretch:f.default.ALIGN_STRETCH,center:f.default.ALIGN_CENTER,"flex-start":f.default.ALIGN_FLEX_START,"flex-end":f.default.ALIGN_FLEX_END,"space-between":f.default.ALIGN_SPACE_BETWEEN,"space-around":f.default.ALIGN_SPACE_AROUND,baseline:f.default.ALIGN_BASELINE,normal:f.default.ALIGN_AUTO},f.default.ALIGN_AUTO)),t.setAlignItems(S(n.alignItems,{stretch:f.default.ALIGN_STRETCH,center:f.default.ALIGN_CENTER,"flex-start":f.default.ALIGN_FLEX_START,"flex-end":f.default.ALIGN_FLEX_END,baseline:f.default.ALIGN_BASELINE,normal:f.default.ALIGN_AUTO},f.default.ALIGN_FLEX_START)),t.setAlignSelf(S(n.alignSelf,{stretch:f.default.ALIGN_STRETCH,center:f.default.ALIGN_CENTER,"flex-start":f.default.ALIGN_FLEX_START,"flex-end":f.default.ALIGN_FLEX_END,baseline:f.default.ALIGN_BASELINE,normal:f.default.ALIGN_AUTO},f.default.ALIGN_AUTO)),t.setJustifyContent(S(n.justifyContent,{center:f.default.JUSTIFY_CENTER,"flex-start":f.default.JUSTIFY_FLEX_START,"flex-end":f.default.JUSTIFY_FLEX_END,"space-between":f.default.JUSTIFY_SPACE_BETWEEN,"space-around":f.default.JUSTIFY_SPACE_AROUND},f.default.JUSTIFY_FLEX_START)),t.setFlexDirection(S(n.flexDirection,{row:f.default.FLEX_DIRECTION_ROW,column:f.default.FLEX_DIRECTION_COLUMN,"row-reverse":f.default.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":f.default.FLEX_DIRECTION_COLUMN_REVERSE},f.default.FLEX_DIRECTION_ROW)),t.setFlexWrap(S(n.flexWrap,{wrap:f.default.WRAP_WRAP,nowrap:f.default.WRAP_NO_WRAP,"wrap-reverse":f.default.WRAP_WRAP_REVERSE},f.default.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:f.default.OVERFLOW_VISIBLE,hidden:f.default.OVERFLOW_HIDDEN},f.default.OVERFLOW_VISIBLE)),t.setMargin(f.default.EDGE_TOP,n.marginTop||0),t.setMargin(f.default.EDGE_BOTTOM,n.marginBottom||0),t.setMargin(f.default.EDGE_LEFT,n.marginLeft||0),t.setMargin(f.default.EDGE_RIGHT,n.marginRight||0),t.setBorder(f.default.EDGE_TOP,n.borderWidth||0),t.setBorder(f.default.EDGE_BOTTOM,n.borderWidth||0),t.setBorder(f.default.EDGE_LEFT,n.borderWidth||0),t.setBorder(f.default.EDGE_RIGHT,n.borderWidth||0),t.setPadding(f.default.EDGE_TOP,n.paddingTop||0),t.setPadding(f.default.EDGE_BOTTOM,n.paddingBottom||0),t.setPadding(f.default.EDGE_LEFT,n.paddingLeft||0),t.setPadding(f.default.EDGE_RIGHT,n.paddingRight||0),t.setPositionType((n.position,f.default.POSITION_TYPE_ABSOLUTE,f.default.POSITION_TYPE_RELATIVE,f.default.POSITION_TYPE_RELATIVE)),typeof n.top!="undefined"&&t.setPosition(f.default.EDGE_TOP,n.top),typeof n.bottom!="undefined"&&t.setPosition(f.default.EDGE_BOTTOM,n.bottom),typeof n.left!="undefined"&&t.setPosition(f.default.EDGE_LEFT,n.left),typeof n.right!="undefined"&&t.setPosition(f.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,X(n)]}var I=x(require("yoga-layout-prebuilt")),dt=require("css-line-break");function W({left:t,top:r,width:e,height:o},s,n){let i;if(n)i=s;else{let a=t+e/2,c=r+o/2;i=F([1,0,0,1,a,c],F(s,[1,0,0,1,-a,-c])),s.__parent&&(i=F(s.__parent,i)),s.splice(0,6,...i)}return`matrix(${i.join(",")})`}function J({left:t,top:r,width:e,height:o,isInheritingTransform:s,path:n,debug:i},a){let c="",u=1,d="";return a.transform&&(c=W({left:t,top:r,width:e,height:o},a.transform,s)),a.opacity&&(u=+a.opacity),i&&(d=`<rect x="${t}" y="${r}" width="${e}" height="${o}" fill="transparent" stroke="#575eff" stroke-width="1" ${c?`transform="${c}"`:""}></rect>`),`<path fill="${a.color}" ${c?`transform="${c}"`:""} ${u!==1?`opacity="${u}"`:""} d="${n}"></path>${d}`}function*z(t,r){let{parentStyle:e,parent:o,font:s,id:n,isInheritingTransform:i,debug:a}=r,c=(0,dt.LineBreaker)(t,{lineBreak:"strict",wordBreak:"normal"}),u=[];for(let p;!(p=c.next()).done;)u.push(p.value.slice());let d=[];o.setAlignItems(I.default.ALIGN_BASELINE),e.textAlign==="left"?o.setJustifyContent(I.default.JUSTIFY_FLEX_START):e.textAlign==="center"?o.setJustifyContent(I.default.JUSTIFY_CENTER):e.textAlign==="right"?o.setJustifyContent(I.default.JUSTIFY_FLEX_END):e.textAlign==="justify"&&o.setJustifyContent(I.default.JUSTIFY_SPACE_BETWEEN);for(let p of u){let h=I.default.Node.create();o.insertChild(h,o.getChildCount());let y=s.measure(p,e),E=(e.letterSpacing||0)*p.length;h.setWidth(y.width+E),h.setHeight(y.ascent*1.2),h.setMargin(I.default.EDGE_BOTTOM,y.descent*1.2),d.push(h)}let[g,m]=yield,l="";for(let p=0;p<d.length;p++){let h=d[p],y=u[p];e.position==="absolute"&&h.calculateLayout();let{left:E,top:$,width:_,height:T}=h.getComputedLayout();E+=g,$+=m;let A=s.getSVG(y,it(N({},e),{top:$,left:E,letterSpacing:e.letterSpacing}));l+=J({id:n,left:E,top:$,width:_,height:T,isInheritingTransform:i,path:A,debug:a},e)}return l}var pt=x(require("gradient-parser"));function At(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 V({id:t,width:r},{image:e}){if(e.startsWith("linear-gradient(")){let o=pt.default.parse(e)[0],s,n,i,a;if(o.orientation.type==="directional")[s,n,i,a]={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 l=+o.orientation.value/180*Math.PI-Math.PI/2,p=Math.cos(l),h=Math.sin(l);s=0,n=0,i=p,a=h,i<0&&(s-=i,i=0),a<0&&(n-=a,a=0)}let c=r,u=[];for(let l of o.colorStops){let p=At(l);if(!u.length&&(u.push({offset:0,color:p}),typeof l.length=="undefined"||l.length.value==="0"))continue;let h=typeof l.length=="undefined"?void 0:l.length.type==="%"?l.length.value/100:l.length.value/c;u.push({offset:h,color:p})}u.length||u.push({offset:0,color:"transparent"});let d=u[u.length-1];d.offset!==1&&(typeof d.offset=="undefined"?d.offset=1:u.push({offset:1,color:d.color}));let g=0,m=1;for(let l=0;l<u.length;l++)if(typeof u[l].offset=="undefined"){for(m<l&&(m=l);typeof u[m].offset=="undefined";)m++;u[l].offset=(u[m].offset-u[g].offset)/(m-g)*(l-g)+u[g].offset}else g=l;return[`satori_bi${t}`,`<linearGradient id="satori_bi${t}" x1="${s}" y1="${n}" x2="${i}" y2="${a}">${u.map(l=>`<stop offset="${l.offset*100}%" stop-color="${l.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 w(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 k({left:t,top:r,width:e,height:o},s){let{borderTopLeftRadius:n,borderTopRightRadius:i,borderBottomLeftRadius:a,borderBottomRightRadius:c}=s;return n=Math.min(n||0,e,o),i=Math.min(i||0,e,o),a=Math.min(a||0,e,o),c=Math.min(c||0,e,o),!n&&!i&&!a&&!c?"":([n,i]=w(n,i,e),[n,a]=w(n,a,o),[i,c]=w(i,c,o),[a,c]=w(a,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+a-e} a${a},${a} 0 0 1 ${-a},${-a} v${a+n-o} a${n},${n} 0 0 1 ${n},${-n}`)}function C({id:t,width:r,height:e},o){if(!o.shadowColor||!o.shadowOffset||typeof o.shadowRadius=="undefined")return"";let s=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),a=Math.max(o.shadowOffset.height+o.shadowRadius*2+e,e);return`<defs><filter id="satori_s-${t}" x="${s/r*100}%" y="${i/e*100}%" width="${(n-s)/r*100}%" height="${(a-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 j({id:t,left:r,top:e,width:o,height:s,isInheritingTransform:n,debug:i},a){if(a.display==="none")return"";let c="rect",u="transparent",d=0,g="",m="",l=[],p=1,h="";if(a.backgroundColor&&l.push(a.backgroundColor),a.borderWidth&&(d=a.borderWidth,u=a.borderColor),a.opacity&&(p=+a.opacity),a.transform&&(g=W({left:r,top:e,width:o,height:s},a.transform,n)),a.backgroundImage){let $=a.backgroundImage.map((_,T)=>V({id:t+"_"+T,width:o,height:s},_)).filter(Boolean);for(let _ of $)m+=_[1],l.push(`url(#${_[0]})`)}let y=k({left:r,top:e,width:o,height:s},a);y&&(c="path");let E=C({width:o,height:s,id:t},a);return l.length||l.push("transparent"),i&&(h=`<rect x="${r}" y="${e}" width="${o}" height="${s}" fill="transparent" stroke="#ff5757" stroke-width="1" ${g?`transform="${g}"`:""}></rect>`),`${m?`<defs>${m}</defs>`:""}${E?`${E}<g filter="url(#satori_s-${t})">`:""}${p!==1?`<g opacity="${p}">`:""}${l.map(($,_)=>$==="transparent"&&!(_===l.length-1&&d)?"":`<${c} x="${r}" y="${e}" width="${o}" height="${s}" fill="${$}" ${_===l.length-1&&d?`stroke="${u}" stroke-width="${d}"`:""} ${y?`d="${y}"`:""} ${g?`transform="${g}"`:""}></${c}>`).join("")}${p!==1?"</g>":""}${E?"</g>":""}${h}`}function q({id:t,left:r,top:e,width:o,height:s,src:n,debug:i},a){if(a.display==="none")return"";let c="",u=1,d=a.objectFit==="contain"?"xMidYMid":a.objectFit==="cover"?"xMidYMid slice":"none",g=k({left:r,top:e,width:o,height:s},a);g&&(c=`<clipPath id="satori_c-${t}"><path x="${r}" y="${e}" width="${o}" height="${s}" d="${g}"></path></clipPath>`),a.opacity&&(u=+a.opacity);let m=C({width:o,height:s,id:t},a);return`${m}${m?`<g filter="url(#satori_s-${t})">`:""}${c}<image href="${n}" x="${r}" y="${e}" width="${o}" height="${s}" preserveAspectRatio="${d}" ${c?`clip-path="url(#satori_c-${t})"`:""} ${u!==1?`opacity="${u}"`:""}></image>${m?"</g>":""}`}function*G(t,r){let{id:e,inheritedStyle:o,parent:s,font:n,debug:i}=r;if(t===null||typeof t=="undefined")return yield,"";if(!Y(t)||typeof t.type=="function"){let R;if(!Y(t))R=z(String(t),r);else{if(ft(t.type))throw new Error("Class component is not supported.");R=G(t.type(t.props),r)}R.next();let B=yield;return R.next(B).value}let{type:a,props:c}=t,{style:u,children:d}=c,g=gt.default.Node.create();s.insertChild(g,s.getChildCount());let[m,l]=H(g,a,o,u,c),p=m.transform===o.transform;p||(m.transform.__parent=o.transform);let h=typeof d=="undefined"?[]:[].concat(d),y=[],E=0;for(let R of h){let B=G(R,{id:e*h.length+ ++E,parentStyle:m,inheritedStyle:l,isInheritingTransform:!0,parent:g,font:n,debug:i});B.next(),y.push(B)}let[$,_]=yield;m.position==="absolute"&&g.calculateLayout();let{left:T,top:A,width:tt,height:et}=g.getComputedLayout();T+=$,A+=_;let P="";a==="img"?P=q({id:e,left:T,top:A,width:tt,height:et,src:c.src,isInheritingTransform:p,debug:i},m):P=j({id:e,left:T,top:A,width:tt,height:et,isInheritingTransform:p,debug:i},m);for(let R of y)P+=R.next([T,A]).value;return P}var K=x(require("opentype.js")),M=class{constructor(r){this.fonts=new Map;for(let e of r){let o=e.data,s="buffer"in o?K.default.parse(o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)):K.default.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:r,weight:e,style:o}){if(!this.fonts.has(r))return this.defaultFont;e==="normal"&&(e=400),e==="bold"&&(e=700);let s=[...this.fonts.get(r)];return s.sort(([n,i,a],[c,u,d])=>{if(i!==u)return i?!u||i===e?-1:u===e?1:e===400&&i===500||e===500&&i===400?-1:e===400&&u===500||e===500&&u===400?1:e<400?i<e&&u<e?u-i:i<e?-1:u<e?1:i-u:e<i&&e<u?i-u:e<i?-1:e<u?1:u-i:1;if(a!==d){if(a===o)return-1;if(d===o)return 1}return-1}),s[0][0]}measure(r,{fontFamily:e,fontSize:o,fontWeight:s=400,fontStyle:n="normal"}){let i=this.get({name:e,weight:s,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:s=400,fontStyle:n="normal",top:i,left:a,letterSpacing:c=0}){let u=this.get({name:e,weight:s,style:n});return i+=u.ascender/u.unitsPerEm*o,u.getPath(r,a,i,o,{letterSpacing:c/o}).toPathData(3)}};function Q({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 Z(t,r){let e=new M(r.fonts),o=L.default.Node.create();o.setWidth(r.width),o.setHeight(r.height),o.setFlexDirection(L.default.FLEX_DIRECTION_ROW),o.setFlexWrap(L.default.WRAP_WRAP),o.setAlignContent(L.default.ALIGN_AUTO),o.setAlignItems(L.default.ALIGN_FLEX_START),o.setJustifyContent(L.default.JUSTIFY_FLEX_START);let s=G(t,{id:1,parentStyle:{},inheritedStyle:{fontSize:16,fontWeight:"normal",fontFamily:"serif",fontStyle:"normal",lineHeight:1.2,color:"black",opacity:1},parent:o,font:e,debug:r.debug});s.next(),o.calculateLayout(r.width,r.height,L.default.DIRECTION_LTR);let n=s.next([0,0]).value;return Q({width:r.width,height:r.height,content:n})}module.exports=xt(Nt);0&&(module.exports={});
|