@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,219 @@
1
+ <script lang="ts">
2
+ import { cn } from '../utils.js';
3
+ import { Copy, Check, Printer } from '@lucide/svelte';
4
+
5
+ export type BarcodeFormat = 'CODE128' | 'CODE39' | 'EAN13';
6
+
7
+ export interface BarcodeProps {
8
+ value: string;
9
+ format?: BarcodeFormat;
10
+ width?: number;
11
+ height?: number;
12
+ showText?: boolean;
13
+ text?: string;
14
+ showActions?: boolean;
15
+ margin?: number;
16
+ class?: string;
17
+ }
18
+
19
+ let {
20
+ value,
21
+ format = 'CODE128',
22
+ width = 2,
23
+ height = 60,
24
+ showText = true,
25
+ text,
26
+ showActions = false,
27
+ margin = 8,
28
+ class: className = '',
29
+ }: BarcodeProps = $props();
30
+
31
+ let copied = $state(false);
32
+
33
+ // CODE39 模式表: 每个字符由 9 个单元组成(5条4空),其中3个为宽单元(值为1表示宽,0表示窄)
34
+ const CODE39_ENCODINGS: Record<string, string> = {
35
+ '0': '000110100', '1': '100100001', '2': '001100001', '3': '101100000',
36
+ '4': '000110001', '5': '100110000', '6': '001110000', '7': '000100101',
37
+ '8': '100100100', '9': '001100100', 'A': '100001001', 'B': '001001001',
38
+ 'C': '101001000', 'D': '000011001', 'E': '100011000', 'F': '001011000',
39
+ 'G': '000001101', 'H': '100001100', 'I': '001001100', 'J': '000011100',
40
+ 'K': '100000011', 'L': '001000011', 'M': '101000010', 'N': '000010011',
41
+ 'O': '100010010', 'P': '001010010', 'Q': '000000111', 'R': '100000110',
42
+ 'S': '001000110', 'T': '000010110', 'U': '110000001', 'V': '011000001',
43
+ 'W': '111000000', 'X': '010010001', 'Y': '110010000', 'Z': '011010000',
44
+ '-': '010000101', '.': '110000100', ' ': '011000100', '$': '010101000',
45
+ '/': '010100010', '+': '010001010', '%': '000101010', '*': '010010100'
46
+ };
47
+
48
+ // CODE128 模式表 (常用模式)
49
+ const CODE128_PATTERNS: string[] = [
50
+ '212222', '222122', '222221', '121223', '121322', '131222', '122213', '122312', '132212', '221213',
51
+ '221312', '231212', '112232', '122132', '122231', '113222', '123122', '123221', '223211', '221132',
52
+ '221231', '213212', '223112', '312131', '311222', '321122', '321221', '312212', '322112', '322211',
53
+ '212123', '212321', '232121', '111323', '131123', '131321', '112313', '132113', '132311', '211313',
54
+ '231113', '231311', '112133', '112331', '132131', '113123', '113321', '133121', '313121', '211331',
55
+ '231131', '213113', '213311', '213131', '311123', '311321', '331121', '312113', '312311', '332111',
56
+ '314111', '221411', '431111', '111224', '111422', '121124', '121421', '141122', '141221', '112214',
57
+ '112412', '122114', '122411', '142112', '142211', '241211', '221114', '413111', '241112', '134111',
58
+ '111242', '121142', '121241', '114212', '124112', '124211', '411212', '421112', '421211', '212141',
59
+ '214121', '412121', '111143', '111341', '131141', '114113', '114311', '411113', '411311', '113141',
60
+ '114131', '311141', '411131', '211412', '211214', '211232', '2331112'
61
+ ];
62
+
63
+ interface BarSegment {
64
+ x: number;
65
+ width: number;
66
+ }
67
+
68
+ const barcodeBars = $derived.by<BarSegment[]>(() => {
69
+ if (!value) return [];
70
+ const bars: BarSegment[] = [];
71
+ let currentX = margin;
72
+
73
+ if (format === 'CODE39') {
74
+ const cleanValue = `*${value.toUpperCase()}*`;
75
+ for (let i = 0; i < cleanValue.length; i++) {
76
+ const char = cleanValue[i] ?? '-';
77
+ const pattern = CODE39_ENCODINGS[char] ?? CODE39_ENCODINGS['-'] ?? '010000101';
78
+ // 9 个单元:偶数索引是条,奇数索引是空
79
+ for (let j = 0; j < 9; j++) {
80
+ const isBar = j % 2 === 0;
81
+ const isWide = pattern[j] === '1';
82
+ const segmentWidth = (isWide ? 3 : 1) * width;
83
+ if (isBar) {
84
+ bars.push({ x: currentX, width: segmentWidth });
85
+ }
86
+ currentX += segmentWidth;
87
+ }
88
+ // 字符间间隔
89
+ currentX += width;
90
+ }
91
+ } else {
92
+ // CODE128 (默认 Code B 模式)
93
+ const startBIndex = 104;
94
+ const stopIndex = 106;
95
+ let checksum = startBIndex;
96
+ const codes: number[] = [startBIndex];
97
+
98
+ for (let i = 0; i < value.length; i++) {
99
+ const charCode = value.charCodeAt(i);
100
+ const codeIndex = charCode >= 32 && charCode <= 126 ? charCode - 32 : 0;
101
+ codes.push(codeIndex);
102
+ checksum += codeIndex * (i + 1);
103
+ }
104
+ codes.push(checksum % 103);
105
+ codes.push(stopIndex);
106
+
107
+ for (const code of codes) {
108
+ const pattern = CODE128_PATTERNS[code] ?? CODE128_PATTERNS[0] ?? '212222';
109
+ let isBar = true;
110
+ for (let j = 0; j < pattern.length; j++) {
111
+ const char = pattern[j] ?? '1';
112
+ const runLength = parseInt(char, 10) * width;
113
+ if (isBar) {
114
+ bars.push({ x: currentX, width: runLength });
115
+ }
116
+ currentX += runLength;
117
+ isBar = !isBar;
118
+ }
119
+ }
120
+ }
121
+
122
+ return bars;
123
+ });
124
+
125
+ const totalWidth = $derived.by(() => {
126
+ if (barcodeBars.length === 0) return 200;
127
+ const lastBar = barcodeBars[barcodeBars.length - 1];
128
+ return lastBar ? lastBar.x + lastBar.width + margin : 200;
129
+ });
130
+
131
+ const displayLabel = $derived(text ?? value);
132
+
133
+ async function copyValue() {
134
+ try {
135
+ await navigator.clipboard.writeText(value);
136
+ copied = true;
137
+ setTimeout(() => { copied = false; }, 2000);
138
+ } catch {
139
+ // ignore
140
+ }
141
+ }
142
+
143
+ function handlePrint() {
144
+ window.print();
145
+ }
146
+ </script>
147
+
148
+ <div
149
+ data-svadmin-component="Barcode"
150
+ class={cn(
151
+ 'inline-flex flex-col items-center justify-center rounded-lg border border-border bg-card p-4 shadow-xs select-none transition-all',
152
+ className
153
+ )}
154
+ >
155
+ <!-- 条形码 SVG 渲染 -->
156
+ <svg
157
+ width={totalWidth}
158
+ height={height + (showText ? 24 : 0)}
159
+ viewBox="0 0 {totalWidth} {height + (showText ? 24 : 0)}"
160
+ class="max-w-full overflow-visible"
161
+ aria-label="Barcode for {value}"
162
+ >
163
+ <!-- 背景填充 -->
164
+ <rect width={totalWidth} height={height + (showText ? 24 : 0)} fill="transparent" />
165
+
166
+ <!-- 条形码黑条 -->
167
+ {#each barcodeBars as bar, idx (`bar-${idx}`)}
168
+ <rect
169
+ x={bar.x}
170
+ y={margin}
171
+ width={bar.width}
172
+ height={height - margin * 0.5}
173
+ class="fill-foreground"
174
+ />
175
+ {/each}
176
+
177
+ <!-- 下方文本 -->
178
+ {#if showText}
179
+ <text
180
+ x={totalWidth / 2}
181
+ y={height + 16}
182
+ text-anchor="middle"
183
+ class="fill-muted-foreground font-mono text-xs tracking-wider"
184
+ >
185
+ {displayLabel}
186
+ </text>
187
+ {/if}
188
+ </svg>
189
+
190
+ <!-- 快捷操作栏(复制、打印) -->
191
+ {#if showActions}
192
+ <div class="mt-3 flex items-center gap-2 border-t border-border pt-2.5 w-full justify-center">
193
+ <button
194
+ type="button"
195
+ onclick={copyValue}
196
+ class="inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
197
+ title="复制条码内容"
198
+ >
199
+ {#if copied}
200
+ <Check class="h-3.5 w-3.5 text-primary" />
201
+ <span>已复制</span>
202
+ {:else}
203
+ <Copy class="h-3.5 w-3.5" />
204
+ <span>复制</span>
205
+ {/if}
206
+ </button>
207
+
208
+ <button
209
+ type="button"
210
+ onclick={handlePrint}
211
+ class="inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
212
+ title="打印条形码"
213
+ >
214
+ <Printer class="h-3.5 w-3.5" />
215
+ <span>打印</span>
216
+ </button>
217
+ </div>
218
+ {/if}
219
+ </div>
@@ -0,0 +1,15 @@
1
+ export type BarcodeFormat = 'CODE128' | 'CODE39' | 'EAN13';
2
+ export interface BarcodeProps {
3
+ value: string;
4
+ format?: BarcodeFormat;
5
+ width?: number;
6
+ height?: number;
7
+ showText?: boolean;
8
+ text?: string;
9
+ showActions?: boolean;
10
+ margin?: number;
11
+ class?: string;
12
+ }
13
+ declare const Barcode: import("svelte").Component<BarcodeProps, {}, "">;
14
+ type Barcode = ReturnType<typeof Barcode>;
15
+ export default Barcode;
@@ -0,0 +1,268 @@
1
+ <script lang="ts">
2
+ import { onMount, onDestroy, type Snippet } from 'svelte';
3
+ import { cn } from '../utils.js';
4
+
5
+ export interface ContextMenuItem {
6
+ key: string;
7
+ label: string;
8
+ icon?: string | Snippet;
9
+ shortcut?: string;
10
+ disabled?: boolean;
11
+ danger?: boolean;
12
+ divider?: boolean;
13
+ children?: ContextMenuItem[];
14
+ onclick?: (item: ContextMenuItem) => void;
15
+ }
16
+
17
+ export interface ContextMenuProps {
18
+ items: ContextMenuItem[];
19
+ disabled?: boolean;
20
+ class?: string;
21
+ onselect?: (item: ContextMenuItem) => void;
22
+ children?: Snippet;
23
+ }
24
+
25
+ let {
26
+ items = [],
27
+ disabled = false,
28
+ class: className = '',
29
+ onselect,
30
+ children,
31
+ }: ContextMenuProps = $props();
32
+
33
+ let isOpen = $state(false);
34
+ let menuX = $state(0);
35
+ let menuY = $state(0);
36
+ let activeSubmenuKey = $state<string | null>(null);
37
+
38
+ let containerEl = $state<HTMLDivElement | null>(null);
39
+ let menuEl = $state<HTMLDivElement | null>(null);
40
+
41
+ function closeMenu() {
42
+ isOpen = false;
43
+ activeSubmenuKey = null;
44
+ }
45
+
46
+ function handleContextMenu(e: MouseEvent) {
47
+ if (disabled || items.length === 0) return;
48
+ e.preventDefault();
49
+ e.stopPropagation();
50
+
51
+ activeSubmenuKey = null;
52
+ const clientX = e.clientX;
53
+ const clientY = e.clientY;
54
+
55
+ const estimatedWidth = 190;
56
+ const estimatedHeight = items.length * 36;
57
+ const winW = typeof window !== 'undefined' ? window.innerWidth : 1024;
58
+ const winH = typeof window !== 'undefined' ? window.innerHeight : 768;
59
+
60
+ let posX = clientX;
61
+ let posY = clientY;
62
+
63
+ if (clientX + estimatedWidth > winW - 8) {
64
+ posX = Math.max(8, clientX - estimatedWidth);
65
+ }
66
+ if (clientY + estimatedHeight > winH - 8) {
67
+ posY = Math.max(8, clientY - estimatedHeight);
68
+ }
69
+
70
+ menuX = posX;
71
+ menuY = posY;
72
+ isOpen = true;
73
+ }
74
+
75
+ function handleItemClick(item: ContextMenuItem, e: MouseEvent) {
76
+ if (item.disabled || item.divider) return;
77
+ if (item.children && item.children.length > 0) {
78
+ // Toggle or keep submenu open
79
+ activeSubmenuKey = activeSubmenuKey === item.key ? null : item.key;
80
+ return;
81
+ }
82
+
83
+ e.stopPropagation();
84
+ item.onclick?.(item);
85
+ onselect?.(item);
86
+ closeMenu();
87
+ }
88
+
89
+ function handleSubItemClick(subItem: ContextMenuItem, e: MouseEvent) {
90
+ if (subItem.disabled || subItem.divider) return;
91
+ e.stopPropagation();
92
+ subItem.onclick?.(subItem);
93
+ onselect?.(subItem);
94
+ closeMenu();
95
+ }
96
+
97
+ function handleGlobalClick(e: MouseEvent) {
98
+ if (!isOpen) return;
99
+ if (menuEl && !menuEl.contains(e.target as Node)) {
100
+ closeMenu();
101
+ }
102
+ }
103
+
104
+ function handleGlobalKeyDown(e: KeyboardEvent) {
105
+ if (!isOpen) return;
106
+ if (e.key === 'Escape') {
107
+ closeMenu();
108
+ }
109
+ }
110
+
111
+ function handleGlobalScroll() {
112
+ if (isOpen) {
113
+ closeMenu();
114
+ }
115
+ }
116
+
117
+ onMount(() => {
118
+ if (typeof window !== 'undefined') {
119
+ window.addEventListener('click', handleGlobalClick);
120
+ window.addEventListener('keydown', handleGlobalKeyDown);
121
+ window.addEventListener('scroll', handleGlobalScroll, true);
122
+ }
123
+ });
124
+
125
+ onDestroy(() => {
126
+ if (typeof window !== 'undefined') {
127
+ window.removeEventListener('click', handleGlobalClick);
128
+ window.removeEventListener('keydown', handleGlobalKeyDown);
129
+ window.removeEventListener('scroll', handleGlobalScroll, true);
130
+ }
131
+ });
132
+ </script>
133
+
134
+ <!-- Outer wrapper capturing right-click context menu -->
135
+ <div
136
+ bind:this={containerEl}
137
+ oncontextmenu={handleContextMenu}
138
+ class={cn('contents', className)}
139
+ data-svadmin-component="ContextMenu"
140
+ role="region"
141
+ aria-label="Context Menu Container"
142
+ >
143
+ {@render children?.()}
144
+ </div>
145
+
146
+ {#if isOpen}
147
+ <div
148
+ bind:this={menuEl}
149
+ class="fixed z-50 min-w-[180px] rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md outline-none animate-in fade-in-80 zoom-in-95"
150
+ style="left: {menuX}px; top: {menuY}px;"
151
+ data-svadmin-context-menu-popup="true"
152
+ role="menu"
153
+ tabindex="-1"
154
+ >
155
+ {#each items as item (item.key)}
156
+ {#if item.divider}
157
+ <div class="-mx-1 my-1 h-px bg-border" role="separator"></div>
158
+ {:else}
159
+ <div
160
+ class="relative"
161
+ role="none"
162
+ onmouseenter={() => {
163
+ if (item.children && item.children.length > 0) {
164
+ activeSubmenuKey = item.key;
165
+ }
166
+ }}
167
+ >
168
+ <button
169
+ type="button"
170
+ role="menuitem"
171
+ disabled={item.disabled}
172
+ aria-disabled={item.disabled}
173
+ aria-haspopup={item.children && item.children.length > 0 ? 'true' : undefined}
174
+ aria-expanded={activeSubmenuKey === item.key}
175
+ class={cn(
176
+ 'flex w-full cursor-default select-none items-center rounded-sm px-2.5 py-1.5 text-sm outline-none transition-colors text-left',
177
+ item.disabled
178
+ ? 'pointer-events-none opacity-50'
179
+ : item.danger
180
+ ? 'text-destructive hover:bg-destructive/10 focus:bg-destructive/10'
181
+ : 'hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground'
182
+ )}
183
+ onclick={(e) => handleItemClick(item, e)}
184
+ >
185
+ {#if item.icon}
186
+ <span class="mr-2 inline-flex h-4 w-4 shrink-0 items-center justify-center">
187
+ {#if typeof item.icon === 'string'}
188
+ <span class="text-xs">{item.icon}</span>
189
+ {:else}
190
+ {@render item.icon()}
191
+ {/if}
192
+ </span>
193
+ {/if}
194
+
195
+ <span class="flex-1 truncate">{item.label}</span>
196
+
197
+ {#if item.shortcut}
198
+ <span class="ml-auto pl-3 font-mono text-xs text-muted-foreground">
199
+ {item.shortcut}
200
+ </span>
201
+ {/if}
202
+
203
+ {#if item.children && item.children.length > 0}
204
+ <svg
205
+ class="ml-auto h-3.5 w-3.5 shrink-0 text-muted-foreground"
206
+ viewBox="0 0 24 24"
207
+ fill="none"
208
+ stroke="currentColor"
209
+ stroke-width="2"
210
+ stroke-linecap="round"
211
+ stroke-linejoin="round"
212
+ >
213
+ <path d="m9 18 6-6-6-6" />
214
+ </svg>
215
+ {/if}
216
+ </button>
217
+
218
+ <!-- Nested Submenu -->
219
+ {#if item.children && item.children.length > 0 && activeSubmenuKey === item.key}
220
+ <div
221
+ class="absolute left-full top-0 ml-1 min-w-[160px] rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md outline-none animate-in fade-in-80 zoom-in-95"
222
+ role="menu"
223
+ tabindex="-1"
224
+ >
225
+ {#each item.children as subItem (subItem.key)}
226
+ {#if subItem.divider}
227
+ <div class="-mx-1 my-1 h-px bg-border" role="separator"></div>
228
+ {:else}
229
+ <button
230
+ type="button"
231
+ role="menuitem"
232
+ disabled={subItem.disabled}
233
+ aria-disabled={subItem.disabled}
234
+ class={cn(
235
+ 'flex w-full cursor-default select-none items-center rounded-sm px-2.5 py-1.5 text-sm outline-none transition-colors text-left',
236
+ subItem.disabled
237
+ ? 'pointer-events-none opacity-50'
238
+ : subItem.danger
239
+ ? 'text-destructive hover:bg-destructive/10 focus:bg-destructive/10'
240
+ : 'hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground'
241
+ )}
242
+ onclick={(e) => handleSubItemClick(subItem, e)}
243
+ >
244
+ {#if subItem.icon}
245
+ <span class="mr-2 inline-flex h-4 w-4 shrink-0 items-center justify-center">
246
+ {#if typeof subItem.icon === 'string'}
247
+ <span class="text-xs">{subItem.icon}</span>
248
+ {:else}
249
+ {@render subItem.icon()}
250
+ {/if}
251
+ </span>
252
+ {/if}
253
+ <span class="flex-1 truncate">{subItem.label}</span>
254
+ {#if subItem.shortcut}
255
+ <span class="ml-auto pl-3 font-mono text-xs text-muted-foreground">
256
+ {subItem.shortcut}
257
+ </span>
258
+ {/if}
259
+ </button>
260
+ {/if}
261
+ {/each}
262
+ </div>
263
+ {/if}
264
+ </div>
265
+ {/if}
266
+ {/each}
267
+ </div>
268
+ {/if}
@@ -0,0 +1,22 @@
1
+ import { type Snippet } from 'svelte';
2
+ export interface ContextMenuItem {
3
+ key: string;
4
+ label: string;
5
+ icon?: string | Snippet;
6
+ shortcut?: string;
7
+ disabled?: boolean;
8
+ danger?: boolean;
9
+ divider?: boolean;
10
+ children?: ContextMenuItem[];
11
+ onclick?: (item: ContextMenuItem) => void;
12
+ }
13
+ export interface ContextMenuProps {
14
+ items: ContextMenuItem[];
15
+ disabled?: boolean;
16
+ class?: string;
17
+ onselect?: (item: ContextMenuItem) => void;
18
+ children?: Snippet;
19
+ }
20
+ declare const ContextMenu: import("svelte").Component<ContextMenuProps, {}, "">;
21
+ type ContextMenu = ReturnType<typeof ContextMenu>;
22
+ export default ContextMenu;