mirror of https://github.com/sveltejs/svelte
parent
68adbc18ae
commit
3d4e58e1f0
@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* 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<never>` both
|
||||||
|
* mean that the action accepts no parameters, which makes it illegal to set the `update` method.
|
||||||
|
* - 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;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* export function myAction(node: HTMLElement, parameter: Parameter): ActionReturn<Parameter, Attributes> {
|
||||||
|
* // ...
|
||||||
|
* return {
|
||||||
|
* update: (updatedParameter) => {...},
|
||||||
|
* destroy: () => {...}
|
||||||
|
* };
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Docs: https://svelte.dev/docs#template-syntax-element-directives-use-action
|
||||||
|
*/
|
||||||
|
export interface ActionReturn<
|
||||||
|
Parameter = never,
|
||||||
|
Attributes extends Record<string, any> = Record<never, any>
|
||||||
|
> {
|
||||||
|
update?: [Parameter] extends [never] ? never : (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 `<div>` elements
|
||||||
|
* and optionally accepts a parameter which it has a default value for:
|
||||||
|
* ```ts
|
||||||
|
* export const myAction: Action<HTMLDivElement, { someProperty: boolean } | undefined> = (node, param = { someProperty: true }) => {
|
||||||
|
* // ...
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
* `Action<HTMLDivElement>` and `Action<HTMLDiveElement, never>` 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.
|
||||||
|
*
|
||||||
|
* Docs: https://svelte.dev/docs#template-syntax-element-directives-use-action
|
||||||
|
*/
|
||||||
|
export interface Action<
|
||||||
|
Element = HTMLElement,
|
||||||
|
Parameter = never,
|
||||||
|
Attributes extends Record<string, any> = Record<never, any>
|
||||||
|
> {
|
||||||
|
<Node extends Element>(
|
||||||
|
...args: [Parameter] extends [never]
|
||||||
|
? [node: Node]
|
||||||
|
: undefined extends Parameter
|
||||||
|
? [node: Node, parameter?: Parameter]
|
||||||
|
: [node: Node, parameter: Parameter]
|
||||||
|
): void | ActionReturn<Parameter, Attributes>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementation notes:
|
||||||
|
// - undefined extends X instead of X extends undefined makes this work better with both strict and nonstrict mode
|
||||||
|
// - [X] extends [never] is needed, X extends never would reduce the whole resulting type to never and not to one of the condition outcomes
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
// 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;
|
||||||
|
}
|
||||||
@ -1,2 +1,3 @@
|
|||||||
|
/** @type {typeof globalThis} */
|
||||||
export const globals =
|
export const globals =
|
||||||
typeof window !== 'undefined' ? window : typeof globalThis !== 'undefined' ? globalThis : global;
|
typeof window !== 'undefined' ? window : typeof globalThis !== 'undefined' ? globalThis : global;
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
/**
|
|
||||||
* INTERNAL, DO NOT USE. Code may change at any time.
|
|
||||||
*/
|
|
||||||
export interface Fragment {
|
|
||||||
key: string | null;
|
|
||||||
first: null;
|
|
||||||
/* create */ c: () => void;
|
|
||||||
/* claim */ l: (nodes: any) => void;
|
|
||||||
/* hydrate */ h: () => void;
|
|
||||||
/* mount */ m: (target: HTMLElement, anchor: any) => void;
|
|
||||||
/* update */ p: (ctx: T$$['ctx'], dirty: T$$['dirty']) => void;
|
|
||||||
/* measure */ r: () => void;
|
|
||||||
/* fix */ f: () => void;
|
|
||||||
/* animate */ a: () => void;
|
|
||||||
/* intro */ i: (local: any) => void;
|
|
||||||
/* outro */ o: (local: any) => void;
|
|
||||||
/* destroy */ d: (detaching: 0 | 1) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FragmentFactory = (ctx: any) => Fragment;
|
|
||||||
|
|
||||||
export interface T$$ {
|
|
||||||
dirty: number[];
|
|
||||||
ctx: any[];
|
|
||||||
bound: any;
|
|
||||||
update: () => void;
|
|
||||||
callbacks: any;
|
|
||||||
after_update: any[];
|
|
||||||
props: Record<string, 0 | string>;
|
|
||||||
fragment: null | false | Fragment;
|
|
||||||
not_equal: any;
|
|
||||||
before_update: any[];
|
|
||||||
context: Map<any, any>;
|
|
||||||
on_mount: any[];
|
|
||||||
on_destroy: any[];
|
|
||||||
skip_bound: boolean;
|
|
||||||
on_disconnect: any[];
|
|
||||||
root: Element | ShadowRoot;
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
export interface EventDispatcher<EventMap extends Record<string, any>> {
|
|
||||||
// Implementation notes:
|
|
||||||
// - undefined extends X instead of X extends undefined makes this work better with both strict and nonstrict mode
|
|
||||||
// - [X] extends [never] is needed, X extends never would reduce the whole resulting type to never and not to one of the condition outcomes
|
|
||||||
<Type extends keyof EventMap>(
|
|
||||||
...args: [EventMap[Type]] extends [never]
|
|
||||||
? [type: Type, parameter?: null | undefined, options?: DispatchOptions]
|
|
||||||
: null extends EventMap[Type]
|
|
||||||
? [type: Type, parameter?: EventMap[Type], options?: DispatchOptions]
|
|
||||||
: undefined extends EventMap[Type]
|
|
||||||
? [type: Type, parameter?: EventMap[Type], options?: DispatchOptions]
|
|
||||||
: [type: Type, parameter: EventMap[Type], options?: DispatchOptions]
|
|
||||||
): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DispatchOptions {
|
|
||||||
cancelable?: boolean;
|
|
||||||
}
|
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
import type { AnimationConfig } from '../animate';
|
||||||
|
import type { Fragment, FragmentFactory } from './public';
|
||||||
|
|
||||||
|
export type AnimationFn = (
|
||||||
|
node: Element,
|
||||||
|
{ from, to }: { from: PositionRect; to: PositionRect },
|
||||||
|
params: any
|
||||||
|
) => AnimationConfig;
|
||||||
|
|
||||||
|
type Listener = (entry: ResizeObserverEntry) => any;
|
||||||
|
|
||||||
|
//todo: documentation says it is DOMRect, but in IE it would be ClientRect
|
||||||
|
export type PositionRect = DOMRect | ClientRect;
|
||||||
|
|
||||||
|
export interface PromiseInfo<T> {
|
||||||
|
ctx: null | any;
|
||||||
|
// unique object instance as a key to compare different promises
|
||||||
|
token: {};
|
||||||
|
hasCatch: boolean;
|
||||||
|
pending: FragmentFactory;
|
||||||
|
then: FragmentFactory;
|
||||||
|
catch: FragmentFactory;
|
||||||
|
// ctx index for resolved value and rejected error
|
||||||
|
value: number;
|
||||||
|
error: number;
|
||||||
|
// resolved value or rejected error
|
||||||
|
resolved?: T;
|
||||||
|
// the current factory function for creating the fragment
|
||||||
|
current: FragmentFactory | null;
|
||||||
|
// the current fragment
|
||||||
|
block: Fragment | null;
|
||||||
|
// tuple of the pending, then, catch fragment
|
||||||
|
blocks: [null | Fragment, null | Fragment, null | Fragment];
|
||||||
|
// DOM elements to mount and anchor on for the {#await} block
|
||||||
|
mount: () => HTMLElement;
|
||||||
|
anchor: HTMLElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this
|
||||||
|
export interface ResizeObserverSize {
|
||||||
|
readonly blockSize: number;
|
||||||
|
readonly inlineSize: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResizeObserverEntry {
|
||||||
|
readonly borderBoxSize: readonly ResizeObserverSize[];
|
||||||
|
readonly contentBoxSize: readonly ResizeObserverSize[];
|
||||||
|
readonly contentRect: DOMRectReadOnly;
|
||||||
|
readonly devicePixelContentBoxSize: readonly ResizeObserverSize[];
|
||||||
|
readonly target: Element;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ResizeObserverBoxOptions = 'border-box' | 'content-box' | 'device-pixel-content-box';
|
||||||
|
|
||||||
|
export interface ResizeObserverOptions {
|
||||||
|
box?: ResizeObserverBoxOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResizeObserver {
|
||||||
|
disconnect(): void;
|
||||||
|
observe(target: Element, options?: ResizeObserverOptions): void;
|
||||||
|
unobserve(target: Element): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResizeObserverCallback {
|
||||||
|
(entries: ResizeObserverEntry[], observer: ResizeObserver): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare let ResizeObserver: {
|
||||||
|
prototype: ResizeObserver;
|
||||||
|
new (callback: ResizeObserverCallback): ResizeObserver;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface StyleInformation {
|
||||||
|
stylesheet: CSSStyleSheet;
|
||||||
|
rules: Record<string, true>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TaskCallback = (now: number) => boolean | void;
|
||||||
|
|
||||||
|
export type TaskEntry = { c: TaskCallback; f: () => void };
|
||||||
Loading…
Reference in new issue