import fetch from "cross-fetch" ; export function isUri ( data ) { return /^(?:https?|data)\:/ . test ( data ) ; } export function dataUri ( mediaType , data ) { return `data:${ mediaType },${ encodeURIComponent ( data ) }` ; } export async function fetchOrDecodeDataUri ( dataOrUrl ) { if ( dataOrUrl . startsWith ( "http" ) || typeof Buffer === "undefined" ) { return fetch ( dataOrUrl ) . then ( ( res ) => res . text ( ) ) ; } if ( ! dataOrUrl . startsWith ( "data:" ) ) { throw new Error ( "Protocol not supported: " + dataOrUrl ) ; } const separator = dataOrUrl . indexOf ( "," ) ; const [ prefix , data ] = [ dataOrUrl . slice ( 0 , separator ) , dataOrUrl . slice ( separator + 1 ) , ] ; const isBase64 = prefix . includes ( ";base64" ) ; return isBase64 ? Buffer . from ( data , "base64" ) . toString ( ) : decodeURIComponent ( data ) ; } let _warned = new Map ( ) ; export function warnDeprecatedName ( oldName , newName ) { if ( ! _warned . get ( oldName ) ) { console . warn ( `${ oldName } is deprecated and will be removed in a future version, please use ${ newName } instead.` ) ; _warned . set ( oldName , true ) ; } }