@dcl/wearable-preview 2.10.2-22931365632.commit-accd8e4 → 2.11.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-COOIY_e7.js → Preview-CssWHr0S.js} +3 -3
- package/assets/UnityPreview-CMaqDuN5.js +1 -0
- package/assets/{babylon.inspector.bundle.max-rkZvcb6W.js → babylon.inspector.bundle.max-Bo2GpqVq.js} +1 -1
- package/assets/{index-B-zvrSa6.js → index-B73y5Fr2.js} +3 -3
- package/assets/{useController-BMlq20pQ.js → useController-CM3TBLFm.js} +1 -1
- package/index.html +3 -3
- package/package.json +2 -2
- package/static-local/assets/{Preview-kQ1b4Ick.js → Preview-Cf7ilJ0M.js} +3 -3
- package/static-local/assets/{UnityPreview-Bv8im4mb.js → UnityPreview-lk2FyjMB.js} +1 -1
- package/static-local/assets/{babylon.inspector.bundle.max-C-uJj2QM.js → babylon.inspector.bundle.max-D9mX-XCO.js} +1 -1
- package/static-local/assets/{index-C9dRmbD1.js → index-BqDxiF8C.js} +2 -2
- package/static-local/assets/{useController-BForzO16.js → useController-BhngQkaM.js} +1 -1
- package/static-local/index.html +1 -1
- package/static-local/package.json +1 -1
- package/assets/UnityPreview-dUUhVAMC.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as D,a as k,r as c,b as q,R as se,j as U}from"./index-B-zvrSa6.js";import{m as oe,d as i,u as ee,s as ie,f as de,a as ce,b as le,i as ue,g as ge,c as Se,e as z,h as $,j as me,k as Ee,l as fe,n as ye,o as F,p as v}from"./useController-BMlq20pQ.js";var G=(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.RELOAD="Reload",e.CLEANUP="Cleanup",e.GET_ELEMENT_BOUNDS="GetElementBounds",e))(G||{});const pe={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"},we={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)},_=(e,r,n)=>{if(e)try{const t=String(r);Object.values(G).includes(t)||(console.warn(`Unknown Unity method: ${t}. Sending anyway...`),D(`Unknown Unity method: ${t}`,{method:t,value:n})),n!==void 0?e.SendMessage("JSBridge",t,n):e.SendMessage("JSBridge",t)}catch(t){console.error(`Failed to send Unity message ${r}:`,t),k(t,{method:String(r),value:n})}else console.warn(`Unity instance not ready, cannot send message: ${r}`),D(`Unity instance not ready, cannot send message: ${r}`,{method:String(r)})},he=(e,r,n)=>{if(!e){console.warn("Unity instance not available, cannot send override messages"),D("Unity instance not available, cannot send override messages");return}let t=0;r.base64s!==void 0&&n.base64s&&(_(e,"ClearBase64"),t++,Array.isArray(r.base64s)&&r.base64s.length>0&&r.base64s.forEach(a=>{_(e,"AddBase64",a),t++})),Object.entries(r).forEach(([a,s])=>{if(a!=="base64s"&&n[a]&&s!==void 0){const o=pe[a];if(o){const d=we[a],l=d?d(s):String(s);_(e,o,l),t++}else console.warn(`No Unity method mapping found for property: ${a}`),D(`No Unity method mapping found for property: ${a}`,{property:a,value:s})}}),t>0&&_(e,"Reload")};var Re={VITE_BASE_URL:"https://cdn.decentraland.org/@dcl/wearable-preview/2.10.2-22931365632.commit-accd8e4"};const V=new Map,I=(e,r)=>{if(!r)return e;const n=e.replace(/\/$/,""),t=r.replace(/^\//,"");return`${n}/${t}`};function be(e){if(V.has(e))return V.get(e);const r=new Promise((n,t)=>{const a=document.querySelector(`script[src="${e}"]`);if(a){a.addEventListener("load",()=>n(a)),a.addEventListener("error",o=>t(o));return}const s=document.createElement("script");s.src=e,s.async=!0,s.onload=()=>n(s),s.onerror=o=>t(o),document.body.appendChild(s)});return V.set(e,r),r}const Pe=async(e,r,n,t,a,s,o,d,l,u,g,f)=>{try{const S=Re.VITE_BASE_URL||"";return await be(I(S,r)),await createUnityInstance(e,{dataUrl:I(S,n),frameworkUrl:I(S,t),codeUrl:I(S,a),streamingAssetsUrl:I(S,o),symbolUrl:I(S,s),companyName:d,productName:l,productVersion:u,matchWebGLToCanvasSize:g,arguments:f})}catch(S){throw console.error("❌ Failed to load Unity instance:",S),S}};function Te(e){return{getScreenshot:()=>new Promise(r=>{if(!e){r("");return}e.SendMessage("JSBridge","TakeScreenshot",""),window.addEventListener("message",function n(t){if(t.data.type==="unity-renderer"){const{type:a,payload:s}=t.data.payload;a==="screenshot"&&(window.removeEventListener("message",n),r(s))}})}),getMetrics:()=>new Promise(r=>{if(!e){r({triangles:0,materials:0,textures:0,meshes:0,bodies:0,entities:0});return}e.SendMessage("JSBridge","GetMetrics",""),window.addEventListener("message",function n(t){if(t.data.type==="unity-renderer"){const{type:a,payload:s}=t.data.payload;a==="metrics"&&(window.removeEventListener("message",n),r(s))}})}),changeZoom:async r=>{e&&e.SendMessage("JSBridge","SetZoom",r.toString())},panCamera:async r=>{if(!e)return;const n=r.x??0,t=r.y??0,a=r.z??0;e.SendMessage("JSBridge","SetOffset",`${n},${t},${a}`)},changeCameraPosition:async r=>{if(!e)return;const n=r.alpha??0,t=r.beta??0,a=r.radius??0;e.SendMessage("JSBridge","SetCameraPosition",`${n},${t},${a}`)},setUsername:async r=>{e&&e.SendMessage("JSBridge","SetUsername",r)},cleanup:async()=>{e&&e.SendMessage("JSBridge","Cleanup","")}}}function Le(e){const r=oe();return{getLength:async()=>new Promise(n=>{if(!e){n(0);return}e.SendMessage("JSBridge","GetEmoteLength",""),window.addEventListener("message",function t(a){if(a.data.type==="unity-renderer"){const{type:s,payload:o}=a.data.payload;s==="emoteLength"&&(window.removeEventListener("message",t),n(o))}})}),isPlaying:async()=>new Promise(n=>{if(!e){n(!1);return}e.SendMessage("JSBridge","IsEmotePlaying",""),window.addEventListener("message",function t(a){if(a.data.type==="unity-renderer"){const{type:s,payload:o}=a.data.payload;s==="isEmotePlaying"&&(window.removeEventListener("message",t),n(o))}})}),goTo:async n=>{e&&(e.SendMessage("JSBridge","GoToEmote",n.toString()),r.emit(i.PreviewEmoteEventType.ANIMATION_PLAYING,{length:n}))},play:async()=>{e&&(e.SendMessage("JSBridge","PlayEmote",""),r.emit(i.PreviewEmoteEventType.ANIMATION_PLAY))},pause:async()=>{e&&(e.SendMessage("JSBridge","PauseEmote",""),r.emit(i.PreviewEmoteEventType.ANIMATION_PAUSE))},stop:async()=>{e&&(e.SendMessage("JSBridge","StopEmote",""),r.emit(i.PreviewEmoteEventType.ANIMATION_END))},enableSound:async()=>{e&&e.SendMessage("JSBridge","EnableSound","")},disableSound:async()=>{e&&e.SendMessage("JSBridge","DisableSound","")},hasSound:async()=>new Promise(n=>{if(!e){n(!1);return}e.SendMessage("JSBridge","HasSound",""),window.addEventListener("message",function t(a){if(a.data.type==="unity-renderer"){const{type:s,payload:o}=a.data.payload;s==="hasSound"&&(window.removeEventListener("message",t),n(o))}})}),events:r}}async function ve(e){let r=null;try{if(r=await Pe(e,"/unity/Build/aang-renderer.loader.js","/unity/Build/aang-renderer.data.br","/unity/Build/aang-renderer.framework.js.br","/unity/Build/aang-renderer.wasm.br","/unity/Build/aang-renderer.symbols.json.br","/emotes","Decentraland","AangRenderer","2.2.2",!0,[]),!r)throw new Error("Failed to load Unity instance");const n=Te(r),t=Le(r);return{scene:n,emote:t,unity:r}}catch(n){if(console.error("Unity render failed:",n),r!=null&&r.Quit)try{r.Quit()}catch(t){console.error("Error quitting Unity instance:",t),k(t,{phase:"unityQuit"})}throw n}}const Oe=()=>Math.floor(Math.random()*159)+1,re=()=>`default${Oe()}`,Ie=(e,r)=>{var n,t,a,s,o,d;return{eyes:z(r.eyes||((t=(n=e==null?void 0:e.avatar)==null?void 0:n.eyes)==null?void 0:t.color)&&$(e.avatar.eyes.color)||"#000000"),hair:z(r.hair||((s=(a=e==null?void 0:e.avatar)==null?void 0:a.hair)==null?void 0:s.color)&&$(e.avatar.hair.color)||"#000000"),skin:z(r.skin||((d=(o=e==null?void 0:e.avatar)==null?void 0:o.skin)==null?void 0:d.color)&&$(e.avatar.skin.color)||"#cc9b76")}},A=e=>e||"",K=e=>e||[],B=e=>e.replace("#","");function X(e){const r=new URL(window.location.href);Object.entries(e).forEach(([n,t])=>{r.searchParams.delete(n),Array.isArray(t)?t.forEach(a=>{a!==""&&r.searchParams.append(n,a)}):t!==""&&r.searchParams.set(n,t)}),window.history.replaceState({},"",r.toString())}function Ce(){const{options:e,overrideSources:r}=ee(),[n,t]=c.useState(null),[a,s]=c.useState(!0),[o,d]=c.useState(null),l=c.useRef(null),u=c.useRef(e),g=c.useRef(!0);return c.useEffect(()=>{const f=JSON.stringify(e),S=JSON.stringify(u.current);if(!g.current&&f===S)return;g.current=!1,u.current=e,(async()=>{var m,E;try{s(!0),d(null);const w=e.peerUrl||q.get("PEER_URL"),j=e.marketplaceServerUrl||e.nftServerUrl||q.get("MARKETPLACE_SERVER_URL");let C=i.PreviewType.WEARABLE,P={color:e.background||"#4b4852",transparent:e.disableBackground===!0};const T=ie(e.profile);let h=T==null?void 0:T.value;h==="default"&&(h=re());const y=h&&T?T.type==="address"?await de(h,w):await ce(h,w):null,R=e.bodyShape||((m=y==null?void 0:y.avatar)==null?void 0:m.bodyShape)||i.BodyShape.MALE;let p=null;if(e.contractAddress&&(p=await le({contractAddress:e.contractAddress,tokenId:e.tokenId,itemId:e.itemId,peerUrl:w,marketplaceServerUrl:j}),p&&ue(p))){P={...P,image:p.thumbnail};const M=ge(p);Se(M)&&(C=i.PreviewType.TEXTURE)}const{eyes:L,hair:H,skin:Y}=Ie(y,{eyes:e.eyes,hair:e.hair,skin:e.skin}),N=e.unityMode||null,te=e.camera&&Object.values(i.PreviewCamera).includes(e.camera)?e.camera:i.PreviewCamera.INTERACTIVE,Q=e.projection&&Object.values(i.PreviewProjection).includes(e.projection)?e.projection:i.PreviewProjection.PERSPECTIVE,O=e.disableDefaultEmotes?null:e.emote&&Object.values(i.PreviewEmote).includes(e.emote)?e.emote:i.PreviewEmote.IDLE,x={background:P,bodyShape:R,mode:N,projection:Q,type:C,base64:((E=e.base64s)==null?void 0:E[0])||null,contract:e.contractAddress||null,disableLoader:e.disableLoader||!1,emote:(O==null?void 0:O.toString())||null,eyeColor:L.replace("#",""),hairColor:H.replace("#",""),item:e.itemId||null,profile:h||null,skinColor:Y.replace("#",""),token:e.tokenId||null,urn:e.urns||null,showAnimationReference:null},ne=JSON.stringify(x),ae=JSON.stringify(l.current);if(ne!==ae){if(l.current=x,Object.keys(r).length===0){const M=K(e.urns),W=K(e.base64s);if(N===i.PreviewUnityMode.CONFIG){const J={mode:A(N||"")};X(J)}else{const J={background:P.transparent?"":B(P.color),disableLoader:e.disableLoader?"true":"",profile:A(h||""),bodyShape:A(R||""),eyeColor:B(L||""),hairColor:B(H||""),skinColor:B(Y||""),mode:A(N||""),camera:te,projection:Q,emote:A((O==null?void 0:O.toString())||""),urn:M.length>0?M:[""],base64:W.length>0?W:[""]};X(J)}}t(x)}s(!1)}catch(w){console.error("[useUnityConfig] Failed to load config:",w),d(w instanceof Error?w.message:"Failed to load config"),s(!1)}})()},[e,r]),[n,a,o]}const Ae="unity-renderer",_e="unity-canvas",Z=1,Ne="Failed to load Unity";var Me=(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))(Me||{});const Ue="get_element_bounds",Be="element_bounds_response",De=(e,r,n,t)=>{const[a,s]=c.useState({isLoaded:!1,isInitialized:!1,error:null}),o=c.useCallback(l=>{if(l.data.type===Ae){const{type:u,payload:g}=l.data.payload;u==="loaded"&&(g===!0||g==="true")?(s(f=>({...f,isLoaded:!0,isInitialized:!0})),i.sendMessage(v(),i.PreviewMessageType.LOAD,{renderer:i.PreviewRenderer.UNITY})):u==="customization-done"?i.sendMessage(v(),i.PreviewMessageType.CONTROLLER_RESPONSE,{id:"customization-done",ok:!0,result:JSON.parse(l.data.payload.payload)}):u==="avatar-customization-step"?i.sendMessage(v(),i.PreviewMessageType.CONTROLLER_RESPONSE,{id:"avatar-customization-step",ok:!0,result:{step:l.data.payload.payload}}):u==="element-bounds"?i.sendMessage(v(),Be,g):u==="error"&&(k(new Error(g),{component:"UnityPreview",phase:"unityMessage"}),s(f=>({...f,error:g})),i.sendMessage(v(),i.PreviewMessageType.ERROR,{message:"Error loading the wearable. Please try again."}))}},[]),d=c.useCallback(async()=>{if(!(!e.canvas.current||e.isInitializing.current||e.unityInstance.current)){e.isInitializing.current=!0,s(l=>({...l,isLoaded:!1,error:null}));try{const{unity:l,scene:u,emote:g}=await ve(e.canvas.current);e.unityInstance.current=l,r.current={scene:u,emote:g},s(f=>({...f,isLoaded:!0,isInitialized:!0})),i.sendMessage(v(),i.PreviewMessageType.LOAD,{renderer:i.PreviewRenderer.UNITY})}catch(l){const u=l instanceof Error?l.message:Ne;console.error("Unity init failed:",l),k(l,{component:"UnityPreview",phase:"initializeUnity"}),s(g=>({...g,error:u})),i.sendMessage(v(),i.PreviewMessageType.ERROR,{message:u})}finally{e.isInitializing.current=!1}}},[e,r]);return c.useEffect(()=>{a.isInitialized||t||!n||d()},[n,t,a.isInitialized,d]),c.useEffect(()=>{if(n)return window.addEventListener("message",o,!1),()=>{window.removeEventListener("message",o,!1)}},[n,o]),a},ke=e=>{const[r,n]=c.useState({pixelRatio:window.devicePixelRatio||Z,is3D:!0,backgroundImage:""});return c.useEffect(()=>{const t=()=>{n(s=>({...s,pixelRatio:window.devicePixelRatio||Z}))},a=window.matchMedia(`(resolution: ${r.pixelRatio}dppx)`);return a.addEventListener("change",t),()=>{a.removeEventListener("change",t)}},[r.pixelRatio]),c.useEffect(()=>{e&&n(t=>({...t,backgroundImage:e.background.image||"",is3D:e.type!==i.PreviewType.TEXTURE}))},[e]),r},je=(e,r,n,t,a)=>{const s=c.useMemo(()=>{const o={};for(const d of Object.keys(a))a[d]&&t[d]!==void 0&&(o[d]=t[d]);return o},[a,t]);c.useEffect(()=>{if(!(!n.isInitialized||!n.isLoaded||!e.current)){if(s.profile==="default"){const o=r.current.profile;s.profile=o!=null&&o.match(/^default\d+$/)?o:re()}Object.keys(s).length>0&&(he(e.current,s,a),r.current=s)}},[n.isInitialized,n.isLoaded,s,a,e,r])},xe=()=>{const{width:e=window.innerWidth,height:r=window.innerHeight}=me(),n=c.useRef(null),t=c.useRef(null),a=c.useRef(!1),s=c.useRef({}),o=Ee(),[d,l,u]=Ce(),{options:g,overrideSources:f}=ee(),S=c.useMemo(()=>({canvas:n,unityInstance:t,isInitializing:a,lastSentOverrides:s}),[]);fe(y=>{var R,p;if(((R=y.data)==null?void 0:R.type)===Ue&&t.current){const L=(p=y.data.payload)==null?void 0:p.elementName;L&&_(t.current,G.GET_ELEMENT_BOUNDS,L)}});const b=De(S,o,d,l),m=ke(d);je(S.unityInstance,S.lastSentOverrides,b,g,f),ye();const E=c.useMemo(()=>{const y=b.error||u,R=!b.isLoaded&&!y,p=!!m.backgroundImage&&!m.is3D&&!R,L=m.is3D&&!R;return{error:y,isLoading:R,showImage:p,showCanvas:L}},[b.error,b.isLoaded,u,m.backgroundImage,m.is3D]),w=c.useMemo(()=>({opacity:1,backgroundColor:!(d!=null&&d.background.transparent)&&(d==null?void 0:d.type)===i.PreviewType.TEXTURE?d.background.color:void 0}),[d]),j=c.useMemo(()=>({width:`${e}px`,height:`${r}px`}),[e,r]),C=c.useMemo(()=>({width:Math.round(e*m.pixelRatio),height:Math.round(r*m.pixelRatio)}),[e,r,m.pixelRatio]),P=c.useMemo(()=>F("Preview",{"is-loading":E.isLoading,"is-loaded":b.isLoaded,"is-3d":m.is3D,"has-error":!!E.error}),[E.isLoading,b.isLoaded,m.is3D,E.error]),T=c.useMemo(()=>F("thumbnail",{"is-visible":E.showImage}),[E.showImage]),h=c.useMemo(()=>F({"is-visible":E.showCanvas}),[E.showCanvas]);return U.jsxs("div",{className:P,style:w,children:[U.jsx("img",{src:m.backgroundImage,className:T,alt:"preview"}),U.jsx("canvas",{ref:S.canvas,id:_e,className:h,width:C.width,height:C.height,style:j}),E.error&&U.jsx("div",{className:"error",children:E.error})]})},$e=se.memo(xe);export{Me as UnityMessageType,$e as default};
|