@noirmd/previewer 1.2.0 → 2.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 (53) hide show
  1. package/dist/NReditor.cjs +851 -895
  2. package/dist/NReditor.cjs.map +1 -1
  3. package/dist/NReditor.d.cts +1 -1
  4. package/dist/NReditor.d.ts +1 -1
  5. package/dist/NReditor.js +852 -896
  6. package/dist/NReditor.js.map +1 -1
  7. package/dist/admonition.css +55 -0
  8. package/dist/{markdown.css → base.css} +96 -126
  9. package/dist/blockquote.css +16 -0
  10. package/dist/button.css +32 -0
  11. package/dist/card.css +143 -0
  12. package/dist/codeblock.css +59 -0
  13. package/dist/core.cjs +9 -1
  14. package/dist/core.cjs.map +1 -1
  15. package/dist/core.js +9 -1
  16. package/dist/core.js.map +1 -1
  17. package/dist/details.css +45 -0
  18. package/dist/editor.css +56 -9
  19. package/dist/fonts/material-icons-round.woff2 +0 -0
  20. package/dist/index.cjs +852 -883
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +41 -70
  23. package/dist/index.d.ts +41 -70
  24. package/dist/index.js +851 -877
  25. package/dist/index.js.map +1 -1
  26. package/dist/list.css +18 -0
  27. package/dist/modal.css +82 -0
  28. package/dist/react.cjs +852 -886
  29. package/dist/react.cjs.map +1 -1
  30. package/dist/react.d.cts +44 -73
  31. package/dist/react.d.ts +44 -73
  32. package/dist/react.js +851 -880
  33. package/dist/react.js.map +1 -1
  34. package/dist/slide.css +21 -0
  35. package/dist/table.css +36 -0
  36. package/dist/toc.css +45 -0
  37. package/dist/vanilla.cjs +42 -28
  38. package/dist/vanilla.cjs.map +1 -1
  39. package/dist/vanilla.css +32 -677
  40. package/dist/vanilla.d.cts +8 -2
  41. package/dist/vanilla.d.ts +8 -2
  42. package/dist/vanilla.js +41 -28
  43. package/dist/vanilla.js.map +1 -1
  44. package/dist/variables.css +53 -0
  45. package/dist/vue.cjs +931 -1121
  46. package/dist/vue.cjs.map +1 -1
  47. package/dist/vue.d.cts +63 -214
  48. package/dist/vue.d.ts +63 -214
  49. package/dist/vue.js +930 -1120
  50. package/dist/vue.js.map +1 -1
  51. package/editor.css +56 -9
  52. package/package.json +5 -10
  53. package/markdown.css +0 -344
package/dist/react.d.cts CHANGED
@@ -5,7 +5,7 @@ interface NRpreviewerProps {
5
5
  content?: string;
6
6
  /** Raw HTML string to render (used when content is not provided) */
7
7
  html?: string;
8
- /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
8
+ /** Inject Tailwind v4 browser CDN at runtime for user-authored Tailwind classes. Default: false */
9
9
  tailwindCDN?: boolean;
10
10
  /** Additional CSS class on the wrapper element */
11
11
  className?: string;
@@ -17,8 +17,8 @@ interface NRpreviewerProps {
17
17
  *
18
18
  * @example
19
19
  * ```tsx
20
- * import { NRpreviewer } from '@noirmd/previewer';
21
- * import '@noirmd/previewer/markdown.css';
20
+ * import { NRpreviewer } from '@noirmd/previewer/react';
21
+ * import '@noirmd/previewer/vanilla/vanilla.css';
22
22
  *
23
23
  * <NRpreviewer content="# Hello **world**" />
24
24
  * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
@@ -31,18 +31,27 @@ interface CustomMarkdownRendererProps {
31
31
  content: string;
32
32
  }
33
33
  /**
34
- * V2 CustomMarkdownRenderer — main orchestrator.
34
+ * CustomMarkdownRenderer — thin React wrapper around the vanilla renderer.
35
35
  *
36
36
  * Pipeline:
37
- * content (string)
38
- * → parseMarkdown() → allElements (Token[])
39
- * → processAndRenderElements() → React tree
37
+ * content (string) → renderMarkdownString() → HTMLElement → mounted
40
38
  *
41
- * Note: Tailwind CDN injection is NOT handled here.
42
- * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
39
+ * The vanilla engine handles all rendering, directives and events;
40
+ * React only owns the mount point. Note: rendering happens on the
41
+ * client (useEffect); the server render is an empty placeholder.
43
42
  */
44
43
  declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
45
44
 
45
+ interface RawHtmlRendererProps {
46
+ content: string;
47
+ wrapperClassName?: string;
48
+ }
49
+ /**
50
+ * RawHtmlRenderer — thin React wrapper around the vanilla raw-HTML renderer.
51
+ * Injects <style> blocks globally and force-executes <script> tags.
52
+ */
53
+ declare const RawHtmlRenderer: React.FC<RawHtmlRendererProps>;
54
+
46
55
  /**
47
56
  * Generic CSSProperties — framework-agnostic equivalent of React.CSSProperties.
48
57
  * Used for inline styles on tokens (e.g. images).
@@ -119,54 +128,12 @@ type Token = HeaderToken | ParagraphToken | CodeblockToken | DirectiveToken | Ht
119
128
  */
120
129
  declare function parseMarkdown(markdown: string): Token[];
121
130
 
122
- /**
123
- * Extract all header tokens from an AST for TOC generation.
124
- */
125
- declare function extractHeaders(elements: Token[]): Token[];
126
-
127
131
  /**
128
132
  * useDebounce — delays updating a value until after a specified delay.
129
133
  * Useful for reducing expensive operations (like preview rendering) during rapid input.
130
134
  */
131
135
  declare function useDebounce<T>(value: T, delay: number): T;
132
136
 
133
- interface IconRendererProps {
134
- iconName: string;
135
- extraClasses?: string;
136
- }
137
- declare const IconRenderer: React.FC<IconRendererProps>;
138
- interface CodeBlockProps {
139
- code: string;
140
- language: string;
141
- title?: string;
142
- }
143
- declare const CodeBlock: React.FC<CodeBlockProps>;
144
- interface AdmonitionProps {
145
- type: string;
146
- title?: string;
147
- icon?: string;
148
- className?: string;
149
- style?: React.CSSProperties;
150
- children: React.ReactNode;
151
- }
152
- declare const Admonition: React.FC<AdmonitionProps>;
153
- interface DetailsProps {
154
- title: string;
155
- icon?: string;
156
- defaultOpen?: boolean;
157
- className?: string;
158
- style?: React.CSSProperties;
159
- children: React.ReactNode;
160
- }
161
- declare const Details: React.FC<DetailsProps>;
162
- interface ModalProps {
163
- title: string;
164
- isOpen: boolean;
165
- onClose: () => void;
166
- children: React.ReactNode;
167
- }
168
- declare const Modal: React.FC<ModalProps>;
169
-
170
137
  declare global {
171
138
  interface Window {
172
139
  __twCDNRefs?: number;
@@ -192,34 +159,38 @@ declare function scanTailwindCDN(): void;
192
159
  */
193
160
  declare function preloadTailwindCDN(): void;
194
161
 
195
- interface RenderContext {
196
- modals: Record<string, boolean>;
197
- setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
198
- articleClass: string;
199
- allElements: Token[];
162
+ interface VanillaRenderContext {
163
+ /** Parse markdown string into tokens */
200
164
  parseMarkdown: (md: string) => Token[];
201
- renderElement: (element: Token, index: number, depth?: number) => React.ReactNode;
202
- renderInline: (text: string) => React.ReactNode;
203
- processAndRenderElements: (elements: Token[], depth?: number) => React.ReactNode[];
204
- }
205
- type DirectiveComponent = React.FC<DirectiveComponentProps>;
206
- interface DirectiveComponentProps {
207
- /** The directive type string, e.g. 'card', 'note', 'modal' */
165
+ /** Render tokens into an HTMLElement */
166
+ renderElements: (tokens: Token[]) => HTMLElement;
167
+ /** Render inline text into a DocumentFragment */
168
+ renderInline: (text: string) => DocumentFragment;
169
+ /** Parse markdown string and render into an HTMLElement */
170
+ renderMarkdown: (md: string) => HTMLElement;
171
+ }
172
+ interface DirectiveProps {
173
+ /** The directive type string */
208
174
  directiveType: string;
209
- /** Parsed key="value" attributes from the {props} block */
175
+ /** Parsed key="value" attributes */
210
176
  props: Record<string, string>;
211
- /** Named slots → raw content strings (to be parsed recursively) */
177
+ /** Named slots → raw content strings */
212
178
  slots: Record<string, string>;
213
- /** Convenience: render a named slot as parsed markdown */
214
- renderSlot: (name: string) => React.ReactNode;
215
- /** Full render context access */
216
- context: RenderContext;
217
- /** Position index in the parent element list */
218
- index: string | number;
179
+ /** Render a named slot as parsed markdown */
180
+ renderSlot: (name: string) => DocumentFragment;
181
+ /** Render context */
182
+ context: VanillaRenderContext;
183
+ /** Position index */
184
+ index: number;
219
185
  /** Full parsed AST */
220
186
  allElements: Token[];
221
- /** Extra flags from the orchestrator */
187
+ /** Extra flags */
222
188
  options?: Record<string, any>;
189
+ /** Inline renderer shortcut */
190
+ renderInline: (text: string) => DocumentFragment;
191
+ /** Full markdown renderer shortcut (for complex directives like slide) */
192
+ renderMarkdown?: (md: string) => HTMLElement;
223
193
  }
194
+ type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
224
195
 
225
- export { Admonition, type CSSProperties, CodeBlock, CustomMarkdownRenderer, Details, type DirectiveComponent, type DirectiveComponentProps, IconRenderer, Modal, NRpreviewer, type NRpreviewerProps, type RenderContext, type Token, extractHeaders, parseMarkdown, preloadTailwindCDN, scanTailwindCDN, useDebounce, useLazyTailwindCDN };
196
+ export { type BlockquoteToken, type CSSProperties, type CodeblockToken, CustomMarkdownRenderer, type DirectiveProps, type DirectiveRendererFn, type DirectiveToken, type HeaderToken, type HrToken, type HtmlBlockToken, type HtmlToken, type ImageToken, type ListToken, NRpreviewer, type NRpreviewerProps, type ParagraphToken, RawHtmlRenderer, type TableToken, type TocToken, type Token, type VanillaRenderContext, parseMarkdown, preloadTailwindCDN, scanTailwindCDN, useDebounce, useLazyTailwindCDN };
package/dist/react.d.ts CHANGED
@@ -5,7 +5,7 @@ interface NRpreviewerProps {
5
5
  content?: string;
6
6
  /** Raw HTML string to render (used when content is not provided) */
7
7
  html?: string;
8
- /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
8
+ /** Inject Tailwind v4 browser CDN at runtime for user-authored Tailwind classes. Default: false */
9
9
  tailwindCDN?: boolean;
10
10
  /** Additional CSS class on the wrapper element */
11
11
  className?: string;
@@ -17,8 +17,8 @@ interface NRpreviewerProps {
17
17
  *
18
18
  * @example
19
19
  * ```tsx
20
- * import { NRpreviewer } from '@noirmd/previewer';
21
- * import '@noirmd/previewer/markdown.css';
20
+ * import { NRpreviewer } from '@noirmd/previewer/react';
21
+ * import '@noirmd/previewer/vanilla/vanilla.css';
22
22
  *
23
23
  * <NRpreviewer content="# Hello **world**" />
24
24
  * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
@@ -31,18 +31,27 @@ interface CustomMarkdownRendererProps {
31
31
  content: string;
32
32
  }
33
33
  /**
34
- * V2 CustomMarkdownRenderer — main orchestrator.
34
+ * CustomMarkdownRenderer — thin React wrapper around the vanilla renderer.
35
35
  *
36
36
  * Pipeline:
37
- * content (string)
38
- * → parseMarkdown() → allElements (Token[])
39
- * → processAndRenderElements() → React tree
37
+ * content (string) → renderMarkdownString() → HTMLElement → mounted
40
38
  *
41
- * Note: Tailwind CDN injection is NOT handled here.
42
- * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
39
+ * The vanilla engine handles all rendering, directives and events;
40
+ * React only owns the mount point. Note: rendering happens on the
41
+ * client (useEffect); the server render is an empty placeholder.
43
42
  */
44
43
  declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
45
44
 
45
+ interface RawHtmlRendererProps {
46
+ content: string;
47
+ wrapperClassName?: string;
48
+ }
49
+ /**
50
+ * RawHtmlRenderer — thin React wrapper around the vanilla raw-HTML renderer.
51
+ * Injects <style> blocks globally and force-executes <script> tags.
52
+ */
53
+ declare const RawHtmlRenderer: React.FC<RawHtmlRendererProps>;
54
+
46
55
  /**
47
56
  * Generic CSSProperties — framework-agnostic equivalent of React.CSSProperties.
48
57
  * Used for inline styles on tokens (e.g. images).
@@ -119,54 +128,12 @@ type Token = HeaderToken | ParagraphToken | CodeblockToken | DirectiveToken | Ht
119
128
  */
120
129
  declare function parseMarkdown(markdown: string): Token[];
121
130
 
122
- /**
123
- * Extract all header tokens from an AST for TOC generation.
124
- */
125
- declare function extractHeaders(elements: Token[]): Token[];
126
-
127
131
  /**
128
132
  * useDebounce — delays updating a value until after a specified delay.
129
133
  * Useful for reducing expensive operations (like preview rendering) during rapid input.
130
134
  */
131
135
  declare function useDebounce<T>(value: T, delay: number): T;
132
136
 
133
- interface IconRendererProps {
134
- iconName: string;
135
- extraClasses?: string;
136
- }
137
- declare const IconRenderer: React.FC<IconRendererProps>;
138
- interface CodeBlockProps {
139
- code: string;
140
- language: string;
141
- title?: string;
142
- }
143
- declare const CodeBlock: React.FC<CodeBlockProps>;
144
- interface AdmonitionProps {
145
- type: string;
146
- title?: string;
147
- icon?: string;
148
- className?: string;
149
- style?: React.CSSProperties;
150
- children: React.ReactNode;
151
- }
152
- declare const Admonition: React.FC<AdmonitionProps>;
153
- interface DetailsProps {
154
- title: string;
155
- icon?: string;
156
- defaultOpen?: boolean;
157
- className?: string;
158
- style?: React.CSSProperties;
159
- children: React.ReactNode;
160
- }
161
- declare const Details: React.FC<DetailsProps>;
162
- interface ModalProps {
163
- title: string;
164
- isOpen: boolean;
165
- onClose: () => void;
166
- children: React.ReactNode;
167
- }
168
- declare const Modal: React.FC<ModalProps>;
169
-
170
137
  declare global {
171
138
  interface Window {
172
139
  __twCDNRefs?: number;
@@ -192,34 +159,38 @@ declare function scanTailwindCDN(): void;
192
159
  */
193
160
  declare function preloadTailwindCDN(): void;
194
161
 
195
- interface RenderContext {
196
- modals: Record<string, boolean>;
197
- setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
198
- articleClass: string;
199
- allElements: Token[];
162
+ interface VanillaRenderContext {
163
+ /** Parse markdown string into tokens */
200
164
  parseMarkdown: (md: string) => Token[];
201
- renderElement: (element: Token, index: number, depth?: number) => React.ReactNode;
202
- renderInline: (text: string) => React.ReactNode;
203
- processAndRenderElements: (elements: Token[], depth?: number) => React.ReactNode[];
204
- }
205
- type DirectiveComponent = React.FC<DirectiveComponentProps>;
206
- interface DirectiveComponentProps {
207
- /** The directive type string, e.g. 'card', 'note', 'modal' */
165
+ /** Render tokens into an HTMLElement */
166
+ renderElements: (tokens: Token[]) => HTMLElement;
167
+ /** Render inline text into a DocumentFragment */
168
+ renderInline: (text: string) => DocumentFragment;
169
+ /** Parse markdown string and render into an HTMLElement */
170
+ renderMarkdown: (md: string) => HTMLElement;
171
+ }
172
+ interface DirectiveProps {
173
+ /** The directive type string */
208
174
  directiveType: string;
209
- /** Parsed key="value" attributes from the {props} block */
175
+ /** Parsed key="value" attributes */
210
176
  props: Record<string, string>;
211
- /** Named slots → raw content strings (to be parsed recursively) */
177
+ /** Named slots → raw content strings */
212
178
  slots: Record<string, string>;
213
- /** Convenience: render a named slot as parsed markdown */
214
- renderSlot: (name: string) => React.ReactNode;
215
- /** Full render context access */
216
- context: RenderContext;
217
- /** Position index in the parent element list */
218
- index: string | number;
179
+ /** Render a named slot as parsed markdown */
180
+ renderSlot: (name: string) => DocumentFragment;
181
+ /** Render context */
182
+ context: VanillaRenderContext;
183
+ /** Position index */
184
+ index: number;
219
185
  /** Full parsed AST */
220
186
  allElements: Token[];
221
- /** Extra flags from the orchestrator */
187
+ /** Extra flags */
222
188
  options?: Record<string, any>;
189
+ /** Inline renderer shortcut */
190
+ renderInline: (text: string) => DocumentFragment;
191
+ /** Full markdown renderer shortcut (for complex directives like slide) */
192
+ renderMarkdown?: (md: string) => HTMLElement;
223
193
  }
194
+ type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
224
195
 
225
- export { Admonition, type CSSProperties, CodeBlock, CustomMarkdownRenderer, Details, type DirectiveComponent, type DirectiveComponentProps, IconRenderer, Modal, NRpreviewer, type NRpreviewerProps, type RenderContext, type Token, extractHeaders, parseMarkdown, preloadTailwindCDN, scanTailwindCDN, useDebounce, useLazyTailwindCDN };
196
+ export { type BlockquoteToken, type CSSProperties, type CodeblockToken, CustomMarkdownRenderer, type DirectiveProps, type DirectiveRendererFn, type DirectiveToken, type HeaderToken, type HrToken, type HtmlBlockToken, type HtmlToken, type ImageToken, type ListToken, NRpreviewer, type NRpreviewerProps, type ParagraphToken, RawHtmlRenderer, type TableToken, type TocToken, type Token, type VanillaRenderContext, parseMarkdown, preloadTailwindCDN, scanTailwindCDN, useDebounce, useLazyTailwindCDN };