@shllg/emend 0.1.0 → 0.2.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.
@@ -20256,6 +20256,9 @@ var LIMITS = {
20256
20256
  prefixSuffixChars: 32,
20257
20257
  diffContextLines: 3,
20258
20258
  titleChars: 200,
20259
+ headingsPerDoc: 1024,
20260
+ headingTextChars: 200,
20261
+ headingIdChars: 256,
20259
20262
  diffSideBytes: 1048576,
20260
20263
  markdownDocBytes: 1048576,
20261
20264
  htmlDocBytes: 8388608,
@@ -20422,6 +20425,15 @@ var DeviceView = external_exports.object({
20422
20425
  });
20423
20426
  var DeviceList = external_exports.object({ items: external_exports.array(DeviceView) });
20424
20427
 
20428
+ // ../../packages/contract/src/doc.ts
20429
+ var DocTitle = external_exports.string().min(1).max(LIMITS.titleChars).refine((title) => /\S/.test(title), "title must not be blank");
20430
+ var DocHeading = external_exports.object({
20431
+ level: external_exports.union([external_exports.literal(2), external_exports.literal(3)]),
20432
+ text: external_exports.string().max(LIMITS.headingTextChars),
20433
+ id: external_exports.string().min(1).max(LIMITS.headingIdChars).optional()
20434
+ });
20435
+ var DocHeadings = external_exports.array(DocHeading).max(LIMITS.headingsPerDoc);
20436
+
20425
20437
  // ../../packages/contract/src/errors.ts
20426
20438
  var ERROR_STATUS = {
20427
20439
  internal: 500,
@@ -20619,7 +20631,11 @@ var PublishManifest = external_exports.object({
20619
20631
  role: external_exports.enum(["diff", "doc"]),
20620
20632
  topic: TopicSlug.optional(),
20621
20633
  source: source.optional(),
20634
+ title: DocTitle.optional(),
20622
20635
  notes: AgentNotes.optional()
20636
+ }).refine((file2) => file2.role === "doc" || file2.title === void 0, {
20637
+ path: ["title"],
20638
+ message: "only doc files have titles"
20623
20639
  }).refine((file2) => file2.role === "diff" || file2.notes === void 0, {
20624
20640
  path: ["notes"],
20625
20641
  message: "only diff files have agent notes"
@@ -20689,6 +20705,7 @@ var ASSET_EXTENSIONS = new Set(
20689
20705
  var Sha256 = external_exports.string().length(64).regex(/^[0-9a-f]{64}$/);
20690
20706
  var PublishFile = external_exports.object({
20691
20707
  path: FilePath,
20708
+ title: DocTitle.optional(),
20692
20709
  oldPath: FilePath.nullable(),
20693
20710
  role: FileRole,
20694
20711
  status: FileStatus.optional(),
@@ -20699,6 +20716,9 @@ var PublishFile = external_exports.object({
20699
20716
  parent: FilePath.optional(),
20700
20717
  assets: external_exports.array(FilePath).max(LIMITS.filesPerRevision).optional(),
20701
20718
  notes: AgentNotes.optional()
20719
+ }).refine((file2) => file2.role === "doc" || file2.title === void 0, {
20720
+ path: ["title"],
20721
+ message: "only doc files have titles"
20702
20722
  }).refine((file2) => file2.role === "diff" || file2.notes === void 0, {
20703
20723
  path: ["notes"],
20704
20724
  message: "only diff files have agent notes"
@@ -20896,6 +20916,7 @@ var ImportRows = external_exports.object({
20896
20916
  oldBlob: Sha256.nullable(),
20897
20917
  newBlob: Sha256.nullable(),
20898
20918
  renderedBlob: Sha256.nullable(),
20919
+ title: DocTitle.nullable().optional(),
20899
20920
  flag: FileFlag.nullable(),
20900
20921
  parentDocId: id.nullable()
20901
20922
  })
@@ -21202,12 +21223,20 @@ var RevisionView = external_exports.object({
21202
21223
  external_exports.object({
21203
21224
  path: FilePath,
21204
21225
  kind: external_exports.literal("markdown"),
21226
+ title: DocTitle.optional(),
21227
+ headings: DocHeadings.optional(),
21205
21228
  blocks: external_exports.array(RenderedBlock).max(LIMITS.blocksPerRevision).refine(
21206
21229
  (blocks) => renderedBytes(blocks) <= LIMITS.renderedBytesPerRevision,
21207
21230
  "doc exceeds the rendered JSON byte budget"
21208
21231
  )
21209
21232
  }),
21210
- external_exports.object({ path: FilePath, kind: external_exports.literal("html"), contentUrl })
21233
+ external_exports.object({
21234
+ path: FilePath,
21235
+ kind: external_exports.literal("html"),
21236
+ contentUrl,
21237
+ title: DocTitle.optional(),
21238
+ headings: DocHeadings.optional()
21239
+ })
21211
21240
  ])
21212
21241
  ).max(LIMITS.filesPerRevision),
21213
21242
  threads: external_exports.array(ThreadView),
@@ -21218,6 +21247,8 @@ var RevisionView = external_exports.object({
21218
21247
  ).refine((view) => {
21219
21248
  let bytes = renderedBytes(view.writeup);
21220
21249
  for (const doc of view.docs) {
21250
+ if (doc.title !== void 0 || doc.headings !== void 0)
21251
+ bytes += renderedBytes({ title: doc.title, headings: doc.headings });
21221
21252
  if (doc.kind === "markdown" && doc.blocks.length) bytes += renderedBytes(doc.blocks);
21222
21253
  if (bytes > LIMITS.renderedBytesPerRevision) return false;
21223
21254
  }
@@ -31951,32 +31982,6 @@ function visualizeCharacterCode(charCode) {
31951
31982
  return "0x" + charCode.toString(16).toUpperCase();
31952
31983
  }
31953
31984
 
31954
- // ../../node_modules/.pnpm/hast-util-to-string@3.0.1/node_modules/hast-util-to-string/lib/index.js
31955
- function toString(node3) {
31956
- if ("children" in node3) {
31957
- return all2(node3);
31958
- }
31959
- return "value" in node3 ? node3.value : "";
31960
- }
31961
- function one2(node3) {
31962
- if (node3.type === "text") {
31963
- return node3.value;
31964
- }
31965
- return "children" in node3 ? all2(node3) : "";
31966
- }
31967
- function all2(node3) {
31968
- let index2 = -1;
31969
- const result = [];
31970
- while (++index2 < node3.children.length) {
31971
- result[index2] = one2(node3.children[index2]);
31972
- }
31973
- return result.join("");
31974
- }
31975
-
31976
- // ../../packages/core/src/doc-title.ts
31977
- var TITLE_PREFIX_BYTES = 64 * 1024;
31978
- var TITLE_CANDIDATE_CHARS = LIMITS.titleChars * 4;
31979
-
31980
31985
  // ../../packages/core/src/render/normalize.ts
31981
31986
  function normalizeText(text10) {
31982
31987
  return text10.normalize("NFC").replace(/[\p{White_Space}]+/gu, " ").trim();
@@ -32042,10 +32047,10 @@ var omitted = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"
32042
32047
  var HTML_NESTING_LIMIT = 512;
32043
32048
  var HtmlNestingLimitError = class extends Error {
32044
32049
  };
32045
- function docText(html7) {
32050
+ function parseDocHtml(html7) {
32046
32051
  try {
32047
32052
  let openElements = 0;
32048
- const tree = parse5(html7, {
32053
+ return parse5(html7, {
32049
32054
  scriptingEnabled: true,
32050
32055
  treeAdapter: {
32051
32056
  ...defaultTreeAdapter,
@@ -32057,21 +32062,47 @@ function docText(html7) {
32057
32062
  }
32058
32063
  }
32059
32064
  });
32060
- const document3 = tree.childNodes.find((node3) => defaultTreeAdapter.isElementNode(node3) && node3.tagName === "html");
32061
- const body3 = document3 && defaultTreeAdapter.isElementNode(document3) ? document3.childNodes.find((node3) => defaultTreeAdapter.isElementNode(node3) && node3.tagName === "body") : void 0;
32062
- if (!body3) return "";
32063
- const parts = [];
32064
- const pending = [body3];
32065
- for (let node3 = pending.pop(); node3 !== void 0; node3 = pending.pop()) {
32066
- if (defaultTreeAdapter.isTextNode(node3)) parts.push(node3.value);
32067
- else if (defaultTreeAdapter.isElementNode(node3) && !omitted.has(node3.tagName)) {
32068
- for (let index2 = node3.childNodes.length - 1; index2 >= 0; index2--) {
32069
- const child = node3.childNodes[index2];
32070
- if (child) pending.push(child);
32071
- }
32072
- }
32065
+ } catch {
32066
+ return null;
32067
+ }
32068
+ }
32069
+ function htmlPart(tree, tag) {
32070
+ const root7 = tree.childNodes.find((node3) => defaultTreeAdapter.isElementNode(node3) && node3.tagName === "html");
32071
+ return root7 && defaultTreeAdapter.isElementNode(root7) ? root7.childNodes.find((node3) => defaultTreeAdapter.isElementNode(node3) && node3.tagName === tag) : void 0;
32072
+ }
32073
+ function* docNodes(root7, nodeLimit = Infinity) {
32074
+ const pending = [[root7][Symbol.iterator]()];
32075
+ while (pending.length) {
32076
+ const next2 = pending.at(-1)?.next();
32077
+ if (!next2 || next2.done) {
32078
+ pending.pop();
32079
+ continue;
32073
32080
  }
32074
- return normalizeText(parts.join(""));
32081
+ if (nodeLimit-- <= 0) return;
32082
+ const node3 = next2.value;
32083
+ if (defaultTreeAdapter.isElementNode(node3) && omitted.has(node3.tagName)) continue;
32084
+ yield node3;
32085
+ if (defaultTreeAdapter.isElementNode(node3)) pending.push(node3.childNodes[Symbol.iterator]());
32086
+ }
32087
+ }
32088
+ function nodeText(root7, limit = Infinity) {
32089
+ const parts = [];
32090
+ if (limit <= 0) return "";
32091
+ for (const node3 of docNodes(root7, 8 * limit)) {
32092
+ if (!defaultTreeAdapter.isTextNode(node3)) continue;
32093
+ const part = node3.value.slice(0, limit);
32094
+ parts.push(part);
32095
+ limit -= part.length;
32096
+ if (limit <= 0) break;
32097
+ }
32098
+ return parts.join("");
32099
+ }
32100
+ function docText(html7) {
32101
+ try {
32102
+ const tree = parseDocHtml(html7);
32103
+ if (!tree) return null;
32104
+ const body3 = htmlPart(tree, "body");
32105
+ return body3 ? normalizeText(nodeText(body3)) : "";
32075
32106
  } catch {
32076
32107
  return null;
32077
32108
  }
@@ -32086,890 +32117,302 @@ function placeHtmlSpan(text10, target) {
32086
32117
  return { status: "unplaced", reason: candidates.length > 1 ? "ambiguous" : "block-gone" };
32087
32118
  }
32088
32119
 
32089
- // ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/base.js
32090
- var Diff = class {
32091
- diff(oldStr, newStr, options = {}) {
32092
- let callback;
32093
- if (typeof options === "function") {
32094
- callback = options;
32095
- options = {};
32096
- } else if ("callback" in options) {
32097
- callback = options.callback;
32098
- }
32099
- const oldString = this.castInput(oldStr, options);
32100
- const newString = this.castInput(newStr, options);
32101
- const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
32102
- const newTokens = this.removeEmpty(this.tokenize(newString, options));
32103
- return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
32120
+ // ../../node_modules/.pnpm/@shikijs+types@4.5.0/node_modules/@shikijs/types/dist/index.mjs
32121
+ var ShikiError = class extends Error {
32122
+ constructor(message) {
32123
+ super(message);
32124
+ this.name = "ShikiError";
32104
32125
  }
32105
- diffWithOptionsObj(oldTokens, newTokens, options, callback) {
32106
- var _a4;
32107
- const done = (value) => {
32108
- value = this.postProcess(value, options);
32109
- if (callback) {
32110
- setTimeout(function() {
32111
- callback(value);
32112
- }, 0);
32113
- return void 0;
32114
- } else {
32115
- return value;
32116
- }
32117
- };
32118
- const newLen = newTokens.length, oldLen = oldTokens.length;
32119
- let editLength = 1;
32120
- let maxEditLength = newLen + oldLen;
32121
- if (options.maxEditLength != null) {
32122
- maxEditLength = Math.min(maxEditLength, options.maxEditLength);
32126
+ };
32127
+
32128
+ // ../../node_modules/.pnpm/@shikijs+vscode-textmate@10.1.0/node_modules/@shikijs/vscode-textmate/dist/index.js
32129
+ function clone2(something) {
32130
+ return doClone(something);
32131
+ }
32132
+ function doClone(something) {
32133
+ if (Array.isArray(something)) {
32134
+ return cloneArray(something);
32135
+ }
32136
+ if (something instanceof RegExp) {
32137
+ return something;
32138
+ }
32139
+ if (typeof something === "object") {
32140
+ return cloneObj(something);
32141
+ }
32142
+ return something;
32143
+ }
32144
+ function cloneArray(arr) {
32145
+ let r4 = [];
32146
+ for (let i2 = 0, len = arr.length; i2 < len; i2++) {
32147
+ r4[i2] = doClone(arr[i2]);
32148
+ }
32149
+ return r4;
32150
+ }
32151
+ function cloneObj(obj) {
32152
+ let r4 = {};
32153
+ for (let key2 in obj) {
32154
+ r4[key2] = doClone(obj[key2]);
32155
+ }
32156
+ return r4;
32157
+ }
32158
+ function mergeObjects(target, ...sources) {
32159
+ sources.forEach((source2) => {
32160
+ for (let key2 in source2) {
32161
+ target[key2] = source2[key2];
32123
32162
  }
32124
- const maxExecutionTime = (_a4 = options.timeout) !== null && _a4 !== void 0 ? _a4 : Infinity;
32125
- const abortAfterTimestamp = Date.now() + maxExecutionTime;
32126
- const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
32127
- let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
32128
- if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
32129
- return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
32163
+ });
32164
+ return target;
32165
+ }
32166
+ function basename(path2) {
32167
+ const idx = ~path2.lastIndexOf("/") || ~path2.lastIndexOf("\\");
32168
+ if (idx === 0) {
32169
+ return path2;
32170
+ } else if (~idx === path2.length - 1) {
32171
+ return basename(path2.substring(0, path2.length - 1));
32172
+ } else {
32173
+ return path2.substr(~idx + 1);
32174
+ }
32175
+ }
32176
+ var CAPTURING_REGEX_SOURCE = /\$(\d+)|\${(\d+):\/(downcase|upcase)}/g;
32177
+ var RegexSource = class {
32178
+ static hasCaptures(regexSource) {
32179
+ if (regexSource === null) {
32180
+ return false;
32130
32181
  }
32131
- let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
32132
- const execEditLength = () => {
32133
- for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
32134
- let basePath;
32135
- const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
32136
- if (removePath) {
32137
- bestPath[diagonalPath - 1] = void 0;
32138
- }
32139
- let canAdd = false;
32140
- if (addPath) {
32141
- const addPathNewPos = addPath.oldPos - diagonalPath;
32142
- canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
32143
- }
32144
- const canRemove = removePath && removePath.oldPos + 1 < oldLen;
32145
- if (!canAdd && !canRemove) {
32146
- bestPath[diagonalPath] = void 0;
32147
- continue;
32148
- }
32149
- if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
32150
- basePath = this.addToPath(addPath, true, false, 0, options);
32151
- } else {
32152
- basePath = this.addToPath(removePath, false, true, 1, options);
32182
+ CAPTURING_REGEX_SOURCE.lastIndex = 0;
32183
+ return CAPTURING_REGEX_SOURCE.test(regexSource);
32184
+ }
32185
+ static replaceCaptures(regexSource, captureSource, captureIndices) {
32186
+ return regexSource.replace(CAPTURING_REGEX_SOURCE, (match, index2, commandIndex, command) => {
32187
+ let capture = captureIndices[parseInt(index2 || commandIndex, 10)];
32188
+ if (capture) {
32189
+ let result = captureSource.substring(capture.start, capture.end);
32190
+ while (result[0] === ".") {
32191
+ result = result.substring(1);
32153
32192
  }
32154
- newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
32155
- if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
32156
- return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
32157
- } else {
32158
- bestPath[diagonalPath] = basePath;
32159
- if (basePath.oldPos + 1 >= oldLen) {
32160
- maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
32161
- }
32162
- if (newPos + 1 >= newLen) {
32163
- minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
32164
- }
32193
+ switch (command) {
32194
+ case "downcase":
32195
+ return result.toLowerCase();
32196
+ case "upcase":
32197
+ return result.toUpperCase();
32198
+ default:
32199
+ return result;
32165
32200
  }
32201
+ } else {
32202
+ return match;
32166
32203
  }
32167
- editLength++;
32168
- };
32169
- if (callback) {
32170
- (function exec() {
32171
- setTimeout(function() {
32172
- if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
32173
- return callback(void 0);
32174
- }
32175
- if (!execEditLength()) {
32176
- exec();
32177
- }
32178
- }, 0);
32179
- })();
32180
- } else {
32181
- while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
32182
- const ret = execEditLength();
32183
- if (ret) {
32184
- return ret;
32185
- }
32204
+ });
32205
+ }
32206
+ };
32207
+ function strcmp(a2, b3) {
32208
+ if (a2 < b3) {
32209
+ return -1;
32210
+ }
32211
+ if (a2 > b3) {
32212
+ return 1;
32213
+ }
32214
+ return 0;
32215
+ }
32216
+ function strArrCmp(a2, b3) {
32217
+ if (a2 === null && b3 === null) {
32218
+ return 0;
32219
+ }
32220
+ if (!a2) {
32221
+ return -1;
32222
+ }
32223
+ if (!b3) {
32224
+ return 1;
32225
+ }
32226
+ let len1 = a2.length;
32227
+ let len2 = b3.length;
32228
+ if (len1 === len2) {
32229
+ for (let i2 = 0; i2 < len1; i2++) {
32230
+ let res = strcmp(a2[i2], b3[i2]);
32231
+ if (res !== 0) {
32232
+ return res;
32186
32233
  }
32187
32234
  }
32235
+ return 0;
32188
32236
  }
32189
- addToPath(path2, added, removed, oldPosInc, options) {
32190
- const last = path2.lastComponent;
32191
- if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
32192
- return {
32193
- oldPos: path2.oldPos + oldPosInc,
32194
- lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
32195
- };
32196
- } else {
32197
- return {
32198
- oldPos: path2.oldPos + oldPosInc,
32199
- lastComponent: { count: 1, added, removed, previousComponent: last }
32200
- };
32237
+ return len1 - len2;
32238
+ }
32239
+ function isValidHexColor(hex3) {
32240
+ if (/^#[0-9a-f]{6}$/i.test(hex3)) {
32241
+ return true;
32242
+ }
32243
+ if (/^#[0-9a-f]{8}$/i.test(hex3)) {
32244
+ return true;
32245
+ }
32246
+ if (/^#[0-9a-f]{3}$/i.test(hex3)) {
32247
+ return true;
32248
+ }
32249
+ if (/^#[0-9a-f]{4}$/i.test(hex3)) {
32250
+ return true;
32251
+ }
32252
+ return false;
32253
+ }
32254
+ function escapeRegExpCharacters(value) {
32255
+ return value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, "\\$&");
32256
+ }
32257
+ var CachedFn = class {
32258
+ constructor(fn) {
32259
+ this.fn = fn;
32260
+ }
32261
+ fn;
32262
+ cache = /* @__PURE__ */ new Map();
32263
+ get(key2) {
32264
+ if (this.cache.has(key2)) {
32265
+ return this.cache.get(key2);
32201
32266
  }
32267
+ const value = this.fn(key2);
32268
+ this.cache.set(key2, value);
32269
+ return value;
32202
32270
  }
32203
- extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
32204
- const newLen = newTokens.length, oldLen = oldTokens.length;
32205
- let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
32206
- while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
32207
- newPos++;
32208
- oldPos++;
32209
- commonCount++;
32210
- if (options.oneChangePerToken) {
32211
- basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
32212
- }
32271
+ };
32272
+ var Theme = class {
32273
+ constructor(_colorMap, _defaults, _root) {
32274
+ this._colorMap = _colorMap;
32275
+ this._defaults = _defaults;
32276
+ this._root = _root;
32277
+ }
32278
+ _colorMap;
32279
+ _defaults;
32280
+ _root;
32281
+ static createFromRawTheme(source2, colorMap) {
32282
+ return this.createFromParsedTheme(parseTheme(source2), colorMap);
32283
+ }
32284
+ static createFromParsedTheme(source2, colorMap) {
32285
+ return resolveParsedThemeRules(source2, colorMap);
32286
+ }
32287
+ _cachedMatchRoot = new CachedFn(
32288
+ (scopeName) => this._root.match(scopeName)
32289
+ );
32290
+ getColorMap() {
32291
+ return this._colorMap.getColorMap();
32292
+ }
32293
+ getDefaults() {
32294
+ return this._defaults;
32295
+ }
32296
+ match(scopePath) {
32297
+ if (scopePath === null) {
32298
+ return this._defaults;
32213
32299
  }
32214
- if (commonCount && !options.oneChangePerToken) {
32215
- basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
32300
+ const scopeName = scopePath.scopeName;
32301
+ const matchingTrieElements = this._cachedMatchRoot.get(scopeName);
32302
+ const effectiveRule = matchingTrieElements.find(
32303
+ (v2) => _scopePathMatchesParentScopes(scopePath.parent, v2.parentScopes)
32304
+ );
32305
+ if (!effectiveRule) {
32306
+ return null;
32216
32307
  }
32217
- basePath.oldPos = oldPos;
32218
- return newPos;
32308
+ return new StyleAttributes(
32309
+ effectiveRule.fontStyle,
32310
+ effectiveRule.foreground,
32311
+ effectiveRule.background
32312
+ );
32219
32313
  }
32220
- equals(left, right, options) {
32221
- if (options.comparator) {
32222
- return options.comparator(left, right);
32223
- } else {
32224
- return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
32225
- }
32314
+ };
32315
+ var ScopeStack = class _ScopeStack {
32316
+ constructor(parent, scopeName) {
32317
+ this.parent = parent;
32318
+ this.scopeName = scopeName;
32226
32319
  }
32227
- removeEmpty(array2) {
32228
- const ret = [];
32229
- for (let i2 = 0; i2 < array2.length; i2++) {
32230
- if (array2[i2]) {
32231
- ret.push(array2[i2]);
32232
- }
32320
+ parent;
32321
+ scopeName;
32322
+ static push(path2, scopeNames) {
32323
+ for (const name of scopeNames) {
32324
+ path2 = new _ScopeStack(path2, name);
32233
32325
  }
32234
- return ret;
32235
- }
32236
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32237
- castInput(value, options) {
32238
- return value;
32326
+ return path2;
32239
32327
  }
32240
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32241
- tokenize(value, options) {
32242
- return Array.from(value);
32328
+ static from(...segments) {
32329
+ let result = null;
32330
+ for (let i2 = 0; i2 < segments.length; i2++) {
32331
+ result = new _ScopeStack(result, segments[i2]);
32332
+ }
32333
+ return result;
32243
32334
  }
32244
- join(chars) {
32245
- return chars.join("");
32335
+ push(scopeName) {
32336
+ return new _ScopeStack(this, scopeName);
32246
32337
  }
32247
- postProcess(changeObjects, options) {
32248
- return changeObjects;
32338
+ getSegments() {
32339
+ let item = this;
32340
+ const result = [];
32341
+ while (item) {
32342
+ result.push(item.scopeName);
32343
+ item = item.parent;
32344
+ }
32345
+ result.reverse();
32346
+ return result;
32249
32347
  }
32250
- get useLongestToken() {
32251
- return false;
32348
+ toString() {
32349
+ return this.getSegments().join(" ");
32252
32350
  }
32253
- buildValues(lastComponent, newTokens, oldTokens) {
32254
- const components = [];
32255
- let nextComponent;
32256
- while (lastComponent) {
32257
- components.push(lastComponent);
32258
- nextComponent = lastComponent.previousComponent;
32259
- delete lastComponent.previousComponent;
32260
- lastComponent = nextComponent;
32351
+ extends(other) {
32352
+ if (this === other) {
32353
+ return true;
32261
32354
  }
32262
- components.reverse();
32263
- const componentLen = components.length;
32264
- let componentPos = 0, newPos = 0, oldPos = 0;
32265
- for (; componentPos < componentLen; componentPos++) {
32266
- const component = components[componentPos];
32267
- if (!component.removed) {
32268
- if (!component.added && this.useLongestToken) {
32269
- let value = newTokens.slice(newPos, newPos + component.count);
32270
- value = value.map(function(value2, i2) {
32271
- const oldValue = oldTokens[oldPos + i2];
32272
- return oldValue.length > value2.length ? oldValue : value2;
32273
- });
32274
- component.value = this.join(value);
32275
- } else {
32276
- component.value = this.join(newTokens.slice(newPos, newPos + component.count));
32277
- }
32278
- newPos += component.count;
32279
- if (!component.added) {
32280
- oldPos += component.count;
32281
- }
32282
- } else {
32283
- component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
32284
- oldPos += component.count;
32285
- }
32355
+ if (this.parent === null) {
32356
+ return false;
32286
32357
  }
32287
- return components;
32358
+ return this.parent.extends(other);
32359
+ }
32360
+ getExtensionIfDefined(base2) {
32361
+ const result = [];
32362
+ let item = this;
32363
+ while (item && item !== base2) {
32364
+ result.push(item.scopeName);
32365
+ item = item.parent;
32366
+ }
32367
+ return item === base2 ? result.reverse() : void 0;
32288
32368
  }
32289
32369
  };
32290
-
32291
- // ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/line.js
32292
- var LineDiff = class extends Diff {
32293
- constructor() {
32294
- super(...arguments);
32295
- this.tokenize = tokenize;
32370
+ function _scopePathMatchesParentScopes(scopePath, parentScopes) {
32371
+ if (parentScopes.length === 0) {
32372
+ return true;
32296
32373
  }
32297
- equals(left, right, options) {
32298
- if (options.ignoreWhitespace) {
32299
- if (!options.newlineIsToken || !left.includes("\n")) {
32300
- left = left.trim();
32301
- }
32302
- if (!options.newlineIsToken || !right.includes("\n")) {
32303
- right = right.trim();
32374
+ for (let index2 = 0; index2 < parentScopes.length; index2++) {
32375
+ let scopePattern = parentScopes[index2];
32376
+ let scopeMustMatch = false;
32377
+ if (scopePattern === ">") {
32378
+ if (index2 === parentScopes.length - 1) {
32379
+ return false;
32304
32380
  }
32305
- } else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
32306
- if (left.endsWith("\n")) {
32307
- left = left.slice(0, -1);
32381
+ scopePattern = parentScopes[++index2];
32382
+ scopeMustMatch = true;
32383
+ }
32384
+ while (scopePath) {
32385
+ if (_matchesScope(scopePath.scopeName, scopePattern)) {
32386
+ break;
32308
32387
  }
32309
- if (right.endsWith("\n")) {
32310
- right = right.slice(0, -1);
32388
+ if (scopeMustMatch) {
32389
+ return false;
32311
32390
  }
32391
+ scopePath = scopePath.parent;
32312
32392
  }
32313
- return super.equals(left, right, options);
32393
+ if (!scopePath) {
32394
+ return false;
32395
+ }
32396
+ scopePath = scopePath.parent;
32314
32397
  }
32315
- };
32316
- var lineDiff = new LineDiff();
32317
- function diffLines(oldStr, newStr, options) {
32318
- return lineDiff.diff(oldStr, newStr, options);
32398
+ return true;
32319
32399
  }
32320
- function tokenize(value, options) {
32321
- if (options.stripTrailingCr) {
32322
- value = value.replace(/\r\n/g, "\n");
32400
+ function _matchesScope(scopeName, scopePattern) {
32401
+ return scopePattern === scopeName || scopeName.startsWith(scopePattern) && scopeName[scopePattern.length] === ".";
32402
+ }
32403
+ var StyleAttributes = class {
32404
+ constructor(fontStyle, foregroundId, backgroundId) {
32405
+ this.fontStyle = fontStyle;
32406
+ this.foregroundId = foregroundId;
32407
+ this.backgroundId = backgroundId;
32323
32408
  }
32324
- const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
32325
- if (!linesAndNewlines[linesAndNewlines.length - 1]) {
32326
- linesAndNewlines.pop();
32327
- }
32328
- for (let i2 = 0; i2 < linesAndNewlines.length; i2++) {
32329
- const line = linesAndNewlines[i2];
32330
- if (i2 % 2 && !options.newlineIsToken) {
32331
- retLines[retLines.length - 1] += line;
32332
- } else {
32333
- retLines.push(line);
32334
- }
32335
- }
32336
- return retLines;
32337
- }
32338
-
32339
- // ../../packages/core/src/place/linemap.ts
32340
- var LINE_MAP_MAX_EDIT_LENGTH = 256;
32341
- function splitLines(text10) {
32342
- if (text10 === "") return [];
32343
- const lines = text10.replace(/\r\n/g, "\n").split("\n");
32344
- if (lines.at(-1) === "") lines.pop();
32345
- return lines;
32346
- }
32347
- function lineMap(from, to) {
32348
- const mapped = [];
32349
- let oldLine = 1;
32350
- let newLine = 1;
32351
- const changes = diffLines(from, to, {
32352
- stripTrailingCr: true,
32353
- ignoreNewlineAtEof: true,
32354
- maxEditLength: LINE_MAP_MAX_EDIT_LENGTH
32355
- });
32356
- if (changes === void 0) return () => null;
32357
- for (const change of changes) {
32358
- if (change.added) newLine += change.count;
32359
- else {
32360
- for (let index2 = 0; index2 < change.count; index2++) {
32361
- mapped[oldLine++] = change.removed ? null : newLine++;
32362
- }
32363
- }
32364
- }
32365
- return (line) => Number.isInteger(line) && line > 0 ? mapped[line] ?? null : null;
32366
- }
32367
-
32368
- // ../../packages/core/src/place/lines.ts
32369
- function matches(lines, start, quote) {
32370
- return start >= 0 && start + quote.length <= lines.length && quote.every((line, index2) => lines[start + index2] === line);
32371
- }
32372
- function placeLines(target, last, next2) {
32373
- if (next2 === null) return { status: "unplaced", reason: "file-gone" };
32374
- const hashKey = target.side === "old" ? "oldHash" : "newHash";
32375
- const textKey = target.side === "old" ? "oldText" : "newText";
32376
- const previousText = last.sides[textKey];
32377
- const nextText = next2[textKey];
32378
- if (nextText === void 0) return { status: "unplaced", reason: "file-gone" };
32379
- const lines = splitLines(nextText);
32380
- const placed = (start2) => ({
32381
- status: "placed",
32382
- location: { kind: "lines", path: target.path, side: target.side, start: start2, end: start2 + target.lines.length - 1 }
32383
- });
32384
- const validRange = last.start > 0 && last.end - last.start + 1 === target.lines.length;
32385
- if (validRange && last.sides[hashKey] !== void 0 && last.sides[hashKey] === next2[hashKey] && matches(lines, last.start - 1, target.lines))
32386
- return placed(last.start);
32387
- if (validRange && previousText !== void 0) {
32388
- const map4 = lineMap(previousText, nextText);
32389
- const start2 = map4(last.start);
32390
- if (start2 !== null && target.lines.every((_3, index2) => map4(last.start + index2) === start2 + index2) && matches(lines, start2 - 1, target.lines))
32391
- return placed(start2);
32392
- }
32393
- const sequence = [...target.before, ...target.lines, ...target.after];
32394
- const found = firstTwoMatches(lines, sequence);
32395
- if (found.length > 1) return { status: "unplaced", reason: "ambiguous" };
32396
- const start = found[0];
32397
- return start === void 0 ? { status: "unplaced", reason: "lines-gone" } : placed(start + target.before.length + 1);
32398
- }
32399
-
32400
- // ../../packages/core/src/place/place.ts
32401
- function placeThread(target, ctx) {
32402
- const last = ctx.last?.location;
32403
- switch (target.kind) {
32404
- case "review":
32405
- return { status: "placed", location: { kind: "review" } };
32406
- case "topic":
32407
- return ctx.topics.has(target.slug) ? { status: "placed", location: { kind: "topic", slug: target.slug } } : { status: "unplaced", reason: "topic-gone" };
32408
- case "writeup-span":
32409
- return placeSpan(ctx.writeup, {
32410
- ...target,
32411
- blockId: last?.kind === "writeup-span" ? last.blockId : target.blockId
32412
- });
32413
- default: {
32414
- const previousPath = last?.kind === target.kind && "path" in last ? last.path : target.path;
32415
- const renamed = ctx.renamedFrom.get(previousPath);
32416
- if (renamed === null) return { status: "unplaced", reason: "file-gone" };
32417
- const path2 = renamed ?? previousPath;
32418
- if (target.kind === "file") {
32419
- return ctx.files.has(path2) ? { status: "placed", location: { kind: "file", path: path2 } } : { status: "unplaced", reason: "file-gone" };
32420
- }
32421
- if (target.kind === "lines") {
32422
- const previous3 = last?.kind === "lines" && last.side === target.side ? last : target;
32423
- return placeLines(
32424
- { ...target, path: path2 },
32425
- {
32426
- start: previous3.start,
32427
- end: previous3.end,
32428
- sides: ctx.last?.sides ?? {}
32429
- },
32430
- ctx.files.get(path2) ?? null
32431
- );
32432
- }
32433
- const doc = ctx.docs.get(path2);
32434
- if (!doc) return { status: "unplaced", reason: "file-gone" };
32435
- if (target.kind === "html-span") {
32436
- return doc.kind === "html" ? placeHtmlSpan(doc.text, { ...target, path: path2 }) : { status: "unplaced", reason: "block-gone" };
32437
- }
32438
- return doc.kind === "markdown" ? placeSpan(doc.blocks, { ...target, path: path2, blockId: last?.kind === "doc-span" ? last.blockId : target.blockId }) : { status: "unplaced", reason: "block-gone" };
32439
- }
32440
- }
32441
- }
32442
-
32443
- // ../../packages/core/src/place/renames.ts
32444
- function composeRenames(steps) {
32445
- const composed = /* @__PURE__ */ new Map();
32446
- for (let index2 = steps.length - 1; index2 >= 0; index2--) {
32447
- const step = steps[index2];
32448
- if (!step) continue;
32449
- const pending = [];
32450
- for (const [from, to] of step) {
32451
- const next2 = to === null ? null : composed.get(to);
32452
- pending.push([from, next2 === void 0 ? to : next2]);
32453
- }
32454
- for (const [from, to] of pending) composed.set(from, to);
32455
- }
32456
- return composed;
32457
- }
32458
-
32459
- // ../../packages/core/src/render/hash.ts
32460
- async function blockHash(text10) {
32461
- const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(text10));
32462
- return Array.from(new Uint8Array(digest).subarray(0, 4), (byte) => byte.toString(16).padStart(2, "0")).join("");
32463
- }
32464
-
32465
- // ../../packages/core/src/render/blocks.ts
32466
- var sectionBlockId = (section, identity) => `${section}-${identity}`;
32467
- function resectionBlocks(blocks, section) {
32468
- return blocks.map((block) => ({
32469
- ...block,
32470
- section,
32471
- id: sectionBlockId(section, block.id.slice(block.section.length + 1))
32472
- }));
32473
- }
32474
- function renderData(element6) {
32475
- element6.data ??= { position: {} };
32476
- return element6.data;
32477
- }
32478
- function blockText(html7) {
32479
- return toString(fromHtml(html7, { fragment: true }));
32480
- }
32481
- function visitElements(node3, visit3) {
32482
- if (node3.type === "element") visit3(node3);
32483
- if ("children" in node3) for (const child of node3.children) visitElements(child, visit3);
32484
- }
32485
- var MAX_BLOCK_DEPTH = 64;
32486
- var blockTags = /* @__PURE__ */ new Set([
32487
- "blockquote",
32488
- "dd",
32489
- "details",
32490
- "div",
32491
- "dl",
32492
- "dt",
32493
- "h1",
32494
- "h2",
32495
- "h3",
32496
- "h4",
32497
- "h5",
32498
- "h6",
32499
- "hr",
32500
- "li",
32501
- "ol",
32502
- "p",
32503
- "pre",
32504
- "section",
32505
- "summary",
32506
- "table",
32507
- "ul"
32508
- ]);
32509
- function hasBlockChildren(node3) {
32510
- return "children" in node3 && node3.children.some((child) => child.type === "element" && (blockTags.has(child.tagName) || hasBlockChildren(child)));
32511
- }
32512
- function isDiagram(node3) {
32513
- return node3.type === "element" && renderData(node3).emendDiagram !== void 0;
32514
- }
32515
- function hasDiagram(node3) {
32516
- return isDiagram(node3) || "children" in node3 && node3.children.some(hasDiagram);
32517
- }
32518
- function hasContent(nodes) {
32519
- return nodes.some((node3) => node3.type === "element" || node3.type === "text" && normalizeText(node3.value) !== "");
32520
- }
32521
- function* divideAtDiagrams(node3) {
32522
- if (isDiagram(node3) || !hasDiagram(node3)) {
32523
- yield node3;
32524
- return;
32525
- }
32526
- let children2 = [];
32527
- for (const child of node3.children) {
32528
- if (child.type !== "element") {
32529
- children2.push(child);
32530
- continue;
32531
- }
32532
- for (const piece of divideAtDiagrams(child)) {
32533
- if (isDiagram(piece)) {
32534
- if (hasContent(children2)) yield { ...node3, children: children2 };
32535
- children2 = [];
32536
- yield piece;
32537
- } else children2.push(piece);
32538
- }
32539
- }
32540
- if (hasContent(children2)) yield { ...node3, children: children2 };
32541
- }
32542
- function* atomicBlock(kind, node3) {
32543
- for (const piece of divideAtDiagrams(node3)) {
32544
- const source2 = renderData(piece).emendDiagram;
32545
- yield source2 === void 0 ? { kind, node: piece } : { kind: "diagram", node: piece, source: source2 };
32546
- }
32547
- }
32548
- function flattenRoots(node3) {
32549
- if (node3.type === "root") {
32550
- return node3.children.flatMap(flattenRoots);
32551
- }
32552
- if (node3.type === "element") {
32553
- node3.children = node3.children.flatMap(flattenRoots).filter((child) => child.type !== "doctype");
32554
- }
32555
- return [node3];
32556
- }
32557
- function* splitChildren(children2, depth) {
32558
- let inline = [];
32559
- for (const child of children2) {
32560
- if (child.type === "element" && (blockTags.has(child.tagName) || hasBlockChildren(child) || hasDiagram(child))) {
32561
- if (hasContent(inline)) yield { kind: "paragraph", node: { type: "root", children: inline } };
32562
- inline = [];
32563
- yield* splitBlocks(child, depth);
32564
- } else if (child.type !== "comment" && child.type !== "doctype") inline.push(child);
32565
- }
32566
- if (hasContent(inline)) yield { kind: "paragraph", node: { type: "root", children: inline } };
32567
- }
32568
- function blockKind(tag) {
32569
- if (/^h[1-6]$/.test(tag)) return "heading";
32570
- if (tag === "li" || tag === "dt" || tag === "dd") return "item";
32571
- if (tag === "pre") return "code";
32572
- if (tag === "table") return "table";
32573
- if (tag === "blockquote") return "quote";
32574
- return "paragraph";
32575
- }
32576
- function* strayListContent(children2, depth) {
32577
- for (const fragment2 of splitChildren(children2, depth)) {
32578
- yield fragment2.kind === "diagram" ? fragment2 : { ...fragment2, kind: "paragraph" };
32579
- }
32580
- }
32581
- function* splitBlocks(node3, depth = 0) {
32582
- if (node3.type === "root") {
32583
- yield* splitChildren(node3.children, depth + 1);
32584
- return;
32585
- }
32586
- if (node3.type !== "element") return;
32587
- const source2 = renderData(node3).emendDiagram;
32588
- if (source2 !== void 0) {
32589
- yield { kind: "diagram", node: node3, source: source2 };
32590
- return;
32591
- }
32592
- const tag = node3.tagName;
32593
- if (tag === "hr") return;
32594
- const kind = blockKind(tag);
32595
- if (depth >= MAX_BLOCK_DEPTH) {
32596
- yield* atomicBlock(kind, node3);
32597
- return;
32598
- }
32599
- if (tag === "ul" || tag === "ol") {
32600
- let ordinal = typeof node3.properties.start === "number" ? node3.properties.start : 1;
32601
- let stray = [];
32602
- for (const child of node3.children) {
32603
- if (child.type !== "element" || child.tagName !== "li") {
32604
- stray.push(child);
32605
- continue;
32606
- }
32607
- yield* strayListContent(stray, depth + 1);
32608
- stray = [];
32609
- const properties2 = { ...node3.properties };
32610
- if (tag === "ol") properties2.start = ordinal++;
32611
- for (const fragment2 of atomicBlock("item", child)) {
32612
- if (fragment2.kind === "diagram") yield fragment2;
32613
- else if (fragment2.node.type === "element") {
32614
- yield { ...fragment2, node: { ...node3, properties: properties2, children: [fragment2.node] } };
32615
- }
32616
- }
32617
- }
32618
- yield* strayListContent(stray, depth + 1);
32619
- return;
32620
- }
32621
- if (kind === "paragraph" && hasBlockChildren(node3)) {
32622
- yield* splitChildren(node3.children, depth + 1);
32623
- return;
32624
- }
32625
- yield* atomicBlock(kind, node3);
32626
- }
32627
- function identityText(node3) {
32628
- if (node3.type === "element" && renderData(node3).emendFootnoteMarker) return "";
32629
- if (node3.type === "element" && renderData(node3).emendMedia !== void 0)
32630
- return `\0media${renderData(node3).emendMedia}`;
32631
- if (node3.type === "text") return node3.value;
32632
- return "children" in node3 ? node3.children.map(identityText).join("") : "";
32633
- }
32634
- function stringifyBlock(node3, stringify4) {
32635
- const parts = [];
32636
- const pending = [node3];
32637
- for (let next2 = pending.pop(); next2 !== void 0; next2 = pending.pop()) {
32638
- if (typeof next2 === "string") parts.push(next2);
32639
- else if (next2.type === "root") {
32640
- for (const child of next2.children.toReversed()) pending.push(child);
32641
- } else if (next2.type === "element" && next2.children.length > 0) {
32642
- const shell = stringify4({ ...next2, children: [] });
32643
- const closing2 = `</${next2.tagName}>`;
32644
- if (shell.endsWith(closing2)) {
32645
- parts.push(shell.slice(0, -closing2.length));
32646
- pending.push(closing2);
32647
- } else parts.push(shell);
32648
- for (const child of next2.children.toReversed()) pending.push(child);
32649
- } else parts.push(stringify4(next2));
32650
- }
32651
- return parts.join("");
32652
- }
32653
- async function blocksFromTree(tree, section, stringify4) {
32654
- const blocks = [];
32655
- const occurrences = /* @__PURE__ */ new Map();
32656
- const append = async ({ kind, node: node3, source: source2 }) => {
32657
- const html7 = kind === "diagram" ? "" : stringifyBlock(node3, stringify4);
32658
- const text10 = source2 ?? blockText(html7);
32659
- if (kind !== "diagram" && normalizeText(text10) === "") return;
32660
- const hash2 = await blockHash(normalizeText(source2 ?? identityText(node3)));
32661
- const count = (occurrences.get(hash2) ?? 0) + 1;
32662
- occurrences.set(hash2, count);
32663
- blocks.push({
32664
- id: sectionBlockId(section, `${hash2}${count === 1 ? "" : `-${count}`}`),
32665
- section,
32666
- kind,
32667
- html: html7,
32668
- text: text10,
32669
- ...source2 === void 0 ? {} : { source: source2 }
32670
- });
32671
- };
32672
- tree.children = flattenRoots(tree);
32673
- for (const fragment2 of splitBlocks(tree)) await append(fragment2);
32674
- return blocks;
32675
- }
32676
-
32677
- // ../../node_modules/.pnpm/@shikijs+types@4.5.0/node_modules/@shikijs/types/dist/index.mjs
32678
- var ShikiError = class extends Error {
32679
- constructor(message) {
32680
- super(message);
32681
- this.name = "ShikiError";
32682
- }
32683
- };
32684
-
32685
- // ../../node_modules/.pnpm/@shikijs+vscode-textmate@10.1.0/node_modules/@shikijs/vscode-textmate/dist/index.js
32686
- function clone2(something) {
32687
- return doClone(something);
32688
- }
32689
- function doClone(something) {
32690
- if (Array.isArray(something)) {
32691
- return cloneArray(something);
32692
- }
32693
- if (something instanceof RegExp) {
32694
- return something;
32695
- }
32696
- if (typeof something === "object") {
32697
- return cloneObj(something);
32698
- }
32699
- return something;
32700
- }
32701
- function cloneArray(arr) {
32702
- let r4 = [];
32703
- for (let i2 = 0, len = arr.length; i2 < len; i2++) {
32704
- r4[i2] = doClone(arr[i2]);
32705
- }
32706
- return r4;
32707
- }
32708
- function cloneObj(obj) {
32709
- let r4 = {};
32710
- for (let key2 in obj) {
32711
- r4[key2] = doClone(obj[key2]);
32712
- }
32713
- return r4;
32714
- }
32715
- function mergeObjects(target, ...sources) {
32716
- sources.forEach((source2) => {
32717
- for (let key2 in source2) {
32718
- target[key2] = source2[key2];
32719
- }
32720
- });
32721
- return target;
32722
- }
32723
- function basename(path2) {
32724
- const idx = ~path2.lastIndexOf("/") || ~path2.lastIndexOf("\\");
32725
- if (idx === 0) {
32726
- return path2;
32727
- } else if (~idx === path2.length - 1) {
32728
- return basename(path2.substring(0, path2.length - 1));
32729
- } else {
32730
- return path2.substr(~idx + 1);
32731
- }
32732
- }
32733
- var CAPTURING_REGEX_SOURCE = /\$(\d+)|\${(\d+):\/(downcase|upcase)}/g;
32734
- var RegexSource = class {
32735
- static hasCaptures(regexSource) {
32736
- if (regexSource === null) {
32737
- return false;
32738
- }
32739
- CAPTURING_REGEX_SOURCE.lastIndex = 0;
32740
- return CAPTURING_REGEX_SOURCE.test(regexSource);
32741
- }
32742
- static replaceCaptures(regexSource, captureSource, captureIndices) {
32743
- return regexSource.replace(CAPTURING_REGEX_SOURCE, (match, index2, commandIndex, command) => {
32744
- let capture = captureIndices[parseInt(index2 || commandIndex, 10)];
32745
- if (capture) {
32746
- let result = captureSource.substring(capture.start, capture.end);
32747
- while (result[0] === ".") {
32748
- result = result.substring(1);
32749
- }
32750
- switch (command) {
32751
- case "downcase":
32752
- return result.toLowerCase();
32753
- case "upcase":
32754
- return result.toUpperCase();
32755
- default:
32756
- return result;
32757
- }
32758
- } else {
32759
- return match;
32760
- }
32761
- });
32762
- }
32763
- };
32764
- function strcmp(a2, b3) {
32765
- if (a2 < b3) {
32766
- return -1;
32767
- }
32768
- if (a2 > b3) {
32769
- return 1;
32770
- }
32771
- return 0;
32772
- }
32773
- function strArrCmp(a2, b3) {
32774
- if (a2 === null && b3 === null) {
32775
- return 0;
32776
- }
32777
- if (!a2) {
32778
- return -1;
32779
- }
32780
- if (!b3) {
32781
- return 1;
32782
- }
32783
- let len1 = a2.length;
32784
- let len2 = b3.length;
32785
- if (len1 === len2) {
32786
- for (let i2 = 0; i2 < len1; i2++) {
32787
- let res = strcmp(a2[i2], b3[i2]);
32788
- if (res !== 0) {
32789
- return res;
32790
- }
32791
- }
32792
- return 0;
32793
- }
32794
- return len1 - len2;
32795
- }
32796
- function isValidHexColor(hex3) {
32797
- if (/^#[0-9a-f]{6}$/i.test(hex3)) {
32798
- return true;
32799
- }
32800
- if (/^#[0-9a-f]{8}$/i.test(hex3)) {
32801
- return true;
32802
- }
32803
- if (/^#[0-9a-f]{3}$/i.test(hex3)) {
32804
- return true;
32805
- }
32806
- if (/^#[0-9a-f]{4}$/i.test(hex3)) {
32807
- return true;
32808
- }
32809
- return false;
32810
- }
32811
- function escapeRegExpCharacters(value) {
32812
- return value.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, "\\$&");
32813
- }
32814
- var CachedFn = class {
32815
- constructor(fn) {
32816
- this.fn = fn;
32817
- }
32818
- fn;
32819
- cache = /* @__PURE__ */ new Map();
32820
- get(key2) {
32821
- if (this.cache.has(key2)) {
32822
- return this.cache.get(key2);
32823
- }
32824
- const value = this.fn(key2);
32825
- this.cache.set(key2, value);
32826
- return value;
32827
- }
32828
- };
32829
- var Theme = class {
32830
- constructor(_colorMap, _defaults, _root) {
32831
- this._colorMap = _colorMap;
32832
- this._defaults = _defaults;
32833
- this._root = _root;
32834
- }
32835
- _colorMap;
32836
- _defaults;
32837
- _root;
32838
- static createFromRawTheme(source2, colorMap) {
32839
- return this.createFromParsedTheme(parseTheme(source2), colorMap);
32840
- }
32841
- static createFromParsedTheme(source2, colorMap) {
32842
- return resolveParsedThemeRules(source2, colorMap);
32843
- }
32844
- _cachedMatchRoot = new CachedFn(
32845
- (scopeName) => this._root.match(scopeName)
32846
- );
32847
- getColorMap() {
32848
- return this._colorMap.getColorMap();
32849
- }
32850
- getDefaults() {
32851
- return this._defaults;
32852
- }
32853
- match(scopePath) {
32854
- if (scopePath === null) {
32855
- return this._defaults;
32856
- }
32857
- const scopeName = scopePath.scopeName;
32858
- const matchingTrieElements = this._cachedMatchRoot.get(scopeName);
32859
- const effectiveRule = matchingTrieElements.find(
32860
- (v2) => _scopePathMatchesParentScopes(scopePath.parent, v2.parentScopes)
32861
- );
32862
- if (!effectiveRule) {
32863
- return null;
32864
- }
32865
- return new StyleAttributes(
32866
- effectiveRule.fontStyle,
32867
- effectiveRule.foreground,
32868
- effectiveRule.background
32869
- );
32870
- }
32871
- };
32872
- var ScopeStack = class _ScopeStack {
32873
- constructor(parent, scopeName) {
32874
- this.parent = parent;
32875
- this.scopeName = scopeName;
32876
- }
32877
- parent;
32878
- scopeName;
32879
- static push(path2, scopeNames) {
32880
- for (const name of scopeNames) {
32881
- path2 = new _ScopeStack(path2, name);
32882
- }
32883
- return path2;
32884
- }
32885
- static from(...segments) {
32886
- let result = null;
32887
- for (let i2 = 0; i2 < segments.length; i2++) {
32888
- result = new _ScopeStack(result, segments[i2]);
32889
- }
32890
- return result;
32891
- }
32892
- push(scopeName) {
32893
- return new _ScopeStack(this, scopeName);
32894
- }
32895
- getSegments() {
32896
- let item = this;
32897
- const result = [];
32898
- while (item) {
32899
- result.push(item.scopeName);
32900
- item = item.parent;
32901
- }
32902
- result.reverse();
32903
- return result;
32904
- }
32905
- toString() {
32906
- return this.getSegments().join(" ");
32907
- }
32908
- extends(other) {
32909
- if (this === other) {
32910
- return true;
32911
- }
32912
- if (this.parent === null) {
32913
- return false;
32914
- }
32915
- return this.parent.extends(other);
32916
- }
32917
- getExtensionIfDefined(base2) {
32918
- const result = [];
32919
- let item = this;
32920
- while (item && item !== base2) {
32921
- result.push(item.scopeName);
32922
- item = item.parent;
32923
- }
32924
- return item === base2 ? result.reverse() : void 0;
32925
- }
32926
- };
32927
- function _scopePathMatchesParentScopes(scopePath, parentScopes) {
32928
- if (parentScopes.length === 0) {
32929
- return true;
32930
- }
32931
- for (let index2 = 0; index2 < parentScopes.length; index2++) {
32932
- let scopePattern = parentScopes[index2];
32933
- let scopeMustMatch = false;
32934
- if (scopePattern === ">") {
32935
- if (index2 === parentScopes.length - 1) {
32936
- return false;
32937
- }
32938
- scopePattern = parentScopes[++index2];
32939
- scopeMustMatch = true;
32940
- }
32941
- while (scopePath) {
32942
- if (_matchesScope(scopePath.scopeName, scopePattern)) {
32943
- break;
32944
- }
32945
- if (scopeMustMatch) {
32946
- return false;
32947
- }
32948
- scopePath = scopePath.parent;
32949
- }
32950
- if (!scopePath) {
32951
- return false;
32952
- }
32953
- scopePath = scopePath.parent;
32954
- }
32955
- return true;
32956
- }
32957
- function _matchesScope(scopeName, scopePattern) {
32958
- return scopePattern === scopeName || scopeName.startsWith(scopePattern) && scopeName[scopePattern.length] === ".";
32959
- }
32960
- var StyleAttributes = class {
32961
- constructor(fontStyle, foregroundId, backgroundId) {
32962
- this.fontStyle = fontStyle;
32963
- this.foregroundId = foregroundId;
32964
- this.backgroundId = backgroundId;
32965
- }
32966
- fontStyle;
32967
- foregroundId;
32968
- backgroundId;
32969
- };
32970
- function parseTheme(source2) {
32971
- if (!source2) {
32972
- return [];
32409
+ fontStyle;
32410
+ foregroundId;
32411
+ backgroundId;
32412
+ };
32413
+ function parseTheme(source2) {
32414
+ if (!source2) {
32415
+ return [];
32973
32416
  }
32974
32417
  if (!source2.settings || !Array.isArray(source2.settings)) {
32975
32418
  return [];
@@ -35951,7 +35394,7 @@ function isSpecialTheme(theme) {
35951
35394
  return isNoneTheme(theme);
35952
35395
  }
35953
35396
  var RE_NEWLINE = /(\r?\n)/g;
35954
- function splitLines2(code4, preserveEnding = false) {
35397
+ function splitLines(code4, preserveEnding = false) {
35955
35398
  if (code4.length === 0) return [["", 0]];
35956
35399
  const parts = code4.split(RE_NEWLINE);
35957
35400
  let index2 = 0;
@@ -36394,7 +35837,7 @@ var RE_COMMA = /,/;
36394
35837
  var RE_SPACE = / /;
36395
35838
  function codeToTokensBase(primitive, code4, options = {}) {
36396
35839
  const { theme: themeName = primitive.getLoadedThemes()[0] } = options;
36397
- if (isPlainLang(primitive.resolveLangAlias(options.lang || "text")) || isNoneTheme(themeName)) return splitLines2(code4).map((line) => [{
35840
+ if (isPlainLang(primitive.resolveLangAlias(options.lang || "text")) || isNoneTheme(themeName)) return splitLines(code4).map((line) => [{
36398
35841
  content: line[0],
36399
35842
  offset: line[1]
36400
35843
  }]);
@@ -36425,7 +35868,7 @@ function tokenizeWithTheme(code4, grammar, theme, colorMap, options) {
36425
35868
  function _tokenizeWithTheme(code4, grammar, theme, colorMap, options) {
36426
35869
  const colorReplacements = resolveColorReplacements(theme, options);
36427
35870
  const { tokenizeMaxLineLength = 0, tokenizeTimeLimit = 500, includeExplanation = false } = options;
36428
- const lines = splitLines2(code4);
35871
+ const lines = splitLines(code4);
36429
35872
  let stateStack = options.grammarState ? getGrammarStack(options.grammarState, theme.name) ?? INITIAL : options.grammarContextCode != null ? _tokenizeWithTheme(options.grammarContextCode, grammar, theme, colorMap, {
36430
35873
  ...options,
36431
35874
  grammarState: void 0,
@@ -36534,7 +35977,7 @@ function explainThemeScopesFull(themeSelectors, scopes) {
36534
35977
  function matchesOne(selector, scope) {
36535
35978
  return selector === scope || scope.substring(0, selector.length) === selector && scope[selector.length] === ".";
36536
35979
  }
36537
- function matches2(selectors, scope, parentScopes) {
35980
+ function matches(selectors, scope, parentScopes) {
36538
35981
  if (!matchesOne(selectors.at(-1), scope)) return false;
36539
35982
  let selectorParentIndex = selectors.length - 2;
36540
35983
  let parentIndex = parentScopes.length - 1;
@@ -36547,7 +35990,7 @@ function matches2(selectors, scope, parentScopes) {
36547
35990
  }
36548
35991
  function explainThemeScope(themeSettingsSelectors, scope, parentScopes) {
36549
35992
  const result = [];
36550
- for (const { selectors, settings } of themeSettingsSelectors) for (const selectorPieces of selectors) if (matches2(selectorPieces, scope, parentScopes)) {
35993
+ for (const { selectors, settings } of themeSettingsSelectors) for (const selectorPieces of selectors) if (matches(selectorPieces, scope, parentScopes)) {
36551
35994
  result.push(settings);
36552
35995
  break;
36553
35996
  }
@@ -37544,8 +36987,8 @@ function toHtml(tree, options) {
37544
36987
  throw new Error("Invalid quote `" + quote + "`, expected `'` or `\"`");
37545
36988
  }
37546
36989
  const state = {
37547
- one: one3,
37548
- all: all3,
36990
+ one: one2,
36991
+ all: all2,
37549
36992
  settings: {
37550
36993
  omitOptionalTags: options_.omitOptionalTags || false,
37551
36994
  allowParseErrors: options_.allowParseErrors || false,
@@ -37575,10 +37018,10 @@ function toHtml(tree, options) {
37575
37018
  void 0
37576
37019
  );
37577
37020
  }
37578
- function one3(node3, index2, parent) {
37021
+ function one2(node3, index2, parent) {
37579
37022
  return handle(node3, index2, parent, this);
37580
37023
  }
37581
- function all3(parent) {
37024
+ function all2(parent) {
37582
37025
  const results = [];
37583
37026
  const children2 = parent && parent.children || emptyChildren2;
37584
37027
  let index2 = -1;
@@ -37601,7 +37044,7 @@ function addClassToHast(node3, className) {
37601
37044
  return node3;
37602
37045
  }
37603
37046
  function createPositionConverter(code4) {
37604
- const lines = splitLines2(code4, true).map(([line]) => line);
37047
+ const lines = splitLines(code4, true).map(([line]) => line);
37605
37048
  function indexToPos(index2) {
37606
37049
  if (index2 === code4.length) return {
37607
37050
  line: lines.length - 1,
@@ -38149,7 +37592,7 @@ var defaultAnsiColors = {
38149
37592
  };
38150
37593
  function tokenizeAnsiWithTheme(theme, fileContents, options) {
38151
37594
  const colorReplacements = resolveColorReplacements(theme, options);
38152
- const lines = splitLines2(fileContents);
37595
+ const lines = splitLines(fileContents);
38153
37596
  const colorPalette = createColorPalette(Object.fromEntries(namedColors.map((name) => {
38154
37597
  const key2 = `terminal.ansi${name[0].toUpperCase()}${name.substring(1)}`;
38155
37598
  return [name, theme.colors?.[key2] || defaultAnsiColors[name]];
@@ -38551,36 +37994,6 @@ async function createHighlighterCore(options) {
38551
37994
  };
38552
37995
  }
38553
37996
 
38554
- // ../../packages/core/src/render/highlight.ts
38555
- var HIGHLIGHT_LINE_CHARS = 400;
38556
- var HIGHLIGHT_FENCE_BYTES = 16384;
38557
- var HIGHLIGHT_RENDER_BYTES = 65536;
38558
- function limitHighlighting(languages) {
38559
- const loaded = new Set(languages);
38560
- const encoder3 = new TextEncoder();
38561
- return (tree, file2) => {
38562
- const budget = file2.data.highlightBudget ?? { highlightedBytes: 0 };
38563
- visitElements(tree, (element6) => {
38564
- if (element6.tagName !== "pre") return;
38565
- const code4 = element6.children[0];
38566
- if (code4?.type !== "element" || code4.tagName !== "code") return;
38567
- const classes = code4.properties.className;
38568
- if (!Array.isArray(classes)) return;
38569
- const languageClass = classes.find((value) => typeof value === "string" && value.startsWith("language-"));
38570
- if (typeof languageClass !== "string") return;
38571
- const language = languageClass.slice(9);
38572
- if (!loaded.has(language) && !isSpecialLang(language)) return;
38573
- const bytes = encoder3.encode(toString(code4)).byteLength;
38574
- if (bytes > HIGHLIGHT_FENCE_BYTES || budget.highlightedBytes + bytes > HIGHLIGHT_RENDER_BYTES || budget.highlightedBytes >= HIGHLIGHT_RENDER_BYTES) {
38575
- code4.properties.className = classes.filter(
38576
- (value) => typeof value !== "string" || !value.startsWith("language-")
38577
- );
38578
- if (code4.properties.className.length === 0) delete code4.properties.className;
38579
- } else budget.highlightedBytes += bytes;
38580
- });
38581
- };
38582
- }
38583
-
38584
37997
  // ../../node_modules/.pnpm/unist-util-is@6.0.1/node_modules/unist-util-is/lib/index.js
38585
37998
  var convert = (
38586
37999
  // Note: overloads in JSDoc can’t yet use different `@template`s.
@@ -38840,6 +38253,28 @@ function wrap(visitor) {
38840
38253
  }
38841
38254
  }
38842
38255
 
38256
+ // ../../node_modules/.pnpm/hast-util-to-string@3.0.1/node_modules/hast-util-to-string/lib/index.js
38257
+ function toString(node3) {
38258
+ if ("children" in node3) {
38259
+ return all3(node3);
38260
+ }
38261
+ return "value" in node3 ? node3.value : "";
38262
+ }
38263
+ function one3(node3) {
38264
+ if (node3.type === "text") {
38265
+ return node3.value;
38266
+ }
38267
+ return "children" in node3 ? all3(node3) : "";
38268
+ }
38269
+ function all3(node3) {
38270
+ let index2 = -1;
38271
+ const result = [];
38272
+ while (++index2 < node3.children.length) {
38273
+ result[index2] = one3(node3.children[index2]);
38274
+ }
38275
+ return result.join("");
38276
+ }
38277
+
38843
38278
  // ../../node_modules/.pnpm/@shikijs+rehype@4.5.0/node_modules/@shikijs/rehype/dist/core-BvUdHGey.mjs
38844
38279
  var RE_TAILING_CURLY_COLON = /(.+)\{:([\w-]+)\}$/;
38845
38280
  var InlineCodeHandlers = { "tailing-curly-colon": (_tree, node3) => {
@@ -55088,21 +54523,283 @@ function assertDone(name, asyncName, complete) {
55088
54523
  );
55089
54524
  }
55090
54525
  }
55091
- function vfile(value) {
55092
- return looksLikeAVFile(value) ? value : new VFile(value);
54526
+ function vfile(value) {
54527
+ return looksLikeAVFile(value) ? value : new VFile(value);
54528
+ }
54529
+ function looksLikeAVFile(value) {
54530
+ return Boolean(
54531
+ value && typeof value === "object" && "message" in value && "messages" in value
54532
+ );
54533
+ }
54534
+ function looksLikeAValue(value) {
54535
+ return typeof value === "string" || isUint8Array2(value);
54536
+ }
54537
+ function isUint8Array2(value) {
54538
+ return Boolean(
54539
+ value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
54540
+ );
54541
+ }
54542
+
54543
+ // ../../packages/core/src/render/hash.ts
54544
+ async function blockHash(text10) {
54545
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(text10));
54546
+ return Array.from(new Uint8Array(digest).subarray(0, 4), (byte) => byte.toString(16).padStart(2, "0")).join("");
54547
+ }
54548
+
54549
+ // ../../packages/core/src/render/blocks.ts
54550
+ var sectionBlockId = (section, identity) => `${section}-${identity}`;
54551
+ function resectionBlocks(blocks, section) {
54552
+ return blocks.map((block) => ({
54553
+ ...block,
54554
+ section,
54555
+ id: sectionBlockId(section, block.id.slice(block.section.length + 1))
54556
+ }));
54557
+ }
54558
+ function renderData(element6) {
54559
+ element6.data ??= { position: {} };
54560
+ return element6.data;
54561
+ }
54562
+ function blockText(html7) {
54563
+ return toString(fromHtml(html7, { fragment: true }));
54564
+ }
54565
+ function visitElements(node3, visit3) {
54566
+ if (node3.type === "element") visit3(node3);
54567
+ if ("children" in node3) for (const child of node3.children) visitElements(child, visit3);
54568
+ }
54569
+ var MAX_BLOCK_DEPTH = 64;
54570
+ var blockTags = /* @__PURE__ */ new Set([
54571
+ "blockquote",
54572
+ "dd",
54573
+ "details",
54574
+ "div",
54575
+ "dl",
54576
+ "dt",
54577
+ "h1",
54578
+ "h2",
54579
+ "h3",
54580
+ "h4",
54581
+ "h5",
54582
+ "h6",
54583
+ "hr",
54584
+ "li",
54585
+ "ol",
54586
+ "p",
54587
+ "pre",
54588
+ "section",
54589
+ "summary",
54590
+ "table",
54591
+ "ul"
54592
+ ]);
54593
+ function hasBlockChildren(node3) {
54594
+ return "children" in node3 && node3.children.some((child) => child.type === "element" && (blockTags.has(child.tagName) || hasBlockChildren(child)));
54595
+ }
54596
+ function isDiagram(node3) {
54597
+ return node3.type === "element" && renderData(node3).emendDiagram !== void 0;
54598
+ }
54599
+ function hasDiagram(node3) {
54600
+ return isDiagram(node3) || "children" in node3 && node3.children.some(hasDiagram);
54601
+ }
54602
+ function hasContent(nodes) {
54603
+ return nodes.some((node3) => node3.type === "element" || node3.type === "text" && normalizeText(node3.value) !== "");
54604
+ }
54605
+ function* divideAtDiagrams(node3) {
54606
+ if (isDiagram(node3) || !hasDiagram(node3)) {
54607
+ yield node3;
54608
+ return;
54609
+ }
54610
+ let children2 = [];
54611
+ for (const child of node3.children) {
54612
+ if (child.type !== "element") {
54613
+ children2.push(child);
54614
+ continue;
54615
+ }
54616
+ for (const piece of divideAtDiagrams(child)) {
54617
+ if (isDiagram(piece)) {
54618
+ if (hasContent(children2)) yield { ...node3, children: children2 };
54619
+ children2 = [];
54620
+ yield piece;
54621
+ } else children2.push(piece);
54622
+ }
54623
+ }
54624
+ if (hasContent(children2)) yield { ...node3, children: children2 };
54625
+ }
54626
+ function* atomicBlock(kind, node3) {
54627
+ for (const piece of divideAtDiagrams(node3)) {
54628
+ const source2 = renderData(piece).emendDiagram;
54629
+ yield source2 === void 0 ? { kind, node: piece } : { kind: "diagram", node: piece, source: source2 };
54630
+ }
54631
+ }
54632
+ function flattenRoots(node3) {
54633
+ if (node3.type === "root") {
54634
+ return node3.children.flatMap(flattenRoots);
54635
+ }
54636
+ if (node3.type === "element") {
54637
+ node3.children = node3.children.flatMap(flattenRoots).filter((child) => child.type !== "doctype");
54638
+ }
54639
+ return [node3];
54640
+ }
54641
+ function* splitChildren(children2, depth) {
54642
+ let inline = [];
54643
+ for (const child of children2) {
54644
+ if (child.type === "element" && (blockTags.has(child.tagName) || hasBlockChildren(child) || hasDiagram(child))) {
54645
+ if (hasContent(inline)) yield { kind: "paragraph", node: { type: "root", children: inline } };
54646
+ inline = [];
54647
+ yield* splitBlocks(child, depth);
54648
+ } else if (child.type !== "comment" && child.type !== "doctype") inline.push(child);
54649
+ }
54650
+ if (hasContent(inline)) yield { kind: "paragraph", node: { type: "root", children: inline } };
54651
+ }
54652
+ function blockKind(tag) {
54653
+ if (/^h[1-6]$/.test(tag)) return "heading";
54654
+ if (tag === "li" || tag === "dt" || tag === "dd") return "item";
54655
+ if (tag === "pre") return "code";
54656
+ if (tag === "table") return "table";
54657
+ if (tag === "blockquote") return "quote";
54658
+ return "paragraph";
54659
+ }
54660
+ function* strayListContent(children2, depth) {
54661
+ for (const fragment2 of splitChildren(children2, depth)) {
54662
+ yield fragment2.kind === "diagram" ? fragment2 : { ...fragment2, kind: "paragraph" };
54663
+ }
54664
+ }
54665
+ function* splitBlocks(node3, depth = 0) {
54666
+ if (node3.type === "root") {
54667
+ yield* splitChildren(node3.children, depth + 1);
54668
+ return;
54669
+ }
54670
+ if (node3.type !== "element") return;
54671
+ const source2 = renderData(node3).emendDiagram;
54672
+ if (source2 !== void 0) {
54673
+ yield { kind: "diagram", node: node3, source: source2 };
54674
+ return;
54675
+ }
54676
+ const tag = node3.tagName;
54677
+ if (tag === "hr") return;
54678
+ const kind = blockKind(tag);
54679
+ if (depth >= MAX_BLOCK_DEPTH) {
54680
+ yield* atomicBlock(kind, node3);
54681
+ return;
54682
+ }
54683
+ if (tag === "ul" || tag === "ol") {
54684
+ let ordinal = typeof node3.properties.start === "number" ? node3.properties.start : 1;
54685
+ let stray = [];
54686
+ for (const child of node3.children) {
54687
+ if (child.type !== "element" || child.tagName !== "li") {
54688
+ stray.push(child);
54689
+ continue;
54690
+ }
54691
+ yield* strayListContent(stray, depth + 1);
54692
+ stray = [];
54693
+ const properties2 = { ...node3.properties };
54694
+ if (tag === "ol") properties2.start = ordinal++;
54695
+ for (const fragment2 of atomicBlock("item", child)) {
54696
+ if (fragment2.kind === "diagram") yield fragment2;
54697
+ else if (fragment2.node.type === "element") {
54698
+ yield { ...fragment2, node: { ...node3, properties: properties2, children: [fragment2.node] } };
54699
+ }
54700
+ }
54701
+ }
54702
+ yield* strayListContent(stray, depth + 1);
54703
+ return;
54704
+ }
54705
+ if (kind === "paragraph" && hasBlockChildren(node3)) {
54706
+ yield* splitChildren(node3.children, depth + 1);
54707
+ return;
54708
+ }
54709
+ yield* atomicBlock(kind, node3);
54710
+ }
54711
+ function identityText(node3) {
54712
+ if (node3.type === "element" && renderData(node3).emendFootnoteMarker) return "";
54713
+ if (node3.type === "element" && renderData(node3).emendMedia !== void 0)
54714
+ return `\0media${renderData(node3).emendMedia}`;
54715
+ if (node3.type === "text") return node3.value;
54716
+ return "children" in node3 ? node3.children.map(identityText).join("") : "";
55093
54717
  }
55094
- function looksLikeAVFile(value) {
55095
- return Boolean(
55096
- value && typeof value === "object" && "message" in value && "messages" in value
55097
- );
54718
+ function stringifyBlock(node3, stringify4) {
54719
+ const parts = [];
54720
+ const pending = [node3];
54721
+ for (let next2 = pending.pop(); next2 !== void 0; next2 = pending.pop()) {
54722
+ if (typeof next2 === "string") parts.push(next2);
54723
+ else if (next2.type === "root") {
54724
+ for (const child of next2.children.toReversed()) pending.push(child);
54725
+ } else if (next2.type === "element" && next2.children.length > 0) {
54726
+ const shell = stringify4({ ...next2, children: [] });
54727
+ const closing2 = `</${next2.tagName}>`;
54728
+ if (shell.endsWith(closing2)) {
54729
+ parts.push(shell.slice(0, -closing2.length));
54730
+ pending.push(closing2);
54731
+ } else parts.push(shell);
54732
+ for (const child of next2.children.toReversed()) pending.push(child);
54733
+ } else parts.push(stringify4(next2));
54734
+ }
54735
+ return parts.join("");
55098
54736
  }
55099
- function looksLikeAValue(value) {
55100
- return typeof value === "string" || isUint8Array2(value);
54737
+ async function blocksFromTree(tree, section, stringify4) {
54738
+ const blocks = [];
54739
+ const elementIds = /* @__PURE__ */ new Map();
54740
+ visitElements(tree, (element6) => {
54741
+ const id2 = element6.properties.id;
54742
+ if (typeof id2 === "string") elementIds.set(id2, (elementIds.get(id2) ?? 0) + 1);
54743
+ });
54744
+ const occurrences = /* @__PURE__ */ new Map();
54745
+ const append = async ({ kind, node: node3, source: source2 }) => {
54746
+ let html7 = kind === "diagram" ? "" : stringifyBlock(node3, stringify4);
54747
+ const text10 = source2 ?? blockText(html7);
54748
+ if (kind !== "diagram" && normalizeText(text10) === "") return;
54749
+ const hash2 = await blockHash(normalizeText(source2 ?? identityText(node3)));
54750
+ const count = (occurrences.get(hash2) ?? 0) + 1;
54751
+ occurrences.set(hash2, count);
54752
+ if (kind === "heading" && node3.type === "element") {
54753
+ const authorId = node3.properties.id;
54754
+ if (typeof authorId !== "string" || !authorId.startsWith("user-content-") || elementIds.get(authorId) !== 1 || authorId.length > LIMITS.headingIdChars || Array.from(authorId).some((char) => {
54755
+ const code4 = char.charCodeAt(0);
54756
+ return code4 < 32 || code4 >= 127 && code4 <= 159;
54757
+ }))
54758
+ node3.properties.id = `heading-${hash2}${count === 1 ? "" : `-${count}`}`;
54759
+ html7 = stringifyBlock(node3, stringify4);
54760
+ }
54761
+ blocks.push({
54762
+ id: sectionBlockId(section, `${hash2}${count === 1 ? "" : `-${count}`}`),
54763
+ section,
54764
+ kind,
54765
+ html: html7,
54766
+ text: text10,
54767
+ ...source2 === void 0 ? {} : { source: source2 }
54768
+ });
54769
+ };
54770
+ tree.children = flattenRoots(tree);
54771
+ for (const fragment2 of splitBlocks(tree)) await append(fragment2);
54772
+ return blocks;
55101
54773
  }
55102
- function isUint8Array2(value) {
55103
- return Boolean(
55104
- value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
55105
- );
54774
+
54775
+ // ../../packages/core/src/render/highlight.ts
54776
+ var HIGHLIGHT_LINE_CHARS = 400;
54777
+ var HIGHLIGHT_FENCE_BYTES = 16384;
54778
+ var HIGHLIGHT_RENDER_BYTES = 65536;
54779
+ function limitHighlighting(languages) {
54780
+ const loaded = new Set(languages);
54781
+ const encoder3 = new TextEncoder();
54782
+ return (tree, file2) => {
54783
+ const budget = file2.data.highlightBudget ?? { highlightedBytes: 0 };
54784
+ visitElements(tree, (element6) => {
54785
+ if (element6.tagName !== "pre") return;
54786
+ const code4 = element6.children[0];
54787
+ if (code4?.type !== "element" || code4.tagName !== "code") return;
54788
+ const classes = code4.properties.className;
54789
+ if (!Array.isArray(classes)) return;
54790
+ const languageClass = classes.find((value) => typeof value === "string" && value.startsWith("language-"));
54791
+ if (typeof languageClass !== "string") return;
54792
+ const language = languageClass.slice(9);
54793
+ if (!loaded.has(language) && !isSpecialLang(language)) return;
54794
+ const bytes = encoder3.encode(toString(code4)).byteLength;
54795
+ if (bytes > HIGHLIGHT_FENCE_BYTES || budget.highlightedBytes + bytes > HIGHLIGHT_RENDER_BYTES || budget.highlightedBytes >= HIGHLIGHT_RENDER_BYTES) {
54796
+ code4.properties.className = classes.filter(
54797
+ (value) => typeof value !== "string" || !value.startsWith("language-")
54798
+ );
54799
+ if (code4.properties.className.length === 0) delete code4.properties.className;
54800
+ } else budget.highlightedBytes += bytes;
54801
+ });
54802
+ };
55106
54803
  }
55107
54804
 
55108
54805
  // ../../packages/core/src/render/issue-refs.ts
@@ -55149,7 +54846,7 @@ function linkIssueRefs() {
55149
54846
  }
55150
54847
 
55151
54848
  // ../../packages/core/src/render/line-breaks.ts
55152
- function splitLines3(value) {
54849
+ function splitLines2(value) {
55153
54850
  const parts = [];
55154
54851
  value.split(/\r\n|\r|\n/).forEach((line, index2) => {
55155
54852
  if (index2 > 0) parts.push({ type: "break" });
@@ -55162,7 +54859,7 @@ function breakText(node3) {
55162
54859
  const next2 = [];
55163
54860
  for (const child of node3.children) {
55164
54861
  if (child.type === "text" && child.value && /[\r\n]/.test(child.value)) {
55165
- next2.push(...splitLines3(child.value));
54862
+ next2.push(...splitLines2(child.value));
55166
54863
  } else {
55167
54864
  breakText(child);
55168
54865
  next2.push(child);
@@ -55207,6 +54904,41 @@ function limitReferences() {
55207
54904
  };
55208
54905
  }
55209
54906
 
54907
+ // ../../packages/core/src/links.ts
54908
+ function resolveDocLink(base2, href, docs2) {
54909
+ const hasControl = (value) => Array.from(value).some((char) => {
54910
+ const code4 = char.charCodeAt(0);
54911
+ return code4 < 32 || code4 >= 127 && code4 <= 159;
54912
+ });
54913
+ if (!href || hasControl(href) || href.includes("\\")) return null;
54914
+ const hash2 = href.indexOf("#");
54915
+ const rawPath = hash2 < 0 ? href : href.slice(0, hash2);
54916
+ if (rawPath.startsWith("/") || rawPath.includes("?") || /%2f|%5c/i.test(href)) return null;
54917
+ let parts;
54918
+ let fragment2;
54919
+ try {
54920
+ parts = rawPath.split("/").map((part) => decodeURIComponent(part));
54921
+ fragment2 = hash2 < 0 ? void 0 : decodeURIComponent(href.slice(hash2 + 1));
54922
+ } catch {
54923
+ return null;
54924
+ }
54925
+ if (parts.some((part) => hasControl(part) || part.includes("\\") || part.includes(":")) || fragment2 !== void 0 && hasControl(fragment2))
54926
+ return null;
54927
+ if (rawPath !== "" && (rawPath.endsWith("/") || parts.at(-1) === "." || parts.at(-1) === "..")) return null;
54928
+ const path2 = rawPath === "" ? base2.split("/") : base2.split("/").slice(0, -1);
54929
+ if (rawPath !== "")
54930
+ for (const part of parts) {
54931
+ if (part === ".") continue;
54932
+ if (part === "") return null;
54933
+ if (part === "..") {
54934
+ if (!path2.length) return null;
54935
+ path2.pop();
54936
+ } else path2.push(part);
54937
+ }
54938
+ const resolved = path2.join("/");
54939
+ return docs2.has(resolved) ? { path: resolved, ...fragment2 ? { fragment: fragment2 } : {} } : null;
54940
+ }
54941
+
55210
54942
  // ../../packages/core/src/render/sanitize.ts
55211
54943
  var prefix = "user-content-";
55212
54944
  var forbiddenTags = [
@@ -55297,7 +55029,10 @@ function restoreFootnotes() {
55297
55029
  if (!("children" in parent)) continue;
55298
55030
  for (const [index2, child] of parent.children.entries()) {
55299
55031
  if (child.type === FOOTNOTE_NODE) {
55300
- parent.children[index2] = child.data.element;
55032
+ const element6 = child.data.element;
55033
+ parent.children[index2] = element6;
55034
+ const link4 = element6.children[0];
55035
+ if (element6.tagName === "sup" && link4?.type === "element") renderData(link4).emendFootnoteMarker = true;
55301
55036
  } else pending.push(child);
55302
55037
  }
55303
55038
  }
@@ -55385,6 +55120,8 @@ function wrapMedia(node3, media) {
55385
55120
  function hardenLinks() {
55386
55121
  return (tree, file2) => {
55387
55122
  const media = file2.data.media;
55123
+ const docs2 = file2.data.docs;
55124
+ const base2 = typeof file2.data.docBase === "string" ? file2.data.docBase : "";
55388
55125
  visitElements(tree, (element6) => {
55389
55126
  const classes = renderData(element6).emendClasses;
55390
55127
  if (Array.isArray(classes) && classes.every(
@@ -55401,6 +55138,21 @@ function hardenLinks() {
55401
55138
  delete element6.properties.href;
55402
55139
  delete element6.properties.rel;
55403
55140
  delete element6.properties.target;
55141
+ if (docs2 && element6.tagName === "a" && !renderData(element6).emendFootnoteMarker && !hasBlockChildren(element6) && typeof href === "string") {
55142
+ const hash2 = href.indexOf("#");
55143
+ const query = href.indexOf("?");
55144
+ const lookup = query >= 0 && (hash2 < 0 || query < hash2) ? href.slice(0, query) + (hash2 < 0 ? "" : href.slice(hash2)) : href;
55145
+ file2.data.docBaseUsed = true;
55146
+ if (lookup.startsWith("#")) file2.data.docPathUsed = true;
55147
+ const link4 = resolveDocLink(base2, lookup, docs2);
55148
+ if (link4) {
55149
+ const params = new URLSearchParams({ tab: "docs", doc: link4.path });
55150
+ const ids = docs2.get(link4.path);
55151
+ const id2 = link4.fragment && ids?.has(`${prefix}${link4.fragment}`) ? `${prefix}${link4.fragment}` : void 0;
55152
+ const heading3 = id2 ? `#h-${encodeURIComponent(id2)}` : "";
55153
+ element6.properties.href = `?${params}${heading3}`;
55154
+ }
55155
+ }
55404
55156
  }
55405
55157
  if (element6.tagName === "img") {
55406
55158
  const path2 = media ? mediaKey(src, media) : null;
@@ -55521,7 +55273,7 @@ async function createProcessor() {
55521
55273
  }).use(rehypeStringify);
55522
55274
  }
55523
55275
  var processorPromise;
55524
- async function renderMarkdownWithBudget(markdown2, section, highlightBudget, repoUrl, media) {
55276
+ async function renderMarkdownWithBudget(markdown2, section, highlightBudget, repoUrl, media, docs2, docBase = "", effects) {
55525
55277
  BlockId.parse(`${section}-00000000`);
55526
55278
  processorPromise ??= createProcessor().catch((error62) => {
55527
55279
  processorPromise = void 0;
@@ -55529,10 +55281,22 @@ async function renderMarkdownWithBudget(markdown2, section, highlightBudget, rep
55529
55281
  });
55530
55282
  const processor = await processorPromise;
55531
55283
  const { source: source2, tables } = prepareTables(markdown2);
55284
+ const data = {
55285
+ highlightBudget,
55286
+ largeTables: tables,
55287
+ repoUrl,
55288
+ media,
55289
+ docs: docs2,
55290
+ docBase,
55291
+ docBaseUsed: false,
55292
+ docPathUsed: false
55293
+ };
55532
55294
  const tree = await processor.run(processor.parse(source2), {
55533
55295
  value: source2,
55534
- data: { highlightBudget, largeTables: tables, repoUrl, media }
55296
+ data
55535
55297
  });
55298
+ if (effects && data.docBaseUsed) effects.docBaseUsed = true;
55299
+ if (effects && data.docPathUsed) effects.docPathUsed = true;
55536
55300
  return blocksFromTree(
55537
55301
  tree,
55538
55302
  section,
@@ -55548,11 +55312,489 @@ async function renderCommentHtml(markdown2, repoUrl) {
55548
55312
  });
55549
55313
  return commentProcessor.stringify(tree);
55550
55314
  }
55551
- function renderMarkdown(markdown2, section, repoUrl) {
55552
- return renderMarkdownWithBudget(markdown2, section, { highlightedBytes: 0 }, repoUrl);
55315
+ async function renderDoc(markdown2, path2, repoUrl, docs2, effects) {
55316
+ return renderMarkdownWithBudget(
55317
+ markdown2,
55318
+ `doc-${await blockHash(path2)}`,
55319
+ { highlightedBytes: 0 },
55320
+ repoUrl,
55321
+ void 0,
55322
+ docs2,
55323
+ path2,
55324
+ effects
55325
+ );
55326
+ }
55327
+ var metadataProcessor = sanitizedPipeline().use(isolateDiagrams).use(rehypeStringify);
55328
+ async function renderMetadataBlocks(markdown2) {
55329
+ const { source: source2, tables } = prepareTables(markdown2);
55330
+ const tree = await metadataProcessor.run(metadataProcessor.parse(source2), {
55331
+ value: source2,
55332
+ data: { largeTables: tables }
55333
+ });
55334
+ return blocksFromTree(
55335
+ tree,
55336
+ "metadata",
55337
+ (node3) => metadataProcessor.stringify(node3.type === "root" ? node3 : { type: "root", children: [node3] })
55338
+ );
55339
+ }
55340
+
55341
+ // ../../packages/core/src/doc-title.ts
55342
+ var TITLE_PREFIX_BYTES = 64 * 1024;
55343
+ var discardedRanges = [
55344
+ [0, 31],
55345
+ [127, 159],
55346
+ [847, 847],
55347
+ [1564, 1564],
55348
+ [4447, 4448],
55349
+ [8203, 8207],
55350
+ [8234, 8238],
55351
+ [8288, 8303],
55352
+ [12644, 12644],
55353
+ [65024, 65039],
55354
+ [65279, 65279],
55355
+ [65440, 65440],
55356
+ [65529, 65531],
55357
+ [917504, 917631],
55358
+ [917760, 917999]
55359
+ ];
55360
+ function cleanDocTitle(value) {
55361
+ return Array.from(value.replace(/[\s\x85]/gu, " ")).filter((char) => {
55362
+ const code4 = char.codePointAt(0) ?? 0;
55363
+ return !discardedRanges.some(([from, to]) => code4 >= from && code4 <= to);
55364
+ }).join("").replace(/ +/g, " ").trim().toWellFormed().slice(0, LIMITS.titleChars).replace(/[\uD800-\uDBFF]$/, "").trim();
55365
+ }
55366
+ function htmlTitle(bytes) {
55367
+ const tree = parseDocHtml(new TextDecoder().decode(bytes.subarray(0, TITLE_PREFIX_BYTES)));
55368
+ if (!tree) return void 0;
55369
+ const head2 = htmlPart(tree, "head");
55370
+ if (head2 && defaultTreeAdapter.isElementNode(head2)) {
55371
+ const title = head2.childNodes.find(
55372
+ (node3) => defaultTreeAdapter.isElementNode(node3) && node3.namespaceURI === html_exports.NS.HTML && node3.tagName === "title"
55373
+ );
55374
+ const cleaned = title ? cleanDocTitle(nodeText(title, 4 * LIMITS.titleChars)) : "";
55375
+ if (cleaned) return cleaned;
55376
+ }
55377
+ const body3 = htmlPart(tree, "body");
55378
+ if (body3)
55379
+ for (const node3 of docNodes(body3)) {
55380
+ if (defaultTreeAdapter.isElementNode(node3) && node3.namespaceURI === html_exports.NS.HTML && node3.tagName === "h1")
55381
+ return cleanDocTitle(nodeText(node3, 4 * LIMITS.titleChars)) || void 0;
55382
+ }
55383
+ return void 0;
55384
+ }
55385
+ function markdownTitle(blocks) {
55386
+ const heading3 = blocks.find((block) => block.kind === "heading" && /^<h1(?:\s|>)/.test(block.html));
55387
+ return heading3 ? cleanDocTitle(heading3.text) || void 0 : void 0;
55388
+ }
55389
+ async function inferDocTitle(kind, bytes) {
55390
+ return kind === "html" ? htmlTitle(bytes) : markdownTitle(await renderMetadataBlocks(new TextDecoder().decode(bytes)));
55391
+ }
55392
+
55393
+ // ../../packages/core/src/doc-headings.ts
55394
+ function htmlHeadings(source2) {
55395
+ const tree = parseDocHtml(source2);
55396
+ const body3 = tree ? htmlPart(tree, "body") : void 0;
55397
+ const headings = [];
55398
+ if (body3)
55399
+ for (const node3 of docNodes(body3)) {
55400
+ if (!defaultTreeAdapter.isElementNode(node3) || node3.namespaceURI !== html_exports.NS.HTML || node3.tagName !== "h2" && node3.tagName !== "h3")
55401
+ continue;
55402
+ headings.push({
55403
+ level: node3.tagName === "h2" ? 2 : 3,
55404
+ text: cleanDocTitle(nodeText(node3, 4 * LIMITS.headingTextChars)).slice(0, LIMITS.headingTextChars)
55405
+ });
55406
+ if (headings.length === LIMITS.headingsPerDoc) break;
55407
+ }
55408
+ return headings;
55409
+ }
55410
+ function markdownHeadings(blocks) {
55411
+ const headings = [];
55412
+ const seen = /* @__PURE__ */ new Set();
55413
+ for (const block of blocks) {
55414
+ if (block.kind !== "heading") continue;
55415
+ if (!/^<h[23](?:\s|>)/.test(block.html)) continue;
55416
+ const node3 = fromHtml(block.html, { fragment: true }).children[0];
55417
+ if (node3?.type !== "element" || typeof node3.properties.id !== "string") continue;
55418
+ if (seen.has(node3.properties.id)) continue;
55419
+ seen.add(node3.properties.id);
55420
+ headings.push({
55421
+ level: node3.tagName === "h2" ? 2 : 3,
55422
+ text: cleanDocTitle(block.text).slice(0, LIMITS.headingTextChars),
55423
+ id: node3.properties.id
55424
+ });
55425
+ if (headings.length === LIMITS.headingsPerDoc) break;
55426
+ }
55427
+ return headings;
55428
+ }
55429
+
55430
+ // ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/base.js
55431
+ var Diff = class {
55432
+ diff(oldStr, newStr, options = {}) {
55433
+ let callback;
55434
+ if (typeof options === "function") {
55435
+ callback = options;
55436
+ options = {};
55437
+ } else if ("callback" in options) {
55438
+ callback = options.callback;
55439
+ }
55440
+ const oldString = this.castInput(oldStr, options);
55441
+ const newString = this.castInput(newStr, options);
55442
+ const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
55443
+ const newTokens = this.removeEmpty(this.tokenize(newString, options));
55444
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
55445
+ }
55446
+ diffWithOptionsObj(oldTokens, newTokens, options, callback) {
55447
+ var _a4;
55448
+ const done = (value) => {
55449
+ value = this.postProcess(value, options);
55450
+ if (callback) {
55451
+ setTimeout(function() {
55452
+ callback(value);
55453
+ }, 0);
55454
+ return void 0;
55455
+ } else {
55456
+ return value;
55457
+ }
55458
+ };
55459
+ const newLen = newTokens.length, oldLen = oldTokens.length;
55460
+ let editLength = 1;
55461
+ let maxEditLength = newLen + oldLen;
55462
+ if (options.maxEditLength != null) {
55463
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
55464
+ }
55465
+ const maxExecutionTime = (_a4 = options.timeout) !== null && _a4 !== void 0 ? _a4 : Infinity;
55466
+ const abortAfterTimestamp = Date.now() + maxExecutionTime;
55467
+ const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
55468
+ let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
55469
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
55470
+ return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
55471
+ }
55472
+ let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
55473
+ const execEditLength = () => {
55474
+ for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
55475
+ let basePath;
55476
+ const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
55477
+ if (removePath) {
55478
+ bestPath[diagonalPath - 1] = void 0;
55479
+ }
55480
+ let canAdd = false;
55481
+ if (addPath) {
55482
+ const addPathNewPos = addPath.oldPos - diagonalPath;
55483
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
55484
+ }
55485
+ const canRemove = removePath && removePath.oldPos + 1 < oldLen;
55486
+ if (!canAdd && !canRemove) {
55487
+ bestPath[diagonalPath] = void 0;
55488
+ continue;
55489
+ }
55490
+ if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
55491
+ basePath = this.addToPath(addPath, true, false, 0, options);
55492
+ } else {
55493
+ basePath = this.addToPath(removePath, false, true, 1, options);
55494
+ }
55495
+ newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
55496
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
55497
+ return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
55498
+ } else {
55499
+ bestPath[diagonalPath] = basePath;
55500
+ if (basePath.oldPos + 1 >= oldLen) {
55501
+ maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
55502
+ }
55503
+ if (newPos + 1 >= newLen) {
55504
+ minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
55505
+ }
55506
+ }
55507
+ }
55508
+ editLength++;
55509
+ };
55510
+ if (callback) {
55511
+ (function exec() {
55512
+ setTimeout(function() {
55513
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
55514
+ return callback(void 0);
55515
+ }
55516
+ if (!execEditLength()) {
55517
+ exec();
55518
+ }
55519
+ }, 0);
55520
+ })();
55521
+ } else {
55522
+ while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
55523
+ const ret = execEditLength();
55524
+ if (ret) {
55525
+ return ret;
55526
+ }
55527
+ }
55528
+ }
55529
+ }
55530
+ addToPath(path2, added, removed, oldPosInc, options) {
55531
+ const last = path2.lastComponent;
55532
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
55533
+ return {
55534
+ oldPos: path2.oldPos + oldPosInc,
55535
+ lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
55536
+ };
55537
+ } else {
55538
+ return {
55539
+ oldPos: path2.oldPos + oldPosInc,
55540
+ lastComponent: { count: 1, added, removed, previousComponent: last }
55541
+ };
55542
+ }
55543
+ }
55544
+ extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
55545
+ const newLen = newTokens.length, oldLen = oldTokens.length;
55546
+ let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
55547
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
55548
+ newPos++;
55549
+ oldPos++;
55550
+ commonCount++;
55551
+ if (options.oneChangePerToken) {
55552
+ basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
55553
+ }
55554
+ }
55555
+ if (commonCount && !options.oneChangePerToken) {
55556
+ basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
55557
+ }
55558
+ basePath.oldPos = oldPos;
55559
+ return newPos;
55560
+ }
55561
+ equals(left, right, options) {
55562
+ if (options.comparator) {
55563
+ return options.comparator(left, right);
55564
+ } else {
55565
+ return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
55566
+ }
55567
+ }
55568
+ removeEmpty(array2) {
55569
+ const ret = [];
55570
+ for (let i2 = 0; i2 < array2.length; i2++) {
55571
+ if (array2[i2]) {
55572
+ ret.push(array2[i2]);
55573
+ }
55574
+ }
55575
+ return ret;
55576
+ }
55577
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
55578
+ castInput(value, options) {
55579
+ return value;
55580
+ }
55581
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
55582
+ tokenize(value, options) {
55583
+ return Array.from(value);
55584
+ }
55585
+ join(chars) {
55586
+ return chars.join("");
55587
+ }
55588
+ postProcess(changeObjects, options) {
55589
+ return changeObjects;
55590
+ }
55591
+ get useLongestToken() {
55592
+ return false;
55593
+ }
55594
+ buildValues(lastComponent, newTokens, oldTokens) {
55595
+ const components = [];
55596
+ let nextComponent;
55597
+ while (lastComponent) {
55598
+ components.push(lastComponent);
55599
+ nextComponent = lastComponent.previousComponent;
55600
+ delete lastComponent.previousComponent;
55601
+ lastComponent = nextComponent;
55602
+ }
55603
+ components.reverse();
55604
+ const componentLen = components.length;
55605
+ let componentPos = 0, newPos = 0, oldPos = 0;
55606
+ for (; componentPos < componentLen; componentPos++) {
55607
+ const component = components[componentPos];
55608
+ if (!component.removed) {
55609
+ if (!component.added && this.useLongestToken) {
55610
+ let value = newTokens.slice(newPos, newPos + component.count);
55611
+ value = value.map(function(value2, i2) {
55612
+ const oldValue = oldTokens[oldPos + i2];
55613
+ return oldValue.length > value2.length ? oldValue : value2;
55614
+ });
55615
+ component.value = this.join(value);
55616
+ } else {
55617
+ component.value = this.join(newTokens.slice(newPos, newPos + component.count));
55618
+ }
55619
+ newPos += component.count;
55620
+ if (!component.added) {
55621
+ oldPos += component.count;
55622
+ }
55623
+ } else {
55624
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
55625
+ oldPos += component.count;
55626
+ }
55627
+ }
55628
+ return components;
55629
+ }
55630
+ };
55631
+
55632
+ // ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/line.js
55633
+ var LineDiff = class extends Diff {
55634
+ constructor() {
55635
+ super(...arguments);
55636
+ this.tokenize = tokenize;
55637
+ }
55638
+ equals(left, right, options) {
55639
+ if (options.ignoreWhitespace) {
55640
+ if (!options.newlineIsToken || !left.includes("\n")) {
55641
+ left = left.trim();
55642
+ }
55643
+ if (!options.newlineIsToken || !right.includes("\n")) {
55644
+ right = right.trim();
55645
+ }
55646
+ } else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
55647
+ if (left.endsWith("\n")) {
55648
+ left = left.slice(0, -1);
55649
+ }
55650
+ if (right.endsWith("\n")) {
55651
+ right = right.slice(0, -1);
55652
+ }
55653
+ }
55654
+ return super.equals(left, right, options);
55655
+ }
55656
+ };
55657
+ var lineDiff = new LineDiff();
55658
+ function diffLines(oldStr, newStr, options) {
55659
+ return lineDiff.diff(oldStr, newStr, options);
55660
+ }
55661
+ function tokenize(value, options) {
55662
+ if (options.stripTrailingCr) {
55663
+ value = value.replace(/\r\n/g, "\n");
55664
+ }
55665
+ const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
55666
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
55667
+ linesAndNewlines.pop();
55668
+ }
55669
+ for (let i2 = 0; i2 < linesAndNewlines.length; i2++) {
55670
+ const line = linesAndNewlines[i2];
55671
+ if (i2 % 2 && !options.newlineIsToken) {
55672
+ retLines[retLines.length - 1] += line;
55673
+ } else {
55674
+ retLines.push(line);
55675
+ }
55676
+ }
55677
+ return retLines;
55678
+ }
55679
+
55680
+ // ../../packages/core/src/place/linemap.ts
55681
+ var LINE_MAP_MAX_EDIT_LENGTH = 256;
55682
+ function splitLines3(text10) {
55683
+ if (text10 === "") return [];
55684
+ const lines = text10.replace(/\r\n/g, "\n").split("\n");
55685
+ if (lines.at(-1) === "") lines.pop();
55686
+ return lines;
55687
+ }
55688
+ function lineMap(from, to) {
55689
+ const mapped = [];
55690
+ let oldLine = 1;
55691
+ let newLine = 1;
55692
+ const changes = diffLines(from, to, {
55693
+ stripTrailingCr: true,
55694
+ ignoreNewlineAtEof: true,
55695
+ maxEditLength: LINE_MAP_MAX_EDIT_LENGTH
55696
+ });
55697
+ if (changes === void 0) return () => null;
55698
+ for (const change of changes) {
55699
+ if (change.added) newLine += change.count;
55700
+ else {
55701
+ for (let index2 = 0; index2 < change.count; index2++) {
55702
+ mapped[oldLine++] = change.removed ? null : newLine++;
55703
+ }
55704
+ }
55705
+ }
55706
+ return (line) => Number.isInteger(line) && line > 0 ? mapped[line] ?? null : null;
55707
+ }
55708
+
55709
+ // ../../packages/core/src/place/lines.ts
55710
+ function matches2(lines, start, quote) {
55711
+ return start >= 0 && start + quote.length <= lines.length && quote.every((line, index2) => lines[start + index2] === line);
55712
+ }
55713
+ function placeLines(target, last, next2) {
55714
+ if (next2 === null) return { status: "unplaced", reason: "file-gone" };
55715
+ const hashKey = target.side === "old" ? "oldHash" : "newHash";
55716
+ const textKey = target.side === "old" ? "oldText" : "newText";
55717
+ const previousText = last.sides[textKey];
55718
+ const nextText = next2[textKey];
55719
+ if (nextText === void 0) return { status: "unplaced", reason: "file-gone" };
55720
+ const lines = splitLines3(nextText);
55721
+ const placed = (start2) => ({
55722
+ status: "placed",
55723
+ location: { kind: "lines", path: target.path, side: target.side, start: start2, end: start2 + target.lines.length - 1 }
55724
+ });
55725
+ const validRange = last.start > 0 && last.end - last.start + 1 === target.lines.length;
55726
+ if (validRange && last.sides[hashKey] !== void 0 && last.sides[hashKey] === next2[hashKey] && matches2(lines, last.start - 1, target.lines))
55727
+ return placed(last.start);
55728
+ if (validRange && previousText !== void 0) {
55729
+ const map4 = lineMap(previousText, nextText);
55730
+ const start2 = map4(last.start);
55731
+ if (start2 !== null && target.lines.every((_3, index2) => map4(last.start + index2) === start2 + index2) && matches2(lines, start2 - 1, target.lines))
55732
+ return placed(start2);
55733
+ }
55734
+ const sequence = [...target.before, ...target.lines, ...target.after];
55735
+ const found = firstTwoMatches(lines, sequence);
55736
+ if (found.length > 1) return { status: "unplaced", reason: "ambiguous" };
55737
+ const start = found[0];
55738
+ return start === void 0 ? { status: "unplaced", reason: "lines-gone" } : placed(start + target.before.length + 1);
55739
+ }
55740
+
55741
+ // ../../packages/core/src/place/place.ts
55742
+ function placeThread(target, ctx) {
55743
+ const last = ctx.last?.location;
55744
+ switch (target.kind) {
55745
+ case "review":
55746
+ return { status: "placed", location: { kind: "review" } };
55747
+ case "topic":
55748
+ return ctx.topics.has(target.slug) ? { status: "placed", location: { kind: "topic", slug: target.slug } } : { status: "unplaced", reason: "topic-gone" };
55749
+ case "writeup-span":
55750
+ return placeSpan(ctx.writeup, {
55751
+ ...target,
55752
+ blockId: last?.kind === "writeup-span" ? last.blockId : target.blockId
55753
+ });
55754
+ default: {
55755
+ const previousPath = last?.kind === target.kind && "path" in last ? last.path : target.path;
55756
+ const renamed = ctx.renamedFrom.get(previousPath);
55757
+ if (renamed === null) return { status: "unplaced", reason: "file-gone" };
55758
+ const path2 = renamed ?? previousPath;
55759
+ if (target.kind === "file") {
55760
+ return ctx.files.has(path2) ? { status: "placed", location: { kind: "file", path: path2 } } : { status: "unplaced", reason: "file-gone" };
55761
+ }
55762
+ if (target.kind === "lines") {
55763
+ const previous3 = last?.kind === "lines" && last.side === target.side ? last : target;
55764
+ return placeLines(
55765
+ { ...target, path: path2 },
55766
+ {
55767
+ start: previous3.start,
55768
+ end: previous3.end,
55769
+ sides: ctx.last?.sides ?? {}
55770
+ },
55771
+ ctx.files.get(path2) ?? null
55772
+ );
55773
+ }
55774
+ const doc = ctx.docs.get(path2);
55775
+ if (!doc) return { status: "unplaced", reason: "file-gone" };
55776
+ if (target.kind === "html-span") {
55777
+ return doc.kind === "html" ? placeHtmlSpan(doc.text, { ...target, path: path2 }) : { status: "unplaced", reason: "block-gone" };
55778
+ }
55779
+ return doc.kind === "markdown" ? placeSpan(doc.blocks, { ...target, path: path2, blockId: last?.kind === "doc-span" ? last.blockId : target.blockId }) : { status: "unplaced", reason: "block-gone" };
55780
+ }
55781
+ }
55553
55782
  }
55554
- async function renderDoc(markdown2, path2, repoUrl) {
55555
- return renderMarkdown(markdown2, `doc-${await blockHash(path2)}`, repoUrl);
55783
+
55784
+ // ../../packages/core/src/place/renames.ts
55785
+ function composeRenames(steps) {
55786
+ const composed = /* @__PURE__ */ new Map();
55787
+ for (let index2 = steps.length - 1; index2 >= 0; index2--) {
55788
+ const step = steps[index2];
55789
+ if (!step) continue;
55790
+ const pending = [];
55791
+ for (const [from, to] of step) {
55792
+ const next2 = to === null ? null : composed.get(to);
55793
+ pending.push([from, next2 === void 0 ? to : next2]);
55794
+ }
55795
+ for (const [from, to] of pending) composed.set(from, to);
55796
+ }
55797
+ return composed;
55556
55798
  }
55557
55799
 
55558
55800
  // ../../packages/core/src/render/writeup.ts
@@ -55566,7 +55808,16 @@ async function renderWriteup(writeup, topics, meta3 = {}) {
55566
55808
  key: key2,
55567
55809
  label,
55568
55810
  topic,
55569
- blocks: await renderMarkdownWithBudget(markdown2, key2, highlightBudget, meta3.repoUrl, meta3.media)
55811
+ blocks: await renderMarkdownWithBudget(
55812
+ markdown2,
55813
+ key2,
55814
+ highlightBudget,
55815
+ meta3.repoUrl,
55816
+ meta3.media,
55817
+ meta3.docs,
55818
+ "",
55819
+ meta3.effects
55820
+ )
55570
55821
  });
55571
55822
  };
55572
55823
  await append("overview", "Overview", writeup.overview);
@@ -55595,15 +55846,26 @@ var parse7 = (bytes, format) => {
55595
55846
  const value = JSON.parse(decode4(bytes));
55596
55847
  return format === "writeup" ? value.sections.flatMap((s3) => s3.blocks) : value;
55597
55848
  };
55598
- function serializeRendered(value) {
55849
+ function serializeRendered(value, pathDependent = false) {
55599
55850
  const blocks = Array.isArray(value) ? value : value.sections.flatMap((s3) => s3.blocks);
55600
55851
  return {
55601
55852
  bytes: new TextEncoder().encode(JSON.stringify(value)).buffer,
55602
55853
  ids: new TextEncoder().encode(blocks.map(({ id: id2 }) => id2).join("\n")).buffer,
55603
- count: blocks.length
55854
+ count: blocks.length,
55855
+ pathDependent
55604
55856
  };
55605
55857
  }
55606
55858
  var executeWork = async (work) => {
55859
+ if (work.kind === "doc-metadata") {
55860
+ if (work.format === "html")
55861
+ return {
55862
+ kind: "doc-metadata",
55863
+ title: await inferDocTitle("html", new Uint8Array(work.bytes)),
55864
+ headings: htmlHeadings(decode4(work.bytes))
55865
+ };
55866
+ const blocks = await renderMetadataBlocks(decode4(work.bytes));
55867
+ return { kind: "doc-metadata", title: markdownTitle(blocks), headings: markdownHeadings(blocks) };
55868
+ }
55607
55869
  if (work.kind === "line-count") {
55608
55870
  const bytes = new Uint8Array(work.bytes);
55609
55871
  let count = bytes.length && bytes.at(-1) !== 10 ? 1 : 0;
@@ -55627,19 +55889,29 @@ var executeWork = async (work) => {
55627
55889
  const bytes = encoder3.encode(JSON.stringify(doc)).buffer;
55628
55890
  return { kind: "placement-doc", bytes, textBytes, encodedBytes: bytes.byteLength };
55629
55891
  }
55630
- if (work.kind === "writeup")
55892
+ if (work.kind === "writeup") {
55893
+ const effects = {};
55894
+ const rendered = await renderWriteup(work.source, work.topics, {
55895
+ links: work.links,
55896
+ repoUrl: work.repoUrl,
55897
+ media: new Map(work.media),
55898
+ docs: work.docs,
55899
+ effects
55900
+ });
55631
55901
  return {
55632
55902
  kind: "writeup",
55633
- ...serializeRendered(
55634
- await renderWriteup(work.source, work.topics, {
55635
- links: work.links,
55636
- repoUrl: work.repoUrl,
55637
- media: new Map(work.media)
55638
- })
55639
- )
55903
+ ...serializeRendered(rendered, effects.docBaseUsed)
55904
+ };
55905
+ }
55906
+ if (work.kind === "doc") {
55907
+ const effects = {};
55908
+ const blocks = await renderDoc(decode4(work.source), work.path, work.repoUrl, work.docs, effects);
55909
+ return {
55910
+ kind: "doc",
55911
+ ...serializeRendered(blocks, effects.docBaseUsed),
55912
+ selfDependent: effects.docPathUsed
55640
55913
  };
55641
- if (work.kind === "doc")
55642
- return { kind: "doc", ...serializeRendered(await renderDoc(decode4(work.source), work.path, work.repoUrl)) };
55914
+ }
55643
55915
  if (work.kind === "comment-md") {
55644
55916
  const html7 = [];
55645
55917
  for (const body3 of work.bodies) {
@@ -55677,8 +55949,8 @@ var executeWork = async (work) => {
55677
55949
  }
55678
55950
  return doc;
55679
55951
  };
55680
- const docs = /* @__PURE__ */ new Map();
55681
- for (const [path2, encoded] of work.parsedDocs ?? []) docs.set(path2, placementDoc(encoded));
55952
+ const docs2 = /* @__PURE__ */ new Map();
55953
+ for (const [path2, encoded] of work.parsedDocs ?? []) docs2.set(path2, placementDoc(encoded));
55682
55954
  const decoded = /* @__PURE__ */ new Map();
55683
55955
  const text10 = (hash2) => {
55684
55956
  const cached2 = decoded.get(hash2);
@@ -55697,9 +55969,9 @@ var executeWork = async (work) => {
55697
55969
  for (const [path2, doc] of work.docs) {
55698
55970
  if (doc.kind === "html") {
55699
55971
  if (!htmlTexts.has(doc.hash)) htmlTexts.set(doc.hash, docText(text10(doc.hash)));
55700
- docs.set(path2, { kind: "html", text: htmlTexts.get(doc.hash) ?? null });
55972
+ docs2.set(path2, { kind: "html", text: htmlTexts.get(doc.hash) ?? null });
55701
55973
  } else
55702
- docs.set(path2, {
55974
+ docs2.set(path2, {
55703
55975
  kind: "markdown",
55704
55976
  blocks: doc.hash ? parse7(work.texts.get(doc.hash) ?? new ArrayBuffer(0), "doc") : []
55705
55977
  });
@@ -55719,7 +55991,7 @@ var executeWork = async (work) => {
55719
55991
  id: thread.id,
55720
55992
  placement: placeThread(target, {
55721
55993
  writeup,
55722
- docs,
55994
+ docs: docs2,
55723
55995
  files,
55724
55996
  topics: work.topics,
55725
55997
  last: thread.last && carriedLocation ? { location: carriedLocation, sides: thread.last.sides ? sides(thread.last.sides) : void 0 } : null,
@@ -55731,9 +56003,14 @@ var executeWork = async (work) => {
55731
56003
  };
55732
56004
 
55733
56005
  // src/server/publish/worker.ts
56006
+ var docs;
55734
56007
  parentPort?.on("message", async (work) => {
56008
+ if (work.kind === "doc-context") {
56009
+ docs = work.docs;
56010
+ return;
56011
+ }
55735
56012
  try {
55736
- const result = await executeWork(work);
56013
+ const result = await executeWork(work.kind === "doc" || work.kind === "writeup" ? { ...work, docs } : work);
55737
56014
  parentPort?.postMessage(
55738
56015
  { ok: true, result },
55739
56016
  "ids" in result ? [result.bytes, result.ids] : "bytes" in result ? [result.bytes] : []