224 Commits

Author SHA1 Message Date
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
Robin Malfait
1868eb6177
Fix @apply order regression (in addComponents, addUtilities, ...) (#7232)
* ensure to partition `@apply` rules generated by addComponents, addUtilities, ...

* update changelog
2022-01-27 13:16:44 +01:00
Robin Malfait
167668e9cf
Ensure to transpile the PostCSS Nesting plugin (tailwindcss/nesting) (#7080)
* ensure that we compile the postcss nesting plugin

* re-add optional chaining

This will allow us to be 100% sure that we can safely call
hasOwnProperty in case we get some very strange objects.

This will now also be compiled/transpiled by esbuild.

* import the internal postcss nesting plugin

This allows us to work on it without re-compiling while running tests.
Just like we do with all other code.

* update changelog
2022-01-15 16:07:20 +01:00
Jordan Pittman
e2928883e8
Only emit utility/component variants when those layers exist (#7066) 2022-01-14 10:20:43 -05:00
Lubomír Blažek
8293c2d33d
Ensure nesting plugins can receive options (#7016)
* fix: options for nesting / nested plugins

* add tests to ensure passing options to postcss plugin works

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-01-14 16:20:06 +01:00
Jordan Pittman
bef3838552
Show warnings for invalid content config (#7065) 2022-01-14 09:47:39 -05:00
Jordan Pittman
b5b387233f Test apply partitioning and media queries
This has already been fixed due to another change but wanted to add an explicit test for it
2022-01-10 12:45:34 -05:00
Jordan Pittman
a891867a2f
Fix consecutive builds with at apply producing different CSS (#6999)
* Partition at rules before building context

* remove unnecessary logic

* Update changelog

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-01-10 12:36:14 -05:00
Jordan Pittman
f2d73b8c3d
Change how we handle defaults (optimized or not) (#6926)
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2022-01-07 11:39:45 -05:00
Robin Malfait
fe08e919dc
Ensure @apply works consistently with or without @layer (#6938)
* partition nodes as soon as possible

Time to write another story on `@apply`...

When we write code like this:

```css
.a {
  @apply b;
}

.b {
  @apply uppercase;
  color: red;
}
```

Then we create 2 Nodes in our context to keep track of. One has
identifier `a`, the other has identifier `b`. However, when we have an
`@apply` and it contains multiple declarations/atrules, then we have to
split up the (aka partition) node into multiple nodes so that we can
guarantee the correct expected sort order.

This means that the above example technically looks like this:

```css
.a {
  @apply b;
}

.b {
  @apply uppercase;
}

.b {
  color: red;
}
```

If this was your input, then we would still have 1 node for identifier
'a', but we would have 2 nodes for identifier 'b'.

As mentioned earlier, this is important to guarantee the correct order,
here is an example:

```css
.b {
  @apply md:font-bold xl:font-normal; /* Here we can sort by our
  internal rules. This means that the `md` comes before `xl`. */
}
```

... however

```css
.b {
  @apply xl:font-normal; /* This now exists _before_ the example below */
}

.b {
  @apply md:font-bold; /* Because we respect the order of the user's css */
}
```

So to guarantee the order when doing this:
```css
.b {
  @apply xl:font-normal;
  @apply lg:font-normal;
}
```

We also split this up into 2 nodes like this:
```css
.b {
  @apply xl:font-normal;
}
.b {
  @apply lg:font-normal;
}
```

The tricky part is that now only 1 empty `.b` node exists in our context
because we partitioned the orginal node into multiple nodes and moved
the children to the new nodes and because they are new nodes it means
that they have a different identity.

This partitioning used to happen in the expandApplyAtRules code, but
this is a bit too late because the context has already been filled at
this time. Instead, we move the code more to the front, as if you wrote
those separated blocks yourself. Now the code to inject those nodes into
the context happens in a single spot instead of multiple places.

Another good part about this is that we have better consistency between
each layer because it turns out that these two examples generated
different results...

```css
.a {
  @apply b;
}
.b {
  @apply uppercase;
  color: red;
}
```

... is different compared to:

```css
@tailwind components;
@layer components {
  .a {
    @apply b;
  }
  .b {
    @apply uppercase;
    color: red;
  }
}
```

Even if both `a` and `b` are being used in one of your content paths...
Yeah.. *sigh*

* add more `@apply` related tests

* update changelog

* remove support for basic nesting (leftover)

* remove leftover todo

This has been fixed already
2022-01-07 16:41:01 +01:00
Robin Malfait
21fe083db0
Ensure we can apply classes defined with non-"on-demandable" selectors (#6922)
* improve extractCandidates

When we have a css rule that is defined as `.foo, .bar {}`, then we will
crawl each selector and link it to the same node. This is useful because
now our Map looks something like this:

```js
Map(2) { 'foo' => Node {}, 'bar' => Node {} }
```

This allows us to later on `@apply foo` or `@apply bar` and we can do a
direct lookup for this "candidate".

When we have css defined as `span {}`, then we consider this
"non-ondemandable". This means that we will _always_ inject these rules
into the `*` section and call it a day.

However, it could happen that you have something like this: `span, .foo
{}` up until now this was totally fine. It contains a non-ondemandable
selector (`span`) and therefore we injected this into that `*` section.

However, the issue occurs if you now try to `@apply foo`. Since we had
an early return for this use case it didn't endup in our Map from above
and now you get an error like:

```
The `foo` class does not exist. If `foo` is a custom class, make sure it
is defined within a `@layer` directive."
```

So instead what we will do is keep track whether or not a css rule
contains any on-demandable classes. If this is the case then we still
generate it always by putting it in that `*` section. However, we will
still register all on-demandable classes in our Map (in this case `.foo`).

This allows us to `@apply foo` again!

* update changelog
2022-01-06 13:27:14 +01:00
Jordan Pittman
82f163d425
Fix use of falsy values in theme config (#6917) 2022-01-05 16:37:07 -05:00
Jordan Pittman
9fdc391d4f Revert apply defaults in isolation 2022-01-05 08:36:30 -05:00
Jordan Pittman
78fb761d75
Preserve case of css variables added by plugins (#6888) 2022-01-04 23:03:41 -05:00
Jordan Pittman
058a9256ae
Emit defaults from apply in css modules (#6875)
* Emit defaults from apply in css modules

* Update changelog
2022-01-04 11:29:33 -05:00
Gary Mathews
722232cb2e
Allow all classes for @apply (#6580)
* Always include css with apply in context

* Use let

We use it more consistently

* Remove early return

To match the style of the surrounding code

* Don't return layer directives

They do not need to be returned here. If it's needed in the future its easy enough to add it back.

* Use let

* Update changelog

* fix typo

And re-format comments

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-01-04 14:23:10 +01:00
Robin Malfait
b9af5a916b
Improve collapsing of duplicate declarations (#6856)
* improve collapsing of duplicate properties

In theory, we don't have to do anything because the browser is smart
enough to figure everything out. However, leaving in duplicate
properties is not that ideal for file size.

Our previous method was pretty simple: if you see a declaration you
already saw in this rule, delete the previous one and keep the current
one.

This works pretty well, but this gets rid of **all** the declarations
with the same property. This is not great for overrides for older
browsers.

In a perfect world, we can handle this based on your target browser but
this is a lot of unnecessary complexity and will slow things down
performance wise.

Alternative, we improved the solution by being a bit smarter:
1. Delete duplicate declarations that have the same property and value
   (this will get rid of **exact** duplications).
2. Delete declarations with the same property and the same **unit**.

This means that we will reduce this:
```css
.example {
  height: 50%;
  height: 100px;
  height: 20vh;
  height: 30%;
  height: 50px;
  height: 30vh;
  transform: var(--value);
  transform: var(--value);
}
```

To:
```diff-css
  .example {
-   height: 50%;    /* Another height exists later with a `%` unit */
-   height: 100px;  /* Another height exists later with a `px` unit */
-   height: 20vh;   /* Another height exists later with a `vh` unit */
    height: 30%;
    height: 50px;
    height: 30vh;
-   transform: var(--value); /* Value is too complex, but is **exactly** the same as the one below */
    transform: var(--value);
  }
```

This will reduce the values that we are 100% sure that can be safely
removed. This will still result in some overrides but the browser can
handle those for you.

Fixes: #6844

* update changelog
2022-01-03 15:41:49 +01:00
Robin Malfait
3149738035
Properly detect theme() value usage in arbitrary properties (#6854)
* properly detect theme value in arbitrary properties

* update changelog
2022-01-03 13:12:43 +01:00
Robin Malfait
c912434e0b
Validate theme() works in arbitray values (#6852)
* add tests to ensure theme value inside arbitrary values work

* update changelog
2022-01-03 11:29:18 +01: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
875c850b37
Improve DEBUG parsing: only take care of tailwindcss and not tailwind (#6804)
* only take care of `tailwindcss` and not `tailwind`

* update changelog
2021-12-30 16:41:23 +01:00
Robin Malfait
10710b08b9
Improve DEBUG flag (#6797)
* improve DEBUG flag

* update changelog
2021-12-29 23:51:30 +01:00
Adam Wathan
1d5aa27e79
Support HSL with hue units in arbitrary values (#6726) 2021-12-24 13:20:35 -05:00
Adam Wathan
da7396cf77 Sketching out more specific tests for our default extractor 2021-12-24 12:56:53 -05:00
Robin Malfait
86e73b2063
Ensure @apply of a rule inside an AtRule works (#6594)
* ensure apply of rule inside atrule works

If that atrule happens to contain another rule that is technically
unrelated.

Co-authored-by: Jordan Pittman <jordan@cryptica.me>

* update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2021-12-17 18:40:20 +01:00
Robin Malfait
9e03a6800b
Improve jsx interpolation candidate matching (#6593)
* ensure that strangely used jsx with interpolation gets detected

Co-authored-by: Luke Warlow <projects@warlow.dev>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>

* update changelog

Co-authored-by: Luke Warlow <projects@warlow.dev>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2021-12-17 17:32:50 +01:00
Jordan Pittman
27c67fef43
Properly extract classes with arbitrary values in arrays and classes followed by escaped quotes (#6590)
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2021-12-17 10:15:36 -05: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
Robin Malfait
7089a80ea1
Improve circular dependency detection when using @apply (#6588)
* improve circular dependency detection when using `@apply`

I also changed the message to the same message we used in V2.

* update changelog
2021-12-17 13:39:32 +01:00
Jordan Pittman
6cf3e3e55f
Don't mutate custom color palette when overriding per-plugin colors (#6546) 2021-12-16 16:19:54 -05:00
Jonathan Reinink
ec911c73f0 Improve order of color properties in transition and transition-colors utilities 2021-12-15 14:09:27 -05:00
Jonathan Reinink
1c7a793c94 Update order of color properties in transition and transition-colors utilities 2021-12-15 13:49:13 -05:00
Felix Klein
9934174867
Add 'text-decoration-color' to default 'transition' and 'transition-colors' utilities (#6405)
* Add 'text-decoration-color' to default 'transition' and 'transition-colors' utilities

* Add 'text-decoration-color' to default 'transition' and 'transition-colors' utilities

* Delete tailwind-output-flagged.css

* Delete tailwind-output-important.css

* Delete tailwind-output-no-color-opacity.css

* Delete tailwind-output.css

Co-authored-by: Jonathan Reinink <jonathan@reinink.ca>
2021-12-15 13:44:51 -05:00
Robin Malfait
0783a4275e
remove unused fixture files 2021-12-15 18:13:09 +01:00
Robin Malfait
deb68d5816
Ensure all plugins are executed for a given candidate (#6540)
* remove early return so that all plugins are handled

We had an early return so that once a plugin was matched, that we could
stop running the code through the other plugins. However, in this case
we have an issue that user defined css is technically also a plugin.

This means that:
  - `bg-green-light`
Would check for:
  - `bg-green-light` (no hit, continue)
  - `bg-green` (Hit! Don't execute next plugins)
  - `bg` (This is the one that would have generated `bg-green-light`)

We tested this change and it doesn't seem to have an impact functionally
and also not really performance wise.

* update changelog
2021-12-15 18:07:26 +01:00
Jordan Pittman
08a07f6e02
Support square bracket notation in paths (#6519) 2021-12-15 11:09:29 -05:00
Robin Malfait
083bca3d3f
Insert always on defaults layer in correct spot (#6526)
* insert in correct spot

We were injecting the always on `@tailwind defaults` layer at the beginning of
the file. However, if a `@tailwind base` layer is available, then that
will now be injected _after_ the defaults layer. The base layer does
contain some reset that are now overriding the defaults we set.

So now we will:
- Insert the `@tailwind defaults` layer at the beginning of the file
  _if_ there is no `@tailwind base`
- Insert the `@tailwind defaults` layer after the `@tailwind base` layer
  if it exists.

* update changelog
2021-12-15 12:34:53 +01:00
Simon J
a7263a8f6f
Add support for negative values in safelist patterns (#6480)
Co-authored-by: Simon Jarrett <simon.jarrett@churchmissionsociety.org>
2021-12-14 15:55:26 -05:00
Jordan Pittman
4041d04b89
Move defaults to their own always-on layer (#6500)
Default's declarations are now processed and merged even when there is no tailwind base directive included in the stylesheet. Without this applying tailwind utilities in css modules would break if they relied on defaults rules.

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2021-12-14 12:21:38 -05: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
Jordan Pittman
399440eef1
Don't output unparsable values (#6469) 2021-12-13 12:39:17 -05:00
Robin Malfait
4b2482ff35
Warn about invalid globs in content (#6449)
* rewrite invalid globs if we can

* warn instead of rewrite

* update changelog
2021-12-13 16:00:31 +01:00
Jordan Pittman
429fe07a5f
Fix defaults optimization when vendor prefixes are involved (#6369) 2021-12-10 10:45:33 -05:00
Robin Malfait
08241c3f75
Detect circular dependencies when using @apply (#6365)
* detect circular dependencies when using `@apply`

* update changelog

* ensure we split by the separator
2021-12-10 16:08:45 +01:00