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.
@@ -0,0 +1,28 @@
1
+ @function --alpha(--color <color>, --opacity <number>: 0.5) returns <color>{result:oklch(from var(--color) l c h/var(--opacity))}@function --lighten(--color <color>, --amount <number>: 0.1) returns <color>{result:oklch(from var(--color) calc(l + var(--amount)) c h)}@function --darken(--color <color>, --amount <number>: 0.1) returns <color>{result:oklch(from var(--color) calc(l - var(--amount)) c h)}@function --saturate(
2
+ --color <color>,
3
+ --amount <number>: 0.2
4
+ ) returns <color>{result:oklch(from var(--color) l calc(c + c * var(--amount)) h)}@function --desaturate(
5
+ --color <color>,
6
+ --amount <number>: 0.2
7
+ ) returns <color>{result:oklch(from var(--color) l calc(c - c * var(--amount)) h)}@function --mix(
8
+ --color1 <color>,
9
+ --color2 <color>,
10
+ --weight <percentage>: 50%
11
+ ) returns <color>{result:color-mix(in oklch,var(--color1) var(--weight),var(--color2))}@function --contrast-text(--bg <color>) returns <color>{result:oklch(from var(--bg) calc((.6 - l) * infinity) 0 0)}@function --space(--multiplier <number>, --base <length>: var(--space-base, 0.25rem)) returns <length>{result:calc(var(--base) * var(--multiplier))}@function --fluid(
12
+ --min <length>,
13
+ --max <length>,
14
+ --min-vw <length>: 375px,
15
+ --max-vw <length>: 1440px
16
+ ) returns <length>{--slope:calc((var(--max) - var(--min)) / (var(--max-vw) - var(--min-vw)));--intercept:calc(var(--min) - var(--slope) * var(--min-vw));result:clamp(var(--min),calc(var(--intercept) + var(--slope) * 100vw),var(--max))}@function --fluid-container(
17
+ --min <length>,
18
+ --max <length>,
19
+ --min-cqw <length>: 20ch,
20
+ --max-cqw <length>: 65ch
21
+ ) returns <length>{--slope:calc((var(--max) - var(--min)) / (var(--max-cqw) - var(--min-cqw)));--intercept:calc(var(--min) - var(--slope) * var(--min-cqw));result:clamp(var(--min),calc(var(--intercept) + var(--slope) * 100cqw),var(--max))}@function --ratio-height(
22
+ --width <length>,
23
+ --ratio-w <number>: 16,
24
+ --ratio-h <number>: 9
25
+ ) returns <length>{result:calc(var(--width) * var(--ratio-h) / var(--ratio-w))}@function --shadow(
26
+ --level <number>,
27
+ --color <color>: oklch(0% 0 0 / 0.1)
28
+ ){--y:calc(var(--level) * 2px);--blur:calc(var(--level) * 4px);--spread:calc(var(--level) * -1px);result:0 var(--y) var(--blur) var(--spread) var(--color),0 calc(var(--y) * .5) calc(var(--blur) * .5) calc(var(--spread) * .5) var(--color)}@function --z(--layer <number>) returns <integer>{result:calc(var(--layer) * 100)}@function --neg(--value <length>) returns <length>{result:calc(var(--value) * -1)}@function --to-rem(--px <number>, --base <number>: var(--rem-base, 16)) returns <length>{result:calc(var(--px) * 1rem / var(--base))}@function --to-px(--rem <number>) returns <length>{result:calc(var(--rem) * 16 * 1px)}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "css-utility-functions",
3
+ "version": "1.0.1",
4
+ "description": "A collection of reusable CSS custom native functions using the @function syntax",
5
+ "main": "dist/index.css",
6
+ "style": "dist/index.css",
7
+ "files": [
8
+ "dist/**/*.css",
9
+ "src/**/*.css",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "build": "postcss src/index.css -o dist/index.css",
14
+ "build:min": "postcss src/index.css -o dist/index.min.css --env production",
15
+ "build:html": "node build-html.js",
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\"",
18
+ "watch:html": "node build-html.js --watch",
19
+ "dev": "concurrently \"npm run watch:html\" \"npm run watch\"",
20
+ "prebuild": "npm run build:html"
21
+ },
22
+ "keywords": [
23
+ "css",
24
+ "css-functions",
25
+ "utility",
26
+ "design-system",
27
+ "css-custom-functions",
28
+ "@function"
29
+ ],
30
+ "author": "Yair Even-Or <vsync.design@gmail.com>",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/yairEO/css-utility-functions.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/yaireo/css-utility-functions/issues"
38
+ },
39
+ "devDependencies": {
40
+ "postcss-cli": "^11.0.0",
41
+ "postcss-import": "^16.1.0",
42
+ "cssnano": "^7.1.2",
43
+ "concurrently": "^9.2.1",
44
+ "nodemon": "^3.1.0"
45
+ }
46
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * --alpha() — Color Transparency
3
+ *
4
+ * Creates a semi-transparent version of any color.
5
+ * Works exactly like CSS opacity property:
6
+ * - 0 = fully transparent (invisible)
7
+ * - 1 = fully opaque (solid)
8
+ * - 0.5 = 50% opaque (50% transparent)
9
+ *
10
+ * @param {color} --color - The base color
11
+ * @param {number} --opacity - Opacity level (0-1), default: 0.5
12
+ * Higher values = more opaque, lower values = more transparent
13
+ * @returns {color} - Color with applied opacity
14
+ *
15
+ * @example
16
+ * .overlay {
17
+ * background: --alpha(#6366f1, 0.2); // 20% opaque, 80% transparent
18
+ * }
19
+ * .backdrop {
20
+ * background: --alpha(var(--brand), 0.85); // 85% opaque, 15% transparent
21
+ * }
22
+ */
23
+
24
+ @function --alpha(--color <color>, --opacity <number>: 0.5) returns <color> {
25
+ result: oklch(from var(--color) l c h / var(--opacity));
26
+ }
27
+
@@ -0,0 +1,23 @@
1
+ /**
2
+ * --complement() — Complementary Color
3
+ *
4
+ * Get the complementary color (opposite on color wheel) by rotating hue 180 degrees.
5
+ * Uses OKLCH color space for accurate hue rotation.
6
+ * Note: Achromatic colors (grays) have no hue, so their complement is unchanged.
7
+ *
8
+ * @param {color} --color - The base color
9
+ * @returns {color} - Complementary color
10
+ *
11
+ * @example
12
+ * .accent {
13
+ * background: --complement(#6366f1); // Blue's complement (orange)
14
+ * }
15
+ * .contrast-border {
16
+ * border-color: --complement(var(--primary));
17
+ * }
18
+ */
19
+
20
+ @function --complement(--color <color>) returns <color> {
21
+ result: oklch(from var(--color) l c calc(h + 180));
22
+ }
23
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ * --contrast-text() — Auto Contrast Text Color
3
+ *
4
+ * Returns black or white depending on background luminance for optimal readability.
5
+ * Uses a mathematical approach with OKLCH lightness.
6
+ *
7
+ * @param {color} --bg - Background color
8
+ * @returns {color} - Black or white based on luminance
9
+ *
10
+ * @example
11
+ * .badge {
12
+ * background: var(--badge-color);
13
+ * color: --contrast-text(var(--badge-color));
14
+ * }
15
+ */
16
+
17
+ @function --contrast-text(--bg <color>) returns <color> {
18
+ result: oklch(from var(--bg) calc((0.6 - l) * infinity) 0 0);
19
+ }
20
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ * --darken() — Color Luminance Decrease
3
+ *
4
+ * Adjust a color's lightness downward.
5
+ * Uses OKLCH lightness channel (0-1 range).
6
+ *
7
+ * @param {color} --color - The base color
8
+ * @param {number} --amount - Amount to darken (0-1, e.g., 0.1 = 10%, 0.2 = 20%), default: 0.1
9
+ * @returns {color} - Darkened color
10
+ *
11
+ * @example
12
+ * .btn:active {
13
+ * background: --darken(var(--btn-bg), 0.1);
14
+ * }
15
+ */
16
+
17
+ @function --darken(--color <color>, --amount <number>: 0.1) returns <color> {
18
+ result: oklch(from var(--color) calc(l - var(--amount)) c h);
19
+ }
20
+
@@ -0,0 +1,22 @@
1
+ /**
2
+ * --desaturate() — Color Saturation Decrease
3
+ *
4
+ * Adjust a color's chroma (saturation) intensity downward.
5
+ *
6
+ * @param {color} --color - The base color
7
+ * @param {number} --amount - Percentage as decimal (e.g., 0.5 = 50%), default: 0.2
8
+ * @returns {color} - Less saturated (more muted) color
9
+ *
10
+ * @example
11
+ * .muted {
12
+ * color: --desaturate(var(--text), 0.5);
13
+ * }
14
+ */
15
+
16
+ @function --desaturate(
17
+ --color <color>,
18
+ --amount <number>: 0.2
19
+ ) returns <color> {
20
+ result: oklch(from var(--color) l calc(c - c * var(--amount)) h);
21
+ }
22
+
@@ -0,0 +1,22 @@
1
+ /**
2
+ * --grayscale() — Grayscale Conversion
3
+ *
4
+ * Convert any color to grayscale by removing chroma (saturation).
5
+ * Uses OKLCH color space, setting chroma to 0 while preserving lightness.
6
+ *
7
+ * @param {color} --color - The base color
8
+ * @returns {color} - Grayscale version of the color
9
+ *
10
+ * @example
11
+ * .monochrome {
12
+ * background: --grayscale(#6366f1); // Blue becomes gray
13
+ * }
14
+ * .desaturated-image {
15
+ * filter: --grayscale(var(--image-color));
16
+ * }
17
+ */
18
+
19
+ @function --grayscale(--color <color>) returns <color> {
20
+ result: oklch(from var(--color) l 0 h);
21
+ }
22
+
@@ -0,0 +1,22 @@
1
+ /**
2
+ * --invert() — Color Inversion
3
+ *
4
+ * Invert a color by flipping its lightness in OKLCH space.
5
+ * Dark colors become light, light colors become dark.
6
+ *
7
+ * @param {color} --color - The base color
8
+ * @returns {color} - Inverted color
9
+ *
10
+ * @example
11
+ * .inverted {
12
+ * background: --invert(#ffffff); // White becomes black
13
+ * }
14
+ * .dark-mode-text {
15
+ * color: --invert(var(--light-text));
16
+ * }
17
+ */
18
+
19
+ @function --invert(--color <color>) returns <color> {
20
+ result: oklch(from var(--color) calc(1 - l) c h);
21
+ }
22
+
@@ -0,0 +1,20 @@
1
+ /**
2
+ * --lighten() — Color Luminance Increase
3
+ *
4
+ * Adjust a color's lightness upward.
5
+ * Uses OKLCH lightness channel (0-1 range).
6
+ *
7
+ * @param {color} --color - The base color
8
+ * @param {number} --amount - Amount to lighten (0-1, e.g., 0.1 = 10%, 0.2 = 20%), default: 0.1
9
+ * @returns {color} - Lightened color
10
+ *
11
+ * @example
12
+ * .btn:hover {
13
+ * background: --lighten(var(--btn-bg), 0.15);
14
+ * }
15
+ */
16
+
17
+ @function --lighten(--color <color>, --amount <number>: 0.1) returns <color> {
18
+ result: oklch(from var(--color) calc(l + var(--amount)) c h);
19
+ }
20
+
@@ -0,0 +1,27 @@
1
+ /**
2
+ * --mix() — Color Mixing
3
+ *
4
+ * Blend two colors by a given percentage.
5
+ *
6
+ * @param {color} --color1 - First color
7
+ * @param {color} --color2 - Second color
8
+ * @param {percentage} --weight - Weight of first color, default: 50%
9
+ * @returns {color} - Mixed color
10
+ *
11
+ * @example
12
+ * .gradient-mid {
13
+ * background: --mix(var(--start), var(--end), 50%);
14
+ * }
15
+ * .tinted {
16
+ * background: --mix(white, var(--brand), 90%);
17
+ * }
18
+ */
19
+
20
+ @function --mix(
21
+ --color1 <color>,
22
+ --color2 <color>,
23
+ --weight <percentage>: 50%
24
+ ) returns <color> {
25
+ result: color-mix(in oklch, var(--color1) var(--weight), var(--color2));
26
+ }
27
+
@@ -0,0 +1,22 @@
1
+ /**
2
+ * --saturate() — Color Saturation Increase
3
+ *
4
+ * Adjust a color's chroma (saturation) intensity upward.
5
+ *
6
+ * @param {color} --color - The base color
7
+ * @param {number} --amount - Percentage as decimal (e.g., 0.4 = 40%), default: 0.2
8
+ * @returns {color} - More saturated color
9
+ *
10
+ * @example
11
+ * .vibrant {
12
+ * background: --saturate(var(--primary), 0.4);
13
+ * }
14
+ */
15
+
16
+ @function --saturate(
17
+ --color <color>,
18
+ --amount <number>: 0.2
19
+ ) returns <color> {
20
+ result: oklch(from var(--color) l calc(c + c * var(--amount)) h);
21
+ }
22
+
@@ -0,0 +1,58 @@
1
+ /**
2
+ * --diagonal-lines() — Diagonal Line Pattern Background
3
+ *
4
+ * Generate a repeating diagonal line pattern with configurable angle, colors, and spacing.
5
+ * Returns a complete repeating-linear-gradient that can be used directly as a background value.
6
+ *
7
+ * @param {angle} --angle - Angle of the lines, default: -45deg
8
+ * @param {color} --line-color - Color of the lines, default: currentColor
9
+ * @param {length} --line-width - Width of each line, default: 1px
10
+ * @param {length} --gap-width - Width of the gap between lines, default: 4px
11
+ * @param {color} --gap-color - Color of the gap (background), default: transparent
12
+ * @returns {image} - Complete repeating-linear-gradient value
13
+ *
14
+ * Related - https://stackoverflow.com/questions/33091401/background-image-linear-gradient-jagged-edged-result-needs-to-be-smooth-edged
15
+ *
16
+ * @example
17
+ * .bg-diagonal {
18
+ * background: --diagonal-lines();
19
+ * }
20
+ *
21
+ * @example
22
+ * .custom-stripes {
23
+ * background: --diagonal-lines(
24
+ * --angle: 45deg,
25
+ * --line-color: #3b82f6,
26
+ * --line-width: 2px,
27
+ * --gap-width: 8px
28
+ * );
29
+ * }
30
+ *
31
+ * @example
32
+ * .subtle-pattern {
33
+ * color: #94a3b8;
34
+ * background: --diagonal-lines(
35
+ * --line-color: currentColor,
36
+ * --line-width: 1px,
37
+ * --gap-width: 10px
38
+ * );
39
+ * }
40
+ */
41
+
42
+ @function --diagonal-lines(
43
+ --angle <angle>: -45deg,
44
+ --line-color <color>: currentColor,
45
+ --line-width <length>: 1px,
46
+ --gap-width <length>: 4px,
47
+ --gap-color <color>: transparent
48
+ ) returns <image> {
49
+ result: repeating-linear-gradient(
50
+ var(--angle),
51
+ var(--line-color) 0,
52
+ var(--line-color) calc(var(--line-width) - 1px),
53
+ var(--gap-color) calc(var(--line-width) + 1px),
54
+ var(--gap-color) calc(var(--line-width) + var(--gap-width))
55
+ );
56
+ }
57
+
58
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * --shadow() — Elevation Shadows
3
+ *
4
+ * Generates layered box-shadows based on elevation level (1-5).
5
+ *
6
+ * @param {number} --level - Elevation level (1-5)
7
+ * @param {color} --color - Shadow color, default: oklch(0% 0 0 / 0.1)
8
+ * @returns {string} - Layered box-shadow value (comma-separated shadow list)
9
+ *
10
+ * @example
11
+ * .card {
12
+ * box-shadow: --shadow(2);
13
+ * }
14
+ * .modal {
15
+ * box-shadow: --shadow(5, oklch(0% 0 0 / 0.25));
16
+ * }
17
+ */
18
+
19
+ @function --shadow(
20
+ --level <number>,
21
+ --color <color>: oklch(0% 0 0 / 0.1)
22
+ ) {
23
+ --y: calc(var(--level) * 2px);
24
+ --blur: calc(var(--level) * 4px);
25
+ --spread: calc(var(--level) * -1px);
26
+ result:
27
+ 0 var(--y) var(--blur) var(--spread) var(--color),
28
+ 0 calc(var(--y) * 0.5) calc(var(--blur) * 0.5) calc(var(--spread) * 0.5) var(--color);
29
+ }
30
+
package/src/index.css ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * CSS Utility Functions
3
+ *
4
+ * A collection of reusable CSS custom functions using the @function syntax.
5
+ * Import this file to use all utility functions in your project.
6
+ *
7
+ * ⚠️ Note: CSS @function is experimental. Check browser support before production use.
8
+ *
9
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@function
10
+ */
11
+
12
+ /* Color Utilities */
13
+ @import './colors/alpha.css';
14
+ @import './colors/lighten.css';
15
+ @import './colors/darken.css';
16
+ @import './colors/saturate.css';
17
+ @import './colors/desaturate.css';
18
+ @import './colors/mix.css';
19
+ @import './colors/contrast-text.css';
20
+ @import './colors/grayscale.css';
21
+ @import './colors/invert.css';
22
+ @import './colors/complement.css';
23
+
24
+ /* Spacing & Sizing */
25
+ @import './spacing/space.css';
26
+ @import './spacing/fluid.css';
27
+ @import './spacing/ratio-height.css';
28
+
29
+ /* Visual Effects */
30
+ @import './effects/shadow.css';
31
+ @import './effects/diagonal-lines.css';
32
+
33
+ /* Layout Utilities */
34
+ @import './layout/z-index.css';
35
+ @import './layout/neg.css';
36
+
37
+ /* Math Utilities */
38
+ @import './math/lerp.css';
39
+ @import './math/circle.css';
40
+ @import './math/modular.css';
41
+ @import './math/poly-angle.css';
42
+
43
+ /* Unit Conversion */
44
+ @import './units/to-rem.css';
45
+ @import './units/to-px.css';
46
+
47
+ /* Logic Operations */
48
+ @import './logic/not.css';
49
+ @import './logic/and.css';
50
+ @import './logic/or.css';
51
+ @import './logic/xor.css';
52
+ @import './logic/nand.css';
53
+ @import './logic/nor.css';
54
+ @import './logic/xnor.css';
55
+
@@ -0,0 +1,21 @@
1
+ /**
2
+ * --neg() — Negative Value
3
+ *
4
+ * Simple negation — useful in calc-heavy layouts.
5
+ *
6
+ * @param {length} --value - Value to negate
7
+ * @returns {length} - Negative value
8
+ *
9
+ * @example
10
+ * .pull-up {
11
+ * margin-top: --neg(var(--header-height));
12
+ * }
13
+ * .bleed {
14
+ * margin-inline: --neg(var(--container-padding));
15
+ * }
16
+ */
17
+
18
+ @function --neg(--value <length>) returns <length> {
19
+ result: calc(var(--value) * -1);
20
+ }
21
+
@@ -0,0 +1,24 @@
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
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * --and() — Logical AND Operation
3
+ *
4
+ * Returns 1 if both operands are 1, otherwise returns 0.
5
+ * Uses multiplication since any value multiplied by 0 equals 0.
6
+ *
7
+ * Truth table:
8
+ * - 0 AND 0 = 0
9
+ * - 0 AND 1 = 0
10
+ * - 1 AND 0 = 0
11
+ * - 1 AND 1 = 1
12
+ *
13
+ * @param {number} --a - First switch variable (0 or 1)
14
+ * @param {number} --b - Second switch variable (0 or 1)
15
+ * @returns {number} - Result (0 or 1)
16
+ *
17
+ * @example
18
+ * .visible-on-mobile-and-dark {
19
+ * --is-mobile: 1;
20
+ * --is-dark-mode: 1;
21
+ * display: --and(var(--is-mobile), var(--is-dark-mode));
22
+ * }
23
+ *
24
+ * @see https://css-tricks.com/logical-operations-with-css-variables/
25
+ */
26
+
27
+ @function --and(--a <number>, --b <number>) returns <number> {
28
+ result: calc(var(--a) * var(--b));
29
+ }
30
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * --nand() — Logical NAND Operation (NOT AND)
3
+ *
4
+ * Returns 0 if both operands are 1, otherwise returns 1.
5
+ * Combination of NOT and AND operations.
6
+ *
7
+ * Truth table:
8
+ * - 0 NAND 0 = 1
9
+ * - 0 NAND 1 = 1
10
+ * - 1 NAND 0 = 1
11
+ * - 1 NAND 1 = 0
12
+ *
13
+ * @param {number} --a - First switch variable (0 or 1)
14
+ * @param {number} --b - Second switch variable (0 or 1)
15
+ * @returns {number} - Result (0 or 1)
16
+ *
17
+ * @example
18
+ * .hide-when-both-active {
19
+ * --feature-a: 1;
20
+ * --feature-b: 1;
21
+ * display: --nand(var(--feature-a), var(--feature-b));
22
+ * }
23
+ *
24
+ * @see https://css-tricks.com/logical-operations-with-css-variables/
25
+ */
26
+
27
+ @function --nand(--a <number>, --b <number>) returns <number> {
28
+ result: calc(1 - var(--a) * var(--b));
29
+ }
30
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * --nor() — Logical NOR Operation (NOT OR)
3
+ *
4
+ * Returns 1 if both operands are 0, otherwise returns 0.
5
+ * Combination of NOT and OR operations.
6
+ *
7
+ * Truth table:
8
+ * - 0 NOR 0 = 1
9
+ * - 0 NOR 1 = 0
10
+ * - 1 NOR 0 = 0
11
+ * - 1 NOR 1 = 0
12
+ *
13
+ * @param {number} --a - First switch variable (0 or 1)
14
+ * @param {number} --b - Second switch variable (0 or 1)
15
+ * @returns {number} - Result (0 or 1)
16
+ *
17
+ * @example
18
+ * .show-default-state {
19
+ * --has-custom-bg: 0;
20
+ * --has-custom-text: 0;
21
+ * opacity: --nor(var(--has-custom-bg), var(--has-custom-text));
22
+ * }
23
+ *
24
+ * @see https://css-tricks.com/logical-operations-with-css-variables/
25
+ */
26
+
27
+ @function --nor(--a <number>, --b <number>) returns <number> {
28
+ result: calc((1 - var(--a)) * (1 - var(--b)));
29
+ }
30
+
@@ -0,0 +1,23 @@
1
+ /**
2
+ * --not() — Boolean Negation
3
+ *
4
+ * Inverts a boolean value (switch variable). Works with values 0 and 1.
5
+ * Returns 1 if input is 0, returns 0 if input is 1.
6
+ *
7
+ * @param {number} --value - Switch variable (0 or 1)
8
+ * @returns {number} - Inverted value (0 or 1)
9
+ *
10
+ * @example
11
+ * .toggle {
12
+ * --is-active: 1;
13
+ * --is-inactive: --not(var(--is-active)); // 0
14
+ * opacity: --not(var(--is-hidden));
15
+ * }
16
+ *
17
+ * @see https://css-tricks.com/logical-operations-with-css-variables/
18
+ */
19
+
20
+ @function --not(--value <number>) returns <number> {
21
+ result: calc(1 - var(--value));
22
+ }
23
+
@@ -0,0 +1,30 @@
1
+ /**
2
+ * --or() — Logical OR Operation
3
+ *
4
+ * Returns 1 if at least one operand is 1, otherwise returns 0.
5
+ * Uses De Morgan's law: NOT (A OR B) = (NOT A) AND (NOT B)
6
+ *
7
+ * Truth table:
8
+ * - 0 OR 0 = 0
9
+ * - 0 OR 1 = 1
10
+ * - 1 OR 0 = 1
11
+ * - 1 OR 1 = 1
12
+ *
13
+ * @param {number} --a - First switch variable (0 or 1)
14
+ * @param {number} --b - Second switch variable (0 or 1)
15
+ * @returns {number} - Result (0 or 1)
16
+ *
17
+ * @example
18
+ * .show-on-mobile-or-tablet {
19
+ * --is-mobile: 0;
20
+ * --is-tablet: 1;
21
+ * display: --or(var(--is-mobile), var(--is-tablet));
22
+ * }
23
+ *
24
+ * @see https://css-tricks.com/logical-operations-with-css-variables/
25
+ */
26
+
27
+ @function --or(--a <number>, --b <number>) returns <number> {
28
+ result: calc(1 - (1 - var(--a)) * (1 - var(--b)));
29
+ }
30
+