5282 Commits

Author SHA1 Message Date
Adam Wathan
4e1f98141a
Support @theme reference without @import (#13222)
* Support `@theme reference` without `@import`

* Fix test

* Update tests

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-12 14:07:01 -04:00
Adam Wathan
65f6f7c1ca
Prepare alpha.8 release (#13203)
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-11 15:10:21 -04:00
Robin Malfait
172bc5d822
Add incremental rebuilds to @tailwindcss/postcss (#13170)
* rename PostCSS plugin name from `tailwindcss-v4` to `@tailwindcss/postcss`

* add incremental rebuilds to `@tailwindcss/postcss`

* improve comment

* update changelog

* Simplify nested conditionals

* Simplify more conditionals

* Refactor file modification tracking

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-11 15:01:28 -04:00
Robin Malfait
a458e5ddda
Add incremental rebuilds to @tailwindcss/cli (#13169)
* ensure the root CSS file part of the `cssImportPaths`

* add incremental rebuilds to `@tailwindcss/cli`

* update changelog
2024-03-11 14:32:41 -04:00
Robin Malfait
d230f2e13b
Improve incremental builds (#13168)
* ensure we don't crash on deleted files

* change return type of `compile` to include a `rebuild()` function

This will allow us in the future to perform incremental rebuilds after
the initial rebuild. This is purely the API change so that we can
prepare all the call sites to use this new API.

* set `@tailwind utilities` nodes

Instead of replacing the node that represents the `@tailwind utilities`
with the generated AST nodes from the rawCandidates, we will set the
nodes of the `@tailwind utilities` rule to the AST nodes instead.

This way we dont' have to remove and replace the `@tailwind utilities`
rule with `n` new nodes. This will later allow us to track the
`@tailwindcss utilities` rule itself and update its `nodes` for
incremental rebuilds.

This also requires a small change to the printer where we now need to
print the children of the `@tailwind utilities` rule. Note: we keep the
same `depth` as-if the `@tailwindcss utilities` rule was not there.
Otherwise additional indentation would be present.

* move sorting to the `ast.sort()` call

This will allow us to keep sorting AST nodes in a single spot.

* move parser functions to the `DesignSystem`

This allows us to put all the parsers in the `DesignSystem`, this allows
us to scope the parsers to the current design system (the current theme,
current utility values and variants).

The implementation of these parsers are also using a `DefaultMap`
implementation. This allows us to make use of caching and only parse a
candidate, parse a variant or compile AST nodes for a given raw
candidate once if we've already done this work in the past.

Again, this is scoped to the `DesignSystem` itself. This means that if
the corresponding theme changes, then we will create a new
`DesignSystem` entirely and the caches will be garbage collected. This
is important because a candidate like `bg-primary` can be invalid in
`DesignSystem` A, but can be valid in `DesignSystem` B and vice versa.

* ensure we sort variants alphabetically by root

For incremental rebuilds we don't know all the used variants upfront,
which means that we can't sort them upfront either (what we used to do).

This code now allows us to sort the variants deterministically when
sorting the variants themselves instead of relying on the fact that they
used to be sorted before.

The sort itself could change slightly compared to the previous
implementation (especially when you used stacked variants in your
candidates), but it will still be deterministic.

* replace `localeCompare` comparisons

Use cheaper comparisons than `localeCompare` when comparing 2 strings.
We currently don't care if it is 100% correctly sorted, but we just want
consistent sorting. This is currently faster compared to
`localeCompare`.

Another benefit is that `localeCompare` could result in
non-deterministic results if the CSS was generated on 2 separate
computers where the `locale` is different.

We could solve that by adding a dedicated locale, but it would still be
slower compared to this.

* track invalid candidates

When an incoming raw candidates doesn't produce any output, then we can
mark it as an invalid candidate. This will allow us to reduce the amount
of candidates to handle in incremental rebuilds.

* add initial incremental rebuild implementation

This includes a number of steps:

1. Track the `@tailwind utilities` rule, so that we can adjust its nodes
   later without re-parsing the full incoming CSS.
2. Add the new incoming raw candidates to the existing set of
   candidates.
3. Parse the merged set to `compileCandidates` (this can accept any
   `Iterable<string>`, which means `string[]`, `Set<string>`, ...)
4. Get the new AST nodes, update the `@tailwind utilities` rule's nodes
   and re-print the AST to CSS.

* improvement 1: ignore known invalid candidates

This will reduce the amount of candidates to handle. They would
eventually be skipped anyway, but now we don't even have to re-parse
(and hit a cache) at all.

* improvement 2: skip work, when generated AST is the same

Currently incremental rebuilds are additive, which means that we are not
keeping track if we should remove CSS again in development.

We can exploit this information, because now we can quickly check the
amoutn of generated AST nodes.

- If they are the same then nothing new is generated — this means that
  we can re-use the previous compiled CSS. We don't even have to
  re-print the AST because we already did do that work in the past.
- If there are more AST nodes, something new is generated — this means
  that we should update the `@tailwind utilities` rule and re-print the
  CSS. We can store the result for future incremental rebuilds.

* improvement 3: skip work if no new candidates are detected

- We already know a set of candidates from previous runs.
- We also already know a set of candidates that are invalid and don't
  produce anything.

This means that an incremental rebuild could give us a new set of
candidates that either already exist or are invalid.

If nothing changes, then we can re-use the compiled CSS.

This actually happens more often than you think, and the bigger your
project is the better this optimization will be.

For example:

```
// Imagine file A exists:
<div class="flex items-center justify-center"></div>
<button class="text-red-500">Delete</button>
```

```
// Now you add a second file B:
<div class="text-red-500 flex"></div>
```

You just created a brand new file with a bunch of HTML elements and
classes, yet all of the candidates in file B already exist in file A, so
nothing changes to the actual generated CSS.

Now imagine the other hundreds of files that already contain hundreds of
classes.

The beauty of this optimization is two-fold:

- On small projects, compiling is very fast even without this check.
  This means it is performant.
- On bigger projects, we will be able to re-use existing candidates.
  This means it stays performant.

* remove `getAstNodeSize`

We can move this up the tree and move it to the `rebuild` function
instead.

* remove invalid candidate tracking from `DesignSystem`

This isn't used anywhere but only in the `rebuild` of the compile step.
This allows us to remove it entirely from core logic, and move it up the
chain where it is needed.

* replace `throwOnInvalidCandidate` with `onInvalidCanidate`

This was only needed for working with `@apply`, now this logic _only_
exists in the code path where we are handling `@apply`.

* update `compile` API signature

* update callsite of `compile()` function

* fix typo
2024-03-11 14:24:49 -04:00
Adam Wathan
78d1c50f1c
Reset borders, padding, and margin universally (#13189)
* Reset borders, padding, and margin universally

Noticed iframes have a default border we weren't resetting, feels safest to just remove borders across the board and reintroduce them for form controls.

We were also resetting padding on an element by element basis but I can't think of any elements we are actually trying to avoid resetting padding on, so just reset it everywhere.

This also removes the left margin on file buttons that separates the button from the meta data about the currently selected file but I think this is fine, let the user decide how much space to put there intentionally like we do with other things.

* Include ::first-letter

Supports margin/padding/border (but not box-sizing) so should be in reset list.

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-11 14:17:19 -04:00
Adam Wathan
d863de7abf
Prevent content-none from being overridden when conditionally styling ::before/::after (#13187)
* Prevent content-none from being overridden when conditionally styling before/after

* Update changelog

* Fix changelog entry

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-11 14:09:50 -04:00
Adam Wathan
8309b47266
Remove static radius values from theme (#13186)
* Remove static radius values from theme

* Update snapshots

* Update changelog

* Use static utilities + a big loop

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-11 14:02:18 -04:00
Robin Malfait
b7dd979735
when using { optimize: true }, also minify the CSS (#13201)
If you don't want to minify, but you do want to optimize, then you can
use `{ optimize: { minify: false} }` instead.
2024-03-11 18:29:21 +01:00
Kris Braun
8123fa513a
Vite plugin: stop checking CSS files that no longer exist (#13197)
* Vite plugin: stop checking CSS files that no longer exist

Fix a potential memory leak in the Vite plugin. If CSS files are created that include `@tailwind` and later deleted, remove them from the list of files checked.

Thanks to @timneutkens for highlighting this issue.

* Vite plugin: don't log when files are removed
2024-03-11 13:24:01 -04:00
Adam Wathan
5c5037d9b5
Ensure scale utilities support percentages (#13182)
* Ensure scale utilities support percentages

* Update changelog

* Fix changelog entry

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: wongjn <11310624+wongjn@users.noreply.github.com>
2024-03-11 13:14:10 -04:00
Robin Malfait
388d1b0298
add "access": "public" to publishConfig (#13164) 2024-03-08 22:04:05 +01:00
Robin Malfait
d68a4af58e
Prepare next 4.0.0-alpha.7 release (#13163)
* bump versions to `4.0.0-alpha.7`

* update changelog
2024-03-08 21:46:03 +01:00
Adam Wathan
4c598d002a Tweak changelog entries 2024-03-08 15:38:03 -05:00
Robin Malfait
6d6df58db1
merge Added sections in the CHANGELOG 2024-03-08 21:31:23 +01:00
Robin Malfait
0b44cbbcf5
Add missing Android packages to version-packages script (#13161)
* add missing `android` packages to `version-packages` script

* update CHANGELOG
2024-03-08 21:30:32 +01:00
Kris Braun
065bbd3c99
[v4] Add provenance to all published packages (#13160)
* Add provenance to all packages

Based on #13097 by @saibotk

Add [provenance](https://docs.npmjs.com/generating-provenance-statements) for all published packages.

---
Co-authored-by: saibotk <git@saibotk.de>

* Document reason for id-token permission

* Update changelog
2024-03-08 21:30:13 +01:00
Adam Wathan
277e2cdd4c
Parse CSS files with CRLF line endings (#13162)
* Parse CSS files with CRLF line endings

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-08 21:28:58 +01:00
Kris Braun
5d1e48de14
Include percent sign in font-stretch utilities (#13158)
Include a percent sign in `font-stretch` utilities (e.g. `font-stretch-50%` rather than `font-stretch-50`) to make the meaning of the value clearer.
2024-03-08 13:32:45 -05:00
Robin Malfait
c550a62be4
[v4] Make CSS optimization and minification configurable (#13130)
* only run Lightning CSS when passing `--minify` to the CLI

* only optimize the CSS when creating a production build

* add `optimize` option to PostCSS plugin

- The optimize option can be set to `true`, which will optimize
  (unnesting, adding browser prefixes, lowering values) and minify
- The optimize option can also be set to `{ minify: false }`, which will
  optimize but not minify.

* default `optimize` option to the true for `NODE_ENV=production`

* add `--optimize` flag to CLI

This will only optimize the CSS output without minification.

* update `--minify` description

* update changelog
2024-03-08 18:36:07 +01:00
Kris Braun
7132875d02
[v4] Add font-stretch utilities (#13153)
* [v4] Add `font-stretch` utilities

Based on #12171 y @Gregory-Gerard.

Add [`font-stretch`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch) utilities. Naming with `font-stretch` rather than `stretch` since the latter isn't clearly associated with fonts. Named values (e.g. `font-stretch-ulta-expanded`) and percentages (e.g. `font-stretch-50`) are supported.
2024-03-08 12:10:29 -05:00
Can Kolay
0e1af11b30
[v4] Android binaries for Oxide (#13115) 2024-03-08 12:08:24 -05:00
Adam Wathan
0a57d33a7d
Don't error on @apply with extra whitespace (#13144)
* Don't crash on @apply with extra whitespace

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-07 22:00:15 -05:00
Kris Braun
eca02424f5
v4 changelog (#13131)
---------

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2024-03-07 14:26:35 -05:00
Robin Malfait
d288c52780
bump versions to 4.0.0-alpha.6 2024-03-07 16:00:23 +01:00
Robin Malfait
324273ce8d
[v4] Only allow CSS variables in @theme (#13125)
* add `WalkAction` to indicate how the `walk` function should behave

You can `Continue` its execution (the default behaviour), `Skip` walking
the current node, or `Stop` walking entirely.

* walk the nodes of `@theme` directly

There is no need to walk the `@theme` itself or to create a temporary
array here.

* improvement: skip walking

* only allow CSS variables inside `@theme`

* update error message
2024-03-07 15:59:59 +01:00
Adam Wathan
d27f4cee32
Update CONTRIBUTING.md 2024-03-07 09:34:19 -05:00
Adam Wathan
fcaff7c613
[v4] Only set border-style for appropriate border side (#13124)
* Only set border-style for appropriate border side

Fixes #13121.

Something to consider is that this implementation will still have issues if we ever implement support for utilities like `border-r-dashed`. 6am and I just woke up and am going to the gym now but leaving this as a note to consider when I get back before merging :)

* Fix typos in test names

* Revert playground change

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-07 09:11:28 -05:00
Robin Malfait
9864b9c9cd
bump versions to 4.0.0-alpha.5 2024-03-07 00:40:10 +01:00
Robin Malfait
f6d93d1151
replace the homemade clearAnsiEscapes with the native stripVTControlCharacters (#13117) 2024-03-07 00:27:59 +01:00
Jordan Pittman
e2dcbad153
Always honor git ignore files (#13119) 2024-03-06 18:24:34 -05:00
Robin Malfait
722f436956
bump versions to 4.0.0-alpha.4 (#13113) 2024-03-06 21:00:27 +01:00
Robin Malfait
9bfc1cc30b
add extension less exports for all exported CSS files (#13110) 2024-03-06 20:56:52 +01:00
Robin Malfait
dd2c68080b
bump versions to 4.0.0-alpha.3 (#13106) 2024-03-06 17:27:17 +01:00
Robin Malfait
99e3fdbceb
drop deprecated decoration-slice and decoration-clone utilities (#13107) 2024-03-06 16:57:23 +01:00
Robin Malfait
813aa45009
[v4] Improve CI by linting before installing playwright browsers (#13105)
* improve CI by linting before building and intalling playwright browsers

* move lint below build
2024-03-06 16:57:13 +01:00
Adam Wathan
b3b2debdd9
[v4] Support old important modifier position (#13103)
* Support old important modifier position

* update

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2024-03-06 10:56:56 -05:00
Robin Malfait
19fcd0ebba
use fs.readFileSync instead of an import (#13104)
In some environments, depending on the Node version importing a `.json`
file without a `with` or `assert` doesn't work.

Let's play it safe and use an `fs.readFileSync` instead.
2024-03-06 10:43:22 -05:00
Robin Malfait
0a2b319ada
bump versions to 4.0.0-alpha.2 2024-03-06 15:13:45 +01:00
Robin Malfait
2ba42fe53d
Copy README file to every package (#13096)
* copy README file to every package

* point workflow status badge to correct workflow file
2024-03-06 08:49:31 -05:00
Robin Malfait
0597489604
Move the CLI to its own package @tailwindcss/cli (#13095)
* move `cli` to its own package `@tailwindcss/cli`

* minify builds when using `tsup`

* prefer tsup cli flag over tsup.config.ts file

* add `--clean`, to make sure `dist/` folders are cleaned before building

* make CLI esm only

* use version of `tailwindcss` instead of the version of `@tailwindcss/cli`
2024-03-06 05:41:12 -05:00
Robin Malfait
bab74da932
Prep alpha release (#13089)
* use `next` as default release channel

* bump versions to `4.0.0-alpha.1`
2024-03-05 14:46:10 -05:00
Kris Braun
abb702bf8f
Add README, LICENSE, and CONTRIBUTING (#13088)
* Add README, LICENSE, CONTRIBUTING, and CODE_OF_CONDUCT

* Add alpha status to README.

* Remove intro sentence

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-03-05 14:45:39 -05:00
Robin Malfait
ca07ca8c69
Only output @property foo once instead of N times (#13087)
* only output `@property foo` once instead of N times

* compute the indent once

* improve performance by using strings and for-loops

* drop unnecessary new line
2024-03-05 18:04:33 +01:00
Robin Malfait
191643f663
pretty print generated CSS by default (#13086)
The pretty printing is fairly basic, but it adds some space between
properties `color: red;`, adds newlines after `;`, `{`, and `}`.

Last but not least, it indents nested CSS based on depth with 2 spaces.
2024-03-05 17:58:17 +01:00
Robin Malfait
86e71194e7
use oxide tag instead of internal tag by default
This will allow us to install `tailwindcss@oxide`
2024-03-05 15:26:37 +01:00
Robin Malfait
1988978fc3
rename release.yml to release-oxide.yml
This way we can re-use the workflow that already exists on the `master`
branch and it will allow us to trigger manual releases from the `next`
branch without making changes to the `master` branch.
2024-03-05 14:50:40 +01:00
Robin Malfait
117ceefe70
ensure CI runs against PRs that have to go into next 2024-03-05 14:43:40 +01:00
Robin Malfait
a500854a9f
run CI on master and next branch 2024-03-05 14:31:08 +01:00
Robin Malfait
a68de1df27
introduce v4 codebase 2024-03-05 14:29:15 +01:00