clean up unused code

This commit is contained in:
Horcrux
2016-09-17 09:49:28 +08:00
parent 09c5b10f02
commit d549f6ca9c
18 changed files with 142 additions and 288 deletions
-21
View File
@@ -1,21 +0,0 @@
import extractSpan from './extractSpan';
import extractTextContent from './extractTextContent';
export default function (props) {
let {children, line} = props;
let extractedProps = extractSpan(props);
if (typeof children === 'string') {
line = children;
children = null;
} else {
children = extractTextContent(props.children);
line = null;
}
console.log(extractedProps);
return {
...extractedProps,
children,
line
};
};
-71
View File
@@ -1,71 +0,0 @@
import extractTextContent from './extractTextContent';
import SerializablePath from '../SerializablePath';
import _ from 'lodash';
const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm%]*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
const fontFamilyPrefix = /^[\s"']*/;
const fontFamilySuffix = /[\s"']*$/;
const spaceReg = /\s+/;
const commaReg = /,/;
let cachedFontObjectsFromString = {};
function extractSingleFontFamily(fontFamilyString) {
// SVG on the web allows for multiple font-families to be specified.
// For compatibility, we extract the first font-family, hoping
// we'll get a match.
return fontFamilyString ? fontFamilyString.split(commaReg)[0]
.replace(fontFamilyPrefix, '')
.replace(fontFamilySuffix, '') : null;
}
function parseFontString(font) {
if (cachedFontObjectsFromString.hasOwnProperty(font)) {
return cachedFontObjectsFromString[font];
}
let match = fontRegExp.exec(font);
if (!match) {
return null;
}
let fontFamily = extractSingleFontFamily(match[3]);
let fontSize = +match[2] || 12;
let isBold = /bold/.exec(match[1]);
let isItalic = /italic/.exec(match[1]);
cachedFontObjectsFromString[font] = {
fontFamily: fontFamily,
fontSize: fontSize,
fontWeight: isBold ? 'bold' : 'normal',
fontStyle: isItalic ? 'italic' : 'normal'
};
return cachedFontObjectsFromString[font];
}
function extractFont(props) {
let font = props.font;
let fontSize = +props.fontSize;
let ownedFont = {
fontFamily: extractSingleFontFamily(props.fontFamily),
fontSize: isNaN(fontSize) ? null : fontSize,
fontWeight: props.fontWeight,
fontStyle: props.fontStyle
};
if (typeof props.font === 'string') {
font = parseFontString(props.font);
}
ownedFont = _.pickBy(ownedFont, prop => !_.isNil(prop));
return _.defaults(ownedFont, font);
}
function parseDelta(delta) {
return delta.toString().split(spaceReg);
}
export default function(props) {
return {
dx: parseDelta(props.dx || ''),
dy: parseDelta(props.dy || ''),
...extractFont(props)
};
}
+4 -3
View File
@@ -209,9 +209,10 @@ export default function(props) {
...extractFont(frame.props)
}
};
return <Span {...spanProps} />
})
// TODO: format children
return <Span {...spanProps} />;
});
return {
alignment,
children
-26
View File
@@ -1,26 +0,0 @@
import React, {
Children
} from 'react';
import TSpan from '../../elements/TSpan';
const newLine = /\n/g;
export default function(children) {
let spans = [];
Children.forEach(children, function (child = '') {
let span;
if (typeof child === 'string') {
span = <TSpan>{child.replace(newLine, ' ')}</TSpan>;
} else if (child.type === TSpan) {
span = child;
} else {
// give warning about the illegal child type
return;
}
spans.push(span);
});
return spans;
}