import * as React from "react"; import styled from '@emotion/styled'; import { color, ColorInput } from "./color.js"; import { Theme } from "./default-theme.js"; export interface WordProps { inverse?: boolean; bg?: boolean; bold?: boolean; underline?: boolean; fg?: string | number; children: string; x: number; y: number; theme: { fontSize: number; lineHeight: number; }; } export const Word: React.FunctionComponent = props => { return ( <> {(props.inverse || props.bg) && ( 0 ? props.children.length : 0} x={props.x} y={props.y - props.theme.fontSize} /> )} {props.children} ); }; const BG_FILL = (props: any) => props.inverse ? fg(props, props.theme) : bg(props, props.theme); const TEXT_FILL = (props: any) => props.inverse ? bg(props, props.theme) : fg(props, props.theme); const DECORATION = (props: any) => (props.underline ? "underline" : null); const FONT_WEIGHT = (props: any) => (props.bold ? "bold" : null); const StyledWordBackground = styled.rect` fill: ${BG_FILL}; `; const StyledWord = styled.text` fill: ${TEXT_FILL}; text-decoration: ${DECORATION}; font-weight: ${FONT_WEIGHT}; white-space: pre; `; function bg(props: any, theme: any) { const b = typeof props.bg === "undefined" ? theme.background : props.bg; return color(b, theme, theme.background); } function fg(props: any, theme: any) { const d = props.bold ? theme.bold : theme.text; // Bold takes precedence if fg is undefined or 0 if (props.bold && !props.fg) { return color(theme.bold, theme); } const f = typeof props.fg === "undefined" ? d : props.fg; return color(f, theme, d); }