@@ -19335,8 +19335,8 @@ mod tests {
1933519335 );
1933619336
1933719337 // Supplementary testing
19338- // TODO: 目前的 calc 不支持除数为 0,导致 alpha / 0 报错,而 alpha / 1 可以通过。
19339- // 依赖: https://github.com/parcel-bundler/lightningcss/pull/1122
19338+ // TODO: calc does not support division by zero yet, so ` alpha / 0` fails while ` alpha / 1` works.
19339+ // Depends on: https://github.com/parcel-bundler/lightningcss/pull/1122
1934019340 // test(
1934119341 // "alpha(from green / calc(alpha / 0))",
1934219342 // "rgb(0, 128, 0)",
@@ -19390,6 +19390,7 @@ mod tests {
1939019390 // Supplementary testing
1939119391 // nested alpha() precision.
1939219392 test("alpha(from alpha(from red / 0.5) / calc(alpha + 0.25))", "#ff0000bf");
19393+ test("alpha(from alpha(from red / -0.5) / calc(alpha + 0.6))", "#f009");
1939319394 test("alpha(from alpha(from green / 0%) / 100%)", "green");
1939419395
1939519396 // Unresolved relative colors keep their tokens.
@@ -19432,9 +19433,33 @@ mod tests {
1943219433 "color(from alpha(from color(display-p3 1 0 0) / 0.5) display-p3 r g b / alpha)",
1943319434 "color(display-p3 1 0 0 / 0.5)",
1943419435 );
19436+ test(
19437+ "color(from alpha(from red / 1.5) srgb r g b / calc(alpha - 0.2))",
19438+ "color(srgb 1 0 0 / 0.8)", // alpha = 1 - 0.2
19439+ );
19440+
19441+ // Test in image()
19442+ minify_test(
19443+ ".foo { mask: image(alpha(from red / 1))}",
19444+ ".foo{mask:image(red)}",
19445+ );
19446+
19447+ // Test in linear-gradient()
19448+ minify_test(
19449+ ".foo { mask: linear-gradient(90deg, alpha(from red / 0%), red) }",
19450+ ".foo{mask:linear-gradient(90deg,#f000,red)}",
19451+ );
19452+ // Compare relative color
19453+ // TODO: Support <color-interpolation-method>
19454+ minify_test(
19455+ ".foo { mask: linear-gradient(90deg in hsl longer hue, rgb(from red r g b / 0), red) }",
19456+ ".foo{mask:linear-gradient(90deg in hsl longer hue, #f000, red)}",
19457+ );
19458+ minify_test(
19459+ ".foo { mask: linear-gradient(90deg in hsl longer hue, alpha(from red / 0%), red) }",
19460+ ".foo{mask:linear-gradient(90deg in hsl longer hue, #f000, red)}",
19461+ );
1943519462
19436- // TODO:添加一个带有 fallback 的输出,需要设置浏览器为较旧的版本
19437- // 最终输出:.foo{color:#ff0f0e;color:color(display-p3 1 0 0)}
1943819463 minify_test(
1943919464 ".foo { color: alpha(from color(display-p3 1 0 0) / 0.5) }",
1944019465 ".foo{color:color(display-p3 1 0 0/.5)}",
@@ -21217,6 +21242,36 @@ mod tests {
2121721242 }
2121821243 }
2121921244
21245+ #[test]
21246+ fn test_relative_alpha_color_fallbacks() {
21247+ prefix_test(
21248+ ".foo { color: alpha(from color(srgb 1 0 0) / 0.5) }",
21249+ indoc! { r#"
21250+ .foo {
21251+ color: #ff000080;
21252+ color: color(srgb 1 0 0 / .5);
21253+ }
21254+ "#},
21255+ Browsers {
21256+ chrome: Some(90 << 16),
21257+ ..Browsers::default()
21258+ },
21259+ );
21260+ prefix_test(
21261+ ".foo { color: alpha(from color(display-p3 1 0 0) / 0.5) }",
21262+ indoc! { r#"
21263+ .foo {
21264+ color: #ff0f0e80;
21265+ color: color(display-p3 1 0 0 / .5);
21266+ }
21267+ "#},
21268+ Browsers {
21269+ chrome: Some(90 << 16),
21270+ ..Browsers::default()
21271+ },
21272+ );
21273+ }
21274+
2122021275 #[test]
2122121276 fn test_color_mix() {
2122221277 minify_test(
0 commit comments