@jieyin/editor-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @jieyin/editor-sdk might be problematic. Click here for more details.

Files changed (33) hide show
  1. package/dist/assets/copyDiecuts.worker-DToLkwQW.js +1 -0
  2. package/dist/assets/deform.worker-D47nPX6L.js +1 -0
  3. package/dist/assets/maskWorker-ZKs7ClE6.js +1 -0
  4. package/dist/assets/renderWorker-xde7w90h.js +1 -0
  5. package/dist/editor-sdk.es.js +12848 -0
  6. package/dist/editor-sdk.umd.js +25 -0
  7. package/dist/style.css +1 -0
  8. package/package.json +11 -1
  9. package/dist/components/Editor/components/CanvasSection.vue.d.ts +0 -90
  10. package/dist/components/Editor/components/EditorSidebar.vue.d.ts +0 -316
  11. package/dist/components/Editor/components/EditorTopbar.vue.d.ts +0 -37
  12. package/dist/components/Editor/components/PreviewPanel.vue.d.ts +0 -67
  13. package/dist/components/Editor/components/TemplateModal.vue.d.ts +0 -35
  14. package/dist/components/Editor/index.vue.d.ts +0 -21
  15. package/dist/components/Editor/workers/copyDiecuts.worker.d.ts +0 -14
  16. package/dist/components/Editor/workers/maskWorker.d.ts +0 -13
  17. package/dist/components/Editor/workers/renderWorker.d.ts +0 -1
  18. package/dist/index.d.ts +0 -38
  19. package/dist/types.d.ts +0 -70
  20. package/dist/utils/encryptJson.d.ts +0 -31
  21. package/dist/utils/fileToken.d.ts +0 -16
  22. package/dist/utils/renderService/blend.d.ts +0 -4
  23. package/dist/utils/renderService/deform.d.ts +0 -21
  24. package/dist/utils/renderService/deform.worker.d.ts +0 -189
  25. package/dist/utils/renderService/image.d.ts +0 -8
  26. package/dist/utils/renderService/index.d.ts +0 -12
  27. package/dist/utils/renderService/mask.d.ts +0 -13
  28. package/dist/utils/renderService/prepareRenderData.d.ts +0 -2
  29. package/dist/utils/renderService/psdConverter.d.ts +0 -6
  30. package/dist/utils/renderService/render.d.ts +0 -14
  31. package/dist/utils/renderService/render.worker.d.ts +0 -17
  32. package/dist/utils/renderService/types.d.ts +0 -216
  33. package/dist/utils/renderService/workerManager.d.ts +0 -24
@@ -0,0 +1 @@
1
+ (function(){"use strict";const d=(t,s)=>{const e=JSON.parse(JSON.stringify(t));return e.customData||(e.customData={}),e.customData.id=s,{cloned:e,nextId:s+1}},u=t=>{const{sourceObjects:s,targetJsonMap:e,objectIndex:r}=t;let o=Number.isFinite(r)?r:1;const n={};return Object.entries(e||{}).forEach(([l,c])=>{const p=Array.isArray(c==null?void 0:c.objects)?c.objects:[],a=[];s.forEach(f=>{const i=d(f,o);a.push(i.cloned),o=i.nextId}),n[l]={...c,objects:[...p,...a]}}),{updates:n,nextObjectIndex:o}};self.onmessage=t=>{const s=t.data;try{const e=u(s);self.postMessage({id:s.id,ok:!0,data:e})}catch(e){self.postMessage({id:s.id,ok:!1,error:e instanceof Error?e.message:String(e)})}}})();
@@ -0,0 +1 @@
1
+ (function(){"use strict";function j(t){return"naturalWidth"in t&&t.naturalWidth?{width:t.naturalWidth,height:t.naturalHeight}:"width"in t?{width:t.width,height:t.height}:{width:0,height:0}}function O(t,e){if(!t||!t.bounds)throw new Error("Invalid layer data: missing bounds");const n=t.bounds;if(e&&e.width>0&&e.height>0)return{...t};const o=t.size||t.placedLayer||{width:n.width,height:n.height},s=o.width/n.width,r=o.height/n.height,c={...t};return t.transform&&t.transform.length===8&&(c.transform=[(t.transform[0]-n.left)*s,(t.transform[1]-n.top)*r,(t.transform[2]-n.left)*s,(t.transform[3]-n.top)*r,(t.transform[4]-n.left)*s,(t.transform[5]-n.top)*r,(t.transform[6]-n.left)*s,(t.transform[7]-n.top)*r]),c}function F(t){return t.error,t}function G(t,e,n){if(!t||!e||!n)return"Invalid Parameters";const o="naturalWidth"in e?e.naturalWidth:"width"in e?e.width:0,s="naturalHeight"in e?e.naturalHeight:"height"in e?e.height:0;if(!o||!s)return"Image Not Loaded";t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";let r=null,c=null,i=null,u=null,h=0,d=0,f=null,x="Unknown";if(n.size&&n.size.width?(h=n.size.width,d=n.size.height):n.placedLayer&&n.placedLayer.width?(h=n.placedLayer.width,d=n.placedLayer.height):n.originalWidth&&(h=n.originalWidth,d=n.originalHeight),n.meshPoints&&n.meshPoints.length>0&&(r=n.meshPoints),n.transform&&n.transform.length===8){const l=n.transform;c=[{x:l[0],y:l[1]},{x:l[2],y:l[3]},{x:l[4],y:l[5]},{x:l[6],y:l[7]}]}return n.quiltSliceX&&(i=n.quiltSliceX),n.quiltSliceY&&(u=n.quiltSliceY),n.filterList&&(f=n.filterList.find(l=>l.type==="puppet"&&l.enabled)),h===0&&i&&i.length>0&&(h=i[i.length-1]),h===0&&(h=1e3),d===0&&(d=1e3),f&&f.filter&&f.filter.puppetShapeList&&f.filter.puppetShapeList.length>0&&c?(_(t,e,c,f.filter.puppetShapeList[0]),x="Puppet Warp"):r&&c?i&&u?(R(t,e,c,r,i,u,h,d),x="Quilt Mesh"):r.length===16?(Q(t,e,c,r),x="Std Mesh (16pt)"):(N(t,e,c,r),x="Auto-Fit Mesh"):r?(J(t,e,r),x="Direct Mesh"):c&&(k(t,e,c),x="Transform Only"),x}function _(t,e,n,o,s,r){if(!o.originalVertexArray||!o.deformedVertexArray||!o.indexArray)return;const c=E(n),i=K(c);if(!i){k(t,e,n);return}const u=o.originalVertexArray,h=o.deformedVertexArray,d=o.indexArray;for(let f=0;f<d.length;f+=3){const x=d[f],l=d[f+1],y=d[f+2];if(!u[x]||!u[l]||!u[y])continue;const m=u[x],w=u[l],a=u[y],b=V(m.x,m.y,i),p=V(w.x,w.y,i),g=V(a.x,a.y,i),M=j(e),I={x:b.x*M.width,y:b.y*M.height},P={x:p.x*M.width,y:p.y*M.height},B={x:g.x*M.width,y:g.y*M.height},T=h[x],v=h[l],z=h[y];H(t,e,I,P,B,T,v,z)}}function Q(t,e,n,o){let s=1/0,r=-1/0,c=1/0,i=-1/0;o.forEach(f=>{s=Math.min(s,f.x),r=Math.max(r,f.x),c=Math.min(c,f.y),i=Math.max(i,f.y)});const u=r-s,h=i-c;if(u<1||h<1){k(t,e,n);return}const d=o.map(f=>{const x=(f.x-s)/u,l=(f.y-c)/h;return L(x,l,n)});A(t,e,d,"bicubic",4,40)}function R(t,e,n,o,s,r,c,i){const u=E(n);let h=1/0,d=-1/0,f=1/0,x=-1/0;o.forEach(a=>{h=Math.min(h,a.x),d=Math.max(d,a.x),f=Math.min(f,a.y),x=Math.max(x,a.y)});const l=d-h||1,y=x-f||1,m=s.length-1,w=r.length-1;for(let a=0;a<w;a++)for(let b=0;b<m;b++){const p=a*3,g=b*3,M=[],I=m*3+1;try{for(let W=0;W<4;W++)for(let $=0;$<4;$++){const Y=(p+W)*I+(g+$);o[Y]&&M.push(o[Y])}}catch{continue}if(M.length<16)continue;const P=M.map(W=>{const $=(W.x-h)/l,Y=(W.y-f)/y;return C($,Y,u)}),B=s[b]/c,T=s[b+1]/c,v=r[a]/i,z=r[a+1]/i;U(t,e,P,B,T,v,z)}}function N(t,e,n,o){const s=E(n);let r=1/0,c=-1/0,i=1/0,u=-1/0;o.forEach(l=>{r=Math.min(r,l.x),c=Math.max(c,l.x),i=Math.min(i,l.y),u=Math.max(u,l.y)});const h=c-r||1,d=u-i||1,f=o.map(l=>{const y=(l.x-r)/h,m=(l.y-i)/d;return C(y,m,s)}),x=Math.floor(Math.sqrt(o.length))||4;A(t,e,f,"grid",x,40)}function U(t,e,n,o,s,r,c){const u=j(e),h=u.width,d=u.height;for(let f=0;f<20;f++)for(let x=0;x<20;x++){const l=x/20,y=f/20,m=(x+1)/20,w=(f+1)/20,a=o+l*(s-o),b=o+m*(s-o),p=r+y*(c-r),g=r+w*(c-r),M={x:a*h,y:p*d},I={x:b*h,y:p*d},P={x:a*h,y:g*d},B={x:b*h,y:g*d},T=S(l,y,n),v=S(m,y,n),z=S(l,w,n),W=S(m,w,n);H(t,e,M,I,P,T,v,z),H(t,e,I,B,P,v,W,z)}}function k(t,e,n){A(t,e,n,"bilinear",0,10)}function J(t,e,n){A(t,e,n,"bicubic",4,40)}function A(t,e,n,o,s,r){const c=j(e),i=c.width,u=c.height;for(let h=0;h<r;h++)for(let d=0;d<r;d++){const f=d/r,x=h/r,l=(d+1)/r,y=(h+1)/r,m={x:f*i,y:x*u},w={x:l*i,y:x*u},a={x:f*i,y:y*u},b={x:l*i,y:y*u};let p,g,M,I;o==="bicubic"?(p=S(f,x,n),g=S(l,x,n),M=S(f,y,n),I=S(l,y,n)):o==="grid"?(p=X(f,x,n,s),g=X(l,x,n,s),M=X(f,y,n,s),I=X(l,y,n,s)):(p=L(f,x,n),g=L(l,x,n),M=L(f,y,n),I=L(l,y,n)),H(t,e,m,w,a,p,g,M),H(t,e,w,b,a,g,I,M)}}function q(t,e){const n=1-e;return t===0?n*n*n:t===1?3*n*n*e:t===2?3*n*e*e:e*e*e}function S(t,e,n){let o=0,s=0;for(let r=0;r<4;r++)for(let c=0;c<4;c++){const i=q(r,e)*q(c,t);o+=n[r*4+c].x*i,s+=n[r*4+c].y*i}return{x:o,y:s}}function L(t,e,n){const o=(1-t)*(1-e)*n[0].x+t*(1-e)*n[1].x+t*e*n[2].x+(1-t)*e*n[3].x,s=(1-t)*(1-e)*n[0].y+t*(1-e)*n[1].y+t*e*n[2].y+(1-t)*e*n[3].y;return{x:o,y:s}}function X(t,e,n,o){const s=o-1,r=t*s,c=e*s;let i=Math.floor(r),u=Math.floor(c);i>=s&&(i=s-1),u>=s&&(u=s-1),i<0&&(i=0),u<0&&(u=0);const h=r-i,d=c-u,f=n[u*o+i],x=n[u*o+(i+1)],l=n[(u+1)*o+i],y=n[(u+1)*o+(i+1)],m=(1-h)*(1-d)*f.x+h*(1-d)*x.x+h*d*y.x+(1-h)*d*l.x,w=(1-h)*(1-d)*f.y+h*(1-d)*x.y+h*d*y.y+(1-h)*d*l.y;return{x:m,y:w}}function E(t){const e=t[0].x,n=t[0].y,o=t[1].x,s=t[1].y,r=t[2].x,c=t[2].y,i=t[3].x,u=t[3].y;let h=o-r,d=s-c,f=i-r,x=u-c,l=e-o+r-i,y=n-s+c-u,m,w,a,b,p,g,M,I;if(l===0&&y===0)a=o-e,b=r-o,p=e,g=s-n,M=c-s,I=n,m=0,w=0;else{const P=h*x-f*d;m=(l*x-y*f)/P,w=(h*y-d*l)/P,a=o-e+m*o,b=i-e+w*i,p=e,g=s-n+m*s,M=u-n+w*u,I=n}return{a,b,c:p,d:g,e:M,f:I,g:m,h:w}}function K(t){const e=t.a,n=t.b,o=t.c,s=t.d,r=t.e,c=t.f,i=t.g,u=t.h,h=1,d=e*(r*h-c*u)-n*(s*h-c*i)+o*(s*u-r*i);if(Math.abs(d)<1e-10)return null;const f=1/d;return{a:(r*h-c*u)*f,b:(o*u-n*h)*f,c:(n*c-o*r)*f,d:(c*i-s*h)*f,e:(e*h-o*i)*f,f:(o*s-e*c)*f,g:(s*u-r*i)*f,h:(n*i-e*u)*f,i:(e*r-n*s)*f}}function V(t,e,n){const o=n.a*t+n.b*e+n.c,s=n.d*t+n.e*e+n.f,r=n.g*t+n.h*e+(n.i||1);return{x:o/r,y:s/r}}function C(t,e,n){const o=n.g*t+n.h*e+1;return{x:(n.a*t+n.b*e+n.c)/o,y:(n.d*t+n.e*e+n.f)/o}}function H(t,e,n,o,s,r,c,i){if(!e||"complete"in e&&!e.complete||!("naturalWidth"in e?e.naturalWidth:e.width))return;const h=(r.x+c.x+i.x)/3,d=(r.y+c.y+i.y)/3,f=(Math.hypot(r.x-h,r.y-d)+Math.hypot(c.x-h,c.y-d)+Math.hypot(i.x-h,i.y-d))/3,l=f>1?(f+1.65)/f:1.5,y=h+(r.x-h)*l,m=d+(r.y-d)*l,w=h+(c.x-h)*l,a=d+(c.y-d)*l,b=h+(i.x-h)*l,p=d+(i.y-d)*l;t.save(),t.beginPath(),t.moveTo(y,m),t.lineTo(w,a),t.lineTo(b,p),t.closePath(),t.clip();const g=n.x*(s.y-o.y)-o.x*s.y+s.x*o.y+(o.x-s.x)*n.y;if(Math.abs(g)<.001){t.restore();return}const M=-(n.y*(i.x-c.x)-o.y*i.x+s.y*c.x+(o.y-s.y)*r.x)/g,I=(o.y*i.y+n.y*(c.y-i.y)-s.y*c.y+(s.y-o.y)*r.y)/g,P=(n.x*(i.x-c.x)-o.x*i.x+s.x*c.x+(o.x-s.x)*r.x)/g,B=-(o.x*i.y+n.x*(c.y-i.y)-s.x*c.y+(s.x-o.x)*r.y)/g,T=(n.x*(s.y*c.x-o.y*i.x)+n.y*(o.x*i.x-s.x*c.x)+(s.x*o.y-o.x*s.y)*r.x)/g,v=(n.x*(s.y*c.y-o.y*i.y)+n.y*(o.x*i.y-s.x*c.y)+(s.x*o.y-o.x*s.y)*r.y)/g;t.transform(M,I,P,B,T,v),t.drawImage(e,0,0),t.restore()}self.onmessage=async t=>{const{id:e,designBitmap:n,layerData:o,canvasSize:s}=t.data;if(!n){console.error(`[deform worker] ❌ designBitmap 未定义 id=${e}`),self.postMessage({id:e,imageBitmap:null,error:"designBitmap 未定义",duration:0});return}if(!o){console.error(`[deform worker] ❌ layerData 未定义 id=${e}`),self.postMessage({id:e,imageBitmap:null,error:"layerData 未定义",duration:0});return}const r=performance.now(),c=new Date().toISOString();console.log(`[deform worker] ⏰ 开始 id=${e} 时间=${c}`,{designBitmap:{width:n.width,height:n.height},size:o.size,bounds:o.bounds,canvasSize:s});try{const i=o.bounds;if(!i||!i.width||!i.height){console.error(`[deform worker] ❌ bounds 无效 id=${e}`,i),self.postMessage({id:e,imageBitmap:null,error:"bounds 无效",duration:0});return}const u=O(o,s);let h,d;if(s&&s.width>0&&s.height>0)h=s.width,d=s.height;else{const p=o.size||o.placedLayer||{width:i.width,height:i.height};h=p.width,d=p.height}const f=new OffscreenCanvas(h,d),x=f.getContext("2d");if(!x){const g=performance.now()-r;self.postMessage({id:e,error:"Canvas context unavailable",duration:g});return}const l=G(x,n,u),y=f.transferToImageBitmap(),w=performance.now()-r,a=new Date().toISOString();console.log(`[deform worker] ✅ 结束 id=${e} 时间=${a} 耗时=${Math.round(w)}ms 变形方法=${l}`,{width:y.width,height:y.height}),n.close();const b=F({id:e,imageBitmap:y,duration:w});self.postMessage(b,b.imageBitmap?[b.imageBitmap]:[])}catch(i){const h=performance.now()-r,d=i instanceof Error?i.message:String(i),f=new Date().toISOString();console.log(`[deform worker] ❌ 错误 id=${e} 时间=${f} 耗时=${Math.round(h)}ms`,d),self.postMessage({id:e,error:d,duration:h})}}})();
@@ -0,0 +1 @@
1
+ (function(){"use strict";const l=async s=>createImageBitmap(s),h=async s=>{const{baseBlob:e,maskBlob:a,maskWidth:t,maskHeight:n,left:p,top:b,canvasWidth:u,canvasHeight:w}=s,[r,c]=await Promise.all([l(e),l(a)]),d=r.width/u,g=r.height/w,i=new OffscreenCanvas(Math.round(t),Math.round(n)),o=i.getContext("2d");if(!o)return null;o.drawImage(r,p*d,b*g,t*d,n*g,0,0,t,n);const m=new OffscreenCanvas(i.width,i.height),f=m.getContext("2d");return f&&(f.drawImage(c,0,0,c.width,c.height,0,0,t,n),o.globalCompositeOperation="destination-in",o.drawImage(m,0,0),o.globalCompositeOperation="source-over"),await i.convertToBlob({type:"image/png"})};self.onmessage=async s=>{const e=s.data;try{const a=await h(e),t=a?await a.arrayBuffer():null;self.postMessage({id:e.id,arrayBuffer:t},t?[t]:[])}catch(a){self.postMessage({id:e.id,error:a instanceof Error?a.message:String(a)})}}})();
@@ -0,0 +1 @@
1
+ (function(){"use strict";var A=(e=>(e[e.Group=0]="Group",e[e.Layer=1]="Layer",e))(A||{});function he(e){let n=e;return()=>{const t=n;return n+=1,t}}function fe(e,n){return{name:e.name||"",type:e.type||"Layer",blendMode:e.blendMode||"normal",transform:e.transform??[],meshPoints:e.meshPoints,bounds:e.bounds??{left:0,top:0,width:0,height:0},isSmartObject:e.isSmartObject??!1,size:e.size,originalWidth:e.originalWidth,originalHeight:e.originalHeight,placedLayer:e.placedLayer,quiltSliceX:e.quiltSliceX,quiltSliceY:e.quiltSliceY,layerOrder:e.layerOrder,imagePath:e.imagePath,vectorMask:e.vectorMask??n,filterList:e.filterList,opacity:e.opacity,clipping:e.clipping}}function pe(e,n,t,r){let a=e.name||"",o=n[a],l=(o==null?void 0:o.partId)??(e.type==="Group"?t.get(a):void 0);if(e.type==="Group"&&l===void 0&&(!o||o.id===void 0)&&e.children&&e.children.length===1){const m=e.children[0].name,p=n[m],M=(p==null?void 0:p.partId)??t.get(m);(M!==void 0||(p==null?void 0:p.id)!==void 0)&&(a=m,o=p,l=M)}const w=e.id??(o==null?void 0:o.id)??r();if(e.type==="Group")return{id:w,partId:l,name:a,blendMode:e.blendMode||"normal",bounds:e.bounds||{left:0,top:0,width:0,height:0},type:A.Group,smartObjects:(e.children??[]).map(m=>fe(m,e.vectorMask)),opacity:e.opacity,clipping:e.clipping,layerOrder:e.layerOrder};let u=o==null?void 0:o.url;return!u&&e.imagePath&&(u=e.imagePath),{id:w,name:e.name||"",blendMode:e.blendMode||"normal",bounds:e.bounds||{left:0,top:0,width:0,height:0},type:A.Layer,url:u,opacity:e.opacity,clipping:e.clipping,layerOrder:e.layerOrder}}function ue(e,n){const t=new Map(n.parts.map(a=>[a.name,a.id])),r=he(n.defaultIdStart??1);return{parts:n.parts,models:e.map(a=>{const o=a.layerExtrasByName??{},l=a.psdJson,w=l.layerList||l.layerList||[],u=l.canvasWidth,m=l.canvasHeight;if(!u||!m)throw new Error(`无法获取 PSD 画布尺寸: canvasWidth=${u}, canvasHeight=${m}。请确保 jsonurl 中的 canvasWidth 和 canvasHeight 存在`);console.log("[psdConverter] 📐 使用 psdJson 画布尺寸:",{canvasWidth:u,canvasHeight:m,note:"应该使用 jsonurl 中的原始尺寸(如 7559x7559)"});const p=[];for(const b of w)if(b.type==="Group"&&b.children){const L=[],T=[],B=[...b.children].sort(($,k)=>{const O=$.layerOrder??0,R=k.layerOrder??0;return O-R});for(const $ of B)$.isSmartObject===!0?L.push($):T.push($);T.length>0&&p.push(...T),L.length>0&&p.push({...b,children:L})}else p.push(b);const M=p.map(b=>pe(b,o,t,r));return{width:u,height:m,psdPartData:M}})}}function me(e){return e?e.vectorMask&&e.vectorMask.paths&&Array.isArray(e.vectorMask.paths)?{type:"bezier",paths:e.vectorMask.paths}:Array.isArray(e.vectorMask)?{type:"simple",points:e.vectorMask}:null:null}function ge(e){return e?e.type==="bezier"?{type:"bezier",paths:e.paths.map(n=>({open:!!n.open,knots:n.knots.map(t=>({linked:!!t.linked,points:Array.isArray(t.points)?[...t.points]:[]}))}))}:e.type==="simple"?{type:"simple",points:e.points.map(n=>({x:n.x,y:n.y,type:n.type}))}:null:null}function z(e,n){if(n){if(e.globalCompositeOperation="destination-in",e.beginPath(),n.type==="bezier"&&Array.isArray(n.paths))n.paths.forEach(t=>{const r=t.knots;if(!r||r.length<2)return;const a=r[0];e.moveTo(a.points[2],a.points[3]);for(let o=0;o<r.length;o++){const l=r[o];let w=(o+1)%r.length;if(!t.open&&o===r.length-1)w=0;else if(t.open&&o===r.length-1)break;const u=r[w],m=l.points[4],p=l.points[5],M=u.points[0],b=u.points[1],L=u.points[2],T=u.points[3];e.bezierCurveTo(m,p,M,b,L,T)}t.open||e.closePath()});else if(n.type==="simple"&&Array.isArray(n.points)){const t=n.points;if(t.length<3)return;e.moveTo(t[0].x,t[0].y);for(let r=1;r<t.length;r++)e.lineTo(t[r].x,t[r].y);e.closePath()}e.fillStyle="#000",e.fill(),e.globalCompositeOperation="source-over"}}const _="file_token",H="file_token_expire_time",we=60*1e3,J=typeof window<"u"&&typeof localStorage<"u";function Q(e){return J?localStorage.getItem(e):null}function Z(e,n){J&&localStorage.setItem(e,n)}function D(e){J&&localStorage.removeItem(e)}function q(){return Q(_)}function ye(e=we){if(!q())return!0;const t=Q(H);if(!t)return!1;const r=Number(t);return Date.now()+e>r}function be(e,n){if(Z(_,e),typeof n=="number"&&n>0){const t=Date.now()+n*1e3;Z(H,String(t))}}function ve(){D(_),D(H)}async function ee(e){var r,a;const n=await e(),t=(r=n==null?void 0:n.data)==null?void 0:r.data;return((a=n==null?void 0:n.data)==null?void 0:a.code)===200&&(t!=null&&t.file_token)?(be(t.file_token,t.expires_in),t.file_token):null}let ke=null;function te(){return typeof window>"u"?null:ke}async function ne(){if(typeof window>"u")return q();const e=q();if(e&&!ye())return e;try{const n=await te();if(e&&(n!=null&&n.fetchFileTokenRefresh)){const t=await ee(n.fetchFileTokenRefresh);if(t)return t}}catch{}try{const n=te();return n!=null&&n.fetchFileToken?await ee(n.fetchFileToken):null}catch{return null}}function re(e){if(!e||e.startsWith("data:")||e.startsWith("blob:"))return!1;try{const n=typeof window<"u"?window.location.origin:"http://localhost",t=new URL(e,n);return!(!t.pathname.includes("/files/")||t.searchParams.has("fileToken"))}catch{return e.includes("/files/")&&!e.includes("fileToken=")}}function oe(e,n){if(!n||!re(e))return e;const t=/^(https?:)?\/\//i.test(e),r=e.startsWith("//");try{const a=typeof window<"u"?window.location.origin:"http://localhost",o=new URL(e,a);return o.searchParams.has("fileToken")?e:(o.searchParams.set("fileToken",n),t?o.toString():r?o.toString().replace(/^https?:/,""):`${o.pathname}${o.search}${o.hash}`)}catch{return e}}function Oe(e){try{const n=typeof window<"u"?window.location.origin:"http://localhost",t=new URL(e,n);if(!t.searchParams.has("fileToken"))return e;t.searchParams.delete("fileToken");const r=/^(https?:)?\/\//i.test(e),a=e.startsWith("//");return r?t.toString():a?t.toString().replace(/^https?:/,""):`${t.pathname}${t.search}${t.hash}`}catch{return e.replace(/([?&])fileToken=[^&]*(&)?/,(n,t,r)=>t==="?"&&r?"?":t==="&"&&r?"&":"").replace(/[?&]$/,"")}}async function Me(e){if(!re(e))return e;const n=await ne();return oe(e,n)}async function ie(e,n){if(typeof window>"u")return fetch(e,n);const t=Oe(e),r=await Me(t),a=await fetch(r,n);if(a.status!==401)return a;ve();const o=await ne(),l=oe(t,o);return fetch(l,n)}const se=e=>{if(!e)return e;if(typeof window<"u"){const t=window.location.hostname;if(t==="localhost"||t==="127.0.0.1")try{const r=new URL(e);if(r.pathname.startsWith("/files/"))return`${r.pathname}${r.search}${r.hash}`}catch{}}if(typeof window<"u"&&window.location.hostname!=="localhost")return e;const n=e.match(/^https?:\/\/([^/]+\.oss[^/]*\.aliyuncs\.com)(.*)$/);return n?`/oss${n[2]}`:e},$e=(e,n)=>{if(typeof OffscreenCanvas<"u"&&typeof document>"u")return new OffscreenCanvas(e,n);const t=document.createElement("canvas");return t.width=e,t.height=n,t},U=async(e,n)=>{var u;if(!n||n<=0)return e;const t=Math.max(e.width,e.height);if(t<=n)return e;const r=n/t,a=Math.max(1,Math.round(e.width*r)),o=Math.max(1,Math.round(e.height*r)),l=$e(a,o),w=l.getContext("2d");return w?(w.drawImage(e,0,0,a,o),(u=e.close)==null||u.call(e),await createImageBitmap(l)):e};async function Se(e,n){if(typeof e=="string")try{const t=se(e),r=await ie(t);if(!r.ok){const o=r.status===404?`图片不存在 (404): ${e}`:`加载图片失败 (${r.status} ${r.statusText}): ${e}`;throw new Error(o)}const a=await r.blob();if(!a.type.startsWith("image/")&&a.size===0)throw new Error(`图片数据无效: URL=${e}`);try{const o=await createImageBitmap(a);return await U(o,n)}catch(o){throw new Error(`图片解码失败: URL=${e}, 错误=${o instanceof Error?o.message:o}`)}}catch(t){throw t instanceof Error?t:new Error(`加载图片失败: ${e}, ${t}`)}if(e instanceof HTMLImageElement){if((!e.complete||e.naturalWidth===0)&&await new Promise((t,r)=>{e.onload=t,e.onerror=()=>r(new Error(`图片加载失败: src=${e.src}`)),e.complete&&t(null)}),e.naturalWidth===0||e.naturalHeight===0)throw new Error(`图片尺寸无效: src=${e.src}, width=${e.naturalWidth}, height=${e.naturalHeight}`);try{const t=await createImageBitmap(e);return await U(t,n)}catch(t){throw new Error(`图片解码失败: src=${e.src}, 错误=${t instanceof Error?t.message:t}`)}}if(e instanceof ImageBitmap){if(e.width===0||e.height===0)throw new Error(`ImageBitmap 尺寸无效: width=${e.width}, height=${e.height}`);return await U(e,n)}throw new Error("不支持的图片类型")}async function Ie(e,n){try{const t=se(e),r=await ie(t);if(!r.ok){const o=r.status===404?`图片不存在 (404): ${e}`:`加载图片失败 (${r.status} ${r.statusText}): ${e}`;throw new Error(o)}const a=await r.blob();if(!a.type.startsWith("image/")&&a.size===0)throw new Error(`图片数据无效: URL=${e}`);try{const o=await createImageBitmap(a);return await U(o,n)}catch(o){throw new Error(`图片解码失败: URL=${e}, 错误=${o instanceof Error?o.message:o}`)}}catch(t){throw t instanceof Error?t:new Error(`加载图片失败: ${e}, ${t}`)}}function ae(e){if(!e)return"source-over";const n=e.trim().toLowerCase();return{normal:"source-over",multiply:"multiply",screen:"screen",overlay:"overlay",darken:"darken",lighten:"lighten","color dodge":"color-dodge","color-dodge":"color-dodge","color burn":"color-burn","color-burn":"color-burn","hard light":"hard-light","hard-light":"hard-light","soft light":"soft-light","soft-light":"soft-light",difference:"difference",exclusion:"exclusion",hue:"hue",saturation:"saturation",color:"color",luminosity:"luminosity","linear burn":"plus-darker","linear dodge":"lighter",lighter:"lighter","pass-through":"source-over"}[n]||"source-over"}const ce=new Map,G=new Map;let Le=0;function Te(e){const n=ce.get(e);if(n)return n;const t=new Worker(new URL("/assets/deform.worker-D47nPX6L.js",self.location.href),{type:"module"});return t.onmessage=r=>{const{id:a,imageBitmap:o,error:l,duration:w}=r.data??{},u=w?` worker耗时=${Math.round(w)}ms`:"";console.log(`[renderService] deform worker 响应 id=${a}${u}`,{hasImageBitmap:!!o,width:o==null?void 0:o.width,height:o==null?void 0:o.height,error:l});const m=G.get(a);if(m){if(G.delete(a),l){m.reject(new Error(l));return}m.resolve(o)}},t.onerror=r=>{console.error("deform worker error",r)},ce.set(e,t),t}function xe(e){var n,t;return{name:e.name,type:e.type,blendMode:e.blendMode,transform:Array.isArray(e.transform)?[...e.transform]:[],meshPoints:Array.isArray(e.meshPoints)?e.meshPoints.map(r=>({x:r.x,y:r.y,type:r.type})):[],bounds:e.bounds?{width:e.bounds.width,height:e.bounds.height,top:e.bounds.top,left:e.bounds.left,bottom:e.bounds.bottom,right:e.bounds.right}:{width:0,height:0,top:0,left:0},size:e.size?{width:e.size.width,height:e.size.height}:void 0,placedLayer:e.placedLayer?{width:e.placedLayer.width,height:e.placedLayer.height}:void 0,isSmartObject:e.isSmartObject,originalWidth:e.originalWidth,originalHeight:e.originalHeight,quiltSliceX:Array.isArray(e.quiltSliceX)?[...e.quiltSliceX]:void 0,quiltSliceY:Array.isArray(e.quiltSliceY)?[...e.quiltSliceY]:void 0,layerOrder:e.layerOrder,imagePath:e.imagePath,vectorMask:e.vectorMask?{paths:(n=e.vectorMask.paths)==null?void 0:n.map(r=>{var a;return{open:r.open,knots:(a=r.knots)==null?void 0:a.map(o=>({linked:o.linked,points:[...o.points]})),fillRule:r.fillRule,operation:r.operation}}),points:(t=e.vectorMask.points)==null?void 0:t.map(r=>({x:r.x,y:r.y,type:r.type})),invert:e.vectorMask.invert,notLink:e.vectorMask.notLink,disable:e.vectorMask.disable,fillStartsWithAllPixels:e.vectorMask.fillStartsWithAllPixels}:void 0,filterList:e.filterList?e.filterList.map(r=>{var a;return{type:r.type,enabled:r.enabled,filter:r.filter?{puppetShapeList:(a=r.filter.puppetShapeList)==null?void 0:a.map(o=>({originalVertexArray:o.originalVertexArray.map(l=>({x:l.x,y:l.y})),deformedVertexArray:o.deformedVertexArray.map(l=>({x:l.x,y:l.y})),indexArray:[...o.indexArray]}))}:void 0}}):void 0,opacity:e.opacity,clipping:e.clipping}}function Pe(e,n,t,r){const a=++Le,o=Te(t),l=performance.now(),w=new Date().toISOString();return console.log(`[renderService] 📤 发送 deform 任务 id=${a} faceId=${t} 时间=${w}`),new Promise((u,m)=>{G.set(a,{resolve:M=>{const b=performance.now(),L=new Date().toISOString(),T=b-l;console.log(`[renderService] 📥 接收 deform 结果 id=${a} 时间=${L} 总耗时=${Math.round(T)}ms`),u(M)},reject:m});const p=xe(n);o.postMessage({id:a,designBitmap:e,layerData:p,canvasSize:r},[e])})}async function We(e,n,t=0,r,a){const o=await Se(e,a);if(!o||o.width===0||o.height===0)throw new Error("图片无效:尺寸为 0");return await Pe(o,n,t,r)}function E(e,n){if(typeof OffscreenCanvas<"u"&&typeof document>"u")return new OffscreenCanvas(e,n);if(typeof document<"u"){const t=document.createElement("canvas");return t.width=e,t.height=n,t}else throw new Error("无法创建 canvas:不在 Worker 或主线程环境中")}function C(e){return e.getContext("2d")}function le(e){const n=C(e);if(!n)throw new Error("无法创建 canvas context");return n}async function Ee(e){const n=performance.now(),{psdJson:t,materialList:r,fabricScreenshotList:a,width:o,height:l,baseUrl:w}=e,u=e.maxImageSize,m=s=>{if(!s||typeof s!="string"||!s.includes("http"))return;if(/^(https?:)?\/\//i.test(s)||s.startsWith("data:")||s.startsWith("blob:"))return s;if(!w)return!s.includes("http")&&!s.startsWith("data:")&&!s.startsWith("blob:")?void 0:s;try{const d=new URL(s,w).toString();return!d.includes("http")&&!d.startsWith("data:")&&!d.startsWith("blob:")?void 0:d}catch(d){console.warn(`[renderByJson] 解析图片 URL 失败: ${s}`,d);return}},p={},M=new Map;for(const s of r)p[s.sourceName]={url:s.url},s.sourceName&&M.set(s.sourceName,s.url);const b=new Map;for(const s of a)b.set(s.id,s.url);function L(s,i){const d=s.id??i;if(s.type==="Group"&&d&&b.has(d)){const f=b.get(d);if(s.children){for(const c of s.children)if(c&&c.isSmartObject===!0){const h=(c==null?void 0:c.name)||"";h&&!p[h]&&(p[h]={}),h&&(p[h].designImage=f)}}}if(s.children)for(const f of s.children)f&&L(f,d)}if(t.layerList)for(const s of t.layerList)s&&L(s);const B=ue([{psdJson:t,layerExtrasByName:p}],{parts:[],defaultIdStart:1});if(!B.models||B.models.length===0)throw new Error("无法解析 JSON 数据");const $=B.models[0];if(!$.psdPartData)throw new Error("JSON 数据中没有 psdPartData");const k=$.width,O=$.height,R=E(k,O),S=le(R),F=[];for(let s=0;s<$.psdPartData.length;s++){const i=$.psdPartData[s],d=p[i.url];if(i.type===A.Layer){const f=(d==null?void 0:d.url)??i.url,c=m(f);if(!c){console.warn(`图层 "${i.name}" 没有 url,跳过`);continue}F.push({index:s,type:"layer",partData:i,promise:Ie(c,u).catch(h=>(console.warn(`⚠️ 加载图层图片失败,将跳过该图层 (${i.name}):`,h.message||h),null))})}else if(i.type===A.Group){if(!i.smartObjects||i.smartObjects.length===0){console.warn(`图层 "${i.name}" 没有 smartObject,跳过变形`);continue}for(let f=0;f<i.smartObjects.length;f++){const c=i.smartObjects[f];if(!c||!c.name){console.warn("智能对象无效,跳过");continue}const h=p[c.name]??d;let y=(h==null?void 0:h.designImage)??(h==null?void 0:h.url)??c.imagePath;if(typeof y=="string"&&(/^(https?:)?\/\//i.test(y)||y.startsWith("data:")||y.startsWith("blob:")||(y=M.get(y)??y),y=m(y)),!y){console.warn(`智能对象 "${c.name}" 没有 designImage、url 或 imagePath,跳过变形`);continue}const W=(i.partId??i.id)*100+f,j=ge(me(c)),V={width:k,height:O};F.push({index:s+f*.01,type:"group",partData:i,smartObject:c,maskData:j,promise:We(y,c,W,V,u).catch(v=>(console.warn(`⚠️ 变形失败,将跳过该图层 (${c.name}):`,v.message||v),null))})}}}const Ae=await Promise.all(F.map(s=>s.promise)),N=F.map((s,i)=>({task:s,imageBitmap:Ae[i]})).sort((s,i)=>{var c,h;const d=s.task.type==="group"&&((c=s.task.smartObject)==null?void 0:c.layerOrder)!==void 0?s.task.smartObject.layerOrder:s.task.partData.layerOrder??s.task.index,f=i.task.type==="group"&&((h=i.task.smartObject)==null?void 0:h.layerOrder)!==void 0?i.task.smartObject.layerOrder:i.task.partData.layerOrder??i.task.index;return d-f});console.log(`[renderByJson] 开始绘制 ${N.length} 个图层`);let X=E(k,O),g=C(X),Y=!1,de="normal";for(let s=0;s<N.length;s++){const{task:i,imageBitmap:d}=N[s];if(!d){console.warn(`[renderByJson] 图层 "${i.partData.name}" 没有 imageBitmap,跳过`);continue}const{partData:f}=i,c=f.bounds;let h;i.type==="group"&&i.smartObject?h=i.smartObject.opacity??f.opacity:h=f.opacity,(typeof h!="number"||isNaN(h))&&(h=1);let y;i.type==="group"&&i.smartObject?y=i.smartObject.clipping??f.clipping===!0:y=f.clipping===!0;const W=N[s+1];let j=!1;if(W){const v=W.task.partData;W.task.type==="group"&&W.task.smartObject?j=W.task.smartObject.clipping??v.clipping===!0:j=v.clipping===!0}const V=i.type==="group"&&i.smartObject&&i.smartObject.name?i.smartObject.name:(f==null?void 0:f.name)||"未命名图层";if(console.log(`[renderByJson] 绘制图层 "${V}"`,{type:i.type,bitmapSize:{width:d.width,height:d.height},bounds:c,hasMask:!!i.maskData,blendMode:f.blendMode,opacity:h,clipping:y}),!y&&j){if(Y=!0,de=f.blendMode||"normal",g){if(g.clearRect(0,0,k,O),g.globalCompositeOperation="source-over",g.globalAlpha=h,i.type==="group"&&i.smartObject)if(i.maskData){const v=E(k,O),I=C(v);I&&(I.drawImage(d,0,0),z(I,i.maskData),g.drawImage(v,0,0))}else g.drawImage(d,0,0);else i.type==="layer"&&(c?g.drawImage(d,c.left,c.top,c.width,c.height):g.drawImage(d,0,0));g.globalAlpha=1}}else if(y){if(g){if(g.globalCompositeOperation="source-atop",g.globalAlpha=h,i.type==="group"&&i.smartObject)if(i.maskData){const v=E(k,O),I=C(v);I&&(I.drawImage(d,0,0),z(I,i.maskData),g.drawImage(v,0,0))}else g.drawImage(d,0,0);else i.type==="layer"&&(c?g.drawImage(d,c.left,c.top,c.width,c.height):g.drawImage(d,0,0));g.globalAlpha=1,g.globalCompositeOperation="source-over"}}else{if(S.globalCompositeOperation=ae(f.blendMode),S.globalAlpha=h,i.type==="group"&&i.smartObject)if(i.maskData){const v=E(k,O),I=C(v);I&&(I.drawImage(d,0,0),z(I,i.maskData),S.drawImage(v,0,0))}else S.drawImage(d,0,0);else i.type==="layer"&&(c?S.drawImage(d,c.left,c.top,c.width,c.height):S.drawImage(d,0,0));S.globalAlpha=1,S.globalCompositeOperation="source-over"}Y&&!j&&(S.globalCompositeOperation=ae(de),S.drawImage(X,0,0),S.globalCompositeOperation="source-over",Y=!1)}X=null,g=null;let K=R,x=k,P=O;if(o!==void 0||l!==void 0){if(o!==void 0&&l!==void 0)x=o,P=l;else if(o!==void 0){const i=o/k;x=o,P=Math.round(O*i)}else if(l!==void 0){const i=l/O;x=Math.round(k*i),P=l}K=E(x,P);const s=le(K);s.imageSmoothingEnabled=!0,s.imageSmoothingQuality="high",s.drawImage(R,0,0,k,O,0,0,x,P),console.log(`[renderByJson] 已缩放结果: ${k}x${O} -> ${x}x${P}`)}const Ce=performance.now()-n;return console.log(`[renderByJson] 绘制完成,总渲染时间: ${Math.round(Ce)}ms`),{canvas:K,width:x,height:P}}const je=async e=>{const t=(await Ee(e)).canvas;return t?createImageBitmap(t):null};self.onmessage=async e=>{const n=e.data;try{const t=await je(n.renderData);self.postMessage({id:n.id,bitmap:t},t?[t]:[])}catch(t){self.postMessage({id:n.id,error:t instanceof Error?t.message:String(t)})}}})();