@svadmin/ui 0.119.0 → 0.121.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/app.css +139 -0
  2. package/dist/app.theme.css +139 -0
  3. package/dist/components/AboutSettings.svelte +1 -1
  4. package/dist/components/Barcode.svelte +219 -0
  5. package/dist/components/Barcode.svelte.d.ts +15 -0
  6. package/dist/components/ContextMenu.svelte +268 -0
  7. package/dist/components/ContextMenu.svelte.d.ts +22 -0
  8. package/dist/components/JsonViewer.svelte +323 -0
  9. package/dist/components/JsonViewer.svelte.d.ts +20 -0
  10. package/dist/components/KpiCard.svelte +250 -0
  11. package/dist/components/KpiCard.svelte.d.ts +44 -0
  12. package/dist/components/NumberRoll.svelte +149 -0
  13. package/dist/components/NumberRoll.svelte.d.ts +17 -0
  14. package/dist/components/OtpInput.svelte +209 -0
  15. package/dist/components/OtpInput.svelte.d.ts +17 -0
  16. package/dist/components/RecordCompareModal.svelte +428 -0
  17. package/dist/components/RecordCompareModal.svelte.d.ts +42 -0
  18. package/dist/components/ResultPage.svelte +166 -0
  19. package/dist/components/ResultPage.svelte.d.ts +28 -0
  20. package/dist/components/SignaturePad.svelte +230 -66
  21. package/dist/components/SignaturePad.svelte.d.ts +6 -5
  22. package/dist/components/Tour.svelte +71 -13
  23. package/dist/components/Tour.svelte.d.ts +1 -1
  24. package/dist/components/TrendIndicator.svelte +21 -13
  25. package/dist/components/TrendIndicator.svelte.d.ts +4 -2
  26. package/dist/components/UnsavedChangesGuard.svelte +138 -0
  27. package/dist/components/UnsavedChangesGuard.svelte.d.ts +32 -0
  28. package/dist/components/VirtualList.svelte +165 -0
  29. package/dist/components/VirtualList.svelte.d.ts +43 -0
  30. package/dist/components/WatermarkContainer.svelte +196 -0
  31. package/dist/components/WatermarkContainer.svelte.d.ts +20 -0
  32. package/dist/components/useUnsavedChanges.d.svelte.ts +1 -0
  33. package/dist/components/useUnsavedChanges.svelte.d.ts +22 -0
  34. package/dist/components/useUnsavedChanges.svelte.js +105 -0
  35. package/dist/index.d.ts +30 -35
  36. package/dist/index.js +18 -2
  37. package/package.json +1 -1
@@ -0,0 +1,149 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+ import { cn } from '../utils.js';
4
+ import { TrendingUp, TrendingDown, Minus } from '@lucide/svelte';
5
+
6
+ export interface NumberRollProps {
7
+ value: number;
8
+ from?: number;
9
+ duration?: number;
10
+ decimals?: number;
11
+ separator?: string;
12
+ decimalSeparator?: string;
13
+ prefix?: string;
14
+ suffix?: string;
15
+ trendColor?: boolean;
16
+ showTrendIcon?: boolean;
17
+ class?: string;
18
+ oncomplete?: () => void;
19
+ }
20
+
21
+ let {
22
+ value,
23
+ from = 0,
24
+ duration = 1200,
25
+ decimals = 0,
26
+ separator = ',',
27
+ decimalSeparator = '.',
28
+ prefix = '',
29
+ suffix = '',
30
+ trendColor = false,
31
+ showTrendIcon = false,
32
+ class: className = '',
33
+ oncomplete,
34
+ }: NumberRollProps = $props();
35
+
36
+ let displayValue = $state<number | null>(null);
37
+ let animationFrameId: number | null = null;
38
+ let previousValue = $state<number | null>(null);
39
+
40
+ // 四次缓动减速函数 (Ease Out Quart)
41
+ function easeOutQuart(x: number): number {
42
+ return 1 - Math.pow(1 - x, 4);
43
+ }
44
+
45
+ function startAnimation(startVal: number, endVal: number) {
46
+ if (animationFrameId !== null) {
47
+ cancelAnimationFrame(animationFrameId);
48
+ }
49
+
50
+ if (duration <= 0) {
51
+ displayValue = endVal;
52
+ previousValue = endVal;
53
+ oncomplete?.();
54
+ return;
55
+ }
56
+
57
+ const startTime = performance.now();
58
+
59
+ function step(currentTime: number) {
60
+ const elapsed = currentTime - startTime;
61
+ const progress = Math.min(elapsed / duration, 1);
62
+ const easedProgress = easeOutQuart(progress);
63
+
64
+ displayValue = startVal + (endVal - startVal) * easedProgress;
65
+
66
+ if (progress < 1) {
67
+ animationFrameId = requestAnimationFrame(step);
68
+ } else {
69
+ displayValue = endVal;
70
+ previousValue = endVal;
71
+ animationFrameId = null;
72
+ oncomplete?.();
73
+ }
74
+ }
75
+
76
+ animationFrameId = requestAnimationFrame(step);
77
+ }
78
+
79
+ // 监听 value 变化并平滑缓动
80
+ $effect(() => {
81
+ const currentTarget = value;
82
+ const startVal = previousValue ?? from;
83
+ if (displayValue === null) {
84
+ displayValue = startVal;
85
+ }
86
+ startAnimation(startVal, currentTarget);
87
+ });
88
+
89
+ onMount(() => {
90
+ return () => {
91
+ if (animationFrameId !== null) {
92
+ cancelAnimationFrame(animationFrameId);
93
+ }
94
+ };
95
+ });
96
+
97
+ // 格式化输出数字(带千分位、小数位)
98
+ const formattedNumber = $derived.by(() => {
99
+ const current = displayValue ?? value;
100
+ const fixed = current.toFixed(decimals);
101
+ const parts = fixed.split('.');
102
+ const intPart = parts[0] ?? '0';
103
+ const decPart = parts[1];
104
+ const formattedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
105
+ return decPart !== undefined ? `${formattedInt}${decimalSeparator}${decPart}` : formattedInt;
106
+ });
107
+
108
+ // 趋势计算 (对比 0)
109
+ const isPositive = $derived(value > 0);
110
+ const isNegative = $derived(value < 0);
111
+
112
+ const trendColorClass = $derived.by(() => {
113
+ if (!trendColor) return 'text-foreground';
114
+ if (isPositive) return 'text-primary';
115
+ if (isNegative) return 'text-destructive';
116
+ return 'text-muted-foreground';
117
+ });
118
+ </script>
119
+
120
+ <span
121
+ data-svadmin-component="NumberRoll"
122
+ class={cn(
123
+ 'inline-flex items-center gap-1 font-mono font-semibold tracking-tight tabular-nums select-none transition-colors',
124
+ trendColorClass,
125
+ className
126
+ )}
127
+ >
128
+ {#if showTrendIcon}
129
+ <span class="inline-flex shrink-0 items-center justify-center">
130
+ {#if isPositive}
131
+ <TrendingUp class="h-4 w-4 text-primary" />
132
+ {:else if isNegative}
133
+ <TrendingDown class="h-4 w-4 text-destructive" />
134
+ {:else}
135
+ <Minus class="h-4 w-4 text-muted-foreground" />
136
+ {/if}
137
+ </span>
138
+ {/if}
139
+
140
+ {#if prefix}
141
+ <span class="text-xs font-normal text-muted-foreground">{prefix}</span>
142
+ {/if}
143
+
144
+ <span class="text-base font-bold">{formattedNumber}</span>
145
+
146
+ {#if suffix}
147
+ <span class="text-xs font-normal text-muted-foreground">{suffix}</span>
148
+ {/if}
149
+ </span>
@@ -0,0 +1,17 @@
1
+ export interface NumberRollProps {
2
+ value: number;
3
+ from?: number;
4
+ duration?: number;
5
+ decimals?: number;
6
+ separator?: string;
7
+ decimalSeparator?: string;
8
+ prefix?: string;
9
+ suffix?: string;
10
+ trendColor?: boolean;
11
+ showTrendIcon?: boolean;
12
+ class?: string;
13
+ oncomplete?: () => void;
14
+ }
15
+ declare const NumberRoll: import("svelte").Component<NumberRollProps, {}, "">;
16
+ type NumberRoll = ReturnType<typeof NumberRoll>;
17
+ export default NumberRoll;
@@ -0,0 +1,209 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+ import { cn } from '../utils.js';
4
+
5
+ export interface OtpInputProps {
6
+ length?: number;
7
+ value?: string | string[];
8
+ type?: 'number' | 'text' | 'alphanumeric';
9
+ mask?: boolean;
10
+ disabled?: boolean;
11
+ error?: boolean;
12
+ autoFocus?: boolean;
13
+ size?: 'sm' | 'md' | 'lg';
14
+ class?: string;
15
+ 'aria-label'?: string;
16
+ onchange?: (value: string) => void;
17
+ oncomplete?: (value: string) => void;
18
+ }
19
+
20
+ let {
21
+ length = 6,
22
+ value = $bindable(''),
23
+ type = 'alphanumeric',
24
+ mask = false,
25
+ disabled = false,
26
+ error = false,
27
+ autoFocus = false,
28
+ size = 'md',
29
+ class: className = '',
30
+ 'aria-label': groupAriaLabel = 'OTP verification code input',
31
+ onchange,
32
+ oncomplete,
33
+ }: OtpInputProps = $props();
34
+
35
+ let digits = $state<string[]>([]);
36
+ const inputRefs: (HTMLInputElement | null)[] = [];
37
+
38
+ function registerInput(node: HTMLInputElement, index: number) {
39
+ inputRefs[index] = node;
40
+ return {
41
+ destroy() {
42
+ if (inputRefs[index] === node) {
43
+ inputRefs[index] = null;
44
+ }
45
+ },
46
+ };
47
+ }
48
+
49
+ function isValidChar(char: string): boolean {
50
+ if (type === 'number') {
51
+ return /^[0-9]$/.test(char);
52
+ }
53
+ if (type === 'alphanumeric') {
54
+ return /^[a-zA-Z0-9]$/.test(char);
55
+ }
56
+ return char.length === 1;
57
+ }
58
+
59
+ function getRawStringValue(): string {
60
+ if (Array.isArray(value)) {
61
+ return value.join('');
62
+ }
63
+ return value || '';
64
+ }
65
+
66
+ function syncFromValue() {
67
+ const raw = getRawStringValue();
68
+ const chars = raw.split('').slice(0, length);
69
+ const newDigits = Array.from({ length }, (_, i) => chars[i] || '');
70
+ digits = newDigits;
71
+ }
72
+
73
+ function notifyChange() {
74
+ const combined = digits.join('');
75
+ if (Array.isArray(value)) {
76
+ value = [...digits];
77
+ } else {
78
+ value = combined;
79
+ }
80
+ onchange?.(combined);
81
+ if (combined.length === length && digits.every((d) => d !== '')) {
82
+ oncomplete?.(combined);
83
+ }
84
+ }
85
+
86
+ function handleInput(e: Event, index: number) {
87
+ const input = e.target as HTMLInputElement;
88
+ const rawVal = input.value;
89
+ const char = rawVal.slice(-1);
90
+
91
+ if (char && isValidChar(char)) {
92
+ digits[index] = char;
93
+ if (index < length - 1) {
94
+ inputRefs[index + 1]?.focus();
95
+ }
96
+ } else {
97
+ digits[index] = '';
98
+ }
99
+
100
+ notifyChange();
101
+ }
102
+
103
+ function handleKeyDown(e: KeyboardEvent, index: number) {
104
+ if (e.key === 'Backspace') {
105
+ if (digits[index] !== '') {
106
+ digits[index] = '';
107
+ notifyChange();
108
+ } else if (index > 0) {
109
+ digits[index - 1] = '';
110
+ inputRefs[index - 1]?.focus();
111
+ notifyChange();
112
+ }
113
+ e.preventDefault();
114
+ } else if (e.key === 'ArrowLeft') {
115
+ if (index > 0) {
116
+ inputRefs[index - 1]?.focus();
117
+ e.preventDefault();
118
+ }
119
+ } else if (e.key === 'ArrowRight') {
120
+ if (index < length - 1) {
121
+ inputRefs[index + 1]?.focus();
122
+ e.preventDefault();
123
+ }
124
+ }
125
+ }
126
+
127
+ function handlePaste(e: ClipboardEvent) {
128
+ e.preventDefault();
129
+ const pastedText = e.clipboardData?.getData('text') || '';
130
+ if (!pastedText) return;
131
+
132
+ let validChars = '';
133
+ for (const char of pastedText) {
134
+ if (isValidChar(char)) {
135
+ validChars += char;
136
+ if (validChars.length === length) break;
137
+ }
138
+ }
139
+
140
+ if (!validChars) return;
141
+
142
+ const newDigits = [...digits];
143
+ for (let i = 0; i < length; i++) {
144
+ const char = validChars[i];
145
+ if (char) {
146
+ newDigits[i] = char;
147
+ }
148
+ }
149
+ digits = newDigits;
150
+ notifyChange();
151
+
152
+ const nextIndex = Math.min(validChars.length, length - 1);
153
+ inputRefs[nextIndex]?.focus();
154
+ }
155
+
156
+ $effect(() => {
157
+ const raw = getRawStringValue();
158
+ if (digits.length !== length || raw !== digits.join('')) {
159
+ syncFromValue();
160
+ }
161
+ });
162
+
163
+ onMount(() => {
164
+ syncFromValue();
165
+ if (autoFocus && inputRefs[0]) {
166
+ inputRefs[0].focus();
167
+ }
168
+ });
169
+
170
+ const sizeClasses = {
171
+ sm: 'h-8 w-8 text-sm',
172
+ md: 'h-10 w-10 text-base',
173
+ lg: 'h-12 w-12 text-lg',
174
+ };
175
+ </script>
176
+
177
+ <div
178
+ class={cn('inline-flex items-center gap-2', className)}
179
+ data-svadmin-component="OtpInput"
180
+ role="group"
181
+ aria-label={groupAriaLabel}
182
+ >
183
+ {#each digits as digit, index (index)}
184
+ <input
185
+ use:registerInput={index}
186
+ type={mask ? 'password' : 'text'}
187
+ inputmode={type === 'number' ? 'numeric' : 'text'}
188
+ pattern={type === 'number' ? '[0-9]*' : undefined}
189
+ maxlength={1}
190
+ value={digit}
191
+ {disabled}
192
+ aria-label={`Digit ${index + 1} of ${length}`}
193
+ aria-invalid={error ? 'true' : undefined}
194
+ class={cn(
195
+ 'rounded-md border text-center font-mono font-semibold transition-all outline-none',
196
+ 'focus:ring-2 focus:ring-primary focus:ring-offset-2',
197
+ sizeClasses[size],
198
+ error
199
+ ? 'border-destructive text-destructive focus:ring-destructive'
200
+ : 'border-input bg-background text-foreground',
201
+ disabled ? 'cursor-not-allowed bg-muted opacity-50' : 'cursor-text'
202
+ )}
203
+ oninput={(e) => handleInput(e, index)}
204
+ onkeydown={(e) => handleKeyDown(e, index)}
205
+ onpaste={handlePaste}
206
+ onfocus={(e) => (e.target as HTMLInputElement).select()}
207
+ />
208
+ {/each}
209
+ </div>
@@ -0,0 +1,17 @@
1
+ export interface OtpInputProps {
2
+ length?: number;
3
+ value?: string | string[];
4
+ type?: 'number' | 'text' | 'alphanumeric';
5
+ mask?: boolean;
6
+ disabled?: boolean;
7
+ error?: boolean;
8
+ autoFocus?: boolean;
9
+ size?: 'sm' | 'md' | 'lg';
10
+ class?: string;
11
+ 'aria-label'?: string;
12
+ onchange?: (value: string) => void;
13
+ oncomplete?: (value: string) => void;
14
+ }
15
+ declare const OtpInput: import("svelte").Component<OtpInputProps, {}, "value">;
16
+ type OtpInput = ReturnType<typeof OtpInput>;
17
+ export default OtpInput;