@snowui-design-system/components 0.3.0-alpha.12 → 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 (67) hide show
  1. package/AGENTS.md +9 -1
  2. package/README.md +6 -4
  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 +2 -2
  26. package/dist/client/i18n/messages.js +17 -1
  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/auto-layout.css +1 -1
  31. package/dist/client/styles/components.css +9 -5
  32. package/dist/client/styles/layout.css +2 -2
  33. package/dist/client/styles/scale.css +16 -16
  34. package/dist/client/styles/scrollbar.css +1 -1
  35. package/dist/client/styles/themes.css +1 -1
  36. package/dist/server/components/Accordion.js +1 -1
  37. package/dist/server/components/AccordionItem.js +1 -1
  38. package/dist/server/components/Avatar.js +42 -7
  39. package/dist/server/components/Button.js +1 -1
  40. package/dist/server/components/Card.js +2 -0
  41. package/dist/server/components/CodeBlock.js +29 -6
  42. package/dist/server/components/Dialog.js +3 -10
  43. package/dist/server/components/Icon.js +37 -2
  44. package/dist/server/components/Image.js +3 -1
  45. package/dist/server/components/Indicator.js +6 -3
  46. package/dist/server/components/Input.js +63 -5
  47. package/dist/server/components/MetricCard.d.ts +13 -0
  48. package/dist/server/components/MetricCard.js +104 -0
  49. package/dist/server/components/OTPInput.d.ts +2 -1
  50. package/dist/server/components/OTPInput.js +66 -35
  51. package/dist/server/components/PasswordStrength.d.ts +20 -0
  52. package/dist/server/components/PasswordStrength.js +105 -0
  53. package/dist/server/components/SnowUILogo.d.ts +1 -0
  54. package/dist/server/components/SnowUILogo.js +5 -3
  55. package/dist/server/components/StyleButton.js +2 -0
  56. package/dist/server/i18n/messages.d.ts +2 -2
  57. package/dist/server/i18n/messages.js +17 -1
  58. package/dist/server/index.d.ts +2 -0
  59. package/dist/server/index.js +2 -0
  60. package/dist/server/internal/component-icon/builtin-icon-data.js +14 -0
  61. package/dist/server/styles/auto-layout.css +1 -1
  62. package/dist/server/styles/components.css +9 -5
  63. package/dist/server/styles/layout.css +2 -2
  64. package/dist/server/styles/scale.css +16 -16
  65. package/dist/server/styles/scrollbar.css +1 -1
  66. package/dist/server/styles/themes.css +1 -1
  67. package/package.json +4 -3
@@ -173,7 +173,9 @@ export default function Input($$renderer, $$props) {
173
173
  const isCustomColorType = $.derived(() => normalizedInputType() === "color");
174
174
  const isCustomTemporalType = $.derived(() => normalizedInputType() === "date" || normalizedInputType() === "month" || normalizedInputType() === "week" || normalizedInputType() === "time" || normalizedInputType() === "datetime-local");
175
175
  const isTemporalValueEmpty = $.derived(() => isCustomTemporalType() && (resolvedValue() === undefined || resolvedValue() === null || resolvedValue() === ""));
176
- const isClearableType = $.derived(() => normalizedInputType() !== "number" && !isCustomColorType() && !isCustomTemporalType());
176
+ let passwordVisible = false;
177
+ const isPasswordType = $.derived(() => normalizedInputType() === "password");
178
+ const isClearableType = $.derived(() => normalizedInputType() !== "number" && !isPasswordType() && !isCustomColorType() && !isCustomTemporalType());
177
179
  const hasContent = $.derived(() => resolvedValue() !== undefined && resolvedValue() !== null && String(resolvedValue()) !== "");
178
180
  const hasClearableValue = $.derived(() => clearable() && isClearableType() && !readonly() && !disabled() && hasContent());
179
181
  const temporalInputType = $.derived(() => isCustomTemporalType() ? normalizedInputType() : null);
@@ -1044,7 +1046,7 @@ export default function Input($$renderer, $$props) {
1044
1046
  class: 'snowui-input-control snowui-native-control snowui-input-embedded-native snowui-horizontal-scroll-mask',
1045
1047
  'data-scroll-mask-x': horizontalScrollMask,
1046
1048
  id: id(),
1047
- type: normalizedInputType(),
1049
+ type: isPasswordType() && passwordVisible ? "text" : normalizedInputType(),
1048
1050
  name: name(),
1049
1051
  placeholder: placeholder(),
1050
1052
  disabled: disabled(),
@@ -1080,6 +1082,34 @@ export default function Input($$renderer, $$props) {
1080
1082
  children()?.($$renderer);
1081
1083
  $$renderer.push(`<!----> `);
1082
1084
 
1085
+ if (isPasswordType() && !hasCustomTrailing) {
1086
+ $$renderer.push('<!--[0-->');
1087
+
1088
+ Button($$renderer, {
1089
+ bare: true,
1090
+ emphasis: 'muted',
1091
+ size: 'sm',
1092
+ type: 'button',
1093
+ as: 'trailing',
1094
+ class: 'snowui-input-password-toggle',
1095
+ disabled: disabled(),
1096
+ 'aria-label': localeContext.t(passwordVisible ? "input.hidePassword" : "input.showPassword"),
1097
+ 'aria-pressed': passwordVisible,
1098
+ onclick: () => passwordVisible = !passwordVisible,
1099
+ children: ($$renderer) => {
1100
+ ComponentIcon($$renderer, {
1101
+ name: passwordVisible ? "eye-slash" : "eye",
1102
+ 'aria-hidden': 'true'
1103
+ });
1104
+ },
1105
+ $$slots: { default: true }
1106
+ });
1107
+ } else {
1108
+ $$renderer.push('<!--[-1-->');
1109
+ }
1110
+
1111
+ $$renderer.push(`<!--]--> `);
1112
+
1083
1113
  if (clearable() && isClearableType() && !disabled() && !readonly()) {
1084
1114
  $$renderer.push('<!--[0-->');
1085
1115
 
@@ -1106,7 +1136,7 @@ export default function Input($$renderer, $$props) {
1106
1136
 
1107
1137
  $$renderer.push(`<!--]--> `);
1108
1138
 
1109
- if (resolvedInvalid() && !hasCustomTrailing) {
1139
+ if (resolvedInvalid() && !hasCustomTrailing && !isPasswordType()) {
1110
1140
  $$renderer.push('<!--[0-->');
1111
1141
  $$renderer.push(`<span class="snowui-input-warning-icon snowui-role-trailing text-secondary-red" aria-hidden="true">`);
1112
1142
 
@@ -1270,7 +1300,7 @@ export default function Input($$renderer, $$props) {
1270
1300
  class: 'snowui-input-control snowui-native-control snowui-horizontal-scroll-mask',
1271
1301
  'data-scroll-mask-x': horizontalScrollMask,
1272
1302
  id: id(),
1273
- type: normalizedInputType(),
1303
+ type: isPasswordType() && passwordVisible ? "text" : normalizedInputType(),
1274
1304
  name: name(),
1275
1305
  placeholder: placeholder(),
1276
1306
  disabled: disabled(),
@@ -1385,6 +1415,34 @@ export default function Input($$renderer, $$props) {
1385
1415
  children()?.($$renderer);
1386
1416
  $$renderer.push(`<!----> `);
1387
1417
 
1418
+ if (isPasswordType() && !hasCustomTrailing) {
1419
+ $$renderer.push('<!--[0-->');
1420
+
1421
+ Button($$renderer, {
1422
+ bare: true,
1423
+ emphasis: 'muted',
1424
+ size: 'sm',
1425
+ type: 'button',
1426
+ as: 'trailing',
1427
+ class: 'snowui-input-password-toggle',
1428
+ disabled: disabled(),
1429
+ 'aria-label': localeContext.t(passwordVisible ? "input.hidePassword" : "input.showPassword"),
1430
+ 'aria-pressed': passwordVisible,
1431
+ onclick: () => passwordVisible = !passwordVisible,
1432
+ children: ($$renderer) => {
1433
+ ComponentIcon($$renderer, {
1434
+ name: passwordVisible ? "eye-slash" : "eye",
1435
+ 'aria-hidden': 'true'
1436
+ });
1437
+ },
1438
+ $$slots: { default: true }
1439
+ });
1440
+ } else {
1441
+ $$renderer.push('<!--[-1-->');
1442
+ }
1443
+
1444
+ $$renderer.push(`<!--]--> `);
1445
+
1388
1446
  if (clearable() && isClearableType() && !disabled() && !readonly()) {
1389
1447
  $$renderer.push('<!--[0-->');
1390
1448
 
@@ -1411,7 +1469,7 @@ export default function Input($$renderer, $$props) {
1411
1469
 
1412
1470
  $$renderer.push(`<!--]--> `);
1413
1471
 
1414
- if (resolvedInvalid() && !hasCustomTrailing) {
1472
+ if (resolvedInvalid() && !hasCustomTrailing && !isPasswordType()) {
1415
1473
  $$renderer.push('<!--[0-->');
1416
1474
  $$renderer.push(`<span class="snowui-input-warning-icon snowui-role-trailing text-secondary-red" aria-hidden="true">`);
1417
1475
 
@@ -0,0 +1,13 @@
1
+ import type { ComponentProps } from 'svelte';
2
+ import Card from './Card.js';
3
+ interface Props extends Omit<ComponentProps<typeof Card>, 'children' | 'contentFill' | 'contentHug' | 'scrollable'> {
4
+ label: string;
5
+ value: string;
6
+ change?: string;
7
+ emphasis?: 'value' | 'change';
8
+ trend?: 'positive' | 'negative' | 'neutral';
9
+ [key: string]: any;
10
+ }
11
+ declare const MetricCard: import("svelte").Component<Props, {}, "">;
12
+ type MetricCard = ReturnType<typeof MetricCard>;
13
+ export default MetricCard;
@@ -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;