@ng-native/tailwind 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/flatten.cjs +85 -9
- package/native.css +4 -4
- package/package.json +3 -3
- package/shared.css +1 -1
- package/tailwind-3-preset.cjs +17 -10
- package/web.css +4 -4
package/flatten.cjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
const { transform, Features } = require('lightningcss');
|
|
18
18
|
const { compileCss, markUnitless } = require('@ng-native/metro/css/compile.cjs');
|
|
19
19
|
|
|
20
|
-
/** `@layer a, b;` - the statement that orders layers
|
|
20
|
+
/** `@layer a, b;` - the statement that orders layers. */
|
|
21
21
|
const LAYER_STATEMENT = /@layer\s+[^;{]+;/g;
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -39,6 +39,60 @@ function rewriteAtRule(css, prelude, keepBody) {
|
|
|
39
39
|
return out;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Put a sheet's rules in the order its cascade layers give them, and take the layers away.
|
|
44
|
+
*
|
|
45
|
+
* A layer's place in the cascade is where it was first named, not where its rules are written:
|
|
46
|
+
* `@layer components { .card { ... } }` after the utilities is still under them, so a utility
|
|
47
|
+
* beside a component's class wins. The engine's cascade is source order, so each layer's rules
|
|
48
|
+
* are moved to its place, the first named first, and what is in no layer goes last, where it
|
|
49
|
+
* beats them all. A layer inside a layer is ordered the same way, within it.
|
|
50
|
+
*
|
|
51
|
+
* `!important` reverses the order of layers in a browser. It does not here.
|
|
52
|
+
*
|
|
53
|
+
* Tailwind's own `properties` layer stays where it is written, at the end: it is the `initial`
|
|
54
|
+
* every `--tw-*` slot starts from, for a browser with no `@property`, and the passes after this
|
|
55
|
+
* one read a slot's value from the last place it is declared.
|
|
56
|
+
*/
|
|
57
|
+
function orderLayers(css) {
|
|
58
|
+
/** Each layer's rules, in the order the layers were first named. */
|
|
59
|
+
const layers = new Map();
|
|
60
|
+
const bodyOf = (name) => layers.get(name) ?? layers.set(name, []).get(name);
|
|
61
|
+
let unlayered = '';
|
|
62
|
+
let from = 0;
|
|
63
|
+
let depth = 0;
|
|
64
|
+
for (let i = 0; i < css.length; i++) {
|
|
65
|
+
if (css[i] === '{') depth++;
|
|
66
|
+
else if (css[i] === '}') depth--;
|
|
67
|
+
if (depth !== 0 || !css.startsWith('@layer', i)) continue;
|
|
68
|
+
const layer = layerAt(css, i);
|
|
69
|
+
if (!layer) break;
|
|
70
|
+
if (layer.names === 'properties') continue;
|
|
71
|
+
// An anonymous layer is one of its own, where it stands.
|
|
72
|
+
if (layer.body === undefined) layer.names.split(',').forEach((name) => bodyOf(name.trim()));
|
|
73
|
+
else bodyOf(layer.names || `\0${layers.size}`).push(orderLayers(layer.body));
|
|
74
|
+
unlayered += css.slice(from, i);
|
|
75
|
+
from = layer.end + 1;
|
|
76
|
+
i = layer.end;
|
|
77
|
+
}
|
|
78
|
+
unlayered += css.slice(from);
|
|
79
|
+
return [...[...layers.values()].flat(), unlayered].join('\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The `@layer` at `at`: the names it gives, where it ends, and the body of a block, which the
|
|
84
|
+
* statement that only orders layers has none of. Nothing when its block never closes.
|
|
85
|
+
*/
|
|
86
|
+
function layerAt(css, at) {
|
|
87
|
+
const end = css.indexOf(';', at);
|
|
88
|
+
const open = css.indexOf('{', at);
|
|
89
|
+
const names = (to) => css.slice(at + '@layer'.length, to).trim();
|
|
90
|
+
if (end !== -1 && (open === -1 || end < open)) return { names: names(end), end };
|
|
91
|
+
const close = open === -1 ? -1 : blockEnd(css, open);
|
|
92
|
+
if (close === -1) return null;
|
|
93
|
+
return { names: names(open), end: close, body: css.slice(open + 1, close) };
|
|
94
|
+
}
|
|
95
|
+
|
|
42
96
|
/** The index of the brace that closes the block opened at `open`, or -1. */
|
|
43
97
|
function blockEnd(css, open) {
|
|
44
98
|
let depth = 0;
|
|
@@ -376,17 +430,36 @@ function nest(at, c) {
|
|
|
376
430
|
* nothing to say why.
|
|
377
431
|
*/
|
|
378
432
|
function dropPseudoElementRules(css) {
|
|
379
|
-
return css.replace(/([^{}]+)\{([^{}]*)\}/g, (whole,
|
|
380
|
-
if (!
|
|
433
|
+
return css.replace(/([^{}]+)\{([^{}]*)\}/g, (whole, before, body) => {
|
|
434
|
+
if (!before.includes('::')) return whole;
|
|
435
|
+
// A nested rule follows its parent's declarations, which are no part of its selector: a comma
|
|
436
|
+
// in one, `transition-property: color,box-shadow`, is not a comma between selectors.
|
|
437
|
+
const start = selectorStart(before);
|
|
438
|
+
const selectors = before.slice(start);
|
|
381
439
|
const all = selectorList(selectors).map((one) => one.trim());
|
|
382
440
|
const kept = all.filter((one) => one && !/::(?!placeholder\b)/.test(one));
|
|
383
441
|
// Tailwind 3's `::backdrop { --tw-...: ... }`, the reset again for a box native never draws: no
|
|
384
442
|
// author wrote it, so it goes without a word.
|
|
385
|
-
if (!kept.length && /^\s*(--tw-[\w-]+\s*:[^;{}]*;?\s*)*$/.test(body))
|
|
386
|
-
|
|
443
|
+
if (!kept.length && /^\s*(--tw-[\w-]+\s*:[^;{}]*;?\s*)*$/.test(body)) {
|
|
444
|
+
return before.slice(0, start);
|
|
445
|
+
}
|
|
446
|
+
return kept.length && kept.length < all.length
|
|
447
|
+
? `${before.slice(0, start)}${kept.join(', ')} {${body}}`
|
|
448
|
+
: whole;
|
|
387
449
|
});
|
|
388
450
|
}
|
|
389
451
|
|
|
452
|
+
/** Where a rule's selector starts in the text before its block: after the last declaration. */
|
|
453
|
+
function selectorStart(before) {
|
|
454
|
+
const at = { depth: 0, quote: null };
|
|
455
|
+
let start = 0;
|
|
456
|
+
for (let i = 0; i < before.length; i++) {
|
|
457
|
+
nest(at, before[i]);
|
|
458
|
+
if (before[i] === ';' && !at.quote && at.depth === 0) start = i + 1;
|
|
459
|
+
}
|
|
460
|
+
return start;
|
|
461
|
+
}
|
|
462
|
+
|
|
390
463
|
/**
|
|
391
464
|
* Fold arithmetic, by handing it to lightningcss with an old target.
|
|
392
465
|
*
|
|
@@ -417,7 +490,9 @@ function fold(css) {
|
|
|
417
490
|
Features.MediaIntervalSyntax |
|
|
418
491
|
Features.OklabColors |
|
|
419
492
|
Features.LabColors |
|
|
420
|
-
Features.ColorFunction
|
|
493
|
+
Features.ColorFunction |
|
|
494
|
+
// `:dir()` is answered from the app's layout direction; lowered, it is a list of languages.
|
|
495
|
+
Features.DirSelector,
|
|
421
496
|
}).code.toString();
|
|
422
497
|
// Lowering can reintroduce feature detection around what it just lowered.
|
|
423
498
|
return rewriteAtRule(foldSimpleCalc(out), '@supports', true);
|
|
@@ -918,9 +993,10 @@ function compiles(selector, declaration) {
|
|
|
918
993
|
function flattenTailwind(css, { onSettled = () => {} } = {}) {
|
|
919
994
|
// Before any pass of lightningcss here, which reads `m-[3]`'s bare 3 as 3px and hides it from
|
|
920
995
|
// the compiler: see `markUnitless`.
|
|
921
|
-
let out = childrenOfWhere(
|
|
922
|
-
|
|
923
|
-
|
|
996
|
+
let out = childrenOfWhere(orderLayers(markUnitlessReverse(markUnitless(unprefixAncestors(css)))));
|
|
997
|
+
// Any layer left is Tailwind's `properties`, or inside something else, a media query say:
|
|
998
|
+
// unwrapped where it stands.
|
|
999
|
+
out = out.replace(LAYER_STATEMENT, '');
|
|
924
1000
|
out = rewriteAtRule(out, '@layer', true);
|
|
925
1001
|
out = rewriteAtRule(out, '@supports', true);
|
|
926
1002
|
out = resetWithoutReverseSlots(out);
|
package/native.css
CHANGED
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
* those events can. `press:` and `hovered:` say one half each, for code that would rather be
|
|
30
30
|
* precise than portable.
|
|
31
31
|
*/
|
|
32
|
-
@custom-variant hover (&:active, &[data-hover]);
|
|
32
|
+
@custom-variant hover (&:active, &[data-hover]:where(:not([data-hover="false"])));
|
|
33
33
|
@custom-variant press (&:active);
|
|
34
|
-
@custom-variant hovered (&[data-hover]);
|
|
34
|
+
@custom-variant hovered (&[data-hover]:where(:not([data-hover="false"])));
|
|
35
35
|
|
|
36
36
|
/*
|
|
37
37
|
* `focus-visible:` is `focus:`, and both match the state attribute as well as the pseudo-class.
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
* on a view wrapping it, and that view can only know it is focused because the primitive told it.
|
|
47
47
|
* The same idea as `hovered:` matching `data-hover`.
|
|
48
48
|
*/
|
|
49
|
-
@custom-variant focus-visible (&:focus, &[data-focus]);
|
|
50
|
-
@custom-variant focus (&:focus, &[data-focus]);
|
|
49
|
+
@custom-variant focus-visible (&:focus, &[data-focus]:where(:not([data-focus="false"])));
|
|
50
|
+
@custom-variant focus (&:focus, &[data-focus]:where(:not([data-focus="false"])));
|
|
51
51
|
|
|
52
52
|
/*
|
|
53
53
|
* `font-mono`, which named a font neither platform has.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/tailwind",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Tailwind CSS preset for Angular Native: Tailwind 4 and Tailwind 3, on native and on the web.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"type": "commonjs",
|
|
18
18
|
"main": "flatten.cjs",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ng-native/metro": "0.
|
|
20
|
+
"@ng-native/metro": "0.5.0",
|
|
21
21
|
"lightningcss": "^1.30.2"
|
|
22
22
|
},
|
|
23
23
|
"nx": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"url": "https://github.com/ng-native/ng-native/issues"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@ng-native/metro": "0.
|
|
35
|
+
"@ng-native/metro": "0.5.0",
|
|
36
36
|
"@tailwindcss/cli": "^4.3.3",
|
|
37
37
|
"tailwindcss": "^3.4.1 || ^4.3.3"
|
|
38
38
|
},
|
package/shared.css
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
* accessibility state and nothing else. `data-disabled` is what a primitive publishes, and both
|
|
43
43
|
* selectors are kept so a host primitive that really does carry the prop still matches.
|
|
44
44
|
*/
|
|
45
|
-
@custom-variant disabled (&[data-disabled], &:disabled);
|
|
45
|
+
@custom-variant disabled (&[data-disabled]:where(:not([data-disabled="false"])), &:disabled);
|
|
46
46
|
|
|
47
47
|
/*
|
|
48
48
|
* `dark:` follows a class, seeded from the OS.
|
package/tailwind-3-preset.cjs
CHANGED
|
@@ -29,6 +29,13 @@ const firstFamily = (value) =>
|
|
|
29
29
|
.split(',')[0]
|
|
30
30
|
.trim();
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* A state attribute that is set, and not to `"false"`: an Angular attribute binding to a boolean
|
|
34
|
+
* writes the string, and a state that is off is not a state. In `:where()`, so the variant weighs
|
|
35
|
+
* what one attribute does.
|
|
36
|
+
*/
|
|
37
|
+
const on = (attribute) => `[${attribute}]:where(:not([${attribute}="false"]))`;
|
|
38
|
+
|
|
32
39
|
/**
|
|
33
40
|
* The states each variant reads. On native, `hover:` is the pressed state, or a real hover where
|
|
34
41
|
* there is a pointer, and `focus-visible:` is `focus:`. A browser has `:hover` and `:focus-visible`
|
|
@@ -36,18 +43,18 @@ const firstFamily = (value) =>
|
|
|
36
43
|
*/
|
|
37
44
|
const STATES = {
|
|
38
45
|
native: {
|
|
39
|
-
hover: [':active', '
|
|
40
|
-
hovered: ['
|
|
41
|
-
focus: [':focus', '
|
|
42
|
-
'focus-visible': [':focus', '
|
|
43
|
-
disabled: ['
|
|
46
|
+
hover: [':active', on('data-hover')],
|
|
47
|
+
hovered: [on('data-hover')],
|
|
48
|
+
focus: [':focus', on('data-focus')],
|
|
49
|
+
'focus-visible': [':focus', on('data-focus')],
|
|
50
|
+
disabled: [on('data-disabled'), ':disabled'],
|
|
44
51
|
},
|
|
45
52
|
web: {
|
|
46
|
-
hover: [':hover', ':active', '
|
|
47
|
-
hovered: [':hover', '
|
|
48
|
-
focus: [':focus', '
|
|
49
|
-
'focus-visible': [':focus-visible', '
|
|
50
|
-
disabled: ['
|
|
53
|
+
hover: [':hover', ':active', on('data-hover')],
|
|
54
|
+
hovered: [':hover', on('data-hover')],
|
|
55
|
+
focus: [':focus', on('data-focus')],
|
|
56
|
+
'focus-visible': [':focus-visible', on('data-focus')],
|
|
57
|
+
disabled: [on('data-disabled'), ':disabled'],
|
|
51
58
|
},
|
|
52
59
|
};
|
|
53
60
|
|
package/web.css
CHANGED
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
* `hovered:` gains `:hover`, so the precise spellings stay precise on a platform that can tell the
|
|
30
30
|
* two apart.
|
|
31
31
|
*/
|
|
32
|
-
@custom-variant hover (&:hover, &:active, &[data-hover]);
|
|
32
|
+
@custom-variant hover (&:hover, &:active, &[data-hover]:where(:not([data-hover="false"])));
|
|
33
33
|
@custom-variant press (&:active);
|
|
34
|
-
@custom-variant hovered (&:hover, &[data-hover]);
|
|
34
|
+
@custom-variant hovered (&:hover, &[data-hover]:where(:not([data-hover="false"])));
|
|
35
35
|
|
|
36
36
|
/*
|
|
37
37
|
* `focus-visible:` is the real thing here, which is the distinction native cannot make.
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
* `:focus-within` would cover the wrapper case natively here, but not the one where the two
|
|
48
48
|
* elements are siblings rather than nested, so the attribute stays as the general answer.
|
|
49
49
|
*/
|
|
50
|
-
@custom-variant focus-visible (&:focus-visible, &[data-focus]);
|
|
51
|
-
@custom-variant focus (&:focus, &[data-focus]);
|
|
50
|
+
@custom-variant focus-visible (&:focus-visible, &[data-focus]:where(:not([data-focus="false"])));
|
|
51
|
+
@custom-variant focus (&:focus, &[data-focus]:where(:not([data-focus="false"])));
|
|
52
52
|
|
|
53
53
|
/*
|
|
54
54
|
* Where the shared utilities get their numbers from on this platform.
|