flex.styl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Vendor "display: flex" support with fallback to obsolete versions.
  3. */
  4. flex-version ?= box flex
  5. //
  6. // 1. Display values
  7. // - http://www.w3.org/TR/css3-flexbox/#flex-containers
  8. //
  9. display(type, args...)
  10. if flex == type || inline-flex == type
  11. if box in flex-version
  12. if flex == type
  13. display: -ms-flexbox args
  14. display: vendor-value(box args, only: moz webkit)
  15. else
  16. display: -ms-inline-flexbox args
  17. display: vendor-value(inline-box args, only: moz webkit)
  18. if flex in flex-version
  19. display: vendor-value(arguments, only: webkit official) // overwrites old webkit
  20. else
  21. display: arguments
  22. /*
  23. * New syntax for browsers like Google Chrome.
  24. * Plus a translation to the old syntax, if possible.
  25. */
  26. //
  27. // 5. Ordering and Orientation
  28. // - http://www.w3.org/TR/css3-flexbox/#ordering-and-orientation
  29. //
  30. -flex-obsolete-direction(direction)
  31. if box in flex-version
  32. if row-reverse == direction || column-reverse == direction
  33. vendor('box-direction', reverse, ignore: ms official)
  34. if row == direction || row-reverse == direction
  35. vendor('box-orient', horizontal, ignore: ms official)
  36. else if column == direction || column-reverse == direction
  37. vendor('box-orient', vertical, ignore: ms official)
  38. -flex-obsolete-wrap(value)
  39. if box in flex-version
  40. // WARN: wrap-reverse does not have a box equivalent. This will render in different manners
  41. // on box vs. flex values.
  42. if 'wrap' == value || wrap-reverse == value
  43. vendor('box-lines', multiple, ignore: ms official)
  44. else if nowrap == value
  45. vendor('box-lines', single, ignore: ms official)
  46. flex-direction(direction)
  47. // obsolete
  48. -flex-obsolete-direction(direction)
  49. // new
  50. if flex in flex-version
  51. vendor('flex-direction', arguments, only: webkit ms official)
  52. flex-wrap(value)
  53. // obsolete
  54. -flex-obsolete-wrap(value)
  55. if flex in flex-version
  56. vendor('flex-wrap', arguments, only: webkit ms official)
  57. flex-flow()
  58. // obsolete
  59. -flex-obsolete-direction(arguments[0])
  60. -flex-obsolete-direction(arguments[1])
  61. -flex-obsolete-wrap(arguments[0])
  62. -flex-obsolete-wrap(arguments[1])
  63. // new
  64. if flex in flex-version
  65. vendor('flex-flow', arguments, only: webkit ms official)
  66. order()
  67. // obsolete
  68. if box in flex-version
  69. vendor('box-ordinal-group', arguments, ignore: ms official)
  70. // new
  71. if flex in flex-version
  72. vendor('flex-order', arguments, only: ms)
  73. vendor('order', arguments, only: webkit official)
  74. //
  75. // 7. Flexibility
  76. // - http://www.w3.org/TR/css3-flexbox/#flexibility
  77. //
  78. flex-grow(growth)
  79. // obsolete
  80. if box in flex-version
  81. vendor('box-flex', growth)
  82. // new
  83. if flex in flex-version
  84. vendor('flex-grow', arguments, only: webkit official)
  85. flex-basis()
  86. if flex in flex-version
  87. vendor('flex-basis', arguments, only: webkit official)
  88. flex-shrink()
  89. if flex in flex-version
  90. vendor('flex-shrink', arguments, only: webkit official)
  91. flex(growth)
  92. // obsolete
  93. if box in flex-version
  94. shrink = 1
  95. if none == growth || initial == growth
  96. // Well known values
  97. shrink = 0 if none == growth
  98. growth = 0
  99. else if is-width(growth) == true
  100. // Basis is defined as the first parameter
  101. growth = arguments[1] || 0
  102. shrink = arguments[2] if 3 <= length(arguments)
  103. else if arguments[1] && is-width(arguments[1]) == false
  104. // Growth is first and shrink is second
  105. shrink = arguments[1]
  106. // Since we can't make the distinction between growing and shrinking in the box model, take
  107. // the one that provides the most flexibility.
  108. vendor('box-flex', max(growth, shrink), ignore: ms)
  109. // new
  110. if flex in flex-version
  111. vendor('flex', arguments, only: webkit ms official)
  112. // converts the justification alignment
  113. -convert-justify(align)
  114. if flex-start == align
  115. return start
  116. else if flex-end == align
  117. return end
  118. else if space-around == align
  119. return distribute
  120. else if space-between == align
  121. return justify
  122. else
  123. return align
  124. //
  125. // 8. Alignment
  126. // - http://www.w3.org/TR/css3-flexbox/#alignment
  127. //
  128. justify-content(align)
  129. // obsolete
  130. if box in flex-version
  131. vendor('box-pack', -convert-justify(align), ignore: ms official)
  132. // new
  133. if flex in flex-version
  134. vendor('flex-pack', -convert-justify(align), only: ms)
  135. vendor('justify-content', align, only: webkit official)
  136. align-content(align)
  137. // WARN: Obsolete spec does not allow for adjustment here
  138. if flex in flex-version
  139. vendor('flex-line-pack', -convert-justify(align), only: ms)
  140. vendor('align-content', align, only: webkit official)
  141. // converts alignment from 'flex' to normal value
  142. -convert-alignment(align)
  143. if flex-start == align
  144. return start
  145. else if flex-end == align
  146. return end
  147. else
  148. return align
  149. align-items(align)
  150. // obsolete
  151. if box in flex-version
  152. vendor('box-align', -convert-alignment(align), ignore: ms official)
  153. // new
  154. if flex in flex-version
  155. vendor('flex-align', -convert-alignment(align), only: ms)
  156. vendor('align-items', arguments, only: webkit official)
  157. align-self(align)
  158. // WARN: Obsolete spec does not allow for overriding alignment on individual items.
  159. if flex in flex-version
  160. vendor('align-self', align, only: webkit official)
  161. vendor('flex-item-align', -convert-alignment(align), only: ms)