@youtyan/code-viewer 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-viewer.js +19 -4
- package/package.json +1 -1
- package/web/app.js +42 -1
- package/web/mermaid.js +6 -7
- package/web/shiki.js +3 -3
package/dist/code-viewer.js
CHANGED
|
@@ -188,9 +188,13 @@ function startServer(options) {
|
|
|
188
188
|
const request = nodeRequestToWeb(req, options.hostname, server.address());
|
|
189
189
|
const response = await options.fetch(request);
|
|
190
190
|
await writeWebResponse(res, response);
|
|
191
|
-
} catch {
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error("[code-viewer] request error:", req.method, req.url, error);
|
|
193
|
+
if (res.headersSent || res.writableEnded) {
|
|
194
|
+
res.destroy(error instanceof Error ? error : undefined);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
|
|
194
198
|
res.end("internal server error");
|
|
195
199
|
}
|
|
196
200
|
});
|
|
@@ -203,7 +207,18 @@ function startServer(options) {
|
|
|
203
207
|
});
|
|
204
208
|
const address = server.address();
|
|
205
209
|
const port = typeof address === "object" && address ? address.port : options.port;
|
|
206
|
-
resolve({
|
|
210
|
+
resolve({
|
|
211
|
+
port,
|
|
212
|
+
close: () => new Promise((resolveClose, rejectClose) => {
|
|
213
|
+
server.close((error) => {
|
|
214
|
+
if (error)
|
|
215
|
+
rejectClose(error);
|
|
216
|
+
else
|
|
217
|
+
resolveClose();
|
|
218
|
+
});
|
|
219
|
+
server.closeAllConnections?.();
|
|
220
|
+
})
|
|
221
|
+
});
|
|
207
222
|
});
|
|
208
223
|
});
|
|
209
224
|
}
|
package/package.json
CHANGED
package/web/app.js
CHANGED
|
@@ -90,6 +90,12 @@
|
|
|
90
90
|
function trailingClickRange(hunkEndNew, step) {
|
|
91
91
|
return { start: hunkEndNew, end: hunkEndNew + step - 1 };
|
|
92
92
|
}
|
|
93
|
+
function trailingExpandTargetIndex(hunkCount) {
|
|
94
|
+
return hunkCount > 0 ? hunkCount - 1 : null;
|
|
95
|
+
}
|
|
96
|
+
function shouldAttachTrailingExpand(probeLineCount) {
|
|
97
|
+
return probeLineCount > 0;
|
|
98
|
+
}
|
|
93
99
|
function applyTrailingResult(state, receivedCount, step) {
|
|
94
100
|
return {
|
|
95
101
|
newStart: state.newStart + receivedCount,
|
|
@@ -106,6 +112,8 @@
|
|
|
106
112
|
applyUp,
|
|
107
113
|
applyDown,
|
|
108
114
|
mapNewToOld,
|
|
115
|
+
trailingExpandTargetIndex,
|
|
116
|
+
shouldAttachTrailingExpand,
|
|
109
117
|
trailingClickRange,
|
|
110
118
|
applyTrailingResult
|
|
111
119
|
};
|
|
@@ -10310,6 +10318,10 @@ ${frontmatter.yaml}
|
|
|
10310
10318
|
for (const item of infoRows) {
|
|
10311
10319
|
attachExpandControls(item, file, ref, refPath);
|
|
10312
10320
|
}
|
|
10321
|
+
const trailingIndex = window.GdpExpandLogic.trailingExpandTargetIndex(infoRows.length);
|
|
10322
|
+
if (trailingIndex != null) {
|
|
10323
|
+
probeAndAttachTrailingExpandControls(infoRows[trailingIndex], file, ref, refPath);
|
|
10324
|
+
}
|
|
10313
10325
|
}
|
|
10314
10326
|
function attachExpandControls(item, file, ref, refPath) {
|
|
10315
10327
|
const { hunk, prevHunkEndNew, prevHunkEndOld } = item;
|
|
@@ -10451,7 +10463,10 @@ ${frontmatter.yaml}
|
|
|
10451
10463
|
requestAnimationFrame(syncHeight);
|
|
10452
10464
|
setTimeout(syncHeight, 100);
|
|
10453
10465
|
}
|
|
10454
|
-
function
|
|
10466
|
+
function attachTrailingExpandControls(item, file, ref, refPath) {
|
|
10467
|
+
const hasTrailingRow = (item.siblings || []).some((sib) => !!sib.tr.parentElement?.querySelector(".gdp-trailing-expand-row"));
|
|
10468
|
+
if (hasTrailingRow)
|
|
10469
|
+
return;
|
|
10455
10470
|
const STEP = 20;
|
|
10456
10471
|
let nextNewStart = nextNewLine(item.hunk);
|
|
10457
10472
|
let nextOldStart = nextOldLine(item.hunk);
|
|
@@ -10485,9 +10500,16 @@ ${frontmatter.yaml}
|
|
|
10485
10500
|
};
|
|
10486
10501
|
const fetchAndInsert = () => {
|
|
10487
10502
|
const range = window.GdpExpandLogic.trailingClickRange(nextNewStart, STEP);
|
|
10503
|
+
const myGen = SERVER_GENERATION;
|
|
10488
10504
|
setBusy(true);
|
|
10489
10505
|
const url = "/file_range?path=" + refPath + "&ref=" + encodeURIComponent(ref) + "&start=" + range.start + "&end=" + range.end;
|
|
10490
10506
|
trackLoad(fetch(url).then((r2) => r2.json())).then((data) => {
|
|
10507
|
+
if (myGen !== SERVER_GENERATION || data.generation && data.generation !== SERVER_GENERATION) {
|
|
10508
|
+
setBusy(false);
|
|
10509
|
+
return;
|
|
10510
|
+
}
|
|
10511
|
+
if (!item.tr.isConnected)
|
|
10512
|
+
return;
|
|
10491
10513
|
const lines = data?.lines || [];
|
|
10492
10514
|
if (!lines.length) {
|
|
10493
10515
|
rows.forEach((row) => {
|
|
@@ -10526,6 +10548,25 @@ ${frontmatter.yaml}
|
|
|
10526
10548
|
});
|
|
10527
10549
|
syncExpandRowHeights(rows.map((row) => row.tr), rows[0].tr);
|
|
10528
10550
|
}
|
|
10551
|
+
function probeAndAttachTrailingExpandControls(item, file, ref, refPath) {
|
|
10552
|
+
const start = nextNewLine(item.hunk);
|
|
10553
|
+
const myGen = SERVER_GENERATION;
|
|
10554
|
+
const url = "/file_range?path=" + refPath + "&ref=" + encodeURIComponent(ref) + "&start=" + start + "&end=" + start;
|
|
10555
|
+
trackLoad(fetch(url).then((r2) => r2.json())).then((data) => {
|
|
10556
|
+
if (myGen !== SERVER_GENERATION)
|
|
10557
|
+
return;
|
|
10558
|
+
if (data.generation && data.generation !== SERVER_GENERATION)
|
|
10559
|
+
return;
|
|
10560
|
+
if (!item.tr.isConnected)
|
|
10561
|
+
return;
|
|
10562
|
+
const hasTrailingRow = (item.siblings || []).some((sib) => !!sib.tr.parentElement?.querySelector(".gdp-trailing-expand-row"));
|
|
10563
|
+
if (hasTrailingRow)
|
|
10564
|
+
return;
|
|
10565
|
+
if (!window.GdpExpandLogic.shouldAttachTrailingExpand(data?.lines?.length || 0))
|
|
10566
|
+
return;
|
|
10567
|
+
attachTrailingExpandControls(item, file, ref, refPath);
|
|
10568
|
+
}).catch(() => {});
|
|
10569
|
+
}
|
|
10529
10570
|
function insertContextRows(targetTr, lines, newStart, oldStart, dir, sideIndex) {
|
|
10530
10571
|
const tbody = targetTr.parentElement;
|
|
10531
10572
|
if (!tbody)
|
package/web/mermaid.js
CHANGED
|
@@ -1930,8 +1930,7 @@ function createDOMPurify() {
|
|
|
1930
1930
|
;
|
|
1931
1931
|
else if (value) {
|
|
1932
1932
|
return false;
|
|
1933
|
-
}
|
|
1934
|
-
;
|
|
1933
|
+
}
|
|
1935
1934
|
return true;
|
|
1936
1935
|
};
|
|
1937
1936
|
const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, ["annotation-xml", "color-profile", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "missing-glyph"]);
|
|
@@ -78802,7 +78801,7 @@ var require_layout_base = __commonJS((exports, module) => {
|
|
|
78802
78801
|
result[2] = p2x;
|
|
78803
78802
|
result[3] = topLeftBy;
|
|
78804
78803
|
return false;
|
|
78805
|
-
}
|
|
78804
|
+
}
|
|
78806
78805
|
} else if (p1y === p2y) {
|
|
78807
78806
|
if (p1x > p2x) {
|
|
78808
78807
|
result[0] = topLeftAx;
|
|
@@ -78816,7 +78815,7 @@ var require_layout_base = __commonJS((exports, module) => {
|
|
|
78816
78815
|
result[2] = topLeftBx;
|
|
78817
78816
|
result[3] = p2y;
|
|
78818
78817
|
return false;
|
|
78819
|
-
}
|
|
78818
|
+
}
|
|
78820
78819
|
} else {
|
|
78821
78820
|
var slopeA = rectA.height / rectA.width;
|
|
78822
78821
|
var slopeB = rectB.height / rectB.width;
|
|
@@ -109930,7 +109929,7 @@ class DefaultDocumentBuilder {
|
|
|
109930
109929
|
options: options2,
|
|
109931
109930
|
result: state2?.result
|
|
109932
109931
|
});
|
|
109933
|
-
}
|
|
109932
|
+
}
|
|
109934
109933
|
}
|
|
109935
109934
|
}
|
|
109936
109935
|
async runCancelable(documents, targetState, cancelToken, callback) {
|
|
@@ -143202,7 +143201,7 @@ var require_layout_base2 = __commonJS((exports, module) => {
|
|
|
143202
143201
|
result[2] = p2x;
|
|
143203
143202
|
result[3] = topLeftBy;
|
|
143204
143203
|
return false;
|
|
143205
|
-
}
|
|
143204
|
+
}
|
|
143206
143205
|
} else if (p1y === p2y) {
|
|
143207
143206
|
if (p1x > p2x) {
|
|
143208
143207
|
result[0] = topLeftAx;
|
|
@@ -143216,7 +143215,7 @@ var require_layout_base2 = __commonJS((exports, module) => {
|
|
|
143216
143215
|
result[2] = topLeftBx;
|
|
143217
143216
|
result[3] = p2y;
|
|
143218
143217
|
return false;
|
|
143219
|
-
}
|
|
143218
|
+
}
|
|
143220
143219
|
} else {
|
|
143221
143220
|
var slopeA = rectA.height / rectA.width;
|
|
143222
143221
|
var slopeB = rectB.height / rectB.width;
|
package/web/shiki.js
CHANGED
|
@@ -7836,7 +7836,7 @@ var RuleFactory = class _RuleFactory {
|
|
|
7836
7836
|
let localIncludedRule = repository[reference.ruleName];
|
|
7837
7837
|
if (localIncludedRule) {
|
|
7838
7838
|
ruleId = _RuleFactory.getCompiledRuleId(localIncludedRule, helper, repository);
|
|
7839
|
-
}
|
|
7839
|
+
}
|
|
7840
7840
|
break;
|
|
7841
7841
|
case 3:
|
|
7842
7842
|
case 4:
|
|
@@ -7848,11 +7848,11 @@ var RuleFactory = class _RuleFactory {
|
|
|
7848
7848
|
let externalIncludedRule = externalGrammar.repository[externalGrammarInclude];
|
|
7849
7849
|
if (externalIncludedRule) {
|
|
7850
7850
|
ruleId = _RuleFactory.getCompiledRuleId(externalIncludedRule, helper, externalGrammar.repository);
|
|
7851
|
-
}
|
|
7851
|
+
}
|
|
7852
7852
|
} else {
|
|
7853
7853
|
ruleId = _RuleFactory.getCompiledRuleId(externalGrammar.repository.$self, helper, externalGrammar.repository);
|
|
7854
7854
|
}
|
|
7855
|
-
}
|
|
7855
|
+
}
|
|
7856
7856
|
break;
|
|
7857
7857
|
}
|
|
7858
7858
|
} else {
|