@elabs-ai/components-viewer 4.0.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.
Files changed (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -0
  3. package/dist/chunk-2NQ4RSJ3.js +18 -0
  4. package/dist/chunk-2NQ4RSJ3.js.map +1 -0
  5. package/dist/chunk-3U3MESBU.js +21 -0
  6. package/dist/chunk-3U3MESBU.js.map +1 -0
  7. package/dist/chunk-4OFQYALG.js +147 -0
  8. package/dist/chunk-4OFQYALG.js.map +1 -0
  9. package/dist/chunk-5OMONA2G.js +87 -0
  10. package/dist/chunk-5OMONA2G.js.map +1 -0
  11. package/dist/chunk-AORNMH77.js +58 -0
  12. package/dist/chunk-AORNMH77.js.map +1 -0
  13. package/dist/chunk-BCF3RWRL.js +18 -0
  14. package/dist/chunk-BCF3RWRL.js.map +1 -0
  15. package/dist/chunk-FELIAGKI.js +22 -0
  16. package/dist/chunk-FELIAGKI.js.map +1 -0
  17. package/dist/chunk-GGR7BNW4.js +18 -0
  18. package/dist/chunk-GGR7BNW4.js.map +1 -0
  19. package/dist/chunk-H3OAON3D.js +22 -0
  20. package/dist/chunk-H3OAON3D.js.map +1 -0
  21. package/dist/chunk-HMG2ERXH.js +17 -0
  22. package/dist/chunk-HMG2ERXH.js.map +1 -0
  23. package/dist/chunk-KOMDRWOU.js +21 -0
  24. package/dist/chunk-KOMDRWOU.js.map +1 -0
  25. package/dist/chunk-NMA57QZ7.js +117 -0
  26. package/dist/chunk-NMA57QZ7.js.map +1 -0
  27. package/dist/chunk-RGWDIQJR.js +26 -0
  28. package/dist/chunk-RGWDIQJR.js.map +1 -0
  29. package/dist/chunk-SLXRUYT3.js +91 -0
  30. package/dist/chunk-SLXRUYT3.js.map +1 -0
  31. package/dist/chunk-UJIJECEF.js +21 -0
  32. package/dist/chunk-UJIJECEF.js.map +1 -0
  33. package/dist/chunk-UL43NGUG.js +68 -0
  34. package/dist/chunk-UL43NGUG.js.map +1 -0
  35. package/dist/chunk-VO2273Z2.js +55 -0
  36. package/dist/chunk-VO2273Z2.js.map +1 -0
  37. package/dist/code-adapter-ADZ4UOGN.js +226 -0
  38. package/dist/code-adapter-ADZ4UOGN.js.map +1 -0
  39. package/dist/csv-adapter-6VU3FFVU.js +100 -0
  40. package/dist/csv-adapter-6VU3FFVU.js.map +1 -0
  41. package/dist/docx-adapter-5CQDHWTD.js +383 -0
  42. package/dist/docx-adapter-5CQDHWTD.js.map +1 -0
  43. package/dist/image-adapter-WOHZR24J.js +132 -0
  44. package/dist/image-adapter-WOHZR24J.js.map +1 -0
  45. package/dist/index.d.ts +1353 -0
  46. package/dist/index.js +1364 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/json-adapter-ZUW5GQHE.js +90 -0
  49. package/dist/json-adapter-ZUW5GQHE.js.map +1 -0
  50. package/dist/markdown-adapter-YC6WTBS4.js +214 -0
  51. package/dist/markdown-adapter-YC6WTBS4.js.map +1 -0
  52. package/dist/media-adapter-MCTB4GBH.js +78 -0
  53. package/dist/media-adapter-MCTB4GBH.js.map +1 -0
  54. package/dist/pdf-adapter-5PMKEXUD.js +424 -0
  55. package/dist/pdf-adapter-5PMKEXUD.js.map +1 -0
  56. package/dist/pptx-adapter-6GEQLS2Z.js +351 -0
  57. package/dist/pptx-adapter-6GEQLS2Z.js.map +1 -0
  58. package/dist/text-adapter-NFNWB5W3.js +81 -0
  59. package/dist/text-adapter-NFNWB5W3.js.map +1 -0
  60. package/dist/xlsx-adapter-CM2Y6AKQ.js +167 -0
  61. package/dist/xlsx-adapter-CM2Y6AKQ.js.map +1 -0
  62. package/package.json +103 -0
  63. package/src/adapters/code/code-adapter.test.tsx +221 -0
  64. package/src/adapters/code/code-adapter.tsx +272 -0
  65. package/src/adapters/code/code-language.test.ts +45 -0
  66. package/src/adapters/code/code-language.ts +100 -0
  67. package/src/adapters/code/code-manifest.ts +19 -0
  68. package/src/adapters/code/code-theme.test.ts +46 -0
  69. package/src/adapters/code/code-theme.ts +99 -0
  70. package/src/adapters/csv/csv-adapter.test.tsx +169 -0
  71. package/src/adapters/csv/csv-adapter.tsx +146 -0
  72. package/src/adapters/csv/csv-manifest.ts +20 -0
  73. package/src/adapters/docx/docx-adapter.test.tsx +192 -0
  74. package/src/adapters/docx/docx-adapter.tsx +328 -0
  75. package/src/adapters/docx/docx-manifest.ts +18 -0
  76. package/src/adapters/docx/docx-model.test.ts +181 -0
  77. package/src/adapters/docx/docx-model.ts +294 -0
  78. package/src/adapters/image/image-adapter.test.tsx +141 -0
  79. package/src/adapters/image/image-adapter.tsx +191 -0
  80. package/src/adapters/image/image-manifest.ts +15 -0
  81. package/src/adapters/index.ts +64 -0
  82. package/src/adapters/json/json-adapter.test.tsx +77 -0
  83. package/src/adapters/json/json-adapter.tsx +141 -0
  84. package/src/adapters/json/json-manifest.ts +11 -0
  85. package/src/adapters/markdown/markdown-adapter.test.tsx +228 -0
  86. package/src/adapters/markdown/markdown-adapter.tsx +353 -0
  87. package/src/adapters/markdown/markdown-manifest.ts +21 -0
  88. package/src/adapters/markdown/markdown-marks.test.ts +85 -0
  89. package/src/adapters/markdown/markdown-marks.ts +119 -0
  90. package/src/adapters/media/media-adapter.test.tsx +79 -0
  91. package/src/adapters/media/media-adapter.tsx +123 -0
  92. package/src/adapters/media/media-manifest.ts +17 -0
  93. package/src/adapters/office-fixture.ts +239 -0
  94. package/src/adapters/pdf/pdf-adapter.test.tsx +489 -0
  95. package/src/adapters/pdf/pdf-adapter.tsx +599 -0
  96. package/src/adapters/pdf/pdf-engine.ts +171 -0
  97. package/src/adapters/pdf/pdf-fixture.ts +27 -0
  98. package/src/adapters/pdf/pdf-manifest.ts +30 -0
  99. package/src/adapters/pdf/pdf-text.test.ts +171 -0
  100. package/src/adapters/pdf/pdf-text.ts +202 -0
  101. package/src/adapters/pptx/pptx-adapter.test.tsx +241 -0
  102. package/src/adapters/pptx/pptx-adapter.tsx +341 -0
  103. package/src/adapters/pptx/pptx-manifest.ts +19 -0
  104. package/src/adapters/pptx/pptx-model.test.ts +219 -0
  105. package/src/adapters/pptx/pptx-model.ts +248 -0
  106. package/src/adapters/text/text-adapter.test.tsx +125 -0
  107. package/src/adapters/text/text-adapter.tsx +117 -0
  108. package/src/adapters/text/text-manifest.ts +19 -0
  109. package/src/adapters/xlsx/xlsx-adapter.test.tsx +159 -0
  110. package/src/adapters/xlsx/xlsx-adapter.tsx +250 -0
  111. package/src/adapters/xlsx/xlsx-manifest.ts +26 -0
  112. package/src/components/grid-text.test.ts +68 -0
  113. package/src/components/grid-text.ts +77 -0
  114. package/src/components/marked-text.tsx +36 -0
  115. package/src/components/sheet-table.tsx +142 -0
  116. package/src/core/errors.ts +120 -0
  117. package/src/core/highlight-marks.test.ts +95 -0
  118. package/src/core/highlight-marks.ts +95 -0
  119. package/src/core/highlight-resolve.test.ts +208 -0
  120. package/src/core/highlight-resolve.ts +191 -0
  121. package/src/core/highlight.ts +125 -0
  122. package/src/core/registry.test.ts +172 -0
  123. package/src/core/registry.ts +188 -0
  124. package/src/core/scroll-host.ts +42 -0
  125. package/src/core/text-index.test.ts +95 -0
  126. package/src/core/text-index.ts +159 -0
  127. package/src/core/types.ts +285 -0
  128. package/src/core/use-highlight-scroll.ts +59 -0
  129. package/src/core/use-page-control.ts +47 -0
  130. package/src/core/use-paged-scroll.ts +194 -0
  131. package/src/core/use-viewport-size.ts +54 -0
  132. package/src/core/zoom.ts +56 -0
  133. package/src/file-viewer/file-viewer-context.tsx +239 -0
  134. package/src/file-viewer/file-viewer-find.tsx +204 -0
  135. package/src/file-viewer/file-viewer-pager.tsx +120 -0
  136. package/src/file-viewer/file-viewer-zoom.tsx +166 -0
  137. package/src/file-viewer/file-viewer.stories.tsx +947 -0
  138. package/src/file-viewer/file-viewer.test.tsx +947 -0
  139. package/src/file-viewer/file-viewer.tsx +1143 -0
  140. package/src/index.ts +157 -0
package/src/index.ts ADDED
@@ -0,0 +1,157 @@
1
+ /**
2
+ * @elabs-ai/components-viewer — render any file in the browser.
3
+ *
4
+ * A Layer-2 leaf (`tokens → ui → viewer`, ADR 0024). Formats are adapters in a
5
+ * registry: an eager manifest plus a lazy loader, so an app that never opens a
6
+ * spreadsheet never downloads a spreadsheet parser. Every parser is an OPTIONAL
7
+ * peer — install only what you open.
8
+ *
9
+ * The input model (`FileSource`, `resolveFileKind`, `fileIconFor`) lives in
10
+ * `@elabs-ai/components-ui`, so `-ai`, `-viewer` and your own code
11
+ * all speak it.
12
+ */
13
+
14
+ // Components
15
+ export {
16
+ FileViewer,
17
+ FileViewerContent,
18
+ FileViewerEmpty,
19
+ FileViewerError,
20
+ FileViewerFrame,
21
+ FileViewerHighlightStatus,
22
+ FileViewerProvider,
23
+ FileViewerSkeleton,
24
+ FileViewerToolbar,
25
+ type FileViewerContentProps,
26
+ type FileViewerFrameProps,
27
+ type FileViewerHighlightStatusProps,
28
+ type FileViewerProps,
29
+ type FileViewerProviderProps,
30
+ type FileViewerToolbarProps,
31
+ } from "./file-viewer/file-viewer";
32
+ export {
33
+ FileViewerFind,
34
+ isFindShortcut,
35
+ type FileViewerFindProps,
36
+ } from "./file-viewer/file-viewer-find";
37
+ // Page, scale and rotation chrome (ADR 0026). Parts, not adapter internals: an
38
+ // app can put any of them in its own header and drive the same provider state.
39
+ export { FileViewerPager, type FileViewerPagerProps } from "./file-viewer/file-viewer-pager";
40
+ export {
41
+ FileViewerRotate,
42
+ FileViewerZoom,
43
+ type FileViewerRotateProps,
44
+ type FileViewerZoomProps,
45
+ } from "./file-viewer/file-viewer-zoom";
46
+ export {
47
+ useFileViewer,
48
+ type FileViewerActions,
49
+ type FileViewerContextValue,
50
+ type FileViewerFindState,
51
+ type FileViewerLoadState,
52
+ type FileViewerState,
53
+ type FileViewerStatus,
54
+ type FileViewerViewState,
55
+ } from "./file-viewer/file-viewer-context";
56
+ // The zoom ladder is shared: the provider steps along it and the shell's control
57
+ // lists it, so a consumer building its own zoom UI reads the same one.
58
+ export { canStepZoom, DEFAULT_ZOOM, isZoomFit, stepZoom, VIEWER_ZOOM_STEPS } from "./core/zoom";
59
+
60
+ // Pointing the viewer at part of a document (ADR 0025). The ADDRESS vocabulary
61
+ // itself is in `@elabs-ai/components-ui` — a citation's producer and
62
+ // this consumer are sibling packages that may not import each other.
63
+ export {
64
+ FIND_MATCH_LIMIT,
65
+ findMatchId,
66
+ isFindMatchId,
67
+ type DocumentHighlight,
68
+ type HighlightMissReason,
69
+ type HighlightSource,
70
+ type HighlightStatus,
71
+ type HighlightSupport,
72
+ type ResolvedHighlight,
73
+ } from "./core/highlight";
74
+ export {
75
+ locateQuote,
76
+ resolveHighlights,
77
+ type HighlightResolveContext,
78
+ } from "./core/highlight-resolve";
79
+ // The PAINT half. Exported for the same reason the index half is: the registry
80
+ // is a documented extension point, so a third-party adapter has to be able to
81
+ // mark a passage the way the shipped ones do. Re-deriving it by hand means
82
+ // re-deriving the merge-vs-`activeIndex` correspondence and the
83
+ // `data-slot`/`data-active` scroll contract, and getting either wrong is silent.
84
+ export { localizeRanges, toMarkRanges, type MarkRanges } from "./core/highlight-marks";
85
+ export {
86
+ useScrollActiveHighlightIntoView,
87
+ ACTIVE_HIGHLIGHT_SELECTOR,
88
+ } from "./core/use-highlight-scroll";
89
+ // `MarkedText` itself stays internal on purpose: it renders a FRAGMENT, so it
90
+ // has no element to carry a `data-slot`, and giving it a wrapper would put a
91
+ // span around every unmarked run of every document to no one's benefit. It is
92
+ // four lines of glue over the two exports above — a third-party adapter composes
93
+ // `localizeRanges` with `MatchHighlight` from `@elabs-ai/components-ui`
94
+ // the same way.
95
+ export {
96
+ chunkOffset,
97
+ createTextIndexBuilder,
98
+ spanAt,
99
+ spansForRange,
100
+ type SpanOverlap,
101
+ type TextIndex,
102
+ type TextIndexBuilder,
103
+ type TextIndexBuilderOptions,
104
+ type TextSpan,
105
+ } from "./core/text-index";
106
+
107
+ // Registry — the extension point
108
+ export { createRegistry, scoreManifest, type ViewerRegistry } from "./core/registry";
109
+ export { createDefaultRegistry } from "./adapters";
110
+ export {
111
+ codeManifest,
112
+ csvManifest,
113
+ docxManifest,
114
+ imageManifest,
115
+ jsonManifest,
116
+ markdownManifest,
117
+ mediaManifest,
118
+ pdfManifest,
119
+ pptxManifest,
120
+ textManifest,
121
+ xlsxManifest,
122
+ } from "./adapters";
123
+
124
+ // PDF engine wiring. Exported so an app behind a strict CSP — or a bundler that
125
+ // cannot see through `new URL(…, import.meta.url)` — can serve the pdf.js worker
126
+ // and font assets itself. Types only; the engine stays behind a dynamic import.
127
+ export {
128
+ configurePdfEngine,
129
+ getPdfEngineConfig,
130
+ type PdfEngineConfig,
131
+ } from "./adapters/pdf/pdf-engine";
132
+ export {
133
+ PROTOCOL_VERSION,
134
+ type AdapterCapabilities,
135
+ type AdapterDocument,
136
+ type AdapterLoadContext,
137
+ type AdapterLoader,
138
+ type AdapterManifest,
139
+ type AdapterModule,
140
+ type AdapterRendererProps,
141
+ type DocumentRotation,
142
+ type FileAdapter,
143
+ type ZoomFit,
144
+ type ZoomLevel,
145
+ } from "./core/types";
146
+
147
+ // Failures — the `code` is the contract, not the message
148
+ export {
149
+ ViewerError,
150
+ isAbort,
151
+ isModuleNotFound,
152
+ isViewerError,
153
+ parserMissingError,
154
+ toViewerError,
155
+ type ViewerErrorCode,
156
+ type ViewerErrorOptions,
157
+ } from "./core/errors";