UNPKG

@angular/platform-server

Version:

Angular - library for using Angular in Node.js

143 lines (135 loc) 3.92 kB
/** * @license Angular v13.3.8 * (c) 2010-2022 Google LLC. https://angular.io/ * License: MIT */ import { ɵsetRootDomAdapter } from '@angular/common'; import { ɵBrowserDomAdapter } from '@angular/platform-browser'; import * as domino from 'domino'; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function setDomTypes() { // Make all Domino types available in the global env. Object.assign(global, domino.impl); global['KeyboardEvent'] = domino.impl.Event; } /** * Parses a document string to a Document object. */ function parseDocument(html, url = '/') { let window = domino.createWindow(html, url); let doc = window.document; return doc; } /** * Serializes a document to string. */ function serializeDocument(doc) { return doc.serialize(); } /** * DOM Adapter for the server platform based on https://github.com/fgnass/domino. */ class DominoAdapter extends ɵBrowserDomAdapter { constructor() { super(...arguments); this.supportsDOMEvents = false; } static makeCurrent() { setDomTypes(); ɵsetRootDomAdapter(new DominoAdapter()); } createHtmlDocument() { return parseDocument('<html><head><title>fakeTitle</title></head><body></body></html>'); } getDefaultDocument() { if (!DominoAdapter.defaultDoc) { DominoAdapter.defaultDoc = domino.createDocument(); } return DominoAdapter.defaultDoc; } isElementNode(node) { return node ? node.nodeType === DominoAdapter.defaultDoc.ELEMENT_NODE : false; } isShadowRoot(node) { return node.shadowRoot == node; } /** @deprecated No longer being used in Ivy code. To be removed in version 14. */ getGlobalEventTarget(doc, target) { if (target === 'window') { return doc.defaultView; } if (target === 'document') { return doc; } if (target === 'body') { return doc.body; } return null; } getBaseHref(doc) { var _a; // TODO(alxhub): Need relative path logic from BrowserDomAdapter here? return ((_a = doc.documentElement.querySelector('base')) === null || _a === void 0 ? void 0 : _a.getAttribute('href')) || ''; } dispatchEvent(el, evt) { el.dispatchEvent(evt); // Dispatch the event to the window also. const doc = el.ownerDocument || el; const win = doc.defaultView; if (win) { win.dispatchEvent(evt); } } getUserAgent() { return 'Fake user agent'; } getCookie(name) { throw new Error('getCookie has not been implemented'); } } /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Apply the necessary shims to make DOM globals (such as `Element`, `HTMLElement`, etc.) available * on the environment. */ function applyShims() { setDomTypes(); } /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ applyShims(); /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Generated bundle index. Do not edit. */ //# sourceMappingURL=init.mjs.map