UNPKG

app-walkthrough

Version:

An intuitive guided walkthrough library with UI highlighting and voice narration for web apps.

45 lines (44 loc) 1.26 kB
/** * Extracts a structured payload from a DOM event for serialization/replay. * Mouse coordinates are intentionally omitted. */ export function getDomEventDetails(e, selectors, target) { var _a; if (!selectors) return null; const selectorData = selectors.map((selector) => ({ selector })); const base = { actionType: e.type, selectors: selectorData, domType: target.tagName.toLowerCase(), beforeMessage: target.name || ((_a = target.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || "", }; switch (e.type) { case "click": case "mousedown": case "mouseup": return base; case "scroll": return { ...base, scrollX: window.scrollX, scrollY: window.scrollY, }; case "input": case "change": return { ...base, value: target.value, }; case "keydown": case "keyup": const keyEvent = e; return { ...base, key: keyEvent.key, code: keyEvent.code, }; default: return null; } }