import { InsertedStyle } from './interface' ; export const injectStyle = ( target , name ) => { const key = `__${ name }__` ; ( window as Record < string , any > ) [ key ] ??= { } ; const insertedStyle = ( window as Record < string , any > ) [ key ] ; insertedStyle . elements ??= [ ] ; insertedStyle . targets ??= [ ] ; if ( ! insertedStyle . targets . includes ( target ) ) { insertedStyle . targets . push ( target ) ; } const inserted = { } ; insertedStyle . elements . forEach ( ( style ) => { if ( style . tagName === 'LINK' ) { try { document . head . removeChild ( style ) ; } catch ( e ) { console . warn ( e ) ; } } const key = ( style as HTMLLinkElement ) . href || style . innerText ; if ( ! inserted [ key ] ) { inserted [ key ] = true ; target . appendChild ( style . cloneNode ( true ) ) ; } } ) ; } ;