@eventop/sdk 1.1.3 → 1.1.5

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.cjs CHANGED
@@ -3,6 +3,1026 @@
3
3
  var react = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
 
6
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
7
+
8
+ var core = {exports: {}};
9
+
10
+ /**
11
+ * ╔══════════════════════════════════════════════════════════════╗
12
+ * ║ @eventop/sdk v1.1.0 ║
13
+ * ║ AI-powered guided tours — themeable, provider-agnostic ║
14
+ * ║ ║
15
+ * ║ Provider: always proxy through your own server. ║
16
+ * ║ Never expose API keys in client-side code. ║
17
+ * ╚══════════════════════════════════════════════════════════════╝
18
+ */
19
+ (function (module) {
20
+ (function (global, factory) {
21
+ if (module.exports) {
22
+ module.exports = factory();
23
+ } else {
24
+ global.Eventop = factory();
25
+ }
26
+ })(typeof globalThis !== 'undefined' ? globalThis : commonjsGlobal, function () {
27
+
28
+ const SHEPHERD_CSS = 'https://cdn.jsdelivr.net/npm/shepherd.js@11.2.0/dist/css/shepherd.css';
29
+ const SHEPHERD_JS = 'https://cdn.jsdelivr.net/npm/shepherd.js@11.2.0/dist/js/shepherd.min.js';
30
+
31
+ // ─── Internal state ──────────────────────────────────────────────────────────
32
+ let _provider = null;
33
+ let _config = null;
34
+ let _tour = null;
35
+ let _isOpen = false;
36
+ let _messages = [];
37
+ let _mediaQuery = null;
38
+
39
+ // Pause/resume state
40
+ let _pausedSteps = null;
41
+ let _pausedIndex = 0;
42
+
43
+ // Active cleanup callbacks — cleared when tour ends or is paused
44
+ let _cleanups = [];
45
+
46
+ // ═══════════════════════════════════════════════════════════════════════════
47
+ // THEME ENGINE
48
+ // ═══════════════════════════════════════════════════════════════════════════
49
+
50
+ const DARK_TOKENS = {
51
+ accent: '#e94560',
52
+ accentSecondary: '#a855f7',
53
+ bg: '#0f0f1a',
54
+ surface: '#1a1a2e',
55
+ border: '#2a2a4a',
56
+ text: '#e0e0f0',
57
+ textDim: '#6060a0',
58
+ radius: '16px',
59
+ fontFamily: "system-ui, -apple-system, 'Segoe UI', sans-serif"
60
+ };
61
+ const LIGHT_TOKENS = {
62
+ accent: '#e94560',
63
+ accentSecondary: '#7c3aed',
64
+ bg: '#ffffff',
65
+ surface: '#f8f8fc',
66
+ border: '#e4e4f0',
67
+ text: '#1a1a2e',
68
+ textDim: '#888899',
69
+ radius: '16px',
70
+ fontFamily: "system-ui, -apple-system, 'Segoe UI', sans-serif"
71
+ };
72
+ const PRESETS = {
73
+ default: {},
74
+ minimal: {
75
+ accent: '#000000',
76
+ accentSecondary: '#333333',
77
+ radius: '8px'
78
+ },
79
+ soft: {
80
+ accent: '#6366f1',
81
+ accentSecondary: '#8b5cf6',
82
+ radius: '20px'
83
+ }
84
+ };
85
+ function resolveTheme(themeConfig = {}) {
86
+ var _window$matchMedia, _window;
87
+ const {
88
+ mode = 'auto',
89
+ preset = 'default',
90
+ tokens = {}
91
+ } = themeConfig;
92
+ const isDark = mode === 'auto' ? ((_window$matchMedia = (_window = window).matchMedia) === null || _window$matchMedia === void 0 ? void 0 : _window$matchMedia.call(_window, '(prefers-color-scheme: dark)').matches) ?? true : mode === 'dark';
93
+ const base = isDark ? {
94
+ ...DARK_TOKENS
95
+ } : {
96
+ ...LIGHT_TOKENS
97
+ };
98
+ return {
99
+ ...base,
100
+ ...(PRESETS[preset] || {}),
101
+ ...tokens,
102
+ _isDark: isDark
103
+ };
104
+ }
105
+ function buildCSSVars(t) {
106
+ return `
107
+ --sai-accent: ${t.accent};
108
+ --sai-accent2: ${t.accentSecondary};
109
+ --sai-bg: ${t.bg};
110
+ --sai-surface: ${t.surface};
111
+ --sai-border: ${t.border};
112
+ --sai-text: ${t.text};
113
+ --sai-text-dim: ${t.textDim};
114
+ --sai-radius: ${t.radius};
115
+ --sai-font: ${t.fontFamily};
116
+ `;
117
+ }
118
+ function applyTheme(t) {
119
+ const panel = document.getElementById('sai-panel');
120
+ const trigger = document.getElementById('sai-trigger');
121
+ if (panel) {
122
+ panel.style.cssText += buildCSSVars(t);
123
+ }
124
+ if (trigger) {
125
+ trigger.style.cssText += buildCSSVars(t);
126
+ }
127
+ }
128
+
129
+ // ═══════════════════════════════════════════════════════════════════════════
130
+ // POSITIONING
131
+ // ═══════════════════════════════════════════════════════════════════════════
132
+
133
+ function resolvePosition(posConfig = {}) {
134
+ const {
135
+ corner = 'bottom-right',
136
+ offsetX = 28,
137
+ offsetY = 28
138
+ } = posConfig;
139
+ const isLeft = corner.includes('left');
140
+ const isTop = corner.includes('top');
141
+ return {
142
+ trigger: {
143
+ [isLeft ? 'left' : 'right']: `${offsetX}px`,
144
+ [isTop ? 'top' : 'bottom']: `${offsetY}px`
145
+ },
146
+ panel: {
147
+ [isLeft ? 'left' : 'right']: `${offsetX}px`,
148
+ [isTop ? 'top' : 'bottom']: `${offsetY + 56 + 12}px`,
149
+ transformOrigin: isTop ? 'top center' : 'bottom center'
150
+ }
151
+ };
152
+ }
153
+ function positionToCSS(obj) {
154
+ return Object.entries(obj).map(([k, v]) => `${k}:${v}`).join(';');
155
+ }
156
+
157
+ // ═══════════════════════════════════════════════════════════════════════════
158
+ // PROVIDER
159
+ // Only custom() is supported — route AI calls through your own server.
160
+ //
161
+ // Your endpoint receives: POST { systemPrompt, messages }
162
+ // Your endpoint must return: { message: string, steps: Step[] }
163
+ //
164
+ // @example
165
+ // Eventop.init({
166
+ // provider: Eventop.providers.custom(async ({ systemPrompt, messages }) => {
167
+ // const res = await fetch('/api/guide', {
168
+ // method: 'POST',
169
+ // headers: { 'Content-Type': 'application/json' },
170
+ // body: JSON.stringify({ systemPrompt, messages }),
171
+ // });
172
+ // return res.json();
173
+ // }),
174
+ // config: { ... },
175
+ // });
176
+ // ═══════════════════════════════════════════════════════════════════════════
177
+
178
+ const providers = {
179
+ custom(fn) {
180
+ if (typeof fn !== 'function') throw new Error('[Eventop] providers.custom() requires a function');
181
+ return fn;
182
+ }
183
+ };
184
+
185
+ // ═══════════════════════════════════════════════════════════════════════════
186
+ // SYSTEM PROMPT
187
+ // ═══════════════════════════════════════════════════════════════════════════
188
+
189
+ function buildSystemPrompt() {
190
+ const screens = [...new Set((_config.features || []).filter(f => {
191
+ var _f$screen;
192
+ return (_f$screen = f.screen) === null || _f$screen === void 0 ? void 0 : _f$screen.id;
193
+ }).map(f => f.screen.id))];
194
+ const featureSummary = (_config.features || []).map(f => {
195
+ var _f$screen2, _f$flow;
196
+ const entry = {
197
+ id: f.id,
198
+ name: f.name,
199
+ description: f.description,
200
+ screen: ((_f$screen2 = f.screen) === null || _f$screen2 === void 0 ? void 0 : _f$screen2.id) || 'default'
201
+ };
202
+ if ((_f$flow = f.flow) !== null && _f$flow !== void 0 && _f$flow.length) {
203
+ entry.note = `This feature has ${f.flow.length} sequential sub-steps. Include ONE step per flow entry.`;
204
+ }
205
+ return entry;
206
+ });
207
+ return `
208
+ You are an in-app assistant called "${_config.assistantName || 'AI Guide'}" for "${_config.appName}".
209
+ Your ONLY job: guide users step-by-step through tasks using the feature map below.
210
+
211
+ ${screens.length > 1 ? `SCREENS: This app has multiple screens: ${screens.join(', ')}. Features are screen-specific. The SDK handles navigation — just pick the right features.` : ''}
212
+
213
+ FEATURE MAP (only reference IDs from this list):
214
+ ${JSON.stringify(featureSummary, null, 2)}
215
+
216
+ RESPOND ONLY with this exact JSON — no markdown, no extra text:
217
+ {
218
+ "message": "Friendly 1-2 sentence intro about what you are helping with.",
219
+ "steps": [
220
+ {
221
+ "id": "feature-id-from-map",
222
+ "title": "3-5 word title",
223
+ "text": "Exact instruction. Max 2 sentences.",
224
+ "selector": "#selector-from-feature-map",
225
+ "position": "bottom"
226
+ }
227
+ ]
228
+ }
229
+
230
+ RULES:
231
+ 1. The step "id" MUST match a feature id from the feature map.
232
+ 2. Only use selectors and IDs from the feature map. Never invent them.
233
+ 3. No matching feature → steps: [], explain kindly in message.
234
+ 4. position values: top | bottom | left | right | auto only.
235
+ 5. Order steps logically. For multi-step flows, order as the user encounters them.
236
+ 6. For forms: ALWAYS include a step for the form section or first input BEFORE the
237
+ continue/submit button. The button step must always be LAST in its section.
238
+ 7. If a feature has a flow, include one step per flow entry using the same feature id —
239
+ the SDK expands them automatically.
240
+ 8. Never skip features in a required sequence. Include every step end-to-end.
241
+ `.trim();
242
+ }
243
+ async function callAI(userMessage) {
244
+ const systemPrompt = buildSystemPrompt();
245
+ const messagesWithNew = [..._messages, {
246
+ role: 'user',
247
+ content: userMessage
248
+ }];
249
+ const result = await _provider({
250
+ systemPrompt,
251
+ messages: messagesWithNew
252
+ });
253
+ _messages.push({
254
+ role: 'user',
255
+ content: userMessage
256
+ });
257
+ _messages.push({
258
+ role: 'assistant',
259
+ content: result.message
260
+ });
261
+ return result;
262
+ }
263
+
264
+ // ═══════════════════════════════════════════════════════════════════════════
265
+ // SCREEN NAVIGATION
266
+ // ═══════════════════════════════════════════════════════════════════════════
267
+
268
+ async function ensureOnCorrectScreen(feature) {
269
+ if (!feature.screen) return;
270
+ if (typeof feature.screen.check === 'function' && feature.screen.check()) return;
271
+ addMsg('ai', 'Taking you to the right screen first…');
272
+ if (typeof feature.screen.navigate === 'function') {
273
+ feature.screen.navigate();
274
+ }
275
+ const waitSelector = feature.screen.waitFor || feature.selector;
276
+ if (waitSelector) await waitForElement(waitSelector, 10000);
277
+ }
278
+
279
+ // ═══════════════════════════════════════════════════════════════════════════
280
+ // FLOW EXPANSION
281
+ // A feature with flow[] gets expanded into multiple Shepherd steps.
282
+ // Developer supplies selectors; AI supplies copy for the parent step.
283
+ // ═══════════════════════════════════════════════════════════════════════════
284
+
285
+ function expandFlowSteps(aiStep, feature) {
286
+ var _feature$flow;
287
+ if (!((_feature$flow = feature.flow) !== null && _feature$flow !== void 0 && _feature$flow.length)) return [aiStep];
288
+ return feature.flow.map((entry, i) => ({
289
+ id: `${aiStep.id}-flow-${i}`,
290
+ title: i === 0 ? aiStep.title : `${aiStep.title} (${i + 1}/${feature.flow.length})`,
291
+ text: i === 0 ? aiStep.text : `Step ${i + 1} of ${feature.flow.length}: continue with the action highlighted below.`,
292
+ position: aiStep.position || 'bottom',
293
+ selector: entry.selector || null,
294
+ waitFor: entry.waitFor || null,
295
+ advanceOn: entry.advanceOn || null,
296
+ _parentId: aiStep.id
297
+ }));
298
+ }
299
+
300
+ // ═══════════════════════════════════════════════════════════════════════════
301
+ // SHEPHERD RUNNER
302
+ // ═══════════════════════════════════════════════════════════════════════════
303
+
304
+ function loadCSS(href) {
305
+ if (document.querySelector(`link[href="${href}"]`)) return;
306
+ const l = document.createElement('link');
307
+ l.rel = 'stylesheet';
308
+ l.href = href;
309
+ document.head.appendChild(l);
310
+ }
311
+ function loadScript(src) {
312
+ return new Promise((res, rej) => {
313
+ if (document.querySelector(`script[src="${src}"]`)) return res();
314
+ const s = document.createElement('script');
315
+ s.src = src;
316
+ s.onload = res;
317
+ s.onerror = rej;
318
+ document.head.appendChild(s);
319
+ });
320
+ }
321
+ async function ensureShepherd() {
322
+ if (typeof Shepherd !== 'undefined') return;
323
+ loadCSS(SHEPHERD_CSS);
324
+ await loadScript(SHEPHERD_JS);
325
+ }
326
+ function waitForElement(selector, timeout = 8000) {
327
+ return new Promise(resolve => {
328
+ if (document.querySelector(selector)) return resolve();
329
+ const timer = setTimeout(() => {
330
+ observer.disconnect();
331
+ console.warn(`[Eventop] waitFor("${selector}") timed out — continuing`);
332
+ resolve();
333
+ }, timeout);
334
+ const observer = new MutationObserver(() => {
335
+ if (document.querySelector(selector)) {
336
+ clearTimeout(timer);
337
+ observer.disconnect();
338
+ resolve();
339
+ }
340
+ });
341
+ observer.observe(document.body, {
342
+ childList: true,
343
+ subtree: true
344
+ });
345
+ _cleanups.push(() => {
346
+ clearTimeout(timer);
347
+ observer.disconnect();
348
+ });
349
+ });
350
+ }
351
+ function mergeWithFeature(step) {
352
+ var _config2;
353
+ if (!((_config2 = _config) !== null && _config2 !== void 0 && _config2.features)) return step;
354
+ const feature = _config.features.find(f => f.id === step.id);
355
+ if (!feature) return step;
356
+ return {
357
+ waitFor: feature.waitFor || null,
358
+ advanceOn: feature.advanceOn || null,
359
+ validate: feature.validate || null,
360
+ screen: feature.screen || null,
361
+ flow: feature.flow || null,
362
+ ...step,
363
+ selector: feature.selector || step.selector // feature map always wins
364
+ };
365
+ }
366
+ function wireAdvanceOn(shepherdStep, advanceOn, tour) {
367
+ if (!(advanceOn !== null && advanceOn !== void 0 && advanceOn.selector) || !(advanceOn !== null && advanceOn !== void 0 && advanceOn.event)) return;
368
+ function handler(e) {
369
+ if (e.target.matches(advanceOn.selector) || e.target.closest(advanceOn.selector)) {
370
+ setTimeout(() => {
371
+ if (tour && !tour.isActive()) return;
372
+ tour.next();
373
+ }, advanceOn.delay || 300);
374
+ }
375
+ }
376
+ document.addEventListener(advanceOn.event, handler, true);
377
+ _cleanups.push(() => document.removeEventListener(advanceOn.event, handler, true));
378
+ shepherdStep.on('show', () => {
379
+ var _shepherdStep$getElem;
380
+ const nextBtn = (_shepherdStep$getElem = shepherdStep.getElement()) === null || _shepherdStep$getElem === void 0 ? void 0 : _shepherdStep$getElem.querySelector('.shepherd-footer .shepherd-button:not(.shepherd-button-secondary)');
381
+ if (nextBtn && !shepherdStep._isLast) {
382
+ nextBtn.style.opacity = '0.4';
383
+ nextBtn.title = 'Complete the action above to continue';
384
+ }
385
+ });
386
+ }
387
+ function addProgressIndicator(shepherdStep, index, total) {
388
+ shepherdStep.on('show', () => {
389
+ var _shepherdStep$getElem2;
390
+ const header = (_shepherdStep$getElem2 = shepherdStep.getElement()) === null || _shepherdStep$getElem2 === void 0 ? void 0 : _shepherdStep$getElem2.querySelector('.shepherd-header');
391
+ if (!header || header.querySelector('.sai-progress')) return;
392
+ const pct = Math.round((index + 1) / total * 100);
393
+ const wrapper = document.createElement('div');
394
+ wrapper.className = 'sai-progress';
395
+ wrapper.innerHTML = `
396
+ <div class="sai-progress-bar">
397
+ <div class="sai-progress-fill" style="width:${pct}%"></div>
398
+ </div>
399
+ <span class="sai-progress-label">${index + 1} / ${total}</span>
400
+ `;
401
+ header.appendChild(wrapper);
402
+ });
403
+ }
404
+ function showResumeButton(fromIndex) {
405
+ var _document$getElementB, _document$getElementB2;
406
+ const msgs = document.getElementById('sai-messages');
407
+ if (!msgs) return;
408
+ (_document$getElementB = document.getElementById('sai-resume-prompt')) === null || _document$getElementB === void 0 || _document$getElementB.remove();
409
+ const div = document.createElement('div');
410
+ div.id = 'sai-resume-prompt';
411
+ div.className = 'sai-msg sai-ai';
412
+ div.innerHTML = `
413
+ Tour paused. Ready when you are.
414
+ <br/>
415
+ <button class="sai-chip" id="sai-resume-btn" style="display:inline-block;margin-top:8px;">
416
+ ▶ Resume from step ${fromIndex + 1}
417
+ </button>
418
+ `;
419
+ msgs.appendChild(div);
420
+ msgs.scrollTop = msgs.scrollHeight;
421
+ (_document$getElementB2 = document.getElementById('sai-resume-btn')) === null || _document$getElementB2 === void 0 || _document$getElementB2.addEventListener('click', () => {
422
+ div.remove();
423
+ if (!_pausedSteps) return;
424
+ const steps = _pausedSteps;
425
+ const idx = _pausedIndex;
426
+ _pausedSteps = null;
427
+ _pausedIndex = 0;
428
+ if (_isOpen) togglePanel();
429
+ runTour(steps.slice(idx));
430
+ });
431
+ if (!_isOpen) togglePanel();
432
+ }
433
+ async function runTour(steps, options = {}) {
434
+ var _config3;
435
+ await ensureShepherd();
436
+ if (_tour) {
437
+ _tour.cancel();
438
+ }
439
+ _cleanups.forEach(fn => fn());
440
+ _cleanups = [];
441
+ _tour = null;
442
+ if (!(steps !== null && steps !== void 0 && steps.length)) return;
443
+ const {
444
+ showProgress = true,
445
+ waitTimeout = 8000
446
+ } = options;
447
+
448
+ // Merge AI steps with feature map
449
+ const mergedSteps = steps.map(mergeWithFeature);
450
+
451
+ // Navigate to the correct screen for the first step if needed
452
+ const firstFeature = (_config3 = _config) === null || _config3 === void 0 || (_config3 = _config3.features) === null || _config3 === void 0 ? void 0 : _config3.find(f => {
453
+ var _mergedSteps$;
454
+ return f.id === ((_mergedSteps$ = mergedSteps[0]) === null || _mergedSteps$ === void 0 ? void 0 : _mergedSteps$.id);
455
+ });
456
+ if (firstFeature) await ensureOnCorrectScreen(firstFeature);
457
+
458
+ // Expand flow[] features into individual Shepherd steps
459
+ const expandedSteps = mergedSteps.flatMap(step => {
460
+ var _config4;
461
+ const feature = (_config4 = _config) === null || _config4 === void 0 || (_config4 = _config4.features) === null || _config4 === void 0 ? void 0 : _config4.find(f => f.id === step.id);
462
+ return feature ? expandFlowSteps(step, feature) : [step];
463
+ });
464
+ const ShepherdClass = typeof Shepherd !== 'undefined' ? Shepherd : window.Shepherd;
465
+ _tour = new ShepherdClass.Tour({
466
+ useModalOverlay: true,
467
+ defaultStepOptions: {
468
+ scrollTo: {
469
+ behavior: 'smooth',
470
+ block: 'center'
471
+ },
472
+ cancelIcon: {
473
+ enabled: true
474
+ },
475
+ classes: 'sai-shepherd-step'
476
+ }
477
+ });
478
+ expandedSteps.forEach((step, i) => {
479
+ var _step$advanceOn, _step$advanceOn2;
480
+ const isLast = i === expandedSteps.length - 1;
481
+ const hasAuto = !!((_step$advanceOn = step.advanceOn) !== null && _step$advanceOn !== void 0 && _step$advanceOn.selector && (_step$advanceOn2 = step.advanceOn) !== null && _step$advanceOn2 !== void 0 && _step$advanceOn2.event);
482
+ const buttons = [];
483
+ if (i > 0) {
484
+ buttons.push({
485
+ text: '← Back',
486
+ action: _tour.back,
487
+ secondary: true
488
+ });
489
+ }
490
+ buttons.push({
491
+ text: isLast ? 'Done ✓' : 'Next →',
492
+ action: isLast ? _tour.complete : _tour.next
493
+ });
494
+ buttons.push({
495
+ text: '⏸ Pause',
496
+ secondary: true,
497
+ action: function () {
498
+ _tour.cancel();
499
+ }
500
+ });
501
+ const shepherdStep = _tour.addStep({
502
+ id: step.id || `sai-step-${i}`,
503
+ title: step.title,
504
+ text: step.text,
505
+ attachTo: step.selector ? {
506
+ element: step.selector,
507
+ on: step.position || 'bottom'
508
+ } : undefined,
509
+ beforeShowPromise: step.waitFor ? () => waitForElement(step.waitFor, waitTimeout) : undefined,
510
+ buttons
511
+ });
512
+ shepherdStep._isLast = isLast;
513
+ if (hasAuto) wireAdvanceOn(shepherdStep, step.advanceOn, _tour);
514
+ if (showProgress && expandedSteps.length > 1) {
515
+ addProgressIndicator(shepherdStep, i, expandedSteps.length);
516
+ }
517
+ });
518
+ _tour.on('complete', () => {
519
+ _cleanups.forEach(fn => fn());
520
+ _cleanups = [];
521
+ _pausedSteps = null;
522
+ _pausedIndex = 0;
523
+ _tour = null;
524
+ });
525
+
526
+ // Cancel → pause instead of hard destroy
527
+ _tour.on('cancel', () => {
528
+ const currentStepEl = _tour.getCurrentStep();
529
+ const currentIdx = currentStepEl ? expandedSteps.findIndex(s => s.id === currentStepEl.id) : 0;
530
+ _cleanups.forEach(fn => fn());
531
+ _cleanups = [];
532
+ _pausedSteps = expandedSteps;
533
+ _pausedIndex = Math.max(0, currentIdx);
534
+ _tour = null;
535
+ showResumeButton(_pausedIndex);
536
+ });
537
+ _tour.start();
538
+ }
539
+ function stepComplete() {
540
+ var _tour2;
541
+ if ((_tour2 = _tour) !== null && _tour2 !== void 0 && _tour2.isActive()) _tour.next();
542
+ }
543
+ function stepFail(message) {
544
+ var _tour3, _el$querySelector;
545
+ if (!((_tour3 = _tour) !== null && _tour3 !== void 0 && _tour3.isActive())) return;
546
+ const current = _tour.getCurrentStep();
547
+ if (!current) return;
548
+ const el = current.getElement();
549
+ el === null || el === void 0 || (_el$querySelector = el.querySelector('.sai-step-error')) === null || _el$querySelector === void 0 || _el$querySelector.remove();
550
+ if (message) {
551
+ var _el$querySelector2;
552
+ const err = document.createElement('div');
553
+ err.className = 'sai-step-error';
554
+ err.textContent = '⚠ ' + message;
555
+ el === null || el === void 0 || (_el$querySelector2 = el.querySelector('.shepherd-text')) === null || _el$querySelector2 === void 0 || _el$querySelector2.appendChild(err);
556
+ }
557
+ }
558
+
559
+ // ═══════════════════════════════════════════════════════════════════════════
560
+ // STYLES
561
+ // ═══════════════════════════════════════════════════════════════════════════
562
+
563
+ function injectStyles(theme, pos) {
564
+ if (document.getElementById('sai-styles')) return;
565
+ const triggerCSS = positionToCSS(pos.trigger);
566
+ const panelCSS = positionToCSS(pos.panel);
567
+ const isDark = theme._isDark;
568
+ const stepBg = isDark ? 'var(--sai-bg)' : '#ffffff';
569
+ const stepSurf = isDark ? 'var(--sai-surface)' : '#f8f8fc';
570
+ const stepText = isDark ? 'var(--sai-text)' : '#1a1a2e';
571
+ const stepBorder = isDark ? 'var(--sai-border)' : '#e4e4f0';
572
+ const style = document.createElement('style');
573
+ style.id = 'sai-styles';
574
+ style.textContent = `
575
+ #sai-trigger, #sai-panel { ${buildCSSVars(theme)} }
576
+
577
+ /* ── Trigger ── */
578
+ #sai-trigger {
579
+ position: fixed; ${triggerCSS};
580
+ width: 54px; height: 54px; border-radius: 50%;
581
+ background: var(--sai-surface); border: 2px solid var(--sai-accent);
582
+ color: var(--sai-text); font-size: 20px; cursor: pointer; z-index: 99998;
583
+ display: flex; align-items: center; justify-content: center;
584
+ box-shadow: 0 4px 20px color-mix(in srgb, var(--sai-accent) 40%, transparent);
585
+ transition: transform .2s ease, box-shadow .2s ease;
586
+ font-family: var(--sai-font); padding: 0;
587
+ }
588
+ #sai-trigger:hover {
589
+ transform: scale(1.08);
590
+ box-shadow: 0 6px 28px color-mix(in srgb, var(--sai-accent) 55%, transparent);
591
+ }
592
+ #sai-trigger .sai-pulse {
593
+ position: absolute; width: 100%; height: 100%; border-radius: 50%;
594
+ background: color-mix(in srgb, var(--sai-accent) 30%, transparent);
595
+ animation: sai-pulse 2.2s ease-out infinite; pointer-events: none;
596
+ }
597
+ #sai-trigger.sai-paused .sai-pulse { animation: none; }
598
+ #sai-trigger.sai-paused::after {
599
+ content: '⏸'; position: absolute; bottom: -2px; right: -2px;
600
+ font-size: 12px; background: var(--sai-accent); border-radius: 50%;
601
+ width: 18px; height: 18px; display: flex; align-items: center;
602
+ justify-content: center; color: #fff; line-height: 1;
603
+ }
604
+ @keyframes sai-pulse {
605
+ 0% { transform: scale(1); opacity: .8; }
606
+ 100% { transform: scale(1.75); opacity: 0; }
607
+ }
608
+
609
+ /* ── Panel ── */
610
+ #sai-panel {
611
+ position: fixed; ${panelCSS};
612
+ width: 340px; background: var(--sai-bg);
613
+ border: 1px solid var(--sai-border); border-radius: var(--sai-radius);
614
+ display: flex; flex-direction: column; z-index: 99999; overflow: hidden;
615
+ box-shadow: 0 16px 48px rgba(0,0,0,.18); font-family: var(--sai-font);
616
+ transform: translateY(12px) scale(.97); opacity: 0; pointer-events: none;
617
+ transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .2s ease;
618
+ max-height: 520px;
619
+ }
620
+ #sai-panel.sai-open { transform: translateY(0) scale(1); opacity: 1; pointer-events: all; }
621
+
622
+ /* ── Header ── */
623
+ #sai-header {
624
+ display: flex; align-items: center; gap: 10px; padding: 13px 15px;
625
+ background: var(--sai-surface); border-bottom: 1px solid var(--sai-border);
626
+ }
627
+ #sai-avatar {
628
+ width: 30px; height: 30px; border-radius: 50%;
629
+ background: linear-gradient(135deg, var(--sai-accent), var(--sai-accent2));
630
+ display: flex; align-items: center; justify-content: center;
631
+ font-size: 14px; flex-shrink: 0; color: #fff;
632
+ }
633
+ #sai-header-info { flex: 1; min-width: 0; }
634
+ #sai-header-info h4 {
635
+ margin: 0; font-size: 13px; font-weight: 600; color: var(--sai-text);
636
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
637
+ }
638
+ #sai-header-info p {
639
+ margin: 0; font-size: 11px; color: var(--sai-text-dim);
640
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
641
+ }
642
+ #sai-close {
643
+ background: none; border: none; color: var(--sai-text-dim); cursor: pointer;
644
+ font-size: 18px; line-height: 1; padding: 0; flex-shrink: 0; transition: color .15s;
645
+ }
646
+ #sai-close:hover { color: var(--sai-text); }
647
+
648
+ /* ── Messages ── */
649
+ #sai-messages {
650
+ flex: 1; overflow-y: auto; padding: 12px;
651
+ display: flex; flex-direction: column; gap: 9px;
652
+ min-height: 160px; max-height: 280px;
653
+ scrollbar-width: thin; scrollbar-color: var(--sai-border) transparent;
654
+ }
655
+ #sai-messages::-webkit-scrollbar { width: 4px; }
656
+ #sai-messages::-webkit-scrollbar-thumb { background: var(--sai-border); border-radius: 2px; }
657
+ .sai-msg {
658
+ max-width: 86%; padding: 8px 11px; border-radius: 11px;
659
+ font-size: 13px; line-height: 1.55; animation: sai-in .18s ease both;
660
+ }
661
+ @keyframes sai-in {
662
+ from { opacity: 0; transform: translateY(5px); }
663
+ to { opacity: 1; transform: translateY(0); }
664
+ }
665
+ .sai-msg.sai-ai {
666
+ background: var(--sai-surface); color: var(--sai-text);
667
+ border-bottom-left-radius: 3px; align-self: flex-start;
668
+ border: 1px solid var(--sai-border);
669
+ }
670
+ .sai-msg.sai-user {
671
+ background: var(--sai-accent); color: #fff;
672
+ border-bottom-right-radius: 3px; align-self: flex-end;
673
+ }
674
+ .sai-msg.sai-error {
675
+ background: color-mix(in srgb, #ef4444 10%, var(--sai-bg));
676
+ color: #ef4444;
677
+ border: 1px solid color-mix(in srgb, #ef4444 25%, var(--sai-bg));
678
+ align-self: flex-start;
679
+ }
680
+
681
+ /* ── Typing indicator ── */
682
+ .sai-typing {
683
+ display: flex; gap: 4px; padding: 9px 12px; align-self: flex-start;
684
+ background: var(--sai-surface); border: 1px solid var(--sai-border);
685
+ border-radius: 11px; border-bottom-left-radius: 3px;
686
+ }
687
+ .sai-typing span {
688
+ width: 5px; height: 5px; border-radius: 50%;
689
+ background: var(--sai-text-dim); animation: sai-bounce 1.2s infinite;
690
+ }
691
+ .sai-typing span:nth-child(2) { animation-delay: .15s; }
692
+ .sai-typing span:nth-child(3) { animation-delay: .3s; }
693
+ @keyframes sai-bounce {
694
+ 0%,80%,100% { transform: translateY(0); }
695
+ 40% { transform: translateY(-5px); }
696
+ }
697
+
698
+ /* ── Suggestions ── */
699
+ #sai-suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
700
+ .sai-chip {
701
+ font-size: 11px; padding: 5px 10px; border-radius: 20px;
702
+ background: transparent; border: 1px solid var(--sai-border);
703
+ color: var(--sai-text-dim); cursor: pointer; font-family: inherit; transition: all .15s;
704
+ }
705
+ .sai-chip:hover {
706
+ border-color: var(--sai-accent); color: var(--sai-accent);
707
+ background: color-mix(in srgb, var(--sai-accent) 6%, transparent);
708
+ }
709
+
710
+ /* ── Input row ── */
711
+ #sai-inputrow {
712
+ display: flex; align-items: center; gap: 7px; padding: 9px 11px;
713
+ border-top: 1px solid var(--sai-border); background: var(--sai-bg);
714
+ }
715
+ #sai-input {
716
+ flex: 1; background: var(--sai-surface); border: 1px solid var(--sai-border);
717
+ border-radius: 8px; padding: 7px 11px; color: var(--sai-text);
718
+ font-size: 13px; outline: none; transition: border-color .15s; font-family: inherit;
719
+ }
720
+ #sai-input::placeholder { color: var(--sai-text-dim); }
721
+ #sai-input:focus { border-color: var(--sai-accent); }
722
+ #sai-send {
723
+ width: 32px; height: 32px; flex-shrink: 0; border-radius: 8px;
724
+ background: var(--sai-accent); border: none; color: #fff; font-size: 14px;
725
+ cursor: pointer; display: flex; align-items: center; justify-content: center;
726
+ transition: filter .15s, transform .1s; line-height: 1;
727
+ }
728
+ #sai-send:hover { filter: brightness(1.1); }
729
+ #sai-send:active { transform: scale(.93); }
730
+ #sai-send:disabled { background: var(--sai-border); cursor: not-allowed; }
731
+
732
+ /* ── Shepherd step overrides ── */
733
+ .sai-shepherd-step {
734
+ background: ${stepBg} !important;
735
+ border: 1px solid ${stepBorder} !important;
736
+ border-radius: 12px !important;
737
+ box-shadow: 0 8px 36px rgba(0,0,0,.18) !important;
738
+ max-width: 290px !important;
739
+ font-family: var(--sai-font, system-ui) !important;
740
+ }
741
+ .sai-shepherd-step.shepherd-has-title .shepherd-content .shepherd-header {
742
+ background: ${stepSurf} !important; padding: 11px 15px 8px !important;
743
+ border-bottom: 1px solid ${stepBorder} !important;
744
+ }
745
+ .sai-shepherd-step .shepherd-title {
746
+ color: var(--sai-accent, #e94560) !important;
747
+ font-size: 13px !important; font-weight: 700 !important;
748
+ }
749
+ .sai-shepherd-step .shepherd-text {
750
+ color: ${stepText} !important; font-size: 13px !important;
751
+ line-height: 1.6 !important; padding: 10px 15px !important;
752
+ }
753
+ .sai-shepherd-step .shepherd-footer {
754
+ border-top: 1px solid ${stepBorder} !important; padding: 8px 11px !important;
755
+ background: ${stepBg} !important; display: flex; gap: 5px; flex-wrap: wrap;
756
+ }
757
+ .sai-shepherd-step .shepherd-button {
758
+ background: var(--sai-accent, #e94560) !important; color: #fff !important;
759
+ border: none !important; border-radius: 6px !important; padding: 6px 13px !important;
760
+ font-size: 12px !important; font-weight: 600 !important; cursor: pointer !important;
761
+ transition: filter .15s !important; font-family: var(--sai-font, system-ui) !important;
762
+ }
763
+ .sai-shepherd-step .shepherd-button:hover { filter: brightness(1.1) !important; }
764
+ .sai-shepherd-step .shepherd-button-secondary {
765
+ background: transparent !important; color: var(--sai-text-dim, #888) !important;
766
+ border: 1px solid ${stepBorder} !important;
767
+ }
768
+ .sai-shepherd-step .shepherd-button-secondary:hover {
769
+ background: ${stepSurf} !important; color: ${stepText} !important;
770
+ }
771
+ .sai-shepherd-step .shepherd-cancel-icon { color: var(--sai-text-dim, #888) !important; }
772
+ .sai-shepherd-step .shepherd-cancel-icon:hover { color: ${stepText} !important; }
773
+ .sai-shepherd-step[data-popper-placement] > .shepherd-arrow::before {
774
+ background: ${stepBorder} !important;
775
+ }
776
+
777
+ /* ── Progress bar ── */
778
+ .sai-progress { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }
779
+ .sai-progress-bar {
780
+ width: 60px; height: 3px; border-radius: 2px; background: ${stepBorder}; overflow: hidden;
781
+ }
782
+ .sai-progress-fill {
783
+ height: 100%; border-radius: 2px;
784
+ background: var(--sai-accent, #e94560); transition: width .3s ease;
785
+ }
786
+ .sai-progress-label {
787
+ font-size: 10px; color: var(--sai-text-dim, #888);
788
+ white-space: nowrap; font-family: var(--sai-font, system-ui);
789
+ }
790
+
791
+ /* ── Step error ── */
792
+ .sai-step-error {
793
+ margin-top: 8px; padding: 6px 10px;
794
+ background: color-mix(in srgb, #ef4444 12%, ${stepBg});
795
+ border: 1px solid color-mix(in srgb, #ef4444 25%, ${stepBorder});
796
+ border-radius: 6px; color: #ef4444; font-size: 12px; line-height: 1.5;
797
+ animation: sai-in .18s ease;
798
+ }
799
+ `;
800
+ document.head.appendChild(style);
801
+ }
802
+
803
+ // ═══════════════════════════════════════════════════════════════════════════
804
+ // CHAT UI
805
+ // ═══════════════════════════════════════════════════════════════════════════
806
+
807
+ function buildChat(theme, positionCSS) {
808
+ var _config$suggestions, _config$theme, _config$theme2;
809
+ if (document.getElementById('sai-trigger')) return;
810
+ injectStyles(theme, positionCSS);
811
+ const trigger = document.createElement('button');
812
+ trigger.id = 'sai-trigger';
813
+ trigger.title = 'Need help?';
814
+ trigger.setAttribute('aria-label', 'Open help assistant');
815
+ trigger.innerHTML = '<span class="sai-pulse" aria-hidden="true"></span>✦';
816
+ document.body.appendChild(trigger);
817
+ const panel = document.createElement('div');
818
+ panel.id = 'sai-panel';
819
+ panel.setAttribute('role', 'dialog');
820
+ panel.setAttribute('aria-label', `${_config.assistantName || 'AI Guide'} chat`);
821
+ panel.innerHTML = `
822
+ <div id="sai-header">
823
+ <div id="sai-avatar" aria-hidden="true">✦</div>
824
+ <div id="sai-header-info">
825
+ <h4>${escHTML(_config.assistantName || 'AI Guide')}</h4>
826
+ <p>Ask me anything about ${escHTML(_config.appName)}</p>
827
+ </div>
828
+ <button id="sai-close" aria-label="Close help assistant">×</button>
829
+ </div>
830
+ <div id="sai-messages" role="log" aria-live="polite"></div>
831
+ <div id="sai-suggestions" aria-label="Suggested questions"></div>
832
+ <div id="sai-inputrow">
833
+ <input id="sai-input" type="text" placeholder="What do you need help with?"
834
+ autocomplete="off" aria-label="Ask a question"/>
835
+ <button id="sai-send" aria-label="Send message">➤</button>
836
+ </div>
837
+ `;
838
+ document.body.appendChild(panel);
839
+ if ((_config$suggestions = _config.suggestions) !== null && _config$suggestions !== void 0 && _config$suggestions.length) {
840
+ const container = panel.querySelector('#sai-suggestions');
841
+ _config.suggestions.forEach(s => {
842
+ const btn = document.createElement('button');
843
+ btn.className = 'sai-chip';
844
+ btn.textContent = s;
845
+ btn.addEventListener('click', () => handleSend(s));
846
+ container.appendChild(btn);
847
+ });
848
+ }
849
+ trigger.addEventListener('click', togglePanel);
850
+ panel.querySelector('#sai-close').addEventListener('click', togglePanel);
851
+ panel.querySelector('#sai-send').addEventListener('click', () => {
852
+ const v = panel.querySelector('#sai-input').value.trim();
853
+ if (v) handleSend(v);
854
+ });
855
+ panel.querySelector('#sai-input').addEventListener('keydown', e => {
856
+ if (e.key === 'Enter' && !e.shiftKey) {
857
+ e.preventDefault();
858
+ const v = e.target.value.trim();
859
+ if (v) handleSend(v);
860
+ }
861
+ });
862
+ addMsg('ai', `Hey! 👋 I can guide you through ${_config.appName}. What would you like to do?`);
863
+
864
+ // Auto theme switching
865
+ if (((_config$theme = _config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.mode) === 'auto' || !((_config$theme2 = _config.theme) !== null && _config$theme2 !== void 0 && _config$theme2.mode)) {
866
+ _mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
867
+ _mediaQuery.addEventListener('change', () => {
868
+ var _document$getElementB3;
869
+ const newTheme = resolveTheme(_config.theme);
870
+ applyTheme(newTheme);
871
+ (_document$getElementB3 = document.getElementById('sai-styles')) === null || _document$getElementB3 === void 0 || _document$getElementB3.remove();
872
+ injectStyles(newTheme, positionCSS);
873
+ });
874
+ }
875
+ }
876
+ function escHTML(str) {
877
+ return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
878
+ }
879
+ function togglePanel() {
880
+ var _document$getElementB4, _document$getElementB5, _document$getElementB6;
881
+ _isOpen = !_isOpen;
882
+ (_document$getElementB4 = document.getElementById('sai-panel')) === null || _document$getElementB4 === void 0 || _document$getElementB4.classList.toggle('sai-open', _isOpen);
883
+ (_document$getElementB5 = document.getElementById('sai-trigger')) === null || _document$getElementB5 === void 0 || _document$getElementB5.classList.toggle('sai-paused', !!_pausedSteps);
884
+ if (_isOpen) (_document$getElementB6 = document.getElementById('sai-input')) === null || _document$getElementB6 === void 0 || _document$getElementB6.focus();
885
+ }
886
+ function addMsg(type, text) {
887
+ const msgs = document.getElementById('sai-messages');
888
+ if (!msgs) return;
889
+ const div = document.createElement('div');
890
+ div.className = `sai-msg sai-${type}`;
891
+ div.textContent = text;
892
+ msgs.appendChild(div);
893
+ msgs.scrollTop = msgs.scrollHeight;
894
+ }
895
+ function showTyping() {
896
+ const msgs = document.getElementById('sai-messages');
897
+ const el = document.createElement('div');
898
+ el.className = 'sai-typing';
899
+ el.id = 'sai-typing';
900
+ el.innerHTML = '<span></span><span></span><span></span>';
901
+ msgs.appendChild(el);
902
+ msgs.scrollTop = msgs.scrollHeight;
903
+ }
904
+ function hideTyping() {
905
+ var _document$getElementB7;
906
+ (_document$getElementB7 = document.getElementById('sai-typing')) === null || _document$getElementB7 === void 0 || _document$getElementB7.remove();
907
+ }
908
+ function setDisabled(d) {
909
+ ['sai-input', 'sai-send'].forEach(id => {
910
+ const el = document.getElementById(id);
911
+ if (el) el.disabled = d;
912
+ });
913
+ }
914
+ async function handleSend(text) {
915
+ var _document$getElementB8, _document$getElementB9;
916
+ const input = document.getElementById('sai-input');
917
+ if (input) input.value = '';
918
+ document.getElementById('sai-suggestions').style.display = 'none';
919
+
920
+ // New message clears any existing pause state
921
+ _pausedSteps = null;
922
+ _pausedIndex = 0;
923
+ (_document$getElementB8 = document.getElementById('sai-resume-prompt')) === null || _document$getElementB8 === void 0 || _document$getElementB8.remove();
924
+ (_document$getElementB9 = document.getElementById('sai-trigger')) === null || _document$getElementB9 === void 0 || _document$getElementB9.classList.remove('sai-paused');
925
+ addMsg('user', text);
926
+ setDisabled(true);
927
+ showTyping();
928
+ try {
929
+ var _result$steps;
930
+ const result = await callAI(text);
931
+ hideTyping();
932
+ addMsg('ai', result.message);
933
+ if ((_result$steps = result.steps) !== null && _result$steps !== void 0 && _result$steps.length) {
934
+ setTimeout(() => {
935
+ togglePanel();
936
+ runTour(result.steps);
937
+ }, 600);
938
+ }
939
+ } catch (err) {
940
+ hideTyping();
941
+ addMsg('error', err.message || 'Something went wrong. Please try again.');
942
+ console.error('[Eventop]', err);
943
+ } finally {
944
+ var _document$getElementB0;
945
+ setDisabled(false);
946
+ (_document$getElementB0 = document.getElementById('sai-input')) === null || _document$getElementB0 === void 0 || _document$getElementB0.focus();
947
+ }
948
+ }
949
+
950
+ // ═══════════════════════════════════════════════════════════════════════════
951
+ // PUBLIC API
952
+ // ═══════════════════════════════════════════════════════════════════════════
953
+
954
+ const Eventop = {
955
+ providers,
956
+ init(opts = {}) {
957
+ var _opts$config, _opts$config2;
958
+ if (!opts.provider) throw new Error('[Eventop] provider is required');
959
+ if (!((_opts$config = opts.config) !== null && _opts$config !== void 0 && _opts$config.appName)) throw new Error('[Eventop] config.appName is required');
960
+ if (!((_opts$config2 = opts.config) !== null && _opts$config2 !== void 0 && _opts$config2.features)) throw new Error('[Eventop] config.features is required');
961
+ _provider = opts.provider;
962
+ _config = opts.config;
963
+ const theme = resolveTheme(_config.theme);
964
+ const posCSS = resolvePosition(_config.position);
965
+ if (document.readyState === 'loading') {
966
+ document.addEventListener('DOMContentLoaded', () => buildChat(theme, posCSS));
967
+ } else {
968
+ buildChat(theme, posCSS);
969
+ }
970
+ ensureShepherd();
971
+ },
972
+ open() {
973
+ if (!_isOpen) togglePanel();
974
+ },
975
+ close() {
976
+ if (_isOpen) togglePanel();
977
+ },
978
+ runTour,
979
+ cancelTour() {
980
+ var _document$getElementB1, _document$getElementB10;
981
+ _pausedSteps = null;
982
+ _pausedIndex = 0;
983
+ if (_tour) {
984
+ _tour.cancel();
985
+ }
986
+ _cleanups.forEach(fn => fn());
987
+ _cleanups = [];
988
+ _tour = null;
989
+ (_document$getElementB1 = document.getElementById('sai-trigger')) === null || _document$getElementB1 === void 0 || _document$getElementB1.classList.remove('sai-paused');
990
+ (_document$getElementB10 = document.getElementById('sai-resume-prompt')) === null || _document$getElementB10 === void 0 || _document$getElementB10.remove();
991
+ },
992
+ resumeTour() {
993
+ var _document$getElementB11, _document$getElementB12;
994
+ if (!_pausedSteps) return;
995
+ const steps = _pausedSteps;
996
+ const idx = _pausedIndex;
997
+ _pausedSteps = null;
998
+ _pausedIndex = 0;
999
+ (_document$getElementB11 = document.getElementById('sai-resume-prompt')) === null || _document$getElementB11 === void 0 || _document$getElementB11.remove();
1000
+ (_document$getElementB12 = document.getElementById('sai-trigger')) === null || _document$getElementB12 === void 0 || _document$getElementB12.classList.remove('sai-paused');
1001
+ if (_isOpen) togglePanel();
1002
+ runTour(steps.slice(idx));
1003
+ },
1004
+ isPaused() {
1005
+ return !!_pausedSteps;
1006
+ },
1007
+ isActive() {
1008
+ var _tour4;
1009
+ return !!((_tour4 = _tour) !== null && _tour4 !== void 0 && _tour4.isActive());
1010
+ },
1011
+ stepComplete,
1012
+ stepFail,
1013
+ /** @internal — used by the React package to sync the live feature registry */
1014
+ _updateConfig(partial) {
1015
+ if (!_config) return;
1016
+ _config = {
1017
+ ..._config,
1018
+ ...partial
1019
+ };
1020
+ }
1021
+ };
1022
+ return Eventop;
1023
+ });
1024
+ })(core);
1025
+
6
1026
  /**
7
1027
  * Root context — holds the global feature registry.
8
1028
  * Set by EventopAIProvider at the root of the app.
@@ -202,8 +1222,9 @@ function EventopProvider({
202
1222
  const registry = react.useRef(createFeatureRegistry()).current;
203
1223
  const sdkReady = react.useRef(false);
204
1224
  const syncToSDK = react.useCallback(() => {
1225
+ var _window$Eventop$_upda, _window$Eventop;
205
1226
  if (!sdkReady.current || !window.Eventop) return;
206
- window.Eventop._updateConfig?.({
1227
+ (_window$Eventop$_upda = (_window$Eventop = window.Eventop)._updateConfig) === null || _window$Eventop$_upda === void 0 || _window$Eventop$_upda.call(_window$Eventop, {
207
1228
  features: registry.snapshot()
208
1229
  });
209
1230
  }, [registry]);
@@ -227,8 +1248,9 @@ function EventopProvider({
227
1248
  boot();
228
1249
  const unsub = registry.subscribe(syncToSDK);
229
1250
  return () => {
1251
+ var _window$Eventop2;
230
1252
  unsub();
231
- window.Eventop?.cancelTour();
1253
+ (_window$Eventop2 = window.Eventop) === null || _window$Eventop2 === void 0 || _window$Eventop2.cancelTour();
232
1254
  };
233
1255
  }, []);
234
1256
  const ctx = {
@@ -383,15 +1405,42 @@ function EventopStep({
383
1405
  function useEventopAI() {
384
1406
  const sdk = () => window.Eventop;
385
1407
  return {
386
- open: () => sdk()?.open(),
387
- close: () => sdk()?.close(),
388
- cancelTour: () => sdk()?.cancelTour(),
389
- resumeTour: () => sdk()?.resumeTour(),
390
- isActive: () => sdk()?.isActive() ?? false,
391
- isPaused: () => sdk()?.isPaused() ?? false,
392
- stepComplete: () => sdk()?.stepComplete(),
393
- stepFail: msg => sdk()?.stepFail(msg),
394
- runTour: steps => sdk()?.runTour(steps)
1408
+ open: () => {
1409
+ var _sdk;
1410
+ return (_sdk = sdk()) === null || _sdk === void 0 ? void 0 : _sdk.open();
1411
+ },
1412
+ close: () => {
1413
+ var _sdk2;
1414
+ return (_sdk2 = sdk()) === null || _sdk2 === void 0 ? void 0 : _sdk2.close();
1415
+ },
1416
+ cancelTour: () => {
1417
+ var _sdk3;
1418
+ return (_sdk3 = sdk()) === null || _sdk3 === void 0 ? void 0 : _sdk3.cancelTour();
1419
+ },
1420
+ resumeTour: () => {
1421
+ var _sdk4;
1422
+ return (_sdk4 = sdk()) === null || _sdk4 === void 0 ? void 0 : _sdk4.resumeTour();
1423
+ },
1424
+ isActive: () => {
1425
+ var _sdk5;
1426
+ return ((_sdk5 = sdk()) === null || _sdk5 === void 0 ? void 0 : _sdk5.isActive()) ?? false;
1427
+ },
1428
+ isPaused: () => {
1429
+ var _sdk6;
1430
+ return ((_sdk6 = sdk()) === null || _sdk6 === void 0 ? void 0 : _sdk6.isPaused()) ?? false;
1431
+ },
1432
+ stepComplete: () => {
1433
+ var _sdk7;
1434
+ return (_sdk7 = sdk()) === null || _sdk7 === void 0 ? void 0 : _sdk7.stepComplete();
1435
+ },
1436
+ stepFail: msg => {
1437
+ var _sdk8;
1438
+ return (_sdk8 = sdk()) === null || _sdk8 === void 0 ? void 0 : _sdk8.stepFail(msg);
1439
+ },
1440
+ runTour: steps => {
1441
+ var _sdk9;
1442
+ return (_sdk9 = sdk()) === null || _sdk9 === void 0 ? void 0 : _sdk9.runTour(steps);
1443
+ }
395
1444
  };
396
1445
  }
397
1446
 
@@ -433,10 +1482,22 @@ function useEventopTour() {
433
1482
  }, []);
434
1483
  return {
435
1484
  ...state,
436
- resume: react.useCallback(() => window.Eventop?.resumeTour(), []),
437
- cancel: react.useCallback(() => window.Eventop?.cancelTour(), []),
438
- open: react.useCallback(() => window.Eventop?.open(), []),
439
- close: react.useCallback(() => window.Eventop?.close(), [])
1485
+ resume: react.useCallback(() => {
1486
+ var _window$Eventop;
1487
+ return (_window$Eventop = window.Eventop) === null || _window$Eventop === void 0 ? void 0 : _window$Eventop.resumeTour();
1488
+ }, []),
1489
+ cancel: react.useCallback(() => {
1490
+ var _window$Eventop2;
1491
+ return (_window$Eventop2 = window.Eventop) === null || _window$Eventop2 === void 0 ? void 0 : _window$Eventop2.cancelTour();
1492
+ }, []),
1493
+ open: react.useCallback(() => {
1494
+ var _window$Eventop3;
1495
+ return (_window$Eventop3 = window.Eventop) === null || _window$Eventop3 === void 0 ? void 0 : _window$Eventop3.open();
1496
+ }, []),
1497
+ close: react.useCallback(() => {
1498
+ var _window$Eventop4;
1499
+ return (_window$Eventop4 = window.Eventop) === null || _window$Eventop4 === void 0 ? void 0 : _window$Eventop4.close();
1500
+ }, [])
440
1501
  };
441
1502
  }
442
1503