Skip to content

Merge css() declarations into each element's own style - #107

Merged
jakejackson1 merged 2 commits into
mainfrom
fix/issue-77
Oct 26, 2026
Merged

jakejackson1 merged 2 commits into
mainfrom
fix/issue-77

Conversation

@gravitypdf-bot

Copy link
Copy Markdown
Contributor

css() read the style attribute of every matched element into one map, merged the new declarations into it, and wrote that one string back to all of them, so each element picked up the others' declarations.

$qp = html5qp('<div><p style="color:red"/><p style="font-size:2px"/></div>', 'p');
$qp->css('margin', '0');

// Before: both are 'color: red;font-size: 2px;margin: 0;'
// After:  'color: red;margin: 0;' and 'font-size: 2px;margin: 0;'

Change: QueryMutators::css() now does the parse, merge and write separately for each element. Non-element matches are still skipped (#98), and the getter is unchanged.

Tests: DOMQueryTest::testCssMergesIntoEachElementsOwnStyle sets styles with both the string and the array form on elements whose existing styles differ, including one with no style attribute, and checks that the getter still returns the first element's raw style. The test fails without the fix. phpunit, lint and lint:min-php all pass.

Fixes #77.

🤖 Generated with Claude Code

css() read the style attribute of every match into one map and wrote the
union back to all of them, so elements picked up each other's
declarations. Parse, merge and write per element instead.

Fixes #77.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.78%. Comparing base (6ae6acf) to head (91b5d83).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #107      +/-   ##
============================================
+ Coverage     90.69%   90.78%   +0.08%     
  Complexity     1424     1424              
============================================
  Files            25       25              
  Lines          3170     3168       -2     
============================================
+ Hits           2875     2876       +1     
+ Misses          295      292       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jakejackson1 jakejackson1 added the bug Something isn't working label Oct 26, 2026
@jakejackson1
jakejackson1 merged commit 0bc5fdb into main Oct 26, 2026
14 checks passed
@jakejackson1
jakejackson1 deleted the fix/issue-77 branch October 26, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

css() pools style declarations across the whole match set and writes the union to every element

2 participants