Skip to content

Commit 6961a5f

Browse files
Update pst styling (#642)
1 parent af3d212 commit 6961a5f

19 files changed

+427
-281
lines changed

assets/theme-css/pst/abstracts/_accessibility.scss

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
// loading the math module
1+
@use "sass:color";
2+
@use "sass:map";
23
@use "sass:math";
34

4-
/**
5-
* Get color combinations that meet a minimum contrast ratio as per WCAG 2
6-
*/
5+
// Get color combinations that meet a minimum contrast ratio as per WCAG 2
6+
77
// @param {color} $bg - Background color of the element
88
// @param {color} optional $target-color-contrast-dark $target-color-contrast-light - Target text colors, defaul to our
99
// $foundation-black and $foundation-white colors
1010
// @return {color} $max-ratio-color - The color that has the highest contrast ratio
11-
//
1211
@function a11y-combination(
1312
$bg,
1413
$target-color-contrast-dark: $foundation-black,
@@ -22,15 +21,16 @@
2221

2322
@each $fg in $foregrounds {
2423
$contrast-ratio: get-contrast-ratio($bg, $fg);
24+
2525
@if $contrast-ratio >= $min-contrast-ratio {
2626
@return $fg;
2727
} @else if $contrast-ratio > $max-ratio {
2828
$max-ratio: $contrast-ratio;
2929
$max-ratio-color: $fg;
3030
}
3131
}
32-
@warn "Found no color leading to #{$min-contrast-ratio}:1 contrast ratio against #{$bg}...";
3332

33+
@warn "Found no color leading to #{$min-contrast-ratio}:1 contrast ratio against #{$bg}...";
3434
@return $max-ratio-color;
3535
}
3636

@@ -49,25 +49,25 @@
4949
// Return WCAG2.1 relative luminance
5050
// See https://www.w3.org/TR/WCAG/#dfn-relative-luminance
5151
// See https://www.w3.org/TR/WCAG/#dfn-contrast-ratio
52-
//
5352
@function luminance($target-color) {
5453
$rgb-col: (
55-
"r": red($target-color),
56-
"g": green($target-color),
57-
"b": blue($target-color),
54+
"r": color.red($target-color),
55+
"g": color.green($target-color),
56+
"b": color.blue($target-color),
5857
);
5958

6059
@each $channel, $value in $rgb-col {
6160
// here we get RsRGB, GsRGB, and BsRGB
62-
@if math.div($value, 255) <=0.03928 {
63-
$rgb-col: map-merge(
61+
// stylelint-disable-next-line number-max-precision
62+
@if math.div($value, 255) <= 0.04045 {
63+
$rgb-col: map.merge(
6464
$rgb-col,
6565
(
6666
$channel: math.div(math.div($value, 255), 12.92),
6767
)
6868
);
6969
} @else {
70-
$rgb-col: map-merge(
70+
$rgb-col: map.merge(
7171
$rgb-col,
7272
(
7373
$channel:
@@ -77,8 +77,9 @@
7777
}
7878
}
7979

80-
@return (
81-
0.2126 * map-get($rgb-col, "r") + 0.7152 * map-get($rgb-col, "g") + 0.0722 *
82-
map-get($rgb-col, "b")
83-
);
80+
$r: map.get($rgb-col, "r");
81+
$g: map.get($rgb-col, "g");
82+
$b: map.get($rgb-col, "b");
83+
84+
@return (0.2126 * $r + 0.7152 * $g + 0.0722 * $b);
8485
}

assets/theme-css/pst/abstracts/_color.scss

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
* Miscellaneous color functions and mixins
33
**/
44

5-
// loading the math module
5+
@use "sass:list";
6+
@use "sass:map";
7+
@use "sass:meta";
68
@use "sass:math";
9+
@use "sass:string";
710

811
// We must add ::before pseudo-element to some theme components (such as admonitions)
912
// because users were instructed to customize the background color this way.
1013
@mixin legacy-backdrop-placeholder {
11-
&:before {
14+
&::before {
1215
content: "";
1316
width: 100%;
1417
height: 100%;
1518
position: absolute;
1619
left: 0;
1720
top: 0;
1821
z-index: -1;
22+
1923
// So that hovering over the text within background is still possible.
2024
// Otherwise the background overlays the text and you cannot click or select easily.
2125
// ref: https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
@@ -31,8 +35,9 @@
3135
// @return {*}
3236
@function map-deep-get($map, $keys...) {
3337
@each $key in $keys {
34-
$map: map-get($map, $key);
38+
$map: map.get($map, $key);
3539
}
40+
3641
@return $map;
3742
}
3843

@@ -44,9 +49,10 @@
4449
// @param {String/Color} $color - Color definition from map
4550
// @return {Color} - Color type (in hex)
4651
@function check-color($color) {
47-
@if type-of($color) == string {
52+
@if meta.type-of($color) == string {
4853
$color: from-hex($color);
4954
}
55+
5056
@return $color;
5157
}
5258

@@ -55,12 +61,12 @@
5561
*/
5662
// @param {String} $string - String representation of a color
5763
@function from-hex($string) {
58-
$string-lower: to-lower-case($string);
64+
$string-lower: string.to-lower-case($string);
5965
$r: "";
6066
$g: "";
6167
$b: "";
6268
$hex: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f";
63-
$length: str-length($string);
69+
$length: string.length($string);
6470
$max: if($length == 4, 1, 2);
6571

6672
// Check for length accuracy
@@ -70,18 +76,18 @@
7076

7177
// Loop from the second character (omitting #)
7278
@for $i from 2 through $length {
73-
$c: str-slice($string-lower, $i, $i);
79+
$c: string.slice($string-lower, $i, $i);
7480

7581
// If wrong character, return
76-
@if index($hex, $c) == null {
82+
@if not list.index($hex, $c) {
7783
@return $string;
7884
}
7985

80-
@if str-length($r) < $max {
86+
@if string.length($r) < $max {
8187
$r: $r + $c;
82-
} @else if str-length($g) < $max {
88+
} @else if string.length($g) < $max {
8389
$g: $g + $c;
84-
} @else if str-length($b) < $max {
90+
} @else if string.length($b) < $max {
8591
$b: $b + $c;
8692
}
8793
}
@@ -92,18 +98,18 @@
9298
$b: $b + $b;
9399
}
94100

95-
@return rgb(_hex-to-dec($r), _hex-to-dec($g), _hex-to-dec($b));
101+
@return rgb(hex-to-dec($r), hex-to-dec($g), hex-to-dec($b));
96102
}
97103

98-
@function _hex-to-dec($string) {
104+
@function hex-to-dec($string) {
99105
$hex: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f";
100-
$string: to-lower-case($string);
101-
$length: str-length($string);
102-
106+
$string: string.to-lower-case($string);
107+
$length: string.length($string);
103108
$dec: 0;
109+
104110
@for $i from 1 through $length {
105111
$factor: 1 + (15 * ($length - $i));
106-
$index: index($hex, str-slice($string, $i, $i));
112+
$index: list.index($hex, string.slice($string, $i, $i));
107113
$dec: $dec + $factor * ($index - 1);
108114
}
109115

0 commit comments

Comments
 (0)