// Generated by dts-bundle-generator v9.5.1 export type IconSize = 72 | 96 | 128 | 144 | 152 | 192 | 384 | 512; export type NewstackNode = string | number | boolean | null | undefined | NewstackNode[]; 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; /** * @description * Newstack Component base class that provides all the necessary methods and properties * for creating a Newstack component. */ 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; } declare class HeadManager { private injections; private cache; currentHash: string | null; collect(html: string): void; reset(): void; clearFor(hash: string): void; /** Returns tagged HTML for the server template. */ serverHtml(): string; /** Flushes injections into document.head. Scoped = one component; unscoped = full route flush. */ flush(scope?: string): void; } export type VNode = { type: string | ((...args: unknown[]) => unknown); props?: Record & { route?: string; children?: VNode | VNode[]; }; }; declare class Renderer { /** * @description * The context object that holds the current state of the application, * such as the current path and other relevant data. * This context is used to determine how components should be rendered * based on the current application state. */ context: NewstackClientContext; /** * @description * A set of all Newstack components that have been defined in the application. * This includes components that have not yet been rendered. */ components: Map Newstack; }>; /** * @description * A set of hashes representing the components that are currently visible in the application. * This is used to track which components should be rendered based on the current route. */ visibleHashes: Set; persistentHashes: Set; instanceHashes: Set; /** * @description * A map that associates Newstack components with their corresponding HTML elements. * This is used to update the DOM when component properties change. */ componentElements: Map; lastVNode: any; private isUpdating; /** * Stack of "did any non-`*` sibling route match the current path?" booleans, * pushed by renderChildren() before walking each array of children and popped * after. Used by the `route="*"` fallback check inside html(). */ private fallbackStack; /** * Accumulated children collected during the current html() pass. * Each entry is tagged with the hash of the component that produced it so * scoped cleanup works when a single component re-renders. */ readonly head: HeadManager; constructor(context?: NewstackClientContext); get hashes(): string[]; /** * @description * Performs a hot module replacement update by swapping the prototype of each * live component instance to the corresponding class from the newly imported * bundle, then re-renders all visible components in place. * * State stored on instances is preserved; only methods/render are updated. * * @param newApp The newly-imported application instance (from re-imported bundle). */ hmrUpdate(newApp: Newstack): void; /** * @description * Finds a Newstack component by its static hash property. * This function iterates through the components map and checks if the * component's constructor has a matching hash. If found, it returns the component. * * @param hash The hash of the component to find. * @returns The Newstack component if found, otherwise null. */ findComponentByHash(hash: string): Newstack; /** * @description * Renders a Newstack component tree to HTML. * This function recursively traverses the component tree, converting each component * and its properties into an HTML string. It handles both standard HTML elements * and Newstack components, allowing for dynamic rendering based on the current context. * * @param node The component or element to render. * @returns A string representing the rendered HTML. */ html(node: VNode): string; /** * Walks an array of sibling vnodes, joining their html. * * Pre-scans for any non-`*` `route` prop that matches the current path so * that `route="*"` siblings know whether to render as the fallback. The * pre-scan is shallow (immediate siblings only) — `*` is scoped to its * JSX-array level, mirroring how routers like react-router treat catch-all * routes inside a `` block. */ private renderChildren; /** * @description * Adds state data from a snapshot to a Newstack component. * This function retrieves the state from the provided states object using the component's hash * and assigns the state properties to the component instance. * * @param component The Newstack component to which the state data should be added. * @param states An object containing state data indexed by component hashes. */ addSnapshotStateData(component: Newstack, states: Record): void; /** * @description * Patches an existing route in the DOM with a new virtual node. * This function updates the HTML of the container element with the new virtual node, * replacing the old content while preserving the structure and attributes of the existing elements. * * @param newVNode The new virtual node to render. * @param container The HTML element where the new virtual node should be rendered. */ patchRoute(newVNode: VNode, container: Element): void; /** * Walks the rendered vnode tree and drops each component's JSX props onto * its live instance. Used before lifecycle loops that run outside of an * html() pass (e.g. prepare() on client soft-navigation) so those methods * still see up-to-date props in their context. Within html() props are * captured inline, so this is only needed for the no-html-walk paths. */ assignProps(vnode: VNode): void; extractParams(vnode: any): void; private scanParams; /** * @description * Updates a Newstack component in the DOM. * This function finds the HTML element associated with the component, * renders the component to a new HTML string, and then patches the existing * element with the new HTML. * * @param component The Newstack component to update. */ updateComponent(component: Newstack): void; mount(ComponentClass: typeof Newstack, container: Element): Newstack; /** * @description * Sets up all components in the application, including the entrypoint component and its children. * This function initializes the components, creates proxies for them to ensure reactivity, * and recursively processes child components to add them to the renderer's component list. * * @param entrypoint The main entrypoint component of the application. * @param context The context object that holds the current state of the application. */ setupAllComponents(entrypoint: Newstack): void; } /** * @description * NewstackClient is a class that initializes and manages the Newstack application on the client side. * It handles rendering the application, managing the client-side state, and routing. */ export declare class NewstackClient { /** * @description * The root HTML element where the Newstack application is rendered. * It should have an id of "app" in the HTML document. */ root: HTMLElement; /** * @description * The Newstack application instance entrypoint that is being served. */ app: Newstack; /** * @description * The context object that holds the current client-side state of the application, * such as the current path and more. */ context: NewstackClientContext; /** * @description * The renderer instance that handles rendering Newstack components to HTML. * It manages the component lifecycle, including hydration and updates. */ renderer: Renderer; private mounted; private workerState; constructor(root?: HTMLElement); static init(root?: HTMLElement): NewstackClient; /** * @description * Starts the Newstack application on the client side. * This method hydrates the application tree into the root element, * sets up client-side routing, and patches links to handle navigation without full page reloads. * * @param app The Newstack application instance to start on the client side. */ start(app: Newstack): Promise; mount(ComponentClass: typeof Newstack, _root?: HTMLElement): { destroy: () => void; }; /** * @description * Renders a specific route in the Newstack application. * This function prepares the application context, renders the HTML for the current route, * and hydrates the components. It also patches links to handle client-side navigation. * * @param href The URL path to render. */ renderRoute(href: string): Promise; /** * @description * Patches links in the application to handle client-side navigation. * This function adds click event listeners to all anchor tags (``) in the document * to prevent the default browser behavior and instead use the Newstack application's routing. * It also listens for the `popstate` event to handle back/forward navigation. */ private patchLinks; /** * @description * Assigns HTML elements to their corresponding Newstack components. * This function finds all components in the renderer, queries the DOM for their associated elements, * and updates the component's element reference. It also calls the component's update method. * */ private assignElements; /** * @description * Destroys all visible components in the renderer and set them as invisible. * This function iterates through the components map and calls the destroy method * on each component that is currently visible. It then marks the component as not visible. * This is used when changing routes. */ private destroyComponents; /** * @description * Starts all visible components in the renderer that are visible. * This function prepares and hydrates all components that are currently visible in the route. * It is called after rendering a new route to ensure that all components are ready for interaction. */ private startComponents; /** * @description * Returns an array of all components that are currently visible in the route. * This function iterates through the renderer's allComponents map and collects * components that are marked as visible. It is used to manage the lifecycle of components * when rendering a new route. * * @returns {Newstack[]} An array of visible Newstack components. */ private routeComponents; private instanceComponents; } /** * @description * Runtime module for handling server function invocations from the client. * This module provides a centralized way to call server-side static methods * from client-side code through HTTP requests. */ export declare const runtime: { /** * @description * Invokes a server-side static method by making a POST request to the server. * The server will execute the actual method and return the result. * * @param methodName The name of the static method to invoke * @param hash The unique hash identifying the component class * @param params The parameters to pass to the server method * @returns A promise that resolves with the method's result * @throws Error if the server returns an error */ invoke(methodName: string, hash: string, params: any): Promise; }; export { Newstack as default, }; export {};