element Class — svelte Architecture
Architecture documentation for the element class in index.d.ts from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 2c262293_d391_5b39_8993_c4c3b48948c4["element"] 6bd9d090_a582_e05c_669e_d53d4e7245f2["index.d.ts"] 2c262293_d391_5b39_8993_c4c3b48948c4 -->|defined in| 6bd9d090_a582_e05c_669e_d53d4e7245f2 ca9340ef_7c81_2058_0ba6_f2657722794e["element()"] 2c262293_d391_5b39_8993_c4c3b48948c4 -->|method| ca9340ef_7c81_2058_0ba6_f2657722794e 7e55ce35_898a_b471_82ed_5524bc8f1b6c["createAttachmentKey()"] 2c262293_d391_5b39_8993_c4c3b48948c4 -->|method| 7e55ce35_898a_b471_82ed_5524bc8f1b6c 2c9176a6_3faf_ff0a_ee36_10d8f27897c2["fromAction()"] 2c262293_d391_5b39_8993_c4c3b48948c4 -->|method| 2c9176a6_3faf_ff0a_ee36_10d8f27897c2 5c104428_a6c7_82ad_1663_b9ca04521cc4["args()"] 2c262293_d391_5b39_8993_c4c3b48948c4 -->|method| 5c104428_a6c7_82ad_1663_b9ca04521cc4
Relationship Graph
Source Code
packages/svelte/types/index.d.ts lines 706–843
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<T extends EventTarget = Element> {
(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
* <script>
* import { createAttachmentKey } from 'svelte/attachments';
*
* const props = {
* class: 'cool',
* onclick: () => alert('clicked'),
* [createAttachmentKey()]: (node) => {
* node.textContent = 'attached!';
* }
* };
* </script>
*
* <button {...props}>click me</button>
* ```
* @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
* <!-- with an action -->
* <div use:foo={bar}>...</div>
*
* <!-- with an attachment -->
* <div {@attach fromAction(foo, () => bar)}>...</div>
* ```
* */
export function fromAction<E extends EventTarget, T extends unknown>(action: Action<E, T> | ((element: E, arg: T) => void | ActionReturn<T>), fn: () => T): Attachment<E>;
/**
* 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
* <!-- with an action -->
* <div use:foo={bar}>...</div>
*
* <!-- with an attachment -->
* <div {@attach fromAction(foo, () => bar)}>...</div>
* ```
* */
export function fromAction<E extends EventTarget>(action: Action<E, void> | ((element: E) => void | ActionReturn<void>)): Attachment<E>;
/**
* 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<undefined>` 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<boolean>) => void;
Defined In
Source
Frequently Asked Questions
What is the element class?
element is a class in the svelte codebase, defined in packages/svelte/types/index.d.ts.
Where is element defined?
element is defined in packages/svelte/types/index.d.ts at line 706.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free