Files
meshcore-analyzer/test-fluid-scaffolding.js
T
Kpa-clawbot 417b460fa0 feat(css): fluid scaffolding — clamp() spacing/type/container tokens (#1054) (#1066)
## Summary

Lands the **fluid CSS foundation** for the responsive scaffolding effort
(parent #1050). Pure additive change to the top of `public/style.css` —
no component CSS touched.

## What changed

### New tokens in `:root`
- **Spacing scale** — `--space-xs … --space-2xl` via `clamp()`. 1440px
targets match the prior hardcoded `4 / 8 / 16 / 24 / 32 / 48` px values
to within ~1px.
- **Type scale** — `--fs-sm … --fs-2xl` via `clamp(min, vw-based, max)`.
Floors keep text readable at 768px; caps prevent runaway growth at
2560px+.
- **Radii** — `--radius-sm/md/lg` via `clamp()`.
- **Container layout** — `--gutter` (`clamp()`) and `--content-max`
(`min(100% - 2*gutter, 1600px)`) for fluid horizontal layout without
media queries.

### Base consumption
- `html, body` now sets `font-size: var(--fs-md)`.

### Parallel-work safety
- Added `FLUID SCAFFOLDING` section header at the top.
- Added `COMPONENT STYLES` section header marking where the rest of the
file (nav, tables, charts, map, packets, analytics …) begins. Sibling
tasks 1050-3..6 / 1052-* edit inside that region and won't conflict with
this PR.

## TDD

- **Red:** `2d6f90a` — `test-fluid-scaffolding.js` asserts the new
tokens exist with `clamp()`/`min()`, that `html, body` consumes
`--fs-md`, and that the section marker is present. Fails on assertions
(15 failed, 0 passed).
- **Green:** `7b4d59b` — implementation in `public/style.css`. All 15
assertions pass.

## Acceptance criteria

- [x] Fluid spacing scale `--space-xs..--space-2xl` via `clamp()`
- [x] Fluid type scale `--fs-sm..--fs-2xl` via `clamp()`
- [x] Replace base body font-size with the new token
- [x] Container layout vars `--content-max`, `--gutter` via
`min()`/`clamp()`
- [x] No component CSS edits (only `:root`, `html`, `body`)
- [x] No visual regression at 1440px (token targets numerically match
prior px values)

## Notes for reviewers

- Pre-existing `test-frontend-helpers.js` failure on master is unrelated
(`nodesContainer.setAttribute is not a function`) and not introduced
here.
- `--content-max` uses `min(100% - 2*gutter, 1600px)` — the `100% - …`
arm wins on small viewports and guarantees a gutter always remains.

Fixes #1054

---------

Co-authored-by: clawbot <bot@corescope.local>
Co-authored-by: openclaw-bot <bot@openclaw.local>
Co-authored-by: meshcore-bot <bot@meshcore.local>
2026-05-05 01:14:39 -07:00

91 lines
3.1 KiB
JavaScript

/* Tests for fluid CSS scaffolding (issue #1054).
* Ensures `public/style.css` declares fluid spacing/type/container tokens
* via clamp() and that base selectors consume them instead of hardcoded px.
*/
'use strict';
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const css = fs.readFileSync(path.join(__dirname, 'public/style.css'), 'utf8');
let passed = 0, failed = 0;
function test(name, fn) {
try { fn(); passed++; console.log(`${name}`); }
catch (e) { failed++; console.log(`${name}: ${e.message}`); }
}
// --- Helpers ---------------------------------------------------------------
// Extract the :root { ... } block (first occurrence — the light/default one).
function rootBlock() {
const m = css.match(/:root\s*\{([\s\S]*?)\}/);
if (!m) throw new Error(':root block not found in style.css');
return m[1];
}
// Find the value of a custom property declared in :root.
function rootVar(name) {
const re = new RegExp(`${name}\\s*:\\s*([^;]+);`);
const m = rootBlock().match(re);
return m ? m[1].trim() : null;
}
function assertClamp(name) {
const v = rootVar(name);
assert.ok(v, `expected :root to declare ${name}`);
assert.ok(/clamp\s*\(/.test(v), `${name} should use clamp(); got: ${v}`);
}
// --- Fluid spacing tokens --------------------------------------------------
const SPACE_TOKENS = ['--space-xs', '--space-sm', '--space-md',
'--space-lg', '--space-xl', '--space-2xl'];
SPACE_TOKENS.forEach(t => {
test(`spacing token ${t} declared with clamp()`, () => assertClamp(t));
});
// --- Fluid type scale ------------------------------------------------------
const TYPE_TOKENS = ['--fs-sm', '--fs-md', '--fs-lg', '--fs-xl', '--fs-2xl'];
TYPE_TOKENS.forEach(t => {
test(`type token ${t} declared with clamp()`, () => assertClamp(t));
});
// --- Container tokens ------------------------------------------------------
test('container token --content-max declared', () => {
const v = rootVar('--content-max');
assert.ok(v, 'expected --content-max in :root');
assert.ok(/min\s*\(|clamp\s*\(/.test(v),
`--content-max should use min()/clamp(); got: ${v}`);
});
test('container token --gutter declared with clamp()', () => assertClamp('--gutter'));
// --- Base selectors must consume fluid tokens ------------------------------
test('html/body rule references fluid font-size token', () => {
// Look at the html, body { ... } rule (first one).
const m = css.match(/html\s*,\s*body\s*\{([^}]*)\}/);
assert.ok(m, 'html, body rule not found');
const block = m[1];
assert.ok(/font-size\s*:\s*var\(--fs-/.test(block),
`html/body should set font-size via var(--fs-*); block was: ${block.trim()}`);
});
// --- Section markers -------------------------------------------------------
test('style.css contains FLUID SCAFFOLDING section marker', () => {
assert.ok(/FLUID SCAFFOLDING/i.test(css),
'expected a "FLUID SCAFFOLDING" section marker comment');
});
// --- Summary ---------------------------------------------------------------
console.log(`\n${passed} passed, ${failed} failed`);
process.exit(failed ? 1 : 0);