@fr0st/ui-passwordstrength 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/frost-ui-passwordstrength.js +8 -0
- package/dist/frost-ui-passwordstrength.js.map +1 -1
- package/dist/frost-ui-passwordstrength.min.js +1 -1
- package/dist/frost-ui-passwordstrength.min.js.map +1 -1
- package/package.json +5 -5
- package/src/password-strength.js +1 -0
- package/src/prototype/render.js +8 -0
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
dispose() {
|
|
35
35
|
$.remove(this._progress);
|
|
36
36
|
$.removeEvent(this._node, 'input.ui.passwordstrength');
|
|
37
|
+
$.removeAttribute(this._node, 'aria-describedby');
|
|
37
38
|
|
|
38
39
|
this._container = null;
|
|
39
40
|
this._progress = null;
|
|
@@ -102,8 +103,11 @@
|
|
|
102
103
|
class: this.constructor.classes.progress,
|
|
103
104
|
});
|
|
104
105
|
|
|
106
|
+
const id = ui.generateId('password-strength');
|
|
107
|
+
|
|
105
108
|
this._progressBar = $.create('div', {
|
|
106
109
|
attributes: {
|
|
110
|
+
'id': id,
|
|
107
111
|
'role': 'progressbar',
|
|
108
112
|
'aria-valuemin': 0,
|
|
109
113
|
'aria-valuemax': 100,
|
|
@@ -112,6 +116,10 @@
|
|
|
112
116
|
|
|
113
117
|
$.append(this._progress, this._progressBar);
|
|
114
118
|
$.append(this._container, this._progress);
|
|
119
|
+
|
|
120
|
+
$.setAttribute(this._node, {
|
|
121
|
+
'aria-describedby': id,
|
|
122
|
+
});
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frost-ui-passwordstrength.js","sources":["../src/password-strength.js","../src/prototype/events.js","../src/prototype/helpers.js","../src/prototype/render.js","../src/static/helpers.js","../src/index.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * PasswordStrength Class\n * @class\n */\nexport default class PasswordStrength extends BaseComponent {\n /**\n * New PasswordStrength constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the PasswordStrength with.\n */\n constructor(node, options) {\n super(node, options);\n\n if (this._options.container) {\n this._container = $.findOne(this._options.container);\n } else {\n this._container = $.closest(this._node, ':not(.form-input):not(.input-group)');\n }\n\n this._render();\n this._refresh();\n this._events();\n }\n\n /**\n * Dispose the PasswordStrength.\n */\n dispose() {\n $.remove(this._progress);\n $.removeEvent(this._node, 'input.ui.passwordstrength');\n\n this._container = null;\n this._progress = null;\n this._progressBar = null;\n\n super.dispose();\n }\n\n /**\n * Get the password strength.\n * @return {number} The password strength. (0, 100)\n */\n getStrength() {\n const value = $.getValue(this._node);\n\n return this.constructor.getStrength(value);\n }\n}\n","import $ from '@fr0st/query';\n\n/**\n * Attach events for the PasswordStrength.\n */\nexport function _events() {\n $.addEvent(this._node, 'input.ui.passwordstrength', (_) => {\n this._refresh();\n });\n};\n","import $ from '@fr0st/query';\n\n/**\n * Refresh the password strength.\n */\nexport function _refresh() {\n const strength = this.getStrength();\n\n let nextLevel;\n for (const level of this._options.levels) {\n if (strength < level.score) {\n break;\n }\n\n nextLevel = level;\n }\n\n $.setStyle(this._progressBar, { width: `${strength}%` });\n $.setAttribute(this._progressBar, {\n 'class': this.constructor.classes.progressBar,\n 'aria-valuenow': strength,\n });\n\n $.addClass(this._progressBar, nextLevel.class);\n\n if (this._options.striped) {\n $.addClass(this._progressBar, this.constructor.classes.progressBarStriped);\n }\n\n if (nextLevel.text) {\n $.setText(this._progressBar, nextLevel.text);\n }\n};\n","import $ from '@fr0st/query';\n\n/**\n * Render the password strength element.\n */\nexport function _render() {\n this._progress = $.create('div', {\n class: this.constructor.classes.progress,\n });\n\n this._progressBar = $.create('div', {\n attributes: {\n 'role': 'progressbar',\n 'aria-valuemin': 0,\n 'aria-valuemax': 100,\n },\n });\n\n $.append(this._progress, this._progressBar);\n $.append(this._container, this._progress);\n};\n","import $ from '@fr0st/query';\n\n/**\n * Find character sequences in a string.\n * @param {string} string The input string.\n * @param {array} locations The character locations.\n * @return {array} The character sequences.\n */\nfunction findSequences(string, locations) {\n const sequences = [];\n let sequence = [];\n\n for (let i = 0; i < locations.length - 1; i++) {\n const current = locations[i];\n const next = locations[i + 1];\n const distance = next - current;\n\n const char = string[current];\n const nextChar = string[next];\n const charDistance = nextChar.charCodeAt(0) - char.charCodeAt(0);\n\n if (distance === 1 && charDistance === 1) {\n if (!sequence.length) {\n sequence.push(char);\n }\n sequence.push(nextChar);\n } else if (sequence.length) {\n sequences.push(sequence);\n sequence = [];\n }\n }\n\n if (sequence.length) {\n sequences.push(sequence);\n }\n\n return sequences;\n};\n\n/**\n * Get the strength of a password.\n * @param {string} password The password.\n * @return {number} The password strength.\n */\nexport function getStrength(password) {\n if (password.match(/^password/i)) {\n password = password.substring(8);\n }\n\n const length = password.length;\n\n let score = 0;\n\n if (length) {\n score += length * 6;\n }\n\n const upper = [];\n const lower = [];\n const numbers = [];\n const symbols = [];\n const dictionary = {};\n\n for (let i = 0; i < length; i++) {\n const char = password[i];\n const code = char.charCodeAt(0);\n\n if (code >= 48 && code <= 57) {\n numbers.push(i);\n } else if (code >= 65 && code <= 90) {\n upper.push(i);\n } else if (code >= 97 && code <= 122) {\n lower.push(i);\n } else {\n symbols.push(i);\n }\n\n if (!(char in dictionary)) {\n dictionary[char] = 0;\n }\n\n dictionary[char]++;\n }\n\n // reward upper/lower case\n if (upper.length !== length && lower.length !== length) {\n if (upper.length) {\n score += length - upper.length;\n }\n\n if (lower.length) {\n score += length - lower.length;\n }\n }\n\n // reward numbers\n if (numbers.length !== length) {\n score += numbers.length * 3;\n }\n\n // reward symbols\n score += symbols.length * 6;\n\n // reward inner numbers/symbols\n for (const list of [numbers, symbols]) {\n const reward = list.filter((v) => v && v !== length - 1).length;\n score += reward * 3;\n }\n\n // punish only letters\n if (!numbers.length && !symbols.length) {\n score -= length;\n }\n\n // punish only numbers\n if (!upper.length && !lower.length && !symbols.length) {\n score -= length;\n }\n\n // punish no symbols\n if (!symbols.length) {\n score -= length;\n }\n\n // repeating characters\n const repeats = Object.values(dictionary)\n .reduce((acc, count) => acc + count - 1, 0);\n\n if (repeats > 0) {\n score -= repeats;\n }\n\n if (length >= 2) {\n // consecutive characters\n const matches = password.matchAll(/(.)\\1+/g);\n\n for (const match of matches) {\n score -= Math.min(match[0].length, 12) * 3;\n }\n\n const lowerPassword = password.toLowerCase();\n\n // sequential letters\n const letters = upper.concat(lower);\n const letterSequences = findSequences(lowerPassword, letters);\n for (const sequence of letterSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n\n // sequential numbers\n const numberSequences = findSequences(lowerPassword, numbers);\n for (const sequence of numberSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n }\n\n return $._clamp(score, 0, 100);\n};\n","import { initComponent } from '@fr0st/ui';\nimport PasswordStrength from './password-strength.js';\nimport { _events } from './prototype/events.js';\nimport { _refresh } from './prototype/helpers.js';\nimport { _render } from './prototype/render.js';\nimport { getStrength } from './static/helpers.js';\n\n// PasswordStrength default options\nPasswordStrength.defaults = {\n levels: [\n {\n score: 0,\n class: 'text-bg-danger',\n text: 'Very Weak',\n },\n {\n score: 20,\n class: 'text-bg-danger',\n text: 'Weak',\n },\n {\n score: 40,\n class: 'text-bg-warning',\n text: 'Normal',\n },\n {\n score: 60,\n class: 'text-bg-success',\n text: 'Strong',\n },\n {\n score: 80,\n class: 'text-bg-success',\n text: 'Very Strong',\n },\n ],\n container: null,\n striped: false,\n};\n\n// PasswordStrength classes\nPasswordStrength.classes = {\n progress: 'progress mt-2',\n progressBar: 'progress-bar',\n progressBarStriped: 'progress-bar-striped',\n};\n\n// PasswordStrength static\nPasswordStrength.getStrength = getStrength;\n\n// PasswordStrength prototype\nconst proto = PasswordStrength.prototype;\n\nproto._events = _events;\nproto._refresh = _refresh;\nproto._render = _render;\n\n// PasswordStrength init\ninitComponent('passwordstrength', PasswordStrength);\n\nexport default PasswordStrength;\n"],"names":["BaseComponent","initComponent"],"mappings":";;;;;;IAGA;IACA;IACA;IACA;IACe,MAAM,gBAAgB,SAASA,gBAAa,CAAC;IAC5D;IACA;IACA;IACA;IACA;IACA,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE;IAC/B,QAAQ,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7B;IACA,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE;IACrC,YAAY,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACjE,SAAS,MAAM;IACf,YAAY,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,qCAAqC,CAAC,CAAC;IAC3F,SAAS;AACT;IACA,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,KAAK;AACL;IACA;IACA;IACA;IACA,IAAI,OAAO,GAAG;IACd,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACjC,QAAQ,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,2BAA2B,CAAC,CAAC;AAC/D;IACA,QAAQ,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAC/B,QAAQ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9B,QAAQ,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;AACjC;IACA,QAAQ,KAAK,CAAC,OAAO,EAAE,CAAC;IACxB,KAAK;AACL;IACA;IACA;IACA;IACA;IACA,IAAI,WAAW,GAAG;IAClB,QAAQ,MAAM,KAAK,GAAG,CAAC,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C;IACA;IACA,MAAM,KAAK,GAAG,gBAAgB,CAAC,SAAS,CAAC;AACzC;IACA,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;AACxB;IACA;AACAC,oBAAa,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"frost-ui-passwordstrength.js","sources":["../src/password-strength.js","../src/prototype/events.js","../src/prototype/helpers.js","../src/prototype/render.js","../src/static/helpers.js","../src/index.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * PasswordStrength Class\n * @class\n */\nexport default class PasswordStrength extends BaseComponent {\n /**\n * New PasswordStrength constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the PasswordStrength with.\n */\n constructor(node, options) {\n super(node, options);\n\n if (this._options.container) {\n this._container = $.findOne(this._options.container);\n } else {\n this._container = $.closest(this._node, ':not(.form-input):not(.input-group)');\n }\n\n this._render();\n this._refresh();\n this._events();\n }\n\n /**\n * Dispose the PasswordStrength.\n */\n dispose() {\n $.remove(this._progress);\n $.removeEvent(this._node, 'input.ui.passwordstrength');\n $.removeAttribute(this._node, 'aria-describedby');\n\n this._container = null;\n this._progress = null;\n this._progressBar = null;\n\n super.dispose();\n }\n\n /**\n * Get the password strength.\n * @return {number} The password strength. (0, 100)\n */\n getStrength() {\n const value = $.getValue(this._node);\n\n return this.constructor.getStrength(value);\n }\n}\n","import $ from '@fr0st/query';\n\n/**\n * Attach events for the PasswordStrength.\n */\nexport function _events() {\n $.addEvent(this._node, 'input.ui.passwordstrength', (_) => {\n this._refresh();\n });\n};\n","import $ from '@fr0st/query';\n\n/**\n * Refresh the password strength.\n */\nexport function _refresh() {\n const strength = this.getStrength();\n\n let nextLevel;\n for (const level of this._options.levels) {\n if (strength < level.score) {\n break;\n }\n\n nextLevel = level;\n }\n\n $.setStyle(this._progressBar, { width: `${strength}%` });\n $.setAttribute(this._progressBar, {\n 'class': this.constructor.classes.progressBar,\n 'aria-valuenow': strength,\n });\n\n $.addClass(this._progressBar, nextLevel.class);\n\n if (this._options.striped) {\n $.addClass(this._progressBar, this.constructor.classes.progressBarStriped);\n }\n\n if (nextLevel.text) {\n $.setText(this._progressBar, nextLevel.text);\n }\n};\n","import $ from '@fr0st/query';\nimport { generateId } from '@fr0st/ui';\n\n/**\n * Render the password strength element.\n */\nexport function _render() {\n this._progress = $.create('div', {\n class: this.constructor.classes.progress,\n });\n\n const id = generateId('password-strength');\n\n this._progressBar = $.create('div', {\n attributes: {\n 'id': id,\n 'role': 'progressbar',\n 'aria-valuemin': 0,\n 'aria-valuemax': 100,\n },\n });\n\n $.append(this._progress, this._progressBar);\n $.append(this._container, this._progress);\n\n $.setAttribute(this._node, {\n 'aria-describedby': id,\n });\n};\n","import $ from '@fr0st/query';\n\n/**\n * Find character sequences in a string.\n * @param {string} string The input string.\n * @param {array} locations The character locations.\n * @return {array} The character sequences.\n */\nfunction findSequences(string, locations) {\n const sequences = [];\n let sequence = [];\n\n for (let i = 0; i < locations.length - 1; i++) {\n const current = locations[i];\n const next = locations[i + 1];\n const distance = next - current;\n\n const char = string[current];\n const nextChar = string[next];\n const charDistance = nextChar.charCodeAt(0) - char.charCodeAt(0);\n\n if (distance === 1 && charDistance === 1) {\n if (!sequence.length) {\n sequence.push(char);\n }\n sequence.push(nextChar);\n } else if (sequence.length) {\n sequences.push(sequence);\n sequence = [];\n }\n }\n\n if (sequence.length) {\n sequences.push(sequence);\n }\n\n return sequences;\n};\n\n/**\n * Get the strength of a password.\n * @param {string} password The password.\n * @return {number} The password strength.\n */\nexport function getStrength(password) {\n if (password.match(/^password/i)) {\n password = password.substring(8);\n }\n\n const length = password.length;\n\n let score = 0;\n\n if (length) {\n score += length * 6;\n }\n\n const upper = [];\n const lower = [];\n const numbers = [];\n const symbols = [];\n const dictionary = {};\n\n for (let i = 0; i < length; i++) {\n const char = password[i];\n const code = char.charCodeAt(0);\n\n if (code >= 48 && code <= 57) {\n numbers.push(i);\n } else if (code >= 65 && code <= 90) {\n upper.push(i);\n } else if (code >= 97 && code <= 122) {\n lower.push(i);\n } else {\n symbols.push(i);\n }\n\n if (!(char in dictionary)) {\n dictionary[char] = 0;\n }\n\n dictionary[char]++;\n }\n\n // reward upper/lower case\n if (upper.length !== length && lower.length !== length) {\n if (upper.length) {\n score += length - upper.length;\n }\n\n if (lower.length) {\n score += length - lower.length;\n }\n }\n\n // reward numbers\n if (numbers.length !== length) {\n score += numbers.length * 3;\n }\n\n // reward symbols\n score += symbols.length * 6;\n\n // reward inner numbers/symbols\n for (const list of [numbers, symbols]) {\n const reward = list.filter((v) => v && v !== length - 1).length;\n score += reward * 3;\n }\n\n // punish only letters\n if (!numbers.length && !symbols.length) {\n score -= length;\n }\n\n // punish only numbers\n if (!upper.length && !lower.length && !symbols.length) {\n score -= length;\n }\n\n // punish no symbols\n if (!symbols.length) {\n score -= length;\n }\n\n // repeating characters\n const repeats = Object.values(dictionary)\n .reduce((acc, count) => acc + count - 1, 0);\n\n if (repeats > 0) {\n score -= repeats;\n }\n\n if (length >= 2) {\n // consecutive characters\n const matches = password.matchAll(/(.)\\1+/g);\n\n for (const match of matches) {\n score -= Math.min(match[0].length, 12) * 3;\n }\n\n const lowerPassword = password.toLowerCase();\n\n // sequential letters\n const letters = upper.concat(lower);\n const letterSequences = findSequences(lowerPassword, letters);\n for (const sequence of letterSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n\n // sequential numbers\n const numberSequences = findSequences(lowerPassword, numbers);\n for (const sequence of numberSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n }\n\n return $._clamp(score, 0, 100);\n};\n","import { initComponent } from '@fr0st/ui';\nimport PasswordStrength from './password-strength.js';\nimport { _events } from './prototype/events.js';\nimport { _refresh } from './prototype/helpers.js';\nimport { _render } from './prototype/render.js';\nimport { getStrength } from './static/helpers.js';\n\n// PasswordStrength default options\nPasswordStrength.defaults = {\n levels: [\n {\n score: 0,\n class: 'text-bg-danger',\n text: 'Very Weak',\n },\n {\n score: 20,\n class: 'text-bg-danger',\n text: 'Weak',\n },\n {\n score: 40,\n class: 'text-bg-warning',\n text: 'Normal',\n },\n {\n score: 60,\n class: 'text-bg-success',\n text: 'Strong',\n },\n {\n score: 80,\n class: 'text-bg-success',\n text: 'Very Strong',\n },\n ],\n container: null,\n striped: false,\n};\n\n// PasswordStrength classes\nPasswordStrength.classes = {\n progress: 'progress mt-2',\n progressBar: 'progress-bar',\n progressBarStriped: 'progress-bar-striped',\n};\n\n// PasswordStrength static\nPasswordStrength.getStrength = getStrength;\n\n// PasswordStrength prototype\nconst proto = PasswordStrength.prototype;\n\nproto._events = _events;\nproto._refresh = _refresh;\nproto._render = _render;\n\n// PasswordStrength init\ninitComponent('passwordstrength', PasswordStrength);\n\nexport default PasswordStrength;\n"],"names":["BaseComponent","generateId","initComponent"],"mappings":";;;;;;IAGA;IACA;IACA;IACA;IACe,MAAM,gBAAgB,SAASA,gBAAa,CAAC;IAC5D;IACA;IACA;IACA;IACA;IACA,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE;IAC/B,QAAQ,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7B;IACA,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE;IACrC,YAAY,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACjE,SAAS,MAAM;IACf,YAAY,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,qCAAqC,CAAC,CAAC;IAC3F,SAAS;AACT;IACA,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,Q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efined"!=typeof module?e(exports,require("@fr0st/ui"),require("@fr0st/query")):"function"==typeof define&&define.amd?define(["exports","@fr0st/ui","@fr0st/query"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).UI=t.UI||{},t.UI,t.fQuery)}(this,(function(t,e,s){"use strict";class r extends e.BaseComponent{constructor(t,e){super(t,e),this._options.container?this._container=s.findOne(this._options.container):this._container=s.closest(this._node,":not(.form-input):not(.input-group)"),this._render(),this._refresh(),this._events()}dispose(){s.remove(this._progress),s.removeEvent(this._node,"input.ui.passwordstrength"),s.removeAttribute(this._node,"aria-describedby"),this._container=null,this._progress=null,this._progressBar=null,super.dispose()}getStrength(){const t=s.getValue(this._node);return this.constructor.getStrength(t)}}function n(t,e){const s=[];let r=[];for(let n=0;n<e.length-1;n++){const o=e[n],i=e[n+1],h=i-o,a=t[o],c=t[i],g=c.charCodeAt(0)-a.charCodeAt(0);1===h&&1===g?(r.length||r.push(a),r.push(c)):r.length&&(s.push(r),r=[])}return r.length&&s.push(r),s}r.defaults={levels:[{score:0,class:"text-bg-danger",text:"Very Weak"},{score:20,class:"text-bg-danger",text:"Weak"},{score:40,class:"text-bg-warning",text:"Normal"},{score:60,class:"text-bg-success",text:"Strong"},{score:80,class:"text-bg-success",text:"Very Strong"}],container:null,striped:!1},r.classes={progress:"progress mt-2",progressBar:"progress-bar",progressBarStriped:"progress-bar-striped"},r.getStrength=function(t){t.match(/^password/i)&&(t=t.substring(8));const e=t.length;let r=0;e&&(r+=6*e);const o=[],i=[],h=[],a=[],c={};for(let s=0;s<e;s++){const e=t[s],r=e.charCodeAt(0);r>=48&&r<=57?h.push(s):r>=65&&r<=90?o.push(s):r>=97&&r<=122?i.push(s):a.push(s),e in c||(c[e]=0),c[e]++}o.length!==e&&i.length!==e&&(o.length&&(r+=e-o.length),i.length&&(r+=e-i.length)),h.length!==e&&(r+=3*h.length),r+=6*a.length;for(const t of[h,a])r+=3*t.filter((t=>t&&t!==e-1)).length;h.length||a.length||(r-=e),o.length||i.length||a.length||(r-=e),a.length||(r-=e);const g=Object.values(c).reduce(((t,e)=>t+e-1),0);if(g>0&&(r-=g),e>=2){const e=t.matchAll(/(.)\1+/g);for(const t of e)r-=3*Math.min(t[0].length,12);const s=t.toLowerCase(),a=n(s,o.concat(i));for(const t of a)t.length>2&&(r-=3*Math.min(t.length-2,16));const c=n(s,h);for(const t of c)t.length>2&&(r-=3*Math.min(t.length-2,16))}return s._clamp(r,0,100)};const o=r.prototype;o._events=function(){s.addEvent(this._node,"input.ui.passwordstrength",(t=>{this._refresh()}))},o._refresh=function(){const t=this.getStrength();let e;for(const s of this._options.levels){if(t<s.score)break;e=s}s.setStyle(this._progressBar,{width:`${t}%`}),s.setAttribute(this._progressBar,{class:this.constructor.classes.progressBar,"aria-valuenow":t}),s.addClass(this._progressBar,e.class),this._options.striped&&s.addClass(this._progressBar,this.constructor.classes.progressBarStriped),e.text&&s.setText(this._progressBar,e.text)},o._render=function(){this._progress=s.create("div",{class:this.constructor.classes.progress});const t=e.generateId("password-strength");this._progressBar=s.create("div",{attributes:{id:t,role:"progressbar","aria-valuemin":0,"aria-valuemax":100}}),s.append(this._progress,this._progressBar),s.append(this._container,this._progress),s.setAttribute(this._node,{"aria-describedby":t})},e.initComponent("passwordstrength",r),t.PasswordStrength=r}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PasswordStrength","BaseComponent","constructor","node","options","super","this","_options","container","_container","$","findOne","closest","_node","_render","_refresh","_events","dispose","remove","_progress","removeEvent","_progressBar","getStrength","value","getValue","findSequences","string","locations","sequences","sequence","i","length","current","next","distance","char","nextChar","charDistance","charCodeAt","push","defaults","levels","score","class","text","striped","classes","progress","progressBar","progressBarStriped","password","match","substring","upper","lower","numbers","symbols","dictionary","code","list","filter","v","repeats","Object","values","reduce","acc","count","matches","matchAll","Math","min","lowerPassword","toLowerCase","letterSequences","concat","numberSequences","_clamp","proto","prototype","addEvent","_","strength","nextLevel","level","setStyle","width","setAttribute","addClass","setText","create","attributes","role","append","initComponent"],"sources":["../src/password-strength.js","../src/static/helpers.js","../src/index.js","../src/prototype/events.js","../src/prototype/helpers.js","../src/prototype/render.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * PasswordStrength Class\n * @class\n */\nexport default class PasswordStrength extends BaseComponent {\n /**\n * New PasswordStrength constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the PasswordStrength with.\n */\n constructor(node, options) {\n super(node, options);\n\n if (this._options.container) {\n this._container = $.findOne(this._options.container);\n } else {\n this._container = $.closest(this._node, ':not(.form-input):not(.input-group)');\n }\n\n this._render();\n this._refresh();\n this._events();\n }\n\n /**\n * Dispose the PasswordStrength.\n */\n dispose() {\n $.remove(this._progress);\n $.removeEvent(this._node, 'input.ui.passwordstrength');\n\n this._container = null;\n this._progress = null;\n this._progressBar = null;\n\n super.dispose();\n }\n\n /**\n * Get the password strength.\n * @return {number} The password strength. (0, 100)\n */\n getStrength() {\n const value = $.getValue(this._node);\n\n return this.constructor.getStrength(value);\n }\n}\n","import $ from '@fr0st/query';\n\n/**\n * Find character sequences in a string.\n * @param {string} string The input string.\n * @param {array} locations The character locations.\n * @return {array} The character sequences.\n */\nfunction findSequences(string, locations) {\n const sequences = [];\n let sequence = [];\n\n for (let i = 0; i < locations.length - 1; i++) {\n const current = locations[i];\n const next = locations[i + 1];\n const distance = next - current;\n\n const char = string[current];\n const nextChar = string[next];\n const charDistance = nextChar.charCodeAt(0) - char.charCodeAt(0);\n\n if (distance === 1 && charDistance === 1) {\n if (!sequence.length) {\n sequence.push(char);\n }\n sequence.push(nextChar);\n } else if (sequence.length) {\n sequences.push(sequence);\n sequence = [];\n }\n }\n\n if (sequence.length) {\n sequences.push(sequence);\n }\n\n return sequences;\n};\n\n/**\n * Get the strength of a password.\n * @param {string} password The password.\n * @return {number} The password strength.\n */\nexport function getStrength(password) {\n if (password.match(/^password/i)) {\n password = password.substring(8);\n }\n\n const length = password.length;\n\n let score = 0;\n\n if (length) {\n score += length * 6;\n }\n\n const upper = [];\n const lower = [];\n const numbers = [];\n const symbols = [];\n const dictionary = {};\n\n for (let i = 0; i < length; i++) {\n const char = password[i];\n const code = char.charCodeAt(0);\n\n if (code >= 48 && code <= 57) {\n numbers.push(i);\n } else if (code >= 65 && code <= 90) {\n upper.push(i);\n } else if (code >= 97 && code <= 122) {\n lower.push(i);\n } else {\n symbols.push(i);\n }\n\n if (!(char in dictionary)) {\n dictionary[char] = 0;\n }\n\n dictionary[char]++;\n }\n\n // reward upper/lower case\n if (upper.length !== length && lower.length !== length) {\n if (upper.length) {\n score += length - upper.length;\n }\n\n if (lower.length) {\n score += length - lower.length;\n }\n }\n\n // reward numbers\n if (numbers.length !== length) {\n score += numbers.length * 3;\n }\n\n // reward symbols\n score += symbols.length * 6;\n\n // reward inner numbers/symbols\n for (const list of [numbers, symbols]) {\n const reward = list.filter((v) => v && v !== length - 1).length;\n score += reward * 3;\n }\n\n // punish only letters\n if (!numbers.length && !symbols.length) {\n score -= length;\n }\n\n // punish only numbers\n if (!upper.length && !lower.length && !symbols.length) {\n score -= length;\n }\n\n // punish no symbols\n if (!symbols.length) {\n score -= length;\n }\n\n // repeating characters\n const repeats = Object.values(dictionary)\n .reduce((acc, count) => acc + count - 1, 0);\n\n if (repeats > 0) {\n score -= repeats;\n }\n\n if (length >= 2) {\n // consecutive characters\n const matches = password.matchAll(/(.)\\1+/g);\n\n for (const match of matches) {\n score -= Math.min(match[0].length, 12) * 3;\n }\n\n const lowerPassword = password.toLowerCase();\n\n // sequential letters\n const letters = upper.concat(lower);\n const letterSequences = findSequences(lowerPassword, letters);\n for (const sequence of letterSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n\n // sequential numbers\n const numberSequences = findSequences(lowerPassword, numbers);\n for (const sequence of numberSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n }\n\n return $._clamp(score, 0, 100);\n};\n","import { initComponent } from '@fr0st/ui';\nimport PasswordStrength from './password-strength.js';\nimport { _events } from './prototype/events.js';\nimport { _refresh } from './prototype/helpers.js';\nimport { _render } from './prototype/render.js';\nimport { getStrength } from './static/helpers.js';\n\n// PasswordStrength default options\nPasswordStrength.defaults = {\n levels: [\n {\n score: 0,\n class: 'text-bg-danger',\n text: 'Very Weak',\n },\n {\n score: 20,\n class: 'text-bg-danger',\n text: 'Weak',\n },\n {\n score: 40,\n class: 'text-bg-warning',\n text: 'Normal',\n },\n {\n score: 60,\n class: 'text-bg-success',\n text: 'Strong',\n },\n {\n score: 80,\n class: 'text-bg-success',\n text: 'Very Strong',\n },\n ],\n container: null,\n striped: false,\n};\n\n// PasswordStrength classes\nPasswordStrength.classes = {\n progress: 'progress mt-2',\n progressBar: 'progress-bar',\n progressBarStriped: 'progress-bar-striped',\n};\n\n// PasswordStrength static\nPasswordStrength.getStrength = getStrength;\n\n// PasswordStrength prototype\nconst proto = PasswordStrength.prototype;\n\nproto._events = _events;\nproto._refresh = _refresh;\nproto._render = _render;\n\n// PasswordStrength init\ninitComponent('passwordstrength', PasswordStrength);\n\nexport default PasswordStrength;\n","import $ from '@fr0st/query';\n\n/**\n * Attach events for the PasswordStrength.\n */\nexport function _events() {\n $.addEvent(this._node, 'input.ui.passwordstrength', (_) => {\n this._refresh();\n });\n};\n","import $ from '@fr0st/query';\n\n/**\n * Refresh the password strength.\n */\nexport function _refresh() {\n const strength = this.getStrength();\n\n let nextLevel;\n for (const level of this._options.levels) {\n if (strength < level.score) {\n break;\n }\n\n nextLevel = level;\n }\n\n $.setStyle(this._progressBar, { width: `${strength}%` });\n $.setAttribute(this._progressBar, {\n 'class': this.constructor.classes.progressBar,\n 'aria-valuenow': strength,\n });\n\n $.addClass(this._progressBar, nextLevel.class);\n\n if (this._options.striped) {\n $.addClass(this._progressBar, this.constructor.classes.progressBarStriped);\n }\n\n if (nextLevel.text) {\n $.setText(this._progressBar, nextLevel.text);\n }\n};\n","import $ from '@fr0st/query';\n\n/**\n * Render the password strength element.\n */\nexport function _render() {\n this._progress = $.create('div', {\n class: this.constructor.classes.progress,\n });\n\n this._progressBar = $.create('div', {\n attributes: {\n 'role': 'progressbar',\n 'aria-valuemin': 0,\n 'aria-valuemax': 100,\n },\n });\n\n $.append(this._progress, this._progressBar);\n $.append(this._container, this._progress);\n};\n"],"mappings":"0UAOe,MAAMA,UAAyBC,gBAM1CC,YAAYC,EAAMC,GACdC,MAAMF,EAAMC,GAERE,KAAKC,SAASC,UACdF,KAAKG,WAAaC,EAAEC,QAAQL,KAAKC,SAASC,WAE1CF,KAAKG,WAAaC,EAAEE,QAAQN,KAAKO,MAAO,uCAG5CP,KAAKQ,UACLR,KAAKS,WACLT,KAAKU,SACb,CAKIC,UACIP,EAAEQ,OAAOZ,KAAKa,WACdT,EAAEU,YAAYd,KAAKO,MAAO,6BAE1BP,KAAKG,WAAa,KAClBH,KAAKa,UAAY,KACjBb,KAAKe,aAAe,KAEpBhB,MAAMY,SACd,CAMIK,cACI,MAAMC,EAAQb,EAAEc,SAASlB,KAAKO,OAE9B,OAAOP,KAAKJ,YAAYoB,YAAYC,EAC5C,ECzCA,SAASE,EAAcC,EAAQC,GAC3B,MAAMC,EAAY,GAClB,IAAIC,EAAW,GAEf,IAAK,IAAIC,EAAI,EAAGA,EAAIH,EAAUI,OAAS,EAAGD,IAAK,CAC3C,MAAME,EAAUL,EAAUG,GACpBG,EAAON,EAAUG,EAAI,GACrBI,EAAWD,EAAOD,EAElBG,EAAOT,EAAOM,GACdI,EAAWV,EAAOO,GAClBI,EAAeD,EAASE,WAAW,GAAKH,EAAKG,WAAW,GAE7C,IAAbJ,GAAmC,IAAjBG,GACbR,EAASE,QACVF,EAASU,KAAKJ,GAElBN,EAASU,KAAKH,IACPP,EAASE,SAChBH,EAAUW,KAAKV,GACfA,EAAW,GAEvB,CAMI,OAJIA,EAASE,QACTH,EAAUW,KAAKV,GAGZD,CACX,CC7BA5B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,EAAE6E,aAAajF,KAAKe,aAAc,CAC9BsB,MAASrC,KAAKJ,YAAY4C,QAAQE,YAClC,gBAAiBkC,IAGrBxE,EAAE8E,SAASlF,KAAKe,aAAc8D,EAAUxC,OAEpCrC,KAAKC,SAASsC,SACdnC,EAAE8E,SAASlF,KAAKe,aAAcf,KAAKJ,YAAY4C,QAAQG,oBAGvDkC,EAAUvC,MACVlC,EAAE+E,QAAQnF,KAAKe,aAAc8D,EAAUvC,KAE/C,EFuBAkC,EAAMhE,QGlDC,WACHR,KAAKa,UAAYT,EAAEgF,OAAO,MAAO,CAC7B/C,MAAOrC,KAAKJ,YAAY4C,QAAQC,WAGpCzC,KAAKe,aAAeX,EAAEgF,OAAO,MAAO,CAChCC,WAAY,CACRC,KAAQ,cACR,gBAAiB,EACjB,gBAAiB,OAIzBlF,EAAEmF,OAAOvF,KAAKa,UAAWb,KAAKe,cAC9BX,EAAEmF,OAAOvF,KAAKG,WAAYH,KAAKa,UACnC,EHsCA2E,gBAAc,mBAAoB9F,G"}
|
|
1
|
+
{"version":3,"names":["PasswordStrength","BaseComponent","constructor","node","options","super","this","_options","container","_container","$","findOne","closest","_node","_render","_refresh","_events","dispose","remove","_progress","removeEvent","removeAttribute","_progressBar","getStrength","value","getValue","findSequences","string","locations","sequences","sequence","i","length","current","next","distance","char","nextChar","charDistance","charCodeAt","push","defaults","levels","score","class","text","striped","classes","progress","progressBar","progressBarStriped","password","match","substring","upper","lower","numbers","symbols","dictionary","code","list","filter","v","repeats","Object","values","reduce","acc","count","matches","matchAll","Math","min","lowerPassword","toLowerCase","letterSequences","concat","numberSequences","_clamp","proto","prototype","addEvent","_","strength","nextLevel","level","setStyle","width","setAttribute","addClass","setText","create","id","generateId","attributes","role","append","initComponent"],"sources":["../src/password-strength.js","../src/static/helpers.js","../src/index.js","../src/prototype/events.js","../src/prototype/helpers.js","../src/prototype/render.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * PasswordStrength Class\n * @class\n */\nexport default class PasswordStrength extends BaseComponent {\n /**\n * New PasswordStrength constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the PasswordStrength with.\n */\n constructor(node, options) {\n super(node, options);\n\n if (this._options.container) {\n this._container = $.findOne(this._options.container);\n } else {\n this._container = $.closest(this._node, ':not(.form-input):not(.input-group)');\n }\n\n this._render();\n this._refresh();\n this._events();\n }\n\n /**\n * Dispose the PasswordStrength.\n */\n dispose() {\n $.remove(this._progress);\n $.removeEvent(this._node, 'input.ui.passwordstrength');\n $.removeAttribute(this._node, 'aria-describedby');\n\n this._container = null;\n this._progress = null;\n this._progressBar = null;\n\n super.dispose();\n }\n\n /**\n * Get the password strength.\n * @return {number} The password strength. (0, 100)\n */\n getStrength() {\n const value = $.getValue(this._node);\n\n return this.constructor.getStrength(value);\n }\n}\n","import $ from '@fr0st/query';\n\n/**\n * Find character sequences in a string.\n * @param {string} string The input string.\n * @param {array} locations The character locations.\n * @return {array} The character sequences.\n */\nfunction findSequences(string, locations) {\n const sequences = [];\n let sequence = [];\n\n for (let i = 0; i < locations.length - 1; i++) {\n const current = locations[i];\n const next = locations[i + 1];\n const distance = next - current;\n\n const char = string[current];\n const nextChar = string[next];\n const charDistance = nextChar.charCodeAt(0) - char.charCodeAt(0);\n\n if (distance === 1 && charDistance === 1) {\n if (!sequence.length) {\n sequence.push(char);\n }\n sequence.push(nextChar);\n } else if (sequence.length) {\n sequences.push(sequence);\n sequence = [];\n }\n }\n\n if (sequence.length) {\n sequences.push(sequence);\n }\n\n return sequences;\n};\n\n/**\n * Get the strength of a password.\n * @param {string} password The password.\n * @return {number} The password strength.\n */\nexport function getStrength(password) {\n if (password.match(/^password/i)) {\n password = password.substring(8);\n }\n\n const length = password.length;\n\n let score = 0;\n\n if (length) {\n score += length * 6;\n }\n\n const upper = [];\n const lower = [];\n const numbers = [];\n const symbols = [];\n const dictionary = {};\n\n for (let i = 0; i < length; i++) {\n const char = password[i];\n const code = char.charCodeAt(0);\n\n if (code >= 48 && code <= 57) {\n numbers.push(i);\n } else if (code >= 65 && code <= 90) {\n upper.push(i);\n } else if (code >= 97 && code <= 122) {\n lower.push(i);\n } else {\n symbols.push(i);\n }\n\n if (!(char in dictionary)) {\n dictionary[char] = 0;\n }\n\n dictionary[char]++;\n }\n\n // reward upper/lower case\n if (upper.length !== length && lower.length !== length) {\n if (upper.length) {\n score += length - upper.length;\n }\n\n if (lower.length) {\n score += length - lower.length;\n }\n }\n\n // reward numbers\n if (numbers.length !== length) {\n score += numbers.length * 3;\n }\n\n // reward symbols\n score += symbols.length * 6;\n\n // reward inner numbers/symbols\n for (const list of [numbers, symbols]) {\n const reward = list.filter((v) => v && v !== length - 1).length;\n score += reward * 3;\n }\n\n // punish only letters\n if (!numbers.length && !symbols.length) {\n score -= length;\n }\n\n // punish only numbers\n if (!upper.length && !lower.length && !symbols.length) {\n score -= length;\n }\n\n // punish no symbols\n if (!symbols.length) {\n score -= length;\n }\n\n // repeating characters\n const repeats = Object.values(dictionary)\n .reduce((acc, count) => acc + count - 1, 0);\n\n if (repeats > 0) {\n score -= repeats;\n }\n\n if (length >= 2) {\n // consecutive characters\n const matches = password.matchAll(/(.)\\1+/g);\n\n for (const match of matches) {\n score -= Math.min(match[0].length, 12) * 3;\n }\n\n const lowerPassword = password.toLowerCase();\n\n // sequential letters\n const letters = upper.concat(lower);\n const letterSequences = findSequences(lowerPassword, letters);\n for (const sequence of letterSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n\n // sequential numbers\n const numberSequences = findSequences(lowerPassword, numbers);\n for (const sequence of numberSequences) {\n if (sequence.length > 2) {\n score -= (Math.min(sequence.length - 2, 16)) * 3;\n }\n }\n }\n\n return $._clamp(score, 0, 100);\n};\n","import { initComponent } from '@fr0st/ui';\nimport PasswordStrength from './password-strength.js';\nimport { _events } from './prototype/events.js';\nimport { _refresh } from './prototype/helpers.js';\nimport { _render } from './prototype/render.js';\nimport { getStrength } from './static/helpers.js';\n\n// PasswordStrength default options\nPasswordStrength.defaults = {\n levels: [\n {\n score: 0,\n class: 'text-bg-danger',\n text: 'Very Weak',\n },\n {\n score: 20,\n class: 'text-bg-danger',\n text: 'Weak',\n },\n {\n score: 40,\n class: 'text-bg-warning',\n text: 'Normal',\n },\n {\n score: 60,\n class: 'text-bg-success',\n text: 'Strong',\n },\n {\n score: 80,\n class: 'text-bg-success',\n text: 'Very Strong',\n },\n ],\n container: null,\n striped: false,\n};\n\n// PasswordStrength classes\nPasswordStrength.classes = {\n progress: 'progress mt-2',\n progressBar: 'progress-bar',\n progressBarStriped: 'progress-bar-striped',\n};\n\n// PasswordStrength static\nPasswordStrength.getStrength = getStrength;\n\n// PasswordStrength prototype\nconst proto = PasswordStrength.prototype;\n\nproto._events = _events;\nproto._refresh = _refresh;\nproto._render = _render;\n\n// PasswordStrength init\ninitComponent('passwordstrength', PasswordStrength);\n\nexport default PasswordStrength;\n","import $ from '@fr0st/query';\n\n/**\n * Attach events for the PasswordStrength.\n */\nexport function _events() {\n $.addEvent(this._node, 'input.ui.passwordstrength', (_) => {\n this._refresh();\n });\n};\n","import $ from '@fr0st/query';\n\n/**\n * Refresh the password strength.\n */\nexport function _refresh() {\n const strength = this.getStrength();\n\n let nextLevel;\n for (const level of this._options.levels) {\n if (strength < level.score) {\n break;\n }\n\n nextLevel = level;\n }\n\n $.setStyle(this._progressBar, { width: `${strength}%` });\n $.setAttribute(this._progressBar, {\n 'class': this.constructor.classes.progressBar,\n 'aria-valuenow': strength,\n });\n\n $.addClass(this._progressBar, nextLevel.class);\n\n if (this._options.striped) {\n $.addClass(this._progressBar, this.constructor.classes.progressBarStriped);\n }\n\n if (nextLevel.text) {\n $.setText(this._progressBar, nextLevel.text);\n }\n};\n","import $ from '@fr0st/query';\nimport { generateId } from '@fr0st/ui';\n\n/**\n * Render the password strength element.\n */\nexport function _render() {\n this._progress = $.create('div', {\n class: this.constructor.classes.progress,\n });\n\n const id = generateId('password-strength');\n\n this._progressBar = $.create('div', {\n attributes: {\n 'id': id,\n 'role': 'progressbar',\n 'aria-valuemin': 0,\n 'aria-valuemax': 100,\n },\n });\n\n $.append(this._progress, this._progressBar);\n $.append(this._container, this._progress);\n\n $.setAttribute(this._node, {\n 'aria-describedby': id,\n });\n};\n"],"mappings":"0UAOe,MAAMA,UAAyBC,gBAM1CC,YAAYC,EAAMC,GACdC,MAAMF,EAAMC,GAERE,KAAKC,SAASC,UACdF,KAAKG,WAAaC,EAAEC,QAAQL,KAAKC,SAASC,WAE1CF,KAAKG,WAAaC,EAAEE,QAAQN,KAAKO,MAAO,uCAG5CP,KAAKQ,UACLR,KAAKS,WACLT,KAAKU,SACb,CAKIC,UACIP,EAAEQ,OAAOZ,KAAKa,WACdT,EAAEU,YAAYd,KAAKO,MAAO,6BAC1BH,EAAEW,gBAAgBf,KAAKO,MAAO,oBAE9BP,KAAKG,WAAa,KAClBH,KAAKa,UAAY,KACjBb,KAAKgB,aAAe,KAEpBjB,MAAMY,SACd,CAMIM,cACI,MAAMC,EAAQd,EAAEe,SAASnB,KAAKO,OAE9B,OAAOP,KAAKJ,YAAYqB,YAAYC,EAC5C,EC1CA,SAASE,EAAcC,EAAQC,GAC3B,MAAMC,EAAY,GAClB,IAAIC,EAAW,GAEf,IAAK,IAAIC,EAAI,EAAGA,EAAIH,EAAUI,OAAS,EAAGD,IAAK,CAC3C,MAAME,EAAUL,EAAUG,GACpBG,EAAON,EAAUG,EAAI,GACrBI,EAAWD,EAAOD,EAElBG,EAAOT,EAAOM,GACdI,EAAWV,EAAOO,GAClBI,EAAeD,EAASE,WAAW,GAAKH,EAAKG,WAAW,GAE7C,IAAbJ,GAAmC,IAAjBG,GACbR,EAASE,QACVF,EAASU,KAAKJ,GAElBN,EAASU,KAAKH,IACPP,EAASE,SAChBH,EAAUW,KAAKV,GACfA,EAAW,GAEvB,CAMI,OAJIA,EAASE,QACTH,EAAUW,KAAKV,GAGZD,CACX,CC7BA7B,EAA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8E,aAAalF,KAAKgB,aAAc,CAC9BsB,MAAStC,KAAKJ,YAAY6C,QAAQE,YAClC,gBAAiBkC,IAGrBzE,EAAE+E,SAASnF,KAAKgB,aAAc8D,EAAUxC,OAEpCtC,KAAKC,SAASuC,SACdpC,EAAE+E,SAASnF,KAAKgB,aAAchB,KAAKJ,YAAY6C,QAAQG,oBAGvDkC,EAAUvC,MACVnC,EAAEgF,QAAQpF,KAAKgB,aAAc8D,EAAUvC,KAE/C,EFuBAkC,EAAMjE,QGjDC,WACHR,KAAKa,UAAYT,EAAEiF,OAAO,MAAO,CAC7B/C,MAAOtC,KAAKJ,YAAY6C,QAAQC,WAGpC,MAAM4C,EAAKC,aAAW,qBAEtBvF,KAAKgB,aAAeZ,EAAEiF,OAAO,MAAO,CAChCG,WAAY,CACRF,GAAMA,EACNG,KAAQ,cACR,gBAAiB,EACjB,gBAAiB,OAIzBrF,EAAEsF,OAAO1F,KAAKa,UAAWb,KAAKgB,cAC9BZ,EAAEsF,OAAO1F,KAAKG,WAAYH,KAAKa,WAE/BT,EAAE8E,aAAalF,KAAKO,MAAO,CACvB,mBAAoB+E,GAE5B,EH8BAK,gBAAc,mBAAoBjG,G"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fr0st/ui-passwordstrength",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "FrostUI-PasswordStrength is a free, open-source Password Strength component for Javascript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"private": false,
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@rollup/plugin-node-resolve": "^15.0
|
|
41
|
-
"eslint": "^8.
|
|
40
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
41
|
+
"eslint": "^8.43.0",
|
|
42
42
|
"eslint-config-google": "^0.14.0",
|
|
43
|
-
"rollup": "^3.
|
|
44
|
-
"terser": "^5.
|
|
43
|
+
"rollup": "^3.25.1",
|
|
44
|
+
"terser": "^5.18.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/password-strength.js
CHANGED
|
@@ -31,6 +31,7 @@ export default class PasswordStrength extends BaseComponent {
|
|
|
31
31
|
dispose() {
|
|
32
32
|
$.remove(this._progress);
|
|
33
33
|
$.removeEvent(this._node, 'input.ui.passwordstrength');
|
|
34
|
+
$.removeAttribute(this._node, 'aria-describedby');
|
|
34
35
|
|
|
35
36
|
this._container = null;
|
|
36
37
|
this._progress = null;
|
package/src/prototype/render.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import $ from '@fr0st/query';
|
|
2
|
+
import { generateId } from '@fr0st/ui';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Render the password strength element.
|
|
@@ -8,8 +9,11 @@ export function _render() {
|
|
|
8
9
|
class: this.constructor.classes.progress,
|
|
9
10
|
});
|
|
10
11
|
|
|
12
|
+
const id = generateId('password-strength');
|
|
13
|
+
|
|
11
14
|
this._progressBar = $.create('div', {
|
|
12
15
|
attributes: {
|
|
16
|
+
'id': id,
|
|
13
17
|
'role': 'progressbar',
|
|
14
18
|
'aria-valuemin': 0,
|
|
15
19
|
'aria-valuemax': 100,
|
|
@@ -18,4 +22,8 @@ export function _render() {
|
|
|
18
22
|
|
|
19
23
|
$.append(this._progress, this._progressBar);
|
|
20
24
|
$.append(this._container, this._progress);
|
|
25
|
+
|
|
26
|
+
$.setAttribute(this._node, {
|
|
27
|
+
'aria-describedby': id,
|
|
28
|
+
});
|
|
21
29
|
};
|