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:
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict';
|
||||
/* ══════════════════════════════════════════════════════════════
|
||||
TitrationSim — acid-base titration simulation
|
||||
Strong acid (HCl) / weak acid (CH₃COOH) + strong base (NaOH)
|
||||
@@ -656,3 +656,55 @@ class TitrationSim {
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined') module.exports = TitrationSim;
|
||||
|
||||
/* ─── lab UI init ─────────────────────────────────── */
|
||||
function _openTitration() {
|
||||
document.getElementById('sim-topbar-title').textContent = 'pH и кривая титрования';
|
||||
_simShow('sim-titration');
|
||||
_registerSimState('titration', () => titrSim?.getParams(), st => titrSim?.setParams(st));
|
||||
if (_embedMode) _startStateEmit('titration');
|
||||
requestAnimationFrame(() => requestAnimationFrame(() => {
|
||||
if (!titrSim) {
|
||||
titrSim = new TitrationSim(document.getElementById('titration-canvas'));
|
||||
titrSim.onUpdate = _titrUpdateUI;
|
||||
}
|
||||
titrSim.fit();
|
||||
titrSim.reset();
|
||||
titrSim.play();
|
||||
}));
|
||||
}
|
||||
|
||||
function titrParam(name, val) {
|
||||
const v = parseFloat(val);
|
||||
const ids = { acidConc: 'titr-ac-val', baseConc: 'titr-bc-val', acidVol: 'titr-vol-val' };
|
||||
const el = document.getElementById(ids[name]);
|
||||
if (el) el.textContent = name === 'acidVol' ? v : v.toFixed(2);
|
||||
if (titrSim) titrSim.setParams({ [name]: v });
|
||||
}
|
||||
|
||||
function titrIndicator(name, btn) {
|
||||
document.querySelectorAll('.titr-ind-btn').forEach(b => b.classList.remove('active'));
|
||||
if (btn) btn.classList.add('active');
|
||||
if (titrSim) titrSim.setParams({ indicator: name });
|
||||
}
|
||||
|
||||
function titrPreset(name) {
|
||||
if (titrSim) { titrSim.preset(name); titrSim.play(); }
|
||||
const defs = { strong_strong: [0.1,0.1,50], weak_strong: [0.1,0.1,50], concentrated: [0.5,0.5,25] };
|
||||
const d = defs[name] || defs.strong_strong;
|
||||
document.getElementById('sl-titr-ac').value = d[0]; document.getElementById('titr-ac-val').textContent = d[0].toFixed(2);
|
||||
document.getElementById('sl-titr-bc').value = d[1]; document.getElementById('titr-bc-val').textContent = d[1].toFixed(2);
|
||||
document.getElementById('sl-titr-vol').value = d[2]; document.getElementById('titr-vol-val').textContent = d[2];
|
||||
}
|
||||
|
||||
function _titrUpdateUI(info) {
|
||||
const v = (id, val) => { const el = document.getElementById(id); if (el) el.textContent = val; };
|
||||
v('titrbar-v1', info.pH);
|
||||
v('titrbar-v2', info.baseAdded + ' мл');
|
||||
v('titrbar-v3', info.eqPoint + ' мл');
|
||||
const indNames = { phenolphthalein: 'Фенолф.', methyl_orange: 'Метилор.', litmus: 'Лакмус' };
|
||||
v('titrbar-v4', indNames[info.indicator] || info.indicator);
|
||||
}
|
||||
|
||||
/* ── refraction ── */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user