@su-labs/fields 0.0.0-stage → 22.0.0
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/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/fesm2022/su-labs-fields.mjs +334 -0
- package/fesm2022/su-labs-fields.mjs.map +1 -0
- package/package.json +49 -3
- package/types/su-labs-fields.d.ts +113 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [22.0.0] - 2026-11-11
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `SuCodeBoxesComponent` (`su-lib-code-boxes`): a short code typed into boxes that fill one by one and turn green in a wave once complete; one real text field underneath, so pasting, phone keyboards and screen readers work
|
|
14
|
+
- `SuStrengthMeterComponent` (`su-lib-strength-meter`): four bars under a new password that fill and change colour as it gets stronger, with its word per step; a `meter` for screen readers
|
|
15
|
+
- `suPasswordStrength()` and `suStrengthLevel()`: the meter's rule, usable on its own
|
|
16
|
+
- `SuAutoGrowDirective` (`textarea[suAutoGrow]`): a text box that grows a line at a time with a soft spring, and shrinks back when emptied
|
|
17
|
+
- `--su-field-*` CSS variables for colours, and no motion for visitors who ask their device for less
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yevheniy Alekseyev <yev.alekseyev@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fields
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@su-labs/fields`
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Small animated form fields for Angular, built on plain inputs so forms, pasting, phone keyboards and screen readers keep working:
|
|
9
|
+
|
|
10
|
+
- **Code boxes**: a short code typed into boxes that fill one by one, then turn green in a wave once it's complete.
|
|
11
|
+
- **Strength meter**: four bars under a new password that fill and change colour as it gets stronger.
|
|
12
|
+
- **Auto grow**: a text box that grows a line at a time with a soft spring.
|
|
13
|
+
|
|
14
|
+
Every animation stops for visitors who ask their device for less motion.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @su-labs/fields
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Code boxes
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { SuCodeBoxesComponent } from '@su-labs/fields';
|
|
26
|
+
|
|
27
|
+
code = signal('');
|
|
28
|
+
isComplete = computed(() => /^[A-Z0-9]{6}$/.test(this.code()));
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<su-lib-code-boxes [(value)]="code" [length]="6" label="Room code" [complete]="isComplete()" />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Input | Type | |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `value` | `string` (two-way) | The code typed so far, in capitals without spaces |
|
|
38
|
+
| `length` | `number` | How many boxes |
|
|
39
|
+
| `label` | `string` | The field's name for screen readers |
|
|
40
|
+
| `complete` | `boolean` | The code is whole and valid: the boxes turn green |
|
|
41
|
+
|
|
42
|
+
## Strength meter
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<input #password type="password" autocomplete="new-password" />
|
|
46
|
+
<su-lib-strength-meter
|
|
47
|
+
[field]="password"
|
|
48
|
+
label="Password strength"
|
|
49
|
+
[levelNames]="{ weak: 'Weak', fair: 'Fair', good: 'Good', strong: 'Strong' }"
|
|
50
|
+
[minLength]="10"
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The meter follows the field's typing. If your code empties the field, send it an `input` event so the meter sees it.
|
|
55
|
+
|
|
56
|
+
The rule is exported too: `suPasswordStrength(password, minLength)` gives 0 to 4 bars, and `suStrengthLevel(bars)` its step
|
|
57
|
+
(`weak`, `fair`, `good`, `strong`).
|
|
58
|
+
|
|
59
|
+
## Auto grow
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<textarea suAutoGrow rows="2"></textarea>
|
|
63
|
+
<textarea [suAutoGrow]="isOn()" rows="2"></textarea>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
It also shrinks back when its form is reset.
|
|
67
|
+
|
|
68
|
+
## Theming
|
|
69
|
+
|
|
70
|
+
Set these CSS variables (each has a fallback):
|
|
71
|
+
|
|
72
|
+
| Variable | Used for |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `--su-field-surface` | Box background |
|
|
75
|
+
| `--su-field-border` | Box border |
|
|
76
|
+
| `--su-field-filled-border` | Border of a filled box |
|
|
77
|
+
| `--su-field-text` | Letters in the boxes |
|
|
78
|
+
| `--su-field-accent` | The box the next letter goes into |
|
|
79
|
+
| `--su-field-success`, `--su-field-success-bg` | A complete code, a strong password |
|
|
80
|
+
| `--su-field-warning` | A fair password |
|
|
81
|
+
| `--su-field-danger` | A weak password |
|
|
82
|
+
| `--su-field-track` | Empty meter bars |
|
|
83
|
+
| `--su-field-font-mono` | Letters in the boxes |
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, afterNextRender, booleanAttribute, computed, effect, inject, input, model, signal } from "@angular/core";
|
|
3
|
+
var SuCodeBoxesComponent = class SuCodeBoxesComponent {
|
|
4
|
+
value = model("", ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
|
|
5
|
+
length = input.required(...ngDevMode ? [{ debugName: "length" }] : /* istanbul ignore next */ []);
|
|
6
|
+
label = input.required(...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
7
|
+
complete = input(false, ...ngDevMode ? [{ debugName: "complete" }] : /* istanbul ignore next */ []);
|
|
8
|
+
boxes = computed(() => Array.from({ length: this.length() }, (_, index) => index), ...ngDevMode ? [{ debugName: "boxes" }] : /* istanbul ignore next */ []);
|
|
9
|
+
onInput(field) {
|
|
10
|
+
const code = field.value.replace(/\s/g, "").toUpperCase().slice(0, this.length());
|
|
11
|
+
field.value = code;
|
|
12
|
+
this.value.set(code);
|
|
13
|
+
}
|
|
14
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
15
|
+
minVersion: "12.0.0",
|
|
16
|
+
version: "22.2.4",
|
|
17
|
+
ngImport: i0,
|
|
18
|
+
type: SuCodeBoxesComponent,
|
|
19
|
+
deps: [],
|
|
20
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
21
|
+
});
|
|
22
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
23
|
+
minVersion: "17.0.0",
|
|
24
|
+
version: "22.2.4",
|
|
25
|
+
type: SuCodeBoxesComponent,
|
|
26
|
+
isStandalone: true,
|
|
27
|
+
selector: "su-lib-code-boxes",
|
|
28
|
+
inputs: {
|
|
29
|
+
value: {
|
|
30
|
+
classPropertyName: "value",
|
|
31
|
+
publicName: "value",
|
|
32
|
+
isSignal: true,
|
|
33
|
+
isRequired: false,
|
|
34
|
+
transformFunction: null
|
|
35
|
+
},
|
|
36
|
+
length: {
|
|
37
|
+
classPropertyName: "length",
|
|
38
|
+
publicName: "length",
|
|
39
|
+
isSignal: true,
|
|
40
|
+
isRequired: true,
|
|
41
|
+
transformFunction: null
|
|
42
|
+
},
|
|
43
|
+
label: {
|
|
44
|
+
classPropertyName: "label",
|
|
45
|
+
publicName: "label",
|
|
46
|
+
isSignal: true,
|
|
47
|
+
isRequired: true,
|
|
48
|
+
transformFunction: null
|
|
49
|
+
},
|
|
50
|
+
complete: {
|
|
51
|
+
classPropertyName: "complete",
|
|
52
|
+
publicName: "complete",
|
|
53
|
+
isSignal: true,
|
|
54
|
+
isRequired: false,
|
|
55
|
+
transformFunction: null
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
outputs: { value: "valueChange" },
|
|
59
|
+
ngImport: i0,
|
|
60
|
+
template: "<input\n #field\n class=\"field\"\n type=\"text\"\n inputmode=\"text\"\n autocomplete=\"off\"\n autocapitalize=\"characters\"\n spellcheck=\"false\"\n required\n [attr.maxlength]=\"length()\"\n [attr.aria-label]=\"label()\"\n [value]=\"value()\"\n (input)=\"onInput(field)\"\n/>\n<span class=\"boxes\" [class.is-complete]=\"complete()\" aria-hidden=\"true\">\n @for (index of boxes(); track index) {\n <span\n class=\"box\"\n [class.is-filled]=\"index < value().length\"\n [class.is-current]=\"index === value().length\"\n [style.--index]=\"index\"\n >{{ value()[index] }}</span\n >\n }\n</span>\n",
|
|
61
|
+
styles: [":host{display:block;position:relative;width:fit-content}.field{background:transparent;border:0;caret-color:transparent;color:transparent;cursor:text;font-size:1rem;inset:0;opacity:.01;position:absolute;width:100%;z-index:1}.boxes{display:flex;gap:.5rem}.box{align-items:center;background:var(--su-field-surface, transparent);border:1px solid var(--su-field-border, rgba(127, 127, 127, .4));border-radius:.5rem;color:var(--su-field-text, currentColor);display:flex;font-family:var(--su-field-font-mono, monospace);font-size:1.375rem;height:3rem;justify-content:center;transition:border-color .2s ease,background-color .2s ease,color .2s ease;width:2.5rem}.box.is-filled{animation:box-pop .22s cubic-bezier(.34,1.56,.64,1);border-color:var(--su-field-filled-border, currentColor)}.field:focus-visible+.boxes .box.is-current,.field:focus+.boxes .box.is-current{border-color:var(--su-field-accent, #3b82f6);box-shadow:0 0 0 3px color-mix(in srgb,var(--su-field-accent, #3b82f6) 25%,transparent)}.boxes.is-complete .box{animation:box-done .36s ease calc(var(--index) * 60ms) both;background:var(--su-field-success-bg, #e6f4ea);border-color:var(--su-field-success, #2e8b57);color:var(--su-field-success, #2e8b57);transition-delay:calc(var(--index) * 60ms)}@keyframes box-pop{0%{transform:scale(.85)}}@keyframes box-done{50%{transform:translateY(-4px)}}@media(prefers-reduced-motion:reduce){.box,.boxes.is-complete .box{animation:none;transition:none}}\n"],
|
|
62
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
66
|
+
minVersion: "12.0.0",
|
|
67
|
+
version: "22.2.4",
|
|
68
|
+
ngImport: i0,
|
|
69
|
+
type: SuCodeBoxesComponent,
|
|
70
|
+
decorators: [{
|
|
71
|
+
type: Component,
|
|
72
|
+
args: [{
|
|
73
|
+
selector: "su-lib-code-boxes",
|
|
74
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
75
|
+
template: "<input\n #field\n class=\"field\"\n type=\"text\"\n inputmode=\"text\"\n autocomplete=\"off\"\n autocapitalize=\"characters\"\n spellcheck=\"false\"\n required\n [attr.maxlength]=\"length()\"\n [attr.aria-label]=\"label()\"\n [value]=\"value()\"\n (input)=\"onInput(field)\"\n/>\n<span class=\"boxes\" [class.is-complete]=\"complete()\" aria-hidden=\"true\">\n @for (index of boxes(); track index) {\n <span\n class=\"box\"\n [class.is-filled]=\"index < value().length\"\n [class.is-current]=\"index === value().length\"\n [style.--index]=\"index\"\n >{{ value()[index] }}</span\n >\n }\n</span>\n",
|
|
76
|
+
styles: [":host{display:block;position:relative;width:fit-content}.field{background:transparent;border:0;caret-color:transparent;color:transparent;cursor:text;font-size:1rem;inset:0;opacity:.01;position:absolute;width:100%;z-index:1}.boxes{display:flex;gap:.5rem}.box{align-items:center;background:var(--su-field-surface, transparent);border:1px solid var(--su-field-border, rgba(127, 127, 127, .4));border-radius:.5rem;color:var(--su-field-text, currentColor);display:flex;font-family:var(--su-field-font-mono, monospace);font-size:1.375rem;height:3rem;justify-content:center;transition:border-color .2s ease,background-color .2s ease,color .2s ease;width:2.5rem}.box.is-filled{animation:box-pop .22s cubic-bezier(.34,1.56,.64,1);border-color:var(--su-field-filled-border, currentColor)}.field:focus-visible+.boxes .box.is-current,.field:focus+.boxes .box.is-current{border-color:var(--su-field-accent, #3b82f6);box-shadow:0 0 0 3px color-mix(in srgb,var(--su-field-accent, #3b82f6) 25%,transparent)}.boxes.is-complete .box{animation:box-done .36s ease calc(var(--index) * 60ms) both;background:var(--su-field-success-bg, #e6f4ea);border-color:var(--su-field-success, #2e8b57);color:var(--su-field-success, #2e8b57);transition-delay:calc(var(--index) * 60ms)}@keyframes box-pop{0%{transform:scale(.85)}}@keyframes box-done{50%{transform:translateY(-4px)}}@media(prefers-reduced-motion:reduce){.box,.boxes.is-complete .box{animation:none;transition:none}}\n"]
|
|
77
|
+
}]
|
|
78
|
+
}],
|
|
79
|
+
propDecorators: {
|
|
80
|
+
value: [{
|
|
81
|
+
type: i0.Input,
|
|
82
|
+
args: [{
|
|
83
|
+
isSignal: true,
|
|
84
|
+
alias: "value",
|
|
85
|
+
required: false
|
|
86
|
+
}]
|
|
87
|
+
}, {
|
|
88
|
+
type: i0.Output,
|
|
89
|
+
args: ["valueChange"]
|
|
90
|
+
}],
|
|
91
|
+
length: [{
|
|
92
|
+
type: i0.Input,
|
|
93
|
+
args: [{
|
|
94
|
+
isSignal: true,
|
|
95
|
+
alias: "length",
|
|
96
|
+
required: true
|
|
97
|
+
}]
|
|
98
|
+
}],
|
|
99
|
+
label: [{
|
|
100
|
+
type: i0.Input,
|
|
101
|
+
args: [{
|
|
102
|
+
isSignal: true,
|
|
103
|
+
alias: "label",
|
|
104
|
+
required: true
|
|
105
|
+
}]
|
|
106
|
+
}],
|
|
107
|
+
complete: [{
|
|
108
|
+
type: i0.Input,
|
|
109
|
+
args: [{
|
|
110
|
+
isSignal: true,
|
|
111
|
+
alias: "complete",
|
|
112
|
+
required: false
|
|
113
|
+
}]
|
|
114
|
+
}]
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const SU_STRENGTH_LEVELS = [
|
|
118
|
+
"weak",
|
|
119
|
+
"fair",
|
|
120
|
+
"good",
|
|
121
|
+
"strong"
|
|
122
|
+
];
|
|
123
|
+
const SU_DEFAULT_MIN_PASSWORD_LENGTH = 8;
|
|
124
|
+
function suPasswordStrength(password, minLength = 8) {
|
|
125
|
+
if (password.length === 0) return 0;
|
|
126
|
+
if (password.length < minLength) return 1;
|
|
127
|
+
return 1 + [
|
|
128
|
+
password.length >= minLength + 4,
|
|
129
|
+
/\p{L}/u.test(password) && /\d/.test(password),
|
|
130
|
+
/[^\p{L}\d]/u.test(password) || /\p{Lu}/u.test(password) && /\p{Ll}/u.test(password)
|
|
131
|
+
].filter(Boolean).length;
|
|
132
|
+
}
|
|
133
|
+
const suStrengthLevel = (bars) => SU_STRENGTH_LEVELS[bars - 1] ?? null;
|
|
134
|
+
var SuStrengthMeterComponent = class SuStrengthMeterComponent {
|
|
135
|
+
field = input.required(...ngDevMode ? [{ debugName: "field" }] : /* istanbul ignore next */ []);
|
|
136
|
+
label = input.required(...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
|
|
137
|
+
levelNames = input.required(...ngDevMode ? [{ debugName: "levelNames" }] : /* istanbul ignore next */ []);
|
|
138
|
+
minLength = input(8, ...ngDevMode ? [{ debugName: "minLength" }] : /* istanbul ignore next */ []);
|
|
139
|
+
password = signal("", ...ngDevMode ? [{ debugName: "password" }] : /* istanbul ignore next */ []);
|
|
140
|
+
steps = SU_STRENGTH_LEVELS;
|
|
141
|
+
bars = computed(() => suPasswordStrength(this.password(), this.minLength()), ...ngDevMode ? [{ debugName: "bars" }] : /* istanbul ignore next */ []);
|
|
142
|
+
level = computed(() => suStrengthLevel(this.bars()), ...ngDevMode ? [{ debugName: "level" }] : /* istanbul ignore next */ []);
|
|
143
|
+
levelName = computed(() => {
|
|
144
|
+
const level = this.level();
|
|
145
|
+
return level ? this.levelNames()[level] : null;
|
|
146
|
+
}, ...ngDevMode ? [{ debugName: "levelName" }] : /* istanbul ignore next */ []);
|
|
147
|
+
constructor() {
|
|
148
|
+
effect((onCleanup) => {
|
|
149
|
+
const field = this.field();
|
|
150
|
+
const read = () => this.password.set(field.value);
|
|
151
|
+
read();
|
|
152
|
+
field.addEventListener("input", read);
|
|
153
|
+
onCleanup(() => field.removeEventListener("input", read));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
157
|
+
minVersion: "12.0.0",
|
|
158
|
+
version: "22.2.4",
|
|
159
|
+
ngImport: i0,
|
|
160
|
+
type: SuStrengthMeterComponent,
|
|
161
|
+
deps: [],
|
|
162
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
163
|
+
});
|
|
164
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
165
|
+
minVersion: "17.0.0",
|
|
166
|
+
version: "22.2.4",
|
|
167
|
+
type: SuStrengthMeterComponent,
|
|
168
|
+
isStandalone: true,
|
|
169
|
+
selector: "su-lib-strength-meter",
|
|
170
|
+
inputs: {
|
|
171
|
+
field: {
|
|
172
|
+
classPropertyName: "field",
|
|
173
|
+
publicName: "field",
|
|
174
|
+
isSignal: true,
|
|
175
|
+
isRequired: true,
|
|
176
|
+
transformFunction: null
|
|
177
|
+
},
|
|
178
|
+
label: {
|
|
179
|
+
classPropertyName: "label",
|
|
180
|
+
publicName: "label",
|
|
181
|
+
isSignal: true,
|
|
182
|
+
isRequired: true,
|
|
183
|
+
transformFunction: null
|
|
184
|
+
},
|
|
185
|
+
levelNames: {
|
|
186
|
+
classPropertyName: "levelNames",
|
|
187
|
+
publicName: "levelNames",
|
|
188
|
+
isSignal: true,
|
|
189
|
+
isRequired: true,
|
|
190
|
+
transformFunction: null
|
|
191
|
+
},
|
|
192
|
+
minLength: {
|
|
193
|
+
classPropertyName: "minLength",
|
|
194
|
+
publicName: "minLength",
|
|
195
|
+
isSignal: true,
|
|
196
|
+
isRequired: false,
|
|
197
|
+
transformFunction: null
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
ngImport: i0,
|
|
201
|
+
template: "<div\n class=\"bars\"\n role=\"meter\"\n [attr.aria-label]=\"label()\"\n aria-valuemin=\"0\"\n [attr.aria-valuemax]=\"steps.length\"\n [attr.aria-valuenow]=\"bars()\"\n [attr.aria-valuetext]=\"levelName()\"\n>\n @for (step of steps; track step; let index = $index) {\n <span class=\"bar\" [class.is-filled]=\"index < bars()\" [style.--index]=\"index\"></span>\n }\n</div>\n@if (levelName(); as name) {\n <small class=\"level\" [attr.data-level]=\"level()\" aria-hidden=\"true\">{{ name }}</small>\n}\n",
|
|
202
|
+
styles: [":host{display:grid;gap:.375rem}.bars{display:grid;gap:.375rem;grid-template-columns:repeat(4,1fr)}.bar{background:var(--su-field-track, rgba(127, 127, 127, .2));border-radius:9999px;height:.3125rem;overflow:hidden;position:relative}.bar:after{background:var(--meter-colour, var(--su-field-danger, #c0392b));border-radius:inherit;content:\"\";inset:0;position:absolute;transform:scaleX(0);transform-origin:left;transition:transform .26s cubic-bezier(.34,1.56,.64,1) calc(var(--index) * 40ms),background-color .26s ease}.bar.is-filled:after{transform:scaleX(1)}:host:has(.level[data-level=fair]){--meter-colour: var(--su-field-warning, #c98a00)}:host:has(.level[data-level=good]),:host:has(.level[data-level=strong]){--meter-colour: var(--su-field-success, #2e8b57)}.level{color:var(--meter-colour, var(--su-field-danger, #c0392b));font-size:.75rem;font-weight:600;justify-self:end}@media(prefers-reduced-motion:reduce){.bar:after{transition:none}}\n"],
|
|
203
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
207
|
+
minVersion: "12.0.0",
|
|
208
|
+
version: "22.2.4",
|
|
209
|
+
ngImport: i0,
|
|
210
|
+
type: SuStrengthMeterComponent,
|
|
211
|
+
decorators: [{
|
|
212
|
+
type: Component,
|
|
213
|
+
args: [{
|
|
214
|
+
selector: "su-lib-strength-meter",
|
|
215
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
216
|
+
template: "<div\n class=\"bars\"\n role=\"meter\"\n [attr.aria-label]=\"label()\"\n aria-valuemin=\"0\"\n [attr.aria-valuemax]=\"steps.length\"\n [attr.aria-valuenow]=\"bars()\"\n [attr.aria-valuetext]=\"levelName()\"\n>\n @for (step of steps; track step; let index = $index) {\n <span class=\"bar\" [class.is-filled]=\"index < bars()\" [style.--index]=\"index\"></span>\n }\n</div>\n@if (levelName(); as name) {\n <small class=\"level\" [attr.data-level]=\"level()\" aria-hidden=\"true\">{{ name }}</small>\n}\n",
|
|
217
|
+
styles: [":host{display:grid;gap:.375rem}.bars{display:grid;gap:.375rem;grid-template-columns:repeat(4,1fr)}.bar{background:var(--su-field-track, rgba(127, 127, 127, .2));border-radius:9999px;height:.3125rem;overflow:hidden;position:relative}.bar:after{background:var(--meter-colour, var(--su-field-danger, #c0392b));border-radius:inherit;content:\"\";inset:0;position:absolute;transform:scaleX(0);transform-origin:left;transition:transform .26s cubic-bezier(.34,1.56,.64,1) calc(var(--index) * 40ms),background-color .26s ease}.bar.is-filled:after{transform:scaleX(1)}:host:has(.level[data-level=fair]){--meter-colour: var(--su-field-warning, #c98a00)}:host:has(.level[data-level=good]),:host:has(.level[data-level=strong]){--meter-colour: var(--su-field-success, #2e8b57)}.level{color:var(--meter-colour, var(--su-field-danger, #c0392b));font-size:.75rem;font-weight:600;justify-self:end}@media(prefers-reduced-motion:reduce){.bar:after{transition:none}}\n"]
|
|
218
|
+
}]
|
|
219
|
+
}],
|
|
220
|
+
ctorParameters: () => [],
|
|
221
|
+
propDecorators: {
|
|
222
|
+
field: [{
|
|
223
|
+
type: i0.Input,
|
|
224
|
+
args: [{
|
|
225
|
+
isSignal: true,
|
|
226
|
+
alias: "field",
|
|
227
|
+
required: true
|
|
228
|
+
}]
|
|
229
|
+
}],
|
|
230
|
+
label: [{
|
|
231
|
+
type: i0.Input,
|
|
232
|
+
args: [{
|
|
233
|
+
isSignal: true,
|
|
234
|
+
alias: "label",
|
|
235
|
+
required: true
|
|
236
|
+
}]
|
|
237
|
+
}],
|
|
238
|
+
levelNames: [{
|
|
239
|
+
type: i0.Input,
|
|
240
|
+
args: [{
|
|
241
|
+
isSignal: true,
|
|
242
|
+
alias: "levelNames",
|
|
243
|
+
required: true
|
|
244
|
+
}]
|
|
245
|
+
}],
|
|
246
|
+
minLength: [{
|
|
247
|
+
type: i0.Input,
|
|
248
|
+
args: [{
|
|
249
|
+
isSignal: true,
|
|
250
|
+
alias: "minLength",
|
|
251
|
+
required: false
|
|
252
|
+
}]
|
|
253
|
+
}]
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const SPRING = "height 240ms cubic-bezier(0.34, 1.56, 0.64, 1)";
|
|
257
|
+
var SuAutoGrowDirective = class SuAutoGrowDirective {
|
|
258
|
+
isOn = input(true, {
|
|
259
|
+
...ngDevMode ? { debugName: "isOn" } : /* istanbul ignore next */ {},
|
|
260
|
+
alias: "suAutoGrow",
|
|
261
|
+
transform: booleanAttribute
|
|
262
|
+
});
|
|
263
|
+
box = inject(ElementRef).nativeElement;
|
|
264
|
+
constructor() {
|
|
265
|
+
const destroyRef = inject(DestroyRef);
|
|
266
|
+
afterNextRender(() => {
|
|
267
|
+
const onReset = () => setTimeout(() => this.fit());
|
|
268
|
+
this.box.form?.addEventListener("reset", onReset);
|
|
269
|
+
destroyRef.onDestroy(() => this.box.form?.removeEventListener("reset", onReset));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
fit() {
|
|
273
|
+
if (!this.isOn()) return;
|
|
274
|
+
const box = this.box;
|
|
275
|
+
const from = box.offsetHeight;
|
|
276
|
+
box.style.transition = "none";
|
|
277
|
+
box.style.height = "auto";
|
|
278
|
+
const to = box.scrollHeight + box.offsetHeight - box.clientHeight;
|
|
279
|
+
box.style.height = `${from}px`;
|
|
280
|
+
box.offsetHeight;
|
|
281
|
+
box.style.overflowY = "hidden";
|
|
282
|
+
box.style.transition = matchMedia("(prefers-reduced-motion: reduce)").matches ? "none" : SPRING;
|
|
283
|
+
box.style.height = `${to}px`;
|
|
284
|
+
}
|
|
285
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
286
|
+
minVersion: "12.0.0",
|
|
287
|
+
version: "22.2.4",
|
|
288
|
+
ngImport: i0,
|
|
289
|
+
type: SuAutoGrowDirective,
|
|
290
|
+
deps: [],
|
|
291
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
292
|
+
});
|
|
293
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
294
|
+
minVersion: "17.1.0",
|
|
295
|
+
version: "22.2.4",
|
|
296
|
+
type: SuAutoGrowDirective,
|
|
297
|
+
isStandalone: true,
|
|
298
|
+
selector: "textarea[suAutoGrow]",
|
|
299
|
+
inputs: { isOn: {
|
|
300
|
+
classPropertyName: "isOn",
|
|
301
|
+
publicName: "suAutoGrow",
|
|
302
|
+
isSignal: true,
|
|
303
|
+
isRequired: false,
|
|
304
|
+
transformFunction: null
|
|
305
|
+
} },
|
|
306
|
+
host: { listeners: { "input": "fit()" } },
|
|
307
|
+
ngImport: i0
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
311
|
+
minVersion: "12.0.0",
|
|
312
|
+
version: "22.2.4",
|
|
313
|
+
ngImport: i0,
|
|
314
|
+
type: SuAutoGrowDirective,
|
|
315
|
+
decorators: [{
|
|
316
|
+
type: Directive,
|
|
317
|
+
args: [{
|
|
318
|
+
selector: "textarea[suAutoGrow]",
|
|
319
|
+
host: { "(input)": "fit()" }
|
|
320
|
+
}]
|
|
321
|
+
}],
|
|
322
|
+
ctorParameters: () => [],
|
|
323
|
+
propDecorators: { isOn: [{
|
|
324
|
+
type: i0.Input,
|
|
325
|
+
args: [{
|
|
326
|
+
isSignal: true,
|
|
327
|
+
alias: "suAutoGrow",
|
|
328
|
+
required: false
|
|
329
|
+
}]
|
|
330
|
+
}] }
|
|
331
|
+
});
|
|
332
|
+
export { SU_DEFAULT_MIN_PASSWORD_LENGTH, SU_STRENGTH_LEVELS, SuAutoGrowDirective, SuCodeBoxesComponent, SuStrengthMeterComponent, suPasswordStrength, suStrengthLevel };
|
|
333
|
+
|
|
334
|
+
//# sourceMappingURL=su-labs-fields.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"su-labs-fields.mjs","names":[],"sources":["../../../../projects/su-labs/fields/src/lib/code-boxes/code-boxes.component.ts","../../../../projects/su-labs/fields/src/lib/code-boxes/code-boxes.component.html","../../../../projects/su-labs/fields/src/lib/strength-meter/password-strength.ts","../../../../projects/su-labs/fields/src/lib/strength-meter/strength-meter.component.ts","../../../../projects/su-labs/fields/src/lib/strength-meter/strength-meter.component.html","../../../../projects/su-labs/fields/src/lib/auto-grow/auto-grow.directive.ts"],"sourcesContent":["import { ChangeDetectionStrategy, Component, computed, input, model } from '@angular/core';\n\n/**\n * A short code typed into a row of boxes that fill one by one, then turn green in a wave once the code is complete.\n * One real text field lies over the boxes, so typing, pasting, the phone keyboard and screen readers all work as usual.\n */\n@Component({\n selector: 'su-lib-code-boxes',\n changeDetection: ChangeDetectionStrategy.OnPush,\n templateUrl: './code-boxes.component.html',\n styleUrl: './code-boxes.component.scss',\n})\nexport class SuCodeBoxesComponent {\n readonly value = model('');\n readonly length = input.required<number>();\n readonly label = input.required<string>();\n /** The code is whole and well-formed: the boxes turn green */\n readonly complete = input(false);\n\n protected readonly boxes = computed(() =>\n Array.from({ length: this.length() }, (_, index) => index)\n );\n\n /** Capitals without spaces, never longer than the boxes */\n protected onInput(field: HTMLInputElement): void {\n const code = field.value\n .replace(/\\s/g, '')\n .toUpperCase()\n .slice(0, this.length());\n field.value = code;\n this.value.set(code);\n }\n}\n","<input\n #field\n class=\"field\"\n type=\"text\"\n inputmode=\"text\"\n autocomplete=\"off\"\n autocapitalize=\"characters\"\n spellcheck=\"false\"\n required\n [attr.maxlength]=\"length()\"\n [attr.aria-label]=\"label()\"\n [value]=\"value()\"\n (input)=\"onInput(field)\"\n/>\n<span class=\"boxes\" [class.is-complete]=\"complete()\" aria-hidden=\"true\">\n @for (index of boxes(); track index) {\n <span\n class=\"box\"\n [class.is-filled]=\"index < value().length\"\n [class.is-current]=\"index === value().length\"\n [style.--index]=\"index\"\n >{{ value()[index] }}</span\n >\n }\n</span>\n","/** How strong a new password looks, one step per bar of the meter */\nexport const SU_STRENGTH_LEVELS = ['weak', 'fair', 'good', 'strong'] as const;\nexport type SuStrengthLevel = (typeof SU_STRENGTH_LEVELS)[number];\n\n/** Shortest password the meter counts as more than weak, unless told otherwise */\nexport const SU_DEFAULT_MIN_PASSWORD_LENGTH = 8;\n\n/**\n * Bars of the strength meter a password fills, from 0 (empty) to 4. Under the minimum length it stays at one bar,\n * whatever else it has. Then one bar each for: four characters past the minimum, letters with digits, and symbols or\n * mixed case.\n */\nexport function suPasswordStrength(\n password: string,\n minLength = SU_DEFAULT_MIN_PASSWORD_LENGTH\n): number {\n if (password.length === 0) {\n return 0;\n }\n if (password.length < minLength) {\n return 1;\n }\n const extras = [\n password.length >= minLength + 4,\n /\\p{L}/u.test(password) && /\\d/.test(password),\n /[^\\p{L}\\d]/u.test(password) ||\n (/\\p{Lu}/u.test(password) && /\\p{Ll}/u.test(password)),\n ].filter(Boolean).length;\n return 1 + extras;\n}\n\n/** The meter's word for a number of bars, or null for an empty password */\nexport const suStrengthLevel = (bars: number): SuStrengthLevel | null =>\n SU_STRENGTH_LEVELS[bars - 1] ?? null;\n","import { ChangeDetectionStrategy, Component, computed, effect, input, signal } from '@angular/core';\nimport { SU_DEFAULT_MIN_PASSWORD_LENGTH, SU_STRENGTH_LEVELS, suPasswordStrength, SuStrengthLevel, suStrengthLevel } from './password-strength';\n\n/**\n * Four bars under a new password that fill, and change colour, as the password gets stronger. It follows the field's\n * own typing, so forms keep their plain fields; a form that empties the field by code sends it an `input` event.\n * Its texts come in as inputs, so it fits any language.\n */\n@Component({\n selector: 'su-lib-strength-meter',\n changeDetection: ChangeDetectionStrategy.OnPush,\n templateUrl: './strength-meter.component.html',\n styleUrl: './strength-meter.component.scss',\n})\nexport class SuStrengthMeterComponent {\n readonly field = input.required<HTMLInputElement>();\n /** The meter's name for screen readers, e.g. \"Password strength\" */\n readonly label = input.required<string>();\n /** The word shown for each step */\n readonly levelNames =\n input.required<Readonly<Record<SuStrengthLevel, string>>>();\n readonly minLength = input(SU_DEFAULT_MIN_PASSWORD_LENGTH);\n\n private readonly password = signal('');\n protected readonly steps = SU_STRENGTH_LEVELS;\n protected readonly bars = computed(() =>\n suPasswordStrength(this.password(), this.minLength())\n );\n protected readonly level = computed(() => suStrengthLevel(this.bars()));\n protected readonly levelName = computed(() => {\n const level = this.level();\n return level ? this.levelNames()[level] : null;\n });\n\n constructor() {\n effect(onCleanup => {\n const field = this.field();\n const read = () => this.password.set(field.value);\n read();\n field.addEventListener('input', read);\n onCleanup(() => field.removeEventListener('input', read));\n });\n }\n}\n","<div\n class=\"bars\"\n role=\"meter\"\n [attr.aria-label]=\"label()\"\n aria-valuemin=\"0\"\n [attr.aria-valuemax]=\"steps.length\"\n [attr.aria-valuenow]=\"bars()\"\n [attr.aria-valuetext]=\"levelName()\"\n>\n @for (step of steps; track step; let index = $index) {\n <span class=\"bar\" [class.is-filled]=\"index < bars()\" [style.--index]=\"index\"></span>\n }\n</div>\n@if (levelName(); as name) {\n <small class=\"level\" [attr.data-level]=\"level()\" aria-hidden=\"true\">{{ name }}</small>\n}\n","import { afterNextRender, booleanAttribute, DestroyRef, Directive, ElementRef, inject, input } from '@angular/core';\n\n/** A soft spring that overshoots a little, as the box settles on its new height */\nconst SPRING = 'height 240ms cubic-bezier(0.34, 1.56, 0.64, 1)';\n\n/**\n * A text box that grows a line at a time as the text gets longer, and shrinks back when it is emptied, with a soft\n * spring (none for visitors who asked their device for less motion). `[suAutoGrow]=\"false\"` leaves it as it is.\n */\n@Directive({\n selector: 'textarea[suAutoGrow]',\n host: { '(input)': 'fit()' },\n})\nexport class SuAutoGrowDirective {\n readonly isOn = input(true, { alias: 'suAutoGrow', transform: booleanAttribute });\n\n private readonly box: HTMLTextAreaElement = inject(ElementRef).nativeElement;\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n afterNextRender(() => {\n // Emptied by a form reset, which sends no input event; the value only changes after the event\n const onReset = () => setTimeout(() => this.fit());\n this.box.form?.addEventListener('reset', onReset);\n destroyRef.onDestroy(() =>\n this.box.form?.removeEventListener('reset', onReset)\n );\n });\n }\n\n protected fit(): void {\n if (!this.isOn()) {\n return;\n }\n const box = this.box;\n const from = box.offsetHeight;\n // Measured at its natural height, without the animation, then set back so the change can animate\n box.style.transition = 'none';\n box.style.height = 'auto';\n const to = box.scrollHeight + box.offsetHeight - box.clientHeight;\n box.style.height = `${from}px`;\n void box.offsetHeight;\n box.style.overflowY = 'hidden';\n box.style.transition = matchMedia('(prefers-reduced-motion: reduce)')\n .matches\n ? 'none'\n : SPRING;\n box.style.height = `${to}px`;\n }\n}\n"],"mappings":";;AAYA,IAAa,uBAAb,MAAa,qBAAoB;CACtB,QAAQ,MAAM,IAAG,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CACjB,SAAS,MAAM,SAAkB,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;CACjC,QAAQ,MAAM,SAAkB,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAEhC,WAAW,MAAM,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAEb,QAAQ,eACzB,MAAM,KAAK,EAAE,QAAQ,KAAK,OAAM,EAAE,IAAK,GAAG,UAAU,KAAK,GAC1D,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAGS,QAAQ,OAAuB;EACvC,MAAM,OAAO,MAAM,MAChB,QAAQ,OAAO,EAAE,CAAC,CAClB,YAAW,CAAE,CACb,MAAM,GAAG,KAAK,OAAM,CAAE;EACzB,MAAM,QAAQ;EACd,KAAK,MAAM,IAAI,IAAI;CACrB;CAnBW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAoB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAApB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAoB,cA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MAAM,MAAM,KAAK;EACjB,MAAM,OAAO,IAAI;EAEjB,IAAI,MAAM,aAAa;EACvB,IAAI,MAAM,SAAS;EACnB,MAAM,KAAK,IAAI,eAAe,IAAI,eAAe,IAAI;EACrD,IAAI,MAAM,SAAS,GAAG,KAAI;EAC1B,AAAK,IAAI;EACT,IAAI,MAAM,YAAY;EACtB,IAAI,MAAM,aAAa,WAAW,kCAAkC,CAAC,CAClE,UACC,SACA;EACJ,IAAI,MAAM,SAAS,GAAG,GAAE;CAC1B;CAnCW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAmB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAnB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAmB,cAAA;EAAA,UAAA;EAAA,QAAA,EAAA,MAAA;GAAA,mBAAA;GAAA,YAAA;GAAA,UAAA;GAAA,YAAA;GAAA,mBAAA;EAAA,EAAA;EAAA,MAAA,EAAA,WAAA,EAAA,SAAA,QAAA,EAAA;EAAA,UAAA;CAAA,CAAA;;AAAnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAmB,YAAA,CAAA;EAJ/B,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,MAAM,EAAE,WAAW,QAAO;EAC3B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/fields",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "22.0.0",
|
|
4
|
+
"description": "Animated Angular form fields: code boxes that fill one by one, a password strength meter, and a text box that grows as you type.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"form",
|
|
8
|
+
"input",
|
|
9
|
+
"otp",
|
|
10
|
+
"code-input",
|
|
11
|
+
"password-strength",
|
|
12
|
+
"textarea",
|
|
13
|
+
"auto-grow",
|
|
14
|
+
"animation",
|
|
15
|
+
"ui"
|
|
16
|
+
],
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Yevheniy Alekseyev",
|
|
19
|
+
"email": "yev.alekseyev@gmail.com",
|
|
20
|
+
"url": "https://github.com/Greezaaa"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/Greezaaa/settings-utils-lib.git",
|
|
25
|
+
"directory": "projects/su-labs/fields"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://su-labs.dev/fields/",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/Greezaaa/settings-utils-lib/issues"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@angular/common": "^22.0.0",
|
|
33
|
+
"@angular/core": "^22.0.0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"tslib": "^2.3.0"
|
|
37
|
+
},
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"module": "fesm2022/su-labs-fields.mjs",
|
|
41
|
+
"typings": "types/su-labs-fields.d.ts",
|
|
42
|
+
"exports": {
|
|
43
|
+
"./package.json": {
|
|
44
|
+
"default": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
".": {
|
|
47
|
+
"types": "./types/su-labs-fields.d.ts",
|
|
48
|
+
"default": "./fesm2022/su-labs-fields.mjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"type": "module"
|
|
6
52
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
/**
|
|
3
|
+
* A short code typed into a row of boxes that fill one by one, then turn green in a wave once the code is complete.
|
|
4
|
+
* One real text field lies over the boxes, so typing, pasting, the phone keyboard and screen readers all work as usual.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SuCodeBoxesComponent {
|
|
7
|
+
readonly value: import("@angular/core").ModelSignal<string>;
|
|
8
|
+
readonly length: import("@angular/core").InputSignal<number>;
|
|
9
|
+
readonly label: import("@angular/core").InputSignal<string>;
|
|
10
|
+
/** The code is whole and well-formed: the boxes turn green */
|
|
11
|
+
readonly complete: import("@angular/core").InputSignal<boolean>;
|
|
12
|
+
protected readonly boxes: import("@angular/core").Signal<number[]>;
|
|
13
|
+
/** Capitals without spaces, never longer than the boxes */
|
|
14
|
+
protected onInput(field: HTMLInputElement): void;
|
|
15
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuCodeBoxesComponent, never>;
|
|
16
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SuCodeBoxesComponent, "su-lib-code-boxes", never, {
|
|
17
|
+
"value": {
|
|
18
|
+
"alias": "value";
|
|
19
|
+
"required": false;
|
|
20
|
+
"isSignal": true;
|
|
21
|
+
};
|
|
22
|
+
"length": {
|
|
23
|
+
"alias": "length";
|
|
24
|
+
"required": true;
|
|
25
|
+
"isSignal": true;
|
|
26
|
+
};
|
|
27
|
+
"label": {
|
|
28
|
+
"alias": "label";
|
|
29
|
+
"required": true;
|
|
30
|
+
"isSignal": true;
|
|
31
|
+
};
|
|
32
|
+
"complete": {
|
|
33
|
+
"alias": "complete";
|
|
34
|
+
"required": false;
|
|
35
|
+
"isSignal": true;
|
|
36
|
+
};
|
|
37
|
+
}, {
|
|
38
|
+
"value": "valueChange";
|
|
39
|
+
}, never, never, true, never>;
|
|
40
|
+
}
|
|
41
|
+
/** How strong a new password looks, one step per bar of the meter */
|
|
42
|
+
export declare const SU_STRENGTH_LEVELS: readonly ["weak", "fair", "good", "strong"];
|
|
43
|
+
export type SuStrengthLevel = (typeof SU_STRENGTH_LEVELS)[number];
|
|
44
|
+
/** Shortest password the meter counts as more than weak, unless told otherwise */
|
|
45
|
+
export declare const SU_DEFAULT_MIN_PASSWORD_LENGTH = 8;
|
|
46
|
+
/**
|
|
47
|
+
* Bars of the strength meter a password fills, from 0 (empty) to 4. Under the minimum length it stays at one bar,
|
|
48
|
+
* whatever else it has. Then one bar each for: four characters past the minimum, letters with digits, and symbols or
|
|
49
|
+
* mixed case.
|
|
50
|
+
*/
|
|
51
|
+
export declare function suPasswordStrength(password: string, minLength?: number): number;
|
|
52
|
+
/** The meter's word for a number of bars, or null for an empty password */
|
|
53
|
+
export declare const suStrengthLevel: (bars: number) => SuStrengthLevel | null;
|
|
54
|
+
/**
|
|
55
|
+
* Four bars under a new password that fill, and change colour, as the password gets stronger. It follows the field's
|
|
56
|
+
* own typing, so forms keep their plain fields; a form that empties the field by code sends it an `input` event.
|
|
57
|
+
* Its texts come in as inputs, so it fits any language.
|
|
58
|
+
*/
|
|
59
|
+
export declare class SuStrengthMeterComponent {
|
|
60
|
+
readonly field: import("@angular/core").InputSignal<HTMLInputElement>;
|
|
61
|
+
/** The meter's name for screen readers, e.g. "Password strength" */
|
|
62
|
+
readonly label: import("@angular/core").InputSignal<string>;
|
|
63
|
+
/** The word shown for each step */
|
|
64
|
+
readonly levelNames: import("@angular/core").InputSignal<Readonly<Record<"weak" | "fair" | "good" | "strong", string>>>;
|
|
65
|
+
readonly minLength: import("@angular/core").InputSignal<number>;
|
|
66
|
+
private readonly password;
|
|
67
|
+
protected readonly steps: readonly ["weak", "fair", "good", "strong"];
|
|
68
|
+
protected readonly bars: import("@angular/core").Signal<number>;
|
|
69
|
+
protected readonly level: import("@angular/core").Signal<"weak" | "fair" | "good" | "strong" | null>;
|
|
70
|
+
protected readonly levelName: import("@angular/core").Signal<string | null>;
|
|
71
|
+
constructor();
|
|
72
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuStrengthMeterComponent, never>;
|
|
73
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SuStrengthMeterComponent, "su-lib-strength-meter", never, {
|
|
74
|
+
"field": {
|
|
75
|
+
"alias": "field";
|
|
76
|
+
"required": true;
|
|
77
|
+
"isSignal": true;
|
|
78
|
+
};
|
|
79
|
+
"label": {
|
|
80
|
+
"alias": "label";
|
|
81
|
+
"required": true;
|
|
82
|
+
"isSignal": true;
|
|
83
|
+
};
|
|
84
|
+
"levelNames": {
|
|
85
|
+
"alias": "levelNames";
|
|
86
|
+
"required": true;
|
|
87
|
+
"isSignal": true;
|
|
88
|
+
};
|
|
89
|
+
"minLength": {
|
|
90
|
+
"alias": "minLength";
|
|
91
|
+
"required": false;
|
|
92
|
+
"isSignal": true;
|
|
93
|
+
};
|
|
94
|
+
}, {}, never, never, true, never>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A text box that grows a line at a time as the text gets longer, and shrinks back when it is emptied, with a soft
|
|
98
|
+
* spring (none for visitors who asked their device for less motion). `[suAutoGrow]="false"` leaves it as it is.
|
|
99
|
+
*/
|
|
100
|
+
export declare class SuAutoGrowDirective {
|
|
101
|
+
readonly isOn: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
102
|
+
private readonly box;
|
|
103
|
+
constructor();
|
|
104
|
+
protected fit(): void;
|
|
105
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuAutoGrowDirective, never>;
|
|
106
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<SuAutoGrowDirective, "textarea[suAutoGrow]", never, {
|
|
107
|
+
"isOn": {
|
|
108
|
+
"alias": "suAutoGrow";
|
|
109
|
+
"required": false;
|
|
110
|
+
"isSignal": true;
|
|
111
|
+
};
|
|
112
|
+
}, {}, never, never, true, never>;
|
|
113
|
+
}
|