/** * @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 */ import { EventEmitter, Inject, Injectable, Optional } from '@angular/core'; import { DIR_DOCUMENT } from './dir-document-token'; import * as i0 from "@angular/core"; /** Regex that matches locales with an RTL script. Taken from `goog.i18n.bidi.isRtlLanguage`. */ const RTL_LOCALE_PATTERN = /^(ar|ckb|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Adlm|Arab|Hebr|Nkoo|Rohg|Thaa))(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)/i; /** Resolves a string value to a specific direction. */ export function _resolveDirectionality(rawValue) { const value = rawValue?.toLowerCase() || ''; if (value === 'auto' && typeof navigator !== 'undefined' && navigator?.language) { return RTL_LOCALE_PATTERN.test(navigator.language) ? 'rtl' : 'ltr'; } return value === 'rtl' ? 'rtl' : 'ltr'; } /** * The directionality (LTR / RTL) context for the application (or a subtree of it). * Exposes the current direction and a stream of direction changes. */ export class Directionality { constructor(_document) { /** The current 'ltr' or 'rtl' value. */ this.value = 'ltr'; /** Stream that emits whenever the 'ltr' / 'rtl' state changes. */ this.change = new EventEmitter(); if (_document) { const bodyDir = _document.body ? _document.body.dir : null; const htmlDir = _document.documentElement ? _document.documentElement.dir : null; this.value = _resolveDirectionality(bodyDir || htmlDir || 'ltr'); } } ngOnDestroy() { this.change.complete(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: Directionality, deps: [{ token: DIR_DOCUMENT, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: Directionality, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: Directionality, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: undefined, decorators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