@typefm/react-markdown-viewer 0.1.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 (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -0
  3. package/dist/ErrorBoundary.d.ts +25 -0
  4. package/dist/ErrorBoundary.d.ts.map +1 -0
  5. package/dist/ErrorBoundary.js +29 -0
  6. package/dist/ErrorBoundary.js.map +1 -0
  7. package/dist/MarkdownViewer.d.ts +41 -0
  8. package/dist/MarkdownViewer.d.ts.map +1 -0
  9. package/dist/MarkdownViewer.js +69 -0
  10. package/dist/MarkdownViewer.js.map +1 -0
  11. package/dist/index.d.ts +17 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +21 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/lib/cache-manager.d.ts +59 -0
  16. package/dist/lib/cache-manager.d.ts.map +1 -0
  17. package/dist/lib/cache-manager.js +160 -0
  18. package/dist/lib/cache-manager.js.map +1 -0
  19. package/dist/lib/cursor-controller.d.ts +13 -0
  20. package/dist/lib/cursor-controller.d.ts.map +1 -0
  21. package/dist/lib/cursor-controller.js +93 -0
  22. package/dist/lib/cursor-controller.js.map +1 -0
  23. package/dist/lib/defaults/code-block.d.ts +71 -0
  24. package/dist/lib/defaults/code-block.d.ts.map +1 -0
  25. package/dist/lib/defaults/code-block.js +104 -0
  26. package/dist/lib/defaults/code-block.js.map +1 -0
  27. package/dist/lib/defaults/image.d.ts +41 -0
  28. package/dist/lib/defaults/image.d.ts.map +1 -0
  29. package/dist/lib/defaults/image.js +45 -0
  30. package/dist/lib/defaults/image.js.map +1 -0
  31. package/dist/lib/defaults/link.d.ts +45 -0
  32. package/dist/lib/defaults/link.d.ts.map +1 -0
  33. package/dist/lib/defaults/link.js +76 -0
  34. package/dist/lib/defaults/link.js.map +1 -0
  35. package/dist/lib/defaults/math.d.ts +51 -0
  36. package/dist/lib/defaults/math.d.ts.map +1 -0
  37. package/dist/lib/defaults/math.js +119 -0
  38. package/dist/lib/defaults/math.js.map +1 -0
  39. package/dist/lib/defaults/table.d.ts +18 -0
  40. package/dist/lib/defaults/table.d.ts.map +1 -0
  41. package/dist/lib/defaults/table.js +19 -0
  42. package/dist/lib/defaults/table.js.map +1 -0
  43. package/dist/lib/highlighter.d.ts +81 -0
  44. package/dist/lib/highlighter.d.ts.map +1 -0
  45. package/dist/lib/highlighter.js +421 -0
  46. package/dist/lib/highlighter.js.map +1 -0
  47. package/dist/lib/hook-utils.d.ts +32 -0
  48. package/dist/lib/hook-utils.d.ts.map +1 -0
  49. package/dist/lib/hook-utils.js +42 -0
  50. package/dist/lib/hook-utils.js.map +1 -0
  51. package/dist/lib/html.d.ts +2 -0
  52. package/dist/lib/html.d.ts.map +1 -0
  53. package/dist/lib/html.js +12 -0
  54. package/dist/lib/html.js.map +1 -0
  55. package/dist/lib/morph.d.ts +57 -0
  56. package/dist/lib/morph.d.ts.map +1 -0
  57. package/dist/lib/morph.js +204 -0
  58. package/dist/lib/morph.js.map +1 -0
  59. package/dist/lib/parser.d.ts +32 -0
  60. package/dist/lib/parser.d.ts.map +1 -0
  61. package/dist/lib/parser.js +645 -0
  62. package/dist/lib/parser.js.map +1 -0
  63. package/dist/lib/wasm-init.d.ts +33 -0
  64. package/dist/lib/wasm-init.d.ts.map +1 -0
  65. package/dist/lib/wasm-init.js +69 -0
  66. package/dist/lib/wasm-init.js.map +1 -0
  67. package/dist/styles/alerts.css +294 -0
  68. package/dist/styles/dotted.svg +3 -0
  69. package/dist/styles/hljs.css +332 -0
  70. package/dist/styles/index.css +17 -0
  71. package/dist/styles/katex.css +74 -0
  72. package/dist/styles/viewer.css +975 -0
  73. package/dist/types/hooks.d.ts +207 -0
  74. package/dist/types/hooks.d.ts.map +1 -0
  75. package/dist/types/hooks.js +7 -0
  76. package/dist/types/hooks.js.map +1 -0
  77. package/dist/useMarkdownViewer.d.ts +18 -0
  78. package/dist/useMarkdownViewer.d.ts.map +1 -0
  79. package/dist/useMarkdownViewer.js +403 -0
  80. package/dist/useMarkdownViewer.js.map +1 -0
  81. package/dist/utils.d.ts +20 -0
  82. package/dist/utils.d.ts.map +1 -0
  83. package/dist/utils.js +18 -0
  84. package/dist/utils.js.map +1 -0
  85. package/package.json +78 -0
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Syntax Highlighting - GitHub Prettylights Theme
3
+ *
4
+ * Based on GitHub's Prettylights syntax highlighting.
5
+ * Includes both light and dark variants automatically.
6
+ *
7
+ * Customization Options:
8
+ *
9
+ * 1. Override CSS variables:
10
+ * .markdown-viewer {
11
+ * --color-prettylights-syntax-keyword: #e06c75;
12
+ * --color-prettylights-syntax-string: #98c379;
13
+ * }
14
+ *
15
+ * 2. Use highlight.js theme directly:
16
+ * @import "highlight.js/styles/monokai.css";
17
+ *
18
+ * Popular themes: github-dark, github, monokai, dracula, nord,
19
+ * vs2015, atom-one-dark, atom-one-light
20
+ * See all: https://highlightjs.org/examples
21
+ */
22
+
23
+ /* ============================================
24
+ Light Theme (default)
25
+ ============================================ */
26
+ .markdown-viewer {
27
+ --color-prettylights-syntax-comment: #59636e;
28
+ --color-prettylights-syntax-constant: #0550ae;
29
+ --color-prettylights-syntax-constant-other-reference-link: #0a3069;
30
+ --color-prettylights-syntax-entity: #6639ba;
31
+ --color-prettylights-syntax-entity-tag: #0550ae;
32
+ --color-prettylights-syntax-keyword: #cf222e;
33
+ --color-prettylights-syntax-string: #0a3069;
34
+ --color-prettylights-syntax-string-regexp: #116329;
35
+ --color-prettylights-syntax-variable: #953800;
36
+ --color-prettylights-syntax-brackethighlighter-angle: #59636e;
37
+ --color-prettylights-syntax-brackethighlighter-unmatched: #82071e;
38
+ --color-prettylights-syntax-carriage-return-text: #f6f8fa;
39
+ --color-prettylights-syntax-carriage-return-bg: #cf222e;
40
+ --color-prettylights-syntax-invalid-illegal-text: #f6f8fa;
41
+ --color-prettylights-syntax-invalid-illegal-bg: #82071e;
42
+ --color-prettylights-syntax-storage-modifier-import: #1f2328;
43
+ --color-prettylights-syntax-markup-heading: #0550ae;
44
+ --color-prettylights-syntax-markup-list: #3b2300;
45
+ --color-prettylights-syntax-markup-bold: #1f2328;
46
+ --color-prettylights-syntax-markup-italic: #1f2328;
47
+ --color-prettylights-syntax-markup-inserted-text: #116329;
48
+ --color-prettylights-syntax-markup-inserted-bg: #dafbe1;
49
+ --color-prettylights-syntax-markup-deleted-text: #82071e;
50
+ --color-prettylights-syntax-markup-deleted-bg: #ffebe9;
51
+ --color-prettylights-syntax-markup-changed-text: #953800;
52
+ --color-prettylights-syntax-markup-changed-bg: #ffd8b5;
53
+ --color-prettylights-syntax-markup-ignored-text: #d1d9e0;
54
+ --color-prettylights-syntax-markup-ignored-bg: #0550ae;
55
+ --color-prettylights-syntax-meta-diff-range: #8250df;
56
+ --color-prettylights-syntax-sublimelinter-gutter-mark: #818b98;
57
+ }
58
+
59
+ /* ============================================
60
+ Dark Theme (automatic via prefers-color-scheme)
61
+ ============================================ */
62
+ @media (prefers-color-scheme: dark) {
63
+ .markdown-viewer {
64
+ --color-prettylights-syntax-comment: #9198a1;
65
+ --color-prettylights-syntax-constant: #79c0ff;
66
+ --color-prettylights-syntax-constant-other-reference-link: #a5d6ff;
67
+ --color-prettylights-syntax-entity: #d2a8ff;
68
+ --color-prettylights-syntax-entity-tag: #7ee787;
69
+ --color-prettylights-syntax-keyword: #ff7b72;
70
+ --color-prettylights-syntax-string: #a5d6ff;
71
+ --color-prettylights-syntax-string-regexp: #7ee787;
72
+ --color-prettylights-syntax-variable: #ffa657;
73
+ --color-prettylights-syntax-brackethighlighter-angle: #9198a1;
74
+ --color-prettylights-syntax-brackethighlighter-unmatched: #f85149;
75
+ --color-prettylights-syntax-carriage-return-text: #f0f6fc;
76
+ --color-prettylights-syntax-carriage-return-bg: #b62324;
77
+ --color-prettylights-syntax-invalid-illegal-text: #f0f6fc;
78
+ --color-prettylights-syntax-invalid-illegal-bg: #8e1519;
79
+ --color-prettylights-syntax-storage-modifier-import: #f0f6fc;
80
+ --color-prettylights-syntax-markup-heading: #1f6feb;
81
+ --color-prettylights-syntax-markup-list: #f2cc60;
82
+ --color-prettylights-syntax-markup-bold: #f0f6fc;
83
+ --color-prettylights-syntax-markup-italic: #f0f6fc;
84
+ --color-prettylights-syntax-markup-inserted-text: #aff5b4;
85
+ --color-prettylights-syntax-markup-inserted-bg: #033a16;
86
+ --color-prettylights-syntax-markup-deleted-text: #ffdcd7;
87
+ --color-prettylights-syntax-markup-deleted-bg: #67060c;
88
+ --color-prettylights-syntax-markup-changed-text: #ffdfb6;
89
+ --color-prettylights-syntax-markup-changed-bg: #5a1e02;
90
+ --color-prettylights-syntax-markup-ignored-text: #f0f6fc;
91
+ --color-prettylights-syntax-markup-ignored-bg: #1158c7;
92
+ --color-prettylights-syntax-meta-diff-range: #d2a8ff;
93
+ --color-prettylights-syntax-sublimelinter-gutter-mark: #3d444d;
94
+ }
95
+ }
96
+
97
+ /* ============================================
98
+ Manual Dark Theme Toggle
99
+ Supports: .dark, [data-theme="dark"], .markdown-viewer.dark
100
+ ============================================ */
101
+ .dark .markdown-viewer,
102
+ [data-theme="dark"] .markdown-viewer,
103
+ .markdown-viewer.dark {
104
+ --color-prettylights-syntax-comment: #9198a1;
105
+ --color-prettylights-syntax-constant: #79c0ff;
106
+ --color-prettylights-syntax-constant-other-reference-link: #a5d6ff;
107
+ --color-prettylights-syntax-entity: #d2a8ff;
108
+ --color-prettylights-syntax-entity-tag: #7ee787;
109
+ --color-prettylights-syntax-keyword: #ff7b72;
110
+ --color-prettylights-syntax-string: #a5d6ff;
111
+ --color-prettylights-syntax-string-regexp: #7ee787;
112
+ --color-prettylights-syntax-variable: #ffa657;
113
+ --color-prettylights-syntax-brackethighlighter-angle: #9198a1;
114
+ --color-prettylights-syntax-brackethighlighter-unmatched: #f85149;
115
+ --color-prettylights-syntax-carriage-return-text: #f0f6fc;
116
+ --color-prettylights-syntax-carriage-return-bg: #b62324;
117
+ --color-prettylights-syntax-invalid-illegal-text: #f0f6fc;
118
+ --color-prettylights-syntax-invalid-illegal-bg: #8e1519;
119
+ --color-prettylights-syntax-storage-modifier-import: #f0f6fc;
120
+ --color-prettylights-syntax-markup-heading: #1f6feb;
121
+ --color-prettylights-syntax-markup-list: #f2cc60;
122
+ --color-prettylights-syntax-markup-bold: #f0f6fc;
123
+ --color-prettylights-syntax-markup-italic: #f0f6fc;
124
+ --color-prettylights-syntax-markup-inserted-text: #aff5b4;
125
+ --color-prettylights-syntax-markup-inserted-bg: #033a16;
126
+ --color-prettylights-syntax-markup-deleted-text: #ffdcd7;
127
+ --color-prettylights-syntax-markup-deleted-bg: #67060c;
128
+ --color-prettylights-syntax-markup-changed-text: #ffdfb6;
129
+ --color-prettylights-syntax-markup-changed-bg: #5a1e02;
130
+ --color-prettylights-syntax-markup-ignored-text: #f0f6fc;
131
+ --color-prettylights-syntax-markup-ignored-bg: #1158c7;
132
+ --color-prettylights-syntax-meta-diff-range: #d2a8ff;
133
+ --color-prettylights-syntax-sublimelinter-gutter-mark: #3d444d;
134
+ }
135
+
136
+ /* ============================================
137
+ Token Mappings - Comments
138
+ // comment, /* comment */, # comment, <!-- comment -->
139
+ ============================================ */
140
+ .hljs-comment,
141
+ .hljs-quote {
142
+ color: var(--color-prettylights-syntax-comment);
143
+ font-style: italic;
144
+ }
145
+
146
+ /* ============================================
147
+ Token Mappings - Constants & Numbers
148
+ Numbers, booleans, null, undefined
149
+ ============================================ */
150
+ .hljs-number,
151
+ .hljs-literal,
152
+ .hljs-boolean,
153
+ .hljs-null {
154
+ color: var(--color-prettylights-syntax-constant);
155
+ }
156
+
157
+ /* ============================================
158
+ Token Mappings - Strings
159
+ "hello", 'world', `template`
160
+ ============================================ */
161
+ .hljs-string,
162
+ .hljs-link {
163
+ color: var(--color-prettylights-syntax-string);
164
+ }
165
+
166
+ .hljs-regexp,
167
+ .hljs-symbol {
168
+ color: var(--color-prettylights-syntax-string-regexp);
169
+ }
170
+
171
+ /* ============================================
172
+ Token Mappings - Keywords & Control Flow
173
+ if, else, return, const, let, function, class, import, export, etc.
174
+ ============================================ */
175
+ .hljs-keyword,
176
+ .hljs-selector-tag,
177
+ .hljs-meta .hljs-keyword,
178
+ .hljs-doctag,
179
+ .hljs-section {
180
+ color: var(--color-prettylights-syntax-keyword);
181
+ }
182
+
183
+ /* Built-ins and types */
184
+ .hljs-built_in,
185
+ .hljs-type {
186
+ color: var(--color-prettylights-syntax-keyword);
187
+ }
188
+
189
+ /* ============================================
190
+ Token Mappings - Entities
191
+ Function names, class names, titles
192
+ ============================================ */
193
+ .hljs-title,
194
+ .hljs-title.function_,
195
+ .hljs-title.class_,
196
+ .hljs-title.function_.inherited__ {
197
+ color: var(--color-prettylights-syntax-entity);
198
+ }
199
+
200
+ /* ============================================
201
+ Token Mappings - Variables & Parameters
202
+ $var, @attr, params, arguments
203
+ ============================================ */
204
+ .hljs-variable,
205
+ .hljs-template-variable,
206
+ .hljs-params {
207
+ color: var(--color-prettylights-syntax-variable);
208
+ }
209
+
210
+ /* ============================================
211
+ Token Mappings - Tags (HTML/XML)
212
+ <div>, <span>, element names
213
+ ============================================ */
214
+ .hljs-name,
215
+ .hljs-tag {
216
+ color: var(--color-prettylights-syntax-entity-tag);
217
+ }
218
+
219
+ /* ============================================
220
+ Token Mappings - Attributes
221
+ href=, class=, id=, data-*=
222
+ ============================================ */
223
+ .hljs-attr,
224
+ .hljs-attribute {
225
+ color: var(--color-prettylights-syntax-constant);
226
+ }
227
+
228
+ /* ============================================
229
+ Token Mappings - Operators & Punctuation
230
+ =, +, -, *, /, {}, (), []
231
+ ============================================ */
232
+ .hljs-punctuation {
233
+ color: var(--color-prettylights-syntax-brackethighlighter-angle);
234
+ }
235
+
236
+ .hljs-operator,
237
+ .hljs-bullet {
238
+ color: var(--color-prettylights-syntax-keyword);
239
+ }
240
+
241
+ /* ============================================
242
+ Token Mappings - Properties
243
+ Object properties, CSS properties
244
+ ============================================ */
245
+ .hljs-property {
246
+ color: var(--color-prettylights-syntax-constant);
247
+ }
248
+
249
+ /* ============================================
250
+ Token Mappings - Selectors (CSS)
251
+ .class, #id, element
252
+ ============================================ */
253
+ .hljs-selector-class,
254
+ .hljs-selector-id,
255
+ .hljs-selector-attr,
256
+ .hljs-selector-pseudo {
257
+ color: var(--color-prettylights-syntax-entity);
258
+ }
259
+
260
+ /* ============================================
261
+ Token Mappings - Diff Highlighting
262
+ + additions, - deletions
263
+ ============================================ */
264
+ .hljs-addition {
265
+ color: var(--color-prettylights-syntax-markup-inserted-text);
266
+ background-color: var(--color-prettylights-syntax-markup-inserted-bg);
267
+ }
268
+
269
+ .hljs-deletion {
270
+ color: var(--color-prettylights-syntax-markup-deleted-text);
271
+ background-color: var(--color-prettylights-syntax-markup-deleted-bg);
272
+ }
273
+
274
+ /* ============================================
275
+ Token Mappings - Meta & Special
276
+ Preprocessor, shebang, annotations
277
+ ============================================ */
278
+ .hljs-meta {
279
+ color: var(--color-prettylights-syntax-variable);
280
+ }
281
+
282
+ .hljs-meta .hljs-string {
283
+ color: var(--color-prettylights-syntax-string);
284
+ }
285
+
286
+ /* ============================================
287
+ Token Mappings - Storage/Import
288
+ import, export, module statements
289
+ ============================================ */
290
+ .hljs-module-access,
291
+ .hljs-formula {
292
+ color: var(--color-prettylights-syntax-storage-modifier-import);
293
+ }
294
+
295
+ /* ============================================
296
+ Token Mappings - Emphasis
297
+ Strong, emphasis in markdown
298
+ ============================================ */
299
+ .hljs-strong {
300
+ font-weight: 600;
301
+ color: var(--color-prettylights-syntax-markup-bold);
302
+ }
303
+
304
+ .hljs-emphasis {
305
+ font-style: italic;
306
+ color: var(--color-prettylights-syntax-markup-italic);
307
+ }
308
+
309
+ /* ============================================
310
+ Token Mappings - Markup Headings
311
+ # Heading in markdown
312
+ ============================================ */
313
+ .hljs-section {
314
+ font-weight: 600;
315
+ color: var(--color-prettylights-syntax-markup-heading);
316
+ }
317
+
318
+ /* ============================================
319
+ Invalid/Illegal Code
320
+ ============================================ */
321
+ .hljs-invalid {
322
+ color: var(--color-prettylights-syntax-invalid-illegal-text);
323
+ background-color: var(--color-prettylights-syntax-invalid-illegal-bg);
324
+ }
325
+
326
+ /* ============================================
327
+ Pending State (language loading)
328
+ ============================================ */
329
+ code[data-hljs-pending="true"] {
330
+ /* Optional: subtle indication that highlighting is pending */
331
+ /* opacity: 0.95; */
332
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * React Markdown Viewer - Combined Styles
3
+ *
4
+ * This is the main entry point that imports all component styles.
5
+ * Import this single file to get complete styling for the viewer.
6
+ *
7
+ * Individual imports available for tree-shaking:
8
+ * - viewer.css : Core markdown rendering styles
9
+ * - alerts.css : GitHub-style alert boxes
10
+ * - katex.css : Math/LaTeX rendering
11
+ * - hljs.css : Syntax highlighting theme
12
+ */
13
+
14
+ @import './viewer.css';
15
+ @import './alerts.css';
16
+ @import './katex.css';
17
+ @import './hljs.css';
@@ -0,0 +1,74 @@
1
+ /**
2
+ * KaTeX Math Rendering Styles
3
+ *
4
+ * Styles for LaTeX/math rendering using KaTeX.
5
+ * KaTeX is loaded lazily when math content is detected.
6
+ *
7
+ * Customization:
8
+ * Override CSS variables or these classes to customize appearance.
9
+ *
10
+ * Usage in markdown:
11
+ * Inline: $x^2 + y^2 = r^2$
12
+ * Display: $$\int_0^\infty e^{-x^2} dx$$
13
+ */
14
+
15
+ /* ============================================
16
+ KaTeX Rendered Output
17
+ Applied after KaTeX processes math content
18
+ ============================================ */
19
+ .markdown-viewer .markdown .katex {
20
+ font-size: 1em;
21
+ max-width: 100%;
22
+ overflow-x: auto;
23
+ overflow-y: clip;
24
+ }
25
+
26
+ /* Display math (block-level) alignment */
27
+ .markdown-viewer .markdown .katex-display {
28
+ text-align: left !important;
29
+ margin-left: 0 !important;
30
+ }
31
+
32
+ /* Display math error (block-level) - centered like valid display math */
33
+ /* More specific selector to override .katex-display text-align */
34
+ .markdown-viewer .markdown .katex-display.katex-error-display {
35
+ display: block;
36
+ text-align: center !important;
37
+ margin: 1em 0;
38
+ }
39
+
40
+ /* ============================================
41
+ Math Placeholder (Loading State)
42
+ Shown while KaTeX library loads asynchronously
43
+ ============================================ */
44
+ .markdown-viewer .markdown .math-placeholder {
45
+ font-family: 'KaTeX_Math', 'Times New Roman', serif;
46
+ font-style: italic;
47
+ color: var(--fgColor-muted, #59636e);
48
+ padding: 0.1em 0.2em;
49
+ background: var(--bgColor-muted, #f6f8fa);
50
+ border-radius: 6px;
51
+ }
52
+
53
+ /* Display math placeholder (block-level) */
54
+ .markdown-viewer .markdown .math-placeholder[data-math-style="display"] {
55
+ display: block;
56
+ text-align: center;
57
+ padding: 0.5em;
58
+ margin: 1em 0;
59
+ }
60
+
61
+ /* ============================================
62
+ Dark Theme Math Placeholder
63
+ ============================================ */
64
+ :is(.dark, [data-theme="dark"]) .markdown-viewer .markdown .math-placeholder {
65
+ color: var(--fgColor-muted, #9198a1);
66
+ background: var(--bgColor-muted, #151b23);
67
+ }
68
+
69
+ @media (prefers-color-scheme: dark) {
70
+ .markdown-viewer:not(:is(.dark, [data-theme="dark"], [data-theme="light"]) *) .markdown .math-placeholder {
71
+ color: var(--fgColor-muted, #9198a1);
72
+ background: var(--bgColor-muted, #151b23);
73
+ }
74
+ }