@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 +191 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.dev.cjs +191 -95
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +190 -95
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +190 -95
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.dev.js
CHANGED
|
@@ -2138,6 +2138,38 @@ function normalizeForMatch(s) {
|
|
|
2138
2138
|
return normalizeIdentifier3(s);
|
|
2139
2139
|
}
|
|
2140
2140
|
|
|
2141
|
+
// src/components/blankLineScanner.ts
|
|
2142
|
+
function createBlankLineScanner() {
|
|
2143
|
+
let end = 0;
|
|
2144
|
+
let newline = false;
|
|
2145
|
+
let cr = false;
|
|
2146
|
+
return (source, from = 0) => {
|
|
2147
|
+
if (from === 0) {
|
|
2148
|
+
end = 0;
|
|
2149
|
+
newline = false;
|
|
2150
|
+
cr = false;
|
|
2151
|
+
}
|
|
2152
|
+
for (let i = from; i < source.length; i++) {
|
|
2153
|
+
const c = source[i];
|
|
2154
|
+
if (c === "\n") {
|
|
2155
|
+
if (newline) {
|
|
2156
|
+
end = i + 1;
|
|
2157
|
+
newline = false;
|
|
2158
|
+
} else newline = true;
|
|
2159
|
+
cr = false;
|
|
2160
|
+
} else if (newline) {
|
|
2161
|
+
if ((c === " " || c === " ") && !cr) continue;
|
|
2162
|
+
if (c === "\r" && !cr) cr = true;
|
|
2163
|
+
else {
|
|
2164
|
+
newline = false;
|
|
2165
|
+
cr = false;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
return end;
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2141
2173
|
// src/components/collectDefLabels.ts
|
|
2142
2174
|
var SCANNER_BOUNDARY_PROFILE = { defListEnabled: false, mathFlow: false, referenceTaint: false };
|
|
2143
2175
|
function buildProcessor() {
|
|
@@ -2169,19 +2201,12 @@ var setsEqual = (a, b) => {
|
|
|
2169
2201
|
for (const v of a) if (!b.has(v)) return false;
|
|
2170
2202
|
return true;
|
|
2171
2203
|
};
|
|
2172
|
-
var BLANK_LINE_RE = /\r?\n[ \t]*\r?\n/g;
|
|
2173
|
-
function lastRegionStart(source) {
|
|
2174
|
-
BLANK_LINE_RE.lastIndex = 0;
|
|
2175
|
-
let start = 0;
|
|
2176
|
-
for (let m = BLANK_LINE_RE.exec(source); m !== null; m = BLANK_LINE_RE.exec(source)) {
|
|
2177
|
-
start = m.index + m[0].length;
|
|
2178
|
-
}
|
|
2179
|
-
return start;
|
|
2180
|
-
}
|
|
2181
2204
|
var DEF_LINE_START_RE = /^[ \t>*+\d.)-]*\[(?:[^\]\\]|\\[\s\S])*\]:/m;
|
|
2182
2205
|
function createDefLabelScanner(parse = collectDefLabels) {
|
|
2183
2206
|
let prevSource = null;
|
|
2184
2207
|
let prevLabels = null;
|
|
2208
|
+
const scanBlankLines = createBlankLineScanner();
|
|
2209
|
+
let regionStart = 0;
|
|
2185
2210
|
let frozenEnd = 0;
|
|
2186
2211
|
let frozenFootnotes = /* @__PURE__ */ new Set();
|
|
2187
2212
|
let frozenLinks = /* @__PURE__ */ new Set();
|
|
@@ -2194,13 +2219,16 @@ function createDefLabelScanner(parse = collectDefLabels) {
|
|
|
2194
2219
|
};
|
|
2195
2220
|
return {
|
|
2196
2221
|
scan(source) {
|
|
2222
|
+
if (source === prevSource && prevLabels !== null) return prevLabels;
|
|
2223
|
+
const previousRegionStart = regionStart;
|
|
2224
|
+
const appended = prevSource !== null && source.startsWith(prevSource);
|
|
2225
|
+
regionStart = scanBlankLines(source, appended ? prevSource.length : 0);
|
|
2197
2226
|
let isAppend = false;
|
|
2198
2227
|
if (prevSource !== null && prevLabels !== null) {
|
|
2199
2228
|
if (source === prevSource) return prevLabels;
|
|
2200
2229
|
if (source.startsWith(prevSource)) {
|
|
2201
2230
|
isAppend = true;
|
|
2202
|
-
const
|
|
2203
|
-
const region = prevSource.slice(regionStart) + source.slice(prevSource.length);
|
|
2231
|
+
const region = source.slice(previousRegionStart);
|
|
2204
2232
|
if (!DEF_LINE_START_RE.test(region)) {
|
|
2205
2233
|
prevSource = source;
|
|
2206
2234
|
return prevLabels;
|
|
@@ -2433,8 +2461,47 @@ function* extractContributions(mdast, options = {}) {
|
|
|
2433
2461
|
for (const c of out) yield c;
|
|
2434
2462
|
}
|
|
2435
2463
|
|
|
2464
|
+
// src/components/registryIndex.ts
|
|
2465
|
+
function buildRegistryIndex(registry) {
|
|
2466
|
+
const index = {
|
|
2467
|
+
footnotes: /* @__PURE__ */ new Map(),
|
|
2468
|
+
links: /* @__PURE__ */ new Map(),
|
|
2469
|
+
numbers: /* @__PURE__ */ new Map(),
|
|
2470
|
+
counts: /* @__PURE__ */ new Map(),
|
|
2471
|
+
occurrences: /* @__PURE__ */ new Map()
|
|
2472
|
+
};
|
|
2473
|
+
for (const sym of registry.chunkOrder) {
|
|
2474
|
+
const data = registry.chunkData.get(sym);
|
|
2475
|
+
if (!data) continue;
|
|
2476
|
+
for (const label of data.defs.keys()) if (!index.footnotes.has(label)) index.footnotes.set(label, sym);
|
|
2477
|
+
for (const label of data.linkDefs.keys()) if (!index.links.has(label)) index.links.set(label, sym);
|
|
2478
|
+
const local = /* @__PURE__ */ new Map();
|
|
2479
|
+
index.occurrences.set(sym, local);
|
|
2480
|
+
for (const ref of data.refs) {
|
|
2481
|
+
if (ref.kind !== "footnote") continue;
|
|
2482
|
+
const label = ref.label;
|
|
2483
|
+
if (!index.numbers.has(label)) index.numbers.set(label, index.numbers.size + 1);
|
|
2484
|
+
const total = (index.counts.get(label) ?? 0) + 1;
|
|
2485
|
+
index.counts.set(label, total);
|
|
2486
|
+
const prior = local.get(label);
|
|
2487
|
+
if (prior) prior.count++;
|
|
2488
|
+
else local.set(label, { start: total, count: 1 });
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
return index;
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2436
2494
|
// src/components/documentRegistry.ts
|
|
2437
2495
|
function createRegistry(onEmpty) {
|
|
2496
|
+
let index;
|
|
2497
|
+
let indexedVersion = -1;
|
|
2498
|
+
const getIndex = () => {
|
|
2499
|
+
if (!index || indexedVersion !== reg.version) {
|
|
2500
|
+
index = buildRegistryIndex(reg);
|
|
2501
|
+
indexedVersion = reg.version;
|
|
2502
|
+
}
|
|
2503
|
+
return index;
|
|
2504
|
+
};
|
|
2438
2505
|
const reg = {
|
|
2439
2506
|
chunkOrder: [],
|
|
2440
2507
|
chunkData: /* @__PURE__ */ new Map(),
|
|
@@ -2586,72 +2653,25 @@ function createRegistry(onEmpty) {
|
|
|
2586
2653
|
};
|
|
2587
2654
|
},
|
|
2588
2655
|
canonicalFootnoteFor(label) {
|
|
2589
|
-
|
|
2590
|
-
for (const sym of this.chunkOrder) {
|
|
2591
|
-
const data = this.chunkData.get(sym);
|
|
2592
|
-
if (data?.defs.has(id)) return sym;
|
|
2593
|
-
}
|
|
2594
|
-
return null;
|
|
2656
|
+
return getIndex().footnotes.get(normalizeId(label)) ?? null;
|
|
2595
2657
|
},
|
|
2596
2658
|
canonicalLinkFor(label) {
|
|
2597
|
-
|
|
2598
|
-
for (const sym of this.chunkOrder) {
|
|
2599
|
-
const data = this.chunkData.get(sym);
|
|
2600
|
-
if (data?.linkDefs.has(id)) return sym;
|
|
2601
|
-
}
|
|
2602
|
-
return null;
|
|
2659
|
+
return getIndex().links.get(normalizeId(label)) ?? null;
|
|
2603
2660
|
},
|
|
2604
2661
|
globalNumber(label) {
|
|
2605
|
-
|
|
2606
|
-
let n = 0;
|
|
2607
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2608
|
-
for (const sym of this.chunkOrder) {
|
|
2609
|
-
const data = this.chunkData.get(sym);
|
|
2610
|
-
if (!data) continue;
|
|
2611
|
-
for (const ref of data.refs) {
|
|
2612
|
-
if (ref.kind !== "footnote") continue;
|
|
2613
|
-
if (!seen.has(ref.label)) {
|
|
2614
|
-
seen.add(ref.label);
|
|
2615
|
-
n++;
|
|
2616
|
-
if (ref.label === id) return n;
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
return null;
|
|
2662
|
+
return getIndex().numbers.get(normalizeId(label)) ?? null;
|
|
2621
2663
|
},
|
|
2622
2664
|
resolveLinkDef(label) {
|
|
2623
|
-
const
|
|
2624
|
-
|
|
2625
|
-
return this.chunkData.get(sym)?.linkDefs.get(
|
|
2665
|
+
const id = normalizeId(label);
|
|
2666
|
+
const sym = getIndex().links.get(id);
|
|
2667
|
+
return sym ? this.chunkData.get(sym)?.linkDefs.get(id) ?? null : null;
|
|
2626
2668
|
},
|
|
2627
2669
|
getRefsForLabel(label) {
|
|
2628
|
-
|
|
2629
|
-
let n = 0;
|
|
2630
|
-
for (const sym of this.chunkOrder) {
|
|
2631
|
-
const data = this.chunkData.get(sym);
|
|
2632
|
-
if (!data) continue;
|
|
2633
|
-
for (const ref of data.refs) {
|
|
2634
|
-
if (ref.kind === "footnote" && ref.label === id) n++;
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
return n;
|
|
2670
|
+
return getIndex().counts.get(normalizeId(label)) ?? 0;
|
|
2638
2671
|
},
|
|
2639
2672
|
globalOccurrenceForRef(chunkSym, label, localOccurrence) {
|
|
2640
|
-
const
|
|
2641
|
-
|
|
2642
|
-
for (const sym of this.chunkOrder) {
|
|
2643
|
-
const data = this.chunkData.get(sym);
|
|
2644
|
-
if (!data) continue;
|
|
2645
|
-
let localCount = 0;
|
|
2646
|
-
for (const ref of data.refs) {
|
|
2647
|
-
if (ref.kind !== "footnote") continue;
|
|
2648
|
-
if (ref.label !== id) continue;
|
|
2649
|
-
localCount++;
|
|
2650
|
-
global2++;
|
|
2651
|
-
if (sym === chunkSym && localCount === localOccurrence) return global2;
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
return null;
|
|
2673
|
+
const range = getIndex().occurrences.get(chunkSym)?.get(normalizeId(label));
|
|
2674
|
+
return range && Number.isInteger(localOccurrence) && localOccurrence > 0 && localOccurrence <= range.count ? range.start + localOccurrence - 1 : null;
|
|
2655
2675
|
},
|
|
2656
2676
|
_notify() {
|
|
2657
2677
|
this.version++;
|
|
@@ -2716,7 +2736,7 @@ var ENGINE_PLACEHOLDER_TAGS = /* @__PURE__ */ new Set([
|
|
|
2716
2736
|
"cross-chunk-image"
|
|
2717
2737
|
]);
|
|
2718
2738
|
var ENGINE_PROVENANCE_PROPERTY = "engineProvenance";
|
|
2719
|
-
function walk(parent, provenance) {
|
|
2739
|
+
function walk(parent, provenance, ancestors) {
|
|
2720
2740
|
const children = parent.children;
|
|
2721
2741
|
let i = 0;
|
|
2722
2742
|
while (i < children.length) {
|
|
@@ -2727,21 +2747,32 @@ function walk(parent, provenance) {
|
|
|
2727
2747
|
const genuine = provenance !== "" && typeof stamped === "string" && stamped === provenance;
|
|
2728
2748
|
if (genuine) {
|
|
2729
2749
|
delete props[ENGINE_PROVENANCE_PROPERTY];
|
|
2730
|
-
|
|
2750
|
+
if (ancestors && (node.tagName === "cross-chunk-link" || node.tagName === "cross-chunk-image")) {
|
|
2751
|
+
(node.data ??= {}).referenceAncestors = ancestors.slice();
|
|
2752
|
+
}
|
|
2753
|
+
ancestors?.push(
|
|
2754
|
+
node.tagName === "cross-chunk-link" ? "a" : node.tagName === "cross-chunk-image" ? "img" : node.tagName
|
|
2755
|
+
);
|
|
2756
|
+
walk(node, provenance, ancestors);
|
|
2757
|
+
ancestors?.pop();
|
|
2731
2758
|
i += 1;
|
|
2732
2759
|
} else {
|
|
2733
2760
|
children.splice(i, 1, ...node.children);
|
|
2734
2761
|
}
|
|
2735
2762
|
continue;
|
|
2736
2763
|
}
|
|
2737
|
-
if (node.type === "element")
|
|
2764
|
+
if (node.type === "element") {
|
|
2765
|
+
ancestors?.push(node.tagName);
|
|
2766
|
+
walk(node, provenance, ancestors);
|
|
2767
|
+
ancestors?.pop();
|
|
2768
|
+
}
|
|
2738
2769
|
i += 1;
|
|
2739
2770
|
}
|
|
2740
2771
|
}
|
|
2741
2772
|
function rehypeVerifyEngineTags(options) {
|
|
2742
2773
|
const provenance = options?.provenance ?? "";
|
|
2743
2774
|
return function transformer(tree) {
|
|
2744
|
-
walk(tree, provenance);
|
|
2775
|
+
walk(tree, provenance, options?.referenceAncestors ? [] : void 0);
|
|
2745
2776
|
};
|
|
2746
2777
|
}
|
|
2747
2778
|
|
|
@@ -2762,16 +2793,18 @@ import remarkRemoveComments from "remark-remove-comments";
|
|
|
2762
2793
|
// src/components/rehypeRebaseHashLinks.ts
|
|
2763
2794
|
import { visit as visit5 } from "unist-util-visit";
|
|
2764
2795
|
var DEFAULT_PREFIX = "user-content-";
|
|
2796
|
+
function rebaseHashHref(href, prefix) {
|
|
2797
|
+
const hashPrefix = "#" + prefix;
|
|
2798
|
+
return href.startsWith("#") && !href.startsWith(hashPrefix) ? hashPrefix + href.slice(1) : href;
|
|
2799
|
+
}
|
|
2765
2800
|
var rehypeRebaseHashLinks = (options) => {
|
|
2766
2801
|
const prefix = options?.prefix ?? DEFAULT_PREFIX;
|
|
2767
|
-
const hashPrefix = "#" + prefix;
|
|
2768
2802
|
return (tree) => {
|
|
2769
2803
|
visit5(tree, "element", (node) => {
|
|
2770
2804
|
if (node.tagName !== "a") return;
|
|
2771
2805
|
const href = node.properties?.href;
|
|
2772
2806
|
if (typeof href !== "string" || !href.startsWith("#")) return;
|
|
2773
|
-
|
|
2774
|
-
node.properties.href = hashPrefix + href.slice(1);
|
|
2807
|
+
node.properties.href = rebaseHashHref(href, prefix);
|
|
2775
2808
|
});
|
|
2776
2809
|
};
|
|
2777
2810
|
};
|
|
@@ -2857,7 +2890,15 @@ function buildCoreRehypePlugins(sanitizeSchema2, clobberPrefix, options) {
|
|
|
2857
2890
|
[rehypeRaw, { passThrough: [] }],
|
|
2858
2891
|
// Unwrap forged engine placeholders BEFORE sanitize admits their tag
|
|
2859
2892
|
// names. Only when the caller holds a credential (see the option's doc).
|
|
2860
|
-
...options ? [
|
|
2893
|
+
...options ? [
|
|
2894
|
+
[
|
|
2895
|
+
rehypeVerifyEngineTags,
|
|
2896
|
+
{
|
|
2897
|
+
provenance: options.provenance,
|
|
2898
|
+
...sanitizeSchema2.ancestors?.a || sanitizeSchema2.ancestors?.img ? { referenceAncestors: true } : {}
|
|
2899
|
+
}
|
|
2900
|
+
]
|
|
2901
|
+
] : [],
|
|
2861
2902
|
// Sanitize HTML while allowing <mark> (highlight), KaTeX class names,
|
|
2862
2903
|
// and any extra protocols the caller permitted via the `sanitizeSchema`
|
|
2863
2904
|
// prop. Override `clobberPrefix` with the instance-scoped value — the
|
|
@@ -2931,11 +2972,9 @@ function buildCrossChunkHandlers() {
|
|
|
2931
2972
|
type: "element",
|
|
2932
2973
|
tagName: "cross-chunk-link",
|
|
2933
2974
|
properties: {
|
|
2934
|
-
//
|
|
2935
|
-
//
|
|
2936
|
-
|
|
2937
|
-
// which also preserves source case. Registry lookups normalize
|
|
2938
|
-
// internally, so cross-chunk case-insensitive matching still works.
|
|
2975
|
+
// Display labels decode escapes; registry identifiers must retain
|
|
2976
|
+
// those bytes. Never use the display label as the lookup key.
|
|
2977
|
+
identifier: node.identifier,
|
|
2939
2978
|
label: node.label ?? node.identifier,
|
|
2940
2979
|
referenceType: node.referenceType,
|
|
2941
2980
|
documentId: s.options.documentId,
|
|
@@ -2954,6 +2993,7 @@ function buildCrossChunkHandlers() {
|
|
|
2954
2993
|
type: "element",
|
|
2955
2994
|
tagName: "cross-chunk-image",
|
|
2956
2995
|
properties: {
|
|
2996
|
+
identifier: node.identifier,
|
|
2957
2997
|
label: node.label ?? node.identifier,
|
|
2958
2998
|
referenceType: node.referenceType,
|
|
2959
2999
|
alt: node.alt ?? "",
|
|
@@ -4216,8 +4256,8 @@ var sanitizeSchema = deepFreeze(
|
|
|
4216
4256
|
attributes: {
|
|
4217
4257
|
...defaultSchema.attributes,
|
|
4218
4258
|
code: mergeClassNameAllowlist(defaultSchema.attributes?.code, ["math-inline", "math-display"]),
|
|
4219
|
-
"cross-chunk-link": ["label", "referenceType", "documentId", "localUrl", "localTitle"],
|
|
4220
|
-
"cross-chunk-image": ["label", "referenceType", "documentId", "alt", "localUrl", "localTitle"],
|
|
4259
|
+
"cross-chunk-link": ["identifier", "label", "referenceType", "documentId", "localUrl", "localTitle"],
|
|
4260
|
+
"cross-chunk-image": ["identifier", "label", "referenceType", "documentId", "alt", "localUrl", "localTitle"],
|
|
4221
4261
|
"footnote-sup": ["label", "localOccurrence", "localNumber", "documentId"]
|
|
4222
4262
|
},
|
|
4223
4263
|
strip: [.../* @__PURE__ */ new Set([...defaultSchema.strip || [], ...STRIPPED_TAGS])]
|
|
@@ -4253,6 +4293,49 @@ function sanitizeCrossChunkUrl(rawUrl, key, tagName, urlTransform, schema) {
|
|
|
4253
4293
|
return String(transformed);
|
|
4254
4294
|
}
|
|
4255
4295
|
|
|
4296
|
+
// src/components/resolveCrossChunkReference.ts
|
|
4297
|
+
import rehypeSanitize2 from "rehype-sanitize";
|
|
4298
|
+
import { normalizeUri as normalizeUri3 } from "micromark-util-sanitize-uri";
|
|
4299
|
+
function resolveCrossChunkReference(input, schema, urlTransform, clobberPrefix) {
|
|
4300
|
+
const key = input.tagName === "a" ? "href" : "src";
|
|
4301
|
+
const element = {
|
|
4302
|
+
type: "element",
|
|
4303
|
+
tagName: input.tagName,
|
|
4304
|
+
properties: {
|
|
4305
|
+
[key]: normalizeUri3(input.url),
|
|
4306
|
+
...input.tagName === "img" ? { alt: input.alt ?? "" } : {},
|
|
4307
|
+
...input.title !== void 0 ? { title: input.title } : {}
|
|
4308
|
+
},
|
|
4309
|
+
children: input.tagName === "a" ? [{ type: "text", value: "__reference_children__" }] : []
|
|
4310
|
+
};
|
|
4311
|
+
const requiredAncestors = schema.ancestors?.[input.tagName];
|
|
4312
|
+
const recordedAncestors = input.node?.data?.referenceAncestors;
|
|
4313
|
+
let finalSchema = schema;
|
|
4314
|
+
if (requiredAncestors && Array.isArray(recordedAncestors) && requiredAncestors.some((tag) => recordedAncestors.includes(tag))) {
|
|
4315
|
+
const ancestors = { ...schema.ancestors };
|
|
4316
|
+
delete ancestors[input.tagName];
|
|
4317
|
+
finalSchema = { ...schema, ancestors };
|
|
4318
|
+
}
|
|
4319
|
+
const root2 = rehypeSanitize2({ ...finalSchema, clobberPrefix })({ type: "root", children: [element] });
|
|
4320
|
+
const node = root2.children[0];
|
|
4321
|
+
if (node?.type !== "element") return { element: null, keepChildren: node?.type === "text" };
|
|
4322
|
+
if (node.tagName === "a" && typeof node.properties.href === "string") {
|
|
4323
|
+
node.properties.href = rebaseHashHref(node.properties.href, clobberPrefix);
|
|
4324
|
+
}
|
|
4325
|
+
node.children = input.node?.children ?? [];
|
|
4326
|
+
if (input.node?.position) node.position = input.node.position;
|
|
4327
|
+
buildTransform({
|
|
4328
|
+
allowedElements: void 0,
|
|
4329
|
+
disallowedElements: void 0,
|
|
4330
|
+
allowElement: void 0,
|
|
4331
|
+
skipHtml: void 0,
|
|
4332
|
+
unwrapDisallowed: void 0,
|
|
4333
|
+
urlTransform
|
|
4334
|
+
})(node, 0, root2);
|
|
4335
|
+
node.children = [];
|
|
4336
|
+
return { element: node, keepChildren: false };
|
|
4337
|
+
}
|
|
4338
|
+
|
|
4256
4339
|
// src/plugins/defs.ts
|
|
4257
4340
|
function getEnginePluginInternals(plugin) {
|
|
4258
4341
|
const candidate = plugin;
|
|
@@ -4469,6 +4552,8 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4469
4552
|
let source = "";
|
|
4470
4553
|
let visibleEnd = 0;
|
|
4471
4554
|
let pending = [];
|
|
4555
|
+
let pendingHead = 0;
|
|
4556
|
+
const pendingCount = () => pending.length - pendingHead;
|
|
4472
4557
|
let tentativeEnd = 0;
|
|
4473
4558
|
let finished = false;
|
|
4474
4559
|
let seam;
|
|
@@ -4513,7 +4598,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4513
4598
|
cancelFrame = void 0;
|
|
4514
4599
|
};
|
|
4515
4600
|
const ensureScheduled = () => {
|
|
4516
|
-
if (disposed || cancelFrame ||
|
|
4601
|
+
if (disposed || cancelFrame || pendingCount() === 0) return;
|
|
4517
4602
|
lastTickAt = now();
|
|
4518
4603
|
credit = 0;
|
|
4519
4604
|
cancelFrame = schedule(tick);
|
|
@@ -4527,31 +4612,38 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4527
4612
|
const params = resolveParams();
|
|
4528
4613
|
let rate;
|
|
4529
4614
|
if (finished && drainDeadlineAt !== void 0) {
|
|
4530
|
-
rate = Math.max(params.minCharsPerSecond,
|
|
4615
|
+
rate = Math.max(params.minCharsPerSecond, pendingCount() * 1e3 / Math.max(1, drainDeadlineAt - t));
|
|
4531
4616
|
} else if (gapWindow.length > 0 && lastArrivalAt !== void 0) {
|
|
4532
4617
|
const gaps = gapWindow.map((s) => s.gap).sort((a, b) => a - b);
|
|
4533
4618
|
const intervalQ = gaps[Math.min(gaps.length - 1, Math.floor(gaps.length * INTERVAL_QUANTILE))];
|
|
4534
4619
|
const horizon = Math.max(16, Math.min(params.bufferFactor * intervalQ + HORIZON_PAD_MS, params.maxLagMs));
|
|
4535
4620
|
const deadline = Math.max(lastArrivalAt + horizon, t + DEADLINE_FLOOR_MS);
|
|
4536
|
-
rate = Math.max(params.minCharsPerSecond,
|
|
4621
|
+
rate = Math.max(params.minCharsPerSecond, pendingCount() * 1e3 / Math.max(1, deadline - t));
|
|
4537
4622
|
} else {
|
|
4538
|
-
rate = Math.max(params.minCharsPerSecond,
|
|
4623
|
+
rate = Math.max(params.minCharsPerSecond, pendingCount() * 1e3 / Math.max(1, params.correctionTauMs));
|
|
4539
4624
|
}
|
|
4540
4625
|
credit += rate * dt / 1e3;
|
|
4541
|
-
const reveal = Math.min(Math.floor(credit),
|
|
4626
|
+
const reveal = Math.min(Math.floor(credit), pendingCount());
|
|
4542
4627
|
if (reveal > 0) {
|
|
4543
|
-
visibleEnd = pending[reveal - 1];
|
|
4544
|
-
|
|
4545
|
-
|
|
4628
|
+
visibleEnd = pending[pendingHead + reveal - 1];
|
|
4629
|
+
pendingHead += reveal;
|
|
4630
|
+
if (pendingHead === pending.length) {
|
|
4631
|
+
pending = [];
|
|
4632
|
+
pendingHead = 0;
|
|
4633
|
+
} else if (pendingHead >= 1024 && pendingHead * 2 >= pending.length) {
|
|
4634
|
+
pending = pending.slice(pendingHead);
|
|
4635
|
+
pendingHead = 0;
|
|
4636
|
+
}
|
|
4637
|
+
credit = pendingCount() > 0 ? credit - reveal : 0;
|
|
4546
4638
|
notify();
|
|
4547
4639
|
}
|
|
4548
|
-
if (!disposed && !cancelFrame &&
|
|
4640
|
+
if (!disposed && !cancelFrame && pendingCount() > 0) cancelFrame = schedule(tick);
|
|
4549
4641
|
};
|
|
4550
4642
|
const resegmentTail = () => {
|
|
4551
|
-
if (seam !== void 0 && seam < source.length && pending[pending.length - 1] === seam) {
|
|
4643
|
+
if (pendingCount() > 0 && seam !== void 0 && seam < source.length && pending[pending.length - 1] === seam) {
|
|
4552
4644
|
pending.pop();
|
|
4553
4645
|
}
|
|
4554
|
-
const from =
|
|
4646
|
+
const from = pendingCount() > 0 ? pending[pending.length - 1] : visibleEnd;
|
|
4555
4647
|
let anchor = from;
|
|
4556
4648
|
if (seam !== void 0 && from <= seam) {
|
|
4557
4649
|
anchor = Math.max(0, from - RESUME_LOOKBACK);
|
|
@@ -4585,6 +4677,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4585
4677
|
visibleEnd = next.length;
|
|
4586
4678
|
tentativeEnd = next.length;
|
|
4587
4679
|
pending = [];
|
|
4680
|
+
pendingHead = 0;
|
|
4588
4681
|
seam = next.length;
|
|
4589
4682
|
credit = 0;
|
|
4590
4683
|
cancelScheduled();
|
|
@@ -4616,7 +4709,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4616
4709
|
if (finished) return;
|
|
4617
4710
|
finished = true;
|
|
4618
4711
|
lastArrivalAt = void 0;
|
|
4619
|
-
if (tentativeEnd > (
|
|
4712
|
+
if (tentativeEnd > (pendingCount() > 0 ? pending[pending.length - 1] : visibleEnd)) {
|
|
4620
4713
|
pending.push(tentativeEnd);
|
|
4621
4714
|
}
|
|
4622
4715
|
const params = resolveParams();
|
|
@@ -4642,10 +4735,11 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4642
4735
|
snap,
|
|
4643
4736
|
flush() {
|
|
4644
4737
|
disposed = false;
|
|
4645
|
-
const target = finished ? source.length :
|
|
4738
|
+
const target = finished ? source.length : pendingCount() > 0 ? pending[pending.length - 1] : visibleEnd;
|
|
4646
4739
|
if (target <= visibleEnd) return;
|
|
4647
4740
|
visibleEnd = target;
|
|
4648
4741
|
pending = [];
|
|
4742
|
+
pendingHead = 0;
|
|
4649
4743
|
credit = 0;
|
|
4650
4744
|
cancelScheduled();
|
|
4651
4745
|
notify();
|
|
@@ -5495,6 +5589,7 @@ export {
|
|
|
5495
5589
|
rehypeRebaseHashLinks_default as rehypeRebaseHashLinks,
|
|
5496
5590
|
rehypeVerifyEngineTags,
|
|
5497
5591
|
removeComments,
|
|
5592
|
+
resolveCrossChunkReference,
|
|
5498
5593
|
sanitizeCrossChunkUrl,
|
|
5499
5594
|
sanitizeSchema,
|
|
5500
5595
|
shortenDocumentId,
|