Add further validation to encodeStates.

This commit is contained in:
Yaro Kasear 2026-01-14 11:12:38 -06:00
parent 82c3ea2b90
commit 41fafae501

View file

@ -290,11 +290,18 @@ function initGridWidget(root, opts = {}) {
function encodeStates(shapes) { function encodeStates(shapes) {
return shapes.map(shape => { return shapes.map(shape => {
if (shape.type !== 'stateChange') return shape; if (shape.type !== 'stateChange') return shape;
const re = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
let newShape = {}; let newShape = {};
Object.keys(shape).forEach(key => { Object.keys(shape).forEach(key => {
if (key === 'strokeOpacity' || key === 'strokeWidth' || key === 'fillOpacity') { if (key === 'strokeOpacity' || key === 'strokeWidth' || key === 'fillOpacity') {
newShape[key] = Math.round(shape[key] * 100); const v = Number(shape[key]);
if (Number.isFinite(v))
newShape[key] = Math.round(v * 100);
} else if (key === 'color') {
newShape[key] = re.test(shape[key]) ? shape[key] : '#000000';
} else if (key === 'fill') {
newShape[key] = !!shape[key];
} }
}); });
return { ...shape, ...newShape }; return { ...shape, ...newShape };