5392 Commits

Author SHA1 Message Date
Philipp Spiess
e920442e49
Prefix internal modules with internal-* (#14074)
Last week we discussed bringing in some consistency for our non-public
npm packages in the repo. We discussed using custom namespaces (e.g.
`@tailwindcss-internal`) vs. simple prefixes but it does not matter too
much if we are both consistent with our pattern and it's easy for us to
see whether a plugin is public or not.

Since we have a mixture of public namespaced (`@tailwindcss/*`) and
non-namespaced (`tailwindcss`) packages, I think it would be best if we
use a prefix to signal internal dependencies. This PR proposes we use
`internal-*` as the prefix and renames `test-utils` to
`internal-example-plugin` (since, really, this package is just an
example for the Tailwind plugin system).
2024-07-29 10:58:07 -04:00
Philipp Spiess
a2159e80f5
Add Windows CI (#14065)
This PR changes the GitHub action workflow for V4 to start running all
unit tests and build on both Ubuntu (our current default) _and_ Windows.
This is to ensure we catch issues with paths and other Windows-specific
things sooner. It does, however, not replace testing on Windows.
2024-07-29 16:50:06 +02:00
Alexander Kachkaev
87c9f32cbc
Remove cursor override for :disabled buttons (#14061)
Related to https://github.com/tailwindlabs/tailwindcss/issues/8961 and
https://github.com/tailwindlabs/tailwindcss/pull/8962

Before v4, buttons got this CSS in preflight:


9824cb64a0/src/css/preflight.css (L339-L353)

v4 (`next` branch) no longer has `cursor: pointer` in
[preflight.css](2fe2499635/packages/tailwindcss/preflight.css)

This PR removes additional CSS for `:disabled` buttons. It was meant to
undo an override that is no longer present.
2024-07-29 10:10:15 -04:00
Alexander Kachkaev
0b7163c727
Specify pnpm version for corepack users (#14066) 2024-07-29 10:06:59 -04:00
Robin Malfait
2fe2499635
Fix failing publish step (#14060)
One of the (private) packages was missing a version which caused `pnpm
publish` to fail. This PR adds the missing version.
2024-07-25 17:31:52 +02:00
Adam Wathan
50a6a37dc9
Prepare for v4.0.0-alpha.18 release (#14057)
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-07-25 10:19:13 -04:00
Adam Wathan
8eca436b3c
Reduce specificity of * variant (#14056)
This PR reduces the specificity of the * variant so that classes
directly on the child elements take precedence over the styles applied
by the parent.

Previously a utility like `*:flex` would generate this CSS:

```css
.\*\:flex > * {
  display: flex;
}
```

This selector has a specificity of `0,1,0`, which is the same as the
specificity for a bare utility class like `flex`, `block`, or `grid`.

Because variants always appear later in the CSS file than bare
utilities, this means that given this HTML, the `grid` class on the
child element would have no effect:

```html
<div class="*:flex">
  <div>...</div>
  <div class="grid">...</div>
  <div>...</div>
</div>
```

After this PR, the `*:flex` utility generates this CSS instead:

```css
:where(.\*\:flex > *) {
  display: flex;
}
```

This selector has a specificity of `0,0,0`, so even though it appears
later in the CSS, a bare utility with a specificity of `0,1,0` will
still take precedence.

This is something we wanted to do when we first introduced the `*`
variant in the v3 series, but couldn't because having such a low
specificity meant that styles in Preflight would take precedence over
utilities like `*:flex`, which is not would anyone would want.

We can make this change for v4 because now all of Preflight is wrapped
in a dedicated `@layer`, and rules from later layers always take
precedence over rules from earlier layers even if the rule in the later
layer has a lower specificity.

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-07-25 10:09:47 -04:00
Adam Wathan
f4bb9a8df3 Tweak changelog entry 2024-07-25 10:03:29 -04:00
Philipp Spiess
d7ec082519
Update CHANGELOG.md 2024-07-25 10:14:22 +02:00
Jordan Pittman
f0e9343b5b
Add support for defining simple custom utilities in CSS via @utility (#14044)
This PR allows you to add custom utilities to your project via the new
`@utility` rule.

For example, given the following:
```css
@utility text-trim {
  text-box-trim: both;
  text-box-edge: cap alphabetic;
}
```

A new `text-trim` utility is available and can be used directly or with
variants:
```html
<div class="text-trim">...</div>
<div class="hover:text-trim">...</div>
<div class="lg:dark:text-trim">...</div>
```

If a utility is defined more than one time the latest definition will be
used:
```css
@utility text-trim {
  text-box-trim: both;
  text-box-edge: cap alphabetic;
}

@utility text-trim {
  text-box-trim: both;
  text-box-edge: cap ideographic;
}
```

Then using `text-trim` will produce the following CSS:
```css
.text-trim {
  text-box-trim: both;
  text-box-edge: cap ideographic;
}
```

You may also override specific existing utilities with this — for
example to add a `text-rendering` property to the `text-sm` utility:
```css
@utility text-sm {
  font-size: var(--font-size-sm, 0.875rem);
  line-height: var(--font-size-sm--line-height, 1.25rem);
  text-rendering: optimizeLegibility;
}
```

Though it's preferred, should you not need to add properties, to
override the theme instead.

Lastly, utilities with special characters do not need to be escaped like
you would for a class name in a selector:
```css
@utility push-1/2 {
  right: 50%;
}
```

We do however explicitly error on certain patterns that we want to
reserve for future use, for example `push-*` and `push-[15px]`.

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2024-07-24 11:07:24 -04:00
Philipp Spiess
300524b893
Normalize attribute selectors for data-* and aria-* modifiers (#14040)
Fixes #14026 
See https://github.com/tailwindlabs/tailwindcss/pull/14037 for the v3
fix

When translating `data-` and `aria-` modifiers with attribute selectors,
we currently do not wrap the target attribute in quotes. This only works
for keywords (purely alphabetic words) but breaks as soon as there are
numbers or things like spaces in the attribute:

```html
<div data-id="foo" class="data-[id=foo]:underline">underlined</div>
<div data-id="f1" class="data-[id=1]:underline">not underlined</div>
<div data-id="foo bar" class="data-[id=foo_bar]:underline">not underlined</div>
```

Since it's fairly common to have attribute selectors with `data-` and
`aria-` modifiers, this PR will now wrap the attribute in quotes unless
these are already wrapped.

| Tailwind Modifier  | CSS Selector |
| ------------- | ------------- |
| `.data-[id=foo]`  | `[data-id='foo']`  |
| `.data-[id='foo']`  | `[data-id='foo']`  |
| `.data-[id=foo_i]`  | `[data-id='foo i']`  |
| `.data-[id='foo'_i]`  | `[data-id='foo' i]`  |
| `.data-[id=123]`  | `[data-id='123']`  |

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2024-07-24 16:55:07 +02:00
Jordan Pittman
6ab289343d
Throw out compound variants using variants with nested selectors (#14018) 2024-07-17 15:08:34 -04:00
Jordan Pittman
705255583c
Ensure compound variants work with variants with multiple selectors (#14016)
* Ensure compound variants work with variants with multiple selectors

* Update changelog
2024-07-17 15:03:57 -04:00
Jordan Pittman
e8546df800
Don’t allow at-rule-only variants to be compounded (#14015)
* Don’t allow at-rule-only variants to be compounded

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-07-17 14:52:29 -04:00
Jordan Pittman
cf846a5ff6 Ensure nested selectors are not modified when using group-* and peer-*
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2024-07-16 17:41:43 -04:00
Jordan Pittman
23e6d433a2
Allow variants to be overridden (#14008)
* Allow variants to be overridden

* Update changelog

* Update changelog

* Update tests
2024-07-16 16:55:13 -04:00
Robin Malfait
5ebd5896d7
Add support for custom variants via CSS (#13992)
* implement `@variant` in CSS

* implement `addVariant(name, objectTree)`

* update changelog

* ensure that `@variant` can only be used top-level

* simplify Plugin API type

* Use type instead of interface (for now)

* Use more realistic variant for test

* Allow custom properties to use `@slot` as content

* Use "cannot" instead of "can not"

* Remove `@variant` right away

* Throw when `@variant` is missing a selector or body

* Use "CSS-in-JS" terminology instead of "CSS Tree"

* Rename tests

* Mark some tests that seem wrong

* Tweak comment, remove unnecessary return

* Ensure group is usable with custom selector lists

* Only apply extra `:is(…)` when there are multiple selectors

* Tweak comment

* Throw when @variant has both selector and body

* Rework tests to use more realistic examples

* Compound variants on an isolated copy

This prevents traversals from leaking across variants

* Handle selector lists for peer variants

* Ignore at rules when compounding group and peer variants

* Re-enable skipped tests

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2024-07-16 16:23:23 -04:00
Adam Wathan
54474086c8
Add support for basic addVariant plugins with new @plugin directive (#13982)
* Add basic `addVariant` plugin support

* Return early

* Load plugins right away instead later

* Use correct type for variant name

* Preliminary support for addVariant plugins in PostCSS plugin

* Add test for compounding plugin variants

* Add basic `loadPlugin` support to Vite plugin

* Add basic `loadPlugin` support to CLI

* add `io.ts` for integrations

* use shared `loadPlugin` from `tailwindcss/io`

* add `tailwindcss-test-utils` to `@tailwindcss/cli` and `@tailwindcss/vite`

* only add `tailwindcss-test-utils` to `tailwindcss` as a dev dependency

Because `src/io.ts` is requiring the plugin.

* move `tailwindcss-test-utils` to `@tailwindcss/postcss `

This is the spot where we actually need it.

* use newer pnpm version

* Duplicate loadPlugin implementation instead of exporting io file

* Remove another io reference

* update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2024-07-11 09:47:26 -04:00
Robin Malfait
f7686e1982
Add missing utilities that exist in v3 (#13971)
* replace `resize-both` with `resize`

* add missing `fill-none`

* add missing `accent-auto`

* add missing `blur-0` and `backdrop-blur-0`

We already have `blur-none`, but that sets the blur to `' '`, whereas
`blur-0` sets it to `blur(0)`.

* add missing `drop-shadow-none`

* support negative `hue-rotate` utilities

* support negative `backdrop-hue-rotate` utilities

* add missing `max-w-screen-*` utilities

* update changelog

* Revert "add missing `blur-0` and `backdrop-blur-0`"

This reverts commit 7c42e4e25d3c06b312107afb5325df4b452086a6.

* Revert "add missing `max-w-screen-*` utilities"

This reverts commit 0c68e890ccfb68d104b252bdb3a8a2b2c34a0793.
2024-07-10 16:05:16 +02:00
Robin Malfait
6c0c6a5941
Discard invalid variants and utilities with modifiers (#13977)
* ensure that static utilities do not take a `modifier`

* do not allow multiple segments for now

Right now, `bg-red-1/2/3` should not parse

* add tests for variants that don't accept a modifier

* ensure static variants do not accept a modifier

* do not accept a modifier for some variants

* add tests for utilities that don't accept a modifier

* do not accept a modifier for some utilities

* update changelog

* re-add sorting related test
2024-07-10 15:56:33 +02:00
Robin Malfait
de48a76b6d
Ensure opacity modifier with variables work with color-mix() (#13972)
* ensure opacity modifier variables work as expected

We use `color-mix()` in v4 which means that we can use this for the
opacity modifier. One thing we do already is convert values such as
`0.5` to `50%` because that's what the `color-mix()` function expects.

However, if you use a variable like this:

```html
<div class="[--opacity:0.5] bg-red-500/[var(--opacity)]"></div>
```

This currently generates:

```css
.bg-red-500\/\[var\(--opacity\)\] {
  background-color: color-mix(
    in srgb,
    var(--color-red-500, #ef4444) var(--opacity),
    transparent
  );
}
.\[--opacity\:0\.5\] {
  --opacity: 0.5;
}
```

Which won't work because the opacity variable resolves to `0.5` instead
of the expected`50%`.

This commit fixes that by always ensuring that we use `* 100%`.

- If you already had a percentage, we would have `calc(50% * 100%)`
  which is `50%`.
- If we have `0.5` then we would have `calc(0.5 * 100%)` which is also
  `50%`.

* wrap everything but percentages in `calc(… * 100%)`

* use `else if`

* update changelog
2024-07-10 15:52:05 +02:00
Robin Malfait
992cf8d573
Fix parsing body-less at-rule without terminating semicolon (#13978)
* ensure body-less at-rules without semicolon are parsed correctly

* update changelog
2024-07-10 15:44:28 +02:00
Robin Malfait
8e97a48357
Discard invalid classes such as bg-red-[#000] (#13970)
* add test that verifies that parsing `bg-red-[#0088cc]` should not work

* improve parsing of arbitrary values, root is known

When using arbitrary values such as `bg-[#0088cc]` then we know that
everything before the `-[` part is the `root` of the utility. This also
means that this should exist in the design system as-is.

If we use `findRoot` instead, it means that `bg-red-[#0088cc]` would
also just parse fine and we don't want.

* small refactor: define `important` and `negative` directly

It's not necessary to track state in a state object. Let's use the
variables directly.

* small refactor: use return on same line for consistency

* add test that verifies that parsing `bg-` should not work

* move `value === ''` check up

The value doesn't change anymore, which means we can discard early and
don't need to start creating candidate objects.

* adjust comment with example

* update changelog
2024-07-10 10:01:23 +02:00
Robin Malfait
06e96e0767
Prep next release: 4.0.0-alpha.17 (#13951)
* bump to version `4.0.0-alpha.17`

* update changelog
2024-07-04 19:08:10 +02:00
Benoît Rouleau
3b85780f89
Revert “Prevent Preflight from affecting list semantics” (#13907)
Due to difference in how it handles an empty `<li>`: https://codepen.io/benface/pen/MWdRdyY
2024-07-04 11:21:09 -04:00
Adam Wathan
407de01e8d
Use initial for @property fallbacks instead of (#13949)
* Use `initial` for `@property` fallbacks instead of ` `

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-07-04 11:20:05 -04:00
Adam Wathan
62de02a379
Support combining arbitrary shadows without a color with shadow color utilities (#13876)
* Support combining arbitrary shadows without a color with shadow color utilities

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-06-21 17:36:59 -04:00
Benoît Rouleau
332347ed83
Prevent Preflight from affecting list semantics (#13815)
* Prevent Preflight from affecting list semantics

* Use `list-style` property

* Update snapshots

* Update changelog

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2024-06-14 15:52:50 -04:00
Jordan Pittman
d9cd199aa6 Fix spacing 2024-06-14 12:05:15 -04:00
Jordan Pittman
2e1e1673f0 Update changelog 2024-06-14 09:42:05 -04:00
Adam Wathan
4f7a79168b
Include variable in output for bare utilities like rounded (#13836)
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-06-14 09:25:05 -04:00
Robin Malfait
564fb78365
Add backdrop-blur-none and blur-none utilities (#13831)
* add `backdrop-blur-none` and `blur-none` utilities

* update changelog
2024-06-13 15:27:45 +02:00
Robin Malfait
5f2d654928
Add rounded-4xl utility (#13827)
* add `rounded-4xl`

* update tests to reflect change

* update changelog
2024-06-12 18:22:37 +02:00
Robin Malfait
c711903af5
Prepare next alpha release: 4.0.0-alpha.16 (#13810)
* bump version to 4.0.0-alpha.16

* update changelog
2024-06-07 18:38:44 +02:00
Robin Malfait
8ddd0c6023
update changelog
Add missing changelog entry for #13806
2024-06-07 10:23:20 +02:00
Robin Malfait
eb28b178bb
fix right-top -> right top (#13806) 2024-06-07 00:53:26 +02:00
Jordan Pittman
7b638868dd
[v4] Support arbitrary gradient angles (#13783)
* Support arbitrary gradient angles

* Update changelog

* Use the `bg-linear` namespace instead

* Tweak comments

* Update changelog

* Support negative angles

* Update changelog

* Update changelog

* Update changelog

* Update changelog
2024-06-04 14:18:07 -04:00
Jordan Pittman
640ecf6a93
Use long form <length> | <percentage> syntax for properties (#13660)
* Use longform length + percentage syntax for properties

Using properties that declare the shorthand syntax `<length-percentage>` has a bug where two properties side-by-side e.g. `var(—foo)var(—bar)` invalidate the property value when it should not. Switching the `@property` definition to use the long form syntax `<length> | <percentage>` fixes this.

* Update changelog

* Update tests
2024-06-03 11:49:33 -04:00
Jordan Pittman
1124d1d3c7
Add nth-* variants (#13661)
* Add `nth-*` variants

* Update changelog

* Update snapshots

* Update

* update older `toMatchInlineSnapshot` to `toEqual`

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2024-06-03 11:41:01 -04:00
Jordan Pittman
2428f8f48c
[v4] Support negative values for {col,row}-{start,end} utilities (#13780)
* Support negative values for `{col,row}-{start,end}` utilities

* Update changelog
2024-06-03 11:34:16 -04:00
Robin Malfait
04906c847e
Use length data type for background-size instead of background-position (#13771)
* move `length` data type from `background-position` to `background-size`

This way it's backwards compatible with v3.

* sort data types

* update changelog

* make sure `length` is inferred later

Otherwise `bg-[120px]` would be inferred as `length` instead of
`position`.

In v3 this maps to `position` instead of `length`.
```css
.bg-\[120px\] {
  background-position: 120px;
}
```

* add explicit test cases for `length` and `size` data types
2024-05-31 17:42:27 +02:00
Robin Malfait
2fedbe0194
Bump dependencies (#13741)
* bump dependencies

* update tests to reflect Lightning CSS change
2024-05-25 14:43:59 +02:00
Robin Malfait
0e92310caf
Bump dependencies (#13738)
* run `pnpm update --recursive`

* update tests to reflect lightningcss bump

It looks like it's mainly (re-)ordering properties. Not 100% sure why
though.
2024-05-24 15:07:44 +02:00
Wes Bos
3116d656f1
Add ESM build of the @tailwindcss/postcss package (#13693)
* Fixes exports when importing CJS form ESM file

* Build a real ESM version of the postcss plugin

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2024-05-23 01:01:56 +02:00
Robin Malfait
5e737d8587
4.0.0-alpha.15 (#13658) 2024-05-08 19:26:59 +02:00
Jordan Pittman
aceec2ea39
Add fallbacks for @property rules for Firefox (#13655)
* Add `@property` fallbacks for Firefox

* Update tests

* Update changelog
2024-05-08 12:39:10 -04:00
Robin Malfait
3a5934006a
Revert "Remove automatic var(…) injection (#13537)"
This reverts commit cd4711cc21b8790d52ff62ffa8bfc03d4e031fdb.
2024-05-08 17:56:09 +02:00
Robin Malfait
cb17447ff1
Ensure strings are consumed as-is when using internal segment() (#13608)
* ensure we handle strings as-in

When encountering strings when using `segment` we didn't really treat
them as actual strings. This means that if you used any parens,
brackets, or curlies then we wanted them to be properly balanced.

This should not be the case, whenever we encounter a string, we want to
consume it as-is and don't want to worry about bracket balancing. We
will now consume it until the end of the string (and make sure that
escaped closing quotes are not seen as real closing quotes).

* update changelog

* drop unnecessary test

Already had this test

* ensure we utilities and variants defined

* add example test that parses with unbalanced brackets inside quotes

* improve changelog entry

* hoist comment
2024-04-30 12:22:11 -04:00
Adam Wathan
719c0d4883 Improve comment 2024-04-27 12:32:59 -04:00
Brandon McConnell
1bdc906976
Allow hyphen character in regex pattern to use support queries as is (#13596)
* Allow hyphen character in regex pattern to use support queries as is

* Update variants.test.ts

---------

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2024-04-27 12:28:59 -04:00