{"version":3,"file":"forty-cdk-checkbox.mjs","sources":["../../../projects/forty-cdk/checkbox/src/checkbox.ts","../../../projects/forty-cdk/checkbox/src/checkbox-indicator.ts","../../../projects/forty-cdk/checkbox/src/checkbox-host-directive.ts","../../../projects/forty-cdk/checkbox/src/forty-cdk-checkbox.ts"],"sourcesContent":["import { computed, Directive, InjectionToken, model } from '@angular/core';\nimport type { FormCheckboxControl } from '@angular/forms/signals';\n\nimport {\n  hostButtonType,\n  FormUiControlBase,\n  injectHiddenInput,\n  injectSyntheticActivation,\n} from 'forty-cdk/core';\n\n/**\n * Injection key the `[forCheckboxIndicator]` uses to resolve its parent\n * checkbox, decoupled from the concrete `ForCheckbox` class. `ForCheckbox`\n * provides itself under this token, so a design system wrapping the checkbox\n * by subclassing re-points it at the subclass with a single provider\n * (`{ provide: FOR_CHECKBOX, useExisting: MtxCheckbox }`) and the indicator\n * keeps resolving — see `docs/wrapping-form-primitives.md`.\n */\nexport const FOR_CHECKBOX = new InjectionToken<ForCheckbox>('FOR_CHECKBOX');\n\n/**\n * Headless checkbox implementing the\n * [WAI-ARIA Checkbox pattern](https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/)\n * with optional tri-state (`indeterminate`) support, plus Angular's\n * `FormCheckboxControl` from `@angular/forms/signals` for `[formField]`\n * auto-wiring.\n *\n * Works on a native `<button>` host and on any arbitrary host element (e.g.\n * `<div>`, `<span>`). On a `<button>` the directive forces `type=\"button\"` to\n * avoid accidental form submission — through a host binding, so a consumer\n * `type=\"submit\"` is overridden rather than honoured — and Enter / Space\n * activation comes from native button behavior (APG only mandates Space, and\n * Enter is harmless on a non-submit button). On a non-button host no `type`\n * attribute is emitted at all (`type` is not valid there), `tabindex=\"0\"` is\n * applied and the same Enter / Space activation is synthesized, so the announced\n * `role=\"checkbox\"` is never left keyboard-inoperable — including when the\n * host is composed through `hostDirectives`, which ignores a directive's\n * selector.\n *\n * Tri-state: when `indeterminate` is `true`, `aria-checked=\"mixed\"` is\n * announced regardless of `checked`. Activating an indeterminate checkbox\n * clears `indeterminate` and toggles `checked` from its current value\n * (matches native `<input type=\"checkbox\">` behavior).\n *\n * The accessible name is the consumer's responsibility — wrap the button in a\n * `<label>` or use `aria-labelledby` / `aria-label`.\n *\n * @example\n * ```html\n * <button forCheckbox [(checked)]=\"agreed\">\n *   <span class=\"indicator\"></span>\n * </button>\n * I agree to the terms.\n *\n * <!-- Non-button host — tabindex and keyboard handling added automatically -->\n * <div forCheckbox [(checked)]=\"agreed\"></div>\n *\n * <!-- With Signal Forms: -->\n * <button forCheckbox [formField]=\"form.acceptTerms\"></button>\n * ```\n */\n@Directive({\n  selector: '[forCheckbox]',\n  exportAs: 'forCheckbox',\n  providers: [{ provide: FOR_CHECKBOX, useExisting: ForCheckbox }],\n  host: {\n    role: 'checkbox',\n    '[attr.type]': 'buttonType()',\n    '[attr.tabindex]': 'tabindex()',\n    '[attr.aria-checked]': 'ariaChecked()',\n    '[attr.aria-disabled]': 'effectiveDisabled() ? \"true\" : null',\n    '[attr.aria-readonly]': 'readonly() ? \"true\" : null',\n    '[attr.aria-required]': 'required() ? \"true\" : null',\n    '[attr.aria-invalid]': 'invalid() ? \"true\" : null',\n    '[attr.aria-busy]': 'pending() ? \"true\" : null',\n    '[attr.name]': 'name() || null',\n    '[attr.data-state]': 'dataState()',\n    '[attr.data-disabled]': 'effectiveDisabled() ? \"\" : null',\n    '[attr.data-readonly]': 'readonly() ? \"\" : null',\n    '(click)': 'onClick()',\n    '(keydown)': 'onKeydown($event)',\n    '(keyup)': 'onKeyup($event)',\n    '(blur)': 'onBlur()',\n  },\n})\nexport class ForCheckbox extends FormUiControlBase implements FormCheckboxControl {\n  protected readonly buttonType = hostButtonType();\n\n  /** Two-way bindable on/off state. Required by `FormCheckboxControl`. */\n  readonly checked = model<boolean>(false);\n\n  /**\n   * Two-way bindable indeterminate state. When true, `aria-checked=\"mixed\"`\n   * is announced regardless of `checked`. Activation clears it.\n   *\n   * Not part of `FormCheckboxControl` — the field's value stays binary.\n   * Indeterminate is a UI-only concern (e.g. a parent \"select all\" reflecting\n   * children with mixed selection).\n   */\n  readonly indeterminate = model<boolean>(false);\n\n  protected readonly ariaChecked = computed<'true' | 'false' | 'mixed'>(() => {\n    if (this.indeterminate()) return 'mixed';\n    return this.checked() ? 'true' : 'false';\n  });\n\n  /**\n   * Logical state reflected on `data-state`: `'checked'`, `'unchecked'`, or\n   * `'indeterminate'`. Exposed so `ForCheckboxIndicator` can mirror it without\n   * re-deriving the same mapping.\n   */\n  readonly dataState = computed<'checked' | 'unchecked' | 'indeterminate'>(() => {\n    if (this.indeterminate()) return 'indeterminate';\n    return this.checked() ? 'checked' : 'unchecked';\n  });\n\n  readonly #activation = injectSyntheticActivation({ disabled: this.effectiveDisabled });\n\n  protected readonly tabindex = this.#activation.tabindex;\n\n  constructor() {\n    super();\n    injectHiddenInput({\n      name: this.name,\n      // Matches native `<input type=\"checkbox\">`: only `checked` contributes\n      // to form submission; `indeterminate` is purely a presentational flag.\n      values: computed(() => (this.checked() ? ['on'] : [])),\n      disabled: this.effectiveDisabled,\n    });\n  }\n\n  protected onClick(): void {\n    if (this.effectiveDisabled() || this.readonly()) {\n      return;\n    }\n    if (this.indeterminate()) {\n      this.indeterminate.set(false);\n    }\n    this.checked.update((v) => !v);\n  }\n\n  protected onKeydown(event: KeyboardEvent): void {\n    this.#activation.keydown(event);\n  }\n\n  protected onKeyup(event: KeyboardEvent): void {\n    this.#activation.keyup(event);\n  }\n\n  protected onBlur(): void {\n    this.#activation.reset();\n    this.markTouched();\n  }\n}\n","import { Directive, inject } from '@angular/core';\n\nimport { orphanContextError } from 'forty-cdk/core';\n\nimport { FOR_CHECKBOX, type ForCheckbox } from './checkbox';\n\n/**\n * Optional indicator slot inside a `ForCheckbox`. Apply on the element\n * the consumer wants to show only while the checkbox is `checked` or\n * `indeterminate` (typically a check icon, dash, or filled square). The\n * directive mirrors `data-state` from the parent so the consumer can\n * style transitions without per-state bindings; hide the unchecked state\n * via `[data-state=\"unchecked\"] { display: none }` or `@if`.\n *\n * Purely a styling convenience — consumers happy with CSS `:has`\n * selectors or `[data-state]` checks on the parent can skip it entirely.\n */\n@Directive({\n  selector: '[forCheckboxIndicator]',\n  exportAs: 'forCheckboxIndicator',\n  host: {\n    '[attr.data-state]': 'parent.dataState()',\n  },\n})\nexport class ForCheckboxIndicator {\n  protected readonly parent: ForCheckbox;\n\n  constructor() {\n    const parent = inject(FOR_CHECKBOX, { optional: true });\n    if (!parent) {\n      throw orphanContextError({\n        code: 'FORCDK-CHECKBOX-001',\n        piece: 'ForCheckboxIndicator',\n        root: '[forCheckbox]',\n        token: 'FOR_CHECKBOX',\n      });\n    }\n    this.parent = parent;\n  }\n}\n","/**\n * Exact public names of every `ForCheckbox` input, its models included. Spread it into the\n * `inputs` array of a `hostDirectives` entry so a wrapper component re-exposes the\n * primitive's full surface — the Signal Forms members `[formField]` binds among them —\n * without hand-maintaining the list. Always spread into an inline object literal as shown\n * below: the literal is what keeps the entry statically analyzable for consumers compiling\n * against the published package. An anti-drift spec fails when this list no longer matches\n * the directive's actual API. See `docs/wrapping-form-primitives.md` for both supported\n * wrapping patterns.\n *\n * @example\n * ```ts\n * @Component({\n *   selector: 'button[myCheckbox]',\n *   template: '',\n *   hostDirectives: [\n *     {\n *       directive: ForCheckbox,\n *       inputs: [...FOR_CHECKBOX_HOST_DIRECTIVE_INPUTS],\n *       outputs: [...FOR_CHECKBOX_HOST_DIRECTIVE_OUTPUTS],\n *     },\n *   ],\n * })\n * export class MyCheckbox {}\n * ```\n */\nexport const FOR_CHECKBOX_HOST_DIRECTIVE_INPUTS = [\n  'checked',\n  'indeterminate',\n  'dirty',\n  'disabled',\n  'errors',\n  'invalid',\n  'name',\n  'pending',\n  'readonly',\n  'required',\n  'touched',\n] as const;\n\n/**\n * Exact public names of every `ForCheckbox` output, the Signal Forms `touch` output\n * included. Spread it into the `outputs` array of the same `hostDirectives` entry as\n * {@link FOR_CHECKBOX_HOST_DIRECTIVE_INPUTS}.\n */\nexport const FOR_CHECKBOX_HOST_DIRECTIVE_OUTPUTS = [\n  'checkedChange',\n  'indeterminateChange',\n  'touchedChange',\n  'touch',\n] as const;\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAUA;;;;;;;AAOG;MACU,YAAY,GAAG,IAAI,cAAc,CAAc,cAAc;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCG;AAyBG,MAAO,WAAY,SAAQ,iBAAiB,CAAA;IAC7B,UAAU,GAAG,cAAc,EAAE;;IAGvC,OAAO,GAAG,KAAK,CAAU,KAAK;gFAAC;AAExC;;;;;;;AAOG;IACM,aAAa,GAAG,KAAK,CAAU,KAAK;sFAAC;AAE3B,IAAA,WAAW,GAAG,QAAQ,CAA6B,MAAK;QACzE,IAAI,IAAI,CAAC,aAAa,EAAE;AAAE,YAAA,OAAO,OAAO;AACxC,QAAA,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,OAAO;IAC1C,CAAC;oFAAC;AAEF;;;;AAIG;AACM,IAAA,SAAS,GAAG,QAAQ,CAA4C,MAAK;QAC5E,IAAI,IAAI,CAAC,aAAa,EAAE;AAAE,YAAA,OAAO,eAAe;AAChD,QAAA,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,SAAS,GAAG,WAAW;IACjD,CAAC;kFAAC;IAEO,WAAW,GAAG,yBAAyB,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC;AAEnE,IAAA,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ;AAEvD,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;AACP,QAAA,iBAAiB,CAAC;YAChB,IAAI,EAAE,IAAI,CAAC,IAAI;;;YAGf,MAAM,EAAE,QAAQ,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CA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