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