feat(compose): cortex compose command stacks widgets into single SVG#12
Merged
AbdullahBakir97 merged 1 commit intomainfrom Apr 27, 2026
Merged
feat(compose): cortex compose command stacks widgets into single SVG#12AbdullahBakir97 merged 1 commit intomainfrom
AbdullahBakir97 merged 1 commit intomainfrom
Conversation
Tier C #8. New CLI command + supporting cortex.compose module. ## Use case Profile READMEs often want ONE image to drop in (a hero stack of header-banner + brain + badges + footer-banner) rather than 17 separate references. compose() builds each listed widget in-memory and nests them vertically inside one outer <svg>. ## CLI cortex compose -c examples/extreme.yml \ -w synthwave-banner -w brain-anatomical -w badges \ -w yearly-highlights -w footer-banner \ -o assets/composite.svg [--gap 12] [--list] --list prints the available widget slugs and exits. ## Implementation - _WIDGET_REGISTRY maps slug -> (builder_module, builder_func, filename), mirroring the order in cortex.__init__.build_all but accessible by name. - _build_widget_svg() invokes the matching builder, reads back the SVG text, parses the viewBox to extract intrinsic height. Falls back to the height= attribute or 200px on parse failure. - _nest_svg() rewrites the outer <svg> opening tag with x/y/width/height while preserving the child's viewBox, xmlns, and other attributes. Renderers handle the coordinate-system mapping automatically. - Composite outer viewBox = 1200 × sum(child_heights) + gap*(n-1). ## Tests 8 new tests in test_compose.py: • list_available() returns all 22 known widget slugs • _strip_xml_decl removes <?xml ...?> declaration safely • compose() with valid widgets produces well-formed XML • Unknown slug raises ValueError with helpful message • Stacked widgets have monotonically-increasing y positions • Composite total height = sum(child heights) + gaps • Size budget for 3-widget compose under 60KB Total tests: 164/164 passing. ## Smoke-test $ cortex compose -c examples/extreme.yml \ -w synthwave-banner -w brain-anatomical -w badges \ -w yearly-highlights -w footer-banner -o /tmp/composite.svg [OK] Composite SVG -> /tmp/composite.svg (158.7 KB) → 1200×2374 viewBox, all 5 widgets stacked correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tier C #8. New CLI command
cortex composeproduces a single composite SVG from any subset of the 22 widgets — for users who want one image to drop in their README rather than 17 separate references.Test plan