-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path_operators.less
85 lines (78 loc) · 3 KB
/
_operators.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// The .op() mixin calls its @content callback iff the
// specified logical operation evaluates to true. The
// input parameters (@first and @second) can either be
// selectors to combine (typically :checked selectors)
// or detached rulesets containing further .op() calls
// to chain.
// To pass a .op() call, use the following syntax:
// { .c(@c) { .op(@c, blah, xor, blah); } }
// We need this complexity to pass @invertCombinator &
// @content from the outer call; see
// https://github.com/less/less.js/issues/2558
// This overload is called by the outermost operation,
// as opposed to operations passed as detached ruleset
// parameters. It calls the actual overloads with the
// default @invertCombinator and the explicitly-passed
// @content parameter
.op(@first, @operation, @second, @content) when (@operation = and), (@operation = xor), (@operation = or) {
.op(normal @content, @first, @operation, @second); // Pass @content via scope
}
.op(@c, @first, @operation, @second) when (length(@c) > 1) {
.op(@first, @operation, @second, extract(@c, 1), extract(@c, 2));
}
@tilde: ~'~ ';
// These overloads are called in detached rulesets when chaining
.op(@first, xor, @second, normal, @content) {
.callSelector(@first, invert, { @{tilde} {
.callSelector(@second, normal, @content);
}});
.callSelector(@first, normal, { @{tilde} {
.callSelector(@second, invert, @content);
}});
}
.op(@first, xor, @second, invert, @content) {
.callSelector(@first, invert, { @{tilde} {
.callSelector(@second, invert, @content);
}});
.callSelector(@first, normal, { @{tilde} {
.callSelector(@second, normal, @content);
}});
}
.op(@first, or, @second, normal, @content) {
.callSelector(@first, normal, @content);
.callSelector(@second, normal, @content);
}
.op(@first, or, @second, invert, @content) {
.callSelector(@first, invert, { @{tilde} {
.callSelector(@second, invert, @content);
}});
}
.op(@first, and, @second, normal, @content) {
.callSelector(@first, normal, { @{tilde} {
.callSelector(@second, normal, @content);
}});
}
.op(@first, and, @second, invert, @content) {
.callSelector(@first, invert, @content);
.callSelector(@second, invert, @content);
}
// Calls a selector (as a string or a nested ruleset),
// passing a context for inversion and target content.
// This should only be used for .op() chaining.
// The @mode, @content parameters ought to be a single
// list, but http://github.com/less/less.js/issues/2587
.callSelector(@selector, @mode, @content) when (isKeyword(@selector)) {
.callSelector(%(~'#%s', @selector), @mode, @content);
}
.callSelector(@selector, @mode, @content) when (isString(@selector)) {
&@{selector}:checked when(@mode = normal) { @content(); }
&@{selector}:not(:checked) when(@mode = invert) { @content(); }
}
.callSelector(@selector, @mode, @content) when (default()) { // isruleset(@selector) doesn't work
@selector();
.c(@mode @content);
}
// Expand the @c parameter pack for direct calls.
.callSelector(@selector, @c) {
.callSelector(@selector, extract(@c, 1), extract(@c, 2));
}