-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_less-inherit.less
57 lines (54 loc) · 1.6 KB
/
_less-inherit.less
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
57
// * css-inherit-fn/_less-inherit.less
// * BSD 2-Clause License
// * Copyright (c) Jane Ori, PropJockey, 2022
.buildDepthSelector(
@evenOdd, @sel, @maxDepth, @i: 1,
@full: ~"", @selX: @sel, @comma: ~""
) when (@i <= @maxDepth) {
.buildDepthSelector(
~"", @sel, @maxDepth, (@i + 2),
"@{full}@{comma}@{selX}:not(@{selX} @{sel})",
"@{selX} @{sel} @{sel}", ", "
);
}
.buildDepthSelector(
@evenOdd, @sel, @maxDepth, @i: 1,
@full: ~"", @selX: ~"", @comma: ~""
) when (@evenOdd = "even") {
@selX: "@{sel} @{sel}";
@i: 2;
.buildDepthSelector(
~"", @sel, @maxDepth, (@i + 2),
"@{full}@{comma}@{selX}:not(@{selX} @{sel})",
"@{selX} @{sel} @{sel}", ", "
);
}
.buildDepthSelector(
@evenOdd, @sel, @maxDepth, @i: 1,
@full: ~"", @selX: ~"", @comma: ~""
) when (@i > @maxDepth) {
@escaped: e(@full);
@result: :where(@escaped);
}
.__inheritchainswap(@ioA, @ioB, @assignments) {
@argLen: length(@assignments);
each(range(1, @argLen, 1), {
@assignment: extract(@assignments, @value);
@var: e(replace(@assignment, "([^:]+):.*", "$1"));
@val: replace(@assignment, "[^:]+:\s*(.*)", "$1");
@inheritVal: replace(@val, "inherit\(--", "var(--@{ioA}", "g");
@{var}: e(@inheritVal);
@outVar: replace(@var, "--", "--@{ioB}", "");
@{outVar}: var(e(@var));
});
}
.buildInherit(@sel, @maxDepth, @assignments...) {
@odd: .buildDepthSelector("odd", @sel, @maxDepth)[@result];
@evn: .buildDepthSelector("even", @sel, @maxDepth)[@result];
@{odd} {
.__inheritchainswap("io1_", "io2_", @assignments);
}
@{evn} {
.__inheritchainswap("io2_", "io1_", @assignments);
}
}