uswds-jekyll 5.0.1 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -93
  3. data/_includes/components/banner.html +11 -9
  4. data/_sass/uswds/components/_header.scss +1 -1
  5. data/_sass/uswds/components/_nav-buttons.scss +4 -4
  6. data/_sass/uswds/src/components/_alerts.scss +8 -9
  7. data/_sass/uswds/src/components/_banner.scss +102 -31
  8. data/_sass/uswds/src/components/_breadcrumb.scss +168 -0
  9. data/_sass/uswds/src/components/_footer.scss +14 -4
  10. data/_sass/uswds/src/components/_header.scss +1 -1
  11. data/_sass/uswds/src/components/_identifier.scss +146 -0
  12. data/_sass/uswds/src/components/_media-block.scss +6 -1
  13. data/_sass/uswds/src/components/_megamenu.scss +4 -1
  14. data/_sass/uswds/src/components/_section.scss +6 -2
  15. data/_sass/uswds/src/components/_skipnav.scss +2 -2
  16. data/_sass/uswds/src/components/_step-indicator.scss +444 -0
  17. data/_sass/uswds/src/components/_tooltip.scss +114 -0
  18. data/_sass/uswds/src/core/_functions.scss +631 -0
  19. data/_sass/uswds/src/core/_notifications.scss +14 -0
  20. data/_sass/uswds/src/core/_properties.scss +120 -108
  21. data/_sass/uswds/src/core/_system-tokens.scss +140 -155
  22. data/_sass/uswds/src/core/_variables.scss +134 -32
  23. data/_sass/uswds/src/core/mixins/_add-link-styles.scss +20 -0
  24. data/_sass/uswds/src/core/mixins/_all.scss +4 -0
  25. data/_sass/uswds/src/core/mixins/_font-face.scss +1 -1
  26. data/_sass/uswds/src/core/mixins/_icon.scss +119 -0
  27. data/_sass/uswds/src/core/mixins/_media-block-img.scss +1 -1
  28. data/_sass/uswds/src/core/mixins/_set-link-from-bg.scss +30 -0
  29. data/_sass/uswds/src/core/mixins/_set-text-from-bg.scss +28 -0
  30. data/_sass/uswds/src/core/mixins/utilities/_align-self.scss +11 -0
  31. data/_sass/uswds/src/core/mixins/utilities/_border.scss +1 -1
  32. data/_sass/uswds/src/core/mixins/utilities/_flex.scss +6 -1
  33. data/_sass/uswds/src/core/mixins/utilities/_text.scss +6 -1
  34. data/_sass/uswds/src/core/placeholders/_list.scss +5 -0
  35. data/_sass/uswds/src/core/system-tokens/_blue-cool.scss +3 -3
  36. data/_sass/uswds/src/core/system-tokens/_blue-warm.scss +3 -3
  37. data/_sass/uswds/src/core/system-tokens/_blue.scss +3 -3
  38. data/_sass/uswds/src/core/system-tokens/_cyan.scss +3 -3
  39. data/_sass/uswds/src/core/system-tokens/_gold.scss +3 -3
  40. data/_sass/uswds/src/core/system-tokens/_gray-cool.scss +2 -2
  41. data/_sass/uswds/src/core/system-tokens/_gray-warm.scss +2 -2
  42. data/_sass/uswds/src/core/system-tokens/_gray.scss +2 -2
  43. data/_sass/uswds/src/core/system-tokens/_green-cool.scss +3 -3
  44. data/_sass/uswds/src/core/system-tokens/_green-warm.scss +3 -3
  45. data/_sass/uswds/src/core/system-tokens/_green.scss +3 -3
  46. data/_sass/uswds/src/core/system-tokens/_indigo-cool.scss +6 -6
  47. data/_sass/uswds/src/core/system-tokens/_indigo-warm.scss +3 -3
  48. data/_sass/uswds/src/core/system-tokens/_indigo.scss +3 -3
  49. data/_sass/uswds/src/core/system-tokens/_magenta.scss +3 -3
  50. data/_sass/uswds/src/core/system-tokens/_mint-cool.scss +3 -3
  51. data/_sass/uswds/src/core/system-tokens/_mint.scss +3 -3
  52. data/_sass/uswds/src/core/system-tokens/_orange-warm.scss +3 -3
  53. data/_sass/uswds/src/core/system-tokens/_orange.scss +3 -3
  54. data/_sass/uswds/src/core/system-tokens/_red-cool.scss +3 -3
  55. data/_sass/uswds/src/core/system-tokens/_red-warm.scss +3 -3
  56. data/_sass/uswds/src/core/system-tokens/_red.scss +3 -3
  57. data/_sass/uswds/src/core/system-tokens/_violet-warm.scss +3 -3
  58. data/_sass/uswds/src/core/system-tokens/_violet.scss +3 -3
  59. data/_sass/uswds/src/core/system-tokens/_yellow.scss +3 -3
  60. data/_sass/uswds/src/elements/_buttons.scss +31 -24
  61. data/_sass/uswds/src/elements/form-controls/_all.scss +2 -0
  62. data/_sass/uswds/src/elements/form-controls/_checkbox-and-radio.scss +4 -2
  63. data/_sass/uswds/src/elements/form-controls/_combo-box.scss +80 -9
  64. data/_sass/uswds/src/elements/form-controls/_date-picker.scss +325 -0
  65. data/_sass/uswds/src/elements/form-controls/_file-input.scss +195 -0
  66. data/_sass/uswds/src/elements/form-controls/_global.scss +10 -3
  67. data/_sass/uswds/src/elements/form-controls/_time-picker.scss +3 -0
  68. data/_sass/uswds/src/packages/_usa-breadcrumb.scss +4 -0
  69. data/_sass/uswds/src/packages/_usa-identifier.scss +1 -0
  70. data/_sass/uswds/src/packages/_usa-step-indicator.scss +2 -0
  71. data/_sass/uswds/src/packages/_usa-tooltip.scss +2 -0
  72. data/_sass/uswds/src/packages/_uswds-components.scss +4 -0
  73. data/_sass/uswds/src/settings/_settings-color.scss +6 -1
  74. data/_sass/uswds/src/settings/_settings-components.scss +45 -1
  75. data/_sass/uswds/src/settings/_settings-general.scss +4 -4
  76. data/_sass/uswds/src/settings/_settings-typography.scss +5 -5
  77. data/_sass/uswds/src/settings/_settings-utilities.scss +89 -75
  78. data/_sass/uswds/src/theme/_uswds-theme-color.scss +4 -1
  79. data/_sass/uswds/src/theme/_uswds-theme-components.scss +45 -1
  80. data/_sass/uswds/src/theme/_uswds-theme-general.scss +4 -4
  81. data/_sass/uswds/src/theme/_uswds-theme-typography.scss +5 -5
  82. data/_sass/uswds/src/theme/_uswds-theme-utilities.scss +90 -77
  83. data/_sass/uswds/src/theme/styles.scss +5 -1
  84. data/_sass/uswds/src/utilities/palettes/_default-palettes.scss +2 -1
  85. data/_sass/uswds/src/utilities/palettes/_font-palettes.scss +478 -478
  86. data/_sass/uswds/src/utilities/palettes/_spacing-palettes.scss +7 -7
  87. data/_sass/uswds/src/utilities/palettes/colors/_all-colors-palettes.scss +2 -2
  88. data/_sass/uswds/src/utilities/palettes/colors/_black-transparent-palettes.scss +2 -2
  89. data/_sass/uswds/src/utilities/palettes/colors/_blue-cool-palettes.scss +7 -7
  90. data/_sass/uswds/src/utilities/palettes/colors/_blue-palettes.scss +7 -7
  91. data/_sass/uswds/src/utilities/palettes/colors/_blue-warm-palettes.scss +7 -7
  92. data/_sass/uswds/src/utilities/palettes/colors/_cyan-palettes.scss +7 -7
  93. data/_sass/uswds/src/utilities/palettes/colors/_gold-palettes.scss +7 -7
  94. data/_sass/uswds/src/utilities/palettes/colors/_gray-cool-palettes.scss +5 -5
  95. data/_sass/uswds/src/utilities/palettes/colors/_gray-palettes.scss +5 -5
  96. data/_sass/uswds/src/utilities/palettes/colors/_gray-warm-palettes.scss +5 -5
  97. data/_sass/uswds/src/utilities/palettes/colors/_green-cool-palettes.scss +7 -7
  98. data/_sass/uswds/src/utilities/palettes/colors/_green-palettes.scss +7 -7
  99. data/_sass/uswds/src/utilities/palettes/colors/_green-warm-palettes.scss +7 -7
  100. data/_sass/uswds/src/utilities/palettes/colors/_indigo-cool-palettes.scss +7 -7
  101. data/_sass/uswds/src/utilities/palettes/colors/_indigo-palettes.scss +7 -7
  102. data/_sass/uswds/src/utilities/palettes/colors/_indigo-warm-palettes.scss +7 -7
  103. data/_sass/uswds/src/utilities/palettes/colors/_magenta-palettes.scss +7 -7
  104. data/_sass/uswds/src/utilities/palettes/colors/_mint-cool-palettes.scss +7 -7
  105. data/_sass/uswds/src/utilities/palettes/colors/_mint-palettes.scss +7 -7
  106. data/_sass/uswds/src/utilities/palettes/colors/_orange-palettes.scss +7 -7
  107. data/_sass/uswds/src/utilities/palettes/colors/_orange-warm-palettes.scss +7 -7
  108. data/_sass/uswds/src/utilities/palettes/colors/_red-cool-palettes.scss +7 -7
  109. data/_sass/uswds/src/utilities/palettes/colors/_red-palettes.scss +7 -7
  110. data/_sass/uswds/src/utilities/palettes/colors/_red-warm-palettes.scss +7 -7
  111. data/_sass/uswds/src/utilities/palettes/colors/_violet-palettes.scss +7 -7
  112. data/_sass/uswds/src/utilities/palettes/colors/_violet-warm-palettes.scss +7 -7
  113. data/_sass/uswds/src/utilities/palettes/colors/_white-transparent-palettes.scss +2 -2
  114. data/_sass/uswds/src/utilities/palettes/colors/_yellow-palettes.scss +7 -7
  115. data/_sass/uswds/src/utilities/rules/_all.scss +1 -0
  116. data/_sass/uswds/src/utilities/rules/_package.scss +1 -0
  117. data/_sass/uswds/src/utilities/rules/add-aspect.scss +13 -13
  118. data/_sass/uswds/src/utilities/rules/add-list-reset.scss +5 -5
  119. data/_sass/uswds/src/utilities/rules/align-items.scss +2 -2
  120. data/_sass/uswds/src/utilities/rules/align-self.scss +27 -0
  121. data/_sass/uswds/src/utilities/rules/background-color.scss +2 -2
  122. data/_sass/uswds/src/utilities/rules/border-color.scss +2 -2
  123. data/_sass/uswds/src/utilities/rules/border-radius.scss +7 -7
  124. data/_sass/uswds/src/utilities/rules/border-style.scss +2 -2
  125. data/_sass/uswds/src/utilities/rules/border-width.scss +5 -5
  126. data/_sass/uswds/src/utilities/rules/border.scss +5 -5
  127. data/_sass/uswds/src/utilities/rules/bottom.scss +2 -2
  128. data/_sass/uswds/src/utilities/rules/box-shadow.scss +2 -2
  129. data/_sass/uswds/src/utilities/rules/circle.scss +4 -4
  130. data/_sass/uswds/src/utilities/rules/clearfix.scss +5 -5
  131. data/_sass/uswds/src/utilities/rules/color.scss +2 -2
  132. data/_sass/uswds/src/utilities/rules/cursor.scss +2 -2
  133. data/_sass/uswds/src/utilities/rules/display.scss +2 -2
  134. data/_sass/uswds/src/utilities/rules/flex-direction.scss +2 -2
  135. data/_sass/uswds/src/utilities/rules/flex-wrap.scss +2 -2
  136. data/_sass/uswds/src/utilities/rules/flex.scss +2 -2
  137. data/_sass/uswds/src/utilities/rules/float.scss +2 -2
  138. data/_sass/uswds/src/utilities/rules/font-family.scss +2 -2
  139. data/_sass/uswds/src/utilities/rules/font-feature.scss +2 -2
  140. data/_sass/uswds/src/utilities/rules/font-style.scss +2 -2
  141. data/_sass/uswds/src/utilities/rules/font-weight.scss +2 -2
  142. data/_sass/uswds/src/utilities/rules/font.scss +2 -2
  143. data/_sass/uswds/src/utilities/rules/height.scss +2 -2
  144. data/_sass/uswds/src/utilities/rules/justify-content.scss +2 -2
  145. data/_sass/uswds/src/utilities/rules/left.scss +2 -2
  146. data/_sass/uswds/src/utilities/rules/letter-spacing.scss +2 -2
  147. data/_sass/uswds/src/utilities/rules/line-height.scss +2 -2
  148. data/_sass/uswds/src/utilities/rules/margin.scss +9 -9
  149. data/_sass/uswds/src/utilities/rules/max-height.scss +2 -2
  150. data/_sass/uswds/src/utilities/rules/max-width.scss +2 -2
  151. data/_sass/uswds/src/utilities/rules/measure.scss +2 -2
  152. data/_sass/uswds/src/utilities/rules/min-height.scss +2 -2
  153. data/_sass/uswds/src/utilities/rules/min-width.scss +2 -2
  154. data/_sass/uswds/src/utilities/rules/opacity.scss +3 -5
  155. data/_sass/uswds/src/utilities/rules/order.scss +2 -2
  156. data/_sass/uswds/src/utilities/rules/outline-color.scss +2 -2
  157. data/_sass/uswds/src/utilities/rules/outline.scss +2 -2
  158. data/_sass/uswds/src/utilities/rules/overflow.scss +3 -3
  159. data/_sass/uswds/src/utilities/rules/padding.scss +5 -5
  160. data/_sass/uswds/src/utilities/rules/pin.scss +19 -19
  161. data/_sass/uswds/src/utilities/rules/position.scss +2 -2
  162. data/_sass/uswds/src/utilities/rules/right.scss +2 -2
  163. data/_sass/uswds/src/utilities/rules/square.scss +4 -4
  164. data/_sass/uswds/src/utilities/rules/text-align.scss +2 -2
  165. data/_sass/uswds/src/utilities/rules/text-decoration-color.scss +2 -2
  166. data/_sass/uswds/src/utilities/rules/text-decoration.scss +2 -2
  167. data/_sass/uswds/src/utilities/rules/text-indent.scss +2 -2
  168. data/_sass/uswds/src/utilities/rules/text-transform.scss +2 -2
  169. data/_sass/uswds/src/utilities/rules/top.scss +2 -2
  170. data/_sass/uswds/src/utilities/rules/vertical-align.scss +2 -2
  171. data/_sass/uswds/src/utilities/rules/whitespace.scss +2 -2
  172. data/_sass/uswds/src/utilities/rules/width.scss +2 -2
  173. data/_sass/uswds/src/utilities/rules/z-index.scss +2 -2
  174. data/assets/uswds/img/angle-arrow-down-gray-90.svg +1 -0
  175. data/assets/uswds/img/angle-arrow-right-white.svg +1 -0
  176. data/assets/uswds/img/angle-arrow-right.svg +1 -0
  177. data/assets/uswds/img/angle-double-left-solid.svg +1 -0
  178. data/assets/uswds/img/angle-double-right-solid.svg +1 -0
  179. data/assets/uswds/img/angle-left-solid.svg +1 -0
  180. data/assets/uswds/img/angle-right-solid.svg +1 -0
  181. data/assets/uswds/img/arrow-down-gray-60.svg +1 -0
  182. data/assets/uswds/img/arrow-left-indigo-cool-50v.svg +1 -0
  183. data/assets/uswds/img/arrow-left-white.svg +1 -0
  184. data/assets/uswds/img/arrow-left.svg +1 -0
  185. data/assets/uswds/img/calendar-alt-solid.svg +1 -0
  186. data/assets/uswds/img/chevron-right-white.svg +1 -0
  187. data/assets/uswds/img/chevron-right.svg +1 -0
  188. data/assets/uswds/img/chevron-white.svg +1 -0
  189. data/assets/uswds/img/chevron.svg +1 -0
  190. data/assets/uswds/img/circle-gray-20.svg +1 -0
  191. data/assets/uswds/img/close-alt-blue-60v.svg +3 -0
  192. data/assets/uswds/img/close-alt.svg +3 -0
  193. data/assets/uswds/img/close-gray-60.svg +1 -0
  194. data/assets/uswds/img/file-excel.svg +1 -0
  195. data/assets/uswds/img/file-pdf.svg +1 -0
  196. data/assets/uswds/img/file-video.svg +1 -0
  197. data/assets/uswds/img/file-word.svg +1 -0
  198. data/assets/uswds/img/file.svg +1 -0
  199. data/assets/uswds/img/loader.gif +0 -0
  200. data/assets/uswds/img/loader.svg +1 -0
  201. data/assets/uswds/img/lock.svg +1 -0
  202. data/assets/uswds/js/uswds.js +3570 -216
  203. data/assets/uswds/js/uswds.min.js +1 -1
  204. data/assets/uswds/js/uswds.min.js.map +1 -1
  205. metadata +59 -2
@@ -0,0 +1,114 @@
1
+ // Variables
2
+ $triangle-size: 5px;
3
+
4
+ /* Tooltips */
5
+ .usa-tooltip {
6
+ display: inline-block;
7
+ position: relative;
8
+ }
9
+
10
+ .usa-tooltip__trigger {
11
+ cursor: pointer;
12
+
13
+ > svg {
14
+ display: block;
15
+ pointer-events: none;
16
+ }
17
+ }
18
+
19
+ .usa-tooltip__body {
20
+ transition: opacity 0.08s ease-in-out;
21
+ background-color: color($theme-tooltip-background-color);
22
+ border-radius: radius($theme-button-border-radius);
23
+ bottom: 0;
24
+ color: color($theme-tooltip-font-color);
25
+ display: none;
26
+ font-size: size("ui", $theme-tooltip-font-size);
27
+ padding: units(1);
28
+ position: absolute;
29
+ pointer-events: none;
30
+ left: 0;
31
+ opacity: 0;
32
+ transform: translateX(-50%);
33
+ width: auto;
34
+ white-space: pre;
35
+ z-index: 100000;
36
+
37
+ &:after {
38
+ content: "";
39
+ display: block;
40
+ width: 0;
41
+ height: 0;
42
+ pointer-events: none;
43
+ border-left: $triangle-size solid transparent;
44
+ border-right: $triangle-size solid transparent;
45
+ border-top: $triangle-size solid color($theme-tooltip-background-color);
46
+ position: absolute;
47
+ bottom: -$triangle-size;
48
+ left: 50%;
49
+ margin-left: -$triangle-size;
50
+ }
51
+ }
52
+
53
+ .usa-tooltip__body--wrap {
54
+ width: 100%;
55
+ white-space: normal;
56
+ }
57
+
58
+ .usa-tooltip__body.is-set {
59
+ display: block;
60
+ }
61
+
62
+ .usa-tooltip__body.is-visible {
63
+ opacity: 1;
64
+ }
65
+
66
+ .usa-tooltip__body--bottom {
67
+ bottom: auto;
68
+ top: 0;
69
+
70
+ &:after {
71
+ border-left: $triangle-size solid transparent;
72
+ border-right: $triangle-size solid transparent;
73
+ border-bottom: $triangle-size solid color($theme-tooltip-background-color);
74
+ border-top: 0;
75
+ bottom: auto;
76
+ top: -$triangle-size;
77
+ }
78
+ }
79
+
80
+ .usa-tooltip__body--right {
81
+ top: auto;
82
+ transform: translateX(0);
83
+
84
+ &:after {
85
+ border-top: $triangle-size solid transparent;
86
+ border-bottom: $triangle-size solid transparent;
87
+ border-right: $triangle-size solid color($theme-tooltip-background-color);
88
+ border-left: 0;
89
+ right: auto;
90
+ top: 50%;
91
+ bottom: 0;
92
+ left: -$triangle-size;
93
+ margin: -$triangle-size 0 0 0;
94
+ }
95
+ }
96
+
97
+ .usa-tooltip__body--left {
98
+ top: auto;
99
+ left: 0;
100
+ right: auto;
101
+ transform: translateX(0);
102
+
103
+ &:after {
104
+ border-top: $triangle-size solid transparent;
105
+ border-bottom: $triangle-size solid transparent;
106
+ border-left: $triangle-size solid color($theme-tooltip-background-color);
107
+ border-right: 0;
108
+ right: -$triangle-size;
109
+ top: 50%;
110
+ bottom: 0;
111
+ left: auto;
112
+ margin: -$triangle-size 0 0 0;
113
+ }
114
+ }
@@ -892,6 +892,382 @@ functions and mixins.
892
892
  @return $value;
893
893
  }
894
894
 
895
+ /*
896
+ ----------------------------------------
897
+ pow()
898
+ ----------------------------------------
899
+ Raises a unitless number to the power
900
+ of another unitless number
901
+
902
+ Includes helper functions
903
+ ----------------------------------------
904
+ */
905
+
906
+ @function pow($number, $exponent) {
907
+ @if (round($exponent) != $exponent) {
908
+ @return exp($exponent * ln($number));
909
+ }
910
+
911
+ $value: 1;
912
+
913
+ @if $exponent > 0 {
914
+ @for $i from 1 through $exponent {
915
+ $value: $value * $number;
916
+ }
917
+ } @else if $exponent < 0 {
918
+ @for $i from 1 through -$exponent {
919
+ $value: $value / $number;
920
+ }
921
+ }
922
+
923
+ @return $value;
924
+ }
925
+
926
+ @function factorial($value) {
927
+ $result: 1;
928
+
929
+ @if $value == 0 {
930
+ @return $result;
931
+ }
932
+
933
+ @for $index from 1 through $value {
934
+ $result: $result * $index;
935
+ }
936
+
937
+ @return $result;
938
+ }
939
+
940
+ @function summation($iteratee, $input, $initial: 0, $limit: 100) {
941
+ $sum: 0;
942
+
943
+ @for $index from $initial to $limit {
944
+ $sum: $sum + call($iteratee, $input, $index);
945
+ }
946
+
947
+ @return $sum;
948
+ }
949
+
950
+ @function exp-maclaurin($x, $n) {
951
+ @return (pow($x, $n) / factorial($n));
952
+ }
953
+
954
+ @function exp($value) {
955
+ @return summation(get-function("exp-maclaurin"), $value, 0, 100);
956
+ }
957
+
958
+ @function ln-maclaurin($x, $n) {
959
+ @return (pow(-1, $n + 1) / $n) * (pow($x - 1, $n));
960
+ }
961
+
962
+ @function ln($value) {
963
+ $ten-exp: 1;
964
+ $ln-ten: 2.30258509;
965
+
966
+ @while ($value > pow(10, $ten-exp)) {
967
+ $ten-exp: $ten-exp + 1;
968
+ }
969
+
970
+ @return summation(
971
+ get-function("ln-maclaurin"),
972
+ $value / pow(10, $ten-exp),
973
+ 1,
974
+ 100
975
+ ) + $ten-exp * $ln-ten;
976
+ }
977
+
978
+ /// Returns the luminance of `$color` as a float (between 0 and 1)
979
+ /// 1 is pure white, 0 is pure black
980
+ /// @param {Color} $color - Color
981
+ /// @return {Number}
982
+ /// @link http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef Reference
983
+ @function luminance($color) {
984
+ $colors: (
985
+ "red": red($color),
986
+ "green": green($color),
987
+ "blue": blue($color),
988
+ );
989
+
990
+ @each $name, $value in $colors {
991
+ $adjusted: 0;
992
+ $value: $value / 256;
993
+
994
+ @if $value < 0.03928 {
995
+ $value: $value / 12.92;
996
+ } @else {
997
+ $value: ($value + 0.055) / 1.055;
998
+ $value: pow($value, 2.4);
999
+ }
1000
+
1001
+ $colors: map-merge(
1002
+ $colors,
1003
+ (
1004
+ $name: $value,
1005
+ )
1006
+ );
1007
+ }
1008
+
1009
+ $lum: (map-get($colors, "red") * 0.2126) +
1010
+ (map-get($colors, "green") * 0.7152) + (map-get($colors, "blue") * 0.0722);
1011
+ $lum: round($lum * 1000) / 1000;
1012
+
1013
+ @return $lum;
1014
+ }
1015
+
1016
+ /// Casts a string into a number
1017
+ ///
1018
+ /// @param {String | Number} $value - Value to be parsed
1019
+ ///
1020
+ /// @return {Number}
1021
+ ///
1022
+ @function to-number($value) {
1023
+ @if type-of($value) == "number" {
1024
+ @return $value;
1025
+ } @else if type-of($value) != "string" {
1026
+ $_: log("Value for `to-number` should be a number or a string.");
1027
+ }
1028
+
1029
+ $result: 0;
1030
+ $digits: 0;
1031
+ $minus: str-slice($value, 1, 1) == "-";
1032
+ $numbers: (
1033
+ "0": 0,
1034
+ "1": 1,
1035
+ "2": 2,
1036
+ "3": 3,
1037
+ "4": 4,
1038
+ "5": 5,
1039
+ "6": 6,
1040
+ "7": 7,
1041
+ "8": 8,
1042
+ "9": 9,
1043
+ );
1044
+
1045
+ @for $i from if($minus, 2, 1) through str-length($value) {
1046
+ $character: str-slice($value, $i, $i);
1047
+
1048
+ @if not(index(map-keys($numbers), $character) or $character == ".") {
1049
+ @return to-length(if($minus, -$result, $result), str-slice($value, $i));
1050
+ }
1051
+
1052
+ @if $character == "." {
1053
+ $digits: 1;
1054
+ } @else if $digits == 0 {
1055
+ $result: $result * 10 + map-get($numbers, $character);
1056
+ } @else {
1057
+ $digits: $digits * 10;
1058
+ $result: $result + map-get($numbers, $character) / $digits;
1059
+ }
1060
+ }
1061
+
1062
+ @return if($minus, -$result, $result);
1063
+ }
1064
+
1065
+ /*
1066
+ ----------------------------------------
1067
+ decompose()
1068
+ ----------------------------------------
1069
+ Convert a color token into into a list
1070
+ of form [family], [grade], [variant]
1071
+
1072
+ Vivid variants return "vivid" as the
1073
+ variant.
1074
+
1075
+ If neither grade nor variant exists,
1076
+ returns 'null'
1077
+ ----------------------------------------
1078
+ */
1079
+
1080
+ @function decompose($token) {
1081
+ $separator: "-";
1082
+ $family: false;
1083
+ $grade: false;
1084
+ $variant: false;
1085
+ $exceptions: (
1086
+ "black": 100,
1087
+ "white": 0,
1088
+ );
1089
+
1090
+ $token: get-color-token-assignment($token);
1091
+ $split: str-split($token, $separator);
1092
+ $grade: nth($split, length($split));
1093
+
1094
+ @if str-index($grade, "v") {
1095
+ $variant: "vivid";
1096
+ $grade: str-slice($grade, 1, (str-index($grade, "v") - 1));
1097
+ }
1098
+
1099
+ @if length($split) == 3 {
1100
+ $family: nth($split, 1) + $separator + nth($split, 2);
1101
+ } @else {
1102
+ $family: nth($split, 1);
1103
+ }
1104
+
1105
+ $grade: to-number($grade);
1106
+
1107
+ @if map-has-key($exceptions, $family) {
1108
+ $grade: map-get($exceptions, $family);
1109
+ }
1110
+
1111
+ @return $family, $grade, $variant;
1112
+ }
1113
+
1114
+ /*
1115
+ ----------------------------------------
1116
+ test-colors()
1117
+ ----------------------------------------
1118
+ Check to see if all system colors
1119
+ fall between the proper relative
1120
+ luminance range for their grade.
1121
+
1122
+ Has a couple quirks, as the luminance()
1123
+ function returns slightly different
1124
+ results than expected.
1125
+ ----------------------------------------
1126
+ */
1127
+
1128
+ @function test-colors($map) {
1129
+ $exceptions: "black", "white", "transparent", "black-transparent",
1130
+ "white-transparent";
1131
+
1132
+ @each $token, $value in $map {
1133
+ $family: nth(decompose($token), 1);
1134
+ $grade: nth(decompose($token), 2);
1135
+ @if not $value {
1136
+ // empty block
1137
+ } @else if not index($exceptions, $family) {
1138
+ $computed: get-color-grade($value);
1139
+ @debug "Checked #{$family}-#{$grade}";
1140
+ @if $grade <= 5 {
1141
+ // empty block
1142
+ } @else if $computed != $grade {
1143
+ @warn "#{$token} (#{$value}) lum: #{luminance($value)} is not in the range #{map-get($system-luminance-grade-ranges, $grade)}";
1144
+ }
1145
+ }
1146
+ }
1147
+
1148
+ @return 1;
1149
+ }
1150
+
1151
+ /*
1152
+ ----------------------------------------
1153
+ str-split()
1154
+ ----------------------------------------
1155
+ Split a string at a given separator
1156
+ and convert into a lisrt of substrings
1157
+ ----------------------------------------
1158
+ */
1159
+
1160
+ @function str-split($string, $separator) {
1161
+ $split-arr: ();
1162
+ $index: str-index($string, $separator);
1163
+ @while $index != null {
1164
+ $item: str-slice($string, 1, $index - 1);
1165
+ $split-arr: append($split-arr, $item);
1166
+ $string: str-slice($string, $index + 1);
1167
+ $index: str-index($string, $separator);
1168
+ }
1169
+ $split-arr: append($split-arr, $string);
1170
+
1171
+ @return $split-arr;
1172
+ }
1173
+
1174
+ /*
1175
+ ----------------------------------------
1176
+ str-replace()
1177
+ ----------------------------------------
1178
+ Replace any substring with another
1179
+ string
1180
+ ----------------------------------------
1181
+ */
1182
+
1183
+ @function str-replace($string, $search, $replace: "") {
1184
+ $index: str-index($string, $search);
1185
+
1186
+ @if $index {
1187
+ @return str-slice($string, 1, $index - 1) + $replace +
1188
+ str-replace(
1189
+ str-slice($string, $index + str-length($search)),
1190
+ $search,
1191
+ $replace
1192
+ );
1193
+ }
1194
+
1195
+ @return $string;
1196
+ }
1197
+
1198
+ /*
1199
+ ----------------------------------------
1200
+ get-color-token-assignment()
1201
+ ----------------------------------------
1202
+ Get the system token equivalent of any
1203
+ theme color token
1204
+ ----------------------------------------
1205
+ */
1206
+
1207
+ @function get-color-token-assignment($color-token) {
1208
+ $system-token: $color-token;
1209
+ $grade: null;
1210
+
1211
+ @if map-has-key($assignments-theme-color, $color-token) {
1212
+ $system-token: map-get($assignments-theme-color, $system-token);
1213
+ } @else if not map-has-key($system-color-shortcodes, $color-token) {
1214
+ @error "'#{$color-token}' is not a valid color token.";
1215
+ }
1216
+
1217
+ @return $system-token;
1218
+ }
1219
+
1220
+ /*
1221
+ ----------------------------------------
1222
+ get-color-grade()
1223
+ ----------------------------------------
1224
+ Derive the grade equivalent any color,
1225
+ even non-token colors
1226
+ ----------------------------------------
1227
+ */
1228
+
1229
+ @function get-color-grade($color-token) {
1230
+ $grade: null;
1231
+ $lum: null;
1232
+ $color: false;
1233
+
1234
+ @if type-of($color-token) == "color" {
1235
+ $color: $color-token;
1236
+ } @else if type-of(get-color-token-assignment($color-token)) == "color" {
1237
+ $color: get-color-token-assignment($color-token);
1238
+ }
1239
+
1240
+ @if $color {
1241
+ $lum: luminance($color);
1242
+
1243
+ @each $grade, $range in $system-luminance-grade-ranges {
1244
+ $min: nth($range, 1);
1245
+ $max: nth($range, 2);
1246
+ $next-max: false;
1247
+ @if $grade < 100 {
1248
+ @if $grade == 5 {
1249
+ $next-max: nth(map-get($system-luminance-grade-ranges, 10), 2);
1250
+ } @else {
1251
+ $next-max: nth(
1252
+ map-get($system-luminance-grade-ranges, ($grade + 10)),
1253
+ 2
1254
+ );
1255
+ }
1256
+ }
1257
+ @if ($lum >= $min) and ($lum <= $max) {
1258
+ @return $grade;
1259
+ }
1260
+ @if $next-max and ($lum < $min) and ($lum > $next-max) {
1261
+ @return $grade + 4.9;
1262
+ }
1263
+ }
1264
+ }
1265
+
1266
+ $system-token: get-color-token-assignment($color-token);
1267
+ $grade: nth(decompose($system-token), 2);
1268
+ @return $grade;
1269
+ }
1270
+
895
1271
  /*
896
1272
  ----------------------------------------
897
1273
  color()
@@ -1321,3 +1697,258 @@ system z-index
1321
1697
  @function z($value) {
1322
1698
  @return z-index($value);
1323
1699
  }
1700
+
1701
+ @function get-token-from-bg(
1702
+ $bg-color,
1703
+ $preferred-text-color: "white",
1704
+ $fallback-text-color: "ink",
1705
+ $wcag-target: "AA"
1706
+ ) {
1707
+ $magic-numbers: (
1708
+ "AA": 50,
1709
+ "AAA": 70,
1710
+ "AA-large": 40,
1711
+ );
1712
+ $target-magic-number: map-get($magic-numbers, $wcag-target);
1713
+ $grade-bg: get-color-grade($bg-color);
1714
+ $grade-preferred: get-color-grade($preferred-text-color);
1715
+ $magic-num-preferred: abs($grade-bg - $grade-preferred);
1716
+ $color: false;
1717
+
1718
+ //@debug "Background grade: #{$grade-bg} | Preferred text grade: #{$grade-preferred} | Magic number: #{$magic-num-preferred} | Target: #{$target-magic-number}";
1719
+
1720
+ @if $magic-num-preferred >= $target-magic-number {
1721
+ $color: $preferred-text-color;
1722
+ } @else {
1723
+ $grade-fallback: get-color-grade($fallback-text-color);
1724
+ $magic-num-fallback: abs($grade-bg - $grade-fallback);
1725
+ $color: $fallback-text-color;
1726
+ }
1727
+
1728
+ @if not $color {
1729
+ @error "Neither '#{$preferred-text-color}' nor '#{$fallback-text-color}' have #{$wcag-target} contrast on a '#{$bg-color}' background.";
1730
+ }
1731
+
1732
+ @return $color;
1733
+ }
1734
+
1735
+ @function get-color-from-bg(
1736
+ $bg-color,
1737
+ $preferred-text-color: "white",
1738
+ $fallback-text-color: "ink",
1739
+ $wcag-target: "AA"
1740
+ ) {
1741
+ $color: get-token-from-bg(
1742
+ $bg-color,
1743
+ $preferred-text-color,
1744
+ $fallback-text-color,
1745
+ $wcag-target
1746
+ );
1747
+ @return color($color);
1748
+ }
1749
+
1750
+ @function get-link-tokens-from-bg(
1751
+ $bg-color,
1752
+ $preferred-link-color: $theme-link-color,
1753
+ $fallback-link-color: $theme-link-reverse-color,
1754
+ $wcag-target: "AA"
1755
+ ) {
1756
+ $magic-numbers: (
1757
+ "AA": 50,
1758
+ "AAA": 70,
1759
+ "AA-large": 40,
1760
+ );
1761
+ $grade-step: 10;
1762
+ $found: false;
1763
+ $decomposed: false;
1764
+
1765
+ @if $preferred-link-color == default {
1766
+ $preferred-link-color: $theme-link-color;
1767
+ }
1768
+
1769
+ $target-magic-number: map-get($magic-numbers, $wcag-target);
1770
+ $bg-grade: get-color-grade($bg-color);
1771
+ $our-color-tokens: ($preferred-link-color, $fallback-link-color);
1772
+
1773
+ $link-token: false;
1774
+ $hover-token: false;
1775
+
1776
+ @each $color-token in $our-color-tokens {
1777
+ //@debug "color token: " + $color-token;
1778
+ // If the color token is a custom color, set a $custom flag
1779
+ $custom: if(
1780
+ type-of(map-get($assignments-theme-color, $color-token)) == "color",
1781
+ true,
1782
+ false
1783
+ );
1784
+
1785
+ // Only get a link color if one has not yet been found
1786
+ @if not $found {
1787
+ $link-grade-token: get-color-grade($color-token);
1788
+ $link-grade: if($link-grade-token < 10, 0, $link-grade-token);
1789
+ $link-magic-number: abs($bg-grade - $link-grade);
1790
+ $token-darker: false;
1791
+ $token-lighter: false;
1792
+ $link-family: false;
1793
+ $link-vivid: false;
1794
+ $hover-grade: false;
1795
+ $hover-vivid: false;
1796
+
1797
+ // If the link color is custom, output theme tokens, not system tokens
1798
+ @if $custom {
1799
+ //@debug "uses custom color.";
1800
+ $custom-token: $color-token;
1801
+ $custom-token-lighter: false;
1802
+ $custom-token-darker: false;
1803
+ $custom-split: str-split($custom-token, "-");
1804
+ $custom-grade: false;
1805
+ $custom-grade-lighter: false;
1806
+ $custom-grade-darker: false;
1807
+ //@debug "custom split:" + $custom-split;
1808
+
1809
+ // set family as the first string in the split
1810
+ $custom-family: nth($custom-split, 1);
1811
+
1812
+ // ignore vivid in token calculations, treat as default
1813
+ @if index($custom-split, "vivid") {
1814
+ $custom-split: remove($custom-split, "vivid");
1815
+ }
1816
+
1817
+ // set family and grade for "accent" families, since their family includes the split character
1818
+ @if $custom-family == "accent" {
1819
+ $custom-family: $custom-family + "-" + nth($custom-split, 2);
1820
+ $custom-grade: if(
1821
+ length($custom-split) == 3,
1822
+ nth($custom-split, 3),
1823
+ "default"
1824
+ );
1825
+ } @else {
1826
+ $custom-grade: if(
1827
+ length($custom-split) == 2,
1828
+ nth($custom-split, 2),
1829
+ "default"
1830
+ );
1831
+ }
1832
+
1833
+ //@debug "custom family: " + $custom-family;
1834
+ //@debug "custom grade: " + $custom-grade;
1835
+
1836
+ $custom-family-lighter: $custom-family;
1837
+ $custom-family-darker: $custom-family;
1838
+ $custom-grade-index: index($uswds-color-theme-grades, $custom-grade);
1839
+
1840
+ // If it's the lightest grade, use "white" for the lighter family
1841
+ @if $custom-grade-index == 1 {
1842
+ $custom-family-lighter: "white";
1843
+ } @else {
1844
+ $custom-grade-lighter: nth(
1845
+ $uswds-color-theme-grades,
1846
+ ($custom-grade-index - 1)
1847
+ );
1848
+ }
1849
+ //@debug "lighter grade: " + $custom-grade-lighter;
1850
+ // If it's the darkest grade, use "black" for the lighter family
1851
+ @if $custom-grade-index == length($uswds-color-theme-grades) {
1852
+ $custom-family-darker: "black";
1853
+ } @else {
1854
+ $custom-grade-darker: nth(
1855
+ $uswds-color-theme-grades,
1856
+ ($custom-grade-index + 1)
1857
+ );
1858
+ }
1859
+ //@debug "darker grade: " + $custom-grade-darker;
1860
+
1861
+ // If any calculated grade is "default", don't output the grade
1862
+ $custom-grade-darker: if(
1863
+ $custom-grade-darker == "default",
1864
+ false,
1865
+ $custom-grade-darker
1866
+ );
1867
+ $custom-grade-lighter: if(
1868
+ $custom-grade-lighter == "default",
1869
+ false,
1870
+ $custom-grade-lighter
1871
+ );
1872
+
1873
+ // Build the custom lighter and darker tokens
1874
+ $token-darker: if(
1875
+ $custom-grade-darker,
1876
+ $custom-family + "-" + $custom-grade-darker,
1877
+ $custom-family-darker
1878
+ );
1879
+ $token-lighter: if(
1880
+ $custom-grade-lighter,
1881
+ $custom-family + "-" + $custom-grade-lighter,
1882
+ $custom-family-lighter
1883
+ );
1884
+ } @else {
1885
+ //@debug "not custom";
1886
+ $decomposed: decompose($color-token);
1887
+ }
1888
+
1889
+ @if $link-grade == 0 {
1890
+ @warn 'Tokens with grades less than 10 (including "white") aren\'t valid link color tokens, since they have no lighter hover states.';
1891
+ } @else if $link-grade == 100 {
1892
+ @warn '"black" isn\'t a valid link color token, since it has no darker hover state.';
1893
+ }
1894
+
1895
+ // Check that link meets contrast target
1896
+ @else if $link-magic-number >= $target-magic-number {
1897
+ $found: true;
1898
+ // Calculate additional link properties
1899
+
1900
+ $link-token: $color-token;
1901
+ @if not $custom {
1902
+ $link-family: nth($decomposed, 1);
1903
+ //@debug "link family: " + $link-family;
1904
+ $link-vivid: "";
1905
+ @if nth($decomposed, 3) {
1906
+ $link-vivid: "v";
1907
+ }
1908
+ }
1909
+
1910
+ // If link is darker than bg, use darker hover
1911
+ // Exclude black as it has no darker hover
1912
+ @if ($link-grade > $bg-grade) and ($link-grade != 100) {
1913
+ //@debug "Link is darker than background";
1914
+ @if $token-darker {
1915
+ //@debug "Getting darker token...";
1916
+ $hover-token: $token-darker;
1917
+ } @else {
1918
+ $hover-grade: $link-grade + $grade-step;
1919
+ $hover-vivid: if($hover-grade == 90, "", $link-vivid);
1920
+ $hover-token: if(
1921
+ $hover-grade == 100,
1922
+ "black",
1923
+ #{$link-family}-#{$hover-grade}#{$hover-vivid}
1924
+ );
1925
+ }
1926
+ }
1927
+
1928
+ // If link is lighter than bg, use lighter hover
1929
+ // Exclude white equivalents as they have no lighter hover
1930
+ @else if ($link-grade != 0) and ($link-grade != 100) {
1931
+ //@debug "Link is lighter than background";
1932
+ @if $token-lighter {
1933
+ //@debug "Getting lighter token...";
1934
+ $hover-token: $token-lighter;
1935
+ } @else {
1936
+ $hover-grade: $link-grade - $grade-step;
1937
+ $hover-token: if(
1938
+ $hover-grade == 0,
1939
+ "white",
1940
+ #{$link-family}-#{$hover-grade}#{$link-vivid}
1941
+ );
1942
+ }
1943
+ }
1944
+ }
1945
+ }
1946
+ }
1947
+
1948
+ @if not $hover-token {
1949
+ @error 'Neither "#{$preferred-link-color}" nor "#{$fallback-link-color}" can be #{$wcag-target} contrast links and hovers on a "#{$bg-color}" background.';
1950
+ }
1951
+
1952
+ //@debug "#{$link-token}, #{$hover-token}";
1953
+ @return $link-token, $hover-token;
1954
+ }