{"version":3,"file":"siemens-element-ng-password-strength.mjs","sources":["../../../../projects/element-ng/password-strength/si-password-strength.directive.ts","../../../../projects/element-ng/password-strength/si-password-strength.component.ts","../../../../projects/element-ng/password-strength/si-password-strength.module.ts","../../../../projects/element-ng/password-strength/index.ts","../../../../projects/element-ng/password-strength/siemens-element-ng-password-strength.ts"],"sourcesContent":["/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nimport { computed, Directive, input, output } from '@angular/core';\nimport { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';\n\nconst RE_UPPER_CASE = /[A-Z]/;\nconst RE_LOWER_CASE = /[a-z]/;\nconst RE_DIGITS = /[0-9]/;\nconst RE_SPECIAL_CHARS = /[\\x21-\\x2F|\\x3A-\\x40|\\x5B-\\x60]/;\nconst RE_WHITESPACES = /\\s/;\n\nexport interface PasswordPolicy {\n  /**\n   * Define minimal number of characters.\n   */\n  minLength: number;\n  /**\n   * Define if uppercase characters are required in password.\n   */\n  uppercase: boolean;\n  /**\n   * Define if lowercase characters are required in password.\n   */\n  lowercase: boolean;\n  /**\n   * Define if digits are required in password.\n   */\n  digits: boolean;\n  /**\n   * Define if special characters are required in password.\n   */\n  special: boolean;\n  /**\n   * Whether to allow whitespaces. By default whitespaces are not allowed.\n   */\n  allowWhitespace?: boolean;\n  /**\n   * Minimum required policies for valid password. When set to a number greater than 0,\n   * defines the number of policies that must be met for the password to be valid.\n   * E.g. when set to 3 and the policies uppercase/lowercase/digits/special are all set\n   * and the password contains 3 out of these four, the password will be valid.\n   */\n  minRequiredPolicies?: number;\n}\n\ninterface StrengthCheck {\n  length: boolean;\n  strength: number;\n}\n\n@Directive({\n  selector: '[siPasswordStrength]',\n  providers: [{ provide: NG_VALIDATORS, useExisting: SiPasswordStrengthDirective, multi: true }],\n  host: {\n    '[class.no-validation]': 'noValidation'\n  }\n})\nexport class SiPasswordStrengthDirective implements Validator {\n  private readonly maxStrength = computed(() => {\n    const strength = this.siPasswordStrength();\n    return (\n      1 +\n      (strength.uppercase ? 1 : 0) +\n      (strength.lowercase ? 1 : 0) +\n      (strength.digits ? 1 : 0) +\n      (strength.special ? 1 : 0)\n    );\n  });\n\n  protected noValidation = false;\n\n  /**\n   * Define Siemens password strength.\n   *\n   * @defaultValue\n   * ```\n   * {\n   *     minLength: 8,\n   *     uppercase: true,\n   *     lowercase: true,\n   *     digits: true,\n   *     special: true\n   *   }\n   * ```\n   */\n  readonly siPasswordStrength = input<PasswordPolicy>({\n    minLength: 8,\n    uppercase: true,\n    lowercase: true,\n    digits: true,\n    special: true\n  });\n\n  /**\n   * Output callback event called when the password changes. The number\n   * indicated the number of rules which still can be met. (`-2` --\\> 2 rules are\n   * still unmet, `0` --\\> all met)\n   */\n  readonly passwordStrengthChanged = output<number | void>();\n\n  /** @internal */\n  validate(control: AbstractControl): ValidationErrors {\n    const strength = this.getStrength(control.value);\n    // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n    const requiredStrength = this.siPasswordStrength().minRequiredPolicies || this.maxStrength();\n    if (strength.length && strength.strength >= requiredStrength) {\n      return {};\n    }\n    return { siPasswordStrength: true };\n  }\n\n  private getStrength(password: string): StrengthCheck {\n    const policy = this.siPasswordStrength();\n    if (!password) {\n      this.noValidation = false;\n      this.passwordStrengthChanged.emit();\n      return { length: false, strength: 0 };\n    }\n\n    let strength = 0;\n    // Strength check\n    const length = password.length >= policy.minLength;\n    strength += length ? 1 : 0;\n    strength += policy.uppercase && password.match(RE_UPPER_CASE) ? 1 : 0;\n    strength += policy.lowercase && password.match(RE_LOWER_CASE) ? 1 : 0;\n    strength += policy.digits && password.match(RE_DIGITS) ? 1 : 0;\n    strength += policy.special && password.match(RE_SPECIAL_CHARS) ? 1 : 0;\n    if (policy.allowWhitespace !== true) {\n      strength = password.match(RE_WHITESPACES) ? 0 : strength;\n    }\n    this.noValidation = true;\n    // Notify listeners\n    this.passwordStrengthChanged.emit(strength - this.maxStrength());\n    return { length, strength };\n  }\n}\n","/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nimport {\n  AfterViewInit,\n  Component,\n  contentChild,\n  contentChildren,\n  ElementRef,\n  input,\n  signal\n} from '@angular/core';\nimport { SiPasswordToggleComponent } from '@siemens/element-ng/password-toggle';\n\nimport { SiPasswordStrengthDirective } from './si-password-strength.directive';\n\n@Component({\n  selector: 'si-password-strength',\n  imports: [SiPasswordToggleComponent],\n  template: `\n    <si-password-toggle [showVisibilityIcon]=\"showVisibilityIcon()\" (typeChange)=\"toggle($event)\">\n      <ng-content />\n    </si-password-toggle>\n  `,\n  styleUrl: './si-password-strength.component.scss',\n  host: {\n    '[class.bad]': 'bad()',\n    '[class.weak]': 'weak()',\n    '[class.medium]': 'medium()',\n    '[class.good]': 'good()',\n    '[class.strong]': 'strong()'\n  }\n})\nexport class SiPasswordStrengthComponent implements AfterViewInit {\n  /**\n   * Whether to show the visibility toggle icon.\n   *\n   * @defaultValue true\n   */\n  readonly showVisibilityIcon = input(true);\n\n  private readonly passwordStrengthDirective = contentChildren(SiPasswordStrengthDirective);\n  private readonly passwordInput = contentChild.required<\n    SiPasswordStrengthDirective,\n    ElementRef<HTMLInputElement>\n  >(SiPasswordStrengthDirective, { read: ElementRef<HTMLInputElement> });\n\n  protected readonly bad = signal(false);\n  protected readonly weak = signal(false);\n  protected readonly medium = signal(false);\n  protected readonly good = signal(false);\n  protected readonly strong = signal(false);\n\n  protected toggle(type: string): void {\n    this.passwordInput().nativeElement.type = type;\n  }\n\n  ngAfterViewInit(): void {\n    this.passwordStrengthDirective().forEach(directive => {\n      directive.passwordStrengthChanged.subscribe((strength: number | void) => {\n        this.strong.set(strength === 0);\n        this.good.set(strength === -1);\n        this.medium.set(strength === -2);\n        this.weak.set(strength === -3);\n        this.bad.set(strength === -4);\n      });\n    });\n  }\n}\n","/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nimport { NgModule } from '@angular/core';\n\nimport { SiPasswordStrengthComponent } from './si-password-strength.component';\nimport { SiPasswordStrengthDirective } from './si-password-strength.directive';\n\n@NgModule({\n  imports: [SiPasswordStrengthComponent, SiPasswordStrengthDirective],\n  exports: [SiPasswordStrengthComponent, SiPasswordStrengthDirective]\n})\nexport class SiPasswordStrengthModule {}\n","/**\n * Copyright (c) Siemens 2016 - 2026\n * SPDX-License-Identifier: MIT\n */\nexport * from './si-password-strength.component';\nexport * from './si-password-strength.directive';\nexport * from './si-password-strength.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAIH,MAAM,aAAa,GAAG,OAAO;AAC7B,MAAM,aAAa,GAAG,OAAO;AAC7B,MAAM,SAAS,GAAG,OAAO;AACzB,MAAM,gBAAgB,GAAG,iCAAiC;AAC1D,MAAM,cAAc,GAAG,IAAI;MAgDd,2BAA2B,CAAA;AACrB,IAAA,WAAW,GAAG,QAAQ,CAAC,MAAK;AAC3C,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,EAAE;AAC1C,QAAA,QACE,CAAC;aACA,QAAQ,CAAC,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC;aAC3B,QAAQ,CAAC,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC;aAC3B,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;AACzB,aAAC,QAAQ,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAE9B,CAAC;oFAAC;IAEQ,YAAY,GAAG,KAAK;AAE9B;;;;;;;;;;;;;AAaG;IACM,kBAAkB,GAAG,KAAK,CAAiB;AAClD,QAAA,SAAS,EAAE,CAAC;AACZ,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,SAAS,EAAE,IAAI;AACf,QAAA,MAAM,EAAE,IAAI;AACZ,QAAA,OAAO,EAAE;AACV,KAAA;2FAAC;AAEF;;;;AAIG;IACM,uBAAuB,GAAG,MAAM,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