var ni=Object.defineProperty;var ai=(n,e,t)=>e in n?ni(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var d=(n,e,t)=>(ai(n,typeof e!="symbol"?e+"":e,t),t);import{aJ as ut,aM as b,av as y,aO as ve,bz as ri,aI as tt,g9 as oi,cl as li,N as Nt,W as ci,aH as it,aK as Rt,ai as Wt,a_ as Fe,by as pi,a$ as hi,gs as ui,b3 as di,co as fi,dh as ke,f4 as gi,aL as mi,eW as yi,e as P,bA as jt,q as et,ay as wi,aP as _t,F as De,j as ot,gt as be,$ as xi,K as Ee,C as R,bV as Pt,aA as vi,p as M,m as E,f as bi,v as Si,aC as Bt,n as Ct,o as Mt,bR as Le,c7 as Ii,bZ as gt,bY as Se,gu as Ri,bk as Ci,dk as _i,eq as Ie,ad as Q,T as D,gv as Re,s as Pi,f6 as Ht,aN as Mi,bX as Jt,b_ as Gt,u as $e,S as Ti,x as yt,aT as dt,bW as Ai,dX as pt,ae as ji,dY as Bi,dZ as Oi}from"./index-03b6134d.js";import{L as Zt}from"./module-101126a2.js";import{u as re,F as Qt,r as te}from"./index-0a53aaef.js";import"./postmen-9e6354af.js";import{c as Ne}from"./createReactComponent-fcd6848b.js";import{I as ze}from"./IconPlus-99d7bb90.js";import{A as Ue}from"./AssetViewer-1a9f3cad.js";import"./meshopt_simplifier.module-cd99529d.js";import{c as Fi}from"./bundlers-9b0d37fc.js";import{b as Ve,a as qe,c as ki}from"./TextureAsset-7172cc65.js";import"./GlTFAsset-dc68541e.js";import"./MaterialAsset-dfaa82d9.js";import"./MeshAsset-07529e4e.js";import"./AnimatorControllerAsset-616578b4.js";import"./AnimationClipAsset-a5d290cc.js";import"./AmbientLightAsset-6b2d168c.js";import{L as Di}from"./module-5fa1eae0.js";import{s as Ei}from"./SpineSkeletonDataAsset-284f5f4d.js";import"./FontAsset-1e1118c1.js";import"./SceneAsset-a39f097a.js";import"./ShaderAsset-068b4b97.js";import{l as Li}from"./ShaderUIScriptAsset-0c11d0ed.js";import"./PrimitiveMesh-9ff7dbc1.js";import"./XRReferenceImageAsset-823e47cd.js";import"./PrefabAsset-4bac196b.js";import"./PhysicsMaterialAsset-e9abb944.js";import"./RenderTargetAsset-e112b8ca.js";import"./AudioAsset-24b03bc3.js";import"./index-19f5510d.js";import"./MarkdownAsset-2a4a1d10.js";import{F as We}from"./FormItemArray-f1283fce.js";import{F as Kt}from"./index-2274eaf1.js";function $i(n,e){const t={};for(let i=0;i<n.length;i++){const s=n[i],a=e(s);Object.hasOwn(t,a)||(t[a]=[]),t[a].push(s)}return t}function Ni(n,e){const t=[],i=[];for(let s=0;s<n.length;s++){const a=n[s];e(a)?t.push(a):i.push(a)}return[t,i]}function zi(n,e){const t=new Map;for(let i=0;i<n.length;i++){const s=n[i],a=e(s);t.has(a)||t.set(a,s)}return Array.from(t.values())}/**
 * @license @tabler/icons-react v3.24.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Ui=Ne("outline","layout-grid","IconLayoutGrid",[["path",{d:"M4 4m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-0"}],["path",{d:"M14 4m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-1"}],["path",{d:"M4 14m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-2"}],["path",{d:"M14 14m0 1a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z",key:"svg-3"}]]);/**
 * @license @tabler/icons-react v3.24.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Vi=Ne("outline","minus","IconMinus",[["path",{d:"M5 12l14 0",key:"svg-0"}]]);const qi=ut(function(n){const[e,t]=b.useState(null),i=n.asset,{assetStore:s,inspectorFacade:a}=re(),r=(o,l,h)=>{a.assetChange(o,l,h)};return b.useEffect(()=>{s.getAssetByRef(i.texture).then(o=>{t(o)})},[i.texture]),y.jsxs(y.Fragment,{children:[y.jsx(ve.List,{model:i,configs:i.formSchema.items,onModelChange:(o,l)=>r(i.id,o,l)}),e&&y.jsxs(y.Fragment,{children:[y.jsx(ri,{}),y.jsx(tt,{justifyContent:"between",css:{padding:"$2 0"},children:y.jsx(oi,{children:"Texture Option"})}),y.jsx(li,{label:"Name",value:e.name,readOnly:!0}),y.jsx(ve.List,{model:e,configs:e.formSchema.items,onModelChange:(o,l)=>r(e.id,o,l)})]})]})});class ee{static update(e,t){this.entity?this.entity.isActive=!0:this.initScene(e),this.spriteRenderer.sprite=t.engineObject}static clear(){this.entity.isActive=!1}static initScene(e){const t=this.entity=e.createChild("sprite");this.spriteRenderer=t.addComponent(Nt)}}d(ee,"entity"),d(ee,"spriteRenderer");class Wi extends Ue{constructor(){super()}setViewAsset(e,t){const i=t.createChild("sprite_entity"),s=i.addComponent(Nt);s.sprite=e.engineObject,this._entity=i}getDescription(e){var i;const t=(i=e.engineObject)==null?void 0:i.texture;if(t){const{width:s,height:a}=t;return`${s}x${a}`}else return""}}const at=1,Hi=220,Ji=180,Xt=ci._pixelsPerUnit??100,Gi={left:"x",bottom:"y",right:"z",top:"w"},Ki={left:{axis:"x",fromStart:!0},right:{axis:"x",fromStart:!1},top:{axis:"y",fromStart:!0},bottom:{axis:"y",fromStart:!1}},Xi=[["left","right"],["top","bottom"]],Yi={left:"width",right:"width",top:"height",bottom:"height"},Zi={left:"right",right:"left",top:"bottom",bottom:"top"},Qi=it(tt,{width:"220px"}),ts=it("div",{position:"relative",width:"100%",height:"180px",borderRadius:"$2",border:"1px solid $gray6",overflow:"hidden",backgroundImage:"linear-gradient(45deg, rgba(255,255,255,0.06) 25%, transparent 25%), linear-gradient(-45deg, rgba(255,255,255,0.06) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.06) 75%), linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.06) 75%)",backgroundSize:"20px 20px",backgroundPosition:"0 0, 0 10px, 10px -10px, -10px 0px"}),es=it("div",{position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)",border:"1px solid $gray9",background:"linear-gradient(135deg, rgba(76, 132, 255, 0.26) 0%, rgba(76, 132, 255, 0.08) 48%, rgba(76, 132, 255, 0.2) 100%)",boxShadow:"inset 0 0 0 1px rgba(0,0,0,0.2)"}),is=it("canvas",{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",pointerEvents:"none"}),ss=it("div",{position:"absolute",borderRadius:"$1",backgroundColor:"rgba(126, 211, 129, 0.1)",pointerEvents:"none"}),Ce=it("div",{position:"absolute",top:0,bottom:0,width:"10px",marginLeft:"-5px",cursor:"ew-resize","&::before":{content:'""',position:"absolute",left:"50%",top:0,bottom:0,borderLeft:"1px dashed $blue9"}}),_e=it("div",{position:"absolute",left:0,right:0,height:"10px",marginTop:"-5px",cursor:"ns-resize","&::before":{content:'""',position:"absolute",top:"50%",left:0,right:0,borderTop:"1px dashed $blue9"}}),ns={flex:1,minWidth:0};function Z(n,e,t){return Math.min(t,Math.max(e,n))}function ht(n,e=2){const t=Math.pow(10,e);return Math.round(n*t)/t}function mt(n,e=0){return Number.isFinite(n)?n:e}function $t(n,e,t,i){return n=Z(mt(n),0,t),e=Z(mt(e),0,t),n+e>t&&(i?e=t-n:n=t-e),[n,e]}function Lt(n,e){const[t,i]=$t(n.x,n.z,1,e==="x"),[s,a]=$t(n.y,n.w,1,e==="y");return{x:ht(t,2),y:ht(s,2),z:ht(i,2),w:ht(a,2)}}function oe(n,e,t,i){const s=Math.max(at,Math.round(mt(e,at))),a=Math.max(at,Math.round(mt(t,at))),[r,o]=$t(n.left,n.right,s,i==="left"),[l,h]=$t(n.top,n.bottom,a,i==="top");return{left:Math.round(r),bottom:Math.round(h),right:Math.round(o),top:Math.round(l)}}function Pe(n,e,t){const i=Lt(n);return oe({left:i.x*e,bottom:i.y*t,right:i.z*e,top:i.w*t},e,t)}function as(n,e,t){const i=oe(n,e,t),s=Math.max(at,e),a=Math.max(at,t),r=ht(Z(i.left/s,0,1),2),o=ht(Z(i.bottom/a,0,1),2),l=ht(Z(i.right/s,0,1-r),2),h=ht(Z(i.top/a,0,1-o),2);return{x:r,y:o,z:l,w:h}}function rs(n,e,t,i){const a=Math.max(1,mt(t,1)),r=Math.max(1,mt(i,1)),o=Math.max(1,n-16*2),l=Math.max(1,e-16*2),h=Math.min(o,l),p=Math.max(a,r),u=h/p;return{width:Math.max(1,a*u),height:Math.max(1,r*u)}}function os(n,e=!0){const[t,i]=b.useState({width:0,height:0});return b.useLayoutEffect(()=>{if(!e){i({width:0,height:0});return}const s=n.current;if(!s)return;const a=()=>{i({width:s.clientWidth,height:s.clientHeight})};a();const r=new ResizeObserver(a);return r.observe(s),()=>{r.disconnect()}},[n,e]),t}const ls=ut(function(e){var de,fe,ge,me,ye,we;const{model:t,inspectorConfig:i,onModelChange:s}=e,{property:a,disabled:r,label:o,info:l}=i,{t:h}=Rt();if(!t||!a)return null;const p={width:t.engineObject.width*Xt,height:t.engineObject.height*Xt},u=Lt(t[a]??{x:0,y:0,z:0,w:0}),c=Pe(u,p.width,p.height),f=b.useRef(null),g=b.useRef(null),v=b.useRef(null),x=b.useRef(null),w=b.useRef(null),S=b.useRef(null),T=b.useRef(!1),k=b.useRef(!1),A=b.useRef(!1),lt=b.useRef(new Wt),z=b.useRef(new Wt),xt=b.useRef(new Wt),[ct,vt]=b.useState(!1),[nt,X]=b.useState(null),O=os(f,ct),L=b.useMemo(()=>({width:O.width>0?O.width:Hi,height:O.height>0?O.height:Ji}),[O.height,O.width]);A.current=ct;const B=b.useMemo(()=>rs(L.width,L.height,p.width,p.height),[p.height,p.width,L.height,L.width]),$=b.useMemo(()=>({left:Z(c.left/Math.max(p.width,at),0,1),bottom:Z(c.bottom/Math.max(p.height,at),0,1),right:Z(c.right/Math.max(p.width,at),0,1),top:Z(c.top/Math.max(p.height,at),0,1)}),[c.bottom,c.left,c.right,c.top,p.height,p.width]),Y=b.useCallback((m=!1)=>{if(S.current!==null&&(cancelAnimationFrame(S.current),S.current=null),T.current=!1,k.current=!1,!m)return;const I=w.current,C=x.current;if(C){const _=(I==null?void 0:I.canvasCtx)??C.getContext("2d");_==null||_.clearRect(0,0,C.width,C.height)}},[]),Ot=b.useCallback(()=>{Y();const m=w.current;if(m){if(m.renderTarget){const I=m.renderTarget.getColorTexture(0);I==null||I.destroy(!0),m.renderTarget.destroy(!0),m.renderTarget=null}try{t.engine.sceneManager.removeScene(m.scene)}catch{}m.scene.destroy(),w.current=null,Y(!0)}},[t.engine,Y]),ce=b.useCallback(()=>{const m=w.current,I=x.current;if(!m||!I)return!1;const C=window.devicePixelRatio||1,_=Math.round(B.width*C),j=Math.round(B.height*C);if(_<=0||j<=0)return!1;if((I.width!==_||I.height!==j)&&(I.width=_,I.height=j),m.renderTarget&&m.renderTarget.width===_&&m.renderTarget.height===j)return m.camera.aspectRatio=_/j,!0;if(m.renderTarget){const bt=m.renderTarget.getColorTexture(0);bt==null||bt.destroy(!0),m.renderTarget.destroy(!0)}const J=new Fe(t.engine,_,j,void 0,!1),rt=new pi(t.engine,_,j,J,hi.Depth,4),qt=new ImageData(new Uint8ClampedArray(_*j*4),_,j);return m.renderTarget=rt,m.imageData=qt,m.camera.aspectRatio=_/j,m.camera.renderTarget=rt,!0},[B.height,B.width,t.engine]),pe=b.useCallback(()=>{const m=w.current;if(!m||!m.spriteRenderer.sprite)return;const I=m.spriteRenderer.bounds,C=lt.current,_=z.current;I.getCenter(C),I.getExtent(_);const j=m.camera.aspectRatio>0?m.camera.aspectRatio:1,J=Math.max(_.x,p.width*.5,.5),rt=Math.max(_.y,p.height*.5,.5);m.camera.isOrthographic=!0,m.camera.orthographicSize=Math.max(rt,J/j)/Xt,m.camera.nearClipPlane=.1,m.camera.farClipPlane=100,m.cameraEntity.transform.setPosition(C.x,C.y,10),xt.current.set(C.x,C.y,0),m.cameraEntity.transform.lookAt(xt.current)},[p.height,p.width]),he=b.useCallback(()=>{const m=w.current,I=x.current;if(!m||!m.renderTarget||!m.imageData||!I)return;const C=t.engine;if(k.current)return;k.current=!0;try{m.camera.renderTarget=m.renderTarget,C.sceneManager.addScene(m.scene),C.update()}finally{try{C.sceneManager.removeScene(m.scene)}catch{}k.current=!1}m.renderTarget.getColorTexture(0).getPixelBuffer(0,0,m.renderTarget.width,m.renderTarget.height,0,m.imageData.data);const j=m.canvasCtx??I.getContext("2d");j==null||j.putImageData(m.imageData,0,0)},[t.engine]),Ft=b.useCallback(()=>{if(w.current)return;const m=x.current;if(!m)return;const I=new ui(t.engine);I.background.solidColor=new di(0,0,0,0);const C=I.createRootEntity("sprite_border_preview_root"),_=C.createChild("sprite_border_preview_camera"),j=_.addComponent(fi),rt=C.createChild("sprite_border_preview_sprite").addComponent(Nt);rt.sprite=t.engineObject??null,w.current={scene:I,camera:j,cameraEntity:_,spriteRenderer:rt,renderTarget:null,imageData:null,canvasCtx:m.getContext("2d")}},[t.engine,t.engineObject]),ue=b.useCallback(()=>{T.current||(T.current=!0,S.current=requestAnimationFrame(()=>{if(T.current=!1,S.current=null,!A.current)return;w.current||Ft();const m=w.current;m&&(m.spriteRenderer.sprite=t.engineObject??null),ce()&&(pe(),he())}))},[ce,pe,Ft,t.engineObject,he]),kt=b.useCallback((m,I)=>{const C=oe(m,p.width,p.height,I),_=as(C,p.width,p.height);t[a]=_;const j=I?Gi[I]:void 0;s==null||s(a,_,j)},[t,s,a,p.height,p.width]),Ke=b.useCallback((m,I)=>{const C=Lt(m,I);t[a]=C,s==null||s(a,C,I)},[t,s,a]),Xe=b.useCallback((m,I)=>{kt({...c,[m]:mt(I,0)},m)},[c,kt]),Dt=b.useMemo(()=>{const m=I=>C=>{C.preventDefault();const _=g.current,j=document.activeElement;_&&j instanceof HTMLElement&&_.contains(j)&&j.blur(),X(I)};return{left:m("left"),right:m("right"),top:m("top"),bottom:m("bottom")}},[]);b.useEffect(()=>{if(!nt)return;const m=Ki[nt],I=_=>{const j=v.current;if(!j)return;const J=j.getBoundingClientRect();if(J.width<=0||J.height<=0)return;const rt=Lt(t[a]??{x:0,y:0,z:0,w:0}),qt=Pe(rt,p.width,p.height),bt=m.axis==="x"?_.clientX:_.clientY,ti=m.axis==="x"?J.left:J.top,ei=m.axis==="x"?J.right:J.bottom,xe=m.axis==="x"?J.width:J.height,ii=m.axis==="x"?p.width:p.height,si=Z(m.fromStart?(bt-ti)/xe:(ei-bt)/xe,0,1);kt({...qt,[nt]:si*ii},nt)},C=()=>{X(null)};return window.addEventListener("mousemove",I),window.addEventListener("mouseup",C),()=>{window.removeEventListener("mousemove",I),window.removeEventListener("mouseup",C)}},[kt,nt,t,a,p.height,p.width]),b.useEffect(()=>{if(!ct){Ot();return}w.current||Ft();const m=w.current;m&&(m.spriteRenderer.sprite=t.engineObject??null),ue()},[Ot,Ft,ct,ue,B.height,B.width,t.engineObject,t.height,(de=t.pivot)==null?void 0:de.x,(fe=t.pivot)==null?void 0:fe.y,(ge=t.region)==null?void 0:ge.height,(me=t.region)==null?void 0:me.width,(ye=t.region)==null?void 0:ye.x,(we=t.region)==null?void 0:we.y,t.width]),b.useEffect(()=>()=>{Ot()},[Ot]);const Ye=typeof o=="string"?h(o):o,Ze=typeof l=="string"?h(l):l,Qe=b.useMemo(()=>({x:"L",y:"B",z:"R",w:"T"}),[]);return y.jsx(ke,{disabled:r,label:Ye,info:Ze,min:0,max:1,step:.01,dragStep:.01,value:u,slotMapping:Qe,onChange:Ke,formEndSlot:y.jsx(gi,{disabled:r,side:"bottom",align:"start",sideOffset:4,onOpenAutoFocus:m=>m.preventDefault(),onOpenChange:m=>{vt(m),m||X(null)},trigger:y.jsx(mi,{variant:"subtle",corner:!0,disabled:r,children:y.jsx(Ui,{size:14})}),children:y.jsxs(Qi,{ref:g,direction:"column",gap:"sm",children:[y.jsx(ts,{ref:f,children:y.jsxs(es,{ref:v,css:{width:`${B.width}px`,height:`${B.height}px`},children:[y.jsx(is,{ref:x}),y.jsx(ss,{css:{left:`${$.left*100}%`,right:`${$.right*100}%`,top:`${$.top*100}%`,bottom:`${$.bottom*100}%`}}),y.jsx(Ce,{onMouseDown:Dt.left,css:{left:`${$.left*100}%`}}),y.jsx(Ce,{onMouseDown:Dt.right,css:{left:`${(1-$.right)*100}%`}}),y.jsx(_e,{onMouseDown:Dt.top,css:{top:`${$.top*100}%`}}),y.jsx(_e,{onMouseDown:Dt.bottom,css:{top:`${(1-$.bottom)*100}%`}})]})}),y.jsx(tt,{direction:"column",gap:"xs",css:{width:"100%"},children:Xi.map(([m,I])=>y.jsx(tt,{gap:"sm",align:"v",children:[m,I].map(C=>y.jsx(tt,{direction:"column",css:ns,children:y.jsx(yi,{min:0,max:Math.max(0,p[Yi[C]]-c[Zi[C]]),dragStep:1,step:1,value:c[C],startSlot:C[0].toUpperCase(),endSlot:"px",onValueChange:_=>Xe(C,_)})},C))},m))})]})})})});class q{constructor(e=0,t=0,i=0,s=0,a=""){d(this,"x",0);d(this,"y",0);d(this,"width",0);d(this,"height",0);d(this,"name","");d(this,"isRotated",!1);d(this,"allowRotate");this.x=e,this.y=t,this.width=i,this.height=s,this.name=a}clone(){return new q(this.x,this.y,this.width,this.height,`${this.name}-clone`)}isContainedIn(e){return this.x>=e.x&&this.y>=e.y&&this.x+this.width<=e.x+e.width&&this.y+this.height<=e.y+e.height}static isContainedIn(e,t){return e.isContainedIn(t)}}var W=(n=>(n[n.BestShortSideFit=0]="BestShortSideFit",n[n.BestLongSideFit=1]="BestLongSideFit",n[n.BestAreaFit=2]="BestAreaFit",n[n.BottomLeftRule=3]="BottomLeftRule",n[n.ContactPointRule=4]="ContactPointRule",n))(W||{});class cs{constructor(){d(this,"binWidth");d(this,"binHeight");d(this,"allowRotate");d(this,"usedRectangles");d(this,"freeRectangles");this.binWidth=0,this.binHeight=0,this.allowRotate=!1,this.usedRectangles=[],this.freeRectangles=[]}init(e,t,i){this.binWidth=e,this.binHeight=t,this.allowRotate=i||!1,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(new q(0,0,e,t))}insert(e,t,i){let s=new q;const a={value:0},r={value:0},o=i||0,l=this.allowRotate;if(!this._canFit(e,t,l))return s;switch(o){case W.BestShortSideFit:s=this._findPositionForNewNodeBestShortSideFit(e,t,a,r,l);break;case W.BottomLeftRule:s=this._findPositionForNewNodeBottomLeft(e,t,a,r,l);break;case W.ContactPointRule:s=this._findPositionForNewNodeContactPoint(e,t,a,l);break;case W.BestLongSideFit:s=this._findPositionForNewNodeBestLongSideFit(e,t,r,a,l);break;case W.BestAreaFit:s=this._findPositionForNewNodeBestAreaFit(e,t,a,r,l);break}return s.height===0||this._placeRectangle(s),s}insert2(e,t){const i=[],s=t||0;for(;e.length>0;){let a=1/0,r=1/0,o=-1,l=new q,h=-1/0;for(let u=0;u<e.length;u++){const c=e[u],f=this._getAllowRotate(c);if(!this._canFit(c.width,c.height,f))continue;const g={value:0},v={value:0},x=this._scoreRectangle(c.width,c.height,s,g,v,f),w=this._getSortKey(c,s);g.value<a||g.value===a&&v.value<r?(a=g.value,r=v.value,l=x,o=u,h=w):o!==-1&&g.value!==1/0&&v.value!==1/0&&g.value===a&&v.value===r&&w>h&&(l=x,o=u,h=w)}if(o===-1)return i;this._placeRectangle(l);const p=e.splice(o,1)[0];p.x=l.x,p.y=l.y,p.isRotated=l.isRotated,i.push(p)}return i}_placeRectangle(e){let t=this.freeRectangles.length;for(let i=0;i<t;i++)this._splitFreeNode(this.freeRectangles[i],e)&&(this.freeRectangles.splice(i,1),i--,t--);this._purgeFreeList(),this._pruneFreeList(),this.usedRectangles.push(e)}_scoreRectangle(e,t,i,s,a,r){let o=new q;switch(s.value=1/0,a.value=1/0,i){case W.BestShortSideFit:o=this._findPositionForNewNodeBestShortSideFit(e,t,s,a,r);break;case W.BottomLeftRule:o=this._findPositionForNewNodeBottomLeft(e,t,s,a,r);break;case W.ContactPointRule:o=this._findPositionForNewNodeContactPoint(e,t,s,r),s.value=-s.value;break;case W.BestLongSideFit:o=this._findPositionForNewNodeBestLongSideFit(e,t,a,s,r);break;case W.BestAreaFit:o=this._findPositionForNewNodeBestAreaFit(e,t,s,a,r);break}return o.height===0&&(s.value=1/0,a.value=1/0),o}_findPositionForNewNodeBottomLeft(e,t,i,s,a){const r=this.freeRectangles,o=new q;i.value=1/0,s.value=1/0;let l,h;for(let p=0;p<r.length;p++)l=r[p],l.width>=e&&l.height>=t&&(h=l.y+t,(h<i.value||h===i.value&&l.x<s.value)&&(o.x=l.x,o.y=l.y,o.width=e,o.height=t,o.isRotated=!1,i.value=h,s.value=l.x)),a&&l.width>=t&&l.height>=e&&(h=l.y+e,(h<i.value||h===i.value&&l.x<s.value)&&(o.x=l.x,o.y=l.y,o.width=t,o.height=e,o.isRotated=!0,i.value=h,s.value=l.x));return o}_findPositionForNewNodeBestShortSideFit(e,t,i,s,a){const r=this.freeRectangles,o=new q;i.value=1/0;let l,h,p,u,c;for(let f=0;f<r.length;f++)if(l=r[f],l.width>=e&&l.height>=t&&(h=Math.abs(l.width-e),p=Math.abs(l.height-t),u=Math.min(h,p),c=Math.max(h,p),(u<i.value||u===i.value&&c<s.value)&&(o.x=l.x,o.y=l.y,o.width=e,o.height=t,o.isRotated=!1,i.value=u,s.value=c)),a&&l.width>=t&&l.height>=e){const g=Math.abs(l.width-t),v=Math.abs(l.height-e),x=Math.min(g,v),w=Math.max(g,v);(x<i.value||x===i.value&&w<s.value)&&(o.x=l.x,o.y=l.y,o.width=t,o.height=e,o.isRotated=!0,i.value=x,s.value=w)}return o}_findPositionForNewNodeBestLongSideFit(e,t,i,s,a){const r=this.freeRectangles,o=new q;s.value=1/0;let l,h,p,u,c;for(let f=0;f<r.length;f++)l=r[f],l.width>=e&&l.height>=t&&(h=Math.abs(l.width-e),p=Math.abs(l.height-t),u=Math.min(h,p),c=Math.max(h,p),(c<s.value||c===s.value&&u<i.value)&&(o.x=l.x,o.y=l.y,o.width=e,o.height=t,o.isRotated=!1,i.value=u,s.value=c)),a&&l.width>=t&&l.height>=e&&(h=Math.abs(l.width-t),p=Math.abs(l.height-e),u=Math.min(h,p),c=Math.max(h,p),(c<s.value||c===s.value&&u<i.value)&&(o.x=l.x,o.y=l.y,o.width=t,o.height=e,o.isRotated=!0,i.value=u,s.value=c));return o}_findPositionForNewNodeBestAreaFit(e,t,i,s,a){const r=this.freeRectangles,o=new q;i.value=1/0;let l,h,p,u,c;for(let f=0;f<r.length;f++)l=r[f],c=l.width*l.height-e*t,l.width>=e&&l.height>=t&&(h=Math.abs(l.width-e),p=Math.abs(l.height-t),u=Math.min(h,p),(c<i.value||c===i.value&&u<s.value)&&(o.x=l.x,o.y=l.y,o.width=e,o.height=t,o.isRotated=!1,s.value=u,i.value=c)),a&&l.width>=t&&l.height>=e&&(h=Math.abs(l.width-t),p=Math.abs(l.height-e),u=Math.min(h,p),(c<i.value||c===i.value&&u<s.value)&&(o.x=l.x,o.y=l.y,o.width=t,o.height=e,o.isRotated=!0,s.value=u,i.value=c));return o}_commonIntervalLength(e,t,i,s){return t<i||s<e?0:Math.min(t,s)-Math.max(e,i)}_contactPointScoreNode(e,t,i,s){const a=this.usedRectangles;let r=0;(e===0||e+i===this.binWidth)&&(r+=s),(t===0||t+s===this.binHeight)&&(r+=i);let o;for(let l=0;l<a.length;l++)o=a[l],(o.x===e+i||o.x+o.width===e)&&(r+=this._commonIntervalLength(o.y,o.y+o.height,t,t+s)),(o.y===t+s||o.y+o.height===t)&&(r+=this._commonIntervalLength(o.x,o.x+o.width,e,e+i));return r}_findPositionForNewNodeContactPoint(e,t,i,s){const a=this.freeRectangles,r=new q;i.value=-1;let o,l;for(let h=0;h<a.length;h++)o=a[h],o.width>=e&&o.height>=t&&(l=this._contactPointScoreNode(o.x,o.y,e,t),l>i.value&&(r.x=o.x,r.y=o.y,r.width=e,r.height=t,r.isRotated=!1,i.value=l)),s&&o.width>=t&&o.height>=e&&(l=this._contactPointScoreNode(o.x,o.y,t,e),l>i.value&&(r.x=o.x,r.y=o.y,r.width=t,r.height=e,r.isRotated=!0,i.value=l));return r}_splitFreeNode(e,t){const i=this.freeRectangles;if(t.x>=e.x+e.width||t.x+t.width<=e.x||t.y>=e.y+e.height||t.y+t.height<=e.y)return!1;let s;return t.x<e.x+e.width&&t.x+t.width>e.x&&(t.y>e.y&&t.y<e.y+e.height&&(s=e.clone(),s.height=t.y-s.y,s.width>0&&s.height>0&&i.push(s)),t.y+t.height<e.y+e.height&&(s=e.clone(),s.y=t.y+t.height,s.height=e.y+e.height-(t.y+t.height),s.width>0&&s.height>0&&i.push(s))),t.y<e.y+e.height&&t.y+t.height>e.y&&(t.x>e.x&&t.x<e.x+e.width&&(s=e.clone(),s.width=t.x-s.x,s.width>0&&s.height>0&&i.push(s)),t.x+t.width<e.x+e.width&&(s=e.clone(),s.x=t.x+t.width,s.width=e.x+e.width-(t.x+t.width),s.width>0&&s.height>0&&i.push(s))),!0}_pruneFreeList(){const e=this.freeRectangles;let t=0;for(;t<e.length;){let i=t+1;const s=e[t];for(;i<e.length;){const a=e[i];if(q.isContainedIn(s,a)){e.splice(t,1),t--;break}q.isContainedIn(a,s)&&(e.splice(i,1),i--),i++}t++}}_purgeFreeList(){const e=this.freeRectangles;for(let t=e.length-1;t>=0;t--){const i=e[t];(i.width<=0||i.height<=0)&&e.splice(t,1)}}_canFit(e,t,i){return!!(e<=this.binWidth&&t<=this.binHeight||i&&t<=this.binWidth&&e<=this.binHeight)}_getAllowRotate(e){return typeof e.allowRotate=="boolean"?e.allowRotate:this.allowRotate}_getSortKey(e,t){return t===W.BestAreaFit?e.width*e.height:Math.max(e.width,e.height)}}var F=(n=>(n[n.Success=0]="Success",n[n.NoImage=1]="NoImage",n[n.ImageLoadError=2]="ImageLoadError",n[n.OffscreenBlobError=3]="OffscreenBlobError",n[n.CanvasBlobError=4]="CanvasBlobError",n[n.PackError=5]="PackError",n))(F||{});class ps{constructor(){d(this,"mipmap");d(this,"wrapModeV");d(this,"wrapModeU");d(this,"filterMode");d(this,"anisoLevel");d(this,"version",0);d(this,"format",1);d(this,"atlasItems",[])}}class hs{constructor(){d(this,"id");d(this,"name");d(this,"atlasRotated");d(this,"atlasRegion");d(this,"atlasRegionOffset");d(this,"region");d(this,"pivot");d(this,"border");d(this,"pixelsPerUnit");d(this,"width");d(this,"height")}}class zt{}class us extends zt{constructor(){super(...arguments);d(this,"canvas");d(this,"context2D")}async parse(t){const i=t.outPut.info=new ps,s=t.option.padding??0,a=t.bins??[];t.outPut.imageFiles=[];const r=i.atlasItems;for(let o=0,l=a.length;o<l;o++){const h=a[o];this.initCanvas(h.width,h.height);const{context2D:p}=this,{rects:u}=h,c=new Array,f={img:"",type:"",width:h.width,height:h.height,sprites:c};for(let v=0,x=u.length;v<x;v++){const w=new hs,S=u[v];w.name=S.name,w.atlasRotated=S.isRotated,w.atlasRegion={x:S.x,y:S.y,w:S.width,h:S.height};const T=this.getItem(t.images,S.name),k=T==null?void 0:T.image;if(k){const A=S.x,lt=S.y,z=t.option.allowTrim?T.trimRect:void 0,xt=z?z.x:0,ct=z?z.y:0,vt=z?z.w:k.width,nt=z?z.h:k.height;if(z){const B=T.sourceWidth??k.width,$=T.sourceHeight??k.height;w.atlasRegionOffset={x:z.x,y:z.y,z:B-z.x-z.w,w:$-z.y-z.h}}let X,O,L;if(S.isRotated){O=nt,L=vt;let B;try{B=new OffscreenCanvas(O,L)}catch{B=document.createElement("canvas"),B.width=O,B.height=L}const $=B.getContext("2d");$.translate(O,0),$.rotate(Math.PI/2),$.drawImage(k,xt,ct,vt,nt,0,0,vt,nt),X=B}else O=vt,L=nt,X=k;if(S.isRotated?p.drawImage(X,0,0,O,L,A,lt,O,L):p.drawImage(X,xt,ct,O,L,A,lt,O,L),s>0)try{const B=S.isRotated?0:xt,$=S.isRotated?0:ct;for(let Y=1;Y<=s;++Y)p.drawImage(X,B,$,O,1,A,lt-Y,O,1),p.drawImage(X,B,$+L-1,O,1,A,lt+L+Y-1,O,1),p.drawImage(X,B,$,1,L,A-Y,lt,1,L),p.drawImage(X,B+O-1,$,1,L,A+O+Y-1,lt,1,L)}catch(B){console.error(JSON.stringify(B))}}c.push(w)}const g=await this.drawCanvas();if(g)t.outPut.imageFiles.push(g),r.push(f);else return F.CanvasBlobError}return F.Success}getItem(t,i){for(let s=t.length-1;s>=0;s--)if(t[s].name===i)return t[s];return null}initCanvas(t,i){if(this.canvas)this.canvas.width!==t||this.canvas.height!==i?(this.canvas.width=t,this.canvas.height=i):this.context2D.clearRect(0,0,t,i);else{try{this.canvas=new OffscreenCanvas(t,i)}catch{this.canvas=document.createElement("canvas"),this.canvas.width=t,this.canvas.height=i}this.context2D=this.canvas.getContext("2d",{willReadFrequently:!0})}}async drawCanvas(){return new Promise((t,i)=>{this.canvas instanceof HTMLCanvasElement?this.canvas.toBlob(s=>{s.arrayBuffer().then(a=>{t(a)}).catch(a=>{console.error(JSON.stringify(a)),i(new Error("Failed to convert canvas blob to ArrayBuffer"))})},"image/png",1):this.canvas.convertToBlob({type:"image/png",quality:1}).then(s=>{s.arrayBuffer().then(a=>{t(a)}).catch(a=>{console.error(JSON.stringify(a)),i(new Error("Failed to convert offscreen blob to ArrayBuffer"))})}).catch(s=>{console.error(JSON.stringify(s)),i(new Error("Failed to convert offscreen canvas to blob"))})})}}class ds extends zt{parse(e){return new Promise((t,i)=>{const{images:s}=e,{width:a,height:r,allowRotate:o,allowTrim:l}=e.option,h=s.length,p=[];for(let u=0;u<h;u++){const c=s[u];let f;const g=c.src;c.image||(g instanceof ArrayBuffer?f=this._loadImageFromBuffer(c):f=this._loadImageFromURL(c),p.push(f))}Promise.all(p).then(u=>{if(!l)for(let c=0,f=u.length;c<f;c++){const g=u[c];if(!(g.width<=a&&g.height<=r||!!o&&g.height<=a&&g.width<=r)){t(F.PackError);return}}t(F.Success)}).catch(u=>{console.error("OptLoadImage:Error",JSON.stringify(u)),i(F.ImageLoadError)})})}_loadImageFromBuffer(e){return new Promise((t,i)=>{const s=e.src,a=new window.Blob([s],{type:e.type}),r=new Image;r.onerror=function(){i(new Error("Failed to load image buffer"))},r.onload=function(){requestAnimationFrame(()=>{r.onload=null,r.onerror=null,r.onabort=null,e.image=r,t(r)})},r.crossOrigin="anonymous",r.src=URL.createObjectURL(a)})}_loadImageFromURL(e){return new Promise((t,i)=>{const s=new Image;s.onerror=function(){i(new Error("Failed to load image buffer"))},s.onload=function(){requestAnimationFrame(()=>{s.onload=null,s.onerror=null,s.onabort=null,e.image=s,t(s)})},s.crossOrigin="anonymous",s.src=e.src})}}const Et=[2048,1024,512,256,128,64,32,16,8,4,2];class fs extends zt{parse(e){const{option:t,images:i}=e,s=t.padding??0,a=!!t.allowRotate,r=t.method??W.BestLongSideFit;let o,l;if(t.square?o=l=Math.min(t.width,t.height):(o=t.width,l=t.height),t.pot){let c=!1,f=!1;for(let g=0,v=Et.length;g<v;++g){const x=Et[g];if(!c&&o>=x&&(o=x,c=!0),!f&&l>=x&&(l=x,f=!0),c&&f)break}}const h=[],p=s*2;for(let c=i.length-1;c>=0;c--){const f=i[c],g=f.image;if(!g)return F.ImageLoadError;const v=t.allowTrim?f.trimRect:void 0,x=v?v.w:g.width,w=v?v.h:g.height;if(!this.checkSizeLegality(x,w,o,l,p,a))return console.log("打包失败，",f.name,"单图尺寸超图集大小"),F.PackError;h.push(new q(0,0,x+p,w+p,f.name))}const u=[];for(;h.length>0;){const c=new cs;c.init(o,l,a);const f=c.insert2(h,r);if(f.length===0)return F.PackError;let g=0,v=0;for(let x=0;x<f.length;x++){const w=f[x],S=w.isRotated?w.height:w.width,T=w.isRotated?w.width:w.height,k=w.x+S,A=w.y+T;g=Math.max(g,k),v=Math.max(v,A),s>0&&(w.x+=s,w.y+=s,w.width-=p,w.height-=p)}if(t.square&&(g=v=Math.max(g,v)),t.pot){let x=!1,w=!1;for(let S=Et.length-1;S>=0;--S){const T=Et[S];if(!x&&g<=T&&(g=T,x=!0),!w&&v<=T&&(v=T,w=!0),x&&w)break}}u.push({rects:f,width:g,height:v})}return e.bins=u,F.Success}checkSizeLegality(e,t,i,s,a,r){const o=e+a,l=t+a;return r?o<=i&&l<=s||l<=i&&o<=s:o<=i&&l<=s}}const St=class St extends zt{static _getTrimContext(){let{_trimContext:e}=St;if(!e){let t;try{t=new OffscreenCanvas(1,1)}catch{t=document.createElement("canvas")}const i=t.getContext("2d",{willReadFrequently:!0});e={canvas:t,ctx:i},St._trimContext=e}return e}parse(e){if(!e.option.allowTrim)return F.Success;const{images:t}=e,{canvas:i,ctx:s}=St._getTrimContext();for(let a=0,r=t.length;a<r;a++){const o=t[a],l=o.image;if(!l)continue;const{width:h,height:p}=l;o.sourceWidth=h,o.sourceHeight=p,i.width=h,i.height=p,s.drawImage(l,0,0);const u=s.getImageData(0,0,h,p).data,c=this._getTrimRect(u,h,p);(c.w<h||c.h<p)&&(o.trimRect=c)}return F.Success}_getTrimRect(e,t,i){let s=t,a=0,r=i,o=0;for(let l=0;l<i;l++){const h=l*t*4;for(let p=0;p<t;p++)e[h+p*4+3]>0&&(p<s&&(s=p),p>a&&(a=p),l<r&&(r=l),l>o&&(o=l))}return a<s||o<r?{x:0,y:0,w:1,h:1}:{x:s,y:r,w:a-s+1,h:o-r+1}}};d(St,"_trimContext",null);let ie=St;const Me=[new ds,new ie,new fs,new us],Yt={width:1024,height:1024,padding:1,allowRotate:!1,square:!1,pot:!1,method:W.BestLongSideFit};async function le(n,e){if(n.length===0)return{code:F.NoImage,msg:Te(F.NoImage)};if(e===void 0)e=Yt;else{const a=Object.keys(Yt);for(let r=a.length-1;r>=0;r--){const o=a[r];e[o]===void 0&&(e[o]=Yt[o])}}const t={};n.sort((a,r)=>r.name.toLowerCase().localeCompare(a.name.toLowerCase()));const i={option:e,images:n,outPut:t};let s=F.Success;for(let a=0;a<Me.length;a++){const r=await Me[a].parse(i);if(r!==F.Success){s=r;break}}return t.code=s,t.msg=Te(s),t}function Te(n){switch(n){case F.Success:return"打包成功！";case F.NoImage:return"传入图片长度为0.";case F.ImageLoadError:return"图片加载失败.";case F.CanvasBlobError:return"画布 blob 转换失败.";case F.OffscreenBlobError:return"离线画布 blob 转换失败.";case F.PackError:return"图集尺寸限制，打包失败。"}}async function It(n,e){await n.root.assetFacade.updateAssetProps(n.id,e)}async function gs(n,e){const t=await Promise.all(n.sprites.map(o=>e.getFileById(o.refId)).map(async o=>({...o,mainData:JSON.parse(await o.content.text())}))),[i,s]=Ni(t,o=>!!o.mainData.texture),a=$i(i,o=>o.mainData.texture.refId);return{packItems:await Promise.all(i.filter(o=>{var h;const l=(h=o.mainData.texture)==null?void 0:h.refId;return l?!!e.getFileById(l):!1}).map(async o=>{const l=o.mainData.texture.refId,p=await(await e.loadFile(l)).arrayBuffer();return{name:l,src:p}})),spriteAssetMap:a,spritesEmpty:s}}async function ms(n){const e=n.root.assetStore,t=await Promise.all(n.sprites.map(a=>e.getAssetByRef(a))),s=(await Promise.all(t.filter(a=>a&&a.texture).map(a=>e.getAssetByRef(a.texture)))).filter(a=>a).map(a=>({name:a.id,src:a.imageBuffer}));return await le(s,{padding:n.padding,width:n.maxWidth,height:n.maxHeight})}async function ys(n,e){let t,i=[];const{spriteAssetMap:s,packItems:a,spritesEmpty:r}=await gs(n,e);if(a.length>0?(t=await le(a,{padding:n.padding,width:n.maxWidth,height:n.maxHeight}),t.code===0?(i=t.info.atlasItems??[],i.forEach(o=>{const{sprites:l}=o;o.sprites=l.flatMap(h=>{const p=s[h.name],{atlasRegion:u,originalSize:c,atlasRotated:f}=h;return p.map(g=>Ae(g,u,c,f))})})):i=[],t.info.atlasItems=i):(t={code:1,msg:P("sprite.atlas.pack-error.no-sprite")},i=[]),r.length>0){const o=r.map(l=>Ae(l));i.push({img:"",sprites:o})}return t.info&&(t.info.atlasItems=i),t}function Ae(n,e,t=0,i=!1){const s=n.mainData,a=s.region,r=s.pivot,o=s.border,l={name:n.path,atlasRegion:e?{x:e.x,y:e.y,w:e.w,h:e.h}:{x:0,y:0,w:1,h:1},originalSize:t,atlasRotated:i,pivot:{x:r.x,y:r.y},region:{x:a.x,y:a.y,w:a.width,h:a.height},border:{x:o.x,y:o.y,z:o.z,w:o.w},width:s.width,height:s.height};return isNaN(s.width)||(l.width=s.width),isNaN(s.height)||(l.height=s.height),l}function ws(n){const e=[],t=i=>{const s=i.children,a=Object.keys(s);for(let r=a.length-1;r>=0;r--){const o=s[a[r]];o instanceof U?e.push(o):o instanceof Qt&&t(o)}};return t(n),e}function Ut(n,e){const t=e.id,i=n.sprites;for(let s=i.length-1;s>=0;s--)if(i[s].refId===t)return s;return-1}function je(n,e,t,i,s="#212324",a=15){var x;const{width:r,height:o}=t,{width:l,height:h}=e;let p,u,c,f;i.clearRect(0,0,t.width,t.height),i.fillStyle=s,r/o>l/h?(u=o,p=o/h*l,c=(r-p)/2,f=0,i.fillRect(0,0,c,o),i.fillRect(c+p,0,c,o)):(p=r,u=r/l*h,c=0,f=(o-u)/2,i.fillRect(0,0,r,f),i.fillRect(0,f+u,r,f)),i.drawImage(e,0,0,e.width,e.height,c,f,p,u);const g="Size: "+l+"x"+h+"   Usage: "+n+"%";i.font=a+"px Arial";const v=((x=i.measureText(g))==null?void 0:x.width)||a*g.length;i.fillStyle="#000000",i.fillText(g,(r-v)/2,o-a*1/3-2),i.fillStyle="#ffffff",i.fillText(g,(r-v)/2,o-a/2-2)}function xs(n){return n.sprites.length>0}async function Be(n,e){await It(n,{texture:e?e.getCurrentRef():null})}async function Tt(n,e){const{belongToAtlas:t}=e,i=t==null?void 0:t.refId;if(i&&i!==n.id){const s=await n.root.assetStore.getAssetByRef(t);if(s){const a=s.sprites.filter(r=>r.refId!==e.id);a.length!==s.sprites.length&&await It(s,{sprites:a})}}if(i!==n.id&&await It(e,{belongToAtlas:n.getCurrentRef()}),Ut(n,e)<0){const s=[...n.sprites,e.getCurrentRef()];await It(n,{sprites:s})}}async function se(n,e){var i;((i=e.belongToAtlas)==null?void 0:i.refId)===n.id&&await It(e,{belongToAtlas:null});const t=Ut(n,e);if(t>=0){const s=n.sprites.filter((a,r)=>r!==t);await It(n,{sprites:s})}}const vs=ut(({asset:n,sprite:e})=>{const{assetStore:t}=n.root,i=Object.values(t.assets).filter(s=>s.getMetaConfig().type==="SpriteAtlas");return y.jsx(jt,{direction:"column",dropLayer:et.Sprite,assets:i,onSelect:async s=>{await se(n,e),await Tt(s,e)},onDelete:()=>{se(n,e)},onLocate:()=>{n&&n.id&&t.selectAsset(n.id)},asset:n,value:n.name})}),bs=ut(({model:n})=>{const{t:e}=Rt(),{assetStore:t}=n.root;Ss(n);const i=n.belongToAtlas?t.getAsset(n.belongToAtlas.refId):null,s=Object.values(t.assets).filter(a=>a.getMetaConfig().type==="SpriteAtlas");return y.jsxs(tt,{fullWidth:!0,css:{padding:"0 $0_5 $1"},children:[y.jsx(wi,{size:"1",css:{marginTop:"$1"},children:e("sprite.atlas.belong-to")}),n.belongToAtlas?y.jsx(vs,{asset:i,sprite:n},i.id):y.jsx(jt,{dropLayer:et.Sprite,assets:s,onSelect:a=>{Tt(a,n)},trigger:y.jsx(tt,{align:"h",css:{padding:"$1 $2 $1"},children:y.jsx(_t,{size:"sm",variant:"solid",css:{padding:"$1 $6"},children:e("sprite.atlas.belong-to")})}),label:"",value:null,asset:null})]})});async function Ss(n){const e=n.root.assetStore,t=n.belongToAtlas,i=t?await e.getAssetByRef(t):null;if(i){Ut(i,n)<0&&await n.root.assetFacade.updateAssetProps(i.id,{sprites:[...i.sprites,n.getCurrentRef()]});return}t&&await n.root.assetFacade.updateAssetProps(n.id,{belongToAtlas:null})}var Is=Object.defineProperty,Rs=Object.getOwnPropertyDescriptor,st=(n,e,t,i)=>{for(var s=i>1?void 0:i?Rs(e,t):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Is(e,t,s),s};const H=new De;function He(n){return n.quickPivot===9}function Oe(n){switch(n){case 0:H.set(.5,.5);break;case 1:H.set(0,1);break;case 2:H.set(.5,1);break;case 3:H.set(1,1);break;case 4:H.set(0,.5);break;case 5:H.set(1,.5);break;case 6:H.set(0,0);break;case 7:{H.set(.5,0);break}case 8:{H.set(1,0);break}}}let U=class extends ot{constructor(e){super(e);d(this,"_delOnTexDel");d(this,"_customWidth");d(this,"_customHeight");d(this,"acceptDragLayer",et.Texture);d(this,"texture",null);d(this,"width");d(this,"height");d(this,"region",{x:0,y:0,width:1,height:1});d(this,"quickPivot",0);d(this,"pivot",{x:.5,y:.5});d(this,"border",{x:0,y:0,z:0,w:0});d(this,"belongToAtlas",null)}async afterDelete(){this.engineObject.destroy(!0);const{belongToAtlas:e}=this;if(e){const t=await this.root.assetStore.getAssetByRef(e);if(t){const i=Ut(t,this);i>-1&&t.sprites.splice(i,1),this.belongToAtlas=null,await this.root.assetFacade.persistAssetMain(t.id)}}this._delOnTexDel&&(this._delOnTexDel(),this._delOnTexDel=null)}getMainData(){const e=this[be]??{},t={};return Object.keys(e).forEach(i=>{switch(i){case"width":isNaN(this._customWidth)||(t.width=this._customWidth);break;case"height":isNaN(this._customHeight)||(t.height=this._customHeight);break;default:t[i]=this[i];break}}),JSON.stringify(t)}async initByMain(e){const t=new xi(this.engine),i=JSON.parse(await e.text());if(isNaN(i.width)||(t.width=this._customWidth=i.width),isNaN(i.height)||(t.height=this._customHeight=i.height),i.texture){const a=await this.root.assetStore.getAssetByRef(i.texture);a&&(await a.ensureReady(),t.texture=a.engineObject)}for(const a in i)this[a]=i[a];this.bindEngineObject(t);const s=new Ee(this.engine);s.addComponent(Nt).sprite=t,this.setDragTempEntity(s),await this.applyBoundPathChange("name",R.Input,this.name)}async initByCreation(){const{assetStore:e,assetUIStore:t}=this.root,{pickedAssets:i}=t,s=JSON.parse(this.getMainData());if(i&&i.length===1){const a={refId:i[0]},r=await e.getAssetByRef(a);r instanceof Ve?(r.setTextureType(qe.Sprite),s.texture=a):r instanceof U&&r.texture&&(s.texture={refId:r.texture.refId})}return s}instantiate(){const e=this.root.sceneStore.createEntity(),t=this.getDragTempEntity(),{position:i,rotation:s}=t.transform,a={components:[{class:"SpriteRenderer",id:Pt(),props:{drawMode:0,enabled:!0,flipX:!1,flipY:!1,maskInteraction:0,maskLayer:vi.Everything,sprite:this.getCurrentRef()}}],id:e.id,isActive:!0,isClone:!1,name:this.name?"sprite-"+this.name:"sprite",transform:{class:"Transform",props:{position:{x:i.x,y:i.y,z:i.z},rotation:{x:s.x,y:s.y,z:s.z},scale:{x:1,y:1,z:1}}}};return e.initByFile(a),e}initByEngineObject(e){const t=Object.keys(this[be]),i=["texture","quickPivot","belongToAtlas"],s=a=>!i.includes(a);t.filter(s).forEach(a=>{const r=e[a];typeof r=="object"?Object.keys(r).forEach(l=>{this[a][l]=r[l]}):this[a]=r}),this.bindEngineObject(e)}async _onDrop(e,t){const i="texture";this.dropping=!1,this.texture=t.getCurrentRef(),this.formSchema.getPropertyConfig(i).onChange(this,i,t),this.updateThumbnail()}};st([M({info:"sprite.texture.info",label:"sprite.texture.label",type:R.AssetPicker,assetType:"Texture",customFilter:n=>n.isSubAsset===!1,onChange:async(n,e,t)=>{const i=n.engineObject;if(n._delOnTexDel&&(n._delOnTexDel(),n._delOnTexDel=null),await n.applyBoundPathChange("texture",R.AssetPicker,t==null?void 0:t.getCurrentRef()),t){const s=()=>{var a;(a=n._delOnTexDel)==null||a.call(n),n._delOnTexDel=null,n.texture=null,n.applyBoundPathChange("texture",R.AssetPicker,void 0),n.updateThumbnail()};t.on("delete",s),n._delOnTexDel=()=>{t.off("delete",s)}}isNaN(n._customWidth)?n.width=i.width:(n.width=n._customWidth,await n.applyBoundPathChange("width",R.Number,n._customWidth)),isNaN(n._customHeight)?n.height=i.height:(n.height=n._customHeight,await n.applyBoundPathChange("height",R.Number,n._customHeight))}}),E()],U.prototype,"texture",2);st([M({label:"sprite.width.label",info:"sprite.width.info",type:R.Number,triggerAfterInit:!1,async onChange(n,e,t){isNaN(t)||(n._customWidth=t,await n.applyBoundPathChange("width",R.Number,t))}}),E()],U.prototype,"width",2);st([M({label:"sprite.height.label",info:"sprite.height.info",type:R.Number,triggerAfterInit:!1,async onChange(n,e,t){isNaN(t)||(n._customHeight=t,await n.applyBoundPathChange("height",R.Number,t))}}),E()],U.prototype,"height",2);st([M({info:"sprite.region.info",label:"sprite.region.label",type:R.Rect,min:0,max:1,dragStep:.01,onChange(n,e,t){n.applyBoundPathChange("region",R.Rect,t)}}),E()],U.prototype,"region",2);st([bi({setPath:"pivot",getActualEditorValue:n=>(Oe(n),new De().copyFrom(H)),getEditorValue:n=>{const{x:e,y:t}=n;return e===.5&&t===.5?0:e===0&&t===1?1:e===.5&&t===1?2:e===1&&t===1?3:e===0&&t===.5?4:e===1&&t===.5?5:e===0&&t===0?6:e===.5&&t===0?7:e===1&&t===0?8:9}}),M({info:"sprite.quick-pivot.info",label:"sprite.quick-pivot.label",type:R.Select,value:0,options:[{label:"sprite.quick-pivot.center",value:0},{label:"sprite.quick-pivot.top-left",value:1},{label:"sprite.quick-pivot.top",value:2},{label:"sprite.quick-pivot.top-right",value:3},{label:"sprite.quick-pivot.left",value:4},{label:"sprite.quick-pivot.right",value:5},{label:"sprite.quick-pivot.bottom-left",value:6},{label:"sprite.quick-pivot.bottom",value:7},{label:"sprite.quick-pivot.bottom-right",value:8},{label:"sprite.quick-pivot.custom",value:9}],onChange(n,e,t){He(n)?H.copyFrom(n.pivot):Oe(t),n.pivot.x=H.x,n.pivot.y=H.y,n.applyBoundPathChange("pivot",R.Vector2,H)}}),E()],U.prototype,"quickPivot",2);st([M({info:"sprite.pivot.info",label:"sprite.pivot.label",type:R.Vector2,onChange(n,e,t){n.quickPivot===9&&n.applyBoundPathChange("pivot",R.Vector2,t)},when:He}),E()],U.prototype,"pivot",2);st([M({info:"sprite.border.info",label:"sprite.border.label",customComponent:ls,slotMapping:{x:"Left",y:"Down",z:"Right",w:"Up"},onChange(n,e,t){n.applyBoundPathChange("border",R.Vector4,t)}}),E()],U.prototype,"border",2);st([M({info:P("sprite.belong.info"),label:P("sprite.belong.label"),customComponent:bs}),E()],U.prototype,"belongToAtlas",2);st([Si()],U.prototype,"getMainData",1);st([Bt],U.prototype,"_onDrop",1);U=st([Ct({type:"sprite",label:P("asset.sprite.title"),loaderType:"Sprite",extname:"sprite",importMenuConfig:{type:Mt.Upload|Mt.Add,tooltip:"支持多选",accept:".png,.jpg,.jpeg,.webp",multiple:!0},viewer:Wi,thumbnail:ee,defaultName:"Sprite",dragLayer:et.Sprite,dragType:"2d",preUpload:async(n,e,t,i)=>{const s=Le(n.main,"sprite.png"),a=s.name;if(i)if(i.meta.type==="Texture"){await Ii.assets.update(i.serverId,{file:s});return}else throw`Can't overwrite type: ${i.meta.type}, name: ${a}`;const r=await t.root.assetFacade.createAssetByUpload({uploadAssetFile:{...n,main:s},assetType:"Texture"});return r.setTextureType(qe.Sprite),new File([JSON.stringify({texture:r.getCurrentRef()})],gt(a,Se(a))+"-spr"+Se(a))},customInspector:qi,async bundle({id:n,content:e,path:t},i,s){const a=s.vfs;return{content:new Blob([await Fi(n,await e.text(),t,async r=>{const o=a.getFileById(r);if(!o)return null;const l=o.content??await a.loadFile(o.id);return l?l.text():null})])}}})],U);const Ln=Object.freeze(Object.defineProperty({__proto__:null,get SpriteAsset(){return U}},Symbol.toStringTag,{value:"Module"})),Cs=it("div",{position:"relative",width:"100%",marginBottom:"$2",aspectRatio:"1/1"}),_s=it("div",{position:"absolute",width:"100%",height:"100%",padding:"$1",boxSizing:"border-box","& canvas":{width:"100%",height:"100%",border:"1px solid $grayA4",borderRadius:"$3",overflow:"hidden"}}),Ps=b.forwardRef(function(e,t){const{buttonContent:i,onClick:s}=e;return y.jsxs(tt,{direction:"column",fullWidth:!0,children:[y.jsx(Cs,{children:y.jsx(_s,{children:y.jsx("canvas",{ref:t,width:"400",height:"400"})})}),i&&y.jsx(tt,{align:"h",css:{margin:"$0 auto"},children:y.jsx(_t,{size:"sm",variant:"solid",css:{padding:"0 $14"},onClick:s,children:i})})]})});function Ms(n,e){return new Promise((t,i)=>{const s=new window.Blob([n],{type:e}),a=new window.Image,r=URL.createObjectURL(s);let o=!1;const l=()=>{o||(o=!0,URL.revokeObjectURL(r))};a.crossOrigin="anonymous",a.onerror=()=>{l(),i(new Error("Failed to load image buffer"))},a.onload=()=>{requestAnimationFrame(()=>{l(),t(a)})},a.src=r})}const Ts=ut(({item:n})=>{const[e,t]=b.useState(null),{assetStore:i}=n.root,{t:s}=Rt(),a=Object.values(i.assets).filter(r=>!r.isSubAsset&&r.getMetaConfig().type==="Texture");return b.useEffect(()=>{let r=!1;return n.texture?i.getAssetByRef(n.texture).then(o=>{r||t(o)}):t(null),()=>{r=!0}},[n.texture]),y.jsxs(y.Fragment,{children:[y.jsx(jt,{dropLayer:et.Sprite,assets:a,onSelect:r=>{Be(n,r)},onDelete:()=>{Be(n,null)},onLocate:()=>{var r;(r=n.texture)!=null&&r.refId&&i.selectAsset(n.texture.refId)},label:s("sprite.texture.label"),value:e&&e.name,asset:e}),y.jsx(Ri,{label:s("sprite.region.label"),value:{x:n.region.x,y:n.region.y,width:n.region.width,height:n.region.height},onChange:(r,o)=>{n.root.inspectorFacade.assetChange(n.id,"region",{...n.region,[o]:r[o]})},min:0,max:1}),y.jsx(Ci,{label:s("sprite.quick-pivot.label"),value:n.quickPivot,options:[{label:s("sprite.quick-pivot.center"),value:0},{label:s("sprite.quick-pivot.top-left"),value:1},{label:s("sprite.quick-pivot.top"),value:2},{label:s("sprite.quick-pivot.top-right"),value:3},{label:s("sprite.quick-pivot.left"),value:4},{label:s("sprite.quick-pivot.right"),value:5},{label:s("sprite.quick-pivot.bottom-left"),value:6},{label:s("sprite.quick-pivot.bottom"),value:7},{label:s("sprite.quick-pivot.bottom-right"),value:8},{label:s("sprite.quick-pivot.custom"),value:9}],onChange:r=>{n.root.inspectorFacade.assetChange(n.id,"quickPivot",r)}}),n.quickPivot===9&&y.jsx(_i,{label:"",value:{x:0,y:0}}),y.jsx(ke,{label:s("sprite.border.label"),value:{x:n.border.x,y:n.border.y,z:n.border.z,w:n.border.w},onChange:(r,o)=>{n.root.inspectorFacade.assetChange(n.id,"border",{...n.border,[o]:r[o]})},min:0,max:1})]})}),As=ut(({model:n,inspectorConfig:e})=>{const{label:t}=e,i=n.sprites,{assetStore:s}=n.root,a=xs(n),{t:r}=Rt();js(n);const o=Object.values(s.assets).filter(c=>{switch(c.getMetaConfig().type){case"sprite":return!i.find(g=>g.refId===c.id);case"Folder":return!0}return!1}),l=b.useRef(null);let h,p;b.useLayoutEffect(()=>{h=l.current,p=h==null?void 0:h.getContext("2d"),n.previewImage&&p&&je(n.usage,n.previewImage,h,p)});async function u(){var c;if(a){if(p){const f=await ms(n),g=((c=f.info)==null?void 0:c.atlasItems)??[],v=g.reduce((S,T)=>S+T.sprites.reduce((k,A)=>k+A.width*A.height,0),0),x=g.reduce((S,T)=>S+T.width*T.height,0),w=x>0?Number((v/x*100).toFixed(2)):0;f.code===0?Ms(f.imageFiles[0],"image/png").then(S=>{n.replacePreview(S),je(w,S,h,p)}):Ie({title:r("sprite.atlas.pack-error.title"),description:f.msg})}}else Ie({title:r("sprite.atlas.pack-error.title"),description:r("sprite.atlas.pack-error.no-sprite")})}return y.jsxs(y.Fragment,{children:[y.jsx(We,{label:t,items:i.map((c,f)=>{const g=s.getAsset(c.refId);return{removable:!0,children:y.jsx(Ts,{item:g}),id:`${f}`,name:g.getRouteString()}}),onDelete:async c=>{const f=await s.getAssetByRef(i[c.id]);await se(n,f)}}),y.jsxs(tt,{align:"both",direction:"column",children:[y.jsx(jt,{assets:o,dropLayer:et.Sprite|et.Folder,customFilter:c=>c instanceof U||c instanceof Qt,onSelect:c=>{if(c instanceof U)Tt(n,c);else if(c instanceof Qt){const f=ws(c);for(let g=f.length-1;g>=0;g--)Tt(n,f[g])}},trigger:y.jsx(_t,{size:"sm",variant:"solid",css:{flex:1},startSlot:y.jsx(ze,{}),children:r("sprite.atlas.add-object.label")}),label:r("sprite.atlas.add-sprite"),value:null,asset:null}),y.jsx(_t,{size:"sm",variant:"solid",positive:!0,fullWidth:!0,css:{margin:"$1"},onClick:u,children:r("sprite.atlas.pack-preview.label")})]}),a&&y.jsx(Ps,{ref:l})]})});async function js(n){var s;const e=n.root.assetStore.assets,t=n.sprites,i=[];for(let a=0;a<t.length;a++){const r=t[a],o=e[r.refId];o&&(i.push(r),((s=o.belongToAtlas)==null?void 0:s.refId)!==n.id&&await Tt(n,o))}i.length!==t.length&&await n.root.assetFacade.updateAssetProps(n.id,{sprites:i})}var Bs=Object.defineProperty,Os=Object.getOwnPropertyDescriptor,G=(n,e,t,i)=>{for(var s=i>1?void 0:i?Os(e,t):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Bs(e,t,s),s};let N=class extends ot{constructor(e){super(e);d(this,"acceptDragLayer",et.Sprite);d(this,"previewTexture2D");d(this,"previewImage");d(this,"usage",0);d(this,"maxWidth",1024);d(this,"maxHeight",1024);d(this,"padding",2);d(this,"allowRotation",!1);d(this,"tightPacking",!1);d(this,"mipmap",!1);d(this,"filterMode",Q.Bilinear);d(this,"wrapModeU",D.Repeat);d(this,"wrapModeV",D.Repeat);d(this,"anisoLevel",1);d(this,"sprites",[]);this.setNameByIncrease("SpriteAtlas");const t=this.formSchema;t.addGroup(P("sprite.atlas.packing"),["maxWidth","maxHeight","padding","allowRotation","tightPacking"]),t.addGroup(P("sprite.atlas.export"),["filterMode","wrapModeU","wrapModeV","anisoLevel","mipmap"]),t.addGroup(P("sprite.atlas.list"),["sprites"])}static async updateSubTextureAssets(e,t,i,s,a){var f;const r=e.meta,o=a.vfs,l=e.dependencies||(e.dependencies=[]),h=((f=l[t])==null?void 0:f.ref.refId)??Pt(),p=gt(e.name).split(".")[0];l[t]||(l[t]={key:"atlasItems["+t+"].img",ref:{refId:h}});let u=o.getFileById(h),c;return u?c=u.meta:(c={id:h,type:ot.getRegisteredAssetMeta(Ve).type,version:te.projectStore.engineVersion,extraData:{},dependencies:[]},a.addFile({name:p+"_image_"+t,assetId:h,url:null,parentId:e.parentId,main:null,meta:c}),u=o.getFileById(h),u.ignoreBundle=!0),c.colorDilate=r.colorDilate??!1,c.filterMode=r.filterMode??Q.Bilinear,c.wrapModeU=r.wrapModeU??D.Repeat,c.wrapModeV=r.wrapModeV??D.Repeat,c.anisoLevel=r.anisoLevel??1,c.runtimeOptions=r.runtimeOptions??{},a.updateFile(h,{main:new Blob([i],{type:"image/png"}),meta:c}),await a.bundleSingleFile(u,s),u}replacePreview(e){this.previewImage=e;const t=this.previewTexture2D;this.previewTexture2D=new Fe(this.engineObject.engine,e.width,e.height),this.previewTexture2D.setImageSource(e),t&&t.destroy(!0)}async afterDelete(){this.engineObject.destroy(!0);const{sprites:e,id:t}=this,i=this.root.assetStore,a=[...e].map(async r=>{var o;try{const h=await i.getAssetByRef(r);((o=h==null?void 0:h.belongToAtlas)==null?void 0:o.refId)===t&&await this.root.assetFacade.updateAssetProps(h.id,{belongToAtlas:null})}catch(l){console.warn(`[SpriteAtlasAsset] Failed to cleanup sprite relation: ${(r==null?void 0:r.refId)??"unknown"}`,l)}});await Promise.allSettled(a),e.length=0}addSprites(e){const t=zi([...this.sprites,...e.map(s=>({refId:s.id}))],s=>s.refId),i=e.map(s=>this.root.assetFacade.updateAssetProps(s.id,{belongToAtlas:{refId:this.id}}));return i.push(this.root.assetFacade.updateAssetProps(this.id,{sprites:t})),Promise.all(i)}async initByMain(e){const{engine:t}=this,i=JSON.parse(await e.text());for(const a in i)this[a]=i[a];const s=new Re(t);this.bindEngineObject(s),s.asset=this}async initByCreation(){this.setNameByIncrease("SpriteAtlas");const e=new Re(this.engine);return this.bindEngineObject(e),e.asset=this,this.getMainData()}async _onDrop(e,t){this.dropping=!1,!this.sprites.find(i=>i.refId===t.id)&&await this.addSprites([t])}};G([M({info:"sprite.atlas.max-width.info",label:"sprite.atlas.max-width.label",type:R.Input}),E()],N.prototype,"maxWidth",2);G([M({info:"sprite.atlas.max-height.info",label:"sprite.atlas.max-height.label",type:R.Input}),E()],N.prototype,"maxHeight",2);G([M({info:"sprite.atlas.padding.info",label:"sprite.atlas.padding.label",type:R.Number,min:0,max:5,dragStep:1}),E()],N.prototype,"padding",2);G([M({info:"sprite.atlas.rotation.info",label:"sprite.atlas.rotation.label",type:R.Toggle}),E()],N.prototype,"allowRotation",2);G([M({info:"sprite.atlas.tight-packing.info",label:"sprite.atlas.tight-packing.label",type:R.Toggle}),E()],N.prototype,"tightPacking",2);G([M({label:"sprite.atlas.mipmap.label",type:R.Toggle}),E()],N.prototype,"mipmap",2);G([M({label:"sprite.atlas.filter-mode.label",type:R.Select,value:Q.Bilinear,options:[{label:"sprite.atlas.filter-mode.point",value:Q.Point},{label:"sprite.atlas.filter-mode.bilinear",value:Q.Bilinear},{label:"sprite.atlas.filter-mode.trilinear",value:Q.Trilinear}]}),E()],N.prototype,"filterMode",2);G([M({label:"sprite.atlas.wrap-mode-u.label",type:R.Select,options:[{label:"sprite.atlas.wrap-mode.clamp",value:D.Clamp},{label:"sprite.atlas.wrap-mode.repeat",value:D.Repeat},{label:"sprite.atlas.wrap-mode.mirror",value:D.Mirror}]}),E()],N.prototype,"wrapModeU",2);G([M({label:"sprite.atlas.wrap-mode-v.label",type:R.Select,options:[{label:"sprite.atlas.wrap-mode.clamp",value:D.Clamp},{label:"sprite.atlas.wrap-mode.repeat",value:D.Repeat},{label:"sprite.atlas.wrap-mode.mirror",value:D.Mirror}]}),E()],N.prototype,"wrapModeV",2);G([M({label:"sprite.atlas.aniso-level.label",type:R.Slider,dragStep:1,max:16,min:1}),E()],N.prototype,"anisoLevel",2);G([Pi({key:"addSprite"}),M({label:P("sprite.atlas.sprite-list.label"),customComponent:As}),E()],N.prototype,"sprites",2);G([Bt],N.prototype,"addSprites",1);N=G([Ct({type:"SpriteAtlas",label:P("asset.sprite-atlas.title"),loaderType:"SpriteAtlas",extname:"atlas",importMenuConfig:{type:Mt.Add},async bundle(n,e,t){var l;const i=t.vfs,s=n.content??await i.loadFile(n.id),a=JSON.parse(await s.text()),r=n.meta,o=n.dependencies||(n.dependencies=[]);if(r.ignorePack){const h=a.atlasItems;for(let p=0,u=h.length;p<u;p++){const c=a.atlasItems[p],f=await fetch(c.img).then(v=>v.arrayBuffer()),g=await N.updateSubTextureAssets(n,p,f,e,t);c.type=g.exportType,c.img="./"+gt(g.path)}}else{const h=n.id,p=a.sprites;for(let c=p.length-1;c>=0;c--){const f=p[c].refId,g=i.getFileById(f);if(g){const v=g.content??await i.loadFile(g.id);((l=JSON.parse(await v.text()).belongToAtlas)==null?void 0:l.refId)!==h&&(p.splice(c,1),console.warn("Sprite.belongToAtlas is not equal to this asset."))}else p.splice(c,1),console.warn("SpriteAsset[refId:",f,"] not found")}const u=await ys(a,i);if(u.code===0){const c=u.info;for(const g in c)a[g]=c[g];const f=u.imageFiles;for(let g=0,v=f.length;g<v;g++){const x=await N.updateSubTextureAssets(n,g,f[g],e,t),w=a.atlasItems[g];w.type=x.exportType,w.img="./"+gt(x.path)}}else{for(let c=0,f=o.length;c<f;c++){const g=o[c].ref.refId;i.deleteFile(g)}o.length=0}}return delete a.usage,delete a.allowRotation,delete a.maxHeight,delete a.maxWidth,delete a.padding,delete a.sprites,delete a.tightPacking,{content:new Blob([JSON.stringify(a)])}}})],N);const $n=Object.freeze(Object.defineProperty({__proto__:null,get SpriteAtlasAsset(){return N}},Symbol.toStringTag,{value:"Module"}));var Fs=Object.defineProperty,ks=Object.getOwnPropertyDescriptor,Ds=(n,e,t,i)=>{for(var s=i>1?void 0:i?ks(e,t):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Fs(e,t,s),s};let ne=class extends ot{initByMain(n,e){return Promise.resolve()}};ne=Ds([Ct({type:"LottieAnimation",async bundle(n){const e=JSON.parse(await n.content.text());return{content:new Blob([JSON.stringify(e)])}}})],ne);const Es=it("div",{display:"grid",columnGap:"$1",gridColumn:2/-1,gridTemplateColumns:"minmax(0, 4fr) repeat(1, 2fr) repeat(1, auto) repeat(1, 2fr) repeat(1, auto)",marginBottom:"$1"}),Ls=function({clip:n,removeClip:e,onClipChange:t}){const{t:i}=Rt();return y.jsxs(Es,{children:[y.jsx(Ht,{size:"sm",value:n.name??"",placeholder:i("lottie.clip.name"),onChange:s=>{t({name:s.currentTarget.value})}}),y.jsx(Ht,{size:"sm",value:n.start??"",placeholder:i("lottie.clip.start"),onChange:s=>{t({start:+s.currentTarget.value})}}),y.jsx(Vi,{width:12,onClick:e}),y.jsx(Ht,{size:"sm",value:n.end??"",placeholder:i("lottie.clip.end"),onChange:s=>{t({end:+s.currentTarget.value})}})]})},$s=ut(function(n){const e=n.model,t=e.getViewer(),{inspectorFacade:i}=re(),{t:s}=Rt(),[a,r]=b.useState(()=>Array.isArray(e.clips)?[...e.clips]:[]);b.useEffect(()=>{r(Array.isArray(e.clips)?[...e.clips]:[])},[e,e.clips]),b.useEffect(()=>{t==null||t.setClips(a)},[a,t]);const o=u=>{r(u),i.assetChange(e.id,"clips",u,"asset-meta")},l=()=>{o([...a,{}])},h=u=>{u<0||u>=a.length||o(a.filter((c,f)=>f!==u))},p=(u,c)=>{if(u<0||u>=a.length)return;const f={...a[u],...c},g=a.map((v,x)=>x===u?f:v);o(g)};return y.jsxs(Mi,{title:s("lottie.clips.title"),defaultOpen:!0,collapsible:!0,children:[a.map((u,c)=>y.jsx(Ls,{clip:u,removeClip:()=>h(c),onClipChange:f=>p(c,f)},`${e.id}-${c}`)),y.jsx(tt,{align:"h",css:{margin:"0 auto",padding:"$1 0 0 0"},children:y.jsx(_t,{size:"sm",variant:"soft",startSlot:y.jsx(ze,{size:"14px"}),onClick:l,children:s("lottie.clips.add")})})]})});async function Ns(n,e,t={}){try{const i=JSON.parse(n),{assets:s}=i,a=[];for(let o=0,l=s.length;o<l;o++){const h=s[o],{p}=h;p&&a.push({name:h.id,src:p})}const r=await le(a,{width:2048,height:2048,...t});return r.code!==0?(console.log("Atlas Error:",r.msg),r):(i.assets=s.filter(o=>!o.p),r.info.jsonFile=JSON.stringify(i),r)}catch{return{code:11,msg:"Parse lottie file error"}}}async function zs(n){const e={uploadFiles:[],errors:[]};for(const t in n){const i=n[t],s=i.name;if(s.endsWith(".json"))try{const a=await i.text(),r=JSON.parse(a);Vs(r)&&e.uploadFiles.push({main:i})}catch(a){e.errors.push(Je(s,a))}}return e}async function Us(n,e,t){const i=Le(n.main,"lottie.json"),s=await i.text();let a;try{a=JSON.parse(s)}catch(l){return console.error(l),Jt.error(Je(i.name,l)),i}const{nm:r}=a,o=await Ns(s);if(o.code===0)try{const{imageFiles:l,atlasFile:h,jsonFile:p}=o.info,u=JSON.parse(h),{atlasItems:c}=u,f=c.length,g=qs(),v=Ws(r,i.name),x=[];for(let A=0;A<f;++A)l[A]&&x.push(Gt.uploadBlob(`${v}-${g}-${A}.png`,new Blob([l[A]])));const w=await Promise.all(x);for(let A=0;A<f;++A)c[A].img=w[A].url;const[S,T]=await Promise.all([Gt.uploadBlob(`${v}-${g}.atlas`,new Blob([JSON.stringify(u)])),Gt.uploadBlob(`${v}-${g}.json`,new Blob([p]))]),k={jsonUrl:T.url,atlasUrl:S.url};return new File([JSON.stringify(k)],i.name)}catch(l){console.error(l),Jt.error(`parse lottie file fail ${l}`)}else console.error(o.msg),Jt.error(o.msg);return i}function Vs(n){return n.nm&&n.w&&n.h&&n.assets&&n.assets.length>0&&n.layers&&n.layers.length>0}function qs(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Ws(n,e){const t=e.replace(/\.[^.]+$/,"")||"lottie";return(typeof n=="string"&&n.length>0?n:t).trim().replace(/[^\w.-]+/g,"_")||"lottie"}function Je(n,e){const t=e instanceof Error?e.message:String(e);return`Failed to parse JSON file "${n}": ${t}`}var Hs=Object.defineProperty,Js=Object.getOwnPropertyDescriptor,wt=(n,e,t,i)=>{for(var s=i>1?void 0:i?Js(e,t):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Hs(e,t,s),s};class ft extends Ue{constructor(){super();d(this,"lottie");d(this,"_updateComponent");d(this,"_lottieAsset");d(this,"playing",!1);d(this,"frameTime",0);d(this,"animationNames",[]);d(this,"animationIndex",0);d(this,"_hasClips",!1);$e(this)}get duration(){const{_lottieAsset:t}=this;return this._hasClips&&t.clips[this.animationIndex]?t.clips[this.animationIndex].end-t.clips[this.animationIndex].start:this._lottieAsset.duration}_setAnimationNames(t){this.animationNames=this._hasClips?t==null?void 0:t.map(i=>i.name):[this._lottieAsset.engineObject.name]}setViewAsset(t,i){const s=t.engineObject,a=i.createChild("lottie_entity"),r=a.addComponent(Zt);this._entity=a,this.lottie=r,r.resource=s,this._lottieAsset=t,this._hasClips=t.clips&&t.clips.length>0,this._setAnimationNames(t.clips),this.animationIndex=0;const o=this;this._updateComponent=this._entity.addComponent(class extends Ti{onUpdate(l){o._onUpdate()}}),this.frameTime=0}getSize(){var t;if((t=this.lottie)!=null&&t.resource){const{width:i,height:s}=this.lottie.resource;return{width:i/100,height:s/100}}return{width:0,height:0}}stopViewAsset(){var t;super.stopViewAsset(),this.lottie=null,(t=this._updateComponent)==null||t.destroy(),this.animationNames=null}setClips(t){this.lottie.resource.setClips(t),this._setAnimationNames(t)}play(t){this.lottie.isLooping=!0,this.lottie.play(t),this.playing=!0}pauseAnimation(){this.lottie.pause(),this.playing=!1}selectAnimation(t){this.animationIndex=t;const i=this._lottieAsset.clips[t];this.play(i==null?void 0:i.name)}playAnimation(){const t=this._lottieAsset.clips[this.animationIndex];this.play(t==null?void 0:t.name)}setFrameTime(t){}_onUpdate(){this.playing&&(this.frameTime=this.lottie.frame)}}wt([yt],ft.prototype,"playing",2);wt([yt],ft.prototype,"frameTime",2);wt([yt],ft.prototype,"animationNames",2);wt([yt],ft.prototype,"animationIndex",2);wt([Bt],ft.prototype,"play",1);wt([Bt],ft.prototype,"pauseAnimation",1);wt([Bt],ft.prototype,"_onUpdate",1);var Gs=Object.defineProperty,Ks=Object.getOwnPropertyDescriptor,K=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ks(e,t):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Gs(e,t,s),s};let V=class extends ot{constructor(e){super(e);d(this,"textureSet",new Set);d(this,"width",0);d(this,"height",0);d(this,"duration",0);d(this,"inPoint",0);d(this,"outPoint",0);d(this,"clips",[]);d(this,"mipmap",!1);d(this,"colorDilate",!1);d(this,"filterMode",Q.Bilinear);d(this,"wrapModeU",D.Repeat);d(this,"wrapModeV",D.Repeat);d(this,"runtimeOptions",{overwrite:!1,textureType:"ktx2",mode:"ETC1S",quality:150,isNormal:!1});this.formSchema.addGroup(P("lottie.asset.atlas-export"),["filterMode","wrapModeU","wrapModeV","mipmap","colorDilate"])}destroy(){super.destroy(),this.textureSet.clear(),this.textureSet=null}async initByUploadFile(e){return await this._initByUrl(this.engine,e),this}async initByMain(e){const{engine:t,meta:i}=this;i.runtimeOptions&&(this.runtimeOptions=i.runtimeOptions),this.clips=i.clips||[],this.filterMode=i.filterMode??this.filterMode,this.wrapModeU=i.wrapModeU??this.wrapModeU,this.wrapModeV=i.wrapModeV??this.wrapModeV,this.mipmap=i.mipmap??this.mipmap,this.colorDilate=i.colorDilate??this.colorDilate,await this._initByUrl(t,e);const s=new Ee(this.engine),a=s.addComponent(Zt);a.resource=this.engineObject,this.setDragTempEntity(s)}instantiate(){const e=this.root.sceneStore.createEntity(),t=this.getDragTempEntity(),{position:i,rotation:s}=t.transform,a={components:[{class:"LottieAnimation",id:Pt(),props:{resource:this.getCurrentRef(),priority:0,defaultState:{}}}],id:e.id,isActive:!0,isClone:!1,name:this.name?this.name:"lottie",transform:{class:"Transform",props:{position:{x:i.x,y:i.y,z:i.z},rotation:{x:s.x,y:s.y,z:s.z},scale:{x:1,y:1,z:1}}}};return e.initByFile(a),e}async _createLottieResource(e,t,i){return(await e.resourceManager.load({urls:[t,i],type:"lottie"})).getComponent(Zt).resource}async _initByUrl(e,t){const i=JSON.parse(await t.text()),{jsonUrl:s,atlasUrl:a}=i,r=await this._createLottieResource(e,s,a);this.bindEngineObject(r);const{sprites:o}=r.atlas,{textureSet:l}=this;for(let h=0,p=o.length;h<p;++h){const u=o[h].texture;l.has(u)||(l.add(u),u.filterMode=this.filterMode,u.wrapModeU=this.wrapModeU,u.wrapModeV=this.wrapModeV)}return this.width=r.width,this.height=r.height,this.duration=r.duration,this.inPoint=r.inPoint,this.outPoint=r.outPoint,this}};K([M({type:R.Input,disabled:!0,label:P("lottie.asset.width")})],V.prototype,"width",2);K([M({type:R.Input,disabled:!0,label:P("lottie.asset.height")})],V.prototype,"height",2);K([M({type:R.Input,disabled:!0,label:P("lottie.asset.duration")})],V.prototype,"duration",2);K([M({type:R.Input,disabled:!0,label:P("lottie.asset.in-point")})],V.prototype,"inPoint",2);K([M({type:R.Input,disabled:!0,label:P("lottie.asset.out-point")})],V.prototype,"outPoint",2);K([M({disabled:!0,customComponent:$s}),dt()],V.prototype,"clips",2);K([M({label:P("lottie.asset.mipmap"),type:R.Toggle}),dt()],V.prototype,"mipmap",2);K([M({label:P("lottie.asset.color-dilate"),type:R.Toggle}),dt()],V.prototype,"colorDilate",2);K([M({label:P("lottie.asset.filter-mode.title"),type:R.Select,value:Q.Bilinear,options:[{label:P("lottie.asset.filter-mode.point"),value:Q.Point},{label:P("lottie.asset.filter-mode.bilinear"),value:Q.Bilinear},{label:P("lottie.asset.filter-mode.trilinear"),value:Q.Trilinear}],onChange(n,e,t){const{textureSet:i}=n;i.forEach(s=>{s.filterMode=t})}}),dt()],V.prototype,"filterMode",2);K([M({label:P("lottie.asset.wrap-mode.u"),type:R.Select,value:D.Repeat,options:[{label:P("lottie.asset.wrap-mode.clamp"),value:D.Clamp},{label:P("lottie.asset.wrap-mode.repeat"),value:D.Repeat},{label:P("lottie.asset.wrap-mode.mirror"),value:D.Mirror}],onChange(n,e,t){const{textureSet:i}=n;i.forEach(s=>{s.wrapModeU=t})}}),dt()],V.prototype,"wrapModeU",2);K([M({label:P("lottie.asset.wrap-mode.v"),type:R.Select,value:D.Repeat,options:[{label:P("lottie.asset.wrap-mode.clamp"),value:D.Clamp},{label:P("lottie.asset.wrap-mode.repeat"),value:D.Repeat},{label:P("lottie.asset.wrap-mode.mirror"),value:D.Mirror}],onChange(n,e,t){const{textureSet:i}=n;i.forEach(s=>{s.wrapModeV=t})}}),dt()],V.prototype,"wrapModeV",2);K([yt,dt()],V.prototype,"runtimeOptions",2);V=K([Ct({type:"Lottie",label:P("asset.lottie.title"),loaderType:"EditorLottie",importMenuConfig:{type:Mt.Upload,accept:".json"},viewer:ft,filterUploadFiles:zs,preUpload:Us,dragLayer:et.Lottie,customInspector:ki,async bundle(n,e,t){var k,A;const i=JSON.parse(await n.content.text()),s=n.meta,{jsonUrl:a,atlasUrl:r}=i,o=gt(n.name).split(".")[0],l=n.dependencies||(n.dependencies=[]),h=t.vfs,p=((k=l[0])==null?void 0:k.ref.refId)??Pt();let u;l[0]||(l[0]={key:"atlasUrl",ref:{refId:p}});let c=h.getFileById(p);c?u=c.meta:(u={id:p,type:ot.getRegisteredAssetMeta(N).type,version:te.projectStore.engineVersion,extraData:{},dependencies:[],ignorePack:!0},t.addFile({name:o+"_atlas.atlas",assetId:p,url:null,parentId:n.parentId,main:null,meta:u}),c=h.getFileById(p),c.ignoreBundle=!0),u.colorDilate=s.colorDilate,u.filterMode=s.filterMode,u.wrapModeU=s.wrapModeU,u.wrapModeV=s.wrapModeV,u.mipmap=s.mipmap;const f=n.meta.runtimeOptions;let g=e.assetOptions.textureOptions;f!=null&&f.overwrite&&(g=Object.assign({},g,f)),u.runtimeOptions=g;const v=await(await fetch(r)).json();t.updateFile(p,{main:new Blob([JSON.stringify(v)]),meta:u}),await t.bundleSingleFile(c,e),i.atlasUrl="./"+gt(c.exportPath);const x=((A=l[1])==null?void 0:A.ref.refId)??Pt();let w;l[1]||(l[1]={key:"jsonUrl",ref:{refId:x}});let S=h.getFileById(x);S?w=S.meta:(w={id:x,type:ot.getRegisteredAssetMeta(ne).type,version:te.projectStore.engineVersion,extraData:{},dependencies:[]},t.addFile({name:o+"_clip.json",assetId:x,url:null,parentId:n.parentId,main:null,meta:w}),S=h.getFileById(x),S.ignoreBundle=!0);const T=await(await fetch(a)).json();return T.lolitaAnimations=s.clips,t.updateFile(x,{main:new Blob([JSON.stringify(T)])}),await t.bundleSingleFile(S,e),i.jsonUrl="./"+gt(S.exportPath),{content:new Blob([JSON.stringify(i)])}}})],V);const Nn=Object.freeze(Object.defineProperty({__proto__:null,get LottieAsset(){return V}},Symbol.toStringTag,{value:"Module"})),Xs=it("div",{marginTop:"20px",fontSize:"12px",fontWeight:500,color:"$gray12"}),Ys=ut(function(n){const{asset:{textures:e,textureAtlas:t,missingTexture:i}}=n,{assetStore:s}=re(),[a,r]=b.useState([]),o=b.useMemo(()=>{if(!t)return[];const l=t.pages,h=[];for(let p=0;p<l.length;p+=1){const u=l[p];h.push({name:u.name,regions:u.regions.map(c=>c.name)})}return h},[t]);return b.useEffect(()=>{let l=!1;return Promise.all(e.map(h=>s.getAssetByRef(h))).then(h=>{l||r(h)}).catch(h=>{l||(console.warn("[SpineAtlasInspector] Failed to load atlas textures:",h),r([]))}),()=>{l=!0}},[s,e]),i?y.jsx(Xs,{children:"Missing atlas texture, please reupload atlas and image files."}):y.jsxs(y.Fragment,{children:[y.jsx(Kt,{label:"atlas textures",value:""}),a.map((l,h)=>y.jsx(jt,{dropLayer:et.Texture,label:"",value:l.name,assets:[],asset:l,onLocate:()=>{var u;const p=(u=e==null?void 0:e[h])==null?void 0:u.refId;p&&s.selectAsset(p)}},l.id)),y.jsx(Kt,{label:"atlas regions",value:""}),y.jsx(We,{label:"",items:o.map((l,h)=>({removable:!1,children:l.regions.map(u=>y.jsx(Kt,{label:"",value:u},u)),id:`${h}`,name:l.name}))})]})});var Zs=Object.defineProperty,Qs=Object.getOwnPropertyDescriptor,Vt=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qs(e,t):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Zs(e,t,s),s};let At=class extends ot{constructor(e){super(e);d(this,"_textureAtlas");d(this,"textures",[]);d(this,"atlasText","");d(this,"missingTexture",!1)}get textureAtlas(){return this._textureAtlas}async initByMain(e){this.atlasText=await e.text();const t=this.meta,{textures:i}=t;this.textures=i;const a=(await Promise.all(this.textures.map(l=>this.root.assetStore.getAssetByRef(l)))).map(l=>l==null?void 0:l.engineObject),r=a.some(l=>l==null)||i.length===0;if(this.missingTexture=r,r)return;const o=Di.createTextureAtlas(this.atlasText,a);this._textureAtlas=o}};Vt([dt(),yt],At.prototype,"textures",2);Vt([E()],At.prototype,"atlasText",2);Vt([yt],At.prototype,"missingTexture",2);At=Vt([Ct({type:"SpineAtlas",label:P("asset.spine-atlas.title"),dragLayer:et.SpineAtlas,customInspector:Ys,loaderType:"SpineAtlas",preUpload:Ei,bundle(n){return n.dependencies=Ai(n.meta,["textures"]),{content:n.content}}})],At);function tn(n){return`// ${n}
float function() {
  return 3.1415926;
}
  `}var en=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,Ge=(n,e,t,i)=>{for(var s=i>1?void 0:i?sn(e,t):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&en(e,t,s),s};function nn(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}let ae=class extends ot{constructor(e){super(e);d(this,"_shaderSource");$e(this)}get includePath(){const e=this.getTempRoutes();return e.push(this._name),e.join("/")}initByCreation(e,t,i){return this._shaderSource=tn(this.name),Promise.resolve(this.getMainData())}getMainData(){return this._shaderSource}async initByMain(e,t){const i=await e.text();this.updateCode(i)}async rename(e){const t=this.includePath;pt.unRegisterInclude(t),await super.rename(e),pt.registerInclude(this.includePath,this._shaderSource),this._invalidateChunkCache(),this.refreshIncludedShaders(t)}async moveTo(e){const t=this.includePath;pt.unRegisterInclude(t),await this.moveViaFacade(e),pt.registerInclude(this.includePath,this._shaderSource),this._invalidateChunkCache(),this.refreshIncludedShaders(t)}updateCode(e,t){const i=this.includePath;pt.unRegisterInclude(i),pt.registerInclude(i,e),this._shaderSource=e,this._invalidateChunkCache(),this.refreshIncludedShaders(void 0,t)}beforeDelete(){this.path&&(pt.unRegisterInclude(this.path),this._invalidateChunkCache()),this.refreshIncludedShaders()}_invalidateChunkCache(){var e;(e=ji._shaderCompiler)==null||e._setIncludeMap(pt.includeMap)}refreshIncludedShaders(e,t=new Set){if(t.has(this.id))return;t.add(this.id);let i;if(e){const r=e.split("/");i=r[r.length-1]}else i=this._name;const s=new RegExp(`#include\\s+"[^"]*${nn(i)}"`),a=Object.values(this.root.assetStore.assets).filter(r=>{if(r.meta.type!=="Shader"&&r.meta.type!=="ShaderChunk")return!1;const o=this.getAssetSource(r);return s.test(o)});for(const r of a){if(t.has(r.id))continue;if(r.meta.type==="ShaderChunk"){const l=r,h=l.getMainData();l.updateCode(typeof h=="string"?h:"",t);continue}const o=r;o.updateCode(o.shaderSource)}}getAssetSource(e){if(e.meta.type==="Shader")return e.shaderSource;if(e.meta.type==="ShaderChunk"){const t=e.getMainData();return typeof t=="string"?t:""}return""}onDoubleClick(){Li(this,this.root,()=>{Bi(this.root.projectStore.id,this.id),Oi()})}};Ge([M({type:R.Input,label:P("shader.chunk.include-path"),disabled:!0})],ae.prototype,"includePath",1);ae=Ge([Ct({type:"ShaderChunk",label:P("shader.chunk.title"),defaultName:"ShaderChunk.glsl",icon:"shader",extname:"glsl",importMenuConfig:{type:Mt.Add}})],ae);export{Vi as I,V as L,U as S,N as a,At as b,ae as c,Ln as d,$n as e,Nn as f};
