1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="dadf92d2-1f23-4cfa-85d2-4bca19f75da9",e._sentryDebugIdIdentifier="sentry-dbid-dadf92d2-1f23-4cfa-85d2-4bca19f75da9")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[51740],{8649:(e,t,r)=>{r.d(t,{k:()=>i});var n=r(97921);let a={generations:0,videoSeconds:0,publishedViews:0,copies:0},i=(0,n.v)()((e,t)=>({profile:null,credits:[],isLoading:!1,error:null,dailyUsage:{...a},setProfile:t=>e({profile:t}),setCredits:t=>e({credits:t}),setDailyUsage:t=>e(e=>({dailyUsage:{...e.dailyUsage,...t}})),setLoading:t=>e({isLoading:t}),setError:t=>e({error:t}),clearUser:()=>e({profile:null,credits:[],dailyUsage:{...a},error:null}),getCredit:e=>t().credits.find(t=>t.type===e),getTotalCredits:e=>{var r;let n=t().credits.find(t=>t.type===e);return null!=(r=null==n?void 0:n.total)?r:0}}))},8977:(e,t,r)=>{r.d(t,{BJ:()=>n,Gu:()=>p,ZL:()=>f,dX:()=>g,fX:()=>h,hy:()=>u,ij:()=>l,lg:()=>s,wy:()=>c,ym:()=>m});let n={draftCreate:"draft:create",storySettings:"story-settings",onboardingCompleted:"onboarding:completed",onboardingSkipped:"onboarding:skipped",onboardingDismissed:"onboarding:dismissed",campaignList:"campaign:list",campaignOnboarding:"campaign:onboarding",campaignPins:"campaign:pins",campaignRecent:"campaign:recent",campaignNotes:"campaign:notes",campaignSavedViews:"campaign:saved-views",campaignAnnualGoals:"campaign:annual-goals",campaignAccents:"campaign:accents",campaignReminders:"campaign:reminders",campaignReminderFired:"campaign:reminder-fired",campaignEpisodeRead:"campaign:episode-read",campaignEpisodeBookmarks:"campaign:episode-bookmarks",campaignEpisodeBookmarkMeta:"campaign:episode-bookmark-meta",campaignEpisodeTags:"campaign:episode-tags",campaignReadingQueue:"campaign:reading-queue",campaignActivityLog:"campaign:activity-log",campaignLastVisit:"campaign:last-visit",campaignFaviconVisit:"campaign:favicon-visit",campaignDetailVisits:"campaign:detail-visits",campaignLifetimeMilestone:"campaign:lifetime-milestone",campaignAnniversaries:"campaign:anniversaries",campaignWrapped:"campaign:wrapped",campaignRecentRoutes:"campaign:recent-routes",creatorAnalysisIntent:"creator-analysis-intent",firstStoryRating:"rating:first-story",libraryFirstStoryChoice:"library:first-story-choice"},a=["myria:draft:create","library:newStorySettings:v1","library:newStorySettings:v2","onboarding_completed","onboarding_skipped","onboarding_dismissed","myria:library-form-authority:v1","@myria/campaigns_list_cache_v1","@myria/campaigns_onboarding_seen_v2","myria:campaigns_onboarding_seen_v2","myria:pinnedCampaigns:v1","myria:recentlyViewedCampaigns:v1","myria:savedViews:v1","myria:annualGoals:v1","myria:campaignReminders:v1","myria:campaignReminders:fired:v1","myria:episodeRead:v1","myria:episodeBookmark:v1","myria:episodeBookmarkMeta:v1","myria:episodeTags:v1","myria:readingQueue:v1","myria:activityLog:v1","myria:campaignsLastVisit:v1","myria:lifetimeEpisodes:lastCelebrated:v1","myria:recentRoutes:v1","viralCopy.pending"],i=["myria:notes:campaign:","myria:accent:campaign:","myria:campaignDetailVisit:v1:","myria:anniv:","myria:wrapped:celebrated:"];function l(e,t){let r="string"==typeof e?e.trim():"";return r&&Number.isSafeInteger(t)&&Number(t)>=0?{principalId:r,authorityEpoch:t}:null}function o(e){return null!==l(null==e?void 0:e.principalId,null==e?void 0:e.authorityEpoch)}function u(e,t){return!!e&&!!t&&e.principalId===t.principalId&&e.authorityEpoch===t.authorityEpoch}function s(e,t){return"unchanged"!==function(e,t){let r=o(e),n=o(t);return r||n?r?n?e.principalId!==t.principalId?"principal_changed":e.authorityEpoch!==t.authorityEpoch?"authority_rotated":"unchanged":"released":"acquired":"unavailable"}(e,t)}function c(e,t){let r=l(null==e?void 0:e.principalId,null==e?void 0:e.authorityEpoch);if(!r)throw TypeError("Creator-local storage requires a concrete principal and authority epoch");if(!Object.values(n).includes(t))throw TypeError("Unknown creator-local storage slot: ".concat(String(t)));return"".concat("myria:creator:v1",":").concat(encodeURIComponent(r.principalId),":").concat(t)}function d(e){if(!o(e.authority))return!1;try{return e.isAuthorityCurrent(e.authority)}catch(e){return!1}}async function f(e,t){if(!d(e))return null;let r=await e.storage.getItem(c(e.authority,t));return d(e)?r:null}async function p(e,t,r){return!!d(e)&&(await e.storage.setItem(c(e.authority,t),r),d(e))}async function g(e,t){return!!d(e)&&(await e.storage.removeItem(c(e.authority,t)),d(e))}async function m(e){var t;let r=(t=e.authority,Object.values(n).map(e=>c(t,e))),a=[];for(let t of r){if(!d(e)){a.push(t);continue}try{await e.storage.removeItem(t),d(e)||a.push(t)}catch(e){a.push(t)}}return{attemptedKeys:r,failedKeys:a}}async function h(e,t){let r=[],n=[];if(t)try{n=(await t()).filter(e=>i.some(t=>e.startsWith(t)))}catch(e){r.push(...i.map(e=>"".concat(e,"*")))}let l=[...new Set([...a,...n])];for(let t of l)try{await e.removeItem(t)}catch(e){r.push(t)}return{attemptedKeys:l,failedKeys:r}}},12880:(e,t,r)=>{r.d(t,{$n:()=>o,HU:()=>d,O2:()=>u,Y6:()=>s,u:()=>c});var n=r(1521),a=r(4992);function i(e){let t=(0,a.x)();return!!(null==t?void 0:t.__loaded)&&!!t.isFeatureEnabled(e)}let l=new Map;function o(){return Object.fromEntries(l)}function u(){l.clear()}function s(e){let t=(0,a.x)();if(!(null==t?void 0:t.__loaded))return;let r=t.getFeatureFlag(e);return"string"==typeof r&&l.set(e,r),r}
1function c(e){let[t,r]=(0,n.useState)(()=>i(e)),l=(0,n.useCallback)(()=>{r(i(e))},[e]);return(0,n.useEffect)(()=>{let e,t=!1,r=()=>{if(t)return!0;let r=(0,a.x)();if(!(null==r?void 0:r.__loaded))return!1;l();let n=r.onFeatureFlags(l);return"function"==typeof n?e=n:n&&"object"==typeof n&&"unsubscribe"in n&&"function"==typeof n.unsubscribe&&(e=()=>n.unsubscribe.call(n)),t=!0,!0};l(),r();let n=setInterval(()=>{r()&&clearInterval(n)},1e3);return()=>{clearInterval(n),null==e||e()}},[e,l]),t}function d(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],[r,i]=(0,n.useState)(void 0);return(0,n.useEffect)(()=>{let n;if(!t||void 0!==r)return;let l=!1,o=()=>{let t=s(e);void 0!==t&&i(t)};o();let u=()=>{if(l)return!0;let e=(0,a.x)();if(!(null==e?void 0:e.__loaded))return!1;o();let t=e.onFeatureFlags(o);return"function"==typeof t?n=t:t&&"object"==typeof t&&"unsubscribe"in t&&"function"==typeof t.unsubscribe&&(n=()=>t.unsubscribe.call(t)),l=!0,!0};u();let c=setInterval(()=>{u()&&clearInterval(c)},1e3);return()=>{clearInterval(c),null==n||n()}},[t,e,r]),r}},16182:(e,t,r)=>{function n(e){return e instanceof Error?e.message:"object"==typeof e&&null!==e&&"message"in e?String(e.message):"string"==typeof e?e:""}function a(e){return"object"==typeof e&&null!==e&&"code"in e?String(e.code):""}function i(e){if("SERVER_UNAVAILABLE"===a(e))return!0;let t=null==e?void 0:e.status;return"number"==typeof t&&t>=500}function l(e,t,r){return Object.assign(Error(t),{code:e,guestThrottled:!0,guestThrottleRetryAtMs:r})}function o(e){return"object"==typeof e&&null!==e&&"guestThrottled"in e&&!0===e.guestThrottled}function u(e){if("object"!=typeof e||null===e||!("nextResetAt"in e))return null;let t=e.nextResetAt;if("string"!=typeof t||!t)return null;let r=Date.parse(t);return Number.isFinite(r)?r:null}r.d(t,{E2:()=>a,GU:()=>i,JP:()=>o,oe:()=>u,pB:()=>l,u1:()=>n})},16804:(e,t,r)=>{function n(){return"function"==typeof window.PasswordCredential&&!!navigator.credentials}async function a(e,t){if(n()&&e&&t)try{let r=new window.PasswordCredential({id:e,password:t,name:e});await navigator.credentials.store(r)}catch(e){}}async function i(e){if(!n())return null;try{let t=await navigator.credentials.get({password:!0,mediation:e});if(!t||"password"!==t.type||!t.id||!t.password)return null;return{id:t.id,password:t.password}}catch(e){return null}}function l(){return i("silent")}async function o(){var e;if(null==(e=navigator.credentials)?void 0:e.preventSilentAccess)try{await navigator.credentials.preventSilentAccess()}catch(e){}}r.d(t,{Nr:()=>l,UA:()=>o,bW:()=>a})},18383:(e,t,r)=>{let n;r.d(t,{c:()=>s,z:()=>u});var a=r(24738),i=r(88248),l=r(12880),o=r(4992);function u(){let e;if(void 0===n||!(0,a.vP)())return;let t=(0,o.x)();if(null==t?void 0:t.__loaded){try{var r;r=t.get_property("$user_id"),e="string"==typeof r&&r.length>0?r:null}catch(e){return}if(null===n){if(null===e)return;try{t.reset()}catch(e){}return}if(e!==n)try{null!==e&&t.reset(),t.identify(n)}catch(e){}}}function s(e){let t="string"==typeof e&&e.length>0?e:null;n!==t&&((0,l.O2)(),(0,i.Py)(),"string"==typeof n&&(0,i.xB)()),n=t,u()}},20436:(e,t,r)=>{r.d(t,{P:()=>a});var n=r(63230);function a(){let e=n.n.getState().accessToken;return e?{Authorization:"Bearer ".concat(e)}:{}}},20651:(e,t,r)=>{r.d(t,{Le:()=>a,TD:()=>s,Tu:()=>i,oJ:()=>l,rK:()=>o,sf:()=>u});var n=r(70541);function a(e){return"string"==typeof e&&/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(e)}function i(e){if(a(e))try{localStorage.setItem(n.EP,JSON.stringify({id:e,ts:Date.now()}))}catch(e){}}function l(){try{let e=localStorage.getItem(n.EP);if(!e)return null;let t=JSON.parse(e);if("number"==typeof t.ts&&Date.now()-t.ts<2592e6&&a(t.id))return t.id;return localStorage.removeItem(n.EP),null}catch(e){return null}}function o(e){if(a(e))try{localStorage.setItem(n.MQ,JSON.stringify({id:e,ts:Date.now()}))}catch(e){}}function u(){try{let e=localStorage.getItem(n.MQ);if(!e)return null;let t=JSON.parse(e);if("number"==typeof t.ts&&Date.now()-t.ts<864e5&&a(t.id))return t.id;return localStorage.removeItem(n.MQ),null}catch(e){return null}}function s(){try{localStorage.removeItem(n.MQ)}catch(e){}}},25354:(e,t,r)=>{r.d(t,{Bp:()=>o,SL:()=>u,Vl:()=>g,ol:()=>c,t4:()=>p,vX:()=>d});
1var n=r(87292),a=r(85109),i=r(63230),l=r(8977);let o=(0,n.PZ)("localStorage"),u=(0,n.PZ)("sessionStorage");function s(e){let t=window[e];if(!t)throw Error("browser storage unavailable");let r=[];for(let e=0;e<t.length;e+=1){let n=t.key(e);null!==n&&r.push(n)}return r}function c(){let e=i.n.getState(),t=(0,a.gi)(e.userId,e);return t?{principalId:t.principalId,authorityEpoch:t.authorityEpoch}:null}function d(e){return(0,a.HV)(e,i.n.getState())}function f(e){return{attemptedKeys:e.flatMap(e=>[...e.attemptedKeys]),failedKeys:e.flatMap(e=>e.failedKeys)}}async function p(){return f(await Promise.all([(0,l.fX)(o,()=>s("localStorage")),(0,l.fX)(u,()=>s("sessionStorage"))]))}async function g(e){let t={authority:e,isAuthorityCurrent:d};return f(await Promise.all([(0,l.ym)({...t,storage:o}),(0,l.ym)({...t,storage:u})]))}},28972:(e,t,r)=>{r.d(t,{X:()=>n});function n(e){return["profile","me",null!=e?e:"anonymous"]}},29877:(e,t,r)=>{r.d(t,{F_:()=>s,IQ:()=>c,Ru:()=>g,j9:()=>u,jV:()=>o,nj:()=>p,zN:()=>d});let n="myria-push-registered",a="myria-push-dismissed",i="myria-push-gen-count",l=null;function o(){return"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window}function u(){return o()?Notification.permission:"unsupported"}function s(){try{localStorage.setItem(a,String(Date.now()))}catch(e){}}function c(){if(!o()||"default"!==Notification.permission||function(){try{let e=localStorage.getItem(a);if(!e)return!1;let t=parseInt(e,10);return Date.now()-t<6048e5}catch(e){return!1}}()||d())return!1;try{let e=parseInt(localStorage.getItem(i)||"0",10)+1;return localStorage.setItem(i,String(e)),e>=1}catch(e){return!1}}function d(){try{return"true"===localStorage.getItem(n)}catch(e){return!1}}async function f(){if(l)return l;if(!o())return null;try{return l=await navigator.serviceWorker.register("/sw.js",{scope:"/"}),await navigator.serviceWorker.ready,l}catch(e){return null}}async function p(e){if(!o()||!e)return!1;if(d())return!0;try{let t=await f();if(!t)return!1;let r=await Notification.requestPermission();if("granted"!==r)return!1;let a="BMjh3rB0SprYd0-awSxCOwaO3OVGdBV4p3O7-8mCAz6in-vPafHKOIN4OhDNM5LCaVMAXxJiU-BOG72v-PVNYc8";if(!a)return!1;let i=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:function(e){let t="=".repeat((4-e.length%4)%4),r=atob((e+t).replace(/-/g,"+").replace(/_/g,"/")),n=new Uint8Array(r.length);for(let e=0;e<r.length;e++)n[e]=r.charCodeAt(e);return n}(a)}),l=JSON.stringify(i.toJSON());if(!(await fetch("".concat("https://api.myria.pro","/api/notifications/register"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({token:l,platform:"web"})})).ok)return!1;try{localStorage.setItem(n,"true")}catch(e){}return!0}catch(e){return!1}}async function g(e){if(o()){try{let t=await f();if(!t)return;let r=await t.pushManager.getSubscription();if(!r)return;let n=JSON.stringify(r.toJSON());await r.unsubscribe(),e&&await fetch("".concat("https://api.myria.pro","/api/notifications/register"),{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e)},body:JSON.stringify({token:n})}).catch(e=>{})}catch(e){}try{localStorage.removeItem(n)}catch(e){}}}},46273:(e,t,r)=>{function n(e){if(429===e)return{rateLimited:!0};if(e>=200&&e<300)return{};throw Error("Resend verification request failed (".concat(e,")"))}function a(e){return"sent"===e||"rate_limited"===e?6e4:null}r.d(t,{$I:()=>a,TH:()=>n})},51740:(e,t,r)=>{r.d(t,{OJ:()=>ei,As:()=>el});var n=r(73365),a=r(1521),i=r(21474),l=r(63230),o=r(8649);function u(){try{let e=[],t=document.createElement("canvas"),r=t.getContext("2d");r&&(r.textBaseline="top",r.font="14px Arial",r.fillStyle="#f60",r.fillRect(125,1,62,20),r.fillStyle="#069",r.fillText("fingerprint",2,15),r.fillStyle="rgba(102, 204, 0, 0.7)",r.fillText("fingerprint",4,17),e.push(t.toDataURL())),e.push(navigator.userAgent),e.push("".concat(screen.width,"x").concat(screen.height,"x").concat(screen.colorDepth)),e.push(Intl.DateTimeFormat().resolvedOptions().timeZone),e.push(navigator.language),e.push(navigator.platform);let n=e.join("|"),a=0;for(let e=0;e<n.length;e++){let t=n.charCodeAt(e);a=(a<<5)-a+t,a&=a}return btoa(Math.abs(a).toString(36))}catch(e){return""}}var s=r(88248);
1let c=(r(10986).env.NEXT_PUBLIC_APP_VERSION||"5c693b75fc346b9f4b23a246623549331d5af8ee").slice(0,40)||"dev";var d=r(29877),f=r(21018),p=r(16182),g=r(60764),m=r(66896),h=r(16804),y=r(68680),v=r(25354),w=r(20651),I=r(56680),S=r(20436),b=r(46273),_=r(63462),A=r(18383),E=r(28972),k=r(71901);let R=[5e3,3e4,12e4,6e5,36e5],C=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,T=/^[A-Za-z0-9_-]{1,128}$/,P=["not_requested","applied","duplicate","already_referred","invalid_code","self_referral"],O=["not_requested","recorded","duplicate","invalid_share_id","unknown_share","self_attribution"],N=()=>({version:1,records:[]});function D(e,t){if("string"!=typeof e)return null;let r=e.trim();return r&&r.length<=t?r:null}function U(e){return!!e&&"object"==typeof e&&!!(D(e.id,128)&&T.test(e.id)&&D(e.userId,128)&&(null===e.referralCode||D(e.referralCode,64))&&(null===e.shareId||D(e.shareId,64)&&C.test(e.shareId))&&"number"==typeof e.createdAt&&Number.isFinite(e.createdAt)&&"number"==typeof e.attempts&&Number.isInteger(e.attempts)&&e.attempts>=0&&"number"==typeof e.nextAttemptAt&&Number.isFinite(e.nextAttemptAt)&&(e.referralCode||e.shareId))}function L(e,t,r){var n;return null!=(n=e.records.find(e=>e.userId===t&&e.nextAttemptAt<=r))?n:null}function x(e,t){return"string"==typeof t&&e.includes(t)}var j=r(80304);let M=new Set;function F(e){try{var t;return null!=(t=window[e])?t:null}catch(e){return null}}function G(e,t){let r=null;try{r=e.getItem(j.d.pendingReferralApplyQueue)}catch(e){}var n=r;if(!n)return N();try{let e=JSON.parse(n);if((null==e?void 0:e.version)!==1||!Array.isArray(e.records))return N();return{version:1,records:e.records.filter(U).filter(e=>t-e.createdAt<=6048e5).slice(0,8)}}catch(e){return N()}}function B(e,t){try{return e.setItem(j.d.pendingReferralApplyQueue,JSON.stringify(t)),!0}catch(e){return!1}}function q(e){var t,r,n,a,i,l,o;let u=null!=(t=e.now)?t:Date.now(),s=null!=(n=null!=(r=e.durableStorage)?r:F("localStorage"))?n:F("sessionStorage"),c=null!=(a=e.stagingStorage)?a:F("sessionStorage");if(!s)return null;let d=G(s,u),f=null,p=null,g=null;if(c)try{f=c.getItem(j.d.pendingReferral),p=c.getItem(j.d.pendingShareId),g=c.getItem(j.d.pendingReferralApplyOwner)}catch(e){}if(f||p){if(!g&&!0!==e.claimUnbound)return L(d,e.userId,u);if(!g){try{null==c||c.setItem(j.d.pendingReferralApplyOwner,e.userId)}catch(e){}g=e.userId}if(g!==e.userId)return L(d,e.userId,u);let t=function(e,t){let r=D(t.userId,128),n=D(t.referralCode,64),a=D(t.shareId,64),i=a&&C.test(a)?a:null,l=D(t.id,128);if(!r||!l||!T.test(l)||!n&&!i)return{queue:e,record:null,accepted:!1};let o=e.records.find(e=>e.userId===r&&e.referralCode===n&&e.shareId===i);if(o)return{queue:e,record:o,accepted:!0};if(e.records.length>=8)return{queue:e,record:null,accepted:!1};let u={id:l,userId:r,referralCode:n,shareId:i,createdAt:t.now,attempts:0,nextAttemptAt:t.now};return{queue:{...e,records:[...e.records,u]},record:u,accepted:!0}}(d,{userId:e.userId,referralCode:f,shareId:p,id:(null!=(i=e.createId)?i:function(){let e="undefined"!=typeof globalThis?globalThis.crypto:void 0;return(0,k.o4)(()=>{var t;return null==e||null==(t=e.randomUUID)?void 0:t.call(e)})})(),now:u});if(t.accepted&&B(s,t.queue)){d=t.queue;try{null==c||c.removeItem(j.d.pendingReferral)}catch(e){}try{null==c||c.removeItem(j.d.pendingShareId)}catch(e){}let e="unread",r="unread";try{e=null!=(l=null==c?void 0:c.getItem(j.d.pendingReferral))?l:null}catch(e){}try{r=null!=(o=null==c?void 0:c.getItem(j.d.pendingShareId))?o:null}catch(e){}if(!e&&!r){try{null==c||c.removeItem(j.d.pendingReferralApplyOwner)}catch(e){}try{null==c||c.removeItem(j.d.pendingReferralOAuthStarted)}catch(e){}}}}else if(!0===e.claimUnbound){try{null==c||c.removeItem(j.d.pendingReferralApplyOwner)}catch(e){}try{null==c||c.removeItem(j.d.pendingReferralOAuthStarted)}catch(e){}}return L(d,e.userId,u)}function J(e){var t,r,n;let a=G(e.storage,e.now),i="complete"===e.outcome?(t=e.record,{...a,records:a.records.filter(e=>e.id!==t.id||e.userId!==t.userId)}):(r=e.record,n=e.now,{...a,records:a.records.map(e=>{if(e.id!==r.id||e.userId!==r.userId)return e;let t=e.attempts+1,a=R[Math.min(t-1,R.length-1)];return{...e,attempts:t,nextAttemptAt:n+a}})});B(e.storage,i)}async function V(e){var t,r,n,a,i,l,o;let u=null!=(t=e.now)?t:Date.now(),s=null!=(n=null!=(r=e.durableStorage)?r:F("localStorage"))?n:F("sessionStorage");
1if(!s)return{attempted:!1,terminal:!1,applied:!1,referrerDisplayName:null};let c=q({userId:e.userId,durableStorage:s,stagingStorage:e.stagingStorage,now:u,createId:e.createId,claimUnbound:null!=(a=e.claimUnbound)&&a});if(!c)return{attempted:!1,terminal:!1,applied:!1,referrerDisplayName:null};let d="".concat(c.userId,":").concat(c.id);if(M.has(d))return{attempted:!1,terminal:!1,applied:!1,referrerDisplayName:null};M.add(d);let f="undefined"!=typeof AbortController?new AbortController:null,p=f?setTimeout(()=>f.abort(),null!=(i=e.requestTimeoutMs)?i:15e3):null;try{let t=await (null!=(l=e.fetcher)?l:fetch)("".concat(null!=(o=e.apiUrl)?o:y.H$,"/api/referral/apply"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(e.authorizationToken),"Idempotency-Key":c.id},body:JSON.stringify({expectedUserId:c.userId,...c.referralCode?{referralCode:c.referralCode}:{},...c.shareId?{shareId:c.shareId}:{}}),...f?{signal:f.signal}:{}});if(!t.ok)return J({storage:s,record:c,now:u,outcome:"defer"}),{attempted:!0,terminal:!1,applied:!1,referrerDisplayName:null};let r=await t.json().catch(()=>null),n=function(e){var t,r;if(!e||"object"!=typeof e)return null;let n=e.data&&"object"==typeof e.data?e.data:e,a=n.receipt;return(null==a?void 0:a.version)===1&&!0===a.terminal&&x(P,null==(t=a.referral)?void 0:t.status)&&x(O,null==(r=a.share)?void 0:r.status)?{receipt:a,applied:!0===n.applied,referrerDisplayName:"string"==typeof n.referrerDisplayName?n.referrerDisplayName:null}:null}(r);if(!n)return J({storage:s,record:c,now:u,outcome:"defer"}),{attempted:!0,terminal:!1,applied:!1,referrerDisplayName:null};return J({storage:s,record:c,now:u,outcome:"complete"}),{attempted:!0,terminal:!0,applied:n.applied,referrerDisplayName:n.referrerDisplayName}}catch(e){return J({storage:s,record:c,now:u,outcome:"defer"}),g.R.warn("[AuthProvider] pending referral apply failed:",e),{attempted:!0,terminal:!1,applied:!1,referrerDisplayName:null}}finally{p&&clearTimeout(p),M.delete(d)}}function $(e){let t=null!=e?e:F("sessionStorage");try{if(null==t?void 0:t.getItem(j.d.pendingReferralApplyOwner))return}catch(e){}try{null==t||t.removeItem(j.d.pendingReferral)}catch(e){}try{null==t||t.removeItem(j.d.pendingShareId)}catch(e){}try{null==t||t.removeItem(j.d.pendingReferralApplyOwner)}catch(e){}try{null==t||t.removeItem(j.d.pendingReferralOAuthStarted)}catch(e){}}function z(e,t){let r=!1;try{r="complete"===new URLSearchParams(e).get("oauth")}catch(e){return!1}if(!r)return!1;let n=null!=t?t:F("sessionStorage");try{return(null==n?void 0:n.getItem(j.d.pendingReferralOAuthStarted))==="1"}catch(e){return!1}}let X=0;function H(e){var t,r;let n="string"==typeof(null==e?void 0:e.new_email)?e.new_email.trim():"";if(n&&(null==e?void 0:e.email_change_sent_at))return{pending:!0,email:n};let a=((null==e?void 0:e.identities)||[]).find(e=>"email"===e.provider);if(!a)return{pending:!1,email:null};let i=null!=(r=null==(t=a.identity_data)?void 0:t.email)?r:a.email;return{pending:!(null==e?void 0:e.email_confirmed_at),email:"string"==typeof i?i:null}}function Q(e){return e.current+=1,e.current}function K(e,t){return e.current===t}async function W(e){return await e.cancel(e.userId),!!e.isCurrent()&&(e.remove(e.userId),!0)}function Y(){let e=Error("Sign in again to continue");return e.code="SIGN_IN_REQUIRED",e.status=401,e}async function Z(e){let t=await e.getClient(),r=e.getAuthority();if(!r.accessToken||!r.userId)throw Y();let n=await e.post(r.accessToken),a=e.getAuthority();if(a.accessToken!==r.accessToken||a.userId!==r.userId||a.authEpoch!==r.authEpoch)throw Y();return{client:t,response:n,authority:{accessToken:r.accessToken,userId:r.userId,authEpoch:r.authEpoch}}}async function ee(e,t,r){let n=null!=t?t:e.current;n&&(n.state="blocked",n.queuedSignedIn={seen:!1,session:null},e.current=n);let a=!1;try{a=await r()===!0}catch(e){a=!1}throw a&&e.current===n&&(e.current=null),Y()}async function et(e){var t;let r=null!=(t=e.attempts)?t:2;for(let t=0;t<r;t+=1){try{await e.signOutLocal()}catch(e){}try{if(await e.getCurrentSession()==null)return!0}catch(e){}}return!1}async function er(e){var t,r;let n;try{n=await e.signInWithPassword()}catch(t){return ee(e.gateRef,e.gateRef.current,e.clearAuthority)}let a=e.gateRef.current,i=function(e,t){var r,n,a,i,l,o,u,s,c;let d=null==(r=t.data)?void 0:r.session,f=null!=(u=null==(a=t.data)||null==(n=a.user)?void 0:n.id)?u:null,p=null!=(s=null==d||null==(i=d.user)?void 0:i.id)?s:null;if(!e||"pending"!==e.state||t.error||!(null==d?void 0:d.access_token)||!d.refresh_token||f!==e.expectedUserId||p!==e.expectedUserId)return null;if(!e.queuedSignedIn.seen)return d;let g=e.queuedSignedIn.session,m=null!=(c=null==g||null==(l=g.user)?void 0:l.id)?c:null;return(null==g?void 0:g.access_token)&&g.refresh_token&&(null==(o=g.user)?void 0:o.id)&&m===e.expectedUserId&&g.access_token===d.access_token&&g.refresh_token===d.refresh_token?g:null}(a,n);if(!a||!i)return ee(e.gateRef,a,e.clearAuthority);e.gateRef.current=null,e.publishAuthority(i,a.expectedUserId);let l=e.refreshProfile(i,a.expectedUserId),o=null==(t=e.getAuthorityGeneration)?void 0:t.call(e);try{await l}catch(t){throw null!=o&&(null==(r=e.getAuthorityGeneration)?void 0:r.call(e))===o&&await ee(e.gateRef,a,e.clearAuthority),Y()}}async function en(e,t){let r=await fetch("".concat(y.H$,"/api/auth/resend-verification"),{method:"POST",headers:{"Content-Type":"application/json",...(0,S.P)()},body:JSON.stringify({email:e.trim().toLowerCase(),clientSurface:"web",returnPath:t&&(0,I.p)(t)?t:"/library"})});return(0,b.TH)(r.status)}let ea=(0,a.createContext)(void 0);function ei(e){let{children:t}=e,S=(0,a.useRef)(null),b=(0,a.useCallback)(async()=>
1{if(!S.current){let{getSupabaseBrowser:e}=await Promise.all([r.e(74339),r.e(50571),r.e(16974)]).then(r.bind(r,94593));S.current=e()}return S.current},[]),k=(0,i.jE)(),{isLoading:R,isAuthenticated:C,accessToken:T,userId:P,isRecovering:O,recoveryEmail:N,setAuth:D,setLoading:U,setRecovering:L,clearAuth:x}=(0,l.n)(),{profile:j,setProfile:M,setCredits:F,clearUser:G}=(0,o.k)(),[B,J]=(0,a.useState)(!1),[Y,ee]=(0,a.useState)(null),ei=(0,a.useCallback)(()=>{J(!1),ee(null)},[]);(0,a.useEffect)(()=>{T||ei()},[T,ei]),(0,a.useEffect)(()=>{R||(0,A.c)(C&&P?P:null)},[R,C,P]),(0,a.useEffect)(()=>{var e,t,r,n;j&&P&&j.id===P&&(0,s.w4)(function(e){var t,r,n;let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now(),i={platform:"web",app_version:c,tier:null!=(t=e.tier)?t:"free",is_premium:null!=(r=e.isPremium)&&r,is_guest:null!=(n=e.isGuest)&&n},l=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();if(!e)return null;let r=Date.parse(e);return Number.isNaN(r)?null:Math.max(0,Math.floor((t-r)/864e5))}(e.createdAt,a);return null!=l&&(i.account_age_days=l),i}({tier:null!=(e=j.tier)?e:null,isPremium:null!=(t=j.isPremium)?t:null,isGuest:null!=(r=j.isGuest)?r:null,createdAt:null!=(n=j.createdAt)?n:null}))},[P,null==j?void 0:j.id,null==j?void 0:j.tier,null==j?void 0:j.isPremium,null==j?void 0:j.isGuest,null==j?void 0:j.createdAt]);let el=(0,a.useRef)(!1),eo=(0,a.useRef)(0),eu=(0,a.useRef)(null),es=(0,a.useRef)(0),ec=(0,a.useRef)(null),[ed,ef]=(0,a.useState)(0),ep=(0,a.useCallback)(()=>{let e=Q(es);return ef(e),e},[]),eg=(0,a.useCallback)(function(e,t){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=l.n.getState();r||n.accessToken===e&&n.userId===t||(eo.current+=1),ep(),el.current=!1,D(e,t)},[ep,D]),em=(0,a.useCallback)(()=>{let e=l.n.getState();(null!==e.accessToken||null!==e.userId)&&(eo.current+=1),ep(),el.current=!1,x()},[ep,x]);(0,a.useEffect)(()=>{let e=!1,t=null,r=e=>{let t=H(null==e?void 0:e.user);J(t.pending),ee(t.email)};return(async()=>{let n=await b();if(e)return;try{let{data:e,error:t}=await Promise.race([n.auth.getSession(),new Promise((e,t)=>{setTimeout(()=>t(Error("session-boot-timeout")),6e3)})]);if(t)await n.auth.signOut({scope:"local"}).catch(()=>{}),eg(null,null),ei();else{let t=e.session;if(null==t?void 0:t.access_token){var a,i,o;let e=null!=(o=null==(a=t.user)?void 0:a.id)?o:null;e&&z(window.location.search)&&q({userId:e,claimUnbound:!0}),eg(t.access_token,e),r(t),(null==(i=t.user)?void 0:i.email_confirmed_at)&&(0,_.D)(t.access_token,e)}else eg(null,null)}}catch(e){await n.auth.signOut({scope:"local"}).catch(()=>{}),eg(null,null),ei()}if(e)return;let{data:{subscription:u}}=n.auth.onAuthStateChange(async(e,t)=>{var n,a,i,o,u,s;let c=null!=(i=null==t?void 0:t.access_token)?i:null,d=null!=(o=null==t||null==(n=t.user)?void 0:n.id)?o:null,f=l.n.getState(),p=function(e){var t,r,n,a,i;let l=null!=(a=null==(t=e.session)?void 0:t.access_token)?a:null,o=null!=(i=null==(n=e.session)||null==(r=n.user)?void 0:r.id)?i:null,u=e.currentAccessToken!==l||e.currentUserId!==o;return u&&(e.authEpochRef.current+=1),e.advanceProfileGeneration(),{intercepted:function(e,t,r){var n,a;if(!e)return!1;if("SIGNED_OUT"===t)return e.state="blocked",e.queuedSignedIn={seen:!1,session:null},!1;if("SIGNED_IN"!==t&&"TOKEN_REFRESHED"!==t&&"INITIAL_SESSION"!==t)return!1;let i=null!=(a=null==r||null==(n=r.user)?void 0:n.id)?a:null;return i&&i!==e.expectedUserId?(e.state="blocked",e.queuedSignedIn={seen:!1,session:null}):"pending"===e.state&&"SIGNED_IN"===t&&(e.queuedSignedIn={seen:!0,session:r}),!0}(e.gate,e.event,e.session),authorityChanged:u}}({gate:eu.current,event:e,session:t,currentAccessToken:f.accessToken,currentUserId:f.userId,authEpochRef:eo,advanceProfileGeneration:ep});p.intercepted||(c&&d&&z(window.location.search)&&q({userId:d,claimUnbound:!0}),eg(c,d,p.authorityChanged),r(t),c&&d&&(null==t||null==(a=t.user)?void 0:a.email_confirmed_at)&&(0,_.D)(c,d),"PASSWORD_RECOVERY"===e&&L(!0,null!=(s=null==t||null==(u=t.user)?void 0:u.email)?s:null),"SIGNED_OUT"===e&&($(),em(),G(),J(!1),ee(null),k.clear()))});e?u.unsubscribe():t=u})(),()=>{e=!0,null==t||t.unsubscribe()}},[b,eg,L,em,G,ei,k]),(0,a.useEffect)(()=>{let e=window.location.hash,t=window.location.search;if(e.includes("access_token=")){let t=new URLSearchParams(e.substring(1)),r=t.get("access_token"),n=t.get("refresh_token");"recovery"===t.get("type")&&L(!0),r&&n&&b().then(e=>e.auth.setSession({access_token:r,refresh_token:n})).then(()=>{window.history.replaceState({},"",window.location.pathname)}).catch(e=>{g.R.error("[Auth] Failed to set session from URL params:",e)})}if(t.includes("code=")){let e=new URLSearchParams(t.substring(1)).get("code");e&&b().then(t=>t.auth.exchangeCodeForSession(e)).then(()=>{window.history.replaceState({},"",window.location.pathname)}).catch(e=>{g.R.error("[Auth] Failed to exchange code for session:",e)})}},[b,L]);let eh=(0,a.useCallback)(async e=>{var t,r,n,a,i,o,u,c,d,p,h,v,w,I,S,b,_,A,R,C,O,N,D,U,L;let x=null!=(t=null==e?void 0:e.accessToken)?t:T,j=null!=(r=null==e?void 0:e.userId)?r:P;if(!x||!j){M(null),F([]);return}if(eu.current||!function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!e||t}(el.current,null==e?void 0:e.force))return;let G=Q(es),B=function(e,t,r){let n=e.current;return e.current={generation:t,userId:r},n&&n.generation!==t?n:null}(ec,G,j);el.current=!0;let q=z(window.location.search);try{let t=(null==e?void 0:e.replaceSharedQuery)?j:null;if(t&&!await W({userId:t,cancel:e=>k.cancelQueries({queryKey:(0,E.X)(e),exact:!0}),remove:e=>k.removeQueries({queryKey:(0,E.X)(e),exact:!0}),isCurrent:()=>K(es,G)}
1)||B&&B.userId!==t&&!await W({userId:B.userId,cancel:e=>k.cancelQueries({queryKey:(0,E.X)(e),exact:!0}),remove:e=>k.removeQueries({queryKey:(0,E.X)(e),exact:!0}),isCurrent:()=>K(es,G)}))return;let r=x,T=await k.fetchQuery({queryKey:(0,E.X)(j),staleTime:0,queryFn:async()=>{let e=(0,s.TK)(),t=e?{"X-Myria-Landing-Page":e}:{},n=await fetch("".concat(y.H$,"/api/profile/me"),{headers:{Authorization:"Bearer ".concat(r),...t}});if(401===n.status)try{var a,i,o;let e=await (0,m.j)();(null==e||null==(a=e.session)?void 0:a.access_token)&&(r=e.session.access_token,eg(r,null!=(o=null==(i=e.session.user)?void 0:i.id)?o:null),n=await fetch("".concat(y.H$,"/api/profile/me"),{headers:{Authorization:"Bearer ".concat(r),...t}}))}catch(e){g.R.warn("[AuthProvider] session refresh failed:",e)}if(!n.ok)throw Error("profile request failed (".concat(n.status,")"));let u=await (0,f.oi)(n);if((null==u?void 0:u.id)!==j||l.n.getState().userId!==j||!K(es,G))throw Error("stale profile response");return u}});if((null==T?void 0:T.id)!==j||l.n.getState().userId!==j||!K(es,G))return;if(M({id:T.id,username:T.username,displayName:T.displayName,avatarUrl:T.avatarUrl,bio:T.bio,isPremium:null!=(a=T.isPremium)&&a,isGuest:null!=(i=T.isGuest)&&i,tier:null!=(o=T.tier)?o:"free",tierFeatures:null!=(u=T.tierFeatures)?u:null,premiumSince:T.premiumSince,premiumUntil:T.premiumUntil,referralCode:null!=(c=null==(n=T.referral)?void 0:n.code)?c:null,createdAt:T.createdAt}),T.isGuest&&r&&function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return t-e>3e5}(X)&&(X=Date.now(),fetch("/api/auth/convert-social",{method:"POST",headers:{Authorization:"Bearer ".concat(r),"Content-Type":"application/json"}}).then(async e=>{if(!e.ok)return;let t=await e.json().catch(()=>({}));(null==t?void 0:t.converted)&&K(es,G)&&eh()}).catch(e=>{g.R.warn("[AuthProvider] auto-convert guest social identity failed:",e)})),T.credits&&"object"==typeof T.credits&&!Array.isArray(T.credits)){let e=T.credits,t=T.freeToday||{};F([{type:"generations",paid:null!=(d=e.gen)?d:0,free:null!=(p=t.gen)?p:0,total:(null!=(h=e.gen)?h:0)+(null!=(v=t.gen)?v:0)},{type:"video_seconds",paid:null!=(w=e.videoSeconds)?w:0,free:null!=(I=t.videoSeconds)?I:0,total:(null!=(S=e.videoSeconds)?S:0)+(null!=(b=t.videoSeconds)?b:0)},{type:"published_views",paid:null!=(_=e.views)?_:0,free:null!=(A=t.views)?A:0,total:(null!=(R=e.views)?R:0)+(null!=(C=t.views)?C:0)},{type:"copies",paid:null!=(O=e.copies)?O:0,free:null!=(N=t.copies)?N:0,total:(null!=(D=e.copies)?D:0)+(null!=(U=t.copies)?U:0)}])}else Array.isArray(T.credits)&&F(T.credits);let P="string"==typeof T.id?T.id:null,L=l.n.getState().userId;P&&r&&L===P&&V({userId:P,authorizationToken:r,claimUnbound:q})}catch(t){if(g.R.warn("[AuthProvider] profile fetch failed:",t),e&&!e.suppressErrors)throw t}finally{K(es,G)&&(el.current=!1),(null==(L=ec.current)?void 0:L.generation)===G&&(ec.current=null)}},[T,P,k,eg,M,F]);(0,a.useEffect)(()=>{C&&T&&P&&eh({accessToken:T,userId:P,replaceSharedQuery:!0,suppressErrors:!0})},[C,T,P,ed,eh]),(0,a.useEffect)(()=>{if(!C||!T)return;let e=null,t=()=>{e||(e=setInterval(eh,6e4))},r=()=>{e&&(clearInterval(e),e=null)},n=()=>{"visible"===document.visibilityState?(t(),eh()):r()};return"visible"===document.visibilityState&&t(),document.addEventListener("visibilitychange",n),()=>{r(),document.removeEventListener("visibilitychange",n)}},[C,T,eh]),(0,a.useEffect)(()=>{if(!C)return;let e=()=>eh();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[C,eh]);let ey=(0,a.useCallback)(async(e,t,r,n,a)=>{U(!0),(0,s.Pj)("email");try{var i,l,o,u,c,d,p,g,m,h,v,w,S,_,A,E,k,R,C;let T=document.cookie.match(/(?:^|; )locale=([^;]*)/),P=T?decodeURIComponent(T[1]):"en",O=(0,s.TK)(),N={email:e,password:t,redirectTo:"".concat(window.location.origin,"/auth/callback"),locale:P,clientSurface:"web",returnPath:a&&(0,I.p)(a)?a:"/library",guestFlow:!0};r&&(N.referralCode=r),n&&(N.shareId=n),O&&(N.landingPage=O);let D=await fetch("".concat(y.H$,"/api/auth/signup"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)}),U=await (0,f.oi)(D);if(!D.ok){let e=null!=(d=null!=(c=null==U||null==(o=U.error)?void 0:o.code)?c:null==U?void 0:U.code)?d:"",t=null!=(g=null!=(p=null==U||null==(u=U.error)?void 0:u.message)?p:null==U?void 0:U.message)?g:"";if(409===D.status||"EMAIL_EXISTS"===e)throw Error("EMAIL_EXISTS");if("EMAIL_BLOCKED"===e)throw Error(t||"Disposable emails are not allowed");if(422===D.status||"PASSWORD_PWNED"===e)throw Error(t||"Choose a stronger password");
1if("VALIDATION_ERROR"===e){let e=null==U||null==(m=U.error)?void 0:m.fields,r=Array.isArray(e)&&e.length>0?e.map(e=>e.message).join(". "):t;throw Error(r||"Signup failed")}throw(0,f.r$)(D.status,U,"Signup failed")}if($(),(null==U?void 0:U.needsConfirmation)&&(null==U?void 0:U.guestFlow)&&(null==U?void 0:U.signupToken)){let r=await b(),{data:n,error:a}=await r.auth.signInAnonymously();if(a)throw a;let i=null==(h=n.session)?void 0:h.access_token;if(!i){let e=Error("Anonymous session is unavailable");throw e.name="GuestEmailUpdateError",e.code="GUEST_SESSION_MISSING",e}let{data:l,error:o}=await r.auth.updateUser({email:e,password:t},{emailRedirectTo:"".concat(window.location.origin,"/auth/callback")});if(o)throw function(e){let t=function(e){let t=String(e.code||"").toLowerCase(),r=String(e.message||"").toLowerCase();return["email_exists","email_already_registered","identity_already_exists","user_already_exists","email_address_already_exists"].includes(t)||/already|registered|exists/.test(r)}(e),r=Error(t?"EMAIL_EXISTS":String(e.message||"Unable to add email credentials"));return r.name="GuestEmailUpdateError",r.code=t?"EMAIL_EXISTS":"GUEST_EMAIL_UPDATE_FAILED",r}(o);let u=await fetch("".concat(y.H$,"/api/auth/guest-finalize"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(i)},body:JSON.stringify({signupToken:U.signupToken})}),s=await (0,f.oi)(u);if(!u.ok){let e=null!=(_=null!=(S=null==s||null==(v=s.error)?void 0:v.code)?S:null==s?void 0:s.code)?_:"GUEST_FINALIZE_FAILED",t=null!=(E=null!=(A=null==s||null==(w=s.error)?void 0:w.message)?A:null==s?void 0:s.message)?E:"Unable to finalize email signup",r=Error(t);throw r.name="GuestEmailFinalizeError",r.code=e,r.status=u.status,r}let c=H(l.user);return J(c.pending),ee(c.email),{needsConfirmation:!0,guestFlow:!0}}if(null==U?void 0:U.needsConfirmation)return{needsConfirmation:!0};if((null==U||null==(i=U.session)?void 0:i.access_token)&&(null==U||null==(l=U.session)?void 0:l.refresh_token)){let e=await b();await e.auth.setSession({access_token:U.session.access_token,refresh_token:U.session.refresh_token});let t=(null==(R=U.session)||null==(k=R.user)?void 0:k.id)||(null==(C=U.user)?void 0:C.id);t&&(0,s.PU)("email",t)}return{}}catch(t){let e=t instanceof Error?t.message:String(t);throw(0,s.Xr)("EMAIL_EXISTS"===e?"email_exists":/disposable/i.test(e)?"email_blocked":/stronger password|pwned|breach/i.test(e)?"password_pwned":/valid|required|at least|must contain|character/i.test(e)?"validation":"unknown"),t}finally{U(!1)}},[b,U]),ev=(0,a.useCallback)(async(e,t,r)=>{eu.current=null,U(!0);try{var n,a,i;let l=await b(),{data:o}=await l.auth.getSession(),c=(null==r?void 0:r.guestDraftRecovery)&&(null==(a=o.session)||null==(n=a.user)?void 0:n.is_anonymous)?o.session.access_token:null,d=c?u():null,p=await fetch("".concat(y.H$,"/api/auth/login"),{method:"POST",headers:{"Content-Type":"application/json",...c?{Authorization:"Bearer ".concat(c)}:{}},body:JSON.stringify({email:e,password:t,locale:(()=>{try{let e=document.cookie.match(/(?:^|; )locale=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}})(),...c&&d?{guestDraftRecovery:!0}:{}})}),g=await (0,f.oi)(p);if(!p.ok)throw(0,f.r$)(p.status,g,"Login failed");$();let{access_token:m,refresh_token:h}=null!=(i=g.session)?i:{};if(m&&h&&(await l.auth.setSession({access_token:m,refresh_token:h}),(0,s.c3)("email"),c&&d&&"string"==typeof g.guestDraftRecoveryProof&&/^[a-f0-9]{64}$/.test(g.guestDraftRecoveryProof)))return{guestDraftRecovery:{proof:g.guestDraftRecoveryProof,guestAccessToken:c,idempotencyKey:crypto.randomUUID(),deviceFingerprint:d,registeredAccessToken:m}};return{}}catch(e){throw(0,s.s9)(function(e){var t,r;let n=String(null!=(t=null==e?void 0:e.code)?t:""),a=String(null!=(r=null==e?void 0:e.message)?r:"").toLowerCase();return"INVALID_CREDENTIALS"===n?"invalid_credentials":"EMAIL_NOT_CONFIRMED"===n?"email_not_confirmed":"RATE_LIMITED"===n?"rate_limited":"EMAIL_EXISTS"===n||"EMAIL_ALREADY_REGISTERED"===n?"email_exists":(null==e?void 0:e.status)===429||a.includes("too many")||a.includes("rate limit")?"rate_limited":a.includes("confirm your email")||a.includes("not confirmed")?"email_not_confirmed":a.includes("invalid login")||a.includes("invalid credentials")||a.includes("invalid password")||a.includes("credential")||a.includes("invalid")&&a.includes("email")?"invali
1d_credentials":(null==e?void 0:e.name)==="AbortError"?"timeout":"number"==typeof(null==e?void 0:e.status)&&e.status>=500?"http_5xx":"number"==typeof(null==e?void 0:e.status)&&e.status>=400?"http_4xx":(null==e?void 0:e.name)==="TypeError"||/network|fetch/i.test(a)?"network":"unknown"}(e)),e}finally{U(!1)}},[b,U]),ew=(0,a.useCallback)(async()=>{try{var e;await (0,h.UA)();let t=await b(),{data:r}=await t.auth.getSession(),n=(null==r||null==(e=r.session)?void 0:e.access_token)||T;await (0,d.Ru)(n).catch(e=>{}),n&&await fetch("".concat(y.H$,"/api/auth/logout"),{method:"POST",headers:{Authorization:"Bearer ".concat(n)}}),(0,A.c)(null),await t.auth.signOut(),em(),G(),k.clear(),await (0,v.t4)(),$()}catch(e){(0,d.Ru)(null).catch(e=>{}),(0,A.c)(null),em(),G(),k.clear(),await (0,v.t4)(),$()}finally{ei()}},[b,T,k,em,G,ei]),eI=(0,a.useCallback)(async e=>{eu.current=null,(0,s.Pj)("google");let t="".concat(window.location.origin,"/auth/callback"),r=e&&(0,I.p)(e)?"".concat(t,"?next=").concat(encodeURIComponent(e)):t,n=await b(),{data:a,error:i}=await n.auth.signInWithOAuth({provider:"google",options:{redirectTo:r,queryParams:{access_type:"offline",prompt:"select_account consent"}}});if(i)throw i},[b]),eS=(0,a.useCallback)(async e=>{eu.current=null,(0,s.Pj)("apple");let t="".concat(window.location.origin,"/auth/callback"),r=e&&(0,I.p)(e)?"".concat(t,"?next=").concat(encodeURIComponent(e)):t,n=await b(),{data:a,error:i}=await n.auth.signInWithOAuth({provider:"apple",options:{redirectTo:r}});if(i)throw i},[b]),eb=(0,a.useCallback)(async()=>{eu.current=null;let e="".concat(window.location.origin,"/auth/callback"),t=await b(),{error:r}=await t.auth.linkIdentity({provider:"google",options:{redirectTo:e,queryParams:{access_type:"offline",prompt:"select_account consent"}}});if(r)throw r},[b]),e_=(0,a.useCallback)(async e=>{U(!0);try{let t=await fetch("".concat(y.H$,"/api/auth/reset-password"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e})}),r=await (0,f.oi)(t);if(!t.ok)throw Error((0,f.PE)(r,"Password reset failed"))}finally{U(!1)}},[U]),eA=(0,a.useCallback)(en,[]),eE=(0,a.useCallback)(async(e,t)=>{U(!0);try{let r=window.location.hash,n=await b();
1if(!T&&r.includes("token=")){let e=new URLSearchParams(r.substring(1)),a=e.get("token"),i=e.get("email")||t||N;a&&i&&await n.auth.verifyOtp({type:"recovery",token_hash:a,email:i})}let{error:a}=await n.auth.updateUser({password:e});if(a)throw a;L(!1),window.history.replaceState({},"",window.location.pathname)}finally{U(!1)}},[b,T,N,U,L]),ek=(0,a.useCallback)(async()=>{U(!0),(0,s.Pj)("guest");try{var e,t,r,n,a,i;let l=u()||void 0,o=await fetch("".concat(y.H$,"/api/auth/guest"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceFingerprint:l})}),c=await (0,f.oi)(o);if(!o.ok){let a=null!=(n=null!=(r=null==c?void 0:c.code)?r:null==c||null==(e=c.error)?void 0:e.code)?n:"",i=(null==c?void 0:c.message)||(null==c||null==(t=c.error)?void 0:t.message)||"Failed to create guest session";if("IP_LIMIT_REACHED"===a||"DEVICE_LIMIT_REACHED"===a)throw(0,p.pB)(a,i||"Too many guest accounts. Please sign up.",(0,p.oe)(null==c?void 0:c.error));throw(0,f.r$)(o.status,c,"Failed to create guest session")}let{access_token:d,refresh_token:g}=null!=(a=c.session)?a:{};if(d&&g){let e=await b();await e.auth.setSession({access_token:d,refresh_token:g});let t=null==(i=c.user)?void 0:i.id;t&&(0,s.PU)("guest",t)}}finally{U(!1)}},[b,U]),eR=(0,a.useCallback)(async(e,t,r,n)=>{U(!0);try{let a=n;if(!a)try{a=localStorage.getItem("myria_referral_code")||void 0}catch(e){}let i=(0,w.oJ)()||void 0,o=await Z({getClient:b,getAuthority:()=>{let e=l.n.getState();return{accessToken:e.accessToken,userId:e.userId,authEpoch:eo.current}},post:n=>fetch("".concat(y.H$,"/api/auth/convert"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(n)},body:JSON.stringify({email:e,password:t,username:r,referralCode:a,...i?{shareId:i}:{}})})}),{client:u,response:s}=o,c=o.authority.userId,d=await (0,f.oi)(s);if(!s.ok)throw(0,f.r$)(s.status,d,"Failed to convert account");eu.current={expectedUserId:c,queuedSignedIn:{seen:!1,session:null},state:"pending"},ep();let p=async()=>{let e=await et({signOutLocal:()=>u.auth.signOut({scope:"local"}),getCurrentSession:async()=>{let{data:e,error:t}=await u.auth.getSession();if(t)throw t;return e.session}});return em(),G(),ei(),k.clear(),e};await er({gateRef:eu,signInWithPassword:()=>u.auth.signInWithPassword({email:e,password:t}),clearAuthority:p,getAuthorityGeneration:()=>eo.current,publishAuthority:(e,t)=>{G(),eg(e.access_token,t);let r=H(e.user);J(r.pending),ee(r.email)},refreshProfile:(e,t)=>eh({accessToken:e.access_token,userId:t,replaceSharedQuery:!0,force:!0})})}finally{U(!1)}},[T,P,U,b,em,G,ei,k,eh,eg]),eC=(0,a.useMemo)(()=>{var e,t;return{isLoading:R,isAuthenticated:C,accessToken:T,userId:P,isRecovering:O,isPremium:null!=(e=null==j?void 0:j.isPremium)&&e,isGuest:null!=(t=null==j?void 0:j.isGuest)&&t,emailPendingConfirmation:B,pendingEmail:Y,signup:ey,login:ev,logout:ew,signInWithGoogle:eI,signInWithApple:eS,linkGoogle:eb,resetPassword:e_,resendVerification:eA,completePasswordReset:eE,refreshProfile:eh,signInAsGuest:ek,convertGuest:eR}},[R,C,T,P,O,null==j?void 0:j.isPremium,null==j?void 0:j.isGuest,B,Y,ey,ev,ew,eI,eS,eb,e_,eA,eE,eh,ek,eR]);return(0,n.jsx)(ea.Provider,{value:eC,children:t})}function el(){let e=(0,a.useContext)(ea);if(!e)throw Error("useAuth must be used within an AuthProvider");return e}},56680:(e,t,r)=>{r.d(t,{p:()=>i});let n=["/library","/web-create","/story","/settings","/admin","/pricing","/blog","/v","/published","/billing","/signup"],a=/^\/[a-z]{2,3}(-[A-Za-z]{2,4})?(?=\/)/;function i(e){let t;if("string"!=typeof e||e.length>4096||!e.startsWith("/")||e.startsWith("//")||e.includes("\\")||e.includes("\0"))return!1;try{t=decodeURIComponent(e)}catch(e){return!1}if(t.startsWith("//")||t.includes(":\\"))return!1;let r=t.split(/[?#]/)[0];if(r.split("/").some(e=>"."===e||".."===e))return!1;let i=r.replace(a,"")||"/";return!i.startsWith("//")&&("/"===i||n.some(e=>i===e||i.startsWith(e+"/")))}},63462:(e,t,r)=>{r.d(t,{D:()=>i});var n=r(68680);let a=new Set;async function i(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:fetch;if(!e||!t)return!1;if(a.has(t))return!0;try{var i;let l=await r("".concat(n.H$,"/api/auth/confirmation-complete"),{method:"POST",headers:{Authorization:"Bearer ".concat(e)},cache:"no-store"});if(!l.ok||(i=await l.json(),!i||"object"!=typeof i||i.userId!==t||!0!==i.confirmed||"boolean"!=typeof i.recorded))return!1;return a.add(t),!0}catch(e){return!1}}},70541:(e,t,r)=>{r.d(t,{$D:()=>u,Bb:()=>f,C5:()=>v,Df:()=>g,EP:()=>I,HA:()=>a,MQ:()=>b,Y7:()=>h,aX:()=>m,ac:()=>l,bA:()=>d,cK:()=>o,ec:()=>c,hX:()=>n,h_:()=>S,ip:()=>w,jR:()=>y,jt:()=>p,kY:()=>_,tw:()=>i,vY:()=>s});let n="source_story",a="seed_style",i="s",l="destination",o="share_watch_remix",u="creator_constellation_capsule",s="discover_lineage_pickup",c="published_story",d="c
1apsule_open_receipt",f="capsule_signup_receipt",p="capsule_id",g="capsule_revision",m="capsule_projection_digest",h="seed_title",y="prefill",v="myria_source_story",w="myria_seed_style",I="myria_share_id",S="myria_seed_title",b="myria_cast_character",_="myria_signup_destination_v1"},80304:(e,t,r)=>{r.d(t,{d:()=>n});let n={pendingReferral:"myria:pendingReferral",pendingShareId:"myria:pendingShareId",pendingReferralOAuthStarted:"myria:pendingReferralOAuthStarted:v1",pendingReferralApplyOwner:"myria:pendingReferralApplyOwner:v1",pendingReferralApplyQueue:"myria:pendingReferralApplyQueue:v1"}},85109:(e,t,r)=>{function n(e){return"string"==typeof e?e.trim():""}function a(e){if(!e)return null;let t=e.split(".");if(3!==t.length)return null;try{let e=t[1].replace(/-/g,"+").replace(/_/g,"/"),r=e.padEnd(4*Math.ceil(e.length/4),"="),n=JSON.parse(atob(r));return"string"==typeof n.sub&&n.sub.trim()?n.sub.trim():null}catch(e){return null}}function i(e,t){let r=n(e);if(r)return r;let i=a(t);return i||(t?"authenticated":"no-user")}function l(e,t,r){let l=n(e);if(!l)return!1;let o=n(t),u=a(r);return(!o||!u||o===u)&&i(t,r)===l&&(!u||u===l)}function o(e,t,r){return r&&l(e,t,r)?r:null}function u(e,t){let r=n(e),a=n(t.userId);if(!r||a!==r)return null;let i=o(r,t.userId,t.accessToken);return i&&Number.isSafeInteger(t.authorityEpoch)&&!(t.authorityEpoch<0)?{principalId:r,authorizationToken:i,authorityEpoch:t.authorityEpoch}:null}function s(e,t){let r=u(e.principalId,t);return(null==r?void 0:r.authorityEpoch)===e.authorityEpoch}r.d(t,{HV:()=>s,I8:()=>l,gV:()=>o,gi:()=>u,vO:()=>i})},87292:(e,t,r)=>{r.d(t,{L7:()=>l,PZ:()=>u,Su:()=>o,wj:()=>i});let n={localStorage:{values:new Map,deleted:new Set},sessionStorage:{values:new Map,deleted:new Set}};function a(e){try{var t;return null!=(t=window[e])?t:null}catch(e){return null}}function i(e,t){let r=function(e,t){var r;if(e)return e.deleted.has(t)?null:e.values.has(t)?null!=(r=e.values.get(t))?r:null:void 0}(n[e],t),i=a(e);if(!i)return{available:!1,value:null!=r?r:null};try{let e=i.getItem(t);return{available:!0,value:void 0!==r?r:e}}catch(e){return{available:!1,value:null!=r?r:null}}}function l(e,t,r){let i=n[e],l=a(e);if(!l)return null==i||i.values.set(t,r),null==i||i.deleted.delete(t),!1;try{return l.setItem(t,r),null==i||i.values.delete(t),null==i||i.deleted.delete(t),!0}catch(e){return null==i||i.values.set(t,r),null==i||i.deleted.delete(t),!1}}function o(e,t){let r=n[e];null==r||r.values.delete(t);let i=a(e);if(!i)return null==r||r.deleted.add(t),!1;try{return i.removeItem(t),null==r||r.deleted.delete(t),!0}catch(e){return null==r||r.deleted.add(t),!1}}function u(e){return{getItem:t=>i(e,t).value,setItem:(t,r)=>{l(e,t,r)},removeItem:t=>{o(e,t)}}}}}]);
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.