@blipit/react-native 0.4.0 → 0.5.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.
package/dist/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -32,27 +22,434 @@ var index_exports = {};
32
22
  __export(index_exports, {
33
23
  BlipitReporter: () => BlipitReporter,
34
24
  DEFAULT_ENDPOINT: () => DEFAULT_ENDPOINT,
25
+ ErrorBoundary: () => ErrorBoundary,
35
26
  VERSION: () => VERSION,
36
- addBreadcrumb: () => import_react_native3.addBreadcrumb,
37
- captureException: () => import_react_native3.captureException,
38
- captureMessage: () => import_react_native3.captureMessage,
27
+ addBreadcrumb: () => addBreadcrumb,
28
+ captureException: () => captureException,
29
+ captureMessage: () => captureMessage,
39
30
  captureSecurity: () => captureSecurity,
40
- dsn: () => dsn,
41
31
  endFlow: () => endFlow,
42
32
  flowStep: () => flowStep,
43
- flush: () => import_react_native3.flush,
44
- init: () => init2,
33
+ flush: () => flush,
34
+ hasReplayConsent: () => hasReplayConsent,
35
+ init: () => init,
36
+ isEnabled: () => isEnabled,
37
+ lastEventId: () => lastEventId,
45
38
  reportReady: () => reportReady,
46
- setTag: () => import_react_native3.setTag,
47
- setUser: () => import_react_native3.setUser,
39
+ setEnabled: () => setEnabled,
40
+ setReplayConsent: () => setReplayConsent,
41
+ setTag: () => setTag,
42
+ setUser: () => setUser,
48
43
  showReport: () => showReport,
49
44
  startFlow: () => startFlow,
50
- withIdentity: () => withIdentity,
51
- wrap: () => import_react_native3.wrap
45
+ trackNavigation: () => trackNavigation2,
46
+ wrap: () => wrap
52
47
  });
53
48
  module.exports = __toCommonJS(index_exports);
54
- var Sentry = __toESM(require("@sentry/react-native"), 1);
55
- var import_react_native2 = require("react-native");
49
+ var import_react_native3 = require("react-native");
50
+
51
+ // src/nuggets.ts
52
+ var VERSION = "0.5.0";
53
+ var SDK_NAME = "@blipit/react-native";
54
+ var DEFAULT_ENDPOINT = "https://in.blipit.io";
55
+ var CATEGORIES = /* @__PURE__ */ new Set(["ui.click", "ui.input", "navigation", "http", "console", "query", "custom"]);
56
+ var CRUMB_LEVELS = /* @__PURE__ */ new Set(["error", "warning", "info", "debug"]);
57
+ var TAG_KEY = /[^a-zA-Z0-9_.-]/g;
58
+ var SENSITIVE = /\b((?:[a-zA-Z0-9_-]*(?:token|key|password|secret|auth|session|passwd|api)[a-zA-Z0-9_-]*)=)[^&\s"']+/gi;
59
+ var QUEUE_MAX = 30;
60
+ var truncate = (v, max) => v.length > max ? v.slice(0, max) : v;
61
+ var scrub = (text2) => text2.replace(SENSITIVE, "$1[redacted]");
62
+ function uuid32() {
63
+ let out = "";
64
+ for (let i = 0; i < 32; i++) out += Math.floor(Math.random() * 16).toString(16);
65
+ return `${out.slice(0, 12)}4${out.slice(13, 16)}${"89ab"[Math.floor(Math.random() * 4)]}${out.slice(17)}`;
66
+ }
67
+ var HERMES = /^\s*at (?:(.+?) \()?(?:address at )?(.+?):(\d+):(\d+)\)?\s*$/;
68
+ var JSC = /^\s*(?:(.*?)@)?(.+?):(\d+):(\d+)\s*$/;
69
+ function parseStack(stack) {
70
+ if (!stack) return [];
71
+ const frames = [];
72
+ for (const line of stack.split("\n")) {
73
+ const m = HERMES.exec(line) ?? (/^\s*at /.test(line) ? null : JSC.exec(line));
74
+ if (!m) continue;
75
+ const file = m[2].replace(/\?.*$/, "");
76
+ const frame = { filename: truncate(file, 1024), lineno: Number(m[3]), colno: Number(m[4]), in_app: !/node_modules|\[native code\]/.test(file) };
77
+ if (m[1]) frame.function = truncate(m[1], 512);
78
+ frames.push(frame);
79
+ }
80
+ return frames.reverse().slice(-128);
81
+ }
82
+ function cleanCrumb(c, at) {
83
+ const ts = typeof c.timestamp === "number" ? new Date(c.timestamp < 1e12 ? c.timestamp * 1e3 : c.timestamp).toISOString() : c.timestamp ?? at;
84
+ const out = { timestamp: ts, category: c.category && CATEGORIES.has(c.category) ? c.category : "custom" };
85
+ if (c.message) out.message = truncate(scrub(String(c.message)), 1024);
86
+ if (c.level && CRUMB_LEVELS.has(c.level)) out.level = c.level;
87
+ if (c.data && typeof c.data === "object") out.data = typeof c.data.url === "string" ? { ...c.data, url: scrub(c.data.url) } : c.data;
88
+ return out;
89
+ }
90
+ var Nuggets = class {
91
+ endpoint;
92
+ key;
93
+ user;
94
+ tags = {};
95
+ lastEventId;
96
+ enabled;
97
+ onError;
98
+ crumbs = [];
99
+ queue = [];
100
+ captured = /* @__PURE__ */ new WeakSet();
101
+ timer;
102
+ sending;
103
+ pausedUntil = 0;
104
+ fetcher;
105
+ now;
106
+ options;
107
+ constructor(options) {
108
+ this.options = options;
109
+ this.endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/api\/v1\/events.*$/, "").replace(/\/+$/, "");
110
+ this.key = options.key;
111
+ this.enabled = options.enabled !== false;
112
+ this.fetcher = options.fetch ?? ((...a) => fetch(...a));
113
+ this.now = options.now ?? Date.now;
114
+ try {
115
+ const saved = JSON.parse(options.store?.load() ?? "[]");
116
+ if (Array.isArray(saved)) this.queue = saved.slice(-QUEUE_MAX);
117
+ } catch {
118
+ }
119
+ }
120
+ get pending() {
121
+ return this.queue.length;
122
+ }
123
+ url(path) {
124
+ return `${this.endpoint}${path}`;
125
+ }
126
+ setEnabled(on) {
127
+ this.enabled = on;
128
+ if (!on) {
129
+ this.queue = [];
130
+ this.crumbs = [];
131
+ this.persist();
132
+ }
133
+ }
134
+ setUser(user) {
135
+ if (!user) return void (this.user = void 0);
136
+ const u = {};
137
+ if (user.id !== void 0 && user.id !== null) u.id = truncate(String(user.id), 128);
138
+ if (user.email) u.email = truncate(user.email, 256);
139
+ if (user.username) u.username = truncate(user.username, 128);
140
+ this.user = Object.keys(u).length ? u : void 0;
141
+ }
142
+ setTag(key, value) {
143
+ const k = truncate(String(key).replace(TAG_KEY, "_"), 64);
144
+ if (k && (k in this.tags || Object.keys(this.tags).length < 32)) this.tags[k] = truncate(String(value), 256);
145
+ }
146
+ addBreadcrumb(crumb) {
147
+ if (!this.enabled) return;
148
+ this.crumbs.push(cleanCrumb(crumb, new Date(this.now()).toISOString()));
149
+ const max = Math.min(this.options.maxBreadcrumbs ?? 50, 100);
150
+ while (this.crumbs.length > max) this.crumbs.shift();
151
+ }
152
+ captureException(error, handled = true, level = "error") {
153
+ if (error && typeof error === "object") {
154
+ if (this.captured.has(error)) return void 0;
155
+ this.captured.add(error);
156
+ }
157
+ const err = error instanceof Error ? error : new Error(typeof error === "string" ? error : safeJson(error));
158
+ const exception = { type: truncate(err.name || "Error", 256), value: truncate(scrub(err.message || String(err)), 4096), handled };
159
+ const frames = parseStack(err.stack);
160
+ if (frames.length) exception.stacktrace = { frames };
161
+ return this.capture({ exception, level });
162
+ }
163
+ captureMessage(message, level = "info") {
164
+ return this.capture({ message: truncate(scrub(String(message)), 8192), level });
165
+ }
166
+ captureSecurity(kind, message, level, security) {
167
+ return this.capture({ message: truncate(message, 8192), level, ...security ? { security } : {}, tags: { "security.kind": truncate(kind, 256) } }, false);
168
+ }
169
+ capture(partial, filter = true) {
170
+ if (!this.enabled) return void 0;
171
+ if (filter && this.options.sampleRate !== void 0 && Math.random() >= this.options.sampleRate) return void 0;
172
+ const text2 = partial.exception?.value ?? partial.message ?? "";
173
+ if (filter && (this.options.ignoreErrors ?? []).some((p) => typeof p === "string" ? text2.includes(p) : p.test(text2))) return void 0;
174
+ let event = {
175
+ event_id: uuid32(),
176
+ timestamp: new Date(this.now()).toISOString(),
177
+ platform: "react-native",
178
+ level: "error",
179
+ environment: this.options.environment ?? "production",
180
+ sdk: { name: SDK_NAME, version: VERSION },
181
+ ...partial
182
+ };
183
+ if (this.options.release) event.release = truncate(this.options.release, 256);
184
+ if (this.user) event.user = { ...this.user };
185
+ const tags = { ...this.tags, ...partial.tags };
186
+ if (Object.keys(tags).length) event.tags = tags;
187
+ if (this.crumbs.length) event.breadcrumbs = [...this.crumbs];
188
+ const contexts2 = this.options.contexts?.();
189
+ if (contexts2 && Object.keys(contexts2).length) event.contexts = contexts2;
190
+ if (this.options.beforeSend) {
191
+ const out = this.options.beforeSend(event);
192
+ if (!out) return void 0;
193
+ event = out;
194
+ }
195
+ this.enqueue(event);
196
+ this.lastEventId = event.event_id;
197
+ if (event.exception) this.onError?.(!event.exception.handled);
198
+ return event.event_id;
199
+ }
200
+ enqueue(event) {
201
+ if (!this.enabled) return false;
202
+ this.queue.push(event);
203
+ while (this.queue.length > QUEUE_MAX) this.queue.shift();
204
+ this.persist();
205
+ this.schedule(1e3);
206
+ return true;
207
+ }
208
+ persist() {
209
+ try {
210
+ this.options.store?.save(JSON.stringify(this.queue));
211
+ } catch {
212
+ }
213
+ }
214
+ schedule(ms) {
215
+ if (this.timer) return;
216
+ this.timer = setTimeout(() => {
217
+ this.timer = void 0;
218
+ void this.flush();
219
+ }, Math.max(ms, this.pausedUntil - this.now()));
220
+ this.timer.unref?.();
221
+ }
222
+ async flush() {
223
+ while (this.sending) await this.sending;
224
+ this.sending = this.drain().finally(() => this.sending = void 0);
225
+ return this.sending;
226
+ }
227
+ async drain() {
228
+ while (this.queue.length && this.enabled && this.now() >= this.pausedUntil) {
229
+ const event = this.queue[0];
230
+ const verdict = await this.send(event);
231
+ if (verdict === "retry") return this.schedule(3e4);
232
+ if (verdict === "wait") return this.schedule(0);
233
+ if (this.queue[0] === event) this.queue.shift();
234
+ this.persist();
235
+ }
236
+ }
237
+ post(path, body) {
238
+ return this.fetcher(this.url(path), { method: "POST", headers: { "Content-Type": "application/json", "X-Blipit-Key": this.key }, body: JSON.stringify(body) });
239
+ }
240
+ async send(event) {
241
+ try {
242
+ const res = await this.post("/api/v1/events", event);
243
+ if (res.status === 429) {
244
+ const header = Number(res.headers?.get?.("retry-after"));
245
+ let seconds = Number.isFinite(header) && header > 0 ? header : 0;
246
+ if (!seconds) {
247
+ try {
248
+ seconds = Number(JSON.parse(await res.text()).retry_after) || 60;
249
+ } catch {
250
+ seconds = 60;
251
+ }
252
+ }
253
+ this.pausedUntil = this.now() + Math.min(seconds, 3600) * 1e3;
254
+ return "wait";
255
+ }
256
+ if (res.status >= 500) return "retry";
257
+ if (res.status >= 400 && this.options.debug) console.warn("[blipit] event rejected", res.status);
258
+ return "done";
259
+ } catch {
260
+ return "retry";
261
+ }
262
+ }
263
+ };
264
+ var RANK = { ok: 0, errored: 1, crashed: 2 };
265
+ var Session = class {
266
+ sid = "";
267
+ started = "";
268
+ status = "ok";
269
+ errors = 0;
270
+ core;
271
+ release;
272
+ environment;
273
+ constructor(core2, release, environment) {
274
+ this.core = core2;
275
+ this.release = release;
276
+ this.environment = environment;
277
+ }
278
+ start() {
279
+ if (this.sid) return;
280
+ this.sid = uuid32();
281
+ this.started = (/* @__PURE__ */ new Date()).toISOString();
282
+ this.status = "ok";
283
+ this.errors = 0;
284
+ this.send(false);
285
+ }
286
+ end() {
287
+ if (!this.sid) return;
288
+ this.send(true);
289
+ this.sid = "";
290
+ }
291
+ markError(unhandled) {
292
+ if (!this.sid) return;
293
+ this.errors += 1;
294
+ const next = unhandled ? "crashed" : "errored";
295
+ if (RANK[next] <= RANK[this.status]) return;
296
+ this.status = next;
297
+ this.send(false);
298
+ }
299
+ send(ending) {
300
+ if (!this.core.enabled) return;
301
+ const did = this.core.user?.id ?? this.core.user?.email;
302
+ const status = this.status === "ok" && ending ? "exited" : this.status;
303
+ this.core.post("/api/v1/sessions", { sid: this.sid, did, status, errors: this.errors, started: this.started, release: this.release, environment: this.environment }).catch(() => void 0);
304
+ }
305
+ };
306
+ function safeJson(v) {
307
+ try {
308
+ return JSON.stringify(v) ?? String(v);
309
+ } catch {
310
+ return String(v);
311
+ }
312
+ }
313
+
314
+ // src/instrument.ts
315
+ var done = /* @__PURE__ */ new WeakSet();
316
+ function instrument(core2, g = globalThis) {
317
+ if (done.has(g)) return;
318
+ done.add(g);
319
+ const eu = g.ErrorUtils;
320
+ if (eu?.setGlobalHandler) {
321
+ const prev = eu.getGlobalHandler?.();
322
+ eu.setGlobalHandler((error, isFatal) => {
323
+ const c = core2();
324
+ c?.captureException(error, false, isFatal ? "fatal" : "error");
325
+ if (isFatal) void c?.flush();
326
+ prev?.(error, isFatal);
327
+ });
328
+ }
329
+ const onUnhandled = (_id, reason) => void core2()?.captureException(reason, false);
330
+ if (g.HermesInternal?.enablePromiseRejectionTracker) {
331
+ g.HermesInternal.enablePromiseRejectionTracker({ allRejections: true, onUnhandled });
332
+ } else {
333
+ try {
334
+ require("promise/setimmediate/rejection-tracking").enable({ allRejections: true, onUnhandled });
335
+ } catch {
336
+ }
337
+ }
338
+ for (const level of ["warn", "error"]) {
339
+ const original = g.console[level];
340
+ if (typeof original !== "function") continue;
341
+ g.console[level] = (...args) => {
342
+ const message = truncate(args.map((a) => typeof a === "string" ? a : a instanceof Error ? a.message : json(a)).join(" "), 1024);
343
+ if (!message.startsWith("[blipit]")) core2()?.addBreadcrumb({ category: "console", level: level === "warn" ? "warning" : "error", message });
344
+ original.apply(g.console, args);
345
+ };
346
+ }
347
+ const proto = g.XMLHttpRequest?.prototype;
348
+ if (proto?.open && proto.send) {
349
+ const open = proto.open;
350
+ const send = proto.send;
351
+ proto.open = function(method, url, ...rest) {
352
+ this._blipit = [String(method).toUpperCase(), String(url)];
353
+ return open.call(this, method, url, ...rest);
354
+ };
355
+ proto.send = function(...args) {
356
+ const meta = this._blipit;
357
+ const c = core2();
358
+ if (c && meta && !meta[1].startsWith(c.endpoint)) {
359
+ const start = Date.now();
360
+ this.addEventListener?.("loadend", () => {
361
+ const status = this.status;
362
+ const url = meta[1].replace(/[?#].*$/, "");
363
+ c.addBreadcrumb({
364
+ category: "http",
365
+ level: !status || status >= 400 ? "error" : "info",
366
+ message: `${meta[0]} ${url} -> ${status || "network error"}`,
367
+ data: { url, method: meta[0], status_code: status || void 0, duration_ms: Date.now() - start }
368
+ });
369
+ });
370
+ }
371
+ return send.apply(this, args);
372
+ };
373
+ }
374
+ }
375
+ function trackNavigation(core2, ref) {
376
+ let last;
377
+ const seen = () => {
378
+ const name = ref.getCurrentRoute()?.name;
379
+ if (!name || name === last) return;
380
+ core2()?.addBreadcrumb({ category: "navigation", message: `Navigated to ${name}`, data: { from: last, to: name } });
381
+ last = name;
382
+ };
383
+ seen();
384
+ return ref.addListener("state", seen);
385
+ }
386
+ function json(v) {
387
+ try {
388
+ return JSON.stringify(v) ?? String(v);
389
+ } catch {
390
+ return String(v);
391
+ }
392
+ }
393
+
394
+ // src/native.ts
395
+ var import_react_native = require("react-native");
396
+ var bridge = () => import_react_native.NativeModules.BlipitNuggets;
397
+ function nativeInfo() {
398
+ const b = bridge();
399
+ try {
400
+ return b?.getConstants?.() ?? b ?? {};
401
+ } catch {
402
+ return {};
403
+ }
404
+ }
405
+ function nativeStore() {
406
+ const b = bridge();
407
+ if (!b?.save || !b.load) return void 0;
408
+ return {
409
+ load: () => {
410
+ try {
411
+ return b.load();
412
+ } catch {
413
+ return null;
414
+ }
415
+ },
416
+ save: (data) => void b.save(data)
417
+ };
418
+ }
419
+ function defaultRelease(info) {
420
+ if (!info.appId || !info.appVersion) return void 0;
421
+ return `${info.appId}@${info.appVersion}${info.appBuild ? `+${info.appBuild}` : ""}`;
422
+ }
423
+
424
+ // src/boundary.ts
425
+ var import_react = require("react");
426
+ var report = () => void 0;
427
+ function setBoundaryReporter(fn) {
428
+ report = fn;
429
+ }
430
+ var ErrorBoundary = class extends import_react.Component {
431
+ state = { error: null };
432
+ static getDerivedStateFromError(error) {
433
+ return { error };
434
+ }
435
+ componentDidCatch(error) {
436
+ const id = report(error);
437
+ this.props.onError?.(error, id);
438
+ }
439
+ resetError = () => this.setState({ error: null });
440
+ render() {
441
+ if (this.state.error === null) return this.props.children ?? null;
442
+ const { fallback } = this.props;
443
+ if (typeof fallback === "function") return fallback({ error: this.state.error, resetError: this.resetError });
444
+ if (fallback === void 0) throw this.state.error;
445
+ return fallback;
446
+ }
447
+ };
448
+ function wrap(Root, options = {}) {
449
+ const Wrapped = (props) => (0, import_react.createElement)(ErrorBoundary, options, (0, import_react.createElement)(Root, props));
450
+ Wrapped.displayName = `Blipit(${Root.displayName ?? Root.name ?? "App"})`;
451
+ return Wrapped;
452
+ }
56
453
 
57
454
  // src/report-strings.ts
58
455
  var REPORT_STRINGS = {
@@ -473,8 +870,8 @@ var ReportClient = class {
473
870
  this.key = key;
474
871
  this.fetcher = fetcher;
475
872
  }
476
- async call(path, init3) {
477
- const res = await this.fetcher(`${this.endpoint}${path}`, { ...init3, headers: { "X-Blipit-Key": this.key, ...init3.headers } });
873
+ async call(path, init2) {
874
+ const res = await this.fetcher(`${this.endpoint}${path}`, { ...init2, headers: { "X-Blipit-Key": this.key, ...init2.headers } });
478
875
  const text2 = await res.text();
479
876
  if (!res.ok) throw new Error(`Blipit returned ${res.status}`);
480
877
  return text2;
@@ -487,9 +884,9 @@ var ReportClient = class {
487
884
  return res.ok || res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429;
488
885
  }
489
886
  async send(body) {
490
- const json = JSON.parse(await this.call("/api/v1/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }));
491
- if (typeof json.upload_token !== "string") throw new Error("Blipit returned no upload token");
492
- return { id: String(json.id), token: json.upload_token, ref: typeof json.ref === "string" ? json.ref : null };
887
+ const json2 = JSON.parse(await this.call("/api/v1/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }));
888
+ if (typeof json2.upload_token !== "string") throw new Error("Blipit returned no upload token");
889
+ return { id: String(json2.id), token: json2.upload_token, ref: typeof json2.ref === "string" ? json2.ref : null };
493
890
  }
494
891
  async uploadScreenshot(receipt, data, type) {
495
892
  await this.call(`/api/v1/feedback/${encodeURIComponent(receipt.id)}/screenshot?position=0`, { method: "POST", headers: { "Content-Type": type, "X-Blipit-Upload": receipt.token }, body: data });
@@ -671,8 +1068,8 @@ function createStuck(transport, info, clock = Date.now) {
671
1068
  }
672
1069
 
673
1070
  // src/reporter.tsx
674
- var import_react = require("react");
675
- var import_react_native = require("react-native");
1071
+ var import_react2 = require("react");
1072
+ var import_react_native2 = require("react-native");
676
1073
  var import_jsx_runtime = require("react/jsx-runtime");
677
1074
  var C = { navy: "#0B1A3A", card: "#1A2135", brand: "#3882F6", muted: "#98A6BE", mark: "#FF3B30", danger: "#FF7A6E", white: "#FFFFFF" };
678
1075
  var opener = null;
@@ -700,14 +1097,14 @@ var languages = () => {
700
1097
  }
701
1098
  };
702
1099
  function BlipitReporter({ children, showButton = false }) {
703
- const lang = (0, import_react.useMemo)(() => pickLang(languages()), []);
1100
+ const lang = (0, import_react2.useMemo)(() => pickLang(languages()), []);
704
1101
  const t = (key) => text(key, lang);
705
- const [stage, setStage] = (0, import_react.useState)("closed");
706
- const [shot, setShot] = (0, import_react.useState)(null);
707
- const [flat, setFlat] = (0, import_react.useState)(null);
708
- const [notice, setNotice] = (0, import_react.useState)(null);
709
- const shapes = (0, import_react.useRef)([]);
710
- (0, import_react.useEffect)(() => {
1102
+ const [stage, setStage] = (0, import_react2.useState)("closed");
1103
+ const [shot, setShot] = (0, import_react2.useState)(null);
1104
+ const [flat, setFlat] = (0, import_react2.useState)(null);
1105
+ const [notice, setNotice] = (0, import_react2.useState)(null);
1106
+ const shapes = (0, import_react2.useRef)([]);
1107
+ (0, import_react2.useEffect)(() => {
711
1108
  opener = () => {
712
1109
  shapes.current = [];
713
1110
  setShot(null);
@@ -726,7 +1123,7 @@ function BlipitReporter({ children, showButton = false }) {
726
1123
  try {
727
1124
  if (!shooter) throw new Error("react-native-view-shot is not installed");
728
1125
  const uri = await shooter.captureScreen({ format: "jpg", quality: 0.9, result: "tmpfile" });
729
- const size = await new Promise((ok, fail) => import_react_native.Image.getSize(uri, (width, height) => ok({ width, height }), fail));
1126
+ const size = await new Promise((ok, fail) => import_react_native2.Image.getSize(uri, (width, height) => ok({ width, height }), fail));
730
1127
  setShot({ uri, ...size });
731
1128
  setStage("editor");
732
1129
  } catch (err) {
@@ -735,17 +1132,17 @@ function BlipitReporter({ children, showButton = false }) {
735
1132
  setStage("details");
736
1133
  }
737
1134
  };
738
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: { flex: 1 }, children: [
1135
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: { flex: 1 }, children: [
739
1136
  children,
740
- showButton && stage === "closed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: () => opener?.(), style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
741
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.fabIcon, children: "!" }),
742
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.fabText, children: t("title") })
1137
+ showButton && stage === "closed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: () => opener?.(), style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
1138
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.fabIcon, children: "!" }),
1139
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.fabText, children: t("title") })
743
1140
  ] }) : null,
744
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Modal, { visible: stage !== "closed", animationType: "none", presentationStyle: "fullScreen", onRequestClose: () => setStage(stage === "details" && shot ? "editor" : stage === "choice" ? "closed" : "choice"), statusBarTranslucent: false, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.SafeAreaView, { style: [s.screen, { direction: lang === "ar" ? "rtl" : import_react_native.I18nManager.isRTL ? "rtl" : "ltr" }], children: [
745
- stage === "choice" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: s.pad, children: [
1141
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Modal, { visible: stage !== "closed", animationType: "none", presentationStyle: "fullScreen", onRequestClose: () => setStage(stage === "details" && shot ? "editor" : stage === "choice" ? "closed" : "choice"), statusBarTranslucent: false, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.SafeAreaView, { style: [s.screen, { direction: lang === "ar" ? "rtl" : import_react_native2.I18nManager.isRTL ? "rtl" : "ltr" }], children: [
1142
+ stage === "choice" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: s.pad, children: [
746
1143
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Bar, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarButton, { label: t("close"), glyph: "\u2715", onPress: () => setStage("closed") }) }),
747
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: s.center, children: [
748
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.h1, children: t("mHow") }),
1144
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: s.center, children: [
1145
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.h1, children: t("mHow") }),
749
1146
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card, { title: t("mShot"), glyph: "\u25CE", onPress: capture }),
750
1147
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
751
1148
  Card,
@@ -790,42 +1187,42 @@ function BlipitReporter({ children, showButton = false }) {
790
1187
  ] });
791
1188
  }
792
1189
  function Bar({ children }) {
793
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: s.bar, children });
1190
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: s.bar, children });
794
1191
  }
795
1192
  function BarButton({ label, glyph, onPress }) {
796
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.Pressable, { accessibilityRole: "button", accessibilityLabel: label, onPress, style: s.barButton, hitSlop: 6, children: [
797
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.glyph, children: glyph }),
798
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.barText, numberOfLines: 1, children: label })
1193
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: label, onPress, style: s.barButton, hitSlop: 6, children: [
1194
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.glyph, children: glyph }),
1195
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.barText, numberOfLines: 1, children: label })
799
1196
  ] });
800
1197
  }
801
1198
  function Primary({ label, onPress, disabled }) {
802
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { disabled }, disabled, onPress, style: [s.primary, disabled && { opacity: 0.6 }], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.primaryText, children: label }) });
1199
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { disabled }, disabled, onPress, style: [s.primary, disabled && { opacity: 0.6 }], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.primaryText, children: label }) });
803
1200
  }
804
1201
  function Card({ title, glyph, onPress }) {
805
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.Pressable, { accessibilityRole: "button", accessibilityLabel: title, onPress, style: ({ pressed }) => [s.card, pressed && { opacity: 0.85 }], children: [
806
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.cardGlyph, children: glyph }),
807
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.cardText, children: title })
1202
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: title, onPress, style: ({ pressed }) => [s.card, pressed && { opacity: 0.85 }], children: [
1203
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.cardGlyph, children: glyph }),
1204
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.cardText, children: title })
808
1205
  ] });
809
1206
  }
810
1207
  function Editor({ shot, shapes, t, onBack, onNext }) {
811
- const [view, setView] = (0, import_react.useState)({ width: 0, height: 0, x: 0, y: 0 });
812
- const [zoom, setZoom] = (0, import_react.useState)(1);
813
- const [pan, setPan] = (0, import_react.useState)({ x: 0, y: 0 });
814
- const [tool, setTool] = (0, import_react.useState)("pen");
815
- const [current, setCurrent] = (0, import_react.useState)(null);
816
- const [, redraw] = (0, import_react.useState)(0);
817
- const [busy, setBusy] = (0, import_react.useState)(false);
818
- const box = (0, import_react.useRef)(null);
819
- const content = (0, import_react.useRef)(null);
820
- const live = (0, import_react.useRef)({ zoom, pan, view, tool, current, gesture: null, lastTap: 0, moved: false });
1208
+ const [view, setView] = (0, import_react2.useState)({ width: 0, height: 0, x: 0, y: 0 });
1209
+ const [zoom, setZoom] = (0, import_react2.useState)(1);
1210
+ const [pan, setPan] = (0, import_react2.useState)({ x: 0, y: 0 });
1211
+ const [tool, setTool] = (0, import_react2.useState)("pen");
1212
+ const [current, setCurrent] = (0, import_react2.useState)(null);
1213
+ const [, redraw] = (0, import_react2.useState)(0);
1214
+ const [busy, setBusy] = (0, import_react2.useState)(false);
1215
+ const box = (0, import_react2.useRef)(null);
1216
+ const content = (0, import_react2.useRef)(null);
1217
+ const live = (0, import_react2.useRef)({ zoom, pan, view, tool, current, gesture: null, lastTap: 0, moved: false });
821
1218
  live.current.zoom = zoom;
822
1219
  live.current.pan = pan;
823
1220
  live.current.view = view;
824
1221
  live.current.tool = tool;
825
1222
  const image = { width: shot.width, height: shot.height };
826
1223
  const local = (e) => e.nativeEvent.touches.map((touch) => ({ x: touch.pageX - live.current.view.x, y: touch.pageY - live.current.view.y }));
827
- const responder = (0, import_react.useMemo)(
828
- () => import_react_native.PanResponder.create({
1224
+ const responder = (0, import_react2.useMemo)(
1225
+ () => import_react_native2.PanResponder.create({
829
1226
  onStartShouldSetPanResponder: () => true,
830
1227
  onMoveShouldSetPanResponder: () => true,
831
1228
  onPanResponderTerminationRequest: () => false,
@@ -926,22 +1323,22 @@ function Editor({ shot, shapes, t, onBack, onNext }) {
926
1323
  ["rect", t("rect"), "\u25A2"],
927
1324
  ["arrow", t("arrow"), "\u2197"]
928
1325
  ];
929
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: { flex: 1 }, children: [
1326
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: { flex: 1 }, children: [
930
1327
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Bar, { children: [
931
1328
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarButton, { label: t("mBack"), glyph: "\u2039", onPress: onBack }),
932
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: { flex: 1 } }),
1329
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: { flex: 1 } }),
933
1330
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconButton, { label: t("mZoomOut"), glyph: "\u2212", onPress: () => zoomBy(1 / 1.5) }),
934
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.Text, { style: s.zoom, children: [
1331
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.Text, { style: s.zoom, children: [
935
1332
  Math.round(zoom * 100),
936
1333
  "%"
937
1334
  ] }),
938
1335
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconButton, { label: t("mZoomIn"), glyph: "+", onPress: () => zoomBy(1.5) }),
939
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: { flex: 1 } }),
940
- busy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.ActivityIndicator, { color: C.white, style: { marginHorizontal: 8 } }) : null,
1336
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: { flex: 1 } }),
1337
+ busy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.ActivityIndicator, { color: C.white, style: { marginHorizontal: 8 } }) : null,
941
1338
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primary, { label: t("mNext"), onPress: next, disabled: busy })
942
1339
  ] }),
943
1340
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
944
- import_react_native.View,
1341
+ import_react_native2.View,
945
1342
  {
946
1343
  ref: box,
947
1344
  style: s.stage,
@@ -951,13 +1348,13 @@ function Editor({ shot, shapes, t, onBack, onNext }) {
951
1348
  setView((v) => ({ ...v, width: w, height: h }));
952
1349
  },
953
1350
  ...responder.panHandlers,
954
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { ref: content, collapsable: false, style: { position: "absolute", left: o.x, top: o.y, width: shot.width * scale, height: shot.height * scale }, pointerEvents: "none", children: [
955
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Image, { source: { uri: shot.uri }, style: import_react_native.StyleSheet.absoluteFill, resizeMode: "stretch" }),
1351
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { ref: content, collapsable: false, style: { position: "absolute", left: o.x, top: o.y, width: shot.width * scale, height: shot.height * scale }, pointerEvents: "none", children: [
1352
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Image, { source: { uri: shot.uri }, style: import_react_native2.StyleSheet.absoluteFill, resizeMode: "stretch" }),
956
1353
  [...shapes.current, ...current ? [current] : []].map((shape, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mark, { shape, scale, width: width * scale }, i))
957
1354
  ] })
958
1355
  }
959
1356
  ),
960
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: s.tools, children: [
1357
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: s.tools, children: [
961
1358
  tools.map(([id, label, glyph]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolButton, { label, glyph, on: tool === id, onPress: () => setTool(id) }, id)),
962
1359
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
963
1360
  ToolButton,
@@ -990,12 +1387,12 @@ function Mark({ shape, scale, width }) {
990
1387
  const ay = a2.y * scale;
991
1388
  const len = Math.hypot(b2.x * scale - ax, b2.y * scale - ay);
992
1389
  const angle = Math.atan2(b2.y * scale - ay, b2.x * scale - ax);
993
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: { position: "absolute", left: ax + (b2.x * scale - ax - len) / 2, top: ay + (b2.y * scale - ay) / 2 - width / 2, width: len, height: width, borderRadius: width / 2, backgroundColor: C.mark, transform: [{ rotate: `${angle}rad` }] } }, key);
1390
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: { position: "absolute", left: ax + (b2.x * scale - ax - len) / 2, top: ay + (b2.y * scale - ay) / 2 - width / 2, width: len, height: width, borderRadius: width / 2, backgroundColor: C.mark, transform: [{ rotate: `${angle}rad` }] } }, key);
994
1391
  };
995
1392
  const a = shape.points[0];
996
1393
  const b = shape.points[shape.points.length - 1];
997
1394
  if (shape.tool === "rect") {
998
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: { position: "absolute", left: Math.min(a.x, b.x) * scale, top: Math.min(a.y, b.y) * scale, width: Math.abs(b.x - a.x) * scale, height: Math.abs(b.y - a.y) * scale, borderWidth: width, borderColor: C.mark } });
1395
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: { position: "absolute", left: Math.min(a.x, b.x) * scale, top: Math.min(a.y, b.y) * scale, width: Math.abs(b.x - a.x) * scale, height: Math.abs(b.y - a.y) * scale, borderWidth: width, borderColor: C.mark } });
999
1396
  }
1000
1397
  if (shape.tool === "arrow") {
1001
1398
  const angle = Math.atan2(b.y - a.y, b.x - a.x);
@@ -1006,20 +1403,20 @@ function Mark({ shape, scale, width }) {
1006
1403
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: shape.points.slice(1).map((p, i) => line(shape.points[i], p, i)) });
1007
1404
  }
1008
1405
  function IconButton({ label, glyph, onPress }) {
1009
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, { accessibilityRole: "button", accessibilityLabel: label, onPress, style: s.icon, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.iconText, children: glyph }) });
1406
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: label, onPress, style: s.icon, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.iconText, children: glyph }) });
1010
1407
  }
1011
1408
  function ToolButton({ label, glyph, on, onPress }) {
1012
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: !!on }, onPress, style: [s.tool, on && { backgroundColor: C.brand }], children: [
1013
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [s.toolGlyph, { color: on ? C.white : C.muted }], children: glyph }),
1014
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [s.toolText, { color: on ? C.white : C.muted }], numberOfLines: 1, children: label })
1409
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: !!on }, onPress, style: [s.tool, on && { backgroundColor: C.brand }], children: [
1410
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [s.toolGlyph, { color: on ? C.white : C.muted }], children: glyph }),
1411
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [s.toolText, { color: on ? C.white : C.muted }], numberOfLines: 1, children: label })
1015
1412
  ] });
1016
1413
  }
1017
1414
  function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1018
- const [title, setTitle] = (0, import_react.useState)("");
1019
- const [message, setMessage] = (0, import_react.useState)("");
1020
- const [email, setEmail] = (0, import_react.useState)("");
1021
- const [status, setStatus] = (0, import_react.useState)(notice ? { text: notice, error: true } : { text: "", error: false });
1022
- const [busy, setBusy] = (0, import_react.useState)(false);
1415
+ const [title, setTitle] = (0, import_react2.useState)("");
1416
+ const [message, setMessage] = (0, import_react2.useState)("");
1417
+ const [email, setEmail] = (0, import_react2.useState)("");
1418
+ const [status, setStatus] = (0, import_react2.useState)(notice ? { text: notice, error: true } : { text: "", error: false });
1419
+ const [busy, setBusy] = (0, import_react2.useState)(false);
1023
1420
  const image = flat ?? shot;
1024
1421
  const submit = async () => {
1025
1422
  if (busy || !config) return;
@@ -1040,8 +1437,8 @@ function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1040
1437
  uploaded = false;
1041
1438
  }
1042
1439
  }
1043
- const done = receipt.ref ? t("sentRef").replace("{ref}", receipt.ref) : t("sentTitle");
1044
- setStatus({ text: uploaded ? done : `${done} \xB7 ${t("noShot")}`, error: !uploaded });
1440
+ const done2 = receipt.ref ? t("sentRef").replace("{ref}", receipt.ref) : t("sentTitle");
1441
+ setStatus({ text: uploaded ? done2 : `${done2} \xB7 ${t("noShot")}`, error: !uploaded });
1045
1442
  setTimeout(onDone, 1600);
1046
1443
  } catch {
1047
1444
  setStatus({ text: t("error"), error: true });
@@ -1049,25 +1446,25 @@ function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1049
1446
  setBusy(false);
1050
1447
  }
1051
1448
  };
1052
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.KeyboardAvoidingView, { style: { flex: 1 }, behavior: import_react_native.Platform.OS === "ios" ? "padding" : void 0, children: [
1449
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.KeyboardAvoidingView, { style: { flex: 1 }, behavior: import_react_native2.Platform.OS === "ios" ? "padding" : void 0, children: [
1053
1450
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Bar, { children: [
1054
1451
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarButton, { label: t("mBack"), glyph: "\u2039", onPress: () => !busy && onBack() }),
1055
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: { flex: 1 } }),
1056
- busy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.ActivityIndicator, { color: C.white, style: { marginHorizontal: 10 } }) : null,
1452
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: { flex: 1 } }),
1453
+ busy ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.ActivityIndicator, { color: C.white, style: { marginHorizontal: 10 } }) : null,
1057
1454
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primary, { label: t("send"), onPress: submit, disabled: busy })
1058
1455
  ] }),
1059
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.ScrollView, { contentContainerStyle: { padding: 20, paddingTop: 8, gap: 12 }, keyboardShouldPersistTaps: "handled", children: [
1060
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: s.h2, children: t("title") }),
1061
- image ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Image, { source: { uri: image.uri }, style: s.preview, resizeMode: "contain", accessibilityIgnoresInvertColors: true }) : null,
1062
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.TextInput, { value: title, onChangeText: setTitle, placeholder: t("fTitle"), placeholderTextColor: C.muted, style: s.input, accessibilityLabel: t("fTitle") }),
1063
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.TextInput, { value: message, onChangeText: setMessage, placeholder: t("fDesc"), placeholderTextColor: C.muted, style: [s.input, { minHeight: 120, textAlignVertical: "top" }], multiline: true, accessibilityLabel: t("fDesc") }),
1064
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.TextInput, { value: email, onChangeText: setEmail, placeholder: t("email"), placeholderTextColor: C.muted, style: s.input, keyboardType: "email-address", autoCapitalize: "none", autoCorrect: false, accessibilityLabel: t("email") }),
1065
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { accessibilityLiveRegion: "polite", style: { color: status.error ? C.danger : C.muted, fontSize: 14 }, children: status.text })
1456
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.ScrollView, { contentContainerStyle: { padding: 20, paddingTop: 8, gap: 12 }, keyboardShouldPersistTaps: "handled", children: [
1457
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.h2, children: t("title") }),
1458
+ image ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Image, { source: { uri: image.uri }, style: s.preview, resizeMode: "contain", accessibilityIgnoresInvertColors: true }) : null,
1459
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.TextInput, { value: title, onChangeText: setTitle, placeholder: t("fTitle"), placeholderTextColor: C.muted, style: s.input, accessibilityLabel: t("fTitle") }),
1460
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.TextInput, { value: message, onChangeText: setMessage, placeholder: t("fDesc"), placeholderTextColor: C.muted, style: [s.input, { minHeight: 120, textAlignVertical: "top" }], multiline: true, accessibilityLabel: t("fDesc") }),
1461
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.TextInput, { value: email, onChangeText: setEmail, placeholder: t("email"), placeholderTextColor: C.muted, style: s.input, keyboardType: "email-address", autoCapitalize: "none", autoCorrect: false, accessibilityLabel: t("email") }),
1462
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { accessibilityLiveRegion: "polite", style: { color: status.error ? C.danger : C.muted, fontSize: 14 }, children: status.text })
1066
1463
  ] })
1067
1464
  ] });
1068
1465
  }
1069
- var s = import_react_native.StyleSheet.create({
1070
- screen: { flex: 1, backgroundColor: C.navy, paddingTop: import_react_native.Platform.OS === "android" ? import_react_native.StatusBar.currentHeight ?? 0 : 0 },
1466
+ var s = import_react_native2.StyleSheet.create({
1467
+ screen: { flex: 1, backgroundColor: C.navy, paddingTop: import_react_native2.Platform.OS === "android" ? import_react_native2.StatusBar.currentHeight ?? 0 : 0 },
1071
1468
  pad: { flex: 1, paddingHorizontal: 20 },
1072
1469
  center: { flex: 1, justifyContent: "center", gap: 14 },
1073
1470
  h1: { color: C.white, fontSize: 24, fontWeight: "700", marginBottom: 8 },
@@ -1097,29 +1494,13 @@ var s = import_react_native.StyleSheet.create({
1097
1494
  });
1098
1495
 
1099
1496
  // src/index.ts
1100
- var import_react_native3 = require("@sentry/react-native");
1101
- var DEFAULT_ENDPOINT = "https://in.blipit.io";
1102
- var VERSION = "0.4.0";
1103
- var PACKAGE = { name: "npm:@blipit/react-native", version: VERSION };
1104
- function withIdentity(user) {
1105
- return (event, hint) => {
1106
- try {
1107
- const sdk = event.sdk ??= {};
1108
- const packages = sdk.packages ?? [];
1109
- if (!packages.some((p) => p?.name === PACKAGE.name)) sdk.packages = [...packages, { ...PACKAGE }];
1110
- } catch {
1111
- }
1112
- return user ? user(event, hint) : event;
1113
- };
1114
- }
1115
- function dsn(key, project, endpoint = DEFAULT_ENDPOINT) {
1116
- const host = endpoint.split("://").pop().replace(/\/+$/, "");
1117
- const scheme = endpoint.startsWith("http://") ? "http" : "https";
1118
- return `${scheme}://${key}@${host}/${project}`;
1119
- }
1497
+ var SECURITY_KINDS = ["login_failed", "login_succeeded", "login_blocked", "password_reset_requested", "privilege_granted"];
1120
1498
  var MISSING_KEY = "[blipit] Blipit.init got no key, so Blipit is off and nothing is sent. Pass the project's public key (app.blipit.io, Keys); with Expo, check that EXPO_PUBLIC_BLIPIT_KEY is set at build time.";
1121
1499
  var MISSING_PROJECT = "[blipit] Blipit.init got no project id, so Blipit is off and nothing is sent. Pass project with the id from the project's Keys page at app.blipit.io.";
1122
- function init2(options) {
1500
+ var core;
1501
+ var session;
1502
+ var appState;
1503
+ function init(options) {
1123
1504
  const { key, publicKey, project, endpoint, waitForReady, ...rest } = options ?? {};
1124
1505
  const k = (key ?? publicKey ?? "").trim();
1125
1506
  if (!k) {
@@ -1130,28 +1511,57 @@ function init2(options) {
1130
1511
  console.warn(MISSING_PROJECT);
1131
1512
  return false;
1132
1513
  }
1133
- Sentry.init({
1134
- dsn: dsn(k, project, endpoint),
1135
- sendDefaultPii: false,
1136
- tracesSampleRate: 0,
1137
- ...rest,
1138
- beforeSend: withIdentity(rest.beforeSend)
1514
+ const info = nativeInfo();
1515
+ const release = rest.release ?? defaultRelease(info);
1516
+ const base = endpoint ?? DEFAULT_ENDPOINT;
1517
+ session?.end();
1518
+ appState?.remove();
1519
+ core = new Nuggets({ ...rest, key: k, endpoint: base, release, store: nativeStore(), contexts: () => contexts(info.model, info.osVersion) });
1520
+ const c = core;
1521
+ setBoundaryReporter((error) => c.captureException(error, false));
1522
+ instrument(() => core);
1523
+ const native = rest.enableNative !== false ? bridge() : void 0;
1524
+ try {
1525
+ native?.start(k, String(project), rest.environment ?? null, release ?? null, c.endpoint);
1526
+ } catch {
1527
+ }
1528
+ session = release && rest.autoSessionTracking !== false ? new Session(c, release, rest.environment ?? "production") : void 0;
1529
+ c.onError = (unhandled) => session?.markError(unhandled);
1530
+ if (c.enabled) session?.start();
1531
+ appState = import_react_native3.AppState?.addEventListener?.("change", (state) => {
1532
+ if (state === "active") {
1533
+ if (c.enabled) session?.start();
1534
+ void c.flush();
1535
+ } else if (state === "background") {
1536
+ session?.end();
1537
+ void c.flush();
1538
+ }
1139
1539
  });
1140
- const client = new ReportClient(endpoint ?? DEFAULT_ENDPOINT, k);
1141
- configureReporter(client, () => deviceContext(rest.release));
1540
+ void c.flush();
1541
+ const reports = new ReportClient(base, k);
1542
+ configureReporter(reports, () => deviceContext(release));
1543
+ reportClient = reports;
1142
1544
  if (!stuck) {
1143
- stuck = createStuck(client, { release: rest.release, environment: rest.environment, os: import_react_native2.Platform.OS, osVersion: String(import_react_native2.Platform.Version), version: VERSION });
1545
+ stuck = createStuck(
1546
+ {
1547
+ settings: () => reportClient ? reportClient.settings() : Promise.resolve(null),
1548
+ event: async (body) => (core?.enqueue(body), true)
1549
+ },
1550
+ { release, environment: rest.environment, os: import_react_native3.Platform.OS, osVersion: info.osVersion ?? String(import_react_native3.Platform.Version), version: VERSION }
1551
+ );
1144
1552
  try {
1145
- stuck.setForeground(import_react_native2.AppState.currentState !== "background");
1146
- import_react_native2.AppState.addEventListener("change", (state) => stuck?.setForeground(state !== "background"));
1553
+ stuck.setForeground(import_react_native3.AppState.currentState !== "background");
1554
+ import_react_native3.AppState.addEventListener("change", (state) => stuck?.setForeground(state !== "background"));
1147
1555
  } catch {
1148
1556
  stuck.setForeground(true);
1149
1557
  }
1150
1558
  if (waitForReady) stuck.start(STARTUP);
1151
1559
  }
1560
+ if (rest.debug) console.log(`[blipit] ${SDK_NAME}@${VERSION} initialized`);
1152
1561
  return true;
1153
1562
  }
1154
1563
  var stuck = null;
1564
+ var reportClient;
1155
1565
  function reportReady() {
1156
1566
  stuck?.end(STARTUP);
1157
1567
  }
@@ -1168,8 +1578,18 @@ function endFlow(name) {
1168
1578
  const flow = cleanName(name, 64);
1169
1579
  if (flow) stuck?.end(flow);
1170
1580
  }
1581
+ function contexts(model, osVersion) {
1582
+ const { width, height } = import_react_native3.Dimensions.get("window");
1583
+ const engine = globalThis.HermesInternal ? "hermes" : "jsc";
1584
+ const rn = import_react_native3.Platform.constants?.reactNativeVersion;
1585
+ return {
1586
+ os: { name: import_react_native3.Platform.OS, version: osVersion ?? String(import_react_native3.Platform.Version) },
1587
+ device: { ...model ? { model } : {}, screen: `${Math.round(width)}x${Math.round(height)}` },
1588
+ runtime: { name: engine, ...rn ? { version: `react-native ${rn.major}.${rn.minor}.${rn.patch}` } : {} }
1589
+ };
1590
+ }
1171
1591
  function deviceContext(release) {
1172
- const { width, height, scale } = import_react_native2.Dimensions.get("window");
1592
+ const { width, height, scale } = import_react_native3.Dimensions.get("window");
1173
1593
  let language = "";
1174
1594
  let timezone = "";
1175
1595
  try {
@@ -1180,11 +1600,17 @@ function deviceContext(release) {
1180
1600
  }
1181
1601
  return {
1182
1602
  platform: "react-native",
1183
- sdk: { name: PACKAGE.name, version: VERSION },
1603
+ sdk: { name: `npm:${SDK_NAME}`, version: VERSION },
1184
1604
  ...release ? { app: { release } } : {},
1185
- device: { os: import_react_native2.Platform.OS, os_version: String(import_react_native2.Platform.Version), screen: `${Math.round(width)}x${Math.round(height)}`, dpr: scale, language, timezone, touch: true }
1605
+ device: { os: import_react_native3.Platform.OS, os_version: String(import_react_native3.Platform.Version), screen: `${Math.round(width)}x${Math.round(height)}`, dpr: scale, language, timezone, touch: true }
1186
1606
  };
1187
1607
  }
1608
+ function captureException(error) {
1609
+ return core?.captureException(error, true);
1610
+ }
1611
+ function captureMessage(message, level = "info") {
1612
+ return core?.captureMessage(message, level);
1613
+ }
1188
1614
  function captureSecurity(kind, actor, details = {}) {
1189
1615
  const context = { kind, actor };
1190
1616
  const extra = { outcome: details.outcome, actor_id: details.actorId, ip: details.ip, user_agent: details.userAgent, target: details.target };
@@ -1192,31 +1618,81 @@ function captureSecurity(kind, actor, details = {}) {
1192
1618
  if (v !== void 0 && v !== null) context[k] = v;
1193
1619
  }
1194
1620
  const level = kind === "login_failed" || kind === "login_blocked" ? "warning" : "info";
1195
- Sentry.withScope((scope) => {
1196
- scope.setContext("security", context);
1197
- scope.setTag("security.kind", kind);
1198
- Sentry.captureMessage(`${kind} for ${actor}`, level);
1199
- });
1621
+ return core?.captureSecurity(kind, `${kind} for ${actor}`, level, SECURITY_KINDS.includes(kind) && actor ? context : void 0);
1622
+ }
1623
+ function setUser(user) {
1624
+ core?.setUser(user);
1625
+ const u = core?.user;
1626
+ try {
1627
+ bridge()?.setUser(u?.id ?? null, u?.email ?? null, u?.username ?? null);
1628
+ } catch {
1629
+ }
1630
+ }
1631
+ function setTag(key, value) {
1632
+ core?.setTag(key, value);
1633
+ try {
1634
+ bridge()?.setTag(key, String(value));
1635
+ } catch {
1636
+ }
1637
+ }
1638
+ function addBreadcrumb(crumb) {
1639
+ core?.addBreadcrumb(crumb);
1640
+ }
1641
+ async function flush(timeout = 2e3) {
1642
+ if (!core) return true;
1643
+ const c = core;
1644
+ let timer;
1645
+ const late = new Promise((r) => timer = setTimeout(() => r(false), timeout));
1646
+ const ok = await Promise.race([c.flush().then(() => c.pending === 0), late]);
1647
+ clearTimeout(timer);
1648
+ return ok;
1649
+ }
1650
+ function setEnabled(on) {
1651
+ if (!core) return;
1652
+ core.setEnabled(on);
1653
+ if (on) session?.start();
1654
+ else session?.end();
1655
+ }
1656
+ var isEnabled = () => core?.enabled ?? false;
1657
+ var lastEventId = () => core?.lastEventId;
1658
+ function setReplayConsent(granted) {
1659
+ try {
1660
+ bridge()?.setReplayConsent(granted);
1661
+ } catch {
1662
+ }
1663
+ }
1664
+ function hasReplayConsent() {
1665
+ try {
1666
+ return bridge()?.hasReplayConsent() === true;
1667
+ } catch {
1668
+ return false;
1669
+ }
1200
1670
  }
1671
+ var trackNavigation2 = (ref) => trackNavigation(() => core, ref);
1201
1672
  // Annotate the CommonJS export names for ESM import in node:
1202
1673
  0 && (module.exports = {
1203
1674
  BlipitReporter,
1204
1675
  DEFAULT_ENDPOINT,
1676
+ ErrorBoundary,
1205
1677
  VERSION,
1206
1678
  addBreadcrumb,
1207
1679
  captureException,
1208
1680
  captureMessage,
1209
1681
  captureSecurity,
1210
- dsn,
1211
1682
  endFlow,
1212
1683
  flowStep,
1213
1684
  flush,
1685
+ hasReplayConsent,
1214
1686
  init,
1687
+ isEnabled,
1688
+ lastEventId,
1215
1689
  reportReady,
1690
+ setEnabled,
1691
+ setReplayConsent,
1216
1692
  setTag,
1217
1693
  setUser,
1218
1694
  showReport,
1219
1695
  startFlow,
1220
- withIdentity,
1696
+ trackNavigation,
1221
1697
  wrap
1222
1698
  });