@ai-react-markdown/core 1.0.0 → 1.0.2

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
@@ -2,65 +2,602 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ComponentType, PropsWithChildren } from 'react';
3
3
  import { Components } from 'react-markdown';
4
4
 
5
+ /**
6
+ * Core type definitions, enums, and default configuration for ai-react-markdown.
7
+ *
8
+ * This module defines the public API surface for configuring the renderer,
9
+ * including extra markdown syntax extensions, display optimization abilities,
10
+ * typography theming, and the shared render state shape.
11
+ *
12
+ * @module defs
13
+ */
14
+
15
+ /**
16
+ * Custom component overrides for the markdown renderer.
17
+ * Alias for `react-markdown`'s `Components` type, re-exported under the
18
+ * library's `AIMarkdown` naming convention so consumers don't need a
19
+ * direct `react-markdown` dependency for type imports.
20
+ */
21
+ type AIMarkdownCustomComponents = Components;
22
+ /**
23
+ * Extra markdown syntax extensions beyond standard GFM.
24
+ * Enable or disable these via {@link AIMarkdownRenderConfig.extraSyntaxSupported}.
25
+ */
5
26
  declare enum AIMarkdownRenderExtraSyntax {
6
- HIGHLIGHT = "HIGHLIGHT",// support ==Highlight==
7
- DEFINITION_LIST = "DEFINITION_LIST",// support Definition List https://michelf.ca/projects/php-markdown/extra/#def-list
27
+ /** `==Highlight==` syntax support. */
28
+ HIGHLIGHT = "HIGHLIGHT",
29
+ /** Definition list syntax. @see https://michelf.ca/projects/php-markdown/extra/#def-list */
30
+ DEFINITION_LIST = "DEFINITION_LIST",
31
+ /** Superscript (`^text^`) and subscript (`~text~`) syntax. */
8
32
  SUBSCRIPT = "SUBSCRIPT"
9
33
  }
34
+ /**
35
+ * Display optimization abilities applied during markdown processing.
36
+ * Enable or disable these via {@link AIMarkdownRenderConfig.displayOptimizeAbilities}.
37
+ */
10
38
  declare enum AIMarkdownRenderDisplayOptimizeAbility {
11
- REMOVE_COMMENTS = "REMOVE_COMMENTS",// remove comments
12
- SMARTYPANTS = "SMARTYPANTS",// make conent more typographic by SmartyPants https://www.npmjs.com/package/smartypants
39
+ /** Strip HTML comments from the content. */
40
+ REMOVE_COMMENTS = "REMOVE_COMMENTS",
41
+ /** Typographic enhancements via SmartyPants (curly quotes, em-dashes, etc.). @see https://www.npmjs.com/package/smartypants */
42
+ SMARTYPANTS = "SMARTYPANTS",
43
+ /** Automatically insert spaces between CJK and half-width characters. */
13
44
  PANGU = "PANGU"
14
45
  }
46
+ /**
47
+ * Configuration object controlling which markdown extensions and
48
+ * display optimizations are active during rendering.
49
+ */
15
50
  interface AIMarkdownRenderConfig {
51
+ /** Extra syntax extensions to enable. */
16
52
  extraSyntaxSupported: AIMarkdownRenderExtraSyntax[];
53
+ /** Display optimization abilities to enable. */
17
54
  displayOptimizeAbilities: AIMarkdownRenderDisplayOptimizeAbility[];
18
55
  }
56
+ /**
57
+ * Sensible default configuration with all extensions and optimizations enabled.
58
+ * Frozen to prevent accidental mutation.
59
+ */
60
+ declare const defaultAIMarkdownRenderConfig: AIMarkdownRenderConfig;
61
+ /**
62
+ * Arbitrary metadata that consumers can pass through a dedicated React context.
63
+ * Custom renderers can access this via the {@link useAIMarkdownMetadata} hook.
64
+ */
19
65
  interface AIMarkdownMetadata extends Record<string, any> {
20
66
  }
67
+ /**
68
+ * Typography variant identifier. Built-in variant is `'default'`;
69
+ * consumers may define additional variants via custom typography components.
70
+ */
21
71
  type AIMarkdownVariant = 'default' | (string & {});
72
+ /**
73
+ * Color scheme identifier. Built-in schemes are `'light'` and `'dark'`;
74
+ * consumers may define additional schemes via custom typography CSS.
75
+ */
22
76
  type AIMarkdownColorScheme = 'light' | 'dark' | (string & {});
77
+ /** Props accepted by a typography wrapper component. */
23
78
  interface AIMarkdownTypographyProps extends PropsWithChildren {
79
+ /** Resolved CSS font-size value (e.g. `'14px'`, `'0.875rem'`). */
24
80
  fontSize: string;
81
+ /** Active typography variant. */
25
82
  variant?: AIMarkdownVariant;
83
+ /** Active color scheme. */
26
84
  colorScheme?: AIMarkdownColorScheme;
27
85
  }
86
+ /** React component type for the typography wrapper. */
28
87
  type AIMarkdownTypographyComponent = ComponentType<AIMarkdownTypographyProps>;
29
- interface AIMarkdownExtraStyleProps extends PropsWithChildren {
88
+ /** Props accepted by an optional extra style wrapper component. */
89
+ interface AIMarkdownExtraStylesProps extends PropsWithChildren {
30
90
  }
31
- type AIMarkdownExtraStyleComponent = ComponentType<AIMarkdownExtraStyleProps>;
32
- interface AIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata> {
91
+ /** React component type for an optional extra style wrapper. */
92
+ type AIMarkdownExtraStylesComponent = ComponentType<AIMarkdownExtraStylesProps>;
93
+ /**
94
+ * Immutable render state exposed to all descendant components via React context.
95
+ * Access this with the {@link useAIMarkdownRenderState} hook.
96
+ *
97
+ * Metadata is provided via a separate context — use {@link useAIMarkdownMetadata} instead.
98
+ *
99
+ * @typeParam TConfig - Render configuration type (defaults to {@link AIMarkdownRenderConfig}).
100
+ */
101
+ interface AIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig> {
102
+ /** Whether the content is currently being streamed (e.g. from an LLM). */
33
103
  streaming: boolean;
104
+ /** Resolved CSS font-size value. */
34
105
  fontSize: string;
106
+ /** Active typography variant. */
107
+ variant: AIMarkdownVariant;
108
+ /** Active color scheme. */
109
+ colorScheme: AIMarkdownColorScheme;
110
+ /** Active render configuration. */
35
111
  config: TConfig;
36
- metadata?: TMetadata;
37
112
  }
38
113
 
39
- type DeepPartial<T> = {
40
- [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
114
+ // Sourced from type-fest v5.4.4
115
+ // https://github.com/sindresorhus/type-fest
116
+ // SPDX-License-Identifier: (MIT OR CC0-1.0)
117
+ // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
118
+
119
+ /**
120
+ Returns a boolean for whether the given type is `never`.
121
+
122
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
123
+ @link https://stackoverflow.com/a/53984913/10292952
124
+ @link https://www.zhenghao.io/posts/ts-never
125
+
126
+ Useful in type utilities, such as checking if something does not occur.
127
+
128
+ @example
129
+ ```
130
+ import type {IsNever, And} from 'type-fest';
131
+
132
+ type A = IsNever<never>;
133
+ //=> true
134
+
135
+ type B = IsNever<any>;
136
+ //=> false
137
+
138
+ type C = IsNever<unknown>;
139
+ //=> false
140
+
141
+ type D = IsNever<never[]>;
142
+ //=> false
143
+
144
+ type E = IsNever<object>;
145
+ //=> false
146
+
147
+ type F = IsNever<string>;
148
+ //=> false
149
+ ```
150
+
151
+ @example
152
+ ```
153
+ import type {IsNever} from 'type-fest';
154
+
155
+ type IsTrue<T> = T extends true ? true : false;
156
+
157
+ // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
158
+ type A = IsTrue<never>;
159
+ //=> never
160
+
161
+ // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
162
+ type IsTrueFixed<T> =
163
+ IsNever<T> extends true ? false : T extends true ? true : false;
164
+
165
+ type B = IsTrueFixed<never>;
166
+ //=> false
167
+ ```
168
+
169
+ @category Type Guard
170
+ @category Utilities
171
+ */
172
+ type IsNever<T> = [T] extends [never] ? true : false;
173
+
174
+ // Sourced from type-fest v5.4.4
175
+ // https://github.com/sindresorhus/type-fest
176
+ // SPDX-License-Identifier: (MIT OR CC0-1.0)
177
+ // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
178
+
179
+
180
+
181
+ /**
182
+ Merges user specified options with default options.
183
+
184
+ @example
185
+ ```
186
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
187
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
188
+ type SpecifiedOptions = {leavesOnly: true};
189
+
190
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
191
+ //=> {maxRecursionDepth: 10; leavesOnly: true}
192
+ ```
193
+
194
+ @example
195
+ ```
196
+ // Complains if default values are not provided for optional options
197
+
198
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
199
+ type DefaultPathsOptions = {maxRecursionDepth: 10};
200
+ type SpecifiedOptions = {};
201
+
202
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
203
+ // ~~~~~~~~~~~~~~~~~~~
204
+ // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
205
+ ```
206
+
207
+ @example
208
+ ```
209
+ // Complains if an option's default type does not conform to the expected type
210
+
211
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
212
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
213
+ type SpecifiedOptions = {};
214
+
215
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
216
+ // ~~~~~~~~~~~~~~~~~~~
217
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
218
+ ```
219
+
220
+ @example
221
+ ```
222
+ // Complains if an option's specified type does not conform to the expected type
223
+
224
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
225
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
226
+ type SpecifiedOptions = {leavesOnly: 'yes'};
227
+
228
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
229
+ // ~~~~~~~~~~~~~~~~
230
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
231
+ ```
232
+ */
233
+ type ApplyDefaultOptions<
234
+ Options extends object,
235
+ Defaults extends Simplify<
236
+ Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>
237
+ >,
238
+ SpecifiedOptions extends Options,
239
+ > = If<
240
+ IsAny<SpecifiedOptions>,
241
+ Defaults,
242
+ If<
243
+ IsNever<SpecifiedOptions>,
244
+ Defaults,
245
+ Simplify<
246
+ Merge<
247
+ Defaults,
248
+ {
249
+ [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options>
250
+ ? undefined extends SpecifiedOptions[Key]
251
+ ? never
252
+ : Key
253
+ : Key]: SpecifiedOptions[Key];
254
+ }
255
+ > &
256
+ Required<Options>
257
+ >
258
+ >
259
+ >; // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
260
+
261
+ /**
262
+ Matches any primitive, `void`, `Date`, or `RegExp` value.
263
+ */
264
+ type BuiltIns = Primitive | void | Date | RegExp;
265
+
266
+ /**
267
+ Test if the given function has multiple call signatures.
268
+
269
+ Needed to handle the case of a single call signature with properties.
270
+
271
+ Multiple call signatures cannot currently be supported due to a TypeScript limitation.
272
+ @see https://github.com/microsoft/TypeScript/issues/29732
273
+ */
274
+ type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
275
+ (...arguments_: infer A): unknown;
276
+ (...arguments_: infer B): unknown;
277
+ }
278
+ ? B extends A
279
+ ? A extends B
280
+ ? false
281
+ : true
282
+ : true
283
+ : false;
284
+
285
+ /**
286
+ @see {@link PartialDeep}
287
+ */
288
+ type PartialDeepOptions = {
289
+ /**
290
+ Whether to affect the individual elements of arrays and tuples.
291
+
292
+ @default false
293
+ */
294
+ readonly recurseIntoArrays?: boolean;
295
+
296
+ /**
297
+ Allows `undefined` values in non-tuple arrays.
298
+
299
+ - When set to `true`, elements of non-tuple arrays can be `undefined`.
300
+ - When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
301
+
302
+ @default false
303
+
304
+ @example
305
+ You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
306
+
307
+ ```
308
+ import type {PartialDeep} from 'type-fest';
309
+
310
+ type Settings = {
311
+ languages: string[];
312
+ };
313
+
314
+ declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
315
+
316
+ partialSettings.languages = [undefined]; // OK
317
+ ```
318
+ */
319
+ readonly allowUndefinedInNonTupleArrays?: boolean;
41
320
  };
42
321
 
43
- declare function useAIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata>(): AIMarkdownRenderState<TConfig, TMetadata>;
44
- interface AIMarkdownRenderStateProviderProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata> extends PropsWithChildren {
322
+ type DefaultPartialDeepOptions = {
323
+ recurseIntoArrays: false;
324
+ allowUndefinedInNonTupleArrays: false;
325
+ };
326
+
327
+ /**
328
+ Create a type from another type with all keys and nested keys set to optional.
329
+
330
+ Use-cases:
331
+ - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
332
+ - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
333
+
334
+ @example
335
+ ```
336
+ import type {PartialDeep} from 'type-fest';
337
+
338
+ let settings = {
339
+ textEditor: {
340
+ fontSize: 14,
341
+ fontColor: '#000000',
342
+ fontWeight: 400,
343
+ },
344
+ autocomplete: false,
345
+ autosave: true,
346
+ };
347
+
348
+ const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
349
+ {...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
350
+ );
351
+
352
+ settings = applySavedSettings({textEditor: {fontWeight: 500}});
353
+ ```
354
+
355
+ By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
356
+
357
+ ```
358
+ import type {PartialDeep} from 'type-fest';
359
+
360
+ type Shape = {
361
+ dimensions: [number, number];
362
+ };
363
+
364
+ const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
365
+ dimensions: [], // OK
366
+ };
367
+
368
+ partialShape.dimensions = [15]; // OK
369
+ ```
370
+
371
+ @see {@link PartialDeepOptions}
372
+
373
+ @category Object
374
+ @category Array
375
+ @category Set
376
+ @category Map
377
+ */
378
+ type PartialDeep<T, Options extends PartialDeepOptions = {}> = _PartialDeep<
379
+ T,
380
+ ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>
381
+ >;
382
+
383
+ type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends
384
+ | BuiltIns
385
+ | (new (...arguments_: any[]) => unknown)
386
+ ? T
387
+ : T extends Map<infer KeyType, infer ValueType>
388
+ ? PartialMapDeep<KeyType, ValueType, Options>
389
+ : T extends Set<infer ItemType>
390
+ ? PartialSetDeep<ItemType, Options>
391
+ : T extends ReadonlyMap<infer KeyType, infer ValueType>
392
+ ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
393
+ : T extends ReadonlySet<infer ItemType>
394
+ ? PartialReadonlySetDeep<ItemType, Options>
395
+ : T extends (...arguments_: any[]) => unknown
396
+ ? IsNever<keyof T> extends true
397
+ ? T // For functions with no properties
398
+ : HasMultipleCallSignatures<T> extends true
399
+ ? T
400
+ : ((...arguments_: Parameters<T>) => ReturnType<T>) & PartialObjectDeep<T, Options>
401
+ : T extends object
402
+ ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
403
+ ? Options['recurseIntoArrays'] extends true
404
+ ? ItemType[] extends T // Test for arrays (non-tuples) specifically
405
+ ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
406
+ ? ReadonlyArray<
407
+ _PartialDeep<
408
+ Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined,
409
+ Options
410
+ >
411
+ >
412
+ : Array<
413
+ _PartialDeep<
414
+ Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined,
415
+ Options
416
+ >
417
+ >
418
+ : PartialObjectDeep<T, Options> // Tuples behave properly
419
+ : T // If they don't opt into array testing, just use the original type
420
+ : PartialObjectDeep<T, Options>
421
+ : unknown;
422
+
423
+ /**
424
+ Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
425
+ */
426
+ type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<
427
+ _PartialDeep<KeyType, Options>,
428
+ _PartialDeep<ValueType, Options>
429
+ >;
430
+
431
+ /**
432
+ Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
433
+ */
434
+ type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
435
+
436
+ /**
437
+ Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
438
+ */
439
+ type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<
440
+ _PartialDeep<KeyType, Options>,
441
+ _PartialDeep<ValueType, Options>
442
+ >;
443
+
444
+ /**
445
+ Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
446
+ */
447
+ type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<
448
+ _PartialDeep<T, Options>
449
+ >;
450
+
451
+ /**
452
+ Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
453
+ */
454
+ type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
455
+ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>;
456
+ };
457
+
458
+ /**
459
+ * Access the current {@link AIMarkdownRenderState} from within the `<AIMarkdown>` tree.
460
+ *
461
+ * Must be called inside a component rendered as a descendant of `<AIMarkdown>`.
462
+ * Throws if called outside the provider boundary.
463
+ *
464
+ * @typeParam TConfig - Expected configuration shape (defaults to {@link AIMarkdownRenderConfig}).
465
+ * @returns The current render state (does not include metadata — use {@link useAIMarkdownMetadata} for that).
466
+ *
467
+ * @example
468
+ * ```tsx
469
+ * function CustomCodeBlock({ children }: PropsWithChildren) {
470
+ * const { streaming, config } = useAIMarkdownRenderState();
471
+ * // ...
472
+ * }
473
+ * ```
474
+ */
475
+ declare function useAIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig>(): AIMarkdownRenderState<TConfig>;
476
+ /**
477
+ * Access the current metadata from within the `<AIMarkdown>` tree.
478
+ *
479
+ * Metadata lives in a separate React context so that changes to metadata
480
+ * do not cause re-renders in components that only consume render state
481
+ * (e.g. {@link MarkdownContent}).
482
+ *
483
+ * @typeParam TMetadata - Expected metadata shape (defaults to {@link AIMarkdownMetadata}).
484
+ * @returns The current metadata, or `undefined` if none was provided.
485
+ */
486
+ declare function useAIMarkdownMetadata<TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata>(): TMetadata | undefined;
487
+ /** Props for {@link AIMarkdownRenderStateProvider}. */
488
+ interface AIMarkdownRenderStateProviderProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig> extends PropsWithChildren {
45
489
  streaming: boolean;
46
490
  fontSize: string;
47
- config?: DeepPartial<TConfig>;
491
+ variant: AIMarkdownVariant;
492
+ colorScheme: AIMarkdownColorScheme;
493
+ /**
494
+ * Base default config to merge against. When omitted, falls back to
495
+ * {@link defaultAIMarkdownRenderConfig}. Sub-packages (e.g. mantine) can
496
+ * pass their own extended defaults here.
497
+ */
498
+ defaultConfig?: TConfig;
499
+ /** Partial config that will be deep-merged with the default config. */
500
+ config?: PartialDeep<TConfig>;
501
+ }
502
+ /** Props for {@link AIMarkdownMetadataProvider}. */
503
+ interface AIMarkdownMetadataProviderProps<TMetadata extends AIMarkdownMetadata = AIMarkdownMetadata> extends PropsWithChildren {
48
504
  metadata?: TMetadata;
49
505
  }
50
506
 
507
+ /**
508
+ * Type definitions for the content preprocessor pipeline.
509
+ *
510
+ * @module preprocessors/defs
511
+ */
512
+ /**
513
+ * A synchronous function that transforms raw markdown content before it is
514
+ * passed to the remark/rehype rendering pipeline.
515
+ *
516
+ * Preprocessors run in sequence -- each receives the output of the previous one.
517
+ *
518
+ * @param content - The raw (or partially processed) markdown string.
519
+ * @returns The transformed markdown string.
520
+ *
521
+ * @example
522
+ * ```ts
523
+ * const stripFrontmatter: AIMDContentPreprocessor = (content) =>
524
+ * content.replace(/^---[\s\S]*?---\n/, '');
525
+ * ```
526
+ */
51
527
  type AIMDContentPreprocessor = (content: string) => string;
52
528
 
53
- interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata> extends Omit<AIMarkdownRenderStateProviderProps<TConfig, TRenderData>, 'fontSize'> {
529
+ /**
530
+ * Hook for referential stability of deep-equal values.
531
+ *
532
+ * @module hooks/useStableValue
533
+ */
534
+ /**
535
+ * Returns a referentially stable version of `value`.
536
+ *
537
+ * On each render the new value is deep-compared (via `lodash/isEqual`) against
538
+ * the previous one. If they are structurally equal the *previous* reference is
539
+ * returned, preventing unnecessary re-renders in downstream `useMemo` / `useEffect`
540
+ * consumers that depend on reference equality.
541
+ *
542
+ * @typeParam T - The value type.
543
+ * @param value - The potentially new value to stabilize.
544
+ * @returns The previous reference when deep-equal, otherwise the new value.
545
+ *
546
+ * @example
547
+ * ```tsx
548
+ * const stableConfig = useStableValue(config);
549
+ * // stableConfig keeps the same reference as long as config is deep-equal.
550
+ * ```
551
+ */
552
+ declare function useStableValue<T>(value: T): T;
553
+
554
+ /**
555
+ * Props for the `<AIMarkdown>` component.
556
+ *
557
+ * @typeParam TConfig - Custom render configuration type (extends {@link AIMarkdownRenderConfig}).
558
+ * @typeParam TRenderData - Custom metadata type (extends {@link AIMarkdownMetadata}).
559
+ */
560
+ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata> extends Omit<AIMarkdownRenderStateProviderProps<TConfig>, 'fontSize' | 'variant' | 'colorScheme'>, AIMarkdownMetadataProviderProps<TRenderData> {
561
+ /**
562
+ * Base font size for the rendered output.
563
+ * Accepts a CSS length string (e.g. `'14px'`, `'0.875rem'`) or a number
564
+ * which is treated as pixels. Defaults to `'0.875rem'`.
565
+ */
54
566
  fontSize?: number | string;
567
+ /** Raw markdown content to render. */
55
568
  content: string;
569
+ /**
570
+ * Additional preprocessors to run on the raw markdown before rendering.
571
+ * These run *after* the built-in LaTeX preprocessor.
572
+ */
56
573
  contentPreprocessors?: AIMDContentPreprocessor[];
57
- customComponents?: Components;
58
- typography?: AIMarkdownTypographyComponent;
59
- extraStyle?: AIMarkdownExtraStyleComponent;
574
+ /**
575
+ * Custom `react-markdown` component overrides.
576
+ * Use this to replace the default renderers for specific HTML elements
577
+ * (e.g. code blocks, links, images).
578
+ */
579
+ customComponents?: AIMarkdownCustomComponents;
580
+ /**
581
+ * Typography wrapper component. Receives `fontSize`, `variant`, and `colorScheme`.
582
+ * Defaults to the built-in {@link DefaultTypography}.
583
+ */
584
+ Typography?: AIMarkdownTypographyComponent;
585
+ /**
586
+ * Optional extra style wrapper component rendered between the typography
587
+ * wrapper and the markdown content. Useful for injecting additional
588
+ * CSS scope or theme providers.
589
+ */
590
+ ExtraStyles?: AIMarkdownExtraStylesComponent;
591
+ /** Typography variant name. Defaults to `'default'`. */
60
592
  variant?: AIMarkdownVariant;
593
+ /** Color scheme name. Defaults to `'light'`. */
61
594
  colorScheme?: AIMarkdownColorScheme;
62
595
  }
63
- declare const AIMarkdownComponent: <TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata>({ streaming, content, fontSize, contentPreprocessors, customComponents, config, metadata, typography: Typography, extraStyle: ExtraStyle, variant, colorScheme, }: AIMarkdownProps<TConfig, TRenderData>) => react_jsx_runtime.JSX.Element;
596
+ /**
597
+ * Root component that preprocesses markdown content and renders it through
598
+ * a configurable remark/rehype pipeline wrapped in typography and style layers.
599
+ */
600
+ declare const AIMarkdownComponent: <TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata>({ streaming, content, fontSize, contentPreprocessors, customComponents, defaultConfig, config, metadata, Typography, ExtraStyles, variant, colorScheme, }: AIMarkdownProps<TConfig, TRenderData>) => react_jsx_runtime.JSX.Element;
64
601
  declare const _default: typeof AIMarkdownComponent;
65
602
 
66
- export { type AIMDContentPreprocessor, type AIMarkdownColorScheme, type AIMarkdownExtraStyleComponent, type AIMarkdownExtraStyleProps, type AIMarkdownMetadata, type AIMarkdownProps, type AIMarkdownRenderConfig, AIMarkdownRenderDisplayOptimizeAbility, AIMarkdownRenderExtraSyntax, type AIMarkdownRenderState, type AIMarkdownTypographyComponent, type AIMarkdownTypographyProps, type AIMarkdownVariant, _default as default, useAIMarkdownRenderState };
603
+ export { type AIMDContentPreprocessor, type AIMarkdownColorScheme, type AIMarkdownCustomComponents, type AIMarkdownExtraStylesComponent, type AIMarkdownExtraStylesProps, type AIMarkdownMetadata, type AIMarkdownProps, type AIMarkdownRenderConfig, AIMarkdownRenderDisplayOptimizeAbility, AIMarkdownRenderExtraSyntax, type AIMarkdownRenderState, type AIMarkdownTypographyComponent, type AIMarkdownTypographyProps, type AIMarkdownVariant, type PartialDeep, _default as default, defaultAIMarkdownRenderConfig, useAIMarkdownMetadata, useAIMarkdownRenderState, useStableValue };