@@ -72,6 +72,7 @@ export class Templates {
7272 * the end
7373 */
7474 let customInjectedStyles : string = ''
75+ let globalScript : string = ''
7576 const styles : string [ ] = [ ]
7677 const scripts : string [ ] = [ ]
7778 const cspNonceAttr = cspNonce ? ` nonce="${ cspNonce } "` : ''
@@ -84,10 +85,18 @@ export class Templates {
8485 }
8586 } )
8687 this . #scripts. forEach ( ( bucket , name ) => {
88+ if ( name === 'global' ) {
89+ globalScript = `<script id="${ name } -script"${ cspNonceAttr } >${ bucket } </script>`
90+ }
91+
8792 scripts . push ( `<script id="${ name } -script"${ cspNonceAttr } >${ bucket } </script>` )
8893 } )
8994
90- return { styles : `${ styles . join ( '\n' ) } \n${ customInjectedStyles } ` , scripts : scripts . join ( '\n' ) }
95+ return {
96+ styles : `${ styles . join ( '\n' ) } \n${ customInjectedStyles } ` ,
97+ scripts : scripts . join ( '\n' ) ,
98+ globalScript,
99+ }
91100 }
92101
93102 /**
@@ -204,8 +213,11 @@ export class Templates {
204213 } ,
205214 } )
206215
207- const { scripts, styles } = this . #getStylesAndScripts( props . cspNonce )
208- return html . replace ( '<!-- STYLES -->' , styles ) . replace ( '<!-- SCRIPTS -->' , scripts )
216+ const { globalScript, scripts, styles } = this . #getStylesAndScripts( props . cspNonce )
217+ return html
218+ . replace ( '<!-- STYLES -->' , styles )
219+ . replace ( '<!-- SCRIPTS -->' , scripts )
220+ . replace ( '<!-- GLOBAL SCRIPT -->' , globalScript )
209221 }
210222
211223 /**
0 commit comments