mostly filebased Content Presentation System
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

168 lines
3.7KB

  1. // Sass Utilities
  2. // ==============
  3. // - Susy Error Output Override [variable]
  4. // - Susy Error [function]
  5. // Susy Error Output Override
  6. // --------------------------
  7. /// Turn off error output for testing
  8. /// @group x-utility
  9. /// @access private
  10. $_susy-error-output-override: false !default;
  11. // Susy Error
  12. // ----------
  13. /// Optionally return error messages without failing,
  14. /// as a way to test error cases
  15. ///
  16. /// @group x-utility
  17. /// @access private
  18. ///
  19. /// @param {string} $message -
  20. /// A useful error message, explaining the problem
  21. /// @param {string} $source -
  22. /// The original source of the error for debugging
  23. /// @param {bool} $override [$_susy-error-output-override] -
  24. /// Optionally return the error rather than failing
  25. /// @return {string} -
  26. /// Combined error with source and message
  27. /// @throws When `$override == true`
  28. @function _susy-error(
  29. $message,
  30. $source,
  31. $override: $_susy-error-output-override
  32. ) {
  33. @if $override {
  34. @return 'ERROR [#{$source}] #{$message}';
  35. }
  36. @error '[#{$source}] #{$message}';
  37. }
  38. // Su Is Comparable
  39. // ----------------
  40. /// Check that the units in a grid are comparable
  41. ///
  42. /// @group _validation
  43. /// @access private
  44. ///
  45. /// @param {numbers} $lengths… -
  46. /// Arglist of all the number values to compare
  47. /// (columns, gutters, span, etc)
  48. ///
  49. /// @return {'fluid' | 'static' | false} -
  50. /// The type of span (fluid or static) when units match,
  51. /// or `false` for mismatched units
  52. @function _su-is-comparable(
  53. $lengths...
  54. ) {
  55. $first: nth($lengths, 1);
  56. @if (length($lengths) == 1) {
  57. @return if(unitless($first), 'fluid', 'static');
  58. }
  59. @for $i from 2 through length($lengths) {
  60. $comp: nth($lengths, $i);
  61. $fail: not comparable($first, $comp);
  62. $fail: $fail or (unitless($first) and not unitless($comp));
  63. $fail: $fail or (unitless($comp) and not unitless($first));
  64. @if $fail {
  65. @return false;
  66. }
  67. }
  68. @return if(unitless($first), 'fluid', 'static');
  69. }
  70. // Su Map Add Units
  71. // ----------------
  72. /// The calc features use a map of units and values
  73. /// to compile the proper algorythm.
  74. /// This function adds a new value to any comparable existing unit/value,
  75. /// or adds a new unit/value pair to the map
  76. ///
  77. /// @group x-utility
  78. /// @access private
  79. ///
  80. /// @param {map} $map -
  81. /// A map of unit/value pairs, e.g. ('px': 120px)
  82. /// @param {length} $value -
  83. /// A new length to be added to the map
  84. /// @return {map} -
  85. /// The updated map, with new value added
  86. ///
  87. /// @example scss -
  88. /// $map: (0px: 120px);
  89. /// $map: _su-map-add-units($map, 1in); // add a comparable unit
  90. /// $map: _su-map-add-units($map, 3vw); // add a new unit
  91. ///
  92. /// @each $units, $value in $map {
  93. /// /* #{$units}: #{$value} */
  94. /// }
  95. @function _su-map-add-units(
  96. $map,
  97. $value
  98. ) {
  99. $unit: $value * 0;
  100. $has: map-get($map, $unit) or 0;
  101. @if ($has == 0) {
  102. @each $try, $could in $map {
  103. $match: comparable($try, $value);
  104. $unit: if($match, $try, $unit);
  105. $has: if($match, $could, $has);
  106. }
  107. }
  108. @return map-merge($map, ($unit: $has + $value));
  109. }
  110. // Susy Flatten
  111. // ------------
  112. /// Flatten a multidimensional list
  113. ///
  114. /// @group x-utility
  115. /// @access private
  116. ///
  117. /// @param {list} $list -
  118. /// The list to be flattened
  119. /// @return {list} -
  120. /// The flattened list
  121. ///
  122. /// @example scss -
  123. /// $list: 120px (30em 30em) 120px;
  124. /// /* #{_susy-flatten($list)} */
  125. @function _susy-flatten(
  126. $list
  127. ) {
  128. $flat: ();
  129. // Don't iterate over maps
  130. @if (type-of($list) == 'map') {
  131. @return $list;
  132. }
  133. // Iterate over lists (or single items)
  134. @each $item in $list {
  135. @if (type-of($item) == 'list') {
  136. $item: _susy-flatten($item);
  137. $flat: join($flat, $item);
  138. } @else {
  139. $flat: append($flat, $item);
  140. }
  141. }
  142. // Return flattened list
  143. @return $flat;
  144. }