fix: _h2r parses rgb() strings to prevent NaN in canvas gradients

_darken3D / _lighten3D return 'rgb(r,g,b)' CSS strings.
When those values were passed as colList to drawCylinder/drawSphere,
_cylGrad called _lighten3D(col) → _h2r('rgb(...)') → parseInt('rg',16)=NaN,
causing addColorStop to throw and killing ALL pillar/tower/sphere buoy symbols.

Fix: _h2r now detects the 'rgb(' prefix and extracts the three integers
via regex before falling through to the existing hex path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-30 16:00:14 -04:00
parent a64a5eb735
commit acd3330bcd
+6 -2
View File
@@ -352,8 +352,12 @@ function _tmX(ctx, cx, cy, r, col) {
}
// ── True-3D colour helpers ────────────────────────────────────────────────
function _h2r(hex) { // hex → [r,g,b]
hex = hex.replace('#','');
function _h2r(hex) { // hex or rgb() → [r,g,b]
if (typeof hex === 'string' && hex.startsWith('rgb')) {
const m = hex.match(/\d+/g);
return m ? [+m[0], +m[1], +m[2]] : [0, 0, 0];
}
hex = (hex || '').replace('#','');
if (hex.length === 3) hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
return [parseInt(hex.slice(0,2),16), parseInt(hex.slice(2,4),16), parseInt(hex.slice(4,6),16)];
}