|
25 | 25 | #e2b { |
26 | 26 | @apply --m2(navy); |
27 | 27 | } |
| 28 | + #e2c { |
| 29 | + color: fuchsia; |
| 30 | + @apply --m2(); |
| 31 | + } |
28 | 32 |
|
29 | 33 | @mixin --m3(--my-color) { |
30 | 34 | color: env(--my-color); |
|
47 | 51 | color: green; |
48 | 52 | @apply --m5(too-many-parameters); |
49 | 53 | } |
| 54 | + |
| 55 | + @mixin --m6(--my-color) { |
| 56 | + color: env(--my-color, navy); |
| 57 | + } |
| 58 | + #e6 { |
| 59 | + @apply --m6(green); |
| 60 | + } |
| 61 | + #e6b { |
| 62 | + @apply --m6; |
| 63 | + } |
| 64 | + #e6c { |
| 65 | + @apply --m6(invalid-color); |
| 66 | + } |
| 67 | + #e6d { |
| 68 | + color: env(--not-within-mixin, green); |
| 69 | + } |
| 70 | + #e6e { |
| 71 | + color: env(--not-within-mixin); |
| 72 | + } |
| 73 | + |
| 74 | + @mixin --m7(--my-color) { |
| 75 | + color: attr(color-attr type(<color>)); |
| 76 | + } |
| 77 | + #e7 { |
| 78 | + @apply --m7(green); |
| 79 | + } |
| 80 | + |
| 81 | + @mixin --m8(--my-length type(<length>)) { |
| 82 | + font-size: 10px; |
| 83 | + --some-length: env(--my-length); |
| 84 | + } |
| 85 | + #e8 { |
| 86 | + @apply --m8(1.0em); |
| 87 | + } |
| 88 | + |
| 89 | + @mixin --m9(--my-length type(length)) { /* Note the syntax error. */ |
| 90 | + font-size: 10px; |
| 91 | + --some-length: env(--my-length); |
| 92 | + } |
| 93 | + #e9 { |
| 94 | + @apply --m9(1.0em); |
| 95 | + } |
| 96 | + |
| 97 | + @mixin --m10inner(--inner-color) { |
| 98 | + color: env(--outer-color); |
| 99 | + } |
| 100 | + @mixin --m10outer(--outer-color) { |
| 101 | + @apply --m10inner(red); |
| 102 | + } |
| 103 | + #e10 { |
| 104 | + @apply --m10outer(green); |
| 105 | + } |
| 106 | + |
| 107 | + @mixin --m11(--val, --true, --false) { |
| 108 | + color: if(style(--x: env(--val)): env(--true); else: env(--false)) |
| 109 | + } |
| 110 | + #e11 { |
| 111 | + --x: a; |
| 112 | + @apply --m11(a, green, red); |
| 113 | + } |
| 114 | + #e11b { |
| 115 | + --x: a; |
| 116 | + @apply --m11(b, red, green); |
| 117 | + } |
| 118 | + |
| 119 | + @function --f() { |
| 120 | + color: env(--my-color); |
| 121 | + } |
| 122 | + @mixin --m12(--my-color) { |
| 123 | + color: --f(); |
| 124 | + } |
| 125 | + #e12 { |
| 126 | + @apply --m12(red); |
| 127 | + } |
| 128 | + } |
| 129 | + </style> |
50 | 130 | </style> |
51 | 131 | </head> |
52 | 132 | <body> |
53 | 133 | <div><div id="e1">This text should be green.</div></div> |
54 | 134 | <div><div id="e2">This text should be green.</div></div> |
55 | 135 | <div><div id="e2b">This text should be navy.</div></div> |
| 136 | + <div><div id="e2c">This text should be fuchsia.</div></div> |
56 | 137 | <div><div id="e3">This text should be green.</div></div> |
57 | 138 | <div><div id="e4">This text should be green.</div></div> |
58 | 139 | <div><div id="e5">This text should be green.</div></div> |
| 140 | + <div><div id="e6">This text should be green.</div></div> |
| 141 | + <div><div id="e6b">This text should be navy.</div></div> |
| 142 | + <div><div id="e6c">This text should be black.</div></div> |
| 143 | + <div><div id="e6d">This text should be green.</div></div> |
| 144 | + <div><div id="e6e">This text should be black.</div></div> |
| 145 | + <div><div id="e7" color-attr="env(--my-color)">This text should be green.</div></div> |
| 146 | + <div><div id="e8">This text does not matter.</div></div> |
| 147 | + <div><div id="e9">This text does not matter.</div></div> |
| 148 | + <div><div id="e10">This text should be green.</div></div> |
| 149 | + <div><div id="e11">This text should be green.</div></div> |
| 150 | + <div><div id="e11b">This text should be green.</div></div> |
| 151 | + <div><div id="e12">This text should be black.</div></div> |
59 | 152 | <script> |
60 | 153 | test(() => { |
61 | 154 | let target = document.getElementById('e1'); |
|
72 | 165 | assert_equals(getComputedStyle(target).color, 'rgb(0, 0, 128)'); |
73 | 166 | }, 'Mixins can be called multiple times with different parameters'); |
74 | 167 |
|
| 168 | + test(() => { |
| 169 | + let target = document.getElementById('e2c'); |
| 170 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 0, 0)'); |
| 171 | + }, 'Too few parameters and no default ignores mixin'); |
| 172 | + |
75 | 173 | test(() => { |
76 | 174 | let target = document.getElementById('e3'); |
77 | 175 | assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
|
86 | 184 | let target = document.getElementById('e5'); |
87 | 185 | assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
88 | 186 | }, '@apply with too many parameters is ignored'); |
| 187 | + |
| 188 | + test(() => { |
| 189 | + let target = document.getElementById('e6'); |
| 190 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
| 191 | + }, 'Fallback is ignored if argument is given'); |
| 192 | + |
| 193 | + test(() => { |
| 194 | + let target = document.getElementById('e6b'); |
| 195 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 0, 128)'); |
| 196 | + }, 'Fallback is used with no parameter and no default'); |
| 197 | + |
| 198 | + test(() => { |
| 199 | + let target = document.getElementById('e6c'); |
| 200 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 0, 0)'); |
| 201 | + }, 'Fallback is not used on other errors'); |
| 202 | + |
| 203 | + test(() => { |
| 204 | + let target = document.getElementById('e6d'); |
| 205 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
| 206 | + }, 'Fallback is not when outside mixin'); |
| 207 | + |
| 208 | + test(() => { |
| 209 | + let target = document.getElementById('e6e'); |
| 210 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 0, 0)'); |
| 211 | + }, 'Invalid when no fallback and outside mixin'); |
| 212 | + |
| 213 | + test(() => { |
| 214 | + let target = document.getElementById('e7'); |
| 215 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
| 216 | + }, 'env() can be accessed from attributes'); |
| 217 | + |
| 218 | + test(() => { |
| 219 | + let target = document.getElementById('e8'); |
| 220 | + assert_equals(getComputedStyle(target).getPropertyValue('--some-length'), '10px'); |
| 221 | + }, 'env() resolves typed parameters'); |
| 222 | + |
| 223 | + test(() => { |
| 224 | + let target = document.getElementById('e9'); |
| 225 | + assert_equals(getComputedStyle(target).getPropertyValue('--some-length'), ''); |
| 226 | + assert_equals(getComputedStyle(target).fontSize, '10px'); |
| 227 | + }, 'env() refuses illegal syntax parameters, but does not fail entire mixin'); |
| 228 | + |
| 229 | + test(() => { |
| 230 | + let target = document.getElementById('e10'); |
| 231 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
| 232 | + }, 'env() can access parameters from outer mixins'); |
| 233 | + |
| 234 | + test(() => { |
| 235 | + let target = document.getElementById('e11'); |
| 236 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
| 237 | + }, 'env() works inside if, in condition and true branch'); |
| 238 | + |
| 239 | + test(() => { |
| 240 | + let target = document.getElementById('e11b'); |
| 241 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 128, 0)'); |
| 242 | + }, 'env() works inside if, in condition and false branch'); |
| 243 | + |
| 244 | + test(() => { |
| 245 | + let target = document.getElementById('e12'); |
| 246 | + assert_equals(getComputedStyle(target).color, 'rgb(0, 0, 0)'); |
| 247 | + }, 'env() within a function should not see parameters from a calling mixin'); |
89 | 248 | </script> |
90 | 249 | </body> |
91 | 250 | </html> |
0 commit comments