refactor all components and isolated from ART dependency

This commit is contained in:
Horcrux
2016-04-20 00:52:59 +08:00
parent c8a04c3d28
commit d700ca5493
81 changed files with 2993 additions and 1437 deletions

90
lib/attributes.js Normal file
View File

@@ -0,0 +1,90 @@
function arrayDiffer(a, b) {
if (a == null) {
return true;
}
if (a.length !== b.length) {
return true;
}
for (var i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return true;
}
}
return false;
}
function fontAndLinesDiffer(a, b) {
if (a === b) {
return false;
}
if (a.font !== b.font) {
if (a.font === null) {
return true;
}
if (b.font === null) {
return true;
}
if (
a.font.fontFamily !== b.font.fontFamily ||
a.font.fontSize !== b.font.fontSize ||
a.font.fontWeight !== b.font.fontWeight ||
a.font.fontStyle !== b.font.fontStyle
) {
return true;
}
}
return arrayDiffer(a.lines, b.lines);
}
var NodeAttributes = {
transform: {
diff: arrayDiffer
},
opacity: true
};
var GroupAttributes = Object.assign({
clipping: {
diff: arrayDiffer
}
}, NodeAttributes);
var RenderableAttributes = Object.assign({
fill: {
diff: arrayDiffer
},
stroke: {
diff: arrayDiffer
},
strokeWidth: true,
strokeCap: true,
strokeJoin: true,
strokeDash: {
diff: arrayDiffer
}
}, NodeAttributes);
var PathAttributes = Object.assign({
d: {
diff: arrayDiffer
}
}, RenderableAttributes);
var TextAttributes = Object.assign({
alignment: true,
frame: {
diff: fontAndLinesDiffer
},
path: {
diff: arrayDiffer
}
}, RenderableAttributes);
export {
GroupAttributes,
PathAttributes,
TextAttributes
}