mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 18:52:18 +00:00
feat(ui): draw the open right rail tab and its panel as one surface
The strip traces the joined silhouette of the open panel and its tab as an SVG path (rounded corners, concave fillets; Cyber's chamfered frame and a square tab) and keeps a join element under the panels: one layer blurs and tints the backdrop inside the path, an SVG strokes the outline along it and another casts the drop shadow. The panel card and the tab draw no surface of their own, so the junction has no seam, doubled edge or second blur region. Cyber's generic selected-button treatment is kept off the tab. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
65c1ae67f2
commit
0a52e94671
5 files changed
+352
-179
No files matched your search
+186
-7
@@ -7,6 +7,11 @@
|
||||
* asks the owner (setPanelCollapsed) for every change, so persistence, share
|
||||
* links and the rail layout pass are untouched. Phones hide the strip and keep
|
||||
* their sheet shell (mobileShell.js).
|
||||
*
|
||||
* The open tab and its panel are drawn as one surface: the strip measures
|
||||
* both, traces their joined silhouette as an SVG path (railJoinPath) and keeps
|
||||
* a join element under the panels whose layers blur, tint, outline and shadow
|
||||
* that one shape (styles/right-rail-tabs.css).
|
||||
*/
|
||||
import { msg, t } from '../i18n/index.js';
|
||||
|
||||
@@ -19,6 +24,8 @@ export const RIGHT_RAIL_TABS_ID = 'right-rail-tabs';
|
||||
*/
|
||||
export const RIGHT_RAIL_TABS_ATTRIBUTE = 'data-rail-tabs';
|
||||
|
||||
const SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
|
||||
/**
|
||||
* The tab keyboard navigation moves to in a vertical tablist: Down and Up
|
||||
* wrap, Home and End jump. Any other key keeps the current index.
|
||||
@@ -51,6 +58,106 @@ export function railTabPanels(rail) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SVG path of the panel with the open tab attached to its right edge, traced
|
||||
* clockwise from the top-left corner, in rail pixels.
|
||||
*
|
||||
* Round: the panel's corners and the tab's outer corners are convex arcs and
|
||||
* the two inner corners where the tab's top and bottom edges meet the panel's
|
||||
* right edge are concave fillets. A tab level with the panel's top shares its
|
||||
* top edge, so that corner and the upper fillet are dropped. Chamfer (Cyber):
|
||||
* the frame's 10px chamfers and 6px calibration bay (cyber.css,
|
||||
* --cyber-panel-frame) and a square tab. `inset` moves the whole outline
|
||||
* inward; 0.5 centres a one-pixel stroke just inside the edge.
|
||||
*
|
||||
* @param {object} g
|
||||
* @param {{x0: number, y0: number, x1: number, y1: number}} g.panel
|
||||
* @param {{top: number, bottom: number, right: number}} g.tab The tab's
|
||||
* extent; its left edge is the panel's right edge.
|
||||
* @param {number} [g.corner] Panel corner radius, or the chamfer size.
|
||||
* @param {number} [g.tabRadius] The tab's outer corner radius.
|
||||
* @param {number} [g.fillet] Concave fillet radius at the junction.
|
||||
* @param {'round'|'chamfer'} [g.style]
|
||||
* @param {number} [g.inset]
|
||||
* @returns {string}
|
||||
*/
|
||||
export function railJoinPath({
|
||||
panel,
|
||||
tab,
|
||||
corner = 16,
|
||||
tabRadius = 10,
|
||||
fillet = 8,
|
||||
style = 'round',
|
||||
inset = 0,
|
||||
}) {
|
||||
const n = (value) => Math.round(value * 100) / 100;
|
||||
const P = (x, y) => `${n(x)} ${n(y)}`;
|
||||
const x0 = panel.x0 + inset;
|
||||
const y0 = panel.y0 + inset;
|
||||
const x1 = panel.x1 - inset;
|
||||
const y1 = panel.y1 - inset;
|
||||
const ty0 = tab.top + inset;
|
||||
const ty1 = tab.bottom - inset;
|
||||
const tx1 = tab.right - inset;
|
||||
if (style === 'chamfer') {
|
||||
const c = corner;
|
||||
const cx = (panel.x0 + panel.x1) / 2;
|
||||
return [
|
||||
`M ${P(x0, y0 + c)}`,
|
||||
`L ${P(x0 + c, y0)}`,
|
||||
`L ${P(cx - 25, y0)}`,
|
||||
`L ${P(cx - 18, y0 + 6)}`,
|
||||
`L ${P(cx + 18, y0 + 6)}`,
|
||||
`L ${P(cx + 25, y0)}`,
|
||||
`L ${P(x1 - c, y0)}`,
|
||||
`L ${P(x1, y0 + c)}`,
|
||||
`L ${P(x1, ty0)}`,
|
||||
`L ${P(tx1, ty0)}`,
|
||||
`L ${P(tx1, ty1)}`,
|
||||
`L ${P(x1, ty1)}`,
|
||||
`L ${P(x1, y1 - c)}`,
|
||||
`L ${P(x1 - c, y1)}`,
|
||||
`L ${P(x0 + c, y1)}`,
|
||||
`L ${P(x0, y1 - c)}`,
|
||||
'Z',
|
||||
].join(' ');
|
||||
}
|
||||
const R = Math.max(0, corner - inset);
|
||||
const r = Math.max(0, tabRadius - inset);
|
||||
const f = fillet + inset;
|
||||
// sweep 1 turns clockwise (convex), 0 counter-clockwise (concave).
|
||||
const arc = (radius, sweep, x, y) =>
|
||||
`A ${n(radius)} ${n(radius)} 0 0 ${sweep} ${P(x, y)}`;
|
||||
const first = tab.top - panel.y0 < 0.5;
|
||||
const d = [`M ${P(x0 + R, y0)}`];
|
||||
if (first) {
|
||||
d.push(`L ${P(tx1 - r, y0)}`, arc(r, 1, tx1, y0 + r));
|
||||
} else {
|
||||
d.push(
|
||||
`L ${P(x1 - R, y0)}`,
|
||||
arc(R, 1, x1, y0 + R),
|
||||
`L ${P(x1, ty0 - f)}`,
|
||||
arc(f, 0, x1 + f, ty0),
|
||||
`L ${P(tx1 - r, ty0)}`,
|
||||
arc(r, 1, tx1, ty0 + r),
|
||||
);
|
||||
}
|
||||
d.push(
|
||||
`L ${P(tx1, ty1 - r)}`,
|
||||
arc(r, 1, tx1 - r, ty1),
|
||||
`L ${P(x1 + f, ty1)}`,
|
||||
arc(f, 0, x1, ty1 + f),
|
||||
`L ${P(x1, y1 - R)}`,
|
||||
arc(R, 1, x1 - R, y1),
|
||||
`L ${P(x0 + R, y1)}`,
|
||||
arc(R, 1, x0, y1 - R),
|
||||
`L ${P(x0, y0 + R)}`,
|
||||
arc(R, 1, x0 + R, y0),
|
||||
'Z',
|
||||
);
|
||||
return d.join(' ');
|
||||
}
|
||||
|
||||
/** The tab label: the panel's own header title, already translated. */
|
||||
function panelTitle(panel) {
|
||||
return (
|
||||
@@ -87,6 +194,26 @@ export function createRightRailTabs({
|
||||
strip.setAttribute('aria-label', t('Panels'));
|
||||
rail.setAttribute(RIGHT_RAIL_TABS_ATTRIBUTE, 'vertical');
|
||||
|
||||
// The join: shadow under, glass, outline over; all shaped by one path.
|
||||
const svg = (tag) =>
|
||||
documentRef.createElementNS?.(SVG_NS, tag) ??
|
||||
documentRef.createElement(tag);
|
||||
const join = documentRef.createElement('div');
|
||||
join.className = 'right-rail-join';
|
||||
join.setAttribute('aria-hidden', 'true');
|
||||
join.hidden = true;
|
||||
const shadow = svg('svg');
|
||||
shadow.setAttribute('class', 'right-rail-join-shadow');
|
||||
const shadowPath = svg('path');
|
||||
shadow.append(shadowPath);
|
||||
const glass = documentRef.createElement('div');
|
||||
glass.setAttribute('class', 'right-rail-join-glass');
|
||||
const outline = svg('svg');
|
||||
outline.setAttribute('class', 'right-rail-join-outline');
|
||||
const outlinePath = svg('path');
|
||||
outline.append(outlinePath);
|
||||
join.append(shadow, glass, outline);
|
||||
|
||||
/** @type {Map<string, {tab: HTMLElement, label: HTMLElement}>} */
|
||||
const entries = new Map();
|
||||
const observed = new WeakSet();
|
||||
@@ -131,12 +258,18 @@ export function createRightRailTabs({
|
||||
});
|
||||
};
|
||||
|
||||
/** A join token from the stylesheet (--right-rail-*), in pixels. */
|
||||
const token = (computed, name, fallback) => {
|
||||
const value = parseFloat(computed?.getPropertyValue?.(name));
|
||||
return Number.isFinite(value) ? value : fallback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Publish the join on the rail for styles/right-rail-tabs.css: the open
|
||||
* tab's extent (--rail-tab-top, --rail-tab-bottom) and the open panel's
|
||||
* height (--rail-panel-height), in rail pixels. The panel outline is drawn
|
||||
* at that height with a notch at the tab, and the panel reaches down to it.
|
||||
* The rail itself can be taller than its panel in the focus layout.
|
||||
* Publish the join: the open tab's extent on the rail (--rail-tab-top,
|
||||
* --rail-tab-bottom, rail pixels, for the panel's minimum height) and the
|
||||
* joined silhouette on the join element's layers. The rail itself can be
|
||||
* taller than its panel in the focus layout, so the join is sized from
|
||||
* the panel, extended down to cover the tab if the panel is shorter.
|
||||
*/
|
||||
function placeJoin(tab, panel) {
|
||||
const style = rail.style;
|
||||
@@ -144,13 +277,55 @@ export function createRightRailTabs({
|
||||
if (!tab || !Number.isFinite(tab.offsetTop)) {
|
||||
style.removeProperty('--rail-tab-top');
|
||||
style.removeProperty('--rail-tab-bottom');
|
||||
style.removeProperty('--rail-panel-height');
|
||||
join.hidden = true;
|
||||
return;
|
||||
}
|
||||
const top = tab.offsetTop - (strip.scrollTop || 0);
|
||||
style.setProperty('--rail-tab-top', `${top}px`);
|
||||
style.setProperty('--rail-tab-bottom', `${top + tab.offsetHeight}px`);
|
||||
style.setProperty('--rail-panel-height', `${panel.offsetHeight}px`);
|
||||
if (!Number.isFinite(panel?.offsetWidth) || !join.style) {
|
||||
join.hidden = true;
|
||||
return;
|
||||
}
|
||||
const computed = documentRef.defaultView?.getComputedStyle?.(rail);
|
||||
const corner = token(computed, '--right-rail-corner', 16);
|
||||
const tabRadius = token(computed, '--right-rail-tab-radius', 10);
|
||||
const fillet = token(computed, '--right-rail-fillet', 8);
|
||||
const chamfer =
|
||||
computed?.getPropertyValue?.('--right-rail-join-style').trim() ===
|
||||
'chamfer';
|
||||
const tabTop = (strip.offsetTop || 0) + top;
|
||||
const tabBottom = tabTop + tab.offsetHeight;
|
||||
const geometry = {
|
||||
panel: {
|
||||
x0: panel.offsetLeft,
|
||||
y0: panel.offsetTop,
|
||||
x1: panel.offsetLeft + panel.offsetWidth,
|
||||
y1: Math.max(
|
||||
panel.offsetTop + panel.offsetHeight,
|
||||
tabBottom + fillet + 4 + corner,
|
||||
),
|
||||
},
|
||||
tab: {
|
||||
top: tabTop,
|
||||
bottom: tabBottom,
|
||||
right: (strip.offsetLeft || 0) + tab.offsetLeft + tab.offsetWidth,
|
||||
},
|
||||
corner,
|
||||
tabRadius,
|
||||
fillet,
|
||||
style: chamfer ? 'chamfer' : 'round',
|
||||
};
|
||||
const shape = railJoinPath(geometry);
|
||||
const width = rail.clientWidth;
|
||||
const height = geometry.panel.y1;
|
||||
join.style.height = `${height}px`;
|
||||
glass.style.clipPath = `path('${shape}')`;
|
||||
shadowPath.setAttribute('d', shape);
|
||||
// Everything but the silhouette: the shadow it casts stays, the fill goes.
|
||||
shadow.style.clipPath = `path(evenodd, 'M -80 -80 H ${width + 80} V ${height + 80} H -80 Z ${shape}')`;
|
||||
outlinePath.setAttribute('d', railJoinPath({ ...geometry, inset: 0.5 }));
|
||||
join.hidden = false;
|
||||
}
|
||||
|
||||
/** Reconcile tabs with the rail: order, visibility, selection, labels. */
|
||||
@@ -160,6 +335,7 @@ export function createRightRailTabs({
|
||||
// tab lands inside the open panel. The rail owner moves panels in at
|
||||
// start-up; keep the strip first afterwards too.
|
||||
if (rail.firstElementChild !== strip) rail.prepend(strip);
|
||||
if (join.parentElement !== rail) rail.append(join);
|
||||
const panels = railTabPanels(rail);
|
||||
const focusOwner =
|
||||
panels.find((panel) => !panel.classList.contains('collapsed')) ||
|
||||
@@ -218,10 +394,12 @@ export function createRightRailTabs({
|
||||
strip.addEventListener('scroll', onScroll, { passive: true });
|
||||
observer?.observe(rail, { childList: true });
|
||||
rail.prepend(strip);
|
||||
rail.append(join);
|
||||
sync();
|
||||
|
||||
return {
|
||||
element: strip,
|
||||
join,
|
||||
sync,
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
@@ -232,6 +410,7 @@ export function createRightRailTabs({
|
||||
strip.removeEventListener('keydown', onKeydown);
|
||||
strip.removeEventListener('scroll', onScroll);
|
||||
strip.remove();
|
||||
join.remove();
|
||||
rail.removeAttribute(RIGHT_RAIL_TABS_ATTRIBUTE);
|
||||
placeJoin(null, null);
|
||||
entries.clear();
|
||||
|
||||
Reference in new issue
Block a user