From 8303d483cc0949b98dceee5089ae548a0902642f Mon Sep 17 00:00:00 2001 From: Maxim Dolgolyov Date: Wed, 24 Jun 2026 19:31:35 +0300 Subject: [PATCH] =?UTF-8?q?fix(labs):=20SVG-=D1=81=D1=82=D1=80=D0=B5=D0=BB?= =?UTF-8?q?=D0=BA=D0=B8=20=D1=83=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=B0=D0=BB=D0=B8=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BA=D0=B0=D0=BA=20=D1=81=D1=8B=D1=80=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=81=D1=82=20=D0=BD=D0=B0=20canvas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Уравнения реакций содержат inline стрелки. На canvas (fillText) разметка показывалась буквально. Добавлен общий хелпер ChemVisuals.cleanIcons (SVG→Unicode →/↑/↓), применён в flask (eq), redox (s.txt) и chemsandbox (ответ квиза — был единственный незакрытый путь мимо _csClean). Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/js/labs/_chem_visuals.js | 13 +++++++++++++ frontend/js/labs/chemsandbox.js | 2 +- frontend/js/labs/flask.js | 2 +- frontend/js/labs/redox.js | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/js/labs/_chem_visuals.js b/frontend/js/labs/_chem_visuals.js index 6947bc2..b4bd2e3 100644 --- a/frontend/js/labs/_chem_visuals.js +++ b/frontend/js/labs/_chem_visuals.js @@ -760,8 +760,21 @@ window.ChemVisuals = (() => { return hex; } + /* Replace inline icon-SVG (reaction arrows) with Unicode for canvas fillText. + Canvas draws plain strings — embedded markup would show as raw text. */ + function cleanIcons(s) { + if (!s || !s.includes('/g, m => { + if (m.includes('x1="5" y1="12" x2="19"')) return '→'; // right arrow + if (m.includes('x1="12" y1="5" x2="12" y2="19"')) return '↓'; // down (precipitate) + if (m.includes('x1="12" y1="19" x2="12" y2="5"')) return '↑'; // up (gas) + return ''; + }); + } + /* ── Public API ─────────────────────────────────────────────── */ return { + cleanIcons, drawErlenmeyer, drawBeaker, drawBurette, diff --git a/frontend/js/labs/chemsandbox.js b/frontend/js/labs/chemsandbox.js index fac1b56..6cfa481 100644 --- a/frontend/js/labs/chemsandbox.js +++ b/frontend/js/labs/chemsandbox.js @@ -1562,7 +1562,7 @@ class ChemSandboxSim { if (!isOk && this._quizTask) { ctx.font = '10px "JetBrains Mono", monospace'; ctx.fillStyle = `rgba(255,255,255,${alpha * 0.45})`; - ctx.fillText('Ответ: ' + this._quizTask.rx.eq, W / 2, bannerY + 65); + ctx.fillText('Ответ: ' + _csClean(this._quizTask.rx.eq), W / 2, bannerY + 65); } } diff --git a/frontend/js/labs/flask.js b/frontend/js/labs/flask.js index 0f8b0a9..6b6e49a 100644 --- a/frontend/js/labs/flask.js +++ b/frontend/js/labs/flask.js @@ -1146,7 +1146,7 @@ class FlaskSim { const eqY = g.cy + g.r + 26; ctx.font = '12.5px monospace'; ctx.fillStyle = 'rgba(185,215,255,0.78)'; - ctx.textAlign = 'center'; ctx.fillText(eq, W * 0.44, eqY); ctx.textAlign = 'left'; + ctx.textAlign = 'center'; ctx.fillText(ChemVisuals.cleanIcons(eq), W * 0.44, eqY); ctx.textAlign = 'left'; if (this._passiv) { ctx.font = 'bold 11px sans-serif'; ctx.fillStyle = '#FFD166'; diff --git a/frontend/js/labs/redox.js b/frontend/js/labs/redox.js index 6adf4c2..7e0e173 100644 --- a/frontend/js/labs/redox.js +++ b/frontend/js/labs/redox.js @@ -547,7 +547,7 @@ class RedoxSim { ctx.fillText(s.lbl, 14, y); ctx.fillStyle = (i === this._stepIdx && this._phase !== 'done') ? '#FFF' : 'rgba(255,255,255,0.62)'; ctx.font = '9.5px monospace'; - ctx.fillText(s.txt, 14 + ctx.measureText(s.lbl).width + 8, y); + ctx.fillText(ChemVisuals.cleanIcons(s.txt), 14 + ctx.measureText(s.lbl).width + 8, y); ctx.restore(); }