@ai-react-markdown/engine 2.3.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/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/index.cjs +4138 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1863 -0
- package/dist/index.d.ts +1863 -0
- package/dist/index.dev.cjs +4150 -0
- package/dist/index.dev.cjs.map +1 -0
- package/dist/index.dev.js +4059 -0
- package/dist/index.dev.js.map +1 -0
- package/dist/index.js +4047 -0
- package/dist/index.js.map +1 -0
- package/package.json +108 -0
|
@@ -0,0 +1,4150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
DEFAULT_PAYLOAD: () => DEFAULT_PAYLOAD,
|
|
34
|
+
DEF_LINE_START_RE: () => DEF_LINE_START_RE,
|
|
35
|
+
PIPELINE_STAGES: () => PIPELINE_STAGES,
|
|
36
|
+
SENTINEL_FN_CONTENT: () => SENTINEL_FN_CONTENT,
|
|
37
|
+
SENTINEL_LINK_URL: () => SENTINEL_LINK_URL,
|
|
38
|
+
SMOOTH_STREAM_PACING_PRESETS: () => SMOOTH_STREAM_PACING_PRESETS,
|
|
39
|
+
STAGE_MEASURE_PREFIX: () => STAGE_MEASURE_PREFIX,
|
|
40
|
+
advanceIncrementalParse: () => advanceIncrementalParse,
|
|
41
|
+
attributeHastChildren: () => attributeHastChildren,
|
|
42
|
+
buildCoreRehypePlugins: () => buildCoreRehypePlugins,
|
|
43
|
+
buildCoreRemarkPlugins: () => buildCoreRemarkPlugins,
|
|
44
|
+
buildCoreRemarkRehypeOptions: () => buildCoreRemarkRehypeOptions,
|
|
45
|
+
buildCrossChunkHandlers: () => buildCrossChunkHandlers,
|
|
46
|
+
buildPhantomSuffix: () => buildPhantomSuffix,
|
|
47
|
+
buildTransform: () => buildTransform,
|
|
48
|
+
codePointSnapshots: () => codePointSnapshots,
|
|
49
|
+
collectDefLabels: () => collectDefLabels,
|
|
50
|
+
computeFreezeBoundary: () => computeFreezeBoundary,
|
|
51
|
+
createDefLabelScanner: () => createDefLabelScanner,
|
|
52
|
+
createFile: () => createFile,
|
|
53
|
+
createIncrementalLatexPreprocessor: () => createIncrementalLatexPreprocessor,
|
|
54
|
+
createProcessor: () => createProcessor,
|
|
55
|
+
createRegistry: () => createRegistry,
|
|
56
|
+
createRemendPreprocessor: () => createRemendPreprocessor,
|
|
57
|
+
createSmoothStreamController: () => createSmoothStreamController,
|
|
58
|
+
defaultEnginePlugins: () => defaultEnginePlugins,
|
|
59
|
+
defaultUrlTransform: () => defaultUrlTransform,
|
|
60
|
+
definitionList: () => definitionList,
|
|
61
|
+
extendSanitizeSchema: () => extendSanitizeSchema,
|
|
62
|
+
extractContributions: () => extractContributions,
|
|
63
|
+
extractDefBodiesFromHast: () => extractDefBodiesFromHast,
|
|
64
|
+
getEnginePluginInternals: () => getEnginePluginInternals,
|
|
65
|
+
highlight: () => highlight,
|
|
66
|
+
isFootnoteSection: () => isFootnoteSection,
|
|
67
|
+
lastRegionStart: () => lastRegionStart,
|
|
68
|
+
measureStage: () => measureStage,
|
|
69
|
+
mergeClassNameAllowlist: () => mergeClassNameAllowlist,
|
|
70
|
+
normalizeForMatch: () => normalizeForMatch,
|
|
71
|
+
normalizeId: () => normalizeId,
|
|
72
|
+
pangu: () => pangu,
|
|
73
|
+
parseStage: () => parseStage,
|
|
74
|
+
preprocessAIMDContent: () => preprocessAIMDContent,
|
|
75
|
+
preprocessLaTeX: () => preprocessLaTeX,
|
|
76
|
+
rehypeFooterAdorn: () => rehypeFooterAdorn,
|
|
77
|
+
rehypeRebaseHashLinks: () => rehypeRebaseHashLinks_default,
|
|
78
|
+
removeComments: () => removeComments,
|
|
79
|
+
sanitizeCrossChunkUrl: () => sanitizeCrossChunkUrl,
|
|
80
|
+
sanitizeSchema: () => sanitizeSchema,
|
|
81
|
+
shortenDocumentId: () => shortenDocumentId,
|
|
82
|
+
smartypants: () => smartypants,
|
|
83
|
+
sourceIdFromFootnoteLiId: () => sourceIdFromFootnoteLiId,
|
|
84
|
+
splitByProtectedRegions: () => splitByProtectedRegions,
|
|
85
|
+
subscribeStageTimings: () => subscribeStageTimings,
|
|
86
|
+
transformStage: () => transformStage,
|
|
87
|
+
withDefs: () => withDefs
|
|
88
|
+
});
|
|
89
|
+
module.exports = __toCommonJS(src_exports);
|
|
90
|
+
|
|
91
|
+
// src/fixtures/scenarios.ts
|
|
92
|
+
var DEFAULT_BLOCKS = [
|
|
93
|
+
"# Stress payload\n\n",
|
|
94
|
+
"Streaming markdown with mixed token boundaries \u2014 code, math, tables, admonitions \u2014 all incomplete during transit.\n\n",
|
|
95
|
+
"```ts\nconst fib = (n: number): number => (n < 2 ? n : fib(n - 1) + fib(n - 2));\nconst result = Array.from({ length: 12 }, (_, i) => fib(i));\n```\n\n",
|
|
96
|
+
"$$\n\\int_0^\\infty e^{-x^2}\\,dx = \\frac{\\sqrt{\\pi}}{2}\n$$\n\n",
|
|
97
|
+
"Inline math like $E = mc^2$ and $\\frac{a}{b}$ keeps appearing.\n\n",
|
|
98
|
+
"| Lang | Year | Stable |\n| --- | --- | --- |\n| JavaScript | 1995 | yes |\n| TypeScript | 2012 | yes |\n| Rust | 2010 | yes |\n\n",
|
|
99
|
+
"> The hard part is **incomplete tokens** \u2014 code fences, LaTeX delimiters, table rows mid-emission.\n\n",
|
|
100
|
+
"- bullet one with `inline code`\n- bullet two with [link](https://example.com)\n- bullet three closes the test payload.\n"
|
|
101
|
+
];
|
|
102
|
+
var DEFAULT_PAYLOAD = DEFAULT_BLOCKS.join("");
|
|
103
|
+
var DEFS_TAIL = 'References[^n1] appear mid-prose[^n2], along with [reference links][spec] and [another one][gfm].\n\n[^n1]: First footnote body with `code` and a [link](https://example.com/fn).\n[^n2]: Second footnote body, plain text.\n\n[spec]: https://spec.commonmark.org\n[gfm]: https://github.github.com/gfm/ "GFM spec"\n';
|
|
104
|
+
function withDefs(payload) {
|
|
105
|
+
const sep = payload.endsWith("\n\n") ? "" : payload.endsWith("\n") ? "\n" : "\n\n";
|
|
106
|
+
return payload + sep + DEFS_TAIL;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/components/markdown/processor.ts
|
|
110
|
+
var import_devlop = require("devlop");
|
|
111
|
+
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
112
|
+
var import_remark_rehype = __toESM(require("remark-rehype"), 1);
|
|
113
|
+
var import_unified = require("unified");
|
|
114
|
+
var import_vfile = require("vfile");
|
|
115
|
+
var emptyPlugins = [];
|
|
116
|
+
var emptyRemarkRehypeOptions = { allowDangerousHtml: true };
|
|
117
|
+
function createProcessor(options) {
|
|
118
|
+
const rehypePlugins = options.rehypePlugins || emptyPlugins;
|
|
119
|
+
const remarkPlugins = options.remarkPlugins || emptyPlugins;
|
|
120
|
+
const remarkRehypeOptions = options.remarkRehypeOptions ? { ...options.remarkRehypeOptions, ...emptyRemarkRehypeOptions } : emptyRemarkRehypeOptions;
|
|
121
|
+
return (0, import_unified.unified)().use(import_remark_parse.default).use(remarkPlugins).use(import_remark_rehype.default, remarkRehypeOptions).use(rehypePlugins);
|
|
122
|
+
}
|
|
123
|
+
function createFile(options) {
|
|
124
|
+
const children = options.children || "";
|
|
125
|
+
const file = new import_vfile.VFile();
|
|
126
|
+
if (typeof children === "string") {
|
|
127
|
+
file.value = children;
|
|
128
|
+
} else {
|
|
129
|
+
(0, import_devlop.unreachable)("Unexpected value `" + String(children) + "` for `children` prop, expected `string`");
|
|
130
|
+
}
|
|
131
|
+
return file;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/components/markdown/stages.ts
|
|
135
|
+
var import_devlop2 = require("devlop");
|
|
136
|
+
var changelog = "https://github.com/remarkjs/react-markdown/blob/main/changelog.md";
|
|
137
|
+
var deprecations = [
|
|
138
|
+
{ from: "astPlugins", id: "remove-buggy-html-in-markdown-parser" },
|
|
139
|
+
{ from: "allowDangerousHtml", id: "remove-buggy-html-in-markdown-parser" },
|
|
140
|
+
{
|
|
141
|
+
from: "allowNode",
|
|
142
|
+
id: "replace-allownode-allowedtypes-and-disallowedtypes",
|
|
143
|
+
to: "allowElement"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
from: "allowedTypes",
|
|
147
|
+
id: "replace-allownode-allowedtypes-and-disallowedtypes",
|
|
148
|
+
to: "allowedElements"
|
|
149
|
+
},
|
|
150
|
+
{ from: "className", id: "remove-classname" },
|
|
151
|
+
{
|
|
152
|
+
from: "disallowedTypes",
|
|
153
|
+
id: "replace-allownode-allowedtypes-and-disallowedtypes",
|
|
154
|
+
to: "disallowedElements"
|
|
155
|
+
},
|
|
156
|
+
{ from: "escapeHtml", id: "remove-buggy-html-in-markdown-parser" },
|
|
157
|
+
{ from: "includeElementIndex", id: "#remove-includeelementindex" },
|
|
158
|
+
{
|
|
159
|
+
from: "includeNodeIndex",
|
|
160
|
+
id: "change-includenodeindex-to-includeelementindex"
|
|
161
|
+
},
|
|
162
|
+
{ from: "linkTarget", id: "remove-linktarget" },
|
|
163
|
+
{ from: "plugins", id: "change-plugins-to-remarkplugins", to: "remarkPlugins" },
|
|
164
|
+
{ from: "rawSourcePos", id: "#remove-rawsourcepos" },
|
|
165
|
+
{ from: "renderers", id: "change-renderers-to-components", to: "components" },
|
|
166
|
+
{ from: "source", id: "change-source-to-children", to: "children" },
|
|
167
|
+
{ from: "sourcePos", id: "#remove-sourcepos" },
|
|
168
|
+
{ from: "transformImageUri", id: "#add-urltransform", to: "urlTransform" },
|
|
169
|
+
{ from: "transformLinkUri", id: "#add-urltransform", to: "urlTransform" }
|
|
170
|
+
];
|
|
171
|
+
function validateOptions(options) {
|
|
172
|
+
for (const deprecation of deprecations) {
|
|
173
|
+
if (Object.hasOwn(options, deprecation.from)) {
|
|
174
|
+
(0, import_devlop2.unreachable)(
|
|
175
|
+
"Unexpected `" + deprecation.from + "` prop, " + (deprecation.to ? "use `" + deprecation.to + "` instead" : "remove it") + " (see <" + changelog + "#" + deprecation.id + "> for more info)"
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (options.allowedElements && options.disallowedElements) {
|
|
180
|
+
(0, import_devlop2.unreachable)("Unexpected combined `allowedElements` and `disallowedElements`, expected one or the other");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function parseStage(options) {
|
|
184
|
+
validateOptions(options);
|
|
185
|
+
const processor2 = createProcessor(options);
|
|
186
|
+
const file = createFile(options);
|
|
187
|
+
const mdast = processor2.parse(file);
|
|
188
|
+
return { processor: processor2, file, mdast };
|
|
189
|
+
}
|
|
190
|
+
function transformStage(parsed) {
|
|
191
|
+
return parsed.processor.runSync(parsed.mdast, parsed.file);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/components/markdown/transform.ts
|
|
195
|
+
var import_html_url_attributes = require("html-url-attributes");
|
|
196
|
+
function buildTransform(ctx) {
|
|
197
|
+
return function transform(node, index, parent) {
|
|
198
|
+
if (node.type === "raw" && parent && typeof index === "number") {
|
|
199
|
+
if (ctx.skipHtml) {
|
|
200
|
+
parent.children.splice(index, 1);
|
|
201
|
+
} else {
|
|
202
|
+
parent.children[index] = { type: "text", value: node.value };
|
|
203
|
+
}
|
|
204
|
+
return index;
|
|
205
|
+
}
|
|
206
|
+
if (node.type === "element") {
|
|
207
|
+
const element = node;
|
|
208
|
+
let key;
|
|
209
|
+
const properties = element.properties ?? {};
|
|
210
|
+
for (key in import_html_url_attributes.urlAttributes) {
|
|
211
|
+
if (Object.hasOwn(import_html_url_attributes.urlAttributes, key) && Object.hasOwn(properties, key)) {
|
|
212
|
+
const test = import_html_url_attributes.urlAttributes[key];
|
|
213
|
+
if (test === null || test.includes(element.tagName)) {
|
|
214
|
+
const stash = element.data?.originalUrls;
|
|
215
|
+
const hasStash = stash !== void 0 && key in stash;
|
|
216
|
+
const original = hasStash ? stash[key] : properties[key];
|
|
217
|
+
const transformed = ctx.urlTransform(String(original || ""), key, element);
|
|
218
|
+
if (!hasStash && transformed !== original) {
|
|
219
|
+
const data = element.data ??= {};
|
|
220
|
+
(data.originalUrls ??= {})[key] = original;
|
|
221
|
+
}
|
|
222
|
+
properties[key] = transformed;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
element.properties = properties;
|
|
227
|
+
}
|
|
228
|
+
if (node.type === "element") {
|
|
229
|
+
const element = node;
|
|
230
|
+
let remove = ctx.allowedElements ? !ctx.allowedElements.includes(element.tagName) : ctx.disallowedElements ? ctx.disallowedElements.includes(element.tagName) : false;
|
|
231
|
+
if (!remove && ctx.allowElement && typeof index === "number") {
|
|
232
|
+
remove = !ctx.allowElement(element, index, parent);
|
|
233
|
+
}
|
|
234
|
+
if (remove && parent && typeof index === "number") {
|
|
235
|
+
if (ctx.unwrapDisallowed && element.children) {
|
|
236
|
+
parent.children.splice(index, 1, ...element.children);
|
|
237
|
+
} else {
|
|
238
|
+
parent.children.splice(index, 1);
|
|
239
|
+
}
|
|
240
|
+
return index;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return void 0;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/components/markdown/urlTransform.ts
|
|
248
|
+
var safeProtocol = /^(https?|ircs?|mailto|xmpp)$/i;
|
|
249
|
+
var defaultUrlTransform = (value) => {
|
|
250
|
+
const colon = value.indexOf(":");
|
|
251
|
+
const questionMark = value.indexOf("?");
|
|
252
|
+
const numberSign = value.indexOf("#");
|
|
253
|
+
const slash = value.indexOf("/");
|
|
254
|
+
if (
|
|
255
|
+
// No protocol → relative.
|
|
256
|
+
colon === -1 || // First colon is after `/`, `?`, or `#` → not a protocol.
|
|
257
|
+
slash !== -1 && colon > slash || questionMark !== -1 && colon > questionMark || numberSign !== -1 && colon > numberSign || // Allowed protocol.
|
|
258
|
+
safeProtocol.test(value.slice(0, colon))
|
|
259
|
+
) {
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
return "";
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/components/incrementalParse/computeFreezeBoundary.ts
|
|
266
|
+
var import_micromark_util_html_tag_name = require("micromark-util-html-tag-name");
|
|
267
|
+
var import_micromark_util_normalize_identifier = require("micromark-util-normalize-identifier");
|
|
268
|
+
var TYPE6_NAMES = new Set(import_micromark_util_html_tag_name.htmlBlockNames);
|
|
269
|
+
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
270
|
+
"area",
|
|
271
|
+
"base",
|
|
272
|
+
"br",
|
|
273
|
+
"col",
|
|
274
|
+
"embed",
|
|
275
|
+
"hr",
|
|
276
|
+
"img",
|
|
277
|
+
"input",
|
|
278
|
+
"link",
|
|
279
|
+
"meta",
|
|
280
|
+
"param",
|
|
281
|
+
"source",
|
|
282
|
+
"track",
|
|
283
|
+
"wbr"
|
|
284
|
+
]);
|
|
285
|
+
var LIST_MARKER_RE = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
|
|
286
|
+
var FOOTNOTE_DEF_RE = /^ {0,3}\[\^[^\]]*\]:/;
|
|
287
|
+
var DEF_LIST_DD_RE = /^ {0,3}:[ \t]/;
|
|
288
|
+
var DEF_RE = /^ {0,3}\[((?:[^[\]\\]|\\.)+)\]:/;
|
|
289
|
+
var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
|
|
290
|
+
var MATH_RUN_RE = /^ {0,3}(\$\$+)/;
|
|
291
|
+
var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|-->/g;
|
|
292
|
+
var TRUNCATED_TAG_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)([^<>]*)$/;
|
|
293
|
+
var REF_RE = /!?\[((?:[^[\]\\]|\\.)*)\]/g;
|
|
294
|
+
var BACKTICK_RUN_RE = /`+/g;
|
|
295
|
+
function computeIndent(text) {
|
|
296
|
+
let indent = 0;
|
|
297
|
+
for (const ch of text) {
|
|
298
|
+
if (ch === " ") indent += 1;
|
|
299
|
+
else if (ch === " ") indent += 4 - indent % 4;
|
|
300
|
+
else break;
|
|
301
|
+
}
|
|
302
|
+
return indent;
|
|
303
|
+
}
|
|
304
|
+
function normalizeLabel(label) {
|
|
305
|
+
const collapsed = label.trim().replace(/[ \t\r\n]+/g, " ");
|
|
306
|
+
return collapsed ? (0, import_micromark_util_normalize_identifier.normalizeIdentifier)(collapsed) : "";
|
|
307
|
+
}
|
|
308
|
+
function canBecomeDdLine(text, confirmed) {
|
|
309
|
+
let i = 0;
|
|
310
|
+
while (i < text.length && text[i] === " ") i += 1;
|
|
311
|
+
if (i > 3) return false;
|
|
312
|
+
if (i === text.length) return !confirmed;
|
|
313
|
+
if (text[i] !== ":") return false;
|
|
314
|
+
if (i + 1 === text.length) return !confirmed;
|
|
315
|
+
return text[i + 1] === " " || text[i + 1] === " ";
|
|
316
|
+
}
|
|
317
|
+
function maskIntraLineCodeSpans(text, carryOpen) {
|
|
318
|
+
BACKTICK_RUN_RE.lastIndex = 0;
|
|
319
|
+
const runs = [];
|
|
320
|
+
let m;
|
|
321
|
+
while ((m = BACKTICK_RUN_RE.exec(text)) !== null) runs.push({ index: m.index, length: m[0].length });
|
|
322
|
+
if (runs.length === 0) return { masked: carryOpen ? null : text, unpaired: false };
|
|
323
|
+
const spans = [];
|
|
324
|
+
let unpaired = false;
|
|
325
|
+
for (let i = 0; i < runs.length; i++) {
|
|
326
|
+
const opener = runs[i];
|
|
327
|
+
let matched = -1;
|
|
328
|
+
for (let j = i + 1; j < runs.length; j++) {
|
|
329
|
+
if (runs[j].length === opener.length) {
|
|
330
|
+
matched = j;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (matched === -1) {
|
|
335
|
+
unpaired = true;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
spans.push([opener.index, runs[matched].index + runs[matched].length]);
|
|
339
|
+
i = matched;
|
|
340
|
+
}
|
|
341
|
+
if (carryOpen || unpaired) return { masked: null, unpaired };
|
|
342
|
+
if (spans.length === 0) return { masked: text, unpaired: false };
|
|
343
|
+
let out = "";
|
|
344
|
+
let cursor = 0;
|
|
345
|
+
for (const [from, to] of spans) {
|
|
346
|
+
out += text.slice(cursor, from) + " ".repeat(to - from);
|
|
347
|
+
cursor = to;
|
|
348
|
+
}
|
|
349
|
+
out += text.slice(cursor);
|
|
350
|
+
return { masked: out, unpaired: false };
|
|
351
|
+
}
|
|
352
|
+
function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
353
|
+
return {
|
|
354
|
+
defListEnabled,
|
|
355
|
+
mathFlow,
|
|
356
|
+
referenceTaint,
|
|
357
|
+
confirmedOffset: 0,
|
|
358
|
+
candidates: [],
|
|
359
|
+
defs: /* @__PURE__ */ new Map(),
|
|
360
|
+
footnoteDefs: /* @__PURE__ */ new Map(),
|
|
361
|
+
unresolvedRefs: [],
|
|
362
|
+
tagBalance: /* @__PURE__ */ new Map(),
|
|
363
|
+
openTotal: 0,
|
|
364
|
+
commentOpen: false,
|
|
365
|
+
piOpen: false,
|
|
366
|
+
declOpen: false,
|
|
367
|
+
cdataOpen: false,
|
|
368
|
+
inFence: false,
|
|
369
|
+
fenceChar: "",
|
|
370
|
+
fenceLen: 0,
|
|
371
|
+
inMath: false,
|
|
372
|
+
mathFenceLen: 0,
|
|
373
|
+
blankRun: 0,
|
|
374
|
+
lastBlankStart: -1,
|
|
375
|
+
hazardVerdict: false,
|
|
376
|
+
prevLineBlank: true,
|
|
377
|
+
// doc start counts as a block start
|
|
378
|
+
prevLineWasText: false,
|
|
379
|
+
prevLineWasValidDef: false,
|
|
380
|
+
paragraphHasUnpairedRun: false,
|
|
381
|
+
htmlFlowSinceBlank: false,
|
|
382
|
+
htmlSeamPending: false,
|
|
383
|
+
phasePoisonedAt: Infinity
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function isPlausibleLinkDefRest(rest) {
|
|
387
|
+
const t = rest.trim();
|
|
388
|
+
if (t === "") return false;
|
|
389
|
+
let destEnd;
|
|
390
|
+
if (t.startsWith("<")) {
|
|
391
|
+
const close = t.indexOf(">");
|
|
392
|
+
if (close === -1) return false;
|
|
393
|
+
destEnd = close + 1;
|
|
394
|
+
} else {
|
|
395
|
+
const ws = t.search(/[ \t]/);
|
|
396
|
+
destEnd = ws === -1 ? t.length : ws;
|
|
397
|
+
}
|
|
398
|
+
const after = t.slice(destEnd).trim();
|
|
399
|
+
if (after === "") return true;
|
|
400
|
+
const opener = after[0];
|
|
401
|
+
if (opener !== '"' && opener !== "'" && opener !== "(") return false;
|
|
402
|
+
const closer = opener === "(" ? ")" : opener;
|
|
403
|
+
for (let i = 1; i < after.length; i++) {
|
|
404
|
+
if (after[i] === "\\") {
|
|
405
|
+
i += 1;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (after[i] === closer) return after.slice(i + 1).trim() === "";
|
|
409
|
+
}
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
function classifyBlockStart(text, indent, defListEnabled) {
|
|
413
|
+
if (indent >= 4) return true;
|
|
414
|
+
if (LIST_MARKER_RE.test(text) || FOOTNOTE_DEF_RE.test(text)) return true;
|
|
415
|
+
if (defListEnabled && DEF_LIST_DD_RE.test(text)) return true;
|
|
416
|
+
if (indent === 0) return false;
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
function computeFreezeBoundary(text, options, resume) {
|
|
420
|
+
const mathFlow = options.mathFlow ?? true;
|
|
421
|
+
const referenceTaint = options.referenceTaint ?? true;
|
|
422
|
+
const cp = resume && resume.defListEnabled === options.defListEnabled && resume.mathFlow === mathFlow && resume.referenceTaint === referenceTaint && resume.confirmedOffset <= text.length ? resume : freshCheckpoint(options.defListEnabled, mathFlow, referenceTaint);
|
|
423
|
+
let start = cp.confirmedOffset;
|
|
424
|
+
let tailLine = null;
|
|
425
|
+
while (start < text.length) {
|
|
426
|
+
let end = text.indexOf("\n", start);
|
|
427
|
+
if (end === -1) end = text.length;
|
|
428
|
+
const confirmed = end < text.length;
|
|
429
|
+
const lineText = text.slice(start, end);
|
|
430
|
+
const ln = {
|
|
431
|
+
start,
|
|
432
|
+
end,
|
|
433
|
+
text: lineText,
|
|
434
|
+
blank: confirmed && lineText.trim() === "",
|
|
435
|
+
indent: computeIndent(lineText)
|
|
436
|
+
};
|
|
437
|
+
if (!confirmed) {
|
|
438
|
+
tailLine = ln;
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
processConfirmedLine(cp, ln, text);
|
|
442
|
+
cp.confirmedOffset = end + 1;
|
|
443
|
+
start = end + 1;
|
|
444
|
+
}
|
|
445
|
+
if (cp.unresolvedRefs.length > 0) {
|
|
446
|
+
const settled = (defEnd) => cp.lastBlankStart >= defEnd;
|
|
447
|
+
cp.unresolvedRefs = cp.unresolvedRefs.filter((ref) => {
|
|
448
|
+
const table = ref.footnote ? cp.footnoteDefs : cp.defs;
|
|
449
|
+
const defEnd = table.get(ref.label);
|
|
450
|
+
return defEnd === void 0 || !settled(defEnd);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
let earliestUnresolved = Infinity;
|
|
454
|
+
for (const ref of cp.unresolvedRefs) earliestUnresolved = Math.min(earliestUnresolved, ref.offset);
|
|
455
|
+
const defListSettled = (c) => {
|
|
456
|
+
if (!options.defListEnabled || c.blankRun >= 2) return true;
|
|
457
|
+
if (c.defListSettled !== null) return c.defListSettled;
|
|
458
|
+
if (tailLine) return !canBecomeDdLine(tailLine.text, false);
|
|
459
|
+
return false;
|
|
460
|
+
};
|
|
461
|
+
let boundary = 0;
|
|
462
|
+
for (let i = cp.candidates.length - 1; i >= 0; i--) {
|
|
463
|
+
const c = cp.candidates[i];
|
|
464
|
+
if (!c.htmlBalanced || c.hazard || c.seamRisk) continue;
|
|
465
|
+
if (c.offset > cp.phasePoisonedAt) continue;
|
|
466
|
+
if (c.offset > earliestUnresolved) continue;
|
|
467
|
+
if (!defListSettled(c)) continue;
|
|
468
|
+
boundary = c.offset;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
return { boundary, checkpoint: cp };
|
|
472
|
+
}
|
|
473
|
+
function processConfirmedLine(cp, ln, text) {
|
|
474
|
+
const newest = cp.candidates[cp.candidates.length - 1];
|
|
475
|
+
if (newest && newest.defListSettled === null) {
|
|
476
|
+
newest.defListSettled = ln.blank ? true : !canBecomeDdLine(ln.text, true);
|
|
477
|
+
}
|
|
478
|
+
const isBlockStart = cp.prevLineBlank;
|
|
479
|
+
if (cp.htmlSeamPending && !ln.blank && !cp.htmlFlowSinceBlank && !(cp.commentOpen || cp.piOpen || cp.declOpen || cp.cdataOpen)) {
|
|
480
|
+
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
|
|
481
|
+
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").trim() === "";
|
|
482
|
+
if (!defShapedLine && !commentOnly) {
|
|
483
|
+
cp.htmlSeamPending = false;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
const applyTag = (tag, closing) => {
|
|
487
|
+
if (closing) {
|
|
488
|
+
const count = cp.tagBalance.get(tag) ?? 0;
|
|
489
|
+
if (count > 0) {
|
|
490
|
+
cp.tagBalance.set(tag, count - 1);
|
|
491
|
+
cp.openTotal -= 1;
|
|
492
|
+
}
|
|
493
|
+
} else {
|
|
494
|
+
cp.tagBalance.set(tag, (cp.tagBalance.get(tag) ?? 0) + 1);
|
|
495
|
+
cp.openTotal += 1;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
const commentOpenAtLineStart = cp.commentOpen;
|
|
499
|
+
const rawOpenAtLineStart = cp.commentOpen || cp.piOpen || cp.declOpen || cp.cdataOpen;
|
|
500
|
+
if (cp.inFence) {
|
|
501
|
+
const close = FENCE_RE.exec(ln.text);
|
|
502
|
+
if (close && close[1][0] === cp.fenceChar && close[1].length >= cp.fenceLen && ln.text.trim() === close[1]) {
|
|
503
|
+
cp.inFence = false;
|
|
504
|
+
cp.fenceChar = "";
|
|
505
|
+
cp.fenceLen = 0;
|
|
506
|
+
}
|
|
507
|
+
cp.blankRun = 0;
|
|
508
|
+
cp.paragraphHasUnpairedRun = false;
|
|
509
|
+
cp.prevLineBlank = false;
|
|
510
|
+
cp.prevLineWasText = false;
|
|
511
|
+
cp.prevLineWasValidDef = false;
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (!cp.inMath && !rawOpenAtLineStart) {
|
|
515
|
+
const open = FENCE_RE.exec(ln.text);
|
|
516
|
+
const bogusInfo = open !== null && open[1][0] === "`" && ln.text.slice(ln.text.indexOf(open[1]) + open[1].length).includes("`");
|
|
517
|
+
if (open && !bogusInfo && cp.htmlFlowSinceBlank) {
|
|
518
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
519
|
+
} else if (open && !bogusInfo) {
|
|
520
|
+
if (isBlockStart) {
|
|
521
|
+
const verdict = classifyBlockStart(ln.text, ln.indent, cp.defListEnabled);
|
|
522
|
+
if (verdict !== null) cp.hazardVerdict = verdict;
|
|
523
|
+
}
|
|
524
|
+
cp.inFence = true;
|
|
525
|
+
cp.fenceChar = open[1][0];
|
|
526
|
+
cp.fenceLen = open[1].length;
|
|
527
|
+
cp.blankRun = 0;
|
|
528
|
+
cp.paragraphHasUnpairedRun = false;
|
|
529
|
+
cp.prevLineBlank = false;
|
|
530
|
+
cp.prevLineWasText = false;
|
|
531
|
+
cp.prevLineWasValidDef = false;
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (cp.inMath) {
|
|
536
|
+
const close = MATH_RUN_RE.exec(ln.text);
|
|
537
|
+
if (close && close[1].length >= cp.mathFenceLen && ln.text.trim() === close[1]) {
|
|
538
|
+
cp.inMath = false;
|
|
539
|
+
cp.mathFenceLen = 0;
|
|
540
|
+
}
|
|
541
|
+
cp.blankRun = 0;
|
|
542
|
+
cp.paragraphHasUnpairedRun = false;
|
|
543
|
+
cp.prevLineBlank = false;
|
|
544
|
+
cp.prevLineWasText = false;
|
|
545
|
+
cp.prevLineWasValidDef = false;
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const mathRun = cp.mathFlow && !rawOpenAtLineStart ? MATH_RUN_RE.exec(ln.text) : null;
|
|
549
|
+
if (mathRun) {
|
|
550
|
+
const rest = ln.text.slice(ln.text.indexOf(mathRun[1]) + mathRun[1].length);
|
|
551
|
+
if (!rest.includes("$")) {
|
|
552
|
+
if (cp.htmlFlowSinceBlank) {
|
|
553
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
554
|
+
} else {
|
|
555
|
+
if (isBlockStart) {
|
|
556
|
+
const verdict = classifyBlockStart(ln.text, ln.indent, cp.defListEnabled);
|
|
557
|
+
if (verdict !== null) cp.hazardVerdict = verdict;
|
|
558
|
+
}
|
|
559
|
+
cp.inMath = true;
|
|
560
|
+
cp.mathFenceLen = mathRun[1].length;
|
|
561
|
+
cp.blankRun = 0;
|
|
562
|
+
cp.paragraphHasUnpairedRun = false;
|
|
563
|
+
cp.prevLineBlank = false;
|
|
564
|
+
cp.prevLineWasText = false;
|
|
565
|
+
cp.prevLineWasValidDef = false;
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (ln.blank) {
|
|
571
|
+
cp.blankRun += 1;
|
|
572
|
+
cp.lastBlankStart = ln.start;
|
|
573
|
+
cp.candidates.push({
|
|
574
|
+
offset: Math.min(ln.end + 1, text.length),
|
|
575
|
+
blankRun: cp.blankRun,
|
|
576
|
+
htmlBalanced: cp.openTotal === 0 && !cp.commentOpen && !cp.piOpen && !cp.declOpen && !cp.cdataOpen,
|
|
577
|
+
hazard: cp.hazardVerdict,
|
|
578
|
+
seamRisk: cp.htmlSeamPending,
|
|
579
|
+
defListSettled: null
|
|
580
|
+
});
|
|
581
|
+
cp.paragraphHasUnpairedRun = false;
|
|
582
|
+
cp.htmlFlowSinceBlank = false;
|
|
583
|
+
cp.prevLineBlank = true;
|
|
584
|
+
cp.prevLineWasText = false;
|
|
585
|
+
cp.prevLineWasValidDef = false;
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
if (isBlockStart) {
|
|
589
|
+
const verdict = classifyBlockStart(ln.text, ln.indent, cp.defListEnabled);
|
|
590
|
+
if (verdict !== null) cp.hazardVerdict = verdict;
|
|
591
|
+
} else if (LIST_MARKER_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defListEnabled && DEF_LIST_DD_RE.test(ln.text) || ln.indent >= 4) {
|
|
592
|
+
cp.hazardVerdict = true;
|
|
593
|
+
}
|
|
594
|
+
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(ln.text.trimStart()) : null;
|
|
595
|
+
if (tagStart) {
|
|
596
|
+
cp.htmlFlowSinceBlank = true;
|
|
597
|
+
if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
|
|
598
|
+
}
|
|
599
|
+
const inRawText = cp.htmlFlowSinceBlank || rawOpenAtLineStart;
|
|
600
|
+
const { masked, unpaired } = inRawText ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
|
|
601
|
+
if (unpaired) cp.paragraphHasUnpairedRun = true;
|
|
602
|
+
const scanText = masked ?? ln.text;
|
|
603
|
+
const defShaped = inRawText ? null : DEF_RE.exec(scanText);
|
|
604
|
+
const def = defShaped !== null && (defShaped[1].startsWith("^") || isPlausibleLinkDefRest(scanText.slice(defShaped.index + defShaped[0].length))) ? defShaped : null;
|
|
605
|
+
const defLineStart = isBlockStart || !cp.prevLineWasText || cp.prevLineWasValidDef;
|
|
606
|
+
const validDef = def !== null && defLineStart;
|
|
607
|
+
if (validDef) {
|
|
608
|
+
const label = def[1];
|
|
609
|
+
if (label.startsWith("^")) {
|
|
610
|
+
const key = normalizeLabel(label.slice(1));
|
|
611
|
+
if (key && !cp.footnoteDefs.has(key)) cp.footnoteDefs.set(key, ln.end);
|
|
612
|
+
} else {
|
|
613
|
+
const key = normalizeLabel(label);
|
|
614
|
+
if (key && !cp.defs.has(key)) cp.defs.set(key, ln.end);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
if (cp.referenceTaint && scanText.includes("[")) {
|
|
618
|
+
const defBracket = validDef ? def.index + def[0].indexOf("[") : -1;
|
|
619
|
+
REF_RE.lastIndex = 0;
|
|
620
|
+
let m;
|
|
621
|
+
while ((m = REF_RE.exec(scanText)) !== null) {
|
|
622
|
+
const follow = scanText[m.index + m[0].length];
|
|
623
|
+
if (follow === "(") continue;
|
|
624
|
+
if (follow === ":" && m.index === defBracket) continue;
|
|
625
|
+
const inner = m[1];
|
|
626
|
+
let label;
|
|
627
|
+
let footnote = false;
|
|
628
|
+
if (inner.startsWith("^")) {
|
|
629
|
+
footnote = true;
|
|
630
|
+
label = normalizeLabel(inner.slice(1));
|
|
631
|
+
} else if (follow === "[") {
|
|
632
|
+
const explicit = /^\[((?:[^[\]\\]|\\.)*)\]/.exec(scanText.slice(m.index + m[0].length));
|
|
633
|
+
label = normalizeLabel(explicit && explicit[1] ? explicit[1] : inner);
|
|
634
|
+
} else {
|
|
635
|
+
label = normalizeLabel(inner);
|
|
636
|
+
}
|
|
637
|
+
if (!label) continue;
|
|
638
|
+
cp.unresolvedRefs.push({ offset: ln.start + m.index, label, footnote });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const rawOpenAtStart = cp.piOpen || cp.declOpen || cp.cdataOpen;
|
|
642
|
+
const rawSpans = [];
|
|
643
|
+
let pos = 0;
|
|
644
|
+
while (pos < scanText.length) {
|
|
645
|
+
if (cp.piOpen) {
|
|
646
|
+
const c = scanText.indexOf("?>", pos);
|
|
647
|
+
if (c === -1) {
|
|
648
|
+
rawSpans.push([pos, scanText.length]);
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
rawSpans.push([pos, c + 2]);
|
|
652
|
+
cp.piOpen = false;
|
|
653
|
+
pos = c + 2;
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
if (cp.cdataOpen) {
|
|
657
|
+
const c = scanText.indexOf("]]>", pos);
|
|
658
|
+
if (c === -1) {
|
|
659
|
+
rawSpans.push([pos, scanText.length]);
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
rawSpans.push([pos, c + 3]);
|
|
663
|
+
cp.cdataOpen = false;
|
|
664
|
+
pos = c + 3;
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
if (cp.declOpen) {
|
|
668
|
+
const c = scanText.indexOf(">", pos);
|
|
669
|
+
if (c === -1) {
|
|
670
|
+
rawSpans.push([pos, scanText.length]);
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
rawSpans.push([pos, c + 1]);
|
|
674
|
+
cp.declOpen = false;
|
|
675
|
+
pos = c + 1;
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
const pi = scanText.indexOf("<?", pos);
|
|
679
|
+
const cd = scanText.indexOf("<![CDATA[", pos);
|
|
680
|
+
const dm = scanText.slice(pos).search(/<![A-Za-z]/);
|
|
681
|
+
const decl = dm === -1 ? -1 : pos + dm;
|
|
682
|
+
const starts = [pi, cd, decl].filter((x) => x !== -1);
|
|
683
|
+
if (starts.length === 0) break;
|
|
684
|
+
const first = Math.min(...starts);
|
|
685
|
+
if (first === cd) {
|
|
686
|
+
rawSpans.push([cd, cd + 9]);
|
|
687
|
+
cp.cdataOpen = true;
|
|
688
|
+
pos = cd + 9;
|
|
689
|
+
} else if (first === pi) {
|
|
690
|
+
rawSpans.push([pi, pi + 2]);
|
|
691
|
+
cp.piOpen = true;
|
|
692
|
+
pos = pi + 2;
|
|
693
|
+
} else {
|
|
694
|
+
rawSpans.push([decl, decl + 2]);
|
|
695
|
+
cp.declOpen = true;
|
|
696
|
+
pos = decl + 2;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const rawOpenAtEnd = cp.piOpen || cp.declOpen || cp.cdataOpen;
|
|
700
|
+
if (!rawOpenAtStart && !rawOpenAtEnd) {
|
|
701
|
+
TAG_OR_COMMENT_RE.lastIndex = 0;
|
|
702
|
+
let m;
|
|
703
|
+
let lastCommentOpenerIdx = -1;
|
|
704
|
+
while ((m = TAG_OR_COMMENT_RE.exec(scanText)) !== null) {
|
|
705
|
+
if (m[0] === "<!--") {
|
|
706
|
+
cp.commentOpen = true;
|
|
707
|
+
lastCommentOpenerIdx = m.index;
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
if (m[0] === "-->") {
|
|
711
|
+
cp.commentOpen = false;
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
if (cp.commentOpen) continue;
|
|
715
|
+
const closing = m[1] === "/";
|
|
716
|
+
const tag = m[2].toLowerCase();
|
|
717
|
+
const selfClosing = m[3] !== void 0 && /\/\s*$/.test(m[3]);
|
|
718
|
+
if (VOID_TAGS.has(tag) || selfClosing) continue;
|
|
719
|
+
applyTag(tag, closing);
|
|
720
|
+
}
|
|
721
|
+
if (cp.commentOpen && lastCommentOpenerIdx !== -1 && !inRawText) {
|
|
722
|
+
if (scanText.slice(0, lastCommentOpenerIdx).trim() !== "") {
|
|
723
|
+
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + lastCommentOpenerIdx);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (!cp.commentOpen) {
|
|
727
|
+
const lastLt = scanText.lastIndexOf("<");
|
|
728
|
+
if (lastLt !== -1 && !scanText.includes(">", lastLt)) {
|
|
729
|
+
const m2 = TRUNCATED_TAG_RE.exec(scanText.slice(lastLt));
|
|
730
|
+
if (m2) {
|
|
731
|
+
const closing = m2[1] === "/";
|
|
732
|
+
const tag = m2[2].toLowerCase();
|
|
733
|
+
if (!VOID_TAGS.has(tag)) applyTag(tag, closing);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (inRawText && cp.openTotal === 0) {
|
|
739
|
+
let residue = scanText;
|
|
740
|
+
for (const [from, to] of rawSpans) {
|
|
741
|
+
residue = residue.slice(0, from) + " ".repeat(to - from) + residue.slice(to);
|
|
742
|
+
}
|
|
743
|
+
residue = residue.replace(/<!--[\s\S]*?-->/g, " ");
|
|
744
|
+
if (commentOpenAtLineStart) {
|
|
745
|
+
residue = residue.includes("-->") ? residue.replace(/[\s\S]*?-->/, " ") : "";
|
|
746
|
+
}
|
|
747
|
+
residue = residue.replace(TAG_OR_COMMENT_RE, "");
|
|
748
|
+
if (residue.trim() !== "") {
|
|
749
|
+
cp.htmlSeamPending = true;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
cp.blankRun = 0;
|
|
753
|
+
cp.prevLineBlank = false;
|
|
754
|
+
cp.prevLineWasText = true;
|
|
755
|
+
cp.prevLineWasValidDef = validDef && !def[1].startsWith("^");
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/components/hastPredicates.ts
|
|
759
|
+
function isFootnoteSection(node) {
|
|
760
|
+
if (node.tagName !== "section") return false;
|
|
761
|
+
const props = node.properties;
|
|
762
|
+
return props?.dataFootnotes !== void 0;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/components/incrementalParse/attributeHastChildren.ts
|
|
766
|
+
function attributeHastChildren(mdast, hast, stopAt = Infinity) {
|
|
767
|
+
const mdastStarts = [];
|
|
768
|
+
for (const child of mdast.children) {
|
|
769
|
+
const off = child.position?.start?.offset;
|
|
770
|
+
if (off !== void 0) mdastStarts.push(off);
|
|
771
|
+
}
|
|
772
|
+
let cursor = 0;
|
|
773
|
+
let mdastIdx = 0;
|
|
774
|
+
const out = [];
|
|
775
|
+
for (let i = 0; i < hast.children.length; i++) {
|
|
776
|
+
const attr = attributeOne(hast.children[i], hast.children[i + 1]);
|
|
777
|
+
out.push(attr);
|
|
778
|
+
if (attr >= stopAt) break;
|
|
779
|
+
}
|
|
780
|
+
return out;
|
|
781
|
+
function attributeOne(child, next) {
|
|
782
|
+
const start = child.position?.start?.offset;
|
|
783
|
+
const end = child.position?.end?.offset;
|
|
784
|
+
if (start !== void 0 && start !== null) {
|
|
785
|
+
cursor = Math.max(cursor, end ?? start);
|
|
786
|
+
return start;
|
|
787
|
+
}
|
|
788
|
+
if (child.type === "element" && isFootnoteSection(child)) return Infinity;
|
|
789
|
+
if (child.type === "text" && next?.type === "element" && isFootnoteSection(next)) return Infinity;
|
|
790
|
+
while (mdastIdx < mdastStarts.length && mdastStarts[mdastIdx] < cursor) mdastIdx += 1;
|
|
791
|
+
return mdastIdx < mdastStarts.length ? mdastStarts[mdastIdx] : cursor;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// src/components/incrementalParse/spliceParse.ts
|
|
796
|
+
function collectPrefixInjection(mdast, content, boundary, resume) {
|
|
797
|
+
const resumeValid = resume != null && resume.boundary <= boundary;
|
|
798
|
+
if (resumeValid && resume.uninjectable) return { events: resume.events, uninjectable: true };
|
|
799
|
+
const resumeAt = resumeValid ? resume.boundary : 0;
|
|
800
|
+
const events = resumeAt > 0 ? cloneEventsForAppend(resume.events) : [];
|
|
801
|
+
let uninjectable = false;
|
|
802
|
+
let cacheable = true;
|
|
803
|
+
const pushRef = (token) => {
|
|
804
|
+
const last = events[events.length - 1];
|
|
805
|
+
if (last && last.kind === "refs") last.tokens.push(token);
|
|
806
|
+
else events.push({ kind: "refs", tokens: [token] });
|
|
807
|
+
};
|
|
808
|
+
const visit6 = (node, nested) => {
|
|
809
|
+
const type = node.type;
|
|
810
|
+
if (type === "definition") {
|
|
811
|
+
const start = node.position?.start?.offset;
|
|
812
|
+
const end = node.position?.end?.offset;
|
|
813
|
+
if (start !== void 0 && end !== void 0 && start < boundary) {
|
|
814
|
+
const slice = content.slice(start, end);
|
|
815
|
+
if (nested && slice.includes("\n")) uninjectable = true;
|
|
816
|
+
else events.push({ kind: "def", source: slice });
|
|
817
|
+
}
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
if (type === "footnoteDefinition") {
|
|
821
|
+
const start = node.position?.start;
|
|
822
|
+
const end = node.position?.end?.offset;
|
|
823
|
+
if (start?.offset === void 0 || end === void 0 || start.offset >= boundary) return;
|
|
824
|
+
if (nested) {
|
|
825
|
+
uninjectable = true;
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const lineStart = start.offset - (start.column - 1);
|
|
829
|
+
events.push({
|
|
830
|
+
kind: "footnoteDef",
|
|
831
|
+
source: content.slice(lineStart, end),
|
|
832
|
+
origStart: lineStart,
|
|
833
|
+
origLine: start.line
|
|
834
|
+
});
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
if (type === "footnoteReference") {
|
|
838
|
+
const start = node.position?.start?.offset;
|
|
839
|
+
const end = node.position?.end?.offset;
|
|
840
|
+
if (start === void 0 || end === void 0) {
|
|
841
|
+
uninjectable = true;
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
pushRef(content.slice(start, end));
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
const children = node.children;
|
|
848
|
+
if (children) {
|
|
849
|
+
for (const child of children) visit6(child, true);
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
for (const child of mdast.children) {
|
|
853
|
+
const start = child.position?.start?.offset;
|
|
854
|
+
if (start === void 0) {
|
|
855
|
+
if (resumeAt > 0) return collectPrefixInjection(mdast, content, boundary, null);
|
|
856
|
+
cacheable = false;
|
|
857
|
+
visit6(child, false);
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
if (start >= boundary) break;
|
|
861
|
+
if (start < resumeAt) continue;
|
|
862
|
+
visit6(child, false);
|
|
863
|
+
}
|
|
864
|
+
return { events, uninjectable, cacheable };
|
|
865
|
+
}
|
|
866
|
+
function cloneEventsForAppend(events) {
|
|
867
|
+
const out = events.slice();
|
|
868
|
+
const last = out[out.length - 1];
|
|
869
|
+
if (last && last.kind === "refs") out[out.length - 1] = { kind: "refs", tokens: last.tokens.slice() };
|
|
870
|
+
return out;
|
|
871
|
+
}
|
|
872
|
+
var TERMINATOR_LABEL = "__aimd_injection_terminator__";
|
|
873
|
+
var INJECTION_TERMINATOR = `[${TERMINATOR_LABEL}]: __aimd_sentinel_link__`;
|
|
874
|
+
function tailMentionsTerminator(tailSource) {
|
|
875
|
+
return tailSource.includes(`[${TERMINATOR_LABEL}`);
|
|
876
|
+
}
|
|
877
|
+
function buildInjectionPrefix(events) {
|
|
878
|
+
if (events.length === 0) return { text: "", segments: [] };
|
|
879
|
+
let text = "";
|
|
880
|
+
let line = 1;
|
|
881
|
+
const segments = [];
|
|
882
|
+
for (const event of events) {
|
|
883
|
+
if (text.length > 0) {
|
|
884
|
+
text += "\n\n";
|
|
885
|
+
line += 2;
|
|
886
|
+
}
|
|
887
|
+
const injStart = text.length;
|
|
888
|
+
const source = event.kind === "refs" ? event.tokens.join(" ") : event.source;
|
|
889
|
+
if (event.kind === "footnoteDef") {
|
|
890
|
+
segments.push({
|
|
891
|
+
injStart,
|
|
892
|
+
injEnd: injStart + source.length,
|
|
893
|
+
offsetDelta: event.origStart - injStart,
|
|
894
|
+
lineDelta: event.origLine - line
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
text += source;
|
|
898
|
+
line += countNewlines(source);
|
|
899
|
+
}
|
|
900
|
+
return { text: `${text}
|
|
901
|
+
|
|
902
|
+
${INJECTION_TERMINATOR}
|
|
903
|
+
|
|
904
|
+
`, segments };
|
|
905
|
+
}
|
|
906
|
+
function rebaseTree(node, offsetDelta, lineDelta) {
|
|
907
|
+
rebaseTreeDual(node, EMPTY_SEGMENTS, offsetDelta, lineDelta);
|
|
908
|
+
}
|
|
909
|
+
var EMPTY_SEGMENTS = [];
|
|
910
|
+
function rebaseTreeDual(node, segments, offsetDelta, lineDelta) {
|
|
911
|
+
const maxEnd = segments.length > 0 ? segments[segments.length - 1].injEnd : -1;
|
|
912
|
+
rebaseDualWalk(node, segments, maxEnd, offsetDelta, lineDelta);
|
|
913
|
+
}
|
|
914
|
+
function rebaseDualWalk(node, segments, maxEnd, offsetDelta, lineDelta) {
|
|
915
|
+
const position = node.position;
|
|
916
|
+
if (position) {
|
|
917
|
+
for (const point of [position.start, position.end]) {
|
|
918
|
+
const seg = point.offset !== void 0 && point.offset <= maxEnd ? segments.find((s) => point.offset >= s.injStart && point.offset <= s.injEnd) : void 0;
|
|
919
|
+
if (seg) {
|
|
920
|
+
point.offset += seg.offsetDelta;
|
|
921
|
+
point.line += seg.lineDelta;
|
|
922
|
+
} else {
|
|
923
|
+
if (point.offset !== void 0) point.offset += offsetDelta;
|
|
924
|
+
point.line += lineDelta;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
const children = node.children;
|
|
929
|
+
if (children) {
|
|
930
|
+
for (const child of children) rebaseDualWalk(child, segments, maxEnd, offsetDelta, lineDelta);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function spliceTrees(input) {
|
|
934
|
+
const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
|
|
935
|
+
const injectedLen = injectionPrefix.length;
|
|
936
|
+
const injectedLines = countNewlines(injectionPrefix);
|
|
937
|
+
const prefixLines = countNewlines(content, boundary);
|
|
938
|
+
const offsetDelta = boundary - injectedLen;
|
|
939
|
+
const lineDelta = prefixLines - injectedLines;
|
|
940
|
+
const prefixMdast = [];
|
|
941
|
+
for (const child of prevMdast.children) {
|
|
942
|
+
const start = child.position?.start?.offset;
|
|
943
|
+
if (start !== void 0 && start < boundary) prefixMdast.push(child);
|
|
944
|
+
}
|
|
945
|
+
const attrs = attributeHastChildren(prevMdast, prevHast, boundary);
|
|
946
|
+
const cutRegion = [];
|
|
947
|
+
for (let i = 0; i < prevHast.children.length; i++) {
|
|
948
|
+
if (attrs[i] < boundary) {
|
|
949
|
+
const node2 = prevHast.children[i];
|
|
950
|
+
const end = node2.position?.end?.offset;
|
|
951
|
+
if (end !== void 0 && end > boundary) return null;
|
|
952
|
+
if (isTrailingLiteralText(node2)) {
|
|
953
|
+
const prev = i > 0 ? prevHast.children[i - 1] : void 0;
|
|
954
|
+
if (!prev || prev.type !== "element" || prev.position === void 0) return null;
|
|
955
|
+
}
|
|
956
|
+
cutRegion.push(node2);
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
const node = prevHast.children[i];
|
|
960
|
+
if (i > 0 && attrs[i - 1] < boundary && prevHast.children[i - 1].type === "element" && isTrailingLiteralText(node)) {
|
|
961
|
+
cutRegion.push(node);
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
for (let j = i; j < prevHast.children.length; j++) {
|
|
965
|
+
const look = prevHast.children[j];
|
|
966
|
+
if (look.type === "element" || look.position !== void 0) break;
|
|
967
|
+
if (isTrailingLiteralText(look)) return null;
|
|
968
|
+
}
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
const tailMdastChildren = tailMdast.children.filter((child) => {
|
|
972
|
+
const start = child.position?.start?.offset;
|
|
973
|
+
return !(start !== void 0 && start < injectedLen);
|
|
974
|
+
});
|
|
975
|
+
const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
|
|
976
|
+
const aligned = alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible);
|
|
977
|
+
if (aligned === null) return null;
|
|
978
|
+
const hastChildren = aligned.children;
|
|
979
|
+
const interiorFinalLiteral = aligned.interiorFinalLiteral;
|
|
980
|
+
const stripResult = stripInjectedHast(tailMdast, tailHast, injectedLen, tailWrapVisible);
|
|
981
|
+
if (stripResult === null) return null;
|
|
982
|
+
const strippedTailHast = stripResult.rest;
|
|
983
|
+
for (const child of tailMdastChildren) rebaseTree(child, offsetDelta, lineDelta);
|
|
984
|
+
for (const child of strippedTailHast) rebaseTreeDual(child, injectedSegments, offsetDelta, lineDelta);
|
|
985
|
+
const mdastChildren = prefixMdast.concat(tailMdastChildren);
|
|
986
|
+
const seamMergeVerdict = stripResult.remnantMerged ?? tailLeadingTextIsHoist(tailMdastChildren, strippedTailHast);
|
|
987
|
+
if (seamMergeVerdict === null) return null;
|
|
988
|
+
const seamMergeAllowed = seamMergeVerdict;
|
|
989
|
+
let firstTailChild = true;
|
|
990
|
+
for (const child of strippedTailHast) {
|
|
991
|
+
const tailEnd = hastChildren[hastChildren.length - 1];
|
|
992
|
+
if (firstTailChild && child.type === "text" && child.position !== void 0) {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
if (firstTailChild && tailEnd && tailEnd.type === "text" && child.type === "text" && child.position === void 0) {
|
|
996
|
+
if (interiorFinalLiteral && tailEnd.value.trim() !== "") {
|
|
997
|
+
if (seamMergeAllowed) return null;
|
|
998
|
+
firstTailChild = false;
|
|
999
|
+
hastChildren.push(child);
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
const literalSeam = tailEnd.value.trim() !== "" && !tailWrapVisible;
|
|
1003
|
+
if (seamMergeAllowed || literalSeam) {
|
|
1004
|
+
hastChildren[hastChildren.length - 1] = { type: "text", value: tailEnd.value + child.value };
|
|
1005
|
+
firstTailChild = false;
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
firstTailChild = false;
|
|
1010
|
+
hastChildren.push(child);
|
|
1011
|
+
}
|
|
1012
|
+
if (!hastChildren.some((child) => child.position !== void 0)) return null;
|
|
1013
|
+
const docStart = { line: 1, column: 1, offset: 0 };
|
|
1014
|
+
const mdastRootPosition = tailMdast.position ? { start: docStart, end: rebasePoint(tailMdast.position.end, offsetDelta, lineDelta) } : prevMdast.position;
|
|
1015
|
+
const hastRootPosition = mdastRootPosition;
|
|
1016
|
+
const mdast = { type: "root", children: mdastChildren };
|
|
1017
|
+
if (mdastRootPosition) mdast.position = mdastRootPosition;
|
|
1018
|
+
const hast = { type: "root", children: hastChildren };
|
|
1019
|
+
if (hastRootPosition) hast.position = hastRootPosition;
|
|
1020
|
+
if (prevHast.data !== void 0) hast.data = prevHast.data;
|
|
1021
|
+
return { mdast, hast };
|
|
1022
|
+
}
|
|
1023
|
+
function rebasePoint(point, offsetDelta, lineDelta) {
|
|
1024
|
+
return {
|
|
1025
|
+
line: point.line + lineDelta,
|
|
1026
|
+
column: point.column,
|
|
1027
|
+
offset: point.offset !== void 0 ? point.offset + offsetDelta : void 0
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
function isWrapInvisible(node) {
|
|
1031
|
+
return node.type === "definition" || node.type === "footnoteDefinition";
|
|
1032
|
+
}
|
|
1033
|
+
function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
|
|
1034
|
+
const visibles = prefixMdast.filter((c) => !isWrapInvisible(c));
|
|
1035
|
+
const out = [];
|
|
1036
|
+
let sepBuffer = [];
|
|
1037
|
+
let pairIdx = -1;
|
|
1038
|
+
let sawContent = false;
|
|
1039
|
+
let literalCredit = 0;
|
|
1040
|
+
for (const node of cutRegion) {
|
|
1041
|
+
if (isSeparatorText(node)) {
|
|
1042
|
+
sepBuffer.push(node);
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
1045
|
+
const start = node.position?.start?.offset;
|
|
1046
|
+
const paired = pairIdx >= 0 ? visibles[pairIdx] : void 0;
|
|
1047
|
+
if (sawContent && start !== void 0 && paired && paired.position?.start?.offset !== void 0 && paired.position?.end?.offset !== void 0 && start >= paired.position.start.offset && start < paired.position.end.offset) {
|
|
1048
|
+
if (sepBuffer.length !== 0) return null;
|
|
1049
|
+
out.push(node);
|
|
1050
|
+
continue;
|
|
1051
|
+
}
|
|
1052
|
+
if (sawContent && isTrailingLiteralText(node)) {
|
|
1053
|
+
if (sepBuffer.length !== 0) return null;
|
|
1054
|
+
out.push(node);
|
|
1055
|
+
literalCredit += countTrailingNewlines(node.value);
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
let nextIdx;
|
|
1059
|
+
if (!sawContent && start !== void 0) {
|
|
1060
|
+
nextIdx = -1;
|
|
1061
|
+
for (let j = 0; j <= sepBuffer.length && j < visibles.length; j++) {
|
|
1062
|
+
const vStart = visibles[j].position?.start?.offset;
|
|
1063
|
+
const vEnd = visibles[j].position?.end?.offset;
|
|
1064
|
+
if (vStart !== void 0 && vEnd !== void 0 && start >= vStart && start < vEnd) {
|
|
1065
|
+
nextIdx = j;
|
|
1066
|
+
break;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
if (nextIdx === -1) return null;
|
|
1070
|
+
const excess = sepBuffer.length - nextIdx;
|
|
1071
|
+
if (excess > (nextIdx === 0 ? 1 : 0)) return null;
|
|
1072
|
+
} else {
|
|
1073
|
+
const stripped = sawContent ? sepBuffer.length + literalCredit - 1 : sepBuffer.length;
|
|
1074
|
+
if (stripped < 0) return null;
|
|
1075
|
+
nextIdx = pairIdx + 1 + stripped;
|
|
1076
|
+
const candidate = visibles[nextIdx];
|
|
1077
|
+
if (!candidate) return null;
|
|
1078
|
+
if (start !== void 0) {
|
|
1079
|
+
const cStart = candidate.position?.start?.offset;
|
|
1080
|
+
const cEnd = candidate.position?.end?.offset;
|
|
1081
|
+
if (cStart === void 0 || cEnd === void 0 || start < cStart || start >= cEnd) return null;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
out.push(...sepBuffer, node);
|
|
1085
|
+
sepBuffer = [];
|
|
1086
|
+
literalCredit = 0;
|
|
1087
|
+
pairIdx = nextIdx;
|
|
1088
|
+
sawContent = true;
|
|
1089
|
+
}
|
|
1090
|
+
const trailingStripped = visibles.length - (pairIdx + 1);
|
|
1091
|
+
const trailingGaps = sawContent ? trailingStripped : Math.max(0, visibles.length - 1);
|
|
1092
|
+
const seam = visibles.length > 0 && tailWrapVisible ? 1 : 0;
|
|
1093
|
+
const last = out[out.length - 1];
|
|
1094
|
+
const lastIsLiteral = last !== void 0 && last.type === "text" && last.value.trim() !== "";
|
|
1095
|
+
const litOwnerEnd = pairIdx >= 0 ? visibles[pairIdx].position?.end?.offset : void 0;
|
|
1096
|
+
const litEnd = lastIsLiteral ? last.position?.end?.offset : void 0;
|
|
1097
|
+
if (lastIsLiteral && last.position !== void 0 && (litEnd === void 0 || litOwnerEnd === void 0)) {
|
|
1098
|
+
return null;
|
|
1099
|
+
}
|
|
1100
|
+
if (litEnd !== void 0 && litOwnerEnd !== void 0 && litEnd > litOwnerEnd) {
|
|
1101
|
+
return null;
|
|
1102
|
+
}
|
|
1103
|
+
const interiorFinalLiteral = lastIsLiteral && litEnd !== void 0 && litOwnerEnd !== void 0 && litEnd < litOwnerEnd;
|
|
1104
|
+
if (lastIsLiteral && !interiorFinalLiteral) {
|
|
1105
|
+
if (trailingGaps > 0 || sepBuffer.length > 0) return null;
|
|
1106
|
+
const body = last.value.replace(/\n+$/, "");
|
|
1107
|
+
if (last.position !== void 0 && body !== last.value) {
|
|
1108
|
+
return null;
|
|
1109
|
+
}
|
|
1110
|
+
if (seam > 0) {
|
|
1111
|
+
out[out.length - 1] = { type: "text", value: `${body}
|
|
1112
|
+
` };
|
|
1113
|
+
} else if (last.position !== void 0) {
|
|
1114
|
+
} else {
|
|
1115
|
+
const prevEl = out.length >= 2 ? out[out.length - 2] : void 0;
|
|
1116
|
+
const owner = pairIdx >= 0 ? visibles[pairIdx] : void 0;
|
|
1117
|
+
const start = prevEl?.type === "element" ? prevEl.position?.end : void 0;
|
|
1118
|
+
const end = owner?.position?.end;
|
|
1119
|
+
if (!start || !end) return null;
|
|
1120
|
+
out[out.length - 1] = { type: "text", value: body, position: { start, end } };
|
|
1121
|
+
}
|
|
1122
|
+
return { children: out, interiorFinalLiteral: false };
|
|
1123
|
+
}
|
|
1124
|
+
if (sepBuffer.some((s) => s.type !== "text" || s.value !== "\n")) return null;
|
|
1125
|
+
if (literalCredit > 0) return null;
|
|
1126
|
+
const lastPaired = pairIdx >= 0 ? visibles[pairIdx] : void 0;
|
|
1127
|
+
if (lastPaired && lastPaired.type === "html") {
|
|
1128
|
+
const v = lastPaired.value;
|
|
1129
|
+
const lastLt = v.lastIndexOf("<");
|
|
1130
|
+
if (lastLt !== -1 && /^<[!?]/.test(v.slice(lastLt))) return null;
|
|
1131
|
+
}
|
|
1132
|
+
if (sepBuffer.length !== trailingGaps && sepBuffer.length !== trailingGaps + 1) return null;
|
|
1133
|
+
for (let i = 0; i < trailingGaps + seam; i++) {
|
|
1134
|
+
out.push({ type: "text", value: "\n" });
|
|
1135
|
+
}
|
|
1136
|
+
return { children: out, interiorFinalLiteral };
|
|
1137
|
+
}
|
|
1138
|
+
function stripInjectedHast(tailMdast, tailHast, injectedLen, tailWrapVisible) {
|
|
1139
|
+
if (injectedLen === 0) return { rest: tailHast.children.slice(), remnantMerged: null };
|
|
1140
|
+
const injectedVisibleCount = tailMdast.children.filter((c) => {
|
|
1141
|
+
const start = c.position?.start?.offset;
|
|
1142
|
+
return start !== void 0 && start < injectedLen && !isWrapInvisible(c);
|
|
1143
|
+
}).length;
|
|
1144
|
+
if (injectedVisibleCount === 0) return { rest: tailHast.children.slice(), remnantMerged: null };
|
|
1145
|
+
const children = tailHast.children;
|
|
1146
|
+
let idx = 0;
|
|
1147
|
+
let consumed = 0;
|
|
1148
|
+
while (idx < children.length && consumed < injectedVisibleCount) {
|
|
1149
|
+
const node = children[idx];
|
|
1150
|
+
if (isSeparatorText(node)) {
|
|
1151
|
+
idx += 1;
|
|
1152
|
+
continue;
|
|
1153
|
+
}
|
|
1154
|
+
const start = node.position?.start?.offset;
|
|
1155
|
+
if (start === void 0 || start >= injectedLen) return null;
|
|
1156
|
+
consumed += 1;
|
|
1157
|
+
idx += 1;
|
|
1158
|
+
}
|
|
1159
|
+
if (consumed < injectedVisibleCount) return null;
|
|
1160
|
+
let remnant = "";
|
|
1161
|
+
let remnantMerged = null;
|
|
1162
|
+
if (tailWrapVisible) {
|
|
1163
|
+
const gap = children[idx];
|
|
1164
|
+
if (!gap || !isSeparatorText(gap)) return null;
|
|
1165
|
+
remnant = gap.value.slice(1);
|
|
1166
|
+
remnantMerged = remnant !== "";
|
|
1167
|
+
idx += 1;
|
|
1168
|
+
}
|
|
1169
|
+
const rest = children.slice(idx);
|
|
1170
|
+
if (remnant !== "") rest.unshift({ type: "text", value: remnant });
|
|
1171
|
+
return { rest, remnantMerged };
|
|
1172
|
+
}
|
|
1173
|
+
function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
|
|
1174
|
+
const firstText = tailHastChildren[0];
|
|
1175
|
+
if (!firstText || !isSeparatorText(firstText)) return false;
|
|
1176
|
+
const firstVisible = tailMdastChildren.find((c) => !isWrapInvisible(c));
|
|
1177
|
+
if (!firstVisible) return false;
|
|
1178
|
+
const firstContent = tailHastChildren.find((c) => !isSeparatorText(c));
|
|
1179
|
+
if (firstContent) {
|
|
1180
|
+
const start = firstContent.position?.start?.offset;
|
|
1181
|
+
const vStart = firstVisible.position?.start?.offset;
|
|
1182
|
+
const vEnd = firstVisible.position?.end?.offset;
|
|
1183
|
+
if (start !== void 0 && vStart !== void 0 && vEnd !== void 0) {
|
|
1184
|
+
if (start >= vStart && start < vEnd) return true;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
if (firstVisible.type === "math") return false;
|
|
1188
|
+
if (firstVisible.type === "html" && isCompleteRawConstruct(firstVisible.value)) return false;
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1191
|
+
function isCompleteRawConstruct(value) {
|
|
1192
|
+
const v = value.trim();
|
|
1193
|
+
return v.startsWith("<!--") && v.endsWith("-->") || v.startsWith("<?") && v.endsWith("?>") || v.startsWith("<![CDATA[") && v.endsWith("]]>") || /^<![A-Za-z]/.test(v) && v.endsWith(">");
|
|
1194
|
+
}
|
|
1195
|
+
function isSeparatorText(node) {
|
|
1196
|
+
return node.type === "text" && node.position === void 0 && node.value.trim() === "";
|
|
1197
|
+
}
|
|
1198
|
+
function isTrailingLiteralText(node) {
|
|
1199
|
+
return node.type === "text" && node.position === void 0 && node.value.trim() !== "";
|
|
1200
|
+
}
|
|
1201
|
+
function countTrailingNewlines(value) {
|
|
1202
|
+
let n = 0;
|
|
1203
|
+
for (let i = value.length - 1; i >= 0 && value[i] === "\n"; i--) n += 1;
|
|
1204
|
+
return n;
|
|
1205
|
+
}
|
|
1206
|
+
function countNewlines(text, end = text.length) {
|
|
1207
|
+
let count = 0;
|
|
1208
|
+
for (let i = text.indexOf("\n"); i !== -1 && i < end; i = text.indexOf("\n", i + 1)) count += 1;
|
|
1209
|
+
return count;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// src/components/incrementalParse/advanceIncrementalParse.ts
|
|
1213
|
+
var identityMeasure = (_stage, fn) => fn();
|
|
1214
|
+
function depsKeyEqual(a, b) {
|
|
1215
|
+
return a.length === b.length && a.every((value, i) => value === b[i]);
|
|
1216
|
+
}
|
|
1217
|
+
function runPipeline(source, options) {
|
|
1218
|
+
const measure = options.measure ?? identityMeasure;
|
|
1219
|
+
const parsed = measure(
|
|
1220
|
+
"parse",
|
|
1221
|
+
() => parseStage({
|
|
1222
|
+
children: source,
|
|
1223
|
+
remarkPlugins: options.remarkPlugins,
|
|
1224
|
+
rehypePlugins: options.rehypePlugins,
|
|
1225
|
+
remarkRehypeOptions: options.remarkRehypeOptions
|
|
1226
|
+
})
|
|
1227
|
+
);
|
|
1228
|
+
const hast = measure("transform", () => transformStage(parsed));
|
|
1229
|
+
return { mdast: parsed.mdast, hast };
|
|
1230
|
+
}
|
|
1231
|
+
function advanceIncrementalParse(prev, content, options) {
|
|
1232
|
+
const measure = options.measure ?? identityMeasure;
|
|
1233
|
+
const phantomSuffix = options.phantomSuffix ?? "";
|
|
1234
|
+
const sameDeps = prev !== null && depsKeyEqual(prev.depsKey, options.depsKey);
|
|
1235
|
+
if (sameDeps && content === prev.content && phantomSuffix === prev.phantomSuffix) {
|
|
1236
|
+
return {
|
|
1237
|
+
mdast: prev.mdast,
|
|
1238
|
+
hast: prev.hast,
|
|
1239
|
+
usedIncremental: true,
|
|
1240
|
+
boundary: prev.stableBoundary,
|
|
1241
|
+
nextState: prev
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
const appendOnly = sameDeps && content.startsWith(prev.content);
|
|
1245
|
+
const scan = measure(
|
|
1246
|
+
"scan",
|
|
1247
|
+
() => computeFreezeBoundary(content, { defListEnabled: options.defListEnabled }, appendOnly ? prev.scanCheckpoint : null)
|
|
1248
|
+
);
|
|
1249
|
+
const freshBoundary = scan.boundary;
|
|
1250
|
+
let injectionPlan = appendOnly ? prev.injectionPlan : null;
|
|
1251
|
+
const finish = (mdast, hast, usedIncremental, boundary2) => ({
|
|
1252
|
+
mdast,
|
|
1253
|
+
hast,
|
|
1254
|
+
usedIncremental,
|
|
1255
|
+
boundary: boundary2,
|
|
1256
|
+
nextState: {
|
|
1257
|
+
content,
|
|
1258
|
+
phantomSuffix,
|
|
1259
|
+
mdast,
|
|
1260
|
+
hast,
|
|
1261
|
+
stableBoundary: freshBoundary,
|
|
1262
|
+
scanCheckpoint: scan.checkpoint,
|
|
1263
|
+
injectionPlan,
|
|
1264
|
+
depsKey: options.depsKey
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
const fullPath = () => {
|
|
1268
|
+
const { mdast, hast } = runPipeline(content + phantomSuffix, options);
|
|
1269
|
+
return finish(mdast, hast, false, 0);
|
|
1270
|
+
};
|
|
1271
|
+
if (!appendOnly) return fullPath();
|
|
1272
|
+
const boundary = Math.min(freshBoundary, prev.stableBoundary);
|
|
1273
|
+
if (boundary <= 0) return fullPath();
|
|
1274
|
+
for (const child of prev.mdast.children) {
|
|
1275
|
+
const start = child.position?.start?.offset;
|
|
1276
|
+
const end = child.position?.end?.offset;
|
|
1277
|
+
if (start !== void 0 && end !== void 0 && start < boundary && end > boundary) {
|
|
1278
|
+
return fullPath();
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
const tailAndSuffix = content.slice(boundary) + phantomSuffix;
|
|
1282
|
+
if (tailMentionsTerminator(tailAndSuffix)) return fullPath();
|
|
1283
|
+
const plan = collectPrefixInjection(prev.mdast, prev.content, boundary, injectionPlan);
|
|
1284
|
+
if (plan.cacheable !== false) {
|
|
1285
|
+
injectionPlan = { boundary, events: plan.events, uninjectable: plan.uninjectable };
|
|
1286
|
+
}
|
|
1287
|
+
if (plan.uninjectable) return fullPath();
|
|
1288
|
+
const injection = buildInjectionPrefix(plan.events);
|
|
1289
|
+
const tailSource = injection.text + tailAndSuffix;
|
|
1290
|
+
const tail = runPipeline(tailSource, options);
|
|
1291
|
+
const spliced = spliceTrees({
|
|
1292
|
+
prevMdast: prev.mdast,
|
|
1293
|
+
prevHast: prev.hast,
|
|
1294
|
+
tailMdast: tail.mdast,
|
|
1295
|
+
tailHast: tail.hast,
|
|
1296
|
+
content,
|
|
1297
|
+
boundary,
|
|
1298
|
+
injectionPrefix: injection.text,
|
|
1299
|
+
injectedSegments: injection.segments
|
|
1300
|
+
});
|
|
1301
|
+
if (spliced === null) return fullPath();
|
|
1302
|
+
return finish(spliced.mdast, spliced.hast, true, boundary);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// src/components/incrementalParse/codePointSnapshots.ts
|
|
1306
|
+
function codePointSnapshots(payload, chunkSize) {
|
|
1307
|
+
const codePoints = Array.from(payload);
|
|
1308
|
+
const snapshots = [];
|
|
1309
|
+
for (let i = chunkSize; i < codePoints.length; i += chunkSize) {
|
|
1310
|
+
snapshots.push(codePoints.slice(0, i).join(""));
|
|
1311
|
+
}
|
|
1312
|
+
snapshots.push(payload);
|
|
1313
|
+
return snapshots;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// src/components/collectDefLabels.ts
|
|
1317
|
+
var import_unified2 = require("unified");
|
|
1318
|
+
var import_remark_parse2 = __toESM(require("remark-parse"), 1);
|
|
1319
|
+
var import_remark_gfm = __toESM(require("remark-gfm"), 1);
|
|
1320
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
1321
|
+
|
|
1322
|
+
// src/components/normalizeId.ts
|
|
1323
|
+
function normalizeId(s) {
|
|
1324
|
+
return s.replace(/\s+/g, " ").toUpperCase();
|
|
1325
|
+
}
|
|
1326
|
+
function normalizeForMatch(s) {
|
|
1327
|
+
return s.replace(/\\(.)/g, "$1").replace(/\s+/g, " ").toUpperCase();
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
// src/components/collectDefLabels.ts
|
|
1331
|
+
var SCANNER_BOUNDARY_PROFILE = { defListEnabled: false, mathFlow: false, referenceTaint: false };
|
|
1332
|
+
function buildProcessor() {
|
|
1333
|
+
return (0, import_unified2.unified)().use(import_remark_parse2.default).use(import_remark_gfm.default);
|
|
1334
|
+
}
|
|
1335
|
+
var _processor = null;
|
|
1336
|
+
function processor() {
|
|
1337
|
+
if (!_processor) _processor = buildProcessor();
|
|
1338
|
+
return _processor;
|
|
1339
|
+
}
|
|
1340
|
+
function collectDefLabels(source) {
|
|
1341
|
+
if (!source) {
|
|
1342
|
+
return { footnoteLabels: /* @__PURE__ */ new Set(), linkLabels: /* @__PURE__ */ new Set() };
|
|
1343
|
+
}
|
|
1344
|
+
const mdast = processor().parse(source);
|
|
1345
|
+
const footnoteLabels = /* @__PURE__ */ new Set();
|
|
1346
|
+
const linkLabels = /* @__PURE__ */ new Set();
|
|
1347
|
+
(0, import_unist_util_visit.visit)(mdast, (node) => {
|
|
1348
|
+
if (node.type === "footnoteDefinition" && "identifier" in node) {
|
|
1349
|
+
footnoteLabels.add(normalizeId(node.identifier));
|
|
1350
|
+
} else if (node.type === "definition" && "identifier" in node) {
|
|
1351
|
+
linkLabels.add(normalizeId(node.identifier));
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
return { footnoteLabels, linkLabels };
|
|
1355
|
+
}
|
|
1356
|
+
var setsEqual = (a, b) => {
|
|
1357
|
+
if (a.size !== b.size) return false;
|
|
1358
|
+
for (const v of a) if (!b.has(v)) return false;
|
|
1359
|
+
return true;
|
|
1360
|
+
};
|
|
1361
|
+
var BLANK_LINE_RE = /\r?\n[ \t]*\r?\n/g;
|
|
1362
|
+
function lastRegionStart(source) {
|
|
1363
|
+
BLANK_LINE_RE.lastIndex = 0;
|
|
1364
|
+
let start = 0;
|
|
1365
|
+
for (let m = BLANK_LINE_RE.exec(source); m !== null; m = BLANK_LINE_RE.exec(source)) {
|
|
1366
|
+
start = m.index + m[0].length;
|
|
1367
|
+
}
|
|
1368
|
+
return start;
|
|
1369
|
+
}
|
|
1370
|
+
var DEF_LINE_START_RE = /^[ \t>*+\d.)-]*\[(?:[^\]\\]|\\[\s\S])*\]:/m;
|
|
1371
|
+
function createDefLabelScanner(parse = collectDefLabels) {
|
|
1372
|
+
let prevSource = null;
|
|
1373
|
+
let prevLabels = null;
|
|
1374
|
+
let frozenEnd = 0;
|
|
1375
|
+
let frozenFootnotes = /* @__PURE__ */ new Set();
|
|
1376
|
+
let frozenLinks = /* @__PURE__ */ new Set();
|
|
1377
|
+
let checkpoint = null;
|
|
1378
|
+
const resetFrozen = () => {
|
|
1379
|
+
frozenEnd = 0;
|
|
1380
|
+
frozenFootnotes = /* @__PURE__ */ new Set();
|
|
1381
|
+
frozenLinks = /* @__PURE__ */ new Set();
|
|
1382
|
+
checkpoint = null;
|
|
1383
|
+
};
|
|
1384
|
+
return {
|
|
1385
|
+
scan(source) {
|
|
1386
|
+
let isAppend = false;
|
|
1387
|
+
if (prevSource !== null && prevLabels !== null) {
|
|
1388
|
+
if (source === prevSource) return prevLabels;
|
|
1389
|
+
if (source.startsWith(prevSource)) {
|
|
1390
|
+
isAppend = true;
|
|
1391
|
+
const regionStart = lastRegionStart(prevSource);
|
|
1392
|
+
const region = prevSource.slice(regionStart) + source.slice(prevSource.length);
|
|
1393
|
+
if (!DEF_LINE_START_RE.test(region)) {
|
|
1394
|
+
prevSource = source;
|
|
1395
|
+
return prevLabels;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
if (!isAppend && prevSource !== null) resetFrozen();
|
|
1400
|
+
const scanResult = computeFreezeBoundary(source, SCANNER_BOUNDARY_PROFILE, isAppend ? checkpoint : null);
|
|
1401
|
+
checkpoint = scanResult.checkpoint;
|
|
1402
|
+
const boundary = Math.max(scanResult.boundary, frozenEnd);
|
|
1403
|
+
if (boundary > frozenEnd) {
|
|
1404
|
+
const slice = source.slice(frozenEnd, boundary);
|
|
1405
|
+
if (DEF_LINE_START_RE.test(slice)) {
|
|
1406
|
+
const sliceLabels = parse(slice);
|
|
1407
|
+
for (const label of sliceLabels.footnoteLabels) frozenFootnotes.add(label);
|
|
1408
|
+
for (const label of sliceLabels.linkLabels) frozenLinks.add(label);
|
|
1409
|
+
}
|
|
1410
|
+
frozenEnd = boundary;
|
|
1411
|
+
}
|
|
1412
|
+
const tailSource = source.slice(frozenEnd);
|
|
1413
|
+
const tail = DEF_LINE_START_RE.test(tailSource) ? parse(tailSource) : { footnoteLabels: /* @__PURE__ */ new Set(), linkLabels: /* @__PURE__ */ new Set() };
|
|
1414
|
+
const next = {
|
|
1415
|
+
footnoteLabels: /* @__PURE__ */ new Set([...frozenFootnotes, ...tail.footnoteLabels]),
|
|
1416
|
+
linkLabels: /* @__PURE__ */ new Set([...frozenLinks, ...tail.linkLabels])
|
|
1417
|
+
};
|
|
1418
|
+
if (prevLabels !== null && setsEqual(next.footnoteLabels, prevLabels.footnoteLabels) && setsEqual(next.linkLabels, prevLabels.linkLabels)) {
|
|
1419
|
+
prevSource = source;
|
|
1420
|
+
return prevLabels;
|
|
1421
|
+
}
|
|
1422
|
+
prevSource = source;
|
|
1423
|
+
prevLabels = next;
|
|
1424
|
+
return next;
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// src/components/extractDefBodiesFromHast.ts
|
|
1430
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
1431
|
+
var FN_LI_ID_RE = /(?:^|-)user-content-fn-(.+)$/;
|
|
1432
|
+
function sourceIdFromFootnoteLiId(idProp, clobberPrefix) {
|
|
1433
|
+
let raw = null;
|
|
1434
|
+
if (clobberPrefix !== void 0) {
|
|
1435
|
+
const exactPrefix = `${clobberPrefix}fn-`;
|
|
1436
|
+
if (idProp.startsWith(exactPrefix)) raw = idProp.slice(exactPrefix.length);
|
|
1437
|
+
}
|
|
1438
|
+
if (raw === null) {
|
|
1439
|
+
const m = idProp.match(FN_LI_ID_RE);
|
|
1440
|
+
raw = m ? m[1] : null;
|
|
1441
|
+
}
|
|
1442
|
+
if (raw === null) return null;
|
|
1443
|
+
try {
|
|
1444
|
+
return decodeURIComponent(raw);
|
|
1445
|
+
} catch {
|
|
1446
|
+
if (true) {
|
|
1447
|
+
console.warn(
|
|
1448
|
+
`[ai-react-markdown] Malformed percent-encoding in footnote id "${raw}"; its body may be missing from the aggregated footnote footer.`
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
return raw;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
function isBackrefAnchor(c) {
|
|
1455
|
+
if (c.type !== "element") return false;
|
|
1456
|
+
const el = c;
|
|
1457
|
+
if (el.tagName !== "a") return false;
|
|
1458
|
+
return Boolean(el.properties && "dataFootnoteBackref" in el.properties);
|
|
1459
|
+
}
|
|
1460
|
+
function isWhitespaceText(c) {
|
|
1461
|
+
if (c.type !== "text") return false;
|
|
1462
|
+
return /^\s*$/.test(c.value);
|
|
1463
|
+
}
|
|
1464
|
+
function lastMeaningfulIdx(children) {
|
|
1465
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
1466
|
+
if (!isWhitespaceText(children[i])) return i;
|
|
1467
|
+
}
|
|
1468
|
+
return -1;
|
|
1469
|
+
}
|
|
1470
|
+
function dropTrailingBackrefs(children) {
|
|
1471
|
+
let trailingWsStart = children.length;
|
|
1472
|
+
while (trailingWsStart > 0 && isWhitespaceText(children[trailingWsStart - 1])) {
|
|
1473
|
+
trailingWsStart--;
|
|
1474
|
+
}
|
|
1475
|
+
let scan = trailingWsStart;
|
|
1476
|
+
let peeledAny = false;
|
|
1477
|
+
while (scan > 0) {
|
|
1478
|
+
const t = children[scan - 1];
|
|
1479
|
+
if (!isBackrefAnchor(t)) break;
|
|
1480
|
+
peeledAny = true;
|
|
1481
|
+
scan -= 1;
|
|
1482
|
+
if (scan > 0 && children[scan - 1].type === "text" && children[scan - 1].value === " ") {
|
|
1483
|
+
scan -= 1;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
if (!peeledAny) return children;
|
|
1487
|
+
const trailing = children.slice(trailingWsStart);
|
|
1488
|
+
if (scan > 0) {
|
|
1489
|
+
const last = children[scan - 1];
|
|
1490
|
+
if (last.type === "text") {
|
|
1491
|
+
const v = last.value;
|
|
1492
|
+
if (v.endsWith(" ") && !/^\s*$/.test(v)) {
|
|
1493
|
+
return [...children.slice(0, scan - 1), { ...last, value: v.slice(0, -1) }, ...trailing];
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return [...children.slice(0, scan), ...trailing];
|
|
1498
|
+
}
|
|
1499
|
+
function stripBackrefs(liChildren) {
|
|
1500
|
+
if (liChildren.length === 0) return liChildren;
|
|
1501
|
+
const lastIdx = lastMeaningfulIdx(liChildren);
|
|
1502
|
+
if (lastIdx < 0) return liChildren;
|
|
1503
|
+
const last = liChildren[lastIdx];
|
|
1504
|
+
if (isBackrefAnchor(last)) {
|
|
1505
|
+
return dropTrailingBackrefs(liChildren);
|
|
1506
|
+
}
|
|
1507
|
+
if (last.type === "element" && last.tagName === "p") {
|
|
1508
|
+
const p = last;
|
|
1509
|
+
const newPChildren = dropTrailingBackrefs(p.children);
|
|
1510
|
+
if (newPChildren === p.children) return liChildren;
|
|
1511
|
+
return liChildren.map((c, i) => i === lastIdx ? { ...p, children: newPChildren } : c);
|
|
1512
|
+
}
|
|
1513
|
+
return liChildren;
|
|
1514
|
+
}
|
|
1515
|
+
function stripLocalOccurrenceFromFootnoteSups(children) {
|
|
1516
|
+
let changed = false;
|
|
1517
|
+
const out = [];
|
|
1518
|
+
for (const c of children) {
|
|
1519
|
+
if (c.type === "element") {
|
|
1520
|
+
const el = c;
|
|
1521
|
+
let nextEl = el;
|
|
1522
|
+
if (el.tagName === "footnote-sup" && el.properties && "localOccurrence" in el.properties) {
|
|
1523
|
+
const { localOccurrence: _drop, ...rest } = el.properties;
|
|
1524
|
+
nextEl = { ...el, properties: rest };
|
|
1525
|
+
changed = true;
|
|
1526
|
+
}
|
|
1527
|
+
const newChildren = stripLocalOccurrenceFromFootnoteSups(nextEl.children);
|
|
1528
|
+
if (newChildren !== nextEl.children) {
|
|
1529
|
+
nextEl = { ...nextEl, children: newChildren };
|
|
1530
|
+
changed = true;
|
|
1531
|
+
}
|
|
1532
|
+
out.push(nextEl);
|
|
1533
|
+
} else {
|
|
1534
|
+
out.push(c);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return changed ? out : children;
|
|
1538
|
+
}
|
|
1539
|
+
function extractDefBodiesFromHast(hast, clobberPrefix) {
|
|
1540
|
+
const out = /* @__PURE__ */ new Map();
|
|
1541
|
+
(0, import_unist_util_visit2.visit)(hast, "element", (sectionNode) => {
|
|
1542
|
+
const sec = sectionNode;
|
|
1543
|
+
if (sec.tagName !== "section") return;
|
|
1544
|
+
if (!(sec.properties && "dataFootnotes" in sec.properties)) return;
|
|
1545
|
+
(0, import_unist_util_visit2.visit)(sec, "element", (liNode) => {
|
|
1546
|
+
const li = liNode;
|
|
1547
|
+
if (li.tagName !== "li") return;
|
|
1548
|
+
const idProp = li.properties?.id;
|
|
1549
|
+
if (typeof idProp !== "string") return;
|
|
1550
|
+
const sourceId = sourceIdFromFootnoteLiId(idProp, clobberPrefix);
|
|
1551
|
+
if (sourceId === null) return;
|
|
1552
|
+
const normalized = normalizeId(sourceId);
|
|
1553
|
+
const stripped = stripBackrefs(li.children);
|
|
1554
|
+
out.set(normalized, stripLocalOccurrenceFromFootnoteSups(stripped));
|
|
1555
|
+
});
|
|
1556
|
+
return import_unist_util_visit2.SKIP;
|
|
1557
|
+
});
|
|
1558
|
+
return out;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
// src/components/extractContributions.ts
|
|
1562
|
+
var import_unist_util_visit3 = require("unist-util-visit");
|
|
1563
|
+
|
|
1564
|
+
// src/components/remarkInjectPhantomDefs.ts
|
|
1565
|
+
var SENTINEL_LINK_URL = "__aimd_sentinel_link__";
|
|
1566
|
+
var SENTINEL_FN_CONTENT = "__aimd_sentinel_fn__";
|
|
1567
|
+
function buildPhantomSuffix(phantoms) {
|
|
1568
|
+
if (phantoms.missingFootnotes.size === 0 && phantoms.missingLinks.size === 0) {
|
|
1569
|
+
return "";
|
|
1570
|
+
}
|
|
1571
|
+
let suffix = "\n\n";
|
|
1572
|
+
for (const label of phantoms.missingLinks) {
|
|
1573
|
+
suffix += `[${label}]: ${SENTINEL_LINK_URL}
|
|
1574
|
+
`;
|
|
1575
|
+
}
|
|
1576
|
+
for (const label of phantoms.missingFootnotes) {
|
|
1577
|
+
suffix += `[^${label}]: ${SENTINEL_FN_CONTENT}
|
|
1578
|
+
`;
|
|
1579
|
+
}
|
|
1580
|
+
return suffix;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// src/components/extractContributions.ts
|
|
1584
|
+
function fakeAnchorElement(url) {
|
|
1585
|
+
return { type: "element", tagName: "a", properties: { href: url }, children: [] };
|
|
1586
|
+
}
|
|
1587
|
+
function sanitizeDefUrl(url, urlTransform) {
|
|
1588
|
+
if (!urlTransform) return url;
|
|
1589
|
+
const result = urlTransform(url, "href", fakeAnchorElement(url));
|
|
1590
|
+
return result == null ? "" : String(result);
|
|
1591
|
+
}
|
|
1592
|
+
function* extractContributions(mdast, options = {}) {
|
|
1593
|
+
const phantomFn = options.phantomFootnoteLabels;
|
|
1594
|
+
const urlTransform = options.urlTransform;
|
|
1595
|
+
const out = [];
|
|
1596
|
+
(0, import_unist_util_visit3.visit)(mdast, (n) => {
|
|
1597
|
+
if (n.type === "footnoteReference") {
|
|
1598
|
+
out.push({
|
|
1599
|
+
kind: "ref",
|
|
1600
|
+
refKind: "footnote",
|
|
1601
|
+
label: normalizeId(n.identifier)
|
|
1602
|
+
});
|
|
1603
|
+
} else if (n.type === "linkReference") {
|
|
1604
|
+
const r = n;
|
|
1605
|
+
out.push({ kind: "ref", refKind: "link", label: normalizeId(r.identifier), referenceType: r.referenceType });
|
|
1606
|
+
} else if (n.type === "imageReference") {
|
|
1607
|
+
const r = n;
|
|
1608
|
+
out.push({ kind: "ref", refKind: "image", label: normalizeId(r.identifier), referenceType: r.referenceType });
|
|
1609
|
+
} else if (n.type === "footnoteDefinition") {
|
|
1610
|
+
const d = n;
|
|
1611
|
+
const label = normalizeId(d.identifier);
|
|
1612
|
+
if (phantomFn?.has(label)) return import_unist_util_visit3.SKIP;
|
|
1613
|
+
const content = JSON.stringify(d.children ?? []);
|
|
1614
|
+
out.push({ kind: "fnDef", label, sourceIdentifier: d.identifier, content });
|
|
1615
|
+
return import_unist_util_visit3.SKIP;
|
|
1616
|
+
} else if (n.type === "definition") {
|
|
1617
|
+
const d = n;
|
|
1618
|
+
if (d.url === SENTINEL_LINK_URL) return;
|
|
1619
|
+
out.push({
|
|
1620
|
+
kind: "linkDef",
|
|
1621
|
+
label: normalizeId(d.identifier),
|
|
1622
|
+
url: sanitizeDefUrl(d.url, urlTransform),
|
|
1623
|
+
title: d.title
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
for (const c of out) yield c;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
// src/components/documentRegistry.ts
|
|
1631
|
+
function createRegistry(onEmpty) {
|
|
1632
|
+
const reg = {
|
|
1633
|
+
chunkOrder: [],
|
|
1634
|
+
chunkData: /* @__PURE__ */ new Map(),
|
|
1635
|
+
labelSet: { footnoteLabels: /* @__PURE__ */ new Set(), linkLabels: /* @__PURE__ */ new Set() },
|
|
1636
|
+
version: 0,
|
|
1637
|
+
_reactIdMap: /* @__PURE__ */ new Map(),
|
|
1638
|
+
_subscribers: /* @__PURE__ */ new Set(),
|
|
1639
|
+
_notifyScheduled: false,
|
|
1640
|
+
allocateSymbol(reactId) {
|
|
1641
|
+
const existing = this._reactIdMap.get(reactId);
|
|
1642
|
+
if (existing) {
|
|
1643
|
+
existing.refcount++;
|
|
1644
|
+
return existing.symbol;
|
|
1645
|
+
}
|
|
1646
|
+
const sym = Symbol(reactId);
|
|
1647
|
+
this._reactIdMap.set(reactId, { symbol: sym, refcount: 1 });
|
|
1648
|
+
this.chunkOrder.push(sym);
|
|
1649
|
+
this._notify();
|
|
1650
|
+
return sym;
|
|
1651
|
+
},
|
|
1652
|
+
registerChunk(reactId, footnotes, links) {
|
|
1653
|
+
const sym = this.allocateSymbol(reactId);
|
|
1654
|
+
this.contributeLabels(sym, footnotes, links);
|
|
1655
|
+
return sym;
|
|
1656
|
+
},
|
|
1657
|
+
releaseSymbol(reactId) {
|
|
1658
|
+
const entry = this._reactIdMap.get(reactId);
|
|
1659
|
+
if (!entry) return;
|
|
1660
|
+
entry.refcount--;
|
|
1661
|
+
if (entry.refcount === 0) {
|
|
1662
|
+
queueMicrotask(() => {
|
|
1663
|
+
const latest = this._reactIdMap.get(reactId);
|
|
1664
|
+
if (latest && latest.refcount === 0) {
|
|
1665
|
+
this._reactIdMap.delete(reactId);
|
|
1666
|
+
const idx = this.chunkOrder.indexOf(entry.symbol);
|
|
1667
|
+
if (idx !== -1) this.chunkOrder.splice(idx, 1);
|
|
1668
|
+
this.chunkData.delete(entry.symbol);
|
|
1669
|
+
const nextFn = /* @__PURE__ */ new Set();
|
|
1670
|
+
const nextLink = /* @__PURE__ */ new Set();
|
|
1671
|
+
for (const cd of this.chunkData.values()) {
|
|
1672
|
+
for (const l of cd.ownFootnoteLabels) nextFn.add(l);
|
|
1673
|
+
for (const l of cd.ownLinkLabels) nextLink.add(l);
|
|
1674
|
+
}
|
|
1675
|
+
this.labelSet.footnoteLabels = nextFn;
|
|
1676
|
+
this.labelSet.linkLabels = nextLink;
|
|
1677
|
+
this._notify();
|
|
1678
|
+
if (this.chunkOrder.length === 0 && this.chunkData.size === 0 && onEmpty) {
|
|
1679
|
+
onEmpty();
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
},
|
|
1685
|
+
contributeLabels(symbol, footnotes, links) {
|
|
1686
|
+
const data = this.chunkData.get(symbol);
|
|
1687
|
+
if (data) {
|
|
1688
|
+
data.ownFootnoteLabels = footnotes;
|
|
1689
|
+
data.ownLinkLabels = links;
|
|
1690
|
+
} else {
|
|
1691
|
+
this.chunkData.set(symbol, {
|
|
1692
|
+
refs: [],
|
|
1693
|
+
defs: /* @__PURE__ */ new Map(),
|
|
1694
|
+
linkDefs: /* @__PURE__ */ new Map(),
|
|
1695
|
+
ownFootnoteLabels: footnotes,
|
|
1696
|
+
ownLinkLabels: links
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
const newFn = /* @__PURE__ */ new Set();
|
|
1700
|
+
const newLink = /* @__PURE__ */ new Set();
|
|
1701
|
+
for (const cd of this.chunkData.values()) {
|
|
1702
|
+
for (const l of cd.ownFootnoteLabels) newFn.add(l);
|
|
1703
|
+
for (const l of cd.ownLinkLabels) newLink.add(l);
|
|
1704
|
+
}
|
|
1705
|
+
this.labelSet.footnoteLabels = newFn;
|
|
1706
|
+
this.labelSet.linkLabels = newLink;
|
|
1707
|
+
this._notify();
|
|
1708
|
+
},
|
|
1709
|
+
contributeChunkData(symbol, data) {
|
|
1710
|
+
this.chunkData.set(symbol, data);
|
|
1711
|
+
this.labelSet.footnoteLabels = /* @__PURE__ */ new Set();
|
|
1712
|
+
this.labelSet.linkLabels = /* @__PURE__ */ new Set();
|
|
1713
|
+
for (const cd of this.chunkData.values()) {
|
|
1714
|
+
for (const l of cd.ownFootnoteLabels) this.labelSet.footnoteLabels.add(l);
|
|
1715
|
+
for (const l of cd.ownLinkLabels) this.labelSet.linkLabels.add(l);
|
|
1716
|
+
}
|
|
1717
|
+
this._notify();
|
|
1718
|
+
},
|
|
1719
|
+
subscribe(cb) {
|
|
1720
|
+
this._subscribers.add(cb);
|
|
1721
|
+
return () => {
|
|
1722
|
+
this._subscribers.delete(cb);
|
|
1723
|
+
};
|
|
1724
|
+
},
|
|
1725
|
+
canonicalFootnoteFor(label) {
|
|
1726
|
+
const id = normalizeId(label);
|
|
1727
|
+
for (const sym of this.chunkOrder) {
|
|
1728
|
+
const data = this.chunkData.get(sym);
|
|
1729
|
+
if (data?.defs.has(id)) return sym;
|
|
1730
|
+
}
|
|
1731
|
+
return null;
|
|
1732
|
+
},
|
|
1733
|
+
canonicalLinkFor(label) {
|
|
1734
|
+
const id = normalizeId(label);
|
|
1735
|
+
for (const sym of this.chunkOrder) {
|
|
1736
|
+
const data = this.chunkData.get(sym);
|
|
1737
|
+
if (data?.linkDefs.has(id)) return sym;
|
|
1738
|
+
}
|
|
1739
|
+
return null;
|
|
1740
|
+
},
|
|
1741
|
+
globalNumber(label) {
|
|
1742
|
+
const id = normalizeId(label);
|
|
1743
|
+
let n = 0;
|
|
1744
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1745
|
+
for (const sym of this.chunkOrder) {
|
|
1746
|
+
const data = this.chunkData.get(sym);
|
|
1747
|
+
if (!data) continue;
|
|
1748
|
+
for (const ref of data.refs) {
|
|
1749
|
+
if (ref.kind !== "footnote") continue;
|
|
1750
|
+
if (!seen.has(ref.label)) {
|
|
1751
|
+
seen.add(ref.label);
|
|
1752
|
+
n++;
|
|
1753
|
+
if (ref.label === id) return n;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
return null;
|
|
1758
|
+
},
|
|
1759
|
+
resolveLinkDef(label) {
|
|
1760
|
+
const sym = this.canonicalLinkFor(label);
|
|
1761
|
+
if (!sym) return null;
|
|
1762
|
+
return this.chunkData.get(sym)?.linkDefs.get(normalizeId(label)) ?? null;
|
|
1763
|
+
},
|
|
1764
|
+
getRefsForLabel(label) {
|
|
1765
|
+
const id = normalizeId(label);
|
|
1766
|
+
let n = 0;
|
|
1767
|
+
for (const sym of this.chunkOrder) {
|
|
1768
|
+
const data = this.chunkData.get(sym);
|
|
1769
|
+
if (!data) continue;
|
|
1770
|
+
for (const ref of data.refs) {
|
|
1771
|
+
if (ref.kind === "footnote" && ref.label === id) n++;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return n;
|
|
1775
|
+
},
|
|
1776
|
+
globalOccurrenceForRef(chunkSym, label, localOccurrence) {
|
|
1777
|
+
const id = normalizeId(label);
|
|
1778
|
+
let global2 = 0;
|
|
1779
|
+
for (const sym of this.chunkOrder) {
|
|
1780
|
+
const data = this.chunkData.get(sym);
|
|
1781
|
+
if (!data) continue;
|
|
1782
|
+
let localCount = 0;
|
|
1783
|
+
for (const ref of data.refs) {
|
|
1784
|
+
if (ref.kind !== "footnote") continue;
|
|
1785
|
+
if (ref.label !== id) continue;
|
|
1786
|
+
localCount++;
|
|
1787
|
+
global2++;
|
|
1788
|
+
if (sym === chunkSym && localCount === localOccurrence) return global2;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
return null;
|
|
1792
|
+
},
|
|
1793
|
+
_notify() {
|
|
1794
|
+
this.version++;
|
|
1795
|
+
if (this._notifyScheduled) return;
|
|
1796
|
+
this._notifyScheduled = true;
|
|
1797
|
+
queueMicrotask(() => {
|
|
1798
|
+
this._notifyScheduled = false;
|
|
1799
|
+
for (const cb of [...this._subscribers]) cb();
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
};
|
|
1803
|
+
return reg;
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
// src/components/pluginChain.ts
|
|
1807
|
+
var import_rehype_katex = __toESM(require("rehype-katex"), 1);
|
|
1808
|
+
var import_rehype_raw = __toESM(require("rehype-raw"), 1);
|
|
1809
|
+
var import_rehype_unwrap_images = __toESM(require("rehype-unwrap-images"), 1);
|
|
1810
|
+
var import_rehype_sanitize = __toESM(require("rehype-sanitize"), 1);
|
|
1811
|
+
var import_remark_breaks = __toESM(require("remark-breaks"), 1);
|
|
1812
|
+
var import_remark_cjk_friendly = __toESM(require("remark-cjk-friendly"), 1);
|
|
1813
|
+
var import_remark_cjk_friendly_gfm_strikethrough = __toESM(require("remark-cjk-friendly-gfm-strikethrough"), 1);
|
|
1814
|
+
var import_remark_emoji = __toESM(require("remark-emoji"), 1);
|
|
1815
|
+
var import_remark_gfm2 = __toESM(require("remark-gfm"), 1);
|
|
1816
|
+
var import_remark_math = __toESM(require("remark-math"), 1);
|
|
1817
|
+
var import_remark_definition_list = require("remark-definition-list");
|
|
1818
|
+
var import_remark_mark_highlight = require("@ai-react-markdown/remark-mark-highlight");
|
|
1819
|
+
var import_remark_squeeze_paragraphs = __toESM(require("remark-squeeze-paragraphs"), 1);
|
|
1820
|
+
var import_remark_smartypants = __toESM(require("remark-smartypants"), 1);
|
|
1821
|
+
var import_remark_pangu = __toESM(require("remark-pangu"), 1);
|
|
1822
|
+
var import_remark_remove_comments = __toESM(require("remark-remove-comments"), 1);
|
|
1823
|
+
|
|
1824
|
+
// src/components/rehypeRebaseHashLinks.ts
|
|
1825
|
+
var import_unist_util_visit4 = require("unist-util-visit");
|
|
1826
|
+
var DEFAULT_PREFIX = "user-content-";
|
|
1827
|
+
var rehypeRebaseHashLinks = (options) => {
|
|
1828
|
+
const prefix = options?.prefix ?? DEFAULT_PREFIX;
|
|
1829
|
+
const hashPrefix = "#" + prefix;
|
|
1830
|
+
return (tree) => {
|
|
1831
|
+
(0, import_unist_util_visit4.visit)(tree, "element", (node) => {
|
|
1832
|
+
if (node.tagName !== "a") return;
|
|
1833
|
+
const href = node.properties?.href;
|
|
1834
|
+
if (typeof href !== "string" || !href.startsWith("#")) return;
|
|
1835
|
+
if (href.startsWith(hashPrefix)) return;
|
|
1836
|
+
node.properties.href = hashPrefix + href.slice(1);
|
|
1837
|
+
});
|
|
1838
|
+
};
|
|
1839
|
+
};
|
|
1840
|
+
var rehypeRebaseHashLinks_default = rehypeRebaseHashLinks;
|
|
1841
|
+
|
|
1842
|
+
// src/components/rehypeFooterAdorn.ts
|
|
1843
|
+
var import_unist_util_visit5 = require("unist-util-visit");
|
|
1844
|
+
var FOOTNOTE_LABEL_ID_RE = /(?:^|-)footnote-label$/;
|
|
1845
|
+
function isFootnoteLabelH2(node) {
|
|
1846
|
+
if (node.type !== "element") return false;
|
|
1847
|
+
const el = node;
|
|
1848
|
+
if (el.tagName !== "h2") return false;
|
|
1849
|
+
const id = el.properties?.id;
|
|
1850
|
+
return typeof id === "string" && FOOTNOTE_LABEL_ID_RE.test(id);
|
|
1851
|
+
}
|
|
1852
|
+
function isHr(node) {
|
|
1853
|
+
if (node.type !== "element") return false;
|
|
1854
|
+
return node.tagName === "hr";
|
|
1855
|
+
}
|
|
1856
|
+
function rehypeFooterAdorn() {
|
|
1857
|
+
return (tree) => {
|
|
1858
|
+
(0, import_unist_util_visit5.visit)(tree, "element", (n) => {
|
|
1859
|
+
const el = n;
|
|
1860
|
+
if (el.tagName !== "section") return;
|
|
1861
|
+
if (!(el.properties && "dataFootnotes" in el.properties)) return;
|
|
1862
|
+
const filtered = el.children.filter((c) => !isFootnoteLabelH2(c));
|
|
1863
|
+
if (!filtered.some(isHr)) {
|
|
1864
|
+
const hr = {
|
|
1865
|
+
type: "element",
|
|
1866
|
+
tagName: "hr",
|
|
1867
|
+
properties: {},
|
|
1868
|
+
children: []
|
|
1869
|
+
};
|
|
1870
|
+
filtered.unshift(hr);
|
|
1871
|
+
}
|
|
1872
|
+
el.children = filtered;
|
|
1873
|
+
if (!el.properties) el.properties = {};
|
|
1874
|
+
if (!("ariaLabel" in el.properties)) {
|
|
1875
|
+
el.properties.ariaLabel = "Footnotes";
|
|
1876
|
+
}
|
|
1877
|
+
});
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// src/components/pluginChain.ts
|
|
1882
|
+
var EXTRA_SYNTAX_CHAIN = [
|
|
1883
|
+
["highlight", import_remark_mark_highlight.remarkMark],
|
|
1884
|
+
["definitionList", import_remark_definition_list.remarkDefinitionList]
|
|
1885
|
+
];
|
|
1886
|
+
var DISPLAY_OPTIMIZE_CHAIN = [
|
|
1887
|
+
["removeComments", import_remark_remove_comments.default],
|
|
1888
|
+
["smartypants", import_remark_smartypants.default],
|
|
1889
|
+
["pangu", import_remark_pangu.default]
|
|
1890
|
+
];
|
|
1891
|
+
function buildCoreRemarkPlugins(enginePlugins) {
|
|
1892
|
+
const selected = new Set(enginePlugins.map((plugin) => plugin.name));
|
|
1893
|
+
return [
|
|
1894
|
+
// --- Core plugins (always active) ---
|
|
1895
|
+
import_remark_gfm2.default,
|
|
1896
|
+
[
|
|
1897
|
+
import_remark_math.default,
|
|
1898
|
+
{
|
|
1899
|
+
// Disable single-dollar inline math to avoid conflicts with currency
|
|
1900
|
+
// signs and other dollar usages; the preprocessor converts $...$ to $$...$$.
|
|
1901
|
+
singleDollarTextMath: false
|
|
1902
|
+
}
|
|
1903
|
+
],
|
|
1904
|
+
// --- Selectable extra syntax plugins (canonical table order) ---
|
|
1905
|
+
...EXTRA_SYNTAX_CHAIN.filter(([name]) => selected.has(name)).map(([, plugin]) => plugin),
|
|
1906
|
+
// --- Formatting & normalization ---
|
|
1907
|
+
import_remark_breaks.default,
|
|
1908
|
+
import_remark_emoji.default,
|
|
1909
|
+
import_remark_squeeze_paragraphs.default,
|
|
1910
|
+
import_remark_cjk_friendly.default,
|
|
1911
|
+
import_remark_cjk_friendly_gfm_strikethrough.default,
|
|
1912
|
+
// --- Selectable display optimizations (canonical table order) ---
|
|
1913
|
+
...DISPLAY_OPTIMIZE_CHAIN.filter(([name]) => selected.has(name)).map(([, plugin]) => plugin)
|
|
1914
|
+
];
|
|
1915
|
+
}
|
|
1916
|
+
function buildCoreRehypePlugins(sanitizeSchema2, clobberPrefix) {
|
|
1917
|
+
return [
|
|
1918
|
+
// Allow raw HTML through so rehype-sanitize can handle it.
|
|
1919
|
+
[import_rehype_raw.default, { passThrough: [] }],
|
|
1920
|
+
// Sanitize HTML while allowing <mark> (highlight), KaTeX class names,
|
|
1921
|
+
// and any extra protocols the caller permitted via the `sanitizeSchema`
|
|
1922
|
+
// prop. Override `clobberPrefix` with the instance-scoped value — the
|
|
1923
|
+
// spread order is intentional: our prefix wins over any caller-supplied
|
|
1924
|
+
// prefix on the schema.
|
|
1925
|
+
[import_rehype_sanitize.default, { ...sanitizeSchema2, clobberPrefix }],
|
|
1926
|
+
// Normalize the auto-generated `<section data-footnotes>`: strip the
|
|
1927
|
+
// sr-only `<h2>Footnotes</h2>` label and prepend `<hr>`. Keeps standalone
|
|
1928
|
+
// single-doc rendering visually consistent with the cross-chunk aggregate
|
|
1929
|
+
// footer (which builds the same shape from scratch).
|
|
1930
|
+
rehypeFooterAdorn,
|
|
1931
|
+
// Re-prefix intra-document hash hrefs so they match the ids that
|
|
1932
|
+
// rehype-sanitize just clobbered. Must use the SAME prefix as the schema
|
|
1933
|
+
// above.
|
|
1934
|
+
[rehypeRebaseHashLinks_default, { prefix: clobberPrefix }],
|
|
1935
|
+
import_rehype_katex.default,
|
|
1936
|
+
import_rehype_unwrap_images.default
|
|
1937
|
+
];
|
|
1938
|
+
}
|
|
1939
|
+
function buildCoreRemarkRehypeOptions(enableDefinitionList) {
|
|
1940
|
+
return {
|
|
1941
|
+
allowDangerousHtml: true,
|
|
1942
|
+
// Suppress mdast-util-to-hast's `user-content-` prefix on footnote
|
|
1943
|
+
// ids/hrefs; rehype-sanitize will apply the same prefix downstream
|
|
1944
|
+
// and `rehypeRebaseHashLinks` mirrors it onto matching hash hrefs.
|
|
1945
|
+
// Without this, ids would end up double-prefixed
|
|
1946
|
+
// (`user-content-user-content-fn-x`).
|
|
1947
|
+
clobberPrefix: "",
|
|
1948
|
+
handlers: {
|
|
1949
|
+
// Inject definition-list HAST handlers when the extension is active.
|
|
1950
|
+
...enableDefinitionList ? import_remark_definition_list.defListHastHandlers : {}
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
// src/components/customMdastHandlers.ts
|
|
1956
|
+
function buildCrossChunkHandlers() {
|
|
1957
|
+
return {
|
|
1958
|
+
footnoteDefinition: (state, node) => {
|
|
1959
|
+
const s = state;
|
|
1960
|
+
const id = normalizeId(node.identifier);
|
|
1961
|
+
if (s.options.phantomFootnoteLabels.has(id)) {
|
|
1962
|
+
return void 0;
|
|
1963
|
+
}
|
|
1964
|
+
if (s.options.preserveOrphan && !s.footnoteOrder.includes(id)) {
|
|
1965
|
+
s.footnoteOrder.push(id);
|
|
1966
|
+
}
|
|
1967
|
+
return void 0;
|
|
1968
|
+
},
|
|
1969
|
+
linkReference: ((state, node) => {
|
|
1970
|
+
const s = state;
|
|
1971
|
+
const id = normalizeId(node.identifier);
|
|
1972
|
+
const resolved = s.definitionById.has(id);
|
|
1973
|
+
if (!resolved) {
|
|
1974
|
+
return void 0;
|
|
1975
|
+
}
|
|
1976
|
+
return {
|
|
1977
|
+
type: "element",
|
|
1978
|
+
tagName: "cross-chunk-link",
|
|
1979
|
+
properties: {
|
|
1980
|
+
// `label` is the ORIGINAL source text (mdast's `label` field), NOT
|
|
1981
|
+
// the normalized `identifier`. The placeholder uses it to construct
|
|
1982
|
+
// hrefs that line up with mdast-util-to-hast's default `<li id>`
|
|
1983
|
+
// which also preserves source case. Registry lookups normalize
|
|
1984
|
+
// internally, so cross-chunk case-insensitive matching still works.
|
|
1985
|
+
label: node.label ?? node.identifier,
|
|
1986
|
+
referenceType: node.referenceType,
|
|
1987
|
+
documentId: s.options.documentId
|
|
1988
|
+
},
|
|
1989
|
+
children: s.all(node)
|
|
1990
|
+
};
|
|
1991
|
+
}),
|
|
1992
|
+
imageReference: ((state, node) => {
|
|
1993
|
+
const s = state;
|
|
1994
|
+
const id = normalizeId(node.identifier);
|
|
1995
|
+
const resolved = s.definitionById.has(id);
|
|
1996
|
+
if (!resolved) return void 0;
|
|
1997
|
+
return {
|
|
1998
|
+
type: "element",
|
|
1999
|
+
tagName: "cross-chunk-image",
|
|
2000
|
+
properties: {
|
|
2001
|
+
label: node.label ?? node.identifier,
|
|
2002
|
+
referenceType: node.referenceType,
|
|
2003
|
+
alt: node.alt ?? "",
|
|
2004
|
+
documentId: s.options.documentId
|
|
2005
|
+
},
|
|
2006
|
+
children: []
|
|
2007
|
+
};
|
|
2008
|
+
}),
|
|
2009
|
+
footnoteReference: ((state, node) => {
|
|
2010
|
+
const s = state;
|
|
2011
|
+
const id = normalizeId(node.identifier);
|
|
2012
|
+
const localOccurrence = (s.footnoteCounts.get(id) ?? 0) + 1;
|
|
2013
|
+
s.footnoteCounts.set(id, localOccurrence);
|
|
2014
|
+
if (s.options.phantomFootnoteLabels.has(id)) {
|
|
2015
|
+
return {
|
|
2016
|
+
type: "element",
|
|
2017
|
+
tagName: "footnote-sup",
|
|
2018
|
+
properties: {
|
|
2019
|
+
label: node.identifier,
|
|
2020
|
+
localOccurrence,
|
|
2021
|
+
documentId: s.options.documentId
|
|
2022
|
+
},
|
|
2023
|
+
children: []
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
if (!s.footnoteOrder.includes(id)) s.footnoteOrder.push(id);
|
|
2027
|
+
return {
|
|
2028
|
+
type: "element",
|
|
2029
|
+
tagName: "footnote-sup",
|
|
2030
|
+
properties: {
|
|
2031
|
+
label: node.identifier,
|
|
2032
|
+
localOccurrence,
|
|
2033
|
+
documentId: s.options.documentId
|
|
2034
|
+
},
|
|
2035
|
+
children: []
|
|
2036
|
+
};
|
|
2037
|
+
})
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_listCacheClear.js
|
|
2042
|
+
function listCacheClear() {
|
|
2043
|
+
this.__data__ = [];
|
|
2044
|
+
this.size = 0;
|
|
2045
|
+
}
|
|
2046
|
+
var listCacheClear_default = listCacheClear;
|
|
2047
|
+
|
|
2048
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/eq.js
|
|
2049
|
+
function eq(value, other) {
|
|
2050
|
+
return value === other || value !== value && other !== other;
|
|
2051
|
+
}
|
|
2052
|
+
var eq_default = eq;
|
|
2053
|
+
|
|
2054
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_assocIndexOf.js
|
|
2055
|
+
function assocIndexOf(array, key) {
|
|
2056
|
+
var length = array.length;
|
|
2057
|
+
while (length--) {
|
|
2058
|
+
if (eq_default(array[length][0], key)) {
|
|
2059
|
+
return length;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
return -1;
|
|
2063
|
+
}
|
|
2064
|
+
var assocIndexOf_default = assocIndexOf;
|
|
2065
|
+
|
|
2066
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_listCacheDelete.js
|
|
2067
|
+
var arrayProto = Array.prototype;
|
|
2068
|
+
var splice = arrayProto.splice;
|
|
2069
|
+
function listCacheDelete(key) {
|
|
2070
|
+
var data = this.__data__, index = assocIndexOf_default(data, key);
|
|
2071
|
+
if (index < 0) {
|
|
2072
|
+
return false;
|
|
2073
|
+
}
|
|
2074
|
+
var lastIndex = data.length - 1;
|
|
2075
|
+
if (index == lastIndex) {
|
|
2076
|
+
data.pop();
|
|
2077
|
+
} else {
|
|
2078
|
+
splice.call(data, index, 1);
|
|
2079
|
+
}
|
|
2080
|
+
--this.size;
|
|
2081
|
+
return true;
|
|
2082
|
+
}
|
|
2083
|
+
var listCacheDelete_default = listCacheDelete;
|
|
2084
|
+
|
|
2085
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_listCacheGet.js
|
|
2086
|
+
function listCacheGet(key) {
|
|
2087
|
+
var data = this.__data__, index = assocIndexOf_default(data, key);
|
|
2088
|
+
return index < 0 ? void 0 : data[index][1];
|
|
2089
|
+
}
|
|
2090
|
+
var listCacheGet_default = listCacheGet;
|
|
2091
|
+
|
|
2092
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_listCacheHas.js
|
|
2093
|
+
function listCacheHas(key) {
|
|
2094
|
+
return assocIndexOf_default(this.__data__, key) > -1;
|
|
2095
|
+
}
|
|
2096
|
+
var listCacheHas_default = listCacheHas;
|
|
2097
|
+
|
|
2098
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_listCacheSet.js
|
|
2099
|
+
function listCacheSet(key, value) {
|
|
2100
|
+
var data = this.__data__, index = assocIndexOf_default(data, key);
|
|
2101
|
+
if (index < 0) {
|
|
2102
|
+
++this.size;
|
|
2103
|
+
data.push([key, value]);
|
|
2104
|
+
} else {
|
|
2105
|
+
data[index][1] = value;
|
|
2106
|
+
}
|
|
2107
|
+
return this;
|
|
2108
|
+
}
|
|
2109
|
+
var listCacheSet_default = listCacheSet;
|
|
2110
|
+
|
|
2111
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_ListCache.js
|
|
2112
|
+
function ListCache(entries) {
|
|
2113
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
2114
|
+
this.clear();
|
|
2115
|
+
while (++index < length) {
|
|
2116
|
+
var entry = entries[index];
|
|
2117
|
+
this.set(entry[0], entry[1]);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
ListCache.prototype.clear = listCacheClear_default;
|
|
2121
|
+
ListCache.prototype["delete"] = listCacheDelete_default;
|
|
2122
|
+
ListCache.prototype.get = listCacheGet_default;
|
|
2123
|
+
ListCache.prototype.has = listCacheHas_default;
|
|
2124
|
+
ListCache.prototype.set = listCacheSet_default;
|
|
2125
|
+
var ListCache_default = ListCache;
|
|
2126
|
+
|
|
2127
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_stackClear.js
|
|
2128
|
+
function stackClear() {
|
|
2129
|
+
this.__data__ = new ListCache_default();
|
|
2130
|
+
this.size = 0;
|
|
2131
|
+
}
|
|
2132
|
+
var stackClear_default = stackClear;
|
|
2133
|
+
|
|
2134
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_stackDelete.js
|
|
2135
|
+
function stackDelete(key) {
|
|
2136
|
+
var data = this.__data__, result = data["delete"](key);
|
|
2137
|
+
this.size = data.size;
|
|
2138
|
+
return result;
|
|
2139
|
+
}
|
|
2140
|
+
var stackDelete_default = stackDelete;
|
|
2141
|
+
|
|
2142
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_stackGet.js
|
|
2143
|
+
function stackGet(key) {
|
|
2144
|
+
return this.__data__.get(key);
|
|
2145
|
+
}
|
|
2146
|
+
var stackGet_default = stackGet;
|
|
2147
|
+
|
|
2148
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_stackHas.js
|
|
2149
|
+
function stackHas(key) {
|
|
2150
|
+
return this.__data__.has(key);
|
|
2151
|
+
}
|
|
2152
|
+
var stackHas_default = stackHas;
|
|
2153
|
+
|
|
2154
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_freeGlobal.js
|
|
2155
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
2156
|
+
var freeGlobal_default = freeGlobal;
|
|
2157
|
+
|
|
2158
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_root.js
|
|
2159
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
2160
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
2161
|
+
var root_default = root;
|
|
2162
|
+
|
|
2163
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_Symbol.js
|
|
2164
|
+
var Symbol2 = root_default.Symbol;
|
|
2165
|
+
var Symbol_default = Symbol2;
|
|
2166
|
+
|
|
2167
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getRawTag.js
|
|
2168
|
+
var objectProto = Object.prototype;
|
|
2169
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
2170
|
+
var nativeObjectToString = objectProto.toString;
|
|
2171
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
2172
|
+
function getRawTag(value) {
|
|
2173
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
2174
|
+
try {
|
|
2175
|
+
value[symToStringTag] = void 0;
|
|
2176
|
+
var unmasked = true;
|
|
2177
|
+
} catch (e) {
|
|
2178
|
+
}
|
|
2179
|
+
var result = nativeObjectToString.call(value);
|
|
2180
|
+
if (unmasked) {
|
|
2181
|
+
if (isOwn) {
|
|
2182
|
+
value[symToStringTag] = tag;
|
|
2183
|
+
} else {
|
|
2184
|
+
delete value[symToStringTag];
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
return result;
|
|
2188
|
+
}
|
|
2189
|
+
var getRawTag_default = getRawTag;
|
|
2190
|
+
|
|
2191
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_objectToString.js
|
|
2192
|
+
var objectProto2 = Object.prototype;
|
|
2193
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
2194
|
+
function objectToString(value) {
|
|
2195
|
+
return nativeObjectToString2.call(value);
|
|
2196
|
+
}
|
|
2197
|
+
var objectToString_default = objectToString;
|
|
2198
|
+
|
|
2199
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseGetTag.js
|
|
2200
|
+
var nullTag = "[object Null]";
|
|
2201
|
+
var undefinedTag = "[object Undefined]";
|
|
2202
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
2203
|
+
function baseGetTag(value) {
|
|
2204
|
+
if (value == null) {
|
|
2205
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
2206
|
+
}
|
|
2207
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
2208
|
+
}
|
|
2209
|
+
var baseGetTag_default = baseGetTag;
|
|
2210
|
+
|
|
2211
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isObject.js
|
|
2212
|
+
function isObject(value) {
|
|
2213
|
+
var type = typeof value;
|
|
2214
|
+
return value != null && (type == "object" || type == "function");
|
|
2215
|
+
}
|
|
2216
|
+
var isObject_default = isObject;
|
|
2217
|
+
|
|
2218
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isFunction.js
|
|
2219
|
+
var asyncTag = "[object AsyncFunction]";
|
|
2220
|
+
var funcTag = "[object Function]";
|
|
2221
|
+
var genTag = "[object GeneratorFunction]";
|
|
2222
|
+
var proxyTag = "[object Proxy]";
|
|
2223
|
+
function isFunction(value) {
|
|
2224
|
+
if (!isObject_default(value)) {
|
|
2225
|
+
return false;
|
|
2226
|
+
}
|
|
2227
|
+
var tag = baseGetTag_default(value);
|
|
2228
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
2229
|
+
}
|
|
2230
|
+
var isFunction_default = isFunction;
|
|
2231
|
+
|
|
2232
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_coreJsData.js
|
|
2233
|
+
var coreJsData = root_default["__core-js_shared__"];
|
|
2234
|
+
var coreJsData_default = coreJsData;
|
|
2235
|
+
|
|
2236
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_isMasked.js
|
|
2237
|
+
var maskSrcKey = (function() {
|
|
2238
|
+
var uid = /[^.]+$/.exec(coreJsData_default && coreJsData_default.keys && coreJsData_default.keys.IE_PROTO || "");
|
|
2239
|
+
return uid ? "Symbol(src)_1." + uid : "";
|
|
2240
|
+
})();
|
|
2241
|
+
function isMasked(func) {
|
|
2242
|
+
return !!maskSrcKey && maskSrcKey in func;
|
|
2243
|
+
}
|
|
2244
|
+
var isMasked_default = isMasked;
|
|
2245
|
+
|
|
2246
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_toSource.js
|
|
2247
|
+
var funcProto = Function.prototype;
|
|
2248
|
+
var funcToString = funcProto.toString;
|
|
2249
|
+
function toSource(func) {
|
|
2250
|
+
if (func != null) {
|
|
2251
|
+
try {
|
|
2252
|
+
return funcToString.call(func);
|
|
2253
|
+
} catch (e) {
|
|
2254
|
+
}
|
|
2255
|
+
try {
|
|
2256
|
+
return func + "";
|
|
2257
|
+
} catch (e) {
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
return "";
|
|
2261
|
+
}
|
|
2262
|
+
var toSource_default = toSource;
|
|
2263
|
+
|
|
2264
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseIsNative.js
|
|
2265
|
+
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
2266
|
+
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
2267
|
+
var funcProto2 = Function.prototype;
|
|
2268
|
+
var objectProto3 = Object.prototype;
|
|
2269
|
+
var funcToString2 = funcProto2.toString;
|
|
2270
|
+
var hasOwnProperty2 = objectProto3.hasOwnProperty;
|
|
2271
|
+
var reIsNative = RegExp(
|
|
2272
|
+
"^" + funcToString2.call(hasOwnProperty2).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
2273
|
+
);
|
|
2274
|
+
function baseIsNative(value) {
|
|
2275
|
+
if (!isObject_default(value) || isMasked_default(value)) {
|
|
2276
|
+
return false;
|
|
2277
|
+
}
|
|
2278
|
+
var pattern = isFunction_default(value) ? reIsNative : reIsHostCtor;
|
|
2279
|
+
return pattern.test(toSource_default(value));
|
|
2280
|
+
}
|
|
2281
|
+
var baseIsNative_default = baseIsNative;
|
|
2282
|
+
|
|
2283
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getValue.js
|
|
2284
|
+
function getValue(object, key) {
|
|
2285
|
+
return object == null ? void 0 : object[key];
|
|
2286
|
+
}
|
|
2287
|
+
var getValue_default = getValue;
|
|
2288
|
+
|
|
2289
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getNative.js
|
|
2290
|
+
function getNative(object, key) {
|
|
2291
|
+
var value = getValue_default(object, key);
|
|
2292
|
+
return baseIsNative_default(value) ? value : void 0;
|
|
2293
|
+
}
|
|
2294
|
+
var getNative_default = getNative;
|
|
2295
|
+
|
|
2296
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_Map.js
|
|
2297
|
+
var Map2 = getNative_default(root_default, "Map");
|
|
2298
|
+
var Map_default = Map2;
|
|
2299
|
+
|
|
2300
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_nativeCreate.js
|
|
2301
|
+
var nativeCreate = getNative_default(Object, "create");
|
|
2302
|
+
var nativeCreate_default = nativeCreate;
|
|
2303
|
+
|
|
2304
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_hashClear.js
|
|
2305
|
+
function hashClear() {
|
|
2306
|
+
this.__data__ = nativeCreate_default ? nativeCreate_default(null) : {};
|
|
2307
|
+
this.size = 0;
|
|
2308
|
+
}
|
|
2309
|
+
var hashClear_default = hashClear;
|
|
2310
|
+
|
|
2311
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_hashDelete.js
|
|
2312
|
+
function hashDelete(key) {
|
|
2313
|
+
var result = this.has(key) && delete this.__data__[key];
|
|
2314
|
+
this.size -= result ? 1 : 0;
|
|
2315
|
+
return result;
|
|
2316
|
+
}
|
|
2317
|
+
var hashDelete_default = hashDelete;
|
|
2318
|
+
|
|
2319
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_hashGet.js
|
|
2320
|
+
var HASH_UNDEFINED = "__lodash_hash_undefined__";
|
|
2321
|
+
var objectProto4 = Object.prototype;
|
|
2322
|
+
var hasOwnProperty3 = objectProto4.hasOwnProperty;
|
|
2323
|
+
function hashGet(key) {
|
|
2324
|
+
var data = this.__data__;
|
|
2325
|
+
if (nativeCreate_default) {
|
|
2326
|
+
var result = data[key];
|
|
2327
|
+
return result === HASH_UNDEFINED ? void 0 : result;
|
|
2328
|
+
}
|
|
2329
|
+
return hasOwnProperty3.call(data, key) ? data[key] : void 0;
|
|
2330
|
+
}
|
|
2331
|
+
var hashGet_default = hashGet;
|
|
2332
|
+
|
|
2333
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_hashHas.js
|
|
2334
|
+
var objectProto5 = Object.prototype;
|
|
2335
|
+
var hasOwnProperty4 = objectProto5.hasOwnProperty;
|
|
2336
|
+
function hashHas(key) {
|
|
2337
|
+
var data = this.__data__;
|
|
2338
|
+
return nativeCreate_default ? data[key] !== void 0 : hasOwnProperty4.call(data, key);
|
|
2339
|
+
}
|
|
2340
|
+
var hashHas_default = hashHas;
|
|
2341
|
+
|
|
2342
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_hashSet.js
|
|
2343
|
+
var HASH_UNDEFINED2 = "__lodash_hash_undefined__";
|
|
2344
|
+
function hashSet(key, value) {
|
|
2345
|
+
var data = this.__data__;
|
|
2346
|
+
this.size += this.has(key) ? 0 : 1;
|
|
2347
|
+
data[key] = nativeCreate_default && value === void 0 ? HASH_UNDEFINED2 : value;
|
|
2348
|
+
return this;
|
|
2349
|
+
}
|
|
2350
|
+
var hashSet_default = hashSet;
|
|
2351
|
+
|
|
2352
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_Hash.js
|
|
2353
|
+
function Hash(entries) {
|
|
2354
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
2355
|
+
this.clear();
|
|
2356
|
+
while (++index < length) {
|
|
2357
|
+
var entry = entries[index];
|
|
2358
|
+
this.set(entry[0], entry[1]);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
Hash.prototype.clear = hashClear_default;
|
|
2362
|
+
Hash.prototype["delete"] = hashDelete_default;
|
|
2363
|
+
Hash.prototype.get = hashGet_default;
|
|
2364
|
+
Hash.prototype.has = hashHas_default;
|
|
2365
|
+
Hash.prototype.set = hashSet_default;
|
|
2366
|
+
var Hash_default = Hash;
|
|
2367
|
+
|
|
2368
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheClear.js
|
|
2369
|
+
function mapCacheClear() {
|
|
2370
|
+
this.size = 0;
|
|
2371
|
+
this.__data__ = {
|
|
2372
|
+
"hash": new Hash_default(),
|
|
2373
|
+
"map": new (Map_default || ListCache_default)(),
|
|
2374
|
+
"string": new Hash_default()
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
var mapCacheClear_default = mapCacheClear;
|
|
2378
|
+
|
|
2379
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_isKeyable.js
|
|
2380
|
+
function isKeyable(value) {
|
|
2381
|
+
var type = typeof value;
|
|
2382
|
+
return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
|
|
2383
|
+
}
|
|
2384
|
+
var isKeyable_default = isKeyable;
|
|
2385
|
+
|
|
2386
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getMapData.js
|
|
2387
|
+
function getMapData(map, key) {
|
|
2388
|
+
var data = map.__data__;
|
|
2389
|
+
return isKeyable_default(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
|
|
2390
|
+
}
|
|
2391
|
+
var getMapData_default = getMapData;
|
|
2392
|
+
|
|
2393
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheDelete.js
|
|
2394
|
+
function mapCacheDelete(key) {
|
|
2395
|
+
var result = getMapData_default(this, key)["delete"](key);
|
|
2396
|
+
this.size -= result ? 1 : 0;
|
|
2397
|
+
return result;
|
|
2398
|
+
}
|
|
2399
|
+
var mapCacheDelete_default = mapCacheDelete;
|
|
2400
|
+
|
|
2401
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheGet.js
|
|
2402
|
+
function mapCacheGet(key) {
|
|
2403
|
+
return getMapData_default(this, key).get(key);
|
|
2404
|
+
}
|
|
2405
|
+
var mapCacheGet_default = mapCacheGet;
|
|
2406
|
+
|
|
2407
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheHas.js
|
|
2408
|
+
function mapCacheHas(key) {
|
|
2409
|
+
return getMapData_default(this, key).has(key);
|
|
2410
|
+
}
|
|
2411
|
+
var mapCacheHas_default = mapCacheHas;
|
|
2412
|
+
|
|
2413
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheSet.js
|
|
2414
|
+
function mapCacheSet(key, value) {
|
|
2415
|
+
var data = getMapData_default(this, key), size = data.size;
|
|
2416
|
+
data.set(key, value);
|
|
2417
|
+
this.size += data.size == size ? 0 : 1;
|
|
2418
|
+
return this;
|
|
2419
|
+
}
|
|
2420
|
+
var mapCacheSet_default = mapCacheSet;
|
|
2421
|
+
|
|
2422
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_MapCache.js
|
|
2423
|
+
function MapCache(entries) {
|
|
2424
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
2425
|
+
this.clear();
|
|
2426
|
+
while (++index < length) {
|
|
2427
|
+
var entry = entries[index];
|
|
2428
|
+
this.set(entry[0], entry[1]);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
MapCache.prototype.clear = mapCacheClear_default;
|
|
2432
|
+
MapCache.prototype["delete"] = mapCacheDelete_default;
|
|
2433
|
+
MapCache.prototype.get = mapCacheGet_default;
|
|
2434
|
+
MapCache.prototype.has = mapCacheHas_default;
|
|
2435
|
+
MapCache.prototype.set = mapCacheSet_default;
|
|
2436
|
+
var MapCache_default = MapCache;
|
|
2437
|
+
|
|
2438
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_stackSet.js
|
|
2439
|
+
var LARGE_ARRAY_SIZE = 200;
|
|
2440
|
+
function stackSet(key, value) {
|
|
2441
|
+
var data = this.__data__;
|
|
2442
|
+
if (data instanceof ListCache_default) {
|
|
2443
|
+
var pairs = data.__data__;
|
|
2444
|
+
if (!Map_default || pairs.length < LARGE_ARRAY_SIZE - 1) {
|
|
2445
|
+
pairs.push([key, value]);
|
|
2446
|
+
this.size = ++data.size;
|
|
2447
|
+
return this;
|
|
2448
|
+
}
|
|
2449
|
+
data = this.__data__ = new MapCache_default(pairs);
|
|
2450
|
+
}
|
|
2451
|
+
data.set(key, value);
|
|
2452
|
+
this.size = data.size;
|
|
2453
|
+
return this;
|
|
2454
|
+
}
|
|
2455
|
+
var stackSet_default = stackSet;
|
|
2456
|
+
|
|
2457
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_Stack.js
|
|
2458
|
+
function Stack(entries) {
|
|
2459
|
+
var data = this.__data__ = new ListCache_default(entries);
|
|
2460
|
+
this.size = data.size;
|
|
2461
|
+
}
|
|
2462
|
+
Stack.prototype.clear = stackClear_default;
|
|
2463
|
+
Stack.prototype["delete"] = stackDelete_default;
|
|
2464
|
+
Stack.prototype.get = stackGet_default;
|
|
2465
|
+
Stack.prototype.has = stackHas_default;
|
|
2466
|
+
Stack.prototype.set = stackSet_default;
|
|
2467
|
+
var Stack_default = Stack;
|
|
2468
|
+
|
|
2469
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_arrayEach.js
|
|
2470
|
+
function arrayEach(array, iteratee) {
|
|
2471
|
+
var index = -1, length = array == null ? 0 : array.length;
|
|
2472
|
+
while (++index < length) {
|
|
2473
|
+
if (iteratee(array[index], index, array) === false) {
|
|
2474
|
+
break;
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
return array;
|
|
2478
|
+
}
|
|
2479
|
+
var arrayEach_default = arrayEach;
|
|
2480
|
+
|
|
2481
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_defineProperty.js
|
|
2482
|
+
var defineProperty = (function() {
|
|
2483
|
+
try {
|
|
2484
|
+
var func = getNative_default(Object, "defineProperty");
|
|
2485
|
+
func({}, "", {});
|
|
2486
|
+
return func;
|
|
2487
|
+
} catch (e) {
|
|
2488
|
+
}
|
|
2489
|
+
})();
|
|
2490
|
+
var defineProperty_default = defineProperty;
|
|
2491
|
+
|
|
2492
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignValue.js
|
|
2493
|
+
function baseAssignValue(object, key, value) {
|
|
2494
|
+
if (key == "__proto__" && defineProperty_default) {
|
|
2495
|
+
defineProperty_default(object, key, {
|
|
2496
|
+
"configurable": true,
|
|
2497
|
+
"enumerable": true,
|
|
2498
|
+
"value": value,
|
|
2499
|
+
"writable": true
|
|
2500
|
+
});
|
|
2501
|
+
} else {
|
|
2502
|
+
object[key] = value;
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
var baseAssignValue_default = baseAssignValue;
|
|
2506
|
+
|
|
2507
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_assignValue.js
|
|
2508
|
+
var objectProto6 = Object.prototype;
|
|
2509
|
+
var hasOwnProperty5 = objectProto6.hasOwnProperty;
|
|
2510
|
+
function assignValue(object, key, value) {
|
|
2511
|
+
var objValue = object[key];
|
|
2512
|
+
if (!(hasOwnProperty5.call(object, key) && eq_default(objValue, value)) || value === void 0 && !(key in object)) {
|
|
2513
|
+
baseAssignValue_default(object, key, value);
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
var assignValue_default = assignValue;
|
|
2517
|
+
|
|
2518
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_copyObject.js
|
|
2519
|
+
function copyObject(source, props, object, customizer) {
|
|
2520
|
+
var isNew = !object;
|
|
2521
|
+
object || (object = {});
|
|
2522
|
+
var index = -1, length = props.length;
|
|
2523
|
+
while (++index < length) {
|
|
2524
|
+
var key = props[index];
|
|
2525
|
+
var newValue = customizer ? customizer(object[key], source[key], key, object, source) : void 0;
|
|
2526
|
+
if (newValue === void 0) {
|
|
2527
|
+
newValue = source[key];
|
|
2528
|
+
}
|
|
2529
|
+
if (isNew) {
|
|
2530
|
+
baseAssignValue_default(object, key, newValue);
|
|
2531
|
+
} else {
|
|
2532
|
+
assignValue_default(object, key, newValue);
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
return object;
|
|
2536
|
+
}
|
|
2537
|
+
var copyObject_default = copyObject;
|
|
2538
|
+
|
|
2539
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseTimes.js
|
|
2540
|
+
function baseTimes(n, iteratee) {
|
|
2541
|
+
var index = -1, result = Array(n);
|
|
2542
|
+
while (++index < n) {
|
|
2543
|
+
result[index] = iteratee(index);
|
|
2544
|
+
}
|
|
2545
|
+
return result;
|
|
2546
|
+
}
|
|
2547
|
+
var baseTimes_default = baseTimes;
|
|
2548
|
+
|
|
2549
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isObjectLike.js
|
|
2550
|
+
function isObjectLike(value) {
|
|
2551
|
+
return value != null && typeof value == "object";
|
|
2552
|
+
}
|
|
2553
|
+
var isObjectLike_default = isObjectLike;
|
|
2554
|
+
|
|
2555
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseIsArguments.js
|
|
2556
|
+
var argsTag = "[object Arguments]";
|
|
2557
|
+
function baseIsArguments(value) {
|
|
2558
|
+
return isObjectLike_default(value) && baseGetTag_default(value) == argsTag;
|
|
2559
|
+
}
|
|
2560
|
+
var baseIsArguments_default = baseIsArguments;
|
|
2561
|
+
|
|
2562
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isArguments.js
|
|
2563
|
+
var objectProto7 = Object.prototype;
|
|
2564
|
+
var hasOwnProperty6 = objectProto7.hasOwnProperty;
|
|
2565
|
+
var propertyIsEnumerable = objectProto7.propertyIsEnumerable;
|
|
2566
|
+
var isArguments = baseIsArguments_default(/* @__PURE__ */ (function() {
|
|
2567
|
+
return arguments;
|
|
2568
|
+
})()) ? baseIsArguments_default : function(value) {
|
|
2569
|
+
return isObjectLike_default(value) && hasOwnProperty6.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
|
|
2570
|
+
};
|
|
2571
|
+
var isArguments_default = isArguments;
|
|
2572
|
+
|
|
2573
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isArray.js
|
|
2574
|
+
var isArray = Array.isArray;
|
|
2575
|
+
var isArray_default = isArray;
|
|
2576
|
+
|
|
2577
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/stubFalse.js
|
|
2578
|
+
function stubFalse() {
|
|
2579
|
+
return false;
|
|
2580
|
+
}
|
|
2581
|
+
var stubFalse_default = stubFalse;
|
|
2582
|
+
|
|
2583
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isBuffer.js
|
|
2584
|
+
var freeExports = typeof exports == "object" && exports && !exports.nodeType && exports;
|
|
2585
|
+
var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module;
|
|
2586
|
+
var moduleExports = freeModule && freeModule.exports === freeExports;
|
|
2587
|
+
var Buffer2 = moduleExports ? root_default.Buffer : void 0;
|
|
2588
|
+
var nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : void 0;
|
|
2589
|
+
var isBuffer = nativeIsBuffer || stubFalse_default;
|
|
2590
|
+
var isBuffer_default = isBuffer;
|
|
2591
|
+
|
|
2592
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_isIndex.js
|
|
2593
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
2594
|
+
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
|
2595
|
+
function isIndex(value, length) {
|
|
2596
|
+
var type = typeof value;
|
|
2597
|
+
length = length == null ? MAX_SAFE_INTEGER : length;
|
|
2598
|
+
return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
|
|
2599
|
+
}
|
|
2600
|
+
var isIndex_default = isIndex;
|
|
2601
|
+
|
|
2602
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isLength.js
|
|
2603
|
+
var MAX_SAFE_INTEGER2 = 9007199254740991;
|
|
2604
|
+
function isLength(value) {
|
|
2605
|
+
return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER2;
|
|
2606
|
+
}
|
|
2607
|
+
var isLength_default = isLength;
|
|
2608
|
+
|
|
2609
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseIsTypedArray.js
|
|
2610
|
+
var argsTag2 = "[object Arguments]";
|
|
2611
|
+
var arrayTag = "[object Array]";
|
|
2612
|
+
var boolTag = "[object Boolean]";
|
|
2613
|
+
var dateTag = "[object Date]";
|
|
2614
|
+
var errorTag = "[object Error]";
|
|
2615
|
+
var funcTag2 = "[object Function]";
|
|
2616
|
+
var mapTag = "[object Map]";
|
|
2617
|
+
var numberTag = "[object Number]";
|
|
2618
|
+
var objectTag = "[object Object]";
|
|
2619
|
+
var regexpTag = "[object RegExp]";
|
|
2620
|
+
var setTag = "[object Set]";
|
|
2621
|
+
var stringTag = "[object String]";
|
|
2622
|
+
var weakMapTag = "[object WeakMap]";
|
|
2623
|
+
var arrayBufferTag = "[object ArrayBuffer]";
|
|
2624
|
+
var dataViewTag = "[object DataView]";
|
|
2625
|
+
var float32Tag = "[object Float32Array]";
|
|
2626
|
+
var float64Tag = "[object Float64Array]";
|
|
2627
|
+
var int8Tag = "[object Int8Array]";
|
|
2628
|
+
var int16Tag = "[object Int16Array]";
|
|
2629
|
+
var int32Tag = "[object Int32Array]";
|
|
2630
|
+
var uint8Tag = "[object Uint8Array]";
|
|
2631
|
+
var uint8ClampedTag = "[object Uint8ClampedArray]";
|
|
2632
|
+
var uint16Tag = "[object Uint16Array]";
|
|
2633
|
+
var uint32Tag = "[object Uint32Array]";
|
|
2634
|
+
var typedArrayTags = {};
|
|
2635
|
+
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
|
|
2636
|
+
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;
|
|
2637
|
+
function baseIsTypedArray(value) {
|
|
2638
|
+
return isObjectLike_default(value) && isLength_default(value.length) && !!typedArrayTags[baseGetTag_default(value)];
|
|
2639
|
+
}
|
|
2640
|
+
var baseIsTypedArray_default = baseIsTypedArray;
|
|
2641
|
+
|
|
2642
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseUnary.js
|
|
2643
|
+
function baseUnary(func) {
|
|
2644
|
+
return function(value) {
|
|
2645
|
+
return func(value);
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
var baseUnary_default = baseUnary;
|
|
2649
|
+
|
|
2650
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_nodeUtil.js
|
|
2651
|
+
var freeExports2 = typeof exports == "object" && exports && !exports.nodeType && exports;
|
|
2652
|
+
var freeModule2 = freeExports2 && typeof module == "object" && module && !module.nodeType && module;
|
|
2653
|
+
var moduleExports2 = freeModule2 && freeModule2.exports === freeExports2;
|
|
2654
|
+
var freeProcess = moduleExports2 && freeGlobal_default.process;
|
|
2655
|
+
var nodeUtil = (function() {
|
|
2656
|
+
try {
|
|
2657
|
+
var types = freeModule2 && freeModule2.require && freeModule2.require("util").types;
|
|
2658
|
+
if (types) {
|
|
2659
|
+
return types;
|
|
2660
|
+
}
|
|
2661
|
+
return freeProcess && freeProcess.binding && freeProcess.binding("util");
|
|
2662
|
+
} catch (e) {
|
|
2663
|
+
}
|
|
2664
|
+
})();
|
|
2665
|
+
var nodeUtil_default = nodeUtil;
|
|
2666
|
+
|
|
2667
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isTypedArray.js
|
|
2668
|
+
var nodeIsTypedArray = nodeUtil_default && nodeUtil_default.isTypedArray;
|
|
2669
|
+
var isTypedArray = nodeIsTypedArray ? baseUnary_default(nodeIsTypedArray) : baseIsTypedArray_default;
|
|
2670
|
+
var isTypedArray_default = isTypedArray;
|
|
2671
|
+
|
|
2672
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_arrayLikeKeys.js
|
|
2673
|
+
var objectProto8 = Object.prototype;
|
|
2674
|
+
var hasOwnProperty7 = objectProto8.hasOwnProperty;
|
|
2675
|
+
function arrayLikeKeys(value, inherited) {
|
|
2676
|
+
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;
|
|
2677
|
+
for (var key in value) {
|
|
2678
|
+
if ((inherited || hasOwnProperty7.call(value, key)) && !(skipIndexes && // Safari 9 has enumerable `arguments.length` in strict mode.
|
|
2679
|
+
(key == "length" || // Node.js 0.10 has enumerable non-index properties on buffers.
|
|
2680
|
+
isBuff && (key == "offset" || key == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays.
|
|
2681
|
+
isType && (key == "buffer" || key == "byteLength" || key == "byteOffset") || // Skip index properties.
|
|
2682
|
+
isIndex_default(key, length)))) {
|
|
2683
|
+
result.push(key);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
return result;
|
|
2687
|
+
}
|
|
2688
|
+
var arrayLikeKeys_default = arrayLikeKeys;
|
|
2689
|
+
|
|
2690
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_isPrototype.js
|
|
2691
|
+
var objectProto9 = Object.prototype;
|
|
2692
|
+
function isPrototype(value) {
|
|
2693
|
+
var Ctor = value && value.constructor, proto = typeof Ctor == "function" && Ctor.prototype || objectProto9;
|
|
2694
|
+
return value === proto;
|
|
2695
|
+
}
|
|
2696
|
+
var isPrototype_default = isPrototype;
|
|
2697
|
+
|
|
2698
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_overArg.js
|
|
2699
|
+
function overArg(func, transform) {
|
|
2700
|
+
return function(arg) {
|
|
2701
|
+
return func(transform(arg));
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
var overArg_default = overArg;
|
|
2705
|
+
|
|
2706
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeys.js
|
|
2707
|
+
var nativeKeys = overArg_default(Object.keys, Object);
|
|
2708
|
+
var nativeKeys_default = nativeKeys;
|
|
2709
|
+
|
|
2710
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseKeys.js
|
|
2711
|
+
var objectProto10 = Object.prototype;
|
|
2712
|
+
var hasOwnProperty8 = objectProto10.hasOwnProperty;
|
|
2713
|
+
function baseKeys(object) {
|
|
2714
|
+
if (!isPrototype_default(object)) {
|
|
2715
|
+
return nativeKeys_default(object);
|
|
2716
|
+
}
|
|
2717
|
+
var result = [];
|
|
2718
|
+
for (var key in Object(object)) {
|
|
2719
|
+
if (hasOwnProperty8.call(object, key) && key != "constructor") {
|
|
2720
|
+
result.push(key);
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
return result;
|
|
2724
|
+
}
|
|
2725
|
+
var baseKeys_default = baseKeys;
|
|
2726
|
+
|
|
2727
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isArrayLike.js
|
|
2728
|
+
function isArrayLike(value) {
|
|
2729
|
+
return value != null && isLength_default(value.length) && !isFunction_default(value);
|
|
2730
|
+
}
|
|
2731
|
+
var isArrayLike_default = isArrayLike;
|
|
2732
|
+
|
|
2733
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/keys.js
|
|
2734
|
+
function keys(object) {
|
|
2735
|
+
return isArrayLike_default(object) ? arrayLikeKeys_default(object) : baseKeys_default(object);
|
|
2736
|
+
}
|
|
2737
|
+
var keys_default = keys;
|
|
2738
|
+
|
|
2739
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseAssign.js
|
|
2740
|
+
function baseAssign(object, source) {
|
|
2741
|
+
return object && copyObject_default(source, keys_default(source), object);
|
|
2742
|
+
}
|
|
2743
|
+
var baseAssign_default = baseAssign;
|
|
2744
|
+
|
|
2745
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeysIn.js
|
|
2746
|
+
function nativeKeysIn(object) {
|
|
2747
|
+
var result = [];
|
|
2748
|
+
if (object != null) {
|
|
2749
|
+
for (var key in Object(object)) {
|
|
2750
|
+
result.push(key);
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
return result;
|
|
2754
|
+
}
|
|
2755
|
+
var nativeKeysIn_default = nativeKeysIn;
|
|
2756
|
+
|
|
2757
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseKeysIn.js
|
|
2758
|
+
var objectProto11 = Object.prototype;
|
|
2759
|
+
var hasOwnProperty9 = objectProto11.hasOwnProperty;
|
|
2760
|
+
function baseKeysIn(object) {
|
|
2761
|
+
if (!isObject_default(object)) {
|
|
2762
|
+
return nativeKeysIn_default(object);
|
|
2763
|
+
}
|
|
2764
|
+
var isProto = isPrototype_default(object), result = [];
|
|
2765
|
+
for (var key in object) {
|
|
2766
|
+
if (!(key == "constructor" && (isProto || !hasOwnProperty9.call(object, key)))) {
|
|
2767
|
+
result.push(key);
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
return result;
|
|
2771
|
+
}
|
|
2772
|
+
var baseKeysIn_default = baseKeysIn;
|
|
2773
|
+
|
|
2774
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/keysIn.js
|
|
2775
|
+
function keysIn(object) {
|
|
2776
|
+
return isArrayLike_default(object) ? arrayLikeKeys_default(object, true) : baseKeysIn_default(object);
|
|
2777
|
+
}
|
|
2778
|
+
var keysIn_default = keysIn;
|
|
2779
|
+
|
|
2780
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignIn.js
|
|
2781
|
+
function baseAssignIn(object, source) {
|
|
2782
|
+
return object && copyObject_default(source, keysIn_default(source), object);
|
|
2783
|
+
}
|
|
2784
|
+
var baseAssignIn_default = baseAssignIn;
|
|
2785
|
+
|
|
2786
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_cloneBuffer.js
|
|
2787
|
+
var freeExports3 = typeof exports == "object" && exports && !exports.nodeType && exports;
|
|
2788
|
+
var freeModule3 = freeExports3 && typeof module == "object" && module && !module.nodeType && module;
|
|
2789
|
+
var moduleExports3 = freeModule3 && freeModule3.exports === freeExports3;
|
|
2790
|
+
var Buffer3 = moduleExports3 ? root_default.Buffer : void 0;
|
|
2791
|
+
var allocUnsafe = Buffer3 ? Buffer3.allocUnsafe : void 0;
|
|
2792
|
+
function cloneBuffer(buffer, isDeep) {
|
|
2793
|
+
if (isDeep) {
|
|
2794
|
+
return buffer.slice();
|
|
2795
|
+
}
|
|
2796
|
+
var length = buffer.length, result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
|
|
2797
|
+
buffer.copy(result);
|
|
2798
|
+
return result;
|
|
2799
|
+
}
|
|
2800
|
+
var cloneBuffer_default = cloneBuffer;
|
|
2801
|
+
|
|
2802
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_copyArray.js
|
|
2803
|
+
function copyArray(source, array) {
|
|
2804
|
+
var index = -1, length = source.length;
|
|
2805
|
+
array || (array = Array(length));
|
|
2806
|
+
while (++index < length) {
|
|
2807
|
+
array[index] = source[index];
|
|
2808
|
+
}
|
|
2809
|
+
return array;
|
|
2810
|
+
}
|
|
2811
|
+
var copyArray_default = copyArray;
|
|
2812
|
+
|
|
2813
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_arrayFilter.js
|
|
2814
|
+
function arrayFilter(array, predicate) {
|
|
2815
|
+
var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = [];
|
|
2816
|
+
while (++index < length) {
|
|
2817
|
+
var value = array[index];
|
|
2818
|
+
if (predicate(value, index, array)) {
|
|
2819
|
+
result[resIndex++] = value;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
return result;
|
|
2823
|
+
}
|
|
2824
|
+
var arrayFilter_default = arrayFilter;
|
|
2825
|
+
|
|
2826
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/stubArray.js
|
|
2827
|
+
function stubArray() {
|
|
2828
|
+
return [];
|
|
2829
|
+
}
|
|
2830
|
+
var stubArray_default = stubArray;
|
|
2831
|
+
|
|
2832
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getSymbols.js
|
|
2833
|
+
var objectProto12 = Object.prototype;
|
|
2834
|
+
var propertyIsEnumerable2 = objectProto12.propertyIsEnumerable;
|
|
2835
|
+
var nativeGetSymbols = Object.getOwnPropertySymbols;
|
|
2836
|
+
var getSymbols = !nativeGetSymbols ? stubArray_default : function(object) {
|
|
2837
|
+
if (object == null) {
|
|
2838
|
+
return [];
|
|
2839
|
+
}
|
|
2840
|
+
object = Object(object);
|
|
2841
|
+
return arrayFilter_default(nativeGetSymbols(object), function(symbol) {
|
|
2842
|
+
return propertyIsEnumerable2.call(object, symbol);
|
|
2843
|
+
});
|
|
2844
|
+
};
|
|
2845
|
+
var getSymbols_default = getSymbols;
|
|
2846
|
+
|
|
2847
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_copySymbols.js
|
|
2848
|
+
function copySymbols(source, object) {
|
|
2849
|
+
return copyObject_default(source, getSymbols_default(source), object);
|
|
2850
|
+
}
|
|
2851
|
+
var copySymbols_default = copySymbols;
|
|
2852
|
+
|
|
2853
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_arrayPush.js
|
|
2854
|
+
function arrayPush(array, values) {
|
|
2855
|
+
var index = -1, length = values.length, offset = array.length;
|
|
2856
|
+
while (++index < length) {
|
|
2857
|
+
array[offset + index] = values[index];
|
|
2858
|
+
}
|
|
2859
|
+
return array;
|
|
2860
|
+
}
|
|
2861
|
+
var arrayPush_default = arrayPush;
|
|
2862
|
+
|
|
2863
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getPrototype.js
|
|
2864
|
+
var getPrototype = overArg_default(Object.getPrototypeOf, Object);
|
|
2865
|
+
var getPrototype_default = getPrototype;
|
|
2866
|
+
|
|
2867
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getSymbolsIn.js
|
|
2868
|
+
var nativeGetSymbols2 = Object.getOwnPropertySymbols;
|
|
2869
|
+
var getSymbolsIn = !nativeGetSymbols2 ? stubArray_default : function(object) {
|
|
2870
|
+
var result = [];
|
|
2871
|
+
while (object) {
|
|
2872
|
+
arrayPush_default(result, getSymbols_default(object));
|
|
2873
|
+
object = getPrototype_default(object);
|
|
2874
|
+
}
|
|
2875
|
+
return result;
|
|
2876
|
+
};
|
|
2877
|
+
var getSymbolsIn_default = getSymbolsIn;
|
|
2878
|
+
|
|
2879
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_copySymbolsIn.js
|
|
2880
|
+
function copySymbolsIn(source, object) {
|
|
2881
|
+
return copyObject_default(source, getSymbolsIn_default(source), object);
|
|
2882
|
+
}
|
|
2883
|
+
var copySymbolsIn_default = copySymbolsIn;
|
|
2884
|
+
|
|
2885
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseGetAllKeys.js
|
|
2886
|
+
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
|
2887
|
+
var result = keysFunc(object);
|
|
2888
|
+
return isArray_default(object) ? result : arrayPush_default(result, symbolsFunc(object));
|
|
2889
|
+
}
|
|
2890
|
+
var baseGetAllKeys_default = baseGetAllKeys;
|
|
2891
|
+
|
|
2892
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeys.js
|
|
2893
|
+
function getAllKeys(object) {
|
|
2894
|
+
return baseGetAllKeys_default(object, keys_default, getSymbols_default);
|
|
2895
|
+
}
|
|
2896
|
+
var getAllKeys_default = getAllKeys;
|
|
2897
|
+
|
|
2898
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeysIn.js
|
|
2899
|
+
function getAllKeysIn(object) {
|
|
2900
|
+
return baseGetAllKeys_default(object, keysIn_default, getSymbolsIn_default);
|
|
2901
|
+
}
|
|
2902
|
+
var getAllKeysIn_default = getAllKeysIn;
|
|
2903
|
+
|
|
2904
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_DataView.js
|
|
2905
|
+
var DataView = getNative_default(root_default, "DataView");
|
|
2906
|
+
var DataView_default = DataView;
|
|
2907
|
+
|
|
2908
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_Promise.js
|
|
2909
|
+
var Promise2 = getNative_default(root_default, "Promise");
|
|
2910
|
+
var Promise_default = Promise2;
|
|
2911
|
+
|
|
2912
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_Set.js
|
|
2913
|
+
var Set2 = getNative_default(root_default, "Set");
|
|
2914
|
+
var Set_default = Set2;
|
|
2915
|
+
|
|
2916
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_WeakMap.js
|
|
2917
|
+
var WeakMap = getNative_default(root_default, "WeakMap");
|
|
2918
|
+
var WeakMap_default = WeakMap;
|
|
2919
|
+
|
|
2920
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_getTag.js
|
|
2921
|
+
var mapTag2 = "[object Map]";
|
|
2922
|
+
var objectTag2 = "[object Object]";
|
|
2923
|
+
var promiseTag = "[object Promise]";
|
|
2924
|
+
var setTag2 = "[object Set]";
|
|
2925
|
+
var weakMapTag2 = "[object WeakMap]";
|
|
2926
|
+
var dataViewTag2 = "[object DataView]";
|
|
2927
|
+
var dataViewCtorString = toSource_default(DataView_default);
|
|
2928
|
+
var mapCtorString = toSource_default(Map_default);
|
|
2929
|
+
var promiseCtorString = toSource_default(Promise_default);
|
|
2930
|
+
var setCtorString = toSource_default(Set_default);
|
|
2931
|
+
var weakMapCtorString = toSource_default(WeakMap_default);
|
|
2932
|
+
var getTag = baseGetTag_default;
|
|
2933
|
+
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) {
|
|
2934
|
+
getTag = function(value) {
|
|
2935
|
+
var result = baseGetTag_default(value), Ctor = result == objectTag2 ? value.constructor : void 0, ctorString = Ctor ? toSource_default(Ctor) : "";
|
|
2936
|
+
if (ctorString) {
|
|
2937
|
+
switch (ctorString) {
|
|
2938
|
+
case dataViewCtorString:
|
|
2939
|
+
return dataViewTag2;
|
|
2940
|
+
case mapCtorString:
|
|
2941
|
+
return mapTag2;
|
|
2942
|
+
case promiseCtorString:
|
|
2943
|
+
return promiseTag;
|
|
2944
|
+
case setCtorString:
|
|
2945
|
+
return setTag2;
|
|
2946
|
+
case weakMapCtorString:
|
|
2947
|
+
return weakMapTag2;
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
return result;
|
|
2951
|
+
};
|
|
2952
|
+
}
|
|
2953
|
+
var getTag_default = getTag;
|
|
2954
|
+
|
|
2955
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_initCloneArray.js
|
|
2956
|
+
var objectProto13 = Object.prototype;
|
|
2957
|
+
var hasOwnProperty10 = objectProto13.hasOwnProperty;
|
|
2958
|
+
function initCloneArray(array) {
|
|
2959
|
+
var length = array.length, result = new array.constructor(length);
|
|
2960
|
+
if (length && typeof array[0] == "string" && hasOwnProperty10.call(array, "index")) {
|
|
2961
|
+
result.index = array.index;
|
|
2962
|
+
result.input = array.input;
|
|
2963
|
+
}
|
|
2964
|
+
return result;
|
|
2965
|
+
}
|
|
2966
|
+
var initCloneArray_default = initCloneArray;
|
|
2967
|
+
|
|
2968
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_Uint8Array.js
|
|
2969
|
+
var Uint8Array2 = root_default.Uint8Array;
|
|
2970
|
+
var Uint8Array_default = Uint8Array2;
|
|
2971
|
+
|
|
2972
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_cloneArrayBuffer.js
|
|
2973
|
+
function cloneArrayBuffer(arrayBuffer) {
|
|
2974
|
+
var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
2975
|
+
new Uint8Array_default(result).set(new Uint8Array_default(arrayBuffer));
|
|
2976
|
+
return result;
|
|
2977
|
+
}
|
|
2978
|
+
var cloneArrayBuffer_default = cloneArrayBuffer;
|
|
2979
|
+
|
|
2980
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_cloneDataView.js
|
|
2981
|
+
function cloneDataView(dataView, isDeep) {
|
|
2982
|
+
var buffer = isDeep ? cloneArrayBuffer_default(dataView.buffer) : dataView.buffer;
|
|
2983
|
+
return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
|
2984
|
+
}
|
|
2985
|
+
var cloneDataView_default = cloneDataView;
|
|
2986
|
+
|
|
2987
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_cloneRegExp.js
|
|
2988
|
+
var reFlags = /\w*$/;
|
|
2989
|
+
function cloneRegExp(regexp) {
|
|
2990
|
+
var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
|
2991
|
+
result.lastIndex = regexp.lastIndex;
|
|
2992
|
+
return result;
|
|
2993
|
+
}
|
|
2994
|
+
var cloneRegExp_default = cloneRegExp;
|
|
2995
|
+
|
|
2996
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_cloneSymbol.js
|
|
2997
|
+
var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
|
|
2998
|
+
var symbolValueOf = symbolProto ? symbolProto.valueOf : void 0;
|
|
2999
|
+
function cloneSymbol(symbol) {
|
|
3000
|
+
return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
|
3001
|
+
}
|
|
3002
|
+
var cloneSymbol_default = cloneSymbol;
|
|
3003
|
+
|
|
3004
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_cloneTypedArray.js
|
|
3005
|
+
function cloneTypedArray(typedArray, isDeep) {
|
|
3006
|
+
var buffer = isDeep ? cloneArrayBuffer_default(typedArray.buffer) : typedArray.buffer;
|
|
3007
|
+
return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
|
3008
|
+
}
|
|
3009
|
+
var cloneTypedArray_default = cloneTypedArray;
|
|
3010
|
+
|
|
3011
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_initCloneByTag.js
|
|
3012
|
+
var boolTag2 = "[object Boolean]";
|
|
3013
|
+
var dateTag2 = "[object Date]";
|
|
3014
|
+
var mapTag3 = "[object Map]";
|
|
3015
|
+
var numberTag2 = "[object Number]";
|
|
3016
|
+
var regexpTag2 = "[object RegExp]";
|
|
3017
|
+
var setTag3 = "[object Set]";
|
|
3018
|
+
var stringTag2 = "[object String]";
|
|
3019
|
+
var symbolTag = "[object Symbol]";
|
|
3020
|
+
var arrayBufferTag2 = "[object ArrayBuffer]";
|
|
3021
|
+
var dataViewTag3 = "[object DataView]";
|
|
3022
|
+
var float32Tag2 = "[object Float32Array]";
|
|
3023
|
+
var float64Tag2 = "[object Float64Array]";
|
|
3024
|
+
var int8Tag2 = "[object Int8Array]";
|
|
3025
|
+
var int16Tag2 = "[object Int16Array]";
|
|
3026
|
+
var int32Tag2 = "[object Int32Array]";
|
|
3027
|
+
var uint8Tag2 = "[object Uint8Array]";
|
|
3028
|
+
var uint8ClampedTag2 = "[object Uint8ClampedArray]";
|
|
3029
|
+
var uint16Tag2 = "[object Uint16Array]";
|
|
3030
|
+
var uint32Tag2 = "[object Uint32Array]";
|
|
3031
|
+
function initCloneByTag(object, tag, isDeep) {
|
|
3032
|
+
var Ctor = object.constructor;
|
|
3033
|
+
switch (tag) {
|
|
3034
|
+
case arrayBufferTag2:
|
|
3035
|
+
return cloneArrayBuffer_default(object);
|
|
3036
|
+
case boolTag2:
|
|
3037
|
+
case dateTag2:
|
|
3038
|
+
return new Ctor(+object);
|
|
3039
|
+
case dataViewTag3:
|
|
3040
|
+
return cloneDataView_default(object, isDeep);
|
|
3041
|
+
case float32Tag2:
|
|
3042
|
+
case float64Tag2:
|
|
3043
|
+
case int8Tag2:
|
|
3044
|
+
case int16Tag2:
|
|
3045
|
+
case int32Tag2:
|
|
3046
|
+
case uint8Tag2:
|
|
3047
|
+
case uint8ClampedTag2:
|
|
3048
|
+
case uint16Tag2:
|
|
3049
|
+
case uint32Tag2:
|
|
3050
|
+
return cloneTypedArray_default(object, isDeep);
|
|
3051
|
+
case mapTag3:
|
|
3052
|
+
return new Ctor();
|
|
3053
|
+
case numberTag2:
|
|
3054
|
+
case stringTag2:
|
|
3055
|
+
return new Ctor(object);
|
|
3056
|
+
case regexpTag2:
|
|
3057
|
+
return cloneRegExp_default(object);
|
|
3058
|
+
case setTag3:
|
|
3059
|
+
return new Ctor();
|
|
3060
|
+
case symbolTag:
|
|
3061
|
+
return cloneSymbol_default(object);
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
var initCloneByTag_default = initCloneByTag;
|
|
3065
|
+
|
|
3066
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseCreate.js
|
|
3067
|
+
var objectCreate = Object.create;
|
|
3068
|
+
var baseCreate = /* @__PURE__ */ (function() {
|
|
3069
|
+
function object() {
|
|
3070
|
+
}
|
|
3071
|
+
return function(proto) {
|
|
3072
|
+
if (!isObject_default(proto)) {
|
|
3073
|
+
return {};
|
|
3074
|
+
}
|
|
3075
|
+
if (objectCreate) {
|
|
3076
|
+
return objectCreate(proto);
|
|
3077
|
+
}
|
|
3078
|
+
object.prototype = proto;
|
|
3079
|
+
var result = new object();
|
|
3080
|
+
object.prototype = void 0;
|
|
3081
|
+
return result;
|
|
3082
|
+
};
|
|
3083
|
+
})();
|
|
3084
|
+
var baseCreate_default = baseCreate;
|
|
3085
|
+
|
|
3086
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_initCloneObject.js
|
|
3087
|
+
function initCloneObject(object) {
|
|
3088
|
+
return typeof object.constructor == "function" && !isPrototype_default(object) ? baseCreate_default(getPrototype_default(object)) : {};
|
|
3089
|
+
}
|
|
3090
|
+
var initCloneObject_default = initCloneObject;
|
|
3091
|
+
|
|
3092
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseIsMap.js
|
|
3093
|
+
var mapTag4 = "[object Map]";
|
|
3094
|
+
function baseIsMap(value) {
|
|
3095
|
+
return isObjectLike_default(value) && getTag_default(value) == mapTag4;
|
|
3096
|
+
}
|
|
3097
|
+
var baseIsMap_default = baseIsMap;
|
|
3098
|
+
|
|
3099
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isMap.js
|
|
3100
|
+
var nodeIsMap = nodeUtil_default && nodeUtil_default.isMap;
|
|
3101
|
+
var isMap = nodeIsMap ? baseUnary_default(nodeIsMap) : baseIsMap_default;
|
|
3102
|
+
var isMap_default = isMap;
|
|
3103
|
+
|
|
3104
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseIsSet.js
|
|
3105
|
+
var setTag4 = "[object Set]";
|
|
3106
|
+
function baseIsSet(value) {
|
|
3107
|
+
return isObjectLike_default(value) && getTag_default(value) == setTag4;
|
|
3108
|
+
}
|
|
3109
|
+
var baseIsSet_default = baseIsSet;
|
|
3110
|
+
|
|
3111
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/isSet.js
|
|
3112
|
+
var nodeIsSet = nodeUtil_default && nodeUtil_default.isSet;
|
|
3113
|
+
var isSet = nodeIsSet ? baseUnary_default(nodeIsSet) : baseIsSet_default;
|
|
3114
|
+
var isSet_default = isSet;
|
|
3115
|
+
|
|
3116
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/_baseClone.js
|
|
3117
|
+
var CLONE_DEEP_FLAG = 1;
|
|
3118
|
+
var CLONE_FLAT_FLAG = 2;
|
|
3119
|
+
var CLONE_SYMBOLS_FLAG = 4;
|
|
3120
|
+
var argsTag3 = "[object Arguments]";
|
|
3121
|
+
var arrayTag2 = "[object Array]";
|
|
3122
|
+
var boolTag3 = "[object Boolean]";
|
|
3123
|
+
var dateTag3 = "[object Date]";
|
|
3124
|
+
var errorTag2 = "[object Error]";
|
|
3125
|
+
var funcTag3 = "[object Function]";
|
|
3126
|
+
var genTag2 = "[object GeneratorFunction]";
|
|
3127
|
+
var mapTag5 = "[object Map]";
|
|
3128
|
+
var numberTag3 = "[object Number]";
|
|
3129
|
+
var objectTag3 = "[object Object]";
|
|
3130
|
+
var regexpTag3 = "[object RegExp]";
|
|
3131
|
+
var setTag5 = "[object Set]";
|
|
3132
|
+
var stringTag3 = "[object String]";
|
|
3133
|
+
var symbolTag2 = "[object Symbol]";
|
|
3134
|
+
var weakMapTag3 = "[object WeakMap]";
|
|
3135
|
+
var arrayBufferTag3 = "[object ArrayBuffer]";
|
|
3136
|
+
var dataViewTag4 = "[object DataView]";
|
|
3137
|
+
var float32Tag3 = "[object Float32Array]";
|
|
3138
|
+
var float64Tag3 = "[object Float64Array]";
|
|
3139
|
+
var int8Tag3 = "[object Int8Array]";
|
|
3140
|
+
var int16Tag3 = "[object Int16Array]";
|
|
3141
|
+
var int32Tag3 = "[object Int32Array]";
|
|
3142
|
+
var uint8Tag3 = "[object Uint8Array]";
|
|
3143
|
+
var uint8ClampedTag3 = "[object Uint8ClampedArray]";
|
|
3144
|
+
var uint16Tag3 = "[object Uint16Array]";
|
|
3145
|
+
var uint32Tag3 = "[object Uint32Array]";
|
|
3146
|
+
var cloneableTags = {};
|
|
3147
|
+
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;
|
|
3148
|
+
cloneableTags[errorTag2] = cloneableTags[funcTag3] = cloneableTags[weakMapTag3] = false;
|
|
3149
|
+
function baseClone(value, bitmask, customizer, key, object, stack) {
|
|
3150
|
+
var result, isDeep = bitmask & CLONE_DEEP_FLAG, isFlat = bitmask & CLONE_FLAT_FLAG, isFull = bitmask & CLONE_SYMBOLS_FLAG;
|
|
3151
|
+
if (customizer) {
|
|
3152
|
+
result = object ? customizer(value, key, object, stack) : customizer(value);
|
|
3153
|
+
}
|
|
3154
|
+
if (result !== void 0) {
|
|
3155
|
+
return result;
|
|
3156
|
+
}
|
|
3157
|
+
if (!isObject_default(value)) {
|
|
3158
|
+
return value;
|
|
3159
|
+
}
|
|
3160
|
+
var isArr = isArray_default(value);
|
|
3161
|
+
if (isArr) {
|
|
3162
|
+
result = initCloneArray_default(value);
|
|
3163
|
+
if (!isDeep) {
|
|
3164
|
+
return copyArray_default(value, result);
|
|
3165
|
+
}
|
|
3166
|
+
} else {
|
|
3167
|
+
var tag = getTag_default(value), isFunc = tag == funcTag3 || tag == genTag2;
|
|
3168
|
+
if (isBuffer_default(value)) {
|
|
3169
|
+
return cloneBuffer_default(value, isDeep);
|
|
3170
|
+
}
|
|
3171
|
+
if (tag == objectTag3 || tag == argsTag3 || isFunc && !object) {
|
|
3172
|
+
result = isFlat || isFunc ? {} : initCloneObject_default(value);
|
|
3173
|
+
if (!isDeep) {
|
|
3174
|
+
return isFlat ? copySymbolsIn_default(value, baseAssignIn_default(result, value)) : copySymbols_default(value, baseAssign_default(result, value));
|
|
3175
|
+
}
|
|
3176
|
+
} else {
|
|
3177
|
+
if (!cloneableTags[tag]) {
|
|
3178
|
+
return object ? value : {};
|
|
3179
|
+
}
|
|
3180
|
+
result = initCloneByTag_default(value, tag, isDeep);
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
stack || (stack = new Stack_default());
|
|
3184
|
+
var stacked = stack.get(value);
|
|
3185
|
+
if (stacked) {
|
|
3186
|
+
return stacked;
|
|
3187
|
+
}
|
|
3188
|
+
stack.set(value, result);
|
|
3189
|
+
if (isSet_default(value)) {
|
|
3190
|
+
value.forEach(function(subValue) {
|
|
3191
|
+
result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
|
|
3192
|
+
});
|
|
3193
|
+
} else if (isMap_default(value)) {
|
|
3194
|
+
value.forEach(function(subValue, key2) {
|
|
3195
|
+
result.set(key2, baseClone(subValue, bitmask, customizer, key2, value, stack));
|
|
3196
|
+
});
|
|
3197
|
+
}
|
|
3198
|
+
var keysFunc = isFull ? isFlat ? getAllKeysIn_default : getAllKeys_default : isFlat ? keysIn_default : keys_default;
|
|
3199
|
+
var props = isArr ? void 0 : keysFunc(value);
|
|
3200
|
+
arrayEach_default(props || value, function(subValue, key2) {
|
|
3201
|
+
if (props) {
|
|
3202
|
+
key2 = subValue;
|
|
3203
|
+
subValue = value[key2];
|
|
3204
|
+
}
|
|
3205
|
+
assignValue_default(result, key2, baseClone(subValue, bitmask, customizer, key2, value, stack));
|
|
3206
|
+
});
|
|
3207
|
+
return result;
|
|
3208
|
+
}
|
|
3209
|
+
var baseClone_default = baseClone;
|
|
3210
|
+
|
|
3211
|
+
// ../../node_modules/.pnpm/lodash-es@4.18.1/node_modules/lodash-es/cloneDeep.js
|
|
3212
|
+
var CLONE_DEEP_FLAG2 = 1;
|
|
3213
|
+
var CLONE_SYMBOLS_FLAG2 = 4;
|
|
3214
|
+
function cloneDeep(value) {
|
|
3215
|
+
return baseClone_default(value, CLONE_DEEP_FLAG2 | CLONE_SYMBOLS_FLAG2);
|
|
3216
|
+
}
|
|
3217
|
+
var cloneDeep_default = cloneDeep;
|
|
3218
|
+
|
|
3219
|
+
// src/components/sanitizeSchema.ts
|
|
3220
|
+
var import_rehype_sanitize2 = require("rehype-sanitize");
|
|
3221
|
+
function mergeClassNameAllowlist(existing, extraClassNames) {
|
|
3222
|
+
const entries = existing ? [...existing] : [];
|
|
3223
|
+
const idx = entries.findIndex(
|
|
3224
|
+
(entry) => typeof entry === "string" ? entry === "className" : entry[0] === "className"
|
|
3225
|
+
);
|
|
3226
|
+
if (idx === -1) {
|
|
3227
|
+
return [...entries, ["className", ...extraClassNames]];
|
|
3228
|
+
}
|
|
3229
|
+
const current = entries[idx];
|
|
3230
|
+
const merged = typeof current === "string" ? ["className", ...extraClassNames] : [...current, ...extraClassNames];
|
|
3231
|
+
entries[idx] = merged;
|
|
3232
|
+
return entries;
|
|
3233
|
+
}
|
|
3234
|
+
var crossChunkTags = ["cross-chunk-link", "cross-chunk-image", "footnote-sup"];
|
|
3235
|
+
var sanitizeSchema = cloneDeep_default({
|
|
3236
|
+
...import_rehype_sanitize2.defaultSchema,
|
|
3237
|
+
tagNames: [...import_rehype_sanitize2.defaultSchema.tagNames || [], "mark", ...crossChunkTags],
|
|
3238
|
+
attributes: {
|
|
3239
|
+
...import_rehype_sanitize2.defaultSchema.attributes,
|
|
3240
|
+
code: mergeClassNameAllowlist(import_rehype_sanitize2.defaultSchema.attributes?.code, ["math-inline", "math-display"]),
|
|
3241
|
+
"cross-chunk-link": ["label", "referenceType", "documentId"],
|
|
3242
|
+
"cross-chunk-image": ["label", "referenceType", "documentId", "alt"],
|
|
3243
|
+
"footnote-sup": ["label", "localOccurrence", "documentId"]
|
|
3244
|
+
}
|
|
3245
|
+
});
|
|
3246
|
+
|
|
3247
|
+
// src/components/crossChunkUrlSanitize.ts
|
|
3248
|
+
function fakeElement(tagName, key, url) {
|
|
3249
|
+
return { type: "element", tagName, properties: { [key]: url }, children: [] };
|
|
3250
|
+
}
|
|
3251
|
+
function isRelative(url, colon) {
|
|
3252
|
+
if (colon === -1) return true;
|
|
3253
|
+
const slash = url.indexOf("/");
|
|
3254
|
+
const questionMark = url.indexOf("?");
|
|
3255
|
+
const numberSign = url.indexOf("#");
|
|
3256
|
+
if (slash !== -1 && colon > slash) return true;
|
|
3257
|
+
if (questionMark !== -1 && colon > questionMark) return true;
|
|
3258
|
+
if (numberSign !== -1 && colon > numberSign) return true;
|
|
3259
|
+
return false;
|
|
3260
|
+
}
|
|
3261
|
+
function isProtocolAllowed(url, allowed) {
|
|
3262
|
+
const colon = url.indexOf(":");
|
|
3263
|
+
if (isRelative(url, colon)) return true;
|
|
3264
|
+
const protocol = url.slice(0, colon);
|
|
3265
|
+
return allowed.some((p) => p === protocol);
|
|
3266
|
+
}
|
|
3267
|
+
function sanitizeCrossChunkUrl(rawUrl, key, tagName, urlTransform, schema) {
|
|
3268
|
+
const transformed = urlTransform(rawUrl, key, fakeElement(tagName, key, rawUrl));
|
|
3269
|
+
if (transformed == null) return "";
|
|
3270
|
+
const stringUrl = String(transformed);
|
|
3271
|
+
if (stringUrl === "") return "";
|
|
3272
|
+
const callerProtocols = schema.protocols;
|
|
3273
|
+
const allowed = callerProtocols === void 0 || callerProtocols === null ? sanitizeSchema.protocols?.[key] : callerProtocols[key];
|
|
3274
|
+
if (!allowed || allowed.length === 0) return stringUrl;
|
|
3275
|
+
return isProtocolAllowed(stringUrl, allowed) ? stringUrl : "";
|
|
3276
|
+
}
|
|
3277
|
+
|
|
3278
|
+
// src/plugins/defs.ts
|
|
3279
|
+
function getEnginePluginInternals(plugin) {
|
|
3280
|
+
const candidate = plugin;
|
|
3281
|
+
return candidate != null && candidate["~sealed"] === "ai-react-markdown/engine-plugin" && candidate.stage != null ? candidate : null;
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
// src/plugins/catalog.ts
|
|
3285
|
+
var seal = (name, stage) => Object.freeze({
|
|
3286
|
+
name,
|
|
3287
|
+
"~sealed": "ai-react-markdown/engine-plugin",
|
|
3288
|
+
stage
|
|
3289
|
+
});
|
|
3290
|
+
var highlight = seal("highlight", "extraSyntax");
|
|
3291
|
+
var definitionList = seal("definitionList", "extraSyntax");
|
|
3292
|
+
var removeComments = seal("removeComments", "displayOptimize");
|
|
3293
|
+
var smartypants = seal("smartypants", "displayOptimize");
|
|
3294
|
+
var pangu = seal("pangu", "displayOptimize");
|
|
3295
|
+
var defaultEnginePlugins = Object.freeze([
|
|
3296
|
+
highlight,
|
|
3297
|
+
definitionList,
|
|
3298
|
+
removeComments,
|
|
3299
|
+
smartypants,
|
|
3300
|
+
pangu
|
|
3301
|
+
]);
|
|
3302
|
+
|
|
3303
|
+
// src/components/shortenDocumentId.ts
|
|
3304
|
+
var BASE62_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
3305
|
+
function toBase62(n) {
|
|
3306
|
+
if (n === 0) return BASE62_ALPHABET[0];
|
|
3307
|
+
let v = n >>> 0;
|
|
3308
|
+
let out = "";
|
|
3309
|
+
while (v > 0) {
|
|
3310
|
+
out = BASE62_ALPHABET[v % 62] + out;
|
|
3311
|
+
v = Math.floor(v / 62);
|
|
3312
|
+
}
|
|
3313
|
+
return out;
|
|
3314
|
+
}
|
|
3315
|
+
function rotl32(x, r) {
|
|
3316
|
+
return (x << r | x >>> 32 - r) >>> 0;
|
|
3317
|
+
}
|
|
3318
|
+
var C1 = 3432918353;
|
|
3319
|
+
var C2 = 461845907;
|
|
3320
|
+
var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
|
|
3321
|
+
function murmur3_32(s, seed = 0) {
|
|
3322
|
+
const bytes = UTF8_ENCODER.encode(s);
|
|
3323
|
+
const len = bytes.length;
|
|
3324
|
+
let h1 = seed >>> 0;
|
|
3325
|
+
const nblocks = len >>> 2;
|
|
3326
|
+
for (let i = 0; i < nblocks; i++) {
|
|
3327
|
+
const b = i * 4;
|
|
3328
|
+
let k1 = bytes[b] | bytes[b + 1] << 8 | bytes[b + 2] << 16 | bytes[b + 3] << 24;
|
|
3329
|
+
k1 = Math.imul(k1, C1);
|
|
3330
|
+
k1 = rotl32(k1, 15);
|
|
3331
|
+
k1 = Math.imul(k1, C2);
|
|
3332
|
+
h1 ^= k1;
|
|
3333
|
+
h1 = rotl32(h1, 13);
|
|
3334
|
+
h1 = Math.imul(h1, 5) + 3864292196 >>> 0;
|
|
3335
|
+
}
|
|
3336
|
+
const tail = nblocks * 4;
|
|
3337
|
+
const rem = len & 3;
|
|
3338
|
+
if (rem > 0) {
|
|
3339
|
+
let k1 = 0;
|
|
3340
|
+
if (rem === 3) k1 ^= bytes[tail + 2] << 16;
|
|
3341
|
+
if (rem >= 2) k1 ^= bytes[tail + 1] << 8;
|
|
3342
|
+
k1 ^= bytes[tail];
|
|
3343
|
+
k1 = Math.imul(k1, C1);
|
|
3344
|
+
k1 = rotl32(k1, 15);
|
|
3345
|
+
k1 = Math.imul(k1, C2);
|
|
3346
|
+
h1 ^= k1;
|
|
3347
|
+
}
|
|
3348
|
+
h1 ^= len;
|
|
3349
|
+
h1 ^= h1 >>> 16;
|
|
3350
|
+
h1 = Math.imul(h1, 2246822507);
|
|
3351
|
+
h1 ^= h1 >>> 13;
|
|
3352
|
+
h1 = Math.imul(h1, 3266489909);
|
|
3353
|
+
h1 ^= h1 >>> 16;
|
|
3354
|
+
return h1 >>> 0;
|
|
3355
|
+
}
|
|
3356
|
+
function shortenDocumentId(id, threshold = 16) {
|
|
3357
|
+
if (id.length <= threshold) return id;
|
|
3358
|
+
return toBase62(murmur3_32(id));
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3361
|
+
// src/components/devStageTimings.ts
|
|
3362
|
+
var PIPELINE_STAGES = ["scan", "parse", "transform", "build", "render"];
|
|
3363
|
+
var STAGE_MEASURE_PREFIX = "ai-markdown:stage:";
|
|
3364
|
+
var STAGE_NAMES = Object.fromEntries(
|
|
3365
|
+
PIPELINE_STAGES.map((stage) => [stage, `${STAGE_MEASURE_PREFIX}${stage}`])
|
|
3366
|
+
);
|
|
3367
|
+
var ENABLED = (() => {
|
|
3368
|
+
if (typeof performance === "undefined" || typeof performance.measure !== "function") {
|
|
3369
|
+
return false;
|
|
3370
|
+
}
|
|
3371
|
+
try {
|
|
3372
|
+
const probe = `${STAGE_MEASURE_PREFIX}probe`;
|
|
3373
|
+
performance.measure(probe, { start: 0, end: 0 });
|
|
3374
|
+
performance.clearMeasures?.(probe);
|
|
3375
|
+
return true;
|
|
3376
|
+
} catch {
|
|
3377
|
+
return false;
|
|
3378
|
+
}
|
|
3379
|
+
})();
|
|
3380
|
+
var stageListeners = /* @__PURE__ */ new Set();
|
|
3381
|
+
function subscribeStageTimings(listener) {
|
|
3382
|
+
stageListeners.add(listener);
|
|
3383
|
+
return () => {
|
|
3384
|
+
stageListeners.delete(listener);
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
function measureStage(stage, fn, instanceId) {
|
|
3388
|
+
if (!ENABLED) return fn();
|
|
3389
|
+
const start = performance.now();
|
|
3390
|
+
const result = fn();
|
|
3391
|
+
const end = performance.now();
|
|
3392
|
+
for (const listener of stageListeners) listener(stage, end - start, instanceId);
|
|
3393
|
+
performance.measure(STAGE_NAMES[stage], { start, end });
|
|
3394
|
+
return result;
|
|
3395
|
+
}
|
|
3396
|
+
|
|
3397
|
+
// src/components/extendSanitizeSchema.ts
|
|
3398
|
+
function extendSanitizeSchema(modifier) {
|
|
3399
|
+
const draft = cloneDeep_default(sanitizeSchema);
|
|
3400
|
+
const result = modifier(draft);
|
|
3401
|
+
return result ?? draft;
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3404
|
+
// src/components/smoothStream/controller.ts
|
|
3405
|
+
var SMOOTH_STREAM_PACING_PRESETS = Object.freeze({
|
|
3406
|
+
smooth: Object.freeze({
|
|
3407
|
+
bufferFactor: 1.7,
|
|
3408
|
+
correctionTauMs: 280,
|
|
3409
|
+
emaTauMs: 2600,
|
|
3410
|
+
minCharsPerSecond: 4,
|
|
3411
|
+
drainMs: 320
|
|
3412
|
+
}),
|
|
3413
|
+
balanced: Object.freeze({
|
|
3414
|
+
bufferFactor: 1,
|
|
3415
|
+
correctionTauMs: 180,
|
|
3416
|
+
emaTauMs: 1800,
|
|
3417
|
+
minCharsPerSecond: 6,
|
|
3418
|
+
drainMs: 240
|
|
3419
|
+
}),
|
|
3420
|
+
responsive: Object.freeze({
|
|
3421
|
+
bufferFactor: 0.45,
|
|
3422
|
+
correctionTauMs: 110,
|
|
3423
|
+
emaTauMs: 1100,
|
|
3424
|
+
minCharsPerSecond: 10,
|
|
3425
|
+
drainMs: 150
|
|
3426
|
+
})
|
|
3427
|
+
});
|
|
3428
|
+
var MAX_TARGET_BUFFER_MS = 1200;
|
|
3429
|
+
var defaultNow = typeof performance !== "undefined" && typeof performance.now === "function" ? () => performance.now() : () => Date.now();
|
|
3430
|
+
var defaultSchedule = (cb) => {
|
|
3431
|
+
if (typeof requestAnimationFrame === "function") {
|
|
3432
|
+
const id2 = requestAnimationFrame(() => cb());
|
|
3433
|
+
return () => cancelAnimationFrame(id2);
|
|
3434
|
+
}
|
|
3435
|
+
const id = setTimeout(cb, 16);
|
|
3436
|
+
return () => clearTimeout(id);
|
|
3437
|
+
};
|
|
3438
|
+
var finiteOr = (value, fallback) => value !== void 0 && Number.isFinite(value) ? value : fallback;
|
|
3439
|
+
var segmenter = typeof Intl !== "undefined" && typeof Intl.Segmenter === "function" ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : void 0;
|
|
3440
|
+
var graphemeEnds = (text, base) => {
|
|
3441
|
+
const ends = [];
|
|
3442
|
+
if (segmenter) {
|
|
3443
|
+
for (const part of segmenter.segment(text)) {
|
|
3444
|
+
ends.push(base + part.index + part.segment.length);
|
|
3445
|
+
}
|
|
3446
|
+
} else {
|
|
3447
|
+
let offset = base;
|
|
3448
|
+
for (const cp of text) {
|
|
3449
|
+
offset += cp.length;
|
|
3450
|
+
ends.push(offset);
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
return ends;
|
|
3454
|
+
};
|
|
3455
|
+
var createSmoothStreamController = (options = {}) => {
|
|
3456
|
+
const now = options.now ?? defaultNow;
|
|
3457
|
+
const schedule = options.schedule ?? defaultSchedule;
|
|
3458
|
+
let source = "";
|
|
3459
|
+
let visibleEnd = 0;
|
|
3460
|
+
let pending = [];
|
|
3461
|
+
let tentativeEnd = 0;
|
|
3462
|
+
let finished = false;
|
|
3463
|
+
let drainDeadlineAt;
|
|
3464
|
+
let initialized = false;
|
|
3465
|
+
let visibleCache = "";
|
|
3466
|
+
let credit = 0;
|
|
3467
|
+
let lastTickAt = 0;
|
|
3468
|
+
let cancelFrame;
|
|
3469
|
+
let disposed = false;
|
|
3470
|
+
let rateEma;
|
|
3471
|
+
let intervalEma;
|
|
3472
|
+
let lastArrivalAt;
|
|
3473
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3474
|
+
const resolveParams = () => {
|
|
3475
|
+
const preset = SMOOTH_STREAM_PACING_PRESETS[options.pacing] ?? SMOOTH_STREAM_PACING_PRESETS.balanced;
|
|
3476
|
+
return {
|
|
3477
|
+
bufferFactor: finiteOr(options.bufferFactor, preset.bufferFactor),
|
|
3478
|
+
correctionTauMs: finiteOr(options.correctionTauMs, preset.correctionTauMs),
|
|
3479
|
+
emaTauMs: finiteOr(options.emaTauMs, preset.emaTauMs),
|
|
3480
|
+
minCharsPerSecond: finiteOr(options.minCharsPerSecond, preset.minCharsPerSecond),
|
|
3481
|
+
drainMs: finiteOr(options.drainMs, preset.drainMs)
|
|
3482
|
+
};
|
|
3483
|
+
};
|
|
3484
|
+
const recordArrival = (t, added) => {
|
|
3485
|
+
if (added <= 0) return;
|
|
3486
|
+
if (lastArrivalAt === void 0) {
|
|
3487
|
+
lastArrivalAt = t;
|
|
3488
|
+
return;
|
|
3489
|
+
}
|
|
3490
|
+
const gap = Math.max(1, t - lastArrivalAt);
|
|
3491
|
+
lastArrivalAt = t;
|
|
3492
|
+
const tau = Math.max(1, resolveParams().emaTauMs);
|
|
3493
|
+
if (gap > tau) return;
|
|
3494
|
+
const alpha = 1 - Math.exp(-gap / tau);
|
|
3495
|
+
const instantRate = added * 1e3 / gap;
|
|
3496
|
+
rateEma = (rateEma ?? 0) + alpha * (instantRate - (rateEma ?? 0));
|
|
3497
|
+
intervalEma = (intervalEma ?? 0) + alpha * (gap - (intervalEma ?? 0));
|
|
3498
|
+
};
|
|
3499
|
+
const notify = () => {
|
|
3500
|
+
visibleCache = source.slice(0, visibleEnd);
|
|
3501
|
+
for (const listener of [...listeners]) listener();
|
|
3502
|
+
};
|
|
3503
|
+
const cancelScheduled = () => {
|
|
3504
|
+
cancelFrame?.();
|
|
3505
|
+
cancelFrame = void 0;
|
|
3506
|
+
};
|
|
3507
|
+
const ensureScheduled = () => {
|
|
3508
|
+
if (disposed || cancelFrame || pending.length === 0) return;
|
|
3509
|
+
lastTickAt = now();
|
|
3510
|
+
credit = 0;
|
|
3511
|
+
cancelFrame = schedule(tick);
|
|
3512
|
+
};
|
|
3513
|
+
const tick = () => {
|
|
3514
|
+
cancelFrame = void 0;
|
|
3515
|
+
if (disposed) return;
|
|
3516
|
+
const t = now();
|
|
3517
|
+
const dt = Math.max(0, t - lastTickAt);
|
|
3518
|
+
lastTickAt = t;
|
|
3519
|
+
const params = resolveParams();
|
|
3520
|
+
let rate;
|
|
3521
|
+
if (finished && drainDeadlineAt !== void 0) {
|
|
3522
|
+
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, drainDeadlineAt - t));
|
|
3523
|
+
} else if (rateEma !== void 0 && intervalEma !== void 0) {
|
|
3524
|
+
const targetBuffer = Math.max(
|
|
3525
|
+
1,
|
|
3526
|
+
Math.min(params.bufferFactor * rateEma * (intervalEma / 1e3), rateEma * MAX_TARGET_BUFFER_MS / 1e3)
|
|
3527
|
+
);
|
|
3528
|
+
rate = Math.max(
|
|
3529
|
+
params.minCharsPerSecond,
|
|
3530
|
+
rateEma + (pending.length - targetBuffer) * 1e3 / Math.max(1, params.correctionTauMs)
|
|
3531
|
+
);
|
|
3532
|
+
} else {
|
|
3533
|
+
rate = Math.max(params.minCharsPerSecond, pending.length * 1e3 / Math.max(1, params.correctionTauMs));
|
|
3534
|
+
}
|
|
3535
|
+
credit += rate * dt / 1e3;
|
|
3536
|
+
const reveal = Math.min(Math.floor(credit), pending.length);
|
|
3537
|
+
if (reveal > 0) {
|
|
3538
|
+
visibleEnd = pending[reveal - 1];
|
|
3539
|
+
pending = pending.slice(reveal);
|
|
3540
|
+
credit = pending.length > 0 ? credit - reveal : 0;
|
|
3541
|
+
notify();
|
|
3542
|
+
}
|
|
3543
|
+
if (!disposed && !cancelFrame && pending.length > 0) cancelFrame = schedule(tick);
|
|
3544
|
+
};
|
|
3545
|
+
const resegmentTail = () => {
|
|
3546
|
+
const from = pending.length > 0 ? pending[pending.length - 1] : visibleEnd;
|
|
3547
|
+
const ends = graphemeEnds(source.slice(from), from);
|
|
3548
|
+
if (ends.length === 0) {
|
|
3549
|
+
tentativeEnd = from;
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
tentativeEnd = ends[ends.length - 1];
|
|
3553
|
+
const confirmedEnds = finished ? ends : ends.slice(0, -1);
|
|
3554
|
+
for (const end of confirmedEnds) pending.push(end);
|
|
3555
|
+
};
|
|
3556
|
+
const snap = (next) => {
|
|
3557
|
+
disposed = false;
|
|
3558
|
+
initialized = true;
|
|
3559
|
+
finished = false;
|
|
3560
|
+
drainDeadlineAt = void 0;
|
|
3561
|
+
rateEma = void 0;
|
|
3562
|
+
intervalEma = void 0;
|
|
3563
|
+
lastArrivalAt = void 0;
|
|
3564
|
+
source = next;
|
|
3565
|
+
visibleEnd = next.length;
|
|
3566
|
+
tentativeEnd = next.length;
|
|
3567
|
+
pending = [];
|
|
3568
|
+
credit = 0;
|
|
3569
|
+
cancelScheduled();
|
|
3570
|
+
if (visibleCache !== next) notify();
|
|
3571
|
+
};
|
|
3572
|
+
const revive = () => {
|
|
3573
|
+
if (!disposed) return;
|
|
3574
|
+
disposed = false;
|
|
3575
|
+
ensureScheduled();
|
|
3576
|
+
};
|
|
3577
|
+
return {
|
|
3578
|
+
update(next) {
|
|
3579
|
+
revive();
|
|
3580
|
+
if (initialized && next === source) return;
|
|
3581
|
+
if (!initialized || !next.startsWith(source)) {
|
|
3582
|
+
snap(next);
|
|
3583
|
+
return;
|
|
3584
|
+
}
|
|
3585
|
+
finished = false;
|
|
3586
|
+
drainDeadlineAt = void 0;
|
|
3587
|
+
const previousLength = source.length;
|
|
3588
|
+
source = next;
|
|
3589
|
+
resegmentTail();
|
|
3590
|
+
recordArrival(now(), next.length - previousLength);
|
|
3591
|
+
ensureScheduled();
|
|
3592
|
+
},
|
|
3593
|
+
finish() {
|
|
3594
|
+
revive();
|
|
3595
|
+
if (finished) return;
|
|
3596
|
+
finished = true;
|
|
3597
|
+
lastArrivalAt = void 0;
|
|
3598
|
+
drainDeadlineAt = now() + resolveParams().drainMs;
|
|
3599
|
+
if (tentativeEnd > (pending.length > 0 ? pending[pending.length - 1] : visibleEnd)) {
|
|
3600
|
+
pending.push(tentativeEnd);
|
|
3601
|
+
}
|
|
3602
|
+
ensureScheduled();
|
|
3603
|
+
},
|
|
3604
|
+
snap,
|
|
3605
|
+
flush() {
|
|
3606
|
+
disposed = false;
|
|
3607
|
+
if (visibleEnd === source.length) return;
|
|
3608
|
+
visibleEnd = source.length;
|
|
3609
|
+
tentativeEnd = source.length;
|
|
3610
|
+
pending = [];
|
|
3611
|
+
credit = 0;
|
|
3612
|
+
cancelScheduled();
|
|
3613
|
+
notify();
|
|
3614
|
+
},
|
|
3615
|
+
subscribe(listener) {
|
|
3616
|
+
revive();
|
|
3617
|
+
listeners.add(listener);
|
|
3618
|
+
return () => {
|
|
3619
|
+
listeners.delete(listener);
|
|
3620
|
+
};
|
|
3621
|
+
},
|
|
3622
|
+
getVisible: () => visibleCache,
|
|
3623
|
+
isDrained: () => visibleEnd === source.length,
|
|
3624
|
+
dispose() {
|
|
3625
|
+
disposed = true;
|
|
3626
|
+
cancelScheduled();
|
|
3627
|
+
listeners.clear();
|
|
3628
|
+
}
|
|
3629
|
+
};
|
|
3630
|
+
};
|
|
3631
|
+
|
|
3632
|
+
// src/preprocessors/latex.ts
|
|
3633
|
+
function getRepeatedMarkerLength(content, start, marker) {
|
|
3634
|
+
let end = start;
|
|
3635
|
+
while (end < content.length && content[end] === marker) {
|
|
3636
|
+
end += 1;
|
|
3637
|
+
}
|
|
3638
|
+
return end - start;
|
|
3639
|
+
}
|
|
3640
|
+
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;
|
|
3641
|
+
var LITERAL_CONTENT_TAGS = /* @__PURE__ */ new Set(["code", "pre", "kbd", "samp", "math", "svg"]);
|
|
3642
|
+
var LITERAL_CONTENT_CLOSE_REGEX = {
|
|
3643
|
+
code: /<\/code\s*>/gi,
|
|
3644
|
+
pre: /<\/pre\s*>/gi,
|
|
3645
|
+
kbd: /<\/kbd\s*>/gi,
|
|
3646
|
+
samp: /<\/samp\s*>/gi,
|
|
3647
|
+
math: /<\/math\s*>/gi,
|
|
3648
|
+
svg: /<\/svg\s*>/gi
|
|
3649
|
+
};
|
|
3650
|
+
function isAtLineStart(content, pos) {
|
|
3651
|
+
let i = pos - 1;
|
|
3652
|
+
let spaces = 0;
|
|
3653
|
+
while (i >= 0 && content[i] === " ") {
|
|
3654
|
+
spaces++;
|
|
3655
|
+
if (spaces > 3) return false;
|
|
3656
|
+
i--;
|
|
3657
|
+
}
|
|
3658
|
+
return i < 0 || content[i] === "\n" || content[i] === "\r";
|
|
3659
|
+
}
|
|
3660
|
+
function findClosingBacktickRun(content, start, n) {
|
|
3661
|
+
let i = start;
|
|
3662
|
+
while (i < content.length) {
|
|
3663
|
+
if (content[i] === "`") {
|
|
3664
|
+
const runLen = getRepeatedMarkerLength(content, i, "`");
|
|
3665
|
+
if (runLen === n) return i;
|
|
3666
|
+
i += runLen;
|
|
3667
|
+
} else {
|
|
3668
|
+
i += 1;
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
return -1;
|
|
3672
|
+
}
|
|
3673
|
+
function splitByProtectedRegions(content) {
|
|
3674
|
+
const segments = [];
|
|
3675
|
+
let lastIndex = 0;
|
|
3676
|
+
let multilineStart = -1;
|
|
3677
|
+
let multilineFenceMarker = null;
|
|
3678
|
+
let multilineFenceLength = 0;
|
|
3679
|
+
function pushProtected(start, end) {
|
|
3680
|
+
if (start > lastIndex) {
|
|
3681
|
+
segments.push({ text: content.substring(lastIndex, start), isCode: false });
|
|
3682
|
+
}
|
|
3683
|
+
segments.push({ text: content.substring(start, end), isCode: true });
|
|
3684
|
+
lastIndex = end;
|
|
3685
|
+
}
|
|
3686
|
+
let i = 0;
|
|
3687
|
+
while (i < content.length) {
|
|
3688
|
+
const char = content[i];
|
|
3689
|
+
if (multilineStart !== -1) {
|
|
3690
|
+
if (char === multilineFenceMarker) {
|
|
3691
|
+
const runLen = getRepeatedMarkerLength(content, i, multilineFenceMarker);
|
|
3692
|
+
if (runLen >= multilineFenceLength && isAtLineStart(content, i)) {
|
|
3693
|
+
pushProtected(multilineStart, i + runLen);
|
|
3694
|
+
multilineStart = -1;
|
|
3695
|
+
multilineFenceMarker = null;
|
|
3696
|
+
multilineFenceLength = 0;
|
|
3697
|
+
i += runLen;
|
|
3698
|
+
continue;
|
|
3699
|
+
}
|
|
3700
|
+
i += runLen;
|
|
3701
|
+
continue;
|
|
3702
|
+
}
|
|
3703
|
+
i += 1;
|
|
3704
|
+
continue;
|
|
3705
|
+
}
|
|
3706
|
+
if (char === "`" || char === "~") {
|
|
3707
|
+
const runLen = getRepeatedMarkerLength(content, i, char);
|
|
3708
|
+
if (runLen >= 3 && isAtLineStart(content, i)) {
|
|
3709
|
+
multilineStart = i;
|
|
3710
|
+
multilineFenceMarker = char;
|
|
3711
|
+
multilineFenceLength = runLen;
|
|
3712
|
+
i += runLen;
|
|
3713
|
+
continue;
|
|
3714
|
+
}
|
|
3715
|
+
if (char === "`") {
|
|
3716
|
+
const closeIdx = findClosingBacktickRun(content, i + runLen, runLen);
|
|
3717
|
+
if (closeIdx !== -1) {
|
|
3718
|
+
pushProtected(i, closeIdx + runLen);
|
|
3719
|
+
i = closeIdx + runLen;
|
|
3720
|
+
continue;
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
i += runLen;
|
|
3724
|
+
continue;
|
|
3725
|
+
}
|
|
3726
|
+
if (char === "<") {
|
|
3727
|
+
HTML_TAG_REGEX.lastIndex = i;
|
|
3728
|
+
const tagMatch = HTML_TAG_REGEX.exec(content);
|
|
3729
|
+
if (tagMatch) {
|
|
3730
|
+
let endIndex = i + tagMatch[0].length;
|
|
3731
|
+
const tagName = tagMatch[1].toLowerCase();
|
|
3732
|
+
const isOpeningPairedTag = content[i + 1] !== "/" && !tagMatch[0].endsWith("/>") && LITERAL_CONTENT_TAGS.has(tagName);
|
|
3733
|
+
if (isOpeningPairedTag) {
|
|
3734
|
+
const closeRegex = LITERAL_CONTENT_CLOSE_REGEX[tagName];
|
|
3735
|
+
closeRegex.lastIndex = endIndex;
|
|
3736
|
+
const closeMatch = closeRegex.exec(content);
|
|
3737
|
+
if (closeMatch) {
|
|
3738
|
+
endIndex = closeMatch.index + closeMatch[0].length;
|
|
3739
|
+
} else {
|
|
3740
|
+
endIndex = content.length;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
pushProtected(i, endIndex);
|
|
3744
|
+
i = endIndex;
|
|
3745
|
+
continue;
|
|
3746
|
+
}
|
|
3747
|
+
}
|
|
3748
|
+
i += 1;
|
|
3749
|
+
}
|
|
3750
|
+
if (multilineStart !== -1) {
|
|
3751
|
+
pushProtected(multilineStart, content.length);
|
|
3752
|
+
}
|
|
3753
|
+
if (lastIndex < content.length) {
|
|
3754
|
+
segments.push({ text: content.substring(lastIndex), isCode: false });
|
|
3755
|
+
}
|
|
3756
|
+
return segments;
|
|
3757
|
+
}
|
|
3758
|
+
function escapeMhchemCommands(text) {
|
|
3759
|
+
return text.replaceAll("$\\ce{", "$\\\\ce{").replaceAll("$\\pu{", "$\\\\pu{");
|
|
3760
|
+
}
|
|
3761
|
+
var CURRENCY_REGEX = /(?<![\\$])\$(?!\$)(?=\d+(?:,\d{3})*(?:\.\d+)?(?:[KMBkmb])?(?:\s|$|[^a-zA-Z\d]))/g;
|
|
3762
|
+
var NO_ESCAPED_DOLLAR_REGEX = /(?<![\\$])\$(?!\$)/g;
|
|
3763
|
+
var DELIMITERS_REGEX = /(?<!!)\\\[([\S\s]*?[^\\])\\](?!\()|\\\((.*?)\\\)/g;
|
|
3764
|
+
var ARRAY_COL_SPEC_OR_PIPE_REGEX = /(\\begin\{(?:array|tabular[x*]?)\}\{[^}]*\})|(?<!\\)\|/g;
|
|
3765
|
+
var LATEX_BLOCK_REGEX = /\$\$([\S\s]*?)\$\$|(?<![\\$])\$(?!\$)((?:[^$\n]|\\\$)*?)(?<![\\`])\$(?!\$)/g;
|
|
3766
|
+
var TEXT_COMMAND = "\\text{";
|
|
3767
|
+
var SINGLE_DOLLAR_REGEX = /(?<![\\$])\$(?!\$)((?:[^$\n]|\\[$])+?)(?<!\\)(?<!`)\$(?!\$)/g;
|
|
3768
|
+
function escapeCurrencyDollarSigns(text) {
|
|
3769
|
+
const parts = [];
|
|
3770
|
+
let lastIndex = 0;
|
|
3771
|
+
const currencyMatches = Array.from(text.matchAll(CURRENCY_REGEX));
|
|
3772
|
+
let currentLineProcessed = "";
|
|
3773
|
+
for (let i = 0; i < currencyMatches.length; i++) {
|
|
3774
|
+
const match = currencyMatches[i];
|
|
3775
|
+
const segment = text.substring(lastIndex, match.index);
|
|
3776
|
+
parts.push(segment);
|
|
3777
|
+
const newlineIdx = Math.max(segment.lastIndexOf("\n"), segment.lastIndexOf("\r"));
|
|
3778
|
+
if (newlineIdx !== -1) {
|
|
3779
|
+
currentLineProcessed = segment.substring(newlineIdx + 1);
|
|
3780
|
+
} else {
|
|
3781
|
+
currentLineProcessed += segment;
|
|
3782
|
+
}
|
|
3783
|
+
let needEscape = true;
|
|
3784
|
+
let restBeforeNextMatchOrEnd = "";
|
|
3785
|
+
if (i < currencyMatches.length - 1) {
|
|
3786
|
+
const nextMatch = currencyMatches[i + 1];
|
|
3787
|
+
if (nextMatch.index - match.index > 1) {
|
|
3788
|
+
restBeforeNextMatchOrEnd = text.substring(match.index + 1, nextMatch.index);
|
|
3789
|
+
}
|
|
3790
|
+
} else {
|
|
3791
|
+
restBeforeNextMatchOrEnd = text.substring(match.index + 1);
|
|
3792
|
+
}
|
|
3793
|
+
const firstLineBeforeNextMatch = restBeforeNextMatchOrEnd.split(/\r\n|\r|\n/g)[0];
|
|
3794
|
+
if (Array.from(firstLineBeforeNextMatch.matchAll(NO_ESCAPED_DOLLAR_REGEX)).length % 2 !== 0) {
|
|
3795
|
+
const wholeLineBeforeNextMatchWithoutCurrentDollar = currentLineProcessed + firstLineBeforeNextMatch;
|
|
3796
|
+
if (Array.from(wholeLineBeforeNextMatchWithoutCurrentDollar.matchAll(NO_ESCAPED_DOLLAR_REGEX)).length % 2 !== 0) {
|
|
3797
|
+
needEscape = false;
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
const replacement = needEscape ? "\\$" : "$";
|
|
3801
|
+
parts.push(replacement);
|
|
3802
|
+
currentLineProcessed += replacement;
|
|
3803
|
+
lastIndex = match.index + 1;
|
|
3804
|
+
}
|
|
3805
|
+
parts.push(text.substring(lastIndex));
|
|
3806
|
+
return parts.join("");
|
|
3807
|
+
}
|
|
3808
|
+
function convertLatexDelimiters(text) {
|
|
3809
|
+
return text.replaceAll(
|
|
3810
|
+
DELIMITERS_REGEX,
|
|
3811
|
+
(match, squareBracket, roundBracket) => {
|
|
3812
|
+
if (squareBracket !== void 0) {
|
|
3813
|
+
return `$$${squareBracket}$$`;
|
|
3814
|
+
} else if (roundBracket !== void 0) {
|
|
3815
|
+
return `$${roundBracket}$`;
|
|
3816
|
+
}
|
|
3817
|
+
return match;
|
|
3818
|
+
}
|
|
3819
|
+
);
|
|
3820
|
+
}
|
|
3821
|
+
var replaceUnescapedPipes = (formula) => (
|
|
3822
|
+
// Use \vert{} so the control sequence terminates before the next token.
|
|
3823
|
+
// Preserve `|` inside \begin{array}{...} / \begin{tabular}{...} column specifiers.
|
|
3824
|
+
formula.replaceAll(
|
|
3825
|
+
ARRAY_COL_SPEC_OR_PIPE_REGEX,
|
|
3826
|
+
(match, colSpec) => colSpec !== void 0 ? match : "\\vert{}"
|
|
3827
|
+
)
|
|
3828
|
+
);
|
|
3829
|
+
function escapeLatexPipes(text) {
|
|
3830
|
+
return text.replaceAll(LATEX_BLOCK_REGEX, (match, display, inline) => {
|
|
3831
|
+
if (display !== void 0) return `$$${replaceUnescapedPipes(display)}$$`;
|
|
3832
|
+
if (inline !== void 0) return `$${replaceUnescapedPipes(inline)}$`;
|
|
3833
|
+
return match;
|
|
3834
|
+
});
|
|
3835
|
+
}
|
|
3836
|
+
function isEscapedByBackslashRun(text, pos) {
|
|
3837
|
+
let count = 0;
|
|
3838
|
+
let j = pos - 1;
|
|
3839
|
+
while (j >= 0 && text[j] === "\\") {
|
|
3840
|
+
count++;
|
|
3841
|
+
j--;
|
|
3842
|
+
}
|
|
3843
|
+
return count % 2 === 1;
|
|
3844
|
+
}
|
|
3845
|
+
function findUnclosedDelimiterStart(text, mode) {
|
|
3846
|
+
let unclosedStart = -1;
|
|
3847
|
+
let i = 0;
|
|
3848
|
+
while (i < text.length) {
|
|
3849
|
+
if (text[i] === "$" && i + 1 < text.length && text[i + 1] === "$" && !isEscapedByBackslashRun(text, i)) {
|
|
3850
|
+
unclosedStart = unclosedStart === -1 ? i : -1;
|
|
3851
|
+
i += 2;
|
|
3852
|
+
} else if (mode === "both" && text[i] === "$" && !isEscapedByBackslashRun(text, i) && (i + 1 >= text.length || text[i + 1] !== "$")) {
|
|
3853
|
+
unclosedStart = unclosedStart === -1 ? i : -1;
|
|
3854
|
+
i += 1;
|
|
3855
|
+
} else {
|
|
3856
|
+
i += 1;
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3859
|
+
return unclosedStart;
|
|
3860
|
+
}
|
|
3861
|
+
function escapeLatexPipesInUnclosed(text) {
|
|
3862
|
+
const unclosedStart = findUnclosedDelimiterStart(text, "both");
|
|
3863
|
+
if (unclosedStart === -1) return text;
|
|
3864
|
+
const before = text.substring(0, unclosedStart);
|
|
3865
|
+
const delimLen = text[unclosedStart + 1] === "$" ? 2 : 1;
|
|
3866
|
+
const delim = text.substring(unclosedStart, unclosedStart + delimLen);
|
|
3867
|
+
const tail = text.substring(unclosedStart + delimLen);
|
|
3868
|
+
return before + delim + replaceUnescapedPipes(tail);
|
|
3869
|
+
}
|
|
3870
|
+
function truncateUnclosedLatexBlock(text) {
|
|
3871
|
+
const unclosedStart = findUnclosedDelimiterStart(text, "double-only");
|
|
3872
|
+
if (unclosedStart === -1) return text;
|
|
3873
|
+
return text.substring(0, unclosedStart).trimEnd();
|
|
3874
|
+
}
|
|
3875
|
+
function escapeTextUnderscores(text) {
|
|
3876
|
+
let out = "";
|
|
3877
|
+
let i = 0;
|
|
3878
|
+
while (i < text.length) {
|
|
3879
|
+
const start = text.indexOf(TEXT_COMMAND, i);
|
|
3880
|
+
if (start === -1) {
|
|
3881
|
+
out += text.substring(i);
|
|
3882
|
+
return out;
|
|
3883
|
+
}
|
|
3884
|
+
out += text.substring(i, start);
|
|
3885
|
+
const bodyStart = start + TEXT_COMMAND.length;
|
|
3886
|
+
let depth = 1;
|
|
3887
|
+
let j = bodyStart;
|
|
3888
|
+
while (j < text.length && depth > 0) {
|
|
3889
|
+
const c = text[j];
|
|
3890
|
+
if (c === "\\" && j + 1 < text.length) {
|
|
3891
|
+
j += 2;
|
|
3892
|
+
continue;
|
|
3893
|
+
}
|
|
3894
|
+
if (c === "{") depth++;
|
|
3895
|
+
else if (c === "}") {
|
|
3896
|
+
depth--;
|
|
3897
|
+
if (depth === 0) break;
|
|
3898
|
+
}
|
|
3899
|
+
j++;
|
|
3900
|
+
}
|
|
3901
|
+
if (depth !== 0) {
|
|
3902
|
+
out += text.substring(start);
|
|
3903
|
+
return out;
|
|
3904
|
+
}
|
|
3905
|
+
const body = text.substring(bodyStart, j);
|
|
3906
|
+
const escapedBody = body.replaceAll(/(?<!\\)_/g, "\\_");
|
|
3907
|
+
out += `\\text{${escapedBody}}`;
|
|
3908
|
+
i = j + 1;
|
|
3909
|
+
}
|
|
3910
|
+
return out;
|
|
3911
|
+
}
|
|
3912
|
+
function convertSingleToDoubleDollar(text) {
|
|
3913
|
+
return text.replaceAll(SINGLE_DOLLAR_REGEX, (_match, content) => `$$${content}$$`);
|
|
3914
|
+
}
|
|
3915
|
+
function preprocessLaTeX(str) {
|
|
3916
|
+
if (!hasLatexTrigger(str)) return str;
|
|
3917
|
+
const segments = splitByProtectedRegions(str);
|
|
3918
|
+
const result = segments.map((segment) => {
|
|
3919
|
+
if (segment.isCode) return segment.text;
|
|
3920
|
+
let text = segment.text;
|
|
3921
|
+
text = escapeMhchemCommands(text);
|
|
3922
|
+
text = escapeCurrencyDollarSigns(text);
|
|
3923
|
+
text = convertLatexDelimiters(text);
|
|
3924
|
+
text = escapeLatexPipes(text);
|
|
3925
|
+
text = escapeLatexPipesInUnclosed(text);
|
|
3926
|
+
text = escapeTextUnderscores(text);
|
|
3927
|
+
text = convertSingleToDoubleDollar(text);
|
|
3928
|
+
text = truncateUnclosedLatexBlock(text);
|
|
3929
|
+
return text;
|
|
3930
|
+
});
|
|
3931
|
+
return result.join("");
|
|
3932
|
+
}
|
|
3933
|
+
function hasLatexTrigger(str) {
|
|
3934
|
+
return str.includes("$") || str.includes("\\[") || str.includes("\\(");
|
|
3935
|
+
}
|
|
3936
|
+
function hasUnclosedTextCommand(text) {
|
|
3937
|
+
let i = 0;
|
|
3938
|
+
while (i < text.length) {
|
|
3939
|
+
const start = text.indexOf(TEXT_COMMAND, i);
|
|
3940
|
+
if (start === -1) return false;
|
|
3941
|
+
let depth = 1;
|
|
3942
|
+
let j = start + TEXT_COMMAND.length;
|
|
3943
|
+
while (j < text.length && depth > 0) {
|
|
3944
|
+
const c = text[j];
|
|
3945
|
+
if (c === "\\" && j + 1 < text.length) {
|
|
3946
|
+
j += 2;
|
|
3947
|
+
continue;
|
|
3948
|
+
}
|
|
3949
|
+
if (c === "{") depth++;
|
|
3950
|
+
else if (c === "}") depth--;
|
|
3951
|
+
j++;
|
|
3952
|
+
}
|
|
3953
|
+
if (depth !== 0) return true;
|
|
3954
|
+
i = j;
|
|
3955
|
+
}
|
|
3956
|
+
return false;
|
|
3957
|
+
}
|
|
3958
|
+
var RESIDUAL_OPEN_BRACKET_RE = /(?<!!)\\\[/;
|
|
3959
|
+
function processSliceInstrumented(slice) {
|
|
3960
|
+
const segments = splitByProtectedRegions(slice);
|
|
3961
|
+
let out = "";
|
|
3962
|
+
let quiescent = true;
|
|
3963
|
+
let truncatedAtSeamStart = false;
|
|
3964
|
+
for (let index = 0; index < segments.length; index++) {
|
|
3965
|
+
const segment = segments[index];
|
|
3966
|
+
if (segment.isCode) {
|
|
3967
|
+
out += segment.text;
|
|
3968
|
+
continue;
|
|
3969
|
+
}
|
|
3970
|
+
let text = segment.text;
|
|
3971
|
+
text = escapeMhchemCommands(text);
|
|
3972
|
+
text = escapeCurrencyDollarSigns(text);
|
|
3973
|
+
text = convertLatexDelimiters(text);
|
|
3974
|
+
if (RESIDUAL_OPEN_BRACKET_RE.test(text)) quiescent = false;
|
|
3975
|
+
text = escapeLatexPipes(text);
|
|
3976
|
+
if (findUnclosedDelimiterStart(text, "both") !== -1) quiescent = false;
|
|
3977
|
+
text = escapeLatexPipesInUnclosed(text);
|
|
3978
|
+
if (hasUnclosedTextCommand(text)) quiescent = false;
|
|
3979
|
+
text = escapeTextUnderscores(text);
|
|
3980
|
+
text = convertSingleToDoubleDollar(text);
|
|
3981
|
+
const unclosedDouble = findUnclosedDelimiterStart(text, "double-only");
|
|
3982
|
+
if (unclosedDouble !== -1) {
|
|
3983
|
+
quiescent = false;
|
|
3984
|
+
if (index === 0 && text.slice(0, unclosedDouble).trim() === "") {
|
|
3985
|
+
truncatedAtSeamStart = true;
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
text = truncateUnclosedLatexBlock(text);
|
|
3989
|
+
out += text;
|
|
3990
|
+
}
|
|
3991
|
+
return { out, quiescent, truncatedAtSeamStart };
|
|
3992
|
+
}
|
|
3993
|
+
function findRawSafeCut(active) {
|
|
3994
|
+
const segments = splitByProtectedRegions(active);
|
|
3995
|
+
let offset = 0;
|
|
3996
|
+
let lastCut = -1;
|
|
3997
|
+
let backtickHazard = false;
|
|
3998
|
+
let latentLt = false;
|
|
3999
|
+
for (const segment of segments) {
|
|
4000
|
+
if (segment.isCode) {
|
|
4001
|
+
if (segment.text.includes(">")) latentLt = false;
|
|
4002
|
+
offset += segment.text.length;
|
|
4003
|
+
continue;
|
|
4004
|
+
}
|
|
4005
|
+
const text = segment.text;
|
|
4006
|
+
let lineStart = 0;
|
|
4007
|
+
while (lineStart <= text.length) {
|
|
4008
|
+
const nl = text.indexOf("\n", lineStart);
|
|
4009
|
+
const lineEnd = nl === -1 ? text.length : nl;
|
|
4010
|
+
for (let i = lineStart; i < lineEnd; i++) {
|
|
4011
|
+
const ch = text[i];
|
|
4012
|
+
if (ch === "`") backtickHazard = true;
|
|
4013
|
+
else if (ch === ">") latentLt = false;
|
|
4014
|
+
else if (ch === "<") {
|
|
4015
|
+
const next = text[i + 1];
|
|
4016
|
+
if (next !== void 0 && (next === "/" || /[A-Za-z]/.test(next))) latentLt = true;
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
if (nl === -1) break;
|
|
4020
|
+
if (!backtickHazard && !latentLt) lastCut = offset + nl + 1;
|
|
4021
|
+
lineStart = nl + 1;
|
|
4022
|
+
}
|
|
4023
|
+
offset += text.length;
|
|
4024
|
+
}
|
|
4025
|
+
return lastCut;
|
|
4026
|
+
}
|
|
4027
|
+
var DEFAULT_FREEZE_ATTEMPT_THRESHOLD = 512;
|
|
4028
|
+
function createIncrementalLatexPreprocessor(options) {
|
|
4029
|
+
const freezeThreshold = options?.freezeThreshold ?? DEFAULT_FREEZE_ATTEMPT_THRESHOLD;
|
|
4030
|
+
let prevSource = "";
|
|
4031
|
+
let prevOutput = "";
|
|
4032
|
+
let frozenSrcEnd = 0;
|
|
4033
|
+
let frozenOut = "";
|
|
4034
|
+
let triggered = false;
|
|
4035
|
+
return function incrementalPreprocessLaTeX(source) {
|
|
4036
|
+
if (source === prevSource) return prevOutput;
|
|
4037
|
+
const isAppend = source.length > prevSource.length && source.startsWith(prevSource);
|
|
4038
|
+
if (!isAppend) {
|
|
4039
|
+
frozenSrcEnd = 0;
|
|
4040
|
+
frozenOut = "";
|
|
4041
|
+
triggered = false;
|
|
4042
|
+
}
|
|
4043
|
+
if (!triggered) {
|
|
4044
|
+
const checkFrom = isAppend ? Math.max(0, prevSource.length - 1) : 0;
|
|
4045
|
+
if (!hasLatexTrigger(source.slice(checkFrom))) {
|
|
4046
|
+
prevSource = source;
|
|
4047
|
+
prevOutput = source;
|
|
4048
|
+
return source;
|
|
4049
|
+
}
|
|
4050
|
+
triggered = true;
|
|
4051
|
+
}
|
|
4052
|
+
let active = source.slice(frozenSrcEnd);
|
|
4053
|
+
if (active.length > freezeThreshold) {
|
|
4054
|
+
const cut = findRawSafeCut(active);
|
|
4055
|
+
if (cut > 0) {
|
|
4056
|
+
const candidate = processSliceInstrumented(active.slice(0, cut));
|
|
4057
|
+
if (candidate.quiescent) {
|
|
4058
|
+
frozenOut += candidate.out;
|
|
4059
|
+
frozenSrcEnd += cut;
|
|
4060
|
+
active = source.slice(frozenSrcEnd);
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
const tail = processSliceInstrumented(active);
|
|
4065
|
+
const head = tail.truncatedAtSeamStart ? frozenOut.replace(/\s+$/, "") : frozenOut;
|
|
4066
|
+
const out = head + tail.out;
|
|
4067
|
+
prevSource = source;
|
|
4068
|
+
prevOutput = out;
|
|
4069
|
+
return out;
|
|
4070
|
+
};
|
|
4071
|
+
}
|
|
4072
|
+
|
|
4073
|
+
// src/preprocessors/index.ts
|
|
4074
|
+
function applyPreprocessors(value, ...fns) {
|
|
4075
|
+
return fns.reduce((result, fn) => fn(result), value);
|
|
4076
|
+
}
|
|
4077
|
+
var defaultExtraPreprocessors = [];
|
|
4078
|
+
function preprocessAIMDContent(content, extraPreprocessors = defaultExtraPreprocessors, latexPreprocessor = preprocessLaTeX) {
|
|
4079
|
+
return applyPreprocessors(content, latexPreprocessor, ...extraPreprocessors);
|
|
4080
|
+
}
|
|
4081
|
+
|
|
4082
|
+
// src/preprocessors/remend.ts
|
|
4083
|
+
var import_remend = __toESM(require("remend"), 1);
|
|
4084
|
+
function createRemendPreprocessor(options) {
|
|
4085
|
+
return (content) => (0, import_remend.default)(content, {
|
|
4086
|
+
linkMode: "text-only",
|
|
4087
|
+
...options,
|
|
4088
|
+
katex: false,
|
|
4089
|
+
inlineKatex: false
|
|
4090
|
+
});
|
|
4091
|
+
}
|
|
4092
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4093
|
+
0 && (module.exports = {
|
|
4094
|
+
DEFAULT_PAYLOAD,
|
|
4095
|
+
DEF_LINE_START_RE,
|
|
4096
|
+
PIPELINE_STAGES,
|
|
4097
|
+
SENTINEL_FN_CONTENT,
|
|
4098
|
+
SENTINEL_LINK_URL,
|
|
4099
|
+
SMOOTH_STREAM_PACING_PRESETS,
|
|
4100
|
+
STAGE_MEASURE_PREFIX,
|
|
4101
|
+
advanceIncrementalParse,
|
|
4102
|
+
attributeHastChildren,
|
|
4103
|
+
buildCoreRehypePlugins,
|
|
4104
|
+
buildCoreRemarkPlugins,
|
|
4105
|
+
buildCoreRemarkRehypeOptions,
|
|
4106
|
+
buildCrossChunkHandlers,
|
|
4107
|
+
buildPhantomSuffix,
|
|
4108
|
+
buildTransform,
|
|
4109
|
+
codePointSnapshots,
|
|
4110
|
+
collectDefLabels,
|
|
4111
|
+
computeFreezeBoundary,
|
|
4112
|
+
createDefLabelScanner,
|
|
4113
|
+
createFile,
|
|
4114
|
+
createIncrementalLatexPreprocessor,
|
|
4115
|
+
createProcessor,
|
|
4116
|
+
createRegistry,
|
|
4117
|
+
createRemendPreprocessor,
|
|
4118
|
+
createSmoothStreamController,
|
|
4119
|
+
defaultEnginePlugins,
|
|
4120
|
+
defaultUrlTransform,
|
|
4121
|
+
definitionList,
|
|
4122
|
+
extendSanitizeSchema,
|
|
4123
|
+
extractContributions,
|
|
4124
|
+
extractDefBodiesFromHast,
|
|
4125
|
+
getEnginePluginInternals,
|
|
4126
|
+
highlight,
|
|
4127
|
+
isFootnoteSection,
|
|
4128
|
+
lastRegionStart,
|
|
4129
|
+
measureStage,
|
|
4130
|
+
mergeClassNameAllowlist,
|
|
4131
|
+
normalizeForMatch,
|
|
4132
|
+
normalizeId,
|
|
4133
|
+
pangu,
|
|
4134
|
+
parseStage,
|
|
4135
|
+
preprocessAIMDContent,
|
|
4136
|
+
preprocessLaTeX,
|
|
4137
|
+
rehypeFooterAdorn,
|
|
4138
|
+
rehypeRebaseHashLinks,
|
|
4139
|
+
removeComments,
|
|
4140
|
+
sanitizeCrossChunkUrl,
|
|
4141
|
+
sanitizeSchema,
|
|
4142
|
+
shortenDocumentId,
|
|
4143
|
+
smartypants,
|
|
4144
|
+
sourceIdFromFootnoteLiId,
|
|
4145
|
+
splitByProtectedRegions,
|
|
4146
|
+
subscribeStageTimings,
|
|
4147
|
+
transformStage,
|
|
4148
|
+
withDefs
|
|
4149
|
+
});
|
|
4150
|
+
//# sourceMappingURL=index.dev.cjs.map
|