bidi.es5.js 7.0 KB

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