'use strict'; /** * Easing curves matching Qt QEasingCurve defaults (the same values Tim's * KWin Click Tween effect uses). Formulas and default parameters come from * Qt 6's QEasingCurve and https://easings.net/. * * Source of the click/release defaults: * /workspace/click-tween/settings.h (clickTime, releaseTime, easing names) * /workspace/click-tween/clicktween.cpp (press scale 0.8, release scale 1.0) * /workspace/click-tween/README.md */ /** Qt QEasingCurve default overshoot for InBack / OutBack / InOutBack. */ var BACK_OVERSHOOT = 1.70158; /** Qt QEasingCurve default period and amplitude for Elastic curves. */ var ELASTIC_PERIOD = 0.3; var ELASTIC_AMPLITUDE = 1.0; function clamp01 (t) { if (t <= 0) { return 0; } if (t >= 1) { return 1; } return t; } /** easeOutBack: overshoots the end value, then settles. Qt / easings.net. */ function easeOutBack (t) { t = clamp01(t); var c1 = BACK_OVERSHOOT; var c3 = c1 + 1; var u = t - 1; return 1 + c3 * u * u * u + c1 * u * u; } /** * easeOutElastic: decaying sine overshoot past the end value. * Qt default amplitude 1, period 0.3 (equivalent to easings.net). */ function easeOutElastic (t) { t = clamp01(t); if (t === 0 || t === 1) { return t; } var p = ELASTIC_PERIOD; var s = p / 4; return Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1; } /** easeOutCubic: 1 − (1−t)³. Smooth, no overshoot (easings.net). */ function easeOutCubic (t) { t = clamp01(t); var u = 1 - t; return 1 - u * u * u; } function tween (from, to, t, ease) { return from + (to - from) * ease(clamp01(t)); } /** * Visual-only block swap tween (t1121). Game logic and the grid update * immediately; this only moves the displaced sprite. 100 ms sits in the * requested 80–120 ms range. */ var SWAP_TWEEN = { duration: 0.100, ease: easeOutCubic }; /** * DEFAULT settings of Tim's KWin Click Tween * (git.timfalken.com/timfa/click-tween). * * Press: shrink to 80% in 150 ms with easeOutBack, stay at 80% while held. * Release: grow back to 100% in 720 ms with easeOutElastic. * Mid-animation release starts from the current scale, like QVariantAnimation. */ var CLICK_TWEEN = { pressScale: 0.8, releaseScale: 1.0, pressDuration: 0.150, releaseDuration: 0.720, pressEase: easeOutBack, releaseEase: easeOutElastic, backOvershoot: BACK_OVERSHOOT, elasticPeriod: ELASTIC_PERIOD, elasticAmplitude: ELASTIC_AMPLITUDE, source: 'click-tween settings.h + clicktween.cpp (Qt QEasingCurve defaults)' }; /** * Visual landing bounce, u in 0..1. Subtle squash with a slight stretch * on the other axis and a tiny upward rebound (in tiles, visual only). */ function bouncePose (u, squash) { if (u <= 0 || u >= 1) { return { sx: 1, sy: 1, dy: 0 }; } var wave = Math.sin(Math.PI * u); return { sx: 1 + squash * 0.6 * wave, sy: 1 - squash * wave, dy: 0.07 * wave * (1 - u) }; } var Easing = { BACK_OVERSHOOT: BACK_OVERSHOOT, ELASTIC_PERIOD: ELASTIC_PERIOD, ELASTIC_AMPLITUDE: ELASTIC_AMPLITUDE, easeOutBack: easeOutBack, easeOutElastic: easeOutElastic, easeOutCubic: easeOutCubic, tween: tween, CLICK_TWEEN: CLICK_TWEEN, SWAP_TWEEN: SWAP_TWEEN, clamp01: clamp01, bouncePose: bouncePose }; if (typeof module !== 'undefined' && module.exports) { module.exports = Easing; } else if (typeof globalThis !== 'undefined') { globalThis.Easing = Easing; }