Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,42 @@
/**
* BaseComponent that must be used to create custom components.
* It has support for loading CSS files and frontend scripts.
*/
export declare abstract class BaseComponent<Props = undefined> {
#private;
$props: Props;
/**
* Absolute path to the frontend JavaScript that should be
* injected within the HTML head. The JavaScript does not
* get transpiled, hence it should work cross browser by
* default.
*/
scriptFile?: string | URL;
/**
* Absolute path to the CSS file that should be injected
* within the HTML head.
*/
cssFile?: string | URL;
constructor(devMode: boolean);
/**
* Returns the styles for the component. The null value
* is not returned if no styles are associated with
* the component
*/
getStyles(): Promise<string | null>;
/**
* Returns the frontend script for the component. The null
* value is not returned if no styles are associated
* with the component
*/
getScript(): Promise<string | null>;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
abstract toHTML(props: Props): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
abstract toANSI(props: Props): Promise<string>;
}

View file

@ -0,0 +1,24 @@
import { type Colors } from '@poppinss/colors/types';
/**
* HTML escape string values so that they can be nested
* inside the pre-tags.
*/
export declare function htmlEscape(value: string): string;
/**
* Wraps a string value to be on multiple lines after
* a certain characters limit has been hit.
*/
export declare function wordWrap(value: string, options: {
width: number;
indent: string;
newLine: string;
escape?: (value: string) => string;
}): string;
/**
* Strips ANSI sequences from the string
*/
export declare function stripAnsi(value: string): string;
/**
* ANSI coloring library
*/
export declare const colors: Colors;

View file

@ -0,0 +1,28 @@
import { type ErrorMetadataGroups, type ErrorMetadataRow } from './types.js';
/**
* Attach metadata to the parsed error as groups, sections
* and rows.
*
* - Groups are rendered as cards
* - Sections are headings within the cards
* - And rows are rendered within HTML tables.
*
* The primitive row values are rendered as it is and rich data-types
* like Objects, Arrays, Maps are printed using dumper.
*/
export declare class Metadata {
#private;
/**
* Define a group, its sections and their rows. In case of
* existing groups/sections, the new data will be merged
* with the existing data
*/
group(name: string, sections: {
[section: string]: ErrorMetadataRow | ErrorMetadataRow[];
}): this;
/**
* Returns the existing metadata groups, sections and
* rows.
*/
toJSON(): ErrorMetadataGroups;
}

View file

@ -0,0 +1 @@
export declare const publicDirURL: URL;

View file

@ -0,0 +1,61 @@
import type { ParsedError } from 'youch-core/types';
import { type Metadata } from './metadata.js';
import type { YouchTemplates } from './types.js';
/**
* A super lightweight templates collection that allows composing
* HTML using TypeScript based components with the ability to
* override the component for a pre-defined template.
*
* @example
* ```ts
* const templates = new Templates()
* const html = templates.render(
* {
* title: 'Internal server error',
* error: await new ErrorParser().parse(error)
* }
* )
*
* // Override a template
* class MyHeader extends BaseComponent {
* async render() {}
* }
*
* templates.use('header', new MyHeader(templates.devMode))
* ```
*/
export declare class Templates {
#private;
devMode: boolean;
constructor(devMode: boolean);
/**
* Define a custom component to be used in place of the default component.
* Overriding components allows you control the HTML layout, styles and
* the frontend scripts of an HTML fragment.
*/
use<K extends keyof YouchTemplates>(templateName: K, component: YouchTemplates[K]): this;
/**
* Inject custom styles to the document. Injected styles are
* always placed after the global and the components style
* tags.
*/
injectStyles(cssFragment: string): this;
/**
* Returns the HTML output for the given parsed error
*/
toHTML(props: {
title: string;
ide?: string;
cspNonce?: string;
error: ParsedError;
metadata: Metadata;
}): Promise<string>;
/**
* Returns the ANSI output to be printed on the terminal
*/
toANSI(props: {
title: string;
error: ParsedError;
metadata: Metadata;
}): Promise<string>;
}

View file

@ -0,0 +1,17 @@
import { BaseComponent } from '../../component.js';
import type { ErrorCauseProps } from '../../types.js';
/**
* Displays the Error cause as a formatted value
*/
export declare class ErrorCause extends BaseComponent<ErrorCauseProps> {
cssFile: URL;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
toHTML(props: ErrorCause['$props']): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
toANSI(props: ErrorCauseProps): Promise<string>;
}

View file

@ -0,0 +1,8 @@
import {
ErrorCause
} from "../../../chunk-X53OIOJH.js";
import "../../../chunk-4L7RY2JA.js";
import "../../../chunk-PE3GG3TN.js";
export {
ErrorCause
};

View file

@ -0,0 +1,19 @@
import { BaseComponent } from '../../component.js';
import type { ErrorInfoProps } from '../../types.js';
/**
* Displays the error info including the response status text,
* error name, error message and the hint.
*/
export declare class ErrorInfo extends BaseComponent<ErrorInfoProps> {
cssFile: URL;
scriptFile: URL;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
toHTML(props: ErrorInfoProps): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
toANSI(props: ErrorInfoProps): Promise<string>;
}

View file

@ -0,0 +1,8 @@
import {
ErrorInfo
} from "../../../chunk-OIJ3WD7L.js";
import "../../../chunk-4L7RY2JA.js";
import "../../../chunk-PE3GG3TN.js";
export {
ErrorInfo
};

View file

@ -0,0 +1,18 @@
import { BaseComponent } from '../../component.js';
import type { ErrorMetadataProps } from '../../types.js';
/**
* Displays the error metadata as cards
*/
export declare class ErrorMetadata extends BaseComponent<ErrorMetadataProps> {
#private;
cssFile: URL;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
toHTML(props: ErrorMetadataProps): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
toANSI(): Promise<string>;
}

View file

@ -0,0 +1,7 @@
import {
ErrorMetadata
} from "../../../chunk-P36L72PL.js";
import "../../../chunk-PE3GG3TN.js";
export {
ErrorMetadata
};

View file

@ -0,0 +1,20 @@
import { BaseComponent } from '../../component.js';
import type { ErrorStackProps } from '../../types.js';
/**
* Displays the formatted and raw error stack along with the
* source code for individual stack frames
*/
export declare class ErrorStack extends BaseComponent<ErrorStackProps> {
#private;
cssFile: URL;
scriptFile: URL;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
toHTML(props: ErrorStackProps): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
toANSI(props: ErrorStackProps): Promise<string>;
}

View file

@ -0,0 +1,8 @@
import {
ErrorStack
} from "../../../chunk-EJH674NB.js";
import "../../../chunk-4L7RY2JA.js";
import "../../../chunk-PE3GG3TN.js";
export {
ErrorStack
};

View file

@ -0,0 +1,18 @@
import { BaseComponent } from '../../component.js';
import type { ErrorStackSourceProps } from '../../types.js';
/**
* Pretty prints the stack frame source code with syntax
* highlighting.
*/
export declare class ErrorStackSource extends BaseComponent<ErrorStackSourceProps> {
cssFile: URL;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
toHTML(props: ErrorStackSourceProps): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
toANSI(props: ErrorStackSourceProps): Promise<string>;
}

View file

@ -0,0 +1,8 @@
import {
ErrorStackSource
} from "../../../chunk-7QV3D5YX.js";
import "../../../chunk-4L7RY2JA.js";
import "../../../chunk-PE3GG3TN.js";
export {
ErrorStackSource
};

View file

@ -0,0 +1,19 @@
import { BaseComponent } from '../../component.js';
import type { ComponentSharedProps } from '../../types.js';
/**
* Renders the header for the error page. It contains only the
* theme-switcher for now
*/
export declare class Header extends BaseComponent<ComponentSharedProps> {
cssFile: URL;
scriptFile: URL;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
toHTML(): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
toANSI(): Promise<string>;
}

View file

@ -0,0 +1,7 @@
import {
Header
} from "../../../chunk-AUGPHE32.js";
import "../../../chunk-PE3GG3TN.js";
export {
Header
};

View file

@ -0,0 +1,22 @@
import { BaseComponent } from '../../component.js';
import type { LayoutProps } from '../../types.js';
/**
* Layout component renders the HTML structure for the document
* along with the styles for the global elements.
*
* You can define a custom Layout if you want to modify the HTML
* structure or the CSS variables for the colors.
*/
export declare class Layout extends BaseComponent<LayoutProps> {
cssFile: URL;
scriptFile: URL;
/**
* The toHTML method is used to output the HTML for the
* web view
*/
toHTML(props: LayoutProps): Promise<string>;
/**
* The toANSI method is used to output the text for the console
*/
toANSI(props: LayoutProps): Promise<string>;
}

View file

@ -0,0 +1,7 @@
import {
Layout
} from "../../../chunk-CM7DWJNZ.js";
import "../../../chunk-PE3GG3TN.js";
export {
Layout
};

View file

@ -0,0 +1,178 @@
import type { ParsedError, StackFrame } from 'youch-core/types';
import type { Metadata } from './metadata.js';
import type { BaseComponent } from './component.js';
export * from 'youch-core/types';
/**
* Props accepted by the Layout component
*/
export type LayoutProps = ComponentSharedProps & {
title: string;
children: () => string | Promise<string>;
};
/**
* Props accepted by the Error stack source component
*/
export type ErrorStackSourceProps = ComponentSharedProps & {
error: ParsedError;
frame: StackFrame;
};
/**
* Props accepted by the Error stack component
*/
export type ErrorStackProps = ComponentSharedProps & {
error: ParsedError;
ide: string;
sourceCodeRenderer: (error: ParsedError, frame: StackFrame) => Promise<string>;
};
/**
* Props accepted by the Error info component
*/
export type ErrorInfoProps = ComponentSharedProps & {
title: string;
error: ParsedError;
};
/**
* Props accepted by the Error cause component
*/
export type ErrorCauseProps = ComponentSharedProps & {
error: ParsedError;
};
/**
* Props accepted by the Error metadata component
*/
export type ErrorMetadataProps = ComponentSharedProps & {
metadata: Metadata;
};
/**
* Error metadata row represents a key-value pair
*/
export type ErrorMetadataRow = {
key: string;
dump?: boolean;
value: any;
};
/**
* Representation of Error metadata groups. Each group is
* a collection of named sections
*/
export type ErrorMetadataGroups = {
[group: string]: {
[section: string]: ErrorMetadataRow | ErrorMetadataRow[];
};
};
/**
* Props shared with all the components
*/
export type ComponentSharedProps = {
ide?: string;
cspNonce?: string;
};
/**
* Collection of known templates. Only these templates can be
* rendered using the Templates collection
*/
export type YouchTemplates = {
header: BaseComponent<ComponentSharedProps>;
layout: BaseComponent<LayoutProps>;
errorInfo: BaseComponent<ErrorInfoProps>;
errorStack: BaseComponent<ErrorStackProps>;
errorStackSource: BaseComponent<ErrorStackSourceProps>;
errorCause: BaseComponent<ErrorCauseProps>;
errorMetadata: BaseComponent<ErrorMetadataProps>;
};
/**
* Set of options accepted by Youch when rendering error
* to HTML
*/
export type YouchHTMLOptions = {
/**
* Define the offset to skip certain stack frames from
* the top
*/
offset?: number;
/**
* Number of lines of code to display for the error stack frame.
* For example: If you set the frameSourceBuffer=7, then 3 lines
* above the error line and 3 lines after the error line will
* be displayed.
*/
frameSourceBuffer?: number;
/**
* Define the error title. It could be the HTTP status
* text
*/
title?: string;
/**
* Define the name of the IDE in which to open the files when
* the filename anchor tag is clicked.
*
* Following is the list of supported editors
*
* - textmate
* - macvim
* - emacs
* - sublime
* - phpstorm
* - atom
* - vscode
*
* You can also specify the URL for the editor via the `ide` property. Make
* sure to specify the placeholders for the filename and the line number
* as follows.
*
* someprotocol://file/%f:%l
*
* - %f is the filename placeholder
* - %l is the line number placeholder
*/
ide?: string;
/**
* CSP nonce to define on inline style and script tags
*/
cspNonce?: string;
/**
* Specify the HTTP request properties to be printed as
* metadata under the "Request" group
*/
request?: {
url?: string;
method?: string;
headers?: Record<string, string | string[] | undefined>;
};
};
/**
* Set of options accepted by Youch when rendering error
* to ANSI output
*/
export type YouchANSIOptions = {
/**
* Define the offset to skip certain stack frames from
* the top
*/
offset?: number;
/**
* Number of lines of code to display for the error stack frame.
* For example: If you set the frameSourceBuffer=7, then 3 lines
* above the error line and 3 lines after the error line will
* be displayed.
*/
frameSourceBuffer?: number;
};
/**
* Set of options accepted by Youch when rendering error
* to JSON output
*/
export type YouchJSONOptions = {
/**
* Define the offset to skip certain stack frames from
* the top
*/
offset?: number;
/**
* Number of lines of code to display for the error stack frame.
* For example: If you set the frameSourceBuffer=7, then 3 lines
* above the error line and 3 lines after the error line will
* be displayed.
*/
frameSourceBuffer?: number;
};

View file

@ -0,0 +1,2 @@
// src/types.ts
export * from "youch-core/types";

View file

@ -0,0 +1,48 @@
import type { Parser, SourceLoader, Transformer } from 'youch-core/types';
import { Metadata } from './metadata.js';
import { Templates } from './templates.js';
import { type YouchANSIOptions, type YouchHTMLOptions, type YouchJSONOptions } from './types.js';
/**
* Youch exposes the API to render errors to HTML output
*/
export declare class Youch {
#private;
/**
* Manage templates used for converting error to the HTML
* output
*/
templates: Templates;
/**
* Define metadata to be displayed alongside the error output
*/
metadata: Metadata;
/**
* Define custom implementation for loading the source code
* of a stack frame.
*/
defineSourceLoader(loader: SourceLoader): this;
/**
* Define a custom parser. Parsers are executed before the
* error gets parsed and provides you with an option to
* modify the error
*/
useParser(parser: Parser): this;
/**
* Define a custom transformer. Transformers are executed
* after the error has been parsed and can mutate the
* properties of the parsed error.
*/
useTransformer(transformer: Transformer): this;
/**
* Parses error to JSON
*/
toJSON(error: unknown, options?: YouchJSONOptions): Promise<import("youch-core/types").ParsedError>;
/**
* Render error to HTML
*/
toHTML(error: unknown, options?: YouchHTMLOptions): Promise<string>;
/**
* Render error to ANSI output
*/
toANSI(error: unknown, options?: YouchANSIOptions): Promise<string>;
}