/** * @license Angular v19.2.13 * (c) 2010-2025 Google LLC. https://angular.io/ * License: MIT */ import * as i0 from '@angular/core'; import { InjectionToken, Directive, forwardRef, Optional, Inject, ɵisPromise as _isPromise, ɵisSubscribable as _isSubscribable, ɵRuntimeError as _RuntimeError, Self, untracked, computed, signal, EventEmitter, Input, Host, SkipSelf, booleanAttribute, ChangeDetectorRef, Output, inject, Injectable, NgModule, Version } from '@angular/core'; import { ɵgetDOM as _getDOM } from '@angular/common'; import { from, forkJoin, Subject } from 'rxjs'; import { map } from 'rxjs/operators'; /** * Base class for all ControlValueAccessor classes defined in Forms package. * Contains common logic and utility functions. * * Note: this is an *internal-only* class and should not be extended or used directly in * applications code. */ class BaseControlValueAccessor { _renderer; _elementRef; /** * The registered callback function called when a change or input event occurs on the input * element. * @docs-private */ onChange = (_) => { }; /** * The registered callback function called when a blur event occurs on the input element. * @docs-private */ onTouched = () => { }; constructor(_renderer, _elementRef) { this._renderer = _renderer; this._elementRef = _elementRef; } /** * Helper method that sets a property on a target element using the current Renderer * implementation. * @docs-private */ setProperty(key, value) { this._renderer.setProperty(this._elementRef.nativeElement, key, value); } /** * Registers a function called when the control is touched. * @docs-private */ registerOnTouched(fn) { this.onTouched = fn; } /** * Registers a function called when the control value changes. * @docs-private */ registerOnChange(fn) { this.onChange = fn; } /** * Sets the "disabled" property on the range input element. * @docs-private */ setDisabledState(isDisabled) { this.setProperty('disabled', isDisabled); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: BaseControlValueAccessor, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.13", type: BaseControlValueAccessor, isStandalone: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: BaseControlValueAccessor, decorators: [{ type: Directive }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }] }); /** * Base class for all built-in ControlValueAccessor classes (except DefaultValueAccessor, which is * used in case no other CVAs can be found). We use this class to distinguish between default CVA, * built-in CVAs and custom CVAs, so that Forms logic can recognize built-in CVAs and treat custom * ones with higher priority (when both built-in and custom CVAs are present). * * Note: this is an *internal-only* class and should not be extended or used directly in * applications code. */ class BuiltInControlValueAccessor extends BaseControlValueAccessor { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: BuiltInControlValueAccessor, deps: null, target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.13", type: BuiltInControlValueAccessor, isStandalone: true, usesInheritance: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: BuiltInControlValueAccessor, decorators: [{ type: Directive }] }); /** * Used to provide a `ControlValueAccessor` for form controls. * * See `DefaultValueAccessor` for how to implement one. * * @publicApi */ const NG_VALUE_ACCESSOR = new InjectionToken(ngDevMode ? 'NgValueAccessor' : ''); const CHECKBOX_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CheckboxControlValueAccessor), multi: true, }; /** * @description * A `ControlValueAccessor` for writing a value and listening to changes on a checkbox input * element. * * @usageNotes * * ### Using a checkbox with a reactive form. * * The following example shows how to use a checkbox with a reactive form. * * ```ts * const rememberLoginControl = new FormControl(); * ``` * * ```html * * ``` * * @ngModule ReactiveFormsModule * @ngModule FormsModule * @publicApi */ class CheckboxControlValueAccessor extends BuiltInControlValueAccessor { /** * Sets the "checked" property on the input element. * @docs-private */ writeValue(value) { this.setProperty('checked', value); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: CheckboxControlValueAccessor, deps: null, target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.13", type: CheckboxControlValueAccessor, isStandalone: false, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]", host: { listeners: { "change": "onChange($event.target.checked)", "blur": "onTouched()" } }, providers: [CHECKBOX_VALUE_ACCESSOR], usesInheritance: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: CheckboxControlValueAccessor, decorators: [{ type: Directive, args: [{ selector: 'input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]', host: { '(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()' }, providers: [CHECKBOX_VALUE_ACCESSOR], standalone: false, }] }] }); const DEFAULT_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DefaultValueAccessor), multi: true, }; /** * We must check whether the agent is Android because composition events * behave differently between iOS and Android. */ function _isAndroid() { const userAgent = _getDOM() ? _getDOM().getUserAgent() : ''; return /android (\d+)/.test(userAgent.toLowerCase()); } /** * @description * Provide this token to control if form directives buffer IME input until * the "compositionend" event occurs. * @publicApi */ const COMPOSITION_BUFFER_MODE = new InjectionToken(ngDevMode ? 'CompositionEventMode' : ''); /** * The default `ControlValueAccessor` for writing a value and listening to changes on input * elements. The accessor is used by the `FormControlDirective`, `FormControlName`, and * `NgModel` directives. * * * @usageNotes * * ### Using the default value accessor * * The following example shows how to use an input element that activates the default value accessor * (in this case, a text field). * * ```ts * const firstNameControl = new FormControl(); * ``` * * ```html * * ``` * * This value accessor is used by default for `` and `