@hamster-note/reader 0.2.0-beta.1

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +267 -0
  3. package/dist/components/IntermediateDocumentViewer/IntermediateDocumentPageContent.d.ts +40 -0
  4. package/dist/components/IntermediateDocumentViewer/IntermediateDocumentPageContent.d.ts.map +1 -0
  5. package/dist/components/IntermediateDocumentViewer/IntermediateDocumentViewer.d.ts +356 -0
  6. package/dist/components/IntermediateDocumentViewer/IntermediateDocumentViewer.d.ts.map +1 -0
  7. package/dist/components/IntermediateDocumentViewer/index.d.ts +7 -0
  8. package/dist/components/IntermediateDocumentViewer/index.d.ts.map +1 -0
  9. package/dist/components/IntermediateDocumentViewer/pageContentGeometry.d.ts +84 -0
  10. package/dist/components/IntermediateDocumentViewer/pageContentGeometry.d.ts.map +1 -0
  11. package/dist/components/IntermediateDocumentViewer/rangeJumpHelpers.d.ts +131 -0
  12. package/dist/components/IntermediateDocumentViewer/rangeJumpHelpers.d.ts.map +1 -0
  13. package/dist/components/IntermediateDocumentViewer/renderTiming.d.ts +44 -0
  14. package/dist/components/IntermediateDocumentViewer/renderTiming.d.ts.map +1 -0
  15. package/dist/components/IntermediateDocumentViewer/selectionAdapter.d.ts +25 -0
  16. package/dist/components/IntermediateDocumentViewer/selectionAdapter.d.ts.map +1 -0
  17. package/dist/components/IntermediateDocumentViewer/textSpanStyle.d.ts +4 -0
  18. package/dist/components/IntermediateDocumentViewer/textSpanStyle.d.ts.map +1 -0
  19. package/dist/components/IntermediateDocumentViewer/useLazyPageQueue.d.ts +73 -0
  20. package/dist/components/IntermediateDocumentViewer/useLazyPageQueue.d.ts.map +1 -0
  21. package/dist/components/IntermediateDocumentViewer.d.ts +2 -0
  22. package/dist/components/IntermediateDocumentViewer.d.ts.map +1 -0
  23. package/dist/components/PopoverPortal.d.ts +21 -0
  24. package/dist/components/PopoverPortal.d.ts.map +1 -0
  25. package/dist/components/Reader.d.ts +122 -0
  26. package/dist/components/Reader.d.ts.map +1 -0
  27. package/dist/components/gestureRouting.d.ts +73 -0
  28. package/dist/components/gestureRouting.d.ts.map +1 -0
  29. package/dist/components/selection/caretResolver.d.ts +33 -0
  30. package/dist/components/selection/caretResolver.d.ts.map +1 -0
  31. package/dist/components/selection/index.d.ts +2 -0
  32. package/dist/components/selection/index.d.ts.map +1 -0
  33. package/dist/components/selection/savedSelection.d.ts +71 -0
  34. package/dist/components/selection/savedSelection.d.ts.map +1 -0
  35. package/dist/components/selection/selectionComposer.d.ts +3 -0
  36. package/dist/components/selection/selectionComposer.d.ts.map +1 -0
  37. package/dist/components/selection/selectionPayloadSerializer.d.ts +21 -0
  38. package/dist/components/selection/selectionPayloadSerializer.d.ts.map +1 -0
  39. package/dist/components/selection/wordRange.d.ts +17 -0
  40. package/dist/components/selection/wordRange.d.ts.map +1 -0
  41. package/dist/index.d.ts +6 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +2933 -0
  44. package/dist/style.css +323 -0
  45. package/dist/types/selection.d.ts +42 -0
  46. package/dist/types/selection.d.ts.map +1 -0
  47. package/dist/vendor/clipper-lib.d.ts +3 -0
  48. package/dist/vendor/clipper-lib.d.ts.map +1 -0
  49. package/package.json +99 -0
package/dist/index.js ADDED
@@ -0,0 +1,2933 @@
1
+ import Wr, { useRef as R, useState as Q, useEffect as K, memo as zr, Profiler as cr, useCallback as f, useMemo as Ie, useId as Vr } from "react";
2
+ import { Selection as Hr } from "@hamster-note/selection";
3
+ import { TextDir as Yr, IntermediateDocument as qr } from "@hamster-note/types";
4
+ import { VirtualPaperInteractionMode as kt, VirtualPaper as Ur } from "@hamster-note/virtual-paper";
5
+ import { createPortal as Gr } from "react-dom";
6
+ var At = { exports: {} }, ot = {};
7
+ var An;
8
+ function Xr() {
9
+ if (An) return ot;
10
+ An = 1;
11
+ var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), t = /* @__PURE__ */ Symbol.for("react.fragment");
12
+ function n(o, i, c) {
13
+ var a = null;
14
+ if (c !== void 0 && (a = "" + c), i.key !== void 0 && (a = "" + i.key), "key" in i) {
15
+ c = {};
16
+ for (var l in i)
17
+ l !== "key" && (c[l] = i[l]);
18
+ } else c = i;
19
+ return i = c.ref, {
20
+ $$typeof: e,
21
+ type: o,
22
+ key: a,
23
+ ref: i !== void 0 ? i : null,
24
+ props: c
25
+ };
26
+ }
27
+ return ot.Fragment = t, ot.jsx = n, ot.jsxs = n, ot;
28
+ }
29
+ var st = {};
30
+ var kn;
31
+ function Jr() {
32
+ return kn || (kn = 1, process.env.NODE_ENV !== "production" && (function() {
33
+ function e(u) {
34
+ if (u == null) return null;
35
+ if (typeof u == "function")
36
+ return u.$$typeof === ae ? null : u.displayName || u.name || null;
37
+ if (typeof u == "string") return u;
38
+ switch (u) {
39
+ case Z:
40
+ return "Fragment";
41
+ case ee:
42
+ return "Profiler";
43
+ case ie:
44
+ return "StrictMode";
45
+ case b:
46
+ return "Suspense";
47
+ case O:
48
+ return "SuspenseList";
49
+ case G:
50
+ return "Activity";
51
+ }
52
+ if (typeof u == "object")
53
+ switch (typeof u.tag == "number" && console.error(
54
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
55
+ ), u.$$typeof) {
56
+ case H:
57
+ return "Portal";
58
+ case xe:
59
+ return u.displayName || "Context";
60
+ case fe:
61
+ return (u._context.displayName || "Context") + ".Consumer";
62
+ case te:
63
+ var v = u.render;
64
+ return u = u.displayName, u || (u = v.displayName || v.name || "", u = u !== "" ? "ForwardRef(" + u + ")" : "ForwardRef"), u;
65
+ case F:
66
+ return v = u.displayName || null, v !== null ? v : e(u.type) || "Memo";
67
+ case z:
68
+ v = u._payload, u = u._init;
69
+ try {
70
+ return e(u(v));
71
+ } catch {
72
+ }
73
+ }
74
+ return null;
75
+ }
76
+ function t(u) {
77
+ return "" + u;
78
+ }
79
+ function n(u) {
80
+ try {
81
+ t(u);
82
+ var v = !1;
83
+ } catch {
84
+ v = !0;
85
+ }
86
+ if (v) {
87
+ v = console;
88
+ var M = v.error, N = typeof Symbol == "function" && Symbol.toStringTag && u[Symbol.toStringTag] || u.constructor.name || "Object";
89
+ return M.call(
90
+ v,
91
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
92
+ N
93
+ ), t(u);
94
+ }
95
+ }
96
+ function o(u) {
97
+ if (u === Z) return "<>";
98
+ if (typeof u == "object" && u !== null && u.$$typeof === z)
99
+ return "<...>";
100
+ try {
101
+ var v = e(u);
102
+ return v ? "<" + v + ">" : "<...>";
103
+ } catch {
104
+ return "<...>";
105
+ }
106
+ }
107
+ function i() {
108
+ var u = $.A;
109
+ return u === null ? null : u.getOwner();
110
+ }
111
+ function c() {
112
+ return Error("react-stack-top-frame");
113
+ }
114
+ function a(u) {
115
+ if (ne.call(u, "key")) {
116
+ var v = Object.getOwnPropertyDescriptor(u, "key").get;
117
+ if (v && v.isReactWarning) return !1;
118
+ }
119
+ return u.key !== void 0;
120
+ }
121
+ function l(u, v) {
122
+ function M() {
123
+ B || (B = !0, console.error(
124
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
125
+ v
126
+ ));
127
+ }
128
+ M.isReactWarning = !0, Object.defineProperty(u, "key", {
129
+ get: M,
130
+ configurable: !0
131
+ });
132
+ }
133
+ function h() {
134
+ var u = e(this.type);
135
+ return re[u] || (re[u] = !0, console.error(
136
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
137
+ )), u = this.props.ref, u !== void 0 ? u : null;
138
+ }
139
+ function x(u, v, M, N, ue, we) {
140
+ var _ = M.ref;
141
+ return u = {
142
+ $$typeof: U,
143
+ type: u,
144
+ key: v,
145
+ props: M,
146
+ _owner: N
147
+ }, (_ !== void 0 ? _ : null) !== null ? Object.defineProperty(u, "ref", {
148
+ enumerable: !1,
149
+ get: h
150
+ }) : Object.defineProperty(u, "ref", { enumerable: !1, value: null }), u._store = {}, Object.defineProperty(u._store, "validated", {
151
+ configurable: !1,
152
+ enumerable: !1,
153
+ writable: !0,
154
+ value: 0
155
+ }), Object.defineProperty(u, "_debugInfo", {
156
+ configurable: !1,
157
+ enumerable: !1,
158
+ writable: !0,
159
+ value: null
160
+ }), Object.defineProperty(u, "_debugStack", {
161
+ configurable: !1,
162
+ enumerable: !1,
163
+ writable: !0,
164
+ value: ue
165
+ }), Object.defineProperty(u, "_debugTask", {
166
+ configurable: !1,
167
+ enumerable: !1,
168
+ writable: !0,
169
+ value: we
170
+ }), Object.freeze && (Object.freeze(u.props), Object.freeze(u)), u;
171
+ }
172
+ function g(u, v, M, N, ue, we) {
173
+ var _ = v.children;
174
+ if (_ !== void 0)
175
+ if (N)
176
+ if (Te(_)) {
177
+ for (N = 0; N < _.length; N++)
178
+ S(_[N]);
179
+ Object.freeze && Object.freeze(_);
180
+ } else
181
+ console.error(
182
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
183
+ );
184
+ else S(_);
185
+ if (ne.call(v, "key")) {
186
+ _ = e(u);
187
+ var W = Object.keys(v).filter(function(X) {
188
+ return X !== "key";
189
+ });
190
+ N = 0 < W.length ? "{key: someKey, " + W.join(": ..., ") + ": ...}" : "{key: someKey}", Ee[_ + N] || (W = 0 < W.length ? "{" + W.join(": ..., ") + ": ...}" : "{}", console.error(
191
+ `A props object containing a "key" prop is being spread into JSX:
192
+ let props = %s;
193
+ <%s {...props} />
194
+ React keys must be passed directly to JSX without using spread:
195
+ let props = %s;
196
+ <%s key={someKey} {...props} />`,
197
+ N,
198
+ _,
199
+ W,
200
+ _
201
+ ), Ee[_ + N] = !0);
202
+ }
203
+ if (_ = null, M !== void 0 && (n(M), _ = "" + M), a(v) && (n(v.key), _ = "" + v.key), "key" in v) {
204
+ M = {};
205
+ for (var ce in v)
206
+ ce !== "key" && (M[ce] = v[ce]);
207
+ } else M = v;
208
+ return _ && l(
209
+ M,
210
+ typeof u == "function" ? u.displayName || u.name || "Unknown" : u
211
+ ), x(
212
+ u,
213
+ _,
214
+ M,
215
+ i(),
216
+ ue,
217
+ we
218
+ );
219
+ }
220
+ function S(u) {
221
+ A(u) ? u._store && (u._store.validated = 1) : typeof u == "object" && u !== null && u.$$typeof === z && (u._payload.status === "fulfilled" ? A(u._payload.value) && u._payload.value._store && (u._payload.value._store.validated = 1) : u._store && (u._store.validated = 1));
222
+ }
223
+ function A(u) {
224
+ return typeof u == "object" && u !== null && u.$$typeof === U;
225
+ }
226
+ var C = Wr, U = /* @__PURE__ */ Symbol.for("react.transitional.element"), H = /* @__PURE__ */ Symbol.for("react.portal"), Z = /* @__PURE__ */ Symbol.for("react.fragment"), ie = /* @__PURE__ */ Symbol.for("react.strict_mode"), ee = /* @__PURE__ */ Symbol.for("react.profiler"), fe = /* @__PURE__ */ Symbol.for("react.consumer"), xe = /* @__PURE__ */ Symbol.for("react.context"), te = /* @__PURE__ */ Symbol.for("react.forward_ref"), b = /* @__PURE__ */ Symbol.for("react.suspense"), O = /* @__PURE__ */ Symbol.for("react.suspense_list"), F = /* @__PURE__ */ Symbol.for("react.memo"), z = /* @__PURE__ */ Symbol.for("react.lazy"), G = /* @__PURE__ */ Symbol.for("react.activity"), ae = /* @__PURE__ */ Symbol.for("react.client.reference"), $ = C.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, ne = Object.prototype.hasOwnProperty, Te = Array.isArray, ve = console.createTask ? console.createTask : function() {
227
+ return null;
228
+ };
229
+ C = {
230
+ react_stack_bottom_frame: function(u) {
231
+ return u();
232
+ }
233
+ };
234
+ var B, re = {}, oe = C.react_stack_bottom_frame.bind(
235
+ C,
236
+ c
237
+ )(), Pe = ve(o(c)), Ee = {};
238
+ st.Fragment = Z, st.jsx = function(u, v, M) {
239
+ var N = 1e4 > $.recentlyCreatedOwnerStacks++;
240
+ return g(
241
+ u,
242
+ v,
243
+ M,
244
+ !1,
245
+ N ? Error("react-stack-top-frame") : oe,
246
+ N ? ve(o(u)) : Pe
247
+ );
248
+ }, st.jsxs = function(u, v, M) {
249
+ var N = 1e4 > $.recentlyCreatedOwnerStacks++;
250
+ return g(
251
+ u,
252
+ v,
253
+ M,
254
+ !0,
255
+ N ? Error("react-stack-top-frame") : oe,
256
+ N ? ve(o(u)) : Pe
257
+ );
258
+ };
259
+ })()), st;
260
+ }
261
+ var On;
262
+ function Kr() {
263
+ return On || (On = 1, process.env.NODE_ENV === "production" ? At.exports = Xr() : At.exports = Jr()), At.exports;
264
+ }
265
+ var E = Kr();
266
+ const Zr = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, Qr = {
267
+ now: () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now()
268
+ };
269
+ function eo() {
270
+ try {
271
+ return Zr?.VITE_HAMSTER_READER_INTERMEDIATE_TIMING === "true";
272
+ } catch {
273
+ return !1;
274
+ }
275
+ }
276
+ function Nn(e) {
277
+ return e !== void 0 ? Object.freeze({ ...e }) : void 0;
278
+ }
279
+ function to(e) {
280
+ const t = e?.callback, n = e?.clock ?? Qr, o = e?.envEnabled ?? eo(), i = t !== void 0 || o;
281
+ function c(a) {
282
+ t && t(a), o && console.debug("[hamster-reader][intermediate-document]", a);
283
+ }
284
+ return {
285
+ enabled: i,
286
+ start(a, l) {
287
+ if (!i) return no;
288
+ const h = n.now(), x = l?.pageNumber, g = Nn(l?.detail);
289
+ return () => {
290
+ const S = n.now();
291
+ c({
292
+ stage: a,
293
+ startedAt: h,
294
+ endedAt: S,
295
+ durationMs: S - h,
296
+ pageNumber: x,
297
+ detail: g
298
+ });
299
+ };
300
+ },
301
+ measure(a, l, h) {
302
+ if (!i) return h();
303
+ const x = n.now(), g = h(), S = n.now();
304
+ return c({
305
+ stage: a,
306
+ startedAt: x,
307
+ endedAt: S,
308
+ durationMs: S - x,
309
+ pageNumber: l?.pageNumber,
310
+ detail: Nn(l?.detail)
311
+ }), g;
312
+ },
313
+ record(a) {
314
+ i && c(a);
315
+ }
316
+ };
317
+ }
318
+ function no() {
319
+ }
320
+ function ro(e) {
321
+ const t = /^page-(\d+)$/.exec(e);
322
+ if (!t)
323
+ return null;
324
+ const n = Number(t[1]);
325
+ return n >= 1 && Number.isInteger(n) ? n : null;
326
+ }
327
+ function oo(e, t) {
328
+ return e.find((n) => n.id === t) ?? null;
329
+ }
330
+ function so(e) {
331
+ const { rectsBySelectionId: t, start: n } = e, o = n.selectionId, i = t[o];
332
+ if (i && i.length > 0)
333
+ return { rect: i[0], pageId: o };
334
+ const c = Object.keys(t).sort();
335
+ for (const a of c) {
336
+ const l = t[a];
337
+ if (l && l.length > 0)
338
+ return { rect: l[0], pageId: a };
339
+ }
340
+ return null;
341
+ }
342
+ function io(e, t, n, o) {
343
+ return t === "percent" ? {
344
+ centerX: (e.x + e.width / 2) / 100 * n,
345
+ centerY: (e.y + e.height / 2) / 100 * o
346
+ } : {
347
+ centerX: e.x + e.width / 2,
348
+ centerY: e.y + e.height / 2
349
+ };
350
+ }
351
+ function jn(e) {
352
+ const { ranges: t, rangeId: n, pageWidth: o, pageHeight: i } = e, c = oo(t, n);
353
+ if (!c)
354
+ return null;
355
+ const a = so(c);
356
+ if (!a)
357
+ return null;
358
+ const l = ro(a.pageId);
359
+ if (l === null)
360
+ return null;
361
+ const h = e.rectType ?? c.overlayRectType ?? "percent", { centerX: x, centerY: g } = io(
362
+ a.rect,
363
+ h,
364
+ o,
365
+ i
366
+ );
367
+ return { pageNumber: l, centerX: x, centerY: g };
368
+ }
369
+ const co = 16;
370
+ function Fn(e, t, n) {
371
+ let o = 0;
372
+ for (const i of t) {
373
+ if (i === e)
374
+ break;
375
+ const c = n.get(i);
376
+ o += (c?.height ?? 0) + co;
377
+ }
378
+ return o;
379
+ }
380
+ function ao(e) {
381
+ const {
382
+ viewportWidth: t,
383
+ viewportHeight: n,
384
+ contentWidth: o,
385
+ contentHeight: i,
386
+ targetContentX: c,
387
+ targetContentY: a,
388
+ scale: l
389
+ } = e;
390
+ if (!(t > 0 && n > 0 && o > 0 && i > 0 && l > 0 && Number.isFinite(c) && Number.isFinite(a)))
391
+ return null;
392
+ const h = o * l, x = i * l, g = t / 2 - c * l, S = n / 2 - a * l, A = h <= t ? (t - h) / 2 : Math.min(0, Math.max(t - h, g)), C = x <= n ? (n - x) / 2 : Math.min(0, Math.max(n - x, S));
393
+ return { x: A, y: C, scale: l };
394
+ }
395
+ function Ln({
396
+ children: e,
397
+ visible: t
398
+ }) {
399
+ const n = R(null), [o, i] = Q(null);
400
+ return K(() => {
401
+ if (!t) {
402
+ i(null);
403
+ return;
404
+ }
405
+ let c;
406
+ const a = () => {
407
+ const l = n.current;
408
+ if (l) {
409
+ const h = l.getBoundingClientRect();
410
+ (h.left !== 0 || h.top !== 0) && i((x) => x && Math.abs(x.left - h.left) < 0.5 && Math.abs(x.top - h.top) < 0.5 ? x : { left: h.left, top: h.top });
411
+ }
412
+ c = requestAnimationFrame(a);
413
+ };
414
+ return c = requestAnimationFrame(a), () => cancelAnimationFrame(c);
415
+ }, [t]), /* @__PURE__ */ E.jsxs(E.Fragment, { children: [
416
+ /* @__PURE__ */ E.jsx(
417
+ "div",
418
+ {
419
+ ref: n,
420
+ "aria-hidden": "true",
421
+ style: {
422
+ position: "absolute",
423
+ left: 0,
424
+ top: 0,
425
+ width: 0,
426
+ height: 0,
427
+ pointerEvents: "none"
428
+ }
429
+ }
430
+ ),
431
+ t && o && Gr(
432
+ /* @__PURE__ */ E.jsx(
433
+ "div",
434
+ {
435
+ className: "hamster-reader-popover-portal hsn-selection-popover",
436
+ style: {
437
+ position: "fixed",
438
+ left: `${o.left}px`,
439
+ top: `${o.top}px`,
440
+ // 与 .hsn-selection-popover 原有 transform 一致:
441
+ // 水平居中、垂直向上
442
+ transform: "translate(-50%, -100%)",
443
+ // 覆盖 .hsn-selection-popover 的 margin-top:-6px,
444
+ // 因为 portal 使用 fixed 定位,坐标已精确计算
445
+ margin: 0,
446
+ zIndex: 1e4,
447
+ pointerEvents: "auto",
448
+ userSelect: "none"
449
+ },
450
+ children: e
451
+ }
452
+ ),
453
+ document.body
454
+ )
455
+ ] });
456
+ }
457
+ const uo = [
458
+ ".hamster-reader__intermediate-page-base-image",
459
+ ".hamster-reader__intermediate-page-background",
460
+ ".hamster-reader__intermediate-page-background-wrapper"
461
+ ].join(", "), lo = (e) => e instanceof Element ? e : e?.parentElement ?? null, ar = (e) => !!lo(e)?.closest(uo), ur = /* @__PURE__ */ new WeakMap(), Dn = (e) => {
462
+ const n = (e instanceof Element ? e : e?.parentElement)?.closest("[data-text-id]");
463
+ return !(n instanceof HTMLElement) || ar(n) ? null : n;
464
+ }, fo = (e) => {
465
+ const t = Dn(e.anchorNode), n = Dn(e.focusNode);
466
+ if (!t || !n) return null;
467
+ const o = t.closest(
468
+ ".hamster-reader__intermediate-document-viewer"
469
+ ), i = n.closest(
470
+ ".hamster-reader__intermediate-document-viewer"
471
+ );
472
+ return o instanceof HTMLElement && o === i ? o : null;
473
+ }, $n = (e) => e.textContent?.length ?? 0, Bn = (e, t, n) => {
474
+ if (t === e)
475
+ return Array.from(e.childNodes).slice(0, n).reduce((a, l) => a + $n(l), 0);
476
+ let o = 0;
477
+ const i = e.ownerDocument.createTreeWalker(
478
+ e,
479
+ NodeFilter.SHOW_TEXT
480
+ );
481
+ let c = i.nextNode();
482
+ for (; c; ) {
483
+ if (c === t)
484
+ return o + n;
485
+ o += $n(c), c = i.nextNode();
486
+ }
487
+ return o;
488
+ }, ho = (e, t) => {
489
+ try {
490
+ return e.intersectsNode(t);
491
+ } catch {
492
+ return !1;
493
+ }
494
+ }, go = (e, t) => {
495
+ const n = t.ownerDocument.createRange();
496
+ return n.selectNodeContents(t), t.contains(e.startContainer) && n.setStart(
497
+ e.startContainer,
498
+ e.startOffset
499
+ ), t.contains(e.endContainer) && n.setEnd(e.endContainer, e.endOffset), n;
500
+ }, mo = (e, t = ur) => {
501
+ if (!e || e.isCollapsed || e.rangeCount === 0)
502
+ return null;
503
+ const n = fo(e);
504
+ if (!n) return null;
505
+ const o = e.getRangeAt(0), i = Array.from(
506
+ n.querySelectorAll("[data-text-id]")
507
+ ).flatMap((a) => {
508
+ if (ar(a)) return [];
509
+ if (!ho(o, a)) return [];
510
+ const l = t.get(a);
511
+ if (!l) return [];
512
+ const h = l.text.content ?? "", x = go(o, a), g = Bn(
513
+ a,
514
+ x.startContainer,
515
+ x.startOffset
516
+ ), S = Bn(
517
+ a,
518
+ x.endContainer,
519
+ x.endOffset
520
+ ), A = Math.max(
521
+ 0,
522
+ Math.min(g, h.length)
523
+ ), C = Math.max(
524
+ A,
525
+ Math.min(S, h.length)
526
+ );
527
+ return C <= A ? [] : [
528
+ {
529
+ ...l.text,
530
+ pageNumber: l.pageNumber,
531
+ selectedText: h.slice(A, C),
532
+ startCharIndex: A,
533
+ endCharIndex: C
534
+ }
535
+ ];
536
+ }), c = i.map((a) => a.selectedText).join("");
537
+ return i.length === 0 || c.trim().length === 0 ? null : { selection: e, segments: i, extractedText: c };
538
+ };
539
+ function lr(e, t) {
540
+ return `${e}:page-${t}`;
541
+ }
542
+ function po(e, t) {
543
+ return e.map((n) => ({
544
+ ...n,
545
+ start: Wn(n.start, t),
546
+ end: Wn(n.end, t),
547
+ rectsBySelectionId: So(
548
+ n.rectsBySelectionId,
549
+ t
550
+ )
551
+ }));
552
+ }
553
+ function xo(e, t) {
554
+ return e.flatMap((n) => {
555
+ const o = Ot(n, t);
556
+ return o ? [o] : [];
557
+ });
558
+ }
559
+ function vo(e, t) {
560
+ const n = e.activeRange ? Ot(e.activeRange, t) : e.activeRange;
561
+ return {
562
+ items: xo(e.items, t),
563
+ selectedRangeId: e.selectedRangeId,
564
+ selectionOrder: e.selectionOrder.flatMap((o) => {
565
+ const i = Nt(
566
+ o,
567
+ t
568
+ );
569
+ return i ? [i] : [];
570
+ }),
571
+ overlayRectType: e.overlayRectType,
572
+ draggingRange: e.draggingRange,
573
+ selectingText: e.selectingText,
574
+ activeRange: n
575
+ };
576
+ }
577
+ function wo({
578
+ scopeId: e,
579
+ ranges: t,
580
+ selectedRangeId: n,
581
+ pageNumbers: o,
582
+ overlayRectType: i,
583
+ transient: c
584
+ }) {
585
+ const { selectionOrder: a, ...l } = c;
586
+ return {
587
+ items: po(t, e),
588
+ selectedRangeId: n,
589
+ selectionOrder: Ro(
590
+ e,
591
+ o,
592
+ a
593
+ ),
594
+ overlayRectType: i,
595
+ ...l
596
+ };
597
+ }
598
+ function Ro(e, t, n) {
599
+ const o = t.map(
600
+ (c) => lr(e, c)
601
+ );
602
+ if (!n)
603
+ return o;
604
+ const i = new Set(o);
605
+ return n.filter(
606
+ (c) => i.has(c)
607
+ );
608
+ }
609
+ function yo(e) {
610
+ const t = {};
611
+ return e.selectionOrder !== void 0 && (t.selectionOrder = e.selectionOrder), e.draggingRange !== void 0 && (t.draggingRange = e.draggingRange), e.selectingText !== void 0 && (t.selectingText = e.selectingText), e.activeRange !== void 0 && (t.activeRange = e.activeRange), t;
612
+ }
613
+ function To(e, t) {
614
+ return Po(e.selectionOrder, t.selectionOrder) && Eo(e.draggingRange, t.draggingRange) && e.selectingText === t.selectingText && bo(e.activeRange, t.activeRange);
615
+ }
616
+ function Po(e, t) {
617
+ return e === t ? !0 : !e || !t || e.length !== t.length ? !1 : e.every((n, o) => n === t[o]);
618
+ }
619
+ function Eo(e, t) {
620
+ return e === t ? !0 : !e || !t || e.type !== t.type ? !1 : e.type === "persisted-range" && t.type === "persisted-range" ? e.id === t.id : !0;
621
+ }
622
+ function bo(e, t) {
623
+ return e === t ? !0 : !e || !t ? !1 : e.id === t.id && e.text === t.text && e.createdAt === t.createdAt && e.overlayRectType === t.overlayRectType && e.start.selectionId === t.start.selectionId && e.start.offset === t.start.offset && e.end.selectionId === t.end.selectionId && e.end.offset === t.end.offset && Io(e.rectsBySelectionId, t.rectsBySelectionId);
624
+ }
625
+ function Io(e, t) {
626
+ const n = Object.keys(e), o = Object.keys(t);
627
+ return n.length !== o.length ? !1 : n.every((i) => {
628
+ const c = e[i], a = t[i];
629
+ return !c || !a || c.length !== a.length ? !1 : c.every((l, h) => {
630
+ const x = a[h];
631
+ return x !== void 0 && l.x === x.x && l.y === x.y && l.width === x.width && l.height === x.height;
632
+ });
633
+ });
634
+ }
635
+ function Ot(e, t) {
636
+ const n = Nt(
637
+ e.start.selectionId,
638
+ t
639
+ ), o = Nt(
640
+ e.end.selectionId,
641
+ t
642
+ );
643
+ return !n || !o ? null : {
644
+ ...e,
645
+ start: {
646
+ ...e.start,
647
+ selectionId: n
648
+ },
649
+ end: {
650
+ ...e.end,
651
+ selectionId: o
652
+ },
653
+ rectsBySelectionId: _o(
654
+ e.rectsBySelectionId,
655
+ t
656
+ )
657
+ };
658
+ }
659
+ function Wn(e, t) {
660
+ return {
661
+ ...e,
662
+ selectionId: `${t}:${e.selectionId}`
663
+ };
664
+ }
665
+ function So(e, t) {
666
+ const n = {};
667
+ return Object.entries(e).forEach(([o, i]) => {
668
+ n[`${t}:${o}`] = i;
669
+ }), n;
670
+ }
671
+ function _o(e, t) {
672
+ const n = {};
673
+ return Object.entries(e).forEach(([o, i]) => {
674
+ const c = Nt(
675
+ o,
676
+ t
677
+ );
678
+ c && (n[c] = i);
679
+ }), n;
680
+ }
681
+ function Nt(e, t) {
682
+ const n = `${t}:`;
683
+ if (!e.startsWith(n))
684
+ return null;
685
+ const o = e.slice(n.length);
686
+ return o.startsWith("page-") ? o : null;
687
+ }
688
+ const dr = (e) => {
689
+ if (!e || e.length < 4)
690
+ return { x: 0, y: 0, width: 0, height: 0 };
691
+ const t = e.map((l) => l?.[0]).filter(Number.isFinite), n = e.map((l) => l?.[1]).filter(Number.isFinite);
692
+ if (t.length === 0 || n.length === 0)
693
+ return { x: 0, y: 0, width: 0, height: 0 };
694
+ const o = Math.min(...t), i = Math.max(...t), c = Math.min(...n), a = Math.max(...n);
695
+ return { x: o, y: c, width: i - o, height: a - c };
696
+ }, rn = (e) => {
697
+ if (!e || e.length !== 4 || !e.every(
698
+ (l) => Array.isArray(l) && l.length === 2 && typeof l[0] == "number" && typeof l[1] == "number" && Number.isFinite(l[0]) && Number.isFinite(l[1])
699
+ ))
700
+ return null;
701
+ const t = e[0], n = e[1], o = e[2], i = Math.sqrt((n[0] - t[0]) ** 2 + (n[1] - t[1]) ** 2), c = Math.sqrt((o[0] - n[0]) ** 2 + (o[1] - n[1]) ** 2);
702
+ if (i === 0 || c === 0)
703
+ return null;
704
+ const a = Math.atan2(n[1] - t[1], n[0] - t[0]) * 180 / Math.PI;
705
+ return {
706
+ x: t[0],
707
+ y: t[1],
708
+ width: i,
709
+ height: c,
710
+ rotation: a
711
+ };
712
+ }, Co = (e) => {
713
+ const t = rn(e.polygon);
714
+ return t !== null ? {
715
+ x: t.x,
716
+ y: t.y,
717
+ width: t.width,
718
+ height: t.height,
719
+ rotation: t.rotation
720
+ } : e.polygon ? {
721
+ ...dr(e.polygon),
722
+ rotation: 0
723
+ } : {
724
+ x: e.x ?? 0,
725
+ y: e.y ?? 0,
726
+ width: e.width ?? 0,
727
+ height: e.height ?? 0,
728
+ rotation: 0
729
+ };
730
+ }, Mo = (e) => {
731
+ const t = rn(e.polygon);
732
+ if (t)
733
+ return t;
734
+ const n = e.polygon;
735
+ return n && n.length >= 4 ? { ...dr(n), rotation: 0 } : { x: 0, y: 0, width: 0, height: 0, rotation: 0 };
736
+ }, Ao = (e, t) => {
737
+ const n = {
738
+ position: "absolute",
739
+ left: `${t.x}px`,
740
+ top: `${t.y}px`,
741
+ width: t.width > 0 ? `${t.width}px` : void 0,
742
+ height: t.height > 0 ? `${t.height}px` : void 0,
743
+ opacity: typeof e.opacity == "number" && Number.isFinite(e.opacity) ? e.opacity : 1,
744
+ transformOrigin: "left top",
745
+ pointerEvents: "none"
746
+ };
747
+ if (t.rotation !== 0 && (n.transform = `rotate(${t.rotation}deg)`), e.clip) {
748
+ const o = e.clip, i = t.width - (o.x + o.width), c = t.height - (o.y + o.height);
749
+ n.clipPath = `inset(${o.y}px ${i}px ${c}px ${o.x}px)`;
750
+ }
751
+ return n;
752
+ }, ko = 8e-5, Oo = (e, t) => {
753
+ const n = [];
754
+ return !t && e.rotate && n.push(`rotate(${e.rotate}deg)`), e.skew && n.push(`skewX(${e.skew}deg)`), n.length > 0 ? n.join(" ") : void 0;
755
+ }, No = (e) => {
756
+ const t = e.trim();
757
+ return t.length === 0 ? "sans-serif" : !t.includes(" ") || t.startsWith('"') || t.startsWith("'") ? t : `"${t.replaceAll('"', '\\"')}"`;
758
+ }, jo = (e) => {
759
+ if (!Number.isFinite(e.fontSize) || e.fontSize <= 0) return null;
760
+ const t = e.italic ? "italic" : "normal", n = Number.isFinite(e.fontWeight) ? e.fontWeight : 400, o = No(e.fontFamily);
761
+ return `${t} ${n} ${e.fontSize}px ${o}`;
762
+ }, Fo = () => typeof document > "u" ? !1 : typeof navigator > "u" ? !0 : !(navigator.userAgent.includes("jsdom/") && HTMLCanvasElement.prototype.getContext.name === "getContext"), Lo = (e) => {
763
+ if (!Fo()) return null;
764
+ const t = document.createElement("canvas").getContext("2d"), n = jo(e);
765
+ if (!t || !n) return null;
766
+ t.font = n;
767
+ const o = t.measureText(e.content);
768
+ return Number.isFinite(o.width) && o.width > 0 ? o.width : null;
769
+ }, Do = (e, t) => {
770
+ if (e.vertical || e.dir === Yr.TTB || !rn(e.polygon) || !Number.isFinite(t.width) || t.width <= 0) return;
771
+ const n = Lo(e);
772
+ if (n === null) return;
773
+ const o = t.width / n;
774
+ if (!(!Number.isFinite(o) || o <= 0))
775
+ return Math.abs(o - 1) > ko ? o : void 0;
776
+ }, $o = (e, t, n = !1) => {
777
+ const o = Oo(e, !!t.rotation), i = n ? Do(e, t) : void 0, c = [
778
+ t.rotation ? `rotate(${t.rotation}deg)` : "",
779
+ i ? `scaleX(${i})` : "",
780
+ o
781
+ ].filter(Boolean).join(" ");
782
+ return {
783
+ position: "absolute",
784
+ left: Number.isFinite(t.x) ? `${t.x}px` : "0px",
785
+ top: Number.isFinite(t.y) ? `${t.y}px` : "0px",
786
+ width: Number.isFinite(t.width) && t.width > 0 ? `${t.width}px` : void 0,
787
+ height: Number.isFinite(t.height) && t.height > 0 ? `${t.height}px` : void 0,
788
+ fontSize: Number.isFinite(e.fontSize) && e.fontSize > 0 ? `${e.fontSize}px` : void 0,
789
+ fontFamily: e.fontFamily || void 0,
790
+ fontWeight: e.fontWeight || void 0,
791
+ fontStyle: e.italic ? "italic" : void 0,
792
+ color: e.color || void 0,
793
+ lineHeight: Number.isFinite(e.lineHeight) && e.lineHeight > 0 ? `${e.lineHeight}px` : void 0,
794
+ transform: c,
795
+ transformOrigin: "left top",
796
+ whiteSpace: "pre"
797
+ };
798
+ }, zn = (e) => e.content.length > 0, Vn = (e, t, n, o = !1) => {
799
+ const i = e, c = Co(i), a = $o(i, c, !0);
800
+ return /* @__PURE__ */ E.jsx(
801
+ "span",
802
+ {
803
+ ref: n(i, t),
804
+ className: "hamster-reader__intermediate-text",
805
+ "data-text-id": i.id,
806
+ "data-page-number": t,
807
+ "data-ocr": o ? "true" : void 0,
808
+ style: a,
809
+ children: i.content
810
+ },
811
+ i.id
812
+ );
813
+ }, Bo = (e) => {
814
+ const t = Mo(e), n = Ao(e, t);
815
+ return /* @__PURE__ */ E.jsx(
816
+ "img",
817
+ {
818
+ className: "hamster-reader__intermediate-page-image",
819
+ src: e.src,
820
+ alt: "",
821
+ "aria-hidden": "true",
822
+ "data-image-id": e.id,
823
+ style: n
824
+ },
825
+ e.id
826
+ );
827
+ };
828
+ function Wo({
829
+ pageNumber: e,
830
+ texts: t,
831
+ ocrTexts: n,
832
+ baseImageSource: o,
833
+ images: i,
834
+ setTextRef: c,
835
+ onRenderTiming: a
836
+ }) {
837
+ const l = t.filter(zn), h = n.filter(zn), x = /* @__PURE__ */ E.jsxs(E.Fragment, { children: [
838
+ o && /* @__PURE__ */ E.jsx(
839
+ "img",
840
+ {
841
+ className: "hamster-reader__intermediate-page-base-image",
842
+ src: o,
843
+ alt: "",
844
+ "aria-hidden": "true"
845
+ }
846
+ ),
847
+ i.map(Bo),
848
+ l.map(
849
+ (g) => Vn(g, e, c)
850
+ ),
851
+ h.map(
852
+ (g) => Vn(g, e, c, !0)
853
+ )
854
+ ] });
855
+ return a ? /* @__PURE__ */ E.jsx(
856
+ cr,
857
+ {
858
+ id: `intermediate-page-content-${e}`,
859
+ onRender: (g, S, A, C, U, H) => {
860
+ a(e, U, H, A);
861
+ },
862
+ children: x
863
+ }
864
+ ) : x;
865
+ }
866
+ const zo = zr(
867
+ Wo
868
+ );
869
+ function Vo(e, t, n) {
870
+ const {
871
+ activeDocumentRef: o,
872
+ isMountedRef: i,
873
+ loadingPagesRef: c,
874
+ getBaseImageFromPage: a,
875
+ getPageContentEntries: l,
876
+ isIntermediateText: h,
877
+ isIntermediateImage: x,
878
+ callbacks: g
879
+ } = n, S = R([]), A = R(/* @__PURE__ */ new Set()), C = R(0), U = R([]), H = R(() => {
880
+ }), Z = f(() => {
881
+ const b = new Set(U.current);
882
+ for (; S.current.length > 0; ) {
883
+ const O = S.current.shift();
884
+ if (O !== void 0 && b.has(O) && !g.isPageLoaded(O) && !c.current.has(O))
885
+ return O;
886
+ }
887
+ }, [g, c]), ie = f(
888
+ (b, O) => {
889
+ const F = t;
890
+ if (!F || o.current !== F || g.isPageLoaded(b) || c.current.has(b))
891
+ return;
892
+ let z;
893
+ try {
894
+ z = F.getPageByPageNumber(b);
895
+ } catch {
896
+ g.onPageError(b);
897
+ return;
898
+ }
899
+ if (!z) {
900
+ g.onPageError(b);
901
+ return;
902
+ }
903
+ c.current.add(b), A.current.add(b), z.then(
904
+ (G) => Promise.all([a(G), l(G)])
905
+ ).then(([G, ae]) => {
906
+ if (!i.current || o.current !== F || C.current !== O)
907
+ return;
908
+ const $ = ae.filter(h), ne = ae.filter(x);
909
+ g.onPageLoaded({ pageNumber: b, baseImage: G, texts: $, images: ne });
910
+ }).catch(() => {
911
+ !i.current || o.current !== F || C.current !== O || g.onPageError(b);
912
+ }).finally(() => {
913
+ C.current === O && (c.current.delete(b), A.current.delete(b)), queueMicrotask(() => {
914
+ !i.current || o.current !== F || C.current !== O || H.current(O);
915
+ });
916
+ });
917
+ },
918
+ [
919
+ t,
920
+ o,
921
+ i,
922
+ c,
923
+ g,
924
+ a,
925
+ l,
926
+ h,
927
+ x
928
+ ]
929
+ ), ee = f(
930
+ (b) => {
931
+ if (C.current !== b || !t || o.current !== t)
932
+ return;
933
+ const O = e.current.pageLoadConcurrency;
934
+ for (; c.current.size < O; ) {
935
+ const F = Z();
936
+ if (F === void 0)
937
+ break;
938
+ ie(F, b);
939
+ }
940
+ },
941
+ [
942
+ e,
943
+ t,
944
+ o,
945
+ c,
946
+ Z,
947
+ ie
948
+ ]
949
+ );
950
+ H.current = ee;
951
+ const fe = f(
952
+ (b) => {
953
+ if (U.current = b, !t)
954
+ return;
955
+ const O = e.current.initialLoadedPages;
956
+ if (O <= 0)
957
+ return;
958
+ const F = b.slice(0, O);
959
+ for (const z of F)
960
+ !g.isPageLoaded(z) && !c.current.has(z) && !S.current.includes(z) && S.current.push(z);
961
+ ee(C.current);
962
+ },
963
+ [e, t, g, c, ee]
964
+ ), xe = f(
965
+ (b) => {
966
+ t && U.current.includes(b) && (g.isPageLoaded(b) || c.current.has(b) || S.current.includes(b) || (S.current.push(b), ee(C.current)));
967
+ },
968
+ [t, g, c, ee]
969
+ ), te = f(() => {
970
+ S.current = [], C.current += 1, A.current.forEach((b) => {
971
+ c.current.delete(b);
972
+ }), A.current.clear();
973
+ }, [c]);
974
+ return K(() => {
975
+ te();
976
+ }, [t, te]), K(() => {
977
+ const b = A.current, O = c.current;
978
+ return () => {
979
+ S.current = [], C.current += 1, b.forEach((F) => {
980
+ O.delete(F);
981
+ }), b.clear();
982
+ };
983
+ }, [c]), { enqueueInitialPages: fe, enqueuePage: xe, cancelAll: te };
984
+ }
985
+ const fr = 24, jt = (e) => Number.isFinite(e.width) && Number.isFinite(e.height) && e.width > 0 && e.height > 0, Ce = (e) => Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 0, Ke = (e) => Number(Ce(e).toFixed(6)), Be = (e) => e.content ?? "", Ft = (e) => typeof e.id == "string" && e.id.length > 0 ? e.id : void 0, on = (e) => {
986
+ if (!e) return;
987
+ const t = e.filter(
988
+ (h) => Array.isArray(h) && h.length === 2 && Number.isFinite(h[0]) && Number.isFinite(h[1])
989
+ );
990
+ if (t.length === 0) return;
991
+ const n = t.map((h) => h[0]), o = t.map((h) => h[1]), i = Math.min(...n), c = Math.max(...n), a = Math.min(...o), l = Math.max(...o);
992
+ return { x: i, y: a, width: c - i, height: l - a };
993
+ }, Lt = (e, t) => e.slice(Math.max(0, t - fr), t), Dt = (e, t) => e.slice(t, t + fr), Ho = (e, t) => Dt(e, t), at = (e) => e.pageNumber ?? 1, Hn = (e, t, n) => {
994
+ const o = Be(e), i = on(e.polygon), c = at(e), a = i && n ? cn([{ ...i, pageNumber: c }], n)[0] : void 0;
995
+ return {
996
+ pageNumber: c,
997
+ textId: Ft(e),
998
+ textHash: Ze(o),
999
+ charIndex: t,
1000
+ contextBefore: Lt(o, t),
1001
+ contextAfter: Dt(o, t),
1002
+ bbox: a
1003
+ };
1004
+ }, Yo = (e, t) => {
1005
+ const n = Be(e), o = on(e.polygon), i = at(e), c = o && t ? cn([{ ...o, pageNumber: i }], t)[0] : void 0;
1006
+ return {
1007
+ pageNumber: i,
1008
+ textId: Ft(e),
1009
+ textHash: Ze(n),
1010
+ startCharIndex: e.startCharIndex,
1011
+ endCharIndex: e.endCharIndex,
1012
+ selectedText: e.selectedText,
1013
+ contextBefore: Lt(n, e.startCharIndex),
1014
+ contextAfter: Ho(n, e.endCharIndex),
1015
+ bbox: c
1016
+ };
1017
+ }, qo = (e, t) => {
1018
+ const n = /* @__PURE__ */ new Map();
1019
+ for (const o of e)
1020
+ n.set(o.pageNumber, [
1021
+ ...n.get(o.pageNumber) ?? [],
1022
+ o
1023
+ ]);
1024
+ return Array.from(n.entries()).flatMap(([o, i]) => {
1025
+ const c = t.get(o);
1026
+ return !c || !jt(c) ? [] : [
1027
+ {
1028
+ pageNumber: o,
1029
+ pageSize: c,
1030
+ rects: cn(i, c)
1031
+ }
1032
+ ];
1033
+ });
1034
+ }, ct = (e) => {
1035
+ const t = Array.from(e.childNodes).find(
1036
+ (n) => n.nodeType === Node.TEXT_NODE
1037
+ );
1038
+ return t || e.ownerDocument.createTextNode("");
1039
+ }, Yn = (e, t, n) => {
1040
+ const o = ct(e), i = e.ownerDocument.createRange();
1041
+ return i.setStart(o, t), i.setEnd(o, n), i;
1042
+ }, qn = (e, t, n, o) => {
1043
+ const i = Array.from(e.getClientRects()).filter(
1044
+ (a) => a.width > 0 && a.height > 0
1045
+ );
1046
+ if (i.length > 0)
1047
+ return i.map((a) => ({
1048
+ x: a.x,
1049
+ y: a.y,
1050
+ width: a.width,
1051
+ height: a.height,
1052
+ pageNumber: t,
1053
+ origin: "viewport"
1054
+ }));
1055
+ const c = e.getBoundingClientRect();
1056
+ return c.width > 0 && c.height > 0 ? [
1057
+ {
1058
+ x: c.x,
1059
+ y: c.y,
1060
+ width: c.width,
1061
+ height: c.height,
1062
+ pageNumber: t,
1063
+ origin: "viewport"
1064
+ }
1065
+ ] : n ? o && jt(o) ? [
1066
+ {
1067
+ x: Ce(n.x) * o.width,
1068
+ y: Ce(n.y) * o.height,
1069
+ width: Ce(n.width) * o.width,
1070
+ height: Ce(n.height) * o.height,
1071
+ pageNumber: t,
1072
+ origin: "page-relative"
1073
+ }
1074
+ ] : [{ ...n, pageNumber: t, origin: "page-relative" }] : [];
1075
+ }, Uo = (e, t) => {
1076
+ if (!e.bbox) return 0;
1077
+ const n = on(t.text.polygon);
1078
+ return n ? Math.abs(n.y - e.bbox.y) : Number.POSITIVE_INFINITY;
1079
+ }, sn = (e, t) => {
1080
+ if (e.length === 0) return null;
1081
+ if (e.length === 1) return e[0];
1082
+ let n = null, o = Number.POSITIVE_INFINITY, i = !1;
1083
+ for (const c of e) {
1084
+ const a = Uo(t, c);
1085
+ a < o ? (n = c, o = a, i = !1) : a === o && (i = !0);
1086
+ }
1087
+ return i ? null : n;
1088
+ }, Un = (e, t) => {
1089
+ if (!e.textId || e.charIndex === void 0) return null;
1090
+ const n = t.find(
1091
+ (i) => i.pageNumber === e.pageNumber && Ft(i.text) === e.textId
1092
+ );
1093
+ if (!n) return null;
1094
+ const o = Be(n.text);
1095
+ return Ze(o) !== e.textHash || e.charIndex < 0 || e.charIndex > o.length ? null : { element: n, charIndex: e.charIndex };
1096
+ }, Gn = (e, t) => {
1097
+ if (!e.textHash) return null;
1098
+ const n = t.filter((i) => {
1099
+ if (i.pageNumber !== e.pageNumber) return !1;
1100
+ const c = Be(i.text);
1101
+ return Ze(c) !== e.textHash || e.charIndex === void 0 ? !1 : Lt(c, e.charIndex) === e.contextBefore && Dt(c, e.charIndex) === e.contextAfter;
1102
+ }), o = sn(n, e);
1103
+ return o && e.charIndex !== void 0 ? { element: o, charIndex: e.charIndex } : null;
1104
+ }, hr = (e, t) => {
1105
+ if (!e.selectedText) return null;
1106
+ const n = e.selectedText, o = t.flatMap((a) => {
1107
+ if (a.pageNumber !== e.pageNumber) return [];
1108
+ const l = Be(a.text), h = [];
1109
+ let x = l.indexOf(n);
1110
+ for (; x !== -1; )
1111
+ h.push(x), x = l.indexOf(n, x + 1);
1112
+ return h.map((g) => ({
1113
+ element: a,
1114
+ startCharIndex: g,
1115
+ endCharIndex: g + n.length
1116
+ }));
1117
+ });
1118
+ if (o.length === 1) return o[0];
1119
+ if (!e.bbox || o.length === 0) return null;
1120
+ const i = sn(
1121
+ o.map((a) => a.element),
1122
+ { bbox: e.bbox }
1123
+ ), c = o.filter((a) => a.element === i);
1124
+ return c.length === 1 ? c[0] : null;
1125
+ }, Go = (e, t) => {
1126
+ if (e.textId && e.startCharIndex !== void 0 && e.endCharIndex !== void 0) {
1127
+ const n = t.find(
1128
+ (o) => o.pageNumber === e.pageNumber && Ft(o.text) === e.textId
1129
+ );
1130
+ if (n && Ze(Be(n.text)) === e.textHash)
1131
+ return {
1132
+ element: n,
1133
+ startCharIndex: e.startCharIndex,
1134
+ endCharIndex: e.endCharIndex
1135
+ };
1136
+ }
1137
+ if (e.textHash && e.startCharIndex !== void 0 && e.endCharIndex !== void 0) {
1138
+ const n = e.startCharIndex, o = e.endCharIndex, i = t.filter((a) => {
1139
+ if (a.pageNumber !== e.pageNumber) return !1;
1140
+ const l = Be(a.text);
1141
+ return Ze(l) !== e.textHash ? !1 : Lt(l, n) === e.contextBefore && Dt(l, o) === e.contextAfter;
1142
+ });
1143
+ let c = null;
1144
+ if (i.length === 1 ? c = i[0] : i.length > 1 && e.bbox && (c = sn(i, { bbox: e.bbox })), c)
1145
+ return { element: c, startCharIndex: n, endCharIndex: o };
1146
+ }
1147
+ return hr(e, t);
1148
+ }, Xo = (e, t) => ({
1149
+ id: e.id,
1150
+ selection: e,
1151
+ status: e.visual.length > 0 ? "visual-fallback" : "unresolved",
1152
+ rects: e.visual.flatMap(
1153
+ (n) => Jo(n.rects, n.pageSize, n.pageNumber).map(
1154
+ (o) => ({
1155
+ ...o,
1156
+ origin: "page-relative"
1157
+ })
1158
+ )
1159
+ ),
1160
+ rectsOrigin: "page-relative",
1161
+ segments: [],
1162
+ extractedText: "",
1163
+ reason: t
1164
+ }), Xn = (e, t, n, o, i) => {
1165
+ const c = n.some((h) => h.origin === "viewport"), a = n.some((h) => h.origin === "page-relative");
1166
+ let l;
1167
+ return c && a ? l = "mixed" : c ? l = "viewport" : a ? l = "page-relative" : l = "viewport", {
1168
+ id: e.id,
1169
+ selection: e,
1170
+ status: "resolved",
1171
+ range: t,
1172
+ rects: n,
1173
+ rectsOrigin: l,
1174
+ segments: o,
1175
+ extractedText: i
1176
+ };
1177
+ }, Ze = (e) => {
1178
+ let t = 2166136261;
1179
+ for (let n = 0; n < e.length; n += 1)
1180
+ t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
1181
+ return (t >>> 0).toString(36);
1182
+ }, cn = (e, t) => jt(t) ? e.map((n) => {
1183
+ const o = Ke(n.x / t.width), i = Ke(n.y / t.height), c = Ke((n.x + n.width) / t.width), a = Ke((n.y + n.height) / t.height);
1184
+ return {
1185
+ x: o,
1186
+ y: i,
1187
+ width: Ke(c - o),
1188
+ height: Ke(a - i)
1189
+ };
1190
+ }) : [], Jo = (e, t, n = 0) => jt(t) ? e.map((o) => ({
1191
+ x: Ce(o.x) * t.width,
1192
+ y: Ce(o.y) * t.height,
1193
+ width: Ce(o.width) * t.width,
1194
+ height: Ce(o.height) * t.height,
1195
+ pageNumber: n
1196
+ })) : [], Ps = (e) => {
1197
+ const [t] = e.segments, n = e.segments[e.segments.length - 1], o = e.segments.map((i) => i.selectedText).join("");
1198
+ return {
1199
+ version: 1,
1200
+ id: e.id,
1201
+ document: e.document,
1202
+ text: o || e.selection.toString(),
1203
+ start: t ? Hn(
1204
+ t,
1205
+ t.startCharIndex,
1206
+ e.pageSizes.get(at(t))
1207
+ ) : { pageNumber: 1 },
1208
+ end: n ? Hn(
1209
+ n,
1210
+ n.endCharIndex,
1211
+ e.pageSizes.get(at(n))
1212
+ ) : { pageNumber: 1 },
1213
+ segments: e.segments.map(
1214
+ (i) => Yo(
1215
+ i,
1216
+ e.pageSizes.get(at(i))
1217
+ )
1218
+ ),
1219
+ visual: qo(e.rects, e.pageSizes)
1220
+ };
1221
+ }, Es = (e, t) => {
1222
+ const n = /* @__PURE__ */ new Map();
1223
+ for (const a of e.visual)
1224
+ n.set(a.pageNumber, a.pageSize);
1225
+ const o = Un(e.start, t) ?? Gn(e.start, t), i = Un(e.end, t) ?? Gn(e.end, t);
1226
+ if (o && i) {
1227
+ const a = o.element.element.ownerDocument.createRange();
1228
+ a.setStart(ct(o.element.element), o.charIndex), a.setEnd(ct(i.element.element), i.charIndex);
1229
+ const l = e.segments, h = e.segments.flatMap((x) => {
1230
+ const g = Go(x, t);
1231
+ if (!g) return [];
1232
+ const S = Yn(
1233
+ g.element.element,
1234
+ g.startCharIndex,
1235
+ g.endCharIndex
1236
+ );
1237
+ return qn(
1238
+ S,
1239
+ x.pageNumber,
1240
+ x.bbox,
1241
+ n.get(x.pageNumber)
1242
+ );
1243
+ });
1244
+ return Xn(
1245
+ e,
1246
+ a,
1247
+ h,
1248
+ l,
1249
+ e.text
1250
+ );
1251
+ }
1252
+ const c = e.segments.map(
1253
+ (a) => hr(a, t)
1254
+ );
1255
+ if (c.every(Boolean) && c.length > 0) {
1256
+ const a = c[0], l = c[c.length - 1];
1257
+ if (a && l) {
1258
+ const h = a.element.element.ownerDocument.createRange();
1259
+ h.setStart(
1260
+ ct(a.element.element),
1261
+ a.startCharIndex
1262
+ ), h.setEnd(
1263
+ ct(l.element.element),
1264
+ l.endCharIndex
1265
+ );
1266
+ const x = c.flatMap((g, S) => {
1267
+ if (!g) return [];
1268
+ const A = e.segments[S], C = Yn(
1269
+ g.element.element,
1270
+ g.startCharIndex,
1271
+ g.endCharIndex
1272
+ );
1273
+ return qn(
1274
+ C,
1275
+ A.pageNumber,
1276
+ A.bbox,
1277
+ n.get(A.pageNumber)
1278
+ );
1279
+ });
1280
+ return Xn(
1281
+ e,
1282
+ h,
1283
+ x,
1284
+ e.segments,
1285
+ e.text
1286
+ );
1287
+ }
1288
+ }
1289
+ return Xo(e, "text anchors unresolved");
1290
+ }, Zt = (e) => e?.ownerDocument.defaultView?.getSelection?.() ?? null, Ko = [], Jn = [], Zo = [], Qo = 5e3, _e = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), Kn = {
1291
+ width: 595,
1292
+ height: 842
1293
+ }, es = (e, t) => {
1294
+ if (!t)
1295
+ return e;
1296
+ const n = Math.trunc(t.start), o = Math.trunc(t.end);
1297
+ return !Number.isFinite(n) || !Number.isFinite(o) || n > o ? [] : e.filter(
1298
+ (i) => i >= n && i <= o
1299
+ );
1300
+ };
1301
+ function Zn(e, t) {
1302
+ return e === void 0 || !Number.isFinite(e) || e <= 0 ? t : e;
1303
+ }
1304
+ function Qn(e, t) {
1305
+ const n = Zn(e, 0.25), o = Zn(t, 4);
1306
+ return n > o ? { min: n, max: n } : { min: n, max: o };
1307
+ }
1308
+ function Qt(e, t) {
1309
+ const n = Number.isFinite(e) && e > 0 ? e : 1;
1310
+ return Math.max(t.min, Math.min(t.max, n));
1311
+ }
1312
+ function ts(e) {
1313
+ return e === kt.MouseWheelCtrlZoom || e === kt.MouseWheelZoom ? "wheel" : "pinch";
1314
+ }
1315
+ function er(e, t, n) {
1316
+ let i = Math.max(5, t * 2 + 5);
1317
+ return e === 1 / 0 ? 1 / 0 : (typeof e == "number" && Number.isFinite(e) && e > 0 && (i = e), Math.max(i, n, 5));
1318
+ }
1319
+ const ns = (e) => typeof e.getPageByPageNumber == "function", tr = (e) => e ? ns(e) ? e : qr.parse(e) : null, nr = (e) => "content" in e && "fontSize" in e, rs = (e) => !("src" in e) || !("polygon" in e) ? !1 : typeof e.src == "string" && e.src.trim().length > 0, gr = (e) => {
1320
+ const t = !(typeof e?.x == "number" && e.x > 0) || !(typeof e?.y == "number" && e.y > 0), n = typeof e?.x == "number" && e.x > 0 ? e.x : Kn.width, o = typeof e?.y == "number" && e.y > 0 ? e.y : Kn.height;
1321
+ return { width: n, height: o, pageSizeUnavailable: t };
1322
+ }, os = (e, t) => e.get(t) ?? gr(void 0), nn = (e, t) => {
1323
+ const n = e.get(t);
1324
+ return n && !n.pageSizeUnavailable ? n : null;
1325
+ }, ss = (e, t) => {
1326
+ let n = null;
1327
+ for (const o of e) {
1328
+ const i = nn(t, o);
1329
+ if (!i) return null;
1330
+ (!n || i.width > n.width) && (n = i);
1331
+ }
1332
+ return n;
1333
+ }, en = (e, t) => (n) => {
1334
+ const o = new Map(n);
1335
+ return o.set(e, t), o;
1336
+ }, rr = (e, t) => (n) => {
1337
+ const o = new Map(n);
1338
+ return o.set(e, t), o;
1339
+ }, or = (e, t) => (n) => {
1340
+ const o = new Map(n);
1341
+ return o.set(e, t), o;
1342
+ }, sr = (e, t) => (n) => {
1343
+ const o = new Map(n);
1344
+ return t ? o.set(e, t) : o.delete(e), o;
1345
+ }, it = (e) => (t) => {
1346
+ if (!t.has(e))
1347
+ return t;
1348
+ const n = new Map(t);
1349
+ return n.delete(e), n;
1350
+ }, is = (e) => (t) => {
1351
+ if (!t.has(e))
1352
+ return t;
1353
+ const n = new Set(t);
1354
+ return n.delete(e), n;
1355
+ }, cs = (e, t, n) => `${e}::${t}::${n}`, tn = (e) => {
1356
+ if (typeof e == "string" && e.trim())
1357
+ return e;
1358
+ if (e && typeof e == "object") {
1359
+ const t = e;
1360
+ if (typeof t.src == "string" && t.src.trim())
1361
+ return t.src;
1362
+ }
1363
+ }, as = async (e) => {
1364
+ if (!e || typeof e != "object")
1365
+ return;
1366
+ const t = e, n = tn(t.thumbnail) ?? tn(t.image);
1367
+ if (n)
1368
+ return n;
1369
+ if (typeof t.getThumbnail == "function")
1370
+ try {
1371
+ return tn(await t.getThumbnail());
1372
+ } catch {
1373
+ return;
1374
+ }
1375
+ }, us = async (e) => (await fetch(e)).blob(), ls = async (e) => {
1376
+ if (!e || typeof e != "object")
1377
+ return [];
1378
+ const t = e;
1379
+ return typeof t.getContent == "function" ? t.getContent() : typeof t.getTexts == "function" ? t.getTexts() : Array.isArray(t.texts) ? t.texts : [];
1380
+ }, ds = (e, t) => e.map((n) => ({
1381
+ ...n,
1382
+ id: `ocr-${t}-${n.id}`
1383
+ })), fs = (e) => e ? e instanceof Element ? e : e.parentElement : null, ir = (e, t) => {
1384
+ const n = fs(e);
1385
+ if (!n) return null;
1386
+ const o = n.closest(".hsn-selection-container");
1387
+ if (o instanceof HTMLElement) {
1388
+ const l = o.dataset.selectionId;
1389
+ if (l) return l;
1390
+ }
1391
+ const i = n.closest(".hamster-reader__intermediate-page");
1392
+ if (!(i instanceof HTMLElement)) return null;
1393
+ const c = i.dataset.selectionId;
1394
+ if (c) return c;
1395
+ const a = Number(i.dataset.pageNumber);
1396
+ return Number.isFinite(a) ? t(a) : null;
1397
+ };
1398
+ function hs({
1399
+ pageNumbers: e,
1400
+ setPageRef: t,
1401
+ setTextRef: n,
1402
+ runtimePageSelectionId: o,
1403
+ pageSizesByPageNumber: i,
1404
+ textsByPageNumber: c,
1405
+ ocrTextsByPageNumber: a,
1406
+ baseImagesByPageNumber: l,
1407
+ imagesByPageNumber: h,
1408
+ pageStatuses: x,
1409
+ runtimeLinkedData: g,
1410
+ handleLinkedDataChange: S,
1411
+ handleLinkedSelect: A,
1412
+ handleLinkedUpdateRange: C,
1413
+ handleLinkedSelectRange: U,
1414
+ onSelectionStartProp: H,
1415
+ handleSelectionStart: Z,
1416
+ onSelectionEndProp: ie,
1417
+ handleSelectionEnd: ee,
1418
+ autoHighlight: fe,
1419
+ highlightColor: xe,
1420
+ selectionColor: te,
1421
+ overlayRectType: b,
1422
+ effectiveSelectedRangeId: O,
1423
+ selectionPopover: F,
1424
+ highlightPopover: z,
1425
+ popoverVisible: G,
1426
+ selectionRefForRuntimeId: ae,
1427
+ onPageRenderTiming: $
1428
+ }) {
1429
+ const ne = Ie(() => {
1430
+ const B = g.selectedRangeId;
1431
+ if (!B)
1432
+ return null;
1433
+ const re = g.items.find(
1434
+ (oe) => oe.id === B
1435
+ );
1436
+ return re ? re.start.selectionId : null;
1437
+ }, [g.selectedRangeId, g.items]), Te = H ? Z : void 0, ve = ie || fe ? ee : void 0;
1438
+ return /* @__PURE__ */ E.jsx("div", { className: "hamster-note-document", children: e.map((B) => {
1439
+ const re = os(
1440
+ i,
1441
+ B
1442
+ ), oe = o(B), Pe = c.get(B), Ee = l.get(B), u = x.get(B) === "loaded", v = ne === null || ne === oe, M = v ? /* @__PURE__ */ E.jsx(Ln, { visible: G, children: z ?? F }) : void 0, N = v ? /* @__PURE__ */ E.jsx(Ln, { visible: G, children: F }) : void 0, ue = u ? /* @__PURE__ */ E.jsx(
1443
+ zo,
1444
+ {
1445
+ pageNumber: B,
1446
+ texts: Pe ?? Jn,
1447
+ ocrTexts: a.get(B) ?? Jn,
1448
+ baseImageSource: Ee,
1449
+ images: h.get(B) ?? Zo,
1450
+ setTextRef: n,
1451
+ onRenderTiming: $
1452
+ }
1453
+ ) : null;
1454
+ return /* @__PURE__ */ E.jsx(
1455
+ "div",
1456
+ {
1457
+ ref: t(B),
1458
+ className: "hamster-reader__intermediate-page",
1459
+ "data-testid": `intermediate-page-${B}`,
1460
+ "data-page-number": B,
1461
+ "data-selection-id": oe,
1462
+ "data-page-size-unavailable": re.pageSizeUnavailable ? "true" : void 0,
1463
+ style: {
1464
+ position: "relative",
1465
+ width: `${re.width}px`,
1466
+ height: `${re.height}px`,
1467
+ overflow: "hidden"
1468
+ },
1469
+ children: u ? /* @__PURE__ */ E.jsx(
1470
+ Hr,
1471
+ {
1472
+ selectionId: oe,
1473
+ linkedMode: !0,
1474
+ linkedData: g,
1475
+ onLinkedDataChange: S,
1476
+ onLinkedSelect: A,
1477
+ onLinkedUpdateRange: C,
1478
+ onLinkedSelectRange: U,
1479
+ ranges: Ko,
1480
+ selectedRangeId: O,
1481
+ onSelect: void 0,
1482
+ onSelectRange: void 0,
1483
+ onUpdateRange: void 0,
1484
+ onSelectionStart: Te,
1485
+ onSelectionEnd: ve,
1486
+ onHighlight: void 0,
1487
+ highlightColor: xe,
1488
+ selectionColor: te,
1489
+ popover: M,
1490
+ selectionPopover: N,
1491
+ overlayRectType: b,
1492
+ ref: ae(oe),
1493
+ children: ue
1494
+ }
1495
+ ) : null
1496
+ },
1497
+ B
1498
+ );
1499
+ }) });
1500
+ }
1501
+ function gs({
1502
+ rootClassName: e,
1503
+ viewerRootRef: t,
1504
+ pageNumbers: n,
1505
+ pageSizesByPageNumber: o,
1506
+ virtualPaperTransform: i,
1507
+ scaleRange: c,
1508
+ onScrollToRange: a,
1509
+ handleVirtualPaperTransformChange: l,
1510
+ handleVirtualPaperTransformChangeEnd: h,
1511
+ effectiveSelectedRangeId: x,
1512
+ runtimePageSelectionId: g,
1513
+ runtimeLinkedData: S,
1514
+ handleLinkedDataChange: A,
1515
+ handleLinkedSelect: C,
1516
+ handleLinkedUpdateRange: U,
1517
+ handleLinkedSelectRange: H,
1518
+ beginLinkedHighlightOperation: Z,
1519
+ schedulePendingLinkedHighlightCleanup: ie,
1520
+ onSelectionStartProp: ee,
1521
+ handleSelectionStart: fe,
1522
+ onSelectionEndProp: xe,
1523
+ handleSelectionEnd: te,
1524
+ highlightColor: b,
1525
+ selectionColor: O,
1526
+ selectionPopover: F,
1527
+ highlightPopover: z,
1528
+ autoHighlight: G,
1529
+ overlayRectType: ae,
1530
+ selectionRef: $,
1531
+ setPageRef: ne,
1532
+ setTextRef: Te,
1533
+ textsByPageNumber: ve,
1534
+ ocrTextsByPageNumber: B,
1535
+ pageStatuses: re,
1536
+ loadablePages: oe,
1537
+ baseImagesByPageNumber: Pe,
1538
+ imagesByPageNumber: Ee,
1539
+ onPageRenderTiming: u
1540
+ }) {
1541
+ const v = R(/* @__PURE__ */ new Map()), M = R(
1542
+ /* @__PURE__ */ new Map()
1543
+ ), N = R(() => {
1544
+ }), [ue, we] = Q(!0), _ = R(null), W = f(() => {
1545
+ for (const T of n) {
1546
+ const j = g(T), I = v.current.get(j);
1547
+ if (I) return I;
1548
+ }
1549
+ }, [n, g]), ce = f(() => {
1550
+ const T = window.getSelection();
1551
+ if (!T || T.isCollapsed) return;
1552
+ const j = [
1553
+ ir(
1554
+ T.anchorNode,
1555
+ g
1556
+ ),
1557
+ ir(
1558
+ T.focusNode,
1559
+ g
1560
+ )
1561
+ ];
1562
+ for (const I of j) {
1563
+ if (!I) continue;
1564
+ const Y = v.current.get(I);
1565
+ if (Y) return Y;
1566
+ }
1567
+ return j.some(Boolean) ? null : void 0;
1568
+ }, [g]), X = f(() => {
1569
+ const T = S.activeRange;
1570
+ if (!T) return;
1571
+ const j = [
1572
+ T.start.selectionId,
1573
+ T.end.selectionId
1574
+ ];
1575
+ for (const I of j) {
1576
+ const Y = v.current.get(I);
1577
+ if (Y) return Y;
1578
+ }
1579
+ return null;
1580
+ }, [S.activeRange]), k = f(() => {
1581
+ const T = Z();
1582
+ try {
1583
+ const j = ce(), I = j === void 0 ? X() : j;
1584
+ (I === void 0 ? W() : I)?.highlight();
1585
+ } finally {
1586
+ ie(T);
1587
+ }
1588
+ }, [
1589
+ Z,
1590
+ X,
1591
+ ce,
1592
+ W,
1593
+ ie
1594
+ ]), he = f(() => {
1595
+ v.current.forEach((T) => {
1596
+ T.clear();
1597
+ });
1598
+ }, []), y = Ie(
1599
+ () => ({
1600
+ highlight: k,
1601
+ clear: he,
1602
+ scrollToRange: a
1603
+ }),
1604
+ [he, k, a]
1605
+ ), le = f(() => {
1606
+ const T = v.current.size > 0 ? y : null;
1607
+ typeof $ == "function" ? $(T) : $ && ($.current = T);
1608
+ }, [y, $]);
1609
+ N.current = le, K(() => (le(), () => {
1610
+ typeof $ == "function" ? $(null) : $ && ($.current = null);
1611
+ }), [$, le]);
1612
+ const Me = f((T) => {
1613
+ let j = M.current.get(T);
1614
+ return j || (j = (I) => {
1615
+ I ? v.current.set(T, I) : v.current.delete(T), N.current();
1616
+ }, M.current.set(
1617
+ T,
1618
+ j
1619
+ )), j;
1620
+ }, []), Se = f(
1621
+ (T, j) => {
1622
+ G && k(), te(T, j);
1623
+ },
1624
+ [G, te, k]
1625
+ ), de = R(S);
1626
+ de.current = S;
1627
+ const Re = f(
1628
+ (T) => {
1629
+ de.current = T, A(T);
1630
+ },
1631
+ [A]
1632
+ ), Ae = f(
1633
+ (T) => {
1634
+ const j = de.current;
1635
+ j.selectedRangeId !== T && Re({
1636
+ ...j,
1637
+ selectedRangeId: T
1638
+ }), H(T);
1639
+ },
1640
+ [H, Re]
1641
+ ), ke = f(
1642
+ (T, j) => {
1643
+ we(!1), _.current && (clearTimeout(_.current), _.current = null), l(T, j);
1644
+ },
1645
+ [l]
1646
+ ), ye = f(
1647
+ (T, j) => {
1648
+ h(T, j), _.current && clearTimeout(_.current), _.current = setTimeout(() => {
1649
+ we(!0), _.current = null;
1650
+ }, 500);
1651
+ },
1652
+ [h]
1653
+ );
1654
+ K(() => () => {
1655
+ _.current && clearTimeout(_.current);
1656
+ }, []);
1657
+ const ge = /* @__PURE__ */ E.jsx(
1658
+ hs,
1659
+ {
1660
+ pageNumbers: n,
1661
+ setPageRef: ne,
1662
+ setTextRef: Te,
1663
+ runtimePageSelectionId: g,
1664
+ pageSizesByPageNumber: o,
1665
+ textsByPageNumber: ve,
1666
+ ocrTextsByPageNumber: B,
1667
+ pageStatuses: re,
1668
+ loadablePages: oe,
1669
+ baseImagesByPageNumber: Pe,
1670
+ imagesByPageNumber: Ee,
1671
+ runtimeLinkedData: S,
1672
+ handleLinkedDataChange: Re,
1673
+ handleLinkedSelect: C,
1674
+ handleLinkedUpdateRange: U,
1675
+ handleLinkedSelectRange: Ae,
1676
+ onSelectionStartProp: ee,
1677
+ handleSelectionStart: fe,
1678
+ onSelectionEndProp: xe,
1679
+ handleSelectionEnd: Se,
1680
+ autoHighlight: G,
1681
+ highlightColor: b,
1682
+ selectionColor: O,
1683
+ overlayRectType: ae,
1684
+ effectiveSelectedRangeId: x,
1685
+ selectionPopover: F,
1686
+ highlightPopover: z,
1687
+ popoverVisible: ue,
1688
+ selectionRefForRuntimeId: Me,
1689
+ onPageRenderTiming: u
1690
+ }
1691
+ ), me = u ? /* @__PURE__ */ E.jsx(
1692
+ cr,
1693
+ {
1694
+ id: "intermediate-document-shell",
1695
+ onRender: (T, j, I, Y, pe, Qe) => {
1696
+ u(0, pe, Qe, I);
1697
+ },
1698
+ children: ge
1699
+ }
1700
+ ) : ge;
1701
+ return /* @__PURE__ */ E.jsx(
1702
+ "div",
1703
+ {
1704
+ ref: t,
1705
+ role: "document",
1706
+ className: e,
1707
+ "data-testid": "intermediate-document-viewer",
1708
+ children: n.length > 0 ? /* @__PURE__ */ E.jsx(
1709
+ Ur,
1710
+ {
1711
+ containMode: !0,
1712
+ transform: i,
1713
+ minScale: c.min,
1714
+ maxScale: c.max,
1715
+ onTransformChange: ke,
1716
+ onTransformChangeEnd: ye,
1717
+ children: me
1718
+ }
1719
+ ) : null
1720
+ }
1721
+ );
1722
+ }
1723
+ function ms({
1724
+ document: e,
1725
+ serializedDocument: t,
1726
+ className: n,
1727
+ overscan: o = 1,
1728
+ pageRange: i,
1729
+ ocr: c,
1730
+ onOcrError: a,
1731
+ onTextSelectionChange: l,
1732
+ onTextSelectionEnd: h,
1733
+ onSelectText: x,
1734
+ scale: g,
1735
+ defaultScale: S,
1736
+ onScaleChange: A,
1737
+ minScale: C,
1738
+ maxScale: U,
1739
+ maxLoadedPages: H,
1740
+ interactionMode: Z = "default",
1741
+ ranges: ie,
1742
+ defaultRanges: ee,
1743
+ selectedRangeId: fe,
1744
+ defaultSelectedRangeId: xe,
1745
+ onSelect: te,
1746
+ onLinkedDataChange: b,
1747
+ onLinkedSelect: O,
1748
+ onLinkedUpdateRange: F,
1749
+ onLinkedSelectRange: z,
1750
+ onSelectRange: G,
1751
+ onUpdateRange: ae,
1752
+ onSelectionStart: $,
1753
+ onSelectionEnd: ne,
1754
+ onHighlight: Te,
1755
+ highlightColor: ve,
1756
+ selectionColor: B,
1757
+ selectionPopover: re,
1758
+ highlightPopover: oe,
1759
+ autoHighlight: Pe,
1760
+ selectionRef: Ee,
1761
+ overlayRectType: u = "percent",
1762
+ initialLoadedPages: v = 1,
1763
+ pageLoadConcurrency: M = 3,
1764
+ pageLoadEnterDelayMs: N = 500,
1765
+ pageUnloadDelayMs: ue = 5e3,
1766
+ onIntermediateDocumentRenderTiming: we
1767
+ }) {
1768
+ const _ = R(we);
1769
+ _.current = we;
1770
+ const W = R(
1771
+ to({
1772
+ callback: (...r) => _.current?.(...r)
1773
+ })
1774
+ ), ce = R([]), X = R(/* @__PURE__ */ new Map()), k = Ie(() => {
1775
+ const r = e ?? t;
1776
+ if (!W.current.enabled)
1777
+ return tr(r);
1778
+ const s = _e(), d = tr(r), m = _e();
1779
+ return ce.current.push({
1780
+ stage: "document-resolution",
1781
+ startedAt: s,
1782
+ endedAt: m,
1783
+ durationMs: m - s,
1784
+ detail: {
1785
+ hasDocument: !!e,
1786
+ hasSerializedDocument: !!t,
1787
+ pageCount: d?.pageNumbers.length ?? 0
1788
+ }
1789
+ }), d;
1790
+ }, [e, t]);
1791
+ K(() => {
1792
+ const r = ce.current;
1793
+ r.length !== 0 && (ce.current = [], r.forEach((s) => {
1794
+ W.current.record(s);
1795
+ }));
1796
+ });
1797
+ const he = R({
1798
+ initialLoadedPages: v,
1799
+ pageLoadConcurrency: M,
1800
+ pageLoadEnterDelayMs: N,
1801
+ pageUnloadDelayMs: ue
1802
+ });
1803
+ he.current = {
1804
+ initialLoadedPages: v,
1805
+ pageLoadConcurrency: M,
1806
+ pageLoadEnterDelayMs: N,
1807
+ pageUnloadDelayMs: ue
1808
+ };
1809
+ const y = Ie(() => {
1810
+ const r = k?.pageNumbers ?? [];
1811
+ return es(r, i);
1812
+ }, [k, i]), le = Ie(() => {
1813
+ const r = /* @__PURE__ */ new Map();
1814
+ return k && y.forEach((s) => {
1815
+ r.set(
1816
+ s,
1817
+ gr(k.getPageSizeByPageNumber(s))
1818
+ );
1819
+ }), r;
1820
+ }, [k, y]), Me = R(/* @__PURE__ */ new Map()), Se = R(/* @__PURE__ */ new Set()), de = R(/* @__PURE__ */ new Set()), Re = R(/* @__PURE__ */ new Map()), Ae = R(/* @__PURE__ */ new Set()), ke = R(/* @__PURE__ */ new Map()), ye = R(/* @__PURE__ */ new Set()), ge = R(null), me = R(!1), T = R(null), j = R(H);
1821
+ j.current = H;
1822
+ const I = R(Z);
1823
+ I.current = Z;
1824
+ const Y = Vr(), pe = Ie(
1825
+ () => `reader-linked-${Y}`,
1826
+ [Y]
1827
+ ), Qe = f(
1828
+ (r) => lr(pe, r),
1829
+ [pe]
1830
+ ), mr = f(
1831
+ (r, s, d, m) => {
1832
+ if (r === 0) {
1833
+ W.current.record({
1834
+ stage: "shell-rendering",
1835
+ startedAt: s,
1836
+ endedAt: d,
1837
+ durationMs: m,
1838
+ detail: { pageCount: y.length }
1839
+ });
1840
+ return;
1841
+ }
1842
+ W.current.record({
1843
+ stage: "page-content-rendering",
1844
+ startedAt: s,
1845
+ endedAt: d,
1846
+ durationMs: m,
1847
+ pageNumber: r
1848
+ });
1849
+ },
1850
+ [y.length]
1851
+ ), pr = W.current.enabled ? mr : void 0, $t = ie !== void 0, [xr, vr] = Q(
1852
+ () => ee ?? []
1853
+ ), ut = $t ? ie : xr, lt = R(ut);
1854
+ lt.current = ut;
1855
+ const We = R(null), an = R(/* @__PURE__ */ new Set()), un = R(/* @__PURE__ */ new Set()), Bt = fe !== void 0, [wr, Rr] = Q(xe ?? null), Wt = Bt ? fe : wr, [ln, yr] = Q({}), zt = Ie(
1856
+ () => wo({
1857
+ scopeId: pe,
1858
+ ranges: ut,
1859
+ selectedRangeId: Wt,
1860
+ pageNumbers: y,
1861
+ overlayRectType: u,
1862
+ transient: ln
1863
+ }),
1864
+ [
1865
+ ut,
1866
+ Wt,
1867
+ u,
1868
+ y,
1869
+ pe,
1870
+ ln
1871
+ ]
1872
+ ), et = Ie(
1873
+ () => Qn(C, U),
1874
+ [C, U]
1875
+ ), [ze, dn] = Q(
1876
+ () => ({
1877
+ x: 0,
1878
+ y: 0,
1879
+ scale: Qt(
1880
+ S ?? 1,
1881
+ Qn(C, U)
1882
+ )
1883
+ })
1884
+ ), dt = Ie(
1885
+ () => Qt(g ?? ze.scale, et),
1886
+ [g, ze.scale, et]
1887
+ ), ft = R(dt);
1888
+ ft.current = dt;
1889
+ const Tr = Ie(
1890
+ () => ({
1891
+ x: ze.x,
1892
+ y: ze.y,
1893
+ scale: dt
1894
+ }),
1895
+ [dt, ze.x, ze.y]
1896
+ ), Ve = R(/* @__PURE__ */ new Map()), Pr = R(
1897
+ /* @__PURE__ */ new WeakMap()
1898
+ ), [ht, Vt] = Q(() => /* @__PURE__ */ new Set()), fn = R(ht), [je, Ht] = Q(() => /* @__PURE__ */ new Set()), Oe = R(/* @__PURE__ */ new Map()), Fe = R(null), gt = R(!1), Yt = R(!1), qt = R(!1), [Er, br] = Q(0), Ut = R(!1), Ne = R(/* @__PURE__ */ new Set()), mt = R(/* @__PURE__ */ new Set()), tt = R(/* @__PURE__ */ new Map()), nt = R(
1899
+ /* @__PURE__ */ new Map()
1900
+ ), [pt, xt] = Q(
1901
+ () => /* @__PURE__ */ new Map()
1902
+ ), [Gt, vt] = Q(
1903
+ () => /* @__PURE__ */ new Map()
1904
+ ), [He, wt] = Q(
1905
+ () => /* @__PURE__ */ new Map()
1906
+ ), [Rt, yt] = Q(
1907
+ () => /* @__PURE__ */ new Map()
1908
+ ), [hn, Tt] = Q(
1909
+ () => /* @__PURE__ */ new Map()
1910
+ ), Ye = Vo(he, k, {
1911
+ activeDocumentRef: ge,
1912
+ isMountedRef: me,
1913
+ loadingPagesRef: Se,
1914
+ getBaseImageFromPage: as,
1915
+ getPageContentEntries: ls,
1916
+ isIntermediateText: nr,
1917
+ isIntermediateImage: rs,
1918
+ callbacks: {
1919
+ onPageLoaded: ({ pageNumber: r, baseImage: s, texts: d, images: m }) => {
1920
+ const w = X.current.get(r);
1921
+ if (w) {
1922
+ const p = _e();
1923
+ W.current.record({
1924
+ stage: w.stage,
1925
+ startedAt: w.startedAt,
1926
+ endedAt: p,
1927
+ durationMs: p - w.startedAt,
1928
+ pageNumber: r
1929
+ }), W.current.record({
1930
+ stage: "content-extraction",
1931
+ startedAt: w.startedAt,
1932
+ endedAt: p,
1933
+ durationMs: p - w.startedAt,
1934
+ pageNumber: r
1935
+ }), X.current.delete(r);
1936
+ }
1937
+ ye.current.delete(r), yt(
1938
+ sr(r, s)
1939
+ ), xt(en(r, d)), Tt(rr(r, m)), wt(or(r, "loaded"));
1940
+ },
1941
+ onPageError: (r) => {
1942
+ X.current.delete(r), yt(
1943
+ sr(r, void 0)
1944
+ ), xt(en(r, [])), Tt(rr(r, [])), wt(or(r, "error"));
1945
+ },
1946
+ isPageLoaded: (r) => He.get(r) === "loaded" || pt.has(r) || Rt.has(r) || hn.has(r) || ye.current.has(r)
1947
+ }
1948
+ }), gn = R(Ye.enqueuePage);
1949
+ gn.current = Ye.enqueuePage;
1950
+ const Le = R(
1951
+ /* @__PURE__ */ new Map()
1952
+ ), Pt = f(() => {
1953
+ Le.current.forEach((r) => {
1954
+ clearTimeout(r);
1955
+ }), Le.current.clear();
1956
+ }, []), mn = f((r) => {
1957
+ const s = Le.current.get(r);
1958
+ s && (clearTimeout(s), Le.current.delete(r));
1959
+ }, []), pn = f((r) => {
1960
+ if (Le.current.has(r))
1961
+ return;
1962
+ const s = he.current.pageLoadEnterDelayMs, d = setTimeout(() => {
1963
+ Le.current.delete(r), me.current && (W.current.enabled && X.current.set(r, {
1964
+ stage: "visibility-lazy-loading",
1965
+ startedAt: _e()
1966
+ }), gn.current(r));
1967
+ }, s);
1968
+ Le.current.set(r, d);
1969
+ }, []), De = R(
1970
+ /* @__PURE__ */ new Map()
1971
+ ), Et = f((r) => {
1972
+ const s = De.current.get(r);
1973
+ s && (clearTimeout(s), De.current.delete(r));
1974
+ }, []), qe = f(() => {
1975
+ De.current.forEach((r) => {
1976
+ clearTimeout(r);
1977
+ }), De.current.clear();
1978
+ }, []), bt = f((r) => {
1979
+ const s = nt.current.get(r);
1980
+ s && (clearTimeout(s), nt.current.delete(r));
1981
+ }, []), Ue = f(
1982
+ (r, s) => {
1983
+ tt.current.get(r) === s && (bt(r), tt.current.delete(r), mt.current.delete(r));
1984
+ },
1985
+ [bt]
1986
+ ), It = f(() => {
1987
+ nt.current.forEach((r) => {
1988
+ clearTimeout(r);
1989
+ }), nt.current.clear(), tt.current.clear(), mt.current.clear();
1990
+ }, []), xn = f(
1991
+ (r) => {
1992
+ const s = /* @__PURE__ */ Symbol(`jump-target-page-${r}`);
1993
+ bt(r), tt.current.set(r, s), mt.current.add(r);
1994
+ const d = setTimeout(() => {
1995
+ Ue(r, s);
1996
+ }, Qo);
1997
+ return nt.current.set(r, d), s;
1998
+ },
1999
+ [bt, Ue]
2000
+ );
2001
+ K(() => {
2002
+ const r = new Set(y);
2003
+ It(), gt.current = !1, Yt.current = !1, Oe.current.forEach((s, d) => {
2004
+ r.has(d) || Oe.current.delete(d);
2005
+ }), Ne.current.forEach((s) => {
2006
+ r.has(s) || Ne.current.delete(s);
2007
+ });
2008
+ }, [It, y]), K(() => (me.current = !0, () => {
2009
+ me.current = !1, ge.current = null;
2010
+ }), []), K(() => {
2011
+ ge.current = k, Se.current.clear(), de.current.clear(), Re.current.clear(), Ae.current.clear(), ye.current.clear(), Vt(/* @__PURE__ */ new Set()), Ht(/* @__PURE__ */ new Set()), xt(/* @__PURE__ */ new Map()), vt(/* @__PURE__ */ new Map()), wt(/* @__PURE__ */ new Map()), yt(/* @__PURE__ */ new Map()), Tt(/* @__PURE__ */ new Map()), qe(), It();
2012
+ }, [k, qe, It]);
2013
+ const vn = f((r) => {
2014
+ const s = ke.current.get(r) ?? 0;
2015
+ ke.current.set(r, s + 1);
2016
+ }, []), wn = f((r) => {
2017
+ T.current = r;
2018
+ }, []), St = f(
2019
+ (r, s) => {
2020
+ const d = Qt(r.scale, et), m = g !== void 0, w = {
2021
+ x: r.x,
2022
+ y: r.y,
2023
+ scale: m ? ft.current : d
2024
+ }, p = ts(s.source), P = s.source === kt.TouchTwoFingerZoom || s.source === kt.TouchTwoFingerPan;
2025
+ dn(w), P && s.phase !== "end" && (gt.current = !0, Yt.current = !0), s.phase === "end" && (gt.current = !1, Yt.current = !1), d !== ft.current && A?.(d, { source: p });
2026
+ },
2027
+ [A, g, et]
2028
+ ), Ir = f(
2029
+ (r, s) => {
2030
+ qt.current = !0, St(r, s);
2031
+ },
2032
+ [St]
2033
+ ), Sr = f(
2034
+ (r, s) => {
2035
+ qt.current = !1, St(r, s), Ut.current && (Ut.current = !1, br((d) => d + 1));
2036
+ },
2037
+ [St]
2038
+ ), Ge = f(
2039
+ (r) => {
2040
+ const s = y.indexOf(r);
2041
+ if (s === -1)
2042
+ return;
2043
+ const d = Math.max(0, o), m = Math.max(0, s - d), w = Math.min(
2044
+ y.length - 1,
2045
+ s + d
2046
+ );
2047
+ Vt((p) => {
2048
+ let P = !1;
2049
+ for (let q = m; q <= w; q += 1)
2050
+ if (!p.has(y[q])) {
2051
+ P = !0;
2052
+ break;
2053
+ }
2054
+ if (!P)
2055
+ return p;
2056
+ const L = new Set(p);
2057
+ for (let q = m; q <= w; q += 1)
2058
+ L.add(y[q]);
2059
+ return L;
2060
+ });
2061
+ },
2062
+ [o, y]
2063
+ ), _r = f(
2064
+ (r) => {
2065
+ if (!k || y.length === 0) return;
2066
+ const s = ss(
2067
+ y,
2068
+ le
2069
+ );
2070
+ if (!s) return;
2071
+ const d = jn({
2072
+ ranges: lt.current,
2073
+ rangeId: r,
2074
+ rectType: u,
2075
+ pageWidth: s.width,
2076
+ pageHeight: s.height
2077
+ });
2078
+ if (!d || !y.includes(d.pageNumber)) return;
2079
+ const m = nn(
2080
+ le,
2081
+ d.pageNumber
2082
+ );
2083
+ if (!m) return;
2084
+ const w = jn({
2085
+ ranges: lt.current,
2086
+ rangeId: r,
2087
+ rectType: u,
2088
+ pageWidth: m.width,
2089
+ pageHeight: m.height
2090
+ });
2091
+ if (!w) return;
2092
+ const p = T.current?.querySelector(
2093
+ ".virtual-paper-wrapper"
2094
+ );
2095
+ if (!(p instanceof HTMLElement)) return;
2096
+ const P = p.getBoundingClientRect(), L = s.width, q = y.at(-1);
2097
+ if (q === void 0) return;
2098
+ const V = nn(
2099
+ le,
2100
+ q
2101
+ );
2102
+ if (!V) return;
2103
+ const D = Fn(q, y, le) + V.height, se = Fn(
2104
+ w.pageNumber,
2105
+ y,
2106
+ le
2107
+ ), J = (L - m.width) / 2 + w.centerX, $e = se + w.centerY, rt = ao({
2108
+ viewportWidth: P.width,
2109
+ viewportHeight: P.height,
2110
+ contentWidth: L,
2111
+ contentHeight: D,
2112
+ targetContentX: J,
2113
+ targetContentY: $e,
2114
+ scale: ft.current
2115
+ });
2116
+ if (!rt) return;
2117
+ const be = w.pageNumber, Mn = He.get(be) === "loaded", $r = xn(be);
2118
+ Et(be), ye.current.delete(be), Ge(be), Mn ? queueMicrotask(() => {
2119
+ Ue(be, $r);
2120
+ }) : Ye.enqueuePage(be), dn((Br) => ({
2121
+ x: rt.x,
2122
+ y: rt.y,
2123
+ scale: Br.scale
2124
+ }));
2125
+ },
2126
+ [
2127
+ Et,
2128
+ Ye,
2129
+ Ge,
2130
+ u,
2131
+ y,
2132
+ le,
2133
+ He,
2134
+ xn,
2135
+ Ue,
2136
+ k
2137
+ ]
2138
+ );
2139
+ K(() => {
2140
+ He.forEach((r, s) => {
2141
+ if (r !== "loaded" && r !== "error")
2142
+ return;
2143
+ const d = tt.current.get(s);
2144
+ d && Ue(s, d);
2145
+ });
2146
+ }, [He, Ue]);
2147
+ const _t = f(
2148
+ (r) => {
2149
+ if (!k || Se.current.has(r) || de.current.has(r))
2150
+ return !1;
2151
+ const s = `${k.id}::${r}::`;
2152
+ return Re.current.forEach((d, m) => {
2153
+ m.startsWith(s) && Re.current.delete(m);
2154
+ }), Ae.current.add(r), ye.current.add(r), Oe.current.delete(r), Ne.current.delete(r), xt(it(r)), vt(it(r)), yt(it(r)), Tt(it(r)), wt(it(r)), Vt(is(r)), vn(r), !0;
2155
+ },
2156
+ [k, vn]
2157
+ ), Xt = f((r) => {
2158
+ if (!r) return null;
2159
+ const m = (r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement)?.closest("[data-page-number]")?.getAttribute("data-page-number");
2160
+ if (m) {
2161
+ const w = Number(m);
2162
+ if (Number.isFinite(w)) return w;
2163
+ }
2164
+ for (const [w, p] of Me.current.entries())
2165
+ if (p.contains(r)) return w;
2166
+ return null;
2167
+ }, []), Jt = f(
2168
+ (r) => {
2169
+ for (const s of y)
2170
+ if (Qe(s) === r)
2171
+ return s;
2172
+ return null;
2173
+ },
2174
+ [Qe, y]
2175
+ ), Kt = f(
2176
+ (r, s, d) => {
2177
+ const m = y.indexOf(s), w = y.indexOf(d);
2178
+ if (m === -1 || w === -1) {
2179
+ r.add(s), r.add(d);
2180
+ return;
2181
+ }
2182
+ const p = Math.min(m, w), P = Math.max(m, w);
2183
+ for (let L = p; L <= P; L += 1)
2184
+ r.add(y[L]);
2185
+ },
2186
+ [y]
2187
+ ), Xe = f(() => {
2188
+ const r = /* @__PURE__ */ new Set(), s = je.size > 0 ? je : Ne.current;
2189
+ s.forEach((p) => {
2190
+ r.add(p);
2191
+ });
2192
+ const d = Math.max(0, o);
2193
+ s.forEach((p) => {
2194
+ const P = y.indexOf(p);
2195
+ if (P === -1) return;
2196
+ const L = Math.max(0, P - d), q = Math.min(
2197
+ y.length - 1,
2198
+ P + d
2199
+ );
2200
+ for (let V = L; V <= q; V += 1)
2201
+ r.add(y[V]);
2202
+ }), Se.current.forEach((p) => {
2203
+ r.add(p);
2204
+ }), de.current.forEach((p) => {
2205
+ r.add(p);
2206
+ }), mt.current.forEach((p) => {
2207
+ r.add(p);
2208
+ });
2209
+ const m = Zt(T.current);
2210
+ if (m && !m.isCollapsed) {
2211
+ const p = Xt(
2212
+ m.anchorNode
2213
+ ), P = Xt(
2214
+ m.focusNode
2215
+ );
2216
+ p !== null && r.add(p), P !== null && r.add(P), p !== null && P !== null && Kt(r, p, P);
2217
+ }
2218
+ const w = zt.activeRange;
2219
+ if (w) {
2220
+ const p = Jt(
2221
+ w.start.selectionId
2222
+ ), P = Jt(
2223
+ w.end.selectionId
2224
+ );
2225
+ p !== null && r.add(p), P !== null && r.add(P), p !== null && P !== null && Kt(r, p, P);
2226
+ }
2227
+ return r;
2228
+ }, [
2229
+ Kt,
2230
+ o,
2231
+ y,
2232
+ Xt,
2233
+ Jt,
2234
+ zt.activeRange,
2235
+ je
2236
+ ]), Rn = R(Xe);
2237
+ Rn.current = Xe;
2238
+ const yn = f(
2239
+ (r) => {
2240
+ if (De.current.has(r))
2241
+ return;
2242
+ const s = he.current.pageUnloadDelayMs, d = setTimeout(() => {
2243
+ if (De.current.delete(r), !me.current || Rn.current().has(r))
2244
+ return;
2245
+ const w = _e();
2246
+ if (_t(r)) {
2247
+ const P = _e();
2248
+ W.current.record({
2249
+ stage: "offscreen-unload",
2250
+ startedAt: w,
2251
+ endedAt: P,
2252
+ durationMs: P - w,
2253
+ pageNumber: r
2254
+ });
2255
+ }
2256
+ }, s);
2257
+ De.current.set(r, d);
2258
+ },
2259
+ [_t]
2260
+ ), Tn = f(
2261
+ (r) => {
2262
+ if (Fe.current !== null)
2263
+ return;
2264
+ const s = new Set(r.pageNumbers);
2265
+ r.visiblePages.forEach((p) => {
2266
+ s.add(p);
2267
+ });
2268
+ const d = Xe(), m = er(
2269
+ H,
2270
+ o,
2271
+ d.size
2272
+ );
2273
+ if (!Number.isFinite(m))
2274
+ return;
2275
+ const w = () => {
2276
+ if (Fe.current = null, gt.current) {
2277
+ Fe.current = window.setTimeout(w, 50);
2278
+ return;
2279
+ }
2280
+ Oe.current.forEach((D, se) => {
2281
+ s.has(se) || Oe.current.delete(se);
2282
+ }), Ne.current.forEach((D) => {
2283
+ s.has(D) || Ne.current.delete(D);
2284
+ });
2285
+ const p = er(
2286
+ H,
2287
+ o,
2288
+ Xe().size
2289
+ );
2290
+ if (!Number.isFinite(p))
2291
+ return;
2292
+ const P = Array.from(fn.current).filter(
2293
+ (D) => s.has(D)
2294
+ );
2295
+ if (P.length <= p)
2296
+ return;
2297
+ const L = Xe(), q = P.filter((D) => !L.has(D)).sort((D, se) => {
2298
+ const J = Oe.current.get(D) ?? 0, $e = Oe.current.get(se) ?? 0;
2299
+ return J === $e ? D - se : J - $e;
2300
+ });
2301
+ let V = P.length;
2302
+ for (const D of q) {
2303
+ if (V <= p)
2304
+ break;
2305
+ _t(D) && (V -= 1);
2306
+ }
2307
+ };
2308
+ if (typeof window.requestIdleCallback == "function") {
2309
+ Fe.current = window.requestIdleCallback(w, {
2310
+ timeout: 200
2311
+ });
2312
+ return;
2313
+ }
2314
+ Fe.current = window.setTimeout(w, 0);
2315
+ },
2316
+ [_t, Xe, H, o]
2317
+ );
2318
+ K(() => {
2319
+ if (fn.current = ht, qt.current) {
2320
+ Ut.current = !0;
2321
+ return;
2322
+ }
2323
+ return Tn({ visiblePages: je, pageNumbers: y }), () => {
2324
+ const r = Fe.current;
2325
+ r !== null && (typeof window.cancelIdleCallback == "function" && window.cancelIdleCallback(r), window.clearTimeout(r), Fe.current = null);
2326
+ };
2327
+ }, [ht, y, Tn, je, Er]);
2328
+ const Pn = R(
2329
+ /* @__PURE__ */ new Map()
2330
+ ), Cr = f((r) => {
2331
+ let s = Pn.current.get(r);
2332
+ return s || (s = (d) => {
2333
+ d ? Me.current.set(r, d) : Me.current.delete(r);
2334
+ }, Pn.current.set(r, s)), s;
2335
+ }, []), Mr = f(
2336
+ (r, s) => (d) => {
2337
+ d ? (Ve.current.set(r.id, { text: r, pageNumber: s }), ur.set(d, { text: r, pageNumber: s })) : Ve.current.delete(r.id);
2338
+ },
2339
+ []
2340
+ ), En = f(
2341
+ (r, s) => {
2342
+ const d = new Set(
2343
+ r.flatMap((p) => {
2344
+ const P = p.getAttribute("data-text-id");
2345
+ return P ? [P] : [];
2346
+ })
2347
+ ), m = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map();
2348
+ s.querySelectorAll("[data-text-id]").forEach((p) => {
2349
+ if (!(p instanceof HTMLElement)) return;
2350
+ const P = p.getAttribute("data-text-id");
2351
+ if (!P || !Ve.current.has(P)) return;
2352
+ const L = Number(p.getAttribute("data-page-number"));
2353
+ Number.isFinite(L) && (m.set(
2354
+ L,
2355
+ (m.get(L) ?? 0) + 1
2356
+ ), d.has(P) && w.set(
2357
+ L,
2358
+ (w.get(L) ?? 0) + 1
2359
+ ));
2360
+ });
2361
+ for (const [p, P] of m) {
2362
+ if (P < 3) continue;
2363
+ if ((w.get(p) ?? 0) >= Math.ceil(P * 0.9))
2364
+ return !0;
2365
+ }
2366
+ return !1;
2367
+ },
2368
+ []
2369
+ ), bn = f(
2370
+ (r, s) => En(r, s),
2371
+ [En]
2372
+ ), Ct = f(
2373
+ (r) => {
2374
+ if (!r || r.isCollapsed) return null;
2375
+ const s = T.current;
2376
+ if (!s) return null;
2377
+ const d = s.contains(r.anchorNode), m = s.contains(r.focusNode);
2378
+ if (!d || !m) return null;
2379
+ const w = [];
2380
+ if (Ve.current.forEach((D, se) => {
2381
+ const J = s.querySelector(`[data-text-id="${se}"]`);
2382
+ J && r.containsNode(J, !0) && w.push(J);
2383
+ }), w.length === 0)
2384
+ return null;
2385
+ w.sort((D, se) => {
2386
+ const J = D.ownerDocument.createRange();
2387
+ J.setStartBefore(D), J.setEndBefore(se);
2388
+ const $e = J.collapsed ? 1 : -1;
2389
+ return J.detach(), $e;
2390
+ });
2391
+ const p = w[0], P = p.getAttribute("data-text-id"), L = Number(
2392
+ p.getAttribute("data-page-number")
2393
+ );
2394
+ if (bn(w, s) || !P) return null;
2395
+ const q = Ve.current.get(P);
2396
+ if (!q) return null;
2397
+ const V = w.flatMap((D) => {
2398
+ const se = D.getAttribute("data-text-id");
2399
+ if (!se)
2400
+ return [];
2401
+ const J = Ve.current.get(se);
2402
+ return J ? [J.text] : [];
2403
+ });
2404
+ return {
2405
+ text: q.text,
2406
+ texts: V,
2407
+ selectedText: r.toString(),
2408
+ pageNumber: L,
2409
+ selection: r
2410
+ };
2411
+ },
2412
+ [bn]
2413
+ ), In = f(
2414
+ (r) => {
2415
+ Oe.current.set(r, Date.now()), Ge(r), Ht((s) => {
2416
+ if (s.has(r))
2417
+ return s;
2418
+ const d = new Set(s);
2419
+ return d.add(r), Ne.current = new Set(d), d;
2420
+ });
2421
+ },
2422
+ [Ge]
2423
+ ), Sn = f((r) => {
2424
+ Ht((s) => {
2425
+ if (!s.has(r))
2426
+ return s;
2427
+ const d = new Set(s);
2428
+ return d.delete(r), d.size > 0 && (Ne.current = new Set(d)), d;
2429
+ });
2430
+ }, []), Je = f(() => {
2431
+ if (!h && !x)
2432
+ return;
2433
+ const r = Zt(T.current);
2434
+ if (!r) return;
2435
+ const s = Ct(r);
2436
+ if (s && (h && h(s.text, s), x)) {
2437
+ const d = Pr.current.get(s) ?? mo(r);
2438
+ d && x(d.selection, d.segments, d.extractedText);
2439
+ }
2440
+ }, [h, x, Ct]), Ar = f(() => {
2441
+ const r = new Set(
2442
+ lt.current.map((s) => s.id)
2443
+ );
2444
+ return We.current = r, r;
2445
+ }, []), kr = f(
2446
+ (r) => {
2447
+ const s = () => {
2448
+ We.current === r && (We.current = null);
2449
+ }, d = T.current?.ownerDocument.defaultView;
2450
+ if (d) {
2451
+ d.setTimeout(s, 0);
2452
+ return;
2453
+ }
2454
+ globalThis.setTimeout(s, 0);
2455
+ },
2456
+ []
2457
+ ), _n = f(
2458
+ (r) => {
2459
+ an.current.has(r.id) || (an.current.add(r.id), te?.(r));
2460
+ },
2461
+ [te]
2462
+ ), Mt = f(
2463
+ (r) => {
2464
+ const s = We.current;
2465
+ !s || s.has(r.id) || (We.current = null, !un.current.has(r.id) && (un.current.add(r.id), Te?.(r)));
2466
+ },
2467
+ [Te]
2468
+ ), Or = f(
2469
+ (r) => {
2470
+ const s = vo(
2471
+ r,
2472
+ pe
2473
+ ), d = yo(r);
2474
+ yr(
2475
+ (m) => To(m, d) ? m : d
2476
+ ), b?.(s), $t || vr(s.items), Bt || Rr(s.selectedRangeId);
2477
+ for (const m of s.items)
2478
+ if (Mt(m), !We.current)
2479
+ break;
2480
+ },
2481
+ [
2482
+ Mt,
2483
+ $t,
2484
+ Bt,
2485
+ b,
2486
+ pe
2487
+ ]
2488
+ ), Nr = f(
2489
+ (r) => {
2490
+ const s = Ot(r, pe);
2491
+ s && (O?.(s), _n(s), Mt(s));
2492
+ },
2493
+ [
2494
+ _n,
2495
+ Mt,
2496
+ O,
2497
+ pe
2498
+ ]
2499
+ ), jr = f(
2500
+ (r) => {
2501
+ const s = Ot(r, pe);
2502
+ s && (F?.(s), ae?.(s));
2503
+ },
2504
+ [F, ae, pe]
2505
+ ), Fr = f(
2506
+ (r) => {
2507
+ z?.(r), G?.(r);
2508
+ },
2509
+ [z, G]
2510
+ ), Lr = f(
2511
+ (r, s) => {
2512
+ $?.(r, s);
2513
+ },
2514
+ [$]
2515
+ ), Dr = f(
2516
+ (r, s) => {
2517
+ ne?.(r, s);
2518
+ },
2519
+ [ne]
2520
+ );
2521
+ K(() => {
2522
+ if (!k || y.length === 0 || (Ge(y[0]), typeof IntersectionObserver > "u"))
2523
+ return;
2524
+ const r = new IntersectionObserver((s) => {
2525
+ s.forEach((d) => {
2526
+ const m = Number(
2527
+ d.target.dataset.pageNumber
2528
+ );
2529
+ if (Number.isFinite(m))
2530
+ if (d.isIntersecting) {
2531
+ In(m), Et(m), ye.current.delete(m);
2532
+ const w = y.indexOf(m), p = he.current.initialLoadedPages;
2533
+ if (w >= 0 && w < p)
2534
+ return;
2535
+ pn(m);
2536
+ } else
2537
+ Sn(m), mn(m), yn(m);
2538
+ });
2539
+ });
2540
+ return y.forEach((s) => {
2541
+ const d = Me.current.get(s);
2542
+ d && r.observe(d);
2543
+ }), () => {
2544
+ r.disconnect(), Pt(), qe();
2545
+ };
2546
+ }, [
2547
+ Sn,
2548
+ Ge,
2549
+ In,
2550
+ y,
2551
+ k,
2552
+ pn,
2553
+ mn,
2554
+ Pt,
2555
+ Et,
2556
+ yn,
2557
+ qe
2558
+ ]), K(() => {
2559
+ if (k) {
2560
+ if (W.current.enabled) {
2561
+ const r = he.current.initialLoadedPages;
2562
+ y.slice(0, r).forEach((d) => {
2563
+ !pt.has(d) && !Se.current.has(d) && !X.current.has(d) && X.current.set(d, {
2564
+ stage: "initial-page-loading",
2565
+ startedAt: _e()
2566
+ });
2567
+ });
2568
+ }
2569
+ Ye.enqueueInitialPages(y);
2570
+ }
2571
+ }, [y, k, Ye, pt]), K(() => () => {
2572
+ Pt(), qe();
2573
+ }, [Pt, qe]), K(() => {
2574
+ !c || !k || !(c === !0 || typeof c == "object" && c.enabled === !0) || je.forEach((s) => {
2575
+ if (Gt.has(s) || de.current.has(s))
2576
+ return;
2577
+ const d = Rt.get(s);
2578
+ if (!d)
2579
+ return;
2580
+ const m = cs(
2581
+ k.id,
2582
+ s,
2583
+ d
2584
+ ), w = Re.current.get(m), p = Ae.current.has(s);
2585
+ if (w && !p) {
2586
+ vt((V) => {
2587
+ const D = new Map(V);
2588
+ return D.set(s, w), D;
2589
+ });
2590
+ return;
2591
+ }
2592
+ de.current.add(s);
2593
+ const P = ke.current.get(s) ?? 0, L = _e();
2594
+ (async () => {
2595
+ try {
2596
+ const { ImageParser: V } = await import("@hamster-note/image-parser"), D = await us(d), rt = (await (await V.encode(D)).pages)[0]?.content ?? [], be = ds(
2597
+ rt.filter(nr),
2598
+ s
2599
+ );
2600
+ if (!me.current || ge.current !== k || (ke.current.get(s) ?? 0) !== P)
2601
+ return;
2602
+ Re.current.set(m, be), Ae.current.delete(s), vt(en(s, be));
2603
+ } catch (V) {
2604
+ if (!me.current || ge.current !== k)
2605
+ return;
2606
+ a && a(V, { pageNumber: s });
2607
+ } finally {
2608
+ if (me.current && ge.current === k) {
2609
+ const V = _e();
2610
+ W.current.record({
2611
+ stage: "ocr-processing",
2612
+ startedAt: L,
2613
+ endedAt: V,
2614
+ durationMs: V - L,
2615
+ pageNumber: s
2616
+ }), de.current.delete(s);
2617
+ }
2618
+ }
2619
+ })();
2620
+ });
2621
+ }, [
2622
+ je,
2623
+ c,
2624
+ k,
2625
+ Rt,
2626
+ a,
2627
+ Gt
2628
+ ]);
2629
+ const Cn = [
2630
+ "hamster-reader__intermediate-document-viewer",
2631
+ n
2632
+ ].filter(Boolean).join(" ");
2633
+ return K(() => {
2634
+ if (!l) return;
2635
+ const r = () => {
2636
+ const s = Zt(T.current);
2637
+ if (!s) return;
2638
+ const d = Ct(s);
2639
+ d && l(d.text, d);
2640
+ };
2641
+ return globalThis.document.addEventListener(
2642
+ "selectionchange",
2643
+ r
2644
+ ), () => {
2645
+ globalThis.document.removeEventListener(
2646
+ "selectionchange",
2647
+ r
2648
+ );
2649
+ };
2650
+ }, [l, Ct]), K(() => {
2651
+ const r = T.current;
2652
+ if (!r) return;
2653
+ const s = (d) => {
2654
+ d.shiftKey && Je();
2655
+ };
2656
+ return r.addEventListener("touchend", Je), r.addEventListener("mouseup", Je), r.addEventListener("keyup", s), () => {
2657
+ r.removeEventListener("touchend", Je), r.removeEventListener("mouseup", Je), r.removeEventListener("keyup", s);
2658
+ };
2659
+ }, [Je]), k ? /* @__PURE__ */ E.jsx(
2660
+ gs,
2661
+ {
2662
+ rootClassName: Cn,
2663
+ viewerRootRef: wn,
2664
+ pageNumbers: y,
2665
+ pageSizesByPageNumber: le,
2666
+ virtualPaperTransform: Tr,
2667
+ scaleRange: et,
2668
+ onScrollToRange: _r,
2669
+ handleVirtualPaperTransformChange: Ir,
2670
+ handleVirtualPaperTransformChangeEnd: Sr,
2671
+ effectiveSelectedRangeId: Wt,
2672
+ runtimePageSelectionId: Qe,
2673
+ runtimeLinkedData: zt,
2674
+ handleLinkedDataChange: Or,
2675
+ handleLinkedSelect: Nr,
2676
+ handleLinkedUpdateRange: jr,
2677
+ handleLinkedSelectRange: Fr,
2678
+ beginLinkedHighlightOperation: Ar,
2679
+ schedulePendingLinkedHighlightCleanup: kr,
2680
+ onSelectionStartProp: $,
2681
+ handleSelectionStart: Lr,
2682
+ onSelectionEndProp: ne,
2683
+ handleSelectionEnd: Dr,
2684
+ highlightColor: ve,
2685
+ selectionColor: B,
2686
+ selectionPopover: re,
2687
+ highlightPopover: oe,
2688
+ autoHighlight: Pe,
2689
+ overlayRectType: u,
2690
+ selectionRef: Ee,
2691
+ setPageRef: Cr,
2692
+ setTextRef: Mr,
2693
+ textsByPageNumber: pt,
2694
+ ocrTextsByPageNumber: Gt,
2695
+ pageStatuses: He,
2696
+ loadablePages: ht,
2697
+ baseImagesByPageNumber: Rt,
2698
+ imagesByPageNumber: hn,
2699
+ onPageRenderTiming: pr
2700
+ }
2701
+ ) : /* @__PURE__ */ E.jsx(
2702
+ "div",
2703
+ {
2704
+ ref: wn,
2705
+ className: Cn,
2706
+ "data-testid": "intermediate-document-viewer"
2707
+ }
2708
+ );
2709
+ }
2710
+ const ps = ".pdf,application/pdf,.txt,text/plain,.docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document,.md,.markdown,text/markdown,text/x-markdown", xs = (e) => e ? Array.isArray(e.pages) ? e.pages.length > 0 : e.pageCount > 0 : !1;
2711
+ function bs({
2712
+ document: e,
2713
+ className: t,
2714
+ emptyText: n = "No document",
2715
+ onFileUpload: o,
2716
+ overscanPages: i,
2717
+ pageRange: c,
2718
+ ocr: a,
2719
+ onOcrError: l,
2720
+ onTextSelectionChange: h,
2721
+ onTextSelectionEnd: x,
2722
+ onSelectText: g,
2723
+ scale: S,
2724
+ defaultScale: A,
2725
+ onScaleChange: C,
2726
+ minScale: U,
2727
+ maxScale: H,
2728
+ maxLoadedPages: Z,
2729
+ interactionMode: ie,
2730
+ ranges: ee,
2731
+ defaultRanges: fe,
2732
+ selectedRangeId: xe,
2733
+ defaultSelectedRangeId: te,
2734
+ onSelect: b,
2735
+ onLinkedDataChange: O,
2736
+ onLinkedSelect: F,
2737
+ onLinkedUpdateRange: z,
2738
+ onLinkedSelectRange: G,
2739
+ onSelectRange: ae,
2740
+ onUpdateRange: $,
2741
+ onSelectionStart: ne,
2742
+ onSelectionEnd: Te,
2743
+ onHighlight: ve,
2744
+ highlightColor: B,
2745
+ selectionColor: re,
2746
+ selectionPopover: oe,
2747
+ highlightPopover: Pe,
2748
+ autoHighlight: Ee,
2749
+ selectionRef: u,
2750
+ overlayRectType: v = "percent",
2751
+ initialLoadedPages: M,
2752
+ pageLoadConcurrency: N,
2753
+ pageLoadEnterDelayMs: ue,
2754
+ pageUnloadDelayMs: we,
2755
+ onIntermediateDocumentRenderTiming: _
2756
+ }) {
2757
+ const [W, ce] = Q(!1), [X, k] = Q(null), he = R(null), y = f(
2758
+ (I) => {
2759
+ const Y = {
2760
+ name: I.name,
2761
+ size: I.size,
2762
+ type: I.type
2763
+ };
2764
+ k(Y), o?.(I);
2765
+ },
2766
+ [o]
2767
+ ), le = f((I) => {
2768
+ I.preventDefault(), I.stopPropagation(), ce(!0);
2769
+ }, []), Me = f((I) => {
2770
+ I.preventDefault(), I.stopPropagation(), ce(!1);
2771
+ }, []), Se = f(
2772
+ (I) => {
2773
+ I.preventDefault(), I.stopPropagation(), ce(!1);
2774
+ const Y = I.dataTransfer.files;
2775
+ Y.length > 0 && y(Y[0]);
2776
+ },
2777
+ [y]
2778
+ ), de = f(() => {
2779
+ he.current?.click();
2780
+ }, []), Re = f(
2781
+ (I) => {
2782
+ const Y = I.target.files;
2783
+ Y && Y.length > 0 && y(Y[0]);
2784
+ },
2785
+ [y]
2786
+ ), Ae = (I) => I < 1024 ? `${I} B` : I < 1024 * 1024 ? `${(I / 1024).toFixed(1)} KB` : `${(I / (1024 * 1024)).toFixed(1)} MB`, ke = t ? `hamster-reader ${t}` : "hamster-reader", ye = !e && !X, ge = !e && X, me = xs(e), T = e?.title ?? n, j = () => me ? /* @__PURE__ */ E.jsx(
2787
+ ms,
2788
+ {
2789
+ document: e,
2790
+ overscan: i,
2791
+ pageRange: c,
2792
+ ocr: a,
2793
+ onOcrError: l,
2794
+ onTextSelectionChange: h,
2795
+ onTextSelectionEnd: x,
2796
+ onSelectText: g,
2797
+ scale: S,
2798
+ defaultScale: A,
2799
+ onScaleChange: C,
2800
+ minScale: U,
2801
+ maxScale: H,
2802
+ maxLoadedPages: Z,
2803
+ interactionMode: ie,
2804
+ ranges: ee,
2805
+ defaultRanges: fe,
2806
+ selectedRangeId: xe,
2807
+ defaultSelectedRangeId: te,
2808
+ onSelect: b,
2809
+ onLinkedDataChange: O,
2810
+ onLinkedSelect: F,
2811
+ onLinkedUpdateRange: z,
2812
+ onLinkedSelectRange: G,
2813
+ onSelectRange: ae,
2814
+ onUpdateRange: $,
2815
+ onSelectionStart: ne,
2816
+ onSelectionEnd: Te,
2817
+ onHighlight: ve,
2818
+ highlightColor: B,
2819
+ selectionColor: re,
2820
+ selectionPopover: oe,
2821
+ highlightPopover: Pe,
2822
+ autoHighlight: Ee,
2823
+ selectionRef: u,
2824
+ overlayRectType: v,
2825
+ initialLoadedPages: M,
2826
+ pageLoadConcurrency: N,
2827
+ pageLoadEnterDelayMs: ue,
2828
+ pageUnloadDelayMs: we,
2829
+ onIntermediateDocumentRenderTiming: _
2830
+ }
2831
+ ) : ye ? n : T;
2832
+ return /* @__PURE__ */ E.jsxs("div", { className: ke, "data-testid": "reader-root", children: [
2833
+ ye && /* @__PURE__ */ E.jsxs(
2834
+ "button",
2835
+ {
2836
+ type: "button",
2837
+ className: `hamster-reader__upload-zone ${W ? "hamster-reader__upload-zone--dragging" : ""}`,
2838
+ onDragOver: le,
2839
+ onDragLeave: Me,
2840
+ onDrop: Se,
2841
+ onClick: de,
2842
+ "data-testid": "upload-zone",
2843
+ children: [
2844
+ /* @__PURE__ */ E.jsx(
2845
+ "input",
2846
+ {
2847
+ ref: he,
2848
+ type: "file",
2849
+ accept: ps,
2850
+ onChange: Re,
2851
+ className: "hamster-reader__file-input",
2852
+ "data-testid": "file-input"
2853
+ }
2854
+ ),
2855
+ /* @__PURE__ */ E.jsxs("div", { className: "hamster-reader__upload-content", children: [
2856
+ /* @__PURE__ */ E.jsxs(
2857
+ "svg",
2858
+ {
2859
+ className: "hamster-reader__upload-icon",
2860
+ viewBox: "0 0 24 24",
2861
+ fill: "none",
2862
+ stroke: "currentColor",
2863
+ strokeWidth: "2",
2864
+ strokeLinecap: "round",
2865
+ strokeLinejoin: "round",
2866
+ "aria-label": "Upload",
2867
+ children: [
2868
+ /* @__PURE__ */ E.jsx("title", { children: "Upload icon" }),
2869
+ /* @__PURE__ */ E.jsx("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
2870
+ /* @__PURE__ */ E.jsx("polyline", { points: "17 8 12 3 7 8" }),
2871
+ /* @__PURE__ */ E.jsx("line", { x1: "12", y1: "3", x2: "12", y2: "15" })
2872
+ ]
2873
+ }
2874
+ ),
2875
+ /* @__PURE__ */ E.jsx("p", { className: "hamster-reader__upload-text", children: W ? "Drop document here" : "Click or drag document to upload" }),
2876
+ /* @__PURE__ */ E.jsx("p", { className: "hamster-reader__upload-hint", children: "Supports PDF, TXT, DOCX, and Markdown files" })
2877
+ ] })
2878
+ ]
2879
+ }
2880
+ ),
2881
+ T && !ge && /* @__PURE__ */ E.jsx("div", { className: "hamster-reader__content", "data-testid": "reader-content", children: j() }),
2882
+ ge && /* @__PURE__ */ E.jsxs("div", { className: "hamster-reader__file-info", "data-testid": "file-info", children: [
2883
+ /* @__PURE__ */ E.jsxs(
2884
+ "svg",
2885
+ {
2886
+ className: "hamster-reader__file-icon",
2887
+ viewBox: "0 0 24 24",
2888
+ fill: "none",
2889
+ stroke: "currentColor",
2890
+ strokeWidth: "2",
2891
+ strokeLinecap: "round",
2892
+ strokeLinejoin: "round",
2893
+ "aria-label": "File",
2894
+ children: [
2895
+ /* @__PURE__ */ E.jsx("title", { children: "File icon" }),
2896
+ /* @__PURE__ */ E.jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
2897
+ /* @__PURE__ */ E.jsx("polyline", { points: "14 2 14 8 20 8" })
2898
+ ]
2899
+ }
2900
+ ),
2901
+ /* @__PURE__ */ E.jsxs("div", { className: "hamster-reader__file-details", children: [
2902
+ /* @__PURE__ */ E.jsx("p", { className: "hamster-reader__file-name", children: X.name }),
2903
+ /* @__PURE__ */ E.jsxs("p", { className: "hamster-reader__file-meta", children: [
2904
+ Ae(X.size),
2905
+ " •",
2906
+ " ",
2907
+ X.type || "unknown type"
2908
+ ] })
2909
+ ] }),
2910
+ /* @__PURE__ */ E.jsx(
2911
+ "button",
2912
+ {
2913
+ type: "button",
2914
+ className: "hamster-reader__upload-another",
2915
+ onClick: de,
2916
+ "data-testid": "upload-another-btn",
2917
+ children: "Upload Another"
2918
+ }
2919
+ )
2920
+ ] })
2921
+ ] });
2922
+ }
2923
+ export {
2924
+ ms as IntermediateDocumentViewer,
2925
+ bs as Reader,
2926
+ Ps as buildSavedSelection,
2927
+ mo as buildSelectionPayload,
2928
+ to as createIntermediateDocumentRenderTiming,
2929
+ Jo as denormalizePageRects,
2930
+ cn as normalizePageRects,
2931
+ Es as resolveSavedSelection,
2932
+ Ze as textHash
2933
+ };