path_coverage 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/README.md +286 -199
- data/exe/path_coverage_report +4 -0
- data/lib/path_coverage/call_trace.rb +88 -0
- data/lib/path_coverage/calls.rb +49 -43
- data/lib/path_coverage/card_context.rb +104 -0
- data/lib/path_coverage/card_forks.rb +44 -0
- data/lib/path_coverage/card_gaps.rb +125 -0
- data/lib/path_coverage/card_scopes.rb +37 -0
- data/lib/path_coverage/card_tree.rb +79 -66
- data/lib/path_coverage/card_way_lists.rb +72 -0
- data/lib/path_coverage/card_ways.rb +123 -67
- data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +35 -33
- data/lib/path_coverage/condition.rb +14 -14
- data/lib/path_coverage/configuration.rb +7 -4
- data/lib/path_coverage/configuration_limits.rb +52 -0
- data/lib/path_coverage/configuration_paths.rb +7 -7
- data/lib/path_coverage/console_summary.rb +24 -22
- data/lib/path_coverage/{site.rb → decision.rb} +2 -2
- data/lib/path_coverage/decision_locations.rb +76 -0
- data/lib/path_coverage/{site_paths.rb → decision_paths.rb} +13 -11
- data/lib/path_coverage/{site_tree.rb → decision_tree.rb} +25 -16
- data/lib/path_coverage/fold_branches.rb +18 -0
- data/lib/path_coverage/fold_cells.rb +42 -0
- data/lib/path_coverage/{html_tree.rb → fold_rows.rb} +42 -71
- data/lib/path_coverage/gaps.rb +33 -15
- data/lib/path_coverage/json_reader.rb +54 -19
- data/lib/path_coverage/json_reports.rb +102 -0
- data/lib/path_coverage/json_writer.rb +27 -12
- data/lib/path_coverage/kernel.rb +56 -58
- data/lib/path_coverage/kinds/base.rb +16 -16
- data/lib/path_coverage/kinds/block.rb +16 -15
- data/lib/path_coverage/kinds/case.rb +14 -12
- data/lib/path_coverage/kinds/chain.rb +40 -11
- data/lib/path_coverage/kinds/choice.rb +4 -3
- data/lib/path_coverage/kinds/contains.rb +40 -32
- data/lib/path_coverage/kinds/safe.rb +38 -26
- data/lib/path_coverage/kinds/write.rb +6 -6
- data/lib/path_coverage/kinds.rb +2 -2
- data/lib/path_coverage/leaving.rb +44 -0
- data/lib/path_coverage/loop_forks.rb +57 -0
- data/lib/path_coverage/loop_nodes.rb +55 -0
- data/lib/path_coverage/manifest.rb +92 -58
- data/lib/path_coverage/manifest_blocks.rb +5 -26
- data/lib/path_coverage/manifest_case.rb +2 -2
- data/lib/path_coverage/manifest_chains.rb +8 -8
- data/lib/path_coverage/manifest_choices.rb +23 -20
- data/lib/path_coverage/manifest_disabled.rb +97 -0
- data/lib/path_coverage/manifest_folding.rb +43 -40
- data/lib/path_coverage/manifest_ignoring.rb +6 -6
- data/lib/path_coverage/manifest_writes.rb +11 -10
- data/lib/path_coverage/measured_by.rb +20 -0
- data/lib/path_coverage/merge.rb +7 -7
- data/lib/path_coverage/method_loops.rb +128 -0
- data/lib/path_coverage/method_statements.rb +130 -127
- data/lib/path_coverage/method_ways.rb +142 -0
- data/lib/path_coverage/paths_report.rb +16 -16
- data/lib/path_coverage/recorder.rb +57 -36
- data/lib/path_coverage/recorder_blocks.rb +17 -17
- data/lib/path_coverage/recorder_cases.rb +12 -11
- data/lib/path_coverage/recorder_chains.rb +12 -12
- data/lib/path_coverage/recorder_writes.rb +9 -9
- data/lib/path_coverage/render.rb +58 -51
- data/lib/path_coverage/result.rb +32 -31
- data/lib/path_coverage/rewriter.rb +39 -27
- data/lib/path_coverage/rewriter_nested.rb +13 -13
- data/lib/path_coverage/runs_report.rb +84 -0
- data/lib/path_coverage/source_lines.rb +16 -16
- data/lib/path_coverage/source_report.rb +100 -0
- data/lib/path_coverage/stable_leaves.rb +162 -0
- data/lib/path_coverage/statement_arms.rb +31 -30
- data/lib/path_coverage/summary.rb +4 -62
- data/lib/path_coverage/totals.rb +10 -8
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/walk.rb +106 -0
- data/lib/path_coverage/way_algebras.rb +127 -0
- data/lib/path_coverage/ways_report.rb +91 -0
- data/lib/path_coverage/ways_totals.rb +46 -0
- data/lib/path_coverage/within_methods.rb +135 -80
- metadata +33 -28
- data/lib/path_coverage/card.rb +0 -14
- data/lib/path_coverage/html/file.html +0 -33
- data/lib/path_coverage/html/index.html +0 -29
- data/lib/path_coverage/html/settings.js +0 -50
- data/lib/path_coverage/html/side.js +0 -599
- data/lib/path_coverage/html/sort.js +0 -34
- data/lib/path_coverage/html/style.css +0 -484
- data/lib/path_coverage/html/tabs.js +0 -15
- data/lib/path_coverage/html/theme.js +0 -27
- data/lib/path_coverage/html_branch.rb +0 -30
- data/lib/path_coverage/html_cards.rb +0 -88
- data/lib/path_coverage/html_cells.rb +0 -71
- data/lib/path_coverage/html_file.rb +0 -123
- data/lib/path_coverage/html_index.rb +0 -128
- data/lib/path_coverage/html_index_head.rb +0 -29
- data/lib/path_coverage/html_labels.rb +0 -16
- data/lib/path_coverage/html_methods.rb +0 -66
- data/lib/path_coverage/html_nav.rb +0 -67
- data/lib/path_coverage/html_report.rb +0 -131
- data/lib/path_coverage/html_statements.rb +0 -186
- data/lib/path_coverage/html_tabs.rb +0 -26
- data/lib/path_coverage/html_template.rb +0 -26
|
@@ -1,599 +0,0 @@
|
|
|
1
|
-
// The behaviour of a file's page: its cards sit in the rail left
|
|
2
|
-
// of the code, one open at a time, level with its first line. A
|
|
3
|
-
// method's def number opens its card, unfolding its body; a loose
|
|
4
|
-
// site's button, outside every method, opens its lines' top card.
|
|
5
|
-
// The page's markup, from the Ruby, already marks every method's
|
|
6
|
-
// lines, numbers and rows; this only opens, closes and places.
|
|
7
|
-
(function () {
|
|
8
|
-
var code = document.querySelector('.code');
|
|
9
|
-
if (!code) { return; }
|
|
10
|
-
var box = code.parentElement;
|
|
11
|
-
var rail = document.querySelector('.rail');
|
|
12
|
-
var divider = document.querySelector('.divider');
|
|
13
|
-
var grids = Array.prototype.slice.call(document.querySelectorAll('.pathgrid'));
|
|
14
|
-
|
|
15
|
-
// True for a top card, of sites outside every method.
|
|
16
|
-
function isTop(grid) {
|
|
17
|
-
return grid.classList.contains('top-level');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// A card's first and last lines.
|
|
21
|
-
function firstOf(grid) { return Number(grid.getAttribute('data-first')); }
|
|
22
|
-
function lastOf(grid) { return Number(grid.getAttribute('data-last')); }
|
|
23
|
-
|
|
24
|
-
// The number span of line n.
|
|
25
|
-
function lineno(n) {
|
|
26
|
-
return document.getElementById('L' + n);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// The row, a line or a loose site's block, holding line n.
|
|
30
|
-
function rowOf(n) {
|
|
31
|
-
return lineno(n).closest('.line, .block');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// The code span of line n, whether a line's own or one of a
|
|
35
|
-
// loose site's lines.
|
|
36
|
-
function srcOf(n) {
|
|
37
|
-
var number = lineno(n);
|
|
38
|
-
if (!number) { return null; }
|
|
39
|
-
var button = number.closest('button.lnum');
|
|
40
|
-
if (!button) { return number.parentElement.querySelector('.src'); }
|
|
41
|
-
var index = Array.prototype.indexOf.call(button.querySelectorAll('.lineno'), number);
|
|
42
|
-
return button.closest('.block').querySelectorAll('.srcs > .src')[index];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// The code of each method's lines, from its def to its end,
|
|
46
|
-
// which thickens its stripe while its card is open; none for a
|
|
47
|
-
// top card.
|
|
48
|
-
var methodSrcs = grids.map(function (grid) {
|
|
49
|
-
if (isTop(grid)) { return []; }
|
|
50
|
-
var srcs = [];
|
|
51
|
-
for (var n = firstOf(grid); n <= lastOf(grid); n++) { srcs.push(srcOf(n)); }
|
|
52
|
-
return srcs;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// The rows of each method's body, after its def line to its end,
|
|
56
|
-
// folded under its def line while its card is closed; a row
|
|
57
|
-
// holding its def line too is never folded. None for a top card.
|
|
58
|
-
var methodRows = grids.map(function (grid) {
|
|
59
|
-
if (isTop(grid)) { return []; }
|
|
60
|
-
var def = rowOf(firstOf(grid));
|
|
61
|
-
var rows = [];
|
|
62
|
-
for (var n = firstOf(grid) + 1; n <= lastOf(grid); n++) {
|
|
63
|
-
var row = rowOf(n);
|
|
64
|
-
if (row !== def && rows.indexOf(row) < 0) { rows.push(row); }
|
|
65
|
-
}
|
|
66
|
-
return rows;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// The def number of each method's card, which opens it; null for
|
|
70
|
-
// a top card, which its site's button opens.
|
|
71
|
-
var defs = grids.map(function (grid) {
|
|
72
|
-
return isTop(grid) ? null : lineno(firstOf(grid));
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// The loose button opening each top card; null for a method's.
|
|
76
|
-
var buttons = grids.map(function (grid) {
|
|
77
|
-
return isTop(grid) ? document.querySelector('button.lnum[aria-controls="' + grid.id + '"]') : null;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Element's top, middle and bottom relative to within's top.
|
|
81
|
-
function spot(element, within) {
|
|
82
|
-
var rect = element.getBoundingClientRect();
|
|
83
|
-
var top = rect.top - within.getBoundingClientRect().top;
|
|
84
|
-
return { top: top, middle: top + rect.height / 2, bottom: top + rect.height };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Opens grid alone, null closing all: a method's card opens its
|
|
88
|
-
// body, every other method's folded; its def number, or its
|
|
89
|
-
// site's button, says it is open.
|
|
90
|
-
function openOnly(open) {
|
|
91
|
-
clear();
|
|
92
|
-
grids.forEach(function (grid, i) {
|
|
93
|
-
var shown = grid === open;
|
|
94
|
-
grid.hidden = !shown;
|
|
95
|
-
methodSrcs[i].forEach(function (src) { src.classList.toggle('method-open', shown); });
|
|
96
|
-
(defs[i] || buttons[i]).setAttribute('aria-expanded', String(shown));
|
|
97
|
-
});
|
|
98
|
-
foldBodies(grids.indexOf(open));
|
|
99
|
-
document.body.toggleAttribute('data-open', open !== null);
|
|
100
|
-
place();
|
|
101
|
-
stickDef();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// True when the method of grids[inner] is defined inside that of
|
|
105
|
-
// grids[outer], eg a def inside a def.
|
|
106
|
-
function nests(inner, outer) {
|
|
107
|
-
return firstOf(grids[outer]) < firstOf(grids[inner]) && lastOf(grids[inner]) <= lastOf(grids[outer]);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Folds every method's body but that of grids[open], none for -1:
|
|
111
|
-
// its rows show, but for those of any method inside it, which stay
|
|
112
|
-
// folded under their def lines; and its def line shows, with those
|
|
113
|
-
// of the methods it is inside, though they lie in folded bodies.
|
|
114
|
-
function foldBodies(open) {
|
|
115
|
-
var shown = [];
|
|
116
|
-
if (open >= 0) {
|
|
117
|
-
shown = methodRows[open].filter(function (row) {
|
|
118
|
-
return !grids.some(function (grid, j) {
|
|
119
|
-
return nests(j, open) && methodRows[j].indexOf(row) >= 0;
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
grids.forEach(function (grid, j) {
|
|
123
|
-
if (j === open || nests(open, j)) { shown.push(rowOf(firstOf(grid))); }
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
methodRows.forEach(function (rows) {
|
|
127
|
-
rows.forEach(function (row) { row.classList.toggle('method-folded', shown.indexOf(row) < 0); });
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// The narrowest the rail drags to, and the narrowest the code
|
|
132
|
-
// beside it is left.
|
|
133
|
-
var RAIL_MIN = 240;
|
|
134
|
-
var CODE_MIN = 320;
|
|
135
|
-
var RAIL_KEY = 'path_coverage.rail';
|
|
136
|
-
|
|
137
|
-
// Sets the rail to width pixels, kept within its bounds, and
|
|
138
|
-
// places the open card again beside it.
|
|
139
|
-
function setRail(width) {
|
|
140
|
-
var most = box.getBoundingClientRect().width - CODE_MIN;
|
|
141
|
-
var wide = Math.round(Math.max(RAIL_MIN, Math.min(most, width)));
|
|
142
|
-
document.body.style.setProperty('--rail', wide + 'px');
|
|
143
|
-
place();
|
|
144
|
-
return wide;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Dragging the divider sets the rail's width, kept in the
|
|
148
|
-
// browser, where it can be, for the next page.
|
|
149
|
-
divider.addEventListener('pointerdown', function (event) {
|
|
150
|
-
divider.setPointerCapture(event.pointerId);
|
|
151
|
-
divider.classList.add('dragging');
|
|
152
|
-
document.body.classList.add('dragging');
|
|
153
|
-
event.preventDefault();
|
|
154
|
-
});
|
|
155
|
-
divider.addEventListener('pointermove', function (event) {
|
|
156
|
-
if (!divider.classList.contains('dragging')) { return; }
|
|
157
|
-
setRail(event.clientX - box.getBoundingClientRect().left - 6);
|
|
158
|
-
});
|
|
159
|
-
divider.addEventListener('pointerup', function (event) {
|
|
160
|
-
divider.releasePointerCapture(event.pointerId);
|
|
161
|
-
divider.classList.remove('dragging');
|
|
162
|
-
document.body.classList.remove('dragging');
|
|
163
|
-
var wide = parseInt(document.body.style.getPropertyValue('--rail'), 10);
|
|
164
|
-
try { window.localStorage.setItem(RAIL_KEY, String(wide)); } catch (e) { /* this page only */ }
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// The rail's width kept from an earlier page, if any.
|
|
168
|
-
function keptRail() {
|
|
169
|
-
try { return parseInt(window.localStorage.getItem(RAIL_KEY), 10); } catch (e) { return NaN; }
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Sets an open card's top so its title row is level with its
|
|
173
|
-
// first line; its rows, and any fold open among them, flow down
|
|
174
|
-
// it. When its first line has scrolled up under the sticky
|
|
175
|
-
// header, the card slides down to stay just below it, but never
|
|
176
|
-
// past its last line. The rail stretches to the card's bottom,
|
|
177
|
-
// as the card, placed absolutely, adds no height of its own, so
|
|
178
|
-
// the box grows to show a card taller than the code.
|
|
179
|
-
function placeGrid(grid) {
|
|
180
|
-
var first = spot(lineno(firstOf(grid)), rail);
|
|
181
|
-
var last = spot(lineno(lastOf(grid)), rail);
|
|
182
|
-
var title = spot(grid.querySelector('.prow'), grid).middle;
|
|
183
|
-
var tall = grid.getBoundingClientRect().height;
|
|
184
|
-
var head = document.querySelector('.head').getBoundingClientRect().bottom;
|
|
185
|
-
var below = head - rail.getBoundingClientRect().top + 8;
|
|
186
|
-
var top = first.middle - title;
|
|
187
|
-
top = Math.max(top, Math.min(below, last.bottom - tall));
|
|
188
|
-
grid.style.top = top + 'px';
|
|
189
|
-
rail.style.minHeight = (top + tall) + 'px';
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Places whichever card is open; with none open the rail is
|
|
193
|
-
// only as tall as the code.
|
|
194
|
-
function place() {
|
|
195
|
-
rail.style.minHeight = '';
|
|
196
|
-
grids.forEach(function (grid) { if (!grid.hidden) { placeGrid(grid); } });
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// The code spans lit for the card row hovered.
|
|
200
|
-
var lit = [];
|
|
201
|
-
|
|
202
|
-
// Lights the code of every line in span, [first, last].
|
|
203
|
-
function light(lines) {
|
|
204
|
-
for (var n = lines[0]; n <= lines[1]; n++) {
|
|
205
|
-
var src = srcOf(n);
|
|
206
|
-
if (src) { src.classList.add('lit'); lit.push(src); }
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Unlights the code lit.
|
|
211
|
-
function clear() {
|
|
212
|
-
lit.forEach(function (src) { src.classList.remove('lit'); });
|
|
213
|
-
lit = [];
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
rail.addEventListener('mouseleave', clear);
|
|
217
|
-
|
|
218
|
-
// The code spans whose characters are marked, with the text
|
|
219
|
-
// each had before.
|
|
220
|
-
var markedSrcs = [];
|
|
221
|
-
|
|
222
|
-
// The length of text's leading whitespace.
|
|
223
|
-
function indentOf(text) {
|
|
224
|
-
return text.match(/^\s*/)[0].length;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Puts back every span marked as it was.
|
|
228
|
-
function unmarkChars() {
|
|
229
|
-
markedSrcs.forEach(function (entry) { entry.src.innerHTML = entry.html; });
|
|
230
|
-
markedSrcs = [];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Marks the characters from line l1, column c1 to line l2,
|
|
234
|
-
// column c2, each line's part in a mark of its own.
|
|
235
|
-
function markChars(l1, c1, l2, c2) {
|
|
236
|
-
unmarkChars();
|
|
237
|
-
for (var n = l1; n <= l2; n++) {
|
|
238
|
-
var src = srcOf(n);
|
|
239
|
-
if (!src) { continue; }
|
|
240
|
-
var text = src.textContent;
|
|
241
|
-
var from = n === l1 ? c1 : indentOf(text);
|
|
242
|
-
var to = n === l2 ? c2 : text.length;
|
|
243
|
-
markedSrcs.push({ src: src, html: src.innerHTML });
|
|
244
|
-
paint(src, function (i) { return i >= from && i < to ? 'chars' : null; }, function () {
|
|
245
|
-
var mark = document.createElement('mark');
|
|
246
|
-
mark.className = 'chars';
|
|
247
|
-
return mark;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
reveal(document.querySelectorAll('mark.chars'));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// The colour class of each of src's characters, the class of the
|
|
254
|
-
// token span it is in, null for one in none.
|
|
255
|
-
function tokensOf(src) {
|
|
256
|
-
var tokens = [];
|
|
257
|
-
var walker = document.createTreeWalker(src, NodeFilter.SHOW_TEXT);
|
|
258
|
-
for (var node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
259
|
-
var parent = node.parentNode;
|
|
260
|
-
var css = parent !== src && parent.tagName === 'SPAN' ? parent.className : null;
|
|
261
|
-
for (var i = 0; i < node.length; i++) { tokens.push(css); }
|
|
262
|
-
}
|
|
263
|
-
return tokens;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Rebuilds src's code, each run of characters keyAt gives one key
|
|
267
|
-
// to in the element wrap makes of that key, the others bare, every
|
|
268
|
-
// character still in a span of its token's colour class.
|
|
269
|
-
function paint(src, keyAt, wrap) {
|
|
270
|
-
var text = src.textContent;
|
|
271
|
-
var tokens = tokensOf(src);
|
|
272
|
-
src.textContent = '';
|
|
273
|
-
var i = 0;
|
|
274
|
-
while (i < text.length) {
|
|
275
|
-
var j = i;
|
|
276
|
-
var key = keyAt(i);
|
|
277
|
-
while (j < text.length && keyAt(j) === key) { j++; }
|
|
278
|
-
var holder = key ? wrap(key) : src;
|
|
279
|
-
appendTokens(holder, text, tokens, i, j);
|
|
280
|
-
if (key) { src.appendChild(holder); }
|
|
281
|
-
i = j;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Appends text's characters i to j to holder, each run of one
|
|
286
|
-
// token class in a span of that class, the rest bare.
|
|
287
|
-
function appendTokens(holder, text, tokens, i, j) {
|
|
288
|
-
var k = i;
|
|
289
|
-
while (k < j) {
|
|
290
|
-
var m = k;
|
|
291
|
-
while (m < j && tokens[m] === tokens[k]) { m++; }
|
|
292
|
-
var part = text.slice(k, m);
|
|
293
|
-
if (tokens[k]) {
|
|
294
|
-
var span = document.createElement('span');
|
|
295
|
-
span.className = tokens[k];
|
|
296
|
-
span.textContent = part;
|
|
297
|
-
holder.appendChild(span);
|
|
298
|
-
} else {
|
|
299
|
-
holder.appendChild(document.createTextNode(part));
|
|
300
|
-
}
|
|
301
|
-
k = m;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// The width of the code pane's left columns (gap arrows and
|
|
306
|
-
// line numbers), which code scrolls under.
|
|
307
|
-
var GUTTER = 108;
|
|
308
|
-
|
|
309
|
-
// Scrolls the code pane sideways so all of marks are in view,
|
|
310
|
-
// their start kept in view when they are wider than the pane.
|
|
311
|
-
function reveal(marks) {
|
|
312
|
-
if (marks.length === 0) { return; }
|
|
313
|
-
var pane = code.getBoundingClientRect();
|
|
314
|
-
var left = Infinity;
|
|
315
|
-
var right = -Infinity;
|
|
316
|
-
marks.forEach(function (mark) {
|
|
317
|
-
var rect = mark.getBoundingClientRect();
|
|
318
|
-
left = Math.min(left, rect.left);
|
|
319
|
-
right = Math.max(right, rect.right);
|
|
320
|
-
});
|
|
321
|
-
var shift = 0;
|
|
322
|
-
if (right > pane.right - 8) { shift = right - pane.right + 8; }
|
|
323
|
-
if (left - shift < pane.left + GUTTER) { shift = left - pane.left - GUTTER; }
|
|
324
|
-
if (shift !== 0) { code.scrollBy({ left: shift, behavior: 'smooth' }); }
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Hovering a row of a fold in a card marks in the code the
|
|
328
|
-
// characters of its operand, or of its operator's whole
|
|
329
|
-
// condition.
|
|
330
|
-
var markedRow = null;
|
|
331
|
-
rail.addEventListener('mouseover', function (event) {
|
|
332
|
-
var row = event.target.closest('.fold .row[data-at]');
|
|
333
|
-
if (row === markedRow) { return; }
|
|
334
|
-
markedRow = row;
|
|
335
|
-
if (!row) { unmarkChars(); return; }
|
|
336
|
-
var at = row.getAttribute('data-at').split(',').map(Number);
|
|
337
|
-
markChars(at[0], at[1], at[2], at[3]);
|
|
338
|
-
});
|
|
339
|
-
rail.addEventListener('mouseleave', function () {
|
|
340
|
-
markedRow = null;
|
|
341
|
-
unmarkChars();
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
// Hovering a statement's row in a card lights its line in the
|
|
345
|
-
// code, scrolling the page only when that line is out of view.
|
|
346
|
-
var litRow = null;
|
|
347
|
-
rail.addEventListener('mouseover', function (event) {
|
|
348
|
-
var row = event.target.closest('.statements .prow[data-line]:not(.calls)');
|
|
349
|
-
if (row === litRow) { return; }
|
|
350
|
-
litRow = row;
|
|
351
|
-
clear();
|
|
352
|
-
if (!row) { return; }
|
|
353
|
-
var n = Number(row.getAttribute('data-line'));
|
|
354
|
-
light([n, n]);
|
|
355
|
-
// A number's scroll margin keeps it clear of the sticky header
|
|
356
|
-
// and the def line stuck below it.
|
|
357
|
-
lineno(n).scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
358
|
-
});
|
|
359
|
-
rail.addEventListener('mouseleave', function () { litRow = null; });
|
|
360
|
-
|
|
361
|
-
// A click on a site's row in a card unfolds that site's tree in
|
|
362
|
-
// the row's place, folding up any other open; a click on the row
|
|
363
|
-
// of the one open, or on its fold's first row, which stands in
|
|
364
|
-
// the row's place, folds it back.
|
|
365
|
-
rail.addEventListener('click', function (event) {
|
|
366
|
-
if (event.target.closest('.fold .site > .row:first-child')) { unfold(null); return; }
|
|
367
|
-
var row = event.target.closest('.statements .prow.site');
|
|
368
|
-
var fold = row && row.nextElementSibling;
|
|
369
|
-
if (!fold || !fold.classList.contains('fold')) { return; }
|
|
370
|
-
unfold(fold.hidden ? fold : null);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
// Shows fold alone, null folding them all up, the arrow of each
|
|
374
|
-
// site's row pointing up while its fold shows; then places the
|
|
375
|
-
// open card again, as its height has changed.
|
|
376
|
-
function unfold(fold) {
|
|
377
|
-
rail.querySelectorAll('.fold').forEach(function (each) {
|
|
378
|
-
each.hidden = each !== fold;
|
|
379
|
-
var arrow = each.previousElementSibling.querySelector('.fold-arrow');
|
|
380
|
-
arrow.setAttribute('aria-expanded', String(each === fold));
|
|
381
|
-
});
|
|
382
|
-
place();
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Hovering code in the open card's lines unfolds that card's fold
|
|
386
|
-
// holding the innermost row whose code is under the pointer, alone,
|
|
387
|
-
// lighting that row; code in no fold, eg x = 42, lights its
|
|
388
|
-
// statement's row in the card instead, every fold folded. Each
|
|
389
|
-
// waits a pause, so sweeping the pointer along a line does not
|
|
390
|
-
// flicker. Leaving the code leaves what was lit lit. A card that
|
|
391
|
-
// is not open is left shut, as opening it would fold other
|
|
392
|
-
// methods' code away from under the pointer.
|
|
393
|
-
var HOVER_PAUSE = 80;
|
|
394
|
-
var hoverTimer = null;
|
|
395
|
-
var hoveredRow = null;
|
|
396
|
-
code.addEventListener('mousemove', function (event) {
|
|
397
|
-
clearTimeout(hoverTimer);
|
|
398
|
-
var x = event.clientX;
|
|
399
|
-
var y = event.clientY;
|
|
400
|
-
hoverTimer = setTimeout(function () { hoverAt(x, y); }, HOVER_PAUSE);
|
|
401
|
-
});
|
|
402
|
-
code.addEventListener('mouseleave', function () { clearTimeout(hoverTimer); });
|
|
403
|
-
|
|
404
|
-
// Shows, in the open card, the row of the code at x, y, if any.
|
|
405
|
-
function hoverAt(x, y) {
|
|
406
|
-
var at = caretAt(x, y);
|
|
407
|
-
var open = grids.filter(function (grid) { return !grid.hidden; })[0];
|
|
408
|
-
if (!at || !open) { return; }
|
|
409
|
-
var row = innermostRow(open, at.line, at.column);
|
|
410
|
-
if (row) {
|
|
411
|
-
if (row !== hoveredRow) { showRow(row); }
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
var statement = statementRow(open, at.line, at.column);
|
|
415
|
-
if (statement && statement !== hoveredRow) { showStatement(statement); }
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// The row of grid's statement holding line and column: of those
|
|
419
|
-
// starting on line, the last starting at or before column, or the
|
|
420
|
-
// first, eg the ?: row for the x = of x = a ? 1 : 2; null for none.
|
|
421
|
-
function statementRow(grid, line, column) {
|
|
422
|
-
var rows = grid.querySelectorAll('.prow[data-line="' + line + '"]:not(.calls)');
|
|
423
|
-
var best = rows[0] || null;
|
|
424
|
-
rows.forEach(function (row) {
|
|
425
|
-
var label = row.querySelector('.plabel').textContent;
|
|
426
|
-
if (Number(label.split(':')[1]) <= column) { best = row; }
|
|
427
|
-
});
|
|
428
|
-
return best;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// Lights row, a statement's, alone, every fold folded.
|
|
432
|
-
function showStatement(row) {
|
|
433
|
-
if (hoveredRow) { hoveredRow.classList.remove('hovered'); }
|
|
434
|
-
hoveredRow = row;
|
|
435
|
-
unfold(null);
|
|
436
|
-
row.classList.add('hovered');
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// The line and column of the code character at x, y; null when
|
|
440
|
-
// no code is there.
|
|
441
|
-
function caretAt(x, y) {
|
|
442
|
-
var node;
|
|
443
|
-
var offset;
|
|
444
|
-
if (document.caretRangeFromPoint) {
|
|
445
|
-
var range = document.caretRangeFromPoint(x, y);
|
|
446
|
-
if (!range) { return null; }
|
|
447
|
-
node = range.startContainer;
|
|
448
|
-
offset = range.startOffset;
|
|
449
|
-
} else if (document.caretPositionFromPoint) {
|
|
450
|
-
var caret = document.caretPositionFromPoint(x, y);
|
|
451
|
-
if (!caret) { return null; }
|
|
452
|
-
node = caret.offsetNode;
|
|
453
|
-
offset = caret.offset;
|
|
454
|
-
} else {
|
|
455
|
-
return null;
|
|
456
|
-
}
|
|
457
|
-
var element = node.nodeType === 1 ? node : node.parentElement;
|
|
458
|
-
var src = element && element.closest('.src');
|
|
459
|
-
if (!src) { return null; }
|
|
460
|
-
var before = document.createRange();
|
|
461
|
-
before.setStart(src, 0);
|
|
462
|
-
before.setEnd(node, offset);
|
|
463
|
-
return { line: lineOf(src), column: before.toString().length };
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// The number of the line whose code is src, a line's own or one of
|
|
467
|
-
// a loose site's lines.
|
|
468
|
-
function lineOf(src) {
|
|
469
|
-
var block = src.closest('.block');
|
|
470
|
-
if (!block) { return Number(src.parentElement.querySelector('.lineno').id.slice(1)); }
|
|
471
|
-
var index = Array.prototype.indexOf.call(block.querySelectorAll('.srcs > .src'), src);
|
|
472
|
-
return Number(block.querySelectorAll('.lineno')[index].id.slice(1));
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// The row, of grid's folds, whose code, its data-at, or whose
|
|
476
|
-
// else keyword, its data-else, holds line and column and is the
|
|
477
|
-
// shortest so; null for none.
|
|
478
|
-
function innermostRow(grid, line, column) {
|
|
479
|
-
var best = null;
|
|
480
|
-
var shortest = Infinity;
|
|
481
|
-
grid.querySelectorAll('.fold .row[data-at], .fold .row[data-else]').forEach(function (row) {
|
|
482
|
-
['data-at', 'data-else'].forEach(function (name) {
|
|
483
|
-
var span = row.getAttribute(name);
|
|
484
|
-
if (!span) { return; }
|
|
485
|
-
var at = span.split(',').map(Number);
|
|
486
|
-
if (!holds(at, line, column)) { return; }
|
|
487
|
-
var size = (at[2] - at[0]) * 100000 + (at[3] - at[1]);
|
|
488
|
-
if (size < shortest) { best = row; shortest = size; }
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
return best;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// True when at, [line, column, end line, end column], holds the
|
|
495
|
-
// character at line and column.
|
|
496
|
-
function holds(at, line, column) {
|
|
497
|
-
var from = line > at[0] || (line === at[0] && column >= at[1]);
|
|
498
|
-
var to = line < at[2] || (line === at[2] && column < at[3]);
|
|
499
|
-
return from && to;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
// Unfolds row's fold alone and lights row, its text scrolled back
|
|
503
|
-
// to its start, unlighting the row lit before.
|
|
504
|
-
function showRow(row) {
|
|
505
|
-
if (hoveredRow) { hoveredRow.classList.remove('hovered'); }
|
|
506
|
-
hoveredRow = row;
|
|
507
|
-
var fold = row.closest('.fold');
|
|
508
|
-
if (fold.hidden) { unfold(fold); }
|
|
509
|
-
row.classList.add('hovered');
|
|
510
|
-
var text = row.querySelector('.text');
|
|
511
|
-
if (text) { text.scrollLeft = 0; }
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// Opening one card closes the others, and a click never closes
|
|
515
|
-
// the one open, so the rail always shows one. A click on a def
|
|
516
|
-
// line opens its method's card; one on a loose site's lines opens
|
|
517
|
-
// their top card; a gutter arrow or a header jump opens the card
|
|
518
|
-
// at the line it jumps to.
|
|
519
|
-
document.addEventListener('click', function (event) {
|
|
520
|
-
var link = event.target.closest('.nav a, a.jump');
|
|
521
|
-
if (link) { openOnly(document.getElementById('paths-' + link.hash.slice(2))); return; }
|
|
522
|
-
if (event.target.closest('a')) { return; }
|
|
523
|
-
var loose = event.target.closest('.block');
|
|
524
|
-
var button = loose && loose.querySelector('button.lnum.loose');
|
|
525
|
-
if (button) { openOnly(document.getElementById(button.getAttribute('aria-controls'))); return; }
|
|
526
|
-
var row = event.target.closest('.line, .block');
|
|
527
|
-
var number = row && row.querySelector('.lineno.mdef');
|
|
528
|
-
if (number) { openOnly(grids[defs.indexOf(number)]); }
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
window.addEventListener('resize', place);
|
|
532
|
-
|
|
533
|
-
// The card of the innermost method whose def to end hold line n,
|
|
534
|
-
// or of the top card holding it, so a linked line in a body is
|
|
535
|
-
// never left folded away; null when none holds n.
|
|
536
|
-
function cardOf(n) {
|
|
537
|
-
var holding = grids.filter(function (grid) { return firstOf(grid) <= n && n <= lastOf(grid); });
|
|
538
|
-
return holding.length ? holding[holding.length - 1] : null;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
// On a page at a linked line, eg #L8, opens the card holding it.
|
|
542
|
-
// Otherwise opens the first card with gaps, or, with none, the
|
|
543
|
-
// first card, its first line scrolled into view, so one is always
|
|
544
|
-
// open, every other method's body folded under its def line;
|
|
545
|
-
// opens nothing only on a page with no card at all.
|
|
546
|
-
function openFirst() {
|
|
547
|
-
var linked = /^#L(\d+)$/.exec(window.location.hash);
|
|
548
|
-
var own = linked && cardOf(Number(linked[1]));
|
|
549
|
-
if (own) { openOnly(own); return; }
|
|
550
|
-
var jump = document.querySelector('.jump-list a.jump');
|
|
551
|
-
var card = jump ? cardOf(Number(jump.hash.slice(2))) : grids[0];
|
|
552
|
-
if (!card) { openOnly(null); return; }
|
|
553
|
-
lineno(firstOf(card)).scrollIntoView({ block: 'center' });
|
|
554
|
-
openOnly(card);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// Keeps the header, the open card and its def line in view as the
|
|
558
|
-
// page scrolls, and as a pinch-zoomed view pans or zooms. Pinch
|
|
559
|
-
// zoom pans a lens over the page, which CSS sticky ignores, so
|
|
560
|
-
// the header is shifted down by the lens's pan; the card and def
|
|
561
|
-
// line then follow the header's drawn bottom.
|
|
562
|
-
function followView() {
|
|
563
|
-
var pan = window.visualViewport ? window.visualViewport.offsetTop : 0;
|
|
564
|
-
document.querySelector('.head').style.transform = pan > 0 ? 'translateY(' + pan + 'px)' : '';
|
|
565
|
-
place();
|
|
566
|
-
stickDef();
|
|
567
|
-
}
|
|
568
|
-
window.addEventListener('scroll', followView);
|
|
569
|
-
window.addEventListener('resize', stickDef);
|
|
570
|
-
if (window.visualViewport) {
|
|
571
|
-
window.visualViewport.addEventListener('scroll', followView);
|
|
572
|
-
window.visualViewport.addEventListener('resize', followView);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
// Keeps the def line of the open method in view: once it would
|
|
576
|
-
// scroll up under the sticky header, it is shifted down to sit
|
|
577
|
-
// just below it, over the body lines passing beneath, but never
|
|
578
|
-
// past the method's last line. The code pane scrolls sideways, so
|
|
579
|
-
// CSS sticky, which would stick within the pane, cannot do this.
|
|
580
|
-
function stickDef() {
|
|
581
|
-
grids.forEach(function (grid) {
|
|
582
|
-
var row = rowOf(firstOf(grid));
|
|
583
|
-
row.style.transform = '';
|
|
584
|
-
row.classList.remove('def-stuck');
|
|
585
|
-
if (grid.hidden) { return; }
|
|
586
|
-
var head = document.querySelector('.head').getBoundingClientRect().bottom;
|
|
587
|
-
var rect = row.getBoundingClientRect();
|
|
588
|
-
var last = lineno(lastOf(grid)).getBoundingClientRect();
|
|
589
|
-
var shift = Math.min(head - rect.top, last.bottom - rect.bottom);
|
|
590
|
-
if (shift <= 0) { return; }
|
|
591
|
-
row.style.transform = 'translateY(' + shift + 'px)';
|
|
592
|
-
row.classList.add('def-stuck');
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
var kept = keptRail();
|
|
597
|
-
if (kept > 0) { setRail(kept); }
|
|
598
|
-
openFirst();
|
|
599
|
-
})();
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Sorts a files table by the clicked column's data-sort values;
|
|
2
|
-
// a second click on the same column reverses the order. A cell
|
|
3
|
-
// with an empty data-sort, one with no value such as a -, stays
|
|
4
|
-
// last in both orders, so either end of the values can be first.
|
|
5
|
-
// Each table, one per tab, sorts on its own.
|
|
6
|
-
(function () {
|
|
7
|
-
document.querySelectorAll('table.files').forEach(function (table) {
|
|
8
|
-
var body = table.tBodies[0];
|
|
9
|
-
var state = { column: -1, ascending: true };
|
|
10
|
-
|
|
11
|
-
table.querySelectorAll('thead button').forEach(function (button) {
|
|
12
|
-
button.addEventListener('click', function () {
|
|
13
|
-
var column = Number(button.dataset.column);
|
|
14
|
-
var numeric = button.dataset.type === 'number';
|
|
15
|
-
state.ascending = state.column === column ? !state.ascending : true;
|
|
16
|
-
state.column = column;
|
|
17
|
-
var rows = Array.from(body.rows);
|
|
18
|
-
rows.sort(function (a, b) {
|
|
19
|
-
var x = a.cells[column].dataset.sort;
|
|
20
|
-
var y = b.cells[column].dataset.sort;
|
|
21
|
-
if (x === '' || y === '') { return (x === '') - (y === ''); }
|
|
22
|
-
var order = numeric ? Number(x) - Number(y) : x.localeCompare(y);
|
|
23
|
-
return state.ascending ? order : -order;
|
|
24
|
-
});
|
|
25
|
-
rows.forEach(function (row) { body.appendChild(row); });
|
|
26
|
-
var sort = state.ascending ? 'ascending' : 'descending';
|
|
27
|
-
table.querySelectorAll('thead button').forEach(function (other) {
|
|
28
|
-
var mine = Number(other.dataset.column) === column;
|
|
29
|
-
other.parentNode.setAttribute('aria-sort', mine ? sort : 'none');
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
})();
|