aegis-desktop 1.0.13 → 1.0.15
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/SOURCE-OFFER.txt +9 -0
- package/bin/aegis.js +1 -32
- package/lib/account-key.js +1 -56
- package/lib/auto.js +1 -430
- package/lib/avatar/companion.js +1 -698
- package/lib/avatar/cosmetics.js +1 -532
- package/lib/avatar/events.js +1 -344
- package/lib/avatar/holder-turn.js +1 -350
- package/lib/avatar/holders.js +1 -612
- package/lib/avatar/identity.js +1 -641
- package/lib/avatar/level.js +1 -368
- package/lib/avatar/mirror.js +1 -524
- package/lib/avatar/persona.js +1 -388
- package/lib/avatar/profile.js +1 -977
- package/lib/avatar/register.js +1 -307
- package/lib/avatar/store.js +1 -472
- package/lib/avatar/tiers.js +1 -38
- package/lib/avatar/transfer.js +1 -415
- package/lib/avatar/turn.js +1 -216
- package/lib/avatar/voice.js +1 -328
- package/lib/avatar/xp.js +1 -404
- package/lib/deep-link.js +1 -120
- package/lib/fingerprint.js +2 -347
- package/lib/google-connect.js +1 -169
- package/lib/local/agents.js +1 -105
- package/lib/local/autonomous.js +1 -1045
- package/lib/local/claude-pro.js +1 -993
- package/lib/local/context.js +1 -95
- package/lib/local/engine.js +1 -3228
- package/lib/local/entitlement.js +1 -654
- package/lib/local/git-scope.js +1 -228
- package/lib/local/local.js +1 -2135
- package/lib/local/prompt.js +1 -275
- package/lib/local/queue.js +1 -560
- package/lib/local/session-rounds.js +1 -208
- package/lib/local/shell.js +1 -680
- package/lib/local/telemetry.js +1 -470
- package/lib/local/tools.js +1 -1238
- package/lib/local/turn-guard.js +1 -300
- package/lib/local/worktree-lock.js +1 -235
- package/lib/provider-key-mirror.js +1 -252
- package/lib/quick-launcher.js +1 -84
- package/lib/settings.js +1 -890
- package/lib/sync/memory-queue.js +1 -60
- package/lib/sync/persist-gate.js +1 -148
- package/lib/sync/sessions.js +1 -106
- package/lib/window-state.js +1 -66
- package/main.js +3 -4390
- package/package.json +3 -5
- package/preload.js +3 -628
- package/renderer/app.js +1 -6560
- package/renderer/avatar/assemble.js +1 -335
- package/renderer/avatar/avatar.js +1 -380
- package/renderer/avatar/cards.js +1 -141
- package/renderer/avatar/hud.js +1 -206
- package/renderer/avatar/machine.js +1 -213
- package/renderer/avatar/pane.js +1 -439
- package/renderer/avatar/parts.js +1 -437
- package/renderer/budget.js +1 -168
- package/renderer/companion.js +1 -223
- package/renderer/diff.js +1 -359
- package/renderer/diffview.js +1 -336
- package/renderer/fingerprint.js +3 -720
- package/renderer/markdown.js +1 -168
- package/renderer/provider-toolbar.js +1 -134
- package/renderer/providers.js +1 -259
- package/renderer/quick.js +1 -191
- package/renderer/stream-policy.js +1 -306
- package/renderer/transcript-view.js +1 -323
- package/renderer/usage.js +1 -1239
- package/vendor/aegis.js +1 -2054
- package/vendor/attest.js +1 -442
- package/vendor/authorship-key.js +1 -410
- package/vendor/auto-provision.js +1 -134
- package/vendor/brain-catalog.js +1 -268
- package/vendor/byok-catalog.js +1 -230
- package/vendor/credentials.js +1 -494
- package/vendor/device-fingerprint.js +1 -141
- package/vendor/drive-connect.js +1 -85
- package/vendor/drive-upload.js +1 -174
- package/vendor/env-file.js +1 -1273
- package/vendor/fingerprint.js +1 -1064
- package/vendor/foreign-memory.js +1 -669
- package/vendor/google-signin.js +1 -125
- package/vendor/hooks.js +1 -430
- package/vendor/model-discovery.js +1 -330
- package/vendor/platform.js +1 -937
- package/vendor/prefs.js +1 -351
- package/vendor/presence-constants.js +1 -107
- package/vendor/presence.js +1 -438
- package/vendor/record-vault.js +3 -1055
- package/vendor/session-store.js +1 -548
- package/vendor/topup.js +1 -297
- package/vendor/touch.js +1 -458
- package/vendor/update.js +1 -704
- package/vendor/user-models.js +1 -381
package/renderer/diffview.js
CHANGED
|
@@ -1,338 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The edit block's paint layer for the DOM transcript: a one-line, clickable
|
|
10
|
-
* summary plus, when the block is open, the diff itself in Monokai Extended
|
|
11
|
-
* colors.
|
|
12
|
-
*
|
|
13
|
-
* Two shapes, driven by one boolean (`open`):
|
|
14
|
-
*
|
|
15
|
-
* collapsed ⎿ Update(src/diff.js) +12 -3 · click to view diff
|
|
16
|
-
*
|
|
17
|
-
* open ⎿ Update(src/diff.js) +12 -3 · click to collapse
|
|
18
|
-
* 12 const a = 1;
|
|
19
|
-
* 13 - const b = 2;
|
|
20
|
-
* 13 + const b = 3;
|
|
21
|
-
*
|
|
22
|
-
* This is the DOM twin of `cli/src/diffview.js`: same structure decisions, same
|
|
23
|
-
* tokenizer, but it builds real element nodes instead of ANSI strings. Small
|
|
24
|
-
* diffs open themselves (AUTO_OPEN_ROWS) so the common one-line edit is
|
|
25
|
-
* readable with no gesture at all; anything bigger starts collapsed so a
|
|
26
|
-
* 300-line rewrite cannot bury the transcript.
|
|
27
|
-
*
|
|
28
|
-
* Every piece of text goes in through `textContent`/`createTextNode` and never
|
|
29
|
-
* `innerHTML` — a diff's content is arbitrary file bytes, so the one thing this
|
|
30
|
-
* module must never do is let a line like `<img src=x onerror=…>` become live
|
|
31
|
-
* markup.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/** Diff body rows at or below this size open without a gesture. */
|
|
35
|
-
const AUTO_OPEN_ROWS = 30;
|
|
36
|
-
/** Rows painted inside one open block before the "… more diff lines" footer. */
|
|
37
|
-
const MAX_BLOCK_ROWS = 200;
|
|
38
|
-
|
|
39
|
-
// The Monokai Extended diff palette, copied from cli/src/theme.js's DIFF so the
|
|
40
|
-
// desktop block and the CLI block read as the same object.
|
|
41
|
-
const DIFF_COLORS = {
|
|
42
|
-
delFg: '#dc5a5a',
|
|
43
|
-
delBg: '#3d0100',
|
|
44
|
-
addFg: '#50c850',
|
|
45
|
-
addBg: '#022800',
|
|
46
|
-
delHiFg: '#f8f8f2',
|
|
47
|
-
delHiBg: '#5c0200',
|
|
48
|
-
addHiFg: '#ffffff',
|
|
49
|
-
addHiBg: '#044700',
|
|
50
|
-
codeFg: '#f8f8f2',
|
|
51
|
-
gutter: '#787878',
|
|
52
|
-
kind: '#c099ff',
|
|
53
|
-
kw: '#66d9ef',
|
|
54
|
-
fn: '#a6e22e',
|
|
55
|
-
str: '#e6db74',
|
|
56
|
-
num: '#ae81ff',
|
|
57
|
-
comment: '#75715e',
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const KEYWORDS = new Set([
|
|
61
|
-
'const', 'let', 'var', 'function', 'return', 'if', 'else', 'for', 'while', 'do', 'switch',
|
|
62
|
-
'case', 'break', 'continue', 'import', 'export', 'from', 'default', 'class', 'extends',
|
|
63
|
-
'new', 'try', 'catch', 'finally', 'throw', 'async', 'await', 'yield', 'static', 'typeof',
|
|
64
|
-
'instanceof', 'in', 'of', 'delete', 'this', 'super', 'null', 'undefined', 'true', 'false',
|
|
65
|
-
'def', 'elif', 'lambda', 'pass', 'raise', 'with', 'as', 'not', 'and', 'or', 'is', 'None',
|
|
66
|
-
'True', 'False', 'self', 'fn', 'mut', 'pub', 'impl', 'struct', 'enum', 'trait', 'match',
|
|
67
|
-
'package', 'func', 'defer', 'chan', 'nil', 'echo', 'local', 'then', 'fi', 'esac',
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Split one line of code into colored tokens. Deliberately line-local and cheap
|
|
72
|
-
* — it runs on every changed row of every block — so it colors comments,
|
|
73
|
-
* strings, numbers, keywords and called functions and leaves the rest plain,
|
|
74
|
-
* which is all the tinted diff rows need to read as code.
|
|
75
|
-
*
|
|
76
|
-
* @param {string} text
|
|
77
|
-
* @param {object} [d] Diff palette (defaults to the dark one).
|
|
78
|
-
* @returns {Array<{t: string, c: string}>} tokens; `c` is a foreground color.
|
|
79
|
-
*/
|
|
80
|
-
function highlightLine(text, d) {
|
|
81
|
-
const D = d || DIFF_COLORS;
|
|
82
|
-
const out = [];
|
|
83
|
-
const src = String(text == null ? '' : text);
|
|
84
|
-
const re = /(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|(0[xX][0-9a-fA-F]+|\d+(?:\.\d+)?)|([A-Za-z_$][A-Za-z0-9_$]*)/g;
|
|
85
|
-
const push = (t, c) => { if (t) out.push({ t, c }); };
|
|
86
|
-
let last = 0;
|
|
87
|
-
let m;
|
|
88
|
-
while ((m = re.exec(src))) {
|
|
89
|
-
if (m.index > last) push(src.slice(last, m.index), D.codeFg);
|
|
90
|
-
if (m[1]) push(m[1], D.comment);
|
|
91
|
-
else if (m[2]) push(m[2], D.str);
|
|
92
|
-
else if (m[3]) push(m[3], D.num);
|
|
93
|
-
else {
|
|
94
|
-
const word = m[4];
|
|
95
|
-
const isCall = /^\s*\(/.test(src.slice(m.index + word.length));
|
|
96
|
-
push(word, KEYWORDS.has(word) ? D.kw : isCall ? D.fn : D.codeFg);
|
|
97
|
-
}
|
|
98
|
-
last = m.index + m[0].length;
|
|
99
|
-
}
|
|
100
|
-
if (last < src.length) push(src.slice(last), D.codeFg);
|
|
101
|
-
return out;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Pair a run of removed rows with the added run that follows it and mark the
|
|
106
|
-
* slice that actually differs, so the changed word renders in the bright
|
|
107
|
-
* variant of the diff color. Equal run lengths only, and only when the shared
|
|
108
|
-
* prefix+suffix dominates the line — otherwise the mark would land on
|
|
109
|
-
* unrelated text. Mutates rows in place, adding `hi = {start, end, side}` in
|
|
110
|
-
* code-point offsets.
|
|
111
|
-
*/
|
|
112
|
-
function markIntraLine(rows) {
|
|
113
|
-
for (let i = 0; i < rows.length; i++) {
|
|
114
|
-
if (rows[i].sign !== '-') continue;
|
|
115
|
-
let d = i;
|
|
116
|
-
while (d < rows.length && rows[d].sign === '-') d++;
|
|
117
|
-
let a = d;
|
|
118
|
-
while (a < rows.length && rows[a].sign === '+') a++;
|
|
119
|
-
const delCount = d - i;
|
|
120
|
-
const addCount = a - d;
|
|
121
|
-
if (delCount && delCount === addCount) {
|
|
122
|
-
for (let k = 0; k < delCount; k++) {
|
|
123
|
-
const pair = intraLine(rows[i + k].text, rows[d + k].text);
|
|
124
|
-
if (!pair) continue;
|
|
125
|
-
rows[i + k].hi = { start: pair.delStart, end: pair.delEnd, side: 'del' };
|
|
126
|
-
rows[d + k].hi = { start: pair.addStart, end: pair.addEnd, side: 'add' };
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
i = a - 1;
|
|
130
|
-
}
|
|
131
|
-
return rows;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function intraLine(delText, addText) {
|
|
135
|
-
const d = [...String(delText == null ? '' : delText)];
|
|
136
|
-
const a = [...String(addText == null ? '' : addText)];
|
|
137
|
-
let pre = 0;
|
|
138
|
-
while (pre < d.length && pre < a.length && d[pre] === a[pre]) pre++;
|
|
139
|
-
let post = 0;
|
|
140
|
-
while (post < d.length - pre && post < a.length - pre && d[d.length - 1 - post] === a[a.length - 1 - post]) post++;
|
|
141
|
-
const shared = pre + post;
|
|
142
|
-
const longest = Math.max(d.length, a.length) || 1;
|
|
143
|
-
if (shared < longest * 0.4) return null;
|
|
144
|
-
return {
|
|
145
|
-
delStart: pre,
|
|
146
|
-
delEnd: d.length - post,
|
|
147
|
-
addStart: pre,
|
|
148
|
-
addEnd: a.length - post,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Should this preview start open? Small diffs (the routine edit) do, so the
|
|
154
|
-
* change is readable immediately; a big one stays a one-line summary.
|
|
155
|
-
*/
|
|
156
|
-
function defaultOpen(preview) {
|
|
157
|
-
if (!preview || !preview.rows) return false;
|
|
158
|
-
return preview.rows.length <= AUTO_OPEN_ROWS;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/** One colored span. `bg` set means this is an intra-line highlight slice. */
|
|
162
|
-
function tokenSpan(document, text, color, bg, fg) {
|
|
163
|
-
const span = document.createElement('span');
|
|
164
|
-
if (bg) {
|
|
165
|
-
span.style.background = bg;
|
|
166
|
-
span.style.color = fg;
|
|
167
|
-
} else {
|
|
168
|
-
span.style.color = color;
|
|
169
|
-
}
|
|
170
|
-
span.textContent = String(text);
|
|
171
|
-
return span;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** A single colored code/highlight fragment inside a row's `.diff-code`. */
|
|
175
|
-
function appendCode(document, container, text, hi) {
|
|
176
|
-
const src = String(text == null ? '' : text);
|
|
177
|
-
let idx = 0;
|
|
178
|
-
for (const tk of highlightLine(src, DIFF_COLORS)) {
|
|
179
|
-
const chars = [...tk.t];
|
|
180
|
-
const start = idx;
|
|
181
|
-
const end = idx + chars.length;
|
|
182
|
-
idx = end;
|
|
183
|
-
if (!hi || end <= hi.start || start >= hi.end) {
|
|
184
|
-
container.appendChild(tokenSpan(document, tk.t, tk.c));
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
const a = Math.max(hi.start, start) - start;
|
|
188
|
-
const b = Math.min(hi.end, end) - start;
|
|
189
|
-
if (a > 0) container.appendChild(tokenSpan(document, chars.slice(0, a).join(''), tk.c));
|
|
190
|
-
if (b > a) {
|
|
191
|
-
const bg = hi.side === 'del' ? DIFF_COLORS.delHiBg : DIFF_COLORS.addHiBg;
|
|
192
|
-
const fg = hi.side === 'del' ? DIFF_COLORS.delHiFg : DIFF_COLORS.addHiFg;
|
|
193
|
-
container.appendChild(tokenSpan(document, chars.slice(a, b).join(''), null, bg, fg));
|
|
194
|
-
}
|
|
195
|
-
if (b < chars.length) container.appendChild(tokenSpan(document, chars.slice(b).join(''), tk.c));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/** One `<div class="diff-row diff-add|diff-del|diff-ctx">` with gutter + tokens. */
|
|
200
|
-
function renderRow(document, r, gutterW) {
|
|
201
|
-
const side = r.sign === '-' ? 'del' : r.sign === '+' ? 'add' : 'ctx';
|
|
202
|
-
const row = document.createElement('div');
|
|
203
|
-
row.className = `diff-row diff-${side}`;
|
|
204
|
-
|
|
205
|
-
const gutter = document.createElement('span');
|
|
206
|
-
gutter.className = 'diff-gutter';
|
|
207
|
-
gutter.textContent = `${String(r.no == null ? '' : r.no).padStart(gutterW)} `;
|
|
208
|
-
row.appendChild(gutter);
|
|
209
|
-
|
|
210
|
-
const sign = document.createElement('span');
|
|
211
|
-
sign.className = 'diff-sign';
|
|
212
|
-
sign.textContent = r.sign === ' ' ? ' ' : r.sign;
|
|
213
|
-
row.appendChild(sign);
|
|
214
|
-
|
|
215
|
-
const code = document.createElement('span');
|
|
216
|
-
code.className = 'diff-code';
|
|
217
|
-
appendCode(document, code, r.text, r.hi);
|
|
218
|
-
row.appendChild(code);
|
|
219
|
-
|
|
220
|
-
return row;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** A collapsed-context / truncation row: `.diff-marker`. */
|
|
224
|
-
function markerRow(document, note) {
|
|
225
|
-
const row = document.createElement('div');
|
|
226
|
-
row.className = 'diff-row diff-marker';
|
|
227
|
-
const code = document.createElement('span');
|
|
228
|
-
code.className = 'diff-code';
|
|
229
|
-
code.textContent = String(note == null ? '' : note);
|
|
230
|
-
row.appendChild(code);
|
|
231
|
-
return row;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Build the collapsible diff block for one edit preview.
|
|
236
|
-
*
|
|
237
|
-
* @param {object} preview From diff.js's editPreview(). Falsy → null.
|
|
238
|
-
* @param {Document} doc The document (injectable so tests need no jsdom).
|
|
239
|
-
* @param {{open?: boolean}} [opts] `open` overrides the AUTO_OPEN_ROWS default.
|
|
240
|
-
* @returns {HTMLElement|null} `div.diff-block` with a clickable `.diff-summary`.
|
|
241
|
-
*/
|
|
242
|
-
function renderDiffBlock(preview, doc, opts = {}) {
|
|
243
|
-
const document = doc || (typeof document !== 'undefined' ? document : null);
|
|
244
|
-
if (!document || !preview || !preview.rows) return null;
|
|
245
|
-
let open = opts.open == null ? defaultOpen(preview) : !!opts.open;
|
|
246
|
-
|
|
247
|
-
const block = document.createElement('div');
|
|
248
|
-
block.className = 'diff-block';
|
|
249
|
-
|
|
250
|
-
const summary = document.createElement('div');
|
|
251
|
-
summary.className = 'diff-summary';
|
|
252
|
-
if (typeof summary.setAttribute === 'function') {
|
|
253
|
-
summary.setAttribute('role', 'button');
|
|
254
|
-
summary.setAttribute('aria-expanded', String(open));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const body = document.createElement('div');
|
|
258
|
-
body.className = 'diff-body';
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Repaint just the summary's text segments. Called on every toggle so the
|
|
262
|
-
* "click to view/collapse" hint and aria-expanded always match the state.
|
|
263
|
-
*/
|
|
264
|
-
function paintSummary() {
|
|
265
|
-
summary.textContent = '';
|
|
266
|
-
const segs = [
|
|
267
|
-
{ t: '⎿ ', c: DIFF_COLORS.gutter },
|
|
268
|
-
{ t: `${preview.kind}(${preview.short})`, c: DIFF_COLORS.kind },
|
|
269
|
-
];
|
|
270
|
-
if (preview.adds) segs.push({ t: ` +${preview.adds}`, c: DIFF_COLORS.addFg });
|
|
271
|
-
if (preview.dels) segs.push({ t: ` -${preview.dels}`, c: DIFF_COLORS.delFg });
|
|
272
|
-
if (!preview.adds && !preview.dels) segs.push({ t: ' no line changes', c: DIFF_COLORS.gutter });
|
|
273
|
-
if (preview.misses) segs.push({ t: ` ${preview.misses} edit(s) not applied`, c: '#ffd166' });
|
|
274
|
-
segs.push({ t: ` ${open ? '· click to collapse' : '· click to view diff'}`, c: DIFF_COLORS.comment });
|
|
275
|
-
for (const s of segs) {
|
|
276
|
-
const span = document.createElement('span');
|
|
277
|
-
span.style.color = s.c;
|
|
278
|
-
span.textContent = s.t;
|
|
279
|
-
summary.appendChild(span);
|
|
280
|
-
}
|
|
281
|
-
if (typeof summary.setAttribute === 'function') summary.setAttribute('aria-expanded', String(open));
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/** Repaint the body rows. Nothing is built while collapsed. */
|
|
285
|
-
function paintBody() {
|
|
286
|
-
body.textContent = '';
|
|
287
|
-
if (!open) return;
|
|
288
|
-
const rows = markIntraLine(
|
|
289
|
-
preview.rows.slice(0, MAX_BLOCK_ROWS).map((r) => Object.assign({}, r)),
|
|
290
|
-
);
|
|
291
|
-
let maxNo = 1;
|
|
292
|
-
for (const r of rows) if (r.no && r.no > maxNo) maxNo = r.no;
|
|
293
|
-
const gutterW = Math.max(2, String(maxNo).length);
|
|
294
|
-
for (const r of rows) {
|
|
295
|
-
if (r.marker) body.appendChild(markerRow(document, r.note));
|
|
296
|
-
else body.appendChild(renderRow(document, r, gutterW));
|
|
297
|
-
}
|
|
298
|
-
const hidden = preview.rows.length - MAX_BLOCK_ROWS;
|
|
299
|
-
if (hidden > 0) body.appendChild(markerRow(document, `… ${hidden} more diff lines`));
|
|
300
|
-
if (preview.truncated) {
|
|
301
|
-
body.appendChild(markerRow(document, '… diff truncated (file too large to compare in full)'));
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/** The whole point: clicking the summary flips the one block's open state. */
|
|
306
|
-
function toggle() {
|
|
307
|
-
open = !open;
|
|
308
|
-
paintSummary();
|
|
309
|
-
paintBody();
|
|
310
|
-
}
|
|
311
|
-
if (typeof summary.addEventListener === 'function') {
|
|
312
|
-
summary.addEventListener('click', toggle);
|
|
313
|
-
summary.addEventListener('keydown', (e) => {
|
|
314
|
-
if (e && (e.key === 'Enter' || e.key === ' ')) {
|
|
315
|
-
if (typeof e.preventDefault === 'function') e.preventDefault();
|
|
316
|
-
toggle();
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
paintSummary();
|
|
322
|
-
paintBody();
|
|
323
|
-
block.appendChild(summary);
|
|
324
|
-
block.appendChild(body);
|
|
325
|
-
return block;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
329
|
-
module.exports = {
|
|
330
|
-
AUTO_OPEN_ROWS,
|
|
331
|
-
MAX_BLOCK_ROWS,
|
|
332
|
-
DIFF_COLORS,
|
|
333
|
-
defaultOpen,
|
|
334
|
-
highlightLine,
|
|
335
|
-
markIntraLine,
|
|
336
|
-
renderDiffBlock,
|
|
337
|
-
};
|
|
338
|
-
}
|
|
3
|
+
"use strict";const AUTO_OPEN_ROWS=30,MAX_BLOCK_ROWS=200,DIFF_COLORS={delFg:"#dc5a5a",delBg:"#3d0100",addFg:"#50c850",addBg:"#022800",delHiFg:"#f8f8f2",delHiBg:"#5c0200",addHiFg:"#ffffff",addHiBg:"#044700",codeFg:"#f8f8f2",gutter:"#787878",kind:"#c099ff",kw:"#66d9ef",fn:"#a6e22e",str:"#e6db74",num:"#ae81ff",comment:"#75715e"},KEYWORDS=new Set(["const","let","var","function","return","if","else","for","while","do","switch","case","break","continue","import","export","from","default","class","extends","new","try","catch","finally","throw","async","await","yield","static","typeof","instanceof","in","of","delete","this","super","null","undefined","true","false","def","elif","lambda","pass","raise","with","as","not","and","or","is","None","True","False","self","fn","mut","pub","impl","struct","enum","trait","match","package","func","defer","chan","nil","echo","local","then","fi","esac"]);function highlightLine(e,t){const n=t||DIFF_COLORS,i=[],d=String(null==e?"":e),l=/(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|(0[xX][0-9a-fA-F]+|\d+(?:\.\d+)?)|([A-Za-z_$][A-Za-z0-9_$]*)/g,a=(e,t)=>{e&&i.push({t:e,c:t})};let o,s=0;for(;o=l.exec(d);){if(o.index>s&&a(d.slice(s,o.index),n.codeFg),o[1])a(o[1],n.comment);else if(o[2])a(o[2],n.str);else if(o[3])a(o[3],n.num);else{const e=o[4],t=/^\s*\(/.test(d.slice(o.index+e.length));a(e,KEYWORDS.has(e)?n.kw:t?n.fn:n.codeFg)}s=o.index+o[0].length}return s<d.length&&a(d.slice(s),n.codeFg),i}function markIntraLine(e){for(let t=0;t<e.length;t++){if("-"!==e[t].sign)continue;let n=t;for(;n<e.length&&"-"===e[n].sign;)n++;let i=n;for(;i<e.length&&"+"===e[i].sign;)i++;const d=n-t;if(d&&d===i-n)for(let i=0;i<d;i++){const d=intraLine(e[t+i].text,e[n+i].text);d&&(e[t+i].hi={start:d.delStart,end:d.delEnd,side:"del"},e[n+i].hi={start:d.addStart,end:d.addEnd,side:"add"})}t=i-1}return e}function intraLine(e,t){const n=[...String(null==e?"":e)],i=[...String(null==t?"":t)];let d=0;for(;d<n.length&&d<i.length&&n[d]===i[d];)d++;let l=0;for(;l<n.length-d&&l<i.length-d&&n[n.length-1-l]===i[i.length-1-l];)l++;return d+l<.4*(Math.max(n.length,i.length)||1)?null:{delStart:d,delEnd:n.length-l,addStart:d,addEnd:i.length-l}}function defaultOpen(e){return!(!e||!e.rows)&&e.rows.length<=AUTO_OPEN_ROWS}function tokenSpan(e,t,n,i,d){const l=e.createElement("span");return i?(l.style.background=i,l.style.color=d):l.style.color=n,l.textContent=String(t),l}function appendCode(e,t,n,i){const d=String(null==n?"":n);let l=0;for(const n of highlightLine(d,DIFF_COLORS)){const d=[...n.t],a=l,o=l+d.length;if(l=o,!i||o<=i.start||a>=i.end){t.appendChild(tokenSpan(e,n.t,n.c));continue}const s=Math.max(i.start,a)-a,r=Math.min(i.end,o)-a;if(s>0&&t.appendChild(tokenSpan(e,d.slice(0,s).join(""),n.c)),r>s){const n="del"===i.side?DIFF_COLORS.delHiBg:DIFF_COLORS.addHiBg,l="del"===i.side?DIFF_COLORS.delHiFg:DIFF_COLORS.addHiFg;t.appendChild(tokenSpan(e,d.slice(s,r).join(""),null,n,l))}r<d.length&&t.appendChild(tokenSpan(e,d.slice(r).join(""),n.c))}}function renderRow(e,t,n){const i="-"===t.sign?"del":"+"===t.sign?"add":"ctx",d=e.createElement("div");d.className=`diff-row diff-${i}`;const l=e.createElement("span");l.className="diff-gutter",l.textContent=`${String(null==t.no?"":t.no).padStart(n)} `,d.appendChild(l);const a=e.createElement("span");a.className="diff-sign",a.textContent=" "===t.sign?" ":t.sign,d.appendChild(a);const o=e.createElement("span");return o.className="diff-code",appendCode(e,o,t.text,t.hi),d.appendChild(o),d}function markerRow(e,t){const n=e.createElement("div");n.className="diff-row diff-marker";const i=e.createElement("span");return i.className="diff-code",i.textContent=String(null==t?"":t),n.appendChild(i),n}function renderDiffBlock(e,t,n={}){const i=t||(void 0!==i?i:null);if(!i||!e||!e.rows)return null;let d=null==n.open?defaultOpen(e):!!n.open;const l=i.createElement("div");l.className="diff-block";const a=i.createElement("div");a.className="diff-summary","function"==typeof a.setAttribute&&(a.setAttribute("role","button"),a.setAttribute("aria-expanded",String(d)));const o=i.createElement("div");function s(){a.textContent="";const t=[{t:"⎿ ",c:DIFF_COLORS.gutter},{t:`${e.kind}(${e.short})`,c:DIFF_COLORS.kind}];e.adds&&t.push({t:` +${e.adds}`,c:DIFF_COLORS.addFg}),e.dels&&t.push({t:` -${e.dels}`,c:DIFF_COLORS.delFg}),e.adds||e.dels||t.push({t:" no line changes",c:DIFF_COLORS.gutter}),e.misses&&t.push({t:` ${e.misses} edit(s) not applied`,c:"#ffd166"}),t.push({t:" "+(d?"· click to collapse":"· click to view diff"),c:DIFF_COLORS.comment});for(const e of t){const t=i.createElement("span");t.style.color=e.c,t.textContent=e.t,a.appendChild(t)}"function"==typeof a.setAttribute&&a.setAttribute("aria-expanded",String(d))}function r(){if(o.textContent="",!d)return;const t=markIntraLine(e.rows.slice(0,200).map((e=>Object.assign({},e))));let n=1;for(const e of t)e.no&&e.no>n&&(n=e.no);const l=Math.max(2,String(n).length);for(const e of t)e.marker?o.appendChild(markerRow(i,e.note)):o.appendChild(renderRow(i,e,l));const a=e.rows.length-200;a>0&&o.appendChild(markerRow(i,`… ${a} more diff lines`)),e.truncated&&o.appendChild(markerRow(i,"… diff truncated (file too large to compare in full)"))}function c(){d=!d,s(),r()}return o.className="diff-body","function"==typeof a.addEventListener&&(a.addEventListener("click",c),a.addEventListener("keydown",(e=>{!e||"Enter"!==e.key&&" "!==e.key||("function"==typeof e.preventDefault&&e.preventDefault(),c())}))),s(),r(),l.appendChild(a),l.appendChild(o),l}"undefined"!=typeof module&&module.exports&&(module.exports={AUTO_OPEN_ROWS:AUTO_OPEN_ROWS,MAX_BLOCK_ROWS:200,DIFF_COLORS:DIFF_COLORS,defaultOpen:defaultOpen,highlightLine:highlightLine,markIntraLine:markIntraLine,renderDiffBlock:renderDiffBlock});
|