feat: implement @idraw/core is and check static attributes

This commit is contained in:
chenshenhai 2021-06-17 11:00:28 +08:00
parent 1f4ea809e1
commit a8b54bf34d
3 changed files with 12 additions and 9 deletions

View file

@ -1,6 +1,10 @@
export const elementTypes = {
'text': true,
'rect': true,
'image': true,
'svg': true,
}
const elementTypes = {
'text': {}, // TODO
'rect': {}, // TODO
'image': {}, // TODO
'svg': {}, // TODO
}
export const elementNames = Object.keys(elementTypes);

View file

@ -74,7 +74,6 @@ function fontFamily(value: any) {
return typeof value === 'string' && value.length > 0;
}
const is = {
x, y, w, h, angle, number,
borderWidth, borderRadius, color,

View file

@ -1,5 +1,5 @@
import { TypeData, TypeElement, TypeElemDesc } from '@idraw/types';
import { elementTypes } from './../constant/element';
import { elementNames } from './../constant/element';
export function parseData(data: any): TypeData {
const result: TypeData = {
@ -24,7 +24,7 @@ function isElement(
if (!(isNumber(elem.x) && isNumber(elem.y) && isNumber(elem.w) && isNumber(elem.h))) {
return false;
}
if (!(typeof elem.type === 'string' && Object.keys(elementTypes).includes(elem.type))) {
if (!(typeof elem.type === 'string' && elementNames.includes(elem.type))) {
return false;
}
return true;