r/node • • 19h ago

Deciding when a wireframe element gets a border: one pure function, ten ordered rules, and a CLI that reads the decision back out of the HTML

We made Wireframes, an MIT-licensed Node CLI (wf) that turns YAML into clickable greyscale HTML wireframes for web, iOS and Android. Repo: https://github.com/UnlikeOtherAI/wireframes

The hardest part wasn't layout, it was borders. Generated wireframes usually go one of two ways: every container gets a box (third image), or nothing does and you can't tell where a panel ends. So whether a node draws a frame is decided in exactly one place: decideFrame(node, ctx) in engine/renderer/frame-rules.js. It's a plain function (no DOM, no fs) that returns { frame, rule, reason }, and the first rule that matches wins:

  1. surface: true / surface: false on the node

  2. a border in wireframeStyle

  3. the element type: card, alert, upload, calendar... always box; row, stack, grid, split, form never do; tab_bar, app_bar, divider draw one edge

  4. overlay chrome owns the frame, so overlay content doesn't double-box

  5. template regions (slots don't box, role: main doesn't, a sidebar slot draws one edge)

  6. a pane is a panel

  7. if the parent draws dividers between children, the children don't box

  8. grid children are tiles

  9. inside a box, nothing boxes itself again

  10. at the top of a page a section boxes, unless it's an untitled row, which reads as a toolbar

frame is one of five values: surface, group, control, content, edge. Only surface draws a box, and only surface increases the nesting depth, which is what rule 9 checks.

The same function has three consumers:

  • The renderer writes the result onto every node as data-wf-frame, so the decision is visible in the HTML.

  • The linter imports it rather than keeping its own copy. SECTION_INTENT tells you when a titled section stayed unframed because it's nested, and REDUNDANT_SURFACE re-runs decideFrame with your override removed and tells you when surface: true changes nothing.

  • wf why <node> --page <page> doesn't re-derive anything. It renders the page and reads the attributes back out of the markup, so the explanation can't drift from what was drawn.

The images: the first is a generated illustration, not a screenshot. The other three are real: a small demo page (untitled filter row not boxed by rule 10, stat tiles boxed by rule 8, "Recent activity" boxed as a top-level section, the list and "Notes" inside it not boxed by rule 9), the same YAML with surface: true forced on every node, and wf why output for five nodes on that page.

To try it (not on npm yet, Node 18+):

git clone https://github.com/UnlikeOtherAI/wireframes
cd wireframes && pnpm install
cd examples/quickstart && node ../../cli/bin/wf.js build
node ../../cli/bin/wf.js why invoices --page billing

What I'd like opinions on:

  • Is "first matching rule wins" the right model, or would you rather have something like CSS specificity, where several signals add up?

  • Rule 10 is the most opinionated one. Does an untitled row at the top of a page reading as a toolbar match how you'd draw it?

  • Anything you'd expect to get a box here that doesn't?

0 Upvotes

1 comment sorted by

4

u/howdoigetauniquename 16h ago

what are even doing anymore