@snowui-design-system/components 0.3.0-alpha.13 → 0.3.0-alpha.14
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/AGENTS.md +3 -1
- package/README.md +5 -3
- package/THIRD_PARTY_NOTICES.md +85 -0
- package/component-catalog.json +65 -0
- package/dist/client/components/Accordion.js +1 -1
- package/dist/client/components/AccordionItem.js +1 -1
- package/dist/client/components/Avatar.js +122 -63
- package/dist/client/components/Button.js +1 -1
- package/dist/client/components/Card.js +10 -0
- package/dist/client/components/CodeBlock.js +38 -10
- package/dist/client/components/Dialog.js +3 -13
- package/dist/client/components/Icon.js +92 -24
- package/dist/client/components/Image.js +21 -10
- package/dist/client/components/Indicator.js +77 -6
- package/dist/client/components/Input.js +192 -94
- package/dist/client/components/MetricCard.d.ts +13 -0
- package/dist/client/components/MetricCard.js +179 -0
- package/dist/client/components/OTPInput.d.ts +2 -1
- package/dist/client/components/OTPInput.js +117 -63
- package/dist/client/components/PasswordStrength.d.ts +20 -0
- package/dist/client/components/PasswordStrength.js +145 -0
- package/dist/client/components/SnowUILogo.d.ts +1 -0
- package/dist/client/components/SnowUILogo.js +11 -7
- package/dist/client/components/StyleButton.js +2 -0
- package/dist/client/i18n/messages.d.ts +1 -1
- package/dist/client/i18n/messages.js +16 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/internal/component-icon/builtin-icon-data.js +14 -0
- package/dist/client/styles/components.css +5 -1
- package/dist/client/styles/scale.css +16 -16
- package/dist/server/components/Accordion.js +1 -1
- package/dist/server/components/AccordionItem.js +1 -1
- package/dist/server/components/Avatar.js +42 -7
- package/dist/server/components/Button.js +1 -1
- package/dist/server/components/Card.js +2 -0
- package/dist/server/components/CodeBlock.js +29 -6
- package/dist/server/components/Dialog.js +3 -10
- package/dist/server/components/Icon.js +37 -2
- package/dist/server/components/Image.js +3 -1
- package/dist/server/components/Indicator.js +6 -3
- package/dist/server/components/Input.js +63 -5
- package/dist/server/components/MetricCard.d.ts +13 -0
- package/dist/server/components/MetricCard.js +104 -0
- package/dist/server/components/OTPInput.d.ts +2 -1
- package/dist/server/components/OTPInput.js +66 -35
- package/dist/server/components/PasswordStrength.d.ts +20 -0
- package/dist/server/components/PasswordStrength.js +105 -0
- package/dist/server/components/SnowUILogo.d.ts +1 -0
- package/dist/server/components/SnowUILogo.js +5 -3
- package/dist/server/components/StyleButton.js +2 -0
- package/dist/server/i18n/messages.d.ts +1 -1
- package/dist/server/i18n/messages.js +16 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +2 -0
- package/dist/server/internal/component-icon/builtin-icon-data.js +14 -0
- package/dist/server/styles/components.css +5 -1
- package/dist/server/styles/scale.css +16 -16
- package/package.json +3 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import 'svelte/internal/disclose-version';
|
|
2
|
+
import * as $ from 'svelte/internal/client';
|
|
3
|
+
import Card from './Card.js';
|
|
4
|
+
import Text from './Text.js';
|
|
5
|
+
|
|
6
|
+
var rest_excludes = new Set([
|
|
7
|
+
'$$slots',
|
|
8
|
+
'$$events',
|
|
9
|
+
'$$legacy',
|
|
10
|
+
'label',
|
|
11
|
+
'value',
|
|
12
|
+
'change',
|
|
13
|
+
'emphasis',
|
|
14
|
+
'trend',
|
|
15
|
+
'class'
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
var root = $.from_html(`<span> </span> `, 1);
|
|
19
|
+
var root_1 = $.from_html(`<!> <!>`, 1);
|
|
20
|
+
var root_2 = $.from_html(`<!> <div class="snowui-metric-values"><!></div>`, 1);
|
|
21
|
+
|
|
22
|
+
const $$css = {
|
|
23
|
+
hash: 'svelte-1iu5zja',
|
|
24
|
+
code: ':where(.snowui-metric-card .snowui-metric-label) {color:var(--black-40, #00000066);padding-inline:var(--padding-1, 4px);}:where(.snowui-metric-values) {display:flex;align-items:baseline;justify-content:space-between;gap:var(--gap-4, 16px);min-width:0;}:where(.snowui-metric-values .snowui-metric-primary) {font-size:var(--text-32, 32px);line-height:var(--leading-32, 40px);min-width:0;}:where(.snowui-metric-values .snowui-metric-secondary) {font-size:var(--text-14);line-height:var(--leading-14, 20px);flex-shrink:0;}:where(.snowui-metric-positive) {color:var(--secondary-green, #71DD8CFF);}:where(.snowui-metric-negative) {color:var(--secondary-red, #FF4747FF);}'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default function MetricCard($$anchor, $$props) {
|
|
28
|
+
$.push($$props, true);
|
|
29
|
+
$.append_styles($$anchor, $$css);
|
|
30
|
+
|
|
31
|
+
let change = $.prop($$props, 'change', 3, undefined),
|
|
32
|
+
emphasis = $.prop($$props, 'emphasis', 3, 'change'),
|
|
33
|
+
trend = $.prop($$props, 'trend', 3, 'neutral'),
|
|
34
|
+
userClass = $.prop($$props, 'class', 3, ''),
|
|
35
|
+
rest = $.rest_props($$props, rest_excludes);
|
|
36
|
+
|
|
37
|
+
let sign = $.derived(() => change() && (/^[+−-]/).test(change()) ? change()[0] : '');
|
|
38
|
+
let changeText = $.derived(() => $.get(sign) ? change()?.slice(1) : change());
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
let $0 = $.derived(() => `snowui-metric-card ${userClass()}`);
|
|
42
|
+
|
|
43
|
+
Card($$anchor, $.spread_props(() => rest, {
|
|
44
|
+
get class() {
|
|
45
|
+
return $.get($0);
|
|
46
|
+
},
|
|
47
|
+
contentFill: true,
|
|
48
|
+
scrollable: false,
|
|
49
|
+
children: ($$anchor, $$slotProps) => {
|
|
50
|
+
var fragment_1 = root_2();
|
|
51
|
+
var node = $.first_child(fragment_1);
|
|
52
|
+
|
|
53
|
+
Text(node, {
|
|
54
|
+
class: 'snowui-metric-label',
|
|
55
|
+
children: ($$anchor, $$slotProps) => {
|
|
56
|
+
$.next();
|
|
57
|
+
|
|
58
|
+
var text = $.text();
|
|
59
|
+
|
|
60
|
+
$.template_effect(() => $.set_text(text, $$props.label));
|
|
61
|
+
$.append($$anchor, text);
|
|
62
|
+
},
|
|
63
|
+
$$slots: { default: true }
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
var div = $.sibling(node, 2);
|
|
67
|
+
var node_1 = $.child(div);
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
var consequent = ($$anchor) => {
|
|
71
|
+
var fragment_3 = root_1();
|
|
72
|
+
var node_2 = $.first_child(fragment_3);
|
|
73
|
+
|
|
74
|
+
Text(node_2, {
|
|
75
|
+
class: 'snowui-metric-primary',
|
|
76
|
+
children: ($$anchor, $$slotProps) => {
|
|
77
|
+
var fragment_4 = root();
|
|
78
|
+
var span = $.first_child(fragment_4);
|
|
79
|
+
var text_1 = $.child(span, true);
|
|
80
|
+
|
|
81
|
+
$.reset(span);
|
|
82
|
+
|
|
83
|
+
var text_2 = $.sibling(span, 1, true);
|
|
84
|
+
|
|
85
|
+
$.template_effect(() => {
|
|
86
|
+
$.set_class(span, 1, `snowui-metric-sign snowui-metric-${trend()}`);
|
|
87
|
+
$.set_text(text_1, $.get(sign));
|
|
88
|
+
$.set_text(text_2, $.get(changeText));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
$.append($$anchor, fragment_4);
|
|
92
|
+
},
|
|
93
|
+
$$slots: { default: true }
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
var node_3 = $.sibling(node_2, 2);
|
|
97
|
+
|
|
98
|
+
Text(node_3, {
|
|
99
|
+
class: 'snowui-metric-secondary',
|
|
100
|
+
children: ($$anchor, $$slotProps) => {
|
|
101
|
+
$.next();
|
|
102
|
+
|
|
103
|
+
var text_3 = $.text();
|
|
104
|
+
|
|
105
|
+
$.template_effect(() => $.set_text(text_3, $$props.value));
|
|
106
|
+
$.append($$anchor, text_3);
|
|
107
|
+
},
|
|
108
|
+
$$slots: { default: true }
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
$.append($$anchor, fragment_3);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
var alternate = ($$anchor) => {
|
|
115
|
+
var fragment_6 = root_1();
|
|
116
|
+
var node_4 = $.first_child(fragment_6);
|
|
117
|
+
|
|
118
|
+
Text(node_4, {
|
|
119
|
+
class: 'snowui-metric-primary',
|
|
120
|
+
children: ($$anchor, $$slotProps) => {
|
|
121
|
+
$.next();
|
|
122
|
+
|
|
123
|
+
var text_4 = $.text();
|
|
124
|
+
|
|
125
|
+
$.template_effect(() => $.set_text(text_4, $$props.value));
|
|
126
|
+
$.append($$anchor, text_4);
|
|
127
|
+
},
|
|
128
|
+
$$slots: { default: true }
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
var node_5 = $.sibling(node_4, 2);
|
|
132
|
+
|
|
133
|
+
{
|
|
134
|
+
var consequent_1 = ($$anchor) => {
|
|
135
|
+
Text($$anchor, {
|
|
136
|
+
class: 'snowui-metric-secondary',
|
|
137
|
+
children: ($$anchor, $$slotProps) => {
|
|
138
|
+
var fragment_9 = root();
|
|
139
|
+
var span_1 = $.first_child(fragment_9);
|
|
140
|
+
var text_5 = $.child(span_1, true);
|
|
141
|
+
|
|
142
|
+
$.reset(span_1);
|
|
143
|
+
|
|
144
|
+
var text_6 = $.sibling(span_1, 1, true);
|
|
145
|
+
|
|
146
|
+
$.template_effect(() => {
|
|
147
|
+
$.set_class(span_1, 1, `snowui-metric-sign snowui-metric-${trend()}`);
|
|
148
|
+
$.set_text(text_5, $.get(sign));
|
|
149
|
+
$.set_text(text_6, $.get(changeText));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
$.append($$anchor, fragment_9);
|
|
153
|
+
},
|
|
154
|
+
$$slots: { default: true }
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
$.if(node_5, ($$render) => {
|
|
159
|
+
if (change() !== undefined) $$render(consequent_1);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
$.append($$anchor, fragment_6);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
$.if(node_1, ($$render) => {
|
|
167
|
+
if (emphasis() === 'change' && change() !== undefined) $$render(consequent); else $$render(alternate, -1);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
$.reset(div);
|
|
172
|
+
$.append($$anchor, fragment_1);
|
|
173
|
+
},
|
|
174
|
+
$$slots: { default: true }
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
$.pop();
|
|
179
|
+
}
|
|
@@ -17,6 +17,7 @@ interface Props extends Omit<FrameProps, "tag" | "children" | "enableScaleObserv
|
|
|
17
17
|
id?: string;
|
|
18
18
|
title?: string;
|
|
19
19
|
invalid?: boolean;
|
|
20
|
+
success?: boolean;
|
|
20
21
|
error?: string | Snippet;
|
|
21
22
|
oncomplete?: (value: string) => void;
|
|
22
23
|
oninput?: (event: Event) => void;
|
|
@@ -27,6 +28,6 @@ interface Props extends Omit<FrameProps, "tag" | "children" | "enableScaleObserv
|
|
|
27
28
|
onpaste?: (event: ClipboardEvent) => void;
|
|
28
29
|
[key: string]: any;
|
|
29
30
|
}
|
|
30
|
-
declare const OTPInput: import("svelte").Component<Props, {}, "value">;
|
|
31
|
+
declare const OTPInput: import("svelte").Component<Props, {}, "value" | "success">;
|
|
31
32
|
type OTPInput = ReturnType<typeof OTPInput>;
|
|
32
33
|
export default OTPInput;
|
|
@@ -3,7 +3,6 @@ import * as $ from 'svelte/internal/client';
|
|
|
3
3
|
import { onDestroy } from "svelte";
|
|
4
4
|
import Text from "./Text.js";
|
|
5
5
|
import { useLocale } from "../i18n/locale.js";
|
|
6
|
-
import { NUMBER_POP_APPEAR_MOTION } from "../motion/presets/effects.js";
|
|
7
6
|
import { TAB_INDICATOR_MOTION_STYLE } from "../motion/presets/tab.js";
|
|
8
7
|
import Frame from "./Frame.js";
|
|
9
8
|
import { splitFrameHostProps } from "../logic/frame-prop-filter.js";
|
|
@@ -26,6 +25,7 @@ var rest_excludes = new Set([
|
|
|
26
25
|
'id',
|
|
27
26
|
'title',
|
|
28
27
|
'invalid',
|
|
28
|
+
'success',
|
|
29
29
|
'error',
|
|
30
30
|
'enableResponsive',
|
|
31
31
|
'enableContext',
|
|
@@ -40,12 +40,14 @@ var rest_excludes = new Set([
|
|
|
40
40
|
'style'
|
|
41
41
|
]);
|
|
42
42
|
|
|
43
|
-
var root = $.from_html(`<span class="snowui-otp-
|
|
44
|
-
var root_1 = $.from_html(`<span class="snowui-otp-
|
|
43
|
+
var root = $.from_html(`<span class="snowui-otp-digit svelte-qr73h1"> </span>`);
|
|
44
|
+
var root_1 = $.from_html(`<span class="snowui-otp-caret svelte-qr73h1" aria-hidden="true"></span>`);
|
|
45
|
+
var root_2 = $.from_html(`<span class="snowui-otp-slot snowui-field-bordered snowui-rounded-rectangle svelte-qr73h1" aria-hidden="true"><!> <!></span>`);
|
|
46
|
+
var root_3 = $.from_html(`<span class="snowui-otp-slots svelte-qr73h1"><input/> <!> <span aria-hidden="true" class="snowui-otp-indicator snowui-field-bordered snowui-rounded-rectangle svelte-qr73h1"></span></span> <!>`, 1);
|
|
45
47
|
|
|
46
48
|
const $$css = {
|
|
47
49
|
hash: 'svelte-qr73h1',
|
|
48
|
-
code: ':where(.snowui-otp-input) {--snowui-otp-input-gap: var(--gap-2);--snowui-otp-input-size: var(--
|
|
50
|
+
code: ':where(.snowui-otp-input) {--snowui-otp-input-gap: var(--gap-2);--snowui-otp-input-size: calc(var(--leading-18, 28px) + 2 * var(--padding-3, 12px));--snowui-otp-input-radius: var(--radius-4);--snowui-otp-input-font-size: var(--text-18);--snowui-otp-input-line-height: var(--leading-18);position:relative;display:inline-flex;flex-direction:column;align-items:flex-start;gap:var(--gap-2);width:fit-content;max-width:100%;color:var(--black-100, #000000);cursor:text;}:where(.snowui-otp-slots) {position:relative;display:flex;gap:var(--snowui-otp-input-gap-override, var(--snowui-otp-input-gap, var(--gap-2)));}:where(.snowui-otp-slot, .snowui-otp-indicator) {display:grid;place-items:center;width:var(--snowui-otp-input-size-override, var(--snowui-otp-input-size, var(--size-10)));height:var(--snowui-otp-input-size-override, var(--snowui-otp-input-size, var(--size-10)));box-sizing:border-box;padding:var(--padding-3, 12px) var(--padding-4, 16px);border:0;border-radius:var(--snowui-otp-input-radius-override, var(--snowui-otp-input-radius, var(--radius-4)));font-size:var(--snowui-otp-input-font-size-override, var(--snowui-otp-input-font-size, var(--text-18, 18px)));line-height:var(--snowui-otp-input-line-height-override, var(--snowui-otp-input-line-height, var(--leading-18, 28px)));font-variant-numeric:tabular-nums;}:where(.snowui-otp-slot) {position:relative;background:var(--surface-1, #ffffffcc);}:where(.snowui-otp-digit) {display:inline-block; animation: svelte-qr73h1-snowui-otp-digit-appear 300ms cubic-bezier(0.34, 1.45, 0.64, 1) both;}\n @keyframes svelte-qr73h1-snowui-otp-digit-appear { from { opacity: 0; transform: perspective(240px) translateY(6px) rotateX(-35deg); } to { opacity: 1; transform: perspective(240px) translateY(0) rotateX(0); } }:where(.snowui-otp-caret) {position:absolute;width:calc(var(--size-1, 4px) / 4);height:var(--size-5, 20px);background:var(--black-100, #000000); animation: svelte-qr73h1-snowui-otp-caret-blink 1s step-end infinite;}:where(.snowui-otp-slot[data-filled="true"] .snowui-otp-caret) {transform:translateX(8px);}\n @keyframes svelte-qr73h1-snowui-otp-caret-blink { 50% { opacity: 0; } }.snowui-otp-input :where(.snowui-otp-indicator) {position:absolute;left:0;top:0;pointer-events:none;opacity:0;transform:translateX(calc(var(--snowui-otp-input-active-index) * (var(--snowui-otp-input-size-override, var(--snowui-otp-input-size)) + var(--snowui-otp-input-gap-override, var(--snowui-otp-input-gap)))));transition:transform var(--snowui-frame-control-motion-duration) var(--snowui-frame-control-motion-easing), box-shadow var(--snowui-frame-control-motion-duration) var(--snowui-frame-control-motion-easing);}.snowui-otp-input :where(.snowui-otp-indicator[data-field-focus="true"]) {opacity:1;}.snowui-otp-input :where(.snowui-otp-indicator[data-field-focus="true"]:not([data-invalid="true"])) {box-shadow:inset 0 0 0 2px var(--black-100, #000000);}:where(.snowui-otp-input[data-disabled="true"]) {cursor:default;opacity:0.2;}:where(.snowui-otp-input[data-readonly="true"]) {cursor:default;}:where(.snowui-otp-input[data-readonly="true"] .snowui-otp-slot) {background:var(--surface-2, #00000008);box-shadow:none;}:where(.snowui-otp-input[data-success="true"] .snowui-otp-slot) {background:var(--surface-2, #00000008);box-shadow:none;}.snowui-otp-input[data-readonly="true"] :where(.snowui-otp-indicator) {opacity:0;}:where(.snowui-otp-native) {position:absolute;inset:0;z-index:1;width:100%;height:100%;margin:0;padding:0;border:0;opacity:0;cursor:inherit;}\n @media (prefers-reduced-motion: reduce) {.snowui-otp-input :where(.snowui-otp-indicator) {transition:none;}:where(.snowui-otp-caret) { animation: none;}:where(.snowui-otp-digit) { animation: none;}\n }'
|
|
49
51
|
};
|
|
50
52
|
|
|
51
53
|
export default function OTPInput($$anchor, $$props) {
|
|
@@ -61,6 +63,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
61
63
|
required = $.prop($$props, 'required', 3, false),
|
|
62
64
|
autocomplete = $.prop($$props, 'autocomplete', 3, "one-time-code"),
|
|
63
65
|
invalid = $.prop($$props, 'invalid', 3, false),
|
|
66
|
+
success = $.prop($$props, 'success', 15, false),
|
|
64
67
|
enableResponsive = $.prop($$props, 'enableResponsive', 3, true),
|
|
65
68
|
enableContext = $.prop($$props, 'enableContext', 3, true),
|
|
66
69
|
userClass = $.prop($$props, 'class', 3, ""),
|
|
@@ -73,8 +76,9 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
73
76
|
let focused = $.state(false);
|
|
74
77
|
let hoveredIndex = $.state(void 0);
|
|
75
78
|
let pasteInvalid = $.state(false);
|
|
79
|
+
let incompleteInvalid = $.state(false);
|
|
76
80
|
let errorTimer;
|
|
77
|
-
const resolvedInvalid = $.derived(() => invalid() || $.get(pasteInvalid));
|
|
81
|
+
const resolvedInvalid = $.derived(() => invalid() || $.get(pasteInvalid) || $.get(incompleteInvalid));
|
|
78
82
|
const errorContent = $.derived(() => $$props.error ?? locale.t("otpInput.invalidCode", { length: length() }));
|
|
79
83
|
|
|
80
84
|
onDestroy(() => {
|
|
@@ -89,10 +93,13 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
89
93
|
const splitProps = $.derived(() => splitFrameHostProps(rest));
|
|
90
94
|
const frameRestProps = $.derived(() => $.get(splitProps).frameProps);
|
|
91
95
|
const inputRestProps = $.derived(() => $.get(splitProps).hostProps);
|
|
92
|
-
|
|
96
|
+
|
|
97
|
+
// 空格仅表示尚未填写的格子;尾部空格不进入外部值。
|
|
98
|
+
const normalize = (raw) => String(raw ?? "").replace(/[^0-9 ]/g, "").slice(0, length()).replace(/ +$/, "");
|
|
99
|
+
|
|
93
100
|
const currentValue = $.derived(() => normalize(value() === undefined ? $$props.defaultValue : value()));
|
|
94
|
-
const digits = $.derived(() => Array.from({ length: length() }, (_, index) => $.get(currentValue)[index] ?? ""));
|
|
95
|
-
const activeIndex = $.derived(() => Math.min($.get(selectionIndex),
|
|
101
|
+
const digits = $.derived(() => Array.from({ length: length() }, (_, index) => $.get(currentValue)[index] === " " ? "" : $.get(currentValue)[index] ?? ""));
|
|
102
|
+
const activeIndex = $.derived(() => Math.min($.get(selectionIndex), length() - 1));
|
|
96
103
|
const groupLabel = $.derived(() => $.get(inputRestProps)["aria-label"]);
|
|
97
104
|
const groupLabelledby = $.derived(() => $.get(inputRestProps)["aria-labelledby"]);
|
|
98
105
|
|
|
@@ -118,6 +125,19 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
118
125
|
if (normalized.length < length()) lastUserCompletion = "";
|
|
119
126
|
});
|
|
120
127
|
|
|
128
|
+
$.user_effect(() => {
|
|
129
|
+
if (!success()) return;
|
|
130
|
+
|
|
131
|
+
const timer = setTimeout(
|
|
132
|
+
() => {
|
|
133
|
+
success(false);
|
|
134
|
+
},
|
|
135
|
+
2000
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
return () => clearTimeout(timer);
|
|
139
|
+
});
|
|
140
|
+
|
|
121
141
|
function formReset(node, formId) {
|
|
122
142
|
let active = true;
|
|
123
143
|
|
|
@@ -140,6 +160,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
140
160
|
|
|
141
161
|
if (!event.defaultPrevented) {
|
|
142
162
|
lastUserCompletion = "";
|
|
163
|
+
$.set(incompleteInvalid, false);
|
|
143
164
|
clearPasteError();
|
|
144
165
|
}
|
|
145
166
|
},
|
|
@@ -164,14 +185,16 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
164
185
|
};
|
|
165
186
|
}
|
|
166
187
|
|
|
167
|
-
function commitFromUser(raw) {
|
|
188
|
+
function commitFromUser(raw, filledLast = false) {
|
|
168
189
|
const next = normalize(raw);
|
|
169
190
|
const previous = $.get(currentValue);
|
|
170
191
|
|
|
171
192
|
value(next);
|
|
172
193
|
$.set(selectionIndex, $.get(inputElement)?.selectionStart ?? next.length, true);
|
|
173
194
|
|
|
174
|
-
if (next.length
|
|
195
|
+
if (next.length < length() || !next.includes(" ")) $.set(incompleteInvalid, false); else if (filledLast) $.set(incompleteInvalid, true);
|
|
196
|
+
|
|
197
|
+
if ((/^[0-9]+$/).test(next) && next.length === length() && next !== previous && next !== lastUserCompletion) {
|
|
175
198
|
lastUserCompletion = next;
|
|
176
199
|
$$props.oncomplete?.(next);
|
|
177
200
|
}
|
|
@@ -200,9 +223,12 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
200
223
|
}
|
|
201
224
|
|
|
202
225
|
function moveCaret(index, select = false) {
|
|
203
|
-
const at = Math.max(0, Math.min(index,
|
|
226
|
+
const at = Math.max(0, Math.min(index, length() - 1));
|
|
204
227
|
|
|
205
228
|
$.set(selectionIndex, at, true);
|
|
229
|
+
|
|
230
|
+
if ($.get(inputElement) && $.get(inputElement).value.length < at) $.get(inputElement).value = $.get(inputElement).value.padEnd(at, " ");
|
|
231
|
+
|
|
206
232
|
$.get(inputElement)?.setSelectionRange(at, select && at < $.get(currentValue).length ? at + 1 : at);
|
|
207
233
|
}
|
|
208
234
|
|
|
@@ -215,18 +241,44 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
215
241
|
return;
|
|
216
242
|
}
|
|
217
243
|
|
|
244
|
+
// 浏览器自动填充或整段替换包含非数字字符时按原有规则过滤;
|
|
245
|
+
// 仅数字和空格组成的值才保留逐格编辑产生的空位。
|
|
246
|
+
if ((/[^0-9 ]/).test(target.value)) target.value = target.value.replace(/\D/g, "");
|
|
247
|
+
|
|
218
248
|
const caret = normalize(target.value.slice(0, target.selectionStart ?? target.value.length)).length;
|
|
249
|
+
const filledLast = event.inputType?.startsWith("insert") === true && (target.selectionStart ?? 0) >= length();
|
|
219
250
|
|
|
220
|
-
commitFromUser(target.value);
|
|
251
|
+
commitFromUser(target.value, filledLast);
|
|
221
252
|
target.value = normalize(target.value);
|
|
222
253
|
|
|
223
254
|
// Use the accepted digit count, not the raw text length, so filtering cannot skip a slot.
|
|
224
255
|
target.setSelectionRange(caret, caret);
|
|
225
256
|
|
|
226
|
-
$.set(selectionIndex, Math.min(caret,
|
|
257
|
+
$.set(selectionIndex, Math.min(caret, length() - 1), true);
|
|
227
258
|
$$props.oninput?.(event);
|
|
228
259
|
}
|
|
229
260
|
|
|
261
|
+
function handleBeforeInput(event) {
|
|
262
|
+
if (disabled() || readonly() || !event.inputType.startsWith("delete")) return;
|
|
263
|
+
|
|
264
|
+
const target = event.currentTarget;
|
|
265
|
+
let start = target.selectionStart ?? $.get(selectionIndex);
|
|
266
|
+
let end = target.selectionEnd ?? start;
|
|
267
|
+
|
|
268
|
+
if (start === end) {
|
|
269
|
+
if (event.inputType === "deleteContentBackward") start = Math.max(0, start - 1); else if (event.inputType === "deleteContentForward") end = Math.min(length(), end + 1); else return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
|
|
274
|
+
const padded = $.get(currentValue).padEnd(length(), " ");
|
|
275
|
+
|
|
276
|
+
target.value = normalize(padded.slice(0, start) + (" ").repeat(end - start) + padded.slice(end));
|
|
277
|
+
target.setSelectionRange(Math.min(start, target.value.length), Math.min(start, target.value.length));
|
|
278
|
+
target.dispatchEvent(new Event("input", { bubbles: true }));
|
|
279
|
+
moveCaret(start);
|
|
280
|
+
}
|
|
281
|
+
|
|
230
282
|
function handlePaste(event) {
|
|
231
283
|
$$props.onpaste?.(event);
|
|
232
284
|
|
|
@@ -235,7 +287,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
235
287
|
event.preventDefault();
|
|
236
288
|
|
|
237
289
|
const pasted = event.clipboardData?.getData("text") ?? "";
|
|
238
|
-
const at = Math.min($.get(selectionIndex),
|
|
290
|
+
const at = Math.min($.get(selectionIndex), length() - 1);
|
|
239
291
|
|
|
240
292
|
if (!(/^[0-9]+$/).test(pasted)) {
|
|
241
293
|
rejectPaste(false);
|
|
@@ -249,7 +301,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
249
301
|
if (pasted.length === length()) {
|
|
250
302
|
next = pasted;
|
|
251
303
|
caret = length();
|
|
252
|
-
} else if (at > 0 && pasted.length <= length() - at) {
|
|
304
|
+
} else if (at > 0 && pasted.length <= length() - at && (/^[0-9]+$/).test($.get(currentValue).slice(0, at)) && $.get(currentValue).slice(0, at).length === at) {
|
|
253
305
|
// Interior paste may complete or partially fill the remaining contiguous suffix.
|
|
254
306
|
next = $.get(currentValue).slice(0, at) + pasted + $.get(currentValue).slice(at + pasted.length);
|
|
255
307
|
|
|
@@ -296,12 +348,9 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
296
348
|
function syncSelection() {
|
|
297
349
|
if (!$.get(inputElement)) return;
|
|
298
350
|
|
|
299
|
-
const index = Math.min($.get(inputElement).selectionStart ?? $.get(currentValue).length,
|
|
351
|
+
const index = Math.min($.get(inputElement).selectionStart ?? $.get(currentValue).length, length() - 1);
|
|
300
352
|
|
|
301
353
|
$.set(selectionIndex, index, true);
|
|
302
|
-
|
|
303
|
-
// A contiguous prefix is the only editable code; never activate a later empty slot.
|
|
304
|
-
if (($.get(inputElement).selectionStart ?? 0) > $.get(currentValue).length) moveCaret(index);
|
|
305
354
|
}
|
|
306
355
|
|
|
307
356
|
{
|
|
@@ -311,6 +360,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
311
360
|
let $3 = $.derived(() => readonly() ? "true" : undefined);
|
|
312
361
|
let $4 = $.derived(() => $.get(resolvedInvalid) ? "true" : undefined);
|
|
313
362
|
let $5 = $.derived(() => $.get(focused) ? "true" : undefined);
|
|
363
|
+
let $6 = $.derived(() => success() ? "true" : undefined);
|
|
314
364
|
|
|
315
365
|
Frame($$anchor, $.spread_props(() => $.get(frameRestProps), {
|
|
316
366
|
tag: 'div',
|
|
@@ -337,6 +387,10 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
337
387
|
get 'data-focus'() {
|
|
338
388
|
return $.get($5);
|
|
339
389
|
},
|
|
390
|
+
|
|
391
|
+
get 'data-success'() {
|
|
392
|
+
return $.get($6);
|
|
393
|
+
},
|
|
340
394
|
role: 'group',
|
|
341
395
|
get 'aria-label'() {
|
|
342
396
|
return $.get(groupLabel);
|
|
@@ -355,7 +409,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
355
409
|
},
|
|
356
410
|
enableScaleObserver: false,
|
|
357
411
|
children: ($$anchor, $$slotProps) => {
|
|
358
|
-
var fragment_1 =
|
|
412
|
+
var fragment_1 = root_3();
|
|
359
413
|
var span = $.first_child(fragment_1);
|
|
360
414
|
var input = $.child(span);
|
|
361
415
|
|
|
@@ -408,6 +462,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
408
462
|
minlength: length(),
|
|
409
463
|
'aria-invalid': $.get(resolvedInvalid) || undefined,
|
|
410
464
|
oninput: handleInput,
|
|
465
|
+
onbeforeinput: handleBeforeInput,
|
|
411
466
|
onchange: $$props.onchange,
|
|
412
467
|
onfocus: event_handler,
|
|
413
468
|
onblur: event_handler_1,
|
|
@@ -426,7 +481,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
426
481
|
],
|
|
427
482
|
void 0,
|
|
428
483
|
void 0,
|
|
429
|
-
|
|
484
|
+
'svelte-qr73h1',
|
|
430
485
|
true
|
|
431
486
|
);
|
|
432
487
|
|
|
@@ -436,7 +491,7 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
436
491
|
var node_1 = $.sibling(input, 2);
|
|
437
492
|
|
|
438
493
|
$.each(node_1, 17, () => $.get(digits), $.index, ($$anchor, digit, index) => {
|
|
439
|
-
var span_1 =
|
|
494
|
+
var span_1 = root_2();
|
|
440
495
|
var node_2 = $.child(span_1);
|
|
441
496
|
|
|
442
497
|
{
|
|
@@ -445,27 +500,12 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
445
500
|
var node_3 = $.first_child(fragment_2);
|
|
446
501
|
|
|
447
502
|
$.key(node_3, () => $.get(digit), ($$anchor) => {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
enableScaleObserver: false,
|
|
455
|
-
get whileAppear() {
|
|
456
|
-
return NUMBER_POP_APPEAR_MOTION;
|
|
457
|
-
},
|
|
458
|
-
|
|
459
|
-
children: ($$anchor, $$slotProps) => {
|
|
460
|
-
$.next();
|
|
461
|
-
|
|
462
|
-
var text = $.text();
|
|
463
|
-
|
|
464
|
-
$.template_effect(() => $.set_text(text, $.get(digit)));
|
|
465
|
-
$.append($$anchor, text);
|
|
466
|
-
},
|
|
467
|
-
$$slots: { default: true }
|
|
468
|
-
});
|
|
503
|
+
var span_2 = root();
|
|
504
|
+
var text = $.child(span_2, true);
|
|
505
|
+
|
|
506
|
+
$.reset(span_2);
|
|
507
|
+
$.template_effect(() => $.set_text(text, $.get(digit)));
|
|
508
|
+
$.append($$anchor, span_2);
|
|
469
509
|
});
|
|
470
510
|
|
|
471
511
|
$.append($$anchor, fragment_2);
|
|
@@ -476,11 +516,25 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
476
516
|
});
|
|
477
517
|
}
|
|
478
518
|
|
|
519
|
+
var node_4 = $.sibling(node_2, 2);
|
|
520
|
+
|
|
521
|
+
{
|
|
522
|
+
var consequent_1 = ($$anchor) => {
|
|
523
|
+
var span_3 = root_1();
|
|
524
|
+
|
|
525
|
+
$.append($$anchor, span_3);
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
$.if(node_4, ($$render) => {
|
|
529
|
+
if ($.get(focused) && index === $.get(activeIndex) && !disabled() && !readonly() && !success()) $$render(consequent_1);
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
479
533
|
$.reset(span_1);
|
|
480
534
|
|
|
481
535
|
$.template_effect(() => {
|
|
482
|
-
$.set_attribute(span_1, 'data-active', $.get(focused) && index === $.get(activeIndex) || undefined);
|
|
483
|
-
$.set_attribute(span_1, 'data-field-hover', $.get(hoveredIndex) === index && !disabled() ? "true" : undefined);
|
|
536
|
+
$.set_attribute(span_1, 'data-active', $.get(focused) && !success() && index === $.get(activeIndex) || undefined);
|
|
537
|
+
$.set_attribute(span_1, 'data-field-hover', $.get(hoveredIndex) === index && !disabled() && !success() ? "true" : undefined);
|
|
484
538
|
$.set_attribute(span_1, 'data-invalid', $.get(resolvedInvalid) ? "true" : undefined);
|
|
485
539
|
$.set_attribute(span_1, 'data-filled', !!$.get(digit) || undefined);
|
|
486
540
|
});
|
|
@@ -488,14 +542,14 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
488
542
|
$.append($$anchor, span_1);
|
|
489
543
|
});
|
|
490
544
|
|
|
491
|
-
var
|
|
545
|
+
var span_4 = $.sibling(node_1, 2);
|
|
492
546
|
|
|
493
547
|
$.reset(span);
|
|
494
548
|
|
|
495
|
-
var
|
|
549
|
+
var node_5 = $.sibling(span, 2);
|
|
496
550
|
|
|
497
551
|
{
|
|
498
|
-
var
|
|
552
|
+
var consequent_3 = ($$anchor) => {
|
|
499
553
|
Text($$anchor, {
|
|
500
554
|
get id() {
|
|
501
555
|
return errorId;
|
|
@@ -505,16 +559,16 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
505
559
|
'aria-live': 'polite',
|
|
506
560
|
class: 'snowui-field-error-message',
|
|
507
561
|
children: ($$anchor, $$slotProps) => {
|
|
508
|
-
var
|
|
509
|
-
var
|
|
562
|
+
var fragment_4 = $.comment();
|
|
563
|
+
var node_6 = $.first_child(fragment_4);
|
|
510
564
|
|
|
511
565
|
{
|
|
512
|
-
var
|
|
513
|
-
var
|
|
514
|
-
var
|
|
566
|
+
var consequent_2 = ($$anchor) => {
|
|
567
|
+
var fragment_5 = $.comment();
|
|
568
|
+
var node_7 = $.first_child(fragment_5);
|
|
515
569
|
|
|
516
|
-
$.snippet(
|
|
517
|
-
$.append($$anchor,
|
|
570
|
+
$.snippet(node_7, () => $.get(errorContent));
|
|
571
|
+
$.append($$anchor, fragment_5);
|
|
518
572
|
};
|
|
519
573
|
|
|
520
574
|
var alternate = ($$anchor) => {
|
|
@@ -524,26 +578,26 @@ export default function OTPInput($$anchor, $$props) {
|
|
|
524
578
|
$.append($$anchor, text_1);
|
|
525
579
|
};
|
|
526
580
|
|
|
527
|
-
$.if(
|
|
528
|
-
if (typeof $.get(errorContent) === "function") $$render(
|
|
581
|
+
$.if(node_6, ($$render) => {
|
|
582
|
+
if (typeof $.get(errorContent) === "function") $$render(consequent_2); else $$render(alternate, -1);
|
|
529
583
|
});
|
|
530
584
|
}
|
|
531
585
|
|
|
532
|
-
$.append($$anchor,
|
|
586
|
+
$.append($$anchor, fragment_4);
|
|
533
587
|
},
|
|
534
588
|
$$slots: { default: true }
|
|
535
589
|
});
|
|
536
590
|
};
|
|
537
591
|
|
|
538
|
-
$.if(
|
|
539
|
-
if ($.get(resolvedInvalid)) $$render(
|
|
592
|
+
$.if(node_5, ($$render) => {
|
|
593
|
+
if ($.get(resolvedInvalid)) $$render(consequent_3);
|
|
540
594
|
});
|
|
541
595
|
}
|
|
542
596
|
|
|
543
597
|
$.template_effect(() => {
|
|
544
|
-
$.set_attribute(
|
|
545
|
-
$.set_attribute(
|
|
546
|
-
$.set_style(
|
|
598
|
+
$.set_attribute(span_4, 'data-field-focus', $.get(focused) && !disabled() && !success() ? "true" : undefined);
|
|
599
|
+
$.set_attribute(span_4, 'data-invalid', $.get(resolvedInvalid) ? "true" : undefined);
|
|
600
|
+
$.set_style(span_4, `${TAB_INDICATOR_MOTION_STYLE}; --snowui-otp-input-active-index: ${$.get(activeIndex)}`);
|
|
547
601
|
});
|
|
548
602
|
|
|
549
603
|
$.append($$anchor, fragment_1);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type PasswordStrengthLevel = 0 | 1 | 2 | 3 | 4;
|
|
2
|
+
export type PasswordStrengthEvaluator = (password: string) => PasswordStrengthLevel;
|
|
3
|
+
/** 参考 shadcn/ui 的规则计数;仅为提示,不是密码安全保证。 */
|
|
4
|
+
export declare function evaluatePasswordStrength(password: string, minimumLength?: number): PasswordStrengthLevel;
|
|
5
|
+
import { type FrameProps } from './Frame.js';
|
|
6
|
+
interface Props extends Omit<FrameProps, 'children' | 'column' | 'row' | 'gap' | 'enableAutoLayout'> {
|
|
7
|
+
password?: string;
|
|
8
|
+
evaluate?: PasswordStrengthEvaluator;
|
|
9
|
+
labels?: readonly [string, string, string, string, string];
|
|
10
|
+
minimumLength?: number;
|
|
11
|
+
minimumLengthMessage?: (length: number) => string;
|
|
12
|
+
requireLowercase?: boolean;
|
|
13
|
+
requireUppercase?: boolean;
|
|
14
|
+
requireNumber?: boolean;
|
|
15
|
+
requireSymbol?: boolean;
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
declare const PasswordStrength: import("svelte").Component<Props, {}, "">;
|
|
19
|
+
type PasswordStrength = ReturnType<typeof PasswordStrength>;
|
|
20
|
+
export default PasswordStrength;
|