chore: use JSDoc import (#12595)

* more

* more

* more
pull/12597/head
Rich Harris 1 year ago committed by GitHub
parent 8d139210b7
commit c173140969
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -59,7 +59,7 @@ export function index(_, i) {
* @param {EachState} state * @param {EachState} state
* @param {EachItem[]} items * @param {EachItem[]} items
* @param {null | Node} controlled_anchor * @param {null | Node} controlled_anchor
* @param {Map<any, import("#client").EachItem>} items_map * @param {Map<any, EachItem>} items_map
*/ */
function pause_effects(state, items, controlled_anchor, items_map) { function pause_effects(state, items, controlled_anchor, items_map) {
/** @type {TransitionManager[]} */ /** @type {TransitionManager[]} */

@ -1,4 +1,4 @@
/** @import { TemplateNode } from '#client' */ /** @import { Effect, TemplateNode } from '#client' */
import { EFFECT_TRANSPARENT } from '../../constants.js'; import { EFFECT_TRANSPARENT } from '../../constants.js';
import { import {
hydrate_next, hydrate_next,
@ -14,8 +14,8 @@ import { HYDRATION_START_ELSE } from '../../../../constants.js';
/** /**
* @param {TemplateNode} node * @param {TemplateNode} node
* @param {() => boolean} get_condition * @param {() => boolean} get_condition
* @param {(anchor: Node) => import('#client').Dom} consequent_fn * @param {(anchor: Node) => void} consequent_fn
* @param {null | ((anchor: Node) => import('#client').Dom)} [alternate_fn] * @param {null | ((anchor: Node) => void)} [alternate_fn]
* @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local' * @param {boolean} [elseif] True if this is an `{:else if ...}` block rather than an `{#if ...}`, as that affects which transitions are considered 'local'
* @returns {void} * @returns {void}
*/ */
@ -26,10 +26,10 @@ export function if_block(node, get_condition, consequent_fn, alternate_fn = null
var anchor = node; var anchor = node;
/** @type {import('#client').Effect | null} */ /** @type {Effect | null} */
var consequent_effect = null; var consequent_effect = null;
/** @type {import('#client').Effect | null} */ /** @type {Effect | null} */
var alternate_effect = null; var alternate_effect = null;
/** @type {boolean | null} */ /** @type {boolean | null} */

@ -1,3 +1,4 @@
/** @import { AnimateFn, Animation, AnimationConfig, EachItem, Effect, Task, TransitionFn, TransitionManager } from '#client' */
import { noop, is_function } from '../../../shared/utils.js'; import { noop, is_function } from '../../../shared/utils.js';
import { effect } from '../../reactivity/effects.js'; import { effect } from '../../reactivity/effects.js';
import { current_effect, untrack } from '../../runtime.js'; import { current_effect, untrack } from '../../runtime.js';
@ -60,11 +61,11 @@ const linear = (t) => t;
* and attaches it to the block, so that moves can be animated following reconciliation. * and attaches it to the block, so that moves can be animated following reconciliation.
* @template P * @template P
* @param {Element} element * @param {Element} element
* @param {() => import('#client').AnimateFn<P | undefined>} get_fn * @param {() => AnimateFn<P | undefined>} get_fn
* @param {(() => P) | null} get_params * @param {(() => P) | null} get_params
*/ */
export function animation(element, get_fn, get_params) { export function animation(element, get_fn, get_params) {
var item = /** @type {import('#client').EachItem} */ (current_each_item); var item = /** @type {EachItem} */ (current_each_item);
/** @type {DOMRect} */ /** @type {DOMRect} */
var from; var from;
@ -72,7 +73,7 @@ export function animation(element, get_fn, get_params) {
/** @type {DOMRect} */ /** @type {DOMRect} */
var to; var to;
/** @type {import('#client').Animation | undefined} */ /** @type {Animation | undefined} */
var animation; var animation;
/** @type {null | { position: string, width: string, height: string, transform: string }} */ /** @type {null | { position: string, width: string, height: string, transform: string }} */
@ -167,7 +168,7 @@ export function animation(element, get_fn, get_params) {
* @template P * @template P
* @param {number} flags * @param {number} flags
* @param {HTMLElement} element * @param {HTMLElement} element
* @param {() => import('#client').TransitionFn<P | undefined>} get_fn * @param {() => TransitionFn<P | undefined>} get_fn
* @param {(() => P) | null} get_params * @param {(() => P) | null} get_params
* @returns {void} * @returns {void}
*/ */
@ -180,15 +181,15 @@ export function transition(flags, element, get_fn, get_params) {
/** @type {'in' | 'out' | 'both'} */ /** @type {'in' | 'out' | 'both'} */
var direction = is_both ? 'both' : is_intro ? 'in' : 'out'; var direction = is_both ? 'both' : is_intro ? 'in' : 'out';
/** @type {import('#client').AnimationConfig | ((opts: { direction: 'in' | 'out' }) => import('#client').AnimationConfig) | undefined} */ /** @type {AnimationConfig | ((opts: { direction: 'in' | 'out' }) => AnimationConfig) | undefined} */
var current_options; var current_options;
var inert = element.inert; var inert = element.inert;
/** @type {import('#client').Animation | undefined} */ /** @type {Animation | undefined} */
var intro; var intro;
/** @type {import('#client').Animation | undefined} */ /** @type {Animation | undefined} */
var outro; var outro;
/** @type {(() => void) | undefined} */ /** @type {(() => void) | undefined} */
@ -201,7 +202,7 @@ export function transition(flags, element, get_fn, get_params) {
return (current_options ??= get_fn()(element, get_params?.(), { direction })); return (current_options ??= get_fn()(element, get_params?.(), { direction }));
} }
/** @type {import('#client').TransitionManager} */ /** @type {TransitionManager} */
var transition = { var transition = {
is_global, is_global,
in() { in() {
@ -271,7 +272,7 @@ export function transition(flags, element, get_fn, get_params) {
} }
}; };
var e = /** @type {import('#client').Effect} */ (current_effect); var e = /** @type {Effect} */ (current_effect);
(e.transitions ??= []).push(transition); (e.transitions ??= []).push(transition);
@ -282,7 +283,7 @@ export function transition(flags, element, get_fn, get_params) {
let run = is_global; let run = is_global;
if (!run) { if (!run) {
var block = /** @type {import('#client').Effect | null} */ (e.parent); var block = /** @type {Effect | null} */ (e.parent);
// skip over transparent blocks (e.g. snippets, else-if blocks) // skip over transparent blocks (e.g. snippets, else-if blocks)
while (block && (block.f & EFFECT_TRANSPARENT) !== 0) { while (block && (block.f & EFFECT_TRANSPARENT) !== 0) {
@ -305,12 +306,12 @@ export function transition(flags, element, get_fn, get_params) {
/** /**
* Animates an element, according to the provided configuration * Animates an element, according to the provided configuration
* @param {Element} element * @param {Element} element
* @param {import('#client').AnimationConfig | ((opts: { direction: 'in' | 'out' }) => import('#client').AnimationConfig)} options * @param {AnimationConfig | ((opts: { direction: 'in' | 'out' }) => AnimationConfig)} options
* @param {import('#client').Animation | undefined} counterpart The corresponding intro/outro to this outro/intro * @param {Animation | undefined} counterpart The corresponding intro/outro to this outro/intro
* @param {number} t2 The target `t` value `1` for intro, `0` for outro * @param {number} t2 The target `t` value `1` for intro, `0` for outro
* @param {(() => void) | undefined} on_finish Called after successfully completing the animation * @param {(() => void) | undefined} on_finish Called after successfully completing the animation
* @param {(() => void) | undefined} on_abort Called if the animation is aborted * @param {(() => void) | undefined} on_abort Called if the animation is aborted
* @returns {import('#client').Animation} * @returns {Animation}
*/ */
function animate(element, options, counterpart, t2, on_finish, on_abort) { function animate(element, options, counterpart, t2, on_finish, on_abort) {
var is_intro = t2 === 1; var is_intro = t2 === 1;
@ -319,7 +320,7 @@ function animate(element, options, counterpart, t2, on_finish, on_abort) {
// In the case of a deferred transition (such as `crossfade`), `option` will be // In the case of a deferred transition (such as `crossfade`), `option` will be
// a function rather than an `AnimationConfig`. We need to call this function // a function rather than an `AnimationConfig`. We need to call this function
// once DOM has been updated... // once DOM has been updated...
/** @type {import('#client').Animation} */ /** @type {Animation} */
var a; var a;
queue_micro_task(() => { queue_micro_task(() => {
@ -358,10 +359,10 @@ function animate(element, options, counterpart, t2, on_finish, on_abort) {
var duration = options.duration * Math.abs(delta); var duration = options.duration * Math.abs(delta);
var end = start + duration; var end = start + duration;
/** @type {Animation} */ /** @type {globalThis.Animation} */
var animation; var animation;
/** @type {import('#client').Task} */ /** @type {Task} */
var task; var task;
if (css) { if (css) {

@ -1,3 +1,4 @@
/** @import { Derived } from '#client' */
import { CLEAN, DERIVED, DESTROYED, DIRTY, MAYBE_DIRTY, UNOWNED } from '../constants.js'; import { CLEAN, DERIVED, DESTROYED, DIRTY, MAYBE_DIRTY, UNOWNED } from '../constants.js';
import { import {
current_reaction, current_reaction,
@ -16,14 +17,14 @@ export let updating_derived = false;
/** /**
* @template V * @template V
* @param {() => V} fn * @param {() => V} fn
* @returns {import('#client').Derived<V>} * @returns {Derived<V>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function derived(fn) { export function derived(fn) {
let flags = DERIVED | DIRTY; let flags = DERIVED | DIRTY;
if (current_effect === null) flags |= UNOWNED; if (current_effect === null) flags |= UNOWNED;
/** @type {import('#client').Derived<V>} */ /** @type {Derived<V>} */
const signal = { const signal = {
deps: null, deps: null,
deriveds: null, deriveds: null,
@ -38,7 +39,7 @@ export function derived(fn) {
}; };
if (current_reaction !== null && (current_reaction.f & DERIVED) !== 0) { if (current_reaction !== null && (current_reaction.f & DERIVED) !== 0) {
var current_derived = /** @type {import('#client').Derived} */ (current_reaction); var current_derived = /** @type {Derived} */ (current_reaction);
if (current_derived.deriveds === null) { if (current_derived.deriveds === null) {
current_derived.deriveds = [signal]; current_derived.deriveds = [signal];
} else { } else {
@ -52,7 +53,7 @@ export function derived(fn) {
/** /**
* @template V * @template V
* @param {() => V} fn * @param {() => V} fn
* @returns {import('#client').Derived<V>} * @returns {Derived<V>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function derived_safe_equal(fn) { export function derived_safe_equal(fn) {
@ -62,7 +63,7 @@ export function derived_safe_equal(fn) {
} }
/** /**
* @param {import('#client').Derived} derived * @param {Derived} derived
* @returns {void} * @returns {void}
*/ */
function destroy_derived_children(derived) { function destroy_derived_children(derived) {
@ -79,7 +80,7 @@ function destroy_derived_children(derived) {
} }
/** /**
* @param {import('#client').Derived} derived * @param {Derived} derived
* @returns {void} * @returns {void}
*/ */
export function update_derived(derived) { export function update_derived(derived) {
@ -103,7 +104,7 @@ export function update_derived(derived) {
} }
/** /**
* @param {import('#client').Derived} signal * @param {Derived} signal
* @returns {void} * @returns {void}
*/ */
export function destroy_derived(signal) { export function destroy_derived(signal) {

@ -1,3 +1,4 @@
/** @import { ComponentContext, ComponentContextLegacy, Effect, Reaction, TemplateNode, TransitionManager } from '#client' */
import { import {
check_dirtiness, check_dirtiness,
current_component_context, current_component_context,
@ -57,8 +58,8 @@ export function validate_effect(rune) {
} }
/** /**
* @param {import("#client").Effect} effect * @param {Effect} effect
* @param {import("#client").Reaction} parent_effect * @param {Reaction} parent_effect
*/ */
export function push_effect(effect, parent_effect) { export function push_effect(effect, parent_effect) {
var parent_last = parent_effect.last; var parent_last = parent_effect.last;
@ -76,12 +77,12 @@ export function push_effect(effect, parent_effect) {
* @param {null | (() => void | (() => void))} fn * @param {null | (() => void | (() => void))} fn
* @param {boolean} sync * @param {boolean} sync
* @param {boolean} push * @param {boolean} push
* @returns {import('#client').Effect} * @returns {Effect}
*/ */
function create_effect(type, fn, sync, push = true) { function create_effect(type, fn, sync, push = true) {
var is_root = (type & ROOT_EFFECT) !== 0; var is_root = (type & ROOT_EFFECT) !== 0;
/** @type {import('#client').Effect} */ /** @type {Effect} */
var effect = { var effect = {
ctx: current_component_context, ctx: current_component_context,
deps: null, deps: null,
@ -187,7 +188,7 @@ export function user_effect(fn) {
} }
if (defer) { if (defer) {
var context = /** @type {import('#client').ComponentContext} */ (current_component_context); var context = /** @type {ComponentContext} */ (current_component_context);
(context.e ??= []).push(fn); (context.e ??= []).push(fn);
} else { } else {
var signal = effect(fn); var signal = effect(fn);
@ -198,7 +199,7 @@ export function user_effect(fn) {
/** /**
* Internal representation of `$effect.pre(...)` * Internal representation of `$effect.pre(...)`
* @param {() => void | (() => void)} fn * @param {() => void | (() => void)} fn
* @returns {import('#client').Effect} * @returns {Effect}
*/ */
export function user_pre_effect(fn) { export function user_pre_effect(fn) {
validate_effect('$effect.pre'); validate_effect('$effect.pre');
@ -229,7 +230,7 @@ export function effect_root(fn) {
/** /**
* @param {() => void | (() => void)} fn * @param {() => void | (() => void)} fn
* @returns {import('#client').Effect} * @returns {Effect}
*/ */
export function effect(fn) { export function effect(fn) {
return create_effect(EFFECT, fn, false); return create_effect(EFFECT, fn, false);
@ -241,9 +242,9 @@ export function effect(fn) {
* @param {() => void | (() => void)} fn * @param {() => void | (() => void)} fn
*/ */
export function legacy_pre_effect(deps, fn) { export function legacy_pre_effect(deps, fn) {
var context = /** @type {import('#client').ComponentContextLegacy} */ (current_component_context); var context = /** @type {ComponentContextLegacy} */ (current_component_context);
/** @type {{ effect: null | import('#client').Effect, ran: boolean }} */ /** @type {{ effect: null | Effect, ran: boolean }} */
var token = { effect: null, ran: false }; var token = { effect: null, ran: false };
context.l.r1.push(token); context.l.r1.push(token);
@ -261,7 +262,7 @@ export function legacy_pre_effect(deps, fn) {
} }
export function legacy_pre_effect_reset() { export function legacy_pre_effect_reset() {
var context = /** @type {import('#client').ComponentContextLegacy} */ (current_component_context); var context = /** @type {ComponentContextLegacy} */ (current_component_context);
render_effect(() => { render_effect(() => {
if (!get(context.l.r2)) return; if (!get(context.l.r2)) return;
@ -283,7 +284,7 @@ export function legacy_pre_effect_reset() {
/** /**
* @param {() => void | (() => void)} fn * @param {() => void | (() => void)} fn
* @returns {import('#client').Effect} * @returns {Effect}
*/ */
export function render_effect(fn) { export function render_effect(fn) {
return create_effect(RENDER_EFFECT, fn, true); return create_effect(RENDER_EFFECT, fn, true);
@ -291,7 +292,7 @@ export function render_effect(fn) {
/** /**
* @param {() => void | (() => void)} fn * @param {() => void | (() => void)} fn
* @returns {import('#client').Effect} * @returns {Effect}
*/ */
export function template_effect(fn) { export function template_effect(fn) {
if (DEV) { if (DEV) {
@ -319,7 +320,7 @@ export function branch(fn, push = true) {
} }
/** /**
* @param {import("#client").Effect} effect * @param {Effect} effect
*/ */
export function execute_effect_teardown(effect) { export function execute_effect_teardown(effect) {
var teardown = effect.teardown; var teardown = effect.teardown;
@ -338,7 +339,7 @@ export function execute_effect_teardown(effect) {
} }
/** /**
* @param {import('#client').Effect} effect * @param {Effect} effect
* @param {boolean} [remove_dom] * @param {boolean} [remove_dom]
* @returns {void} * @returns {void}
*/ */
@ -346,14 +347,13 @@ export function destroy_effect(effect, remove_dom = true) {
var removed = false; var removed = false;
if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null) { if ((remove_dom || (effect.f & HEAD_EFFECT) !== 0) && effect.nodes !== null) {
/** @type {import('#client').TemplateNode | null} */ /** @type {TemplateNode | null} */
var node = effect.nodes.start; var node = effect.nodes.start;
var end = effect.nodes.end; var end = effect.nodes.end;
while (node !== null) { while (node !== null) {
/** @type {import('#client').TemplateNode | null} */ /** @type {TemplateNode | null} */
var next = var next = node === end ? null : /** @type {TemplateNode} */ (node.nextSibling);
node === end ? null : /** @type {import('#client').TemplateNode} */ (node.nextSibling);
node.remove(); node.remove();
node = next; node = next;
@ -396,7 +396,7 @@ export function destroy_effect(effect, remove_dom = true) {
/** /**
* Detach an effect from the effect tree, freeing up memory and * Detach an effect from the effect tree, freeing up memory and
* reducing the amount of work that happens on subsequent traversals * reducing the amount of work that happens on subsequent traversals
* @param {import('#client').Effect} effect * @param {Effect} effect
*/ */
export function unlink_effect(effect) { export function unlink_effect(effect) {
var parent = effect.parent; var parent = effect.parent;
@ -418,11 +418,11 @@ export function unlink_effect(effect) {
* It stays around (in memory, and in the DOM) until outro transitions have * It stays around (in memory, and in the DOM) until outro transitions have
* completed, and if the state change is reversed then we _resume_ it. * completed, and if the state change is reversed then we _resume_ it.
* A paused effect does not update, and the DOM subtree becomes inert. * A paused effect does not update, and the DOM subtree becomes inert.
* @param {import('#client').Effect} effect * @param {Effect} effect
* @param {() => void} [callback] * @param {() => void} [callback]
*/ */
export function pause_effect(effect, callback) { export function pause_effect(effect, callback) {
/** @type {import('#client').TransitionManager[]} */ /** @type {TransitionManager[]} */
var transitions = []; var transitions = [];
pause_children(effect, transitions, true); pause_children(effect, transitions, true);
@ -434,7 +434,7 @@ export function pause_effect(effect, callback) {
} }
/** /**
* @param {import('#client').TransitionManager[]} transitions * @param {TransitionManager[]} transitions
* @param {() => void} fn * @param {() => void} fn
*/ */
export function run_out_transitions(transitions, fn) { export function run_out_transitions(transitions, fn) {
@ -450,8 +450,8 @@ export function run_out_transitions(transitions, fn) {
} }
/** /**
* @param {import('#client').Effect} effect * @param {Effect} effect
* @param {import('#client').TransitionManager[]} transitions * @param {TransitionManager[]} transitions
* @param {boolean} local * @param {boolean} local
*/ */
export function pause_children(effect, transitions, local) { export function pause_children(effect, transitions, local) {
@ -482,14 +482,14 @@ export function pause_children(effect, transitions, local) {
/** /**
* The opposite of `pause_effect`. We call this if (for example) * The opposite of `pause_effect`. We call this if (for example)
* `x` becomes falsy then truthy: `{#if x}...{/if}` * `x` becomes falsy then truthy: `{#if x}...{/if}`
* @param {import('#client').Effect} effect * @param {Effect} effect
*/ */
export function resume_effect(effect) { export function resume_effect(effect) {
resume_children(effect, true); resume_children(effect, true);
} }
/** /**
* @param {import('#client').Effect} effect * @param {Effect} effect
* @param {boolean} local * @param {boolean} local
*/ */
function resume_children(effect, local) { function resume_children(effect, local) {

@ -1,3 +1,4 @@
/** @import { Derived, Effect, Source, Value } from '#client' */
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { import {
current_component_context, current_component_context,
@ -31,7 +32,7 @@ let inspect_effects = new Set();
/** /**
* @template V * @template V
* @param {V} v * @param {V} v
* @returns {import('#client').Source<V>} * @returns {Source<V>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function source(v) { export function source(v) {
@ -47,7 +48,7 @@ export function source(v) {
/** /**
* @template V * @template V
* @param {V} initial_value * @param {V} initial_value
* @returns {import('#client').Source<V>} * @returns {Source<V>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function mutable_source(initial_value) { export function mutable_source(initial_value) {
@ -65,7 +66,7 @@ export function mutable_source(initial_value) {
/** /**
* @template V * @template V
* @param {import('#client').Value<V>} source * @param {Value<V>} source
* @param {V} value * @param {V} value
*/ */
export function mutate(source, value) { export function mutate(source, value) {
@ -78,7 +79,7 @@ export function mutate(source, value) {
/** /**
* @template V * @template V
* @param {import('#client').Source<V>} source * @param {Source<V>} source
* @param {V} value * @param {V} value
* @returns {V} * @returns {V}
*/ */
@ -129,7 +130,7 @@ export function set(source, value) {
} }
/** /**
* @param {import('#client').Value} signal * @param {Value} signal
* @param {number} status should be DIRTY or MAYBE_DIRTY * @param {number} status should be DIRTY or MAYBE_DIRTY
* @returns {void} * @returns {void}
*/ */
@ -161,9 +162,9 @@ function mark_reactions(signal, status) {
// If the signal a) was previously clean or b) is an unowned derived, then mark it // If the signal a) was previously clean or b) is an unowned derived, then mark it
if ((flags & (CLEAN | UNOWNED)) !== 0) { if ((flags & (CLEAN | UNOWNED)) !== 0) {
if ((flags & DERIVED) !== 0) { if ((flags & DERIVED) !== 0) {
mark_reactions(/** @type {import('#client').Derived} */ (reaction), MAYBE_DIRTY); mark_reactions(/** @type {Derived} */ (reaction), MAYBE_DIRTY);
} else { } else {
schedule_effect(/** @type {import('#client').Effect} */ (reaction)); schedule_effect(/** @type {Effect} */ (reaction));
} }
} }
} }

@ -1,3 +1,4 @@
/** @import { Component, Payload } from '#server' */
import { import {
FILENAME, FILENAME,
disallowed_paragraph_contents, disallowed_paragraph_contents,
@ -33,7 +34,7 @@ function stringify(element) {
} }
/** /**
* @param {import('#server').Payload} payload * @param {Payload} payload
* @param {Element} parent * @param {Element} parent
* @param {Element} child * @param {Element} child
*/ */
@ -51,13 +52,13 @@ function print_error(payload, parent, child) {
} }
/** /**
* @param {import('#server').Payload} payload * @param {Payload} payload
* @param {string} tag * @param {string} tag
* @param {number} line * @param {number} line
* @param {number} column * @param {number} column
*/ */
export function push_element(payload, tag, line, column) { export function push_element(payload, tag, line, column) {
var filename = /** @type {import('#server').Component} */ (current_component).function[FILENAME]; var filename = /** @type {Component} */ (current_component).function[FILENAME];
var child = { tag, parent, filename, line, column }; var child = { tag, parent, filename, line, column };
if (parent !== null && !is_tag_valid_with_parent(tag, parent.tag)) { if (parent !== null && !is_tag_valid_with_parent(tag, parent.tag)) {

@ -1,3 +1,4 @@
/** @import { ComponentType, SvelteComponent } from 'svelte' */
/** @import { Component, Payload, RenderOutput } from '#server' */ /** @import { Component, Payload, RenderOutput } from '#server' */
/** @import { Store } from '#shared' */ /** @import { Store } from '#shared' */
export { FILENAME, HMR } from '../../constants.js'; export { FILENAME, HMR } from '../../constants.js';
@ -103,7 +104,7 @@ export let on_destroy = [];
* Only available on the server and when compiling with the `server` option. * Only available on the server and when compiling with the `server` option.
* Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app. * Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
* @template {Record<string, any>} Props * @template {Record<string, any>} Props
* @param {import('svelte').Component<Props> | import('svelte').ComponentType<import('svelte').SvelteComponent<Props>>} component * @param {import('svelte').Component<Props> | ComponentType<SvelteComponent<Props>>} component
* @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }} [options] * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }} [options]
* @returns {RenderOutput} * @returns {RenderOutput}
*/ */

@ -1,3 +1,6 @@
/** @import { Task } from '#client' */
/** @import { SpringOpts, SpringUpdateOpts, TickContext } from './private.js' */
/** @import { Spring } from './public.js' */
import { writable } from '../store/index.js'; import { writable } from '../store/index.js';
import { loop } from '../internal/client/loop.js'; import { loop } from '../internal/client/loop.js';
import { raf } from '../internal/client/timing.js'; import { raf } from '../internal/client/timing.js';
@ -5,7 +8,7 @@ import { is_date } from './utils.js';
/** /**
* @template T * @template T
* @param {import('./private').TickContext<T>} ctx * @param {TickContext<T>} ctx
* @param {T} last_value * @param {T} last_value
* @param {T} current_value * @param {T} current_value
* @param {T} target_value * @param {T} target_value
@ -53,15 +56,15 @@ function tick_spring(ctx, last_value, current_value, target_value) {
* https://svelte.dev/docs/svelte-motion#spring * https://svelte.dev/docs/svelte-motion#spring
* @template [T=any] * @template [T=any]
* @param {T} [value] * @param {T} [value]
* @param {import('./private').SpringOpts} [opts] * @param {SpringOpts} [opts]
* @returns {import('./public.js').Spring<T>} * @returns {Spring<T>}
*/ */
export function spring(value, opts = {}) { export function spring(value, opts = {}) {
const store = writable(value); const store = writable(value);
const { stiffness = 0.15, damping = 0.8, precision = 0.01 } = opts; const { stiffness = 0.15, damping = 0.8, precision = 0.01 } = opts;
/** @type {number} */ /** @type {number} */
let last_time; let last_time;
/** @type {import('../internal/client/types').Task | null} */ /** @type {Task | null} */
let task; let task;
/** @type {object} */ /** @type {object} */
let current_token; let current_token;
@ -74,7 +77,7 @@ export function spring(value, opts = {}) {
let cancel_task = false; let cancel_task = false;
/** /**
* @param {T} new_value * @param {T} new_value
* @param {import('./private').SpringUpdateOpts} opts * @param {SpringUpdateOpts} opts
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
function set(new_value, opts = {}) { function set(new_value, opts = {}) {
@ -101,7 +104,7 @@ export function spring(value, opts = {}) {
return false; return false;
} }
inv_mass = Math.min(inv_mass + inv_mass_recovery_rate, 1); inv_mass = Math.min(inv_mass + inv_mass_recovery_rate, 1);
/** @type {import('./private').TickContext<T>} */ /** @type {TickContext<T>} */
const ctx = { const ctx = {
inv_mass, inv_mass,
opts: spring, opts: spring,
@ -120,12 +123,12 @@ export function spring(value, opts = {}) {
}); });
} }
return new Promise((fulfil) => { return new Promise((fulfil) => {
/** @type {import('../internal/client/types').Task} */ (task).promise.then(() => { /** @type {Task} */ (task).promise.then(() => {
if (token === current_token) fulfil(); if (token === current_token) fulfil();
}); });
}); });
} }
/** @type {import('./public.js').Spring<T>} */ /** @type {Spring<T>} */
const spring = { const spring = {
set, set,
update: (fn, opts) => set(fn(/** @type {T} */ (target_value), /** @type {T} */ (value)), opts), update: (fn, opts) => set(fn(/** @type {T} */ (target_value), /** @type {T} */ (value)), opts),

@ -1,3 +1,4 @@
/** @import { Source } from '#client' */
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js'; import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js'; import { get } from '../internal/client/runtime.js';
@ -9,7 +10,7 @@ import { increment } from './utils.js';
* @extends {Map<K, V>} * @extends {Map<K, V>}
*/ */
export class SvelteMap extends Map { export class SvelteMap extends Map {
/** @type {Map<K, import('#client').Source<number>>} */ /** @type {Map<K, Source<number>>} */
#sources = new Map(); #sources = new Map();
#version = source(0); #version = source(0);
#size = source(0); #size = source(0);

@ -1,3 +1,4 @@
/** @import { Source } from '#client' */
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js'; import { source, set } from '../internal/client/reactivity/sources.js';
import { get } from '../internal/client/runtime.js'; import { get } from '../internal/client/runtime.js';
@ -13,7 +14,7 @@ var inited = false;
* @extends {Set<T>} * @extends {Set<T>}
*/ */
export class SvelteSet extends Set { export class SvelteSet extends Set {
/** @type {Map<T, import('#client').Source<boolean>>} */ /** @type {Map<T, Source<boolean>>} */
#sources = new Map(); #sources = new Map();
#version = source(0); #version = source(0);
#size = source(0); #size = source(0);

@ -1,3 +1,4 @@
/** @import { Source } from '#client' */
import { set } from '../internal/client/reactivity/sources.js'; import { set } from '../internal/client/reactivity/sources.js';
/** /**
@ -30,7 +31,7 @@ function get_this() {
return this; return this;
} }
/** @param {import('#client').Source<number>} source */ /** @param {Source<number>} source */
export function increment(source) { export function increment(source) {
set(source, source.v + 1); set(source, source.v + 1);
} }

Loading…
Cancel
Save