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