import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Input, Output, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; const INPUTSWITCH_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => InputSwitch), multi: true }; class InputSwitch { constructor(cd) { this.cd = cd; this.onChange = new EventEmitter(); this.checked = false; this.focused = false; this.onModelChange = () => { }; this.onModelTouched = () => { }; } onClick(event, cb) { if (!this.disabled && !this.readonly) { event.preventDefault(); this.toggle(event); cb.focus(); } } onInputChange(event) { if (!this.readonly) { const inputChecked = event.target.checked; this.updateModel(event, inputChecked); } } toggle(event) { this.updateModel(event, !this.checked); } updateModel(event, value) { this.checked = value; this.onModelChange(this.checked); this.onChange.emit({ originalEvent: event, checked: this.checked }); } onFocus(event) { this.focused = true; } onBlur(event) { this.focused = false; this.onModelTouched(); } writeValue(checked) { this.checked = checked; this.cd.markForCheck(); } registerOnChange(fn) { this.onModelChange = fn; } registerOnTouched(fn) { this.onModelTouched = fn; } setDisabledState(val) { this.disabled = val; this.cd.markForCheck(); } } InputSwitch.decorators = [ { type: Component, args: [{ selector: 'p-inputSwitch', template: `