{"version":3,"file":"ngwr-directives.mjs","sources":["../../../projects/lib/directives/autofocus.ts","../../../projects/lib/directives/autosize.ts","../../../projects/lib/directives/click-outside.ts","../../../projects/lib/directives/copy-to-clipboard.ts","../../../projects/lib/directives/ngwr-directives.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceBooleanProperty } from '@angular/cdk/coercion';\nimport { Directive, ElementRef, afterNextRender, effect, inject, input } from '@angular/core';\n\n/**\n * Focus the host element after the first render — or whenever the bound\n * expression transitions to truthy.\n *\n * @example\n * ```html\n * <input wrAutofocus />\n * <input [wrAutofocus]=\"shouldFocus()\" />\n * ```\n */\n@Directive({ selector: '[wrAutofocus]' })\nexport class WrAutofocus {\n  /** Truthy = focus. Defaults to `true` so bare `wrAutofocus` works. */\n  readonly wrAutofocus = input(true, { transform: coerceBooleanProperty });\n\n  private readonly el = inject<ElementRef<HTMLElement>>(ElementRef);\n\n  constructor() {\n    afterNextRender(() => {\n      if (this.wrAutofocus()) this.el.nativeElement.focus();\n    });\n    effect(() => {\n      if (this.wrAutofocus()) {\n        // Microtask defer so view updates that flip the expression land first.\n        queueMicrotask(() => this.el.nativeElement.focus());\n      }\n    });\n  }\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceNumberProperty } from '@angular/cdk/coercion';\nimport { Directive, ElementRef, afterEveryRender, effect, inject, input } from '@angular/core';\n\n/**\n * Auto-grow a `<textarea>` to fit its content. Optional `minRows` /\n * `maxRows` bounds the height in rendered rows.\n *\n * @example\n * ```html\n * <textarea wrAutosize minRows=\"2\" maxRows=\"8\" [(ngModel)]=\"text\"></textarea>\n * ```\n */\n@Directive({\n  selector: 'textarea[wrAutosize]',\n  host: { style: 'overflow: hidden; resize: none;', '(input)': 'onInput()' },\n})\nexport class WrAutosize {\n  readonly minRows = input(1, { transform: (v: unknown): number => Math.max(1, coerceNumberProperty(v, 1)) });\n  readonly maxRows = input(0, { transform: (v: unknown): number => Math.max(0, coerceNumberProperty(v, 0)) });\n\n  private readonly el = inject<ElementRef<HTMLTextAreaElement>>(ElementRef);\n\n  private lastValue: string | null = null;\n\n  constructor() {\n    // Typing fires `input`, but `[(ngModel)]` / `setValue` write the value\n    // without one — a cheap per-render value check catches both, including\n    // the initial write that lands after the first render.\n    afterEveryRender(() => {\n      const value = this.el.nativeElement.value;\n      if (value !== this.lastValue) {\n        this.lastValue = value;\n        this.resize();\n      }\n    });\n    // Resize when `minRows` / `maxRows` change.\n    effect(() => {\n      this.minRows();\n      this.maxRows();\n      this.resize();\n    });\n  }\n\n  /** @internal */\n  protected onInput(): void {\n    this.lastValue = this.el.nativeElement.value;\n    this.resize();\n  }\n\n  /** Recompute height from `scrollHeight`, clamped to min/max rows. */\n  private resize(): void {\n    const node = this.el.nativeElement;\n    const styles = getComputedStyle(node);\n    // `line-height: normal` computes to the literal string — derive the\n    // row height from the font size instead of guessing a fixed 20px.\n    const lineHeight = parseFloat(styles.lineHeight) || parseFloat(styles.fontSize) * 1.25 || 20;\n    const paddingY = parseFloat(styles.paddingTop) + parseFloat(styles.paddingBottom);\n    const border = (parseFloat(styles.borderTopWidth) || 0) + (parseFloat(styles.borderBottomWidth) || 0);\n\n    // Reset to a single row first so `scrollHeight` shrinks as well as grows.\n    node.style.height = 'auto';\n    const min = this.minRows() * lineHeight + paddingY + border;\n    const max = this.maxRows() > 0 ? this.maxRows() * lineHeight + paddingY + border : Infinity;\n    const next = Math.min(Math.max(node.scrollHeight + border, min), max);\n    node.style.height = `${next}px`;\n    node.style.overflowY = node.scrollHeight + border > max ? 'auto' : 'hidden';\n  }\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { DOCUMENT } from '@angular/common';\nimport { DestroyRef, Directive, ElementRef, NgZone, inject, output } from '@angular/core';\n\n/**\n * Fires `(wrClickOutside)` when a pointer event lands outside the host\n * element. Useful for closing custom poppers / menus.\n *\n * @example\n * ```html\n * <div class=\"popup\" (wrClickOutside)=\"close()\"> … </div>\n * ```\n */\n@Directive({ selector: '[wrClickOutside]' })\nexport class WrClickOutside {\n  readonly wrClickOutside = output<MouseEvent>();\n\n  private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n  private readonly doc = inject(DOCUMENT);\n  private readonly zone = inject(NgZone);\n  private readonly destroyRef = inject(DestroyRef);\n\n  constructor() {\n    // Listen outside Angular to avoid CD on every page click; re-enter\n    // only when the event lands outside the host.\n    this.zone.runOutsideAngular(() => {\n      const handler = (event: MouseEvent): void => {\n        const target = event.target as Node | null;\n        if (target && !this.host.nativeElement.contains(target)) {\n          this.zone.run(() => this.wrClickOutside.emit(event));\n        }\n      };\n      this.doc.addEventListener('mousedown', handler, true);\n      this.destroyRef.onDestroy(() => {\n        this.doc.removeEventListener('mousedown', handler, true);\n      });\n    });\n  }\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { DOCUMENT } from '@angular/common';\nimport { Directive, inject, input, output } from '@angular/core';\n\n/**\n * Copy `wrCopyToClipboard` to the system clipboard on host click.\n *\n * Uses `navigator.clipboard.writeText` when available, with a hidden\n * `<textarea>` + `document.execCommand('copy')` fallback for older browsers\n * and non-secure contexts.\n *\n * @example\n * ```html\n * <button [wrCopyToClipboard]=\"value\" (copied)=\"toast('Copied!')\">Copy</button>\n * ```\n */\n@Directive({ selector: '[wrCopyToClipboard]', host: { '(click)': 'onClick()' } })\nexport class WrCopyToClipboard {\n  /** The text to copy. */\n  readonly wrCopyToClipboard = input.required<string>();\n\n  /** Emitted with the copied text once the write succeeds. */\n  readonly copied = output<string>();\n\n  /** Emitted if the copy fails (denied permission, no clipboard, …). */\n  readonly copyFailed = output<unknown>();\n\n  private readonly doc = inject(DOCUMENT);\n\n  /** @internal */\n  protected async onClick(): Promise<void> {\n    const text = this.wrCopyToClipboard();\n    try {\n      if (this.doc.defaultView?.navigator?.clipboard) {\n        await this.doc.defaultView.navigator.clipboard.writeText(text);\n      } else {\n        this.fallback(text);\n      }\n      this.copied.emit(text);\n    } catch (error) {\n      try {\n        this.fallback(text);\n        this.copied.emit(text);\n      } catch (fallbackError) {\n        this.copyFailed.emit(fallbackError ?? error);\n      }\n    }\n  }\n\n  /** Legacy clipboard write — hidden textarea + execCommand('copy'). */\n  private fallback(text: string): void {\n    const node = this.doc.createElement('textarea');\n    node.value = text;\n    node.setAttribute('readonly', '');\n    node.style.position = 'fixed';\n    node.style.top = '0';\n    node.style.left = '0';\n    node.style.opacity = '0';\n    node.style.pointerEvents = 'none';\n    this.doc.body.appendChild(node);\n    node.select();\n    try {\n      this.doc.execCommand('copy');\n    } finally {\n      this.doc.body.removeChild(node);\n    }\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAAA;;;;;AAKG;AAKH;;;;;;;;;AASG;MAEU,WAAW,CAAA;;IAEb,WAAW,GAAG,KAAK,CAAC,IAAI,mFAAI,SAAS,EAAE,qBAAqB,EAAA,CAAG;AAEvD,IAAA,EAAE,GAAG,MAAM,CAA0B,UAAU,CAAC;AAEjE,IAAA,WAAA,GAAA;QACE,eAAe,CAAC,MAAK;YACnB,IAAI,IAAI,CAAC,WAAW,EAAE;AAAE,gBAAA,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE;AACvD,QAAA,CAAC,CAAC;QACF,MAAM,CAAC,MAAK;AACV,YAAA,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE;;AAEtB,gBAAA,cAAc,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YACrD;AACF,QAAA,CA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