import { MediaQuery } from "./svelte_reactivity.js"; import { a as writable } from "./shared-Clug2-tp.js"; import { Et as raf, Tt as loop } from "./attachments-C3vJBgrq.js"; import { Jn as deferred, Qt as tag, a as get, ar as noop, dt as state, k as render_effect, lt as set } from "./runtime-DInTlc-h.js"; import { linear } from "./svelte_easing.js"; // node_modules/svelte/src/motion/utils.js /** * @param {any} obj * @returns {obj is Date} */ function is_date(obj) { return Object.prototype.toString.call(obj) === "[object Date]"; } // node_modules/svelte/src/motion/spring.js /** @import { Task } from '#client' */ /** @import { TickContext } from './private.js' */ /** @import { Spring as SpringStore, SpringOptions, SpringUpdateOptions } from './public.js' */ /** * @template T * @param {TickContext} ctx * @param {T} last_value * @param {T} current_value * @param {T} target_value * @returns {T} */ function tick_spring(ctx, last_value, current_value, target_value) { if (typeof current_value === "number" || is_date(current_value)) { const delta = target_value - current_value; const velocity = (current_value - last_value) / (ctx.dt || 1 / 60); const d = (velocity + (ctx.opts.stiffness * delta - ctx.opts.damping * velocity) * ctx.inv_mass) * ctx.dt; if (Math.abs(d) < ctx.opts.precision && Math.abs(delta) < ctx.opts.precision) return target_value; else { ctx.settled = false; return is_date(current_value) ? new Date(current_value.getTime() + d) : current_value + d; } } else if (Array.isArray(current_value)) return current_value.map((_, i) => tick_spring(ctx, last_value[i], current_value[i], target_value[i])); else if (typeof current_value === "object") { const next_value = {}; for (const k in current_value) next_value[k] = tick_spring(ctx, last_value[k], current_value[k], target_value[k]); return next_value; } else throw new Error(`Cannot spring ${typeof current_value} values`); } /** * The spring function in Svelte creates a store whose value is animated, with a motion that simulates the behavior of a spring. This means when the value changes, instead of transitioning at a steady rate, it "bounces" like a spring would, depending on the physics parameters provided. This adds a level of realism to the transitions and can enhance the user experience. * * @deprecated Use [`Spring`](https://svelte.dev/docs/svelte/svelte-motion#Spring) instead * @template [T=any] * @param {T} [value] * @param {SpringOptions} [opts] * @returns {SpringStore} */ function spring(value, opts = {}) { const store = writable(value); const { stiffness = .15, damping = .8, precision = .01 } = opts; /** @type {number} */ let last_time; /** @type {Task | null} */ let task; /** @type {object} */ let current_token; let last_value = value; let target_value = value; let inv_mass = 1; let inv_mass_recovery_rate = 0; let cancel_task = false; /** * @param {T} new_value * @param {SpringUpdateOptions} opts * @returns {Promise} */ function set(new_value, opts = {}) { target_value = new_value; const token = current_token = {}; if (value == null || opts.hard || spring.stiffness >= 1 && spring.damping >= 1) { cancel_task = true; last_time = raf.now(); last_value = new_value; store.set(value = target_value); return Promise.resolve(); } else if (opts.soft) { inv_mass_recovery_rate = 1 / ((opts.soft === true ? .5 : +opts.soft) * 60); inv_mass = 0; } if (!task) { last_time = raf.now(); cancel_task = false; task = loop((now) => { if (cancel_task) { cancel_task = false; task = null; return false; } inv_mass = Math.min(inv_mass + inv_mass_recovery_rate, 1); const elapsed = Math.min(now - last_time, 1e3 / 30); /** @type {TickContext} */ const ctx = { inv_mass, opts: spring, settled: true, dt: elapsed * 60 / 1e3 }; const next_value = tick_spring(ctx, last_value, value, target_value); last_time = now; last_value = value; store.set(value = next_value); if (ctx.settled) task = null; return !ctx.settled; }); } return new Promise((fulfil) => { /** @type {Task} */ task.promise.then(() => { if (token === current_token) fulfil(); }); }); } /** @type {SpringStore} */ const spring = { set, update: (fn, opts) => set(fn(target_value, value), opts), subscribe: store.subscribe, stiffness, damping, precision }; return spring; } /** * A wrapper for a value that behaves in a spring-like fashion. Changes to `spring.target` will cause `spring.current` to * move towards it over time, taking account of the `spring.stiffness` and `spring.damping` parameters. * * ```svelte *