css-utility-functions 1.0.4 → 1.1.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 +26 -9
- package/dist/index.css +52 -29
- package/dist/index.min.css +9 -4
- package/package.json +3 -3
- package/src/effects/bevel.css +38 -0
- package/src/effects/shadow.css +12 -4
- package/src/index.css +1 -1
- package/src/layout/z-index.css +0 -24
package/README.md
CHANGED
|
@@ -145,26 +145,43 @@ Calculate height from width and aspect ratio.
|
|
|
145
145
|
### Visual Effects
|
|
146
146
|
|
|
147
147
|
#### `--shadow()`
|
|
148
|
-
Elevation shadows based on level (1-5).
|
|
148
|
+
Elevation shadows based on level (1-5). Optionally control shadow direction with angle parameter.
|
|
149
149
|
|
|
150
150
|
```css
|
|
151
151
|
.card {
|
|
152
152
|
box-shadow: --shadow(2);
|
|
153
153
|
}
|
|
154
|
-
```
|
|
155
154
|
|
|
156
|
-
|
|
155
|
+
.lit-from-top-right {
|
|
156
|
+
box-shadow: --shadow(3, oklch(0% 0 0 / 0.15), 135deg);
|
|
157
|
+
}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
+
.lit-from-left {
|
|
160
|
+
box-shadow: --shadow(2, oklch(0% 0 0 / 0.1), 180deg);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
159
163
|
|
|
160
|
-
#### `--
|
|
161
|
-
|
|
164
|
+
#### `--bevel()`
|
|
165
|
+
Inset elevation shadows for embossed/debossed effects. Optionally control light source direction with angle parameter.
|
|
162
166
|
|
|
163
167
|
```css
|
|
164
|
-
.
|
|
165
|
-
|
|
168
|
+
.pressed-button {
|
|
169
|
+
box-shadow: --bevel(2);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.lit-from-top {
|
|
173
|
+
box-shadow: --bevel(2, oklch(0% 0 0 / 0.1), 270deg);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.input-field {
|
|
177
|
+
box-shadow: --bevel(1, oklch(0% 0 0 / 0.08), 90deg);
|
|
178
|
+
}
|
|
166
179
|
```
|
|
167
180
|
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
### Layout Utilities
|
|
184
|
+
|
|
168
185
|
#### `--neg()`
|
|
169
186
|
Negate a value (useful for negative margins).
|
|
170
187
|
|
|
@@ -212,9 +229,9 @@ Convert between pixels and rem (assumes 16px base).
|
|
|
212
229
|
| `--ratio-height()` | Aspect ratio calc | `--ratio-height(100px, 16, 9)` |
|
|
213
230
|
| **Visual Effects** |||
|
|
214
231
|
| `--shadow()` | Elevation shadows | `--shadow(3)` |
|
|
232
|
+
| `--bevel()` | Inset shadows (emboss/deboss) | `--bevel(2)` |
|
|
215
233
|
| `--diagonal-lines()` | Diagonal line pattern | `--diagonal-lines(--angle: 45deg)` |
|
|
216
234
|
| **Layout Utilities** |||
|
|
217
|
-
| `--z()` | Z-index layers | `--z(5)` → `500` |
|
|
218
235
|
| `--neg()` | Negate value | `--neg(2rem)` → `-2rem` |
|
|
219
236
|
| **Math Utilities** |||
|
|
220
237
|
| `--lerp()` | Linear interpolation | `--lerp(100px, 500px, 0.5)` |
|
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CSS Utility Functions v1.
|
|
2
|
+
* CSS Utility Functions v1.1.1
|
|
3
3
|
* Author: Yair Even-Or
|
|
4
4
|
* Repository: https://github.com/yairEO/css-utility-functions
|
|
5
5
|
*
|
|
@@ -377,9 +377,11 @@
|
|
|
377
377
|
* --shadow() — Elevation Shadows
|
|
378
378
|
*
|
|
379
379
|
* Generates layered box-shadows based on elevation level (1-5).
|
|
380
|
+
* Optionally control shadow direction with angle parameter.
|
|
380
381
|
*
|
|
381
382
|
* @param {number} --level - Elevation level (1-5)
|
|
382
383
|
* @param {color} --color - Shadow color, default: oklch(0% 0 0 / 0.1)
|
|
384
|
+
* @param {angle} --angle - Shadow direction angle, default: 90deg (downward)
|
|
383
385
|
* @returns {string} - Layered box-shadow value (comma-separated shadow list)
|
|
384
386
|
*
|
|
385
387
|
* @example
|
|
@@ -389,18 +391,63 @@
|
|
|
389
391
|
* .modal {
|
|
390
392
|
* box-shadow: --shadow(5, oklch(0% 0 0 / 0.25));
|
|
391
393
|
* }
|
|
394
|
+
* .lit-from-top-right {
|
|
395
|
+
* box-shadow: --shadow(3, oklch(0% 0 0 / 0.15), 135deg);
|
|
396
|
+
* }
|
|
392
397
|
*/
|
|
393
398
|
|
|
394
399
|
@function --shadow(
|
|
395
400
|
--level <number>,
|
|
396
|
-
--color <color>: oklch(0% 0 0 / 0.1)
|
|
401
|
+
--color <color>: oklch(0% 0 0 / 0.1),
|
|
402
|
+
--angle <angle>: 90deg
|
|
403
|
+
) {
|
|
404
|
+
--distance: calc(var(--level) * 2px);
|
|
405
|
+
--x: calc(var(--distance) * cos(var(--angle)));
|
|
406
|
+
--y: calc(var(--distance) * sin(var(--angle)));
|
|
407
|
+
--blur: calc(var(--level) * 4px);
|
|
408
|
+
--spread: calc(var(--level) * -1px);
|
|
409
|
+
result:
|
|
410
|
+
var(--x) var(--y) var(--blur) var(--spread) var(--color),
|
|
411
|
+
calc(var(--x) * 0.5) calc(var(--y) * 0.5) calc(var(--blur) * 0.5) calc(var(--spread) * 0.5) var(--color);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* --bevel() — Inset Elevation Shadows
|
|
416
|
+
*
|
|
417
|
+
* Generates layered inset box-shadows for embossed/debossed effects based on level (1-5).
|
|
418
|
+
* Creates a recessed appearance ideal for pressed buttons, input fields, and sunken UI elements.
|
|
419
|
+
* Optionally control light source direction with angle parameter.
|
|
420
|
+
*
|
|
421
|
+
* @param {number} --level - Elevation level (1-5)
|
|
422
|
+
* @param {color} --color - Shadow color, default: oklch(0% 0 0 / 0.1)
|
|
423
|
+
* @param {angle} --angle - Light source direction angle, default: 90deg (lit from bottom)
|
|
424
|
+
* @returns {string} - Layered inset box-shadow value (comma-separated shadow list)
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* .pressed-button {
|
|
428
|
+
* box-shadow: --bevel(2);
|
|
429
|
+
* }
|
|
430
|
+
* .input-field {
|
|
431
|
+
* box-shadow: --bevel(1, oklch(0% 0 0 / 0.08));
|
|
432
|
+
* }
|
|
433
|
+
* .lit-from-top {
|
|
434
|
+
* box-shadow: --bevel(2, oklch(0% 0 0 / 0.1), 270deg);
|
|
435
|
+
* }
|
|
436
|
+
*/
|
|
437
|
+
|
|
438
|
+
@function --bevel(
|
|
439
|
+
--level <number>,
|
|
440
|
+
--color <color>: oklch(0% 0 0 / 0.1),
|
|
441
|
+
--angle <angle>: 90deg
|
|
397
442
|
) {
|
|
398
|
-
--
|
|
443
|
+
--distance: calc(var(--level) * 2px);
|
|
444
|
+
--x: calc(var(--distance) * cos(var(--angle)));
|
|
445
|
+
--y: calc(var(--distance) * sin(var(--angle)));
|
|
399
446
|
--blur: calc(var(--level) * 4px);
|
|
400
447
|
--spread: calc(var(--level) * -1px);
|
|
401
448
|
result:
|
|
402
|
-
|
|
403
|
-
0 calc(var(--y) * 0.5) calc(var(--blur) * 0.5) calc(var(--spread) * 0.5) var(--color);
|
|
449
|
+
inset var(--x) var(--y) var(--blur) var(--spread) var(--color),
|
|
450
|
+
inset calc(var(--x) * 0.5) calc(var(--y) * 0.5) calc(var(--blur) * 0.5) calc(var(--spread) * 0.5) var(--color);
|
|
404
451
|
}
|
|
405
452
|
|
|
406
453
|
/**
|
|
@@ -462,30 +509,6 @@
|
|
|
462
509
|
|
|
463
510
|
/* Layout Utilities */
|
|
464
511
|
|
|
465
|
-
/**
|
|
466
|
-
* --z() — Z-Index Scale
|
|
467
|
-
*
|
|
468
|
-
* Named z-index layers to avoid magic numbers and conflicts.
|
|
469
|
-
*
|
|
470
|
-
* Layer reference:
|
|
471
|
-
* 1: dropdown, 2: sticky, 3: fixed,
|
|
472
|
-
* 4: drawer, 5: modal, 6: popover,
|
|
473
|
-
* 7: tooltip, 8: toast, 9: max
|
|
474
|
-
*
|
|
475
|
-
* @param {number} --layer - Layer number (1-9)
|
|
476
|
-
* @returns {integer} - Z-index value (layer × 100)
|
|
477
|
-
*
|
|
478
|
-
* @example
|
|
479
|
-
* .dropdown { z-index: --z(1); }
|
|
480
|
-
* .header { z-index: --z(3); }
|
|
481
|
-
* .modal { z-index: --z(5); }
|
|
482
|
-
* .tooltip { z-index: --z(7); }
|
|
483
|
-
*/
|
|
484
|
-
|
|
485
|
-
@function --z(--layer <number>) returns <integer> {
|
|
486
|
-
result: calc(var(--layer) * 100);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
512
|
/**
|
|
490
513
|
* --neg() — Negative Value
|
|
491
514
|
*
|
package/dist/index.min.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CSS Utility Functions v1.
|
|
2
|
+
* CSS Utility Functions v1.1.1
|
|
3
3
|
* Author: Yair Even-Or
|
|
4
4
|
* Repository: https://github.com/yairEO/css-utility-functions
|
|
5
5
|
*
|
|
@@ -37,14 +37,19 @@
|
|
|
37
37
|
--ratio-h <number>: 9
|
|
38
38
|
) returns <length>{result:calc(var(--width) * var(--ratio-h) / var(--ratio-w))}@function --shadow(
|
|
39
39
|
--level <number>,
|
|
40
|
-
--color <color>: oklch(0% 0 0 / 0.1)
|
|
41
|
-
|
|
40
|
+
--color <color>: oklch(0% 0 0 / 0.1),
|
|
41
|
+
--angle <angle>: 90deg
|
|
42
|
+
){--distance:calc(var(--level) * 2px);--x:calc(var(--distance) * cos(var(--angle)));--y:calc(var(--distance) * sin(var(--angle)));--blur:calc(var(--level) * 4px);--spread:calc(var(--level) * -1px);result:var(--x) var(--y) var(--blur) var(--spread) var(--color),calc(var(--x) * .5) calc(var(--y) * .5) calc(var(--blur) * .5) calc(var(--spread) * .5) var(--color)}@function --bevel(
|
|
43
|
+
--level <number>,
|
|
44
|
+
--color <color>: oklch(0% 0 0 / 0.1),
|
|
45
|
+
--angle <angle>: 90deg
|
|
46
|
+
){--distance:calc(var(--level) * 2px);--x:calc(var(--distance) * cos(var(--angle)));--y:calc(var(--distance) * sin(var(--angle)));--blur:calc(var(--level) * 4px);--spread:calc(var(--level) * -1px);result:inset var(--x) var(--y) var(--blur) var(--spread) var(--color),inset calc(var(--x) * .5) calc(var(--y) * .5) calc(var(--blur) * .5) calc(var(--spread) * .5) var(--color)}@function --diagonal-lines(
|
|
42
47
|
--angle <angle>: -45deg,
|
|
43
48
|
--line-color <color>: currentColor,
|
|
44
49
|
--line-width <length>: 1px,
|
|
45
50
|
--gap-width <length>: 4px,
|
|
46
51
|
--gap-color <color>: transparent
|
|
47
|
-
) returns <image>{result:repeating-linear-gradient(var(--angle),var(--line-color) 0,var(--line-color) calc(var(--line-width) - 1px),var(--gap-color) calc(var(--line-width) + 1px),var(--gap-color) calc(var(--line-width) + var(--gap-width)))}@function --
|
|
52
|
+
) returns <image>{result:repeating-linear-gradient(var(--angle),var(--line-color) 0,var(--line-color) calc(var(--line-width) - 1px),var(--gap-color) calc(var(--line-width) + 1px),var(--gap-color) calc(var(--line-width) + var(--gap-width)))}@function --neg(--value <length>) returns <length>{result:calc(var(--value) * -1)}@function --lerp(
|
|
48
53
|
--a <length-percentage>,
|
|
49
54
|
--b <length-percentage>,
|
|
50
55
|
--t <number>: 0.5
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-utility-functions",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A collection of reusable CSS custom native functions using the @function syntax",
|
|
5
5
|
"main": "dist/index.css",
|
|
6
6
|
"style": "dist/index.css",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"build:min": "postcss src/index.css -o dist/index.min.css --env production && node add-header.js dist/index.min.css && cp dist/index.min.css docs/index.min.css",
|
|
15
15
|
"build:html": "node build-html.js",
|
|
16
16
|
"build:all": "npm run build:html && npm run build && npm run build:min",
|
|
17
|
-
"watch": "nodemon --watch src --ext css --exec \"npm run build\"",
|
|
17
|
+
"watch": "nodemon --watch src --ext css --exec \"npm run build && npm run build:min\"",
|
|
18
18
|
"watch:html": "node build-html.js --watch",
|
|
19
19
|
"dev": "concurrently \"npm run watch:html\" \"npm run watch\"",
|
|
20
20
|
"prebuild": "npm run build:html",
|
|
21
|
-
"
|
|
21
|
+
"version": "npm run build:all"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"css",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --bevel() — Inset Elevation Shadows
|
|
3
|
+
*
|
|
4
|
+
* Generates layered inset box-shadows for embossed/debossed effects based on level (1-5).
|
|
5
|
+
* Creates a recessed appearance ideal for pressed buttons, input fields, and sunken UI elements.
|
|
6
|
+
* Optionally control light source direction with angle parameter.
|
|
7
|
+
*
|
|
8
|
+
* @param {number} --level - Elevation level (1-5)
|
|
9
|
+
* @param {color} --color - Shadow color, default: oklch(0% 0 0 / 0.1)
|
|
10
|
+
* @param {angle} --angle - Light source direction angle, default: 90deg (lit from bottom)
|
|
11
|
+
* @returns {string} - Layered inset box-shadow value (comma-separated shadow list)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* .pressed-button {
|
|
15
|
+
* box-shadow: --bevel(2);
|
|
16
|
+
* }
|
|
17
|
+
* .input-field {
|
|
18
|
+
* box-shadow: --bevel(1, oklch(0% 0 0 / 0.08));
|
|
19
|
+
* }
|
|
20
|
+
* .lit-from-top {
|
|
21
|
+
* box-shadow: --bevel(2, oklch(0% 0 0 / 0.1), 270deg);
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
@function --bevel(
|
|
26
|
+
--level <number>,
|
|
27
|
+
--color <color>: oklch(0% 0 0 / 0.1),
|
|
28
|
+
--angle <angle>: 90deg
|
|
29
|
+
) {
|
|
30
|
+
--distance: calc(var(--level) * 2px);
|
|
31
|
+
--x: calc(var(--distance) * cos(var(--angle)));
|
|
32
|
+
--y: calc(var(--distance) * sin(var(--angle)));
|
|
33
|
+
--blur: calc(var(--level) * 4px);
|
|
34
|
+
--spread: calc(var(--level) * -1px);
|
|
35
|
+
result:
|
|
36
|
+
inset var(--x) var(--y) var(--blur) var(--spread) var(--color),
|
|
37
|
+
inset calc(var(--x) * 0.5) calc(var(--y) * 0.5) calc(var(--blur) * 0.5) calc(var(--spread) * 0.5) var(--color);
|
|
38
|
+
}
|
package/src/effects/shadow.css
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* --shadow() — Elevation Shadows
|
|
3
3
|
*
|
|
4
4
|
* Generates layered box-shadows based on elevation level (1-5).
|
|
5
|
+
* Optionally control shadow direction with angle parameter.
|
|
5
6
|
*
|
|
6
7
|
* @param {number} --level - Elevation level (1-5)
|
|
7
8
|
* @param {color} --color - Shadow color, default: oklch(0% 0 0 / 0.1)
|
|
9
|
+
* @param {angle} --angle - Shadow direction angle, default: 90deg (downward)
|
|
8
10
|
* @returns {string} - Layered box-shadow value (comma-separated shadow list)
|
|
9
11
|
*
|
|
10
12
|
* @example
|
|
@@ -14,17 +16,23 @@
|
|
|
14
16
|
* .modal {
|
|
15
17
|
* box-shadow: --shadow(5, oklch(0% 0 0 / 0.25));
|
|
16
18
|
* }
|
|
19
|
+
* .lit-from-top-right {
|
|
20
|
+
* box-shadow: --shadow(3, oklch(0% 0 0 / 0.15), 135deg);
|
|
21
|
+
* }
|
|
17
22
|
*/
|
|
18
23
|
|
|
19
24
|
@function --shadow(
|
|
20
25
|
--level <number>,
|
|
21
|
-
--color <color>: oklch(0% 0 0 / 0.1)
|
|
26
|
+
--color <color>: oklch(0% 0 0 / 0.1),
|
|
27
|
+
--angle <angle>: 90deg
|
|
22
28
|
) {
|
|
23
|
-
--
|
|
29
|
+
--distance: calc(var(--level) * 2px);
|
|
30
|
+
--x: calc(var(--distance) * cos(var(--angle)));
|
|
31
|
+
--y: calc(var(--distance) * sin(var(--angle)));
|
|
24
32
|
--blur: calc(var(--level) * 4px);
|
|
25
33
|
--spread: calc(var(--level) * -1px);
|
|
26
34
|
result:
|
|
27
|
-
|
|
28
|
-
0 calc(var(--y) * 0.5) calc(var(--blur) * 0.5) calc(var(--spread) * 0.5) var(--color);
|
|
35
|
+
var(--x) var(--y) var(--blur) var(--spread) var(--color),
|
|
36
|
+
calc(var(--x) * 0.5) calc(var(--y) * 0.5) calc(var(--blur) * 0.5) calc(var(--spread) * 0.5) var(--color);
|
|
29
37
|
}
|
|
30
38
|
|
package/src/index.css
CHANGED
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
|
|
29
29
|
/* Visual Effects */
|
|
30
30
|
@import './effects/shadow.css';
|
|
31
|
+
@import './effects/bevel.css';
|
|
31
32
|
@import './effects/diagonal-lines.css';
|
|
32
33
|
|
|
33
34
|
/* Layout Utilities */
|
|
34
|
-
@import './layout/z-index.css';
|
|
35
35
|
@import './layout/neg.css';
|
|
36
36
|
|
|
37
37
|
/* Math Utilities */
|
package/src/layout/z-index.css
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* --z() — Z-Index Scale
|
|
3
|
-
*
|
|
4
|
-
* Named z-index layers to avoid magic numbers and conflicts.
|
|
5
|
-
*
|
|
6
|
-
* Layer reference:
|
|
7
|
-
* 1: dropdown, 2: sticky, 3: fixed,
|
|
8
|
-
* 4: drawer, 5: modal, 6: popover,
|
|
9
|
-
* 7: tooltip, 8: toast, 9: max
|
|
10
|
-
*
|
|
11
|
-
* @param {number} --layer - Layer number (1-9)
|
|
12
|
-
* @returns {integer} - Z-index value (layer × 100)
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* .dropdown { z-index: --z(1); }
|
|
16
|
-
* .header { z-index: --z(3); }
|
|
17
|
-
* .modal { z-index: --z(5); }
|
|
18
|
-
* .tooltip { z-index: --z(7); }
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
@function --z(--layer <number>) returns <integer> {
|
|
22
|
-
result: calc(var(--layer) * 100);
|
|
23
|
-
}
|
|
24
|
-
|