@ai-react-markdown/core 1.2.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  // src/index.tsx
4
- import { useMemo as useMemo3, memo as memo3 } from "react";
4
+ import { useMemo as useMemo6, memo as memo4, useId as useId3 } from "react";
5
5
 
6
6
  // src/context.tsx
7
- import { createContext, useContext, useMemo } from "react";
7
+ import { createContext, useContext, useId, useMemo } from "react";
8
8
 
9
9
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_listCacheClear.js
10
10
  function listCacheClear() {
@@ -129,8 +129,8 @@ var root = freeGlobal_default || freeSelf || Function("return this")();
129
129
  var root_default = root;
130
130
 
131
131
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Symbol.js
132
- var Symbol = root_default.Symbol;
133
- var Symbol_default = Symbol;
132
+ var Symbol2 = root_default.Symbol;
133
+ var Symbol_default = Symbol2;
134
134
 
135
135
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getRawTag.js
136
136
  var objectProto = Object.prototype;
@@ -262,8 +262,8 @@ function getNative(object, key) {
262
262
  var getNative_default = getNative;
263
263
 
264
264
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Map.js
265
- var Map = getNative_default(root_default, "Map");
266
- var Map_default = Map;
265
+ var Map2 = getNative_default(root_default, "Map");
266
+ var Map_default = Map2;
267
267
 
268
268
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_nativeCreate.js
269
269
  var nativeCreate = getNative_default(Object, "create");
@@ -434,18 +434,6 @@ Stack.prototype.has = stackHas_default;
434
434
  Stack.prototype.set = stackSet_default;
435
435
  var Stack_default = Stack;
436
436
 
437
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayEach.js
438
- function arrayEach(array, iteratee) {
439
- var index = -1, length = array == null ? 0 : array.length;
440
- while (++index < length) {
441
- if (iteratee(array[index], index, array) === false) {
442
- break;
443
- }
444
- }
445
- return array;
446
- }
447
- var arrayEach_default = arrayEach;
448
-
449
437
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_defineProperty.js
450
438
  var defineProperty = (function() {
451
439
  try {
@@ -472,47 +460,124 @@ function baseAssignValue(object, key, value) {
472
460
  }
473
461
  var baseAssignValue_default = baseAssignValue;
474
462
 
475
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_assignValue.js
476
- var objectProto6 = Object.prototype;
477
- var hasOwnProperty5 = objectProto6.hasOwnProperty;
478
- function assignValue(object, key, value) {
479
- var objValue = object[key];
480
- if (!(hasOwnProperty5.call(object, key) && eq_default(objValue, value)) || value === void 0 && !(key in object)) {
463
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_assignMergeValue.js
464
+ function assignMergeValue(object, key, value) {
465
+ if (value !== void 0 && !eq_default(object[key], value) || value === void 0 && !(key in object)) {
481
466
  baseAssignValue_default(object, key, value);
482
467
  }
483
468
  }
484
- var assignValue_default = assignValue;
469
+ var assignMergeValue_default = assignMergeValue;
485
470
 
486
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copyObject.js
487
- function copyObject(source, props, object, customizer) {
488
- var isNew = !object;
489
- object || (object = {});
490
- var index = -1, length = props.length;
491
- while (++index < length) {
492
- var key = props[index];
493
- var newValue = customizer ? customizer(object[key], source[key], key, object, source) : void 0;
494
- if (newValue === void 0) {
495
- newValue = source[key];
496
- }
497
- if (isNew) {
498
- baseAssignValue_default(object, key, newValue);
499
- } else {
500
- assignValue_default(object, key, newValue);
471
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_createBaseFor.js
472
+ function createBaseFor(fromRight) {
473
+ return function(object, iteratee, keysFunc) {
474
+ var index = -1, iterable = Object(object), props = keysFunc(object), length = props.length;
475
+ while (length--) {
476
+ var key = props[fromRight ? length : ++index];
477
+ if (iteratee(iterable[key], key, iterable) === false) {
478
+ break;
479
+ }
501
480
  }
502
- }
503
- return object;
481
+ return object;
482
+ };
504
483
  }
505
- var copyObject_default = copyObject;
484
+ var createBaseFor_default = createBaseFor;
506
485
 
507
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseTimes.js
508
- function baseTimes(n, iteratee) {
509
- var index = -1, result = Array(n);
510
- while (++index < n) {
511
- result[index] = iteratee(index);
486
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseFor.js
487
+ var baseFor = createBaseFor_default();
488
+ var baseFor_default = baseFor;
489
+
490
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneBuffer.js
491
+ var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports;
492
+ var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module;
493
+ var moduleExports = freeModule && freeModule.exports === freeExports;
494
+ var Buffer = moduleExports ? root_default.Buffer : void 0;
495
+ var allocUnsafe = Buffer ? Buffer.allocUnsafe : void 0;
496
+ function cloneBuffer(buffer, isDeep) {
497
+ if (isDeep) {
498
+ return buffer.slice();
512
499
  }
500
+ var length = buffer.length, result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
501
+ buffer.copy(result);
513
502
  return result;
514
503
  }
515
- var baseTimes_default = baseTimes;
504
+ var cloneBuffer_default = cloneBuffer;
505
+
506
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Uint8Array.js
507
+ var Uint8Array = root_default.Uint8Array;
508
+ var Uint8Array_default = Uint8Array;
509
+
510
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneArrayBuffer.js
511
+ function cloneArrayBuffer(arrayBuffer) {
512
+ var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
513
+ new Uint8Array_default(result).set(new Uint8Array_default(arrayBuffer));
514
+ return result;
515
+ }
516
+ var cloneArrayBuffer_default = cloneArrayBuffer;
517
+
518
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneTypedArray.js
519
+ function cloneTypedArray(typedArray, isDeep) {
520
+ var buffer = isDeep ? cloneArrayBuffer_default(typedArray.buffer) : typedArray.buffer;
521
+ return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
522
+ }
523
+ var cloneTypedArray_default = cloneTypedArray;
524
+
525
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copyArray.js
526
+ function copyArray(source, array) {
527
+ var index = -1, length = source.length;
528
+ array || (array = Array(length));
529
+ while (++index < length) {
530
+ array[index] = source[index];
531
+ }
532
+ return array;
533
+ }
534
+ var copyArray_default = copyArray;
535
+
536
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseCreate.js
537
+ var objectCreate = Object.create;
538
+ var baseCreate = /* @__PURE__ */ (function() {
539
+ function object() {
540
+ }
541
+ return function(proto) {
542
+ if (!isObject_default(proto)) {
543
+ return {};
544
+ }
545
+ if (objectCreate) {
546
+ return objectCreate(proto);
547
+ }
548
+ object.prototype = proto;
549
+ var result = new object();
550
+ object.prototype = void 0;
551
+ return result;
552
+ };
553
+ })();
554
+ var baseCreate_default = baseCreate;
555
+
556
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_overArg.js
557
+ function overArg(func, transform) {
558
+ return function(arg) {
559
+ return func(transform(arg));
560
+ };
561
+ }
562
+ var overArg_default = overArg;
563
+
564
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getPrototype.js
565
+ var getPrototype = overArg_default(Object.getPrototypeOf, Object);
566
+ var getPrototype_default = getPrototype;
567
+
568
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_isPrototype.js
569
+ var objectProto6 = Object.prototype;
570
+ function isPrototype(value) {
571
+ var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto6;
572
+ return value === proto;
573
+ }
574
+ var isPrototype_default = isPrototype;
575
+
576
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_initCloneObject.js
577
+ function initCloneObject(object) {
578
+ return typeof object.constructor == "function" && !isPrototype_default(object) ? baseCreate_default(getPrototype_default(object)) : {};
579
+ }
580
+ var initCloneObject_default = initCloneObject;
516
581
 
517
582
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isObjectLike.js
518
583
  function isObjectLike(value) {
@@ -529,12 +594,12 @@ var baseIsArguments_default = baseIsArguments;
529
594
 
530
595
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isArguments.js
531
596
  var objectProto7 = Object.prototype;
532
- var hasOwnProperty6 = objectProto7.hasOwnProperty;
597
+ var hasOwnProperty5 = objectProto7.hasOwnProperty;
533
598
  var propertyIsEnumerable = objectProto7.propertyIsEnumerable;
534
599
  var isArguments = baseIsArguments_default(/* @__PURE__ */ (function() {
535
600
  return arguments;
536
601
  })()) ? baseIsArguments_default : function(value) {
537
- return isObjectLike_default(value) && hasOwnProperty6.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
602
+ return isObjectLike_default(value) && hasOwnProperty5.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
538
603
  };
539
604
  var isArguments_default = isArguments;
540
605
 
@@ -542,6 +607,25 @@ var isArguments_default = isArguments;
542
607
  var isArray = Array.isArray;
543
608
  var isArray_default = isArray;
544
609
 
610
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isLength.js
611
+ var MAX_SAFE_INTEGER = 9007199254740991;
612
+ function isLength(value) {
613
+ return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
614
+ }
615
+ var isLength_default = isLength;
616
+
617
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isArrayLike.js
618
+ function isArrayLike(value) {
619
+ return value != null && isLength_default(value.length) && !isFunction_default(value);
620
+ }
621
+ var isArrayLike_default = isArrayLike;
622
+
623
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isArrayLikeObject.js
624
+ function isArrayLikeObject(value) {
625
+ return isObjectLike_default(value) && isArrayLike_default(value);
626
+ }
627
+ var isArrayLikeObject_default = isArrayLikeObject;
628
+
545
629
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/stubFalse.js
546
630
  function stubFalse() {
547
631
  return false;
@@ -549,30 +633,33 @@ function stubFalse() {
549
633
  var stubFalse_default = stubFalse;
550
634
 
551
635
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isBuffer.js
552
- var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports;
553
- var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module;
554
- var moduleExports = freeModule && freeModule.exports === freeExports;
555
- var Buffer = moduleExports ? root_default.Buffer : void 0;
556
- var nativeIsBuffer = Buffer ? Buffer.isBuffer : void 0;
636
+ var freeExports2 = typeof exports == "object" && exports && !exports.nodeType && exports;
637
+ var freeModule2 = freeExports2 && typeof module == "object" && module && !module.nodeType && module;
638
+ var moduleExports2 = freeModule2 && freeModule2.exports === freeExports2;
639
+ var Buffer2 = moduleExports2 ? root_default.Buffer : void 0;
640
+ var nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : void 0;
557
641
  var isBuffer = nativeIsBuffer || stubFalse_default;
558
642
  var isBuffer_default = isBuffer;
559
643
 
560
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_isIndex.js
561
- var MAX_SAFE_INTEGER = 9007199254740991;
562
- var reIsUint = /^(?:0|[1-9]\d*)$/;
563
- function isIndex(value, length) {
564
- var type = typeof value;
565
- length = length == null ? MAX_SAFE_INTEGER : length;
566
- return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
567
- }
568
- var isIndex_default = isIndex;
569
-
570
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isLength.js
571
- var MAX_SAFE_INTEGER2 = 9007199254740991;
572
- function isLength(value) {
573
- return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER2;
644
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isPlainObject.js
645
+ var objectTag = "[object Object]";
646
+ var funcProto3 = Function.prototype;
647
+ var objectProto8 = Object.prototype;
648
+ var funcToString3 = funcProto3.toString;
649
+ var hasOwnProperty6 = objectProto8.hasOwnProperty;
650
+ var objectCtorString = funcToString3.call(Object);
651
+ function isPlainObject(value) {
652
+ if (!isObjectLike_default(value) || baseGetTag_default(value) != objectTag) {
653
+ return false;
654
+ }
655
+ var proto = getPrototype_default(value);
656
+ if (proto === null) {
657
+ return true;
658
+ }
659
+ var Ctor = hasOwnProperty6.call(proto, "constructor") && proto.constructor;
660
+ return typeof Ctor == "function" && Ctor instanceof Ctor && funcToString3.call(Ctor) == objectCtorString;
574
661
  }
575
- var isLength_default = isLength;
662
+ var isPlainObject_default = isPlainObject;
576
663
 
577
664
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseIsTypedArray.js
578
665
  var argsTag2 = "[object Arguments]";
@@ -583,7 +670,7 @@ var errorTag = "[object Error]";
583
670
  var funcTag2 = "[object Function]";
584
671
  var mapTag = "[object Map]";
585
672
  var numberTag = "[object Number]";
586
- var objectTag = "[object Object]";
673
+ var objectTag2 = "[object Object]";
587
674
  var regexpTag = "[object RegExp]";
588
675
  var setTag = "[object Set]";
589
676
  var stringTag = "[object String]";
@@ -601,7 +688,7 @@ var uint16Tag = "[object Uint16Array]";
601
688
  var uint32Tag = "[object Uint32Array]";
602
689
  var typedArrayTags = {};
603
690
  typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
604
- typedArrayTags[argsTag2] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag2] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
691
+ typedArrayTags[argsTag2] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag2] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag2] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
605
692
  function baseIsTypedArray(value) {
606
693
  return isObjectLike_default(value) && isLength_default(value.length) && !!typedArrayTags[baseGetTag_default(value)];
607
694
  }
@@ -616,13 +703,13 @@ function baseUnary(func) {
616
703
  var baseUnary_default = baseUnary;
617
704
 
618
705
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_nodeUtil.js
619
- var freeExports2 = typeof exports == "object" && exports && !exports.nodeType && exports;
620
- var freeModule2 = freeExports2 && typeof module == "object" && module && !module.nodeType && module;
621
- var moduleExports2 = freeModule2 && freeModule2.exports === freeExports2;
622
- var freeProcess = moduleExports2 && freeGlobal_default.process;
706
+ var freeExports3 = typeof exports == "object" && exports && !exports.nodeType && exports;
707
+ var freeModule3 = freeExports3 && typeof module == "object" && module && !module.nodeType && module;
708
+ var moduleExports3 = freeModule3 && freeModule3.exports === freeExports3;
709
+ var freeProcess = moduleExports3 && freeGlobal_default.process;
623
710
  var nodeUtil = (function() {
624
711
  try {
625
- var types = freeModule2 && freeModule2.require && freeModule2.require("util").types;
712
+ var types = freeModule3 && freeModule3.require && freeModule3.require("util").types;
626
713
  if (types) {
627
714
  return types;
628
715
  }
@@ -637,617 +724,122 @@ var nodeIsTypedArray = nodeUtil_default && nodeUtil_default.isTypedArray;
637
724
  var isTypedArray = nodeIsTypedArray ? baseUnary_default(nodeIsTypedArray) : baseIsTypedArray_default;
638
725
  var isTypedArray_default = isTypedArray;
639
726
 
640
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayLikeKeys.js
641
- var objectProto8 = Object.prototype;
642
- var hasOwnProperty7 = objectProto8.hasOwnProperty;
643
- function arrayLikeKeys(value, inherited) {
644
- var isArr = isArray_default(value), isArg = !isArr && isArguments_default(value), isBuff = !isArr && !isArg && isBuffer_default(value), isType = !isArr && !isArg && !isBuff && isTypedArray_default(value), skipIndexes = isArr || isArg || isBuff || isType, result = skipIndexes ? baseTimes_default(value.length, String) : [], length = result.length;
645
- for (var key in value) {
646
- if ((inherited || hasOwnProperty7.call(value, key)) && !(skipIndexes && // Safari 9 has enumerable `arguments.length` in strict mode.
647
- (key == "length" || // Node.js 0.10 has enumerable non-index properties on buffers.
648
- isBuff && (key == "offset" || key == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays.
649
- isType && (key == "buffer" || key == "byteLength" || key == "byteOffset") || // Skip index properties.
650
- isIndex_default(key, length)))) {
651
- result.push(key);
652
- }
727
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_safeGet.js
728
+ function safeGet(object, key) {
729
+ if (key === "constructor" && typeof object[key] === "function") {
730
+ return;
653
731
  }
654
- return result;
732
+ if (key == "__proto__") {
733
+ return;
734
+ }
735
+ return object[key];
655
736
  }
656
- var arrayLikeKeys_default = arrayLikeKeys;
737
+ var safeGet_default = safeGet;
657
738
 
658
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_isPrototype.js
739
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_assignValue.js
659
740
  var objectProto9 = Object.prototype;
660
- function isPrototype(value) {
661
- var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto9;
662
- return value === proto;
663
- }
664
- var isPrototype_default = isPrototype;
665
-
666
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_overArg.js
667
- function overArg(func, transform) {
668
- return function(arg) {
669
- return func(transform(arg));
670
- };
741
+ var hasOwnProperty7 = objectProto9.hasOwnProperty;
742
+ function assignValue(object, key, value) {
743
+ var objValue = object[key];
744
+ if (!(hasOwnProperty7.call(object, key) && eq_default(objValue, value)) || value === void 0 && !(key in object)) {
745
+ baseAssignValue_default(object, key, value);
746
+ }
671
747
  }
672
- var overArg_default = overArg;
673
-
674
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeys.js
675
- var nativeKeys = overArg_default(Object.keys, Object);
676
- var nativeKeys_default = nativeKeys;
748
+ var assignValue_default = assignValue;
677
749
 
678
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseKeys.js
679
- var objectProto10 = Object.prototype;
680
- var hasOwnProperty8 = objectProto10.hasOwnProperty;
681
- function baseKeys(object) {
682
- if (!isPrototype_default(object)) {
683
- return nativeKeys_default(object);
684
- }
685
- var result = [];
686
- for (var key in Object(object)) {
687
- if (hasOwnProperty8.call(object, key) && key != "constructor") {
688
- result.push(key);
689
- }
690
- }
691
- return result;
692
- }
693
- var baseKeys_default = baseKeys;
694
-
695
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isArrayLike.js
696
- function isArrayLike(value) {
697
- return value != null && isLength_default(value.length) && !isFunction_default(value);
698
- }
699
- var isArrayLike_default = isArrayLike;
700
-
701
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/keys.js
702
- function keys(object) {
703
- return isArrayLike_default(object) ? arrayLikeKeys_default(object) : baseKeys_default(object);
704
- }
705
- var keys_default = keys;
706
-
707
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseAssign.js
708
- function baseAssign(object, source) {
709
- return object && copyObject_default(source, keys_default(source), object);
710
- }
711
- var baseAssign_default = baseAssign;
712
-
713
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeysIn.js
714
- function nativeKeysIn(object) {
715
- var result = [];
716
- if (object != null) {
717
- for (var key in Object(object)) {
718
- result.push(key);
750
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copyObject.js
751
+ function copyObject(source, props, object, customizer) {
752
+ var isNew = !object;
753
+ object || (object = {});
754
+ var index = -1, length = props.length;
755
+ while (++index < length) {
756
+ var key = props[index];
757
+ var newValue = customizer ? customizer(object[key], source[key], key, object, source) : void 0;
758
+ if (newValue === void 0) {
759
+ newValue = source[key];
719
760
  }
720
- }
721
- return result;
722
- }
723
- var nativeKeysIn_default = nativeKeysIn;
724
-
725
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseKeysIn.js
726
- var objectProto11 = Object.prototype;
727
- var hasOwnProperty9 = objectProto11.hasOwnProperty;
728
- function baseKeysIn(object) {
729
- if (!isObject_default(object)) {
730
- return nativeKeysIn_default(object);
731
- }
732
- var isProto = isPrototype_default(object), result = [];
733
- for (var key in object) {
734
- if (!(key == "constructor" && (isProto || !hasOwnProperty9.call(object, key)))) {
735
- result.push(key);
761
+ if (isNew) {
762
+ baseAssignValue_default(object, key, newValue);
763
+ } else {
764
+ assignValue_default(object, key, newValue);
736
765
  }
737
766
  }
738
- return result;
739
- }
740
- var baseKeysIn_default = baseKeysIn;
741
-
742
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/keysIn.js
743
- function keysIn(object) {
744
- return isArrayLike_default(object) ? arrayLikeKeys_default(object, true) : baseKeysIn_default(object);
745
- }
746
- var keysIn_default = keysIn;
747
-
748
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignIn.js
749
- function baseAssignIn(object, source) {
750
- return object && copyObject_default(source, keysIn_default(source), object);
767
+ return object;
751
768
  }
752
- var baseAssignIn_default = baseAssignIn;
769
+ var copyObject_default = copyObject;
753
770
 
754
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneBuffer.js
755
- var freeExports3 = typeof exports == "object" && exports && !exports.nodeType && exports;
756
- var freeModule3 = freeExports3 && typeof module == "object" && module && !module.nodeType && module;
757
- var moduleExports3 = freeModule3 && freeModule3.exports === freeExports3;
758
- var Buffer2 = moduleExports3 ? root_default.Buffer : void 0;
759
- var allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : void 0;
760
- function cloneBuffer(buffer, isDeep) {
761
- if (isDeep) {
762
- return buffer.slice();
771
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseTimes.js
772
+ function baseTimes(n, iteratee) {
773
+ var index = -1, result = Array(n);
774
+ while (++index < n) {
775
+ result[index] = iteratee(index);
763
776
  }
764
- var length = buffer.length, result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
765
- buffer.copy(result);
766
777
  return result;
767
778
  }
768
- var cloneBuffer_default = cloneBuffer;
779
+ var baseTimes_default = baseTimes;
769
780
 
770
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copyArray.js
771
- function copyArray(source, array) {
772
- var index = -1, length = source.length;
773
- array || (array = Array(length));
774
- while (++index < length) {
775
- array[index] = source[index];
776
- }
777
- return array;
781
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_isIndex.js
782
+ var MAX_SAFE_INTEGER2 = 9007199254740991;
783
+ var reIsUint = /^(?:0|[1-9]\d*)$/;
784
+ function isIndex(value, length) {
785
+ var type = typeof value;
786
+ length = length == null ? MAX_SAFE_INTEGER2 : length;
787
+ return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
778
788
  }
779
- var copyArray_default = copyArray;
789
+ var isIndex_default = isIndex;
780
790
 
781
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayFilter.js
782
- function arrayFilter(array, predicate) {
783
- var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = [];
784
- while (++index < length) {
785
- var value = array[index];
786
- if (predicate(value, index, array)) {
787
- result[resIndex++] = value;
791
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayLikeKeys.js
792
+ var objectProto10 = Object.prototype;
793
+ var hasOwnProperty8 = objectProto10.hasOwnProperty;
794
+ function arrayLikeKeys(value, inherited) {
795
+ var isArr = isArray_default(value), isArg = !isArr && isArguments_default(value), isBuff = !isArr && !isArg && isBuffer_default(value), isType = !isArr && !isArg && !isBuff && isTypedArray_default(value), skipIndexes = isArr || isArg || isBuff || isType, result = skipIndexes ? baseTimes_default(value.length, String) : [], length = result.length;
796
+ for (var key in value) {
797
+ if ((inherited || hasOwnProperty8.call(value, key)) && !(skipIndexes && // Safari 9 has enumerable `arguments.length` in strict mode.
798
+ (key == "length" || // Node.js 0.10 has enumerable non-index properties on buffers.
799
+ isBuff && (key == "offset" || key == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays.
800
+ isType && (key == "buffer" || key == "byteLength" || key == "byteOffset") || // Skip index properties.
801
+ isIndex_default(key, length)))) {
802
+ result.push(key);
788
803
  }
789
804
  }
790
805
  return result;
791
806
  }
792
- var arrayFilter_default = arrayFilter;
793
-
794
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/stubArray.js
795
- function stubArray() {
796
- return [];
797
- }
798
- var stubArray_default = stubArray;
799
-
800
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getSymbols.js
801
- var objectProto12 = Object.prototype;
802
- var propertyIsEnumerable2 = objectProto12.propertyIsEnumerable;
803
- var nativeGetSymbols = Object.getOwnPropertySymbols;
804
- var getSymbols = !nativeGetSymbols ? stubArray_default : function(object) {
805
- if (object == null) {
806
- return [];
807
- }
808
- object = Object(object);
809
- return arrayFilter_default(nativeGetSymbols(object), function(symbol) {
810
- return propertyIsEnumerable2.call(object, symbol);
811
- });
812
- };
813
- var getSymbols_default = getSymbols;
814
-
815
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copySymbols.js
816
- function copySymbols(source, object) {
817
- return copyObject_default(source, getSymbols_default(source), object);
818
- }
819
- var copySymbols_default = copySymbols;
820
-
821
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayPush.js
822
- function arrayPush(array, values) {
823
- var index = -1, length = values.length, offset = array.length;
824
- while (++index < length) {
825
- array[offset + index] = values[index];
826
- }
827
- return array;
828
- }
829
- var arrayPush_default = arrayPush;
830
-
831
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getPrototype.js
832
- var getPrototype = overArg_default(Object.getPrototypeOf, Object);
833
- var getPrototype_default = getPrototype;
807
+ var arrayLikeKeys_default = arrayLikeKeys;
834
808
 
835
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getSymbolsIn.js
836
- var nativeGetSymbols2 = Object.getOwnPropertySymbols;
837
- var getSymbolsIn = !nativeGetSymbols2 ? stubArray_default : function(object) {
809
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeysIn.js
810
+ function nativeKeysIn(object) {
838
811
  var result = [];
839
- while (object) {
840
- arrayPush_default(result, getSymbols_default(object));
841
- object = getPrototype_default(object);
842
- }
843
- return result;
844
- };
845
- var getSymbolsIn_default = getSymbolsIn;
846
-
847
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_copySymbolsIn.js
848
- function copySymbolsIn(source, object) {
849
- return copyObject_default(source, getSymbolsIn_default(source), object);
850
- }
851
- var copySymbolsIn_default = copySymbolsIn;
852
-
853
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseGetAllKeys.js
854
- function baseGetAllKeys(object, keysFunc, symbolsFunc) {
855
- var result = keysFunc(object);
856
- return isArray_default(object) ? result : arrayPush_default(result, symbolsFunc(object));
857
- }
858
- var baseGetAllKeys_default = baseGetAllKeys;
859
-
860
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeys.js
861
- function getAllKeys(object) {
862
- return baseGetAllKeys_default(object, keys_default, getSymbols_default);
863
- }
864
- var getAllKeys_default = getAllKeys;
865
-
866
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeysIn.js
867
- function getAllKeysIn(object) {
868
- return baseGetAllKeys_default(object, keysIn_default, getSymbolsIn_default);
869
- }
870
- var getAllKeysIn_default = getAllKeysIn;
871
-
872
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_DataView.js
873
- var DataView = getNative_default(root_default, "DataView");
874
- var DataView_default = DataView;
875
-
876
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Promise.js
877
- var Promise2 = getNative_default(root_default, "Promise");
878
- var Promise_default = Promise2;
879
-
880
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Set.js
881
- var Set = getNative_default(root_default, "Set");
882
- var Set_default = Set;
883
-
884
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_WeakMap.js
885
- var WeakMap = getNative_default(root_default, "WeakMap");
886
- var WeakMap_default = WeakMap;
887
-
888
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getTag.js
889
- var mapTag2 = "[object Map]";
890
- var objectTag2 = "[object Object]";
891
- var promiseTag = "[object Promise]";
892
- var setTag2 = "[object Set]";
893
- var weakMapTag2 = "[object WeakMap]";
894
- var dataViewTag2 = "[object DataView]";
895
- var dataViewCtorString = toSource_default(DataView_default);
896
- var mapCtorString = toSource_default(Map_default);
897
- var promiseCtorString = toSource_default(Promise_default);
898
- var setCtorString = toSource_default(Set_default);
899
- var weakMapCtorString = toSource_default(WeakMap_default);
900
- var getTag = baseGetTag_default;
901
- if (DataView_default && getTag(new DataView_default(new ArrayBuffer(1))) != dataViewTag2 || Map_default && getTag(new Map_default()) != mapTag2 || Promise_default && getTag(Promise_default.resolve()) != promiseTag || Set_default && getTag(new Set_default()) != setTag2 || WeakMap_default && getTag(new WeakMap_default()) != weakMapTag2) {
902
- getTag = function(value) {
903
- var result = baseGetTag_default(value), Ctor = result == objectTag2 ? value.constructor : void 0, ctorString = Ctor ? toSource_default(Ctor) : "";
904
- if (ctorString) {
905
- switch (ctorString) {
906
- case dataViewCtorString:
907
- return dataViewTag2;
908
- case mapCtorString:
909
- return mapTag2;
910
- case promiseCtorString:
911
- return promiseTag;
912
- case setCtorString:
913
- return setTag2;
914
- case weakMapCtorString:
915
- return weakMapTag2;
916
- }
917
- }
918
- return result;
919
- };
920
- }
921
- var getTag_default = getTag;
922
-
923
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_initCloneArray.js
924
- var objectProto13 = Object.prototype;
925
- var hasOwnProperty10 = objectProto13.hasOwnProperty;
926
- function initCloneArray(array) {
927
- var length = array.length, result = new array.constructor(length);
928
- if (length && typeof array[0] == "string" && hasOwnProperty10.call(array, "index")) {
929
- result.index = array.index;
930
- result.input = array.input;
931
- }
932
- return result;
933
- }
934
- var initCloneArray_default = initCloneArray;
935
-
936
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Uint8Array.js
937
- var Uint8Array = root_default.Uint8Array;
938
- var Uint8Array_default = Uint8Array;
939
-
940
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneArrayBuffer.js
941
- function cloneArrayBuffer(arrayBuffer) {
942
- var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
943
- new Uint8Array_default(result).set(new Uint8Array_default(arrayBuffer));
944
- return result;
945
- }
946
- var cloneArrayBuffer_default = cloneArrayBuffer;
947
-
948
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneDataView.js
949
- function cloneDataView(dataView, isDeep) {
950
- var buffer = isDeep ? cloneArrayBuffer_default(dataView.buffer) : dataView.buffer;
951
- return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
952
- }
953
- var cloneDataView_default = cloneDataView;
954
-
955
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneRegExp.js
956
- var reFlags = /\w*$/;
957
- function cloneRegExp(regexp) {
958
- var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
959
- result.lastIndex = regexp.lastIndex;
960
- return result;
961
- }
962
- var cloneRegExp_default = cloneRegExp;
963
-
964
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneSymbol.js
965
- var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
966
- var symbolValueOf = symbolProto ? symbolProto.valueOf : void 0;
967
- function cloneSymbol(symbol) {
968
- return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
969
- }
970
- var cloneSymbol_default = cloneSymbol;
971
-
972
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_cloneTypedArray.js
973
- function cloneTypedArray(typedArray, isDeep) {
974
- var buffer = isDeep ? cloneArrayBuffer_default(typedArray.buffer) : typedArray.buffer;
975
- return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
976
- }
977
- var cloneTypedArray_default = cloneTypedArray;
978
-
979
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_initCloneByTag.js
980
- var boolTag2 = "[object Boolean]";
981
- var dateTag2 = "[object Date]";
982
- var mapTag3 = "[object Map]";
983
- var numberTag2 = "[object Number]";
984
- var regexpTag2 = "[object RegExp]";
985
- var setTag3 = "[object Set]";
986
- var stringTag2 = "[object String]";
987
- var symbolTag = "[object Symbol]";
988
- var arrayBufferTag2 = "[object ArrayBuffer]";
989
- var dataViewTag3 = "[object DataView]";
990
- var float32Tag2 = "[object Float32Array]";
991
- var float64Tag2 = "[object Float64Array]";
992
- var int8Tag2 = "[object Int8Array]";
993
- var int16Tag2 = "[object Int16Array]";
994
- var int32Tag2 = "[object Int32Array]";
995
- var uint8Tag2 = "[object Uint8Array]";
996
- var uint8ClampedTag2 = "[object Uint8ClampedArray]";
997
- var uint16Tag2 = "[object Uint16Array]";
998
- var uint32Tag2 = "[object Uint32Array]";
999
- function initCloneByTag(object, tag, isDeep) {
1000
- var Ctor = object.constructor;
1001
- switch (tag) {
1002
- case arrayBufferTag2:
1003
- return cloneArrayBuffer_default(object);
1004
- case boolTag2:
1005
- case dateTag2:
1006
- return new Ctor(+object);
1007
- case dataViewTag3:
1008
- return cloneDataView_default(object, isDeep);
1009
- case float32Tag2:
1010
- case float64Tag2:
1011
- case int8Tag2:
1012
- case int16Tag2:
1013
- case int32Tag2:
1014
- case uint8Tag2:
1015
- case uint8ClampedTag2:
1016
- case uint16Tag2:
1017
- case uint32Tag2:
1018
- return cloneTypedArray_default(object, isDeep);
1019
- case mapTag3:
1020
- return new Ctor();
1021
- case numberTag2:
1022
- case stringTag2:
1023
- return new Ctor(object);
1024
- case regexpTag2:
1025
- return cloneRegExp_default(object);
1026
- case setTag3:
1027
- return new Ctor();
1028
- case symbolTag:
1029
- return cloneSymbol_default(object);
1030
- }
1031
- }
1032
- var initCloneByTag_default = initCloneByTag;
1033
-
1034
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseCreate.js
1035
- var objectCreate = Object.create;
1036
- var baseCreate = /* @__PURE__ */ (function() {
1037
- function object() {
1038
- }
1039
- return function(proto) {
1040
- if (!isObject_default(proto)) {
1041
- return {};
1042
- }
1043
- if (objectCreate) {
1044
- return objectCreate(proto);
1045
- }
1046
- object.prototype = proto;
1047
- var result = new object();
1048
- object.prototype = void 0;
1049
- return result;
1050
- };
1051
- })();
1052
- var baseCreate_default = baseCreate;
1053
-
1054
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_initCloneObject.js
1055
- function initCloneObject(object) {
1056
- return typeof object.constructor == "function" && !isPrototype_default(object) ? baseCreate_default(getPrototype_default(object)) : {};
1057
- }
1058
- var initCloneObject_default = initCloneObject;
1059
-
1060
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseIsMap.js
1061
- var mapTag4 = "[object Map]";
1062
- function baseIsMap(value) {
1063
- return isObjectLike_default(value) && getTag_default(value) == mapTag4;
1064
- }
1065
- var baseIsMap_default = baseIsMap;
1066
-
1067
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isMap.js
1068
- var nodeIsMap = nodeUtil_default && nodeUtil_default.isMap;
1069
- var isMap = nodeIsMap ? baseUnary_default(nodeIsMap) : baseIsMap_default;
1070
- var isMap_default = isMap;
1071
-
1072
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseIsSet.js
1073
- var setTag4 = "[object Set]";
1074
- function baseIsSet(value) {
1075
- return isObjectLike_default(value) && getTag_default(value) == setTag4;
1076
- }
1077
- var baseIsSet_default = baseIsSet;
1078
-
1079
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isSet.js
1080
- var nodeIsSet = nodeUtil_default && nodeUtil_default.isSet;
1081
- var isSet = nodeIsSet ? baseUnary_default(nodeIsSet) : baseIsSet_default;
1082
- var isSet_default = isSet;
1083
-
1084
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseClone.js
1085
- var CLONE_DEEP_FLAG = 1;
1086
- var CLONE_FLAT_FLAG = 2;
1087
- var CLONE_SYMBOLS_FLAG = 4;
1088
- var argsTag3 = "[object Arguments]";
1089
- var arrayTag2 = "[object Array]";
1090
- var boolTag3 = "[object Boolean]";
1091
- var dateTag3 = "[object Date]";
1092
- var errorTag2 = "[object Error]";
1093
- var funcTag3 = "[object Function]";
1094
- var genTag2 = "[object GeneratorFunction]";
1095
- var mapTag5 = "[object Map]";
1096
- var numberTag3 = "[object Number]";
1097
- var objectTag3 = "[object Object]";
1098
- var regexpTag3 = "[object RegExp]";
1099
- var setTag5 = "[object Set]";
1100
- var stringTag3 = "[object String]";
1101
- var symbolTag2 = "[object Symbol]";
1102
- var weakMapTag3 = "[object WeakMap]";
1103
- var arrayBufferTag3 = "[object ArrayBuffer]";
1104
- var dataViewTag4 = "[object DataView]";
1105
- var float32Tag3 = "[object Float32Array]";
1106
- var float64Tag3 = "[object Float64Array]";
1107
- var int8Tag3 = "[object Int8Array]";
1108
- var int16Tag3 = "[object Int16Array]";
1109
- var int32Tag3 = "[object Int32Array]";
1110
- var uint8Tag3 = "[object Uint8Array]";
1111
- var uint8ClampedTag3 = "[object Uint8ClampedArray]";
1112
- var uint16Tag3 = "[object Uint16Array]";
1113
- var uint32Tag3 = "[object Uint32Array]";
1114
- var cloneableTags = {};
1115
- cloneableTags[argsTag3] = cloneableTags[arrayTag2] = cloneableTags[arrayBufferTag3] = cloneableTags[dataViewTag4] = cloneableTags[boolTag3] = cloneableTags[dateTag3] = cloneableTags[float32Tag3] = cloneableTags[float64Tag3] = cloneableTags[int8Tag3] = cloneableTags[int16Tag3] = cloneableTags[int32Tag3] = cloneableTags[mapTag5] = cloneableTags[numberTag3] = cloneableTags[objectTag3] = cloneableTags[regexpTag3] = cloneableTags[setTag5] = cloneableTags[stringTag3] = cloneableTags[symbolTag2] = cloneableTags[uint8Tag3] = cloneableTags[uint8ClampedTag3] = cloneableTags[uint16Tag3] = cloneableTags[uint32Tag3] = true;
1116
- cloneableTags[errorTag2] = cloneableTags[funcTag3] = cloneableTags[weakMapTag3] = false;
1117
- function baseClone(value, bitmask, customizer, key, object, stack) {
1118
- var result, isDeep = bitmask & CLONE_DEEP_FLAG, isFlat = bitmask & CLONE_FLAT_FLAG, isFull = bitmask & CLONE_SYMBOLS_FLAG;
1119
- if (customizer) {
1120
- result = object ? customizer(value, key, object, stack) : customizer(value);
1121
- }
1122
- if (result !== void 0) {
1123
- return result;
1124
- }
1125
- if (!isObject_default(value)) {
1126
- return value;
1127
- }
1128
- var isArr = isArray_default(value);
1129
- if (isArr) {
1130
- result = initCloneArray_default(value);
1131
- if (!isDeep) {
1132
- return copyArray_default(value, result);
1133
- }
1134
- } else {
1135
- var tag = getTag_default(value), isFunc = tag == funcTag3 || tag == genTag2;
1136
- if (isBuffer_default(value)) {
1137
- return cloneBuffer_default(value, isDeep);
1138
- }
1139
- if (tag == objectTag3 || tag == argsTag3 || isFunc && !object) {
1140
- result = isFlat || isFunc ? {} : initCloneObject_default(value);
1141
- if (!isDeep) {
1142
- return isFlat ? copySymbolsIn_default(value, baseAssignIn_default(result, value)) : copySymbols_default(value, baseAssign_default(result, value));
1143
- }
1144
- } else {
1145
- if (!cloneableTags[tag]) {
1146
- return object ? value : {};
1147
- }
1148
- result = initCloneByTag_default(value, tag, isDeep);
1149
- }
1150
- }
1151
- stack || (stack = new Stack_default());
1152
- var stacked = stack.get(value);
1153
- if (stacked) {
1154
- return stacked;
1155
- }
1156
- stack.set(value, result);
1157
- if (isSet_default(value)) {
1158
- value.forEach(function(subValue) {
1159
- result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
1160
- });
1161
- } else if (isMap_default(value)) {
1162
- value.forEach(function(subValue, key2) {
1163
- result.set(key2, baseClone(subValue, bitmask, customizer, key2, value, stack));
1164
- });
1165
- }
1166
- var keysFunc = isFull ? isFlat ? getAllKeysIn_default : getAllKeys_default : isFlat ? keysIn_default : keys_default;
1167
- var props = isArr ? void 0 : keysFunc(value);
1168
- arrayEach_default(props || value, function(subValue, key2) {
1169
- if (props) {
1170
- key2 = subValue;
1171
- subValue = value[key2];
1172
- }
1173
- assignValue_default(result, key2, baseClone(subValue, bitmask, customizer, key2, value, stack));
1174
- });
1175
- return result;
1176
- }
1177
- var baseClone_default = baseClone;
1178
-
1179
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/cloneDeep.js
1180
- var CLONE_DEEP_FLAG2 = 1;
1181
- var CLONE_SYMBOLS_FLAG2 = 4;
1182
- function cloneDeep(value) {
1183
- return baseClone_default(value, CLONE_DEEP_FLAG2 | CLONE_SYMBOLS_FLAG2);
1184
- }
1185
- var cloneDeep_default = cloneDeep;
1186
-
1187
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_assignMergeValue.js
1188
- function assignMergeValue(object, key, value) {
1189
- if (value !== void 0 && !eq_default(object[key], value) || value === void 0 && !(key in object)) {
1190
- baseAssignValue_default(object, key, value);
1191
- }
1192
- }
1193
- var assignMergeValue_default = assignMergeValue;
1194
-
1195
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_createBaseFor.js
1196
- function createBaseFor(fromRight) {
1197
- return function(object, iteratee, keysFunc) {
1198
- var index = -1, iterable = Object(object), props = keysFunc(object), length = props.length;
1199
- while (length--) {
1200
- var key = props[fromRight ? length : ++index];
1201
- if (iteratee(iterable[key], key, iterable) === false) {
1202
- break;
1203
- }
812
+ if (object != null) {
813
+ for (var key in Object(object)) {
814
+ result.push(key);
1204
815
  }
1205
- return object;
1206
- };
1207
- }
1208
- var createBaseFor_default = createBaseFor;
1209
-
1210
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseFor.js
1211
- var baseFor = createBaseFor_default();
1212
- var baseFor_default = baseFor;
1213
-
1214
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isArrayLikeObject.js
1215
- function isArrayLikeObject(value) {
1216
- return isObjectLike_default(value) && isArrayLike_default(value);
1217
- }
1218
- var isArrayLikeObject_default = isArrayLikeObject;
1219
-
1220
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/isPlainObject.js
1221
- var objectTag4 = "[object Object]";
1222
- var funcProto3 = Function.prototype;
1223
- var objectProto14 = Object.prototype;
1224
- var funcToString3 = funcProto3.toString;
1225
- var hasOwnProperty11 = objectProto14.hasOwnProperty;
1226
- var objectCtorString = funcToString3.call(Object);
1227
- function isPlainObject(value) {
1228
- if (!isObjectLike_default(value) || baseGetTag_default(value) != objectTag4) {
1229
- return false;
1230
- }
1231
- var proto = getPrototype_default(value);
1232
- if (proto === null) {
1233
- return true;
1234
816
  }
1235
- var Ctor = hasOwnProperty11.call(proto, "constructor") && proto.constructor;
1236
- return typeof Ctor == "function" && Ctor instanceof Ctor && funcToString3.call(Ctor) == objectCtorString;
817
+ return result;
1237
818
  }
1238
- var isPlainObject_default = isPlainObject;
819
+ var nativeKeysIn_default = nativeKeysIn;
1239
820
 
1240
- // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_safeGet.js
1241
- function safeGet(object, key) {
1242
- if (key === "constructor" && typeof object[key] === "function") {
1243
- return;
821
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseKeysIn.js
822
+ var objectProto11 = Object.prototype;
823
+ var hasOwnProperty9 = objectProto11.hasOwnProperty;
824
+ function baseKeysIn(object) {
825
+ if (!isObject_default(object)) {
826
+ return nativeKeysIn_default(object);
1244
827
  }
1245
- if (key == "__proto__") {
1246
- return;
828
+ var isProto = isPrototype_default(object), result = [];
829
+ for (var key in object) {
830
+ if (!(key == "constructor" && (isProto || !hasOwnProperty9.call(object, key)))) {
831
+ result.push(key);
832
+ }
1247
833
  }
1248
- return object[key];
834
+ return result;
1249
835
  }
1250
- var safeGet_default = safeGet;
836
+ var baseKeysIn_default = baseKeysIn;
837
+
838
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/keysIn.js
839
+ function keysIn(object) {
840
+ return isArrayLike_default(object) ? arrayLikeKeys_default(object, true) : baseKeysIn_default(object);
841
+ }
842
+ var keysIn_default = keysIn;
1251
843
 
1252
844
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/toPlainObject.js
1253
845
  function toPlainObject(value) {
@@ -1457,7 +1049,6 @@ var mergeWith_default = mergeWith;
1457
1049
  var AIMarkdownRenderExtraSyntax = /* @__PURE__ */ ((AIMarkdownRenderExtraSyntax2) => {
1458
1050
  AIMarkdownRenderExtraSyntax2["HIGHLIGHT"] = "HIGHLIGHT";
1459
1051
  AIMarkdownRenderExtraSyntax2["DEFINITION_LIST"] = "DEFINITION_LIST";
1460
- AIMarkdownRenderExtraSyntax2["SUBSCRIPT"] = "SUBSCRIPT";
1461
1052
  return AIMarkdownRenderExtraSyntax2;
1462
1053
  })(AIMarkdownRenderExtraSyntax || {});
1463
1054
  var AIMarkdownRenderDisplayOptimizeAbility = /* @__PURE__ */ ((AIMarkdownRenderDisplayOptimizeAbility2) => {
@@ -1469,14 +1060,15 @@ var AIMarkdownRenderDisplayOptimizeAbility = /* @__PURE__ */ ((AIMarkdownRenderD
1469
1060
  var defaultAIMarkdownRenderConfig = Object.freeze({
1470
1061
  extraSyntaxSupported: Object.freeze([
1471
1062
  "HIGHLIGHT" /* HIGHLIGHT */,
1472
- "DEFINITION_LIST" /* DEFINITION_LIST */,
1473
- "SUBSCRIPT" /* SUBSCRIPT */
1063
+ "DEFINITION_LIST" /* DEFINITION_LIST */
1474
1064
  ]),
1475
1065
  displayOptimizeAbilities: Object.freeze([
1476
1066
  "REMOVE_COMMENTS" /* REMOVE_COMMENTS */,
1477
1067
  "SMARTYPANTS" /* SMARTYPANTS */,
1478
1068
  "PANGU" /* PANGU */
1479
- ])
1069
+ ]),
1070
+ blockMemoEnabled: true,
1071
+ preserveOrphanReferences: true
1480
1072
  });
1481
1073
 
1482
1074
  // src/context.tsx
@@ -1509,24 +1101,35 @@ var AIMarkdownRenderStateProvider = ({
1509
1101
  fontSize,
1510
1102
  variant,
1511
1103
  colorScheme,
1104
+ documentId,
1512
1105
  defaultConfig,
1513
1106
  config,
1514
1107
  children
1515
1108
  }) => {
1516
1109
  const baseConfig = defaultConfig ?? defaultAIMarkdownRenderConfig;
1517
1110
  const mergedConfig = useMemo(
1518
- () => config ? mergeWith_default(cloneDeep_default(baseConfig), config, configMergeCustomizer) : baseConfig,
1111
+ () => config ? mergeWith_default({}, baseConfig, config, configMergeCustomizer) : baseConfig,
1519
1112
  [baseConfig, config]
1520
1113
  );
1114
+ const fallbackId = useId();
1115
+ const resolvedDocumentId = documentId && documentId.length > 0 ? documentId : fallbackId;
1521
1116
  const state = useMemo(
1522
1117
  () => Object.freeze({
1523
1118
  streaming,
1524
1119
  fontSize,
1525
1120
  variant,
1526
1121
  colorScheme,
1122
+ documentId: resolvedDocumentId,
1123
+ // URI-fragment safe per-document prefix derived once here so downstream
1124
+ // consumers (MarkdownContent, cross-chunk placeholder components) read
1125
+ // from one canonical source. `encodeURIComponent` runs at the prefix
1126
+ // construction site, not at the documentId storage site, so consumers
1127
+ // accessing `documentId` directly still see the raw React-native value
1128
+ // (e.g. `useId()`'s `_r_0_`) while id="..."/href="#..." bytes are safe.
1129
+ clobberPrefix: `${encodeURIComponent(resolvedDocumentId)}-user-content-`,
1527
1130
  config: mergedConfig
1528
1131
  }),
1529
- [streaming, fontSize, variant, colorScheme, mergedConfig]
1132
+ [streaming, fontSize, variant, colorScheme, resolvedDocumentId, mergedConfig]
1530
1133
  );
1531
1134
  return /* @__PURE__ */ jsx(AIMarkdownRenderStateContext.Provider, { value: state, children });
1532
1135
  };
@@ -1540,10 +1143,42 @@ function getRepeatedMarkerLength(content, start, marker) {
1540
1143
  }
1541
1144
  return end - start;
1542
1145
  }
1146
+ var HTML_TAG_REGEX = /<\/?(span|div|p|br|hr|img|a|em|strong|b|i|u|s|sub|sup|code|pre|table|tr|td|th|thead|tbody|tfoot|ul|ol|li|dl|dt|dd|h[1-6]|blockquote|details|summary|figure|figcaption|section|article|aside|nav|header|footer|main|mark|del|ins|small|abbr|cite|dfn|kbd|samp|var|ruby|rt|rp|bdo|wbr|input|button|select|textarea|label|fieldset|legend|output|iframe|video|audio|source|canvas|svg|math|time)(?:\s[^>]*)?\/?>/iy;
1147
+ var LITERAL_CONTENT_TAGS = /* @__PURE__ */ new Set(["code", "pre", "kbd", "samp", "math", "svg"]);
1148
+ var LITERAL_CONTENT_CLOSE_REGEX = {
1149
+ code: /<\/code\s*>/gi,
1150
+ pre: /<\/pre\s*>/gi,
1151
+ kbd: /<\/kbd\s*>/gi,
1152
+ samp: /<\/samp\s*>/gi,
1153
+ math: /<\/math\s*>/gi,
1154
+ svg: /<\/svg\s*>/gi
1155
+ };
1156
+ function isAtLineStart(content, pos) {
1157
+ let i = pos - 1;
1158
+ let spaces = 0;
1159
+ while (i >= 0 && content[i] === " ") {
1160
+ spaces++;
1161
+ if (spaces > 3) return false;
1162
+ i--;
1163
+ }
1164
+ return i < 0 || content[i] === "\n" || content[i] === "\r";
1165
+ }
1166
+ function findClosingBacktickRun(content, start, n) {
1167
+ let i = start;
1168
+ while (i < content.length) {
1169
+ if (content[i] === "`") {
1170
+ const runLen = getRepeatedMarkerLength(content, i, "`");
1171
+ if (runLen === n) return i;
1172
+ i += runLen;
1173
+ } else {
1174
+ i += 1;
1175
+ }
1176
+ }
1177
+ return -1;
1178
+ }
1543
1179
  function splitByProtectedRegions(content) {
1544
1180
  const segments = [];
1545
1181
  let lastIndex = 0;
1546
- let inlineStart = -1;
1547
1182
  let multilineStart = -1;
1548
1183
  let multilineFenceMarker = null;
1549
1184
  let multilineFenceLength = 0;
@@ -1554,42 +1189,69 @@ function splitByProtectedRegions(content) {
1554
1189
  segments.push({ text: content.substring(start, end), isCode: true });
1555
1190
  lastIndex = end;
1556
1191
  }
1557
- for (let i = 0; i < content.length; i++) {
1192
+ let i = 0;
1193
+ while (i < content.length) {
1558
1194
  const char = content[i];
1559
- const fenceLength = char === "`" || char === "~" ? getRepeatedMarkerLength(content, i, char) : 0;
1560
- if ((char === "`" || char === "~") && fenceLength >= 3) {
1561
- if (multilineStart === -1) {
1562
- inlineStart = -1;
1195
+ if (multilineStart !== -1) {
1196
+ if (char === multilineFenceMarker) {
1197
+ const runLen = getRepeatedMarkerLength(content, i, multilineFenceMarker);
1198
+ if (runLen >= multilineFenceLength && isAtLineStart(content, i)) {
1199
+ pushProtected(multilineStart, i + runLen);
1200
+ multilineStart = -1;
1201
+ multilineFenceMarker = null;
1202
+ multilineFenceLength = 0;
1203
+ i += runLen;
1204
+ continue;
1205
+ }
1206
+ i += runLen;
1207
+ continue;
1208
+ }
1209
+ i += 1;
1210
+ continue;
1211
+ }
1212
+ if (char === "`" || char === "~") {
1213
+ const runLen = getRepeatedMarkerLength(content, i, char);
1214
+ if (runLen >= 3 && isAtLineStart(content, i)) {
1563
1215
  multilineStart = i;
1564
1216
  multilineFenceMarker = char;
1565
- multilineFenceLength = fenceLength;
1566
- i += fenceLength - 1;
1567
- } else if (char === multilineFenceMarker && fenceLength >= multilineFenceLength) {
1568
- pushProtected(multilineStart, i + fenceLength);
1569
- multilineStart = -1;
1570
- multilineFenceMarker = null;
1571
- multilineFenceLength = 0;
1572
- i += fenceLength - 1;
1573
- } else {
1574
- i += fenceLength - 1;
1217
+ multilineFenceLength = runLen;
1218
+ i += runLen;
1219
+ continue;
1575
1220
  }
1576
- } else if (char === "`" && multilineStart === -1) {
1577
- if (inlineStart === -1) {
1578
- inlineStart = i;
1579
- } else {
1580
- pushProtected(inlineStart, i + 1);
1581
- inlineStart = -1;
1221
+ if (char === "`") {
1222
+ const closeIdx = findClosingBacktickRun(content, i + runLen, runLen);
1223
+ if (closeIdx !== -1) {
1224
+ pushProtected(i, closeIdx + runLen);
1225
+ i = closeIdx + runLen;
1226
+ continue;
1227
+ }
1582
1228
  }
1583
- } else if (char === "<" && multilineStart === -1 && inlineStart === -1) {
1584
- const rest = content.substring(i);
1585
- const tagMatch = rest.match(
1586
- /^<\/?(span|div|p|br|hr|img|a|em|strong|b|i|u|s|sub|sup|code|pre|table|tr|td|th|thead|tbody|tfoot|ul|ol|li|dl|dt|dd|h[1-6]|blockquote|details|summary|figure|figcaption|section|article|aside|nav|header|footer|main|mark|del|ins|small|abbr|cite|dfn|kbd|samp|var|ruby|rt|rp|bdo|wbr|input|button|select|textarea|label|fieldset|legend|output|iframe|video|audio|source|canvas|svg|math|time)(?:\s[^>]*)?\/?>/i
1587
- );
1229
+ i += runLen;
1230
+ continue;
1231
+ }
1232
+ if (char === "<") {
1233
+ HTML_TAG_REGEX.lastIndex = i;
1234
+ const tagMatch = HTML_TAG_REGEX.exec(content);
1588
1235
  if (tagMatch) {
1589
- pushProtected(i, i + tagMatch[0].length);
1590
- i += tagMatch[0].length - 1;
1236
+ let endIndex = i + tagMatch[0].length;
1237
+ const tagName = tagMatch[1].toLowerCase();
1238
+ const isOpeningPairedTag = content[i + 1] !== "/" && !tagMatch[0].endsWith("/>") && LITERAL_CONTENT_TAGS.has(tagName);
1239
+ if (isOpeningPairedTag) {
1240
+ const closeRegex = LITERAL_CONTENT_CLOSE_REGEX[tagName];
1241
+ closeRegex.lastIndex = endIndex;
1242
+ const closeMatch = closeRegex.exec(content);
1243
+ if (closeMatch) {
1244
+ endIndex = closeMatch.index + closeMatch[0].length;
1245
+ } else {
1246
+ endIndex = content.length;
1247
+ }
1248
+ }
1249
+ pushProtected(i, endIndex);
1250
+ i = endIndex;
1251
+ continue;
1591
1252
  }
1592
1253
  }
1254
+ i += 1;
1593
1255
  }
1594
1256
  if (multilineStart !== -1) {
1595
1257
  pushProtected(multilineStart, content.length);
@@ -1607,15 +1269,23 @@ var NO_ESCAPED_DOLLAR_REGEX = /(?<![\\$])\$(?!\$)/g;
1607
1269
  var DELIMITERS_REGEX = /(?<!!)\\\[([\S\s]*?[^\\])\\](?!\()|\\\((.*?)\\\)/g;
1608
1270
  var ARRAY_COL_SPEC_OR_PIPE_REGEX = /(\\begin\{(?:array|tabular[x*]?)\}\{[^}]*\})|(?<!\\)\|/g;
1609
1271
  var LATEX_BLOCK_REGEX = /\$\$([\S\s]*?)\$\$|(?<![\\$])\$(?!\$)((?:[^$\n]|\\\$)*?)(?<![\\`])\$(?!\$)/g;
1610
- var ESCAPE_TEXT_UNDERSCORES_REGEX = /\\text{([^}]*)}/g;
1272
+ var TEXT_COMMAND = "\\text{";
1611
1273
  var SINGLE_DOLLAR_REGEX = /(?<![\\$])\$(?!\$)((?:[^$\n]|\\[$])+?)(?<!\\)(?<!`)\$(?!\$)/g;
1612
1274
  function escapeCurrencyDollarSigns(text) {
1613
1275
  const parts = [];
1614
1276
  let lastIndex = 0;
1615
1277
  const currencyMatches = Array.from(text.matchAll(CURRENCY_REGEX));
1278
+ let currentLineProcessed = "";
1616
1279
  for (let i = 0; i < currencyMatches.length; i++) {
1617
1280
  const match = currencyMatches[i];
1618
- parts.push(text.substring(lastIndex, match.index));
1281
+ const segment = text.substring(lastIndex, match.index);
1282
+ parts.push(segment);
1283
+ const newlineIdx = Math.max(segment.lastIndexOf("\n"), segment.lastIndexOf("\r"));
1284
+ if (newlineIdx !== -1) {
1285
+ currentLineProcessed = segment.substring(newlineIdx + 1);
1286
+ } else {
1287
+ currentLineProcessed += segment;
1288
+ }
1619
1289
  let needEscape = true;
1620
1290
  let restBeforeNextMatchOrEnd = "";
1621
1291
  if (i < currencyMatches.length - 1) {
@@ -1628,14 +1298,14 @@ function escapeCurrencyDollarSigns(text) {
1628
1298
  }
1629
1299
  const firstLineBeforeNextMatch = restBeforeNextMatchOrEnd.split(/\r\n|\r|\n/g)[0];
1630
1300
  if (Array.from(firstLineBeforeNextMatch.matchAll(NO_ESCAPED_DOLLAR_REGEX)).length % 2 !== 0) {
1631
- const previousNewContent = parts.join("");
1632
- const previousLastLineContent = previousNewContent.split(/\r\n|\r|\n/g).pop();
1633
- const wholeLineBeforeNextMatchWithoutCurrentDollar = previousLastLineContent + firstLineBeforeNextMatch;
1301
+ const wholeLineBeforeNextMatchWithoutCurrentDollar = currentLineProcessed + firstLineBeforeNextMatch;
1634
1302
  if (Array.from(wholeLineBeforeNextMatchWithoutCurrentDollar.matchAll(NO_ESCAPED_DOLLAR_REGEX)).length % 2 !== 0) {
1635
1303
  needEscape = false;
1636
1304
  }
1637
1305
  }
1638
- parts.push(needEscape ? "\\$" : "$");
1306
+ const replacement = needEscape ? "\\$" : "$";
1307
+ parts.push(replacement);
1308
+ currentLineProcessed += replacement;
1639
1309
  lastIndex = match.index + 1;
1640
1310
  }
1641
1311
  parts.push(text.substring(lastIndex));
@@ -1669,14 +1339,23 @@ function escapeLatexPipes(text) {
1669
1339
  return match;
1670
1340
  });
1671
1341
  }
1342
+ function isEscapedByBackslashRun(text, pos) {
1343
+ let count = 0;
1344
+ let j = pos - 1;
1345
+ while (j >= 0 && text[j] === "\\") {
1346
+ count++;
1347
+ j--;
1348
+ }
1349
+ return count % 2 === 1;
1350
+ }
1672
1351
  function findUnclosedDelimiterStart(text, mode) {
1673
1352
  let unclosedStart = -1;
1674
1353
  let i = 0;
1675
1354
  while (i < text.length) {
1676
- if (text[i] === "$" && i + 1 < text.length && text[i + 1] === "$") {
1355
+ if (text[i] === "$" && i + 1 < text.length && text[i + 1] === "$" && !isEscapedByBackslashRun(text, i)) {
1677
1356
  unclosedStart = unclosedStart === -1 ? i : -1;
1678
1357
  i += 2;
1679
- } else if (mode === "both" && text[i] === "$" && (i === 0 || text[i - 1] !== "\\") && (i + 1 >= text.length || text[i + 1] !== "$")) {
1358
+ } else if (mode === "both" && text[i] === "$" && !isEscapedByBackslashRun(text, i) && (i + 1 >= text.length || text[i + 1] !== "$")) {
1680
1359
  unclosedStart = unclosedStart === -1 ? i : -1;
1681
1360
  i += 1;
1682
1361
  } else {
@@ -1700,10 +1379,41 @@ function truncateUnclosedLatexBlock(text) {
1700
1379
  return text.substring(0, unclosedStart).trimEnd();
1701
1380
  }
1702
1381
  function escapeTextUnderscores(text) {
1703
- return text.replaceAll(ESCAPE_TEXT_UNDERSCORES_REGEX, (_match, textContent) => {
1704
- const escapedTextContent = textContent.replaceAll(/(?<!\\)_/g, "\\_");
1705
- return `\\text{${escapedTextContent}}`;
1706
- });
1382
+ let out = "";
1383
+ let i = 0;
1384
+ while (i < text.length) {
1385
+ const start = text.indexOf(TEXT_COMMAND, i);
1386
+ if (start === -1) {
1387
+ out += text.substring(i);
1388
+ return out;
1389
+ }
1390
+ out += text.substring(i, start);
1391
+ const bodyStart = start + TEXT_COMMAND.length;
1392
+ let depth = 1;
1393
+ let j = bodyStart;
1394
+ while (j < text.length && depth > 0) {
1395
+ const c = text[j];
1396
+ if (c === "\\" && j + 1 < text.length) {
1397
+ j += 2;
1398
+ continue;
1399
+ }
1400
+ if (c === "{") depth++;
1401
+ else if (c === "}") {
1402
+ depth--;
1403
+ if (depth === 0) break;
1404
+ }
1405
+ j++;
1406
+ }
1407
+ if (depth !== 0) {
1408
+ out += text.substring(start);
1409
+ return out;
1410
+ }
1411
+ const body = text.substring(bodyStart, j);
1412
+ const escapedBody = body.replaceAll(/(?<!\\)_/g, "\\_");
1413
+ out += `\\text{${escapedBody}}`;
1414
+ i = j + 1;
1415
+ }
1416
+ return out;
1707
1417
  }
1708
1418
  function convertSingleToDoubleDollar(text) {
1709
1419
  return text.replaceAll(SINGLE_DOLLAR_REGEX, (_match, content) => `$$${content}$$`);
@@ -1724,39 +1434,1353 @@ function preprocessLaTeX(str) {
1724
1434
  text = truncateUnclosedLatexBlock(text);
1725
1435
  return text;
1726
1436
  });
1727
- return result.join("");
1437
+ return result.join("");
1438
+ }
1439
+
1440
+ // src/preprocessors/index.ts
1441
+ function applyPreprocessors(value, ...fns) {
1442
+ return fns.reduce((result, fn) => fn(result), value);
1443
+ }
1444
+ var defaultExtraPreprocessors = [];
1445
+ function preprocessAIMDContent(content, extraPreprocessors = defaultExtraPreprocessors) {
1446
+ return applyPreprocessors(content, preprocessLaTeX, ...extraPreprocessors);
1447
+ }
1448
+
1449
+ // src/components/MarkdownContent.tsx
1450
+ import { Fragment as Fragment3, memo as memo2, useCallback as useCallback2, useEffect, useId as useId2, useMemo as useMemo4, useRef as useRef2, useState, useSyncExternalStore as useSyncExternalStore2 } from "react";
1451
+
1452
+ // src/components/markdown/Markdown.tsx
1453
+ import { unreachable as unreachable2 } from "devlop";
1454
+ import { toJsxRuntime } from "hast-util-to-jsx-runtime";
1455
+ import { Fragment } from "react";
1456
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
1457
+ import { visit } from "unist-util-visit";
1458
+
1459
+ // src/components/markdown/processor.ts
1460
+ import { unreachable } from "devlop";
1461
+ import remarkParse from "remark-parse";
1462
+ import remarkRehype from "remark-rehype";
1463
+ import { unified } from "unified";
1464
+ import { VFile } from "vfile";
1465
+ var emptyPlugins = [];
1466
+ var emptyRemarkRehypeOptions = { allowDangerousHtml: true };
1467
+ function createProcessor(options) {
1468
+ const rehypePlugins = options.rehypePlugins || emptyPlugins;
1469
+ const remarkPlugins = options.remarkPlugins || emptyPlugins;
1470
+ const remarkRehypeOptions = options.remarkRehypeOptions ? { ...options.remarkRehypeOptions, ...emptyRemarkRehypeOptions } : emptyRemarkRehypeOptions;
1471
+ return unified().use(remarkParse).use(remarkPlugins).use(remarkRehype, remarkRehypeOptions).use(rehypePlugins);
1472
+ }
1473
+ function createFile(options) {
1474
+ const children = options.children || "";
1475
+ const file = new VFile();
1476
+ if (typeof children === "string") {
1477
+ file.value = children;
1478
+ } else {
1479
+ unreachable("Unexpected value `" + String(children) + "` for `children` prop, expected `string`");
1480
+ }
1481
+ return file;
1482
+ }
1483
+
1484
+ // src/components/markdown/transform.ts
1485
+ import { urlAttributes } from "html-url-attributes";
1486
+ function buildTransform(ctx) {
1487
+ return function transform(node, index, parent) {
1488
+ if (node.type === "raw" && parent && typeof index === "number") {
1489
+ if (ctx.skipHtml) {
1490
+ parent.children.splice(index, 1);
1491
+ } else {
1492
+ parent.children[index] = { type: "text", value: node.value };
1493
+ }
1494
+ return index;
1495
+ }
1496
+ if (node.type === "element") {
1497
+ const element = node;
1498
+ let key;
1499
+ for (key in urlAttributes) {
1500
+ if (Object.hasOwn(urlAttributes, key) && Object.hasOwn(element.properties, key)) {
1501
+ const value = element.properties[key];
1502
+ const test = urlAttributes[key];
1503
+ if (test === null || test.includes(element.tagName)) {
1504
+ element.properties[key] = ctx.urlTransform(String(value || ""), key, element);
1505
+ }
1506
+ }
1507
+ }
1508
+ }
1509
+ if (node.type === "element") {
1510
+ const element = node;
1511
+ let remove = ctx.allowedElements ? !ctx.allowedElements.includes(element.tagName) : ctx.disallowedElements ? ctx.disallowedElements.includes(element.tagName) : false;
1512
+ if (!remove && ctx.allowElement && typeof index === "number") {
1513
+ remove = !ctx.allowElement(element, index, parent);
1514
+ }
1515
+ if (remove && parent && typeof index === "number") {
1516
+ if (ctx.unwrapDisallowed && element.children) {
1517
+ parent.children.splice(index, 1, ...element.children);
1518
+ } else {
1519
+ parent.children.splice(index, 1);
1520
+ }
1521
+ return index;
1522
+ }
1523
+ }
1524
+ return void 0;
1525
+ };
1526
+ }
1527
+
1528
+ // src/components/markdown/urlTransform.ts
1529
+ var safeProtocol = /^(https?|ircs?|mailto|xmpp)$/i;
1530
+ var defaultUrlTransform = (value) => {
1531
+ const colon = value.indexOf(":");
1532
+ const questionMark = value.indexOf("?");
1533
+ const numberSign = value.indexOf("#");
1534
+ const slash = value.indexOf("/");
1535
+ if (
1536
+ // No protocol → relative.
1537
+ colon === -1 || // First colon is after `/`, `?`, or `#` → not a protocol.
1538
+ slash !== -1 && colon > slash || questionMark !== -1 && colon > questionMark || numberSign !== -1 && colon > numberSign || // Allowed protocol.
1539
+ safeProtocol.test(value.slice(0, colon))
1540
+ ) {
1541
+ return value;
1542
+ }
1543
+ return "";
1544
+ };
1545
+
1546
+ // src/components/markdown/Markdown.tsx
1547
+ var changelog = "https://github.com/remarkjs/react-markdown/blob/main/changelog.md";
1548
+ var deprecations = [
1549
+ { from: "astPlugins", id: "remove-buggy-html-in-markdown-parser" },
1550
+ { from: "allowDangerousHtml", id: "remove-buggy-html-in-markdown-parser" },
1551
+ {
1552
+ from: "allowNode",
1553
+ id: "replace-allownode-allowedtypes-and-disallowedtypes",
1554
+ to: "allowElement"
1555
+ },
1556
+ {
1557
+ from: "allowedTypes",
1558
+ id: "replace-allownode-allowedtypes-and-disallowedtypes",
1559
+ to: "allowedElements"
1560
+ },
1561
+ { from: "className", id: "remove-classname" },
1562
+ {
1563
+ from: "disallowedTypes",
1564
+ id: "replace-allownode-allowedtypes-and-disallowedtypes",
1565
+ to: "disallowedElements"
1566
+ },
1567
+ { from: "escapeHtml", id: "remove-buggy-html-in-markdown-parser" },
1568
+ { from: "includeElementIndex", id: "#remove-includeelementindex" },
1569
+ {
1570
+ from: "includeNodeIndex",
1571
+ id: "change-includenodeindex-to-includeelementindex"
1572
+ },
1573
+ { from: "linkTarget", id: "remove-linktarget" },
1574
+ { from: "plugins", id: "change-plugins-to-remarkplugins", to: "remarkPlugins" },
1575
+ { from: "rawSourcePos", id: "#remove-rawsourcepos" },
1576
+ { from: "renderers", id: "change-renderers-to-components", to: "components" },
1577
+ { from: "source", id: "change-source-to-children", to: "children" },
1578
+ { from: "sourcePos", id: "#remove-sourcepos" },
1579
+ { from: "transformImageUri", id: "#add-urltransform", to: "urlTransform" },
1580
+ { from: "transformLinkUri", id: "#add-urltransform", to: "urlTransform" }
1581
+ ];
1582
+ function validateOptions(options) {
1583
+ for (const deprecation of deprecations) {
1584
+ if (Object.hasOwn(options, deprecation.from)) {
1585
+ unreachable2(
1586
+ "Unexpected `" + deprecation.from + "` prop, " + (deprecation.to ? "use `" + deprecation.to + "` instead" : "remove it") + " (see <" + changelog + "#" + deprecation.id + "> for more info)"
1587
+ );
1588
+ }
1589
+ }
1590
+ if (options.allowedElements && options.disallowedElements) {
1591
+ unreachable2("Unexpected combined `allowedElements` and `disallowedElements`, expected one or the other");
1592
+ }
1593
+ }
1594
+ function parseStage(options) {
1595
+ validateOptions(options);
1596
+ const processor2 = createProcessor(options);
1597
+ const file = createFile(options);
1598
+ const mdast = processor2.parse(file);
1599
+ return { processor: processor2, file, mdast };
1600
+ }
1601
+ function transformStage(parsed) {
1602
+ return parsed.processor.runSync(parsed.mdast, parsed.file);
1603
+ }
1604
+ function renderHastSubtree(tree, options) {
1605
+ const root2 = tree.type === "root" ? tree : { type: "root", children: [tree] };
1606
+ visit(
1607
+ root2,
1608
+ buildTransform({
1609
+ allowedElements: options.allowedElements,
1610
+ allowElement: options.allowElement,
1611
+ disallowedElements: options.disallowedElements,
1612
+ skipHtml: options.skipHtml,
1613
+ unwrapDisallowed: options.unwrapDisallowed,
1614
+ urlTransform: options.urlTransform || defaultUrlTransform
1615
+ })
1616
+ );
1617
+ return toJsxRuntime(root2, {
1618
+ Fragment,
1619
+ components: options.components,
1620
+ ignoreInvalidStyle: true,
1621
+ jsx: jsx2,
1622
+ jsxs,
1623
+ passKeys: true,
1624
+ passNode: true
1625
+ });
1626
+ }
1627
+ function Markdown(options) {
1628
+ const parsed = parseStage(options);
1629
+ const tree = transformStage(parsed);
1630
+ return renderHastSubtree(tree, options);
1631
+ }
1632
+ var Markdown_default = Markdown;
1633
+
1634
+ // src/components/MarkdownContent.tsx
1635
+ import rehypeKatex from "rehype-katex";
1636
+ import rehypeRaw from "rehype-raw";
1637
+ import rehypeUnwrapImages from "rehype-unwrap-images";
1638
+ import rehypeSanitize from "rehype-sanitize";
1639
+
1640
+ // src/components/sanitizeSchema.ts
1641
+ import { defaultSchema } from "rehype-sanitize";
1642
+ function mergeClassNameAllowlist(existing, extraClassNames) {
1643
+ const entries = existing ? [...existing] : [];
1644
+ const idx = entries.findIndex(
1645
+ (entry) => typeof entry === "string" ? entry === "className" : entry[0] === "className"
1646
+ );
1647
+ if (idx === -1) {
1648
+ return [...entries, ["className", ...extraClassNames]];
1649
+ }
1650
+ const current = entries[idx];
1651
+ const merged = typeof current === "string" ? ["className", ...extraClassNames] : [...current, ...extraClassNames];
1652
+ entries[idx] = merged;
1653
+ return entries;
1654
+ }
1655
+ var crossChunkTags = ["cross-chunk-link", "cross-chunk-image", "footnote-sup"];
1656
+ var sanitizeSchema = {
1657
+ ...defaultSchema,
1658
+ tagNames: [...defaultSchema.tagNames || [], "mark", ...crossChunkTags],
1659
+ attributes: {
1660
+ ...defaultSchema.attributes,
1661
+ code: mergeClassNameAllowlist(defaultSchema.attributes?.code, ["math-inline", "math-display"]),
1662
+ "cross-chunk-link": ["label", "referenceType", "documentId"],
1663
+ "cross-chunk-image": ["label", "referenceType", "documentId", "alt"],
1664
+ "footnote-sup": ["label", "localOccurrence", "documentId"]
1665
+ }
1666
+ };
1667
+
1668
+ // src/components/rehypeRebaseHashLinks.ts
1669
+ import { visit as visit2 } from "unist-util-visit";
1670
+ var DEFAULT_PREFIX = "user-content-";
1671
+ var rehypeRebaseHashLinks = (options) => {
1672
+ const prefix = options?.prefix ?? DEFAULT_PREFIX;
1673
+ const hashPrefix = "#" + prefix;
1674
+ return (tree) => {
1675
+ visit2(tree, "element", (node) => {
1676
+ if (node.tagName !== "a") return;
1677
+ const href = node.properties?.href;
1678
+ if (typeof href !== "string" || !href.startsWith("#")) return;
1679
+ if (href.startsWith(hashPrefix)) return;
1680
+ node.properties.href = hashPrefix + href.slice(1);
1681
+ });
1682
+ };
1683
+ };
1684
+ var rehypeRebaseHashLinks_default = rehypeRebaseHashLinks;
1685
+
1686
+ // src/components/rehypeFooterAdorn.ts
1687
+ import { visit as visit3 } from "unist-util-visit";
1688
+ var FOOTNOTE_LABEL_ID_RE = /(?:^|-)footnote-label$/;
1689
+ function isFootnoteLabelH2(node) {
1690
+ if (node.type !== "element") return false;
1691
+ const el = node;
1692
+ if (el.tagName !== "h2") return false;
1693
+ const id = el.properties?.id;
1694
+ return typeof id === "string" && FOOTNOTE_LABEL_ID_RE.test(id);
1695
+ }
1696
+ function isHr(node) {
1697
+ if (node.type !== "element") return false;
1698
+ return node.tagName === "hr";
1699
+ }
1700
+ function rehypeFooterAdorn() {
1701
+ return (tree) => {
1702
+ visit3(tree, "element", (n) => {
1703
+ const el = n;
1704
+ if (el.tagName !== "section") return;
1705
+ if (!(el.properties && "dataFootnotes" in el.properties)) return;
1706
+ const filtered = el.children.filter((c) => !isFootnoteLabelH2(c));
1707
+ if (!filtered.some(isHr)) {
1708
+ const hr = {
1709
+ type: "element",
1710
+ tagName: "hr",
1711
+ properties: {},
1712
+ children: []
1713
+ };
1714
+ filtered.unshift(hr);
1715
+ }
1716
+ el.children = filtered;
1717
+ if (!el.properties) el.properties = {};
1718
+ if (!("ariaLabel" in el.properties)) {
1719
+ el.properties.ariaLabel = "Footnotes";
1720
+ }
1721
+ });
1722
+ };
1723
+ }
1724
+
1725
+ // src/components/MarkdownContent.tsx
1726
+ import remarkBreaks from "remark-breaks";
1727
+ import remarkCjkFriendly from "remark-cjk-friendly";
1728
+ import remarkCjkFriendlyGfmStrikethrough from "remark-cjk-friendly-gfm-strikethrough";
1729
+ import remarkEmoji from "remark-emoji";
1730
+ import remarkGfm2 from "remark-gfm";
1731
+ import remarkMath from "remark-math";
1732
+ import { remarkDefinitionList, defListHastHandlers } from "remark-definition-list";
1733
+ import { remarkMark as remarkMarkHighlight } from "remark-mark-highlight";
1734
+ import remarkSqueezeParagraphs from "remark-squeeze-paragraphs";
1735
+ import remarkSmartypants from "remark-smartypants";
1736
+ import remarkPangu from "remark-pangu";
1737
+ import remarkRemoveComments from "remark-remove-comments";
1738
+
1739
+ // src/components/blockMemo.ts
1740
+ import { visit as visit4 } from "unist-util-visit";
1741
+
1742
+ // src/components/normalizeId.ts
1743
+ function normalizeId(s) {
1744
+ return s.replace(/\s+/g, " ").toUpperCase();
1745
+ }
1746
+ function normalizeForMatch(s) {
1747
+ return s.replace(/\\(.)/g, "$1").replace(/\s+/g, " ").toUpperCase();
1748
+ }
1749
+
1750
+ // src/components/blockMemo.ts
1751
+ var TAINT_TYPES = /* @__PURE__ */ new Set([
1752
+ "footnoteReference",
1753
+ "footnoteDefinition",
1754
+ "linkReference",
1755
+ "imageReference",
1756
+ "definition"
1757
+ ]);
1758
+ var CTX_TYPES = TAINT_TYPES;
1759
+ function createCache() {
1760
+ return { blocks: /* @__PURE__ */ new Map() };
1761
+ }
1762
+ function extractRaw(node, source) {
1763
+ if (!node.position) return "";
1764
+ return source.slice(node.position.start.offset, node.position.end.offset);
1765
+ }
1766
+ function isFootnoteSection(node) {
1767
+ if (node.tagName !== "section") return false;
1768
+ const props = node.properties;
1769
+ return props?.dataFootnotes !== void 0;
1770
+ }
1771
+ function hasMdastSource(node) {
1772
+ return node.position !== void 0;
1773
+ }
1774
+ var FOOTNOTE_SECTION_KEY = "__footnote_section__";
1775
+ function buildBlocks(mdast, hast, source) {
1776
+ const mdastByOffset = /* @__PURE__ */ new Map();
1777
+ const mdastRanges = [];
1778
+ for (const child of mdast.children) {
1779
+ const off = child.position?.start.offset;
1780
+ const endOff = child.position?.end.offset;
1781
+ if (off !== void 0) {
1782
+ mdastByOffset.set(off, child);
1783
+ }
1784
+ if (off !== void 0 && endOff !== void 0) {
1785
+ mdastRanges.push({ start: off, end: endOff, node: child });
1786
+ }
1787
+ }
1788
+ if (process.env.NODE_ENV !== "production") {
1789
+ for (let i = 1; i < mdastRanges.length; i++) {
1790
+ if (mdastRanges[i].start < mdastRanges[i - 1].start) {
1791
+ throw new Error(
1792
+ "block-memo: mdast.children not sorted by source offset \u2014 a remark plugin is reordering top-level children."
1793
+ );
1794
+ }
1795
+ }
1796
+ }
1797
+ function findContainingMdast(offset) {
1798
+ let lo = 0;
1799
+ let hi = mdastRanges.length;
1800
+ while (lo < hi) {
1801
+ const mid = lo + hi >>> 1;
1802
+ if (mdastRanges[mid].start <= offset) lo = mid + 1;
1803
+ else hi = mid;
1804
+ }
1805
+ const idx = lo - 1;
1806
+ if (idx < 0) return void 0;
1807
+ const r = mdastRanges[idx];
1808
+ return offset < r.end ? r.node : void 0;
1809
+ }
1810
+ const ctxParts = [];
1811
+ visit4(mdast, (n) => {
1812
+ if (!CTX_TYPES.has(n.type)) return;
1813
+ if (n.type === "footnoteReference") ctxParts.push(["fr", n.identifier]);
1814
+ else if (n.type === "footnoteDefinition") ctxParts.push(["fd", n.identifier, extractRaw(n, source)]);
1815
+ else if (n.type === "linkReference") ctxParts.push(["lr", n.identifier]);
1816
+ else if (n.type === "imageReference") ctxParts.push(["ir", n.identifier]);
1817
+ else if (n.type === "definition") ctxParts.push(["d", n.identifier, n.url, n.title ?? null]);
1818
+ });
1819
+ const globalCtx = JSON.stringify(ctxParts);
1820
+ const plan = [];
1821
+ const blocks = [];
1822
+ const blockHasts = [];
1823
+ let synthetic;
1824
+ for (let i = 0; i < hast.children.length; i++) {
1825
+ const hastChild = hast.children[i];
1826
+ if (hastChild.type !== "element") {
1827
+ const off = hastChild.position?.start.offset;
1828
+ const reactKey = off !== void 0 ? `inline-${off}` : `inline-i${i}`;
1829
+ plan.push({ kind: "inline", el: hastChild, reactKey });
1830
+ continue;
1831
+ }
1832
+ const el = hastChild;
1833
+ if (isFootnoteSection(el)) {
1834
+ synthetic = el;
1835
+ plan.push({ kind: "synthetic", el, reactKey: FOOTNOTE_SECTION_KEY });
1836
+ continue;
1837
+ }
1838
+ const hastOffset = el.position?.start.offset;
1839
+ if (hastOffset === void 0) {
1840
+ plan.push({ kind: "inline", el, reactKey: `inline-i${i}` });
1841
+ continue;
1842
+ }
1843
+ let mdastNode = mdastByOffset.get(hastOffset);
1844
+ if (!mdastNode) {
1845
+ mdastNode = findContainingMdast(hastOffset);
1846
+ }
1847
+ if (!mdastNode) {
1848
+ if (process.env.NODE_ENV !== "production") {
1849
+ throw new Error(
1850
+ `block-memo: hast block at offset ${hastOffset} has no mdast counterpart. A rehype plugin may have synthesized positions outside source. tagName=${el.tagName}`
1851
+ );
1852
+ }
1853
+ plan.push({ kind: "inline", el, reactKey: `inline-${hastOffset}` });
1854
+ continue;
1855
+ }
1856
+ if (mdastNode.type === "footnoteDefinition") {
1857
+ plan.push({ kind: "inline", el, reactKey: `inline-${hastOffset}` });
1858
+ continue;
1859
+ }
1860
+ let hasReference = false;
1861
+ const footnoteRefLabels = [];
1862
+ const linkRefLabels = [];
1863
+ const imageRefLabels = [];
1864
+ const footnoteDefLabels = [];
1865
+ visit4(mdastNode, (n) => {
1866
+ if (!TAINT_TYPES.has(n.type)) return;
1867
+ hasReference = true;
1868
+ const id = "identifier" in n ? normalizeId(String(n.identifier)) : null;
1869
+ if (id === null) return;
1870
+ if (n.type === "footnoteReference") footnoteRefLabels.push(id);
1871
+ else if (n.type === "linkReference") linkRefLabels.push(id);
1872
+ else if (n.type === "imageReference") imageRefLabels.push(id);
1873
+ else if (n.type === "footnoteDefinition") footnoteDefLabels.push(id);
1874
+ });
1875
+ const mdastPos = mdastNode.position;
1876
+ if (!mdastPos || mdastPos.start.offset === void 0 || mdastPos.end.offset === void 0) {
1877
+ continue;
1878
+ }
1879
+ const info = {
1880
+ raw: extractRaw(mdastNode, source),
1881
+ startOffset: mdastPos.start.offset,
1882
+ endOffset: mdastPos.end.offset,
1883
+ startLine: mdastPos.start.line,
1884
+ startColumn: mdastPos.start.column,
1885
+ hasReference,
1886
+ ...hasReference ? {
1887
+ taintLabels: { footnoteRefLabels, linkRefLabels, imageRefLabels, footnoteDefLabels }
1888
+ } : {}
1889
+ };
1890
+ blocks.push(info);
1891
+ blockHasts.push(el);
1892
+ plan.push({ kind: "block", el, info, reactKey: `block-${hastOffset}` });
1893
+ }
1894
+ return { plan, globalCtx, blocks, blockHasts, synthetic };
1895
+ }
1896
+ function computeBlockFingerprint(taintLabels, registry, thisChunkSym, clobberPrefix) {
1897
+ const parts = [clobberPrefix];
1898
+ for (const label of taintLabels.footnoteRefLabels) {
1899
+ parts.push(`fn:${label}=${registry.globalNumber(label) ?? "null"}`);
1900
+ }
1901
+ for (const label of taintLabels.linkRefLabels) {
1902
+ const def = registry.resolveLinkDef(label);
1903
+ parts.push(`lr:${label}=${def?.url ?? "null"}|${def?.title ?? ""}`);
1904
+ }
1905
+ for (const label of taintLabels.imageRefLabels) {
1906
+ const def = registry.resolveLinkDef(label);
1907
+ parts.push(`ir:${label}=${def?.url ?? "null"}|${def?.title ?? ""}`);
1908
+ }
1909
+ for (const label of taintLabels.footnoteDefLabels) {
1910
+ const isCanonical = registry.canonicalFootnoteFor(label) === thisChunkSym ? 1 : 0;
1911
+ parts.push(`fd:${label}=${isCanonical}/${registry.getRefsForLabel(label)}`);
1912
+ }
1913
+ return parts.join("|");
1914
+ }
1915
+ function renderBlocksWithCache(cacheRef, plan, globalCtx, postOptions) {
1916
+ const prev = cacheRef.current;
1917
+ const next = { blocks: /* @__PURE__ */ new Map() };
1918
+ const rendered = [];
1919
+ if (process.env.NODE_ENV !== "production") {
1920
+ for (const item of plan) {
1921
+ if (item.kind === "block" && !hasMdastSource(item.el)) {
1922
+ throw new Error(
1923
+ "block-memo: block hast child has no position. Did a rehype plugin strip it? (Run positionPropagation.test.ts to verify.)"
1924
+ );
1925
+ }
1926
+ }
1927
+ }
1928
+ for (const item of plan) {
1929
+ if (item.kind === "inline") {
1930
+ rendered.push({
1931
+ node: renderHastSubtree(item.el, postOptions),
1932
+ reactKey: item.reactKey
1933
+ });
1934
+ continue;
1935
+ }
1936
+ if (item.kind === "synthetic") {
1937
+ if (postOptions.registry && postOptions.thisChunkSymbol) {
1938
+ continue;
1939
+ }
1940
+ const cached = prev.footnoteSection;
1941
+ let node;
1942
+ if (cached && cached.ctx === globalCtx) {
1943
+ node = cached.node;
1944
+ } else {
1945
+ node = renderHastSubtree(item.el, postOptions);
1946
+ }
1947
+ next.footnoteSection = { ctx: globalCtx, node };
1948
+ rendered.push({ node, reactKey: item.reactKey });
1949
+ continue;
1950
+ }
1951
+ const block = item.info;
1952
+ let bucket = next.blocks.get(block.raw);
1953
+ if (!bucket) {
1954
+ bucket = [];
1955
+ next.blocks.set(block.raw, bucket);
1956
+ }
1957
+ const occ = bucket.length;
1958
+ if (block.hasReference) {
1959
+ const useFingerprint = postOptions.registry && block.taintLabels && postOptions.thisChunkSymbol && postOptions.clobberPrefix !== void 0;
1960
+ const blockCtx = useFingerprint ? computeBlockFingerprint(
1961
+ block.taintLabels,
1962
+ postOptions.registry,
1963
+ postOptions.thisChunkSymbol,
1964
+ postOptions.clobberPrefix
1965
+ ) : globalCtx;
1966
+ const entry = prev.blocks.get(block.raw)?.[occ];
1967
+ const valid = entry !== void 0 && entry.ctx === blockCtx && entry.startOffset === block.startOffset && entry.startLine === block.startLine && entry.startColumn === block.startColumn;
1968
+ let node;
1969
+ if (valid) {
1970
+ node = entry.node;
1971
+ } else {
1972
+ node = renderHastSubtree(item.el, postOptions);
1973
+ }
1974
+ bucket.push({
1975
+ node,
1976
+ ctx: blockCtx,
1977
+ startOffset: block.startOffset,
1978
+ startLine: block.startLine,
1979
+ startColumn: block.startColumn
1980
+ });
1981
+ rendered.push({ node, reactKey: item.reactKey });
1982
+ continue;
1983
+ }
1984
+ {
1985
+ const entry = prev.blocks.get(block.raw)?.[occ];
1986
+ const valid = entry !== void 0 && entry.ctx === "" && entry.startOffset === block.startOffset && entry.startLine === block.startLine && entry.startColumn === block.startColumn;
1987
+ const node = valid ? entry.node : renderHastSubtree(item.el, postOptions);
1988
+ bucket.push({
1989
+ node,
1990
+ ctx: "",
1991
+ startOffset: block.startOffset,
1992
+ startLine: block.startLine,
1993
+ startColumn: block.startColumn
1994
+ });
1995
+ rendered.push({ node, reactKey: item.reactKey });
1996
+ }
1997
+ }
1998
+ cacheRef.current = next;
1999
+ return rendered;
2000
+ }
2001
+
2002
+ // src/components/collectDefLabels.ts
2003
+ import { unified as unified2 } from "unified";
2004
+ import remarkParse2 from "remark-parse";
2005
+ import remarkGfm from "remark-gfm";
2006
+ import { visit as visit5 } from "unist-util-visit";
2007
+ function buildProcessor() {
2008
+ return unified2().use(remarkParse2).use(remarkGfm);
2009
+ }
2010
+ var _processor = null;
2011
+ function processor() {
2012
+ if (!_processor) _processor = buildProcessor();
2013
+ return _processor;
2014
+ }
2015
+ function collectDefLabels(source) {
2016
+ if (!source) {
2017
+ return { footnoteLabels: /* @__PURE__ */ new Set(), linkLabels: /* @__PURE__ */ new Set() };
2018
+ }
2019
+ const mdast = processor().parse(source);
2020
+ const footnoteLabels = /* @__PURE__ */ new Set();
2021
+ const linkLabels = /* @__PURE__ */ new Set();
2022
+ visit5(mdast, (node) => {
2023
+ if (node.type === "footnoteDefinition" && "identifier" in node) {
2024
+ footnoteLabels.add(normalizeId(node.identifier));
2025
+ } else if (node.type === "definition" && "identifier" in node) {
2026
+ linkLabels.add(normalizeId(node.identifier));
2027
+ }
2028
+ });
2029
+ return { footnoteLabels, linkLabels };
2030
+ }
2031
+
2032
+ // src/components/AIMarkdownDocuments.tsx
2033
+ import { createContext as createContext2, useContext as useContext2, useMemo as useMemo2, useRef } from "react";
2034
+
2035
+ // src/components/documentRegistry.ts
2036
+ function createRegistry(onEmpty) {
2037
+ const reg = {
2038
+ chunkOrder: [],
2039
+ chunkData: /* @__PURE__ */ new Map(),
2040
+ labelSet: { footnoteLabels: /* @__PURE__ */ new Set(), linkLabels: /* @__PURE__ */ new Set() },
2041
+ version: 0,
2042
+ _reactIdMap: /* @__PURE__ */ new Map(),
2043
+ _subscribers: /* @__PURE__ */ new Set(),
2044
+ _notifyScheduled: false,
2045
+ allocateSymbol(reactId) {
2046
+ const existing = this._reactIdMap.get(reactId);
2047
+ if (existing) {
2048
+ existing.refcount++;
2049
+ return existing.symbol;
2050
+ }
2051
+ const sym = Symbol(reactId);
2052
+ this._reactIdMap.set(reactId, { symbol: sym, refcount: 1 });
2053
+ this.chunkOrder.push(sym);
2054
+ this._notify();
2055
+ return sym;
2056
+ },
2057
+ registerChunk(reactId, footnotes, links) {
2058
+ const sym = this.allocateSymbol(reactId);
2059
+ this.contributeLabels(sym, footnotes, links);
2060
+ return sym;
2061
+ },
2062
+ releaseSymbol(reactId) {
2063
+ const entry = this._reactIdMap.get(reactId);
2064
+ if (!entry) return;
2065
+ entry.refcount--;
2066
+ if (entry.refcount === 0) {
2067
+ queueMicrotask(() => {
2068
+ const latest = this._reactIdMap.get(reactId);
2069
+ if (latest && latest.refcount === 0) {
2070
+ this._reactIdMap.delete(reactId);
2071
+ const idx = this.chunkOrder.indexOf(entry.symbol);
2072
+ if (idx !== -1) this.chunkOrder.splice(idx, 1);
2073
+ this.chunkData.delete(entry.symbol);
2074
+ const nextFn = /* @__PURE__ */ new Set();
2075
+ const nextLink = /* @__PURE__ */ new Set();
2076
+ for (const cd of this.chunkData.values()) {
2077
+ for (const l of cd.ownFootnoteLabels) nextFn.add(l);
2078
+ for (const l of cd.ownLinkLabels) nextLink.add(l);
2079
+ }
2080
+ this.labelSet.footnoteLabels = nextFn;
2081
+ this.labelSet.linkLabels = nextLink;
2082
+ this._notify();
2083
+ if (this.chunkOrder.length === 0 && this.chunkData.size === 0 && onEmpty) {
2084
+ onEmpty();
2085
+ }
2086
+ }
2087
+ });
2088
+ }
2089
+ },
2090
+ contributeLabels(symbol, footnotes, links) {
2091
+ const data = this.chunkData.get(symbol);
2092
+ if (data) {
2093
+ data.ownFootnoteLabels = footnotes;
2094
+ data.ownLinkLabels = links;
2095
+ } else {
2096
+ this.chunkData.set(symbol, {
2097
+ refs: [],
2098
+ defs: /* @__PURE__ */ new Map(),
2099
+ linkDefs: /* @__PURE__ */ new Map(),
2100
+ ownFootnoteLabels: footnotes,
2101
+ ownLinkLabels: links
2102
+ });
2103
+ }
2104
+ const newFn = /* @__PURE__ */ new Set();
2105
+ const newLink = /* @__PURE__ */ new Set();
2106
+ for (const cd of this.chunkData.values()) {
2107
+ for (const l of cd.ownFootnoteLabels) newFn.add(l);
2108
+ for (const l of cd.ownLinkLabels) newLink.add(l);
2109
+ }
2110
+ this.labelSet.footnoteLabels = newFn;
2111
+ this.labelSet.linkLabels = newLink;
2112
+ this._notify();
2113
+ },
2114
+ contributeChunkData(symbol, data) {
2115
+ this.chunkData.set(symbol, data);
2116
+ this.labelSet.footnoteLabels = /* @__PURE__ */ new Set();
2117
+ this.labelSet.linkLabels = /* @__PURE__ */ new Set();
2118
+ for (const cd of this.chunkData.values()) {
2119
+ for (const l of cd.ownFootnoteLabels) this.labelSet.footnoteLabels.add(l);
2120
+ for (const l of cd.ownLinkLabels) this.labelSet.linkLabels.add(l);
2121
+ }
2122
+ this._notify();
2123
+ },
2124
+ subscribe(cb) {
2125
+ this._subscribers.add(cb);
2126
+ return () => {
2127
+ this._subscribers.delete(cb);
2128
+ };
2129
+ },
2130
+ canonicalFootnoteFor(label) {
2131
+ const id = normalizeId(label);
2132
+ for (const sym of this.chunkOrder) {
2133
+ const data = this.chunkData.get(sym);
2134
+ if (data?.defs.has(id)) return sym;
2135
+ }
2136
+ return null;
2137
+ },
2138
+ canonicalLinkFor(label) {
2139
+ const id = normalizeId(label);
2140
+ for (const sym of this.chunkOrder) {
2141
+ const data = this.chunkData.get(sym);
2142
+ if (data?.linkDefs.has(id)) return sym;
2143
+ }
2144
+ return null;
2145
+ },
2146
+ globalNumber(label) {
2147
+ const id = normalizeId(label);
2148
+ let n = 0;
2149
+ const seen = /* @__PURE__ */ new Set();
2150
+ for (const sym of this.chunkOrder) {
2151
+ const data = this.chunkData.get(sym);
2152
+ if (!data) continue;
2153
+ for (const ref of data.refs) {
2154
+ if (ref.kind !== "footnote") continue;
2155
+ if (!seen.has(ref.label)) {
2156
+ seen.add(ref.label);
2157
+ n++;
2158
+ if (ref.label === id) return n;
2159
+ }
2160
+ }
2161
+ }
2162
+ return null;
2163
+ },
2164
+ resolveLinkDef(label) {
2165
+ const sym = this.canonicalLinkFor(label);
2166
+ if (!sym) return null;
2167
+ return this.chunkData.get(sym)?.linkDefs.get(normalizeId(label)) ?? null;
2168
+ },
2169
+ getRefsForLabel(label) {
2170
+ const id = normalizeId(label);
2171
+ let n = 0;
2172
+ for (const sym of this.chunkOrder) {
2173
+ const data = this.chunkData.get(sym);
2174
+ if (!data) continue;
2175
+ for (const ref of data.refs) {
2176
+ if (ref.kind === "footnote" && ref.label === id) n++;
2177
+ }
2178
+ }
2179
+ return n;
2180
+ },
2181
+ globalOccurrenceForRef(chunkSym, label, localOccurrence) {
2182
+ const id = normalizeId(label);
2183
+ let global2 = 0;
2184
+ for (const sym of this.chunkOrder) {
2185
+ const data = this.chunkData.get(sym);
2186
+ if (!data) continue;
2187
+ let localCount = 0;
2188
+ for (const ref of data.refs) {
2189
+ if (ref.kind !== "footnote") continue;
2190
+ if (ref.label !== id) continue;
2191
+ localCount++;
2192
+ global2++;
2193
+ if (sym === chunkSym && localCount === localOccurrence) return global2;
2194
+ }
2195
+ }
2196
+ return null;
2197
+ },
2198
+ _notify() {
2199
+ this.version++;
2200
+ if (this._notifyScheduled) return;
2201
+ this._notifyScheduled = true;
2202
+ queueMicrotask(() => {
2203
+ this._notifyScheduled = false;
2204
+ for (const cb of [...this._subscribers]) cb();
2205
+ });
2206
+ }
2207
+ };
2208
+ return reg;
2209
+ }
2210
+
2211
+ // src/components/AIMarkdownDocuments.tsx
2212
+ import { jsx as jsx3 } from "react/jsx-runtime";
2213
+ var AIMarkdownDocumentsContext = createContext2(null);
2214
+ var AIMarkdownDocuments = ({ preserveOrphanReferences = true, children }) => {
2215
+ const parent = useContext2(AIMarkdownDocumentsContext);
2216
+ if (parent !== null) {
2217
+ throw new Error(
2218
+ "<AIMarkdownDocuments> must not be nested inside another <AIMarkdownDocuments>. Use a single top-level wrapper per coordinated scope."
2219
+ );
2220
+ }
2221
+ const registriesRef = useRef(/* @__PURE__ */ new Map());
2222
+ const value = useMemo2(
2223
+ () => ({
2224
+ preserveOrphanReferences,
2225
+ getRegistry(documentId) {
2226
+ let r = registriesRef.current.get(documentId);
2227
+ if (!r) {
2228
+ const created = createRegistry(() => {
2229
+ if (registriesRef.current.get(documentId) === created) {
2230
+ registriesRef.current.delete(documentId);
2231
+ }
2232
+ });
2233
+ r = created;
2234
+ registriesRef.current.set(documentId, r);
2235
+ }
2236
+ return r;
2237
+ }
2238
+ }),
2239
+ [preserveOrphanReferences]
2240
+ );
2241
+ return /* @__PURE__ */ jsx3(AIMarkdownDocumentsContext.Provider, { value, children });
2242
+ };
2243
+ function useDocumentRegistry(documentId) {
2244
+ const ctx = useContext2(AIMarkdownDocumentsContext);
2245
+ if (!ctx || !documentId) return null;
2246
+ return ctx.getRegistry(documentId);
2247
+ }
2248
+ function usePreserveOrphanReferences(fallback) {
2249
+ const ctx = useContext2(AIMarkdownDocumentsContext);
2250
+ return ctx?.preserveOrphanReferences ?? fallback;
2251
+ }
2252
+
2253
+ // src/components/remarkInjectPhantomDefs.ts
2254
+ var SENTINEL_LINK_URL = "__aimd_sentinel_link__";
2255
+ var SENTINEL_FN_CONTENT = "__aimd_sentinel_fn__";
2256
+ function augmentSourceWithPhantoms(source, phantoms) {
2257
+ if (phantoms.missingFootnotes.size === 0 && phantoms.missingLinks.size === 0) {
2258
+ return source;
2259
+ }
2260
+ let suffix = "\n\n";
2261
+ for (const label of phantoms.missingLinks) {
2262
+ suffix += `[${label}]: ${SENTINEL_LINK_URL}
2263
+ `;
2264
+ }
2265
+ for (const label of phantoms.missingFootnotes) {
2266
+ suffix += `[^${label}]: ${SENTINEL_FN_CONTENT}
2267
+ `;
2268
+ }
2269
+ return source + suffix;
2270
+ }
2271
+
2272
+ // src/components/customMdastHandlers.ts
2273
+ function buildCrossChunkHandlers() {
2274
+ return {
2275
+ footnoteDefinition: (state, node) => {
2276
+ const s = state;
2277
+ const id = normalizeId(node.identifier);
2278
+ if (s.options.phantomFootnoteLabels.has(id)) {
2279
+ return void 0;
2280
+ }
2281
+ if (s.options.preserveOrphan && !s.footnoteOrder.includes(id)) {
2282
+ s.footnoteOrder.push(id);
2283
+ }
2284
+ return void 0;
2285
+ },
2286
+ linkReference: ((state, node) => {
2287
+ const s = state;
2288
+ const id = normalizeId(node.identifier);
2289
+ const resolved = s.definitionById.has(id);
2290
+ if (!resolved) {
2291
+ return void 0;
2292
+ }
2293
+ return {
2294
+ type: "element",
2295
+ tagName: "cross-chunk-link",
2296
+ properties: {
2297
+ // `label` is the ORIGINAL source text (mdast's `label` field), NOT
2298
+ // the normalized `identifier`. The placeholder uses it to construct
2299
+ // hrefs that line up with mdast-util-to-hast's default `<li id>`
2300
+ // which also preserves source case. Registry lookups normalize
2301
+ // internally, so cross-chunk case-insensitive matching still works.
2302
+ label: node.label ?? node.identifier,
2303
+ referenceType: node.referenceType,
2304
+ documentId: s.options.documentId
2305
+ },
2306
+ children: s.all(node)
2307
+ };
2308
+ }),
2309
+ imageReference: ((state, node) => {
2310
+ const s = state;
2311
+ const id = normalizeId(node.identifier);
2312
+ const resolved = s.definitionById.has(id);
2313
+ if (!resolved) return void 0;
2314
+ return {
2315
+ type: "element",
2316
+ tagName: "cross-chunk-image",
2317
+ properties: {
2318
+ label: node.label ?? node.identifier,
2319
+ referenceType: node.referenceType,
2320
+ alt: node.alt ?? "",
2321
+ documentId: s.options.documentId
2322
+ },
2323
+ children: []
2324
+ };
2325
+ }),
2326
+ footnoteReference: ((state, node) => {
2327
+ const s = state;
2328
+ const id = normalizeId(node.identifier);
2329
+ const localOccurrence = (s.footnoteCounts.get(id) ?? 0) + 1;
2330
+ s.footnoteCounts.set(id, localOccurrence);
2331
+ if (s.options.phantomFootnoteLabels.has(id)) {
2332
+ return {
2333
+ type: "element",
2334
+ tagName: "footnote-sup",
2335
+ properties: {
2336
+ label: node.identifier,
2337
+ localOccurrence,
2338
+ documentId: s.options.documentId
2339
+ },
2340
+ children: []
2341
+ };
2342
+ }
2343
+ if (!s.footnoteOrder.includes(id)) s.footnoteOrder.push(id);
2344
+ return {
2345
+ type: "element",
2346
+ tagName: "footnote-sup",
2347
+ properties: {
2348
+ label: node.identifier,
2349
+ localOccurrence,
2350
+ documentId: s.options.documentId
2351
+ },
2352
+ children: []
2353
+ };
2354
+ })
2355
+ };
2356
+ }
2357
+
2358
+ // src/components/crossChunkPlaceholders.tsx
2359
+ import { isValidElement, useCallback, useContext as useContext3, useSyncExternalStore } from "react";
2360
+
2361
+ // src/components/chunkSymbolContext.ts
2362
+ import { createContext as createContext3 } from "react";
2363
+ var ChunkSymbolContext = createContext3(null);
2364
+
2365
+ // src/components/crossChunkPlaceholders.tsx
2366
+ import { jsx as jsx4 } from "react/jsx-runtime";
2367
+ var SSR_NUM_SNAPSHOT = () => 0;
2368
+ var SSR_DEF_SNAPSHOT = () => null;
2369
+ function coerceLocalOccurrence(v) {
2370
+ if (v === void 0) return null;
2371
+ if (typeof v === "number") return Number.isFinite(v) && v >= 1 ? Math.trunc(v) : null;
2372
+ const n = Number(v);
2373
+ return Number.isFinite(n) && n >= 1 ? Math.trunc(n) : null;
2374
+ }
2375
+ function FootnoteSupNumber({ label, localOccurrence: localOccurrenceRaw }) {
2376
+ const localOccurrence = coerceLocalOccurrence(localOccurrenceRaw);
2377
+ const { documentId, clobberPrefix } = useAIMarkdownRenderState();
2378
+ const registry = useDocumentRegistry(documentId);
2379
+ const chunkSym = useContext3(ChunkSymbolContext);
2380
+ const subscribe = useCallback((cb) => registry ? registry.subscribe(cb) : () => {
2381
+ }, [registry]);
2382
+ const getSnapshot = useCallback(() => registry?.version ?? 0, [registry]);
2383
+ useSyncExternalStore(subscribe, getSnapshot, SSR_NUM_SNAPSHOT);
2384
+ const num = registry?.globalNumber(label) ?? null;
2385
+ if (num === null) return null;
2386
+ if (localOccurrence !== null && !chunkSym) return null;
2387
+ const globalOcc = registry && chunkSym && localOccurrence !== null ? registry.globalOccurrenceForRef(chunkSym, label, localOccurrence) : null;
2388
+ if (localOccurrence !== null && globalOcc === null) return null;
2389
+ const occSuffix = globalOcc !== null && globalOcc > 1 ? `-${globalOcc}` : "";
2390
+ return /* @__PURE__ */ jsx4("sup", { children: /* @__PURE__ */ jsx4("a", { href: `#${clobberPrefix}fn-${label}`, id: `${clobberPrefix}fnref-${label}${occSuffix}`, "data-footnote-ref": true, children: num }) });
2391
+ }
2392
+ function reactNodeToText(node) {
2393
+ if (node === null || node === void 0 || typeof node === "boolean") return "";
2394
+ if (typeof node === "string") return node;
2395
+ if (typeof node === "number" || typeof node === "bigint") return String(node);
2396
+ if (Array.isArray(node)) return node.map(reactNodeToText).join("");
2397
+ if (isValidElement(node)) {
2398
+ return reactNodeToText(node.props.children);
2399
+ }
2400
+ return "";
2401
+ }
2402
+ function literalLink(rt, label, children) {
2403
+ const text = reactNodeToText(children);
2404
+ switch (rt) {
2405
+ case "full":
2406
+ return `[${text}][${label}]`;
2407
+ case "collapsed":
2408
+ return `[${label}][]`;
2409
+ case "shortcut":
2410
+ default:
2411
+ return `[${label}]`;
2412
+ }
2413
+ }
2414
+ function CrossChunkLink({ label, referenceType, children }) {
2415
+ const { documentId } = useAIMarkdownRenderState();
2416
+ const registry = useDocumentRegistry(documentId);
2417
+ const subscribe = useCallback((cb) => registry ? registry.subscribe(cb) : () => {
2418
+ }, [registry]);
2419
+ const getSnapshot = useCallback(() => registry?.resolveLinkDef(label) ?? null, [registry, label]);
2420
+ const def = useSyncExternalStore(subscribe, getSnapshot, SSR_DEF_SNAPSHOT);
2421
+ if (!def) {
2422
+ return literalLink(referenceType, label, children);
2423
+ }
2424
+ return /* @__PURE__ */ jsx4("a", { href: def.url, title: def.title, children });
2425
+ }
2426
+ function literalImage(rt, label, alt) {
2427
+ switch (rt) {
2428
+ case "full":
2429
+ return `![${alt}][${label}]`;
2430
+ case "collapsed":
2431
+ return `![${alt}][]`;
2432
+ case "shortcut":
2433
+ default:
2434
+ return `![${label}]`;
2435
+ }
2436
+ }
2437
+ function CrossChunkImage({ label, referenceType, alt = "" }) {
2438
+ const { documentId } = useAIMarkdownRenderState();
2439
+ const registry = useDocumentRegistry(documentId);
2440
+ const subscribe = useCallback((cb) => registry ? registry.subscribe(cb) : () => {
2441
+ }, [registry]);
2442
+ const getSnapshot = useCallback(() => registry?.resolveLinkDef(label) ?? null, [registry, label]);
2443
+ const def = useSyncExternalStore(subscribe, getSnapshot, SSR_DEF_SNAPSHOT);
2444
+ if (!def) {
2445
+ return literalImage(referenceType, label, alt);
2446
+ }
2447
+ return /* @__PURE__ */ jsx4("img", { src: def.url, alt, title: def.title });
2448
+ }
2449
+ var crossChunkComponents = {
2450
+ "footnote-sup": FootnoteSupNumber,
2451
+ "cross-chunk-link": CrossChunkLink,
2452
+ "cross-chunk-image": CrossChunkImage
2453
+ };
2454
+
2455
+ // src/components/extractContributions.ts
2456
+ import { SKIP, visit as visit6 } from "unist-util-visit";
2457
+ function* extractContributions(mdast, options = {}) {
2458
+ const phantomFn = options.phantomFootnoteLabels;
2459
+ const out = [];
2460
+ visit6(mdast, (n) => {
2461
+ if (n.type === "footnoteReference") {
2462
+ out.push({
2463
+ kind: "ref",
2464
+ refKind: "footnote",
2465
+ label: normalizeId(n.identifier)
2466
+ });
2467
+ } else if (n.type === "linkReference") {
2468
+ const r = n;
2469
+ out.push({ kind: "ref", refKind: "link", label: normalizeId(r.identifier), referenceType: r.referenceType });
2470
+ } else if (n.type === "imageReference") {
2471
+ const r = n;
2472
+ out.push({ kind: "ref", refKind: "image", label: normalizeId(r.identifier), referenceType: r.referenceType });
2473
+ } else if (n.type === "footnoteDefinition") {
2474
+ const d = n;
2475
+ const label = normalizeId(d.identifier);
2476
+ if (phantomFn?.has(label)) return SKIP;
2477
+ const content = JSON.stringify(d.children ?? []);
2478
+ out.push({ kind: "fnDef", label, sourceIdentifier: d.identifier, content });
2479
+ return SKIP;
2480
+ } else if (n.type === "definition") {
2481
+ const d = n;
2482
+ if (d.url === SENTINEL_LINK_URL) return;
2483
+ out.push({ kind: "linkDef", label: normalizeId(d.identifier), url: d.url, title: d.title });
2484
+ }
2485
+ });
2486
+ for (const c of out) yield c;
2487
+ }
2488
+
2489
+ // src/components/extractDefBodiesFromHast.ts
2490
+ import { SKIP as SKIP2, visit as visit7 } from "unist-util-visit";
2491
+ var FN_LI_ID_RE = /(?:^|-)user-content-fn-(.+)$/;
2492
+ function sourceIdFromFootnoteLiId(idProp, clobberPrefix) {
2493
+ let raw = null;
2494
+ if (clobberPrefix !== void 0) {
2495
+ const exactPrefix = `${clobberPrefix}fn-`;
2496
+ if (idProp.startsWith(exactPrefix)) raw = idProp.slice(exactPrefix.length);
2497
+ }
2498
+ if (raw === null) {
2499
+ const m = idProp.match(FN_LI_ID_RE);
2500
+ raw = m ? m[1] : null;
2501
+ }
2502
+ if (raw === null) return null;
2503
+ try {
2504
+ return decodeURIComponent(raw);
2505
+ } catch {
2506
+ return raw;
2507
+ }
2508
+ }
2509
+ function isBackrefAnchor(c) {
2510
+ if (c.type !== "element") return false;
2511
+ const el = c;
2512
+ if (el.tagName !== "a") return false;
2513
+ return Boolean(el.properties && "dataFootnoteBackref" in el.properties);
2514
+ }
2515
+ function isWhitespaceText(c) {
2516
+ if (c.type !== "text") return false;
2517
+ return /^\s*$/.test(c.value);
2518
+ }
2519
+ function lastMeaningfulIdx(children) {
2520
+ for (let i = children.length - 1; i >= 0; i--) {
2521
+ if (!isWhitespaceText(children[i])) return i;
2522
+ }
2523
+ return -1;
2524
+ }
2525
+ function dropTrailingBackrefs(children) {
2526
+ let trailingWsStart = children.length;
2527
+ while (trailingWsStart > 0 && isWhitespaceText(children[trailingWsStart - 1])) {
2528
+ trailingWsStart--;
2529
+ }
2530
+ let scan = trailingWsStart;
2531
+ let peeledAny = false;
2532
+ while (scan > 0) {
2533
+ const t = children[scan - 1];
2534
+ if (!isBackrefAnchor(t)) break;
2535
+ peeledAny = true;
2536
+ scan -= 1;
2537
+ if (scan > 0 && children[scan - 1].type === "text" && children[scan - 1].value === " ") {
2538
+ scan -= 1;
2539
+ }
2540
+ }
2541
+ if (!peeledAny) return children;
2542
+ const trailing = children.slice(trailingWsStart);
2543
+ if (scan > 0) {
2544
+ const last = children[scan - 1];
2545
+ if (last.type === "text") {
2546
+ const v = last.value;
2547
+ if (v.endsWith(" ") && !/^\s*$/.test(v)) {
2548
+ return [...children.slice(0, scan - 1), { ...last, value: v.slice(0, -1) }, ...trailing];
2549
+ }
2550
+ }
2551
+ }
2552
+ return [...children.slice(0, scan), ...trailing];
2553
+ }
2554
+ function stripBackrefs(liChildren) {
2555
+ if (liChildren.length === 0) return liChildren;
2556
+ const lastIdx = lastMeaningfulIdx(liChildren);
2557
+ if (lastIdx < 0) return liChildren;
2558
+ const last = liChildren[lastIdx];
2559
+ if (isBackrefAnchor(last)) {
2560
+ return dropTrailingBackrefs(liChildren);
2561
+ }
2562
+ if (last.type === "element" && last.tagName === "p") {
2563
+ const p = last;
2564
+ const newPChildren = dropTrailingBackrefs(p.children);
2565
+ if (newPChildren === p.children) return liChildren;
2566
+ return liChildren.map((c, i) => i === lastIdx ? { ...p, children: newPChildren } : c);
2567
+ }
2568
+ return liChildren;
2569
+ }
2570
+ function stripLocalOccurrenceFromFootnoteSups(children) {
2571
+ let changed = false;
2572
+ const out = [];
2573
+ for (const c of children) {
2574
+ if (c.type === "element") {
2575
+ const el = c;
2576
+ let nextEl = el;
2577
+ if (el.tagName === "footnote-sup" && el.properties && "localOccurrence" in el.properties) {
2578
+ const { localOccurrence: _drop, ...rest } = el.properties;
2579
+ nextEl = { ...el, properties: rest };
2580
+ changed = true;
2581
+ }
2582
+ const newChildren = stripLocalOccurrenceFromFootnoteSups(nextEl.children);
2583
+ if (newChildren !== nextEl.children) {
2584
+ nextEl = { ...nextEl, children: newChildren };
2585
+ changed = true;
2586
+ }
2587
+ out.push(nextEl);
2588
+ } else {
2589
+ out.push(c);
2590
+ }
2591
+ }
2592
+ return changed ? out : children;
2593
+ }
2594
+ function extractDefBodiesFromHast(hast, clobberPrefix) {
2595
+ const out = /* @__PURE__ */ new Map();
2596
+ visit7(hast, "element", (sectionNode) => {
2597
+ const sec = sectionNode;
2598
+ if (sec.tagName !== "section") return;
2599
+ if (!(sec.properties && "dataFootnotes" in sec.properties)) return;
2600
+ visit7(sec, "element", (liNode) => {
2601
+ const li = liNode;
2602
+ if (li.tagName !== "li") return;
2603
+ const idProp = li.properties?.id;
2604
+ if (typeof idProp !== "string") return;
2605
+ const sourceId = sourceIdFromFootnoteLiId(idProp, clobberPrefix);
2606
+ if (sourceId === null) return;
2607
+ const normalized = normalizeId(sourceId);
2608
+ const stripped = stripBackrefs(li.children);
2609
+ out.set(normalized, stripLocalOccurrenceFromFootnoteSups(stripped));
2610
+ });
2611
+ return SKIP2;
2612
+ });
2613
+ return out;
1728
2614
  }
1729
2615
 
1730
- // src/preprocessors/index.ts
1731
- function applyPreprocessors(value, ...fns) {
1732
- return fns.reduce((result, fn) => fn(result), value);
2616
+ // src/components/aggregateFootnotesIfLast.tsx
2617
+ import { memo, useMemo as useMemo3 } from "react";
2618
+ import { Fragment as Fragment2, jsx as jsx5 } from "react/jsx-runtime";
2619
+ function cloneHast(node) {
2620
+ return JSON.parse(JSON.stringify(node));
1733
2621
  }
1734
- var defaultExtraPreprocessors = [];
1735
- function preprocessAIMDContent(content, extraPreprocessors = defaultExtraPreprocessors) {
1736
- return applyPreprocessors(content, preprocessLaTeX, ...extraPreprocessors);
2622
+ function isWhitespaceText2(c) {
2623
+ return c.type === "text" && /^\s*$/.test(c.value);
2624
+ }
2625
+ function lastMeaningfulIdx2(children) {
2626
+ for (let i = children.length - 1; i >= 0; i--) {
2627
+ if (!isWhitespaceText2(children[i])) return i;
2628
+ }
2629
+ return -1;
2630
+ }
2631
+ function buildBackref(href, occurrence, globalNumber) {
2632
+ const children = [{ type: "text", value: "\u21A9" }];
2633
+ if (occurrence > 1) {
2634
+ children.push({
2635
+ type: "element",
2636
+ tagName: "sup",
2637
+ properties: {},
2638
+ children: [{ type: "text", value: String(occurrence) }]
2639
+ });
2640
+ }
2641
+ const ariaLabel = occurrence === 1 ? `Back to reference ${globalNumber}` : `Back to reference ${globalNumber}-${occurrence}`;
2642
+ return {
2643
+ type: "element",
2644
+ tagName: "a",
2645
+ properties: {
2646
+ href,
2647
+ dataFootnoteBackref: "",
2648
+ className: ["data-footnote-backref"],
2649
+ ariaLabel
2650
+ },
2651
+ children
2652
+ };
1737
2653
  }
2654
+ function buildAggregateTree(registry, clobberPrefix, preserveOrphanReferences = false) {
2655
+ const seen = /* @__PURE__ */ new Set();
2656
+ const ordered = [];
2657
+ for (const sym of registry.chunkOrder) {
2658
+ const data = registry.chunkData.get(sym);
2659
+ if (!data) continue;
2660
+ for (const ref of data.refs) {
2661
+ if (ref.kind !== "footnote") continue;
2662
+ if (seen.has(ref.label)) continue;
2663
+ seen.add(ref.label);
2664
+ const canonicalSym = registry.canonicalFootnoteFor(ref.label);
2665
+ if (!canonicalSym) continue;
2666
+ const def = registry.chunkData.get(canonicalSym)?.defs.get(ref.label);
2667
+ if (!def) continue;
2668
+ const n = registry.globalNumber(ref.label);
2669
+ if (n === null) continue;
2670
+ const sourceIdentifier = def.sourceIdentifier ?? ref.label;
2671
+ ordered.push({
2672
+ normalizedLabel: ref.label,
2673
+ sourceIdentifier,
2674
+ bodyHast: def.bodyHast ?? [],
2675
+ n,
2676
+ withBackref: true
2677
+ });
2678
+ }
2679
+ }
2680
+ if (preserveOrphanReferences) {
2681
+ for (const sym of registry.chunkOrder) {
2682
+ const data = registry.chunkData.get(sym);
2683
+ if (!data) continue;
2684
+ for (const [label, def] of data.defs) {
2685
+ if (seen.has(label)) continue;
2686
+ if (registry.canonicalFootnoteFor(label) !== sym) continue;
2687
+ seen.add(label);
2688
+ ordered.push({
2689
+ normalizedLabel: label,
2690
+ sourceIdentifier: def.sourceIdentifier ?? label,
2691
+ bodyHast: def.bodyHast ?? [],
2692
+ n: null,
2693
+ withBackref: false
2694
+ });
2695
+ }
2696
+ }
2697
+ }
2698
+ if (ordered.length === 0) return null;
2699
+ const liElements = ordered.map(({ normalizedLabel, sourceIdentifier, bodyHast, n, withBackref }) => {
2700
+ const liChildren = bodyHast.map((c) => cloneHast(c));
2701
+ if (withBackref) {
2702
+ const totalRefs = registry.getRefsForLabel(normalizedLabel);
2703
+ const tailIdx = lastMeaningfulIdx2(liChildren);
2704
+ const tail = tailIdx !== -1 ? liChildren[tailIdx] : null;
2705
+ const dest = tail && tail.type === "element" && tail.tagName === "p" ? tail : null;
2706
+ const appended = [];
2707
+ for (let i = 1; i <= Math.max(totalRefs, 1); i++) {
2708
+ appended.push({ type: "text", value: " " });
2709
+ const href = i === 1 ? `#${clobberPrefix}fnref-${sourceIdentifier}` : `#${clobberPrefix}fnref-${sourceIdentifier}-${i}`;
2710
+ appended.push(buildBackref(href, i, n ?? 0));
2711
+ }
2712
+ if (dest) {
2713
+ dest.children = [...dest.children, ...appended];
2714
+ } else if (tailIdx !== -1) {
2715
+ liChildren.splice(tailIdx + 1, 0, ...appended);
2716
+ } else {
2717
+ liChildren.push(...appended);
2718
+ }
2719
+ }
2720
+ return {
2721
+ type: "element",
2722
+ tagName: "li",
2723
+ properties: {
2724
+ id: `${clobberPrefix}fn-${sourceIdentifier}`,
2725
+ ...n !== null ? { value: n } : {}
2726
+ },
2727
+ children: liChildren
2728
+ };
2729
+ });
2730
+ return {
2731
+ type: "element",
2732
+ tagName: "section",
2733
+ properties: {
2734
+ className: ["footnotes"],
2735
+ dataFootnotes: true,
2736
+ // a11y: name the section landmark so screen readers still announce it
2737
+ // even though the visible "Footnotes" h2 is omitted in coordinated mode.
2738
+ ariaLabel: "Footnotes"
2739
+ },
2740
+ children: [
2741
+ // Conventional separator above the footnote list. The default
2742
+ // mdast-util-to-hast footer doesn't emit one (GitHub renders the
2743
+ // separation via CSS `border-top` on `.footnotes`); we render a literal
2744
+ // `<hr>` so the visual break is preserved without sanitize-friendly CSS.
2745
+ {
2746
+ type: "element",
2747
+ tagName: "hr",
2748
+ properties: {},
2749
+ children: []
2750
+ },
2751
+ {
2752
+ type: "element",
2753
+ tagName: "ol",
2754
+ properties: {},
2755
+ children: liElements
2756
+ }
2757
+ ]
2758
+ };
2759
+ }
2760
+ var AggregateFootnotesIfLastImpl = ({
2761
+ registry,
2762
+ thisChunkSym,
2763
+ clobberPrefix,
2764
+ postOptions,
2765
+ preserveOrphanReferences = false
2766
+ }) => {
2767
+ const tree = useMemo3(
2768
+ () => buildAggregateTree(registry, clobberPrefix, preserveOrphanReferences),
2769
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2770
+ [registry, registry.version, clobberPrefix, preserveOrphanReferences]
2771
+ );
2772
+ const order = registry.chunkOrder;
2773
+ if (order.length === 0) return null;
2774
+ if (order[order.length - 1] !== thisChunkSym) return null;
2775
+ if (!tree) return null;
2776
+ return /* @__PURE__ */ jsx5(Fragment2, { children: renderHastSubtree(cloneHast(tree), postOptions) });
2777
+ };
2778
+ var AggregateFootnotesIfLast = memo(AggregateFootnotesIfLastImpl);
2779
+ AggregateFootnotesIfLast.displayName = "AggregateFootnotesIfLast";
1738
2780
 
1739
2781
  // src/components/MarkdownContent.tsx
1740
- import { memo, useMemo as useMemo2 } from "react";
1741
- import ReactMarkdown from "react-markdown";
1742
- import rehypeKatex from "rehype-katex";
1743
- import rehypeRaw from "rehype-raw";
1744
- import rehypeUnwrapImages from "rehype-unwrap-images";
1745
- import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
1746
- import remarkBreaks from "remark-breaks";
1747
- import remarkCjkFriendly from "remark-cjk-friendly";
1748
- import remarkCjkFriendlyGfmStrikethrough from "remark-cjk-friendly-gfm-strikethrough";
1749
- import remarkEmoji from "remark-emoji";
1750
- import remarkGfm from "remark-gfm";
1751
- import remarkMath from "remark-math";
1752
- import { remarkDefinitionList, defListHastHandlers } from "remark-definition-list";
1753
- import remarkSupersub from "remark-supersub";
1754
- import { remarkMark as remarkMarkHighlight } from "remark-mark-highlight";
1755
- import remarkSqueezeParagraphs from "remark-squeeze-paragraphs";
1756
- import remarkSmartypants from "remark-smartypants";
1757
- import remarkPangu from "remark-pangu";
1758
- import remarkRemoveComments from "remark-remove-comments";
1759
- import { jsx as jsx2 } from "react/jsx-runtime";
2782
+ import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
2783
+ var REGISTRY_SSR_SNAPSHOT = () => 0;
1760
2784
  var DisplayOptimizeRemarkPluginMap = {
1761
2785
  ["REMOVE_COMMENTS" /* REMOVE_COMMENTS */]: remarkRemoveComments,
1762
2786
  ["SMARTYPANTS" /* SMARTYPANTS */]: remarkSmartypants,
@@ -1764,83 +2788,359 @@ var DisplayOptimizeRemarkPluginMap = {
1764
2788
  };
1765
2789
  var ExtraSyntaxRemarkPluginMap = {
1766
2790
  ["HIGHLIGHT" /* HIGHLIGHT */]: remarkMarkHighlight,
1767
- ["DEFINITION_LIST" /* DEFINITION_LIST */]: remarkDefinitionList,
1768
- ["SUBSCRIPT" /* SUBSCRIPT */]: remarkSupersub
2791
+ ["DEFINITION_LIST" /* DEFINITION_LIST */]: remarkDefinitionList
1769
2792
  };
1770
2793
  var DefaultCustomComponents = {};
1771
- var AIMarkdownContent = memo(({ content, customComponents }) => {
1772
- const { config } = useAIMarkdownRenderState();
1773
- const { extraSyntaxRemarkPlugins, enableDefinitionList } = useMemo2(
2794
+ var BlockMemoizedRenderer = memo2(
2795
+ ({ content, usedComponents, remarkPlugins, rehypePlugins, remarkRehypeOptions }) => {
2796
+ const urlTransform = void 0;
2797
+ const allowedElements = void 0;
2798
+ const disallowedElements = void 0;
2799
+ const allowElement = void 0;
2800
+ const skipHtml = void 0;
2801
+ const unwrapDisallowed = void 0;
2802
+ const { documentId, clobberPrefix, config } = useAIMarkdownRenderState();
2803
+ const reactId = useId2();
2804
+ const registry = useDocumentRegistry(documentId);
2805
+ const [allocation, setAllocation] = useState(null);
2806
+ const sym = allocation && allocation.registry === registry ? allocation.sym : null;
2807
+ const subscribeRegistry = useCallback2(
2808
+ (cb) => registry ? registry.subscribe(cb) : () => {
2809
+ },
2810
+ [registry]
2811
+ );
2812
+ const getRegistryVersion = useCallback2(() => registry?.version ?? 0, [registry]);
2813
+ useSyncExternalStore2(subscribeRegistry, getRegistryVersion, REGISTRY_SSR_SNAPSHOT);
2814
+ const ownLabels = useMemo4(() => collectDefLabels(content ?? ""), [content]);
2815
+ useEffect(() => {
2816
+ if (!registry) return;
2817
+ const s = registry.registerChunk(reactId, ownLabels.footnoteLabels, ownLabels.linkLabels);
2818
+ setAllocation({ registry, sym: s });
2819
+ return () => {
2820
+ registry.releaseSymbol(reactId);
2821
+ setAllocation(null);
2822
+ };
2823
+ }, [reactId, registry, ownLabels]);
2824
+ const cacheRef = useRef2(createCache());
2825
+ const depsRef = useRef2({
2826
+ usedComponents,
2827
+ remarkPlugins,
2828
+ rehypePlugins,
2829
+ remarkRehypeOptions,
2830
+ urlTransform,
2831
+ allowedElements,
2832
+ disallowedElements,
2833
+ allowElement,
2834
+ skipHtml,
2835
+ unwrapDisallowed,
2836
+ registry,
2837
+ symbol: sym
2838
+ });
2839
+ if (depsRef.current.usedComponents !== usedComponents || depsRef.current.remarkPlugins !== remarkPlugins || depsRef.current.rehypePlugins !== rehypePlugins || depsRef.current.remarkRehypeOptions !== remarkRehypeOptions || depsRef.current.urlTransform !== urlTransform || depsRef.current.allowedElements !== allowedElements || depsRef.current.disallowedElements !== disallowedElements || depsRef.current.allowElement !== allowElement || depsRef.current.skipHtml !== skipHtml || depsRef.current.unwrapDisallowed !== unwrapDisallowed || depsRef.current.registry !== registry || depsRef.current.symbol !== sym) {
2840
+ cacheRef.current = createCache();
2841
+ depsRef.current = {
2842
+ usedComponents,
2843
+ remarkPlugins,
2844
+ rehypePlugins,
2845
+ remarkRehypeOptions,
2846
+ urlTransform,
2847
+ allowedElements,
2848
+ disallowedElements,
2849
+ allowElement,
2850
+ skipHtml,
2851
+ unwrapDisallowed,
2852
+ registry,
2853
+ symbol: sym
2854
+ };
2855
+ }
2856
+ const targetPhantomsRef = useRef2({
2857
+ missingFootnotes: /* @__PURE__ */ new Set(),
2858
+ missingLinks: /* @__PURE__ */ new Set()
2859
+ });
2860
+ const targetPhantoms = useMemo4(() => {
2861
+ let nextFootnotes;
2862
+ let nextLinks;
2863
+ if (!registry) {
2864
+ nextFootnotes = /* @__PURE__ */ new Set();
2865
+ nextLinks = /* @__PURE__ */ new Set();
2866
+ } else {
2867
+ const normalized = normalizeForMatch(content ?? "");
2868
+ nextFootnotes = /* @__PURE__ */ new Set();
2869
+ nextLinks = /* @__PURE__ */ new Set();
2870
+ for (const label of registry.labelSet.footnoteLabels) {
2871
+ if (ownLabels.footnoteLabels.has(label)) continue;
2872
+ if (normalized.includes(label)) nextFootnotes.add(label);
2873
+ }
2874
+ for (const label of registry.labelSet.linkLabels) {
2875
+ if (ownLabels.linkLabels.has(label)) continue;
2876
+ if (normalized.includes(label)) nextLinks.add(label);
2877
+ }
2878
+ }
2879
+ const prev = targetPhantomsRef.current;
2880
+ if (nextFootnotes.size === prev.missingFootnotes.size && nextLinks.size === prev.missingLinks.size && [...nextFootnotes].every((l) => prev.missingFootnotes.has(l)) && [...nextLinks].every((l) => prev.missingLinks.has(l))) {
2881
+ return prev;
2882
+ }
2883
+ const next = { missingFootnotes: nextFootnotes, missingLinks: nextLinks };
2884
+ targetPhantomsRef.current = next;
2885
+ return next;
2886
+ }, [registry, registry?.version, content, ownLabels]);
2887
+ const effectivePreserveOrphan = usePreserveOrphanReferences(config.preserveOrphanReferences);
2888
+ const preserveForBodyHarvest = effectivePreserveOrphan || Boolean(registry && sym);
2889
+ const handlers = useMemo4(() => {
2890
+ if (registry) return buildCrossChunkHandlers();
2891
+ if (effectivePreserveOrphan) {
2892
+ const { footnoteDefinition } = buildCrossChunkHandlers();
2893
+ return { footnoteDefinition };
2894
+ }
2895
+ return void 0;
2896
+ }, [registry, effectivePreserveOrphan]);
2897
+ const parsed = useMemo4(() => {
2898
+ const augmented = augmentSourceWithPhantoms(content ?? "", targetPhantoms);
2899
+ const baseHandlers = remarkRehypeOptions?.handlers ?? {};
2900
+ const mergedRemarkRehypeOptions = handlers ? {
2901
+ ...remarkRehypeOptions,
2902
+ handlers: { ...baseHandlers, ...handlers },
2903
+ // Phantom label sets are empty in standalone mode (no PASS 0.5
2904
+ // injection happened); the footnoteDefinition handler still reads
2905
+ // them via `state.options.phantomFootnoteLabels.has(id)`, which
2906
+ // returns false for every id → orphan-protect path proceeds.
2907
+ phantomFootnoteLabels: targetPhantoms.missingFootnotes,
2908
+ phantomLinkLabels: targetPhantoms.missingLinks,
2909
+ preserveOrphan: preserveForBodyHarvest,
2910
+ documentId
2911
+ } : {
2912
+ ...remarkRehypeOptions
2913
+ };
2914
+ return parseStage({
2915
+ children: augmented,
2916
+ remarkPlugins,
2917
+ rehypePlugins,
2918
+ remarkRehypeOptions: mergedRemarkRehypeOptions
2919
+ });
2920
+ }, [
2921
+ content,
2922
+ targetPhantoms,
2923
+ remarkPlugins,
2924
+ rehypePlugins,
2925
+ remarkRehypeOptions,
2926
+ handlers,
2927
+ preserveForBodyHarvest,
2928
+ documentId
2929
+ ]);
2930
+ const hast = useMemo4(() => transformStage(parsed), [parsed]);
2931
+ const built = useMemo4(() => buildBlocks(parsed.mdast, hast, content ?? ""), [parsed.mdast, hast, content]);
2932
+ const postOptions = useMemo4(
2933
+ () => ({
2934
+ components: { ...crossChunkComponents, ...usedComponents },
2935
+ urlTransform,
2936
+ allowedElements,
2937
+ disallowedElements,
2938
+ allowElement,
2939
+ skipHtml,
2940
+ unwrapDisallowed,
2941
+ // v6 fingerprint cache fields:
2942
+ registry: registry ?? void 0,
2943
+ thisChunkSymbol: sym ?? void 0,
2944
+ clobberPrefix
2945
+ }),
2946
+ // `sym` is now real state (setSym after allocateSymbol), so it's a
2947
+ // proper dep and postOptions refreshes when allocation completes.
2948
+ // `registry?.version` stays in deps so the per-block fingerprint cache
2949
+ // path sees the latest registry version on every coordinated update.
2950
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2951
+ [
2952
+ usedComponents,
2953
+ urlTransform,
2954
+ allowedElements,
2955
+ disallowedElements,
2956
+ allowElement,
2957
+ skipHtml,
2958
+ unwrapDisallowed,
2959
+ registry,
2960
+ registry?.version,
2961
+ sym,
2962
+ clobberPrefix
2963
+ ]
2964
+ );
2965
+ const lastContributionRef = useRef2(null);
2966
+ useEffect(() => {
2967
+ if (!registry || !sym) return;
2968
+ const refs = [];
2969
+ const defMeta = /* @__PURE__ */ new Map();
2970
+ const linkDefs = /* @__PURE__ */ new Map();
2971
+ for (const node of extractContributions(parsed.mdast, {
2972
+ phantomFootnoteLabels: targetPhantoms.missingFootnotes
2973
+ })) {
2974
+ if (node.kind === "ref") {
2975
+ refs.push({ label: node.label, kind: node.refKind, referenceType: node.referenceType });
2976
+ } else if (node.kind === "fnDef") {
2977
+ defMeta.set(node.label, {
2978
+ identifier: node.label,
2979
+ sourceIdentifier: node.sourceIdentifier,
2980
+ contentSource: node.content
2981
+ });
2982
+ } else if (node.kind === "linkDef") {
2983
+ linkDefs.set(node.label, { identifier: node.label, url: node.url, title: node.title });
2984
+ }
2985
+ }
2986
+ const fp = JSON.stringify({
2987
+ r: refs,
2988
+ d: Array.from(defMeta.entries()).map(([k, v]) => [k, v.sourceIdentifier, v.contentSource]),
2989
+ l: Array.from(linkDefs.entries()).map(([k, v]) => [k, v.url, v.title ?? ""]),
2990
+ ofn: Array.from(ownLabels.footnoteLabels).sort(),
2991
+ ol: Array.from(ownLabels.linkLabels).sort(),
2992
+ // Include targetPhantoms in the fingerprint: a phantom→resolved
2993
+ // transition (another chunk publishes a def for a label this chunk
2994
+ // references inside one of its OWN def bodies) changes the rendered
2995
+ // hast — the `<cross-chunk-link>` / `<cross-chunk-image>` placeholder
2996
+ // disappears and a real `<a>` / `<img>` takes its place — without
2997
+ // touching this chunk's refs / defMeta / linkDefs / ownLabels. Without
2998
+ // including the phantom snapshot in the fingerprint, the fp check
2999
+ // would short-circuit and the registry would keep stale bodyHast
3000
+ // forever, leaving the aggregate footer rendering the placeholder
3001
+ // long after the label was resolved.
3002
+ tpfn: Array.from(targetPhantoms.missingFootnotes).sort(),
3003
+ tpl: Array.from(targetPhantoms.missingLinks).sort()
3004
+ });
3005
+ if (lastContributionRef.current?.registry === registry && lastContributionRef.current.symbol === sym && lastContributionRef.current.fp === fp) {
3006
+ return;
3007
+ }
3008
+ const bodiesByLabel = extractDefBodiesFromHast(hast, clobberPrefix);
3009
+ const defs = /* @__PURE__ */ new Map();
3010
+ for (const [label, meta] of defMeta) {
3011
+ defs.set(label, {
3012
+ identifier: meta.identifier,
3013
+ sourceIdentifier: meta.sourceIdentifier,
3014
+ contentSource: meta.contentSource,
3015
+ bodyHast: bodiesByLabel.get(label) ?? []
3016
+ });
3017
+ }
3018
+ lastContributionRef.current = { registry, symbol: sym, fp };
3019
+ registry.contributeChunkData(sym, {
3020
+ refs,
3021
+ defs,
3022
+ linkDefs,
3023
+ ownFootnoteLabels: ownLabels.footnoteLabels,
3024
+ ownLinkLabels: ownLabels.linkLabels
3025
+ });
3026
+ }, [parsed, ownLabels, registry, targetPhantoms, sym, hast, clobberPrefix]);
3027
+ const rendered = renderBlocksWithCache(cacheRef, built.plan, built.globalCtx, postOptions);
3028
+ return /* @__PURE__ */ jsxs2(ChunkSymbolContext.Provider, { value: sym, children: [
3029
+ rendered.map(({ node, reactKey }) => /* @__PURE__ */ jsx6(Fragment3, { children: node }, reactKey)),
3030
+ registry && sym ? /* @__PURE__ */ jsx6(
3031
+ AggregateFootnotesIfLast,
3032
+ {
3033
+ registry,
3034
+ thisChunkSym: sym,
3035
+ clobberPrefix,
3036
+ postOptions,
3037
+ preserveOrphanReferences: effectivePreserveOrphan
3038
+ }
3039
+ ) : null
3040
+ ] });
3041
+ }
3042
+ );
3043
+ BlockMemoizedRenderer.displayName = "BlockMemoizedRenderer";
3044
+ var LegacyRenderer = memo2(
3045
+ ({ content, usedComponents, remarkPlugins, rehypePlugins, remarkRehypeOptions }) => /* @__PURE__ */ jsx6(
3046
+ Markdown_default,
3047
+ {
3048
+ remarkPlugins,
3049
+ rehypePlugins,
3050
+ remarkRehypeOptions,
3051
+ components: usedComponents,
3052
+ children: content
3053
+ }
3054
+ )
3055
+ );
3056
+ LegacyRenderer.displayName = "LegacyRenderer";
3057
+ var AIMarkdownContent = memo2(({ content, customComponents }) => {
3058
+ const { config, clobberPrefix } = useAIMarkdownRenderState();
3059
+ const { extraSyntaxRemarkPlugins, enableDefinitionList } = useMemo4(
1774
3060
  () => ({
1775
3061
  extraSyntaxRemarkPlugins: config.extraSyntaxSupported.map((syntax) => ExtraSyntaxRemarkPluginMap[syntax]),
1776
3062
  enableDefinitionList: config.extraSyntaxSupported.includes("DEFINITION_LIST" /* DEFINITION_LIST */)
1777
3063
  }),
1778
3064
  [config.extraSyntaxSupported]
1779
3065
  );
1780
- const displayOptimizeRemarkPlugins = useMemo2(() => {
3066
+ const displayOptimizeRemarkPlugins = useMemo4(() => {
1781
3067
  return config.displayOptimizeAbilities.map((ability) => DisplayOptimizeRemarkPluginMap[ability]);
1782
3068
  }, [config.displayOptimizeAbilities]);
1783
- const usedComponents = useMemo2(() => {
3069
+ const usedComponents = useMemo4(() => {
1784
3070
  return customComponents ? { ...DefaultCustomComponents, ...customComponents } : DefaultCustomComponents;
1785
3071
  }, [customComponents]);
1786
- return /* @__PURE__ */ jsx2(
1787
- ReactMarkdown,
1788
- {
1789
- remarkPlugins: [
1790
- // --- Core plugins (always active) ---
1791
- remarkGfm,
1792
- [
1793
- remarkMath,
1794
- {
1795
- // Disable single-dollar inline math to avoid conflicts with currency
1796
- // signs and other dollar usages; the preprocessor converts $...$ to $$...$$.
1797
- singleDollarTextMath: false
1798
- }
1799
- ],
1800
- // --- Configurable extra syntax plugins ---
1801
- ...extraSyntaxRemarkPlugins,
1802
- // --- Formatting & normalization ---
1803
- remarkBreaks,
1804
- remarkEmoji,
1805
- remarkSqueezeParagraphs,
1806
- remarkCjkFriendly,
1807
- remarkCjkFriendlyGfmStrikethrough,
1808
- // --- Configurable display optimizations ---
1809
- ...displayOptimizeRemarkPlugins
1810
- ],
1811
- rehypePlugins: [
1812
- // Allow raw HTML through so rehype-sanitize can handle it.
1813
- [
1814
- rehypeRaw,
1815
- {
1816
- passThrough: []
1817
- }
1818
- ],
1819
- // Sanitize HTML while allowing <mark> (highlight) and KaTeX class names.
1820
- [
1821
- rehypeSanitize,
1822
- {
1823
- ...defaultSchema,
1824
- tagNames: [...defaultSchema.tagNames || [], "mark"],
1825
- attributes: {
1826
- ...defaultSchema.attributes,
1827
- // The `language-*` regex is allowed by default.
1828
- code: [["className", /^language-./, "math-inline", "math-display"]]
1829
- }
1830
- }
1831
- ],
1832
- rehypeKatex,
1833
- rehypeUnwrapImages
1834
- ],
1835
- remarkRehypeOptions: {
1836
- allowDangerousHtml: true,
1837
- handlers: {
1838
- // Inject definition-list HAST handlers when the extension is active.
1839
- ...enableDefinitionList ? defListHastHandlers : {}
3072
+ const remarkPlugins = useMemo4(
3073
+ () => [
3074
+ // --- Core plugins (always active) ---
3075
+ remarkGfm2,
3076
+ [
3077
+ remarkMath,
3078
+ {
3079
+ // Disable single-dollar inline math to avoid conflicts with currency
3080
+ // signs and other dollar usages; the preprocessor converts $...$ to $$...$$.
3081
+ singleDollarTextMath: false
1840
3082
  }
1841
- },
1842
- components: usedComponents,
1843
- children: content
3083
+ ],
3084
+ // --- Configurable extra syntax plugins ---
3085
+ ...extraSyntaxRemarkPlugins,
3086
+ // --- Formatting & normalization ---
3087
+ remarkBreaks,
3088
+ remarkEmoji,
3089
+ remarkSqueezeParagraphs,
3090
+ remarkCjkFriendly,
3091
+ remarkCjkFriendlyGfmStrikethrough,
3092
+ // --- Configurable display optimizations ---
3093
+ ...displayOptimizeRemarkPlugins
3094
+ ],
3095
+ [extraSyntaxRemarkPlugins, displayOptimizeRemarkPlugins]
3096
+ );
3097
+ const rehypePlugins = useMemo4(
3098
+ () => [
3099
+ // Allow raw HTML through so rehype-sanitize can handle it.
3100
+ [rehypeRaw, { passThrough: [] }],
3101
+ // Sanitize HTML while allowing <mark> (highlight) and KaTeX class names.
3102
+ // Override `clobberPrefix` with the instance-scoped value so every id
3103
+ // and clobberable attribute is namespaced to this `<AIMarkdown>` instance.
3104
+ [rehypeSanitize, { ...sanitizeSchema, clobberPrefix }],
3105
+ // Normalize the auto-generated `<section data-footnotes>`: strip the
3106
+ // sr-only `<h2>Footnotes</h2>` label and prepend `<hr>`. Keeps standalone
3107
+ // single-doc rendering visually consistent with the cross-chunk aggregate
3108
+ // footer (which builds the same shape from scratch).
3109
+ rehypeFooterAdorn,
3110
+ // Re-prefix intra-document hash hrefs so they match the ids that
3111
+ // rehype-sanitize just clobbered. Must use the SAME prefix as the schema
3112
+ // above — that's why both read from `clobberPrefix`.
3113
+ [rehypeRebaseHashLinks_default, { prefix: clobberPrefix }],
3114
+ rehypeKatex,
3115
+ rehypeUnwrapImages
3116
+ ],
3117
+ [clobberPrefix]
3118
+ );
3119
+ const remarkRehypeOptions = useMemo4(
3120
+ () => ({
3121
+ allowDangerousHtml: true,
3122
+ // Suppress mdast-util-to-hast's `user-content-` prefix on footnote
3123
+ // ids/hrefs; rehype-sanitize will apply the same prefix downstream
3124
+ // and `rehypeRebaseHashLinks` mirrors it onto matching hash hrefs.
3125
+ // Without this, ids would end up double-prefixed
3126
+ // (`user-content-user-content-fn-x`).
3127
+ clobberPrefix: "",
3128
+ handlers: {
3129
+ // Inject definition-list HAST handlers when the extension is active.
3130
+ ...enableDefinitionList ? defListHastHandlers : {}
3131
+ }
3132
+ }),
3133
+ [enableDefinitionList]
3134
+ );
3135
+ const Renderer = config.blockMemoEnabled ? BlockMemoizedRenderer : LegacyRenderer;
3136
+ return /* @__PURE__ */ jsx6(
3137
+ Renderer,
3138
+ {
3139
+ content,
3140
+ usedComponents,
3141
+ remarkPlugins,
3142
+ rehypePlugins,
3143
+ remarkRehypeOptions
1844
3144
  }
1845
3145
  );
1846
3146
  });
@@ -1848,7 +3148,7 @@ AIMarkdownContent.displayName = "AIMarkdownContent";
1848
3148
  var MarkdownContent_default = AIMarkdownContent;
1849
3149
 
1850
3150
  // src/hooks/useStableValue.ts
1851
- import { useRef, useEffect } from "react";
3151
+ import { useRef as useRef3, useLayoutEffect, useEffect as useEffect2 } from "react";
1852
3152
 
1853
3153
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_setCacheAdd.js
1854
3154
  var HASH_UNDEFINED3 = "__lodash_hash_undefined__";
@@ -1965,44 +3265,44 @@ var setToArray_default = setToArray;
1965
3265
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_equalByTag.js
1966
3266
  var COMPARE_PARTIAL_FLAG2 = 1;
1967
3267
  var COMPARE_UNORDERED_FLAG2 = 2;
1968
- var boolTag4 = "[object Boolean]";
1969
- var dateTag4 = "[object Date]";
1970
- var errorTag3 = "[object Error]";
1971
- var mapTag6 = "[object Map]";
1972
- var numberTag4 = "[object Number]";
1973
- var regexpTag4 = "[object RegExp]";
1974
- var setTag6 = "[object Set]";
1975
- var stringTag4 = "[object String]";
1976
- var symbolTag3 = "[object Symbol]";
1977
- var arrayBufferTag4 = "[object ArrayBuffer]";
1978
- var dataViewTag5 = "[object DataView]";
1979
- var symbolProto2 = Symbol_default ? Symbol_default.prototype : void 0;
1980
- var symbolValueOf2 = symbolProto2 ? symbolProto2.valueOf : void 0;
3268
+ var boolTag2 = "[object Boolean]";
3269
+ var dateTag2 = "[object Date]";
3270
+ var errorTag2 = "[object Error]";
3271
+ var mapTag2 = "[object Map]";
3272
+ var numberTag2 = "[object Number]";
3273
+ var regexpTag2 = "[object RegExp]";
3274
+ var setTag2 = "[object Set]";
3275
+ var stringTag2 = "[object String]";
3276
+ var symbolTag = "[object Symbol]";
3277
+ var arrayBufferTag2 = "[object ArrayBuffer]";
3278
+ var dataViewTag2 = "[object DataView]";
3279
+ var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
3280
+ var symbolValueOf = symbolProto ? symbolProto.valueOf : void 0;
1981
3281
  function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
1982
3282
  switch (tag) {
1983
- case dataViewTag5:
3283
+ case dataViewTag2:
1984
3284
  if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
1985
3285
  return false;
1986
3286
  }
1987
3287
  object = object.buffer;
1988
3288
  other = other.buffer;
1989
- case arrayBufferTag4:
3289
+ case arrayBufferTag2:
1990
3290
  if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array_default(object), new Uint8Array_default(other))) {
1991
3291
  return false;
1992
3292
  }
1993
3293
  return true;
1994
- case boolTag4:
1995
- case dateTag4:
1996
- case numberTag4:
3294
+ case boolTag2:
3295
+ case dateTag2:
3296
+ case numberTag2:
1997
3297
  return eq_default(+object, +other);
1998
- case errorTag3:
3298
+ case errorTag2:
1999
3299
  return object.name == other.name && object.message == other.message;
2000
- case regexpTag4:
2001
- case stringTag4:
3300
+ case regexpTag2:
3301
+ case stringTag2:
2002
3302
  return object == other + "";
2003
- case mapTag6:
3303
+ case mapTag2:
2004
3304
  var convert = mapToArray_default;
2005
- case setTag6:
3305
+ case setTag2:
2006
3306
  var isPartial = bitmask & COMPARE_PARTIAL_FLAG2;
2007
3307
  convert || (convert = setToArray_default);
2008
3308
  if (object.size != other.size && !isPartial) {
@@ -2017,19 +3317,103 @@ function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
2017
3317
  var result = equalArrays_default(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
2018
3318
  stack["delete"](object);
2019
3319
  return result;
2020
- case symbolTag3:
2021
- if (symbolValueOf2) {
2022
- return symbolValueOf2.call(object) == symbolValueOf2.call(other);
3320
+ case symbolTag:
3321
+ if (symbolValueOf) {
3322
+ return symbolValueOf.call(object) == symbolValueOf.call(other);
2023
3323
  }
2024
3324
  }
2025
3325
  return false;
2026
3326
  }
2027
3327
  var equalByTag_default = equalByTag;
2028
3328
 
3329
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayPush.js
3330
+ function arrayPush(array, values) {
3331
+ var index = -1, length = values.length, offset = array.length;
3332
+ while (++index < length) {
3333
+ array[offset + index] = values[index];
3334
+ }
3335
+ return array;
3336
+ }
3337
+ var arrayPush_default = arrayPush;
3338
+
3339
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseGetAllKeys.js
3340
+ function baseGetAllKeys(object, keysFunc, symbolsFunc) {
3341
+ var result = keysFunc(object);
3342
+ return isArray_default(object) ? result : arrayPush_default(result, symbolsFunc(object));
3343
+ }
3344
+ var baseGetAllKeys_default = baseGetAllKeys;
3345
+
3346
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_arrayFilter.js
3347
+ function arrayFilter(array, predicate) {
3348
+ var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = [];
3349
+ while (++index < length) {
3350
+ var value = array[index];
3351
+ if (predicate(value, index, array)) {
3352
+ result[resIndex++] = value;
3353
+ }
3354
+ }
3355
+ return result;
3356
+ }
3357
+ var arrayFilter_default = arrayFilter;
3358
+
3359
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/stubArray.js
3360
+ function stubArray() {
3361
+ return [];
3362
+ }
3363
+ var stubArray_default = stubArray;
3364
+
3365
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getSymbols.js
3366
+ var objectProto12 = Object.prototype;
3367
+ var propertyIsEnumerable2 = objectProto12.propertyIsEnumerable;
3368
+ var nativeGetSymbols = Object.getOwnPropertySymbols;
3369
+ var getSymbols = !nativeGetSymbols ? stubArray_default : function(object) {
3370
+ if (object == null) {
3371
+ return [];
3372
+ }
3373
+ object = Object(object);
3374
+ return arrayFilter_default(nativeGetSymbols(object), function(symbol) {
3375
+ return propertyIsEnumerable2.call(object, symbol);
3376
+ });
3377
+ };
3378
+ var getSymbols_default = getSymbols;
3379
+
3380
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeys.js
3381
+ var nativeKeys = overArg_default(Object.keys, Object);
3382
+ var nativeKeys_default = nativeKeys;
3383
+
3384
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseKeys.js
3385
+ var objectProto13 = Object.prototype;
3386
+ var hasOwnProperty10 = objectProto13.hasOwnProperty;
3387
+ function baseKeys(object) {
3388
+ if (!isPrototype_default(object)) {
3389
+ return nativeKeys_default(object);
3390
+ }
3391
+ var result = [];
3392
+ for (var key in Object(object)) {
3393
+ if (hasOwnProperty10.call(object, key) && key != "constructor") {
3394
+ result.push(key);
3395
+ }
3396
+ }
3397
+ return result;
3398
+ }
3399
+ var baseKeys_default = baseKeys;
3400
+
3401
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/keys.js
3402
+ function keys(object) {
3403
+ return isArrayLike_default(object) ? arrayLikeKeys_default(object) : baseKeys_default(object);
3404
+ }
3405
+ var keys_default = keys;
3406
+
3407
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeys.js
3408
+ function getAllKeys(object) {
3409
+ return baseGetAllKeys_default(object, keys_default, getSymbols_default);
3410
+ }
3411
+ var getAllKeys_default = getAllKeys;
3412
+
2029
3413
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_equalObjects.js
2030
3414
  var COMPARE_PARTIAL_FLAG3 = 1;
2031
- var objectProto15 = Object.prototype;
2032
- var hasOwnProperty12 = objectProto15.hasOwnProperty;
3415
+ var objectProto14 = Object.prototype;
3416
+ var hasOwnProperty11 = objectProto14.hasOwnProperty;
2033
3417
  function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
2034
3418
  var isPartial = bitmask & COMPARE_PARTIAL_FLAG3, objProps = getAllKeys_default(object), objLength = objProps.length, othProps = getAllKeys_default(other), othLength = othProps.length;
2035
3419
  if (objLength != othLength && !isPartial) {
@@ -2038,7 +3422,7 @@ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
2038
3422
  var index = objLength;
2039
3423
  while (index--) {
2040
3424
  var key = objProps[index];
2041
- if (!(isPartial ? key in other : hasOwnProperty12.call(other, key))) {
3425
+ if (!(isPartial ? key in other : hasOwnProperty11.call(other, key))) {
2042
3426
  return false;
2043
3427
  }
2044
3428
  }
@@ -2075,18 +3459,69 @@ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
2075
3459
  }
2076
3460
  var equalObjects_default = equalObjects;
2077
3461
 
3462
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_DataView.js
3463
+ var DataView = getNative_default(root_default, "DataView");
3464
+ var DataView_default = DataView;
3465
+
3466
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Promise.js
3467
+ var Promise2 = getNative_default(root_default, "Promise");
3468
+ var Promise_default = Promise2;
3469
+
3470
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_Set.js
3471
+ var Set2 = getNative_default(root_default, "Set");
3472
+ var Set_default = Set2;
3473
+
3474
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_WeakMap.js
3475
+ var WeakMap = getNative_default(root_default, "WeakMap");
3476
+ var WeakMap_default = WeakMap;
3477
+
3478
+ // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_getTag.js
3479
+ var mapTag3 = "[object Map]";
3480
+ var objectTag3 = "[object Object]";
3481
+ var promiseTag = "[object Promise]";
3482
+ var setTag3 = "[object Set]";
3483
+ var weakMapTag2 = "[object WeakMap]";
3484
+ var dataViewTag3 = "[object DataView]";
3485
+ var dataViewCtorString = toSource_default(DataView_default);
3486
+ var mapCtorString = toSource_default(Map_default);
3487
+ var promiseCtorString = toSource_default(Promise_default);
3488
+ var setCtorString = toSource_default(Set_default);
3489
+ var weakMapCtorString = toSource_default(WeakMap_default);
3490
+ var getTag = baseGetTag_default;
3491
+ if (DataView_default && getTag(new DataView_default(new ArrayBuffer(1))) != dataViewTag3 || Map_default && getTag(new Map_default()) != mapTag3 || Promise_default && getTag(Promise_default.resolve()) != promiseTag || Set_default && getTag(new Set_default()) != setTag3 || WeakMap_default && getTag(new WeakMap_default()) != weakMapTag2) {
3492
+ getTag = function(value) {
3493
+ var result = baseGetTag_default(value), Ctor = result == objectTag3 ? value.constructor : void 0, ctorString = Ctor ? toSource_default(Ctor) : "";
3494
+ if (ctorString) {
3495
+ switch (ctorString) {
3496
+ case dataViewCtorString:
3497
+ return dataViewTag3;
3498
+ case mapCtorString:
3499
+ return mapTag3;
3500
+ case promiseCtorString:
3501
+ return promiseTag;
3502
+ case setCtorString:
3503
+ return setTag3;
3504
+ case weakMapCtorString:
3505
+ return weakMapTag2;
3506
+ }
3507
+ }
3508
+ return result;
3509
+ };
3510
+ }
3511
+ var getTag_default = getTag;
3512
+
2078
3513
  // ../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/_baseIsEqualDeep.js
2079
3514
  var COMPARE_PARTIAL_FLAG4 = 1;
2080
- var argsTag4 = "[object Arguments]";
2081
- var arrayTag3 = "[object Array]";
2082
- var objectTag5 = "[object Object]";
2083
- var objectProto16 = Object.prototype;
2084
- var hasOwnProperty13 = objectProto16.hasOwnProperty;
3515
+ var argsTag3 = "[object Arguments]";
3516
+ var arrayTag2 = "[object Array]";
3517
+ var objectTag4 = "[object Object]";
3518
+ var objectProto15 = Object.prototype;
3519
+ var hasOwnProperty12 = objectProto15.hasOwnProperty;
2085
3520
  function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
2086
- var objIsArr = isArray_default(object), othIsArr = isArray_default(other), objTag = objIsArr ? arrayTag3 : getTag_default(object), othTag = othIsArr ? arrayTag3 : getTag_default(other);
2087
- objTag = objTag == argsTag4 ? objectTag5 : objTag;
2088
- othTag = othTag == argsTag4 ? objectTag5 : othTag;
2089
- var objIsObj = objTag == objectTag5, othIsObj = othTag == objectTag5, isSameTag = objTag == othTag;
3521
+ var objIsArr = isArray_default(object), othIsArr = isArray_default(other), objTag = objIsArr ? arrayTag2 : getTag_default(object), othTag = othIsArr ? arrayTag2 : getTag_default(other);
3522
+ objTag = objTag == argsTag3 ? objectTag4 : objTag;
3523
+ othTag = othTag == argsTag3 ? objectTag4 : othTag;
3524
+ var objIsObj = objTag == objectTag4, othIsObj = othTag == objectTag4, isSameTag = objTag == othTag;
2090
3525
  if (isSameTag && isBuffer_default(object)) {
2091
3526
  if (!isBuffer_default(other)) {
2092
3527
  return false;
@@ -2099,7 +3534,7 @@ function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
2099
3534
  return objIsArr || isTypedArray_default(object) ? equalArrays_default(object, other, bitmask, customizer, equalFunc, stack) : equalByTag_default(object, other, objTag, bitmask, customizer, equalFunc, stack);
2100
3535
  }
2101
3536
  if (!(bitmask & COMPARE_PARTIAL_FLAG4)) {
2102
- var objIsWrapped = objIsObj && hasOwnProperty13.call(object, "__wrapped__"), othIsWrapped = othIsObj && hasOwnProperty13.call(other, "__wrapped__");
3537
+ var objIsWrapped = objIsObj && hasOwnProperty12.call(object, "__wrapped__"), othIsWrapped = othIsObj && hasOwnProperty12.call(other, "__wrapped__");
2103
3538
  if (objIsWrapped || othIsWrapped) {
2104
3539
  var objUnwrapped = objIsWrapped ? object.value() : object, othUnwrapped = othIsWrapped ? other.value() : other;
2105
3540
  stack || (stack = new Stack_default());
@@ -2133,32 +3568,33 @@ function isEqual(value, other) {
2133
3568
  var isEqual_default = isEqual;
2134
3569
 
2135
3570
  // src/hooks/useStableValue.ts
3571
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect2;
2136
3572
  function useStableValue(value) {
2137
- const ref = useRef(value);
3573
+ const ref = useRef3(value);
2138
3574
  const prev = ref.current;
2139
3575
  const stableValue = isEqual_default(prev, value) ? prev : value;
2140
- useEffect(() => {
3576
+ useIsomorphicLayoutEffect(() => {
2141
3577
  ref.current = stableValue;
2142
3578
  }, [stableValue]);
2143
3579
  return stableValue;
2144
3580
  }
2145
3581
 
2146
3582
  // src/components/typography/Default.tsx
2147
- import { memo as memo2 } from "react";
2148
- import { jsx as jsx3 } from "react/jsx-runtime";
2149
- var DefaultTypography = memo2(({ children, fontSize, variant, colorScheme, style }) => /* @__PURE__ */ jsx3(
2150
- "div",
2151
- {
2152
- className: `aim-typography-root ${variant ?? ""} ${colorScheme ?? ""}`.trim(),
2153
- style: { width: "100%", fontSize, ...style },
2154
- children
2155
- }
2156
- ));
3583
+ import { memo as memo3, useMemo as useMemo5 } from "react";
3584
+ import { jsx as jsx7 } from "react/jsx-runtime";
3585
+ var DefaultTypography = memo3(({ children, fontSize, variant, colorScheme, style }) => {
3586
+ const className = useMemo5(
3587
+ () => ["aim-typography-root", variant, colorScheme].filter(Boolean).join(" "),
3588
+ [variant, colorScheme]
3589
+ );
3590
+ const mergedStyle = useMemo5(() => ({ width: "100%", fontSize, ...style }), [fontSize, style]);
3591
+ return /* @__PURE__ */ jsx7("div", { className, style: mergedStyle, children });
3592
+ });
2157
3593
  DefaultTypography.displayName = "DefaultTypography";
2158
3594
  var Default_default = DefaultTypography;
2159
3595
 
2160
3596
  // src/index.tsx
2161
- import { jsx as jsx4 } from "react/jsx-runtime";
3597
+ import { jsx as jsx8 } from "react/jsx-runtime";
2162
3598
  var AIMarkdownComponent = ({
2163
3599
  streaming = false,
2164
3600
  content,
@@ -2171,49 +3607,56 @@ var AIMarkdownComponent = ({
2171
3607
  Typography = Default_default,
2172
3608
  ExtraStyles,
2173
3609
  variant = "default",
2174
- colorScheme = "light"
3610
+ colorScheme = "light",
3611
+ documentId
2175
3612
  }) => {
2176
- const usedFontSize = fontSize ? typeof fontSize === "number" ? `${fontSize}px` : fontSize : "0.9375rem";
3613
+ const usedFontSize = fontSize === void 0 ? "0.9375rem" : typeof fontSize === "number" ? `${fontSize}px` : fontSize;
3614
+ const generatedId = useId3();
3615
+ const usedDocumentId = documentId && documentId.length > 0 ? documentId : generatedId;
2177
3616
  const stableDefaultConfig = useStableValue(defaultConfig);
2178
3617
  const stableConfig = useStableValue(config);
2179
3618
  const stablePreprocessors = useStableValue(contentPreprocessors);
2180
3619
  const stableCustomComponents = useStableValue(customComponents);
2181
- const usedContent = useMemo3(
3620
+ const usedContent = useMemo6(
2182
3621
  () => content ? preprocessAIMDContent(content, stablePreprocessors) : content,
2183
3622
  [content, stablePreprocessors]
2184
3623
  );
2185
- return /* @__PURE__ */ jsx4(AIMarkdownMetadataProvider, { metadata, children: /* @__PURE__ */ jsx4(
3624
+ const typographyStyle = useMemo6(() => ({ "--aim-font-size-root": usedFontSize }), [usedFontSize]);
3625
+ return /* @__PURE__ */ jsx8(AIMarkdownMetadataProvider, { metadata, children: /* @__PURE__ */ jsx8(
2186
3626
  context_default,
2187
3627
  {
2188
3628
  streaming,
2189
3629
  fontSize: usedFontSize,
2190
3630
  variant,
2191
3631
  colorScheme,
3632
+ documentId: usedDocumentId,
2192
3633
  defaultConfig: stableDefaultConfig,
2193
3634
  config: stableConfig,
2194
- children: /* @__PURE__ */ jsx4(
3635
+ children: /* @__PURE__ */ jsx8(
2195
3636
  Typography,
2196
3637
  {
2197
3638
  fontSize: usedFontSize,
2198
3639
  variant,
2199
3640
  colorScheme,
2200
- style: { "--aim-font-size-root": usedFontSize },
2201
- children: ExtraStyles ? /* @__PURE__ */ jsx4(ExtraStyles, { children: /* @__PURE__ */ jsx4(MarkdownContent_default, { content: usedContent, customComponents: stableCustomComponents }) }) : /* @__PURE__ */ jsx4(MarkdownContent_default, { content: usedContent, customComponents: stableCustomComponents })
3641
+ style: typographyStyle,
3642
+ children: ExtraStyles ? /* @__PURE__ */ jsx8(ExtraStyles, { children: /* @__PURE__ */ jsx8(MarkdownContent_default, { content: usedContent, customComponents: stableCustomComponents }) }) : /* @__PURE__ */ jsx8(MarkdownContent_default, { content: usedContent, customComponents: stableCustomComponents })
2202
3643
  }
2203
3644
  )
2204
3645
  }
2205
3646
  ) });
2206
3647
  };
2207
- var AIMarkdown = memo3(AIMarkdownComponent);
3648
+ var AIMarkdown = memo4(AIMarkdownComponent);
2208
3649
  AIMarkdown.displayName = "AIMarkdown";
2209
3650
  var index_default = AIMarkdown;
2210
3651
  export {
3652
+ AIMarkdownDocuments,
2211
3653
  AIMarkdownRenderDisplayOptimizeAbility,
2212
3654
  AIMarkdownRenderExtraSyntax,
2213
3655
  index_default as default,
2214
3656
  defaultAIMarkdownRenderConfig,
2215
3657
  useAIMarkdownMetadata,
2216
3658
  useAIMarkdownRenderState,
3659
+ useDocumentRegistry,
2217
3660
  useStableValue
2218
3661
  };
2219
3662
  //# sourceMappingURL=index.js.map