@guidelytech/guide-runtime 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -2
- package/dist/index.cjs +2381 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +390 -0
- package/dist/index.d.ts +390 -0
- package/dist/index.js +2312 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2381 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
DEFAULT_THEME: () => DEFAULT_THEME,
|
|
26
|
+
HOST_ID: () => HOST_ID2,
|
|
27
|
+
STYLES: () => STYLES,
|
|
28
|
+
TargetTimeoutError: () => TargetTimeoutError,
|
|
29
|
+
anchor: () => anchor,
|
|
30
|
+
applyTheme: () => applyTheme,
|
|
31
|
+
buildCard: () => buildCard,
|
|
32
|
+
createScope: () => createScope,
|
|
33
|
+
describeElement: () => describeElement,
|
|
34
|
+
destroyHost: () => destroyHost,
|
|
35
|
+
ensureHost: () => ensureHost,
|
|
36
|
+
generateSelectors: () => generateSelectors,
|
|
37
|
+
highlightSelectors: () => highlightSelectors,
|
|
38
|
+
isAnchoredStep: () => isAnchoredStep,
|
|
39
|
+
isChecklistComplete: () => isChecklistComplete,
|
|
40
|
+
isGuidelyElement: () => isGuidelyElement,
|
|
41
|
+
isQuestionVisible: () => isQuestionVisible,
|
|
42
|
+
isStableId: () => isStableId,
|
|
43
|
+
isVisible: () => isVisible,
|
|
44
|
+
normalizeText: () => normalizeText,
|
|
45
|
+
prefersReducedMotion: () => prefersReducedMotion,
|
|
46
|
+
previewStep: () => previewStep,
|
|
47
|
+
querySelectorStrategy: () => querySelectorStrategy,
|
|
48
|
+
renderBanner: () => renderBanner,
|
|
49
|
+
renderChecklist: () => renderChecklist,
|
|
50
|
+
renderCustom: () => renderCustom,
|
|
51
|
+
renderHotspot: () => renderHotspot,
|
|
52
|
+
renderModal: () => renderModal,
|
|
53
|
+
renderResourceCenter: () => renderResourceCenter,
|
|
54
|
+
renderSlideout: () => renderSlideout,
|
|
55
|
+
renderSpotlight: () => renderSpotlight,
|
|
56
|
+
renderStep: () => renderStep,
|
|
57
|
+
renderSurvey: () => renderSurvey,
|
|
58
|
+
renderTooltip: () => renderTooltip,
|
|
59
|
+
resolveTarget: () => resolveTarget,
|
|
60
|
+
resolveTheme: () => resolveTheme,
|
|
61
|
+
runGuide: () => runGuide,
|
|
62
|
+
sanitizeHtml: () => sanitizeHtml,
|
|
63
|
+
sanitizeToFragment: () => sanitizeToFragment,
|
|
64
|
+
setSanitizedHtml: () => setSanitizedHtml,
|
|
65
|
+
startAuthoring: () => startAuthoring,
|
|
66
|
+
textSnapshotOf: () => textSnapshotOf,
|
|
67
|
+
trackRect: () => trackRect,
|
|
68
|
+
urlMatches: () => urlMatches,
|
|
69
|
+
waitForTarget: () => waitForTarget
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(index_exports);
|
|
72
|
+
|
|
73
|
+
// src/selectors.ts
|
|
74
|
+
var import_runtime = require("@guidelytech/shared/runtime");
|
|
75
|
+
function urlMatches(pattern, url) {
|
|
76
|
+
if (!pattern) return true;
|
|
77
|
+
if ((0, import_runtime.matchUrlPattern)(pattern, url)) return true;
|
|
78
|
+
try {
|
|
79
|
+
const u = new URL(url, "http://localhost");
|
|
80
|
+
if (!pattern.includes("?") && !pattern.includes("#")) return (0, import_runtime.matchUrlPattern)(pattern, u.pathname) || (0, import_runtime.matchUrlPattern)(pattern, u.origin + u.pathname);
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
var TEXT_CANDIDATES = "button, a, [role='button'], [role='link'], [role='tab'], [role='menuitem'], h1, h2, h3, h4, h5, h6, label, summary";
|
|
86
|
+
var HOST_ID = "guidely-root";
|
|
87
|
+
function docOf(root) {
|
|
88
|
+
return root.nodeType === 9 ? root : root.ownerDocument;
|
|
89
|
+
}
|
|
90
|
+
function hasLayout(doc) {
|
|
91
|
+
const de = doc.documentElement;
|
|
92
|
+
if (!de) return false;
|
|
93
|
+
const r = de.getBoundingClientRect();
|
|
94
|
+
return r.width > 0 || r.height > 0;
|
|
95
|
+
}
|
|
96
|
+
function normalizeText(text) {
|
|
97
|
+
return (text || "").replace(/\s+/g, " ").trim();
|
|
98
|
+
}
|
|
99
|
+
function isVisible(el2) {
|
|
100
|
+
if (!el2.isConnected) return false;
|
|
101
|
+
const doc = el2.ownerDocument;
|
|
102
|
+
const win = doc.defaultView;
|
|
103
|
+
let cur = el2;
|
|
104
|
+
while (cur && cur !== doc.documentElement) {
|
|
105
|
+
if (cur.hidden) return false;
|
|
106
|
+
if (win) {
|
|
107
|
+
const cs = win.getComputedStyle(cur);
|
|
108
|
+
if (cs.display === "none" || cs.visibility === "hidden") return false;
|
|
109
|
+
}
|
|
110
|
+
cur = cur.parentElement ?? cur.getRootNode().host ?? null;
|
|
111
|
+
}
|
|
112
|
+
if (hasLayout(doc)) {
|
|
113
|
+
const r = el2.getBoundingClientRect();
|
|
114
|
+
if (r.width === 0 && r.height === 0) return false;
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
function isGuidelyElement(el2) {
|
|
119
|
+
if (!el2) return false;
|
|
120
|
+
const root = el2.getRootNode();
|
|
121
|
+
if (root instanceof ShadowRoot && root.host.id === HOST_ID) return true;
|
|
122
|
+
return el2.id === HOST_ID || !!el2.closest?.(`#${HOST_ID}`);
|
|
123
|
+
}
|
|
124
|
+
function safeQueryAll(root, selector) {
|
|
125
|
+
try {
|
|
126
|
+
return Array.from(root.querySelectorAll(selector));
|
|
127
|
+
} catch {
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function escapeCss(value) {
|
|
132
|
+
const g = globalThis;
|
|
133
|
+
if (g.CSS && typeof g.CSS.escape === "function") return g.CSS.escape(value);
|
|
134
|
+
return value.replace(/["\\]/g, "\\$&");
|
|
135
|
+
}
|
|
136
|
+
function queryXPath(root, expr) {
|
|
137
|
+
const doc = docOf(root);
|
|
138
|
+
const d = doc;
|
|
139
|
+
if (typeof d.evaluate !== "function") return [];
|
|
140
|
+
try {
|
|
141
|
+
const result = d.evaluate(expr, root, null, 7, null);
|
|
142
|
+
const out = [];
|
|
143
|
+
for (let i = 0; i < result.snapshotLength; i++) {
|
|
144
|
+
const n = result.snapshotItem(i);
|
|
145
|
+
if (n && n.nodeType === 1) out.push(n);
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
} catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function queryText(root, text) {
|
|
153
|
+
const needle = normalizeText(text).toLowerCase();
|
|
154
|
+
if (!needle) return [];
|
|
155
|
+
const candidates = safeQueryAll(root, TEXT_CANDIDATES);
|
|
156
|
+
const exact = candidates.filter((c) => normalizeText(c.textContent).toLowerCase() === needle);
|
|
157
|
+
if (exact.length) return exact;
|
|
158
|
+
return candidates.filter((c) => normalizeText(c.textContent).toLowerCase().includes(needle));
|
|
159
|
+
}
|
|
160
|
+
function querySelectorStrategy(strategy, root) {
|
|
161
|
+
const value = strategy.value.trim();
|
|
162
|
+
if (!value) return [];
|
|
163
|
+
switch (strategy.kind) {
|
|
164
|
+
case "id": {
|
|
165
|
+
const id = value.startsWith("#") ? value.slice(1) : value;
|
|
166
|
+
return safeQueryAll(root, `#${escapeCss(id)}`);
|
|
167
|
+
}
|
|
168
|
+
case "data-attr":
|
|
169
|
+
case "aria":
|
|
170
|
+
case "css":
|
|
171
|
+
return safeQueryAll(root, value.startsWith("[") || /^[a-z*#.[]/i.test(value) ? value : `[${value}]`);
|
|
172
|
+
case "text":
|
|
173
|
+
return queryText(root, value);
|
|
174
|
+
case "xpath":
|
|
175
|
+
return queryXPath(root, value);
|
|
176
|
+
default:
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function resolveTarget(target, root = document) {
|
|
181
|
+
const selectors = Array.isArray(target) ? target : target.selectors;
|
|
182
|
+
for (const strategy of selectors) {
|
|
183
|
+
const matches = querySelectorStrategy(strategy, root).filter((el2) => !isGuidelyElement(el2) && isVisible(el2));
|
|
184
|
+
if (matches.length === 1) return matches[0];
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
var TargetTimeoutError = class extends Error {
|
|
189
|
+
constructor(message = "Target element not found before timeout") {
|
|
190
|
+
super(message);
|
|
191
|
+
__publicField(this, "name", "TargetTimeoutError");
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
function waitForTarget(target, options = {}) {
|
|
195
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
196
|
+
const root = options.root ?? document;
|
|
197
|
+
const pollMs = Math.min(250, Math.max(16, options.pollMs ?? 250));
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
const immediate = resolveTarget(target, root);
|
|
200
|
+
if (immediate) return resolve(immediate);
|
|
201
|
+
if (options.signal?.aborted) return reject(new DOMException("Aborted", "AbortError"));
|
|
202
|
+
let done = false;
|
|
203
|
+
let observer = null;
|
|
204
|
+
let timer = null;
|
|
205
|
+
let timeout = null;
|
|
206
|
+
const cleanup = () => {
|
|
207
|
+
done = true;
|
|
208
|
+
observer?.disconnect();
|
|
209
|
+
if (timer) clearInterval(timer);
|
|
210
|
+
if (timeout) clearTimeout(timeout);
|
|
211
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
212
|
+
};
|
|
213
|
+
const check = () => {
|
|
214
|
+
if (done) return;
|
|
215
|
+
const el2 = resolveTarget(target, root);
|
|
216
|
+
if (el2) {
|
|
217
|
+
cleanup();
|
|
218
|
+
resolve(el2);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const onAbort = () => {
|
|
222
|
+
cleanup();
|
|
223
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
224
|
+
};
|
|
225
|
+
options.signal?.addEventListener("abort", onAbort);
|
|
226
|
+
const observeRoot = root.nodeType === 9 ? root.documentElement : root;
|
|
227
|
+
if (typeof MutationObserver !== "undefined" && observeRoot) {
|
|
228
|
+
observer = new MutationObserver(check);
|
|
229
|
+
observer.observe(observeRoot, { childList: true, subtree: true, attributes: true, attributeFilter: ["class", "style", "hidden", "id", "data-tour", "aria-label"] });
|
|
230
|
+
}
|
|
231
|
+
timer = setInterval(check, pollMs);
|
|
232
|
+
if (timeoutMs > 0) {
|
|
233
|
+
timeout = setTimeout(() => {
|
|
234
|
+
cleanup();
|
|
235
|
+
reject(new TargetTimeoutError());
|
|
236
|
+
}, timeoutMs);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
var GENERATED_ID = /(\d{4,}|:r[0-9a-z]+:|^radix-|^headlessui-|^mui-|^ember\d|^react-|^\w*-\d+$|__|^[a-f0-9]{8,}$|^svelte-)/i;
|
|
241
|
+
var GENERATED_CLASS = /(^css-|^sc-|^jss\d|^svelte-|^emotion-|^chakra-|^Mui|^_|[0-9a-f]{6,}|^\w{1,2}$|^[a-z]+-\d+$|[:[\]/])/;
|
|
242
|
+
var PREFERRED_DATA_ATTRS = ["data-testid", "data-tour", "data-test", "data-test-id", "data-cy", "data-qa", "data-id", "data-name", "data-guidely"];
|
|
243
|
+
var IGNORED_DATA_ATTRS = /^data-(state|v-|reactid|react|radix|headlessui|svelte|hydrated|orientation|highlighted|focus|key|index|rbd|dnd|rk-|sveltekit)/i;
|
|
244
|
+
function isStableId(id) {
|
|
245
|
+
return !!id && /^[A-Za-z][\w-]*$/.test(id) && !GENERATED_ID.test(id);
|
|
246
|
+
}
|
|
247
|
+
function isStableClass(cls) {
|
|
248
|
+
return !!cls && !GENERATED_CLASS.test(cls) && cls.length <= 40;
|
|
249
|
+
}
|
|
250
|
+
function uniqueIn(doc, selector, el2) {
|
|
251
|
+
const all = safeQueryAll(doc, selector);
|
|
252
|
+
return all.length === 1 && all[0] === el2;
|
|
253
|
+
}
|
|
254
|
+
function attrSelector(name, value) {
|
|
255
|
+
return `[${name}='${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}']`;
|
|
256
|
+
}
|
|
257
|
+
function cssPath(el2, doc) {
|
|
258
|
+
const segments = [];
|
|
259
|
+
let cur = el2;
|
|
260
|
+
while (cur && cur.nodeType === 1 && cur !== doc.body && cur !== doc.documentElement) {
|
|
261
|
+
const tag = cur.tagName.toLowerCase();
|
|
262
|
+
if (isStableId(cur.id)) {
|
|
263
|
+
segments.unshift(`#${cur.id}`);
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
let seg = tag;
|
|
267
|
+
const parent = cur.parentElement;
|
|
268
|
+
if (parent) {
|
|
269
|
+
const sameTag = Array.from(parent.children).filter((c) => c.tagName === cur.tagName);
|
|
270
|
+
if (sameTag.length > 1) {
|
|
271
|
+
const stableCls = Array.from(cur.classList).find((c) => isStableClass(c) && sameTag.filter((s) => s.classList.contains(c)).length === 1);
|
|
272
|
+
seg += stableCls ? `.${escapeCss(stableCls)}` : `:nth-of-type(${sameTag.indexOf(cur) + 1})`;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
segments.unshift(seg);
|
|
276
|
+
const candidate = segments.join(" > ");
|
|
277
|
+
if (uniqueIn(doc, candidate, el2)) return candidate;
|
|
278
|
+
cur = parent;
|
|
279
|
+
}
|
|
280
|
+
const full = segments.join(" > ");
|
|
281
|
+
return uniqueIn(doc, full, el2) ? full : null;
|
|
282
|
+
}
|
|
283
|
+
function textSnapshotOf(el2) {
|
|
284
|
+
const he = el2;
|
|
285
|
+
const own = normalizeText(he.innerText ?? el2.textContent);
|
|
286
|
+
const alt = normalizeText(el2.getAttribute("aria-label") || el2.getAttribute("title") || el2.getAttribute("placeholder") || el2.getAttribute("alt") || el2.value);
|
|
287
|
+
return (own || alt).slice(0, 200);
|
|
288
|
+
}
|
|
289
|
+
function generateSelectors(el2) {
|
|
290
|
+
const doc = el2.ownerDocument;
|
|
291
|
+
const out = [];
|
|
292
|
+
const seen = /* @__PURE__ */ new Set();
|
|
293
|
+
const push = (s) => {
|
|
294
|
+
const k = `${s.kind}:${s.value}`;
|
|
295
|
+
if (!seen.has(k)) {
|
|
296
|
+
seen.add(k);
|
|
297
|
+
out.push(s);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
const tag = el2.tagName.toLowerCase();
|
|
301
|
+
if (isStableId(el2.id) && uniqueIn(doc, `#${escapeCss(el2.id)}`, el2)) push({ kind: "id", value: `#${el2.id}`, label: `id ${el2.id}` });
|
|
302
|
+
const dataAttrs = Array.from(el2.attributes).filter((a) => a.name.startsWith("data-") && !IGNORED_DATA_ATTRS.test(a.name) && a.value && a.value.length <= 120 && !/\d{5,}/.test(a.value));
|
|
303
|
+
dataAttrs.sort((a, b) => {
|
|
304
|
+
const ia = PREFERRED_DATA_ATTRS.indexOf(a.name);
|
|
305
|
+
const ib = PREFERRED_DATA_ATTRS.indexOf(b.name);
|
|
306
|
+
return (ia === -1 ? 99 : ia) - (ib === -1 ? 99 : ib);
|
|
307
|
+
});
|
|
308
|
+
for (const a of dataAttrs) {
|
|
309
|
+
const sel = attrSelector(a.name, a.value);
|
|
310
|
+
if (uniqueIn(doc, sel, el2)) push({ kind: "data-attr", value: sel, label: `${a.name}=${a.value}` });
|
|
311
|
+
else if (uniqueIn(doc, tag + sel, el2)) push({ kind: "data-attr", value: tag + sel, label: `${a.name}=${a.value}` });
|
|
312
|
+
}
|
|
313
|
+
const aria = el2.getAttribute("aria-label");
|
|
314
|
+
if (aria && aria.length <= 120) {
|
|
315
|
+
const sel = attrSelector("aria-label", aria);
|
|
316
|
+
if (uniqueIn(doc, sel, el2)) push({ kind: "aria", value: sel, label: aria });
|
|
317
|
+
else if (uniqueIn(doc, tag + sel, el2)) push({ kind: "aria", value: tag + sel, label: aria });
|
|
318
|
+
}
|
|
319
|
+
const name = el2.getAttribute("name");
|
|
320
|
+
if (name && uniqueIn(doc, tag + attrSelector("name", name), el2)) push({ kind: "css", value: tag + attrSelector("name", name), label: `${tag} name=${name}` });
|
|
321
|
+
const role = el2.getAttribute("role");
|
|
322
|
+
if (role) {
|
|
323
|
+
const title = el2.getAttribute("title") || el2.getAttribute("aria-labelledby");
|
|
324
|
+
const sel = title ? `[role='${role}']${attrSelector(el2.getAttribute("title") ? "title" : "aria-labelledby", title)}` : `[role='${role}']`;
|
|
325
|
+
if (uniqueIn(doc, sel, el2)) push({ kind: "css", value: sel, label: `role ${role}` });
|
|
326
|
+
}
|
|
327
|
+
if (tag === "a") {
|
|
328
|
+
const href = el2.getAttribute("href");
|
|
329
|
+
if (href && href.length <= 200 && uniqueIn(doc, `a${attrSelector("href", href)}`, el2)) push({ kind: "css", value: `a${attrSelector("href", href)}`, label: `link ${href}` });
|
|
330
|
+
}
|
|
331
|
+
const path = cssPath(el2, doc);
|
|
332
|
+
if (path) push({ kind: "css", value: path, label: "css path" });
|
|
333
|
+
if (/^(button|a|h[1-6]|label|summary)$/.test(tag) || role === "button" || role === "link" || role === "tab" || role === "menuitem") {
|
|
334
|
+
const text = normalizeText(el2.innerText ?? el2.textContent);
|
|
335
|
+
if (text && text.length <= 80) push({ kind: "text", value: text, label: `text "${text}"` });
|
|
336
|
+
}
|
|
337
|
+
return out.slice(0, 10);
|
|
338
|
+
}
|
|
339
|
+
function describeElement(el2) {
|
|
340
|
+
const r = el2.getBoundingClientRect();
|
|
341
|
+
return {
|
|
342
|
+
selectors: generateSelectors(el2),
|
|
343
|
+
textSnapshot: textSnapshotOf(el2),
|
|
344
|
+
rect: { x: r.x, y: r.y, width: r.width, height: r.height },
|
|
345
|
+
tag: el2.tagName.toLowerCase()
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/sanitize.ts
|
|
350
|
+
var ALLOWED_TAGS = /* @__PURE__ */ new Set(["p", "br", "strong", "b", "em", "i", "u", "a", "ul", "ol", "li", "img", "h1", "h2", "h3", "h4", "code", "pre", "blockquote", "span", "div", "hr", "button"]);
|
|
351
|
+
var DROP_TAGS = /* @__PURE__ */ new Set(["script", "style", "iframe", "object", "embed", "form", "input", "textarea", "select", "link", "meta", "base", "template", "svg", "math", "frame", "frameset", "noscript"]);
|
|
352
|
+
var ALLOWED_ATTRS = /* @__PURE__ */ new Set(["href", "src", "alt", "title", "target", "rel", "class", "data-g-action", "data-g-value"]);
|
|
353
|
+
function isSafeUrl(value, attr, tag) {
|
|
354
|
+
const v = value.trim().replace(/[\u0000-\u001f\s]/g, "").toLowerCase();
|
|
355
|
+
if (!v) return false;
|
|
356
|
+
const m = /^([a-z][a-z0-9+.-]*):/.exec(v);
|
|
357
|
+
if (!m) return true;
|
|
358
|
+
const scheme = m[1];
|
|
359
|
+
if (scheme === "data") return tag === "img" && attr === "src" && v.startsWith("data:image/");
|
|
360
|
+
return scheme === "http" || scheme === "https" || scheme === "mailto" || scheme === "tel";
|
|
361
|
+
}
|
|
362
|
+
function sanitizeElement(el2) {
|
|
363
|
+
const tag = el2.tagName.toLowerCase();
|
|
364
|
+
for (const attr of Array.from(el2.attributes)) {
|
|
365
|
+
const name = attr.name.toLowerCase();
|
|
366
|
+
if (name.startsWith("on") || !ALLOWED_ATTRS.has(name)) {
|
|
367
|
+
el2.removeAttribute(attr.name);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if ((name === "href" || name === "src") && !isSafeUrl(attr.value, name, tag)) el2.removeAttribute(attr.name);
|
|
371
|
+
}
|
|
372
|
+
if (tag === "a") {
|
|
373
|
+
const target = el2.getAttribute("target");
|
|
374
|
+
if (target && target !== "_blank" && target !== "_self") el2.removeAttribute("target");
|
|
375
|
+
if (el2.getAttribute("target") === "_blank") el2.setAttribute("rel", "noopener noreferrer");
|
|
376
|
+
}
|
|
377
|
+
if (tag === "button") el2.setAttribute("type", "button");
|
|
378
|
+
if (tag === "img") {
|
|
379
|
+
el2.setAttribute("loading", "lazy");
|
|
380
|
+
if (!el2.getAttribute("alt")) el2.setAttribute("alt", "");
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function walk(node) {
|
|
384
|
+
const children = Array.from(node.childNodes);
|
|
385
|
+
for (const child of children) {
|
|
386
|
+
if (child.nodeType === 8) {
|
|
387
|
+
node.removeChild(child);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (child.nodeType !== 1) continue;
|
|
391
|
+
const el2 = child;
|
|
392
|
+
const tag = el2.tagName.toLowerCase();
|
|
393
|
+
if (DROP_TAGS.has(tag)) {
|
|
394
|
+
node.removeChild(el2);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (!ALLOWED_TAGS.has(tag)) {
|
|
398
|
+
while (el2.firstChild) node.insertBefore(el2.firstChild, el2);
|
|
399
|
+
node.removeChild(el2);
|
|
400
|
+
walk(node);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
sanitizeElement(el2);
|
|
404
|
+
walk(el2);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function sanitizeToFragment(html, doc = document) {
|
|
408
|
+
const tpl = doc.createElement("template");
|
|
409
|
+
tpl.innerHTML = html || "";
|
|
410
|
+
walk(tpl.content);
|
|
411
|
+
return tpl.content;
|
|
412
|
+
}
|
|
413
|
+
function sanitizeHtml(html, doc = document) {
|
|
414
|
+
const frag = sanitizeToFragment(html, doc);
|
|
415
|
+
const div = doc.createElement("div");
|
|
416
|
+
div.appendChild(frag);
|
|
417
|
+
return div.innerHTML;
|
|
418
|
+
}
|
|
419
|
+
function setSanitizedHtml(el2, html) {
|
|
420
|
+
el2.textContent = "";
|
|
421
|
+
el2.appendChild(sanitizeToFragment(html, el2.ownerDocument));
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/styles.ts
|
|
425
|
+
var STYLES = `
|
|
426
|
+
:host{all:initial;position:static;display:block;contain:none}
|
|
427
|
+
*,*::before,*::after{box-sizing:border-box}
|
|
428
|
+
.g-scope [hidden]{display:none!important}
|
|
429
|
+
.g-scope{
|
|
430
|
+
--g-primary:#4f46e5;--g-bg:#ffffff;--g-text:#111827;--g-radius:12px;--g-font:Inter,system-ui,-apple-system,sans-serif;--g-z:2147483000;--g-overlay:.5;
|
|
431
|
+
--g-muted:color-mix(in srgb,var(--g-text) 62%,transparent);--g-border:color-mix(in srgb,var(--g-text) 12%,transparent);
|
|
432
|
+
--g-subtle:color-mix(in srgb,var(--g-text) 5%,transparent);--g-shadow:0 10px 40px rgba(0,0,0,.18),0 2px 8px rgba(0,0,0,.08);
|
|
433
|
+
--g-primary-text:#ffffff;
|
|
434
|
+
font-family:var(--g-font);font-size:14px;line-height:1.5;color:var(--g-text);-webkit-font-smoothing:antialiased;
|
|
435
|
+
}
|
|
436
|
+
.g-scope[data-theme="dark"]{--g-shadow:0 10px 40px rgba(0,0,0,.5),0 2px 8px rgba(0,0,0,.3)}
|
|
437
|
+
.g-live{position:fixed;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
438
|
+
.g-layer{position:fixed;inset:0;z-index:var(--g-z);pointer-events:none}
|
|
439
|
+
.g-overlay{position:fixed;inset:0;background:rgba(0,0,0,var(--g-overlay));z-index:calc(var(--g-z) + 3);pointer-events:auto}
|
|
440
|
+
.g-overlay.g-transparent{background:transparent}
|
|
441
|
+
.g-spot-rect{position:fixed;background:rgba(0,0,0,var(--g-overlay));z-index:calc(var(--g-z) + 3);pointer-events:auto}
|
|
442
|
+
.g-spot-ring{position:fixed;z-index:calc(var(--g-z) + 3);pointer-events:none;border-radius:6px;box-shadow:0 0 0 2px var(--g-primary),0 0 0 6px color-mix(in srgb,var(--g-primary) 30%,transparent)}
|
|
443
|
+
.g-card{
|
|
444
|
+
position:fixed;z-index:calc(var(--g-z) + 4);pointer-events:auto;background:var(--g-bg);color:var(--g-text);border-radius:var(--g-radius);
|
|
445
|
+
box-shadow:var(--g-shadow);border:1px solid var(--g-border);width:min(360px,calc(100vw - 32px));max-width:calc(100vw - 32px);max-height:calc(100vh - 32px);overflow:auto;outline:none;
|
|
446
|
+
}
|
|
447
|
+
.g-card.g-modal{left:50%;top:50%;transform:translate(-50%,-50%);width:min(480px,calc(100vw - 32px))}
|
|
448
|
+
.g-card.g-tooltip,.g-card.g-popover,.g-card.g-spotlight-card,.g-card.g-hotspot-card{top:0;left:0;width:min(320px,calc(100vw - 32px))}
|
|
449
|
+
.g-card.g-slideout{width:min(360px,calc(100vw - 32px));margin:16px}
|
|
450
|
+
.g-pos-bottom-right{right:0;bottom:0}.g-pos-bottom-left{left:0;bottom:0}.g-pos-top-right{right:0;top:0}.g-pos-top-left{left:0;top:0}
|
|
451
|
+
.g-pos-center{left:50%;top:50%;transform:translate(-50%,-50%)}
|
|
452
|
+
.g-pos-top{top:0;left:0;right:0}.g-pos-bottom{bottom:0;left:0;right:0}
|
|
453
|
+
.g-banner{position:fixed;left:0;right:0;z-index:calc(var(--g-z) + 1);pointer-events:auto;background:var(--g-primary);color:var(--g-primary-text);padding:10px 48px 10px 16px;display:flex;align-items:center;gap:12px;font-size:14px;box-shadow:0 2px 10px rgba(0,0,0,.15);max-width:100vw}
|
|
454
|
+
.g-banner .g-body{flex:1;min-width:0}
|
|
455
|
+
.g-banner .g-body a{color:inherit;text-decoration:underline}
|
|
456
|
+
.g-banner .g-close{color:inherit;right:8px;top:50%;transform:translateY(-50%)}
|
|
457
|
+
.g-banner .g-btn{background:rgba(255,255,255,.18);color:inherit;border-color:transparent;min-height:36px}
|
|
458
|
+
.g-banner.g-pos-top{top:0}.g-banner.g-pos-bottom{bottom:0}
|
|
459
|
+
.g-inner{padding:20px}
|
|
460
|
+
.g-close{position:absolute;top:8px;right:8px;width:40px;height:40px;display:inline-flex;align-items:center;justify-content:center;border:0;background:transparent;color:var(--g-muted);border-radius:999px;cursor:pointer;font:inherit;font-size:20px;line-height:1}
|
|
461
|
+
.g-close:hover,.g-close:focus-visible{background:var(--g-subtle);color:var(--g-text);outline:none}
|
|
462
|
+
.g-close:focus-visible,.g-btn:focus-visible,.g-task:focus-visible,.g-choice:focus-visible,.g-scale button:focus-visible,.g-launcher:focus-visible,.g-input:focus-visible,.g-rc-item:focus-visible{outline:2px solid var(--g-primary);outline-offset:2px}
|
|
463
|
+
.g-image{display:block;width:100%;max-height:220px;object-fit:cover;border-radius:var(--g-radius) var(--g-radius) 0 0}
|
|
464
|
+
.g-title{margin:0 28px 6px 0;font-size:16px;font-weight:600;line-height:1.3}
|
|
465
|
+
.g-body{font-size:14px;color:var(--g-text)}
|
|
466
|
+
.g-body p{margin:0 0 8px}.g-body p:last-child{margin-bottom:0}
|
|
467
|
+
.g-body ul,.g-body ol{margin:6px 0;padding-left:20px}
|
|
468
|
+
.g-body a{color:var(--g-primary)}
|
|
469
|
+
.g-body img{max-width:100%;height:auto;border-radius:6px}
|
|
470
|
+
.g-body code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px;background:var(--g-subtle);padding:1px 4px;border-radius:4px}
|
|
471
|
+
.g-body pre{background:var(--g-subtle);padding:10px;border-radius:6px;overflow:auto}
|
|
472
|
+
.g-body blockquote{margin:6px 0;padding-left:10px;border-left:3px solid var(--g-border);color:var(--g-muted)}
|
|
473
|
+
.g-footer{display:flex;align-items:center;gap:8px;margin-top:14px;flex-wrap:wrap}
|
|
474
|
+
.g-progress{font-size:12px;color:var(--g-muted);margin-right:auto}
|
|
475
|
+
.g-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:40px;padding:8px 14px;border-radius:calc(var(--g-radius) * .66);border:1px solid transparent;font:inherit;font-size:14px;font-weight:500;cursor:pointer;text-decoration:none;transition:background .15s,color .15s,border-color .15s}
|
|
476
|
+
.g-btn-primary{background:var(--g-primary);color:var(--g-primary-text)}
|
|
477
|
+
.g-btn-primary:hover{filter:brightness(1.08)}
|
|
478
|
+
.g-btn-secondary{background:var(--g-subtle);color:var(--g-text);border-color:var(--g-border)}
|
|
479
|
+
.g-btn-secondary:hover{background:color-mix(in srgb,var(--g-text) 10%,transparent)}
|
|
480
|
+
.g-btn-ghost{background:transparent;color:var(--g-muted)}
|
|
481
|
+
.g-btn-ghost:hover{background:var(--g-subtle);color:var(--g-text)}
|
|
482
|
+
.g-btn-link{background:transparent;color:var(--g-primary);padding-left:4px;padding-right:4px}
|
|
483
|
+
.g-btn-link:hover{text-decoration:underline}
|
|
484
|
+
.g-btn:disabled{opacity:.5;cursor:not-allowed}
|
|
485
|
+
.g-arrow{position:absolute;width:12px;height:12px;background:var(--g-bg);transform:rotate(45deg);border:1px solid var(--g-border);z-index:-1}
|
|
486
|
+
.g-hotspot{position:fixed;z-index:calc(var(--g-z) + 1);pointer-events:auto;border-radius:999px;background:var(--g-primary);border:2px solid #fff;box-shadow:0 0 0 2px color-mix(in srgb,var(--g-primary) 40%,transparent);cursor:pointer;padding:0;margin:0}
|
|
487
|
+
.g-hotspot::after{content:"";position:absolute;inset:-4px;border-radius:999px;border:2px solid var(--g-primary);opacity:0}
|
|
488
|
+
.g-hotspot.g-pulse::after{animation:g-pulse 1.8s ease-out infinite}
|
|
489
|
+
.g-hotspot-hit{position:absolute;inset:-14px}
|
|
490
|
+
.g-custom{position:fixed;z-index:calc(var(--g-z) + 4);pointer-events:auto;left:50%;top:50%;transform:translate(-50%,-50%);max-width:calc(100vw - 32px);max-height:calc(100vh - 32px);overflow:auto}
|
|
491
|
+
/* animations */
|
|
492
|
+
.g-scope[data-anim="fade"] .g-card,.g-scope[data-anim="fade"] .g-banner,.g-scope[data-anim="fade"] .g-panel{animation:g-fade .18s ease-out}
|
|
493
|
+
.g-scope[data-anim="slide"] .g-card,.g-scope[data-anim="slide"] .g-panel{animation:g-slide .22s ease-out}
|
|
494
|
+
.g-scope[data-anim="none"] *{animation:none!important;transition:none!important}
|
|
495
|
+
@keyframes g-fade{from{opacity:0}to{opacity:1}}
|
|
496
|
+
@keyframes g-slide{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
|
|
497
|
+
@keyframes g-pulse{0%{transform:scale(.6);opacity:.9}100%{transform:scale(2.2);opacity:0}}
|
|
498
|
+
@media (prefers-reduced-motion:reduce){.g-scope *{animation:none!important;transition:none!important}}
|
|
499
|
+
/* launcher + panel (checklist / resource center) */
|
|
500
|
+
.g-launcher{position:fixed;z-index:calc(var(--g-z) + 1);pointer-events:auto;display:inline-flex;align-items:center;gap:8px;min-height:44px;padding:10px 16px;border-radius:999px;border:0;background:var(--g-primary);color:var(--g-primary-text);font:inherit;font-size:14px;font-weight:600;cursor:pointer;box-shadow:var(--g-shadow);margin:16px}
|
|
501
|
+
.g-launcher .g-ring{width:22px;height:22px;border-radius:999px;background:conic-gradient(#fff var(--g-pct,0%),rgba(255,255,255,.3) 0);display:inline-flex;align-items:center;justify-content:center;font-size:10px;position:relative}
|
|
502
|
+
.g-launcher .g-ring::after{content:"";position:absolute;inset:3px;border-radius:999px;background:var(--g-primary)}
|
|
503
|
+
.g-launcher .g-count{position:relative;z-index:1}
|
|
504
|
+
.g-panel{position:fixed;z-index:calc(var(--g-z) + 2);pointer-events:auto;width:min(380px,calc(100vw - 32px));max-height:min(620px,calc(100vh - 100px));display:flex;flex-direction:column;background:var(--g-bg);color:var(--g-text);border-radius:var(--g-radius);box-shadow:var(--g-shadow);border:1px solid var(--g-border);margin:16px;bottom:60px;overflow:hidden}
|
|
505
|
+
.g-panel-head{padding:16px 48px 12px 20px;border-bottom:1px solid var(--g-border);position:relative}
|
|
506
|
+
.g-panel-title{margin:0;font-size:16px;font-weight:600}
|
|
507
|
+
.g-panel-sub{margin:4px 0 0;font-size:12px;color:var(--g-muted)}
|
|
508
|
+
.g-panel-body{overflow:auto;padding:8px 0;flex:1}
|
|
509
|
+
.g-bar{height:6px;border-radius:999px;background:var(--g-subtle);overflow:hidden;margin-top:10px}
|
|
510
|
+
.g-bar > span{display:block;height:100%;background:var(--g-primary);transition:width .3s}
|
|
511
|
+
.g-task{display:flex;gap:12px;align-items:flex-start;width:100%;padding:12px 20px;border:0;background:transparent;text-align:left;font:inherit;color:inherit;cursor:pointer;min-height:44px}
|
|
512
|
+
.g-task:hover{background:var(--g-subtle)}
|
|
513
|
+
.g-task[disabled]{cursor:not-allowed;opacity:.55}
|
|
514
|
+
.g-task .g-check{flex:none;width:22px;height:22px;border-radius:999px;border:2px solid var(--g-border);display:inline-flex;align-items:center;justify-content:center;font-size:13px;margin-top:1px;color:#fff}
|
|
515
|
+
.g-task.g-done .g-check{background:var(--g-primary);border-color:var(--g-primary)}
|
|
516
|
+
.g-task.g-done .g-task-title{text-decoration:line-through;color:var(--g-muted)}
|
|
517
|
+
.g-task-title{font-weight:500}
|
|
518
|
+
.g-task-desc{font-size:12px;color:var(--g-muted);margin-top:2px}
|
|
519
|
+
.g-panel-foot{padding:10px 20px;border-top:1px solid var(--g-border);display:flex;justify-content:flex-end;gap:8px}
|
|
520
|
+
.g-complete{padding:28px 20px;text-align:center}
|
|
521
|
+
.g-complete .g-title{margin-right:0;font-size:18px}
|
|
522
|
+
/* survey */
|
|
523
|
+
.g-question{margin-bottom:16px}
|
|
524
|
+
.g-q-title{font-weight:600;margin:0 0 4px}
|
|
525
|
+
.g-q-desc{font-size:12px;color:var(--g-muted);margin:0 0 8px}
|
|
526
|
+
.g-scale{display:flex;gap:4px;flex-wrap:wrap}
|
|
527
|
+
.g-scale button{min-width:34px;height:40px;flex:1;padding:0 4px;border-radius:6px;border:1px solid var(--g-border);background:var(--g-subtle);color:var(--g-text);font:inherit;cursor:pointer}
|
|
528
|
+
.g-scale button[aria-pressed="true"],.g-scale button:hover{background:var(--g-primary);color:var(--g-primary-text);border-color:var(--g-primary)}
|
|
529
|
+
.g-scale-labels{display:flex;justify-content:space-between;font-size:11px;color:var(--g-muted);margin-top:4px}
|
|
530
|
+
.g-stars button,.g-thumbs button{font-size:22px;background:transparent;border:0;cursor:pointer;color:var(--g-muted);min-width:40px;height:40px;font:inherit}
|
|
531
|
+
.g-stars button[aria-pressed="true"],.g-stars button.g-on{color:#f59e0b}
|
|
532
|
+
.g-thumbs button[aria-pressed="true"]{color:var(--g-primary)}
|
|
533
|
+
.g-choice{display:flex;align-items:center;gap:10px;padding:8px 10px;border:1px solid var(--g-border);border-radius:8px;margin-bottom:6px;cursor:pointer;min-height:40px;font:inherit;background:transparent;color:inherit;width:100%;text-align:left}
|
|
534
|
+
.g-choice[aria-checked="true"]{border-color:var(--g-primary);background:color-mix(in srgb,var(--g-primary) 8%,transparent)}
|
|
535
|
+
.g-choice .g-dot{width:16px;height:16px;border-radius:999px;border:2px solid var(--g-border);flex:none}
|
|
536
|
+
.g-choice.g-multi .g-dot{border-radius:4px}
|
|
537
|
+
.g-choice[aria-checked="true"] .g-dot{background:var(--g-primary);border-color:var(--g-primary)}
|
|
538
|
+
.g-input{width:100%;min-height:40px;padding:8px 10px;border:1px solid var(--g-border);border-radius:8px;background:var(--g-bg);color:var(--g-text);font:inherit;resize:vertical}
|
|
539
|
+
.g-error{color:#dc2626;font-size:12px;margin-top:4px}
|
|
540
|
+
/* resource center */
|
|
541
|
+
.g-rc-search{padding:12px 20px 4px}
|
|
542
|
+
.g-rc-section{padding:8px 20px 4px;font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--g-muted);font-weight:600}
|
|
543
|
+
.g-rc-item{display:flex;align-items:flex-start;gap:10px;width:100%;padding:10px 20px;border:0;background:transparent;font:inherit;color:inherit;text-align:left;cursor:pointer;min-height:44px;text-decoration:none}
|
|
544
|
+
.g-rc-item:hover{background:var(--g-subtle)}
|
|
545
|
+
.g-rc-item .g-rc-title{font-weight:500}
|
|
546
|
+
.g-rc-item .g-rc-sum{font-size:12px;color:var(--g-muted);margin-top:2px}
|
|
547
|
+
.g-rc-item .g-rc-icon{flex:none;width:20px;text-align:center;color:var(--g-primary)}
|
|
548
|
+
.g-rc-article{padding:16px 20px}
|
|
549
|
+
.g-rc-back{margin-bottom:8px}
|
|
550
|
+
.g-rc-empty{padding:24px 20px;color:var(--g-muted);text-align:center}
|
|
551
|
+
.g-faq-a{padding:0 20px 12px 50px;font-size:13px;color:var(--g-muted)}
|
|
552
|
+
.g-faq-a[hidden]{display:none}
|
|
553
|
+
/* authoring */
|
|
554
|
+
.g-auth-bar{position:fixed;top:0;left:0;right:0;z-index:calc(var(--g-z) + 10);pointer-events:auto;display:flex;align-items:center;gap:12px;padding:8px 16px;background:#111827;color:#fff;font:500 13px/1.4 var(--g-font);box-shadow:0 2px 10px rgba(0,0,0,.3)}
|
|
555
|
+
.g-auth-bar .g-dot-live{width:8px;height:8px;border-radius:999px;background:#22c55e;box-shadow:0 0 0 3px rgba(34,197,94,.3)}
|
|
556
|
+
.g-auth-bar .g-spacer{flex:1}
|
|
557
|
+
.g-auth-bar .g-btn{min-height:32px;padding:4px 12px;font-size:13px}
|
|
558
|
+
.g-auth-bar .g-btn-secondary{background:rgba(255,255,255,.12);color:#fff;border-color:transparent}
|
|
559
|
+
.g-auth-outline{position:fixed;z-index:calc(var(--g-z) + 9);pointer-events:none;border:2px solid var(--g-primary);background:color-mix(in srgb,var(--g-primary) 12%,transparent);border-radius:4px;transition:all .06s linear}
|
|
560
|
+
.g-auth-label{position:absolute;left:-2px;top:-24px;background:var(--g-primary);color:#fff;font:600 11px/1 var(--g-font);padding:5px 7px;border-radius:4px;white-space:nowrap;max-width:320px;overflow:hidden;text-overflow:ellipsis}
|
|
561
|
+
.g-auth-outline.g-picked{border-style:dashed;border-color:#22c55e;background:rgba(34,197,94,.12)}
|
|
562
|
+
.g-auth-outline.g-picked .g-auth-label{background:#16a34a}
|
|
563
|
+
.g-highlight{position:fixed;z-index:calc(var(--g-z) + 8);pointer-events:none;border:2px dashed #f59e0b;background:rgba(245,158,11,.12);border-radius:4px}
|
|
564
|
+
@media (max-width:480px){.g-card.g-modal,.g-panel{width:calc(100vw - 32px)}.g-inner{padding:16px}}
|
|
565
|
+
`;
|
|
566
|
+
|
|
567
|
+
// src/host.ts
|
|
568
|
+
var HOST_ID2 = "guidely-root";
|
|
569
|
+
var current = null;
|
|
570
|
+
var DEFAULT_THEME = {
|
|
571
|
+
primaryColor: "#4f46e5",
|
|
572
|
+
backgroundColor: "#ffffff",
|
|
573
|
+
textColor: "#111827",
|
|
574
|
+
borderRadius: 12,
|
|
575
|
+
fontFamily: "Inter, system-ui, -apple-system, sans-serif"
|
|
576
|
+
};
|
|
577
|
+
function ensureHost(doc = document) {
|
|
578
|
+
if (current && current.host.isConnected && current.host.ownerDocument === doc) return current;
|
|
579
|
+
let host = doc.getElementById(HOST_ID2);
|
|
580
|
+
if (!host) {
|
|
581
|
+
host = doc.createElement("div");
|
|
582
|
+
host.id = HOST_ID2;
|
|
583
|
+
host.setAttribute("data-guidely", "");
|
|
584
|
+
(doc.body || doc.documentElement).appendChild(host);
|
|
585
|
+
}
|
|
586
|
+
const shadow = host.shadowRoot ?? host.attachShadow({ mode: "open" });
|
|
587
|
+
if (!shadow.querySelector("style[data-g-base]")) {
|
|
588
|
+
const style = doc.createElement("style");
|
|
589
|
+
style.setAttribute("data-g-base", "");
|
|
590
|
+
style.textContent = STYLES;
|
|
591
|
+
shadow.appendChild(style);
|
|
592
|
+
}
|
|
593
|
+
let live = shadow.querySelector(".g-live");
|
|
594
|
+
if (!live) {
|
|
595
|
+
live = doc.createElement("div");
|
|
596
|
+
live.className = "g-live";
|
|
597
|
+
live.setAttribute("aria-live", "polite");
|
|
598
|
+
live.setAttribute("aria-atomic", "true");
|
|
599
|
+
shadow.appendChild(live);
|
|
600
|
+
}
|
|
601
|
+
const liveEl = live;
|
|
602
|
+
current = {
|
|
603
|
+
host,
|
|
604
|
+
shadow,
|
|
605
|
+
live: liveEl,
|
|
606
|
+
announce(text) {
|
|
607
|
+
liveEl.textContent = "";
|
|
608
|
+
setTimeout(() => {
|
|
609
|
+
liveEl.textContent = text;
|
|
610
|
+
}, 30);
|
|
611
|
+
},
|
|
612
|
+
destroy() {
|
|
613
|
+
host?.remove();
|
|
614
|
+
if (current?.host === host) current = null;
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
return current;
|
|
618
|
+
}
|
|
619
|
+
function destroyHost() {
|
|
620
|
+
current?.destroy();
|
|
621
|
+
const stray = typeof document !== "undefined" ? document.getElementById(HOST_ID2) : null;
|
|
622
|
+
stray?.remove();
|
|
623
|
+
current = null;
|
|
624
|
+
}
|
|
625
|
+
function prefersDark() {
|
|
626
|
+
try {
|
|
627
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
628
|
+
} catch {
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
function prefersReducedMotion() {
|
|
633
|
+
try {
|
|
634
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
635
|
+
} catch {
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function resolveTheme(theme, appearance) {
|
|
640
|
+
const t = { ...DEFAULT_THEME, ...theme || {} };
|
|
641
|
+
const a = appearance || {};
|
|
642
|
+
const requested = a.theme ?? "auto";
|
|
643
|
+
const mode = requested === "auto" ? prefersDark() ? "dark" : "light" : requested;
|
|
644
|
+
const dark = mode === "dark";
|
|
645
|
+
return {
|
|
646
|
+
primary: a.primaryColor || t.primaryColor,
|
|
647
|
+
bg: a.backgroundColor || (dark ? "#1f2937" : t.backgroundColor),
|
|
648
|
+
text: a.textColor || (dark ? "#f9fafb" : t.textColor),
|
|
649
|
+
radius: a.borderRadius ?? t.borderRadius,
|
|
650
|
+
font: a.fontFamily || t.fontFamily,
|
|
651
|
+
z: a.zIndex ?? 2147483e3,
|
|
652
|
+
overlay: a.overlayOpacity ?? 0.5,
|
|
653
|
+
mode,
|
|
654
|
+
animation: prefersReducedMotion() ? "none" : a.animation ?? "fade"
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function applyTheme(el2, vars) {
|
|
658
|
+
el2.style.setProperty("--g-primary", vars.primary);
|
|
659
|
+
el2.style.setProperty("--g-bg", vars.bg);
|
|
660
|
+
el2.style.setProperty("--g-text", vars.text);
|
|
661
|
+
el2.style.setProperty("--g-radius", `${vars.radius}px`);
|
|
662
|
+
el2.style.setProperty("--g-font", vars.font);
|
|
663
|
+
el2.style.setProperty("--g-z", String(vars.z));
|
|
664
|
+
el2.style.setProperty("--g-overlay", String(vars.overlay));
|
|
665
|
+
el2.setAttribute("data-theme", vars.mode);
|
|
666
|
+
el2.setAttribute("data-anim", vars.animation);
|
|
667
|
+
}
|
|
668
|
+
function createScope(theme, appearance, doc = document) {
|
|
669
|
+
const handle = ensureHost(doc);
|
|
670
|
+
const el2 = doc.createElement("div");
|
|
671
|
+
el2.className = "g-scope";
|
|
672
|
+
const vars = resolveTheme(theme, appearance);
|
|
673
|
+
applyTheme(el2, vars);
|
|
674
|
+
handle.shadow.appendChild(el2);
|
|
675
|
+
let mq = null;
|
|
676
|
+
const onChange = () => applyTheme(el2, resolveTheme(theme, appearance));
|
|
677
|
+
if ((appearance?.theme ?? "auto") === "auto" && typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
678
|
+
try {
|
|
679
|
+
mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
680
|
+
mq.addEventListener?.("change", onChange);
|
|
681
|
+
} catch {
|
|
682
|
+
mq = null;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
el: el2,
|
|
687
|
+
vars,
|
|
688
|
+
destroy() {
|
|
689
|
+
mq?.removeEventListener?.("change", onChange);
|
|
690
|
+
el2.remove();
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// src/position.ts
|
|
696
|
+
var import_dom = require("@floating-ui/dom");
|
|
697
|
+
function anchor(reference, floating, options = {}) {
|
|
698
|
+
const placement = options.placement ?? "auto";
|
|
699
|
+
const gap = options.offset ?? 10;
|
|
700
|
+
const middleware = [(0, import_dom.offset)(gap + (options.arrowEl ? 4 : 0))];
|
|
701
|
+
if (placement === "auto") middleware.push((0, import_dom.autoPlacement)({ padding: 16 }));
|
|
702
|
+
else middleware.push((0, import_dom.flip)({ padding: 16 }));
|
|
703
|
+
middleware.push((0, import_dom.shift)({ padding: 16 }));
|
|
704
|
+
if (options.arrowEl) middleware.push((0, import_dom.arrow)({ element: options.arrowEl, padding: 8 }));
|
|
705
|
+
let stopped = false;
|
|
706
|
+
const update = async () => {
|
|
707
|
+
if (stopped || !floating.isConnected) return;
|
|
708
|
+
try {
|
|
709
|
+
const result = await (0, import_dom.computePosition)(reference, floating, {
|
|
710
|
+
placement: placement === "auto" ? "bottom" : placement,
|
|
711
|
+
strategy: "fixed",
|
|
712
|
+
middleware
|
|
713
|
+
});
|
|
714
|
+
if (stopped) return;
|
|
715
|
+
floating.style.left = `${Math.round(result.x)}px`;
|
|
716
|
+
floating.style.top = `${Math.round(result.y)}px`;
|
|
717
|
+
floating.setAttribute("data-placement", result.placement);
|
|
718
|
+
if (options.arrowEl && result.middlewareData.arrow) {
|
|
719
|
+
const { x, y } = result.middlewareData.arrow;
|
|
720
|
+
const side = result.placement.split("-")[0];
|
|
721
|
+
const staticSide = { top: "bottom", right: "left", bottom: "top", left: "right" }[side];
|
|
722
|
+
Object.assign(options.arrowEl.style, {
|
|
723
|
+
left: x != null ? `${x}px` : "",
|
|
724
|
+
top: y != null ? `${y}px` : "",
|
|
725
|
+
right: "",
|
|
726
|
+
bottom: "",
|
|
727
|
+
[staticSide]: "-7px"
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
options.onUpdate?.(result.placement);
|
|
731
|
+
} catch {
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
let stopAuto = null;
|
|
735
|
+
try {
|
|
736
|
+
stopAuto = (0, import_dom.autoUpdate)(reference, floating, () => void update(), { animationFrame: false });
|
|
737
|
+
} catch {
|
|
738
|
+
void update();
|
|
739
|
+
}
|
|
740
|
+
return () => {
|
|
741
|
+
stopped = true;
|
|
742
|
+
stopAuto?.();
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
function trackRect(el2, cb) {
|
|
746
|
+
let raf = 0;
|
|
747
|
+
let stopped = false;
|
|
748
|
+
const run = () => {
|
|
749
|
+
if (stopped) return;
|
|
750
|
+
cb(el2.getBoundingClientRect());
|
|
751
|
+
};
|
|
752
|
+
const schedule = () => {
|
|
753
|
+
if (stopped) return;
|
|
754
|
+
if (typeof requestAnimationFrame === "function") {
|
|
755
|
+
cancelAnimationFrame(raf);
|
|
756
|
+
raf = requestAnimationFrame(run);
|
|
757
|
+
} else run();
|
|
758
|
+
};
|
|
759
|
+
run();
|
|
760
|
+
const win = el2.ownerDocument.defaultView;
|
|
761
|
+
win?.addEventListener("scroll", schedule, true);
|
|
762
|
+
win?.addEventListener("resize", schedule);
|
|
763
|
+
let ro = null;
|
|
764
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
765
|
+
try {
|
|
766
|
+
ro = new ResizeObserver(schedule);
|
|
767
|
+
ro.observe(el2);
|
|
768
|
+
if (el2.ownerDocument.documentElement) ro.observe(el2.ownerDocument.documentElement);
|
|
769
|
+
} catch {
|
|
770
|
+
ro = null;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
const interval = setInterval(run, 500);
|
|
774
|
+
return () => {
|
|
775
|
+
stopped = true;
|
|
776
|
+
win?.removeEventListener("scroll", schedule, true);
|
|
777
|
+
win?.removeEventListener("resize", schedule);
|
|
778
|
+
ro?.disconnect();
|
|
779
|
+
clearInterval(interval);
|
|
780
|
+
if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(raf);
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/render.ts
|
|
785
|
+
var FOCUSABLE = "button:not([disabled]),[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex='-1'])";
|
|
786
|
+
var uid = 0;
|
|
787
|
+
var nextId = (p) => `g-${p}-${++uid}`;
|
|
788
|
+
function h(doc, tag, className, text) {
|
|
789
|
+
const el2 = doc.createElement(tag);
|
|
790
|
+
if (className) el2.className = className;
|
|
791
|
+
if (text != null) el2.textContent = text;
|
|
792
|
+
return el2;
|
|
793
|
+
}
|
|
794
|
+
function buildButtons(doc, step, onButton) {
|
|
795
|
+
return step.buttons.map((b) => {
|
|
796
|
+
const btn = h(doc, "button", `g-btn g-btn-${b.variant}`, b.label);
|
|
797
|
+
btn.type = "button";
|
|
798
|
+
btn.setAttribute("data-action", b.action);
|
|
799
|
+
btn.addEventListener("click", (e) => {
|
|
800
|
+
e.preventDefault();
|
|
801
|
+
onButton(b);
|
|
802
|
+
});
|
|
803
|
+
return btn;
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
function buildCard(doc, opts, extraClass) {
|
|
807
|
+
const { step } = opts;
|
|
808
|
+
const card = h(doc, "div", `g-card ${extraClass}`);
|
|
809
|
+
card.tabIndex = -1;
|
|
810
|
+
card.setAttribute("data-step-id", step.id);
|
|
811
|
+
if (step.width) card.style.width = `min(${step.width}px, calc(100vw - 32px))`;
|
|
812
|
+
const titleId = nextId("title");
|
|
813
|
+
const bodyId = nextId("body");
|
|
814
|
+
if (step.imageUrl) {
|
|
815
|
+
const img = h(doc, "img", "g-image");
|
|
816
|
+
img.src = step.imageUrl;
|
|
817
|
+
img.alt = "";
|
|
818
|
+
card.appendChild(img);
|
|
819
|
+
}
|
|
820
|
+
const inner = h(doc, "div", "g-inner");
|
|
821
|
+
if (step.showClose) {
|
|
822
|
+
const close = h(doc, "button", "g-close", "\xD7");
|
|
823
|
+
close.type = "button";
|
|
824
|
+
close.setAttribute("aria-label", "Close");
|
|
825
|
+
close.addEventListener("click", (e) => {
|
|
826
|
+
e.preventDefault();
|
|
827
|
+
opts.onClose();
|
|
828
|
+
});
|
|
829
|
+
card.appendChild(close);
|
|
830
|
+
}
|
|
831
|
+
if (step.title) {
|
|
832
|
+
const t = h(doc, "h2", "g-title", step.title);
|
|
833
|
+
t.id = titleId;
|
|
834
|
+
inner.appendChild(t);
|
|
835
|
+
}
|
|
836
|
+
if (step.body) {
|
|
837
|
+
const b = h(doc, "div", "g-body");
|
|
838
|
+
b.id = bodyId;
|
|
839
|
+
setSanitizedHtml(b, step.body);
|
|
840
|
+
inner.appendChild(b);
|
|
841
|
+
}
|
|
842
|
+
const buttons = buildButtons(doc, step, opts.onButton);
|
|
843
|
+
if (buttons.length || step.showProgress && opts.total > 1) {
|
|
844
|
+
const footer = h(doc, "div", "g-footer");
|
|
845
|
+
if (step.showProgress && opts.total > 1) footer.appendChild(h(doc, "span", "g-progress", `${opts.index + 1} of ${opts.total}`));
|
|
846
|
+
buttons.forEach((b) => footer.appendChild(b));
|
|
847
|
+
inner.appendChild(footer);
|
|
848
|
+
}
|
|
849
|
+
card.appendChild(inner);
|
|
850
|
+
if (step.title) card.setAttribute("aria-labelledby", titleId);
|
|
851
|
+
if (step.body) card.setAttribute("aria-describedby", bodyId);
|
|
852
|
+
return { card, inner, titleId, bodyId };
|
|
853
|
+
}
|
|
854
|
+
function focusables(root) {
|
|
855
|
+
return Array.from(root.querySelectorAll(FOCUSABLE));
|
|
856
|
+
}
|
|
857
|
+
function installKeyboard(card, step, trap, onClose) {
|
|
858
|
+
const onKey = (e) => {
|
|
859
|
+
if (e.key === "Escape" && step.showClose) {
|
|
860
|
+
e.stopPropagation();
|
|
861
|
+
onClose();
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
if (trap && e.key === "Tab") {
|
|
865
|
+
const items = focusables(card);
|
|
866
|
+
if (!items.length) {
|
|
867
|
+
e.preventDefault();
|
|
868
|
+
card.focus();
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
const first = items[0];
|
|
872
|
+
const last = items[items.length - 1];
|
|
873
|
+
const active = card.getRootNode().activeElement;
|
|
874
|
+
if (e.shiftKey && (active === first || active === card)) {
|
|
875
|
+
e.preventDefault();
|
|
876
|
+
last.focus();
|
|
877
|
+
} else if (!e.shiftKey && active === last) {
|
|
878
|
+
e.preventDefault();
|
|
879
|
+
first.focus();
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
card.addEventListener("keydown", onKey);
|
|
884
|
+
return () => card.removeEventListener("keydown", onKey);
|
|
885
|
+
}
|
|
886
|
+
function focusInto(card) {
|
|
887
|
+
const doc = card.ownerDocument;
|
|
888
|
+
const previous = doc.activeElement;
|
|
889
|
+
const primary = card.querySelector(".g-btn-primary") || focusables(card)[0] || card;
|
|
890
|
+
try {
|
|
891
|
+
primary.focus({ preventScroll: true });
|
|
892
|
+
} catch {
|
|
893
|
+
}
|
|
894
|
+
return () => {
|
|
895
|
+
try {
|
|
896
|
+
if (previous && previous.isConnected && typeof previous.focus === "function") previous.focus({ preventScroll: true });
|
|
897
|
+
} catch {
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
function overlayEl(doc, opts, transparent = false) {
|
|
902
|
+
const overlay = h(doc, "div", `g-overlay${transparent ? " g-transparent" : ""}`);
|
|
903
|
+
if (opts.step.dismissOnOutsideClick) overlay.addEventListener("click", () => opts.onClose());
|
|
904
|
+
return overlay;
|
|
905
|
+
}
|
|
906
|
+
function positionClass(position) {
|
|
907
|
+
return `g-pos-${position}`;
|
|
908
|
+
}
|
|
909
|
+
function renderModal(doc, opts) {
|
|
910
|
+
const cleanups = [];
|
|
911
|
+
const { card } = buildCard(doc, opts, "g-modal");
|
|
912
|
+
card.setAttribute("role", "dialog");
|
|
913
|
+
card.setAttribute("aria-modal", "true");
|
|
914
|
+
const wrapper = h(doc, "div", "g-step");
|
|
915
|
+
if (opts.step.showOverlay || opts.asModal) wrapper.appendChild(overlayEl(doc, opts));
|
|
916
|
+
else if (opts.step.dismissOnOutsideClick) wrapper.appendChild(overlayEl(doc, opts, true));
|
|
917
|
+
wrapper.appendChild(card);
|
|
918
|
+
opts.scope.appendChild(wrapper);
|
|
919
|
+
cleanups.push(installKeyboard(card, opts.step, true, opts.onClose));
|
|
920
|
+
cleanups.push(focusInto(card));
|
|
921
|
+
return { el: wrapper, card, destroy: () => cleanupAll(cleanups, wrapper) };
|
|
922
|
+
}
|
|
923
|
+
function cleanupAll(cleanups, el2) {
|
|
924
|
+
cleanups.splice(0).forEach((fn) => {
|
|
925
|
+
try {
|
|
926
|
+
fn();
|
|
927
|
+
} catch {
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
el2.remove();
|
|
931
|
+
}
|
|
932
|
+
function setTargetDescribedBy(target, id) {
|
|
933
|
+
const prev = target.getAttribute("aria-describedby");
|
|
934
|
+
try {
|
|
935
|
+
target.setAttribute("aria-describedby", prev ? `${prev} ${id}` : id);
|
|
936
|
+
} catch {
|
|
937
|
+
return () => {
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
return () => {
|
|
941
|
+
if (prev) target.setAttribute("aria-describedby", prev);
|
|
942
|
+
else target.removeAttribute("aria-describedby");
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
function renderTooltip(doc, opts, kind) {
|
|
946
|
+
const target = opts.target;
|
|
947
|
+
if (!target) return renderModal(doc, { ...opts, asModal: true });
|
|
948
|
+
const cleanups = [];
|
|
949
|
+
const { card } = buildCard(doc, opts, `g-${kind}`);
|
|
950
|
+
const arrowEl = h(doc, "div", "g-arrow");
|
|
951
|
+
card.appendChild(arrowEl);
|
|
952
|
+
card.setAttribute("role", kind === "tooltip" ? "tooltip" : "dialog");
|
|
953
|
+
card.id = nextId(kind);
|
|
954
|
+
const wrapper = h(doc, "div", "g-step");
|
|
955
|
+
if (opts.step.showOverlay) wrapper.appendChild(overlayEl(doc, opts));
|
|
956
|
+
else if (opts.step.dismissOnOutsideClick) wrapper.appendChild(overlayEl(doc, opts, true));
|
|
957
|
+
wrapper.appendChild(card);
|
|
958
|
+
opts.scope.appendChild(wrapper);
|
|
959
|
+
if (opts.step.target?.scrollIntoView !== false) scrollTo(target);
|
|
960
|
+
cleanups.push(anchor(target, card, { placement: opts.step.placement, offset: opts.step.offset, arrowEl }));
|
|
961
|
+
cleanups.push(setTargetDescribedBy(target, card.id));
|
|
962
|
+
cleanups.push(installKeyboard(card, opts.step, false, opts.onClose));
|
|
963
|
+
cleanups.push(focusInto(card));
|
|
964
|
+
return { el: wrapper, card, destroy: () => cleanupAll(cleanups, wrapper) };
|
|
965
|
+
}
|
|
966
|
+
function scrollTo(target) {
|
|
967
|
+
try {
|
|
968
|
+
target.scrollIntoView?.({ block: "nearest", inline: "nearest", behavior: "auto" });
|
|
969
|
+
} catch {
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
function renderSpotlight(doc, opts) {
|
|
973
|
+
const target = opts.target;
|
|
974
|
+
if (!target) return renderModal(doc, { ...opts, asModal: true });
|
|
975
|
+
const cleanups = [];
|
|
976
|
+
const wrapper = h(doc, "div", "g-step");
|
|
977
|
+
const pad = opts.step.spotlightPadding ?? 6;
|
|
978
|
+
const rects = ["top", "left", "right", "bottom"].map((side) => {
|
|
979
|
+
const r = h(doc, "div", `g-spot-rect g-spot-${side}`);
|
|
980
|
+
if (opts.step.dismissOnOutsideClick) r.addEventListener("click", () => opts.onClose());
|
|
981
|
+
wrapper.appendChild(r);
|
|
982
|
+
return r;
|
|
983
|
+
});
|
|
984
|
+
const ring = h(doc, "div", "g-spot-ring");
|
|
985
|
+
wrapper.appendChild(ring);
|
|
986
|
+
const { card } = buildCard(doc, opts, "g-spotlight-card");
|
|
987
|
+
card.setAttribute("role", "dialog");
|
|
988
|
+
const arrowEl = h(doc, "div", "g-arrow");
|
|
989
|
+
card.appendChild(arrowEl);
|
|
990
|
+
wrapper.appendChild(card);
|
|
991
|
+
opts.scope.appendChild(wrapper);
|
|
992
|
+
if (opts.step.target?.scrollIntoView !== false) scrollTo(target);
|
|
993
|
+
const win = doc.defaultView;
|
|
994
|
+
const layout = (r) => {
|
|
995
|
+
const vw = win?.innerWidth ?? 0;
|
|
996
|
+
const vh = win?.innerHeight ?? 0;
|
|
997
|
+
const x = Math.max(0, r.left - pad);
|
|
998
|
+
const y = Math.max(0, r.top - pad);
|
|
999
|
+
const w = Math.min(vw, r.right + pad) - x;
|
|
1000
|
+
const hgt = Math.min(vh, r.bottom + pad) - y;
|
|
1001
|
+
const [top, left, right, bottom] = rects;
|
|
1002
|
+
Object.assign(top.style, { left: "0", top: "0", width: "100%", height: `${y}px` });
|
|
1003
|
+
Object.assign(left.style, { left: "0", top: `${y}px`, width: `${x}px`, height: `${hgt}px` });
|
|
1004
|
+
Object.assign(right.style, { left: `${x + w}px`, top: `${y}px`, width: `${Math.max(0, vw - x - w)}px`, height: `${hgt}px` });
|
|
1005
|
+
Object.assign(bottom.style, { left: "0", top: `${y + hgt}px`, width: "100%", height: `${Math.max(0, vh - y - hgt)}px` });
|
|
1006
|
+
Object.assign(ring.style, { left: `${x}px`, top: `${y}px`, width: `${w}px`, height: `${hgt}px` });
|
|
1007
|
+
};
|
|
1008
|
+
cleanups.push(trackRect(target, layout));
|
|
1009
|
+
cleanups.push(anchor(target, card, { placement: opts.step.placement, offset: opts.step.offset + pad, arrowEl }));
|
|
1010
|
+
cleanups.push(installKeyboard(card, opts.step, false, opts.onClose));
|
|
1011
|
+
cleanups.push(focusInto(card));
|
|
1012
|
+
return { el: wrapper, card, destroy: () => cleanupAll(cleanups, wrapper) };
|
|
1013
|
+
}
|
|
1014
|
+
function renderHotspot(doc, opts) {
|
|
1015
|
+
const target = opts.target;
|
|
1016
|
+
if (!target) return renderModal(doc, { ...opts, asModal: true });
|
|
1017
|
+
const cleanups = [];
|
|
1018
|
+
const cfg = opts.step.hotspot ?? { size: 14, pulse: true, openOn: "click" };
|
|
1019
|
+
const wrapper = h(doc, "div", "g-step");
|
|
1020
|
+
const dot = h(doc, "button", `g-hotspot${cfg.pulse ? " g-pulse" : ""}`);
|
|
1021
|
+
dot.type = "button";
|
|
1022
|
+
dot.setAttribute("aria-label", opts.step.title || "Open hint");
|
|
1023
|
+
dot.setAttribute("aria-expanded", "false");
|
|
1024
|
+
dot.style.width = `${cfg.size}px`;
|
|
1025
|
+
dot.style.height = `${cfg.size}px`;
|
|
1026
|
+
dot.appendChild(h(doc, "span", "g-hotspot-hit"));
|
|
1027
|
+
wrapper.appendChild(dot);
|
|
1028
|
+
opts.scope.appendChild(wrapper);
|
|
1029
|
+
cleanups.push(trackRect(target, (r) => {
|
|
1030
|
+
dot.style.left = `${Math.round(r.right - cfg.size / 2)}px`;
|
|
1031
|
+
dot.style.top = `${Math.round(r.top - cfg.size / 2)}px`;
|
|
1032
|
+
}));
|
|
1033
|
+
let card = null;
|
|
1034
|
+
let stopAnchor = null;
|
|
1035
|
+
let stopKeys = null;
|
|
1036
|
+
const close = () => {
|
|
1037
|
+
stopAnchor?.();
|
|
1038
|
+
stopKeys?.();
|
|
1039
|
+
card?.remove();
|
|
1040
|
+
card = null;
|
|
1041
|
+
dot.setAttribute("aria-expanded", "false");
|
|
1042
|
+
};
|
|
1043
|
+
const open = () => {
|
|
1044
|
+
if (card) return;
|
|
1045
|
+
const built = buildCard(doc, { ...opts, onClose: () => opts.onClose() }, "g-hotspot-card");
|
|
1046
|
+
card = built.card;
|
|
1047
|
+
card.setAttribute("role", "dialog");
|
|
1048
|
+
const arrowEl = h(doc, "div", "g-arrow");
|
|
1049
|
+
card.appendChild(arrowEl);
|
|
1050
|
+
wrapper.appendChild(card);
|
|
1051
|
+
stopAnchor = anchor(target, card, { placement: opts.step.placement, offset: opts.step.offset, arrowEl });
|
|
1052
|
+
stopKeys = installKeyboard(card, opts.step, false, close);
|
|
1053
|
+
dot.setAttribute("aria-expanded", "true");
|
|
1054
|
+
opts.onOpen?.();
|
|
1055
|
+
if (cfg.openOn === "click") focusInto(card);
|
|
1056
|
+
};
|
|
1057
|
+
dot.addEventListener("click", (e) => {
|
|
1058
|
+
e.preventDefault();
|
|
1059
|
+
if (card) close();
|
|
1060
|
+
else open();
|
|
1061
|
+
});
|
|
1062
|
+
if (cfg.openOn === "hover") {
|
|
1063
|
+
dot.addEventListener("mouseenter", open);
|
|
1064
|
+
dot.addEventListener("focus", open);
|
|
1065
|
+
}
|
|
1066
|
+
cleanups.push(close);
|
|
1067
|
+
return { el: wrapper, card: dot, destroy: () => cleanupAll(cleanups, wrapper) };
|
|
1068
|
+
}
|
|
1069
|
+
function renderBanner(doc, opts) {
|
|
1070
|
+
const { step } = opts;
|
|
1071
|
+
const cleanups = [];
|
|
1072
|
+
const pos = step.position === "top" || step.placement === "top" || step.position.startsWith("top") ? "top" : "bottom";
|
|
1073
|
+
const banner = h(doc, "div", `g-banner g-pos-${pos}`);
|
|
1074
|
+
banner.setAttribute("role", "status");
|
|
1075
|
+
banner.setAttribute("data-step-id", step.id);
|
|
1076
|
+
const body = h(doc, "div", "g-body");
|
|
1077
|
+
if (step.title) body.appendChild(h(doc, "strong", "", `${step.title} `));
|
|
1078
|
+
const text = h(doc, "span");
|
|
1079
|
+
setSanitizedHtml(text, step.body);
|
|
1080
|
+
body.appendChild(text);
|
|
1081
|
+
banner.appendChild(body);
|
|
1082
|
+
buildButtons(doc, step, opts.onButton).forEach((b) => banner.appendChild(b));
|
|
1083
|
+
if (step.showClose) {
|
|
1084
|
+
const close = h(doc, "button", "g-close", "\xD7");
|
|
1085
|
+
close.type = "button";
|
|
1086
|
+
close.setAttribute("aria-label", "Dismiss");
|
|
1087
|
+
close.addEventListener("click", () => opts.onClose());
|
|
1088
|
+
banner.appendChild(close);
|
|
1089
|
+
}
|
|
1090
|
+
opts.scope.appendChild(banner);
|
|
1091
|
+
cleanups.push(installKeyboard(banner, step, false, opts.onClose));
|
|
1092
|
+
return { el: banner, card: banner, destroy: () => cleanupAll(cleanups, banner) };
|
|
1093
|
+
}
|
|
1094
|
+
function renderSlideout(doc, opts) {
|
|
1095
|
+
const cleanups = [];
|
|
1096
|
+
const pos = opts.step.position === "top" ? "top-right" : opts.step.position === "bottom" ? "bottom-right" : opts.step.position;
|
|
1097
|
+
const { card } = buildCard(doc, opts, `g-slideout ${positionClass(pos)}`);
|
|
1098
|
+
card.setAttribute("role", "dialog");
|
|
1099
|
+
const wrapper = h(doc, "div", "g-step");
|
|
1100
|
+
if (opts.step.dismissOnOutsideClick) wrapper.appendChild(overlayEl(doc, opts, true));
|
|
1101
|
+
wrapper.appendChild(card);
|
|
1102
|
+
opts.scope.appendChild(wrapper);
|
|
1103
|
+
cleanups.push(installKeyboard(card, opts.step, false, opts.onClose));
|
|
1104
|
+
cleanups.push(focusInto(card));
|
|
1105
|
+
return { el: wrapper, card, destroy: () => cleanupAll(cleanups, wrapper) };
|
|
1106
|
+
}
|
|
1107
|
+
function renderCustom(doc, opts) {
|
|
1108
|
+
const cleanups = [];
|
|
1109
|
+
const wrapper = h(doc, "div", "g-step");
|
|
1110
|
+
if (opts.step.showOverlay) wrapper.appendChild(overlayEl(doc, opts));
|
|
1111
|
+
const el2 = h(doc, "div", "g-custom");
|
|
1112
|
+
el2.tabIndex = -1;
|
|
1113
|
+
el2.setAttribute("data-step-id", opts.step.id);
|
|
1114
|
+
setSanitizedHtml(el2, opts.step.customHtml || opts.step.body || "");
|
|
1115
|
+
const onClick = (e) => {
|
|
1116
|
+
const t = e.target?.closest?.("[data-g-action]");
|
|
1117
|
+
const action = t?.getAttribute("data-g-action");
|
|
1118
|
+
if (!action) return;
|
|
1119
|
+
e.preventDefault();
|
|
1120
|
+
if (action === "dismiss") opts.onClose();
|
|
1121
|
+
else opts.onButton({ id: `custom-${action}`, label: action, action, variant: "primary", value: t?.getAttribute("data-g-value") || void 0 });
|
|
1122
|
+
};
|
|
1123
|
+
el2.addEventListener("click", onClick);
|
|
1124
|
+
wrapper.appendChild(el2);
|
|
1125
|
+
opts.scope.appendChild(wrapper);
|
|
1126
|
+
cleanups.push(installKeyboard(el2, opts.step, false, opts.onClose));
|
|
1127
|
+
cleanups.push(focusInto(el2));
|
|
1128
|
+
return { el: wrapper, card: el2, destroy: () => cleanupAll(cleanups, wrapper) };
|
|
1129
|
+
}
|
|
1130
|
+
function renderStep(opts) {
|
|
1131
|
+
const doc = opts.scope.ownerDocument;
|
|
1132
|
+
const type = opts.asModal ? "modal" : opts.step.type;
|
|
1133
|
+
switch (type) {
|
|
1134
|
+
case "tooltip":
|
|
1135
|
+
return renderTooltip(doc, opts, "tooltip");
|
|
1136
|
+
case "popover":
|
|
1137
|
+
return renderTooltip(doc, opts, "popover");
|
|
1138
|
+
case "spotlight":
|
|
1139
|
+
return renderSpotlight(doc, opts);
|
|
1140
|
+
case "hotspot":
|
|
1141
|
+
return renderHotspot(doc, opts);
|
|
1142
|
+
case "banner":
|
|
1143
|
+
return renderBanner(doc, opts);
|
|
1144
|
+
case "slideout":
|
|
1145
|
+
return renderSlideout(doc, opts);
|
|
1146
|
+
case "custom":
|
|
1147
|
+
return renderCustom(doc, opts);
|
|
1148
|
+
case "modal":
|
|
1149
|
+
case "checklist":
|
|
1150
|
+
case "survey":
|
|
1151
|
+
default:
|
|
1152
|
+
return renderModal(doc, opts);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
function isAnchoredStep(step) {
|
|
1156
|
+
return (step.type === "tooltip" || step.type === "popover" || step.type === "spotlight" || step.type === "hotspot") && !!step.target && step.target.selectors.length > 0;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
// src/controller.ts
|
|
1160
|
+
var import_runtime3 = require("@guidelytech/shared/runtime");
|
|
1161
|
+
function noop() {
|
|
1162
|
+
}
|
|
1163
|
+
function runGuide(guide, options = {}) {
|
|
1164
|
+
const doc = options.doc ?? (options.container?.ownerDocument || document);
|
|
1165
|
+
const steps = guide.config.steps;
|
|
1166
|
+
const total = steps.length;
|
|
1167
|
+
const onEvent = options.onEvent ?? noop;
|
|
1168
|
+
const onError = options.onError ?? noop;
|
|
1169
|
+
const getCtx = () => (typeof options.ctx === "function" ? options.ctx() : options.ctx) ?? null;
|
|
1170
|
+
const currentUrl = options.currentUrl ?? (() => typeof location !== "undefined" ? location.href : "");
|
|
1171
|
+
let status = "idle";
|
|
1172
|
+
let index = -1;
|
|
1173
|
+
let pendingIndex = -1;
|
|
1174
|
+
let view = null;
|
|
1175
|
+
const stepCleanups = [];
|
|
1176
|
+
let started = false;
|
|
1177
|
+
let stepDone = false;
|
|
1178
|
+
let ended = false;
|
|
1179
|
+
const history = [];
|
|
1180
|
+
let scope = null;
|
|
1181
|
+
const emit = (name, step, stepIndex, properties) => {
|
|
1182
|
+
try {
|
|
1183
|
+
onEvent({ name, guideId: guide.id, guideKey: guide.key, guideVersion: guide.version, stepId: step?.id, stepIndex, properties });
|
|
1184
|
+
} catch (err) {
|
|
1185
|
+
onError(err);
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
const announce = (text) => {
|
|
1189
|
+
try {
|
|
1190
|
+
ensureHost(doc).announce(text);
|
|
1191
|
+
} catch {
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
const getScope = () => {
|
|
1195
|
+
if (options.container) return options.container;
|
|
1196
|
+
if (!scope) scope = createScope(options.theme, guide.config.appearance, doc);
|
|
1197
|
+
return scope.el;
|
|
1198
|
+
};
|
|
1199
|
+
const clearStep = () => {
|
|
1200
|
+
stepCleanups.splice(0).forEach((fn) => {
|
|
1201
|
+
try {
|
|
1202
|
+
fn();
|
|
1203
|
+
} catch {
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
try {
|
|
1207
|
+
view?.destroy();
|
|
1208
|
+
} catch (err) {
|
|
1209
|
+
onError(err);
|
|
1210
|
+
}
|
|
1211
|
+
view = null;
|
|
1212
|
+
stepDone = false;
|
|
1213
|
+
};
|
|
1214
|
+
const end = (reason) => {
|
|
1215
|
+
if (ended) return;
|
|
1216
|
+
ended = true;
|
|
1217
|
+
const step = steps[index];
|
|
1218
|
+
clearStep();
|
|
1219
|
+
status = "ended";
|
|
1220
|
+
if (reason === "completed") emit("guide_completed", step, index);
|
|
1221
|
+
else if (reason === "dismissed") emit("guide_dismissed", step, index);
|
|
1222
|
+
else if (reason === "skipped") emit("guide_skipped", step, index);
|
|
1223
|
+
scope?.destroy();
|
|
1224
|
+
scope = null;
|
|
1225
|
+
try {
|
|
1226
|
+
options.onEnd?.(reason);
|
|
1227
|
+
} catch (err) {
|
|
1228
|
+
onError(err);
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
const completeStep = () => {
|
|
1232
|
+
if (stepDone || index < 0) return;
|
|
1233
|
+
stepDone = true;
|
|
1234
|
+
emit("step_completed", steps[index], index);
|
|
1235
|
+
};
|
|
1236
|
+
const goNext = (overrideStepId) => {
|
|
1237
|
+
const step = steps[index];
|
|
1238
|
+
let target = -1;
|
|
1239
|
+
const ctx = getCtx();
|
|
1240
|
+
if (step && ctx) {
|
|
1241
|
+
for (const branch of step.branches) {
|
|
1242
|
+
if ((0, import_runtime3.evaluateRules)(branch.when, ctx)) {
|
|
1243
|
+
target = steps.findIndex((s) => s.id === branch.goTo);
|
|
1244
|
+
if (target >= 0) break;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
if (target < 0 && overrideStepId) target = steps.findIndex((s) => s.id === overrideStepId);
|
|
1249
|
+
if (target < 0) target = index + 1;
|
|
1250
|
+
if (target >= total) return end("completed");
|
|
1251
|
+
history.push(index);
|
|
1252
|
+
showStep(target, 1);
|
|
1253
|
+
};
|
|
1254
|
+
const advance = () => {
|
|
1255
|
+
if (ended) return;
|
|
1256
|
+
completeStep();
|
|
1257
|
+
goNext();
|
|
1258
|
+
};
|
|
1259
|
+
const handleButton = (b) => {
|
|
1260
|
+
try {
|
|
1261
|
+
switch (b.action) {
|
|
1262
|
+
case "next":
|
|
1263
|
+
completeStep();
|
|
1264
|
+
goNext(b.value);
|
|
1265
|
+
break;
|
|
1266
|
+
case "back":
|
|
1267
|
+
controller.back();
|
|
1268
|
+
break;
|
|
1269
|
+
case "dismiss":
|
|
1270
|
+
end("dismissed");
|
|
1271
|
+
break;
|
|
1272
|
+
case "complete":
|
|
1273
|
+
completeStep();
|
|
1274
|
+
end("completed");
|
|
1275
|
+
break;
|
|
1276
|
+
case "skip":
|
|
1277
|
+
end("skipped");
|
|
1278
|
+
break;
|
|
1279
|
+
case "url": {
|
|
1280
|
+
completeStep();
|
|
1281
|
+
const url = b.value || "";
|
|
1282
|
+
if (options.onNavigate) options.onNavigate(url, b.newTab);
|
|
1283
|
+
else if (b.newTab) window.open(url, "_blank", "noopener");
|
|
1284
|
+
else location.assign(url);
|
|
1285
|
+
if (index + 1 >= total) end("completed");
|
|
1286
|
+
else goNext();
|
|
1287
|
+
break;
|
|
1288
|
+
}
|
|
1289
|
+
case "start_guide":
|
|
1290
|
+
completeStep();
|
|
1291
|
+
end("completed");
|
|
1292
|
+
options.onAction?.("start_guide", b.value, b);
|
|
1293
|
+
break;
|
|
1294
|
+
case "event":
|
|
1295
|
+
options.onAction?.("event", b.value, b);
|
|
1296
|
+
break;
|
|
1297
|
+
case "open_resource_center":
|
|
1298
|
+
options.onAction?.("open_resource_center", b.value, b);
|
|
1299
|
+
break;
|
|
1300
|
+
default:
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
} catch (err) {
|
|
1304
|
+
onError(err);
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
const setupAdvance = (step) => {
|
|
1308
|
+
const modes = step.advanceOn === "any" ? ["element_click", "element_visible", "event", "delay"] : [step.advanceOn];
|
|
1309
|
+
for (const mode of modes) {
|
|
1310
|
+
if (mode === "element_click" && step.advanceValue) {
|
|
1311
|
+
const selector = step.advanceValue;
|
|
1312
|
+
const handler = (e) => {
|
|
1313
|
+
const t = e.target;
|
|
1314
|
+
try {
|
|
1315
|
+
if (t && typeof t.closest === "function" && t.closest(selector)) advance();
|
|
1316
|
+
} catch {
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
doc.addEventListener("click", handler, true);
|
|
1320
|
+
doc.addEventListener("focusin", handler, true);
|
|
1321
|
+
stepCleanups.push(() => {
|
|
1322
|
+
doc.removeEventListener("click", handler, true);
|
|
1323
|
+
doc.removeEventListener("focusin", handler, true);
|
|
1324
|
+
});
|
|
1325
|
+
} else if (mode === "element_visible" && step.advanceValue) {
|
|
1326
|
+
const ac = new AbortController();
|
|
1327
|
+
stepCleanups.push(() => ac.abort());
|
|
1328
|
+
waitForTarget([{ kind: "css", value: step.advanceValue }], { timeoutMs: 0, signal: ac.signal, root: doc }).then((el2) => {
|
|
1329
|
+
if (ac.signal.aborted) return;
|
|
1330
|
+
if (typeof IntersectionObserver === "undefined") return advance();
|
|
1331
|
+
const io = new IntersectionObserver((entries) => {
|
|
1332
|
+
if (entries.some((en) => en.isIntersecting)) {
|
|
1333
|
+
io.disconnect();
|
|
1334
|
+
advance();
|
|
1335
|
+
}
|
|
1336
|
+
});
|
|
1337
|
+
io.observe(el2);
|
|
1338
|
+
stepCleanups.push(() => io.disconnect());
|
|
1339
|
+
}).catch(noop);
|
|
1340
|
+
} else if (mode === "event" && step.advanceValue && options.eventBus) {
|
|
1341
|
+
stepCleanups.push(options.eventBus.on(step.advanceValue, advance));
|
|
1342
|
+
} else if (mode === "delay") {
|
|
1343
|
+
const t = setTimeout(advance, step.advanceDelayMs ?? 3e3);
|
|
1344
|
+
stepCleanups.push(() => clearTimeout(t));
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
const render = (step, target, asModal = false) => {
|
|
1349
|
+
if (ended) return;
|
|
1350
|
+
status = "running";
|
|
1351
|
+
try {
|
|
1352
|
+
view = renderStep({
|
|
1353
|
+
scope: getScope(),
|
|
1354
|
+
step,
|
|
1355
|
+
index,
|
|
1356
|
+
total,
|
|
1357
|
+
target,
|
|
1358
|
+
asModal,
|
|
1359
|
+
onButton: handleButton,
|
|
1360
|
+
onClose: () => end("dismissed"),
|
|
1361
|
+
announce
|
|
1362
|
+
});
|
|
1363
|
+
} catch (err) {
|
|
1364
|
+
onError(err);
|
|
1365
|
+
view = null;
|
|
1366
|
+
if (index + 1 < total) return goNext();
|
|
1367
|
+
return end("skipped");
|
|
1368
|
+
}
|
|
1369
|
+
if (!started) {
|
|
1370
|
+
started = true;
|
|
1371
|
+
emit("guide_started", step, index);
|
|
1372
|
+
}
|
|
1373
|
+
emit("step_viewed", step, index, asModal ? { fallback: "show_as_modal" } : void 0);
|
|
1374
|
+
announce(step.title ? `${step.title}. Step ${index + 1} of ${total}` : `Step ${index + 1} of ${total}`);
|
|
1375
|
+
setupAdvance(step);
|
|
1376
|
+
};
|
|
1377
|
+
const applyFallback = (step, direction) => {
|
|
1378
|
+
const fallback = step.target?.fallback ?? "skip";
|
|
1379
|
+
emit("step_viewed", step, index, { fallback, targetMissing: true });
|
|
1380
|
+
if (fallback === "show_as_modal") return render(step, null, true);
|
|
1381
|
+
if (fallback === "end_guide") return end("skipped");
|
|
1382
|
+
const nextIndex = index + direction;
|
|
1383
|
+
if (nextIndex < 0) return showStep(0, 1);
|
|
1384
|
+
if (nextIndex >= total) return end("completed");
|
|
1385
|
+
showStep(nextIndex, direction);
|
|
1386
|
+
};
|
|
1387
|
+
function showStep(i, direction = 1) {
|
|
1388
|
+
if (ended) return;
|
|
1389
|
+
clearStep();
|
|
1390
|
+
if (i < 0) i = 0;
|
|
1391
|
+
if (i >= total) return end("completed");
|
|
1392
|
+
index = i;
|
|
1393
|
+
const step = steps[i];
|
|
1394
|
+
const ctx = getCtx();
|
|
1395
|
+
if (step.targeting && step.targeting.rules.length && ctx && !(0, import_runtime3.evaluateRules)(step.targeting, ctx)) {
|
|
1396
|
+
const nextIndex = i + direction;
|
|
1397
|
+
if (nextIndex >= total) return end("completed");
|
|
1398
|
+
if (nextIndex < 0) return;
|
|
1399
|
+
return showStep(nextIndex, direction);
|
|
1400
|
+
}
|
|
1401
|
+
if (step.url && !urlMatches(step.url, currentUrl())) {
|
|
1402
|
+
status = "waiting_url";
|
|
1403
|
+
pendingIndex = i;
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
pendingIndex = -1;
|
|
1407
|
+
if (isAnchoredStep(step) && step.target) {
|
|
1408
|
+
status = "waiting_target";
|
|
1409
|
+
const ac = new AbortController();
|
|
1410
|
+
stepCleanups.push(() => ac.abort());
|
|
1411
|
+
const timeoutMs = step.target.fallback === "wait" ? 0 : step.target.waitMs;
|
|
1412
|
+
waitForTarget(step.target, { timeoutMs, signal: ac.signal, root: doc }).then((el2) => {
|
|
1413
|
+
if (ac.signal.aborted || ended) return;
|
|
1414
|
+
render(step, el2);
|
|
1415
|
+
}).catch((err) => {
|
|
1416
|
+
if (ac.signal.aborted || ended) return;
|
|
1417
|
+
if (err && err.name === "AbortError") return;
|
|
1418
|
+
applyFallback(step, direction);
|
|
1419
|
+
});
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
render(step, null);
|
|
1423
|
+
}
|
|
1424
|
+
const controller = {
|
|
1425
|
+
guide,
|
|
1426
|
+
start() {
|
|
1427
|
+
if (status !== "idle") return;
|
|
1428
|
+
emit("guide_viewed");
|
|
1429
|
+
if (total === 0) return end("completed");
|
|
1430
|
+
let startIndex = options.startAtStep ? steps.findIndex((s) => s.id === options.startAtStep) : 0;
|
|
1431
|
+
if (startIndex < 0) startIndex = 0;
|
|
1432
|
+
showStep(startIndex, 1);
|
|
1433
|
+
},
|
|
1434
|
+
next() {
|
|
1435
|
+
if (ended || index < 0) return;
|
|
1436
|
+
completeStep();
|
|
1437
|
+
goNext();
|
|
1438
|
+
},
|
|
1439
|
+
back() {
|
|
1440
|
+
if (ended) return;
|
|
1441
|
+
const prev = history.pop();
|
|
1442
|
+
if (prev == null) {
|
|
1443
|
+
if (index > 0) showStep(index - 1, -1);
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
showStep(prev, -1);
|
|
1447
|
+
},
|
|
1448
|
+
goTo(stepId) {
|
|
1449
|
+
const i = steps.findIndex((s) => s.id === stepId);
|
|
1450
|
+
if (i >= 0 && !ended) {
|
|
1451
|
+
if (index >= 0) history.push(index);
|
|
1452
|
+
showStep(i, 1);
|
|
1453
|
+
}
|
|
1454
|
+
},
|
|
1455
|
+
dismiss: () => end("dismissed"),
|
|
1456
|
+
complete() {
|
|
1457
|
+
completeStep();
|
|
1458
|
+
end("completed");
|
|
1459
|
+
},
|
|
1460
|
+
skip: () => end("skipped"),
|
|
1461
|
+
resume() {
|
|
1462
|
+
if (ended) return;
|
|
1463
|
+
if (status === "waiting_url" && pendingIndex >= 0) {
|
|
1464
|
+
showStep(pendingIndex, 1);
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
const step = steps[index];
|
|
1468
|
+
if (step?.url && status === "running" && !urlMatches(step.url, currentUrl())) showStep(index, 1);
|
|
1469
|
+
},
|
|
1470
|
+
destroy() {
|
|
1471
|
+
if (ended) return;
|
|
1472
|
+
ended = true;
|
|
1473
|
+
clearStep();
|
|
1474
|
+
status = "ended";
|
|
1475
|
+
scope?.destroy();
|
|
1476
|
+
scope = null;
|
|
1477
|
+
try {
|
|
1478
|
+
options.onEnd?.("destroyed");
|
|
1479
|
+
} catch (err) {
|
|
1480
|
+
onError(err);
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
getState: () => ({ status, stepId: steps[index]?.id ?? null, stepIndex: index, total })
|
|
1484
|
+
};
|
|
1485
|
+
return controller;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
// src/checklist.ts
|
|
1489
|
+
function isChecklistComplete(config, progress) {
|
|
1490
|
+
const done = new Set(progress.completedTaskIds);
|
|
1491
|
+
return config.tasks.filter((t) => t.required).every((t) => done.has(t.id));
|
|
1492
|
+
}
|
|
1493
|
+
function renderChecklist(options) {
|
|
1494
|
+
const { scope, config } = options;
|
|
1495
|
+
const doc = scope.ownerDocument;
|
|
1496
|
+
let progress = options.progress ?? { completedTaskIds: [] };
|
|
1497
|
+
let open = options.open ?? config.autoOpen;
|
|
1498
|
+
const pos = `g-pos-${config.position}`;
|
|
1499
|
+
const root = doc.createElement("div");
|
|
1500
|
+
root.className = "g-checklist";
|
|
1501
|
+
const launcher = doc.createElement("button");
|
|
1502
|
+
launcher.type = "button";
|
|
1503
|
+
launcher.className = `g-launcher ${pos}`;
|
|
1504
|
+
launcher.setAttribute("aria-expanded", "false");
|
|
1505
|
+
const ring = doc.createElement("span");
|
|
1506
|
+
ring.className = "g-ring";
|
|
1507
|
+
const count = doc.createElement("span");
|
|
1508
|
+
count.className = "g-count";
|
|
1509
|
+
ring.appendChild(count);
|
|
1510
|
+
launcher.appendChild(ring);
|
|
1511
|
+
const label = doc.createElement("span");
|
|
1512
|
+
label.textContent = config.launcherLabel;
|
|
1513
|
+
launcher.appendChild(label);
|
|
1514
|
+
const panel = doc.createElement("div");
|
|
1515
|
+
panel.className = `g-panel ${pos}`;
|
|
1516
|
+
panel.setAttribute("role", "dialog");
|
|
1517
|
+
panel.setAttribute("aria-label", config.launcherLabel);
|
|
1518
|
+
panel.hidden = true;
|
|
1519
|
+
const head = doc.createElement("div");
|
|
1520
|
+
head.className = "g-panel-head";
|
|
1521
|
+
const title = doc.createElement("h2");
|
|
1522
|
+
title.className = "g-panel-title";
|
|
1523
|
+
title.textContent = config.launcherLabel;
|
|
1524
|
+
const sub = doc.createElement("p");
|
|
1525
|
+
sub.className = "g-panel-sub";
|
|
1526
|
+
const bar = doc.createElement("div");
|
|
1527
|
+
bar.className = "g-bar";
|
|
1528
|
+
const fill = doc.createElement("span");
|
|
1529
|
+
bar.appendChild(fill);
|
|
1530
|
+
const close = doc.createElement("button");
|
|
1531
|
+
close.type = "button";
|
|
1532
|
+
close.className = "g-close";
|
|
1533
|
+
close.textContent = "\xD7";
|
|
1534
|
+
close.setAttribute("aria-label", "Minimize checklist");
|
|
1535
|
+
head.append(title, sub, bar, close);
|
|
1536
|
+
const body = doc.createElement("div");
|
|
1537
|
+
body.className = "g-panel-body";
|
|
1538
|
+
const foot = doc.createElement("div");
|
|
1539
|
+
foot.className = "g-panel-foot";
|
|
1540
|
+
panel.append(head, body, foot);
|
|
1541
|
+
root.append(launcher, panel);
|
|
1542
|
+
scope.appendChild(root);
|
|
1543
|
+
const setOpen = (v) => {
|
|
1544
|
+
open = v;
|
|
1545
|
+
panel.hidden = !v;
|
|
1546
|
+
launcher.setAttribute("aria-expanded", String(v));
|
|
1547
|
+
if (v) {
|
|
1548
|
+
(panel.querySelector(".g-task:not([disabled])") || close).focus?.({ preventScroll: true });
|
|
1549
|
+
options.onOpen?.();
|
|
1550
|
+
} else options.onClose?.();
|
|
1551
|
+
};
|
|
1552
|
+
const renderTasks = () => {
|
|
1553
|
+
const done = new Set(progress.completedTaskIds);
|
|
1554
|
+
const doneCount = config.tasks.filter((t) => done.has(t.id)).length;
|
|
1555
|
+
const pct = config.tasks.length ? Math.round(doneCount / config.tasks.length * 100) : 0;
|
|
1556
|
+
count.textContent = `${doneCount}/${config.tasks.length}`;
|
|
1557
|
+
launcher.style.setProperty("--g-pct", `${pct}%`);
|
|
1558
|
+
launcher.setAttribute("aria-label", `${config.launcherLabel}: ${doneCount} of ${config.tasks.length} tasks completed`);
|
|
1559
|
+
sub.textContent = `${doneCount} of ${config.tasks.length} completed`;
|
|
1560
|
+
fill.style.width = `${pct}%`;
|
|
1561
|
+
bar.setAttribute("role", "progressbar");
|
|
1562
|
+
bar.setAttribute("aria-valuenow", String(pct));
|
|
1563
|
+
bar.setAttribute("aria-valuemin", "0");
|
|
1564
|
+
bar.setAttribute("aria-valuemax", "100");
|
|
1565
|
+
body.textContent = "";
|
|
1566
|
+
foot.textContent = "";
|
|
1567
|
+
const complete = isChecklistComplete(config, progress);
|
|
1568
|
+
if (complete) {
|
|
1569
|
+
const wrap = doc.createElement("div");
|
|
1570
|
+
wrap.className = "g-complete";
|
|
1571
|
+
const t = doc.createElement("h3");
|
|
1572
|
+
t.className = "g-title";
|
|
1573
|
+
t.textContent = config.completionTitle;
|
|
1574
|
+
const b = doc.createElement("div");
|
|
1575
|
+
b.className = "g-body";
|
|
1576
|
+
setSanitizedHtml(b, config.completionBody);
|
|
1577
|
+
wrap.append(t, b);
|
|
1578
|
+
body.appendChild(wrap);
|
|
1579
|
+
}
|
|
1580
|
+
const list = doc.createElement("div");
|
|
1581
|
+
list.setAttribute("role", "list");
|
|
1582
|
+
let locked = false;
|
|
1583
|
+
config.tasks.forEach((task, i) => {
|
|
1584
|
+
const isDone = done.has(task.id);
|
|
1585
|
+
const btn = doc.createElement("button");
|
|
1586
|
+
btn.type = "button";
|
|
1587
|
+
btn.className = `g-task${isDone ? " g-done" : ""}`;
|
|
1588
|
+
btn.setAttribute("role", "listitem");
|
|
1589
|
+
btn.setAttribute("data-task-id", task.id);
|
|
1590
|
+
btn.setAttribute("aria-checked", String(isDone));
|
|
1591
|
+
if (config.ordered && locked && !isDone) {
|
|
1592
|
+
btn.disabled = true;
|
|
1593
|
+
btn.title = "Complete the previous task first";
|
|
1594
|
+
}
|
|
1595
|
+
if (config.ordered && !isDone) locked = true;
|
|
1596
|
+
const check = doc.createElement("span");
|
|
1597
|
+
check.className = "g-check";
|
|
1598
|
+
check.setAttribute("aria-hidden", "true");
|
|
1599
|
+
check.textContent = isDone ? "\u2713" : "";
|
|
1600
|
+
const text = doc.createElement("span");
|
|
1601
|
+
const tt = doc.createElement("div");
|
|
1602
|
+
tt.className = "g-task-title";
|
|
1603
|
+
tt.textContent = `${i + 1}. ${task.title}`;
|
|
1604
|
+
text.appendChild(tt);
|
|
1605
|
+
if (task.description) {
|
|
1606
|
+
const td = doc.createElement("div");
|
|
1607
|
+
td.className = "g-task-desc";
|
|
1608
|
+
td.textContent = task.description;
|
|
1609
|
+
text.appendChild(td);
|
|
1610
|
+
}
|
|
1611
|
+
btn.append(check, text);
|
|
1612
|
+
btn.addEventListener("click", () => options.onTaskClick?.(task));
|
|
1613
|
+
list.appendChild(btn);
|
|
1614
|
+
});
|
|
1615
|
+
body.appendChild(list);
|
|
1616
|
+
if (config.dismissible) {
|
|
1617
|
+
const dismiss = doc.createElement("button");
|
|
1618
|
+
dismiss.type = "button";
|
|
1619
|
+
dismiss.className = "g-btn g-btn-ghost";
|
|
1620
|
+
dismiss.textContent = complete ? "Close" : "Dismiss checklist";
|
|
1621
|
+
dismiss.addEventListener("click", () => options.onDismiss?.());
|
|
1622
|
+
foot.appendChild(dismiss);
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
launcher.addEventListener("click", () => setOpen(!open));
|
|
1626
|
+
close.addEventListener("click", () => setOpen(false));
|
|
1627
|
+
const onKey = (e) => {
|
|
1628
|
+
if (e.key === "Escape" && open) {
|
|
1629
|
+
e.stopPropagation();
|
|
1630
|
+
setOpen(false);
|
|
1631
|
+
launcher.focus();
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
panel.addEventListener("keydown", onKey);
|
|
1635
|
+
renderTasks();
|
|
1636
|
+
if (open) setOpen(true);
|
|
1637
|
+
return {
|
|
1638
|
+
el: root,
|
|
1639
|
+
open: () => setOpen(true),
|
|
1640
|
+
close: () => setOpen(false),
|
|
1641
|
+
toggle: () => setOpen(!open),
|
|
1642
|
+
isOpen: () => open,
|
|
1643
|
+
setProgress(p) {
|
|
1644
|
+
progress = p;
|
|
1645
|
+
renderTasks();
|
|
1646
|
+
},
|
|
1647
|
+
destroy() {
|
|
1648
|
+
panel.removeEventListener("keydown", onKey);
|
|
1649
|
+
root.remove();
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// src/survey.ts
|
|
1655
|
+
function isQuestionVisible(q, answers) {
|
|
1656
|
+
if (!q.showWhen) return true;
|
|
1657
|
+
const actual = answers[q.showWhen.questionId];
|
|
1658
|
+
if (actual === void 0) return false;
|
|
1659
|
+
const expected = q.showWhen.value;
|
|
1660
|
+
switch (q.showWhen.op) {
|
|
1661
|
+
case "equals":
|
|
1662
|
+
return Array.isArray(actual) ? actual.includes(String(expected)) : String(actual) === String(expected);
|
|
1663
|
+
case "lte":
|
|
1664
|
+
return Number(actual) <= Number(expected);
|
|
1665
|
+
case "gte":
|
|
1666
|
+
return Number(actual) >= Number(expected);
|
|
1667
|
+
case "in": {
|
|
1668
|
+
const list = Array.isArray(expected) ? expected : [String(expected)];
|
|
1669
|
+
return Array.isArray(actual) ? actual.some((a) => list.includes(a)) : list.includes(String(actual));
|
|
1670
|
+
}
|
|
1671
|
+
default:
|
|
1672
|
+
return false;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
function renderSurvey(options) {
|
|
1676
|
+
const { scope, config } = options;
|
|
1677
|
+
const doc = scope.ownerDocument;
|
|
1678
|
+
const answers = {};
|
|
1679
|
+
const card = doc.createElement("div");
|
|
1680
|
+
card.className = `g-card g-survey g-slideout g-pos-${config.position}`;
|
|
1681
|
+
card.setAttribute("role", "dialog");
|
|
1682
|
+
card.setAttribute("aria-label", options.title || "Survey");
|
|
1683
|
+
card.tabIndex = -1;
|
|
1684
|
+
const inner = doc.createElement("div");
|
|
1685
|
+
inner.className = "g-inner";
|
|
1686
|
+
card.appendChild(inner);
|
|
1687
|
+
if (options.onDismiss) {
|
|
1688
|
+
const close = doc.createElement("button");
|
|
1689
|
+
close.type = "button";
|
|
1690
|
+
close.className = "g-close";
|
|
1691
|
+
close.textContent = "\xD7";
|
|
1692
|
+
close.setAttribute("aria-label", "Close survey");
|
|
1693
|
+
close.addEventListener("click", () => options.onDismiss?.());
|
|
1694
|
+
card.appendChild(close);
|
|
1695
|
+
}
|
|
1696
|
+
scope.appendChild(card);
|
|
1697
|
+
const form = doc.createElement("form");
|
|
1698
|
+
form.noValidate = true;
|
|
1699
|
+
inner.appendChild(form);
|
|
1700
|
+
const errorEl = doc.createElement("div");
|
|
1701
|
+
errorEl.className = "g-error";
|
|
1702
|
+
errorEl.setAttribute("role", "alert");
|
|
1703
|
+
const setAnswer = (id, v) => {
|
|
1704
|
+
if (v === void 0 || v === "" || Array.isArray(v) && v.length === 0) delete answers[id];
|
|
1705
|
+
else answers[id] = v;
|
|
1706
|
+
options.onChange?.({ ...answers });
|
|
1707
|
+
updateVisibility();
|
|
1708
|
+
};
|
|
1709
|
+
const questionEls = /* @__PURE__ */ new Map();
|
|
1710
|
+
const scaleButtons = (q, min, max, labels) => {
|
|
1711
|
+
const wrap = doc.createElement("div");
|
|
1712
|
+
const row = doc.createElement("div");
|
|
1713
|
+
row.className = "g-scale";
|
|
1714
|
+
row.setAttribute("role", "radiogroup");
|
|
1715
|
+
row.setAttribute("aria-label", q.title);
|
|
1716
|
+
for (let i = min; i <= max; i++) {
|
|
1717
|
+
const b = doc.createElement("button");
|
|
1718
|
+
b.type = "button";
|
|
1719
|
+
b.textContent = String(i);
|
|
1720
|
+
b.setAttribute("aria-pressed", "false");
|
|
1721
|
+
b.addEventListener("click", () => {
|
|
1722
|
+
row.querySelectorAll("button").forEach((x) => x.setAttribute("aria-pressed", "false"));
|
|
1723
|
+
b.setAttribute("aria-pressed", "true");
|
|
1724
|
+
setAnswer(q.id, i);
|
|
1725
|
+
});
|
|
1726
|
+
row.appendChild(b);
|
|
1727
|
+
}
|
|
1728
|
+
wrap.appendChild(row);
|
|
1729
|
+
if (labels && (q.lowLabel || q.highLabel)) {
|
|
1730
|
+
const l = doc.createElement("div");
|
|
1731
|
+
l.className = "g-scale-labels";
|
|
1732
|
+
l.append(Object.assign(doc.createElement("span"), { textContent: q.lowLabel || "" }), Object.assign(doc.createElement("span"), { textContent: q.highLabel || "" }));
|
|
1733
|
+
wrap.appendChild(l);
|
|
1734
|
+
}
|
|
1735
|
+
return wrap;
|
|
1736
|
+
};
|
|
1737
|
+
const buildInput = (q) => {
|
|
1738
|
+
switch (q.type) {
|
|
1739
|
+
case "nps":
|
|
1740
|
+
return scaleButtons(q, 0, 10, true);
|
|
1741
|
+
case "csat":
|
|
1742
|
+
return scaleButtons(q, 1, q.scaleMax ?? 5, true);
|
|
1743
|
+
case "rating": {
|
|
1744
|
+
const max = q.scaleMax ?? 5;
|
|
1745
|
+
const row = doc.createElement("div");
|
|
1746
|
+
row.className = "g-stars";
|
|
1747
|
+
row.setAttribute("role", "radiogroup");
|
|
1748
|
+
row.setAttribute("aria-label", q.title);
|
|
1749
|
+
const btns = [];
|
|
1750
|
+
for (let i = 1; i <= max; i++) {
|
|
1751
|
+
const b = doc.createElement("button");
|
|
1752
|
+
b.type = "button";
|
|
1753
|
+
b.textContent = "\u2605";
|
|
1754
|
+
b.setAttribute("aria-label", `${i} of ${max}`);
|
|
1755
|
+
b.setAttribute("aria-pressed", "false");
|
|
1756
|
+
b.addEventListener("click", () => {
|
|
1757
|
+
btns.forEach((x, j) => {
|
|
1758
|
+
x.classList.toggle("g-on", j < i);
|
|
1759
|
+
x.setAttribute("aria-pressed", String(j === i - 1));
|
|
1760
|
+
});
|
|
1761
|
+
setAnswer(q.id, i);
|
|
1762
|
+
});
|
|
1763
|
+
btns.push(b);
|
|
1764
|
+
row.appendChild(b);
|
|
1765
|
+
}
|
|
1766
|
+
return row;
|
|
1767
|
+
}
|
|
1768
|
+
case "thumbs": {
|
|
1769
|
+
const row = doc.createElement("div");
|
|
1770
|
+
row.className = "g-thumbs";
|
|
1771
|
+
row.setAttribute("role", "radiogroup");
|
|
1772
|
+
[
|
|
1773
|
+
["up", "\u{1F44D}", "Thumbs up"],
|
|
1774
|
+
["down", "\u{1F44E}", "Thumbs down"]
|
|
1775
|
+
].forEach(([val, icon, lbl]) => {
|
|
1776
|
+
const b = doc.createElement("button");
|
|
1777
|
+
b.type = "button";
|
|
1778
|
+
b.textContent = icon;
|
|
1779
|
+
b.setAttribute("aria-label", lbl);
|
|
1780
|
+
b.setAttribute("aria-pressed", "false");
|
|
1781
|
+
b.addEventListener("click", () => {
|
|
1782
|
+
row.querySelectorAll("button").forEach((x) => x.setAttribute("aria-pressed", "false"));
|
|
1783
|
+
b.setAttribute("aria-pressed", "true");
|
|
1784
|
+
setAnswer(q.id, val === "up");
|
|
1785
|
+
});
|
|
1786
|
+
row.appendChild(b);
|
|
1787
|
+
});
|
|
1788
|
+
return row;
|
|
1789
|
+
}
|
|
1790
|
+
case "single_choice":
|
|
1791
|
+
case "multiple_choice": {
|
|
1792
|
+
const multi = q.type === "multiple_choice";
|
|
1793
|
+
const group = doc.createElement("div");
|
|
1794
|
+
group.setAttribute("role", multi ? "group" : "radiogroup");
|
|
1795
|
+
group.setAttribute("aria-label", q.title);
|
|
1796
|
+
q.options.forEach((opt) => {
|
|
1797
|
+
const b = doc.createElement("button");
|
|
1798
|
+
b.type = "button";
|
|
1799
|
+
b.className = `g-choice${multi ? " g-multi" : ""}`;
|
|
1800
|
+
b.setAttribute("role", multi ? "checkbox" : "radio");
|
|
1801
|
+
b.setAttribute("aria-checked", "false");
|
|
1802
|
+
b.setAttribute("data-option-id", opt.id);
|
|
1803
|
+
const dot = doc.createElement("span");
|
|
1804
|
+
dot.className = "g-dot";
|
|
1805
|
+
b.append(dot, Object.assign(doc.createElement("span"), { textContent: opt.label }));
|
|
1806
|
+
b.addEventListener("click", () => {
|
|
1807
|
+
if (multi) {
|
|
1808
|
+
const cur = new Set(answers[q.id] ?? []);
|
|
1809
|
+
if (cur.has(opt.id)) cur.delete(opt.id);
|
|
1810
|
+
else cur.add(opt.id);
|
|
1811
|
+
b.setAttribute("aria-checked", String(cur.has(opt.id)));
|
|
1812
|
+
setAnswer(q.id, Array.from(cur));
|
|
1813
|
+
} else {
|
|
1814
|
+
group.querySelectorAll(".g-choice").forEach((x) => x.setAttribute("aria-checked", "false"));
|
|
1815
|
+
b.setAttribute("aria-checked", "true");
|
|
1816
|
+
setAnswer(q.id, opt.id);
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
group.appendChild(b);
|
|
1820
|
+
});
|
|
1821
|
+
return group;
|
|
1822
|
+
}
|
|
1823
|
+
case "text":
|
|
1824
|
+
default: {
|
|
1825
|
+
const ta = doc.createElement("textarea");
|
|
1826
|
+
ta.className = "g-input";
|
|
1827
|
+
ta.rows = 3;
|
|
1828
|
+
ta.placeholder = q.placeholder || "";
|
|
1829
|
+
ta.setAttribute("aria-label", q.title);
|
|
1830
|
+
ta.addEventListener("input", () => setAnswer(q.id, ta.value.slice(0, 5e3)));
|
|
1831
|
+
return ta;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
config.questions.forEach((q) => {
|
|
1836
|
+
const wrap = doc.createElement("div");
|
|
1837
|
+
wrap.className = "g-question";
|
|
1838
|
+
wrap.setAttribute("data-question-id", q.id);
|
|
1839
|
+
const t = doc.createElement("p");
|
|
1840
|
+
t.className = "g-q-title";
|
|
1841
|
+
t.textContent = q.title + (q.required ? "" : " (optional)");
|
|
1842
|
+
wrap.appendChild(t);
|
|
1843
|
+
if (q.description) {
|
|
1844
|
+
const d = doc.createElement("p");
|
|
1845
|
+
d.className = "g-q-desc";
|
|
1846
|
+
d.textContent = q.description;
|
|
1847
|
+
wrap.appendChild(d);
|
|
1848
|
+
}
|
|
1849
|
+
wrap.appendChild(buildInput(q));
|
|
1850
|
+
questionEls.set(q.id, wrap);
|
|
1851
|
+
form.appendChild(wrap);
|
|
1852
|
+
});
|
|
1853
|
+
const footer = doc.createElement("div");
|
|
1854
|
+
footer.className = "g-footer";
|
|
1855
|
+
const submit = doc.createElement("button");
|
|
1856
|
+
submit.type = "submit";
|
|
1857
|
+
submit.className = "g-btn g-btn-primary";
|
|
1858
|
+
submit.textContent = "Submit";
|
|
1859
|
+
footer.appendChild(submit);
|
|
1860
|
+
form.appendChild(errorEl);
|
|
1861
|
+
form.appendChild(footer);
|
|
1862
|
+
function updateVisibility() {
|
|
1863
|
+
config.questions.forEach((q) => {
|
|
1864
|
+
const el2 = questionEls.get(q.id);
|
|
1865
|
+
if (!el2) return;
|
|
1866
|
+
const visible = isQuestionVisible(q, answers);
|
|
1867
|
+
el2.hidden = !visible;
|
|
1868
|
+
if (!visible && answers[q.id] !== void 0) delete answers[q.id];
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
form.addEventListener("submit", (e) => {
|
|
1872
|
+
e.preventDefault();
|
|
1873
|
+
const missing = config.questions.filter((q) => q.required && isQuestionVisible(q, answers) && answers[q.id] === void 0);
|
|
1874
|
+
if (missing.length) {
|
|
1875
|
+
errorEl.textContent = `Please answer: ${missing.map((q) => q.title).join(", ")}`;
|
|
1876
|
+
questionEls.get(missing[0].id)?.querySelector("button,textarea")?.focus();
|
|
1877
|
+
return;
|
|
1878
|
+
}
|
|
1879
|
+
errorEl.textContent = "";
|
|
1880
|
+
options.onSubmit({ ...answers });
|
|
1881
|
+
});
|
|
1882
|
+
const onKey = (e) => {
|
|
1883
|
+
if (e.key === "Escape" && options.onDismiss) {
|
|
1884
|
+
e.stopPropagation();
|
|
1885
|
+
options.onDismiss();
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
card.addEventListener("keydown", onKey);
|
|
1889
|
+
updateVisibility();
|
|
1890
|
+
(form.querySelector("button,textarea") || card).focus?.({ preventScroll: true });
|
|
1891
|
+
return {
|
|
1892
|
+
el: card,
|
|
1893
|
+
getAnswers: () => ({ ...answers }),
|
|
1894
|
+
showThankYou() {
|
|
1895
|
+
inner.textContent = "";
|
|
1896
|
+
const wrap = doc.createElement("div");
|
|
1897
|
+
wrap.className = "g-complete";
|
|
1898
|
+
const t = doc.createElement("h3");
|
|
1899
|
+
t.className = "g-title";
|
|
1900
|
+
t.textContent = config.thankYouTitle;
|
|
1901
|
+
const b = doc.createElement("div");
|
|
1902
|
+
b.className = "g-body";
|
|
1903
|
+
setSanitizedHtml(b, config.thankYouBody);
|
|
1904
|
+
const done = doc.createElement("button");
|
|
1905
|
+
done.type = "button";
|
|
1906
|
+
done.className = "g-btn g-btn-primary";
|
|
1907
|
+
done.textContent = "Done";
|
|
1908
|
+
done.style.marginTop = "12px";
|
|
1909
|
+
done.addEventListener("click", () => options.onDismiss?.());
|
|
1910
|
+
wrap.append(t, b, done);
|
|
1911
|
+
inner.appendChild(wrap);
|
|
1912
|
+
done.focus?.({ preventScroll: true });
|
|
1913
|
+
},
|
|
1914
|
+
destroy() {
|
|
1915
|
+
card.removeEventListener("keydown", onKey);
|
|
1916
|
+
card.remove();
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
// src/resource-center.ts
|
|
1922
|
+
function el(doc, tag, cls, text) {
|
|
1923
|
+
const e = doc.createElement(tag);
|
|
1924
|
+
if (cls) e.className = cls;
|
|
1925
|
+
if (text != null) e.textContent = text;
|
|
1926
|
+
return e;
|
|
1927
|
+
}
|
|
1928
|
+
function item(doc, icon, title, summary) {
|
|
1929
|
+
const b = el(doc, "button", "g-rc-item");
|
|
1930
|
+
b.type = "button";
|
|
1931
|
+
const i = el(doc, "span", "g-rc-icon", icon);
|
|
1932
|
+
i.setAttribute("aria-hidden", "true");
|
|
1933
|
+
const text = el(doc, "span");
|
|
1934
|
+
text.appendChild(el(doc, "div", "g-rc-title", title));
|
|
1935
|
+
if (summary) text.appendChild(el(doc, "div", "g-rc-sum", summary));
|
|
1936
|
+
b.append(i, text);
|
|
1937
|
+
return b;
|
|
1938
|
+
}
|
|
1939
|
+
function renderResourceCenter(options) {
|
|
1940
|
+
const { scope, config } = options;
|
|
1941
|
+
const doc = scope.ownerDocument;
|
|
1942
|
+
const guides = options.guides ?? [];
|
|
1943
|
+
let open = false;
|
|
1944
|
+
let query = "";
|
|
1945
|
+
let serverResults = [];
|
|
1946
|
+
let searchSeq = 0;
|
|
1947
|
+
let activeArticle = null;
|
|
1948
|
+
const pos = `g-pos-${config.launcher.position}`;
|
|
1949
|
+
const root = el(doc, "div", "g-resource-center");
|
|
1950
|
+
const launcher = el(doc, "button", `g-launcher ${pos}`);
|
|
1951
|
+
launcher.type = "button";
|
|
1952
|
+
launcher.setAttribute("aria-expanded", "false");
|
|
1953
|
+
if (config.launcher.showIcon) {
|
|
1954
|
+
const icon = el(doc, "span", "", "?");
|
|
1955
|
+
icon.setAttribute("aria-hidden", "true");
|
|
1956
|
+
launcher.appendChild(icon);
|
|
1957
|
+
}
|
|
1958
|
+
launcher.appendChild(el(doc, "span", "", config.launcher.label || config.title));
|
|
1959
|
+
launcher.setAttribute("aria-label", config.launcher.label || config.title);
|
|
1960
|
+
if (options.hideLauncher) launcher.hidden = true;
|
|
1961
|
+
const panel = el(doc, "div", `g-panel ${pos}`);
|
|
1962
|
+
panel.setAttribute("role", "dialog");
|
|
1963
|
+
panel.setAttribute("aria-label", config.title);
|
|
1964
|
+
panel.hidden = true;
|
|
1965
|
+
const head = el(doc, "div", "g-panel-head");
|
|
1966
|
+
head.appendChild(el(doc, "h2", "g-panel-title", config.title));
|
|
1967
|
+
const close = el(doc, "button", "g-close", "\xD7");
|
|
1968
|
+
close.type = "button";
|
|
1969
|
+
close.setAttribute("aria-label", "Close");
|
|
1970
|
+
head.appendChild(close);
|
|
1971
|
+
const searchWrap = el(doc, "div", "g-rc-search");
|
|
1972
|
+
const input = el(doc, "input", "g-input");
|
|
1973
|
+
input.type = "search";
|
|
1974
|
+
input.placeholder = "Search help articles\u2026";
|
|
1975
|
+
input.setAttribute("aria-label", "Search help articles");
|
|
1976
|
+
searchWrap.appendChild(input);
|
|
1977
|
+
const body = el(doc, "div", "g-panel-body");
|
|
1978
|
+
panel.append(head, searchWrap, body);
|
|
1979
|
+
root.append(launcher, panel);
|
|
1980
|
+
scope.appendChild(root);
|
|
1981
|
+
const openArticle = (article) => {
|
|
1982
|
+
if (article.externalUrl) {
|
|
1983
|
+
window.open(article.externalUrl, "_blank", "noopener,noreferrer");
|
|
1984
|
+
options.onArticleView?.(article);
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1987
|
+
activeArticle = article;
|
|
1988
|
+
options.onArticleView?.(article);
|
|
1989
|
+
renderBody();
|
|
1990
|
+
};
|
|
1991
|
+
const renderArticle = (article) => {
|
|
1992
|
+
const wrap = el(doc, "div", "g-rc-article");
|
|
1993
|
+
const back = el(doc, "button", "g-btn g-btn-link g-rc-back", "\u2190 Back");
|
|
1994
|
+
back.type = "button";
|
|
1995
|
+
back.addEventListener("click", () => {
|
|
1996
|
+
activeArticle = null;
|
|
1997
|
+
renderBody();
|
|
1998
|
+
});
|
|
1999
|
+
const title = el(doc, "h3", "g-title", article.title);
|
|
2000
|
+
const content = el(doc, "div", "g-body");
|
|
2001
|
+
setSanitizedHtml(content, article.body);
|
|
2002
|
+
wrap.append(back, title, content);
|
|
2003
|
+
body.appendChild(wrap);
|
|
2004
|
+
back.focus?.({ preventScroll: true });
|
|
2005
|
+
};
|
|
2006
|
+
const section = (label) => body.appendChild(el(doc, "div", "g-rc-section", label));
|
|
2007
|
+
const renderBody = () => {
|
|
2008
|
+
body.textContent = "";
|
|
2009
|
+
if (activeArticle) return renderArticle(activeArticle);
|
|
2010
|
+
const q = query.trim().toLowerCase();
|
|
2011
|
+
if (q) {
|
|
2012
|
+
const local = config.articles.filter((a) => a.title.toLowerCase().includes(q) || a.summary.toLowerCase().includes(q));
|
|
2013
|
+
const seen = new Set(local.map((a) => a.id));
|
|
2014
|
+
const merged = [...local, ...serverResults.filter((a) => !seen.has(a.id))];
|
|
2015
|
+
section(`Results (${merged.length})`);
|
|
2016
|
+
if (!merged.length) body.appendChild(el(doc, "div", "g-rc-empty", "No articles match your search."));
|
|
2017
|
+
merged.forEach((a) => {
|
|
2018
|
+
const b = item(doc, "\u{1F4C4}", a.title, a.summary);
|
|
2019
|
+
b.addEventListener("click", () => openArticle(a));
|
|
2020
|
+
body.appendChild(b);
|
|
2021
|
+
});
|
|
2022
|
+
return;
|
|
2023
|
+
}
|
|
2024
|
+
const recommended = config.recommendedGuideIds.map((id) => guides.find((g) => g.id === id || g.key === id)).filter((g) => !!g);
|
|
2025
|
+
if (recommended.length) {
|
|
2026
|
+
section("Recommended");
|
|
2027
|
+
recommended.forEach((g) => {
|
|
2028
|
+
const b = item(doc, "\u25B6", g.name, "Start guide");
|
|
2029
|
+
b.addEventListener("click", () => options.onStartGuide?.(g.id));
|
|
2030
|
+
body.appendChild(b);
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
const checklists = config.checklistGuideIds.map((id) => guides.find((g) => g.id === id || g.key === id)).filter((g) => !!g);
|
|
2034
|
+
if (checklists.length) {
|
|
2035
|
+
section("Checklists");
|
|
2036
|
+
checklists.forEach((g) => {
|
|
2037
|
+
const b = item(doc, "\u2611", g.name, "Open checklist");
|
|
2038
|
+
b.addEventListener("click", () => options.onOpenChecklist?.(g.id));
|
|
2039
|
+
body.appendChild(b);
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
const collections = [...config.collections].sort((a, b) => a.order - b.order);
|
|
2043
|
+
const uncollected = config.articles.filter((a) => !a.collectionId || !collections.some((c) => c.id === a.collectionId));
|
|
2044
|
+
collections.forEach((c) => {
|
|
2045
|
+
const articles = config.articles.filter((a) => a.collectionId === c.id);
|
|
2046
|
+
if (!articles.length) return;
|
|
2047
|
+
section(c.name);
|
|
2048
|
+
articles.forEach((a) => {
|
|
2049
|
+
const b = item(doc, "\u{1F4C4}", a.title, a.summary);
|
|
2050
|
+
b.addEventListener("click", () => openArticle(a));
|
|
2051
|
+
body.appendChild(b);
|
|
2052
|
+
});
|
|
2053
|
+
});
|
|
2054
|
+
if (uncollected.length) {
|
|
2055
|
+
section("Articles");
|
|
2056
|
+
uncollected.forEach((a) => {
|
|
2057
|
+
const b = item(doc, "\u{1F4C4}", a.title, a.summary);
|
|
2058
|
+
b.addEventListener("click", () => openArticle(a));
|
|
2059
|
+
body.appendChild(b);
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
if (config.faqs.length) {
|
|
2063
|
+
section("FAQ");
|
|
2064
|
+
config.faqs.forEach((f) => {
|
|
2065
|
+
const b = item(doc, "?", f.question);
|
|
2066
|
+
b.setAttribute("aria-expanded", "false");
|
|
2067
|
+
const a = el(doc, "div", "g-faq-a");
|
|
2068
|
+
setSanitizedHtml(a, f.answer);
|
|
2069
|
+
a.hidden = true;
|
|
2070
|
+
b.addEventListener("click", () => {
|
|
2071
|
+
a.hidden = !a.hidden;
|
|
2072
|
+
b.setAttribute("aria-expanded", String(!a.hidden));
|
|
2073
|
+
});
|
|
2074
|
+
body.append(b, a);
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
if (config.links.length) {
|
|
2078
|
+
section("Links");
|
|
2079
|
+
config.links.forEach((l) => {
|
|
2080
|
+
const a = el(doc, "a", "g-rc-item");
|
|
2081
|
+
a.href = l.url;
|
|
2082
|
+
a.target = "_blank";
|
|
2083
|
+
a.rel = "noopener noreferrer";
|
|
2084
|
+
const i = el(doc, "span", "g-rc-icon", "\u2197");
|
|
2085
|
+
i.setAttribute("aria-hidden", "true");
|
|
2086
|
+
a.append(i, el(doc, "span", "g-rc-title", l.label));
|
|
2087
|
+
body.appendChild(a);
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
if (!body.childNodes.length) body.appendChild(el(doc, "div", "g-rc-empty", "Nothing here yet."));
|
|
2091
|
+
};
|
|
2092
|
+
let debounce = null;
|
|
2093
|
+
input.addEventListener("input", () => {
|
|
2094
|
+
query = input.value;
|
|
2095
|
+
activeArticle = null;
|
|
2096
|
+
renderBody();
|
|
2097
|
+
if (debounce) clearTimeout(debounce);
|
|
2098
|
+
if (!options.search || !query.trim()) {
|
|
2099
|
+
serverResults = [];
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
const seq = ++searchSeq;
|
|
2103
|
+
debounce = setTimeout(() => {
|
|
2104
|
+
options.search?.(query.trim()).then((results) => {
|
|
2105
|
+
if (seq !== searchSeq) return;
|
|
2106
|
+
serverResults = Array.isArray(results) ? results : [];
|
|
2107
|
+
renderBody();
|
|
2108
|
+
}).catch(() => {
|
|
2109
|
+
});
|
|
2110
|
+
}, 250);
|
|
2111
|
+
});
|
|
2112
|
+
const setOpen = (v) => {
|
|
2113
|
+
if (open === v) return;
|
|
2114
|
+
open = v;
|
|
2115
|
+
panel.hidden = !v;
|
|
2116
|
+
launcher.setAttribute("aria-expanded", String(v));
|
|
2117
|
+
if (v) {
|
|
2118
|
+
renderBody();
|
|
2119
|
+
input.focus?.({ preventScroll: true });
|
|
2120
|
+
options.onOpen?.();
|
|
2121
|
+
} else {
|
|
2122
|
+
activeArticle = null;
|
|
2123
|
+
options.onClose?.();
|
|
2124
|
+
}
|
|
2125
|
+
};
|
|
2126
|
+
launcher.addEventListener("click", () => setOpen(!open));
|
|
2127
|
+
close.addEventListener("click", () => setOpen(false));
|
|
2128
|
+
const onKey = (e) => {
|
|
2129
|
+
if (e.key === "Escape") {
|
|
2130
|
+
e.stopPropagation();
|
|
2131
|
+
setOpen(false);
|
|
2132
|
+
launcher.focus();
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
panel.addEventListener("keydown", onKey);
|
|
2136
|
+
return {
|
|
2137
|
+
el: root,
|
|
2138
|
+
open: () => setOpen(true),
|
|
2139
|
+
close: () => setOpen(false),
|
|
2140
|
+
toggle: () => setOpen(!open),
|
|
2141
|
+
isOpen: () => open,
|
|
2142
|
+
destroy() {
|
|
2143
|
+
if (debounce) clearTimeout(debounce);
|
|
2144
|
+
panel.removeEventListener("keydown", onKey);
|
|
2145
|
+
root.remove();
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
// src/authoring.ts
|
|
2151
|
+
var DEFAULT_MESSAGE = "Guidely authoring \u2014 hover an element and click to select \xB7 Esc to cancel";
|
|
2152
|
+
function startAuthoring(options) {
|
|
2153
|
+
const doc = options.doc ?? document;
|
|
2154
|
+
const win = doc.defaultView ?? window;
|
|
2155
|
+
const scope = createScope(null, { theme: "light", animation: "none" }, doc);
|
|
2156
|
+
const bar = doc.createElement("div");
|
|
2157
|
+
bar.className = "g-auth-bar";
|
|
2158
|
+
bar.setAttribute("role", "toolbar");
|
|
2159
|
+
const dot = doc.createElement("span");
|
|
2160
|
+
dot.className = "g-dot-live";
|
|
2161
|
+
const status = doc.createElement("span");
|
|
2162
|
+
status.textContent = options.message ?? DEFAULT_MESSAGE;
|
|
2163
|
+
const spacer = doc.createElement("span");
|
|
2164
|
+
spacer.className = "g-spacer";
|
|
2165
|
+
const done = doc.createElement("button");
|
|
2166
|
+
done.type = "button";
|
|
2167
|
+
done.className = "g-btn g-btn-primary";
|
|
2168
|
+
done.textContent = "Done";
|
|
2169
|
+
const exit = doc.createElement("button");
|
|
2170
|
+
exit.type = "button";
|
|
2171
|
+
exit.className = "g-btn g-btn-secondary";
|
|
2172
|
+
exit.textContent = "Exit authoring";
|
|
2173
|
+
bar.append(dot, status, spacer, done, exit);
|
|
2174
|
+
const outline = doc.createElement("div");
|
|
2175
|
+
outline.className = "g-auth-outline";
|
|
2176
|
+
outline.hidden = true;
|
|
2177
|
+
const label = doc.createElement("span");
|
|
2178
|
+
label.className = "g-auth-label";
|
|
2179
|
+
outline.appendChild(label);
|
|
2180
|
+
scope.el.append(bar, outline);
|
|
2181
|
+
let picking = true;
|
|
2182
|
+
let hovered = null;
|
|
2183
|
+
let stopped = false;
|
|
2184
|
+
const describe = (el2) => {
|
|
2185
|
+
const tag = el2.tagName.toLowerCase();
|
|
2186
|
+
const id = el2.id ? `#${el2.id}` : "";
|
|
2187
|
+
const tour = el2.getAttribute("data-tour") || el2.getAttribute("data-testid");
|
|
2188
|
+
const text = (el2.textContent || "").replace(/\s+/g, " ").trim().slice(0, 40);
|
|
2189
|
+
return `${tag}${id}${tour ? `[${tour}]` : ""}${text ? ` \u201C${text}\u201D` : ""}`;
|
|
2190
|
+
};
|
|
2191
|
+
const paint = (el2, picked = false) => {
|
|
2192
|
+
if (!el2) {
|
|
2193
|
+
outline.hidden = true;
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
const r = el2.getBoundingClientRect();
|
|
2197
|
+
outline.hidden = false;
|
|
2198
|
+
outline.classList.toggle("g-picked", picked);
|
|
2199
|
+
Object.assign(outline.style, { left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px` });
|
|
2200
|
+
label.textContent = describe(el2);
|
|
2201
|
+
label.style.top = r.top < 30 ? "100%" : "-24px";
|
|
2202
|
+
};
|
|
2203
|
+
const elementAt = (x, y) => {
|
|
2204
|
+
const el2 = doc.elementFromPoint(x, y);
|
|
2205
|
+
if (!el2 || isGuidelyElement(el2) || el2 === doc.documentElement || el2 === doc.body) return null;
|
|
2206
|
+
return el2;
|
|
2207
|
+
};
|
|
2208
|
+
const onMove = (e) => {
|
|
2209
|
+
if (!picking || stopped) return;
|
|
2210
|
+
const el2 = elementAt(e.clientX, e.clientY);
|
|
2211
|
+
if (el2 !== hovered) {
|
|
2212
|
+
hovered = el2;
|
|
2213
|
+
paint(el2);
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2216
|
+
const onScroll = () => {
|
|
2217
|
+
if (hovered) paint(hovered);
|
|
2218
|
+
};
|
|
2219
|
+
const onClick = (e) => {
|
|
2220
|
+
if (!picking || stopped) return;
|
|
2221
|
+
if (e.target && isGuidelyElement(e.target)) return;
|
|
2222
|
+
const el2 = elementAt(e.clientX, e.clientY) ?? hovered;
|
|
2223
|
+
if (!el2) return;
|
|
2224
|
+
e.preventDefault();
|
|
2225
|
+
e.stopPropagation();
|
|
2226
|
+
e.stopImmediatePropagation();
|
|
2227
|
+
const d = describeElement(el2);
|
|
2228
|
+
paint(el2, true);
|
|
2229
|
+
status.textContent = `Selected ${describe(el2)} \u2014 click another element or press Done`;
|
|
2230
|
+
options.onPick({ selectors: d.selectors, textSnapshot: d.textSnapshot, rect: d.rect, url: win.location.href, element: el2 });
|
|
2231
|
+
};
|
|
2232
|
+
const swallow = (e) => {
|
|
2233
|
+
if (!picking || stopped) return;
|
|
2234
|
+
const t = e.target;
|
|
2235
|
+
if (t && isGuidelyElement(t)) return;
|
|
2236
|
+
e.preventDefault();
|
|
2237
|
+
e.stopPropagation();
|
|
2238
|
+
};
|
|
2239
|
+
const onKey = (e) => {
|
|
2240
|
+
if (e.key === "Escape") {
|
|
2241
|
+
e.preventDefault();
|
|
2242
|
+
e.stopPropagation();
|
|
2243
|
+
stop();
|
|
2244
|
+
options.onExit();
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
const stop = () => {
|
|
2248
|
+
if (stopped) return;
|
|
2249
|
+
stopped = true;
|
|
2250
|
+
doc.removeEventListener("mousemove", onMove, true);
|
|
2251
|
+
doc.removeEventListener("click", onClick, true);
|
|
2252
|
+
doc.removeEventListener("mousedown", swallow, true);
|
|
2253
|
+
doc.removeEventListener("mouseup", swallow, true);
|
|
2254
|
+
doc.removeEventListener("keydown", onKey, true);
|
|
2255
|
+
win.removeEventListener("scroll", onScroll, true);
|
|
2256
|
+
win.removeEventListener("resize", onScroll);
|
|
2257
|
+
scope.destroy();
|
|
2258
|
+
};
|
|
2259
|
+
done.addEventListener("click", () => {
|
|
2260
|
+
stop();
|
|
2261
|
+
options.onExit();
|
|
2262
|
+
});
|
|
2263
|
+
exit.addEventListener("click", () => {
|
|
2264
|
+
stop();
|
|
2265
|
+
options.onExit();
|
|
2266
|
+
});
|
|
2267
|
+
doc.addEventListener("mousemove", onMove, true);
|
|
2268
|
+
doc.addEventListener("click", onClick, true);
|
|
2269
|
+
doc.addEventListener("mousedown", swallow, true);
|
|
2270
|
+
doc.addEventListener("mouseup", swallow, true);
|
|
2271
|
+
doc.addEventListener("keydown", onKey, true);
|
|
2272
|
+
win.addEventListener("scroll", onScroll, true);
|
|
2273
|
+
win.addEventListener("resize", onScroll);
|
|
2274
|
+
return {
|
|
2275
|
+
setStatus: (text) => {
|
|
2276
|
+
status.textContent = text;
|
|
2277
|
+
},
|
|
2278
|
+
setPicking: (enabled) => {
|
|
2279
|
+
picking = enabled;
|
|
2280
|
+
if (!enabled) paint(null);
|
|
2281
|
+
},
|
|
2282
|
+
stop
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
function previewStep(step, theme, options = {}) {
|
|
2286
|
+
const previewStepConfig = { ...step, target: step.target ? { ...step.target, fallback: "show_as_modal", waitMs: Math.min(step.target.waitMs, 1500) } : step.target };
|
|
2287
|
+
const guide = {
|
|
2288
|
+
id: `preview-${step.id}`,
|
|
2289
|
+
key: "preview",
|
|
2290
|
+
name: "Preview",
|
|
2291
|
+
kind: "flow",
|
|
2292
|
+
version: 0,
|
|
2293
|
+
config: { steps: [previewStepConfig], targeting: { id: "root", op: "and", rules: [] }, trigger: { type: "manual", delayMs: 0 }, frequency: { mode: "every_time", cooldownHours: 0, priority: 0, mutuallyExclusiveWith: [], reshowAfterDismiss: true }, appearance: options.appearance ?? { theme: "auto", animation: "fade" }, urlPatterns: [] }
|
|
2294
|
+
};
|
|
2295
|
+
const controller = runGuide(guide, { theme, doc: options.doc, onEnd: () => options.onEnd?.(), onNavigate: () => {
|
|
2296
|
+
}, onAction: () => {
|
|
2297
|
+
} });
|
|
2298
|
+
controller.start();
|
|
2299
|
+
return { controller, destroy: () => controller.destroy() };
|
|
2300
|
+
}
|
|
2301
|
+
function highlightSelectors(selectors, options = {}) {
|
|
2302
|
+
const doc = options.doc ?? document;
|
|
2303
|
+
const scope = createScope(null, { theme: "light", animation: "none" }, doc);
|
|
2304
|
+
const boxes = [];
|
|
2305
|
+
const counts = [];
|
|
2306
|
+
let resolved = null;
|
|
2307
|
+
const matched = /* @__PURE__ */ new Set();
|
|
2308
|
+
selectors.forEach((s) => {
|
|
2309
|
+
const els = querySelectorStrategy(s, doc).filter((el2) => !isGuidelyElement(el2));
|
|
2310
|
+
const visible = els.filter(isVisible);
|
|
2311
|
+
counts.push(els.length);
|
|
2312
|
+
if (!resolved && visible.length === 1) resolved = visible[0];
|
|
2313
|
+
els.forEach((el2) => matched.add(el2));
|
|
2314
|
+
});
|
|
2315
|
+
matched.forEach((el2) => {
|
|
2316
|
+
const r = el2.getBoundingClientRect();
|
|
2317
|
+
const box = doc.createElement("div");
|
|
2318
|
+
box.className = "g-highlight";
|
|
2319
|
+
Object.assign(box.style, { left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px` });
|
|
2320
|
+
if (el2 === resolved) box.style.borderColor = "#22c55e";
|
|
2321
|
+
scope.el.appendChild(box);
|
|
2322
|
+
boxes.push(box);
|
|
2323
|
+
});
|
|
2324
|
+
let timer = null;
|
|
2325
|
+
const destroy = () => {
|
|
2326
|
+
if (timer) clearTimeout(timer);
|
|
2327
|
+
scope.destroy();
|
|
2328
|
+
};
|
|
2329
|
+
if (options.durationMs !== 0) timer = setTimeout(destroy, options.durationMs ?? 2500);
|
|
2330
|
+
ensureHost(doc);
|
|
2331
|
+
return { counts, resolved, destroy };
|
|
2332
|
+
}
|
|
2333
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2334
|
+
0 && (module.exports = {
|
|
2335
|
+
DEFAULT_THEME,
|
|
2336
|
+
HOST_ID,
|
|
2337
|
+
STYLES,
|
|
2338
|
+
TargetTimeoutError,
|
|
2339
|
+
anchor,
|
|
2340
|
+
applyTheme,
|
|
2341
|
+
buildCard,
|
|
2342
|
+
createScope,
|
|
2343
|
+
describeElement,
|
|
2344
|
+
destroyHost,
|
|
2345
|
+
ensureHost,
|
|
2346
|
+
generateSelectors,
|
|
2347
|
+
highlightSelectors,
|
|
2348
|
+
isAnchoredStep,
|
|
2349
|
+
isChecklistComplete,
|
|
2350
|
+
isGuidelyElement,
|
|
2351
|
+
isQuestionVisible,
|
|
2352
|
+
isStableId,
|
|
2353
|
+
isVisible,
|
|
2354
|
+
normalizeText,
|
|
2355
|
+
prefersReducedMotion,
|
|
2356
|
+
previewStep,
|
|
2357
|
+
querySelectorStrategy,
|
|
2358
|
+
renderBanner,
|
|
2359
|
+
renderChecklist,
|
|
2360
|
+
renderCustom,
|
|
2361
|
+
renderHotspot,
|
|
2362
|
+
renderModal,
|
|
2363
|
+
renderResourceCenter,
|
|
2364
|
+
renderSlideout,
|
|
2365
|
+
renderSpotlight,
|
|
2366
|
+
renderStep,
|
|
2367
|
+
renderSurvey,
|
|
2368
|
+
renderTooltip,
|
|
2369
|
+
resolveTarget,
|
|
2370
|
+
resolveTheme,
|
|
2371
|
+
runGuide,
|
|
2372
|
+
sanitizeHtml,
|
|
2373
|
+
sanitizeToFragment,
|
|
2374
|
+
setSanitizedHtml,
|
|
2375
|
+
startAuthoring,
|
|
2376
|
+
textSnapshotOf,
|
|
2377
|
+
trackRect,
|
|
2378
|
+
urlMatches,
|
|
2379
|
+
waitForTarget
|
|
2380
|
+
});
|
|
2381
|
+
//# sourceMappingURL=index.cjs.map
|