UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

1 lines 5.38 kB
{"version":3,"file":"_directionality-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/cdk/bidi/dir-document-token.ts","../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/cdk/bidi/directionality.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {inject, InjectionToken, DOCUMENT} from '@angular/core';\n\n/**\n * Injection token used to inject the document into Directionality.\n * This is used so that the value can be faked in tests.\n *\n * We can't use the real document in tests because changing the real `dir` causes geometry-based\n * tests in Safari to fail.\n *\n * We also can't re-provide the DOCUMENT token from platform-browser because the unit tests\n * themselves use things like `querySelector` in test code.\n *\n * This token is defined in a separate file from Directionality as a workaround for\n * https://github.com/angular/angular/issues/22559\n *\n * @docs-private\n */\nexport const DIR_DOCUMENT = new InjectionToken<Document>('cdk-dir-doc', {\n providedIn: 'root',\n factory: () => inject(DOCUMENT),\n});\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {EventEmitter, Injectable, OnDestroy, inject, signal} from '@angular/core';\nimport {DIR_DOCUMENT} from './dir-document-token';\n\nexport type Direction = 'ltr' | 'rtl';\n\n/** Regex that matches locales with an RTL script. Taken from `goog.i18n.bidi.isRtlLanguage`. */\nconst RTL_LOCALE_PATTERN =\n /^(ar|ckb|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Adlm|Arab|Hebr|Nkoo|Rohg|Thaa))(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)/i;\n\n/** Resolves a string value to a specific direction. */\nexport function _resolveDirectionality(rawValue: string): Direction {\n const value = rawValue?.toLowerCase() || '';\n\n if (value === 'auto' && typeof navigator !== 'undefined' && navigator?.language) {\n return RTL_LOCALE_PATTERN.test(navigator.language) ? 'rtl' : 'ltr';\n }\n\n return value === 'rtl' ? 'rtl' : 'ltr';\n}\n\n/**\n * The directionality (LTR / RTL) context for the application (or a subtree of it).\n * Exposes the current direction and a stream of direction changes.\n */\n@Injectable({providedIn: 'root'})\nexport class Directionality implements OnDestroy {\n /** The current 'ltr' or 'rtl' value. */\n get value() {\n return this.valueSignal();\n }\n\n /**\n * The current 'ltr' or 'rtl' value.\n */\n readonly valueSignal = signal<Direction>('ltr');\n\n /** Stream that emits whenever the 'ltr' / 'rtl' state changes. */\n readonly change = new EventEmitter<Direction>();\n\n constructor(...args: unknown[]);\n\n constructor() {\n const _document = inject(DIR_DOCUMENT, {optional: true});\n\n if (_document) {\n const bodyDir = _document.body ? _document.body.dir : null;\n const htmlDir = _document.documentElement ? _document.documentElement.dir : null;\n this.valueSignal.set(_resolveDirectionality(bodyDir || htmlDir || 'ltr'));\n }\n }\n\n ngOnDestroy() {\n this.change.complete();\n }\n}\n"],"names":["DIR_DOCUMENT","InjectionToken","providedIn","factory","inject","DOCUMENT","RTL_LOCALE_PATTERN","_resolveDirectionality","rawValue","value","toLowerCase","navigator","language","test","Directionality","valueSignal","signal","change","EventEmitter","constructor","_document","optional","bodyDir","body","dir","htmlDir","documentElement","set","ngOnDestroy","complete","deps","target","i0","ɵɵFactoryTarget","Injectable","ɵprov","ɵɵngDeclareInjectable","minVersion","version","ngImport","type","decorators"],"mappings":";;;MAyBaA,YAAY,GAAG,IAAIC,cAAc,CAAW,aAAa,EAAE;AACtEC,EAAAA,UAAU,EAAE,MAAM;AAClBC,EAAAA,OAAO,EAAEA,MAAMC,MAAM,CAACC,QAAQ;AAC/B,CAAA;;ACdD,MAAMC,kBAAkB,GACtB,oHAAoH;AAGhH,SAAUC,sBAAsBA,CAACC,QAAgB,EAAA;EACrD,MAAMC,KAAK,GAAGD,QAAQ,EAAEE,WAAW,EAAE,IAAI,EAAE;AAE3C,EAAA,IAAID,KAA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