gerillass 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "author": "Halil İbrahim Çakıroğlu",
7
7
  "main": "scss/_gerillass.scss",
8
8
  "license": "Apache-2.0",
9
- "version": "1.3.3",
9
+ "version": "1.4.0",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "git+https://github.com/selfishprimate/gerillass.git"
@@ -961,27 +961,7 @@
961
961
  &::before {
962
962
  content: "";
963
963
  display: block;
964
- @if not $ratio {
965
- padding-top: 56.25%;
966
- } @else if $ratio {
967
- @if type-of($ratio) == string {
968
- $width: null;
969
- $height: null;
970
- @if str-index($ratio, "/") {
971
- $fslash-index: str-index($ratio, "/");
972
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
973
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
974
- } @else if str-index($ratio, ":") {
975
- $colon-index: str-index($ratio, ":");
976
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
977
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
978
- }
979
- $calc: math.div($height, $width) * 100;
980
- padding-top: #{$calc * 1%};
981
- } @else if type-of($ratio) == number {
982
- padding-top: math.div(1, $ratio) * 100%;
983
- }
984
- }
964
+ padding-top: __validateRatio($ratio);
985
965
  }
986
966
  & > * {
987
967
  width: 100%;
@@ -1115,27 +1095,7 @@
1115
1095
  &::before {
1116
1096
  content: "";
1117
1097
  display: block;
1118
- @if not $ratio {
1119
- padding-top: 56.25%;
1120
- } @else if $ratio {
1121
- @if type-of($ratio) == string {
1122
- $width: null;
1123
- $height: null;
1124
- @if str-index($ratio, "/") {
1125
- $fslash-index: str-index($ratio, "/");
1126
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
1127
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
1128
- } @else if str-index($ratio, ":") {
1129
- $colon-index: str-index($ratio, ":");
1130
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
1131
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
1132
- }
1133
- $calc: math.div($height, $width) * 100;
1134
- padding-top: #{$calc * 1%};
1135
- } @else if type-of($ratio) == number {
1136
- padding-top: math.div(1, $ratio) * 100%;
1137
- }
1138
- }
1098
+ padding-top: __validateRatio($ratio);
1139
1099
  }
1140
1100
  & > * {
1141
1101
  width: 100%;
@@ -38,6 +38,7 @@
38
38
  @import "utilities/shorthand-property";
39
39
  @import "utilities/validate-breakpoint";
40
40
  @import "utilities/validate-length";
41
+ @import "utilities/validate-ratio";
41
42
  @import "utilities/validate-scissors";
42
43
 
43
44
  @import "library/adaptive";
@@ -5,27 +5,7 @@
5
5
  &::before {
6
6
  content: "";
7
7
  display: block;
8
- @if not $ratio {
9
- padding-top: 56.25%;
10
- } @else if $ratio {
11
- @if type-of($ratio) == string {
12
- $width: null;
13
- $height: null;
14
- @if str-index($ratio, "/") {
15
- $fslash-index: str-index($ratio, "/");
16
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
17
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
18
- } @else if str-index($ratio, ":") {
19
- $colon-index: str-index($ratio, ":");
20
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
21
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
22
- }
23
- $calc: math.div($height, $width) * 100;
24
- padding-top: #{$calc * 1%};
25
- } @else if type-of($ratio) == number {
26
- padding-top: math.div(1, $ratio) * 100%;
27
- }
28
- }
8
+ padding-top: __validateRatio($ratio);
29
9
  }
30
10
  & > * {
31
11
  width: 100%;
@@ -5,27 +5,7 @@
5
5
  &::before {
6
6
  content: "";
7
7
  display: block;
8
- @if not $ratio {
9
- padding-top: 56.25%;
10
- } @else if $ratio {
11
- @if type-of($ratio) == string {
12
- $width: null;
13
- $height: null;
14
- @if str-index($ratio, "/") {
15
- $fslash-index: str-index($ratio, "/");
16
- $width: __convertToNumber(str-slice($ratio, 1, $fslash-index - 1));
17
- $height: __convertToNumber(str-slice($ratio, $fslash-index + 1));
18
- } @else if str-index($ratio, ":") {
19
- $colon-index: str-index($ratio, ":");
20
- $width: __convertToNumber(str-slice($ratio, 1, $colon-index - 1));
21
- $height: __convertToNumber(str-slice($ratio, $colon-index + 1));
22
- }
23
- $calc: math.div($height, $width) * 100;
24
- padding-top: #{$calc * 1%};
25
- } @else if type-of($ratio) == number {
26
- padding-top: math.div(1, $ratio) * 100%;
27
- }
28
- }
8
+ padding-top: __validateRatio($ratio);
29
9
  }
30
10
  & > * {
31
11
  width: 100%;
@@ -0,0 +1,42 @@
1
+ @charset "UTF-8";
2
+
3
+ @function __validateRatio($ratio) {
4
+ // No argument at all keeps the 16/9 default.
5
+ @if $ratio == null {
6
+ @return 56.25%;
7
+ }
8
+
9
+ @if type-of($ratio) == "number" {
10
+ @if not unitless($ratio) {
11
+ @error "`#{$ratio}` is not a valid ratio. A numeric ratio must be unitless, like `1.77`.";
12
+ }
13
+ @if $ratio <= 0 {
14
+ @error "`#{$ratio}` is not a valid ratio. A numeric ratio must be greater than zero.";
15
+ }
16
+ @return math.div(1, $ratio) * 100%;
17
+ }
18
+
19
+ @if type-of($ratio) == "string" {
20
+ $separator: null;
21
+ @if str-index($ratio, "/") {
22
+ $separator: str-index($ratio, "/");
23
+ } @else if str-index($ratio, ":") {
24
+ $separator: str-index($ratio, ":");
25
+ } @else {
26
+ @error "`#{$ratio}` is not a valid ratio. A string ratio must separate width and height with `/` or `:`, like `\"16/9\"` or `\"16:9\"`.";
27
+ }
28
+
29
+ $width: __convertToNumber(str-slice($ratio, 1, $separator - 1));
30
+ $height: __convertToNumber(str-slice($ratio, $separator + 1));
31
+
32
+ @if $width == 0 {
33
+ @error "`#{$ratio}` is not a valid ratio. The width must be greater than zero.";
34
+ }
35
+ @return math.div($height, $width) * 100%;
36
+ }
37
+
38
+ // Anything else -- most commonly a list, which is what `16/9` becomes once
39
+ // Dart Sass 2.0.0 removes slash division. Without this the mixin would emit
40
+ // no padding-top at all and silently produce a ratio box with no ratio.
41
+ @error "`#{$ratio}` is not a valid ratio. Pass a string like `\"16/9\"` or `\"16:9\"`, a unitless number like `1.77`, or no argument at all for the 16/9 default. You passed a #{type-of($ratio)}.";
42
+ }