@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.js
CHANGED
|
@@ -4335,24 +4335,32 @@ var SMOOTH_STREAM_PACING_PRESETS = Object.freeze({
|
|
|
4335
4335
|
correctionTauMs: 280,
|
|
4336
4336
|
emaTauMs: 2600,
|
|
4337
4337
|
minCharsPerSecond: 4,
|
|
4338
|
-
drainMs: 320
|
|
4338
|
+
drainMs: 320,
|
|
4339
|
+
maxLagMs: 3500
|
|
4339
4340
|
}),
|
|
4340
4341
|
balanced: Object.freeze({
|
|
4341
4342
|
bufferFactor: 1,
|
|
4342
4343
|
correctionTauMs: 180,
|
|
4343
4344
|
emaTauMs: 1800,
|
|
4344
4345
|
minCharsPerSecond: 6,
|
|
4345
|
-
drainMs: 240
|
|
4346
|
+
drainMs: 240,
|
|
4347
|
+
maxLagMs: 2500
|
|
4346
4348
|
}),
|
|
4347
4349
|
responsive: Object.freeze({
|
|
4348
4350
|
bufferFactor: 0.45,
|
|
4349
4351
|
correctionTauMs: 110,
|
|
4350
4352
|
emaTauMs: 1100,
|
|
4351
4353
|
minCharsPerSecond: 10,
|
|
4352
|
-
drainMs: 150
|
|
4354
|
+
drainMs: 150,
|
|
4355
|
+
maxLagMs: 800
|
|
4353
4356
|
})
|
|
4354
4357
|
});
|
|
4355
|
-
var
|
|
4358
|
+
var GAP_WINDOW = 16;
|
|
4359
|
+
var INTERVAL_QUANTILE = 0.9;
|
|
4360
|
+
var HORIZON_PAD_MS = 50;
|
|
4361
|
+
var DEADLINE_FLOOR_MS = 33;
|
|
4362
|
+
var DRAIN_CATCHUP_FACTOR = 2;
|
|
4363
|
+
var DRAIN_MAX_FACTOR = 3;
|
|
4356
4364
|
var defaultNow = typeof performance !== "undefined" && typeof performance.now === "function" ? () => performance.now() : () => Date.now();
|
|
4357
4365
|
var defaultSchedule = (cb) => {
|
|
4358
4366
|
if (typeof requestAnimationFrame === "function") {
|
|
@@ -4403,18 +4411,18 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4403
4411
|
let lastTickAt = 0;
|
|
4404
4412
|
let cancelFrame;
|
|
4405
4413
|
let disposed = false;
|
|
4406
|
-
let
|
|
4407
|
-
let intervalEma;
|
|
4414
|
+
let gapWindow = [];
|
|
4408
4415
|
let lastArrivalAt;
|
|
4409
4416
|
const listeners = /* @__PURE__ */ new Set();
|
|
4410
4417
|
const resolveParams = () => {
|
|
4411
|
-
const preset = SMOOTH_STREAM_PACING_PRESETS[options.pacing]
|
|
4418
|
+
const preset = Object.hasOwn(SMOOTH_STREAM_PACING_PRESETS, options.pacing) ? SMOOTH_STREAM_PACING_PRESETS[options.pacing] : SMOOTH_STREAM_PACING_PRESETS.balanced;
|
|
4412
4419
|
return {
|
|
4413
4420
|
bufferFactor: finiteOr(options.bufferFactor, preset.bufferFactor),
|
|
4414
4421
|
correctionTauMs: finiteOr(options.correctionTauMs, preset.correctionTauMs),
|
|
4415
4422
|
emaTauMs: finiteOr(options.emaTauMs, preset.emaTauMs),
|
|
4416
4423
|
minCharsPerSecond: finiteOr(options.minCharsPerSecond, preset.minCharsPerSecond),
|
|
4417
|
-
drainMs: finiteOr(options.drainMs, preset.drainMs)
|
|
4424
|
+
drainMs: finiteOr(options.drainMs, preset.drainMs),
|
|
4425
|
+
maxLagMs: finiteOr(options.maxLagMs, preset.maxLagMs ?? 2500)
|
|
4418
4426
|
};
|
|
4419
4427
|
};
|
|
4420
4428
|
const recordArrival = (t, added) => {
|
|
@@ -4425,12 +4433,8 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4425
4433
|
}
|
|
4426
4434
|
const gap = Math.max(1, t - lastArrivalAt);
|
|
4427
4435
|
lastArrivalAt = t;
|
|
4428
|
-
|
|
4429
|
-
if (
|
|
4430
|
-
const alpha = 1 - Math.exp(-gap / tau);
|
|
4431
|
-
const instantRate = added * 1e3 / gap;
|
|
4432
|
-
rateEma = (rateEma ?? 0) + alpha * (instantRate - (rateEma ?? 0));
|
|
4433
|
-
intervalEma = (intervalEma ?? 0) + alpha * (gap - (intervalEma ?? 0));
|
|
4436
|
+
gapWindow.push({ gap, added });
|
|
4437
|
+
if (gapWindow.length > GAP_WINDOW) gapWindow.shift();
|
|
4434
4438
|
};
|
|
4435
4439
|
const notify = () => {
|
|
4436
4440
|
visibleCache = source.slice(0, visibleEnd);
|
|
@@ -4456,15 +4460,12 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4456
4460
|
let rate;
|
|
4457
4461
|
if (finished && drainDeadlineAt !== void 0) {
|
|
4458
4462
|
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, drainDeadlineAt - t));
|
|
4459
|
-
} else if (
|
|
4460
|
-
const
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
);
|
|
4464
|
-
rate = Math.max(
|
|
4465
|
-
params.minCharsPerSecond,
|
|
4466
|
-
rateEma + (pending.length - targetBuffer) * 1e3 / Math.max(1, params.correctionTauMs)
|
|
4467
|
-
);
|
|
4463
|
+
} else if (gapWindow.length > 0 && lastArrivalAt !== void 0) {
|
|
4464
|
+
const gaps = gapWindow.map((s) => s.gap).sort((a, b) => a - b);
|
|
4465
|
+
const intervalQ = gaps[Math.min(gaps.length - 1, Math.floor(gaps.length * INTERVAL_QUANTILE))];
|
|
4466
|
+
const horizon = Math.max(16, Math.min(params.bufferFactor * intervalQ + HORIZON_PAD_MS, params.maxLagMs));
|
|
4467
|
+
const deadline = Math.max(lastArrivalAt + horizon, t + DEADLINE_FLOOR_MS);
|
|
4468
|
+
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, deadline - t));
|
|
4468
4469
|
} else {
|
|
4469
4470
|
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, params.correctionTauMs));
|
|
4470
4471
|
}
|
|
@@ -4510,8 +4511,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4510
4511
|
initialized = true;
|
|
4511
4512
|
finished = false;
|
|
4512
4513
|
drainDeadlineAt = void 0;
|
|
4513
|
-
|
|
4514
|
-
intervalEma = void 0;
|
|
4514
|
+
gapWindow = [];
|
|
4515
4515
|
lastArrivalAt = void 0;
|
|
4516
4516
|
source = next;
|
|
4517
4517
|
visibleEnd = next.length;
|
|
@@ -4548,10 +4548,26 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4548
4548
|
if (finished) return;
|
|
4549
4549
|
finished = true;
|
|
4550
4550
|
lastArrivalAt = void 0;
|
|
4551
|
-
drainDeadlineAt = now() + resolveParams().drainMs;
|
|
4552
4551
|
if (tentativeEnd > (pending.length > 0 ? pending[pending.length - 1] : visibleEnd)) {
|
|
4553
4552
|
pending.push(tentativeEnd);
|
|
4554
4553
|
}
|
|
4554
|
+
const params = resolveParams();
|
|
4555
|
+
let drainWin = params.drainMs;
|
|
4556
|
+
let chars = 0;
|
|
4557
|
+
let ms = 0;
|
|
4558
|
+
for (let i = 0; i < gapWindow.length - 1; i += 1) {
|
|
4559
|
+
chars += gapWindow[i].added;
|
|
4560
|
+
ms += gapWindow[i].gap;
|
|
4561
|
+
}
|
|
4562
|
+
const backlog = source.length - visibleEnd;
|
|
4563
|
+
if (chars > 0 && ms > 0 && backlog > 0) {
|
|
4564
|
+
const throughput = chars * 1e3 / ms;
|
|
4565
|
+
drainWin = Math.min(
|
|
4566
|
+
Math.max(backlog * 1e3 / (DRAIN_CATCHUP_FACTOR * throughput), params.drainMs),
|
|
4567
|
+
DRAIN_MAX_FACTOR * params.drainMs
|
|
4568
|
+
);
|
|
4569
|
+
}
|
|
4570
|
+
drainDeadlineAt = now() + drainWin;
|
|
4555
4571
|
seam = source.length;
|
|
4556
4572
|
ensureScheduled();
|
|
4557
4573
|
},
|
|
@@ -4883,8 +4899,20 @@ function escapeLatexPipesInUnclosed(text) {
|
|
|
4883
4899
|
const tail = text.substring(unclosedStart + delimLen);
|
|
4884
4900
|
return before + delim + replaceUnescapedPipes(tail);
|
|
4885
4901
|
}
|
|
4902
|
+
function opensMathFlow(text, pos) {
|
|
4903
|
+
let i = pos;
|
|
4904
|
+
let spaces = 0;
|
|
4905
|
+
while (i > 0 && text[i - 1] !== "\n") {
|
|
4906
|
+
i -= 1;
|
|
4907
|
+
if (text[i] !== " ") return false;
|
|
4908
|
+
spaces += 1;
|
|
4909
|
+
if (spaces > 3) return false;
|
|
4910
|
+
}
|
|
4911
|
+
return true;
|
|
4912
|
+
}
|
|
4886
4913
|
function truncateUnclosedLatexBlock(text, unclosedStart = findUnclosedDelimiterStart(text, "double-only")) {
|
|
4887
4914
|
if (unclosedStart === -1) return text;
|
|
4915
|
+
if (!opensMathFlow(text, unclosedStart)) return text;
|
|
4888
4916
|
return text.substring(0, unclosedStart).trimEnd();
|
|
4889
4917
|
}
|
|
4890
4918
|
function escapeTextUnderscores(text) {
|
|
@@ -4985,7 +5013,7 @@ function processSlice(slice, probe = true) {
|
|
|
4985
5013
|
unclosedDouble = findUnclosedDelimiterStart(text, "double-only");
|
|
4986
5014
|
if (unclosedDouble !== -1) {
|
|
4987
5015
|
quiescent = false;
|
|
4988
|
-
if (index === 0 && text.slice(0, unclosedDouble).trim() === "") {
|
|
5016
|
+
if (index === 0 && opensMathFlow(text, unclosedDouble) && text.slice(0, unclosedDouble).trim() === "") {
|
|
4989
5017
|
truncatedAtSeamStart = true;
|
|
4990
5018
|
}
|
|
4991
5019
|
}
|