{"version":3,"file":"ngx-com-components-native-control.mjs","sources":["../../../projects/com/components/native-control/native-control.variants.ts","../../../projects/com/components/native-control/native-control.directive.ts","../../../projects/com/components/native-control/index.ts","../../../projects/com/components/native-control/ngx-com-components-native-control.ts"],"sourcesContent":["import { cva, type VariantProps } from 'class-variance-authority';\n\n/**\n * Size type for native control.\n */\nexport type NativeControlSize = 'sm' | 'default' | 'lg';\n\n/**\n * Visual variant for native control.\n */\nexport type NativeControlVariant = 'outline' | 'filled' | 'ghost';\n\n/**\n * CVA variants for the native control directive.\n *\n * @tokens `--color-input-border`, `--color-input-background`, `--color-input-foreground`,\n *         `--color-input-placeholder`, `--color-disabled`, `--color-disabled-foreground`,\n *         `--color-ring`, `--color-warn`, `--color-muted`, `--color-border`,\n *         `--radius-input`\n */\nexport const nativeControlVariants: (props?: {\n  variant?: NativeControlVariant;\n  size?: NativeControlSize;\n  error?: boolean;\n}) => string = cva(\n  [\n    'com-native-control',\n    'w-full',\n    'text-input-foreground',\n    'placeholder:text-input-placeholder',\n    'rounded-input',\n    'focus-visible:outline-[1px] focus-visible:outline-offset-2 focus-visible:outline-ring',\n    'disabled:bg-disabled disabled:text-disabled-foreground disabled:border-disabled disabled:cursor-not-allowed',\n    'read-only:bg-muted read-only:cursor-default',\n    'aria-[invalid=true]:border-warn aria-[invalid=true]:ring-1 aria-[invalid=true]:ring-warn',\n    'file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-input-foreground',\n    'transition-colors',\n  ],\n  {\n    variants: {\n      variant: {\n        outline: [\n          'border border-input-border bg-input-background',\n          'hover:border-border',\n        ],\n        filled: [\n          'border border-transparent bg-muted',\n          'hover:bg-muted-hover',\n          'focus-visible:border-input-border focus-visible:bg-input-background',\n        ],\n        ghost: [\n          'border border-transparent bg-transparent',\n          'hover:bg-muted',\n          'focus-visible:border-input-border focus-visible:bg-input-background',\n        ],\n      },\n      size: {\n        sm: 'h-8 px-2.5 text-sm',\n        default: 'h-10 px-3 text-sm',\n        lg: 'h-12 px-4 text-base',\n      },\n      error: {\n        true: 'border-warn ring-1 ring-warn focus-visible:outline-warn',\n        false: '',\n      },\n    },\n    defaultVariants: {\n      variant: 'outline',\n      size: 'default',\n      error: false,\n    },\n  }\n);\n\nexport type NativeControlVariants = VariantProps<typeof nativeControlVariants>;\n","import {\n  booleanAttribute,\n  computed,\n  Directive,\n  inject,\n  input,\n  signal,\n} from '@angular/core';\nimport type { DoCheck, InputSignal, InputSignalWithTransform, Signal, WritableSignal } from '@angular/core';\nimport { FormGroupDirective, NgControl, NgForm } from '@angular/forms';\nimport { ErrorStateMatcher } from 'ngx-com/components/form-field';\nimport { mergeClasses } from './native-control.utils';\nimport { nativeControlVariants } from './native-control.variants';\nimport type { NativeControlSize, NativeControlVariant } from './native-control.variants';\n\n/**\n * Standalone styling directive for native `<input>`, `<select>`, and `<textarea>` elements.\n *\n * Applies consistent borders, background, text color, focus outline, disabled state,\n * error state, and size scaling via CVA. Integrates with both Reactive Forms (via NgControl)\n * and Signal Forms (via `invalid`/`touched` inputs set by `[formField]`).\n *\n * For full form integration (label, hint, error), use `com-form-field` + `comInput`.\n *\n * @tokens `--color-input-border`, `--color-input-background`, `--color-input-foreground`,\n *         `--color-input-placeholder`, `--color-disabled`, `--color-disabled-foreground`,\n *         `--color-ring`, `--color-warn`, `--color-muted`, `--color-border`,\n *         `--radius-input`\n *\n * @example Basic usage\n * ```html\n * <input comNativeControl placeholder=\"Enter your name\" />\n * ```\n *\n * @example Variants\n * ```html\n * <input comNativeControl variant=\"outline\" placeholder=\"Outline (default)\" />\n * <input comNativeControl variant=\"filled\" placeholder=\"Filled\" />\n * <input comNativeControl variant=\"ghost\" placeholder=\"Ghost\" />\n * ```\n *\n * @example Reactive Forms\n * ```html\n * <input comNativeControl [formControl]=\"nameCtrl\" />\n * ```\n *\n * @example Signal Forms\n * ```html\n * <input comNativeControl [formField]=\"myForm.name\" />\n * ```\n */\n@Directive({\n  selector: 'input[comNativeControl], select[comNativeControl], textarea[comNativeControl]',\n  exportAs: 'comNativeControl',\n  host: {\n    '[class]': 'computedClass()',\n    '[attr.aria-invalid]': 'errorState() || null',\n  },\n})\nexport class ComNativeControl implements DoCheck {\n  private readonly defaultErrorStateMatcher = inject(ErrorStateMatcher);\n  private readonly parentForm = inject(NgForm, { optional: true });\n  private readonly parentFormGroup = inject(FormGroupDirective, { optional: true });\n\n  /** NgControl bound to this element (if using reactive forms). */\n  readonly ngControl: NgControl | null = inject(NgControl, { optional: true, self: true });\n\n  /** Whether the form system is Signal Forms (no NgControl present). */\n  private readonly isSignalForms: boolean = !this.ngControl;\n\n  // ── Inputs ──\n\n  /** Visual variant — outline (bordered), filled (bg fill), or ghost (transparent) */\n  readonly variant: InputSignal<NativeControlVariant> = input<NativeControlVariant>('outline');\n\n  /** Control size — affects height, padding, and font size */\n  readonly size: InputSignal<NativeControlSize> = input<NativeControlSize>('default');\n\n  /** Consumer CSS classes — merged with variant classes via mergeClasses() */\n  readonly userClass: InputSignal<string> = input<string>('', { alias: 'class' });\n\n  /** Custom error state matcher (overrides the default). */\n  readonly errorStateMatcher: InputSignal<ErrorStateMatcher | undefined> = input<ErrorStateMatcher>();\n\n  // ── Signal Forms inputs — set automatically by [formField] ──\n\n  readonly sfInvalid: InputSignalWithTransform<boolean, unknown> = input(false, {\n    alias: 'invalid',\n    transform: booleanAttribute,\n  });\n  readonly sfTouched: InputSignalWithTransform<boolean, unknown> = input(false, {\n    alias: 'touched',\n    transform: booleanAttribute,\n  });\n\n  // ── Error state ──\n\n  /**\n   * Reactive Forms error state — imperatively updated in DoCheck because\n   * NgControl properties (touched, invalid) are not signals.\n   */\n  private readonly _reactiveErrorState: WritableSignal<boolean> = signal(false);\n\n  /** Whether the control is in an error state. */\n  readonly errorState: Signal<boolean> = computed(() => {\n    if (this.isSignalForms) {\n      return this.sfInvalid() && this.sfTouched();\n    }\n    return this._reactiveErrorState();\n  });\n\n  /** @internal Computed host class from CVA + consumer overrides */\n  protected readonly computedClass: Signal<string> = computed(() =>\n    mergeClasses(\n      nativeControlVariants({\n        variant: this.variant(),\n        size: this.size(),\n        error: this.errorState(),\n      }),\n      this.userClass()\n    )\n  );\n\n  ngDoCheck(): void {\n    if (this.ngControl) {\n      const matcher = this.errorStateMatcher() ?? this.defaultErrorStateMatcher;\n      const form = this.parentFormGroup ?? this.parentForm;\n      this._reactiveErrorState.set(\n        matcher.isErrorState(this.ngControl.control ?? null, form)\n      );\n    }\n  }\n}\n","// Public API for the native-control directive\n\n// Main directive\nexport { ComNativeControl } from './native-control.directive';\n\n// Variants (for advanced customization)\nexport { nativeControlVariants } from './native-control.variants';\n\nexport type {\n  NativeControlVariant,\n  NativeControlSize,\n  NativeControlVariants,\n} from './native-control.variants';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAYA;;;;;;;AAOG;AACI,MAAM,qBAAqB,GAInB,GAAG,CAChB;IACE,oBAAoB;IACpB,QAAQ;IACR,uBAAuB;IACvB,oCAAoC;IACpC,eAAe;IACf,uFAAuF;IACvF,6GAA6G;IAC7G,6CAA6C;IAC7C,0FAA0F;IAC1F,4FAA4F;IAC5F,mBAAmB;CACpB,EACD;AACE,IAAA,QAAQ,EAAE;AACR,QAAA,OAAO,EAAE;AACP,YAAA,OAAO,EAAE;gBACP,gDAAgD;gBAChD,qBAAqB;AACtB,aAAA;AACD,YAAA,MAAM,EAAE;gBACN,oCAAoC;gBACpC,sBAAsB;gBACtB,qEAAqE;AACtE,aAAA;AACD,YAAA,KAAK,EAAE;gBACL,0CAA0C;gBAC1C,gBAAgB;gBAChB,qEAAqE;AACtE,aAAA;AACF,SAAA;AACD,QAAA,IAAI,EAAE;AACJ,YAAA,EAAE,EAAE,oBAAoB;AACxB,YAAA,OAAO,EAAE,mBAAmB;AAC5B,YAAA,EAAE,EAAE,qBAAqB;AAC1B,SAAA;AACD,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,yDAAyD;AAC/D,YAAA,KAAK,EAAE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