1- let { equal } = require ( 'node:assert' )
1+ let { equal, throws } = require ( 'node:assert/strict ' )
22let { test } = require ( 'node:test' )
33let postcss = require ( 'postcss' )
44
@@ -11,6 +11,79 @@ function run(input, output, opts) {
1111 return result
1212}
1313
14- test ( 'exists' , ( ) => {
15- run ( '' , '' )
14+ test ( 'replaces --smooth-shadow with layered box shadows' , ( ) => {
15+ run (
16+ '.card { box-shadow: --smooth-shadow(#000, 10px, 2); }' ,
17+ '.card { box-shadow: 0 calc(10px / 2) calc(10px / 2 * 2) rgb(from #000 r g b / 0.25), 0 calc(10px / 2 * 2) calc(10px / 2 * 3) rgb(from #000 r g b / 0.18), 0 calc(10px / 2 * 3) calc(10px / 2 * 4) rgb(from #000 r g b / 0.12); }'
18+ )
19+ } )
20+
21+ test ( 'handles CSS variables as parameters' , ( ) => {
22+ run (
23+ '.element { box-shadow: --smooth-shadow(var(--shadow-color), var(--shadow-size), var(--shadow-spread)); }' ,
24+ '.element { box-shadow: 0 calc(var(--shadow-size) / var(--shadow-spread)) calc(var(--shadow-size) / var(--shadow-spread) * 2) rgb(from var(--shadow-color) r g b / 0.25), 0 calc(var(--shadow-size) / var(--shadow-spread) * 2) calc(var(--shadow-size) / var(--shadow-spread) * 3) rgb(from var(--shadow-color) r g b / 0.18), 0 calc(var(--shadow-size) / var(--shadow-spread) * 3) calc(var(--shadow-size) / var(--shadow-spread) * 4) rgb(from var(--shadow-color) r g b / 0.12); }'
25+ )
26+ } )
27+
28+ test ( 'uses default spread value of 3 when omitted' , ( ) => {
29+ run (
30+ '.card { box-shadow: --smooth-shadow(#000, 12px); }' ,
31+ '.card { box-shadow: 0 calc(12px / 3) calc(12px / 3 * 2) rgb(from #000 r g b / 0.25), 0 calc(12px / 3 * 2) calc(12px / 3 * 3) rgb(from #000 r g b / 0.18), 0 calc(12px / 3 * 3) calc(12px / 3 * 4) rgb(from #000 r g b / 0.12); }'
32+ )
33+ } )
34+
35+ test ( 'handles mix of two and three parameter calls' , ( ) => {
36+ run (
37+ '.mixed { box-shadow: --smooth-shadow(#000, 6px), --smooth-shadow(#fff, 4px, 2); }' ,
38+ '.mixed { box-shadow: 0 calc(6px / 3) calc(6px / 3 * 2) rgb(from #000 r g b / 0.25), 0 calc(6px / 3 * 2) calc(6px / 3 * 3) rgb(from #000 r g b / 0.18), 0 calc(6px / 3 * 3) calc(6px / 3 * 4) rgb(from #000 r g b / 0.12), 0 calc(4px / 2) calc(4px / 2 * 2) rgb(from #fff r g b / 0.25), 0 calc(4px / 2 * 2) calc(4px / 2 * 3) rgb(from #fff r g b / 0.18), 0 calc(4px / 2 * 3) calc(4px / 2 * 4) rgb(from #fff r g b / 0.12); }'
39+ )
40+ } )
41+
42+ test ( 'handles multiple --smooth-shadow calls in same declaration' , ( ) => {
43+ run (
44+ '.card { box-shadow: --smooth-shadow(#000, 5px, 1), inset --smooth-shadow(#fff, 2px, 1); }' ,
45+ '.card { box-shadow: 0 calc(5px / 1) calc(5px / 1 * 2) rgb(from #000 r g b / 0.25), 0 calc(5px / 1 * 2) calc(5px / 1 * 3) rgb(from #000 r g b / 0.18), 0 calc(5px / 1 * 3) calc(5px / 1 * 4) rgb(from #000 r g b / 0.12), inset 0 calc(2px / 1) calc(2px / 1 * 2) rgb(from #fff r g b / 0.25), 0 calc(2px / 1 * 2) calc(2px / 1 * 3) rgb(from #fff r g b / 0.18), 0 calc(2px / 1 * 3) calc(2px / 1 * 4) rgb(from #fff r g b / 0.12); }'
46+ )
47+ } )
48+
49+ test ( 'works with different color formats' , ( ) => {
50+ run (
51+ '.test { box-shadow: --smooth-shadow(rgb(255, 0, 0), 8px, 2); }' ,
52+ '.test { box-shadow: 0 calc(8px / 2) calc(8px / 2 * 2) rgb(from rgb(255, 0, 0) r g b / 0.25), 0 calc(8px / 2 * 2) calc(8px / 2 * 3) rgb(from rgb(255, 0, 0) r g b / 0.18), 0 calc(8px / 2 * 3) calc(8px / 2 * 4) rgb(from rgb(255, 0, 0) r g b / 0.12); }'
53+ )
54+ } )
55+
56+ test ( 'handles decimal values' , ( ) => {
57+ run (
58+ '.button { box-shadow: --smooth-shadow(#333, 4.5px, 1.5); }' ,
59+ '.button { box-shadow: 0 calc(4.5px / 1.5) calc(4.5px / 1.5 * 2) rgb(from #333 r g b / 0.25), 0 calc(4.5px / 1.5 * 2) calc(4.5px / 1.5 * 3) rgb(from #333 r g b / 0.18), 0 calc(4.5px / 1.5 * 3) calc(4.5px / 1.5 * 4) rgb(from #333 r g b / 0.12); }'
60+ )
61+ } )
62+
63+ test ( 'leaves other declarations unchanged' , ( ) => {
64+ run (
65+ '.normal { color: red; background: blue; }' ,
66+ '.normal { color: red; background: blue; }'
67+ )
68+ } )
69+
70+ test ( 'works in other properties besides box-shadow' , ( ) => {
71+ run (
72+ '.custom { filter: drop-shadow(--smooth-shadow(#000, 3px, 1)); }' ,
73+ '.custom { filter: drop-shadow(0 calc(3px / 1) calc(3px / 1 * 2) rgb(from #000 r g b / 0.25), 0 calc(3px / 1 * 2) calc(3px / 1 * 3) rgb(from #000 r g b / 0.18), 0 calc(3px / 1 * 3) calc(3px / 1 * 4) rgb(from #000 r g b / 0.12)); }'
74+ )
75+ } )
76+
77+ test ( 'throws error for insufficient parameters' , ( ) => {
78+ let input = '.error { box-shadow: --smooth-shadow(#000); }'
79+ throws ( ( ) => {
80+ postcss ( [ plugin ] ) . process ( input , { from : undefined } ) . css
81+ } , '--smooth-shadow() requires 2 or 3 parameters' )
82+ } )
83+
84+ test ( 'throws error for too many parameters' , ( ) => {
85+ let input = '.error { box-shadow: --smooth-shadow(#000, 10px, 2, extra); }'
86+ throws ( ( ) => {
87+ postcss ( [ plugin ] ) . process ( input , { from : undefined } ) . css
88+ } , '--smooth-shadow() requires 2 or 3 parameters' )
1689} )
0 commit comments