@@ -11,86 +11,58 @@ import { Compiler, CompilerFactory, NgModuleFactory, StaticProvider, Type } from
1111import { platformDynamicServer } from '@angular/platform-server' ;
1212
1313import { ORIGIN_URL , REQUEST } from '@nguniversal/aspnetcore-engine/tokens' ;
14- import { FileLoader } from './file-loader ' ;
14+ import { ɵFileLoader } from '@nguniversal/common/engine ' ;
1515import { IEngineOptions } from './interfaces/engine-options' ;
1616import { IEngineRenderResult } from './interfaces/engine-render-result' ;
1717import { renderModuleFactory } from './platform-server-utils' ;
1818
19- /* @internal */
20- export class UniversalData {
21- appNode = '' ;
22- title = '' ;
23- scripts = '' ;
24- styles = '' ;
25- meta = '' ;
26- links = '' ;
27- }
28-
2919/* @internal */
3020let appSelector = 'app-root' ; // default
3121
3222/* @internal */
33- function _getUniversalData ( doc : Document ) : UniversalData {
23+ function _getUniversalData ( doc : Document ) : Omit < IEngineRenderResult , 'moduleRef' > {
3424
35- const STYLES : string [ ] = [ ] ;
36- const SCRIPTS : string [ ] = [ ] ;
37- const META : string [ ] = [ ] ;
38- const LINKS : string [ ] = [ ] ;
25+ const styles : string [ ] = [ ] ;
26+ const scripts : string [ ] = [ ] ;
27+ const meta : string [ ] = [ ] ;
28+ const links : string [ ] = [ ] ;
3929
40- // tslint:disable-next-line: no-non-null-assertion
41- for ( let i = 0 ; i < doc . head ! . children . length ; i ++ ) {
42- // tslint:disable-next-line: no-non-null-assertion
43- const element = doc . head ! . children [ i ] ;
44- const tagName = element . tagName . toUpperCase ( ) ;
45-
46- switch ( tagName ) {
47- case 'SCRIPT' :
48- SCRIPTS . push ( element . outerHTML ) ;
49- break ;
50- case 'STYLE' :
51- STYLES . push ( element . outerHTML ) ;
52- break ;
53- case 'LINK' :
54- LINKS . push ( element . outerHTML ) ;
55- break ;
56- case 'META' :
57- META . push ( element . outerHTML ) ;
58- break ;
59- default :
60- break ;
61- }
62- }
63-
64- for ( let i = 0 ; i < doc . body . children . length ; i ++ ) {
65- const element : Element = doc . body . children [ i ] ;
66- const tagName = element . tagName . toUpperCase ( ) ;
30+ // tslint:disable: no-non-null-assertion
31+ const elements = [
32+ ...Array . from ( doc . head ! . children ) ,
33+ ...Array . from ( doc . body ! . children ) ,
34+ ] ;
35+ // tslint:enable: no-non-null-assertion
6736
68- switch ( tagName ) {
37+ for ( const element of elements ) {
38+ switch ( element . tagName . toUpperCase ( ) ) {
6939 case 'SCRIPT' :
70- SCRIPTS . push ( element . outerHTML ) ;
40+ scripts . push ( element . outerHTML ) ;
7141 break ;
7242 case 'STYLE' :
73- STYLES . push ( element . outerHTML ) ;
43+ styles . push ( element . outerHTML ) ;
7444 break ;
7545 case 'LINK' :
76- LINKS . push ( element . outerHTML ) ;
46+ links . push ( element . outerHTML ) ;
7747 break ;
7848 case 'META' :
79- META . push ( element . outerHTML ) ;
49+ meta . push ( element . outerHTML ) ;
8050 break ;
8151 default :
8252 break ;
8353 }
8454 }
8555
8656 return {
87- title : doc . title ,
8857 // tslint:disable-next-line: no-non-null-assertion
89- appNode : doc . querySelector ( appSelector ) ! . outerHTML ,
90- scripts : SCRIPTS . join ( '\n' ) ,
91- styles : STYLES . join ( '\n' ) ,
92- meta : META . join ( '\n' ) ,
93- links : LINKS . join ( '\n' )
58+ html : doc . querySelector ( appSelector ) ! . outerHTML ,
59+ globals : {
60+ title : doc . title ,
61+ scripts : scripts . join ( '\n' ) ,
62+ styles : styles . join ( '\n' ) ,
63+ meta : meta . join ( '\n' ) ,
64+ links : links . join ( '\n' )
65+ }
9466 } ;
9567}
9668
@@ -109,7 +81,7 @@ export async function ngAspnetCoreEngine(options: Readonly<IEngineOptions>)
10981 const compiler : Compiler = compilerFactory . createCompiler ( [
11082 {
11183 providers : [
112- { provide : ResourceLoader , useClass : FileLoader , deps : [ ] }
84+ { provide : ResourceLoader , useClass : ɵFileLoader , deps : [ ] }
11385 ]
11486 }
11587 ] ) ;
@@ -132,18 +104,10 @@ export async function ngAspnetCoreEngine(options: Readonly<IEngineOptions>)
132104 } ) ;
133105
134106 const doc = result . moduleRef . injector . get ( DOCUMENT ) ;
135- const universalData = _getUniversalData ( doc ) ;
136107
137108 return {
138- html : universalData . appNode ,
139109 moduleRef : result . moduleRef ,
140- globals : {
141- styles : universalData . styles ,
142- title : universalData . title ,
143- scripts : universalData . scripts ,
144- meta : universalData . meta ,
145- links : universalData . links
146- }
110+ ..._getUniversalData ( doc ) ,
147111 } ;
148112}
149113
0 commit comments