Skip to content

Commit 8c70555

Browse files
committed
WIP
1 parent b146f71 commit 8c70555

37 files changed

+580
-240
lines changed

src/lib/expandTailwindAtRules.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ function buildStylesheet(rules, context) {
129129
return returnValue
130130
}
131131

132-
export const DEFAULTS_LAYER = Symbol('defaults-layer')
133-
134132
export default function expandTailwindAtRules(context) {
135133
return (root) => {
136134
let layerNodes = {
@@ -209,12 +207,10 @@ export default function expandTailwindAtRules(context) {
209207
// @defaults rules are unconditionally added first to ensure that
210208
// using any utility that relies on defaults will work even when
211209
// compiled in an isolated environment like CSS modules
212-
if (context.tailwindConfig[DEFAULTS_LAYER] !== false) {
213-
if (layerNodes.base) {
214-
layerNodes.base.after(cloneNodes([...defaultNodes], root.source))
215-
} else {
216-
root.prepend(cloneNodes([...defaultNodes], root.source))
217-
}
210+
if (layerNodes.base) {
211+
layerNodes.base.after(cloneNodes([...defaultNodes], root.source))
212+
} else {
213+
root.prepend(cloneNodes([...defaultNodes], root.source))
218214
}
219215

220216
if (layerNodes.base) {

tests/animations.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { run, html, css } from './util/run'
1+
import { run, html, css, defaults } from './util/run'
22

33
test('basic', () => {
44
let config = {
@@ -15,6 +15,7 @@ test('basic', () => {
1515

1616
return run('@tailwind utilities', config).then((result) => {
1717
expect(result.css).toMatchFormattedCss(css`
18+
${defaults}
1819
@keyframes spin {
1920
to {
2021
transform: rotate(360deg);
@@ -68,6 +69,7 @@ test('custom', () => {
6869

6970
return run('@tailwind utilities', config).then((result) => {
7071
expect(result.css).toMatchFormattedCss(css`
72+
${defaults}
7173
@keyframes one {
7274
to {
7375
transform: rotate(360deg);
@@ -98,6 +100,7 @@ test('custom prefixed', () => {
98100

99101
return run('@tailwind utilities', config).then((result) => {
100102
expect(result.css).toMatchFormattedCss(css`
103+
${defaults}
101104
@keyframes tw-one {
102105
to {
103106
transform: rotate(360deg);
@@ -124,6 +127,7 @@ test('multiple', () => {
124127

125128
return run('@tailwind utilities', config).then((result) => {
126129
expect(result.css).toMatchFormattedCss(css`
130+
${defaults}
127131
@keyframes bounce {
128132
0%,
129133
100% {
@@ -165,6 +169,7 @@ test('multiple custom', () => {
165169

166170
return run('@tailwind utilities', config).then((result) => {
167171
expect(result.css).toMatchFormattedCss(css`
172+
${defaults}
168173
@keyframes one {
169174
to {
170175
transform: rotate(360deg);

tests/apply.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import { DEFAULTS_LAYER } from '../src/lib/expandTailwindAtRules.js'
43

54
import { run, html, css, defaults } from './util/run'
65

@@ -284,6 +283,7 @@ test('@apply classes from outside a @layer', async () => {
284283

285284
await run(input, config).then((result) => {
286285
return expect(result.css).toMatchFormattedCss(css`
286+
${defaults}
287287
.font-bold {
288288
font-weight: 700;
289289
}
@@ -351,6 +351,7 @@ test('@applying classes from outside a @layer respects the source order', async
351351

352352
await run(input, config).then((result) => {
353353
return expect(result.css).toMatchFormattedCss(css`
354+
${defaults}
354355
.baz {
355356
text-decoration-line: underline;
356357
text-decoration-line: none;
@@ -419,6 +420,7 @@ it('should remove duplicate properties when using apply with similar properties'
419420

420421
return run(input, config).then((result) => {
421422
expect(result.css).toMatchFormattedCss(css`
423+
${defaults}
422424
.foo {
423425
position: absolute;
424426
top: 50%;
@@ -462,6 +464,7 @@ it('should apply all the definitions of a class', () => {
462464

463465
return run(input, config).then((result) => {
464466
return expect(result.css).toMatchFormattedCss(css`
467+
${defaults}
465468
.foo {
466469
position: relative;
467470
--tw-aspect-w: 1;
@@ -543,6 +546,7 @@ it('should not throw when the selector is different (but contains the base parti
543546

544547
return run(input, config).then((result) => {
545548
expect(result.css).toMatchFormattedCss(css`
549+
${defaults}
546550
.bg-gray-500 {
547551
--tw-bg-opacity: 1;
548552
background-color: rgb(107 114 128 / var(--tw-bg-opacity));
@@ -641,6 +645,7 @@ it('rules with vendor prefixes are still separate when optimizing defaults rules
641645

642646
return run(input, config).then((result) => {
643647
return expect(result.css).toMatchFormattedCss(css`
648+
${defaults}
644649
[type='range']::-moz-range-thumb {
645650
border-color: #e5e7eb;
646651
}
@@ -678,6 +683,7 @@ it('should be possible to apply user css', () => {
678683

679684
return run(input, config).then((result) => {
680685
return expect(result.css).toMatchFormattedCss(css`
686+
${defaults}
681687
.foo {
682688
color: red;
683689
}
@@ -749,6 +755,7 @@ it('should not apply unrelated siblings when applying something from within atru
749755

750756
return run(input, config).then((result) => {
751757
expect(result.css).toMatchFormattedCss(css`
758+
${defaults}
752759
.foo {
753760
font-weight: bold;
754761
color: green;
@@ -797,6 +804,7 @@ it('should be possible to apply user css without tailwind directives', () => {
797804

798805
return run(input, config).then((result) => {
799806
return expect(result.css).toMatchFormattedCss(css`
807+
${defaults}
800808
.bop {
801809
color: red;
802810
}
@@ -814,7 +822,6 @@ it('should be possible to apply user css without tailwind directives', () => {
814822

815823
it('apply can emit defaults in isolated environments without @tailwind directives', () => {
816824
let config = {
817-
[DEFAULTS_LAYER]: true,
818825
experimental: { optimizeUniversalDefaults: true },
819826

820827
content: [{ raw: html`<div class="foo"></div>` }],
@@ -829,6 +836,7 @@ it('apply can emit defaults in isolated environments without @tailwind directive
829836
// TODO: Do we want this to work?
830837
return run(input, config).then((result) => {
831838
return expect(result.css).toMatchFormattedCss(css`
839+
${defaults}
832840
.foo {
833841
--tw-translate-x: 0;
834842
--tw-translate-y: 0;
@@ -850,7 +858,6 @@ it('apply can emit defaults in isolated environments without @tailwind directive
850858

851859
it('apply does not emit defaults in isolated environments without optimizeUniversalDefaults', () => {
852860
let config = {
853-
[DEFAULTS_LAYER]: true,
854861
experimental: { optimizeUniversalDefaults: false },
855862
content: [{ raw: html`<div class="foo"></div>` }],
856863
corePlugins: { preflight: false },

tests/arbitrary-values.test.css

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1+
*,
2+
::before,
3+
::after {
4+
--tw-translate-x: 0;
5+
--tw-translate-y: 0;
6+
--tw-rotate: 0;
7+
--tw-skew-x: 0;
8+
--tw-skew-y: 0;
9+
--tw-scale-x: 1;
10+
--tw-scale-y: 1;
11+
--tw-pan-x: ;
12+
--tw-pan-y: ;
13+
--tw-pinch-zoom: ;
14+
--tw-scroll-snap-strictness: proximity;
15+
border-color: #e5e7eb;
16+
--tw-ordinal: ;
17+
--tw-slashed-zero: ;
18+
--tw-numeric-figure: ;
19+
--tw-numeric-spacing: ;
20+
--tw-numeric-fraction: ;
21+
--tw-ring-inset: ;
22+
--tw-ring-offset-width: 0px;
23+
--tw-ring-offset-color: #fff;
24+
--tw-ring-color: rgb(59 130 246 / 0.5);
25+
--tw-ring-offset-shadow: 0 0 #0000;
26+
--tw-ring-shadow: 0 0 #0000;
27+
--tw-shadow: 0 0 #0000;
28+
--tw-shadow-colored: 0 0 #0000;
29+
--tw-blur: ;
30+
--tw-brightness: ;
31+
--tw-contrast: ;
32+
--tw-grayscale: ;
33+
--tw-hue-rotate: ;
34+
--tw-invert: ;
35+
--tw-saturate: ;
36+
--tw-sepia: ;
37+
--tw-drop-shadow: ;
38+
--tw-backdrop-blur: ;
39+
--tw-backdrop-brightness: ;
40+
--tw-backdrop-contrast: ;
41+
--tw-backdrop-grayscale: ;
42+
--tw-backdrop-hue-rotate: ;
43+
--tw-backdrop-invert: ;
44+
--tw-backdrop-opacity: ;
45+
--tw-backdrop-saturate: ;
46+
--tw-backdrop-sepia: ;
47+
}
148
.inset-\[11px\] {
249
top: 11px;
350
right: 11px;

tests/arbitrary-values.test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
import path from 'path'
33

4-
import { run, html, css } from './util/run'
4+
import { run, html, css, defaults } from './util/run'
55

66
test('arbitrary values', () => {
77
let config = {
@@ -27,6 +27,7 @@ it('should be possible to differentiate between decoration utilities', () => {
2727

2828
return run('@tailwind utilities', config).then((result) => {
2929
return expect(result.css).toMatchFormattedCss(css`
30+
${defaults}
3031
.decoration-\[\#ccc\] {
3132
text-decoration-color: #ccc;
3233
}
@@ -49,6 +50,7 @@ it('should support modifiers for arbitrary values that contain the separator', (
4950

5051
return run('@tailwind utilities', config).then((result) => {
5152
return expect(result.css).toMatchFormattedCss(css`
53+
${defaults}
5254
.hover\:bg-\[url\(\'https\:\/\/github\.com\/tailwindlabs\.png\'\)\]:hover {
5355
background-image: url('https://github.com/tailwindlabs.png');
5456
}
@@ -79,6 +81,7 @@ it('should support arbitrary values for various background utilities', () => {
7981

8082
return run('@tailwind utilities', config).then((result) => {
8183
return expect(result.css).toMatchFormattedCss(css`
84+
${defaults}
8285
.bg-red-500 {
8386
--tw-bg-opacity: 1;
8487
background-color: rgb(239 68 68 / var(--tw-bg-opacity));
@@ -118,7 +121,9 @@ it('should not generate any css if an unknown typehint is used', () => {
118121
}
119122

120123
return run('@tailwind utilities', config).then((result) => {
121-
return expect(result.css).toMatchFormattedCss(css``)
124+
return expect(result.css).toMatchFormattedCss(css`
125+
${defaults}
126+
`)
122127
})
123128
})
124129

@@ -127,6 +132,7 @@ it('should handle unknown typehints', () => {
127132

128133
return run('@tailwind utilities', config).then((result) => {
129134
return expect(result.css).toMatchFormattedCss(css`
135+
${defaults}
130136
.w-\[length\:12px\] {
131137
width: 12px;
132138
}
@@ -139,7 +145,10 @@ it('should convert _ to spaces', () => {
139145
// into an issue with `\2c ` escapes. If we use `\2c ` then JS complains
140146
// about strict mode. But `\\2c ` is not what it expected.
141147
function css(templates) {
142-
return templates.join('')
148+
return `
149+
${defaults}\n
150+
${templates.join('')}
151+
`
143152
}
144153

145154
let config = {
@@ -244,6 +253,7 @@ it('should not convert escaped underscores with spaces', () => {
244253

245254
return run('@tailwind utilities', config).then((result) => {
246255
return expect(result.css).toMatchFormattedCss(css`
256+
${defaults}
247257
.content-\[\'snake\\_case\'\] {
248258
--tw-content: 'snake_case';
249259
content: var(--tw-content);
@@ -260,7 +270,9 @@ it('should warn and not generate if arbitrary values are ambiguous', () => {
260270
}
261271

262272
return run('@tailwind utilities', config).then((result) => {
263-
return expect(result.css).toMatchFormattedCss(css``)
273+
return expect(result.css).toMatchFormattedCss(css`
274+
${defaults}
275+
`)
264276
})
265277
})
266278

@@ -273,6 +285,7 @@ it('should support colons in URLs', () => {
273285

274286
return run('@tailwind utilities', config).then((result) => {
275287
return expect(result.css).toMatchFormattedCss(css`
288+
${defaults}
276289
.bg-\[url\(\'https\:\/\/www\.spacejam\.com\/1996\/img\/bg_stars\.gif\'\)\] {
277290
background-image: url('https://www.spacejam.com/1996/img/bg_stars.gif');
278291
}
@@ -289,6 +302,7 @@ it('should support unescaped underscores in URLs', () => {
289302

290303
return run('@tailwind utilities', config).then((result) => {
291304
return expect(result.css).toMatchFormattedCss(`
305+
${defaults}
292306
.bg-\\[url\\(\\'brown_potato\\.jpg\\'\\)\\2c _url\\(\\'red_tomato\\.png\\'\\)\\] {
293307
background-image: url('brown_potato.jpg'), url('red_tomato.png');
294308
}
@@ -309,6 +323,7 @@ it('should be possible to read theme values in arbitrary values (without quotes)
309323

310324
return run('@tailwind utilities', config).then((result) => {
311325
return expect(result.css).toMatchFormattedCss(css`
326+
${defaults}
312327
.w-\[theme\(spacing\.1\)\] {
313328
width: calc(1 * 0.25rem);
314329
}
@@ -332,6 +347,7 @@ it('should be possible to read theme values in arbitrary values (with quotes)',
332347

333348
return run('@tailwind utilities', config).then((result) => {
334349
return expect(result.css).toMatchFormattedCss(css`
350+
${defaults}
335351
.w-\[theme\(\'spacing\.1\'\)\] {
336352
width: calc(1 * 0.25rem);
337353
}

tests/basic-usage.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
import path from 'path'
33

4-
import { html, run, css } from './util/run'
4+
import { html, run, css, defaults } from './util/run'
55

66
test('basic usage', () => {
77
let config = {
@@ -46,6 +46,7 @@ test('all plugins are executed that match a candidate', () => {
4646

4747
return run(input, config).then((result) => {
4848
expect(result.css).toMatchFormattedCss(css`
49+
${defaults}
4950
.bg-green-light {
5051
--tw-bg-opacity: 1;
5152
background-color: rgb(0 128 0 / var(--tw-bg-opacity));
@@ -98,6 +99,7 @@ test('per-plugin colors with the same key can differ when using a custom colors
9899

99100
return run(input, config).then((result) => {
100101
expect(result.css).toMatchFormattedCss(css`
102+
${defaults}
101103
.bg-theme {
102104
--tw-bg-opacity: 1;
103105
background-color: rgb(255 0 0 / var(--tw-bg-opacity));

0 commit comments

Comments
 (0)