@getpinax/widget 1.0.0-beta.1 → 1.0.0-beta.2

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/dist/pinax.mjs CHANGED
@@ -1,19 +1,20 @@
1
- import { n as e, t } from "./chunks/text-8QYEyRYs.mjs";
2
- import { a as n, c as r, i, l as a, o, s, t as c, u as l } from "./chunks/widget-CkR1Ptzb.mjs";
3
- function u(e) {
1
+ import { a as e, c as t, d as n, i as r, l as i, o as a, s as o, t as s, u as c } from "./chunks/widget-BpTBdX2R.mjs";
2
+ import { a as l, i as u, n as d, r as f } from "./chunks/text-D9SaDBT0.mjs";
3
+ import { o as p } from "./chunks/privacy-B_b1_Y1n.mjs";
4
+ function m(e) {
4
5
  return (e || "https://api.getpinax.com").replace(/\/+$/, "");
5
6
  }
6
- function d(e, t) {
7
+ function h(e, t) {
7
8
  let n = e ?? (t ? "" : "https://cdn.getpinax.com");
8
9
  return n ? n.replace(/\/+$/, "") : null;
9
10
  }
10
- function f(e, t) {
11
+ function g(e, t) {
11
12
  return `${e}/config/${encodeURIComponent(t)}.json`;
12
13
  }
13
- function p(e, t, n) {
14
+ function _(e, t, n) {
14
15
  return `${e}/v1/widget/${encodeURIComponent(t)}/${n}`;
15
16
  }
16
- async function m(e, t) {
17
+ async function v(e, t) {
17
18
  let n = await e(t, { credentials: "omit" });
18
19
  if (!n.ok) return {
19
20
  status: n.status,
@@ -27,19 +28,19 @@ async function m(e, t) {
27
28
  }
28
29
  async function ee(e, t, n, r = null) {
29
30
  if (r) try {
30
- let { config: t } = await m(e, f(r, n));
31
+ let { config: t } = await v(e, g(r, n));
31
32
  if (t) return t;
32
33
  } catch {}
33
- return (await m(e, p(t, n, "config"))).config;
34
+ return (await v(e, _(t, n, "config"))).config;
34
35
  }
35
- function te(t, n, r, i) {
36
+ function te(e, t, r, i) {
36
37
  try {
37
38
  if (!new URL(i).searchParams.has("pinax_verify")) return;
38
- t(p(n, r, "ping"), {
39
+ e(_(t, r, "ping"), {
39
40
  method: "POST",
40
41
  credentials: "omit",
41
42
  headers: { "Content-Type": "application/json" },
42
- body: JSON.stringify({ url: e(i) })
43
+ body: JSON.stringify({ url: n(i) })
43
44
  }).catch(() => {});
44
45
  } catch {}
45
46
  }
@@ -49,10 +50,10 @@ var ne = {
49
50
  413: "That screenshot is too big to send. Remove it and try again.",
50
51
  429: "Too many reports from this device. Please try again in a few minutes."
51
52
  };
52
- async function re(e, t, n, r) {
53
+ async function y(e, t, n, r) {
53
54
  let i;
54
55
  try {
55
- i = await e(p(t, n, "reports"), {
56
+ i = await e(_(t, n, "reports"), {
56
57
  method: "POST",
57
58
  credentials: "omit",
58
59
  headers: { "Content-Type": "application/json" },
@@ -82,15 +83,15 @@ async function re(e, t, n, r) {
82
83
  message: ne[o] ?? (o === 400 && a?.message ? a.message : "Something went wrong. Please try again.")
83
84
  };
84
85
  }
85
- var ie = 4e3;
86
- async function ae(e, t, n, r, i = ie) {
86
+ var re = 4e3;
87
+ async function ie(e, t, n, r, i = re) {
87
88
  let a = typeof AbortController == "function" ? new AbortController() : null, o, s = new Promise((e) => {
88
89
  o = setTimeout(() => {
89
90
  a?.abort(), e(null);
90
91
  }, i);
91
92
  }), c = (async () => {
92
93
  try {
93
- let i = await e(p(t, n, "follow-up"), {
94
+ let i = await e(_(t, n, "follow-up"), {
94
95
  method: "POST",
95
96
  credentials: "omit",
96
97
  headers: { "Content-Type": "application/json" },
@@ -114,21 +115,50 @@ async function ae(e, t, n, r, i = ie) {
114
115
  clearTimeout(o);
115
116
  }
116
117
  }
117
- function oe(e, t, n, r) {
118
+ function b(e, t, n, r, i = "fix-check") {
118
119
  try {
119
- e(p(t, n, "fix-check"), {
120
+ e(_(t, n, i), {
120
121
  method: "POST",
121
122
  credentials: "omit",
122
123
  keepalive: !0,
123
124
  headers: { "Content-Type": "application/json" },
124
125
  body: JSON.stringify({
125
126
  checkId: r.checkId.slice(0, 64),
126
- signature: r.signature.slice(0, 300)
127
+ signature: r.signature.slice(0, 300),
128
+ ...i === "sighting" && r.basket ? { basket: r.basket } : {},
129
+ ...r.consent ? { consent: !0 } : {}
127
130
  })
128
131
  }).catch(() => {});
129
132
  } catch {}
130
133
  }
131
- var h = "input,textarea,select,[contenteditable]:not([contenteditable=false]),[data-pinax-mask],.pinax-mask", g = "[data-pinax-mask],.pinax-mask", _ = "a[href],button,input,select,textarea,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=radio],[role=switch],[role=option],[contenteditable]:not([contenteditable=false])", se = {
134
+ function ae(e, t, n) {
135
+ return n ? `${n}/count/${encodeURIComponent(t)}` : _(e, t, "count");
136
+ }
137
+ function oe(e, t, n, r) {
138
+ try {
139
+ e(ae(t, n, r), {
140
+ method: "POST",
141
+ credentials: "omit",
142
+ keepalive: !0
143
+ }).catch(() => {});
144
+ } catch {}
145
+ }
146
+ async function se(e, t, n) {
147
+ try {
148
+ return (await e(t, {
149
+ method: "POST",
150
+ credentials: "omit",
151
+ headers: { "Content-Type": "application/json" },
152
+ body: JSON.stringify(n)
153
+ })).ok;
154
+ } catch {
155
+ return !1;
156
+ }
157
+ }
158
+ function ce(e, t, n, r, i) {
159
+ return se(e, _(t, n, `known/${encodeURIComponent(r)}/me-too`), i ? { email: i.trim().slice(0, 254) } : {});
160
+ }
161
+ var le = "input,textarea,select,[contenteditable]:not([contenteditable=false]),[data-pinax-mask],.pinax-mask", ue = "[data-pinax-mask],.pinax-mask", de = "a[href],button,input,select,textarea,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=checkbox],[role=radio],[role=switch],[role=option],[contenteditable]:not([contenteditable=false])", fe = {
132
162
  button: "button",
133
163
  submit: "button",
134
164
  reset: "button",
@@ -138,27 +168,27 @@ var h = "input,textarea,select,[contenteditable]:not([contenteditable=false]),[d
138
168
  range: "slider",
139
169
  search: "searchbox"
140
170
  };
141
- function v(e, t) {
171
+ function x(e, t) {
142
172
  try {
143
173
  return e.matches(t);
144
174
  } catch {
145
175
  return !1;
146
176
  }
147
177
  }
148
- function y(e, t) {
178
+ function S(e, t) {
149
179
  try {
150
180
  return e.closest(t);
151
181
  } catch {
152
182
  return null;
153
183
  }
154
184
  }
155
- var b = (e) => e.replace(/\s+/g, " ").trim();
156
- function ce(e) {
185
+ var C = (e) => e.replace(/\s+/g, " ").trim();
186
+ function pe(e) {
157
187
  if (e.tagName !== "INPUT") return !1;
158
188
  let t = e, n = (t.getAttribute("autocomplete") ?? "").toLowerCase(), r = `${t.name} ${t.id}`.toLowerCase();
159
189
  return t.type === "password" || n.includes("cc-") || n.includes("password") || /\b(card|cc|cvc|cvv|iban)/.test(r);
160
190
  }
161
- function x(e) {
191
+ function w(e) {
162
192
  let t = e.getAttribute("role")?.trim().split(/\s+/)[0];
163
193
  if (t) return t;
164
194
  let n = e.tagName.toLowerCase();
@@ -166,7 +196,7 @@ function x(e) {
166
196
  case "a": return e.hasAttribute("href") ? "link" : "text";
167
197
  case "button":
168
198
  case "summary": return "button";
169
- case "input": return se[e.type?.toLowerCase()] ?? "textbox";
199
+ case "input": return fe[e.type?.toLowerCase()] ?? "textbox";
170
200
  case "textarea": return "textbox";
171
201
  case "select": return "combobox";
172
202
  case "img": return "image";
@@ -176,11 +206,11 @@ function x(e) {
176
206
  case "h4":
177
207
  case "h5":
178
208
  case "h6": return "heading";
179
- default: return v(e, "[contenteditable]:not([contenteditable=false])") ? "textbox" : n;
209
+ default: return x(e, "[contenteditable]:not([contenteditable=false])") ? "textbox" : n;
180
210
  }
181
211
  }
182
- function S(e, t = 120) {
183
- if (v(e, h) || y(e, g)) return "";
212
+ function T(e, t = 120) {
213
+ if (x(e, le) || S(e, ue)) return "";
184
214
  let n = "", r = (e) => {
185
215
  if (n.length > t) return;
186
216
  if (e.nodeType === 3) {
@@ -189,7 +219,7 @@ function S(e, t = 120) {
189
219
  }
190
220
  if (e.nodeType !== 1) return;
191
221
  let i = e, a = i.tagName;
192
- if (a !== "SCRIPT" && a !== "STYLE" && a !== "TEMPLATE" && !v(i, h) && i.getAttribute("aria-hidden") !== "true") {
222
+ if (a !== "SCRIPT" && a !== "STYLE" && a !== "TEMPLATE" && !x(i, le) && i.getAttribute("aria-hidden") !== "true") {
193
223
  if (a === "IMG") n += ` ${i.getAttribute("alt") ?? ""} `;
194
224
  else {
195
225
  for (let e of i.childNodes) r(e);
@@ -198,51 +228,51 @@ function S(e, t = 120) {
198
228
  }
199
229
  };
200
230
  for (let t of e.childNodes) r(t);
201
- return b(n);
231
+ return C(n);
202
232
  }
203
- function le(e) {
233
+ function me(e) {
204
234
  let t = e.getAttribute("aria-labelledby");
205
235
  if (!t) return "";
206
236
  let n = e.ownerDocument;
207
- return b(t.split(/\s+/).map((e) => {
237
+ return C(t.split(/\s+/).map((e) => {
208
238
  let t = n.getElementById(e);
209
- return t ? S(t) : "";
239
+ return t ? T(t) : "";
210
240
  }).join(" "));
211
241
  }
212
- function ue(e) {
242
+ function he(e) {
213
243
  let t = e;
214
- return b((t.labels ? [...t.labels] : []).map((e) => S(e)).join(" ")) || b(t.getAttribute("placeholder") ?? "") || b(t.getAttribute("title") ?? "") || b(t.getAttribute("name") ?? "");
244
+ return C((t.labels ? [...t.labels] : []).map((e) => T(e)).join(" ")) || C(t.getAttribute("placeholder") ?? "") || C(t.getAttribute("title") ?? "") || C(t.getAttribute("name") ?? "");
215
245
  }
216
- function de(e) {
217
- if (y(e, g)) return "";
218
- let t = b(e.getAttribute("aria-label") ?? "");
246
+ function ge(e) {
247
+ if (S(e, ue)) return "";
248
+ let t = C(e.getAttribute("aria-label") ?? "");
219
249
  if (t) return t;
220
- let n = le(e);
250
+ let n = me(e);
221
251
  if (n) return n;
222
252
  let r = e.tagName;
223
253
  if (r === "INPUT") {
224
254
  let t = e.type?.toLowerCase();
225
- return t === "submit" || t === "button" || t === "reset" ? b(e.getAttribute("value") ?? "") : t === "image" ? b(e.getAttribute("alt") ?? "") : ue(e);
255
+ return t === "submit" || t === "button" || t === "reset" ? C(e.getAttribute("value") ?? "") : t === "image" ? C(e.getAttribute("alt") ?? "") : he(e);
226
256
  }
227
- return r === "TEXTAREA" || r === "SELECT" ? ue(e) : v(e, "[contenteditable]:not([contenteditable=false])") ? b(e.getAttribute("title") ?? "") : r === "IMG" ? b(e.getAttribute("alt") ?? "") : S(e) || b(e.getAttribute("title") ?? "");
257
+ return r === "TEXTAREA" || r === "SELECT" ? he(e) : x(e, "[contenteditable]:not([contenteditable=false])") ? C(e.getAttribute("title") ?? "") : r === "IMG" ? C(e.getAttribute("alt") ?? "") : T(e) || C(e.getAttribute("title") ?? "");
228
258
  }
229
- function fe(e) {
230
- let n = y(e, _);
231
- if (!n) return t(x(e), 200);
232
- let r = n;
233
- if (ce(r)) return r.type === "password" ? "password field" : "card field";
234
- let i = x(r), a = t(de(r), 60).replace(/"/g, "'");
235
- return t(a ? `${i} "${a}"` : i, 200);
259
+ function _e(e) {
260
+ let t = S(e, de);
261
+ if (!t) return d(w(e), 200);
262
+ let n = t;
263
+ if (pe(n)) return n.type === "password" ? "password field" : "card field";
264
+ let r = w(n), i = d(ge(n), 60).replace(/"/g, "'");
265
+ return d(i ? `${r} "${i}"` : r, 200);
236
266
  }
237
- function C(n = location.href) {
267
+ function E(e = location.href) {
238
268
  try {
239
- let r = new URL(e(n));
240
- return t(`${r.pathname}${r.search}`, 500);
269
+ let t = new URL(l(e));
270
+ return d(u(`${t.pathname}${t.search}`), 500);
241
271
  } catch {
242
272
  return "/";
243
273
  }
244
274
  }
245
- function pe(e, t = {}) {
275
+ function ve(e, t = {}) {
246
276
  let n = t.doc ?? document, r = t.ignore ?? (() => !1), i = "", a = null, o = (t) => {
247
277
  try {
248
278
  e.push(t);
@@ -259,8 +289,8 @@ function pe(e, t = {}) {
259
289
  a = null, o({
260
290
  kind: "click",
261
291
  at: (/* @__PURE__ */ new Date()).toISOString(),
262
- path: C(),
263
- target: fe(t)
292
+ path: E(),
293
+ target: _e(t)
264
294
  });
265
295
  } catch {}
266
296
  }, l = (e) => {
@@ -268,23 +298,23 @@ function pe(e, t = {}) {
268
298
  if (r(e.target)) return;
269
299
  let t = s(e.target);
270
300
  if (!t) return;
271
- let n = y(t, _) ?? t;
301
+ let n = S(t, de) ?? t;
272
302
  if (n.tagName === "INPUT" && /^(checkbox|radio)$/i.test(n.type) || n === a) return;
273
303
  a = n, o({
274
304
  kind: "input",
275
305
  at: (/* @__PURE__ */ new Date()).toISOString(),
276
- path: C(),
277
- target: fe(n)
306
+ path: E(),
307
+ target: _e(n)
278
308
  });
279
309
  } catch {}
280
310
  }, u = () => {
281
311
  try {
282
- let e = C();
312
+ let e = location.pathname + location.search;
283
313
  if (e === i) return;
284
314
  i = e, a = null, o({
285
315
  kind: "navigation",
286
316
  at: (/* @__PURE__ */ new Date()).toISOString(),
287
- path: e
317
+ path: E()
288
318
  });
289
319
  } catch {}
290
320
  };
@@ -296,120 +326,120 @@ function pe(e, t = {}) {
296
326
  };
297
327
  }
298
328
  // src/capture/console.ts
299
- var me = [
329
+ var ye = [
300
330
  "error",
301
331
  "warn",
302
332
  "log",
303
333
  "info",
304
334
  "debug"
305
- ], w = 2e3, T = 4e3;
306
- function E(e, n = 0) {
335
+ ], D = 2e3, O = 4e3;
336
+ function be(e, t = 0) {
307
337
  if (typeof e == "string") return e;
308
338
  if (e instanceof Error) return `${e.name}: ${e.message}`;
309
339
  if (e == null) return String(e);
310
340
  if (typeof e == "function") return `[function ${e.name || ""}]`;
311
341
  if (typeof e != "object") return String(e);
312
342
  if (typeof Node < "u" && e instanceof Node) return `[${e.nodeName.toLowerCase()}]`;
313
- if (n > 0) return Array.isArray(e) ? "[…]" : "{…}";
343
+ if (t > 0) return Array.isArray(e) ? "[…]" : "{…}";
314
344
  try {
315
- let n = /* @__PURE__ */ new WeakSet(), r = JSON.stringify(e, (e, t) => {
316
- if (t && typeof t == "object") {
317
- if (n.has(t)) return "[circular]";
318
- n.add(t);
345
+ let t = /* @__PURE__ */ new WeakSet(), n = JSON.stringify(e, (e, n) => {
346
+ if (n && typeof n == "object") {
347
+ if (t.has(n)) return "[circular]";
348
+ t.add(n);
319
349
  }
320
- return t;
350
+ return n;
321
351
  });
322
- return t(r ?? String(e), w);
352
+ return d(n ?? String(e), D);
323
353
  } catch {
324
354
  return Object.prototype.toString.call(e);
325
355
  }
326
356
  }
327
- function he(e) {
328
- return t(e.map((e) => E(e)).join(" "), w);
357
+ function xe(e) {
358
+ return d(e.map((e) => be(e)).join(" "), D);
329
359
  }
330
- function ge(e) {
331
- let n = e.find((e) => e instanceof Error);
332
- return n?.stack ? t(n.stack, T) : void 0;
360
+ function Se(e) {
361
+ let t = e.find((e) => e instanceof Error);
362
+ return t?.stack ? d(t.stack, O) : void 0;
333
363
  }
334
- function _e() {
364
+ function Ce() {
335
365
  let e = (/* @__PURE__ */ Error()).stack;
336
366
  if (!e) return;
337
- let n = e.split("\n"), r = n[0].startsWith("Error") ? 3 : 2, i = n.slice(r).join("\n");
338
- return i ? t(i, T) : void 0;
367
+ let t = e.split("\n"), n = t[0].startsWith("Error") ? 3 : 2, r = t.slice(n).join("\n");
368
+ return r ? d(r, O) : void 0;
339
369
  }
340
- function ve(e, n = window) {
341
- let r = n.console, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = !1, s = (t) => {
370
+ function we(e, t = window) {
371
+ let n = t.console, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = !1, o = (t) => {
342
372
  try {
343
373
  e.push(t);
344
374
  } catch {}
345
375
  };
346
- for (let e of me) {
347
- let t = r?.[e];
376
+ for (let e of ye) {
377
+ let t = n?.[e];
348
378
  if (typeof t != "function") continue;
349
- let n = function(...n) {
350
- if (!o) {
351
- o = !0;
379
+ let s = function(...n) {
380
+ if (!a) {
381
+ a = !0;
352
382
  try {
353
- s({
383
+ o({
354
384
  level: e,
355
- message: he(n),
356
- stack: ge(n) ?? (e === "error" || e === "warn" ? _e() : void 0),
385
+ message: xe(n),
386
+ stack: Se(n) ?? (e === "error" || e === "warn" ? Ce() : void 0),
357
387
  at: (/* @__PURE__ */ new Date()).toISOString()
358
388
  });
359
389
  } catch {} finally {
360
- o = !1;
390
+ a = !1;
361
391
  }
362
392
  }
363
393
  return t.apply(this, n);
364
394
  };
365
- n.__pinaxOriginal = t, i.set(e, t), a.set(e, n);
395
+ s.__pinaxOriginal = t, r.set(e, t), i.set(e, s);
366
396
  try {
367
- r[e] = n;
397
+ n[e] = s;
368
398
  } catch {}
369
399
  }
370
- let c = (e) => {
400
+ let s = (e) => {
371
401
  try {
372
402
  if (!e.message && !e.error) return;
373
- let n = e.error, r = e.filename ? ` (${e.filename}:${e.lineno}:${e.colno})` : "";
374
- s({
403
+ let t = e.error, n = e.filename ? ` (${e.filename}:${e.lineno}:${e.colno})` : "";
404
+ o({
375
405
  level: "error",
376
- message: t(`Uncaught ${n?.name ? `${n.name}: ${n.message}` : e.message}${r}`, w),
377
- stack: n?.stack ? t(n.stack, T) : void 0,
406
+ message: d(`Uncaught ${t?.name ? `${t.name}: ${t.message}` : e.message}${n}`, D),
407
+ stack: t?.stack ? d(t.stack, O) : void 0,
378
408
  at: (/* @__PURE__ */ new Date()).toISOString()
379
409
  });
380
410
  } catch {}
381
- }, l = (e) => {
411
+ }, c = (e) => {
382
412
  try {
383
- let n = e.reason;
384
- s({
413
+ let t = e.reason;
414
+ o({
385
415
  level: "error",
386
- message: t(`Unhandled promise rejection: ${E(n)}`, w),
387
- stack: n instanceof Error && n.stack ? t(n.stack, T) : void 0,
416
+ message: d(`Unhandled promise rejection: ${be(t)}`, D),
417
+ stack: t instanceof Error && t.stack ? d(t.stack, O) : void 0,
388
418
  at: (/* @__PURE__ */ new Date()).toISOString()
389
419
  });
390
420
  } catch {}
391
421
  };
392
- return n.addEventListener("error", c), n.addEventListener("unhandledrejection", l), () => {
393
- n.removeEventListener("error", c), n.removeEventListener("unhandledrejection", l);
394
- for (let [e, t] of i) try {
395
- r[e] === a.get(e) && (r[e] = t);
422
+ return t.addEventListener("error", s), t.addEventListener("unhandledrejection", c), () => {
423
+ t.removeEventListener("error", s), t.removeEventListener("unhandledrejection", c);
424
+ for (let [e, t] of r) try {
425
+ n[e] === i.get(e) && (n[e] = t);
396
426
  } catch {}
397
427
  };
398
428
  }
399
429
  // src/capture/ua.ts
400
- var D = {
430
+ var Te = {
401
431
  "10.0": "10/11",
402
432
  "6.3": "8.1",
403
433
  "6.2": "8",
404
434
  "6.1": "7"
405
435
  };
406
- function O(e, t) {
436
+ function k(e, t) {
407
437
  return t.exec(e)?.[1];
408
438
  }
409
- function k(e) {
439
+ function A(e) {
410
440
  if (e) return e.replace(/_/g, ".").split(".").slice(0, 2).join(".");
411
441
  }
412
- function ye(e, t = 0) {
442
+ function Ee(e, t = 0) {
413
443
  let n = { deviceType: "desktop" };
414
444
  for (let [t, r] of [
415
445
  ["Edge", /Edg(?:e|A|iOS)?\/([\d.]+)/],
@@ -419,139 +449,139 @@ function ye(e, t = 0) {
419
449
  ["Chrome", /(?:Chrome|CriOS)\/([\d.]+)/],
420
450
  ["Safari", /Version\/([\d.]+).*Safari\//]
421
451
  ]) {
422
- let i = O(e, r);
452
+ let i = k(e, r);
423
453
  if (i) {
424
- n.browser = t, n.browserVersion = k(i);
454
+ n.browser = t, n.browserVersion = A(i);
425
455
  break;
426
456
  }
427
457
  }
428
458
  !n.browser && /AppleWebKit/.test(e) && /Mobile\//.test(e) && (n.browser = "Safari (in-app)");
429
459
  let r = /iPad/.test(e) || /Macintosh/.test(e) && t > 1;
430
- if (/iPhone|iPod/.test(e)) n.os = `iOS ${k(O(e, /OS ([\d_]+) like Mac/)) ?? ""}`.trim(), n.deviceType = "mobile", n.deviceModel = /iPod/.test(e) ? "iPod" : "iPhone";
460
+ if (/iPhone|iPod/.test(e)) n.os = `iOS ${A(k(e, /OS ([\d_]+) like Mac/)) ?? ""}`.trim(), n.deviceType = "mobile", n.deviceModel = /iPod/.test(e) ? "iPod" : "iPhone";
431
461
  else if (r) {
432
- let t = k(O(e, /OS ([\d_]+) like Mac/));
462
+ let t = A(k(e, /OS ([\d_]+) like Mac/));
433
463
  n.os = t ? `iPadOS ${t}` : "iPadOS", n.deviceType = "tablet", n.deviceModel = "iPad";
434
464
  } else if (/Android/.test(e)) {
435
- n.os = `Android ${O(e, /Android ([\d.]+)/) ?? ""}`.trim(), n.deviceType = /Mobile/.test(e) ? "mobile" : "tablet";
436
- let t = O(e, /Android [\d.]+;(?: [a-z]{2}[-_][a-z]{2};)? ([^;)]+?)(?: Build\/[^;)]*)?\)/i);
465
+ n.os = `Android ${k(e, /Android ([\d.]+)/) ?? ""}`.trim(), n.deviceType = /Mobile/.test(e) ? "mobile" : "tablet";
466
+ let t = k(e, /Android [\d.]+;(?: [a-z]{2}[-_][a-z]{2};)? ([^;)]+?)(?: Build\/[^;)]*)?\)/i);
437
467
  t && t !== "K" && !/^wv$/.test(t) && (n.deviceModel = t.trim());
438
468
  } else if (/CrOS/.test(e)) n.os = "ChromeOS";
439
469
  else if (/Windows NT/.test(e)) {
440
- let t = O(e, /Windows NT ([\d.]+)/);
441
- n.os = t && D[t] ? `Windows ${D[t]}` : "Windows";
442
- } else /Mac OS X/.test(e) ? n.os = `macOS ${k(O(e, /Mac OS X ([\d_.]+)/)) ?? ""}`.trim() : /Linux/.test(e) && (n.os = "Linux");
470
+ let t = k(e, /Windows NT ([\d.]+)/);
471
+ n.os = t && Te[t] ? `Windows ${Te[t]}` : "Windows";
472
+ } else /Mac OS X/.test(e) ? n.os = `macOS ${A(k(e, /Mac OS X ([\d_.]+)/)) ?? ""}`.trim() : /Linux/.test(e) && (n.os = "Linux");
443
473
  return n.deviceType === "desktop" && /Mobi|Tablet|Kindle|Silk/.test(e) && (n.deviceType = /Tablet|Kindle|Silk/.test(e) ? "tablet" : "mobile"), n;
444
474
  }
445
475
  // src/capture/env.ts
446
- var A = (e) => typeof e == "number" && Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
447
- function be(e = /* @__PURE__ */ new Date()) {
476
+ var j = (e) => typeof e == "number" && Number.isFinite(e) ? Math.max(0, Math.round(e)) : 0;
477
+ function De(e = /* @__PURE__ */ new Date()) {
448
478
  let t = (e, t = 2) => String(Math.abs(e)).padStart(t, "0"), n = -e.getTimezoneOffset(), r = n >= 0 ? "+" : "-";
449
479
  return `${e.getFullYear()}-${t(e.getMonth() + 1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}.${t(e.getMilliseconds(), 3)}${r}${t(Math.trunc(n / 60))}:${t(n % 60)}`;
450
480
  }
451
- function xe(e = window) {
452
- let n = e.navigator, r = n?.userAgent ?? "", i = ye(r, n?.maxTouchPoints ?? 0), a = "UTC";
481
+ function Oe(e = window) {
482
+ let t = e.navigator, n = t?.userAgent ?? "", r = Ee(n, t?.maxTouchPoints ?? 0), i = "UTC";
453
483
  try {
454
- a = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
484
+ i = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
455
485
  } catch {}
456
- let o = (e, n) => e ? t(e, n) : void 0;
486
+ let a = (e, t) => e ? d(e, t) : void 0;
457
487
  return {
458
- userAgent: t(r, 1e3),
459
- browser: o(i.browser, 100),
460
- browserVersion: o(i.browserVersion, 50),
461
- os: o(i.os, 100),
462
- deviceType: i.deviceType,
463
- deviceModel: o(i.deviceModel, 100),
488
+ userAgent: d(n, 1e3),
489
+ browser: a(r.browser, 100),
490
+ browserVersion: a(r.browserVersion, 50),
491
+ os: a(r.os, 100),
492
+ deviceType: r.deviceType,
493
+ deviceModel: a(r.deviceModel, 100),
464
494
  screen: {
465
- w: A(e.screen?.width),
466
- h: A(e.screen?.height)
495
+ w: j(e.screen?.width),
496
+ h: j(e.screen?.height)
467
497
  },
468
498
  viewport: {
469
- w: A(e.innerWidth),
470
- h: A(e.innerHeight)
499
+ w: j(e.innerWidth),
500
+ h: j(e.innerHeight)
471
501
  },
472
502
  pixelRatio: Math.min(10, Math.max(0, e.devicePixelRatio || 1)),
473
- timeZone: t(a, 100),
474
- language: o(n?.language, 35),
475
- occurredAt: be()
503
+ timeZone: d(i, 100),
504
+ language: a(t?.language, 35),
505
+ occurredAt: De()
476
506
  };
477
507
  }
478
- function Se(e, t) {
508
+ function ke(e, t) {
479
509
  return e === 0 || e >= 400 || t > 2e3;
480
510
  }
481
- function Ce(n, r = window, i = {}) {
482
- let a = i.now ?? (() => typeof performance < "u" ? performance.now() : Date.now()), o = r.location?.href, s = i.ignore ?? (() => !1), c = (r, i, c, l, u) => {
511
+ function Ae(e, t = window, n = {}) {
512
+ let r = n.now ?? (() => typeof performance < "u" ? performance.now() : Date.now()), i = t.location?.href, a = n.ignore ?? (() => !1), o = (t, n, o, s, c) => {
483
513
  try {
484
- let d = Math.max(0, Math.round(a() - l));
485
- if (!Se(c, d)) return;
486
- let f = e(i, o);
487
- if (s(f)) return;
488
- n.push({
489
- method: t(r.toUpperCase(), 10),
490
- url: t(f, 2e3),
491
- status: Math.min(999, Math.max(0, c | 0)),
492
- durationMs: Math.min(6e5, d),
493
- at: u
514
+ let l = Math.max(0, Math.round(r() - s));
515
+ if (!ke(o, l)) return;
516
+ let u = f(n, i);
517
+ if (a(u)) return;
518
+ e.push({
519
+ method: d(t.toUpperCase(), 10),
520
+ url: d(u, 2e3),
521
+ status: Math.min(999, Math.max(0, o | 0)),
522
+ durationMs: Math.min(6e5, l),
523
+ at: c
494
524
  });
495
525
  } catch {}
496
- }, l = [], u = r.fetch;
497
- if (typeof u == "function") {
498
- let e = (e, t) => {
499
- let n = "GET", i = "", o = a(), s = (/* @__PURE__ */ new Date()).toISOString();
526
+ }, s = [], c = t.fetch;
527
+ if (typeof c == "function") {
528
+ let e = (e, n) => {
529
+ let i = "GET", a = "", s = r(), l = (/* @__PURE__ */ new Date()).toISOString();
500
530
  try {
501
- typeof e == "string" ? i = e : e instanceof URL ? i = e.href : e && typeof e.url == "string" && (i = e.url, n = e.method || n), t?.method && (n = t.method);
531
+ typeof e == "string" ? a = e : e instanceof URL ? a = e.href : e && typeof e.url == "string" && (a = e.url, i = e.method || i), n?.method && (i = n.method);
502
532
  } catch {}
503
- let l = u.call(r, e, t);
533
+ let u = c.call(t, e, n);
504
534
  try {
505
- l.then((e) => c(n, i, e?.status ?? 0, o, s), () => c(n, i, 0, o, s));
535
+ u.then((e) => o(i, a, e?.status ?? 0, s, l), () => o(i, a, 0, s, l));
506
536
  } catch {}
507
- return l;
537
+ return u;
508
538
  };
509
539
  try {
510
- r.fetch = e, l.push(() => {
511
- r.fetch === e && (r.fetch = u);
540
+ t.fetch = e, s.push(() => {
541
+ t.fetch === e && (t.fetch = c);
512
542
  });
513
543
  } catch {}
514
544
  }
515
- let d = r.XMLHttpRequest;
516
- if (d?.prototype) {
517
- let e = d.prototype, t = e.open, n = e.send, r = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakSet(), s = function(e, n, ...i) {
545
+ let l = t.XMLHttpRequest;
546
+ if (l?.prototype) {
547
+ let e = l.prototype, t = e.open, n = e.send, i = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakSet(), u = function(e, n, ...r) {
518
548
  try {
519
- r.set(this, {
549
+ i.set(this, {
520
550
  method: String(e),
521
551
  url: String(n)
522
552
  });
523
553
  } catch {}
524
- return t.call(this, e, n, ...i);
525
- }, u = function(e) {
554
+ return t.call(this, e, n, ...r);
555
+ }, d = function(e) {
526
556
  try {
527
- let e = r.get(this);
528
- e && (i.set(this, {
557
+ let e = i.get(this);
558
+ e && (a.set(this, {
529
559
  m: e,
530
- start: a(),
560
+ start: r(),
531
561
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
532
562
  aborted: !1
533
- }), o.has(this) || (o.add(this), this.addEventListener("abort", () => {
534
- let e = i.get(this);
563
+ }), c.has(this) || (c.add(this), this.addEventListener("abort", () => {
564
+ let e = a.get(this);
535
565
  e && (e.aborted = !0);
536
566
  }), this.addEventListener("loadend", () => {
537
- let e = i.get(this);
538
- i.delete(this), e && !e.aborted && c(e.m.method, e.m.url, this.status, e.start, e.startedAt);
567
+ let e = a.get(this);
568
+ a.delete(this), e && !e.aborted && o(e.m.method, e.m.url, this.status, e.start, e.startedAt);
539
569
  })));
540
570
  } catch {}
541
571
  return n.call(this, e);
542
572
  };
543
- e.open = s, e.send = u, l.push(() => {
544
- e.open === s && (e.open = t), e.send === u && (e.send = n);
573
+ e.open = u, e.send = d, s.push(() => {
574
+ e.open === u && (e.open = t), e.send === d && (e.send = n);
545
575
  });
546
576
  }
547
577
  return () => {
548
- for (let e of l) try {
578
+ for (let e of s) try {
549
579
  e();
550
580
  } catch {}
551
581
  };
552
582
  }
553
583
  // src/capture/ring.ts
554
- var j = class {
584
+ var M = class {
555
585
  constructor(e) {
556
586
  this.capacity = e, this.items = [], this.listeners = /* @__PURE__ */ new Set();
557
587
  }
@@ -575,37 +605,40 @@ var j = class {
575
605
  }
576
606
  };
577
607
  // src/editor-loader.ts
578
- function M() {
579
- return import("./chunks/editor-DbHLGwOA.mjs");
608
+ function je() {
609
+ return import("./chunks/editor-0Kr31Uly.mjs");
580
610
  }
581
- function we() {
582
- return import("./chunks/recorder-BUtEB_em.mjs");
611
+ function Me() {
612
+ return import("./chunks/recorder-tu4yugLw.mjs");
613
+ }
614
+ function Ne() {
615
+ return import("./chunks/scan-CFQwrtAQ.mjs");
583
616
  }
584
617
  // src/capture/signature.ts
585
- function N(e) {
586
- return e.replace(/https?:\/\/\S+/g, "<url>").replace(/\b[0-9a-f]{8,}\b/gi, "<id>").replace(/\d+/g, "<n>").replace(/\s+/g, " ").trim().slice(0, 200);
618
+ function Pe(e) {
619
+ return p(e).replace(/https?:\/\/\S+/g, "<url>").replace(/\b[0-9a-f]{8,}\b/gi, "<id>").replace(/\d+/g, "<n>").replace(/\s+/g, " ").trim().slice(0, 200);
587
620
  }
588
- function P(e, t) {
621
+ function N(e, t) {
589
622
  let n = (Array.isArray(e) ? e : []).filter((e) => e.level === "error");
590
- if (n[0]?.message) return `console:${N(n[0].message)}`;
623
+ if (n[0]?.message) return `console:${Pe(n[0].message)}`;
591
624
  let r = (Array.isArray(t) ? t : []).find((e) => e.status === 0 || e.status >= 500);
592
625
  if (r) {
593
626
  let e = r.url;
594
627
  try {
595
628
  e = new URL(r.url).pathname;
596
629
  } catch {}
597
- return `network:${r.method.toUpperCase()} ${N(e)} ${r.status === 0 ? "failed" : "5xx"}`;
630
+ return `network:${r.method.toUpperCase()} ${Pe(e)} ${r.status === 0 ? "failed" : "5xx"}`;
598
631
  }
599
632
  return null;
600
633
  }
601
634
  // src/fixcheck.ts
602
- function F(e) {
603
- return e.level === "error" ? P([e], []) : null;
635
+ function P(e) {
636
+ return e.level === "error" ? N([e], []) : null;
604
637
  }
605
- function I(e) {
606
- return P([], [e]);
638
+ function Fe(e) {
639
+ return N([], [e]);
607
640
  }
608
- function Te(e) {
641
+ function F(e) {
609
642
  let t = e.path ?? (() => location.pathname), n = e.random ?? Math.random, r = e.now ?? Date.now, i = [], a = /* @__PURE__ */ new Set(), o = r(), s = null, c = (t) => {
610
643
  if (t) {
611
644
  for (let n of i) if (!(n.signature !== t || a.has(n.id))) {
@@ -620,16 +653,16 @@ function Te(e) {
620
653
  return Number.isNaN(t) || t >= o - 1;
621
654
  }, u = (r) => {
622
655
  let u = t();
623
- if (s = u, o = r, a = /* @__PURE__ */ new Set(), i = e.checks.filter((t) => Ee(t.path, u) && e.sampleRate > 0 && n() < e.sampleRate), i.length) {
624
- for (let t of e.console.toArray()) l(t.at) && c(F(t));
625
- for (let t of e.network.toArray()) l(t.at) && c(I(t));
656
+ if (s = u, o = r, a = /* @__PURE__ */ new Set(), i = e.checks.filter((t) => Ie(t.path, u) && e.sampleRate > 0 && n() < e.sampleRate), i.length) {
657
+ for (let t of e.console.toArray()) l(t.at) && c(P(t));
658
+ for (let t of e.network.toArray()) l(t.at) && c(Fe(t));
626
659
  }
627
660
  }, d = e.console.subscribe((e) => {
628
- i.length && c(F(e));
661
+ i.length && c(P(e));
629
662
  }), f = e.network.subscribe((e) => {
630
- i.length && c(I(e));
663
+ i.length && c(Fe(e));
631
664
  }), p = typeof performance < "u" && performance.timeOrigin ? performance.timeOrigin : r();
632
- return u(Math.min(p, r())), {
665
+ return u(e.since ?? Math.min(p, r())), {
633
666
  navigated: () => {
634
667
  t() !== s && u(r());
635
668
  },
@@ -638,23 +671,52 @@ function Te(e) {
638
671
  }
639
672
  };
640
673
  }
641
- function Ee(e, t) {
674
+ function Ie(e, t) {
675
+ return e === "*" || Le(e, t);
676
+ }
677
+ function Le(e, t) {
642
678
  let n = (e) => e.length > 1 ? e.replace(/\/+$/, "") : e;
643
679
  return n(e) === n(t);
644
680
  }
681
+ function Re(e) {
682
+ let t = e.path ?? (() => location.pathname), n = /* @__PURE__ */ new Set(), r = t(), i = e.known.flatMap((e) => e.signature ? [{
683
+ id: e.id,
684
+ path: "*",
685
+ signature: e.signature
686
+ }] : []), a = i.length ? F({
687
+ checks: i,
688
+ sampleRate: 1,
689
+ random: () => 0,
690
+ console: e.console,
691
+ network: e.network,
692
+ report: (e) => n.add(e.id),
693
+ path: t,
694
+ now: e.now
695
+ }) : null;
696
+ return {
697
+ matches: () => ze(e.known, t(), n),
698
+ navigated: () => {
699
+ t() !== r && (r = t(), n.clear()), a?.navigated();
700
+ },
701
+ stop: () => a?.stop()
702
+ };
703
+ }
704
+ function ze(e, t, n = /* @__PURE__ */ new Set()) {
705
+ return e.filter((e) => n.has(e.id) || e.paths.some((e) => Le(e, t))).slice(0, 3);
706
+ }
645
707
  // src/mount.ts
646
- var L = "pinax-widget-root";
647
- function De(e = document) {
648
- let t = e.getElementById(L);
708
+ var I = "pinax-widget-root";
709
+ function Be(e = document) {
710
+ let t = e.getElementById(I);
649
711
  if (t?.shadowRoot) return t.shadowRoot;
650
712
  let n = e.createElement("div");
651
- return n.id = L, n.className = "ph-no-capture fs-exclude", n.setAttribute("data-hj-suppress", ""), n.setAttribute("data-clarity-mask", "true"), n.setAttribute("data-private", ""), n.style.cssText = "all: initial; position: fixed; z-index: 2147483647;", e.body.appendChild(n), n.attachShadow({ mode: "open" });
713
+ return n.id = I, n.className = "ph-no-capture fs-exclude", n.setAttribute("data-hj-suppress", ""), n.setAttribute("data-clarity-mask", "true"), n.setAttribute("data-private", ""), n.style.cssText = "all: initial; position: fixed; z-index: 2147483647;", e.body.appendChild(n), n.attachShadow({ mode: "open" });
652
714
  }
653
- function Oe(e = document) {
654
- e.getElementById(L)?.remove();
715
+ function Ve(e = document) {
716
+ e.getElementById(I)?.remove();
655
717
  }
656
718
  // src/navigation.ts
657
- function ke(e, t = window) {
719
+ function He(e, t = window) {
658
720
  let n = !0, r = !1, i = () => {
659
721
  if (!n || r) return;
660
722
  r = !0;
@@ -690,46 +752,58 @@ function ke(e, t = window) {
690
752
  };
691
753
  }
692
754
  // src/paths.ts
693
- var R = /* @__PURE__ */ new Map();
694
- function Ae(e) {
695
- let t = R.get(e);
755
+ var L = /* @__PURE__ */ new Map();
756
+ function Ue(e) {
757
+ let t = L.get(e);
696
758
  if (!t) {
697
- let n = z(e.trim()).split("*").map((e) => e.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*");
698
- t = RegExp(`^${n}$`), R.size > 200 && R.clear(), R.set(e, t);
759
+ let n = R(e.trim()).split("*").map((e) => e.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*");
760
+ t = RegExp(`^${n}$`), L.size > 200 && L.clear(), L.set(e, t);
699
761
  }
700
762
  return t;
701
763
  }
702
- function z(e) {
764
+ function R(e) {
703
765
  return e.length > 1 ? e.replace(/\/+$/, "") || "/" : e;
704
766
  }
705
- function je(e) {
767
+ function We(e) {
706
768
  try {
707
769
  return decodeURI(e);
708
770
  } catch {
709
771
  return e;
710
772
  }
711
773
  }
712
- function Me(e, t) {
774
+ function Ge(e, t) {
713
775
  if (typeof e != "string" || !e.trim()) return !1;
714
- let n = Ae(e), r = z(t || "/"), i = [r, `${r === "/" ? "" : r}/`], a = je(r);
776
+ let n = Ue(e), r = R(t || "/"), i = [r, `${r === "/" ? "" : r}/`], a = We(r);
715
777
  return a !== r && i.push(a, `${a}/`), i.some((e) => n.test(e));
716
778
  }
717
- function Ne(e, t) {
718
- return e?.length ? e.some((e) => Me(e, t)) : !1;
779
+ function Ke(e, t) {
780
+ return e?.length ? e.some((e) => Ge(e, t)) : !1;
719
781
  }
720
782
  // src/queue.ts
721
- var Pe = 864e5, Fe = 8, B = (e) => `pinax:queue:${e}`;
783
+ var qe = 36e5, Je = 8, z = (e) => `pinax:queue:${e}`, B = /* @__PURE__ */ new Map(), Ye = (e) => Date.now() - e.queuedAt <= qe, Xe = (e) => {
784
+ let t = e;
785
+ return !!t && typeof t.queuedAt == "number" && typeof t.tries == "number" && typeof t.body?.page?.url == "string";
786
+ };
722
787
  function V(e, t) {
788
+ let n;
723
789
  try {
724
- let n = e.getItem(B(t)), r = n ? JSON.parse(n) : [];
725
- return Array.isArray(r) ? r : [];
790
+ let r = e.getItem(z(t)), i = r ? JSON.parse(r) : [];
791
+ n = Array.isArray(i) ? i : [];
726
792
  } catch {
727
793
  return [];
728
794
  }
795
+ let r = n.filter((e) => Xe(e) && Ye(e)), i = r.some((e) => "email" in e.body || "user" in e.body);
796
+ if (r.length === n.length && !i) return r;
797
+ for (let e of n) !r.includes(e) && e?.id && B.delete(e.id);
798
+ let a = r.map((e) => ({
799
+ ...e,
800
+ body: Ze(e.body)
801
+ }));
802
+ return H(e, t, a), a;
729
803
  }
730
804
  function H(e, t, n) {
731
805
  try {
732
- return n.length ? e.setItem(B(t), JSON.stringify(n)) : e.removeItem(B(t)), !0;
806
+ return n.length ? e.setItem(z(t), JSON.stringify(n)) : e.removeItem(z(t)), !0;
733
807
  } catch {
734
808
  return !1;
735
809
  }
@@ -741,45 +815,56 @@ function U() {
741
815
  return null;
742
816
  }
743
817
  }
744
- function Ie(e) {
745
- let { user: t, console: n, screenshot: r, annotations: i, replay: a, ...o } = e;
818
+ function Ze(e) {
819
+ let { email: t, user: r, console: i, screenshot: a, annotations: o, replay: s, ...c } = e;
746
820
  return {
747
- ...o,
821
+ ...c,
748
822
  page: {
749
- ...o.page,
750
- url: l(o.page.url)
823
+ ...c.page,
824
+ url: n(c.page.url)
751
825
  }
752
826
  };
753
827
  }
754
- function Le(e, t) {
828
+ var Qe = () => `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}`;
829
+ function $e(e, t) {
755
830
  let n = U();
756
- return n ? H(n, e, [...V(n, e).slice(-4), {
757
- body: Ie(t),
831
+ if (!n) return !1;
832
+ let r = V(n, e), i = r.slice(0, Math.max(0, r.length - 4));
833
+ for (let e of i) e.id && B.delete(e.id);
834
+ let a = Qe(), o = H(n, e, [...r.slice(-4), {
835
+ id: a,
836
+ body: Ze(t),
758
837
  queuedAt: Date.now(),
759
838
  tries: 0
760
- }]) : !1;
839
+ }]);
840
+ return o && (t.email || t.user) && B.set(a, {
841
+ ...t.email && { email: t.email },
842
+ ...t.user && { user: t.user }
843
+ }), o;
761
844
  }
762
- function Re(e) {
845
+ function et(e) {
763
846
  let t = U();
764
847
  return t ? V(t, e).length : 0;
765
848
  }
766
849
  var W = !1;
767
- async function ze(e, t, n) {
850
+ async function tt(e, t, n) {
768
851
  let r = U();
769
852
  if (r && !W && (typeof navigator > "u" || navigator.onLine !== !1)) {
770
853
  W = !0;
771
854
  try {
772
855
  let i = V(r, n), a = [];
773
856
  for (let r of i) {
774
- if (Date.now() - r.queuedAt > Pe) continue;
775
- let i = await re(e, t, n, r.body);
776
- !i.ok && i.retry && r.tries + 1 < Fe && a.push({
857
+ let i = r.id ? B.get(r.id) : void 0, o = await y(e, t, n, {
858
+ ...r.body,
859
+ ...i
860
+ });
861
+ !o.ok && o.retry && r.tries + 1 < Je ? a.push({
777
862
  ...r,
778
863
  tries: r.tries + 1
779
- });
864
+ }) : r.id && B.delete(r.id);
780
865
  }
781
- let o = V(r, n).slice(i.length);
782
- H(r, n, [...a, ...o]);
866
+ let o = new Set(i.map((e) => e.id)), s = V(r, n).filter((e) => !o.has(e.id));
867
+ H(r, n, [...a, ...s]);
783
868
  } finally {
784
869
  W = !1;
785
870
  }
@@ -790,7 +875,7 @@ var G = {
790
875
  opened: "Pinax Widget Opened",
791
876
  submitted: "Feedback Submitted"
792
877
  };
793
- function K(e = window) {
878
+ function nt(e = window) {
794
879
  try {
795
880
  let t = e.analytics;
796
881
  return !t || typeof t != "object" && typeof t != "function" ? null : typeof t.track == "function" ? t : null;
@@ -798,34 +883,34 @@ function K(e = window) {
798
883
  return null;
799
884
  }
800
885
  }
801
- function Be(e, t) {
886
+ function rt(e, t) {
802
887
  return typeof e == "boolean" ? e : t === !0;
803
888
  }
804
- function q(e, t) {
889
+ function it(e, t) {
805
890
  try {
806
- K()?.track?.(e, t);
891
+ nt()?.track?.(e, t);
807
892
  } catch {}
808
893
  }
809
- function Ve() {
810
- q(G.opened, { source: "pinax" });
894
+ function at() {
895
+ it(G.opened, { source: "pinax" });
811
896
  }
812
- function He(e) {
897
+ function ot(e) {
813
898
  let t = {
814
899
  source: "pinax",
815
900
  type: e.type.toLowerCase()
816
901
  };
817
- typeof e.rating == "number" && (t.rating = e.rating), e.reportId && (t.reportId = e.reportId), e.queued && (t.queued = !0), q(G.submitted, t);
902
+ typeof e.rating == "number" && (t.rating = e.rating), e.reportId && (t.reportId = e.reportId), e.queued && (t.queued = !0), it(G.submitted, t);
818
903
  }
819
- function Ue() {
904
+ function st() {
820
905
  try {
821
- let e = K()?.user?.()?.id?.();
906
+ let e = nt()?.user?.()?.id?.();
822
907
  return typeof e == "string" && e.trim() ? e.trim().slice(0, 200) : typeof e == "number" && Number.isFinite(e) ? String(e) : null;
823
908
  } catch {
824
909
  return null;
825
910
  }
826
911
  }
827
912
  // src/index.ts
828
- var J = null, Y, We, X = (e, t) => (We ?? window.fetch).call(window, e, t);
913
+ var ct = 8e3, K = null, q, J, Y, lt, X = (e, t) => (lt ?? window.fetch).call(window, e, t);
829
914
  function Z(e, t) {
830
915
  try {
831
916
  (console.warn.__pinaxOriginal ?? console.warn).call(console, `Pinax: ${e}`, t ?? "");
@@ -838,204 +923,348 @@ function Q(e) {
838
923
  Z("capture could not start", e);
839
924
  }
840
925
  }
841
- function Ge(e) {
842
- if (J) return;
843
- if (!e?.key) throw Error("Pinax: init() needs a website key");
844
- let t = u(e.apiUrl), r = d(e.cdnUrl, e.apiUrl);
845
- We = typeof window.fetch == "function" ? window.fetch : void 0;
846
- let a = {
847
- options: e,
848
- api: t,
849
- root: De(),
850
- user: Y,
851
- console: new j(50),
852
- network: new j(50),
853
- breadcrumbs: new j(20),
926
+ function ut(t) {
927
+ if (K) return;
928
+ if (!t?.key) throw Error("Pinax: init() needs a website key");
929
+ let n = m(t.apiUrl), i = h(t.cdnUrl, t.apiUrl);
930
+ lt = typeof window.fetch == "function" ? window.fetch : void 0;
931
+ let c = {
932
+ options: t,
933
+ api: n,
934
+ cdn: i,
935
+ root: Be(),
936
+ user: q,
937
+ console: new M(50),
938
+ network: new M(50),
939
+ breadcrumbs: new M(20),
940
+ replayStarting: !1,
941
+ replaySampled: !1,
942
+ consent: {
943
+ diagnostics: !1,
944
+ replay: !1,
945
+ ...J
946
+ },
947
+ running: !1,
948
+ watchers: {},
949
+ counted: !1,
854
950
  stopCapture: {},
855
951
  onNavigate: [],
856
952
  cleanups: [],
857
953
  openWhenReady: !1,
858
954
  alive: !0
859
955
  };
860
- J = a, Y = void 0, Q(() => {
861
- let e = $(ve(a.console));
862
- a.stopCapture.console = e, a.cleanups.push(e);
956
+ K = c, q = void 0, J = void 0, Q(() => {
957
+ let e = dt(we(c.console));
958
+ c.stopCapture.console = e, c.cleanups.push(e);
863
959
  }), Q(() => {
864
- let n = $(Ce(a.network, window, { ignore: (n) => n.startsWith(`${t}/v1/widget/`) || r !== null && n.startsWith(f(r, e.key)) }));
865
- a.stopCapture.network = n, a.cleanups.push(n);
960
+ let e = dt(Ae(c.network, window, { ignore: (e) => e.startsWith(`${n}/v1/widget/`) || i !== null && (e.startsWith(g(i, t.key)) || e.startsWith(ae(n, t.key, i))) }));
961
+ c.stopCapture.network = e, c.cleanups.push(e);
866
962
  });
867
- let s = a.root.host;
963
+ let l = c.root.host;
868
964
  Q(() => {
869
- let e = pe(a.breadcrumbs, { ignore: (e) => e instanceof Node && s.contains(e) });
870
- a.onNavigate.push(e.navigated), a.cleanups.push(e.stop);
871
- }), Q(() => a.cleanups.push(ke(() => {
872
- for (let e of a.onNavigate) try {
965
+ let e = ve(c.breadcrumbs, { ignore: (e) => e instanceof Node && l.contains(e) });
966
+ c.onNavigate.push(e.navigated), c.cleanups.push(e.stop);
967
+ }), c.onNavigate.push(() => {
968
+ c.watchers.fixChecks?.navigated(), c.watchers.sightings?.navigated();
969
+ }), c.cleanups.push(() => {
970
+ bt(c), wt(c);
971
+ }), Q(() => c.cleanups.push(He(() => {
972
+ for (let e of c.onNavigate) try {
873
973
  e();
874
974
  } catch {}
875
975
  })));
876
- let l = () => {
877
- ze(X, t, e.key).catch(() => {});
976
+ let u = () => {
977
+ tt(X, n, t.key).catch(() => {});
878
978
  };
879
- window.addEventListener("online", l), a.cleanups.push(() => window.removeEventListener("online", l)), ee(X, t, e.key, r).then((r) => {
880
- if (!a.alive) return;
881
- if (!r) {
979
+ window.addEventListener("online", u), c.cleanups.push(() => window.removeEventListener("online", u)), ee(X, n, t.key, i).then((i) => {
980
+ if (!c.alive) return;
981
+ if (!i) {
882
982
  Z("this website key was not found");
883
983
  return;
884
984
  }
885
- let s = i(r.ai, r.samplingRate);
886
- if (a.config = {
887
- ...r,
888
- settings: o(r.settings),
889
- branding: n(r.branding),
890
- ai: s
891
- }, Ke(a), te(X, t, e.key, location.href), Re(e.key) && l(), !r.enabled) return;
892
- if (!nt(r.allowedDomains, location.hostname)) {
893
- Z(`${location.hostname} isn't one of this website's allowed domains, so the button is hidden. Add it under Websites in Pinax.`);
894
- return;
895
- }
896
- qe(a);
897
- let u = Be(e.segment, a.config.settings.segment);
898
- s.replay && Math.random() < s.replaySampleRate && Ye(a);
899
- let d = new c(a.root, a.config, {
900
- takeScreenshot: async () => (await M()).takeScreenshot(a.root.host, { autoBlur: s.autoBlur }),
901
- markUp: async (e) => (await M()).markUp(a.root, e),
902
- submit: (e) => Ze(a, e, u),
903
- user: () => a.user,
904
- opened: u ? Ve : void 0,
905
- followUp: s.followUp ? ({ type: n, message: r }) => ae(X, t, e.key, {
906
- type: n,
985
+ let l = r(i.ai, i.samplingRate), d = o(i.settings);
986
+ c.config = {
987
+ ...i,
988
+ settings: d,
989
+ branding: e(i.branding),
990
+ ai: l,
991
+ known: a(i.known, d.knownIssues)
992
+ }, ft(c), c.replaySampled = l.replay && Math.random() < l.replaySampleRate, te(X, n, t.key, location.href), et(t.key) && u();
993
+ let f = It(i.allowedDomains, location.hostname);
994
+ if (i.enabled && !f && Z(`${location.hostname} isn't one of this website's allowed domains, so the button is hidden. Add it under Websites in Pinax.`), c.running = i.enabled && f, ht(c), !c.running) return;
995
+ let p = xt(c), m = rt(t.segment, c.config.settings.segment), h = new s(c.root, c.config, {
996
+ takeScreenshot: async () => (await je()).takeScreenshot(c.root.host, { autoBlur: l.autoBlur }),
997
+ markUp: async (e) => (await je()).markUp(c.root, e),
998
+ submit: (e) => Ot(c, e, m),
999
+ user: () => c.user,
1000
+ opened: m ? at : void 0,
1001
+ followUp: l.followUp ? ({ type: e, message: r }) => ie(X, n, t.key, {
1002
+ type: e,
907
1003
  message: r,
908
1004
  pagePath: location.pathname
909
- }) : void 0
1005
+ }) : void 0,
1006
+ knownIssues: p,
1007
+ meToo: (e, r) => ce(X, n, t.key, e, r),
1008
+ attachments: () => Dt(c)
910
1009
  });
911
- a.ui = d;
912
- let { hidePaths: f, hideButton: p } = a.config.settings;
913
- if (f.length && !p) {
914
- let e = () => d.setPathHidden(Ne(f, location.pathname));
915
- e(), a.onNavigate.push(e);
1010
+ c.ui = h;
1011
+ let { hidePaths: g, hideButton: _ } = c.config.settings;
1012
+ if (g.length && !_) {
1013
+ let e = () => h.setPathHidden(Ke(g, location.pathname));
1014
+ e(), c.onNavigate.push(e);
916
1015
  }
917
- a.openWhenReady && d.open();
1016
+ c.openWhenReady && h.open();
918
1017
  }).catch((e) => {
919
- a.alive && Z("could not load widget settings", e);
1018
+ c.alive && Z("could not load widget settings", e);
920
1019
  });
921
1020
  }
922
- function $(e) {
1021
+ function dt(e) {
923
1022
  let t = !1;
924
1023
  return () => {
925
1024
  t || (t = !0, e());
926
1025
  };
927
1026
  }
928
- function Ke(e) {
1027
+ function ft(e) {
929
1028
  let t = e.config?.settings.capture;
930
1029
  t && (t.console || (Q(() => e.stopCapture.console?.()), e.console.clear()), t.network || (Q(() => e.stopCapture.network?.()), e.network.clear()));
931
1030
  }
932
- function qe(e) {
1031
+ function pt(e) {
1032
+ let t = e.options.consent;
1033
+ return t === "wait" || t !== "none" && e.config?.settings.consent?.required === !0;
1034
+ }
1035
+ function mt(e) {
1036
+ return pt(e) || e.config?.settings.consent?.required === !0;
1037
+ }
1038
+ function $(e) {
1039
+ let t = pt(e);
1040
+ return {
1041
+ diagnostics: !t || e.consent.diagnostics,
1042
+ replay: !t || e.consent.replay
1043
+ };
1044
+ }
1045
+ function ht(e) {
1046
+ try {
1047
+ gt(e);
1048
+ } catch (e) {
1049
+ Z("could not apply consent", e);
1050
+ }
1051
+ }
1052
+ function gt(e) {
1053
+ if (!e.alive || !e.config) return;
1054
+ let t = $(e);
1055
+ e.config.settings.consent?.required && t.diagnostics && !e.counted && (e.counted = !0, oe(X, e.api, e.options.key, e.cdn)), e.running && (t.diagnostics ? (vt(e), yt(e)) : bt(e), t.replay && e.replaySampled ? Ct(e) : wt(e)), e.ui?.refresh();
1056
+ }
1057
+ var _t = (e) => mt(e) && $(e).diagnostics ? !0 : void 0;
1058
+ function vt(e) {
933
1059
  let t = e.config?.ai;
934
- !t?.fixChecks.length || t.fixCheckSampleRate <= 0 || Q(() => {
935
- let n = Te({
1060
+ !e.watchers.fixChecks && t?.fixChecks.length && (t.fixCheckSampleRate <= 0 || Q(() => {
1061
+ e.watchers.fixChecks = F({
936
1062
  checks: t.fixChecks,
937
1063
  sampleRate: t.fixCheckSampleRate,
938
1064
  console: e.console,
939
1065
  network: e.network,
940
- report: (t) => oe(X, e.api, e.options.key, {
1066
+ since: e.watchersSince,
1067
+ report: (t) => b(X, e.api, e.options.key, {
941
1068
  checkId: t.id,
942
- signature: t.signature
1069
+ signature: t.signature,
1070
+ consent: _t(e)
943
1071
  })
944
1072
  });
945
- e.onNavigate.push(n.navigated), e.cleanups.push(n.stop);
946
- });
1073
+ }));
1074
+ }
1075
+ function yt(e) {
1076
+ let t = e.config?.ai;
1077
+ !e.watchers.sightings && t?.watches.length && (t.fixCheckSampleRate <= 0 || Q(() => {
1078
+ e.watchers.sightings = F({
1079
+ checks: t.watches.map((e) => ({
1080
+ ...e,
1081
+ path: "*"
1082
+ })),
1083
+ sampleRate: t.fixCheckSampleRate,
1084
+ console: e.console,
1085
+ network: e.network,
1086
+ since: e.watchersSince,
1087
+ report: (t) => b(X, e.api, e.options.key, {
1088
+ checkId: t.id,
1089
+ signature: t.signature,
1090
+ basket: Y,
1091
+ consent: _t(e)
1092
+ }, "sighting")
1093
+ });
1094
+ }));
1095
+ }
1096
+ function bt(e) {
1097
+ let { fixChecks: t, sightings: n } = e.watchers;
1098
+ (t || n) && (e.watchers = {}, e.watchersSince = Date.now() + 2, Q(() => t?.stop()), Q(() => n?.stop()));
1099
+ }
1100
+ function xt(e) {
1101
+ let t = e.config?.known;
1102
+ if (!t?.length) return;
1103
+ let n;
1104
+ return Q(() => {
1105
+ let r = Re({
1106
+ known: t,
1107
+ console: e.console,
1108
+ network: e.network
1109
+ });
1110
+ e.onNavigate.push(r.navigated), e.cleanups.push(r.stop), n = r.matches;
1111
+ }), n;
947
1112
  }
948
- function Je(e) {
1113
+ function St(e) {
949
1114
  let t = () => {
950
1115
  let t = window.requestIdleCallback;
951
1116
  typeof t == "function" ? t(e, { timeout: 3e3 }) : setTimeout(e, 200);
952
1117
  };
953
1118
  document.readyState === "complete" ? t() : window.addEventListener("load", t, { once: !0 });
954
1119
  }
955
- function Ye(e) {
956
- Je(() => {
957
- e.alive && we().then((t) => {
958
- if (!e.alive) return;
959
- let n = t.startRecorder({ exclude: `#${e.root.host.id}` });
960
- e.recorder = n, e.cleanups.push(() => n.stop());
961
- }).catch((e) => Z("session replay could not start", e));
1120
+ function Ct(e) {
1121
+ if (e.recorder || e.replayStarting) return;
1122
+ e.replayStarting = !0;
1123
+ let t = () => e.alive && e.running && e.replaySampled && $(e).replay;
1124
+ St(() => {
1125
+ t() ? Me().then((n) => {
1126
+ e.replayStarting = !1, !e.recorder && t() && (e.recorder = n.startRecorder({
1127
+ exclude: `#${e.root.host.id}`,
1128
+ mask: e.config?.ai?.replayMask
1129
+ }), e.ui?.refresh());
1130
+ }).catch((t) => {
1131
+ e.replayStarting = !1, Z("session replay could not start", t);
1132
+ }) : e.replayStarting = !1;
962
1133
  });
963
1134
  }
964
- async function Xe(e) {
1135
+ function wt(e) {
1136
+ let t = e.recorder;
1137
+ e.recorder = void 0, t && Q(() => t.stop());
1138
+ }
1139
+ async function Tt(e) {
965
1140
  if (!e.recorder) return null;
1141
+ let n;
1142
+ try {
1143
+ return await Promise.race([e.recorder.exportReplay(t.replayChars).catch(() => null), new Promise((e) => {
1144
+ n = setTimeout(() => e(null), 5e3);
1145
+ })]);
1146
+ } finally {
1147
+ clearTimeout(n);
1148
+ }
1149
+ }
1150
+ async function Et(e) {
966
1151
  let t;
967
1152
  try {
968
- return await Promise.race([e.recorder.exportReplay(s.replayChars).catch(() => null), new Promise((e) => {
969
- t = setTimeout(() => e(null), 5e3);
1153
+ return await Promise.race([Ne().then((t) => t.scanPage({ exclude: `#${e.root.host.id}` })).catch(() => null), new Promise((e) => {
1154
+ t = setTimeout(() => e(null), ct);
970
1155
  })]);
971
1156
  } finally {
972
1157
  clearTimeout(t);
973
1158
  }
974
1159
  }
975
- async function Ze(t, n, i = !1) {
976
- let o = i && !t.user?.id ? Ue() : null, s = o ? {
977
- ...t.user,
978
- id: o
979
- } : t.user, c = t.config?.settings.capture, l = a({
980
- type: n.type,
981
- message: n.message,
982
- rating: n.rating,
983
- email: n.email,
984
- user: s,
985
- screenshot: n.shot?.dataUrl,
986
- annotations: n.shot?.annotations,
987
- followUp: n.followUp,
988
- fields: n.fields,
989
- hp: n.hp,
990
- elapsedMs: n.elapsedMs
1160
+ function Dt(e) {
1161
+ let t = $(e), n = e.config?.settings.capture, r = n?.console !== !1, i = n?.network !== !1;
1162
+ return {
1163
+ logs: t.diagnostics && (r && e.console.size > 0 || i && e.network.size > 0 || e.breadcrumbs.size > 0),
1164
+ askLogs: !t.diagnostics && (r || i),
1165
+ replay: t.replay && !!e.recorder && typeof CompressionStream == "function"
1166
+ };
1167
+ }
1168
+ async function Ot(e, t, r = !1) {
1169
+ let a = t.type === "ACCESSIBILITY" ? await Et(e) : void 0, o = $(e), s = (o.diagnostics || t.includeLogs === !0) && t.listed?.logs !== !1, l = o.replay && t.listed?.replay !== !1, u = r && o.diagnostics && !e.user?.id ? st() : null, d = u ? {
1170
+ ...e.user,
1171
+ id: u
1172
+ } : e.user, f = e.config?.settings.capture, p = c({
1173
+ type: t.type,
1174
+ message: t.message,
1175
+ rating: t.rating,
1176
+ email: t.email,
1177
+ user: d,
1178
+ screenshot: t.shot?.dataUrl,
1179
+ annotations: t.shot?.annotations,
1180
+ followUp: t.followUp,
1181
+ fields: t.fields,
1182
+ barrier: t.barrier,
1183
+ a11yScan: a,
1184
+ hp: t.hp,
1185
+ elapsedMs: t.elapsedMs,
1186
+ consent: mt(e) ? o : void 0,
1187
+ includeLogs: t.includeLogs
991
1188
  }, {
992
1189
  page: {
993
- url: e(location.href),
1190
+ url: n(location.href),
994
1191
  title: document.title || void 0
995
1192
  },
996
- environment: xe(),
997
- console: c?.console === !1 ? [] : t.console.toArray(),
998
- network: c?.network === !1 ? [] : t.network.toArray(),
999
- breadcrumbs: t.breadcrumbs.toArray()
1193
+ environment: Oe(),
1194
+ console: !s || f?.console === !1 ? [] : e.console.toArray(),
1195
+ network: !s || f?.network === !1 ? [] : e.network.toArray(),
1196
+ breadcrumbs: s ? e.breadcrumbs.toArray() : []
1000
1197
  });
1001
- r(l, await Xe(t));
1002
- let u = await re(X, t.api, t.options.key, l), d = (e, t) => {
1003
- i && He({
1004
- type: n.type,
1005
- rating: n.rating,
1006
- reportId: t,
1198
+ l && i(p, await Tt(e));
1199
+ let m = await y(X, e.api, e.options.key, p), h = (e, n) => {
1200
+ r && ot({
1201
+ type: t.type,
1202
+ rating: t.rating,
1203
+ reportId: n,
1007
1204
  queued: e
1008
1205
  });
1009
1206
  };
1010
- return u.ok ? (d(!1, u.id || void 0), { status: "sent" }) : u.retry && Le(t.options.key, l) ? (d(!0), { status: "queued" }) : {
1207
+ return m.ok ? (h(!1, m.id || void 0), { status: "sent" }) : m.retry && $e(e.options.key, p) ? (h(!0), { status: "queued" }) : {
1011
1208
  status: "error",
1012
- message: u.message
1209
+ message: m.message
1013
1210
  };
1014
1211
  }
1015
- function Qe() {
1016
- J ? J.ui ? J.ui.open() : J.config || (J.openWhenReady = !0) : Z("call init() before open()");
1212
+ function kt() {
1213
+ K ? K.ui ? K.ui.open() : K.config || (K.openWhenReady = !0) : Z("call init() before open()");
1214
+ }
1215
+ function At(e) {
1216
+ let t;
1217
+ if (typeof e == "boolean") t = {
1218
+ diagnostics: e,
1219
+ replay: e
1220
+ };
1221
+ else if (e && typeof e == "object") {
1222
+ t = {};
1223
+ for (let n of ["diagnostics", "replay"]) e[n] !== void 0 && (t[n] = e[n] === !0);
1224
+ } else {
1225
+ Z("consent() takes true, false or { diagnostics, replay }");
1226
+ return;
1227
+ }
1228
+ K ? (K.consent = {
1229
+ ...K.consent,
1230
+ ...t
1231
+ }, ht(K)) : J = {
1232
+ ...J,
1233
+ ...t
1234
+ };
1017
1235
  }
1018
- function $e(e) {
1236
+ function jt(e) {
1019
1237
  let t = e ? { ...e } : void 0;
1020
- J ? J.user = t : Y = t;
1238
+ K ? K.user = t : q = t;
1239
+ }
1240
+ function Mt(e) {
1241
+ Y = Nt(e);
1242
+ }
1243
+ function Nt(e) {
1244
+ if (!e || typeof e != "object") return;
1245
+ let { value: t, currency: n } = e, r = typeof n == "string" ? n.trim().toUpperCase() : "";
1246
+ if (!(typeof t != "number" || !Number.isFinite(t) || t <= 0 || t > 1e7 || !/^[A-Z]{3}$/.test(r))) return {
1247
+ value: Math.round(t * 100) / 100,
1248
+ currency: r
1249
+ };
1021
1250
  }
1022
- function et() {
1023
- if (J) {
1024
- J.alive = !1, J.ui?.destroy();
1025
- for (let e of J.cleanups.reverse()) try {
1251
+ function Pt() {
1252
+ if (K) {
1253
+ K.alive = !1, K.ui?.destroy();
1254
+ for (let e of K.cleanups.reverse()) try {
1026
1255
  e();
1027
1256
  } catch {}
1028
1257
  }
1029
- Oe(), J = null, Y = void 0;
1258
+ Ve(), K = null, q = void 0, J = void 0, Y = void 0;
1030
1259
  }
1031
- function tt() {
1032
- return J;
1260
+ function Ft() {
1261
+ return K;
1033
1262
  }
1034
- function nt(e, t) {
1263
+ function It(e, t) {
1035
1264
  if (!e) return !0;
1036
1265
  let n = t.toLowerCase();
1037
1266
  return e.some((e) => e.toLowerCase() === n);
1038
1267
  }
1039
- export { et as destroy, tt as getState, $e as identify, Ge as init, Qe as open };
1268
+ export { Nt as cleanBasket, At as consent, Pt as destroy, Ft as getState, jt as identify, ut as init, kt as open, Mt as setBasket };
1040
1269
 
1041
1270
  //# sourceMappingURL=pinax.mjs.map