import { VERSION as CDK_VERSION } from '@angular/cdk' ; import { HighContrastModeDetector } from '@angular/cdk/a11y' ; import { _isTestEnvironment } from '@angular/cdk/platform' ; import { DOCUMENT } from '@angular/common' ; import { Inject , InjectionToken , NgModule , Optional } from '@angular/core' ; import { VERSION } from '../version' ; import { ɵvariant } from './variant' ; docs-private export function SBB_SANITY_CHECKS_FACTORY ( ) { return true ; } /** Injection token that configures whether the SBB sanity checks are enabled. */ export const SBB_SANITY_CHECKS = new InjectionToken < SanityChecks > ( 'sbb-sanity-checks' , { providedIn : 'root' , factory : SBB_SANITY_CHECKS_FACTORY , } ) ; /**
 * Possible sanity checks that can be enabled. If set to
 * true/false, all checks will be enabled/disabled.
 */ export type SanityChecks = boolean | GranularSanityChecks ; /** Object that can be used to configure the sanity checks granularly. */ export interface GranularSanityChecks { doctype : boolean ; typography : boolean ; version : boolean ; } /**
 * Module that captures anything that should be loaded and/or run for *all* sbb-angular
 * components. This includes variant, etc.
 *
 * This module should be imported to each top-level component module (e.g. SbbTabsModule).
 */ @ NgModule ( ) export class SbbCommonModule { /** Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype). */ private _hasDoneGlobalChecks = false ; constructor ( highContrastModeDetector , @ Optional ( ) @ Inject ( SBB_SANITY_CHECKS ) private _sanityChecks , @ Inject ( DOCUMENT ) private _document ) { ɵvariant . next ( this . _document . documentElement . classList . contains ( 'sbb-lean' ) ? 'lean' : 'standard' ) ; highContrastModeDetector . _applyBodyHighContrastModeCssClasses ( ) ; if ( ! this . _hasDoneGlobalChecks ) { this . _hasDoneGlobalChecks = true ; if ( typeof ngDevMode === 'undefined' || ngDevMode ) { if ( this . _checkIsEnabled ( 'doctype' ) ) { _checkDoctypeIsDefined ( this . _document ) ; } if ( this . _checkIsEnabled ( 'typography' ) ) { _checkTypographyIsPresent ( this . _document ) ; } if ( this . _checkIsEnabled ( 'version' ) ) { _checkCdkVersionMatch ( ) ; } } } } /** Gets whether a specific sanity check is enabled. */ private _checkIsEnabled ( name ) { if ( _isTestEnvironment ( ) ) { return false ; } if ( typeof this . _sanityChecks === 'boolean' ) { return this . _sanityChecks ; } return ! ! this . _sanityChecks [ name ] ; } } /** Checks that the page has a doctype. */ function _checkDoctypeIsDefined ( doc ) { if ( ! doc . doctype ) { console . warn ( 'Current document does not have a doctype. This may cause ' + 'some sbb-angular components not to behave as expected.' ) ; } } /** Checks that the typography has been included. */ function _checkTypographyIsPresent ( doc ) { if ( ! doc . body || typeof getComputedStyle !== 'function' ) { return ; } const missingScalingFactorVariable = ! getComputedStyle ( doc . documentElement ) . getPropertyValue ( '--sbb-scaling-factor' ) ; if ( missingScalingFactorVariable ) { console . warn ( 'Could not find @sbb-esta/angular typography. Most @sbb-esta/angular ' + 'components may not work as expected.' ) ; } } /** Checks whether the @sbb-esta/angular version matches the CDK major version. */ function _checkCdkVersionMatch ( ) { if ( VERSION . major !== CDK_VERSION . major ) { console . warn ( `The @sbb-esta/angular version (${ VERSION . full }) does not match the Angular CDK major version` + ` (${ CDK_VERSION . full }).\nPlease ensure the major versions of these two packages match.` ) ; } }