rari 0.10.18 → 0.10.20
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/dist/cli.mjs +3 -3
- package/dist/client.d.mts +2 -2
- package/dist/client.mjs +3 -3
- package/dist/get-client-component-YrjzU6RI.mjs +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/proxy/RariRequest.d.mts +1 -1
- package/dist/proxy/RariResponse.d.mts +1 -1
- package/dist/proxy/runtime-executor.d.mts +6 -4
- package/dist/proxy/runtime-executor.mjs +1 -1
- package/dist/railway-2u_Vq-71.mjs +67 -0
- package/dist/render-jhijat1L.mjs +73 -0
- package/dist/robots-generator-Bw9KFHn4.mjs +2 -0
- package/dist/runtime/AppRouterProvider.mjs +4 -4
- package/dist/runtime/ErrorBoundaryWrapper.mjs +1 -1
- package/dist/runtime/entry-client.mjs +1 -1
- package/dist/runtime/react-server-dom-rari-client.mjs +1 -1
- package/dist/runtime/rsc-client-runtime.mjs +1 -1
- package/dist/runtime-client-yoJmu7vX.mjs +6 -0
- package/dist/server-build-BUnvC6Er.mjs +175 -0
- package/dist/{server-config-x5pDgs13.d.mts → server-config-Cf6g4PHZ.d.mts} +1 -0
- package/dist/sitemap-generator-CzZZcCF6.mjs +7 -0
- package/dist/timer-utils-BO5HIsHv.mjs +1 -0
- package/dist/utils-BGFxUpBh-CWvq2hOR.mjs +37 -0
- package/dist/vite.d.mts +4 -4
- package/dist/vite.mjs +16 -16
- package/package.json +11 -11
- package/dist/get-client-component-DOrK5M2i.mjs +0 -1
- package/dist/railway-wWoxBe94.mjs +0 -102
- package/dist/render-BD1SX5GJ.mjs +0 -108
- package/dist/robots-generator-CDQtL299.mjs +0 -2
- package/dist/runtime-client-C80F166Y.mjs +0 -6
- package/dist/server-build-C6FM1GI2.mjs +0 -175
- package/dist/sitemap-generator-CJ-3AADp.mjs +0 -4
- package/dist/utils-dqnEOG_U-BFRRjfIS.mjs +0 -1
- /package/dist/{metadata-route-D44UGnHc.d.mts → metadata-route-BDdxZuGv.d.mts} +0 -0
- /package/dist/{preload-components-RB1K2A_B.mjs → preload-components-DD3aKUwy.mjs} +0 -0
- /package/dist/{types-C-syXDfX.d.mts → types-BhqnAV4k.d.mts} +0 -0
- /package/dist/{types-B9Cjrsqs.d.mts → types-Cfe0C3JU.d.mts} +0 -0
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{getBinaryPath as e,getInstallationInstructions as t}from"./platform.mjs";import{existsSync as n,readFileSync as r,realpathSync as i}from"node:fs";import{resolve as a}from"node:path";import o from"node:process";import{spawn as s}from"node:child_process";import{fileURLToPath as c}from"node:url";import{styleText as l}from"node:util";function u(e){console.warn(`${l(`blue`,`info`)} ${e}`)}function d(e){console.warn(`${l(`green`,`✓`)} ${e}`)}function f(e){console.error(`${l(`red`,`✗`)} ${e}`)}function p(e){console.warn(`${l(`yellow`,`⚠`)} ${e}`)}const m=/^([^=]+)=(.*)$/;function h(){let e=a(o.cwd(),`.env`);if(n(e))
|
|
3
|
-
`)){let t=e
|
|
2
|
+
import{getBinaryPath as e,getInstallationInstructions as t}from"./platform.mjs";import{existsSync as n,readFileSync as r,realpathSync as i}from"node:fs";import{resolve as a}from"node:path";import o from"node:process";import{spawn as s}from"node:child_process";import{fileURLToPath as c}from"node:url";import{styleText as l}from"node:util";function u(e){console.warn(`${l(`blue`,`info`)} ${e}`)}function d(e){console.warn(`${l(`green`,`✓`)} ${e}`)}function f(e){console.error(`${l(`red`,`✗`)} ${e}`)}function p(e){console.warn(`${l(`yellow`,`⚠`)} ${e}`)}const m=/^([^=]+)=(.*)$/;function h(e){let t=e.trim();if(!t||t.startsWith(`#`))return null;let n=t.match(m);if(!n)return null;let[,r,i]=n,a=r.trim(),o=i.trim();return(o.startsWith(`"`)&&o.endsWith(`"`)||o.startsWith(`'`)&&o.endsWith(`'`))&&(o=o.slice(1,-1)),{key:a,value:o}}function g(){let e=a(o.cwd(),`.env`);if(!n(e))return;let t=r(e,`utf-8`);for(let e of t.split(`
|
|
3
|
+
`)){let t=h(e);t&&!o.env[t.key]&&(o.env[t.key]=t.value)}}g();const[,,_,...v]=o.argv;function y(e){return n(a(e,`pnpm-lock.yaml`))?`pnpm`:n(a(e,`yarn.lock`))?`yarn`:n(a(e,`bun.lockb`))?`bun`:n(a(e,`package-lock.json`))?`npm`:null}function b(e){try{let t=a(e,`package.json`);if(!n(t))return null;let i=JSON.parse(r(t,`utf-8`));if(i.packageManager?.startsWith(`pnpm`))return`pnpm`;if(i.packageManager?.startsWith(`yarn`))return`yarn`;if(i.packageManager?.startsWith(`bun`))return`bun`;if(i.packageManager?.startsWith(`npm`))return`npm`}catch{}return null}function x(){let e=o.cwd(),t=a(`/`),n=0;for(;e!==t&&n<20;){n++;let t=y(e);if(t)return t;let r=b(e);if(r)return r;let i=a(e,`..`);if(i===e)break;e=i}return`npm`}function S(){let e=x(),t=o.platform===`win32`;switch(e){case`bun`:return t?`bun.cmd`:`bun`;case`pnpm`:return t?`pnpm.cmd`:`pnpm`;case`yarn`:return t?`yarn.cmd`:`yarn`;default:return t?`npx.cmd`:`npx`}}function C(e,t,n={}){let r=o.platform===`win32`;if(e===`npx`){let e=S();if(e.includes(`bun`))return s(r?`bunx.cmd`:`bunx`,t,{...n,shell:r});if(e.includes(`pnpm`))return s(e,[`exec`,...t],{...n,shell:r});if(e.includes(`yarn`))return s(e,[`dlx`,...t],{...n,shell:r})}return r&&e===`npx`?s(`npx.cmd`,t,{...n,shell:!0}):s(e,t,n)}function w(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function T(){return!!(o.env.RAILWAY_ENVIRONMENT||o.env.RAILWAY_PROJECT_ID||o.env.RAILWAY_SERVICE_ID)}function E(){return!!(o.env.RENDER||o.env.RENDER_SERVICE_ID||o.env.RENDER_SERVICE_NAME)}function D(){return T()||E()}function O(){return T()?`Railway`:E()?`Render`:`local`}function k(){return{port:o.env.PORT||o.env.RSC_PORT||`3000`,mode:o.env.NODE_ENV||`production`,host:D()?`0.0.0.0`:`127.0.0.1`}}async function A(){let{existsSync:e,rmSync:t}=await import(`node:fs`),{resolve:n}=await import(`node:path`),r=n(o.cwd(),`dist`);e(r)&&(u(`Cleaning dist folder...`),t(r,{recursive:!0,force:!0})),u(`Type checking...`);let i=C(`npx`,[`tsgo`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((e,t)=>{i.on(`exit`,n=>{n===0?(d(`Type check passed`),e()):(f(`Type check failed with code ${n}`),t(Error(`Type check failed with code ${n}`)))}),i.on(`error`,t)}),u(`Building for production...`);let a=C(`npx`,[`vp`,`build`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((e,t)=>{a.on(`exit`,n=>{n===0?(d(`Build complete`),e()):(f(`Build failed with code ${n}`),t(Error(`Build failed with code ${n}`)))}),a.on(`error`,t)}),await j()}async function j(){if(n(a(o.cwd(),`dist`,`server`,`image.json`))&&n(a(o.cwd(),`public`)))try{let t=s(e(),[`optimize-images`],{stdio:`inherit`,cwd:o.cwd(),shell:!1});await new Promise(e=>{t.on(`exit`,t=>{t===0||p(`Image pre-optimization exited with code ${t}`),e()}),t.on(`error`,t=>{p(`Image pre-optimization error: ${w(t)}`),e()})})}catch(e){p(`Could not pre-optimize images: ${w(e)}`)}}async function M(){let{existsSync:e}=await import(`node:fs`),{resolve:t}=await import(`node:path`);if(!e(t(o.cwd(),`dist`))){u(`First run detected - building project...`);let e=C(`npx`,[`vp`,`build`,`--mode`,`development`],{stdio:`inherit`,cwd:o.cwd()});await new Promise((t,n)=>{e.on(`exit`,e=>{e===0?(d(`Initial build complete`),t()):(f(`Build failed with code ${e}`),n(Error(`Build failed with code ${e}`)))}),e.on(`error`,n)})}u(`Starting Vite+ dev server...`);let n=C(`npx`,[`vp`,`dev`],{stdio:`inherit`,cwd:o.cwd()}),r=()=>{u(`Shutting down dev server...`),n.kill(`SIGTERM`)};return o.on(`SIGINT`,r),o.on(`SIGTERM`,r),n.on(`error`,e=>{f(`Failed to start Vite: ${e.message}`),o.exit(1)}),n.on(`exit`,e=>{e!==0&&e!==null&&(f(`Vite exited with code ${e}`),o.exit(e))}),new Promise(()=>{})}async function N(){let n;try{n=e()}catch{f(`Failed to obtain rari binary`),f(t()),o.exit(1)}let{port:r,mode:i,host:a}=k();if(D()){let e=O();u(`${e} environment detected`),u(`Starting rari server for ${e} deployment...`),u(`Mode: ${i}, Host: ${a}, Port: ${r}`),u(`using binary: ${n}`)}let c=s(n,[`--mode`,i,`--port`,r,`--host`,a],{stdio:`inherit`,cwd:o.cwd(),env:{...o.env,RUST_LOG:o.env.RUST_LOG||`error`}}),l=()=>{u(`shutting down...`),c.kill(`SIGTERM`)};return o.on(`SIGINT`,l),o.on(`SIGTERM`,l),c.on(`error`,e=>{f(`Failed to start rari server: ${e.message}`),e.message.includes(`ENOENT`)&&f(`Binary not found. Please ensure rari is properly installed.`),o.exit(1)}),c.on(`exit`,(e,t)=>{t?u(`server stopped by signal ${t}`):e===0?d(`server stopped successfully`):(f(`server exited with code ${e}`),o.exit(e||1))}),new Promise(()=>{})}async function P(){u(`Setting up Railway deployment...`),D()&&(f(`Already running in ${O()} environment. Use "rari start" instead.`),o.exit(1));let{createRailwayDeployment:e}=await import(`./railway-2u_Vq-71.mjs`);await e()}async function F(){u(`Setting up Render deployment...`),D()&&(f(`Already running in ${O()} environment. Use "rari start" instead.`),o.exit(1));let{createRenderDeployment:e}=await import(`./render-jhijat1L.mjs`);await e()}async function I(){switch(_){case void 0:case`help`:case`--help`:case`-h`:console.warn(`${l(`bold`,`rari CLI`)}
|
|
4
4
|
|
|
5
5
|
${l(`bold`,`Usage:`)}
|
|
6
6
|
${l(`cyan`,`rari dev`)} Start the development server with Vite
|
|
@@ -63,4 +63,4 @@ ${l(`bold`,`Notes:`)}
|
|
|
63
63
|
- Platform deployment is automatically detected and configured
|
|
64
64
|
- Use Ctrl+C to stop the server gracefully
|
|
65
65
|
|
|
66
|
-
`);break;case`dev`:await
|
|
66
|
+
`);break;case`dev`:await M();break;case`build`:await A();break;case`start`:await N();break;case`deploy`:v[0]===`railway`?await P():v[0]===`render`?await F():(f(`Unknown deployment target. Available: railway, render`),o.exit(1));break;default:console.error(`${l(`bold`,`Unknown command:`)} ${_}`),console.warn(`Run "${l(`cyan`,`rari help`)}" for available commands`),o.exit(1)}}const L=o.argv[1]?i(a(o.argv[1])):``,R=i(c(import.meta.url));L&&R===L&&I().catch(e=>{f(`CLI Error: ${w(e)}`),console.error(e),o.exit(1)});export{x as detectPackageManager,k as getDeploymentConfig,T as isRailwayEnvironment,E as isRenderEnvironment};
|
package/dist/client.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as extractServerPropsWithCache, S as extractServerProps, T as hasServerSideDataFetching, _ as ServerSidePropsResult, a as ServerSpamBlockerConfig, b as clearPropsCacheForComponent, c as ErrorBoundary, d as NotFound, f as RuntimeClient, g as MetadataResult, h as createLoadingBoundary, i as ServerRateLimitConfig, l as HttpRuntimeClient, m as createHttpRuntimeClient, o as DefaultError, p as createErrorBoundary, r as ServerConfig, s as DefaultLoading, t as ServerCSPConfig, u as LoadingSpinner, v as StaticParamsResult, w as extractStaticParams, x as extractMetadata, y as clearPropsCache } from "./server-config-
|
|
2
|
-
import { a as ErrorProps, c as LayoutEntry, f as NotFoundEntry, h as RouteSegmentType, i as ErrorEntry, m as RouteSegment, n as AppRouteManifest, o as GenerateMetadata, r as AppRouteMatch, s as GenerateStaticParams, t as AppRouteEntry, u as LoadingEntry } from "./types-
|
|
1
|
+
import { C as extractServerPropsWithCache, S as extractServerProps, T as hasServerSideDataFetching, _ as ServerSidePropsResult, a as ServerSpamBlockerConfig, b as clearPropsCacheForComponent, c as ErrorBoundary, d as NotFound, f as RuntimeClient, g as MetadataResult, h as createLoadingBoundary, i as ServerRateLimitConfig, l as HttpRuntimeClient, m as createHttpRuntimeClient, o as DefaultError, p as createErrorBoundary, r as ServerConfig, s as DefaultLoading, t as ServerCSPConfig, u as LoadingSpinner, v as StaticParamsResult, w as extractStaticParams, x as extractMetadata, y as clearPropsCache } from "./server-config-Cf6g4PHZ.mjs";
|
|
2
|
+
import { a as ErrorProps, c as LayoutEntry, f as NotFoundEntry, h as RouteSegmentType, i as ErrorEntry, m as RouteSegment, n as AppRouteManifest, o as GenerateMetadata, r as AppRouteMatch, s as GenerateStaticParams, t as AppRouteEntry, u as LoadingEntry } from "./types-Cfe0C3JU.mjs";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Component, ErrorInfo, ReactNode } from "react";
|
|
5
5
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
package/dist/client.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{i as e,t}from"./navigate-hfIqe3MK.mjs";import{a as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as u,n as d,o as f,p,r as m,s as h,t as g,u as _}from"./runtime-client-C80F166Y.mjs";import{Component as v,useEffect as y,useLayoutEffect as b,useRef as x,useState as S}from"react";import{Fragment as C,jsx as w,jsxs as T}from"react/jsx-runtime";function E(e,t,n={}){let r=null,i=0,a=0,o=null,s=null,{leading:c=!1,trailing:l=!0,maxWait:u}=n;function d(t){let n=o,r=s;return o=null,s=null,a=t,e.apply(r,n)}function f(e){let n=e-i,r=e-a;return i===0||n>=t||n<0||u!==void 0&&r>=u}function p(){let e=Date.now();if(f(e))return h(e);let n=e-i,o=e-a,s=t-n,c=u===void 0?1/0:u-o,l=Math.min(s,c);r=setTimeout(p,l)}function m(e){return a=e,r=setTimeout(p,t),c?d(e):void 0}function h(e){if(r=null,l&&o)return d(e);o=null,s=null}function g(){r!==null&&clearTimeout(r),a=0,o=null,i=0,s=null,r=null}function _(){return r===null?void 0:h(Date.now())}function v(){return r!==null}function y(...e){let n=Date.now(),a=f(n);if(o=e,s=this,i=n,a){if(r===null)return m(i);if(u!==void 0)return r=setTimeout(p,t),d(i)}r===null&&(r=setTimeout(p,t))}return y.cancel=g,y.flush=_,y.pending=v,y}function D(e,t){if(e instanceof Error&&e.name===`AbortError`)return{type:`abort`,message:`Navigation was cancelled`,originalError:e,url:t,timestamp:Date.now(),retryable:!1};if(e instanceof Error&&e.message.includes(`timeout`))return{type:`timeout`,message:`Navigation request timed out`,originalError:e,url:t,timestamp:Date.now(),retryable:!0};if(e instanceof Error&&`status`in e){let n=e.status;return n===404?{type:`not-found`,message:`Page not found`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:!1}:n>=500?{type:`server-error`,message:`Server error: ${n}`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:!0}:{type:`fetch-error`,message:`HTTP error: ${n}`,originalError:e,statusCode:n,url:t,timestamp:Date.now(),retryable:n>=500}}return e instanceof TypeError&&e.message.includes(`fetch`)?{type:`network-error`,message:`Network error - check your connection`,originalError:e,url:t,timestamp:Date.now(),retryable:!0}:e instanceof SyntaxError||e instanceof Error&&e.message.includes(`parse`)?{type:`parse-error`,message:`Failed to parse server response`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}:{type:`fetch-error`,message:e instanceof Error?e.message:`Unknown error occurred`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}}var O=class{options;retryCount;constructor(e={}){this.options={timeout:e.timeout??1e4,maxRetries:e.maxRetries??3,onError:e.onError??(()=>{}),onRetry:e.onRetry??(()=>{})},this.retryCount=new Map}handleError(e,t){let n=D(e,t);return this.options.onError(n),console.error(`[rari] Navigation:`,n.type,n.message,{url:n.url,statusCode:n.statusCode,retryable:n.retryable}),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`rari:navigation-error`,{detail:n})),n}canRetry(e,t){return e.retryable?(this.retryCount.get(t)??0)<this.options.maxRetries:!1}incrementRetry(e){let t=(this.retryCount.get(e)??0)+1;return this.retryCount.set(e,t),this.options.onRetry(t,{type:`fetch-error`,message:`Retry attempt ${t}`,url:e,timestamp:Date.now(),retryable:!0}),t}resetRetry(e){this.retryCount.delete(e)}getRetryCount(e){return this.retryCount.get(e)??0}clearRetries(){this.retryCount.clear()}};const k=/(^\/+)|(\/+$)/g;function A(e){let t=e.replace(k,``);return t?t.split(`/`):[]}function j(e){try{return decodeURIComponent(e)}catch{return null}}function M(e,t,n){let r=A(n),i={},a=0;for(let e=0;e<t.length;e++){let n=t[e];if(a>=r.length){if(n.type===`optional-catch-all`){n.param&&(i[n.param]=[]);continue}return null}switch(n.type){case`static`:if(r[a]!==n.value)return null;a++;break;case`dynamic`:if(n.param){let e=j(r[a]);if(e===null)return null;i[n.param]=e}a++;break;case`catch-all`:case`optional-catch-all`:if(n.param){let e=[];for(let t of r.slice(a)){let n=j(t);if(n===null)return null;e.push(n)}i[n.param]=e}a=r.length;break}}return a===r.length?i:null}function N(e){if(!e||e===`/`)return`/`;let t=e;for(;t.endsWith(`/`)&&t.length>1;)t=t.slice(0,-1);return t.startsWith(`/`)||(t=`/${t}`),t}function P(e,t){try{return new URL(e,t||window.location.origin).origin!==(t||window.location.origin)}catch{return!1}}function F(e){try{let t=new URL(e,window.location.origin);return t.pathname+t.hash}catch{return e}}function I({error:e,onRetry:t,onReload:n,onDismiss:r,retryCount:i=0,maxRetries:a=3}){let o=e.retryable&&i<a;return w(`div`,{style:{position:`fixed`,top:0,left:0,right:0,bottom:0,background:`rgba(0, 0, 0, 0.5)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:1e4,padding:`20px`},onClick:e=>{e.target===e.currentTarget&&r&&r()},children:T(`div`,{style:{background:`white`,borderRadius:`8px`,padding:`24px`,maxWidth:`500px`,width:`100%`,boxShadow:`0 4px 12px rgba(0, 0, 0, 0.15)`},onClick:e=>e.stopPropagation(),children:[T(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,marginBottom:`16px`},children:[w(`span`,{style:{fontSize:`32px`},children:(()=>{switch(e.type){case`timeout`:return`⏱️`;case`network-error`:return`📡`;case`not-found`:return`🔍`;case`server-error`:return`⚠️`;case`parse-error`:return`📄`;case`abort`:return`🚫`;default:return`❌`}})()}),w(`h2`,{style:{margin:0,fontSize:`20px`,fontWeight:`600`,color:`#1f2937`},children:`Navigation Error`})]}),w(`p`,{style:{margin:`0 0 16px 0`,fontSize:`15px`,lineHeight:`1.5`,color:`#4b5563`},children:(()=>{switch(e.type){case`timeout`:return`The page took too long to load. Please try again.`;case`network-error`:return`Unable to connect to the server. Please check your internet connection.`;case`not-found`:return`The page you're looking for doesn't exist.`;case`server-error`:return`The server encountered an error. Please try again in a moment.`;case`parse-error`:return`Unable to load the page content. Please try reloading.`;case`abort`:return`Navigation was cancelled.`;default:return e.message||`An unexpected error occurred.`}})()}),e.url&&T(`details`,{style:{marginBottom:`16px`,fontSize:`13px`,color:`#6b7280`},children:[w(`summary`,{style:{cursor:`pointer`,userSelect:`none`,marginBottom:`8px`},children:`Technical details`}),T(`div`,{style:{padding:`12px`,background:`#f9fafb`,borderRadius:`4px`,fontFamily:`monospace`,fontSize:`12px`,wordBreak:`break-all`},children:[T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`URL:`}),` `,e.url]}),e.statusCode&&T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`Status:`}),` `,e.statusCode]}),T(`div`,{style:{marginBottom:`4px`},children:[w(`strong`,{children:`Type:`}),` `,e.type]}),e.originalError&&T(`div`,{children:[w(`strong`,{children:`Error:`}),` `,e.originalError.message]})]})]}),o&&i>0&&T(`div`,{style:{marginBottom:`16px`,padding:`8px 12px`,background:`#fef3c7`,border:`1px solid #fbbf24`,borderRadius:`4px`,fontSize:`13px`,color:`#92400e`},children:[`Retry attempt`,` `,i,` `,`of`,` `,a]}),T(`div`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`},children:[o&&t&&w(`button`,{onClick:t,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#3b82f6`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#2563eb`},onMouseLeave:e=>{e.currentTarget.style.background=`#3b82f6`},children:`Try Again`}),n&&w(`button`,{onClick:n,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#6b7280`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#4b5563`},onMouseLeave:e=>{e.currentTarget.style.background=`#6b7280`},children:`Reload Page`}),r&&w(`button`,{onClick:r,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`transparent`,color:`#6b7280`,border:`1px solid #d1d5db`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`all 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#f9fafb`,e.currentTarget.style.borderColor=`#9ca3af`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`,e.currentTarget.style.borderColor=`#d1d5db`},children:`Dismiss`})]}),w(`p`,{style:{marginTop:`16px`,marginBottom:0,fontSize:`12px`,color:`#9ca3af`,textAlign:`center`},children:`Your current page is still available below this message`})]})})}const L=new class{cache=new Map;pendingRequests=new Map;async get(e){let t=this.cache.get(e);if(t)return t;let n=this.pendingRequests.get(e);if(n)return n;let r=this.fetchRouteInfo(e);this.pendingRequests.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pendingRequests.delete(e)}}async fetchRouteInfo(e){let t={path:e},n=await fetch(`/_rari/route-info`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=null;try{e=await n.json()}catch{}throw e?.error?Error(e.error):Error(`Failed to fetch route info: ${n.status} ${n.statusText}`)}let r=n.clone();try{return await n.json()}catch(t){try{let e=await r.text();return JSON.parse(e)}catch(n){throw console.error(`[RouteInfo] Failed to parse response:`,{error:t,parseError:n,path:e}),Error(`Failed to parse route info response`)}}}clear(){this.cache.clear(),this.pendingRequests.clear()}invalidate(e){this.cache.delete(e)}};if(typeof window<`u`){let e=window[`~rari`]||{};window[`~rari`]||(window[`~rari`]=e),e.routeInfoCache=L}var R=class{stateHistory;routeAccessOrder;maxHistorySize;scrollableSelector;constructor(e={}){this.stateHistory=new Map,this.routeAccessOrder=[],this.maxHistorySize=e.maxHistorySize||50,this.scrollableSelector=e.scrollableSelector||`[data-scrollable], .scrollable, [style*="overflow"]`}captureState(e){let t={scrollPositions:this.captureScrollPositions(),formData:this.captureFormData(),focusedElement:this.captureFocusedElement()};return this.storeState(e,t),t}captureScrollPositions(){let e=new Map;try{e.set(`window`,{x:window.scrollX,y:window.scrollY,element:`window`}),document.querySelectorAll(this.scrollableSelector).forEach((t,n)=>{if(t instanceof HTMLElement){let r=t.id||`scrollable-${n}`;(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&e.set(r,{x:t.scrollLeft,y:t.scrollTop,element:r})}})}catch{}return e}captureFormData(){let e=new Map;try{document.querySelectorAll(`form`).forEach((t,n)=>{let r=t.id||t.name||`form-${n}`,i=new FormData(t);i.entries().next().done||e.set(r,i)})}catch{}return e}captureFocusedElement(){try{let e=document.activeElement;if(e&&e!==document.body){if(e.id)return`#${e.id}`;if((e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.name)return`[name="${e.name}"]`}}catch{}return null}storeState(e,t){let n=this.routeAccessOrder.indexOf(e);for(n!==-1&&this.routeAccessOrder.splice(n,1),this.routeAccessOrder.push(e),this.stateHistory.set(e,t);this.routeAccessOrder.length>this.maxHistorySize;){let e=this.routeAccessOrder.shift();e&&this.stateHistory.delete(e)}}getHistorySize(){return this.stateHistory.size}hasState(e){return this.stateHistory.has(e)}getState(e){return this.stateHistory.get(e)}clearAll(){this.stateHistory.clear(),this.routeAccessOrder=[]}clearState(e){this.stateHistory.delete(e);let t=this.routeAccessOrder.indexOf(e);t!==-1&&this.routeAccessOrder.splice(t,1)}restoreState(e){let t=this.stateHistory.get(e);if(!t)return!1;let n=!0;return this.restoreScrollPositions(t.scrollPositions)||(n=!1),this.restoreFormData(t.formData)||(n=!1),t.focusedElement&&this.restoreFocus(t.focusedElement),n}restoreScrollPositions(e){let t=!0;try{e.forEach((e,n)=>{try{if(n===`window`)window.scrollTo(e.x,e.y);else{let r=document.getElementById(n)||document.querySelector(`[data-scrollable-id="${n}"]`);r instanceof HTMLElement?(r.scrollLeft=e.x,r.scrollTop=e.y):t=!1}}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore scroll positions:`,e),t=!1}return t}restoreFormData(e){let t=!0;try{e.forEach((e,n)=>{try{let r=document.getElementById(n)||document.querySelector(`form[name="${n}"]`)||document.querySelectorAll(`form`)[Number.parseInt(n.replace(`form-`,``),10)];r instanceof HTMLFormElement?e.forEach((e,n)=>{try{let t=r.elements.namedItem(n);t instanceof RadioNodeList?t.forEach(t=>{t instanceof HTMLInputElement&&(t.type===`radio`||t.type===`checkbox`?t.checked=t.value===e:t.value=e)}):(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&(t instanceof HTMLInputElement&&(t.type===`checkbox`||t.type===`radio`)?t.checked=t.value===e:t.value=e)}catch{t=!1}}):t=!1}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore form data:`,e),t=!1}return t}restoreFocus(e){try{let t=document.querySelector(e);t instanceof HTMLElement&&requestAnimationFrame(()=>{try{t.focus()}catch{}})}catch{}}};function z(e){e.title&&(document.title=e.title);let t=(e,t)=>{let n=document.querySelector(e);if(n)t.content&&n.setAttribute(`content`,t.content);else{n=document.createElement(`meta`);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);document.head.appendChild(n)}};if(e.description&&t(`meta[name="description"]`,{name:`description`,content:e.description}),e.keywords&&e.keywords.length>0&&t(`meta[name="keywords"]`,{name:`keywords`,content:e.keywords.join(`, `)}),e.viewport&&t(`meta[name="viewport"]`,{name:`viewport`,content:e.viewport}),e.canonical){let t=document.querySelector(`link[rel="canonical"]`);t||(t=document.createElement(`link`),t.setAttribute(`rel`,`canonical`),document.head.appendChild(t)),t.setAttribute(`href`,e.canonical)}if(e.robots){let n=[];e.robots.index!==void 0&&n.push(e.robots.index?`index`:`noindex`),e.robots.follow!==void 0&&n.push(e.robots.follow?`follow`:`nofollow`),e.robots.nocache&&n.push(`nocache`),n.length>0&&t(`meta[name="robots"]`,{name:`robots`,content:n.join(`, `)})}if(e.openGraph){let n=e.openGraph;if(n.title&&t(`meta[property="og:title"]`,{property:`og:title`,content:n.title}),n.description&&t(`meta[property="og:description"]`,{property:`og:description`,content:n.description}),n.url&&t(`meta[property="og:url"]`,{property:`og:url`,content:n.url}),n.siteName&&t(`meta[property="og:site_name"]`,{property:`og:site_name`,content:n.siteName}),n.type&&t(`meta[property="og:type"]`,{property:`og:type`,content:n.type}),n.images&&n.images.length>0){document.querySelectorAll(`meta[property="og:image"]`).forEach(e=>e.remove());for(let e of n.images){let t=document.createElement(`meta`);t.setAttribute(`property`,`og:image`),t.setAttribute(`content`,e),document.head.appendChild(t)}}}if(e.twitter){let n=e.twitter;if(n.card&&t(`meta[name="twitter:card"]`,{name:`twitter:card`,content:n.card}),n.site&&t(`meta[name="twitter:site"]`,{name:`twitter:site`,content:n.site}),n.creator&&t(`meta[name="twitter:creator"]`,{name:`twitter:creator`,content:n.creator}),n.title&&t(`meta[name="twitter:title"]`,{name:`twitter:title`,content:n.title}),n.description&&t(`meta[name="twitter:description"]`,{name:`twitter:description`,content:n.description}),n.images&&n.images.length>0){document.querySelectorAll(`meta[name="twitter:image"]`).forEach(e=>e.remove());for(let e of n.images){let t=document.createElement(`meta`);t.setAttribute(`name`,`twitter:image`),t.setAttribute(`content`,e),document.head.appendChild(t)}}}}function B({children:n,initialRoute:r,staleWindowMs:i=3e4}){let[a,o]=S(()=>({currentRoute:N(r),navigationId:0,error:null})),s=x(null),c=x(!0),l=x(N(r)),u=x(new O({timeout:1e4,maxRetries:3,onError:e=>{console.error(`[rari] Router: Navigation error:`,e)},onRetry:()=>{}})),d=x(new Map),f=x([]),p=x(new R({maxHistorySize:50})),m=x(null),h=x(i),g=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,_=()=>{s.current&&=(s.current.abort(),null)},v=()=>{for(let[,e]of d.current.entries())e.abortController.abort();d.current.clear()},D=(e,t)=>{d.current.delete(e),c.current&&a.navigationId===t&&o(e=>({...e}))},k=async e=>L.get(e),A=x(null),j=async(e,t={})=>{if(!e||typeof e!=`string`){console.error(`[rari] Router: Invalid navigation target:`,e);return}let[n,r]=e.includes(`#`)?e.split(`#`):[e,``],i=N(n);if(i===l.current&&!t.replace){if(r){let e=document.getElementById(r);e&&(e.scrollIntoView({behavior:`smooth`,block:`start`}),window.history.pushState(window.history.state,``,`${i}#${r}`))}return}let f=d.current.get(i);if(f)return f.promise;let m=await k(i);v(),_();let h=new AbortController;s.current=h;let y=a.navigationId+1,b=(async()=>{let e=l.current;try{t.historyKey||p.current.captureState(e);let n=t.historyKey||g(),a={route:i,navigationId:y,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:n},s=r?`${i}#${r}`:i;t.replace?window.history.replaceState(a,``,s):window.history.pushState(a,``,s);let f=window.location.origin+i,_=await fetch(f,{headers:{Accept:`text/x-component`},signal:h.signal});if(!_.ok&&_.status!==404)throw Error(`Failed to fetch: ${_.status}`);let v=new URL(_.url).pathname,b=v===i?i:v;if(v!==i){let e=r?`${v}#${r}`:v;window.history.replaceState({route:v,navigationId:y,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:t.historyKey||g()},``,e)}if(h.signal.aborted){D(b,y);return}try{let e=_.headers.get(`x-rari-metadata`);if(e){let t=decodeURIComponent(e);z(JSON.parse(t))}}catch{}let x=_.headers.get(`x-render-mode`)===`streaming`,S=m?.segments&&M(``,m.segments,b)||{};if(x&&_.body){let n=_.body.getReader(),r=new TextDecoder,i=``;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;if(h.signal.aborted){await n.cancel(),D(b,y);return}i+=r.decode(t,{stream:!0});let a=i.split(`
|
|
2
|
-
`);
|
|
3
|
-
`,this.state.error.stack]})]}),
|
|
1
|
+
import{i as e,t}from"./navigate-hfIqe3MK.mjs";import{_ as n,a as r,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,n as f,o as p,p as m,r as h,s as g,t as _}from"./runtime-client-yoJmu7vX.mjs";import{Component as v,useEffect as y,useLayoutEffect as ee,useRef as b,useState as x}from"react";import{Fragment as S,jsx as C,jsxs as w}from"react/jsx-runtime";function T(e,t,n={}){let r=null,i=0,a=0,o=null,s=null,{leading:c=!1,trailing:l=!0,maxWait:u}=n;function d(t){let n=o,r=s;return o=null,s=null,a=t,e.apply(r,n)}function f(e){let n=e-i,r=e-a;return i===0||n>=t||n<0||u!==void 0&&r>=u}function p(){let e=Date.now();if(f(e))return h(e);let n=e-i,o=e-a,s=t-n,c=u===void 0?1/0:u-o,l=Math.min(s,c);r=setTimeout(p,l)}function m(e){return a=e,r=setTimeout(p,t),c?d(e):void 0}function h(e){if(r=null,l&&o)return d(e);o=null,s=null}function g(){r!==null&&clearTimeout(r),a=0,o=null,i=0,s=null,r=null}function _(){return r===null?void 0:h(Date.now())}function v(){return r!==null}function y(...e){let n=Date.now(),a=f(n);if(o=e,s=this,i=n,a){if(r===null)return m(i);if(u!==void 0)return r=setTimeout(p,t),d(i)}r===null&&(r=setTimeout(p,t))}return y.cancel=g,y.flush=_,y.pending=v,y}const E=/fetch|networkerror|load failed/i;function D(e,t){return{type:`abort`,message:`Navigation was cancelled`,originalError:e,url:t,timestamp:Date.now(),retryable:!1}}function O(e,t){return{type:`timeout`,message:`Navigation request timed out`,originalError:e,url:t,timestamp:Date.now(),retryable:!0}}function k(e,t,n){if(t===404)return{type:`not-found`,message:`Page not found`,originalError:e,statusCode:t,url:n,timestamp:Date.now(),retryable:!1};if(t>=500)return{type:`server-error`,message:`Server error: ${t}`,originalError:e,statusCode:t,url:n,timestamp:Date.now(),retryable:!0};let r=t===408||t===429;return{type:`fetch-error`,message:`HTTP error: ${t}`,originalError:e,statusCode:t,url:n,timestamp:Date.now(),retryable:r}}function A(e,t){return{type:`network-error`,message:`Network error - check your connection`,originalError:e,url:t,timestamp:Date.now(),retryable:!0}}function j(e,t){return{type:`parse-error`,message:`Failed to parse server response`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}}function M(e,t){return{type:`fetch-error`,message:e instanceof Error?e.message:`Unknown error occurred`,originalError:e instanceof Error?e:void 0,url:t,timestamp:Date.now(),retryable:!1}}function N(e,t){if(e instanceof Error&&e.name===`AbortError`)return D(e,t);if(e instanceof Error&&(e.name===`TimeoutError`||e.message.includes(`timeout`)))return O(e,t);if(e instanceof Error&&`status`in e){let n=e.status;return typeof n==`number`?k(e,n,t):M(e,t)}return e instanceof TypeError&&E.test(e.message)?A(e,t):e instanceof SyntaxError||e instanceof Error&&e.message.includes(`parse`)?j(e,t):M(e,t)}var P=class{options;retryCount;constructor(e={}){this.options={timeout:e.timeout??1e4,maxRetries:e.maxRetries??3,onError:e.onError??(()=>{}),onRetry:e.onRetry??(()=>{})},this.retryCount=new Map}handleError(e,t){let n=N(e,t);return this.options.onError(n),console.error(`[rari] Navigation:`,n.type,n.message,{url:n.url,statusCode:n.statusCode,retryable:n.retryable}),n}canRetry(e,t){return e.retryable?(this.retryCount.get(t)??0)<this.options.maxRetries:!1}incrementRetry(e){let t=(this.retryCount.get(e)??0)+1;return this.retryCount.set(e,t),this.options.onRetry(t,{type:`fetch-error`,message:`Retry attempt ${t}`,url:e,timestamp:Date.now(),retryable:!0}),t}resetRetry(e){this.retryCount.delete(e)}getRetryCount(e){return this.retryCount.get(e)??0}clearRetries(){this.retryCount.clear()}};const F=/(^\/+)|(\/+$)/g;function I(e){let t=e.replace(F,``);return t?t.split(`/`):[]}function L(e){try{return decodeURIComponent(e)}catch{return null}}function R(e,t){let n=L(e),r=L(t);return n===null||r===null?!1:n===r}function z(e,t,n){if(!t)return!1;let r=L(e);return r===null?!1:(n[t]=r,!0)}function B(e,t,n,r){if(!n)return{success:!1,newIndex:t};let i=[];for(let n of e.slice(t)){let e=L(n);if(e===null)return{success:!1,newIndex:t};i.push(e)}return r[n]=i,{success:!0,newIndex:e.length}}function V(e,t,n,r){e>=t&&n&&(r[n]=[])}function H(e,t,n,r){if(n>=t.length)return e.type===`optional-catch-all`&&e.param?(V(n,t.length,e.param,r),{success:!0,newIndex:n}):{success:!1,newIndex:n};switch(e.type){case`static`:return R(t[n],e.value)?{success:!0,newIndex:n+1}:{success:!1,newIndex:n};case`dynamic`:return z(t[n],e.param,r)?{success:!0,newIndex:n+1}:{success:!1,newIndex:n};case`catch-all`:case`optional-catch-all`:return B(t,n,e.param,r);default:return{success:!1,newIndex:n}}}function U(e,t,n){let r=I(n),i={},a=0;for(let e of t){let t=H(e,r,a,i);if(!t.success)return null;a=t.newIndex}return a===r.length?i:null}function W(e){if(!e||e===`/`)return`/`;let t=e;for(;t.endsWith(`/`)&&t.length>1;)t=t.slice(0,-1);return t.startsWith(`/`)||(t=`/${t}`),t}function G(e,t){try{return new URL(e,t||window.location.origin).origin!==(t||window.location.origin)}catch{return!1}}function te(e){try{let t=new URL(e,window.location.origin);return t.pathname+t.hash}catch{return e}}function K({error:e,onRetry:t,onReload:n,onDismiss:r,retryCount:i=0,maxRetries:a=3}){let o=e.retryable&&i<a;return C(`div`,{style:{position:`fixed`,top:0,left:0,right:0,bottom:0,background:`rgba(0, 0, 0, 0.5)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:1e4,padding:`20px`},onClick:e=>{e.target===e.currentTarget&&r&&r()},children:w(`div`,{style:{background:`white`,borderRadius:`8px`,padding:`24px`,maxWidth:`500px`,width:`100%`,boxShadow:`0 4px 12px rgba(0, 0, 0, 0.15)`},onClick:e=>e.stopPropagation(),children:[w(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,marginBottom:`16px`},children:[C(`span`,{style:{fontSize:`32px`},children:(()=>{switch(e.type){case`timeout`:return`⏱️`;case`network-error`:return`📡`;case`not-found`:return`🔍`;case`server-error`:return`⚠️`;case`parse-error`:return`📄`;case`abort`:return`🚫`;default:return`❌`}})()}),C(`h2`,{style:{margin:0,fontSize:`20px`,fontWeight:`600`,color:`#1f2937`},children:`Navigation Error`})]}),C(`p`,{style:{margin:`0 0 16px 0`,fontSize:`15px`,lineHeight:`1.5`,color:`#4b5563`},children:(()=>{switch(e.type){case`timeout`:return`The page took too long to load. Please try again.`;case`network-error`:return`Unable to connect to the server. Please check your internet connection.`;case`not-found`:return`The page you're looking for doesn't exist.`;case`server-error`:return`The server encountered an error. Please try again in a moment.`;case`parse-error`:return`Unable to load the page content. Please try reloading.`;case`abort`:return`Navigation was cancelled.`;default:return e.message||`An unexpected error occurred.`}})()}),e.url&&w(`details`,{style:{marginBottom:`16px`,fontSize:`13px`,color:`#6b7280`},children:[C(`summary`,{style:{cursor:`pointer`,userSelect:`none`,marginBottom:`8px`},children:`Technical details`}),w(`div`,{style:{padding:`12px`,background:`#f9fafb`,borderRadius:`4px`,fontFamily:`monospace`,fontSize:`12px`,wordBreak:`break-all`},children:[w(`div`,{style:{marginBottom:`4px`},children:[C(`strong`,{children:`URL:`}),` `,e.url]}),e.statusCode&&w(`div`,{style:{marginBottom:`4px`},children:[C(`strong`,{children:`Status:`}),` `,e.statusCode]}),w(`div`,{style:{marginBottom:`4px`},children:[C(`strong`,{children:`Type:`}),` `,e.type]}),e.originalError&&w(`div`,{children:[C(`strong`,{children:`Error:`}),` `,e.originalError.message]})]})]}),o&&i>0&&w(`div`,{style:{marginBottom:`16px`,padding:`8px 12px`,background:`#fef3c7`,border:`1px solid #fbbf24`,borderRadius:`4px`,fontSize:`13px`,color:`#92400e`},children:[`Retry attempt`,` `,i,` `,`of`,` `,a]}),w(`div`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`},children:[o&&t&&C(`button`,{onClick:t,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#3b82f6`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#2563eb`},onMouseLeave:e=>{e.currentTarget.style.background=`#3b82f6`},children:`Try Again`}),n&&C(`button`,{onClick:n,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`#6b7280`,color:`white`,border:`none`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`background 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#4b5563`},onMouseLeave:e=>{e.currentTarget.style.background=`#6b7280`},children:`Reload Page`}),r&&C(`button`,{onClick:r,type:`button`,style:{flex:1,minWidth:`120px`,padding:`10px 16px`,background:`transparent`,color:`#6b7280`,border:`1px solid #d1d5db`,borderRadius:`6px`,fontSize:`14px`,fontWeight:`500`,cursor:`pointer`,transition:`all 0.2s`},onMouseEnter:e=>{e.currentTarget.style.background=`#f9fafb`,e.currentTarget.style.borderColor=`#9ca3af`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`,e.currentTarget.style.borderColor=`#d1d5db`},children:`Dismiss`})]}),C(`p`,{style:{marginTop:`16px`,marginBottom:0,fontSize:`12px`,color:`#9ca3af`,textAlign:`center`},children:`Your current page is still available below this message`})]})})}const q=new class{cache=new Map;pendingRequests=new Map;async get(e){let t=this.cache.get(e);if(t)return t;let n=this.pendingRequests.get(e);if(n)return n;let r=this.fetchRouteInfo(e);this.pendingRequests.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pendingRequests.delete(e)}}async fetchRouteInfo(e){let t={path:e},n=await fetch(`/_rari/route-info`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=null;try{e=await n.json()}catch{}throw e?.error?Error(e.error):Error(`Failed to fetch route info: ${n.status} ${n.statusText}`)}let r=n.clone();try{return await n.json()}catch(t){try{let e=await r.text();return JSON.parse(e)}catch(n){throw console.error(`[RouteInfo] Failed to parse response:`,{error:t,parseError:n,path:e}),Error(`Failed to parse route info response`)}}}clear(){this.cache.clear(),this.pendingRequests.clear()}invalidate(e){this.cache.delete(e)}};if(typeof window<`u`){let e=window[`~rari`]||{};window[`~rari`]||(window[`~rari`]=e),e.routeInfoCache=q}var J=class{stateHistory;routeAccessOrder;maxHistorySize;scrollableSelector;constructor(e={}){this.stateHistory=new Map,this.routeAccessOrder=[],this.maxHistorySize=e.maxHistorySize||50,this.scrollableSelector=e.scrollableSelector||`[data-scrollable], .scrollable, [style*="overflow"]`}captureState(e){let t={scrollPositions:this.captureScrollPositions(),formData:this.captureFormData(),focusedElement:this.captureFocusedElement()};return this.storeState(e,t),t}captureScrollPositions(){let e=new Map;try{e.set(`window`,{x:window.scrollX,y:window.scrollY,element:`window`}),document.querySelectorAll(this.scrollableSelector).forEach((t,n)=>{if(t instanceof HTMLElement){let r=t.id||`scrollable-${n}`;(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&e.set(r,{x:t.scrollLeft,y:t.scrollTop,element:r})}})}catch{}return e}captureFormData(){let e=new Map;try{document.querySelectorAll(`form`).forEach((t,n)=>{let r=t.id||t.name||`form-${n}`,i=new FormData(t);i.entries().next().done||e.set(r,i)})}catch{}return e}captureFocusedElement(){try{let e=document.activeElement;if(e&&e!==document.body){if(e.id)return`#${e.id}`;if((e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.name)return`[name="${e.name}"]`}}catch{}return null}storeState(e,t){let n=this.routeAccessOrder.indexOf(e);for(n!==-1&&this.routeAccessOrder.splice(n,1),this.routeAccessOrder.push(e),this.stateHistory.set(e,t);this.routeAccessOrder.length>this.maxHistorySize;){let e=this.routeAccessOrder.shift();e&&this.stateHistory.delete(e)}}getHistorySize(){return this.stateHistory.size}hasState(e){return this.stateHistory.has(e)}getState(e){return this.stateHistory.get(e)}clearAll(){this.stateHistory.clear(),this.routeAccessOrder=[]}clearState(e){this.stateHistory.delete(e);let t=this.routeAccessOrder.indexOf(e);t!==-1&&this.routeAccessOrder.splice(t,1)}restoreState(e){let t=this.stateHistory.get(e);if(!t)return!1;let n=!0;return this.restoreScrollPositions(t.scrollPositions)||(n=!1),this.restoreFormData(t.formData)||(n=!1),t.focusedElement&&this.restoreFocus(t.focusedElement),n}restoreScrollPositions(e){let t=!0;try{e.forEach((e,n)=>{try{if(n===`window`)window.scrollTo(e.x,e.y);else{let r=document.getElementById(n)||document.querySelector(`[data-scrollable-id="${n}"]`);r instanceof HTMLElement?(r.scrollLeft=e.x,r.scrollTop=e.y):t=!1}}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore scroll positions:`,e),t=!1}return t}restoreFormData(e){let t=!0;try{e.forEach((e,n)=>{try{let r=document.getElementById(n)||document.querySelector(`form[name="${n}"]`)||document.querySelectorAll(`form`)[Number.parseInt(n.replace(`form-`,``),10)];r instanceof HTMLFormElement?e.forEach((e,n)=>{try{let t=r.elements.namedItem(n);t instanceof RadioNodeList?t.forEach(t=>{t instanceof HTMLInputElement&&(t.type===`radio`||t.type===`checkbox`?t.checked=t.value===e:t.value=e)}):(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&(t instanceof HTMLInputElement&&(t.type===`checkbox`||t.type===`radio`)?t.checked=t.value===e:t.value=e)}catch{t=!1}}):t=!1}catch{t=!1}})}catch(e){console.error(`[rari] Router: Failed to restore form data:`,e),t=!1}return t}restoreFocus(e){try{let t=document.querySelector(e);t instanceof HTMLElement&&requestAnimationFrame(()=>{try{t.focus()}catch{}})}catch{}}};function Y(e,t){let n=document.querySelector(e);if(n)t.content&&n.setAttribute(`content`,t.content);else{n=document.createElement(`meta`);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);document.head.appendChild(n)}}function X(e){let t=document.querySelector(e);t&&t.remove()}function Z(e){e.title&&(document.title=e.title),e.description?Y(`meta[name="description"]`,{name:`description`,content:e.description}):X(`meta[name="description"]`),e.keywords&&e.keywords.length>0?Y(`meta[name="keywords"]`,{name:`keywords`,content:e.keywords.join(`, `)}):X(`meta[name="keywords"]`),e.viewport&&Y(`meta[name="viewport"]`,{name:`viewport`,content:e.viewport})}function Q(e){let t=document.querySelector(`link[rel="canonical"]`);if(e===void 0){t&&t.remove();return}if(t)t.setAttribute(`href`,e);else{let t=document.createElement(`link`);t.setAttribute(`rel`,`canonical`),t.setAttribute(`href`,e),document.head.appendChild(t)}}function $(e){if(e===void 0){X(`meta[name="robots"]`);return}let t=[];e.index!==void 0&&t.push(e.index?`index`:`noindex`),e.follow!==void 0&&t.push(e.follow?`follow`:`nofollow`),e.nocache&&t.push(`nocache`),t.length>0?Y(`meta[name="robots"]`,{name:`robots`,content:t.join(`, `)}):X(`meta[name="robots"]`)}function ne(e){if(e===void 0){X(`meta[property="og:title"]`),X(`meta[property="og:description"]`),X(`meta[property="og:url"]`),X(`meta[property="og:site_name"]`),X(`meta[property="og:type"]`),document.querySelectorAll(`meta[property="og:image"]`).forEach(e=>e.remove());return}if(e.title?Y(`meta[property="og:title"]`,{property:`og:title`,content:e.title}):X(`meta[property="og:title"]`),e.description?Y(`meta[property="og:description"]`,{property:`og:description`,content:e.description}):X(`meta[property="og:description"]`),e.url?Y(`meta[property="og:url"]`,{property:`og:url`,content:e.url}):X(`meta[property="og:url"]`),e.siteName?Y(`meta[property="og:site_name"]`,{property:`og:site_name`,content:e.siteName}):X(`meta[property="og:site_name"]`),e.type?Y(`meta[property="og:type"]`,{property:`og:type`,content:e.type}):X(`meta[property="og:type"]`),e.images&&e.images.length>0){document.querySelectorAll(`meta[property="og:image"]`).forEach(e=>e.remove());for(let t of e.images){let e=document.createElement(`meta`);e.setAttribute(`property`,`og:image`),e.setAttribute(`content`,t),document.head.appendChild(e)}}else document.querySelectorAll(`meta[property="og:image"]`).forEach(e=>e.remove())}function re(e){if(e===void 0){X(`meta[name="twitter:card"]`),X(`meta[name="twitter:site"]`),X(`meta[name="twitter:creator"]`),X(`meta[name="twitter:title"]`),X(`meta[name="twitter:description"]`),document.querySelectorAll(`meta[name="twitter:image"]`).forEach(e=>e.remove());return}if(e.card?Y(`meta[name="twitter:card"]`,{name:`twitter:card`,content:e.card}):X(`meta[name="twitter:card"]`),e.site?Y(`meta[name="twitter:site"]`,{name:`twitter:site`,content:e.site}):X(`meta[name="twitter:site"]`),e.creator?Y(`meta[name="twitter:creator"]`,{name:`twitter:creator`,content:e.creator}):X(`meta[name="twitter:creator"]`),e.title?Y(`meta[name="twitter:title"]`,{name:`twitter:title`,content:e.title}):X(`meta[name="twitter:title"]`),e.description?Y(`meta[name="twitter:description"]`,{name:`twitter:description`,content:e.description}):X(`meta[name="twitter:description"]`),e.images&&e.images.length>0){document.querySelectorAll(`meta[name="twitter:image"]`).forEach(e=>e.remove());for(let t of e.images){let e=document.createElement(`meta`);e.setAttribute(`name`,`twitter:image`),e.setAttribute(`content`,t),document.head.appendChild(e)}}else document.querySelectorAll(`meta[name="twitter:image"]`).forEach(e=>e.remove())}function ie(e){Z(e),Q(e.canonical),$(e.robots),ne(e.openGraph),re(e.twitter)}function ae({children:n,initialRoute:r,staleWindowMs:i=3e4}){let[a,o]=x(()=>({currentRoute:W(r),navigationId:0,error:null})),s=b(null),c=b(!0),l=b(W(r)),u=b(new P({timeout:1e4,maxRetries:3,onError:e=>{console.error(`[rari] Router: Navigation error:`,e)},onRetry:()=>{}})),d=b(new Map),f=b([]),p=b(new J({maxHistorySize:50})),m=b(null),h=b(i),g=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,_=()=>{s.current&&=(s.current.abort(),null)},v=()=>{for(let[,e]of d.current.entries())e.abortController.abort();d.current.clear()},E=(e,t)=>{d.current.delete(e),c.current&&a.navigationId===t&&o(e=>({...e}))},D=async e=>q.get(e),O=b(null),k=(e,t)=>{if(!t)return;let n=document.getElementById(t);n&&(n.scrollIntoView({behavior:`smooth`,block:`start`}),window.history.pushState(window.history.state,``,`${e}#${t}`))},A=e=>{try{let t=e.headers.get(`x-rari-metadata`);if(t){let e=decodeURIComponent(t);ie(JSON.parse(e))}}catch(e){console.warn(`[rari] Router: Failed to parse x-rari-metadata header:`,e)}},j=async(e,t,n,r,i,a,o,s,c)=>{if(!e.body)return;let l=e.body.getReader(),u=new TextDecoder,d=``;try{for(;;){let{done:e,value:r}=await l.read();if(e)break;if(t.signal.aborted){await l.cancel(),E(n,i);return}d+=u.decode(r,{stream:!0});let a=d.split(`
|
|
2
|
+
`);d=a.pop()||``;for(let e of a)e.trim()&&window.dispatchEvent(new CustomEvent(`rari:rsc-row`,{detail:{rscRow:e}}))}d+=u.decode(),d.trim()&&window.dispatchEvent(new CustomEvent(`rari:rsc-row`,{detail:{rscRow:d}})),window.dispatchEvent(new CustomEvent(`rari:navigate`,{detail:{from:a,to:r,navigationId:i,options:o,routeInfo:{...s,extractedParams:c},abortSignal:t.signal,isStreaming:!0}}))}catch(e){throw console.error(`[rari] Router: Streaming error:`,e),e}},M=async(e,t,n,r,i,a,o,s)=>{let c=await e.text();window.dispatchEvent(new CustomEvent(`rari:navigate`,{detail:{from:t,to:n,navigationId:r,options:i,routeInfo:{...a,extractedParams:o},abortSignal:s.signal,rscWireFormat:c}}))},N=(e,t,n)=>{n.historyKey?requestAnimationFrame(()=>{p.current.restoreState(e)}):t&&requestAnimationFrame(()=>{let e=(n=0)=>{let r=document.getElementById(t);r?r.scrollIntoView({behavior:`smooth`,block:`start`}):n<10&&setTimeout(e,50,n+1)};e()})},F=(e,t,n,r)=>{c.current&&(l.current=e,o(t=>({...t,currentRoute:e,navigationId:r,error:null})),u.current.resetRetry(e),N(e,t,n))},I=(e,t,n,r)=>{if(e instanceof Error&&e.name===`AbortError`){E(t,n);return}let i=u.current.handleError(e,t);c.current&&o(e=>({...e,error:i})),d.current.delete(t),window.dispatchEvent(new CustomEvent(`rari:navigate-error`,{detail:{from:r,to:t,error:i,navigationId:n}})),O.current?.()},L=async(e,t={})=>{if(!e||typeof e!=`string`){console.error(`[rari] Router: Invalid navigation target:`,e);return}let[n,r]=e.includes(`#`)?e.split(`#`):[e,``],i=W(n);if(i===l.current&&!t.replace){k(i,r);return}let o=d.current.get(i);if(o)return o.promise;let c=await D(i);v(),_();let u=new AbortController;s.current=u;let f=a.navigationId+1,m=(async()=>{let e=l.current;try{t.historyKey||p.current.captureState(e);let n=t.historyKey||g(),a=window.location.origin+i,o=await fetch(a,{headers:{Accept:`text/x-component`},signal:u.signal});if(!o.ok&&o.status!==404)throw Error(`Failed to fetch: ${o.status}`);let s=new URL(o.url).pathname;if(u.signal.aborted){E(i,f);return}let l=r?`${s}#${r}`:s,m={route:s,navigationId:f,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:n};t.replace?window.history.replaceState(m,``,l):window.history.pushState(m,``,l),A(o);let h=o.headers.get(`x-render-mode`)===`streaming`,_=c?.segments&&U(``,c.segments,s)||{};if(h&&o.body?await j(o,u,i,s,f,e,t,c,_):await M(o,e,s,f,t,c,_,u),u.signal.aborted){E(i,f);return}F(s,r,t,f),d.current.delete(i),O.current?.()}catch(t){I(t,i,f,e)}})();return d.current.set(i,{targetPath:i,navigationId:f,promise:m,abortController:u}),m},R=async()=>{if(f.current.length===0)return;let e=f.current.at(-1);e&&(f.current=[],await L(e.path,e.options))},z=b(L);ee(()=>(O.current=R,z.current=L,()=>{O.current=null,z.current=null}));let B=b(null);B.current||=T((e,t)=>{z.current?.(e,t)},50,{leading:!1,trailing:!0,maxWait:200});let V=e=>{if(e.button!==0||e.ctrlKey||e.shiftKey||e.altKey||e.metaKey)return;let t=e.target;for(;t&&t.tagName!==`A`;)t=t.parentElement;if(!t||t.tagName!==`A`)return;let n=t;if(n.target&&n.target!==`_self`||n.hasAttribute(`download`))return;let r=n.getAttribute(`href`);if(!r||G(r))return;if(r.startsWith(`#`)){e.preventDefault();let t=r.slice(1),n=document.getElementById(t);n&&(n.scrollIntoView({behavior:`smooth`,block:`start`}),window.history.pushState(window.history.state,``,r));return}e.preventDefault();let i=te(r);B.current&&B.current(i,{replace:!1})},H=e=>{let t=window.location.pathname,n=e.state;z.current&&z.current(t,{replace:!0,scroll:!1,historyKey:n?.key})},Y=()=>{if(a.error&&a.error.url){let e=a.error.url;u.current.incrementRetry(e),L(e,{replace:!1})}},X=()=>{window.location.reload()},Z=()=>{o(e=>({...e,error:null}))};y(()=>{let e=window.history.state;if(!e||!e.key){let e={route:W(r),navigationId:0,scrollPosition:{x:window.scrollX,y:window.scrollY},timestamp:Date.now(),key:g()};window.history.replaceState(e,``,window.location.pathname+window.location.search+window.location.hash)}},[r]);let Q=e=>{if(e.persisted){let e=window.location.pathname;p.current.captureState(e)}},$=e=>{if(e.persisted){let e=window.location.pathname,t=window.history.state;requestAnimationFrame(()=>{p.current.restoreState(e),t?.scrollPosition&&window.scrollTo(t.scrollPosition.x,t.scrollPosition.y)})}};return y(()=>(document.addEventListener(`click`,V),window.addEventListener(`popstate`,H),window.addEventListener(`pagehide`,Q),window.addEventListener(`pageshow`,$),()=>{document.removeEventListener(`click`,V),window.removeEventListener(`popstate`,H),window.removeEventListener(`pagehide`,Q),window.removeEventListener(`pageshow`,$)}),[]),y(()=>{h.current=i;let e=()=>{document.hidden?m.current=Date.now():m.current!==null&&Date.now()-m.current>h.current&&q.clear()};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[i]),y(()=>(c.current=!0,e((e,t)=>z.current?.(e,t)??Promise.resolve()),()=>{c.current=!1,t(),_(),v(),B.current?.cancel&&B.current.cancel()}),[]),w(S,{children:[n,a.error&&C(K,{error:a.error,onRetry:Y,onReload:X,onDismiss:Z,retryCount:u.current.getRetryCount(a.error.url||``),maxRetries:3})]})}var oe=class extends v{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[rari] Layout: Error in layout "${this.props.layoutPath}":`,e,t),this.props.onError&&this.props.onError(e,t),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`rari:layout-error`,{detail:{layoutPath:this.props.layoutPath,error:e,errorInfo:t,timestamp:Date.now()}}))}reset=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?this.props.fallback(this.state.error,this.reset):w(`div`,{style:{padding:`16px`,margin:`16px 0`,background:`#fee`,border:`1px solid #fcc`,borderRadius:`4px`},children:[C(`h3`,{style:{margin:`0 0 8px 0`,color:`#c00`},children:`Layout Error`}),w(`p`,{style:{margin:`0 0 8px 0`,fontSize:`14px`},children:[`An error occurred in layout:`,` `,C(`code`,{children:this.props.layoutPath})]}),w(`details`,{style:{fontSize:`12px`,marginBottom:`8px`},children:[C(`summary`,{style:{cursor:`pointer`},children:`Error details`}),w(`pre`,{style:{marginTop:`8px`,padding:`8px`,background:`#fff`,border:`1px solid #ddd`,borderRadius:`2px`,overflow:`auto`},children:[this.state.error.message,`
|
|
3
|
+
`,this.state.error.stack]})]}),C(`button`,{onClick:this.reset,type:`button`,style:{padding:`6px 12px`,background:`#c00`,color:`white`,border:`none`,borderRadius:`4px`,cursor:`pointer`,fontSize:`14px`},children:`Try Again`})]}):this.props.children}};export{ae as ClientRouter,_ as DefaultError,f as DefaultLoading,h as ErrorBoundary,l as HttpRuntimeClient,oe as LayoutErrorBoundary,r as LoadingSpinner,P as NavigationErrorHandler,K as NavigationErrorOverlay,p as NotFound,J as StatePreserver,a as clearPropsCache,o as clearPropsCacheForComponent,g as createErrorBoundary,i as createHttpRuntimeClient,u as createLoadingBoundary,m as extractMetadata,d as extractServerProps,c as extractServerPropsWithCache,s as extractStaticParams,n as hasServerSideDataFetching};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e.loading=!0,e.loadPromise=e.loader().then(t=>{let n=t.default||t;return e.component=n,e.registered=!0,e.loading=!1,n}).catch(t=>{throw console.error(`[rari] Failed to load component ${e.id}:`,t),e.loading=!1,e.loadPromise=void 0,t}),e.loadPromise}async function t(t,n){if(t.component!=null){if(n&&n!==`default`){let e=t.component[n];return e===void 0?null:e}return t.component}if(t.loadPromise){if(await t.loadPromise,n&&n!==`default`){let e=t.component?.[n];return e===void 0?null:e}return t.component??null}if(t.loader){let r=await e(t);if(r==null)return null;if(n&&n!==`default`){let e=r[n];return e===void 0?null:e}return r}return null}function n(t){return!t.loader||t.loading||t.component!=null||t.loadPromise?Promise.resolve(null):e(t)}function r(e,t){return e.component||e.loader&&!e.loading&&(e.loading=!0,e.loadPromise=e.loader().then(t=>(e.component=t.default||t,e.registered=!0,e.loading=!1,e.component)).catch(n=>{e.loading=!1,e.loadPromise=void 0,console.error(`[rari] Failed to load component ${t}:`,n)})),null}function i(e,t){return e.component==null?null:!t||t===`default`?e.component:e.component[t]}function a(e){e.loader&&!e.loading&&!e.loadPromise&&n(e).catch(()=>{})}function o(e,t){let n=e.indexOf(`#`),r=n===-1?e:e.slice(0,n),i=n===-1?void 0:e.slice(n+1),o=t[r];if(!o)return null;if(o.component!=null){if(i&&i!==`default`){let e=o.component[i];return e===void 0?null:e}return o.component}return a(o),null}function s(e,t,n,r){let o=r[e];if(!o||!n[o])return null;let s=n[o];return i(s,t)??(a(s),null)}function c(e,t,n){let r=e.indexOf(`#`),i=r===-1?e:e.slice(0,r),a=r===-1?``:e.slice(r+1),o=f(i);for(let e of o){let r=s(e,a,t,n);if(r!==null)return r}return null}function l(e,t,n){let r=e.indexOf(`#`),o=r===-1?e:e.slice(0,r),s=r===-1?void 0:e.slice(r+1),c=n[o];if(!c||!t[c])return null;let l=t[c];return i(l,s)??(a(l),null)}function u(e,t){let n=t[`~clientComponents`]||{},r=t[`~clientComponentPaths`]||{},i=t[`~clientComponentNames`]||{},a=o(e,n);if(a!==null)return a;let s=c(e,n,r);return s===null?l(e,n,i):s}function d(e){return u(e,globalThis)}function f(e){return e.startsWith(`./`)?[e,e.slice(2)]:[e,`./${e}`]}async function p(e){let n=globalThis[`~clientComponents`]||{},r=globalThis[`~clientComponentPaths`]||{},i=globalThis[`~clientComponentNames`]||{},a=e.indexOf(`#`),o=a===-1?e:e.slice(0,a),s=a===-1?void 0:e.slice(a+1),c=n[o];if(c)return await t(c,s);let l=f(o);for(let e of l){let i=r[e];if(i&&(c=n[i],c))return await t(c,s)}let u=i[o];return u&&(c=n[u],c)?await t(c,s):null}export{p as n,r,d as t};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { d as Metadata, l as LayoutProps, p as PageProps } from "./types-
|
|
2
|
-
import { a as SitemapImage, i as SitemapEntry, n as RobotsRule, o as SitemapVideo, r as Sitemap, t as Robots } from "./metadata-route-
|
|
3
|
-
import { c as RariURL, n as ProxyConfig, r as ProxyFunction, s as RariFetchEvent } from "./types-
|
|
1
|
+
import { d as Metadata, l as LayoutProps, p as PageProps } from "./types-Cfe0C3JU.mjs";
|
|
2
|
+
import { a as SitemapImage, i as SitemapEntry, n as RobotsRule, o as SitemapVideo, r as Sitemap, t as Robots } from "./metadata-route-BDdxZuGv.mjs";
|
|
3
|
+
import { c as RariURL, n as ProxyConfig, r as ProxyFunction, s as RariFetchEvent } from "./types-BhqnAV4k.mjs";
|
|
4
4
|
import { RariRequest } from "./proxy/RariRequest.mjs";
|
|
5
5
|
import { RariResponse } from "./proxy/RariResponse.mjs";
|
|
6
6
|
export { type LayoutProps, type Metadata, type PageProps, type ProxyConfig, type ProxyFunction, type RariFetchEvent, RariRequest, RariResponse, type RariURL, type Robots, type RobotsRule, type Sitemap, type SitemapEntry, type SitemapImage, type SitemapVideo };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/proxy/
|
|
1
|
+
//#region src/proxy/shared/utils.d.ts
|
|
2
2
|
interface SimpleRequest {
|
|
3
3
|
url: string;
|
|
4
4
|
method: string;
|
|
@@ -11,14 +11,16 @@ interface SimpleProxyResult {
|
|
|
11
11
|
permanent: boolean;
|
|
12
12
|
};
|
|
13
13
|
rewrite?: string;
|
|
14
|
-
requestHeaders?: Record<string, string>;
|
|
15
|
-
responseHeaders?: Record<string, string>;
|
|
14
|
+
requestHeaders?: Record<string, string | string[]>;
|
|
15
|
+
responseHeaders?: Record<string, string | string[]>;
|
|
16
16
|
response?: {
|
|
17
17
|
status: number;
|
|
18
|
-
headers: Record<string, string>;
|
|
18
|
+
headers: Record<string, string | string[]>;
|
|
19
19
|
body?: string;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/proxy/runtime-executor.d.ts
|
|
22
24
|
declare global {
|
|
23
25
|
interface GlobalThis {
|
|
24
26
|
'~rariExecuteProxy'?: (request: SimpleRequest) => Promise<SimpleProxyResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function e(e){if(!e)return null;let t=e.headers?.get?.(`x-rari-proxy-rewrite`);return t?{continue:!1,rewrite:t}:null}function t(e){if(!e||e.status==null)return null;let t=e.headers?.get?.(`location`);return t&&e.status>=300&&e.status<400?{continue:!1,redirect:{destination:t,permanent:e.status===301||e.status===308}}:null}function n(e,t,n){if(Object.hasOwn(e,t)){let r=e[t];e[t]=Array.isArray(r)?[...r,n]:[r,n]}else e[t]=n}function r(e){let t={},r={};return e?.forEach&&e.forEach((e,i)=>{let a=i.toLowerCase();a.startsWith(`x-rari-proxy-request-`)?n(t,a.replace(`x-rari-proxy-request-`,``),e):a.startsWith(`x-rari-proxy-`)||n(r,a,e)}),{requestHeaders:Object.keys(t).length>0?t:void 0,responseHeaders:Object.keys(r).length>0?r:void 0}}function i(e){let{requestHeaders:t,responseHeaders:n}=r(e.headers);return{continue:!0,requestHeaders:t,responseHeaders:n}}async function a(e){let t={};e.headers?.forEach&&e.headers.forEach((e,r)=>{n(t,r.toLowerCase(),e)});let r;try{e.text&&typeof e.text==`function`?r=await e.text():e.body!=null&&typeof e.body==`string`?r=e.body:e.body!=null&&console.warn(`[rari] Proxy: Response body is not extractable as text`)}catch(e){console.error(`[rari] Proxy: Failed to extract response body:`,e)}return{continue:!1,response:{status:e.status??200,headers:t,body:r}}}async function o(n){return n?e(n)||t(n)||(n.headers?.get?.(`x-rari-proxy-continue`)===`true`?i(n):n.status==null?{continue:!0}:await a(n)):{continue:!0}}async function s(e,t){try{let n=await import(e);if(!n||!n.proxy)return console.error(`[rari] Proxy: proxy function not found in module`),!1;let{RariRequest:r}=await import(t);return globalThis[`~rariExecuteProxy`]=async function(e){try{let t=new r(e.url,{method:e.method,headers:new Headers(e.headers)}),i=[],a=await n.proxy(t,{waitUntil:e=>{e.catch(()=>{}),i.push(e)}});return i.length>0&&Promise.allSettled(i).then(e=>{e.forEach((e,t)=>{e.status===`rejected`&&console.error(`[rari] Proxy: waitUntil promise ${t} failed:`,e.reason)})}),await o(a)}catch(e){return console.error(`[rari] Proxy: Proxy execution error:`,e),{continue:!0}}},!0}catch(e){return console.error(`[rari] Proxy: Failed to initialize proxy executor:`,e),!1}}export{s as initializeProxyExecutor};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,t as a}from"./utils-BGFxUpBh-CWvq2hOR.mjs";import{existsSync as o,readFileSync as s,writeFileSync as c}from"node:fs";import{join as l}from"node:path";import u from"node:process";import{styleText as d}from"node:util";function f(){let r=u.cwd();e(`Creating Railway deployment configuration...`),t(r,{providerName:`Railway`,deployScript:`echo "Push to GitHub and connect to Railway to deploy"`,startScript:`rari start`,dependency:n()}),p(r),a(r,`Railway`,`.railway`),m(r),h()}function p(e){i(e,`railway.toml`,`[build]
|
|
2
|
+
builder = "RAILPACK"
|
|
3
|
+
|
|
4
|
+
[deploy]
|
|
5
|
+
startCommand = "npm start"
|
|
6
|
+
healthcheckPath = "/"
|
|
7
|
+
healthcheckTimeout = 300
|
|
8
|
+
restartPolicyType = "ON_FAILURE"
|
|
9
|
+
restartPolicyMaxRetries = 3
|
|
10
|
+
`)}function m(e){let t=l(e,`README.md`),n=`
|
|
11
|
+
## 🚂 Deploy to Railway
|
|
12
|
+
|
|
13
|
+
This rari application is configured for Railway deployment.
|
|
14
|
+
|
|
15
|
+
### Quick Deploy
|
|
16
|
+
|
|
17
|
+
1. **Push to GitHub**:
|
|
18
|
+
\`\`\`bash
|
|
19
|
+
git add .
|
|
20
|
+
git commit -m "Add Railway deployment"
|
|
21
|
+
git push origin main
|
|
22
|
+
\`\`\`
|
|
23
|
+
|
|
24
|
+
2. **Deploy to Railway**:
|
|
25
|
+
- Go to [railway.app](https://railway.app)
|
|
26
|
+
- Create new project → "Deploy from GitHub repo"
|
|
27
|
+
- Select your repository
|
|
28
|
+
- Click "Deploy Now"
|
|
29
|
+
|
|
30
|
+
3. **Generate Domain**:
|
|
31
|
+
- In Railway dashboard → Settings → Networking
|
|
32
|
+
- Click "Generate Domain"
|
|
33
|
+
- Your app will be live! 🎉
|
|
34
|
+
|
|
35
|
+
### Local Development
|
|
36
|
+
|
|
37
|
+
\`\`\`bash
|
|
38
|
+
# Development server
|
|
39
|
+
npm run start:local
|
|
40
|
+
|
|
41
|
+
# Production simulation
|
|
42
|
+
npm start
|
|
43
|
+
\`\`\`
|
|
44
|
+
|
|
45
|
+
### Environment Variables
|
|
46
|
+
|
|
47
|
+
Railway automatically provides:
|
|
48
|
+
- \`PORT\` - Server port (Railway assigns this)
|
|
49
|
+
- \`NODE_ENV=production\` - Production mode
|
|
50
|
+
|
|
51
|
+
Optional variables you can set:
|
|
52
|
+
- \`RUST_LOG=debug\` - Rust logging level
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
`;if(o(t)){let e=s(t,`utf-8`);e.includes(`Deploy to Railway`)||(c(t,e+n),r(`Updated README.md with Railway deployment instructions`))}else c(t,`# My rari App
|
|
56
|
+
|
|
57
|
+
A high-performance React Server Components application powered by rari.
|
|
58
|
+
${n}
|
|
59
|
+
## Getting Started
|
|
60
|
+
|
|
61
|
+
\`\`\`bash
|
|
62
|
+
npm install
|
|
63
|
+
npm start
|
|
64
|
+
\`\`\`
|
|
65
|
+
|
|
66
|
+
Visit [http://localhost:3000](http://localhost:3000) to see your app.
|
|
67
|
+
`),r(`Created README.md with Railway deployment instructions`)}function h(){console.warn(``),r(`Railway deployment setup complete! 🎉`),console.warn(``),e(`Next steps:`),console.warn(` 1. ${d(`cyan`,`git add .`)}`),console.warn(` 2. ${d(`cyan`,`git commit -m "Add Railway deployment"`)}`),console.warn(` 3. ${d(`cyan`,`git push origin main`)}`),console.warn(` 4. Go to ${d(`cyan`,`https://railway.app`)} and deploy from GitHub`),console.warn(``),e(`Your rari app will automatically:`),console.warn(` ✅ Detect Railway environment`),console.warn(` ✅ Bind to 0.0.0.0 (Railway requirement)`),console.warn(` ✅ Use Railway's PORT environment variable`),console.warn(` ✅ Run in production mode`),console.warn(` ✅ Download platform-specific rari binary`),console.warn(``),r(`Ready for deployment! 🚀`)}export{f as createRailwayDeployment};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,t as a}from"./utils-BGFxUpBh-CWvq2hOR.mjs";import{existsSync as o,readFileSync as s,writeFileSync as c}from"node:fs";import{join as l}from"node:path";import u from"node:process";import{styleText as d}from"node:util";function f(){let r=u.cwd();e(`Creating Render deployment configuration...`),t(r,{providerName:`Render`,deployScript:`echo "Push to GitHub and connect to Render to deploy"`,startScript:`rari start`,dependency:n()}),p(r),a(r,`Render`,`.render`),m(r),h()}function p(e){i(e,`render.yaml`,`services:
|
|
2
|
+
- type: web
|
|
3
|
+
name: rari-app
|
|
4
|
+
runtime: node
|
|
5
|
+
env: node
|
|
6
|
+
plan: free
|
|
7
|
+
buildCommand: npm install
|
|
8
|
+
startCommand: npm start
|
|
9
|
+
healthCheckPath: /
|
|
10
|
+
envVars:
|
|
11
|
+
- key: NODE_ENV
|
|
12
|
+
value: production
|
|
13
|
+
- key: RUST_LOG
|
|
14
|
+
value: info
|
|
15
|
+
`)}function m(e){let t=l(e,`README.md`),n=`
|
|
16
|
+
## 🎨 Deploy to Render
|
|
17
|
+
|
|
18
|
+
This rari application is configured for Render deployment.
|
|
19
|
+
|
|
20
|
+
### Quick Deploy
|
|
21
|
+
|
|
22
|
+
1. **Push to GitHub**:
|
|
23
|
+
\`\`\`bash
|
|
24
|
+
git add .
|
|
25
|
+
git commit -m "Add Render deployment"
|
|
26
|
+
git push origin main
|
|
27
|
+
\`\`\`
|
|
28
|
+
|
|
29
|
+
2. **Deploy to Render**:
|
|
30
|
+
- Go to [render.com](https://render.com)
|
|
31
|
+
- Create new "Web Service"
|
|
32
|
+
- Connect your GitHub repository
|
|
33
|
+
- Render will auto-detect Node.js and use the configuration from \`render.yaml\`
|
|
34
|
+
- Click "Create Web Service"
|
|
35
|
+
|
|
36
|
+
3. **Your app will be live!** 🎉
|
|
37
|
+
- Render provides a \`.onrender.com\` URL
|
|
38
|
+
- Optional: Add custom domain in Render dashboard
|
|
39
|
+
|
|
40
|
+
### Local Development
|
|
41
|
+
|
|
42
|
+
\`\`\`bash
|
|
43
|
+
# Development server
|
|
44
|
+
npm run start:local
|
|
45
|
+
|
|
46
|
+
# Production simulation
|
|
47
|
+
npm start
|
|
48
|
+
\`\`\`
|
|
49
|
+
|
|
50
|
+
### Environment Variables
|
|
51
|
+
|
|
52
|
+
Render automatically provides:
|
|
53
|
+
- \`PORT\` - Server port (Render assigns this)
|
|
54
|
+
- \`NODE_ENV=production\` - Production mode (from render.yaml)
|
|
55
|
+
- \`RUST_LOG=info\` - Rust logging level (from render.yaml)
|
|
56
|
+
|
|
57
|
+
Optional variables you can add in Render dashboard:
|
|
58
|
+
- \`RUST_LOG=debug\` - Enhanced logging
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
`;if(o(t)){let e=s(t,`utf-8`);e.includes(`Deploy to Render`)||(c(t,e+n),r(`Updated README.md with Render deployment instructions`))}else c(t,`# My rari App
|
|
62
|
+
|
|
63
|
+
A high-performance React Server Components application powered by rari.
|
|
64
|
+
${n}
|
|
65
|
+
## Getting Started
|
|
66
|
+
|
|
67
|
+
\`\`\`bash
|
|
68
|
+
npm install
|
|
69
|
+
npm start
|
|
70
|
+
\`\`\`
|
|
71
|
+
|
|
72
|
+
Visit [http://localhost:3000](http://localhost:3000) to see your app.
|
|
73
|
+
`),r(`Created README.md with Render deployment instructions`)}function h(){console.warn(``),r(`Render deployment setup complete! 🎉`),console.warn(``),e(`Next steps:`),console.warn(` 1. ${d(`cyan`,`git add .`)}`),console.warn(` 2. ${d(`cyan`,`git commit -m "Add Render deployment"`)}`),console.warn(` 3. ${d(`cyan`,`git push origin main`)}`),console.warn(` 4. Go to ${d(`cyan`,`https://render.com`)} and create a Web Service`),console.warn(``),e(`Your rari app will automatically:`),console.warn(` ✅ Detect Render environment`),console.warn(` ✅ Bind to 0.0.0.0 (Render requirement)`),console.warn(` ✅ Use Render's PORT environment variable`),console.warn(` ✅ Run in production mode`),console.warn(` ✅ Download platform-specific rari binary`),console.warn(``),r(`Ready for deployment! 🚀`)}export{f as createRenderDeployment};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{promises as e}from"node:fs";import t from"node:path";import{Buffer as n}from"node:buffer";function r(e){return Array.isArray(e)?e:e?[e]:[`*`]}function i(e){return e===void 0?[]:(Array.isArray(e)?e:[e]).filter(e=>e!==``)}function a(e){let t=[],n=r(e.userAgent);for(let r of n){t.push(`User-Agent: ${r}`);let n=i(e.allow);for(let e of n)t.push(`Allow: ${e}`);let a=i(e.disallow);for(let e of a)t.push(`Disallow: ${e}`);e.crawlDelay!==void 0&&t.push(`Crawl-delay: ${e.crawlDelay}`),t.push(``)}return t}function o(e){return e?[`Host: ${e}`,``]:[]}function s(e){return i(e).map(e=>`Sitemap: ${e}`)}function c(e){let t=[],n=Array.isArray(e.rules)?e.rules:[e.rules];for(let e of n)t.push(...a(e));return t.push(...o(e.host)),t.push(...s(e.sitemap)),t.join(`
|
|
2
|
+
`)}async function l(n,r=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`]){let i=t.join(n,`robots.txt`);try{return await e.access(i),{type:`static`,path:i}}catch(e){if(e?.code!==`ENOENT`)throw e}for(let i of r){let r=t.join(n,`robots${i}`);try{return await e.access(r),{type:`dynamic`,path:r}}catch(e){if(e?.code!==`ENOENT`)throw e}}return null}async function u(r){let{appDir:i,outDir:a,extensions:o}=r,s=await l(i,o);if(!s)return!1;let u=t.join(a,`robots.txt`);if(await e.mkdir(t.dirname(u),{recursive:!0}),s.type===`static`)return await e.copyFile(s.path,u),!0;try{let{build:r}=await import(`rolldown`),i=await e.readFile(s.path,`utf-8`),a=`\0virtual:robots`,o=await r({input:a,external:[`rari`],platform:`node`,write:!1,output:{format:`esm`,codeSplitting:!1},plugins:[{name:`virtual-robots`,resolveId(e){return e===a?e:e.startsWith(`.`)?t.resolve(t.dirname(s.path),e):null},load(e){if(e===a){let e=t.extname(s.path).slice(1),n;switch(e){case`ts`:n=`ts`;break;case`tsx`:n=`tsx`;break;case`js`:case`mjs`:case`cjs`:n=`js`;break;case`jsx`:n=`jsx`;break;default:throw Error(`Unsupported robots file extension: .${e}. Supported extensions are: .ts, .tsx, .js, .jsx, .mjs, .cjs`)}return{code:i,moduleType:n}}return null}}]});if(!o.output||o.output.length===0)throw Error(`Failed to build robots module`);let l=o.output.find(e=>e.type===`chunk`&&e.isEntry)||o.output.find(e=>e.type===`chunk`);if(!l||l.type!==`chunk`)throw Error(`No chunk output found in robots build result`);let d=l.code,f=await import(`data:text/javascript;base64,${n.from(d).toString(`base64`)}`);if(!f||f.default==null)throw Error(`Robots file must export a default export (either an object or a function)`);let p;if(typeof f.default==`function`){let e=f.default();p=e instanceof Promise?await e:e}else p=f.default;let m=c(p);return await e.writeFile(u,m),!0}catch(e){return console.error(`[rari] Failed to build/execute robots file:`,e),!1}}export{u as generateRobotsFile};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use client";import{S as e,b as t}from"../regex-constants-DOQkuGm5.mjs";import{t as n}from"../preload-components-
|
|
1
|
+
"use client";import{S as e,b as t}from"../regex-constants-DOQkuGm5.mjs";import{t as n}from"../preload-components-DD3aKUwy.mjs";import*as r from"react";import{Suspense as i,useEffect as a,useRef as o,useState as s,useTransition as c}from"react";import{Fragment as l,jsx as u,jsxs as d}from"react/jsx-runtime";const f=/"timestamp":(\d+)/,p=/^[;\s]*$/;function m(){return d(`div`,{style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:9999},children:[u(`div`,{style:{width:`40px`,height:`40px`,border:`4px solid rgba(0, 0, 0, 0.1)`,borderTopColor:`#3b82f6`,borderRadius:`50%`,animation:`spin 1s linear infinite`}}),u(`style`,{children:`
|
|
2
2
|
@keyframes spin {
|
|
3
3
|
to { transform: rotate(360deg); }
|
|
4
4
|
}
|
|
5
|
-
`})]})}function
|
|
6
|
-
`),
|
|
7
|
-
`),t=await
|
|
5
|
+
`})]})}function ee({contentRef:e,rowsDataRef:t,modulesDataRef:n,symbolsDataRef:i,suspendingPromisesRef:a,getSuspendingPromise:o,rscToReact:s}){let c=t.current,l=n.current,u=i.current,d=a.current,f=c.has(e);if(r.useEffect(()=>{f&&d.has(e)&&d.delete(e)},[e,f,d]),f)return s(c.get(e),l,void 0,u,c);throw o(e)}function h({children:h,initialPayload:te,onNavigate:g}){let[_,v]=s(te),[,y]=s(0),b=o({x:0,y:0}),x=o(new Map),S=o(null),[,C]=c(),w=o(g),T=o(0),E=o(new Map),D=o([]),O=o(null),k=o(0),[A,j]=s(null),M=o(typeof window<`u`&&window.location.hash.length>0),N=o(0);a(()=>{w.current=g},[g]);let P=()=>{if(typeof document>`u`)return;let e=document.querySelectorAll(`form`);x.current.clear(),e.forEach((e,t)=>{let n=new FormData(e);x.current.set(`form-${t}`,n)})},F=()=>{typeof document>`u`||document.querySelectorAll(`form`).forEach((e,t)=>{let n=x.current.get(`form-${t}`);n&&n.forEach((t,n)=>{let r=e.elements.namedItem(n);r&&(r.type===`checkbox`||r.type===`radio`?r.checked=t===`on`:r.value=t)})})},I=(e,t,n,r)=>{let i={timestamp:Date.now(),error:e,type:t,details:n,filePath:r};D.current.push(i),k.current+=1,D.current.length>10&&D.current.shift(),console.error(`[rari] HMR: Failure detected`,{type:t,details:n,filePath:r,consecutiveFailures:k.current,error:e.message,stack:e.stack,timestamp:new Date(i.timestamp).toISOString()}),k.current>=2&&j(i),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`rari:hmr-failure`,{detail:i}))},L=()=>{setTimeout(()=>{window.location.reload()},1e3)},R=()=>{k.current>0&&(k.current=0)},z=e=>{if(!O.current)return!1;if(e===O.current)return!0;let t=e.match(f);if(t){let e=Number.parseInt(t[1],10);if(Date.now()-e>5e3)return!0}return!1};function B(e){let t;try{t=JSON.stringify(e)}catch{try{let n=new WeakSet;t=JSON.stringify(e,(e,t)=>{if(typeof t==`object`&&t){if(n.has(t))return`[Circular]`;n.add(t)}return t})}catch{t=`[Unstringifiable:${typeof e}:${String(e).substring(0,50)}]`}}let n=0;for(let e=0;e<t.length;e++){let r=t.charCodeAt(e);n=(n<<5)-n+r,n&=n}return Math.abs(n).toString(36)}function V(e,n,i,a,o){if(!e)return null;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e)){if(e.length>=4&&e[0]===`$`){let[,s,c,l]=e,u=s;if(typeof s==`string`&&s.startsWith(`$`)&&a){let e=s.substring(1);if(t.test(e)){let e=a.get(s);e&&(e===`$Sreact.suspense`||e===`react.suspense`?u=`Suspense`:console.warn(`[rari] AppRouter: Unknown symbol:`,e))}}if(u===`Suspense`||s===`Suspense`){let e=J(l,n,i,a,o);return r.createElement(r.Suspense,c?{...e,key:c}:e)}if(typeof u==`string`&&u.startsWith(`$L`)){let e=n.get(u);if(!e)return null;let t=globalThis[`~clientComponents`]?.[e.id]?.component;if(!t||typeof t!=`function`)return null;let s=c||`fallback-${u}-${N.current++}`,d={...l,children:l.children?V(l.children,n,i,a,o):void 0};return r.createElement(t,{key:s,...d})}if(!u||typeof u!=`string`&&typeof u!=`function`)return console.error(`[rari] AppRouter: Invalid component type:`,{type:u,typeOf:typeof u,serverKey:c,props:l,rscData:e}),null;let d=J(l,n,i,a,o);return r.createElement(u,c?{...d,key:c}:d)}return e.map((e,t)=>{let s=V(e,n,i,a,o);if(!s)return null;if(typeof s==`object`&&r.isValidElement(s)&&!s.key){let n=typeof e==`object`&&e?B(e):`primitive`,i=`rsc-${Array.isArray(e)&&e[0]===`$`&&e[1]?String(e[1]):`unknown`}-${n}-${t}`;return r.createElement(r.Fragment,{key:i},s)}return s}).filter(Boolean)}return e}let H=o(new Set),U=o(new Map),W=o(new Map),G=o(new Map),K=o(new Map);function ne(e){if(!K.current.has(e)){let t=new Promise(()=>{});K.current.set(e,{promise:t,timestamp:Date.now()})}return K.current.get(e).promise}function q(){K.current.clear(),H.current.clear()}function re(){let e=Date.now(),t=[];K.current.forEach((n,r)=>{e-n.timestamp>3e4&&t.push(r)}),t.forEach(e=>{K.current.delete(e),H.current.delete(e)})}function J(e,t,n,i,a){if(!e||typeof e!=`object`)return e;a&&(U.current=a),t&&(W.current=t),i&&(G.current=i);let o={};for(let s in e)if(Object.hasOwn(e,s))if(s===`children`){let c=e.children;if(typeof c==`string`&&c.startsWith(`$L`))if(a&&a.has(c)){let e=a.get(c);H.current.delete(c),o[s]=V(e,t,n,i,a)}else H.current.add(c),o[s]=r.createElement(ee,{key:`lazy-${c}`,contentRef:c,rowsDataRef:U,modulesDataRef:W,symbolsDataRef:G,suspendingPromisesRef:K,getSuspendingPromise:ne,rscToReact:V});else o[s]=c?V(c,t,n,i,a):void 0}else s===`dangerouslySetInnerHTML`?o[s]=e[s]:o[s]=V(e[s],t,n,i,a);return o}let ie=(e,t)=>{try{let n=t===`array`?`[`:`{`,r=t===`array`?`]`:`}`,i=0,a=-1,o=!1,s=!1;for(let t=0;t<e.length;t++){let c=e[t];if(s){s=!1;continue}if(c===`\\`){s=!0;continue}if(c===`"`&&!s){o=!o;continue}if(!o){if(c===n)i++;else if(c===r&&(i--,i===0)){a=t+1;break}}}if(a===-1)return null;let c=e.substring(0,a),l=e.substring(a).trim();return l.length>0&&!p.test(l)&&console.warn(`[rari] Sanitized corrupted JSON (possible userscript injection):`,{extracted:c.substring(0,100),discarded:l.substring(0,50)}),c}catch(e){return console.error(`[rari] Failed to sanitize JSON:`,e),null}},Y=async(e,i=!1)=>{try{let a=e.trim().split(`
|
|
6
|
+
`),o=new Map,s=new Map,c=new Map,l=null,u=[],d=null,f=null;for(let e=0;e<a.length;e++){let n=a[e].trim();if(!n)continue;let r=n.indexOf(`:`);if(r===-1)continue;let p=n.substring(0,r);if(!t.test(p)){console.warn(`[rari] AppRouter: Invalid row ID (non-numeric), skipping line:`,n.substring(0,50));continue}let m=n.substring(r+1);try{if(m.startsWith(`"$S`)){let e=m.slice(1,-1);s.set(`$${p}`,e);continue}if(m.startsWith(`I[`)){let t=ie(m.substring(1),`array`);if(!t){console.warn(`[rari] AppRouter: Could not sanitize import line, skipping:`,n.substring(0,80));continue}let r=JSON.parse(t);if(Array.isArray(r)&&r.length>=3){let[t,n,a]=r;o.set(`$L${p}`,{id:t,chunks:Array.isArray(n)?n:[n],name:a||`default`}),i&&t.includes(`layout`)&&(d!==null&&f!==null&&u.push({layoutPath:d,startLine:f,endLine:e-1,props:{}}),d=t,f=e)}}else if(m.startsWith(`[`)){let e=JSON.parse(m);if(c.set(`$L${p}`,e),i&&Array.isArray(e)&&e.length>=4&&typeof e[1]==`string`&&e[1].startsWith(`$L`)){let t=e[1],n=o.get(t);if(n&&n.id.includes(`layout`)){let t=e[3]||{};if(d&&f!==null){let e=u.find(e=>e.layoutPath===d&&e.startLine===f);e&&(e.props=t)}}}!l&&Array.isArray(e)&&(e[0]===`$`?l=e:Array.isArray(e[0])&&e[0][0]===`$`&&(l=e.length===1?e[0]:e))}}catch(e){console.error(`[rari] AppRouter: Failed to parse RSC line:`,n,e)}}if(await n(o),i&&d!==null&&f!==null&&u.push({layoutPath:d,startLine:f,endLine:a.length-1,props:{}}),l&&Array.isArray(l)){if(N.current=0,l[0]===`$`)l=V(l,o,void 0,s,c);else if(Array.isArray(l[0])){let e=l.map(e=>Array.isArray(e)&&e[0]===`$`?V(e,o,void 0,s,c):e).filter(e=>e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||r.isValidElement(e));l=e.length===1?e[0]:e}}return{element:l,modules:o,symbols:s,wireFormat:e,layoutBoundaries:i?u:void 0}}catch(e){throw console.error(`[rari] AppRouter: Failed to parse RSC wire format:`,e),e}},X=async(t,n)=>{let r=t||window.location.pathname,i=E.current.get(r);if(i)return i;let a=(async()=>{try{let t=(import.meta.env.RARI_SERVER_URL||window.location.origin).replace(e,``)+r+window.location.search,i=await fetch(t,{headers:{Accept:`text/x-component`},cache:`no-store`,signal:n});if(!i.ok){let e=Error(`Failed to fetch RSC data: ${i.status} ${i.statusText}`);throw I(e,`fetch`,`HTTP ${i.status} when fetching ${t}`,window.location.pathname),e}let a=await i.text();if(z(a)&&_)return _;let o;try{o=await Y(a,!1)}catch(e){let t=e instanceof Error?e:Error(String(e));throw I(t,`parse`,`Failed to parse RSC wire format: ${t.message}`,window.location.pathname),t}return v(o),O.current=a,R(),o}catch(e){throw e instanceof Error&&!e.message.includes(`Failed to fetch RSC data`)&&!e.message.includes(`Failed to parse`)&&I(e,`network`,`Network error: ${e.message}`,window.location.pathname),console.error(`[rari] AppRouter: Error fetching RSC payload:`,e),e}finally{E.current.delete(r)}})();return E.current.set(r,a),a},Z=o(Y),Q=o(X),ae=o(J),oe=o(V);a(()=>{Z.current=Y,Q.current=X,ae.current=J,oe.current=V}),a(()=>{if(typeof window>`u`)return;let e=setInterval(()=>{re()},3e4),t=async e=>{let t=e.detail;T.current=t.navigationId,S.current=null,M.current=!0,q(),b.current={x:window.scrollX,y:window.scrollY},P(),C(async()=>{try{t.rscWireFormat?(v(await Z.current(t.rscWireFormat,!1)),O.current=t.rscWireFormat,R()):t.isStreaming?S.current=[]:await Q.current(t.to,t.abortSignal),T.current===t.navigationId&&(y(e=>e+1),j(null),w.current&&w.current(t))}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;console.error(`[rari] AppRouter: Navigation failed:`,e),window.dispatchEvent(new CustomEvent(`rari:navigate-error`,{detail:{from:t.from,to:t.to,error:e,navigationId:t.navigationId}})),k.current>=3&&L()}finally{let e=typeof window<`u`&&window.location.hash.length>0;!t.options?.historyKey&&!e&&requestAnimationFrame(()=>{t.options?.scroll!==!1&&window.scrollTo(0,0)})}})},n=async()=>{b.current={x:window.scrollX,y:window.scrollY},P();try{await Q.current(),y(e=>e+1),j(null)}catch(e){console.error(`[rari] AppRouter: HMR update failed:`,e),k.current>=3&&L()}finally{requestAnimationFrame(()=>{window.scrollTo(b.current.x,b.current.y),F()})}},r=async()=>{try{await Q.current(),y(e=>e+1),j(null)}catch(e){console.error(`[rari] AppRouter: RSC invalidation failed:`,e),k.current>=3&&L()}},i=async()=>{try{await Q.current(),j(null)}catch(e){console.error(`[rari] AppRouter: Manifest update failed:`,e),k.current>=3&&L()}},a=async e=>{let t=e.detail.rscRow;if(!(!t||!t.trim())){S.current||=[],S.current.push(t);try{let e=S.current.join(`
|
|
7
|
+
`),t=await Z.current(e,!1);S.current.length<=2&&e.includes(`~boundaryId`)?(v(t),y(e=>e+1)):C(()=>{v(t),y(e=>e+1)})}catch(e){console.error(`[rari] AppRouter: Failed to parse streaming RSC row:`,e)}}};return window.addEventListener(`rari:navigate`,t),window.addEventListener(`rari:app-router-rerender`,n),window.addEventListener(`rari:rsc-invalidate`,r),window.addEventListener(`rari:app-router-manifest-updated`,i),window.addEventListener(`rari:rsc-row`,a),()=>{clearInterval(e),q(),window.removeEventListener(`rari:navigate`,t),window.removeEventListener(`rari:app-router-rerender`,n),window.removeEventListener(`rari:rsc-invalidate`,r),window.removeEventListener(`rari:app-router-manifest-updated`,i),window.removeEventListener(`rari:rsc-row`,a)}},[]),a(()=>{if(!(typeof window>`u`)&&window.location.hash&&_&&M.current){let e=window.location.hash.slice(1);requestAnimationFrame(()=>{requestAnimationFrame(()=>{let t=document.getElementById(e);t&&(t.scrollIntoView({behavior:`instant`,block:`start`}),M.current=!1)})})}},[_]);let se=()=>{window.location.reload()},ce=()=>{j(null)},le=e=>{if(!e||typeof e!=`object`)return null;if(e.type===`html`&&e.props?.children){let t=Array.isArray(e.props.children)?e.props.children:[e.props.children];for(let e of t)if(e&&typeof e==`object`&&e.type===`body`)return e.props?.children||null}return e},$=h;return _?.element&&($=le(_.element)||_.element),Array.isArray($)&&$.length===1&&r.isValidElement($[0])?$=$[0]:Array.isArray($)&&$.length>0&&$.every(e=>r.isValidElement(e)||e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)&&($=r.createElement(r.Fragment,null,...$)),$&&typeof $==`object`&&!r.isValidElement($)&&(console.error(`[rari] AppRouter: Invalid content to render:`,$),$=h),d(l,{children:[A&&d(`div`,{style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,padding:`24px`,background:`rgba(220, 38, 38, 0.95)`,color:`white`,borderRadius:`8px`,fontSize:`14px`,zIndex:1e4,maxWidth:`500px`,boxShadow:`0 4px 6px rgba(0, 0, 0, 0.3)`},children:[u(`div`,{style:{marginBottom:`16px`,fontWeight:`bold`,fontSize:`16px`},children:`⚠️ HMR Update Failed`}),d(`div`,{style:{marginBottom:`12px`,opacity:.9},children:[A.type===`fetch`&&`Failed to fetch updated content from server.`,A.type===`parse`&&`Failed to parse server response.`,A.type===`stale`&&`Server returned stale content.`,A.type===`network`&&`Network error occurred.`]}),u(`div`,{style:{marginBottom:`16px`,fontSize:`12px`,opacity:.8,fontFamily:`monospace`},children:A.details}),d(`div`,{style:{marginBottom:`12px`,fontSize:`12px`,opacity:.7},children:[`Consecutive failures:`,` `,k.current,` `,`/`,` `,3]}),d(`div`,{style:{display:`flex`,gap:`8px`},children:[u(`button`,{onClick:se,type:`button`,style:{padding:`8px 16px`,background:`white`,color:`#dc2626`,border:`none`,borderRadius:`4px`,cursor:`pointer`,fontWeight:`bold`,fontSize:`14px`},children:`Refresh Page`}),u(`button`,{onClick:ce,type:`button`,style:{padding:`8px 16px`,background:`rgba(255, 255, 255, 0.2)`,color:`white`,border:`1px solid rgba(255, 255, 255, 0.3)`,borderRadius:`4px`,cursor:`pointer`,fontSize:`14px`},children:`Dismiss`})]}),u(`div`,{style:{marginTop:`12px`,fontSize:`11px`,opacity:.6},children:`Check the console for detailed error logs.`})]}),u(i,{fallback:u(m,{}),children:$})]})}export{h as AppRouterProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{t as e}from"../timer-utils-BO5HIsHv.mjs";import{Component as t}from"react";import{jsx as n,jsxs as r}from"react/jsx-runtime";var i=class extends t{_isMounted=!1;_pendingTimer=null;constructor(e){super(e),this.state={hasError:!1,error:null,ErrorComponent:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidMount(){this._isMounted=!0}componentWillUnmount(){this._isMounted=!1,this._pendingTimer=e(this._pendingTimer)}componentDidCatch(e,t){console.error(`[rari] Error boundary caught error:`,e,t);let n=this.props.errorComponentId;if(n&&typeof window<`u`){let e=window[`~clientComponents`]?.[n];e&&(e.component&&typeof e.component==`function`?this.setState({ErrorComponent:e.component}):e.loader&&!e.loading&&(e.loading=!0,e.loader().then(t=>{let n=t.default||t;e.component=n,e.registered=!0,e.loading=!1,this.setState({ErrorComponent:n})}).catch(t=>{e.loading=!1,console.error(`[rari] Failed to load error component ${n}:`,t)})))}}reset=()=>{this._pendingTimer=e(this._pendingTimer),this._pendingTimer=setTimeout(()=>{this._isMounted&&this.setState({hasError:!1,error:null,ErrorComponent:null}),this._pendingTimer=null},50)};render(){if(this.state.hasError&&this.state.error){let{ErrorComponent:e}=this.state;return e?n(e,{error:this.state.error,reset:this.reset}):r(`div`,{style:{padding:`20px`,background:`#fee`,border:`2px solid #f00`},children:[n(`h2`,{children:`Error`}),n(`p`,{children:`Something went wrong.`})]})}return this.props.children}};export{i as ErrorBoundaryWrapper};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"../regex-constants-DOQkuGm5.mjs";import{n as e,t}from"../get-client-component-
|
|
1
|
+
import"../regex-constants-DOQkuGm5.mjs";import{n as e,t}from"../get-client-component-YrjzU6RI.mjs";import*as n from"react";import"react";import{ClientRouter as r}from"rari/client";import{RouterProvider as i}from"rari/router";import{createRoot as a}from"react-dom/client";import{AppRouterProvider as o}from"virtual:app-router-provider";import{createFromReadableStream as s}from"virtual:react-server-dom-rari-client.ts";import"virtual:rsc-integration.ts";function c(){return globalThis[`~rari`]}function l(){return globalThis}function u(){return window}function d(){return{moduleMap:new Proxy({},{get(e,t){return new Proxy({},{get(e,n){return{id:`${String(t)}#${String(n)}`,chunks:[],name:String(n)}}})}}),moduleLoading:new Proxy({},{get(e,t){return new Proxy({},{get(e,n){return async()=>{try{let e=String(t),r=String(n),i=`${e}#${r}`;if(l()[`~clientComponents`]?.[i]?.component)return l()[`~clientComponents`][i].component;if(l()[`~clientComponents`]?.[e]?.component){let t=l()[`~clientComponents`][e].component;return r===`default`?t:t?.[r]}let a=l()[`~clientComponents`]?.[i]||l()[`~clientComponents`]?.[e];if(a?.loader){a.loadPromise||=(a.loading=!0,a.loader().then(e=>(a.component=e.default||e,a.registered=!0,a.loading=!1,e)).catch(t=>{throw a.loading=!1,a.loadPromise=void 0,console.error(`[rari] Failed to lazy load ${e}#${r}:`,t),t}));let t=await a.loadPromise,n=t.default||t;return r===`default`?n:n?.[r]??n}return console.warn(`[rari] Module ${e}#${r} not found in client components registry`),null}catch(e){return console.error(`[rari] Failed to load ${String(t)}#${String(n)}:`,e),null}}}})}})}}c()===void 0&&(globalThis[`~rari`]={}),c().AppRouterProvider=o,c().ClientRouter=r,c().getClientComponent=t;async function f(t){try{await e(t)}catch(e){console.error(`[rari] Failed to preload component ${t}:`,e)}}
|
|
2
2
|
/*! @preserve CLIENT_COMPONENT_IMPORTS_PLACEHOLDER */
|
|
3
3
|
c().preloadClientComponent=f,l()[`~clientComponents`]===void 0&&(globalThis[`~clientComponents`]={}),l()[`~clientComponentPaths`]===void 0&&(globalThis[`~clientComponentPaths`]={});
|
|
4
4
|
/*! @preserve CLIENT_COMPONENT_REGISTRATIONS_PLACEHOLDER */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as e,t,w as n}from"../regex-constants-DOQkuGm5.mjs";import{r}from"../get-client-component-
|
|
1
|
+
import{b as e,t,w as n}from"../regex-constants-DOQkuGm5.mjs";import{r}from"../get-client-component-YrjzU6RI.mjs";import{t as i}from"../preload-components-DD3aKUwy.mjs";import*as a from"react";async function o(e,t={}){let{moduleMap:n={}}=t,r=e.getReader(),a=[];for(;;){let{done:e,value:t}=await r.read();if(e)break;a.push(t)}let o=new Uint8Array(a.reduce((e,t)=>e+t.length,0)),s=0;for(let e of a)o.set(e,s),s+=e.length;let l=c(new TextDecoder().decode(o));return await i(l.modules),u(l.rootElement,l.modules,n,l.symbols,l.chunks)}async function s(e,t={}){let n=c(await(await e).text());return await i(n.modules),u(n.rootElement,n.modules,t.moduleMap||{},n.symbols,n.chunks)}function c(e){let t=new Map,n=new Map,r=new Map,i=0,a=0,o=0,s=0,c=``,u=null;for(;i<e.length;){let d=e[i],f=e.charCodeAt(i);switch(a){case 0:d===`:`?(a=1,i++):(f>=48&&f<=57?o=o<<4|f-48:f>=97&&f<=102?o=o<<4|f-87:f>=65&&f<=70&&(o=o<<4|f-55),i++);break;case 1:f===73||f===69||f===84||f===72||f===68||f===87||f===67?(s=f,a=2,i++):(s=0,a=2);break;case 2:d===`
|
|
2
2
|
`?(l(o,s,c,t,n,r),u===null&&s!==73&&c.trim()&&!(c.startsWith(`"$S`)&&c.endsWith(`"`))&&n.has(o.toString())&&(u=o.toString()),a=0,o=0,s=0,c=``):c+=d,i++;break}}return c.trim()&&(l(o,s,c,t,n,r),u===null&&s!==73&&!(c.startsWith(`"$S`)&&c.endsWith(`"`))&&n.has(o.toString())&&(u=o.toString())),{modules:t,chunks:n,symbols:r,rootElement:u===null?null:n.get(u)}}function l(e,t,n,r,i,a){let o=e.toString();try{switch(t){case 73:{let e=JSON.parse(n);Array.isArray(e)&&e.length>=3&&r.set(`$L${o}`,{id:e[0],chunks:e[1]||[],name:e[2]||`default`});break}case 69:{console.error(`[rari] RSC: Error chunk:`,n);let e=JSON.parse(n);i.set(o,{error:e});break}case 84:i.set(o,n);break;case 72:case 68:case 87:break;case 67:break;default:{if(!n.trim())break;if(n.startsWith(`"$S`)&&n.endsWith(`"`)){let e=n.slice(1,-1);a.set(o,e);break}let e=JSON.parse(n);i.set(o,e);break}}}catch(e){console.error(`[rari] RSC: Failed to parse row:`,{id:o,tag:t,data:n},e)}}function u(t,n,r,i,o){if(!t)return null;if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`){if(typeof t==`string`&&t.startsWith(`$`)&&t.length>1){if(t[1]===`L`){let e=t.slice(2),a=o?.get(e);if(!a){let e=new Promise(()=>{});throw e._rscLazyRef=t,e}return u(a,n,r,i,o)}let e=t.slice(1),a=o?.get(e);return a?u(a,n,r,i,o):null}return t}if(Array.isArray(t)){if(t.length>=4&&t[0]===`$`){let[,s,c,l]=t;if(typeof s==`string`&&s.startsWith(`$`)&&s.length>1&&e.test(s.slice(1))){let e=s.slice(1),t=i?.get(e);if(t&&t.startsWith(`$S`)&&t.slice(2)===`react.suspense`){let e=f(l,n,r,i,o);return a.createElement(a.Suspense,c?{...e,key:c}:e)}}if(typeof s==`string`&&s.startsWith(`$S`)){if(s.slice(2)===`react.suspense`){let e=f(l,n,r,i,o);return a.createElement(a.Suspense,c?{...e,key:c}:e)}return null}if(typeof s==`string`&&s.startsWith(`$L`)){let e=s.substring(2);if(e===`ClientRouter`&&(!l||!l.manifest))return l&&l.children?u(l.children,n,r,i,o):null;let t=d(e,n,r);if(t){let e=f(l,n,r,i,o);return a.createElement(t,c?{...e,key:c}:e)}return null}let p=f(l,n,r,i,o);return a.createElement(s,c?{...p,key:c}:p)}return t.map(e=>u(e,n,r,i,o))}return t}function d(e,i,a){if(e===`AppRouterProvider`){let e=globalThis[`~rari`]?.AppRouterProvider;if(e)return e}if(e===`ClientRouter`){let e=globalThis[`~rari`]?.ClientRouter;if(e)return e}if(i&&i.size>0){let a=`$L${e}`,o=i.get(a);if(o){let e=globalThis[`~clientComponents`]||{},i=[o.id,`${o.id}#${o.name||`default`}`,o.id.replace(n,``),o.id.replace(t,`/`)];for(let t of i){let n=e[t];if(n){if(n.component)return n.component;if(n.loader&&!n.loading)return r(n,o.id);if(n.loading)return null}}console.warn(`[rari] Component not found in registry:`,{moduleId:o.id,moduleName:o.name,triedKeys:i,availableKeys:Object.keys(e).slice(0,10)})}}if(a[e])return a[e];let o=globalThis[`~clientComponents`]||{};for(let[t,n]of Object.entries(o)){let i=t===e,a=t.endsWith(`/${e}`)||t.endsWith(`\\${e}`),o=t.endsWith(`#${e}`),s=n.name===e;if(i||a||o||s){if(n.component)return n.component;if(n.loader&&!n.loading)return r(n,t)}}return null}function f(e,t,n,r,i){if(!e||typeof e!=`object`)return e;let a={};for(let o in e)if(Object.hasOwn(e,o)){if(o.startsWith(`~`)||o===`ref`)continue;o===`children`?a[o]=e.children?u(e.children,t,n,r,i):void 0:a[o]=e[o]}return a}function p(e){return JSON.stringify(e)}function m(e){return JSON.parse(e)}export{s as createFromFetch,o as createFromReadableStream,m as decodeReply,p as encodeReply};
|