export const svgAttrs = (deg = 45) => { const anglePI = deg * (Math.PI / 180) const attrs = { // prettier-ignore x1: `${Math.round(50 + (Math.sin(anglePI) * 50))}%`, // prettier-ignore y1: `${Math.round(50 + (Math.cos(anglePI) * 50))}%`, // prettier-ignore x2: `${Math.round(50 + (Math.sin(anglePI + Math.PI) * 50))}%`, // prettier-ignore y2: `${Math.round(50 + (Math.cos(anglePI + Math.PI) * 50))}%` } return Object.entries(attrs) .map(([k, v]) => `${k}="${v}"`) .join(' ') } export const percents = (value: T, i: number, a: T[]) => [ ((i / (a.length - 1)) * 100) | 0, value, ] export const indent = (lines = '', tab = ' ') => lines .split('\n') .map(line => `${tab}${line}`) .join('\n') import C from 'color' export const validColor = (input: string) => { if (!String(input) || input === 'undefined') { return null } if (input.trim().startsWith('var(')) { return input.trim() } try { return C(input) .rgb() .string() } catch (e) { // console.log(e.message) return null } } export type Escape = (s: string) => string export const tokens = (line: string[] | string): string[] => typeof line === 'string' ? line.split(/\s/) : line export const esc: Escape = s => `${s}` export const join = (...args: Array) => args.filter(x => String(x)).join('-') export const trim = (s: string) => s.trim()