{"version":3,"file":"ng-primitives-input.mjs","sources":["../../../../packages/ng-primitives/input/src/input/input-state.ts","../../../../packages/ng-primitives/input/src/input/input.ts","../../../../packages/ng-primitives/input/src/ng-primitives-input.ts"],"sourcesContent":["import { computed, Signal, signal, WritableSignal } from '@angular/core';\nimport { ngpAutofill } from 'ng-primitives/autofill';\nimport { ngpFormControl } from 'ng-primitives/form-field';\nimport { ngpInteractions } from 'ng-primitives/interactions';\nimport { injectElementRef } from 'ng-primitives/internal';\nimport { injectSearchState } from 'ng-primitives/search';\nimport { attrBinding, controlled, createPrimitive, deprecatedSetter } from 'ng-primitives/state';\nimport { NgpControlStatus, uniqueId } from 'ng-primitives/utils';\n\n/**\n * Public state surface for the Input primitive.\n */\nexport interface NgpInputState {\n  /**\n   * The id of the input.\n   */\n  readonly id: Signal<string>;\n\n  /**\n   * The form control state.\n   */\n  readonly status: Signal<NgpControlStatus>;\n\n  /**\n   * Whether the input is disabled.\n   */\n  readonly disabled: WritableSignal<boolean>;\n\n  /**\n   * Set the disabled state of the input.\n   * @param value The disabled state.\n   */\n  setDisabled(value: boolean): void;\n}\n\n/**\n * Inputs for configuring the Input primitive.\n */\nexport interface NgpInputProps {\n  /**\n   * The id of the input.\n   */\n  readonly id?: Signal<string>;\n  /**\n   * Whether the input is disabled.\n   */\n  readonly disabled?: Signal<boolean>;\n}\n\nexport const [NgpInputStateToken, ngpInput, injectInputState, provideInputState] = createPrimitive(\n  'NgpInput',\n  ({ id = signal(uniqueId('ngp-input')), disabled: _disabled = signal(false) }: NgpInputProps) => {\n    const element = injectElementRef<HTMLInputElement>();\n    const searchState = injectSearchState({ optional: true });\n    const disabled = controlled(_disabled);\n\n    // Setup autofill detection\n    ngpAutofill({});\n\n    // Setup interactions and form control bindings\n    const status = ngpFormControl({ id, disabled });\n    const isDisabled = computed(() => status().disabled ?? disabled());\n\n    ngpInteractions({ hover: true, press: true, focus: true, disabled: isDisabled });\n\n    // Host bindings\n    attrBinding(element, 'id', id);\n    attrBinding(element, 'disabled', () => (isDisabled() ? '' : null));\n\n    // Register the input with an enclosing search field if present\n    const search = searchState();\n\n    if (search) {\n      search.registerInput(element.nativeElement);\n    }\n\n    function setDisabled(value: boolean): void {\n      disabled.set(value);\n    }\n\n    return {\n      id,\n      disabled: deprecatedSetter(disabled, 'setDisabled', setDisabled),\n      status,\n      setDisabled,\n    } satisfies NgpInputState;\n  },\n);\n","import { BooleanInput } from '@angular/cdk/coercion';\nimport { booleanAttribute, Directive, input } from '@angular/core';\nimport { uniqueId } from 'ng-primitives/utils';\nimport { ngpInput, provideInputState } from './input-state';\n\n@Directive({\n  selector: 'input[ngpInput]',\n  exportAs: 'ngpInput',\n  providers: [provideInputState({ inherit: false })],\n})\nexport class NgpInput {\n  /**\n   * The id of the input.\n   */\n  readonly id = input(uniqueId('ngp-input'));\n\n  /**\n   * Whether the element is disabled.\n   */\n  readonly disabled = input<boolean, BooleanInput>(false, {\n    transform: booleanAttribute,\n  });\n\n  /**\n   * The input state.\n   */\n  protected readonly state = ngpInput({\n    id: this.id,\n    disabled: this.disabled,\n  });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;AAiDO,MAAM,CAAC,kBAAkB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,GAAG,eAAe,CAChG,UAAU,EACV,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,EAAiB,KAAI;AAC7F,IAAA,MAAM,OAAO,GAAG,gBAAgB,EAAoB;IACpD,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AACzD,IAAA,MAAM,QAAQ,GAAG,UAAU,CAAC,SAAS,CAAC;;IAGtC,WAAW,CAAC,EAAE,CAAC;;IAGf,MAAM,MAAM,GAAG,cAAc,CAAC,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