ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
96 stars 9 forks source link

add support for optimizing CSS `:has` / `:is` pseudo-selectors #1107

Closed thescientist13 closed 9 months ago

thescientist13 commented 1 year ago

Related Issue

resolves #1106

So for example, with this HTML

<h1>Heading for :has (should be red)</h1>
<p>Testing :has!</p>

<h1>Heading for :is (should not be red)</h1>
<ol>
  <li>Saturn</li>
  <li>
    <ul>
      <li>Mimas</li>
      <li>Enceladus</li>
      <li>
        <ol>
          <li>Voyager</li>
          <li>Cassini</li>
        </ol>
      </li>
      <li>Tethys</li>
    </ul>
  </li>
  <li>Uranus</li>
  <li>
    <ol>
      <li>Titania</li>
      <li>Oberon</li>
    </ol>
  </li>
</ol>

And this CSS (from the MDN page)

h1:has(+ p) {
  color: red;
}

ol {
  list-style-type: upper-alpha;
  color: darkblue;
}

:is(ol, ul, menu:unsupported) :is(ol, ul) {
  color: green;
}

:is(ol, ul) :is(ol, ul) ol {
  list-style-type: lower-greek;
  color: chocolate;
}

The styles work as expected in dev and production builds Screenshot 2023-11-03 at 7 37 48 PM Screenshot 2023-11-03 at 7 51 25 PM

Summary of Changes

  1. Add support for optimizing :has
  2. Add support for optimizing :is
  3. Add test case

TODO

  1. [x] Demo / test
  2. [x] also need :is support?