use-scroll-animate 5.0.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10169,19 +10169,23 @@ function bindEffect(el, name, options = {}) {
10169
10169
  if (!def)
10170
10170
  throw new Error(`[use-scroll-animate] unknown effect "${name}"`);
10171
10171
  const offs = [];
10172
+ let current = null;
10172
10173
  const fire = (e) => {
10173
- if (trigger === 'loop' || def.kind === 'loop' || def.kind === 'background' || def.kind === 'cursor') {
10174
- const ctx = context(e);
10175
- if (ctx.reduced && (def.reduced ?? 'skip') === 'skip')
10176
- return;
10177
- const out = def.run(el, { ...(def.defaults || {}), ...opts }, ctx);
10178
- if (typeof out === 'function')
10179
- offs.push(out);
10180
- offs.push(...ctx.cleanups);
10174
+ const ctx = context(e);
10175
+ if (ctx.reduced && (def.reduced ?? (SKIP_BY_DEFAULT.includes(def.kind) ? 'skip' : 'run')) === 'skip')
10181
10176
  return;
10182
- }
10183
- void playEffect(el, name, opts, e).catch(() => undefined);
10177
+ // A persistent effect (returns a cleanup) replaces its previous run instead of stacking.
10178
+ current?.();
10179
+ current = null;
10180
+ const out = def.run(el, { ...(def.defaults || {}), ...opts }, ctx);
10181
+ const stops = [...ctx.cleanups, ...(typeof out === 'function' ? [out] : [])];
10182
+ if (stops.length)
10183
+ current = () => stops.splice(0).forEach((f) => f());
10184
10184
  };
10185
+ offs.push(() => {
10186
+ current?.();
10187
+ current = null;
10188
+ });
10185
10189
  const on = (type, opt) => {
10186
10190
  el.addEventListener(type, fire, opt);
10187
10191
  offs.push(() => el.removeEventListener(type, fire, opt));