leesto-connect 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.
@@ -0,0 +1,705 @@
1
+ function J(e) {
2
+ return typeof e == "object" && e !== null && typeof e.type == "string" && e.type.startsWith("leesto:");
3
+ }
4
+ var Q = "leesto_diag", ee = "leesto_run", F = "X-Leesto-Run-Id", te = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
5
+ function G(e) {
6
+ return typeof e == "string" && te.test(e);
7
+ }
8
+ function ne() {
9
+ try {
10
+ const e = globalThis.crypto, t = e?.randomUUID?.();
11
+ if (G(t)) return t;
12
+ if (!e?.getRandomValues) return;
13
+ const r = e.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
14
+ r[6] = (r[6] ?? 0) & 15 | 64, r[8] = (r[8] ?? 0) & 63 | 128;
15
+ const c = Array.from(r, (s) => s.toString(16).padStart(2, "0")).join(""), l = `${c.slice(0, 8)}-${c.slice(8, 12)}-${c.slice(12, 16)}-${c.slice(16, 20)}-${c.slice(20)}`;
16
+ return G(l) ? l : void 0;
17
+ } catch {
18
+ return;
19
+ }
20
+ }
21
+ function re(e) {
22
+ try {
23
+ const t = new URLSearchParams(e).get(ee);
24
+ return G(t) ? t : void 0;
25
+ } catch {
26
+ return;
27
+ }
28
+ }
29
+ function oe(e) {
30
+ try {
31
+ return new URLSearchParams(e).get(Q) === "1";
32
+ } catch {
33
+ return !1;
34
+ }
35
+ }
36
+ var W = "leesto/console", B = "leesto/network", se = "leesto/network-ring", ie = "leesto/console-ring", ce = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, ae = /\b\d{3}-\d{2}-\d{4}\b/g, le = /\d(?:[ -]?\d){12,18}/g;
37
+ function ue(e) {
38
+ let t = 0, r = !1;
39
+ for (let c = e.length - 1; c >= 0; c--) {
40
+ let l = e.charCodeAt(c) - 48;
41
+ if (l < 0 || l > 9) return !1;
42
+ r && (l *= 2, l > 9 && (l -= 9)), t += l, r = !r;
43
+ }
44
+ return t % 10 === 0;
45
+ }
46
+ function b(e) {
47
+ if (!e) return e;
48
+ let t = e.replace(ce, "[email masqué]");
49
+ return t = t.replace(ae, "[id masqué]"), t = t.replace(le, (r) => {
50
+ const c = r.replace(/[ -]/g, "");
51
+ return c.length >= 13 && c.length <= 19 && ue(c) ? "[carte masquée]" : r;
52
+ }), t;
53
+ }
54
+ function I(e) {
55
+ const t = typeof e == "string" ? e : e instanceof URL ? e.href : e instanceof Request ? e.url : String(e);
56
+ try {
57
+ const r = new URL(t, typeof location < "u" ? location.href : void 0);
58
+ return r.origin + b(r.pathname);
59
+ } catch {
60
+ return b(t.split("?")[0] ?? t);
61
+ }
62
+ }
63
+ var de = /* @__PURE__ */ new Set(["fetch", "xmlhttprequest"]), fe = ["deprecation", "intervention"], pe = { teardown: () => {
64
+ } };
65
+ function he(e) {
66
+ const t = typeof performance < "u" ? performance.timeOrigin : 0;
67
+ return Math.round(t + e);
68
+ }
69
+ function ge(e) {
70
+ const t = e.responseStatus;
71
+ return typeof t == "number" && t > 0 ? t : void 0;
72
+ }
73
+ function me(e) {
74
+ if (de.has(e.initiatorType)) return null;
75
+ const t = ge(e), r = e.transferSize || e.encodedBodySize || void 0;
76
+ return {
77
+ method: "GET",
78
+ url: I(e.name),
79
+ ...t !== void 0 ? { status: t } : {},
80
+ durationMs: Math.round(e.duration),
81
+ ...r ? { responseSize: r } : {},
82
+ startedAt: he(e.startTime),
83
+ ...t !== void 0 && t >= 400 ? { failed: !0 } : {},
84
+ initiatorType: e.initiatorType
85
+ };
86
+ }
87
+ function ye(e) {
88
+ if (typeof window > "u") return pe;
89
+ const t = [];
90
+ if (typeof PerformanceObserver < "u") try {
91
+ const s = new PerformanceObserver((u) => {
92
+ for (const d of u.getEntries()) try {
93
+ const h = me(d);
94
+ h && e.onResource(h);
95
+ } catch {
96
+ }
97
+ });
98
+ s.observe({
99
+ type: "resource",
100
+ buffered: !0
101
+ }), t.push(() => s.disconnect());
102
+ } catch {
103
+ }
104
+ const r = window.ReportingObserver;
105
+ if (r) try {
106
+ const s = new r(((u) => {
107
+ for (const d of u) {
108
+ const h = typeof d.body?.message == "string" ? d.body.message : d.type;
109
+ e.onReport("warn", `Navigateur (${d.type}) : ${h}`);
110
+ }
111
+ }), {
112
+ types: fe,
113
+ buffered: !0
114
+ });
115
+ s.observe(), t.push(() => s.disconnect());
116
+ } catch {
117
+ }
118
+ const c = (s) => {
119
+ const u = s;
120
+ e.onReport("error", `CSP : ${u.blockedURI || "ressource"} bloqué par « ${u.violatedDirective} »`);
121
+ };
122
+ window.addEventListener("securitypolicyviolation", c), t.push(() => window.removeEventListener("securitypolicyviolation", c));
123
+ let l = !1;
124
+ return { teardown: () => {
125
+ if (!l) {
126
+ l = !0;
127
+ for (const s of t) try {
128
+ s();
129
+ } catch {
130
+ }
131
+ }
132
+ } };
133
+ }
134
+ function x(e) {
135
+ const t = [];
136
+ return {
137
+ push(r) {
138
+ t.push(r), t.length > e && t.shift();
139
+ },
140
+ snapshot() {
141
+ return t.slice();
142
+ }
143
+ };
144
+ }
145
+ var we = 50, ve = 30, Re = 100, Se = 50, N = 500, Ee = 8e3;
146
+ function j(e) {
147
+ const t = e instanceof Error ? e.stack : void 0;
148
+ if (t)
149
+ return b(t).slice(0, Ee);
150
+ }
151
+ function X(e) {
152
+ if (e instanceof Error) return `${e.name}: ${e.message}`;
153
+ if (typeof e == "string") return e;
154
+ if (typeof e == "object" && e !== null) try {
155
+ return JSON.stringify(e, (t, r) => /^(authorization|cookie|set-cookie|token|access_token|refresh_token|password|secret|api[-_]?key)$/i.test(t) ? "[masqué]" : r).slice(0, 500);
156
+ } catch {
157
+ return "[objet]";
158
+ }
159
+ return String(e);
160
+ }
161
+ function V(e) {
162
+ if (!e) return;
163
+ const t = Number(e);
164
+ return Number.isFinite(t) && t >= 0 ? t : void 0;
165
+ }
166
+ var ke = {
167
+ snapshot: () => ({
168
+ errors: [],
169
+ logs: [],
170
+ network: []
171
+ }),
172
+ setSink: () => {
173
+ },
174
+ flushRings: () => {
175
+ },
176
+ teardown: () => {
177
+ }
178
+ };
179
+ function Z(e) {
180
+ if (typeof window > "u") return ke;
181
+ const t = x(we), r = x(ve), c = x(Re), l = x(Se), s = G(e.runId) ? e.runId : void 0, u = (o) => {
182
+ if (!s) return !1;
183
+ try {
184
+ const n = new URL(String(o), location.href);
185
+ return n.origin === location.origin || (e.runIdOrigins ?? []).includes(n.origin);
186
+ } catch {
187
+ return !1;
188
+ }
189
+ };
190
+ let d = e.sink ?? null;
191
+ const h = (o, n) => {
192
+ d?.(o, n);
193
+ }, m = (o) => {
194
+ e.captureNetwork && t.push(o);
195
+ }, w = (o, n, i, a = {}) => {
196
+ if (!n) return;
197
+ const g = {
198
+ level: o,
199
+ message: n,
200
+ ...i ? { stack: i } : {},
201
+ ...a,
202
+ at: Date.now()
203
+ };
204
+ l.push(g), h(W, g);
205
+ }, O = (o, n) => {
206
+ try {
207
+ const i = b(n.map(X).join(" ")).slice(0, N), a = n.find((g) => g instanceof Error);
208
+ w(o, i, j(a), {
209
+ mechanism: "console",
210
+ ...a instanceof Error && a.name ? { name: a.name } : {}
211
+ });
212
+ } catch {
213
+ }
214
+ }, E = (o, n) => {
215
+ try {
216
+ const i = b(n.map(X).join(" ")).slice(0, N);
217
+ i && c.push({
218
+ level: o,
219
+ message: i,
220
+ at: Date.now()
221
+ });
222
+ } catch {
223
+ }
224
+ }, R = console.error, v = console.warn, y = console.log, k = console.info;
225
+ console.error = (...o) => (O("error", o), R.apply(console, o)), console.warn = (...o) => (O("warn", o), v.apply(console, o)), console.log = (...o) => (E("log", o), y.apply(console, o)), console.info = (...o) => (E("info", o), k.apply(console, o));
226
+ const _ = (o) => {
227
+ const n = o.target;
228
+ if (n instanceof Element) {
229
+ const a = n.src || n.href || "";
230
+ if (!a) return;
231
+ w("error", `Ressource non chargée : <${n.tagName.toLowerCase()}> ${I(a)}`.slice(0, N), void 0, {
232
+ mechanism: "resource",
233
+ sourceUrl: I(a)
234
+ });
235
+ return;
236
+ }
237
+ const i = o;
238
+ w("error", b(`Erreur non gérée : ${i.message}`).slice(0, N), j(i.error), {
239
+ mechanism: "window.error",
240
+ ...typeof i.error?.name == "string" ? { name: i.error.name } : {},
241
+ ...typeof i.filename == "string" && i.filename ? { sourceUrl: I(i.filename) } : {},
242
+ ...typeof i.lineno == "number" && i.lineno > 0 ? { line: i.lineno } : {},
243
+ ...typeof i.colno == "number" && i.colno > 0 ? { column: i.colno } : {}
244
+ });
245
+ }, T = (o) => {
246
+ w("error", b(`Promesse rejetée : ${X(o.reason)}`).slice(0, N), j(o.reason), {
247
+ mechanism: "unhandledrejection",
248
+ ...o.reason instanceof Error && o.reason.name ? { name: o.reason.name } : {}
249
+ });
250
+ };
251
+ window.addEventListener("error", _, !0), window.addEventListener("unhandledrejection", T);
252
+ const A = typeof window.fetch == "function" ? window.fetch.bind(window) : null;
253
+ A && (window.fetch = (async (o, n) => {
254
+ const i = Date.now(), a = (n?.method ?? (o instanceof Request ? o.method : "GET") ?? "GET").toUpperCase(), g = I(o);
255
+ let L = n;
256
+ if (s && u(o)) {
257
+ const p = new Headers(o instanceof Request ? o.headers : void 0);
258
+ for (const [f, C] of new Headers(n?.headers)) p.set(f, C);
259
+ p.set(F, s), L = {
260
+ ...n,
261
+ headers: p
262
+ };
263
+ }
264
+ try {
265
+ const p = await A(o, L);
266
+ try {
267
+ const f = p.headers.get("x-request-id"), C = p.headers.get("traceparent");
268
+ m({
269
+ method: a,
270
+ url: g,
271
+ status: p.status,
272
+ durationMs: Date.now() - i,
273
+ responseSize: V(p.headers.get("content-length")),
274
+ contentType: p.headers.get("content-type") ?? void 0,
275
+ startedAt: i,
276
+ ...f ? { requestId: f.slice(0, 200) } : {},
277
+ ...C ? { traceparent: C.slice(0, 200) } : {},
278
+ ...s ? { runId: s } : {}
279
+ }), p.ok || h(B, {
280
+ method: a,
281
+ url: g,
282
+ status: p.status,
283
+ durationMs: Date.now() - i
284
+ });
285
+ } catch {
286
+ }
287
+ return p;
288
+ } catch (p) {
289
+ try {
290
+ const f = Date.now() - i;
291
+ m({
292
+ method: a,
293
+ url: g,
294
+ status: 0,
295
+ durationMs: f,
296
+ startedAt: i,
297
+ failed: !0,
298
+ ...s ? { runId: s } : {}
299
+ }), h(B, {
300
+ method: a,
301
+ url: g,
302
+ status: 0,
303
+ durationMs: f
304
+ });
305
+ } catch {
306
+ }
307
+ throw p;
308
+ }
309
+ }));
310
+ const M = XMLHttpRequest.prototype.open, q = XMLHttpRequest.prototype.send, S = "__echoNet";
311
+ XMLHttpRequest.prototype.open = function(o, n, ...i) {
312
+ return this[S] = {
313
+ method: (o || "GET").toUpperCase(),
314
+ url: I(n),
315
+ start: 0,
316
+ propagate: u(n)
317
+ }, M.apply(this, [
318
+ o,
319
+ n,
320
+ ...i
321
+ ]);
322
+ }, XMLHttpRequest.prototype.send = function(...o) {
323
+ const n = this[S];
324
+ if (n) {
325
+ if (n.start = Date.now(), s && n.propagate) try {
326
+ this.setRequestHeader(F, s);
327
+ } catch {
328
+ }
329
+ this.addEventListener("loadend", () => {
330
+ try {
331
+ const i = Date.now() - n.start, a = this.status, g = a === 0, L = this.getResponseHeader("x-request-id"), p = this.getResponseHeader("traceparent");
332
+ m({
333
+ method: n.method,
334
+ url: n.url,
335
+ status: a,
336
+ durationMs: i,
337
+ responseSize: V(this.getResponseHeader("content-length")),
338
+ contentType: this.getResponseHeader("content-type") ?? void 0,
339
+ startedAt: n.start,
340
+ ...g ? { failed: !0 } : {},
341
+ ...s ? { runId: s } : {},
342
+ ...L ? { requestId: L.slice(0, 200) } : {},
343
+ ...p ? { traceparent: p.slice(0, 200) } : {}
344
+ }), (g || a >= 400) && h(B, {
345
+ method: n.method,
346
+ url: n.url,
347
+ status: a,
348
+ durationMs: i
349
+ });
350
+ } catch {
351
+ }
352
+ }, { once: !0 });
353
+ }
354
+ return q.apply(this, o);
355
+ };
356
+ const D = ye({
357
+ onResource: (o) => {
358
+ e.captureNetwork && r.push(s ? {
359
+ ...o,
360
+ runId: s
361
+ } : o);
362
+ },
363
+ onReport: (o, n) => w(o, b(n).slice(0, N), void 0, { mechanism: "report" })
364
+ }), $ = () => e.captureNetwork ? [...t.snapshot(), ...r.snapshot()].sort((o, n) => o.startedAt - n.startedAt) : [];
365
+ let P = !1;
366
+ return {
367
+ snapshot: () => ({
368
+ errors: l.snapshot(),
369
+ logs: c.snapshot(),
370
+ network: $(),
371
+ ...s ? { runId: s } : {}
372
+ }),
373
+ setSink: (o) => {
374
+ d = o;
375
+ },
376
+ flushRings: () => {
377
+ const o = $();
378
+ o.length > 0 && h(se, { entries: o });
379
+ const n = c.snapshot();
380
+ n.length > 0 && h(ie, { entries: n });
381
+ const i = l.snapshot();
382
+ i.length > 0 && h(W, { entries: i });
383
+ },
384
+ teardown: () => {
385
+ P || (P = !0, d = null, D.teardown(), console.error = R, console.warn = v, console.log = y, console.info = k, window.removeEventListener("error", _, !0), window.removeEventListener("unhandledrejection", T), A && (window.fetch = A), XMLHttpRequest.prototype.open = M, XMLHttpRequest.prototype.send = q);
386
+ }
387
+ };
388
+ }
389
+ var Le = 6e5, be = 1e3, Oe = {
390
+ maskAllInputs: !0,
391
+ maskInputOptions: {
392
+ password: !0,
393
+ email: !0,
394
+ tel: !0,
395
+ text: !0
396
+ },
397
+ blockClass: "leesto-mask",
398
+ blockSelector: "[data-leesto-block]",
399
+ maskTextClass: "leesto-mask-text",
400
+ maskTextSelector: "[data-private]"
401
+ };
402
+ async function _e(e) {
403
+ const { record: t, addCustomEvent: r } = await import("./chunks/rrweb-qwppqH_c.js"), c = Date.now();
404
+ let l = [], s = !1, u = 0;
405
+ const d = () => {
406
+ if (l.length === 0) return;
407
+ const y = l;
408
+ l = [], e.onBatch(y);
409
+ }, h = t({
410
+ emit(y) {
411
+ l.push(y);
412
+ },
413
+ ...Oe
414
+ }), m = e.diagnostics ?? null, w = h ? m ?? Z({ captureNetwork: e.captureNetwork !== !1 }) : null, O = w !== null && m === null;
415
+ w?.setSink((y, k) => {
416
+ try {
417
+ r(y, k);
418
+ } catch {
419
+ }
420
+ });
421
+ const E = setInterval(d, be), R = { timer: null }, v = () => (s || (s = !0, clearInterval(E), clearTimeout(R.timer ?? void 0), w?.flushRings(), w?.setSink(null), O && w?.teardown(), h?.(), d(), u = Date.now() - c), u);
422
+ return R.timer = setTimeout(() => {
423
+ v(), e.onCap();
424
+ }, Le), { stop: v };
425
+ }
426
+ var Ae = ["https://lab.leesto.app", "https://studio-dev.leesto.app"], Ce = ["http://localhost:3505", "http://127.0.0.1:3505"];
427
+ function Ne(e) {
428
+ try {
429
+ const t = new URL(e).hostname;
430
+ return t === "localhost" || t.endsWith(".localhost") || t === "127.0.0.1" || t === "[::1]";
431
+ } catch {
432
+ return !1;
433
+ }
434
+ }
435
+ function Ie(e) {
436
+ const t = e.trim();
437
+ if (!t) return null;
438
+ try {
439
+ const { origin: r } = new URL(t);
440
+ return r === "null" ? null : r;
441
+ } catch {
442
+ return null;
443
+ }
444
+ }
445
+ function Te(e) {
446
+ const t = (e.explicit ?? []).map(Ie).filter((c) => c !== null);
447
+ if (t.length > 0) return [...new Set(t)];
448
+ const r = [...Ae];
449
+ return Ne(e.pageOrigin) && r.push(...Ce), [...new Set(r)];
450
+ }
451
+ function K(e, t) {
452
+ return !e || e === "*" || e === "null" ? !1 : t.includes(e);
453
+ }
454
+ function z() {
455
+ return typeof navigator < "u" && navigator.globalPrivacyControl === !0;
456
+ }
457
+ function Me(e) {
458
+ const t = (u) => {
459
+ const d = typeof u == "string" ? u.trim() : "";
460
+ return d.length > 0 ? d : void 0;
461
+ }, r = (u) => {
462
+ if (!(typeof document > "u"))
463
+ return t(document.querySelector(`meta[name="${u}"]`)?.getAttribute("content"));
464
+ }, c = typeof window < "u" ? window.__LEESTO_APP_BUILD__ : void 0, l = t(e?.version) ?? t(c?.version) ?? r("app-version"), s = t(e?.environment) ?? t(c?.environment) ?? r("app-environment");
465
+ if (!(!l && !s))
466
+ return {
467
+ ...l ? { version: l } : {},
468
+ ...s ? { environment: s } : {}
469
+ };
470
+ }
471
+ function qe() {
472
+ if (typeof document > "u") return;
473
+ const e = document.querySelector('link[rel~="icon"], link[rel="shortcut icon"], link[rel="apple-touch-icon"]');
474
+ if (e?.href)
475
+ try {
476
+ return new URL(e.href, location.href).href;
477
+ } catch {
478
+ return;
479
+ }
480
+ }
481
+ function $e() {
482
+ const e = (c) => !!c && c !== "transparent" && !/^rgba\(\s*0,\s*0,\s*0,\s*0\s*\)$/.test(c), t = getComputedStyle(document.body).backgroundColor;
483
+ if (e(t)) return t;
484
+ const r = getComputedStyle(document.documentElement).backgroundColor;
485
+ return e(r) ? r : "#ffffff";
486
+ }
487
+ async function Pe() {
488
+ const { domToPng: e } = await import("./chunks/dist-BTlWkbvW.js"), t = document.documentElement, r = window.scrollX, c = window.scrollY, l = [];
489
+ for (const s of t.querySelectorAll("*")) {
490
+ const u = getComputedStyle(s).position;
491
+ if (u === "fixed" || u === "sticky") {
492
+ const d = s.style.transform;
493
+ l.push([s, d]), s.style.transform = `translate(${r}px, ${c}px)${d ? ` ${d}` : ""}`;
494
+ }
495
+ }
496
+ try {
497
+ return await e(t, {
498
+ quality: 0.92,
499
+ backgroundColor: $e(),
500
+ width: t.clientWidth,
501
+ height: t.clientHeight,
502
+ style: {
503
+ transform: `translate(${-r}px, ${-c}px)`,
504
+ transformOrigin: "top left"
505
+ }
506
+ });
507
+ } finally {
508
+ for (const [s, u] of l) s.style.transform = u;
509
+ }
510
+ }
511
+ function De(e) {
512
+ if (e.id) return `#${CSS.escape(e.id)}`;
513
+ const t = [];
514
+ let r = e;
515
+ for (; r && r.nodeType === 1 && r !== document.body && t.length < 4; ) {
516
+ if (r.id) {
517
+ t.unshift(`#${CSS.escape(r.id)}`);
518
+ break;
519
+ }
520
+ let c = r.tagName.toLowerCase();
521
+ const l = typeof r.className == "string" ? r.className.trim().split(/\s+/).filter(Boolean)[0] : null;
522
+ l && (c += `.${CSS.escape(l)}`);
523
+ const s = r.parentElement;
524
+ if (s) {
525
+ const u = Array.from(s.children).filter((d) => d.tagName === r?.tagName);
526
+ u.length > 1 && (c += `:nth-of-type(${u.indexOf(r) + 1})`);
527
+ }
528
+ t.unshift(c), r = s;
529
+ }
530
+ return t.join(" > ");
531
+ }
532
+ function He(e) {
533
+ const t = e.tagName.toLowerCase(), r = (e.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 40);
534
+ return r ? `${t} · ${r}` : t;
535
+ }
536
+ function Y(e = {}) {
537
+ if (typeof window > "u" || window.parent === window) return () => {
538
+ };
539
+ const t = window.parent, r = e.highlightColor ?? "#6B8E23", c = Te({
540
+ explicit: e.shellOrigins,
541
+ pageOrigin: location.origin
542
+ });
543
+ let l = null;
544
+ try {
545
+ const n = document.referrer ? new URL(document.referrer).origin : "";
546
+ K(n, c) && (l = n);
547
+ } catch {
548
+ }
549
+ const s = (n) => {
550
+ if (l) {
551
+ t.postMessage(n, l);
552
+ return;
553
+ }
554
+ for (const i of c) t.postMessage(n, i);
555
+ };
556
+ let u = null, d = "";
557
+ const h = () => {
558
+ u && (u.style.outline = d), u = null;
559
+ };
560
+ let m = null;
561
+ const w = () => {
562
+ if (m) return;
563
+ let n = null, i = "";
564
+ const a = (f) => {
565
+ n !== f && (n && (n.style.outline = i), n = f, f && (i = f.style.outline, f.style.outline = `2px dashed ${r}`, f.style.outlineOffset = "1px"));
566
+ }, g = (f) => a(f.target instanceof HTMLElement ? f.target : null), L = (f) => {
567
+ f.preventDefault(), f.stopPropagation();
568
+ const C = f.target, H = C instanceof HTMLElement ? C : null;
569
+ if (m?.(), H) {
570
+ const U = H.getBoundingClientRect();
571
+ s({
572
+ type: "leesto:element-picked",
573
+ selector: De(H),
574
+ label: He(H),
575
+ rect: {
576
+ x: U.x,
577
+ y: U.y,
578
+ width: U.width,
579
+ height: U.height
580
+ }
581
+ });
582
+ }
583
+ }, p = (f) => {
584
+ f.key === "Escape" && (m?.(), s({ type: "leesto:pick-cancelled" }));
585
+ };
586
+ m = () => {
587
+ n && (n.style.outline = i), n = null, document.removeEventListener("mousemove", g, !0), document.removeEventListener("click", L, !0), document.removeEventListener("keydown", p, !0), document.body.style.cursor = "", m = null;
588
+ }, document.body.style.cursor = "crosshair", document.addEventListener("mousemove", g, !0), document.addEventListener("click", L, !0), document.addEventListener("keydown", p, !0);
589
+ }, O = oe(location.search) && !z(), E = O ? re(location.search) ?? ne() : void 0, R = O ? Z({
590
+ captureNetwork: e.captureNetwork !== !1,
591
+ runId: E,
592
+ runIdOrigins: e.runIdOrigins
593
+ }) : null;
594
+ let v = null, y = !1, k = !1;
595
+ const _ = () => {
596
+ if (v) {
597
+ const n = v.stop();
598
+ v = null, s({
599
+ type: "leesto:rec-stopped",
600
+ durationMs: n
601
+ });
602
+ } else y && (k = !0);
603
+ }, T = (n) => {
604
+ if (n.source !== t || !K(n.origin, c) || !J(n.data)) return;
605
+ l || (l = n.origin);
606
+ const i = n.data;
607
+ if (i.type === "leesto:ping") s({ type: "leesto:pong" });
608
+ else if (i.type === "leesto:highlight") {
609
+ if (h(), i.selector) {
610
+ let a = null;
611
+ try {
612
+ a = document.querySelector(i.selector);
613
+ } catch {
614
+ a = null;
615
+ }
616
+ a && (u = a, d = a.style.outline, a.style.outline = `2px solid ${r}`, a.style.outlineOffset = "2px", a.scrollIntoView({
617
+ block: "center",
618
+ behavior: "smooth"
619
+ }));
620
+ }
621
+ } else if (i.type === "leesto:pick-start") w();
622
+ else if (i.type === "leesto:pick-stop") m?.();
623
+ else if (i.type === "leesto:capture-request") (e.capture ?? Pe)().then((a) => s({
624
+ type: "leesto:screenshot",
625
+ dataUrl: a
626
+ })).catch((a) => s({
627
+ type: "leesto:capture-failed",
628
+ reason: a instanceof Error ? a.message : "capture_error"
629
+ }));
630
+ else if (i.type === "leesto:rec-start") {
631
+ if (v || y) return;
632
+ if (z()) {
633
+ s({
634
+ type: "leesto:rec-blocked",
635
+ reason: "gpc"
636
+ });
637
+ return;
638
+ }
639
+ y = !0, k = !1, _e({
640
+ onBatch: (a) => s({
641
+ type: "leesto:rec-batch",
642
+ events: a
643
+ }),
644
+ onCap: () => _(),
645
+ captureNetwork: e.captureNetwork,
646
+ diagnostics: R
647
+ }).then((a) => {
648
+ y = !1, v = a, k && _();
649
+ }).catch((a) => {
650
+ y = !1, s({
651
+ type: "leesto:rec-error",
652
+ reason: a instanceof Error ? a.message : "rec_error"
653
+ });
654
+ });
655
+ } else i.type === "leesto:rec-stop" ? _() : i.type === "leesto:diagnostics-request" && s({
656
+ type: "leesto:diagnostics",
657
+ snapshot: R?.snapshot() ?? {
658
+ errors: [],
659
+ logs: [],
660
+ network: []
661
+ }
662
+ });
663
+ };
664
+ window.addEventListener("message", T);
665
+ const A = Me(e.build), M = qe();
666
+ s({
667
+ type: "leesto:ready",
668
+ url: location.href,
669
+ bridgeVersion: 1,
670
+ ...M ? { favicon: M } : {},
671
+ ...A ? { build: A } : {},
672
+ ...E ? { diagnosticRunId: E } : {},
673
+ ...z() ? { gpc: !0 } : {}
674
+ });
675
+ let q = location.href;
676
+ const S = () => {
677
+ location.href !== q && (q = location.href, s({
678
+ type: "leesto:location",
679
+ url: location.href
680
+ }));
681
+ }, D = history.pushState, $ = history.replaceState, P = (...n) => {
682
+ D.apply(history, n), S();
683
+ }, o = (...n) => {
684
+ $.apply(history, n), S();
685
+ };
686
+ return history.pushState = P, history.replaceState = o, window.addEventListener("popstate", S), window.addEventListener("hashchange", S), () => {
687
+ _(), R?.teardown(), h(), m?.(), window.removeEventListener("message", T), window.removeEventListener("popstate", S), window.removeEventListener("hashchange", S), history.pushState === P && (history.pushState = D), history.replaceState === o && (history.replaceState = $);
688
+ };
689
+ }
690
+ function Ue() {
691
+ return typeof document > "u" ? null : document.currentScript ?? document.querySelector("script[data-leesto-connect]");
692
+ }
693
+ function xe(e) {
694
+ const t = {}, r = e?.dataset.highlightColor;
695
+ r && (t.highlightColor = r);
696
+ const c = (e?.dataset.shellOrigin ?? "").split(",").map((l) => l.trim()).filter(Boolean);
697
+ return c.length > 0 && (t.shellOrigins = c), t;
698
+ }
699
+ if (typeof window < "u") {
700
+ window.LeestoConnect = { connect: (t) => Y(t) };
701
+ const e = Ue();
702
+ (!e || e.dataset.leestoManual === void 0) && Y(xe(e));
703
+ }
704
+
705
+ //# sourceMappingURL=leesto-connect.js.map