@lamberl-lee/file-preview 0.2.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 (263) hide show
  1. package/COPYING +674 -0
  2. package/LICENSE +165 -0
  3. package/README.md +165 -0
  4. package/dist/AudioPreview.d.ts +9 -0
  5. package/dist/AudioPreview.js +29 -0
  6. package/dist/AudioPreview.js.map +1 -0
  7. package/dist/CodePreview.d.ts +10 -0
  8. package/dist/CodePreview.js +121 -0
  9. package/dist/CodePreview.js.map +1 -0
  10. package/dist/CsvPreview.d.ts +9 -0
  11. package/dist/CsvPreview.js +117 -0
  12. package/dist/CsvPreview.js.map +1 -0
  13. package/dist/DocxPreview.d.ts +11 -0
  14. package/dist/DocxPreview.js +89 -0
  15. package/dist/DocxPreview.js.map +1 -0
  16. package/dist/EpubPreview.d.ts +9 -0
  17. package/dist/EpubPreview.js +693 -0
  18. package/dist/EpubPreview.js.map +1 -0
  19. package/dist/HtmlPreview.d.ts +9 -0
  20. package/dist/HtmlPreview.js +60 -0
  21. package/dist/HtmlPreview.js.map +1 -0
  22. package/dist/ImagePreview.d.ts +9 -0
  23. package/dist/ImagePreview.js +44 -0
  24. package/dist/ImagePreview.js.map +1 -0
  25. package/dist/LargeFileGate.d.ts +12 -0
  26. package/dist/LargeFileGate.js +88 -0
  27. package/dist/LargeFileGate.js.map +1 -0
  28. package/dist/MarkdownPreview.d.ts +8 -0
  29. package/dist/MarkdownPreview.js +140 -0
  30. package/dist/MarkdownPreview.js.map +1 -0
  31. package/dist/PdfPreview.d.ts +11 -0
  32. package/dist/PdfPreview.js +206 -0
  33. package/dist/PdfPreview.js.map +1 -0
  34. package/dist/PlainTextLargePreview.d.ts +9 -0
  35. package/dist/PlainTextLargePreview.js +62 -0
  36. package/dist/PlainTextLargePreview.js.map +1 -0
  37. package/dist/PluginPreviewRenderer.d.ts +13 -0
  38. package/dist/PluginPreviewRenderer.js +89 -0
  39. package/dist/PluginPreviewRenderer.js.map +1 -0
  40. package/dist/PptxPreview.d.ts +16 -0
  41. package/dist/PptxPreview.js +376 -0
  42. package/dist/PptxPreview.js.map +1 -0
  43. package/dist/PreviewErrorBoundary.d.ts +29 -0
  44. package/dist/PreviewErrorBoundary.js +53 -0
  45. package/dist/PreviewErrorBoundary.js.map +1 -0
  46. package/dist/PreviewFallback.d.ts +18 -0
  47. package/dist/PreviewFallback.js +143 -0
  48. package/dist/PreviewFallback.js.map +1 -0
  49. package/dist/PreviewLoading.d.ts +8 -0
  50. package/dist/PreviewLoading.js +14 -0
  51. package/dist/PreviewLoading.js.map +1 -0
  52. package/dist/RtfPreview.d.ts +10 -0
  53. package/dist/RtfPreview.js +240 -0
  54. package/dist/RtfPreview.js.map +1 -0
  55. package/dist/ShikiSourceView.d.ts +11 -0
  56. package/dist/ShikiSourceView.js +112 -0
  57. package/dist/ShikiSourceView.js.map +1 -0
  58. package/dist/SvgPreview.d.ts +9 -0
  59. package/dist/SvgPreview.js +89 -0
  60. package/dist/SvgPreview.js.map +1 -0
  61. package/dist/TextPreview.d.ts +9 -0
  62. package/dist/TextPreview.js +9 -0
  63. package/dist/TextPreview.js.map +1 -0
  64. package/dist/VideoPreview.d.ts +9 -0
  65. package/dist/VideoPreview.js +18 -0
  66. package/dist/VideoPreview.js.map +1 -0
  67. package/dist/XlsxPreview.d.ts +12 -0
  68. package/dist/XlsxPreview.js +856 -0
  69. package/dist/XlsxPreview.js.map +1 -0
  70. package/dist/ZipPreview.d.ts +9 -0
  71. package/dist/ZipPreview.js +153 -0
  72. package/dist/ZipPreview.js.map +1 -0
  73. package/dist/core/binary.d.ts +10 -0
  74. package/dist/core/binary.js +27 -0
  75. package/dist/core/binary.js.map +1 -0
  76. package/dist/core/config.d.ts +17 -0
  77. package/dist/core/config.js +19 -0
  78. package/dist/core/config.js.map +1 -0
  79. package/dist/core/download.d.ts +5 -0
  80. package/dist/core/download.js +20 -0
  81. package/dist/core/download.js.map +1 -0
  82. package/dist/core/i18n.d.ts +101 -0
  83. package/dist/core/i18n.js +200 -0
  84. package/dist/core/i18n.js.map +1 -0
  85. package/dist/core/plugin.d.ts +38 -0
  86. package/dist/core/plugin.js +46 -0
  87. package/dist/core/plugin.js.map +1 -0
  88. package/dist/core/registry.d.ts +13 -0
  89. package/dist/core/registry.js +33 -0
  90. package/dist/core/registry.js.map +1 -0
  91. package/dist/core/source.d.ts +14 -0
  92. package/dist/core/source.js +131 -0
  93. package/dist/core/source.js.map +1 -0
  94. package/dist/core/types.d.ts +88 -0
  95. package/dist/core/types.js +27 -0
  96. package/dist/core/types.js.map +1 -0
  97. package/dist/hooks/useObjectUrlFromSource.d.ts +9 -0
  98. package/dist/hooks/useObjectUrlFromSource.js +50 -0
  99. package/dist/hooks/useObjectUrlFromSource.js.map +1 -0
  100. package/dist/hooks/useSourceBase64.d.ts +10 -0
  101. package/dist/hooks/useSourceBase64.js +32 -0
  102. package/dist/hooks/useSourceBase64.js.map +1 -0
  103. package/dist/hooks/useSourceText.d.ts +10 -0
  104. package/dist/hooks/useSourceText.js +32 -0
  105. package/dist/hooks/useSourceText.js.map +1 -0
  106. package/dist/icons.d.ts +44 -0
  107. package/dist/icons.js +248 -0
  108. package/dist/icons.js.map +1 -0
  109. package/dist/index.d.ts +36 -0
  110. package/dist/index.js +147 -0
  111. package/dist/index.js.map +1 -0
  112. package/dist/limits.d.ts +26 -0
  113. package/dist/limits.js +45 -0
  114. package/dist/limits.js.map +1 -0
  115. package/dist/performance-limits.d.ts +27 -0
  116. package/dist/performance-limits.js +54 -0
  117. package/dist/performance-limits.js.map +1 -0
  118. package/dist/plugins/audio-plugin.d.ts +7 -0
  119. package/dist/plugins/audio-plugin.js +11 -0
  120. package/dist/plugins/audio-plugin.js.map +1 -0
  121. package/dist/plugins/builtin-plugins.d.ts +9 -0
  122. package/dist/plugins/builtin-plugins.js +43 -0
  123. package/dist/plugins/builtin-plugins.js.map +1 -0
  124. package/dist/plugins/csv-plugin.d.ts +7 -0
  125. package/dist/plugins/csv-plugin.js +11 -0
  126. package/dist/plugins/csv-plugin.js.map +1 -0
  127. package/dist/plugins/docx-plugin.d.ts +7 -0
  128. package/dist/plugins/docx-plugin.js +15 -0
  129. package/dist/plugins/docx-plugin.js.map +1 -0
  130. package/dist/plugins/epub-plugin.d.ts +7 -0
  131. package/dist/plugins/epub-plugin.js +15 -0
  132. package/dist/plugins/epub-plugin.js.map +1 -0
  133. package/dist/plugins/html-plugin.d.ts +7 -0
  134. package/dist/plugins/html-plugin.js +11 -0
  135. package/dist/plugins/html-plugin.js.map +1 -0
  136. package/dist/plugins/image-plugin.d.ts +7 -0
  137. package/dist/plugins/image-plugin.js +11 -0
  138. package/dist/plugins/image-plugin.js.map +1 -0
  139. package/dist/plugins/markdown-plugin.d.ts +7 -0
  140. package/dist/plugins/markdown-plugin.js +11 -0
  141. package/dist/plugins/markdown-plugin.js.map +1 -0
  142. package/dist/plugins/pdf-plugin.d.ts +7 -0
  143. package/dist/plugins/pdf-plugin.js +15 -0
  144. package/dist/plugins/pdf-plugin.js.map +1 -0
  145. package/dist/plugins/pptx-plugin.d.ts +7 -0
  146. package/dist/plugins/pptx-plugin.js +15 -0
  147. package/dist/plugins/pptx-plugin.js.map +1 -0
  148. package/dist/plugins/rtf-plugin.d.ts +7 -0
  149. package/dist/plugins/rtf-plugin.js +15 -0
  150. package/dist/plugins/rtf-plugin.js.map +1 -0
  151. package/dist/plugins/source-code-plugin.d.ts +7 -0
  152. package/dist/plugins/source-code-plugin.js +11 -0
  153. package/dist/plugins/source-code-plugin.js.map +1 -0
  154. package/dist/plugins/svg-plugin.d.ts +7 -0
  155. package/dist/plugins/svg-plugin.js +11 -0
  156. package/dist/plugins/svg-plugin.js.map +1 -0
  157. package/dist/plugins/text-plugin.d.ts +7 -0
  158. package/dist/plugins/text-plugin.js +11 -0
  159. package/dist/plugins/text-plugin.js.map +1 -0
  160. package/dist/plugins/video-plugin.d.ts +7 -0
  161. package/dist/plugins/video-plugin.js +11 -0
  162. package/dist/plugins/video-plugin.js.map +1 -0
  163. package/dist/plugins/xlsx-plugin.d.ts +7 -0
  164. package/dist/plugins/xlsx-plugin.js +15 -0
  165. package/dist/plugins/xlsx-plugin.js.map +1 -0
  166. package/dist/plugins/zip-plugin.d.ts +7 -0
  167. package/dist/plugins/zip-plugin.js +15 -0
  168. package/dist/plugins/zip-plugin.js.map +1 -0
  169. package/dist/preview-adapters/AudioPreviewAdapter.d.ts +8 -0
  170. package/dist/preview-adapters/AudioPreviewAdapter.js +31 -0
  171. package/dist/preview-adapters/AudioPreviewAdapter.js.map +1 -0
  172. package/dist/preview-adapters/CsvPreviewAdapter.d.ts +8 -0
  173. package/dist/preview-adapters/CsvPreviewAdapter.js +28 -0
  174. package/dist/preview-adapters/CsvPreviewAdapter.js.map +1 -0
  175. package/dist/preview-adapters/DocxPreviewAdapter.d.ts +8 -0
  176. package/dist/preview-adapters/DocxPreviewAdapter.js +16 -0
  177. package/dist/preview-adapters/DocxPreviewAdapter.js.map +1 -0
  178. package/dist/preview-adapters/EpubPreviewAdapter.d.ts +8 -0
  179. package/dist/preview-adapters/EpubPreviewAdapter.js +28 -0
  180. package/dist/preview-adapters/EpubPreviewAdapter.js.map +1 -0
  181. package/dist/preview-adapters/HtmlPreviewAdapter.d.ts +8 -0
  182. package/dist/preview-adapters/HtmlPreviewAdapter.js +28 -0
  183. package/dist/preview-adapters/HtmlPreviewAdapter.js.map +1 -0
  184. package/dist/preview-adapters/ImagePreviewAdapter.d.ts +8 -0
  185. package/dist/preview-adapters/ImagePreviewAdapter.js +31 -0
  186. package/dist/preview-adapters/ImagePreviewAdapter.js.map +1 -0
  187. package/dist/preview-adapters/MarkdownPreviewAdapter.d.ts +8 -0
  188. package/dist/preview-adapters/MarkdownPreviewAdapter.js +28 -0
  189. package/dist/preview-adapters/MarkdownPreviewAdapter.js.map +1 -0
  190. package/dist/preview-adapters/PdfPreviewAdapter.d.ts +8 -0
  191. package/dist/preview-adapters/PdfPreviewAdapter.js +16 -0
  192. package/dist/preview-adapters/PdfPreviewAdapter.js.map +1 -0
  193. package/dist/preview-adapters/PptxPreviewAdapter.d.ts +8 -0
  194. package/dist/preview-adapters/PptxPreviewAdapter.js +16 -0
  195. package/dist/preview-adapters/PptxPreviewAdapter.js.map +1 -0
  196. package/dist/preview-adapters/RtfPreviewAdapter.d.ts +8 -0
  197. package/dist/preview-adapters/RtfPreviewAdapter.js +54 -0
  198. package/dist/preview-adapters/RtfPreviewAdapter.js.map +1 -0
  199. package/dist/preview-adapters/SourceCodePreviewAdapter.d.ts +8 -0
  200. package/dist/preview-adapters/SourceCodePreviewAdapter.js +35 -0
  201. package/dist/preview-adapters/SourceCodePreviewAdapter.js.map +1 -0
  202. package/dist/preview-adapters/SvgPreviewAdapter.d.ts +8 -0
  203. package/dist/preview-adapters/SvgPreviewAdapter.js +28 -0
  204. package/dist/preview-adapters/SvgPreviewAdapter.js.map +1 -0
  205. package/dist/preview-adapters/TextPreviewAdapter.d.ts +8 -0
  206. package/dist/preview-adapters/TextPreviewAdapter.js +28 -0
  207. package/dist/preview-adapters/TextPreviewAdapter.js.map +1 -0
  208. package/dist/preview-adapters/UnsupportedPluginPreview.d.ts +11 -0
  209. package/dist/preview-adapters/UnsupportedPluginPreview.js +34 -0
  210. package/dist/preview-adapters/UnsupportedPluginPreview.js.map +1 -0
  211. package/dist/preview-adapters/VideoPreviewAdapter.d.ts +8 -0
  212. package/dist/preview-adapters/VideoPreviewAdapter.js +31 -0
  213. package/dist/preview-adapters/VideoPreviewAdapter.js.map +1 -0
  214. package/dist/preview-adapters/XlsxPreviewAdapter.d.ts +8 -0
  215. package/dist/preview-adapters/XlsxPreviewAdapter.js +17 -0
  216. package/dist/preview-adapters/XlsxPreviewAdapter.js.map +1 -0
  217. package/dist/preview-adapters/ZipPreviewAdapter.d.ts +8 -0
  218. package/dist/preview-adapters/ZipPreviewAdapter.js +28 -0
  219. package/dist/preview-adapters/ZipPreviewAdapter.js.map +1 -0
  220. package/dist/remote-url.d.ts +20 -0
  221. package/dist/remote-url.js +478 -0
  222. package/dist/remote-url.js.map +1 -0
  223. package/dist/rtf/load-rtfjs.d.ts +42 -0
  224. package/dist/rtf/load-rtfjs.js +71 -0
  225. package/dist/rtf/load-rtfjs.js.map +1 -0
  226. package/dist/rtf/normalize-codepage.d.ts +33 -0
  227. package/dist/rtf/normalize-codepage.js +88 -0
  228. package/dist/rtf/normalize-codepage.js.map +1 -0
  229. package/dist/shiki.d.ts +35 -0
  230. package/dist/shiki.js +128 -0
  231. package/dist/shiki.js.map +1 -0
  232. package/dist/styles/AudioPreview.css +35 -0
  233. package/dist/styles/CsvPreview.css +106 -0
  234. package/dist/styles/DocxPreview.css +93 -0
  235. package/dist/styles/EpubPreview.css +509 -0
  236. package/dist/styles/HtmlPreview.css +15 -0
  237. package/dist/styles/ImagePreview.css +45 -0
  238. package/dist/styles/LargeFileGate.css +55 -0
  239. package/dist/styles/MarkdownPreview.css +291 -0
  240. package/dist/styles/PdfPreview.css +68 -0
  241. package/dist/styles/PlainTextLargePreview.css +85 -0
  242. package/dist/styles/PluginDebugBar.css +30 -0
  243. package/dist/styles/PptxPreview.css +207 -0
  244. package/dist/styles/PreviewFallback.css +88 -0
  245. package/dist/styles/PreviewLoading.css +13 -0
  246. package/dist/styles/RtfPreview.css +99 -0
  247. package/dist/styles/ShikiSourceView.css +159 -0
  248. package/dist/styles/SvgPreview.css +99 -0
  249. package/dist/styles/VideoPreview.css +19 -0
  250. package/dist/styles/ViewModeBar.css +38 -0
  251. package/dist/styles/XlsxPreview.css +361 -0
  252. package/dist/styles/ZipPreview.css +86 -0
  253. package/dist/styles/base.css +238 -0
  254. package/dist/styles/index.css +39 -0
  255. package/dist/support-status.d.ts +19 -0
  256. package/dist/support-status.js +174 -0
  257. package/dist/support-status.js.map +1 -0
  258. package/dist/utils.d.ts +17 -0
  259. package/dist/utils.js +205 -0
  260. package/dist/utils.js.map +1 -0
  261. package/package.json +125 -0
  262. package/scripts/copy-pdf-worker.mjs +31 -0
  263. package/scripts/copy-rtfjs-bundles.mjs +49 -0
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # @lamberl-lee/file-preview
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@lamberl-lee/file-preview.svg?style=flat-square)](https://www.npmjs.com/package/@lamberl-lee/file-preview)
4
+ [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@lamberl-lee/file-preview?style=flat-square&label=gzip)](https://bundlephobia.com/package/@lamberl-lee/file-preview)
5
+ [![license](https://img.shields.io/npm/l/@lamberl-lee/file-preview?style=flat-square)](./LICENSE)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/CoderLambert/filevista/ci.yml?branch=main&style=flat-square&label=CI)](https://github.com/CoderLambert/filevista/actions/workflows/ci.yml)
7
+
8
+ > Browser-side file preview toolkit for React — 20+ formats with zero server processing.
9
+
10
+ Render PDF, DOCX, PPTX, XLSX, EPUB, RTF, Markdown, code, images, video, audio, ZIP, CSV, SVG, HTML, and plain text — all in the browser. Files never leave the user's device.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @lamberl-lee/file-preview
16
+ # or pnpm add / yarn add
17
+ ```
18
+
19
+ The base install only ships what every consumer needs: Markdown, code highlighting (Shiki), HTML sanitization (DOMPurify), and the always-included image / video / audio / SVG / CSV / plain-text / JSON renderers.
20
+
21
+ To preview the heavier formats, install **only the optional peer dependencies for the formats you actually use**:
22
+
23
+ | Format | Add this peer dep | Approx size (gzipped) |
24
+ | --- | --- | --- |
25
+ | PDF | `pdfjs-dist` (^4.4.0) | ~280 KB worker, lazy-loaded |
26
+ | DOCX | `docx-preview` (^0.3.7) | ~45 KB |
27
+ | XLSX | `exceljs` (^4.4.0) | ~250 KB |
28
+ | PPTX | `pptx-preview` (^1.0.7) | ~80 KB |
29
+ | RTF | `rtf.js` (^3.0.9) | ~120 KB worker, lazy-loaded |
30
+ | ZIP / EPUB | `jszip` (^3.10.1) | ~30 KB |
31
+
32
+ ```bash
33
+ # Example: only PDF + Markdown previews
34
+ pnpm add @lamberl-lee/file-preview pdfjs-dist
35
+ ```
36
+
37
+ If a user uploads a format whose peer dep is missing, the preview falls back to a clear "install `<package>`" message instead of a cryptic bundler error. So you can ship safely with just the formats you need.
38
+
39
+ `react` and `react-dom` (>=18.2) are also peer dependencies.
40
+
41
+ ## Quick start
42
+
43
+ ```tsx
44
+ import {
45
+ PluginPreviewRenderer,
46
+ detectFileType,
47
+ setAssetBasePath,
48
+ type FileInfo,
49
+ } from "@lamberl-lee/file-preview";
50
+ import "@lamberl-lee/file-preview/styles/index.css";
51
+
52
+ // Tell the library where PDF.js worker / RTF.js bundles are served from.
53
+ // (See "Static assets" below.) Empty string means same origin / "/".
54
+ setAssetBasePath("");
55
+
56
+ function Demo({ file }: { file: File }) {
57
+ const info: FileInfo = {
58
+ id: crypto.randomUUID(),
59
+ name: file.name,
60
+ size: file.size,
61
+ type: file.type,
62
+ fileType: detectFileType(file.name, file.type),
63
+ source: { kind: "file", file },
64
+ };
65
+
66
+ return <PluginPreviewRenderer file={info} />;
67
+ }
68
+ ```
69
+
70
+ ### Remote URL
71
+
72
+ ```tsx
73
+ import { processRemoteUrl } from "@lamberl-lee/file-preview";
74
+
75
+ const info = await processRemoteUrl("https://example.com/foo.pdf", {
76
+ onProgress: (p) => console.log(p),
77
+ });
78
+ ```
79
+
80
+ ## Static assets (PDF.js worker, RTF.js bundles)
81
+
82
+ PDF and RTF previews need extra runtime assets that must be served from a static path. The package ships two helper scripts:
83
+
84
+ ```jsonc
85
+ // package.json
86
+ {
87
+ "scripts": {
88
+ "postinstall": "node node_modules/@lamberl-lee/file-preview/scripts/copy-pdf-worker.mjs && node node_modules/@lamberl-lee/file-preview/scripts/copy-rtfjs-bundles.mjs"
89
+ }
90
+ }
91
+ ```
92
+
93
+ These copy:
94
+
95
+ - `pdfjs-dist/build/pdf.worker.min.mjs` → `public/vendor/pdfjs/pdf.worker.min.mjs`
96
+ - `rtf.js/dist/{WMFJS,EMFJS,RTFJS}.bundle.min.js` → `public/vendor/rtfjs/`
97
+
98
+ Skip the `copy-pdf-worker.mjs` line if you don't install `pdfjs-dist`, and the `copy-rtfjs-bundles.mjs` line if you don't install `rtf.js` — both scripts are no-ops when the source package is missing.
99
+
100
+ Then call `setAssetBasePath()` once at app startup to match the public path you serve them from (e.g. `""` for root, `"/static"` for a CDN prefix, or `"/myapp"` for a Next.js `basePath`).
101
+
102
+ ## Theming
103
+
104
+ Override CSS variables on the document root:
105
+
106
+ ```css
107
+ [data-fv-theme="dark"] {
108
+ --fv-bg: #0b0b0c;
109
+ --fv-fg: #e7e7e7;
110
+ --fv-border: #2a2a2c;
111
+ --fv-primary: #4f8cff;
112
+ /* … */
113
+ }
114
+ ```
115
+
116
+ ## i18n
117
+
118
+ ```tsx
119
+ import { LocaleProvider, enUS } from "@lamberl-lee/file-preview";
120
+
121
+ <LocaleProvider value={enUS}>
122
+ <PluginPreviewRenderer file={info} />
123
+ </LocaleProvider>
124
+ ```
125
+
126
+ Built-in locales: `zhCN` (default), `enUS`. Pass a fully custom `LocaleMessages` object to localize.
127
+
128
+ ## Custom plugin registry
129
+
130
+ Drop or replace formats:
131
+
132
+ ```tsx
133
+ import {
134
+ createPreviewPluginRegistry,
135
+ pdfPlugin,
136
+ markdownPlugin,
137
+ imagePlugin,
138
+ } from "@lamberl-lee/file-preview";
139
+
140
+ const registry = createPreviewPluginRegistry([pdfPlugin, markdownPlugin, imagePlugin]);
141
+
142
+ <PluginPreviewRenderer file={info} registry={registry} />;
143
+ ```
144
+
145
+ A registry built from a subset of plugins also means the bundler will tree-shake away the formats you don't include.
146
+
147
+ ## Supported formats
148
+
149
+ PDF · DOCX · PPTX · XLSX · EPUB · RTF · Markdown · HTML · code (Shiki-highlighted) · plain text · CSV · JSON · SVG · images · video · audio · ZIP listing.
150
+
151
+ ## Browser support
152
+
153
+ | Browser | Minimum |
154
+ | --- | --- |
155
+ | Chrome / Edge | 90+ |
156
+ | Firefox | 88+ |
157
+ | Safari | 14+ |
158
+
159
+ The library relies on browser-native `File`/`Blob`/`ArrayBuffer`, `fetch`, `URL.createObjectURL`, and dynamic `import()`. PDF preview additionally uses a Web Worker (PDF.js). No polyfills are shipped — if you need to support older browsers, add the relevant polyfills yourself.
160
+
161
+ ## License
162
+
163
+ LGPL-3.0-or-later — see `LICENSE` (LGPL-3.0) and `COPYING` (GPL-3.0, which LGPL-3.0 extends).
164
+
165
+ You can use this package in proprietary applications without making your application LGPL — that's exactly what the L (Lesser) in LGPL is for. The obligation only applies if you ship a modified version of this library itself.
@@ -0,0 +1,9 @@
1
+ import * as react from 'react';
2
+
3
+ interface AudioPreviewProps {
4
+ url: string;
5
+ fileName: string;
6
+ }
7
+ declare function AudioPreview({ url, fileName }: AudioPreviewProps): react.JSX.Element;
8
+
9
+ export { AudioPreview };
@@ -0,0 +1,29 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import "./styles/AudioPreview.css";
3
+ function AudioPreview({ url, fileName }) {
4
+ return /* @__PURE__ */ jsxs("div", { className: "fv-audio", children: [
5
+ /* @__PURE__ */ jsx("div", { className: "fv-audio__icon-wrap", children: /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "40", height: "40", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
6
+ /* @__PURE__ */ jsx("path", { d: "M9 18V5l12-2v13" }),
7
+ /* @__PURE__ */ jsx("circle", { cx: "6", cy: "18", r: "3" }),
8
+ /* @__PURE__ */ jsx("circle", { cx: "18", cy: "16", r: "3" })
9
+ ] }) }),
10
+ /* @__PURE__ */ jsxs("div", { className: "fv-audio__info", children: [
11
+ /* @__PURE__ */ jsx("p", { className: "fv-audio__name", children: fileName }),
12
+ /* @__PURE__ */ jsx("p", { className: "fv-audio__label", children: "Audio file" })
13
+ ] }),
14
+ /* @__PURE__ */ jsx(
15
+ "audio",
16
+ {
17
+ src: url,
18
+ controls: true,
19
+ className: "fv-audio__player",
20
+ "aria-label": fileName,
21
+ children: "Your browser does not support the audio tag."
22
+ }
23
+ )
24
+ ] });
25
+ }
26
+ export {
27
+ AudioPreview
28
+ };
29
+ //# sourceMappingURL=AudioPreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/AudioPreview.tsx"],"sourcesContent":["import \"./styles/AudioPreview.css\";\n\ninterface AudioPreviewProps {\n url: string;\n fileName: string;\n}\n\nexport function AudioPreview({ url, fileName }: AudioPreviewProps) {\n return (\n <div className=\"fv-audio\">\n <div className=\"fv-audio__icon-wrap\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"40\" height=\"40\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <path d=\"M9 18V5l12-2v13\" />\n <circle cx=\"6\" cy=\"18\" r=\"3\" />\n <circle cx=\"18\" cy=\"16\" r=\"3\" />\n </svg>\n </div>\n <div className=\"fv-audio__info\">\n <p className=\"fv-audio__name\">{fileName}</p>\n <p className=\"fv-audio__label\">Audio file</p>\n </div>\n <audio\n src={url}\n controls\n className=\"fv-audio__player\"\n aria-label={fileName}\n >\n Your browser does not support the audio tag.\n </audio>\n </div>\n );\n}\n"],"mappings":"AAWQ,SACE,KADF;AAXR,OAAO;AAOA,SAAS,aAAa,EAAE,KAAK,SAAS,GAAsB;AACjE,SACE,qBAAC,SAAI,WAAU,YACb;AAAA,wBAAC,SAAI,WAAU,uBACb,+BAAC,SAAI,OAAM,8BAA6B,OAAM,MAAK,QAAO,MAAK,SAAQ,aAAY,MAAK,QAAO,QAAO,gBAAe,aAAY,OAAM,eAAc,SAAQ,gBAAe,SAC1K;AAAA,0BAAC,UAAK,GAAE,mBAAkB;AAAA,MAC1B,oBAAC,YAAO,IAAG,KAAI,IAAG,MAAK,GAAE,KAAI;AAAA,MAC7B,oBAAC,YAAO,IAAG,MAAK,IAAG,MAAK,GAAE,KAAI;AAAA,OAChC,GACF;AAAA,IACA,qBAAC,SAAI,WAAU,kBACb;AAAA,0BAAC,OAAE,WAAU,kBAAkB,oBAAS;AAAA,MACxC,oBAAC,OAAE,WAAU,mBAAkB,wBAAU;AAAA,OAC3C;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,UAAQ;AAAA,QACR,WAAU;AAAA,QACV,cAAY;AAAA,QACb;AAAA;AAAA,IAED;AAAA,KACF;AAEJ;","names":[]}
@@ -0,0 +1,10 @@
1
+ import * as react from 'react';
2
+
3
+ interface CodePreviewProps {
4
+ content: string;
5
+ fileName: string;
6
+ isJson?: boolean;
7
+ }
8
+ declare function CodePreview({ content, fileName, isJson }: CodePreviewProps): react.JSX.Element;
9
+
10
+ export { CodePreview };
@@ -0,0 +1,121 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useMemo } from "react";
3
+ import { CopyIcon, CheckIcon, WrapTextIcon } from "./icons";
4
+ import { highlightCode as shikiHighlight, getShikiLanguage } from "./shiki";
5
+ import { shouldHighlight } from "./limits";
6
+ import { PlainTextLargePreview } from "./PlainTextLargePreview";
7
+ import { useLocale } from "./core/i18n";
8
+ import "./styles/ShikiSourceView.css";
9
+ function CodePreview({ content, fileName, isJson }) {
10
+ const [html, setHtml] = useState("");
11
+ const [loading, setLoading] = useState(true);
12
+ const [error, setError] = useState(null);
13
+ const [copied, setCopied] = useState(false);
14
+ const [wordWrap, setWordWrap] = useState(true);
15
+ const t = useLocale();
16
+ const language = useMemo(
17
+ () => isJson ? "json" : getShikiLanguage(fileName),
18
+ [isJson, fileName]
19
+ );
20
+ const displayContent = useMemo(() => {
21
+ if (isJson) {
22
+ try {
23
+ return JSON.stringify(JSON.parse(content), null, 2);
24
+ } catch {
25
+ return content;
26
+ }
27
+ }
28
+ return content;
29
+ }, [content, isJson]);
30
+ const lineCount = useMemo(
31
+ () => displayContent.split("\n").length,
32
+ [displayContent]
33
+ );
34
+ const canHighlight = shouldHighlight(displayContent);
35
+ const [prevDeps, setPrevDeps] = useState({ displayContent, language });
36
+ if (prevDeps.displayContent !== displayContent || prevDeps.language !== language) {
37
+ setPrevDeps({ displayContent, language });
38
+ setHtml("");
39
+ setError(null);
40
+ setLoading(canHighlight);
41
+ }
42
+ useEffect(() => {
43
+ if (!canHighlight) return;
44
+ let cancelled = false;
45
+ shikiHighlight(displayContent, language).then(
46
+ (result) => {
47
+ if (cancelled) return;
48
+ setHtml(result);
49
+ setError(null);
50
+ setLoading(false);
51
+ },
52
+ (err) => {
53
+ if (cancelled) return;
54
+ console.error("[CodePreview] Shiki highlight error:", err);
55
+ setError(err instanceof Error ? err.message : "Highlight failed");
56
+ setHtml("");
57
+ setLoading(false);
58
+ }
59
+ );
60
+ return () => {
61
+ cancelled = true;
62
+ };
63
+ }, [displayContent, language, canHighlight]);
64
+ const handleCopy = async () => {
65
+ await navigator.clipboard.writeText(displayContent);
66
+ setCopied(true);
67
+ setTimeout(() => setCopied(false), 2e3);
68
+ };
69
+ if (!canHighlight) {
70
+ return /* @__PURE__ */ jsx(PlainTextLargePreview, { content: displayContent, language });
71
+ }
72
+ return /* @__PURE__ */ jsxs("div", { className: "fv-source", children: [
73
+ /* @__PURE__ */ jsxs("div", { className: "fv-source__toolbar", children: [
74
+ /* @__PURE__ */ jsxs("div", { className: "fv-source__toolbar-left", children: [
75
+ /* @__PURE__ */ jsx("span", { className: "fv-source__lang-badge", children: language }),
76
+ /* @__PURE__ */ jsxs("span", { className: "fv-source__line-count", children: [
77
+ lineCount,
78
+ " line",
79
+ lineCount !== 1 ? "s" : ""
80
+ ] })
81
+ ] }),
82
+ /* @__PURE__ */ jsxs("div", { className: "fv-source__toolbar-right", children: [
83
+ /* @__PURE__ */ jsx(
84
+ "button",
85
+ {
86
+ onClick: () => setWordWrap((w) => !w),
87
+ className: `fv-btn fv-btn--icon ${wordWrap ? "fv-source__btn-active" : ""}`,
88
+ title: wordWrap ? "Disable word wrap" : "Enable word wrap",
89
+ children: /* @__PURE__ */ jsx(WrapTextIcon, { size: 14 })
90
+ }
91
+ ),
92
+ /* @__PURE__ */ jsx(
93
+ "button",
94
+ {
95
+ onClick: handleCopy,
96
+ className: "fv-btn fv-btn--icon",
97
+ title: t.copyCode,
98
+ children: copied ? /* @__PURE__ */ jsx(CheckIcon, { size: 14 }) : /* @__PURE__ */ jsx(CopyIcon, { size: 14 })
99
+ }
100
+ )
101
+ ] })
102
+ ] }),
103
+ /* @__PURE__ */ jsx("div", { className: "fv-source__content", children: loading ? /* @__PURE__ */ jsx("div", { className: "fv-source__loading", children: /* @__PURE__ */ jsxs("div", { className: "fv-source__loading-inner", children: [
104
+ /* @__PURE__ */ jsx("div", { className: "fv-spinner" }),
105
+ /* @__PURE__ */ jsx("p", { className: "fv-source__loading-label", children: "Loading syntax highlighter..." })
106
+ ] }) }) : html ? /* @__PURE__ */ jsx(
107
+ "div",
108
+ {
109
+ className: `fv-shiki-wrapper ${wordWrap ? "fv-shiki-wrap" : "fv-shiki-nowrap"}`,
110
+ dangerouslySetInnerHTML: { __html: html }
111
+ }
112
+ ) : /* @__PURE__ */ jsx("div", { className: "fv-shiki-plaintext", children: /* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: displayContent.split("\n").map((line, i) => /* @__PURE__ */ jsxs("div", { className: "line", children: [
113
+ /* @__PURE__ */ jsx("span", { className: "linenumber", children: i + 1 }),
114
+ /* @__PURE__ */ jsx("span", { className: "linecontent", children: line || "\xA0" })
115
+ ] }, i)) }) }) }) })
116
+ ] });
117
+ }
118
+ export {
119
+ CodePreview
120
+ };
121
+ //# sourceMappingURL=CodePreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/CodePreview.tsx"],"sourcesContent":["import { useState, useEffect, useMemo } from \"react\";\nimport { CopyIcon, CheckIcon, WrapTextIcon } from \"./icons\";\nimport { highlightCode as shikiHighlight, getShikiLanguage } from \"./shiki\";\nimport { shouldHighlight } from \"./limits\";\nimport { PlainTextLargePreview } from \"./PlainTextLargePreview\";\nimport { useLocale } from \"./core/i18n\";\nimport \"./styles/ShikiSourceView.css\";\n\ninterface CodePreviewProps {\n content: string;\n fileName: string;\n isJson?: boolean;\n}\n\nexport function CodePreview({ content, fileName, isJson }: CodePreviewProps) {\n const [html, setHtml] = useState<string>(\"\");\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<string | null>(null);\n const [copied, setCopied] = useState(false);\n const [wordWrap, setWordWrap] = useState(true);\n const t = useLocale();\n\n const language = useMemo(\n () => (isJson ? \"json\" : getShikiLanguage(fileName)),\n [isJson, fileName]\n );\n\n const displayContent = useMemo(() => {\n if (isJson) {\n try {\n return JSON.stringify(JSON.parse(content), null, 2);\n } catch {\n return content;\n }\n }\n return content;\n }, [content, isJson]);\n\n const lineCount = useMemo(\n () => displayContent.split(\"\\n\").length,\n [displayContent]\n );\n\n const canHighlight = shouldHighlight(displayContent);\n\n const [prevDeps, setPrevDeps] = useState({ displayContent, language });\n if (prevDeps.displayContent !== displayContent || prevDeps.language !== language) {\n setPrevDeps({ displayContent, language });\n setHtml(\"\");\n setError(null);\n setLoading(canHighlight);\n }\n\n useEffect(() => {\n if (!canHighlight) return;\n\n let cancelled = false;\n shikiHighlight(displayContent, language).then(\n (result) => {\n if (cancelled) return;\n setHtml(result);\n setError(null);\n setLoading(false);\n },\n (err) => {\n if (cancelled) return;\n console.error(\"[CodePreview] Shiki highlight error:\", err);\n setError(err instanceof Error ? err.message : \"Highlight failed\");\n setHtml(\"\");\n setLoading(false);\n }\n );\n\n return () => {\n cancelled = true;\n };\n }, [displayContent, language, canHighlight]);\n\n const handleCopy = async () => {\n await navigator.clipboard.writeText(displayContent);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n };\n\n if (!canHighlight) {\n return <PlainTextLargePreview content={displayContent} language={language} />;\n }\n\n return (\n <div className=\"fv-source\">\n <div className=\"fv-source__toolbar\">\n <div className=\"fv-source__toolbar-left\">\n <span className=\"fv-source__lang-badge\">{language}</span>\n <span className=\"fv-source__line-count\">\n {lineCount} line{lineCount !== 1 ? \"s\" : \"\"}\n </span>\n </div>\n <div className=\"fv-source__toolbar-right\">\n <button\n onClick={() => setWordWrap((w) => !w)}\n className={`fv-btn fv-btn--icon ${wordWrap ? \"fv-source__btn-active\" : \"\"}`}\n title={wordWrap ? \"Disable word wrap\" : \"Enable word wrap\"}\n >\n <WrapTextIcon size={14} />\n </button>\n <button\n onClick={handleCopy}\n className=\"fv-btn fv-btn--icon\"\n title={t.copyCode}\n >\n {copied ? <CheckIcon size={14} /> : <CopyIcon size={14} />}\n </button>\n </div>\n </div>\n\n <div className=\"fv-source__content\">\n {loading ? (\n <div className=\"fv-source__loading\">\n <div className=\"fv-source__loading-inner\">\n <div className=\"fv-spinner\" />\n <p className=\"fv-source__loading-label\">Loading syntax highlighter...</p>\n </div>\n </div>\n ) : html ? (\n <div\n className={`fv-shiki-wrapper ${wordWrap ? \"fv-shiki-wrap\" : \"fv-shiki-nowrap\"}`}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n ) : (\n <div className=\"fv-shiki-plaintext\">\n <pre>\n <code>\n {displayContent.split(\"\\n\").map((line, i) => (\n <div key={i} className=\"line\">\n <span className=\"linenumber\">{i + 1}</span>\n <span className=\"linecontent\">{line || \" \"}</span>\n </div>\n ))}\n </code>\n </pre>\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,9 @@
1
+ import * as react from 'react';
2
+
3
+ interface CsvPreviewProps {
4
+ content: string;
5
+ fileName: string;
6
+ }
7
+ declare function CsvPreview({ content, fileName }: CsvPreviewProps): react.JSX.Element;
8
+
9
+ export { CsvPreview };
@@ -0,0 +1,117 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useMemo } from "react";
3
+ import { ArrowUpDownIcon, SearchIcon } from "./icons";
4
+ import "./styles/CsvPreview.css";
5
+ function parseCsv(content) {
6
+ const lines = content.trim().split("\n");
7
+ if (lines.length === 0) return { headers: [], rows: [] };
8
+ const parseLine = (line) => {
9
+ const result = [];
10
+ let current = "";
11
+ let inQuotes = false;
12
+ for (let i = 0; i < line.length; i++) {
13
+ const char = line[i];
14
+ if (char === '"') {
15
+ if (inQuotes && i + 1 < line.length && line[i + 1] === '"') {
16
+ current += '"';
17
+ i++;
18
+ } else {
19
+ inQuotes = !inQuotes;
20
+ }
21
+ } else if (char === "," && !inQuotes) {
22
+ result.push(current.trim());
23
+ current = "";
24
+ } else {
25
+ current += char;
26
+ }
27
+ }
28
+ result.push(current.trim());
29
+ return result;
30
+ };
31
+ const headers = parseLine(lines[0]);
32
+ const rows = lines.slice(1).map(parseLine);
33
+ return { headers, rows };
34
+ }
35
+ function CsvPreview({ content, fileName }) {
36
+ const [sortColumn, setSortColumn] = useState(null);
37
+ const [sortAsc, setSortAsc] = useState(true);
38
+ const [searchTerm, setSearchTerm] = useState("");
39
+ const { headers, rows } = useMemo(() => parseCsv(content), [content]);
40
+ const filteredRows = useMemo(() => {
41
+ if (!searchTerm) return rows;
42
+ return rows.filter(
43
+ (row) => row.some(
44
+ (cell) => cell.toLowerCase().includes(searchTerm.toLowerCase())
45
+ )
46
+ );
47
+ }, [rows, searchTerm]);
48
+ const sortedRows = useMemo(() => {
49
+ if (sortColumn === null) return filteredRows;
50
+ return [...filteredRows].sort((a, b) => {
51
+ const valA = a[sortColumn] || "";
52
+ const valB = b[sortColumn] || "";
53
+ const numA = Number(valA);
54
+ const numB = Number(valB);
55
+ if (!isNaN(numA) && !isNaN(numB)) {
56
+ return sortAsc ? numA - numB : numB - numA;
57
+ }
58
+ return sortAsc ? valA.localeCompare(valB) : valB.localeCompare(valA);
59
+ });
60
+ }, [filteredRows, sortColumn, sortAsc]);
61
+ const handleSort = (colIndex) => {
62
+ if (sortColumn === colIndex) {
63
+ setSortAsc(!sortAsc);
64
+ } else {
65
+ setSortColumn(colIndex);
66
+ setSortAsc(true);
67
+ }
68
+ };
69
+ return /* @__PURE__ */ jsxs("div", { className: "fv-csv", children: [
70
+ /* @__PURE__ */ jsxs("div", { className: "fv-csv__toolbar", children: [
71
+ /* @__PURE__ */ jsxs("div", { className: "fv-csv__search-wrap", children: [
72
+ /* @__PURE__ */ jsx("span", { className: "fv-csv__search-icon", children: /* @__PURE__ */ jsx(SearchIcon, { size: 14 }) }),
73
+ /* @__PURE__ */ jsx(
74
+ "input",
75
+ {
76
+ type: "text",
77
+ placeholder: "Search in table...",
78
+ value: searchTerm,
79
+ onChange: (e) => setSearchTerm(e.target.value),
80
+ className: "fv-csv__search-input"
81
+ }
82
+ )
83
+ ] }),
84
+ /* @__PURE__ */ jsxs("span", { className: "fv-csv__row-count", children: [
85
+ sortedRows.length,
86
+ " row",
87
+ sortedRows.length !== 1 ? "s" : ""
88
+ ] })
89
+ ] }),
90
+ /* @__PURE__ */ jsx("div", { className: "fv-csv__table-wrap", children: /* @__PURE__ */ jsxs("table", { className: "fv-csv__table", children: [
91
+ /* @__PURE__ */ jsx("thead", { className: "fv-csv__thead", children: /* @__PURE__ */ jsxs("tr", { children: [
92
+ /* @__PURE__ */ jsx("th", { className: "fv-csv__th fv-csv__th-num", children: "#" }),
93
+ headers.map((header, i) => /* @__PURE__ */ jsx("th", { className: "fv-csv__th", onClick: () => handleSort(i), children: /* @__PURE__ */ jsxs("div", { className: "fv-csv__th-inner", children: [
94
+ /* @__PURE__ */ jsx("span", { children: header || `Column ${i + 1}` }),
95
+ /* @__PURE__ */ jsx(
96
+ ArrowUpDownIcon,
97
+ {
98
+ size: 12,
99
+ className: `fv-csv__sort-icon ${sortColumn === i ? "fv-csv__sort-icon--active" : ""}`
100
+ }
101
+ )
102
+ ] }) }, i))
103
+ ] }) }),
104
+ /* @__PURE__ */ jsxs("tbody", { children: [
105
+ sortedRows.map((row, rowIdx) => /* @__PURE__ */ jsxs("tr", { children: [
106
+ /* @__PURE__ */ jsx("td", { className: "fv-csv__td fv-csv__td-num", children: rowIdx + 1 }),
107
+ headers.map((_, colIdx) => /* @__PURE__ */ jsx("td", { className: "fv-csv__td", children: row[colIdx] || "" }, colIdx))
108
+ ] }, rowIdx)),
109
+ sortedRows.length === 0 && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: headers.length + 1, className: "fv-csv__empty", children: "No matching rows found" }) })
110
+ ] })
111
+ ] }) })
112
+ ] });
113
+ }
114
+ export {
115
+ CsvPreview
116
+ };
117
+ //# sourceMappingURL=CsvPreview.js.map