react-docxodus-viewer 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as c, Fragment as ze } from "react/jsx-runtime";
2
2
  import { useState as o, useMemo as ne, useRef as we, useEffect as $, useCallback as f } from "react";
3
3
  import { useDocxodus as gn, PaginatedDocument as cn } from "docxodus/react";
4
- import { isFormatChange as S, isMove as Q, isDeletion as ge, isInsertion as ce, PaginationMode as tn, getDocumentMetadata as In, AnnotationLabelMode as q, CommentRenderMode as ee } from "docxodus";
4
+ import { isFormatChange as D, isMove as U, isDeletion as ge, isInsertion as ce, PaginationMode as tn, getDocumentMetadata as In, AnnotationLabelMode as q, CommentRenderMode as ee } from "docxodus";
5
5
  import { RevisionType as Bn, isDeletion as Xn, isFormatChange as Nn, isInsertion as Rn, isMove as Hn } from "docxodus";
6
6
  function z() {
7
7
  return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
@@ -137,10 +137,10 @@ const dn = {
137
137
  annotationCssClassPrefix: "annot-"
138
138
  };
139
139
  function on(g) {
140
- return ce(g) ? "Inserted" : ge(g) ? "Deleted" : Q(g) ? g.isMoveSource ? "Moved from" : "Moved to" : S(g) ? "Formatted" : String(g.revisionType);
140
+ return ce(g) ? "Inserted" : ge(g) ? "Deleted" : U(g) ? g.isMoveSource ? "Moved from" : "Moved to" : D(g) ? "Formatted" : String(g.revisionType);
141
141
  }
142
142
  function Cn(g) {
143
- return ce(g) ? "rdv-revision--insertion" : ge(g) ? "rdv-revision--deletion" : Q(g) ? "rdv-revision--move" : S(g) ? "rdv-revision--format" : "";
143
+ return ce(g) ? "rdv-revision--insertion" : ge(g) ? "rdv-revision--deletion" : U(g) ? "rdv-revision--move" : D(g) ? "rdv-revision--format" : "";
144
144
  }
145
145
  function rn(g) {
146
146
  try {
@@ -198,9 +198,9 @@ function bn({ revisions: g }) {
198
198
  case "deletions":
199
199
  return ge(t);
200
200
  case "moves":
201
- return Q(t);
201
+ return U(t);
202
202
  case "formatting":
203
- return S(t);
203
+ return D(t);
204
204
  default:
205
205
  return !0;
206
206
  }
@@ -208,8 +208,8 @@ function bn({ revisions: g }) {
208
208
  total: g.length,
209
209
  insertions: g.filter(ce).length,
210
210
  deletions: g.filter(ge).length,
211
- moves: g.filter(Q).length,
212
- formatting: g.filter(S).length
211
+ moves: g.filter(U).length,
212
+ formatting: g.filter(D).length
213
213
  }), [g]), h = (t) => {
214
214
  m((i) => {
215
215
  const d = new Set(i);
@@ -277,7 +277,7 @@ function bn({ revisions: g }) {
277
277
  )
278
278
  ] }),
279
279
  /* @__PURE__ */ e("div", { className: "rdv-revision-list", children: C.map((t, i) => {
280
- const d = A.has(i), b = t.text.length > 150, y = S(t) ? mn(t) : [];
280
+ const d = A.has(i), b = t.text.length > 150, y = D(t) ? mn(t) : [];
281
281
  return /* @__PURE__ */ c(
282
282
  "div",
283
283
  {
@@ -285,7 +285,7 @@ function bn({ revisions: g }) {
285
285
  children: [
286
286
  /* @__PURE__ */ c("div", { className: "rdv-revision-item__header", children: [
287
287
  /* @__PURE__ */ e("span", { className: "rdv-revision-type", children: on(t) }),
288
- Q(t) && t.moveGroupId !== void 0 && /* @__PURE__ */ c("span", { className: "rdv-revision-move-id", children: [
288
+ U(t) && t.moveGroupId !== void 0 && /* @__PURE__ */ c("span", { className: "rdv-revision-move-id", children: [
289
289
  "#",
290
290
  t.moveGroupId
291
291
  ] }),
@@ -362,7 +362,7 @@ function pn({
362
362
  style: y,
363
363
  toolbar: r = "top",
364
364
  showSettingsButton: te = !0,
365
- showRevisionsTab: D = !0,
365
+ showRevisionsTab: P = !0,
366
366
  placeholder: fe = "Open a DOCX file to view",
367
367
  wasmBasePath: Ie,
368
368
  useWorker: u = !0
@@ -370,23 +370,23 @@ function pn({
370
370
  const ae = ne(
371
371
  () => ({ ...dn, ...i }),
372
372
  [i]
373
- ), [Ye, ue] = o(null), [Je, U] = o(null), [Ze, ke] = o(ae), X = g !== void 0 ? g : Ye, N = s !== void 0 ? s : Je, a = ne(
373
+ ), [Ye, ue] = o(null), [Je, x] = o(null), [Ze, ke] = o(ae), N = g !== void 0 ? g : Ye, G = s !== void 0 ? s : Je, a = ne(
374
374
  () => t ? { ...ae, ...t } : Ze,
375
375
  [t, ae, Ze]
376
- ), R = gn(Ie), [G, he] = o(null), [Ke, ve] = o(!1), [Se, le] = o(!1), [Qe, Ve] = o(null), P = we(null);
376
+ ), R = gn(Ie), [W, he] = o(null), [Ke, ve] = o(!1), [Se, le] = o(!1), [Qe, Ve] = o(null), M = we(null);
377
377
  $(() => {
378
378
  if (!u || !sn())
379
379
  return;
380
380
  let n = !1;
381
381
  return le(!0), Ve(null), ln({ wasmBasePath: Ie }).then((I) => {
382
- n ? I.terminate() : (P.current = I, he(I), ve(!0), le(!1));
382
+ n ? I.terminate() : (M.current = I, he(I), ve(!0), le(!1));
383
383
  }).catch((I) => {
384
384
  n || (Ve(I instanceof Error ? I : new Error(String(I))), le(!1));
385
385
  }), () => {
386
- n = !0, P.current && (P.current.terminate(), P.current = null, he(null), ve(!1));
386
+ n = !0, M.current && (M.current.terminate(), M.current = null, he(null), ve(!1));
387
387
  };
388
388
  }, [u, Ie]);
389
- const H = u ? Ke : R.isReady, Y = u ? Se : R.isLoading, x = u ? Qe : R.error, [W, ye] = o(!1), [pe, M] = o(null), [Ge, We] = o(""), [B, ie] = o(1), [p, se] = o(0), [De, L] = o(!1), [J, j] = o("document"), [de, O] = o([]), [Ue, Be] = o(!1), [F, T] = o(null), oe = we(null), Ce = f(() => ({
389
+ const H = u ? Ke : R.isReady, Y = u ? Se : R.isLoading, L = u ? Qe : R.error, [B, ye] = o(!1), [pe, j] = o(null), [Ge, We] = o(""), [X, ie] = o(1), [p, se] = o(0), [De, O] = o(!1), [J, k] = o("document"), [de, K] = o([]), [Ue, Be] = o(!1), [F, T] = o(null), oe = we(null), Ce = f(() => ({
390
390
  commentRenderMode: un(a.commentMode),
391
391
  pageTitle: a.pageTitle,
392
392
  cssPrefix: a.cssPrefix,
@@ -405,47 +405,47 @@ function pn({
405
405
  renderMoveOperations: a.renderMoveOperations
406
406
  }), [a]), Pe = f(async (n) => {
407
407
  try {
408
- const I = u && G ? await G.getDocumentMetadata(n) : await In(n);
408
+ const I = u && W ? await W.getDocumentMetadata(n) : await In(n);
409
409
  T(I);
410
410
  } catch {
411
411
  T(null);
412
412
  }
413
- }, [u, G]), Xe = f(async (n) => {
414
- if (!(!H || !D)) {
413
+ }, [u, W]), Xe = f(async (n) => {
414
+ if (!(!H || !P)) {
415
415
  Be(!0);
416
416
  try {
417
- const I = u && G ? await G.getRevisions(n) : await R.getRevisions(n);
418
- O(I), h?.(I);
417
+ const I = u && W ? await W.getRevisions(n) : await R.getRevisions(n);
418
+ K(I), h?.(I);
419
419
  } catch {
420
- O([]);
420
+ K([]);
421
421
  } finally {
422
422
  Be(!1);
423
423
  }
424
424
  }
425
- }, [H, u, G, R, D, h]), k = f(async (n) => {
425
+ }, [H, u, W, R, P, h]), S = f(async (n) => {
426
426
  if (H) {
427
- ye(!0), M(null), O([]), j("document"), A?.(), u || await new Promise((I) => requestAnimationFrame(() => requestAnimationFrame(I)));
427
+ ye(!0), j(null), K([]), k("document"), A?.(), u || await new Promise((I) => requestAnimationFrame(() => requestAnimationFrame(I)));
428
428
  try {
429
- const I = u && G ? await G.convertDocxToHtml(n, Ce()) : await R.convertToHtml(n, Ce());
430
- s === void 0 && U(I), m?.(I), Xe(n);
429
+ const I = u && W ? await W.convertDocxToHtml(n, Ce()) : await R.convertToHtml(n, Ce());
430
+ s === void 0 && x(I), m?.(I), Xe(n);
431
431
  } catch (I) {
432
432
  const V = I instanceof Error ? I : new Error(String(I));
433
- M(V), C?.(V);
433
+ j(V), C?.(V);
434
434
  } finally {
435
435
  ye(!1);
436
436
  }
437
437
  }
438
- }, [H, u, G, R, Ce, s, A, m, C, Xe]);
438
+ }, [H, u, W, R, Ce, s, A, m, C, Xe]);
439
439
  $(() => {
440
- H && X && !N && !W && s === void 0 && k(X);
441
- }, [H, X, N, W, k, s]);
440
+ H && N && !G && !B && s === void 0 && S(N);
441
+ }, [H, N, G, B, S, s]);
442
442
  const xe = async (n) => {
443
443
  const I = n.target.files?.[0];
444
- I && (We(I.name), M(null), ie(1), se(0), T(null), g === void 0 && (ue(I), U(null)), Z?.(I), Pe(I), H && s === void 0 && await k(I));
444
+ I && (We(I.name), j(null), ie(1), se(0), T(null), K([]), k("document"), g === void 0 && (ue(I), x(null)), Z?.(I), Pe(I), H && s === void 0 && await S(I));
445
445
  }, Me = f(async () => {
446
- X && (s === void 0 && U(null), await k(X));
447
- }, [X, k, s]), Le = () => {
448
- g === void 0 && ue(null), s === void 0 && U(null), M(null), We(""), ie(1), se(0), O([]), j("document"), T(null), Z?.(null);
446
+ N && (s === void 0 && x(null), await S(N));
447
+ }, [N, S, s]), Le = () => {
448
+ g === void 0 && ue(null), s === void 0 && x(null), j(null), We(""), ie(1), se(0), K([]), k("document"), T(null), Z?.(null);
449
449
  const n = document.getElementById("rdv-file-input");
450
450
  n && (n.value = "");
451
451
  }, v = f((n) => {
@@ -462,7 +462,7 @@ function pn({
462
462
  if (!I || n < 1 || n > p) return;
463
463
  const V = I.querySelector(`[data-page-number="${n}"]`);
464
464
  V && V.scrollIntoView({ behavior: "smooth", block: "start" });
465
- }, Ee = () => B > 1 && re(B - 1), _e = () => B < p && re(B + 1), $e = (n) => {
465
+ }, Ee = () => X > 1 && re(X - 1), _e = () => X < p && re(X + 1), $e = (n) => {
466
466
  ie(n), l?.(n, p);
467
467
  };
468
468
  $(() => {
@@ -471,20 +471,20 @@ function pn({
471
471
  const I = (V) => {
472
472
  const E = V.target.closest('a[href^="#"]');
473
473
  if (!E) return;
474
- const K = E.getAttribute("href");
475
- if (!K || !K.startsWith("#")) return;
474
+ const Q = E.getAttribute("href");
475
+ if (!Q || !Q.startsWith("#")) return;
476
476
  V.preventDefault();
477
- const He = K.substring(1), _ = n.querySelector(`[id="${He}"], [name="${He}"]`);
477
+ const He = Q.substring(1), _ = n.querySelector(`[id="${He}"], [name="${He}"]`);
478
478
  _ && (_.scrollIntoView({ behavior: "smooth", block: "center" }), _.classList.add("rdv-footnote-highlight"), setTimeout(() => _.classList.remove("rdv-footnote-highlight"), 2e3));
479
479
  };
480
480
  return n.addEventListener("click", I), () => n.removeEventListener("click", I);
481
- }, [N]), $(() => {
482
- p > 0 && l?.(B, p);
483
- }, [p, B, l]);
484
- const Ne = W || Y, qe = () => /* @__PURE__ */ e("div", { className: "rdv-settings-overlay", onClick: () => L(!1), children: /* @__PURE__ */ c("div", { className: "rdv-settings-modal", onClick: (n) => n.stopPropagation(), children: [
481
+ }, [G]), $(() => {
482
+ p > 0 && l?.(X, p);
483
+ }, [p, X, l]);
484
+ const Ne = B || Y, qe = () => /* @__PURE__ */ e("div", { className: "rdv-settings-overlay", onClick: () => O(!1), children: /* @__PURE__ */ c("div", { className: "rdv-settings-modal", onClick: (n) => n.stopPropagation(), children: [
485
485
  /* @__PURE__ */ c("div", { className: "rdv-settings-header", children: [
486
486
  /* @__PURE__ */ e("h3", { children: "Viewer Settings" }),
487
- /* @__PURE__ */ e("button", { className: "rdv-settings-close", onClick: () => L(!1), children: "×" })
487
+ /* @__PURE__ */ e("button", { className: "rdv-settings-close", onClick: () => O(!1), children: "×" })
488
488
  ] }),
489
489
  /* @__PURE__ */ c("div", { className: "rdv-settings-body", children: [
490
490
  /* @__PURE__ */ c("div", { className: "rdv-settings-section", children: [
@@ -596,7 +596,7 @@ function pn({
596
596
  ] })
597
597
  ] }),
598
598
  /* @__PURE__ */ e("div", { className: "rdv-settings-footer", children: /* @__PURE__ */ e("button", { className: "rdv-settings-apply", onClick: () => {
599
- Me(), L(!1);
599
+ Me(), O(!1);
600
600
  }, children: "Apply & Close" }) })
601
601
  ] }) }), en = de.length > 0, Re = () => /* @__PURE__ */ c("div", { className: "rdv-toolbar", children: [
602
602
  /* @__PURE__ */ c("div", { className: "rdv-toolbar-left", children: [
@@ -613,14 +613,14 @@ function pn({
613
613
  }
614
614
  ),
615
615
  Ge && /* @__PURE__ */ e("button", { className: "rdv-toolbar-btn rdv-toolbar-clear", onClick: Le, disabled: Ne, children: "×" }),
616
- D && en && /* @__PURE__ */ c(ze, { children: [
616
+ P && en && G && /* @__PURE__ */ c(ze, { children: [
617
617
  /* @__PURE__ */ e("div", { className: "rdv-toolbar-separator" }),
618
618
  /* @__PURE__ */ c("div", { className: "rdv-view-tabs", children: [
619
619
  /* @__PURE__ */ e(
620
620
  "button",
621
621
  {
622
622
  className: `rdv-view-tab ${J === "document" ? "rdv-view-tab--active" : ""}`,
623
- onClick: () => j("document"),
623
+ onClick: () => k("document"),
624
624
  title: "View Document",
625
625
  children: "Document"
626
626
  }
@@ -629,7 +629,7 @@ function pn({
629
629
  "button",
630
630
  {
631
631
  className: `rdv-view-tab ${J === "revisions" ? "rdv-view-tab--active" : ""}`,
632
- onClick: () => j("revisions"),
632
+ onClick: () => k("revisions"),
633
633
  title: "View Tracked Changes",
634
634
  children: [
635
635
  "Changes (",
@@ -640,15 +640,15 @@ function pn({
640
640
  )
641
641
  ] })
642
642
  ] }),
643
- D && Ue && /* @__PURE__ */ e("span", { className: "rdv-extracting-indicator", title: "Extracting tracked changes...", children: "..." })
643
+ P && Ue && /* @__PURE__ */ e("span", { className: "rdv-extracting-indicator", title: "Extracting tracked changes...", children: "..." })
644
644
  ] }),
645
- /* @__PURE__ */ e("div", { className: "rdv-toolbar-center", children: N && p > 0 && J === "document" && /* @__PURE__ */ c(ze, { children: [
645
+ /* @__PURE__ */ e("div", { className: "rdv-toolbar-center", children: G && p > 0 && J === "document" && /* @__PURE__ */ c(ze, { children: [
646
646
  /* @__PURE__ */ e(
647
647
  "button",
648
648
  {
649
649
  className: "rdv-toolbar-btn",
650
650
  onClick: Ee,
651
- disabled: B <= 1,
651
+ disabled: X <= 1,
652
652
  title: "Previous Page",
653
653
  children: "◀"
654
654
  }
@@ -659,7 +659,7 @@ function pn({
659
659
  {
660
660
  type: "number",
661
661
  className: "rdv-page-input",
662
- value: B,
662
+ value: X,
663
663
  min: 1,
664
664
  max: p,
665
665
  onChange: (n) => {
@@ -678,7 +678,7 @@ function pn({
678
678
  {
679
679
  className: "rdv-toolbar-btn",
680
680
  onClick: _e,
681
- disabled: B >= p,
681
+ disabled: X >= p,
682
682
  title: "Next Page",
683
683
  children: "▶"
684
684
  }
@@ -727,7 +727,7 @@ function pn({
727
727
  "button",
728
728
  {
729
729
  className: "rdv-toolbar-btn rdv-toolbar-settings",
730
- onClick: () => L(!0),
730
+ onClick: () => O(!0),
731
731
  title: "Settings",
732
732
  children: "⚙"
733
733
  }
@@ -736,21 +736,21 @@ function pn({
736
736
  return /* @__PURE__ */ c("div", { className: nn, style: y, children: [
737
737
  r === "top" && /* @__PURE__ */ e(Re, {}),
738
738
  /* @__PURE__ */ c("div", { className: "rdv-content", children: [
739
- x && /* @__PURE__ */ e("div", { className: "rdv-message rdv-message--error", children: /* @__PURE__ */ c("p", { children: [
739
+ L && /* @__PURE__ */ e("div", { className: "rdv-message rdv-message--error", children: /* @__PURE__ */ c("p", { children: [
740
740
  "Failed to initialize: ",
741
- x.message
741
+ L.message
742
742
  ] }) }),
743
- !x && (Y || W) && (F && W ? (
743
+ !L && (Y || B) && (F && B ? (
744
744
  // Show page placeholders while converting
745
745
  /* @__PURE__ */ e("div", { className: "rdv-pages rdv-pages--loading", children: /* @__PURE__ */ e("div", { className: "rdv-page-placeholders", style: { backgroundColor: "#525659" }, children: Array.from({ length: F.estimatedPageCount || 1 }).map((n, I) => {
746
- const V = F.sections[Math.min(I, F.sections.length - 1)], Ae = a.paginationScale, E = Math.round((V?.pageWidthPt || 612) * (96 / 72) * Ae), K = Math.round((V?.pageHeightPt || 792) * (96 / 72) * Ae);
746
+ const V = F.sections[Math.min(I, F.sections.length - 1)], Ae = a.paginationScale, E = Math.round((V?.pageWidthPt || 612) * (96 / 72) * Ae), Q = Math.round((V?.pageHeightPt || 792) * (96 / 72) * Ae);
747
747
  return /* @__PURE__ */ c(
748
748
  "div",
749
749
  {
750
750
  className: "rdv-page-placeholder",
751
751
  style: {
752
752
  width: `${E}px`,
753
- height: `${K}px`,
753
+ height: `${Q}px`,
754
754
  marginBottom: "20px"
755
755
  },
756
756
  children: [
@@ -773,20 +773,20 @@ function pn({
773
773
  }) }) })
774
774
  ) : /* @__PURE__ */ c("div", { className: "rdv-message", children: [
775
775
  /* @__PURE__ */ e("div", { className: "rdv-spinner" }),
776
- /* @__PURE__ */ e("p", { children: Y && X ? "Loading engine & preparing document..." : Y ? "Loading document engine..." : "Processing document..." })
776
+ /* @__PURE__ */ e("p", { children: Y && N ? "Loading engine & preparing document..." : Y ? "Loading document engine..." : "Processing document..." })
777
777
  ] })),
778
- !Y && !x && !N && !W && !X && /* @__PURE__ */ c("div", { className: "rdv-message", children: [
778
+ !Y && !L && !G && !B && !N && /* @__PURE__ */ c("div", { className: "rdv-message", children: [
779
779
  /* @__PURE__ */ e("div", { className: "rdv-message__icon", children: "📄" }),
780
780
  /* @__PURE__ */ e("p", { children: fe })
781
781
  ] }),
782
- pe && !W && /* @__PURE__ */ e("div", { className: "rdv-message rdv-message--error", children: /* @__PURE__ */ c("p", { children: [
782
+ pe && !B && /* @__PURE__ */ e("div", { className: "rdv-message rdv-message--error", children: /* @__PURE__ */ c("p", { children: [
783
783
  "Error: ",
784
784
  pe.message
785
785
  ] }) }),
786
- N && !W && J === "document" && /* @__PURE__ */ e("div", { ref: oe, className: "rdv-pages", children: /* @__PURE__ */ e(
786
+ J === "document" && G && !B && /* @__PURE__ */ e("div", { ref: oe, className: "rdv-pages", children: /* @__PURE__ */ e(
787
787
  cn,
788
788
  {
789
- html: N,
789
+ html: G,
790
790
  scale: a.paginationScale,
791
791
  showPageNumbers: a.showPageNumbers,
792
792
  pageGap: 20,
@@ -798,7 +798,7 @@ function pn({
798
798
  onPageVisible: $e
799
799
  }
800
800
  ) }),
801
- N && !W && J === "revisions" && /* @__PURE__ */ e(bn, { revisions: de })
801
+ J === "revisions" && G && !B && /* @__PURE__ */ e(bn, { revisions: de })
802
802
  ] }),
803
803
  r === "bottom" && /* @__PURE__ */ e(Re, {}),
804
804
  De && /* @__PURE__ */ e(qe, {})