@ng-native/tailwind 0.0.1 → 0.1.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/LICENSE +21 -0
- package/README.md +89 -1
- package/config.cjs +238 -0
- package/flatten.cjs +830 -0
- package/native.css +84 -0
- package/package.json +47 -3
- package/preset.cjs +122 -0
- package/shared.css +203 -0
- package/web.css +85 -0
package/native.css
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* What Tailwind does not know about a phone.
|
|
3
|
+
*
|
|
4
|
+
* @import "tailwindcss/theme.css";
|
|
5
|
+
* @import "tailwindcss/utilities.css";
|
|
6
|
+
* @import "@ng-native/tailwind/native.css";
|
|
7
|
+
*
|
|
8
|
+
* `active:` needs nothing added: it lands on the `:active` the engine already tracks. Everything
|
|
9
|
+
* that is not about the input device lives in `shared.css`, which this imports - the safe-area
|
|
10
|
+
* and hairline utilities, and the platform, disabled and dark variants. What is left here is the
|
|
11
|
+
* four variants where having a pointer, or not, changes the answer.
|
|
12
|
+
*
|
|
13
|
+
* `web.css` is the counterpart, and the two files are worth reading side by side: the difference
|
|
14
|
+
* between them is the whole of what this platform is missing and what it has instead.
|
|
15
|
+
*/
|
|
16
|
+
@import './shared.css';
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* `hover:` is the pressed state, or a real hover where there is a pointer.
|
|
20
|
+
*
|
|
21
|
+
* `:hover` is dropped with a build warning here and always will be: it is a pseudo-class the
|
|
22
|
+
* matcher has no way to answer. But a hover style and a press style answer the same design question - what does this
|
|
23
|
+
* look like while the user is engaging with it - and class strings written for the web ask it with
|
|
24
|
+
* `hover:`. Pointing the variant at `:active`, which the engine sets on the touched view and its
|
|
25
|
+
* ancestors, is what lets those strings port unedited.
|
|
26
|
+
*
|
|
27
|
+
* `data-hover` is for the one device with a pointer: an iPad with a trackpad or a mouse, which
|
|
28
|
+
* sends React Native's pointer events. Nothing sets it for you; a component that listens for
|
|
29
|
+
* those events can. `press:` and `hovered:` say one half each, for code that would rather be
|
|
30
|
+
* precise than portable.
|
|
31
|
+
*/
|
|
32
|
+
@custom-variant hover (&:active, &[data-hover]);
|
|
33
|
+
@custom-variant press (&:active);
|
|
34
|
+
@custom-variant hovered (&[data-hover]);
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* `focus-visible:` is `focus:`, and both match the state attribute as well as the pseudo-class.
|
|
38
|
+
*
|
|
39
|
+
* The web distinction exists to keep a focus ring off a control someone clicked, and there is no
|
|
40
|
+
* clicking here: focus arrives from a keyboard, a remote or an assistive technology, all of which
|
|
41
|
+
* are exactly the cases the ring is for. `:focus-visible` is also dropped with a build warning,
|
|
42
|
+
* and shadcn puts one on every interactive control, so without this nothing ports.
|
|
43
|
+
*
|
|
44
|
+
* `data-focus` is there because focus lands on the control and the ring belongs on the box around
|
|
45
|
+
* it. A text field is the native view that takes focus; the border, the radius and the padding are
|
|
46
|
+
* on a view wrapping it, and that view can only know it is focused because the primitive told it.
|
|
47
|
+
* The same idea as `hovered:` matching `data-hover`.
|
|
48
|
+
*/
|
|
49
|
+
@custom-variant focus-visible (&:focus, &[data-focus]);
|
|
50
|
+
@custom-variant focus (&:focus, &[data-focus]);
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* `font-mono`, which named a font neither platform has.
|
|
54
|
+
*
|
|
55
|
+
* Tailwind's `--font-mono` is a CSS stack beginning `ui-monospace`, and this compiler takes the
|
|
56
|
+
* first family from a stack because React Native's `fontFamily` is one name, not a list. So
|
|
57
|
+
* `font-mono` reached the device as `fontFamily: "ui-monospace"` - a CSS generic keyword that
|
|
58
|
+
* exists on neither iOS nor Android - and every device silently fell back to the system font.
|
|
59
|
+
* `ui-chart`'s tooltip and three story pages ask for it and none of them got it.
|
|
60
|
+
*
|
|
61
|
+
* Three lines rather than one, because there is no single name both platforms have:
|
|
62
|
+
*
|
|
63
|
+
* `Courier New` is the floor. It is a real font on both, so `font-mono` means something even in
|
|
64
|
+
* an app that never sets a platform class on its root. That matters more than it looks: the
|
|
65
|
+
* alternative was a rule that works only if the app remembered something, which is the same
|
|
66
|
+
* silent failure in a new shape.
|
|
67
|
+
*
|
|
68
|
+
* The two platform rules then upgrade it to the font each platform actually uses for code -
|
|
69
|
+
* Menlo on iOS, and Android's own `monospace` alias, which maps to Roboto Mono. They win on
|
|
70
|
+
* specificity, two classes against one.
|
|
71
|
+
*
|
|
72
|
+
* The web keeps Tailwind's full stack: `web.css` does not import this, and a browser resolves
|
|
73
|
+
* `ui-monospace` correctly on its own.
|
|
74
|
+
*/
|
|
75
|
+
@theme {
|
|
76
|
+
--font-mono: 'Courier New';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.platform-ios .font-mono {
|
|
80
|
+
font-family: Menlo;
|
|
81
|
+
}
|
|
82
|
+
.platform-android .font-mono {
|
|
83
|
+
font-family: monospace;
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/tailwind",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tailwind CSS preset for Angular Native: Tailwind 4 on native and web, Tailwind 3 on native.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"react-native",
|
|
8
|
+
"angular-native",
|
|
9
|
+
"ios",
|
|
10
|
+
"android",
|
|
11
|
+
"fabric",
|
|
12
|
+
"native",
|
|
13
|
+
"tailwind",
|
|
14
|
+
"tailwindcss",
|
|
15
|
+
"css"
|
|
16
|
+
],
|
|
17
|
+
"type": "commonjs",
|
|
18
|
+
"main": "flatten.cjs",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"lightningcss": "^1.30.2",
|
|
21
|
+
"@ng-native/metro": "0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"nx": {
|
|
24
|
+
"tags": [
|
|
25
|
+
"scope:tailwind",
|
|
26
|
+
"layer:build"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
5
29
|
"license": "MIT",
|
|
30
|
+
"homepage": "https://ng-native.com/packages/tailwind",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/ng-native/ng-native/issues"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@tailwindcss/cli": "^4.3.3",
|
|
36
|
+
"tailwindcss": "^3.4.1 || ^4.3.3",
|
|
37
|
+
"@ng-native/metro": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@tailwindcss/cli": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
6
44
|
"repository": {
|
|
7
45
|
"type": "git",
|
|
8
46
|
"url": "git+https://github.com/ng-native/ng-native.git",
|
|
9
47
|
"directory": "packages/tailwind"
|
|
10
48
|
},
|
|
11
|
-
"
|
|
49
|
+
"files": [
|
|
50
|
+
"*.cjs",
|
|
51
|
+
"*.css"
|
|
52
|
+
],
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
12
56
|
}
|
package/preset.cjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The native preset, for Tailwind 3.
|
|
3
|
+
*
|
|
4
|
+
* // tailwind.config.js
|
|
5
|
+
* module.exports = {
|
|
6
|
+
* presets: [require('@ng-native/tailwind/preset.cjs')],
|
|
7
|
+
* content: ['./src/**\/*.{ts,html}'],
|
|
8
|
+
* };
|
|
9
|
+
*
|
|
10
|
+
* The same vocabulary as `native.css`, which is the Tailwind 4 preset, in the JavaScript form
|
|
11
|
+
* Tailwind 3 takes: read the two side by side, and change them together. Every choice is explained
|
|
12
|
+
* there and in `shared.css`; this file only says how each one is spelt here.
|
|
13
|
+
*
|
|
14
|
+
* The plugin is a plain function rather than `require('tailwindcss/plugin')(...)`, which Tailwind 3
|
|
15
|
+
* accepts, so this file resolves nothing from the app.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** The four safe-area edges, keyed by the letter a spacing utility uses for them. */
|
|
19
|
+
const EDGES = { t: 'top', r: 'right', b: 'bottom', l: 'left' };
|
|
20
|
+
|
|
21
|
+
/** `var(--safe-area-inset-top, 0px)`: the inset `<safe-area-provider>` sets on the root. */
|
|
22
|
+
const inset = (edge) => `var(--safe-area-inset-${edge}, 0px)`;
|
|
23
|
+
|
|
24
|
+
const HAIRLINE = 'var(--hairline, 1px)';
|
|
25
|
+
|
|
26
|
+
function nativePreset({ addUtilities, addVariant, matchUtilities, theme }) {
|
|
27
|
+
// `hover:` is the pressed state, or a real hover where there is a pointer.
|
|
28
|
+
addVariant('hover', ['&:active', '&[data-hover]']);
|
|
29
|
+
addVariant('press', '&:active');
|
|
30
|
+
addVariant('hovered', '&[data-hover]');
|
|
31
|
+
// `focus-visible:` is `focus:`, and both follow the state attribute.
|
|
32
|
+
addVariant('focus-visible', ['&:focus', '&[data-focus]']);
|
|
33
|
+
addVariant('focus', ['&:focus', '&[data-focus]']);
|
|
34
|
+
addVariant('disabled', ['&[data-disabled]', '&:disabled']);
|
|
35
|
+
|
|
36
|
+
// Tailwind 3 builds `group-*:` and `peer-*:` from the pseudo-class itself rather than from the
|
|
37
|
+
// variants above, so each state is spelt again for an ancestor `.group` and an earlier `.peer`.
|
|
38
|
+
const states = {
|
|
39
|
+
hover: [':active', '[data-hover]'],
|
|
40
|
+
focus: [':focus', '[data-focus]'],
|
|
41
|
+
'focus-visible': [':focus', '[data-focus]'],
|
|
42
|
+
disabled: ['[data-disabled]', ':disabled'],
|
|
43
|
+
};
|
|
44
|
+
for (const [state, selectors] of Object.entries(states)) {
|
|
45
|
+
addVariant(
|
|
46
|
+
`group-${state}`,
|
|
47
|
+
selectors.map((s) => `:merge(.group)${s} &`),
|
|
48
|
+
);
|
|
49
|
+
addVariant(
|
|
50
|
+
`peer-${state}`,
|
|
51
|
+
selectors.map((s) => `:merge(.peer)${s} ~ &`),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The platform, from a class on the root.
|
|
56
|
+
addVariant('ios', '.platform-ios &');
|
|
57
|
+
addVariant('android', '.platform-android &');
|
|
58
|
+
addVariant('web', '.platform-web &');
|
|
59
|
+
addVariant('native', ['.platform-ios &', '.platform-android &']);
|
|
60
|
+
|
|
61
|
+
const safe = {
|
|
62
|
+
'.p-safe': Object.fromEntries(
|
|
63
|
+
Object.values(EDGES).map((edge) => [`padding-${edge}`, inset(edge)]),
|
|
64
|
+
),
|
|
65
|
+
'.px-safe': { 'padding-right': inset('right'), 'padding-left': inset('left') },
|
|
66
|
+
'.py-safe': { 'padding-top': inset('top'), 'padding-bottom': inset('bottom') },
|
|
67
|
+
};
|
|
68
|
+
for (const [letter, edge] of Object.entries(EDGES)) {
|
|
69
|
+
safe[`.p${letter}-safe`] = { [`padding-${edge}`]: inset(edge) };
|
|
70
|
+
safe[`.m${letter}-safe`] = { [`margin-${edge}`]: inset(edge) };
|
|
71
|
+
}
|
|
72
|
+
addUtilities(safe);
|
|
73
|
+
|
|
74
|
+
// The inset plus a step off the spacing scale, and whichever of the two is larger.
|
|
75
|
+
// Lengths only: a bare number after the inset is no length, and a browser drops it.
|
|
76
|
+
const spacing = { values: theme('spacing'), type: ['length', 'percentage'] };
|
|
77
|
+
for (const [letter, edge] of [
|
|
78
|
+
['t', 'top'],
|
|
79
|
+
['b', 'bottom'],
|
|
80
|
+
]) {
|
|
81
|
+
matchUtilities(
|
|
82
|
+
{
|
|
83
|
+
[`p${letter}-safe`]: (step) => ({ [`padding-${edge}`]: `calc(${inset(edge)} + ${step})` }),
|
|
84
|
+
[`m${letter}-safe`]: (step) => ({ [`margin-${edge}`]: `calc(${inset(edge)} + ${step})` }),
|
|
85
|
+
[`min-p${letter}-safe`]: (step) => ({
|
|
86
|
+
[`padding-${edge}`]: `max(${inset(edge)}, ${step})`,
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
spacing,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const hairlines = {
|
|
94
|
+
'.h-hairline': { height: HAIRLINE },
|
|
95
|
+
'.w-hairline': { width: HAIRLINE },
|
|
96
|
+
'.border-hairline': { 'border-style': 'solid', 'border-width': HAIRLINE },
|
|
97
|
+
};
|
|
98
|
+
for (const [letter, edge] of Object.entries(EDGES)) {
|
|
99
|
+
hairlines[`.border-${letter}-hairline`] = {
|
|
100
|
+
'border-style': 'solid',
|
|
101
|
+
'border-width': '0',
|
|
102
|
+
[`border-${edge}-width`]: HAIRLINE,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
addUtilities(hairlines);
|
|
106
|
+
|
|
107
|
+
// `font-mono`, upgraded to the font each platform uses for code. Utilities rather than base
|
|
108
|
+
// rules, so an app's `important: true` makes them important too, and they still win.
|
|
109
|
+
addUtilities({
|
|
110
|
+
'.platform-ios .font-mono': { 'font-family': 'Menlo' },
|
|
111
|
+
'.platform-android .font-mono': { 'font-family': 'monospace' },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
// A class seeded from the OS, so an app can disagree with it.
|
|
117
|
+
darkMode: ['variant', '.dark &'],
|
|
118
|
+
// A browser reset in terms of `html` and `::before`, none of which means anything on a phone.
|
|
119
|
+
corePlugins: { preflight: false },
|
|
120
|
+
theme: { extend: { fontFamily: { mono: ['Courier New'] } } },
|
|
121
|
+
plugins: [nativePreset],
|
|
122
|
+
};
|
package/shared.css
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The half of the preset that is the same wherever it runs.
|
|
3
|
+
*
|
|
4
|
+
* Split out when the web host arrived, because most of this file never depended on the platform
|
|
5
|
+
* in the first place: the safe-area and hairline utilities read custom properties, so all that
|
|
6
|
+
* changes between a phone and a browser is who sets those properties, and the platform, disabled
|
|
7
|
+
* and dark variants are class and attribute selectors that mean the same thing anywhere.
|
|
8
|
+
*
|
|
9
|
+
* What genuinely differs lives in `native.css` and `web.css`, which each import this and then add
|
|
10
|
+
* their own answers for `hover:`, `press:`, `hovered:` and `focus-visible:`. Those four are where
|
|
11
|
+
* the two platforms actually disagree, and the disagreement is real rather than cosmetic: one has
|
|
12
|
+
* a pointer and the other mostly does not.
|
|
13
|
+
*
|
|
14
|
+
* Not imported directly by an app. Import `native.css` or `web.css`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* The platform, which Tailwind cannot infer. Put the class on the root of the app -
|
|
19
|
+
*
|
|
20
|
+
* <view [class]="'platform-' + platform" style="flex: 1">
|
|
21
|
+
*
|
|
22
|
+
* with `platform` from `nativePlatform()` on native, or `platform-web` on the web, and `ios:`,
|
|
23
|
+
* `android:` and `web:` all work everywhere beneath it. A variant whose class is never present
|
|
24
|
+
* compiles and never matches, which is exactly what a shared class string wants: `ios:pt-2` on a
|
|
25
|
+
* web page is not an error, it is simply not an iPhone.
|
|
26
|
+
*
|
|
27
|
+
* Written as `(.platform-ios &)` rather than Tailwind's usual `(&:where(.platform-ios *))`, which
|
|
28
|
+
* puts a combinator inside `:where()`; the native compiler refuses that, and a plain descendant
|
|
29
|
+
* selector says the same thing in a form both engines have always matched.
|
|
30
|
+
*/
|
|
31
|
+
@custom-variant ios (.platform-ios &);
|
|
32
|
+
@custom-variant android (.platform-android &);
|
|
33
|
+
@custom-variant web (.platform-web &);
|
|
34
|
+
/** Either of the two native platforms, for a rule that is about not being a browser. */
|
|
35
|
+
@custom-variant native (.platform-ios &, .platform-android &);
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* `disabled:` follows the state attribute, not the pseudo-class.
|
|
39
|
+
*
|
|
40
|
+
* `:disabled` compiles to a test for a `disabled` prop on the node, and there is never one: a
|
|
41
|
+
* primitive's `disabled` is an Angular input, consumed by the directive, so it reaches the
|
|
42
|
+
* accessibility state and nothing else. `data-disabled` is what a primitive publishes, and both
|
|
43
|
+
* selectors are kept so a host primitive that really does carry the prop still matches.
|
|
44
|
+
*/
|
|
45
|
+
@custom-variant disabled (&[data-disabled], &:disabled);
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* `dark:` follows a class, seeded from the OS.
|
|
49
|
+
*
|
|
50
|
+
* Tailwind's own `dark:` is `@media (prefers-color-scheme: dark)`, which the engine answers and
|
|
51
|
+
* keeps in step with the system. That is one variant short of what a theme needs: a design system
|
|
52
|
+
* ships its dark palette as `.dark { --background: ... }`, and an app wants a switcher that can
|
|
53
|
+
* disagree with the OS. A class does both - put `dark` on the root and everything beneath it
|
|
54
|
+
* flips, whatever the system thinks.
|
|
55
|
+
*
|
|
56
|
+
* Bind it from `ColorScheme` and the default behaviour is unchanged:
|
|
57
|
+
*
|
|
58
|
+
* <view [class]="scheme.colorScheme()" style="flex: 1">
|
|
59
|
+
*
|
|
60
|
+
* `.dark &` rather than `&:is(.dark *)`, for the same reason as the platform variants above: the
|
|
61
|
+
* compiler refuses a combinator inside `:is()`, and a descendant selector says it plainly.
|
|
62
|
+
*/
|
|
63
|
+
@custom-variant dark (.dark &);
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* The safe area, as utilities.
|
|
67
|
+
*
|
|
68
|
+
* `pb-safe` is the inset on its own; `pb-safe-4` is the inset plus the padding the design wanted
|
|
69
|
+
* anyway, which is what a layout above the home indicator almost always means; `min-pb-safe-4` is
|
|
70
|
+
* whichever of the two is larger, for a design that already had a padding and only needs it to
|
|
71
|
+
* grow on a device with an indicator.
|
|
72
|
+
*
|
|
73
|
+
* The values arrive at runtime, from `<safe-area-provider>`, as custom properties on the root -
|
|
74
|
+
* so they change on rotation without a rebuild, and a `:root` rule in the app's own sheet still
|
|
75
|
+
* overrides them. `env()` is the same idea on the web; this is not spelt `env()` because there is
|
|
76
|
+
* no CSS parser on device, and a custom property is something the cascade already carries.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
@utility p-safe {
|
|
80
|
+
padding-top: var(--safe-area-inset-top, 0px);
|
|
81
|
+
padding-right: var(--safe-area-inset-right, 0px);
|
|
82
|
+
padding-bottom: var(--safe-area-inset-bottom, 0px);
|
|
83
|
+
padding-left: var(--safe-area-inset-left, 0px);
|
|
84
|
+
}
|
|
85
|
+
@utility px-safe {
|
|
86
|
+
padding-right: var(--safe-area-inset-right, 0px);
|
|
87
|
+
padding-left: var(--safe-area-inset-left, 0px);
|
|
88
|
+
}
|
|
89
|
+
@utility py-safe {
|
|
90
|
+
padding-top: var(--safe-area-inset-top, 0px);
|
|
91
|
+
padding-bottom: var(--safe-area-inset-bottom, 0px);
|
|
92
|
+
}
|
|
93
|
+
@utility pt-safe {
|
|
94
|
+
padding-top: var(--safe-area-inset-top, 0px);
|
|
95
|
+
}
|
|
96
|
+
@utility pr-safe {
|
|
97
|
+
padding-right: var(--safe-area-inset-right, 0px);
|
|
98
|
+
}
|
|
99
|
+
@utility pb-safe {
|
|
100
|
+
padding-bottom: var(--safe-area-inset-bottom, 0px);
|
|
101
|
+
}
|
|
102
|
+
@utility pl-safe {
|
|
103
|
+
padding-left: var(--safe-area-inset-left, 0px);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@utility mt-safe {
|
|
107
|
+
margin-top: var(--safe-area-inset-top, 0px);
|
|
108
|
+
}
|
|
109
|
+
@utility mr-safe {
|
|
110
|
+
margin-right: var(--safe-area-inset-right, 0px);
|
|
111
|
+
}
|
|
112
|
+
@utility mb-safe {
|
|
113
|
+
margin-bottom: var(--safe-area-inset-bottom, 0px);
|
|
114
|
+
}
|
|
115
|
+
@utility ml-safe {
|
|
116
|
+
margin-left: var(--safe-area-inset-left, 0px);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* The inset, plus a step off the spacing scale. */
|
|
120
|
+
@utility pt-safe-* {
|
|
121
|
+
padding-top: calc(var(--safe-area-inset-top, 0px) + --spacing(--value(integer)));
|
|
122
|
+
}
|
|
123
|
+
@utility pb-safe-* {
|
|
124
|
+
padding-bottom: calc(var(--safe-area-inset-bottom, 0px) + --spacing(--value(integer)));
|
|
125
|
+
}
|
|
126
|
+
@utility mt-safe-* {
|
|
127
|
+
margin-top: calc(var(--safe-area-inset-top, 0px) + --spacing(--value(integer)));
|
|
128
|
+
}
|
|
129
|
+
@utility mb-safe-* {
|
|
130
|
+
margin-bottom: calc(var(--safe-area-inset-bottom, 0px) + --spacing(--value(integer)));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* Whichever is larger: the inset, or the step. */
|
|
134
|
+
@utility min-pt-safe-* {
|
|
135
|
+
padding-top: max(var(--safe-area-inset-top, 0px), --spacing(--value(integer)));
|
|
136
|
+
}
|
|
137
|
+
@utility min-pb-safe-* {
|
|
138
|
+
padding-bottom: max(var(--safe-area-inset-bottom, 0px), --spacing(--value(integer)));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* The hairline: the thinnest line the screen can draw.
|
|
143
|
+
*
|
|
144
|
+
* Tailwind's `border` is 1px, which is what a browser means by a thin line and what a 3x phone
|
|
145
|
+
* draws as three physical pixels. A native divider is one physical pixel - a third of a point -
|
|
146
|
+
* so `border-b-hairline` is the class a list separator wants. The number comes from React Native
|
|
147
|
+
* at startup, through `deviceTokens()`, and the 1px fallback is what a screen with no answer
|
|
148
|
+
* would have drawn anyway.
|
|
149
|
+
*
|
|
150
|
+
* `border-style: solid` alongside the width, and it is not decoration. React Native has no such
|
|
151
|
+
* property - a border width alone draws a line - but CSS defaults `border-style` to `none`, and a
|
|
152
|
+
* width with no style computes to `0px`. Tailwind's own `border` utilities carry a style of their
|
|
153
|
+
* own, and its preflight sets one globally, but this project deliberately does not import
|
|
154
|
+
* preflight because it is a browser reset that means nothing on a phone. So these utilities, and
|
|
155
|
+
* only these, drew nothing at all on the web: every table row separator, every accordion divider,
|
|
156
|
+
* every sheet and drawer edge, invisible, with the class present and correct on the element.
|
|
157
|
+
*
|
|
158
|
+
* The shorthand rather than `border-bottom-style`, because the compiler maps the shorthand and
|
|
159
|
+
* refuses the longhand. That is also why `border-width: 0` comes with it: a style of `solid` on
|
|
160
|
+
* all four sides makes the three this utility does not name fall back to CSS's initial `medium`,
|
|
161
|
+
* which is 3px, so a one-sided hairline came out as a box with three fat edges. Zero them, then
|
|
162
|
+
* name the one.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/*
|
|
166
|
+
* A hairline as a size, not only as a border.
|
|
167
|
+
*
|
|
168
|
+
* A separator is a view with a height rather than a border, and one point is three physical pixels
|
|
169
|
+
* on a 3x screen where a native divider is one. Same number as the border utilities below, from
|
|
170
|
+
* the same token.
|
|
171
|
+
*/
|
|
172
|
+
@utility h-hairline {
|
|
173
|
+
height: var(--hairline, 1px);
|
|
174
|
+
}
|
|
175
|
+
@utility w-hairline {
|
|
176
|
+
width: var(--hairline, 1px);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@utility border-hairline {
|
|
180
|
+
border-style: solid;
|
|
181
|
+
border-width: 0;
|
|
182
|
+
border-width: var(--hairline, 1px);
|
|
183
|
+
}
|
|
184
|
+
@utility border-t-hairline {
|
|
185
|
+
border-style: solid;
|
|
186
|
+
border-width: 0;
|
|
187
|
+
border-top-width: var(--hairline, 1px);
|
|
188
|
+
}
|
|
189
|
+
@utility border-r-hairline {
|
|
190
|
+
border-style: solid;
|
|
191
|
+
border-width: 0;
|
|
192
|
+
border-right-width: var(--hairline, 1px);
|
|
193
|
+
}
|
|
194
|
+
@utility border-b-hairline {
|
|
195
|
+
border-style: solid;
|
|
196
|
+
border-width: 0;
|
|
197
|
+
border-bottom-width: var(--hairline, 1px);
|
|
198
|
+
}
|
|
199
|
+
@utility border-l-hairline {
|
|
200
|
+
border-style: solid;
|
|
201
|
+
border-width: 0;
|
|
202
|
+
border-left-width: var(--hairline, 1px);
|
|
203
|
+
}
|
package/web.css
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The same preset, for a browser.
|
|
3
|
+
*
|
|
4
|
+
* @import "tailwindcss/theme.css";
|
|
5
|
+
* @import "tailwindcss/utilities.css";
|
|
6
|
+
* @import "@ng-native/tailwind/web.css";
|
|
7
|
+
*
|
|
8
|
+
* `native.css` is the counterpart, and the two are worth reading side by side: what differs
|
|
9
|
+
* between them is the whole of what each platform has and the other does not. Everything else -
|
|
10
|
+
* the safe-area and hairline utilities, the platform, disabled and dark variants - is in
|
|
11
|
+
* `shared.css`, which both import.
|
|
12
|
+
*
|
|
13
|
+
* The point of this file is that a class string written once works on both. `hover:bg-accent` on
|
|
14
|
+
* a shadcn button means the same design intent in both places and resolves to whatever that
|
|
15
|
+
* platform can actually observe.
|
|
16
|
+
*/
|
|
17
|
+
@import './shared.css';
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* `hover:` is a real hover here, and still the pressed state as well.
|
|
21
|
+
*
|
|
22
|
+
* The native preset points this at `:active` because a phone has no pointer, and at `data-hover`
|
|
23
|
+
* because an iPad with a trackpad does. A browser has `:hover` for real, so it leads - but the
|
|
24
|
+
* other two stay, and that is deliberate rather than defensive. `:active` is what a touchscreen
|
|
25
|
+
* laptop or a phone browser gives you, where `:hover` either never fires or fires and sticks after
|
|
26
|
+
* a tap. Keeping all three means a class string behaves the same on a desktop browser, a tablet
|
|
27
|
+
* browser and a phone, without the component knowing which it is on.
|
|
28
|
+
*
|
|
29
|
+
* `hovered:` gains `:hover`, so the precise spellings stay precise on a platform that can tell the
|
|
30
|
+
* two apart.
|
|
31
|
+
*/
|
|
32
|
+
@custom-variant hover (&:hover, &:active, &[data-hover]);
|
|
33
|
+
@custom-variant press (&:active);
|
|
34
|
+
@custom-variant hovered (&:hover, &[data-hover]);
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* `focus-visible:` is the real thing here, which is the distinction native cannot make.
|
|
38
|
+
*
|
|
39
|
+
* The native preset aliases it to `:focus`, because there is no clicking on a phone: focus only
|
|
40
|
+
* ever arrives from a keyboard, a remote or an assistive technology, which are exactly the cases
|
|
41
|
+
* a ring is for. A browser has mice, so the distinction is real again and the browser's own
|
|
42
|
+
* heuristic is better than anything this could reimplement.
|
|
43
|
+
*
|
|
44
|
+
* `data-focus` is kept in both. Focus lands on the control and the ring belongs on the box around
|
|
45
|
+
* it: a text field is the element that takes focus, while the border, the radius and the padding
|
|
46
|
+
* are on a wrapper, and that wrapper can only know it is focused because the primitive told it.
|
|
47
|
+
* `:focus-within` would cover the wrapper case natively here, but not the one where the two
|
|
48
|
+
* elements are siblings rather than nested, so the attribute stays as the general answer.
|
|
49
|
+
*/
|
|
50
|
+
@custom-variant focus-visible (&:focus-visible, &[data-focus]);
|
|
51
|
+
@custom-variant focus (&:focus, &[data-focus]);
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Where the shared utilities get their numbers from on this platform.
|
|
55
|
+
*
|
|
56
|
+
* The safe-area and hairline utilities in `shared.css` read custom properties, which is what lets
|
|
57
|
+
* them be shared at all: on native the values arrive at runtime from `<safe-area-provider>` and
|
|
58
|
+
* `deviceTokens()`, and here they come from the browser's own `env()` and a resolution query.
|
|
59
|
+
* Neither side needs to know about the other.
|
|
60
|
+
*
|
|
61
|
+
* `env()` returns nothing outside a viewport-fit page, and the fallbacks in `shared.css` are
|
|
62
|
+
* already `0px`, so a page that never opted in is unaffected rather than broken.
|
|
63
|
+
*/
|
|
64
|
+
:root {
|
|
65
|
+
--safe-area-inset-top: env(safe-area-inset-top, 0px);
|
|
66
|
+
--safe-area-inset-right: env(safe-area-inset-right, 0px);
|
|
67
|
+
--safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
|
|
68
|
+
--safe-area-inset-left: env(safe-area-inset-left, 0px);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* A hairline is one physical pixel, which is what a native divider is and what `shared.css`'s
|
|
73
|
+
* utilities are named after. A browser's `1px` is one *CSS* pixel, so on a 2x display the line a
|
|
74
|
+
* design asked to be as thin as possible is drawn twice as thick as it should be.
|
|
75
|
+
*/
|
|
76
|
+
@media (min-resolution: 2dppx) {
|
|
77
|
+
:root {
|
|
78
|
+
--hairline: 0.5px;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
@media (min-resolution: 3dppx) {
|
|
82
|
+
:root {
|
|
83
|
+
--hairline: 0.33px;
|
|
84
|
+
}
|
|
85
|
+
}
|