refactor: distribute lab-init.js into 34 engine files

lab-init.js: 4098 -> 543 lines (infrastructure + THEORY only)

Each sim's _open*() + UI helpers moved to its engine file:
graph.js, projectile.js, collision.js, magnetic.js, triangle.js,
geometry.js, trigcircle.js, gas.js (molphys), coulomb.js, circuit.js,
reactions.js (chemistry), newton.js (dynamics), chemsandbox.js,
celldivision.js, photosynthesis.js, angrybirds.js, quadratic.js,
normaldist.js, graphtransform.js, pendulum.js, equilibrium.js,
thinlens.js, mirror.js, isoprocess.js, titration.js, refraction.js,
probability.js, bohratom.js, electrolysis.js, waves.js,
crystal.js, orbitals.js, stereo.js, hydrostatics.js

All 34 engine files syntax-checked OK.
This commit is contained in:
Maxim Dolgolyov
2026-05-08 14:54:54 +03:00
parent d5f77bb648
commit ae31e4c4e8
35 changed files with 3657 additions and 3589 deletions
+81 -1
View File
@@ -1,4 +1,4 @@
'use strict';
'use strict';
/* ═══════════════════════════════════════════════════════════════════════
TrigCircleSim — premium interactive unit-circle + graph visualisation
@@ -967,3 +967,83 @@ class TrigCircleSim {
}
if (typeof window !== 'undefined') window.TrigCircleSim = TrigCircleSim;
/* ─── lab UI init ─────────────────────────────────── */
var trigSim = null;
function _openTrigCircle() {
document.getElementById('sim-topbar-title').textContent = 'Тригонометрическая окружность';
_simShow('sim-trigcircle');
_simShow('ctrl-trigcircle');
requestAnimationFrame(() => requestAnimationFrame(() => {
if (!trigSim) {
trigSim = new TrigCircleSim(document.getElementById('trigcircle-canvas'));
trigSim.onUpdate = _trigUpdateUI;
}
trigSim.fit();
trigSim.start();
_trigUpdateUI(trigSim.stats());
}));
}
function trigToggle(layer, rowEl) {
if (!trigSim) return;
const isActive = rowEl.classList.toggle('active');
trigSim.toggleLayer(layer, isActive);
}
function trigSetGraphFn(fn, el) {
if (!trigSim) return;
document.querySelectorAll('.trig-fn-btn').forEach(b => b.classList.remove('active'));
el.classList.add('active');
trigSim.setGraphFn(fn);
}
function trigGoTo(rad) {
if (!trigSim) return;
trigSim.goToAngle(rad);
}
function trigReset() {
if (!trigSim) return;
trigSim.setAngle(Math.PI / 4);
}
function _trigUpdateUI(s) {
const _f = v => {
if (v === undefined) return '—';
const a = Math.abs(v), sg = v < 0 ? '' : '';
if (a < 5e-4) return '0';
if (Math.abs(a - 0.5) < 1e-3) return sg + '½';
if (Math.abs(a - 1) < 1e-3) return sg + '1';
if (Math.abs(a - Math.SQRT2/2) < 1e-3) return sg + '√2/2';
if (Math.abs(a - Math.sqrt(3)/2) < 1e-3) return sg + '√3/2';
if (Math.abs(a - Math.sqrt(3)/3) < 1e-3) return sg + '√3/3';
if (Math.abs(a - Math.sqrt(3)) < 1e-3) return sg + '√3';
return v.toFixed(4);
};
const degStr = s.deg.toFixed(1) + '°';
// Panel values (nice fractions)
document.getElementById('trig-v-sin').textContent = _f(s.sin);
document.getElementById('trig-v-cos').textContent = _f(s.cos);
document.getElementById('trig-v-tan').textContent = _f(s.tan);
document.getElementById('trig-v-cot').textContent = _f(s.cot);
// Angle badge
document.getElementById('trig-angle-badge').innerHTML =
`${degStr} = ${s.radLabel}<br><span style="font-size:0.72rem;opacity:0.6">${s.angle.toFixed(4)} рад</span>`;
// Stats bar (nice fractions)
document.getElementById('trigbar-angle').textContent = degStr;
document.getElementById('trigbar-sin').textContent = _f(s.sin);
document.getElementById('trigbar-cos').textContent = _f(s.cos);
document.getElementById('trigbar-tan').textContent = _f(s.tan);
document.getElementById('trigbar-cot').textContent = _f(s.cot);
document.getElementById('trigbar-quad').textContent = ['I', 'II', 'III', 'IV'][s.quadrant - 1];
}
/* ── KaTeX live preview ── */
/** Convert user ascii expression <svg class="ic" viewBox="0 0 24 24"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg> LaTeX string for KaTeX preview */