typey 1.0.0.beta.5 → 1.0.0.beta.6

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.
@@ -1,9 +1,15 @@
1
+ @import "typey/functions/helpers";
2
+ @import "typey/functions/validators";
3
+ @import "typey/functions/em-calculators";
4
+ @import "typey/functions/outputters";
5
+ @import "typey/functions/sizers";
6
+ @import "typey/functions/extras";
7
+ @import "typey/functions/depreciated";
1
8
  @import "typey/defaults";
2
- @import "typey/helpers";
3
9
  @import "typey/font-stacks";
4
- @import "typey/font-size";
5
- @import "typey/line-height";
6
- @import "typey/type-layout";
7
- @import "typey/weight";
8
- @import "typey/margin";
9
- @import "typey/padding";
10
+ @import "typey/mixins/define-type-sizing";
11
+ @import "typey/mixins/font-size";
12
+ @import "typey/mixins/line-height";
13
+ @import "typey/mixins/type-layout";
14
+ @import "typey/mixins/margin";
15
+ @import "typey/mixins/padding";
@@ -2,16 +2,26 @@
2
2
  // Allowed units: px
3
3
  $browser-font-size: 16px !default;
4
4
 
5
+ // Allowed units: rem, em or px
6
+ $base-unit: rem !default;
7
+
5
8
  // The base font size will be used for most calculations involving font-size.
6
9
  // Allowed units: px
7
10
  $base-font-size: 16px !default;
8
11
 
9
12
  // The base line height will be used for most calculations involving height.
10
13
  // Allowed units: px
11
- $base-line-height: 21px !default;
14
+ $base-line-height: 20px !default;
12
15
 
13
- // Allowed units: rem, em or px
14
- $base-unit: rem !default;
16
+ // The method to calculate line-height. Allowed values: rhythm or ratio.
17
+ // Rhytm uses a vertical rhythm approach where line-height is specified as
18
+ // a multiple of the $base-line-height.
19
+ // Ratio uses a ratio approach where line-height is specified as a ratio
20
+ // of the elements font-size.
21
+ $line-height-method: rhythm !default;
22
+
23
+ // The default ratio of line-height to font-size.
24
+ $base-line-height-ratio: 1.25 !default;
15
25
 
16
26
  // By default we will provide fallbacks when rem is the base unit.
17
27
  $rem-fallback: true !default;
@@ -72,39 +82,3 @@ $font-weight: (
72
82
  @error "Size '#{$key}' in $font-size map is not specified in px";
73
83
  }
74
84
  }
75
-
76
- // Define defaults (in the HTML element).
77
- //
78
- // @param number $base-font-size
79
- // (optional) Use to set to anything other than the base value.
80
- // Allowed units: px
81
- // @param number $base-line-height
82
- // (optional) Use to set to anything other than the base value.
83
- // Allowed units: px
84
- @mixin define-type-sizing($base-font-size: $base-font-size, $base-line-height: $base-line-height) {
85
- @if $base-unit == rem {
86
- font-size: $base-font-size / $browser-font-size * 100%;
87
- @if $rem-fallback == true {
88
- line-height: $base-line-height;
89
- }
90
- line-height: output-unit($base-line-height / $base-font-size);
91
- }
92
- @if $base-unit == px {
93
- font-size: $base-font-size;
94
- line-height: $base-line-height;
95
- }
96
- @if $base-unit == em {
97
- font-size: $base-font-size / $browser-font-size * 100%;
98
- line-height: output-unit($base-line-height / $base-font-size);
99
- }
100
- @if $auto-print-sizing == true {
101
- @if $base-unit == rem or $base-unit == em {
102
- @media print {
103
- font-size: $print-font-size;
104
- }
105
- }
106
- @else {
107
- @warn "As you are not using a relative base unit (rem or em) automatic print media sizing will not work. Set $auto-print-sizing to false to hide this warning"
108
- }
109
- }
110
- }
@@ -9,17 +9,3 @@ $helvetica-stack: "Helvetica Neue", Helvetica, Arial, sans-serif;
9
9
  $baskerville-stack: Baskerville, "Baskerville Old Face", "Hoefler Text", Garamond, "Times New Roman", serif;
10
10
  $monaco-stack: Monaco, Consolas, "Lucida Console", monospace, monospace;
11
11
  $trebuchet-ms-stack: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif;
12
-
13
- // Extend a font by adding a web-safe stack to it.
14
- //
15
- // Example usage:
16
- // $new-font-stack: extend-font-stack("Open sans", $sans-serif-stack);
17
- //
18
- // @param string $font
19
- // The name of the font. Use inverted commas if there are spaces in the font
20
- // name. i.e "Open sans"
21
- // @param list $font-stack
22
- // The font stack variable to extend.
23
- @function extend-font-stack($font, $font-stack) {
24
- @return join($font, $font-stack, $separator: comma);
25
- }
@@ -0,0 +1,55 @@
1
+ // DEPRECIATED FUNCTIONS
2
+ // The names of these functions have been refined and namespaced (above) to avoid
3
+ // potential confusion with functions from other libraries.
4
+
5
+ // (Depreciated) Output a number in the $base-unit..
6
+ //
7
+ // @param string $weight
8
+ // A weight from the $font-weight map.
9
+ //
10
+ // @return string
11
+ // The selected font-weight.
12
+ @function output-unit($number) {
13
+ @warn "output-unit() is depreciated. Please use typey-output-in-base-unit() instead.";
14
+ @return typey-output-in-base-unit($number);
15
+ }
16
+
17
+ // (Depreciated) Remove the unit from a number.
18
+ //
19
+ // @param number $number
20
+ // The number (with unit) to convert. Allowed units: any
21
+ //
22
+ // @return number
23
+ // The number without the unit.
24
+ @function strip-unit($number) {
25
+ @warn "strip-unit() is depreciated. Please use typey-strip-unit() instead.";
26
+ @return typey-strip-unit($number);
27
+ }
28
+
29
+ // (Depreciated) Convert px to the $base-unit.
30
+ //
31
+ // @param number $number
32
+ // The number (with unit) to convert. Allowed units: px
33
+ // @param number|string $context
34
+ // (optional) Only used if em is the $base-unit. The value of the elements/parents
35
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
36
+ // value in px.
37
+ //
38
+ // @return number
39
+ // The number converted to the base unit.
40
+ @function convert-unit($number, $context: $base-font-size) {
41
+ @warn "convert-unit() is depreciated. Please use output-from-px() instead.";
42
+ @return output-from-px($number, $context);
43
+ }
44
+
45
+ // (Depreciated) Retrieve a font weight.
46
+ //
47
+ // @param string $weight
48
+ // A weight from the $font-weight map.
49
+ //
50
+ // @return string
51
+ // The selected font-weight.
52
+ @function font-weight($weight) {
53
+ @warn "font-weight() is depreciated. Please use weight() instead.";
54
+ @return weight($weight);
55
+ }
@@ -0,0 +1,41 @@
1
+ // Calculate relative sizing for em when a px value is used.
2
+ //
3
+ // @param number $number
4
+ // The px value
5
+ // @param number|string $context
6
+ // The relative value to perform the calculation.
7
+ //
8
+ // @return number
9
+ // The calculated value in the base unit.
10
+ @function calculate-em-px($x, $context) {
11
+ $allowed-types: "font-size", "px";
12
+ $type: typey-validator($context, $allowed-types);
13
+ @if $type == "font-size" {
14
+ $context-map-size: map-get($font-size, $context);
15
+ @return typey-output-in-base-unit(($x / $context-map-size));
16
+ }
17
+ @if $type == "px" {
18
+ @return typey-output-in-base-unit(($x / $context));
19
+ }
20
+ }
21
+
22
+ // Calculate relative sizing for em when a multiplier is used.
23
+ //
24
+ // @param number $number
25
+ // Multiple of line height to be used.
26
+ // @param number|string $context
27
+ // The relative value to perform the calculation.
28
+ //
29
+ // @return number
30
+ // The calculated value in the base unit.
31
+ @function calculate-em-multiplier($x, $context) {
32
+ $allowed-types: "font-size", "px";
33
+ $type: typey-validator($context, $allowed-types);
34
+ @if $type == "font-size" {
35
+ $context-map-size: map-get($font-size, $context);
36
+ @return typey-output-in-base-unit(($x * $base-line-height) / $context-map-size);
37
+ }
38
+ @if $type == "px" {
39
+ @return typey-output-in-base-unit(($x * $base-line-height) / $context);
40
+ }
41
+ }
@@ -19,14 +19,16 @@
19
19
  }
20
20
  }
21
21
 
22
- // (Depreciated) Retrieve a font weight.
22
+ // Extend a font by adding a web-safe stack to it.
23
23
  //
24
- // @param string $weight
25
- // A weight from the $font-weight map.
24
+ // Example usage:
25
+ // $new-font-stack: extend-font-stack("Open sans", $sans-serif-stack);
26
26
  //
27
- // @return string
28
- // The selected font-weight.
29
- @function font-weight($weight) {
30
- @warn "font-weight() is depreciated. Please use weight() instead.";
31
- @return weight($weight);
27
+ // @param string $font
28
+ // The name of the font. Use inverted commas if there are spaces in the font
29
+ // name. i.e "Open sans"
30
+ // @param list $font-stack
31
+ // The font stack variable to extend.
32
+ @function extend-font-stack($font, $font-stack) {
33
+ @return join($font, $font-stack, $separator: comma);
32
34
  }
@@ -0,0 +1,32 @@
1
+ // Output a number in the $base-unit.
2
+ //
3
+ // @param number $number
4
+ // The number (without unit) to output.
5
+ //
6
+ // @return number
7
+ // The number with the base unit
8
+ @function typey-output-in-base-unit($number) {
9
+ @if $base-unit == rem {
10
+ @return $number * 1rem;
11
+ }
12
+ @if $base-unit == px {
13
+ @return $number * 1px;
14
+ }
15
+ @if $base-unit == em {
16
+ @return $number * 1em;
17
+ }
18
+ }
19
+
20
+ // Remove the unit from a number.
21
+ //
22
+ // @param number $number
23
+ // The number (with unit) to convert. Allowed units: any
24
+ //
25
+ // @return number
26
+ // The number without the unit.
27
+ @function typey-strip-unit($number) {
28
+ @if type-of($number) == "number" and not unitless($number) {
29
+ @return $number / ($number * 0 + 1);
30
+ }
31
+ @return $number;
32
+ }
@@ -0,0 +1,83 @@
1
+ // Take a px value and output converted value.
2
+ //
3
+ // @param number $number
4
+ // A px value to convert.
5
+ // @param number|string $context
6
+ // (optional) Only used if em is the $base-unit. The value of the elements/parents
7
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
8
+ // value in px.
9
+ //
10
+ // @return number
11
+ // The number converted to the base unit.
12
+ @function output-from-px($number, $context: $base-font-size) {
13
+ @if $base-unit == rem {
14
+ @return typey-output-in-base-unit(($number / $base-font-size));
15
+ }
16
+ @if $base-unit == px {
17
+ @return typey-output-in-base-unit(typey-strip-unit($number));
18
+ }
19
+ @if $base-unit == em {
20
+ @return calculate-em-px($number, $context);
21
+ }
22
+ }
23
+
24
+ // Take a key from the $font-size map and output converted value.
25
+ //
26
+ // @param string $size
27
+ // A size from the $font-size map.
28
+ // @param number|string $context
29
+ // (optional) Only used if em is the $base-unit. The value of the parent
30
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
31
+ // value in px.
32
+ //
33
+ // @return number
34
+ // The selected font-size in $base-unit.
35
+ @function output-from-font-size-map($size, $context: $base-font-size) {
36
+ $map-size: map-get($font-size, $size);
37
+ @if $base-unit == rem {
38
+ @return typey-output-in-base-unit(($map-size / $base-font-size));
39
+ }
40
+ @if $base-unit == px or $base-unit == pt {
41
+ @return typey-output-in-base-unit(typey-strip-unit($map-size));
42
+ }
43
+ @if $base-unit == em {
44
+ @return calculate-em-px($map-size, $context);
45
+ }
46
+ }
47
+
48
+ // Take a line-height multipler and output converted value.
49
+ //
50
+ // @param number $number
51
+ // Multiple of line height to be used.
52
+ // @param number|string $context
53
+ // (optional) Only used if em is the $base-unit. The value of the elements/parents
54
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
55
+ // value in px.
56
+ //
57
+ // @return number
58
+ // The value of the line-height multiple converted to the base unit.
59
+ @function output-from-multiplier($x, $context: $base-font-size) {
60
+ @if $base-unit == rem {
61
+ @return typey-output-in-base-unit(($x * $base-line-height) / $base-font-size);
62
+ }
63
+ @if $base-unit == px {
64
+ @return typey-output-in-base-unit(typey-strip-unit($x * $base-line-height));
65
+ }
66
+ @if $base-unit == em {
67
+ @return calculate-em-multiplier($x, $context);
68
+ }
69
+ }
70
+
71
+ // Take a line-height ratio and output as em.
72
+ //
73
+ // @param number $ratio
74
+ // Multiple of the $font-size to be used.
75
+ // @param number|string $context
76
+ // (optional) used to ensure function outputs the ratio regardless of whether
77
+ // it is the same as the $base-line-height-ratio.
78
+ //
79
+ // @return number
80
+ // The ratio in em.
81
+ @function output-from-ratio($ratio: $base-line-height-ratio) {
82
+ @return $ratio * 1em;
83
+ }
@@ -0,0 +1,117 @@
1
+ // Takes a sizing from the $font-size map (m, xl, xxl, etc) and convert it to
2
+ // the base unit. Alternatively convert a px font-size into the base unit.
3
+ //
4
+ // @param number|string $size
5
+ // A size from the $font-size map or px value to be converted
6
+ // @param number|string $context
7
+ // (optional) Only used if em is the $base-unit. The value of the parent
8
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
9
+ // value in px.
10
+ //
11
+ // @return number
12
+ // The selected font-size in $base-unit.
13
+ @function font-size($size, $context: $base-font-size) {
14
+ $allowed-types: "font-size", "px";
15
+ $type: typey-validator($size, $allowed-types);
16
+ @if $type == "font-size" {
17
+ @return output-from-font-size-map($size, $context);
18
+ }
19
+ @if $type == "px" {
20
+ @return output-from-px($size, $context);
21
+ }
22
+ }
23
+
24
+ // Generate a value to be used as line-height from either:
25
+ // a) a multiple of $base-line-height
26
+ // b) a static px value
27
+ // c) a ratio of the font-size
28
+ //
29
+ // Example usage with multiple:
30
+ // line-height: line-height(2);
31
+ // Example usage with static value:
32
+ // line-height: line-height(18px);
33
+ // Example usage with ratio:
34
+ // line-height: line-height(1.5);
35
+ //
36
+ // @param number $x
37
+ // Multiple of line height to be used, px value to be converted, or ratio of
38
+ // font-size.
39
+ // @param number|string $context
40
+ // (optional) Only used if em is the $base-unit. The value of the
41
+ // elements/parents font-size if it differs from $base-font-size.
42
+ // Specified as a t-shirt size or value in px.
43
+ // @return number
44
+ // The calculated height in $base-unit.
45
+ @function line-height($x, $context: $base-font-size) {
46
+ $allowed-types: "multiplier", "px";
47
+ $type: typey-validator($x, $allowed-types);
48
+ @if $type == "multiplier" {
49
+ @if ($line-height-method == "ratio") {
50
+ @return output-from-ratio($x);
51
+ }
52
+ @else {
53
+ @return output-from-multiplier($x, $context);
54
+ }
55
+ }
56
+ @if $type == "px" {
57
+ @return output-from-px($x, $context);
58
+ }
59
+ }
60
+
61
+ // Generate a value to be used as margin from either:
62
+ // a) a multiple of $base-line-height
63
+ // b) a static px value
64
+ //
65
+ // Example usage with multiple:
66
+ // line-height: line-height(2);
67
+ // Example usage with static value:
68
+ // line-height: line-height(18px);
69
+ //
70
+ // @param number $x
71
+ // Multiple of line height to be used or px value to be converted.
72
+ // @param number|string $context
73
+ // (optional) Only used if em is the $base-unit. The value of the elements/parents
74
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
75
+ // value in px.
76
+ //
77
+ // @return number
78
+ // The calculated height in $base-unit.
79
+ @function margin($x, $context: $base-font-size) {
80
+ $allowed-types: "multiplier", "px";
81
+ $type: typey-validator($x, $allowed-types);
82
+ @if $type == "multiplier" {
83
+ @return output-from-multiplier($x, $context);
84
+ }
85
+ @if $type == "px" {
86
+ @return output-from-px($x, $context);
87
+ }
88
+ }
89
+
90
+ // Generate a value to be used as padding from either:
91
+ // a) a multiple of $base-line-height
92
+ // b) a static px value
93
+ //
94
+ // Example usage with multiple:
95
+ // line-height: line-height(2);
96
+ // Example usage with static value:
97
+ // line-height: line-height(18px);
98
+ //
99
+ // @param number $x
100
+ // Multiple of line height to be used or px value to be converted.
101
+ // @param number|string $context
102
+ // (optional) Only used if em is the $base-unit. The value of the elements/parents
103
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
104
+ // value in px.
105
+ //
106
+ // @return number
107
+ // The calculated height in $base-unit.
108
+ @function padding($x, $context: $base-font-size) {
109
+ $allowed-types: "multiplier", "px";
110
+ $type: typey-validator($x, $allowed-types);
111
+ @if $type == "multiplier" {
112
+ @return output-from-multiplier($x, $context);
113
+ }
114
+ @if $type == "px" {
115
+ @return output-from-px($x, $context);
116
+ }
117
+ }
@@ -0,0 +1,77 @@
1
+ // Takes a value and checks to ensure it's expressed correctly then returns
2
+ // the type.
3
+ //
4
+ // @param number|string|list $x
5
+ // A multiple of $base-line-height.
6
+ // A px value.
7
+ // A size from the $font-size map.
8
+ // A space seperated list container multiples and/or px values.
9
+ //
10
+ // @return string
11
+ // multiplier, px, font-size, list
12
+ @function typey-check-value($x) {
13
+ @if type-of($x) == "number" {
14
+ @if unitless($x) {
15
+ @return "multiplier";
16
+ }
17
+ @if not unitless($x) {
18
+ @if unit($x) == px {
19
+ @return "px";
20
+ }
21
+ @else {
22
+ @error "All units must be expressed in px";
23
+ }
24
+ }
25
+ }
26
+ @if type-of($x) == "string" {
27
+ @if map-has-key($font-size, $x) {
28
+ @return "font-size";
29
+ }
30
+ @else {
31
+ @error "'#{$x}' not found in $font-size map";
32
+ }
33
+ }
34
+ @if type-of($x) == "list" {
35
+ @if list-separator($x) == space {
36
+ @each $value in $x {
37
+ @if type-of($value) == "number" {
38
+ @if not unitless($value) and unit($value) != px {
39
+ @error "All units must be expressed in px";
40
+ }
41
+ }
42
+ @else {
43
+ @error "Values specified inside lists must be a number";
44
+ }
45
+ }
46
+ @return "list";
47
+ }
48
+ @else {
49
+ @error "All lists must use a space as their seperator";
50
+ }
51
+ }
52
+ @else {
53
+ @return type-of($x);
54
+ }
55
+ }
56
+
57
+ // Takes a value and validates it against a specified type.
58
+ //
59
+ // @param number|string|list $x
60
+ // A multiple of $base-line-height.
61
+ // A px value.
62
+ // A size from the $font-size map.
63
+ // A space seperated list container multiples and/or px values.
64
+ // @param string|list $allowed-types
65
+ // Either multiplier, px, font-size, list, or a comibation specified in a list.
66
+ //
67
+ // @return string
68
+ // The values type.
69
+ @function typey-validator($x, $allowed-types) {
70
+ $type: typey-check-value($x);
71
+ @if index($allowed-types, $type) != null {
72
+ @return $type;
73
+ }
74
+ @else {
75
+ @error "'#{$type}' is not a valid type for this function (allowed types are: #{$allowed-types})";
76
+ }
77
+ }
@@ -0,0 +1,49 @@
1
+ // Define defaults (use this in the HTML element).
2
+ //
3
+ // @param number $size
4
+ // (optional) The font-size. Use to set to anything other than $base-font-size.
5
+ // @param number $line-height
6
+ // (optional) The line-height. Use to set to anything other than $base-line-height.
7
+ // Set to a ratio when $line-height-as-ratio is true. Will default to $base-line-height-ratio.
8
+ // Set to false if you do not want to change a ratio of line-height already set.
9
+ @mixin define-type-sizing($size: $base-font-size, $line-height: $base-line-height) {
10
+ @if $base-unit == rem or $base-unit == em {
11
+ font-size: $size / $browser-font-size * 100%;
12
+ }
13
+ @if $base-unit == px {
14
+ font-size: $size;
15
+ }
16
+
17
+ @if $line-height != false {
18
+ @if $line-height-method == "ratio" {
19
+ @if $line-height == $base-line-height {
20
+ $line-height: $base-line-height-ratio;
21
+ }
22
+ line-height: $line-height * 1em;
23
+ }
24
+ @else {
25
+ @if $base-unit == rem {
26
+ @if $rem-fallback == true {
27
+ line-height: $line-height;
28
+ }
29
+ }
30
+ @if $base-unit == rem or $base-unit == em {
31
+ line-height: typey-output-in-base-unit($line-height / $size);
32
+ }
33
+ @if $base-unit == px {
34
+ line-height: $line-height;
35
+ }
36
+ }
37
+ }
38
+
39
+ @if $auto-print-sizing == true {
40
+ @if $base-unit == rem or $base-unit == em {
41
+ @media print {
42
+ font-size: $print-font-size;
43
+ }
44
+ }
45
+ @else {
46
+ @warn "As you are not using a relative base unit (rem or em) automatic print media sizing will not work. Set $auto-print-sizing to false to hide this warning"
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,24 @@
1
+ // Define font-size (with fallback)
2
+ //
3
+ // @param number|string $size
4
+ // A size from the $font-size map or px value to be converted
5
+ // @param number|string $context
6
+ // (optional) Only used if em is the $base-unit. The value of the elements/parents
7
+ // font-size if it differs from $base-font-size. Specified as a t-shirt size or
8
+ // value in px.
9
+ @mixin font-size($size, $context: $base-font-size) {
10
+ $allowed-types: "font-size", "px";
11
+ $type: typey-validator($size, $allowed-types);
12
+ @if $base-unit == rem {
13
+ @if $rem-fallback == true {
14
+ @if $type == "font-size" {
15
+ $map-size: map-get($font-size, $size);
16
+ font-size: $map-size;
17
+ }
18
+ @if $type == "px" {
19
+ font-size: $size;
20
+ }
21
+ }
22
+ }
23
+ font-size: font-size($size, $context);
24
+ }
@@ -0,0 +1,25 @@
1
+ // Define line-height (with fallback).
2
+ // This is only necessary to use if you want to provide fallbacks when you are
3
+ // using rem as $base-unit.
4
+ //
5
+ // @param number $x
6
+ // Multiple of line height to be used or px value to be converted.
7
+ // @param number|string $context
8
+ // (optional) Only used if em is the $base-unit. The value of the
9
+ // elements/parents font-size if it differs from $base-font-size.
10
+ // Specified as a t-shirt size or value in px.
11
+ @mixin line-height($x, $context: $base-font-size) {
12
+ $allowed-types: "multiplier", "px";
13
+ $type: typey-validator($x, $allowed-types);
14
+ @if $base-unit == rem and $line-height-method == "rhythm" {
15
+ @if $rem-fallback == true {
16
+ @if $type == "multiplier" {
17
+ line-height: $x * $base-line-height;
18
+ }
19
+ @if $type == "px" {
20
+ line-height: $x;
21
+ }
22
+ }
23
+ }
24
+ line-height: line-height($x, $context);
25
+ }