import { MediaQuery } from "./chunk-RHT4Y54V.js"; import "./chunk-IJHFOFMR.js"; import { writable } from "./chunk-E3I477XG.js"; import "./chunk-MOB764PV.js"; import "./chunk-7RQDXF5S.js"; import { linear } from "./chunk-YERFD2CZ.js"; import { loop, raf } from "./chunk-6JSPETGJ.js"; import "./chunk-IDIKHXSC.js"; import { deferred, get, noop, render_effect, set, source } from "./chunk-VV65CU2H.js"; import "./chunk-HNWPC2PS.js"; import "./chunk-U7P2NEEE.js"; import "./chunk-RVAV4ZRS.js"; import { __privateAdd, __privateGet, __privateMethod, __privateSet } from "./chunk-4VWCUJXE.js"; // node_modules/svelte/src/motion/utils.js function is_date(obj) { return Object.prototype.toString.call(obj) === "[object Date]"; } // node_modules/svelte/src/motion/spring.js 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 spring2 = ctx.opts.stiffness * delta; const damper = ctx.opts.damping * velocity; const acceleration = (spring2 - damper) * ctx.inv_mass; const d = (velocity + acceleration) * 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) => ( // @ts-ignore 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`); } } function spring(value, opts = {}) { const store = writable(value); const { stiffness = 0.15, damping = 0.8, precision = 0.01 } = opts; let last_time; let task; let current_token; let last_value = ( /** @type {T} */ value ); let target_value = ( /** @type {T | undefined} */ value ); let inv_mass = 1; let inv_mass_recovery_rate = 0; let cancel_task = false; function set2(new_value, opts2 = {}) { target_value = new_value; const token = current_token = {}; if (value == null || opts2.hard || spring2.stiffness >= 1 && spring2.damping >= 1) { cancel_task = true; last_time = raf.now(); last_value = new_value; store.set(value = target_value); return Promise.resolve(); } else if (opts2.soft) { const rate = opts2.soft === true ? 0.5 : +opts2.soft; inv_mass_recovery_rate = 1 / (rate * 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 ctx = { inv_mass, opts: spring2, settled: true, dt: (now - last_time) * 60 / 1e3 }; const next_value = tick_spring(ctx, last_value, value, target_value); last_time = now; last_value = /** @type {T} */ value; store.set(value = /** @type {T} */ next_value); if (ctx.settled) { task = null; } return !ctx.settled; }); } return new Promise((fulfil) => { task.promise.then(() => { if (token === current_token) fulfil(); }); }); } const spring2 = { set: set2, update: (fn, opts2) => set2(fn( /** @type {T} */ target_value, /** @type {T} */ value ), opts2), subscribe: store.subscribe, stiffness, damping, precision }; return spring2; } var _stiffness, _damping, _precision, _current, _target, _last_value, _last_time, _inverse_mass, _momentum, _task, _deferred, _Spring_instances, update_fn; var _Spring = class _Spring { /** * @param {T} value * @param {SpringOpts} [options] */ constructor(value, options = {}) { __privateAdd(this, _Spring_instances); __privateAdd(this, _stiffness, source(0.15)); __privateAdd(this, _damping, source(0.8)); __privateAdd(this, _precision, source(0.01)); __privateAdd(this, _current, source( /** @type {T} */ void 0 )); __privateAdd(this, _target, source( /** @type {T} */ void 0 )); __privateAdd(this, _last_value); __privateAdd(this, _last_time, 0); __privateAdd(this, _inverse_mass, 1); __privateAdd(this, _momentum, 0); /** @type {import('../internal/client/types').Task | null} */ __privateAdd(this, _task, null); /** @type {ReturnType | null} */ __privateAdd(this, _deferred, null); __privateGet(this, _current).v = __privateGet(this, _target).v = value; if (typeof options.stiffness === "number") __privateGet(this, _stiffness).v = clamp(options.stiffness, 0, 1); if (typeof options.damping === "number") __privateGet(this, _damping).v = clamp(options.damping, 0, 1); if (typeof options.precision === "number") __privateGet(this, _precision).v = options.precision; } /** * Create a spring whose value is bound to the return value of `fn`. This must be called * inside an effect root (for example, during component initialisation). * * ```svelte *