Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ kbd { font-family: var(--font-mono); font-size: 10.5px; padding: 1px 5px; border

/* Code. */
mark.hit { background: oklch(var(--hit)); color: inherit; border-radius: 2px; padding: 0 1px; }
/* Search field hover card (dark tip): matches keep readable ink on the hit colour. */
.field-tip mark.hit { color: oklch(var(--ink)); }
.code-line { display: flex; }
.code-line.sel { background: oklch(var(--live) / 0.08); box-shadow: inset 2px 0 oklch(var(--live)); }
.tok-k { color: oklch(0.55 0.17 300); }
Expand Down
68 changes: 66 additions & 2 deletions web/assets/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@
var f = self.pick(e);
canvas.style.cursor = f && f.href ? 'pointer' : '';
var key = f ? f.key : null;
if (key !== self.hoverKey) { self.hoverKey = key; self.focus(key); }
if (key !== self.hoverKey) { self.hoverKey = key; self.focus(key); self.card(f && f.tip ? f.tip() : '', key); }
});
canvas.addEventListener('mouseleave', function () {
canvas.style.cursor = '';
if (self.hoverKey) { self.hoverKey = null; self.focus(null); }
self.card('');
});
// The card is placed against the cluster; scrolling moves the cluster away.
window.addEventListener('scroll', function () {
if (self.hoverKey) { self.hoverKey = null; self.focus(null); }
self.card('');
}, true);
canvas.addEventListener('click', function (e) {
var f = self.pick(e);
if (!f || !f.href) return;
Expand All @@ -58,6 +64,45 @@
});
}

// The hover card of a result: the site's dark tip with an arrow, placed
// below the result's dot cluster (above when there is no room below),
// with the arrow left of the tip's centre, kept inside the window; the arrow points at the
// cluster's centre. Empty html hides it.
Field.prototype.card = function (html, key) {
var idxs = key && this.files[key];
if (!html || !idxs || !idxs.length) { if (this.cardEl) this.cardEl.style.visibility = 'hidden'; return; }
if (!this.cardEl) {
var el = document.createElement('div');
el.setAttribute('role', 'tooltip');
// The site's tip style (app.js data-tip), sized for a few code lines.
el.className = 'pointer-events-none fixed z-[60] w-[440px] max-w-[calc(100vw-16px)] rounded-control bg-ink px-3 py-2.5 text-[12.5px] leading-snug text-paper shadow-lg';
el.innerHTML = '<div data-body></div><span data-arrow class="absolute h-2.5 w-2.5 bg-ink" style="transform:rotate(45deg)"></span>';
document.body.appendChild(el);
this.cardEl = el;
}
var el = this.cardEl, arrow = el.querySelector('[data-arrow]');
el.querySelector('[data-body]').innerHTML = html;
el.style.visibility = 'hidden'; el.style.left = '0px'; el.style.top = '0px';
// The cluster's box in window coordinates.
var c = this.c.getBoundingClientRect(), x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity;
for (var k = 0; k < idxs.length; k++) {
var i = idxs[k];
x0 = Math.min(x0, this.x[i]); x1 = Math.max(x1, this.x[i]); y0 = Math.min(y0, this.y[i]); y1 = Math.max(y1, this.y[i]);
}
var cx = c.left + (x0 + x1) / 2, top = c.top + y0 - 4, bottom = c.top + y1 + 4, gap = 9;
var w = el.offsetWidth, h = el.offsetHeight;
// The arrow sits left of the tip's centre (a quarter of its width), not mid-way.
var left = Math.min(Math.max(8, cx - Math.min(w / 4, 96)), window.innerWidth - w - 8);
var above = bottom + gap + h > window.innerHeight - 8 && top - gap - h >= 8, y = above ? top - gap - h : bottom + gap;
el.style.left = left + 'px'; el.style.top = y + 'px';
// The arrow follows the cluster even when the card is shifted to stay on screen.
var ax = Math.min(Math.max(12, cx - left), w - 12);
arrow.style.left = (ax - 5) + 'px';
arrow.style.top = above ? '' : '-5px';
arrow.style.bottom = above ? '-5px' : '';
el.style.visibility = 'visible';
};

// The settled file under the pointer: its label, or the hit cluster nearest to it.
Field.prototype.pick = function (e) {
if (this.mode !== 'settled' || !this.lastFiles || !this.n) return null;
Expand Down Expand Up @@ -107,6 +152,7 @@
this.hit = new Float32Array(this.n); // 0 = no hit, otherwise reveal time (ms)
this.owner = new Int32Array(this.n).fill(-1);
this.hitDim = new Uint8Array(this.n);
this.shared = new Uint8Array(this.n); // dots claimed by more than one result cluster
for (var i = 0; i < this.n; i++) this.phase[i] = rand(i, 7) * Math.PI * 2;
if (this.opts.onLayout) this.opts.onLayout(this.n, this.shards);
if (this.mode === 'settled') this.placeHits(this.lastFiles || []);
Expand All @@ -130,6 +176,7 @@
Field.prototype.candidates = function () { return Math.round(this.frac * this.n); };

Field.prototype.scan = function () {
this.card('');
this.labels = []; this.labelBoxes = [];
this.mode = 'scan';
this.pending = null;
Expand Down Expand Up @@ -158,6 +205,7 @@
var rows = this.rows, cols = Math.floor(this.n / rows);
this.hit.fill(0);
this.hitDim.fill(0);
this.shared.fill(0);
this.owner.fill(-1);
this.files = {};
this.labels = []; this.labelBoxes = [];
Expand All @@ -173,16 +221,27 @@
idxs.push(i);
self.hit[i] = now + 40 + Math.abs(self.x[i] - originX) * 0.12 + fi * stagger + j * 10;
self.hitDim[i] = j >= lit ? 1 : 0;
if (self.owner[i] >= 0 && self.owner[i] !== fi) self.shared[i] = 1;
self.owner[i] = fi;
}
self.files[f.key] = idxs;
if (idxs.length) self.labels.push({ key: f.key, text: f.label || '', i: idxs[idxs.length - 1], at: self.hit[idxs[0]] + 180 });
});
// A crossing shows inside the overlap only: its edge (dots with a 4-neighbour
// outside the overlap) is drawn as an ordinary lit hit.
var edge = [];
for (var i = 0; i < this.n; i++) {
if (!this.shared[i]) continue;
var r = i % rows, near = [r > 0 ? i - 1 : -1, r < rows - 1 ? i + 1 : -1, i - rows, i + rows];
for (var q = 0; q < 4; q++) { var nb = near[q]; if (nb >= 0 && nb < this.n && !this.shared[nb]) { edge.push(i); break; } }
}
for (var e = 0; e < edge.length; e++) { this.shared[edge[e]] = 0; this.hitDim[edge[e]] = 0; }
};

Field.prototype.focus = function (key) { this.focusKey = key; };

Field.prototype.reset = function () {
this.card('');
this.labels = [];
this.pending = null; this.labelBoxes = [];
this.mode = 'idle'; this.frac = 0; this.hit.fill(0); this.owner.fill(-1); this.scanned.fill(0); this.focusKey = null; this.lastFiles = [];
Expand Down Expand Up @@ -242,6 +301,8 @@
if (h && now >= h) {
var pop = Math.min(1, (now - h) / 260);
ink = (this.hitDim[i] ? 0.12 + 0.2 * pop : 0.3 + 0.7 * pop);
// Where clusters cross: normal size, between a lit hit and a background dot.
if (this.shared[i]) ink = 0.15 + 0.35 * pop;
if (focusSet && focusSet[i]) { blue = 1; ink = 0; }
}
}
Expand All @@ -252,6 +313,7 @@
if (blue > 0.02) blueBins[Math.round(Math.min(1, blue) * LEVELS)].push(i);
}

this.now = now;
ctx.clearRect(0, 0, w, this.h);
this.drawBins(inkBins, this.inkColor, R);
this.drawBins(blueBins, this.liveColor, R + 0.25);
Expand Down Expand Up @@ -300,7 +362,9 @@
ctx.globalAlpha = lv / LEVELS;
ctx.beginPath();
for (var j = 0; j < list.length; j++) {
var i = list[j], rr = r + (this.hit[i] && !this.hitDim[i] && lv > LEVELS * 0.8 ? 0.7 : 0);
// A result dot has one size whatever its colour (hover only recolours):
// lit hits grow once they have popped in; dim and crossing dots stay at R.
var i = list[j], rr = this.hit[i] && this.now >= this.hit[i] ? R + (!this.hitDim[i] && !this.shared[i] && this.now - this.hit[i] >= 180 ? 0.7 : 0) : r;
ctx.moveTo(this.x[i] + rr, this.y[i]);
ctx.arc(this.x[i], this.y[i], rr, 0, Math.PI * 2);
}
Expand Down
14 changes: 13 additions & 1 deletion web/assets/search-page.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{brand}}</title>
<link rel="icon" href="data:,">
<link rel="stylesheet" href="assets/base.css?v=20260927-5">
<link rel="stylesheet" href="assets/base.css?v=20261201-1">
<script src="assets/clients.js?v=20260927-5"></script>
<script src="assets/app.js?v=20260927-5"></script>
<script src="assets/select.js?v=20260927-5"></script>
<script src="assets/client-panel.js?v=20260927-5"></script>
<script src="assets/field.js?v=20260927-5"></script>
<script src="assets/field.js?v=20261201-1"></script>
<style>
@media(max-width:639px){#stage .relative.flex.items-stretch{flex-wrap:wrap}#scope{min-height:44px;white-space:normal;overflow-wrap:anywhere}#scope-menu{position:fixed;left:1rem;right:1rem;top:5rem;width:auto;max-width:none;max-height:calc(100vh - 6rem);overflow:auto}#scope-filter{font-size:16px}#q{font-size:16px;min-width:120px}#stage #scope-menu input{font-size:16px}}
</style>
Expand Down