@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.
Files changed (59) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.md +5 -3
  3. package/THIRD_PARTY_NOTICES.md +85 -0
  4. package/component-catalog.json +65 -0
  5. package/dist/client/components/Accordion.js +1 -1
  6. package/dist/client/components/AccordionItem.js +1 -1
  7. package/dist/client/components/Avatar.js +122 -63
  8. package/dist/client/components/Button.js +1 -1
  9. package/dist/client/components/Card.js +10 -0
  10. package/dist/client/components/CodeBlock.js +38 -10
  11. package/dist/client/components/Dialog.js +3 -13
  12. package/dist/client/components/Icon.js +92 -24
  13. package/dist/client/components/Image.js +21 -10
  14. package/dist/client/components/Indicator.js +77 -6
  15. package/dist/client/components/Input.js +192 -94
  16. package/dist/client/components/MetricCard.d.ts +13 -0
  17. package/dist/client/components/MetricCard.js +179 -0
  18. package/dist/client/components/OTPInput.d.ts +2 -1
  19. package/dist/client/components/OTPInput.js +117 -63
  20. package/dist/client/components/PasswordStrength.d.ts +20 -0
  21. package/dist/client/components/PasswordStrength.js +145 -0
  22. package/dist/client/components/SnowUILogo.d.ts +1 -0
  23. package/dist/client/components/SnowUILogo.js +11 -7
  24. package/dist/client/components/StyleButton.js +2 -0
  25. package/dist/client/i18n/messages.d.ts +1 -1
  26. package/dist/client/i18n/messages.js +16 -0
  27. package/dist/client/index.d.ts +2 -0
  28. package/dist/client/index.js +2 -0
  29. package/dist/client/internal/component-icon/builtin-icon-data.js +14 -0
  30. package/dist/client/styles/components.css +5 -1
  31. package/dist/client/styles/scale.css +16 -16
  32. package/dist/server/components/Accordion.js +1 -1
  33. package/dist/server/components/AccordionItem.js +1 -1
  34. package/dist/server/components/Avatar.js +42 -7
  35. package/dist/server/components/Button.js +1 -1
  36. package/dist/server/components/Card.js +2 -0
  37. package/dist/server/components/CodeBlock.js +29 -6
  38. package/dist/server/components/Dialog.js +3 -10
  39. package/dist/server/components/Icon.js +37 -2
  40. package/dist/server/components/Image.js +3 -1
  41. package/dist/server/components/Indicator.js +6 -3
  42. package/dist/server/components/Input.js +63 -5
  43. package/dist/server/components/MetricCard.d.ts +13 -0
  44. package/dist/server/components/MetricCard.js +104 -0
  45. package/dist/server/components/OTPInput.d.ts +2 -1
  46. package/dist/server/components/OTPInput.js +66 -35
  47. package/dist/server/components/PasswordStrength.d.ts +20 -0
  48. package/dist/server/components/PasswordStrength.js +105 -0
  49. package/dist/server/components/SnowUILogo.d.ts +1 -0
  50. package/dist/server/components/SnowUILogo.js +5 -3
  51. package/dist/server/components/StyleButton.js +2 -0
  52. package/dist/server/i18n/messages.d.ts +1 -1
  53. package/dist/server/i18n/messages.js +16 -0
  54. package/dist/server/index.d.ts +2 -0
  55. package/dist/server/index.js +2 -0
  56. package/dist/server/internal/component-icon/builtin-icon-data.js +14 -0
  57. package/dist/server/styles/components.css +5 -1
  58. package/dist/server/styles/scale.css +16 -16
  59. package/package.json +3 -2
@@ -0,0 +1,104 @@
1
+ import * as $ from 'svelte/internal/server';
2
+ import Card from './Card.js';
3
+ import Text from './Text.js';
4
+
5
+ const $$css = {
6
+ hash: 'svelte-1iu5zja',
7
+ 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);}'
8
+ };
9
+
10
+ export default function MetricCard($$renderer, $$props) {
11
+ $$renderer.global.css.add($$css);
12
+
13
+ $$renderer.component(($$renderer) => {
14
+ let {
15
+ label,
16
+ value,
17
+ change = undefined,
18
+ emphasis = 'change',
19
+ trend = 'neutral',
20
+ class: userClass = '',
21
+ $$slots,
22
+ $$events,
23
+ ...rest
24
+ } = $$props;
25
+
26
+ let sign = $.derived(() => change && (/^[+−-]/).test(change) ? change[0] : '');
27
+ let changeText = $.derived(() => sign() ? change?.slice(1) : change);
28
+
29
+ Card($$renderer, $.spread_props([
30
+ rest,
31
+ {
32
+ class: `snowui-metric-card ${userClass}`,
33
+ contentFill: true,
34
+ scrollable: false,
35
+ children: ($$renderer) => {
36
+ Text($$renderer, {
37
+ class: 'snowui-metric-label',
38
+ children: ($$renderer) => {
39
+ $$renderer.push(`<!---->${$.escape(label)}`);
40
+ },
41
+ $$slots: { default: true }
42
+ });
43
+
44
+ $$renderer.push(`<!----> <div class="snowui-metric-values">`);
45
+
46
+ if (emphasis === 'change' && change !== undefined) {
47
+ $$renderer.push('<!--[0-->');
48
+
49
+ Text($$renderer, {
50
+ class: 'snowui-metric-primary',
51
+ children: ($$renderer) => {
52
+ $$renderer.push(`<span${$.attr_class(`snowui-metric-sign snowui-metric-${trend}`)}>${$.escape(sign())}</span>${$.escape(changeText())}`);
53
+ },
54
+ $$slots: { default: true }
55
+ });
56
+
57
+ $$renderer.push(`<!----> `);
58
+
59
+ Text($$renderer, {
60
+ class: 'snowui-metric-secondary',
61
+ children: ($$renderer) => {
62
+ $$renderer.push(`<!---->${$.escape(value)}`);
63
+ },
64
+ $$slots: { default: true }
65
+ });
66
+
67
+ $$renderer.push(`<!---->`);
68
+ } else {
69
+ $$renderer.push('<!--[-1-->');
70
+
71
+ Text($$renderer, {
72
+ class: 'snowui-metric-primary',
73
+ children: ($$renderer) => {
74
+ $$renderer.push(`<!---->${$.escape(value)}`);
75
+ },
76
+ $$slots: { default: true }
77
+ });
78
+
79
+ $$renderer.push(`<!----> `);
80
+
81
+ if (change !== undefined) {
82
+ $$renderer.push('<!--[0-->');
83
+
84
+ Text($$renderer, {
85
+ class: 'snowui-metric-secondary',
86
+ children: ($$renderer) => {
87
+ $$renderer.push(`<span${$.attr_class(`snowui-metric-sign snowui-metric-${trend}`)}>${$.escape(sign())}</span>${$.escape(changeText())}`);
88
+ },
89
+ $$slots: { default: true }
90
+ });
91
+ } else {
92
+ $$renderer.push('<!--[-1-->');
93
+ }
94
+
95
+ $$renderer.push(`<!--]-->`);
96
+ }
97
+
98
+ $$renderer.push(`<!--]--></div>`);
99
+ },
100
+ $$slots: { default: true }
101
+ }
102
+ ]));
103
+ });
104
+ }
@@ -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;
@@ -2,14 +2,13 @@ import * as $ from 'svelte/internal/server';
2
2
  import { onDestroy } from "svelte";
3
3
  import Text from "./Text.js";
4
4
  import { useLocale } from "../i18n/locale.js";
5
- import { NUMBER_POP_APPEAR_MOTION } from "../motion/presets/effects.js";
6
5
  import { TAB_INDICATOR_MOTION_STYLE } from "../motion/presets/tab.js";
7
6
  import Frame from "./Frame.js";
8
7
  import { splitFrameHostProps } from "../logic/frame-prop-filter.js";
9
8
 
10
9
  const $$css = {
11
10
  hash: 'svelte-qr73h1',
12
- code: ':where(.snowui-otp-input) {--snowui-otp-input-gap: var(--gap-2);--snowui-otp-input-size: var(--size-10);--snowui-otp-input-radius: var(--radius-4);--snowui-otp-input-font-size: var(--text-16);--snowui-otp-input-line-height: var(--leading-14);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;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-16)));line-height:var(--snowui-otp-input-line-height-override, var(--snowui-otp-input-line-height, var(--leading-14)));font-variant-numeric:tabular-nums;}:where(.snowui-otp-slot) {background:var(--surface-1, #ffffffcc);}.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;}:where(.snowui-otp-input[data-disabled="true"]) {cursor:not-allowed;opacity:0.4;}: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;}.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;}\n }'
11
+ 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 }'
13
12
  };
14
13
 
15
14
  export default function OTPInput($$renderer, $$props) {
@@ -33,6 +32,7 @@ export default function OTPInput($$renderer, $$props) {
33
32
  id,
34
33
  title,
35
34
  invalid = false,
35
+ success = false,
36
36
  error,
37
37
  enableResponsive = true,
38
38
  enableContext = true,
@@ -56,8 +56,9 @@ export default function OTPInput($$renderer, $$props) {
56
56
  let focused = false;
57
57
  let hoveredIndex = void 0;
58
58
  let pasteInvalid = false;
59
+ let incompleteInvalid = false;
59
60
  let errorTimer;
60
- const resolvedInvalid = $.derived(() => invalid || pasteInvalid);
61
+ const resolvedInvalid = $.derived(() => invalid || pasteInvalid || incompleteInvalid);
61
62
  const errorContent = $.derived(() => error ?? locale.t("otpInput.invalidCode", { length }));
62
63
 
63
64
  onDestroy(() => {
@@ -72,10 +73,13 @@ export default function OTPInput($$renderer, $$props) {
72
73
  const splitProps = $.derived(() => splitFrameHostProps(rest));
73
74
  const frameRestProps = $.derived(() => splitProps().frameProps);
74
75
  const inputRestProps = $.derived(() => splitProps().hostProps);
75
- const normalize = (raw) => String(raw ?? "").replace(/\D/g, "").slice(0, length);
76
+
77
+ // 空格仅表示尚未填写的格子;尾部空格不进入外部值。
78
+ const normalize = (raw) => String(raw ?? "").replace(/[^0-9 ]/g, "").slice(0, length).replace(/ +$/, "");
79
+
76
80
  const currentValue = $.derived(() => normalize(value === undefined ? defaultValue : value));
77
- const digits = $.derived(() => Array.from({ length }, (_, index) => currentValue()[index] ?? ""));
78
- const activeIndex = $.derived(() => Math.min(selectionIndex, currentValue().length, length - 1));
81
+ const digits = $.derived(() => Array.from({ length }, (_, index) => currentValue()[index] === " " ? "" : currentValue()[index] ?? ""));
82
+ const activeIndex = $.derived(() => Math.min(selectionIndex, length - 1));
79
83
  const groupLabel = $.derived(() => inputRestProps()["aria-label"]);
80
84
  const groupLabelledby = $.derived(() => inputRestProps()["aria-labelledby"]);
81
85
 
@@ -111,6 +115,7 @@ export default function OTPInput($$renderer, $$props) {
111
115
 
112
116
  if (!event.defaultPrevented) {
113
117
  lastUserCompletion = "";
118
+ incompleteInvalid = false;
114
119
  clearPasteError();
115
120
  }
116
121
  },
@@ -135,14 +140,16 @@ export default function OTPInput($$renderer, $$props) {
135
140
  };
136
141
  }
137
142
 
138
- function commitFromUser(raw) {
143
+ function commitFromUser(raw, filledLast = false) {
139
144
  const next = normalize(raw);
140
145
  const previous = currentValue();
141
146
 
142
147
  value = next;
143
148
  selectionIndex = inputElement?.selectionStart ?? next.length;
144
149
 
145
- if (next.length === length && next !== previous && next !== lastUserCompletion) {
150
+ if (next.length < length || !next.includes(" ")) incompleteInvalid = false; else if (filledLast) incompleteInvalid = true;
151
+
152
+ if ((/^[0-9]+$/).test(next) && next.length === length && next !== previous && next !== lastUserCompletion) {
146
153
  lastUserCompletion = next;
147
154
  oncomplete?.(next);
148
155
  }
@@ -171,9 +178,12 @@ export default function OTPInput($$renderer, $$props) {
171
178
  }
172
179
 
173
180
  function moveCaret(index, select = false) {
174
- const at = Math.max(0, Math.min(index, currentValue().length, length - 1));
181
+ const at = Math.max(0, Math.min(index, length - 1));
175
182
 
176
183
  selectionIndex = at;
184
+
185
+ if (inputElement && inputElement.value.length < at) inputElement.value = inputElement.value.padEnd(at, " ");
186
+
177
187
  inputElement?.setSelectionRange(at, select && at < currentValue().length ? at + 1 : at);
178
188
  }
179
189
 
@@ -186,18 +196,44 @@ export default function OTPInput($$renderer, $$props) {
186
196
  return;
187
197
  }
188
198
 
199
+ // 浏览器自动填充或整段替换包含非数字字符时按原有规则过滤;
200
+ // 仅数字和空格组成的值才保留逐格编辑产生的空位。
201
+ if ((/[^0-9 ]/).test(target.value)) target.value = target.value.replace(/\D/g, "");
202
+
189
203
  const caret = normalize(target.value.slice(0, target.selectionStart ?? target.value.length)).length;
204
+ const filledLast = event.inputType?.startsWith("insert") === true && (target.selectionStart ?? 0) >= length;
190
205
 
191
- commitFromUser(target.value);
206
+ commitFromUser(target.value, filledLast);
192
207
  target.value = normalize(target.value);
193
208
 
194
209
  // Use the accepted digit count, not the raw text length, so filtering cannot skip a slot.
195
210
  target.setSelectionRange(caret, caret);
196
211
 
197
- selectionIndex = Math.min(caret, target.value.length, length - 1);
212
+ selectionIndex = Math.min(caret, length - 1);
198
213
  oninput?.(event);
199
214
  }
200
215
 
216
+ function handleBeforeInput(event) {
217
+ if (disabled || readonly || !event.inputType.startsWith("delete")) return;
218
+
219
+ const target = event.currentTarget;
220
+ let start = target.selectionStart ?? selectionIndex;
221
+ let end = target.selectionEnd ?? start;
222
+
223
+ if (start === end) {
224
+ if (event.inputType === "deleteContentBackward") start = Math.max(0, start - 1); else if (event.inputType === "deleteContentForward") end = Math.min(length, end + 1); else return;
225
+ }
226
+
227
+ event.preventDefault();
228
+
229
+ const padded = currentValue().padEnd(length, " ");
230
+
231
+ target.value = normalize(padded.slice(0, start) + (" ").repeat(end - start) + padded.slice(end));
232
+ target.setSelectionRange(Math.min(start, target.value.length), Math.min(start, target.value.length));
233
+ target.dispatchEvent(new Event("input", { bubbles: true }));
234
+ moveCaret(start);
235
+ }
236
+
201
237
  function handlePaste(event) {
202
238
  onpaste?.(event);
203
239
 
@@ -206,7 +242,7 @@ export default function OTPInput($$renderer, $$props) {
206
242
  event.preventDefault();
207
243
 
208
244
  const pasted = event.clipboardData?.getData("text") ?? "";
209
- const at = Math.min(selectionIndex, currentValue().length, length - 1);
245
+ const at = Math.min(selectionIndex, length - 1);
210
246
 
211
247
  if (!(/^[0-9]+$/).test(pasted)) {
212
248
  rejectPaste(false);
@@ -220,7 +256,7 @@ export default function OTPInput($$renderer, $$props) {
220
256
  if (pasted.length === length) {
221
257
  next = pasted;
222
258
  caret = length;
223
- } else if (at > 0 && pasted.length <= length - at) {
259
+ } else if (at > 0 && pasted.length <= length - at && (/^[0-9]+$/).test(currentValue().slice(0, at)) && currentValue().slice(0, at).length === at) {
224
260
  // Interior paste may complete or partially fill the remaining contiguous suffix.
225
261
  next = currentValue().slice(0, at) + pasted + currentValue().slice(at + pasted.length);
226
262
 
@@ -267,12 +303,9 @@ export default function OTPInput($$renderer, $$props) {
267
303
  function syncSelection() {
268
304
  if (!inputElement) return;
269
305
 
270
- const index = Math.min(inputElement.selectionStart ?? currentValue().length, currentValue().length, length - 1);
306
+ const index = Math.min(inputElement.selectionStart ?? currentValue().length, length - 1);
271
307
 
272
308
  selectionIndex = index;
273
-
274
- // A contiguous prefix is the only editable code; never activate a later empty slot.
275
- if ((inputElement.selectionStart ?? 0) > currentValue().length) moveCaret(index);
276
309
  }
277
310
 
278
311
  Frame($$renderer, $.spread_props([
@@ -285,6 +318,7 @@ export default function OTPInput($$renderer, $$props) {
285
318
  'data-readonly': readonly ? "true" : undefined,
286
319
  'data-invalid': resolvedInvalid() ? "true" : undefined,
287
320
  'data-focus': focused ? "true" : undefined,
321
+ 'data-success': success ? "true" : undefined,
288
322
  role: 'group',
289
323
  'aria-label': groupLabel(),
290
324
  'aria-labelledby': groupLabelledby(),
@@ -293,7 +327,7 @@ export default function OTPInput($$renderer, $$props) {
293
327
  enableContext,
294
328
  enableScaleObserver: false,
295
329
  children: ($$renderer) => {
296
- $$renderer.push(`<span class="snowui-otp-slots"><input${$.attributes(
330
+ $$renderer.push(`<span class="snowui-otp-slots svelte-qr73h1"><input${$.attributes(
297
331
  {
298
332
  ...nativeInputProps(),
299
333
  class: 'snowui-otp-native',
@@ -320,7 +354,7 @@ export default function OTPInput($$renderer, $$props) {
320
354
  minlength: length,
321
355
  'aria-invalid': resolvedInvalid() || undefined
322
356
  },
323
- void 0,
357
+ 'svelte-qr73h1',
324
358
  void 0,
325
359
  void 0,
326
360
  4
@@ -331,26 +365,14 @@ export default function OTPInput($$renderer, $$props) {
331
365
  for (let index = 0, $$length = each_array.length; index < $$length; index++) {
332
366
  let digit = each_array[index];
333
367
 
334
- $$renderer.push(`<span class="snowui-otp-slot snowui-field-bordered snowui-rounded-rectangle" aria-hidden="true"${$.attr('data-active', focused && index === activeIndex() || undefined)}${$.attr('data-field-hover', hoveredIndex === index && !disabled ? "true" : undefined)}${$.attr('data-invalid', resolvedInvalid() ? "true" : undefined)}${$.attr('data-filled', !!digit || undefined)}>`);
368
+ $$renderer.push(`<span class="snowui-otp-slot snowui-field-bordered snowui-rounded-rectangle svelte-qr73h1" aria-hidden="true"${$.attr('data-active', focused && !success && index === activeIndex() || undefined)}${$.attr('data-field-hover', hoveredIndex === index && !disabled && !success ? "true" : undefined)}${$.attr('data-invalid', resolvedInvalid() ? "true" : undefined)}${$.attr('data-filled', !!digit || undefined)}>`);
335
369
 
336
370
  if (digit) {
337
371
  $$renderer.push('<!--[0-->');
338
372
  $$renderer.push(`<!---->`);
339
373
 
340
374
  {
341
- Frame($$renderer, {
342
- tag: 'span',
343
- class: 'snowui-otp-digit',
344
- enableAutoLayout: false,
345
- enableContext: false,
346
- enableResponsive: false,
347
- enableScaleObserver: false,
348
- whileAppear: NUMBER_POP_APPEAR_MOTION,
349
- children: ($$renderer) => {
350
- $$renderer.push(`<!---->${$.escape(digit)}`);
351
- },
352
- $$slots: { default: true }
353
- });
375
+ $$renderer.push(`<span class="snowui-otp-digit svelte-qr73h1">${$.escape(digit)}</span>`);
354
376
  }
355
377
 
356
378
  $$renderer.push(`<!---->`);
@@ -358,10 +380,19 @@ export default function OTPInput($$renderer, $$props) {
358
380
  $$renderer.push('<!--[-1-->');
359
381
  }
360
382
 
383
+ $$renderer.push(`<!--]--> `);
384
+
385
+ if (focused && index === activeIndex() && !disabled && !readonly && !success) {
386
+ $$renderer.push('<!--[0-->');
387
+ $$renderer.push(`<span class="snowui-otp-caret svelte-qr73h1" aria-hidden="true"></span>`);
388
+ } else {
389
+ $$renderer.push('<!--[-1-->');
390
+ }
391
+
361
392
  $$renderer.push(`<!--]--></span>`);
362
393
  }
363
394
 
364
- $$renderer.push(`<!--]--> <span aria-hidden="true" class="snowui-otp-indicator snowui-field-bordered snowui-rounded-rectangle"${$.attr('data-field-focus', focused && !disabled ? "true" : undefined)}${$.attr('data-invalid', resolvedInvalid() ? "true" : undefined)}${$.attr_style(`${TAB_INDICATOR_MOTION_STYLE}; --snowui-otp-input-active-index: ${activeIndex()}`)}></span></span> `);
395
+ $$renderer.push(`<!--]--> <span aria-hidden="true" class="snowui-otp-indicator snowui-field-bordered snowui-rounded-rectangle svelte-qr73h1"${$.attr('data-field-focus', focused && !disabled && !success ? "true" : undefined)}${$.attr('data-invalid', resolvedInvalid() ? "true" : undefined)}${$.attr_style(`${TAB_INDICATOR_MOTION_STYLE}; --snowui-otp-input-active-index: ${activeIndex()}`)}></span></span> `);
365
396
 
366
397
  if (resolvedInvalid()) {
367
398
  $$renderer.push('<!--[0-->');
@@ -396,6 +427,6 @@ export default function OTPInput($$renderer, $$props) {
396
427
  }
397
428
  ]));
398
429
 
399
- $.bind_props($$props, { value });
430
+ $.bind_props($$props, { value, success });
400
431
  });
401
432
  }
@@ -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;
@@ -0,0 +1,105 @@
1
+ import * as $ from 'svelte/internal/server';
2
+ import Frame from './Frame.js';
3
+ import Text from './Text.js';
4
+ import { useLocale } from '../i18n/locale.js';
5
+
6
+ export function evaluatePasswordStrength(password, minimumLength = 8) {
7
+ if (!password) return 0;
8
+ if (password.length < minimumLength) return 1;
9
+
10
+ const rules = [/[a-z]/, /[A-Z]/, /[0-9]/, /[^a-zA-Z0-9]/].filter((pattern) => pattern.test(password)).length;
11
+
12
+ return Math.max(1, rules);
13
+ }
14
+
15
+ const $$css = {
16
+ hash: 'svelte-11vc0ks',
17
+ code: ':where(.snowui-password-strength) {--snowui-password-strength-segment-gap: var(--gap-2);--snowui-password-strength-segment-radius: var(--radius-full);padding-inline:var(--padding-1, 4px);box-sizing:border-box;}:where(.snowui-strength-track) {display:flex;gap:var(--snowui-password-strength-segment-gap-override, var(--snowui-password-strength-segment-gap, var(--gap-2)));width:100%;}:where(.snowui-strength-track span) {flex:1 1 0;min-width:0;height:var(--size-1, 4px);border-radius:var(--snowui-password-strength-segment-radius-override, var(--snowui-password-strength-segment-radius, var(--radius-full)));background:var(--black-10, #0000001A);}:where(.snowui-strength-track .snowui-strength-active.snowui-strength-level-1) {background:var(--secondary-red, #FF4747FF);}:where(.snowui-strength-track .snowui-strength-active.snowui-strength-level-2) {background:var(--secondary-orange, #FFB55BFF);}:where(.snowui-strength-track .snowui-strength-active.snowui-strength-level-strong) {background:var(--secondary-green, #71DD8CFF);}:where(.snowui-password-strength .snowui-strength-label) {color:var(--black-40, #00000066);font-size:var(--text-12, 12px);line-height:var(--leading-12, 16px);min-width:0;width:100%;white-space:normal;overflow-wrap:anywhere;}'
18
+ };
19
+
20
+ export default function PasswordStrength($$renderer, $$props) {
21
+ $$renderer.global.css.add($$css);
22
+
23
+ $$renderer.component(($$renderer) => {
24
+ let {
25
+ password = '',
26
+ evaluate,
27
+ labels = ['请输入密码', '弱', '一般', '较强', '完美'],
28
+ minimumLength = 8,
29
+ minimumLengthMessage,
30
+ requireLowercase = false,
31
+ requireUppercase = false,
32
+ requireNumber = false,
33
+ requireSymbol = false,
34
+ enableResponsive = true,
35
+ enableContext = true,
36
+ enableScaleObserver = false,
37
+ class: userClass = '',
38
+ $$slots,
39
+ $$events,
40
+ ...rest
41
+ } = $$props;
42
+
43
+ const locale = useLocale();
44
+
45
+ let level = $.derived(() => evaluate
46
+ ? evaluate(password)
47
+ : evaluatePasswordStrength(password, minimumLength));
48
+
49
+ let missingRequirements = $.derived(() => [
50
+ requireLowercase && !(/[a-z]/).test(password) ? locale.t('passwordStrength.lowercase') : '',
51
+ requireUppercase && !(/[A-Z]/).test(password) ? locale.t('passwordStrength.uppercase') : '',
52
+ requireNumber && !(/[0-9]/).test(password) ? locale.t('passwordStrength.number') : '',
53
+ requireSymbol && !(/[^\p{L}\p{N}\s]/u).test(password) ? locale.t('passwordStrength.symbol') : ''
54
+ ].filter(Boolean));
55
+
56
+ let message = $.derived(() => password.length < minimumLength
57
+ ? minimumLengthMessage?.(minimumLength) ?? locale.t('passwordStrength.minimumLength', { length: minimumLength })
58
+ : missingRequirements().length
59
+ ? locale.t('passwordStrength.requirements', { requirements: missingRequirements().join('、') })
60
+ : labels[level()]);
61
+
62
+ Frame($$renderer, $.spread_props([
63
+ rest,
64
+ {
65
+ row: false,
66
+ column: true,
67
+ gap: 2,
68
+ enableAutoLayout: false,
69
+ enableResponsive,
70
+ enableContext,
71
+ enableScaleObserver,
72
+ class: `snowui-password-strength ${userClass}`,
73
+ children: ($$renderer) => {
74
+ $$renderer.push(`<div class="snowui-strength-track" aria-hidden="true"><!--[-->`);
75
+
76
+ const each_array = $.ensure_array_like([1, 2, 3, 4]);
77
+
78
+ for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
79
+ let segment = each_array[$$index];
80
+
81
+ $$renderer.push(`<span${$.attr_class('', void 0, {
82
+ 'snowui-strength-active': segment <= level(),
83
+ 'snowui-strength-level-1': level() === 1,
84
+ 'snowui-strength-level-2': level() === 2,
85
+ 'snowui-strength-level-strong': level() >= 3
86
+ })}></span>`);
87
+ }
88
+
89
+ $$renderer.push(`<!--]--></div> `);
90
+
91
+ Text($$renderer, {
92
+ class: 'snowui-strength-label',
93
+ children: ($$renderer) => {
94
+ $$renderer.push(`<!---->${$.escape(message())}`);
95
+ },
96
+ $$slots: { default: true }
97
+ });
98
+
99
+ $$renderer.push(`<!---->`);
100
+ },
101
+ $$slots: { default: true }
102
+ }
103
+ ]));
104
+ });
105
+ }
@@ -5,6 +5,7 @@ interface Props extends Omit<FrameProps, "children" | "size" | "width" | "height
5
5
  scale?: number;
6
6
  compactProgress?: number;
7
7
  idleMotion?: boolean;
8
+ hoverMotion?: boolean;
8
9
  textMotion?: "greetings" | "variants";
9
10
  decorative?: boolean;
10
11
  [key: string]: any;
@@ -21,6 +21,7 @@ export default function SnowUILogo($$renderer, $$props) {
21
21
  scale = 1,
22
22
  compactProgress = 0,
23
23
  idleMotion = false,
24
+ hoverMotion = false,
24
25
  textMotion = "greetings",
25
26
  decorative = false,
26
27
  role = undefined,
@@ -177,6 +178,9 @@ export default function SnowUILogo($$renderer, $$props) {
177
178
  const run = ++generation;
178
179
 
179
180
  nodeStartedAt = performance.now();
181
+
182
+ if (index >= 0) emojiMetrics[index] = measureLogoEmoji(greetings[index][0]);
183
+
180
184
  greetingIndex = index;
181
185
 
182
186
  // 等 Svelte 提交所有字母和图标后,再由实际 transition end 判断完成。
@@ -222,7 +226,7 @@ export default function SnowUILogo($$renderer, $$props) {
222
226
  }
223
227
 
224
228
  function handleMouseEnter(event) {
225
- if (!prefersReducedMotion()) {
229
+ if (hoverMotion && !prefersReducedMotion()) {
226
230
  hovered = true;
227
231
  resumeRequested = performance.now() <= resumeUntil;
228
232
  reconcileHover();
@@ -240,8 +244,6 @@ export default function SnowUILogo($$renderer, $$props) {
240
244
  }
241
245
 
242
246
  onMount(() => {
243
- emojiMetrics = greetings.map(([emoji]) => measureLogoEmoji(emoji));
244
-
245
247
  const preference = window.matchMedia("(prefers-reduced-motion: reduce)");
246
248
 
247
249
  reducedMotion = preference.matches;
@@ -49,8 +49,10 @@ export default function StyleButton($$renderer, $$props) {
49
49
 
50
50
  if (nextMode === "apple") {
51
51
  document.documentElement.setAttribute("mode", "ios");
52
+ document.body?.setAttribute("mode", "ios");
52
53
  } else {
53
54
  document.documentElement.removeAttribute("mode");
55
+ document.body?.removeAttribute("mode");
54
56
  }
55
57
  }
56
58
 
@@ -1,6 +1,6 @@
1
1
  /** SnowUI 组件内置 UI 文案 catalog。文档: ../../../docs/standards/LocalizationSpec.md */
2
2
  export declare const DEFAULT_LOCALE = "zh-CN";
3
- export type SnowUIMessageKey = "copyButton.copy" | "copyButton.copied" | "codeBlock.copyCode" | "codeBlock.fullscreen" | "codeBlock.exitFullscreen" | "codeBlock.resize" | "codeBlock.fullscreenDialog" | "expandButton.expand" | "expandButton.collapse" | "sidebarSection.expand" | "sidebarSection.collapse" | "breadcrumb.navigation" | "pagination.navigation" | "spinner.loading" | "scrollArea.content" | "barChart.name" | "barChart.cells" | "lineChart.name" | "lineChart.cells" | "circularChart.name" | "gaugeChart.name" | "chartGroup.name" | "chartGroup.cells" | "chartGroup.cell" | "searchBox.placeholder" | "searchBox.clear" | "sidePanel.title" | "slider.title" | "menuItem.deleteCustom" | "listbox.search" | "tag.close" | "sidebar.navigation" | "sidebar.expand" | "sidebar.collapse" | "sidebarItem.updated" | "sidebar.resize" | "pagination.pageSize" | "pagination.previous" | "pagination.next" | "pagination.page" | "otpInput.invalidCode" | "input.clear" | "input.increment" | "input.decrement" | "input.openTime" | "input.openDate" | "input.year" | "input.month" | "input.day" | "input.week" | "input.hour" | "input.minute" | "input.second" | "input.yearPlaceholder" | "input.monthPlaceholder" | "input.dayPlaceholder" | "input.weekPlaceholder" | "imageViewer.previous" | "imageViewer.next" | "imageViewer.close" | "toast.close" | "table.scrollRegion" | "table.scrollRegionNamed" | "tableHead.selectAll" | "tableHead.resizeColumn" | "tableHead.resizeColumnGeneric" | "tableCell.selectRow" | "text.expand" | "textarea.resize" | "indicator.resizeWidth" | "indicator.resizeHeight" | "indicator.resizeBoth" | "colorSchemeButton.toLight" | "colorSchemeButton.toDark" | "styleButton.toSnowUI" | "styleButton.toApple" | "sidePanel.placement.toInline" | "sidePanel.placement.toFloating" | "sidePanel.previous" | "sidePanel.next" | "sidePanel.copy" | "sidePanel.delete" | "sidePanel.cancel" | "sidePanel.save" | "sidePanel.close" | "sidePanel.resize" | "tableToolbar.name" | "tableToolbar.search" | "tableToolbar.sort" | "tableToolbar.filter" | "tableToolbar.clear" | "tableToolbar.copy" | "tableToolbar.delete" | "tableToolbar.selected" | "tableToolbar.deleting" | "tableToolbar.defaultSort" | "tableToolbar.ascending" | "tableToolbar.descending" | "tableToolbar.defaultFilter" | "overflowActions.more" | "dialog.close";
3
+ export type SnowUIMessageKey = "copyButton.copy" | "copyButton.copied" | "codeBlock.copyCode" | "codeBlock.fullscreen" | "codeBlock.exitFullscreen" | "codeBlock.resize" | "codeBlock.fullscreenDialog" | "expandButton.expand" | "expandButton.collapse" | "sidebarSection.expand" | "sidebarSection.collapse" | "breadcrumb.navigation" | "pagination.navigation" | "spinner.loading" | "scrollArea.content" | "barChart.name" | "barChart.cells" | "lineChart.name" | "lineChart.cells" | "circularChart.name" | "gaugeChart.name" | "chartGroup.name" | "chartGroup.cells" | "chartGroup.cell" | "searchBox.placeholder" | "searchBox.clear" | "sidePanel.title" | "slider.title" | "menuItem.deleteCustom" | "listbox.search" | "tag.close" | "sidebar.navigation" | "sidebar.expand" | "sidebar.collapse" | "sidebarItem.updated" | "sidebar.resize" | "pagination.pageSize" | "pagination.previous" | "pagination.next" | "pagination.page" | "otpInput.invalidCode" | "input.clear" | "input.showPassword" | "input.hidePassword" | "passwordStrength.minimumLength" | "passwordStrength.requirements" | "passwordStrength.lowercase" | "passwordStrength.uppercase" | "passwordStrength.number" | "passwordStrength.symbol" | "input.increment" | "input.decrement" | "input.openTime" | "input.openDate" | "input.year" | "input.month" | "input.day" | "input.week" | "input.hour" | "input.minute" | "input.second" | "input.yearPlaceholder" | "input.monthPlaceholder" | "input.dayPlaceholder" | "input.weekPlaceholder" | "imageViewer.previous" | "imageViewer.next" | "imageViewer.close" | "toast.close" | "table.scrollRegion" | "table.scrollRegionNamed" | "tableHead.selectAll" | "tableHead.resizeColumn" | "tableHead.resizeColumnGeneric" | "tableCell.selectRow" | "text.expand" | "textarea.resize" | "indicator.resizeWidth" | "indicator.resizeHeight" | "indicator.resizeBoth" | "colorSchemeButton.toLight" | "colorSchemeButton.toDark" | "styleButton.toSnowUI" | "styleButton.toApple" | "sidePanel.placement.toInline" | "sidePanel.placement.toFloating" | "sidePanel.previous" | "sidePanel.next" | "sidePanel.copy" | "sidePanel.delete" | "sidePanel.cancel" | "sidePanel.save" | "sidePanel.close" | "sidePanel.resize" | "tableToolbar.name" | "tableToolbar.search" | "tableToolbar.sort" | "tableToolbar.filter" | "tableToolbar.clear" | "tableToolbar.copy" | "tableToolbar.delete" | "tableToolbar.selected" | "tableToolbar.deleting" | "tableToolbar.defaultSort" | "tableToolbar.ascending" | "tableToolbar.descending" | "tableToolbar.defaultFilter" | "overflowActions.more" | "dialog.close";
4
4
  export type SnowUIMessageValues = Record<string, string | number>;
5
5
  export type SnowUIMessageOverrides = Partial<Record<SnowUIMessageKey, string>>;
6
6
  export declare const SNOWUI_MESSAGES: Record<string, Record<SnowUIMessageKey, string>>;
@@ -46,6 +46,14 @@ export const SNOWUI_MESSAGES = {
46
46
  "pagination.page": "第 {{page}} 页",
47
47
  "otpInput.invalidCode": "请输入 {{length}} 位数字验证码",
48
48
  "input.clear": "清除输入",
49
+ "input.showPassword": "显示密码",
50
+ "input.hidePassword": "隐藏密码",
51
+ "passwordStrength.minimumLength": "密码至少需要 {{length}} 个字符",
52
+ "passwordStrength.requirements": "密码还需包含:{{requirements}}",
53
+ "passwordStrength.lowercase": "小写字母",
54
+ "passwordStrength.uppercase": "大写字母",
55
+ "passwordStrength.number": "数字",
56
+ "passwordStrength.symbol": "特殊字符(例如 ! @ # $ %)",
49
57
  "input.increment": "增加数值",
50
58
  "input.decrement": "减少数值",
51
59
  "input.openTime": "打开时间选择",
@@ -149,6 +157,14 @@ export const SNOWUI_MESSAGES = {
149
157
  "pagination.page": "Page {{page}}",
150
158
  "otpInput.invalidCode": "Enter a {{length}}-digit verification code",
151
159
  "input.clear": "Clear input",
160
+ "input.showPassword": "Show password",
161
+ "input.hidePassword": "Hide password",
162
+ "passwordStrength.minimumLength": "Password must be at least {{length}} characters",
163
+ "passwordStrength.requirements": "Password must also include: {{requirements}}",
164
+ "passwordStrength.lowercase": "a lowercase letter",
165
+ "passwordStrength.uppercase": "an uppercase letter",
166
+ "passwordStrength.number": "a number",
167
+ "passwordStrength.symbol": "a special character (e.g. ! @ # $ %)",
152
168
  "input.increment": "Increase value",
153
169
  "input.decrement": "Decrease value",
154
170
  "input.openTime": "Open time picker",
@@ -126,3 +126,5 @@ export * from './blocks';
126
126
  export * from './lib/split-pane';
127
127
  export { default as SearchPopup, type SearchPopupItem } from "./blocks/SearchPopup.js";
128
128
  export { default as BlurText } from "./components/BlurText.js";
129
+ export { default as MetricCard } from "./components/MetricCard.js";
130
+ export { default as PasswordStrength, evaluatePasswordStrength, type PasswordStrengthLevel, type PasswordStrengthEvaluator } from "./components/PasswordStrength.js";
@@ -116,3 +116,5 @@ export * from './blocks/index.js';
116
116
  export * from './lib/split-pane.js';
117
117
  export { default as SearchPopup } from "./blocks/SearchPopup.js";
118
118
  export { default as BlurText } from "./components/BlurText.js";
119
+ export { default as MetricCard } from "./components/MetricCard.js";
120
+ export { default as PasswordStrength, evaluatePasswordStrength } from "./components/PasswordStrength.js";