// Generated by dts-bundle-generator v9.5.1 import { Hono } from 'hono/tiny'; export type IconSize = 72 | 96 | 128 | 144 | 152 | 192 | 384 | 512; export interface NewstackPage { title: string; image: string; description?: string; locale: string; } export interface NewstackProject { domain: string; name: string; icons: Partial>; favicon: string; cdn?: string; color?: string; shortName?: string; backgroundColor?: string; display?: "standalone" | "fullscreen" | "minimal-ui" | "browser"; orientation?: "portrait" | "landscape" | "any"; scope?: string; } export interface NewstackRouter { url: string; path: string; base: string; event: string; previous: string; } export interface NewstackParams extends Record { } export interface NewstackSettings extends Record { } export interface NewstackSecrets extends Record { } export interface NewstackDependencies extends Record { } export interface NewstackWorker { enabled: boolean; mode: "ssr" | "ssg" | "spa"; online: boolean; responsive: boolean; registration: ServiceWorkerRegistration | null; installation: Event | null; queues: Record; } /** * Collection of instances of Newstack classes that can be used to store * and manage state or services across the application. */ export interface NewstackInstances extends Record { } export interface NewstackCommonContext { /** * Page metadata */ page: NewstackPage; /** * Unique hash for the current build, used for cache-busting assets. */ fingerprint: string; /** * Information about the app manifest and metadata */ project: NewstackProject; /** * Map of public settings and configuration that can * be used in the application. */ settings: NewstackSettings; /** * Environment information */ environment: "client" | "server"; path: string; /** * Registry of named component instances. * Components declare themselves with key="name" and become accessible * to the entire tree via context.instances.name */ instances: NewstackInstances; } export type NewstackClientContext = NewstackCommonContext & { /** * Newstack router information */ router: NewstackRouter; /** * Query parameters from the URL */ params: NewstackParams; worker?: NewstackWorker; /** * The DOM event that triggered the current handler call, if any. */ event?: Event; /** * Bind object */ bind?: { property: string | number; object: any; }[]; /** * Bind value */ value?: any; /** * Ref object */ ref?: T extends { ref: any; } ? T["ref"] : { object: any; property: string | number; }; /** * Ref reference */ element?: Element; } & T; export type NewstackServerContext = NewstackCommonContext & { /** * Map of secrets that are not exposed to the client. */ secrets: NewstackSecrets; /** * Map of dependencies that can be used in the application. */ deps: NewstackDependencies; } & T; declare abstract class NewstackComponent { prepared: boolean; hydrated: boolean; abstract hydrate(context?: NewstackClientContext): void; abstract prepare(context?: NewstackClientContext): void; abstract update(context?: NewstackClientContext): void; abstract destroy(context?: NewstackClientContext): void; abstract render(context?: NewstackClientContext): any; } export type VoidOrPromise = void | Promise; declare abstract class Newstack extends NewstackComponent { /** * @description * Component identifier automatically set in the build time. */ static hash: string; constructor(); /** Automatically set to true after prepare() completes. */ prepared: boolean; /** Automatically set to true after hydrate() completes. */ hydrated: boolean; /** Method automatically ran in the server when this is being served for the first time and automatically ran in the client before the HTML is rendered in the DOM */ prepare?(context?: NewstackClientContext | NewstackServerContext): VoidOrPromise; /** Method automatically ran in the client right after the HTML is rendered in the DOM. */ hydrate?(context?: NewstackClientContext): VoidOrPromise; /** Method automatically ran in the client when the component or children reactivity are updated. */ update?(context?: NewstackClientContext): VoidOrPromise; /** Method automatically ran in the client when the component is no longer in the DOM. */ destroy?(context?: NewstackClientContext): VoidOrPromise; /** * @deprecated Use `destroy` instead. * Alias for `destroy` — kept for Nullstack compatibility. */ terminate?(context?: NewstackClientContext): VoidOrPromise; /** Method automatically ran in the client for reactivity and ran once in the server for first-page-view SSR. */ render?(context?: NewstackClientContext): any; } export type BuildOpts = { outDir?: string; deps?: Record; dynamicRoutes?: string[]; getStaticPaths?: () => Promise | string[]; hydrate?: boolean; }; /** * @description * NewstackServer is a class that serves a Newstack application using Hono. * It sets up routes for handling API requests and serving the initial HTML page. * The server handles server-side rendering of Newstack components and provides * a way to execute server functions defined in the components. */ export declare class NewstackServer { /** * @description * The Hono application instance that serves the Newstack server. */ server: Hono; /** * @description * The Newstack application instance that is being served. */ app: Newstack; /** * @description * The renderer instance that handles rendering Newstack components to HTML. */ private renderer; private hmrManager; private buildManager; constructor(); /** * @description * Prepares the components for rendering in the server-side. */ private prepare; /** * @description * Executes a server function based on the provided hash and method name. * It finds the component by its hash and calls the method by its name with * the provided arguments. * * @param {string} hash - The hash of the component (Generated in the build process). * @param {string} method - The name of the method to execute (Component class method name). * @param {unknown} args - The arguments to pass to the method (Arguments passed in the server function). * * @returns {Promise} - The result of the method execution and any error that occurred. */ private executeServerFunction; /** * @description * Handles the request for static files. * It reads the file from the public directory and returns its content. * If the file is not found, it returns an empty string. * * @param {string} name - The name of the file to handle (e.g., "favicon.ico", "style.css"). * @returns {Promise} - The content of the file as a Buffer or null if not found. */ private handleFile; /** * @description * Sets up the routes that render the pages on the first visit. * This is where the initial HTML is served to the client. * The client will then take over and handle the routing. */ private setupRoutes; /** * @description * Serves the application by handling all incoming requests. * It serves static files and renders the initial HTML page for the application. */ private serveAppRoutes; /** * @description * Generates the HTML template for the initial page. * It renders the application and prepares the components for server-side rendering. * * @returns {Promise} - The HTML template as a string. */ private template; /** * @description * Generates a static HTML template for SSG build mode. * Unlike the regular template, this does not include client.js or state hydration, * as the pages are fully static. Server functions are executed during build time. * * @returns {Promise} - The HTML template as a string. */ private templateStatic; /** * @description * Starts the Newstack server and listens for incoming requests. * * @returns {Hono} */ start(app: Newstack, opts?: { deps: Record; }): Hono; build(app: Newstack, opts?: BuildOpts): Promise; private setupSpaRoutes; } export {};