Skip to content

refactor(core): layoutMultipleSystems options object + shared group-collapse machinery - #2057

Merged
kompiro merged 2 commits into
mainfrom
refactor/core-layout-options
Jul 17, 2026
Merged

kompiro merged 2 commits into
mainfrom
refactor/core-layout-options

Conversation

@kompiro

@kompiro kompiro commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

Point 4 of the packages/core refactoring analysis in #2014.

Step 1 (signature): layoutMultipleSystems took 10 mostly-optional positional params that just re-splat the LayoutOptions object layout() already received. Changed the signature to layoutMultipleSystems(viewSlice, options: LayoutOptions); the call site in layout() now passes options straight through instead of destructuring into positionals.

Step 2 (shared machinery): layout()'s single-system path and layoutMultipleSystems()'s per-system loop both duplicated the group-collapse (collapseGroups) + grouped-layer-assignment (assignGroupedLayers) sequence — the multi-system path's comments literally said "mirrors layout()". Extracted collapseAndAssignGroupLayers(), a pure helper returning { nodes, edges, stubGroup, remapEndpoint, foldedEdgeDiffState, groupIdOf, grouped }; both functions now call it.

Preserved asymmetry

The two callers differ on whether they commit the collapse when assignGroupedLayers fails to produce bands:

  • layout() always adopts allNodes/allEdges from the collapse result once the groupBy && groupIndex block runs, regardless of whether grouping succeeded.
  • layoutMultipleSystems() only adopts workNodes/workEdges (and the grouped-layer results) when collapsed.grouped is non-null — on failure it keeps the original uncollapsed rawNodes/sys.edges.

Per the issue's explicit instruction, this difference was not unified — each call site still decides independently what to do with the helper's grouped result, exactly matching pre-refactor behavior. (In practice the divergence is a no-op today: collapseGroups is identity when nothing is configured to collapse, and the only path where assignGroupedLayers can return null after a real collapse is one an existing bug guard already handles the same way on both sides — this PR does not change that.)

Verification

Gate Result
pnpm --filter @karasu-tools/core test ✅ 95 files / 2362 tests passed
pnpm typecheck (full repo) ✅ all 9 packages pass
pnpm check:cycles ✅ no circular dependency
pnpm knip ✅ 0 unused exports (pre-existing @resvg/resvg-wasm config hint only)
pnpm lint ✅ 0 warnings / 0 errors
Byte-identity render check ✅ all 25 bundled example projects (examples/en/*, examples/ja/*) rendered via buildAllViewsSvgProject in both shape and icon display modes — 50/50 SVGs byte-identical between main and this branch

No changeset — internal refactor, zero user-visible change (per .claude/rules/changesets.md).

Refs #2014

🤖 Generated with Claude Code

kompiro and others added 2 commits July 17, 2026 14:54
…-collapse machinery

layoutMultipleSystems() took 10 mostly-optional positional params that
just re-splat the LayoutOptions object layout() already received.
Change the signature to layoutMultipleSystems(viewSlice, options) and
pass the options object straight through from the layout() call site.

Also extract collapseAndAssignGroupLayers(), the group-collapse +
assignGroupedLayers sequence duplicated between layout()'s single-system
path and layoutMultipleSystems()'s per-system loop. The two callers
differ on whether they commit the collapsed nodes/edges when band
assignment fails to produce groups (layout() always keeps them once the
block runs; layoutMultipleSystems() only adopts them when grouping
succeeds) — that decision stays at each call site so both paths keep
today's behavior exactly.

Zero behavior change: full core test suite passes, and all 25 bundled
example projects (en+ja) rendered via buildAllViewsSvgProject in both
shape and icon display modes (50 SVGs) are byte-identical against main.

Refs #2014

Co-Authored-By: Claude <[email protected]>

This branch was successfully deployed

1 active deployment
preview — c70e7a10 Deployed Jul 17, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant