@ai-react-markdown/core 1.4.1 → 1.4.3

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.cjs CHANGED
@@ -36,13 +36,16 @@ __export(index_exports, {
36
36
  AIMarkdownRenderExtraSyntax: () => AIMarkdownRenderExtraSyntax,
37
37
  default: () => index_default,
38
38
  defaultAIMarkdownRenderConfig: () => defaultAIMarkdownRenderConfig,
39
+ defaultUrlTransform: () => defaultUrlTransform,
40
+ extendSanitizeSchema: () => extendSanitizeSchema,
41
+ sanitizeSchema: () => sanitizeSchema,
39
42
  useAIMarkdownMetadata: () => useAIMarkdownMetadata,
40
43
  useAIMarkdownRenderState: () => useAIMarkdownRenderState,
41
44
  useDocumentRegistry: () => useDocumentRegistry,
42
45
  useStableValue: () => useStableValue
43
46
  });
44
47
  module.exports = __toCommonJS(index_exports);
45
- var import_react10 = require("react");
48
+ var import_react11 = require("react");
46
49
 
47
50
  // src/context.tsx
48
51
  var import_react = require("react");
@@ -1112,6 +1115,64 @@ var defaultAIMarkdownRenderConfig = Object.freeze({
1112
1115
  preserveOrphanReferences: true
1113
1116
  });
1114
1117
 
1118
+ // src/components/shortenDocumentId.ts
1119
+ var BASE62_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1120
+ function toBase62(n) {
1121
+ if (n === 0) return BASE62_ALPHABET[0];
1122
+ let v = n >>> 0;
1123
+ let out = "";
1124
+ while (v > 0) {
1125
+ out = BASE62_ALPHABET[v % 62] + out;
1126
+ v = Math.floor(v / 62);
1127
+ }
1128
+ return out;
1129
+ }
1130
+ function rotl32(x, r) {
1131
+ return (x << r | x >>> 32 - r) >>> 0;
1132
+ }
1133
+ var C1 = 3432918353;
1134
+ var C2 = 461845907;
1135
+ var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
1136
+ function murmur3_32(s, seed = 0) {
1137
+ const bytes = UTF8_ENCODER.encode(s);
1138
+ const len = bytes.length;
1139
+ let h1 = seed >>> 0;
1140
+ const nblocks = len >>> 2;
1141
+ for (let i = 0; i < nblocks; i++) {
1142
+ const b = i * 4;
1143
+ let k1 = bytes[b] | bytes[b + 1] << 8 | bytes[b + 2] << 16 | bytes[b + 3] << 24;
1144
+ k1 = Math.imul(k1, C1);
1145
+ k1 = rotl32(k1, 15);
1146
+ k1 = Math.imul(k1, C2);
1147
+ h1 ^= k1;
1148
+ h1 = rotl32(h1, 13);
1149
+ h1 = Math.imul(h1, 5) + 3864292196 >>> 0;
1150
+ }
1151
+ const tail = nblocks * 4;
1152
+ const rem = len & 3;
1153
+ if (rem > 0) {
1154
+ let k1 = 0;
1155
+ if (rem === 3) k1 ^= bytes[tail + 2] << 16;
1156
+ if (rem >= 2) k1 ^= bytes[tail + 1] << 8;
1157
+ k1 ^= bytes[tail];
1158
+ k1 = Math.imul(k1, C1);
1159
+ k1 = rotl32(k1, 15);
1160
+ k1 = Math.imul(k1, C2);
1161
+ h1 ^= k1;
1162
+ }
1163
+ h1 ^= len;
1164
+ h1 ^= h1 >>> 16;
1165
+ h1 = Math.imul(h1, 2246822507);
1166
+ h1 ^= h1 >>> 13;
1167
+ h1 = Math.imul(h1, 3266489909);
1168
+ h1 ^= h1 >>> 16;
1169
+ return h1 >>> 0;
1170
+ }
1171
+ function shortenDocumentId(id, threshold = 16) {
1172
+ if (id.length <= threshold) return id;
1173
+ return toBase62(murmur3_32(id));
1174
+ }
1175
+
1115
1176
  // src/context.tsx
1116
1177
  var import_jsx_runtime = require("react/jsx-runtime");
1117
1178
  var AIMarkdownRenderStateContext = (0, import_react.createContext)(null);
@@ -1167,7 +1228,15 @@ var AIMarkdownRenderStateProvider = ({
1167
1228
  // construction site, not at the documentId storage site, so consumers
1168
1229
  // accessing `documentId` directly still see the raw React-native value
1169
1230
  // (e.g. `useId()`'s `_r_0_`) while id="..."/href="#..." bytes are safe.
1170
- clobberPrefix: `${encodeURIComponent(resolvedDocumentId)}-user-content-`,
1231
+ //
1232
+ // `shortenDocumentId` is applied here (NOT at the documentId storage
1233
+ // site) for the same reason: consumer-supplied UUIDs and nanoids
1234
+ // shouldn't bloat every rendered `id="…"`. Registry keying — which
1235
+ // reads `state.documentId` directly — stays on the raw value, so the
1236
+ // shortening is a pure HTML-output concern and the `useDocumentRegistry`
1237
+ // API surface is unaffected. Pure function ⇒ all chunks sharing one
1238
+ // logical documentId still produce identical prefixes.
1239
+ clobberPrefix: `${encodeURIComponent(shortenDocumentId(resolvedDocumentId))}-user-content-`,
1171
1240
  config: mergedConfig
1172
1241
  }),
1173
1242
  [streaming, fontSize, variant, colorScheme, resolvedDocumentId, mergedConfig]
@@ -2833,8 +2902,7 @@ var ExtraSyntaxRemarkPluginMap = {
2833
2902
  };
2834
2903
  var DefaultCustomComponents = {};
2835
2904
  var BlockMemoizedRenderer = (0, import_react7.memo)(
2836
- ({ content, usedComponents, remarkPlugins, rehypePlugins, remarkRehypeOptions }) => {
2837
- const urlTransform = void 0;
2905
+ ({ content, usedComponents, remarkPlugins, rehypePlugins, remarkRehypeOptions, urlTransform }) => {
2838
2906
  const allowedElements = void 0;
2839
2907
  const disallowedElements = void 0;
2840
2908
  const allowElement = void 0;
@@ -3083,108 +3151,116 @@ var BlockMemoizedRenderer = (0, import_react7.memo)(
3083
3151
  );
3084
3152
  BlockMemoizedRenderer.displayName = "BlockMemoizedRenderer";
3085
3153
  var LegacyRenderer = (0, import_react7.memo)(
3086
- ({ content, usedComponents, remarkPlugins, rehypePlugins, remarkRehypeOptions }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3154
+ ({ content, usedComponents, remarkPlugins, rehypePlugins, remarkRehypeOptions, urlTransform }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3087
3155
  Markdown_default,
3088
3156
  {
3089
3157
  remarkPlugins,
3090
3158
  rehypePlugins,
3091
3159
  remarkRehypeOptions,
3092
3160
  components: usedComponents,
3161
+ urlTransform,
3093
3162
  children: content
3094
3163
  }
3095
3164
  )
3096
3165
  );
3097
3166
  LegacyRenderer.displayName = "LegacyRenderer";
3098
- var AIMarkdownContent = (0, import_react7.memo)(({ content, customComponents }) => {
3099
- const { config, clobberPrefix } = useAIMarkdownRenderState();
3100
- const { extraSyntaxRemarkPlugins, enableDefinitionList } = (0, import_react7.useMemo)(
3101
- () => ({
3102
- extraSyntaxRemarkPlugins: config.extraSyntaxSupported.map((syntax) => ExtraSyntaxRemarkPluginMap[syntax]),
3103
- enableDefinitionList: config.extraSyntaxSupported.includes("DEFINITION_LIST" /* DEFINITION_LIST */)
3104
- }),
3105
- [config.extraSyntaxSupported]
3106
- );
3107
- const displayOptimizeRemarkPlugins = (0, import_react7.useMemo)(() => {
3108
- return config.displayOptimizeAbilities.map((ability) => DisplayOptimizeRemarkPluginMap[ability]);
3109
- }, [config.displayOptimizeAbilities]);
3110
- const usedComponents = (0, import_react7.useMemo)(() => {
3111
- return customComponents ? { ...DefaultCustomComponents, ...customComponents } : DefaultCustomComponents;
3112
- }, [customComponents]);
3113
- const remarkPlugins = (0, import_react7.useMemo)(
3114
- () => [
3115
- // --- Core plugins (always active) ---
3116
- import_remark_gfm2.default,
3117
- [
3118
- import_remark_math.default,
3119
- {
3120
- // Disable single-dollar inline math to avoid conflicts with currency
3121
- // signs and other dollar usages; the preprocessor converts $...$ to $$...$$.
3122
- singleDollarTextMath: false
3123
- }
3167
+ var AIMarkdownContent = (0, import_react7.memo)(
3168
+ ({ content, customComponents, urlTransform, sanitizeSchema: customSanitizeSchema }) => {
3169
+ const { config, clobberPrefix } = useAIMarkdownRenderState();
3170
+ const usedSanitizeSchema = customSanitizeSchema ?? sanitizeSchema;
3171
+ const { extraSyntaxRemarkPlugins, enableDefinitionList } = (0, import_react7.useMemo)(
3172
+ () => ({
3173
+ extraSyntaxRemarkPlugins: config.extraSyntaxSupported.map((syntax) => ExtraSyntaxRemarkPluginMap[syntax]),
3174
+ enableDefinitionList: config.extraSyntaxSupported.includes("DEFINITION_LIST" /* DEFINITION_LIST */)
3175
+ }),
3176
+ [config.extraSyntaxSupported]
3177
+ );
3178
+ const displayOptimizeRemarkPlugins = (0, import_react7.useMemo)(() => {
3179
+ return config.displayOptimizeAbilities.map((ability) => DisplayOptimizeRemarkPluginMap[ability]);
3180
+ }, [config.displayOptimizeAbilities]);
3181
+ const usedComponents = (0, import_react7.useMemo)(() => {
3182
+ return customComponents ? { ...DefaultCustomComponents, ...customComponents } : DefaultCustomComponents;
3183
+ }, [customComponents]);
3184
+ const remarkPlugins = (0, import_react7.useMemo)(
3185
+ () => [
3186
+ // --- Core plugins (always active) ---
3187
+ import_remark_gfm2.default,
3188
+ [
3189
+ import_remark_math.default,
3190
+ {
3191
+ // Disable single-dollar inline math to avoid conflicts with currency
3192
+ // signs and other dollar usages; the preprocessor converts $...$ to $$...$$.
3193
+ singleDollarTextMath: false
3194
+ }
3195
+ ],
3196
+ // --- Configurable extra syntax plugins ---
3197
+ ...extraSyntaxRemarkPlugins,
3198
+ // --- Formatting & normalization ---
3199
+ import_remark_breaks.default,
3200
+ import_remark_emoji.default,
3201
+ import_remark_squeeze_paragraphs.default,
3202
+ import_remark_cjk_friendly.default,
3203
+ import_remark_cjk_friendly_gfm_strikethrough.default,
3204
+ // --- Configurable display optimizations ---
3205
+ ...displayOptimizeRemarkPlugins
3124
3206
  ],
3125
- // --- Configurable extra syntax plugins ---
3126
- ...extraSyntaxRemarkPlugins,
3127
- // --- Formatting & normalization ---
3128
- import_remark_breaks.default,
3129
- import_remark_emoji.default,
3130
- import_remark_squeeze_paragraphs.default,
3131
- import_remark_cjk_friendly.default,
3132
- import_remark_cjk_friendly_gfm_strikethrough.default,
3133
- // --- Configurable display optimizations ---
3134
- ...displayOptimizeRemarkPlugins
3135
- ],
3136
- [extraSyntaxRemarkPlugins, displayOptimizeRemarkPlugins]
3137
- );
3138
- const rehypePlugins = (0, import_react7.useMemo)(
3139
- () => [
3140
- // Allow raw HTML through so rehype-sanitize can handle it.
3141
- [import_rehype_raw.default, { passThrough: [] }],
3142
- // Sanitize HTML while allowing <mark> (highlight) and KaTeX class names.
3143
- // Override `clobberPrefix` with the instance-scoped value so every id
3144
- // and clobberable attribute is namespaced to this `<AIMarkdown>` instance.
3145
- [import_rehype_sanitize2.default, { ...sanitizeSchema, clobberPrefix }],
3146
- // Normalize the auto-generated `<section data-footnotes>`: strip the
3147
- // sr-only `<h2>Footnotes</h2>` label and prepend `<hr>`. Keeps standalone
3148
- // single-doc rendering visually consistent with the cross-chunk aggregate
3149
- // footer (which builds the same shape from scratch).
3150
- rehypeFooterAdorn,
3151
- // Re-prefix intra-document hash hrefs so they match the ids that
3152
- // rehype-sanitize just clobbered. Must use the SAME prefix as the schema
3153
- // above — that's why both read from `clobberPrefix`.
3154
- [rehypeRebaseHashLinks_default, { prefix: clobberPrefix }],
3155
- import_rehype_katex.default,
3156
- import_rehype_unwrap_images.default
3157
- ],
3158
- [clobberPrefix]
3159
- );
3160
- const remarkRehypeOptions = (0, import_react7.useMemo)(
3161
- () => ({
3162
- allowDangerousHtml: true,
3163
- // Suppress mdast-util-to-hast's `user-content-` prefix on footnote
3164
- // ids/hrefs; rehype-sanitize will apply the same prefix downstream
3165
- // and `rehypeRebaseHashLinks` mirrors it onto matching hash hrefs.
3166
- // Without this, ids would end up double-prefixed
3167
- // (`user-content-user-content-fn-x`).
3168
- clobberPrefix: "",
3169
- handlers: {
3170
- // Inject definition-list HAST handlers when the extension is active.
3171
- ...enableDefinitionList ? import_remark_definition_list.defListHastHandlers : {}
3207
+ [extraSyntaxRemarkPlugins, displayOptimizeRemarkPlugins]
3208
+ );
3209
+ const rehypePlugins = (0, import_react7.useMemo)(
3210
+ () => [
3211
+ // Allow raw HTML through so rehype-sanitize can handle it.
3212
+ [import_rehype_raw.default, { passThrough: [] }],
3213
+ // Sanitize HTML while allowing <mark> (highlight), KaTeX class names,
3214
+ // and any extra protocols the caller permitted via the `sanitizeSchema`
3215
+ // prop. Override `clobberPrefix` with the instance-scoped value so every
3216
+ // id and clobberable attribute is namespaced to this `<AIMarkdown>`
3217
+ // instance — the spread order is intentional: our prefix wins over any
3218
+ // caller-supplied prefix on the schema.
3219
+ [import_rehype_sanitize2.default, { ...usedSanitizeSchema, clobberPrefix }],
3220
+ // Normalize the auto-generated `<section data-footnotes>`: strip the
3221
+ // sr-only `<h2>Footnotes</h2>` label and prepend `<hr>`. Keeps standalone
3222
+ // single-doc rendering visually consistent with the cross-chunk aggregate
3223
+ // footer (which builds the same shape from scratch).
3224
+ rehypeFooterAdorn,
3225
+ // Re-prefix intra-document hash hrefs so they match the ids that
3226
+ // rehype-sanitize just clobbered. Must use the SAME prefix as the schema
3227
+ // above that's why both read from `clobberPrefix`.
3228
+ [rehypeRebaseHashLinks_default, { prefix: clobberPrefix }],
3229
+ import_rehype_katex.default,
3230
+ import_rehype_unwrap_images.default
3231
+ ],
3232
+ [clobberPrefix, usedSanitizeSchema]
3233
+ );
3234
+ const remarkRehypeOptions = (0, import_react7.useMemo)(
3235
+ () => ({
3236
+ allowDangerousHtml: true,
3237
+ // Suppress mdast-util-to-hast's `user-content-` prefix on footnote
3238
+ // ids/hrefs; rehype-sanitize will apply the same prefix downstream
3239
+ // and `rehypeRebaseHashLinks` mirrors it onto matching hash hrefs.
3240
+ // Without this, ids would end up double-prefixed
3241
+ // (`user-content-user-content-fn-x`).
3242
+ clobberPrefix: "",
3243
+ handlers: {
3244
+ // Inject definition-list HAST handlers when the extension is active.
3245
+ ...enableDefinitionList ? import_remark_definition_list.defListHastHandlers : {}
3246
+ }
3247
+ }),
3248
+ [enableDefinitionList]
3249
+ );
3250
+ const Renderer = config.blockMemoEnabled ? BlockMemoizedRenderer : LegacyRenderer;
3251
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3252
+ Renderer,
3253
+ {
3254
+ content,
3255
+ usedComponents,
3256
+ remarkPlugins,
3257
+ rehypePlugins,
3258
+ remarkRehypeOptions,
3259
+ urlTransform
3172
3260
  }
3173
- }),
3174
- [enableDefinitionList]
3175
- );
3176
- const Renderer = config.blockMemoEnabled ? BlockMemoizedRenderer : LegacyRenderer;
3177
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3178
- Renderer,
3179
- {
3180
- content,
3181
- usedComponents,
3182
- remarkPlugins,
3183
- rehypePlugins,
3184
- remarkRehypeOptions
3185
- }
3186
- );
3187
- });
3261
+ );
3262
+ }
3263
+ );
3188
3264
  AIMarkdownContent.displayName = "AIMarkdownContent";
3189
3265
  var MarkdownContent_default = AIMarkdownContent;
3190
3266
 
@@ -3620,20 +3696,322 @@ function useStableValue(value) {
3620
3696
  return stableValue;
3621
3697
  }
3622
3698
 
3623
- // src/components/typography/Default.tsx
3699
+ // src/hooks/useReferenceFlipWarning.ts
3624
3700
  var import_react9 = require("react");
3701
+ var __DEV__ = typeof process !== "undefined" && process.env.NODE_ENV !== "production";
3702
+ var FLIP_THRESHOLD = 3;
3703
+ var WARN_COOLDOWN_MS = 5e3;
3704
+ function trackFlip(state, value, propName, now) {
3705
+ if (state.prev === value) return;
3706
+ state.flips++;
3707
+ state.prev = value;
3708
+ if (state.flips < FLIP_THRESHOLD) return;
3709
+ if (now - state.lastWarnAt < WARN_COOLDOWN_MS) return;
3710
+ state.lastWarnAt = now;
3711
+ console.warn(
3712
+ `[AIMarkdown] \`${propName}\` reference is changing on every render. Define it at module scope or wrap with useMemo/useCallback to avoid discarding the per-block memo cache on every parent re-render.`
3713
+ );
3714
+ }
3715
+ function useReferenceFlipWarning(value, propName) {
3716
+ const stateRef = (0, import_react9.useRef)({ prev: value, flips: 0, lastWarnAt: -Infinity });
3717
+ if (!__DEV__) return;
3718
+ trackFlip(stateRef.current, value, propName, Date.now());
3719
+ }
3720
+
3721
+ // src/components/typography/Default.tsx
3722
+ var import_react10 = require("react");
3625
3723
  var import_jsx_runtime7 = require("react/jsx-runtime");
3626
- var DefaultTypography = (0, import_react9.memo)(({ children, fontSize, variant, colorScheme, style }) => {
3627
- const className = (0, import_react9.useMemo)(
3724
+ var DefaultTypography = (0, import_react10.memo)(({ children, fontSize, variant, colorScheme, style }) => {
3725
+ const className = (0, import_react10.useMemo)(
3628
3726
  () => ["aim-typography-root", variant, colorScheme].filter(Boolean).join(" "),
3629
3727
  [variant, colorScheme]
3630
3728
  );
3631
- const mergedStyle = (0, import_react9.useMemo)(() => ({ width: "100%", fontSize, ...style }), [fontSize, style]);
3729
+ const mergedStyle = (0, import_react10.useMemo)(() => ({ width: "100%", fontSize, ...style }), [fontSize, style]);
3632
3730
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className, style: mergedStyle, children });
3633
3731
  });
3634
3732
  DefaultTypography.displayName = "DefaultTypography";
3635
3733
  var Default_default = DefaultTypography;
3636
3734
 
3735
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayEach.js
3736
+ function arrayEach(array, iteratee) {
3737
+ var index = -1, length = array == null ? 0 : array.length;
3738
+ while (++index < length) {
3739
+ if (iteratee(array[index], index, array) === false) {
3740
+ break;
3741
+ }
3742
+ }
3743
+ return array;
3744
+ }
3745
+ var arrayEach_default = arrayEach;
3746
+
3747
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseAssign.js
3748
+ function baseAssign(object, source) {
3749
+ return object && copyObject_default(source, keys_default(source), object);
3750
+ }
3751
+ var baseAssign_default = baseAssign;
3752
+
3753
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignIn.js
3754
+ function baseAssignIn(object, source) {
3755
+ return object && copyObject_default(source, keysIn_default(source), object);
3756
+ }
3757
+ var baseAssignIn_default = baseAssignIn;
3758
+
3759
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copySymbols.js
3760
+ function copySymbols(source, object) {
3761
+ return copyObject_default(source, getSymbols_default(source), object);
3762
+ }
3763
+ var copySymbols_default = copySymbols;
3764
+
3765
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getSymbolsIn.js
3766
+ var nativeGetSymbols2 = Object.getOwnPropertySymbols;
3767
+ var getSymbolsIn = !nativeGetSymbols2 ? stubArray_default : function(object) {
3768
+ var result = [];
3769
+ while (object) {
3770
+ arrayPush_default(result, getSymbols_default(object));
3771
+ object = getPrototype_default(object);
3772
+ }
3773
+ return result;
3774
+ };
3775
+ var getSymbolsIn_default = getSymbolsIn;
3776
+
3777
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copySymbolsIn.js
3778
+ function copySymbolsIn(source, object) {
3779
+ return copyObject_default(source, getSymbolsIn_default(source), object);
3780
+ }
3781
+ var copySymbolsIn_default = copySymbolsIn;
3782
+
3783
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeysIn.js
3784
+ function getAllKeysIn(object) {
3785
+ return baseGetAllKeys_default(object, keysIn_default, getSymbolsIn_default);
3786
+ }
3787
+ var getAllKeysIn_default = getAllKeysIn;
3788
+
3789
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_initCloneArray.js
3790
+ var objectProto16 = Object.prototype;
3791
+ var hasOwnProperty13 = objectProto16.hasOwnProperty;
3792
+ function initCloneArray(array) {
3793
+ var length = array.length, result = new array.constructor(length);
3794
+ if (length && typeof array[0] == "string" && hasOwnProperty13.call(array, "index")) {
3795
+ result.index = array.index;
3796
+ result.input = array.input;
3797
+ }
3798
+ return result;
3799
+ }
3800
+ var initCloneArray_default = initCloneArray;
3801
+
3802
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneDataView.js
3803
+ function cloneDataView(dataView, isDeep) {
3804
+ var buffer = isDeep ? cloneArrayBuffer_default(dataView.buffer) : dataView.buffer;
3805
+ return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
3806
+ }
3807
+ var cloneDataView_default = cloneDataView;
3808
+
3809
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneRegExp.js
3810
+ var reFlags = /\w*$/;
3811
+ function cloneRegExp(regexp) {
3812
+ var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
3813
+ result.lastIndex = regexp.lastIndex;
3814
+ return result;
3815
+ }
3816
+ var cloneRegExp_default = cloneRegExp;
3817
+
3818
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneSymbol.js
3819
+ var symbolProto2 = Symbol_default ? Symbol_default.prototype : void 0;
3820
+ var symbolValueOf2 = symbolProto2 ? symbolProto2.valueOf : void 0;
3821
+ function cloneSymbol(symbol) {
3822
+ return symbolValueOf2 ? Object(symbolValueOf2.call(symbol)) : {};
3823
+ }
3824
+ var cloneSymbol_default = cloneSymbol;
3825
+
3826
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_initCloneByTag.js
3827
+ var boolTag3 = "[object Boolean]";
3828
+ var dateTag3 = "[object Date]";
3829
+ var mapTag4 = "[object Map]";
3830
+ var numberTag3 = "[object Number]";
3831
+ var regexpTag3 = "[object RegExp]";
3832
+ var setTag4 = "[object Set]";
3833
+ var stringTag3 = "[object String]";
3834
+ var symbolTag2 = "[object Symbol]";
3835
+ var arrayBufferTag3 = "[object ArrayBuffer]";
3836
+ var dataViewTag4 = "[object DataView]";
3837
+ var float32Tag2 = "[object Float32Array]";
3838
+ var float64Tag2 = "[object Float64Array]";
3839
+ var int8Tag2 = "[object Int8Array]";
3840
+ var int16Tag2 = "[object Int16Array]";
3841
+ var int32Tag2 = "[object Int32Array]";
3842
+ var uint8Tag2 = "[object Uint8Array]";
3843
+ var uint8ClampedTag2 = "[object Uint8ClampedArray]";
3844
+ var uint16Tag2 = "[object Uint16Array]";
3845
+ var uint32Tag2 = "[object Uint32Array]";
3846
+ function initCloneByTag(object, tag, isDeep) {
3847
+ var Ctor = object.constructor;
3848
+ switch (tag) {
3849
+ case arrayBufferTag3:
3850
+ return cloneArrayBuffer_default(object);
3851
+ case boolTag3:
3852
+ case dateTag3:
3853
+ return new Ctor(+object);
3854
+ case dataViewTag4:
3855
+ return cloneDataView_default(object, isDeep);
3856
+ case float32Tag2:
3857
+ case float64Tag2:
3858
+ case int8Tag2:
3859
+ case int16Tag2:
3860
+ case int32Tag2:
3861
+ case uint8Tag2:
3862
+ case uint8ClampedTag2:
3863
+ case uint16Tag2:
3864
+ case uint32Tag2:
3865
+ return cloneTypedArray_default(object, isDeep);
3866
+ case mapTag4:
3867
+ return new Ctor();
3868
+ case numberTag3:
3869
+ case stringTag3:
3870
+ return new Ctor(object);
3871
+ case regexpTag3:
3872
+ return cloneRegExp_default(object);
3873
+ case setTag4:
3874
+ return new Ctor();
3875
+ case symbolTag2:
3876
+ return cloneSymbol_default(object);
3877
+ }
3878
+ }
3879
+ var initCloneByTag_default = initCloneByTag;
3880
+
3881
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseIsMap.js
3882
+ var mapTag5 = "[object Map]";
3883
+ function baseIsMap(value) {
3884
+ return isObjectLike_default(value) && getTag_default(value) == mapTag5;
3885
+ }
3886
+ var baseIsMap_default = baseIsMap;
3887
+
3888
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isMap.js
3889
+ var nodeIsMap = nodeUtil_default && nodeUtil_default.isMap;
3890
+ var isMap = nodeIsMap ? baseUnary_default(nodeIsMap) : baseIsMap_default;
3891
+ var isMap_default = isMap;
3892
+
3893
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseIsSet.js
3894
+ var setTag5 = "[object Set]";
3895
+ function baseIsSet(value) {
3896
+ return isObjectLike_default(value) && getTag_default(value) == setTag5;
3897
+ }
3898
+ var baseIsSet_default = baseIsSet;
3899
+
3900
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isSet.js
3901
+ var nodeIsSet = nodeUtil_default && nodeUtil_default.isSet;
3902
+ var isSet = nodeIsSet ? baseUnary_default(nodeIsSet) : baseIsSet_default;
3903
+ var isSet_default = isSet;
3904
+
3905
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseClone.js
3906
+ var CLONE_DEEP_FLAG = 1;
3907
+ var CLONE_FLAT_FLAG = 2;
3908
+ var CLONE_SYMBOLS_FLAG = 4;
3909
+ var argsTag4 = "[object Arguments]";
3910
+ var arrayTag3 = "[object Array]";
3911
+ var boolTag4 = "[object Boolean]";
3912
+ var dateTag4 = "[object Date]";
3913
+ var errorTag3 = "[object Error]";
3914
+ var funcTag3 = "[object Function]";
3915
+ var genTag2 = "[object GeneratorFunction]";
3916
+ var mapTag6 = "[object Map]";
3917
+ var numberTag4 = "[object Number]";
3918
+ var objectTag5 = "[object Object]";
3919
+ var regexpTag4 = "[object RegExp]";
3920
+ var setTag6 = "[object Set]";
3921
+ var stringTag4 = "[object String]";
3922
+ var symbolTag3 = "[object Symbol]";
3923
+ var weakMapTag3 = "[object WeakMap]";
3924
+ var arrayBufferTag4 = "[object ArrayBuffer]";
3925
+ var dataViewTag5 = "[object DataView]";
3926
+ var float32Tag3 = "[object Float32Array]";
3927
+ var float64Tag3 = "[object Float64Array]";
3928
+ var int8Tag3 = "[object Int8Array]";
3929
+ var int16Tag3 = "[object Int16Array]";
3930
+ var int32Tag3 = "[object Int32Array]";
3931
+ var uint8Tag3 = "[object Uint8Array]";
3932
+ var uint8ClampedTag3 = "[object Uint8ClampedArray]";
3933
+ var uint16Tag3 = "[object Uint16Array]";
3934
+ var uint32Tag3 = "[object Uint32Array]";
3935
+ var cloneableTags = {};
3936
+ cloneableTags[argsTag4] = cloneableTags[arrayTag3] = cloneableTags[arrayBufferTag4] = cloneableTags[dataViewTag5] = cloneableTags[boolTag4] = cloneableTags[dateTag4] = cloneableTags[float32Tag3] = cloneableTags[float64Tag3] = cloneableTags[int8Tag3] = cloneableTags[int16Tag3] = cloneableTags[int32Tag3] = cloneableTags[mapTag6] = cloneableTags[numberTag4] = cloneableTags[objectTag5] = cloneableTags[regexpTag4] = cloneableTags[setTag6] = cloneableTags[stringTag4] = cloneableTags[symbolTag3] = cloneableTags[uint8Tag3] = cloneableTags[uint8ClampedTag3] = cloneableTags[uint16Tag3] = cloneableTags[uint32Tag3] = true;
3937
+ cloneableTags[errorTag3] = cloneableTags[funcTag3] = cloneableTags[weakMapTag3] = false;
3938
+ function baseClone(value, bitmask, customizer, key, object, stack) {
3939
+ var result, isDeep = bitmask & CLONE_DEEP_FLAG, isFlat = bitmask & CLONE_FLAT_FLAG, isFull = bitmask & CLONE_SYMBOLS_FLAG;
3940
+ if (customizer) {
3941
+ result = object ? customizer(value, key, object, stack) : customizer(value);
3942
+ }
3943
+ if (result !== void 0) {
3944
+ return result;
3945
+ }
3946
+ if (!isObject_default(value)) {
3947
+ return value;
3948
+ }
3949
+ var isArr = isArray_default(value);
3950
+ if (isArr) {
3951
+ result = initCloneArray_default(value);
3952
+ if (!isDeep) {
3953
+ return copyArray_default(value, result);
3954
+ }
3955
+ } else {
3956
+ var tag = getTag_default(value), isFunc = tag == funcTag3 || tag == genTag2;
3957
+ if (isBuffer_default(value)) {
3958
+ return cloneBuffer_default(value, isDeep);
3959
+ }
3960
+ if (tag == objectTag5 || tag == argsTag4 || isFunc && !object) {
3961
+ result = isFlat || isFunc ? {} : initCloneObject_default(value);
3962
+ if (!isDeep) {
3963
+ return isFlat ? copySymbolsIn_default(value, baseAssignIn_default(result, value)) : copySymbols_default(value, baseAssign_default(result, value));
3964
+ }
3965
+ } else {
3966
+ if (!cloneableTags[tag]) {
3967
+ return object ? value : {};
3968
+ }
3969
+ result = initCloneByTag_default(value, tag, isDeep);
3970
+ }
3971
+ }
3972
+ stack || (stack = new Stack_default());
3973
+ var stacked = stack.get(value);
3974
+ if (stacked) {
3975
+ return stacked;
3976
+ }
3977
+ stack.set(value, result);
3978
+ if (isSet_default(value)) {
3979
+ value.forEach(function(subValue) {
3980
+ result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
3981
+ });
3982
+ } else if (isMap_default(value)) {
3983
+ value.forEach(function(subValue, key2) {
3984
+ result.set(key2, baseClone(subValue, bitmask, customizer, key2, value, stack));
3985
+ });
3986
+ }
3987
+ var keysFunc = isFull ? isFlat ? getAllKeysIn_default : getAllKeys_default : isFlat ? keysIn_default : keys_default;
3988
+ var props = isArr ? void 0 : keysFunc(value);
3989
+ arrayEach_default(props || value, function(subValue, key2) {
3990
+ if (props) {
3991
+ key2 = subValue;
3992
+ subValue = value[key2];
3993
+ }
3994
+ assignValue_default(result, key2, baseClone(subValue, bitmask, customizer, key2, value, stack));
3995
+ });
3996
+ return result;
3997
+ }
3998
+ var baseClone_default = baseClone;
3999
+
4000
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/cloneDeep.js
4001
+ var CLONE_DEEP_FLAG2 = 1;
4002
+ var CLONE_SYMBOLS_FLAG2 = 4;
4003
+ function cloneDeep(value) {
4004
+ return baseClone_default(value, CLONE_DEEP_FLAG2 | CLONE_SYMBOLS_FLAG2);
4005
+ }
4006
+ var cloneDeep_default = cloneDeep;
4007
+
4008
+ // src/components/extendSanitizeSchema.ts
4009
+ function extendSanitizeSchema(modifier) {
4010
+ const draft = cloneDeep_default(sanitizeSchema);
4011
+ const result = modifier(draft);
4012
+ return result ?? draft;
4013
+ }
4014
+
3637
4015
  // src/index.tsx
3638
4016
  var import_jsx_runtime8 = require("react/jsx-runtime");
3639
4017
  var AIMarkdownComponent = ({
@@ -3649,20 +4027,25 @@ var AIMarkdownComponent = ({
3649
4027
  ExtraStyles,
3650
4028
  variant = "default",
3651
4029
  colorScheme = "light",
3652
- documentId
4030
+ documentId,
4031
+ urlTransform,
4032
+ sanitizeSchema: sanitizeSchema2
3653
4033
  }) => {
3654
4034
  const usedFontSize = fontSize === void 0 ? "0.9375rem" : typeof fontSize === "number" ? `${fontSize}px` : fontSize;
3655
- const generatedId = (0, import_react10.useId)();
4035
+ const generatedId = (0, import_react11.useId)();
3656
4036
  const usedDocumentId = documentId && documentId.length > 0 ? documentId : generatedId;
4037
+ useReferenceFlipWarning(urlTransform, "urlTransform");
4038
+ useReferenceFlipWarning(sanitizeSchema2, "sanitizeSchema");
3657
4039
  const stableDefaultConfig = useStableValue(defaultConfig);
3658
4040
  const stableConfig = useStableValue(config);
3659
4041
  const stablePreprocessors = useStableValue(contentPreprocessors);
3660
4042
  const stableCustomComponents = useStableValue(customComponents);
3661
- const usedContent = (0, import_react10.useMemo)(
4043
+ const stableSanitizeSchema = useStableValue(sanitizeSchema2);
4044
+ const usedContent = (0, import_react11.useMemo)(
3662
4045
  () => content ? preprocessAIMDContent(content, stablePreprocessors) : content,
3663
4046
  [content, stablePreprocessors]
3664
4047
  );
3665
- const typographyStyle = (0, import_react10.useMemo)(() => ({ "--aim-font-size-root": usedFontSize }), [usedFontSize]);
4048
+ const typographyStyle = (0, import_react11.useMemo)(() => ({ "--aim-font-size-root": usedFontSize }), [usedFontSize]);
3666
4049
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AIMarkdownMetadataProvider, { metadata, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3667
4050
  context_default,
3668
4051
  {
@@ -3680,13 +4063,29 @@ var AIMarkdownComponent = ({
3680
4063
  variant,
3681
4064
  colorScheme,
3682
4065
  style: typographyStyle,
3683
- children: ExtraStyles ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ExtraStyles, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MarkdownContent_default, { content: usedContent, customComponents: stableCustomComponents }) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MarkdownContent_default, { content: usedContent, customComponents: stableCustomComponents })
4066
+ children: ExtraStyles ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ExtraStyles, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4067
+ MarkdownContent_default,
4068
+ {
4069
+ content: usedContent,
4070
+ customComponents: stableCustomComponents,
4071
+ urlTransform: urlTransform ?? void 0,
4072
+ sanitizeSchema: stableSanitizeSchema
4073
+ }
4074
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4075
+ MarkdownContent_default,
4076
+ {
4077
+ content: usedContent,
4078
+ customComponents: stableCustomComponents,
4079
+ urlTransform: urlTransform ?? void 0,
4080
+ sanitizeSchema: stableSanitizeSchema
4081
+ }
4082
+ )
3684
4083
  }
3685
4084
  )
3686
4085
  }
3687
4086
  ) });
3688
4087
  };
3689
- var AIMarkdown = (0, import_react10.memo)(AIMarkdownComponent);
4088
+ var AIMarkdown = (0, import_react11.memo)(AIMarkdownComponent);
3690
4089
  AIMarkdown.displayName = "AIMarkdown";
3691
4090
  var index_default = AIMarkdown;
3692
4091
  // Annotate the CommonJS export names for ESM import in node:
@@ -3695,6 +4094,9 @@ var index_default = AIMarkdown;
3695
4094
  AIMarkdownRenderDisplayOptimizeAbility,
3696
4095
  AIMarkdownRenderExtraSyntax,
3697
4096
  defaultAIMarkdownRenderConfig,
4097
+ defaultUrlTransform,
4098
+ extendSanitizeSchema,
4099
+ sanitizeSchema,
3698
4100
  useAIMarkdownMetadata,
3699
4101
  useAIMarkdownRenderState,
3700
4102
  useDocumentRegistry,