Filters: the panel is a bar (status segment, always visible) plus a body that lives as a layer under it - collapsed by default, expands on hover/focus/tap and never moves the case grid; the reset control appears only when a facet is limited; width capped at 720px (measured 45px slack against 477px before). Facet research report is included. Links: project links in the mini card and in the project window are icon-only buttons with a uniform slot (16px card / 18px window) and the accessible name in aria-label; studio contacts (mail, VK, RuStore) live outside the cards. Team and page: real photos from the public TITANS team page go to the member window while the card keeps the mascot; the portfolio gains the First Step Radio card and genre values, the process block became an individual-approach section, plus a cookie bar and a removable ticker. Design folders under design/ keep reports, measurements, scripts and the .pen; probe and before/after screenshot dumps, editor backups and caches are removed. Background-variant and palette previews stay until the client picks one.
200 lines
11 KiB
JavaScript
200 lines
11 KiB
JavaScript
/*
|
||
* Замер оптической массы знаков ресурсов (§10.28, kanban t_d3adf730).
|
||
*
|
||
* Что делает (всё на реальных данных, без «на глаз»):
|
||
* 1) берёт ФАКТИЧЕСКИЕ знаки из src/js/main.js (LINK_ICONS);
|
||
* 2) растеризует каждый знак в браузере (Playwright + Chromium) в canvas на увеличении 32x
|
||
* и ЗАМЕРОМ определяет чернильный bbox в единицах исходного viewBox и alpha-площадь
|
||
* (оптическая масса) в единицах² — геометрия не задаётся руками;
|
||
* 3) замеряет ТЕКУЩЕЕ состояние (карточка: height 16 px + width:auto; окно: 18 px);
|
||
* 4) решает нормализацию в единый слот: общий viewBox 0 0 24 24, знак центрируется по
|
||
* чернильному bbox, большая сторона = L единиц; L на знак подбирается так, чтобы
|
||
* alpha-масса всех четырёх совпала (тяжёлые силуэты ужимаются, штриховые растут);
|
||
* 5) перепроверяет решение РЕНДЕРОМ итоговой разметки в слотах 16 и 18 px.
|
||
*
|
||
* Запуск: node design/glyph-slot-2026-10-14/measure-glyph-mass.cjs
|
||
* Выход: stdout (таблицы) + glyph-mass.json рядом со скриптом.
|
||
*/
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
const { launch } = require('./pw.cjs');
|
||
|
||
const ROOT = path.resolve(__dirname, '..', '..');
|
||
const OUT = __dirname;
|
||
|
||
const mainJs = fs.readFileSync(path.join(ROOT, 'src', 'js', 'main.js'), 'utf8');
|
||
const block = mainJs.match(/var LINK_ICONS = \{[\s\S]*?\n \};/);
|
||
if (!block) throw new Error('LINK_ICONS не найден в src/js/main.js');
|
||
const LINK_ICONS = eval('(function(){' + block[0] + ' return LINK_ICONS;})()');
|
||
|
||
const rsPath = (LINK_ICONS.rustore.match(/<path[^>]*>/) || [])[0];
|
||
if (!rsPath) throw new Error('path знака RuStore не найден');
|
||
|
||
// Геометрия — официальная, перенесена из main.js как есть. Меняются только viewBox-обёртки.
|
||
const GLYPHS = {
|
||
vk: {
|
||
kind: 'fill', viewBox: [3.9, 7.15, 16.31, 10.29],
|
||
body: '<path d="M6.79 7.3H4.05c.13 6.24 3.25 9.99 8.72 9.99h.31v-3.57c2.01.2 3.53 1.67 4.14 3.57h2.84c-.78-2.84-2.83-4.41-4.11-5.01 1.28-.74 3.08-2.54 3.51-4.98h-2.58c-.56 1.98-2.22 3.78-3.8 3.95V7.3H10.5v6.92c-1.6-.4-3.62-2.34-3.71-6.92Z" fill="currentColor"/>'
|
||
},
|
||
rustore: { kind: 'fill', viewBox: [14.65, 15.95, 58.835, 55.99], body: rsPath },
|
||
site: {
|
||
kind: 'stroke', strokeWidth: 2, viewBox: [0, 0, 24, 24],
|
||
body: '<circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><ellipse cx="12" cy="12" rx="4" ry="9"/>'
|
||
},
|
||
video: {
|
||
kind: 'stroke', strokeWidth: 2, viewBox: [0, 0, 24, 24],
|
||
body: '<rect x="2" y="5" width="14" height="14" rx="2.5"/><path d="M16 10.5 22 7v10l-6-3.5z"/>'
|
||
}
|
||
};
|
||
const ORDER = ['rustore', 'vk', 'site', 'video'];
|
||
|
||
const attr = (g) => (g.kind === 'stroke'
|
||
? ' fill="none" stroke="currentColor" stroke-width="' + g.strokeWidth + '" stroke-linecap="round" stroke-linejoin="round"'
|
||
: '');
|
||
|
||
// знак в СВОИХ единицах, картинка размером viewBox (1 ед. = 1 px при scale=1)
|
||
const nativeSvg = (g) => '<svg xmlns="http://www.w3.org/2000/svg" style="display:block;width:' + g.viewBox[2] +
|
||
'px;height:' + g.viewBox[3] + 'px" viewBox="' + g.viewBox.join(' ') + '"' + attr(g) + '>' + g.body + '</svg>';
|
||
|
||
// итоговая разметка: слот S×S px, общий viewBox 0 0 24 24, знак внутри группы
|
||
const slotSvg = (g, t, S) => '<svg xmlns="http://www.w3.org/2000/svg" style="display:block;width:' + S + 'px;height:' + S +
|
||
'px" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><g transform="translate(' + t.tx + ' ' + t.ty +
|
||
') scale(' + t.s + ')"' + (g.kind === 'stroke' ? ' fill="none" stroke="currentColor" stroke-width="' + g.strokeWidth +
|
||
'" stroke-linecap="round" stroke-linejoin="round"' : '') + '>' + g.body + '</g></svg>';
|
||
|
||
(async () => {
|
||
const browser = await launch();
|
||
const p = await browser.newPage({ viewport: { width: 400, height: 300 } });
|
||
await p.setContent('<!doctype html><meta charset="utf-8"><body style="margin:0;background:#fff;color:#000"></body>');
|
||
|
||
// Растеризация в canvas: возвращает alpha-площадь и чернильный bbox в пикселях canvas.
|
||
const ink = async (svgString, w, h, scale) => p.evaluate(async ({ svgString, w, h, scale }) => {
|
||
const px = Math.round(w * scale), py = Math.round(h * scale);
|
||
const url = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgString)));
|
||
const img = new Image();
|
||
await new Promise((res, rej) => { img.onload = res; img.onerror = rej; img.src = url; });
|
||
const c = document.createElement('canvas');
|
||
c.width = px; c.height = py;
|
||
const ctx = c.getContext('2d');
|
||
ctx.drawImage(img, 0, 0, px, py);
|
||
const d = ctx.getImageData(0, 0, px, py).data;
|
||
let sum = 0, minX = 1e9, minY = 1e9, maxX = -1, maxY = -1;
|
||
for (let y = 0; y < py; y++) {
|
||
for (let x = 0; x < px; x++) {
|
||
const a = d[(y * px + x) * 4 + 3];
|
||
if (a === 0) continue;
|
||
sum += a / 255;
|
||
if (x < minX) minX = x; if (x > maxX) maxX = x;
|
||
if (y < minY) minY = y; if (y > maxY) maxY = y;
|
||
}
|
||
}
|
||
return {
|
||
areaPx: sum, // alpha-площадь в px² увеличенного рендера
|
||
bx: minX / scale, by: minY / scale,
|
||
bw: (maxX - minX + 1) / scale, bh: (maxY - minY + 1) / scale
|
||
};
|
||
}, { svgString, w, h, scale });
|
||
|
||
const SCALE = 32;
|
||
const geo = {};
|
||
for (const k of ORDER) {
|
||
const g = GLYPHS[k];
|
||
const m = await ink(nativeSvg(g), g.viewBox[2], g.viewBox[3], SCALE);
|
||
geo[k] = {
|
||
// чернильный bbox в единицах ИСХОДНОГО viewBox (замер, не догадка)
|
||
ink: { x: +(g.viewBox[0] + m.bx).toFixed(3), y: +(g.viewBox[1] + m.by).toFixed(3), w: +m.bw.toFixed(3), h: +m.bh.toFixed(3) },
|
||
areaUnits: +(m.areaPx / (SCALE * SCALE)).toFixed(3), // alpha-площадь в единицах²
|
||
aspect: +(m.bw / m.bh).toFixed(3)
|
||
};
|
||
}
|
||
|
||
// --- ТЕКУЩЕЕ состояние: height + width:auto, как в отгруженном CSS ---
|
||
const current = {};
|
||
for (const k of ORDER) {
|
||
const g = GLYPHS[k], vb = g.viewBox;
|
||
const svgAt = (H) => '<svg xmlns="http://www.w3.org/2000/svg" style="display:block;height:' + H +
|
||
'px;width:auto" viewBox="' + vb.join(' ') + '"' + attr(g) + '>' + g.body + '</svg>';
|
||
const W_card = +(16 * (geo[k].ink.w / geo[k].ink.h)).toFixed(2);
|
||
const m16 = await ink(svgAt(16), Math.max(W_card, 1), 16, SCALE);
|
||
const m18 = await ink(svgAt(18), Math.max(W_card * 18 / 16, 1), 18, SCALE);
|
||
current[k] = {
|
||
inkBox: geo[k].ink.w + '×' + geo[k].ink.h + ' ед. → ' + W_card + '×16 px в карточке',
|
||
pxCard: +(m16.bw).toFixed(2) + '×' + +(m16.bh).toFixed(2),
|
||
pxWindow: +(m18.bw).toFixed(2) + '×' + +(m18.bh).toFixed(2),
|
||
massPx2_card: +(m16.areaPx / (SCALE * SCALE)).toFixed(2),
|
||
massPx2_window: +(m18.areaPx / (SCALE * SCALE)).toFixed(2),
|
||
fillRatioCard: +(m16.areaPx / (SCALE * SCALE) / (m16.bw * m16.bh)).toFixed(3)
|
||
};
|
||
}
|
||
|
||
// --- Слот: L = большая сторона чернильного bbox в единицах viewBox 24x24, центр -> 12,12 ---
|
||
const tf = (k, L) => {
|
||
const b = geo[k].ink, s = L / Math.max(b.w, b.h);
|
||
return { s: +s.toFixed(5), tx: +(12 - (b.x + b.w / 2) * s).toFixed(5), ty: +(12 - (b.y + b.h / 2) * s).toFixed(5) };
|
||
};
|
||
|
||
// опорный замер: все знаки в слоте при L = 19 единиц
|
||
const ref = {};
|
||
for (const k of ORDER) {
|
||
const t = tf(k, 19);
|
||
const m = await ink(slotSvg(GLYPHS[k], t, 24), 24, 24, SCALE);
|
||
ref[k] = {
|
||
s: t.s, massRender: +(m.areaPx / (SCALE * SCALE)).toFixed(2),
|
||
inkPx: +m.bw.toFixed(2) + '×' + +m.bh.toFixed(2)
|
||
};
|
||
}
|
||
|
||
// --- Решение: масса всех четырёх совпадает. Лёгкий знак задаёт полосу (L = 19.5 ед.),
|
||
// тяжёлые поджимаются; границы 14..20.5 ед., чтобы знак не лип к краю слота. ---
|
||
const LIGHT = 19.5, L_MIN = 14, L_MAX = 20.5;
|
||
const lightest = ORDER.slice().sort((a, b) => ref[a].massRender - ref[b].massRender)[0];
|
||
const TARGET = ref[lightest].massRender * Math.pow(LIGHT / 19, 2);
|
||
const solved = {};
|
||
for (const k of ORDER) {
|
||
const rawL = 19 * Math.sqrt(TARGET / ref[k].massRender);
|
||
const L = Math.min(L_MAX, Math.max(L_MIN, rawL));
|
||
const t = tf(k, +L.toFixed(2));
|
||
const m24 = await ink(slotSvg(GLYPHS[k], t, 24), 24, 24, SCALE);
|
||
const m16 = await ink(slotSvg(GLYPHS[k], t, 16), 16, 16, SCALE);
|
||
const m18 = await ink(slotSvg(GLYPHS[k], t, 18), 18, 18, SCALE);
|
||
solved[k] = {
|
||
L: +L.toFixed(2), clamped: Math.abs(rawL - L) > 0.01, s: t.s, tx: t.tx, ty: t.ty,
|
||
mass24: +(m24.areaPx / (SCALE * SCALE)).toFixed(2),
|
||
mass16: +(m16.areaPx / (SCALE * SCALE)).toFixed(2),
|
||
mass18: +(m18.areaPx / (SCALE * SCALE)).toFixed(2),
|
||
ink16: +(m16.bw).toFixed(2) + '×' + +(m16.bh).toFixed(2),
|
||
ink18: +(m18.bw).toFixed(2) + '×' + +(m18.bh).toFixed(2)
|
||
};
|
||
}
|
||
const masses24 = ORDER.map(k => solved[k].mass24);
|
||
const spread = Math.max(...masses24) / Math.min(...masses24);
|
||
|
||
const shortMarkup = (k, S) => slotSvg(GLYPHS[k], solved[k], S).replace(/<path d="M51\.2[^"]*"/, '<path d="…геометрия RuStore…"');
|
||
|
||
const report = {
|
||
measured_from: 'src/js/main.js LINK_ICONS (raster in Chromium via Playwright, scale 32x)',
|
||
geometry: geo, current,
|
||
slot_reference_L19: ref,
|
||
target: { lightest, TARGET: +TARGET.toFixed(3), LIGHT, L_MIN, L_MAX },
|
||
solved,
|
||
mass_spread_after: +spread.toFixed(3),
|
||
markup: Object.fromEntries(ORDER.map(k => [k, shortMarkup(k, 16)]))
|
||
};
|
||
fs.writeFileSync(path.join(OUT, 'glyph-mass.json'), JSON.stringify(report, null, 2) + '\n');
|
||
|
||
console.log('=== ЗАМЕР ГЕОМЕТРИИ (чернильный bbox в единицах исходного viewBox) ===');
|
||
console.table(ORDER.map(k => ({ знак: k, bbox: JSON.stringify(geo[k].ink), аспект: geo[k].aspect, 'площадь ед²': geo[k].areaUnits })));
|
||
|
||
console.log('=== ТЕКУЩЕЕ (height 16 карточка / 18 окно, width:auto) ===');
|
||
console.table(ORDER.map(k => ({ знак: k, 'карточка px': current[k].pxCard, 'окно px': current[k].pxWindow, 'масса@16 px²': current[k].massPx2_card, 'заполнение бокса': current[k].fillRatioCard })));
|
||
|
||
console.log('=== ВСЕ ЧЕТЫРЕ В СЛОТЕ 24×24 ПРИ L=19 (опора для выравнивания массы) ===');
|
||
console.table(ORDER.map(k => ({ знак: k, s: ref[k].s, 'масса px²': ref[k].massRender, чернила: ref[k].inkPx })));
|
||
|
||
console.log('=== РЕШЕНИЕ: единый слот, L на знак (масса всех четырёх совпала) ===');
|
||
console.table(ORDER.map(k => ({ знак: k, L: solved[k].L, s: solved[k].s, translate: solved[k].tx + ',' + solved[k].ty, 'масса@24 px²': solved[k].mass24, 'чернила@16': solved[k].ink16, 'чернила@18': solved[k].ink18 })));
|
||
console.log('разброс массы после выравнивания: max/min =', spread.toFixed(3));
|
||
|
||
await browser.close();
|
||
})();
|