Files
Maxim Dolgolyov 6afe928c0d feat(labs): visual polish wave — LabFX foundation + 33 sims juiced up
ФУНДАМЕНТ (4 новых файла):
- _fx_core.js: LabFX namespace, glow.drawGlow, glow.pulse, haptic, shake
- _fx_particles.js: пул 1500 объектов, 6 shapes (dot/spark/ring/smoke/splash/dust)
- _fx_motion.js: tween + 12 easings + critically-damped spring
- _fx_sound.js: 9 procedural synth-звуков (click/tick/whoosh/chime/fizz/spark/bounce/pour/drone), Web Audio API
- Sound toggle в шапке lab.html с localStorage-persist

UX МИКРО (CSS + JS):
- Button states: hover scale+brightness, active scale-down, disabled grayscale
- Slider polish: custom thumb с тенью, filled-track gradient, hover/active
- Focus rings через :focus-visible
- Tooltip system .tt-host data-tt= с 400ms hover, fade-in
- Marching ants для selection
- Loading skeleton с shimmer
- Empty state .sim-empty-* паттерн
- Toast: progress bar внизу, icons по типу
- Cursor states utility classes
- View Transitions API для smooth sim-switch, fallback на CSS fade

PHASE 2 — визуальные эффекты для 33 симуляций:

Physics motion: projectile (launch whoosh + landing splash/shake/haptic + target chime), pendulum (max-extension tick + bob glow), collision (bounce + sparks + shake), angrybirds (whoosh/bounce/fizz/chime + confetti), newton (rocket flame trail + scene transitions), forcesandbox (spring glow + impact sparks)

Physics fields: emfield (field-lines glow + particle trail + lightning при high field + Gauss-drag haptic + rod motion sparks), circuit (energized-wire glow ∝ current + LED bloom + short-circuit shake/spark + heat shimmer smoke + place/erase/switch sounds), opticsbench (beam glow на всех режимах + caustics dust у фокуса + TIR/Brewster one-shot sounds)

Thermo+waves: waves (mode-switch whoosh + Mach-cone particles + spectrum harmonic chime + waveform glow), hydrostatics (pour sound + splash при погружении + valve click), isoprocess (PV-trail dust), heatengine (drone цикла + hot/cold reservoir smoke/dust + phase-change ticks), radioactive (Geiger tick throttle + decay sparks + half-life chime + α/β/γ glow)

Chemistry: chemsandbox (pour splash + fizz bubbles/dust/spark по типу реакции + shake при горении), equilibrium/electrolysis/reactions/titration/flask/ionexchange/redox (pour/fizz/spark/chime по событиям, частицы при ключевых моментах), stoichiometry (fizz bubbles + recipe-change click)

Math+geom: geometry (tool-click + object-create tick + locus glow + challenge confetti via LabFX + haptic), triangle (vertex-drop tick + special-point glow), stereo (figure-change whoosh + cross-section chime, no particles — Three.js), trigcircle (drag-haptic + pitch∝angle tick + sin/cos glow), graph/graphtransform/quadratic (slider-tick throttled + curve glow + discriminant-cross chime), probability (bounce + finish-chime burst), normaldist (pulsing shade + bell glow)

Bio+misc: celldivision (phase-change whoosh + prophase dust + anaphase poles spark + cytokinesis chime), photosynthesis (photon tick + ATP chime + glucose sparkle), bohratom (electron-jump chime ∝ levels + photon spark), orbitals/crystal (mode-change whoosh — Three.js, sound only), logic (gate-place + wire-connect + LED bloom + HIGH wire flowing dots + preset chime), gas/brownian/diffusion/states (preset whoosh, throttled tick по событиям)

Все LabFX вызовы обёрнуты в if (window.LabFX) guard — graceful degradation если фундамент не загружен. 47 JS файлов прошли syntax check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 13:58:49 +03:00

154 lines
5.1 KiB
JavaScript

'use strict';
(function(global) {
global.LabFX = global.LabFX || {};
/* ─────────────────────────────────────────────
EASINGS — standard Penner equations
───────────────────────────────────────────── */
var easings = {
linear: function(t) { return t; },
easeInQuad: function(t) { return t * t; },
easeOutQuad: function(t) { return t * (2 - t); },
easeInOutQuad: function(t) { return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t; },
easeInCubic: function(t) { return t * t * t; },
easeOutCubic: function(t) { var u = t - 1; return u * u * u + 1; },
easeInOutCubic: function(t) {
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
},
easeInOutQuint: function(t) {
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * (--t) * t * t * t * t;
},
easeOutBack: function(t) {
var c1 = 1.70158;
var c3 = c1 + 1;
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
},
easeOutElastic: function(t) {
if (t === 0 || t === 1) return t;
var c4 = (2 * Math.PI) / 3;
return Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
},
easeInExpo: function(t) { return t === 0 ? 0 : Math.pow(2, 10 * t - 10); },
easeOutExpo: function(t) { return t === 1 ? 1 : 1 - Math.pow(2, -10 * t); }
};
/* ─────────────────────────────────────────────
TWEEN
───────────────────────────────────────────── */
/**
* Tween a numeric value from `from` to `to` over `durMs` milliseconds.
*
* @param {number} from
* @param {number} to
* @param {number} durMs
* @param {function|string} easing - easing fn or key in LabFX.motion.easings
* @param {function} onUpdate - called with current value each frame
* @param {function} [onDone]
* @returns {{ cancel: function, running: boolean }}
*/
function tween(from, to, durMs, easing, onUpdate, onDone) {
var easeFn = (typeof easing === 'function')
? easing
: (easings[easing] || easings.linear);
var start = null;
var handle = { running: true, cancel: null };
var rafId;
function step(now) {
if (!handle.running) return;
if (start === null) start = now;
var elapsed = now - start;
var progress = Math.min(elapsed / durMs, 1);
var value = from + (to - from) * easeFn(progress);
onUpdate(value);
if (progress < 1) {
rafId = requestAnimationFrame(step);
} else {
handle.running = false;
if (typeof onDone === 'function') onDone();
}
}
handle.cancel = function() {
handle.running = false;
cancelAnimationFrame(rafId);
};
rafId = requestAnimationFrame(step);
return handle;
}
/* ─────────────────────────────────────────────
SPRING (critically-damped simulation)
───────────────────────────────────────────── */
/**
* Returns a spring factory.
* Usage: LabFX.motion.spring(170, 26)(from, to, onUpdate, onDone) → handle
*
* @param {number} stiffness (default 170)
* @param {number} damping (default 26)
*/
function springFactory(stiffness, damping) {
stiffness = stiffness != null ? stiffness : 170;
damping = damping != null ? damping : 26;
return function(from, to, onUpdate, onDone) {
var pos = from;
var vel = 0;
var prev = null;
var handle = { running: true, cancel: null };
var rafId;
function step(now) {
if (!handle.running) return;
if (prev === null) { prev = now; }
var dt = Math.min((now - prev) / 1000, 0.05); /* cap at 50ms */
prev = now;
var force = -stiffness * (pos - to) - damping * vel;
vel += force * dt;
pos += vel * dt;
onUpdate(pos);
var settled = Math.abs(pos - to) < 0.01 && Math.abs(vel) < 0.01;
if (!settled) {
rafId = requestAnimationFrame(step);
} else {
onUpdate(to);
handle.running = false;
if (typeof onDone === 'function') onDone();
}
}
handle.cancel = function() {
handle.running = false;
cancelAnimationFrame(rafId);
};
rafId = requestAnimationFrame(step);
return handle;
};
}
/* ─────────────────────────────────────────────
EXPORT
───────────────────────────────────────────── */
global.LabFX.motion = {
tween: tween,
spring: springFactory,
easings: easings
};
})(window);