@ai-react-markdown/engine 2.11.0 → 2.12.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.cjs CHANGED
@@ -79,6 +79,7 @@ __export(src_exports, {
79
79
  rehypeRebaseHashLinks: () => rehypeRebaseHashLinks_default,
80
80
  rehypeVerifyEngineTags: () => rehypeVerifyEngineTags,
81
81
  removeComments: () => removeComments,
82
+ resolveCrossChunkReference: () => resolveCrossChunkReference,
82
83
  sanitizeCrossChunkUrl: () => sanitizeCrossChunkUrl,
83
84
  sanitizeSchema: () => sanitizeSchema,
84
85
  shortenDocumentId: () => shortenDocumentId,
@@ -2223,6 +2224,38 @@ function normalizeForMatch(s) {
2223
2224
  return (0, import_micromark_util_normalize_identifier3.normalizeIdentifier)(s);
2224
2225
  }
2225
2226
 
2227
+ // src/components/blankLineScanner.ts
2228
+ function createBlankLineScanner() {
2229
+ let end = 0;
2230
+ let newline = false;
2231
+ let cr = false;
2232
+ return (source, from = 0) => {
2233
+ if (from === 0) {
2234
+ end = 0;
2235
+ newline = false;
2236
+ cr = false;
2237
+ }
2238
+ for (let i = from; i < source.length; i++) {
2239
+ const c = source[i];
2240
+ if (c === "\n") {
2241
+ if (newline) {
2242
+ end = i + 1;
2243
+ newline = false;
2244
+ } else newline = true;
2245
+ cr = false;
2246
+ } else if (newline) {
2247
+ if ((c === " " || c === " ") && !cr) continue;
2248
+ if (c === "\r" && !cr) cr = true;
2249
+ else {
2250
+ newline = false;
2251
+ cr = false;
2252
+ }
2253
+ }
2254
+ }
2255
+ return end;
2256
+ };
2257
+ }
2258
+
2226
2259
  // src/components/collectDefLabels.ts
2227
2260
  var SCANNER_BOUNDARY_PROFILE = { defListEnabled: false, mathFlow: false, referenceTaint: false };
2228
2261
  function buildProcessor() {
@@ -2254,19 +2287,12 @@ var setsEqual = (a, b) => {
2254
2287
  for (const v of a) if (!b.has(v)) return false;
2255
2288
  return true;
2256
2289
  };
2257
- var BLANK_LINE_RE = /\r?\n[ \t]*\r?\n/g;
2258
- function lastRegionStart(source) {
2259
- BLANK_LINE_RE.lastIndex = 0;
2260
- let start = 0;
2261
- for (let m = BLANK_LINE_RE.exec(source); m !== null; m = BLANK_LINE_RE.exec(source)) {
2262
- start = m.index + m[0].length;
2263
- }
2264
- return start;
2265
- }
2266
2290
  var DEF_LINE_START_RE = /^[ \t>*+\d.)-]*\[(?:[^\]\\]|\\[\s\S])*\]:/m;
2267
2291
  function createDefLabelScanner(parse = collectDefLabels) {
2268
2292
  let prevSource = null;
2269
2293
  let prevLabels = null;
2294
+ const scanBlankLines = createBlankLineScanner();
2295
+ let regionStart = 0;
2270
2296
  let frozenEnd = 0;
2271
2297
  let frozenFootnotes = /* @__PURE__ */ new Set();
2272
2298
  let frozenLinks = /* @__PURE__ */ new Set();
@@ -2279,13 +2305,16 @@ function createDefLabelScanner(parse = collectDefLabels) {
2279
2305
  };
2280
2306
  return {
2281
2307
  scan(source) {
2308
+ if (source === prevSource && prevLabels !== null) return prevLabels;
2309
+ const previousRegionStart = regionStart;
2310
+ const appended = prevSource !== null && source.startsWith(prevSource);
2311
+ regionStart = scanBlankLines(source, appended ? prevSource.length : 0);
2282
2312
  let isAppend = false;
2283
2313
  if (prevSource !== null && prevLabels !== null) {
2284
2314
  if (source === prevSource) return prevLabels;
2285
2315
  if (source.startsWith(prevSource)) {
2286
2316
  isAppend = true;
2287
- const regionStart = lastRegionStart(prevSource);
2288
- const region = prevSource.slice(regionStart) + source.slice(prevSource.length);
2317
+ const region = source.slice(previousRegionStart);
2289
2318
  if (!DEF_LINE_START_RE.test(region)) {
2290
2319
  prevSource = source;
2291
2320
  return prevLabels;
@@ -2518,8 +2547,47 @@ function* extractContributions(mdast, options = {}) {
2518
2547
  for (const c of out) yield c;
2519
2548
  }
2520
2549
 
2550
+ // src/components/registryIndex.ts
2551
+ function buildRegistryIndex(registry) {
2552
+ const index = {
2553
+ footnotes: /* @__PURE__ */ new Map(),
2554
+ links: /* @__PURE__ */ new Map(),
2555
+ numbers: /* @__PURE__ */ new Map(),
2556
+ counts: /* @__PURE__ */ new Map(),
2557
+ occurrences: /* @__PURE__ */ new Map()
2558
+ };
2559
+ for (const sym of registry.chunkOrder) {
2560
+ const data = registry.chunkData.get(sym);
2561
+ if (!data) continue;
2562
+ for (const label of data.defs.keys()) if (!index.footnotes.has(label)) index.footnotes.set(label, sym);
2563
+ for (const label of data.linkDefs.keys()) if (!index.links.has(label)) index.links.set(label, sym);
2564
+ const local = /* @__PURE__ */ new Map();
2565
+ index.occurrences.set(sym, local);
2566
+ for (const ref of data.refs) {
2567
+ if (ref.kind !== "footnote") continue;
2568
+ const label = ref.label;
2569
+ if (!index.numbers.has(label)) index.numbers.set(label, index.numbers.size + 1);
2570
+ const total = (index.counts.get(label) ?? 0) + 1;
2571
+ index.counts.set(label, total);
2572
+ const prior = local.get(label);
2573
+ if (prior) prior.count++;
2574
+ else local.set(label, { start: total, count: 1 });
2575
+ }
2576
+ }
2577
+ return index;
2578
+ }
2579
+
2521
2580
  // src/components/documentRegistry.ts
2522
2581
  function createRegistry(onEmpty) {
2582
+ let index;
2583
+ let indexedVersion = -1;
2584
+ const getIndex = () => {
2585
+ if (!index || indexedVersion !== reg.version) {
2586
+ index = buildRegistryIndex(reg);
2587
+ indexedVersion = reg.version;
2588
+ }
2589
+ return index;
2590
+ };
2523
2591
  const reg = {
2524
2592
  chunkOrder: [],
2525
2593
  chunkData: /* @__PURE__ */ new Map(),
@@ -2671,72 +2739,25 @@ function createRegistry(onEmpty) {
2671
2739
  };
2672
2740
  },
2673
2741
  canonicalFootnoteFor(label) {
2674
- const id = normalizeId(label);
2675
- for (const sym of this.chunkOrder) {
2676
- const data = this.chunkData.get(sym);
2677
- if (data?.defs.has(id)) return sym;
2678
- }
2679
- return null;
2742
+ return getIndex().footnotes.get(normalizeId(label)) ?? null;
2680
2743
  },
2681
2744
  canonicalLinkFor(label) {
2682
- const id = normalizeId(label);
2683
- for (const sym of this.chunkOrder) {
2684
- const data = this.chunkData.get(sym);
2685
- if (data?.linkDefs.has(id)) return sym;
2686
- }
2687
- return null;
2745
+ return getIndex().links.get(normalizeId(label)) ?? null;
2688
2746
  },
2689
2747
  globalNumber(label) {
2690
- const id = normalizeId(label);
2691
- let n = 0;
2692
- const seen = /* @__PURE__ */ new Set();
2693
- for (const sym of this.chunkOrder) {
2694
- const data = this.chunkData.get(sym);
2695
- if (!data) continue;
2696
- for (const ref of data.refs) {
2697
- if (ref.kind !== "footnote") continue;
2698
- if (!seen.has(ref.label)) {
2699
- seen.add(ref.label);
2700
- n++;
2701
- if (ref.label === id) return n;
2702
- }
2703
- }
2704
- }
2705
- return null;
2748
+ return getIndex().numbers.get(normalizeId(label)) ?? null;
2706
2749
  },
2707
2750
  resolveLinkDef(label) {
2708
- const sym = this.canonicalLinkFor(label);
2709
- if (!sym) return null;
2710
- return this.chunkData.get(sym)?.linkDefs.get(normalizeId(label)) ?? null;
2751
+ const id = normalizeId(label);
2752
+ const sym = getIndex().links.get(id);
2753
+ return sym ? this.chunkData.get(sym)?.linkDefs.get(id) ?? null : null;
2711
2754
  },
2712
2755
  getRefsForLabel(label) {
2713
- const id = normalizeId(label);
2714
- let n = 0;
2715
- for (const sym of this.chunkOrder) {
2716
- const data = this.chunkData.get(sym);
2717
- if (!data) continue;
2718
- for (const ref of data.refs) {
2719
- if (ref.kind === "footnote" && ref.label === id) n++;
2720
- }
2721
- }
2722
- return n;
2756
+ return getIndex().counts.get(normalizeId(label)) ?? 0;
2723
2757
  },
2724
2758
  globalOccurrenceForRef(chunkSym, label, localOccurrence) {
2725
- const id = normalizeId(label);
2726
- let global2 = 0;
2727
- for (const sym of this.chunkOrder) {
2728
- const data = this.chunkData.get(sym);
2729
- if (!data) continue;
2730
- let localCount = 0;
2731
- for (const ref of data.refs) {
2732
- if (ref.kind !== "footnote") continue;
2733
- if (ref.label !== id) continue;
2734
- localCount++;
2735
- global2++;
2736
- if (sym === chunkSym && localCount === localOccurrence) return global2;
2737
- }
2738
- }
2739
- return null;
2759
+ const range = getIndex().occurrences.get(chunkSym)?.get(normalizeId(label));
2760
+ return range && Number.isInteger(localOccurrence) && localOccurrence > 0 && localOccurrence <= range.count ? range.start + localOccurrence - 1 : null;
2740
2761
  },
2741
2762
  _notify() {
2742
2763
  this.version++;
@@ -2801,7 +2822,7 @@ var ENGINE_PLACEHOLDER_TAGS = /* @__PURE__ */ new Set([
2801
2822
  "cross-chunk-image"
2802
2823
  ]);
2803
2824
  var ENGINE_PROVENANCE_PROPERTY = "engineProvenance";
2804
- function walk(parent, provenance) {
2825
+ function walk(parent, provenance, ancestors) {
2805
2826
  const children = parent.children;
2806
2827
  let i = 0;
2807
2828
  while (i < children.length) {
@@ -2812,21 +2833,32 @@ function walk(parent, provenance) {
2812
2833
  const genuine = provenance !== "" && typeof stamped === "string" && stamped === provenance;
2813
2834
  if (genuine) {
2814
2835
  delete props[ENGINE_PROVENANCE_PROPERTY];
2815
- walk(node, provenance);
2836
+ if (ancestors && (node.tagName === "cross-chunk-link" || node.tagName === "cross-chunk-image")) {
2837
+ (node.data ??= {}).referenceAncestors = ancestors.slice();
2838
+ }
2839
+ ancestors?.push(
2840
+ node.tagName === "cross-chunk-link" ? "a" : node.tagName === "cross-chunk-image" ? "img" : node.tagName
2841
+ );
2842
+ walk(node, provenance, ancestors);
2843
+ ancestors?.pop();
2816
2844
  i += 1;
2817
2845
  } else {
2818
2846
  children.splice(i, 1, ...node.children);
2819
2847
  }
2820
2848
  continue;
2821
2849
  }
2822
- if (node.type === "element") walk(node, provenance);
2850
+ if (node.type === "element") {
2851
+ ancestors?.push(node.tagName);
2852
+ walk(node, provenance, ancestors);
2853
+ ancestors?.pop();
2854
+ }
2823
2855
  i += 1;
2824
2856
  }
2825
2857
  }
2826
2858
  function rehypeVerifyEngineTags(options) {
2827
2859
  const provenance = options?.provenance ?? "";
2828
2860
  return function transformer(tree) {
2829
- walk(tree, provenance);
2861
+ walk(tree, provenance, options?.referenceAncestors ? [] : void 0);
2830
2862
  };
2831
2863
  }
2832
2864
 
@@ -2847,16 +2879,18 @@ var import_remark_remove_comments = __toESM(require("remark-remove-comments"), 1
2847
2879
  // src/components/rehypeRebaseHashLinks.ts
2848
2880
  var import_unist_util_visit5 = require("unist-util-visit");
2849
2881
  var DEFAULT_PREFIX = "user-content-";
2882
+ function rebaseHashHref(href, prefix) {
2883
+ const hashPrefix = "#" + prefix;
2884
+ return href.startsWith("#") && !href.startsWith(hashPrefix) ? hashPrefix + href.slice(1) : href;
2885
+ }
2850
2886
  var rehypeRebaseHashLinks = (options) => {
2851
2887
  const prefix = options?.prefix ?? DEFAULT_PREFIX;
2852
- const hashPrefix = "#" + prefix;
2853
2888
  return (tree) => {
2854
2889
  (0, import_unist_util_visit5.visit)(tree, "element", (node) => {
2855
2890
  if (node.tagName !== "a") return;
2856
2891
  const href = node.properties?.href;
2857
2892
  if (typeof href !== "string" || !href.startsWith("#")) return;
2858
- if (href.startsWith(hashPrefix)) return;
2859
- node.properties.href = hashPrefix + href.slice(1);
2893
+ node.properties.href = rebaseHashHref(href, prefix);
2860
2894
  });
2861
2895
  };
2862
2896
  };
@@ -2942,7 +2976,15 @@ function buildCoreRehypePlugins(sanitizeSchema2, clobberPrefix, options) {
2942
2976
  [import_rehype_raw.default, { passThrough: [] }],
2943
2977
  // Unwrap forged engine placeholders BEFORE sanitize admits their tag
2944
2978
  // names. Only when the caller holds a credential (see the option's doc).
2945
- ...options ? [[rehypeVerifyEngineTags, { provenance: options.provenance }]] : [],
2979
+ ...options ? [
2980
+ [
2981
+ rehypeVerifyEngineTags,
2982
+ {
2983
+ provenance: options.provenance,
2984
+ ...sanitizeSchema2.ancestors?.a || sanitizeSchema2.ancestors?.img ? { referenceAncestors: true } : {}
2985
+ }
2986
+ ]
2987
+ ] : [],
2946
2988
  // Sanitize HTML while allowing <mark> (highlight), KaTeX class names,
2947
2989
  // and any extra protocols the caller permitted via the `sanitizeSchema`
2948
2990
  // prop. Override `clobberPrefix` with the instance-scoped value — the
@@ -3016,11 +3058,9 @@ function buildCrossChunkHandlers() {
3016
3058
  type: "element",
3017
3059
  tagName: "cross-chunk-link",
3018
3060
  properties: {
3019
- // `label` is the ORIGINAL source text (mdast's `label` field), NOT
3020
- // the normalized `identifier`. The placeholder uses it to construct
3021
- // hrefs that line up with mdast-util-to-hast's default `<li id>`
3022
- // which also preserves source case. Registry lookups normalize
3023
- // internally, so cross-chunk case-insensitive matching still works.
3061
+ // Display labels decode escapes; registry identifiers must retain
3062
+ // those bytes. Never use the display label as the lookup key.
3063
+ identifier: node.identifier,
3024
3064
  label: node.label ?? node.identifier,
3025
3065
  referenceType: node.referenceType,
3026
3066
  documentId: s.options.documentId,
@@ -3039,6 +3079,7 @@ function buildCrossChunkHandlers() {
3039
3079
  type: "element",
3040
3080
  tagName: "cross-chunk-image",
3041
3081
  properties: {
3082
+ identifier: node.identifier,
3042
3083
  label: node.label ?? node.identifier,
3043
3084
  referenceType: node.referenceType,
3044
3085
  alt: node.alt ?? "",
@@ -4301,8 +4342,8 @@ var sanitizeSchema = deepFreeze(
4301
4342
  attributes: {
4302
4343
  ...import_rehype_sanitize2.defaultSchema.attributes,
4303
4344
  code: mergeClassNameAllowlist(import_rehype_sanitize2.defaultSchema.attributes?.code, ["math-inline", "math-display"]),
4304
- "cross-chunk-link": ["label", "referenceType", "documentId", "localUrl", "localTitle"],
4305
- "cross-chunk-image": ["label", "referenceType", "documentId", "alt", "localUrl", "localTitle"],
4345
+ "cross-chunk-link": ["identifier", "label", "referenceType", "documentId", "localUrl", "localTitle"],
4346
+ "cross-chunk-image": ["identifier", "label", "referenceType", "documentId", "alt", "localUrl", "localTitle"],
4306
4347
  "footnote-sup": ["label", "localOccurrence", "localNumber", "documentId"]
4307
4348
  },
4308
4349
  strip: [.../* @__PURE__ */ new Set([...import_rehype_sanitize2.defaultSchema.strip || [], ...STRIPPED_TAGS])]
@@ -4338,6 +4379,49 @@ function sanitizeCrossChunkUrl(rawUrl, key, tagName, urlTransform, schema) {
4338
4379
  return String(transformed);
4339
4380
  }
4340
4381
 
4382
+ // src/components/resolveCrossChunkReference.ts
4383
+ var import_rehype_sanitize3 = __toESM(require("rehype-sanitize"), 1);
4384
+ var import_micromark_util_sanitize_uri3 = require("micromark-util-sanitize-uri");
4385
+ function resolveCrossChunkReference(input, schema, urlTransform, clobberPrefix) {
4386
+ const key = input.tagName === "a" ? "href" : "src";
4387
+ const element = {
4388
+ type: "element",
4389
+ tagName: input.tagName,
4390
+ properties: {
4391
+ [key]: (0, import_micromark_util_sanitize_uri3.normalizeUri)(input.url),
4392
+ ...input.tagName === "img" ? { alt: input.alt ?? "" } : {},
4393
+ ...input.title !== void 0 ? { title: input.title } : {}
4394
+ },
4395
+ children: input.tagName === "a" ? [{ type: "text", value: "__reference_children__" }] : []
4396
+ };
4397
+ const requiredAncestors = schema.ancestors?.[input.tagName];
4398
+ const recordedAncestors = input.node?.data?.referenceAncestors;
4399
+ let finalSchema = schema;
4400
+ if (requiredAncestors && Array.isArray(recordedAncestors) && requiredAncestors.some((tag) => recordedAncestors.includes(tag))) {
4401
+ const ancestors = { ...schema.ancestors };
4402
+ delete ancestors[input.tagName];
4403
+ finalSchema = { ...schema, ancestors };
4404
+ }
4405
+ const root2 = (0, import_rehype_sanitize3.default)({ ...finalSchema, clobberPrefix })({ type: "root", children: [element] });
4406
+ const node = root2.children[0];
4407
+ if (node?.type !== "element") return { element: null, keepChildren: node?.type === "text" };
4408
+ if (node.tagName === "a" && typeof node.properties.href === "string") {
4409
+ node.properties.href = rebaseHashHref(node.properties.href, clobberPrefix);
4410
+ }
4411
+ node.children = input.node?.children ?? [];
4412
+ if (input.node?.position) node.position = input.node.position;
4413
+ buildTransform({
4414
+ allowedElements: void 0,
4415
+ disallowedElements: void 0,
4416
+ allowElement: void 0,
4417
+ skipHtml: void 0,
4418
+ unwrapDisallowed: void 0,
4419
+ urlTransform
4420
+ })(node, 0, root2);
4421
+ node.children = [];
4422
+ return { element: node, keepChildren: false };
4423
+ }
4424
+
4341
4425
  // src/plugins/defs.ts
4342
4426
  function getEnginePluginInternals(plugin) {
4343
4427
  const candidate = plugin;
@@ -4542,6 +4626,8 @@ var createSmoothStreamController = (options = {}) => {
4542
4626
  let source = "";
4543
4627
  let visibleEnd = 0;
4544
4628
  let pending = [];
4629
+ let pendingHead = 0;
4630
+ const pendingCount = () => pending.length - pendingHead;
4545
4631
  let tentativeEnd = 0;
4546
4632
  let finished = false;
4547
4633
  let seam;
@@ -4586,7 +4672,7 @@ var createSmoothStreamController = (options = {}) => {
4586
4672
  cancelFrame = void 0;
4587
4673
  };
4588
4674
  const ensureScheduled = () => {
4589
- if (disposed || cancelFrame || pending.length === 0) return;
4675
+ if (disposed || cancelFrame || pendingCount() === 0) return;
4590
4676
  lastTickAt = now();
4591
4677
  credit = 0;
4592
4678
  cancelFrame = schedule(tick);
@@ -4600,31 +4686,38 @@ var createSmoothStreamController = (options = {}) => {
4600
4686
  const params = resolveParams();
4601
4687
  let rate;
4602
4688
  if (finished && drainDeadlineAt !== void 0) {
4603
- rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, drainDeadlineAt - t));
4689
+ rate = Math.max(params.minCharsPerSecond, pendingCount() * 1e3 / Math.max(1, drainDeadlineAt - t));
4604
4690
  } else if (gapWindow.length > 0 && lastArrivalAt !== void 0) {
4605
4691
  const gaps = gapWindow.map((s) => s.gap).sort((a, b) => a - b);
4606
4692
  const intervalQ = gaps[Math.min(gaps.length - 1, Math.floor(gaps.length * INTERVAL_QUANTILE))];
4607
4693
  const horizon = Math.max(16, Math.min(params.bufferFactor * intervalQ + HORIZON_PAD_MS, params.maxLagMs));
4608
4694
  const deadline = Math.max(lastArrivalAt + horizon, t + DEADLINE_FLOOR_MS);
4609
- rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, deadline - t));
4695
+ rate = Math.max(params.minCharsPerSecond, pendingCount() * 1e3 / Math.max(1, deadline - t));
4610
4696
  } else {
4611
- rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, params.correctionTauMs));
4697
+ rate = Math.max(params.minCharsPerSecond, pendingCount() * 1e3 / Math.max(1, params.correctionTauMs));
4612
4698
  }
4613
4699
  credit += rate * dt / 1e3;
4614
- const reveal = Math.min(Math.floor(credit), pending.length);
4700
+ const reveal = Math.min(Math.floor(credit), pendingCount());
4615
4701
  if (reveal > 0) {
4616
- visibleEnd = pending[reveal - 1];
4617
- pending = pending.slice(reveal);
4618
- credit = pending.length > 0 ? credit - reveal : 0;
4702
+ visibleEnd = pending[pendingHead + reveal - 1];
4703
+ pendingHead += reveal;
4704
+ if (pendingHead === pending.length) {
4705
+ pending = [];
4706
+ pendingHead = 0;
4707
+ } else if (pendingHead >= 1024 && pendingHead * 2 >= pending.length) {
4708
+ pending = pending.slice(pendingHead);
4709
+ pendingHead = 0;
4710
+ }
4711
+ credit = pendingCount() > 0 ? credit - reveal : 0;
4619
4712
  notify();
4620
4713
  }
4621
- if (!disposed && !cancelFrame && pending.length > 0) cancelFrame = schedule(tick);
4714
+ if (!disposed && !cancelFrame && pendingCount() > 0) cancelFrame = schedule(tick);
4622
4715
  };
4623
4716
  const resegmentTail = () => {
4624
- if (seam !== void 0 && seam < source.length && pending[pending.length - 1] === seam) {
4717
+ if (pendingCount() > 0 && seam !== void 0 && seam < source.length && pending[pending.length - 1] === seam) {
4625
4718
  pending.pop();
4626
4719
  }
4627
- const from = pending.length > 0 ? pending[pending.length - 1] : visibleEnd;
4720
+ const from = pendingCount() > 0 ? pending[pending.length - 1] : visibleEnd;
4628
4721
  let anchor = from;
4629
4722
  if (seam !== void 0 && from <= seam) {
4630
4723
  anchor = Math.max(0, from - RESUME_LOOKBACK);
@@ -4658,6 +4751,7 @@ var createSmoothStreamController = (options = {}) => {
4658
4751
  visibleEnd = next.length;
4659
4752
  tentativeEnd = next.length;
4660
4753
  pending = [];
4754
+ pendingHead = 0;
4661
4755
  seam = next.length;
4662
4756
  credit = 0;
4663
4757
  cancelScheduled();
@@ -4689,7 +4783,7 @@ var createSmoothStreamController = (options = {}) => {
4689
4783
  if (finished) return;
4690
4784
  finished = true;
4691
4785
  lastArrivalAt = void 0;
4692
- if (tentativeEnd > (pending.length > 0 ? pending[pending.length - 1] : visibleEnd)) {
4786
+ if (tentativeEnd > (pendingCount() > 0 ? pending[pending.length - 1] : visibleEnd)) {
4693
4787
  pending.push(tentativeEnd);
4694
4788
  }
4695
4789
  const params = resolveParams();
@@ -4715,10 +4809,11 @@ var createSmoothStreamController = (options = {}) => {
4715
4809
  snap,
4716
4810
  flush() {
4717
4811
  disposed = false;
4718
- const target = finished ? source.length : pending.length > 0 ? pending[pending.length - 1] : visibleEnd;
4812
+ const target = finished ? source.length : pendingCount() > 0 ? pending[pending.length - 1] : visibleEnd;
4719
4813
  if (target <= visibleEnd) return;
4720
4814
  visibleEnd = target;
4721
4815
  pending = [];
4816
+ pendingHead = 0;
4722
4817
  credit = 0;
4723
4818
  cancelScheduled();
4724
4819
  notify();
@@ -5569,6 +5664,7 @@ function createRemendPreprocessor(options) {
5569
5664
  rehypeRebaseHashLinks,
5570
5665
  rehypeVerifyEngineTags,
5571
5666
  removeComments,
5667
+ resolveCrossChunkReference,
5572
5668
  sanitizeCrossChunkUrl,
5573
5669
  sanitizeSchema,
5574
5670
  shortenDocumentId,