@jetprint/editor-sdk 1.2.14 → 1.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -501,4 +501,4 @@ void main() {
501
501
  color.b += max != color.b ? (max - color.b) * amt : 0.00;
502
502
  gl_FragColor = color;
503
503
  }
504
- `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let r=0;r<e.length;r+=4){const i=e[r],o=e[r+1],a=e[r+2],h=Math.max(i,o,a),l=(i+o+a)/3,c=2*Math.abs(h-l)/255*s;e[r]+=h!==i?(h-i)*c:0,e[r+1]+=h!==o?(h-o)*c:0,e[r+2]+=h!==a?(h-a)*c:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}y(nr,"type","Vibrance"),y(nr,"defaults",{vibrance:0}),y(nr,"uniformLocations",["uVibrance"]),P.setClass(nr);function Mo(n){const t=n&&n.bounds;if(t&&typeof t.width=="number"&&typeof t.height=="number"&&t.width>0&&t.height>0)return{left:typeof t.left=="number"?t.left:0,top:typeof t.top=="number"?t.top:0,width:t.width,height:t.height};if(Array.isArray(n==null?void 0:n.children))for(const e of n.children){const s=Mo(e);if(s)return s}return null}function Jh(n,t="split"){if(!Array.isArray(n))return[];const e=(o,a)=>{for(const h of o){if(h&&h.name===a&&h.type==="Group")return h;if(Array.isArray(h==null?void 0:h.children)){const l=e(h.children,a);if(l)return l}}return null},s=e(n,t),r=s&&s.children||[],i=[];for(const o of r){if(!o||o.type!=="Group"||o.id==null)continue;const a=Mo(o);a&&i.push({id:Number(o.id),name:o.name||"",bounds:a})}return i}function Qh(n){return new Promise((t,e)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>t(s),s.onerror=()=>e(new Error("图片加载失败: "+n.slice(0,60))),s.src=n})}const Zh=5,tl="#ff0000",el=9,sl=7,rl="#ff0000",il="#ffffff",nl=8,ol=16,al=250;function hl(n,t,e,s,r,i,o,a,h,l){if(o<=0||a<=0||h<=0)return;const c=document.createElement("canvas");c.width=o,c.height=a;const u=c.getContext("2d");if(!u)return;u.drawImage(t,0,0,e,s,0,0,o,a);const g=l.replace("#",""),d=parseInt(g.slice(0,2),16)||0,f=parseInt(g.slice(2,4),16)||0,p=parseInt(g.slice(4,6),16)||0,m=u.getImageData(0,0,o,a),v=m.data;let w=0,C=0,x=0;for(let D=0;D<v.length;D+=4)if(v[D+3]>10){v[D]=d,v[D+1]=f,v[D+2]=p,v[D+3]=255;const A=D>>2;w+=A%o,C+=A/o|0,x++}else v[D]=v[D+1]=v[D+2]=v[D+3]=0;u.putImageData(m,0,0);const _=o+h*2,b=a+h*2,O=document.createElement("canvas");O.width=_,O.height=b;const T=O.getContext("2d");if(!T)return;for(let D=1;D<=h;D++)for(let A=0;A<360;A+=30){const L=A*Math.PI/180;T.drawImage(c,h+Math.round(Math.cos(L)*D),h+Math.round(Math.sin(L)*D))}const k=T.getImageData(0,0,_,b).data;if(T.globalCompositeOperation="destination-out",T.drawImage(c,h,h),T.globalCompositeOperation="source-over",n.drawImage(O,r-h,i-h),x>0){const D=2*(o+a);let A=Math.round(D/al);A=Math.max(nl,Math.min(ol,A));const L=w/x+h,I=C/x+h,j=Math.ceil(Math.hypot(_,b)),U=[];for(let N=0;N<A;N++){const H=N/A*Math.PI*2,$=Math.cos(H),tt=Math.sin(H);let K=-1,ft=-1;for(let at=1;at<=j;at++){const E=Math.round(L+$*at),M=Math.round(I+tt*at);if(E<0||M<0||E>=_||M>=b)break;k[(M*_+E)*4+3]>0&&(K=E,ft=M)}K>=0&&U.push({x:r-h+K,y:i-h+ft})}ll(n,U)}}function ll(n,t){if(t.length){n.save(),n.font=`bold ${sl}px sans-serif`,n.textAlign="center",n.textBaseline="middle";for(let e=0;e<t.length;e++){const{x:s,y:r}=t[e];n.beginPath(),n.arc(s,r,el,0,Math.PI*2),n.fillStyle=rl,n.fill(),n.fillStyle=il,n.fillText(String(e+1),s,r)}n.restore()}}async function cl(n,t,e="png",s){const r=Number(t==null?void 0:t.canvasWidth)||0,i=(t==null?void 0:t.canvasHeight)!=null?Number(t.canvasHeight):r;if(!(r>0&&i>0))throw new Error("productJson.canvasWidth/canvasHeight 无效");const o=Jh((t==null?void 0:t.layerList)||[],"split");if(!o.length)throw new Error("productJson 中未解析到 split 分片结构");const a=new Map,h=new Map;for(const m of n||[])m!=null&&m.name&&a.set(m.name,m),(m==null?void 0:m.id)!=null&&h.set(String(m.id),m);const l=document.createElement("canvas");l.width=r,l.height=i;const c=l.getContext("2d");if(!c)throw new Error("无法创建画布 2D 上下文");e==="jpeg"&&(c.fillStyle="#ffffff",c.fillRect(0,0,r,i));const u=[],g=[],d=[];try{for(const m of o){const v=m.name&&a.get(m.name)||h.get(String(m.id));if(!(v!=null&&v.blob)){g.push(`${m.name||m.id}(无位图)`);continue}const{left:w,top:C,width:x,height:_}=m.bounds;if(x<=0||_<=0){g.push(`${m.name||m.id}(槽位无效)`);continue}const b=URL.createObjectURL(v.blob);d.push(b);const O=await Qh(b),T=O.naturalWidth||1,k=O.naturalHeight||1,D=Math.max(x/T,_/k),A=Math.round(T*D),L=Math.round(k*D),I=Math.round(w+(x-A)/2),j=Math.round(C+(_-L)/2);c.save(),c.beginPath(),c.rect(w,C,x,_),c.clip(),c.drawImage(O,0,0,T,k,I,j,A,L),s==="pillow3d"&&hl(c,O,T,k,I,j,A,L,Zh,tl),c.restore(),u.push(m.name||String(m.id))}}finally{d.forEach(m=>{try{URL.revokeObjectURL(m)}catch{}})}const f=e==="jpeg"?"image/jpeg":"image/png";return{blob:await new Promise((m,v)=>{l.toBlob(w=>w?m(w):v(new Error("canvas.toBlob 返回空")),f,e==="jpeg"?1:void 0)}),canvasWidth:r,canvasHeight:i,drawn:u,skipped:g}}const ul=0,yi="single",gl="full",ko="#1677ff";function dl(n){var t;return((t=n==null?void 0:n.customData)==null?void 0:t.patternRenderMode)===yi?yi:gl}function fl(n){return dl(n)===yi}function or(n,t){return t?(n%t+t)%t:0}function pl(n){var l,c,u;const t=(n==null?void 0:n.customData)||{},e=Number((l=n==null?void 0:n.patternTileWidth)!=null?l:t.patternTileWidth)||100,s=Number((c=n==null?void 0:n.patternTileHeight)!=null?c:t.patternTileHeight)||100,r=n==null?void 0:n.patternScale,i=typeof r=="number"&&r>0&&r<=2?Math.max(.01,r):Math.max(.01,(Number((u=t.patternScale)!=null?u:100)||100)/100),o=Math.max(1,e*i),a=Math.max(1,s*i),h=vi(n);return{tileW:o,tileH:a,strideW:o+h.x,strideH:a+h.y,scale:i}}function Do(n){var m,v,w,C;const t=pl(n),{strideW:e,strideH:s}=t,r=Number(n==null?void 0:n.width)||0,i=Number(n==null?void 0:n.height)||0,o=(m=n==null?void 0:n.getCenterPoint)==null?void 0:m.call(n),a=Number(o==null?void 0:o.x)||(Number(n==null?void 0:n.left)||0)+r/2,h=Number(o==null?void 0:o.y)||(Number(n==null?void 0:n.top)||0)+i/2,l=a-r/2,c=h-i/2,u=typeof(n==null?void 0:n.patternPhaseX)=="number"?n.patternPhaseX:typeof((v=n==null?void 0:n.customData)==null?void 0:v.patternPhaseX)=="number"?n.customData.patternPhaseX:0,g=typeof(n==null?void 0:n.patternPhaseY)=="number"?n.patternPhaseY:typeof((w=n==null?void 0:n.customData)==null?void 0:w.patternPhaseY)=="number"?n.customData.patternPhaseY:0,d=l-or(l-u,e),f=c-or(c-g,s),p=(n==null?void 0:n.patternMode)||((C=n==null?void 0:n.customData)==null?void 0:C.patternMode)||"";return{...t,centerX:a,centerY:h,sceneLeft:l,sceneTop:c,startSceneX:d,startSceneY:f,startX:d-a,startY:f-h,phaseX:u,phaseY:g,mode:p}}function ml(n,t,e){const s=Do(n),{strideW:r,strideH:i,tileW:o,tileH:a,startSceneX:h,startSceneY:l,centerX:c,centerY:u,phaseX:g,phaseY:d,mode:f}=s,p=Eo(n);if(p%360!==0){const x=p*Math.PI/180,_=Math.cos(x),b=Math.sin(x),O=t-c,T=e-u,k=O*_+T*b,D=-O*b+T*_,A=g-c,L=d-u,I=A*_+L*b,j=-A*b+L*_,U=Math.floor((k-I)/r),N=Math.floor((D-j)/i);let H=I+U*r,$=j+N*i;f==="brick-x"&&Math.round(($-j)/i)&1&&(H+=r/2),f==="brick-y"&&Math.round((H-I)/r)&1&&($+=i/2);const tt=c+H*_-$*b,K=u+H*b+$*_;return{left:tt,top:K,tileW:o,tileH:a}}const m=Math.floor((t-h)/r),v=Math.floor((e-l)/i);let w=h+m*r,C=l+v*i;return f==="brick-x"&&Math.round((C-d)/i)&1&&(w+=r/2),f==="brick-y"&&Math.round((w-g)/r)&1&&(C+=i/2),{left:w,top:C,tileW:o,tileH:a}}function Ne(n,t=ul){const e=Number(n);return Number.isFinite(e)?Math.max(0,e):t}function ar(n){const t=n,e=(t==null?void 0:t.naturalWidth)||(t==null?void 0:t.videoWidth)||(t==null?void 0:t.width)||0,s=(t==null?void 0:t.naturalHeight)||(t==null?void 0:t.videoHeight)||(t==null?void 0:t.height)||0;return{width:e,height:s}}function yl(n,t,e){let s=e*2654435761>>>0;return s=(s<<5)-s+n|0,s=(s<<5)-s+t|0,s>>>0}function vi(n){var e,s;const t=(n==null?void 0:n.customData)||{};return{x:Ne((e=n==null?void 0:n.patternGapX)!=null?e:t.patternGapX),y:Ne((s=n==null?void 0:n.patternGapY)!=null?s:t.patternGapY)}}function hr(n){const t=Number(n);return Number.isFinite(t)?(t%360+360)%360:0}function Eo(n){const t=(n==null?void 0:n.customData)||{},e=[n==null?void 0:n.patternTileAngle,t.patternTileAngle,t.originalAngle];for(const s of e){const r=Number(s);if(Number.isFinite(r)&&r!==0)return hr(r)}return 0}function vl(n){var e,s,r,i;const t=(n==null?void 0:n.customData)||{};return{flipX:!!((s=(e=n==null?void 0:n.patternTileFlipX)!=null?e:t.patternTileFlipX)!=null?s:t.originalFlipX),flipY:!!((i=(r=n==null?void 0:n.patternTileFlipY)!=null?r:t.patternTileFlipY)!=null?i:t.originalFlipY),angle:Eo(n)}}function xl(n,t,e,s,r,i,o=!1,a=!1,h=0){const l=hr(h),c=.75;if(!o&&!a&&l===0){n.drawImage(t,e-c,s-c,r+c*2,i+c*2);return}n.save(),n.translate(e+r/2,s+i/2),l&&n.rotate(l*Math.PI/180),n.scale(o?-1:1,a?-1:1),n.drawImage(t,-r/2-c,-i/2-c,r+c*2,i+c*2),n.restore()}class lr extends Et{constructor(t={}){var e,s,r;super({...t,originX:"left",originY:"top",objectCaching:!1,hasControls:!1,hasBorders:!1,lockScalingX:!0,lockScalingY:!0,lockRotation:!0,fill:(e=t.fill)!=null?e:"",stroke:(s=t.stroke)!=null?s:null,borderColor:ko,cornerColor:ko,cornerStrokeColor:"#ffffff",transparentCorners:!1,borderScaleFactor:2}),this.patternElement=(r=t.patternElement)!=null?r:null,this.patternTileWidth=Number(t.patternTileWidth)||ar(this.patternElement).width||100,this.patternTileHeight=Number(t.patternTileHeight)||ar(this.patternElement).height||100,this.patternScale=Number(t.patternScale)||1,this.patternPhaseX=Number(t.patternPhaseX)||0,this.patternPhaseY=Number(t.patternPhaseY)||0,this.patternGapX=Ne(t.patternGapX),this.patternGapY=Ne(t.patternGapY),this.patternMode=t.patternMode||"",this.patternSeed=Number(t.patternSeed)||1,this.patternTileFlipX=!!t.patternTileFlipX,this.patternTileFlipY=!!t.patternTileFlipY,this.patternTileAngle=hr(t.patternTileAngle),this.patternActiveTileLeft=null,this.patternActiveTileTop=null}setActiveDragTile(t,e){this.patternActiveTileLeft=t,this.patternActiveTileTop=e,this.dirty=!0}clearActiveDragTile(){this.patternActiveTileLeft==null&&this.patternActiveTileTop==null||(this.patternActiveTileLeft=null,this.patternActiveTileTop=null,this.dirty=!0)}setPatternElement(t){this.patternElement=t;const e=ar(t);!this.patternTileWidth&&e.width&&(this.patternTileWidth=e.width),!this.patternTileHeight&&e.height&&(this.patternTileHeight=e.height),this.dirty=!0}setPatternPhase(t,e){this.patternPhaseX=t,this.patternPhaseY=e,this.customData={...this.customData||{},patternPhaseX:t,patternPhaseY:e},this.dirty=!0}setPatternGap(t,e){this.patternGapX=Ne(t),this.patternGapY=Ne(e),this.customData={...this.customData||{},patternGapX:this.patternGapX,patternGapY:this.patternGapY},this.dirty=!0}toObject(t=[]){return super.toObject(["patternTileWidth","patternTileHeight","patternScale","patternPhaseX","patternPhaseY","patternGapX","patternGapY","patternMode","patternSeed","patternTileFlipX","patternTileFlipY","patternTileAngle",...t])}_render(t){var N,H,$,tt,K,ft,at,E;const e=this.patternElement;if(!e){super._render(t);return}const s=Number(this.width)||0,r=Number(this.height)||0,i=Do(this),{tileW:o,tileH:a,strideW:h,strideH:l,centerX:c,centerY:u}=i;let g=i.startX,d=i.startY,f=i.phaseX,p=i.phaseY;const m=i.mode,v=-s/2,w=-r/2;let C=s/2,x=r/2;t.save(),t.beginPath(),t.rect(v,w,s,r),t.clip(),t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const{flipX:_,flipY:b,angle:O}=vl(this),T=(M,F)=>({flipX:_!==M,flipY:b!==F}),k=vi(this),D=O*Math.PI/180,A=O%360!==0;if(A){t.rotate(D);const M=Math.cos(D),F=Math.sin(D),X=f-c,W=p-u,R=X*M+W*F,J=-X*F+W*M;f=R+c,p=J+u;const it=Math.abs(M),Xt=Math.abs(F),Wt=s/2*it+r/2*Xt+h,Te=s/2*Xt+r/2*it+l;C=Wt,x=Te,g=-Wt-or(-Wt-R,h),d=-Te-or(-Te-J,l)}const L=(M,F,X,W)=>{xl(t,e,M,F,o,a,X,W,0)};if(fl(this)){const M=f-c,F=p-u;if(L(M,F,_,b),((H=(N=this.canvas)==null?void 0:N.getActiveObject)==null?void 0:H.call(N))===this){const W=Math.abs(Number((tt=($=this.canvas)==null?void 0:$.getZoom)==null?void 0:tt.call($))||1);t.save(),t.strokeStyle="#1677ff",t.lineWidth=10/W,t.setLineDash([18/W,15/W]),t.strokeRect(M,F,o,a),t.restore()}t.restore();return}const I=ar(e);if((m===""||m==="grid")&&k.x===0&&k.y===0&&!_&&!b&&hr(O)===0&&I.width>0&&I.height>0){const M=t.createPattern(e,"repeat");if(M){const F=f-c,X=p-u;M.setTransform(new DOMMatrix([o/I.width,0,0,a/I.height,F,X])),t.fillStyle=M,t.fillRect(v,w,s,r)}}else if(m==="brick-x")for(let M=d-l;M<x;M+=l){const F=u+M,W=Math.round((F-p)/l)&1?h/2:0;for(let R=g-h;R<C;R+=h)L(R+W,M,_,b)}else if(m==="brick-y")for(let M=d-l;M<x;M+=l)for(let F=g-h;F<C;F+=h){const X=c+F,R=Math.round((X-f)/h)&1?l/2:0;L(F,M+R,_,b)}else if(m==="mirror")for(let M=d;M<x;M+=l){const F=u+M,W=!!(Math.round((F-p)/l)&1);for(let R=g;R<C;R+=h){const J=c+R,Xt=!!(Math.round((J-f)/h)&1),{flipX:Wt,flipY:Te}=T(Xt,W);L(R,M,Wt,Te)}}else if(m==="random"){const M=this.patternSeed||1;for(let F=d;F<x;F+=l){const X=u+F,W=Math.round((X-p)/l);for(let R=g;R<C;R+=h){const J=c+R,it=Math.round((J-f)/h),Xt=yl(W,it,M),{flipX:Wt,flipY:Te}=T(!!(Xt&1),!!(Xt&2));L(R,F,Wt,Te)}}}else for(let M=d;M<x;M+=l)for(let F=g;F<C;F+=h)L(F,M,_,b);if(((ft=(K=this.canvas)==null?void 0:K.getActiveObject)==null?void 0:ft.call(K))===this){let M,F;if(this.patternActiveTileLeft!=null&&this.patternActiveTileTop!=null)M=this.patternActiveTileLeft,F=this.patternActiveTileTop;else{const J=ml(this,c,u);M=J.left,F=J.top}let X,W;if(A){const J=Math.cos(D),it=Math.sin(D),Xt=M-c,Wt=F-u;X=Xt*J+Wt*it,W=-Xt*it+Wt*J}else X=M-c,W=F-u;const R=Math.abs(Number((E=(at=this.canvas)==null?void 0:at.getZoom)==null?void 0:E.call(at))||1);t.save(),t.strokeStyle="#1677ff",t.lineWidth=10/R,t.setLineDash([18/R,15/R]),t.strokeRect(X,W,o,a),t.restore()}t.restore()}}xr(lr,"type","pattern-layer"),P.setClass(lr);function Po(n){var t;return!!((t=n==null?void 0:n.customData)!=null&&t.isPatternRect)||n instanceof lr||(n==null?void 0:n.type)===lr.type}function _l(n,t){return!(n!=null&&n.patternElement)||!t||!Po(n)?!1:(typeof t.setPatternElement=="function"?t.setPatternElement(n.patternElement):t.patternElement=n.patternElement,t.patternTileWidth=n.patternTileWidth,t.patternTileHeight=n.patternTileHeight,t.patternScale=n.patternScale,t.patternPhaseX=n.patternPhaseX,t.patternPhaseY=n.patternPhaseY,t.patternGapX=n.patternGapX,t.patternGapY=n.patternGapY,t.patternMode=n.patternMode,t.patternSeed=n.patternSeed,t.patternTileFlipX=n.patternTileFlipX,t.patternTileFlipY=n.patternTileFlipY,t.patternTileAngle=n.patternTileAngle,t.dirty=!0,!0)}const wl=n=>Number.isFinite(n)?Math.min(200,Math.max(1,Math.round(n))):100,Sl=n=>{var s,r;if(!n)return null;const t=(s=n.width)!=null?s:n.naturalWidth,e=(r=n.height)!=null?r:n.naturalHeight;return!t||!e?null:{width:t,height:e}};function Cl(n,t,e){var o,a;const s=(...h)=>{for(const l of h){const c=Number(l);if(Number.isFinite(c)&&c>0)return c}return null},r=(o=s(n==null?void 0:n.patternTileWidth,n==null?void 0:n.originalWidth,e==null?void 0:e.patternTileWidth,t==null?void 0:t.width))!=null?o:100,i=(a=s(n==null?void 0:n.patternTileHeight,n==null?void 0:n.originalHeight,e==null?void 0:e.patternTileHeight,t==null?void 0:t.height))!=null?a:100;return{tw:r,th:i}}class be{static getItem(t){if(!this.hasStorage)return null;try{return localStorage.getItem(t)}catch(e){return console.warn(`读取 localStorage 失败 [${t}]:`,e),null}}static setItem(t,e){if(!this.hasStorage)return!1;try{return localStorage.setItem(t,e),!0}catch(s){return console.warn(`写入 localStorage 失败 [${t}]:`,s),!1}}static removeItem(t){if(!this.hasStorage)return!1;try{return localStorage.removeItem(t),!0}catch(e){return console.warn(`删除 localStorage 失败 [${t}]:`,e),!1}}static clear(){if(!this.hasStorage)return!1;try{return localStorage.clear(),!0}catch(t){return console.warn("清空 localStorage 失败:",t),!1}}static isAvailable(){return this.hasStorage}}xr(be,"hasStorage",typeof window!="undefined"&&typeof localStorage!="undefined");class cr{static isBrowser(){return typeof window!="undefined"}static isWorker(){return typeof WorkerGlobalScope!="undefined"}static hasLocalStorage(){return this.isBrowser()&&typeof localStorage!="undefined"}static hasCanvas(){return this.isBrowser()&&typeof HTMLCanvasElement!="undefined"}static getDomain(){return this.isBrowser()?window.location.hostname:"localhost"}static getOrigin(){return this.isBrowser()?window.location.origin:"http://localhost"}}const vr=class vr{static parse(t){try{const e=cr.getOrigin();return new URL(t,e)}catch{return null}}static addParam(t,e,s){const r=this.parse(t);return!r||r.searchParams.has(e)?t:(r.searchParams.set(e,s),this.formatUrl(t,r))}static removeParam(t,e){const s=this.parse(t);return!s||!s.searchParams.has(e)?t:(s.searchParams.delete(e),this.formatUrl(t,s))}static hasParam(t,e){var r;const s=this.parse(t);return(r=s==null?void 0:s.searchParams.has(e))!=null?r:!1}static forceHttpsAsset(t){if(typeof t!="string"||!/^http:\/\//i.test(t))return t;const e=t.slice(t.indexOf("://")+3),s=e.split(/[/?#]/)[0].split("@").pop().split(":")[0];return vr.HTTPS_ASSET_HOST_RE.test(s)?"https://"+e:t}static formatUrl(t,e){const s=/^(https?:)?\/\//i.test(t),r=t.startsWith("//");return s?e.toString():r?e.toString().replace(/^https?:/,""):`${e.pathname}${e.search}${e.hash}`}static isDataUrl(t){var e;return(e=t==null?void 0:t.startsWith("data:"))!=null?e:!1}static isBlobUrl(t){var e;return(e=t==null?void 0:t.startsWith("blob:"))!=null?e:!1}};xr(vr,"HTTPS_ASSET_HOST_RE",/(^|\.)(r480\.cn|aliyuncs\.com)$/i);let dt=vr;const bl=new Map,Tl=new Map;function Ol(){bl.clear(),Tl.clear()}const Ml=new Map,kl=new Map;function Dl(){Ml.clear(),kl.clear()}const xi="file_token",_i="file_token_expire_time",El=60*1e3;function wi(){return be.getItem(xi)}function Pl(n=El){if(!wi())return!0;const e=be.getItem(_i);if(!e)return!1;const s=Number(e);return Date.now()+n>s}function Ao(n,t){if(be.setItem(xi,n),typeof t=="number"&&t>0){const e=Date.now()+t*1e3;be.setItem(_i,String(e))}}function Al(){be.removeItem(xi),be.removeItem(_i),Ol(),Dl()}async function Fo(n){var s,r;const t=await n(),e=(s=t==null?void 0:t.data)==null?void 0:s.data;return((r=t==null?void 0:t.data)==null?void 0:r.code)===200&&(e!=null&&e.file_token)?(Ao(e.file_token,e.expires_in),e.file_token):null}let Fl=null,Si=null;function Lo(n,t){Si=n,n&&Ao(n)}function Io(){return cr.isBrowser()?Fl:null}async function Ci(){if(Si)return Si;if(!cr.isBrowser())return wi();const n=wi();if(n&&!Pl())return n;try{const t=await Io();if(n&&(t!=null&&t.fetchFileTokenRefresh)){const e=await Fo(t.fetchFileTokenRefresh);if(e)return e}}catch{}try{const t=Io();return t!=null&&t.fetchFileToken?await Fo(t.fetchFileToken):null}catch{return null}}const jo=["/files/","/pd/","/pm/","/test/","/test-local/","/wd/","/whiteboard/"];function Ro(n){if(!n||dt.isDataUrl(n)||dt.isBlobUrl(n))return!1;const t=dt.parse(n);return t?jo.some(e=>t.pathname.includes(e))&&!dt.hasParam(n,"fileToken"):jo.some(e=>n.includes(e))&&!n.includes("fileToken=")}function bi(n,t){return n=dt.forceHttpsAsset(n),!t||!Ro(n)?n:dt.addParam(n,"fileToken",t)}function Ll(n){return dt.removeParam(n,"fileToken")}function Bo(n,t){const e=dt.forceHttpsAsset(n);return!t||dt.hasParam(e,"fileToken")?e:dt.addParam(e,"fileToken",t)}async function Il(n){if(!Ro(n))return n;const t=await Ci();return bi(n,t)}const Ti=new Map;function jl(n,t){return`${String((t==null?void 0:t.method)||"GET").toUpperCase()}\0${n}`}async function $o(n,t,e){if(!cr.isBrowser())return fetch(n,t);const s=dt.forceHttpsAsset(Ll(n)),r=(e==null?void 0:e.forceToken)===!0,i=jl(s,t)+"";let o=Ti.get(i);return o||(o=(async()=>{try{const h=r?Bo(s,await Ci()):await Il(s),l=3;let c=null;for(let u=0;u<l;u++)try{let g;try{g=await fetch(h,t)}catch{if((t==null?void 0:t.mode)==="cors")g=await fetch(h,{...t,cache:"no-store"});else throw new Error("fetch failed")}if(g.status===401){Al();const d=await Ci(),f=r?Bo(s,d):bi(s,d);return await fetch(f,t)}if(g.status>=500&&u<l-1){c=new Error(`HTTP ${g.status}`),await new Promise(d=>setTimeout(d,300*Math.pow(2,u)));continue}return g}catch(g){if(c=g,u<l-1){await new Promise(d=>setTimeout(d,300*Math.pow(2,u)));continue}}throw c!=null?c:new Error("fetchWithFileToken failed")}finally{Ti.delete(i)}})(),Ti.set(i,o)),(await o).clone()}const Oi="all";function Rl(n){if(!(!n||n===Oi))return n}function Bl(n,t){if(n==null)return!0;if(Array.isArray(n)){if(n.length===0||n.includes(Oi))return!0;const s=n.filter(r=>r!==Oi);return s.length===0||t==null?!0:s.includes(t)}const e=Rl(n);return!e||t==null?!0:t===e}function Xo(n){const t=n==null?void 0:n.bounds;if(t&&typeof t.width=="number"&&typeof t.height=="number"&&t.width>0&&t.height>0)return{left:typeof t.left=="number"?t.left:0,top:typeof t.top=="number"?t.top:0,width:t.width,height:t.height};if(Array.isArray(n.children))for(const e of n.children){const s=Xo(e);if(s)return s}return null}const $l=(n,t)=>{var r;const e=Math.max(1,Number(t.canvasWidth)||1);let s=Number(t.canvasHeight);if(!s||!Number.isFinite(s)){const i=Array.isArray(n)?n.find(o=>(o==null?void 0:o.name)==="bg"):null;s=Math.max(1,Number((r=i==null?void 0:i.bounds)==null?void 0:r.height)||e)}return{psdW:e,psdH:s}},Xl=(n,t,e,s)=>{const r=Math.max(1,n),i=Math.max(1,t),o=Math.max(1,e),a=Math.max(1,s),h=Math.min(o/r,a/i),l=(o-r*h)/2,c=(a-i*h)/2;return{scale:h,offsetX:l,offsetY:c}},Wl=(n,t,e,s,r)=>{const{scale:i,offsetX:o,offsetY:a}=Xl(t,e,s,r);return{left:o+n.left*i,top:a+n.top*i,width:n.width*i,height:n.height*i}},Yl=(n,t="split")=>{var o;if(!Array.isArray(n))return[];const e=(a,h="split")=>{for(const l of a){if((l==null?void 0:l.name)===h&&(l==null?void 0:l.type)==="Group")return l;if(Array.isArray(l.children)){const c=e(l.children);if(c)return c}}return null},s=e(n,t),r=(o=s==null?void 0:s.children)!=null?o:[],i=[];for(const a of r){if((a==null?void 0:a.type)!=="Group"||a.id==null)continue;const h=Xo(a);h&&i.push({id:a.id,name:a.name||"",bounds:h})}return i},Nl=(n,t)=>{var a,h,l;const r=((a=n==null?void 0:n.data)!=null?a:[]).filter(c=>Bl(t,c==null?void 0:c.size)).find(c=>(c==null?void 0:c.type)==="SPLIT");if(!(r!=null&&r.jsonURL))return null;const i=(h=r.resources)!=null?h:[],o=new Map;for(const c of i){if(!(c!=null&&c.groupId))continue;const u=String(c.groupId);let g=o.get(u);g||(g={groupId:u,groupName:String((l=c.groupName)!=null?l:""),maskUrl:"",maskWidth:0,maskHeight:0},o.set(u,g)),c.groupName&&(g.groupName=String(c.groupName)),c.type==="MASK"&&c.url&&(g.maskUrl=c.url,g.maskWidth=Number(c.width)||0,g.maskHeight=Number(c.height)||0),c.type==="DOTTED_LINE"&&c.url&&(g.dottedLineUrl=c.url,g.dottedLineWidth=Number(c.width)||0,g.dottedLineHeight=Number(c.height)||0)}for(const[c,u]of[...o]){const g=!!(u.maskUrl&&u.maskWidth&&u.maskHeight),d=!!(u.dottedLineUrl&&u.dottedLineWidth&&u.dottedLineHeight)||!!(u.dottedLineUrl&&g);!g&&!d&&o.delete(c)}return o.size?{jsonURL:r.jsonURL,slicesByGroupId:o}:null},ur=(n,t="image/png",e)=>new Promise((s,r)=>{n.toBlob(i=>{if(!i){r(new Error("canvas toBlob failed"));return}s(i)},t,e)});function Hl(n,t){if(t)return;const e=n.backgroundColor;return e!=null&&e!==""?String(e):"#ffffff"}const Wo="guide-resource",gr=(n,t)=>{var s;const e=(s=n==null?void 0:n.customData)==null?void 0:s.role;return e===t||e==="guide"||e==="grid"},Gl=n=>{var e;const t=(e=n==null?void 0:n.customData)==null?void 0:e.guideKind;return t==="split-piece-mask"||t==="split-piece-dotted"};function Yo(n,t=Wo){var g,d,f;const e=Math.max(1,typeof n.getWidth=="function"?n.getWidth():1),s=Math.max(1,typeof n.getHeight=="function"?n.getHeight():1);let r=0,i=0,o=e,a=s;for(const p of(d=(g=n.getObjects)==null?void 0:g.call(n))!=null?d:[])if(!(gr(p,t)&&!Gl(p))&&p.type!=="activeSelection"&&!((f=p.customData)!=null&&f.isPatternRect)&&!p.group&&typeof p.getBoundingRect=="function")try{const m=p.getBoundingRect(!0,!0);if(!m||!Number.isFinite(m.width)||!Number.isFinite(m.height))continue;r=Math.min(r,m.left),i=Math.min(i,m.top),o=Math.max(o,m.left+m.width),a=Math.max(a,m.top+m.height)}catch{}const l=n.backgroundImage;if(l&&typeof l.getBoundingRect=="function")try{const p=l.getBoundingRect(!0,!0);p&&Number.isFinite(p.width)&&Number.isFinite(p.height)&&(r=Math.min(r,p.left),i=Math.min(i,p.top),o=Math.max(o,p.left+p.width),a=Math.max(a,p.top+p.height))}catch{}const c=Math.max(1,Math.ceil(o-r)),u=Math.max(1,Math.ceil(a-i));return{minL:r,minT:i,maxR:o,maxB:a,width:c,height:u}}async function Vl(n,t,e,s){var c;const r=document.createElement("canvas"),i=Yo(n,t),o=i.width,a=i.height,h=n;let l=null;try{l=new Le(r,{width:o,height:a,renderOnAddRemove:!1,enableRetinaScaling:!!h.enableRetinaScaling,backgroundColor:Hl(h,s)}),l.setViewportTransform([1,0,0,1,-i.minL,-i.minT]);const u=h.backgroundImage;if(!s&&u&&typeof u.clone=="function")try{l.backgroundImage=await u.clone()}catch{}const g=performance.now();for(const m of n.getObjects())if(!gr(m,t)&&m.type!=="activeSelection")try{const v=await m.clone();Po(v)&&_l(m,v);const w=m.group;if(w){const C=typeof m.calcOwnMatrix=="function"?m.calcOwnMatrix():m.calcTransformMatrix(),x=typeof w.calcTransformMatrix=="function"?w.calcTransformMatrix():null,_=x?oo.multiplyTransformMatrices(x,C):m.calcTransformMatrix(),b=oo.qrDecompose(_);v.set({originX:"center",originY:"center",left:b.translateX,top:b.translateY,angle:b.angle,scaleX:b.scaleX,scaleY:b.scaleY,skewX:b.skewX,skewY:b.skewY,flipX:m.flipX,flipY:m.flipY}),(c=v.setCoords)==null||c.call(v)}l.add(v)}catch(v){return console.warn("[fabricMainCanvasSnapshot] offscreen clone failed:",m.type,v),null}const d=Math.round(performance.now()-g);l.requestRenderAll(),await new Promise(m=>requestAnimationFrame(()=>requestAnimationFrame(()=>m())));const f=l;if(typeof f.toBlob=="function"){const m=await f.toBlob({format:"png",quality:1,multiplier:e,enableRetinaScaling:!!l.enableRetinaScaling});return m!=null?m:null}const p=l.lowerCanvasEl;if(!p)return null;if(e<1){const m=Math.max(1,Math.floor(p.width*e)),v=Math.max(1,Math.floor(p.height*e)),w=document.createElement("canvas");w.width=m,w.height=v;const C=w.getContext("2d");return C?(C.imageSmoothingEnabled=!0,C.imageSmoothingQuality="medium",C.drawImage(p,0,0,p.width,p.height,0,0,m,v),await ur(w,"image/png")):null}return await ur(p,"image/png")}catch(u){return console.warn("[fabricMainCanvasSnapshot] offscreen export failed:",u),null}finally{if(l)try{await l.dispose()}catch{}}}async function zl(n,t,e){var o,a,h,l;const s=n;if(typeof s.toBlob=="function"){let c;try{c=n.getActiveObject(),c&&((o=s._discardActiveObject)==null||o.call(s));const u=await s.toBlob({format:"png",quality:1,multiplier:e,enableRetinaScaling:!!s.enableRetinaScaling,filter:g=>!gr(g,t)});return u!=null?u:null}catch(u){return console.warn("[fabricMainCanvasSnapshot] toBlob(filter) 导出失败:",u),null}finally{try{c&&((a=s._setActiveObject)==null||a.call(s,c)),n.renderAll()}catch{}}}const r=[];let i;try{for(const u of n.getObjects())gr(u,t)&&(r.push({obj:u,visible:u.visible!==!1}),u.set("visible",!1));i=n.getActiveObject(),i&&((h=n._discardActiveObject)==null||h.call(n)),n.renderAll();const c=n.lowerCanvasEl;if(!c)return null;if(e<1){const u=Math.max(1,Math.floor(c.width*e)),g=Math.max(1,Math.floor(c.height*e)),d=document.createElement("canvas");d.width=u,d.height=g;const f=d.getContext("2d");return f?(f.imageSmoothingEnabled=!0,f.imageSmoothingQuality="medium",f.drawImage(c,0,0,c.width,c.height,0,0,u,g),await ur(d,"image/png")):null}return await ur(c,"image/png")}catch(c){return console.warn("[fabricMainCanvasSnapshot] 导出主画布失败:",c),null}finally{for(const{obj:c,visible:u}of r)try{c.set("visible",u)}catch{}try{i&&((l=n._setActiveObject)==null||l.call(n,i)),n.renderAll()}catch{}}}async function No(n,t){var h;const e=(h=t==null?void 0:t.guideResourceRole)!=null?h:Wo,s=(t==null?void 0:t.multiplier)!=null&&t.multiplier>0?t.multiplier:1,r=!!(t!=null&&t.useIdentityViewport),i=(t==null?void 0:t.transparentBackground)===!0;if(r){const l=await Vl(n,e,s,i);if(l)return l;if(i)return console.warn("[fabricMainCanvasSnapshot] 透明底离屏导出失败,不再回退主画布直读(会带白底)"),null;console.warn("[fabricMainCanvasSnapshot] 离屏导出失败,回退为临时单位视口")}let o=null;const a=()=>{if(!(!r||!o||o.length<6))try{n.setViewportTransform(o),n.requestRenderAll()}catch{}};try{if(r){const c=n.viewportTransform;o=Array.isArray(c)&&c.length>=6?[...c]:[1,0,0,1,0,0],n.setViewportTransform([1,0,0,1,0,0]),n.requestRenderAll(),await new Promise(u=>requestAnimationFrame(()=>requestAnimationFrame(()=>u())))}return await zl(n,e,s)}finally{a()}}const dr=[{family:"Oswald",googleSlug:"Oswald",category:"sans-serif"},{family:"EB Garamond",googleSlug:"EB+Garamond",category:"serif"},{family:"Itim",googleSlug:"Itim",category:"handwriting"},{family:"Tangerine",googleSlug:"Tangerine",category:"handwriting"},{family:"Pinyon Script",googleSlug:"Pinyon+Script",category:"handwriting"},{family:"Arizonia",googleSlug:"Arizonia",category:"handwriting"},{family:"Ballet",googleSlug:"Ballet",category:"handwriting"},{family:"Roboto",googleSlug:"Roboto",category:"sans-serif"},{family:"Open Sans",googleSlug:"Open+Sans",category:"sans-serif"},{family:"Montserrat",googleSlug:"Montserrat",category:"sans-serif"},{family:"Lato",googleSlug:"Lato",category:"sans-serif"},{family:"Poppins",googleSlug:"Poppins",category:"sans-serif"},{family:"Raleway",googleSlug:"Raleway",category:"sans-serif"},{family:"Inter",googleSlug:"Inter",category:"sans-serif"},{family:"Bebas Neue",googleSlug:"Bebas+Neue",category:"sans-serif"},{family:"Anton",googleSlug:"Anton",category:"sans-serif"},{family:"Playfair Display",googleSlug:"Playfair+Display",category:"serif"},{family:"Merriweather",googleSlug:"Merriweather",category:"serif"},{family:"Lora",googleSlug:"Lora",category:"serif"},{family:"PT Serif",googleSlug:"PT+Serif",category:"serif"},{family:"Cormorant Garamond",googleSlug:"Cormorant+Garamond",category:"serif"},{family:"Lobster",googleSlug:"Lobster",category:"display"},{family:"Pacifico",googleSlug:"Pacifico",category:"display"},{family:"Abril Fatface",googleSlug:"Abril+Fatface",category:"display"},{family:"Alfa Slab One",googleSlug:"Alfa+Slab+One",category:"display"},{family:"Dancing Script",googleSlug:"Dancing+Script",category:"handwriting"},{family:"Caveat",googleSlug:"Caveat",category:"handwriting"},{family:"Great Vibes",googleSlug:"Great+Vibes",category:"handwriting"},{family:"Satisfy",googleSlug:"Satisfy",category:"handwriting"},{family:"Permanent Marker",googleSlug:"Permanent+Marker",category:"handwriting"},{family:"Roboto Mono",googleSlug:"Roboto+Mono",category:"monospace"}],Ho=dr.map(n=>n.family);(ea=Ho[1])!=null||Ho[0];const Ul="https://fonts.loli.net/css2";let Go=!1;function ql(){if(!(Go||typeof document=="undefined")){Go=!0;for(const n of dr){const t=`gf-${n.googleSlug}`;if(document.getElementById(t))continue;const e=document.createElement("link");e.id=t,e.rel="stylesheet",e.href=`${Ul}?family=${n.googleSlug}:ital,wght@0,400;0,700;1,400;1,700&display=swap`,document.head.appendChild(e)}}}const Kl=new Set(dr.map(n=>n.family));async function Jl(n){if(typeof document=="undefined"||!document.fonts)return;ql();const t=n.length?n.filter(s=>Kl.has(s)):dr.map(s=>s.family),e=[];for(const s of t)e.push(document.fonts.load(`400 16px "${s}"`).catch(()=>{})),e.push(document.fonts.load(`700 16px "${s}"`).catch(()=>{})),e.push(document.fonts.load(`italic 400 16px "${s}"`).catch(()=>{})),e.push(document.fonts.load(`italic 700 16px "${s}"`).catch(()=>{}));await Promise.all(e);try{await document.fonts.ready}catch{}}function Ql(n){const t=new Set,e=s=>{if(Array.isArray(s))for(const r of s)r&&typeof r.fontFamily=="string"&&r.fontFamily&&t.add(r.fontFamily),Array.isArray(r==null?void 0:r.objects)&&e(r.objects)};return e(n),Array.from(t)}function Mi(n){const t=n/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function fr(n,t,e){const s=Mi(n),r=Mi(t),i=Mi(e);let o=s*.4124+r*.3576+i*.1805,a=s*.2126+r*.7152+i*.0722,h=s*.0193+r*.1192+i*.9505;o/=.95047,h/=1.08883;const l=d=>d>.008856?Math.cbrt(d):7.787*d+16/116,c=l(o),u=l(a),g=l(h);return[116*u-16,500*(c-u),200*(u-g)]}function pr(n,t){const e=n[0]-t[0],s=n[1]-t[1],r=n[2]-t[2];return e*e+s*s+r*r}function Zl(n,t,e,s=12){const r=n.length,i=Math.max(1,Math.min(e,r)),o=[0],a=new Float64Array(r).fill(1/0);for(let p=1;p<i;p++){const m=n[o[p-1]];let v=0;for(let x=0;x<r;x++){const _=pr(n[x],m);_<a[x]&&(a[x]=_),v+=a[x]}let w=v*(p*.6180339887%1),C=0;for(let x=0;x<r;x++)if(w-=a[x],w<=0){C=x;break}o.push(C)}const h=o.map(p=>n[p].slice()),l=new Int32Array(r);for(let p=0;p<s;p++){let m=0;for(let _=0;_<r;_++){let b=0,O=1/0;for(let T=0;T<i;T++){const k=pr(n[_],h[T]);k<O&&(O=k,b=T)}l[_]!==b&&m++,l[_]=b}const v=new Float64Array(i),w=new Float64Array(i),C=new Float64Array(i),x=new Int32Array(i);for(let _=0;_<r;_++){const b=l[_];v[b]+=n[_][0],w[b]+=n[_][1],C[b]+=n[_][2],x[b]++}for(let _=0;_<i;_++)x[_]>0&&(h[_]=[v[_]/x[_],w[_]/x[_],C[_]/x[_]]);if(m===0&&p>0)break}const c=new Float64Array(i),u=new Float64Array(i),g=new Float64Array(i),d=new Int32Array(i);for(let p=0;p<r;p++){const m=l[p];c[m]+=t[p][0],u[m]+=t[p][1],g[m]+=t[p][2],d[m]++}const f=[];for(let p=0;p<i;p++)d[p]>0?f.push([Math.round(c[p]/d[p]),Math.round(u[p]/d[p]),Math.round(g[p]/d[p])]):f.push([128,128,128]);return{centersLab:h,centersRgb:f}}function tc(n,t,e,s){var K,ft,at;const r=t*e,i=(K=s.alphaThreshold)!=null?K:128,o=n;let a=0;for(let E=3;E<o.length;E+=4)o[E]>i&&a++;const l=Math.max(1,Math.floor(a/4e4)),c=[],u=[];let g=0;for(let E=0;E<r;E++){const M=E*4;if(!(o[M+3]<=i)){if(g%l===0){const F=o[M],X=o[M+1],W=o[M+2];u.push([F,X,W]),c.push(fr(F,X,W))}g++}}if(c.length===0)return{width:t,height:e,regionIds:new Int32Array(r).fill(-1),regions:[],palette:[]};const{centersLab:d,centersRgb:f}=Zl(c,u,s.k),p=d.length,m=new Int32Array(r).fill(-1);for(let E=0;E<r;E++){const M=E*4;if(o[M+3]<=i)continue;const F=fr(o[M],o[M+1],o[M+2]);let X=0,W=1/0;for(let R=0;R<p;R++){const J=pr(F,d[R]);J<W&&(W=J,X=R)}m[E]=X}const v=(ft=s.minRegionArea)!=null?ft:Math.max(16,Math.round(r*4e-4)),w=((at=s.mergeColorDist)!=null?at:14)**2,C=new Int32Array(p);for(let E=0;E<p;E++)C[E]=E;const x=E=>{let M=E;for(;C[M]!==M;)M=C[M];for(;C[E]!==M;){const F=C[E];C[E]=M,E=F}return M};for(let E=0;E<p;E++)for(let M=E+1;M<p;M++)if(pr(d[E],d[M])<w){const F=x(E),X=x(M);F!==X&&(C[F]=X)}const _=new Int32Array(p),b=new Map;let O=0;for(let E=0;E<p;E++){const M=x(E);let F=b.get(M);F===void 0&&(F=O++,b.set(M,F)),_[E]=F}const T=new Int32Array(r).fill(-1),k=new Float64Array(O),D=new Float64Array(O),A=new Float64Array(O),L=new Float64Array(O),I=new Int32Array(O).fill(t),j=new Int32Array(O).fill(e),U=new Int32Array(O).fill(-1),N=new Int32Array(O).fill(-1);for(let E=0;E<e;E++){const M=E*t;for(let F=0;F<t;F++){const X=M+F,W=m[X];if(W<0)continue;const R=_[W];T[X]=R;const J=f[W];k[R]++,D[R]+=J[0],A[R]+=J[1],L[R]+=J[2],F<I[R]&&(I[R]=F),E<j[R]&&(j[R]=E),F>U[R]&&(U[R]=F),E>N[R]&&(N[R]=E)}}const H=new Int32Array(O).fill(-1),$=[];let tt=0;for(let E=0;E<O;E++)k[E]<v||(H[E]=tt,$.push({id:tt,color:[Math.round(D[E]/k[E]),Math.round(A[E]/k[E]),Math.round(L[E]/k[E])],area:k[E],bbox:{x:I[E],y:j[E],w:U[E]-I[E]+1,h:N[E]-j[E]+1}}),tt++);for(let E=0;E<r;E++){const M=T[E];T[E]=M<0?-1:H[M]}return{width:t,height:e,regionIds:T,regions:$,palette:f}}const ec=(n,t,e,s)=>n>=0&&t>=0&&n<e&&t<s;function ne(n,t,e){const s=t|0,r=e|0;return ec(s,r,n.width,n.height)?n.regionIds[r*n.width+s]===n.targetId:!1}const Vo=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]];function ki(n,t){if(n.length<2)return n.slice();const e=[n[0]];let s=t,r=0;for(let a=1;a<n.length;a++){const[h,l]=n[a-1],[c,u]=n[a],g=Math.hypot(c-h,u-l);if(g!==0){for(;r+g>=s;){const d=(s-r)/g;e.push([h+(c-h)*d,l+(u-l)*d]),s+=t}r+=g}}const i=n[n.length-1],o=e[e.length-1];return Math.hypot(i[0]-o[0],i[1]-o[1])>t*.4&&e.push(i),e}function He(n,t,e){const{bbox:s}=n,r=s.x+s.w/2,i=s.y+s.h/2,o=n.angle*Math.PI/180,a=Math.cos(o),h=Math.sin(o),l=-h,c=a,u=Math.ceil(Math.hypot(s.w,s.h)/2)+t,g=[];let d=0;for(let f=-u;f<=u;f+=t){const p=r+l*f,m=i+c*f,v=[];let w=!1,C=0;for(let x=-u;x<=u;x+=1){const _=ne(n,p+a*x,m+h*x);_&&!w?(w=!0,C=x):!_&&w&&(w=!1,v.push([C,x-1]))}if(w&&v.push([C,u]),v.length){const x=d%2===0?v:v.slice().reverse();for(const _ of x){let[b,O]=_;d%2!==0&&([b,O]=[O,b]);const T=Math.abs(O-b),k=Math.max(1,Math.round(T/e));for(let D=0;D<=k;D++){const A=b+(O-b)*D/k;g.push([p+a*A,m+h*A])}}}d++}return g}function Di(n,t){const{bbox:e}=n;let s=-1,r=-1;for(let u=e.y;u<e.y+e.h&&r<0;u++)for(let g=e.x;g<e.x+e.w;g++)if(t(g,u)){s=g,r=u;break}if(s<0)return[];const i=[];let o=s,a=r,h=6;const l=(e.w+e.h)*8+32;let c=0;do{i.push([o,a]);let u=!1;for(let g=0;g<8;g++){const d=(h+1+g)%8,f=o+Vo[d][0],p=a+Vo[d][1];if(t(f,p)){o=f,a=p,h=(d+4)%8,u=!0;break}}if(!u)break;c++}while((o!==s||a!==r)&&c<l);return i}function sc(n,t){if(t<=0)return(s,r)=>ne(n,s,r);const e=t*t;return(s,r)=>{for(let i=-t;i<=t;i++)for(let o=-t;o<=t;o++)if(!(o*o+i*i>e)&&!ne(n,s+o,r+i))return!1;return!0}}function rc(n,t){const e=[],s=Math.ceil(Math.min(n.bbox.w,n.bbox.h)/(2*Math.max(1,n.spacing)))+1;for(let r=0;r<s;r++){const i=r*n.spacing,o=Di(n,sc(n,i));if(o.length<3)break;e.push(...ki(o,Math.max(t,n.spacing)))}return e}function zo(n,t,e){const s=[],r=t/2;for(let i=n.bbox.y;i<n.bbox.y+n.bbox.h;i+=t)for(let o=n.bbox.x;o<n.bbox.x+n.bbox.w;o+=t)ne(n,o+r,i+r)&&(e==="cross"?s.push([o,i],[o+t,i+t],[o+t,i],[o,i+t]):s.push([o+r,i+r],[o+r+1,i+r],[o+r,i+r+1],[o+r,i+r]));return s}function ic(n,t){let e=0,s=0,r=0;for(let g=n.bbox.y;g<n.bbox.y+n.bbox.h;g+=2)for(let d=n.bbox.x;d<n.bbox.x+n.bbox.w;d+=2)ne(n,d,g)&&(e+=d,s+=g,r++);if(!r)return[];const i=e/r,o=s/r,a=Math.hypot(n.bbox.w,n.bbox.h)/2,h=Math.max(.5,n.spacing)/(2*Math.PI),l=[];let c=0,u=0;for(;u++<2e4;){const g=h*c;if(g>a)break;const d=i+g*Math.cos(c),f=o+g*Math.sin(c);ne(n,d,f)&&l.push([d,f]),c+=t/Math.max(1,h*(c/(2*Math.PI)+.5))}return l}function nc(n){var s;const t=Math.max(1,n.spacing),e=Math.max(1,(s=n.stitchLen)!=null?s:Math.max(2.5,t*.6));switch(n.stitchType){case"satin":return He(n,Math.max(1.2,t*.5),e);case"fill":case"zigzag":case"estitch":return He(n,t,e);case"meander":return He(n,Math.max(t,6),Math.max(e,4));case"tartan":{const r=He(n,t,e),i=He({...n,angle:n.angle+90},t,e);return r.concat(i)}case"running":return ki(Di(n,(r,i)=>ne(n,r,i)),Math.max(e,t));case"bean":{const r=ki(Di(n,(o,a)=>ne(n,o,a)),Math.max(e,t)),i=[];for(let o=0;o<r.length;o++)i.push(r[o]),o>0&&i.push(r[o-1],r[o]);return i}case"contour":case"circular":return rc(n,e);case"cross":return zo(n,Math.max(6,t),"cross");case"frenchKnot":return zo(n,Math.max(5,t),"knot");case"spiral":return ic(n,e);default:return He(n,t,e)}}const oc={satin:4,fill:5,running:8,bean:7,zigzag:7,estitch:9,cross:9,tartan:12,circular:6,contour:6,spiral:6,meander:9,frenchKnot:7},Uo=1e3,qo=1600;async function mr(n,t){if(n&&typeof n=="object")return n;if(typeof n!="string"||!n.trim())throw new Error("JSON 入参为空");let e=dt.forceHttpsAsset(n.trim());t&&(e+=(e.includes("?")?"&":"?")+"file_token="+encodeURIComponent(t));let s=null;for(let r=0;r<3;r++){try{const i=await fetch(e);if(i.ok)return await i.json();if(i.status<500)throw new Error(`加载 JSON 失败 HTTP ${i.status}: ${e.slice(0,80)}`);s=new Error(`加载 JSON 失败 HTTP ${i.status}: ${e.slice(0,80)}`)}catch(i){if(s=i,i instanceof Error&&/HTTP 4\d\d/.test(i.message))throw i}r<2&&await new Promise(i=>setTimeout(i,200*(r+1)))}throw s instanceof Error?s:new Error("加载 JSON 失败: "+e.slice(0,80))}function ac(n,t,e){var m,v;const s=n!=null&&n.stateMap&&typeof n.stateMap=="object"?n.stateMap:{},r=Number(n==null?void 0:n.designCanvasSize)>0?Number(n.designCanvasSize):Uo,i=Number(n==null?void 0:n.designCanvasHeight)>0?Number(n.designCanvasHeight):qo,o=String((m=e!=null?e:n==null?void 0:n.selectedSize)!=null?m:"").trim(),a=w=>{const C=String(w!=null?w:"").trim().toLowerCase();return C==="default"||C==="all"||C==="common"?"":C},h=a(o),c=(Array.isArray(n==null?void 0:n.data)?n.data:[]).filter(w=>(w==null?void 0:w.type)===t),u=c.filter(w=>{var x;const C=a(String((x=w==null?void 0:w.size)!=null?x:""));return!h||C===h||C===""}),g=u[u.length-1]||c[c.length-1]||null,d=g&&typeof g.jsonURL=="object"?g.jsonURL:null,f=Array.isArray(g==null?void 0:g.resources)?g.resources:[],p=[];for(const w of Object.keys(s)){let C="";if(w.includes("::")){const[k,D]=w.split("::"),A=a(D!=null?D:"");if(h&&A!==""&&A!==h)continue;C=k}else C=w;const x=s[w];if(!x||typeof x!="object")continue;const _=Number(x.designCanvasSize)>0?Number(x.designCanvasSize):r,b=Number(x.designCanvasHeight)>0?Number(x.designCanvasHeight):i,O=f.filter(k=>{var D;return String((D=k==null?void 0:k.groupId)!=null?D:"")===String(C)}),T=((v=O.find(k=>k==null?void 0:k.groupName))==null?void 0:v.groupName)||"";p.push({groupId:String(C),name:T,state:x,savedCanvasW:_,savedCanvasH:b,resources:O,guideline:d})}return p}function hc(n,t){return!n||!t?n:bi(n,t)}function Ei(n){return new Promise((t,e)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>t(s),s.onerror=()=>e(new Error("图片加载失败: "+n.slice(0,80))),s.src=dt.forceHttpsAsset(n)})}async function yr(n,t){if(n&&/^https?:/i.test(n)){try{const e=await $o(n,{mode:"cors"});if(e.ok)return await Ei(URL.createObjectURL(await e.blob()))}catch{}return await Ei(hc(n,t))}return await Ei(n)}function Pi(n,t="image/png",e){return new Promise((s,r)=>{n.toBlob(i=>i?s(i):r(new Error("canvas.toBlob 返回空")),t,e)})}async function lc(n,t){var s,r,i,o,a,h,l,c,u,g;const e=(r=(s=n.getObjects)==null?void 0:s.call(n))!=null?r:[];for(const d of e){if(!((i=d==null?void 0:d.customData)!=null&&i.isPatternRect))continue;const f=d.customData.patternSource||d.customData.savedSrc;if(!(!f||typeof f!="string"))try{const p=await yr(f,t),m=(o=d.customData.patternScale)!=null?o:100,v=Math.max(.01,wl(m)/100),w=Sl(p),{tw:C,th:x}=Cl(d.customData,w,{patternTileWidth:d.patternTileWidth,patternTileHeight:d.patternTileHeight});typeof d.setPatternElement=="function"?d.setPatternElement(p):d.patternElement=p,d.patternTileWidth=C,d.patternTileHeight=x,d.patternScale=v;const _=vi(d);d.patternGapX=_.x,d.patternGapY=_.y,d.customData={...d.customData||{},patternTileWidth:C,patternTileHeight:x,patternGapX:_.x,patternGapY:_.y};const b=typeof((a=d.customData)==null?void 0:a.patternPhaseX)=="number"?d.customData.patternPhaseX:typeof((h=d.fill)==null?void 0:h.offsetX)=="number"?((l=d.left)!=null?l:0)+d.fill.offsetX:d.patternPhaseX||0,O=typeof((c=d.customData)==null?void 0:c.patternPhaseY)=="number"?d.customData.patternPhaseY:typeof((u=d.fill)==null?void 0:u.offsetY)=="number"?((g=d.top)!=null?g:0)+d.fill.offsetY:d.patternPhaseY||0;typeof d.setPatternPhase=="function"?d.setPatternPhase(b,O):(d.patternPhaseX=b,d.patternPhaseY=O),d.objectCaching=!1,d.dirty=!0}catch(p){console.warn("[productionRender] rebuildPattern 失败",p)}}}async function Ko(n,t){var v;(v=n.renderAll)==null||v.call(n);const e=n.getWidth?n.getWidth():1,s=n.getHeight?n.getHeight():1,r=n.getElement?n.getElement():n.lowerCanvasEl;if(!r)throw new Error("无法取得 Fabric 画布元素");const i=await Pi(r),o=await createImageBitmap(i),a=o.width/e,h=o.height/s,l=Math.max(0,Math.floor(t.left*a)),c=Math.max(0,Math.floor(t.top*h)),u=Math.max(1,Math.min(o.width-l,Math.ceil(t.width*a))),g=Math.max(1,Math.min(o.height-c,Math.ceil(t.height*h))),d=Math.max(1,Math.round(t.width)),f=Math.max(1,Math.round(t.height)),p=document.createElement("canvas");p.width=d,p.height=f;const m=p.getContext("2d");return m?(m.imageSmoothingEnabled=!0,m.imageSmoothingQuality="high",m.drawImage(o,l,c,u,g,0,0,d,f),o.close(),Pi(p)):(o.close(),i)}async function Jo(n,t){const e=Math.max(1,Math.round(n.savedCanvasW)),s=Math.max(1,Math.round(n.savedCanvasH)),r=document.createElement("canvas");r.width=e,r.height=s;const i=new hi(r,{width:e,height:s,preserveObjectStacking:!0,enableRetinaScaling:!1,renderOnAddRemove:!1}),o=JSON.parse(JSON.stringify(n.state)),a=Array.isArray(o.objects)?o.objects:[];let h=0,l=0,c=0;for(const g of a)if(String(g==null?void 0:g.type).toLowerCase()==="image"&&typeof g.src=="string"&&/^https?:/i.test(g.src)){h++;try{const d=await $o(g.src,{mode:"cors"});d.ok?(g.src=URL.createObjectURL(await d.blob()),l++):(c++,console.warn(`[productionRender] 设计图 fetch !ok status=${d.status} ${String(g.src).slice(0,80)}`))}catch(d){c++,console.warn(`[productionRender] 设计图 fetch 异常 ${String(g.src).slice(0,80)}`,d)}}await i.loadFromJSON(o,(g,d)=>{var f;String(d==null?void 0:d.type).toLowerCase()==="image"&&((f=d.set)==null||f.call(d,{crossOrigin:"anonymous"}))}),console.log(`[productionRender] loadFromJSON done piece=${n.groupId} jsonObjs=${a.length} httpImg(total/ok/fail)=${h}/${l}/${c} loadedObjs=${i.getObjects().length} loadedTypes=${JSON.stringify(i.getObjects().map(g=>g.type))}`),await lc(i,t);const u=Ql(a);return await Jl(u),console.log(`[productionRender] fonts ready piece=${n.groupId} families=${JSON.stringify(u)}`),i.renderAll(),{canvas:i,W:e,H:s}}async function cc(n,t,e=!1){var o;const{canvas:s,W:r,H:i}=await Jo(n,t);try{const a=(n.resources||[]).find(c=>(c==null?void 0:c.type)==="MASK");if(console.log(`[productionRender] piece=${n.groupId} name=${n.name} canvas=${r}x${i} objects=${s.getObjects().length} mask=${a!=null&&a.url?"Y":"N"} restoreOnly=${e}`),e){const c=await No(s,{useIdentityViewport:!0,transparentBackground:!0});return c!=null?c:await Ko(s,{left:0,top:0,width:r,height:i})}const h=(n.resources||[]).find(c=>(c==null?void 0:c.type)==="MASK");let l={left:0,top:0,width:r,height:i};if(h!=null&&h.url){const c=Number(h.width)||1e3,u=Number(h.height)||1e3,g=Math.min(r/c,i/u),d=c*g,f=u*g,p=(r-d)/2,m=(i-f)/2,v=await yr(h.url,t),w=new Ft(v,{left:p+d/2,top:m+f/2,originX:"center",originY:"center",scaleX:d/c,scaleY:f/u,selectable:!1,evented:!1,globalCompositeOperation:"destination-in"});s.add(w),s.renderAll(),l={left:p,top:m,width:d,height:f}}return await Ko(s,l)}finally{try{(o=s.dispose)==null||o.call(s)}catch{}}}async function uc(n,t,e=!1){const s=[];for(const r of n)try{const i=await cc(r,t,e);i&&s.push({id:r.groupId,name:r.name,blob:i})}catch(i){console.warn("[productionRender] 分片渲染失败",r.groupId,r.name,i)}return s}function Qo(n,t,e){var h;const s=Array.isArray(n==null?void 0:n.data)?n.data:[],r=String((h=e!=null?e:n==null?void 0:n.selectedSize)!=null?h:"").trim().toLowerCase(),i=l=>{var c;return String((c=l==null?void 0:l.size)!=null?c:"").trim().toLowerCase()},o=s.filter(l=>(l==null?void 0:l.type)===t),a=o.filter(l=>!r||i(l)===r);return a[a.length-1]||o.find(l=>i(l)==="default")||o[o.length-1]||null}function gc(n,t){var d,f,p;const e=n!=null&&n.stateMap&&typeof n.stateMap=="object"?n.stateMap:{},s=Number(n==null?void 0:n.designCanvasSize)>0?Number(n.designCanvasSize):Uo,r=Number(n==null?void 0:n.designCanvasHeight)>0?Number(n.designCanvasHeight):qo,i=String((d=t!=null?t:n==null?void 0:n.selectedSize)!=null?d:"").trim(),o=Qo(n,"COMPLETE",i),a=String((p=(f=(Array.isArray(o==null?void 0:o.resources)?o.resources:[]).find(m=>(m==null?void 0:m.type)==="MASK"))==null?void 0:f.groupId)!=null?p:""),h=Object.keys(e);let l=a&&h.find(m=>m===`${a}::${i}`)||a&&h.find(m=>m===`${a}::`)||a&&h.find(m=>m===a)||a&&h.find(m=>m.startsWith(`${a}::`))||i&&h.find(m=>m.endsWith(`::${i}`))||h[0];if(!l)return null;const c=e[l];if(!c||typeof c!="object")return null;const u=Number(c.designCanvasSize)>0?Number(c.designCanvasSize):s,g=Number(c.designCanvasHeight)>0?Number(c.designCanvasHeight):r;return{groupId:a||l,name:"complete",state:c,savedCanvasW:u,savedCanvasH:g,resources:[]}}function dc(n,t,e,s,r,i){const o=Math.max(0,Math.min(n,e)),a=Math.max(0,Math.min(t,s)),h=Math.max(0,Math.min(n,e+r)),l=Math.max(0,Math.min(t,s+i)),c=Math.max(0,Math.floor(h-o)),u=Math.max(0,Math.floor(l-a));return{sx:o,sy:a,sw:c,sh:u,dx:Math.round(o-e),dy:Math.round(a-s)}}async function fc(n,t,e,s,r,i,o){var v;const a=Nl(r,i);if(!((v=a==null?void 0:a.slicesByGroupId)!=null&&v.size))return console.warn("[productionRender] COMPLETE: 无 SPLIT slices 配置,无法裁切"),[];const h=Qo(r,"SPLIT",i),l=h&&typeof h.jsonURL=="object"?h.jsonURL:await mr(h==null?void 0:h.jsonURL,o),c=Array.isArray(l==null?void 0:l.layerList)?l.layerList:[],u=Yl(c),{psdW:g,psdH:d}=$l(c,l),f=n.width/Math.max(1,t.width),p=n.height/Math.max(1,t.height);if(console.log(`[productionRender] COMPLETE children=${u.length} slices=${a.slicesByGroupId.size} psd=${g}x${d} canvas=${e}x${s} ext=[${Math.round(t.minL)},${Math.round(t.minT)} ${Math.round(t.width)}x${Math.round(t.height)}] base=${n.width}x${n.height}`,u.map(w=>`${w.id}/${w.name}`)),!u.length)return[];const m=[];for(const w of u){const C=a.slicesByGroupId.get(String(w.id));if(!(C!=null&&C.maskUrl))continue;const x=Wl(w.bounds,g,d,e,s),_=Math.round((x.left-t.minL)*f),b=Math.round((x.top-t.minT)*p),O=Math.max(1,Math.round(x.width*f)),T=Math.max(1,Math.round(x.height*p)),k=document.createElement("canvas");k.width=O,k.height=T;const D=k.getContext("2d");if(!D)continue;D.imageSmoothingEnabled=!0,D.imageSmoothingQuality="high";const A=dc(n.width,n.height,_,b,O,T);A.sw>0&&A.sh>0&&D.drawImage(n,A.sx,A.sy,A.sw,A.sh,A.dx,A.dy,A.sw,A.sh);try{const L=await yr(C.maskUrl,o),I=L.naturalWidth||L.width,j=L.naturalHeight||L.height;D.globalCompositeOperation="destination-in",D.drawImage(L,0,0,I,j,0,0,O,T),D.globalCompositeOperation="source-over"}catch(L){console.warn("[productionRender] COMPLETE mask 加载失败",w.id,w.name,L)}m.push({id:String(w.id),name:w.name,blob:await Pi(k)})}return m}async function Zo(n){var u,g,d,f,p,m,v,w,C;n.fileToken&&Lo(n.fileToken);const t=await mr(n.fabricJson,n.fileToken),e=await mr(n.productJson,n.fileToken),s=(t==null?void 0:t.selectedMode)==="SPLIT"?"SPLIT":"COMPLETE",r=n.fabricDirect===!0,i=n.imageFormat==="jpeg"?"jpeg":"png",o=String((u=n.size)!=null?u:"").trim(),a=!o||/^(default|all|common)$/i.test(o)?String((g=t==null?void 0:t.selectedSize)!=null?g:"").trim():o;let h=[];if(s==="COMPLETE"){const x=gc(t,a);if(!x)throw new Error(`COMPLETE:未解析到尺码「${a||(t==null?void 0:t.selectedSize)||""}」的整稿设计`);console.log(`[productionRender] mode=COMPLETE size=${a} (raw=${o}) baseGid=${x.groupId} base=${x.savedCanvasW}x${x.savedCanvasH} objs=${(p=(f=(d=x.state)==null?void 0:d.objects)==null?void 0:f.length)!=null?p:0} restoreOnly=${r}`);const{canvas:_,W:b,H:O}=await Jo(x,n.fileToken);try{const T=Yo(_),k=await No(_,{useIdentityViewport:!0,transparentBackground:!0});if(!k)throw new Error("COMPLETE:整稿 base 渲染失败");if(r)return k;const D=await createImageBitmap(k);try{h=await fc(D,T,b,O,t,a,n.fileToken)}finally{(m=D.close)==null||m.call(D)}}finally{(v=_.dispose)==null||v.call(_)}}else{const x=ac(t,s,a);if(console.log(`[productionRender] mode=${s} size=${a} (raw=${o}) tasks=${x.length} restoreOnly=${r}`,x.map(_=>{var b,O,T;return`${_.groupId}/${_.name}/${_.savedCanvasW}x${_.savedCanvasH}/objs=${(T=(O=(b=_.state)==null?void 0:b.objects)==null?void 0:O.length)!=null?T:0}/res=${_.resources.length}`})),!x.length)throw new Error(`未解析到尺码「${a||(t==null?void 0:t.selectedSize)||""}」的分片设计(检查 size 与 stateMap 键)`);h=await uc(x,n.fileToken,r)}console.log(`[productionRender] bitmaps=${h.length}`,h.map(x=>`${x.id}/${x.name}/${Math.round(x.blob.size/1024)}KB`));const l=String((C=(w=t==null?void 0:t.typeModel)!=null?w:t==null?void 0:t.specialMode)!=null?C:"").trim()||void 0,c=await cl(h,e,i,l);return console.log(`[productionRender] compose drawn=[${c.drawn.join(",")}] skipped=[${c.skipped.join(",")}] out=${c.canvasWidth}x${c.canvasHeight}`),c.blob}async function ta(n){n.fileToken&&Lo(n.fileToken);const t=await mr(n.fabricJson,n.fileToken),e=t==null?void 0:t.embroidery;if(!e||typeof e.sourceSrc!="string"||!e.sourceSrc)throw new Error("刺绣针迹:fabricJson 缺少 embroidery 数据(typeModel 应为 embroidery)");const s=Math.max(2,Number(e.colorCount)||12),r=Number(e.mergeColorDist)||14,i=Math.max(64,Number(e.maxWorkSize)||800),o=await yr(e.sourceSrc,n.fileToken),a=o.naturalWidth||o.width||1,h=o.naturalHeight||o.height||1,l=Math.min(1,i/Math.max(a,h)),c=Math.max(1,Math.round(a*l)),u=Math.max(1,Math.round(h*l)),g=document.createElement("canvas");g.width=c,g.height=u;const d=g.getContext("2d",{willReadFrequently:!0});if(!d)throw new Error("刺绣针迹:无法创建画布上下文");d.clearRect(0,0,c,u),d.drawImage(o,0,0,a,h,0,0,c,u);const f=d.getImageData(0,0,c,u).data,p=tc(f,c,u,{k:s,mergeColorDist:r});console.log(`[embroideryStitches] quantize w=${c} h=${u} k=${s} regions=${p.regions.length}`);const v=(Array.isArray(e.groups)?e.groups:[]).map(C=>{var x,_,b;return{g:C,lab:fr(((x=C.color)==null?void 0:x[0])|0,((_=C.color)==null?void 0:_[1])|0,((b=C.color)==null?void 0:b[2])|0)}}),w=[];for(const C of p.regions){const x=fr(C.color[0],C.color[1],C.color[2]);let _=null,b=1/0;for(const A of v){const L=(A.lab[0]-x[0])**2+(A.lab[1]-x[1])**2+(A.lab[2]-x[2])**2;L<b&&(b=L,_=A.g)}const O=(_==null?void 0:_.stitch)||"satin",T=Number(_==null?void 0:_.spacing)||oc[O]||5,k=Number.isFinite(Number(_==null?void 0:_.angle))?Number(_==null?void 0:_.angle):45,D=nc({regionIds:p.regionIds,width:c,height:u,targetId:C.id,bbox:C.bbox,stitchType:O,spacing:T,angle:k});D.length&&w.push({color:C.color,stitchType:O,spacing:T,angle:k,stitches:D})}return console.log(`[embroideryStitches] colors=${w.length} totalStitches=${w.reduce((C,x)=>C+x.stitches.length,0)}`),{width:c,height:u,sourceSrc:e.sourceSrc,colorCount:s,mergeColorDist:r,colors:w}}return typeof window!="undefined"&&(window.generateProductionImage=Zo,window.generateEmbroideryStitches=ta,window.__JETPRINT_HEADLESS_VERSION__="1.2.14"),Lt.generateEmbroideryStitches=ta,Lt.generateProductionImage=Zo,Object.defineProperty(Lt,Symbol.toStringTag,{value:"Module"}),Lt})({});
504
+ `}applyTo2d(t){let{imageData:{data:e}}=t;const s=-this.vibrance;for(let r=0;r<e.length;r+=4){const i=e[r],o=e[r+1],a=e[r+2],h=Math.max(i,o,a),l=(i+o+a)/3,c=2*Math.abs(h-l)/255*s;e[r]+=h!==i?(h-i)*c:0,e[r+1]+=h!==o?(h-o)*c:0,e[r+2]+=h!==a?(h-a)*c:0}}sendUniformData(t,e){t.uniform1f(e.uVibrance,-this.vibrance)}isNeutralState(){return this.vibrance===0}}y(nr,"type","Vibrance"),y(nr,"defaults",{vibrance:0}),y(nr,"uniformLocations",["uVibrance"]),P.setClass(nr);function Mo(n){const t=n&&n.bounds;if(t&&typeof t.width=="number"&&typeof t.height=="number"&&t.width>0&&t.height>0)return{left:typeof t.left=="number"?t.left:0,top:typeof t.top=="number"?t.top:0,width:t.width,height:t.height};if(Array.isArray(n==null?void 0:n.children))for(const e of n.children){const s=Mo(e);if(s)return s}return null}function Jh(n,t="split"){if(!Array.isArray(n))return[];const e=(o,a)=>{for(const h of o){if(h&&h.name===a&&h.type==="Group")return h;if(Array.isArray(h==null?void 0:h.children)){const l=e(h.children,a);if(l)return l}}return null},s=e(n,t),r=s&&s.children||[],i=[];for(const o of r){if(!o||o.type!=="Group"||o.id==null)continue;const a=Mo(o);a&&i.push({id:Number(o.id),name:o.name||"",bounds:a})}return i}function Qh(n){return new Promise((t,e)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>t(s),s.onerror=()=>e(new Error("图片加载失败: "+n.slice(0,60))),s.src=n})}const Zh=5,tl="#ff0000",el=9,sl=7,rl="#ff0000",il="#ffffff",nl=8,ol=16,al=250;function hl(n,t,e,s,r,i,o,a,h,l){if(o<=0||a<=0||h<=0)return;const c=document.createElement("canvas");c.width=o,c.height=a;const u=c.getContext("2d");if(!u)return;u.drawImage(t,0,0,e,s,0,0,o,a);const g=l.replace("#",""),d=parseInt(g.slice(0,2),16)||0,f=parseInt(g.slice(2,4),16)||0,p=parseInt(g.slice(4,6),16)||0,m=u.getImageData(0,0,o,a),v=m.data;let w=0,C=0,x=0;for(let D=0;D<v.length;D+=4)if(v[D+3]>10){v[D]=d,v[D+1]=f,v[D+2]=p,v[D+3]=255;const A=D>>2;w+=A%o,C+=A/o|0,x++}else v[D]=v[D+1]=v[D+2]=v[D+3]=0;u.putImageData(m,0,0);const _=o+h*2,b=a+h*2,O=document.createElement("canvas");O.width=_,O.height=b;const T=O.getContext("2d");if(!T)return;for(let D=1;D<=h;D++)for(let A=0;A<360;A+=30){const L=A*Math.PI/180;T.drawImage(c,h+Math.round(Math.cos(L)*D),h+Math.round(Math.sin(L)*D))}const k=T.getImageData(0,0,_,b).data;if(T.globalCompositeOperation="destination-out",T.drawImage(c,h,h),T.globalCompositeOperation="source-over",n.drawImage(O,r-h,i-h),x>0){const D=2*(o+a);let A=Math.round(D/al);A=Math.max(nl,Math.min(ol,A));const L=w/x+h,I=C/x+h,j=Math.ceil(Math.hypot(_,b)),U=[];for(let N=0;N<A;N++){const H=N/A*Math.PI*2,$=Math.cos(H),tt=Math.sin(H);let K=-1,ft=-1;for(let at=1;at<=j;at++){const E=Math.round(L+$*at),M=Math.round(I+tt*at);if(E<0||M<0||E>=_||M>=b)break;k[(M*_+E)*4+3]>0&&(K=E,ft=M)}K>=0&&U.push({x:r-h+K,y:i-h+ft})}ll(n,U)}}function ll(n,t){if(t.length){n.save(),n.font=`bold ${sl}px sans-serif`,n.textAlign="center",n.textBaseline="middle";for(let e=0;e<t.length;e++){const{x:s,y:r}=t[e];n.beginPath(),n.arc(s,r,el,0,Math.PI*2),n.fillStyle=rl,n.fill(),n.fillStyle=il,n.fillText(String(e+1),s,r)}n.restore()}}async function cl(n,t,e="png",s){const r=Number(t==null?void 0:t.canvasWidth)||0,i=(t==null?void 0:t.canvasHeight)!=null?Number(t.canvasHeight):r;if(!(r>0&&i>0))throw new Error("productJson.canvasWidth/canvasHeight 无效");const o=Jh((t==null?void 0:t.layerList)||[],"split");if(!o.length)throw new Error("productJson 中未解析到 split 分片结构");const a=new Map,h=new Map;for(const m of n||[])m!=null&&m.name&&a.set(m.name,m),(m==null?void 0:m.id)!=null&&h.set(String(m.id),m);const l=document.createElement("canvas");l.width=r,l.height=i;const c=l.getContext("2d");if(!c)throw new Error("无法创建画布 2D 上下文");e==="jpeg"&&(c.fillStyle="#ffffff",c.fillRect(0,0,r,i));const u=[],g=[],d=[];try{for(const m of o){const v=m.name&&a.get(m.name)||h.get(String(m.id));if(!(v!=null&&v.blob)){g.push(`${m.name||m.id}(无位图)`);continue}const{left:w,top:C,width:x,height:_}=m.bounds;if(x<=0||_<=0){g.push(`${m.name||m.id}(槽位无效)`);continue}const b=URL.createObjectURL(v.blob);d.push(b);const O=await Qh(b),T=O.naturalWidth||1,k=O.naturalHeight||1,D=Math.max(x/T,_/k),A=Math.round(T*D),L=Math.round(k*D),I=Math.round(w+(x-A)/2),j=Math.round(C+(_-L)/2);c.save(),c.beginPath(),c.rect(w,C,x,_),c.clip(),c.drawImage(O,0,0,T,k,I,j,A,L),s==="pillow3d"&&hl(c,O,T,k,I,j,A,L,Zh,tl),c.restore(),u.push(m.name||String(m.id))}}finally{d.forEach(m=>{try{URL.revokeObjectURL(m)}catch{}})}const f=e==="jpeg"?"image/jpeg":"image/png";return{blob:await new Promise((m,v)=>{l.toBlob(w=>w?m(w):v(new Error("canvas.toBlob 返回空")),f,e==="jpeg"?1:void 0)}),canvasWidth:r,canvasHeight:i,drawn:u,skipped:g}}const ul=0,yi="single",gl="full",ko="#1677ff";function dl(n){var t;return((t=n==null?void 0:n.customData)==null?void 0:t.patternRenderMode)===yi?yi:gl}function fl(n){return dl(n)===yi}function or(n,t){return t?(n%t+t)%t:0}function pl(n){var l,c,u;const t=(n==null?void 0:n.customData)||{},e=Number((l=n==null?void 0:n.patternTileWidth)!=null?l:t.patternTileWidth)||100,s=Number((c=n==null?void 0:n.patternTileHeight)!=null?c:t.patternTileHeight)||100,r=n==null?void 0:n.patternScale,i=typeof r=="number"&&r>0&&r<=2?Math.max(.01,r):Math.max(.01,(Number((u=t.patternScale)!=null?u:100)||100)/100),o=Math.max(1,e*i),a=Math.max(1,s*i),h=vi(n);return{tileW:o,tileH:a,strideW:o+h.x,strideH:a+h.y,scale:i}}function Do(n){var m,v,w,C;const t=pl(n),{strideW:e,strideH:s}=t,r=Number(n==null?void 0:n.width)||0,i=Number(n==null?void 0:n.height)||0,o=(m=n==null?void 0:n.getCenterPoint)==null?void 0:m.call(n),a=Number(o==null?void 0:o.x)||(Number(n==null?void 0:n.left)||0)+r/2,h=Number(o==null?void 0:o.y)||(Number(n==null?void 0:n.top)||0)+i/2,l=a-r/2,c=h-i/2,u=typeof(n==null?void 0:n.patternPhaseX)=="number"?n.patternPhaseX:typeof((v=n==null?void 0:n.customData)==null?void 0:v.patternPhaseX)=="number"?n.customData.patternPhaseX:0,g=typeof(n==null?void 0:n.patternPhaseY)=="number"?n.patternPhaseY:typeof((w=n==null?void 0:n.customData)==null?void 0:w.patternPhaseY)=="number"?n.customData.patternPhaseY:0,d=l-or(l-u,e),f=c-or(c-g,s),p=(n==null?void 0:n.patternMode)||((C=n==null?void 0:n.customData)==null?void 0:C.patternMode)||"";return{...t,centerX:a,centerY:h,sceneLeft:l,sceneTop:c,startSceneX:d,startSceneY:f,startX:d-a,startY:f-h,phaseX:u,phaseY:g,mode:p}}function ml(n,t,e){const s=Do(n),{strideW:r,strideH:i,tileW:o,tileH:a,startSceneX:h,startSceneY:l,centerX:c,centerY:u,phaseX:g,phaseY:d,mode:f}=s,p=Eo(n);if(p%360!==0){const x=p*Math.PI/180,_=Math.cos(x),b=Math.sin(x),O=t-c,T=e-u,k=O*_+T*b,D=-O*b+T*_,A=g-c,L=d-u,I=A*_+L*b,j=-A*b+L*_,U=Math.floor((k-I)/r),N=Math.floor((D-j)/i);let H=I+U*r,$=j+N*i;f==="brick-x"&&Math.round(($-j)/i)&1&&(H+=r/2),f==="brick-y"&&Math.round((H-I)/r)&1&&($+=i/2);const tt=c+H*_-$*b,K=u+H*b+$*_;return{left:tt,top:K,tileW:o,tileH:a}}const m=Math.floor((t-h)/r),v=Math.floor((e-l)/i);let w=h+m*r,C=l+v*i;return f==="brick-x"&&Math.round((C-d)/i)&1&&(w+=r/2),f==="brick-y"&&Math.round((w-g)/r)&1&&(C+=i/2),{left:w,top:C,tileW:o,tileH:a}}function Ne(n,t=ul){const e=Number(n);return Number.isFinite(e)?Math.max(0,e):t}function ar(n){const t=n,e=(t==null?void 0:t.naturalWidth)||(t==null?void 0:t.videoWidth)||(t==null?void 0:t.width)||0,s=(t==null?void 0:t.naturalHeight)||(t==null?void 0:t.videoHeight)||(t==null?void 0:t.height)||0;return{width:e,height:s}}function yl(n,t,e){let s=e*2654435761>>>0;return s=(s<<5)-s+n|0,s=(s<<5)-s+t|0,s>>>0}function vi(n){var e,s;const t=(n==null?void 0:n.customData)||{};return{x:Ne((e=n==null?void 0:n.patternGapX)!=null?e:t.patternGapX),y:Ne((s=n==null?void 0:n.patternGapY)!=null?s:t.patternGapY)}}function hr(n){const t=Number(n);return Number.isFinite(t)?(t%360+360)%360:0}function Eo(n){const t=(n==null?void 0:n.customData)||{},e=[n==null?void 0:n.patternTileAngle,t.patternTileAngle,t.originalAngle];for(const s of e){const r=Number(s);if(Number.isFinite(r)&&r!==0)return hr(r)}return 0}function vl(n){var e,s,r,i;const t=(n==null?void 0:n.customData)||{};return{flipX:!!((s=(e=n==null?void 0:n.patternTileFlipX)!=null?e:t.patternTileFlipX)!=null?s:t.originalFlipX),flipY:!!((i=(r=n==null?void 0:n.patternTileFlipY)!=null?r:t.patternTileFlipY)!=null?i:t.originalFlipY),angle:Eo(n)}}function xl(n,t,e,s,r,i,o=!1,a=!1,h=0){const l=hr(h),c=.75;if(!o&&!a&&l===0){n.drawImage(t,e-c,s-c,r+c*2,i+c*2);return}n.save(),n.translate(e+r/2,s+i/2),l&&n.rotate(l*Math.PI/180),n.scale(o?-1:1,a?-1:1),n.drawImage(t,-r/2-c,-i/2-c,r+c*2,i+c*2),n.restore()}class lr extends Et{constructor(t={}){var e,s,r;super({...t,originX:"left",originY:"top",objectCaching:!1,hasControls:!1,hasBorders:!1,lockScalingX:!0,lockScalingY:!0,lockRotation:!0,fill:(e=t.fill)!=null?e:"",stroke:(s=t.stroke)!=null?s:null,borderColor:ko,cornerColor:ko,cornerStrokeColor:"#ffffff",transparentCorners:!1,borderScaleFactor:2}),this.patternElement=(r=t.patternElement)!=null?r:null,this.patternTileWidth=Number(t.patternTileWidth)||ar(this.patternElement).width||100,this.patternTileHeight=Number(t.patternTileHeight)||ar(this.patternElement).height||100,this.patternScale=Number(t.patternScale)||1,this.patternPhaseX=Number(t.patternPhaseX)||0,this.patternPhaseY=Number(t.patternPhaseY)||0,this.patternGapX=Ne(t.patternGapX),this.patternGapY=Ne(t.patternGapY),this.patternMode=t.patternMode||"",this.patternSeed=Number(t.patternSeed)||1,this.patternTileFlipX=!!t.patternTileFlipX,this.patternTileFlipY=!!t.patternTileFlipY,this.patternTileAngle=hr(t.patternTileAngle),this.patternActiveTileLeft=null,this.patternActiveTileTop=null}setActiveDragTile(t,e){this.patternActiveTileLeft=t,this.patternActiveTileTop=e,this.dirty=!0}clearActiveDragTile(){this.patternActiveTileLeft==null&&this.patternActiveTileTop==null||(this.patternActiveTileLeft=null,this.patternActiveTileTop=null,this.dirty=!0)}setPatternElement(t){this.patternElement=t;const e=ar(t);!this.patternTileWidth&&e.width&&(this.patternTileWidth=e.width),!this.patternTileHeight&&e.height&&(this.patternTileHeight=e.height),this.dirty=!0}setPatternPhase(t,e){this.patternPhaseX=t,this.patternPhaseY=e,this.customData={...this.customData||{},patternPhaseX:t,patternPhaseY:e},this.dirty=!0}setPatternGap(t,e){this.patternGapX=Ne(t),this.patternGapY=Ne(e),this.customData={...this.customData||{},patternGapX:this.patternGapX,patternGapY:this.patternGapY},this.dirty=!0}toObject(t=[]){return super.toObject(["patternTileWidth","patternTileHeight","patternScale","patternPhaseX","patternPhaseY","patternGapX","patternGapY","patternMode","patternSeed","patternTileFlipX","patternTileFlipY","patternTileAngle",...t])}_render(t){var N,H,$,tt,K,ft,at,E;const e=this.patternElement;if(!e){super._render(t);return}const s=Number(this.width)||0,r=Number(this.height)||0,i=Do(this),{tileW:o,tileH:a,strideW:h,strideH:l,centerX:c,centerY:u}=i;let g=i.startX,d=i.startY,f=i.phaseX,p=i.phaseY;const m=i.mode,v=-s/2,w=-r/2;let C=s/2,x=r/2;t.save(),t.beginPath(),t.rect(v,w,s,r),t.clip(),t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const{flipX:_,flipY:b,angle:O}=vl(this),T=(M,F)=>({flipX:_!==M,flipY:b!==F}),k=vi(this),D=O*Math.PI/180,A=O%360!==0;if(A){t.rotate(D);const M=Math.cos(D),F=Math.sin(D),X=f-c,W=p-u,R=X*M+W*F,J=-X*F+W*M;f=R+c,p=J+u;const it=Math.abs(M),Xt=Math.abs(F),Wt=s/2*it+r/2*Xt+h,Te=s/2*Xt+r/2*it+l;C=Wt,x=Te,g=-Wt-or(-Wt-R,h),d=-Te-or(-Te-J,l)}const L=(M,F,X,W)=>{xl(t,e,M,F,o,a,X,W,0)};if(fl(this)){const M=f-c,F=p-u;if(L(M,F,_,b),((H=(N=this.canvas)==null?void 0:N.getActiveObject)==null?void 0:H.call(N))===this){const W=Math.abs(Number((tt=($=this.canvas)==null?void 0:$.getZoom)==null?void 0:tt.call($))||1);t.save(),t.strokeStyle="#1677ff",t.lineWidth=10/W,t.setLineDash([18/W,15/W]),t.strokeRect(M,F,o,a),t.restore()}t.restore();return}const I=ar(e);if((m===""||m==="grid")&&k.x===0&&k.y===0&&!_&&!b&&hr(O)===0&&I.width>0&&I.height>0){const M=t.createPattern(e,"repeat");if(M){const F=f-c,X=p-u;M.setTransform(new DOMMatrix([o/I.width,0,0,a/I.height,F,X])),t.fillStyle=M,t.fillRect(v,w,s,r)}}else if(m==="brick-x")for(let M=d-l;M<x;M+=l){const F=u+M,W=Math.round((F-p)/l)&1?h/2:0;for(let R=g-h;R<C;R+=h)L(R+W,M,_,b)}else if(m==="brick-y")for(let M=d-l;M<x;M+=l)for(let F=g-h;F<C;F+=h){const X=c+F,R=Math.round((X-f)/h)&1?l/2:0;L(F,M+R,_,b)}else if(m==="mirror")for(let M=d;M<x;M+=l){const F=u+M,W=!!(Math.round((F-p)/l)&1);for(let R=g;R<C;R+=h){const J=c+R,Xt=!!(Math.round((J-f)/h)&1),{flipX:Wt,flipY:Te}=T(Xt,W);L(R,M,Wt,Te)}}else if(m==="random"){const M=this.patternSeed||1;for(let F=d;F<x;F+=l){const X=u+F,W=Math.round((X-p)/l);for(let R=g;R<C;R+=h){const J=c+R,it=Math.round((J-f)/h),Xt=yl(W,it,M),{flipX:Wt,flipY:Te}=T(!!(Xt&1),!!(Xt&2));L(R,F,Wt,Te)}}}else for(let M=d;M<x;M+=l)for(let F=g;F<C;F+=h)L(F,M,_,b);if(((ft=(K=this.canvas)==null?void 0:K.getActiveObject)==null?void 0:ft.call(K))===this){let M,F;if(this.patternActiveTileLeft!=null&&this.patternActiveTileTop!=null)M=this.patternActiveTileLeft,F=this.patternActiveTileTop;else{const J=ml(this,c,u);M=J.left,F=J.top}let X,W;if(A){const J=Math.cos(D),it=Math.sin(D),Xt=M-c,Wt=F-u;X=Xt*J+Wt*it,W=-Xt*it+Wt*J}else X=M-c,W=F-u;const R=Math.abs(Number((E=(at=this.canvas)==null?void 0:at.getZoom)==null?void 0:E.call(at))||1);t.save(),t.strokeStyle="#1677ff",t.lineWidth=10/R,t.setLineDash([18/R,15/R]),t.strokeRect(X,W,o,a),t.restore()}t.restore()}}xr(lr,"type","pattern-layer"),P.setClass(lr);function Po(n){var t;return!!((t=n==null?void 0:n.customData)!=null&&t.isPatternRect)||n instanceof lr||(n==null?void 0:n.type)===lr.type}function _l(n,t){return!(n!=null&&n.patternElement)||!t||!Po(n)?!1:(typeof t.setPatternElement=="function"?t.setPatternElement(n.patternElement):t.patternElement=n.patternElement,t.patternTileWidth=n.patternTileWidth,t.patternTileHeight=n.patternTileHeight,t.patternScale=n.patternScale,t.patternPhaseX=n.patternPhaseX,t.patternPhaseY=n.patternPhaseY,t.patternGapX=n.patternGapX,t.patternGapY=n.patternGapY,t.patternMode=n.patternMode,t.patternSeed=n.patternSeed,t.patternTileFlipX=n.patternTileFlipX,t.patternTileFlipY=n.patternTileFlipY,t.patternTileAngle=n.patternTileAngle,t.dirty=!0,!0)}const wl=n=>Number.isFinite(n)?Math.min(200,Math.max(1,Math.round(n))):100,Sl=n=>{var s,r;if(!n)return null;const t=(s=n.width)!=null?s:n.naturalWidth,e=(r=n.height)!=null?r:n.naturalHeight;return!t||!e?null:{width:t,height:e}};function Cl(n,t,e){var o,a;const s=(...h)=>{for(const l of h){const c=Number(l);if(Number.isFinite(c)&&c>0)return c}return null},r=(o=s(n==null?void 0:n.patternTileWidth,n==null?void 0:n.originalWidth,e==null?void 0:e.patternTileWidth,t==null?void 0:t.width))!=null?o:100,i=(a=s(n==null?void 0:n.patternTileHeight,n==null?void 0:n.originalHeight,e==null?void 0:e.patternTileHeight,t==null?void 0:t.height))!=null?a:100;return{tw:r,th:i}}class be{static getItem(t){if(!this.hasStorage)return null;try{return localStorage.getItem(t)}catch(e){return console.warn(`读取 localStorage 失败 [${t}]:`,e),null}}static setItem(t,e){if(!this.hasStorage)return!1;try{return localStorage.setItem(t,e),!0}catch(s){return console.warn(`写入 localStorage 失败 [${t}]:`,s),!1}}static removeItem(t){if(!this.hasStorage)return!1;try{return localStorage.removeItem(t),!0}catch(e){return console.warn(`删除 localStorage 失败 [${t}]:`,e),!1}}static clear(){if(!this.hasStorage)return!1;try{return localStorage.clear(),!0}catch(t){return console.warn("清空 localStorage 失败:",t),!1}}static isAvailable(){return this.hasStorage}}xr(be,"hasStorage",typeof window!="undefined"&&typeof localStorage!="undefined");class cr{static isBrowser(){return typeof window!="undefined"}static isWorker(){return typeof WorkerGlobalScope!="undefined"}static hasLocalStorage(){return this.isBrowser()&&typeof localStorage!="undefined"}static hasCanvas(){return this.isBrowser()&&typeof HTMLCanvasElement!="undefined"}static getDomain(){return this.isBrowser()?window.location.hostname:"localhost"}static getOrigin(){return this.isBrowser()?window.location.origin:"http://localhost"}}const vr=class vr{static parse(t){try{const e=cr.getOrigin();return new URL(t,e)}catch{return null}}static addParam(t,e,s){const r=this.parse(t);return!r||r.searchParams.has(e)?t:(r.searchParams.set(e,s),this.formatUrl(t,r))}static removeParam(t,e){const s=this.parse(t);return!s||!s.searchParams.has(e)?t:(s.searchParams.delete(e),this.formatUrl(t,s))}static hasParam(t,e){var r;const s=this.parse(t);return(r=s==null?void 0:s.searchParams.has(e))!=null?r:!1}static forceHttpsAsset(t){if(typeof t!="string"||!/^http:\/\//i.test(t))return t;const e=t.slice(t.indexOf("://")+3),s=e.split(/[/?#]/)[0].split("@").pop().split(":")[0];return vr.HTTPS_ASSET_HOST_RE.test(s)?"https://"+e:t}static formatUrl(t,e){const s=/^(https?:)?\/\//i.test(t),r=t.startsWith("//");return s?e.toString():r?e.toString().replace(/^https?:/,""):`${e.pathname}${e.search}${e.hash}`}static isDataUrl(t){var e;return(e=t==null?void 0:t.startsWith("data:"))!=null?e:!1}static isBlobUrl(t){var e;return(e=t==null?void 0:t.startsWith("blob:"))!=null?e:!1}};xr(vr,"HTTPS_ASSET_HOST_RE",/(^|\.)(r480\.cn|aliyuncs\.com)$/i);let dt=vr;const bl=new Map,Tl=new Map;function Ol(){bl.clear(),Tl.clear()}const Ml=new Map,kl=new Map;function Dl(){Ml.clear(),kl.clear()}const xi="file_token",_i="file_token_expire_time",El=60*1e3;function wi(){return be.getItem(xi)}function Pl(n=El){if(!wi())return!0;const e=be.getItem(_i);if(!e)return!1;const s=Number(e);return Date.now()+n>s}function Ao(n,t){if(be.setItem(xi,n),typeof t=="number"&&t>0){const e=Date.now()+t*1e3;be.setItem(_i,String(e))}}function Al(){be.removeItem(xi),be.removeItem(_i),Ol(),Dl()}async function Fo(n){var s,r;const t=await n(),e=(s=t==null?void 0:t.data)==null?void 0:s.data;return((r=t==null?void 0:t.data)==null?void 0:r.code)===200&&(e!=null&&e.file_token)?(Ao(e.file_token,e.expires_in),e.file_token):null}let Fl=null,Si=null;function Lo(n,t){Si=n,n&&Ao(n)}function Io(){return cr.isBrowser()?Fl:null}async function Ci(){if(Si)return Si;if(!cr.isBrowser())return wi();const n=wi();if(n&&!Pl())return n;try{const t=await Io();if(n&&(t!=null&&t.fetchFileTokenRefresh)){const e=await Fo(t.fetchFileTokenRefresh);if(e)return e}}catch{}try{const t=Io();return t!=null&&t.fetchFileToken?await Fo(t.fetchFileToken):null}catch{return null}}const jo=["/files/","/pd/","/pm/","/test/","/test-local/","/wd/","/whiteboard/"];function Ro(n){if(!n||dt.isDataUrl(n)||dt.isBlobUrl(n))return!1;const t=dt.parse(n);return t?jo.some(e=>t.pathname.includes(e))&&!dt.hasParam(n,"fileToken"):jo.some(e=>n.includes(e))&&!n.includes("fileToken=")}function bi(n,t){return n=dt.forceHttpsAsset(n),!t||!Ro(n)?n:dt.addParam(n,"fileToken",t)}function Ll(n){return dt.removeParam(n,"fileToken")}function Bo(n,t){const e=dt.forceHttpsAsset(n);return!t||dt.hasParam(e,"fileToken")?e:dt.addParam(e,"fileToken",t)}async function Il(n){if(!Ro(n))return n;const t=await Ci();return bi(n,t)}const Ti=new Map;function jl(n,t){return`${String((t==null?void 0:t.method)||"GET").toUpperCase()}\0${n}`}async function $o(n,t,e){if(!cr.isBrowser())return fetch(n,t);const s=dt.forceHttpsAsset(Ll(n)),r=(e==null?void 0:e.forceToken)===!0,i=jl(s,t)+"";let o=Ti.get(i);return o||(o=(async()=>{try{const h=r?Bo(s,await Ci()):await Il(s),l=3;let c=null;for(let u=0;u<l;u++)try{let g;try{g=await fetch(h,t)}catch{if((t==null?void 0:t.mode)==="cors")g=await fetch(h,{...t,cache:"no-store"});else throw new Error("fetch failed")}if(g.status===401){Al();const d=await Ci(),f=r?Bo(s,d):bi(s,d);return await fetch(f,t)}if(g.status>=500&&u<l-1){c=new Error(`HTTP ${g.status}`),await new Promise(d=>setTimeout(d,300*Math.pow(2,u)));continue}return g}catch(g){if(c=g,u<l-1){await new Promise(d=>setTimeout(d,300*Math.pow(2,u)));continue}}throw c!=null?c:new Error("fetchWithFileToken failed")}finally{Ti.delete(i)}})(),Ti.set(i,o)),(await o).clone()}const Oi="all";function Rl(n){if(!(!n||n===Oi))return n}function Bl(n,t){if(n==null)return!0;if(Array.isArray(n)){if(n.length===0||n.includes(Oi))return!0;const s=n.filter(r=>r!==Oi);return s.length===0||t==null?!0:s.includes(t)}const e=Rl(n);return!e||t==null?!0:t===e}function Xo(n){const t=n==null?void 0:n.bounds;if(t&&typeof t.width=="number"&&typeof t.height=="number"&&t.width>0&&t.height>0)return{left:typeof t.left=="number"?t.left:0,top:typeof t.top=="number"?t.top:0,width:t.width,height:t.height};if(Array.isArray(n.children))for(const e of n.children){const s=Xo(e);if(s)return s}return null}const $l=(n,t)=>{var r;const e=Math.max(1,Number(t.canvasWidth)||1);let s=Number(t.canvasHeight);if(!s||!Number.isFinite(s)){const i=Array.isArray(n)?n.find(o=>(o==null?void 0:o.name)==="bg"):null;s=Math.max(1,Number((r=i==null?void 0:i.bounds)==null?void 0:r.height)||e)}return{psdW:e,psdH:s}},Xl=(n,t,e,s)=>{const r=Math.max(1,n),i=Math.max(1,t),o=Math.max(1,e),a=Math.max(1,s),h=Math.min(o/r,a/i),l=(o-r*h)/2,c=(a-i*h)/2;return{scale:h,offsetX:l,offsetY:c}},Wl=(n,t,e,s,r)=>{const{scale:i,offsetX:o,offsetY:a}=Xl(t,e,s,r);return{left:o+n.left*i,top:a+n.top*i,width:n.width*i,height:n.height*i}},Yl=(n,t="split")=>{var o;if(!Array.isArray(n))return[];const e=(a,h="split")=>{for(const l of a){if((l==null?void 0:l.name)===h&&(l==null?void 0:l.type)==="Group")return l;if(Array.isArray(l.children)){const c=e(l.children);if(c)return c}}return null},s=e(n,t),r=(o=s==null?void 0:s.children)!=null?o:[],i=[];for(const a of r){if((a==null?void 0:a.type)!=="Group"||a.id==null)continue;const h=Xo(a);h&&i.push({id:a.id,name:a.name||"",bounds:h})}return i},Nl=(n,t)=>{var a,h,l;const r=((a=n==null?void 0:n.data)!=null?a:[]).filter(c=>Bl(t,c==null?void 0:c.size)).find(c=>(c==null?void 0:c.type)==="SPLIT");if(!(r!=null&&r.jsonURL))return null;const i=(h=r.resources)!=null?h:[],o=new Map;for(const c of i){if(!(c!=null&&c.groupId))continue;const u=String(c.groupId);let g=o.get(u);g||(g={groupId:u,groupName:String((l=c.groupName)!=null?l:""),maskUrl:"",maskWidth:0,maskHeight:0},o.set(u,g)),c.groupName&&(g.groupName=String(c.groupName)),c.type==="MASK"&&c.url&&(g.maskUrl=c.url,g.maskWidth=Number(c.width)||0,g.maskHeight=Number(c.height)||0),c.type==="DOTTED_LINE"&&c.url&&(g.dottedLineUrl=c.url,g.dottedLineWidth=Number(c.width)||0,g.dottedLineHeight=Number(c.height)||0)}for(const[c,u]of[...o]){const g=!!(u.maskUrl&&u.maskWidth&&u.maskHeight),d=!!(u.dottedLineUrl&&u.dottedLineWidth&&u.dottedLineHeight)||!!(u.dottedLineUrl&&g);!g&&!d&&o.delete(c)}return o.size?{jsonURL:r.jsonURL,slicesByGroupId:o}:null},ur=(n,t="image/png",e)=>new Promise((s,r)=>{n.toBlob(i=>{if(!i){r(new Error("canvas toBlob failed"));return}s(i)},t,e)});function Hl(n,t){if(t)return;const e=n.backgroundColor;return e!=null&&e!==""?String(e):"#ffffff"}const Wo="guide-resource",gr=(n,t)=>{var s;const e=(s=n==null?void 0:n.customData)==null?void 0:s.role;return e===t||e==="guide"||e==="grid"},Gl=n=>{var e;const t=(e=n==null?void 0:n.customData)==null?void 0:e.guideKind;return t==="split-piece-mask"||t==="split-piece-dotted"};function Yo(n,t=Wo){var g,d,f;const e=Math.max(1,typeof n.getWidth=="function"?n.getWidth():1),s=Math.max(1,typeof n.getHeight=="function"?n.getHeight():1);let r=0,i=0,o=e,a=s;for(const p of(d=(g=n.getObjects)==null?void 0:g.call(n))!=null?d:[])if(!(gr(p,t)&&!Gl(p))&&p.type!=="activeSelection"&&!((f=p.customData)!=null&&f.isPatternRect)&&!p.group&&typeof p.getBoundingRect=="function")try{const m=p.getBoundingRect(!0,!0);if(!m||!Number.isFinite(m.width)||!Number.isFinite(m.height))continue;r=Math.min(r,m.left),i=Math.min(i,m.top),o=Math.max(o,m.left+m.width),a=Math.max(a,m.top+m.height)}catch{}const l=n.backgroundImage;if(l&&typeof l.getBoundingRect=="function")try{const p=l.getBoundingRect(!0,!0);p&&Number.isFinite(p.width)&&Number.isFinite(p.height)&&(r=Math.min(r,p.left),i=Math.min(i,p.top),o=Math.max(o,p.left+p.width),a=Math.max(a,p.top+p.height))}catch{}const c=Math.max(1,Math.ceil(o-r)),u=Math.max(1,Math.ceil(a-i));return{minL:r,minT:i,maxR:o,maxB:a,width:c,height:u}}async function Vl(n,t,e,s){var c;const r=document.createElement("canvas"),i=Yo(n,t),o=i.width,a=i.height,h=n;let l=null;try{l=new Le(r,{width:o,height:a,renderOnAddRemove:!1,enableRetinaScaling:!!h.enableRetinaScaling,backgroundColor:Hl(h,s)}),l.setViewportTransform([1,0,0,1,-i.minL,-i.minT]);const u=h.backgroundImage;if(!s&&u&&typeof u.clone=="function")try{l.backgroundImage=await u.clone()}catch{}const g=performance.now();for(const m of n.getObjects())if(!gr(m,t)&&m.type!=="activeSelection")try{const v=await m.clone();Po(v)&&_l(m,v);const w=m.group;if(w){const C=typeof m.calcOwnMatrix=="function"?m.calcOwnMatrix():m.calcTransformMatrix(),x=typeof w.calcTransformMatrix=="function"?w.calcTransformMatrix():null,_=x?oo.multiplyTransformMatrices(x,C):m.calcTransformMatrix(),b=oo.qrDecompose(_);v.set({originX:"center",originY:"center",left:b.translateX,top:b.translateY,angle:b.angle,scaleX:b.scaleX,scaleY:b.scaleY,skewX:b.skewX,skewY:b.skewY,flipX:m.flipX,flipY:m.flipY}),(c=v.setCoords)==null||c.call(v)}l.add(v)}catch(v){return console.warn("[fabricMainCanvasSnapshot] offscreen clone failed:",m.type,v),null}const d=Math.round(performance.now()-g);l.requestRenderAll(),await new Promise(m=>requestAnimationFrame(()=>requestAnimationFrame(()=>m())));const f=l;if(typeof f.toBlob=="function"){const m=await f.toBlob({format:"png",quality:1,multiplier:e,enableRetinaScaling:!!l.enableRetinaScaling});return m!=null?m:null}const p=l.lowerCanvasEl;if(!p)return null;if(e<1){const m=Math.max(1,Math.floor(p.width*e)),v=Math.max(1,Math.floor(p.height*e)),w=document.createElement("canvas");w.width=m,w.height=v;const C=w.getContext("2d");return C?(C.imageSmoothingEnabled=!0,C.imageSmoothingQuality="medium",C.drawImage(p,0,0,p.width,p.height,0,0,m,v),await ur(w,"image/png")):null}return await ur(p,"image/png")}catch(u){return console.warn("[fabricMainCanvasSnapshot] offscreen export failed:",u),null}finally{if(l)try{await l.dispose()}catch{}}}async function zl(n,t,e){var o,a,h,l;const s=n;if(typeof s.toBlob=="function"){let c;try{c=n.getActiveObject(),c&&((o=s._discardActiveObject)==null||o.call(s));const u=await s.toBlob({format:"png",quality:1,multiplier:e,enableRetinaScaling:!!s.enableRetinaScaling,filter:g=>!gr(g,t)});return u!=null?u:null}catch(u){return console.warn("[fabricMainCanvasSnapshot] toBlob(filter) 导出失败:",u),null}finally{try{c&&((a=s._setActiveObject)==null||a.call(s,c)),n.renderAll()}catch{}}}const r=[];let i;try{for(const u of n.getObjects())gr(u,t)&&(r.push({obj:u,visible:u.visible!==!1}),u.set("visible",!1));i=n.getActiveObject(),i&&((h=n._discardActiveObject)==null||h.call(n)),n.renderAll();const c=n.lowerCanvasEl;if(!c)return null;if(e<1){const u=Math.max(1,Math.floor(c.width*e)),g=Math.max(1,Math.floor(c.height*e)),d=document.createElement("canvas");d.width=u,d.height=g;const f=d.getContext("2d");return f?(f.imageSmoothingEnabled=!0,f.imageSmoothingQuality="medium",f.drawImage(c,0,0,c.width,c.height,0,0,u,g),await ur(d,"image/png")):null}return await ur(c,"image/png")}catch(c){return console.warn("[fabricMainCanvasSnapshot] 导出主画布失败:",c),null}finally{for(const{obj:c,visible:u}of r)try{c.set("visible",u)}catch{}try{i&&((l=n._setActiveObject)==null||l.call(n,i)),n.renderAll()}catch{}}}async function No(n,t){var h;const e=(h=t==null?void 0:t.guideResourceRole)!=null?h:Wo,s=(t==null?void 0:t.multiplier)!=null&&t.multiplier>0?t.multiplier:1,r=!!(t!=null&&t.useIdentityViewport),i=(t==null?void 0:t.transparentBackground)===!0;if(r){const l=await Vl(n,e,s,i);if(l)return l;if(i)return console.warn("[fabricMainCanvasSnapshot] 透明底离屏导出失败,不再回退主画布直读(会带白底)"),null;console.warn("[fabricMainCanvasSnapshot] 离屏导出失败,回退为临时单位视口")}let o=null;const a=()=>{if(!(!r||!o||o.length<6))try{n.setViewportTransform(o),n.requestRenderAll()}catch{}};try{if(r){const c=n.viewportTransform;o=Array.isArray(c)&&c.length>=6?[...c]:[1,0,0,1,0,0],n.setViewportTransform([1,0,0,1,0,0]),n.requestRenderAll(),await new Promise(u=>requestAnimationFrame(()=>requestAnimationFrame(()=>u())))}return await zl(n,e,s)}finally{a()}}const dr=[{family:"Oswald",googleSlug:"Oswald",category:"sans-serif"},{family:"EB Garamond",googleSlug:"EB+Garamond",category:"serif"},{family:"Itim",googleSlug:"Itim",category:"handwriting"},{family:"Tangerine",googleSlug:"Tangerine",category:"handwriting"},{family:"Pinyon Script",googleSlug:"Pinyon+Script",category:"handwriting"},{family:"Arizonia",googleSlug:"Arizonia",category:"handwriting"},{family:"Ballet",googleSlug:"Ballet",category:"handwriting"},{family:"Roboto",googleSlug:"Roboto",category:"sans-serif"},{family:"Open Sans",googleSlug:"Open+Sans",category:"sans-serif"},{family:"Montserrat",googleSlug:"Montserrat",category:"sans-serif"},{family:"Lato",googleSlug:"Lato",category:"sans-serif"},{family:"Poppins",googleSlug:"Poppins",category:"sans-serif"},{family:"Raleway",googleSlug:"Raleway",category:"sans-serif"},{family:"Inter",googleSlug:"Inter",category:"sans-serif"},{family:"Bebas Neue",googleSlug:"Bebas+Neue",category:"sans-serif"},{family:"Anton",googleSlug:"Anton",category:"sans-serif"},{family:"Playfair Display",googleSlug:"Playfair+Display",category:"serif"},{family:"Merriweather",googleSlug:"Merriweather",category:"serif"},{family:"Lora",googleSlug:"Lora",category:"serif"},{family:"PT Serif",googleSlug:"PT+Serif",category:"serif"},{family:"Cormorant Garamond",googleSlug:"Cormorant+Garamond",category:"serif"},{family:"Lobster",googleSlug:"Lobster",category:"display"},{family:"Pacifico",googleSlug:"Pacifico",category:"display"},{family:"Abril Fatface",googleSlug:"Abril+Fatface",category:"display"},{family:"Alfa Slab One",googleSlug:"Alfa+Slab+One",category:"display"},{family:"Dancing Script",googleSlug:"Dancing+Script",category:"handwriting"},{family:"Caveat",googleSlug:"Caveat",category:"handwriting"},{family:"Great Vibes",googleSlug:"Great+Vibes",category:"handwriting"},{family:"Satisfy",googleSlug:"Satisfy",category:"handwriting"},{family:"Permanent Marker",googleSlug:"Permanent+Marker",category:"handwriting"},{family:"Roboto Mono",googleSlug:"Roboto+Mono",category:"monospace"}],Ho=dr.map(n=>n.family);(ea=Ho[1])!=null||Ho[0];const Ul="https://fonts.loli.net/css2";let Go=!1;function ql(){if(!(Go||typeof document=="undefined")){Go=!0;for(const n of dr){const t=`gf-${n.googleSlug}`;if(document.getElementById(t))continue;const e=document.createElement("link");e.id=t,e.rel="stylesheet",e.href=`${Ul}?family=${n.googleSlug}:ital,wght@0,400;0,700;1,400;1,700&display=swap`,document.head.appendChild(e)}}}const Kl=new Set(dr.map(n=>n.family));async function Jl(n){if(typeof document=="undefined"||!document.fonts)return;ql();const t=n.length?n.filter(s=>Kl.has(s)):dr.map(s=>s.family),e=[];for(const s of t)e.push(document.fonts.load(`400 16px "${s}"`).catch(()=>{})),e.push(document.fonts.load(`700 16px "${s}"`).catch(()=>{})),e.push(document.fonts.load(`italic 400 16px "${s}"`).catch(()=>{})),e.push(document.fonts.load(`italic 700 16px "${s}"`).catch(()=>{}));await Promise.all(e);try{await document.fonts.ready}catch{}}function Ql(n){const t=new Set,e=s=>{if(Array.isArray(s))for(const r of s)r&&typeof r.fontFamily=="string"&&r.fontFamily&&t.add(r.fontFamily),Array.isArray(r==null?void 0:r.objects)&&e(r.objects)};return e(n),Array.from(t)}function Mi(n){const t=n/255;return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function fr(n,t,e){const s=Mi(n),r=Mi(t),i=Mi(e);let o=s*.4124+r*.3576+i*.1805,a=s*.2126+r*.7152+i*.0722,h=s*.0193+r*.1192+i*.9505;o/=.95047,h/=1.08883;const l=d=>d>.008856?Math.cbrt(d):7.787*d+16/116,c=l(o),u=l(a),g=l(h);return[116*u-16,500*(c-u),200*(u-g)]}function pr(n,t){const e=n[0]-t[0],s=n[1]-t[1],r=n[2]-t[2];return e*e+s*s+r*r}function Zl(n,t,e,s=12){const r=n.length,i=Math.max(1,Math.min(e,r)),o=[0],a=new Float64Array(r).fill(1/0);for(let p=1;p<i;p++){const m=n[o[p-1]];let v=0;for(let x=0;x<r;x++){const _=pr(n[x],m);_<a[x]&&(a[x]=_),v+=a[x]}let w=v*(p*.6180339887%1),C=0;for(let x=0;x<r;x++)if(w-=a[x],w<=0){C=x;break}o.push(C)}const h=o.map(p=>n[p].slice()),l=new Int32Array(r);for(let p=0;p<s;p++){let m=0;for(let _=0;_<r;_++){let b=0,O=1/0;for(let T=0;T<i;T++){const k=pr(n[_],h[T]);k<O&&(O=k,b=T)}l[_]!==b&&m++,l[_]=b}const v=new Float64Array(i),w=new Float64Array(i),C=new Float64Array(i),x=new Int32Array(i);for(let _=0;_<r;_++){const b=l[_];v[b]+=n[_][0],w[b]+=n[_][1],C[b]+=n[_][2],x[b]++}for(let _=0;_<i;_++)x[_]>0&&(h[_]=[v[_]/x[_],w[_]/x[_],C[_]/x[_]]);if(m===0&&p>0)break}const c=new Float64Array(i),u=new Float64Array(i),g=new Float64Array(i),d=new Int32Array(i);for(let p=0;p<r;p++){const m=l[p];c[m]+=t[p][0],u[m]+=t[p][1],g[m]+=t[p][2],d[m]++}const f=[];for(let p=0;p<i;p++)d[p]>0?f.push([Math.round(c[p]/d[p]),Math.round(u[p]/d[p]),Math.round(g[p]/d[p])]):f.push([128,128,128]);return{centersLab:h,centersRgb:f}}function tc(n,t,e,s){var K,ft,at;const r=t*e,i=(K=s.alphaThreshold)!=null?K:128,o=n;let a=0;for(let E=3;E<o.length;E+=4)o[E]>i&&a++;const l=Math.max(1,Math.floor(a/4e4)),c=[],u=[];let g=0;for(let E=0;E<r;E++){const M=E*4;if(!(o[M+3]<=i)){if(g%l===0){const F=o[M],X=o[M+1],W=o[M+2];u.push([F,X,W]),c.push(fr(F,X,W))}g++}}if(c.length===0)return{width:t,height:e,regionIds:new Int32Array(r).fill(-1),regions:[],palette:[]};const{centersLab:d,centersRgb:f}=Zl(c,u,s.k),p=d.length,m=new Int32Array(r).fill(-1);for(let E=0;E<r;E++){const M=E*4;if(o[M+3]<=i)continue;const F=fr(o[M],o[M+1],o[M+2]);let X=0,W=1/0;for(let R=0;R<p;R++){const J=pr(F,d[R]);J<W&&(W=J,X=R)}m[E]=X}const v=(ft=s.minRegionArea)!=null?ft:Math.max(16,Math.round(r*4e-4)),w=((at=s.mergeColorDist)!=null?at:14)**2,C=new Int32Array(p);for(let E=0;E<p;E++)C[E]=E;const x=E=>{let M=E;for(;C[M]!==M;)M=C[M];for(;C[E]!==M;){const F=C[E];C[E]=M,E=F}return M};for(let E=0;E<p;E++)for(let M=E+1;M<p;M++)if(pr(d[E],d[M])<w){const F=x(E),X=x(M);F!==X&&(C[F]=X)}const _=new Int32Array(p),b=new Map;let O=0;for(let E=0;E<p;E++){const M=x(E);let F=b.get(M);F===void 0&&(F=O++,b.set(M,F)),_[E]=F}const T=new Int32Array(r).fill(-1),k=new Float64Array(O),D=new Float64Array(O),A=new Float64Array(O),L=new Float64Array(O),I=new Int32Array(O).fill(t),j=new Int32Array(O).fill(e),U=new Int32Array(O).fill(-1),N=new Int32Array(O).fill(-1);for(let E=0;E<e;E++){const M=E*t;for(let F=0;F<t;F++){const X=M+F,W=m[X];if(W<0)continue;const R=_[W];T[X]=R;const J=f[W];k[R]++,D[R]+=J[0],A[R]+=J[1],L[R]+=J[2],F<I[R]&&(I[R]=F),E<j[R]&&(j[R]=E),F>U[R]&&(U[R]=F),E>N[R]&&(N[R]=E)}}const H=new Int32Array(O).fill(-1),$=[];let tt=0;for(let E=0;E<O;E++)k[E]<v||(H[E]=tt,$.push({id:tt,color:[Math.round(D[E]/k[E]),Math.round(A[E]/k[E]),Math.round(L[E]/k[E])],area:k[E],bbox:{x:I[E],y:j[E],w:U[E]-I[E]+1,h:N[E]-j[E]+1}}),tt++);for(let E=0;E<r;E++){const M=T[E];T[E]=M<0?-1:H[M]}return{width:t,height:e,regionIds:T,regions:$,palette:f}}const ec=(n,t,e,s)=>n>=0&&t>=0&&n<e&&t<s;function ne(n,t,e){const s=t|0,r=e|0;return ec(s,r,n.width,n.height)?n.regionIds[r*n.width+s]===n.targetId:!1}const Vo=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]];function ki(n,t){if(n.length<2)return n.slice();const e=[n[0]];let s=t,r=0;for(let a=1;a<n.length;a++){const[h,l]=n[a-1],[c,u]=n[a],g=Math.hypot(c-h,u-l);if(g!==0){for(;r+g>=s;){const d=(s-r)/g;e.push([h+(c-h)*d,l+(u-l)*d]),s+=t}r+=g}}const i=n[n.length-1],o=e[e.length-1];return Math.hypot(i[0]-o[0],i[1]-o[1])>t*.4&&e.push(i),e}function He(n,t,e){const{bbox:s}=n,r=s.x+s.w/2,i=s.y+s.h/2,o=n.angle*Math.PI/180,a=Math.cos(o),h=Math.sin(o),l=-h,c=a,u=Math.ceil(Math.hypot(s.w,s.h)/2)+t,g=[];let d=0;for(let f=-u;f<=u;f+=t){const p=r+l*f,m=i+c*f,v=[];let w=!1,C=0;for(let x=-u;x<=u;x+=1){const _=ne(n,p+a*x,m+h*x);_&&!w?(w=!0,C=x):!_&&w&&(w=!1,v.push([C,x-1]))}if(w&&v.push([C,u]),v.length){const x=d%2===0?v:v.slice().reverse();for(const _ of x){let[b,O]=_;d%2!==0&&([b,O]=[O,b]);const T=Math.abs(O-b),k=Math.max(1,Math.round(T/e));for(let D=0;D<=k;D++){const A=b+(O-b)*D/k;g.push([p+a*A,m+h*A])}}}d++}return g}function Di(n,t){const{bbox:e}=n;let s=-1,r=-1;for(let u=e.y;u<e.y+e.h&&r<0;u++)for(let g=e.x;g<e.x+e.w;g++)if(t(g,u)){s=g,r=u;break}if(s<0)return[];const i=[];let o=s,a=r,h=6;const l=(e.w+e.h)*8+32;let c=0;do{i.push([o,a]);let u=!1;for(let g=0;g<8;g++){const d=(h+1+g)%8,f=o+Vo[d][0],p=a+Vo[d][1];if(t(f,p)){o=f,a=p,h=(d+4)%8,u=!0;break}}if(!u)break;c++}while((o!==s||a!==r)&&c<l);return i}function sc(n,t){if(t<=0)return(s,r)=>ne(n,s,r);const e=t*t;return(s,r)=>{for(let i=-t;i<=t;i++)for(let o=-t;o<=t;o++)if(!(o*o+i*i>e)&&!ne(n,s+o,r+i))return!1;return!0}}function rc(n,t){const e=[],s=Math.ceil(Math.min(n.bbox.w,n.bbox.h)/(2*Math.max(1,n.spacing)))+1;for(let r=0;r<s;r++){const i=r*n.spacing,o=Di(n,sc(n,i));if(o.length<3)break;e.push(...ki(o,Math.max(t,n.spacing)))}return e}function zo(n,t,e){const s=[],r=t/2;for(let i=n.bbox.y;i<n.bbox.y+n.bbox.h;i+=t)for(let o=n.bbox.x;o<n.bbox.x+n.bbox.w;o+=t)ne(n,o+r,i+r)&&(e==="cross"?s.push([o,i],[o+t,i+t],[o+t,i],[o,i+t]):s.push([o+r,i+r],[o+r+1,i+r],[o+r,i+r+1],[o+r,i+r]));return s}function ic(n,t){let e=0,s=0,r=0;for(let g=n.bbox.y;g<n.bbox.y+n.bbox.h;g+=2)for(let d=n.bbox.x;d<n.bbox.x+n.bbox.w;d+=2)ne(n,d,g)&&(e+=d,s+=g,r++);if(!r)return[];const i=e/r,o=s/r,a=Math.hypot(n.bbox.w,n.bbox.h)/2,h=Math.max(.5,n.spacing)/(2*Math.PI),l=[];let c=0,u=0;for(;u++<2e4;){const g=h*c;if(g>a)break;const d=i+g*Math.cos(c),f=o+g*Math.sin(c);ne(n,d,f)&&l.push([d,f]),c+=t/Math.max(1,h*(c/(2*Math.PI)+.5))}return l}function nc(n){var s;const t=Math.max(1,n.spacing),e=Math.max(1,(s=n.stitchLen)!=null?s:Math.max(2.5,t*.6));switch(n.stitchType){case"satin":return He(n,Math.max(1.2,t*.5),e);case"fill":case"zigzag":case"estitch":return He(n,t,e);case"meander":return He(n,Math.max(t,6),Math.max(e,4));case"tartan":{const r=He(n,t,e),i=He({...n,angle:n.angle+90},t,e);return r.concat(i)}case"running":return ki(Di(n,(r,i)=>ne(n,r,i)),Math.max(e,t));case"bean":{const r=ki(Di(n,(o,a)=>ne(n,o,a)),Math.max(e,t)),i=[];for(let o=0;o<r.length;o++)i.push(r[o]),o>0&&i.push(r[o-1],r[o]);return i}case"contour":case"circular":return rc(n,e);case"cross":return zo(n,Math.max(6,t),"cross");case"frenchKnot":return zo(n,Math.max(5,t),"knot");case"spiral":return ic(n,e);default:return He(n,t,e)}}const oc={satin:4,fill:5,running:8,bean:7,zigzag:7,estitch:9,cross:9,tartan:12,circular:6,contour:6,spiral:6,meander:9,frenchKnot:7},Uo=1e3,qo=1600;async function mr(n,t){if(n&&typeof n=="object")return n;if(typeof n!="string"||!n.trim())throw new Error("JSON 入参为空");let e=dt.forceHttpsAsset(n.trim());t&&(e+=(e.includes("?")?"&":"?")+"file_token="+encodeURIComponent(t));let s=null;for(let r=0;r<3;r++){try{const i=await fetch(e);if(i.ok)return await i.json();if(i.status<500)throw new Error(`加载 JSON 失败 HTTP ${i.status}: ${e.slice(0,80)}`);s=new Error(`加载 JSON 失败 HTTP ${i.status}: ${e.slice(0,80)}`)}catch(i){if(s=i,i instanceof Error&&/HTTP 4\d\d/.test(i.message))throw i}r<2&&await new Promise(i=>setTimeout(i,200*(r+1)))}throw s instanceof Error?s:new Error("加载 JSON 失败: "+e.slice(0,80))}function ac(n,t,e){var m,v;const s=n!=null&&n.stateMap&&typeof n.stateMap=="object"?n.stateMap:{},r=Number(n==null?void 0:n.designCanvasSize)>0?Number(n.designCanvasSize):Uo,i=Number(n==null?void 0:n.designCanvasHeight)>0?Number(n.designCanvasHeight):qo,o=String((m=e!=null?e:n==null?void 0:n.selectedSize)!=null?m:"").trim(),a=w=>{const C=String(w!=null?w:"").trim().toLowerCase();return C==="default"||C==="all"||C==="common"?"":C},h=a(o),c=(Array.isArray(n==null?void 0:n.data)?n.data:[]).filter(w=>(w==null?void 0:w.type)===t),u=c.filter(w=>{var x;const C=a(String((x=w==null?void 0:w.size)!=null?x:""));return!h||C===h||C===""}),g=u[u.length-1]||c[c.length-1]||null,d=g&&typeof g.jsonURL=="object"?g.jsonURL:null,f=Array.isArray(g==null?void 0:g.resources)?g.resources:[],p=[];for(const w of Object.keys(s)){let C="";if(w.includes("::")){const[k,D]=w.split("::"),A=a(D!=null?D:"");if(h&&A!==""&&A!==h)continue;C=k}else C=w;const x=s[w];if(!x||typeof x!="object")continue;const _=Number(x.designCanvasSize)>0?Number(x.designCanvasSize):r,b=Number(x.designCanvasHeight)>0?Number(x.designCanvasHeight):i,O=f.filter(k=>{var D;return String((D=k==null?void 0:k.groupId)!=null?D:"")===String(C)}),T=((v=O.find(k=>k==null?void 0:k.groupName))==null?void 0:v.groupName)||"";p.push({groupId:String(C),name:T,state:x,savedCanvasW:_,savedCanvasH:b,resources:O,guideline:d})}return p}function hc(n,t){return!n||!t?n:bi(n,t)}function Ei(n){return new Promise((t,e)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>t(s),s.onerror=()=>e(new Error("图片加载失败: "+n.slice(0,80))),s.src=dt.forceHttpsAsset(n)})}async function yr(n,t){if(n&&/^https?:/i.test(n)){try{const e=await $o(n,{mode:"cors"});if(e.ok)return await Ei(URL.createObjectURL(await e.blob()))}catch{}return await Ei(hc(n,t))}return await Ei(n)}function Pi(n,t="image/png",e){return new Promise((s,r)=>{n.toBlob(i=>i?s(i):r(new Error("canvas.toBlob 返回空")),t,e)})}async function lc(n,t){var s,r,i,o,a,h,l,c,u,g;const e=(r=(s=n.getObjects)==null?void 0:s.call(n))!=null?r:[];for(const d of e){if(!((i=d==null?void 0:d.customData)!=null&&i.isPatternRect))continue;const f=d.customData.patternSource||d.customData.savedSrc;if(!(!f||typeof f!="string"))try{const p=await yr(f,t),m=(o=d.customData.patternScale)!=null?o:100,v=Math.max(.01,wl(m)/100),w=Sl(p),{tw:C,th:x}=Cl(d.customData,w,{patternTileWidth:d.patternTileWidth,patternTileHeight:d.patternTileHeight});typeof d.setPatternElement=="function"?d.setPatternElement(p):d.patternElement=p,d.patternTileWidth=C,d.patternTileHeight=x,d.patternScale=v;const _=vi(d);d.patternGapX=_.x,d.patternGapY=_.y,d.customData={...d.customData||{},patternTileWidth:C,patternTileHeight:x,patternGapX:_.x,patternGapY:_.y};const b=typeof((a=d.customData)==null?void 0:a.patternPhaseX)=="number"?d.customData.patternPhaseX:typeof((h=d.fill)==null?void 0:h.offsetX)=="number"?((l=d.left)!=null?l:0)+d.fill.offsetX:d.patternPhaseX||0,O=typeof((c=d.customData)==null?void 0:c.patternPhaseY)=="number"?d.customData.patternPhaseY:typeof((u=d.fill)==null?void 0:u.offsetY)=="number"?((g=d.top)!=null?g:0)+d.fill.offsetY:d.patternPhaseY||0;typeof d.setPatternPhase=="function"?d.setPatternPhase(b,O):(d.patternPhaseX=b,d.patternPhaseY=O),d.objectCaching=!1,d.dirty=!0}catch(p){console.warn("[productionRender] rebuildPattern 失败",p)}}}async function Ko(n,t){var v;(v=n.renderAll)==null||v.call(n);const e=n.getWidth?n.getWidth():1,s=n.getHeight?n.getHeight():1,r=n.getElement?n.getElement():n.lowerCanvasEl;if(!r)throw new Error("无法取得 Fabric 画布元素");const i=await Pi(r),o=await createImageBitmap(i),a=o.width/e,h=o.height/s,l=Math.max(0,Math.floor(t.left*a)),c=Math.max(0,Math.floor(t.top*h)),u=Math.max(1,Math.min(o.width-l,Math.ceil(t.width*a))),g=Math.max(1,Math.min(o.height-c,Math.ceil(t.height*h))),d=Math.max(1,Math.round(t.width)),f=Math.max(1,Math.round(t.height)),p=document.createElement("canvas");p.width=d,p.height=f;const m=p.getContext("2d");return m?(m.imageSmoothingEnabled=!0,m.imageSmoothingQuality="high",m.drawImage(o,l,c,u,g,0,0,d,f),o.close(),Pi(p)):(o.close(),i)}async function Jo(n,t){const e=Math.max(1,Math.round(n.savedCanvasW)),s=Math.max(1,Math.round(n.savedCanvasH)),r=document.createElement("canvas");r.width=e,r.height=s;const i=new hi(r,{width:e,height:s,preserveObjectStacking:!0,enableRetinaScaling:!1,renderOnAddRemove:!1}),o=JSON.parse(JSON.stringify(n.state)),a=Array.isArray(o.objects)?o.objects:[];let h=0,l=0,c=0;for(const g of a)if(String(g==null?void 0:g.type).toLowerCase()==="image"&&typeof g.src=="string"&&/^https?:/i.test(g.src)){h++;try{const d=await $o(g.src,{mode:"cors"});d.ok?(g.src=URL.createObjectURL(await d.blob()),l++):(c++,console.warn(`[productionRender] 设计图 fetch !ok status=${d.status} ${String(g.src).slice(0,80)}`))}catch(d){c++,console.warn(`[productionRender] 设计图 fetch 异常 ${String(g.src).slice(0,80)}`,d)}}await i.loadFromJSON(o,(g,d)=>{var f;String(d==null?void 0:d.type).toLowerCase()==="image"&&((f=d.set)==null||f.call(d,{crossOrigin:"anonymous"}))}),console.log(`[productionRender] loadFromJSON done piece=${n.groupId} jsonObjs=${a.length} httpImg(total/ok/fail)=${h}/${l}/${c} loadedObjs=${i.getObjects().length} loadedTypes=${JSON.stringify(i.getObjects().map(g=>g.type))}`),await lc(i,t);const u=Ql(a);return await Jl(u),console.log(`[productionRender] fonts ready piece=${n.groupId} families=${JSON.stringify(u)}`),i.renderAll(),{canvas:i,W:e,H:s}}async function cc(n,t,e=!1){var o;const{canvas:s,W:r,H:i}=await Jo(n,t);try{const a=(n.resources||[]).find(c=>(c==null?void 0:c.type)==="MASK");if(console.log(`[productionRender] piece=${n.groupId} name=${n.name} canvas=${r}x${i} objects=${s.getObjects().length} mask=${a!=null&&a.url?"Y":"N"} restoreOnly=${e}`),e){const c=await No(s,{useIdentityViewport:!0,transparentBackground:!0});return c!=null?c:await Ko(s,{left:0,top:0,width:r,height:i})}const h=(n.resources||[]).find(c=>(c==null?void 0:c.type)==="MASK");let l={left:0,top:0,width:r,height:i};if(h!=null&&h.url){const c=Number(h.width)||1e3,u=Number(h.height)||1e3,g=Math.min(r/c,i/u),d=c*g,f=u*g,p=(r-d)/2,m=(i-f)/2,v=await yr(h.url,t),w=new Ft(v,{left:p+d/2,top:m+f/2,originX:"center",originY:"center",scaleX:d/c,scaleY:f/u,selectable:!1,evented:!1,globalCompositeOperation:"destination-in"});s.add(w),s.renderAll(),l={left:p,top:m,width:d,height:f}}return await Ko(s,l)}finally{try{(o=s.dispose)==null||o.call(s)}catch{}}}async function uc(n,t,e=!1){const s=[];for(const r of n)try{const i=await cc(r,t,e);i&&s.push({id:r.groupId,name:r.name,blob:i})}catch(i){console.warn("[productionRender] 分片渲染失败",r.groupId,r.name,i)}return s}function Qo(n,t,e){var h;const s=Array.isArray(n==null?void 0:n.data)?n.data:[],r=String((h=e!=null?e:n==null?void 0:n.selectedSize)!=null?h:"").trim().toLowerCase(),i=l=>{var c;return String((c=l==null?void 0:l.size)!=null?c:"").trim().toLowerCase()},o=s.filter(l=>(l==null?void 0:l.type)===t),a=o.filter(l=>!r||i(l)===r);return a[a.length-1]||o.find(l=>i(l)==="default")||o[o.length-1]||null}function gc(n,t){var d,f,p;const e=n!=null&&n.stateMap&&typeof n.stateMap=="object"?n.stateMap:{},s=Number(n==null?void 0:n.designCanvasSize)>0?Number(n.designCanvasSize):Uo,r=Number(n==null?void 0:n.designCanvasHeight)>0?Number(n.designCanvasHeight):qo,i=String((d=t!=null?t:n==null?void 0:n.selectedSize)!=null?d:"").trim(),o=Qo(n,"COMPLETE",i),a=String((p=(f=(Array.isArray(o==null?void 0:o.resources)?o.resources:[]).find(m=>(m==null?void 0:m.type)==="MASK"))==null?void 0:f.groupId)!=null?p:""),h=Object.keys(e);let l=a&&h.find(m=>m===`${a}::${i}`)||a&&h.find(m=>m===`${a}::`)||a&&h.find(m=>m===a)||a&&h.find(m=>m.startsWith(`${a}::`))||i&&h.find(m=>m.endsWith(`::${i}`))||h[0];if(!l)return null;const c=e[l];if(!c||typeof c!="object")return null;const u=Number(c.designCanvasSize)>0?Number(c.designCanvasSize):s,g=Number(c.designCanvasHeight)>0?Number(c.designCanvasHeight):r;return{groupId:a||l,name:"complete",state:c,savedCanvasW:u,savedCanvasH:g,resources:[]}}function dc(n,t,e,s,r,i){const o=Math.max(0,Math.min(n,e)),a=Math.max(0,Math.min(t,s)),h=Math.max(0,Math.min(n,e+r)),l=Math.max(0,Math.min(t,s+i)),c=Math.max(0,Math.floor(h-o)),u=Math.max(0,Math.floor(l-a));return{sx:o,sy:a,sw:c,sh:u,dx:Math.round(o-e),dy:Math.round(a-s)}}async function fc(n,t,e,s,r,i,o){var v;const a=Nl(r,i);if(!((v=a==null?void 0:a.slicesByGroupId)!=null&&v.size))return console.warn("[productionRender] COMPLETE: 无 SPLIT slices 配置,无法裁切"),[];const h=Qo(r,"SPLIT",i),l=h&&typeof h.jsonURL=="object"?h.jsonURL:await mr(h==null?void 0:h.jsonURL,o),c=Array.isArray(l==null?void 0:l.layerList)?l.layerList:[],u=Yl(c),{psdW:g,psdH:d}=$l(c,l),f=n.width/Math.max(1,t.width),p=n.height/Math.max(1,t.height);if(console.log(`[productionRender] COMPLETE children=${u.length} slices=${a.slicesByGroupId.size} psd=${g}x${d} canvas=${e}x${s} ext=[${Math.round(t.minL)},${Math.round(t.minT)} ${Math.round(t.width)}x${Math.round(t.height)}] base=${n.width}x${n.height}`,u.map(w=>`${w.id}/${w.name}`)),!u.length)return[];const m=[];for(const w of u){const C=a.slicesByGroupId.get(String(w.id));if(!(C!=null&&C.maskUrl))continue;const x=Wl(w.bounds,g,d,e,s),_=Math.round((x.left-t.minL)*f),b=Math.round((x.top-t.minT)*p),O=Math.max(1,Math.round(x.width*f)),T=Math.max(1,Math.round(x.height*p)),k=document.createElement("canvas");k.width=O,k.height=T;const D=k.getContext("2d");if(!D)continue;D.imageSmoothingEnabled=!0,D.imageSmoothingQuality="high";const A=dc(n.width,n.height,_,b,O,T);A.sw>0&&A.sh>0&&D.drawImage(n,A.sx,A.sy,A.sw,A.sh,A.dx,A.dy,A.sw,A.sh);try{const L=await yr(C.maskUrl,o),I=L.naturalWidth||L.width,j=L.naturalHeight||L.height;D.globalCompositeOperation="destination-in",D.drawImage(L,0,0,I,j,0,0,O,T),D.globalCompositeOperation="source-over"}catch(L){console.warn("[productionRender] COMPLETE mask 加载失败",w.id,w.name,L)}m.push({id:String(w.id),name:w.name,blob:await Pi(k)})}return m}async function Zo(n){var u,g,d,f,p,m,v,w,C;n.fileToken&&Lo(n.fileToken);const t=await mr(n.fabricJson,n.fileToken),e=await mr(n.productJson,n.fileToken),s=(t==null?void 0:t.selectedMode)==="SPLIT"?"SPLIT":"COMPLETE",r=n.fabricDirect===!0,i=n.imageFormat==="jpeg"?"jpeg":"png",o=String((u=n.size)!=null?u:"").trim(),a=!o||/^(default|all|common)$/i.test(o)?String((g=t==null?void 0:t.selectedSize)!=null?g:"").trim():o;let h=[];if(s==="COMPLETE"){const x=gc(t,a);if(!x)throw new Error(`COMPLETE:未解析到尺码「${a||(t==null?void 0:t.selectedSize)||""}」的整稿设计`);console.log(`[productionRender] mode=COMPLETE size=${a} (raw=${o}) baseGid=${x.groupId} base=${x.savedCanvasW}x${x.savedCanvasH} objs=${(p=(f=(d=x.state)==null?void 0:d.objects)==null?void 0:f.length)!=null?p:0} restoreOnly=${r}`);const{canvas:_,W:b,H:O}=await Jo(x,n.fileToken);try{const T=Yo(_),k=await No(_,{useIdentityViewport:!0,transparentBackground:!0});if(!k)throw new Error("COMPLETE:整稿 base 渲染失败");if(r)return k;const D=await createImageBitmap(k);try{h=await fc(D,T,b,O,t,a,n.fileToken)}finally{(m=D.close)==null||m.call(D)}}finally{(v=_.dispose)==null||v.call(_)}}else{const x=ac(t,s,a);if(console.log(`[productionRender] mode=${s} size=${a} (raw=${o}) tasks=${x.length} restoreOnly=${r}`,x.map(_=>{var b,O,T;return`${_.groupId}/${_.name}/${_.savedCanvasW}x${_.savedCanvasH}/objs=${(T=(O=(b=_.state)==null?void 0:b.objects)==null?void 0:O.length)!=null?T:0}/res=${_.resources.length}`})),!x.length)throw new Error(`未解析到尺码「${a||(t==null?void 0:t.selectedSize)||""}」的分片设计(检查 size 与 stateMap 键)`);h=await uc(x,n.fileToken,r)}console.log(`[productionRender] bitmaps=${h.length}`,h.map(x=>`${x.id}/${x.name}/${Math.round(x.blob.size/1024)}KB`));const l=String((C=(w=t==null?void 0:t.typeModel)!=null?w:t==null?void 0:t.specialMode)!=null?C:"").trim()||void 0,c=await cl(h,e,i,l);return console.log(`[productionRender] compose drawn=[${c.drawn.join(",")}] skipped=[${c.skipped.join(",")}] out=${c.canvasWidth}x${c.canvasHeight}`),c.blob}async function ta(n){n.fileToken&&Lo(n.fileToken);const t=await mr(n.fabricJson,n.fileToken),e=t==null?void 0:t.embroidery;if(!e||typeof e.sourceSrc!="string"||!e.sourceSrc)throw new Error("刺绣针迹:fabricJson 缺少 embroidery 数据(typeModel 应为 embroidery)");const s=Math.max(2,Number(e.colorCount)||12),r=Number(e.mergeColorDist)||14,i=Math.max(64,Number(e.maxWorkSize)||800),o=await yr(e.sourceSrc,n.fileToken),a=o.naturalWidth||o.width||1,h=o.naturalHeight||o.height||1,l=Math.min(1,i/Math.max(a,h)),c=Math.max(1,Math.round(a*l)),u=Math.max(1,Math.round(h*l)),g=document.createElement("canvas");g.width=c,g.height=u;const d=g.getContext("2d",{willReadFrequently:!0});if(!d)throw new Error("刺绣针迹:无法创建画布上下文");d.clearRect(0,0,c,u),d.drawImage(o,0,0,a,h,0,0,c,u);const f=d.getImageData(0,0,c,u).data,p=tc(f,c,u,{k:s,mergeColorDist:r});console.log(`[embroideryStitches] quantize w=${c} h=${u} k=${s} regions=${p.regions.length}`);const v=(Array.isArray(e.groups)?e.groups:[]).map(C=>{var x,_,b;return{g:C,lab:fr(((x=C.color)==null?void 0:x[0])|0,((_=C.color)==null?void 0:_[1])|0,((b=C.color)==null?void 0:b[2])|0)}}),w=[];for(const C of p.regions){const x=fr(C.color[0],C.color[1],C.color[2]);let _=null,b=1/0;for(const A of v){const L=(A.lab[0]-x[0])**2+(A.lab[1]-x[1])**2+(A.lab[2]-x[2])**2;L<b&&(b=L,_=A.g)}const O=(_==null?void 0:_.stitch)||"satin",T=Number(_==null?void 0:_.spacing)||oc[O]||5,k=Number.isFinite(Number(_==null?void 0:_.angle))?Number(_==null?void 0:_.angle):45,D=nc({regionIds:p.regionIds,width:c,height:u,targetId:C.id,bbox:C.bbox,stitchType:O,spacing:T,angle:k});D.length&&w.push({color:C.color,stitchType:O,spacing:T,angle:k,stitches:D})}return console.log(`[embroideryStitches] colors=${w.length} totalStitches=${w.reduce((C,x)=>C+x.stitches.length,0)}`),{width:c,height:u,sourceSrc:e.sourceSrc,colorCount:s,mergeColorDist:r,colors:w}}return typeof window!="undefined"&&(window.generateProductionImage=Zo,window.generateEmbroideryStitches=ta,window.__JETPRINT_HEADLESS_VERSION__="1.2.15"),Lt.generateEmbroideryStitches=ta,Lt.generateProductionImage=Zo,Object.defineProperty(Lt,Symbol.toStringTag,{value:"Module"}),Lt})({});