import { getCdnCssUrl , parseVersion } from './url' ; function createStylesheetLink ( href ) { const link = document . createElement ( 'link' ) ; link . rel = 'stylesheet' ; link . href = href ; return link ; } function insertLink ( link , before ? ) { if ( before ) { const beforeNode = document . querySelector ( before ) ; beforeNode . parentNode . insertBefore ( link , beforeNode ) ; } else { document . head . appendChild ( link ) ; } } function getCss ( url ) { return document . querySelector ( `link[href*="${ url }"]` ) as HTMLLinkElement ; } function getCssUrl ( urlOrVersion ? ) { return ! urlOrVersion || parseVersion ( urlOrVersion ) ? getCdnCssUrl ( urlOrVersion ) : urlOrVersion ; } export function loadCss ( urlOrVersion ? , before ? ) { const url = getCssUrl ( urlOrVersion ) ; let link = getCss ( url ) ; if ( ! link ) { link = createStylesheetLink ( url ) ; insertLink ( link , before ) ; } return link ; }