cdk-bidi.umd.js 7.2 KB

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