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, Injector, Optional, ViewEncapsulation, RendererStyleFlags2, PLATFORM_ID, PLATFORM_INITIALIZER, ɵALLOW_MULTIPLE_PLATFORMS, RendererFactory2, NgZone, Testability, ɵTESTABILITY, NgModule, ɵsetDocument, createPlatformFactory, platformCore, APP_ID, ApplicationRef, ɵisPromise, importProvidersFrom, ɵinternalBootstrapApplication, Version } from '@angular/core';
|
10 | import * as i1 from '@angular/platform-browser';
|
11 | import { ɵBrowserDomAdapter, ɵflattenStyles, ɵNAMESPACE_URIS, ɵshimContentAttribute, ɵshimHostAttribute, ɵSharedStylesHost, ɵTRANSITION_ID, EVENT_MANAGER_PLUGINS, BrowserModule, ɵescapeHtml, TransferState } from '@angular/platform-browser';
|
12 | import * as domino from 'domino';
|
13 | import { ɵAnimationEngine } from '@angular/animations/browser';
|
14 | import { ɵHttpInterceptingHandler, HttpHandler, HttpBackend, 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: "14.0.4", ngImport: i0, type: PlatformState, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
141 | PlatformState.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: PlatformState });
|
142 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", 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: "14.0.4", ngImport: i0, type: ServerXhr, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
187 | ServerXhr.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerXhr });
|
188 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", 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 zoneWrappedInterceptingHandler(backend, injector, platformLocation, config) {
|
279 | const realBackend = new ɵHttpInterceptingHandler(backend, injector);
|
280 | return new ZoneClientBackend(realBackend, platformLocation, config);
|
281 | }
|
282 | const SERVER_HTTP_PROVIDERS = [
|
283 | { provide: XhrFactory, useClass: ServerXhr }, {
|
284 | provide: HttpHandler,
|
285 | useFactory: zoneWrappedInterceptingHandler,
|
286 | deps: [HttpBackend, Injector, PlatformLocation, INITIAL_CONFIG]
|
287 | }
|
288 | ];
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | function parseUrl(urlStr) {
|
298 | const parsedUrl = url.parse(urlStr);
|
299 | return {
|
300 | hostname: parsedUrl.hostname || '',
|
301 | protocol: parsedUrl.protocol || '',
|
302 | port: parsedUrl.port || '',
|
303 | pathname: parsedUrl.pathname || '',
|
304 | search: parsedUrl.search || '',
|
305 | hash: parsedUrl.hash || '',
|
306 | };
|
307 | }
|
308 |
|
309 |
|
310 |
|
311 |
|
312 | class ServerPlatformLocation {
|
313 | constructor(_doc, _config) {
|
314 | this._doc = _doc;
|
315 | this.href = '/';
|
316 | this.hostname = '/';
|
317 | this.protocol = '/';
|
318 | this.port = '/';
|
319 | this.pathname = '/';
|
320 | this.search = '';
|
321 | this.hash = '';
|
322 | this._hashUpdate = new Subject();
|
323 | const config = _config;
|
324 | if (!config) {
|
325 | return;
|
326 | }
|
327 | if (config.url) {
|
328 | const url = parseUrl(config.url);
|
329 | this.protocol = url.protocol;
|
330 | this.hostname = url.hostname;
|
331 | this.port = url.port;
|
332 | this.pathname = url.pathname;
|
333 | this.search = url.search;
|
334 | this.hash = url.hash;
|
335 | this.href = _doc.location.href;
|
336 | }
|
337 | if (config.useAbsoluteUrl) {
|
338 | if (!config.baseUrl) {
|
339 | throw new Error(`"PlatformConfig.baseUrl" must be set if "useAbsoluteUrl" is true`);
|
340 | }
|
341 | const url = parseUrl(config.baseUrl);
|
342 | this.protocol = url.protocol;
|
343 | this.hostname = url.hostname;
|
344 | this.port = url.port;
|
345 | }
|
346 | }
|
347 | getBaseHrefFromDOM() {
|
348 | return ɵgetDOM().getBaseHref(this._doc);
|
349 | }
|
350 | onPopState(fn) {
|
351 |
|
352 |
|
353 | return () => { };
|
354 | }
|
355 | onHashChange(fn) {
|
356 | const subscription = this._hashUpdate.subscribe(fn);
|
357 | return () => subscription.unsubscribe();
|
358 | }
|
359 | get url() {
|
360 | return `${this.pathname}${this.search}${this.hash}`;
|
361 | }
|
362 | setHash(value, oldUrl) {
|
363 | if (this.hash === value) {
|
364 |
|
365 | return;
|
366 | }
|
367 | this.hash = value;
|
368 | const newUrl = this.url;
|
369 | scheduleMicroTask(() => this._hashUpdate.next({ type: 'hashchange', state: null, oldUrl, newUrl }));
|
370 | }
|
371 | replaceState(state, title, newUrl) {
|
372 | const oldUrl = this.url;
|
373 | const parsedUrl = parseUrl(newUrl);
|
374 | this.pathname = parsedUrl.pathname;
|
375 | this.search = parsedUrl.search;
|
376 | this.setHash(parsedUrl.hash, oldUrl);
|
377 | }
|
378 | pushState(state, title, newUrl) {
|
379 | this.replaceState(state, title, newUrl);
|
380 | }
|
381 | forward() {
|
382 | throw new Error('Not implemented');
|
383 | }
|
384 | back() {
|
385 | throw new Error('Not implemented');
|
386 | }
|
387 |
|
388 | getState() {
|
389 | return undefined;
|
390 | }
|
391 | }
|
392 | ServerPlatformLocation.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerPlatformLocation, deps: [{ token: DOCUMENT }, { token: INITIAL_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
393 | ServerPlatformLocation.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerPlatformLocation });
|
394 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerPlatformLocation, decorators: [{
|
395 | type: Injectable
|
396 | }], ctorParameters: function () {
|
397 | return [{ type: undefined, decorators: [{
|
398 | type: Inject,
|
399 | args: [DOCUMENT]
|
400 | }] }, { type: undefined, decorators: [{
|
401 | type: Optional
|
402 | }, {
|
403 | type: Inject,
|
404 | args: [INITIAL_CONFIG]
|
405 | }] }];
|
406 | } });
|
407 | function scheduleMicroTask(fn) {
|
408 | Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
409 | }
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | class ServerEventManagerPlugin /* extends EventManagerPlugin which is private */ {
|
419 | constructor(doc) {
|
420 | this.doc = doc;
|
421 | }
|
422 |
|
423 | supports(eventName) {
|
424 | return true;
|
425 | }
|
426 | addEventListener(element, eventName, handler) {
|
427 | return ɵgetDOM().onAndCancel(element, eventName, handler);
|
428 | }
|
429 |
|
430 | addGlobalEventListener(element, eventName, handler) {
|
431 | const target = ɵgetDOM().getGlobalEventTarget(this.doc, element);
|
432 | if (!target) {
|
433 | throw new Error(`Unsupported event target ${target} for event ${eventName}`);
|
434 | }
|
435 | return this.addEventListener(target, eventName, handler);
|
436 | }
|
437 | }
|
438 | ServerEventManagerPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerEventManagerPlugin , deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
439 | ServerEventManagerPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerEventManagerPlugin });
|
440 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerEventManagerPlugin , decorators: [{
|
441 | type: Injectable
|
442 | }], ctorParameters: function () {
|
443 | return [{ type: undefined, decorators: [{
|
444 | type: Inject,
|
445 | args: [DOCUMENT]
|
446 | }] }];
|
447 | } });
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 | const EMPTY_ARRAY = [];
|
457 | const DEFAULT_SCHEMA = new DomElementSchemaRegistry();
|
458 | class ServerRendererFactory2 {
|
459 | constructor(eventManager, ngZone, document, sharedStylesHost) {
|
460 | this.eventManager = eventManager;
|
461 | this.ngZone = ngZone;
|
462 | this.document = document;
|
463 | this.sharedStylesHost = sharedStylesHost;
|
464 | this.rendererByCompId = new Map();
|
465 | this.schema = DEFAULT_SCHEMA;
|
466 | this.defaultRenderer = new DefaultServerRenderer2(eventManager, document, ngZone, this.schema);
|
467 | }
|
468 | createRenderer(element, type) {
|
469 | if (!element || !type) {
|
470 | return this.defaultRenderer;
|
471 | }
|
472 | switch (type.encapsulation) {
|
473 | case ViewEncapsulation.Emulated: {
|
474 | let renderer = this.rendererByCompId.get(type.id);
|
475 | if (!renderer) {
|
476 | renderer = new EmulatedEncapsulationServerRenderer2(this.eventManager, this.document, this.ngZone, this.sharedStylesHost, this.schema, type);
|
477 | this.rendererByCompId.set(type.id, renderer);
|
478 | }
|
479 | renderer.applyToHost(element);
|
480 | return renderer;
|
481 | }
|
482 | default: {
|
483 | if (!this.rendererByCompId.has(type.id)) {
|
484 | const styles = ɵflattenStyles(type.id, type.styles, []);
|
485 | this.sharedStylesHost.addStyles(styles);
|
486 | this.rendererByCompId.set(type.id, this.defaultRenderer);
|
487 | }
|
488 | return this.defaultRenderer;
|
489 | }
|
490 | }
|
491 | }
|
492 | begin() { }
|
493 | end() { }
|
494 | }
|
495 | ServerRendererFactory2.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerRendererFactory2, deps: [{ token: i1.EventManager }, { token: i0.NgZone }, { token: DOCUMENT }, { token: i1.ɵSharedStylesHost }], target: i0.ɵɵFactoryTarget.Injectable });
|
496 | ServerRendererFactory2.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerRendererFactory2 });
|
497 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerRendererFactory2, decorators: [{
|
498 | type: Injectable
|
499 | }], ctorParameters: function () {
|
500 | return [{ type: i1.EventManager }, { type: i0.NgZone }, { type: undefined, decorators: [{
|
501 | type: Inject,
|
502 | args: [DOCUMENT]
|
503 | }] }, { type: i1.ɵSharedStylesHost }];
|
504 | } });
|
505 | class DefaultServerRenderer2 {
|
506 | constructor(eventManager, document, ngZone, schema) {
|
507 | this.eventManager = eventManager;
|
508 | this.document = document;
|
509 | this.ngZone = ngZone;
|
510 | this.schema = schema;
|
511 | this.data = Object.create(null);
|
512 | this.destroyNode = null;
|
513 | }
|
514 | destroy() { }
|
515 | createElement(name, namespace, debugInfo) {
|
516 | if (namespace) {
|
517 | const doc = this.document || ɵgetDOM().getDefaultDocument();
|
518 | return doc.createElementNS(ɵNAMESPACE_URIS[namespace], name);
|
519 | }
|
520 | return ɵgetDOM().createElement(name, this.document);
|
521 | }
|
522 | createComment(value, debugInfo) {
|
523 | return ɵgetDOM().getDefaultDocument().createComment(value);
|
524 | }
|
525 | createText(value, debugInfo) {
|
526 | const doc = ɵgetDOM().getDefaultDocument();
|
527 | return doc.createTextNode(value);
|
528 | }
|
529 | appendChild(parent, newChild) {
|
530 | const targetParent = isTemplateNode(parent) ? parent.content : parent;
|
531 | targetParent.appendChild(newChild);
|
532 | }
|
533 | insertBefore(parent, newChild, refChild) {
|
534 | if (parent) {
|
535 | const targetParent = isTemplateNode(parent) ? parent.content : parent;
|
536 | targetParent.insertBefore(newChild, refChild);
|
537 | }
|
538 | }
|
539 | removeChild(parent, oldChild) {
|
540 | if (parent) {
|
541 | parent.removeChild(oldChild);
|
542 | }
|
543 | }
|
544 | selectRootElement(selectorOrNode, debugInfo) {
|
545 | let el;
|
546 | if (typeof selectorOrNode === 'string') {
|
547 | el = this.document.querySelector(selectorOrNode);
|
548 | if (!el) {
|
549 | throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
|
550 | }
|
551 | }
|
552 | else {
|
553 | el = selectorOrNode;
|
554 | }
|
555 | while (el.firstChild) {
|
556 | el.removeChild(el.firstChild);
|
557 | }
|
558 | return el;
|
559 | }
|
560 | parentNode(node) {
|
561 | return node.parentNode;
|
562 | }
|
563 | nextSibling(node) {
|
564 | return node.nextSibling;
|
565 | }
|
566 | setAttribute(el, name, value, namespace) {
|
567 | if (namespace) {
|
568 | el.setAttributeNS(ɵNAMESPACE_URIS[namespace], namespace + ':' + name, value);
|
569 | }
|
570 | else {
|
571 | el.setAttribute(name, value);
|
572 | }
|
573 | }
|
574 | removeAttribute(el, name, namespace) {
|
575 | if (namespace) {
|
576 | el.removeAttributeNS(ɵNAMESPACE_URIS[namespace], name);
|
577 | }
|
578 | else {
|
579 | el.removeAttribute(name);
|
580 | }
|
581 | }
|
582 | addClass(el, name) {
|
583 | el.classList.add(name);
|
584 | }
|
585 | removeClass(el, name) {
|
586 | el.classList.remove(name);
|
587 | }
|
588 | setStyle(el, style, value, flags) {
|
589 | style = style.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
590 | value = value == null ? '' : `${value}`.trim();
|
591 | const styleMap = _readStyleAttribute(el);
|
592 | if (flags & RendererStyleFlags2.Important) {
|
593 | value += ' !important';
|
594 | }
|
595 | styleMap[style] = value;
|
596 | _writeStyleAttribute(el, styleMap);
|
597 | }
|
598 | removeStyle(el, style, flags) {
|
599 |
|
600 |
|
601 | this.setStyle(el, style, '', flags);
|
602 | }
|
603 |
|
604 |
|
605 |
|
606 |
|
607 | _isSafeToReflectProperty(tagName, propertyName) {
|
608 | return this.schema.securityContext(tagName, propertyName, true) ===
|
609 | this.schema.securityContext(tagName, propertyName, false);
|
610 | }
|
611 | setProperty(el, name, value) {
|
612 | checkNoSyntheticProp(name, 'property');
|
613 | if (name === 'innerText') {
|
614 |
|
615 | el.textContent = value;
|
616 | }
|
617 | el[name] = value;
|
618 |
|
619 |
|
620 |
|
621 | const tagName = el.tagName.toLowerCase();
|
622 | if (value != null && (typeof value === 'number' || typeof value == 'string') &&
|
623 | name.toLowerCase() !== 'innerhtml' && this.schema.hasElement(tagName, EMPTY_ARRAY) &&
|
624 | this.schema.hasProperty(tagName, name, EMPTY_ARRAY) &&
|
625 | this._isSafeToReflectProperty(tagName, name)) {
|
626 | this.setAttribute(el, name, value.toString());
|
627 | }
|
628 | }
|
629 | setValue(node, value) {
|
630 | node.textContent = value;
|
631 | }
|
632 | listen(target, eventName, callback) {
|
633 | checkNoSyntheticProp(eventName, 'listener');
|
634 | if (typeof target === 'string') {
|
635 | return this.eventManager.addGlobalEventListener(target, eventName, this.decoratePreventDefault(callback));
|
636 | }
|
637 | return this.eventManager.addEventListener(target, eventName, this.decoratePreventDefault(callback));
|
638 | }
|
639 | decoratePreventDefault(eventHandler) {
|
640 | return (event) => {
|
641 |
|
642 |
|
643 | if (event === Function) {
|
644 | return eventHandler;
|
645 | }
|
646 |
|
647 |
|
648 | const allowDefaultBehavior = this.ngZone.runGuarded(() => eventHandler(event));
|
649 | if (allowDefaultBehavior === false) {
|
650 | event.preventDefault();
|
651 | event.returnValue = false;
|
652 | }
|
653 | return undefined;
|
654 | };
|
655 | }
|
656 | }
|
657 | const AT_CHARCODE = '@'.charCodeAt(0);
|
658 | function checkNoSyntheticProp(name, nameKind) {
|
659 | if (name.charCodeAt(0) === AT_CHARCODE) {
|
660 | throw new Error(`Unexpected synthetic ${nameKind} ${name} found. Please make sure that:
|
661 | - Either \`BrowserAnimationsModule\` or \`NoopAnimationsModule\` are imported in your application.
|
662 | - 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).`);
|
663 | }
|
664 | }
|
665 | function isTemplateNode(node) {
|
666 | return node.tagName === 'TEMPLATE' && node.content !== undefined;
|
667 | }
|
668 | class EmulatedEncapsulationServerRenderer2 extends DefaultServerRenderer2 {
|
669 | constructor(eventManager, document, ngZone, sharedStylesHost, schema, component) {
|
670 | super(eventManager, document, ngZone, schema);
|
671 | this.component = component;
|
672 |
|
673 | const componentId = 's' + component.id;
|
674 | const styles = ɵflattenStyles(componentId, component.styles, []);
|
675 | sharedStylesHost.addStyles(styles);
|
676 | this.contentAttr = ɵshimContentAttribute(componentId);
|
677 | this.hostAttr = ɵshimHostAttribute(componentId);
|
678 | }
|
679 | applyToHost(element) {
|
680 | super.setAttribute(element, this.hostAttr, '');
|
681 | }
|
682 | createElement(parent, name) {
|
683 | const el = super.createElement(parent, name, this.document);
|
684 | super.setAttribute(el, this.contentAttr, '');
|
685 | return el;
|
686 | }
|
687 | }
|
688 | function _readStyleAttribute(element) {
|
689 | const styleMap = {};
|
690 | const styleAttribute = element.getAttribute('style');
|
691 | if (styleAttribute) {
|
692 | const styleList = styleAttribute.split(/;+/g);
|
693 | for (let i = 0; i < styleList.length; i++) {
|
694 | const style = styleList[i].trim();
|
695 | if (style.length > 0) {
|
696 | const colonIndex = style.indexOf(':');
|
697 | if (colonIndex === -1) {
|
698 | throw new Error(`Invalid CSS style: ${style}`);
|
699 | }
|
700 | const name = style.slice(0, colonIndex).trim();
|
701 | styleMap[name] = style.slice(colonIndex + 1).trim();
|
702 | }
|
703 | }
|
704 | }
|
705 | return styleMap;
|
706 | }
|
707 | function _writeStyleAttribute(element, styleMap) {
|
708 |
|
709 |
|
710 |
|
711 | let styleAttrValue = '';
|
712 | for (const key in styleMap) {
|
713 | const newValue = styleMap[key];
|
714 | if (newValue != null && newValue !== '') {
|
715 | styleAttrValue += key + ':' + newValue + ';';
|
716 | }
|
717 | }
|
718 | if (styleAttrValue) {
|
719 | element.setAttribute('style', styleAttrValue);
|
720 | }
|
721 | else {
|
722 | element.removeAttribute('style');
|
723 | }
|
724 | }
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 | class ServerStylesHost extends ɵSharedStylesHost {
|
734 | constructor(doc, transitionId) {
|
735 | super();
|
736 | this.doc = doc;
|
737 | this.transitionId = transitionId;
|
738 | this.head = null;
|
739 | this._styleNodes = new Set();
|
740 | this.head = doc.getElementsByTagName('head')[0];
|
741 | }
|
742 | _addStyle(style) {
|
743 | let adapter = ɵgetDOM();
|
744 | const el = adapter.createElement('style');
|
745 | el.textContent = style;
|
746 | if (!!this.transitionId) {
|
747 | el.setAttribute('ng-transition', this.transitionId);
|
748 | }
|
749 | this.head.appendChild(el);
|
750 | this._styleNodes.add(el);
|
751 | }
|
752 | onStylesAdded(additions) {
|
753 | additions.forEach(style => this._addStyle(style));
|
754 | }
|
755 | ngOnDestroy() {
|
756 | this._styleNodes.forEach(styleNode => styleNode.remove());
|
757 | }
|
758 | }
|
759 | ServerStylesHost.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerStylesHost, deps: [{ token: DOCUMENT }, { token: ɵTRANSITION_ID, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
760 | ServerStylesHost.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerStylesHost });
|
761 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerStylesHost, decorators: [{
|
762 | type: Injectable
|
763 | }], ctorParameters: function () {
|
764 | return [{ type: undefined, decorators: [{
|
765 | type: Inject,
|
766 | args: [DOCUMENT]
|
767 | }] }, { type: undefined, decorators: [{
|
768 | type: Optional
|
769 | }, {
|
770 | type: Inject,
|
771 | args: [ɵTRANSITION_ID]
|
772 | }] }];
|
773 | } });
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 | const INTERNAL_SERVER_PLATFORM_PROVIDERS = [
|
783 | { provide: DOCUMENT, useFactory: _document, deps: [Injector] },
|
784 | { provide: PLATFORM_ID, useValue: ɵPLATFORM_SERVER_ID },
|
785 | { provide: PLATFORM_INITIALIZER, useFactory: initDominoAdapter, multi: true, deps: [Injector] }, {
|
786 | provide: PlatformLocation,
|
787 | useClass: ServerPlatformLocation,
|
788 | deps: [DOCUMENT, [Optional, INITIAL_CONFIG]]
|
789 | },
|
790 | { provide: PlatformState, deps: [DOCUMENT] },
|
791 |
|
792 | { provide: ɵALLOW_MULTIPLE_PLATFORMS, useValue: true }
|
793 | ];
|
794 | function initDominoAdapter(injector) {
|
795 | return () => {
|
796 | DominoAdapter.makeCurrent();
|
797 | };
|
798 | }
|
799 | function instantiateServerRendererFactory(renderer, engine, zone) {
|
800 | return new ɵAnimationRendererFactory(renderer, engine, zone);
|
801 | }
|
802 | const SERVER_RENDER_PROVIDERS = [
|
803 | ServerRendererFactory2,
|
804 | {
|
805 | provide: RendererFactory2,
|
806 | useFactory: instantiateServerRendererFactory,
|
807 | deps: [ServerRendererFactory2, ɵAnimationEngine, NgZone]
|
808 | },
|
809 | ServerStylesHost,
|
810 | { provide: ɵSharedStylesHost, useExisting: ServerStylesHost },
|
811 | { provide: EVENT_MANAGER_PLUGINS, multi: true, useClass: ServerEventManagerPlugin },
|
812 | ];
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 | class ServerModule {
|
819 | }
|
820 | ServerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
821 | ServerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.4", ngImport: i0, type: ServerModule, imports: [HttpClientModule, NoopAnimationsModule], exports: [BrowserModule] });
|
822 | ServerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerModule, providers: [
|
823 | SERVER_RENDER_PROVIDERS,
|
824 | SERVER_HTTP_PROVIDERS,
|
825 | { provide: Testability, useValue: null },
|
826 | { provide: ɵTESTABILITY, useValue: null },
|
827 | { provide: ViewportScroller, useClass: ɵNullViewportScroller },
|
828 | ], imports: [HttpClientModule, NoopAnimationsModule, BrowserModule] });
|
829 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerModule, decorators: [{
|
830 | type: NgModule,
|
831 | args: [{
|
832 | exports: [BrowserModule],
|
833 | imports: [HttpClientModule, NoopAnimationsModule],
|
834 | providers: [
|
835 | SERVER_RENDER_PROVIDERS,
|
836 | SERVER_HTTP_PROVIDERS,
|
837 | { provide: Testability, useValue: null },
|
838 | { provide: ɵTESTABILITY, useValue: null },
|
839 | { provide: ViewportScroller, useClass: ɵNullViewportScroller },
|
840 | ],
|
841 | }]
|
842 | }] });
|
843 | function _document(injector) {
|
844 | let config = injector.get(INITIAL_CONFIG, null);
|
845 | const document = config && config.document ? parseDocument(config.document, config.url) :
|
846 | ɵgetDOM().createHtmlDocument();
|
847 |
|
848 | ɵsetDocument(document);
|
849 | return document;
|
850 | }
|
851 |
|
852 |
|
853 |
|
854 | const platformServer = createPlatformFactory(platformCore, 'server', INTERNAL_SERVER_PLATFORM_PROVIDERS);
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 | const platformDynamicServer = createPlatformFactory(ɵplatformCoreDynamic, 'serverDynamic', INTERNAL_SERVER_PLATFORM_PROVIDERS);
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 | function serializeTransferStateFactory(doc, appId, transferStore) {
|
870 | return () => {
|
871 | const script = doc.createElement('script');
|
872 | script.id = appId + '-state';
|
873 | script.setAttribute('type', 'application/json');
|
874 | script.textContent = ɵescapeHtml(transferStore.toJson());
|
875 | doc.body.appendChild(script);
|
876 | };
|
877 | }
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 | class ServerTransferStateModule {
|
885 | }
|
886 | ServerTransferStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerTransferStateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
887 | ServerTransferStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.4", ngImport: i0, type: ServerTransferStateModule });
|
888 | ServerTransferStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerTransferStateModule, providers: [
|
889 | TransferState, {
|
890 | provide: BEFORE_APP_SERIALIZED,
|
891 | useFactory: serializeTransferStateFactory,
|
892 | deps: [DOCUMENT, APP_ID, TransferState],
|
893 | multi: true,
|
894 | }
|
895 | ] });
|
896 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: ServerTransferStateModule, decorators: [{
|
897 | type: NgModule,
|
898 | args: [{
|
899 | providers: [
|
900 | TransferState, {
|
901 | provide: BEFORE_APP_SERIALIZED,
|
902 | useFactory: serializeTransferStateFactory,
|
903 | deps: [DOCUMENT, APP_ID, TransferState],
|
904 | multi: true,
|
905 | }
|
906 | ]
|
907 | }]
|
908 | }] });
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 | function _getPlatform(platformFactory, options) {
|
918 | var _a;
|
919 | const extraProviders = (_a = options.platformProviders) !== null && _a !== void 0 ? _a : [];
|
920 | return platformFactory([
|
921 | { provide: INITIAL_CONFIG, useValue: { document: options.document, url: options.url } },
|
922 | extraProviders
|
923 | ]);
|
924 | }
|
925 | function _render(platform, bootstrapPromise) {
|
926 | return bootstrapPromise.then((moduleOrApplicationRef) => {
|
927 | const environmentInjector = moduleOrApplicationRef.injector;
|
928 | const transitionId = environmentInjector.get(ɵTRANSITION_ID, null);
|
929 | if (!transitionId) {
|
930 | throw new Error(`renderModule[Factory]() requires the use of BrowserModule.withServerTransition() to ensure
|
931 | the server-rendered app can be properly bootstrapped into a client app.`);
|
932 | }
|
933 | const applicationRef = moduleOrApplicationRef instanceof ApplicationRef ?
|
934 | moduleOrApplicationRef :
|
935 | environmentInjector.get(ApplicationRef);
|
936 | return applicationRef.isStable.pipe((first((isStable) => isStable)))
|
937 | .toPromise()
|
938 | .then(() => {
|
939 | const platformState = platform.injector.get(PlatformState);
|
940 | const asyncPromises = [];
|
941 |
|
942 | const callbacks = environmentInjector.get(BEFORE_APP_SERIALIZED, null);
|
943 | if (callbacks) {
|
944 | for (const callback of callbacks) {
|
945 | try {
|
946 | const callbackResult = callback();
|
947 | if (ɵisPromise(callbackResult)) {
|
948 |
|
949 | asyncPromises.push(callbackResult);
|
950 | }
|
951 | }
|
952 | catch (e) {
|
953 |
|
954 | console.warn('Ignoring BEFORE_APP_SERIALIZED Exception: ', e);
|
955 | }
|
956 | }
|
957 | }
|
958 | const complete = () => {
|
959 | const output = platformState.renderToString();
|
960 | platform.destroy();
|
961 | return output;
|
962 | };
|
963 | if (asyncPromises.length === 0) {
|
964 | return complete();
|
965 | }
|
966 | return Promise
|
967 | .all(asyncPromises.map(asyncPromise => {
|
968 | return asyncPromise.catch(e => {
|
969 | console.warn('Ignoring BEFORE_APP_SERIALIZED Exception: ', e);
|
970 | });
|
971 | }))
|
972 | .then(complete);
|
973 | });
|
974 | });
|
975 | }
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 | function renderModule(module, options) {
|
986 | const { document, url, extraProviders: platformProviders } = options;
|
987 | const platform = _getPlatform(platformDynamicServer, { document, url, platformProviders });
|
988 | return _render(platform, platform.bootstrapModule(module));
|
989 | }
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 | function renderApplication(rootComponent, options) {
|
1021 | var _a;
|
1022 | const { document, url, platformProviders, appId } = options;
|
1023 | const platform = _getPlatform(platformDynamicServer, { document, url, platformProviders });
|
1024 | const appProviders = [
|
1025 | importProvidersFrom(BrowserModule.withServerTransition({ appId })),
|
1026 | importProvidersFrom(ServerModule),
|
1027 | ...((_a = options.providers) !== null && _a !== void 0 ? _a : []),
|
1028 | ];
|
1029 | return _render(platform, ɵinternalBootstrapApplication({ rootComponent, appProviders }));
|
1030 | }
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 | function renderModuleFactory(moduleFactory, options) {
|
1045 | const { document, url, extraProviders: platformProviders } = options;
|
1046 | const platform = _getPlatform(platformServer, { document, url, platformProviders });
|
1047 | return _render(platform, platform.bootstrapModuleFactory(moduleFactory));
|
1048 | }
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 | const VERSION = new Version('14.0.4');
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 | 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_RENDER_PROVIDERS as ɵSERVER_RENDER_PROVIDERS, ServerRendererFactory2 as ɵServerRendererFactory2, setDomTypes as ɵsetDomTypes };
|
1100 |
|