@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/index.d.cts CHANGED
@@ -122,7 +122,7 @@ interface NRpreviewerProps {
122
122
  content?: string;
123
123
  /** Raw HTML string to render (used when content is not provided) */
124
124
  html?: string;
125
- /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
125
+ /** Inject Tailwind v4 browser CDN at runtime for user-authored Tailwind classes. Default: false */
126
126
  tailwindCDN?: boolean;
127
127
  /** Additional CSS class on the wrapper element */
128
128
  className?: string;
@@ -134,8 +134,8 @@ interface NRpreviewerProps {
134
134
  *
135
135
  * @example
136
136
  * ```tsx
137
- * import { NRpreviewer } from '@noirmd/previewer';
138
- * import '@noirmd/previewer/markdown.css';
137
+ * import { NRpreviewer } from '@noirmd/previewer/react';
138
+ * import '@noirmd/previewer/vanilla/vanilla.css';
139
139
  *
140
140
  * <NRpreviewer content="# Hello **world**" />
141
141
  * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
@@ -148,22 +148,26 @@ interface CustomMarkdownRendererProps {
148
148
  content: string;
149
149
  }
150
150
  /**
151
- * V2 CustomMarkdownRenderer — main orchestrator.
151
+ * CustomMarkdownRenderer — thin React wrapper around the vanilla renderer.
152
152
  *
153
153
  * Pipeline:
154
- * content (string)
155
- * → parseMarkdown() → allElements (Token[])
156
- * → processAndRenderElements() → React tree
154
+ * content (string) → renderMarkdownString() → HTMLElement → mounted
157
155
  *
158
- * Note: Tailwind CDN injection is NOT handled here.
159
- * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
156
+ * The vanilla engine handles all rendering, directives and events;
157
+ * React only owns the mount point. Note: rendering happens on the
158
+ * client (useEffect); the server render is an empty placeholder.
160
159
  */
161
160
  declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
162
161
 
162
+ interface RawHtmlRendererProps {
163
+ content: string;
164
+ wrapperClassName?: string;
165
+ }
163
166
  /**
164
- * Extract all header tokens from an AST for TOC generation.
167
+ * RawHtmlRenderer thin React wrapper around the vanilla raw-HTML renderer.
168
+ * Injects <style> blocks globally and force-executes <script> tags.
165
169
  */
166
- declare function extractHeaders(elements: Token[]): Token[];
170
+ declare const RawHtmlRenderer: React.FC<RawHtmlRendererProps>;
167
171
 
168
172
  /**
169
173
  * useDebounce — delays updating a value until after a specified delay.
@@ -171,43 +175,6 @@ declare function extractHeaders(elements: Token[]): Token[];
171
175
  */
172
176
  declare function useDebounce<T>(value: T, delay: number): T;
173
177
 
174
- interface IconRendererProps {
175
- iconName: string;
176
- extraClasses?: string;
177
- }
178
- declare const IconRenderer: React.FC<IconRendererProps>;
179
- interface CodeBlockProps {
180
- code: string;
181
- language: string;
182
- title?: string;
183
- }
184
- declare const CodeBlock: React.FC<CodeBlockProps>;
185
- interface AdmonitionProps {
186
- type: string;
187
- title?: string;
188
- icon?: string;
189
- className?: string;
190
- style?: React.CSSProperties;
191
- children: React.ReactNode;
192
- }
193
- declare const Admonition: React.FC<AdmonitionProps>;
194
- interface DetailsProps {
195
- title: string;
196
- icon?: string;
197
- defaultOpen?: boolean;
198
- className?: string;
199
- style?: React.CSSProperties;
200
- children: React.ReactNode;
201
- }
202
- declare const Details: React.FC<DetailsProps>;
203
- interface ModalProps {
204
- title: string;
205
- isOpen: boolean;
206
- onClose: () => void;
207
- children: React.ReactNode;
208
- }
209
- declare const Modal: React.FC<ModalProps>;
210
-
211
178
  declare global {
212
179
  interface Window {
213
180
  __twCDNRefs?: number;
@@ -233,34 +200,38 @@ declare function scanTailwindCDN(): void;
233
200
  */
234
201
  declare function preloadTailwindCDN(): void;
235
202
 
236
- interface RenderContext {
237
- modals: Record<string, boolean>;
238
- setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
239
- articleClass: string;
240
- allElements: Token[];
203
+ interface VanillaRenderContext {
204
+ /** Parse markdown string into tokens */
241
205
  parseMarkdown: (md: string) => Token[];
242
- renderElement: (element: Token, index: number, depth?: number) => React.ReactNode;
243
- renderInline: (text: string) => React.ReactNode;
244
- processAndRenderElements: (elements: Token[], depth?: number) => React.ReactNode[];
245
- }
246
- type DirectiveComponent = React.FC<DirectiveComponentProps>;
247
- interface DirectiveComponentProps {
248
- /** The directive type string, e.g. 'card', 'note', 'modal' */
206
+ /** Render tokens into an HTMLElement */
207
+ renderElements: (tokens: Token[]) => HTMLElement;
208
+ /** Render inline text into a DocumentFragment */
209
+ renderInline: (text: string) => DocumentFragment;
210
+ /** Parse markdown string and render into an HTMLElement */
211
+ renderMarkdown: (md: string) => HTMLElement;
212
+ }
213
+ interface DirectiveProps {
214
+ /** The directive type string */
249
215
  directiveType: string;
250
- /** Parsed key="value" attributes from the {props} block */
216
+ /** Parsed key="value" attributes */
251
217
  props: Record<string, string>;
252
- /** Named slots → raw content strings (to be parsed recursively) */
218
+ /** Named slots → raw content strings */
253
219
  slots: Record<string, string>;
254
- /** Convenience: render a named slot as parsed markdown */
255
- renderSlot: (name: string) => React.ReactNode;
256
- /** Full render context access */
257
- context: RenderContext;
258
- /** Position index in the parent element list */
259
- index: string | number;
220
+ /** Render a named slot as parsed markdown */
221
+ renderSlot: (name: string) => DocumentFragment;
222
+ /** Render context */
223
+ context: VanillaRenderContext;
224
+ /** Position index */
225
+ index: number;
260
226
  /** Full parsed AST */
261
227
  allElements: Token[];
262
- /** Extra flags from the orchestrator */
228
+ /** Extra flags */
263
229
  options?: Record<string, any>;
230
+ /** Inline renderer shortcut */
231
+ renderInline: (text: string) => DocumentFragment;
232
+ /** Full markdown renderer shortcut (for complex directives like slide) */
233
+ renderMarkdown?: (md: string) => HTMLElement;
264
234
  }
235
+ type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
265
236
 
266
- export { Admonition, type BlockquoteToken, type CSSProperties, CodeBlock, type CodeblockToken, CustomMarkdownRenderer, Details, type DirectiveComponent, type DirectiveComponentProps, type DirectiveToken, type HeaderToken, type HrToken, type HtmlBlockToken, type HtmlToken, IconRenderer, type ImageToken, type ListToken, Modal, NRpreviewer, type NRpreviewerProps, type ParagraphToken, type RenderContext, type TableToken, type TocToken, type Token, extractAttributes, extractHeaders, generateId, generateScopeId, parseCssString, parseHtmlAttrs, parseMarkdown, parseProps, preloadTailwindCDN, resetScopeCounter, scanTailwindCDN, scrollToId, useDebounce, useLazyTailwindCDN };
237
+ 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, extractAttributes, generateId, generateScopeId, parseCssString, parseHtmlAttrs, parseMarkdown, parseProps, preloadTailwindCDN, resetScopeCounter, scanTailwindCDN, scrollToId, useDebounce, useLazyTailwindCDN };
package/dist/index.d.ts CHANGED
@@ -122,7 +122,7 @@ interface NRpreviewerProps {
122
122
  content?: string;
123
123
  /** Raw HTML string to render (used when content is not provided) */
124
124
  html?: string;
125
- /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
125
+ /** Inject Tailwind v4 browser CDN at runtime for user-authored Tailwind classes. Default: false */
126
126
  tailwindCDN?: boolean;
127
127
  /** Additional CSS class on the wrapper element */
128
128
  className?: string;
@@ -134,8 +134,8 @@ interface NRpreviewerProps {
134
134
  *
135
135
  * @example
136
136
  * ```tsx
137
- * import { NRpreviewer } from '@noirmd/previewer';
138
- * import '@noirmd/previewer/markdown.css';
137
+ * import { NRpreviewer } from '@noirmd/previewer/react';
138
+ * import '@noirmd/previewer/vanilla/vanilla.css';
139
139
  *
140
140
  * <NRpreviewer content="# Hello **world**" />
141
141
  * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
@@ -148,22 +148,26 @@ interface CustomMarkdownRendererProps {
148
148
  content: string;
149
149
  }
150
150
  /**
151
- * V2 CustomMarkdownRenderer — main orchestrator.
151
+ * CustomMarkdownRenderer — thin React wrapper around the vanilla renderer.
152
152
  *
153
153
  * Pipeline:
154
- * content (string)
155
- * → parseMarkdown() → allElements (Token[])
156
- * → processAndRenderElements() → React tree
154
+ * content (string) → renderMarkdownString() → HTMLElement → mounted
157
155
  *
158
- * Note: Tailwind CDN injection is NOT handled here.
159
- * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
156
+ * The vanilla engine handles all rendering, directives and events;
157
+ * React only owns the mount point. Note: rendering happens on the
158
+ * client (useEffect); the server render is an empty placeholder.
160
159
  */
161
160
  declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
162
161
 
162
+ interface RawHtmlRendererProps {
163
+ content: string;
164
+ wrapperClassName?: string;
165
+ }
163
166
  /**
164
- * Extract all header tokens from an AST for TOC generation.
167
+ * RawHtmlRenderer thin React wrapper around the vanilla raw-HTML renderer.
168
+ * Injects <style> blocks globally and force-executes <script> tags.
165
169
  */
166
- declare function extractHeaders(elements: Token[]): Token[];
170
+ declare const RawHtmlRenderer: React.FC<RawHtmlRendererProps>;
167
171
 
168
172
  /**
169
173
  * useDebounce — delays updating a value until after a specified delay.
@@ -171,43 +175,6 @@ declare function extractHeaders(elements: Token[]): Token[];
171
175
  */
172
176
  declare function useDebounce<T>(value: T, delay: number): T;
173
177
 
174
- interface IconRendererProps {
175
- iconName: string;
176
- extraClasses?: string;
177
- }
178
- declare const IconRenderer: React.FC<IconRendererProps>;
179
- interface CodeBlockProps {
180
- code: string;
181
- language: string;
182
- title?: string;
183
- }
184
- declare const CodeBlock: React.FC<CodeBlockProps>;
185
- interface AdmonitionProps {
186
- type: string;
187
- title?: string;
188
- icon?: string;
189
- className?: string;
190
- style?: React.CSSProperties;
191
- children: React.ReactNode;
192
- }
193
- declare const Admonition: React.FC<AdmonitionProps>;
194
- interface DetailsProps {
195
- title: string;
196
- icon?: string;
197
- defaultOpen?: boolean;
198
- className?: string;
199
- style?: React.CSSProperties;
200
- children: React.ReactNode;
201
- }
202
- declare const Details: React.FC<DetailsProps>;
203
- interface ModalProps {
204
- title: string;
205
- isOpen: boolean;
206
- onClose: () => void;
207
- children: React.ReactNode;
208
- }
209
- declare const Modal: React.FC<ModalProps>;
210
-
211
178
  declare global {
212
179
  interface Window {
213
180
  __twCDNRefs?: number;
@@ -233,34 +200,38 @@ declare function scanTailwindCDN(): void;
233
200
  */
234
201
  declare function preloadTailwindCDN(): void;
235
202
 
236
- interface RenderContext {
237
- modals: Record<string, boolean>;
238
- setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
239
- articleClass: string;
240
- allElements: Token[];
203
+ interface VanillaRenderContext {
204
+ /** Parse markdown string into tokens */
241
205
  parseMarkdown: (md: string) => Token[];
242
- renderElement: (element: Token, index: number, depth?: number) => React.ReactNode;
243
- renderInline: (text: string) => React.ReactNode;
244
- processAndRenderElements: (elements: Token[], depth?: number) => React.ReactNode[];
245
- }
246
- type DirectiveComponent = React.FC<DirectiveComponentProps>;
247
- interface DirectiveComponentProps {
248
- /** The directive type string, e.g. 'card', 'note', 'modal' */
206
+ /** Render tokens into an HTMLElement */
207
+ renderElements: (tokens: Token[]) => HTMLElement;
208
+ /** Render inline text into a DocumentFragment */
209
+ renderInline: (text: string) => DocumentFragment;
210
+ /** Parse markdown string and render into an HTMLElement */
211
+ renderMarkdown: (md: string) => HTMLElement;
212
+ }
213
+ interface DirectiveProps {
214
+ /** The directive type string */
249
215
  directiveType: string;
250
- /** Parsed key="value" attributes from the {props} block */
216
+ /** Parsed key="value" attributes */
251
217
  props: Record<string, string>;
252
- /** Named slots → raw content strings (to be parsed recursively) */
218
+ /** Named slots → raw content strings */
253
219
  slots: Record<string, string>;
254
- /** Convenience: render a named slot as parsed markdown */
255
- renderSlot: (name: string) => React.ReactNode;
256
- /** Full render context access */
257
- context: RenderContext;
258
- /** Position index in the parent element list */
259
- index: string | number;
220
+ /** Render a named slot as parsed markdown */
221
+ renderSlot: (name: string) => DocumentFragment;
222
+ /** Render context */
223
+ context: VanillaRenderContext;
224
+ /** Position index */
225
+ index: number;
260
226
  /** Full parsed AST */
261
227
  allElements: Token[];
262
- /** Extra flags from the orchestrator */
228
+ /** Extra flags */
263
229
  options?: Record<string, any>;
230
+ /** Inline renderer shortcut */
231
+ renderInline: (text: string) => DocumentFragment;
232
+ /** Full markdown renderer shortcut (for complex directives like slide) */
233
+ renderMarkdown?: (md: string) => HTMLElement;
264
234
  }
235
+ type DirectiveRendererFn = (props: DirectiveProps) => HTMLElement | DocumentFragment;
265
236
 
266
- export { Admonition, type BlockquoteToken, type CSSProperties, CodeBlock, type CodeblockToken, CustomMarkdownRenderer, Details, type DirectiveComponent, type DirectiveComponentProps, type DirectiveToken, type HeaderToken, type HrToken, type HtmlBlockToken, type HtmlToken, IconRenderer, type ImageToken, type ListToken, Modal, NRpreviewer, type NRpreviewerProps, type ParagraphToken, type RenderContext, type TableToken, type TocToken, type Token, extractAttributes, extractHeaders, generateId, generateScopeId, parseCssString, parseHtmlAttrs, parseMarkdown, parseProps, preloadTailwindCDN, resetScopeCounter, scanTailwindCDN, scrollToId, useDebounce, useLazyTailwindCDN };
237
+ 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, extractAttributes, generateId, generateScopeId, parseCssString, parseHtmlAttrs, parseMarkdown, parseProps, preloadTailwindCDN, resetScopeCounter, scanTailwindCDN, scrollToId, useDebounce, useLazyTailwindCDN };