rari 0.7.5 → 0.7.7

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.
Files changed (55) hide show
  1. package/dist/cli.mjs +144 -22
  2. package/dist/client.mjs +8 -8
  3. package/dist/constants-wQafG3CE.mjs +33 -0
  4. package/dist/image/index.d.mts +1 -1
  5. package/dist/image/index.mjs +171 -1
  6. package/dist/index.d.mts +0 -1
  7. package/dist/index.mjs +5 -5
  8. package/dist/proxy/runtime-executor.d.mts +26 -1
  9. package/dist/proxy/runtime-executor.mjs +4 -4
  10. package/dist/{railway-DVrZWPOO.mjs → railway-D_JxHvQD.mjs} +22 -27
  11. package/dist/{render-ALOsrnWD.mjs → render-BXSC62Pt.mjs} +5 -5
  12. package/dist/routes-DVpNEEhv.mjs +3 -0
  13. package/dist/{routes-BHZ20uQX.mjs → routes-n_EfMXUa.mjs} +7 -7
  14. package/dist/runtime/actions.mjs +5 -5
  15. package/dist/{runtime-client-B7wmvKD3.mjs → runtime-client-DkgL4Orp.mjs} +7 -7
  16. package/dist/server-build-Chl-ND4C.mjs +3 -0
  17. package/dist/{server-build-VeqQZBax.mjs → server-build-X1pfRKXQ.mjs} +8 -8
  18. package/dist/{vite-BWd99saK.mjs → vite-BzmOMWUI.mjs} +33 -33
  19. package/dist/vite.d.mts +0 -1
  20. package/dist/vite.mjs +5 -5
  21. package/package.json +72 -72
  22. package/src/cli.ts +154 -16
  23. package/src/deployment/railway.ts +22 -33
  24. package/src/deployment/render.ts +5 -5
  25. package/src/image/index.ts +1 -0
  26. package/src/platform.ts +4 -4
  27. package/src/proxy/execute-proxy.ts +2 -2
  28. package/src/proxy/executor.ts +4 -4
  29. package/src/proxy/runtime-executor.ts +4 -4
  30. package/src/proxy/vite-plugin.ts +1 -1
  31. package/src/router/ClientRouter.tsx +3 -3
  32. package/src/router/LayoutErrorBoundary.tsx +1 -1
  33. package/src/router/StatePreserver.ts +2 -2
  34. package/src/router/navigation-error-handler.ts +1 -1
  35. package/src/router/props-extractor.ts +3 -3
  36. package/src/router/routes.ts +7 -7
  37. package/src/router/vite-plugin.ts +9 -9
  38. package/src/runtime/AppRouterProvider.tsx +12 -12
  39. package/src/runtime/LoadingErrorBoundary.tsx +2 -2
  40. package/src/runtime/actions.ts +3 -3
  41. package/src/runtime/csrf.ts +2 -2
  42. package/src/runtime/entry-client.js +15 -15
  43. package/src/runtime/react-server-dom-rari-client.js +2 -2
  44. package/src/runtime/rsc-client-runtime.js +38 -22
  45. package/src/runtime-client.ts +4 -4
  46. package/src/vite/hmr-coordinator.ts +2 -2
  47. package/src/vite/hmr-error-handler.ts +1 -1
  48. package/src/vite/index.ts +20 -26
  49. package/src/vite/server-build.ts +8 -8
  50. package/src/vite.ts +2 -1
  51. package/dist/image-CL9iVW32.mjs +0 -204
  52. package/dist/routes-DjIf7Qiq.mjs +0 -3
  53. package/dist/runtime-executor-NBcG4boA.d.mts +0 -27
  54. package/dist/server-build-C9oLpeMw.mjs +0 -3
  55. package/src/proxy/index.ts +0 -16
package/dist/cli.mjs CHANGED
@@ -28,7 +28,7 @@ function getPlatformInfo() {
28
28
  case "win32":
29
29
  normalizedPlatform = "win32";
30
30
  break;
31
- default: throw new Error(`Unsupported platform: ${platform}. Rari supports Linux, macOS, and Windows.`);
31
+ default: throw new Error(`Unsupported platform: ${platform}. rari supports Linux, macOS, and Windows.`);
32
32
  }
33
33
  let normalizedArch;
34
34
  switch (arch) {
@@ -38,7 +38,7 @@ function getPlatformInfo() {
38
38
  case "arm64":
39
39
  normalizedArch = "arm64";
40
40
  break;
41
- default: throw new Error(`Unsupported architecture: ${arch}. Rari supports x64 and ARM64.`);
41
+ default: throw new Error(`Unsupported architecture: ${arch}. rari supports x64 and ARM64.`);
42
42
  }
43
43
  const packageName = SUPPORTED_PLATFORMS[`${normalizedPlatform}-${normalizedArch}`];
44
44
  if (!packageName) throw new Error(`Unsupported platform combination: ${normalizedPlatform}-${normalizedArch}. Supported platforms: ${Object.keys(SUPPORTED_PLATFORMS).join(", ")}`);
@@ -71,13 +71,13 @@ function getBinaryPath() {
71
71
  if (existsSync(binaryPath)) return binaryPath;
72
72
  throw new Error(`Binary not found at ${binaryPath}`);
73
73
  } catch {
74
- throw new Error(`Failed to locate Rari binary for ${packageName}. Please ensure the platform package is installed: npm install ${packageName}`);
74
+ throw new Error(`Failed to locate rari binary for ${packageName}. Please ensure the platform package is installed: npm install ${packageName}`);
75
75
  }
76
76
  }
77
77
  function getInstallationInstructions() {
78
78
  const { packageName } = getPlatformInfo();
79
79
  return `
80
- To install Rari for your platform, run:
80
+ To install rari for your platform, run:
81
81
 
82
82
  npm install ${packageName}
83
83
 
@@ -143,16 +143,118 @@ function getPlatformName() {
143
143
  function getDeploymentConfig() {
144
144
  return {
145
145
  port: process.env.PORT || process.env.RSC_PORT || "3000",
146
- mode: process.env.NODE_ENV === "production" ? "production" : "development",
146
+ mode: process.env.NODE_ENV || "production",
147
147
  host: isPlatformEnvironment() ? "0.0.0.0" : "127.0.0.1"
148
148
  };
149
149
  }
150
+ async function runViteBuild() {
151
+ const { existsSync: existsSync$1, rmSync } = await import("node:fs");
152
+ const { resolve: resolve$1 } = await import("node:path");
153
+ const { spawn: spawn$1 } = await import("node:child_process");
154
+ const distPath = resolve$1(process.cwd(), "dist");
155
+ if (existsSync$1(distPath)) {
156
+ logInfo("Cleaning dist folder...");
157
+ rmSync(distPath, {
158
+ recursive: true,
159
+ force: true
160
+ });
161
+ }
162
+ logInfo("Type checking...");
163
+ const typecheckProcess = spawn$1("npx", ["tsgo"], {
164
+ stdio: "inherit",
165
+ cwd: process.cwd(),
166
+ shell: true
167
+ });
168
+ await new Promise((resolve$2, reject) => {
169
+ typecheckProcess.on("exit", (code) => {
170
+ if (code === 0) {
171
+ logSuccess("Type check passed");
172
+ resolve$2();
173
+ } else {
174
+ logError(`Type check failed with code ${code}`);
175
+ reject(/* @__PURE__ */ new Error(`Type check failed with code ${code}`));
176
+ }
177
+ });
178
+ typecheckProcess.on("error", reject);
179
+ });
180
+ logInfo("Building for production...");
181
+ const buildProcess = spawn$1("npx", ["vite", "build"], {
182
+ stdio: "inherit",
183
+ cwd: process.cwd(),
184
+ shell: true
185
+ });
186
+ await new Promise((resolve$2, reject) => {
187
+ buildProcess.on("exit", (code) => {
188
+ if (code === 0) {
189
+ logSuccess("Build complete");
190
+ resolve$2();
191
+ } else {
192
+ logError(`Build failed with code ${code}`);
193
+ reject(/* @__PURE__ */ new Error(`Build failed with code ${code}`));
194
+ }
195
+ });
196
+ buildProcess.on("error", reject);
197
+ });
198
+ }
199
+ async function runViteDev() {
200
+ const { existsSync: existsSync$1 } = await import("node:fs");
201
+ const { resolve: resolve$1 } = await import("node:path");
202
+ const { spawn: spawn$1 } = await import("node:child_process");
203
+ if (!existsSync$1(resolve$1(process.cwd(), "dist"))) {
204
+ logInfo("First run detected - building project...");
205
+ const buildProcess = spawn$1("npx", [
206
+ "vite",
207
+ "build",
208
+ "--mode",
209
+ "development"
210
+ ], {
211
+ stdio: "inherit",
212
+ cwd: process.cwd(),
213
+ shell: true
214
+ });
215
+ await new Promise((resolve$2, reject) => {
216
+ buildProcess.on("exit", (code) => {
217
+ if (code === 0) {
218
+ logSuccess("Initial build complete");
219
+ resolve$2();
220
+ } else {
221
+ logError(`Build failed with code ${code}`);
222
+ reject(/* @__PURE__ */ new Error(`Build failed with code ${code}`));
223
+ }
224
+ });
225
+ buildProcess.on("error", reject);
226
+ });
227
+ }
228
+ logInfo("Starting Vite dev server...");
229
+ const viteProcess = spawn$1("npx", ["vite"], {
230
+ stdio: "inherit",
231
+ cwd: process.cwd(),
232
+ shell: true
233
+ });
234
+ const shutdown = () => {
235
+ logInfo("Shutting down dev server...");
236
+ viteProcess.kill("SIGTERM");
237
+ };
238
+ process.on("SIGINT", shutdown);
239
+ process.on("SIGTERM", shutdown);
240
+ viteProcess.on("error", (error) => {
241
+ logError(`Failed to start Vite: ${error.message}`);
242
+ process.exit(1);
243
+ });
244
+ viteProcess.on("exit", (code) => {
245
+ if (code !== 0 && code !== null) {
246
+ logError(`Vite exited with code ${code}`);
247
+ process.exit(code);
248
+ }
249
+ });
250
+ return new Promise(() => {});
251
+ }
150
252
  async function startRustServer() {
151
253
  let binaryPath;
152
254
  try {
153
255
  binaryPath = getBinaryPath();
154
256
  } catch {
155
- logError("Failed to obtain Rari binary");
257
+ logError("Failed to obtain rari binary");
156
258
  logError(getInstallationInstructions());
157
259
  process.exit(1);
158
260
  }
@@ -160,7 +262,7 @@ async function startRustServer() {
160
262
  if (isPlatformEnvironment()) {
161
263
  const platformName = getPlatformName();
162
264
  logInfo(`${platformName} environment detected`);
163
- logInfo(`Starting Rari server for ${platformName} deployment...`);
265
+ logInfo(`Starting rari server for ${platformName} deployment...`);
164
266
  logInfo(`Mode: ${mode}, Host: ${host}, Port: ${port}`);
165
267
  logInfo(`using binary: ${binaryPath}`);
166
268
  }
@@ -186,8 +288,8 @@ async function startRustServer() {
186
288
  process.on("SIGINT", shutdown);
187
289
  process.on("SIGTERM", shutdown);
188
290
  rustServer.on("error", (error) => {
189
- logError(`Failed to start Rari server: ${error.message}`);
190
- if (error.message.includes("ENOENT")) logError("Binary not found. Please ensure Rari is properly installed.");
291
+ logError(`Failed to start rari server: ${error.message}`);
292
+ if (error.message.includes("ENOENT")) logError("Binary not found. Please ensure rari is properly installed.");
191
293
  process.exit(1);
192
294
  });
193
295
  rustServer.on("exit", (code, signal) => {
@@ -206,7 +308,7 @@ async function deployToRailway() {
206
308
  logError(`Already running in ${getPlatformName()} environment. Use "rari start" instead.`);
207
309
  process.exit(1);
208
310
  }
209
- const { createRailwayDeployment } = await import("./railway-DVrZWPOO.mjs");
311
+ const { createRailwayDeployment } = await import("./railway-D_JxHvQD.mjs");
210
312
  await createRailwayDeployment();
211
313
  }
212
314
  async function deployToRender() {
@@ -215,7 +317,7 @@ async function deployToRender() {
215
317
  logError(`Already running in ${getPlatformName()} environment. Use "rari start" instead.`);
216
318
  process.exit(1);
217
319
  }
218
- const { createRenderDeployment } = await import("./render-ALOsrnWD.mjs");
320
+ const { createRenderDeployment } = await import("./render-BXSC62Pt.mjs");
219
321
  await createRenderDeployment();
220
322
  }
221
323
  async function main() {
@@ -224,26 +326,37 @@ async function main() {
224
326
  case "help":
225
327
  case "--help":
226
328
  case "-h":
227
- console.warn(`${colors.bold("Rari CLI")}
329
+ console.warn(`${colors.bold("rari CLI")}
228
330
 
229
331
  ${colors.bold("Usage:")}
230
- ${colors.cyan("rari start")} Start the Rari server
231
- ${colors.cyan("rari deploy railway")} Setup Railway deployment
232
- ${colors.cyan("rari deploy render")} Setup Render deployment
233
- ${colors.cyan("rari help")} Show this help message
332
+ ${colors.cyan("rari dev")} Start the development server with Vite
333
+ ${colors.cyan("rari build")} Build for production
334
+ ${colors.cyan("rari start")} Start the rari server (defaults to production)
335
+ ${colors.cyan("rari deploy railway")} Setup Railway deployment
336
+ ${colors.cyan("rari deploy render")} Setup Render deployment
337
+ ${colors.cyan("rari help")} Show this help message
234
338
 
235
339
  ${colors.bold("Environment Variables:")}
236
- ${colors.yellow("PORT")} Server port (default: 3000)
237
- ${colors.yellow("RSC_PORT")} Alternative server port
238
- ${colors.yellow("NODE_ENV")} Environment (development/production)
239
- ${colors.yellow("RUST_LOG")} Rust logging level (default: info)
340
+ ${colors.yellow("PORT")} Server port (default: 3000)
341
+ ${colors.yellow("RSC_PORT")} Alternative server port
342
+ ${colors.yellow("NODE_ENV")} Environment (default: production for start, development for dev)
343
+ ${colors.yellow("RUST_LOG")} Rust logging level (default: info)
240
344
 
241
345
  ${colors.bold("Examples:")}
242
- ${colors.gray("# Start development server on port 3000")}
346
+ ${colors.gray("# Start development server with Vite")}
347
+ ${colors.cyan("rari dev")}
348
+
349
+ ${colors.gray("# Build for production")}
350
+ ${colors.cyan("rari build")}
351
+
352
+ ${colors.gray("# Start production server (default)")}
243
353
  ${colors.cyan("rari start")}
244
354
 
355
+ ${colors.gray("# Start in development mode")}
356
+ ${colors.cyan("NODE_ENV=development rari start")}
357
+
245
358
  ${colors.gray("# Start production server on port 8080")}
246
- ${colors.cyan("PORT=8080 NODE_ENV=production rari start")}
359
+ ${colors.cyan("PORT=8080 rari start")}
247
360
 
248
361
  ${colors.gray("# Setup Railway deployment")}
249
362
  ${colors.cyan("rari deploy railway")}
@@ -269,12 +382,21 @@ ${colors.bold("Binary Resolution:")}
269
382
  3. Install from source with Cargo
270
383
 
271
384
  ${colors.bold("Notes:")}
385
+ - 'rari start' defaults to production mode unless NODE_ENV is set
386
+ - 'rari dev' runs in development mode with Vite hot reload
387
+ - 'rari build' cleans, type checks, and builds for production
272
388
  - Platform binary is automatically detected and used
273
389
  - Platform deployment is automatically detected and configured
274
390
  - Use Ctrl+C to stop the server gracefully
275
391
 
276
392
  `);
277
393
  break;
394
+ case "dev":
395
+ await runViteDev();
396
+ break;
397
+ case "build":
398
+ await runViteBuild();
399
+ break;
278
400
  case "start":
279
401
  await startRustServer();
280
402
  break;
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as LoadingSpinner, c as createHttpRuntimeClient, d as clearPropsCacheForComponent, f as extractMetadata, g as hasServerSideDataFetching, h as extractStaticParams, i as HttpRuntimeClient, l as createLoadingBoundary, m as extractServerPropsWithCache, n as DefaultLoading, o as NotFound, p as extractServerProps, r as ErrorBoundary, s as createErrorBoundary, t as DefaultError, u as clearPropsCache } from "./runtime-client-B7wmvKD3.mjs";
1
+ import { a as LoadingSpinner, c as createHttpRuntimeClient, d as clearPropsCacheForComponent, f as extractMetadata, g as hasServerSideDataFetching, h as extractStaticParams, i as HttpRuntimeClient, l as createLoadingBoundary, m as extractServerPropsWithCache, n as DefaultLoading, o as NotFound, p as extractServerProps, r as ErrorBoundary, s as createErrorBoundary, t as DefaultError, u as clearPropsCache } from "./runtime-client-DkgL4Orp.mjs";
2
2
  import { Component, useEffect, useRef, useState } from "react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
4
 
@@ -170,7 +170,7 @@ var NavigationErrorHandler = class {
170
170
  handleError(error, url) {
171
171
  const navError = createNavigationError(error, url);
172
172
  this.options.onError(navError);
173
- console.error("[NavigationErrorHandler]", navError.type, navError.message, {
173
+ console.error("[rari] Navigation:", navError.type, navError.message, {
174
174
  url: navError.url,
175
175
  statusCode: navError.statusCode,
176
176
  retryable: navError.retryable
@@ -654,7 +654,7 @@ var StatePreserver = class {
654
654
  }
655
655
  });
656
656
  } catch (error) {
657
- console.error("Failed to restore scroll positions:", error);
657
+ console.error("[rari] Router: Failed to restore scroll positions:", error);
658
658
  allSucceeded = false;
659
659
  }
660
660
  return allSucceeded;
@@ -684,7 +684,7 @@ var StatePreserver = class {
684
684
  }
685
685
  });
686
686
  } catch (error) {
687
- console.error("Failed to restore form data:", error);
687
+ console.error("[rari] Router: Failed to restore form data:", error);
688
688
  allSucceeded = false;
689
689
  }
690
690
  return allSucceeded;
@@ -822,7 +822,7 @@ function ClientRouter({ children, initialRoute }) {
822
822
  timeout: 1e4,
823
823
  maxRetries: 3,
824
824
  onError: (error) => {
825
- console.error("[ClientRouter] Navigation error:", error);
825
+ console.error("[rari] Router: Navigation error:", error);
826
826
  },
827
827
  onRetry: () => {}
828
828
  }));
@@ -854,7 +854,7 @@ function ClientRouter({ children, initialRoute }) {
854
854
  const processNavigationQueueRef = useRef(null);
855
855
  const navigate = async (href, options = {}) => {
856
856
  if (!href || typeof href !== "string") {
857
- console.error("[ClientRouter] Invalid navigation target:", href);
857
+ console.error("[rari] Router: Invalid navigation target:", href);
858
858
  return;
859
859
  }
860
860
  const [pathWithoutHash, hash] = href.includes("#") ? href.split("#") : [href, ""];
@@ -959,7 +959,7 @@ function ClientRouter({ children, initialRoute }) {
959
959
  isStreaming: true
960
960
  } }));
961
961
  } catch (streamError) {
962
- console.error("[ClientRouter] Streaming error:", streamError);
962
+ console.error("[rari] Router: Streaming error:", streamError);
963
963
  throw streamError;
964
964
  }
965
965
  } else {
@@ -1175,7 +1175,7 @@ var LayoutErrorBoundary = class extends Component {
1175
1175
  };
1176
1176
  }
1177
1177
  componentDidCatch(error, errorInfo) {
1178
- console.error(`[LayoutErrorBoundary] Error in layout "${this.props.layoutPath}":`, error, errorInfo);
1178
+ console.error(`[rari] Layout: Error in layout "${this.props.layoutPath}":`, error, errorInfo);
1179
1179
  if (this.props.onError) this.props.onError(error, errorInfo);
1180
1180
  if (typeof window !== "undefined") window.dispatchEvent(new CustomEvent("rari:layout-error", { detail: {
1181
1181
  layoutPath: this.props.layoutPath,
@@ -0,0 +1,33 @@
1
+ //#region src/image/constants.ts
2
+ const DEFAULT_DEVICE_SIZES = [
3
+ 640,
4
+ 750,
5
+ 828,
6
+ 1080,
7
+ 1200,
8
+ 1920,
9
+ 2048,
10
+ 3840
11
+ ];
12
+ const DEFAULT_IMAGE_SIZES = [
13
+ 16,
14
+ 32,
15
+ 48,
16
+ 64,
17
+ 96,
18
+ 128,
19
+ 256,
20
+ 384
21
+ ];
22
+ const DEFAULT_FORMATS = ["avif"];
23
+ const DEFAULT_QUALITY_LEVELS = [
24
+ 25,
25
+ 50,
26
+ 75,
27
+ 100
28
+ ];
29
+ const DEFAULT_MINIMUM_CACHE_TTL = 60;
30
+ const DEFAULT_MAX_CACHE_SIZE = 100 * 1024 * 1024;
31
+
32
+ //#endregion
33
+ export { DEFAULT_MINIMUM_CACHE_TTL as a, DEFAULT_MAX_CACHE_SIZE as i, DEFAULT_FORMATS as n, DEFAULT_QUALITY_LEVELS as o, DEFAULT_IMAGE_SIZES as r, DEFAULT_DEVICE_SIZES as t };
@@ -63,4 +63,4 @@ declare function Image({
63
63
  decoding
64
64
  }: ImageProps): react_jsx_runtime0.JSX.Element;
65
65
  //#endregion
66
- export { DEFAULT_DEVICE_SIZES, DEFAULT_FORMATS, DEFAULT_IMAGE_SIZES, DEFAULT_MAX_CACHE_SIZE, DEFAULT_MINIMUM_CACHE_TTL, DEFAULT_QUALITY_LEVELS, Image, type ImageProps, type StaticImageData };
66
+ export { DEFAULT_DEVICE_SIZES, DEFAULT_FORMATS, DEFAULT_IMAGE_SIZES, DEFAULT_MAX_CACHE_SIZE, DEFAULT_MINIMUM_CACHE_TTL, DEFAULT_QUALITY_LEVELS, Image, type ImageFormat, type ImageProps, type StaticImageData };
@@ -1,3 +1,173 @@
1
- import { a as DEFAULT_MAX_CACHE_SIZE, i as DEFAULT_IMAGE_SIZES, n as DEFAULT_DEVICE_SIZES, o as DEFAULT_MINIMUM_CACHE_TTL, r as DEFAULT_FORMATS, s as DEFAULT_QUALITY_LEVELS, t as Image } from "../image-CL9iVW32.mjs";
1
+ import { a as DEFAULT_MINIMUM_CACHE_TTL, i as DEFAULT_MAX_CACHE_SIZE, n as DEFAULT_FORMATS, o as DEFAULT_QUALITY_LEVELS, r as DEFAULT_IMAGE_SIZES, t as DEFAULT_DEVICE_SIZES } from "../constants-wQafG3CE.mjs";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
2
4
 
5
+ //#region src/image/Image.tsx
6
+ function buildImageUrl(src, width, quality, format) {
7
+ const params = new URLSearchParams();
8
+ params.set("url", src);
9
+ params.set("w", width.toString());
10
+ params.set("q", quality.toString());
11
+ if (format) params.set("f", format);
12
+ return `/_rari/image?${params}`;
13
+ }
14
+ function Image({ src, alt, width, height, quality = 75, preload = false, loading = "lazy", placeholder = "empty", blurDataURL, fill = false, sizes, style, className, onLoad, onError, unoptimized = false, loader, overrideSrc, decoding }) {
15
+ const imgSrc = typeof src === "string" ? src : src.src;
16
+ const imgWidth = width || (typeof src !== "string" ? src.width : void 0);
17
+ const imgHeight = height || (typeof src !== "string" ? src.height : void 0);
18
+ const imgBlurDataURL = blurDataURL || (typeof src !== "string" ? src.blurDataURL : void 0);
19
+ const finalSrc = overrideSrc || imgSrc;
20
+ const shouldPreload = preload;
21
+ const imgDecoding = decoding || (preload ? "sync" : "async");
22
+ const [blurComplete, setBlurComplete] = useState(false);
23
+ const [showAltText, setShowAltText] = useState(false);
24
+ const imgRef = useRef(null);
25
+ const onLoadRef = useRef(onLoad);
26
+ const pictureRef = useRef(null);
27
+ useEffect(() => {
28
+ onLoadRef.current = onLoad;
29
+ }, [onLoad]);
30
+ const handleLoad = useCallback((event) => {
31
+ const img = event.currentTarget;
32
+ if (img.src && img.complete) {
33
+ if (placeholder === "blur") setBlurComplete(true);
34
+ if (onLoadRef.current) onLoadRef.current(event);
35
+ }
36
+ }, [placeholder]);
37
+ const handleError = useCallback((event) => {
38
+ setShowAltText(true);
39
+ if (placeholder === "blur") setBlurComplete(true);
40
+ if (onError) onError(event);
41
+ }, [placeholder, onError]);
42
+ useEffect(() => {
43
+ if (shouldPreload) {
44
+ const link = document.createElement("link");
45
+ link.rel = "preload";
46
+ link.as = "image";
47
+ link.href = loader ? loader({
48
+ src: finalSrc,
49
+ width: imgWidth || 1920,
50
+ quality
51
+ }) : unoptimized ? finalSrc : buildImageUrl(finalSrc, imgWidth || 1920, quality);
52
+ if (sizes) link.setAttribute("imagesizes", sizes);
53
+ document.head.appendChild(link);
54
+ return () => {
55
+ document.head.removeChild(link);
56
+ };
57
+ }
58
+ }, [
59
+ shouldPreload,
60
+ finalSrc,
61
+ imgWidth,
62
+ quality,
63
+ sizes,
64
+ loader,
65
+ unoptimized
66
+ ]);
67
+ useEffect(() => {
68
+ if (shouldPreload || unoptimized || loading === "eager") return;
69
+ const img = imgRef.current;
70
+ if (!img) return;
71
+ const observer = new IntersectionObserver((entries) => {
72
+ entries.forEach((entry) => {
73
+ if (entry.isIntersecting) observer.unobserve(img);
74
+ });
75
+ }, { rootMargin: "50px" });
76
+ observer.observe(img);
77
+ return () => {
78
+ observer.disconnect();
79
+ };
80
+ }, [
81
+ shouldPreload,
82
+ unoptimized,
83
+ loading
84
+ ]);
85
+ const imgStyle = {
86
+ ...style,
87
+ ...fill && {
88
+ position: "absolute",
89
+ inset: 0,
90
+ width: "100%",
91
+ height: "100%",
92
+ objectFit: "cover"
93
+ },
94
+ ...placeholder === "blur" && imgBlurDataURL && !blurComplete && {
95
+ backgroundImage: `url(${imgBlurDataURL})`,
96
+ backgroundSize: "cover",
97
+ backgroundPosition: "center",
98
+ filter: "blur(20px)",
99
+ transition: "filter 0.3s ease-out"
100
+ },
101
+ ...placeholder === "blur" && blurComplete && {
102
+ filter: "none",
103
+ transition: "filter 0.3s ease-out"
104
+ }
105
+ };
106
+ if (unoptimized) return /* @__PURE__ */ jsx("img", {
107
+ ref: imgRef,
108
+ src: loader ? loader({
109
+ src: finalSrc,
110
+ width: imgWidth || 1920,
111
+ quality
112
+ }) : finalSrc,
113
+ alt: showAltText ? alt : "",
114
+ width: fill ? void 0 : imgWidth,
115
+ height: fill ? void 0 : imgHeight,
116
+ loading: shouldPreload ? "eager" : loading,
117
+ fetchPriority: shouldPreload ? "high" : "auto",
118
+ decoding: imgDecoding,
119
+ onLoad: handleLoad,
120
+ onError: handleError,
121
+ style: imgStyle,
122
+ className
123
+ });
124
+ const sizesArray = fill ? DEFAULT_IMAGE_SIZES : DEFAULT_DEVICE_SIZES;
125
+ const defaultWidth = imgWidth || 1920;
126
+ const buildSrcSet = (format) => {
127
+ if (loader) return sizesArray.map((w) => `${loader({
128
+ src: finalSrc,
129
+ width: w,
130
+ quality
131
+ })} ${w}w`).join(", ");
132
+ return sizesArray.map((w) => `${buildImageUrl(finalSrc, w, quality, format)} ${w}w`).join(", ");
133
+ };
134
+ const imgElement = /* @__PURE__ */ jsx("img", {
135
+ ref: imgRef,
136
+ src: loader ? loader({
137
+ src: finalSrc,
138
+ width: defaultWidth,
139
+ quality
140
+ }) : buildImageUrl(finalSrc, defaultWidth, quality),
141
+ srcSet: buildSrcSet(),
142
+ sizes,
143
+ alt: showAltText ? alt : "",
144
+ width: fill ? void 0 : imgWidth,
145
+ height: fill ? void 0 : imgHeight,
146
+ loading: shouldPreload ? "eager" : loading,
147
+ fetchPriority: shouldPreload ? "high" : "auto",
148
+ decoding: imgDecoding,
149
+ onLoad: handleLoad,
150
+ onError: handleError,
151
+ style: imgStyle,
152
+ className
153
+ });
154
+ return /* @__PURE__ */ jsxs("picture", {
155
+ ref: pictureRef,
156
+ children: [
157
+ DEFAULT_FORMATS.includes("avif") && /* @__PURE__ */ jsx("source", {
158
+ type: "image/avif",
159
+ srcSet: buildSrcSet("avif"),
160
+ sizes
161
+ }),
162
+ DEFAULT_FORMATS.includes("webp") && /* @__PURE__ */ jsx("source", {
163
+ type: "image/webp",
164
+ srcSet: buildSrcSet("webp"),
165
+ sizes
166
+ }),
167
+ imgElement
168
+ ]
169
+ });
170
+ }
171
+
172
+ //#endregion
3
173
  export { DEFAULT_DEVICE_SIZES, DEFAULT_FORMATS, DEFAULT_IMAGE_SIZES, DEFAULT_MAX_CACHE_SIZE, DEFAULT_MINIMUM_CACHE_TTL, DEFAULT_QUALITY_LEVELS, Image };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
1
  import { A as extractMetadata, C as RouteSegment, D as StaticParamsResult, E as ServerPropsResult, M as extractServerPropsWithCache, N as extractStaticParams, O as clearPropsCache, P as hasServerSideDataFetching, S as PageProps, T as MetadataResult, _ as GenerateStaticParams, b as LoadingEntry, d as AppRouteEntry, f as AppRouteManifest, g as GenerateMetadata, h as ErrorProps, i as HttpRuntimeClient, j as extractServerProps, k as clearPropsCacheForComponent, l as createHttpRuntimeClient, m as ErrorEntry, p as AppRouteMatch, s as RuntimeClient, v as LayoutEntry, w as RouteSegmentType, x as NotFoundEntry, y as LayoutProps } from "./runtime-client-BV3qaQrj.mjs";
2
2
  import { C as ApiRouteHandlers, D as RobotsRule, E as Robots, S as ApiResponse, T as RouteHandler, _ as ProxyResult, a as rari, b as RequestCookies, c as ProxyPluginOptions, d as RariRequest, f as CookieOptions, g as ProxyModule, h as ProxyMatcher, i as defineRariOptions, l as rariProxy, m as ProxyFunction, n as Response, o as rariRouter, p as ProxyConfig, r as defineRariConfig, s as generateAppRouteManifest, t as Request, u as RariResponse, v as RariFetchEvent, w as RouteContext, x as ResponseCookies, y as RariURL } from "./vite-BrjcNDVC.mjs";
3
- import "./runtime-executor-NBcG4boA.mjs";
4
3
  export { ApiResponse, ApiRouteHandlers, AppRouteEntry, AppRouteManifest, AppRouteMatch, CookieOptions, ErrorEntry, ErrorProps, GenerateMetadata, GenerateStaticParams, HttpRuntimeClient, LayoutEntry, LayoutProps, LoadingEntry, MetadataResult, NotFoundEntry, PageProps, ProxyConfig, ProxyFunction, ProxyMatcher, ProxyModule, ProxyPluginOptions, ProxyResult, RariFetchEvent, RariRequest, RariResponse, RariURL, Request, RequestCookies, Response, ResponseCookies, type Robots, type RobotsRule, RouteContext, RouteHandler, RouteSegment, RouteSegmentType, RuntimeClient, ServerPropsResult, StaticParamsResult, clearPropsCache, clearPropsCacheForComponent, createHttpRuntimeClient, defineRariConfig, defineRariOptions, extractMetadata, extractServerProps, extractServerPropsWithCache, extractStaticParams, generateAppRouteManifest, hasServerSideDataFetching, rari, rariProxy, rariRouter };
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { a as rariProxy, i as rariRouter, n as defineRariOptions, o as RariResponse, r as rari, s as ApiResponse, t as defineRariConfig } from "./vite-BWd99saK.mjs";
1
+ import { a as rariProxy, i as rariRouter, n as defineRariOptions, o as RariResponse, r as rari, s as ApiResponse, t as defineRariConfig } from "./vite-BzmOMWUI.mjs";
2
2
  import { t as RariRequest } from "./RariRequest-DM6Q4JDB.mjs";
3
- import { c as createHttpRuntimeClient, d as clearPropsCacheForComponent, f as extractMetadata, g as hasServerSideDataFetching, h as extractStaticParams, i as HttpRuntimeClient, m as extractServerPropsWithCache, p as extractServerProps, u as clearPropsCache } from "./runtime-client-B7wmvKD3.mjs";
4
- import { t as generateAppRouteManifest } from "./routes-BHZ20uQX.mjs";
5
- import "./image-CL9iVW32.mjs";
6
- import "./server-build-VeqQZBax.mjs";
3
+ import { c as createHttpRuntimeClient, d as clearPropsCacheForComponent, f as extractMetadata, g as hasServerSideDataFetching, h as extractStaticParams, i as HttpRuntimeClient, m as extractServerPropsWithCache, p as extractServerProps, u as clearPropsCache } from "./runtime-client-DkgL4Orp.mjs";
4
+ import { t as generateAppRouteManifest } from "./routes-n_EfMXUa.mjs";
5
+ import "./constants-wQafG3CE.mjs";
6
+ import "./server-build-X1pfRKXQ.mjs";
7
7
 
8
8
  export { ApiResponse, HttpRuntimeClient, RariRequest, RariResponse, clearPropsCache, clearPropsCacheForComponent, createHttpRuntimeClient, defineRariConfig, defineRariOptions, extractMetadata, extractServerProps, extractServerPropsWithCache, extractStaticParams, generateAppRouteManifest, hasServerSideDataFetching, rari, rariProxy, rariRouter };
@@ -1,2 +1,27 @@
1
- import { t as initializeProxyExecutor } from "../runtime-executor-NBcG4boA.mjs";
1
+ //#region src/proxy/runtime-executor.d.ts
2
+ interface SimpleRequest {
3
+ url: string;
4
+ method: string;
5
+ headers: Record<string, string>;
6
+ }
7
+ interface SimpleProxyResult {
8
+ continue: boolean;
9
+ redirect?: {
10
+ destination: string;
11
+ permanent: boolean;
12
+ };
13
+ rewrite?: string;
14
+ requestHeaders?: Record<string, string>;
15
+ responseHeaders?: Record<string, string>;
16
+ response?: {
17
+ status: number;
18
+ headers: Record<string, string>;
19
+ body?: string;
20
+ };
21
+ }
22
+ declare global {
23
+ var __rariExecuteProxy: ((request: SimpleRequest) => Promise<SimpleProxyResult>) | undefined;
24
+ }
25
+ declare function initializeProxyExecutor(proxyModulePath: string): Promise<boolean>;
26
+ //#endregion
2
27
  export { initializeProxyExecutor };
@@ -3,7 +3,7 @@ async function initializeProxyExecutor(proxyModulePath) {
3
3
  try {
4
4
  const proxyModule = await import(proxyModulePath);
5
5
  if (!proxyModule || !proxyModule.proxy) {
6
- console.error("[rari:proxy] proxy function not found in module");
6
+ console.error("[rari] Proxy: proxy function not found in module");
7
7
  return false;
8
8
  }
9
9
  const { RariRequest } = await import("../RariRequest-D_4bWdqr.mjs");
@@ -18,7 +18,7 @@ async function initializeProxyExecutor(proxyModulePath) {
18
18
  waitUntilPromises.push(promise);
19
19
  } });
20
20
  if (waitUntilPromises.length > 0) Promise.allSettled(waitUntilPromises).catch((error) => {
21
- console.error("[rari:proxy] waitUntil promise failed:", error);
21
+ console.error("[rari] Proxy: waitUntil promise failed:", error);
22
22
  });
23
23
  if (!result) return { continue: true };
24
24
  const continueHeader = result.headers?.get?.("x-rari-proxy-continue");
@@ -71,13 +71,13 @@ async function initializeProxyExecutor(proxyModulePath) {
71
71
  }
72
72
  return { continue: true };
73
73
  } catch (error) {
74
- console.error("[rari:proxy] Proxy execution error:", error);
74
+ console.error("[rari] Proxy: Proxy execution error:", error);
75
75
  return { continue: true };
76
76
  }
77
77
  };
78
78
  return true;
79
79
  } catch (error) {
80
- console.error("[rari:proxy] Failed to initialize proxy executor:", error);
80
+ console.error("[rari] Proxy: Failed to initialize proxy executor:", error);
81
81
  return false;
82
82
  }
83
83
  }