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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --xnor() — Exclusive NOR Operation (NOT XOR)
|
|
3
|
+
*
|
|
4
|
+
* Returns 1 if both operands are the same, otherwise returns 0.
|
|
5
|
+
* The opposite of XOR - checks for equality.
|
|
6
|
+
*
|
|
7
|
+
* Truth table:
|
|
8
|
+
* - 0 XNOR 0 = 1 (both same)
|
|
9
|
+
* - 0 XNOR 1 = 0 (different)
|
|
10
|
+
* - 1 XNOR 0 = 0 (different)
|
|
11
|
+
* - 1 XNOR 1 = 1 (both same)
|
|
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
|
+
* .sync-indicator {
|
|
19
|
+
* --local-state: 1;
|
|
20
|
+
* --remote-state: 1;
|
|
21
|
+
* opacity: --xnor(var(--local-state), var(--remote-state));
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @see https://css-tricks.com/logical-operations-with-css-variables/
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
@function --xnor(--a <number>, --b <number>) returns <number> {
|
|
28
|
+
result: calc(1 - (var(--a) - var(--b)) * (var(--a) - var(--b)));
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --xor() — Exclusive OR Operation
|
|
3
|
+
*
|
|
4
|
+
* Returns 1 if exactly one operand is 1, otherwise returns 0.
|
|
5
|
+
* Uses subtraction squared to get absolute value: (a - b)²
|
|
6
|
+
*
|
|
7
|
+
* Truth table:
|
|
8
|
+
* - 0 XOR 0 = 0 (both same)
|
|
9
|
+
* - 0 XOR 1 = 1 (different)
|
|
10
|
+
* - 1 XOR 0 = 1 (different)
|
|
11
|
+
* - 1 XOR 1 = 0 (both same)
|
|
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
|
+
* .highlight-when-different {
|
|
19
|
+
* --user-theme: 1;
|
|
20
|
+
* --system-theme: 0;
|
|
21
|
+
* opacity: --xor(var(--user-theme), var(--system-theme));
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @see https://css-tricks.com/logical-operations-with-css-variables/
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
@function --xor(--a <number>, --b <number>) returns <number> {
|
|
28
|
+
result: calc((var(--a) - var(--b)) * (var(--a) - var(--b)));
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --circle-x() — Circle X Position
|
|
3
|
+
*
|
|
4
|
+
* Calculate X coordinate on a circle using radius and angle.
|
|
5
|
+
* Uses cosine: r * cos(deg)
|
|
6
|
+
*
|
|
7
|
+
* @param {length} --radius - Circle radius
|
|
8
|
+
* @param {angle} --angle - Angle in degrees, default: 0deg
|
|
9
|
+
* @returns {length} - X coordinate offset from center
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* .orbit {
|
|
13
|
+
* left: calc(50% + --circle-x(100px, 45deg)); // 45° position
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
@function --circle-x(
|
|
18
|
+
--radius <length>,
|
|
19
|
+
--angle <angle>: 0deg
|
|
20
|
+
) returns <length> {
|
|
21
|
+
result: calc(var(--radius) * cos(var(--angle)));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* --circle-y() — Circle Y Position
|
|
26
|
+
*
|
|
27
|
+
* Calculate Y coordinate on a circle using radius and angle.
|
|
28
|
+
* Uses sine: r * sin(deg)
|
|
29
|
+
*
|
|
30
|
+
* @param {length} --radius - Circle radius
|
|
31
|
+
* @param {angle} --angle - Angle in degrees, default: 0deg
|
|
32
|
+
* @returns {length} - Y coordinate offset from center
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* .orbit {
|
|
36
|
+
* top: calc(50% + --circle-y(100px, 45deg)); // 45° position
|
|
37
|
+
* }
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
@function --circle-y(
|
|
41
|
+
--radius <length>,
|
|
42
|
+
--angle <angle>: 0deg
|
|
43
|
+
) returns <length> {
|
|
44
|
+
result: calc(var(--radius) * sin(var(--angle)));
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --lerp() — Linear Interpolation
|
|
3
|
+
*
|
|
4
|
+
* Interpolates between two values using a t parameter (0-1).
|
|
5
|
+
* When t=0, returns a; when t=1, returns b; when t=0.5, returns midpoint.
|
|
6
|
+
* Hides the complex calc expression: calc(a + (b - a) * t)
|
|
7
|
+
*
|
|
8
|
+
* @param {length-percentage} --a - Start value
|
|
9
|
+
* @param {length-percentage} --b - End value
|
|
10
|
+
* @param {number} --t - Interpolation factor (0-1), default: 0.5
|
|
11
|
+
* @returns {length-percentage} - Interpolated value
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* .animated {
|
|
15
|
+
* width: --lerp(100px, 500px, 0.3); // 30% between 100px and 500px
|
|
16
|
+
* }
|
|
17
|
+
* .transition {
|
|
18
|
+
* width: --lerp(10%, 80%, 0.75); // 75% between 10% and 80%
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
@function --lerp(
|
|
23
|
+
--a <length-percentage>,
|
|
24
|
+
--b <length-percentage>,
|
|
25
|
+
--t <number>: 0.5
|
|
26
|
+
) returns <length-percentage> {
|
|
27
|
+
result: calc(var(--a) * (1 - var(--t)) + var(--b) * var(--t));
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --modular() — Modular Scale (Typographic Scale)
|
|
3
|
+
*
|
|
4
|
+
* Calculate values using a modular scale (typographic ratio).
|
|
5
|
+
* Hides the pow calculation: base * pow(ratio, step)
|
|
6
|
+
*
|
|
7
|
+
* @param {number} --step - Scale step (can be negative for smaller values)
|
|
8
|
+
* @param {length|number} --base - Base value, default: 1rem
|
|
9
|
+
* @param {number} --ratio - Scale ratio, default: 1.25 (major third)
|
|
10
|
+
* @returns {length|number} - Scaled value
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* :root {
|
|
14
|
+
* --type-base: 1rem;
|
|
15
|
+
* --type-ratio: 1.25;
|
|
16
|
+
* }
|
|
17
|
+
* h1 {
|
|
18
|
+
* font-size: --modular(4, var(--type-base), var(--type-ratio)); // Large scale
|
|
19
|
+
* }
|
|
20
|
+
* small {
|
|
21
|
+
* font-size: --modular(-1, var(--type-base), var(--type-ratio)); // Smaller
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
@function --modular(
|
|
26
|
+
--step <number>,
|
|
27
|
+
--base <length|number>: 1rem,
|
|
28
|
+
--ratio <number>: 1.25
|
|
29
|
+
) returns <length|number> {
|
|
30
|
+
result: calc(var(--base) * pow(var(--ratio), var(--step)));
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --poly-angle() — Polygon Vertex Angle
|
|
3
|
+
*
|
|
4
|
+
* Calculate the angle for a vertex in a regular polygon.
|
|
5
|
+
* Useful for creating polygon shapes with CSS transforms.
|
|
6
|
+
* Formula: (360deg / sides * index) - 90deg
|
|
7
|
+
*
|
|
8
|
+
* @param {number} --sides - Number of sides in polygon
|
|
9
|
+
* @param {number} --index - Vertex index (0-based), default: 0
|
|
10
|
+
* @returns {angle} - Angle in degrees
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* .hexagon-vertex-0 {
|
|
14
|
+
* transform: rotate(--poly-angle(6, 0)); // First vertex of hexagon
|
|
15
|
+
* }
|
|
16
|
+
* .pentagon-vertex-2 {
|
|
17
|
+
* transform: rotate(--poly-angle(5, 2)); // Third vertex of pentagon
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
@function --poly-angle(
|
|
22
|
+
--sides <number>,
|
|
23
|
+
--index <number>: 0
|
|
24
|
+
) returns <angle> {
|
|
25
|
+
result: calc(360deg / var(--sides) * var(--index) - 90deg);
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --fluid() — Fluid Viewport-Based Sizing
|
|
3
|
+
*
|
|
4
|
+
* Generates a clamp() value that scales smoothly between viewport widths.
|
|
5
|
+
* Use this for global, viewport-dependent responsive sizing.
|
|
6
|
+
*
|
|
7
|
+
* @param {length} --min - Minimum size
|
|
8
|
+
* @param {length} --max - Maximum size
|
|
9
|
+
* @param {length} --min-vw - Minimum viewport width, default: 375px
|
|
10
|
+
* @param {length} --max-vw - Maximum viewport width, default: 1440px
|
|
11
|
+
* @returns {length} - Fluid clamp value based on viewport width
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* h1 {
|
|
15
|
+
* font-size: --fluid(1.5rem, 4rem);
|
|
16
|
+
* }
|
|
17
|
+
* .container {
|
|
18
|
+
* padding: --fluid(1rem, 3rem, 320px, 1200px);
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* @see --fluid-container() for container-based fluid sizing
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
@function --fluid(
|
|
25
|
+
--min <length>,
|
|
26
|
+
--max <length>,
|
|
27
|
+
--min-vw <length>: 375px,
|
|
28
|
+
--max-vw <length>: 1440px
|
|
29
|
+
) returns <length> {
|
|
30
|
+
--slope: calc((var(--max) - var(--min)) / (var(--max-vw) - var(--min-vw)));
|
|
31
|
+
--intercept: calc(var(--min) - var(--slope) * var(--min-vw));
|
|
32
|
+
result: clamp(var(--min), calc(var(--intercept) + var(--slope) * 100vw), var(--max));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* --fluid-container() — Fluid Container-Based Sizing
|
|
37
|
+
*
|
|
38
|
+
* Generates a clamp() value that scales smoothly based on container width.
|
|
39
|
+
* Requires the parent element to have container-type: inline-size or container: name / inline-size.
|
|
40
|
+
* Perfect for component-level responsive design independent of viewport size.
|
|
41
|
+
*
|
|
42
|
+
* @param {length} --min - Minimum size
|
|
43
|
+
* @param {length} --max - Maximum size
|
|
44
|
+
* @param {length} --min-cqw - Minimum container width, default: 20ch
|
|
45
|
+
* @param {length} --max-cqw - Maximum container width, default: 65ch
|
|
46
|
+
* @returns {length} - Fluid clamp value based on container width
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* .card {
|
|
50
|
+
* container-type: inline-size;
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* .card h2 {
|
|
54
|
+
* font-size: --fluid-container(1rem, 2rem);
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* .card p {
|
|
58
|
+
* font-size: --fluid-container(0.875rem, 1.125rem, 30ch, 60ch);
|
|
59
|
+
* }
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
@function --fluid-container(
|
|
63
|
+
--min <length>,
|
|
64
|
+
--max <length>,
|
|
65
|
+
--min-cqw <length>: 20ch,
|
|
66
|
+
--max-cqw <length>: 65ch
|
|
67
|
+
) returns <length> {
|
|
68
|
+
--slope: calc((var(--max) - var(--min)) / (var(--max-cqw) - var(--min-cqw)));
|
|
69
|
+
--intercept: calc(var(--min) - var(--slope) * var(--min-cqw));
|
|
70
|
+
result: clamp(var(--min), calc(var(--intercept) + var(--slope) * 100cqw), var(--max));
|
|
71
|
+
}
|
|
72
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --ratio-height() — Aspect Ratio Height
|
|
3
|
+
*
|
|
4
|
+
* Calculate height from width and aspect ratio (useful for images/containers).
|
|
5
|
+
*
|
|
6
|
+
* @param {length} --width - Element width
|
|
7
|
+
* @param {number} --ratio-w - Ratio width part, default: 16
|
|
8
|
+
* @param {number} --ratio-h - Ratio height part, default: 9
|
|
9
|
+
* @returns {length} - Calculated height
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* .video-thumb {
|
|
13
|
+
* width: 320px;
|
|
14
|
+
* height: --ratio-height(320px, 16, 9);
|
|
15
|
+
* }
|
|
16
|
+
* .square-avatar {
|
|
17
|
+
* width: 48px;
|
|
18
|
+
* height: --ratio-height(48px, 1, 1);
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
@function --ratio-height(
|
|
23
|
+
--width <length>,
|
|
24
|
+
--ratio-w <number>: 16,
|
|
25
|
+
--ratio-h <number>: 9
|
|
26
|
+
) returns <length> {
|
|
27
|
+
result: calc(var(--width) * var(--ratio-h) / var(--ratio-w));
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --space() — Spacing Scale
|
|
3
|
+
*
|
|
4
|
+
* Returns spacing based on a consistent multiplier scale.
|
|
5
|
+
* The base unit can be customized via the --space-base CSS custom property.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} --multiplier - Scale multiplier
|
|
8
|
+
* @param {length} --base - Base spacing unit, default: var(--space-base, 0.25rem)
|
|
9
|
+
* @returns {length} - Calculated spacing
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* :root {
|
|
13
|
+
* --space-base: 0.25rem;
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* .card {
|
|
17
|
+
* padding: --space(4);
|
|
18
|
+
* margin-bottom: --space(6);
|
|
19
|
+
* gap: --space(2);
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* .special {
|
|
23
|
+
* padding: --space(4, 0.5rem);
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
@function --space(--multiplier <number>, --base <length>: var(--space-base, 0.25rem)) returns <length> {
|
|
28
|
+
result: calc(var(--base) * var(--multiplier));
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --to-px() — REM to Pixel Conversion
|
|
3
|
+
*
|
|
4
|
+
* Convert a rem value to pixels (assumes 16px base).
|
|
5
|
+
*
|
|
6
|
+
* @param {number} --rem - REM value (unitless)
|
|
7
|
+
* @returns {length} - Pixel value
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* .legacy-system {
|
|
11
|
+
* width: --to-px(10);
|
|
12
|
+
* height: --to-px(5);
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
@function --to-px(--rem <number>) returns <length> {
|
|
17
|
+
result: calc(var(--rem) * 16 * 1px);
|
|
18
|
+
}
|
|
19
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --to-rem() — Pixel to REM Conversion
|
|
3
|
+
*
|
|
4
|
+
* Convert a pixel value to rem units. Base pixel size defaults to --rem-base (or 16px).
|
|
5
|
+
*
|
|
6
|
+
* @param {number} --px - Pixel value (unitless)
|
|
7
|
+
* @param {number} --base - Base pixel size for conversion, defaults to var(--rem-base, 16)
|
|
8
|
+
* @returns {length} - REM value
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* .legacy-compat {
|
|
12
|
+
* font-size: --to-rem(18);
|
|
13
|
+
* padding: --to-rem(24);
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* .custom-base {
|
|
17
|
+
* font-size: --to-rem(18, 10);
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* :root {
|
|
21
|
+
* --rem-base: 20;
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
@function --to-rem(--px <number>, --base <number>: var(--rem-base, 16)) returns <length> {
|
|
26
|
+
result: calc(var(--px) * 1rem / var(--base));
|
|
27
|
+
}
|
|
28
|
+
|