satori 0.0.14-beta.0 → 0.0.17
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 +5 -3
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.wasm.js +1 -2
- package/dist/esm/index.wasm.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -88,6 +88,8 @@ satori(
|
|
|
88
88
|
)
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
When using `background-image`, the image will be stretched to fit the element by default if you don't specify the size.
|
|
92
|
+
|
|
91
93
|
If you want to render the generated SVG to another image format such as PNG, it would be better to use base64 encoded image data directly as `props.src` so no extra I/O is needed.
|
|
92
94
|
|
|
93
95
|
#### Emojis
|
|
@@ -140,6 +142,7 @@ The image will be resized to the current font-size (both width and height), so i
|
|
|
140
142
|
| `overflow` | `visible`, `hidden` |
|
|
141
143
|
| `color` | Supported |
|
|
142
144
|
| `transform` | Support absolute values |
|
|
145
|
+
| `transform-origin` | Support one-value and two-value syntax (both relative and absolute values) |
|
|
143
146
|
| `object-fit` | `contain`, `cover`, `none` |
|
|
144
147
|
| `opacity` | Supported |
|
|
145
148
|
| `background-color` | Supported |
|
|
@@ -147,13 +150,12 @@ The image will be resized to the current font-size (both width and height), so i
|
|
|
147
150
|
| `word-break` | Supported |
|
|
148
151
|
| `text-shadow` | Supported |
|
|
149
152
|
| `text-transform` | Support `lowercase`, `uppercase`, `capitalize` |
|
|
153
|
+
| `background-position` | Supported |
|
|
154
|
+
| `background-size` | Support two-value size string such as `10px 20%` |
|
|
150
155
|
| `background-clip` | TBD |
|
|
151
|
-
| `background-size` | TBD |
|
|
152
|
-
| `background-position` | TBD |
|
|
153
156
|
| `background-repeat` | TBD |
|
|
154
157
|
| `background-origin` | TBD |
|
|
155
158
|
| `text-decoration` | TBD |
|
|
156
|
-
| `transform-origin` | TBD |
|
|
157
159
|
| `line-height` | TBD |
|
|
158
160
|
| `white-space` | TBD |
|
|
159
161
|
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
var at=Object.defineProperty,zt=Object.defineProperties,Ut=Object.getOwnPropertyDescriptor,Xt=Object.getOwnPropertyDescriptors,Ht=Object.getOwnPropertyNames,Tt=Object.getOwnPropertySymbols;var Lt=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable;var It=(t,r,e)=>r in t?at(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,Z=(t,r)=>{for(var e in r||(r={}))Lt.call(r,e)&&It(t,e,r[e]);if(Tt)for(var e of Tt(r))Vt.call(r,e)&&It(t,e,r[e]);return t},wt=(t,r)=>zt(t,Xt(r)),Jt=t=>at(t,"__esModule",{value:!0});var At=(t,r)=>()=>(t&&(r=t(t=0)),r);var jt=(t,r)=>{for(var e in r)at(t,e,{get:r[e],enumerable:!0})},Kt=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Ht(r))!Lt.call(t,s)&&(e||s!=="default")&&at(t,s,{get:()=>r[s],enumerable:!(i=Ut(r,s))||i.enumerable});return t};var qt=(t=>(r,e)=>t&&t.get(r)||(e=Kt(Jt({}),r,1),t&&t.set(r,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var d=At(()=>{});var Ct={};jt(Ct,{default:()=>Qt});import*as Zt from"yoga-layout-prebuilt";var Qt,Ft=At(()=>{d();Qt=Zt});d();d();d();var st;{let t=(Ft(),qt(Ct));t.default?st=t.default:st=t}function te(t){st=t}function B(){return st}d();d();function ct(t){let r=typeof t;return!(r==="number"||r==="bigint"||r==="string"||r==="boolean")}function Ot(t){return/^class\s/.test(Function.prototype.toString.call(t))}function Q(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]]}function F(t,r,e){let i=r[t];return typeof i=="undefined"?e:i}d();d();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"}};d();var ee=new Set(["color","font","fontFamily","fontSize","fontStyle","fontWeight","lineHeight","textAlign","textTransform","whiteSpace","letterSpacing","transform","wordBreak","textShadowOffset","textShadowColor","textShadowRadius","opacity"]);function mt(t){let r={};for(let e in t)ee.has(e)&&(r[e]=t[e]);return r}d();import{getPropertyName as vt,getStylesForProperty as re}from"css-to-react-native";import Gt from"parse-css-dimension";import{parseElementStyle as ne}from"css-background-parser";var oe=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),kt=[1,0,0,1,0,0];function ie(t,r){return typeof r=="number"?oe.has(t)?String(r):r+"px":r}function Wt(t,r){if(typeof t=="number")return t;try{let e=new Gt(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 ft(t,r){let e=[];for(let o in t){let n=vt(o);e.push([n,ie(n,t[o])])}let i=e.reduce((o,n)=>{let a=vt(n[0]),c=n[1];return Object.assign(o,re(a,c,!0))},{});if(i.backgroundImage){let{backgrounds:o}=ne(i);i.backgroundImage=o}let s=i.fontSize||r.fontSize;if(typeof s=="string")try{let o=new Gt(s);switch(o.unit){case"em":s=o.value*r.fontSize;break;case"rem":s=o.value*16;break}}catch{s=16}typeof i.fontSize!="undefined"&&(i.fontSize=s);for(let o in i){let n=i[o];if(typeof n=="string"){let a=Wt(n,s);typeof a!="undefined"&&(i[o]=a),n=i[o]}if(o==="opacity"&&(n=i[o]=n*r.opacity),o==="transform"){let a=[...kt],c=n;for(let l of c){let p=Object.keys(l)[0],h=l[p],g=typeof h=="string"?Wt(h,s):h,f=[...kt];switch(p){case"translateX":f[4]=g;break;case"translateY":f[5]=g;break;case"scaleX":f[0]=g;break;case"scaleY":f[3]=g;break;case"rotate":let y=g*Math.PI/180,x=Math.cos(y),I=Math.sin(y);f[0]=x,f[1]=I,f[2]=-I,f[3]=x;break;case"skewX":f[2]=Math.tan(g*Math.PI/180);break;case"skewY":f[1]=Math.tan(g*Math.PI/180);break}a=Q(f,a)}i.transform=a}}return i}function dt(t,r,e,i,s){let o=B(),n=Z(Z(Z({},e),ft(Nt[r],e)),ft(i,e));if(r==="img"){let a=parseInt(s.width),l=parseInt(s.height)/a;n.width||(n.width=a),n.height||(n.height=l*n.width)}return t.setDisplay(F(n.display,{flex:o.DISPLAY_FLEX,none:o.DISPLAY_NONE},o.DISPLAY_FLEX)),t.setAlignContent(F(n.alignContent,{stretch:o.ALIGN_STRETCH,center:o.ALIGN_CENTER,"flex-start":o.ALIGN_FLEX_START,"flex-end":o.ALIGN_FLEX_END,"space-between":o.ALIGN_SPACE_BETWEEN,"space-around":o.ALIGN_SPACE_AROUND,baseline:o.ALIGN_BASELINE,normal:o.ALIGN_AUTO},o.ALIGN_AUTO)),t.setAlignItems(F(n.alignItems,{stretch:o.ALIGN_STRETCH,center:o.ALIGN_CENTER,"flex-start":o.ALIGN_FLEX_START,"flex-end":o.ALIGN_FLEX_END,baseline:o.ALIGN_BASELINE,normal:o.ALIGN_AUTO},o.ALIGN_FLEX_START)),t.setAlignSelf(F(n.alignSelf,{stretch:o.ALIGN_STRETCH,center:o.ALIGN_CENTER,"flex-start":o.ALIGN_FLEX_START,"flex-end":o.ALIGN_FLEX_END,baseline:o.ALIGN_BASELINE,normal:o.ALIGN_AUTO},o.ALIGN_AUTO)),t.setJustifyContent(F(n.justifyContent,{center:o.JUSTIFY_CENTER,"flex-start":o.JUSTIFY_FLEX_START,"flex-end":o.JUSTIFY_FLEX_END,"space-between":o.JUSTIFY_SPACE_BETWEEN,"space-around":o.JUSTIFY_SPACE_AROUND},o.JUSTIFY_FLEX_START)),t.setFlexDirection(F(n.flexDirection,{row:o.FLEX_DIRECTION_ROW,column:o.FLEX_DIRECTION_COLUMN,"row-reverse":o.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":o.FLEX_DIRECTION_COLUMN_REVERSE},o.FLEX_DIRECTION_ROW)),t.setFlexWrap(F(n.flexWrap,{wrap:o.WRAP_WRAP,nowrap:o.WRAP_NO_WRAP,"wrap-reverse":o.WRAP_WRAP_REVERSE},o.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(F(n.overflow,{visible:o.OVERFLOW_VISIBLE,hidden:o.OVERFLOW_HIDDEN},o.OVERFLOW_VISIBLE)),t.setMargin(o.EDGE_TOP,n.marginTop||0),t.setMargin(o.EDGE_BOTTOM,n.marginBottom||0),t.setMargin(o.EDGE_LEFT,n.marginLeft||0),t.setMargin(o.EDGE_RIGHT,n.marginRight||0),t.setBorder(o.EDGE_TOP,n.borderWidth||0),t.setBorder(o.EDGE_BOTTOM,n.borderWidth||0),t.setBorder(o.EDGE_LEFT,n.borderWidth||0),t.setBorder(o.EDGE_RIGHT,n.borderWidth||0),t.setPadding(o.EDGE_TOP,n.paddingTop||0),t.setPadding(o.EDGE_BOTTOM,n.paddingBottom||0),t.setPadding(o.EDGE_LEFT,n.paddingLeft||0),t.setPadding(o.EDGE_RIGHT,n.paddingRight||0),t.setPositionType(F(n.position,{absolute:o.POSITION_TYPE_ABSOLUTE,relative:o.POSITION_TYPE_RELATIVE},o.POSITION_TYPE_RELATIVE)),typeof n.top!="undefined"&&t.setPosition(o.EDGE_TOP,n.top),typeof n.bottom!="undefined"&&t.setPosition(o.EDGE_BOTTOM,n.bottom),typeof n.left!="undefined"&&t.setPosition(o.EDGE_LEFT,n.left),typeof n.right!="undefined"&&t.setPosition(o.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,mt(n)]}d();import{LineBreaker as ae}from"css-line-break";import{splitGraphemes as se}from"text-segmentation";d();d();function et({left:t,top:r,width:e,height:i},s,o){let n;if(o)n=s;else{let a=t+e/2,c=r+i/2;n=Q([1,0,0,1,a,c],Q(s,[1,0,0,1,-a,-c])),s.__parent&&(n=Q(s.__parent,n)),s.splice(0,6,...n)}return`matrix(${n.map(a=>a.toFixed(2)).join(",")})`}function Pt({left:t,top:r,width:e,height:i,isInheritingTransform:s},o){let n="",a=1,c="";return o.transform&&(n=et({left:t,top:r,width:e,height:i},o.transform,s)),o.opacity&&(a=+o.opacity),{matrix:n,opacity:a}}function gt({id:t,content:r,filter:e,left:i,top:s,width:o,height:n,matrix:a,opacity:c,path:l,image:p,debug:h},g){let f="";return h&&(f=`<rect x="${i}" y="${s}" width="${o}" height="${l===null?.5:n}" fill="transparent" stroke="#575eff" stroke-width="1" ${a?`transform="${a}"`:""}></rect>`),p?`${e?`${e}<g filter="url(#satori_s-${t})">`:""}<image href="${p}" x="${i}" y="${s}" width="${o}" height="${n}" ${a?`transform="${a}"`:""} ${c!==1?`opacity="${c}"`:""}></image>${e?"</g>":""}${f}`:l===null?`${e?`${e}<g filter="url(#satori_s-${t})">`:""}<text x="${i}" y="${s}" width="${o}" height="${n}" fill="${g.color}" font-weight="${g.fontWeight}" font-style="${g.fontStyle}" font-size="${g.fontSize}" font-family="${g.fontFamily}" ${g.letterSpacing?`letter-spacing="${g.letterSpacing}"`:""} ${a?`transform="${a}"`:""} ${c!==1?`opacity="${c}"`:""}>${r}</text>${e?"</g>":""}${f}`:`${e?`${e}<g filter="url(#satori_s-${t})">`:""}<path fill="${g.color}" ${a?`transform="${a}"`:""} ${c!==1?`opacity="${c}"`:""} d="${l}"></path>${e?"</g>":""}${f}`}d();function j({id:t,width:r,height:e},i){if(!i.shadowColor||!i.shadowOffset||typeof i.shadowRadius=="undefined")return"";let s=i.shadowRadius*i.shadowRadius/4,o=Math.min(i.shadowOffset.width-s,0),n=Math.max(i.shadowOffset.width+s+r,r),a=Math.min(i.shadowOffset.height-s,0),c=Math.max(i.shadowOffset.height+s+e,e);return`<defs><filter id="satori_s-${t}" x="${o/r*100}%" y="${a/e*100}%" width="${(n-o)/r*100}%" height="${(c-a)/e*100}%"><feDropShadow dx="${i.shadowOffset.width}" dy="${i.shadowOffset.height}" stdDeviation="${i.shadowRadius/2}" flood-color="${i.shadowColor}" flood-opacity="1"/></filter></defs>`}var rt="en",ht=typeof Intl!="undefined"&&"Segmenter"in Intl,fe=ht?new Intl.Segmenter(rt,{granularity:"word"}):null,le=ht?new Intl.Segmenter(rt,{granularity:"grapheme"}):null,ue=[32,160,4961,65792,65793,4153,4241],ce=t=>{let r=ae(t,{lineBreak:"strict",wordBreak:"normal"}),e=[],i;for(;!(i=r.next()).done;)if(i.value){let s=i.value.slice(),o=[].map.call(s,a=>a.codePointAt(0)),n="";o.forEach(a=>{ue.includes(a)?(n.length&&e.push(n),e.push(String.fromCodePoint(a)),n=""):n+=String.fromCodePoint(a)}),n.length&&e.push(n)}return e};function pt(t,r){return ht?r==="word"?[...fe.segment(t)].map(e=>e.segment):[...le.segment(t)].map(e=>e.segment):r==="word"?ce(t):se(t)}function*bt(t,r){let e=B(),{parentStyle:i,parent:s,font:o,id:n,isInheritingTransform:a,debug:c,embedFont:l,graphemeImages:p}=r;i.textTransform==="uppercase"?t=t.toLocaleUpperCase(rt):i.textTransform==="lowercase"?t=t.toLocaleLowerCase(rt):i.textTransform==="capitalize"&&(t=pt(t,"word").map(m=>pt(m,"grapheme").map((b,R)=>R===0?b.toLocaleUpperCase(rt):b).join("")).join(""));let h=F(i.wordBreak,{normal:"word","break-all":"grapheme","break-word":"grapheme","keep-all":"word"},"word"),g=pt(t,h),f=e.Node.create();f.setAlignItems(e.ALIGN_BASELINE),i.textAlign==="left"?f.setJustifyContent(e.JUSTIFY_FLEX_START):i.textAlign==="center"?f.setJustifyContent(e.JUSTIFY_CENTER):i.textAlign==="right"?f.setJustifyContent(e.JUSTIFY_FLEX_END):i.textAlign==="justify"&&f.setJustifyContent(e.JUSTIFY_SPACE_BETWEEN),s.insertChild(f,s.getChildCount());let y=o.getFont(i),x=y.ascender/y.unitsPerEm*i.fontSize,I=-(y.descender/y.unitsPerEm)*i.fontSize,L=(x+I)*1.2,{textAlign:$}=i,N=[],P=[],w=[];f.setMeasureFunc((m,b,R,K)=>{let W=[],k="",G=0,V="",T=0,J=0,q=-1;N=[],P=[0];for(let U=0;U<g.length;U++){let X=g[U];if([" ",`
|
|
2
|
-
`," ","\u3000"].includes(X))k+=X,G=o.measure(y,k,i),w[U]=null;else{let tt=p&&p[X]?i.fontSize:o.measure(y,X,i);T||(k="",G=0);let Yt=G||",.!?:-@)>]}%#".indexOf(X[0])<0,Rt=!T||!!G;Yt&&T+G+tt>m?(N.push(T),W.push(V),V=X,T=tt,P.push(1),q=-1):(V+=k+X,T+=G+tt,Rt&&P[P.length-1]++),k="",G=0,Rt&&q++,J=Math.max(J,T),w[U]={y:W.length*L,x:T-tt,width:tt,line:W.length,lineIndex:q}}}return T&&(W.push(V),N.push(T)),W.length>1&&(J=m),{width:J,height:W.length*L}});let[D,Y]=yield,H="";i.position==="absolute"&&f.calculateLayout();let{left:z,top:C,width:A,height:M}=f.getComputedLayout(),_=D+z,v=Y+C,{matrix:it,opacity:u}=Pt({left:z,top:C,width:A,height:M,isInheritingTransform:a},i);for(let m=0;m<g.length;m++){if(!w[m])continue;let b=g[m],R=null,K=null,W=w[m].y,k=w[m].x,G=w[m].width,V=L,T=A-N[w[m].line];if($==="right"||$==="end")k+=T;else if($==="center")k+=T/2;else if($==="justify"){let q=w[m].line;if(q<N.length-1){let U=P[q];k+=(U>1?T/(U-1):0)*w[m].lineIndex}}p&&p[b]?K=p[b]:l?R=o.getSVG(y,b,wt(Z({},i),{left:_+k,top:v+W,letterSpacing:i.letterSpacing})):W+=x;let J="";i.textShadowOffset&&(J=j({width:G,height:V,id:n},{shadowColor:i.textShadowColor,shadowOffset:i.textShadowOffset,shadowRadius:i.textShadowRadius})),H+=gt({content:b,filter:J,id:n,left:_+k,top:v+W,width:G,height:V,matrix:it,opacity:u,path:R,image:K,debug:c},i)}return H}d();d();d();var yt=yt||{};yt.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]+\.?))/},r="";function e(u){var m=new Error(r+": "+u);throw m.source=r,m}function i(){var u=s();return r.length>0&&e("Invalid input not EOF"),u}function s(){return $(o)}function o(){return n("linear-gradient",t.linearGradient,c)||n("repeating-linear-gradient",t.repeatingLinearGradient,c)||n("radial-gradient",t.radialGradient,h)||n("repeating-radial-gradient",t.repeatingRadialGradient,h)}function n(u,m,b){return a(m,function(R){var K=b();return K&&(v(t.comma)||e("Missing comma before color stops")),{type:u,orientation:K,colorStops:$(N)}})}function a(u,m){var b=v(u);if(b){v(t.startCall)||e("Missing (");var R=m(b);return v(t.endCall)||e("Missing )"),R}}function c(){return l()||p()}function l(){return _("directional",t.sideOrCorner,1)}function p(){return _("angular",t.angleValue,1)}function h(){var u,m=g(),b;return m&&(u=[],u.push(m),b=r,v(t.comma)&&(m=g(),m?u.push(m):r=b)),u}function g(){var u=f()||y();if(u)u.at=I();else{var m=x();if(m){u=m;var b=I();b&&(u.at=b)}else{var R=O();R&&(u={type:"default-radial",at:R})}}return u}function f(){var u=_("shape",/^(circle)/i,0);return u&&(u.style=M()||x()),u}function y(){var u=_("shape",/^(ellipse)/i,0);return u&&(u.style=C()||x()),u}function x(){return _("extent-keyword",t.extentKeywords,1)}function I(){if(_("position",/^at/,0)){var u=O();return u||e("Missing positioning value"),u}}function O(){var u=L();if(u.x||u.y)return{type:"position",value:u}}function L(){return{x:C(),y:C()}}function $(u){var m=u(),b=[];if(m)for(b.push(m);v(t.comma);)m=u(),m?b.push(m):e("One extra comma");return b}function N(){var u=P();return u||e("Expected color definition"),u.length=C(),u}function P(){return D()||H()||Y()||w()}function w(){return _("literal",t.literalColor,0)}function D(){return _("hex",t.hexColor,1)}function Y(){return a(t.rgbColor,function(){return{type:"rgb",value:$(z)}})}function H(){return a(t.rgbaColor,function(){return{type:"rgba",value:$(z)}})}function z(){return v(t.number)[1]}function C(){return _("%",t.percentageValue,1)||A()||M()}function A(){return _("position-keyword",t.positionKeywords,1)}function M(){return _("px",t.pixelValue,1)||_("em",t.emValue,1)}function _(u,m,b){var R=v(m);if(R)return{type:u,value:R[b]}}function v(u){var m,b;return b=/^[\n\r\t\s]+/.exec(r),b&&it(b[0].length),m=u.exec(r),m&&it(m[0].length),m}function it(u){r=r.substr(u)}return function(u){return r=u.toString(),i()}}();var Mt=yt;function me(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 xt({id:t,width:r},{image:e}){if(e.startsWith("linear-gradient(")){let i=Mt.parse(e)[0],s,o,n,a;if(i.orientation.type==="directional")[s,o,n,a]={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 f=+i.orientation.value/180*Math.PI-Math.PI/2,y=Math.cos(f),x=Math.sin(f);s=0,o=0,n=y,a=x,n<0&&(s-=n,n=0),a<0&&(o-=a,a=0)}let c=r,l=[];for(let f of i.colorStops){let y=me(f);if(!l.length&&(l.push({offset:0,color:y}),typeof f.length=="undefined"||f.length.value==="0"))continue;let x=typeof f.length=="undefined"?void 0:f.length.type==="%"?f.length.value/100:f.length.value/c;l.push({offset:x,color:y})}l.length||l.push({offset:0,color:"transparent"});let p=l[l.length-1];p.offset!==1&&(typeof p.offset=="undefined"?p.offset=1:l.push({offset:1,color:p.color}));let h=0,g=1;for(let f=0;f<l.length;f++)if(typeof l[f].offset=="undefined"){for(g<f&&(g=f);typeof l[g].offset=="undefined";)g++;l[f].offset=(l[g].offset-l[h].offset)/(g-h)*(f-h)+l[h].offset}else h=f;return[`satori_bi${t}`,`<linearGradient id="satori_bi${t}" x1="${s}" y1="${o}" x2="${n}" y2="${a}">${l.map(f=>`<stop offset="${f.offset*100}%" stop-color="${f.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>`]}}d();function lt(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 nt({left:t,top:r,width:e,height:i},s){let{borderTopLeftRadius:o,borderTopRightRadius:n,borderBottomLeftRadius:a,borderBottomRightRadius:c}=s;return o=Math.min(o||0,e,i),n=Math.min(n||0,e,i),a=Math.min(a||0,e,i),c=Math.min(c||0,e,i),!o&&!n&&!a&&!c?"":([o,n]=lt(o,n,e),[o,a]=lt(o,a,i),[n,c]=lt(n,c,i),[a,c]=lt(a,c,e),`M${t+o},${r} h${e-o-n} a${n},${n} 0 0 1 ${n},${n} v${i-n-c} a${c},${c} 0 0 1 ${-c},${c} h${c+a-e} a${a},${a} 0 0 1 ${-a},${-a} v${a+o-i} a${o},${o} 0 0 1 ${o},${-o}`)}function $t({id:t,left:r,top:e,width:i,height:s,isInheritingTransform:o,debug:n},a){if(a.display==="none")return"";let c="rect",l="transparent",p=0,h="",g="",f=[],y=1,x="";if(a.backgroundColor&&f.push(a.backgroundColor),a.borderWidth&&(p=a.borderWidth,l=a.borderColor),a.opacity&&(y=+a.opacity),a.transform&&(h=et({left:r,top:e,width:i,height:s},a.transform,o)),a.backgroundImage){let L=a.backgroundImage.map(($,N)=>xt({id:t+"_"+N,width:i,height:s},$)).filter(Boolean);for(let $ of L)g+=$[1],f.push(`url(#${$[0]})`)}let I=nt({left:r,top:e,width:i,height:s},a);I&&(c="path");let O=j({width:i,height:s,id:t},a);return f.length||f.push("transparent"),n&&(x=`<rect x="${r}" y="${e}" width="${i}" height="${s}" fill="transparent" stroke="#ff5757" stroke-width="1" ${h?`transform="${h}"`:""}></rect>`),`${g?`<defs>${g}</defs>`:""}${O?`${O}<g filter="url(#satori_s-${t})">`:""}${y!==1?`<g opacity="${y}">`:""}${f.map((L,$)=>L==="transparent"&&!($===f.length-1&&p)?"":`<${c} x="${r}" y="${e}" width="${i}" height="${s}" fill="${L}" ${$===f.length-1&&p?`stroke="${l}" stroke-width="${p}"`:""} ${I?`d="${I}"`:""} ${h?`transform="${h}"`:""}></${c}>`).join("")}${y!==1?"</g>":""}${O?"</g>":""}${x}`}d();function Et({id:t,left:r,top:e,width:i,height:s,src:o,debug:n},a){if(a.display==="none")return"";let c="",l=1,p=a.objectFit==="contain"?"xMidYMid":a.objectFit==="cover"?"xMidYMid slice":"none",h=nt({left:r,top:e,width:i,height:s},a);h&&(c=`<clipPath id="satori_c-${t}"><path x="${r}" y="${e}" width="${i}" height="${s}" d="${h}"></path></clipPath>`),a.opacity&&(l=+a.opacity);let g=j({width:i,height:s,id:t},a);return`${g}${g?`<g filter="url(#satori_s-${t})">`:""}${c}<image href="${o}" x="${r}" y="${e}" width="${i}" height="${s}" preserveAspectRatio="${p}" ${c?`clip-path="url(#satori_c-${t})"`:""} ${l!==1?`opacity="${l}"`:""}></image>${g?"</g>":""}`}function*ot(t,r){let e=B(),{id:i,inheritedStyle:s,parent:o,font:n,debug:a,embedFont:c=!0,graphemeImages:l}=r;if(t===null||typeof t=="undefined")return yield,"";if(!ct(t)||typeof t.type=="function"){let A;if(!ct(t))A=bt(String(t),r);else{if(Ot(t.type))throw new Error("Class component is not supported.");A=ot(t.type(t.props),r)}A.next();let M=yield;return A.next(M).value}let{type:p,props:h}=t,{style:g,children:f}=h,y=e.Node.create();o.insertChild(y,o.getChildCount());let[x,I]=dt(y,p,s,g,h),O=x.transform===s.transform;O||(x.transform.__parent=s.transform);let L=typeof f=="undefined"?[]:[].concat(f),$=[],N=0;for(let A of L){let M=ot(A,{id:i*L.length+ ++N,parentStyle:x,inheritedStyle:I,isInheritingTransform:!0,parent:y,font:n,embedFont:c,debug:a,graphemeImages:l});M.next(),$.push(M)}let[P,w]=yield;x.position==="absolute"&&y.calculateLayout();let{left:D,top:Y,width:H,height:z}=y.getComputedLayout();D+=P,Y+=w;let C="";p==="img"?C=Et({id:i,left:D,top:Y,width:H,height:z,src:h.src,isInheritingTransform:O,debug:a},x):C=$t({id:i,left:D,top:Y,width:H,height:z,isInheritingTransform:O,debug:a},x);for(let A of $)C+=A.next([D,Y]).value;return C}d();import Bt from"opentype.js";var ut=class{constructor(r){this.fonts=new Map;for(let e of r){let i=e.data,s="buffer"in i?Bt.parse(i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)):Bt.parse(i);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:i}){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(([o,n,a],[c,l,p])=>{if(n!==l)return n?!l||n===e?-1:l===e?1:e===400&&n===500||e===500&&n===400?-1:e===400&&l===500||e===500&&l===400?1:e<400?n<e&&l<e?l-n:n<e?-1:l<e?1:n-l:e<n&&e<l?n-l:e<n?-1:e<l?1:l-n:1;if(a!==p){if(a===i)return-1;if(p===i)return 1}return-1}),s[0][0]}getFont({fontFamily:r,fontWeight:e=400,fontStyle:i="normal"}){return this.get({name:r,weight:e,style:i})}measure(r,e,{fontSize:i,letterSpacing:s=0}){return r.getAdvanceWidth(e,i,{letterSpacing:s/i})}getSVG(r,e,{fontSize:i,top:s,left:o,letterSpacing:n=0}){return s+=r.ascender/r.unitsPerEm*i,r.getPath(e,o,s,i,{letterSpacing:n/i}).toPathData(2)}};d();function St({width:t,height:r,content:e},i){return`<svg width="${t}" height="${r}" viewBox="0 0 ${t} ${r}" xmlns="http://www.w3.org/2000/svg">${e}</svg>`}var _t=new WeakMap;function Dt(t,r){let e=B();if(!e)throw new Error("Satori is not initialized.");let i;_t.has(r.fonts)?i=_t.get(r.fonts):_t.set(r.fonts,i=new ut(r.fonts));let s=e.Node.create();s.setWidth(r.width),s.setHeight(r.height),s.setFlexDirection(e.FLEX_DIRECTION_ROW),s.setFlexWrap(e.WRAP_WRAP),s.setAlignContent(e.ALIGN_AUTO),s.setAlignItems(e.ALIGN_FLEX_START),s.setJustifyContent(e.JUSTIFY_FLEX_START);let o=ot(t,{id:1,parentStyle:{},inheritedStyle:{fontSize:16,fontWeight:"normal",fontFamily:"serif",fontStyle:"normal",lineHeight:1.2,color:"black",opacity:1},parent:s,font:i,embedFont:r.embedFont,debug:r.debug,graphemeImages:r.graphemeImages});o.next(),s.calculateLayout(r.width,r.height,e.DIRECTION_LTR);let n=o.next([0,0]).value;return St({width:r.width,height:r.height,content:n})}export{Dt as default,te as init};
|
|
1
|
+
var ie=Object.defineProperty,je=Object.defineProperties,Ke=Object.getOwnPropertyDescriptor,qe=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertyNames,ve=Object.getOwnPropertySymbols;var Fe=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable;var Ce=(e,r,t)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,H=(e,r)=>{for(var t in r||(r={}))Fe.call(r,t)&&Ce(e,t,r[t]);if(ve)for(var t of ve(r))Qe.call(r,t)&&Ce(e,t,r[t]);return e},Oe=(e,r)=>je(e,qe(r)),et=e=>ie(e,"__esModule",{value:!0});var Ne=(e,r)=>()=>(e&&(r=e(e=0)),r);var tt=(e,r)=>{for(var t in r)ie(e,t,{get:r[t],enumerable:!0})},rt=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Ze(r))!Fe.call(e,s)&&(t||s!=="default")&&ie(e,s,{get:()=>r[s],enumerable:!(i=Ke(r,s))||i.enumerable});return e};var nt=(e=>(r,t)=>e&&e.get(r)||(t=rt(et({}),r,1),e&&e.set(r,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var u=Ne(()=>{});var ke={};tt(ke,{default:()=>it});import*as ot from"yoga-layout-prebuilt";var it,We=Ne(()=>{u();it=ot});u();u();u();var ae;{let e=(We(),nt(ke));e.default?ae=e.default:ae=e}function at(e){ae=e}function V(){return ae}u();u();import{LineBreaker as st}from"css-line-break";import{splitGraphemes as ft}from"text-segmentation";function me(e){let r=typeof e;return!(r==="number"||r==="bigint"||r==="string"||r==="boolean")}function Pe(e){return/^class\s/.test(Function.prototype.toString.call(e))}function ee(e,r){return[e[0]*r[0]+e[2]*r[1],e[1]*r[0]+e[3]*r[1],e[0]*r[2]+e[2]*r[3],e[1]*r[2]+e[3]*r[3],e[0]*r[4]+e[2]*r[5]+e[4],e[1]*r[4]+e[3]*r[5]+e[5]]}function k(e,r,t){let i=r[e];return typeof i=="undefined"?t:i}var Ge=void 0,de=typeof Intl!="undefined"&&"Segmenter"in Intl,lt=de?new Intl.Segmenter(Ge,{granularity:"word"}):null,ut=de?new Intl.Segmenter(Ge,{granularity:"grapheme"}):null,pe=[32,160,4961,65792,65793,4153,4241].map(e=>String.fromCodePoint(e)),ct=e=>{let r=st(e,{lineBreak:"strict",wordBreak:"normal"}),t=[],i;for(;!(i=r.next()).done;)if(i.value){let s=i.value.slice(),o="";for(let n=0;n<s.length;n++){let a=s[n];pe.includes(a)?(o.length&&t.push(o),t.push(a),o=""):o+=a}o.length&&t.push(o)}return t};function se(e,r){return de?r==="word"?[...lt.segment(e)].map(t=>t.segment):[...ut.segment(e)].map(t=>t.segment):r==="word"?ct(e):ft(e)}u();u();var De={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"}};u();var mt=new Set(["color","font","fontFamily","fontSize","fontStyle","fontWeight","lineHeight","textAlign","textTransform","whiteSpace","letterSpacing","transform","wordBreak","textShadowOffset","textShadowColor","textShadowRadius","opacity"]);function ge(e){let r={};for(let t in e)mt.has(t)&&(r[t]=e[t]);return r}u();import{getPropertyName as Me,getStylesForProperty as ht}from"css-to-react-native";import Ue from"parse-css-dimension";import{parseElementStyle as bt}from"css-background-parser";u();import dt from"postcss-value-parser";import pt from"parse-css-dimension";function gt(e,r){try{let t=new pt(e);switch(t.unit){case"px":return{absolute:t.value};case"em":return{absolute:t.value*r};case"rem":return{absolute:t.value*16};case"%":return{relative:t.value};default:return{}}}catch{return{}}}function he(e,r,t){switch(e){case"top":return{yRelative:0};case"left":return{xRelative:0};case"right":return{xRelative:100};case"bottom":return{yRelative:100};case"center":return{};default:let i=gt(e,r);return i.absolute?{[t?"xAbsolute":"yAbsolute"]:i.absolute}:i.relative?{[t?"xRelative":"yRelative"]:i.relative}:{}}}function be(e,r){if(typeof e=="number")return{xAbsolute:e};let t;try{t=dt(e).nodes.filter(i=>i.type==="word").map(i=>i.value)}catch{return{}}return t.length===1?he(t[0],r,!0):t.length===2?((t[0]==="top"||t[0]==="bottom"||t[1]==="left"||t[1]==="right")&&t.reverse(),H(H({},he(t[0],r,!0)),he(t[1],r,!1))):{}}var yt=new Set(["flex","flexGrow","flexShrink","flexBasis","fontWeight","lineHeight","opacity","scale","scaleX","scaleY"]),Be=[1,0,0,1,0,0];function xt(e,r){return typeof r=="number"?yt.has(e)?String(r):r+"px":r}function Ye(e,r){if(typeof e=="number")return e;try{let t=new Ue(e);if(t.type==="length")switch(t.unit){case"em":return t.value*r;case"rem":return t.value*16;default:return t.value}else if(t.type==="angle")switch(t.unit){case"deg":return t.value;case"rad":return t.value*180/Math.PI;default:return t.value}}catch{}}function fe(e,r){let t=[];for(let o in e){let n=Me(o);t.push([n,xt(n,e[o])])}let i=t.reduce((o,n)=>{let a=Me(n[0]),f=n[1];return Object.assign(o,ht(a,f,!0))},{});if(i.backgroundImage){let{backgrounds:o}=bt(i);i.backgroundImage=o}let s=i.fontSize||r.fontSize;if(typeof s=="string")try{let o=new Ue(s);switch(o.unit){case"em":s=o.value*r.fontSize;break;case"rem":s=o.value*16;break}}catch{s=16}typeof i.fontSize!="undefined"&&(i.fontSize=s),i.transformOrigin&&(i.transformOrigin=be(i.transformOrigin,s));for(let o in i){let n=i[o];if(typeof n=="string"){let a=Ye(n,s);typeof a!="undefined"&&(i[o]=a),n=i[o]}if(o==="opacity"&&(n=i[o]=n*r.opacity),o==="transform"){let a=[...Be],f=n;for(let c of f){let b=Object.keys(c)[0],p=c[b],d=typeof p=="string"?Ye(p,s):p,g=[...Be];switch(b){case"translateX":g[4]=d;break;case"translateY":g[5]=d;break;case"scaleX":g[0]=d;break;case"scaleY":g[3]=d;break;case"rotate":let m=d*Math.PI/180,x=Math.cos(m),I=Math.sin(m);g[0]=x,g[1]=I,g[2]=-I,g[3]=x;break;case"skewX":g[2]=Math.tan(d*Math.PI/180);break;case"skewY":g[1]=Math.tan(d*Math.PI/180);break}a=ee(g,a)}i.transform=a}}return i}function ye(e,r,t,i,s){let o=V(),n=H(H(H({},t),fe(De[r],t)),fe(i,t));if(r==="img"){let a=parseInt(s.width),c=parseInt(s.height)/a;n.width||(n.width=a),n.height||(n.height=c*n.width)}return e.setDisplay(k(n.display,{flex:o.DISPLAY_FLEX,none:o.DISPLAY_NONE},o.DISPLAY_FLEX)),e.setAlignContent(k(n.alignContent,{stretch:o.ALIGN_STRETCH,center:o.ALIGN_CENTER,"flex-start":o.ALIGN_FLEX_START,"flex-end":o.ALIGN_FLEX_END,"space-between":o.ALIGN_SPACE_BETWEEN,"space-around":o.ALIGN_SPACE_AROUND,baseline:o.ALIGN_BASELINE,normal:o.ALIGN_AUTO},o.ALIGN_AUTO)),e.setAlignItems(k(n.alignItems,{stretch:o.ALIGN_STRETCH,center:o.ALIGN_CENTER,"flex-start":o.ALIGN_FLEX_START,"flex-end":o.ALIGN_FLEX_END,baseline:o.ALIGN_BASELINE,normal:o.ALIGN_AUTO},o.ALIGN_FLEX_START)),e.setAlignSelf(k(n.alignSelf,{stretch:o.ALIGN_STRETCH,center:o.ALIGN_CENTER,"flex-start":o.ALIGN_FLEX_START,"flex-end":o.ALIGN_FLEX_END,baseline:o.ALIGN_BASELINE,normal:o.ALIGN_AUTO},o.ALIGN_AUTO)),e.setJustifyContent(k(n.justifyContent,{center:o.JUSTIFY_CENTER,"flex-start":o.JUSTIFY_FLEX_START,"flex-end":o.JUSTIFY_FLEX_END,"space-between":o.JUSTIFY_SPACE_BETWEEN,"space-around":o.JUSTIFY_SPACE_AROUND},o.JUSTIFY_FLEX_START)),e.setFlexDirection(k(n.flexDirection,{row:o.FLEX_DIRECTION_ROW,column:o.FLEX_DIRECTION_COLUMN,"row-reverse":o.FLEX_DIRECTION_ROW_REVERSE,"column-reverse":o.FLEX_DIRECTION_COLUMN_REVERSE},o.FLEX_DIRECTION_ROW)),e.setFlexWrap(k(n.flexWrap,{wrap:o.WRAP_WRAP,nowrap:o.WRAP_NO_WRAP,"wrap-reverse":o.WRAP_WRAP_REVERSE},o.WRAP_WRAP)),typeof n.flexBasis!="undefined"&&e.setFlexBasis(n.flexBasis),e.setFlexGrow(typeof n.flexGrow=="undefined"?0:n.flexGrow),e.setFlexShrink(typeof n.flexShrink=="undefined"?1:n.flexShrink),typeof n.maxHeight!="undefined"&&e.setMaxHeight(n.maxHeight),typeof n.maxWidth!="undefined"&&e.setMaxWidth(n.maxWidth),typeof n.minHeight!="undefined"&&e.setMinHeight(n.minHeight),typeof n.minWidth!="undefined"&&e.setMinWidth(n.minWidth),e.setOverflow(k(n.overflow,{visible:o.OVERFLOW_VISIBLE,hidden:o.OVERFLOW_HIDDEN},o.OVERFLOW_VISIBLE)),e.setMargin(o.EDGE_TOP,n.marginTop||0),e.setMargin(o.EDGE_BOTTOM,n.marginBottom||0),e.setMargin(o.EDGE_LEFT,n.marginLeft||0),e.setMargin(o.EDGE_RIGHT,n.marginRight||0),e.setBorder(o.EDGE_TOP,n.borderWidth||0),e.setBorder(o.EDGE_BOTTOM,n.borderWidth||0),e.setBorder(o.EDGE_LEFT,n.borderWidth||0),e.setBorder(o.EDGE_RIGHT,n.borderWidth||0),e.setPadding(o.EDGE_TOP,n.paddingTop||0),e.setPadding(o.EDGE_BOTTOM,n.paddingBottom||0),e.setPadding(o.EDGE_LEFT,n.paddingLeft||0),e.setPadding(o.EDGE_RIGHT,n.paddingRight||0),e.setPositionType(k(n.position,{absolute:o.POSITION_TYPE_ABSOLUTE,relative:o.POSITION_TYPE_RELATIVE},o.POSITION_TYPE_RELATIVE)),typeof n.top!="undefined"&&e.setPosition(o.EDGE_TOP,n.top),typeof n.bottom!="undefined"&&e.setPosition(o.EDGE_BOTTOM,n.bottom),typeof n.left!="undefined"&&e.setPosition(o.EDGE_LEFT,n.left),typeof n.right!="undefined"&&e.setPosition(o.EDGE_RIGHT,n.right),typeof n.height!="undefined"?e.setHeight(n.height):e.setHeightAuto(),typeof n.width!="undefined"?e.setWidth(n.width):e.setWidthAuto(),[n,ge(n)]}u();u();u();function re({left:e,top:r,width:t,height:i},s,o,n){var f,c,b,p;let a;if(o)a=s;else{let d=(c=n==null?void 0:n.xAbsolute)!=null?c:((f=n==null?void 0:n.xRelative)!=null?f:50)*t/100,g=(p=n==null?void 0:n.yAbsolute)!=null?p:((b=n==null?void 0:n.yRelative)!=null?b:50)*i/100,m=e+d,x=r+g;a=ee([1,0,0,1,m,x],ee(s,[1,0,0,1,-m,-x])),s.__parent&&(a=ee(s.__parent,a)),s.splice(0,6,...a)}return`matrix(${a.map(d=>d.toFixed(2)).join(",")})`}function Xe({left:e,top:r,width:t,height:i,isInheritingTransform:s},o){let n="",a=1;return o.transform&&(n=re({left:e,top:r,width:t,height:i},o.transform,s,o.transformOrigin)),o.opacity&&(a=+o.opacity),{matrix:n,opacity:a}}function xe({id:e,content:r,filter:t,left:i,top:s,width:o,height:n,matrix:a,opacity:f,image:c,debug:b},p){let d="";return b&&(d=`<rect x="${i}" y="${s}" width="${o}" height="0.5" fill="transparent" stroke="#575eff" stroke-width="1" ${a?`transform="${a}"`:""}></rect>`),c?`${t?`${t}<g filter="url(#satori_s-${e})">`:""}<image href="${c}" x="${i}" y="${s}" width="${o}" height="${n}" ${a?`transform="${a}"`:""} ${f!==1?`opacity="${f}"`:""}></image>${t?"</g>":""}${d}`:`${t?`${t}<g filter="url(#satori_s-${e})">`:""}<text x="${i}" y="${s}" width="${o}" height="${n}" fill="${p.color}" font-weight="${p.fontWeight}" font-style="${p.fontStyle}" font-size="${p.fontSize}" font-family="${p.fontFamily}" ${p.letterSpacing?`letter-spacing="${p.letterSpacing}"`:""} ${a?`transform="${a}"`:""} ${f!==1?`opacity="${f}"`:""}>${r}</text>${t?"</g>":""}${d}`}u();function Z({id:e,width:r,height:t},i){if(!i.shadowColor||!i.shadowOffset||typeof i.shadowRadius=="undefined")return"";let s=i.shadowRadius*i.shadowRadius/4,o=Math.min(i.shadowOffset.width-s,0),n=Math.max(i.shadowOffset.width+s+r,r),a=Math.min(i.shadowOffset.height-s,0),f=Math.max(i.shadowOffset.height+s+t,t);return`<defs><filter id="satori_s-${e}" x="${o/r*100}%" y="${a/t*100}%" width="${(n-o)/r*100}%" height="${(f-a)/t*100}%"><feDropShadow dx="${i.shadowOffset.width}" dy="${i.shadowOffset.height}" stdDeviation="${i.shadowRadius/2}" flood-color="${i.shadowColor}" flood-opacity="1"/></filter></defs>`}var $e=void 0;function*Ee(e,r){let t=V(),{parentStyle:i,parent:s,font:o,id:n,isInheritingTransform:a,debug:f,embedFont:c,graphemeImages:b}=r;i.textTransform==="uppercase"?e=e.toLocaleUpperCase($e):i.textTransform==="lowercase"?e=e.toLocaleLowerCase($e):i.textTransform==="capitalize"&&(e=se(e,"word").map(S=>se(S,"grapheme").map((L,M)=>M===0?L.toLocaleUpperCase($e):L).join("")).join(""));let p=k(i.wordBreak,{normal:"word","break-all":"grapheme","break-word":"grapheme","keep-all":"word"},"word"),d=se(e,p),g=t.Node.create();g.setAlignItems(t.ALIGN_BASELINE),i.textAlign==="left"?g.setJustifyContent(t.JUSTIFY_FLEX_START):i.textAlign==="center"?g.setJustifyContent(t.JUSTIFY_CENTER):i.textAlign==="right"?g.setJustifyContent(t.JUSTIFY_FLEX_END):i.textAlign==="justify"&&g.setJustifyContent(t.JUSTIFY_SPACE_BETWEEN),s.insertChild(g,s.getChildCount());let m=o.getFont(i),x=m.ascender/m.unitsPerEm*i.fontSize,I=-(m.descender/m.unitsPerEm)*i.fontSize,_=x+I,h=_*1.2,E=(i.fontSize-_)/2,{textAlign:v}=i,P=[],U=[],w=[],G=new Map,K=S=>{if(G.has(S))return G.get(S);let L=o.measure(m,S,i);return G.set(S,L),L};g.setMeasureFunc(S=>{let L=0,M="",B=0,F=0,Y=0,te=-1;P=[],U=[0];for(let X=0;X<d.length;X++){let z=d[X];if(pe.includes(z))M+=z,B=K(M),w[X]=null;else{let j=b&&b[z]?i.fontSize:K(z);F||(M="",B=0);let we=B||",.!?:-@)>]}%#".indexOf(z[0])<0,Ae=!F||!!B;we&&F+B+j>S?(P.push(F),L++,F=j,U.push(1),te=-1):(F+=B+j,Ae&&U[U.length-1]++),M="",B=0,Ae&&te++,Y=Math.max(Y,F),w[X]={y:L*h-E,x:F-j,width:j,line:L,lineIndex:te}}}return F&&(L++,P.push(F)),L>1&&(Y=S),{width:Y,height:L*h}});let[q,W]=yield,C="",{left:D,top:A,width:O,height:Q}=g.getComputedLayout(),l=q+D,y=W+A,{matrix:$,opacity:N}=Xe({left:D,top:A,width:O,height:Q,isInheritingTransform:a},i),J="";i.textShadowOffset&&(J=Z({width:O,height:Q,id:n},{shadowColor:i.textShadowColor,shadowOffset:i.textShadowOffset,shadowRadius:i.textShadowRadius}));let ce="";for(let S=0;S<d.length;S++){if(!w[S])continue;let L=d[S],M=null,B=null,F=w[S].y,Y=w[S].x,te=w[S].width,X=w[S].line;if(P.length>1){let z=O-P[X];if(v==="right"||v==="end")Y+=z;else if(v==="center")Y+=z/2;else if(v==="justify"&&X<P.length-1){let j=U[X];Y+=(j>1?z/(j-1):0)*w[S].lineIndex}}b&&b[L]?B=b[L]:c?M=o.getSVG(m,L,Oe(H({},i),{left:l+Y,top:y+F+x,letterSpacing:i.letterSpacing})):F+=x,M?ce+=M+" ":C+=xe({content:L,filter:J,id:n,left:l+Y,top:y+F,width:te,height:h,matrix:$,opacity:N,image:B,debug:f},i)}if(ce){let S="";f&&(S=`<rect x="${l}" y="${y}" width="${O}" height="${Q}" fill="transparent" stroke="#575eff" stroke-width="1" ${$?`transform="${$}"`:""}></rect>`),C+=`${J?`${J}<g filter="url(#satori_s-${n})">`:""}<path fill="${i.color}" ${$?`transform="${$}"`:""} ${N!==1?`opacity="${N}"`:""} d="${ce}"></path>${J?"</g>":""}${S}`}return C}u();u();import $t from"parse-css-dimension";u();var Se=Se||{};Se.parse=function(){var e={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]+\.?))/},r="";function t(l){var y=new Error(r+": "+l);throw y.source=r,y}function i(){var l=s();return r.length>0&&t("Invalid input not EOF"),l}function s(){return E(o)}function o(){return n("linear-gradient",e.linearGradient,f)||n("repeating-linear-gradient",e.repeatingLinearGradient,f)||n("radial-gradient",e.radialGradient,p)||n("repeating-radial-gradient",e.repeatingRadialGradient,p)}function n(l,y,$){return a(y,function(N){var J=$();return J&&(O(e.comma)||t("Missing comma before color stops")),{type:l,orientation:J,colorStops:E(v)}})}function a(l,y){var $=O(l);if($){O(e.startCall)||t("Missing (");var N=y($);return O(e.endCall)||t("Missing )"),N}}function f(){return c()||b()}function c(){return A("directional",e.sideOrCorner,1)}function b(){return A("angular",e.angleValue,1)}function p(){var l,y=d(),$;return y&&(l=[],l.push(y),$=r,O(e.comma)&&(y=d(),y?l.push(y):r=$)),l}function d(){var l=g()||m();if(l)l.at=I();else{var y=x();if(y){l=y;var $=I();$&&(l.at=$)}else{var N=_();N&&(l={type:"default-radial",at:N})}}return l}function g(){var l=A("shape",/^(circle)/i,0);return l&&(l.style=D()||x()),l}function m(){var l=A("shape",/^(ellipse)/i,0);return l&&(l.style=W()||x()),l}function x(){return A("extent-keyword",e.extentKeywords,1)}function I(){if(A("position",/^at/,0)){var l=_();return l||t("Missing positioning value"),l}}function _(){var l=h();if(l.x||l.y)return{type:"position",value:l}}function h(){return{x:W(),y:W()}}function E(l){var y=l(),$=[];if(y)for($.push(y);O(e.comma);)y=l(),y?$.push(y):t("One extra comma");return $}function v(){var l=P();return l||t("Expected color definition"),l.length=W(),l}function P(){return w()||K()||G()||U()}function U(){return A("literal",e.literalColor,0)}function w(){return A("hex",e.hexColor,1)}function G(){return a(e.rgbColor,function(){return{type:"rgb",value:E(q)}})}function K(){return a(e.rgbaColor,function(){return{type:"rgba",value:E(q)}})}function q(){return O(e.number)[1]}function W(){return A("%",e.percentageValue,1)||C()||D()}function C(){return A("position-keyword",e.positionKeywords,1)}function D(){return A("px",e.pixelValue,1)||A("em",e.emValue,1)}function A(l,y,$){var N=O(y);if(N)return{type:l,value:N[$]}}function O(l){var y,$;return $=/^[\n\r\t\s]+/.exec(r),$&&Q($[0].length),y=l.exec(r),y&&Q(y[0].length),y}function Q(l){r=r.substr(l)}return function(l){return r=l.toString(),i()}}();var ze=Se;function Et(e){return e.type==="literal"?e.value:e.type==="hex"?`#${e.value}`:e.type==="rgb"?`rgb(${e.value.join(",")})`:e.type==="rgba"?`rgba(${e.value.join(",")})`:"transparent"}function St(e,r){return typeof e=="string"&&e.endsWith("%")?r*parseFloat(e)/100:+e}function He(e,{x:r,y:t,defaultX:i,defaultY:s}){return(e?e.split(" ").map(o=>{try{let n=new $t(o);return n.type==="length"||n.type==="number"?n.value:n.value+n.unit}catch{return null}}).filter(o=>o!==null):[i,s]).map((o,n)=>St(o,[r,t][n]))}function Re({id:e,width:r,height:t},{image:i,size:s,position:o}){let n=He(s,{x:r,y:t,defaultX:r,defaultY:t}),a=He(o,{x:r,y:t,defaultX:0,defaultY:0});if(i.startsWith("linear-gradient(")){let f=ze.parse(i)[0],c,b,p,d;if(f.orientation.type==="directional")[c,b,p,d]={top:[0,1,0,0],bottom:[0,0,0,1],left:[1,0,0,0],right:[0,0,1,0]}[f.orientation.value];else if(f.orientation.type==="angular"){let h=+f.orientation.value/180*Math.PI-Math.PI/2,E=Math.cos(h),v=Math.sin(h);c=0,b=0,p=E,d=v,p<0&&(c-=p,p=0),d<0&&(b-=d,d=0)}let g=r,m=[];for(let h of f.colorStops){let E=Et(h);if(!m.length&&(m.push({offset:0,color:E}),typeof h.length=="undefined"||h.length.value==="0"))continue;let v=typeof h.length=="undefined"?void 0:h.length.type==="%"?h.length.value/100:h.length.value/g;m.push({offset:v,color:E})}m.length||m.push({offset:0,color:"transparent"});let x=m[m.length-1];x.offset!==1&&(typeof x.offset=="undefined"?x.offset=1:m.push({offset:1,color:x.color}));let I=0,_=1;for(let h=0;h<m.length;h++)if(typeof m[h].offset=="undefined"){for(_<h&&(_=h);typeof m[_].offset=="undefined";)_++;m[h].offset=(m[_].offset-m[I].offset)/(_-I)*(h-I)+m[I].offset}else I=h;return[`satori_bi${e}`,`<linearGradient id="satori_bi${e}" x1="${c}" y1="${b}" x2="${p}" y2="${d}">${m.map(h=>`<stop offset="${h.offset*100}%" stop-color="${h.color}"/>`).join("")}</linearGradient>`]}if(i.startsWith("url(")){let f=i.slice(4,-1);return[`satori_bi${e}`,`<pattern id="satori_bi${e}" patternContentUnits="userSpaceOnUse" patternUnits="userSpaceOnUse" x="${a[0]}" y="${a[1]}" width="${n[0]}" height="${n[1]}"><image href="${f}" x="0" y="0" width="${n[0]}" height="${n[1]}"/></pattern>`]}}u();function le(e,r,t){return t<e+r&&(t/2<e&&t/2<r?e=r=t/2:t/2<e?e=t-r:t/2<r&&(r=t-e)),[e,r]}function ne({left:e,top:r,width:t,height:i},s){let{borderTopLeftRadius:o,borderTopRightRadius:n,borderBottomLeftRadius:a,borderBottomRightRadius:f}=s;return o=Math.min(o||0,t,i),n=Math.min(n||0,t,i),a=Math.min(a||0,t,i),f=Math.min(f||0,t,i),!o&&!n&&!a&&!f?"":([o,n]=le(o,n,t),[o,a]=le(o,a,i),[n,f]=le(n,f,i),[a,f]=le(a,f,t),`M${e+o},${r} h${t-o-n} a${n},${n} 0 0 1 ${n},${n} v${i-n-f} a${f},${f} 0 0 1 ${-f},${f} h${f+a-t} a${a},${a} 0 0 1 ${-a},${-a} v${a+o-i} a${o},${o} 0 0 1 ${o},${-o}`)}function Te({id:e,left:r,top:t,width:i,height:s,isInheritingTransform:o,debug:n},a){if(a.display==="none")return"";let f="rect",c="transparent",b=0,p="",d="",g=[],m=1,x="";if(a.backgroundColor&&g.push(a.backgroundColor),a.borderWidth&&(b=a.borderWidth,c=a.borderColor),a.opacity&&(m=+a.opacity),a.transform&&(p=re({left:r,top:t,width:i,height:s},a.transform,o,a.transformOrigin)),a.backgroundImage){let h=a.backgroundImage.map((E,v)=>Re({id:e+"_"+v,width:i,height:s},E)).filter(Boolean);for(let E of h)d+=E[1],g.push(`url(#${E[0]})`)}let I=ne({left:r,top:t,width:i,height:s},a);I&&(f="path");let _=Z({width:i,height:s,id:e},a);return g.length||g.push("transparent"),n&&(x=`<rect x="${r}" y="${t}" width="${i}" height="${s}" fill="transparent" stroke="#ff5757" stroke-width="1" ${p?`transform="${p}"`:""}></rect>`),`${d?`<defs>${d}</defs>`:""}${_?`${_}<g filter="url(#satori_s-${e})">`:""}${m!==1?`<g opacity="${m}">`:""}${g.map((h,E)=>h==="transparent"&&!(E===g.length-1&&b)?"":`<${f} x="${r}" y="${t}" width="${i}" height="${s}" fill="${h}" ${E===g.length-1&&b?`stroke="${c}" stroke-width="${b}"`:""} ${I?`d="${I}"`:""} ${p?`transform="${p}"`:""}></${f}>`).join("")}${m!==1?"</g>":""}${_?"</g>":""}${x}`}u();function _e({id:e,left:r,top:t,width:i,height:s,src:o,debug:n},a){if(a.display==="none")return"";let f="",c=1,b=a.objectFit==="contain"?"xMidYMid":a.objectFit==="cover"?"xMidYMid slice":"none",p=ne({left:r,top:t,width:i,height:s},a);p&&(f=`<clipPath id="satori_c-${e}"><path x="${r}" y="${t}" width="${i}" height="${s}" d="${p}"></path></clipPath>`),a.opacity&&(c=+a.opacity);let d=Z({width:i,height:s,id:e},a);return`${d}${d?`<g filter="url(#satori_s-${e})">`:""}${f}<image href="${o}" x="${r}" y="${t}" width="${i}" height="${s}" preserveAspectRatio="${b}" ${f?`clip-path="url(#satori_c-${e})"`:""} ${c!==1?`opacity="${c}"`:""}></image>${d?"</g>":""}`}function*oe(e,r){let t=V(),{id:i,inheritedStyle:s,parent:o,font:n,debug:a,embedFont:f=!0,graphemeImages:c}=r;if(e===null||typeof e=="undefined")return yield,"";if(!me(e)||typeof e.type=="function"){let C;if(!me(e))C=Ee(String(e),r);else{if(Pe(e.type))throw new Error("Class component is not supported.");C=oe(e.type(e.props),r)}C.next();let D=yield;return C.next(D).value}let{type:b,props:p}=e,{style:d,children:g}=p,m=t.Node.create();o.insertChild(m,o.getChildCount());let[x,I]=ye(m,b,s,d,p),_=x.transform===s.transform;_||(x.transform.__parent=s.transform);let h=typeof g=="undefined"?[]:[].concat(g),E=[],v=0;for(let C of h){let D=oe(C,{id:i*h.length+ ++v,parentStyle:x,inheritedStyle:I,isInheritingTransform:!0,parent:m,font:n,embedFont:f,debug:a,graphemeImages:c});D.next(),E.push(D)}let[P,U]=yield;x.position==="absolute"&&m.calculateLayout();let{left:w,top:G,width:K,height:q}=m.getComputedLayout();w+=P,G+=U;let W="";b==="img"?W=_e({id:i,left:w,top:G,width:K,height:q,src:p.src,isInheritingTransform:_,debug:a},x):W=Te({id:i,left:w,top:G,width:K,height:q,isInheritingTransform:_,debug:a},x);for(let C of E)W+=C.next([w,G]).value;return W}u();import Ve from"@shuding/opentype.js";var ue=class{constructor(r){this.fonts=new Map;for(let t of r){let i=t.data,s="buffer"in i?Ve.parse(i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength)):Ve.parse(i);this.defaultFont||(this.defaultFont=s),this.fonts.has(t.name)||this.fonts.set(t.name,[]),this.fonts.get(t.name).push([s,t.weight,t.style])}}get({name:r,weight:t,style:i}){if(!this.fonts.has(r))return this.defaultFont;t==="normal"&&(t=400),t==="bold"&&(t=700);let s=[...this.fonts.get(r)];return s.sort(([o,n,a],[f,c,b])=>{if(n!==c)return n?!c||n===t?-1:c===t?1:t===400&&n===500||t===500&&n===400?-1:t===400&&c===500||t===500&&c===400?1:t<400?n<t&&c<t?c-n:n<t?-1:c<t?1:n-c:t<n&&t<c?n-c:t<n?-1:t<c?1:c-n:1;if(a!==b){if(a===i)return-1;if(b===i)return 1}return-1}),s[0][0]}getFont({fontFamily:r,fontWeight:t=400,fontStyle:i="normal"}){return this.get({name:r,weight:t,style:i})}measure(r,t,{fontSize:i,letterSpacing:s=0}){return r.getAdvanceWidth(t,i,{letterSpacing:s/i})}getSVG(r,t,{fontSize:i,top:s,left:o,letterSpacing:n=0}){return r.getPath(t,o,s,i,{letterSpacing:n/i}).toPathData(1)}};u();function Ie({width:e,height:r,content:t},i){return`<svg width="${e}" height="${r}" viewBox="0 0 ${e} ${r}" xmlns="http://www.w3.org/2000/svg">${t}</svg>`}var Le=new WeakMap;function Je(e,r){let t=V();if(!t)throw new Error("Satori is not initialized.");let i;Le.has(r.fonts)?i=Le.get(r.fonts):Le.set(r.fonts,i=new ue(r.fonts));let s=t.Node.create();s.setWidth(r.width),s.setHeight(r.height),s.setFlexDirection(t.FLEX_DIRECTION_ROW),s.setFlexWrap(t.WRAP_WRAP),s.setAlignContent(t.ALIGN_AUTO),s.setAlignItems(t.ALIGN_FLEX_START),s.setJustifyContent(t.JUSTIFY_FLEX_START);let o=oe(e,{id:1,parentStyle:{},inheritedStyle:{fontSize:16,fontWeight:"normal",fontFamily:"serif",fontStyle:"normal",lineHeight:1.2,color:"black",opacity:1},parent:s,font:i,embedFont:r.embedFont,debug:r.debug,graphemeImages:r.graphemeImages});o.next(),s.calculateLayout(r.width,r.height,t.DIRECTION_LTR);let n=o.next([0,0]).value;return Ie({width:r.width,height:r.height,content:n})}export{Je as default,at as init};
|
|
3
2
|
//# sourceMappingURL=index.js.map
|