// Type definitions for Coherent.js SvelteKit integration. // // Aligned with the runtime exports of ../../src/sveltekit/index.js. import type { Handle } from '@sveltejs/kit'; import type { CoherentNode } from '@coherent.js/core'; /** A Coherent.js component: a node, or a function of props returning one. */ export type CoherentSvelteKitComponent = CoherentNode | ((props: Props) => CoherentNode); export interface CoherentSvelteKitLoadEvent { params: Record; url: URL; fetch: typeof fetch; } export interface CoherentSvelteKitAdapter { name: string; /** Render a component (or component function) to an HTML string. */ renderComponent(component: CoherentSvelteKitComponent, props?: Props): string; /** * Create a server `load` function returning the rendered HTML and the props. * Without `getProps` the component receives `{ params }`. */ createLoad( component: CoherentSvelteKitComponent, getProps?: (event: CoherentSvelteKitLoadEvent) => Props | Promise ): (event: CoherentSvelteKitLoadEvent) => Promise<{ html: string; props: Props }>; /** Create a form action that passes the submitted fields to `handler`. */ createAction( handler: (args: { data: Record; params: Record }) => Result ): (event: { request: Request; params: Record }) => Promise>; } export function createSvelteKitAdapter(options?: Record): CoherentSvelteKitAdapter; export interface CoherentPreprocessorOptions { /** * Tag whose content (a JS expression, usually an object literal) is * rendered with Coherent.js * @default 'coherent' */ tag?: string; } /** * Svelte markup preprocessor: replaces `{...}` blocks * with `{@html ...}` of the rendered component and imports the renderer from * `@coherent.js/core` into the component. */ export function createPreprocessor(options?: CoherentPreprocessorOptions): { name: string; markup(input: { content: string; filename?: string }): { code: string; map: null }; }; /** What {@link createHandle} puts on `event.locals.coherent`. */ export interface CoherentLocals { render(component: CoherentSvelteKitComponent, props?: Props): string; } /** * SvelteKit `handle` hook that sets `event.locals.coherent` (see * {@link CoherentLocals}; add it to `App.Locals` in your `app.d.ts`). */ export function createHandle(options?: Record): Handle;