{"version":3,"file":"forty-cdk-switch.mjs","sources":["../../../projects/forty-cdk/switch/src/switch.ts","../../../projects/forty-cdk/switch/src/switch-host-directive.ts","../../../projects/forty-cdk/switch/src/forty-cdk-switch.ts"],"sourcesContent":["import { computed, Directive, 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 * Headless on/off switch implementing the\n * [WAI-ARIA Switch pattern](https://www.w3.org/WAI/ARIA/apg/patterns/switch/)\n * and Angular's `FormCheckboxControl` from `@angular/forms/signals` so it\n * auto-wires with `[formField]`.\n *\n * Works on a native `<button>` host and on any arbitrary host element (e.g.\n * `<div>`, `<span>`). On a `<button>` Enter / Space activation comes from native\n * button behavior and the directive forces `type=\"button\"` to prevent\n * accidental form submission when nested inside a `<form>` — through a host\n * binding, so a consumer `type=\"submit\"` is overridden rather than honoured. On\n * a non-button host no `type` attribute is emitted at all (`type` is not valid\n * there), `tabindex=\"0\"` is applied and the same Enter / Space activation is\n * synthesized, so the announced `role=\"switch\"` is never left\n * keyboard-inoperable — including when the host is composed through\n * `hostDirectives`, which ignores a directive's selector.\n *\n * @example\n * ```html\n * <button forSwitch [(checked)]=\"enabled\">\n *   <span class=\"thumb\"></span>\n * </button>\n *\n * <!-- Non-button host — tabindex and keyboard handling added automatically -->\n * <div forSwitch [(checked)]=\"enabled\"></div>\n *\n * <!-- With Signal Forms: -->\n * <button forSwitch [formField]=\"settings.notifications\"></button>\n * ```\n */\n@Directive({\n  selector: '[forSwitch]',\n  exportAs: 'forSwitch',\n  host: {\n    role: 'switch',\n    '[attr.type]': 'buttonType()',\n    '[attr.tabindex]': 'tabindex()',\n    '[attr.aria-checked]': 'checked() ? \"true\" : \"false\"',\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]': 'checked() ? \"checked\" : \"unchecked\"',\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 ForSwitch 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  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      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    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","/**\n * Exact public names of every `ForSwitch` 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[mySwitch]',\n *   template: '',\n *   hostDirectives: [\n *     {\n *       directive: ForSwitch,\n *       inputs: [...FOR_SWITCH_HOST_DIRECTIVE_INPUTS],\n *       outputs: [...FOR_SWITCH_HOST_DIRECTIVE_OUTPUTS],\n *     },\n *   ],\n * })\n * export class MySwitch {}\n * ```\n */\nexport const FOR_SWITCH_HOST_DIRECTIVE_INPUTS = [\n  'checked',\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 `ForSwitch` output, the Signal Forms `touch` output\n * included. Spread it into the `outputs` array of the same `hostDirectives` entry as\n * {@link FOR_SWITCH_HOST_DIRECTIVE_INPUTS}.\n */\nexport const FOR_SWITCH_HOST_DIRECTIVE_OUTPUTS = [\n  'checkedChange',\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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AAwBG,MAAO,SAAU,SAAQ,iBAAiB,CAAA;IAC3B,UAAU,GAAG,cAAc,EAAE;;IAGvC,OAAO,GAAG,KAAK,CAAU,KAAK;gFAAC;IAE/B,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;YACf,MAAM,EAAE,QAAQ,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YACtD,QAAQ,EAAE,IAAI,CAAC,iBAAiB;AACjC,SAAA,CAAC;IACJ;IAEU,OAAO,GAAA;QACf,IAAI,IAAI,CAAC,iBAAiB,EAAE,IAAI,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