pull/12239/head
Rich Harris 2 years ago
parent 0d862a9db8
commit 842d823fea

@ -1,11 +1,11 @@
/** @import * as Public from './public' */
/** @import * as Private from './private' */
/** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from './public' */
/** @import { Invalidator, Stores, StoresValues, SubscribeInvalidateTuple } from './private' */
import { noop, run_all } from '../internal/shared/utils.js';
import { safe_not_equal } from '../internal/client/reactivity/equality.js';
import { subscribe_to_store } from './utils.js';
/**
* @type {Array<Private.SubscribeInvalidateTuple<any> | any>}
* @type {Array<SubscribeInvalidateTuple<any> | any>}
*/
const subscriber_queue = [];
@ -15,8 +15,8 @@ const subscriber_queue = [];
* https://svelte.dev/docs/svelte-store#readable
* @template T
* @param {T} [value] initial value
* @param {Public.StartStopNotifier<T>} [start]
* @returns {Public.Readable<T>}
* @param {StartStopNotifier<T>} [start]
* @returns {Readable<T>}
*/
export function readable(value, start) {
return {
@ -30,14 +30,14 @@ export function readable(value, start) {
* https://svelte.dev/docs/svelte-store#writable
* @template T
* @param {T} [value] initial value
* @param {Public.StartStopNotifier<T>} [start]
* @returns {Public.Writable<T>}
* @param {StartStopNotifier<T>} [start]
* @returns {Writable<T>}
*/
export function writable(value, start = noop) {
/** @type {Public.Unsubscriber | null} */
/** @type {Unsubscriber | null} */
let stop = null;
/** @type {Set<Private.SubscribeInvalidateTuple<T>>} */
/** @type {Set<SubscribeInvalidateTuple<T>>} */
const subscribers = new Set();
/**
@ -65,7 +65,7 @@ export function writable(value, start = noop) {
}
/**
* @param {Public.Updater<T>} fn
* @param {Updater<T>} fn
* @returns {void}
*/
function update(fn) {
@ -73,12 +73,12 @@ export function writable(value, start = noop) {
}
/**
* @param {Public.Subscriber<T>} run
* @param {Private.Invalidator<T>} [invalidate]
* @returns {Public.Unsubscriber}
* @param {Subscriber<T>} run
* @param {Invalidator<T>} [invalidate]
* @returns {Unsubscriber}
*/
function subscribe(run, invalidate = noop) {
/** @type {Private.SubscribeInvalidateTuple<T>} */
/** @type {SubscribeInvalidateTuple<T>} */
const subscriber = [run, invalidate];
subscribers.add(subscriber);
if (subscribers.size === 1) {
@ -101,38 +101,38 @@ export function writable(value, start = noop) {
* applying an aggregation function over its input values.
*
* https://svelte.dev/docs/svelte-store#derived
* @template {Private.Stores} S
* @template {Stores} S
* @template T
* @overload
* @param {S} stores
* @param {(values: StoresValues<S>, set: (value: T) => void, update: (fn: Updater<T>) => void) => Unsubscriber | void} fn
* @param {T} [initial_value]
* @returns {Public.Readable<T>}
* @returns {Readable<T>}
*/
/**
* Derived value store by synchronizing one or more readable stores and
* applying an aggregation function over its input values.
*
* https://svelte.dev/docs/svelte-store#derived
* @template {Private.Stores} S
* @template {Stores} S
* @template T
* @overload
* @param {S} stores
* @param {(values: StoresValues<S>) => T} fn
* @param {T} [initial_value]
* @returns {Public.Readable<T>}
* @returns {Readable<T>}
*/
/**
* @template {Private.Stores} S
* @template {Stores} S
* @template T
* @param {S} stores
* @param {Function} fn
* @param {T} [initial_value]
* @returns {Public.Readable<T>}
* @returns {Readable<T>}
*/
export function derived(stores, fn, initial_value) {
const single = !Array.isArray(stores);
/** @type {Array<Public.Readable<any>>} */
/** @type {Array<Readable<any>>} */
const stores_array = single ? [stores] : stores;
if (!stores_array.every(Boolean)) {
throw new Error('derived() expects stores as input, got a falsy value');
@ -189,8 +189,8 @@ export function derived(stores, fn, initial_value) {
*
* https://svelte.dev/docs/svelte-store#readonly
* @template T
* @param {Public.Readable<T>} store - store to make readonly
* @returns {Public.Readable<T>}
* @param {Readable<T>} store - store to make readonly
* @returns {Readable<T>}
*/
export function readonly(store) {
return {
@ -204,7 +204,7 @@ export function readonly(store) {
*
* https://svelte.dev/docs/svelte-store#get
* @template T
* @param {Public.Readable<T>} store
* @param {Readable<T>} store
* @returns {T}
*/
export function get(store) {

@ -1,17 +1,16 @@
import { Readable, Subscriber } from './public.js';
/** Cleanup logic callback. */
export type Invalidator<T> = (value?: T) => void;
type Invalidator<T> = (value?: T) => void;
/** Pair of subscriber and invalidator. */
export type SubscribeInvalidateTuple<T> = [Subscriber<T>, Invalidator<T>];
type SubscribeInvalidateTuple<T> = [Subscriber<T>, Invalidator<T>];
/** One or more `Readable`s. */
export type Stores =
| Readable<any>
| [Readable<any>, ...Array<Readable<any>>]
| Array<Readable<any>>;
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;
/** One or more values from `Readable` stores. */
export type StoresValues<T> =
type StoresValues<T> =
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };
export { Invalidator, SubscribeInvalidateTuple, Stores, StoresValues };

@ -1,13 +1,13 @@
import type { Invalidator } from './private.js';
/** Callback to inform of a value updates. */
export type Subscriber<T> = (value: T) => void;
type Subscriber<T> = (value: T) => void;
/** Unsubscribes from value updates. */
export type Unsubscriber = () => void;
type Unsubscriber = () => void;
/** Callback to update a value. */
export type Updater<T> = (value: T) => T;
type Updater<T> = (value: T) => T;
/**
* Start and stop notification callbacks.
@ -18,13 +18,13 @@ export type Updater<T> = (value: T) => T;
* @returns {void | (() => void)} Optionally, a cleanup function that is called when the last remaining
* subscriber unsubscribes.
*/
export type StartStopNotifier<T> = (
type StartStopNotifier<T> = (
set: (value: T) => void,
update: (fn: Updater<T>) => void
) => void | (() => void);
/** Readable interface for subscribing. */
export interface Readable<T> {
interface Readable<T> {
/**
* Subscribe on value changes.
* @param run subscription callback
@ -34,7 +34,7 @@ export interface Readable<T> {
}
/** Writable interface for both updating and subscribing. */
export interface Writable<T> extends Readable<T> {
interface Writable<T> extends Readable<T> {
/**
* Set value and inform subscribers.
* @param value to set
@ -48,4 +48,6 @@ export interface Writable<T> extends Readable<T> {
update(this: void, updater: Updater<T>): void;
}
export { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable };
export * from './index.js';

@ -1,4 +1,4 @@
/** @import * as Public from './public' */
/** @import { BlurParams, CrossfadeParams, DrawParams, FadeParams, FlyParams, ScaleParams, SlideParams, TransitionConfig } from './public' */
/** @param {number} x */
const linear = (x) => x;
@ -30,8 +30,8 @@ function split_css_unit(value) {
*
* https://svelte.dev/docs/svelte-transition#blur
* @param {Element} node
* @param {Public.BlurParams} [params]
* @returns {Public.TransitionConfig}
* @param {BlurParams} [params]
* @returns {TransitionConfig}
*/
export function blur(
node,
@ -55,8 +55,8 @@ export function blur(
*
* https://svelte.dev/docs/svelte-transition#fade
* @param {Element} node
* @param {Public.FadeParams} [params]
* @returns {Public.TransitionConfig}
* @param {FadeParams} [params]
* @returns {TransitionConfig}
*/
export function fade(node, { delay = 0, duration = 400, easing = linear } = {}) {
const o = +getComputedStyle(node).opacity;
@ -73,8 +73,8 @@ export function fade(node, { delay = 0, duration = 400, easing = linear } = {})
*
* https://svelte.dev/docs/svelte-transition#fly
* @param {Element} node
* @param {Public.FlyParams} [params]
* @returns {Public.TransitionConfig}
* @param {FlyParams} [params]
* @returns {TransitionConfig}
*/
export function fly(
node,
@ -101,8 +101,8 @@ export function fly(
*
* https://svelte.dev/docs/svelte-transition#slide
* @param {Element} node
* @param {Public.SlideParams} [params]
* @returns {Public.TransitionConfig}
* @param {SlideParams} [params]
* @returns {TransitionConfig}
*/
export function slide(node, { delay = 0, duration = 400, easing = cubic_out, axis = 'y' } = {}) {
const style = getComputedStyle(node);
@ -145,8 +145,8 @@ export function slide(node, { delay = 0, duration = 400, easing = cubic_out, axi
*
* https://svelte.dev/docs/svelte-transition#scale
* @param {Element} node
* @param {Public.ScaleParams} [params]
* @returns {Public.TransitionConfig}
* @param {ScaleParams} [params]
* @returns {TransitionConfig}
*/
export function scale(
node,
@ -173,8 +173,8 @@ export function scale(
*
* https://svelte.dev/docs/svelte-transition#draw
* @param {SVGElement & { getTotalLength(): number }} node
* @param {Public.DrawParams} [params]
* @returns {Public.TransitionConfig}
* @param {DrawParams} [params]
* @returns {TransitionConfig}
*/
export function draw(node, { delay = 0, speed, duration, easing = cubic_in_out } = {}) {
let len = node.getTotalLength();
@ -219,10 +219,10 @@ function assign(tar, src) {
* The `crossfade` function creates a pair of [transitions](https://svelte.dev/docs#template-syntax-element-directives-transition-fn) called `send` and `receive`. When an element is 'sent', it looks for a corresponding element being 'received', and generates a transition that transforms the element to its counterpart's position and fades it out. When an element is 'received', the reverse happens. If there is no counterpart, the `fallback` transition is used.
*
* https://svelte.dev/docs/svelte-transition#crossfade
* @param {Public.CrossfadeParams & {
* fallback?: (node: Element, params: Public.CrossfadeParams, intro: boolean) => Public.TransitionConfig;
* @param {CrossfadeParams & {
* fallback?: (node: Element, params: CrossfadeParams, intro: boolean) => TransitionConfig;
* }} params
* @returns {[(node: any, params: Public.CrossfadeParams & { key: any; }) => () => Public.TransitionConfig, (node: any, params: Public.CrossfadeParams & { key: any; }) => () => Public.TransitionConfig]}
* @returns {[(node: any, params: CrossfadeParams & { key: any; }) => () => TransitionConfig, (node: any, params: CrossfadeParams & { key: any; }) => () => TransitionConfig]}
*/
export function crossfade({ fallback, ...defaults }) {
/** @type {Map<any, Element>} */
@ -233,8 +233,8 @@ export function crossfade({ fallback, ...defaults }) {
/**
* @param {Element} from_node
* @param {Element} node
* @param {Public.CrossfadeParams} params
* @returns {Public.TransitionConfig}
* @param {CrossfadeParams} params
* @returns {TransitionConfig}
*/
function crossfade(from_node, node, params) {
const {
@ -270,7 +270,7 @@ export function crossfade({ fallback, ...defaults }) {
* @param {Map<any, Element>} items
* @param {Map<any, Element>} counterparts
* @param {boolean} intro
* @returns {(node: any, params: Public.CrossfadeParams & { key: any; }) => () => Public.TransitionConfig}
* @returns {(node: any, params: CrossfadeParams & { key: any; }) => () => TransitionConfig}
*/
function transition(items, counterparts, intro) {
// @ts-expect-error TODO improve typings (are the public types wrong?)

@ -1,6 +1,6 @@
export type EasingFunction = (t: number) => number;
type EasingFunction = (t: number) => number;
export interface TransitionConfig {
interface TransitionConfig {
delay?: number;
duration?: number;
easing?: EasingFunction;
@ -8,7 +8,7 @@ export interface TransitionConfig {
tick?: (t: number, u: number) => void;
}
export interface BlurParams {
interface BlurParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
@ -16,13 +16,13 @@ export interface BlurParams {
opacity?: number;
}
export interface FadeParams {
interface FadeParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
}
export interface FlyParams {
interface FlyParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
@ -31,14 +31,14 @@ export interface FlyParams {
opacity?: number;
}
export interface SlideParams {
interface SlideParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
axis?: 'x' | 'y';
}
export interface ScaleParams {
interface ScaleParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
@ -46,17 +46,29 @@ export interface ScaleParams {
opacity?: number;
}
export interface DrawParams {
interface DrawParams {
delay?: number;
speed?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}
export interface CrossfadeParams {
interface CrossfadeParams {
delay?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}
export {
EasingFunction,
TransitionConfig,
BlurParams,
FadeParams,
FlyParams,
SlideParams,
ScaleParams,
DrawParams,
CrossfadeParams
};
export * from './index.js';

@ -952,6 +952,29 @@ declare module 'svelte/compiler' {
inside_rest?: boolean;
} | null;
}
/**
* The preprocess function provides convenient hooks for arbitrarily transforming component source code.
* For example, it can be used to convert a <style lang="sass"> block into vanilla CSS.
*
* https://svelte.dev/docs/svelte-compiler#svelte-preprocess
* */
function preprocess(source: string, preprocessor: PreprocessorGroup | PreprocessorGroup[], options?: {
filename?: string;
} | undefined): Promise<Processed>;
/**
* The current version, as set in package.json.
*
* https://svelte.dev/docs/svelte-compiler#svelte-version
* */
const VERSION: string;
/**
* Does a best-effort migration of Svelte code towards using runes, event attributes and render tags.
* May throw an error if the code is too complex to migrate automatically.
*
* */
function migrate(source: string): {
code: string;
};
interface BaseNode_1 {
type: string;
start: number;
@ -1191,29 +1214,6 @@ declare module 'svelte/compiler' {
| LegacyAttributeShorthand
| LegacyCssNode
| Text;
/**
* The preprocess function provides convenient hooks for arbitrarily transforming component source code.
* For example, it can be used to convert a <style lang="sass"> block into vanilla CSS.
*
* https://svelte.dev/docs/svelte-compiler#svelte-preprocess
* */
function preprocess(source: string, preprocessor: PreprocessorGroup | PreprocessorGroup[], options?: {
filename?: string;
} | undefined): Promise<Processed>;
/**
* The current version, as set in package.json.
*
* https://svelte.dev/docs/svelte-compiler#svelte-version
* */
const VERSION: string;
/**
* Does a best-effort migration of Svelte code towards using runes, event attributes and render tags.
* May throw an error if the code is too complex to migrate automatically.
*
* */
function migrate(source: string): {
code: string;
};
class Scope {
constructor(root: ScopeRoot, parent: Scope | null, porous: boolean);
@ -2030,25 +2030,26 @@ declare module 'svelte/easing' {
}
declare module 'svelte/legacy' {
import type { ComponentConstructorOptions, SvelteComponent, ComponentType, Component } from 'svelte';
/**
* Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.
*
* @deprecated Use this only as a temporary solution to migrate your imperative component code to Svelte 5.
*
* */
function createClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(options: import("svelte").ComponentConstructorOptions<Props> & {
component: import("svelte").ComponentType<import("svelte").SvelteComponent<Props, Events, Slots>> | import("svelte").Component<Props>;
function createClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(options: ComponentConstructorOptions<Props> & {
component: ComponentType<SvelteComponent<Props, Events, Slots>> | Component<Props>;
immutable?: boolean;
hydrate?: boolean;
recover?: boolean;
}): import("svelte").SvelteComponent<Props, Events, Slots> & Exports;
}): SvelteComponent<Props, Events, Slots> & Exports;
/**
* Takes the component function and returns a Svelte 4 compatible component constructor.
*
* @deprecated Use this only as a temporary solution to migrate your imperative component code to Svelte 5.
*
* */
function asClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(component: import("svelte").SvelteComponent<Props, Events, Slots> | import("svelte").Component<Props>): import("svelte").ComponentType<import("svelte").SvelteComponent<Props, Events, Slots> & Exports>;
function asClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(component: SvelteComponent<Props, Events, Slots> | Component<Props>): ComponentType<SvelteComponent<Props, Events, Slots> & Exports>;
/**
* Runs the given function once immediately on the server, and works like `$effect.pre` on the client.
*
@ -2252,10 +2253,7 @@ declare module 'svelte/store' {
type Invalidator<T> = (value?: T) => void;
/** One or more `Readable`s. */
type Stores =
| Readable<any>
| [Readable<any>, ...Array<Readable<any>>]
| Array<Readable<any>>;
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;
/** One or more values from `Readable` stores. */
type StoresValues<T> =
@ -2302,7 +2300,7 @@ declare module 'svelte/store' {
* */
function get<T>(store: Readable<T>): T;
export { Subscriber, Unsubscriber, Updater, StartStopNotifier, Readable, Writable, readable, writable, derived, readonly, get };
export { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable, readable, writable, derived, readonly, get };
}
declare module 'svelte/transition' {

Loading…
Cancel
Save