1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3415],{4145:function(e,t,o){o.d(t,{AnalyticsProvider:function(){return k},_:function(){return w},z:function(){return b}});var a=o(7437),i=o(2265),n=o(2185);class r{enqueue(e){if(this.queue.push(e),this.queue.length>=this.opts.maxSize)return this.flushNow();this.timer||(this.timer=setTimeout(()=>this.flushNow(),this.opts.flushMs))}flushNow(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),0===this.queue.length)return;let e=this.queue;this.queue=[],this.opts.send(e)}constructor(e){this.opts=e,this.queue=[],this.timer=null}}let s="/api/t";function l(e){if("undefined"==typeof navigator||0===e.length)return;let t=JSON.stringify(e);if("function"==typeof navigator.sendBeacon){navigator.sendBeacon(s,new Blob([t],{type:"application/json"}));return}"function"==typeof fetch&&fetch(s,{method:"POST",body:t,headers:{"Content-Type":"application/json"},keepalive:!0}).catch(()=>{})}let c=null;var u=o(6095);let p="ms_aid";function d(e){return"/internetbedroom"===e||"/internetbedroom/"===e?"landing":(0,u.vU)(e)?"quiz_hub":(0,u.$p)(e)?"landing":e.startsWith("/quiz/")?e.replace(/\/$/,"").split("/").length>3?"quiz_result":"quiz":/^\/[^/]+\/screenshot\/?$/.test(e)?"screenshot":/^\/[^/]+\/?$/.test(e)?"share_view":"other"}function m(){return"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}let f="",h="",y="none",v={utm_source:"",utm_medium:"",utm_campaign:""},g=!1;function w(e,t){h=e||"",t&&(y=t)}let _=(0,i.createContext)(null);function b(){return(0,i.useContext)(_)||{trackEvent:()=>{}}}let k=e=>{let{children:t}=e;return(0,i.useEffect)(()=>{!function(){let{id:e,created:t}=function(e,t){let o=function(e,t){if(e)for(let o of e.split(";")){let[e,...a]=o.trim().split("=");if(e===t)return a.join("=")}}(e,p);return o?{id:o,created:!1}:{id:t(),created:!0}}(document.cookie,m);t&&(document.cookie="".concat(p,"=").concat(e,"; Path=/; Max-Age=31536000; SameSite=Lax; Secure"))}()},[]),(0,a.jsx)(_.Provider,{value:{trackEvent:e=>{if("undefined"!=typeof location&&"screenshot"===d(location.pathname))return;try{(function(){if(!c&&(c=new r({maxSize:20,flushMs:5e3,send:l}),"undefined"!=typeof document)){let e=()=>null==c?void 0:c.flushNow();document.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState&&e()}),window.addEventListener("pagehide",e)}return c})().enqueue(function(e){let t="undefined"!=typeof location?location.pathname:"",o="props"in e&&e.props?e.props:{};return{event_id:m(),event_name:e.name,client_ts:new Date().toISOString(),session_id:(f||(f=m()),f),user_id:h,auth_type:y,path:t,page_type:d(t),share_slug:"string"==typeof o.share_slug?o.share_slug:"",referrer_domain:"undefined"!=typeof document?function(e){if(!e)return"";try{return new URL(e).host}catch(e){return""}}(document.referrer):"",language:"undefined"!=typeof navigator?navigator.language:"",...function(){if(!g){g=!0;try{let e=function(e){let t=new URLSearchParams(e||"");return{utm_source:t.get("utm_source")||"",utm_medium:t.get("utm_medium")||"",utm_campaign:t.get("utm_campaign")||""}}(location.search);(e.utm_source||e.utm_medium||e.utm_campaign)&&sessionStorage.setItem("ms_utm",JSON.stringify(e));let t=sessionStorage.getItem("ms_utm");t&&(v=JSON.parse(t))}catch(e){}}return v}(),props:JSON.stringify(o)}}(e))}catch(e){console.error("[analytics] enqueue failed",e)}let t=window.innerWidth<768?"mobile":"desktop",o="props"in e&&e.props?e.props:{},a={agent:t};for(let[e,t]of Object.entries(o))a[e]=null===t||["string","number","boolean"].includes(typeof t)?t:JSON.stringify(t);(0,n.j)(e.name,a)}},children:t})}},3415:function(e,t,o){o.d(t,{AppProvider:function(){return k},q:function(){return b}});var a=o(7437),i=o(9526),n=o(2265),r=o(4145),s=o(7776),l=o(9618),c=o(9005);async function u(e){let t=await e.api.music("v1/me/recent/played/tracks");return console.log("res",t),await t.data.data.map(e=>{var t,o,a,i,n;let{attributes:r}=e;return{isrc:r.isrc,url:r.url,image_url:h(null!==(i=null===(t=r.artwork)||void 0===t?void 0:t.url)&&void 0!==i?i:""),preview_url:null!==(n=null===(a=r.previews)||void 0===a?void 0:null===(o=a.at(0))||void 0===o?void 0:o.url)&&void 0!==n?n:"",title:r.name,artist:r.artistName}})}async function p(e){return function(e){let t=new Map;for(let{attributes:n}of e){var o,a,i;let e=null==n?void 0:n.artistName;if(!e)continue;let r=null!==(i=null===(o=n.genreNames)||void 0===o?void 0:o.map(e=>e.toLowerCase()))&&void 0!==i?i:[],s=(null===(a=n.artwork)||void 0===a?void 0:a.url)?h(n.artwork.url):"",l=t.get(e);if(l){for(let e of(l.count++,r))l.genres.includes(e)||l.genres.push(e);!l.image_url&&s&&(l.image_url=s)}else t.set(e,{name:e,genres:r,image_url:s,count:1})}return Array.from(t.values()).sort((e,t)=>
1t.count-e.count).map(e=>{let{count:t,...o}=e;return o})}((await e.api.music("v1/me/recent/played/tracks")).data.data)}let d={rap:"pl.87c7af5767764860a0e3368d0bef9a6f",pop:"pl.5ee8333dbe944d9f9151e97d92d1ead9",edm:"pl.d66feecbd40d423d81e8e643e368291a",country:"pl.87bb5b36a9bd49db8c975607452bfa2b",indie:"pl.0e91490f3310408eb1186fc9befb3d11",rock:"pl.0b593f1142b84a50a2c1e7088b3fb683",kpop:"pl.48229b41bbfc47d7af39dae8e8b5276e",reggaeton:"pl.5e1bae7879a34b2ab53f10191b65fe2b"};async function m(e){try{let t=d[e]||d.pop,o=await fetch("https://api.music.apple.com/v1/catalog/us/playlists/".concat(t,"/tracks"),{headers:{Authorization:"Bearer ".concat("eyJhbGciOiJFUzI1NiIsImtpZCI6IjI1RzMzTEozUDMiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiIyTEdKNFRYMzYzIiwiZXhwIjoxNzkzODE0Mzk0LCJpYXQiOjE3NzgyNTg3OTR9.2jx-G8G7eu1rJ20aV0Ho7vvdoZRM0LdbimmbcjoCH98ID8XY3GiAz5yjdzIg5Oed471mMV_CIQ01W4Werq4upA")}});if(!o.ok)throw Error("".concat(o.status," Apple Music API: ").concat(await o.text()));return(await o.json()).data.map(e=>{var t,o,a,i,n;return{isrc:e.attributes.isrc,title:e.attributes.name,url:e.attributes.url,preview_url:null!==(i=null===(o=e.attributes.previews)||void 0===o?void 0:null===(t=o[0])||void 0===t?void 0:t.url)&&void 0!==i?i:"",artist:e.attributes.artistName,image_url:h(null!==(n=null===(a=e.attributes.artwork)||void 0===a?void 0:a.url)&&void 0!==n?n:"")}})}catch(e){throw console.error("Error fetching playlist tracks:",e),e}}class f{}f.getUserTopTracks=u,f.getUserTopArtists=p,f.getPlaylistTracks=m;let h=e=>e.replace("{w}x{h}","200x200"),y=["3cdf5f8a91d941d49dd6a06475463bf0","20f462645e8f43c19f1d4b7540520598","deaf1024e3b94f11a42310dfac77db40","fec77bedbbef41f3afc8d77b182407b1"];var v=o(3932),g=o(6095),w=o(8845);let _=(0,n.createContext)(null),b=()=>{let e=(0,n.useContext)(_);if(!e)throw Error("useApp must be used within AppProvider");return e},k=e=>{var t,o,u,p,d,m;let{children:h}=e,{trackEvent:b}=(0,r.z)(),k=(0,c.L)(),S=function(){let[e,t]=(0,n.useState)(null);return(0,n.useEffect)(()=>{let e=localStorage.getItem("apiKeyIndex");if(null===e){let e=Math.floor(3*Math.random());console.log("storage empty. app:",e),localStorage.setItem("apiKeyIndex",e.toString()),t(e)}else console.log("loaded from storage. app:",e),t(parseInt(e,10))},[]),e}
1(),[I,T]=(0,n.useState)({status:"init",authType:"spotify",spotify:{code:null,accessToken:null,user:null,authorized:!1},modalOpen:!1,mobileShareSheetOpen:!1,claimPopupOpen:!1,unsaved:!0,lastEditTime:Date.now(),previewSavedAt:0,paymentModalOpen:!1,hasCompletedPayment:!1,rateLimitModalOpen:!1,spotifyPremiumAuthModalOpen:!1}),O=(0,n.useRef)(null),z=(null===(t=I.stripe)||void 0===t?void 0:t.paymentVerified)?3:S,E=e=>{let t=["madeonverse.com","myinternetbedroom.com","internetbedroom.com"].includes(window.location.hostname.replace(/^www\./,""))?"https://madeonverse.com/":"".concat((0,l.yd)(window.location.origin),"/"),o=new URLSearchParams({client_id:y[z],response_type:"code",redirect_uri:t,scope:i.WI.scopes});(null==e?void 0:e.forceDialog)&&o.set("show_dialog","true"),window.location.href="https://accounts.spotify.com/authorize?".concat(o.toString())},j=async e=>{let t=await fetch("/api/spotify-access-token?code=".concat(e,"&app=").concat(z));if(429===t.status)throw Error("rate limit");await t.json().then(async t=>{let o=await i.WI.getUser(t.access_token);(0,r._)(o.id,"spotify"),b({name:"auth_completed",props:{provider:"spotify"}}),b({name:"identify",props:{provider:"spotify"}}),T({...I,status:"generating",spotify:{...I.spotify,code:e,accessToken:t.access_token,user:o,authorized:!0}}),localStorage.setItem("spotify_user",JSON.stringify({id:o.id,code:e,accessToken:t.access_token,refreshToken:t.refresh_token,appIdx:z,user:o,authorized:!0})),console.log("local storage updated",o.id)}).catch(e=>{throw console.log("spotify error",e),localStorage.clear(),e})},M=async()=>{var e,t;let o=JSON.parse(localStorage.getItem("spotify_user")||"null");if(!(null==o?void 0:o.refreshToken)||!(null==o?void 0:o.user))throw Error("no resumable session");let a=await fetch("/api/spotify-refresh-token?refreshToken=".concat(encodeURIComponent(o.refreshToken),"&app=").concat(null!==(e=o.appIdx)&&void 0!==e?e:0));if(429===a.status)throw Error("rate limit");let i=await a.json();if(!a.ok||!i.access_token)throw Error("refresh failed");let n=o.user;(0,r._)(n.id,"spotify"),localStorage.setItem("spotify_user",JSON.stringify({...o,accessToken:i.access_token,refreshToken:null!==(t=i.refresh_token)&&void 0!==t?t:o.refreshToken})),T(e=>({...e,status:"generating",spotify:{...e.spotify,code:null,accessToken:i.access_token,user:n,authorized:!0}}))},A=async()=>{var e;return b({name:"auth_started",props:{provider:"apple"}}),await (null===(e=k.music)||void 0===e?void 0:e.authorize().then(()=>{let e="AP".concat((0,l.O1)(10));(0,r._)(e,"apple"),b({name:"auth_completed",props:{provider:"apple"}}),b({name:"identify",props:{provider:"apple"}}),localStorage.setItem("apple_user_id",e),console.log("local storage updated",e),T(t=>({...t,status:"generating",authType:"apple",apple:{authorized:!0,hash:e}}))}).catch(e=>{b({name:"auth_failed",props:{provider:"apple",reason:e.message}}),s.Am.error("Auth Failed. If you are in private mode, please try again in a normal tab.")}))},N=async()=>{b({name:"generate_started",props:{provider:"spotify"===I.authType?"spotify":"apple"}});let e=async()=>{if("spotify"===I.authType){var e,t;return fetch("/api/generate-space?accessToken=".concat(I.spotify.accessToken,"&displayName=").concat(encodeURIComponent((null===(e=I.spotify.user)||void 0===e?void 0:e.display_name)||""),"&spotifyUserId=").concat(encodeURIComponent((null===(t=I.spotify.user)||void 0===t?void 0:t.id)||"")))}{let[e,t]=await Promise.all([f.getUserTopArtists(k.music),f.getUserTopTracks(k.music)]);return fetch("/api/generate-space",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({artists:e,tracks:t})})}};await e().then(e=>{if(200!==e.status){let t;throw console.log("spotify error",e),429===e.status?(b({name:"rate_limited",props:{source:"generating-space",is_premium_key:3===z}}
1),t="We are experiencing crazy traffic right now! Please try again later.",V()):(t="Something went wrong with generating your internet bedroom. Please try again later!",T(e=>({...e,status:"error",error:t}))),Error(t)}return e.json()}).then(e=>{var t,o,a,i,n,r,s;let l=null!==(a=null==e?void 0:e.space)&&void 0!==a?a:e,c=null==e?void 0:e.musicData,u=null==e?void 0:e.mode,p=null==e?void 0:e.artistRoomName,d=!!p&&"refreshed"!==u&&"cached"!==u,m=d?"ib_artist_reveal_seen:".concat(null!==(i=null==l?void 0:l.style)&&void 0!==i?i:p):null,f=!!m&&"1"===localStorage.getItem(m),h=null!==(n=null==e?void 0:e.unlockTheme)&&void 0!==n?n:null,y=null==e?void 0:e.newTopArtist,v=!h&&d&&!f,g=h?{name:h.name}:v?{name:p,image:null==c?void 0:null===(o=c.top_artists)||void 0===o?void 0:null===(t=o[0])||void 0===t?void 0:t.image_url}:y?{name:y.name,image:null!==(r=y.image)&&void 0!==r?r:void 0,isNewTopArtist:!0}:null;v&&m&&localStorage.setItem(m,"1");let w=null!==(s=null==e?void 0:e.newlyUnlocked)&&void 0!==s?s:[],_=null==e?void 0:e.coinsEarned,k="ib_unlock_reveal_seen:".concat(new Date().toISOString().slice(0,10)),S="1"===localStorage.getItem(k),I="1"===localStorage.getItem("ib_unlock_intro_seen"),O="generated"===u,z=(O?I:"cached"===u||S)?[]:w;z.length&&(localStorage.setItem(O?"ib_unlock_intro_seen":k,"1"),b({name:"unlock_reveal_shown",props:{count:z.length,generation_mode:u,is_artist_room:!!p,has_featured_artist_asset:z.some(e=>!!e.artistImage),reveal_source:O?"intro":"daily"}})),localStorage.setItem("space_json",JSON.stringify(l)),console.log("stored space json",JSON.stringify(l)),T(e=>({...e,space:l,musicData:c,generationMode:u,revealArtist:g,unlockTheme:h,newlyUnlocked:z,coinsEarned:_,unsaved:"cached"!==u,previewSavedAt:0}))}).catch(e=>{console.error("Error generating space:",e),T(t=>({...t,status:"error",error:e.message}))})},P=async function(){let e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"edit";if(!I.unsaved)return console.log("skipping save. no changes."),{saved:!1,versionId:null};let o=Date.now();if("spotify"===I.authType){let o=I.spotify.user;if(!o)throw Error("no spotify user");e={spotifyUserId:o.id,email:o.email||null,displayName:o.display_name||null,imageUrl:o.image_url||null,authType:"spotify",space:I.space,musicData:I.musicData,source:t}}else{var a;e={spotifyUserId:null===(a=I.apple)||void 0===a?void 0:a.hash,email:null,displayName:null,imageUrl:null,authType:"apple",space:I.space,musicData:I.musicData,source:t}}return{saved:!0,versionId:await fetch("/api/save-space",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(async e=>{var t;if(!e.ok)throw Error("save failed: ".concat(e.status));let a=await e.json().catch(()=>null);return console.log("db save"),T(e=>({...e,unsaved:e.lastEditTime>o})),(0,l.Je)({message:"Space saved!",type:"success"}),null!==(t=null==a?void 0:a.versionId)&&void 0!==t?t:null}).catch(e=>(console.error(e),null))}},U=(0,n.useRef)(P);U.current=P;let C=(0,n.useRef)(I.handle);C.current=I.handle,(0,n.useEffect)(()=>{var e,t;if("complete"!==I.status||!I.unsaved)return;let o="spotify"===I.authType?null===(e=I.spotify.user)||void 0===e?void 0:e.id:null===(t=I.apple)||void 0===t?void 0:t.hash;if(!o)return;let a=window.location.pathname,i=(0,g.$p)(a)?"":a.replace(/^\//,"");if(!(0,v.Y9)(i,o,I.handle))return;let n=setTimeout(()=>{U.current("autosave")},1500);return()=>clearTimeout(n)},[I.status,I.unsaved,I.lastEditTime,I.authType,null===(o=I.spotify.user)||void 0===o?void 0:o.id,null===(u=I.apple)||void 0===u?void 0:u.hash,I.handle]);let x=async function(e){var t;let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now(),a=new File([e],"internet-bedroom.jpg",{type:"image/jpeg"}),i=new FormData;i.append("image",a);let n="/api/upload-image?".concat("spotify"===I.authType?"userId=".concat(I.spotify.user.id):"hash=".concat(null===(t=I.apple)||void 0===t?void 0:t.hash)),r=await fetch(n,{method:"POST",body:i});if(!r.ok)throw console.log("s3 image save failed"),Error((await r.json()).error||"Failed to upload image");console.log("s3 image save"),T(e=>({...e,previewSavedAt:o})),(0,l.Je)({message:"Preview image saved!",type:"success"})},J=async(e,t)=>{let o=new File([e],"room-version.jpg",{type:"image/jpeg"}),a=new FormData;a.append("image",o),await fetch("/api/save-version-screenshot?versionId=".concat(encodeURIComponent(t)),{method:"POST",body:a}).catch(console.error)},R=async()=>
1{if("spotify"===I.authType&&!I.spotify.user){(0,l.Je)({message:"could not generate image, no spotify user",type:"error"});return}console.log("generating a ".concat("fresh"," preview image")),(0,l.Je)({message:"generating a ".concat("fresh"," preview image"),type:"info"});let e="spotify"===I.authType?I.spotify.user.id:I.apple.hash,t="".concat("https://internetbedroom.com","/").concat(e,"/screenshot");return await fetch("/api/generate-image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clipX:0,clipY:0,clipWidth:452,clipHeight:804,url:t})}).then(e=>(console.log("".concat("fresh"," image generated")),e.blob()))},L=async()=>{let e=Date.now(),t=I.lastEditTime>I.previewSavedAt,{versionId:o}=await P();await R().then(a=>{t&&x(a,e),o&&a&&J(a,o);let i=document.createElement("a");i.download="internet-bedroom.jpg",i.href=URL.createObjectURL(a),i.click(),URL.revokeObjectURL(i.href),i.remove()})},D=async()=>{var e,t;let o=Date.now(),a=I.lastEditTime>I.previewSavedAt;P().then(e=>{let{versionId:t}=e;a&&R().then(e=>{x(e,o),t&&e&&J(e,t)})});let i="spotify"===I.authType?null===(e=I.spotify.user)||void 0===e?void 0:e.id:null===(t=I.apple)||void 0===t?void 0:t.hash,n="".concat(window.location.origin,"/").concat((0,v.eL)(I.handle,i));await navigator.clipboard.writeText(n)},q=async()=>{let e=Date.now(),{versionId:t}=await P(),o=await R();await x(o,e),t&&o&&await J(o,t)},V=()=>{b({name:"payment_modal_shown",props:{source:"rate limit"}}),localStorage.setItem("payment_type","premium"),console.log("setting payment_type to premium"),T(e=>({...e,rateLimitModalOpen:!0}))},K="spotify"===I.authType&&!!(null===(p=I.spotify.user)||void 0===p?void 0:p.id)&&(null===I.handle||(0,v.Ri)());(0,n.useEffect)(()=>{var e;let t="spotify"===I.authType?null===(e=I.spotify.user)||void 0===e?void 0:e.id:void 0;t&&void 0===I.handle&&fetch("/api/get-handle?userId=".concat(encodeURIComponent(t))).then(e=>e.json()).then(e=>T(t=>({...t,handle:"string"==typeof(null==e?void 0:e.handle)?e.handle:null}))).catch(()=>{})},[I.authType,null===(d=I.spotify.user)||void 0===d?void 0:d.id,I.handle]),(0,n.useEffect)(()=>{var e;let t=I.handle,o="spotify"===I.authType?null===(e=I.spotify.user)||void 0===e?void 0:e.id:void 0;t&&o&&window.location.pathname.replace(/^\//,"")===o&&window.history.replaceState(null,document.title,"".concat(window.location.origin,"/").concat(t))},[I.handle,I.authType,null===(m=I.spotify.user)||void 0===m?void 0:m.id]);let Y=async()=>{var e;let t=null===(e=I.stripe)||void 0===e?void 0:e.sessionId;fetch("/api/checkout?session_id=".concat(t),{method:"GET"}).then(e=>e.json()).then(e=>{let o=e.customer_email,a=localStorage.getItem("payment_type");if(b({name:"payment_completed",props:{type:a}}),"customization"===a){let e=localStorage.getItem("space_json"),a=e?JSON.parse(e):null,r=JSON.parse(localStorage.getItem("spotify_user")||"null"),s=localStorage.getItem("apple_user_id");a&&s?T({...I,space:a,status:"complete",authType:"apple",apple:{authorized:!0,hash:s},stripe:{sessionId:t,paymentVerified:!0,email:o},hasCompletedPayment:!0}):a&&r?T({...I,space:a,status:"complete",authType:"apple",spotify:r,stripe:{sessionId:t,paymentVerified:!0,email:o},hasCompletedPayment:!0}):console.warn("No space-json found in localStorage");{var i,n;let e="spotify"===I.authType?null===(i=I.spotify.user)||void 0===i?void 0:i.id:null===(n=I.apple)||void 0===n?void 0:n.hash;window.history.pushState(null,document.title,"".concat(window.location.origin,"/").concat(e))}}else"premium"===a&&(localStorage.setItem("paymentVerified","true"),T({...I,status:"premium-spotify-confirmation",stripe:{sessionId:t,paymentVerified:!0,email:o},spotifyPremiumAuthModalOpen:!0}))}).catch(()=>{T({...I,status:"init",stripe:void 0}),s.Am.error("payment failed, you have not been charged")})};return(0,n.useEffect)(()=>{if(!(0,g.$p)(window.location.pathname))return;let e=new URLSearchParams(window.location.search),t=e.get("code"),o=e.get("session_id"),a="true"===localStorage.getItem("paymentVerified"),i=localStorage.getItem("payment_type"),n=JSON.parse(localStorage.getItem("spotify_user")||"null");console.log("localStorage paymentVerified",a),console.log("localStorage paymentType",i),window.history.replaceState({},document.title,window.location.pathname),o?T({...I,status:"verifying-payment",stripe:{sessionId:o,paymentVerified:!1}}):t?T({...I,spotify:{...I.spotify,code:t},stripe:{paymentVerified:a},status:"unauthorized"}):(null==n?void 0:n.refreshToken)&&(null==n?void 0:n.user)?T({...I,spotify:{code:null,accessToken:null,user:n.user,authorized:!1},stripe:{paymentVerified:a},status:"unauthorized"}):T({...I,stripe:{paymentVerified:a},status:"need-spotify-code"})},[]),(0,n.useEffect)(()=>
1{if("unauthorized"===I.status){let e=!I.spotify.code;(e?M():j(I.spotify.code)).catch(t=>{"rate limit"===t.message?(b({name:"rate_limited",props:{source:"auth",is_premium_key:3===z}}),T(e=>({...e,status:"need-spotify-code"})),V()):(console.error(t),e?(localStorage.removeItem("spotify_user"),T(e=>({...e,status:"need-spotify-code"}))):(T({...I,status:"need-spotify-code"}),s.Am.error("Failed to connect, please refresh & try again."),b({name:"auth_failed",props:{provider:"spotify",reason:t.message}})))})}else if("generating"===I.status)N().catch(e=>{T({...I,status:"error",error:e.message})});else if("complete"===I.status){var e,t,o,a,i,n,r;let l="spotify"===I.authType?null===(e=I.spotify.user)||void 0===e?void 0:e.id:null===(t=I.apple)||void 0===t?void 0:t.hash,c=window.location.pathname.replace(/^\//,"");if(b({name:"reveal_complete",props:{style:null===(o=I.space)||void 0===o?void 0:o.style,generation_mode:I.generationMode,is_owner:(0,v.Y9)(c,l,I.handle),room_version_ts:null===(a=I.space)||void 0===a?void 0:a.last_generated_at,unlock_count:null!==(n=null===(i=I.newlyUnlocked)||void 0===i?void 0:i.length)&&void 0!==n?n:0,has_artist_asset:(null!==(r=I.newlyUnlocked)&&void 0!==r?r:[]).some(e=>!!e.artistImage)}}),(0,g.$p)(window.location.pathname)){let e=()=>{{var e,t;let o="spotify"===I.authType?null===(e=I.spotify.user)||void 0===e?void 0:e.id:null===(t=I.apple)||void 0===t?void 0:t.hash,a=(0,v.eL)(C.current,o);window.history.pushState(null,document.title,"".concat(window.location.origin,"/").concat(a))}};"cached"===I.generationMode?e():P("refreshed"===I.generationMode||"theme-unlock"===I.generationMode?"daily":"generate").then(t=>{let{versionId:o}=t;R().then(e=>{x(e),o&&e&&J(e,o)}),e()}).catch(e=>{s.Am.error("failed to save")})}}else"verifying-payment"===I.status&&Y()},[I.status]),(0,a.jsx)(_.Provider,{value:{state:I,spaceCanvasRef:O,requestAuth:E,switchSpotifyAccount:()=>{b({name:"auth_started",props:{provider:"spotify",cta_location:"switch_account"}}),localStorage.removeItem("spotify_user"),localStorage.removeItem("space_json"),E({forceDialog:!0})},download:L,copyLink:D,mobileUpdateShareAsset:q,setState:T,openModal:()=>{b({name:"download_app_clicked",props:{placement:"qr_code"}}),T({...I,modalOpen:!0})},closeModal:()=>T({...I,modalOpen:!1}),openMobileShareSheet:e=>{b({name:"mobile_share_opened",props:{platform:"web_moonshot",source:"daily_timer"===e||"claim_popup"===e?e:"room"}}),T({...I,mobileShareSheetOpen:!0})},closeMobileShareSheet:()=>T({...I,mobileShareSheetOpen:!1}),openClaimPopup:()=>T(e=>({...e,claimPopupOpen:!0})),closeClaimPopup:()=>T(e=>({...e,claimPopupOpen:!1})),setHandle:e=>T(t=>({...t,handle:e})),needsHandleClaim:K,authorizeAppleMusic:A,openPaymentModal:()=>{var e;b({name:"payment_modal_shown",props:{source:"customization",bedroomStyle:null===(e=I.space)||void 0===e?void 0:e.style}}),localStorage.setItem("payment_type","customization"),console.log("setting payment_type to customization"),T({...I,paymentModalOpen:!0})},closePaymentModal:()=>T({...I,paymentModalOpen:!1}),openRateLimitModal:V,closeRateLimitModal:()=>T({...I,rateLimitModalOpen:!1}),redecorateNewTheme:()=>{let e=I.unlockTheme;e&&(b({name:"daily_theme_choice",props:{action:"redecorate",style:e.slug}}),T(t=>t.space?{...t,space:(0,w._)(t.space,e.layout,e.slug),unsaved:!0,lastEditTime:Date.now(),status:"complete",unlockTheme:null}:{...t,status:"complete",unlockTheme:null}))},keepPreviousRoom:()=>{I.unlockTheme&&b({name:"daily_theme_choice",props:{action:"keep",style:I.unlockTheme.slug}}),T(e=>({...e,status:"complete",unlockTheme:null}))}},children:h})}},9005:function(e,t,o){o.d(t,{AppleMusicProvider:function(){return l},L:function(){return s}});var a=o(7437),i=o(1877),n=o(2265);let r=(0,n.createContext)(null),s=()=>{let e=(0,n.useContext)(r);if(!e)throw Error("useGlobalAudioContext must be used within a GlobalAudioContext.Provider");return e},l=e=>{let{children:t}=e,[o,s]=(0,n.useState)(null),l=(0,n.useRef)(!1),c=async()=>{if(!l.current&&window.MusicKit){console.log("Configuring MusicKit");try{await window.MusicKit.configure({developerToken:"eyJhbGciOiJFUzI1NiIsImtpZCI6IjI1RzMzTEozUDMiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiIyTEdKNFRYMzYzIiwiZXhwIjoxNzkzODE0Mzk0LCJpYXQiOjE3NzgyNTg3OTR9.2jx-G8G7eu1rJ20aV0Ho7vvdoZRM0LdbimmbcjoCH98ID8XY3GiAz5yjdzIg5Oed471mMV_CIQ01W4Werq4upA",app:{n
1ame:"Spaces",build:"1.0"}}),s(window.MusicKit.getInstance()),l.current=!0}catch(e){console.error("Error configuring MusicKit:",e)}}};return(0,n.useEffect)(()=>{let e=()=>{window.MusicKit?c():setTimeout(e,100)};return e(),()=>{l.current=!0}},[]),(0,a.jsxs)(r.Provider,{value:{music:o},children:[(0,a.jsx)(i.default,{src:"https://js-cdn.music.apple.com/musickit/v3/musickit.js",strategy:"afterInteractive",async:!0}),t]})}},8845:function(e,t,o){o.d(t,{_:function(){return i}});let a=(e,t)=>e.find(e=>e.placeholder_key===t);function i(e,t,o){var i,n;let r=JSON.parse(JSON.stringify(t));for(let t=0;t<6;t++){let o=a(e.elements,"track:".concat(t)),i=a(r.elements,"track:".concat(t));(null==o?void 0:o.data.track)&&(null==i?void 0:i.data)&&(i.data.track=o.data.track)}let s=a(e.elements,"poster"),l=a(r.elements,"poster");(null==s?void 0:null===(i=s.data.image)||void 0===i?void 0:i.url)&&(null==l?void 0:l.data.image)&&(l.data.image.url=s.data.image.url);let c=a(e.elements,"name"),u=a(r.elements,"name");return(null==c?void 0:null===(n=c.data.text)||void 0===n?void 0:n.body)!==void 0&&(null==u?void 0:u.data.text)&&(u.data.text.body=c.data.text.body),r.hero_track=e.hero_track,r.last_generated_at=e.last_generated_at,r.style="".concat(o,"-template.json"),r}},3932:function(e,t,o){o.d(t,{BJ:function(){return s},QX:function(){return n},Ri:function(){return p},Xm:function(){return l},Y9:function(){return u},bS:function(){return a},dl:function(){return c},eL:function(){return r}});let a=25,i=/^[a-z0-9]{1,25}$/,n="internetbedroom.com";function r(e,t){return e||(null!=t?t:"")}function s(e){return(null!=e?e:"").toLowerCase().replace(/[^a-z0-9]/g,"").slice(0,a)}function l(e){return i.test(e)}function c(e){let t=e;try{t=decodeURIComponent(e)}catch(e){}let o=t.replace(/^@/,"").toLowerCase();return i.test(o)?o:null}function u(e,t,o){return!e||!!t&&e===t||!!o&&c(e)===o}function p(){try{return"1"===localStorage.getItem("force_claim_popup")}catch(e){return!1}}},6095:function(e,t,o){function a(e){return"/"===e||""===e}o.d(t,{$p:function(){return a},t7:function(){return i},vU:function(){return n}});let i="/quizzes";function n(e){return e===i||e==="".concat(i,"/")}},9526:function(e,t,o){async function a(e){try{var t;let o=await fetch("https://api.spotify.com/v1/me/",{headers:{Authorization:"Bearer ".concat(e)}});if(!o.ok){if(429===o.status)throw console.log("spotify rate limited"),Error("rate limit");throw Error("".concat(o.status," Spotify API: ").concat(await o.text()))}let a=await o.json();return{id:a.id,display_name:a.display_name,image_url:null===(t=a.images[0])||void 0===t?void 0:t.url,email:a.email}}catch(e){throw console.error("Error fetching user",e),e}}async function i(e){try{let t=await fetch("https://api.spotify.com/v1/me/top/tracks?time_range=medium_term&limit=10",{headers:{Authorization:"Bearer ".concat(e)}});if(!t.ok){if(429===t.status)throw console.log("spotify rate limited"),Error("rate limit");throw Error("".concat(t.status," Spotify API: ").concat(await t.text()))}return(await t.json()).items.map(e=>{var t,o;return{isrc:null===(t=e.external_ids)||void 0===t?void 0:t.isrc,title:e.name,preview_url:e.preview_url,artist:e.artists.map(e=>e.name).join(", "),image_url:null===(o=e.album.images[0])||void 0===o?void 0:o.url}})}catch(e){throw console.error("Error fetching top tracks:",e),e}}async function n(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"medium_term";try{let o=await fetch("https://api.spotify.com/v1/me/top/artists?time_range=".concat(t,"&limit=5"),{headers:{Authorization:"Bearer ".concat(e)}});if(!o.ok){if(429===o.status)throw console.log("spotify rate limited"),Error("rate limit");throw Error("".concat(o.status," Spotify API: ").concat(await o.text()))}return(await o.json()).items.map(e=>{var t;return{name:e.name,genres:e.genres,image_url:null===(t=e.images[0])||void 0===t?void 0:t.url}})}catch(e){throw console.error("Error fetching top artists:",e),e}}async function r(e){try{var t;let o=await fetch("https://api.spotify.com/v1/me/player/recently-played?limit=50",{headers:{Authorization:"Bearer ".concat(e)}});if(!o.ok){if(429===o.status)throw console.log("spotify rate limited"),Error("rate limit");throw Error("".concat(o.status," Spotify API: ").concat(await o.text()))}let a=await o.json();return(null!==(t=a.items)&&void 0!==t?t:[]).map(e=>{var t,o;return{played_at:e.played_at,track:{isrc:null===(t=e.track.external_ids)||void 0===t?void 0:t.isrc,title:e.track.name,preview_url:e.track.preview_url,artist:e.track.artists.map(e=>e.name).join(", "),image_url:null===(o=e.track.album.images[0])||void 0===o?void 0:o.url}}})}catch(e){throw console.error("Error fetching recently played:",e),e}}o.d(t,{WI:function(){return s}});class s{}s.scopes="user-top-read user-read-recently-played playlist-modify-private playlist-read-collaborative playlist-modify-public playlist-read-private user-library-modify user-library-read user-read-private user-read-email",s.getUser=a,s.getUserTopTracks=i,s.getUserTopArtists=n,s.getUserRecentlyPlayed=r},9618:function(e,t,o){o.d(t,{Je:function(){return i},O1:function(){return r},aQ:function(){return n},ee:function(){return a},yd:function(){return s}}),o(1642),o(7776),o(357);let a=e=>{let t,{amplitude:o,frequency:a,phase:i,dampeningReductionFactor:n,discretePoints:r}=e,s=[];for(let e=0;e<r;e++)s.push(o*Math.sin(t=2*Math.PI*e/r*a+i)/(1+n*t));return s},i=e=>{},n=e=>"".concat(100*e,"%");function r(e){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",o="",a=t.length;for(let i=0;i<e;i++)o+=t.charAt(Math.floor(Math.random()*a));return o}function s(e){return e.replace("www.","")}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.