import { isPlatformBrowser } from '@angular/common'; import { InjectionToken, PLATFORM_ID, Injectable } from '@angular/core'; import * as i0 from "@angular/core"; /** * Create a new injection token for injecting the Document into a component. */ export const DOCUMENT = new InjectionToken('DocumentToken'); /** * Define abstract class for obtaining reference to the global Document object. */ export class DocumentRef { get nativeDocument() { throw new Error('Not implemented.'); } } /** * Define class that implements the abstract class and returns the native Document object. */ class BrowserDocumentRef extends DocumentRef { constructor() { super(); } /** * @returns Document object */ get nativeDocument() { return document; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BrowserDocumentRef, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BrowserDocumentRef }); } export { BrowserDocumentRef }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BrowserDocumentRef, decorators: [{ type: Injectable }], ctorParameters: function () { return []; } }); /** * Create an factory function that returns the native Document object. * @param browserDocumentRef Native Document object * @param platformId id of platform * @returns type of platform of empty object */ export function documentFactory(browserDocumentRef, platformId) { if (isPlatformBrowser(platformId)) { return browserDocumentRef.nativeDocument; } const doc = { hidden: false, visibilityState: 'visible' }; return doc; } /** * Create a injectable provider for the DocumentRef token that uses the BrowserDocumentRef class. */ export const browserDocumentProvider = { provide: DocumentRef, useClass: BrowserDocumentRef }; /** * Create an injectable provider that uses the DocumentFactory function for returning the native Document object. */ export const documentProvider = { provide: DOCUMENT, useFactory: documentFactory, deps: [DocumentRef, PLATFORM_ID] }; /** * Create an array of providers. */ export const DOCUMENT_PROVIDERS = [browserDocumentProvider, documentProvider]; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG9jdW1lbnQtcmVmLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9saWJzL25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