26 Commits

Author SHA1 Message Date
Jordan Pittman
01f928d6de
Handle variants in utility selectors using :where() and :has() (#9309)
* Replaces classes in utility selectors like :where and :has

* Update changelog

* wip
2022-09-12 15:08:31 -04:00
Jordan Pittman
db50bbbc71
Handle variants on complex selectors (#9262)
* Handle variants on complex selector utilities

* Update changelog
2022-09-06 12:58:38 -04:00
Jordan Pittman
15dc5a3da9
Remove text opacity CSS variables from ::marker (#8622)
* Refactor

* Allow parallel variant fns to mutate the container

* Remove text color variable from marker pseudo class

wip

* Update changelog
2022-06-14 10:09:09 -04:00
Jordan Pittman
037396b4a6
Ignore PostCSS nodes returned by addVariant (#8608)
* Fix issue with returning postcss nodes in addVariant

It’s not a supported use case but it didn’t use to break so let’s just fail silently

* Update changelog
2022-06-12 10:50:41 -04:00
Adam Wathan
128030fcfa
Only apply hover styles when supported (future) (#8394)
* Only apply hover styles when supported (future)

Co-Authored-By: Andrew Brown <browner12@gmail.com>

* update changelog

Co-authored-by: Andrew Brown <browner12@gmail.com>
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-05-20 11:20:20 -04:00
Adam Wathan
7fa2a200b2
Reject invalid custom and arbitrary variants (#8345)
* WIP

Still need to write error message

* Update error message

first pass at something better

* Detect invalid variant formats returned by functions

* Add proper error message

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-05-14 13:58:02 -04:00
Jordan Pittman
1402be2dd0
Handle utilities with multiple and/or grouped selectors better (#8262)
* Add failing test cases

* Flatten finalizeSelector code

* Use AST operations to format selector classes

With this change we only parse the selector once and operate on the AST until we need to turn it back into a selector. In addition this lets us solve an issue where .replace(…) did the wrong thing because it doesn’t understand that .base and .base-foo are two different classes

* Remove extraneous, non-matching selectors from utilities

* Update changelog
2022-05-03 13:10:27 -04:00
Jordan Pittman
7ed46b6f52 Re-enable new features
This reverts commits 1456ed9021b3455dbb4458c2fb7d8ab66dfb3fed, d0269c24b3c7ad4557b7e3f2779bd15c5ac501f7, and 57699a04036c542d82e7b7102d775d4d2379493d.
2022-04-12 14:13:04 -04:00
Jordan Pittman
d0269c24b3 Temp fix CS errors 2022-04-12 14:03:24 -04:00
Jordan Pittman
57699a0403
Prep for patch release (#8098)
* Disable backdrop variant

* Disable enabled variant

* Disable border spacing utilities

* Disable text-start/end utilities

* Disable poll option in CLI

* Disable ring color default fn

* Disable dark mode class name customization

* Disable support for `Document` node types

* Disable rgb/hsl fns

* Update tests

* Temporarily disable type generation

* Update changelog
2022-04-12 13:58:57 -04:00
Jordan Pittman
4fed060b7c
Add support for PostCSS Document nodes (#7291)
* Run Tailwind CSS once for each root in a postcss document

* Update changelog
2022-02-25 14:52:20 -05:00
Jordan Pittman
f116f9f664
Remove opacity variables from :visited pseudo class (#7458)
* Support functions in pseudo variant list

* Remove text/border/bg color from :visited

* Update changelog
2022-02-14 13:24:18 -05:00
Jordan Pittman
e2928883e8
Only emit utility/component variants when those layers exist (#7066) 2022-01-14 10:20:43 -05:00
Robin Malfait
b341813d3f
Ensure we can use < and > characters in modifiers (#6851)
* ensure we can use "special" characters in modifiers

Fixes: #6778

* update changelog
2022-01-03 11:17:58 +01:00
Robin Malfait
2fdbe108cb
Only generate variants for non-user layers (#6589)
* only generate variants for non-user layers

If you have the following css:

```css
@tailwind utilities;
.foo {
  color: red;
}
```

And you HTML looks like this:
```html
<div class="hover:foo"></div>
```

Then the output should _not_ generate a `.hover\:foo {}` class.

* ensure that you can apply user csss (without variants)

* update changelog
2021-12-17 14:49:07 +01:00
Oliver Williams
95dd82b749
use text-decoration-line instead of text-decoration (#6378)
* use text-decoration-line instead of text-decoration

* fix tests

Co-authored-by: Oliver Williams <oliver@Olivers-MacBook-Pro.local>
2021-12-13 16:09:14 -05:00
Robin Malfait
81f52a24f4
Ensure complex variants with multiple classes work (#6311)
* ensure complex variants with multiple classes work

* update changelog
2021-12-10 10:57:40 +01:00
Robin Malfait
a3579bcf2f
Enforce the order of pseudo elements (#6018)
* enforce the order of some variants

* update changelog

* use better algorithm
2021-11-12 16:38:03 +01:00
Adam Wathan
a6bcd22722 Add test for using variants with multi-class selectors 2021-11-06 07:25:32 -04:00
Robin Malfait
fd9dbe18ac
Allow the use of @media print without parens (#5898) 2021-10-27 15:04:37 +02:00
Robin Malfait
36c880abab
Improve before and after variants (#5820)
* remove unused `withRule`

* ensure all ::before and ::after elements have content

* update --tw-content for the content plugin

* simplify `before` and `after` variants

* update tests, to reflect changes

* make new `format` and `wrap` API's private for now

* allow returning a format string from `addVariant` callback

* add `content: var(--tw-content)` for before/after variants

* update tests to add `content: var(--tw-content)`

* update changelog
2021-10-18 18:11:34 +02:00
Robin Malfait
f12c0e1fa5
Improve css expectations in tests (#5819)
* use String.raw for css escapes

This will allow us to write code like:
```css
.mobile\:font-bold {}
```
Instead of
```css
.mobile\\:font-bold {}
```

Which resembles "real" css way better in our tests.

* use String.raw in integration tests as well
2021-10-18 12:08:48 +02:00
Robin Malfait
5809c4d07c
Improve addVariant API (#5809)
* fix incorrect comment

Probably messed this up in another PR, so just a bit of cleaning.

* implement a formatVariantSelector function

This will be used to eventually simplify the addVariant API.

The idea is that it can take a list of strings that define a certain
format. Then it squashes everything to a single format how you would
expect it.

E.g.:

Input:
  - '&:hover'
  - '&:focus'
  - '.dark &'
  - ':merge(.group):hover &'
  - ':merge(.group):focus &'
Output:
  - ':merge(.group):focus:hover .dark &:focus:hover'

The API here is:
  - `&`, this means "The parent" or "The previous selector" (you can
    think of it like if you are using nested selectors)
  - `:merge(.group)`, this means insert a `.group` if it doesn't exist
    yet, but if it does exist already, then merge the new value with the
    old value. This allows us to merge group-focus, group-hover into a
    single `.group:focus:hover ...`

* add new `format`, `withRule` and `wrap` API for addVariant

* implement backwards compatibility

This will ensure that the backwards compatibility for `modifySelectors`
and direct mutations to the `container` will still work.

We will try to capture the changes made to the `rule.selector`, we will
also "backup" the existing selector. This allows us to diff the old and
new selectors and determine what actually happened.

Once we know this, we can restore the selector to the "old" selector and
add the diffed string e.g.: `.foo &`, to the `collectedFormats` as if
you called `format()` directly. This is a bunch of extra work, but it
allows us to be backwards compatible.

In the future we could also warn if you are using `modifySelectors`, but
it is going to be a little bit tricky, because usually that's
implemented by plugin authors and therefore you don't have direct
control over this. Maybe we can figure out the plugin this is used in
and change the warning somehow?

* fix incorrect test

This was clearly a bug, keyframes should not include escaped variants at
all. The reason this is here in the first place is because the nodes in
a keyframe are also "rule" nodes.

* swap the order of pseudo states

The current implementation had a strange side effect, that resulted in
incorrect class definitions. When you are combining the `:hover` and
`:focus` event, then there is no difference between `:hover:focus` and
`:focus:hover`.

However, when you use `:hover::file-selector-button` or `::file-selector-button:hover`,
then there is a big difference. In the first place, you can hover over the full file input
to apply changes to the `File selector button`.
In the second scenario you have to hover over the `File selector button` itself to apply changes.

You can think of it as function calls:
- focus(hover(text-center))

What you would expect is something like this:
`.focus\:hover\:text-center:hover:focus`, where `hover` is on the
inside, and `focus` is on the outside. However in the current
implementation this is implemented as
`.focus\:hover\:text-cener:focus:hover`

* add more variant tests for the new API

* update parallel variants tests to make use of new API

* implement core variants with new API

* simplify/cleanup existing plugin utils

We can get rid of this because we drastically simplified the new
addVariant API.

* add addVariant shorthand signature

The current API looks like this:

```js
addVariant('name', ({ format, wrap }) => {
  // Wrap in an atRule
  wrap(postcss.atRule({ name: 'media', params: '(prefers-reduced-motion: reduce)' }))

  // "Mutate" the selector, for example prepend `.dark`
  format('.dark &')
})
```

It is also pretty common to have this:
```js
addVariant('name', ({ format }) => format('.dark &'))
```
So we simplified this to:
```js
addVariant('name', '.dark &')
```

It is also pretty common to have this:
```js
addVariant('name', ({ wrap }) => wrap(postcss.atRule({ name: 'media', params: '(prefers-reduced-motion: reduce)' })))
```
So we simplified this to:
```js
addVariant('name', '@media (prefers-reduced-motion: reduce)')
```

* improve fontVariantNumeric implementation

We will use `@defaults`, so that only the resets are injected for the
utilities we actually use.

* fix typo

* allow for nested addVariant shorthand

This will allow to write something like:

```js
addVariant('name', `
  @supports (hover: hover) {
    @media (print) {
      &:hover
    }
  }
`)
// Or as a one-liner
addVariant('name', '@supports (hover: hover) { @media (print) { &:hover } }')
```

* update changelog
2021-10-18 11:26:11 +02:00
Robin Malfait
bd21bef99a
Polish match APIs (#5664)
* fix incorrect logic for validating content paths

* remove `includeRules` helper

* generate keyframes as part of the animate plugin

* add matchUtilities

* splitup `variantPlugins` and `corePlugins`
2021-10-01 17:31:09 +02:00
Brad Cornes
4919cbfbb8
Update color parsing and formatting (#5442)
* Replace `culori` with simple color parser

* Use space-separated color syntax

* Update default color values to use space-separated syntax

* Update separator regex

* Fix tests

* add tests for the new `color` util

Also slightly modified the `color` util itself to take `transparent`
into account and also format every value as a string for consistency.

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2021-09-09 16:15:53 +02:00
Robin Malfait
e37931ba65
JIT by default - move tests and make them consistent (#5374)
* move `./tests/jit` to `./tests`

* make tests consistent

Abstracted a `run` function and some syntax highlighting helpers for
`html`, `css` and `javascript`.
2021-09-03 13:48:16 +02:00