@dcl/wearable-preview 2.20.2-40372362292.commit-e1572ae → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/{Preview-B8wyDcxU.js → Preview-wli12GGv.js} +3 -3
- package/assets/UnityPreview-BPkXjmj4.js +1 -0
- package/{static-local/assets/babylon.inspector.bundle.max-Bn7kcfak.js → assets/babylon.inspector.bundle.max-COP5uCHL.js} +1 -1
- package/{static-local/assets/emote-events-anMmkWrd.js → assets/emote-events-CJT7MGKy.js} +2 -2
- package/assets/{index-Da1yLqsl.js → index-DIQUh6QQ.js} +3 -3
- package/index.html +3 -3
- package/package.json +3 -3
- package/static-local/assets/{Preview-BPlukz5y.js → Preview-ya9jiRpO.js} +3 -3
- package/static-local/assets/UnityPreview-BRxWyhj2.js +1 -0
- package/{assets/babylon.inspector.bundle.max-Crzw0FJz.js → static-local/assets/babylon.inspector.bundle.max-Cigs2ga4.js} +1 -1
- package/{assets/emote-events-C7HwoaAX.js → static-local/assets/emote-events-B1S6RSNf.js} +2 -2
- package/static-local/assets/{index-Dfw6X7u2.js → index-Bjzk8VLb.js} +2 -2
- package/static-local/index.html +1 -1
- package/static-local/package.json +1 -1
- package/static-local/unity/Build/avatar-preview-renderer.data.br +0 -0
- package/static-local/unity/Build/avatar-preview-renderer.framework.js.br +0 -0
- package/static-local/unity/Build/avatar-preview-renderer.loader.js +1 -1
- package/static-local/unity/Build/avatar-preview-renderer.symbols.json.br +0 -0
- package/static-local/unity/Build/avatar-preview-renderer.wasm.br +0 -0
- package/unity/Build/avatar-preview-renderer.data.br +0 -0
- package/unity/Build/avatar-preview-renderer.framework.js.br +0 -0
- package/unity/Build/avatar-preview-renderer.loader.js +1 -1
- package/unity/Build/avatar-preview-renderer.symbols.json.br +0 -0
- package/unity/Build/avatar-preview-renderer.wasm.br +0 -0
- package/assets/UnityPreview-DXu_W8zj.js +0 -1
- package/static-local/assets/UnityPreview-D_zxrUl-.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as k,a as x,r as m,b as q,R as ue,j as U}from"./index-Da1yLqsl.js";import{f as me,i as ne,m as Se,a as W,d as l,L as pe,b as se,g as Ee,u as ae,s as fe,c as ge,e as ye,h as we,j as he,k as Re,p as be,l as Ae,n as ve,o as Pe,q as Te,r as $,t as C,v as Ie}from"./emote-events-C7HwoaAX.js";var J=(e=>(e.SET_MODE="SetMode",e.SET_PROFILE="SetProfile",e.SET_EMOTE="SetEmote",e.SET_URNS="SetUrns",e.SET_BACKGROUND="SetBackground",e.SET_SKIN_COLOR="SetSkinColor",e.SET_HAIR_COLOR="SetHairColor",e.SET_EYE_COLOR="SetEyeColor",e.SET_BODY_SHAPE="SetBodyShape",e.SET_SHOW_ANIMATION_REFERENCE="SetShowAnimationReference",e.SET_PROJECTION="SetProjection",e.ADD_BASE64="AddBase64",e.CLEAR_BASE64="ClearBase64",e.SET_CONTRACT="SetContract",e.SET_ITEM_ID="SetItemID",e.SET_TOKEN_ID="SetTokenID",e.SET_DISABLE_LOADER="SetDisableLoader",e.SET_TYPE="SetType",e.RELOAD="Reload",e.CLEANUP="Cleanup",e.GET_ELEMENT_BOUNDS="GetElementBounds",e.SET_SPRING_BONES_PARAMS="SetSpringBonesParams",e))(J||{});const Oe={unityMode:"SetMode",profile:"SetProfile",emote:"SetEmote",urns:"SetUrns",background:"SetBackground",skin:"SetSkinColor",hair:"SetHairColor",eyes:"SetEyeColor",bodyShape:"SetBodyShape",showAnimationReference:"SetShowAnimationReference",projection:"SetProjection",base64s:"AddBase64",contractAddress:"SetContract",itemId:"SetItemID",tokenId:"SetTokenID",disableLoader:"SetDisableLoader",type:"SetType"},Le={unityMode:e=>String(e),profile:e=>String(e),emote:e=>String(e),urns:e=>Array.isArray(e)?e.join(","):String(e),background:e=>typeof e=="string"?e.replace("#",""):String(e),skin:e=>typeof e=="string"?e.replace("#",""):String(e),hair:e=>typeof e=="string"?e.replace("#",""):String(e),eyes:e=>typeof e=="string"?e.replace("#",""):String(e),bodyShape:e=>String(e),showAnimationReference:e=>String(e),projection:e=>String(e),contractAddress:e=>String(e),itemId:e=>String(e),tokenId:e=>String(e),disableLoader:e=>String(e),type:e=>String(e)},_=(e,t,r)=>{if(e)try{const s=String(t);Object.values(J).includes(s)||(console.warn(`Unknown Unity method: ${s}. Sending anyway...`),k(`Unknown Unity method: ${s}`,{method:s,value:r})),r!==void 0?e.SendMessage("JSBridge",s,r):e.SendMessage("JSBridge",s)}catch(s){console.error(`Failed to send Unity message ${t}:`,s),x(s,{method:String(t),value:r})}else console.warn(`Unity instance not ready, cannot send message: ${t}`),k(`Unity instance not ready, cannot send message: ${t}`,{method:String(t)})},Ce=(e,t,r)=>{if(!e){console.warn("Unity instance not available, cannot send override messages"),k("Unity instance not available, cannot send override messages");return}let s=0;t.base64s!==void 0&&r.base64s&&(_(e,"ClearBase64"),s++,Array.isArray(t.base64s)&&t.base64s.length>0&&t.base64s.forEach(n=>{_(e,"AddBase64",n),s++})),Object.entries(t).forEach(([n,o])=>{if(n!=="base64s"&&r[n]&&o!==void 0){const i=Oe[n];if(i){const a=Le[n],d=a?a(o):String(o);_(e,i,d),s++}else console.warn(`No Unity method mapping found for property: ${n}`),k(`No Unity method mapping found for property: ${n}`,{property:n,value:o})}}),s>0&&_(e,"Reload")};let K=[];function Ne(e){for(const o of K)URL.revokeObjectURL(o);const t=me(e);K=("emoteDataADR74"in t?t.emoteDataADR74.representations:t.data.representations).flatMap(o=>o.contents.map(i=>i.url));const s=new TextEncoder().encode(JSON.stringify(t));let n="";for(const o of s)n+=String.fromCharCode(o);return{base64:btoa(n),definition:t}}function _e(e){const t=Uint8Array.from(atob(e),r=>r.charCodeAt(0));return JSON.parse(new TextDecoder().decode(t))}function Me(e){for(let t=e.length-1;t>=0;t--)try{const r=_e(e[t]);if(ne(r))return r}catch{}return null}var De={VITE_BASE_URL:"https://cdn.decentraland.org/@dcl/wearable-preview/2.20.2-40372362292.commit-e1572ae"};const G=new Map,N=(e,t)=>{if(!t)return e;const r=e.replace(/\/$/,""),s=t.replace(/^\//,"");return`${r}/${s}`};function Be(e){if(G.has(e))return G.get(e);const t=new Promise((r,s)=>{const n=document.querySelector(`script[src="${e}"]`);if(n){n.addEventListener("load",()=>r(n)),n.addEventListener("error",i=>s(i));return}const o=document.createElement("script");o.src=e,o.async=!0,o.onload=()=>r(o),o.onerror=i=>s(i),document.body.appendChild(o)});return G.set(e,t),t}const Ue=async(e,t,r,s,n,o,i,a,d,p,S,E)=>{try{const c=De.VITE_BASE_URL||"";return await Be(N(c,t)),await createUnityInstance(e,{dataUrl:N(c,r),frameworkUrl:N(c,s),codeUrl:N(c,n),streamingAssetsUrl:N(c,i),symbolUrl:N(c,o),companyName:a,productName:d,productVersion:p,matchWebGLToCanvasSize:S,arguments:E})}catch(c){throw console.error("❌ Failed to load Unity instance:",c),c}},oe=new Set;let X=!1;const Z=()=>oe.forEach(e=>e());function ke(){if(X||!window.AudioContext)return;X=!0;const e=window.AudioContext;window.AudioContext=class extends e{constructor(t){super(t);const r=()=>{this.state==="running"&&(this.removeEventListener("statechange",r),Z())};this.addEventListener("statechange",r)}decodeAudioData(t,r,s){return super.decodeAudioData(t,n=>{r==null||r(n),this.state==="running"&&Z()},s)}}}function xe(e){oe.add(e)}const Je="data:image/png;base64,";function je(e){return{getScreenshot:()=>new Promise(t=>{if(!e){t("");return}e.SendMessage("JSBridge","TakeScreenshot",""),window.addEventListener("message",function r(s){if(s.data.type==="unity-renderer"){const{type:n,payload:o}=s.data.payload;n==="screenshot"&&(window.removeEventListener("message",r),t(Je+o))}})}),getMetrics:()=>new Promise(t=>{if(!e){t({triangles:0,materials:0,textures:0,meshes:0,bodies:0,entities:0});return}e.SendMessage("JSBridge","GetMetrics",""),window.addEventListener("message",function r(s){if(s.data.type==="unity-renderer"){const{type:n,payload:o}=s.data.payload;n==="metrics"&&(window.removeEventListener("message",r),t(o))}})}),changeZoom:async t=>{e&&e.SendMessage("JSBridge","SetZoom",t.toString())},panCamera:async t=>{if(!e)return;const r=t.x??0,s=t.y??0,n=t.z??0;e.SendMessage("JSBridge","SetOffset",`${r},${s},${n}`)},changeCameraPosition:async t=>{if(!e)return;const r=t.alpha??0,s=t.beta??0,n=t.radius??0;e.SendMessage("JSBridge","SetCameraPosition",`${r},${s},${n}`)},setUsername:async t=>{e&&e.SendMessage("JSBridge","SetUsername",t)},cleanup:async()=>{e&&e.SendMessage("JSBridge","Cleanup","")}}}function ze(e,t,r,s){const n=Se();let o=s??null,i=0,a=0,d="stopped",p=null,S=0,E=t,c=0;const y=()=>{var u;return r?r.loop:E?!!((u=E.emoteDataADR74)!=null&&u.loop):!!(o&&pe.includes(o))},f=()=>{c++,R(),d="stopped",a=0,i=0};xe(()=>{d==="playing"?(e.SendMessage("JSBridge","StopEmote",""),e.SendMessage("JSBridge","PlayEmote",""),a=0,S=Date.now(),n.emit(l.PreviewEmoteEventType.ANIMATION_LOOP)):d==="stopped"&&a>0&&e.SendMessage("JSBridge","StopEmote","")});const w=()=>{R(),S=Date.now(),p=setInterval(()=>{if(d!=="playing")return;const u=Date.now(),g=(u-S)/1e3;if(S=u,a+=g,i>0&&a>=i)if(y())a=a%i,n.emit(l.PreviewEmoteEventType.ANIMATION_LOOP);else{a=i,R(),d="stopped",e.SendMessage("JSBridge","StopEmote",""),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAYING,{length:a}),n.emit(l.PreviewEmoteEventType.ANIMATION_END);return}n.emit(l.PreviewEmoteEventType.ANIMATION_PLAYING,{length:a})},15)},R=()=>{p!==null&&(clearInterval(p),p=null)},O=(u,g,T)=>new Promise(h=>{if(!e){h(T);return}const b=v=>{if(v.data.type==="unity-renderer"){const{type:A,payload:M}=v.data.payload;A===g&&(window.removeEventListener("message",b),h(M))}};window.addEventListener("message",b),u()}),P=()=>O(()=>e.SendMessage("JSBridge","GetEmoteLength",""),"emoteLength",0);return{syncAutoplay:async()=>{if(!e)return;f();const u=c,g=await P();u!==c||d!=="stopped"||g<=0||(i=g,d="playing",w(),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAY))},getLength:P,isPlaying:async()=>O(()=>e.SendMessage("JSBridge","IsEmotePlaying",""),"isEmotePlaying",!1),goTo:async u=>{e&&(a=u,e.SendMessage("JSBridge","GoToEmote",u.toString()),d==="stopped"&&(e.SendMessage("JSBridge","PauseEmote",""),d="paused"),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAYING,{length:u}))},play:async()=>{if(!e||d==="playing")return;const u=c;if(i<=0){const g=await P();if(u!==c||d==="playing"||g<=0)return;i=g}d!=="paused"&&(a=0),d="playing",e.SendMessage("JSBridge","PlayEmote",""),w(),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAY)},pause:async()=>{e&&d==="playing"&&(d="paused",R(),e.SendMessage("JSBridge","PauseEmote",""),n.emit(l.PreviewEmoteEventType.ANIMATION_PAUSE))},stop:async()=>{e&&(d="stopped",a=0,R(),e.SendMessage("JSBridge","StopEmote",""),n.emit(l.PreviewEmoteEventType.ANIMATION_END))},enableSound:async()=>{e&&e.SendMessage("JSBridge","EnableSound","")},disableSound:async()=>{e&&e.SendMessage("JSBridge","DisableSound","")},hasSound:async()=>O(()=>e.SendMessage("JSBridge","HasSound",""),"hasSound",!1),isSocialEmote:async()=>W(E),getSocialEmoteAnimations:async()=>!E||!W(E)?null:[{title:"Start Animation",...E.emoteDataADR74.startAnimation},...E.emoteDataADR74.outcomes.map(u=>({title:u.title,loop:u.loop,audio:u.audio,...u.clips}))],getPlayingSocialEmoteAnimation:async()=>r??null,get emote(){return E},set emote(u){E=u,f(),r=void 0},get previewEmote(){return o},set previewEmote(u){u!==o&&(o=u,f())},events:n}}function $e(e){return{setSpringBonesParams:async(t,r)=>{e&&e.SendMessage("JSBridge",J.SET_SPRING_BONES_PARAMS,JSON.stringify({itemId:t,params:r}))}}}const Ge={dataUrl:"/unity/Build/avatar-preview-renderer.data.br",frameworkUrl:"/unity/Build/avatar-preview-renderer.framework.js.br",codeUrl:"/unity/Build/avatar-preview-renderer.wasm.br",symbolUrl:"/unity/Build/avatar-preview-renderer.symbols.json.br"};function Fe(){return Ge}async function Ve(e,t){let r=null;try{const s=Fe();if(ke(),r=await Ue(e,"/unity/Build/avatar-preview-renderer.loader.js",s.dataUrl,s.frameworkUrl,s.codeUrl,s.symbolUrl,"/emotes","Decentraland","AvatarPreviewRenderer","2.2.2",!0,[]),!r)throw new Error("Failed to load Unity instance");const n=t!=null&&t.itemDefinition&&ne(t.itemDefinition)?t.itemDefinition:null,o=(t==null?void 0:t.socialEmote)||void 0,i=(t==null?void 0:t.emote)||null,a=je(r),d=ze(r,n,o,i),p=$e(r);if(t!=null&&t.itemDefinition&&t.bodyShape&&se(t.itemDefinition)){const S=Ee(t.itemDefinition,t.bodyShape);S&&p.setSpringBonesParams(t.itemDefinition.id,S)}return{scene:a,emote:d,physics:p,unity:r}}catch(s){if(console.error("Unity render failed:",s),r!=null&&r.Quit)try{r.Quit()}catch(n){console.error("Error quitting Unity instance:",n),x(n,{phase:"unityQuit"})}throw s}}const Ye=()=>Math.floor(Math.random()*159)+1,ie=()=>`default${Ye()}`,He=e=>e===l.PreviewType.AVATAR||e===l.PreviewType.WEARABLE?e:null,F=e=>e&&be(e)||null,I=e=>e||"",ee=e=>e||[],Qe=e=>e.replace("#","");function te(e){const t=new URL(window.location.href);Object.entries(e).forEach(([r,s])=>{t.searchParams.delete(r),Array.isArray(s)?s.forEach(n=>{n!==""&&t.searchParams.append(r,n)}):s!==""&&t.searchParams.set(r,s)}),window.history.replaceState({},"",t.toString())}function qe(){const{options:e,overrideSources:t}=ae(),[r,s]=m.useState(null),[n,o]=m.useState(!0),[i,a]=m.useState(null),d=m.useRef(null),p=m.useRef(e),S=m.useRef(!0);return m.useEffect(()=>{const E=JSON.stringify(e),c=JSON.stringify(p.current);if(!S.current&&E===c)return;S.current=!1,p.current=e,(async()=>{var f,w;try{o(!0),a(null);const R=e.peerUrl||q.get("PEER_URL"),O=e.marketplaceServerUrl||e.nftServerUrl||q.get("MARKETPLACE_SERVER_URL"),P=He(e.type);let u=P||l.PreviewType.WEARABLE,g={color:e.background||"#4b4852",transparent:e.disableBackground===!0};const T=fe(e.profile);let h=T==null?void 0:T.value;h==="default"&&(h=ie());const b=h&&T?T.type==="address"?await ge(h,R):await ye(h,R):null,v=e.bodyShape||((f=b==null?void 0:b.avatar)==null?void 0:f.bodyShape)||l.BodyShape.MALE;let A=null;if(e.contractAddress&&(A=await we({contractAddress:e.contractAddress,tokenId:e.tokenId,itemId:e.itemId,peerUrl:R,marketplaceServerUrl:O}),A&&se(A))){g={...g,image:A.thumbnail};const B=he(A);Re(B)&&u!==l.PreviewType.AVATAR&&(u=l.PreviewType.TEXTURE)}const M=F(e.eyes),V=F(e.hair),Y=F(e.skin),D=e.unityMode||null,de=e.camera&&Object.values(l.PreviewCamera).includes(e.camera)?e.camera:l.PreviewCamera.INTERACTIVE,H=e.projection&&Object.values(l.PreviewProjection).includes(e.projection)?e.projection:l.PreviewProjection.PERSPECTIVE,L=e.disableDefaultEmotes?null:e.emote&&Object.values(l.PreviewEmote).includes(e.emote)?e.emote:l.PreviewEmote.IDLE,j={background:g,bodyShape:v,mode:D,projection:H,type:u,base64:((w=e.base64s)==null?void 0:w[0])||null,contract:e.contractAddress||null,disableLoader:e.disableLoader||!1,emote:(L==null?void 0:L.toString())||null,eyeColor:M,hairColor:V,item:e.itemId||null,profile:h||null,skinColor:Y,token:e.tokenId||null,urn:e.urns||null,showAnimationReference:null,itemDefinition:A,socialEmote:e.socialEmote||null},le=JSON.stringify(j),ce=JSON.stringify(d.current);if(le!==ce){if(d.current=j,Object.keys(t).length===0){const B=ee(e.urns),Q=ee(e.base64s);if(D===l.PreviewUnityMode.CONFIG){const z={mode:I(D||"")};te(z)}else{const z={background:g.transparent?"":Qe(g.color),disableLoader:e.disableLoader?"true":"",profile:I(h||""),bodyShape:I(v||""),eyeColor:I(M),hairColor:I(V),skinColor:I(Y),mode:I(D||""),camera:de,projection:H,emote:I((L==null?void 0:L.toString())||""),type:I(P),urn:B.length>0?B:[""],base64:Q.length>0?Q:[""]};te(z)}}s(j)}o(!1)}catch(R){console.error("[useUnityConfig] Failed to load config:",R),a(R instanceof Error?R.message:"Failed to load config"),o(!1)}})()},[e,t]),[r,n,i]}const We="unity-renderer",Ke="unity-canvas",re=1,Xe="Failed to load Unity";var Ze=(e=>(e.LOADED="loaded",e.ERROR="error",e.SCREENSHOT="screenshot",e.CUSTOMIZATION_DONE="customization-done",e.CUSTOMIZATION_STEP="avatar-customization-step",e.ELEMENT_BOUNDS="element-bounds",e))(Ze||{});const et="get_element_bounds",tt="element_bounds_response",rt=(e,t,r,s)=>{const[n,o]=m.useState({isLoaded:!1,isInitialized:!1,error:null}),i=m.useRef(null),a=m.useCallback(p=>{var S,E;if(p.data.type===We){const{type:c,payload:y}=p.data.payload;c==="loaded"&&(y===!0||y==="true")?(o(f=>({...f,isLoaded:!0,isInitialized:!0})),l.sendMessage(C(),l.PreviewMessageType.LOAD,{renderer:l.PreviewRenderer.UNITY}),(E=(S=t.current)==null?void 0:S.emote)==null||E.syncAutoplay()):c==="customization-done"?l.sendMessage(C(),l.PreviewMessageType.CONTROLLER_RESPONSE,{id:"customization-done",ok:!0,result:JSON.parse(p.data.payload.payload)}):c==="avatar-customization-step"?l.sendMessage(C(),l.PreviewMessageType.CONTROLLER_RESPONSE,{id:"avatar-customization-step",ok:!0,result:{step:p.data.payload.payload}}):c==="element-bounds"?l.sendMessage(C(),tt,y):c==="error"&&(x(new Error(y),{component:"UnityPreview",phase:"unityMessage"}),o(f=>({...f,error:y})),l.sendMessage(C(),l.PreviewMessageType.ERROR,{message:"Error loading the wearable. Please try again."}))}},[]),d=m.useCallback(async p=>{if(!(!e.canvas.current||e.isInitializing.current||e.unityInstance.current)){e.isInitializing.current=!0,o(S=>({...S,isLoaded:!1,error:null}));try{const{unity:S,...E}=await Ve(e.canvas.current,p);e.unityInstance.current=S,t.current=E,i.current&&i.current(),i.current=Ie(t.current),o(c=>({...c,isInitialized:!0}))}catch(S){const E=S instanceof Error?S.message:Xe;console.error("Unity init failed:",S),x(S,{component:"UnityPreview",phase:"initializeUnity"}),o(c=>({...c,error:E})),l.sendMessage(C(),l.PreviewMessageType.ERROR,{message:E})}finally{e.isInitializing.current=!1}}},[e,t]);return m.useEffect(()=>{n.isInitialized||s||!r||d(r)},[r,s,n.isInitialized,d]),m.useEffect(()=>()=>{i.current&&i.current()},[]),m.useEffect(()=>{if(r)return window.addEventListener("message",a,!1),()=>{window.removeEventListener("message",a,!1)}},[r,a]),n},nt=e=>{const[t,r]=m.useState({pixelRatio:window.devicePixelRatio||re,is3D:!0,backgroundImage:""});return m.useEffect(()=>{const s=()=>{r(o=>({...o,pixelRatio:window.devicePixelRatio||re}))},n=window.matchMedia(`(resolution: ${t.pixelRatio}dppx)`);return n.addEventListener("change",s),()=>{n.removeEventListener("change",s)}},[t.pixelRatio]),m.useEffect(()=>{e&&r(s=>({...s,backgroundImage:e.background.image||"",is3D:e.type!==l.PreviewType.TEXTURE}))},[e]),t},st=(e,t,r,s,n,o)=>{const i=m.useMemo(()=>{const a={};for(const d of Object.keys(n))n[d]&&s[d]!==void 0&&(a[d]=s[d]);return a},[n,s]);m.useEffect(()=>{if(!(!r.isInitialized||!r.isLoaded||!e.current)){if(i.profile==="default"){const a=t.current.profile;i.profile=a!=null&&a.match(/^default\d+$/)?a:ie()}if(Object.keys(i).length>0){const a={...i};if(a.blob){const{base64:p}=Ne(a.blob);a.base64s=[...a.base64s??[],p],delete a.blob}a.base64s!==void 0&&o.current&&(o.current.emote.emote=Me(a.base64s)),"emote"in a&&o.current&&a.emote!==t.current.emote&&(o.current.emote.previewEmote=a.emote??null);const d=a.base64s!==void 0&&!n.base64s?{...n,base64s:!0}:n;Ce(e.current,a,d),t.current=a}}},[r.isInitialized,r.isLoaded,i,n,e,t,o])},at=()=>{const{width:e=window.innerWidth,height:t=window.innerHeight}=Ae(),r=m.useRef(null),s=m.useRef(null),n=m.useRef(!1),o=m.useRef({}),i=ve(),[a,d,p]=qe(),{options:S,overrideSources:E}=ae(),c=m.useMemo(()=>({canvas:r,unityInstance:s,isInitializing:n,lastSentOverrides:o}),[]);Pe(h=>{var b,v;if(((b=h.data)==null?void 0:b.type)===et&&s.current){const A=(v=h.data.payload)==null?void 0:v.elementName;A&&_(s.current,J.GET_ELEMENT_BOUNDS,A)}});const y=rt(c,i,a,d),f=nt(a);st(c.unityInstance,c.lastSentOverrides,y,S,E,i),Te();const w=m.useMemo(()=>{const h=y.error||p,b=!y.isLoaded&&!h,v=!!f.backgroundImage&&!f.is3D&&!b,A=f.is3D&&!b;return{error:h,isLoading:b,showImage:v,showCanvas:A}},[y.error,y.isLoaded,p,f.backgroundImage,f.is3D]),R=m.useMemo(()=>({opacity:1,backgroundColor:!(a!=null&&a.background.transparent)&&(a==null?void 0:a.type)===l.PreviewType.TEXTURE?a.background.color:void 0}),[a]),O=m.useMemo(()=>({width:`${e}px`,height:`${t}px`}),[e,t]),P=m.useMemo(()=>({width:Math.round(e*f.pixelRatio),height:Math.round(t*f.pixelRatio)}),[e,t,f.pixelRatio]),u=m.useMemo(()=>$("Preview",{"is-loading":w.isLoading,"is-loaded":y.isLoaded,"is-3d":f.is3D,"has-error":!!w.error}),[w.isLoading,y.isLoaded,f.is3D,w.error]),g=m.useMemo(()=>$("thumbnail",{"is-visible":w.showImage}),[w.showImage]),T=m.useMemo(()=>$({"is-visible":w.showCanvas}),[w.showCanvas]);return U.jsxs("div",{className:u,style:R,children:[U.jsx("img",{src:f.backgroundImage,className:g,alt:"preview"}),U.jsx("canvas",{ref:c.canvas,id:Ke,className:T,width:P.width,height:P.height,style:O}),w.error&&U.jsx("div",{className:"error",children:w.error})]})},dt=ue.memo(at);export{Ze as UnityMessageType,dt as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as k,a as x,r as m,b as q,R as ue,j as U}from"./index-Dfw6X7u2.js";import{f as me,i as ne,m as Se,a as W,d as l,L as pe,b as se,g as Ee,u as oe,s as fe,c as ge,e as ye,h as we,j as he,k as Re,p as be,l as Ae,n as ve,o as Te,q as Pe,r as $,t as C,v as Ie}from"./emote-events-anMmkWrd.js";var J=(e=>(e.SET_MODE="SetMode",e.SET_PROFILE="SetProfile",e.SET_EMOTE="SetEmote",e.SET_URNS="SetUrns",e.SET_BACKGROUND="SetBackground",e.SET_SKIN_COLOR="SetSkinColor",e.SET_HAIR_COLOR="SetHairColor",e.SET_EYE_COLOR="SetEyeColor",e.SET_BODY_SHAPE="SetBodyShape",e.SET_SHOW_ANIMATION_REFERENCE="SetShowAnimationReference",e.SET_PROJECTION="SetProjection",e.ADD_BASE64="AddBase64",e.CLEAR_BASE64="ClearBase64",e.SET_CONTRACT="SetContract",e.SET_ITEM_ID="SetItemID",e.SET_TOKEN_ID="SetTokenID",e.SET_DISABLE_LOADER="SetDisableLoader",e.SET_TYPE="SetType",e.RELOAD="Reload",e.CLEANUP="Cleanup",e.GET_ELEMENT_BOUNDS="GetElementBounds",e.SET_SPRING_BONES_PARAMS="SetSpringBonesParams",e))(J||{});const Oe={unityMode:"SetMode",profile:"SetProfile",emote:"SetEmote",urns:"SetUrns",background:"SetBackground",skin:"SetSkinColor",hair:"SetHairColor",eyes:"SetEyeColor",bodyShape:"SetBodyShape",showAnimationReference:"SetShowAnimationReference",projection:"SetProjection",base64s:"AddBase64",contractAddress:"SetContract",itemId:"SetItemID",tokenId:"SetTokenID",disableLoader:"SetDisableLoader",type:"SetType"},Le={unityMode:e=>String(e),profile:e=>String(e),emote:e=>String(e),urns:e=>Array.isArray(e)?e.join(","):String(e),background:e=>typeof e=="string"?e.replace("#",""):String(e),skin:e=>typeof e=="string"?e.replace("#",""):String(e),hair:e=>typeof e=="string"?e.replace("#",""):String(e),eyes:e=>typeof e=="string"?e.replace("#",""):String(e),bodyShape:e=>String(e),showAnimationReference:e=>String(e),projection:e=>String(e),contractAddress:e=>String(e),itemId:e=>String(e),tokenId:e=>String(e),disableLoader:e=>String(e),type:e=>String(e)},_=(e,t,r)=>{if(e)try{const s=String(t);Object.values(J).includes(s)||(console.warn(`Unknown Unity method: ${s}. Sending anyway...`),k(`Unknown Unity method: ${s}`,{method:s,value:r})),r!==void 0?e.SendMessage("JSBridge",s,r):e.SendMessage("JSBridge",s)}catch(s){console.error(`Failed to send Unity message ${t}:`,s),x(s,{method:String(t),value:r})}else console.warn(`Unity instance not ready, cannot send message: ${t}`),k(`Unity instance not ready, cannot send message: ${t}`,{method:String(t)})},Ce=(e,t,r)=>{if(!e){console.warn("Unity instance not available, cannot send override messages"),k("Unity instance not available, cannot send override messages");return}let s=0;t.base64s!==void 0&&r.base64s&&(_(e,"ClearBase64"),s++,Array.isArray(t.base64s)&&t.base64s.length>0&&t.base64s.forEach(n=>{_(e,"AddBase64",n),s++})),Object.entries(t).forEach(([n,a])=>{if(n!=="base64s"&&r[n]&&a!==void 0){const i=Oe[n];if(i){const o=Le[n],d=o?o(a):String(a);_(e,i,d),s++}else console.warn(`No Unity method mapping found for property: ${n}`),k(`No Unity method mapping found for property: ${n}`,{property:n,value:a})}}),s>0&&_(e,"Reload")};let K=[];function Ne(e){for(const a of K)URL.revokeObjectURL(a);const t=me(e);K=("emoteDataADR74"in t?t.emoteDataADR74.representations:t.data.representations).flatMap(a=>a.contents.map(i=>i.url));const s=new TextEncoder().encode(JSON.stringify(t));let n="";for(const a of s)n+=String.fromCharCode(a);return{base64:btoa(n),definition:t}}function _e(e){const t=Uint8Array.from(atob(e),r=>r.charCodeAt(0));return JSON.parse(new TextDecoder().decode(t))}function Me(e){for(let t=e.length-1;t>=0;t--)try{const r=_e(e[t]);if(ne(r))return r}catch{}return null}var De={VITE_BASE_URL:""};const G=new Map,N=(e,t)=>t;function Be(e){if(G.has(e))return G.get(e);const t=new Promise((r,s)=>{const n=document.querySelector(`script[src="${e}"]`);if(n){n.addEventListener("load",()=>r(n)),n.addEventListener("error",i=>s(i));return}const a=document.createElement("script");a.src=e,a.async=!0,a.onload=()=>r(a),a.onerror=i=>s(i),document.body.appendChild(a)});return G.set(e,t),t}const Ue=async(e,t,r,s,n,a,i,o,d,p,S,E)=>{try{const c=De.VITE_BASE_URL||"";return await Be(N(c,t)),await createUnityInstance(e,{dataUrl:N(c,r),frameworkUrl:N(c,s),codeUrl:N(c,n),streamingAssetsUrl:N(c,i),symbolUrl:N(c,a),companyName:o,productName:d,productVersion:p,matchWebGLToCanvasSize:S,arguments:E})}catch(c){throw console.error("❌ Failed to load Unity instance:",c),c}},ae=new Set;let X=!1;const Z=()=>ae.forEach(e=>e());function ke(){if(X||!window.AudioContext)return;X=!0;const e=window.AudioContext;window.AudioContext=class extends e{constructor(t){super(t);const r=()=>{this.state==="running"&&(this.removeEventListener("statechange",r),Z())};this.addEventListener("statechange",r)}decodeAudioData(t,r,s){return super.decodeAudioData(t,n=>{r==null||r(n),this.state==="running"&&Z()},s)}}}function xe(e){ae.add(e)}const Je="data:image/png;base64,";function je(e){return{getScreenshot:()=>new Promise(t=>{if(!e){t("");return}e.SendMessage("JSBridge","TakeScreenshot",""),window.addEventListener("message",function r(s){if(s.data.type==="unity-renderer"){const{type:n,payload:a}=s.data.payload;n==="screenshot"&&(window.removeEventListener("message",r),t(Je+a))}})}),getMetrics:()=>new Promise(t=>{if(!e){t({triangles:0,materials:0,textures:0,meshes:0,bodies:0,entities:0});return}e.SendMessage("JSBridge","GetMetrics",""),window.addEventListener("message",function r(s){if(s.data.type==="unity-renderer"){const{type:n,payload:a}=s.data.payload;n==="metrics"&&(window.removeEventListener("message",r),t(a))}})}),changeZoom:async t=>{e&&e.SendMessage("JSBridge","SetZoom",t.toString())},panCamera:async t=>{if(!e)return;const r=t.x??0,s=t.y??0,n=t.z??0;e.SendMessage("JSBridge","SetOffset",`${r},${s},${n}`)},changeCameraPosition:async t=>{if(!e)return;const r=t.alpha??0,s=t.beta??0,n=t.radius??0;e.SendMessage("JSBridge","SetCameraPosition",`${r},${s},${n}`)},setUsername:async t=>{e&&e.SendMessage("JSBridge","SetUsername",t)},cleanup:async()=>{e&&e.SendMessage("JSBridge","Cleanup","")}}}function ze(e,t,r,s){const n=Se();let a=s??null,i=0,o=0,d="stopped",p=null,S=0,E=t,c=0;const y=()=>{var u;return r?r.loop:E?!!((u=E.emoteDataADR74)!=null&&u.loop):!!(a&&pe.includes(a))},f=()=>{c++,R(),d="stopped",o=0,i=0};xe(()=>{d==="playing"?(e.SendMessage("JSBridge","StopEmote",""),e.SendMessage("JSBridge","PlayEmote",""),o=0,S=Date.now(),n.emit(l.PreviewEmoteEventType.ANIMATION_LOOP)):d==="stopped"&&o>0&&e.SendMessage("JSBridge","StopEmote","")});const w=()=>{R(),S=Date.now(),p=setInterval(()=>{if(d!=="playing")return;const u=Date.now(),g=(u-S)/1e3;if(S=u,o+=g,i>0&&o>=i)if(y())o=o%i,n.emit(l.PreviewEmoteEventType.ANIMATION_LOOP);else{o=i,R(),d="stopped",e.SendMessage("JSBridge","StopEmote",""),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAYING,{length:o}),n.emit(l.PreviewEmoteEventType.ANIMATION_END);return}n.emit(l.PreviewEmoteEventType.ANIMATION_PLAYING,{length:o})},15)},R=()=>{p!==null&&(clearInterval(p),p=null)},O=(u,g,P)=>new Promise(h=>{if(!e){h(P);return}const b=v=>{if(v.data.type==="unity-renderer"){const{type:A,payload:M}=v.data.payload;A===g&&(window.removeEventListener("message",b),h(M))}};window.addEventListener("message",b),u()}),T=()=>O(()=>e.SendMessage("JSBridge","GetEmoteLength",""),"emoteLength",0);return{syncAutoplay:async()=>{if(!e)return;f();const u=c,g=await T();u!==c||d!=="stopped"||g<=0||(i=g,d="playing",w(),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAY))},getLength:T,isPlaying:async()=>O(()=>e.SendMessage("JSBridge","IsEmotePlaying",""),"isEmotePlaying",!1),goTo:async u=>{e&&(o=u,e.SendMessage("JSBridge","GoToEmote",u.toString()),d==="stopped"&&(e.SendMessage("JSBridge","PauseEmote",""),d="paused"),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAYING,{length:u}))},play:async()=>{if(!e||d==="playing")return;const u=c;if(i<=0){const g=await T();if(u!==c||d==="playing"||g<=0)return;i=g}d!=="paused"&&(o=0),d="playing",e.SendMessage("JSBridge","PlayEmote",""),w(),n.emit(l.PreviewEmoteEventType.ANIMATION_PLAY)},pause:async()=>{e&&d==="playing"&&(d="paused",R(),e.SendMessage("JSBridge","PauseEmote",""),n.emit(l.PreviewEmoteEventType.ANIMATION_PAUSE))},stop:async()=>{e&&(d="stopped",o=0,R(),e.SendMessage("JSBridge","StopEmote",""),n.emit(l.PreviewEmoteEventType.ANIMATION_END))},enableSound:async()=>{e&&e.SendMessage("JSBridge","EnableSound","")},disableSound:async()=>{e&&e.SendMessage("JSBridge","DisableSound","")},hasSound:async()=>O(()=>e.SendMessage("JSBridge","HasSound",""),"hasSound",!1),isSocialEmote:async()=>W(E),getSocialEmoteAnimations:async()=>!E||!W(E)?null:[{title:"Start Animation",...E.emoteDataADR74.startAnimation},...E.emoteDataADR74.outcomes.map(u=>({title:u.title,loop:u.loop,audio:u.audio,...u.clips}))],getPlayingSocialEmoteAnimation:async()=>r??null,get emote(){return E},set emote(u){E=u,f(),r=void 0},get previewEmote(){return a},set previewEmote(u){u!==a&&(a=u,f())},events:n}}function $e(e){return{setSpringBonesParams:async(t,r)=>{e&&e.SendMessage("JSBridge",J.SET_SPRING_BONES_PARAMS,JSON.stringify({itemId:t,params:r}))}}}const Ge={dataUrl:"/unity/Build/avatar-preview-renderer.data.br",frameworkUrl:"/unity/Build/avatar-preview-renderer.framework.js.br",codeUrl:"/unity/Build/avatar-preview-renderer.wasm.br",symbolUrl:"/unity/Build/avatar-preview-renderer.symbols.json.br"};function Fe(){return Ge}async function Ve(e,t){let r=null;try{const s=Fe();if(ke(),r=await Ue(e,"/unity/Build/avatar-preview-renderer.loader.js",s.dataUrl,s.frameworkUrl,s.codeUrl,s.symbolUrl,"/emotes","Decentraland","AvatarPreviewRenderer","2.2.2",!0,[]),!r)throw new Error("Failed to load Unity instance");const n=t!=null&&t.itemDefinition&&ne(t.itemDefinition)?t.itemDefinition:null,a=(t==null?void 0:t.socialEmote)||void 0,i=(t==null?void 0:t.emote)||null,o=je(r),d=ze(r,n,a,i),p=$e(r);if(t!=null&&t.itemDefinition&&t.bodyShape&&se(t.itemDefinition)){const S=Ee(t.itemDefinition,t.bodyShape);S&&p.setSpringBonesParams(t.itemDefinition.id,S)}return{scene:o,emote:d,physics:p,unity:r}}catch(s){if(console.error("Unity render failed:",s),r!=null&&r.Quit)try{r.Quit()}catch(n){console.error("Error quitting Unity instance:",n),x(n,{phase:"unityQuit"})}throw s}}const Ye=()=>Math.floor(Math.random()*159)+1,ie=()=>`default${Ye()}`,He=e=>e===l.PreviewType.AVATAR||e===l.PreviewType.WEARABLE?e:null,F=e=>e&&be(e)||null,I=e=>e||"",ee=e=>e||[],Qe=e=>e.replace("#","");function te(e){const t=new URL(window.location.href);Object.entries(e).forEach(([r,s])=>{t.searchParams.delete(r),Array.isArray(s)?s.forEach(n=>{n!==""&&t.searchParams.append(r,n)}):s!==""&&t.searchParams.set(r,s)}),window.history.replaceState({},"",t.toString())}function qe(){const{options:e,overrideSources:t}=oe(),[r,s]=m.useState(null),[n,a]=m.useState(!0),[i,o]=m.useState(null),d=m.useRef(null),p=m.useRef(e),S=m.useRef(!0);return m.useEffect(()=>{const E=JSON.stringify(e),c=JSON.stringify(p.current);if(!S.current&&E===c)return;S.current=!1,p.current=e,(async()=>{var f,w;try{a(!0),o(null);const R=e.peerUrl||q.get("PEER_URL"),O=e.marketplaceServerUrl||e.nftServerUrl||q.get("MARKETPLACE_SERVER_URL"),T=He(e.type);let u=T||l.PreviewType.WEARABLE,g={color:e.background||"#4b4852",transparent:e.disableBackground===!0};const P=fe(e.profile);let h=P==null?void 0:P.value;h==="default"&&(h=ie());const b=h&&P?P.type==="address"?await ge(h,R):await ye(h,R):null,v=e.bodyShape||((f=b==null?void 0:b.avatar)==null?void 0:f.bodyShape)||l.BodyShape.MALE;let A=null;if(e.contractAddress&&(A=await we({contractAddress:e.contractAddress,tokenId:e.tokenId,itemId:e.itemId,peerUrl:R,marketplaceServerUrl:O}),A&&se(A))){g={...g,image:A.thumbnail};const B=he(A);Re(B)&&u!==l.PreviewType.AVATAR&&(u=l.PreviewType.TEXTURE)}const M=F(e.eyes),V=F(e.hair),Y=F(e.skin),D=e.unityMode||null,de=e.camera&&Object.values(l.PreviewCamera).includes(e.camera)?e.camera:l.PreviewCamera.INTERACTIVE,H=e.projection&&Object.values(l.PreviewProjection).includes(e.projection)?e.projection:l.PreviewProjection.PERSPECTIVE,L=e.disableDefaultEmotes?null:e.emote&&Object.values(l.PreviewEmote).includes(e.emote)?e.emote:l.PreviewEmote.IDLE,j={background:g,bodyShape:v,mode:D,projection:H,type:u,base64:((w=e.base64s)==null?void 0:w[0])||null,contract:e.contractAddress||null,disableLoader:e.disableLoader||!1,emote:(L==null?void 0:L.toString())||null,eyeColor:M,hairColor:V,item:e.itemId||null,profile:h||null,skinColor:Y,token:e.tokenId||null,urn:e.urns||null,showAnimationReference:null,itemDefinition:A,socialEmote:e.socialEmote||null},le=JSON.stringify(j),ce=JSON.stringify(d.current);if(le!==ce){if(d.current=j,Object.keys(t).length===0){const B=ee(e.urns),Q=ee(e.base64s);if(D===l.PreviewUnityMode.CONFIG){const z={mode:I(D||"")};te(z)}else{const z={background:g.transparent?"":Qe(g.color),disableLoader:e.disableLoader?"true":"",profile:I(h||""),bodyShape:I(v||""),eyeColor:I(M),hairColor:I(V),skinColor:I(Y),mode:I(D||""),camera:de,projection:H,emote:I((L==null?void 0:L.toString())||""),type:I(T),urn:B.length>0?B:[""],base64:Q.length>0?Q:[""]};te(z)}}s(j)}a(!1)}catch(R){console.error("[useUnityConfig] Failed to load config:",R),o(R instanceof Error?R.message:"Failed to load config"),a(!1)}})()},[e,t]),[r,n,i]}const We="unity-renderer",Ke="unity-canvas",re=1,Xe="Failed to load Unity";var Ze=(e=>(e.LOADED="loaded",e.ERROR="error",e.SCREENSHOT="screenshot",e.CUSTOMIZATION_DONE="customization-done",e.CUSTOMIZATION_STEP="avatar-customization-step",e.ELEMENT_BOUNDS="element-bounds",e))(Ze||{});const et="get_element_bounds",tt="element_bounds_response",rt=(e,t,r,s)=>{const[n,a]=m.useState({isLoaded:!1,isInitialized:!1,error:null}),i=m.useRef(null),o=m.useCallback(p=>{var S,E;if(p.data.type===We){const{type:c,payload:y}=p.data.payload;c==="loaded"&&(y===!0||y==="true")?(a(f=>({...f,isLoaded:!0,isInitialized:!0})),l.sendMessage(C(),l.PreviewMessageType.LOAD,{renderer:l.PreviewRenderer.UNITY}),(E=(S=t.current)==null?void 0:S.emote)==null||E.syncAutoplay()):c==="customization-done"?l.sendMessage(C(),l.PreviewMessageType.CONTROLLER_RESPONSE,{id:"customization-done",ok:!0,result:JSON.parse(p.data.payload.payload)}):c==="avatar-customization-step"?l.sendMessage(C(),l.PreviewMessageType.CONTROLLER_RESPONSE,{id:"avatar-customization-step",ok:!0,result:{step:p.data.payload.payload}}):c==="element-bounds"?l.sendMessage(C(),tt,y):c==="error"&&(x(new Error(y),{component:"UnityPreview",phase:"unityMessage"}),a(f=>({...f,error:y})),l.sendMessage(C(),l.PreviewMessageType.ERROR,{message:"Error loading the wearable. Please try again."}))}},[]),d=m.useCallback(async p=>{if(!(!e.canvas.current||e.isInitializing.current||e.unityInstance.current)){e.isInitializing.current=!0,a(S=>({...S,isLoaded:!1,error:null}));try{const{unity:S,...E}=await Ve(e.canvas.current,p);e.unityInstance.current=S,t.current=E,i.current&&i.current(),i.current=Ie(t.current),a(c=>({...c,isInitialized:!0}))}catch(S){const E=S instanceof Error?S.message:Xe;console.error("Unity init failed:",S),x(S,{component:"UnityPreview",phase:"initializeUnity"}),a(c=>({...c,error:E})),l.sendMessage(C(),l.PreviewMessageType.ERROR,{message:E})}finally{e.isInitializing.current=!1}}},[e,t]);return m.useEffect(()=>{n.isInitialized||s||!r||d(r)},[r,s,n.isInitialized,d]),m.useEffect(()=>()=>{i.current&&i.current()},[]),m.useEffect(()=>{if(r)return window.addEventListener("message",o,!1),()=>{window.removeEventListener("message",o,!1)}},[r,o]),n},nt=e=>{const[t,r]=m.useState({pixelRatio:window.devicePixelRatio||re,is3D:!0,backgroundImage:""});return m.useEffect(()=>{const s=()=>{r(a=>({...a,pixelRatio:window.devicePixelRatio||re}))},n=window.matchMedia(`(resolution: ${t.pixelRatio}dppx)`);return n.addEventListener("change",s),()=>{n.removeEventListener("change",s)}},[t.pixelRatio]),m.useEffect(()=>{e&&r(s=>({...s,backgroundImage:e.background.image||"",is3D:e.type!==l.PreviewType.TEXTURE}))},[e]),t},st=(e,t,r,s,n,a)=>{const i=m.useMemo(()=>{const o={};for(const d of Object.keys(n))n[d]&&s[d]!==void 0&&(o[d]=s[d]);return o},[n,s]);m.useEffect(()=>{if(!(!r.isInitialized||!r.isLoaded||!e.current)){if(i.profile==="default"){const o=t.current.profile;i.profile=o!=null&&o.match(/^default\d+$/)?o:ie()}if(Object.keys(i).length>0){const o={...i};if(o.blob){const{base64:p}=Ne(o.blob);o.base64s=[...o.base64s??[],p],delete o.blob}o.base64s!==void 0&&a.current&&(a.current.emote.emote=Me(o.base64s)),"emote"in o&&a.current&&o.emote!==t.current.emote&&(a.current.emote.previewEmote=o.emote??null);const d=o.base64s!==void 0&&!n.base64s?{...n,base64s:!0}:n;Ce(e.current,o,d),t.current=o}}},[r.isInitialized,r.isLoaded,i,n,e,t,a])},ot=()=>{const{width:e=window.innerWidth,height:t=window.innerHeight}=Ae(),r=m.useRef(null),s=m.useRef(null),n=m.useRef(!1),a=m.useRef({}),i=ve(),[o,d,p]=qe(),{options:S,overrideSources:E}=oe(),c=m.useMemo(()=>({canvas:r,unityInstance:s,isInitializing:n,lastSentOverrides:a}),[]);Te(h=>{var b,v;if(((b=h.data)==null?void 0:b.type)===et&&s.current){const A=(v=h.data.payload)==null?void 0:v.elementName;A&&_(s.current,J.GET_ELEMENT_BOUNDS,A)}});const y=rt(c,i,o,d),f=nt(o);st(c.unityInstance,c.lastSentOverrides,y,S,E,i),Pe();const w=m.useMemo(()=>{const h=y.error||p,b=!y.isLoaded&&!h,v=!!f.backgroundImage&&!f.is3D&&!b,A=f.is3D&&!b;return{error:h,isLoading:b,showImage:v,showCanvas:A}},[y.error,y.isLoaded,p,f.backgroundImage,f.is3D]),R=m.useMemo(()=>({opacity:1,backgroundColor:!(o!=null&&o.background.transparent)&&(o==null?void 0:o.type)===l.PreviewType.TEXTURE?o.background.color:void 0}),[o]),O=m.useMemo(()=>({width:`${e}px`,height:`${t}px`}),[e,t]),T=m.useMemo(()=>({width:Math.round(e*f.pixelRatio),height:Math.round(t*f.pixelRatio)}),[e,t,f.pixelRatio]),u=m.useMemo(()=>$("Preview",{"is-loading":w.isLoading,"is-loaded":y.isLoaded,"is-3d":f.is3D,"has-error":!!w.error}),[w.isLoading,y.isLoaded,f.is3D,w.error]),g=m.useMemo(()=>$("thumbnail",{"is-visible":w.showImage}),[w.showImage]),P=m.useMemo(()=>$({"is-visible":w.showCanvas}),[w.showCanvas]);return U.jsxs("div",{className:u,style:R,children:[U.jsx("img",{src:f.backgroundImage,className:g,alt:"preview"}),U.jsx("canvas",{ref:c.canvas,id:Ke,className:P,width:T.width,height:T.height,style:O}),w.error&&U.jsx("div",{className:"error",children:w.error})]})},dt=ue.memo(ot);export{Ze as UnityMessageType,dt as default};
|