UNPKG

8.12 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
3 typeof define === 'function' && define.amd ? define('@angular/cdk/bidi', ['exports', '@angular/core', '@angular/common'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.bidi = {}), global.ng.core, global.ng.common));
5}(this, (function (exports, i0, common) { 'use strict';
6
7 function _interopNamespace(e) {
8 if (e && e.__esModule) return e;
9 var n = Object.create(null);
10 if (e) {
11 Object.keys(e).forEach(function (k) {
12 if (k !== 'default') {
13 var d = Object.getOwnPropertyDescriptor(e, k);
14 Object.defineProperty(n, k, d.get ? d : {
15 enumerable: true,
16 get: function () {
17 return e[k];
18 }
19 });
20 }
21 });
22 }
23 n['default'] = e;
24 return Object.freeze(n);
25 }
26
27 var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
29 /**
30 * @license
31 * Copyright Google LLC All Rights Reserved.
32 *
33 * Use of this source code is governed by an MIT-style license that can be
34 * found in the LICENSE file at https://angular.io/license
35 */
36 /**
37 * Injection token used to inject the document into Directionality.
38 * This is used so that the value can be faked in tests.
39 *
40 * We can't use the real document in tests because changing the real `dir` causes geometry-based
41 * tests in Safari to fail.
42 *
43 * We also can't re-provide the DOCUMENT token from platform-brower because the unit tests
44 * themselves use things like `querySelector` in test code.
45 *
46 * This token is defined in a separate file from Directionality as a workaround for
47 * https://github.com/angular/angular/issues/22559
48 *
49 * @docs-private
50 */
51 var DIR_DOCUMENT = new i0.InjectionToken('cdk-dir-doc', {
52 providedIn: 'root',
53 factory: DIR_DOCUMENT_FACTORY,
54 });
55 /** @docs-private */
56 function DIR_DOCUMENT_FACTORY() {
57 return i0.inject(common.DOCUMENT);
58 }
59
60 /**
61 * @license
62 * Copyright Google LLC All Rights Reserved.
63 *
64 * Use of this source code is governed by an MIT-style license that can be
65 * found in the LICENSE file at https://angular.io/license
66 */
67 /**
68 * The directionality (LTR / RTL) context for the application (or a subtree of it).
69 * Exposes the current direction and a stream of direction changes.
70 */
71 var Directionality = /** @class */ (function () {
72 function Directionality(_document) {
73 /** The current 'ltr' or 'rtl' value. */
74 this.value = 'ltr';
75 /** Stream that emits whenever the 'ltr' / 'rtl' state changes. */
76 this.change = new i0.EventEmitter();
77 if (_document) {
78 // TODO: handle 'auto' value -
79 // We still need to account for dir="auto".
80 // It looks like HTMLElemenet.dir is also "auto" when that's set to the attribute,
81 // but getComputedStyle return either "ltr" or "rtl". avoiding getComputedStyle for now
82 var bodyDir = _document.body ? _document.body.dir : null;
83 var htmlDir = _document.documentElement ? _document.documentElement.dir : null;
84 var value = bodyDir || htmlDir;
85 this.value = (value === 'ltr' || value === 'rtl') ? value : 'ltr';
86 }
87 }
88 Directionality.prototype.ngOnDestroy = function () {
89 this.change.complete();
90 };
91 return Directionality;
92 }());
93 Directionality.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Directionality_Factory() { return new Directionality(i0__namespace.ɵɵinject(DIR_DOCUMENT, 8)); }, token: Directionality, providedIn: "root" });
94 Directionality.decorators = [
95 { type: i0.Injectable, args: [{ providedIn: 'root' },] }
96 ];
97 Directionality.ctorParameters = function () { return [
98 { type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [DIR_DOCUMENT,] }] }
99 ]; };
100
101 /**
102 * @license
103 * Copyright Google LLC All Rights Reserved.
104 *
105 * Use of this source code is governed by an MIT-style license that can be
106 * found in the LICENSE file at https://angular.io/license
107 */
108 /**
109 * Directive to listen for changes of direction of part of the DOM.
110 *
111 * Provides itself as Directionality such that descendant directives only need to ever inject
112 * Directionality to get the closest direction.
113 */
114 var Dir = /** @class */ (function () {
115 function Dir() {
116 /** Normalized direction that accounts for invalid/unsupported values. */
117 this._dir = 'ltr';
118 /** Whether the `value` has been set to its initial value. */
119 this._isInitialized = false;
120 /** Event emitted when the direction changes. */
121 this.change = new i0.EventEmitter();
122 }
123 Object.defineProperty(Dir.prototype, "dir", {
124 /** @docs-private */
125 get: function () { return this._dir; },
126 set: function (value) {
127 var old = this._dir;
128 var normalizedValue = value ? value.toLowerCase() : value;
129 this._rawDir = value;
130 this._dir = (normalizedValue === 'ltr' || normalizedValue === 'rtl') ? normalizedValue : 'ltr';
131 if (old !== this._dir && this._isInitialized) {
132 this.change.emit(this._dir);
133 }
134 },
135 enumerable: false,
136 configurable: true
137 });
138 Object.defineProperty(Dir.prototype, "value", {
139 /** Current layout direction of the element. */
140 get: function () { return this.dir; },
141 enumerable: false,
142 configurable: true
143 });
144 /** Initialize once default value has been set. */
145 Dir.prototype.ngAfterContentInit = function () {
146 this._isInitialized = true;
147 };
148 Dir.prototype.ngOnDestroy = function () {
149 this.change.complete();
150 };
151 return Dir;
152 }());
153 Dir.decorators = [
154 { type: i0.Directive, args: [{
155 selector: '[dir]',
156 providers: [{ provide: Directionality, useExisting: Dir }],
157 host: { '[attr.dir]': '_rawDir' },
158 exportAs: 'dir',
159 },] }
160 ];
161 Dir.propDecorators = {
162 change: [{ type: i0.Output, args: ['dirChange',] }],
163 dir: [{ type: i0.Input }]
164 };
165
166 /**
167 * @license
168 * Copyright Google LLC All Rights Reserved.
169 *
170 * Use of this source code is governed by an MIT-style license that can be
171 * found in the LICENSE file at https://angular.io/license
172 */
173 var BidiModule = /** @class */ (function () {
174 function BidiModule() {
175 }
176 return BidiModule;
177 }());
178 BidiModule.decorators = [
179 { type: i0.NgModule, args: [{
180 exports: [Dir],
181 declarations: [Dir],
182 },] }
183 ];
184
185 /**
186 * @license
187 * Copyright Google LLC All Rights Reserved.
188 *
189 * Use of this source code is governed by an MIT-style license that can be
190 * found in the LICENSE file at https://angular.io/license
191 */
192
193 /**
194 * Generated bundle index. Do not edit.
195 */
196
197 exports.BidiModule = BidiModule;
198 exports.DIR_DOCUMENT = DIR_DOCUMENT;
199 exports.Dir = Dir;
200 exports.Directionality = Directionality;
201 exports.ɵangular_material_src_cdk_bidi_bidi_a = DIR_DOCUMENT_FACTORY;
202
203 Object.defineProperty(exports, '__esModule', { value: true });
204
205})));
206//# sourceMappingURL=cdk-bidi.umd.js.map