@arbidocs/react 0.4.128 → 0.4.129

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 (55) hide show
  1. package/dist/artifacts/index.cjs +20 -2
  2. package/dist/artifacts/index.cjs.map +1 -1
  3. package/dist/artifacts/index.d.cts +17 -1
  4. package/dist/artifacts/index.d.ts +17 -1
  5. package/dist/artifacts/index.js +17 -2
  6. package/dist/artifacts/index.js.map +1 -1
  7. package/dist/{chunk-GX75JCPR.cjs → chunk-65WT5PHA.cjs} +361 -189
  8. package/dist/chunk-65WT5PHA.cjs.map +1 -0
  9. package/dist/{chunk-ECOSGMTW.js → chunk-6AWF4HFU.js} +14 -6
  10. package/dist/chunk-6AWF4HFU.js.map +1 -0
  11. package/dist/chunk-6JSXDLIQ.js +101 -0
  12. package/dist/chunk-6JSXDLIQ.js.map +1 -0
  13. package/dist/{chunk-F7KQVVD2.cjs → chunk-BOJHNPNJ.cjs} +14 -6
  14. package/dist/chunk-BOJHNPNJ.cjs.map +1 -0
  15. package/dist/{chunk-EKRRORFO.js → chunk-C44GO33B.js} +105 -46
  16. package/dist/chunk-C44GO33B.js.map +1 -0
  17. package/dist/{chunk-5PQO46PE.js → chunk-J3BYHBKW.js} +358 -189
  18. package/dist/chunk-J3BYHBKW.js.map +1 -0
  19. package/dist/{chunk-TBELZWGV.cjs → chunk-OC7F5SNA.cjs} +108 -44
  20. package/dist/chunk-OC7F5SNA.cjs.map +1 -0
  21. package/dist/chunk-S7J5SCTZ.cjs +110 -0
  22. package/dist/chunk-S7J5SCTZ.cjs.map +1 -0
  23. package/dist/document-tools/index.cjs +69 -121
  24. package/dist/document-tools/index.cjs.map +1 -1
  25. package/dist/document-tools/index.d.cts +16 -4
  26. package/dist/document-tools/index.d.ts +16 -4
  27. package/dist/document-tools/index.js +27 -103
  28. package/dist/document-tools/index.js.map +1 -1
  29. package/dist/{index-B1O2cqOo.d.cts → index-2Y2MVegs.d.cts} +85 -6
  30. package/dist/{index-B1O2cqOo.d.ts → index-2Y2MVegs.d.ts} +85 -6
  31. package/dist/index.cjs +233 -200
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +26 -8
  34. package/dist/index.d.ts +26 -8
  35. package/dist/index.js +16 -8
  36. package/dist/index.js.map +1 -1
  37. package/dist/shell/index.cjs +6 -6
  38. package/dist/shell/index.js +1 -1
  39. package/dist/ui/index.cjs +144 -120
  40. package/dist/ui/index.d.cts +2 -1
  41. package/dist/ui/index.d.ts +2 -1
  42. package/dist/ui/index.js +2 -2
  43. package/dist/viewers/index.cjs +91 -0
  44. package/dist/viewers/index.cjs.map +1 -1
  45. package/dist/viewers/index.d.cts +62 -1
  46. package/dist/viewers/index.d.ts +62 -1
  47. package/dist/viewers/index.js +90 -1
  48. package/dist/viewers/index.js.map +1 -1
  49. package/package.json +8 -3
  50. package/dist/chunk-5PQO46PE.js.map +0 -1
  51. package/dist/chunk-ECOSGMTW.js.map +0 -1
  52. package/dist/chunk-EKRRORFO.js.map +0 -1
  53. package/dist/chunk-F7KQVVD2.cjs.map +0 -1
  54. package/dist/chunk-GX75JCPR.cjs.map +0 -1
  55. package/dist/chunk-TBELZWGV.cjs.map +0 -1
@@ -211,4 +211,65 @@ declare const INITIAL_LAZY_LOAD_BUFFER: {
211
211
  after: number;
212
212
  };
213
213
 
214
- export { AudioViewer, type AudioViewerProps, DocumentViewer, type DocumentViewerProps, DocxViewer, type DocxViewerProps, INITIAL_LAZY_LOAD_BUFFER, ImageViewer, type ImageViewerProps, LAZY_LOAD_BUFFER_AFTER, LAZY_LOAD_BUFFER_BEFORE, MAX_ZOOM, MIN_ZOOM, type NativeViewerKind, PAGE_SELECTOR, PdfViewerAssets, VideoViewer, type VideoViewerProps, XlsxViewer, type XlsxViewerProps, anchorDelta, anchoredScroll, clampZoom, cycleZoom, doubleTapZoom, nativeViewerKind, pinchZoom, renderDpr, usePageIntersectionObserver, usePinchZoom, useScrollAnchor, zoomLabel };
214
+ /**
215
+ * Processed Chunks Hook
216
+ *
217
+ * Processes raw document chunks into page-grouped structure.
218
+ * Pre-computes footnote inlining so it runs once during processing, not on every render.
219
+ */
220
+ interface RawChunk {
221
+ content: string;
222
+ metadata?: {
223
+ page_number?: number;
224
+ chunk_doc_idx?: number;
225
+ chunk_ext_id?: string;
226
+ doc_title?: string | null;
227
+ };
228
+ }
229
+ interface ProcessedChunk {
230
+ content: string;
231
+ chunkIndex: number | undefined;
232
+ chunkExtId: string | undefined;
233
+ docTitle: string | undefined;
234
+ }
235
+ interface ProcessedPage {
236
+ pageNumber: number | null;
237
+ chunks: ProcessedChunk[];
238
+ }
239
+ interface UseProcessedChunksResult {
240
+ processedChunks: ProcessedPage[];
241
+ maxPageNumber: number;
242
+ }
243
+ declare function useProcessedChunks(chunks: RawChunk[] | undefined, footnotes?: Record<string, string>): UseProcessedChunksResult;
244
+
245
+ /**
246
+ * Contiguous-run grouping for selected passages.
247
+ *
248
+ * Selecting passages 4–9 is one citation, not six. This collapses a flat set of
249
+ * selected chunk ids into the contiguous runs they form in document order, so
250
+ * the viewer can draw each run as a single block with a single "p.3(4–9)" label
251
+ * instead of stacking six identical pills.
252
+ *
253
+ * Purely positional: the pages arrive in document order (which is
254
+ * `chunk_doc_idx` order), so adjacency is just "next in the list".
255
+ */
256
+ interface RunChunk {
257
+ chunkExtId: string | undefined;
258
+ /** 0-based index within the document; displayed 1-based */
259
+ chunkIndex: number | undefined;
260
+ }
261
+ interface RunPage {
262
+ pageNumber: number | null;
263
+ chunks: RunChunk[];
264
+ }
265
+ /** Where a selected chunk sits inside its contiguous run of selected chunks. */
266
+ interface ChunkRunInfo {
267
+ isStart: boolean;
268
+ isEnd: boolean;
269
+ /** Set only on the run's first member — the bounds its single label shows. */
270
+ endIndex: number | undefined;
271
+ endPage: number | null | undefined;
272
+ }
273
+ declare function computeSelectionRuns(pages: RunPage[], selectedChunks: Set<string>): Map<string, ChunkRunInfo>;
274
+
275
+ export { AudioViewer, type AudioViewerProps, type ChunkRunInfo, DocumentViewer, type DocumentViewerProps, DocxViewer, type DocxViewerProps, INITIAL_LAZY_LOAD_BUFFER, ImageViewer, type ImageViewerProps, LAZY_LOAD_BUFFER_AFTER, LAZY_LOAD_BUFFER_BEFORE, MAX_ZOOM, MIN_ZOOM, type NativeViewerKind, PAGE_SELECTOR, PdfViewerAssets, type ProcessedChunk, type ProcessedPage, type RawChunk, type RunChunk, type RunPage, type UseProcessedChunksResult, VideoViewer, type VideoViewerProps, XlsxViewer, type XlsxViewerProps, anchorDelta, anchoredScroll, clampZoom, computeSelectionRuns, cycleZoom, doubleTapZoom, nativeViewerKind, pinchZoom, renderDpr, usePageIntersectionObserver, usePinchZoom, useProcessedChunks, useScrollAnchor, zoomLabel };
@@ -894,7 +894,96 @@ function DocumentViewer({
894
894
  })();
895
895
  return className ? /* @__PURE__ */ jsx("div", { className, "data-testid": "document-viewer", children: body }) : body;
896
896
  }
897
+ function inlineFootnotes(content, footnotes) {
898
+ if (!footnotes || Object.keys(footnotes).length === 0) return content;
899
+ let result = content;
900
+ result = result.replace(/^\[\^[^\]]+\]:[ \t]+.*(?:\n(?:[ \t]+.+)?)*/gm, "");
901
+ result = result.replace(/\[\^([^\]]+)\]/g, (_match, key) => {
902
+ const fnContent = footnotes[key];
903
+ if (!fnContent) return `<sup class="fn-ref">${key}</sup>`;
904
+ const escaped = fnContent.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
905
+ return `<sup class="fn-ref">${key}</sup><span class="fn-inline" title="${escaped}">[${escaped}]</span>`;
906
+ });
907
+ return result.trim();
908
+ }
909
+ function useProcessedChunks(chunks, footnotes) {
910
+ return useMemo(() => {
911
+ if (!chunks || chunks.length === 0) {
912
+ return { processedChunks: [], maxPageNumber: 0 };
913
+ }
914
+ const hasFootnotes = footnotes && Object.keys(footnotes).length > 0;
915
+ const chunksByPage = [];
916
+ let currentPageNumber = -1;
917
+ let currentPageChunks = [];
918
+ let maxPageNumber = 0;
919
+ chunks.forEach((chunk) => {
920
+ const pageNum = chunk.metadata?.page_number;
921
+ if (pageNum && pageNum > maxPageNumber) {
922
+ maxPageNumber = pageNum;
923
+ }
924
+ if (pageNum !== currentPageNumber) {
925
+ if (currentPageChunks.length > 0) {
926
+ chunksByPage.push({
927
+ pageNumber: currentPageNumber > 0 ? currentPageNumber : null,
928
+ chunks: currentPageChunks
929
+ });
930
+ }
931
+ currentPageNumber = pageNum ?? -1;
932
+ currentPageChunks = [];
933
+ }
934
+ currentPageChunks.push({
935
+ content: hasFootnotes ? inlineFootnotes(chunk.content, footnotes) : chunk.content,
936
+ chunkIndex: chunk.metadata?.chunk_doc_idx,
937
+ chunkExtId: chunk.metadata?.chunk_ext_id,
938
+ docTitle: chunk.metadata?.doc_title ?? void 0
939
+ });
940
+ });
941
+ if (currentPageChunks.length > 0) {
942
+ chunksByPage.push({
943
+ pageNumber: currentPageNumber > 0 ? currentPageNumber : null,
944
+ chunks: currentPageChunks
945
+ });
946
+ }
947
+ return { processedChunks: chunksByPage, maxPageNumber };
948
+ }, [chunks, footnotes]);
949
+ }
950
+
951
+ // src/viewers/selection-runs.ts
952
+ function computeSelectionRuns(pages, selectedChunks) {
953
+ const runs = /* @__PURE__ */ new Map();
954
+ if (selectedChunks.size === 0) return runs;
955
+ const flat = pages.flatMap(
956
+ (page) => page.chunks.map((c) => ({ ...c, pageNumber: page.pageNumber }))
957
+ );
958
+ let i = 0;
959
+ while (i < flat.length) {
960
+ const chunk = flat[i];
961
+ if (!chunk.chunkExtId || !selectedChunks.has(chunk.chunkExtId)) {
962
+ i += 1;
963
+ continue;
964
+ }
965
+ let end = i;
966
+ while (end + 1 < flat.length && flat[end + 1].chunkExtId && selectedChunks.has(flat[end + 1].chunkExtId)) {
967
+ end += 1;
968
+ }
969
+ const last = flat[end];
970
+ const endIndex = last.chunkIndex !== void 0 ? last.chunkIndex + 1 : void 0;
971
+ for (let k = i; k <= end; k += 1) {
972
+ const id = flat[k].chunkExtId;
973
+ if (!id) continue;
974
+ runs.set(id, {
975
+ isStart: k === i,
976
+ isEnd: k === end,
977
+ // Only the run's first member carries the label bounds.
978
+ endIndex: k === i ? endIndex : void 0,
979
+ endPage: k === i ? last.pageNumber : void 0
980
+ });
981
+ }
982
+ i = end + 1;
983
+ }
984
+ return runs;
985
+ }
897
986
 
898
- export { DocumentViewer, DocxViewer, INITIAL_LAZY_LOAD_BUFFER, LAZY_LOAD_BUFFER_AFTER, LAZY_LOAD_BUFFER_BEFORE, MAX_ZOOM, MIN_ZOOM, PAGE_SELECTOR, PdfViewer, XlsxViewer, anchorDelta, anchoredScroll, clampZoom, cycleZoom, doubleTapZoom, nativeViewerKind, pinchZoom, renderDpr, usePageIntersectionObserver, usePinchZoom, useScrollAnchor, zoomLabel };
987
+ export { DocumentViewer, DocxViewer, INITIAL_LAZY_LOAD_BUFFER, LAZY_LOAD_BUFFER_AFTER, LAZY_LOAD_BUFFER_BEFORE, MAX_ZOOM, MIN_ZOOM, PAGE_SELECTOR, PdfViewer, XlsxViewer, anchorDelta, anchoredScroll, clampZoom, computeSelectionRuns, cycleZoom, doubleTapZoom, nativeViewerKind, pinchZoom, renderDpr, usePageIntersectionObserver, usePinchZoom, useProcessedChunks, useScrollAnchor, zoomLabel };
899
988
  //# sourceMappingURL=index.js.map
900
989
  //# sourceMappingURL=index.js.map