mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-21 06:15:15 +00:00
Run Prettier, configure ESLint.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import _ from 'lodash';
|
||||
import _ from "lodash";
|
||||
//noinspection JSUnresolvedVariable
|
||||
import React, {Children} from 'react';
|
||||
import TSpan from '../../elements/TSpan';
|
||||
import extractLengthList from './extractLengthList';
|
||||
import React, { Children } from "react";
|
||||
import TSpan from "../../elements/TSpan";
|
||||
import extractLengthList from "./extractLengthList";
|
||||
|
||||
const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?[ptexm%])*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
|
||||
const fontFamilyPrefix = /^[\s"']*/;
|
||||
@@ -15,9 +15,12 @@ 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;
|
||||
return fontFamilyString
|
||||
? fontFamilyString
|
||||
.split(commaReg)[0]
|
||||
.replace(fontFamilyPrefix, "")
|
||||
.replace(fontFamilySuffix, "")
|
||||
: null;
|
||||
}
|
||||
|
||||
function parseFontString(font) {
|
||||
@@ -29,16 +32,16 @@ function parseFontString(font) {
|
||||
return null;
|
||||
}
|
||||
const fontFamily = extractSingleFontFamily(match[3]);
|
||||
const fontSize = match[2] || '12';
|
||||
const fontSize = match[2] || "12";
|
||||
const isBold = /bold/.exec(match[1]);
|
||||
const isItalic = /italic/.exec(match[1]);
|
||||
const fontWeight = isBold ? 'bold' : 'normal';
|
||||
const fontStyle = isItalic ? 'italic' : 'normal';
|
||||
const fontWeight = isBold ? "bold" : "normal";
|
||||
const fontStyle = isItalic ? "italic" : "normal";
|
||||
cachedFontObjectsFromString[font] = {
|
||||
fontSize,
|
||||
fontFamily,
|
||||
fontWeight,
|
||||
fontStyle,
|
||||
fontStyle
|
||||
};
|
||||
return cachedFontObjectsFromString[font];
|
||||
}
|
||||
@@ -56,35 +59,34 @@ export function extractFont(props) {
|
||||
wordSpacing,
|
||||
kerning,
|
||||
fontVariantLigatures,
|
||||
fontFeatureSettings,
|
||||
} = props;
|
||||
let {
|
||||
fontSize,
|
||||
fontFamily,
|
||||
font,
|
||||
fontFeatureSettings
|
||||
} = props;
|
||||
let { fontSize, fontFamily, font } = props;
|
||||
|
||||
fontFamily = extractSingleFontFamily(fontFamily);
|
||||
fontSize = fontSize ? '' + fontSize : null;
|
||||
fontSize = fontSize ? "" + fontSize : null;
|
||||
|
||||
const ownedFont = _.pickBy({
|
||||
fontData,
|
||||
fontStyle,
|
||||
fontVariant,
|
||||
fontWeight,
|
||||
fontStretch,
|
||||
fontSize,
|
||||
fontFamily,
|
||||
textAnchor,
|
||||
textDecoration,
|
||||
letterSpacing,
|
||||
wordSpacing,
|
||||
kerning,
|
||||
fontVariantLigatures,
|
||||
fontFeatureSettings,
|
||||
}, prop => !_.isNil(prop));
|
||||
const ownedFont = _.pickBy(
|
||||
{
|
||||
fontData,
|
||||
fontStyle,
|
||||
fontVariant,
|
||||
fontWeight,
|
||||
fontStretch,
|
||||
fontSize,
|
||||
fontFamily,
|
||||
textAnchor,
|
||||
textDecoration,
|
||||
letterSpacing,
|
||||
wordSpacing,
|
||||
kerning,
|
||||
fontVariantLigatures,
|
||||
fontFeatureSettings
|
||||
},
|
||||
prop => !_.isNil(prop)
|
||||
);
|
||||
|
||||
if (typeof font === 'string') {
|
||||
if (typeof font === "string") {
|
||||
font = parseFontString(font);
|
||||
}
|
||||
|
||||
@@ -99,12 +101,9 @@ export default function(props, container) {
|
||||
dy,
|
||||
alignmentBaseline,
|
||||
baselineShift,
|
||||
verticalAlign,
|
||||
} = props;
|
||||
let {
|
||||
rotate,
|
||||
children
|
||||
verticalAlign
|
||||
} = props;
|
||||
let { rotate, children } = props;
|
||||
|
||||
const positionX = extractLengthList(x);
|
||||
const positionY = extractLengthList(y);
|
||||
@@ -113,7 +112,7 @@ export default function(props, container) {
|
||||
rotate = extractLengthList(rotate);
|
||||
|
||||
let content = null;
|
||||
if (typeof children === 'string' || typeof children === 'number') {
|
||||
if (typeof children === "string" || typeof children === "number") {
|
||||
const childrenString = children.toString();
|
||||
if (container) {
|
||||
children = <TSpan>{childrenString}</TSpan>;
|
||||
@@ -123,7 +122,7 @@ export default function(props, container) {
|
||||
}
|
||||
} else if (Children.count(children) > 1 || Array.isArray(children)) {
|
||||
children = Children.map(children, child => {
|
||||
if (typeof child === 'string' || typeof child === 'number') {
|
||||
if (typeof child === "string" || typeof child === "number") {
|
||||
return <TSpan>{child.toString()}</TSpan>;
|
||||
} else {
|
||||
return child;
|
||||
@@ -144,6 +143,6 @@ export default function(props, container) {
|
||||
deltaY,
|
||||
alignmentBaseline,
|
||||
baselineShift,
|
||||
verticalAlign,
|
||||
verticalAlign
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user