267 Commits

Author SHA1 Message Date
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
b49dc7cafa
Move important selector to the front when @apply-ing selector-modifying variants in custom utilities (#8313)
* Fix generated utilities using `@apply` with important selectors

* Update changelog
2022-05-09 14:20:36 -04:00
Robin Malfait
be51739337
Arbitrary variants (#8299)
* register arbitrary variants

With the new `addVariant` API, we have a beautiful way of creating new
variants.

You can use it as:
```js
addVariant('children', '& > *')
```

Now you can use the `children:` variant. The API uses a `&` as a
reference for the candidate, which means that:
```html
children:pl-4
```

Will result in:
```css
.children\:pl-4 > * { .. }
```

Notice that the `&` was replaced by `.children\:pl-4`.

We can leverage this API to implement arbitrary variants, this means
that you can write those `&>*` (Notice that we don't have spaces) inside
a variant directly. An example of this can be:
```html
<ul class="[&>*]:underline">
  <li>A</li>
  <li>B</li>
  <li>C</li>
</ul>
```
Which generates the following css:
```css
.\[\&\>\*\]\:underline > * {
  text-decoration-line: underline;
}
```

Now all the children of the `ul` will have an `underline`. The selector
itself is a bit crazy since it contains the candidate which is the
selector itself, it is just escaped.

* add tests for arbitrary variants

This still requires some work to the `defaultExtractor` to make sure it
all works with existing code.

* update changelog

* Fix candidate detection for arbitrary variants

* Refactor

* Add support for at rules

* Add test for attribute selectors

* Fix test

* Add attribute selector support

* Split top-level comma parsing into a generalized splitting routine

We can now split on any character at the top level with any nesting. We don’t balance brackets directly here but this is probably “enough”

* Split variants by separator at the top-level only

This means that the separator has to be ouside of balanced brackets

* Fix extraction when using custom variant separators

* Support custom separators when top-level splitting variants

* Add a second multi-character separator test

* Split tests for at-rule and at-rule with selector changes

* Add nested at-rule tests

* Fix space-less at-rule parsing in addVariant

* Add test for using with `@apply`

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-05-08 12:24:59 -04:00
Jordan Pittman
d676086a75
Rewrite default class extractor (#8204)
* Rewrite default extractor

* Eliminate lookbehind assertions in expand apply at rules

* Update changelog
2022-05-04 16:08:25 -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
7c337f24fc
Only check selectors containing apply candidates for circular dependencies (#8222)
* Only check selectors containing base apply candidates for circular dependencies

When given a two rule like `html.dark .a, .b { … }` and `html.dark .c { @apply b }` we would see `.dark` in both the base rule and the rule being applied and consider it a circular dependency. However, the selectors `html.dark .a` and `.b` are considered on their own and is therefore do not introduce a circular dependency.

This better matches the user’s mental model that the selectors are just two definitions sharing the same properties.

* Update changelog
2022-05-02 11:11:21 -04:00
Stefan Rumzucker
c3381d90a5
Remove default [hidden] style in preflight (#8248)
* Remove default `[hidden]` style in preflight

* Update snapshots

* Update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-05-02 10:30:06 -04:00
Brad Cornes
cc696338b1
Improve type detection for arbitrary color values (#8201) 2022-04-28 11:18:51 +01:00
Jordan Pittman
67bf8167d1
Allow arbitrary values with commas in @apply (#8125)
* De-indent code

* Allow arbitrary values with commas in `@apply`

* Update changelog
2022-04-15 16:23:30 -04:00
Jordan Pittman
e5ed08b5cb
Handle duplicate atrules without children (#8122)
* Handle duplicate atrules without children

We assumed that all At Rule nodes had children. Including ones that do not and should not — for example `@import url(…);`. Since this is not the case we’ll skip adding children for nodes that don’t have any.

* Update changelog

Co-authored-by: Jordi Marimon Palarea <jordimarimon7@gmail.com>
2022-04-15 12:24:27 -04:00
Jordan Pittman
5c76de72ba
Require matching prefix when detecting negatives (#8121)
* Require matching prefix when detecting negatives

* Update changelog
2022-04-15 11:57:06 -04:00
Michaël Gallego
206f1d6df5
Make font weight inherit in preflight (#8078)
* Make font weight inherit

* Update snapshots

* Update changelog

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-04-15 11:26:24 -04:00
Jordan Pittman
34c1e36c2a
Don’t split vars with numbers in them inside arbitrary values (#8091)
* Don’t mangle vars with numbers in them

* Update changelog
2022-04-13 09:31:10 -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
Robin Malfait
2d3a748d1f
Ensure the percentage data type is validated correctly (#8015)
* ensure the `percentage` data type is validated correctly

When checking for our data types, we have to make sure that each part is
correct, this wasn't happening for the `percentage` data type, which
meant that `top_right_50%` was a valid percentage value because it ended
in `%` which is not correct.

Because of this, the generated code was non-existent because we got a
warning:

  The class `bg-[top_right_50%]` is ambiguous and matches multiple utilities.
     Use `bg-[length:top_right_50%]` for `background-size: top right 50%`
     Use `bg-[position:top_right_50%]` for `background-position: top right 50%`
   If this is content and not a class, replace it with `bg-&lsqb;top_right_50%&rsqb;` to silence this warning.

But this is not correct because this can never be a valid background
size due to the `top right` section.

This fixes it by validating each part individually, and now we get
generated css.

* update changelog
2022-04-01 12:37:22 +02:00
Robin Malfait
ea80db213a
fix plugin order 2022-03-25 22:36:18 +01:00
seb-jean
79f018c16b
Add backdrop variant (#7924)
* Update corePlugins.js

* Update variants.test.html

* Update variants.test.css
2022-03-25 15:42:27 -04:00
Robin Malfait
315e3a2445
Allow for custom properties in rgb, rgba, hsl and hsla colors (#7933)
* allow for custom properties in `rgb`, `rgba`, `hsl` and `hsla` colors

* update changelog

* add more `parseColor` test cases
2022-03-24 12:43:21 +01:00
Adam Wathan
c9d2d0d5eb
Add enabled variant (#7905)
* Add enabled variant

* Update changelog
2022-03-22 10:43:39 -04:00
Robin Malfait
48728ed5d3
Fix generation of div:not(.foo) if .foo is never defined (#7815)
* fix little typo

* ensure that `div:not(.unknown-class)` gets generated

* update changelog
2022-03-17 16:35:40 +01:00
Jordan Pittman
68d896bbbe
Don't output unparsable arbitrary values (#7789)
* Refactor

* Don’t output unparsable arbitrary values

* Update changelog
2022-03-08 12:43:06 -05:00
Juan Martín Seery
dbb5b1d8f7
Added border-spacing utility (#7102)
* Added `border-spacing` utility

* Update to base CSS variable approach

Co-authored-by: Jonathan Reinink <jonathan@reinink.ca>
2022-03-04 11:20:23 -05:00
Samuel Alev
bc46d0e0bc
Fix extraction from template literal/function with array (#7481)
* fix: allow extraction from template literal with array

* fix: support extraction from array in function

* test: add more tests for function and template

* test: add test for dynamic classes

* test: add dynamic class test in js

* test: add dynamic class test in js single quote

* Cleanup a bit

* Update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-03-01 14:23:06 -05:00
vitorrd
7df3d938ec
Correctly parse and prefix animation names with dots (#7163)
* Add prefix alone to animation names. Fixes #7149.

* Add test for keyframe animations with a dot in the name

* Add test for prefixed version

* Fix CS

* Simplify

* Update changelog

* Fix

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-03-01 14:08:43 -05:00
Adam Wathan
ec962f09dd Use tuple syntax for customizing darkMode class name 2022-02-25 20:03:07 -05:00
Michael De Giovanni
77156de519 custom dark mode class 2022-02-25 19:59:23 -05: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
bbf3a37810
Add rgb and hsl color helpers for CSS variables (#7665)
* Add rgb/hsl color helpers

* Update changelog

Co-authored-by: Stefan Schweiger <staeff@me.com>
2022-02-25 14:03:40 -05:00
Adam Wathan
f7a9d370c8
Only add ! to selector class matching template candidate (#7664)
* Only add `!` to selector class matching template candidate

Fixes #7226.

Before this PR, if you had a class like:

```css
.one .two {
  background: black
}
```

...and then used `!one` in your template, the generated CSS would be this:

```css
.\!one .\!two {
  background: black !important
}
```

This would cause the styles to not be applied unless you also added `!` to the beginning of other classes in the template that are part of this selector.

This PR makes sure that other classes in the selector aren't mistakenly prefixed with `!`, so that you can add `!` to only one of the classes in your template and get the expected result.

* Update CHANGELOG
2022-02-25 13:17:44 -05:00
Jordan Pittman
bd167635d5
Invalidate context when main css changes (#7626)
* Invalidate context when CSS changes

* Remove invalidation count check

* Add sass integration test

* Update changelog
2022-02-25 13:12:45 -05:00
Adam Wathan
d9bc25da6a Inline test resources 2022-02-25 13:00:57 -05:00
Jordan Pittman
910b655388
Use local user css cache for apply (#7524)
* Fix context reuse test

* Don't update files with at-apply when content changes

* Prevent at-apply directives from creating new contexts

* Rework apply to use local postcss root

We were storing user CSS in the context so we could use it with apply. The problem is that this CSS does not get updated on save unless it has a tailwind directive in it resulting in stale apply caches. This could result in either stale generation or errors about missing classes.

* Don’t build local cache unless `@apply` is used

* Update changelog
2022-02-25 08:35:22 -05:00
Jordan Pittman
04686b8a05
Split box shadows on top-level commas only (#7479)
* Split box shadows on top-level commas only

* Update changelog
2022-02-23 11:31:55 -05:00
Jordan Pittman
b94d565eb6
Preserve source maps for generated CSS (#7588)
* Preserve source maps for `@apply`

* Overwrite the source for all cloned descendants

* Preserve source maps when expanding defaults

* Verify that source maps are correctly generated

* Update changelog
2022-02-23 11:24:54 -05:00
Jordan Pittman
d72b277ba6
Allow default ring color to be a function (#7587)
* Allow default ring color to be a function

* Update changelog
2022-02-22 16:51:04 -05:00
Jordan Pittman
3b8ca9d4eb
Recursively collapse adjacent rules (#7565)
* Recursively collapse adjacent rules

* Update changelog
2022-02-21 12:58:12 -05:00
Jordan Pittman
af64d7190c
Prevent nesting plugin from breaking other plugins (#7563)
* Prevent nesting plugin from breaking other plugins

This uses a private API but it’s the only solution we have right now. It’s guarded to hopefully be less breaking if the API disappears.

* Update changelog
2022-02-21 10:12:39 -05:00
Robin Malfait
63537aaa89
Implement getClassOrder instead of sortClassList (#7459)
* implement `getSortOrder` instead of `sortClassList`

* rename `getSortOrder` to `getClassOrder`

* update changelog
2022-02-16 11:03:00 +01:00
Jordan Pittman
be5d5c9e66
Fix wildcard duplication issue (#7478)
This would be better as a symbol but the stringy-ness of class candidates is fairly well baked into assumptions across the codebase. Using `new String` with a well placed check seems to solve the problem.
2022-02-15 13:44:19 -05:00
Jordan Pittman
db475be6dd
Support arbitrary values + calc + theme with quotes (#7462)
* Support arbitrary values + calc + theme with quotes

* Update changelog
2022-02-14 15:44:27 -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
Robin Malfait
96d4ce2516
Expose context.sortClassList(classes) (#7412)
* add prettier-plugin-tailwindcss

This will use the prettier plugin in our tests as well, yay consistency!

* ensure that both `group` and `peer` can't be used in `@apply`

This was only configured for `group`

* expose `sortClassList` on the context

This function will be used by the `prettier-plugin-tailwindcss` plugin,
this way the sorting happens within Tailwind CSS itself adn the
`prettier-plugin-tailwindcss` plugin doesn't have to use internal /
private APIs.

The signature looks like this:
```ts
function sortClassList(classes: string[]): string[]
```

E.g.:
```js
let sortedClasses = context.sortClassList(['p-1', 'm-1', 'container'])
```

* update changelog

* add sort test for utilities with the important modifier e.g.: `!p-4`
2022-02-10 18:06:41 +01:00
Jordan Pittman
01fbe196c4
Fix negative utility generation and detection when using a prefix (#7295)
* Add failing tests for negative utility detection

We're not generating them properly in all cases, when using at-apply we sometimes crash, and safelisting doesn't currently work as expected.

* Refactor

* Generate utilities for negatives before and after the prefix

* Properly detect negative utilities with prefixes in the safelist

* Refactor test a bit

* Add class list tests

* Update changelog
2022-02-07 10:24:30 -05:00
Jordan Pittman
ab9fd951dd
Use less hacky fix for urls detected as custom properties (#7275)
* Use less hacky fix for urls detected as custom properties

* Add more test cases

* Update changelog
2022-02-07 10:00:19 -05:00
Jordan Pittman
dc6644e0c8
Eliminate recursion from candidatePermutations (#7331) 2022-02-07 09:52:54 -05:00
Jordan Pittman
50802e1aed
Correctly parse shadow lengths without a leading zero (#7289)
* Correctly parse shadow lengths without a leading zero

* Update changelog

* Fix code style
2022-02-01 11:54:03 -05:00
Jordan Pittman
75ba4e0f8f
Fix preflight border color fallback (#7288) 2022-02-01 11:27:42 -05:00
Robin Malfait
39193c17e1
Quick fix for incorrect arbitrary properties when using URLs (#7252)
* quick fix for incorrect arbitrary properties

Turns out that using links like [https://example.com] causes arbitrary
properties to generate invalid css.
This is a very dirty quick fix for this specific case, so we have to fix
this properly!

* update changelog
2022-01-28 20:45:24 +01:00