UNPKG

@jumio/websdk

Version:

Jumio WebSDK is a powerful, flexible software development kit that simplifies the integration of Jumio's services into your web applications.

1,219 lines (1,218 loc) 31.4 kB
import { B as y, k as ge, C as A, E as $, F as me, N as g, G as Ee, H as z, I as Te, J as Ie, K as W, M as ye, P as Ne, O as ve, Q as K, T as be, U as J, W as j, X as Ce, Y as Z, Z as v, _ as q, L as R, $ as we, a0 as O, a1 as C, t as S, r as Me, a2 as Re, a3 as N, a4 as x, a5 as M, a6 as _e, a7 as xe, a8 as Ae, a9 as De, aa as Oe, ab as Le, ac as Pe, ad as ke, ae as Ve, m as ze, s as Ue, af as He, ag as Fe, ah as Be, g as Ge, p as Ye, c as Xe, a as $e, b as We } from "../index.W6WfC45m.js"; function Ke() { return Je() === 1; } let U; function Je() { return U ?? (U = je()); } function je(e = window) { const t = e.navigator.userAgent; return e.chrome || /HeadlessChrome/.test(t) ? 0 : e.navigator.vendor?.indexOf("Apple") === 0 || /safari/i.test(t) && !/chrome|android/i.test(t) ? 1 : 2; } const T = { FullSnapshot: 2, IncrementalSnapshot: 3, Meta: 4, Focus: 6, ViewEnd: 7, VisualViewport: 8, Change: 12 }, h = { AddString: 0, AddNode: 1, RemoveNode: 2, Attribute: 3, Text: 4, Size: 5, ScrollPosition: 6, AddStyleSheet: 7, AttachedStyleSheets: 8, MediaPlaybackState: 9, VisualViewport: 10 }, E = { MouseMove: 1, MouseInteraction: 2, Scroll: 3, ViewportResize: 4, Input: 5, TouchMove: 6, MediaInteraction: 7, StyleSheetRule: 8 }, m = { MouseUp: 0, MouseDown: 1, Click: 2, ContextMenu: 3, DblClick: 4, Focus: 5, Blur: 6, TouchStart: 7, TouchEnd: 9 }, D = { Play: 0, Pause: 1 }, Ze = { Change: 1 }; function qe(e) { return Q(void 0, void 0, e); } function Qe(e, t, n) { return Q(e, t, n); } function Q(e, t, n) { let o = { container: void 0, parentId: e, previousSiblingId: void 0, nextSiblingId: t }; const i = (s) => o.previousSiblingId === s - 1 ? 0 : o.nextSiblingId !== void 0 ? o.nextSiblingId - s : o.parentId !== void 0 ? s - o.parentId : null; return { advance(s) { const r = n.getOrInsert(s), a = i(r); return o.previousSiblingId = r, { nodeId: r, insertionPoint: a }; }, ascend() { o.container && (o = o.container); }, descend() { o.previousSiblingId !== void 0 && (o = { container: o, parentId: o.previousSiblingId, previousSiblingId: void 0, nextSiblingId: void 0 }); } }; } function ee() { return { cssText: { count: 0, max: 0, sum: 0 }, serializationDuration: { count: 0, max: 0, sum: 0 } }; } function H(e, t, n) { e[t].count += 1, e[t].max = Math.max(e[t].max, n), e[t].sum += n; } function et(e, t) { for (const n of ["cssText", "serializationDuration"]) e[n].count += t[n].count, e[n].max = Math.max(e[n].max, t[n].max), e[n].sum += t[n].sum; } function tt(e) { let t = {}; const n = (s) => { for (let r = 0, a = s.length; r < a; r++) { const c = s[r]; if (typeof c == "string") { const u = e.size; u < 1e6 ? (s[r] = e.getOrInsert(c), e.size > u && o(h.AddString, c)) : s[r] = e.get(c) ?? c; } else Array.isArray(c) && n(c); } }, o = (s, r) => { s in t || (t[s] = [s]), s !== h.AddString && Array.isArray(r) && n(r), t[s].push(r); }; return { add: o, flush: () => { const s = []; return [ h.AddString, h.AddNode, h.RemoveNode, h.Attribute, h.Text, h.Size, h.ScrollPosition, h.AddStyleSheet, h.AttachedStyleSheets, h.MediaPlaybackState, h.VisualViewport ].forEach((r) => { const a = t[r]; a && s.push(a); }), t = {}, s; } }; } function te(e, t, n, o, i, s) { const r = tt(o.stringIds), a = ee(), c = { addMetric(l, f) { H(a, l, f); }, addNode(...l) { r.add(h.AddNode, l); }, addStyleSheet(l, f, p) { p ? r.add(h.AddStyleSheet, [ l, f || [], p ]) : f ? r.add(h.AddStyleSheet, [l, f]) : r.add(h.AddStyleSheet, [l]); }, attachStyleSheets(l, f) { const p = [l]; for (const b of f) p.push(b); r.add(h.AttachedStyleSheets, p); }, removeNode(l) { r.add(h.RemoveNode, l); }, setAttributes(l) { r.add(h.Attribute, l); }, setMediaPlaybackState(l, f) { r.add(h.MediaPlaybackState, [l, f]); }, setScrollPosition(l, f, p) { r.add(h.ScrollPosition, [ l, f, p ]); }, setSize(l, f, p) { r.add(h.Size, [ l, f, p ]); }, setText(l, f) { r.add(h.Text, [l, f]); }, kind: e, scope: o }, u = y(); s(c), H(a, "serializationDuration", ge(u, y())); const d = r.flush(); d.length > 0 && t(e === 0 || e === 1 ? { data: d, format: Ze.Change, type: T.FullSnapshot, timestamp: i } : { data: d, type: T.Change, timestamp: i }), n(a); } function P(e, t) { const n = e.tagName, o = e.value; if (A(e, t)) { const i = e.type; return n === "INPUT" && (i === "button" || i === "submit" || i === "reset") ? o : !o || n === "OPTION" ? void 0 : $; } if (n === "OPTION" || n === "SELECT") return e.value; if (!(n !== "INPUT" && n !== "TEXTAREA")) return o; } const nt = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm, ot = /^[A-Za-z]+:|^\/\//, st = /^["']?data:.*,/i; function it(e, t) { return e.replace(nt, (n, o, i, s, r, a) => { const c = i || r || a; if (!t || !c || ot.test(c) || st.test(c)) return n; const u = o || s || ""; return `url(${u}${rt(c, t)}${u})`; }); } function rt(e, t) { try { return me(e, t).href; } catch { return e; } } function ne(e) { return e.tagName.toLowerCase(); } function F(e, t) { return `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='${e}' height='${t}' style='background-color:silver'%3E%3C/svg%3E`; } const at = 1e6; function oe(e, t, n, o) { if (t === g.HIDDEN) return null; const i = e.getAttribute(n), s = e.tagName; if (Ee(s, n, i, t, o)) { if (s === "IMG") { const r = e; if (r.naturalWidth > 0) return F(r.naturalWidth, r.naturalHeight); const { width: a, height: c } = e.getBoundingClientRect(); return a > 0 || c > 0 ? F(a, c) : z; } return s === "SOURCE" ? z : $; } return i && Te(i, at); } function ct(e, t, n) { if (t === g.HIDDEN) return {}; const o = {}, i = ne(e); for (let r = 0; r < e.attributes.length; r += 1) { const a = e.attributes.item(r).name, c = oe(e, t, a, n.scope.configuration); c !== null && (o[a] = c); } if (e.value && (i === "textarea" || i === "select" || i === "option" || i === "input")) { const r = P(e, t); r !== void 0 && (o.value = r); } if (i === "option") { const r = e; r.selected && !A(r, t) ? o.selected = "" : delete o.selected; } const s = e; return i === "input" && (s.type === "radio" || s.type === "checkbox") && (s.checked && !A(s, t) ? o.checked = "" : delete o.checked), o; } function ut(e, t, n) { if (t === g.HIDDEN) return {}; const o = {}, i = e.ownerDocument, s = ne(e); if (s === "link") { const c = Array.from(i.styleSheets).find((d) => d.href === e.href), u = L(c); u && c && (n.addMetric("cssText", u.length), o._cssText = u); } if (s === "style" && e.sheet) { const c = L(e.sheet); c && (n.addMetric("cssText", c.length), o._cssText = c); } (s === "audio" || s === "video") && (o.rr_mediaState = e.paused ? "paused" : "played"); let r, a; switch (n.kind) { case 0: r = Math.round(e.scrollTop), a = Math.round(e.scrollLeft), (r || a) && n.scope.elementsScrollPositions.set(e, { scrollTop: r, scrollLeft: a }); break; case 1: n.scope.elementsScrollPositions.has(e) && ({ scrollTop: r, scrollLeft: a } = n.scope.elementsScrollPositions.get(e)); break; } return a && (o.rr_scrollLeft = a), r && (o.rr_scrollTop = r), o; } function L(e) { if (!e) return null; let t; try { t = e.rules || e.cssRules; } catch { } return t ? it(Array.from(t, Ke() ? dt : se).join(""), e.href) : null; } function dt(e) { return ft(e) && e.selectorText.includes(":") ? e.cssText.replace(/(\[[\w-]+[^\\])(:[^\]]+\])/g, "$1\\$2") : se(e); } function se(e) { return lt(e) && L(e.styleSheet) || e.cssText; } function lt(e) { return "styleSheet" in e; } function ft(e) { return "selectorText" in e; } function k(e, t, n, o) { if (t.parentNode?.nodeName === "STYLE" || n === g.HIDDEN || n === g.IGNORE) return; let i; const s = Ie(t); if (s ? i = Ce(s, n) : i = n, i === g.HIDDEN) { Tt(e, t, o); return; } if (i !== g.IGNORE) { switch (t.nodeType) { case t.CDATA_SECTION_NODE: Et(e, t, o); break; case t.DOCUMENT_NODE: pt(e, t, o); break; case t.DOCUMENT_FRAGMENT_NODE: ht(e, t, o); break; case t.DOCUMENT_TYPE_NODE: St(e, t, o); break; case t.ELEMENT_NODE: gt(e, t, i, o); break; case t.TEXT_NODE: mt(e, t, i, o); break; default: return; } switch (t.nodeType) { case t.CDATA_SECTION_NODE: case t.DOCUMENT_TYPE_NODE: case t.TEXT_NODE: return; } e.descend(), W(t, (r) => { k(e, r, i, o); }), e.ascend(); } } function pt(e, t, n) { const { nodeId: o, insertionPoint: i } = e.advance(t); n.addNode(i, "#document"), n.setScrollPosition(o, J(), j()), ie(t.adoptedStyleSheets, o, n); } function ht(e, t, n) { const { nodeId: o, insertionPoint: i } = e.advance(t); if (!be(t)) { n.addNode(i, "#document-fragment"); return; } n.addNode(i, "#shadow-root"), n.scope.shadowRootsController.addShadowRoot(t, n.scope), ie(t.adoptedStyleSheets, o, n); } function St(e, t, n) { const { insertionPoint: o } = e.advance(t); n.addNode(o, "#doctype", t.name, t.publicId, t.systemId); } function gt(e, t, n, o) { const { nodeId: i, insertionPoint: s } = e.advance(t), r = Object.entries(ct(t, n, o)); o.addNode(s, re(t), ...r); const { _cssText: a, rr_mediaState: c, rr_scrollLeft: u, rr_scrollTop: d } = ut(t, n, o), l = t; if (a !== void 0 && l.sheet) { const f = o.scope.styleSheetIds.getOrInsert(l.sheet); o.addStyleSheet(a), o.attachStyleSheets(i, [f]); } c === "played" ? o.setMediaPlaybackState(i, D.Play) : c === "paused" && o.setMediaPlaybackState(i, D.Pause), (u !== void 0 || d !== void 0) && o.setScrollPosition(i, u || 0, d || 0); } function mt(e, t, n, o) { const { insertionPoint: i } = e.advance(t), s = K(t, n); o.addNode(i, "#text", s); } function Et(e, t, n) { const { insertionPoint: o } = e.advance(t); n.addNode(o, "#cdata-section"); } function Tt(e, t, n) { if (!ye(t)) return; const { nodeId: o, insertionPoint: i } = e.advance(t); n.addNode(i, re(t), [Ne, ve]); const { width: s, height: r } = t.getBoundingClientRect(); n.setSize(o, s, r); } function ie(e, t, n) { !e || e.length === 0 || n.attachStyleSheets(t, e.map((o) => It(o, n))); } function It(e, t) { const n = Array.from(e.cssRules || e.rules, (i) => i.cssText), o = e.media.length > 0 ? Array.from(e.media) : void 0; return t.addMetric("cssText", n.reduce((i, s) => i + s.length, 0)), t.addStyleSheet(n, o, e.disabled), t.scope.styleSheetIds.getOrInsert(e); } function re(e) { const t = e.nodeName; return yt(e) ? `svg>${t}` : t; } function yt(e) { return e.namespaceURI === "http://www.w3.org/2000/svg"; } function Nt(e, t, n, o, i, s) { s.resetIds(), te(t, o, i, s, e, (r) => { k(qe(s.nodeIds), n, s.configuration.defaultPrivacyLevel, r); }); } function vt(e, t, n, o, i) { te(2, n, o, i, e, (s) => bt(t, s)); } function bt(e, t) { const n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(); for (const c of e) switch (c.type) { case "attributes": { const u = c.target; let d = o.get(u); d || (d = /* @__PURE__ */ new Map(), o.set(u, d)); const l = c.attributeName; d.has(l) || d.set(l, c.oldValue); break; } case "characterData": i.has(c.target) || i.set(c.target, c.oldValue); break; case "childList": for (let u = 0; u < c.addedNodes.length; u++) n.add(c.addedNodes[u]); for (let u = 0; u < c.removedNodes.length; u++) s.add(c.removedNodes[u]); break; } const r = t.scope.nodeIds.nextId, a = /* @__PURE__ */ new Map(); Ct(s, t), wt(n, a, t), Mt(i, r, a, t), Rt(o, r, a, t); } function Ct(e, t) { const n = t.scope.nodeIds; for (const o of e) { const i = n.get(o); i !== void 0 && (ae(o, (s) => { q(s) && t.scope.shadowRootsController.removeShadowRoot(s.shadowRoot), n.delete(s); }), t.removeNode(i)); } } function wt(e, t, n) { const o = n.scope.nodeIds; for (const i of e) { if (!i.isConnected || o.get(i) !== void 0) continue; const s = Z(i); if (!s) continue; const r = o.get(s); if (r === void 0) continue; const a = v(s, n.scope.configuration.defaultPrivacyLevel, t); k(Qe(r, _t(i, o), o), i, a, n); } } function Mt(e, t, n, o) { const i = o.scope.nodeIds; for (const [s, r] of e) { if (s.textContent === r || !s.isConnected) continue; const a = i.get(s); if (a === void 0 || a >= t) continue; const c = Z(s); if (!c) continue; const u = v(c, o.scope.configuration.defaultPrivacyLevel, n); if (u === g.HIDDEN || u === g.IGNORE) continue; const d = K(s, u); o.setText(a, d); } } function Rt(e, t, n, o) { const i = o.scope.nodeIds; for (const [s, r] of e) { if (!s.isConnected) continue; const a = i.get(s); if (a === void 0 || a >= t) continue; const c = v(s, o.scope.configuration.defaultPrivacyLevel, n); if (c === g.HIDDEN || c === g.IGNORE) continue; const u = [a]; for (const [d, l] of r) { if (s.getAttribute(d) === l) continue; if (d === "value") { const p = P(s, c); p !== void 0 && u.push([d, p]); continue; } const f = oe(s, c, d, o.scope.configuration); f === null ? u.push([d]) : u.push([d, f]); } u.length > 1 && o.setAttributes(u); } } function _t(e, t) { let n = e.nextSibling; for (; n; ) { const o = t.get(n); if (o !== void 0) return o; n = n.nextSibling; } } function ae(e, t) { t(e), W(e, (n) => ae(n, t)); } const B = 25; function xt(e) { return Math.abs(e.pageTop - e.offsetTop - window.scrollY) > B || Math.abs(e.pageLeft - e.offsetLeft - window.scrollX) > B; } const At = (e, t) => { const n = window.visualViewport, o = { layoutViewportX: e, layoutViewportY: t, visualViewportX: e, visualViewportY: t }; if (n) xt(n) ? (o.layoutViewportX = Math.round(e + n.offsetLeft), o.layoutViewportY = Math.round(t + n.offsetTop)) : (o.visualViewportX = Math.round(e - n.offsetLeft), o.visualViewportY = Math.round(t - n.offsetTop)); else return o; return o; }, ce = (e) => ({ scale: e.scale, offsetLeft: e.offsetLeft, offsetTop: e.offsetTop, pageLeft: e.pageLeft, pageTop: e.pageTop, height: e.height, width: e.width }); function Dt(e, t, n, o, i) { G(y(), 0, t, n, i); const { unsubscribe: s } = e.subscribe(R.VIEW_CREATED, (r) => { o(), G(r.startClocks.timeStamp, 1, t, n, i); }); return { stop: s }; } function G(e, t, n, o, i) { const { width: s, height: r } = we(); n({ data: { height: r, href: window.location.href, width: s }, type: T.Meta, timestamp: e }), n({ data: { has_focus: document.hasFocus() }, type: T.Focus, timestamp: e }), Nt(e, t, document, n, o, i), window.visualViewport && n({ data: ce(window.visualViewport), type: T.VisualViewport, timestamp: e }); } function Ot() { return V(1); } function Lt() { return V(0); } function Pt() { return Vt(0); } function kt() { return V(0); } function Vt(e) { return ue(() => /* @__PURE__ */ new Map(), e); } function V(e) { return ue(() => /* @__PURE__ */ new WeakMap(), e); } function ue(e, t) { let n = e(), o = t; const i = (s) => n.get(s); return { clear() { o !== t && (n = e(), o = t); }, delete(s) { n.delete(s); }, get: i, getOrInsert(s) { let r = i(s); return r === void 0 && (r = o++, n.set(s, r)), r; }, get nextId() { return o; }, get size() { return o - t; } }; } function zt(e, t, n) { const o = { resetIds() { o.eventIds.clear(), o.nodeIds.clear(), o.stringIds.clear(), o.styleSheetIds.clear(); }, configuration: e, elementsScrollPositions: t, eventIds: Ot(), nodeIds: Lt(), shadowRootsController: n, stringIds: Pt(), styleSheetIds: kt() }; return o; } function Ut() { const e = /* @__PURE__ */ new WeakMap(); return { set(t, n) { t === document && !document.scrollingElement || e.set(t === document ? document.scrollingElement : t, n); }, get(t) { return e.get(t); }, has(t) { return e.has(t); } }; } function de(e) { return !!e.changedTouches; } function _(e) { return e.composed === !0 && q(e.target) ? e.composedPath()[0] : e.target; } function I(e, t, n = y()) { return { data: { source: e, ...t }, type: T.IncrementalSnapshot, timestamp: n }; } const Ht = 50; function Ft(e, t) { const { throttled: n, cancel: o } = O((s) => { const r = _(s), a = t.nodeIds.get(r); if (a === void 0) return; const c = le(s); if (!c) return; const u = { id: a, timeOffset: 0, x: c.x, y: c.y }; e(I(de(s) ? E.TouchMove : E.MouseMove, { positions: [u] })); }, Ht, { trailing: !1 }), { stop: i } = C(document, [S.MOUSE_MOVE, S.TOUCH_MOVE], n, { capture: !0, passive: !0 }); return { stop: () => { i(), o(); } }; } function le(e) { let { clientX: t, clientY: n } = de(e) ? e.changedTouches[0] : e; if (window.visualViewport) { const { visualViewportX: o, visualViewportY: i } = At(t, n); t = o, n = i; } if (!(!Number.isFinite(t) || !Number.isFinite(n))) return { x: t, y: n }; } const Y = { [S.POINTER_UP]: m.MouseUp, [S.MOUSE_DOWN]: m.MouseDown, [S.CLICK]: m.Click, [S.CONTEXT_MENU]: m.ContextMenu, [S.DBL_CLICK]: m.DblClick, [S.FOCUS]: m.Focus, [S.BLUR]: m.Blur, [S.TOUCH_START]: m.TouchStart, [S.TOUCH_END]: m.TouchEnd }; function Bt(e, t) { const n = (o) => { const i = _(o), s = t.nodeIds.get(i); if (s === void 0 || v(i, t.configuration.defaultPrivacyLevel) === g.HIDDEN) return; const r = Y[o.type]; let a; if (r !== m.Blur && r !== m.Focus) { const c = le(o); if (!c) return; a = { id: s, type: r, x: c.x, y: c.y }; } else a = { id: s, type: r }; e({ id: t.eventIds.getOrInsert(o), ...I(E.MouseInteraction, a) }); }; return C(document, Object.keys(Y), n, { capture: !0, passive: !0 }); } const Gt = 100; function fe(e, t, n) { const { throttled: o, cancel: i } = O((r) => { const a = _(r); if (!a) return; const c = n.nodeIds.get(a); if (c === void 0 || v(a, n.configuration.defaultPrivacyLevel) === g.HIDDEN) return; const u = a === document ? { scrollTop: j(), scrollLeft: J() } : { scrollTop: Math.round(a.scrollTop), scrollLeft: Math.round(a.scrollLeft) }; n.elementsScrollPositions.set(a, u), t(I(E.Scroll, { id: c, x: u.scrollLeft, y: u.scrollTop })); }, Gt), { stop: s } = Me(e, S.SCROLL, o, { capture: !0, passive: !0 }); return { stop: () => { s(), i(); } }; } const Yt = 200; function Xt(e) { const t = Re().subscribe((n) => { e(I(E.ViewportResize, n)); }); return { stop: () => { t.unsubscribe(); } }; } function $t(e) { const t = window.visualViewport; if (!t) return { stop: N }; const { throttled: n, cancel: o } = O(() => { e({ data: ce(t), type: T.VisualViewport, timestamp: y() }); }, Yt, { trailing: !1 }), { stop: i } = C(t, [S.RESIZE, S.SCROLL], n, { capture: !0, passive: !0 }); return { stop: () => { i(), o(); } }; } function Wt(e, t) { return C(document, [S.PLAY, S.PAUSE], (n) => { const o = _(n); if (!o) return; const i = t.nodeIds.get(o); i === void 0 || v(o, t.configuration.defaultPrivacyLevel) === g.HIDDEN || e(I(E.MediaInteraction, { id: i, type: n.type === S.PLAY ? D.Play : D.Pause })); }, { capture: !0, passive: !0 }); } function Kt(e, t) { function n(s, r) { if (!s?.ownerNode) return; const a = t.nodeIds.get(s.ownerNode); a !== void 0 && r(a); } const o = [x(CSSStyleSheet.prototype, "insertRule", ({ target: s, parameters: [r, a] }) => { n(s, (c) => e(I(E.StyleSheetRule, { id: c, adds: [{ rule: r, index: a }] }))); }), x(CSSStyleSheet.prototype, "deleteRule", ({ target: s, parameters: [r] }) => { n(s, (a) => e(I(E.StyleSheetRule, { id: a, removes: [{ index: r }] }))); })]; typeof CSSGroupingRule < "u" ? i(CSSGroupingRule) : (i(CSSMediaRule), i(CSSSupportsRule)); function i(s) { o.push(x(s.prototype, "insertRule", ({ target: r, parameters: [a, c] }) => { n(r.parentStyleSheet, (u) => { const d = X(r); d && (d.push(c || 0), e(I(E.StyleSheetRule, { id: u, adds: [{ rule: a, index: d }] }))); }); }), x(s.prototype, "deleteRule", ({ target: r, parameters: [a] }) => { n(r.parentStyleSheet, (c) => { const u = X(r); u && (u.push(a), e(I(E.StyleSheetRule, { id: c, removes: [{ index: u }] }))); }); })); } return { stop: () => { o.forEach((s) => s.stop()); } }; } function X(e) { const t = []; let n = e; for (; n.parentRule; ) { const i = Array.from(n.parentRule.cssRules).indexOf(n); t.unshift(i), n = n.parentRule; } if (!n.parentStyleSheet) return; const o = Array.from(n.parentStyleSheet.cssRules).indexOf(n); return t.unshift(o), t; } function Jt(e) { return C(window, [S.FOCUS, S.BLUR], () => { e({ data: { has_focus: document.hasFocus() }, type: T.Focus, timestamp: y() }); }); } function jt(e, t, n) { const o = e.subscribe(R.VIEW_ENDED, () => { n(), t({ timestamp: y(), type: T.ViewEnd }); }); return { stop: () => { o.unsubscribe(); } }; } function pe(e, t, n) { const o = n.configuration.defaultPrivacyLevel, i = /* @__PURE__ */ new WeakMap(), s = e !== document, { stop: r } = C(e, s ? [S.CHANGE] : [S.INPUT, S.CHANGE], (d) => { const l = _(d); (l instanceof HTMLInputElement || l instanceof HTMLTextAreaElement || l instanceof HTMLSelectElement) && c(l); }, { capture: !0, passive: !0 }); let a; if (s) a = N; else { const d = [ M(HTMLInputElement.prototype, "value", c), M(HTMLInputElement.prototype, "checked", c), M(HTMLSelectElement.prototype, "value", c), M(HTMLTextAreaElement.prototype, "value", c), M(HTMLSelectElement.prototype, "selectedIndex", c) ]; a = () => { d.forEach((l) => l.stop()); }; } return { stop: () => { a(), r(); } }; function c(d) { const l = v(d, o); if (l === g.HIDDEN) return; const f = d.type; let p; if (f === "radio" || f === "checkbox") { if (A(d, l)) return; p = { isChecked: d.checked }; } else { const w = P(d, l); if (w === void 0) return; p = { text: w }; } u(d, p); const b = d.name; f === "radio" && b && d.checked && document.querySelectorAll(`input[type="radio"][name="${CSS.escape(b)}"]`).forEach((w) => { w !== d && u(w, { isChecked: !1 }); }); } function u(d, l) { const f = n.nodeIds.get(d); if (f === void 0) return; const p = i.get(d); (!p || p.text !== l.text || p.isChecked !== l.isChecked) && (i.set(d, l), t(I(E.Input, { id: f, ...l }))); } } const Zt = 100; function qt(e) { let t = N, n = []; function o() { t(), e(n), n = []; } const { throttled: i, cancel: s } = O(o, 16, { leading: !1 }); return { addMutations: (r) => { n.length === 0 && (t = _e(i, { timeout: Zt })); for (const a of r) n.push(a); }, flush: o, stop: () => { t(), s(); } }; } function he(e, t, n, o) { const i = xe(); if (!i) return { stop: N, flush: N }; const s = qt((a) => { vt(y(), a.concat(r.takeRecords()), t, n, o); }), r = new i(Ae(s.addMutations)); return r.observe(e, { attributeOldValue: !0, attributes: !0, characterData: !0, characterDataOldValue: !0, childList: !0, subtree: !0 }), { stop: () => { r.disconnect(), s.stop(); }, flush: () => { s.flush(); } }; } const Qt = (e, t) => { const n = /* @__PURE__ */ new Map(); return { addShadowRoot: (o, i) => { if (n.has(o)) return; const s = he(o, e, t, i), r = pe(o, e, i), a = fe(o, e, i); n.set(o, { flush: () => s.flush(), stop: () => { s.stop(), r.stop(), a.stop(); } }); }, removeShadowRoot: (o) => { const i = n.get(o); i && (i.stop(), n.delete(o)); }, stop: () => { n.forEach(({ stop: o }) => o()); }, flush: () => { n.forEach(({ flush: o }) => o()); } }; }; function en(e) { const { emitRecord: t, emitStats: n, configuration: o, lifeCycle: i } = e; if (!t || !n) throw new Error("emit functions are required"); const s = (f) => { t(f), De("record", { record: f }), Oe(e.viewHistory.findView().id); }, r = Qt(s, n), a = zt(o, Ut(), r), { stop: c } = Dt(i, s, n, u, a); function u() { r.flush(), d.flush(); } const d = he(document, s, n, a), l = [ d, Ft(s, a), Bt(s, a), fe(document, s, a), Xt(s), pe(document, s, a), Wt(s, a), Kt(s, a), Jt(s), $t(s), jt(i, s, u) ]; return { stop: () => { r.stop(), l.forEach((f) => f.stop()), c(); }, flushMutations: u, shadowRootsController: r }; } function tn(e, t, n, o) { const i = new FormData(); i.append("segment", new Blob([e], { type: "application/octet-stream" }), `${t.session.id}-${t.start}`); const s = { raw_segment_size: o, compressed_segment_size: e.byteLength, ...t }, r = JSON.stringify(s); return i.append("event", new Blob([r], { type: "application/json" })), { data: i, bytesCount: e.byteLength, cssText: n.cssText, isFullSnapshot: t.index_in_view === 0, rawSize: o, recordCount: t.records_count, serializationDuration: n.serializationDuration }; } function nn({ context: e, creationReason: t, encoder: n }) { let o = 0; const i = e.view.id, s = { start: 1 / 0, end: -1 / 0, creation_reason: t, records_count: 0, has_full_snapshot: !1, index_in_view: Le(i), source: "browser", ...e }, r = ee(); Pe(i); function a(d, l) { s.start = Math.min(s.start, d.timestamp), s.end = Math.max(s.end, d.timestamp), s.records_count += 1, s.has_full_snapshot ||= d.type === T.FullSnapshot || d.type === T.Change && s.index_in_view === 0; const f = n.isEmpty ? '{"records":[' : ","; n.write(f + JSON.stringify(d), (p) => { o += p, l(o); }); } function c(d) { et(r, d); } function u(d) { if (n.isEmpty) throw new Error("Empty segment flushed"); n.write(`],${JSON.stringify(s).slice(1)} `), n.finish((l) => { ke(s.view.id, l.rawBytesCount), d(s, r, l); }); } return { addRecord: a, addStats: c, flush: u }; } const on = 5 * He; let Se = 6e4; function sn(e, t, n, o, i, s) { return rn(e, () => an(t.applicationId, n, o), i, s); } function rn(e, t, n, o) { let i = { status: 0, nextSegmentCreationReason: "init" }; const { unsubscribe: s } = e.subscribe(R.VIEW_CREATED, () => { a("view_change"); }), { unsubscribe: r } = e.subscribe(R.PAGE_MAY_EXIT, (c) => { a(c.reason); }); function a(c) { i.status === 1 && (i.segment.flush((u, d, l) => { const f = tn(l.output, u, d, l.rawBytesCount); Ve(c) ? n.sendOnExit(f) : n.send(f); }), ze(i.expirationTimeoutId)), c !== "stop" ? i = { status: 0, nextSegmentCreationReason: c } : i = { status: 2 }; } return { addRecord: (c) => { if (i.status !== 2) { if (i.status === 0) { const u = t(); if (!u) return; i = { status: 1, segment: nn({ encoder: o, context: u, creationReason: i.nextSegmentCreationReason }), expirationTimeoutId: Ue(() => { a("segment_duration_limit"); }, on) }; } i.segment.addRecord(c, (u) => { u > Se && a("segment_bytes_limit"); }); } }, addStats: (c) => { i.status === 1 && i.segment.addStats(c); }, stop: () => { a("stop"), s(), r(); } }; } function an(e, t, n) { const o = t.findTrackedSession(), i = n.findView(); if (!(!o || !i)) return { application: { id: e }, session: { id: o.id }, view: { id: i.id } }; } function cn(e, t) { if (!e.metricsEnabled) return { stop: N }; const { unsubscribe: n } = t.subscribe((o) => { if (o.type === "failure" || o.type === "queue-full" || o.type === "success" && o.payload.isFullSnapshot) { const i = un(o.type, o.bandwidth, o.payload); Fe(Be.SEGMENT_METRICS_TELEMETRY_NAME, { metrics: i }); } }); return { stop: n }; } function un(e, t, n) { return { cssText: { count: n.cssText.count, max: n.cssText.max, sum: n.cssText.sum }, encoding: { fullSnapshot: "change", incrementalSnapshot: "change" }, isFullSnapshot: n.isFullSnapshot, ongoingRequests: { count: t.ongoingRequestCount, totalSize: t.ongoingByteCount }, recordCount: n.recordCount, result: e, serializationDuration: { count: n.serializationDuration.count, max: n.serializationDuration.max, sum: n.serializationDuration.sum }, size: { compressed: n.bytesCount, raw: n.rawSize } }; } function dn(e) { const t = Ge(); return { addRecord: (n) => { const o = e.findView(); t.send("record", n, o.id); } }; } function fn(e, t, n, o, i, s, r) { const a = [], c = (p) => { e.notify(R.RAW_ERROR_COLLECTED, { error: p }), We("Error reported to customer", { "error.message": p.message }); }, u = r || Xe([$e(t, "replay")], c, Se); let d, l; if (Ye()) ({ addRecord: d } = dn(o)), l = N; else { const p = sn(e, t, n, o, u, i); d = p.addRecord, l = p.addStats, a.push(p.stop); const b = cn(s, u.observable); a.push(b.stop); } const { stop: f } = en({ emitRecord: d, emitStats: l, configuration: t, lifeCycle: e, viewHistory: o }); return a.push(f), { stop: () => { a.forEach((p) => p()); } }; } export { fn as startRecording }; //# sourceMappingURL=datadogRecorder-CW1uYAo0.js.map