@levo-so/react 0.1.33 → 0.1.34

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.
@@ -1,478 +0,0 @@
1
- "use client";
2
- var rt = Object.defineProperty;
3
- var ot = (t, n, e) => n in t ? rt(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
4
- var F = (t, n, e) => ot(t, typeof n != "symbol" ? n + "" : n, e);
5
- import { j as st } from "./jsx-runtime-B6kdoens.js";
6
- import { useEffect as d, useState as b } from "react";
7
- import { useInView as it } from "react-intersection-observer";
8
- import { useLevo as S } from "./providers/index.js";
9
- import { usePageLifecycle as ct, LifecycleState as E } from "use-page-lifecycle";
10
- const le = ({ id: t, properties: n = {} }) => {
11
- const { audience: e } = S(), { ref: r, inView: o } = it({
12
- triggerOnce: !0
13
- });
14
- return d(() => {
15
- e != null && e.instance && o && (e == null || e.track("block.view", {
16
- ...n,
17
- resource: "block",
18
- identifier: t
19
- }));
20
- }, [o]), /* @__PURE__ */ st.jsx("div", { ref: r, style: { height: "0px" } });
21
- }, ge = ({ event: t, properties: n }) => {
22
- const { audience: e } = S();
23
- return d(() => {
24
- e != null && e.instance && (e == null || e.track(t, n));
25
- }, [e == null ? void 0 : e.instance, t, n]), null;
26
- };
27
- function A(t) {
28
- var n = typeof t;
29
- return t != null && (n == "object" || n == "function");
30
- }
31
- var at = typeof global == "object" && global && global.Object === Object && global, ut = typeof self == "object" && self && self.Object === Object && self, G = at || ut || Function("return this")(), O = function() {
32
- return G.Date.now();
33
- }, ft = /\s/;
34
- function dt(t) {
35
- for (var n = t.length; n-- && ft.test(t.charAt(n)); )
36
- ;
37
- return n;
38
- }
39
- var lt = /^\s+/;
40
- function gt(t) {
41
- return t && t.slice(0, dt(t) + 1).replace(lt, "");
42
- }
43
- var x = G.Symbol, K = Object.prototype, pt = K.hasOwnProperty, mt = K.toString, y = x ? x.toStringTag : void 0;
44
- function ht(t) {
45
- var n = pt.call(t, y), e = t[y];
46
- try {
47
- t[y] = void 0;
48
- var r = !0;
49
- } catch {
50
- }
51
- var o = mt.call(t);
52
- return r && (n ? t[y] = e : delete t[y]), o;
53
- }
54
- var bt = Object.prototype, wt = bt.toString;
55
- function yt(t) {
56
- return wt.call(t);
57
- }
58
- var vt = "[object Null]", St = "[object Undefined]", U = x ? x.toStringTag : void 0;
59
- function Tt(t) {
60
- return t == null ? t === void 0 ? St : vt : U && U in Object(t) ? ht(t) : yt(t);
61
- }
62
- function Et(t) {
63
- return t != null && typeof t == "object";
64
- }
65
- var Lt = "[object Symbol]";
66
- function xt(t) {
67
- return typeof t == "symbol" || Et(t) && Tt(t) == Lt;
68
- }
69
- var H = NaN, Ct = /^[-+]0x[0-9a-f]+$/i, _t = /^0b[01]+$/i, kt = /^0o[0-7]+$/i, Nt = parseInt;
70
- function B(t) {
71
- if (typeof t == "number")
72
- return t;
73
- if (xt(t))
74
- return H;
75
- if (A(t)) {
76
- var n = typeof t.valueOf == "function" ? t.valueOf() : t;
77
- t = A(n) ? n + "" : n;
78
- }
79
- if (typeof t != "string")
80
- return t === 0 ? t : +t;
81
- t = gt(t);
82
- var e = _t.test(t);
83
- return e || kt.test(t) ? Nt(t.slice(2), e ? 2 : 8) : Ct.test(t) ? H : +t;
84
- }
85
- var Ot = "Expected a function", It = Math.max, Rt = Math.min;
86
- function At(t, n, e) {
87
- var r, o, c, a, s, i, u = 0, g = !1, l = !1, p = !0;
88
- if (typeof t != "function")
89
- throw new TypeError(Ot);
90
- n = B(n) || 0, A(e) && (g = !!e.leading, l = "maxWait" in e, c = l ? It(B(e.maxWait) || 0, n) : c, p = "trailing" in e ? !!e.trailing : p);
91
- function k(f) {
92
- var m = r, w = o;
93
- return r = o = void 0, u = f, a = t.apply(w, m), a;
94
- }
95
- function Q(f) {
96
- return u = f, s = setTimeout(T, n), g ? k(f) : a;
97
- }
98
- function tt(f) {
99
- var m = f - i, w = f - u, P = n - m;
100
- return l ? Rt(P, c - w) : P;
101
- }
102
- function M(f) {
103
- var m = f - i, w = f - u;
104
- return i === void 0 || m >= n || m < 0 || l && w >= c;
105
- }
106
- function T() {
107
- var f = O();
108
- if (M(f))
109
- return D(f);
110
- s = setTimeout(T, tt(f));
111
- }
112
- function D(f) {
113
- return s = void 0, p && r ? k(f) : (r = o = void 0, a);
114
- }
115
- function et() {
116
- s !== void 0 && clearTimeout(s), u = 0, r = i = o = s = void 0;
117
- }
118
- function nt() {
119
- return s === void 0 ? a : D(O());
120
- }
121
- function N() {
122
- var f = O(), m = M(f);
123
- if (r = arguments, o = this, i = f, m) {
124
- if (s === void 0)
125
- return Q(i);
126
- if (l)
127
- return clearTimeout(s), s = setTimeout(T, n), k(i);
128
- }
129
- return s === void 0 && (s = setTimeout(T, n)), a;
130
- }
131
- return N.cancel = et, N.flush = nt, N;
132
- }
133
- const jt = () => {
134
- const [t, n] = b(0), [e, r] = b(0), o = At((c) => {
135
- r(c), n(c);
136
- }, 250);
137
- return d(() => {
138
- const c = () => {
139
- const a = window.scrollY, s = document.documentElement.scrollHeight, i = window.innerHeight, u = Math.round(
140
- a / (s - i) * 100
141
- );
142
- u % 10 === 0 && u > e && o(u);
143
- };
144
- return window.addEventListener("scroll", c), () => window.removeEventListener("scroll", c);
145
- }, [e]), t;
146
- }, v = "lv_insights_ot", $t = () => {
147
- const [t, n] = b(0);
148
- return d(() => {
149
- const e = Number(localStorage.getItem(v)) || 0;
150
- n(e), localStorage.setItem(v, (e + 1).toString());
151
- const r = (c) => {
152
- c.key === v && n(Number(c.newValue) || 0);
153
- };
154
- window.addEventListener("storage", r);
155
- const o = () => {
156
- const c = Number(localStorage.getItem(v)) || 0;
157
- c > 0 && localStorage.setItem(v, (c - 1).toString());
158
- };
159
- return window.addEventListener("beforeunload", o), () => {
160
- window.removeEventListener("storage", r), window.removeEventListener("beforeunload", o);
161
- };
162
- }, []), t;
163
- }, W = "lv_insights_ct", I = "lv_insights_at", Mt = () => {
164
- const [t, n] = b(null);
165
- return d(() => {
166
- let e = sessionStorage.getItem(W);
167
- const r = JSON.parse(
168
- localStorage.getItem(I) || "[]"
169
- );
170
- e && r.includes(e) && (e = null), e || (e = `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, sessionStorage.setItem(W, e)), r.includes(e) || (r.push(e), localStorage.setItem(
171
- I,
172
- JSON.stringify(r)
173
- )), n(e);
174
- const o = () => {
175
- const c = r.filter(
176
- (a) => a !== e
177
- );
178
- localStorage.setItem(
179
- I,
180
- JSON.stringify(c)
181
- );
182
- };
183
- return window.addEventListener("beforeunload", o), () => {
184
- window.removeEventListener("beforeunload", o);
185
- };
186
- }, []), t;
187
- }, C = (t) => Object.prototype.toString.call(t) == "[object String]", Dt = (t, n) => t.indexOf(n) !== -1, _ = (t) => t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""), V = (t) => t === void 0, Pt = (t) => t === null, Y = (t) => V(t) || Pt(t), J = (t) => !!t && (t == null ? void 0 : t.nodeType) === 3;
188
- function Ft(t) {
189
- return !!t && (t == null ? void 0 : t.nodeType) === 1;
190
- }
191
- function Ut(t, n) {
192
- return !!t && !!(t != null && t.tagName) && (t == null ? void 0 : t.tagName.toLowerCase()) === n.toLowerCase();
193
- }
194
- function Ht(t) {
195
- return t ? _(t).split(/\s+/) : [];
196
- }
197
- function Bt(t) {
198
- let n = "";
199
- switch (typeof (t == null ? void 0 : t.className)) {
200
- case "string":
201
- n = t == null ? void 0 : t.className;
202
- break;
203
- case "object":
204
- n = (t != null && t.className && "baseVal" in (t == null ? void 0 : t.className) ? (t == null ? void 0 : t.className).baseVal : null) || (t == null ? void 0 : t.getAttribute("class")) || "";
205
- break;
206
- default:
207
- n = "";
208
- }
209
- return Ht(n);
210
- }
211
- const h = (t, n = 255) => Y(t) ? "" : _(t).split(/(\s+)/).filter((e) => $(e)).join("").replace(/[\r\n]/g, " ").replace(/[ ]+/g, " ").substring(0, n), j = (t) => {
212
- let n = "";
213
- if (Kt(t) && // !isSensitiveElement(el) &&
214
- (t != null && t.childNodes) && (t != null && t.childNodes.length))
215
- for (const e of t == null ? void 0 : t.childNodes)
216
- J(e) && e.textContent && (n += h(e.textContent) ?? "");
217
- return _(n);
218
- }, Wt = (t) => {
219
- var n, e;
220
- return V(t.target) ? (t == null ? void 0 : t.srcElement) || null : (n = t == null ? void 0 : t.target) != null && n.shadowRoot ? ((e = t == null ? void 0 : t.composedPath()) == null ? void 0 : e[0]) || null : (t == null ? void 0 : t.target) || null;
221
- }, Gt = (t, n) => {
222
- if (!window || !t || Ut(t, "html") || !Ft(t))
223
- return !1;
224
- const e = window.getComputedStyle(t);
225
- if (e && e.getPropertyValue("cursor") === "pointer" && n.type === "click")
226
- return !0;
227
- switch (t == null ? void 0 : t.tagName.toLowerCase()) {
228
- case "html":
229
- return !1;
230
- case "form":
231
- return n.type === "submit";
232
- case "input":
233
- case "select":
234
- case "textarea":
235
- return ["change", "click"].includes(n.type);
236
- default:
237
- return n.type === "click";
238
- }
239
- };
240
- function Kt(t) {
241
- if (Dt(Bt(t), "ph-include"))
242
- return !0;
243
- const n = t.type || "";
244
- if (C(n))
245
- switch (n.toLowerCase()) {
246
- case "hidden":
247
- return !1;
248
- case "password":
249
- return !1;
250
- }
251
- const e = t.name || (t == null ? void 0 : t.id) || "";
252
- return !(C(e) && /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(e.replace(/[^a-zA-Z0-9]/g, "")));
253
- }
254
- const X = "(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11})", Vt = new RegExp(`^(?:${X})$`), Yt = new RegExp(X), z = "\\d{3}-?\\d{2}-?\\d{4}", Jt = new RegExp(`^(${z})$`), Xt = new RegExp(`(${z})`), $ = (t, n = !0) => !(Y(t) || C(t) && (t = _(t), (n ? Vt : Yt).test((t || "").replace(/[- ]/g, "")) || (n ? Jt : Xt).test(t))), zt = (t) => C(t) ? t.substring(0, 10) === "_ngcontent" || t.substring(0, 7) === "_nghost" : !1, Zt = (t) => {
255
- let n = j(t);
256
- return n = `${n} ${Z(t)}`.trim(), $(n) ? n : "";
257
- };
258
- function Z(t) {
259
- var e;
260
- let n = "";
261
- if (t != null && t.childNodes.length) {
262
- for (const r of t.childNodes)
263
- if (r && ((e = r.tagName) == null ? void 0 : e.toLowerCase()) === "span")
264
- try {
265
- const o = j(r);
266
- n = `${n} ${o}`.trim(), r != null && r.childNodes.length && (n = `${n} ${Z(r)}`.trim());
267
- } catch {
268
- }
269
- }
270
- return n;
271
- }
272
- const qt = ["input", "textarea", "select"], q = (t) => {
273
- var o, c, a;
274
- const n = t.tagName.toLowerCase(), e = {
275
- element: n
276
- };
277
- n.toLowerCase() === "a" || n.toLowerCase() === "button" ? e.text = Zt(t) : e.text = j(t);
278
- const r = Array.from(t.attributes).reduce(
279
- (s, i) => {
280
- if ($(i.value) && !zt(i.name)) {
281
- if (i.name === "class")
282
- return s;
283
- s[i.name] = typeof (i == null ? void 0 : i.value) == "string" ? h(i.value) : i.value;
284
- }
285
- return s;
286
- },
287
- {}
288
- );
289
- if (e.attributes = r, qt.includes(n) || (t == null ? void 0 : t.getAttribute("contenteditable")) === "true") {
290
- let s;
291
- t.matches('input[type="checkbox"], input[type="radio"]') ? s = t.checked : t.matches("input, select, textarea") && !t.matches('input[type="password"]') && (s = t.value), s !== void 0 && (e.value = typeof s == "string" || s === null ? h(s, 1024) : s);
292
- let i = "";
293
- e != null && e.attributes.id && (i = h(
294
- ((c = (o = document.querySelector(`label[for="${e == null ? void 0 : e.attributes.id}"]`)) == null ? void 0 : o.textContent) == null ? void 0 : c.trim()) || ""
295
- ));
296
- const u = t.closest("label");
297
- i || (i = h(((a = u == null ? void 0 : u.textContent) == null ? void 0 : a.trim()) || "")), i && (e.label = i);
298
- }
299
- return e;
300
- }, Qt = (t, n) => {
301
- var o;
302
- let e = Wt(t);
303
- J(e) && (e = e.parentNode || null);
304
- const r = ["copy", "cut"].includes(n);
305
- if (e && (Gt(e, t) || r)) {
306
- const c = q(e);
307
- if (r) {
308
- const a = h((o = window == null ? void 0 : window.getSelection()) == null ? void 0 : o.toString()), s = (t == null ? void 0 : t.type) || "clipboard";
309
- c.copy_text = a ?? "", c.copy_type = s ?? "";
310
- }
311
- return c;
312
- }
313
- return null;
314
- }, te = 30, ee = 1e3, ne = 3;
315
- class re {
316
- constructor() {
317
- F(this, "clicks");
318
- this.clicks = [];
319
- }
320
- isRageClick(n, e, r) {
321
- const o = this.clicks[this.clicks.length - 1];
322
- if (o && Math.abs(n - o.x) + Math.abs(e - o.y) < te && r - o.timestamp < ee) {
323
- if (this.clicks.push({ x: n, y: e, timestamp: r }), this.clicks.length === ne)
324
- return !0;
325
- } else
326
- this.clicks = [{ x: n, y: e, timestamp: r }];
327
- return !1;
328
- }
329
- }
330
- const R = new re(), oe = () => {
331
- const { audience: t } = S();
332
- d(() => {
333
- const n = (e) => {
334
- try {
335
- let r = {
336
- hostname: window.location.hostname,
337
- pathname: window.location.pathname,
338
- page_title: document.title,
339
- url: window.location.href,
340
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
341
- event_type: e.type,
342
- button_type: e.button
343
- };
344
- if (e.target instanceof HTMLElement) {
345
- const o = e.target;
346
- r.rage_click = R == null ? void 0 : R.isRageClick(
347
- e.clientX,
348
- e.clientY,
349
- (/* @__PURE__ */ new Date()).getTime()
350
- ), r = {
351
- ...r,
352
- ...q(o)
353
- };
354
- let c = o == null ? void 0 : o.getAttribute("href");
355
- if (!c) {
356
- let a = o.parentNode, s = 0;
357
- for (; a && s < 8; ) {
358
- const i = a == null ? void 0 : a.getAttribute(
359
- "href"
360
- );
361
- if (i) {
362
- c = i;
363
- break;
364
- }
365
- a = a.parentNode, s++;
366
- }
367
- }
368
- t == null || t.track("page.click", {
369
- ...r,
370
- href: c || void 0
371
- });
372
- }
373
- } catch (r) {
374
- console.error(r);
375
- }
376
- };
377
- return document.addEventListener("click", n), () => {
378
- document.removeEventListener("click", n);
379
- };
380
- }, [t]);
381
- }, L = (t) => Number(t.toFixed(0)), se = (t) => {
382
- const { audience: n } = S(), [, e] = b({
383
- page_loaded_at: L(performance.timeOrigin),
384
- script_load: L(performance.now()),
385
- first_contentful_paint: null,
386
- window_onload: null
387
- }), [r, o] = b(
388
- null
389
- );
390
- return d(() => {
391
- let c = !0;
392
- const a = (u) => {
393
- c && e((g) => {
394
- const l = { ...g, ...u };
395
- return Object.values(l).every((p) => p !== null) && o(l), l;
396
- });
397
- }, s = new PerformanceObserver((u) => {
398
- for (const g of u.getEntries())
399
- g.name === "first-contentful-paint" && a({ first_contentful_paint: L(g.startTime) });
400
- });
401
- s.observe({ type: "paint", buffered: !0 });
402
- const i = () => a({ window_onload: L(performance.now()) });
403
- return document.readyState === "complete" ? i() : window.addEventListener("load", i), () => {
404
- c = !1, s.disconnect(), window.removeEventListener("load", i);
405
- };
406
- }, [t]), d(() => {
407
- r && n && (n == null || n.track("page.metrics", r));
408
- }, [r, n]), r;
409
- }, pe = ({ id: t, properties: n = {} }) => {
410
- const e = typeof window < "u" ? window.location.href : "", { client: r, audience: o } = S();
411
- d(() => {
412
- r && typeof window < "u" && (window.levo_client = r);
413
- }, [r]), d(() => {
414
- o && typeof window < "u" && (window.levo_audience = o);
415
- }, [o]), $t(), Mt(), oe();
416
- const c = jt();
417
- d(() => {
418
- o != null && o.instance && o.track("page.scroll", {
419
- resource: "page",
420
- identifier: t,
421
- percent: c
422
- });
423
- }, [o == null ? void 0 : o.instance, c, t]), se(e), d(() => {
424
- const s = () => {
425
- o == null || o.bounce({
426
- resource: "page",
427
- identifier: t
428
- });
429
- };
430
- return window && window.addEventListener("beforeunload", s), () => {
431
- window && window.removeEventListener("beforeunload", s);
432
- };
433
- }, [o, t]);
434
- const [a] = ct();
435
- return d(() => {
436
- (a === E.TERMINATED || a === E.HIDDEN || a === E.UNKNOWN || a === E.FROZEN) && (o == null || o.bounce({
437
- resource: "page",
438
- identifier: t,
439
- state: a
440
- }));
441
- }, [a, o, t]), d(() => {
442
- (() => {
443
- r != null && r.insightsUrl && r.workspace && e && (o != null && o.instance ? o.instance.page({
444
- resource: "page",
445
- identifier: t
446
- }) : o == null || o.initiate({
447
- ...n,
448
- id: t,
449
- created_at: (/* @__PURE__ */ new Date()).toISOString()
450
- }));
451
- })();
452
- }, [r == null ? void 0 : r.insightsUrl, r == null ? void 0 : r.workspace, e]), d(() => {
453
- const s = {
454
- change: "form.change",
455
- submit: "form.submit",
456
- copy: "page.copy",
457
- cut: "page.copy"
458
- }, i = (g) => (l) => {
459
- const p = Qt(l, g);
460
- p && (o == null || o.track(s[g], p));
461
- }, u = {
462
- change: i("change"),
463
- copy: i("copy"),
464
- cut: i("cut"),
465
- submit: i("submit")
466
- };
467
- return document.addEventListener("change", u.change), document.addEventListener("copy", u.copy), document.addEventListener("cut", u.cut), document.addEventListener("submit", u.submit), () => {
468
- document.removeEventListener("change", u.change), document.removeEventListener("copy", u.copy), document.removeEventListener("cut", u.cut), document.removeEventListener("submit", u.submit);
469
- };
470
- }, []), (!(r != null && r.insightsUrl) || !r.workspace || !r.workspace.startsWith("W")) && console.error(
471
- "[@levo-so/react] The utility could not be initialized, due to missing workspace, or endpoint for insights."
472
- ), null;
473
- };
474
- export {
475
- le as L,
476
- ge as a,
477
- pe as b
478
- };