1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { ɵsetRootDomAdapter, DOCUMENT, XhrFactory, PlatformLocation, ɵgetDOM, ɵPLATFORM_SERVER_ID, ViewportScroller, ɵNullViewportScroller } from '@angular/common';
|
8 | import * as i0 from '@angular/core';
|
9 | import { Injectable, Inject, InjectionToken, inject, EnvironmentInjector, Optional, ViewEncapsulation, RendererStyleFlags2, APP_ID, NgModule, Injector, PLATFORM_ID, PLATFORM_INITIALIZER, ɵALLOW_MULTIPLE_PLATFORMS, RendererFactory2, NgZone, Testability, ɵTESTABILITY, ɵsetDocument, createPlatformFactory, platformCore, Renderer2, ApplicationRef, ɵisPromise, importProvidersFrom, ɵinternalCreateApplication, Version } from '@angular/core';
|
10 | import * as i1 from '@angular/platform-browser';
|
11 | import { ɵBrowserDomAdapter, ɵflattenStyles, ɵNAMESPACE_URIS, ɵshimContentAttribute, ɵshimHostAttribute, ɵSharedStylesHost, ɵTRANSITION_ID, TransferState, ɵescapeHtml, EVENT_MANAGER_PLUGINS, BrowserModule } from '@angular/platform-browser';
|
12 | import * as domino from 'domino';
|
13 | import { ɵAnimationEngine } from '@angular/animations/browser';
|
14 | import { ɵHttpInterceptorHandler, HttpBackend, HttpHandler, HttpClientModule } from '@angular/common/http';
|
15 | import { ɵplatformCoreDynamic } from '@angular/platform-browser-dynamic';
|
16 | import { ɵAnimationRendererFactory, NoopAnimationsModule } from '@angular/platform-browser/animations';
|
17 | import { Observable, Subject } from 'rxjs';
|
18 | import * as xhr2 from 'xhr2';
|
19 | import * as url from 'url';
|
20 | import { DomElementSchemaRegistry } from '@angular/compiler';
|
21 | import { first } from 'rxjs/operators';
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | function setDomTypes() {
|
31 |
|
32 | Object.assign(global, domino.impl);
|
33 | global['KeyboardEvent'] = domino.impl.Event;
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | function parseDocument(html, url = '/') {
|
39 | let window = domino.createWindow(html, url);
|
40 | let doc = window.document;
|
41 | return doc;
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 | function serializeDocument(doc) {
|
47 | return doc.serialize();
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 | class DominoAdapter extends ɵBrowserDomAdapter {
|
53 | constructor() {
|
54 | super(...arguments);
|
55 | this.supportsDOMEvents = false;
|
56 | }
|
57 | static makeCurrent() {
|
58 | setDomTypes();
|
59 | ɵsetRootDomAdapter(new DominoAdapter());
|
60 | }
|
61 | createHtmlDocument() {
|
62 | return parseDocument('<html><head><title>fakeTitle</title></head><body></body></html>');
|
63 | }
|
64 | getDefaultDocument() {
|
65 | if (!DominoAdapter.defaultDoc) {
|
66 | DominoAdapter.defaultDoc = domino.createDocument();
|
67 | }
|
68 | return DominoAdapter.defaultDoc;
|
69 | }
|
70 | isElementNode(node) {
|
71 | return node ? node.nodeType === DominoAdapter.defaultDoc.ELEMENT_NODE : false;
|
72 | }
|
73 | isShadowRoot(node) {
|
74 | return node.shadowRoot == node;
|
75 | }
|
76 |
|
77 | getGlobalEventTarget(doc, target) {
|
78 | if (target === 'window') {
|
79 | return doc.defaultView;
|
80 | }
|
81 | if (target === 'document') {
|
82 | return doc;
|
83 | }
|
84 | if (target === 'body') {
|
85 | return doc.body;
|
86 | }
|
87 | return null;
|
88 | }
|
89 | getBaseHref(doc) {
|
90 | var _a;
|
91 |
|
92 | return ((_a = doc.documentElement.querySelector('base')) === null || _a === void 0 ? void 0 : _a.getAttribute('href')) || '';
|
93 | }
|
94 | dispatchEvent(el, evt) {
|
95 | el.dispatchEvent(evt);
|
96 |
|
97 | const doc = el.ownerDocument || el;
|
98 | const win = doc.defaultView;
|
99 | if (win) {
|
100 | win.dispatchEvent(evt);
|
101 | }
|
102 | }
|
103 | getUserAgent() {
|
104 | return 'Fake user agent';
|
105 | }
|
106 | getCookie(name) {
|
107 | throw new Error('getCookie has not been implemented');
|
108 | }
|
109 | }
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | class PlatformState {
|
124 | constructor(_doc) {
|
125 | this._doc = _doc;
|
126 | }
|
127 | |
128 |
|
129 |
|
130 | renderToString() {
|
131 | return serializeDocument(this._doc);
|
132 | }
|
133 | |
134 |
|
135 |
|
136 | getDocument() {
|
137 | return this._doc;
|
138 | }
|
139 | }
|
140 | PlatformState.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: PlatformState, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
141 | PlatformState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: PlatformState });
|
142 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: PlatformState, decorators: [{
|
143 | type: Injectable
|
144 | }], ctorParameters: function () {
|
145 | return [{ type: undefined, decorators: [{
|
146 | type: Inject,
|
147 | args: [DOCUMENT]
|
148 | }] }];
|
149 | } });
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | const INITIAL_CONFIG = new InjectionToken('Server.INITIAL_CONFIG');
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | const BEFORE_APP_SERIALIZED = new InjectionToken('Server.RENDER_MODULE_HOOK');
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | const isAbsoluteUrl = /^[a-zA-Z\-\+.]+:\/\//;
|
181 | class ServerXhr {
|
182 | build() {
|
183 | return new xhr2.XMLHttpRequest();
|
184 | }
|
185 | }
|
186 | ServerXhr.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerXhr, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
187 | ServerXhr.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerXhr });
|
188 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerXhr, decorators: [{
|
189 | type: Injectable
|
190 | }] });
|
191 | class ZoneMacroTaskWrapper {
|
192 | wrap(request) {
|
193 | return new Observable((observer) => {
|
194 | let task = null;
|
195 | let scheduled = false;
|
196 | let sub = null;
|
197 | let savedResult = null;
|
198 | let savedError = null;
|
199 | const scheduleTask = (_task) => {
|
200 | task = _task;
|
201 | scheduled = true;
|
202 | const delegate = this.delegate(request);
|
203 | sub = delegate.subscribe(res => savedResult = res, err => {
|
204 | if (!scheduled) {
|
205 | throw new Error('An http observable was completed twice. This shouldn\'t happen, please file a bug.');
|
206 | }
|
207 | savedError = err;
|
208 | scheduled = false;
|
209 | task.invoke();
|
210 | }, () => {
|
211 | if (!scheduled) {
|
212 | throw new Error('An http observable was completed twice. This shouldn\'t happen, please file a bug.');
|
213 | }
|
214 | scheduled = false;
|
215 | task.invoke();
|
216 | });
|
217 | };
|
218 | const cancelTask = (_task) => {
|
219 | if (!scheduled) {
|
220 | return;
|
221 | }
|
222 | scheduled = false;
|
223 | if (sub) {
|
224 | sub.unsubscribe();
|
225 | sub = null;
|
226 | }
|
227 | };
|
228 | const onComplete = () => {
|
229 | if (savedError !== null) {
|
230 | observer.error(savedError);
|
231 | }
|
232 | else {
|
233 | observer.next(savedResult);
|
234 | observer.complete();
|
235 | }
|
236 | };
|
237 |
|
238 |
|
239 |
|
240 | const _task = Zone.current.scheduleMacroTask('ZoneMacroTaskWrapper.subscribe', onComplete, {}, () => null, cancelTask);
|
241 | scheduleTask(_task);
|
242 | return () => {
|
243 | if (scheduled && task) {
|
244 | task.zone.cancelTask(task);
|
245 | scheduled = false;
|
246 | }
|
247 | if (sub) {
|
248 | sub.unsubscribe();
|
249 | sub = null;
|
250 | }
|
251 | };
|
252 | });
|
253 | }
|
254 | }
|
255 | class ZoneClientBackend extends ZoneMacroTaskWrapper {
|
256 | constructor(backend, platformLocation, config) {
|
257 | super();
|
258 | this.backend = backend;
|
259 | this.platformLocation = platformLocation;
|
260 | this.config = config;
|
261 | }
|
262 | handle(request) {
|
263 | const { href, protocol, hostname, port } = this.platformLocation;
|
264 | if (this.config.useAbsoluteUrl && !isAbsoluteUrl.test(request.url) &&
|
265 | isAbsoluteUrl.test(href)) {
|
266 | const baseHref = this.platformLocation.getBaseHrefFromDOM() || href;
|
267 | const urlPrefix = `${protocol}//${hostname}` + (port ? `:${port}` : '');
|
268 | const baseUrl = new URL(baseHref, urlPrefix);
|
269 | const url = new URL(request.url, baseUrl);
|
270 | return this.wrap(request.clone({ url: url.toString() }));
|
271 | }
|
272 | return this.wrap(request);
|
273 | }
|
274 | delegate(request) {
|
275 | return this.backend.handle(request);
|
276 | }
|
277 | }
|
278 | function zoneWrappedInterceptorHandler(platformLocation, config) {
|
279 | return new ZoneClientBackend(new ɵHttpInterceptorHandler(inject(HttpBackend), inject(EnvironmentInjector)), platformLocation, config);
|
280 | }
|
281 | const SERVER_HTTP_PROVIDERS = [
|
282 | { provide: XhrFactory, useClass: ServerXhr }, {
|
283 | provide: HttpHandler,
|
284 | useFactory: zoneWrappedInterceptorHandler,
|
285 | deps: [PlatformLocation, INITIAL_CONFIG]
|
286 | }
|
287 | ];
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | function parseUrl(urlStr) {
|
297 | const parsedUrl = url.parse(urlStr);
|
298 | return {
|
299 | hostname: parsedUrl.hostname || '',
|
300 | protocol: parsedUrl.protocol || '',
|
301 | port: parsedUrl.port || '',
|
302 | pathname: parsedUrl.pathname || '',
|
303 | search: parsedUrl.search || '',
|
304 | hash: parsedUrl.hash || '',
|
305 | };
|
306 | }
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | class ServerPlatformLocation {
|
312 | constructor(_doc, _config) {
|
313 | this._doc = _doc;
|
314 | this.href = '/';
|
315 | this.hostname = '/';
|
316 | this.protocol = '/';
|
317 | this.port = '/';
|
318 | this.pathname = '/';
|
319 | this.search = '';
|
320 | this.hash = '';
|
321 | this._hashUpdate = new Subject();
|
322 | const config = _config;
|
323 | if (!config) {
|
324 | return;
|
325 | }
|
326 | if (config.url) {
|
327 | const url = parseUrl(config.url);
|
328 | this.protocol = url.protocol;
|
329 | this.hostname = url.hostname;
|
330 | this.port = url.port;
|
331 | this.pathname = url.pathname;
|
332 | this.search = url.search;
|
333 | this.hash = url.hash;
|
334 | this.href = _doc.location.href;
|
335 | }
|
336 | if (config.useAbsoluteUrl) {
|
337 | if (!config.baseUrl) {
|
338 | throw new Error(`"PlatformConfig.baseUrl" must be set if "useAbsoluteUrl" is true`);
|
339 | }
|
340 | const url = parseUrl(config.baseUrl);
|
341 | this.protocol = url.protocol;
|
342 | this.hostname = url.hostname;
|
343 | this.port = url.port;
|
344 | }
|
345 | }
|
346 | getBaseHrefFromDOM() {
|
347 | return ɵgetDOM().getBaseHref(this._doc);
|
348 | }
|
349 | onPopState(fn) {
|
350 |
|
351 |
|
352 | return () => { };
|
353 | }
|
354 | onHashChange(fn) {
|
355 | const subscription = this._hashUpdate.subscribe(fn);
|
356 | return () => subscription.unsubscribe();
|
357 | }
|
358 | get url() {
|
359 | return `${this.pathname}${this.search}${this.hash}`;
|
360 | }
|
361 | setHash(value, oldUrl) {
|
362 | if (this.hash === value) {
|
363 |
|
364 | return;
|
365 | }
|
366 | this.hash = value;
|
367 | const newUrl = this.url;
|
368 | scheduleMicroTask(() => this._hashUpdate.next({ type: 'hashchange', state: null, oldUrl, newUrl }));
|
369 | }
|
370 | replaceState(state, title, newUrl) {
|
371 | const oldUrl = this.url;
|
372 | const parsedUrl = parseUrl(newUrl);
|
373 | this.pathname = parsedUrl.pathname;
|
374 | this.search = parsedUrl.search;
|
375 | this.setHash(parsedUrl.hash, oldUrl);
|
376 | }
|
377 | pushState(state, title, newUrl) {
|
378 | this.replaceState(state, title, newUrl);
|
379 | }
|
380 | forward() {
|
381 | throw new Error('Not implemented');
|
382 | }
|
383 | back() {
|
384 | throw new Error('Not implemented');
|
385 | }
|
386 |
|
387 | getState() {
|
388 | return undefined;
|
389 | }
|
390 | }
|
391 | ServerPlatformLocation.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerPlatformLocation, deps: [{ token: DOCUMENT }, { token: INITIAL_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
392 | ServerPlatformLocation.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerPlatformLocation });
|
393 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerPlatformLocation, decorators: [{
|
394 | type: Injectable
|
395 | }], ctorParameters: function () {
|
396 | return [{ type: undefined, decorators: [{
|
397 | type: Inject,
|
398 | args: [DOCUMENT]
|
399 | }] }, { type: undefined, decorators: [{
|
400 | type: Optional
|
401 | }, {
|
402 | type: Inject,
|
403 | args: [INITIAL_CONFIG]
|
404 | }] }];
|
405 | } });
|
406 | function scheduleMicroTask(fn) {
|
407 | Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
408 | }
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | class ServerEventManagerPlugin /* extends EventManagerPlugin which is private */ {
|
418 | constructor(doc) {
|
419 | this.doc = doc;
|
420 | }
|
421 |
|
422 | supports(eventName) {
|
423 | return true;
|
424 | }
|
425 | addEventListener(element, eventName, handler) {
|
426 | return ɵgetDOM().onAndCancel(element, eventName, handler);
|
427 | }
|
428 |
|
429 | addGlobalEventListener(element, eventName, handler) {
|
430 | const target = ɵgetDOM().getGlobalEventTarget(this.doc, element);
|
431 | if (!target) {
|
432 | throw new Error(`Unsupported event target ${target} for event ${eventName}`);
|
433 | }
|
434 | return this.addEventListener(target, eventName, handler);
|
435 | }
|
436 | }
|
437 | ServerEventManagerPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerEventManagerPlugin , deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
438 | ServerEventManagerPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerEventManagerPlugin });
|
439 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerEventManagerPlugin , decorators: [{
|
440 | type: Injectable
|
441 | }], ctorParameters: function () {
|
442 | return [{ type: undefined, decorators: [{
|
443 | type: Inject,
|
444 | args: [DOCUMENT]
|
445 | }] }];
|
446 | } });
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | const EMPTY_ARRAY = [];
|
456 | const DEFAULT_SCHEMA = new DomElementSchemaRegistry();
|
457 | class ServerRendererFactory2 {
|
458 | constructor(eventManager, ngZone, document, sharedStylesHost) {
|
459 | this.eventManager = eventManager;
|
460 | this.ngZone = ngZone;
|
461 | this.document = document;
|
462 | this.sharedStylesHost = sharedStylesHost;
|
463 | this.rendererByCompId = new Map();
|
464 | this.schema = DEFAULT_SCHEMA;
|
465 | this.defaultRenderer = new DefaultServerRenderer2(eventManager, document, ngZone, this.schema);
|
466 | }
|
467 | createRenderer(element, type) {
|
468 | if (!element || !type) {
|
469 | return this.defaultRenderer;
|
470 | }
|
471 | switch (type.encapsulation) {
|
472 | case ViewEncapsulation.Emulated: {
|
473 | let renderer = this.rendererByCompId.get(type.id);
|
474 | if (!renderer) {
|
475 | renderer = new EmulatedEncapsulationServerRenderer2(this.eventManager, this.document, this.ngZone, this.sharedStylesHost, this.schema, type);
|
476 | this.rendererByCompId.set(type.id, renderer);
|
477 | }
|
478 | renderer.applyToHost(element);
|
479 | return renderer;
|
480 | }
|
481 | default: {
|
482 | if (!this.rendererByCompId.has(type.id)) {
|
483 | const styles = ɵflattenStyles(type.id, type.styles, []);
|
484 | this.sharedStylesHost.addStyles(styles);
|
485 | this.rendererByCompId.set(type.id, this.defaultRenderer);
|
486 | }
|
487 | return this.defaultRenderer;
|
488 | }
|
489 | }
|
490 | }
|
491 | begin() { }
|
492 | end() { }
|
493 | }
|
494 | ServerRendererFactory2.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerRendererFactory2, deps: [{ token: i1.EventManager }, { token: i0.NgZone }, { token: DOCUMENT }, { token: i1.ɵSharedStylesHost }], target: i0.ɵɵFactoryTarget.Injectable });
|
495 | ServerRendererFactory2.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerRendererFactory2 });
|
496 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerRendererFactory2, decorators: [{
|
497 | type: Injectable
|
498 | }], ctorParameters: function () {
|
499 | return [{ type: i1.EventManager }, { type: i0.NgZone }, { type: undefined, decorators: [{
|
500 | type: Inject,
|
501 | args: [DOCUMENT]
|
502 | }] }, { type: i1.ɵSharedStylesHost }];
|
503 | } });
|
504 | class DefaultServerRenderer2 {
|
505 | constructor(eventManager, document, ngZone, schema) {
|
506 | this.eventManager = eventManager;
|
507 | this.document = document;
|
508 | this.ngZone = ngZone;
|
509 | this.schema = schema;
|
510 | this.data = Object.create(null);
|
511 | this.destroyNode = null;
|
512 | }
|
513 | destroy() { }
|
514 | createElement(name, namespace) {
|
515 | if (namespace) {
|
516 | const doc = this.document || ɵgetDOM().getDefaultDocument();
|
517 | return doc.createElementNS(ɵNAMESPACE_URIS[namespace], name);
|
518 | }
|
519 | return ɵgetDOM().createElement(name, this.document);
|
520 | }
|
521 | createComment(value) {
|
522 | return ɵgetDOM().getDefaultDocument().createComment(value);
|
523 | }
|
524 | createText(value) {
|
525 | const doc = ɵgetDOM().getDefaultDocument();
|
526 | return doc.createTextNode(value);
|
527 | }
|
528 | appendChild(parent, newChild) {
|
529 | const targetParent = isTemplateNode(parent) ? parent.content : parent;
|
530 | targetParent.appendChild(newChild);
|
531 | }
|
532 | insertBefore(parent, newChild, refChild) {
|
533 | if (parent) {
|
534 | const targetParent = isTemplateNode(parent) ? parent.content : parent;
|
535 | targetParent.insertBefore(newChild, refChild);
|
536 | }
|
537 | }
|
538 | removeChild(parent, oldChild) {
|
539 | if (parent) {
|
540 | parent.removeChild(oldChild);
|
541 | }
|
542 | }
|
543 | selectRootElement(selectorOrNode, preserveContent) {
|
544 | const el = typeof selectorOrNode === 'string' ? this.document.querySelector(selectorOrNode) :
|
545 | selectorOrNode;
|
546 | if (!el) {
|
547 | throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
|
548 | }
|
549 | if (!preserveContent) {
|
550 | while (el.firstChild) {
|
551 | el.removeChild(el.firstChild);
|
552 | }
|
553 | }
|
554 | return el;
|
555 | }
|
556 | parentNode(node) {
|
557 | return node.parentNode;
|
558 | }
|
559 | nextSibling(node) {
|
560 | return node.nextSibling;
|
561 | }
|
562 | setAttribute(el, name, value, namespace) {
|
563 | if (namespace) {
|
564 | el.setAttributeNS(ɵNAMESPACE_URIS[namespace], namespace + ':' + name, value);
|
565 | }
|
566 | else {
|
567 | el.setAttribute(name, value);
|
568 | }
|
569 | }
|
570 | removeAttribute(el, name, namespace) {
|
571 | if (namespace) {
|
572 | el.removeAttributeNS(ɵNAMESPACE_URIS[namespace], name);
|
573 | }
|
574 | else {
|
575 | el.removeAttribute(name);
|
576 | }
|
577 | }
|
578 | addClass(el, name) {
|
579 | el.classList.add(name);
|
580 | }
|
581 | removeClass(el, name) {
|
582 | el.classList.remove(name);
|
583 | }
|
584 | setStyle(el, style, value, flags) {
|
585 | style = style.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
586 | value = value == null ? '' : `${value}`.trim();
|
587 | const styleMap = _readStyleAttribute(el);
|
588 | if (flags & RendererStyleFlags2.Important) {
|
589 | value += ' !important';
|
590 | }
|
591 | styleMap[style] = value;
|
592 | _writeStyleAttribute(el, styleMap);
|
593 | }
|
594 | removeStyle(el, style, flags) {
|
595 |
|
596 |
|
597 | this.setStyle(el, style, '', flags);
|
598 | }
|
599 |
|
600 |
|
601 |
|
602 |
|
603 | _isSafeToReflectProperty(tagName, propertyName) {
|
604 | return this.schema.securityContext(tagName, propertyName, true) ===
|
605 | this.schema.securityContext(tagName, propertyName, false);
|
606 | }
|
607 | setProperty(el, name, value) {
|
608 | checkNoSyntheticProp(name, 'property');
|
609 | if (name === 'innerText') {
|
610 |
|
611 | el.textContent = value;
|
612 | }
|
613 | el[name] = value;
|
614 |
|
615 |
|
616 |
|
617 | const tagName = el.tagName.toLowerCase();
|
618 | if (value != null && (typeof value === 'number' || typeof value == 'string') &&
|
619 | name.toLowerCase() !== 'innerhtml' && this.schema.hasElement(tagName, EMPTY_ARRAY) &&
|
620 | this.schema.hasProperty(tagName, name, EMPTY_ARRAY) &&
|
621 | this._isSafeToReflectProperty(tagName, name)) {
|
622 | this.setAttribute(el, name, value.toString());
|
623 | }
|
624 | }
|
625 | setValue(node, value) {
|
626 | node.textContent = value;
|
627 | }
|
628 | listen(target, eventName, callback) {
|
629 | checkNoSyntheticProp(eventName, 'listener');
|
630 | if (typeof target === 'string') {
|
631 | return this.eventManager.addGlobalEventListener(target, eventName, this.decoratePreventDefault(callback));
|
632 | }
|
633 | return this.eventManager.addEventListener(target, eventName, this.decoratePreventDefault(callback));
|
634 | }
|
635 | decoratePreventDefault(eventHandler) {
|
636 | return (event) => {
|
637 |
|
638 |
|
639 | if (event === Function) {
|
640 | return eventHandler;
|
641 | }
|
642 |
|
643 |
|
644 | const allowDefaultBehavior = this.ngZone.runGuarded(() => eventHandler(event));
|
645 | if (allowDefaultBehavior === false) {
|
646 | event.preventDefault();
|
647 | event.returnValue = false;
|
648 | }
|
649 | return undefined;
|
650 | };
|
651 | }
|
652 | }
|
653 | const AT_CHARCODE = '@'.charCodeAt(0);
|
654 | function checkNoSyntheticProp(name, nameKind) {
|
655 | if (name.charCodeAt(0) === AT_CHARCODE) {
|
656 | throw new Error(`Unexpected synthetic ${nameKind} ${name} found. Please make sure that:
|
657 | - Either \`BrowserAnimationsModule\` or \`NoopAnimationsModule\` are imported in your application.
|
658 | - There is corresponding configuration for the animation named \`${name}\` defined in the \`animations\` field of the \`@Component\` decorator (see https://angular.io/api/core/Component#animations).`);
|
659 | }
|
660 | }
|
661 | function isTemplateNode(node) {
|
662 | return node.tagName === 'TEMPLATE' && node.content !== undefined;
|
663 | }
|
664 | class EmulatedEncapsulationServerRenderer2 extends DefaultServerRenderer2 {
|
665 | constructor(eventManager, document, ngZone, sharedStylesHost, schema, component) {
|
666 | super(eventManager, document, ngZone, schema);
|
667 | this.component = component;
|
668 |
|
669 | const componentId = 's' + component.id;
|
670 | const styles = ɵflattenStyles(componentId, component.styles, []);
|
671 | sharedStylesHost.addStyles(styles);
|
672 | this.contentAttr = ɵshimContentAttribute(componentId);
|
673 | this.hostAttr = ɵshimHostAttribute(componentId);
|
674 | }
|
675 | applyToHost(element) {
|
676 | super.setAttribute(element, this.hostAttr, '');
|
677 | }
|
678 | createElement(parent, name) {
|
679 | const el = super.createElement(parent, name);
|
680 | super.setAttribute(el, this.contentAttr, '');
|
681 | return el;
|
682 | }
|
683 | }
|
684 | function _readStyleAttribute(element) {
|
685 | const styleMap = {};
|
686 | const styleAttribute = element.getAttribute('style');
|
687 | if (styleAttribute) {
|
688 | const styleList = styleAttribute.split(/;+/g);
|
689 | for (let i = 0; i < styleList.length; i++) {
|
690 | const style = styleList[i].trim();
|
691 | if (style.length > 0) {
|
692 | const colonIndex = style.indexOf(':');
|
693 | if (colonIndex === -1) {
|
694 | throw new Error(`Invalid CSS style: ${style}`);
|
695 | }
|
696 | const name = style.slice(0, colonIndex).trim();
|
697 | styleMap[name] = style.slice(colonIndex + 1).trim();
|
698 | }
|
699 | }
|
700 | }
|
701 | return styleMap;
|
702 | }
|
703 | function _writeStyleAttribute(element, styleMap) {
|
704 |
|
705 |
|
706 |
|
707 | let styleAttrValue = '';
|
708 | for (const key in styleMap) {
|
709 | const newValue = styleMap[key];
|
710 | if (newValue != null && newValue !== '') {
|
711 | styleAttrValue += key + ':' + newValue + ';';
|
712 | }
|
713 | }
|
714 | if (styleAttrValue) {
|
715 | element.setAttribute('style', styleAttrValue);
|
716 | }
|
717 | else {
|
718 | element.removeAttribute('style');
|
719 | }
|
720 | }
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 | class ServerStylesHost extends ɵSharedStylesHost {
|
730 | constructor(doc, transitionId) {
|
731 | super();
|
732 | this.doc = doc;
|
733 | this.transitionId = transitionId;
|
734 | this.head = null;
|
735 | this._styleNodes = new Set();
|
736 | this.head = doc.getElementsByTagName('head')[0];
|
737 | }
|
738 | _addStyle(style) {
|
739 | let adapter = ɵgetDOM();
|
740 | const el = adapter.createElement('style');
|
741 | el.textContent = style;
|
742 | if (!!this.transitionId) {
|
743 | el.setAttribute('ng-transition', this.transitionId);
|
744 | }
|
745 | this.head.appendChild(el);
|
746 | this._styleNodes.add(el);
|
747 | }
|
748 | onStylesAdded(additions) {
|
749 | additions.forEach(style => this._addStyle(style));
|
750 | }
|
751 | ngOnDestroy() {
|
752 | this._styleNodes.forEach(styleNode => styleNode.remove());
|
753 | }
|
754 | }
|
755 | ServerStylesHost.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerStylesHost, deps: [{ token: DOCUMENT }, { token: ɵTRANSITION_ID, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
756 | ServerStylesHost.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerStylesHost });
|
757 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerStylesHost, decorators: [{
|
758 | type: Injectable
|
759 | }], ctorParameters: function () {
|
760 | return [{ type: undefined, decorators: [{
|
761 | type: Inject,
|
762 | args: [DOCUMENT]
|
763 | }] }, { type: undefined, decorators: [{
|
764 | type: Optional
|
765 | }, {
|
766 | type: Inject,
|
767 | args: [ɵTRANSITION_ID]
|
768 | }] }];
|
769 | } });
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 | const TRANSFER_STATE_SERIALIZATION_PROVIDERS = [{
|
779 | provide: BEFORE_APP_SERIALIZED,
|
780 | useFactory: serializeTransferStateFactory,
|
781 | deps: [DOCUMENT, APP_ID, TransferState],
|
782 | multi: true,
|
783 | }];
|
784 | function serializeTransferStateFactory(doc, appId, transferStore) {
|
785 | return () => {
|
786 |
|
787 |
|
788 | const content = transferStore.toJson();
|
789 | if (transferStore.isEmpty) {
|
790 |
|
791 |
|
792 | return;
|
793 | }
|
794 | const script = doc.createElement('script');
|
795 | script.id = appId + '-state';
|
796 | script.setAttribute('type', 'application/json');
|
797 | script.textContent = ɵescapeHtml(content);
|
798 | doc.body.appendChild(script);
|
799 | };
|
800 | }
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 | class ServerTransferStateModule {
|
813 | }
|
814 | ServerTransferStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerTransferStateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
815 | ServerTransferStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.1", ngImport: i0, type: ServerTransferStateModule });
|
816 | ServerTransferStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerTransferStateModule });
|
817 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerTransferStateModule, decorators: [{
|
818 | type: NgModule,
|
819 | args: [{}]
|
820 | }] });
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 | const INTERNAL_SERVER_PLATFORM_PROVIDERS = [
|
830 | { provide: DOCUMENT, useFactory: _document, deps: [Injector] },
|
831 | { provide: PLATFORM_ID, useValue: ɵPLATFORM_SERVER_ID },
|
832 | { provide: PLATFORM_INITIALIZER, useFactory: initDominoAdapter, multi: true, deps: [Injector] }, {
|
833 | provide: PlatformLocation,
|
834 | useClass: ServerPlatformLocation,
|
835 | deps: [DOCUMENT, [Optional, INITIAL_CONFIG]]
|
836 | },
|
837 | { provide: PlatformState, deps: [DOCUMENT] },
|
838 |
|
839 | { provide: ɵALLOW_MULTIPLE_PLATFORMS, useValue: true }
|
840 | ];
|
841 | function initDominoAdapter(injector) {
|
842 | return () => {
|
843 | DominoAdapter.makeCurrent();
|
844 | };
|
845 | }
|
846 | function instantiateServerRendererFactory(renderer, engine, zone) {
|
847 | return new ɵAnimationRendererFactory(renderer, engine, zone);
|
848 | }
|
849 | const SERVER_RENDER_PROVIDERS = [
|
850 | ServerRendererFactory2,
|
851 | {
|
852 | provide: RendererFactory2,
|
853 | useFactory: instantiateServerRendererFactory,
|
854 | deps: [ServerRendererFactory2, ɵAnimationEngine, NgZone]
|
855 | },
|
856 | ServerStylesHost,
|
857 | { provide: ɵSharedStylesHost, useExisting: ServerStylesHost },
|
858 | { provide: EVENT_MANAGER_PLUGINS, multi: true, useClass: ServerEventManagerPlugin },
|
859 | ];
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 | class ServerModule {
|
866 | }
|
867 | ServerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
868 | ServerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.1", ngImport: i0, type: ServerModule, imports: [HttpClientModule, NoopAnimationsModule], exports: [BrowserModule] });
|
869 | ServerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerModule, providers: [
|
870 | TRANSFER_STATE_SERIALIZATION_PROVIDERS,
|
871 | SERVER_RENDER_PROVIDERS,
|
872 | SERVER_HTTP_PROVIDERS,
|
873 | { provide: Testability, useValue: null },
|
874 | { provide: ɵTESTABILITY, useValue: null },
|
875 | { provide: ViewportScroller, useClass: ɵNullViewportScroller },
|
876 | ], imports: [HttpClientModule, NoopAnimationsModule, BrowserModule] });
|
877 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImport: i0, type: ServerModule, decorators: [{
|
878 | type: NgModule,
|
879 | args: [{
|
880 | exports: [BrowserModule],
|
881 | imports: [HttpClientModule, NoopAnimationsModule],
|
882 | providers: [
|
883 | TRANSFER_STATE_SERIALIZATION_PROVIDERS,
|
884 | SERVER_RENDER_PROVIDERS,
|
885 | SERVER_HTTP_PROVIDERS,
|
886 | { provide: Testability, useValue: null },
|
887 | { provide: ɵTESTABILITY, useValue: null },
|
888 | { provide: ViewportScroller, useClass: ɵNullViewportScroller },
|
889 | ],
|
890 | }]
|
891 | }] });
|
892 | function _document(injector) {
|
893 | const config = injector.get(INITIAL_CONFIG, null);
|
894 | let document;
|
895 | if (config && config.document) {
|
896 | document = typeof config.document === 'string' ? parseDocument(config.document, config.url) :
|
897 | config.document;
|
898 | }
|
899 | else {
|
900 | document = ɵgetDOM().createHtmlDocument();
|
901 | }
|
902 |
|
903 | ɵsetDocument(document);
|
904 | return document;
|
905 | }
|
906 |
|
907 |
|
908 |
|
909 | const platformServer = createPlatformFactory(platformCore, 'server', INTERNAL_SERVER_PLATFORM_PROVIDERS);
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 | const platformDynamicServer = createPlatformFactory(ɵplatformCoreDynamic, 'serverDynamic', INTERNAL_SERVER_PLATFORM_PROVIDERS);
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 | function _getPlatform(platformFactory, options) {
|
925 | var _a;
|
926 | const extraProviders = (_a = options.platformProviders) !== null && _a !== void 0 ? _a : [];
|
927 | return platformFactory([
|
928 | { provide: INITIAL_CONFIG, useValue: { document: options.document, url: options.url } },
|
929 | extraProviders
|
930 | ]);
|
931 | }
|
932 |
|
933 |
|
934 |
|
935 |
|
936 | function appendServerContextInfo(serverContext, applicationRef) {
|
937 | applicationRef.components.forEach(componentRef => {
|
938 | const renderer = componentRef.injector.get(Renderer2);
|
939 | const element = componentRef.location.nativeElement;
|
940 | if (element) {
|
941 | renderer.setAttribute(element, 'ng-server-context', serverContext);
|
942 | }
|
943 | });
|
944 | }
|
945 | function _render(platform, bootstrapPromise) {
|
946 | return bootstrapPromise.then((moduleOrApplicationRef) => {
|
947 | const environmentInjector = moduleOrApplicationRef.injector;
|
948 | const transitionId = environmentInjector.get(ɵTRANSITION_ID, null);
|
949 | if (!transitionId) {
|
950 | throw new Error(`renderModule[Factory]() requires the use of BrowserModule.withServerTransition() to ensure
|
951 | the server-rendered app can be properly bootstrapped into a client app.`);
|
952 | }
|
953 | const applicationRef = moduleOrApplicationRef instanceof ApplicationRef ?
|
954 | moduleOrApplicationRef :
|
955 | environmentInjector.get(ApplicationRef);
|
956 | const serverContext = sanitizeServerContext(environmentInjector.get(SERVER_CONTEXT, DEFAULT_SERVER_CONTEXT));
|
957 | return applicationRef.isStable.pipe((first((isStable) => isStable)))
|
958 | .toPromise()
|
959 | .then(() => {
|
960 | appendServerContextInfo(serverContext, applicationRef);
|
961 | const platformState = platform.injector.get(PlatformState);
|
962 | const asyncPromises = [];
|
963 |
|
964 | const callbacks = environmentInjector.get(BEFORE_APP_SERIALIZED, null);
|
965 | if (callbacks) {
|
966 | for (const callback of callbacks) {
|
967 | try {
|
968 | const callbackResult = callback();
|
969 | if (ɵisPromise(callbackResult)) {
|
970 |
|
971 | asyncPromises.push(callbackResult);
|
972 | }
|
973 | }
|
974 | catch (e) {
|
975 |
|
976 | console.warn('Ignoring BEFORE_APP_SERIALIZED Exception: ', e);
|
977 | }
|
978 | }
|
979 | }
|
980 | const complete = () => {
|
981 | const output = platformState.renderToString();
|
982 | platform.destroy();
|
983 | return output;
|
984 | };
|
985 | if (asyncPromises.length === 0) {
|
986 | return complete();
|
987 | }
|
988 | return Promise
|
989 | .all(asyncPromises.map(asyncPromise => {
|
990 | return asyncPromise.catch(e => {
|
991 | console.warn('Ignoring BEFORE_APP_SERIALIZED Exception: ', e);
|
992 | });
|
993 | }))
|
994 | .then(complete);
|
995 | });
|
996 | });
|
997 | }
|
998 |
|
999 |
|
1000 |
|
1001 | const DEFAULT_SERVER_CONTEXT = 'other';
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 | const SERVER_CONTEXT = new InjectionToken('SERVER_CONTEXT');
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 | function sanitizeServerContext(serverContext) {
|
1014 | const context = serverContext.replace(/[^a-zA-Z0-9\-]/g, '');
|
1015 | return context.length > 0 ? context : DEFAULT_SERVER_CONTEXT;
|
1016 | }
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 | function renderModule(moduleType, options) {
|
1030 | const { document, url, extraProviders: platformProviders } = options;
|
1031 | const platform = _getPlatform(platformDynamicServer, { document, url, platformProviders });
|
1032 | return _render(platform, platform.bootstrapModule(moduleType));
|
1033 | }
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 | function renderApplication(rootComponent, options) {
|
1067 | var _a;
|
1068 | const { document, url, platformProviders, appId } = options;
|
1069 | const platform = _getPlatform(platformDynamicServer, { document, url, platformProviders });
|
1070 | const appProviders = [
|
1071 | importProvidersFrom(BrowserModule.withServerTransition({ appId })),
|
1072 | importProvidersFrom(ServerModule),
|
1073 | ...TRANSFER_STATE_SERIALIZATION_PROVIDERS,
|
1074 | ...((_a = options.providers) !== null && _a !== void 0 ? _a : []),
|
1075 | ];
|
1076 | return _render(platform, ɵinternalCreateApplication({ rootComponent, appProviders }));
|
1077 | }
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 | function renderModuleFactory(moduleFactory, options) {
|
1097 | const { document, url, extraProviders: platformProviders } = options;
|
1098 | const platform = _getPlatform(platformServer, { document, url, platformProviders });
|
1099 | return _render(platform, platform.bootstrapModuleFactory(moduleFactory));
|
1100 | }
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 | const VERSION = new Version('15.0.1');
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 | export { BEFORE_APP_SERIALIZED, INITIAL_CONFIG, PlatformState, ServerModule, ServerTransferStateModule, VERSION, platformDynamicServer, platformServer, renderApplication, renderModule, renderModuleFactory, INTERNAL_SERVER_PLATFORM_PROVIDERS as ɵINTERNAL_SERVER_PLATFORM_PROVIDERS, SERVER_CONTEXT as ɵSERVER_CONTEXT, SERVER_RENDER_PROVIDERS as ɵSERVER_RENDER_PROVIDERS, ServerRendererFactory2 as ɵServerRendererFactory2, setDomTypes as ɵsetDomTypes };
|
1152 |
|