335 Commits

Author SHA1 Message Date
Robin Malfait
727de668fd
Improve type checking for formal syntax (#9448)
* Improve type checking for formal syntax

* Add test

* Change order of test class name

* fix failing tests

* prefer `position` over `size` for backwards compatibility reasons

Previously `bg-[10px_10%]` generated `background-position: 10px 10%` before we introduced the fallback plugins.
Therefore we should prefer `position` over `size` as the default for backwards compatibility.

* update changelog

* ensure correct order

Thanks Prettier!

* update changelog

Co-authored-by: lzt1008 <lzt1008@live.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: liangzhengtai <liangzhengtai_i@didiglobal.com>
2022-09-29 18:24:51 +02:00
Robin Malfait
94d6e7299a
Implement fallback plugins when arbitrary values result in css from multiple plugins (#9376)
* use test with non-any type plugin

* choose backgroundSize over backgroundPosition

Ensure that `backgroundColor` can take any value

* add tests to verify fallback plugins

* implement fallback plugins

Whenever an arbitrary value results in css from multiple plugins we
first try to resolve a falback plugin.

The fallback mechanism works like this:

- If A has type `any` and B has type `color`, then B should win.

  > This is because `A` will match *anything*, but the more precise type
    should win instead. E.g.: `backgroundColor` has the type `any` so
    `bg-[100px_200px]` would match both the `backgroundColor` and
    `backgroundSize` but `backgroundSize` matched because of a specific
    type and not because of the `any` type.
- If A has type `length` and B has type `[length, { disambiguate: true }]`, then B should win.
  > This is because `B` marked the `length` as the plugin that should
    win in case a clash happens.

* Add any type to a handful of plugins

Needs tests tho

* Add any type to `border-{x,y,t,r,b,l}` plugins

* Add test for any type

* Split on multiple lines

* fixup

* add tests for implicit `any` types

* rename `disambiguate` to `preferOnConflict`

* update tests to reflect `any` types a bit better

* update changelog

* annotate any-type test with a bit more information

Just for future debugging reasons!

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-09-29 17:26:27 +02:00
Robin Malfait
26cab53c15
Support sort function in matchVariant (#9423)
* support `sort` function in `matchVariant`

This will ensure that we can sort arbitrary variant values (and
hardcoded values) to ensure the order.

* update changelog
2022-09-26 13:08:12 -04:00
Jordan Pittman
bf44941049
Allow resolving content paths relative to the config file (#9396)
* Update lockfile

* Tweak formatting

* Refactor content path parsing

* Allow resolving content paths relative to the config file

* Include resolved symlinks as additional content paths

* Update changelog

* Work on suite of tests for content resolution

* reformat integration test list

* Move content resolution tests to integration

* Update future and experimental types
2022-09-23 08:09:02 -04:00
Robin Malfait
e62525226e
Ignore unset values (like null or undefined) when resolving the classList for intellisense (#9385)
* ignored `undefined` and `null` value values for intellisense

We are not completely ignoring "all" falsey values, because then we
would get rid of `0` values (e.g.: `p-0`) which is not what we want.

* update changelog
2022-09-21 14:31:08 +02:00
Robin Malfait
4fddd2d611
Polish matchVariant API (#9313)
* convert the `matchVariant` to look more like `addVariant`

With the biggest difference that the `matchVariant` will have a callback
function that receives the current value of the variant.

* use object as argument for `matchVariant` callback

This will allow us to add more properties in the future if needed
without breaking changes.

- This is a breaking change: `(value) => ...` -> `({ value, other }) => ...`
- This is **not** a breaking change: `({ value }) => ...` -> `({ value, other }) => ...`

* add types for `matchVariant`
2022-09-16 15:37:35 +02:00
Jordan Pittman
8fe6f4868e
Don't emit utilities containing invalid theme fn keys (#9319)
* Don't emit utilities containing invalid theme keys

* Update changelog
2022-09-14 13:27:01 -04:00
Robin Malfait
527031d5f6
Improve data type analyses for arbitrary values (#9320)
* improve split logic by delimiter

The original RegEx did mostly what we want, the idea is that we wanted
to split by a `,` but one that was not within `()`. This is useful when
you define multiple background colors for example:
```html
<div class="bg-[rgb(0,0,0),rgb(255,255,255)]"></div>
```

In this case splitting by the regex would result in the proper result:
```js
let result = [
  'rgb(0,0,0)',
  'rgb(255,255,255)'
]
```

Visually, you can think of it like:
```
    ┌─[./example.html]
    │
∙ 1 │   <div class="bg-[rgb(0,0,0),rgb(255,255,255)]"></div>
    ·                       ──┬── ┬    ─────┬─────
    ·                         │   │         ╰─────── Guarded by parens
    ·                         │   ╰───────────────── We will split here
    ·                         ╰───────────────────── Guarded by parens
    │
    └─
```

We properly split by `,` not inside a `()`. However, this RegEx fails
the moment you have deeply nested RegEx values.

Visually, this is what's happening:
```
    ┌─[./example.html]
    │
∙ 1 │   <div class="bg-[rgba(0,0,0,var(--alpha))]"></div>
    ·                         ┬ ┬ ┬
    ·                         ╰─┴─┴── We accidentally split here
    │
    └─
```
This is because on the right of the `,`, the first paren is an opening
paren `(` instead of a closing one `)`.

I'm not 100% sure how we can improve the RegEx to handle that case as
well, instead I wrote a small `splitBy` function that allows you to
split the string by a character (just like you could do before) but
ignores the ones inside the given exceptions. This keeps track of a
stack to know whether we are within parens or not.

Visually, the fix looks like this:
```
    ┌─[./example.html]
    │
∙ 1 │   <div class="bg-[rgba(0,0,0,var(--alpha)),rgb(255,255,255,var(--alpha))]"></div>
    ·                         ┬ ┬ ┬             ┬       ┬   ┬   ┬
    ·                         │ │ │             │       ╰───┴───┴── Guarded by parens
    ·                         │ │ │             ╰────────────────── We will split here
    ·                         ╰─┴─┴──────────────────────────────── Guarded by parens
    │
    └─
```

* use already existing `splitAtTopLevelOnly` function

* add faster implemetation for `splitAtTopLevelOnly`

However, the faster version can't handle separators with multiple
characters right now. So instead of using buggy code or only using the
"slower" code, we've added a fast path where we use the faster code
wherever we can.

* use `splitAtTopLevelOnly` directly

* make split go brrrrrrr

* update changelog

* remove unncessary array.from call

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-09-14 14:08:56 +02:00
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
Brandon McConnell
cc1be47a4f
Add support for visibility: collapse with new collapsed utility (#9181)
* Add support for `visibility: collapse` with new `collapsed` utility

* fixup

* Update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-09-09 13:19:24 -04:00
Jordan Pittman
d6bec49934
Fix parallel variant ordering clash (#9282)
* Remove remnants of the user layer

It hasn’t been used in a while

* Rewrite sort offset generation

* wip

* wip

wip

* Handle parasite utilities

* wip

* wip

* Make parallel variants sorting more resillient

It’s not perfect but it’s close

* fix

* remove todo

it adds a new bit so it can’t

* Simplify getClassOrder usage

* Simplify

oops

oops

* Add parasite utility for `dark`

dark mode class name

* Cleanup

* Cleanup

* Simplify

* format files

* Fix prettier plugin to use git build of Tailwind CSS

Symlink and build instead of adding a recursive dev dependency

It breaks node < 16

* Fix prettier error

* wip

* fix test

* Update changelog

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-09-09 13:12:43 -04:00
Remco Haszing
88e98f557c
Fix issue with Tailwind modifying global state (#9294)
* Fix issue with Tailwind modifying global state

When running Tailwind, it modifies the plugin defaults parameters. As a
result Tailwind using a Tailwind plugin in the same process twice yields
different results.

* Add failing test

* Undo defaults change

* wip

* Fix shared mutation problem

* Update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-09-09 11:45:25 -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
17b81b4150
Allow negating utilities using min/max/clamp (#9237)
* Allow negating utilities using min/max/clamp

* Update changelog
2022-09-01 12:15:23 -04:00
Brad Cornes
edf47a012d
Fix theme(fontFamily.*) when family contains fontFeatureSettings config (#9217) 2022-08-30 17:18:41 +01:00
Jordan Pittman
58cc7ed3e8
Re-use existing entries in the rule cache (#9208)
* Add test

* Reuse rule cache entries when possible

* Update changelog
2022-08-29 14:13:32 -04:00
Jordan Pittman
7f93550e63
Honor the hidden attribute on elements in preflight (#9174)
* Honor the `hidden` attribute on elements

You’ll still be able to override this with utilities but this ensures that things like `<iframe hidden>` work as expected

* Update changelog
2022-08-24 17:05:44 -04:00
Justin Wong
9d495b9ed0
Implement negative outline offsets (#9136)
* Implement negative outline offsets

* Update changelog
2022-08-19 06:32:18 -04:00
Jordan Pittman
7924e7b40c Don’t replace all instances of the same class
This isn’t 100% correct either so we’re backing out this change
2022-08-15 16:05:47 -04:00
Jordan Pittman
ef74fd3db6
Fix @apply selector rewriting when multiple classes are involved (#9107)
* Rewrite `replaceSelector` using `postcss-selector-parser`

* Sort classes between tags and pseudos when rewriting selectors

* Update changelog
2022-08-15 14:43:41 -04:00
Jordan Pittman
b0018e20bf
Add future flag to disable color opacity utility plugins (#9088)
* Add future flag to disable opacity utility plugins

This will become the default in Tailwind CSS v4.0

* Update changelog
2022-08-15 13:45:02 -04:00
Jordan Pittman
2882d4c9ee
Fix ring color utility generation when using respectDefaultRingColorOpacity (#9070)
* Correct ring color list when using `respectDefaultRingColorOpacity`

* Update changelog
2022-08-10 10:36:04 -04:00
Adam Wathan
c7f627dd68
Add support for configuring default font-feature-settings for a font-family (#9039)
* Add support for configuring default font-feature-settings for a font-family

* Update changelog

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2022-08-08 15:02:08 -04:00
Jordan Pittman
0a3aad9511 Revert "Don't use cursor: pointer for buttons by default (#8962)"
We’re undecided on whether or not this should be released right now so we’ll revert it and revisit it later.
2022-08-05 10:05:46 -04:00
Jordan Pittman
20456efae4
Fix @apply of user utilities when negative and non-negative versions both exist (#9027)
* Fix application of rules with multiple matches of differing selectors

`-foo-1` and `foo-1` are both matches for the class `-foo-1` but `@apply` only wants the first one. It would remove the second one and cause an error because it’s an entirely separate match that had it’s only rule removed.

* Update changelog
2022-08-04 14:24:17 -04:00
Jordan Pittman
89b960d771
Fix resolution of alpha values inside color functions (#9008)
* Fix resolution of alpha values inside color functions

* Update changelog
2022-08-02 11:13:04 -04:00
Justin Wong
0b5bfc8065
Remove class prefix in arbitrary variant that is used multiple times (#8992)
* Remove prefix in multi-used arbitrary variant

* Update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-07-31 18:20:43 -04:00
Jordan Pittman
262079e1e5 Revert "Revert "Don't use cursor: pointer for buttons by default (#8962)""
This reverts commit e1aafc5df5e33e4fa69e4923ada23e683296dc14.
2022-07-29 17:03:38 -04:00
Jordan Pittman
e1aafc5df5 Revert "Don't use cursor: pointer for buttons by default (#8962)"
This reverts commit ed3a4f3032b486d8d328089011def785d6572462.
2022-07-29 11:03:28 -04:00
Jordan Pittman
a1346c9a8e
Don't rewrite source maps for @layer rules (#8971)
* Cleanup

* Don’t rewrite source maps for `@layer` rules

* Update changelog
2022-07-27 12:19:08 -04:00
Adam Wathan
ed3a4f3032
Don't use cursor: pointer for buttons by default (#8962)
* Don't use `cursor: pointer` for buttons by default

This is a pretty common expectation but as outlined in in #8961 isn't really right. We considered this a long time ago but it felt too against the grain at the time. These days though very UI-forward applications like [Linear](https://linear.app/) are using the default cursor for buttons and I think this trend will continue as more people become aware that `cursor: pointer` is meant for links.

Let's update our defaults here to help nudge people in this direction and make it more common. If people want to change this in their own apps, it's just a line or two of CSS to add to their projects.

* Update changelog

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2022-07-26 20:55:09 -04:00
Adam Wathan
268ef00696 Use safelist 2022-07-18 09:31:45 -04:00
Jordan Pittman
deefbf5aaf
Handle theme keys with slashes when using theme() in CSS (#8831)
* Fix lookup of `theme(…)` paths with slashes in them

* Update changelog
2022-07-11 10:47:17 -04:00
Tmk
6729524185 Support font-weight in font-size utilities (#8763)
* Support font-weight in font-size utilities

* WIP update tests

* Update changelog

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-07-04 17:01:06 -04:00
Jordan Pittman
102977530e
Add support for alpha values in safelist (#8774)
Co-authored-by: Petr Novak <petr.nmn.novak@gmail.com>
2022-07-04 16:37:38 -04:00
Jordan Pittman
8494f7515d
Don’t prefix selectors in arbitrary variants (#8773)
* Don’t prefix selectors in arbitrary variants

* Update changelog
2022-07-04 14:52:24 -04:00
Jordan Pittman
5191ec1c00
Fix usage of special-character prefixes (#8772)
* Fix import

* Support arbitrary prefixes

* Add test

* Update changelog
2022-07-04 14:42:27 -04:00
Jordan Pittman
00af2e8947
Don’t add spaces around raw / that are preceded by numbers (#8688)
* Don’t add spaces around raw `/` that are preceded by numbers

* Update changelog
2022-06-20 10:49:55 -04:00
Jordan Pittman
c5e7857362
Detect arbitrary variants with quotes (#8687)
* Refactor

* Support variants with quotes in them

We have to have two regexes here because this is actually ambiguous in the general case. The regex that generally handles `[&[foo='bar']]` would incorrectly match `['bar':'baz']` for instance. So, instead we’ll use multiple regexes and match both!

* Update changelog
2022-06-20 09:56:40 -04:00
Jordan Pittman
9778b528dc
Provide default to <alpha-value> when using theme() (#8652)
* Ensure default alpha is 1.0 when using new `<alpha-value>` format with the theme function

* Update changelog
2022-06-15 15:11:08 -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
Adam Wathan
22eaad17c3
Fix "Maximum call stack size exceeded" bug (#8636)
* Fix potential call stack size issue

* Update defaultExtractor.js

* add test to verify "Maximum call stack size exceeded" is fixed

* update changelog

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-06-14 14:17:40 +02:00
Jordan Pittman
1c24d7a473
Detect alpha value in CSS theme() function when using quotes (#8625)
* Allow alpha value inside quotes

* Optimize regex

* Add test

* Update changelog
2022-06-13 15:32:52 -04:00
Dany Castillo
aad299cf90
Fix missing spaces around arithmetic operators (#8615)
* add tests for spaced around operators in CSS math functions

* fix CSS math functons besides calc not getting the love they deserve

* improve comment

* update changelog

* update changelog

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-06-13 11:58:07 +02: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
Jordan Pittman
a9c7e52a59
Fix extraction of multi-word utilities with arbitrary values and quotes (#8604)
* Fix extraction of multi-word utilityies with arbitrary values and quotes

* Update  changelog

* Fix changelog entry

This wasn’t in 3.1.2 oops
2022-06-12 10:10:10 -04:00
Robin Malfait
d32728b433
Ensure \ is a valid arbitrary variant token (#8576)
* `\` are valid arbitrary variant tokens

We use `\` for escaping `.` or `_` so they should be part of the
arbitrary variant regex.

* update changelog
2022-06-10 10:51:16 +02:00
Jordan Pittman
0664aae901
Fix class detection in markdown code fences and slim templates (#8569)
* Fix detection of classes in markdown code fences

* Fix candidate detection in `.slim` templates

* Update changelog
2022-06-09 16:53:02 -04:00
Jordan Pittman
6b1eb19079
Split ::backdrop into separate defaults group (#8567)
* Split `::backdrop` into separate defaults group

* Update tests

* Update changelog
2022-06-09 16:26:18 -04:00
Jordan Pittman
7aa2d4ddf3
Don’t clip slashes inside brackets when using the theme function (#8563) 2022-06-09 14:09:57 -04:00