Add further validation to encodeStates.
This commit is contained in:
parent
82c3ea2b90
commit
41fafae501
1 changed files with 8 additions and 1 deletions
|
|
@ -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 };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue