@angular/cdk
Version:
Angular Material Component Development Kit
69 lines • 7.76 kB
JavaScript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Directive, Output, Input, EventEmitter } from '@angular/core';
import { Directionality, _resolveDirectionality } from './directionality';
import * as i0 from "@angular/core";
/**
* Directive to listen for changes of direction of part of the DOM.
*
* Provides itself as Directionality such that descendant directives only need to ever inject
* Directionality to get the closest direction.
*/
export class Dir {
constructor() {
/** Normalized direction that accounts for invalid/unsupported values. */
this._dir = 'ltr';
/** Whether the `value` has been set to its initial value. */
this._isInitialized = false;
/** Event emitted when the direction changes. */
this.change = new EventEmitter();
}
/** @docs-private */
get dir() {
return this._dir;
}
set dir(value) {
const previousValue = this._dir;
// Note: `_resolveDirectionality` resolves the language based on the browser's language,
// whereas the browser does it based on the content of the element. Since doing so based
// on the content can be expensive, for now we're doing the simpler matching.
this._dir = _resolveDirectionality(value);
this._rawDir = value;
if (previousValue !== this._dir && this._isInitialized) {
this.change.emit(this._dir);
}
}
/** Current layout direction of the element. */
get value() {
return this.dir;
}
/** Initialize once default value has been set. */
ngAfterContentInit() {
this._isInitialized = true;
}
ngOnDestroy() {
this.change.complete();
}
}
Dir.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: Dir, deps: [], target: i0.ɵɵFactoryTarget.Directive });
Dir.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.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 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: Dir, decorators: [{
type: Directive,
args: [{
selector: '[dir]',
providers: [{ provide: Directionality, useExisting: Dir }],
host: { '[attr.dir]': '_rawDir' },
exportAs: 'dir',
}]
}], propDecorators: { change: [{
type: Output,
args: ['dirChange']
}], dir: [{
type: Input
}] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGlyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9iaWRpL2Rpci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsU0FBUyxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsWUFBWSxFQUE4QixNQUFNLGVBQWUsQ0FBQztBQUVsRyxPQUFPLEVBQVksY0FBYyxFQUFFLHNCQUFzQixFQUFDLE1BQU0sa0JBQWtCLENBQUM7O0FBRW5GOzs7OztHQUtHO0FBT0gsTUFBTSxPQUFPLEdBQUc7SUFOaEI7UUFPRSx5RUFBeUU7UUFDakUsU0FBSSxHQUFjLEtBQUssQ0FBQztRQUVoQyw2REFBNkQ7UUFDckQsbUJBQWMsR0FBWSxLQUFLLENBQUM7UUFLeEMsZ0RBQWdEO1FBQ2xCLFdBQU0sR0FBRyxJQUFJLFlBQVksRUFBYSxDQUFDO0tBa0N0RTtJQWhDQyxvQkFBb0I7SUFDcEIsSUFDSSxHQUFHO1FBQ0wsT0FBTyxJQUFJLENBQUMsSUFBSSxDQUFDO0lBQ25CLENBQUM7SUFDRCxJQUFJLEdBQUcsQ0FBQyxLQUF5QjtRQUMvQixNQUFNLGFBQWEsR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDO1FBRWhDLHdGQUF3RjtRQUN4Rix3RkFBd0Y7UUFDeEYsNkVBQTZFO1FBQzdFLElBQUksQ0FBQyxJQUFJLEdBQUcsc0JBQXNCLENBQUMsS0FBSyxDQUFDLENBQUM7UUFDMUMsSUFBSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7UUFFckIsSUFBSSxhQ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