148 Commits

Author SHA1 Message Date
Robin Malfait
ee3f3fd0be
Ensure comments in @layer rules don't crash (#5854)
* ensure comments in @layer rules don't crash

* update changelog
2021-10-22 15:19:21 +02:00
Robin Malfait
0ab39c312a
Allow _ inside url() when using arbitrary values (#5853)
* allow for underscores in url()

* update changelog
2021-10-22 14:43:46 +02:00
Robin Malfait
ea6f14a499
Dedupe duplicate properties (#5830)
* add `collapseDuplicateDeclarations`

This will allow us to remove duplicate declarations. This occurs when
you are using `@apply` for example.

The reason I implemented it as a separate step, is because this doesn't
only happen for `@apply`, but it also happens if you do something like:

```js
addComponents({ '.btn-blue, .btm-red': { padding: '10px' } })
```

So instead of tracking down every place this is happening, it now
happens at the very end.

* use new plugin in processTailwindFeatures

* add/update tests by removing duplicate declarations

* update changelog
2021-10-21 11:54:23 +02:00
Robin Malfait
0c2f1a6472
Remove prefix as a function (#5829)
* mark `prefix` as a function as a breaking change

* remove `prefix` as a function related code

* remove `prefix` as a function related tests

* update changelog
2021-10-19 15:22:49 +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
MichaelAllenWarner
8259dfdf48
Add text-decoration-color utilities (#5760)
* utilities and tests in place for textDecorationColor and textDecorationOpacity

* change 'backgroundColor' to 'textDecorationColor' in corePlugin declaration for latter

* remove explicit textDecorationOpacity utility (the JIT slash syntax suffices)

Co-authored-by: Michael Warner <michaelwarner@Michaels-MacBook-Pro.local>
2021-10-12 13:35:59 -04:00
Adam Wathan
d2b53cd3af
Add grow and shrink aliases (#5733)
This adds `grow-*` and `shrink-*` utilities as aliases for `flex-grow-*` and `flex-shrink-*` since those names are unnecessarily verbose. We will stop documenting the long form ones and consider them deprecated.

```diff
- <div class="flex-grow-0 flex-shrink">
+ <div class="grow-0 shrink">
```
2021-10-09 09:48:12 -04:00
Adam Wathan
97062c398b
Make negative values a first-class feature, rather than theme-driven (#5709)
* WIP

* Add failing test for negating default values

* Add dynamic negative value opt-in (#5713)

* Add `supportsNegativeValues` plugin option

* Update `getClassList` to support dynamic negative values

* Add test for using a negative scale value with a plugin that does not support dynamic negative values

* Support dynamic negation of `DEFAULT` values (#5718)

* Add test case

Co-authored-by: Brad Cornes <bradlc41@gmail.com>
2021-10-06 13:42:05 -04:00
Robin Malfait
b661614265
Enable optimize universal defaults by default (#5635)
* enabled `optimizeUniversalDefaults` by default

This PR is done in a way so that the default is set to `true`, but you
can still disable it if it causes issues. In this case we do appreciate
an issue in that case 😅.

* update tests to use optimized universal selector

* update integration tests

* add dedicated tests for the optimized universal selector

* improve minimumImpactSelector algorithm

I think I cracked the algorithm, but I will probably need another pair
of eyes on the subject.

The current implementation works like this:

Prerequisites:

- The selector should already have been parsed using the selectorParser
  from 'postcss-selector-parser'.

Algorithm:

1. Remove all of the pseudo classes from the list of nodes.
  1.1. We do want to keep pseudo elements (E.g.: `::before`, `::first-line`, ...)
  1.2. We do want to keep pseudo classes that contain nodes (E.g.:
    `:not(...)`)
2. Reverse the list of nodes.
  This will make it easier to search from the end to the start. For
  example `.group:hover .group-hover` should result in `.group-hover`
  not `.group`.
  2.1. Find the index of the best match (class, id, attribute), and
    convert the node if required. (E.g.: `span#app` -> `#app` => `[id="app"]`)
  2.2. Remove the rest of the selector that is not important anymore
  2.3. Re-join the left-over nodes together

* update tests using new algorithm

* also look for `tag` types

* take `tag` into account

* simplify logic

* add test to prove `rest.reverse()` in first case is required

In case we don't find a match (idx === -1), we use `rest.reverse()`.
However, it looks like you can just use `nodes` instead.
This is not entirely true, because the `rest` variable will contain only
the nodes that are not pseudo elements.

`*:hover` would result in `*:hover` instead of just `*`

* replace all nodes after > with a single universal selector
2021-10-06 17:45:26 +02:00
Adam Wathan
a2676b0544
Add flex-basis utilities (#5671) 2021-10-04 15:47:14 -04: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
Robin Malfait
d94541cbf3
Handle old to new config when normalizing the config (#5658)
* immediately take the `safelist` values into account

Currently we had to manually add them in the `setupTrackingContext`,
`setupWatchingContext` and the `cli`.

This was a bit cumbersome, because the `safelist` function (to resolve
regex patterns) was implemented on the context. This means that we had
to do something like this:

```js
let changedContent = []
let context = createContext(config, changedContent)
for (let content of context.safelist()) {
  changedContent.push(content)
}
```

This just feels wrong in general, so now it is handled internally for
you which means that we can't mess it up anymore in those 3 spots.

* drop the dot from the extension

Our transformers and extractors are implemented for `html` for example.
However the `path.extname()` returns `.html`.

This isn't an issue by default, but it could be for with custom
extractors / transformers.

* normalize the configuration

* make shared cache local per extractor

* ensure we always have an `extension`

Defaults to `html`

* splitup custom-extractors test

* update old config structure to new structure

* ensure we validate the "old" structure, and warn if invalid

* add tests with "old" config, to ensure it keeps working

* add missing `content` object

* inline unnecessary function abstraction
2021-10-01 12:56:54 +02:00
Brad Cornes
ba9d177891
Rename completions and remove color information (#5662) 2021-10-01 09:41:27 +01:00
Robin Malfait
11bfa0a9bd
Detect ambiguity in arbitrary values (#5634)
* detect ambiguity in arbitrary values

* update warning message
2021-09-30 12:39:41 +02:00
Jonathan Reinink
ca1dfd6313
Add border-x-{width}, border-y-{width}, border-x-{color} and border-y-{color} utilities (#5639)
Co-Authored-By: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-Authored-By: Davy <davy@prepr.io>
2021-09-29 10:32:31 -04:00
Jonathan Reinink
753d3f146c
Add scroll-snap utilities (#5637)
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Peter Jonsson <4572231+95jonpet@users.noreply.github.com>
Co-authored-by: Enzo Innocenzi <enzo@innocenzi.dev>
2021-09-29 09:57:26 -04:00
Brad Cornes
0b23d2e1d2
Fix using negated content globs (#5625)
* Fix negated content patterns

* Update changelog
2021-09-29 11:15:31 +01:00
Jonathan Reinink
8004917618
Add [open] variant (#5627)
* Add `[open]` variant

Co-Authored-By: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-Authored-By: Sean Doyle <2575027+seanpdoyle@users.noreply.github.com>

* Add new `applyStateToMarker()` function

This function replaces the existing `applyPseudoToMarker()` and `applyAttributeToMarker()` functions.

Co-Authored-By: Robin Malfait <1834413+RobinMalfait@users.noreply.github.com>

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Sean Doyle <2575027+seanpdoyle@users.noreply.github.com>
Co-authored-by: Robin Malfait <1834413+RobinMalfait@users.noreply.github.com>
2021-09-28 11:13:58 -04:00
Robin Malfait
5d6d84fda1
Ensure full node stays, if only a partial is used (#5617) 2021-09-28 11:54:39 +02:00
Adam Wathan
6c0b8e8f0f
Support arbitrary color with opacity modifier (#4723) 2021-09-26 11:45:13 -04:00
Adam Wathan
e602a3dca7
Add touch-action utilities (#5603)
Co-Authored-By: Mattèo Gauthier <matteo.gauthier@gmail.com>

Co-authored-by: Mattèo Gauthier <matteo.gauthier@gmail.com>
2021-09-26 09:41:36 -04:00
Robin Malfait
4cb1de0f01
ensure we don't override the name (#5602)
Keep track of unknown values (like css variables) in an unknown section.
Currently we only need to know the name, so this will be good enough for now.
2021-09-26 07:44:41 -04:00
Robin Malfait
c03f9ad600
Improve public API (#5526)
* introduce `public` folder

This can contain all of the `public` functions we want to expose.
This will be a bit nicer for example when you want to use
internal/private functions (we use some in the vscode intellisense
plugin).

* use public `resolveConfig` function

* expose resolveConfig in the root

This will use the resolveConfig we expose from the `public` folder. We
can probably generate these as well.

* make `colors` public

* make `default config` public

* make `default theme` public

* make `create plugin` public

* update to public paths

* remove `@tailwindcss/aspect-ratio` from tests

This should be tested in its own repo instead.

* remove `@tailwindcss/aspect-ratio` as a dependency

* drop `Build` step from CI

The build step is not a prerequisite anymore for running the tests. When
we want to release a new (insiders) release, the `prepublishOnly` step
will be executed for us.

Before this change, it would have been executed twice:
- Once before the tests
- Once before the actual release

* improve paths for caching purposes

* add pretest scrip for generating the plugin list

Now that we can use `SWC`, automatically generating the plugin list
before running the tests is super fast and you don't even have to think
about it anymore!
2021-09-26 12:44:13 +02:00
Robin Malfait
c3906b459b
Expose completions API (#5520) 2021-09-26 12:01:07 +02:00
Adam Wathan
ed61821e42
Properly optimize universal defaults for legacy pseudo-element syntax (#5594) 2021-09-24 14:27:42 -04:00
Robin Malfait
1ec5438448
Improve arbitrary value support (#5568)
* simplify `inset` plugin

* run `prettier` on stub file

* simplify `align` utility

* improve arbitrary support for outline

This will allow us to use `outline-[OUTLINE,OPTIONAL_OFFSET]`

Input:
```html
outline-[2px_solid_black]
```

Output:
```css
.outline-\[2px_solid_black\] {
  outline: 2px solid black;
  outline-offset: 0;
}
```

---

Input:
```html
outline-[2px_solid_black,2px]
```

Output:
```css
.outline-\[2px_solid_black\2c 2px\] {
  outline: 2px solid black;
  outline-offset: 2px;
}
```

* remove default `type`

* simplify createUtilityPlugin, use types directly

* find first matching type when coercing the value

* introduce css data types

Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types

These data types will be used to "guess" the type of an arbitrary value
if there is some ambiguity going on. For example:

```
bg-[#0088cc]      -> This is a `color`  -> `background-color`
bg-[url('...')]   -> This is a `url`    -> `background-image`
```

If you are using css variables, then there is no way of knowing which
type it is referring to, in that case you can be explicit:

```
bg-[color:var(--value)]   -> This is a `color`  -> `background-color`
bg-[url:var(--value)]     -> This is a `url`    -> `background-image`
```

When you explicitly pass a data type, then we bypass the type system and
assume you are right. This is nice in a way because now we don't have to
run all of the guessing type code. On the other hand, you can introduce
runtime issues that we are not able to detect:

```
:root {
  --value: 12px;
}

/* Later... */
bg-[color:var(--value)] -> Assumes `color` -> *eventually* -> `background-color: 12px`
```

* add a bunch of new tests for advanced arbitrary values
2021-09-24 18:45:42 +02:00
Robin Malfait
ab17c6c427
Handle unknown typehints (#5588)
If you use a typehint like `w-[length:12px]`, then currently that
wouldn't generate anything because we don't have a matchUtilities for
`w` with a `length` type. To fix this, we can detect if this is
unnecessary, if it is we still generate the expected outcome. (In this
case `width: 12px`) but we also warn to the user that we detected this.

Currently we detect this by checking if there is only a single plugin
registered for handling the prefix (e.g.: `w-`). We can probably improve
this by also checking all the types that all plugins are handling for
the resolved plugins.
2021-09-24 18:28:08 +02:00
Robin Malfait
79b37a874c
Ensure invalid typehints are not generated (#5590) 2021-09-24 18:18:48 +02:00
Robin Malfait
abcd9acd18
Support URL in arbitrary values (#5587)
* add url to resolveArbitraryValue list

* add `asURL` data type

* add `bg-[url('..')]` regex

* allow for `resolveArbitraryValue` to be an array

* prevent spaces around `-` when in a `url`

* add tests to verify `bg-[url('...')]` and `stroke-[url(...)]`
2021-09-24 16:13:16 +02:00
Robin Malfait
a4d1bdb7fa
Fix angle brackets in content (#5585)
* move to real regexes

These regexes are only calculated once so we don't really have a
performance penalty here. However, it's a bit nicer to do it this way
because now you don't have to think about the proper escapes.

/.*/.source will basically take the source of the regex ".*" without
flags and converts it to a string with the proper escapes for you.

Fun fact, this `.source` property has been supported since Chrome,
Firefox and Safari version 1.

* allow for `'>'` in `content-['>']`
2021-09-24 15:22:23 +02:00
Luke Warlow
f0ce096d8d
Add variant for ::file-selector-button pseudo element (#4936)
* Add variant for file-selector-button pseudo element

* Rename `file-selector-button` variant to `file`

Co-Authored-By: Adam Wathan <4323180+adamwathan@users.noreply.github.com>

Co-authored-by: Jonathan Reinink <jonathan@reinink.ca>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2021-09-23 15:43:37 -04:00
Robin Malfait
a8836eb093
Improve experimental universal selector improvements (#5517)
* add dedicated tests for the experimenal universal selector improvements

* Add failing test

* keep pseudo elements

* re-add logic for special types (class, id, attribute)

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2021-09-23 15:05:35 -04:00
Jonathan Reinink
744249d631
Add break-before, break-inside and break-after utilities (#5530)
* Add `break-before` utilities

* Add `break-inside` utilities

* Add `break-after` utilities

* Add `break-before/inside/after` utilities to basic usage test

* Remove `break-before` and `break-after` utilities that have no browser support

* Rename `break-inside: avoid-column` utility to `break-inside-avoid-column`
2021-09-23 14:31:23 -04:00
Adam Wathan
3d1118f5df Fix svelte test 2021-09-21 12:43:44 -04:00
Adam Wathan
b7d2c8f11e Add test for lit-html syntax 2021-09-21 12:41:58 -04:00
Adam Wathan
a44f58f913 Fix test extension 2021-09-21 12:41:00 -04:00
Adam Wathan
6121cbe22a Remove svelte CSS test file 2021-09-21 12:38:11 -04:00
Adam Wathan
2d9759b604 Rename svelte tests 2021-09-21 12:37:49 -04:00
Robin Malfait
6c0b7bc8b2
Pattern safelisting (#5511)
* splitup nameClass functionality

We want to separate the logic of the formatting the class and of turning
it into a class with a `.` and escaped values.

* collect base classList

* implement `safelist` where you can use regex patterns
2021-09-16 14:47:41 +02:00
Robin Malfait
14d49a9fd5
Warn when nesting is detected (#5489)
* warn when nesting is detected

* add todo for improving warning messages
2021-09-16 14:13:45 +02:00
Adam Wathan
16a910b0f5 Add arbitrary value support for vertical-align utilities 2021-09-12 16:39:11 -04:00
Adam Wathan
fda68f7138
Add border-hidden utility (#5485)
Co-Authored-By: 藍 <50108258+kwaa@users.noreply.github.com>

Co-authored-by: 藍 <50108258+kwaa@users.noreply.github.com>
2021-09-12 16:18:17 -04:00
Adam Wathan
b16eb2034e
Add arbitrary value support for transition-property (#5481)
Co-Authored-By: Eric F. <2483476+ericbf@users.noreply.github.com>

Co-authored-by: Eric F. <2483476+ericbf@users.noreply.github.com>
2021-09-12 10:07:57 -04:00
Luke Warlow
3b81c5329b
Add scroll-behavior utilities (#5388) 2021-09-11 09:13:28 -04:00
Adam Wathan
b0cf6eded3
Support using functions as colors when disabling color opacity utilities (#5470) 2021-09-10 09:35:15 -04:00
Robin Malfait
50b766dd47
Remove variants related code (#5465)
* drop `variants` related resolveConfig functionality

More AOT code that we could get rid of!

* drop more files!

I keep finding these unused files 😅

* Update setupContextUtils.js

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2021-09-10 09:34:27 -04:00
Robin Malfait
9daebe43b9
Replace underscore with space in arbitrary values (#5460)
* refactor dropShadow plugin, use `matchUtilities`

* replace `_` with ` ` for arbitrary values

* remove custom `asList` function

* do not replace escaped underscores with spaces
2021-09-09 18:10:04 +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