@pi-outpost/embed 0.34.0 → 0.35.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.
@@ -1,4 +1,4 @@
1
- import { a as e } from "./workspacePath-CpsPdoMU.js";
1
+ import { a as e } from "./workspacePath-Dzahj9-k.js";
2
2
  import { n as t, t as n } from "./findInPage-xFP831JH.js";
3
3
  import { forwardRef as r, useCallback as i, useEffect as a, useImperativeHandle as o, useRef as s, useState as c } from "react";
4
4
  import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
@@ -65,19 +65,19 @@ function _(e) {
65
65
  case "unreadable": return "This file could not be read as a PDF.";
66
66
  }
67
67
  }
68
- async function v(t, n, r, i) {
69
- let a = await fetch(e(t, n, null, i), { headers: r ? { Authorization: `Bearer ${r}` } : {} });
70
- if (!a.ok) {
71
- if (a.status === 413) {
72
- let e = await a.json().catch(() => ({}));
68
+ async function v(t, n, r, i, a) {
69
+ let o = await fetch(e(t, n, null, i, a), { headers: r ? { Authorization: `Bearer ${r}` } : {} });
70
+ if (!o.ok) {
71
+ if (o.status === 413) {
72
+ let e = await o.json().catch(() => ({}));
73
73
  throw {
74
74
  kind: "too-large",
75
75
  ...typeof e.limit == "number" ? { limitBytes: e.limit } : {}
76
76
  };
77
77
  }
78
- throw a.status === 401 || a.status === 403 ? { kind: "unauthorized" } : a.status === 404 ? { kind: "not-found" } : { kind: "unreadable" };
78
+ throw o.status === 401 || o.status === 403 ? { kind: "unauthorized" } : o.status === 404 ? { kind: "not-found" } : { kind: "unreadable" };
79
79
  }
80
- return new Uint8Array(await a.arrayBuffer());
80
+ return new Uint8Array(await o.arrayBuffer());
81
81
  }
82
82
  var y = null;
83
83
  function b() {
@@ -193,15 +193,15 @@ function ne({ doc: e, pageNumber: t, scale: n, baseSize: r, active: i, registerS
193
193
  })] }) : null
194
194
  });
195
195
  }
196
- var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l = 0, onLoaded: f, findQuery: g = "", onFindStateChange: y }, b) {
197
- let [x, S] = c(null), [w, T] = c(null), [E, D] = c(1), [O, k] = c(2), [A, j] = c(null), M = s(null), N = s(/* @__PURE__ */ new Map()), [P, F] = c(/* @__PURE__ */ new Map()), [I, L] = c(!1), [R, z] = c([]), [B, V] = c(-1), H = s(null), U = s(!1), W = s(g), G = s(/* @__PURE__ */ new Map()), K = s(null), q = s([]), J = s(-1), Y = s(g);
196
+ var w = r(function({ path: e, serverUrl: n = "", token: r = null, workspace: l, revision: f = 0, onLoaded: g, findQuery: y = "", onFindStateChange: b }, x) {
197
+ let [S, w] = c(null), [T, E] = c(null), [D, O] = c(1), [k, A] = c(2), [re, j] = c(null), M = s(null), N = s(/* @__PURE__ */ new Map()), [P, F] = c(/* @__PURE__ */ new Map()), [I, L] = c(!1), [R, z] = c([]), [B, V] = c(-1), H = s(null), U = s(!1), W = s(y), G = s(/* @__PURE__ */ new Map()), K = s(null), q = s([]), J = s(-1), Y = s(y);
198
198
  a(() => {
199
199
  q.current = R;
200
200
  }, [R]), a(() => {
201
201
  J.current = B;
202
202
  }, [B]), a(() => {
203
- Y.current = g;
204
- }, [g]);
203
+ Y.current = y;
204
+ }, [y]);
205
205
  let X = i(() => {
206
206
  K.current?.result.clear(), K.current = null;
207
207
  }, []), Z = i((e, n) => {
@@ -214,7 +214,7 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
214
214
  let i = r.matches[e.ordinalOnPage]?.marks ?? [];
215
215
  for (let e of i) e.classList.add("find-match-current");
216
216
  i[0]?.scrollIntoView({ block: "center" });
217
- }, [X]), re = i((e, t) => {
217
+ }, [X]), ie = i((e, t) => {
218
218
  if (t === null) {
219
219
  G.current.delete(e);
220
220
  return;
@@ -225,9 +225,9 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
225
225
  }, [Z]);
226
226
  a(() => {
227
227
  let t = !1, i = null;
228
- return S(null), T(null), D(1), j(null), H.current?.cancel(), H.current = null, U.current = !1, F(/* @__PURE__ */ new Map()), L(!1), z([]), V(-1), X(), G.current.clear(), (async () => {
228
+ return w(null), E(null), O(1), j(null), H.current?.cancel(), H.current = null, U.current = !1, F(/* @__PURE__ */ new Map()), L(!1), z([]), V(-1), X(), G.current.clear(), (async () => {
229
229
  try {
230
- let { doc: a, task: o } = await ee(await v(n, e, r, l));
230
+ let { doc: a, task: o } = await ee(await v(n, e, r, f, l));
231
231
  if (i = o, t) {
232
232
  await o.destroy().catch(() => {});
233
233
  return;
@@ -245,9 +245,9 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
245
245
  });
246
246
  }
247
247
  if (t) return;
248
- S(a), f?.(e);
248
+ w(a), g?.(e);
249
249
  } catch (e) {
250
- t || T(te(e) ? e : { kind: "unreadable" });
250
+ t || E(te(e) ? e : { kind: "unreadable" });
251
251
  }
252
252
  })(), () => {
253
253
  t = !0, i?.destroy().catch(() => {});
@@ -256,47 +256,48 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
256
256
  e,
257
257
  n,
258
258
  r,
259
- l
259
+ l,
260
+ f
260
261
  ]);
261
- let Q = x?.numPages ?? 0, ie = i((e, t) => {
262
+ let Q = S?.numPages ?? 0, ae = i((e, t) => {
262
263
  t === null ? N.current.delete(e) : N.current.set(e, t);
263
264
  }, []);
264
265
  a(() => {
265
- if (x === null || g === "" || U.current) return;
266
+ if (S === null || y === "" || U.current) return;
266
267
  U.current = !0, L(!0);
267
- let e = x, t = {
268
+ let e = S, t = {
268
269
  numPages: e.numPages,
269
270
  getPageText: async (t) => {
270
271
  let n = await e.getPage(t);
271
272
  return n.getTextContent === void 0 ? "" : (await n.getTextContent()).items.map((e) => typeof e.str == "string" ? e.str : "").join("");
272
273
  }
273
274
  };
274
- H.current = p(t, E, (e, t) => F((n) => {
275
+ H.current = p(t, D, (e, t) => F((n) => {
275
276
  let r = new Map(n);
276
277
  return r.set(e, t), r;
277
278
  }), () => L(!1));
278
- }, [x, g]), a(() => () => {
279
+ }, [S, y]), a(() => () => {
279
280
  H.current?.cancel(), H.current = null;
280
- }, [x]), a(() => {
281
- let e = m(P, x?.numPages ?? 0, g), t = g !== W.current;
282
- W.current = g, z(e), V((n) => e.length === 0 ? -1 : t || n === -1 ? 0 : Math.min(n, e.length - 1));
281
+ }, [S]), a(() => {
282
+ let e = m(P, S?.numPages ?? 0, y), t = y !== W.current;
283
+ W.current = y, z(e), V((n) => e.length === 0 ? -1 : t || n === -1 ? 0 : Math.min(n, e.length - 1));
283
284
  }, [
284
285
  P,
285
- g,
286
- x
286
+ y,
287
+ S
287
288
  ]), a(() => {
288
289
  if (B === -1 || R.length === 0) {
289
290
  X();
290
291
  return;
291
292
  }
292
293
  let e = R[B];
293
- if (K.current !== null && K.current.page !== e.page && X(), Math.abs(e.page - E) > C) {
294
+ if (K.current !== null && K.current.page !== e.page && X(), Math.abs(e.page - D) > C) {
294
295
  $(e.page);
295
296
  return;
296
297
  }
297
298
  let t = G.current.get(e.page);
298
299
  t !== void 0 && Z(e, t);
299
- }, [B, R]), o(b, () => ({
300
+ }, [B, R]), o(x, () => ({
300
301
  findNext() {
301
302
  q.current.length !== 0 && V((e) => (e + 1) % q.current.length);
302
303
  },
@@ -304,7 +305,7 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
304
305
  q.current.length !== 0 && V((e) => (e - 1 + q.current.length) % q.current.length);
305
306
  }
306
307
  }), []), a(() => {
307
- y?.({
308
+ b?.({
308
309
  matchCount: R.length,
309
310
  currentIndex: B,
310
311
  searching: I
@@ -314,14 +315,14 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
314
315
  B,
315
316
  I
316
317
  ]), a(() => {
317
- if (x === null || typeof IntersectionObserver > "u") return;
318
+ if (S === null || typeof IntersectionObserver > "u") return;
318
319
  let e = M.current;
319
320
  if (e === null) return;
320
321
  let t = new IntersectionObserver((e) => {
321
322
  for (let t of e) {
322
323
  if (!t.isIntersecting) continue;
323
324
  let e = Number(t.target.dataset.page);
324
- Number.isFinite(e) && D(e);
325
+ Number.isFinite(e) && O(e);
325
326
  }
326
327
  }, {
327
328
  root: e,
@@ -330,11 +331,11 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
330
331
  });
331
332
  for (let e of N.current.values()) t.observe(e);
332
333
  return () => t.disconnect();
333
- }, [x, Q]);
334
+ }, [S, Q]);
334
335
  let $ = i((e) => {
335
- e < 1 || e > Q || (D(e), N.current.get(e)?.scrollIntoView({ block: "start" }));
336
+ e < 1 || e > Q || (O(e), N.current.get(e)?.scrollIntoView({ block: "start" }));
336
337
  }, [Q]);
337
- return w === null ? x === null ? /* @__PURE__ */ u("div", {
338
+ return T === null ? S === null ? /* @__PURE__ */ u("div", {
338
339
  className: "flex h-full items-center justify-center p-6",
339
340
  children: /* @__PURE__ */ u("p", {
340
341
  className: "text-sm text-zinc-500",
@@ -343,8 +344,8 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
343
344
  }) : /* @__PURE__ */ d("div", {
344
345
  className: "flex h-full flex-col",
345
346
  onKeyDown: (e) => {
346
- if (e.key === "PageDown" || e.key === "ArrowRight") $(E + 1);
347
- else if (e.key === "PageUp" || e.key === "ArrowLeft") $(E - 1);
347
+ if (e.key === "PageDown" || e.key === "ArrowRight") $(D + 1);
348
+ else if (e.key === "PageUp" || e.key === "ArrowLeft") $(D - 1);
348
349
  else return;
349
350
  e.preventDefault();
350
351
  },
@@ -353,8 +354,8 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
353
354
  children: [
354
355
  /* @__PURE__ */ u("button", {
355
356
  type: "button",
356
- onClick: () => $(E - 1),
357
- disabled: E <= 1,
357
+ onClick: () => $(D - 1),
358
+ disabled: D <= 1,
358
359
  "aria-label": "Previous page",
359
360
  className: "rounded px-2 py-1 hover:bg-zinc-100 disabled:opacity-40 dark:hover:bg-zinc-800",
360
361
  children: "‹"
@@ -363,15 +364,15 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
363
364
  className: "tabular-nums text-zinc-600 dark:text-zinc-400",
364
365
  children: [
365
366
  "Page ",
366
- E,
367
+ D,
367
368
  " / ",
368
369
  Q
369
370
  ]
370
371
  }),
371
372
  /* @__PURE__ */ u("button", {
372
373
  type: "button",
373
- onClick: () => $(E + 1),
374
- disabled: E >= Q,
374
+ onClick: () => $(D + 1),
375
+ disabled: D >= Q,
375
376
  "aria-label": "Next page",
376
377
  className: "rounded px-2 py-1 hover:bg-zinc-100 disabled:opacity-40 dark:hover:bg-zinc-800",
377
378
  children: "›"
@@ -381,20 +382,20 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
381
382
  children: [
382
383
  /* @__PURE__ */ u("button", {
383
384
  type: "button",
384
- onClick: () => k((e) => Math.max(0, e - 1)),
385
- disabled: O === 0,
385
+ onClick: () => A((e) => Math.max(0, e - 1)),
386
+ disabled: k === 0,
386
387
  "aria-label": "Zoom out",
387
388
  className: "rounded px-2 py-1 hover:bg-zinc-100 disabled:opacity-40 dark:hover:bg-zinc-800",
388
389
  children: "−"
389
390
  }),
390
391
  /* @__PURE__ */ d("span", {
391
392
  className: "tabular-nums text-zinc-500",
392
- children: [Math.round(h[O] * 100), "%"]
393
+ children: [Math.round(h[k] * 100), "%"]
393
394
  }),
394
395
  /* @__PURE__ */ u("button", {
395
396
  type: "button",
396
- onClick: () => k((e) => Math.min(h.length - 1, e + 1)),
397
- disabled: O === h.length - 1,
397
+ onClick: () => A((e) => Math.min(h.length - 1, e + 1)),
398
+ disabled: k === h.length - 1,
398
399
  "aria-label": "Zoom in",
399
400
  className: "rounded px-2 py-1 hover:bg-zinc-100 disabled:opacity-40 dark:hover:bg-zinc-800",
400
401
  children: "+"
@@ -405,21 +406,21 @@ var w = r(function({ path: e, serverUrl: n = "", token: r = null, revision: l =
405
406
  }), /* @__PURE__ */ u("div", {
406
407
  ref: M,
407
408
  className: "flex-1 overflow-auto bg-zinc-100 p-4 dark:bg-zinc-950",
408
- children: A !== null && Array.from({ length: Q }, (e, t) => t + 1).map((e) => /* @__PURE__ */ u(ne, {
409
- doc: x,
409
+ children: re !== null && Array.from({ length: Q }, (e, t) => t + 1).map((e) => /* @__PURE__ */ u(ne, {
410
+ doc: S,
410
411
  pageNumber: e,
411
- scale: h[O],
412
- baseSize: A,
413
- active: Math.abs(e - E) <= C,
414
- registerSlot: ie,
415
- onTextLayerReady: re
412
+ scale: h[k],
413
+ baseSize: re,
414
+ active: Math.abs(e - D) <= C,
415
+ registerSlot: ae,
416
+ onTextLayerReady: ie
416
417
  }, e))
417
418
  })]
418
419
  }) : /* @__PURE__ */ u("div", {
419
420
  className: "flex h-full items-center justify-center p-6",
420
421
  children: /* @__PURE__ */ u("p", {
421
422
  className: "max-w-md text-center text-sm text-zinc-600 dark:text-zinc-400",
422
- children: _(w)
423
+ children: _(T)
423
424
  })
424
425
  });
425
426
  });