-
Notifications
You must be signed in to change notification settings - Fork 1
/
_sass-inherit.scss
56 lines (53 loc) · 1.51 KB
/
_sass-inherit.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// * css-inherit-fn/_sass-inherit.scss
// * BSD 2-Clause License
// * Copyright (c) Jane Ori, PropJockey, 2022
@mixin buildDepthSelector($evenOdd, $sel, $maxDepth) {
$full: "";
$selX: $sel;
$i: 1;
@if $evenOdd == "even" {
$selX: $selX + " " + $sel;
$i: 2;
}
@while $i <= $maxDepth {
$full: $full + $selX + ":not(";
$selX: $selX + " " + $sel;
$full: $full + $selX + "), ";
$selX: $selX + " " + $sel;
$i: $i + 2;
}
:where(#{$full}) {
@content
}
}
@mixin __inheritchainswap($ioA, $ioB, $assignments) {
$arglen: length($assignments);
$i: 1;
@while $i <= $arglen {
$assignment: nth($assignments, $i);
$index: str-index($assignment, ":");
$var: str-slice($assignment, 1, $index - 1);
$val: str-slice($assignment, $index + 1, -1);
@if str-slice($val, 1, 1) == " " {
$val: str-slice($val, 2, -1);
}
$index: str-index($val, "inherit(--");
@while $index {
$before: str-slice($val, 1, $index - 1);
$after: str-slice($val, $index + 10, -1);
$val: $before + "var(--" + $ioA + $after;
$index: str-index($val, "inherit(--");
}
#{$var}: unquote($val);
#{str-insert($var, $ioB, 3)}: var(unquote($var));
$i: $i + 1;
}
}
@mixin buildInherit($sel, $maxDepth, $assignments...) {
@include buildDepthSelector("odd", $sel, $maxDepth) {
@include __inheritchainswap("io1_", "io2_", $assignments);
}
@include buildDepthSelector("even", $sel, $maxDepth) {
@include __inheritchainswap("io2_", "io1_", $assignments);
}
}