@ai-react-markdown/core 1.4.3 → 1.4.5
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/README.md +90 -54
- package/dist/index.cjs +2185 -2080
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -58
- package/dist/index.d.ts +86 -58
- package/dist/index.js +586 -480
- package/dist/index.js.map +1 -1
- package/dist/typography/all.css +34 -29
- package/dist/typography/all.css.map +1 -1
- package/dist/typography/default.css +34 -29
- package/dist/typography/default.css.map +1 -1
- package/package.json +11 -3
package/dist/index.d.cts
CHANGED
|
@@ -183,6 +183,10 @@ interface AIMarkdownTypographyProps extends PropsWithChildren {
|
|
|
183
183
|
* `font-size: var(--aim-font-size-root)` to opt out of `em` compounding
|
|
184
184
|
* when a stable size is needed.
|
|
185
185
|
*
|
|
186
|
+
* The built-in `default` variant consumes this variable: its spacing,
|
|
187
|
+
* font-size, and heading tokens are defined as `calc(var(--aim-font-size-root) * k)`,
|
|
188
|
+
* so the `fontSize` prop proportionally scales every rendered dimension.
|
|
189
|
+
*
|
|
186
190
|
* @example
|
|
187
191
|
* ```tsx
|
|
188
192
|
* const MyTypography: AIMarkdownTypographyComponent = ({ children, fontSize, style }) => (
|
|
@@ -318,6 +322,16 @@ type IsNever<T> = [T] extends [never] ? true : false;
|
|
|
318
322
|
// https://github.com/sindresorhus/type-fest
|
|
319
323
|
// SPDX-License-Identifier: (MIT OR CC0-1.0)
|
|
320
324
|
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
325
|
+
//
|
|
326
|
+
// Vendored verbatim from upstream. The `any[]` spellings in
|
|
327
|
+
// `HasMultipleCallSignatures` and the function-fallback branch are
|
|
328
|
+
// load-bearing for type-fest's variadic-arity matching — replacing them
|
|
329
|
+
// with `unknown[]` would either narrow or widen the inference in a
|
|
330
|
+
// non-equivalent way, and the test suite for those exact helpers lives in
|
|
331
|
+
// type-fest's own repo. Disable the rule at the file scope to mirror
|
|
332
|
+
// upstream while keeping the rest of the package's `no-explicit-any`
|
|
333
|
+
// contract strict.
|
|
334
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
321
335
|
|
|
322
336
|
|
|
323
337
|
|
|
@@ -664,7 +678,7 @@ declare function useAIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig
|
|
|
664
678
|
*
|
|
665
679
|
* Metadata lives in a separate React context so that changes to metadata
|
|
666
680
|
* do not cause re-renders in components that only consume render state
|
|
667
|
-
* (e.g.
|
|
681
|
+
* (e.g. the internal `MarkdownContent` renderer).
|
|
668
682
|
*
|
|
669
683
|
* ### `TMetadata` is a caller-asserted type
|
|
670
684
|
*
|
|
@@ -742,14 +756,16 @@ interface AIMarkdownMetadataProviderProps<TMetadata extends AIMarkdownMetadata =
|
|
|
742
756
|
type AIMDContentPreprocessor = (content: string) => string;
|
|
743
757
|
|
|
744
758
|
/**
|
|
745
|
-
* Builds a `rehype-sanitize` schema by handing the caller a deep clone of
|
|
746
|
-
* library default
|
|
759
|
+
* Builds a `rehype-sanitize` schema by handing the caller a deep clone of
|
|
760
|
+
* the library's internal default schema to mutate or replace.
|
|
747
761
|
*
|
|
748
762
|
* The mutate-and-return pattern matches the ergonomics of Next.js's
|
|
749
763
|
* `webpack(config)` and Express middleware: a callback receives a draft,
|
|
750
764
|
* either modifies it in place (returning nothing) or returns a fresh object
|
|
751
765
|
* to replace it. The library guarantees the draft is a deep clone, so direct
|
|
752
|
-
* mutation never leaks into the
|
|
766
|
+
* mutation never leaks into the singleton — and the singleton itself is not
|
|
767
|
+
* exported, so consumers cannot accidentally hand-roll a schema that drops
|
|
768
|
+
* the library's cross-chunk tag allowlist or KaTeX className additions.
|
|
753
769
|
*
|
|
754
770
|
* @module components/extendSanitizeSchema
|
|
755
771
|
*/
|
|
@@ -792,6 +808,16 @@ type SanitizeSchema = typeof defaultSchema;
|
|
|
792
808
|
* }));
|
|
793
809
|
* ```
|
|
794
810
|
*
|
|
811
|
+
* @example Inspect the library default (e.g. to learn what's already allowed):
|
|
812
|
+
* ```ts
|
|
813
|
+
* // The draft handed to the modifier IS the library default, deep-cloned.
|
|
814
|
+
* // Logging it once at module load surfaces every default field — protocols,
|
|
815
|
+
* // attributes, tagNames, etc. — without ever exposing the singleton itself.
|
|
816
|
+
* extendSanitizeSchema((s) => {
|
|
817
|
+
* console.log('default sanitize schema:', s);
|
|
818
|
+
* });
|
|
819
|
+
* ```
|
|
820
|
+
*
|
|
795
821
|
* @remarks Allowing a protocol on `protocols.href` lets the URL through the
|
|
796
822
|
* SECOND sanitize gate. The FIRST gate (`urlTransform`) must permit the
|
|
797
823
|
* same protocol independently — see the `urlTransform` prop on
|
|
@@ -853,23 +879,6 @@ declare function extendSanitizeSchema(modifier: (draft: SanitizeSchema) => Sanit
|
|
|
853
879
|
*/
|
|
854
880
|
declare function useStableValue<T>(value: T): T;
|
|
855
881
|
|
|
856
|
-
/**
|
|
857
|
-
* Builds the `rehype-sanitize` schema used by {@link MarkdownContent}.
|
|
858
|
-
*
|
|
859
|
-
* Extracted into its own module so the merge logic can be unit-tested in
|
|
860
|
-
* isolation without pulling in React or the full markdown pipeline.
|
|
861
|
-
*
|
|
862
|
-
* @module components/sanitizeSchema
|
|
863
|
-
*/
|
|
864
|
-
|
|
865
|
-
type Schema = typeof defaultSchema;
|
|
866
|
-
/**
|
|
867
|
-
* The full sanitize schema used by the markdown renderer: extends
|
|
868
|
-
* `defaultSchema` to allow `<mark>`, the KaTeX math class names, and the
|
|
869
|
-
* three custom hast tags emitted by cross-chunk coordination handlers.
|
|
870
|
-
*/
|
|
871
|
-
declare const sanitizeSchema: Schema;
|
|
872
|
-
|
|
873
882
|
/**
|
|
874
883
|
* Cross-chunk shared state. Holds per-chunk contributions (refs, defs,
|
|
875
884
|
* linkDefs) keyed by Symbol identity allocated via useId reactId, with
|
|
@@ -920,45 +929,62 @@ interface ChunkData {
|
|
|
920
929
|
ownFootnoteLabels: Set<string>;
|
|
921
930
|
ownLinkLabels: Set<string>;
|
|
922
931
|
}
|
|
932
|
+
/**
|
|
933
|
+
* Public, read-only view of the cross-chunk registry. This is the type
|
|
934
|
+
* surfaced by `useDocumentRegistry` and re-exported from the package
|
|
935
|
+
* barrel. Consumers can:
|
|
936
|
+
*
|
|
937
|
+
* - read the registry's current state (`chunkOrder`, `chunkData`,
|
|
938
|
+
* `labelSet`, `version`)
|
|
939
|
+
* - observe changes (`subscribe`)
|
|
940
|
+
* - run selectors (`globalNumber`, `resolveLinkDef`, …)
|
|
941
|
+
*
|
|
942
|
+
* Mutators — `registerChunk`, `allocateSymbol`, `releaseSymbol`,
|
|
943
|
+
* `contributeLabels`, `contributeChunkData` — are intentionally off this
|
|
944
|
+
* interface. Driving the registry directly is reserved for internal
|
|
945
|
+
* coordinators (the package's own `MarkdownContent` renderer) and tests,
|
|
946
|
+
* which import the wider `RegistryInternal` type from this module.
|
|
947
|
+
* `RegistryInternal` is exported here but NOT re-exported from the package
|
|
948
|
+
* barrel — keeping mutators off the public surface prevents a misbehaving
|
|
949
|
+
* consumer-component from corrupting refcounts, skipping version bumps, or
|
|
950
|
+
* otherwise breaking the invariants the renderer relies on.
|
|
951
|
+
*/
|
|
923
952
|
interface Registry {
|
|
924
|
-
/** Chunk mount-order Symbol list. **Read-only
|
|
925
|
-
*
|
|
926
|
-
*
|
|
927
|
-
* `allocateSymbol` / `releaseSymbol` / `registerChunk` API instead. */
|
|
953
|
+
/** Chunk mount-order Symbol list. **Read-only.** Direct mutation
|
|
954
|
+
* (`.push`, `.splice`, index assignment) corrupts footnote numbering,
|
|
955
|
+
* "last chunk" detection, and eviction. */
|
|
928
956
|
readonly chunkOrder: readonly symbol[];
|
|
929
|
-
/** Chunk Symbol → contribution payload. **Read-only
|
|
930
|
-
*
|
|
931
|
-
* publish; direct `.set` / `.delete` bypasses version bumps and
|
|
932
|
-
* subscriber wake-ups. */
|
|
957
|
+
/** Chunk Symbol → contribution payload. **Read-only.** Direct `.set` /
|
|
958
|
+
* `.delete` bypasses version bumps and subscriber wake-ups. */
|
|
933
959
|
readonly chunkData: ReadonlyMap<symbol, ChunkData>;
|
|
934
960
|
/** Union of own-def labels across all chunks. PASS 0.5 phantom-injection
|
|
935
|
-
* driver. **Read-only
|
|
936
|
-
*
|
|
961
|
+
* driver. **Read-only.** The registry derives this from per-chunk
|
|
962
|
+
* contributions; direct mutation breaks the derivation. */
|
|
937
963
|
readonly labelSet: {
|
|
938
964
|
readonly footnoteLabels: ReadonlySet<string>;
|
|
939
965
|
readonly linkLabels: ReadonlySet<string>;
|
|
940
966
|
};
|
|
941
|
-
/** Monotonic version counter bumped by every mutation. **Read-only
|
|
942
|
-
*
|
|
967
|
+
/** Monotonic version counter bumped by every mutation. **Read-only** —
|
|
968
|
+
* consumers should observe via `subscribe`, not by writing. */
|
|
943
969
|
readonly version: number;
|
|
944
|
-
/** Allocate (or reuse, for Strict Mode remount) the chunk Symbol for
|
|
945
|
-
* `reactId` AND publish this chunk's own def labels (footnotes + links)
|
|
946
|
-
* in one call. Canonical pair API used by `MarkdownContent`'s allocate
|
|
947
|
-
* effect — combining the two reduces the pair to a single registry
|
|
948
|
-
* version step, which downstream consumers see as one wake-up rather
|
|
949
|
-
* than two (the second was already coalesced by microtask, but this
|
|
950
|
-
* keeps the version monotonic-by-1-per-mount which makes debugging
|
|
951
|
-
* easier). The granular `allocateSymbol` / `contributeLabels` methods
|
|
952
|
-
* remain available for tests that need to exercise each step. */
|
|
953
|
-
registerChunk(reactId: string, footnotes: Set<string>, links: Set<string>): symbol;
|
|
954
|
-
allocateSymbol(reactId: string): symbol;
|
|
955
|
-
releaseSymbol(reactId: string): void;
|
|
956
|
-
contributeLabels(symbol: symbol, footnotes: Set<string>, links: Set<string>): void;
|
|
957
|
-
contributeChunkData(symbol: symbol, data: ChunkData): void;
|
|
958
970
|
subscribe(cb: () => void): () => void;
|
|
959
971
|
canonicalFootnoteFor(label: string): symbol | null;
|
|
960
972
|
canonicalLinkFor(label: string): symbol | null;
|
|
961
973
|
globalNumber(label: string): number | null;
|
|
974
|
+
/**
|
|
975
|
+
* Resolve a cross-chunk link definition by label. The returned `url` is the
|
|
976
|
+
* value the contributing chunk's `urlTransform` produced — cross-chunk
|
|
977
|
+
* link/image references run a second, per-attribute sanitization pass
|
|
978
|
+
* (`urlTransform` + `sanitizeSchema.protocols`) at render time, so the
|
|
979
|
+
* placeholder components themselves never trust this value blindly.
|
|
980
|
+
*
|
|
981
|
+
* Consumers reading `def.url` directly (custom backlink panels, analytics,
|
|
982
|
+
* dev tooling) receive a defense-in-depth-filtered string but should still
|
|
983
|
+
* pipe it through their own `urlTransform` if they intend to render it as
|
|
984
|
+
* an `href`/`src` — the contribute-time pass uses the `'href'` key and a
|
|
985
|
+
* synthetic `<a>` node, so a key-aware policy may treat the value
|
|
986
|
+
* differently when used as an `<img src>`.
|
|
987
|
+
*/
|
|
962
988
|
resolveLinkDef(label: string): LinkDef | null;
|
|
963
989
|
getRefsForLabel(label: string): number;
|
|
964
990
|
/** Map a chunk-local footnote-ref occurrence index (1-based, as emitted by
|
|
@@ -1110,8 +1136,8 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1110
1136
|
*
|
|
1111
1137
|
* Allowing a protocol here is necessary but **not sufficient** to render
|
|
1112
1138
|
* a link — the second gate (`rehype-sanitize`) also enforces its own
|
|
1113
|
-
* protocol allowlist. See the
|
|
1114
|
-
*
|
|
1139
|
+
* protocol allowlist. See the `sanitizeSchema` prop on this component
|
|
1140
|
+
* and the {@link extendSanitizeSchema} helper for the second gate.
|
|
1115
1141
|
*
|
|
1116
1142
|
* **API stability**: the `UrlTransform` type tracks the upstream
|
|
1117
1143
|
* `react-markdown` shape and may change with its major versions.
|
|
@@ -1119,10 +1145,11 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1119
1145
|
urlTransform?: UrlTransform | null;
|
|
1120
1146
|
/**
|
|
1121
1147
|
* Override the `rehype-sanitize` schema applied to the rendered output.
|
|
1122
|
-
* The library default
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1125
|
-
* `footnote-sup`).
|
|
1148
|
+
* The library default extends `rehype-sanitize`'s own `defaultSchema`
|
|
1149
|
+
* with the `<mark>` tag, KaTeX class names, and the cross-chunk
|
|
1150
|
+
* coordination tags (`cross-chunk-link`, `cross-chunk-image`,
|
|
1151
|
+
* `footnote-sup`). The default is not exported as a value — see
|
|
1152
|
+
* {@link extendSanitizeSchema} for how to inspect or extend it safely.
|
|
1126
1153
|
*
|
|
1127
1154
|
* **Recommended pattern**: build the schema with {@link extendSanitizeSchema}
|
|
1128
1155
|
* (mutate-and-return form) so those library additions stay intact, and
|
|
@@ -1147,10 +1174,11 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1147
1174
|
* lose its placeholders. Prefer the helper unless you have a specific
|
|
1148
1175
|
* reason to opt out.
|
|
1149
1176
|
*
|
|
1150
|
-
* **Reference stability matters.**
|
|
1151
|
-
*
|
|
1152
|
-
* `useStableValue` deep-equal pass, but the safer pattern is
|
|
1153
|
-
* module-scope. Development builds will `console.warn` on identity
|
|
1177
|
+
* **Reference stability matters.** An inline call
|
|
1178
|
+
* (`sanitizeSchema={extendSanitizeSchema((s) => { … })}`) is mitigated by
|
|
1179
|
+
* an internal `useStableValue` deep-equal pass, but the safer pattern is
|
|
1180
|
+
* still module-scope. Development builds will `console.warn` on identity
|
|
1181
|
+
* flips.
|
|
1154
1182
|
*
|
|
1155
1183
|
* **API stability**: the `SanitizeSchema` type tracks the upstream
|
|
1156
1184
|
* `rehype-sanitize` shape and may change with its major versions.
|
|
@@ -1164,4 +1192,4 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1164
1192
|
declare const AIMarkdownComponent: <TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata>({ streaming, content, fontSize, contentPreprocessors, customComponents, defaultConfig, config, metadata, Typography, ExtraStyles, variant, colorScheme, documentId, urlTransform, sanitizeSchema, }: AIMarkdownProps<TConfig, TRenderData>) => react_jsx_runtime.JSX.Element;
|
|
1165
1193
|
declare const _default: typeof AIMarkdownComponent;
|
|
1166
1194
|
|
|
1167
|
-
export { type AIMDContentPreprocessor, type AIMarkdownColorScheme, type AIMarkdownCustomComponents, AIMarkdownDocuments, type AIMarkdownDocumentsProps, type AIMarkdownExtraStylesComponent, type AIMarkdownExtraStylesProps, type AIMarkdownMetadata, type AIMarkdownProps, type AIMarkdownRenderConfig, AIMarkdownRenderDisplayOptimizeAbility, AIMarkdownRenderExtraSyntax, type AIMarkdownRenderState, type AIMarkdownTypographyComponent, type AIMarkdownTypographyProps, type AIMarkdownVariant, type ChunkData, type FootnoteDef, type LinkDef, type PartialDeep, type RefKind, type RefRecord, type Registry, type SanitizeSchema, type UrlTransform, _default as default, defaultAIMarkdownRenderConfig, defaultUrlTransform, extendSanitizeSchema,
|
|
1195
|
+
export { type AIMDContentPreprocessor, type AIMarkdownColorScheme, type AIMarkdownCustomComponents, AIMarkdownDocuments, type AIMarkdownDocumentsProps, type AIMarkdownExtraStylesComponent, type AIMarkdownExtraStylesProps, type AIMarkdownMetadata, type AIMarkdownProps, type AIMarkdownRenderConfig, AIMarkdownRenderDisplayOptimizeAbility, AIMarkdownRenderExtraSyntax, type AIMarkdownRenderState, type AIMarkdownTypographyComponent, type AIMarkdownTypographyProps, type AIMarkdownVariant, type ChunkData, type FootnoteDef, type LinkDef, type PartialDeep, type RefKind, type RefRecord, type Registry, type SanitizeSchema, type UrlTransform, _default as default, defaultAIMarkdownRenderConfig, defaultUrlTransform, extendSanitizeSchema, useAIMarkdownMetadata, useAIMarkdownRenderState, useDocumentRegistry, useStableValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,10 @@ interface AIMarkdownTypographyProps extends PropsWithChildren {
|
|
|
183
183
|
* `font-size: var(--aim-font-size-root)` to opt out of `em` compounding
|
|
184
184
|
* when a stable size is needed.
|
|
185
185
|
*
|
|
186
|
+
* The built-in `default` variant consumes this variable: its spacing,
|
|
187
|
+
* font-size, and heading tokens are defined as `calc(var(--aim-font-size-root) * k)`,
|
|
188
|
+
* so the `fontSize` prop proportionally scales every rendered dimension.
|
|
189
|
+
*
|
|
186
190
|
* @example
|
|
187
191
|
* ```tsx
|
|
188
192
|
* const MyTypography: AIMarkdownTypographyComponent = ({ children, fontSize, style }) => (
|
|
@@ -318,6 +322,16 @@ type IsNever<T> = [T] extends [never] ? true : false;
|
|
|
318
322
|
// https://github.com/sindresorhus/type-fest
|
|
319
323
|
// SPDX-License-Identifier: (MIT OR CC0-1.0)
|
|
320
324
|
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
325
|
+
//
|
|
326
|
+
// Vendored verbatim from upstream. The `any[]` spellings in
|
|
327
|
+
// `HasMultipleCallSignatures` and the function-fallback branch are
|
|
328
|
+
// load-bearing for type-fest's variadic-arity matching — replacing them
|
|
329
|
+
// with `unknown[]` would either narrow or widen the inference in a
|
|
330
|
+
// non-equivalent way, and the test suite for those exact helpers lives in
|
|
331
|
+
// type-fest's own repo. Disable the rule at the file scope to mirror
|
|
332
|
+
// upstream while keeping the rest of the package's `no-explicit-any`
|
|
333
|
+
// contract strict.
|
|
334
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
321
335
|
|
|
322
336
|
|
|
323
337
|
|
|
@@ -664,7 +678,7 @@ declare function useAIMarkdownRenderState<TConfig extends AIMarkdownRenderConfig
|
|
|
664
678
|
*
|
|
665
679
|
* Metadata lives in a separate React context so that changes to metadata
|
|
666
680
|
* do not cause re-renders in components that only consume render state
|
|
667
|
-
* (e.g.
|
|
681
|
+
* (e.g. the internal `MarkdownContent` renderer).
|
|
668
682
|
*
|
|
669
683
|
* ### `TMetadata` is a caller-asserted type
|
|
670
684
|
*
|
|
@@ -742,14 +756,16 @@ interface AIMarkdownMetadataProviderProps<TMetadata extends AIMarkdownMetadata =
|
|
|
742
756
|
type AIMDContentPreprocessor = (content: string) => string;
|
|
743
757
|
|
|
744
758
|
/**
|
|
745
|
-
* Builds a `rehype-sanitize` schema by handing the caller a deep clone of
|
|
746
|
-
* library default
|
|
759
|
+
* Builds a `rehype-sanitize` schema by handing the caller a deep clone of
|
|
760
|
+
* the library's internal default schema to mutate or replace.
|
|
747
761
|
*
|
|
748
762
|
* The mutate-and-return pattern matches the ergonomics of Next.js's
|
|
749
763
|
* `webpack(config)` and Express middleware: a callback receives a draft,
|
|
750
764
|
* either modifies it in place (returning nothing) or returns a fresh object
|
|
751
765
|
* to replace it. The library guarantees the draft is a deep clone, so direct
|
|
752
|
-
* mutation never leaks into the
|
|
766
|
+
* mutation never leaks into the singleton — and the singleton itself is not
|
|
767
|
+
* exported, so consumers cannot accidentally hand-roll a schema that drops
|
|
768
|
+
* the library's cross-chunk tag allowlist or KaTeX className additions.
|
|
753
769
|
*
|
|
754
770
|
* @module components/extendSanitizeSchema
|
|
755
771
|
*/
|
|
@@ -792,6 +808,16 @@ type SanitizeSchema = typeof defaultSchema;
|
|
|
792
808
|
* }));
|
|
793
809
|
* ```
|
|
794
810
|
*
|
|
811
|
+
* @example Inspect the library default (e.g. to learn what's already allowed):
|
|
812
|
+
* ```ts
|
|
813
|
+
* // The draft handed to the modifier IS the library default, deep-cloned.
|
|
814
|
+
* // Logging it once at module load surfaces every default field — protocols,
|
|
815
|
+
* // attributes, tagNames, etc. — without ever exposing the singleton itself.
|
|
816
|
+
* extendSanitizeSchema((s) => {
|
|
817
|
+
* console.log('default sanitize schema:', s);
|
|
818
|
+
* });
|
|
819
|
+
* ```
|
|
820
|
+
*
|
|
795
821
|
* @remarks Allowing a protocol on `protocols.href` lets the URL through the
|
|
796
822
|
* SECOND sanitize gate. The FIRST gate (`urlTransform`) must permit the
|
|
797
823
|
* same protocol independently — see the `urlTransform` prop on
|
|
@@ -853,23 +879,6 @@ declare function extendSanitizeSchema(modifier: (draft: SanitizeSchema) => Sanit
|
|
|
853
879
|
*/
|
|
854
880
|
declare function useStableValue<T>(value: T): T;
|
|
855
881
|
|
|
856
|
-
/**
|
|
857
|
-
* Builds the `rehype-sanitize` schema used by {@link MarkdownContent}.
|
|
858
|
-
*
|
|
859
|
-
* Extracted into its own module so the merge logic can be unit-tested in
|
|
860
|
-
* isolation without pulling in React or the full markdown pipeline.
|
|
861
|
-
*
|
|
862
|
-
* @module components/sanitizeSchema
|
|
863
|
-
*/
|
|
864
|
-
|
|
865
|
-
type Schema = typeof defaultSchema;
|
|
866
|
-
/**
|
|
867
|
-
* The full sanitize schema used by the markdown renderer: extends
|
|
868
|
-
* `defaultSchema` to allow `<mark>`, the KaTeX math class names, and the
|
|
869
|
-
* three custom hast tags emitted by cross-chunk coordination handlers.
|
|
870
|
-
*/
|
|
871
|
-
declare const sanitizeSchema: Schema;
|
|
872
|
-
|
|
873
882
|
/**
|
|
874
883
|
* Cross-chunk shared state. Holds per-chunk contributions (refs, defs,
|
|
875
884
|
* linkDefs) keyed by Symbol identity allocated via useId reactId, with
|
|
@@ -920,45 +929,62 @@ interface ChunkData {
|
|
|
920
929
|
ownFootnoteLabels: Set<string>;
|
|
921
930
|
ownLinkLabels: Set<string>;
|
|
922
931
|
}
|
|
932
|
+
/**
|
|
933
|
+
* Public, read-only view of the cross-chunk registry. This is the type
|
|
934
|
+
* surfaced by `useDocumentRegistry` and re-exported from the package
|
|
935
|
+
* barrel. Consumers can:
|
|
936
|
+
*
|
|
937
|
+
* - read the registry's current state (`chunkOrder`, `chunkData`,
|
|
938
|
+
* `labelSet`, `version`)
|
|
939
|
+
* - observe changes (`subscribe`)
|
|
940
|
+
* - run selectors (`globalNumber`, `resolveLinkDef`, …)
|
|
941
|
+
*
|
|
942
|
+
* Mutators — `registerChunk`, `allocateSymbol`, `releaseSymbol`,
|
|
943
|
+
* `contributeLabels`, `contributeChunkData` — are intentionally off this
|
|
944
|
+
* interface. Driving the registry directly is reserved for internal
|
|
945
|
+
* coordinators (the package's own `MarkdownContent` renderer) and tests,
|
|
946
|
+
* which import the wider `RegistryInternal` type from this module.
|
|
947
|
+
* `RegistryInternal` is exported here but NOT re-exported from the package
|
|
948
|
+
* barrel — keeping mutators off the public surface prevents a misbehaving
|
|
949
|
+
* consumer-component from corrupting refcounts, skipping version bumps, or
|
|
950
|
+
* otherwise breaking the invariants the renderer relies on.
|
|
951
|
+
*/
|
|
923
952
|
interface Registry {
|
|
924
|
-
/** Chunk mount-order Symbol list. **Read-only
|
|
925
|
-
*
|
|
926
|
-
*
|
|
927
|
-
* `allocateSymbol` / `releaseSymbol` / `registerChunk` API instead. */
|
|
953
|
+
/** Chunk mount-order Symbol list. **Read-only.** Direct mutation
|
|
954
|
+
* (`.push`, `.splice`, index assignment) corrupts footnote numbering,
|
|
955
|
+
* "last chunk" detection, and eviction. */
|
|
928
956
|
readonly chunkOrder: readonly symbol[];
|
|
929
|
-
/** Chunk Symbol → contribution payload. **Read-only
|
|
930
|
-
*
|
|
931
|
-
* publish; direct `.set` / `.delete` bypasses version bumps and
|
|
932
|
-
* subscriber wake-ups. */
|
|
957
|
+
/** Chunk Symbol → contribution payload. **Read-only.** Direct `.set` /
|
|
958
|
+
* `.delete` bypasses version bumps and subscriber wake-ups. */
|
|
933
959
|
readonly chunkData: ReadonlyMap<symbol, ChunkData>;
|
|
934
960
|
/** Union of own-def labels across all chunks. PASS 0.5 phantom-injection
|
|
935
|
-
* driver. **Read-only
|
|
936
|
-
*
|
|
961
|
+
* driver. **Read-only.** The registry derives this from per-chunk
|
|
962
|
+
* contributions; direct mutation breaks the derivation. */
|
|
937
963
|
readonly labelSet: {
|
|
938
964
|
readonly footnoteLabels: ReadonlySet<string>;
|
|
939
965
|
readonly linkLabels: ReadonlySet<string>;
|
|
940
966
|
};
|
|
941
|
-
/** Monotonic version counter bumped by every mutation. **Read-only
|
|
942
|
-
*
|
|
967
|
+
/** Monotonic version counter bumped by every mutation. **Read-only** —
|
|
968
|
+
* consumers should observe via `subscribe`, not by writing. */
|
|
943
969
|
readonly version: number;
|
|
944
|
-
/** Allocate (or reuse, for Strict Mode remount) the chunk Symbol for
|
|
945
|
-
* `reactId` AND publish this chunk's own def labels (footnotes + links)
|
|
946
|
-
* in one call. Canonical pair API used by `MarkdownContent`'s allocate
|
|
947
|
-
* effect — combining the two reduces the pair to a single registry
|
|
948
|
-
* version step, which downstream consumers see as one wake-up rather
|
|
949
|
-
* than two (the second was already coalesced by microtask, but this
|
|
950
|
-
* keeps the version monotonic-by-1-per-mount which makes debugging
|
|
951
|
-
* easier). The granular `allocateSymbol` / `contributeLabels` methods
|
|
952
|
-
* remain available for tests that need to exercise each step. */
|
|
953
|
-
registerChunk(reactId: string, footnotes: Set<string>, links: Set<string>): symbol;
|
|
954
|
-
allocateSymbol(reactId: string): symbol;
|
|
955
|
-
releaseSymbol(reactId: string): void;
|
|
956
|
-
contributeLabels(symbol: symbol, footnotes: Set<string>, links: Set<string>): void;
|
|
957
|
-
contributeChunkData(symbol: symbol, data: ChunkData): void;
|
|
958
970
|
subscribe(cb: () => void): () => void;
|
|
959
971
|
canonicalFootnoteFor(label: string): symbol | null;
|
|
960
972
|
canonicalLinkFor(label: string): symbol | null;
|
|
961
973
|
globalNumber(label: string): number | null;
|
|
974
|
+
/**
|
|
975
|
+
* Resolve a cross-chunk link definition by label. The returned `url` is the
|
|
976
|
+
* value the contributing chunk's `urlTransform` produced — cross-chunk
|
|
977
|
+
* link/image references run a second, per-attribute sanitization pass
|
|
978
|
+
* (`urlTransform` + `sanitizeSchema.protocols`) at render time, so the
|
|
979
|
+
* placeholder components themselves never trust this value blindly.
|
|
980
|
+
*
|
|
981
|
+
* Consumers reading `def.url` directly (custom backlink panels, analytics,
|
|
982
|
+
* dev tooling) receive a defense-in-depth-filtered string but should still
|
|
983
|
+
* pipe it through their own `urlTransform` if they intend to render it as
|
|
984
|
+
* an `href`/`src` — the contribute-time pass uses the `'href'` key and a
|
|
985
|
+
* synthetic `<a>` node, so a key-aware policy may treat the value
|
|
986
|
+
* differently when used as an `<img src>`.
|
|
987
|
+
*/
|
|
962
988
|
resolveLinkDef(label: string): LinkDef | null;
|
|
963
989
|
getRefsForLabel(label: string): number;
|
|
964
990
|
/** Map a chunk-local footnote-ref occurrence index (1-based, as emitted by
|
|
@@ -1110,8 +1136,8 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1110
1136
|
*
|
|
1111
1137
|
* Allowing a protocol here is necessary but **not sufficient** to render
|
|
1112
1138
|
* a link — the second gate (`rehype-sanitize`) also enforces its own
|
|
1113
|
-
* protocol allowlist. See the
|
|
1114
|
-
*
|
|
1139
|
+
* protocol allowlist. See the `sanitizeSchema` prop on this component
|
|
1140
|
+
* and the {@link extendSanitizeSchema} helper for the second gate.
|
|
1115
1141
|
*
|
|
1116
1142
|
* **API stability**: the `UrlTransform` type tracks the upstream
|
|
1117
1143
|
* `react-markdown` shape and may change with its major versions.
|
|
@@ -1119,10 +1145,11 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1119
1145
|
urlTransform?: UrlTransform | null;
|
|
1120
1146
|
/**
|
|
1121
1147
|
* Override the `rehype-sanitize` schema applied to the rendered output.
|
|
1122
|
-
* The library default
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1125
|
-
* `footnote-sup`).
|
|
1148
|
+
* The library default extends `rehype-sanitize`'s own `defaultSchema`
|
|
1149
|
+
* with the `<mark>` tag, KaTeX class names, and the cross-chunk
|
|
1150
|
+
* coordination tags (`cross-chunk-link`, `cross-chunk-image`,
|
|
1151
|
+
* `footnote-sup`). The default is not exported as a value — see
|
|
1152
|
+
* {@link extendSanitizeSchema} for how to inspect or extend it safely.
|
|
1126
1153
|
*
|
|
1127
1154
|
* **Recommended pattern**: build the schema with {@link extendSanitizeSchema}
|
|
1128
1155
|
* (mutate-and-return form) so those library additions stay intact, and
|
|
@@ -1147,10 +1174,11 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1147
1174
|
* lose its placeholders. Prefer the helper unless you have a specific
|
|
1148
1175
|
* reason to opt out.
|
|
1149
1176
|
*
|
|
1150
|
-
* **Reference stability matters.**
|
|
1151
|
-
*
|
|
1152
|
-
* `useStableValue` deep-equal pass, but the safer pattern is
|
|
1153
|
-
* module-scope. Development builds will `console.warn` on identity
|
|
1177
|
+
* **Reference stability matters.** An inline call
|
|
1178
|
+
* (`sanitizeSchema={extendSanitizeSchema((s) => { … })}`) is mitigated by
|
|
1179
|
+
* an internal `useStableValue` deep-equal pass, but the safer pattern is
|
|
1180
|
+
* still module-scope. Development builds will `console.warn` on identity
|
|
1181
|
+
* flips.
|
|
1154
1182
|
*
|
|
1155
1183
|
* **API stability**: the `SanitizeSchema` type tracks the upstream
|
|
1156
1184
|
* `rehype-sanitize` shape and may change with its major versions.
|
|
@@ -1164,4 +1192,4 @@ interface AIMarkdownProps<TConfig extends AIMarkdownRenderConfig = AIMarkdownRen
|
|
|
1164
1192
|
declare const AIMarkdownComponent: <TConfig extends AIMarkdownRenderConfig = AIMarkdownRenderConfig, TRenderData extends AIMarkdownMetadata = AIMarkdownMetadata>({ streaming, content, fontSize, contentPreprocessors, customComponents, defaultConfig, config, metadata, Typography, ExtraStyles, variant, colorScheme, documentId, urlTransform, sanitizeSchema, }: AIMarkdownProps<TConfig, TRenderData>) => react_jsx_runtime.JSX.Element;
|
|
1165
1193
|
declare const _default: typeof AIMarkdownComponent;
|
|
1166
1194
|
|
|
1167
|
-
export { type AIMDContentPreprocessor, type AIMarkdownColorScheme, type AIMarkdownCustomComponents, AIMarkdownDocuments, type AIMarkdownDocumentsProps, type AIMarkdownExtraStylesComponent, type AIMarkdownExtraStylesProps, type AIMarkdownMetadata, type AIMarkdownProps, type AIMarkdownRenderConfig, AIMarkdownRenderDisplayOptimizeAbility, AIMarkdownRenderExtraSyntax, type AIMarkdownRenderState, type AIMarkdownTypographyComponent, type AIMarkdownTypographyProps, type AIMarkdownVariant, type ChunkData, type FootnoteDef, type LinkDef, type PartialDeep, type RefKind, type RefRecord, type Registry, type SanitizeSchema, type UrlTransform, _default as default, defaultAIMarkdownRenderConfig, defaultUrlTransform, extendSanitizeSchema,
|
|
1195
|
+
export { type AIMDContentPreprocessor, type AIMarkdownColorScheme, type AIMarkdownCustomComponents, AIMarkdownDocuments, type AIMarkdownDocumentsProps, type AIMarkdownExtraStylesComponent, type AIMarkdownExtraStylesProps, type AIMarkdownMetadata, type AIMarkdownProps, type AIMarkdownRenderConfig, AIMarkdownRenderDisplayOptimizeAbility, AIMarkdownRenderExtraSyntax, type AIMarkdownRenderState, type AIMarkdownTypographyComponent, type AIMarkdownTypographyProps, type AIMarkdownVariant, type ChunkData, type FootnoteDef, type LinkDef, type PartialDeep, type RefKind, type RefRecord, type Registry, type SanitizeSchema, type UrlTransform, _default as default, defaultAIMarkdownRenderConfig, defaultUrlTransform, extendSanitizeSchema, useAIMarkdownMetadata, useAIMarkdownRenderState, useDocumentRegistry, useStableValue };
|