Skip to content

feat: scope_css - extract scoped CSS from Tailwind output for Web Components (#50)#52

Merged
ssilvius merged 4 commits intomainfrom
feat/50-scope-css
Apr 17, 2026
Merged

feat: scope_css - extract scoped CSS from Tailwind output for Web Components (#50)#52
ssilvius merged 4 commits intomainfrom
feat/50-scope-css

Conversation

@ssilvius
Copy link
Copy Markdown
Contributor

Summary

  • Add scope_css(classes, full_css) — extracts matching @utility blocks from a Tailwind v4 CSS source file; strips all modifier prefixes (hover:, @sm:, focus-visible:, chained @sm:hover:, etc.) via rfind(':')'; includes only the @theme custom property declarations referenced by matched utilities via var(--...)
  • Add extract_classes_from_ts(source) — parses a .classes.ts file via oxc, walks exported string literals recursively (flat strings, object property values, arrays), returns deduplicated sorted class tokens
  • Both are re-exported from the veneer-adapters public API

Implementation notes

  • Regex-based CSS parsing (v1 spec — no lightningcss)
  • Shared find_matching_brace helper for both @utility and @theme block extraction
  • No new crate dependencies — regex was already in the workspace

Test plan

  • 14 scope-specific tests: empty inputs, modifier stripping (hover/CQ/@sm/focus-visible/chained), @theme inclusion scoped to referenced vars only, malformed CSS no-panic, TS flat string, TS object values, deduplication
  • 79 total veneer-adapters tests passing
  • cargo clippy -p veneer-adapters -- -D warnings clean
  • cargo fmt -- --check clean

Closes #50

🤖 Generated with Claude Code

ssilvius and others added 4 commits April 10, 2026 22:37
Add .claude/worktrees/ to .gitignore per legion team finding (#214) where
rust sub-agents staging with git add -A pulled worktree gitlinks into main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ponents (#50)

Add scope_css and extract_classes_from_ts to veneer-adapters for
per-component Shadow DOM stylesheet scoping.

- scope_css: extracts @Utility blocks matching a class list from a
  Tailwind v4 CSS source file; strips modifier prefixes (hover:, @sm:,
  focus-visible:, etc.) to resolve base names; includes only the @theme
  custom property declarations referenced by matched utilities
- extract_classes_from_ts: parses .classes.ts source via oxc, walks
  exported string literals (flat, object, array), returns deduplicated
  sorted class tokens

Regex-based CSS parsing (v1 spec). No new crate deps -- regex was
already in the workspace. 13 new tests, 78 total passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Extract find_matching_brace helper to dedupe brace-depth tracking
  across extract_utility_blocks and extract_relevant_theme_decls
- Replace body_end==0 sentinel with Option<usize> for correctness
- Remove dead @ prefix strip from strip_modifiers (rfind handles it)
- Collapse double-traversal in collect_classes_from_expr: recurse into
  object properties directly instead of calling extract_nested_object_classes
  then also iterating props
- Dedupe warning loops in scope_css to single pass
- Add chained-modifier test (@sm:hover:flex)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ssilvius ssilvius merged commit e2de4f7 into main Apr 17, 2026
7 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.

Implement scope_css - extract scoped CSS from Tailwind output for Web Components

1 participant