UNPKG

@getcronit/pylon

Version:

![Pylon cover](https://github.com/user-attachments/assets/c28e49b2-5672-4849-826e-8b2eab0360cc)

809 lines (792 loc) 35.7 kB
var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; // src/lib/utils.ts import { clsx } from "clsx"; import { twMerge } from "tailwind-merge"; function cn(...inputs) { return twMerge(clsx(inputs)); } var init_utils = __esm({ "src/lib/utils.ts"() { "use strict"; } }); // src/components/logo.tsx import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime"; var Logo, logo_default; var init_logo = __esm({ "src/components/logo.tsx"() { "use strict"; init_utils(); Logo = (props) => { return /* @__PURE__ */ jsxs2( "svg", { className: cn("h-12 w-auto", props.className), xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink", zoomAndPan: "magnify", viewBox: "0 0 286.5 121.500001", preserveAspectRatio: "xMidYMid meet", version: "1.0", children: [ /* @__PURE__ */ jsxs2("defs", { children: [ /* @__PURE__ */ jsx4("g", {}), /* @__PURE__ */ jsx4("clipPath", { id: "38f6fcde47", children: /* @__PURE__ */ jsx4( "path", { d: "M 0.339844 42 L 10 42 L 10 79 L 0.339844 79 Z M 0.339844 42 ", clipRule: "nonzero" } ) }), /* @__PURE__ */ jsx4("clipPath", { id: "af000f7256", children: /* @__PURE__ */ jsx4( "path", { d: "M 64 23.925781 L 72.789062 23.925781 L 72.789062 96.378906 L 64 96.378906 Z M 64 23.925781 ", clipRule: "nonzero" } ) }) ] }), /* @__PURE__ */ jsx4("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx4("g", { transform: "translate(107.11969, 78.49768)", children: /* @__PURE__ */ jsx4("g", { children: /* @__PURE__ */ jsx4("path", { d: "M 10.078125 -25.046875 C 11.109375 -26.398438 12.507812 -27.535156 14.28125 -28.453125 C 16.0625 -29.378906 18.070312 -29.84375 20.3125 -29.84375 C 22.863281 -29.84375 25.195312 -29.210938 27.3125 -27.953125 C 29.425781 -26.691406 31.085938 -24.921875 32.296875 -22.640625 C 33.503906 -20.367188 34.109375 -17.757812 34.109375 -14.8125 C 34.109375 -11.863281 33.503906 -9.222656 32.296875 -6.890625 C 31.085938 -4.566406 29.425781 -2.753906 27.3125 -1.453125 C 25.195312 -0.160156 22.863281 0.484375 20.3125 0.484375 C 18.070312 0.484375 16.078125 0.03125 14.328125 -0.875 C 12.585938 -1.78125 11.171875 -2.910156 10.078125 -4.265625 L 10.078125 13.96875 L 4 13.96875 L 4 -29.359375 L 10.078125 -29.359375 Z M 27.921875 -14.8125 C 27.921875 -16.84375 27.503906 -18.59375 26.671875 -20.0625 C 25.835938 -21.539062 24.734375 -22.660156 23.359375 -23.421875 C 21.992188 -24.179688 20.53125 -24.5625 18.96875 -24.5625 C 17.445312 -24.5625 16 -24.171875 14.625 -23.390625 C 13.257812 -22.609375 12.160156 -21.472656 11.328125 -19.984375 C 10.492188 -18.492188 10.078125 -16.734375 10.078125 -14.703125 C 10.078125 -12.679688 10.492188 -10.914062 11.328125 -9.40625 C 12.160156 -7.894531 13.257812 -6.75 14.625 -5.96875 C 16 -5.1875 17.445312 -4.796875 18.96875 -4.796875 C 20.53125 -4.796875 21.992188 -5.191406 23.359375 -5.984375 C 24.734375 -6.785156 25.835938 -7.953125 26.671875 -9.484375 C 27.503906 -11.015625 27.921875 -12.789062 27.921875 -14.8125 Z M 27.921875 -14.8125 " }) }) }) }), /* @__PURE__ */ jsx4("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx4("g", { transform: "translate(143.259256, 78.49768)", children: /* @__PURE__ */ jsx4("g", { children: /* @__PURE__ */ jsx4("path", { d: "M 30.4375 -29.359375 L 12.421875 13.796875 L 6.125 13.796875 L 12.09375 -0.484375 L 0.53125 -29.359375 L 7.296875 -29.359375 L 15.5625 -6.984375 L 24.140625 -29.359375 Z M 30.4375 -29.359375 " }) }) }) }), /* @__PURE__ */ jsx4("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx4("g", { transform: "translate(174.281707, 78.49768)", children: /* @__PURE__ */ jsx4("g", { children: /* @__PURE__ */ jsx4("path", { d: "M 10.078125 -39.4375 L 10.078125 0 L 4 0 L 4 -39.4375 Z M 10.078125 -39.4375 " }) }) }) }), /* @__PURE__ */ jsx4("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx4("g", { transform: "translate(188.353752, 78.49768)", children: /* @__PURE__ */ jsx4("g", { children: /* @__PURE__ */ jsx4("path", { d: "M 16.734375 0.484375 C 13.960938 0.484375 11.457031 -0.144531 9.21875 -1.40625 C 6.976562 -2.664062 5.21875 -4.441406 3.9375 -6.734375 C 2.664062 -9.035156 2.03125 -11.691406 2.03125 -14.703125 C 2.03125 -17.691406 2.6875 -20.335938 4 -22.640625 C 5.3125 -24.953125 7.101562 -26.726562 9.375 -27.96875 C 11.65625 -29.21875 14.195312 -29.84375 17 -29.84375 C 19.8125 -29.84375 22.351562 -29.21875 24.625 -27.96875 C 26.894531 -26.726562 28.6875 -24.953125 30 -22.640625 C 31.320312 -20.335938 31.984375 -17.691406 31.984375 -14.703125 C 31.984375 -11.722656 31.304688 -9.078125 29.953125 -6.765625 C 28.597656 -4.453125 26.757812 -2.664062 24.4375 -1.40625 C 22.113281 -0.144531 19.546875 0.484375 16.734375 0.484375 Z M 16.734375 -4.796875 C 18.296875 -4.796875 19.757812 -5.164062 21.125 -5.90625 C 22.5 -6.65625 23.613281 -7.773438 24.46875 -9.265625 C 25.320312 -10.765625 25.75 -12.578125 25.75 -14.703125 C 25.75 -16.835938 25.335938 -18.640625 24.515625 -20.109375 C 23.703125 -21.585938 22.617188 -22.695312 21.265625 -23.4375 C 19.910156 -24.1875 18.453125 -24.5625 16.890625 -24.5625 C 15.328125 -24.5625 13.878906 -24.1875 12.546875 -23.4375 C 11.210938 -22.695312 10.15625 -21.585938 9.375 -20.109375 C 8.59375 -18.640625 8.203125 -16.835938 8.203125 -14.703125 C 8.203125 -11.546875 9.007812 -9.101562 10.625 -7.375 C 12.25 -5.65625 14.285156 -4.796875 16.734375 -4.796875 Z M 16.734375 -4.796875 " }) }) }) }), /* @__PURE__ */ jsx4("g", { fill: "currentColor", fillOpacity: "1", children: /* @__PURE__ */ jsx4("g", { transform: "translate(222.361196, 78.49768)", children: /* @__PURE__ */ jsx4("g", { children: /* @__PURE__ */ jsx4("path", { d: "M 18.8125 -29.84375 C 21.125 -29.84375 23.191406 -29.363281 25.015625 -28.40625 C 26.847656 -27.445312 28.28125 -26.023438 29.3125 -24.140625 C 30.34375 -22.253906 30.859375 -19.984375 30.859375 -17.328125 L 30.859375 0 L 24.84375 0 L 24.84375 -16.421875 C 24.84375 -19.046875 24.179688 -21.054688 22.859375 -22.453125 C 21.546875 -23.859375 19.753906 -24.5625 17.484375 -24.5625 C 15.210938 -24.5625 13.410156 -23.859375 12.078125 -22.453125 C 10.742188 -21.054688 10.078125 -19.046875 10.078125 -16.421875 L 10.078125 0 L 4 0 L 4 -29.359375 L 10.078125 -29.359375 L 10.078125 -26.015625 C 11.066406 -27.222656 12.332031 -28.160156 13.875 -28.828125 C 15.425781 -29.503906 17.070312 -29.84375 18.8125 -29.84375 Z M 18.8125 -29.84375 " }) }) }) }), /* @__PURE__ */ jsx4( "path", { fill: "currentColor", d: "M 53.359375 31.652344 L 53.359375 88.6875 L 62.410156 90.859375 L 62.410156 29.484375 Z M 53.359375 31.652344 ", fillOpacity: "1", fillRule: "nonzero" } ), /* @__PURE__ */ jsx4("g", { clipPath: "url(#38f6fcde47)", children: /* @__PURE__ */ jsx4( "path", { fill: "currentColor", d: "M 0.339844 47.433594 L 0.339844 72.910156 C 0.339844 73.34375 0.410156 73.769531 0.554688 74.179688 C 0.699219 74.59375 0.90625 74.96875 1.175781 75.3125 C 1.445312 75.65625 1.765625 75.945312 2.132812 76.179688 C 2.503906 76.414062 2.898438 76.582031 3.324219 76.683594 L 9.390625 78.140625 L 9.390625 42.195312 L 3.3125 43.660156 C 2.890625 43.761719 2.492188 43.929688 2.125 44.164062 C 1.761719 44.402344 1.441406 44.6875 1.171875 45.03125 C 0.902344 45.375 0.695312 45.75 0.554688 46.164062 C 0.410156 46.574219 0.339844 46.996094 0.339844 47.433594 Z M 0.339844 47.433594 ", fillOpacity: "1", fillRule: "nonzero" } ) }), /* @__PURE__ */ jsx4("g", { clipPath: "url(#af000f7256)", children: /* @__PURE__ */ jsx4( "path", { fill: "currentColor", d: "M 64.996094 95.085938 L 64.996094 25.253906 C 64.996094 25.082031 65.027344 24.917969 65.09375 24.761719 C 65.160156 24.601562 65.253906 24.460938 65.375 24.339844 C 65.496094 24.21875 65.636719 24.125 65.792969 24.0625 C 65.953125 23.996094 66.117188 23.960938 66.289062 23.960938 L 71.460938 23.960938 C 71.632812 23.960938 71.796875 23.996094 71.957031 24.0625 C 72.113281 24.125 72.253906 24.21875 72.375 24.339844 C 72.496094 24.460938 72.589844 24.601562 72.65625 24.761719 C 72.722656 24.917969 72.753906 25.082031 72.753906 25.253906 L 72.753906 95.085938 C 72.753906 95.257812 72.722656 95.421875 72.65625 95.582031 C 72.589844 95.738281 72.496094 95.878906 72.375 96 C 72.253906 96.121094 72.113281 96.214844 71.957031 96.28125 C 71.796875 96.347656 71.632812 96.378906 71.460938 96.378906 L 66.289062 96.378906 C 66.117188 96.378906 65.953125 96.347656 65.792969 96.28125 C 65.636719 96.214844 65.496094 96.121094 65.375 96 C 65.253906 95.878906 65.160156 95.738281 65.09375 95.582031 C 65.027344 95.421875 64.996094 95.257812 64.996094 95.085938 Z M 64.996094 95.085938 ", fillOpacity: "1", fillRule: "nonzero" } ) }), /* @__PURE__ */ jsx4( "path", { fill: "currentColor", d: "M 22.320312 81.238281 L 22.320312 39.101562 L 11.976562 41.585938 L 11.976562 78.757812 Z M 22.320312 81.238281 ", fillOpacity: "1", fillRule: "nonzero" } ), /* @__PURE__ */ jsx4( "path", { fill: "currentColor", d: "M 50.769531 88.066406 L 50.769531 32.277344 L 37.839844 35.378906 L 37.839844 84.960938 Z M 50.769531 88.066406 ", fillOpacity: "1", fillRule: "nonzero" } ), /* @__PURE__ */ jsx4( "path", { fill: "currentColor", d: "M 24.90625 81.863281 L 35.253906 84.34375 L 35.253906 35.996094 L 24.90625 38.480469 Z M 24.90625 81.863281 ", fillOpacity: "1", fillRule: "nonzero" } ) ] } ); }; logo_default = Logo; } }); // src/components/global-error-page.tsx import { useEffect as useEffect4 } from "react"; import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime"; function GlobalError({ error, ...rest }) { useEffect4(() => { console.error("Global error:", error); }, [error]); const reset = () => { window.location.reload(); }; const manifest = globalThis.__PYLON_MANIFEST__; return /* @__PURE__ */ jsxs5("html", { lang: "en", children: [ /* @__PURE__ */ jsxs5("head", { children: [ /* @__PURE__ */ jsx7("meta", { charSet: "utf-8" }), /* @__PURE__ */ jsx7("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }), manifest?.["index.css"] && /* @__PURE__ */ jsx7( "link", { rel: "stylesheet", href: manifest["index.css"], precedence: "high" } ) ] }), /* @__PURE__ */ jsx7("body", { children: /* @__PURE__ */ jsx7("div", { className: "fixed inset-0 bg-black/90 z-50 overflow-y-auto p-4 flex items-center justify-center", children: /* @__PURE__ */ jsxs5("div", { className: "w-full max-w-3xl bg-black border border-red-600 rounded-lg overflow-hidden text-white font-sans", children: [ /* @__PURE__ */ jsx7("div", { className: "flex items-center justify-between border-b border-neutral-800 p-4", children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-3", children: [ /* @__PURE__ */ jsx7("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx7(logo_default, { className: "h-8 w-auto text-white" }) }), /* @__PURE__ */ jsx7("div", { children: /* @__PURE__ */ jsx7("h1", { className: "text-xl font-medium text-red-500", children: "Application Crashed" }) }) ] }) }), /* @__PURE__ */ jsxs5("div", { className: "p-4", children: [ /* @__PURE__ */ jsx7("div", { className: "mb-4 text-neutral-400", children: "The application encountered a critical error and could not continue." }), /* @__PURE__ */ jsx7("h2", { className: "text-2xl font-bold mb-4 text-white", children: error.message || "A critical error occurred" }), error.digest && /* @__PURE__ */ jsxs5("div", { className: "mb-4", children: [ /* @__PURE__ */ jsx7("h3", { className: "text-sm uppercase tracking-wider text-neutral-500 font-medium mb-2", children: "Error ID" }), /* @__PURE__ */ jsx7("div", { className: "bg-neutral-900 rounded-md p-3 text-neutral-300 font-mono", children: error.digest }) ] }) ] }) ] }) }) }) ] }); } var init_global_error_page = __esm({ "src/components/global-error-page.tsx"() { "use strict"; init_logo(); } }); // src/components/ui/button.tsx import { Slot } from "@radix-ui/react-slot"; import { cva } from "class-variance-authority"; import { jsx as jsx8 } from "react/jsx-runtime"; function Button({ className, variant, size, asChild = false, ...props }) { const Comp = asChild ? Slot : "button"; return /* @__PURE__ */ jsx8( Comp, { "data-slot": "button", className: cn(buttonVariants({ variant, size, className })), ...props } ); } var buttonVariants; var init_button = __esm({ "src/components/ui/button.tsx"() { "use strict"; init_utils(); buttonVariants = cva( "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[color,box-shadow] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", { variants: { variant: { default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90", destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40", outline: "border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground", secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80", ghost: "hover:bg-accent hover:text-accent-foreground", link: "text-primary underline-offset-4 hover:underline" }, size: { default: "h-9 px-4 py-2 has-[>svg]:px-3", sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5", lg: "h-10 rounded-md px-6 has-[>svg]:px-4", icon: "size-9" } }, defaultVariants: { variant: "default", size: "default" } } ); } }); // src/components/status-page.tsx import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime"; var StatusPage; var init_status_page = __esm({ "src/components/status-page.tsx"() { "use strict"; init_button(); StatusPage = ({ code, title, message, standalone = false, returnText = "Return to home", returnUrl = "/" }) => { const element = /* @__PURE__ */ jsxs6("div", { className: "flex min-h-screen w-full flex-col items-center justify-center bg-white p-4 text-center", children: [ /* @__PURE__ */ jsx9("title", { children: title }), /* @__PURE__ */ jsx9("h1", { className: "mb-2 text-9xl font-thin tracking-tight text-gray-900", children: code }), /* @__PURE__ */ jsx9("h2", { className: "mb-6 text-xl font-light text-gray-600", children: title }), /* @__PURE__ */ jsx9("p", { className: "mb-8 max-w-md text-sm text-gray-500", children: message }), /* @__PURE__ */ jsx9(Button, { asChild: true, children: /* @__PURE__ */ jsx9("a", { href: returnUrl, children: returnText }) }) ] }); const manifest = globalThis.__PYLON_MANIFEST__; if (standalone) { return /* @__PURE__ */ jsxs6("html", { children: [ /* @__PURE__ */ jsxs6("head", { children: [ /* @__PURE__ */ jsx9("meta", { charSet: "utf-8" }), /* @__PURE__ */ jsx9("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }), manifest?.["index.css"] && /* @__PURE__ */ jsx9( "link", { rel: "stylesheet", href: manifest["index.css"], precedence: "high" } ) ] }), /* @__PURE__ */ jsx9("body", { children: element }) ] }); } return element; }; } }); // src/pages/index.ts import * as __PYLON_ROUTER_INTERNALS_DO_NOT_USE from "react-router"; // src/pages/internals.tsx var internals_exports = {}; __export(internals_exports, { DataClientProvider: () => DataClientProvider, RouteDataProvider: () => RouteDataProvider, SSRPruningProvider: () => SSRPruningProvider, useDataClient: () => useDataClient, useRouteData: () => useRouteData, useRouteDataRefetch: () => useRouteDataRefetch, useSSRPruning: () => useSSRPruning }); import { createContext, useContext, useEffect, useRef } from "react"; import { jsx } from "react/jsx-runtime"; var dataClientContext = createContext(null); var DataClientProvider = ({ children, client }) => { return /* @__PURE__ */ jsx(dataClientContext.Provider, { value: { client }, children }); }; var useDataClient = () => { const context = useContext(dataClientContext); if (!context) { throw new Error("useDataClient must be used within a DataClientProvider"); } return context.client; }; var refetchRegistry = /* @__PURE__ */ new Map(); var RouteDataContext = createContext(null); var RouteDataProvider = ({ children, props, name }) => { const refetchFnRef = useRef(props.data.$refetch); refetchFnRef.current = props.data.$refetch; useEffect(() => { if (name) { refetchRegistry.set(name, refetchFnRef.current); return () => { refetchRegistry.delete(name); }; } }, [name]); return /* @__PURE__ */ jsx(RouteDataContext.Provider, { value: props, children }); }; var useRouteData = () => { const context = useContext(RouteDataContext); if (!context) { throw new Error("useRouteData must be used within a RouteDataProvider"); } return context; }; var useRouteDataRefetch = () => { const currentRefetch = useRouteData().data.$refetch; const pageRefresh = (names) => { const refetchesToCall = [currentRefetch]; if (names && names.length > 0) { for (const name of names) { const namedRefetch = refetchRegistry.get(name); if (namedRefetch) { if (namedRefetch !== currentRefetch) { refetchesToCall.push(namedRefetch); } } else { console.warn( `usePageRefresh: No RouteDataProvider found currently mounted with name "${name}". Skipping refresh for this name.` ); } } } const uniqueRefetches = Array.from(new Set(refetchesToCall)); return Promise.all(uniqueRefetches.map((refetch) => refetch())); }; return pageRefresh; }; var SSRPruningContext = createContext(null); var SSRPruningProvider = ({ children, target }) => { return /* @__PURE__ */ jsx(SSRPruningContext.Provider, { value: target, children }); }; var useSSRPruning = () => { return useContext(SSRPruningContext); }; // src/pages/image.tsx import { useMemo } from "react"; import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime"; var usePylonImageValues = (props) => { return useMemo(() => { const pylonMediaSearchParams = new URLSearchParams({}); let blurDataURL; if (typeof props.src === "string") { pylonMediaSearchParams.set("src", props.src); } else { pylonMediaSearchParams.set("src", props.src.url); if (props.src.width) { pylonMediaSearchParams.set("w", props.src.width.toString()); } if (props.src.height) { pylonMediaSearchParams.set("h", props.src.height.toString()); } blurDataURL = props.src.blurDataURL; } if (props.width) { pylonMediaSearchParams.set("w", props.width.toString()); } if (props.height) { pylonMediaSearchParams.set("h", props.height.toString()); } if (props.blurDataURL) { blurDataURL = props.blurDataURL; } const finalSrc = `/__pylon/image?${pylonMediaSearchParams.toString()}`; const width = pylonMediaSearchParams.has("w") ? parseInt(pylonMediaSearchParams.get("w")) : void 0; const height = pylonMediaSearchParams.has("h") ? parseInt(pylonMediaSearchParams.get("h")) : void 0; const preloads = []; if (!blurDataURL) { blurDataURL = finalSrc + "&lqip=true"; preloads.push(blurDataURL); } return { width, height, blurDataURL, src: finalSrc, preloads }; }, [props]); }; var Image = (props) => { const values = usePylonImageValues(props); return /* @__PURE__ */ jsxs(Fragment, { children: [ values.preloads.map((src, index) => /* @__PURE__ */ jsx2("link", { rel: "preload", as: "image", href: src }, index)), /* @__PURE__ */ jsx2( "img", { src: values.src, alt: props.alt, className: props.className, width: values.width, height: values.height, style: { backgroundImage: `url(${values.blurDataURL})`, backgroundSize: "cover", height: props.fill ? "100%" : void 0, width: props.fill ? "100%" : void 0, ...props.style }, loading: "lazy" } ) ] }); }; // src/pages/link.tsx import { Link as LinkComp } from "react-router"; import { jsx as jsx3 } from "react/jsx-runtime"; var Link = (props) => { const { href, ...rest } = props; return /* @__PURE__ */ jsx3(LinkComp, { to: href, ...rest }); }; // src/components/dev-overlay/report-error.ts var errorStore = { error: null, errorInfo: null, errorType: null, listeners: /* @__PURE__ */ new Set() }; function reportError(error, errorInfo, errorType) { errorStore.error = error; errorStore.errorInfo = errorInfo; errorStore.errorType = errorType; const data = { error: errorStore.error, errorInfo: errorStore.errorInfo, errorType: errorStore.errorType }; errorStore.listeners.forEach((listener) => { listener(data); }); if (true) { console.error(`[${errorType} error]:`, error); if (errorInfo.componentStack) { console.error("Component stack:", errorInfo.componentStack); } } } function clearError() { errorStore.error = null; errorStore.errorInfo = null; errorStore.errorType = null; const data = { error: null, errorInfo: null, errorType: null }; errorStore.listeners.forEach((listener) => { listener(data); }); } function subscribeToErrors(callback) { errorStore.listeners.add(callback); return () => { errorStore.listeners.delete(callback); }; } function getCurrentError() { return { error: errorStore.error, errorInfo: errorStore.errorInfo, errorType: errorStore.errorType }; } var onCaughtErrorProd = (error, errorInfo) => { reportError(error, errorInfo, "caught"); }; var onUncaughtErrorProd = (error, errorInfo) => { reportError(error, errorInfo, "uncaught"); }; var onRecoverableErrorProd = (error, errorInfo) => { reportError(error, errorInfo, "recoverable"); }; // src/components/dev-overlay/dev-overlay-provider.tsx init_logo(); import { useEffect as useEffect3, useState as useState2 } from "react"; import { createPortal } from "react-dom"; // src/components/dev-overlay/dev-error-overlay.tsx import { X } from "lucide-react"; import { useEffect as useEffect2, useState } from "react"; import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime"; function DevErrorOverlay({ error, errorInfo, errorType, onCaughtError, onUncaughtError, onRecoverableError, identifierPrefix, onDismiss, logo }) { const [isVisible, setIsVisible] = useState(true); useEffect2(() => { if (errorType === "caught" && onCaughtError) { onCaughtError(error, errorInfo); } else if (errorType === "uncaught" && onUncaughtError) { onUncaughtError(error, errorInfo); } else if (errorType === "recoverable" && onRecoverableError) { onRecoverableError(error, errorInfo); } }, [ error, errorInfo, errorType, onCaughtError, onUncaughtError, onRecoverableError ]); const handleDismiss = () => { setIsVisible(false); if (onDismiss) onDismiss(); }; if (!isVisible || !error) { return null; } const getErrorTypeLabel = () => { switch (errorType) { case "caught": return "Error Boundary Caught Error"; case "uncaught": return "Uncaught Error"; case "recoverable": return "Recoverable Error"; case "identifier": return "Identifier Prefix Error"; default: return "Runtime Error"; } }; const getErrorTypeDescription = () => { switch (errorType) { case "caught": return "This error was caught by a React Error Boundary."; case "uncaught": return "This error was not caught by any Error Boundary and crashed your application."; case "recoverable": return "React automatically recovered from this error, but you should still fix it."; case "identifier": return `Identifier prefix mismatch. Expected prefix: "${identifierPrefix}".`; default: return "An unexpected error occurred during runtime."; } }; const getErrorBorderColor = () => { switch (errorType) { case "caught": return "border-yellow-600"; case "uncaught": return "border-red-600"; case "recoverable": return "border-blue-600"; case "identifier": return "border-purple-600"; default: return "border-red-600"; } }; const manifest = globalThis.__PYLON_MANIFEST__; return /* @__PURE__ */ jsxs3("div", { className: "fixed inset-0 bg-black/80 backdrop-blur-sm z-50 overflow-y-auto p-4 flex items-start justify-center", children: [ manifest?.["index.css"] && /* @__PURE__ */ jsx5("link", { rel: "stylesheet", href: manifest["index.css"], precedence: "high" }), /* @__PURE__ */ jsxs3( "div", { className: `w-full max-w-3xl bg-black border ${getErrorBorderColor()} rounded-lg mt-16 overflow-hidden text-white font-sans`, children: [ /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between border-b border-neutral-800 p-4", children: [ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-3", children: [ logo && /* @__PURE__ */ jsx5("div", { className: "flex-shrink-0", children: typeof logo === "string" ? /* @__PURE__ */ jsx5( "img", { src: logo || "/placeholder.svg", alt: "Error Overlay Logo", className: "h-8 w-auto" } ) : logo }), /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5("h1", { className: "text-xl font-medium text-red-500", children: getErrorTypeLabel() }) }) ] }), /* @__PURE__ */ jsx5( "button", { onClick: handleDismiss, className: "p-2 rounded-full hover:bg-neutral-800 transition-colors", "aria-label": "Dismiss error overlay", children: /* @__PURE__ */ jsx5(X, { className: "h-5 w-5 text-neutral-400" }) } ) ] }), /* @__PURE__ */ jsxs3("div", { className: "p-4", children: [ /* @__PURE__ */ jsx5("div", { className: "mb-4 text-neutral-400", children: getErrorTypeDescription() }), /* @__PURE__ */ jsx5("h2", { className: "text-2xl font-bold mb-4 text-white", children: error.message || "An unexpected error has occurred" }), !!error.cause && /* @__PURE__ */ jsxs3("div", { className: "mb-4", children: [ /* @__PURE__ */ jsx5("h3", { className: "text-sm uppercase tracking-wider text-neutral-500 font-medium mb-2", children: "Cause" }), /* @__PURE__ */ jsx5("div", { className: "bg-neutral-900 rounded-md p-3 text-neutral-300", children: String(error.cause) }) ] }) ] }), errorInfo?.componentStack && /* @__PURE__ */ jsxs3("div", { className: "p-4 border-t border-neutral-800", children: [ /* @__PURE__ */ jsx5("h3", { className: "text-sm uppercase tracking-wider text-neutral-500 font-medium mb-3", children: "Component Stack" }), /* @__PURE__ */ jsx5("div", { className: "bg-neutral-900 rounded-md p-4 overflow-x-auto", children: /* @__PURE__ */ jsx5("pre", { className: "font-mono text-sm text-neutral-300 whitespace-pre-wrap", children: errorInfo.componentStack }) }) ] }), /* @__PURE__ */ jsxs3("div", { className: "p-4 border-t border-neutral-800", children: [ /* @__PURE__ */ jsx5("h3", { className: "text-sm uppercase tracking-wider text-neutral-500 font-medium mb-3", children: "Call Stack" }), /* @__PURE__ */ jsx5("div", { className: "bg-neutral-900 rounded-md p-4 overflow-x-auto", children: /* @__PURE__ */ jsx5("pre", { className: "font-mono text-sm text-neutral-300 whitespace-pre-wrap", children: error.stack || "No stack trace available" }) }) ] }), /* @__PURE__ */ jsxs3("div", { className: "p-4 border-t border-neutral-800 flex justify-between", children: [ /* @__PURE__ */ jsx5("div", { children: errorType === "recoverable" && /* @__PURE__ */ jsx5("span", { className: "text-blue-400 text-sm", children: "React automatically recovered from this error" }) }), /* @__PURE__ */ jsxs3("div", { className: "flex gap-3", children: [ /* @__PURE__ */ jsx5( "button", { onClick: handleDismiss, className: "bg-neutral-800 text-white px-4 py-2 rounded-md text-sm font-medium hover:bg-neutral-700 transition-colors", children: "Dismiss" } ), /* @__PURE__ */ jsx5( "button", { onClick: () => window.location.reload(), className: "bg-white text-black px-4 py-2 rounded-md text-sm font-medium hover:bg-neutral-200 transition-colors", children: "Reload Page" } ) ] }) ] }) ] } ) ] }); } // src/components/dev-overlay/error-boundary.tsx import { Component } from "react"; var ErrorBoundary = class extends Component { constructor(props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(_) { return { hasError: true }; } componentDidCatch(error, errorInfo) { const customErrorInfo = { componentStack: errorInfo.componentStack }; onCaughtErrorProd(error, customErrorInfo); console.error("Error caught by boundary:", error, errorInfo); } render() { if (this.state.hasError) { return this.props.fallback || null; } return this.props.children; } }; // src/components/dev-overlay/dev-overlay-provider.tsx import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime"; function DevOverlayProvider({ children, identifierPrefix }) { const [error, setError] = useState2(null); const [errorInfo, setErrorInfo] = useState2(null); const [errorType, setErrorType] = useState2(null); const [overlayContainer, setOverlayContainer] = useState2( null ); useEffect3(() => { const currentError = getCurrentError(); if (currentError.error) { setError(currentError.error); setErrorInfo(currentError.errorInfo); setErrorType(currentError.errorType); } const container = document.createElement("div"); container.id = "dev-error-overlay-container"; document.body.appendChild(container); setOverlayContainer(container); const unsubscribe = subscribeToErrors((data) => { setError(data.error); setErrorInfo(data.errorInfo); setErrorType(data.errorType); }); return () => { unsubscribe(); document.body.removeChild(container); }; }, []); const handleDismiss = () => { clearError(); setError(null); setErrorInfo(null); setErrorType(null); }; return /* @__PURE__ */ jsxs4(Fragment2, { children: [ /* @__PURE__ */ jsx6(ErrorBoundary, { children }), overlayContainer && error && errorInfo && errorType && createPortal( /* @__PURE__ */ jsx6( DevErrorOverlay, { logo: /* @__PURE__ */ jsx6(logo_default, {}), error, errorInfo, errorType, onDismiss: handleDismiss, identifierPrefix, onCaughtError: (e, i) => console.log("Overlay caught error:", e, i), onUncaughtError: (e, i) => console.log("Overlay uncaught error:", e, i), onRecoverableError: (e, i) => console.log("Overlay recoverable error:", e, i) } ), overlayContainer ) ] }); } // src/pages/index.ts init_global_error_page(); init_status_page(); // src/pages/http.ts function notFound(message = "Not Found", args) { const data = { message, returnText: args?.returnText, returnUrl: args?.returnUrl }; throw new Response(JSON.stringify(data), { status: 404, statusText: args?.statusText || "This page doesn't exist" }); } function forbidden(message = "Forbidden", args) { const data = { message, returnText: args?.returnText, returnUrl: args?.returnUrl }; throw new Response(JSON.stringify(data), { status: 403, statusText: args?.statusText || "Forbidden" }); } function unauthorized(message = "Unauthorized", args) { const data = { message, returnText: args?.returnText, returnUrl: args?.returnUrl }; throw new Response(JSON.stringify(data), { status: 401, statusText: args?.statusText || "Unauthorized" }); } function redirect(url, args) { const response = new Response(null, { status: args?.status || 302, statusText: args?.statusText || "Redirecting", headers: { Location: url, ...args?.headers } }); throw response; } export { DevOverlayProvider as DevOverlay, GlobalError as GlobalErrorPage, Image, Link, StatusPage, internals_exports as __PYLON_INTERNALS_DO_NOT_USE, __PYLON_ROUTER_INTERNALS_DO_NOT_USE, clearError, forbidden, getCurrentError, notFound, onCaughtErrorProd, onRecoverableErrorProd, onUncaughtErrorProd, redirect, reportError, subscribeToErrors, unauthorized, useRouteData, useRouteDataRefetch }; //# sourceMappingURL=index.js.map