import React from 'react' import { Property } from 'csstype' import { ScriptNameType, getFontForScript } from '../configuration/font' import C from '../classes' import tone from '@wavebond/tone' import _ from 'lodash' export type ColorType = | 'red' | 'purple' | 'green' | 'blue' | 'yellow' | 'black' | 'white' type TypeType = { align?: Property.TextAlign block?: boolean bold?: boolean direction?: Property.Direction | undefined size?: number text?: React.ReactNode title?: string script?: ScriptNameType style?: string fontFamily?: string className?: string color?: ColorType indent?: number lineHeight?: number } type SpanType = TypeType & { children: React.ReactNode style: string script: ScriptNameType fontFamily?: string } function Span({ children, script, style, size, fontFamily, ...props }: SpanType) { const c = getCSSClassList(props) const fontData = getFontForScript({ script, style }) const indent: Record = {} if (props.indent) { indent.paddingLeft = props.indent indent.textIndent = -props.indent } return ( {children} ) } export function getCSSClassList(props: TypeType) { const c = [C.breakWord] switch (props.align) { case 'right': c.push(C.textRight) break } if (props.direction === 'rtl') { c.push(C.rtl) } if (props.bold) { c.push(C.fontBold) } if (props.block) { c.push(C.displayBlock) } if (props.className) { c.push(props.className) } switch (props.color) { case 'red': c.push(C.textFillRed) break case 'yellow': c.push(C.textFillYellow) break case 'green': c.push(C.textFillGreen) break case 'blue': c.push(C.textFillBlue) break case 'purple': c.push(C.textFillPurple) break case 'black': c.push(C.textFillDark) break case 'white': c.push(C.textFillLight) break } return c } export function adjustFontSize({ script, size, }: { script?: string size: number }) { switch (script) { case 'amharic': return _.round(size * 1.4, 2) case 'arabic': return _.round(size * 1.4, 2) case 'armenian': return _.round(size * 1.4, 2) case 'bengali': return _.round(size * 1.4, 2) case 'chinese': return _.round(size * 1.4, 2) case 'cuneiform': return _.round(size * 1.4, 2) case 'devanagari': return _.round(size * 1.4, 2) case 'egyptian': return _.round(size * 1.4, 2) case 'georgian': return _.round(size * 1.4, 2) case 'gujarati': return _.round(size * 1.4, 2) case 'gurmukhi': return _.round(size * 1.4, 2) case 'hebrew': return _.round(size * 1.4, 2) case 'canadian': return _.round(size * 1.4, 2) case 'japanese': return _.round(size * 1.4, 2) case 'kannada': return _.round(size * 1.4, 2) case 'khmer': return _.round(size * 1.4, 2) case 'korean': return _.round(size * 1.4, 2) case 'latin': return _.round(size, 2) case 'malayalam': return _.round(size * 1.4, 2) case 'oriya': return _.round(size * 1.4, 2) case 'runic': return _.round(size * 1.4, 2) case 'sanskrit': return _.round(size * 1.4, 2) case 'sinhala': return _.round(size * 1.4, 2) case 'syriac': return _.round(size * 1.4, 2) case 'tamil': return _.round(size * 1.4, 2) case 'telugu': return _.round(size * 1.4, 2) case 'thai': return _.round(size * 1.4, 2) case 'tibetan': return _.round(size * 1.4, 2) case 'tone': return _.round(size * 1.4, 2) default: return _.round(size, 2) } } export default function Type({ script = 'latin', style = 'modern', fontFamily, text, ...props }: TypeType) { if (script === 'tone') { try { text = tone.make(text as string) } catch (e) { text = '' } } return ( {text} ) }