/// declare module 'svelte' { /** * @deprecated In Svelte 4, components are classes. In Svelte 5, they are functions. * Use `mount` instead to instantiate components. * See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) * for more info. */ export interface ComponentConstructorOptions< Props extends Record = Record > { target: Element | Document | ShadowRoot; anchor?: Element; props?: Props; context?: Map; hydrate?: boolean; intro?: boolean; recover?: boolean; sync?: boolean; idPrefix?: string; $$inline?: boolean; transformError?: (error: unknown) => unknown; } /** * Utility type for ensuring backwards compatibility on a type level that if there's a default slot, add 'children' to the props */ type Properties = Props & (Slots extends { default: any } ? // This is unfortunate because it means "accepts no props" turns into "accepts any prop" // but the alternative is non-fixable type errors because of the way TypeScript index // signatures work (they will always take precedence and make an impossible-to-satisfy children type). Props extends Record ? any : { children?: any } : {}); /** * This was the base class for Svelte components in Svelte 4. Svelte 5+ components * are completely different under the hood. For typing, use `Component` instead. * To instantiate components, use `mount` instead. * See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) for more info. */ export class SvelteComponent< Props extends Record = Record, Events extends Record = any, Slots extends Record = any > { /** The custom element version of the component. Only present if compiled with the `customElement` compiler option */ static element?: typeof HTMLElement; [prop: string]: any; /** * @deprecated This constructor only exists when using the `asClassComponent` compatibility helper, which * is a stop-gap solution. Migrate towards using `mount` instead. See * [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) for more info. */ constructor(options: ComponentConstructorOptions>); /** * For type checking capabilities only. * Does not exist at runtime. * ### DO NOT USE! */ $$prop_def: Props; // Without Properties: unnecessary, causes type bugs /** * For type checking capabilities only. * Does not exist at runtime. * ### DO NOT USE! */ $$events_def: Events; /** * For type checking capabilities only. * Does not exist at runtime. * ### DO NOT USE! */ $$slot_def: Slots; /** * For type checking capabilities only. * Does not exist at runtime. * ### DO NOT USE! */ $$bindings?: string; /** * @deprecated This method only exists when using one of the legacy compatibility helpers, which * is a stop-gap solution. See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) * for more info. */ $destroy(): void; /** * @deprecated This method only exists when using one of the legacy compatibility helpers, which * is a stop-gap solution. See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) * for more info. */ $on>( type: K, callback: (e: Events[K]) => void ): () => void; /** * @deprecated This method only exists when using one of the legacy compatibility helpers, which * is a stop-gap solution. See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) * for more info. */ $set(props: Partial): void; } const brand: unique symbol; type Brand = { [brand]: B }; type Branded = T & Brand; /** * Internal implementation details that vary between environments */ export type ComponentInternals = Branded<{}, 'ComponentInternals'>; /** * Can be used to create strongly typed Svelte components. * * #### Example: * * You have component library on npm called `component-library`, from which * you export a component called `MyComponent`. For Svelte+TypeScript users, * you want to provide typings. Therefore you create a `index.d.ts`: * ```ts * import type { Component } from 'svelte'; * export declare const MyComponent: Component<{ foo: string }> {} * ``` * Typing this makes it possible for IDEs like VS Code with the Svelte extension * to provide intellisense and to use the component like this in a Svelte file * with TypeScript: * ```svelte * * * ``` */ export interface Component< Props extends Record = {}, Exports extends Record = {}, Bindings extends keyof Props | '' = string > { /** * @param internal An internal object used by Svelte. Do not use or modify. * @param props The props passed to the component. */ ( this: void, internals: ComponentInternals, props: Props ): { /** * @deprecated This method only exists when using one of the legacy compatibility helpers, which * is a stop-gap solution. See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) * for more info. */ $on?(type: string, callback: (e: any) => void): () => void; /** * @deprecated This method only exists when using one of the legacy compatibility helpers, which * is a stop-gap solution. See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) * for more info. */ $set?(props: Partial): void; } & Exports; /** The custom element version of the component. Only present if compiled with the `customElement` compiler option */ element?: typeof HTMLElement; /** Does not exist at runtime, for typing capabilities only. DO NOT USE */ z_$$bindings?: Bindings; } /** * @deprecated Use `Component` instead. See [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes) for more information. */ export class SvelteComponentTyped< Props extends Record = Record, Events extends Record = any, Slots extends Record = any > extends SvelteComponent {} /** * @deprecated The new `Component` type does not have a dedicated Events type. Use `ComponentProps` instead. * * @description * Convenience type to get the events the given component expects. Example: * ```html * * * * ``` */ export type ComponentEvents = Comp extends SvelteComponent ? Events : never; /** * Convenience type to get the props the given component expects. * * Example: Ensure a variable contains the props expected by `MyComponent`: * * ```ts * import type { ComponentProps } from 'svelte'; * import MyComponent from './MyComponent.svelte'; * * // Errors if these aren't the correct props expected by MyComponent. * const props: ComponentProps = { foo: 'bar' }; * ``` * * > [!NOTE] In Svelte 4, you would do `ComponentProps` because `MyComponent` was a class. * * Example: A generic function that accepts some component and infers the type of its props: * * ```ts * import type { Component, ComponentProps } from 'svelte'; * import MyComponent from './MyComponent.svelte'; * * function withProps>( * component: TComponent, * props: ComponentProps * ) {}; * * // Errors if the second argument is not the correct props expected by the component in the first argument. * withProps(MyComponent, { foo: 'bar' }); * ``` */ export type ComponentProps> = Comp extends SvelteComponent ? Props : Comp extends Component ? Props : never; /** * @deprecated This type is obsolete when working with the new `Component` type. * * @description * Convenience type to get the type of a Svelte component. Useful for example in combination with * dynamic components using ``. * * Example: * ```html * * * * * ``` */ export type ComponentType = (new ( options: ComponentConstructorOptions< Comp extends SvelteComponent ? Props : Record > ) => Comp) & { /** The custom element version of the component. Only present if compiled with the `customElement` compiler option */ element?: typeof HTMLElement; }; const SnippetReturn: unique symbol; // Use an interface instead of a type, makes for better intellisense info because the type is named in more situations. /** * The type of a `#snippet` block. You can use it to (for example) express that your component expects a snippet of a certain type: * ```ts * let { banner }: { banner: Snippet<[{ text: string }]> } = $props(); * ``` * You can only call a snippet through the `{@render ...}` tag. * * See the [snippet documentation](https://svelte.dev/docs/svelte/snippet) for more info. * * @template Parameters the parameters that the snippet expects (if any) as a tuple. */ export interface Snippet { ( this: void, // this conditional allows tuples but not arrays. Arrays would indicate a // rest parameter type, which is not supported. If rest parameters are added // in the future, the condition can be removed. ...args: number extends Parameters['length'] ? never : Parameters ): { '{@render ...} must be called with a Snippet': "import type { Snippet } from 'svelte'"; } & typeof SnippetReturn; } interface DispatchOptions { cancelable?: boolean; } export interface EventDispatcher> { // Implementation notes: // - undefined extends X instead of X extends undefined makes this work better with both strict and nonstrict mode // - | null | undefined is added for convenience, as they are equivalent for the custom event constructor (both result in a null detail) ( ...args: null extends EventMap[Type] ? [type: Type, parameter?: EventMap[Type] | null | undefined, options?: DispatchOptions] : undefined extends EventMap[Type] ? [type: Type, parameter?: EventMap[Type] | null | undefined, options?: DispatchOptions] : [type: Type, parameter: EventMap[Type], options?: DispatchOptions] ): boolean; } /** * Defines the options accepted by the `mount()` function. */ export type MountOptions = Record> = { /** * Target element where the component will be mounted. */ target: Document | Element | ShadowRoot; /** * Optional node inside `target`. When specified, it is used to render the component immediately before it. */ anchor?: Node; /** * Allows the specification of events. * @deprecated Use callback props instead. */ events?: Record any>; /** * Can be accessed via `getContext()` at the component level. */ context?: Map; /** * Whether or not to play transitions on initial render. * @default true */ intro?: boolean; /** * A function that transforms errors caught by error boundaries before they are passed to the `failed` snippet. * Defaults to the identity function. */ transformError?: (error: unknown) => unknown | Promise; } & ({} extends Props ? { /** * Component properties. */ props?: Props; } : { /** * Component properties. */ props: Props; }); /** * Represents work that is happening off-screen, such as data being preloaded * in anticipation of the user navigating * @since 5.42 */ export interface Fork { /** * Commit the fork. The promise will resolve once the state change has been applied */ commit(): Promise; /** * Discard the fork */ discard(): void; } /** * Returns an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that aborts when the current [derived](https://svelte.dev/docs/svelte/$derived) or [effect](https://svelte.dev/docs/svelte/$effect) re-runs or is destroyed. * * Must be called while a derived or effect is running. * * ```svelte * * ``` */ export function getAbortSignal(): AbortSignal; /** * `onMount`, like [`$effect`](https://svelte.dev/docs/svelte/$effect), schedules a function to run as soon as the component has been mounted to the DOM. * Unlike `$effect`, the provided function only runs once. * * It must be called during the component's initialisation (but doesn't need to live _inside_ the component; * it can be called from an external module). If a function is returned _synchronously_ from `onMount`, * it will be called when the component is unmounted. * * `onMount` functions do not run during [server-side rendering](https://svelte.dev/docs/svelte/svelte-server#render). * * */ export function onMount(fn: () => NotFunction | Promise> | (() => any)): void; /** * Schedules a callback to run immediately before the component is unmounted. * * Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the * only one that runs inside a server-side component. * * */ export function onDestroy(fn: () => any): void; /** * Creates an event dispatcher that can be used to dispatch [component events](https://svelte.dev/docs/svelte/legacy-on#Component-events). * Event dispatchers are functions that can take two arguments: `name` and `detail`. * * Component events created with `createEventDispatcher` create a * [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent). * These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture). * The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail) * property and can contain any type of data. * * The event dispatcher can be typed to narrow the allowed event names and the type of the `detail` argument: * ```ts * const dispatch = createEventDispatcher<{ * loaded: null; // does not take a detail argument * change: string; // takes a detail argument of type string, which is required * optional: number | null; // takes an optional detail argument of type number * }>(); * ``` * * @deprecated Use callback props and/or the `$host()` rune instead — see [migration guide](https://svelte.dev/docs/svelte/v5-migration-guide#Event-changes-Component-events) * */ export function createEventDispatcher = any>(): EventDispatcher; /** * Schedules a callback to run immediately before the component is updated after any state change. * * The first time the callback runs will be before the initial `onMount`. * * In runes mode use `$effect.pre` instead. * * @deprecated Use [`$effect.pre`](https://svelte.dev/docs/svelte/$effect#$effect.pre) instead * */ export function beforeUpdate(fn: () => void): void; /** * Schedules a callback to run immediately after the component has been updated. * * The first time the callback runs will be after the initial `onMount`. * * In runes mode use `$effect` instead. * * @deprecated Use [`$effect`](https://svelte.dev/docs/svelte/$effect) instead * */ export function afterUpdate(fn: () => void): void; export function hydratable(key: string, fn: () => T): T; /** * Create a snippet programmatically * */ export function createRawSnippet(fn: (...params: Getters) => { render: () => string; setup?: (element: Element) => void | (() => void); }): Snippet; /** Anything except a function */ type NotFunction = T extends Function ? never : T; /** * Synchronously flush any pending updates. * Returns void if no callback is provided, otherwise returns the result of calling the callback. * */ export function flushSync(fn?: (() => T) | undefined): T; /** * Creates a 'fork', in which state changes are evaluated but not applied to the DOM. * This is useful for speculatively loading data (for example) when you suspect that * the user is about to take some action. * * Frameworks like SvelteKit can use this to preload data when the user touches or * hovers over a link, making any subsequent navigation feel instantaneous. * * The `fn` parameter is a synchronous function that modifies some state. The * state changes will be reverted after the fork is initialised, then reapplied * if and when the fork is eventually committed. * * When it becomes clear that a fork will _not_ be committed (e.g. because the * user navigated elsewhere), it must be discarded to avoid leaking memory. * * @since 5.42 */ export function fork(fn: () => void): Fork; /** * Returns a `[get, set]` pair of functions for working with context in a type-safe way. * * `get` will throw an error if no parent component called `set`. * * @since 5.40.0 */ export function createContext(): [() => T, (context: T) => T]; /** * Retrieves the context that belongs to the closest parent component with the specified `key`. * Must be called during component initialisation. * * [`createContext`](https://svelte.dev/docs/svelte/svelte#createContext) is a type-safe alternative. * * */ export function getContext(key: any): T; /** * Associates an arbitrary `context` object with the current component and the specified `key` * and returns that object. The context is then available to children of the component * (including slotted content) with `getContext`. * * Like lifecycle functions, this must be called during component initialisation. * * [`createContext`](https://svelte.dev/docs/svelte/svelte#createContext) is a type-safe alternative. * * */ export function setContext(key: any, context: T): T; /** * Checks whether a given `key` has been set in the context of a parent component. * Must be called during component initialisation. * * */ export function hasContext(key: any): boolean; /** * Retrieves the whole context map that belongs to the closest parent component. * Must be called during component initialisation. Useful, for example, if you * programmatically create a component and want to pass the existing context to it. * * */ export function getAllContexts = Map>(): T; /** * Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component. * Transitions will play during the initial render unless the `intro` option is set to `false`. * * */ export function mount, Exports extends Record>(component: ComponentType> | Component, options: MountOptions): Exports; /** * Hydrates a component on the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component * * */ export function hydrate, Exports extends Record>(component: ComponentType> | Component, options: {} extends Props ? { target: Document | Element | ShadowRoot; props?: Props; events?: Record any>; context?: Map; intro?: boolean; recover?: boolean; transformError?: (error: unknown) => unknown; } : { target: Document | Element | ShadowRoot; props: Props; events?: Record any>; context?: Map; intro?: boolean; recover?: boolean; transformError?: (error: unknown) => unknown; }): Exports; /** * Unmounts a component that was previously mounted using `mount` or `hydrate`. * * Since 5.13.0, if `options.outro` is `true`, [transitions](https://svelte.dev/docs/svelte/transition) will play before the component is removed from the DOM. * * Returns a `Promise` that resolves after transitions have completed if `options.outro` is true, or immediately otherwise (prior to 5.13.0, returns `void`). * * ```js * import { mount, unmount } from 'svelte'; * import App from './App.svelte'; * * const app = mount(App, { target: document.body }); * * // later... * unmount(app, { outro: true }); * ``` * */ export function unmount(component: Record, options?: { outro?: boolean; } | undefined): Promise; /** * Returns a promise that resolves once any pending state changes have been applied. * */ export function tick(): Promise; /** * Returns a promise that resolves once any state changes, and asynchronous work resulting from them, * have resolved and the DOM has been updated * @since 5.36 */ export function settled(): Promise; /** * When used inside a [`$derived`](https://svelte.dev/docs/svelte/$derived) or [`$effect`](https://svelte.dev/docs/svelte/$effect), * any state read inside `fn` will not be treated as a dependency. * * ```ts * $effect(() => { * // this will run when `data` changes, but not when `time` changes * save(data, { * timestamp: untrack(() => time) * }); * }); * ``` * */ export function untrack(fn: () => T): T; type Getters = { [K in keyof T]: () => T[K]; }; export {}; } declare module 'svelte/action' { /** * Actions can return an object containing the two properties defined in this interface. Both are optional. * - update: An action can have a parameter. This method will be called whenever that parameter changes, * immediately after Svelte has applied updates to the markup. `ActionReturn` and `ActionReturn` both * mean that the action accepts no parameters. * - destroy: Method that is called after the element is unmounted * * Additionally, you can specify which additional attributes and events the action enables on the applied element. * This applies to TypeScript typings only and has no effect at runtime. * * Example usage: * ```ts * interface Attributes { * newprop?: string; * 'on:event': (e: CustomEvent) => void; * } * * export function myAction(node: HTMLElement, parameter: Parameter): ActionReturn { * // ... * return { * update: (updatedParameter) => {...}, * destroy: () => {...} * }; * } * ``` */ export interface ActionReturn< Parameter = undefined, Attributes extends Record = Record > { update?: (parameter: Parameter) => void; destroy?: () => void; /** * ### DO NOT USE THIS * This exists solely for type-checking and has no effect at runtime. * Set this through the `Attributes` generic instead. */ $$_attributes?: Attributes; } /** * Actions are functions that are called when an element is created. * You can use this interface to type such actions. * The following example defines an action that only works on `
` elements * and optionally accepts a parameter which it has a default value for: * ```ts * export const myAction: Action = (node, param = { someProperty: true }) => { * // ... * } * ``` * `Action` and `Action` both signal that the action accepts no parameters. * * You can return an object with methods `update` and `destroy` from the function and type which additional attributes and events it has. * See interface `ActionReturn` for more details. */ export interface Action< Element = HTMLElement, Parameter = undefined, Attributes extends Record = Record > { ( ...args: undefined extends Parameter ? [node: Node, parameter?: Parameter] : [node: Node, parameter: Parameter] ): void | ActionReturn; } // Implementation notes: // - undefined extends X instead of X extends undefined makes this work better with both strict and nonstrict mode export {}; } declare module 'svelte/animate' { // todo: same as Transition, should it be shared? export interface AnimationConfig { delay?: number; duration?: number; easing?: (t: number) => number; css?: (t: number, u: number) => string; tick?: (t: number, u: number) => void; } export interface FlipParams { delay?: number; duration?: number | ((len: number) => number); easing?: (t: number) => number; } /** * The flip function calculates the start and end position of an element and animates between them, translating the x and y values. * `flip` stands for [First, Last, Invert, Play](https://aerotwist.com/blog/flip-your-animations/). * * */ export function flip(node: Element, { from, to }: { from: DOMRect; to: DOMRect; }, params?: FlipParams): AnimationConfig; export {}; } declare module 'svelte/attachments' { /** * An [attachment](https://svelte.dev/docs/svelte/@attach) is a function that runs when an element is mounted * to the DOM, and optionally returns a function that is called when the element is later removed. * * It can be attached to an element with an `{@attach ...}` tag, or by spreading an object containing * a property created with [`createAttachmentKey`](https://svelte.dev/docs/svelte/svelte-attachments#createAttachmentKey). */ export interface Attachment { (element: T): void | (() => void); } /** * Creates an object key that will be recognised as an attachment when the object is spread onto an element, * as a programmatic alternative to using `{@attach ...}`. This can be useful for library authors, though * is generally not needed when building an app. * * ```svelte * * * * ``` * @since 5.29 */ export function createAttachmentKey(): symbol; /** * Converts an [action](https://svelte.dev/docs/svelte/use) into an [attachment](https://svelte.dev/docs/svelte/@attach) keeping the same behavior. * It's useful if you want to start using attachments on components but you have actions provided by a library. * * Note that the second argument, if provided, must be a function that _returns_ the argument to the * action function, not the argument itself. * * ```svelte * *
...
* * *
bar)}>...
* ``` * */ export function fromAction(action: Action | ((element: E, arg: T) => void | ActionReturn), fn: () => T): Attachment; /** * Converts an [action](https://svelte.dev/docs/svelte/use) into an [attachment](https://svelte.dev/docs/svelte/@attach) keeping the same behavior. * It's useful if you want to start using attachments on components but you have actions provided by a library. * * Note that the second argument, if provided, must be a function that _returns_ the argument to the * action function, not the argument itself. * * ```svelte * *
...
* * *
bar)}>...
* ``` * */ export function fromAction(action: Action | ((element: E) => void | ActionReturn)): Attachment; /** * Actions can return an object containing the two properties defined in this interface. Both are optional. * - update: An action can have a parameter. This method will be called whenever that parameter changes, * immediately after Svelte has applied updates to the markup. `ActionReturn` and `ActionReturn` both * mean that the action accepts no parameters. * - destroy: Method that is called after the element is unmounted * * Additionally, you can specify which additional attributes and events the action enables on the applied element. * This applies to TypeScript typings only and has no effect at runtime. * * Example usage: * ```ts * interface Attributes { * newprop?: string; * 'on:event': (e: CustomEvent) => void; * } * * export function myAction(node: HTMLElement, parameter: Parameter): ActionReturn { * // ... * return { * update: (updatedParameter) => {...}, * destroy: () => {...} * }; * } * ``` */ interface ActionReturn< Parameter = undefined, Attributes extends Record = Record > { update?: (parameter: Parameter) => void; destroy?: () => void; /** * ### DO NOT USE THIS * This exists solely for type-checking and has no effect at runtime. * Set this through the `Attributes` generic instead. */ $$_attributes?: Attributes; } /** * Actions are functions that are called when an element is created. * You can use this interface to type such actions. * The following example defines an action that only works on `
` elements * and optionally accepts a parameter which it has a default value for: * ```ts * export const myAction: Action = (node, param = { someProperty: true }) => { * // ... * } * ``` * `Action` and `Action` both signal that the action accepts no parameters. * * You can return an object with methods `update` and `destroy` from the function and type which additional attributes and events it has. * See interface `ActionReturn` for more details. */ interface Action< Element = HTMLElement, Parameter = undefined, Attributes extends Record = Record > { ( ...args: undefined extends Parameter ? [node: Node, parameter?: Parameter] : [node: Node, parameter: Parameter] ): void | ActionReturn; } // Implementation notes: // - undefined extends X instead of X extends undefined makes this work better with both strict and nonstrict mode export {}; } declare module 'svelte/compiler' { import type { SourceMap } from 'magic-string'; import type { ArrayExpression, ArrowFunctionExpression, VariableDeclaration, VariableDeclarator, Expression, Identifier, MemberExpression, Node, ObjectExpression, Pattern, Program, ChainExpression, SimpleCallExpression, SequenceExpression, SourceLocation } from 'estree'; import type { Location } from 'locate-character'; import type { default as ts } from 'esrap/languages/ts'; /** * `compile` converts your `.svelte` source code into a JavaScript module that exports a component * * @param source The component source code * @param options The compiler options * */ export function compile(source: string, options: CompileOptions): CompileResult; /** * `compileModule` takes your JavaScript source code containing runes, and turns it into a JavaScript module. * * @param source The component source code * */ export function compileModule(source: string, options: ModuleCompileOptions): CompileResult; /** * The parse function parses a component, returning only its abstract syntax tree. * * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * */ export function parse(source: string, options: { filename?: string; modern: true; loose?: boolean; }): AST.Root; /** * The parse function parses a component, returning only its abstract syntax tree. * * The `modern` option (`false` by default in Svelte 5) makes the parser return a modern AST instead of the legacy AST. * `modern` will become `true` by default in Svelte 6, and the option will be removed in Svelte 7. * * */ export function parse(source: string, options?: { filename?: string; modern?: false; loose?: boolean; } | undefined): Record; /** * The parseCss function parses a CSS stylesheet, returning its abstract syntax tree. * * @param source The CSS source code * */ export function parseCss(source: string): AST.CSS.StyleSheetFile; /** * @deprecated Replace this with `import { walk } from 'estree-walker'` * */ export function walk(): never; /** * The result of a preprocessor run. If the preprocessor does not return a result, it is assumed that the code is unchanged. */ export interface Processed { /** * The new code */ code: string; /** * A source map mapping back to the original code */ map?: string | object; // we are opaque with the type here to avoid dependency on the remapping module for our public types. /** * A list of additional files to watch for changes */ dependencies?: string[]; /** * Only for script/style preprocessors: The updated attributes to set on the tag. If undefined, attributes stay unchanged. */ attributes?: Record; toString?: () => string; } /** * A markup preprocessor that takes a string of code and returns a processed version. */ export type MarkupPreprocessor = (options: { /** * The whole Svelte file content */ content: string; /** * The filename of the Svelte file */ filename?: string; }) => Processed | void | Promise; /** * A script/style preprocessor that takes a string of code and returns a processed version. */ export type Preprocessor = (options: { /** * The script/style tag content */ content: string; /** * The attributes on the script/style tag */ attributes: Record; /** * The whole Svelte file content */ markup: string; /** * The filename of the Svelte file */ filename?: string; }) => Processed | void | Promise; /** * A preprocessor group is a set of preprocessors that are applied to a Svelte file. */ export interface PreprocessorGroup { /** Name of the preprocessor. Will be a required option in the next major version */ name?: string; markup?: MarkupPreprocessor; style?: Preprocessor; script?: Preprocessor; } /** The return value of `compile` from `svelte/compiler` */ export interface CompileResult { /** The compiled JavaScript */ js: { /** The generated code */ code: string; /** A source map */ map: SourceMap; }; /** The compiled CSS */ css: null | { /** The generated code */ code: string; /** A source map */ map: SourceMap; /** Whether or not the CSS includes global rules */ hasGlobal: boolean; }; /** * An array of warning objects that were generated during compilation. Each warning has several properties: * - `code` is a string identifying the category of warning * - `message` describes the issue in human-readable terms * - `start` and `end`, if the warning relates to a specific location, are objects with `line`, `column` and `character` properties */ warnings: Warning[]; /** * Metadata about the compiled component */ metadata: { /** * Whether the file was compiled in runes mode, either because of an explicit option or inferred from usage. * For `compileModule`, this is always `true` */ runes: boolean; }; /** The AST */ ast: any; } export interface Warning extends ICompileDiagnostic {} export interface CompileError extends ICompileDiagnostic {} type CssHashGetter = (args: { name: string; filename: string; css: string; hash: (input: string) => string; }) => string; export interface CompileOptions extends ModuleCompileOptions { /** * Sets the name of the resulting JavaScript class (though the compiler will rename it if it would otherwise conflict with other variables in scope). * If unspecified, will be inferred from `filename` */ name?: string; /** * If `true`, tells the compiler to generate a custom element constructor instead of a regular Svelte component. * * You can also pass a function that receives `{ filename }` and returns a boolean. * * @default false */ customElement?: boolean | ((options: { filename: string }) => boolean); /** * If `true`, getters and setters will be created for the component's props. If `false`, they will only be created for readonly exported values (i.e. those declared with `const`, `class` and `function`). If compiling with `customElement: true` this option defaults to `true`. * * @default false * @deprecated This will have no effect in runes mode */ accessors?: boolean; /** * The namespace of the element; e.g., `"html"`, `"svg"`, `"mathml"`. * * @default 'html' */ namespace?: Namespace; /** * If `true`, tells the compiler that you promise not to mutate any objects. * This allows it to be less conservative about checking whether values have changed. * * @default false * @deprecated This will have no effect in runes mode */ immutable?: boolean; /** * - `'injected'`: styles will be included in the `head` when using `render(...)`, and injected into the document (if not already present) when the component mounts. For components compiled as custom elements, styles are injected to the shadow root. * - `'external'`: the CSS will only be returned in the `css` field of the compilation result. Most Svelte bundler plugins will set this to `'external'` and use the CSS that is statically generated for better performance, as it will result in smaller JavaScript bundles and the output can be served as cacheable `.css` files. * This is always `'injected'` when compiling with `customElement` mode. * * You can also pass a function that receives `{ filename }` and returns either `'injected'` or `'external'`. */ css?: 'injected' | 'external' | ((options: { filename: string }) => 'injected' | 'external'); /** * A function that takes a `{ hash, css, name, filename }` argument and returns the string that is used as a classname for scoped CSS. * It defaults to returning `svelte-${hash(filename ?? css)}`. * * @default undefined */ cssHash?: CssHashGetter; /** * If `true`, your HTML comments will be preserved in the output. By default, they are stripped out. * * @default false */ preserveComments?: boolean; /** * If `true`, whitespace inside and between elements is kept as you typed it, rather than removed or collapsed to a single space where possible. * * @default false */ preserveWhitespace?: boolean; /** * Which strategy to use when cloning DOM fragments: * * - `html` populates a `