wontfix-sdk 0.0.1 → 0.0.3

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.
@@ -1,5 +1,1318 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Component } from '@angular/core';
2
+ import { EventEmitter, Output, Input, ChangeDetectionStrategy, Component, inject, ApplicationRef, Injector, createComponent, Injectable } from '@angular/core';
3
+ import { BehaviorSubject, firstValueFrom, filter, take } from 'rxjs';
4
+ import { Router, NavigationEnd } from '@angular/router';
5
+ import * as i1 from '@angular/common';
6
+ import { CommonModule } from '@angular/common';
7
+
8
+ /**
9
+ * Mock tooltip data for demo purposes
10
+ * Paths are in format: tag_index/tag_index/.../
11
+ * Index indicates which child with that tag name (0-based)
12
+ * templateId: 1 = product tour, 2 = tooltip
13
+ */
14
+ const MOCK_TOOLTIPS = [
15
+ {
16
+ templateId: 2,
17
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_0/div_0/button_0/',
18
+ pageUrl: '*',
19
+ metadata: {
20
+ interaction: 'hover',
21
+ position: 'top',
22
+ text: '💾 Save your work! All changes will be stored securely.'
23
+ }
24
+ },
25
+ {
26
+ templateId: 2,
27
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_0/div_0/button_1/',
28
+ pageUrl: '*',
29
+ metadata: {
30
+ interaction: 'hover',
31
+ position: 'top',
32
+ text: '⚠️ Warning: This action cannot be undone!'
33
+ }
34
+ },
35
+ {
36
+ templateId: 2,
37
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_0/div_0/button_2/',
38
+ pageUrl: '*',
39
+ metadata: {
40
+ interaction: 'hover',
41
+ position: 'top',
42
+ text: '🔄 Refresh the page to get latest updates'
43
+ }
44
+ },
45
+ {
46
+ templateId: 2,
47
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_1/div_0/button_0/',
48
+ pageUrl: '*',
49
+ metadata: {
50
+ interaction: 'click',
51
+ position: 'right',
52
+ text: '❓ Need help? Click here to view our documentation and FAQs.'
53
+ }
54
+ },
55
+ {
56
+ templateId: 2,
57
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_1/div_0/button_1/',
58
+ pageUrl: '*',
59
+ metadata: {
60
+ interaction: 'click',
61
+ position: 'right',
62
+ text: '⚙️ Configure app settings and preferences'
63
+ }
64
+ },
65
+ {
66
+ templateId: 2,
67
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_1/div_0/button_2/',
68
+ pageUrl: '*',
69
+ metadata: {
70
+ interaction: 'click',
71
+ position: 'right',
72
+ text: 'ℹ️ Learn more about Wontfix Tooltip SDK v1.0'
73
+ }
74
+ },
75
+ {
76
+ templateId: 2,
77
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_2/form_0/div_0/input_0/',
78
+ pageUrl: '*',
79
+ metadata: {
80
+ interaction: 'click',
81
+ position: 'right',
82
+ text: '📧 Enter a valid email address (e.g., user@example.com)'
83
+ }
84
+ },
85
+ {
86
+ templateId: 2,
87
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_2/form_0/div_1/input_0/',
88
+ pageUrl: '*',
89
+ metadata: {
90
+ interaction: 'click',
91
+ position: 'right',
92
+ text: '🔒 Use a strong password with at least 8 characters'
93
+ }
94
+ },
95
+ {
96
+ templateId: 2,
97
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_2/form_0/div_2/input_0/',
98
+ pageUrl: '*',
99
+ metadata: {
100
+ interaction: 'click',
101
+ position: 'right',
102
+ text: '✓ Must match the password above'
103
+ }
104
+ },
105
+ {
106
+ templateId: 2,
107
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_3/div_0/button_0/',
108
+ pageUrl: '*',
109
+ metadata: {
110
+ interaction: 'click',
111
+ position: 'top',
112
+ text: '⬆️ This tooltip appears at the TOP'
113
+ }
114
+ },
115
+ {
116
+ templateId: 2,
117
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_3/div_0/button_1/',
118
+ pageUrl: '*',
119
+ metadata: {
120
+ interaction: 'click',
121
+ position: 'right',
122
+ text: '➡️ This tooltip appears on the RIGHT'
123
+ }
124
+ },
125
+ {
126
+ templateId: 2,
127
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_3/div_0/button_2/',
128
+ pageUrl: '*',
129
+ metadata: {
130
+ interaction: 'click',
131
+ position: 'bottom',
132
+ text: '⬇️ This tooltip appears at the BOTTOM'
133
+ }
134
+ },
135
+ {
136
+ templateId: 2,
137
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_3/div_0/button_3/',
138
+ pageUrl: '*',
139
+ metadata: {
140
+ interaction: 'click',
141
+ position: 'left',
142
+ text: '⬅️ This tooltip appears on the LEFT'
143
+ }
144
+ },
145
+ {
146
+ templateId: 1,
147
+ path: '*',
148
+ pageUrl: '/product-tour',
149
+ metadata: {
150
+ assetUrl: '/assets/product-tour.mp4',
151
+ header: 'Cool Product Tour',
152
+ buttonText: 'Awesome!'
153
+ }
154
+ },
155
+ {
156
+ templateId: 3,
157
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_2/div_0/button_0/',
158
+ pageUrl: '*',
159
+ metadata: {
160
+ position: 'left',
161
+ label: ''
162
+ }
163
+ },
164
+ {
165
+ templateId: 3,
166
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_2/div_0/button_1/',
167
+ pageUrl: '*',
168
+ metadata: {
169
+ position: 'right',
170
+ label: 'Hot'
171
+ }
172
+ },
173
+ {
174
+ templateId: 4,
175
+ path: '*',
176
+ pageUrl: '*',
177
+ metadata: {
178
+ title: 'Getting Started Tour',
179
+ steps: [
180
+ {
181
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_0/div_0/button_0/',
182
+ position: 'bottom',
183
+ title: 'Save Your Work',
184
+ text: 'Click the Save button to securely store all your changes.',
185
+ order: 1
186
+ },
187
+ {
188
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_0/div_0/button_1/',
189
+ position: 'bottom',
190
+ title: 'Delete Items',
191
+ text: 'Use this button to permanently delete items. This action cannot be undone!',
192
+ order: 2
193
+ },
194
+ {
195
+ path: 'html_0/body_0/app-root_0/app-tooltip-demo_0/div_0/section_1/div_0/button_0/',
196
+ position: 'right',
197
+ title: 'Get Help',
198
+ text: 'Need assistance? Click here to access our comprehensive help documentation.',
199
+ order: 3
200
+ }
201
+ ]
202
+ }
203
+ },
204
+ {
205
+ templateId: 5,
206
+ path: '*',
207
+ pageUrl: '/popup-demo',
208
+ metadata: {
209
+ title: 'Welcome to Wontfix! 🎉',
210
+ text: 'We\'re excited to have you here. This popup demonstrates how you can show important announcements, feature updates, or onboarding messages to your users.',
211
+ buttonText: 'Got it'
212
+ }
213
+ }
214
+ ];
215
+
216
+ /**
217
+ * Path matcher utility for DOM element targeting
218
+ * Matches elements based on their path in the DOM tree
219
+ *
220
+ * Path format: "body_0/app-root_0/app-tooltip-demo_0/div_0/button_1/"
221
+ * Numbers indicate the child index (0-based) among siblings of the same tag name
222
+ */
223
+ class PathMatcher {
224
+ /**
225
+ * Find DOM element by path
226
+ * @param path DOM path like "html_0/body_0/div_0/button_1/"
227
+ * @returns The matching element or null
228
+ */
229
+ static findElementByPath(path) {
230
+ // Remove leading/trailing slashes and split
231
+ const segments = path.split('/').filter(s => s.length > 0);
232
+ if (segments.length === 0) {
233
+ return null;
234
+ }
235
+ // Start from the appropriate root
236
+ let currentElement = null;
237
+ let startIndex = 0;
238
+ // Check if first segment is the html element
239
+ if (segments[0].startsWith('html')) {
240
+ currentElement = document.documentElement;
241
+ startIndex = 1;
242
+ }
243
+ else if (segments[0].startsWith('body')) {
244
+ currentElement = document.body;
245
+ startIndex = 1;
246
+ }
247
+ else {
248
+ currentElement = document.documentElement;
249
+ }
250
+ // Process remaining segments
251
+ for (let i = startIndex; i < segments.length; i++) {
252
+ if (!currentElement) {
253
+ return null;
254
+ }
255
+ const segment = segments[i];
256
+ const [tagName, indexStr] = this.parseSegment(segment);
257
+ const index = parseInt(indexStr, 10);
258
+ // Find all children with the same tag name
259
+ const childrenWithTag = Array.from(currentElement.children).filter((child) => {
260
+ const matches = child.tagName.toLowerCase() === tagName.toLowerCase();
261
+ return matches;
262
+ });
263
+ // Get the element at the specified index
264
+ if (index >= 0 && index < childrenWithTag.length) {
265
+ currentElement = childrenWithTag[index];
266
+ }
267
+ else {
268
+ return null; // Index out of bounds
269
+ }
270
+ }
271
+ return currentElement instanceof HTMLElement ? currentElement : null;
272
+ }
273
+ /**
274
+ * Get the path for a given DOM element
275
+ * @param element The element to get the path for
276
+ * @returns Path string like "body_0/div_0/button_1/"
277
+ */
278
+ static getPathForElement(element) {
279
+ const segments = [];
280
+ let currentElement = element;
281
+ while (currentElement && currentElement !== document.documentElement) {
282
+ const parent = currentElement.parentElement;
283
+ if (!parent)
284
+ break;
285
+ // Count siblings with same tag name that come before this element
286
+ const siblings = Array.from(parent.children).filter((child) => child.tagName === currentElement.tagName);
287
+ const index = siblings.indexOf(currentElement);
288
+ if (index >= 0) {
289
+ segments.unshift(`${currentElement.tagName.toLowerCase()}_${index}`);
290
+ }
291
+ currentElement = parent;
292
+ }
293
+ // Add root element
294
+ if (currentElement === document.documentElement) {
295
+ segments.unshift(`${document.documentElement.tagName.toLowerCase()}_0`);
296
+ }
297
+ return segments.join('/') + '/';
298
+ }
299
+ /**
300
+ * Parse a path segment like "button_1" into ["button", "1"]
301
+ */
302
+ static parseSegment(segment) {
303
+ const lastUnderscoreIndex = segment.lastIndexOf('_');
304
+ if (lastUnderscoreIndex === -1) {
305
+ return [segment, '0'];
306
+ }
307
+ return [
308
+ segment.substring(0, lastUnderscoreIndex),
309
+ segment.substring(lastUnderscoreIndex + 1)
310
+ ];
311
+ }
312
+ }
313
+
314
+ class TooltipComponent {
315
+ tooltip;
316
+ close = new EventEmitter();
317
+ top = 0;
318
+ left = 0;
319
+ closeTooltip() {
320
+ this.close.emit();
321
+ }
322
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: TooltipComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
323
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.8", type: TooltipComponent, isStandalone: true, selector: "app-tooltip-popover", inputs: { tooltip: "tooltip" }, outputs: { close: "close" }, ngImport: i0, template: `
324
+ <div
325
+ class="tooltip-container"
326
+ [ngClass]="'tooltip-' + tooltip.position"
327
+ [style.top.px]="top"
328
+ [style.left.px]="left"
329
+ >
330
+ <div class="tooltip-content">
331
+ {{ tooltip.text }}
332
+ </div>
333
+ <div class="tooltip-arrow"></div>
334
+ </div>
335
+ `, isInline: true, styles: [".tooltip-container{position:fixed;background-color:#333;color:#fff;padding:8px 12px;border-radius:4px;font-size:12px;z-index:9999;box-shadow:0 2px 8px #00000026;max-width:300px;word-wrap:break-word;pointer-events:none;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif}.tooltip-arrow{position:absolute;width:0;height:0;border-style:solid}.tooltip-top{transform:translate(-50%) translateY(-100%)}.tooltip-top .tooltip-arrow{bottom:-4px;left:50%;transform:translate(-50%);border-width:4px 4px 0 4px;border-color:#333 transparent transparent transparent}.tooltip-bottom{transform:translate(-50%) translateY(8px)}.tooltip-bottom .tooltip-arrow{top:-4px;left:50%;transform:translate(-50%);border-width:0 4px 4px 4px;border-color:transparent transparent #333 transparent}.tooltip-left{transform:translate(-8px) translateY(-50%)}.tooltip-left .tooltip-arrow{right:-4px;top:50%;transform:translateY(-50%);border-width:4px 0 4px 4px;border-color:transparent transparent transparent #333}.tooltip-right{transform:translate(8px) translateY(-50%)}.tooltip-right .tooltip-arrow{left:-4px;top:50%;transform:translateY(-50%);border-width:4px 4px 4px 0;border-color:transparent #333 transparent transparent}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
336
+ }
337
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: TooltipComponent, decorators: [{
338
+ type: Component,
339
+ args: [{ selector: 'app-tooltip-popover', standalone: true, imports: [CommonModule], changeDetection: ChangeDetectionStrategy.OnPush, template: `
340
+ <div
341
+ class="tooltip-container"
342
+ [ngClass]="'tooltip-' + tooltip.position"
343
+ [style.top.px]="top"
344
+ [style.left.px]="left"
345
+ >
346
+ <div class="tooltip-content">
347
+ {{ tooltip.text }}
348
+ </div>
349
+ <div class="tooltip-arrow"></div>
350
+ </div>
351
+ `, styles: [".tooltip-container{position:fixed;background-color:#333;color:#fff;padding:8px 12px;border-radius:4px;font-size:12px;z-index:9999;box-shadow:0 2px 8px #00000026;max-width:300px;word-wrap:break-word;pointer-events:none;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif}.tooltip-arrow{position:absolute;width:0;height:0;border-style:solid}.tooltip-top{transform:translate(-50%) translateY(-100%)}.tooltip-top .tooltip-arrow{bottom:-4px;left:50%;transform:translate(-50%);border-width:4px 4px 0 4px;border-color:#333 transparent transparent transparent}.tooltip-bottom{transform:translate(-50%) translateY(8px)}.tooltip-bottom .tooltip-arrow{top:-4px;left:50%;transform:translate(-50%);border-width:0 4px 4px 4px;border-color:transparent transparent #333 transparent}.tooltip-left{transform:translate(-8px) translateY(-50%)}.tooltip-left .tooltip-arrow{right:-4px;top:50%;transform:translateY(-50%);border-width:4px 0 4px 4px;border-color:transparent transparent transparent #333}.tooltip-right{transform:translate(8px) translateY(-50%)}.tooltip-right .tooltip-arrow{left:-4px;top:50%;transform:translateY(-50%);border-width:4px 4px 4px 0;border-color:transparent #333 transparent transparent}\n"] }]
352
+ }], propDecorators: { tooltip: [{
353
+ type: Input
354
+ }], close: [{
355
+ type: Output
356
+ }] } });
357
+
358
+ class BeaconComponent {
359
+ elementRef;
360
+ config;
361
+ constructor(elementRef) {
362
+ this.elementRef = elementRef;
363
+ }
364
+ ngOnInit() {
365
+ // Position beacon relative to its parent container
366
+ // The beacon container will be positioned at top-left, then adjusted via CSS classes
367
+ }
368
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: BeaconComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
369
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.8", type: BeaconComponent, isStandalone: true, selector: "app-beacon", inputs: { config: "config" }, ngImport: i0, template: `
370
+ <div class="beacon-container" [class]="'beacon-' + config.position">
371
+ <div class="beacon-pulse"></div>
372
+ <div class="beacon-dot"></div>
373
+ </div>
374
+ @if (config.label) {
375
+ <span class="beacon-label">{{ config.label }}</span>
376
+ }
377
+ `, isInline: true, styles: [".beacon-container{display:flex;justify-content:center;align-items:center;gap:6px;z-index:100}.beacon-pulse{position:absolute;width:18px;height:18px;border-radius:50%;background:#e74c3c4d;animation:pulse 2s infinite}@keyframes pulse{0%{transform:scale(.8);opacity:1}70%{transform:scale(1.8);opacity:0}to{transform:scale(2);opacity:0}}.beacon-dot{position:relative;width:10px;height:10px;border-radius:50%;background:#e74c3c;box-shadow:0 2px 6px #e74c3c80;z-index:1;flex-shrink:0}.beacon-label{display:block;margin-top:8px;font-size:10px;font-weight:700;color:#fff;background:#e74c3c;padding:2px 5px;border-radius:3px;white-space:nowrap;text-transform:uppercase;letter-spacing:.4px;flex-shrink:0}\n"] });
378
+ }
379
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: BeaconComponent, decorators: [{
380
+ type: Component,
381
+ args: [{ selector: 'app-beacon', standalone: true, template: `
382
+ <div class="beacon-container" [class]="'beacon-' + config.position">
383
+ <div class="beacon-pulse"></div>
384
+ <div class="beacon-dot"></div>
385
+ </div>
386
+ @if (config.label) {
387
+ <span class="beacon-label">{{ config.label }}</span>
388
+ }
389
+ `, styles: [".beacon-container{display:flex;justify-content:center;align-items:center;gap:6px;z-index:100}.beacon-pulse{position:absolute;width:18px;height:18px;border-radius:50%;background:#e74c3c4d;animation:pulse 2s infinite}@keyframes pulse{0%{transform:scale(.8);opacity:1}70%{transform:scale(1.8);opacity:0}to{transform:scale(2);opacity:0}}.beacon-dot{position:relative;width:10px;height:10px;border-radius:50%;background:#e74c3c;box-shadow:0 2px 6px #e74c3c80;z-index:1;flex-shrink:0}.beacon-label{display:block;margin-top:8px;font-size:10px;font-weight:700;color:#fff;background:#e74c3c;padding:2px 5px;border-radius:3px;white-space:nowrap;text-transform:uppercase;letter-spacing:.4px;flex-shrink:0}\n"] }]
390
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { config: [{
391
+ type: Input
392
+ }] } });
393
+
394
+ class NavFlowComponent {
395
+ step;
396
+ currentStep;
397
+ totalSteps;
398
+ next = new EventEmitter();
399
+ previous = new EventEmitter();
400
+ close = new EventEmitter();
401
+ top = 0;
402
+ left = 0;
403
+ onNextClick() {
404
+ if (this.currentStep === this.totalSteps) {
405
+ this.close.emit();
406
+ }
407
+ else {
408
+ this.next.emit();
409
+ }
410
+ }
411
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: NavFlowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
412
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.8", type: NavFlowComponent, isStandalone: true, selector: "app-nav-flow", inputs: { step: "step", currentStep: "currentStep", totalSteps: "totalSteps" }, outputs: { next: "next", previous: "previous", close: "close" }, ngImport: i0, template: `
413
+ <div
414
+ class="nav-flow-container"
415
+ [ngClass]="'nav-flow-' + step.position"
416
+ [style.top.px]="top"
417
+ [style.left.px]="left"
418
+ >
419
+ <div class="nav-flow-header">
420
+ <span class="step-indicator">{{ currentStep }} of {{ totalSteps }}</span>
421
+ <button class="close-btn" (click)="close.emit()">✕</button>
422
+ </div>
423
+ <h3 class="nav-flow-title">{{ step.title }}</h3>
424
+ <p class="nav-flow-text">{{ step.text }}</p>
425
+ <div class="nav-flow-footer">
426
+ <button
427
+ class="nav-btn"
428
+ [disabled]="currentStep === 1"
429
+ (click)="previous.emit()"
430
+ >
431
+ ← Previous
432
+ </button>
433
+ <button
434
+ class="nav-btn primary"
435
+ (click)="onNextClick()"
436
+ >
437
+ {{ currentStep === totalSteps ? 'Finish' : 'Next →' }}
438
+ </button>
439
+ </div>
440
+ <div class="nav-flow-arrow"></div>
441
+ </div>
442
+ `, isInline: true, styles: [".nav-flow-container{position:fixed;background:#fff;border-radius:8px;padding:20px;box-shadow:0 4px 20px #0003;max-width:350px;z-index:10001;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif}.nav-flow-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.step-indicator{font-size:12px;color:#7f8c8d;font-weight:600}.close-btn{background:transparent;border:none;font-size:20px;cursor:pointer;color:#7f8c8d;padding:0;width:24px;height:24px;display:flex;align-items:center;justify-content:center;border-radius:4px;transition:background-color .2s}.close-btn:hover{background-color:#f0f0f0}.nav-flow-title{margin:0 0 8px;font-size:18px;font-weight:700;color:#2c3e50}.nav-flow-text{margin:0 0 16px;font-size:14px;line-height:1.5;color:#34495e}.nav-flow-footer{display:flex;gap:8px;justify-content:flex-end}.nav-btn{padding:8px 16px;border:1px solid #ddd;background:#fff;border-radius:6px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s}.nav-btn:hover:not(:disabled){background:#f8f9fa}.nav-btn:disabled{opacity:.5;cursor:not-allowed}.nav-btn.primary{background:#3498db;color:#fff;border-color:#3498db}.nav-btn.primary:hover{background:#2980b9}.nav-flow-arrow{position:absolute;width:0;height:0;border-style:solid}.nav-flow-top .nav-flow-arrow{bottom:-8px;left:50%;transform:translate(-50%);border-width:8px 8px 0 8px;border-color:white transparent transparent transparent}.nav-flow-bottom .nav-flow-arrow{top:-8px;left:50%;transform:translate(-50%);border-width:0 8px 8px 8px;border-color:transparent transparent white transparent}.nav-flow-left .nav-flow-arrow{right:-8px;top:50%;transform:translateY(-50%);border-width:8px 0 8px 8px;border-color:transparent transparent transparent white}.nav-flow-right .nav-flow-arrow{left:-8px;top:50%;transform:translateY(-50%);border-width:8px 8px 8px 0;border-color:transparent white transparent transparent}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
443
+ }
444
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: NavFlowComponent, decorators: [{
445
+ type: Component,
446
+ args: [{ selector: 'app-nav-flow', standalone: true, imports: [CommonModule], template: `
447
+ <div
448
+ class="nav-flow-container"
449
+ [ngClass]="'nav-flow-' + step.position"
450
+ [style.top.px]="top"
451
+ [style.left.px]="left"
452
+ >
453
+ <div class="nav-flow-header">
454
+ <span class="step-indicator">{{ currentStep }} of {{ totalSteps }}</span>
455
+ <button class="close-btn" (click)="close.emit()">✕</button>
456
+ </div>
457
+ <h3 class="nav-flow-title">{{ step.title }}</h3>
458
+ <p class="nav-flow-text">{{ step.text }}</p>
459
+ <div class="nav-flow-footer">
460
+ <button
461
+ class="nav-btn"
462
+ [disabled]="currentStep === 1"
463
+ (click)="previous.emit()"
464
+ >
465
+ ← Previous
466
+ </button>
467
+ <button
468
+ class="nav-btn primary"
469
+ (click)="onNextClick()"
470
+ >
471
+ {{ currentStep === totalSteps ? 'Finish' : 'Next →' }}
472
+ </button>
473
+ </div>
474
+ <div class="nav-flow-arrow"></div>
475
+ </div>
476
+ `, styles: [".nav-flow-container{position:fixed;background:#fff;border-radius:8px;padding:20px;box-shadow:0 4px 20px #0003;max-width:350px;z-index:10001;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif}.nav-flow-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.step-indicator{font-size:12px;color:#7f8c8d;font-weight:600}.close-btn{background:transparent;border:none;font-size:20px;cursor:pointer;color:#7f8c8d;padding:0;width:24px;height:24px;display:flex;align-items:center;justify-content:center;border-radius:4px;transition:background-color .2s}.close-btn:hover{background-color:#f0f0f0}.nav-flow-title{margin:0 0 8px;font-size:18px;font-weight:700;color:#2c3e50}.nav-flow-text{margin:0 0 16px;font-size:14px;line-height:1.5;color:#34495e}.nav-flow-footer{display:flex;gap:8px;justify-content:flex-end}.nav-btn{padding:8px 16px;border:1px solid #ddd;background:#fff;border-radius:6px;font-size:14px;font-weight:600;cursor:pointer;transition:all .2s}.nav-btn:hover:not(:disabled){background:#f8f9fa}.nav-btn:disabled{opacity:.5;cursor:not-allowed}.nav-btn.primary{background:#3498db;color:#fff;border-color:#3498db}.nav-btn.primary:hover{background:#2980b9}.nav-flow-arrow{position:absolute;width:0;height:0;border-style:solid}.nav-flow-top .nav-flow-arrow{bottom:-8px;left:50%;transform:translate(-50%);border-width:8px 8px 0 8px;border-color:white transparent transparent transparent}.nav-flow-bottom .nav-flow-arrow{top:-8px;left:50%;transform:translate(-50%);border-width:0 8px 8px 8px;border-color:transparent transparent white transparent}.nav-flow-left .nav-flow-arrow{right:-8px;top:50%;transform:translateY(-50%);border-width:8px 0 8px 8px;border-color:transparent transparent transparent white}.nav-flow-right .nav-flow-arrow{left:-8px;top:50%;transform:translateY(-50%);border-width:8px 8px 8px 0;border-color:transparent white transparent transparent}\n"] }]
477
+ }], propDecorators: { step: [{
478
+ type: Input
479
+ }], currentStep: [{
480
+ type: Input
481
+ }], totalSteps: [{
482
+ type: Input
483
+ }], next: [{
484
+ type: Output
485
+ }], previous: [{
486
+ type: Output
487
+ }], close: [{
488
+ type: Output
489
+ }] } });
490
+
491
+ class TooltipService {
492
+ appRef = inject(ApplicationRef);
493
+ injector = inject(Injector);
494
+ router = inject(Router, { optional: true });
495
+ tooltipsSubject = new BehaviorSubject([]);
496
+ config = null;
497
+ guidanceCollections = [];
498
+ tooltipComponentRefs = new Map();
499
+ tooltipElements = new Map();
500
+ tooltipListenerCleanup = new Map();
501
+ beaconComponentRefs = new Map();
502
+ beaconElements = new Map();
503
+ navFlowComponentRef = null;
504
+ navFlowElement = null;
505
+ currentNavFlowStep = 0;
506
+ navFlowData = null;
507
+ popupComponentRef = null;
508
+ popupElement = null;
509
+ popupOpen = false;
510
+ routeSubscription = null;
511
+ windowRouteListenersAttached = false;
512
+ tooltips$ = this.tooltipsSubject.asObservable();
513
+ /**
514
+ * Initialize tooltips by fetching from API on app load
515
+ * Waits for Angular to stabilize before matching paths
516
+ */
517
+ async initializeTooltips(config) {
518
+ this.config = config;
519
+ if (config.debug) {
520
+ console.log('[Wontfix] Initializing tooltips...');
521
+ }
522
+ try {
523
+ // Wait for Angular to stabilize (all components rendered and change detection complete)
524
+ // Some host apps may never become "stable" due to long-running tasks; don't block forever.
525
+ if (config.debug) {
526
+ console.log('[Wontfix] Waiting for Angular to stabilize...');
527
+ }
528
+ await this.waitForAngularStability(5000);
529
+ if (config.debug) {
530
+ console.log('[Wontfix] Angular stable, fetching tooltips');
531
+ }
532
+ await this.fetchTooltips();
533
+ // After initial load, keep reacting to host route changes.
534
+ this.setupRouteListener();
535
+ }
536
+ catch (error) {
537
+ console.error('[Wontfix] Failed to initialize tooltips:', error);
538
+ }
539
+ }
540
+ /**
541
+ * Fetch tooltips (currently using mock data)
542
+ */
543
+ async fetchTooltips() {
544
+ if (!this.config)
545
+ return;
546
+ const collections = await this.fetchGuidanceCollections();
547
+ this.guidanceCollections = collections;
548
+ if (this.config.debug) {
549
+ console.log(`[Wontfix] Loaded ${collections.length} guidance collections`);
550
+ }
551
+ // Map new API contract -> existing TooltipInstance shape used by TooltipComponent.
552
+ const tooltips = collections
553
+ .filter((c) => c?.type === 'tooltip')
554
+ .reduce((accumulator, collection) => {
555
+ const pageUrl = this.normalizeUrlToPathPattern(collection.url);
556
+ const elements = Array.isArray(collection.elements) ? collection.elements : [];
557
+ for (const el of elements) {
558
+ const position = (el.position ?? 'top');
559
+ const interaction = (el.interaction ?? 'hover');
560
+ const text = el.content ?? '';
561
+ accumulator.push({
562
+ templateId: 2,
563
+ path: el.selector,
564
+ pageUrl,
565
+ metadata: {
566
+ interaction,
567
+ position,
568
+ text,
569
+ },
570
+ priority: el.order ?? undefined,
571
+ id: `tooltip-${collection.id}-${el.id}`,
572
+ isVisible: false,
573
+ interaction,
574
+ position,
575
+ text,
576
+ });
577
+ }
578
+ return accumulator;
579
+ }, []);
580
+ this.tooltipsSubject.next(tooltips);
581
+ this.matchSelectorsToDOM();
582
+ // Also initialize beacons
583
+ this.initializeBeacons();
584
+ // Check for popups on current route
585
+ this.checkPopups();
586
+ // Check for product tours on current route
587
+ this.checkProductTours();
588
+ }
589
+ /**
590
+ * Initialize beacons (templateId: 3)
591
+ */
592
+ initializeBeacons() {
593
+ const currentUrl = window.location.pathname;
594
+ const beacons = this.guidanceCollections.filter((c) => c?.type === 'beacon' && this.urlMatches(c.url, currentUrl));
595
+ beacons.forEach((beacon, collectionIndex) => {
596
+ const elements = Array.isArray(beacon.elements) ? beacon.elements : [];
597
+ elements.forEach((beaconElement, elementIndex) => {
598
+ try {
599
+ const element = this.resolveTargetElement(beaconElement.selector);
600
+ if (element instanceof HTMLElement) {
601
+ this.attachBeaconToElement(element, beacon, beaconElement, collectionIndex, elementIndex);
602
+ }
603
+ }
604
+ catch (error) {
605
+ console.error(`[Wontfix] ERROR matching beacon selector "${beaconElement.selector}":`, error);
606
+ }
607
+ });
608
+ });
609
+ }
610
+ /**
611
+ * Attach beacon to an element
612
+ */
613
+ attachBeaconToElement(element, beacon, beaconElementConfig, collectionIndex, elementIndex) {
614
+ const beaconId = `beacon-${beacon.id}-${beaconElementConfig.id ?? `${collectionIndex}-${elementIndex}`}`;
615
+ const componentRef = createComponent(BeaconComponent, {
616
+ environmentInjector: this.appRef.injector,
617
+ });
618
+ componentRef.instance.config = {
619
+ position: (beaconElementConfig.position ?? 'top'),
620
+ label: beaconElementConfig.content
621
+ };
622
+ this.appRef.attachView(componentRef.hostView);
623
+ const beaconElement = componentRef.location.nativeElement;
624
+ // Get parent button group
625
+ const parent = element.parentElement;
626
+ if (parent) {
627
+ parent.style.position = 'relative';
628
+ // Calculate button position within parent
629
+ const buttonRect = element.getBoundingClientRect();
630
+ const parentRect = parent.getBoundingClientRect();
631
+ const relativeTop = buttonRect.top - parentRect.top;
632
+ const relativeLeft = buttonRect.left - parentRect.left;
633
+ const buttonWidth = buttonRect.width;
634
+ const buttonHeight = buttonRect.height;
635
+ // Set beacon position based on position prop
636
+ const position = beaconElementConfig.position;
637
+ let top = relativeTop;
638
+ let left = relativeLeft;
639
+ switch (position) {
640
+ case 'top':
641
+ top = relativeTop - 18;
642
+ left = relativeLeft + buttonWidth / 2 - 5;
643
+ break;
644
+ case 'bottom':
645
+ top = relativeTop + buttonHeight + 8;
646
+ left = relativeLeft + buttonWidth / 2 - 5;
647
+ break;
648
+ case 'left':
649
+ top = relativeTop + buttonHeight / 2 - 5;
650
+ left = relativeLeft - 18;
651
+ break;
652
+ case 'right':
653
+ top = relativeTop + buttonHeight / 2 - 5;
654
+ left = relativeLeft + buttonWidth + 8;
655
+ break;
656
+ default:
657
+ break;
658
+ }
659
+ beaconElement.style.position = 'absolute';
660
+ beaconElement.style.top = top + 'px';
661
+ beaconElement.style.left = left + 'px';
662
+ parent.appendChild(beaconElement);
663
+ }
664
+ else {
665
+ element.appendChild(beaconElement);
666
+ }
667
+ this.beaconElements.set(beaconId, beaconElement);
668
+ this.beaconComponentRefs.set(beaconId, componentRef);
669
+ }
670
+ /**
671
+ * Check if current route should show a product tour
672
+ */
673
+ checkProductTours() {
674
+ const currentUrl = window.location.pathname;
675
+ const productTours = this.guidanceCollections.filter(item => item?.type === 'product-tour' && this.urlMatches(item.url, currentUrl));
676
+ if (productTours.length > 0 && this.config?.debug) {
677
+ console.log('[Wontfix] Product tour found for route:', currentUrl);
678
+ // Product tour will be handled by the ProductTourComponent on that route
679
+ }
680
+ }
681
+ /**
682
+ * Get all tooltips for current page
683
+ */
684
+ getTooltipsForCurrentPage() {
685
+ const currentUrl = window.location.pathname;
686
+ return this.tooltipsSubject.value.filter(tooltip => this.urlMatches(tooltip.pageUrl, currentUrl));
687
+ }
688
+ /**
689
+ * Match tooltip paths to actual DOM elements
690
+ */
691
+ matchSelectorsToDOM() {
692
+ const tooltips = this.tooltipsSubject.value;
693
+ const currentUrl = window.location.pathname;
694
+ tooltips.forEach((tooltip) => {
695
+ if (!this.urlMatches(tooltip.pageUrl, currentUrl)) {
696
+ return;
697
+ }
698
+ try {
699
+ const element = this.resolveTargetElement(tooltip.path);
700
+ if (element instanceof HTMLElement) {
701
+ tooltip.element = element;
702
+ this.attachTooltipToElement(tooltip);
703
+ }
704
+ }
705
+ catch (error) {
706
+ console.error(`[Wontfix] ERROR matching path "${tooltip.path}":`, error);
707
+ }
708
+ });
709
+ this.tooltipsSubject.next(tooltips);
710
+ }
711
+ /**
712
+ * Attach tooltip event listeners to an element
713
+ */
714
+ attachTooltipToElement(tooltip) {
715
+ const element = tooltip.element;
716
+ if (!element) {
717
+ return;
718
+ }
719
+ const existingCleanup = this.tooltipListenerCleanup.get(tooltip.id);
720
+ if (existingCleanup) {
721
+ existingCleanup();
722
+ this.tooltipListenerCleanup.delete(tooltip.id);
723
+ }
724
+ if (tooltip.interaction === 'hover') {
725
+ const onEnter = () => this.showTooltip(tooltip.id);
726
+ const onLeave = () => this.hideTooltip(tooltip.id);
727
+ element.addEventListener('mouseenter', onEnter);
728
+ element.addEventListener('mouseleave', onLeave);
729
+ this.tooltipListenerCleanup.set(tooltip.id, () => {
730
+ element.removeEventListener('mouseenter', onEnter);
731
+ element.removeEventListener('mouseleave', onLeave);
732
+ });
733
+ }
734
+ else if (tooltip.interaction === 'click') {
735
+ const onElementClick = (e) => {
736
+ e.stopPropagation();
737
+ const isVisible = this.tooltipsSubject.value.find(t => t.id === tooltip.id)?.isVisible;
738
+ if (isVisible) {
739
+ this.hideTooltip(tooltip.id);
740
+ }
741
+ else {
742
+ this.showTooltip(tooltip.id);
743
+ }
744
+ };
745
+ element.addEventListener('click', onElementClick);
746
+ // Close on outside click
747
+ const onDocumentClick = () => this.hideTooltip(tooltip.id);
748
+ document.addEventListener('click', onDocumentClick);
749
+ this.tooltipListenerCleanup.set(tooltip.id, () => {
750
+ element.removeEventListener('click', onElementClick);
751
+ document.removeEventListener('click', onDocumentClick);
752
+ });
753
+ }
754
+ }
755
+ /**
756
+ * Show tooltip
757
+ */
758
+ showTooltip(tooltipId) {
759
+ const tooltip = this.tooltipsSubject.value.find(t => t.id === tooltipId);
760
+ if (!tooltip || tooltip.isVisible)
761
+ return;
762
+ tooltip.isVisible = true;
763
+ this.createAndShowTooltip(tooltip);
764
+ this.tooltipsSubject.next(this.tooltipsSubject.value);
765
+ }
766
+ /**
767
+ * Create and show tooltip component
768
+ */
769
+ createAndShowTooltip(tooltip) {
770
+ if (!tooltip.element) {
771
+ return;
772
+ }
773
+ // Remove existing tooltip
774
+ this.hideTooltip(tooltip.id);
775
+ // Create component
776
+ const componentRef = createComponent(TooltipComponent, {
777
+ environmentInjector: this.appRef.injector,
778
+ elementInjector: this.injector
779
+ });
780
+ componentRef.instance.tooltip = tooltip;
781
+ componentRef.instance.close.subscribe(() => {
782
+ this.hideTooltip(tooltip.id);
783
+ });
784
+ this.appRef.attachView(componentRef.hostView);
785
+ const tooltipElement = componentRef.location.nativeElement;
786
+ document.body.appendChild(tooltipElement);
787
+ this.tooltipElements.set(tooltip.id, tooltipElement);
788
+ this.tooltipComponentRefs.set(tooltip.id, componentRef);
789
+ // Position tooltip
790
+ this.positionTooltip(tooltip, tooltipElement);
791
+ }
792
+ /**
793
+ * Position tooltip relative to element
794
+ */
795
+ positionTooltip(tooltip, tooltipElement) {
796
+ if (!tooltip.element)
797
+ return;
798
+ const rect = tooltip.element.getBoundingClientRect();
799
+ const tooltipRect = tooltipElement.getBoundingClientRect();
800
+ let top = 0;
801
+ let left = 0;
802
+ const offset = 8;
803
+ switch (tooltip.position) {
804
+ case 'top':
805
+ top = rect.top - tooltipRect.height - offset;
806
+ left = rect.left + rect.width / 2 - tooltipRect.width / 2;
807
+ break;
808
+ case 'bottom':
809
+ top = rect.bottom + offset;
810
+ left = rect.left + rect.width / 2 - tooltipRect.width / 2;
811
+ break;
812
+ case 'left':
813
+ top = rect.top + rect.height / 2 - tooltipRect.height / 2;
814
+ left = rect.left - tooltipRect.width - offset;
815
+ break;
816
+ case 'right':
817
+ top = rect.top + rect.height / 2 - tooltipRect.height / 2;
818
+ left = rect.right + offset;
819
+ break;
820
+ }
821
+ // Don't add scroll offset for position: fixed elements
822
+ // Fixed positioning is relative to viewport, not document
823
+ // Set position on component instance
824
+ const componentInstance = this.tooltipComponentRefs.get(tooltip.id)?.instance;
825
+ if (componentInstance) {
826
+ componentInstance.top = top;
827
+ componentInstance.left = left;
828
+ }
829
+ }
830
+ /**
831
+ * Hide tooltip
832
+ */
833
+ hideTooltip(tooltipId) {
834
+ const tooltip = this.tooltipsSubject.value.find(t => t.id === tooltipId);
835
+ if (tooltip) {
836
+ tooltip.isVisible = false;
837
+ }
838
+ const componentRef = this.tooltipComponentRefs.get(tooltipId);
839
+ const tooltipElement = this.tooltipElements.get(tooltipId);
840
+ if (componentRef) {
841
+ this.appRef.detachView(componentRef.hostView);
842
+ componentRef.destroy();
843
+ this.tooltipComponentRefs.delete(tooltipId);
844
+ }
845
+ if (tooltipElement && tooltipElement.parentNode) {
846
+ tooltipElement.parentNode.removeChild(tooltipElement);
847
+ this.tooltipElements.delete(tooltipId);
848
+ }
849
+ this.tooltipsSubject.next(this.tooltipsSubject.value);
850
+ }
851
+ closeAllTooltips() {
852
+ for (const tooltipId of Array.from(this.tooltipComponentRefs.keys())) {
853
+ const tooltip = this.tooltipsSubject.value.find(t => t.id === tooltipId);
854
+ if (tooltip) {
855
+ tooltip.isVisible = false;
856
+ }
857
+ const componentRef = this.tooltipComponentRefs.get(tooltipId);
858
+ const tooltipElement = this.tooltipElements.get(tooltipId);
859
+ if (componentRef) {
860
+ this.appRef.detachView(componentRef.hostView);
861
+ componentRef.destroy();
862
+ }
863
+ if (tooltipElement && tooltipElement.parentNode) {
864
+ tooltipElement.parentNode.removeChild(tooltipElement);
865
+ }
866
+ }
867
+ this.tooltipComponentRefs.clear();
868
+ this.tooltipElements.clear();
869
+ this.tooltipsSubject.next(this.tooltipsSubject.value);
870
+ }
871
+ detachAllTooltipListeners() {
872
+ this.tooltipListenerCleanup.forEach((cleanup) => cleanup());
873
+ this.tooltipListenerCleanup.clear();
874
+ }
875
+ /**
876
+ * Re-scan DOM for new elements (useful for dynamically added content)
877
+ */
878
+ rescanDOM() {
879
+ this.matchSelectorsToDOM();
880
+ }
881
+ /**
882
+ * Update tooltip visibility
883
+ */
884
+ setTooltipVisible(tooltipId, visible) {
885
+ const tooltips = this.tooltipsSubject.value.map(t => t.id === tooltipId ? { ...t, isVisible: visible } : t);
886
+ this.tooltipsSubject.next(tooltips);
887
+ }
888
+ /**
889
+ * Check if page URL matches the tooltip's pageUrl pattern
890
+ * Supports:
891
+ * - Exact match: "/dashboard"
892
+ * - Wildcard: "/dashboard/*"
893
+ * - All pages: "*"
894
+ */
895
+ urlMatches(pattern, currentUrl) {
896
+ const normalizedPattern = this.normalizeUrlToPathPattern(pattern);
897
+ const normalizedCurrent = this.normalizeUrlToPathPattern(currentUrl);
898
+ if (normalizedPattern === '*')
899
+ return true;
900
+ if (normalizedPattern === normalizedCurrent)
901
+ return true;
902
+ // Handle wildcard patterns like "/dashboard/*"
903
+ const regexPattern = normalizedPattern
904
+ .replace(/\//g, '\\/')
905
+ .replace(/\*/g, '.*');
906
+ try {
907
+ return new RegExp(`^${regexPattern}$`).test(currentUrl);
908
+ }
909
+ catch {
910
+ return false;
911
+ }
912
+ }
913
+ /**
914
+ * Get tooltip by ID
915
+ */
916
+ getTooltipById(id) {
917
+ return this.tooltipsSubject.value.find(t => t.id === id);
918
+ }
919
+ /**
920
+ * Get all available tooltips (for debugging)
921
+ */
922
+ getAvailableTooltips() {
923
+ return this.tooltipsSubject.value.map(t => t.id);
924
+ }
925
+ /**
926
+ * Get product tour data for current route
927
+ */
928
+ getProductTourForRoute(route) {
929
+ const productTour = this.guidanceCollections.find(item => item?.type === 'product-tour' && this.urlMatches(item.url, route));
930
+ return productTour;
931
+ }
932
+ /**
933
+ * Reinitialize tooltips and beacons (useful when navigating back to a route)
934
+ */
935
+ reinitializeTooltips() {
936
+ this.closeAllTooltips();
937
+ this.closeNavFlow();
938
+ this.closePopup();
939
+ this.detachAllTooltipListeners();
940
+ // Clear existing beacons
941
+ this.beaconComponentRefs.forEach(ref => {
942
+ this.appRef.detachView(ref.hostView);
943
+ ref.destroy();
944
+ });
945
+ this.beaconComponentRefs.clear();
946
+ this.beaconElements.forEach(el => {
947
+ if (el && el.parentNode) {
948
+ el.parentNode.removeChild(el);
949
+ }
950
+ });
951
+ this.beaconElements.clear();
952
+ // Reinitialize beacons
953
+ this.initializeBeacons();
954
+ // Rematch tooltips to DOM
955
+ this.matchSelectorsToDOM();
956
+ this.checkPopups();
957
+ this.checkProductTours();
958
+ }
959
+ /**
960
+ * Start a nav-flow for the current page
961
+ */
962
+ startNavFlow() {
963
+ const currentUrl = window.location.pathname;
964
+ const navFlow = this.guidanceCollections.find(item => item?.type === 'nav-flow' && this.urlMatches(item.url, currentUrl));
965
+ if (!navFlow || !navFlow.metadata.steps) {
966
+ console.warn('[Wontfix] No nav-flow found for current page');
967
+ return;
968
+ }
969
+ this.navFlowData = navFlow;
970
+ this.currentNavFlowStep = 0;
971
+ this.showNavFlowStep(0);
972
+ }
973
+ /**
974
+ * Show a specific nav-flow step
975
+ */
976
+ showNavFlowStep(stepIndex) {
977
+ if (!this.navFlowData)
978
+ return;
979
+ const steps = this.navFlowData.metadata.steps;
980
+ if (stepIndex < 0 || stepIndex >= steps.length)
981
+ return;
982
+ // Clean up existing nav-flow component without resetting state
983
+ if (this.navFlowComponentRef) {
984
+ this.appRef.detachView(this.navFlowComponentRef.hostView);
985
+ this.navFlowComponentRef.destroy();
986
+ this.navFlowComponentRef = null;
987
+ }
988
+ if (this.navFlowElement && this.navFlowElement.parentNode) {
989
+ this.navFlowElement.parentNode.removeChild(this.navFlowElement);
990
+ this.navFlowElement = null;
991
+ }
992
+ const step = steps[stepIndex];
993
+ this.currentNavFlowStep = stepIndex;
994
+ try {
995
+ const element = this.resolveTargetElement(step.path);
996
+ if (element instanceof HTMLElement) {
997
+ this.createAndShowNavFlow(element, step, stepIndex + 1, steps.length);
998
+ }
999
+ }
1000
+ catch (error) {
1001
+ console.error(`[Wontfix] ERROR finding element for nav-flow step:`, error);
1002
+ }
1003
+ }
1004
+ /**
1005
+ * Create and show nav-flow component
1006
+ */
1007
+ createAndShowNavFlow(element, step, currentStep, totalSteps) {
1008
+ const componentRef = createComponent(NavFlowComponent, {
1009
+ environmentInjector: this.appRef.injector,
1010
+ });
1011
+ componentRef.instance.step = step;
1012
+ componentRef.instance.currentStep = currentStep;
1013
+ componentRef.instance.totalSteps = totalSteps;
1014
+ this.appRef.attachView(componentRef.hostView);
1015
+ const navFlowElement = componentRef.location.nativeElement;
1016
+ document.body.appendChild(navFlowElement);
1017
+ this.navFlowElement = navFlowElement;
1018
+ this.navFlowComponentRef = componentRef;
1019
+ // Position nav-flow
1020
+ this.positionNavFlow(element, step, navFlowElement, componentRef);
1021
+ // Subscribe to events after setting refs
1022
+ componentRef.instance.next.subscribe(() => {
1023
+ this.nextNavFlowStep();
1024
+ });
1025
+ componentRef.instance.previous.subscribe(() => {
1026
+ this.previousNavFlowStep();
1027
+ });
1028
+ componentRef.instance.close.subscribe(() => {
1029
+ this.closeNavFlow();
1030
+ });
1031
+ }
1032
+ /**
1033
+ * Position nav-flow relative to element
1034
+ */
1035
+ positionNavFlow(element, step, navFlowElement, componentRef) {
1036
+ const rect = element.getBoundingClientRect();
1037
+ const navFlowRect = navFlowElement.getBoundingClientRect();
1038
+ let top = 0;
1039
+ let left = 0;
1040
+ const offset = 8;
1041
+ // Use actual dimensions or fallback if not rendered yet
1042
+ const navFlowWidth = navFlowRect.width || 350;
1043
+ const navFlowHeight = navFlowRect.height || 200; // Approximate height
1044
+ switch (step.position) {
1045
+ case 'top':
1046
+ top = rect.top - navFlowHeight - offset;
1047
+ left = rect.left + rect.width / 2 - navFlowWidth / 2;
1048
+ break;
1049
+ case 'bottom':
1050
+ top = rect.bottom + offset;
1051
+ left = rect.left + rect.width / 2 - navFlowWidth / 2;
1052
+ break;
1053
+ case 'left':
1054
+ top = rect.top + rect.height / 2 - navFlowHeight / 2;
1055
+ left = rect.left - navFlowWidth - offset;
1056
+ break;
1057
+ case 'right':
1058
+ top = rect.top + rect.height / 2 - navFlowHeight / 2;
1059
+ left = rect.right + offset;
1060
+ break;
1061
+ }
1062
+ componentRef.instance.top = top;
1063
+ componentRef.instance.left = left;
1064
+ }
1065
+ /**
1066
+ * Go to next nav-flow step
1067
+ */
1068
+ nextNavFlowStep() {
1069
+ this.showNavFlowStep(this.currentNavFlowStep + 1);
1070
+ }
1071
+ /**
1072
+ * Go to previous nav-flow step
1073
+ */
1074
+ previousNavFlowStep() {
1075
+ this.showNavFlowStep(this.currentNavFlowStep - 1);
1076
+ }
1077
+ /**
1078
+ * Close nav-flow
1079
+ */
1080
+ closeNavFlow() {
1081
+ if (this.navFlowComponentRef) {
1082
+ this.appRef.detachView(this.navFlowComponentRef.hostView);
1083
+ this.navFlowComponentRef.destroy();
1084
+ this.navFlowComponentRef = null;
1085
+ }
1086
+ if (this.navFlowElement && this.navFlowElement.parentNode) {
1087
+ this.navFlowElement.parentNode.removeChild(this.navFlowElement);
1088
+ this.navFlowElement = null;
1089
+ }
1090
+ this.navFlowData = null;
1091
+ this.currentNavFlowStep = 0;
1092
+ }
1093
+ /**
1094
+ * Check if current route should show a popup
1095
+ */
1096
+ checkPopups() {
1097
+ const currentUrl = window.location.pathname;
1098
+ const popup = this.guidanceCollections.find(item => item?.type === 'popup' && this.urlMatches(item.url, currentUrl));
1099
+ if (popup && this.config?.debug) {
1100
+ console.log('[Wontfix] Popup found for route:', currentUrl);
1101
+ // Popup will be handled by the PopupComponent on that route
1102
+ }
1103
+ }
1104
+ /**
1105
+ * Get popup data for current route
1106
+ */
1107
+ getPopupForRoute(route) {
1108
+ const popup = this.guidanceCollections.find(item => item?.type === 'popup' && this.urlMatches(item.url, route));
1109
+ return popup;
1110
+ }
1111
+ setupRouteListener() {
1112
+ if (this.routeSubscription || this.windowRouteListenersAttached) {
1113
+ return;
1114
+ }
1115
+ if (this.router) {
1116
+ this.routeSubscription = this.router.events.subscribe((event) => {
1117
+ if (event instanceof NavigationEnd) {
1118
+ this.onRouteChanged();
1119
+ }
1120
+ });
1121
+ return;
1122
+ }
1123
+ window.addEventListener('popstate', this.onRouteChanged);
1124
+ window.addEventListener('hashchange', this.onRouteChanged);
1125
+ this.windowRouteListenersAttached = true;
1126
+ }
1127
+ onRouteChanged = async () => {
1128
+ try {
1129
+ await firstValueFrom(this.appRef.isStable.pipe(filter(stable => stable === true), take(1)));
1130
+ this.reinitializeTooltips();
1131
+ }
1132
+ catch (error) {
1133
+ if (this.config?.debug) {
1134
+ console.warn('[Wontfix] Route-change reinit failed:', error);
1135
+ }
1136
+ }
1137
+ };
1138
+ async fetchGuidanceCollections() {
1139
+ const fallbackToMock = this.config?.fallbackToMock ?? true;
1140
+ try {
1141
+ if (!this.config?.apiUrl) {
1142
+ return fallbackToMock ? this.normalizeGuidanceCollections(MOCK_TOOLTIPS) : [];
1143
+ }
1144
+ const hasPayload = this.config.payload !== undefined;
1145
+ if (this.config.debug) {
1146
+ console.log('[Wontfix] Fetching guidance collections...', {
1147
+ url: this.config.apiUrl,
1148
+ method: hasPayload ? 'POST' : 'GET'
1149
+ });
1150
+ }
1151
+ const response = await fetch(this.config.apiUrl, {
1152
+ method: hasPayload ? 'POST' : 'GET',
1153
+ headers: {
1154
+ 'Content-Type': 'application/json',
1155
+ },
1156
+ body: hasPayload ? JSON.stringify(this.config.payload) : undefined,
1157
+ });
1158
+ if (!response.ok) {
1159
+ throw new Error(`HTTP ${response.status}`);
1160
+ }
1161
+ const json = await response.json();
1162
+ const raw = Array.isArray(json)
1163
+ ? json
1164
+ : Array.isArray(json?.data)
1165
+ ? json.data
1166
+ : Array.isArray(json?.items)
1167
+ ? json.items
1168
+ : [];
1169
+ if (this.config.debug) {
1170
+ console.log('[Wontfix] Guidance collections fetched', {
1171
+ status: json?.status,
1172
+ count: Array.isArray(raw) ? raw.length : 0
1173
+ });
1174
+ }
1175
+ return this.normalizeGuidanceCollections(raw);
1176
+ }
1177
+ catch (error) {
1178
+ console.error('[Wontfix] Failed to fetch guidance elements:', error);
1179
+ return fallbackToMock ? this.normalizeGuidanceCollections(MOCK_TOOLTIPS) : [];
1180
+ }
1181
+ }
1182
+ async waitForAngularStability(timeoutMs) {
1183
+ try {
1184
+ await Promise.race([
1185
+ firstValueFrom(this.appRef.isStable.pipe(filter(stable => stable === true), take(1))),
1186
+ new Promise((resolve) => setTimeout(resolve, timeoutMs)),
1187
+ ]);
1188
+ if (this.config?.debug) {
1189
+ console.log('[Wontfix] Stability wait finished');
1190
+ }
1191
+ }
1192
+ catch {
1193
+ // Never block initialization on stability failures.
1194
+ }
1195
+ }
1196
+ normalizeGuidanceCollections(raw) {
1197
+ if (!Array.isArray(raw))
1198
+ return [];
1199
+ const result = [];
1200
+ raw.forEach((item, index) => {
1201
+ if (item && typeof item === 'object' && typeof item.type === 'string' && typeof item.url === 'string') {
1202
+ if (item.isActive === false)
1203
+ return;
1204
+ if (Array.isArray(item.elements)) {
1205
+ item.elements = item.elements.filter((el) => el?.isActive !== false);
1206
+ }
1207
+ result.push(item);
1208
+ return;
1209
+ }
1210
+ if (item && typeof item === 'object' && typeof item.templateId === 'number') {
1211
+ const templateId = item.templateId;
1212
+ const type = templateId === 2 ? 'tooltip' :
1213
+ templateId === 3 ? 'beacon' :
1214
+ templateId === 1 ? 'product-tour' :
1215
+ templateId === 4 ? 'nav-flow' :
1216
+ templateId === 5 ? 'popup' :
1217
+ 'unknown';
1218
+ result.push({
1219
+ id: item.id ?? `legacy-${templateId}-${index}`,
1220
+ type,
1221
+ url: item.pageUrl ?? '*',
1222
+ elements: [
1223
+ {
1224
+ id: item.elements?.[0]?.id ?? `legacy-el-${index}`,
1225
+ selector: item.path ?? item.selector,
1226
+ position: item.metadata?.position,
1227
+ interaction: item.metadata?.interaction,
1228
+ content: item.metadata?.text,
1229
+ order: item.priority ?? item.order ?? item.elements?.[0]?.order,
1230
+ },
1231
+ ],
1232
+ metadata: item.metadata,
1233
+ });
1234
+ }
1235
+ });
1236
+ return result;
1237
+ }
1238
+ resolveTargetElement(selectorOrPath) {
1239
+ if (!selectorOrPath)
1240
+ return null;
1241
+ if (selectorOrPath.includes('/')) {
1242
+ return PathMatcher.findElementByPath(selectorOrPath);
1243
+ }
1244
+ try {
1245
+ const element = document.querySelector(selectorOrPath);
1246
+ return element instanceof HTMLElement ? element : null;
1247
+ }
1248
+ catch {
1249
+ return PathMatcher.findElementByPath(selectorOrPath);
1250
+ }
1251
+ }
1252
+ normalizeUrlToPathPattern(value) {
1253
+ if (!value)
1254
+ return '';
1255
+ if (value === '*')
1256
+ return '*';
1257
+ if (value.startsWith('/')) {
1258
+ return value;
1259
+ }
1260
+ try {
1261
+ const parsed = new URL(value);
1262
+ return parsed.pathname || '/';
1263
+ }
1264
+ catch {
1265
+ return value;
1266
+ }
1267
+ }
1268
+ /**
1269
+ * Close popup
1270
+ */
1271
+ closePopup() {
1272
+ this.popupOpen = false;
1273
+ if (this.popupComponentRef) {
1274
+ this.appRef.detachView(this.popupComponentRef.hostView);
1275
+ this.popupComponentRef.destroy();
1276
+ this.popupComponentRef = null;
1277
+ }
1278
+ if (this.popupElement && this.popupElement.parentNode) {
1279
+ this.popupElement.parentNode.removeChild(this.popupElement);
1280
+ this.popupElement = null;
1281
+ }
1282
+ }
1283
+ /**
1284
+ * Check if popup is open
1285
+ */
1286
+ isPopupOpen() {
1287
+ return this.popupOpen;
1288
+ }
1289
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: TooltipService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1290
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: TooltipService, providedIn: 'root' });
1291
+ }
1292
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: TooltipService, decorators: [{
1293
+ type: Injectable,
1294
+ args: [{
1295
+ providedIn: 'root'
1296
+ }]
1297
+ }] });
1298
+
1299
+ /*
1300
+ * Tooltips are fetched once on app load.
1301
+ * Updates are only available on next app reload.
1302
+ */
1303
+ function wontfixInitializer(config) {
1304
+ return () => {
1305
+ const tooltipService = inject(TooltipService);
1306
+ return tooltipService.initializeTooltips(config);
1307
+ };
1308
+ }
1309
+
1310
+ /**
1311
+ * Wontfix Tooltip SDK - Public API
1312
+ *
1313
+ * This is the main entry point for applications using the Wontfix SDK.
1314
+ * Export only the public-facing APIs that consumers should use.
1315
+ */
3
1316
 
4
1317
  class WontfixSdk {
5
1318
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: WontfixSdk, deps: [], target: i0.ɵɵFactoryTarget.Component });
@@ -21,10 +1334,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImpor
21
1334
  /*
22
1335
  * Public API Surface of wontfix-sdk
23
1336
  */
1337
+ // Main SDK surface (service + initializer + types)
24
1338
 
25
1339
  /**
26
1340
  * Generated bundle index. Do not edit.
27
1341
  */
28
1342
 
29
- export { WontfixSdk };
1343
+ export { TooltipService, WontfixSdk, wontfixInitializer };
30
1344
  //# sourceMappingURL=wontfix-sdk.mjs.map