Skip to content

svg: use shared floating-point colour compatibility parser - #3798

Merged
dylanmtaylor merged 6 commits into
mainfrom
refactor/shared-svg-colors
Nov 17, 2026
Merged

dylanmtaylor merged 6 commits into
mainfrom
refactor/shared-svg-colors

Conversation

@dylanmtaylor

@dylanmtaylor dylanmtaylor commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Scope

Replace the local SVG colour parser/table with craft_svg::color::parse_rgba_compat, retaining EffectCraft's f64 channels and alpha. Existing colour/non-finite tests remain on the production re-export; add exact precision/clamping coverage.

Depends on storytold/craft-libs#1971 at c4e930536c8cf30928024902199b07f721642914. Merge the prerequisite, repin to merged shared main, and rerun hosted gates before merging this consumer.

This is colour parsing only, not full SVG completion. Path geometry, CSS stylesheet integration (#3797), document mapping and rendering remain separate. When reconciling #3797, retain both cutovers and pin a shared main containing both prerequisites.

Compatibility and attribution

  • Keep transparent, f64 channel/alpha precision, finite-channel clamping, loose legacy grammar and invalid hex handling. Strict quantized shared colour APIs are intentionally not substituted.
  • Safety change: standalone colour input above 64 MiB now returns None rather than allocating without a cap. Existing invalid-colour caller behavior handles this refusal. Shared storage also caps four arguments/eight hex digits.
  • Shared primary-author commits preserve Brandon Thomas's original parser and NetterSilver's finite-value guards. The app deletes the duplicate implementation and keeps its regression tests.
  • Only the craft-svg manifest revision changes. Lock removals reflect craft-svg's already-merged optional raster-codec dependency split, not unrelated dependency upgrades.

Validation

  • rustfmt --check, whitespace check, cargo metadata --no-deps --locked passed.
  • Shared isolated rustc harness passed16tests and10,220 exact old/new differential colour comparisons; all148 named colours match.
  • No full local Cargo build, Clippy, WASM or app tests run. Independent review and successful relevant hosted checks required. No CI bypass or workflow changes.

Summary by CodeRabbit

  • Bug Fixes
    • SVG color values retain fractional channel precision, clamp RGB components outside the supported range, and accept percentage-based components.
    • Hexadecimal color values with whitespace immediately after # are rejected.
    • Color parsing is more consistent across the app, including how supported color values are interpreted. These changes help ensure SVG colors are handled predictably across common input formats.

Merged shared integration

Shared #1971 merged as 54715d0b92ca22c031245136da6292f6a101978b. Consumer 99a9af8 merges current app main and repins craft-svg/XML to that merged commit; locked metadata, package formatting and whitespace checks pass. Fresh hosted integration gates required.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 76d98ec and 69b4115.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The SVG color module now re-exports craft-svg’s compatibility parser instead of implementing color parsing locally. The workspace pins a new craft-svg revision. Tests cover selected parser behaviors.

Changes: SVG color parsing

Layer / File(s) Summary
Use and validate the shared parser
Cargo.toml, crates/svg/src/color.rs
The craft-svg dependency revision changes. parse_color now re-exports parse_rgba_compat. Tests cover percentage and fractional RGB values, clamping, and rejection of whitespace after #.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: echelon, fredapps

Merge Risk: Minimal · previous review 76d98

This change moves SVG colour parsing to a shared parser and updates a dependency pin. No concrete defect was found. Hosted build and test checks should still pass before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "svg: use shared floating-point colour compatibility parser" matches the main change. The crates/svg/src/color.rs parse_color function is replaced by a re-export of craft_svg::color::parse_r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "svg: use shared floating-point colour compatibility parser" matches the main change. The crates/svg/src/color.rs parse_color function is replaced by a re-export of craft_svg::color::parse_rgba_compat, and the local named-color table and parsing helpers are removed. The title is specific, concise, and uses the crate prefix convention. The Cargo.toml revision bump and the lock file changes are supporting changes and need not appear in the title.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d0cbc53 and 76d98ec.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 1

  • Cargo.toml

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@sonarqubecloud

Copy link
Copy Markdown

@dylanmtaylor
dylanmtaylor merged commit 7a34cef into main Nov 17, 2026
11 checks passed
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