css-utility-functions 1.0.1
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/README.md +245 -0
- package/dist/index.css +897 -0
- package/dist/index.min.css +28 -0
- package/package.json +46 -0
- package/src/colors/alpha.css +27 -0
- package/src/colors/complement.css +23 -0
- package/src/colors/contrast-text.css +20 -0
- package/src/colors/darken.css +20 -0
- package/src/colors/desaturate.css +22 -0
- package/src/colors/grayscale.css +22 -0
- package/src/colors/invert.css +22 -0
- package/src/colors/lighten.css +20 -0
- package/src/colors/mix.css +27 -0
- package/src/colors/saturate.css +22 -0
- package/src/effects/diagonal-lines.css +58 -0
- package/src/effects/shadow.css +30 -0
- package/src/index.css +55 -0
- package/src/layout/neg.css +21 -0
- package/src/layout/z-index.css +24 -0
- package/src/logic/and.css +30 -0
- package/src/logic/nand.css +30 -0
- package/src/logic/nor.css +30 -0
- package/src/logic/not.css +23 -0
- package/src/logic/or.css +30 -0
- package/src/logic/xnor.css +30 -0
- package/src/logic/xor.css +30 -0
- package/src/math/circle.css +46 -0
- package/src/math/lerp.css +29 -0
- package/src/math/modular.css +32 -0
- package/src/math/poly-angle.css +27 -0
- package/src/spacing/fluid.css +72 -0
- package/src/spacing/ratio-height.css +29 -0
- package/src/spacing/space.css +30 -0
- package/src/units/to-px.css +19 -0
- package/src/units/to-rem.css +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# CSS Utility Functions
|
|
2
|
+
|
|
3
|
+
A collection of reusable CSS custom native functions using the new `@function` syntax.
|
|
4
|
+
|
|
5
|
+
⚠️ **Experimental Feature**: CSS `@function` is currently experimental. Check [browser compatibility](https://developer.mozilla.org/en-US/docs/Web/CSS/@function#browser_compatibility) before using in production.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install css-utility-functions
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or download and include in your project.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Option 1: Use Bundled Version (Recommended)
|
|
18
|
+
|
|
19
|
+
```css
|
|
20
|
+
/* All functions in one file */
|
|
21
|
+
@import 'css-utility-functions';
|
|
22
|
+
|
|
23
|
+
/* Or use minified version */
|
|
24
|
+
@import 'css-utility-functions/dist/index.min.css';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Option 2: Import Individual Functions
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
@import 'css-utility-functions/src/alpha.css';
|
|
31
|
+
@import 'css-utility-functions/src/fluid.css';
|
|
32
|
+
/* ... import only what you need */
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Option 3: Development (Source Files)
|
|
36
|
+
|
|
37
|
+
```css
|
|
38
|
+
@import './src/index.css';
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Building
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Install dependencies
|
|
45
|
+
npm install
|
|
46
|
+
|
|
47
|
+
# Build bundled version
|
|
48
|
+
npm run build
|
|
49
|
+
|
|
50
|
+
# Build minified version
|
|
51
|
+
npm run build:min
|
|
52
|
+
|
|
53
|
+
# Build both
|
|
54
|
+
npm run build:all
|
|
55
|
+
|
|
56
|
+
# Watch for changes
|
|
57
|
+
npm run watch
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Available Functions
|
|
61
|
+
|
|
62
|
+
### Color Utilities
|
|
63
|
+
|
|
64
|
+
#### `--alpha()`
|
|
65
|
+
Creates a semi-transparent version of any color.
|
|
66
|
+
|
|
67
|
+
```css
|
|
68
|
+
.overlay {
|
|
69
|
+
background: --alpha(#6366f1, 0.2);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### `--lighten()` / `--darken()`
|
|
74
|
+
Adjust a color's lightness. Use decimal values (0.1 = 10%, 0.2 = 20%).
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
.btn:hover {
|
|
78
|
+
background: --lighten(var(--btn-bg), 0.15);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### `--saturate()` / `--desaturate()`
|
|
83
|
+
Adjust a color's saturation/chroma. Use decimal values (0.4 = 40%, 1.0 = 100%).
|
|
84
|
+
|
|
85
|
+
```css
|
|
86
|
+
.vibrant {
|
|
87
|
+
background: --saturate(var(--primary), 0.4);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### `--mix()`
|
|
92
|
+
Blend two colors by percentage.
|
|
93
|
+
|
|
94
|
+
```css
|
|
95
|
+
.tinted {
|
|
96
|
+
background: --mix(white, var(--brand), 90%);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### `--contrast-text()`
|
|
101
|
+
Auto-select black or white text for optimal contrast.
|
|
102
|
+
|
|
103
|
+
```css
|
|
104
|
+
.badge {
|
|
105
|
+
background: var(--badge-color);
|
|
106
|
+
color: --contrast-text(var(--badge-color));
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### Spacing & Sizing
|
|
113
|
+
|
|
114
|
+
#### `--space()`
|
|
115
|
+
Consistent spacing scale (4px base).
|
|
116
|
+
|
|
117
|
+
```css
|
|
118
|
+
.card {
|
|
119
|
+
padding: --space(4); /* 1rem */
|
|
120
|
+
gap: --space(2); /* 0.5rem */
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### `--fluid()`
|
|
125
|
+
Responsive sizing that scales smoothly between viewports.
|
|
126
|
+
|
|
127
|
+
```css
|
|
128
|
+
h1 {
|
|
129
|
+
font-size: --fluid(1.5rem, 4rem);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `--ratio-height()`
|
|
134
|
+
Calculate height from width and aspect ratio.
|
|
135
|
+
|
|
136
|
+
```css
|
|
137
|
+
.video-thumb {
|
|
138
|
+
width: 320px;
|
|
139
|
+
height: --ratio-height(320px, 16, 9); /* 180px */
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### Visual Effects
|
|
146
|
+
|
|
147
|
+
#### `--shadow()`
|
|
148
|
+
Elevation shadows based on level (1-5).
|
|
149
|
+
|
|
150
|
+
```css
|
|
151
|
+
.card {
|
|
152
|
+
box-shadow: --shadow(2);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
### Layout Utilities
|
|
159
|
+
|
|
160
|
+
#### `--z()`
|
|
161
|
+
Semantic z-index scale (avoids magic numbers).
|
|
162
|
+
|
|
163
|
+
```css
|
|
164
|
+
.modal { z-index: --z(5); } /* 500 */
|
|
165
|
+
.tooltip { z-index: --z(7); } /* 700 */
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### `--neg()`
|
|
169
|
+
Negate a value (useful for negative margins).
|
|
170
|
+
|
|
171
|
+
```css
|
|
172
|
+
.pull-up {
|
|
173
|
+
margin-top: --neg(var(--header-height));
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### Unit Conversion
|
|
180
|
+
|
|
181
|
+
#### `--to-rem()` / `--to-px()`
|
|
182
|
+
Convert between pixels and rem (assumes 16px base).
|
|
183
|
+
|
|
184
|
+
```css
|
|
185
|
+
.legacy {
|
|
186
|
+
font-size: --to-rem(18); /* 1.125rem */
|
|
187
|
+
width: --to-px(10); /* 160px */
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Quick Reference
|
|
194
|
+
|
|
195
|
+
| Function | Purpose | Example |
|
|
196
|
+
|----------|---------|---------|
|
|
197
|
+
| **Color Utilities** |||
|
|
198
|
+
| `--alpha()` | Color transparency | `--alpha(blue, 0.3)` |
|
|
199
|
+
| `--lighten()` | Increase lightness | `--lighten(#333, 0.2)` |
|
|
200
|
+
| `--darken()` | Decrease lightness | `--darken(#ccc, 0.1)` |
|
|
201
|
+
| `--saturate()` | Boost saturation | `--saturate(gray, 0.5)` |
|
|
202
|
+
| `--desaturate()` | Reduce saturation | `--desaturate(#f00, 0.3)` |
|
|
203
|
+
| `--mix()` | Blend colors | `--mix(red, blue, 25%)` |
|
|
204
|
+
| `--contrast-text()` | Auto text color | `--contrast-text(var(--bg))` |
|
|
205
|
+
| `--grayscale()` | Remove saturation | `--grayscale(#6366f1)` |
|
|
206
|
+
| `--invert()` | Invert lightness | `--invert(#fff)` → `#000` |
|
|
207
|
+
| `--complement()` | Complementary color | `--complement(blue)` → orange |
|
|
208
|
+
| **Spacing & Sizing** |||
|
|
209
|
+
| `--space()` | Spacing scale | `--space(4)` → `1rem` |
|
|
210
|
+
| `--fluid()` | Viewport-responsive sizing | `--fluid(1rem, 3rem)` |
|
|
211
|
+
| `--fluid-container()` | Container-responsive sizing | `--fluid-container(1rem, 2rem)` |
|
|
212
|
+
| `--ratio-height()` | Aspect ratio calc | `--ratio-height(100px, 16, 9)` |
|
|
213
|
+
| **Visual Effects** |||
|
|
214
|
+
| `--shadow()` | Elevation shadows | `--shadow(3)` |
|
|
215
|
+
| `--diagonal-lines()` | Diagonal line pattern | `--diagonal-lines(--angle: 45deg)` |
|
|
216
|
+
| **Layout Utilities** |||
|
|
217
|
+
| `--z()` | Z-index layers | `--z(5)` → `500` |
|
|
218
|
+
| `--neg()` | Negate value | `--neg(2rem)` → `-2rem` |
|
|
219
|
+
| **Math Utilities** |||
|
|
220
|
+
| `--lerp()` | Linear interpolation | `--lerp(100px, 500px, 0.5)` |
|
|
221
|
+
| `--circle-x()` / `--circle-y()` | Circle coordinates | `--circle-x(100px, 45deg)` |
|
|
222
|
+
| `--modular()` | Typographic scale | `--modular(2, 1rem, 1.25)` |
|
|
223
|
+
| `--poly-angle()` | Polygon vertex angle | `--poly-angle(6, 0)` |
|
|
224
|
+
| **Unit Conversion** |||
|
|
225
|
+
| `--to-rem()` | px → rem | `--to-rem(16)` → `1rem` |
|
|
226
|
+
| `--to-px()` | rem → px | `--to-px(2)` → `32px` |
|
|
227
|
+
| **Logic Operations** |||
|
|
228
|
+
| `--not()` | Boolean negation | `--not(1)` → `0` |
|
|
229
|
+
| `--and()` | Logical AND | `--and(1, 1)` → `1` |
|
|
230
|
+
| `--or()` | Logical OR | `--or(0, 1)` → `1` |
|
|
231
|
+
| `--xor()` | Exclusive OR | `--xor(1, 0)` → `1` |
|
|
232
|
+
| `--nand()` | NOT AND | `--nand(1, 1)` → `0` |
|
|
233
|
+
| `--nor()` | NOT OR | `--nor(0, 0)` → `1` |
|
|
234
|
+
| `--xnor()` | Exclusive NOR | `--xnor(1, 1)` → `1` |
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Browser Support
|
|
239
|
+
|
|
240
|
+
CSS `@function` is an experimental feature. Check [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/@function) for current browser support.
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
MIT (or your preferred license)
|
|
245
|
+
|