@mastergo/html-mastergo
Advanced tools
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var b=(t=>(t.PESUDO="PESUDO",t.INPUT="INPUT",t))(b||{});const v=t=>({...getComputedStyle(t)}),X={jpg:"jpeg",jpeg:"jpeg",png:"png",webp:"webp"},V=t=>new Promise((e,n)=>{var o;try{const r=t.imageRef;if(!r||!r.length)throw new Error("url \u9519\u8BEF");const a=r.split("."),i=((o=a[a.length-1].match(/^(jpg|jpeg|png|webp|)*/i))==null?void 0:o[0].toLowerCase())||"png",s=new Image;s.crossOrigin="anonymous",s.onload=()=>{const c=document.createElement("canvas");c.width=s.width,c.height=s.height,c.getContext("2d").drawImage(s,0,0),c.toBlob(function(d){const u=new FileReader;u.addEventListener("loadend",function(){t.bytes=new Uint8Array(this.result),e(t)}),u.addEventListener("error",g=>{console.error("\u8BFB\u53D6\u56FE\u7247\u5931\u8D25",t),n(g)}),u.readAsArrayBuffer(d)},`image/${X[i]}`)},s.onerror=c=>{console.error("\u8F6C\u6362\u56FE\u7247\u5931\u8D25",t),n(c)},s.src=r}catch(r){n(r)}}),K=t=>{const e=t.imageRef,n=window.atob(e.split(",")[1]),o=n.length,r=new Uint8Array(o);for(let a=0;a<o;a++)r[a]=n.charCodeAt(a);return t.bytes=r,Promise.resolve(t)},Z=t=>~t.imageRef.indexOf("data:image")?K(t):V(t),D=["flexMode","itemSpacing","mainAxisAlignItems","crossAxisAlignItems","mainAxisSizingMode","crossAxisSizingMode","strokesIncludedInLayout","itemReverseZIndex"],J=(t,e)=>{e.flexMode=t.flexMode;for(const n of D.slice(1))n in t&&(e[n]=t[n])};function Y(t){var o;const e=(o=t.parentElement)==null?void 0:o.getBoundingClientRect(),n=t.getBoundingClientRect();return{...n.toJSON(),left:e?n.left-e.left:n.left,top:e?n.top-e.top:n.top}}const q={100:"Thin",200:"UltraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Heavy",950:"ExtraBlack"},O={thin:["Thin","Hairline"],hairline:["Thin","Hairline"],extralight:["UltraLight","ExtraLight"],ultralight:["UltraLight","ExtraLight"],light:["Light"],regular:["Regular","Normal"],normal:["Regular","Normal"],medium:["Medium"],semibold:["SemiBold","DemiBold"],demibold:["SemiBold","DemiBold"],bold:["Bold"],extrabold:["ExtraBold","UltraBold"],ultrabold:["ExtraBold","UltraBold"],heavy:["Heavy","Black"],black:["Heavy","Black"],extrablack:["ExtraBlack","UltraBlack"],ultrablack:["ExtraBlack","UltraBlack"]},m=t=>t.toLowerCase().replace(/[^a-z]/gi,""),L={},Q={family:"Source Han Sans CN",style:"Regular"},B=async(t,e,n,o)=>{const r=`${m(t)}-${m(e)}`,a=n[r];return a?(await mg.loadFontAsync(a),L[o]=a,a):null};async function tt(t,e){const{family:n,style:o}=t,r=`${m(n)}-${m(o)}`;if(L[r])return L[r];const a=n.split(/\s*,\s*/),i=O[m(o)]||[];for(const s of a){for(const u of i){const g=await B(s,u,e,r);if(g)return g}const c=s.match(/(.+)-([a-z]*)$/i),f=c==null?void 0:c[1],d=c==null?void 0:c[2];if(f&&d){const u=O[m(d)]||[];for(const g of u){const p=await B(f,g,e,r);if(p)return p}}}return Q}const et=(t,e)=>{let n;const{value:o,placeholder:r}=t;if(!o&&!r)return null;o?n=o:n=r;const a=document.createTextNode(n);document.body.append(a);const{paddingLeft:i,paddingRight:s,paddingTop:c,textIndent:f,width:d,height:u}=e,g={...e},p=document.createRange();p.selectNode(a);const h=p.getBoundingClientRect();p.detach(),g.width=`${l(d)-l(i)-l(f)-l(s)}px`,g.height=`${h.height}px`;const x=`${l(g.x)+l(i)+l(f)}px`;let E=`${l(c)}px`;if((t.tagName==="INPUT"||t instanceof HTMLInputElement)&&(E=`${(l(u)-h.height)/2+l(c)}px`),g.x=x,g.y=E,g.left=x,g.top=E,!o){const N=getComputedStyle(t,"::placeholder");g.color=JSON.stringify(N)!==JSON.stringify(e)?N.color:"rgba(0, 0, 0, 0.24)"}return document.body.removeChild(a),{nodeType:b.INPUT,styles:g,node:{textContent:n}}},M=async t=>await Promise.allSettled(t.map(async e=>{switch(e.type){case"IMAGE":{const n=await mg.createImage(e.bytes||new Uint8Array([]));return delete e.bytes,{...e,imageRef:n.href}}}return e})),nt=["::after","::before"],ot=t=>nt.map(e=>{const n=getComputedStyle(t,e);return n.content.trim()==='""'?{nodeType:b.PESUDO,styles:{...n,isPesudo:!0},type:e}:null}).filter(e=>!!e),l=t=>{if(!t)return 0;const e=parseFloat(t);return isNaN(e)?0:e},k=t=>{var r,a;const e={r:0,g:0,b:0,a:1};if(!t)return e;const n=new RegExp(/rgb\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t)||new RegExp(/rgba\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t);if(!n)return e;const o=(r=n[1])==null?void 0:r.split(",");return e.r=parseFloat(o[0])/255,e.g=parseFloat(o[1])/255,e.b=parseFloat(o[2])/255,e.a=parseFloat((a=o[3])!=null?a:1),e},rt=t=>{t.sort((e,n)=>e.index-n.index)},at=t=>{var e;return((e=t.getClientRects())==null?void 0:e.length)>1},H=(t,e)=>({name:t,index:l(e.zIndex)}),$=t=>({isVisible:t.visibility!=="hidden",isLocked:!1}),it={normal:"NORMAL",multiply:"MULTIPLY",screen:"SCREEN",overlay:"OVERLAY",darken:"DARKEN",lighten:"LIGHTEN","color-dodge":"COLOR_DODGE","color-burn":"COLOR_BURN","hard-light":"HARD_LIGHT","soft-light":"SOFT_LIGHT",difference:"DIFFERENCE",exclusion:"EXCLUSION",hue:"HUE",saturation:"SATURATION",color:"COLOR",luminosity:"LUMINOSITY","plus-lighter":"PLUS_LIGHTER","plus-darker":"PLUS_DARKER"},st=t=>it[t]||"NORMAL",ct=t=>{let e=[],n=t.boxShadow;if(n!=="none"){const o=/\s(?![^(]*\))/,r=n.split(o);e=r.reduce((i,s)=>(/.*,$/.test(s)?(i[i.length-1].push(s.substring(0,s.length-1)),i.push([])):i[i.length-1].push(s),i),[[]]).filter(i=>i.length).map(i=>{const s={};s.color=k(i.find(p=>/(rgba|rgb?\(.+?\))/.test(p))||"rgba(0, 0, 0, 0.84)");const c=r.filter(p=>p!=="inset").filter(p=>!/(rgba|rgb?\(.+?\))/.test(p)).map(l),[f,d,u,g]=c;return s.offset={x:f,y:d},s.radius=u,s.spread=g,s.isVisible=!0,s.type=i.includes("inset")?"INNER_SHADOW":"DROP_SHADOW",s.blendMode="NORMAL",s})}return e},lt=t=>{let e=[];const n=t.filter,o=t.filter,r=(a,i)=>{var c;const s={};return s.type=a,s.isVisible=!0,s.blendMode="NORMAL",s.radius=l(((c=i.match(/blur\((.+)\)/))==null?void 0:c[1])||"0"),s};return n==="none"&&/blur\(.+\)/.test(n)&&e.push(r("BACKGROUND_BLUR",n)),o==="none"&&/blur\(.+\)/.test(o)&&e.push(r("LAYER_BLUR",o)),e},ut=t=>{const e=[];return e.push(...ct(t)),e},U=t=>({effects:[...ut(t),...lt(t)],opacity:l(t.opacity),blendMode:st(t.mixBlendMode),isMask:!1}),T={borderTop:"strokeTopWeight",borderBottom:"strokeBottomWeight",borderLeft:"strokeLeftWeight",borderRight:"strokeRightWeight"},G=t=>({type:"SOLID",isVisible:!0,alpha:1,blendMode:"NORMAL",color:k(t)}),ft={"to top":180,"to bottom":0,"to left":270,"to right":90,"to left top":315,"to left bottom":225,"to right top":45,"to right bottom":135},dt=(t,e,n)=>{if(t===0)return{length:n,handlePositions:[{x:.5,y:0},{x:.5,y:1}]};if(t===90)return{length:n,handlePositions:[{x:0,y:.5},{x:1,y:.5}]};if(t===180)return{length:n,handlePositions:[{x:.5,y:1},{x:.5,y:0}]};if(t===270)return{length:n,handlePositions:[{x:1,y:.5},{x:0,y:.5}]};const o=Math.atan(e/n)*180/Math.PI,r=90-o,a=(c,f,d)=>{let u=.5*f,g=u/Math.cos(c*Math.PI/180);const p=u*Math.tan(c*Math.PI/180),h=.5*d-p;return(Math.sin(c*Math.PI/180)*h+g)*2};let i=n,s=[{x:.5,y:0},{x:.5,y:1}];if(0<t&&t<=o){const c=t;i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+f)/e,s[1].y=1-(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=(.5*n+d)/n}else if(o<t&&t<=90+r){const c=Math.abs(t-90);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+d)/e,s[1].y=(.5*n+f)/n,s[0].x=1-(.5*e+d)/e,s[0].y=1-(.5*n+f)/n}else if(90+r<t&&t<=180+o){const c=Math.abs(180-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;t<180?(s[1].x=(.5*e+f)/e,s[1].y=(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=1-(.5*n+d)/n):(s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n)}else if(180+o<t&&t<=270+r){const c=Math.abs(270-t);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+d)/e,s[0].y=(.5*n+f)/n,s[1].x=1-(.5*e+d)/e,s[1].y=1-(.5*n+f)/n}else if(270+r<t&&t<=360){const c=Math.abs(360-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n}return 180<=t&&t<=270&&s.forEach(c=>{c.y>.5?c.y=c.y-2*(c.y-.5):c.y=c.y+2*(.5-c.y)}),{length:i,handlePositions:s}},gt=(t,e)=>{const n=[...t],o=n[0],r=o.split(new RegExp("(?<!,)(?:\\s)")),a=n[n.length-1],i=a.split(new RegExp("(?<!,)(?:\\s)"));return r.length===1?n[0]=`${o} 0%`:l(r[1])!==0&&n.splice(0,0,`${r[0]} 0%`),i.length===1?n[n.length-1]=`${a} 100%`:(i[1].includes("%")&&l(i[1])!==100||i[1].includes("px")&&l(i[1])<e)&&n.splice(0,n.length-1,`${i[0]} 100%`),n},pt=(t,e)=>t.includes("%")?Math.min(1,l(t)/100):Math.min(1,l(t)/e),ht=(t,e)=>{const n=gt(t,e);let o=0,r=1;const a=[];return n.reduce((i,s,c)=>{const f={color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1},position:0},d=s.split(new RegExp("(?<!,)(?:\\s)"));f.color=k(d[0]);const u=d[1];if(u)f.position=pt(u,e),o=f.position;else{if(!a.length)for(let g=c;g<n.length-1;g++){const p=n[c].split(new RegExp("(?<!,)(?:\\s)"));if(p.length>1){r=l(p[1]);break}else a.push("")}f.position=o+(r-o)/(a.length+1),a.pop()}return i.push(f),i.sort((g,p)=>g.position-p.position)},[])},mt=(t,e)=>{let o=t.match(/.*linear-gradient\((.*)\)\s/i)[1].split(new RegExp("(?<=\\D)(?:,\\s)")),r=0,a=[[1,0,0],[0,1,0]],i=[];if(o[0].match(/to|deg/)){const f=o.splice(0,1)[0];f.includes("to")?r=ft[f]:r=l(f)%360,a=[[Math.cos(r*Math.PI/180),Math.sin(r*Math.PI/180),0],[-Math.sin(r*Math.PI/180),Math.cos(r*Math.PI/180),0]]}const{length:s,handlePositions:c}=dt(r,l(e.width),l(e.height));return i=ht(o,s),{type:"GRADIENT_LINEAR",gradientStops:i,transform:a,gradientHandlePositions:c}},xt=(t,e)=>t.includes("linear-gradient")?mt(t,e):t.includes("conic-gradient")?{type:"GRADIENT_ANGULAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:t.includes("radial-gradient")?{type:"GRADIENT_RADIAL",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:{type:"GRADIENT_LINEAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}],gradientHandlePositions:[{x:.5,y:.5},{x:.5,y:1}]},bt=(t,e,n)=>e==="no-repeat"?"FILL":t==="contain"||n==="contain"?"FIT":t==="cover"||n==="cover"?"STRETCH":"FILL",Et=t=>{switch(t){case"solid":return"SOLID";case"dashed":return"DASH";default:return"SOLID"}},Tt=(t,e)=>{var o;const n=[];return(o=e==null?void 0:e.background)!=null&&o.match(/gradient/)?n.push(xt(e.background,e)):t&&n.push(G(t)),n},St=({backgroundImage:t,backgroundRepeat:e,backgroundSize:n,objectFit:o})=>{let r=null;return t&&t!=="none"&&(r={type:"IMAGE",isVisible:!0,alpha:1,blendMode:"NORMAL",imageRef:t,scaleMode:bt(n,e,o)}),r},Rt=(t,e)=>Tt(t,e),Mt=(t,e)=>{const n={},o=t.split(new RegExp("(?<!,)\\s"));return n.strokeWeight=l(o[0]),n.color=o[2],n.side=e,n},At=t=>{let e=!1;const n={};if([{value:t.borderTop,side:T.borderTop},{value:t.borderBottom,side:T.borderBottom},{value:t.borderLeft,side:T.borderLeft},{value:t.borderRight,side:T.borderRight}].forEach(a=>{const i=Mt(a.value,a.side);i.strokeWeight>0&&(e=!0),n[i.color]?n[i.color].push(i):n[i.color]=[i]}),!e)return[];let o=[];const r=Object.entries(n).filter(([a,i])=>i.every(c=>c.strokeWeight===0)?(o.push(...i),!1):!0);return r[0][1].push(...o),r},_=(t,e)=>{const n=t.backgroundImage.split(/(?=url)(?![^(]*\))/).map(a=>{var i;return(i=/url\("(.*)"\)/.exec(a))==null?void 0:i[1]}).filter(a=>!!a),o=[...Rt(e==="TEXT"?t.color:t.backgroundColor,t),...n.map(a=>St({backgroundImage:a,backgroundRepeat:t.backgroundRepeat,backgroundSize:t.backgroundSize,objectFit:t.objectFit})).filter(a=>!!a)],r={};if(r.fills=o,e!=="TEXT"){r.strokeWeight=parseFloat(t.borderWidth)||0;const a=At(t),i=a.map(s=>{const[c,f]=s,d=G(c);if(a.length>1||f.some(({strokeWeight:u})=>u===0))for(const{strokeWeight:u,side:g}of f)r[g]=u;return d});r.strokes=i,r.strokeStyle=Et(t.borderStyle),r.strokeAlign=t.boxSizing==="border-box"?"INSIDE":"OUTSIDE",r.strokeCap="NONE",r.strokeJoin="MITER"}return r},S=.01,Lt=t=>{const e=t.match(/^matrix\((.*)\)$/);if(!e)return null;const[n,o,r,a,i,s]=e[1].split(",").map(c=>Number(c));return{a:n,b:o,c:r,d:a,e:i,f:s}},y=(t,e,n)=>{const o={};if(o.layoutPositioning="ABSOLUTE",o.width=t.width==="auto"?S:Math.max(S,l(t.width)),o.height=t.height==="auto"?S:Math.max(S,l(t.height)),o.x=l(t.x),o.y=l(t.y),t.isPesudo&&(o.x+=l(e.borderLeftWidth||"0px")+l(t.left)+l(t.marginLeft),o.y+=l(e.borderTopWidth||"0px")+l(t.top)+l(t.marginTop)),n!=="TEXT"){const r=Lt(t.transform);if(r){const{a,b:i,c:s,d:c,e:f,f:d}=r,u=Math.round(Math.atan2(i,a)*(180/Math.PI));u!==0&&(o.rotation=u),o.x+=f,o.y+=d}}return o},R=(t,e)=>{const n=t==null?void 0:t.match(/^(\d+px)/);if(n)return l(n[0]);const o=t==null?void 0:t.match(/^(\d+%)/);if(o){const r=l(o[0]);return parseFloat((e*r/100).toFixed(2))}return 0},P=t=>{const e={};return e.topLeftRadius=R(t.borderTopLeftRadius,l(t.height))||0,e.topRightRadius=R(t.borderTopRightRadius,l(t.height))||0,e.bottomLeftRadius=R(t.borderBottomLeftRadius,l(t.height))||0,e.bottomRightRadius=R(t.borderBottomRightRadius,l(t.height))||0,e},W={absoluteBounds:!1},It=t=>{Object.assign(W,{...t})},kt=["hidden","scroll","auto","clip","overlay"],yt=(t,e,n)=>{const o={};return Object.assign(o,y(t,e,"FRAME")),Object.assign(o,H(n,t)),Object.assign(o,$(t)),Object.assign(o,U(t)),Object.assign(o,_(t,"FRAME")),Object.assign(o,P(t)),o},w=t=>{switch(t){case"flex-start":return"FLEX_START";case"flex-end":return"FLEX_END";case"center":return"CENTER";case"space-between":return"SPACING_BETWEEN";default:return"FLEX_START"}},Pt=t=>{const e={};if(["inline-flex",["flex"]].includes(t.display)){const n=t.flexDirection==="row";e.flexMode=n?"HORIZONTAL":"VERTICAL",e.itemSpacing=l(n?t.rowGap:t.columnGap),e.mainAxisAlignItems=w(t.justifyContent),e.crossAxisAlignItems=w(t.alignItems),n?(t.width&&(e.mainAxisSizingMode="FIXED"),t.height&&(e.crossAxisSizingMode="FIXED")):(t.width&&(e.crossAxisSizingMode="FIXED"),t.height&&(e.mainAxisSizingMode="FIXED"))}else if(l(t.paddingTop)||l(t.paddingBottom)||l(t.paddingLeft)||l(t.paddingRight))e.flexMode="VERTICAL";else return e;return e.paddingTop=l(t.paddingTop),e.paddingRight=l(t.paddingRight),e.paddingBottom=l(t.paddingBottom),e.paddingLeft=l(t.paddingLeft),e},Ct=t=>{const e={};return Object.assign(e,Pt(t)),W.absoluteBounds?e.clipsContent=!1:e.clipsContent=kt.some(n=>t.overflow.includes(n)),e},C=(t,e,n,o)=>({...H(t,e),...$(e),...U(e),..._(e,o),...y(e,n,o)}),Nt=t=>{switch(t){case"left":return"LEFT";case"center":return"CENTER";case"right":return"RIGHT";case"justify":return"JUSTIFIED";default:return"LEFT"}};function Ot(t){switch(t){case"middle":return"CENTER";case"bottom":return"BOTTOM";default:return"TOP"}}function Bt(t){switch(t){case"underline":return"UNDERLINE";case"line-through":return"STRIKETHROUGH";case"node":default:return"NONE"}}const wt=(t,e)=>{const n=q[e];let o="Regular";switch(t){case"italic":o="Italic";case"oblique":o="Italic";default:o="Regular"}return o==="Italic"?`${n} ${o}`:n};function Ft(t){if(t.boxSizing==="border-box"){let e=t.lineHeight==="normal"?l(t.fontSize)*1.14:l(t.lineHeight);return Math.min(l(t.height),e+l(t.borderTopWidth)+l(t.borderBottomWidth))}else return l(t.lineHeight)}const F=(t,e,n)=>{var a;if(!t.textContent||e.display==="none")return null;const o={};o.characters=t.textContent||"",o.type="TEXT",o.textAutoResize=(a=e.textAutoResize)!=null?a:"WIDTH_AND_HEIGHT",l(e.fontSize)*1.14,e.lineHeight.endsWith("px")&&l(e.lineHeight),e.isTextWrapped&&(o.textAutoResize="NONE"),o.textAlignHorizontal=Nt(e.textAlign),o.textAlignVertical=Ot(e.verticalAlign),o.textStyles=[{start:0,end:o.characters.length,textStyle:{lineHeight:{unit:"PIXELS",value:Ft(e)},fontSize:l(e.fontSize),fontName:{family:e.fontFamily,style:wt(e.fontStyle,e.fontWeight)},textDecoration:Bt(e.textDecorationLine)}}],e.backgroundColor=e.color;const r=C(o.characters||"\u6587\u5B57",e,n,"TEXT");return Object.assign(o,r),o},vt=(t,e,n)=>{const o=t.getAttribute("src");return o&&e.backgroundImage==="none"&&(e.backgroundImage=`url("${o}")`),{...C(t.id||t.tagName,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"}},Dt=(t,e,n)=>{const o={...yt(e,n,t.id||t.tagName),...Ct(e)};return o.type="FRAME",o},Ht=(t,e,n)=>e.display==="none"?null:{...C(t,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"},$t=(t,e,n)=>{const o={},r=e.fill,a=e.stroke,i=e.color;t.style.fill.toLowerCase()==="currentcolor"&&(t.style.fill=/rgba|rgb/.test(r)?r:i),t.style.stroke.toLowerCase()==="currentcolor"&&(t.style.stroke=/rgba|rgb/.test(a)?a:i),o.type="PEN";let s=t.outerHTML;return s=s.replace(/(fill="currentColor"|fill="")/i,`fill="${/rgba|rgb/.test(r)?r:i}"`),s=s.replace(/(stroke="currentColor"|stroke="")/i,`stroke="${/rgba|rgb/.test(a)?a:i}"`),o.content=s,Object.assign(o,y(e,n,"PEN")),o},I={};function A(t,e){var n;return!!((n=Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(t),e))!=null&&n.set)}const Ut=async(t,e)=>{var n;try{const o=Object.keys(t).filter(r=>!D.includes(r));t.flexMode&&t.flexMode!=="NONE"&&J(t,e);for(const r of o)typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await M(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r]);return await Promise.allSettled(((n=t.children)==null?void 0:n.map(async r=>{const a=await jt(r);return a&&(e.appendChild(a),await j(r,a)),!0}))||[]),e}catch(o){return console.error("\u53D1\u751F\u9519\u8BEF,",o),null}},Gt=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await M(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e},_t=async(t,e)=>{var o;const n=Object.keys(t);(o=t.textStyles)==null||o.forEach(async r=>{const a=r.textStyle.fontName,i=await tt(a,I);e.setRangeFontName(r.start,r.end,i),e.setRangeLineHeight(r.start,r.end,r.textStyle.lineHeight),e.setRangeFontSize(r.start,r.end,r.textStyle.fontSize)}),delete t.textStyles;for(const r of n)try{typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await M(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r])}catch(a){console.log(`Failed to set ${r} of node ${e==null?void 0:e.name}`,a)}return e},Wt=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await M(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e};async function jt(t){if(!t)return null;switch(t==null?void 0:t.type){case"FRAME":return mg.createFrame();case"RECTANGLE":return mg.createRectangle();case"TEXT":return mg.createText();case"PEN":return await mg.createNodeFromSvgAsync(t.content)}return null}const j=async(t,e)=>{if(!t||!e)return null;let n={};const o=t.rotation;switch(delete t.rotation,t==null?void 0:t.type){case"FRAME":{n=await Ut(t,e);break}case"RECTANGLE":{n=await Gt(t,e);break}case"TEXT":{n=await _t(t,e);break}case"PEN":{n=await Wt(t,e);break}default:throw new Error("failed to convert, layer has unknown type.")}return requestAnimationFrame(()=>{o&&n&&(n.rotation=o)}),n},zt=async t=>{if(!mg)throw new Error("Please invoke this function at plugin environment");return Object.keys(I).length||(await mg.listAvailableFontsAsync()).forEach(n=>{const{family:o,style:r}=n.fontName;I[`${m(o)}-${m(r)}`]=n.fontName}),await j(t,mg.createFrame())},Xt=async t=>{const e=[],n=o=>{var r;if(!o)return null;try{const a=Object.keys(o);for(const i of a)if(["fills","strokes"].includes(i)){const s=o[i];s==null||s.forEach(c=>{c.type==="IMAGE"&&e.push(Z(c))})}else if(i==="children"&&((r=o.children)==null?void 0:r.length))for(const s of o.children)n(s)}catch(a){console.error("error occured in secondary operation",a)}};return n(t),await Promise.allSettled(e),t},z=async(t,e,n)=>{var f,d;if(e.display==="none")return null;e.transform!=="none"&&(t.style.transform="unset",t.style.transition="unset",await new Promise(u=>{setTimeout(()=>{u(1)},100)}));const o=Y(t);if(e.width==="auto"||e.height==="auto"){const u=document.createRange();u.selectNode(t);const g=u.getBoundingClientRect();e.width=`${g.width}px`,e.height=`${g.height}px`,u.detach()}if(e.x=`${o.left}px`,e.y=`${o.top}px`,e.width=`${o.width}px`,e.height=`${o.height}px`,t.tagName==="svg")return $t(t,e,n);let r=null;(["TEXTAREA","INPUT"].includes(t.tagName)||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)&&(r=et(t,e));const a=ot(t);if(!t.hasChildNodes()&&a.length===0&&!r)return vt(t,e,n);const i=Dt(t,e,n);i.children=[];let s=Array.from((f=t.childNodes)!=null?f:[]);s=s.concat(a).concat(r);const c=await Promise.allSettled(s.map(async u=>{let g;if(!u)return null;if(u.nodeType===Node.ELEMENT_NODE){const p=v(u);g=await z(u,{...p},e)}if(u.nodeType===Node.TEXT_NODE){const p=document.createRange();p.selectNodeContents(u);const h=p.getBoundingClientRect(),x=at(p);p.detach(),g=F(u,{...e,isTextWrapped:x,width:`${h.width}px`,height:`${h.height}px`,x:`${h.x-o.x}px`,y:`${h.y-o.y}px`,left:`${h.left}px`,right:`${h.right}px`,top:`${h.top}px`,bottom:`${h.bottom}px`},e)}else u.nodeType===b.PESUDO?g=Ht(u.type,u.styles,e):u.nodeType===b.INPUT&&(g=F(u.node,u.styles,u.styles));return g}));return i.children=c.filter(u=>(u==null?void 0:u.status)==="fulfilled"&&!!(u!=null&&u.value)).map(u=>u.value),(d=i.children)!=null&&d.length&&rt(i.children),e.transform!=="none"&&(t.style.transform="",t.style.transition=""),i},Vt=async(t,e)=>{if(e&&It(e),!getComputedStyle)throw new Error("getComputedStyle is not defined");try{const n=await z(t,v(t),null);return console.log("\u8F6C\u6362\u7ED3\u679C",n),n}catch(n){console.error("\u8F6C\u6362\u51FA\u9519",n)}return null};exports.htmlToMG=Vt;exports.postProcess=Xt;exports.renderToMasterGo=zt; | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var b=(t=>(t.PESUDO="PESUDO",t.INPUT="INPUT",t))(b||{});const v=t=>({...getComputedStyle(t)}),X={jpg:"jpeg",jpeg:"jpeg",png:"png",webp:"webp"},V=t=>new Promise((e,n)=>{var o;try{const r=t.imageRef;if(!r||!r.length)throw new Error("url \u9519\u8BEF");const a=r.split("."),i=((o=a[a.length-1].match(/^(jpg|jpeg|png|webp|)*/i))==null?void 0:o[0].toLowerCase())||"png",s=new Image;s.crossOrigin="anonymous",s.onload=()=>{const c=document.createElement("canvas");c.width=s.width,c.height=s.height,c.getContext("2d").drawImage(s,0,0),c.toBlob(function(d){const u=new FileReader;u.addEventListener("loadend",function(){t.bytes=new Uint8Array(this.result),e(t)}),u.addEventListener("error",g=>{console.error("\u8BFB\u53D6\u56FE\u7247\u5931\u8D25",t),n(g)}),u.readAsArrayBuffer(d)},`image/${X[i]}`)},s.onerror=c=>{console.error("\u8F6C\u6362\u56FE\u7247\u5931\u8D25",t),n(c)},s.src=r}catch(r){n(r)}}),K=t=>{const e=t.imageRef,n=window.atob(e.split(",")[1]),o=n.length,r=new Uint8Array(o);for(let a=0;a<o;a++)r[a]=n.charCodeAt(a);return t.bytes=r,Promise.resolve(t)},Z=t=>~t.imageRef.indexOf("data:image")?K(t):V(t),D=["flexMode","itemSpacing","mainAxisAlignItems","crossAxisAlignItems","mainAxisSizingMode","crossAxisSizingMode","strokesIncludedInLayout","itemReverseZIndex"],J=(t,e)=>{e.flexMode=t.flexMode;for(const n of D.slice(1))n in t&&(e[n]=t[n])};function Y(t){var o;const e=(o=t.parentElement)==null?void 0:o.getBoundingClientRect(),n=t.getBoundingClientRect();return{...n.toJSON(),left:e?n.left-e.left:n.left,top:e?n.top-e.top:n.top}}const q={100:"Thin",200:"UltraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Heavy",950:"ExtraBlack"},O={thin:["Thin","Hairline"],hairline:["Thin","Hairline"],extralight:["UltraLight","ExtraLight"],ultralight:["UltraLight","ExtraLight"],light:["Light"],regular:["Regular","Normal"],normal:["Regular","Normal"],medium:["Medium"],semibold:["SemiBold","DemiBold"],demibold:["SemiBold","DemiBold"],bold:["Bold"],extrabold:["ExtraBold","UltraBold"],ultrabold:["ExtraBold","UltraBold"],heavy:["Heavy","Black"],black:["Heavy","Black"],extrablack:["ExtraBlack","UltraBlack"],ultrablack:["ExtraBlack","UltraBlack"]},m=t=>t.toLowerCase().replace(/[^a-z]/gi,""),L={},Q={family:"Source Han Sans CN",style:"Regular"},B=async(t,e,n,o)=>{const r=`${m(t)}-${m(e)}`,a=n[r];return a?(await mg.loadFontAsync(a),L[o]=a,a):null};async function tt(t,e){const{family:n,style:o}=t,r=`${m(n)}-${m(o)}`;if(L[r])return L[r];const a=n.split(/\s*,\s*/),i=O[m(o)]||[];for(const s of a){for(const u of i){const g=await B(s,u,e,r);if(g)return g}const c=s.match(/(.+)-([a-z]*)$/i),f=c==null?void 0:c[1],d=c==null?void 0:c[2];if(f&&d){const u=O[m(d)]||[];for(const g of u){const p=await B(f,g,e,r);if(p)return p}}}return Q}const et=(t,e)=>{let n;const{value:o,placeholder:r}=t;if(!o&&!r)return null;o?n=o:n=r;const a=document.createTextNode(n);document.body.append(a);const{paddingLeft:i,paddingRight:s,paddingTop:c,textIndent:f,width:d,height:u}=e,g={...e},p=document.createRange();p.selectNode(a);const h=p.getBoundingClientRect();p.detach(),g.width=`${l(d)-l(i)-l(f)-l(s)}px`,g.height=`${h.height}px`;const x=`${l(i)+l(f)}px`;let E=`${l(c)}px`;if((t.tagName==="INPUT"||t instanceof HTMLInputElement)&&(E=`${(l(u)-h.height)/2+l(c)}px`),g.x=x,g.y=E,g.left=x,g.top=E,!o){const C=getComputedStyle(t,"::placeholder");g.color=JSON.stringify(C)!==JSON.stringify(e)?C.color:"rgba(0, 0, 0, 0.24)"}return document.body.removeChild(a),{nodeType:b.INPUT,styles:g,node:{textContent:n}}},M=async t=>await Promise.allSettled(t.map(async e=>{switch(e.type){case"IMAGE":{const n=await mg.createImage(e.bytes||new Uint8Array([]));return delete e.bytes,{...e,imageRef:n.href}}}return e})),nt=["::after","::before"],ot=t=>nt.map(e=>{const n=getComputedStyle(t,e);return n.content.trim()==='""'?{nodeType:b.PESUDO,styles:{...n,isPesudo:!0},type:e}:null}).filter(e=>!!e),l=t=>{if(!t)return 0;const e=parseFloat(t);return isNaN(e)?0:e},k=t=>{var r,a;const e={r:0,g:0,b:0,a:1};if(!t)return e;const n=new RegExp(/rgb\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t)||new RegExp(/rgba\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t);if(!n)return e;const o=(r=n[1])==null?void 0:r.split(",");return e.r=parseFloat(o[0])/255,e.g=parseFloat(o[1])/255,e.b=parseFloat(o[2])/255,e.a=parseFloat((a=o[3])!=null?a:1),e},rt=t=>{t.sort((e,n)=>e.index-n.index)},at=t=>{var e;return((e=t.getClientRects())==null?void 0:e.length)>1},H=(t,e)=>({name:t,index:l(e.zIndex)}),$=t=>({isVisible:t.visibility!=="hidden",isLocked:!1}),it={normal:"NORMAL",multiply:"MULTIPLY",screen:"SCREEN",overlay:"OVERLAY",darken:"DARKEN",lighten:"LIGHTEN","color-dodge":"COLOR_DODGE","color-burn":"COLOR_BURN","hard-light":"HARD_LIGHT","soft-light":"SOFT_LIGHT",difference:"DIFFERENCE",exclusion:"EXCLUSION",hue:"HUE",saturation:"SATURATION",color:"COLOR",luminosity:"LUMINOSITY","plus-lighter":"PLUS_LIGHTER","plus-darker":"PLUS_DARKER"},st=t=>it[t]||"NORMAL",ct=t=>{let e=[],n=t.boxShadow;if(n!=="none"){const o=/\s(?![^(]*\))/,r=n.split(o);e=r.reduce((i,s)=>(/.*,$/.test(s)?(i[i.length-1].push(s.substring(0,s.length-1)),i.push([])):i[i.length-1].push(s),i),[[]]).filter(i=>i.length).map(i=>{const s={};s.color=k(i.find(p=>/(rgba|rgb?\(.+?\))/.test(p))||"rgba(0, 0, 0, 0.84)");const c=r.filter(p=>p!=="inset").filter(p=>!/(rgba|rgb?\(.+?\))/.test(p)).map(l),[f,d,u,g]=c;return s.offset={x:f,y:d},s.radius=u,s.spread=g,s.isVisible=!0,s.type=i.includes("inset")?"INNER_SHADOW":"DROP_SHADOW",s.blendMode="NORMAL",s})}return e},lt=t=>{let e=[];const n=t.filter,o=t.filter,r=(a,i)=>{var c;const s={};return s.type=a,s.isVisible=!0,s.blendMode="NORMAL",s.radius=l(((c=i.match(/blur\((.+)\)/))==null?void 0:c[1])||"0"),s};return n==="none"&&/blur\(.+\)/.test(n)&&e.push(r("BACKGROUND_BLUR",n)),o==="none"&&/blur\(.+\)/.test(o)&&e.push(r("LAYER_BLUR",o)),e},ut=t=>{const e=[];return e.push(...ct(t)),e},U=t=>({effects:[...ut(t),...lt(t)],opacity:l(t.opacity)||1,blendMode:st(t.mixBlendMode),isMask:!1}),T={borderTop:"strokeTopWeight",borderBottom:"strokeBottomWeight",borderLeft:"strokeLeftWeight",borderRight:"strokeRightWeight"},G=t=>({type:"SOLID",isVisible:!0,alpha:1,blendMode:"NORMAL",color:k(t)}),ft={"to top":180,"to bottom":0,"to left":270,"to right":90,"to left top":315,"to left bottom":225,"to right top":45,"to right bottom":135},dt=(t,e,n)=>{if(t===0)return{length:n,handlePositions:[{x:.5,y:0},{x:.5,y:1}]};if(t===90)return{length:n,handlePositions:[{x:0,y:.5},{x:1,y:.5}]};if(t===180)return{length:n,handlePositions:[{x:.5,y:1},{x:.5,y:0}]};if(t===270)return{length:n,handlePositions:[{x:1,y:.5},{x:0,y:.5}]};const o=Math.atan(e/n)*180/Math.PI,r=90-o,a=(c,f,d)=>{let u=.5*f,g=u/Math.cos(c*Math.PI/180);const p=u*Math.tan(c*Math.PI/180),h=.5*d-p;return(Math.sin(c*Math.PI/180)*h+g)*2};let i=n,s=[{x:.5,y:0},{x:.5,y:1}];if(0<t&&t<=o){const c=t;i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+f)/e,s[1].y=1-(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=(.5*n+d)/n}else if(o<t&&t<=90+r){const c=Math.abs(t-90);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+d)/e,s[1].y=(.5*n+f)/n,s[0].x=1-(.5*e+d)/e,s[0].y=1-(.5*n+f)/n}else if(90+r<t&&t<=180+o){const c=Math.abs(180-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;t<180?(s[1].x=(.5*e+f)/e,s[1].y=(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=1-(.5*n+d)/n):(s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n)}else if(180+o<t&&t<=270+r){const c=Math.abs(270-t);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+d)/e,s[0].y=(.5*n+f)/n,s[1].x=1-(.5*e+d)/e,s[1].y=1-(.5*n+f)/n}else if(270+r<t&&t<=360){const c=Math.abs(360-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n}return 180<=t&&t<=270&&s.forEach(c=>{c.y>.5?c.y=c.y-2*(c.y-.5):c.y=c.y+2*(.5-c.y)}),{length:i,handlePositions:s}},gt=(t,e)=>{const n=[...t],o=n[0],r=o.split(new RegExp("(?<!,)(?:\\s)")),a=n[n.length-1],i=a.split(new RegExp("(?<!,)(?:\\s)"));return r.length===1?n[0]=`${o} 0%`:l(r[1])!==0&&n.splice(0,0,`${r[0]} 0%`),i.length===1?n[n.length-1]=`${a} 100%`:(i[1].includes("%")&&l(i[1])!==100||i[1].includes("px")&&l(i[1])<e)&&n.splice(0,n.length-1,`${i[0]} 100%`),n},pt=(t,e)=>t.includes("%")?Math.min(1,l(t)/100):Math.min(1,l(t)/e),ht=(t,e)=>{const n=gt(t,e);let o=0,r=1;const a=[];return n.reduce((i,s,c)=>{const f={color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1},position:0},d=s.split(new RegExp("(?<!,)(?:\\s)"));f.color=k(d[0]);const u=d[1];if(u)f.position=pt(u,e),o=f.position;else{if(!a.length)for(let g=c;g<n.length-1;g++){const p=n[c].split(new RegExp("(?<!,)(?:\\s)"));if(p.length>1){r=l(p[1]);break}else a.push("")}f.position=o+(r-o)/(a.length+1),a.pop()}return i.push(f),i.sort((g,p)=>g.position-p.position)},[])},mt=(t,e)=>{let o=t.match(/.*linear-gradient\((.*)\)\s/i)[1].split(new RegExp("(?<=\\D)(?:,\\s)")),r=0,a=[[1,0,0],[0,1,0]],i=[];if(o[0].match(/to|deg/)){const f=o.splice(0,1)[0];f.includes("to")?r=ft[f]:r=l(f)%360,a=[[Math.cos(r*Math.PI/180),Math.sin(r*Math.PI/180),0],[-Math.sin(r*Math.PI/180),Math.cos(r*Math.PI/180),0]]}const{length:s,handlePositions:c}=dt(r,l(e.width),l(e.height));return i=ht(o,s),{type:"GRADIENT_LINEAR",gradientStops:i,transform:a,gradientHandlePositions:c}},xt=(t,e)=>t.includes("linear-gradient")?mt(t,e):t.includes("conic-gradient")?{type:"GRADIENT_ANGULAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:t.includes("radial-gradient")?{type:"GRADIENT_RADIAL",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:{type:"GRADIENT_LINEAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}],gradientHandlePositions:[{x:.5,y:.5},{x:.5,y:1}]},bt=(t,e,n)=>e==="no-repeat"?"FILL":t==="contain"||n==="contain"?"FIT":t==="cover"||n==="cover"?"STRETCH":"FILL",Et=t=>{switch(t){case"solid":return"SOLID";case"dashed":return"DASH";default:return"SOLID"}},Tt=(t,e)=>{var o;const n=[];return(o=e==null?void 0:e.background)!=null&&o.match(/gradient/)?n.push(xt(e.background,e)):t&&n.push(G(t)),n},St=({backgroundImage:t,backgroundRepeat:e,backgroundSize:n,objectFit:o})=>{let r=null;return t&&t!=="none"&&(r={type:"IMAGE",isVisible:!0,alpha:1,blendMode:"NORMAL",imageRef:t,scaleMode:bt(n,e,o)}),r},Rt=(t,e)=>Tt(t,e),Mt=(t,e)=>{const n={},o=t.split(new RegExp("(?<!,)\\s"));return n.strokeWeight=l(o[0]),n.color=o[2],n.side=e,n},At=t=>{let e=!1;const n={};if([{value:t.borderTop,side:T.borderTop},{value:t.borderBottom,side:T.borderBottom},{value:t.borderLeft,side:T.borderLeft},{value:t.borderRight,side:T.borderRight}].forEach(a=>{const i=Mt(a.value,a.side);i.strokeWeight>0&&(e=!0),n[i.color]?n[i.color].push(i):n[i.color]=[i]}),!e)return[];let o=[];const r=Object.entries(n).filter(([a,i])=>i.every(c=>c.strokeWeight===0)?(o.push(...i),!1):!0);return r[0][1].push(...o),r},_=(t,e)=>{const n=t.backgroundImage.split(/(?=url)(?![^(]*\))/).map(a=>{var i;return(i=/url\("(.*)"\)/.exec(a))==null?void 0:i[1]}).filter(a=>!!a),o=[...Rt(e==="TEXT"?t.color:t.backgroundColor,t),...n.map(a=>St({backgroundImage:a,backgroundRepeat:t.backgroundRepeat,backgroundSize:t.backgroundSize,objectFit:t.objectFit})).filter(a=>!!a)],r={};if(r.fills=o,e!=="TEXT"){r.strokeWeight=parseFloat(t.borderWidth)||0;const a=At(t),i=a.map(s=>{const[c,f]=s,d=G(c);if(a.length>1||f.some(({strokeWeight:u})=>u===0))for(const{strokeWeight:u,side:g}of f)r[g]=u;return d});r.strokes=i,r.strokeStyle=Et(t.borderStyle),r.strokeAlign=t.boxSizing==="border-box"?"INSIDE":"OUTSIDE",r.strokeCap="NONE",r.strokeJoin="MITER"}return r},S=.01,Lt=t=>{const e=t.match(/^matrix\((.*)\)$/);if(!e)return null;const[n,o,r,a,i,s]=e[1].split(",").map(c=>Number(c));return{a:n,b:o,c:r,d:a,e:i,f:s}},y=(t,e,n)=>{const o={};if(o.layoutPositioning="ABSOLUTE",o.width=t.width==="auto"?S:Math.max(S,l(t.width)),o.height=t.height==="auto"?S:Math.max(S,l(t.height)),o.x=l(t.x),o.y=l(t.y),t.isPesudo&&(o.x+=l(e.borderLeftWidth||"0px")+l(t.left)+l(t.marginLeft),o.y+=l(e.borderTopWidth||"0px")+l(t.top)+l(t.marginTop)),n!=="TEXT"){const r=Lt(t.transform);if(r){const{a,b:i,c:s,d:c,e:f,f:d}=r,u=Math.round(Math.atan2(i,a)*(180/Math.PI));u!==0&&(o.rotation=u),o.x+=f,o.y+=d}}return o},R=(t,e)=>{const n=t==null?void 0:t.match(/^(\d+px)/);if(n)return l(n[0]);const o=t==null?void 0:t.match(/^(\d+%)/);if(o){const r=l(o[0]);return parseFloat((e*r/100).toFixed(2))}return 0},P=t=>{const e={};return e.topLeftRadius=R(t.borderTopLeftRadius,l(t.height))||0,e.topRightRadius=R(t.borderTopRightRadius,l(t.height))||0,e.bottomLeftRadius=R(t.borderBottomLeftRadius,l(t.height))||0,e.bottomRightRadius=R(t.borderBottomRightRadius,l(t.height))||0,e},W={absoluteBounds:!1},It=t=>{Object.assign(W,{...t})},kt=["hidden","scroll","auto","clip","overlay"],yt=(t,e,n)=>{const o={};return Object.assign(o,y(t,e,"FRAME")),Object.assign(o,H(n,t)),Object.assign(o,$(t)),Object.assign(o,U(t)),Object.assign(o,_(t,"FRAME")),Object.assign(o,P(t)),o},w=t=>{switch(t){case"flex-start":return"FLEX_START";case"flex-end":return"FLEX_END";case"center":return"CENTER";case"space-between":return"SPACING_BETWEEN";default:return"FLEX_START"}},Pt=t=>{const e={};if(["inline-flex",["flex"]].includes(t.display)){const n=t.flexDirection==="row";e.flexMode=n?"HORIZONTAL":"VERTICAL",e.itemSpacing=l(n?t.rowGap:t.columnGap),e.mainAxisAlignItems=w(t.justifyContent),e.crossAxisAlignItems=w(t.alignItems),n?(t.width&&(e.mainAxisSizingMode="FIXED"),t.height&&(e.crossAxisSizingMode="FIXED")):(t.width&&(e.crossAxisSizingMode="FIXED"),t.height&&(e.mainAxisSizingMode="FIXED"))}else if(l(t.paddingTop)||l(t.paddingBottom)||l(t.paddingLeft)||l(t.paddingRight))e.flexMode="VERTICAL";else return e;return e.paddingTop=l(t.paddingTop),e.paddingRight=l(t.paddingRight),e.paddingBottom=l(t.paddingBottom),e.paddingLeft=l(t.paddingLeft),e},Nt=t=>{const e={};return Object.assign(e,Pt(t)),W.absoluteBounds?e.clipsContent=!1:e.clipsContent=kt.some(n=>t.overflow.includes(n)),e},N=(t,e,n,o)=>({...H(t,e),...$(e),...U(e),..._(e,o),...y(e,n,o)}),Ct=t=>{switch(t){case"left":return"LEFT";case"center":return"CENTER";case"right":return"RIGHT";case"justify":return"JUSTIFIED";default:return"LEFT"}};function Ot(t){switch(t){case"middle":return"CENTER";case"bottom":return"BOTTOM";default:return"TOP"}}function Bt(t){switch(t){case"underline":return"UNDERLINE";case"line-through":return"STRIKETHROUGH";case"node":default:return"NONE"}}const wt=(t,e)=>{const n=q[e];let o="Regular";switch(t){case"italic":o="Italic";case"oblique":o="Italic";default:o="Regular"}return o==="Italic"?`${n} ${o}`:n};function Ft(t){if(t.boxSizing==="border-box"){let e=t.lineHeight==="normal"?l(t.fontSize)*1.14:l(t.lineHeight);return Math.min(l(t.height),e+l(t.borderTopWidth)+l(t.borderBottomWidth))}else return l(t.lineHeight)}const F=(t,e,n)=>{var a;if(!t.textContent||e.display==="none")return null;const o={};o.characters=t.textContent||"",o.type="TEXT",o.textAutoResize=(a=e.textAutoResize)!=null?a:"WIDTH_AND_HEIGHT",l(e.fontSize)*1.14,e.lineHeight.endsWith("px")&&l(e.lineHeight),e.isTextWrapped&&(o.textAutoResize="NONE"),o.textAlignHorizontal=Ct(e.textAlign),o.textAlignVertical=Ot(e.verticalAlign),o.textStyles=[{start:0,end:o.characters.length,textStyle:{lineHeight:{unit:"PIXELS",value:Ft(e)},fontSize:l(e.fontSize),fontName:{family:e.fontFamily,style:wt(e.fontStyle,e.fontWeight)},textDecoration:Bt(e.textDecorationLine)}}],e.backgroundColor=e.color;const r=N(o.characters||"\u6587\u5B57",e,n,"TEXT");return Object.assign(o,r),o},vt=(t,e,n)=>{const o=t.getAttribute("src");return o&&e.backgroundImage==="none"&&(e.backgroundImage=`url("${o}")`),{...N(t.id||t.tagName,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"}},Dt=(t,e,n)=>{const o={...yt(e,n,t.id||t.tagName),...Nt(e)};return o.type="FRAME",o},Ht=(t,e,n)=>e.display==="none"?null:{...N(t,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"},$t=(t,e,n)=>{const o={},r=e.fill,a=e.stroke,i=e.color;t.style.fill.toLowerCase()==="currentcolor"&&(t.style.fill=/rgba|rgb/.test(r)?r:i),t.style.stroke.toLowerCase()==="currentcolor"&&(t.style.stroke=/rgba|rgb/.test(a)?a:i),o.type="PEN";let s=t.outerHTML;return s=s.replace(/(fill="currentColor"|fill="")/i,`fill="${/rgba|rgb/.test(r)?r:i}"`),s=s.replace(/(stroke="currentColor"|stroke="")/i,`stroke="${/rgba|rgb/.test(a)?a:i}"`),o.content=s,Object.assign(o,y(e,n,"PEN")),o},I={};function A(t,e){var n;return!!((n=Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(t),e))!=null&&n.set)}const Ut=async(t,e)=>{var n;try{const o=Object.keys(t).filter(r=>!D.includes(r));t.flexMode&&t.flexMode!=="NONE"&&J(t,e);for(const r of o)typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await M(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r]);return await Promise.allSettled(((n=t.children)==null?void 0:n.map(async r=>{const a=await jt(r);return a&&(e.appendChild(a),await j(r,a)),!0}))||[]),e}catch(o){return console.error("\u53D1\u751F\u9519\u8BEF,",o),null}},Gt=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await M(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e},_t=async(t,e)=>{var o;const n=Object.keys(t);(o=t.textStyles)==null||o.forEach(async r=>{const a=r.textStyle.fontName,i=await tt(a,I);e.setRangeFontName(r.start,r.end,i),e.setRangeLineHeight(r.start,r.end,r.textStyle.lineHeight),e.setRangeFontSize(r.start,r.end,r.textStyle.fontSize)}),delete t.textStyles;for(const r of n)try{typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await M(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r])}catch(a){console.log(`Failed to set ${r} of node ${e==null?void 0:e.name}`,a)}return e},Wt=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await M(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e};async function jt(t){if(!t)return null;switch(t==null?void 0:t.type){case"FRAME":return mg.createFrame();case"RECTANGLE":return mg.createRectangle();case"TEXT":return mg.createText();case"PEN":return await mg.createNodeFromSvgAsync(t.content)}return null}const j=async(t,e)=>{if(!t||!e)return null;let n={};const o=t.rotation;switch(delete t.rotation,t==null?void 0:t.type){case"FRAME":{n=await Ut(t,e);break}case"RECTANGLE":{n=await Gt(t,e);break}case"TEXT":{n=await _t(t,e);break}case"PEN":{n=await Wt(t,e);break}default:throw new Error("failed to convert, layer has unknown type.")}return requestAnimationFrame(()=>{o&&n&&(n.rotation=o)}),n},zt=async t=>{if(!mg)throw new Error("Please invoke this function at plugin environment");return Object.keys(I).length||(await mg.listAvailableFontsAsync()).forEach(n=>{const{family:o,style:r}=n.fontName;I[`${m(o)}-${m(r)}`]=n.fontName}),await j(t,mg.createFrame())},Xt=async t=>{const e=[],n=o=>{var r;if(!o)return null;try{const a=Object.keys(o);for(const i of a)if(["fills","strokes"].includes(i)){const s=o[i];s==null||s.forEach(c=>{c.type==="IMAGE"&&e.push(Z(c))})}else if(i==="children"&&((r=o.children)==null?void 0:r.length))for(const s of o.children)n(s)}catch(a){console.error("error occured in secondary operation",a)}};return n(t),await Promise.allSettled(e),t},z=async(t,e,n)=>{var f,d;if(e.display==="none")return null;e.transform!=="none"&&(t.style.transform="unset",t.style.transition="unset",await new Promise(u=>{setTimeout(()=>{u(1)},100)}));const o=Y(t);if(e.width==="auto"||e.height==="auto"){const u=document.createRange();u.selectNode(t);const g=u.getBoundingClientRect();e.width=`${g.width}px`,e.height=`${g.height}px`,u.detach()}if(e.x=`${o.left}px`,e.y=`${o.top}px`,e.width=`${o.width}px`,e.height=`${o.height}px`,t.tagName==="svg")return $t(t,e,n);let r=null;(["TEXTAREA","INPUT"].includes(t.tagName)||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)&&(r=et(t,e));const a=ot(t);if(!t.hasChildNodes()&&a.length===0&&!r)return vt(t,e,n);const i=Dt(t,e,n);i.children=[];let s=t.tagName!=="TEXTAREA"?Array.from((f=t.childNodes)!=null?f:[]):[];s=s.concat(a).concat(r);const c=await Promise.allSettled(s.map(async u=>{let g;if(!u)return null;if(u.nodeType===Node.ELEMENT_NODE){const p=v(u);g=await z(u,{...p},e)}if(u.nodeType===Node.TEXT_NODE){const p=document.createRange();p.selectNode(u);const h=p.getBoundingClientRect(),x=at(p);p.detach(),g=F(u,{...e,isTextWrapped:x,width:`${h.width}px`,height:`${h.height}px`,x:`${h.x-o.x}px`,y:`${h.y-o.y}px`,left:`${h.left}px`,right:`${h.right}px`,top:`${h.top}px`,bottom:`${h.bottom}px`},e)}else u.nodeType===b.PESUDO?g=Ht(u.type,u.styles,e):u.nodeType===b.INPUT&&(g=F(u.node,u.styles,u.styles));return g}));return i.children=c.filter(u=>(u==null?void 0:u.status)==="fulfilled"&&!!(u!=null&&u.value)).map(u=>u.value),(d=i.children)!=null&&d.length&&rt(i.children),e.transform!=="none"&&(t.style.transform="",t.style.transition=""),i},Vt=async(t,e)=>{if(e&&It(e),!getComputedStyle)throw new Error("getComputedStyle is not defined");try{const n=await z(t,v(t),null);return console.log("\u8F6C\u6362\u7ED3\u679C",n),n}catch(n){console.error("\u8F6C\u6362\u51FA\u9519",n)}return null};exports.htmlToMG=Vt;exports.postProcess=Xt;exports.renderToMasterGo=zt; |
+24
-24
@@ -136,7 +136,7 @@ var b = /* @__PURE__ */ ((t) => (t.PESUDO = "PESUDO", t.INPUT = "INPUT", t))(b || {}); | ||
| p.detach(), g.width = `${l(d) - l(i) - l(f) - l(s)}px`, g.height = `${h.height}px`; | ||
| const x = `${l(g.x) + l(i) + l(f)}px`; | ||
| const x = `${l(i) + l(f)}px`; | ||
| let E = `${l(c)}px`; | ||
| if ((t.tagName === "INPUT" || t instanceof HTMLInputElement) && (E = `${(l(u) - h.height) / 2 + l(c)}px`), g.x = x, g.y = E, g.left = x, g.top = E, !o) { | ||
| const N = getComputedStyle(t, "::placeholder"); | ||
| g.color = JSON.stringify(N) !== JSON.stringify(e) ? N.color : "rgba(0, 0, 0, 0.24)"; | ||
| const C = getComputedStyle(t, "::placeholder"); | ||
| g.color = JSON.stringify(C) !== JSON.stringify(e) ? C.color : "rgba(0, 0, 0, 0.24)"; | ||
| } | ||
@@ -150,3 +150,3 @@ return document.body.removeChild(a), { | ||
| }; | ||
| }, M = async (t) => await Promise.allSettled(t.map(async (e) => { | ||
| }, A = async (t) => await Promise.allSettled(t.map(async (e) => { | ||
| switch (e.type) { | ||
@@ -247,3 +247,3 @@ case "IMAGE": { | ||
| effects: [...ut(t), ...lt(t)], | ||
| opacity: l(t.opacity), | ||
| opacity: l(t.opacity) || 1, | ||
| blendMode: st(t.mixBlendMode), | ||
@@ -459,6 +459,6 @@ isMask: !1 | ||
| }), r; | ||
| }, Rt = (t, e) => Tt(t, e), Mt = (t, e) => { | ||
| }, Rt = (t, e) => Tt(t, e), At = (t, e) => { | ||
| const n = {}, o = t.split(new RegExp("(?<!,)\\s")); | ||
| return n.strokeWeight = l(o[0]), n.color = o[2], n.side = e, n; | ||
| }, At = (t) => { | ||
| }, Mt = (t) => { | ||
| let e = !1; | ||
@@ -472,3 +472,3 @@ const n = {}; | ||
| ].forEach((a) => { | ||
| const i = Mt(a.value, a.side); | ||
| const i = At(a.value, a.side); | ||
| i.strokeWeight > 0 && (e = !0), n[i.color] ? n[i.color].push(i) : n[i.color] = [i]; | ||
@@ -495,3 +495,3 @@ }), !e) | ||
| r.strokeWeight = parseFloat(t.borderWidth) || 0; | ||
| const a = At(t), i = a.map((s) => { | ||
| const a = Mt(t), i = a.map((s) => { | ||
| const [c, f] = s, d = G(c); | ||
@@ -565,6 +565,6 @@ if (a.length > 1 || f.some(({ strokeWeight: u }) => u === 0)) | ||
| return e.paddingTop = l(t.paddingTop), e.paddingRight = l(t.paddingRight), e.paddingBottom = l(t.paddingBottom), e.paddingLeft = l(t.paddingLeft), e; | ||
| }, Ct = (t) => { | ||
| }, Nt = (t) => { | ||
| const e = {}; | ||
| return Object.assign(e, Pt(t)), _.absoluteBounds ? e.clipsContent = !1 : e.clipsContent = kt.some((n) => t.overflow.includes(n)), e; | ||
| }, C = (t, e, n, o) => ({ | ||
| }, N = (t, e, n, o) => ({ | ||
| ...H(t, e), | ||
@@ -575,3 +575,3 @@ ...$(e), | ||
| ...y(e, n, o) | ||
| }), Nt = (t) => { | ||
| }), Ct = (t) => { | ||
| switch (t) { | ||
@@ -636,3 +636,3 @@ case "left": | ||
| const o = {}; | ||
| o.characters = t.textContent || "", o.type = "TEXT", o.textAutoResize = (a = e.textAutoResize) != null ? a : "WIDTH_AND_HEIGHT", l(e.fontSize) * 1.14, e.lineHeight.endsWith("px") && l(e.lineHeight), e.isTextWrapped && (o.textAutoResize = "NONE"), o.textAlignHorizontal = Nt(e.textAlign), o.textAlignVertical = Ot(e.verticalAlign), o.textStyles = [{ | ||
| o.characters = t.textContent || "", o.type = "TEXT", o.textAutoResize = (a = e.textAutoResize) != null ? a : "WIDTH_AND_HEIGHT", l(e.fontSize) * 1.14, e.lineHeight.endsWith("px") && l(e.lineHeight), e.isTextWrapped && (o.textAutoResize = "NONE"), o.textAlignHorizontal = Ct(e.textAlign), o.textAlignVertical = Ot(e.verticalAlign), o.textStyles = [{ | ||
| start: 0, | ||
@@ -653,3 +653,3 @@ end: o.characters.length, | ||
| }], e.backgroundColor = e.color; | ||
| const r = C(o.characters || "\u6587\u5B57", e, n, "TEXT"); | ||
| const r = N(o.characters || "\u6587\u5B57", e, n, "TEXT"); | ||
| return Object.assign(o, r), o; | ||
@@ -659,3 +659,3 @@ }, vt = (t, e, n) => { | ||
| return o && e.backgroundImage === "none" && (e.backgroundImage = `url("${o}")`), { | ||
| ...C(t.id || t.tagName, e, n, "RECTANGLE"), | ||
| ...N(t.id || t.tagName, e, n, "RECTANGLE"), | ||
| ...P(e), | ||
@@ -667,7 +667,7 @@ type: "RECTANGLE" | ||
| ...yt(e, n, t.id || t.tagName), | ||
| ...Ct(e) | ||
| ...Nt(e) | ||
| }; | ||
| return o.type = "FRAME", o; | ||
| }, Ht = (t, e, n) => e.display === "none" ? null : { | ||
| ...C(t, e, n, "RECTANGLE"), | ||
| ...N(t, e, n, "RECTANGLE"), | ||
| ...P(e), | ||
@@ -681,3 +681,3 @@ type: "RECTANGLE" | ||
| }, I = {}; | ||
| function A(t, e) { | ||
| function M(t, e) { | ||
| var n; | ||
@@ -692,3 +692,3 @@ return !!((n = Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(t), e)) != null && n.set); | ||
| for (const r of o) | ||
| typeof t[r] != "function" && A(e, r) && (["fills", "strokes"].includes(r) ? e[r] = (await M(t[r])).filter((a) => a.status === "fulfilled").map((a) => a.value) : e[r] = t[r]); | ||
| typeof t[r] != "function" && M(e, r) && (["fills", "strokes"].includes(r) ? e[r] = (await A(t[r])).filter((a) => a.status === "fulfilled").map((a) => a.value) : e[r] = t[r]); | ||
| return await Promise.allSettled(((n = t.children) == null ? void 0 : n.map(async (r) => { | ||
@@ -705,3 +705,3 @@ const a = await zt(r); | ||
| try { | ||
| typeof t[o] != "function" && A(e, o) && (["fills", "strokes"].includes(o) ? e[o] = (await M(t[o])).filter((r) => r.status === "fulfilled").map((r) => r.value) : e[o] = t[o]); | ||
| typeof t[o] != "function" && M(e, o) && (["fills", "strokes"].includes(o) ? e[o] = (await A(t[o])).filter((r) => r.status === "fulfilled").map((r) => r.value) : e[o] = t[o]); | ||
| } catch (r) { | ||
@@ -720,3 +720,3 @@ console.log(`Failed to set ${o} of node ${e == null ? void 0 : e.name}`, r); | ||
| try { | ||
| typeof t[r] != "function" && A(e, r) && (["fills", "strokes"].includes(r) ? e[r] = (await M(t[r])).filter((a) => a.status === "fulfilled").map((a) => a.value) : e[r] = t[r]); | ||
| typeof t[r] != "function" && M(e, r) && (["fills", "strokes"].includes(r) ? e[r] = (await A(t[r])).filter((a) => a.status === "fulfilled").map((a) => a.value) : e[r] = t[r]); | ||
| } catch (a) { | ||
@@ -730,3 +730,3 @@ console.log(`Failed to set ${r} of node ${e == null ? void 0 : e.name}`, a); | ||
| try { | ||
| typeof t[o] != "function" && A(e, o) && (["fills", "strokes"].includes(o) ? e[o] = (await M(t[o])).filter((r) => r.status === "fulfilled").map((r) => r.value) : e[o] = t[o]); | ||
| typeof t[o] != "function" && M(e, o) && (["fills", "strokes"].includes(o) ? e[o] = (await A(t[o])).filter((r) => r.status === "fulfilled").map((r) => r.value) : e[o] = t[o]); | ||
| } catch (r) { | ||
@@ -833,3 +833,3 @@ console.log(`Failed to set ${o} of node ${e == null ? void 0 : e.name}`, r); | ||
| i.children = []; | ||
| let s = Array.from((f = t.childNodes) != null ? f : []); | ||
| let s = t.tagName !== "TEXTAREA" ? Array.from((f = t.childNodes) != null ? f : []) : []; | ||
| s = s.concat(a).concat(r); | ||
@@ -848,3 +848,3 @@ const c = await Promise.allSettled(s.map(async (u) => { | ||
| const p = document.createRange(); | ||
| p.selectNodeContents(u); | ||
| p.selectNode(u); | ||
| const h = p.getBoundingClientRect(), x = at(p); | ||
@@ -851,0 +851,0 @@ p.detach(), g = F(u, { |
+1
-1
@@ -1,1 +0,1 @@ | ||
| (function(x,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(x=typeof globalThis<"u"?globalThis:x||self,m(x.sdk={}))})(this,function(x){"use strict";var m=(t=>(t.PESUDO="PESUDO",t.INPUT="INPUT",t))(m||{});const O=t=>({...getComputedStyle(t)}),V={jpg:"jpeg",jpeg:"jpeg",png:"png",webp:"webp"},K=t=>new Promise((e,n)=>{var o;try{const r=t.imageRef;if(!r||!r.length)throw new Error("url \u9519\u8BEF");const a=r.split("."),i=((o=a[a.length-1].match(/^(jpg|jpeg|png|webp|)*/i))==null?void 0:o[0].toLowerCase())||"png",s=new Image;s.crossOrigin="anonymous",s.onload=()=>{const c=document.createElement("canvas");c.width=s.width,c.height=s.height,c.getContext("2d").drawImage(s,0,0),c.toBlob(function(d){const u=new FileReader;u.addEventListener("loadend",function(){t.bytes=new Uint8Array(this.result),e(t)}),u.addEventListener("error",g=>{console.error("\u8BFB\u53D6\u56FE\u7247\u5931\u8D25",t),n(g)}),u.readAsArrayBuffer(d)},`image/${V[i]}`)},s.onerror=c=>{console.error("\u8F6C\u6362\u56FE\u7247\u5931\u8D25",t),n(c)},s.src=r}catch(r){n(r)}}),Z=t=>{const e=t.imageRef,n=window.atob(e.split(",")[1]),o=n.length,r=new Uint8Array(o);for(let a=0;a<o;a++)r[a]=n.charCodeAt(a);return t.bytes=r,Promise.resolve(t)},J=t=>~t.imageRef.indexOf("data:image")?Z(t):K(t),B=["flexMode","itemSpacing","mainAxisAlignItems","crossAxisAlignItems","mainAxisSizingMode","crossAxisSizingMode","strokesIncludedInLayout","itemReverseZIndex"],Y=(t,e)=>{e.flexMode=t.flexMode;for(const n of B.slice(1))n in t&&(e[n]=t[n])};function q(t){var o;const e=(o=t.parentElement)==null?void 0:o.getBoundingClientRect(),n=t.getBoundingClientRect();return{...n.toJSON(),left:e?n.left-e.left:n.left,top:e?n.top-e.top:n.top}}const Q={100:"Thin",200:"UltraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Heavy",950:"ExtraBlack"},w={thin:["Thin","Hairline"],hairline:["Thin","Hairline"],extralight:["UltraLight","ExtraLight"],ultralight:["UltraLight","ExtraLight"],light:["Light"],regular:["Regular","Normal"],normal:["Regular","Normal"],medium:["Medium"],semibold:["SemiBold","DemiBold"],demibold:["SemiBold","DemiBold"],bold:["Bold"],extrabold:["ExtraBold","UltraBold"],ultrabold:["ExtraBold","UltraBold"],heavy:["Heavy","Black"],black:["Heavy","Black"],extrablack:["ExtraBlack","UltraBlack"],ultrablack:["ExtraBlack","UltraBlack"]},b=t=>t.toLowerCase().replace(/[^a-z]/gi,""),I={},tt={family:"Source Han Sans CN",style:"Regular"},F=async(t,e,n,o)=>{const r=`${b(t)}-${b(e)}`,a=n[r];return a?(await mg.loadFontAsync(a),I[o]=a,a):null};async function et(t,e){const{family:n,style:o}=t,r=`${b(n)}-${b(o)}`;if(I[r])return I[r];const a=n.split(/\s*,\s*/),i=w[b(o)]||[];for(const s of a){for(const u of i){const g=await F(s,u,e,r);if(g)return g}const c=s.match(/(.+)-([a-z]*)$/i),f=c==null?void 0:c[1],d=c==null?void 0:c[2];if(f&&d){const u=w[b(d)]||[];for(const g of u){const p=await F(f,g,e,r);if(p)return p}}}return tt}const nt=(t,e)=>{let n;const{value:o,placeholder:r}=t;if(!o&&!r)return null;o?n=o:n=r;const a=document.createTextNode(n);document.body.append(a);const{paddingLeft:i,paddingRight:s,paddingTop:c,textIndent:f,width:d,height:u}=e,g={...e},p=document.createRange();p.selectNode(a);const h=p.getBoundingClientRect();p.detach(),g.width=`${l(d)-l(i)-l(f)-l(s)}px`,g.height=`${h.height}px`;const E=`${l(g.x)+l(i)+l(f)}px`;let L=`${l(c)}px`;if((t.tagName==="INPUT"||t instanceof HTMLInputElement)&&(L=`${(l(u)-h.height)/2+l(c)}px`),g.x=E,g.y=L,g.left=E,g.top=L,!o){const X=getComputedStyle(t,"::placeholder");g.color=JSON.stringify(X)!==JSON.stringify(e)?X.color:"rgba(0, 0, 0, 0.24)"}return document.body.removeChild(a),{nodeType:m.INPUT,styles:g,node:{textContent:n}}},T=async t=>await Promise.allSettled(t.map(async e=>{switch(e.type){case"IMAGE":{const n=await mg.createImage(e.bytes||new Uint8Array([]));return delete e.bytes,{...e,imageRef:n.href}}}return e})),ot=["::after","::before"],rt=t=>ot.map(e=>{const n=getComputedStyle(t,e);return n.content.trim()==='""'?{nodeType:m.PESUDO,styles:{...n,isPesudo:!0},type:e}:null}).filter(e=>!!e),l=t=>{if(!t)return 0;const e=parseFloat(t);return isNaN(e)?0:e},k=t=>{var r,a;const e={r:0,g:0,b:0,a:1};if(!t)return e;const n=new RegExp(/rgb\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t)||new RegExp(/rgba\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t);if(!n)return e;const o=(r=n[1])==null?void 0:r.split(",");return e.r=parseFloat(o[0])/255,e.g=parseFloat(o[1])/255,e.b=parseFloat(o[2])/255,e.a=parseFloat((a=o[3])!=null?a:1),e},at=t=>{t.sort((e,n)=>e.index-n.index)},it=t=>{var e;return((e=t.getClientRects())==null?void 0:e.length)>1},v=(t,e)=>({name:t,index:l(e.zIndex)}),D=t=>({isVisible:t.visibility!=="hidden",isLocked:!1}),st={normal:"NORMAL",multiply:"MULTIPLY",screen:"SCREEN",overlay:"OVERLAY",darken:"DARKEN",lighten:"LIGHTEN","color-dodge":"COLOR_DODGE","color-burn":"COLOR_BURN","hard-light":"HARD_LIGHT","soft-light":"SOFT_LIGHT",difference:"DIFFERENCE",exclusion:"EXCLUSION",hue:"HUE",saturation:"SATURATION",color:"COLOR",luminosity:"LUMINOSITY","plus-lighter":"PLUS_LIGHTER","plus-darker":"PLUS_DARKER"},ct=t=>st[t]||"NORMAL",lt=t=>{let e=[],n=t.boxShadow;if(n!=="none"){const o=/\s(?![^(]*\))/,r=n.split(o);e=r.reduce((i,s)=>(/.*,$/.test(s)?(i[i.length-1].push(s.substring(0,s.length-1)),i.push([])):i[i.length-1].push(s),i),[[]]).filter(i=>i.length).map(i=>{const s={};s.color=k(i.find(p=>/(rgba|rgb?\(.+?\))/.test(p))||"rgba(0, 0, 0, 0.84)");const c=r.filter(p=>p!=="inset").filter(p=>!/(rgba|rgb?\(.+?\))/.test(p)).map(l),[f,d,u,g]=c;return s.offset={x:f,y:d},s.radius=u,s.spread=g,s.isVisible=!0,s.type=i.includes("inset")?"INNER_SHADOW":"DROP_SHADOW",s.blendMode="NORMAL",s})}return e},ut=t=>{let e=[];const n=t.filter,o=t.filter,r=(a,i)=>{var c;const s={};return s.type=a,s.isVisible=!0,s.blendMode="NORMAL",s.radius=l(((c=i.match(/blur\((.+)\)/))==null?void 0:c[1])||"0"),s};return n==="none"&&/blur\(.+\)/.test(n)&&e.push(r("BACKGROUND_BLUR",n)),o==="none"&&/blur\(.+\)/.test(o)&&e.push(r("LAYER_BLUR",o)),e},ft=t=>{const e=[];return e.push(...lt(t)),e},H=t=>({effects:[...ft(t),...ut(t)],opacity:l(t.opacity),blendMode:ct(t.mixBlendMode),isMask:!1}),S={borderTop:"strokeTopWeight",borderBottom:"strokeBottomWeight",borderLeft:"strokeLeftWeight",borderRight:"strokeRightWeight"},$=t=>({type:"SOLID",isVisible:!0,alpha:1,blendMode:"NORMAL",color:k(t)}),dt={"to top":180,"to bottom":0,"to left":270,"to right":90,"to left top":315,"to left bottom":225,"to right top":45,"to right bottom":135},gt=(t,e,n)=>{if(t===0)return{length:n,handlePositions:[{x:.5,y:0},{x:.5,y:1}]};if(t===90)return{length:n,handlePositions:[{x:0,y:.5},{x:1,y:.5}]};if(t===180)return{length:n,handlePositions:[{x:.5,y:1},{x:.5,y:0}]};if(t===270)return{length:n,handlePositions:[{x:1,y:.5},{x:0,y:.5}]};const o=Math.atan(e/n)*180/Math.PI,r=90-o,a=(c,f,d)=>{let u=.5*f,g=u/Math.cos(c*Math.PI/180);const p=u*Math.tan(c*Math.PI/180),h=.5*d-p;return(Math.sin(c*Math.PI/180)*h+g)*2};let i=n,s=[{x:.5,y:0},{x:.5,y:1}];if(0<t&&t<=o){const c=t;i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+f)/e,s[1].y=1-(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=(.5*n+d)/n}else if(o<t&&t<=90+r){const c=Math.abs(t-90);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+d)/e,s[1].y=(.5*n+f)/n,s[0].x=1-(.5*e+d)/e,s[0].y=1-(.5*n+f)/n}else if(90+r<t&&t<=180+o){const c=Math.abs(180-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;t<180?(s[1].x=(.5*e+f)/e,s[1].y=(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=1-(.5*n+d)/n):(s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n)}else if(180+o<t&&t<=270+r){const c=Math.abs(270-t);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+d)/e,s[0].y=(.5*n+f)/n,s[1].x=1-(.5*e+d)/e,s[1].y=1-(.5*n+f)/n}else if(270+r<t&&t<=360){const c=Math.abs(360-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n}return 180<=t&&t<=270&&s.forEach(c=>{c.y>.5?c.y=c.y-2*(c.y-.5):c.y=c.y+2*(.5-c.y)}),{length:i,handlePositions:s}},pt=(t,e)=>{const n=[...t],o=n[0],r=o.split(new RegExp("(?<!,)(?:\\s)")),a=n[n.length-1],i=a.split(new RegExp("(?<!,)(?:\\s)"));return r.length===1?n[0]=`${o} 0%`:l(r[1])!==0&&n.splice(0,0,`${r[0]} 0%`),i.length===1?n[n.length-1]=`${a} 100%`:(i[1].includes("%")&&l(i[1])!==100||i[1].includes("px")&&l(i[1])<e)&&n.splice(0,n.length-1,`${i[0]} 100%`),n},ht=(t,e)=>t.includes("%")?Math.min(1,l(t)/100):Math.min(1,l(t)/e),mt=(t,e)=>{const n=pt(t,e);let o=0,r=1;const a=[];return n.reduce((i,s,c)=>{const f={color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1},position:0},d=s.split(new RegExp("(?<!,)(?:\\s)"));f.color=k(d[0]);const u=d[1];if(u)f.position=ht(u,e),o=f.position;else{if(!a.length)for(let g=c;g<n.length-1;g++){const p=n[c].split(new RegExp("(?<!,)(?:\\s)"));if(p.length>1){r=l(p[1]);break}else a.push("")}f.position=o+(r-o)/(a.length+1),a.pop()}return i.push(f),i.sort((g,p)=>g.position-p.position)},[])},xt=(t,e)=>{let o=t.match(/.*linear-gradient\((.*)\)\s/i)[1].split(new RegExp("(?<=\\D)(?:,\\s)")),r=0,a=[[1,0,0],[0,1,0]],i=[];if(o[0].match(/to|deg/)){const f=o.splice(0,1)[0];f.includes("to")?r=dt[f]:r=l(f)%360,a=[[Math.cos(r*Math.PI/180),Math.sin(r*Math.PI/180),0],[-Math.sin(r*Math.PI/180),Math.cos(r*Math.PI/180),0]]}const{length:s,handlePositions:c}=gt(r,l(e.width),l(e.height));return i=mt(o,s),{type:"GRADIENT_LINEAR",gradientStops:i,transform:a,gradientHandlePositions:c}},bt=(t,e)=>t.includes("linear-gradient")?xt(t,e):t.includes("conic-gradient")?{type:"GRADIENT_ANGULAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:t.includes("radial-gradient")?{type:"GRADIENT_RADIAL",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:{type:"GRADIENT_LINEAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}],gradientHandlePositions:[{x:.5,y:.5},{x:.5,y:1}]},Et=(t,e,n)=>e==="no-repeat"?"FILL":t==="contain"||n==="contain"?"FIT":t==="cover"||n==="cover"?"STRETCH":"FILL",Tt=t=>{switch(t){case"solid":return"SOLID";case"dashed":return"DASH";default:return"SOLID"}},St=(t,e)=>{var o;const n=[];return(o=e==null?void 0:e.background)!=null&&o.match(/gradient/)?n.push(bt(e.background,e)):t&&n.push($(t)),n},Rt=({backgroundImage:t,backgroundRepeat:e,backgroundSize:n,objectFit:o})=>{let r=null;return t&&t!=="none"&&(r={type:"IMAGE",isVisible:!0,alpha:1,blendMode:"NORMAL",imageRef:t,scaleMode:Et(n,e,o)}),r},Mt=(t,e)=>St(t,e),At=(t,e)=>{const n={},o=t.split(new RegExp("(?<!,)\\s"));return n.strokeWeight=l(o[0]),n.color=o[2],n.side=e,n},Lt=t=>{let e=!1;const n={};if([{value:t.borderTop,side:S.borderTop},{value:t.borderBottom,side:S.borderBottom},{value:t.borderLeft,side:S.borderLeft},{value:t.borderRight,side:S.borderRight}].forEach(a=>{const i=At(a.value,a.side);i.strokeWeight>0&&(e=!0),n[i.color]?n[i.color].push(i):n[i.color]=[i]}),!e)return[];let o=[];const r=Object.entries(n).filter(([a,i])=>i.every(c=>c.strokeWeight===0)?(o.push(...i),!1):!0);return r[0][1].push(...o),r},U=(t,e)=>{const n=t.backgroundImage.split(/(?=url)(?![^(]*\))/).map(a=>{var i;return(i=/url\("(.*)"\)/.exec(a))==null?void 0:i[1]}).filter(a=>!!a),o=[...Mt(e==="TEXT"?t.color:t.backgroundColor,t),...n.map(a=>Rt({backgroundImage:a,backgroundRepeat:t.backgroundRepeat,backgroundSize:t.backgroundSize,objectFit:t.objectFit})).filter(a=>!!a)],r={};if(r.fills=o,e!=="TEXT"){r.strokeWeight=parseFloat(t.borderWidth)||0;const a=Lt(t),i=a.map(s=>{const[c,f]=s,d=$(c);if(a.length>1||f.some(({strokeWeight:u})=>u===0))for(const{strokeWeight:u,side:g}of f)r[g]=u;return d});r.strokes=i,r.strokeStyle=Tt(t.borderStyle),r.strokeAlign=t.boxSizing==="border-box"?"INSIDE":"OUTSIDE",r.strokeCap="NONE",r.strokeJoin="MITER"}return r},R=.01,It=t=>{const e=t.match(/^matrix\((.*)\)$/);if(!e)return null;const[n,o,r,a,i,s]=e[1].split(",").map(c=>Number(c));return{a:n,b:o,c:r,d:a,e:i,f:s}},y=(t,e,n)=>{const o={};if(o.layoutPositioning="ABSOLUTE",o.width=t.width==="auto"?R:Math.max(R,l(t.width)),o.height=t.height==="auto"?R:Math.max(R,l(t.height)),o.x=l(t.x),o.y=l(t.y),t.isPesudo&&(o.x+=l(e.borderLeftWidth||"0px")+l(t.left)+l(t.marginLeft),o.y+=l(e.borderTopWidth||"0px")+l(t.top)+l(t.marginTop)),n!=="TEXT"){const r=It(t.transform);if(r){const{a,b:i,c:s,d:c,e:f,f:d}=r,u=Math.round(Math.atan2(i,a)*(180/Math.PI));u!==0&&(o.rotation=u),o.x+=f,o.y+=d}}return o},M=(t,e)=>{const n=t==null?void 0:t.match(/^(\d+px)/);if(n)return l(n[0]);const o=t==null?void 0:t.match(/^(\d+%)/);if(o){const r=l(o[0]);return parseFloat((e*r/100).toFixed(2))}return 0},P=t=>{const e={};return e.topLeftRadius=M(t.borderTopLeftRadius,l(t.height))||0,e.topRightRadius=M(t.borderTopRightRadius,l(t.height))||0,e.bottomLeftRadius=M(t.borderBottomLeftRadius,l(t.height))||0,e.bottomRightRadius=M(t.borderBottomRightRadius,l(t.height))||0,e},G={absoluteBounds:!1},kt=t=>{Object.assign(G,{...t})},yt=["hidden","scroll","auto","clip","overlay"],Pt=(t,e,n)=>{const o={};return Object.assign(o,y(t,e,"FRAME")),Object.assign(o,v(n,t)),Object.assign(o,D(t)),Object.assign(o,H(t)),Object.assign(o,U(t,"FRAME")),Object.assign(o,P(t)),o},_=t=>{switch(t){case"flex-start":return"FLEX_START";case"flex-end":return"FLEX_END";case"center":return"CENTER";case"space-between":return"SPACING_BETWEEN";default:return"FLEX_START"}},Ct=t=>{const e={};if(["inline-flex",["flex"]].includes(t.display)){const n=t.flexDirection==="row";e.flexMode=n?"HORIZONTAL":"VERTICAL",e.itemSpacing=l(n?t.rowGap:t.columnGap),e.mainAxisAlignItems=_(t.justifyContent),e.crossAxisAlignItems=_(t.alignItems),n?(t.width&&(e.mainAxisSizingMode="FIXED"),t.height&&(e.crossAxisSizingMode="FIXED")):(t.width&&(e.crossAxisSizingMode="FIXED"),t.height&&(e.mainAxisSizingMode="FIXED"))}else if(l(t.paddingTop)||l(t.paddingBottom)||l(t.paddingLeft)||l(t.paddingRight))e.flexMode="VERTICAL";else return e;return e.paddingTop=l(t.paddingTop),e.paddingRight=l(t.paddingRight),e.paddingBottom=l(t.paddingBottom),e.paddingLeft=l(t.paddingLeft),e},Nt=t=>{const e={};return Object.assign(e,Ct(t)),G.absoluteBounds?e.clipsContent=!1:e.clipsContent=yt.some(n=>t.overflow.includes(n)),e},C=(t,e,n,o)=>({...v(t,e),...D(e),...H(e),...U(e,o),...y(e,n,o)}),Ot=t=>{switch(t){case"left":return"LEFT";case"center":return"CENTER";case"right":return"RIGHT";case"justify":return"JUSTIFIED";default:return"LEFT"}};function Bt(t){switch(t){case"middle":return"CENTER";case"bottom":return"BOTTOM";default:return"TOP"}}function wt(t){switch(t){case"underline":return"UNDERLINE";case"line-through":return"STRIKETHROUGH";case"node":default:return"NONE"}}const Ft=(t,e)=>{const n=Q[e];let o="Regular";switch(t){case"italic":o="Italic";case"oblique":o="Italic";default:o="Regular"}return o==="Italic"?`${n} ${o}`:n};function vt(t){if(t.boxSizing==="border-box"){let e=t.lineHeight==="normal"?l(t.fontSize)*1.14:l(t.lineHeight);return Math.min(l(t.height),e+l(t.borderTopWidth)+l(t.borderBottomWidth))}else return l(t.lineHeight)}const W=(t,e,n)=>{var a;if(!t.textContent||e.display==="none")return null;const o={};o.characters=t.textContent||"",o.type="TEXT",o.textAutoResize=(a=e.textAutoResize)!=null?a:"WIDTH_AND_HEIGHT",l(e.fontSize)*1.14,e.lineHeight.endsWith("px")&&l(e.lineHeight),e.isTextWrapped&&(o.textAutoResize="NONE"),o.textAlignHorizontal=Ot(e.textAlign),o.textAlignVertical=Bt(e.verticalAlign),o.textStyles=[{start:0,end:o.characters.length,textStyle:{lineHeight:{unit:"PIXELS",value:vt(e)},fontSize:l(e.fontSize),fontName:{family:e.fontFamily,style:Ft(e.fontStyle,e.fontWeight)},textDecoration:wt(e.textDecorationLine)}}],e.backgroundColor=e.color;const r=C(o.characters||"\u6587\u5B57",e,n,"TEXT");return Object.assign(o,r),o},Dt=(t,e,n)=>{const o=t.getAttribute("src");return o&&e.backgroundImage==="none"&&(e.backgroundImage=`url("${o}")`),{...C(t.id||t.tagName,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"}},Ht=(t,e,n)=>{const o={...Pt(e,n,t.id||t.tagName),...Nt(e)};return o.type="FRAME",o},$t=(t,e,n)=>e.display==="none"?null:{...C(t,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"},Ut=(t,e,n)=>{const o={},r=e.fill,a=e.stroke,i=e.color;t.style.fill.toLowerCase()==="currentcolor"&&(t.style.fill=/rgba|rgb/.test(r)?r:i),t.style.stroke.toLowerCase()==="currentcolor"&&(t.style.stroke=/rgba|rgb/.test(a)?a:i),o.type="PEN";let s=t.outerHTML;return s=s.replace(/(fill="currentColor"|fill="")/i,`fill="${/rgba|rgb/.test(r)?r:i}"`),s=s.replace(/(stroke="currentColor"|stroke="")/i,`stroke="${/rgba|rgb/.test(a)?a:i}"`),o.content=s,Object.assign(o,y(e,n,"PEN")),o},N={};function A(t,e){var n;return!!((n=Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(t),e))!=null&&n.set)}const Gt=async(t,e)=>{var n;try{const o=Object.keys(t).filter(r=>!B.includes(r));t.flexMode&&t.flexMode!=="NONE"&&Y(t,e);for(const r of o)typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await T(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r]);return await Promise.allSettled(((n=t.children)==null?void 0:n.map(async r=>{const a=await zt(r);return a&&(e.appendChild(a),await j(r,a)),!0}))||[]),e}catch(o){return console.error("\u53D1\u751F\u9519\u8BEF,",o),null}},_t=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await T(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e},Wt=async(t,e)=>{var o;const n=Object.keys(t);(o=t.textStyles)==null||o.forEach(async r=>{const a=r.textStyle.fontName,i=await et(a,N);e.setRangeFontName(r.start,r.end,i),e.setRangeLineHeight(r.start,r.end,r.textStyle.lineHeight),e.setRangeFontSize(r.start,r.end,r.textStyle.fontSize)}),delete t.textStyles;for(const r of n)try{typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await T(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r])}catch(a){console.log(`Failed to set ${r} of node ${e==null?void 0:e.name}`,a)}return e},jt=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await T(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e};async function zt(t){if(!t)return null;switch(t==null?void 0:t.type){case"FRAME":return mg.createFrame();case"RECTANGLE":return mg.createRectangle();case"TEXT":return mg.createText();case"PEN":return await mg.createNodeFromSvgAsync(t.content)}return null}const j=async(t,e)=>{if(!t||!e)return null;let n={};const o=t.rotation;switch(delete t.rotation,t==null?void 0:t.type){case"FRAME":{n=await Gt(t,e);break}case"RECTANGLE":{n=await _t(t,e);break}case"TEXT":{n=await Wt(t,e);break}case"PEN":{n=await jt(t,e);break}default:throw new Error("failed to convert, layer has unknown type.")}return requestAnimationFrame(()=>{o&&n&&(n.rotation=o)}),n},Xt=async t=>{if(!mg)throw new Error("Please invoke this function at plugin environment");return Object.keys(N).length||(await mg.listAvailableFontsAsync()).forEach(n=>{const{family:o,style:r}=n.fontName;N[`${b(o)}-${b(r)}`]=n.fontName}),await j(t,mg.createFrame())},Vt=async t=>{const e=[],n=o=>{var r;if(!o)return null;try{const a=Object.keys(o);for(const i of a)if(["fills","strokes"].includes(i)){const s=o[i];s==null||s.forEach(c=>{c.type==="IMAGE"&&e.push(J(c))})}else if(i==="children"&&((r=o.children)==null?void 0:r.length))for(const s of o.children)n(s)}catch(a){console.error("error occured in secondary operation",a)}};return n(t),await Promise.allSettled(e),t},z=async(t,e,n)=>{var f,d;if(e.display==="none")return null;e.transform!=="none"&&(t.style.transform="unset",t.style.transition="unset",await new Promise(u=>{setTimeout(()=>{u(1)},100)}));const o=q(t);if(e.width==="auto"||e.height==="auto"){const u=document.createRange();u.selectNode(t);const g=u.getBoundingClientRect();e.width=`${g.width}px`,e.height=`${g.height}px`,u.detach()}if(e.x=`${o.left}px`,e.y=`${o.top}px`,e.width=`${o.width}px`,e.height=`${o.height}px`,t.tagName==="svg")return Ut(t,e,n);let r=null;(["TEXTAREA","INPUT"].includes(t.tagName)||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)&&(r=nt(t,e));const a=rt(t);if(!t.hasChildNodes()&&a.length===0&&!r)return Dt(t,e,n);const i=Ht(t,e,n);i.children=[];let s=Array.from((f=t.childNodes)!=null?f:[]);s=s.concat(a).concat(r);const c=await Promise.allSettled(s.map(async u=>{let g;if(!u)return null;if(u.nodeType===Node.ELEMENT_NODE){const p=O(u);g=await z(u,{...p},e)}if(u.nodeType===Node.TEXT_NODE){const p=document.createRange();p.selectNodeContents(u);const h=p.getBoundingClientRect(),E=it(p);p.detach(),g=W(u,{...e,isTextWrapped:E,width:`${h.width}px`,height:`${h.height}px`,x:`${h.x-o.x}px`,y:`${h.y-o.y}px`,left:`${h.left}px`,right:`${h.right}px`,top:`${h.top}px`,bottom:`${h.bottom}px`},e)}else u.nodeType===m.PESUDO?g=$t(u.type,u.styles,e):u.nodeType===m.INPUT&&(g=W(u.node,u.styles,u.styles));return g}));return i.children=c.filter(u=>(u==null?void 0:u.status)==="fulfilled"&&!!(u!=null&&u.value)).map(u=>u.value),(d=i.children)!=null&&d.length&&at(i.children),e.transform!=="none"&&(t.style.transform="",t.style.transition=""),i},Kt=async(t,e)=>{if(e&&kt(e),!getComputedStyle)throw new Error("getComputedStyle is not defined");try{const n=await z(t,O(t),null);return console.log("\u8F6C\u6362\u7ED3\u679C",n),n}catch(n){console.error("\u8F6C\u6362\u51FA\u9519",n)}return null};x.htmlToMG=Kt,x.postProcess=Vt,x.renderToMasterGo=Xt,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
| (function(x,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(x=typeof globalThis<"u"?globalThis:x||self,m(x.sdk={}))})(this,function(x){"use strict";var m=(t=>(t.PESUDO="PESUDO",t.INPUT="INPUT",t))(m||{});const O=t=>({...getComputedStyle(t)}),V={jpg:"jpeg",jpeg:"jpeg",png:"png",webp:"webp"},K=t=>new Promise((e,n)=>{var o;try{const r=t.imageRef;if(!r||!r.length)throw new Error("url \u9519\u8BEF");const a=r.split("."),i=((o=a[a.length-1].match(/^(jpg|jpeg|png|webp|)*/i))==null?void 0:o[0].toLowerCase())||"png",s=new Image;s.crossOrigin="anonymous",s.onload=()=>{const c=document.createElement("canvas");c.width=s.width,c.height=s.height,c.getContext("2d").drawImage(s,0,0),c.toBlob(function(d){const u=new FileReader;u.addEventListener("loadend",function(){t.bytes=new Uint8Array(this.result),e(t)}),u.addEventListener("error",g=>{console.error("\u8BFB\u53D6\u56FE\u7247\u5931\u8D25",t),n(g)}),u.readAsArrayBuffer(d)},`image/${V[i]}`)},s.onerror=c=>{console.error("\u8F6C\u6362\u56FE\u7247\u5931\u8D25",t),n(c)},s.src=r}catch(r){n(r)}}),Z=t=>{const e=t.imageRef,n=window.atob(e.split(",")[1]),o=n.length,r=new Uint8Array(o);for(let a=0;a<o;a++)r[a]=n.charCodeAt(a);return t.bytes=r,Promise.resolve(t)},J=t=>~t.imageRef.indexOf("data:image")?Z(t):K(t),B=["flexMode","itemSpacing","mainAxisAlignItems","crossAxisAlignItems","mainAxisSizingMode","crossAxisSizingMode","strokesIncludedInLayout","itemReverseZIndex"],Y=(t,e)=>{e.flexMode=t.flexMode;for(const n of B.slice(1))n in t&&(e[n]=t[n])};function q(t){var o;const e=(o=t.parentElement)==null?void 0:o.getBoundingClientRect(),n=t.getBoundingClientRect();return{...n.toJSON(),left:e?n.left-e.left:n.left,top:e?n.top-e.top:n.top}}const Q={100:"Thin",200:"UltraLight",300:"Light",400:"Regular",500:"Medium",600:"SemiBold",700:"Bold",800:"ExtraBold",900:"Heavy",950:"ExtraBlack"},w={thin:["Thin","Hairline"],hairline:["Thin","Hairline"],extralight:["UltraLight","ExtraLight"],ultralight:["UltraLight","ExtraLight"],light:["Light"],regular:["Regular","Normal"],normal:["Regular","Normal"],medium:["Medium"],semibold:["SemiBold","DemiBold"],demibold:["SemiBold","DemiBold"],bold:["Bold"],extrabold:["ExtraBold","UltraBold"],ultrabold:["ExtraBold","UltraBold"],heavy:["Heavy","Black"],black:["Heavy","Black"],extrablack:["ExtraBlack","UltraBlack"],ultrablack:["ExtraBlack","UltraBlack"]},b=t=>t.toLowerCase().replace(/[^a-z]/gi,""),I={},tt={family:"Source Han Sans CN",style:"Regular"},F=async(t,e,n,o)=>{const r=`${b(t)}-${b(e)}`,a=n[r];return a?(await mg.loadFontAsync(a),I[o]=a,a):null};async function et(t,e){const{family:n,style:o}=t,r=`${b(n)}-${b(o)}`;if(I[r])return I[r];const a=n.split(/\s*,\s*/),i=w[b(o)]||[];for(const s of a){for(const u of i){const g=await F(s,u,e,r);if(g)return g}const c=s.match(/(.+)-([a-z]*)$/i),f=c==null?void 0:c[1],d=c==null?void 0:c[2];if(f&&d){const u=w[b(d)]||[];for(const g of u){const p=await F(f,g,e,r);if(p)return p}}}return tt}const nt=(t,e)=>{let n;const{value:o,placeholder:r}=t;if(!o&&!r)return null;o?n=o:n=r;const a=document.createTextNode(n);document.body.append(a);const{paddingLeft:i,paddingRight:s,paddingTop:c,textIndent:f,width:d,height:u}=e,g={...e},p=document.createRange();p.selectNode(a);const h=p.getBoundingClientRect();p.detach(),g.width=`${l(d)-l(i)-l(f)-l(s)}px`,g.height=`${h.height}px`;const E=`${l(i)+l(f)}px`;let L=`${l(c)}px`;if((t.tagName==="INPUT"||t instanceof HTMLInputElement)&&(L=`${(l(u)-h.height)/2+l(c)}px`),g.x=E,g.y=L,g.left=E,g.top=L,!o){const X=getComputedStyle(t,"::placeholder");g.color=JSON.stringify(X)!==JSON.stringify(e)?X.color:"rgba(0, 0, 0, 0.24)"}return document.body.removeChild(a),{nodeType:m.INPUT,styles:g,node:{textContent:n}}},T=async t=>await Promise.allSettled(t.map(async e=>{switch(e.type){case"IMAGE":{const n=await mg.createImage(e.bytes||new Uint8Array([]));return delete e.bytes,{...e,imageRef:n.href}}}return e})),ot=["::after","::before"],rt=t=>ot.map(e=>{const n=getComputedStyle(t,e);return n.content.trim()==='""'?{nodeType:m.PESUDO,styles:{...n,isPesudo:!0},type:e}:null}).filter(e=>!!e),l=t=>{if(!t)return 0;const e=parseFloat(t);return isNaN(e)?0:e},k=t=>{var r,a;const e={r:0,g:0,b:0,a:1};if(!t)return e;const n=new RegExp(/rgb\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t)||new RegExp(/rgba\((\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*,\s*\d*\.?\d+\s*)\)/).exec(t);if(!n)return e;const o=(r=n[1])==null?void 0:r.split(",");return e.r=parseFloat(o[0])/255,e.g=parseFloat(o[1])/255,e.b=parseFloat(o[2])/255,e.a=parseFloat((a=o[3])!=null?a:1),e},at=t=>{t.sort((e,n)=>e.index-n.index)},it=t=>{var e;return((e=t.getClientRects())==null?void 0:e.length)>1},v=(t,e)=>({name:t,index:l(e.zIndex)}),D=t=>({isVisible:t.visibility!=="hidden",isLocked:!1}),st={normal:"NORMAL",multiply:"MULTIPLY",screen:"SCREEN",overlay:"OVERLAY",darken:"DARKEN",lighten:"LIGHTEN","color-dodge":"COLOR_DODGE","color-burn":"COLOR_BURN","hard-light":"HARD_LIGHT","soft-light":"SOFT_LIGHT",difference:"DIFFERENCE",exclusion:"EXCLUSION",hue:"HUE",saturation:"SATURATION",color:"COLOR",luminosity:"LUMINOSITY","plus-lighter":"PLUS_LIGHTER","plus-darker":"PLUS_DARKER"},ct=t=>st[t]||"NORMAL",lt=t=>{let e=[],n=t.boxShadow;if(n!=="none"){const o=/\s(?![^(]*\))/,r=n.split(o);e=r.reduce((i,s)=>(/.*,$/.test(s)?(i[i.length-1].push(s.substring(0,s.length-1)),i.push([])):i[i.length-1].push(s),i),[[]]).filter(i=>i.length).map(i=>{const s={};s.color=k(i.find(p=>/(rgba|rgb?\(.+?\))/.test(p))||"rgba(0, 0, 0, 0.84)");const c=r.filter(p=>p!=="inset").filter(p=>!/(rgba|rgb?\(.+?\))/.test(p)).map(l),[f,d,u,g]=c;return s.offset={x:f,y:d},s.radius=u,s.spread=g,s.isVisible=!0,s.type=i.includes("inset")?"INNER_SHADOW":"DROP_SHADOW",s.blendMode="NORMAL",s})}return e},ut=t=>{let e=[];const n=t.filter,o=t.filter,r=(a,i)=>{var c;const s={};return s.type=a,s.isVisible=!0,s.blendMode="NORMAL",s.radius=l(((c=i.match(/blur\((.+)\)/))==null?void 0:c[1])||"0"),s};return n==="none"&&/blur\(.+\)/.test(n)&&e.push(r("BACKGROUND_BLUR",n)),o==="none"&&/blur\(.+\)/.test(o)&&e.push(r("LAYER_BLUR",o)),e},ft=t=>{const e=[];return e.push(...lt(t)),e},H=t=>({effects:[...ft(t),...ut(t)],opacity:l(t.opacity)||1,blendMode:ct(t.mixBlendMode),isMask:!1}),S={borderTop:"strokeTopWeight",borderBottom:"strokeBottomWeight",borderLeft:"strokeLeftWeight",borderRight:"strokeRightWeight"},$=t=>({type:"SOLID",isVisible:!0,alpha:1,blendMode:"NORMAL",color:k(t)}),dt={"to top":180,"to bottom":0,"to left":270,"to right":90,"to left top":315,"to left bottom":225,"to right top":45,"to right bottom":135},gt=(t,e,n)=>{if(t===0)return{length:n,handlePositions:[{x:.5,y:0},{x:.5,y:1}]};if(t===90)return{length:n,handlePositions:[{x:0,y:.5},{x:1,y:.5}]};if(t===180)return{length:n,handlePositions:[{x:.5,y:1},{x:.5,y:0}]};if(t===270)return{length:n,handlePositions:[{x:1,y:.5},{x:0,y:.5}]};const o=Math.atan(e/n)*180/Math.PI,r=90-o,a=(c,f,d)=>{let u=.5*f,g=u/Math.cos(c*Math.PI/180);const p=u*Math.tan(c*Math.PI/180),h=.5*d-p;return(Math.sin(c*Math.PI/180)*h+g)*2};let i=n,s=[{x:.5,y:0},{x:.5,y:1}];if(0<t&&t<=o){const c=t;i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+f)/e,s[1].y=1-(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=(.5*n+d)/n}else if(o<t&&t<=90+r){const c=Math.abs(t-90);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[1].x=(.5*e+d)/e,s[1].y=(.5*n+f)/n,s[0].x=1-(.5*e+d)/e,s[0].y=1-(.5*n+f)/n}else if(90+r<t&&t<=180+o){const c=Math.abs(180-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;t<180?(s[1].x=(.5*e+f)/e,s[1].y=(.5*n+d)/n,s[0].x=1-(.5*e+f)/e,s[0].y=1-(.5*n+d)/n):(s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n)}else if(180+o<t&&t<=270+r){const c=Math.abs(270-t);i=a(c,e,n);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+d)/e,s[0].y=(.5*n+f)/n,s[1].x=1-(.5*e+d)/e,s[1].y=1-(.5*n+f)/n}else if(270+r<t&&t<=360){const c=Math.abs(360-t);i=a(c,n,e);const f=Math.sin(c*Math.PI/180)*i/2,d=Math.cos(c*Math.PI/180)*i/2;s[0].x=(.5*e+f)/e,s[0].y=(.5*n+d)/n,s[1].x=1-(.5*e+f)/e,s[1].y=1-(.5*n+d)/n}return 180<=t&&t<=270&&s.forEach(c=>{c.y>.5?c.y=c.y-2*(c.y-.5):c.y=c.y+2*(.5-c.y)}),{length:i,handlePositions:s}},pt=(t,e)=>{const n=[...t],o=n[0],r=o.split(new RegExp("(?<!,)(?:\\s)")),a=n[n.length-1],i=a.split(new RegExp("(?<!,)(?:\\s)"));return r.length===1?n[0]=`${o} 0%`:l(r[1])!==0&&n.splice(0,0,`${r[0]} 0%`),i.length===1?n[n.length-1]=`${a} 100%`:(i[1].includes("%")&&l(i[1])!==100||i[1].includes("px")&&l(i[1])<e)&&n.splice(0,n.length-1,`${i[0]} 100%`),n},ht=(t,e)=>t.includes("%")?Math.min(1,l(t)/100):Math.min(1,l(t)/e),mt=(t,e)=>{const n=pt(t,e);let o=0,r=1;const a=[];return n.reduce((i,s,c)=>{const f={color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1},position:0},d=s.split(new RegExp("(?<!,)(?:\\s)"));f.color=k(d[0]);const u=d[1];if(u)f.position=ht(u,e),o=f.position;else{if(!a.length)for(let g=c;g<n.length-1;g++){const p=n[c].split(new RegExp("(?<!,)(?:\\s)"));if(p.length>1){r=l(p[1]);break}else a.push("")}f.position=o+(r-o)/(a.length+1),a.pop()}return i.push(f),i.sort((g,p)=>g.position-p.position)},[])},xt=(t,e)=>{let o=t.match(/.*linear-gradient\((.*)\)\s/i)[1].split(new RegExp("(?<=\\D)(?:,\\s)")),r=0,a=[[1,0,0],[0,1,0]],i=[];if(o[0].match(/to|deg/)){const f=o.splice(0,1)[0];f.includes("to")?r=dt[f]:r=l(f)%360,a=[[Math.cos(r*Math.PI/180),Math.sin(r*Math.PI/180),0],[-Math.sin(r*Math.PI/180),Math.cos(r*Math.PI/180),0]]}const{length:s,handlePositions:c}=gt(r,l(e.width),l(e.height));return i=mt(o,s),{type:"GRADIENT_LINEAR",gradientStops:i,transform:a,gradientHandlePositions:c}},bt=(t,e)=>t.includes("linear-gradient")?xt(t,e):t.includes("conic-gradient")?{type:"GRADIENT_ANGULAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:t.includes("radial-gradient")?{type:"GRADIENT_RADIAL",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}]}:{type:"GRADIENT_LINEAR",transform:[[1,0,0],[0,1,0]],gradientStops:[{position:0,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:1}},{position:1,color:{r:.8470588326454163,g:.8470588326454163,b:.8470588326454163,a:0}}],gradientHandlePositions:[{x:.5,y:.5},{x:.5,y:1}]},Et=(t,e,n)=>e==="no-repeat"?"FILL":t==="contain"||n==="contain"?"FIT":t==="cover"||n==="cover"?"STRETCH":"FILL",Tt=t=>{switch(t){case"solid":return"SOLID";case"dashed":return"DASH";default:return"SOLID"}},St=(t,e)=>{var o;const n=[];return(o=e==null?void 0:e.background)!=null&&o.match(/gradient/)?n.push(bt(e.background,e)):t&&n.push($(t)),n},Rt=({backgroundImage:t,backgroundRepeat:e,backgroundSize:n,objectFit:o})=>{let r=null;return t&&t!=="none"&&(r={type:"IMAGE",isVisible:!0,alpha:1,blendMode:"NORMAL",imageRef:t,scaleMode:Et(n,e,o)}),r},Mt=(t,e)=>St(t,e),At=(t,e)=>{const n={},o=t.split(new RegExp("(?<!,)\\s"));return n.strokeWeight=l(o[0]),n.color=o[2],n.side=e,n},Lt=t=>{let e=!1;const n={};if([{value:t.borderTop,side:S.borderTop},{value:t.borderBottom,side:S.borderBottom},{value:t.borderLeft,side:S.borderLeft},{value:t.borderRight,side:S.borderRight}].forEach(a=>{const i=At(a.value,a.side);i.strokeWeight>0&&(e=!0),n[i.color]?n[i.color].push(i):n[i.color]=[i]}),!e)return[];let o=[];const r=Object.entries(n).filter(([a,i])=>i.every(c=>c.strokeWeight===0)?(o.push(...i),!1):!0);return r[0][1].push(...o),r},U=(t,e)=>{const n=t.backgroundImage.split(/(?=url)(?![^(]*\))/).map(a=>{var i;return(i=/url\("(.*)"\)/.exec(a))==null?void 0:i[1]}).filter(a=>!!a),o=[...Mt(e==="TEXT"?t.color:t.backgroundColor,t),...n.map(a=>Rt({backgroundImage:a,backgroundRepeat:t.backgroundRepeat,backgroundSize:t.backgroundSize,objectFit:t.objectFit})).filter(a=>!!a)],r={};if(r.fills=o,e!=="TEXT"){r.strokeWeight=parseFloat(t.borderWidth)||0;const a=Lt(t),i=a.map(s=>{const[c,f]=s,d=$(c);if(a.length>1||f.some(({strokeWeight:u})=>u===0))for(const{strokeWeight:u,side:g}of f)r[g]=u;return d});r.strokes=i,r.strokeStyle=Tt(t.borderStyle),r.strokeAlign=t.boxSizing==="border-box"?"INSIDE":"OUTSIDE",r.strokeCap="NONE",r.strokeJoin="MITER"}return r},R=.01,It=t=>{const e=t.match(/^matrix\((.*)\)$/);if(!e)return null;const[n,o,r,a,i,s]=e[1].split(",").map(c=>Number(c));return{a:n,b:o,c:r,d:a,e:i,f:s}},y=(t,e,n)=>{const o={};if(o.layoutPositioning="ABSOLUTE",o.width=t.width==="auto"?R:Math.max(R,l(t.width)),o.height=t.height==="auto"?R:Math.max(R,l(t.height)),o.x=l(t.x),o.y=l(t.y),t.isPesudo&&(o.x+=l(e.borderLeftWidth||"0px")+l(t.left)+l(t.marginLeft),o.y+=l(e.borderTopWidth||"0px")+l(t.top)+l(t.marginTop)),n!=="TEXT"){const r=It(t.transform);if(r){const{a,b:i,c:s,d:c,e:f,f:d}=r,u=Math.round(Math.atan2(i,a)*(180/Math.PI));u!==0&&(o.rotation=u),o.x+=f,o.y+=d}}return o},M=(t,e)=>{const n=t==null?void 0:t.match(/^(\d+px)/);if(n)return l(n[0]);const o=t==null?void 0:t.match(/^(\d+%)/);if(o){const r=l(o[0]);return parseFloat((e*r/100).toFixed(2))}return 0},P=t=>{const e={};return e.topLeftRadius=M(t.borderTopLeftRadius,l(t.height))||0,e.topRightRadius=M(t.borderTopRightRadius,l(t.height))||0,e.bottomLeftRadius=M(t.borderBottomLeftRadius,l(t.height))||0,e.bottomRightRadius=M(t.borderBottomRightRadius,l(t.height))||0,e},G={absoluteBounds:!1},kt=t=>{Object.assign(G,{...t})},yt=["hidden","scroll","auto","clip","overlay"],Pt=(t,e,n)=>{const o={};return Object.assign(o,y(t,e,"FRAME")),Object.assign(o,v(n,t)),Object.assign(o,D(t)),Object.assign(o,H(t)),Object.assign(o,U(t,"FRAME")),Object.assign(o,P(t)),o},_=t=>{switch(t){case"flex-start":return"FLEX_START";case"flex-end":return"FLEX_END";case"center":return"CENTER";case"space-between":return"SPACING_BETWEEN";default:return"FLEX_START"}},Nt=t=>{const e={};if(["inline-flex",["flex"]].includes(t.display)){const n=t.flexDirection==="row";e.flexMode=n?"HORIZONTAL":"VERTICAL",e.itemSpacing=l(n?t.rowGap:t.columnGap),e.mainAxisAlignItems=_(t.justifyContent),e.crossAxisAlignItems=_(t.alignItems),n?(t.width&&(e.mainAxisSizingMode="FIXED"),t.height&&(e.crossAxisSizingMode="FIXED")):(t.width&&(e.crossAxisSizingMode="FIXED"),t.height&&(e.mainAxisSizingMode="FIXED"))}else if(l(t.paddingTop)||l(t.paddingBottom)||l(t.paddingLeft)||l(t.paddingRight))e.flexMode="VERTICAL";else return e;return e.paddingTop=l(t.paddingTop),e.paddingRight=l(t.paddingRight),e.paddingBottom=l(t.paddingBottom),e.paddingLeft=l(t.paddingLeft),e},Ct=t=>{const e={};return Object.assign(e,Nt(t)),G.absoluteBounds?e.clipsContent=!1:e.clipsContent=yt.some(n=>t.overflow.includes(n)),e},N=(t,e,n,o)=>({...v(t,e),...D(e),...H(e),...U(e,o),...y(e,n,o)}),Ot=t=>{switch(t){case"left":return"LEFT";case"center":return"CENTER";case"right":return"RIGHT";case"justify":return"JUSTIFIED";default:return"LEFT"}};function Bt(t){switch(t){case"middle":return"CENTER";case"bottom":return"BOTTOM";default:return"TOP"}}function wt(t){switch(t){case"underline":return"UNDERLINE";case"line-through":return"STRIKETHROUGH";case"node":default:return"NONE"}}const Ft=(t,e)=>{const n=Q[e];let o="Regular";switch(t){case"italic":o="Italic";case"oblique":o="Italic";default:o="Regular"}return o==="Italic"?`${n} ${o}`:n};function vt(t){if(t.boxSizing==="border-box"){let e=t.lineHeight==="normal"?l(t.fontSize)*1.14:l(t.lineHeight);return Math.min(l(t.height),e+l(t.borderTopWidth)+l(t.borderBottomWidth))}else return l(t.lineHeight)}const W=(t,e,n)=>{var a;if(!t.textContent||e.display==="none")return null;const o={};o.characters=t.textContent||"",o.type="TEXT",o.textAutoResize=(a=e.textAutoResize)!=null?a:"WIDTH_AND_HEIGHT",l(e.fontSize)*1.14,e.lineHeight.endsWith("px")&&l(e.lineHeight),e.isTextWrapped&&(o.textAutoResize="NONE"),o.textAlignHorizontal=Ot(e.textAlign),o.textAlignVertical=Bt(e.verticalAlign),o.textStyles=[{start:0,end:o.characters.length,textStyle:{lineHeight:{unit:"PIXELS",value:vt(e)},fontSize:l(e.fontSize),fontName:{family:e.fontFamily,style:Ft(e.fontStyle,e.fontWeight)},textDecoration:wt(e.textDecorationLine)}}],e.backgroundColor=e.color;const r=N(o.characters||"\u6587\u5B57",e,n,"TEXT");return Object.assign(o,r),o},Dt=(t,e,n)=>{const o=t.getAttribute("src");return o&&e.backgroundImage==="none"&&(e.backgroundImage=`url("${o}")`),{...N(t.id||t.tagName,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"}},Ht=(t,e,n)=>{const o={...Pt(e,n,t.id||t.tagName),...Ct(e)};return o.type="FRAME",o},$t=(t,e,n)=>e.display==="none"?null:{...N(t,e,n,"RECTANGLE"),...P(e),type:"RECTANGLE"},Ut=(t,e,n)=>{const o={},r=e.fill,a=e.stroke,i=e.color;t.style.fill.toLowerCase()==="currentcolor"&&(t.style.fill=/rgba|rgb/.test(r)?r:i),t.style.stroke.toLowerCase()==="currentcolor"&&(t.style.stroke=/rgba|rgb/.test(a)?a:i),o.type="PEN";let s=t.outerHTML;return s=s.replace(/(fill="currentColor"|fill="")/i,`fill="${/rgba|rgb/.test(r)?r:i}"`),s=s.replace(/(stroke="currentColor"|stroke="")/i,`stroke="${/rgba|rgb/.test(a)?a:i}"`),o.content=s,Object.assign(o,y(e,n,"PEN")),o},C={};function A(t,e){var n;return!!((n=Reflect.getOwnPropertyDescriptor(Object.getPrototypeOf(t),e))!=null&&n.set)}const Gt=async(t,e)=>{var n;try{const o=Object.keys(t).filter(r=>!B.includes(r));t.flexMode&&t.flexMode!=="NONE"&&Y(t,e);for(const r of o)typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await T(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r]);return await Promise.allSettled(((n=t.children)==null?void 0:n.map(async r=>{const a=await zt(r);return a&&(e.appendChild(a),await j(r,a)),!0}))||[]),e}catch(o){return console.error("\u53D1\u751F\u9519\u8BEF,",o),null}},_t=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await T(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e},Wt=async(t,e)=>{var o;const n=Object.keys(t);(o=t.textStyles)==null||o.forEach(async r=>{const a=r.textStyle.fontName,i=await et(a,C);e.setRangeFontName(r.start,r.end,i),e.setRangeLineHeight(r.start,r.end,r.textStyle.lineHeight),e.setRangeFontSize(r.start,r.end,r.textStyle.fontSize)}),delete t.textStyles;for(const r of n)try{typeof t[r]!="function"&&A(e,r)&&(["fills","strokes"].includes(r)?e[r]=(await T(t[r])).filter(a=>a.status==="fulfilled").map(a=>a.value):e[r]=t[r])}catch(a){console.log(`Failed to set ${r} of node ${e==null?void 0:e.name}`,a)}return e},jt=async(t,e)=>{const n=Object.keys(t);for(const o of n)try{typeof t[o]!="function"&&A(e,o)&&(["fills","strokes"].includes(o)?e[o]=(await T(t[o])).filter(r=>r.status==="fulfilled").map(r=>r.value):e[o]=t[o])}catch(r){console.log(`Failed to set ${o} of node ${e==null?void 0:e.name}`,r)}return e};async function zt(t){if(!t)return null;switch(t==null?void 0:t.type){case"FRAME":return mg.createFrame();case"RECTANGLE":return mg.createRectangle();case"TEXT":return mg.createText();case"PEN":return await mg.createNodeFromSvgAsync(t.content)}return null}const j=async(t,e)=>{if(!t||!e)return null;let n={};const o=t.rotation;switch(delete t.rotation,t==null?void 0:t.type){case"FRAME":{n=await Gt(t,e);break}case"RECTANGLE":{n=await _t(t,e);break}case"TEXT":{n=await Wt(t,e);break}case"PEN":{n=await jt(t,e);break}default:throw new Error("failed to convert, layer has unknown type.")}return requestAnimationFrame(()=>{o&&n&&(n.rotation=o)}),n},Xt=async t=>{if(!mg)throw new Error("Please invoke this function at plugin environment");return Object.keys(C).length||(await mg.listAvailableFontsAsync()).forEach(n=>{const{family:o,style:r}=n.fontName;C[`${b(o)}-${b(r)}`]=n.fontName}),await j(t,mg.createFrame())},Vt=async t=>{const e=[],n=o=>{var r;if(!o)return null;try{const a=Object.keys(o);for(const i of a)if(["fills","strokes"].includes(i)){const s=o[i];s==null||s.forEach(c=>{c.type==="IMAGE"&&e.push(J(c))})}else if(i==="children"&&((r=o.children)==null?void 0:r.length))for(const s of o.children)n(s)}catch(a){console.error("error occured in secondary operation",a)}};return n(t),await Promise.allSettled(e),t},z=async(t,e,n)=>{var f,d;if(e.display==="none")return null;e.transform!=="none"&&(t.style.transform="unset",t.style.transition="unset",await new Promise(u=>{setTimeout(()=>{u(1)},100)}));const o=q(t);if(e.width==="auto"||e.height==="auto"){const u=document.createRange();u.selectNode(t);const g=u.getBoundingClientRect();e.width=`${g.width}px`,e.height=`${g.height}px`,u.detach()}if(e.x=`${o.left}px`,e.y=`${o.top}px`,e.width=`${o.width}px`,e.height=`${o.height}px`,t.tagName==="svg")return Ut(t,e,n);let r=null;(["TEXTAREA","INPUT"].includes(t.tagName)||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)&&(r=nt(t,e));const a=rt(t);if(!t.hasChildNodes()&&a.length===0&&!r)return Dt(t,e,n);const i=Ht(t,e,n);i.children=[];let s=t.tagName!=="TEXTAREA"?Array.from((f=t.childNodes)!=null?f:[]):[];s=s.concat(a).concat(r);const c=await Promise.allSettled(s.map(async u=>{let g;if(!u)return null;if(u.nodeType===Node.ELEMENT_NODE){const p=O(u);g=await z(u,{...p},e)}if(u.nodeType===Node.TEXT_NODE){const p=document.createRange();p.selectNode(u);const h=p.getBoundingClientRect(),E=it(p);p.detach(),g=W(u,{...e,isTextWrapped:E,width:`${h.width}px`,height:`${h.height}px`,x:`${h.x-o.x}px`,y:`${h.y-o.y}px`,left:`${h.left}px`,right:`${h.right}px`,top:`${h.top}px`,bottom:`${h.bottom}px`},e)}else u.nodeType===m.PESUDO?g=$t(u.type,u.styles,e):u.nodeType===m.INPUT&&(g=W(u.node,u.styles,u.styles));return g}));return i.children=c.filter(u=>(u==null?void 0:u.status)==="fulfilled"&&!!(u!=null&&u.value)).map(u=>u.value),(d=i.children)!=null&&d.length&&at(i.children),e.transform!=="none"&&(t.style.transform="",t.style.transition=""),i},Kt=async(t,e)=>{if(e&&kt(e),!getComputedStyle)throw new Error("getComputedStyle is not defined");try{const n=await z(t,O(t),null);return console.log("\u8F6C\u6362\u7ED3\u679C",n),n}catch(n){console.error("\u8F6C\u6362\u51FA\u9519",n)}return null};x.htmlToMG=Kt,x.postProcess=Vt,x.renderToMasterGo=Xt,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
+1
-1
| { | ||
| "name": "@mastergo/html-mastergo", | ||
| "version": "1.6.1", | ||
| "version": "1.6.2", | ||
| "description": "Convert HTML to Mastergo code", | ||
@@ -5,0 +5,0 @@ "files": [ |
83761
0.06%