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EAAE;YACnB,QAAQ,EAAE,aAAa;YACvB,WAAW,EAAE,eAAe;YAC5B,SAAS,EAAE,CAAC,cAAc,CAAC;YAC3B,IAAI,EAAE;gBACJ,mCAAmC,EAAE,eAAe;gBACpD,6BAA6B,EAAE,SAAS;gBACxC,8BAA8B,EAAE,UAAU;gBAC1C,+BAA+B,EAAE,gBAAgB;gBACjD,6BAA6B,EAAE,UAAU;aAC1C;YACD,SAAS,EAAE,CAAC,kCAAkC,CAAC;YAC/C,aAAa,EAAE,iBAAiB,CAAC,IAAI;YACrC,eAAe,EAAE,uBAAuB,CAAC,MAAM;SAChD,CAAC;;kBAAA;IAwOF,iBAAC;AAAD,CAvOA,AAuOC,IAAA;AAOD;IAAA;IAOA,CAAC;IANQ,wBAAO,GAAd;QACE,MAAM,CAAC;YACL,QAAQ,EAAE,gBAAgB;YAC1B,SAAS,EAAE,EAAE;SACd,CAAC;IACJ,CAAC;IAVH;QAAC,QAAQ,CAAC;YACR,OAAO,EAAE,CAAC,UAAU,CAAC;YACrB,YAAY,EAAE,CAAC,UAAU,CAAC;SAC3B,CAAC;;wBAAA;IAQF,uBAAC;AAAD,CAPA,AAOC,IAAA","file":"checkbox/checkbox.js","sourcesContent":["import {\n    ChangeDetectionStrategy,\n    Component,\n    ElementRef,\n    EventEmitter,\n    Input,\n    Output,\n    Renderer,\n    ViewEncapsulation,\n    forwardRef,\n    NgModule,\n    ModuleWithProviders,\n} from '@angular/core';\nimport {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';\n\n/**\n * Monotonically increasing integer used to auto-generate unique ids for checkbox components.\n */\nlet nextId = 0;\n\n/**\n * Provider Expression that allows md-checkbox to register as a ControlValueAccessor. This allows it\n * to support [(ngModel)].\n */\nexport const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {\n  provide: NG_VALUE_ACCESSOR,\n  useExisting: forwardRef(() => MdCheckbox),\n  multi: true\n};\n\n/**\n * Represents the different states that require custom transitions between them.\n */\nexport enum TransitionCheckState {\n  /** The initial state of the component before any user interaction. */\n  Init,\n  /** The state representing the component when it's becoming checked. */\n  Checked,\n  /** The state representing the component when it's becoming unchecked. */\n  Unchecked,\n  /** The state representing the component when it's becoming indeterminate. */\n  Indeterminate\n}\n\n// A simple change event emitted by the MdCheckbox component.\nexport class MdCheckboxChange {\n  source: MdCheckbox;\n  checked: boolean;\n}\n\n/**\n * A material design checkbox component. Supports all of the functionality of an HTML5 checkbox,\n * and exposes a similar API. An MdCheckbox can be either checked, unchecked, indeterminate, or\n * disabled. Note that all additional accessibility attributes are taken care of by the component,\n * so there is no need to provide them yourself. However, if you want to omit a label and still\n * have the checkbox be accessible, you may supply an [aria-label] input.\n * See: https://www.google.com/design/spec/components/selection-controls.html\n */\n@Component({\n  moduleId: module.id,\n  selector: 'md-checkbox',\n  templateUrl: 'checkbox.html',\n  styleUrls: ['checkbox.css'],\n  host: {\n    '[class.md-checkbox-indeterminate]': 'indeterminate',\n    '[class.md-checkbox-checked]': 'checked',\n    '[class.md-checkbox-disabled]': 'disabled',\n    '[class.md-checkbox-align-end]': 'align == \"end\"',\n    '[class.md-checkbox-focused]': 'hasFocus',\n  },\n  providers: [MD_CHECKBOX_CONTROL_VALUE_ACCESSOR],\n  encapsulation: ViewEncapsulation.None,\n  changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class MdCheckbox implements ControlValueAccessor {\n  /**\n   * Attached to the aria-label attribute of the host element. In most cases, arial-labelledby will\n   * take precedence so this may be omitted.\n   */\n  @Input('aria-label') ariaLabel: string = '';\n\n  /**\n   * Users can specify the `aria-labelledby` attribute which will be forwarded to the input element\n   */\n  @Input('aria-labelledby') ariaLabelledby: string = null;\n\n  /** A unique id for the checkbox. If one is not supplied, it is auto-generated. */\n  @Input() id: string = `md-checkbox-${++nextId}`;\n\n  /** ID to be applied to the `input` element */\n  get inputId(): string {\n    return `input-${this.id}`;\n  }\n\n  /** Whether or not the checkbox should come before or after the label. */\n  @Input() align: 'start' | 'end' = 'start';\n\n  /**\n   * Whether the checkbox is disabled. When the checkbox is disabled it cannot be interacted with.\n   * The correct ARIA attributes are applied to denote this to assistive technology.\n   */\n  @Input() disabled: boolean = false;\n\n  /**\n   * The tabindex attribute for the checkbox. Note that when the checkbox is disabled, the attribute\n   * on the host element will be removed. It will be placed back when the checkbox is re-enabled.\n   */\n  @Input() tabindex: number = 0;\n\n  /** Name value will be applied to the input element if present */\n  @Input() name: string = null;\n\n  /** Event emitted when the checkbox's `checked` value changes. */\n  @Output() change: EventEmitter<MdCheckboxChange> = new EventEmitter<MdCheckboxChange>();\n\n  /** Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor. */\n  onTouched: () => any = () => {};\n\n  private _currentAnimationClass: string = '';\n\n  private _currentCheckState: TransitionCheckState = TransitionCheckState.Init;\n\n  private _checked: boolean = false;\n\n  private _indeterminate: boolean = false;\n\n  private _controlValueAccessorChangeFn: (value: any) => void = (value) => {};\n\n  hasFocus: boolean = false;\n\n  constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}\n\n  /**\n   * Whether the checkbox is checked. Note that setting `checked` will immediately set\n   * `indeterminate` to false.\n   */\n  @Input() get checked() {\n    return this._checked;\n  }\n\n  set checked(checked: boolean) {\n    if (checked != this.checked) {\n      this._indeterminate = false;\n      this._checked = checked;\n      this._transitionCheckState(\n          this._checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);\n    }\n  }\n\n  /**\n   * Whether the checkbox is indeterminate. This is also known as \"mixed\" mode and can be used to\n   * represent a checkbox with three states, e.g. a checkbox that represents a nested list of\n   * checkable items. Note that whenever `checked` is set, indeterminate is immediately set to\n   * false. This differs from the web platform in that indeterminate state on native\n   * checkboxes is only remove when the user manually checks the checkbox (rather than setting the\n   * `checked` property programmatically). However, we feel that this behavior is more accommodating\n   * to the way consumers would envision using this component.\n   */\n  @Input() get indeterminate() {\n    return this._indeterminate;\n  }\n\n  set indeterminate(indeterminate: boolean) {\n    this._indeterminate = indeterminate;\n    if (this._indeterminate) {\n      this._transitionCheckState(TransitionCheckState.Indeterminate);\n    } else {\n      this._transitionCheckState(\n          this.checked ? TransitionCheckState.Checked : TransitionCheckState.Unchecked);\n    }\n  }\n\n  /**\n   * Implemented as part of ControlValueAccessor.\n   * TODO: internal\n   */\n  writeValue(value: any) {\n    this.checked = !!value;\n  }\n\n  /**\n   * Implemented as part of ControlValueAccessor.\n   * TODO: internal\n   */\n  registerOnChange(fn: (value: any) => void) {\n    this._controlValueAccessorChangeFn = fn;\n  }\n\n  /**\n   * Implemented as part of ControlValueAccessor.\n   * TODO: internal\n   */\n  registerOnTouched(fn: any) {\n    this.onTouched = fn;\n  }\n\n  private _transitionCheckState(newState: TransitionCheckState) {\n    let oldState = this._currentCheckState;\n    let renderer = this._renderer;\n    let elementRef = this._elementRef;\n\n    if (oldState === newState) {\n      return;\n    }\n    if (this._currentAnimationClass.length > 0) {\n      renderer.setElementClass(elementRef.nativeElement, this._currentAnimationClass, false);\n    }\n\n    this._currentAnimationClass = this._getAnimationClassForCheckStateTransition(\n        oldState, newState);\n    this._currentCheckState = newState;\n\n    if (this._currentAnimationClass.length > 0) {\n      renderer.setElementClass(elementRef.nativeElement, this._currentAnimationClass, true);\n    }\n  }\n\n  private _emitChangeEvent() {\n    let event = new MdCheckboxChange();\n    event.source = this;\n    event.checked = this.checked;\n\n    this._controlValueAccessorChangeFn(this.checked);\n    this.change.emit(event);\n  }\n\n  /** Informs the component when the input has focus so that we can style accordingly */\n  _onInputFocus() {\n    this.hasFocus = true;\n  }\n\n  /** Informs the component when we lose focus in order to style accordingly */\n  _onInputBlur() {\n    this.hasFocus = false;\n    this.onTouched();\n  }\n\n  /**\n   * Toggles the `checked` value between true and false\n   */\n  toggle() {\n    this.checked = !this.checked;\n  }\n\n  /**\n   * Event handler for checkbox input element.\n   * Toggles checked state if element is not disabled.\n   * @param event\n   */\n  _onInteractionEvent(event: Event) {\n    // We always have to stop propagation on the change event.\n    // Otherwise the change event, from the input element, will bubble up and\n    // emit its event object to the `change` output.\n    event.stopPropagation();\n\n    if (!this.disabled) {\n      this.toggle();\n\n      // Emit our custom change event if the native input emitted one.\n      // It is important to only emit it, if the native input triggered one, because\n      // we don't want to trigger a change event, when the `checked` variable changes for example.\n      this._emitChangeEvent();\n    }\n  }\n\n  _onInputClick(event: Event) {\n    // We have to stop propagation for click events on the visual hidden input element.\n    // By default, when a user clicks on a label element, a generated click event will be\n    // dispatched on the associated input element. Since we are using a label element as our\n    // root container, the click event on the `checkbox` will be executed twice.\n    // The real click event will bubble up, and the generated click event also tries to bubble up.\n    // This will lead to multiple click events.\n    // Preventing bubbling for the second event will solve that issue.\n    event.stopPropagation();\n  }\n\n  private _getAnimationClassForCheckStateTransition(\n      oldState: TransitionCheckState, newState: TransitionCheckState): string {\n    var animSuffix: string;\n\n    switch (oldState) {\n    case TransitionCheckState.Init:\n      // Handle edge case where user interacts with checkbox that does not have [(ngModel)] or\n      // [checked] bound to it.\n      if (newState === TransitionCheckState.Checked) {\n        animSuffix = 'unchecked-checked';\n      } else {\n        return '';\n      }\n      break;\n    case TransitionCheckState.Unchecked:\n      animSuffix = newState === TransitionCheckState.Checked ?\n          'unchecked-checked' : 'unchecked-indeterminate';\n      break;\n    case TransitionCheckState.Checked:\n      animSuffix = newState === TransitionCheckState.Unchecked ?\n          'checked-unchecked' : 'checked-indeterminate';\n      break;\n    case TransitionCheckState.Indeterminate:\n      animSuffix = newState === TransitionCheckState.Checked ?\n          'indeterminate-checked' : 'indeterminate-unchecked';\n    }\n\n    return `md-checkbox-anim-${animSuffix}`;\n  }\n}\n\n\n@NgModule({\n  exports: [MdCheckbox],\n  declarations: [MdCheckbox],\n})\nexport class MdCheckboxModule {\n  static forRoot(): ModuleWithProviders {\n    return {\n      ngModule: MdCheckboxModule,\n      providers: []\n    };\n  }\n}\n"],"sourceRoot":"/source/"}