@signosoft/signpad-js 0.0.1 → 0.2.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/index.d.ts CHANGED
@@ -2,142 +2,875 @@ import { CSSResult } from 'lit';
2
2
  import { LitElement } from 'lit';
3
3
  import { TemplateResult } from 'lit-html';
4
4
 
5
+ declare class ButtonManager {
6
+ private component;
7
+ constructor(component: SignosoftSignpad);
8
+ /**
9
+ * Clears the current signature on device and UI, then dispatches SIGN_CLEAR.
10
+ * @returns Resolves when the clear flow completes.
11
+ */
12
+ handleClear(): Promise<void>;
13
+ /**
14
+ * Finalizes the signature, dispatches SIGN_OK, and returns captured data.
15
+ * @returns Captured signature payload from the driver.
16
+ */
17
+ handleOk(): Promise<any>;
18
+ /**
19
+ * Cancels the signature without collecting data, dispatches SIGN_CANCEL.
20
+ * @returns Resolves when the cancel flow completes.
21
+ */
22
+ handleCancel(): Promise<void>;
23
+ /**
24
+ * Starts a new signing session and transitions to the ready state.
25
+ * @param drawingOptions - Optional line thickness and color settings.
26
+ * @returns Resolves when the session is ready.
27
+ */
28
+ startSigning(drawingOptions?: IDrawingOptions): Promise<void>;
29
+ /**
30
+ * Stops the current signing session and returns captured data.
31
+ * @returns Captured signature payload from the driver.
32
+ */
33
+ stopSigning(): Promise<any>;
34
+ /**
35
+ * Shared template for OK, Cancel, and Clear actions.
36
+ * @param processingState - State used while processing the action.
37
+ * @param actionLogic - Action-specific logic to execute.
38
+ * @returns Result produced by the action logic.
39
+ */
40
+ private executeAction;
41
+ /**
42
+ * Resolves the ready state based on current connection type.
43
+ * @returns The next ready state (physical or fallback).
44
+ */
45
+ private getReadyState;
46
+ /**
47
+ * Handles post-action flow (state transition or auto-restart).
48
+ * @returns Resolves after state transition or auto-restart completes.
49
+ */
50
+ private finalizePostAction;
51
+ /**
52
+ * Fallback handling when startSigning cannot proceed.
53
+ */
54
+ private handleStartSigningError;
55
+ /**
56
+ * Centralized error handling for button actions.
57
+ * @param message - Human-readable error description.
58
+ * @param error - Original error instance.
59
+ */
60
+ private handleError;
61
+ }
62
+
5
63
  /**
6
- * `signosoft-signpad` web component for capturing signatures using a tablet or mouse.
7
- * This component orchestrates signature capture, manages canvas drawing,
8
- * handles mouse input fallback, and provides custom events for application integration.
9
- *
10
- * @element signosoft-signpad
11
- *
12
- * @fires sign-pen - Fired on every pen movement (Wacom or mouse) with `penData` in `event.detail`.
13
- * @fires sign-clear - Fired when the signature is cleared (via internal UI button, tablet event, or by calling the public `clear()` method).
14
- * @fires sign-cancel - Fired when the signature process is cancelled (via internal UI button, tablet event, or by calling the public `cancel()` method).
15
- * @fires sign-ok - Fired when the 'OK' action is completed (via internal UI button, tablet event, or by calling the public `ok()` method).
16
- * @fires sign-disconnect - Fired if the tablet unexpectedly disconnects.
17
- * @fires sign-error - Fired when an error occurs during connection or initialization.
64
+ * `CanvasManager` handles all low-level drawing operations on the HTMLCanvasElement.
65
+ * It manages DPI scaling for high-resolution displays, stroke interpolation,
66
+ * pressure-sensitive line thickness, and canvas state.
67
+ */
68
+ declare class CanvasManager {
69
+ /** @private The target canvas element */
70
+ private canvas;
71
+ /** @private The 2D rendering context */
72
+ private ctx;
73
+ /** @private The last point processed in the current stroke */
74
+ private lastDrawPoint;
75
+ /** @private The active configuration for line styles */
76
+ private currentDrawingOptions;
77
+ /**
78
+ * Creates an instance of CanvasManager.
79
+ * @param canvas - The HTMLCanvasElement to draw on.
80
+ * @param initialDrawingOptions - Configuration for colors and line thickness.
81
+ */
82
+ constructor(canvas: HTMLCanvasElement, initialDrawingOptions?: IDrawingOptions);
83
+ /**
84
+ * Returns the currently active drawing configuration.
85
+ * @returns A copy of the current drawing options.
86
+ */
87
+ get drawingOptions(): IDrawingOptions;
88
+ /**
89
+ * Updates the drawing options and immediately applies them to the context.
90
+ * @param options - The new drawing configuration.
91
+ */
92
+ updateDrawingOptions(options: IDrawingOptions): void;
93
+ /**
94
+ * Draws a line segment between the previous point and the current pen data.
95
+ * Handles coordinate normalization and pressure-based thickness.
96
+ * @param penData - Data containing coordinates (0-1), pressure, and contact status.
97
+ */
98
+ drawSegment(penData: IPenData): void;
99
+ /**
100
+ * Wipes the canvas clean and resets the drawing state.
101
+ */
102
+ clear(): void;
103
+ /**
104
+ * Adjusts the canvas internal resolution to match high-DPI (Retina) screens.
105
+ * Prevents signatures from appearing blurry.
106
+ * @private
107
+ */
108
+ private configureCanvasForDPI;
109
+ /**
110
+ * Applies line caps, joins, and composite operations to the rendering context.
111
+ * @param options - The style options to apply.
112
+ * @private
113
+ */
114
+ private applyDrawingStyles;
115
+ }
116
+
117
+ /**
118
+ * Handles config-driven side effects for the signpad component.
119
+ */
120
+ declare class ConfigManager {
121
+ private component;
122
+ private configEventHandlers;
123
+ /**
124
+ * @param component - The host SignosoftSignpad instance.
125
+ */
126
+ constructor(component: SignosoftSignpad);
127
+ /**
128
+ * Applies config-driven side effects (localization, drawing, callbacks).
129
+ * @param prevConfig - Optional previous config for diffing.
130
+ */
131
+ apply(prevConfig?: SignpadConfig): void;
132
+ /**
133
+ * Applies custom CSS variables from the config to the host element.
134
+ */
135
+ applyCssVariables(): void;
136
+ /**
137
+ * Returns resolved UI visibility options with defaults applied.
138
+ * @returns UI visibility options.
139
+ */
140
+ getUiVisibilityOptions(): IUIVisibilityOptions;
141
+ /**
142
+ * Returns resolved drawing options with defaults applied.
143
+ * @returns Drawing options for the canvas.
144
+ */
145
+ getDrawingOptions(): IDrawingOptions;
146
+ /**
147
+ * Applies localization updates when language configuration changes.
148
+ * @param prevConfig - Previous configuration.
149
+ * @param currentConfig - Current configuration.
150
+ */
151
+ private applyLocalization;
152
+ /**
153
+ * Applies drawing option updates when configuration changes.
154
+ * @param prevConfig - Previous configuration.
155
+ * @param currentConfig - Current configuration.
156
+ */
157
+ private applyDrawingOptions;
158
+ /**
159
+ * Syncs config-provided event handlers with component listeners,
160
+ * adding, replacing, or removing them as needed.
161
+ * @param config - Current signpad configuration.
162
+ */
163
+ private syncConfigEventHandlers;
164
+ /**
165
+ * Removes all config-based event handlers from the component.
166
+ */
167
+ private clearConfigEventHandlers;
168
+ }
169
+
170
+ /**
171
+ * `ConnectionManager` handles the lifecycle of the signature pad connection.
172
+ * It manages driver initialization, license authentication, device handshaking,
173
+ * and event forwarding from the physical driver to the component.
174
+ */
175
+ declare class ConnectionManager {
176
+ /** @private Reference to the parent component */
177
+ private component;
178
+ /** @private The low-level driver instance */
179
+ private sigLayer;
180
+ /** @private Debug counter for callback registrations */
181
+ private debugCallbackRegistrationCount;
182
+ /** @private Offscreen canvas used to capture driver input without direct UI interference */
183
+ private offscreenDrawingCanvas;
184
+ /** @private Cached device info from the last successful connect */
185
+ private cachedDeviceInfo;
186
+ /** @private Tracks SignatureLayer initialization state */
187
+ private sigLayerInitialized;
188
+ /** @private License server endpoint */
189
+ private licenseServerUrl;
190
+ /** @private Timestamp of the last pen event dispatch */
191
+ private lastPenDispatchTime;
192
+ /** @private Buffered pen data for throttling */
193
+ private penDataToDispatch;
194
+ /** @private Minimum delay between pen events (approx 60fps) */
195
+ private throttleDelayMs;
196
+ private fetchShimInstalled;
197
+ /**
198
+ * @param component - The host SignosoftSignpad instance.
199
+ */
200
+ constructor(component: SignosoftSignpad);
201
+ /**
202
+ * Initiates the connection process to a physical device or a mouse fallback.
203
+ *
204
+ * @param autoConnect - If true, attempts to connect without showing a device selection dialog.
205
+ * @param allowFallback - If true, enables mouse/pointer input if no physical device is found.
206
+ * @returns A promise resolving to true if connection (or fallback) was successful.
207
+ */
208
+ connect(autoConnect?: boolean, allowFallback?: boolean): Promise<boolean>;
209
+ /**
210
+ * Terminates the connection with the device and cleans up the driver instance.
211
+ * @returns Resolves when disconnection completes.
212
+ */
213
+ disconnect(): Promise<void>;
214
+ /**
215
+ * Returns true when a SignatureLayer instance exists.
216
+ * @returns True if the driver instance is available.
217
+ */
218
+ hasSignatureLayer(): boolean;
219
+ /**
220
+ * Returns the device info from SignatureLayer if available.
221
+ * @returns Device info or null if unavailable.
222
+ */
223
+ getDeviceInfo(): Promise<any | null>;
224
+ /**
225
+ * Returns true if the SignatureLayer reports an active connection.
226
+ * @returns True if a device is connected.
227
+ */
228
+ isDeviceConnected(): boolean;
229
+ /**
230
+ * Returns true if the SignatureLayer is in signing mode.
231
+ * @returns True if a signing session is active.
232
+ */
233
+ isSigningActive(): boolean;
234
+ /**
235
+ * Starts a signing session on the provided canvas.
236
+ * @param canvasElement - Optional canvas reference.
237
+ * @param drawingOptions - Optional drawing options.
238
+ * @returns A promise resolving to true if the session started successfully.
239
+ */
240
+ startSigning(canvas: HTMLCanvasElement, drawingOptions?: IDrawingOptions): Promise<boolean>;
241
+ /**
242
+ * Stops the current signing session if active.
243
+ * @returns Signature data if available.
244
+ */
245
+ stopSigning(): Promise<any>;
246
+ /**
247
+ * Clears the signature on the device if a signing session is active.
248
+ * Silently does nothing if no session is active.
249
+ * @returns Resolves when the clear completes.
250
+ */
251
+ clearSignature(): Promise<void>;
252
+ /**
253
+ * Instantiates the SignatureLayer if it doesn't exist and attaches listeners.
254
+ * @returns Resolves when the driver is ready.
255
+ */
256
+ private ensureSignatureLayer;
257
+ /**
258
+ * Configures driver event listeners (OK, Clear, Cancel, Pen events).
259
+ * @returns void
260
+ */
261
+ private setupCallbacks;
262
+ /**
263
+ * Throttles pen data dispatches to optimize event bus performance.
264
+ * @param data - The IPenData received from the driver.
265
+ */
266
+ private runThrottledPenDispatch;
267
+ /**
268
+ * Fetches a lease from the license server and initializes the driver.
269
+ * @returns Resolves when the driver is initialized.
270
+ */
271
+ private initializeTabletWithLicense;
272
+ /**
273
+ * Installs a fetch shim to resolve lib assets when bundled.
274
+ */
275
+ private installLibAsset;
276
+ isFallback(deviceInfo: any | null, isDeviceConnected: boolean, includeDisconnected: boolean): boolean;
277
+ /**
278
+ * Normalizes device info to always include deviceName.
279
+ * @param deviceInfo - Raw device info.
280
+ * @returns Normalized device info or null.
281
+ */
282
+ private normalizeDeviceInfo;
283
+ }
284
+
285
+ export declare enum DeviceStatusText {
286
+ NOT_CONNECTED = "NOT_CONNECTED",
287
+ CONNECTED = "CONNECTED",
288
+ CONNECTING = "CONNECTING",
289
+ MOUSE = "MOUSE",
290
+ CONNECTED_UNKNOWN = "CONNECTED_UNKNOWN_DEVICE"
291
+ }
292
+
293
+ export declare interface IActionHandlers {
294
+ handleOk?: () => any | Promise<any>;
295
+ handleClear?: () => any | Promise<any>;
296
+ handleCancel?: () => any | Promise<any>;
297
+ }
298
+
299
+ export declare interface IAutoconnectOptions {
300
+ autoConnect?: boolean;
301
+ autoConnectOnPlugIn?: boolean;
302
+ autoRestartSigningAfterAction?: boolean;
303
+ }
304
+
305
+ export declare interface IDrawingOptions {
306
+ minWidth?: number;
307
+ maxWidth?: number;
308
+ color?: string;
309
+ }
310
+
311
+ export declare interface IDriverInfo {
312
+ name: string;
313
+ ready: boolean;
314
+ aspectRatio: number;
315
+ isCanvasStyleTablet: boolean;
316
+ supportedCommands: string[];
317
+ }
318
+
319
+ export declare interface IEventCallbacks {
320
+ onConnect?: (event: CustomEvent<{
321
+ deviceInfo: any;
322
+ }>) => void;
323
+ onDisconnect?: (event: CustomEvent<void>) => void;
324
+ onPen?: (event: CustomEvent<PenData>) => void;
325
+ onOk?: (event: CustomEvent<void>) => void;
326
+ onClear?: (event: CustomEvent<void>) => void;
327
+ onCancel?: (event: CustomEvent<void>) => void;
328
+ onError?: (event: CustomEvent<Error>) => void;
329
+ }
330
+
331
+ export declare interface ILanguageOptions {
332
+ lang?: LanguageCode;
333
+ langPath?: string;
334
+ translations?: ITranslationSet | Record<string, ITranslationSet>;
335
+ }
336
+
337
+ export declare type IPenData = {
338
+ relativeX: number;
339
+ relativeY: number;
340
+ absoluteX?: number;
341
+ absoluteY?: number;
342
+ pressure?: number;
343
+ timestamp?: number;
344
+ inContact: boolean;
345
+ [key: string]: any;
346
+ };
347
+
348
+ export declare interface IPenDataCallback {
349
+ (penData: PenData): void;
350
+ }
351
+
352
+ export declare interface ITranslationSet {
353
+ [key: string]: string;
354
+ }
355
+
356
+ export declare interface IUIVisibilityOptions {
357
+ topBarVisible?: boolean;
358
+ topBarClearButtonVisible?: boolean;
359
+ bottomBarVisible?: boolean;
360
+ okButtonVisible?: boolean;
361
+ clearButtonVisible?: boolean;
362
+ cancelButtonVisible?: boolean;
363
+ canvasLineVisible?: boolean;
364
+ deviceStatusTextVisible?: boolean;
365
+ additionalTextVisible?: boolean;
366
+ }
367
+
368
+ export declare type LanguageCode = "en" | "cs" | "pt" | (string & {});
369
+
370
+ /**
371
+ * Manages localization for the signpad component.
18
372
  *
19
- * @property {string} licenseKey - Backend license key for the signature driver.
20
- * @property {boolean} topBarVisible - Controls the visibility of the top action bar.
21
- * @property {boolean} bottomBarVisible - Controls the visibility of the bottom action bar with OK, Clear, Cancel buttons.
22
- * @property {boolean} okButtonVisible - Controls the visibility of the 'OK' button.
23
- * @property {boolean} clearButtonVisible - Controls the visibility of the 'Clear' button.
24
- * @property {boolean} cancelButtonVisible - Controls the visibility of the 'Cancel' button.
25
- * @property {boolean} canvasLineVisible - Controls the visibility of the line on the canvas.
26
- * @property {boolean} deviceStateTextVisible - Controls the visibility of the device state text.
27
- * @property {string | null} [customDeviceStateText] - Optional custom text to display for the device state, overriding the default.
28
- * @property {number} minThickness - Minimum pen stroke thickness in pixels.
29
- * @property {number} maxThickness - Maximum pen stroke thickness in pixels (at full pressure).
30
- * @property {string} penColor - Pen stroke color (CSS color, e.g., '#000000' or 'red').
31
- * @property {Record<string, string>} [customCssVariables] - An object containing CSS custom property names as keys and their values as strings. These will be applied directly to the component's host element for styling customization.
32
- * @property {function} [OkButton] - Optional callback function (async or sync) to execute when the public `ok()` method is called, either internally or externally. It runs after the component's internal processing.
33
- * @property {function} [ClearButton] - Optional callback function (async or sync) to execute when the public `clear()` method is called, either internally or externally. It runs after the component's internal processing.
34
- * @property {function} [CancelButton] - Optional callback function (async or sync) to execute when the public `cancel()` method is called, either internally or externally. It runs after the component's internal processing.
35
- * @property {string | null} [canvasAdditionalText] - Optional additional text to display in the canvas footer. If null or empty, a default text will be shown. Default behavior is "Sign area with mouse or pen" when disconnected/error, and "Sign with [device name]" when connected.
373
+ * This manager supports:
374
+ * 1. Built-in translations (English as default fallback).
375
+ * 2. External translation overrides via remote JSON files.
376
+ * 3. Dynamic parameter interpolation in strings.
377
+ */
378
+ declare class LocalizationManager {
379
+ /** @private Reference to the parent component to trigger updates */
380
+ private component;
381
+ /** @private The currently active translation dictionary */
382
+ private translations;
383
+ /** @private The ISO code of the currently loaded language */
384
+ private currentLang;
385
+ /** @private The last used path for external translations */
386
+ private currentPath;
387
+ /**
388
+ * @param component - The LitElement instance that uses this manager.
389
+ */
390
+ constructor(component: LitElement);
391
+ /**
392
+ * Translates a key based on the loaded dictionary.
393
+ * Supports parameter interpolation using the `{key}` syntax.
394
+ *
395
+ * @param key - The translation key (e.g., "CONNECT_DEVICE").
396
+ * @param params - Key-value pairs to replace placeholders in the string.
397
+ * @returns The translated string, or the raw key if no translation exists.
398
+ */
399
+ t(key: string, params?: Record<string, string>): string;
400
+ /**
401
+ * Loads and merges translations for the specified language.
402
+ *
403
+ * Strategy:
404
+ * 1. Check for redundancy: If lang and path haven't changed, skip.
405
+ * 2. Baseline: Start with built-in translations (merged with English as fallback).
406
+ * 3. Fetch: If a path is provided, attempt to fetch an external JSON file.
407
+ * 4. Merge: External translations override built-in ones.
408
+ *
409
+ * @param langCode - ISO language code (e.g., 'en', 'cs', 'de').
410
+ * @param basePath - Optional path/URL to fetch external translation files.
411
+ * @param inlineTranslations - Optional inline translations to apply.
412
+ * @returns Resolves when translations are loaded and applied.
413
+ */
414
+ loadLanguage(langCode: string, basePath?: string, inlineTranslations?: ITranslationSet | Record<string, ITranslationSet>): Promise<void>;
415
+ /**
416
+ * Determines the initial translation set.
417
+ * If the language is built-in, it merges it with English to ensure no missing keys.
418
+ *
419
+ * @param langCode - The target language code.
420
+ * @returns Baseline translations for the language.
421
+ */
422
+ private getBaselineTranslations;
423
+ /**
424
+ * Resolves inline translations for the requested language, if provided.
425
+ * @param langCode - The target language code.
426
+ * @param inline - Inline translation map or set.
427
+ * @returns Inline translations for the language if found.
428
+ */
429
+ private resolveInlineTranslations;
430
+ /**
431
+ * Constructs the full URL for the translation JSON file.
432
+ *
433
+ * @param langCode - The language code.
434
+ * @param basePath - The directory path.
435
+ * @returns Resolved translation file URL.
436
+ */
437
+ private constructUrl;
438
+ }
439
+
440
+ /**
441
+ * `MouseManager` handles mouse interactions on a canvas element and converts them
442
+ * into standardized `IPenData`. This serves as a fallback mechanism for
443
+ * signature capture when a physical signature tablet is not available.
444
+ */
445
+ declare class MouseManager {
446
+ /** @private */
447
+ private canvas;
448
+ /** @private */
449
+ private onPenData;
450
+ /** @private */
451
+ private isDrawing;
452
+ /** @private */
453
+ private sequenceCounter;
454
+ /** @private */
455
+ private sessionStartTime;
456
+ /** @private Debug counter for listener registrations */
457
+ private debugListenerRegistrationCount;
458
+ /** @private */
459
+ private listenersAttached;
460
+ private boundHandleMouseDown;
461
+ private boundHandleMouseMove;
462
+ private boundHandleMouseUp;
463
+ private boundHandleMouseLeave;
464
+ /**
465
+ * Creates an instance of MouseManager.
466
+ * @param canvas - The HTMLCanvasElement to attach mouse listeners to.
467
+ * @param onPenDataCallback - The callback function that receives generated IPenData.
468
+ */
469
+ constructor(canvas: HTMLCanvasElement, onPenDataCallback: IPenDataCallback);
470
+ /**
471
+ * Returns whether the user is currently in the middle of a drawing stroke.
472
+ */
473
+ get isCurrentlyDrawing(): boolean;
474
+ /**
475
+ * Attaches mouse event listeners to the canvas to enable signature capture.
476
+ */
477
+ addListeners(): void;
478
+ /**
479
+ * Removes mouse event listeners from the canvas and stops active drawing.
480
+ */
481
+ removeListeners(): void;
482
+ /**
483
+ * Returns true if mouse listeners are currently attached.
484
+ */
485
+ areListenersAttached(): boolean;
486
+ /**
487
+ * Resets the internal session state, including sequence counters and start time.
488
+ */
489
+ resetSession(): void;
490
+ /**
491
+ * Handles the 'mousedown' event: starts a stroke and initializes the session time.
492
+ * @private
493
+ */
494
+ private handleMouseDown;
495
+ /**
496
+ * Handles the 'mousemove' event: continues the stroke if mouse is down.
497
+ * @private
498
+ */
499
+ private handleMouseMove;
500
+ /**
501
+ * Handles the 'mouseup' event: ends the stroke.
502
+ * @private
503
+ */
504
+ private handleMouseUp;
505
+ /**
506
+ * Handles the 'mouseleave' event: ends the stroke if the mouse leaves the canvas area.
507
+ * @private
508
+ */
509
+ private handleMouseLeave;
510
+ /**
511
+ * Core logic to transform a MouseEvent into IPenData.
512
+ * @param event - The raw browser MouseEvent.
513
+ * @param inContact - Whether the "pen" (mouse button) is touching the surface.
514
+ * @private
515
+ */
516
+ private processMouseEvent;
517
+ /**
518
+ * Converts absolute mouse coordinates into a normalized 0-1 range relative to canvas size.
519
+ * @private
520
+ */
521
+ private getNormalizedCoordinates;
522
+ /**
523
+ * Calculates the seconds elapsed since the start of the signature session.
524
+ * @private
525
+ */
526
+ private timestampToSeconds;
527
+ }
528
+
529
+ /**
530
+ * SignosoftSignpad Web Component.
531
+ * A professional signature capture component supporting physical tablets and mouse fallback.
36
532
  */
37
533
  export declare class SignosoftSignpad extends LitElement {
38
- licenseKey: string;
39
- canvasAdditionalText: string | null;
40
- topBarVisible: boolean;
41
- bottomBarVisible: boolean;
42
- okButtonVisible: boolean;
43
- clearButtonVisible: boolean;
44
- cancelButtonVisible: boolean;
45
- canvasLineVisible: boolean;
46
- deviceStateTextVisible: boolean;
47
- customDeviceStateText: string | null;
48
- minThickness: number;
49
- maxThickness: number;
50
- penColor: string;
51
- OkButton?: () => Promise<void>;
52
- ClearButton?: () => Promise<void>;
53
- CancelButton?: () => Promise<void>;
54
- customCssVariables: Record<string, string>;
534
+ #private;
535
+ /**
536
+ * Main configuration object for the signpad.
537
+ * Settable from outside via property binding.
538
+ */
539
+ config: SignpadConfig;
540
+ /**
541
+ * Reference to the internal canvas element.
542
+ * @private
543
+ */
55
544
  canvasRef: HTMLCanvasElement;
56
- private _deviceStateText;
57
- private _isConnected;
58
- private _hasStartedDrawing;
59
- private _isDisconnectingIntentionally;
60
- private licenseServerUrl;
61
- private sigLayer;
62
- private canvasPainter;
63
- private mouseInputHandler;
64
- private offscreenDrawingCanvas;
545
+ /** Current state of the signpad machine. */
546
+ get currentState(): SignpadState;
547
+ /** Current status message key for localization. */
548
+ get statusMessage(): string;
549
+ /** Boolean flag indicating if the user has started drawing. */
550
+ get hasStartedDrawing(): boolean;
551
+ /** Text representation of the current device status. */
552
+ get deviceStatusText(): string;
553
+ setCurrentState(value: SignpadState): void;
554
+ setStatusMessage(value: string): void;
555
+ setHasStartedDrawing(value: boolean): void;
556
+ setDeviceStatusText(value: string): void;
557
+ canvasManager: CanvasManager | null;
558
+ mouseManager: MouseManager | null;
559
+ connectionManager: ConnectionManager;
560
+ stateManager: StateManager;
561
+ buttonManager: ButtonManager;
562
+ localizationManager: LocalizationManager;
563
+ configManager: ConfigManager;
564
+ webHIDAPI: any;
65
565
  static styles: CSSResult[];
66
- constructor();
67
566
  /**
68
- * Invoked once after the component's first render.
69
- * Initializes CanvasPainter and MouseInputHandler, then starts driver initialization.
567
+ * Lit lifecycle: Invoked after the element's DOM has been updated the first time.
568
+ * Initializes managers and handles auto-connection logic.
569
+ * @protected
570
+ * @returns Resolves when initialization completes.
70
571
  */
71
- protected firstUpdated(): void;
572
+ protected firstUpdated(): Promise<void>;
72
573
  /**
73
- * Invoked before the component's render method is called.
74
- * Updates CanvasPainter's drawing options if related properties have changed.
574
+ * Lit lifecycle: Invoked when the element's properties change.
575
+ * @param changedProperties - Map of changed properties.
576
+ * @protected
75
577
  */
76
578
  protected willUpdate(changedProperties: Map<string | number | symbol, unknown>): void;
77
579
  /**
78
- * Invoked after the component's render method is called and its DOM has been updated.
79
- * Applies custom CSS variables from the `customCssVariables` property to the host element.
580
+ * Lit lifecycle: Invoked after every update.
581
+ * @protected
80
582
  */
81
583
  protected updated(changedProperties: Map<PropertyKey, unknown>): void;
82
584
  /**
83
- * Prepares the SignatureLayer instance.
84
- * This method now creates a new instance if `sigLayer` is null.
85
- */
86
- private prepareSignatureLayer;
87
- /**
88
- * Sets up internal callbacks for the SignatureLayer instance.
89
- * These callbacks ensure that actions from the Wacom tablet (e.g., OK, Clear, Cancel)
90
- * trigger the corresponding public methods of this component.
585
+ * Component constructor.
586
+ * Initializes all sub-managers.
91
587
  */
92
- private setupCallbacks;
588
+ constructor();
93
589
  /**
94
- * Dispatches a custom event from this web component.
95
- * @param name - The name of the custom event to dispatch.
96
- * @param [detail] - Optional data to include with the event, accessible via `event.detail`.
590
+ * Dispatches a custom event from the component.
591
+ * @param name - The name of the event.
592
+ * @param detail - Optional data payload for the event.
593
+ * @returns void
97
594
  */
98
- private dispatch;
595
+ dispatch(name: string, detail?: any): void;
99
596
  /**
100
- * Connects to the signature tablet.
101
- * This involves obtaining a license, initializing the signature layer,
102
- * connecting to the device, and starting the signing process.
103
- * This method strategically passes an offscreen canvas or the actual visible canvas to SignatureLayer
104
- * based on the detected device, to prevent unwanted internal drawing by SignatureLayer.
105
- * This method can be invoked externally (e.g., from a "Connect Signpad" button).
106
- * @param autoConnect - If true, attempts to automatically select the first available device.
107
- * @returns True if successfully connected and signing started, false otherwise.
597
+ * Attempts to establish a connection with a signature tablet.
598
+ * @param autoConnect - If true, tries to connect without showing a device picker.
599
+ * @param allowFallback - If true, enables mouse/touch signing if no device is found.
600
+ * @returns A promise resolving to true if connection (or fallback) succeeded.
108
601
  */
109
- connectTablet(autoConnect?: boolean): Promise<boolean>;
602
+ connect(autoConnect?: boolean, allowFallback?: boolean): Promise<boolean>;
110
603
  /**
111
- * Disconnects from the signature tablet and resets its state.
112
- * This method can be invoked externally.
113
- * @returns A promise that resolves when the tablet is disconnected.
604
+ * Closes the active tablet connection and cleans up the state.
605
+ * @returns A promise that resolves when disconnection is complete.
114
606
  */
115
- disconnectTablet(): Promise<void>;
607
+ disconnect(): Promise<void>;
116
608
  /**
117
- * Clears the current signature from both the tablet's screen and the component's canvas.
118
- * Invokes the optional `ClearButton` external callback (if provided)
119
- * and then dispatches a 'sign-clear' custom event.
120
- * This method can be invoked externally or internally (e.g., from a "Clear" button).
609
+ * Clears the signature from both the UI canvas and the physical device screen.
610
+ * @returns Resolves when the clear flow completes.
121
611
  */
122
612
  clear(): Promise<void>;
123
613
  /**
124
- * Handles the 'OK' action, typically stopping the signing process and preparing the signature for submission.
125
- * If an `OkButton` callback function is provided via properties, it will be executed.
126
- * Afterwards, a `sign-ok` custom event is dispatched.
127
- * This method can be invoked externally or internally (e.g., from an "OK" button).
614
+ * Finalizes the signature session (OK action).
615
+ * @returns Captured signature payload from the driver.
128
616
  */
129
- ok(): Promise<void>;
617
+ ok(): Promise<any>;
130
618
  /**
131
- * Handles the 'Cancel' action, which typically clears any drawn signature and stops the signing process.
132
- * If a `CancelButton` callback function is provided via properties, it will be executed.
133
- * Finally, a `sign-cancel` custom event is dispatched.
134
- * This method can be invoked externally or internally (e.g., from a "Cancel" button).
619
+ * Aborts the current signature session (Cancel action).
620
+ * @returns Resolves when the cancel flow completes.
135
621
  */
136
622
  cancel(): Promise<void>;
137
623
  /**
138
- * Renders the component's HTML template.
624
+ * Programmatically starts a new signing session.
625
+ * @param drawingOptions - Optional settings for line thickness and color.
626
+ * @returns Resolves when the session is ready.
627
+ */
628
+ startSigning(drawingOptions?: IDrawingOptions): Promise<void>;
629
+ /**
630
+ * Programmatically stops the current signing session.
631
+ * @returns Resolves when the session stops.
632
+ */
633
+ stopSigning(): Promise<void>;
634
+ /**
635
+ * Resets the UI canvas and internal drawing flags.
636
+ * @returns void
637
+ */
638
+ resetDrawingState(): void;
639
+ /**
640
+ * Lit lifecycle: Invoked when the component is removed from the document's DOM.
641
+ * Performs necessary cleanup of listeners and connections.
642
+ * @returns void
643
+ */
644
+ disconnectedCallback(): void;
645
+ /**
646
+ * Attaches WebHID API event listeners for device connection and disconnection.
647
+ * @private
648
+ * @returns void
649
+ */
650
+ private addWebHIDListeners;
651
+ /**
652
+ * Removes WebHID API event listeners.
653
+ * @private
654
+ * @returns void
655
+ */
656
+ private removeWebHIDListeners;
657
+ /**
658
+ * Handler for HID device connection.
659
+ * @private
660
+ * @returns void
661
+ */
662
+ private handleHIDConnect;
663
+ /**
664
+ * Handler for HID device disconnection.
665
+ * @private
666
+ * @returns void
667
+ */
668
+ private handleHIDDisconnect;
669
+ /**
670
+ * Initializes the CanvasManager for rendering signature strokes.
671
+ * @private
672
+ * @returns void
673
+ */
674
+ private initializeCanvasManger;
675
+ /**
676
+ * Initializes the MouseManager for mouse and touch fallback.
677
+ * @private
678
+ * @returns void
679
+ */
680
+ private initializeMouseManager;
681
+ /**
682
+ * Renders the HTML template for the component.
683
+ * Uses Lit's html template literal.
684
+ * @returns Rendered template.
139
685
  */
140
686
  render(): TemplateResult<1>;
141
687
  }
142
688
 
689
+ export declare type SignosoftSignpadProps = {
690
+ config?: SignpadConfig;
691
+ class?: string;
692
+ id?: string;
693
+ style?: string | Record<string, string>;
694
+ key?: string | number;
695
+ ref?: any;
696
+ children?: any;
697
+ };
698
+
699
+ export declare interface SignpadConfig {
700
+ licenseKey?: string;
701
+ languageOptions?: ILanguageOptions;
702
+ autoconnectOptions?: IAutoconnectOptions;
703
+ uiVisibilityOptions?: IUIVisibilityOptions;
704
+ canvasAndDrawigOptions?: IDrawingOptions;
705
+ actionHandlers?: IActionHandlers;
706
+ eventCallbacks?: IEventCallbacks;
707
+ customCssVariables?: Record<string, string>;
708
+ }
709
+
710
+ export declare enum SignpadEventType {
711
+ SIGN_PEN = "sign-pen",
712
+ SIGN_OK = "sign-ok",
713
+ SIGN_CLEAR = "sign-clear",
714
+ SIGN_CANCEL = "sign-cancel",
715
+ SIGN_ERROR = "sign-error",
716
+ SIGN_CONNECT = "sign-connect",
717
+ SIGN_DISCONNECT = "sign-disconnect"
718
+ }
719
+
720
+ export declare enum SignpadMessage {
721
+ AUTO_CONNECTING = "AUTO_CONNECTING",
722
+ CONNECTING_TO_DEVICE = "CONNECTING_TO_DEVICE",
723
+ DISCONNECTING_DEVICE = "DISCONNECTING_DEVICE",
724
+ COMPONENT_INITIALIZED = "COMPONENT_INITIALIZED",
725
+ TEXT_START_SIGNING = "TEXT_START_SIGNING",
726
+ TEXT_SIGN_WITH_PHYSICAL = "TEXT_SIGN_WITH_PHYSICAL",
727
+ TEXT_SIGN_WITH_MOUSE = "TEXT_SIGN_WITH_MOUSE",
728
+ TEXT_SIGN_GENERIC = "TEXT_SIGN_GENERIC",
729
+ TEXT_SIGNING_WITH_DEVICE = "TEXT_SIGNING_WITH_DEVICE",
730
+ NO_DEVICE_FOUND = "NO_DEVICE_FOUND",
731
+ CONNECTION_ERROR = "CONNECTION_ERROR",
732
+ ERROR_DISCONNECTION = "ERROR_DISCONNECTION",
733
+ ERROR_INSTANTIATING_DRIVER = "ERROR_INSTANTIATING_DRIVER",
734
+ SIGNPAD_DISCONNECTED = "SIGNPAD_DISCONNECTED",
735
+ DEVICE_UNEXPECTEDLY_DISCONNECTED = "DEVICE_UNEXPECTEDLY_DISCONNECTED",
736
+ SIGN_SUCCESSFUL = "SIGN_SUCCESSFUL",
737
+ SIGN_CANCELLED = "SIGN_CANCELLED",
738
+ SIGN_CLEARED = "SIGN_CLEARED",
739
+ MISSING_LICENSE_KEY = "MISSING_LICENSE_KEY",
740
+ READY_TO_CONNECT = "READY_TO_CONNECT",
741
+ SIGNPAD_DETECTED = "SIGNPAD_DETECTED",
742
+ NO_LICENSE_KEY = "NO_LICENSE_KEY"
743
+ }
744
+
745
+ export declare enum SignpadState {
746
+ INITIAL = "initial",
747
+ DISCONNECTED = "disconnected",
748
+ FINISHED = "finished",
749
+ CONNECTING = "connecting",
750
+ WAITING_FOR_DEVICE_SELECTION = "waiting_for_device_selection",
751
+ CONNECTED_PHYSICAL = "connected_physical",
752
+ CONNECTED_MOUSE_FALLBACK = "connected_mouse_fallback",
753
+ SIGNING_ACTIVE = "signing_active",
754
+ PROCESSING_OK = "processing_ok",
755
+ PROCESSING_CLEAR = "processing_clear",
756
+ PROCESSING_CANCEL = "processing_cancel",
757
+ DISCONNECTING = "disconnecting",
758
+ ERROR = "error"
759
+ }
760
+
761
+ export declare enum SignpadUI {
762
+ OK = "OK",
763
+ CLEAR = "CLEAR",
764
+ CANCEL = "CANCEL",
765
+ CLEAR_SIGNATURE = "CLEAR_SIGNATURE",
766
+ DISCONNECT = "DISCONNECT",
767
+ CONNECT_SIGNPAD = "CONNECT_SIGNPAD"
768
+ }
769
+
770
+ /**
771
+ * Manages the finite state machine and UI logic for the Signpad component.
772
+ * It handles state transitions, side effects (like adding/removing listeners),
773
+ * and provides computed properties for the UI (button states, visibility, etc.).
774
+ */
775
+ declare class StateManager {
776
+ /**
777
+ * Reference to the parent component.
778
+ * @private
779
+ */
780
+ private component;
781
+ /**
782
+ * @param component - The host SignosoftSignpad instance.
783
+ */
784
+ constructor(component: SignosoftSignpad);
785
+ /**
786
+ * Returns the localization key or device name for the current status.
787
+ * @returns Localization key or device name.
788
+ */
789
+ get deviceStatusKey(): string;
790
+ /**
791
+ * Returns the current status message key.
792
+ * @returns Status message key.
793
+ */
794
+ get statusMessageKey(): string;
795
+ /**
796
+ * Computes the localization key for instructions based on current state.
797
+ * Returns null if custom additionalText is provided by the user.
798
+ * @returns Localization key for additional text.
799
+ */
800
+ get additionalTextKey(): string;
801
+ /**
802
+ * Returns true if the component is in any connected state (Physical or Fallback).
803
+ * @returns True when connected or signing.
804
+ */
805
+ get isConnected(): boolean;
806
+ /**
807
+ * Returns true if the component is performing an asynchronous operation.
808
+ * @returns True when busy.
809
+ */
810
+ get isBusy(): boolean;
811
+ /**
812
+ * Returns true if the component is in an ERROR state.
813
+ * @returns True when in error state.
814
+ */
815
+ get isError(): boolean;
816
+ /**
817
+ * Logic for disabling primary action buttons (OK, Clear, Cancel).
818
+ * Buttons are disabled if not connected, if no drawing has occurred, or if busy.
819
+ * @returns True if action buttons should be disabled.
820
+ */
821
+ get actionButtonsDisabled(): boolean;
822
+ /**
823
+ * Logic for disabling the Connect button.
824
+ * @returns True if the connect button should be disabled.
825
+ */
826
+ get connectButtonDisabled(): boolean;
827
+ /**
828
+ * Logic for disabling the Disconnect button.
829
+ * @returns True if the disconnect button should be disabled.
830
+ */
831
+ get disconnectButtonDisabled(): boolean;
832
+ /**
833
+ * Transitions the component to a new state and triggers side effects.
834
+ *
835
+ * @param newState - The target SignpadState.
836
+ * @param messageKey - An optional localization key for status messages.
837
+ * @param error - Optional error object if transitioning to an ERROR state.
838
+ * @returns void
839
+ */
840
+ transitionTo(newState: SignpadState, messageKey?: string, error?: Error): void;
841
+ /**
842
+ * Updates the internal drawing flag. Triggers a UI update if the value changes.
843
+ * @param started - Boolean indicating if the user has started drawing.
844
+ */
845
+ setDrawingStarted(started: boolean): void;
846
+ /**
847
+ * Handles side effects triggered by state transitions, such as
848
+ * initializing mouse listeners or clearing the canvas.
849
+ * @param newState - The state being transitioned to.
850
+ * @param oldState - The previous state.
851
+ * @private
852
+ */
853
+ private handleSideEffects;
854
+ }
855
+
143
856
  export { }
857
+
858
+
859
+ declare global {
860
+ interface HTMLElementTagNameMap {
861
+ "signosoft-signpad": SignosoftSignpad;
862
+ }
863
+ namespace JSX {
864
+ interface IntrinsicElements {
865
+ "signosoft-signpad": SignosoftSignpadProps;
866
+ }
867
+ }
868
+
869
+ namespace React {
870
+ namespace JSX {
871
+ interface IntrinsicElements {
872
+ "signosoft-signpad": SignosoftSignpadProps;
873
+ }
874
+ }
875
+ }
876
+ }