webdrive 1.0.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.
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Placement options for the popover relative to the target element.
3
+ */
4
+ type Position = "top" | "right" | "bottom" | "left";
5
+ /**
6
+ * Alignment of the popover along the target element's axis.
7
+ */
8
+ type Alignment = "start" | "center" | "end";
9
+ /**
10
+ * Strategy to use when a target element is not immediately present in the DOM.
11
+ * - "skip": skips the step and advances to the next available step.
12
+ * - "stop": halts the tour safely.
13
+ * - "wait": observes DOM mutations until the element appears or timeout expires.
14
+ */
15
+ type MissingElementBehavior = "skip" | "stop" | "wait";
16
+ /**
17
+ * Step configuration interface for WebDrive.
18
+ */
19
+ interface WebDriveStep {
20
+ /** Target element selector or DOM HTMLElement */
21
+ element: string | HTMLElement;
22
+ /** Title displayed in the popover header */
23
+ title?: string;
24
+ /** Plain text description rendered inside the popover content */
25
+ description?: string;
26
+ /** Optional HTML content for rich formatting */
27
+ content?: string;
28
+ /** Preferred popover position relative to target */
29
+ position?: Position;
30
+ /** Popover alignment relative to target */
31
+ align?: Alignment;
32
+ /** Padding around the highlighted element in pixels */
33
+ padding?: number;
34
+ /** Distance between the popover and the highlighted target in pixels */
35
+ offset?: number;
36
+ /** Whether to show the Next / Finish button on this step */
37
+ showNextButton?: boolean;
38
+ /** Whether to show the Previous button on this step */
39
+ showPreviousButton?: boolean;
40
+ /** Whether to show the Close button on this step */
41
+ showCloseButton?: boolean;
42
+ /** Custom text for Next button on this step */
43
+ nextButtonText?: string;
44
+ /** Custom text for Previous button on this step */
45
+ previousButtonText?: string;
46
+ /** Custom text for Done/Finish button on this step */
47
+ doneButtonText?: string;
48
+ /** Custom text for Close button on this step */
49
+ closeButtonText?: string;
50
+ /** Callback invoked when entering this step */
51
+ onEnter?: () => void | Promise<void>;
52
+ /** Callback invoked when leaving this step */
53
+ onLeave?: () => void | Promise<void>;
54
+ /** Allows future extensibility without breaking the public API */
55
+ [key: string]: unknown;
56
+ }
57
+ /**
58
+ * Custom storage adapter interface for tour completion persistence.
59
+ */
60
+ interface WebDriveStorage {
61
+ getItem: (key: string) => string | null | Promise<string | null>;
62
+ setItem: (key: string, value: string) => void | Promise<void>;
63
+ removeItem: (key: string) => void | Promise<void>;
64
+ }
65
+ /**
66
+ * Global configuration options for WebDrive.
67
+ */
68
+ interface WebDriveOptions {
69
+ /** Unique ID for the tour (used for storage persistence) */
70
+ id?: string;
71
+ /** Sequence of tour steps */
72
+ steps: WebDriveStep[];
73
+ /** Automatically start the tour upon instantiation if not already completed */
74
+ autoStart?: boolean;
75
+ /** Show step counter progress indicator (e.g., "2 / 5") */
76
+ showProgress?: boolean;
77
+ /** Allow user to close the tour via close button or backdrop click */
78
+ allowClose?: boolean;
79
+ /** Animate transitions between steps */
80
+ animate?: boolean;
81
+ /** Smoothly scroll target elements into view */
82
+ smoothScroll?: boolean;
83
+ /** Display darkened backdrop overlay */
84
+ overlay?: boolean;
85
+ /** Opacity of the backdrop overlay (0.0 to 1.0) */
86
+ overlayOpacity?: number;
87
+ /** Color of the backdrop overlay (CSS color string) */
88
+ overlayColor?: string;
89
+ /** Custom base z-index for the tour overlay and popover */
90
+ zIndex?: number;
91
+ /** Default padding around highlighted elements in pixels */
92
+ stagePadding?: number;
93
+ /** Border radius for the highlighted cutout area in pixels */
94
+ stageRadius?: number;
95
+ /** Enable keyboard navigation (ArrowRight, ArrowLeft, Escape) */
96
+ keyboardNavigation?: boolean;
97
+ /** Close tour when pressing Escape key */
98
+ closeOnEscape?: boolean;
99
+ /** Show navigation buttons in popover footer */
100
+ showButtons?: boolean;
101
+ /** Text for Next button */
102
+ nextButtonText?: string;
103
+ /** Text for Previous button */
104
+ previousButtonText?: string;
105
+ /** Text for Done/Finish button */
106
+ doneButtonText?: string;
107
+ /** Text for Close button */
108
+ closeButtonText?: string;
109
+ /** Persist completed state in storage so tour doesn't repeat */
110
+ remember?: boolean;
111
+ /** Custom storage provider (defaults to window.localStorage with memory fallback) */
112
+ storage?: WebDriveStorage;
113
+ /** Behavior when a target element is not found */
114
+ missingElementBehavior?: MissingElementBehavior;
115
+ /** Maximum time in milliseconds to wait for a missing element if behavior is "wait" */
116
+ missingElementWaitTimeout?: number;
117
+ /** Custom renderer for progress text */
118
+ renderProgress?: (current: number, total: number) => string;
119
+ /** Callback invoked when the tour starts */
120
+ onStart?: () => void;
121
+ /** Callback invoked when moving to a new step */
122
+ onStepChange?: (step: WebDriveStep, index: number) => void;
123
+ /** Callback invoked when the tour completes the final step */
124
+ onComplete?: () => void;
125
+ /** Callback invoked when the tour is closed before completion or via close button */
126
+ onClose?: () => void;
127
+ /** Callback invoked when the tour is destroyed */
128
+ onDestroy?: () => void;
129
+ }
130
+ /**
131
+ * Event map for strongly typed WebDrive event emitter.
132
+ */
133
+ interface WebDriveEvents {
134
+ start: void;
135
+ stepChange: {
136
+ step: WebDriveStep;
137
+ index: number;
138
+ };
139
+ complete: void;
140
+ close: void;
141
+ destroy: void;
142
+ }
143
+ /**
144
+ * Result returned by the positioning calculation engine.
145
+ */
146
+ interface PopoverPositionResult {
147
+ top: number;
148
+ left: number;
149
+ placement: Position;
150
+ alignment: Alignment;
151
+ arrowTop?: number;
152
+ arrowLeft?: number;
153
+ arrowPlacement?: Position;
154
+ }
155
+ /**
156
+ * Parameters for the popover positioning calculation.
157
+ */
158
+ interface CalculatePositionParams {
159
+ targetRect: {
160
+ top: number;
161
+ left: number;
162
+ width: number;
163
+ height: number;
164
+ right?: number;
165
+ bottom?: number;
166
+ };
167
+ popoverRect: {
168
+ width: number;
169
+ height: number;
170
+ };
171
+ placement?: Position;
172
+ alignment?: Alignment;
173
+ offset?: number;
174
+ viewportPadding?: number;
175
+ arrowSize?: number;
176
+ viewportWidth?: number;
177
+ viewportHeight?: number;
178
+ }
179
+
180
+ declare class WebDrive {
181
+ private options;
182
+ private emitter;
183
+ private storage;
184
+ private controller;
185
+ constructor(options: WebDriveOptions);
186
+ private ensureController;
187
+ start(startIndex?: number): Promise<void>;
188
+ stop(): Promise<void>;
189
+ next(): Promise<void>;
190
+ previous(): Promise<void>;
191
+ goTo(index: number): Promise<void>;
192
+ refresh(): void;
193
+ destroy(): void;
194
+ isActive(): boolean;
195
+ getCurrentStep(): WebDriveStep | null;
196
+ getCurrentStepIndex(): number;
197
+ hasCompleted(): Promise<boolean>;
198
+ reset(): Promise<void>;
199
+ resetAll(): Promise<void>;
200
+ on<K extends keyof WebDriveEvents>(event: K, callback: (data: WebDriveEvents[K]) => void): this;
201
+ off<K extends keyof WebDriveEvents>(event: K, callback: (data: WebDriveEvents[K]) => void): this;
202
+ }
203
+
204
+ declare class EventEmitter {
205
+ private events;
206
+ on<K extends keyof WebDriveEvents>(event: K, handler: (data: WebDriveEvents[K]) => void): void;
207
+ off<K extends keyof WebDriveEvents>(event: K, handler: (data: WebDriveEvents[K]) => void): void;
208
+ emit<K extends keyof WebDriveEvents>(event: K, ...args: WebDriveEvents[K] extends void ? [] : [WebDriveEvents[K]]): void;
209
+ removeAllListeners(): void;
210
+ }
211
+
212
+ declare class StorageManager {
213
+ private storage;
214
+ private readonly prefix;
215
+ constructor(customStorage?: WebDriveStorage);
216
+ private getKey;
217
+ isCompleted(id: string): Promise<boolean>;
218
+ markCompleted(id: string): Promise<void>;
219
+ reset(id: string): Promise<void>;
220
+ resetAll(): Promise<void>;
221
+ }
222
+
223
+ declare class TourController {
224
+ private options;
225
+ private emitter;
226
+ private storage;
227
+ private overlay;
228
+ private popover;
229
+ private highlight;
230
+ private accessibility;
231
+ private currentStepIndex;
232
+ private tourActive;
233
+ private destroyed;
234
+ private resizeListener;
235
+ private scrollListener;
236
+ private rafId;
237
+ private waitObserver;
238
+ private waitTimeoutId;
239
+ constructor(options: WebDriveOptions, emitter: EventEmitter, storage: StorageManager);
240
+ start(startIndex?: number): Promise<void>;
241
+ stop(): Promise<void>;
242
+ complete(): Promise<void>;
243
+ next(): Promise<void>;
244
+ previous(): Promise<void>;
245
+ goTo(index: number, direction?: "forward" | "backward"): Promise<void>;
246
+ refresh(): void;
247
+ destroy(): void;
248
+ isActive(): boolean;
249
+ getCurrentStep(): WebDriveStep | null;
250
+ getCurrentStepIndex(): number;
251
+ private syncUI;
252
+ private updatePosition;
253
+ private triggerStepLeave;
254
+ private advanceFromMissing;
255
+ private waitForElement;
256
+ private cleanupWaiting;
257
+ private setupViewportListeners;
258
+ private removeViewportListeners;
259
+ }
260
+
261
+ /**
262
+ * Computes optimal popover position, handles viewport collision, fallback, clamping,
263
+ * and arrow positioning.
264
+ */
265
+ declare function calculatePopoverPosition(params: CalculatePositionParams): PopoverPositionResult;
266
+
267
+ export { type Alignment, type CalculatePositionParams, EventEmitter, type MissingElementBehavior, type PopoverPositionResult, type Position, StorageManager, TourController, WebDrive, type WebDriveEvents, type WebDriveOptions, type WebDriveStep, type WebDriveStorage, calculatePopoverPosition, WebDrive as default };