@noirmd/previewer 1.0.2 → 1.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.
package/dist/index.d.cts CHANGED
@@ -1,48 +1,10 @@
1
1
  import React from 'react';
2
2
 
3
- interface NRpreviewerProps {
4
- /** Markdown string to render */
5
- content?: string;
6
- /** Raw HTML string to render (used when content is not provided) */
7
- html?: string;
8
- /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
9
- tailwindCDN?: boolean;
10
- /** Additional CSS class on the wrapper element */
11
- className?: string;
12
- /** Inline styles on the wrapper element */
13
- style?: React.CSSProperties;
14
- }
15
3
  /**
16
- * NRpreviewerdrop-in markdown/HTML preview component.
17
- *
18
- * @example
19
- * ```tsx
20
- * import { NRpreviewer } from '@noirmd/previewer';
21
- * import '@noirmd/previewer/markdown.css';
22
- *
23
- * <NRpreviewer content="# Hello **world**" />
24
- * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
25
- * <NRpreviewer html="<h1>Raw HTML</h1>" />
26
- * ```
27
- */
28
- declare const NRpreviewer: React.FC<NRpreviewerProps>;
29
-
30
- interface CustomMarkdownRendererProps {
31
- content: string;
32
- }
33
- /**
34
- * V2 CustomMarkdownRenderer — main orchestrator.
35
- *
36
- * Pipeline:
37
- * content (string)
38
- * → parseMarkdown() → allElements (Token[])
39
- * → processAndRenderElements() → React tree
40
- *
41
- * Note: Tailwind CDN injection is NOT handled here.
42
- * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
4
+ * Generic CSSProperties framework-agnostic equivalent of React.CSSProperties.
5
+ * Used for inline styles on tokens (e.g. images).
43
6
  */
44
- declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
45
-
7
+ type CSSProperties = Record<string, string | number>;
46
8
  interface HeaderToken {
47
9
  type: 'header';
48
10
  level: number;
@@ -85,7 +47,7 @@ interface ImageToken {
85
47
  type: 'image';
86
48
  alt: string;
87
49
  src: string;
88
- style: React.CSSProperties;
50
+ style: CSSProperties;
89
51
  }
90
52
  interface TableToken {
91
53
  type: 'table';
@@ -108,41 +70,96 @@ interface TocToken {
108
70
  type: 'toc';
109
71
  }
110
72
  type Token = HeaderToken | ParagraphToken | CodeblockToken | DirectiveToken | HtmlToken | HtmlBlockToken | ImageToken | TableToken | ListToken | BlockquoteToken | HrToken | TocToken;
111
- interface RenderContext {
112
- modals: Record<string, boolean>;
113
- setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
114
- articleClass: string;
115
- allElements: Token[];
116
- parseMarkdown: (md: string) => Token[];
117
- renderElement: (element: Token, index: number, depth?: number) => React.ReactNode;
118
- renderInline: (text: string) => React.ReactNode;
119
- processAndRenderElements: (elements: Token[], depth?: number) => React.ReactNode[];
120
- }
121
- type DirectiveComponent = React.FC<DirectiveComponentProps>;
122
- interface DirectiveComponentProps {
123
- /** The directive type string, e.g. 'card', 'note', 'modal' */
124
- directiveType: string;
125
- /** Parsed key="value" attributes from the {props} block */
126
- props: Record<string, string>;
127
- /** Named slots → raw content strings (to be parsed recursively) */
128
- slots: Record<string, string>;
129
- /** Convenience: render a named slot as parsed markdown */
130
- renderSlot: (name: string) => React.ReactNode;
131
- /** Full render context access */
132
- context: RenderContext;
133
- /** Position index in the parent element list */
134
- index: string | number;
135
- /** Full parsed AST */
136
- allElements: Token[];
137
- /** Extra flags from the orchestrator */
138
- options?: Record<string, any>;
139
- }
140
73
 
141
74
  /**
142
- * V2 Markdown Parser — line-by-line state machine.
75
+ * V2 Markdown Parser — line-by-line state machine (framework-agnostic).
143
76
  */
144
77
  declare function parseMarkdown(markdown: string): Token[];
145
78
 
79
+ /**
80
+ * Parse an inline CSS string (e.g. "color: red; padding: 1rem") into a CSSProperties object.
81
+ */
82
+ declare function parseCssString(cssText: string): CSSProperties;
83
+ /**
84
+ * Generate a URL-safe slug from text (NFD decomposition, strip accents, lowercase, hyphenate).
85
+ */
86
+ declare function generateId(text: string): string;
87
+ /**
88
+ * Smooth-scroll to an element by its ID.
89
+ */
90
+ declare function scrollToId(id: string): void;
91
+ /**
92
+ * Parse attribute suffix like `##{.my-class #my-id}` from a text line.
93
+ * Returns the cleaned text, extracted classes, and id.
94
+ */
95
+ declare function extractAttributes(text: string): {
96
+ text: string;
97
+ classes: string;
98
+ id: string;
99
+ };
100
+ declare function resetScopeCounter(): void;
101
+ /**
102
+ * Generate a unique scope ID for CSS isolation.
103
+ */
104
+ declare function generateScopeId(): string;
105
+ /**
106
+ * Parse props from a `{key="value" key2="value2"}` string.
107
+ * Also supports `.className` shorthand → adds to `class` prop.
108
+ * Also supports `#id` shorthand → adds to `id` prop.
109
+ */
110
+ declare function parseProps(propsString: string): Record<string, string>;
111
+ /**
112
+ * Parse raw HTML attributes string (e.g. `class="..." style="..." data-foo="..."`)
113
+ * into a plain props object.
114
+ *
115
+ * NOTE: This does NOT rename `class` → `className`. Framework adapters
116
+ * (React, Vue, etc.) should handle their own attribute name mapping.
117
+ */
118
+ declare function parseHtmlAttrs(attrsString: string): Record<string, any>;
119
+
120
+ interface NRpreviewerProps {
121
+ /** Markdown string to render */
122
+ content?: string;
123
+ /** Raw HTML string to render (used when content is not provided) */
124
+ html?: string;
125
+ /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
126
+ tailwindCDN?: boolean;
127
+ /** Additional CSS class on the wrapper element */
128
+ className?: string;
129
+ /** Inline styles on the wrapper element */
130
+ style?: React.CSSProperties;
131
+ }
132
+ /**
133
+ * NRpreviewer — drop-in markdown/HTML preview component.
134
+ *
135
+ * @example
136
+ * ```tsx
137
+ * import { NRpreviewer } from '@noirmd/previewer';
138
+ * import '@noirmd/previewer/markdown.css';
139
+ *
140
+ * <NRpreviewer content="# Hello **world**" />
141
+ * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
142
+ * <NRpreviewer html="<h1>Raw HTML</h1>" />
143
+ * ```
144
+ */
145
+ declare const NRpreviewer: React.FC<NRpreviewerProps>;
146
+
147
+ interface CustomMarkdownRendererProps {
148
+ content: string;
149
+ }
150
+ /**
151
+ * V2 CustomMarkdownRenderer — main orchestrator.
152
+ *
153
+ * Pipeline:
154
+ * content (string)
155
+ * → parseMarkdown() → allElements (Token[])
156
+ * → processAndRenderElements() → React tree
157
+ *
158
+ * Note: Tailwind CDN injection is NOT handled here.
159
+ * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
160
+ */
161
+ declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
162
+
146
163
  /**
147
164
  * Extract all header tokens from an AST for TOC generation.
148
165
  */
@@ -216,4 +233,34 @@ declare function scanTailwindCDN(): void;
216
233
  */
217
234
  declare function preloadTailwindCDN(): void;
218
235
 
219
- export { Admonition, CodeBlock, CustomMarkdownRenderer, Details, type DirectiveComponent, type DirectiveComponentProps, IconRenderer, Modal, NRpreviewer, type NRpreviewerProps, type RenderContext, type Token, extractHeaders, parseMarkdown, preloadTailwindCDN, scanTailwindCDN, useDebounce, useLazyTailwindCDN };
236
+ interface RenderContext {
237
+ modals: Record<string, boolean>;
238
+ setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
239
+ articleClass: string;
240
+ allElements: Token[];
241
+ 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' */
249
+ directiveType: string;
250
+ /** Parsed key="value" attributes from the {props} block */
251
+ props: Record<string, string>;
252
+ /** Named slots → raw content strings (to be parsed recursively) */
253
+ 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;
260
+ /** Full parsed AST */
261
+ allElements: Token[];
262
+ /** Extra flags from the orchestrator */
263
+ options?: Record<string, any>;
264
+ }
265
+
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 };
package/dist/index.d.ts CHANGED
@@ -1,48 +1,10 @@
1
1
  import React from 'react';
2
2
 
3
- interface NRpreviewerProps {
4
- /** Markdown string to render */
5
- content?: string;
6
- /** Raw HTML string to render (used when content is not provided) */
7
- html?: string;
8
- /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
9
- tailwindCDN?: boolean;
10
- /** Additional CSS class on the wrapper element */
11
- className?: string;
12
- /** Inline styles on the wrapper element */
13
- style?: React.CSSProperties;
14
- }
15
3
  /**
16
- * NRpreviewerdrop-in markdown/HTML preview component.
17
- *
18
- * @example
19
- * ```tsx
20
- * import { NRpreviewer } from '@noirmd/previewer';
21
- * import '@noirmd/previewer/markdown.css';
22
- *
23
- * <NRpreviewer content="# Hello **world**" />
24
- * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
25
- * <NRpreviewer html="<h1>Raw HTML</h1>" />
26
- * ```
27
- */
28
- declare const NRpreviewer: React.FC<NRpreviewerProps>;
29
-
30
- interface CustomMarkdownRendererProps {
31
- content: string;
32
- }
33
- /**
34
- * V2 CustomMarkdownRenderer — main orchestrator.
35
- *
36
- * Pipeline:
37
- * content (string)
38
- * → parseMarkdown() → allElements (Token[])
39
- * → processAndRenderElements() → React tree
40
- *
41
- * Note: Tailwind CDN injection is NOT handled here.
42
- * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
4
+ * Generic CSSProperties framework-agnostic equivalent of React.CSSProperties.
5
+ * Used for inline styles on tokens (e.g. images).
43
6
  */
44
- declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
45
-
7
+ type CSSProperties = Record<string, string | number>;
46
8
  interface HeaderToken {
47
9
  type: 'header';
48
10
  level: number;
@@ -85,7 +47,7 @@ interface ImageToken {
85
47
  type: 'image';
86
48
  alt: string;
87
49
  src: string;
88
- style: React.CSSProperties;
50
+ style: CSSProperties;
89
51
  }
90
52
  interface TableToken {
91
53
  type: 'table';
@@ -108,41 +70,96 @@ interface TocToken {
108
70
  type: 'toc';
109
71
  }
110
72
  type Token = HeaderToken | ParagraphToken | CodeblockToken | DirectiveToken | HtmlToken | HtmlBlockToken | ImageToken | TableToken | ListToken | BlockquoteToken | HrToken | TocToken;
111
- interface RenderContext {
112
- modals: Record<string, boolean>;
113
- setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
114
- articleClass: string;
115
- allElements: Token[];
116
- parseMarkdown: (md: string) => Token[];
117
- renderElement: (element: Token, index: number, depth?: number) => React.ReactNode;
118
- renderInline: (text: string) => React.ReactNode;
119
- processAndRenderElements: (elements: Token[], depth?: number) => React.ReactNode[];
120
- }
121
- type DirectiveComponent = React.FC<DirectiveComponentProps>;
122
- interface DirectiveComponentProps {
123
- /** The directive type string, e.g. 'card', 'note', 'modal' */
124
- directiveType: string;
125
- /** Parsed key="value" attributes from the {props} block */
126
- props: Record<string, string>;
127
- /** Named slots → raw content strings (to be parsed recursively) */
128
- slots: Record<string, string>;
129
- /** Convenience: render a named slot as parsed markdown */
130
- renderSlot: (name: string) => React.ReactNode;
131
- /** Full render context access */
132
- context: RenderContext;
133
- /** Position index in the parent element list */
134
- index: string | number;
135
- /** Full parsed AST */
136
- allElements: Token[];
137
- /** Extra flags from the orchestrator */
138
- options?: Record<string, any>;
139
- }
140
73
 
141
74
  /**
142
- * V2 Markdown Parser — line-by-line state machine.
75
+ * V2 Markdown Parser — line-by-line state machine (framework-agnostic).
143
76
  */
144
77
  declare function parseMarkdown(markdown: string): Token[];
145
78
 
79
+ /**
80
+ * Parse an inline CSS string (e.g. "color: red; padding: 1rem") into a CSSProperties object.
81
+ */
82
+ declare function parseCssString(cssText: string): CSSProperties;
83
+ /**
84
+ * Generate a URL-safe slug from text (NFD decomposition, strip accents, lowercase, hyphenate).
85
+ */
86
+ declare function generateId(text: string): string;
87
+ /**
88
+ * Smooth-scroll to an element by its ID.
89
+ */
90
+ declare function scrollToId(id: string): void;
91
+ /**
92
+ * Parse attribute suffix like `##{.my-class #my-id}` from a text line.
93
+ * Returns the cleaned text, extracted classes, and id.
94
+ */
95
+ declare function extractAttributes(text: string): {
96
+ text: string;
97
+ classes: string;
98
+ id: string;
99
+ };
100
+ declare function resetScopeCounter(): void;
101
+ /**
102
+ * Generate a unique scope ID for CSS isolation.
103
+ */
104
+ declare function generateScopeId(): string;
105
+ /**
106
+ * Parse props from a `{key="value" key2="value2"}` string.
107
+ * Also supports `.className` shorthand → adds to `class` prop.
108
+ * Also supports `#id` shorthand → adds to `id` prop.
109
+ */
110
+ declare function parseProps(propsString: string): Record<string, string>;
111
+ /**
112
+ * Parse raw HTML attributes string (e.g. `class="..." style="..." data-foo="..."`)
113
+ * into a plain props object.
114
+ *
115
+ * NOTE: This does NOT rename `class` → `className`. Framework adapters
116
+ * (React, Vue, etc.) should handle their own attribute name mapping.
117
+ */
118
+ declare function parseHtmlAttrs(attrsString: string): Record<string, any>;
119
+
120
+ interface NRpreviewerProps {
121
+ /** Markdown string to render */
122
+ content?: string;
123
+ /** Raw HTML string to render (used when content is not provided) */
124
+ html?: string;
125
+ /** Inject Tailwind v4 browser CDN at runtime for directive styling. Default: false */
126
+ tailwindCDN?: boolean;
127
+ /** Additional CSS class on the wrapper element */
128
+ className?: string;
129
+ /** Inline styles on the wrapper element */
130
+ style?: React.CSSProperties;
131
+ }
132
+ /**
133
+ * NRpreviewer — drop-in markdown/HTML preview component.
134
+ *
135
+ * @example
136
+ * ```tsx
137
+ * import { NRpreviewer } from '@noirmd/previewer';
138
+ * import '@noirmd/previewer/markdown.css';
139
+ *
140
+ * <NRpreviewer content="# Hello **world**" />
141
+ * <NRpreviewer content=":::note Title\nContent\n:::" tailwindCDN />
142
+ * <NRpreviewer html="<h1>Raw HTML</h1>" />
143
+ * ```
144
+ */
145
+ declare const NRpreviewer: React.FC<NRpreviewerProps>;
146
+
147
+ interface CustomMarkdownRendererProps {
148
+ content: string;
149
+ }
150
+ /**
151
+ * V2 CustomMarkdownRenderer — main orchestrator.
152
+ *
153
+ * Pipeline:
154
+ * content (string)
155
+ * → parseMarkdown() → allElements (Token[])
156
+ * → processAndRenderElements() → React tree
157
+ *
158
+ * Note: Tailwind CDN injection is NOT handled here.
159
+ * Use NRpreviewer (which wraps this) or call useLazyTailwindCDN yourself.
160
+ */
161
+ declare const CustomMarkdownRenderer: React.FC<CustomMarkdownRendererProps>;
162
+
146
163
  /**
147
164
  * Extract all header tokens from an AST for TOC generation.
148
165
  */
@@ -216,4 +233,34 @@ declare function scanTailwindCDN(): void;
216
233
  */
217
234
  declare function preloadTailwindCDN(): void;
218
235
 
219
- export { Admonition, CodeBlock, CustomMarkdownRenderer, Details, type DirectiveComponent, type DirectiveComponentProps, IconRenderer, Modal, NRpreviewer, type NRpreviewerProps, type RenderContext, type Token, extractHeaders, parseMarkdown, preloadTailwindCDN, scanTailwindCDN, useDebounce, useLazyTailwindCDN };
236
+ interface RenderContext {
237
+ modals: Record<string, boolean>;
238
+ setModals: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
239
+ articleClass: string;
240
+ allElements: Token[];
241
+ 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' */
249
+ directiveType: string;
250
+ /** Parsed key="value" attributes from the {props} block */
251
+ props: Record<string, string>;
252
+ /** Named slots → raw content strings (to be parsed recursively) */
253
+ 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;
260
+ /** Full parsed AST */
261
+ allElements: Token[];
262
+ /** Extra flags from the orchestrator */
263
+ options?: Record<string, any>;
264
+ }
265
+
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 };