@ai-react-markdown/engine 2.9.1 → 2.10.1
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 +55 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -36
- package/dist/index.d.ts +68 -36
- package/dist/index.dev.cjs +55 -27
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +55 -27
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +55 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4424,24 +4424,32 @@ var SMOOTH_STREAM_PACING_PRESETS = Object.freeze({
|
|
|
4424
4424
|
correctionTauMs: 280,
|
|
4425
4425
|
emaTauMs: 2600,
|
|
4426
4426
|
minCharsPerSecond: 4,
|
|
4427
|
-
drainMs: 320
|
|
4427
|
+
drainMs: 320,
|
|
4428
|
+
maxLagMs: 3500
|
|
4428
4429
|
}),
|
|
4429
4430
|
balanced: Object.freeze({
|
|
4430
4431
|
bufferFactor: 1,
|
|
4431
4432
|
correctionTauMs: 180,
|
|
4432
4433
|
emaTauMs: 1800,
|
|
4433
4434
|
minCharsPerSecond: 6,
|
|
4434
|
-
drainMs: 240
|
|
4435
|
+
drainMs: 240,
|
|
4436
|
+
maxLagMs: 2500
|
|
4435
4437
|
}),
|
|
4436
4438
|
responsive: Object.freeze({
|
|
4437
4439
|
bufferFactor: 0.45,
|
|
4438
4440
|
correctionTauMs: 110,
|
|
4439
4441
|
emaTauMs: 1100,
|
|
4440
4442
|
minCharsPerSecond: 10,
|
|
4441
|
-
drainMs: 150
|
|
4443
|
+
drainMs: 150,
|
|
4444
|
+
maxLagMs: 800
|
|
4442
4445
|
})
|
|
4443
4446
|
});
|
|
4444
|
-
var
|
|
4447
|
+
var GAP_WINDOW = 16;
|
|
4448
|
+
var INTERVAL_QUANTILE = 0.9;
|
|
4449
|
+
var HORIZON_PAD_MS = 50;
|
|
4450
|
+
var DEADLINE_FLOOR_MS = 33;
|
|
4451
|
+
var DRAIN_CATCHUP_FACTOR = 2;
|
|
4452
|
+
var DRAIN_MAX_FACTOR = 3;
|
|
4445
4453
|
var defaultNow = typeof performance !== "undefined" && typeof performance.now === "function" ? () => performance.now() : () => Date.now();
|
|
4446
4454
|
var defaultSchedule = (cb) => {
|
|
4447
4455
|
if (typeof requestAnimationFrame === "function") {
|
|
@@ -4492,18 +4500,18 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4492
4500
|
let lastTickAt = 0;
|
|
4493
4501
|
let cancelFrame;
|
|
4494
4502
|
let disposed = false;
|
|
4495
|
-
let
|
|
4496
|
-
let intervalEma;
|
|
4503
|
+
let gapWindow = [];
|
|
4497
4504
|
let lastArrivalAt;
|
|
4498
4505
|
const listeners = /* @__PURE__ */ new Set();
|
|
4499
4506
|
const resolveParams = () => {
|
|
4500
|
-
const preset = SMOOTH_STREAM_PACING_PRESETS[options.pacing]
|
|
4507
|
+
const preset = Object.hasOwn(SMOOTH_STREAM_PACING_PRESETS, options.pacing) ? SMOOTH_STREAM_PACING_PRESETS[options.pacing] : SMOOTH_STREAM_PACING_PRESETS.balanced;
|
|
4501
4508
|
return {
|
|
4502
4509
|
bufferFactor: finiteOr(options.bufferFactor, preset.bufferFactor),
|
|
4503
4510
|
correctionTauMs: finiteOr(options.correctionTauMs, preset.correctionTauMs),
|
|
4504
4511
|
emaTauMs: finiteOr(options.emaTauMs, preset.emaTauMs),
|
|
4505
4512
|
minCharsPerSecond: finiteOr(options.minCharsPerSecond, preset.minCharsPerSecond),
|
|
4506
|
-
drainMs: finiteOr(options.drainMs, preset.drainMs)
|
|
4513
|
+
drainMs: finiteOr(options.drainMs, preset.drainMs),
|
|
4514
|
+
maxLagMs: finiteOr(options.maxLagMs, preset.maxLagMs ?? 2500)
|
|
4507
4515
|
};
|
|
4508
4516
|
};
|
|
4509
4517
|
const recordArrival = (t, added) => {
|
|
@@ -4514,12 +4522,8 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4514
4522
|
}
|
|
4515
4523
|
const gap = Math.max(1, t - lastArrivalAt);
|
|
4516
4524
|
lastArrivalAt = t;
|
|
4517
|
-
|
|
4518
|
-
if (
|
|
4519
|
-
const alpha = 1 - Math.exp(-gap / tau);
|
|
4520
|
-
const instantRate = added * 1e3 / gap;
|
|
4521
|
-
rateEma = (rateEma ?? 0) + alpha * (instantRate - (rateEma ?? 0));
|
|
4522
|
-
intervalEma = (intervalEma ?? 0) + alpha * (gap - (intervalEma ?? 0));
|
|
4525
|
+
gapWindow.push({ gap, added });
|
|
4526
|
+
if (gapWindow.length > GAP_WINDOW) gapWindow.shift();
|
|
4523
4527
|
};
|
|
4524
4528
|
const notify = () => {
|
|
4525
4529
|
visibleCache = source.slice(0, visibleEnd);
|
|
@@ -4545,15 +4549,12 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4545
4549
|
let rate;
|
|
4546
4550
|
if (finished && drainDeadlineAt !== void 0) {
|
|
4547
4551
|
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, drainDeadlineAt - t));
|
|
4548
|
-
} else if (
|
|
4549
|
-
const
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
);
|
|
4553
|
-
rate = Math.max(
|
|
4554
|
-
params.minCharsPerSecond,
|
|
4555
|
-
rateEma + (pending.length - targetBuffer) * 1e3 / Math.max(1, params.correctionTauMs)
|
|
4556
|
-
);
|
|
4552
|
+
} else if (gapWindow.length > 0 && lastArrivalAt !== void 0) {
|
|
4553
|
+
const gaps = gapWindow.map((s) => s.gap).sort((a, b) => a - b);
|
|
4554
|
+
const intervalQ = gaps[Math.min(gaps.length - 1, Math.floor(gaps.length * INTERVAL_QUANTILE))];
|
|
4555
|
+
const horizon = Math.max(16, Math.min(params.bufferFactor * intervalQ + HORIZON_PAD_MS, params.maxLagMs));
|
|
4556
|
+
const deadline = Math.max(lastArrivalAt + horizon, t + DEADLINE_FLOOR_MS);
|
|
4557
|
+
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, deadline - t));
|
|
4557
4558
|
} else {
|
|
4558
4559
|
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, params.correctionTauMs));
|
|
4559
4560
|
}
|
|
@@ -4599,8 +4600,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4599
4600
|
initialized = true;
|
|
4600
4601
|
finished = false;
|
|
4601
4602
|
drainDeadlineAt = void 0;
|
|
4602
|
-
|
|
4603
|
-
intervalEma = void 0;
|
|
4603
|
+
gapWindow = [];
|
|
4604
4604
|
lastArrivalAt = void 0;
|
|
4605
4605
|
source = next;
|
|
4606
4606
|
visibleEnd = next.length;
|
|
@@ -4637,10 +4637,26 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4637
4637
|
if (finished) return;
|
|
4638
4638
|
finished = true;
|
|
4639
4639
|
lastArrivalAt = void 0;
|
|
4640
|
-
drainDeadlineAt = now() + resolveParams().drainMs;
|
|
4641
4640
|
if (tentativeEnd > (pending.length > 0 ? pending[pending.length - 1] : visibleEnd)) {
|
|
4642
4641
|
pending.push(tentativeEnd);
|
|
4643
4642
|
}
|
|
4643
|
+
const params = resolveParams();
|
|
4644
|
+
let drainWin = params.drainMs;
|
|
4645
|
+
let chars = 0;
|
|
4646
|
+
let ms = 0;
|
|
4647
|
+
for (let i = 0; i < gapWindow.length - 1; i += 1) {
|
|
4648
|
+
chars += gapWindow[i].added;
|
|
4649
|
+
ms += gapWindow[i].gap;
|
|
4650
|
+
}
|
|
4651
|
+
const backlog = source.length - visibleEnd;
|
|
4652
|
+
if (chars > 0 && ms > 0 && backlog > 0) {
|
|
4653
|
+
const throughput = chars * 1e3 / ms;
|
|
4654
|
+
drainWin = Math.min(
|
|
4655
|
+
Math.max(backlog * 1e3 / (DRAIN_CATCHUP_FACTOR * throughput), params.drainMs),
|
|
4656
|
+
DRAIN_MAX_FACTOR * params.drainMs
|
|
4657
|
+
);
|
|
4658
|
+
}
|
|
4659
|
+
drainDeadlineAt = now() + drainWin;
|
|
4644
4660
|
seam = source.length;
|
|
4645
4661
|
ensureScheduled();
|
|
4646
4662
|
},
|
|
@@ -4972,8 +4988,20 @@ function escapeLatexPipesInUnclosed(text) {
|
|
|
4972
4988
|
const tail = text.substring(unclosedStart + delimLen);
|
|
4973
4989
|
return before + delim + replaceUnescapedPipes(tail);
|
|
4974
4990
|
}
|
|
4991
|
+
function opensMathFlow(text, pos) {
|
|
4992
|
+
let i = pos;
|
|
4993
|
+
let spaces = 0;
|
|
4994
|
+
while (i > 0 && text[i - 1] !== "\n") {
|
|
4995
|
+
i -= 1;
|
|
4996
|
+
if (text[i] !== " ") return false;
|
|
4997
|
+
spaces += 1;
|
|
4998
|
+
if (spaces > 3) return false;
|
|
4999
|
+
}
|
|
5000
|
+
return true;
|
|
5001
|
+
}
|
|
4975
5002
|
function truncateUnclosedLatexBlock(text, unclosedStart = findUnclosedDelimiterStart(text, "double-only")) {
|
|
4976
5003
|
if (unclosedStart === -1) return text;
|
|
5004
|
+
if (!opensMathFlow(text, unclosedStart)) return text;
|
|
4977
5005
|
return text.substring(0, unclosedStart).trimEnd();
|
|
4978
5006
|
}
|
|
4979
5007
|
function escapeTextUnderscores(text) {
|
|
@@ -5074,7 +5102,7 @@ function processSlice(slice, probe = true) {
|
|
|
5074
5102
|
unclosedDouble = findUnclosedDelimiterStart(text, "double-only");
|
|
5075
5103
|
if (unclosedDouble !== -1) {
|
|
5076
5104
|
quiescent = false;
|
|
5077
|
-
if (index === 0 && text.slice(0, unclosedDouble).trim() === "") {
|
|
5105
|
+
if (index === 0 && opensMathFlow(text, unclosedDouble) && text.slice(0, unclosedDouble).trim() === "") {
|
|
5078
5106
|
truncatedAtSeamStart = true;
|
|
5079
5107
|
}
|
|
5080
5108
|
}
|