c a l l e d - f r o m = ( )
v e n d o r s = m o z w e b k i t o m s o f f i c i a l
/ / s t r i n g if y t h e g i v e n a r g
-string ( a r g )
type ( a r g ) + ' ' + a r g
/ / r e q u i r e a color
require-color ( color )
unless color is a ' color '
error ( ' R G B or H S L v a l u e e x p e c t e d , g o t a ' + -string ( color ) )
/ / r e q u i r e a u n i t
require-unit ( n )
unless n is a ' u n i t '
error ( ' u n i t e x p e c t e d , g o t a ' + -string ( n ) )
/ / r e q u i r e a s t r i n g
require-string ( s t r )
unless s t r is a ' s t r i n g ' or s t r is a ' i d e n t '
error ( ' s t r i n g e x p e c t e d , g o t a ' + -string ( s t r ) )
/ / M a t h f u n c t i o n s
abs ( n ) { math ( n , ' a b s ' ) }
min ( a , b ) { a < b ? a : b }
max ( a , b ) { a > b ? a : b }
/ / T r i g o n o m e t r i c s
P I = -math-prop ( ' P I ' )
radians-to-degrees ( a n g l e )
a n g l e * ( 1 8 0 / P I )
degrees-to-radians ( a n g l e )
unit ( a n g l e * ( P I / 1 8 0 ) , ' ' )
sin ( n )
n = degrees-to-radians ( n ) if unit ( n ) == ' d e g '
round ( math ( n , ' s i n ' ) , 9 )
cos ( n )
n = degrees-to-radians ( n ) if unit ( n ) == ' d e g '
round ( math ( n , ' c o s ' ) , 9 )
/ / R o u n d i n g M a t h f u n c t i o n s
ceil ( n , p r e c i s i o n = 0 )
m u l t i p l i e r = 1 0 ** p r e c i s i o n
math ( n * m u l t i p l i e r , ' c e i l ' ) / m u l t i p l i e r
floor ( n , p r e c i s i o n = 0 )
m u l t i p l i e r = 1 0 ** p r e c i s i o n
math ( n * m u l t i p l i e r , ' f l o o r ' ) / m u l t i p l i e r
round ( n , p r e c i s i o n = 0 )
m u l t i p l i e r = 1 0 ** p r e c i s i o n
math ( n * m u l t i p l i e r , ' r o u n d ' ) / m u l t i p l i e r
/ / return t h e s u m o f t h e g i v e n n u m b e r s
sum ( n u m s )
s u m = 0
s u m + = n for n in n u m s
/ / return t h e a v e r a g e o f t h e g i v e n n u m b e r s
avg ( n u m s )
sum ( n u m s ) / length ( n u m s )
/ / return a u n i t l e s s n u m b e r , or p a s s t h r o u g h
remove-unit ( n )
if typeof ( n ) is " u n i t "
unit ( n , " " )
else
n
/ / c o n v e r t a p e r c e n t t o a d e c i m a l , or p a s s t h r o u g h
percent-to-decimal ( n )
if unit ( n ) is " % "
remove-unit ( n ) / 1 0 0
else
n
/ / c h e c k if n is a n o d d n u m b e r
odd ( n )
1 == n % 2
/ / c h e c k if n is a n e v e n n u m b e r
even ( n )
0 == n % 2
/ / c h e c k if color is l i g h t
light ( color )
lightness ( color ) >= 5 0 %
/ / c h e c k if color is d a r k
dark ( color )
lightness ( color ) < 5 0 %
/ / d e s a t u r a t e color b y a m o u n t
desaturate ( color , a m o u n t )
adjust ( color , ' s a t u r a t i o n ' , - a m o u n t )
/ / s a t u r a t e color b y a m o u n t
saturate ( color = ' ' , a m o u n t = 1 0 0 % )
if color is a ' color '
adjust ( color , ' s a t u r a t i o n ' , a m o u n t )
else
unquote ( " saturate ( " + color + " ) " )
/ / d a r k e n b y t h e g i v e n a m o u n t
darken ( color , a m o u n t )
adjust ( color , ' l i g h t n e s s ' , - a m o u n t )
/ / l i g h t e n b y t h e g i v e n a m o u n t
lighten ( color , a m o u n t )
adjust ( color , ' l i g h t n e s s ' , a m o u n t )
/ / d e c r e a s e opacity b y a m o u n t
fade-out ( color , a m o u n t )
color - rgba ( black , percent-to-decimal ( a m o u n t ) )
/ / i n c r e a s e opacity b y a m o u n t
fade-in ( color , a m o u n t )
color + rgba ( black , percent-to-decimal ( a m o u n t ) )
/ / s p i n h u e b y a g i v e n a m o u n t
spin ( color , a m o u n t )
color + unit ( a m o u n t , d e g )
/ / mix t w o c o l o r s b y a g i v e n a m o u n t
mix ( c o l o r 1 , c o l o r 2 , w e i g h t = 5 0 % )
unless w e i g h t in 0 . . 100
error ( " W e i g h t m u s t b e b e t w e e n 0 % and 1 0 0 % " )
if length ( c o l o r 1 ) == 2
w e i g h t = c o l o r 1 [ 0 ]
c o l o r 1 = c o l o r 1 [ 1 ]
else if length ( c o l o r 2 ) == 2
w e i g h t = 1 0 0 - c o l o r 2 [ 0 ]
c o l o r 2 = c o l o r 2 [ 1 ]
require-color ( c o l o r 1 )
require-color ( c o l o r 2 )
p = unit ( w e i g h t / 1 0 0 , ' ' )
w = p * 2 - 1
a = alpha ( c o l o r 1 ) - alpha ( c o l o r 2 )
w 1 = ( ( ( w * a == - 1 ) ? w : ( w + a ) / ( 1 + w * a ) ) + 1 ) / 2
w 2 = 1 - w 1
c h a n n e l s = ( red ( c o l o r 1 ) red ( c o l o r 2 ) ) ( green ( c o l o r 1 ) green ( c o l o r 2 ) ) ( blue ( c o l o r 1 ) blue ( c o l o r 2 ) )
r g b = ( )
for p a i r in c h a n n e l s
push ( r g b , floor ( p a i r [ 0 ] * w 1 + p a i r [ 1 ] * w 2 ) )
a 1 = alpha ( c o l o r 1 ) * p
a 2 = alpha ( c o l o r 2 ) * ( 1 - p )
a l p h a = a 1 + a 2
rgba ( r g b [ 0 ] , r g b [ 1 ] , r g b [ 2 ] , a l p h a )
/ / i n v e r t c o l o r s , l e a v e a l p h a i n t a c t
invert ( color = ' ' )
if color is a ' color '
rgba ( #fff - color , alpha ( color ) )
else
unquote ( " invert ( " + color + " ) " )
/ / g i v e c o m p l e m e n t o f t h e g i v e n color
complement ( color )
spin ( color , 1 8 0 )
/ / g i v e g r a y s c a l e o f t h e g i v e n color
grayscale ( color = ' ' )
if color is a ' color '
desaturate ( color , 1 0 0 % )
else
unquote ( " grayscale ( " + color + " ) " )
/ / mix t h e g i v e n color w i t h white
tint ( color , p e r c e n t )
mix ( white , color , p e r c e n t )
/ / mix t h e g i v e n color w i t h black
shade ( color , p e r c e n t )
mix ( black , color , p e r c e n t )
/ / return t h e l a s t v a l u e in t h e g i v e n e x p r
last ( e x p r )
e x p r [ length ( e x p r ) - 1 ]
/ / return k e y s in t h e g i v e n p a i r s or object
keys ( p a i r s )
r e t = ( )
if type ( p a i r s ) == ' object '
for k e y in p a i r s
push ( r e t , k e y )
else
for p a i r in p a i r s
push ( r e t , p a i r [ 0 ] ) ;
r e t
/ / return v a l u e s in t h e g i v e n p a i r s or object
values ( p a i r s )
r e t = ( )
if type ( p a i r s ) == ' object '
for k e y , v a l in p a i r s
push ( r e t , v a l )
else
for p a i r in p a i r s
push ( r e t , p a i r [ 1 ] ) ;
r e t
/ / j o i n v a l u e s w i t h t h e g i v e n d e l i m i t e r
join ( d e l i m , v a l s . . . )
b u f = ' '
v a l s = v a l s [ 0 ] if length ( v a l s ) == 1
for v a l , i in v a l s
b u f + = i ? d e l i m + v a l : v a l
/ / a d d a C S S r u l e t o t h e c o n t a i n i n g b l o c k
/ / - T h i s d e f i n i t i o n a l l o w s a d d - p r o p e r t y t o b e u s e d a s a m i x i n
/ / - I t h a s t h e s a m e e f f e c t a s i n t e r p o l a t i o n b u t a l l o w s u s e r s
/ / t o o p t for a f u n c t i o n a l style
a d d - p r o p e r t y - f u n c t i o n = a d d - p r o p e r t y
add-property ( n a m e , e x p r )
if m i x i n
{ n a m e } e x p r
else
add-property-function ( n a m e , e x p r )
prefix-classes ( p r e f i x )
-prefix-classes ( p r e f i x , b l o c k )
/ / C a c h i n g m i x i n , u s e i n s i d e y o u r f u n c t i o n s t o e n a b l e c a c h i n g b y e x t e n d i n g .
$stylus_mixin_cache = { }
cache ( )
$key = ( current-media ( ) or ' n o - m e d i a ' ) + ' _ _ ' + c a l l e d - f r o m [ 0 ] + ' _ _ ' + a r g u m e n t s
if $key in $stylus_mixin_cache
@extend { " $cache_placeholder_for_ " + $stylus_mixin_cache [ $key ] }
else if ' c a c h e ' in c a l l e d - f r o m
{ b l o c k }
else
$id = length ( $stylus_mixin_cache )
& ,
/ $cache_placeholder_for_ { $id }
$stylus_mixin_cache [ $key ] = $id
{ b l o c k }
/ / P e r c e n t a g e f u n c t i o n t o c o n v e r t a n u m b e r , e . g . " . 45 " , i n t o a p e r c e n t a g e , e . g . " 4 5 % "
percentage ( n u m )
return unit ( n u m * 1 0 0 , ' % ' )
/ / Return s t h e position o f a ` v a l u e ` w i t h i n a ` l i s t `
index ( l i s t , v a l u e )
for v a l , i in l i s t
return i if v a l == v a l u e