123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import * as i0 from '@angular/core';
- import { InjectionToken, inject, EventEmitter, Injectable } from '@angular/core';
- import { DOCUMENT } from '@angular/common';
- /**
- * Injection token used to inject the document into Directionality.
- * This is used so that the value can be faked in tests.
- *
- * We can't use the real document in tests because changing the real `dir` causes geometry-based
- * tests in Safari to fail.
- *
- * We also can't re-provide the DOCUMENT token from platform-browser because the unit tests
- * themselves use things like `querySelector` in test code.
- *
- * This token is defined in a separate file from Directionality as a workaround for
- * https://github.com/angular/angular/issues/22559
- *
- * @docs-private
- */
- const DIR_DOCUMENT = new InjectionToken('cdk-dir-doc', {
- providedIn: 'root',
- factory: DIR_DOCUMENT_FACTORY,
- });
- /**
- * @docs-private
- * @deprecated No longer used, will be removed.
- * @breaking-change 21.0.0
- */
- function DIR_DOCUMENT_FACTORY() {
- return inject(DOCUMENT);
- }
- /** 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. */
- 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.
- */
- class Directionality {
- /** The current 'ltr' or 'rtl' value. */
- value = 'ltr';
- /** Stream that emits whenever the 'ltr' / 'rtl' state changes. */
- change = new EventEmitter();
- constructor() {
- const _document = inject(DIR_DOCUMENT, { optional: true });
- 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 ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: Directionality, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: Directionality, providedIn: 'root' });
- }
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: Directionality, decorators: [{
- type: Injectable,
- args: [{ providedIn: 'root' }]
- }], ctorParameters: () => [] });
- export { Directionality as D, _resolveDirectionality as _, DIR_DOCUMENT as a };
- //# sourceMappingURL=directionality-CBXD4hga.mjs.map
|