import { raiseError } from './utilities/errors' ; import { FloatArray } from './types' ; import { parsePoints } from './operators/parsePoints' ; import { _ } from './constants' ; const selectorRegex = /^([#|\.]|path)/i ; export type IPathSource = string | SupportedElement ; type SupportedElement = SVGPathElement ; param pathSource export function convertToPathData ( pathSource ) { if ( Array . isArray ( pathSource ) ) { return { data : pathSource , stringData : _ } ; } let stringData ; if ( typeof pathSource === 'string' && selectorRegex . test ( pathSource ) ) { pathSource = document . querySelector ( pathSource ) as SupportedElement ; } else { stringData = pathSource as string ; } if ( typeof pathSource === 'string' ) { return { data : parsePoints ( pathSource ) , stringData } ; } const pathElement = pathSource as SupportedElement ; if ( pathElement . tagName . toUpperCase ( ) === 'PATH' ) { stringData = pathElement . getAttribute ( 'd' ) ; return { data : parsePoints ( stringData ) , stringData } ; } return raiseError ( 'Unsupported element ' , ( pathElement as Element ) . tagName ) ; } export interface IPathData { data : FloatArray [ ] ; stringData : string | undefined ; }