@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.
- package/dist/app.css +139 -0
- package/dist/app.theme.css +139 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/Barcode.svelte +219 -0
- package/dist/components/Barcode.svelte.d.ts +15 -0
- package/dist/components/ContextMenu.svelte +268 -0
- package/dist/components/ContextMenu.svelte.d.ts +22 -0
- package/dist/components/JsonViewer.svelte +323 -0
- package/dist/components/JsonViewer.svelte.d.ts +20 -0
- package/dist/components/KpiCard.svelte +250 -0
- package/dist/components/KpiCard.svelte.d.ts +44 -0
- package/dist/components/NumberRoll.svelte +149 -0
- package/dist/components/NumberRoll.svelte.d.ts +17 -0
- package/dist/components/OtpInput.svelte +209 -0
- package/dist/components/OtpInput.svelte.d.ts +17 -0
- package/dist/components/RecordCompareModal.svelte +428 -0
- package/dist/components/RecordCompareModal.svelte.d.ts +42 -0
- package/dist/components/ResultPage.svelte +166 -0
- package/dist/components/ResultPage.svelte.d.ts +28 -0
- package/dist/components/SignaturePad.svelte +230 -66
- package/dist/components/SignaturePad.svelte.d.ts +6 -5
- package/dist/components/Tour.svelte +71 -13
- package/dist/components/Tour.svelte.d.ts +1 -1
- package/dist/components/TrendIndicator.svelte +21 -13
- package/dist/components/TrendIndicator.svelte.d.ts +4 -2
- package/dist/components/UnsavedChangesGuard.svelte +138 -0
- package/dist/components/UnsavedChangesGuard.svelte.d.ts +32 -0
- package/dist/components/VirtualList.svelte +165 -0
- package/dist/components/VirtualList.svelte.d.ts +43 -0
- package/dist/components/WatermarkContainer.svelte +196 -0
- package/dist/components/WatermarkContainer.svelte.d.ts +20 -0
- package/dist/components/useUnsavedChanges.d.svelte.ts +1 -0
- package/dist/components/useUnsavedChanges.svelte.d.ts +22 -0
- package/dist/components/useUnsavedChanges.svelte.js +105 -0
- package/dist/index.d.ts +30 -35
- package/dist/index.js +18 -2
- package/package.json +1 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from 'svelte';
|
|
3
3
|
import { Button } from './ui/button/index.js';
|
|
4
|
-
import { RotateCcw, Trash2, Check, Download } from '@lucide/svelte';
|
|
4
|
+
import { RotateCcw, RotateCw, Trash2, Check, Download, FileCode } from '@lucide/svelte';
|
|
5
5
|
import { cn } from '../utils.js';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
export interface SignaturePadProps {
|
|
8
8
|
value?: string;
|
|
9
9
|
width?: number;
|
|
10
10
|
height?: number;
|
|
11
11
|
strokeColor?: string;
|
|
12
12
|
strokeWidth?: number;
|
|
13
13
|
disabled?: boolean;
|
|
14
|
+
withTimestamp?: boolean;
|
|
14
15
|
onchange?: (dataUrl: string) => void;
|
|
15
16
|
onsave?: (dataUrl: string) => void;
|
|
16
17
|
class?: string;
|
|
@@ -23,22 +24,26 @@
|
|
|
23
24
|
strokeColor = 'currentColor',
|
|
24
25
|
strokeWidth = 2.5,
|
|
25
26
|
disabled = false,
|
|
27
|
+
withTimestamp = false,
|
|
26
28
|
onchange,
|
|
27
29
|
onsave,
|
|
28
30
|
class: className = '',
|
|
29
|
-
}:
|
|
31
|
+
}: SignaturePadProps = $props();
|
|
30
32
|
|
|
31
33
|
let canvasEl = $state<HTMLCanvasElement | null>(null);
|
|
32
34
|
let isDrawing = $state(false);
|
|
33
35
|
let isEmpty = $state(true);
|
|
34
|
-
let
|
|
36
|
+
let undoHistory = $state<ImageData[]>([]);
|
|
37
|
+
let redoHistory = $state<ImageData[]>([]);
|
|
35
38
|
|
|
36
39
|
interface Point {
|
|
37
40
|
x: number;
|
|
38
41
|
y: number;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
let
|
|
44
|
+
let currentStroke = $state<Point[]>([]);
|
|
45
|
+
let allStrokes = $state<Point[][]>([]);
|
|
46
|
+
let redoStrokes = $state<Point[][]>([]);
|
|
42
47
|
|
|
43
48
|
function getCanvasPos(e: MouseEvent | TouchEvent): Point | null {
|
|
44
49
|
if (!canvasEl) return null;
|
|
@@ -64,18 +69,38 @@
|
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
function setupContext(ctx: CanvasRenderingContext2D) {
|
|
73
|
+
ctx.strokeStyle = strokeColor === 'currentColor'
|
|
74
|
+
? (canvasEl ? getComputedStyle(canvasEl).color || 'rgb(24, 24, 27)' : 'rgb(24, 24, 27)')
|
|
75
|
+
: strokeColor;
|
|
76
|
+
ctx.lineWidth = strokeWidth;
|
|
77
|
+
ctx.lineCap = 'round';
|
|
78
|
+
ctx.lineJoin = 'round';
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
function startDrawing(e: MouseEvent | TouchEvent) {
|
|
68
82
|
if (disabled || !canvasEl) return;
|
|
69
83
|
const pos = getCanvasPos(e);
|
|
70
84
|
if (!pos) return;
|
|
71
85
|
|
|
72
86
|
const ctx = canvasEl.getContext('2d');
|
|
73
|
-
if (ctx)
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
if (!ctx) return;
|
|
88
|
+
|
|
89
|
+
// Save state before this new stroke for undo
|
|
90
|
+
const snapshot = ctx.getImageData(0, 0, canvasEl.width, canvasEl.height);
|
|
91
|
+
undoHistory = [...undoHistory, snapshot];
|
|
92
|
+
redoHistory = [];
|
|
93
|
+
redoStrokes = [];
|
|
76
94
|
|
|
77
95
|
isDrawing = true;
|
|
78
|
-
|
|
96
|
+
isEmpty = false;
|
|
97
|
+
currentStroke = [pos];
|
|
98
|
+
|
|
99
|
+
setupContext(ctx);
|
|
100
|
+
ctx.beginPath();
|
|
101
|
+
ctx.arc(pos.x, pos.y, strokeWidth / 2, 0, Math.PI * 2);
|
|
102
|
+
ctx.fillStyle = ctx.strokeStyle;
|
|
103
|
+
ctx.fill();
|
|
79
104
|
}
|
|
80
105
|
|
|
81
106
|
function draw(e: MouseEvent | TouchEvent) {
|
|
@@ -83,50 +108,45 @@
|
|
|
83
108
|
const pos = getCanvasPos(e);
|
|
84
109
|
if (!pos) return;
|
|
85
110
|
|
|
86
|
-
points.push(pos);
|
|
87
111
|
const ctx = canvasEl.getContext('2d');
|
|
88
112
|
if (!ctx) return;
|
|
89
113
|
|
|
90
|
-
|
|
91
|
-
ctx
|
|
92
|
-
|
|
93
|
-
|
|
114
|
+
currentStroke.push(pos);
|
|
115
|
+
setupContext(ctx);
|
|
116
|
+
|
|
117
|
+
// Quadratic Bezier curve smoothing for natural calligraphy stroke
|
|
118
|
+
if (currentStroke.length >= 3) {
|
|
119
|
+
const p0 = currentStroke[currentStroke.length - 3];
|
|
120
|
+
const p1 = currentStroke[currentStroke.length - 2];
|
|
121
|
+
const p2 = currentStroke[currentStroke.length - 1];
|
|
122
|
+
|
|
123
|
+
if (p0 && p1 && p2) {
|
|
124
|
+
const mid1 = { x: (p0.x + p1.x) / 2, y: (p0.y + p1.y) / 2 };
|
|
125
|
+
const mid2 = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
|
|
94
126
|
|
|
95
|
-
if (points.length < 3) {
|
|
96
|
-
const b = points[0];
|
|
97
|
-
if (b) {
|
|
98
127
|
ctx.beginPath();
|
|
99
|
-
ctx.
|
|
100
|
-
ctx.
|
|
101
|
-
ctx.
|
|
102
|
-
ctx.closePath();
|
|
128
|
+
ctx.moveTo(mid1.x, mid1.y);
|
|
129
|
+
ctx.quadraticCurveTo(p1.x, p1.y, mid2.x, mid2.y);
|
|
130
|
+
ctx.stroke();
|
|
103
131
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
ctx.moveTo(p0.x, p0.y);
|
|
112
|
-
}
|
|
113
|
-
for (let i = 1; i < points.length - 1; i++) {
|
|
114
|
-
const pi = points[i];
|
|
115
|
-
const pi1 = points[i + 1];
|
|
116
|
-
if (pi && pi1) {
|
|
117
|
-
const xc = (pi.x + pi1.x) / 2;
|
|
118
|
-
const yc = (pi.y + pi1.y) / 2;
|
|
119
|
-
ctx.quadraticCurveTo(pi.x, pi.y, xc, yc);
|
|
132
|
+
} else if (currentStroke.length === 2) {
|
|
133
|
+
const p0 = currentStroke[0];
|
|
134
|
+
if (p0) {
|
|
135
|
+
ctx.beginPath();
|
|
136
|
+
ctx.moveTo(p0.x, p0.y);
|
|
137
|
+
ctx.lineTo(pos.x, pos.y);
|
|
138
|
+
ctx.stroke();
|
|
120
139
|
}
|
|
121
140
|
}
|
|
122
|
-
ctx.stroke();
|
|
123
|
-
isEmpty = false;
|
|
124
141
|
}
|
|
125
142
|
|
|
126
143
|
function stopDrawing() {
|
|
127
144
|
if (!isDrawing || !canvasEl) return;
|
|
128
145
|
isDrawing = false;
|
|
129
|
-
|
|
146
|
+
if (currentStroke.length > 0) {
|
|
147
|
+
allStrokes = [...allStrokes, [...currentStroke]];
|
|
148
|
+
currentStroke = [];
|
|
149
|
+
}
|
|
130
150
|
|
|
131
151
|
const dataUrl = canvasEl.toDataURL('image/png');
|
|
132
152
|
value = dataUrl;
|
|
@@ -137,55 +157,170 @@
|
|
|
137
157
|
if (!canvasEl) return;
|
|
138
158
|
const ctx = canvasEl.getContext('2d');
|
|
139
159
|
if (!ctx) return;
|
|
160
|
+
|
|
161
|
+
const snapshot = ctx.getImageData(0, 0, canvasEl.width, canvasEl.height);
|
|
162
|
+
undoHistory = [...undoHistory, snapshot];
|
|
163
|
+
redoHistory = [];
|
|
164
|
+
redoStrokes = [];
|
|
165
|
+
allStrokes = [];
|
|
166
|
+
currentStroke = [];
|
|
167
|
+
|
|
140
168
|
ctx.clearRect(0, 0, canvasEl.width, canvasEl.height);
|
|
141
|
-
history = [];
|
|
142
169
|
isEmpty = true;
|
|
143
170
|
value = '';
|
|
144
171
|
onchange?.('');
|
|
145
172
|
}
|
|
146
173
|
|
|
147
|
-
export function toDataURL(type = 'image/png'): string {
|
|
148
|
-
return canvasEl ? canvasEl.toDataURL(type) : '';
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function toSVG(): string {
|
|
152
|
-
if (!canvasEl) return '';
|
|
153
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"><image href="${toDataURL()}" width="${width}" height="${height}" /></svg>`;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function getIsEmpty(): boolean {
|
|
157
|
-
return isEmpty;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
174
|
export function undo() {
|
|
161
|
-
if (!canvasEl ||
|
|
175
|
+
if (!canvasEl || undoHistory.length === 0) return;
|
|
162
176
|
const ctx = canvasEl.getContext('2d');
|
|
163
177
|
if (!ctx) return;
|
|
164
|
-
|
|
165
|
-
|
|
178
|
+
|
|
179
|
+
const currentFrame = ctx.getImageData(0, 0, canvasEl.width, canvasEl.height);
|
|
180
|
+
redoHistory = [...redoHistory, currentFrame];
|
|
181
|
+
|
|
182
|
+
if (allStrokes.length > 0) {
|
|
183
|
+
const lastStroke = allStrokes[allStrokes.length - 1];
|
|
184
|
+
if (lastStroke) {
|
|
185
|
+
redoStrokes = [...redoStrokes, lastStroke];
|
|
186
|
+
}
|
|
187
|
+
allStrokes = allStrokes.slice(0, -1);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const previous = undoHistory[undoHistory.length - 1];
|
|
191
|
+
undoHistory = undoHistory.slice(0, -1);
|
|
166
192
|
if (previous) {
|
|
167
193
|
ctx.putImageData(previous, 0, 0);
|
|
168
194
|
}
|
|
169
|
-
|
|
195
|
+
|
|
196
|
+
isEmpty = undoHistory.length === 0 && allStrokes.length === 0;
|
|
170
197
|
const dataUrl = isEmpty ? '' : canvasEl.toDataURL('image/png');
|
|
171
198
|
value = dataUrl;
|
|
172
199
|
onchange?.(dataUrl);
|
|
173
200
|
}
|
|
174
201
|
|
|
202
|
+
export function redo() {
|
|
203
|
+
if (!canvasEl || redoHistory.length === 0) return;
|
|
204
|
+
const ctx = canvasEl.getContext('2d');
|
|
205
|
+
if (!ctx) return;
|
|
206
|
+
|
|
207
|
+
const currentFrame = ctx.getImageData(0, 0, canvasEl.width, canvasEl.height);
|
|
208
|
+
undoHistory = [...undoHistory, currentFrame];
|
|
209
|
+
|
|
210
|
+
const nextFrame = redoHistory[redoHistory.length - 1];
|
|
211
|
+
redoHistory = redoHistory.slice(0, -1);
|
|
212
|
+
if (nextFrame) {
|
|
213
|
+
ctx.putImageData(nextFrame, 0, 0);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (redoStrokes.length > 0) {
|
|
217
|
+
const nextStroke = redoStrokes[redoStrokes.length - 1];
|
|
218
|
+
if (nextStroke) {
|
|
219
|
+
allStrokes = [...allStrokes, nextStroke];
|
|
220
|
+
}
|
|
221
|
+
redoStrokes = redoStrokes.slice(0, -1);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
isEmpty = false;
|
|
225
|
+
const dataUrl = canvasEl.toDataURL('image/png');
|
|
226
|
+
value = dataUrl;
|
|
227
|
+
onchange?.(dataUrl);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function toSVG(): string {
|
|
231
|
+
const strokeHex = strokeColor === 'currentColor' ? 'currentColor' : strokeColor;
|
|
232
|
+
let paths = '';
|
|
233
|
+
|
|
234
|
+
for (const stroke of allStrokes) {
|
|
235
|
+
if (stroke.length === 0) continue;
|
|
236
|
+
const first = stroke[0];
|
|
237
|
+
if (!first) continue;
|
|
238
|
+
|
|
239
|
+
if (stroke.length === 1) {
|
|
240
|
+
paths += `<circle cx="${first.x.toFixed(1)}" cy="${first.y.toFixed(1)}" r="${(strokeWidth / 2).toFixed(1)}" fill="${strokeHex}" />\n`;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
let d = `M ${first.x.toFixed(1)} ${first.y.toFixed(1)}`;
|
|
244
|
+
if (stroke.length === 2) {
|
|
245
|
+
const second = stroke[1];
|
|
246
|
+
if (second) {
|
|
247
|
+
d += ` L ${second.x.toFixed(1)} ${second.y.toFixed(1)}`;
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
for (let i = 1; i < stroke.length - 1; i++) {
|
|
251
|
+
const p1 = stroke[i];
|
|
252
|
+
const p2 = stroke[i + 1];
|
|
253
|
+
if (p1 && p2) {
|
|
254
|
+
const mid = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
|
|
255
|
+
d += ` Q ${p1.x.toFixed(1)} ${p1.y.toFixed(1)}, ${mid.x.toFixed(1)} ${mid.y.toFixed(1)}`;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const last = stroke[stroke.length - 1];
|
|
259
|
+
if (last) {
|
|
260
|
+
d += ` L ${last.x.toFixed(1)} ${last.y.toFixed(1)}`;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
paths += `<path d="${d}" fill="none" stroke="${strokeHex}" stroke-width="${strokeWidth}" stroke-linecap="round" stroke-linejoin="round" />\n`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let timestampSvg = '';
|
|
267
|
+
if (withTimestamp) {
|
|
268
|
+
const ts = new Date().toISOString().replace('T', ' ').slice(0, 19) + ' UTC';
|
|
269
|
+
timestampSvg = `<text x="${width - 12}" y="${height - 10}" text-anchor="end" font-family="monospace" font-size="10" fill="currentColor" opacity="0.65">Signed: ${ts} (Verified)</text>\n`;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">\n${paths}${timestampSvg}</svg>`;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function toDataURL(type = 'image/png'): string {
|
|
276
|
+
if (!canvasEl || isEmpty) return '';
|
|
277
|
+
if (!withTimestamp) {
|
|
278
|
+
return canvasEl.toDataURL(type);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Embed tamper-evident verification timestamp watermark
|
|
282
|
+
const offscreen = document.createElement('canvas');
|
|
283
|
+
offscreen.width = canvasEl.width;
|
|
284
|
+
offscreen.height = canvasEl.height;
|
|
285
|
+
const ctx = offscreen.getContext('2d');
|
|
286
|
+
if (!ctx) return canvasEl.toDataURL(type);
|
|
287
|
+
|
|
288
|
+
ctx.drawImage(canvasEl, 0, 0);
|
|
289
|
+
ctx.font = '10px monospace';
|
|
290
|
+
ctx.fillStyle = 'rgba(113, 113, 122, 0.8)';
|
|
291
|
+
ctx.textAlign = 'right';
|
|
292
|
+
const ts = new Date().toISOString().replace('T', ' ').slice(0, 19) + ' UTC';
|
|
293
|
+
ctx.fillText(`Signed: ${ts} (Verified)`, offscreen.width - 12, offscreen.height - 10);
|
|
294
|
+
|
|
295
|
+
return offscreen.toDataURL(type);
|
|
296
|
+
}
|
|
297
|
+
|
|
175
298
|
function handleSave() {
|
|
176
299
|
if (isEmpty || !canvasEl) return;
|
|
177
|
-
const dataUrl =
|
|
300
|
+
const dataUrl = toDataURL('image/png');
|
|
178
301
|
onsave?.(dataUrl);
|
|
179
302
|
}
|
|
180
303
|
|
|
181
|
-
function
|
|
304
|
+
function handleDownloadPNG() {
|
|
182
305
|
if (isEmpty || !canvasEl) return;
|
|
183
306
|
const a = document.createElement('a');
|
|
184
|
-
a.href =
|
|
307
|
+
a.href = toDataURL('image/png');
|
|
185
308
|
a.download = `signature_${Date.now()}.png`;
|
|
186
309
|
a.click();
|
|
187
310
|
}
|
|
188
311
|
|
|
312
|
+
function handleDownloadSVG() {
|
|
313
|
+
if (isEmpty) return;
|
|
314
|
+
const svgContent = toSVG();
|
|
315
|
+
const blob = new Blob([svgContent], { type: 'image/svg+xml;charset=utf-8' });
|
|
316
|
+
const url = URL.createObjectURL(blob);
|
|
317
|
+
const a = document.createElement('a');
|
|
318
|
+
a.href = url;
|
|
319
|
+
a.download = `signature_${Date.now()}.svg`;
|
|
320
|
+
a.click();
|
|
321
|
+
URL.revokeObjectURL(url);
|
|
322
|
+
}
|
|
323
|
+
|
|
189
324
|
onMount(() => {
|
|
190
325
|
if (canvasEl && value) {
|
|
191
326
|
const img = new Image();
|
|
@@ -203,8 +338,14 @@
|
|
|
203
338
|
|
|
204
339
|
<div data-svadmin-component="SignaturePad" class={cn('rounded-xl border border-border bg-card p-4 shadow-xs text-xs space-y-3', className)}>
|
|
205
340
|
<div class="flex items-center justify-between gap-2 pb-2 border-b border-border/60">
|
|
206
|
-
<div class="font-semibold text-foreground">
|
|
207
|
-
|
|
341
|
+
<div class="font-semibold text-foreground flex items-center gap-2">
|
|
342
|
+
<span>Electronic Signature</span>
|
|
343
|
+
<span class="text-muted-foreground font-normal">(Sign inside the box)</span>
|
|
344
|
+
{#if withTimestamp}
|
|
345
|
+
<span class="font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground">
|
|
346
|
+
Timestamped
|
|
347
|
+
</span>
|
|
348
|
+
{/if}
|
|
208
349
|
</div>
|
|
209
350
|
|
|
210
351
|
<div class="flex items-center gap-1.5">
|
|
@@ -212,13 +353,24 @@
|
|
|
212
353
|
variant="ghost"
|
|
213
354
|
size="sm"
|
|
214
355
|
class="h-7 text-xs gap-1 text-muted-foreground hover:text-foreground"
|
|
215
|
-
disabled={
|
|
356
|
+
disabled={undoHistory.length === 0 || disabled}
|
|
216
357
|
onclick={undo}
|
|
217
358
|
>
|
|
218
359
|
<RotateCcw class="h-3 w-3" />
|
|
219
360
|
Undo
|
|
220
361
|
</Button>
|
|
221
362
|
|
|
363
|
+
<Button
|
|
364
|
+
variant="ghost"
|
|
365
|
+
size="sm"
|
|
366
|
+
class="h-7 text-xs gap-1 text-muted-foreground hover:text-foreground"
|
|
367
|
+
disabled={redoHistory.length === 0 || disabled}
|
|
368
|
+
onclick={redo}
|
|
369
|
+
>
|
|
370
|
+
<RotateCw class="h-3 w-3" />
|
|
371
|
+
Redo
|
|
372
|
+
</Button>
|
|
373
|
+
|
|
222
374
|
<Button
|
|
223
375
|
variant="ghost"
|
|
224
376
|
size="sm"
|
|
@@ -230,6 +382,18 @@
|
|
|
230
382
|
Clear
|
|
231
383
|
</Button>
|
|
232
384
|
|
|
385
|
+
<Button
|
|
386
|
+
variant="outline"
|
|
387
|
+
size="sm"
|
|
388
|
+
class="h-7 text-xs gap-1 text-muted-foreground hover:text-foreground"
|
|
389
|
+
disabled={isEmpty || disabled}
|
|
390
|
+
onclick={handleDownloadSVG}
|
|
391
|
+
title="Export Vector SVG"
|
|
392
|
+
>
|
|
393
|
+
<FileCode class="h-3 w-3" />
|
|
394
|
+
SVG
|
|
395
|
+
</Button>
|
|
396
|
+
|
|
233
397
|
{#if onsave}
|
|
234
398
|
<Button
|
|
235
399
|
size="sm"
|
|
@@ -244,9 +408,9 @@
|
|
|
244
408
|
<Button
|
|
245
409
|
variant="outline"
|
|
246
410
|
size="sm"
|
|
247
|
-
class="h-7 text-xs gap-1"
|
|
411
|
+
class="h-7 text-xs gap-1 text-muted-foreground hover:text-foreground"
|
|
248
412
|
disabled={isEmpty || disabled}
|
|
249
|
-
onclick={
|
|
413
|
+
onclick={handleDownloadPNG}
|
|
250
414
|
>
|
|
251
415
|
<Download class="h-3 w-3" />
|
|
252
416
|
Download
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
interface
|
|
1
|
+
export interface SignaturePadProps {
|
|
2
2
|
value?: string;
|
|
3
3
|
width?: number;
|
|
4
4
|
height?: number;
|
|
5
5
|
strokeColor?: string;
|
|
6
6
|
strokeWidth?: number;
|
|
7
7
|
disabled?: boolean;
|
|
8
|
+
withTimestamp?: boolean;
|
|
8
9
|
onchange?: (dataUrl: string) => void;
|
|
9
10
|
onsave?: (dataUrl: string) => void;
|
|
10
11
|
class?: string;
|
|
11
12
|
}
|
|
12
|
-
declare const SignaturePad: import("svelte").Component<
|
|
13
|
+
declare const SignaturePad: import("svelte").Component<SignaturePadProps, {
|
|
13
14
|
clear: () => void;
|
|
14
|
-
toDataURL: (type?: string) => string;
|
|
15
|
-
toSVG: () => string;
|
|
16
|
-
getIsEmpty: () => boolean;
|
|
17
15
|
undo: () => void;
|
|
16
|
+
redo: () => void;
|
|
17
|
+
toSVG: () => string;
|
|
18
|
+
toDataURL: (type?: string) => string;
|
|
18
19
|
}, "value">;
|
|
19
20
|
type SignaturePad = ReturnType<typeof SignaturePad>;
|
|
20
21
|
export default SignaturePad;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
target?: string;
|
|
8
8
|
title: string;
|
|
9
9
|
description?: string;
|
|
10
|
-
placement?: 'top' | 'bottom' | 'left' | 'right';
|
|
10
|
+
placement?: 'top' | 'bottom' | 'left' | 'right' | 'auto';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
@@ -46,6 +46,8 @@
|
|
|
46
46
|
|
|
47
47
|
let panel = $state<HTMLElement | null>(null);
|
|
48
48
|
let rect = $state<{ top: number; left: number; width: number; height: number } | null>(null);
|
|
49
|
+
const maskId = `svadmin-tour-mask-${Math.random().toString(36).slice(2, 8)}`;
|
|
50
|
+
|
|
49
51
|
const step = $derived(steps[Math.max(0, Math.min(current, steps.length - 1))]);
|
|
50
52
|
const last = $derived(current >= steps.length - 1);
|
|
51
53
|
|
|
@@ -69,9 +71,20 @@
|
|
|
69
71
|
const width = Math.min(320, window.innerWidth - 24);
|
|
70
72
|
let top = rect.top + rect.height + gap;
|
|
71
73
|
let left = Math.max(12, Math.min(rect.left, window.innerWidth - width - 12));
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
74
|
+
const placement = step?.placement ?? 'auto';
|
|
75
|
+
|
|
76
|
+
if (placement === 'top') {
|
|
77
|
+
top = rect.top - gap - 160;
|
|
78
|
+
} else if (placement === 'left') {
|
|
79
|
+
left = Math.max(12, rect.left - width - gap);
|
|
80
|
+
top = rect.top;
|
|
81
|
+
} else if (placement === 'right') {
|
|
82
|
+
left = Math.min(window.innerWidth - width - 12, rect.left + rect.width + gap);
|
|
83
|
+
top = rect.top;
|
|
84
|
+
} else if (placement === 'bottom') {
|
|
85
|
+
top = rect.top + rect.height + gap;
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
const maxTop = Math.max(12, window.innerHeight - 200);
|
|
76
89
|
top = Math.max(12, Math.min(top, maxTop));
|
|
77
90
|
return `top:${top}px;left:${left}px;width:${width}px`;
|
|
@@ -132,6 +145,17 @@
|
|
|
132
145
|
}
|
|
133
146
|
}
|
|
134
147
|
|
|
148
|
+
$effect(() => {
|
|
149
|
+
if (storageKey && typeof localStorage !== 'undefined') {
|
|
150
|
+
try {
|
|
151
|
+
if (localStorage.getItem(storageKey) === 'true') {
|
|
152
|
+
open = false;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
} catch { /* ignore */ }
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
135
159
|
$effect(() => {
|
|
136
160
|
if (!open) return;
|
|
137
161
|
const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
@@ -156,17 +180,45 @@
|
|
|
156
180
|
|
|
157
181
|
{#if open}
|
|
158
182
|
<div data-svadmin-component="TourGuide" data-targeted={rect ? 'true' : 'false'} class={cn('svadmin-tour', className)}>
|
|
183
|
+
<!-- Background dismissal trigger to block click-through -->
|
|
159
184
|
<button type="button" tabindex="-1" class="svadmin-tour__dismiss" aria-label={skipText} onclick={close}></button>
|
|
185
|
+
|
|
186
|
+
<!-- Pure SVG Viewport Cutout Mask for Target Element Spotlight -->
|
|
160
187
|
{#if rect}
|
|
188
|
+
<svg class="svadmin-tour__svg-mask fixed inset-0 w-full h-full pointer-events-none z-[61]" aria-hidden="true">
|
|
189
|
+
<defs>
|
|
190
|
+
<mask id={maskId}>
|
|
191
|
+
<rect x="0" y="0" width="100%" height="100%" fill="white" />
|
|
192
|
+
<rect
|
|
193
|
+
x={rect.left - 6}
|
|
194
|
+
y={rect.top - 6}
|
|
195
|
+
width={rect.width + 12}
|
|
196
|
+
height={rect.height + 12}
|
|
197
|
+
rx="8"
|
|
198
|
+
ry="8"
|
|
199
|
+
fill="black"
|
|
200
|
+
/>
|
|
201
|
+
</mask>
|
|
202
|
+
</defs>
|
|
203
|
+
<rect
|
|
204
|
+
x="0"
|
|
205
|
+
y="0"
|
|
206
|
+
width="100%"
|
|
207
|
+
height="100%"
|
|
208
|
+
fill="color-mix(in srgb, var(--foreground) 45%, transparent)"
|
|
209
|
+
mask="url(#{maskId})"
|
|
210
|
+
/>
|
|
211
|
+
</svg>
|
|
161
212
|
<div
|
|
162
213
|
class="svadmin-tour__spotlight"
|
|
163
214
|
aria-hidden="true"
|
|
164
|
-
style:top={`${rect.top -
|
|
165
|
-
style:left={`${rect.left -
|
|
166
|
-
style:width={`${rect.width +
|
|
167
|
-
style:height={`${rect.height +
|
|
215
|
+
style:top={`${rect.top - 6}px`}
|
|
216
|
+
style:left={`${rect.left - 6}px`}
|
|
217
|
+
style:width={`${rect.width + 12}px`}
|
|
218
|
+
style:height={`${rect.height + 12}px`}
|
|
168
219
|
></div>
|
|
169
220
|
{/if}
|
|
221
|
+
|
|
170
222
|
<div
|
|
171
223
|
bind:this={panel}
|
|
172
224
|
class="svadmin-tour__panel"
|
|
@@ -178,7 +230,12 @@
|
|
|
178
230
|
onkeydown={onKeydown}
|
|
179
231
|
>
|
|
180
232
|
<header class="svadmin-tour__header">
|
|
181
|
-
<
|
|
233
|
+
<div class="flex items-center justify-between gap-2">
|
|
234
|
+
<p class="svadmin-tour__eyebrow">{title} · {current + 1}/{steps.length}</p>
|
|
235
|
+
<span class="text-[11px] font-mono px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground">
|
|
236
|
+
{current + 1} / {steps.length}
|
|
237
|
+
</span>
|
|
238
|
+
</div>
|
|
182
239
|
<h2 id="svadmin-tour-title">{step?.title}</h2>
|
|
183
240
|
{#if step?.description}<p class="svadmin-tour__description">{step.description}</p>{/if}
|
|
184
241
|
</header>
|
|
@@ -198,17 +255,18 @@
|
|
|
198
255
|
|
|
199
256
|
<style>
|
|
200
257
|
.svadmin-tour__dismiss { position: fixed; inset: 0; z-index: 60; border: 0; background: transparent; cursor: default; }
|
|
201
|
-
.svadmin-tour[data-targeted='false'] .svadmin-tour__dismiss { background: color-mix(in srgb, var(--foreground)
|
|
258
|
+
.svadmin-tour[data-targeted='false'] .svadmin-tour__dismiss { background: color-mix(in srgb, var(--foreground) 38%, transparent); }
|
|
202
259
|
.svadmin-tour__spotlight {
|
|
203
260
|
position: fixed;
|
|
204
|
-
z-index:
|
|
261
|
+
z-index: 62;
|
|
205
262
|
border-radius: var(--radius-md);
|
|
206
|
-
box-shadow: 0 0 0
|
|
263
|
+
box-shadow: 0 0 0 2px var(--primary), 0 0 16px color-mix(in srgb, var(--primary) 35%, transparent);
|
|
207
264
|
pointer-events: none;
|
|
265
|
+
transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
208
266
|
}
|
|
209
267
|
.svadmin-tour__panel {
|
|
210
268
|
position: fixed;
|
|
211
|
-
z-index:
|
|
269
|
+
z-index: 63;
|
|
212
270
|
display: grid;
|
|
213
271
|
max-width: calc(100vw - 1.5rem);
|
|
214
272
|
gap: var(--svadmin-space-4);
|