@thexjs/core 1.2.4 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +44 -2
- package/dist/index.js +130 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentType, ReactNode, AnchorHTMLAttributes } from 'react';
|
|
2
|
+
import { ComponentType, ReactNode, CSSProperties, AnchorHTMLAttributes } from 'react';
|
|
3
3
|
|
|
4
4
|
type RouteMode = "static" | "server";
|
|
5
5
|
interface BuildOptions {
|
|
@@ -523,6 +523,48 @@ declare function createApp(options: CreateAppOptions): Promise<AppServeOptions>;
|
|
|
523
523
|
|
|
524
524
|
declare function renderErrorOverlay(error: unknown): string;
|
|
525
525
|
|
|
526
|
+
interface ImageProps {
|
|
527
|
+
src: string;
|
|
528
|
+
alt: string;
|
|
529
|
+
/** Intrinsic width in px. Omitted when using `fill`. */
|
|
530
|
+
width?: number;
|
|
531
|
+
/** Intrinsic height in px. Omitted when using `fill`. */
|
|
532
|
+
height?: number;
|
|
533
|
+
/** `sizes` attribute for responsive srcset. */
|
|
534
|
+
sizes?: string;
|
|
535
|
+
/** LCP image — skips lazy-loading, adds fetchpriority="high". */
|
|
536
|
+
priority?: boolean;
|
|
537
|
+
/** Absolutely-fill the parent (hero/card layouts). Mutually exclusive with width/height. */
|
|
538
|
+
fill?: boolean;
|
|
539
|
+
/** Blur placeholder mode. Requires blurDataURL for a visible effect. */
|
|
540
|
+
placeholder?: "blur" | "empty";
|
|
541
|
+
/** Tiny base64 image used as the blur placeholder until the real image loads. */
|
|
542
|
+
blurDataURL?: string;
|
|
543
|
+
/** 1-100, forwarded to the proxy as `&q=` (validated-and-ignored until a resizer exists). */
|
|
544
|
+
quality?: number;
|
|
545
|
+
className?: string;
|
|
546
|
+
style?: CSSProperties;
|
|
547
|
+
children?: ReactNode;
|
|
548
|
+
}
|
|
549
|
+
/** Candidate widths for srcset generation (px), spread across common breakpoints/DPR. */
|
|
550
|
+
declare const SRCSET_WIDTHS: number[];
|
|
551
|
+
/**
|
|
552
|
+
* Generates a responsive srcset for a remote image by appending width params
|
|
553
|
+
* to the proxy URL (`/_x/image?url=...&w=640`, ...) — only when the src is
|
|
554
|
+
* remote and its host is in the allow-list. Local images have no resize
|
|
555
|
+
* pipeline, so they return undefined and use the intrinsic src.
|
|
556
|
+
*/
|
|
557
|
+
declare function buildSrcSet(src: string, opts?: {
|
|
558
|
+
quality?: number;
|
|
559
|
+
remoteHosts?: string[];
|
|
560
|
+
}): string | undefined;
|
|
561
|
+
/**
|
|
562
|
+
* Set an explicit remote-host allow-list so dev-mode warnings can fail fast
|
|
563
|
+
* on a remote src whose host isn't configured. Mirrors x.config images.remoteHosts.
|
|
564
|
+
*/
|
|
565
|
+
declare function setImageRemoteHosts(hosts: string[]): void;
|
|
566
|
+
declare function Image(props: ImageProps): ReactNode;
|
|
567
|
+
|
|
526
568
|
type IslandMode = "idle" | "visible" | "load";
|
|
527
569
|
interface IslandEntry {
|
|
528
570
|
name: string;
|
|
@@ -626,4 +668,4 @@ declare function resetServerFunctions(): void;
|
|
|
626
668
|
declare function registerServerFunctions(routePath: string, paramNames: string[], fns: Record<string, (...args: unknown[]) => Promise<unknown>>): void;
|
|
627
669
|
declare function getServerFunctionHandler(csrfOptions?: CsrfOptions): (req: Request) => Promise<Response | null>;
|
|
628
670
|
|
|
629
|
-
export { type BuildOptions, CLIENT_NAV_SCRIPT, type ContentEntry, type CounterSeries, type CreateAppOptions, type CsrfOptions, type CsrfResult, DEFAULT_HISTOGRAM_BUCKETS_MS, DefaultNotFound, EnvLeakageError, type ErrorContext, type ErrorReporter, type Frontmatter, type HealthCheck, type HealthCheckOptions, type HistogramSeries, type ImageProxyOptions, type InMemoryMetricsOptions, type InMemoryMetricsReporter, Island, type IslandEntry, type IslandMode, IslandProvider, type LayoutEntry, Link, type LinkProps, type LoaderArgs, type LoaderReturn, type LogFields, type Logger, type MetricLabels, type MetricsReporter, type MetricsSnapshot, type MiddlewareContext, type MiddlewareEntry, type MiddlewareFn, type MiddlewareNext, type NotFoundEntry, type OtelMeterLike, type OtelTracerLike, PUBLIC_ENV_PREFIX, type RateLimitOptions, type RateLimitResult, type RateLimitStore, type ReadinessResult, type RevalidateOptions, type RouteEntry, type RouteMode, type RouteProps, type SecurityHeadersOptions, type SentryLike, applySecurityHeaders, assertNoEnvLeakage, build, buildSecurityHeaders, checkCsrf, combineReporters, composeMiddleware, createApp, createHealthCheckHandler, createImageProxyHandler, createInMemoryMetrics, createOtelReporter, createOtlpMetricsReporter, createRateLimiter, createRedisRateLimitStore, createSentryReporter, defineConfig, escapeHtml, findLayoutChain, findLeakedEnvKeys, findMiddlewareChain, generateCsrfToken, generateManifestSource, generateServerFunctionClient, getErrorReporter, getServerFunctionHandler, logger, noopMetrics, noopReporter, rateLimitMiddleware, registerServerFunctions, renderErrorOverlay, renderMarkdown, renderPage, renderStaticPage, renderStreamingPage, reportException, resetServerFunctions, scanApiDir, scanContent, scanLayouts, scanLayoutsDir, scanMiddleware, scanNotFound, scanPages, scanRoutes, setErrorReporter, verifyCsrfToken, verifyOrigin, withCsrfCookie, withRequestLogging, withRequestMetrics, writeManifest };
|
|
671
|
+
export { type BuildOptions, CLIENT_NAV_SCRIPT, type ContentEntry, type CounterSeries, type CreateAppOptions, type CsrfOptions, type CsrfResult, DEFAULT_HISTOGRAM_BUCKETS_MS, DefaultNotFound, EnvLeakageError, type ErrorContext, type ErrorReporter, type Frontmatter, type HealthCheck, type HealthCheckOptions, type HistogramSeries, Image, type ImageProps, type ImageProxyOptions, type InMemoryMetricsOptions, type InMemoryMetricsReporter, Island, type IslandEntry, type IslandMode, IslandProvider, type LayoutEntry, Link, type LinkProps, type LoaderArgs, type LoaderReturn, type LogFields, type Logger, type MetricLabels, type MetricsReporter, type MetricsSnapshot, type MiddlewareContext, type MiddlewareEntry, type MiddlewareFn, type MiddlewareNext, type NotFoundEntry, type OtelMeterLike, type OtelTracerLike, PUBLIC_ENV_PREFIX, type RateLimitOptions, type RateLimitResult, type RateLimitStore, type ReadinessResult, type RevalidateOptions, type RouteEntry, type RouteMode, type RouteProps, SRCSET_WIDTHS, type SecurityHeadersOptions, type SentryLike, applySecurityHeaders, assertNoEnvLeakage, build, buildSecurityHeaders, buildSrcSet, checkCsrf, combineReporters, composeMiddleware, createApp, createHealthCheckHandler, createImageProxyHandler, createInMemoryMetrics, createOtelReporter, createOtlpMetricsReporter, createRateLimiter, createRedisRateLimitStore, createSentryReporter, defineConfig, escapeHtml, findLayoutChain, findLeakedEnvKeys, findMiddlewareChain, generateCsrfToken, generateManifestSource, generateServerFunctionClient, getErrorReporter, getServerFunctionHandler, logger, noopMetrics, noopReporter, rateLimitMiddleware, registerServerFunctions, renderErrorOverlay, renderMarkdown, renderPage, renderStaticPage, renderStreamingPage, reportException, resetServerFunctions, scanApiDir, scanContent, scanLayouts, scanLayoutsDir, scanMiddleware, scanNotFound, scanPages, scanRoutes, setErrorReporter, setImageRemoteHosts, verifyCsrfToken, verifyOrigin, withCsrfCookie, withRequestLogging, withRequestMetrics, writeManifest };
|
package/dist/index.js
CHANGED
|
@@ -1336,6 +1336,20 @@ function createImageProxyHandler(options = {}) {
|
|
|
1336
1336
|
if (!allowedUrl(parsed)) {
|
|
1337
1337
|
return new Response("host not allow-listed for image proxy", { status: 403 });
|
|
1338
1338
|
}
|
|
1339
|
+
const wParam = reqUrl.searchParams.get("w");
|
|
1340
|
+
const qParam = reqUrl.searchParams.get("q");
|
|
1341
|
+
if (wParam !== null) {
|
|
1342
|
+
const w = Number.parseInt(wParam, 10);
|
|
1343
|
+
if (!Number.isFinite(w) || w < 1 || w > 8192) {
|
|
1344
|
+
return new Response("invalid w param", { status: 400 });
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
if (qParam !== null) {
|
|
1348
|
+
const q = Number.parseInt(qParam, 10);
|
|
1349
|
+
if (!Number.isFinite(q) || q < 1 || q > 100) {
|
|
1350
|
+
return new Response("invalid q param", { status: 400 });
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1339
1353
|
const isRedirect = (status) => status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
1340
1354
|
let upstream;
|
|
1341
1355
|
try {
|
|
@@ -2501,10 +2515,120 @@ data: ${data}
|
|
|
2501
2515
|
};
|
|
2502
2516
|
}
|
|
2503
2517
|
|
|
2518
|
+
// src/image.tsx
|
|
2519
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2520
|
+
var DEV = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
|
|
2521
|
+
var PROXY_PATH = "/_x/image";
|
|
2522
|
+
var SRCSET_WIDTHS = [320, 640, 750, 828, 1080, 1200, 1920, 2048, 3840];
|
|
2523
|
+
function isRemoteUrl(src) {
|
|
2524
|
+
return /^https?:\/\//i.test(src);
|
|
2525
|
+
}
|
|
2526
|
+
function proxyUrl(src, w, q) {
|
|
2527
|
+
const params = new URLSearchParams({ url: src });
|
|
2528
|
+
if (w !== void 0) params.set("w", String(w));
|
|
2529
|
+
if (q !== void 0) params.set("q", String(q));
|
|
2530
|
+
return `${PROXY_PATH}?${params.toString()}`;
|
|
2531
|
+
}
|
|
2532
|
+
function devWarn(message) {
|
|
2533
|
+
if (DEV) {
|
|
2534
|
+
console.warn(`[x/image] ${message}`);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
function buildSrcSet(src, opts = {}) {
|
|
2538
|
+
if (!isRemoteUrl(src)) return void 0;
|
|
2539
|
+
try {
|
|
2540
|
+
const hosts = new Set(opts.remoteHosts ?? []);
|
|
2541
|
+
if (!hosts.has(new URL(src).hostname)) return void 0;
|
|
2542
|
+
} catch {
|
|
2543
|
+
return void 0;
|
|
2544
|
+
}
|
|
2545
|
+
return SRCSET_WIDTHS.map((w) => `${proxyUrl(src, w, opts.quality)} ${w}w`).join(", ");
|
|
2546
|
+
}
|
|
2547
|
+
function setImageRemoteHosts(hosts) {
|
|
2548
|
+
_remoteHosts = hosts;
|
|
2549
|
+
}
|
|
2550
|
+
var _remoteHosts;
|
|
2551
|
+
function Image(props) {
|
|
2552
|
+
const {
|
|
2553
|
+
src,
|
|
2554
|
+
alt,
|
|
2555
|
+
width,
|
|
2556
|
+
height,
|
|
2557
|
+
sizes,
|
|
2558
|
+
priority = false,
|
|
2559
|
+
fill = false,
|
|
2560
|
+
placeholder = "empty",
|
|
2561
|
+
blurDataURL,
|
|
2562
|
+
quality,
|
|
2563
|
+
className,
|
|
2564
|
+
style: userStyle,
|
|
2565
|
+
children
|
|
2566
|
+
} = props;
|
|
2567
|
+
const remote = isRemoteUrl(src);
|
|
2568
|
+
if (DEV) {
|
|
2569
|
+
if (fill && (width !== void 0 || height !== void 0)) {
|
|
2570
|
+
devWarn(`both "fill" and width/height are set on "${src}" \u2014 fill ignores dimensions.`);
|
|
2571
|
+
}
|
|
2572
|
+
if (!fill && (width === void 0 || height === void 0)) {
|
|
2573
|
+
devWarn(
|
|
2574
|
+
`missing width/height on "${src}" (causes layout shift). Provide both or use "fill".`
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
2577
|
+
if (remote) {
|
|
2578
|
+
const host = new URL(src).hostname;
|
|
2579
|
+
if (!_remoteHosts?.includes(host)) {
|
|
2580
|
+
devWarn(
|
|
2581
|
+
`remote src "${src}" host "${host}" is not in images.remoteHosts \u2014 the proxy will 403.`
|
|
2582
|
+
);
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
const resolvedSrc = remote ? proxyUrl(src, quality) : src;
|
|
2587
|
+
const baseStyle = fill ? { position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover" } : { maxWidth: "100%", height: "auto" };
|
|
2588
|
+
if (!fill && width !== void 0 && height !== void 0) {
|
|
2589
|
+
baseStyle.aspectRatio = `${width} / ${height}`;
|
|
2590
|
+
}
|
|
2591
|
+
const placeholderStyle = placeholder === "blur" && blurDataURL ? {
|
|
2592
|
+
backgroundImage: `url(${blurDataURL})`,
|
|
2593
|
+
backgroundSize: "cover",
|
|
2594
|
+
backgroundPosition: "center"
|
|
2595
|
+
} : {};
|
|
2596
|
+
const imgProps = {
|
|
2597
|
+
src: resolvedSrc,
|
|
2598
|
+
sizes,
|
|
2599
|
+
className,
|
|
2600
|
+
style: { ...baseStyle, ...placeholderStyle, ...userStyle },
|
|
2601
|
+
decoding: "async"
|
|
2602
|
+
};
|
|
2603
|
+
if (fill) {
|
|
2604
|
+
imgProps.width = void 0;
|
|
2605
|
+
imgProps.height = void 0;
|
|
2606
|
+
} else {
|
|
2607
|
+
imgProps.width = width;
|
|
2608
|
+
imgProps.height = height;
|
|
2609
|
+
}
|
|
2610
|
+
if (priority) {
|
|
2611
|
+
imgProps.fetchPriority = "high";
|
|
2612
|
+
} else {
|
|
2613
|
+
imgProps.loading = "lazy";
|
|
2614
|
+
}
|
|
2615
|
+
if (remote) {
|
|
2616
|
+
imgProps.srcSet = SRCSET_WIDTHS.map((w) => `${proxyUrl(src, w, quality)} ${w}w`).join(", ");
|
|
2617
|
+
}
|
|
2618
|
+
const img = /* @__PURE__ */ jsx3("img", { alt, ...imgProps });
|
|
2619
|
+
if (children) {
|
|
2620
|
+
return /* @__PURE__ */ jsxs2("picture", { children: [
|
|
2621
|
+
children,
|
|
2622
|
+
img
|
|
2623
|
+
] });
|
|
2624
|
+
}
|
|
2625
|
+
return img;
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2504
2628
|
// src/link.tsx
|
|
2505
|
-
import { jsx as
|
|
2629
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
2506
2630
|
function Link({ href, children, clientNav = true, prefetch = true, ...rest }) {
|
|
2507
|
-
return /* @__PURE__ */
|
|
2631
|
+
return /* @__PURE__ */ jsx4(
|
|
2508
2632
|
"a",
|
|
2509
2633
|
{
|
|
2510
2634
|
href,
|
|
@@ -2520,14 +2644,17 @@ export {
|
|
|
2520
2644
|
DEFAULT_HISTOGRAM_BUCKETS_MS,
|
|
2521
2645
|
DefaultNotFound,
|
|
2522
2646
|
EnvLeakageError,
|
|
2647
|
+
Image,
|
|
2523
2648
|
Island,
|
|
2524
2649
|
IslandProvider,
|
|
2525
2650
|
Link,
|
|
2526
2651
|
PUBLIC_ENV_PREFIX,
|
|
2652
|
+
SRCSET_WIDTHS,
|
|
2527
2653
|
applySecurityHeaders,
|
|
2528
2654
|
assertNoEnvLeakage,
|
|
2529
2655
|
build,
|
|
2530
2656
|
buildSecurityHeaders,
|
|
2657
|
+
buildSrcSet,
|
|
2531
2658
|
checkCsrf,
|
|
2532
2659
|
combineReporters,
|
|
2533
2660
|
composeMiddleware,
|
|
@@ -2571,6 +2698,7 @@ export {
|
|
|
2571
2698
|
scanPages,
|
|
2572
2699
|
scanRoutes,
|
|
2573
2700
|
setErrorReporter,
|
|
2701
|
+
setImageRemoteHosts,
|
|
2574
2702
|
verifyCsrfToken,
|
|
2575
2703
|
verifyOrigin,
|
|
2576
2704
|
withCsrfCookie,
|
package/package.json
CHANGED