Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof json.textStyle.encodedAttributes.kerning !== 'undefined') {
style.letterSpacing = json.textStyle.encodedAttributes.kerning;
}
const color = json.textStyle.encodedAttributes.MSAttributedStringColorAttribute;
style.color = `#${Math.round(color.red * 255).toString(16)}${Math.round(
color.green * 255,
).toString(16)}${Math.round(color.blue * 255).toString(16)}`;
if (color.alpha !== 1) {
style.color += `${Math.round(color.alpha * 255).toString(16)}`;
}
if (
json.textStyle.encodedAttributes.MSAttributedStringTextTransformAttribute !==
FileFormat.TextTransform.None
) {
style.textTransform =
json.textStyle.encodedAttributes.MSAttributedStringTextTransformAttribute ===
FileFormat.TextTransform.Lowercase
? 'lowercase'
: 'uppercase';
}
const font = json.textStyle.encodedAttributes.MSAttributedStringFontAttribute;
style.fontSize = font.attributes.size;
// we are cheating here, setting the name of the font instead of parsing
// the family, weight and traits. react-sketchapp will handle it nevertheless
style.fontFamily = font.attributes.name;
}
justify: FileFormat.TextHorizontalAlignment.Justified,
};
const TEXT_ALIGN_REVERSE = {
[FileFormat.TextHorizontalAlignment.Right]: 'right',
[FileFormat.TextHorizontalAlignment.Centered]: 'center',
[FileFormat.TextHorizontalAlignment.Justified]: 'justify',
};
export const TEXT_DECORATION_LINETHROUGH = {
none: 0,
'line-through': 1,
};
export const TEXT_TRANSFORM = {
uppercase: FileFormat.TextTransform.Uppercase,
lowercase: FileFormat.TextTransform.Lowercase,
initial: FileFormat.TextTransform.None,
inherit: FileFormat.TextTransform.None,
none: FileFormat.TextTransform.None,
capitalize: FileFormat.TextTransform.None,
};
// this borrows heavily from react-native's RCTFont class
// thanks y'all
// https://github.com/facebook/react-native/blob/master/React/Views/RCTFont.mm
export const FONT_STYLES = {
normal: false,
italic: true,
oblique: true,
};