@dcl/wearable-preview 2.21.0 → 2.21.1-46664124900.commit-0e093f5
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-wli12GGv.js → Preview-gzF0kpDw.js} +3 -3
- package/assets/UnityPreview-Ht6kYAXJ.js +1 -0
- package/{static-local/assets/babylon.inspector.bundle.max-Cigs2ga4.js → assets/babylon.inspector.bundle.max-DlTXHUOj.js} +1 -1
- package/{static-local/assets/emote-events-B1S6RSNf.js → assets/emote-events-BjEuujVz.js} +1 -1
- package/assets/{index-DIQUh6QQ.js → index-bWGIAv1v.js} +3 -3
- package/index.html +3 -3
- package/package.json +3 -3
- package/static-local/assets/{Preview-ya9jiRpO.js → Preview-B_P6Kq-5.js} +3 -3
- package/{assets/UnityPreview-BPkXjmj4.js → static-local/assets/UnityPreview-OCPATfTC.js} +1 -1
- package/{assets/babylon.inspector.bundle.max-COP5uCHL.js → static-local/assets/babylon.inspector.bundle.max-3J-bFWf5.js} +1 -1
- package/{assets/emote-events-CJT7MGKy.js → static-local/assets/emote-events-gPYE5jqc.js} +1 -1
- package/static-local/assets/{index-Bjzk8VLb.js → index-gK0Vd9dG.js} +2 -2
- package/static-local/index.html +1 -1
- package/static-local/package.json +1 -1
- package/static-local/assets/UnityPreview-BRxWyhj2.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as j,a as W,r as u,b as ie,R as _e,j as F}from"./index-Bjzk8VLb.js";import{d as c,f as Pe,i as J,m as Ce,a as le,b as pe,g as Oe,u as ge,s as Le,c as ve,e as Be,h as De,j as Ne,k as Ie,p as ke,l as Ue,n as Me,o as ze,q as xe,r as Ze,t as G,v as M,w as Fe}from"./emote-events-B1S6RSNf.js";function be(e){return e.zoom!==null&&e.zoom!==void 0||e.wheelZoom!==null&&e.wheelZoom!==void 0||e.showThumbnailBoundaries===!0||e.camera===c.PreviewCamera.STATIC}var Y=(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.ADD_URL="AddUrl",e.CLEAR_URLS="ClearUrls",e.SET_DISABLE_FACE="SetDisableFace",e.SET_DISABLE_DEFAULT_WEARABLES="SetDisableDefaultWearables",e.SET_PEER_URL="SetPeerUrl",e.SET_MARKETPLACE_SERVER_URL="SetMarketplaceServerUrl",e.SET_ZOOM_LEVEL="SetZoomLevel",e.SET_WHEEL_ZOOM="SetWheelZoom",e.SET_WHEEL_START="SetWheelStart",e.SET_CAMERA="SetCamera",e.SET_LOCK_ALPHA="SetLockAlpha",e.SET_LOCK_BETA="SetLockBeta",e.SET_LOCK_RADIUS="SetLockRadius",e.SET_PANNING="SetPanning",e.SET_DISABLE_AUTO_ROTATE="SetDisableAutoRotate",e.SET_AUTO_ROTATE_SPEED="SetAutoRotateSpeed",e.SET_OFFSET="SetOffset",e.SET_SHOW_THUMBNAIL_BOUNDARIES="SetShowThumbnailBoundaries",e.SET_SHOW_SCENE_BOUNDARIES="SetShowSceneBoundaries",e.SET_SHADOW="SetShadow",e.SET_GLOW="SetGlow",e.SET_WHEEL_PRECISION="SetWheelPrecision",e.SET_ZOOM_SCALE="SetZoomScale",e.SET_CAMERA_X="SetCameraX",e.SET_CAMERA_Y="SetCameraY",e.SET_CAMERA_Z="SetCameraZ",e.SET_DISABLE_AUTO_CENTER="SetDisableAutoCenter",e.SET_SOCIAL_EMOTE="SetSocialEmote",e.RELOAD="Reload",e.CLEANUP="Cleanup",e.SET_HIDE_CONTROLS="SetHideControls",e.GET_ELEMENT_BOUNDS="GetElementBounds",e.SET_SPRING_BONES_PARAMS="SetSpringBonesParams",e))(Y||{});const je={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",disableFace:"SetDisableFace",disableDefaultWearables:"SetDisableDefaultWearables",peerUrl:"SetPeerUrl",marketplaceServerUrl:"SetMarketplaceServerUrl",nftServerUrl:"SetMarketplaceServerUrl",zoom:"SetZoomLevel",wheelZoom:"SetWheelZoom",wheelStart:"SetWheelStart",camera:"SetCamera",lockAlpha:"SetLockAlpha",lockBeta:"SetLockBeta",lockRadius:"SetLockRadius",panning:"SetPanning",disableAutoRotate:"SetDisableAutoRotate",autoRotateSpeed:"SetAutoRotateSpeed",showThumbnailBoundaries:"SetShowThumbnailBoundaries",showSceneBoundaries:"SetShowSceneBoundaries",wheelPrecision:"SetWheelPrecision",zoomScale:"SetZoomScale",cameraX:"SetCameraX",cameraY:"SetCameraY",cameraZ:"SetCameraZ",disableAutoCenter:"SetDisableAutoCenter",socialEmote:"SetSocialEmote"},$=["offsetX","offsetY","offsetZ"],We=["base64s","urls","background","disableBackground","disableDefaultEmotes"],Je="00000000",Ye="4b4852",He="none",Ge="idle",$e=new Set(["SetHideControls","SetBackground","SetZoomLevel","SetWheelZoom","SetWheelStart","SetCamera","SetLockAlpha","SetLockBeta","SetLockRadius","SetPanning","SetDisableAutoRotate","SetAutoRotateSpeed","SetOffset","SetShowThumbnailBoundaries","SetShowSceneBoundaries","SetShadow","SetGlow","SetWheelPrecision","SetZoomScale"]),Ve={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),disableFace:e=>String(e),disableDefaultWearables:e=>String(e),peerUrl:e=>String(e),marketplaceServerUrl:e=>String(e),nftServerUrl:e=>String(e),zoom:e=>String(e),wheelZoom:e=>String(e),wheelStart:e=>String(e),camera:e=>String(e),lockAlpha:e=>String(e),lockBeta:e=>String(e),lockRadius:e=>String(e),panning:e=>String(e),disableAutoRotate:e=>String(e),autoRotateSpeed:e=>String(e),showThumbnailBoundaries:e=>String(e),showSceneBoundaries:e=>String(e),wheelPrecision:e=>String(e),zoomScale:e=>String(e),cameraX:e=>String(e),cameraY:e=>String(e),cameraZ:e=>String(e),disableAutoCenter:e=>String(e),socialEmote:e=>e?JSON.stringify(e):""},h=(e,t,r)=>{if(e)try{const a=String(t);Object.values(Y).includes(a)||(console.warn(`Unknown Unity method: ${a}. Sending anyway...`),j(`Unknown Unity method: ${a}`,{method:a,value:r})),r!==void 0?e.SendMessage("JSBridge",a,r):e.SendMessage("JSBridge",a)}catch(a){console.error(`Failed to send Unity message ${t}:`,a),W(a,{method:String(t),value:r})}else console.warn(`Unity instance not ready, cannot send message: ${t}`),j(`Unity instance not ready, cannot send message: ${t}`,{method:String(t)})},Xe=(e,t,r)=>{if(!e){console.warn("Unity instance not available, cannot send override messages"),j("Unity instance not available, cannot send override messages");return}let a=!1;t.base64s!==void 0&&r.base64s&&(h(e,"ClearBase64"),a=!0,Array.isArray(t.base64s)&&t.base64s.length>0&&t.base64s.forEach(o=>{h(e,"AddBase64",o)}));const n=o=>r[o]&&t[o]!==void 0;if(n("urls")&&(h(e,"ClearUrls"),a=!0,Array.isArray(t.urls)&&t.urls.forEach(o=>{h(e,"AddUrl",o)})),$.some(n)){const o=$.map(l=>Number(t[l])||0).join(",");h(e,"SetOffset",o)}if(t.disableBackground===!0||n("background")){const o=typeof t.background=="string"?t.background.replace("#",""):Ye;h(e,"SetBackground",t.disableBackground===!0?Je:o)}if(n("disableBackground")){const o=t.disableBackground===!0?"off":"on";h(e,"SetShadow",o),h(e,"SetGlow",o)}n("disableDefaultEmotes")&&!n("emote")&&(h(e,"SetEmote",t.disableDefaultEmotes?He:Ge),a=!0),Object.entries(t).forEach(([o,l])=>{if(!(We.includes(o)||$.includes(o))&&n(o)){const s=je[o];if(s){const i=Ve[o],S=i?i(l):String(l);h(e,s,S),$e.has(s)||(a=!0)}else console.warn(`No Unity method mapping found for property: ${o}`),j(`No Unity method mapping found for property: ${o}`,{property:o,value:l})}}),be(t)&&h(e,"SetHideControls","true"),a&&h(e,"Reload")};let ce=[];function qe(e){for(const o of ce)URL.revokeObjectURL(o);const t=Pe(e);ce=("emoteDataADR74"in t?t.emoteDataADR74.representations:t.data.representations).flatMap(o=>o.contents.map(l=>l.url));const a=new TextEncoder().encode(JSON.stringify(t));let n="";for(const o of a)n+=String.fromCharCode(o);return{base64:btoa(n),definition:t}}function Ke(e){const t=Uint8Array.from(atob(e),r=>r.charCodeAt(0));return JSON.parse(new TextDecoder().decode(t))}function Qe(e){for(let t=e.length-1;t>=0;t--)try{const r=Ke(e[t]);if(J(r))return r}catch{}return null}var et={VITE_BASE_URL:""};const V=new Map,z=(e,t)=>t;function tt(e){if(V.has(e))return V.get(e);const t=new Promise((r,a)=>{const n=document.querySelector(`script[src="${e}"]`);if(n){n.addEventListener("load",()=>r(n)),n.addEventListener("error",l=>a(l));return}const o=document.createElement("script");o.src=e,o.async=!0,o.onload=()=>r(o),o.onerror=l=>a(l),document.body.appendChild(o)});return V.set(e,t),t}const rt=async(e,t,r,a,n,o,l,s,i,S,m,p)=>{try{const d=et.VITE_BASE_URL||"";return await tt(z(d,t)),await createUnityInstance(e,{dataUrl:z(d,r),frameworkUrl:z(d,a),codeUrl:z(d,n),streamingAssetsUrl:z(d,l),symbolUrl:z(d,o),companyName:s,productName:i,productVersion:S,matchWebGLToCanvasSize:m,arguments:p})}catch(d){throw console.error("❌ Failed to load Unity instance:",d),d}},Ae=new Set;let de=!1;const ue=()=>Ae.forEach(e=>e());function at(){if(de||!window.AudioContext)return;de=!0;const e=window.AudioContext;window.AudioContext=class extends e{constructor(t){super(t);const r=()=>{this.state==="running"&&(this.removeEventListener("statechange",r),ue())};this.addEventListener("statechange",r)}decodeAudioData(t,r,a){return super.decodeAudioData(t,n=>{r==null||r(n),this.state==="running"&&ue()},a)}}}function ot(e){Ae.add(e)}const nt="data:image/png;base64,";function Se(e,t,r,a){return new Promise((n,o)=>{function l(s){var m;if(((m=s.data)==null?void 0:m.type)!=="unity-renderer")return;const{type:i,payload:S}=s.data.payload;i===a?(window.removeEventListener("message",l),n(S)):i==="request-failed"&&(S==null?void 0:S.request)===a&&(window.removeEventListener("message",l),o(new Error(S.reason)))}window.addEventListener("message",l),e.SendMessage("JSBridge",t,r)})}const me=e=>Number.isInteger(e)&&e>0;function st(e){return{getScreenshot:async(t,r)=>{if(!e)return"";const a=me(t)&&me(r)?`${t},${r}`:"",n=await Se(e,"TakeScreenshot",a,"screenshot");return nt+n},getMetrics:()=>e?Se(e,"GetMetrics","","metrics"):Promise.resolve({triangles:0,materials:0,textures:0,meshes:0,bodies:0,entities:0}),changeZoom:async t=>{e&&e.SendMessage("JSBridge","SetZoom",t.toString())},panCamera:async t=>{if(!e)return;const r=t.x??0,a=t.y??0,n=t.z??0;e.SendMessage("JSBridge","SetOffset",`${r},${a},${n}`)},changeCameraPosition:async t=>{if(!e)return;const r=t.alpha??0,a=t.beta??0,n=t.radius??0;e.SendMessage("JSBridge","SetCameraPosition",`${r},${a},${n}`)},setUsername:async t=>{e&&e.SendMessage("JSBridge","SetUsername",t)},cleanup:async()=>{e&&e.SendMessage("JSBridge","Cleanup","")}}}function it(e,t,r,a){const n=Ce();let o=a??null,l=0,s=0,i="stopped",S=0,m=!1,p=t,d=0;const b=()=>{d++,i="stopped",s=0,l=0,S=0,m=!1},A=()=>{S++,e.SendMessage("JSBridge","PlayEmote","")},w=(f,g)=>{switch(f){case"play":i="playing",s=g,S>0?S--:m=!0,n.emit(c.PreviewEmoteEventType.ANIMATION_PLAY);break;case"playing":s=g,n.emit(c.PreviewEmoteEventType.ANIMATION_PLAYING,{length:g});break;case"pause":i="paused",s=g,n.emit(c.PreviewEmoteEventType.ANIMATION_PAUSE);break;case"loop":s=0,n.emit(c.PreviewEmoteEventType.ANIMATION_LOOP);break;case"end":i="stopped",s=g,g>0&&n.emit(c.PreviewEmoteEventType.ANIMATION_PLAYING,{length:g}),n.emit(c.PreviewEmoteEventType.ANIMATION_END);break}};window.addEventListener("message",f=>{var B;if(((B=f.data)==null?void 0:B.type)!=="unity-renderer")return;const{type:g,payload:R}=f.data.payload;g!=="emote-event"||!R||w(R.event,Number(R.time)||0)}),ot(()=>{i==="playing"?A():i==="stopped"&&s>0&&e.SendMessage("JSBridge","StopEmote","")});const N=(f,g,R)=>new Promise(B=>{if(!e){B(R);return}const L=y=>{if(y.data.type==="unity-renderer"){const{type:T,payload:_}=y.data.payload;T===g&&(window.removeEventListener("message",L),B(_))}};window.addEventListener("message",L),f()}),I=()=>N(()=>e.SendMessage("JSBridge","GetEmoteLength",""),"emoteLength",0);return{syncAutoplay:async()=>{if(!e||m)return;b();const f=d,g=await I();f!==d||i!=="stopped"||g<=0||(l=g,i="playing",n.emit(c.PreviewEmoteEventType.ANIMATION_PLAY))},getLength:I,isPlaying:async()=>N(()=>e.SendMessage("JSBridge","IsEmotePlaying",""),"isEmotePlaying",!1),goTo:async f=>{e&&(e.SendMessage("JSBridge","GoToEmote",f.toString()),i==="stopped"&&(e.SendMessage("JSBridge","PauseEmote",""),i="paused"))},play:async()=>{if(!e||i==="playing")return;const f=d;if(l<=0){const g=await I();if(f!==d||i==="playing"||g<=0)return;l=g}i!=="paused"&&(s=0),i="playing",A()},pause:async()=>{e&&i==="playing"&&(i="paused",e.SendMessage("JSBridge","PauseEmote",""))},stop:async()=>{e&&(i="stopped",s=0,e.SendMessage("JSBridge","StopEmote",""))},enableSound:async()=>{e&&e.SendMessage("JSBridge","EnableSound","")},disableSound:async()=>{e&&e.SendMessage("JSBridge","DisableSound","")},hasSound:async()=>N(()=>e.SendMessage("JSBridge","HasSound",""),"hasSound",!1),isSocialEmote:async()=>le(p),getSocialEmoteAnimations:async()=>!p||!le(p)?null:[{title:"Start Animation",...p.emoteDataADR74.startAnimation},...p.emoteDataADR74.outcomes.map(f=>({title:f.title,loop:f.loop,audio:f.audio,...f.clips}))],getPlayingSocialEmoteAnimation:async()=>r??null,get emote(){return p},set emote(f){p=f,b(),r=void 0},get previewEmote(){return o},set previewEmote(f){f!==o&&(o=f,b())},events:n}}function lt(e){return{setSpringBonesParams:async(t,r)=>{e&&e.SendMessage("JSBridge",Y.SET_SPRING_BONES_PARAMS,JSON.stringify({itemId:t,params:r}))}}}const ct={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 dt(){return ct}async function ut(e,t){let r=null;try{const a=dt();if(at(),r=await rt(e,"/unity/Build/avatar-preview-renderer.loader.js",a.dataUrl,a.frameworkUrl,a.codeUrl,a.symbolUrl,"/emotes","Decentraland","AvatarPreviewRenderer","2.2.2",!0,[]),!r)throw new Error("Failed to load Unity instance");const n=t!=null&&t.itemDefinition&&J(t.itemDefinition)?t.itemDefinition:null,o=(t==null?void 0:t.socialEmote)||void 0,l=(t==null?void 0:t.emote)||null,s=st(r),i=it(r,n,o,l),S=lt(r);if(t!=null&&t.itemDefinition&&t.bodyShape&&pe(t.itemDefinition)){const m=Oe(t.itemDefinition,t.bodyShape);m&&S.setSpringBonesParams(t.itemDefinition.id,m)}return{scene:s,emote:i,physics:S,unity:r}}catch(a){if(console.error("Unity render failed:",a),r!=null&&r.Quit)try{r.Quit()}catch(n){console.error("Error quitting Unity instance:",n),W(n,{phase:"unityQuit"})}throw a}}const St=()=>Math.floor(Math.random()*159)+1,we=()=>`default${St()}`,mt="none",Et=e=>e===c.PreviewType.AVATAR||e===c.PreviewType.WEARABLE?e:null,X=e=>e&&ke(e)||null,v=e=>e||"",q=e=>e||[],C=e=>typeof e=="number"&&!isNaN(e)?e:null,O=e=>e===null?"":String(e),D=e=>e?"true":"",ft=(e,t)=>{var r;return!t||!J(t)?null:(((r=e.current)==null?void 0:r.id)!==t.id&&(e.current={id:t.id,animation:Ue(t)}),e.current.animation)},pt=e=>e.replace("#","");function Ee(e){const t=new URL(window.location.href);Object.entries(e).forEach(([r,a])=>{t.searchParams.delete(r),Array.isArray(a)?a.forEach(n=>{n!==""&&t.searchParams.append(r,n)}):a!==""&&t.searchParams.set(r,a)}),window.history.replaceState({},"",t.toString())}function gt(){const{options:e,overrideSources:t}=ge(),[r,a]=u.useState(null),[n,o]=u.useState(!0),[l,s]=u.useState(null),i=u.useRef(null),S=u.useRef(null),m=u.useRef(e),p=u.useRef(!0);return u.useEffect(()=>{const d=JSON.stringify(e),b=JSON.stringify(m.current);if(!p.current&&d===b)return;p.current=!1,m.current=e,(async()=>{var w,N,I,f,g;try{o(!0),s(null);const R=e.peerUrl||ie.get("PEER_URL"),B=e.marketplaceServerUrl||e.nftServerUrl||ie.get("MARKETPLACE_SERVER_URL"),L=Et(e.type);let y=L||c.PreviewType.WEARABLE,T={color:e.background||"#4b4852",transparent:e.disableBackground===!0};const _=Le(e.profile);let k=_==null?void 0:_.value;k==="default"&&(k=we());const H=k&&_?_.type==="address"?await ve(k,R):await Be(k,R):null,K=e.bodyShape||((w=H==null?void 0:H.avatar)==null?void 0:w.bodyShape)||c.BodyShape.MALE;let P=null;if(e.contractAddress){if(P=await De({contractAddress:e.contractAddress,tokenId:e.tokenId,itemId:e.itemId,peerUrl:R,marketplaceServerUrl:B}),P&&pe(P)){T={...T,image:P.thumbnail};const Z=Ne(P);Ie(Z)&&y!==c.PreviewType.AVATAR&&(y=c.PreviewType.TEXTURE)}P&&c.isStandard(P)&&!e.background&&(T={...T,color:c.Rarity.getColor(P.rarity)})}const Q=X(e.eyes),ee=X(e.hair),te=X(e.skin),x=e.unityMode||c.PreviewUnityMode.MARKETPLACE,Re=(((N=e.urns)==null?void 0:N.length)??0)>0||(((I=e.urls)==null?void 0:I.length)??0)>0||(((f=e.base64s)==null?void 0:f.length)??0)>0||P&&J(P)||e.profile?c.PreviewType.AVATAR:c.PreviewType.WEARABLE,Te=L||(e.unityMode?null:Re),re=e.camera&&Object.values(c.PreviewCamera).includes(e.camera)?e.camera:c.PreviewCamera.INTERACTIVE,ae=e.projection&&Object.values(c.PreviewProjection).includes(e.projection)?e.projection:c.PreviewProjection.PERSPECTIVE,oe=e.emote&&Object.values(c.PreviewEmote).includes(e.emote)?e.emote:e.disableDefaultEmotes?mt:c.PreviewEmote.IDLE,E={background:T,bodyShape:K,mode:x,projection:ae,type:y,base64:((g=e.base64s)==null?void 0:g[0])||null,contract:e.contractAddress||null,disableLoader:e.disableLoader||!1,emote:oe,eyeColor:Q,hairColor:ee,item:e.itemId||null,profile:k||null,skinColor:te,token:e.tokenId||null,urn:e.urns||null,urls:e.urls||null,showAnimationReference:null,itemDefinition:P,socialEmote:e.socialEmote||ft(S,P),disableFace:!!e.disableFace,disableDefaultWearables:!!e.disableDefaultWearables,peerUrl:e.peerUrl||null,marketplaceServerUrl:e.marketplaceServerUrl||e.nftServerUrl||null,camera:re,zoom:C(e.zoom),wheelZoom:C(e.wheelZoom),wheelStart:C(e.wheelStart),lockAlpha:!!e.lockAlpha,lockBeta:!!e.lockBeta,lockRadius:!!e.lockRadius,panning:e.panning!==!1,disableAutoRotate:!!e.disableAutoRotate,autoRotateSpeed:C(e.autoRotateSpeed),offsetX:C(e.offsetX),offsetY:C(e.offsetY),offsetZ:C(e.offsetZ),cameraX:C(e.cameraX),cameraY:C(e.cameraY),cameraZ:C(e.cameraZ),wheelPrecision:C(e.wheelPrecision),zoomScale:C(e.zoomScale),disableAutoCenter:!!e.disableAutoCenter,showThumbnailBoundaries:!!e.showThumbnailBoundaries,showSceneBoundaries:!!e.showSceneBoundaries},ye=JSON.stringify(E),he=JSON.stringify(i.current);if(ye!==he){if(i.current=E,Object.keys(t).length===0){const Z=q(e.urns),ne=q(e.urls),se=q(e.base64s);if(x===c.PreviewUnityMode.CONFIG){const U={mode:v(x||"")};Ee(U)}else{const U={background:T.transparent?"":pt(T.color),disableLoader:e.disableLoader?"true":"",profile:v(k||""),bodyShape:v(K||""),eyeColor:v(Q),hairColor:v(ee),skinColor:v(te),mode:v(x||""),camera:re,projection:ae,emote:oe,type:v(Te),urn:Z.length>0?Z:[""],url:ne.length>0?ne:[""],base64:se.length>0?se:[""],disableFace:D(E.disableFace),disableDefaultWearables:D(E.disableDefaultWearables),peerUrl:v(E.peerUrl),marketplaceServerUrl:v(E.marketplaceServerUrl),zoom:O(E.zoom),wheelZoom:O(E.wheelZoom),wheelStart:O(E.wheelStart),lockAlpha:D(E.lockAlpha),lockBeta:D(E.lockBeta),lockRadius:D(E.lockRadius),panning:E.panning?"":"false",disableAutoRotate:D(E.disableAutoRotate),autoRotateSpeed:O(E.autoRotateSpeed),offsetX:O(E.offsetX),offsetY:O(E.offsetY),offsetZ:O(E.offsetZ),cameraX:O(E.cameraX),cameraY:O(E.cameraY),cameraZ:O(E.cameraZ),wheelPrecision:O(E.wheelPrecision),zoomScale:O(E.zoomScale),disableAutoCenter:D(E.disableAutoCenter),showThumbnailBoundaries:D(E.showThumbnailBoundaries),showSceneBoundaries:D(E.showSceneBoundaries),socialEmote:E.socialEmote?JSON.stringify(E.socialEmote):""};T.transparent&&(U.shadow="off",U.glow="off"),be(e)&&(U.hideControls="true"),Ee(U)}}a(E)}o(!1)}catch(R){console.error("[useUnityConfig] Failed to load config:",R),s(R instanceof Error?R.message:"Failed to load config"),o(!1)}})()},[e,t]),[r,n,l]}const bt="unity-renderer",At="unity-canvas",fe=1,wt="Failed to load Unity";var Rt=(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))(Rt||{});const Tt="get_element_bounds",yt="element_bounds_response",ht=(e,t,r,a)=>{const[n,o]=u.useState({isLoaded:!1,isInitialized:!1,error:null}),l=u.useRef(null),s=u.useCallback(S=>{var m,p;if(S.data.type===bt){const{type:d,payload:b}=S.data.payload;d==="loaded"&&(b===!0||b==="true")?(o(A=>({...A,isLoaded:!0,isInitialized:!0})),c.sendMessage(M(),c.PreviewMessageType.LOAD,{renderer:c.PreviewRenderer.UNITY}),(p=(m=t.current)==null?void 0:m.emote)==null||p.syncAutoplay()):d==="customization-done"?c.sendMessage(M(),c.PreviewMessageType.CONTROLLER_RESPONSE,{id:"customization-done",ok:!0,result:JSON.parse(S.data.payload.payload)}):d==="avatar-customization-step"?c.sendMessage(M(),c.PreviewMessageType.CONTROLLER_RESPONSE,{id:"avatar-customization-step",ok:!0,result:{step:S.data.payload.payload}}):d==="element-bounds"?c.sendMessage(M(),yt,b):d==="error"&&(W(new Error(b),{component:"UnityPreview",phase:"unityMessage"}),o(A=>({...A,error:b})),c.sendMessage(M(),c.PreviewMessageType.ERROR,{message:"Error loading the wearable. Please try again."}))}},[]),i=u.useCallback(async S=>{if(!(!e.canvas.current||e.isInitializing.current||e.unityInstance.current)){e.isInitializing.current=!0,o(m=>({...m,isLoaded:!1,error:null}));try{const{unity:m,...p}=await ut(e.canvas.current,S);e.unityInstance.current=m,t.current=p,l.current&&l.current(),l.current=Fe(t.current),o(d=>({...d,isInitialized:!0}))}catch(m){const p=m instanceof Error?m.message:wt;console.error("Unity init failed:",m),W(m,{component:"UnityPreview",phase:"initializeUnity"}),o(d=>({...d,error:p})),c.sendMessage(M(),c.PreviewMessageType.ERROR,{message:p})}finally{e.isInitializing.current=!1}}},[e,t]);return u.useEffect(()=>{n.isInitialized||a||!r||i(r)},[r,a,n.isInitialized,i]),u.useEffect(()=>()=>{l.current&&l.current()},[]),u.useEffect(()=>{if(r)return window.addEventListener("message",s,!1),()=>{window.removeEventListener("message",s,!1)}},[r,s]),n},_t=e=>{const[t,r]=u.useState({pixelRatio:window.devicePixelRatio||fe,is3D:!0,backgroundImage:""});return u.useEffect(()=>{const a=()=>{r(o=>({...o,pixelRatio:window.devicePixelRatio||fe}))},n=window.matchMedia(`(resolution: ${t.pixelRatio}dppx)`);return n.addEventListener("change",a),()=>{n.removeEventListener("change",a)}},[t.pixelRatio]),u.useEffect(()=>{e&&r(a=>({...a,backgroundImage:e.background.image||"",is3D:e.type!==c.PreviewType.TEXTURE}))},[e]),t},Pt=(e,t,r,a,n,o)=>{const l=u.useMemo(()=>{const s={};for(const i of Object.keys(n))n[i]&&a[i]!==void 0&&(s[i]=a[i]);return s},[n,a]);u.useEffect(()=>{if(!(!r.isInitialized||!r.isLoaded||!e.current)){if(l.profile==="default"){const s=t.current.profile;l.profile=s!=null&&s.match(/^default\d+$/)?s:we()}if(Object.keys(l).length>0){const s={...l};if(s.blob){const{base64:S}=qe(s.blob);s.base64s=[...s.base64s??[],S],delete s.blob}s.base64s!==void 0&&o.current&&(o.current.emote.emote=Qe(s.base64s)),"emote"in s&&o.current&&s.emote!==t.current.emote&&(o.current.emote.previewEmote=s.emote??null);const i=s.base64s!==void 0&&!n.base64s?{...n,base64s:!0}:n;Xe(e.current,s,i),t.current=s}}},[r.isInitialized,r.isLoaded,l,n,e,t,o])},Ct=()=>{const{width:e=window.innerWidth,height:t=window.innerHeight}=Me(),r=u.useRef(null),a=u.useRef(null),n=u.useRef(!1),o=u.useRef({}),l=ze(),[s,i,S]=gt(),{options:m,overrideSources:p}=ge(),d=u.useMemo(()=>({canvas:r,unityInstance:a,isInitializing:n,lastSentOverrides:o}),[]);xe(L=>{var y,T;if(((y=L.data)==null?void 0:y.type)===Tt&&a.current){const _=(T=L.data.payload)==null?void 0:T.elementName;_&&h(a.current,Y.GET_ELEMENT_BOUNDS,_)}});const b=ht(d,l,s,i),A=_t(s);Pt(d.unityInstance,d.lastSentOverrides,b,m,p,l),Ze();const w=u.useMemo(()=>{const L=b.error||S,y=!b.isLoaded&&!L,T=!!A.backgroundImage&&!A.is3D&&!y,_=A.is3D&&!y;return{error:L,isLoading:y,showImage:T,showCanvas:_}},[b.error,b.isLoaded,S,A.backgroundImage,A.is3D]),N=u.useMemo(()=>({opacity:1,backgroundColor:!(s!=null&&s.background.transparent)&&(s==null?void 0:s.type)===c.PreviewType.TEXTURE?s.background.color:void 0}),[s]),I=u.useMemo(()=>({width:`${e}px`,height:`${t}px`}),[e,t]),f=u.useMemo(()=>({width:Math.round(e*A.pixelRatio),height:Math.round(t*A.pixelRatio)}),[e,t,A.pixelRatio]),g=u.useMemo(()=>G("Preview",{"is-loading":w.isLoading,"is-loaded":b.isLoaded,"is-3d":A.is3D,"has-error":!!w.error,"no-fade-effect":!!m.disableFadeEffect}),[w.isLoading,b.isLoaded,A.is3D,w.error,m.disableFadeEffect]),R=u.useMemo(()=>G("thumbnail",{"is-visible":w.showImage}),[w.showImage]),B=u.useMemo(()=>G({"is-visible":w.showCanvas}),[w.showCanvas]);return F.jsxs("div",{className:g,style:N,children:[F.jsx("img",{src:A.backgroundImage,className:R,alt:"preview"}),F.jsx("canvas",{ref:d.canvas,id:At,className:B,width:f.width,height:f.height,style:I}),w.error&&F.jsx("div",{className:"error",children:w.error})]})},vt=_e.memo(Ct);export{Rt as UnityMessageType,vt as default};
|