1 | import * as i0 from '@angular/core';
|
2 | import { InjectionToken, inject, EventEmitter, Injectable, Optional, Inject, Directive, Output, Input, NgModule } from '@angular/core';
|
3 | import { DOCUMENT } from '@angular/common';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const DIR_DOCUMENT = new InjectionToken('cdk-dir-doc', {
|
21 | providedIn: 'root',
|
22 | factory: DIR_DOCUMENT_FACTORY,
|
23 | });
|
24 |
|
25 | function DIR_DOCUMENT_FACTORY() {
|
26 | return inject(DOCUMENT);
|
27 | }
|
28 |
|
29 |
|
30 | 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;
|
31 |
|
32 | function _resolveDirectionality(rawValue) {
|
33 | const value = rawValue?.toLowerCase() || '';
|
34 | if (value === 'auto' && typeof navigator !== 'undefined' && navigator?.language) {
|
35 | return RTL_LOCALE_PATTERN.test(navigator.language) ? 'rtl' : 'ltr';
|
36 | }
|
37 | return value === 'rtl' ? 'rtl' : 'ltr';
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | class Directionality {
|
44 | constructor(_document) {
|
45 |
|
46 | this.value = 'ltr';
|
47 |
|
48 | this.change = new EventEmitter();
|
49 | if (_document) {
|
50 | const bodyDir = _document.body ? _document.body.dir : null;
|
51 | const htmlDir = _document.documentElement ? _document.documentElement.dir : null;
|
52 | this.value = _resolveDirectionality(bodyDir || htmlDir || 'ltr');
|
53 | }
|
54 | }
|
55 | ngOnDestroy() {
|
56 | this.change.complete();
|
57 | }
|
58 | static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: Directionality, deps: [{ token: DIR_DOCUMENT, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
59 | static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: Directionality, providedIn: 'root' }); }
|
60 | }
|
61 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: Directionality, decorators: [{
|
62 | type: Injectable,
|
63 | args: [{ providedIn: 'root' }]
|
64 | }], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
65 | type: Optional
|
66 | }, {
|
67 | type: Inject,
|
68 | args: [DIR_DOCUMENT]
|
69 | }] }]; } });
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | class Dir {
|
78 | constructor() {
|
79 |
|
80 | this._dir = 'ltr';
|
81 |
|
82 | this._isInitialized = false;
|
83 |
|
84 | this.change = new EventEmitter();
|
85 | }
|
86 |
|
87 | get dir() {
|
88 | return this._dir;
|
89 | }
|
90 | set dir(value) {
|
91 | const previousValue = this._dir;
|
92 |
|
93 |
|
94 |
|
95 | this._dir = _resolveDirectionality(value);
|
96 | this._rawDir = value;
|
97 | if (previousValue !== this._dir && this._isInitialized) {
|
98 | this.change.emit(this._dir);
|
99 | }
|
100 | }
|
101 |
|
102 | get value() {
|
103 | return this.dir;
|
104 | }
|
105 |
|
106 | ngAfterContentInit() {
|
107 | this._isInitialized = true;
|
108 | }
|
109 | ngOnDestroy() {
|
110 | this.change.complete();
|
111 | }
|
112 | static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: Dir, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
113 | static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: Dir, selector: "[dir]", inputs: { dir: "dir" }, outputs: { change: "dirChange" }, host: { properties: { "attr.dir": "_rawDir" } }, providers: [{ provide: Directionality, useExisting: Dir }], exportAs: ["dir"], ngImport: i0 }); }
|
114 | }
|
115 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: Dir, decorators: [{
|
116 | type: Directive,
|
117 | args: [{
|
118 | selector: '[dir]',
|
119 | providers: [{ provide: Directionality, useExisting: Dir }],
|
120 | host: { '[attr.dir]': '_rawDir' },
|
121 | exportAs: 'dir',
|
122 | }]
|
123 | }], propDecorators: { change: [{
|
124 | type: Output,
|
125 | args: ['dirChange']
|
126 | }], dir: [{
|
127 | type: Input
|
128 | }] } });
|
129 |
|
130 | class BidiModule {
|
131 | static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BidiModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
132 | static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: BidiModule, declarations: [Dir], exports: [Dir] }); }
|
133 | static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BidiModule }); }
|
134 | }
|
135 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: BidiModule, decorators: [{
|
136 | type: NgModule,
|
137 | args: [{
|
138 | exports: [Dir],
|
139 | declarations: [Dir],
|
140 | }]
|
141 | }] });
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | export { BidiModule, DIR_DOCUMENT, Dir, Directionality };
|
148 |
|