Skip to content

Moved CSS named-color table to gosub_shared so inline styles can reso…#1137

Merged
jaytaph merged 1 commit into
gosub-io:mainfrom
jaytaph:css-color-fixes
Jul 20, 2026
Merged

Moved CSS named-color table to gosub_shared so inline styles can reso…#1137
jaytaph merged 1 commit into
gosub-io:mainfrom
jaytaph:css-color-fixes

Conversation

@jaytaph

@jaytaph jaytaph commented Jul 19, 2026

Copy link
Copy Markdown
Member

…lve named colors

Since we don't want to have dependencies between the render pipeline and css3 crates, we moved the named colors to gosub_shared (better solution available once we came up with one)

Summary by CodeRabbit

  • New Features
    • Added shared support for CSS named colors and system colors, with case-insensitive matching.
    • Inline color handling now resolves named colors via the shared table, while keeping transparent fully transparent.
  • Bug Fixes
    • Improved consistency of named-color resolution across rendering and style parsing; unknown color names now reliably fall back to keyword handling.
  • Tests
    • Added unit coverage for shared-table resolution, unknown-name fallback behavior, and transparent handling.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change centralizes CSS named-color data and lookup helpers in gosub_shared, updates CSS3 and inline-style parsing to consume them, removes the duplicated local table, and adds inline-style color parsing tests.

Changes

Shared CSS color lookup

Layer / File(s) Summary
Shared color table and public API
crates/gosub_shared/src/css_colors.rs, crates/gosub_shared/src/lib.rs
Adds the shared CSS named-color table, system color names, color entry type, case-insensitive lookup helpers, and public module registration.
CSS3 color integration
crates/gosub_css3/src/colors.rs, crates/gosub_css3/Cargo.toml
Re-exports shared color APIs, resolves named colors through named_color_hex, removes the local dataset, and removes lazy_static.
Inline style color parsing and validation
crates/gosub_render_pipeline/src/common/document/inline_style.rs
Uses shared named-color resolution while retaining direct parsing paths and adds coverage for named, unknown, and transparent colors.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: sharktheone

Poem

I’m a rabbit with colors tucked neatly away,
Shared names now guide every CSS ray.
Hex hops in, keywords stay clear,
Transparent clouds disappear.
One table to serve them all—
I nibble the duplication small!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: moving the CSS named-color table to gosub_shared for inline style resolution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/gosub_shared/src/css_colors.rs (1)

13-30: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Consider optimizing lookups for high-throughput parsing.

The linear searches over the static arrays using eq_ignore_ascii_case are simple and correct. However, if color resolution becomes a hot path during CSS parsing, consider using perfect hash maps (e.g., via the phf crate) or sorting the arrays alphabetically to enable binary searching.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/gosub_shared/src/css_colors.rs` around lines 13 - 30, The color lookup
functions named_color_hex, is_system_color, and is_named_color currently scan
static arrays linearly. Optimize these lookups for high-throughput parsing by
replacing the linear searches with a suitable static lookup structure, such as a
perfect hash map or alphabetically sorted arrays with binary search, while
preserving ASCII case-insensitive matching and existing return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/gosub_shared/src/css_colors.rs`:
- Around line 13-30: The color lookup functions named_color_hex,
is_system_color, and is_named_color currently scan static arrays linearly.
Optimize these lookups for high-throughput parsing by replacing the linear
searches with a suitable static lookup structure, such as a perfect hash map or
alphabetically sorted arrays with binary search, while preserving ASCII
case-insensitive matching and existing return behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a7c6b99-ab51-4b03-8487-335ec68b496e

📥 Commits

Reviewing files that changed from the base of the PR and between 0ded7ec and 3068fe9.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • crates/gosub_css3/Cargo.toml
  • crates/gosub_css3/src/colors.rs
  • crates/gosub_render_pipeline/src/common/document/inline_style.rs
  • crates/gosub_shared/src/css_colors.rs
  • crates/gosub_shared/src/lib.rs
💤 Files with no reviewable changes (1)
  • crates/gosub_css3/Cargo.toml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/gosub_render_pipeline/src/common/document/inline_style.rs`:
- Around line 46-47: Update the inline-style function matching around the
rgb/rgba match arms to use ASCII case-insensitive prefix checks, consistent with
the existing transparent handling. Preserve dispatch to parse_rgb and parse_rgba
so uppercase and mixed-case CSS function names are parsed correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba0147ba-0bb0-4840-a861-0413418b7c41

📥 Commits

Reviewing files that changed from the base of the PR and between 3068fe9 and cd2afdd.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • crates/gosub_css3/Cargo.toml
  • crates/gosub_css3/src/colors.rs
  • crates/gosub_render_pipeline/src/common/document/inline_style.rs
  • crates/gosub_shared/src/css_colors.rs
  • crates/gosub_shared/src/lib.rs
💤 Files with no reviewable changes (1)
  • crates/gosub_css3/Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/gosub_shared/src/lib.rs
  • crates/gosub_shared/src/css_colors.rs
  • crates/gosub_css3/src/colors.rs

Comment on lines 46 to 47
s if s.starts_with("rgb(") => parse_rgb(s),
s if s.starts_with("rgba(") => parse_rgba(s),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make rgb( and rgba( checks case-insensitive.

CSS function names are ASCII case-insensitive. Because starts_with is case-sensitive, valid inline styles like color: RGB(0, 0, 0) will bypass these match arms, fail the named_color_hex lookup, and incorrectly fall back to a keyword.

Consider using a case-insensitive prefix check to match the behavior implemented for transparent.

💡 Proposed fix
-        s if s.starts_with("rgb(") => parse_rgb(s),
-        s if s.starts_with("rgba(") => parse_rgba(s),
+        s if s.get(..4).is_some_and(|p| p.eq_ignore_ascii_case("rgb(")) => parse_rgb(s),
+        s if s.get(..5).is_some_and(|p| p.eq_ignore_ascii_case("rgba(")) => parse_rgba(s),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
s if s.starts_with("rgb(") => parse_rgb(s),
s if s.starts_with("rgba(") => parse_rgba(s),
s if s.get(..4).is_some_and(|p| p.eq_ignore_ascii_case("rgb(")) => parse_rgb(s),
s if s.get(..5).is_some_and(|p| p.eq_ignore_ascii_case("rgba(")) => parse_rgba(s),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/gosub_render_pipeline/src/common/document/inline_style.rs` around
lines 46 - 47, Update the inline-style function matching around the rgb/rgba
match arms to use ASCII case-insensitive prefix checks, consistent with the
existing transparent handling. Preserve dispatch to parse_rgb and parse_rgba so
uppercase and mixed-case CSS function names are parsed correctly.

@jaytaph
jaytaph merged commit 19812a9 into gosub-io:main Jul 20, 2026
10 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