unit.gl 0.0.35 → 0.0.39

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.
Files changed (72) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +30 -74
  3. package/css/unit.gl.css +28 -65
  4. package/css/unit.gl.min.css +1 -1
  5. package/package.json +13 -8
  6. package/scss/_global.scss +5 -23
  7. package/scss/_reset.scss +13 -15
  8. package/scss/classes/_guide.scss +126 -0
  9. package/scss/classes/_index.scss +25 -11
  10. package/scss/classes/_ratio.scss +30 -0
  11. package/scss/dev/_banner.scss +30 -1
  12. package/scss/dev/_index.scss +0 -0
  13. package/scss/functions/_color.scss +40 -0
  14. package/scss/functions/_index.scss +39 -16
  15. package/scss/functions/_layer.scss +48 -0
  16. package/scss/functions/_ratio.scss +58 -157
  17. package/scss/functions/_scale.scss +55 -49
  18. package/scss/functions/_sequence.scss +154 -126
  19. package/scss/functions/_view.scss +40 -0
  20. package/scss/functions/math/_arithmetic.scss +102 -0
  21. package/scss/functions/math/_index.scss +30 -0
  22. package/scss/functions/unit/_index.scss +30 -0
  23. package/scss/functions/unit/_unit_conversion.scss +94 -0
  24. package/scss/functions/{_unit_functions.scss → unit/_unit_functions.scss} +70 -36
  25. package/scss/index.scss +2 -16
  26. package/scss/maps/_color.scss +43 -0
  27. package/scss/maps/_index.scss +1 -0
  28. package/scss/mixins/_device.scss +63 -25
  29. package/scss/mixins/_display.scss +106 -44
  30. package/scss/mixins/_guide.scss +191 -158
  31. package/scss/mixins/_helper.scss +287 -52
  32. package/scss/mixins/_index.scss +50 -17
  33. package/scss/mixins/_paper.scss +38 -17
  34. package/scss/mixins/_ratio.scss +30 -13
  35. package/scss/mixins/_unit.scss +94 -0
  36. package/scss/mixins/_view.scss +123 -44
  37. package/scss/tags/_index.scss +30 -0
  38. package/scss/tags/_unit.scss +40 -0
  39. package/scss/utilities/_guides.scss +103 -0
  40. package/scss/utilities/_index.scss +6 -0
  41. package/scss/variables/_color.scss +83 -0
  42. package/scss/variables/_device.scss +140 -50
  43. package/scss/variables/_index.scss +84 -16
  44. package/scss/variables/_layer.scss +148 -51
  45. package/scss/variables/_paper.scss +243 -17
  46. package/scss/variables/_ratio.scss +224 -0
  47. package/scss/variables/_scale.scss +230 -104
  48. package/scss/variables/_unit.scss +76 -72
  49. package/scss/variables/_view.scss +135 -39
  50. package/ts/AspectRatio.ts +29 -0
  51. package/ts/Border.ts +29 -0
  52. package/ts/BoxModel.ts +40 -0
  53. package/ts/FlexContainer.ts +48 -0
  54. package/ts/Grid.ts +21 -0
  55. package/ts/GridContainer.ts +33 -0
  56. package/ts/Layout.ts +34 -0
  57. package/ts/Position.ts +28 -0
  58. package/ts/Rectangle.ts +28 -0
  59. package/ts/ResponsiveImage.ts +28 -0
  60. package/ts/ResponsiveScale.ts +21 -0
  61. package/ts/Size.ts +32 -0
  62. package/ts/Spacing.ts +68 -0
  63. package/ts/Transform.ts +38 -0
  64. package/ts/Typography.ts +41 -0
  65. package/ts/Unit.ts +57 -0
  66. package/ts/Viewport.ts +24 -0
  67. package/js/index.d.ts +0 -1
  68. package/js/index.js +0 -3
  69. package/js/unit.gl.min.js +0 -1
  70. package/scss/classes/_paper.scss +0 -97
  71. package/scss/functions/_arithmetic.scss +0 -64
  72. package/scss/functions/_unit_conversion.scss +0 -77
@@ -1,172 +1,73 @@
1
- // Copyright 2024 Scape Agency BV
2
-
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
-
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
-
16
1
  // ============================================================================
17
- // Math | Ratio's
2
+ // Poster
18
3
  // ============================================================================
19
4
 
5
+ ////
6
+ ///
7
+ /// Ratio Functions Module
8
+ /// ===========================================================================
9
+ ///
10
+ /// This module provides functions for calculating sizes based on well-known
11
+ /// mathematical ratios, such as the golden ratio. These functions are useful
12
+ /// for maintaining harmonious proportions in design elements like spacing,
13
+ /// typography, and layout.
14
+ ///
15
+ /// @group Ratio
16
+ /// @author Scape Agency
17
+ /// @link https://unit.gl
18
+ /// @since 0.1.0 initial release
19
+ /// @todo None
20
+ /// @access public
21
+ ///
22
+ ////
20
23
 
21
24
 
25
+ // ============================================================================
26
+ // Use
27
+ // ============================================================================
22
28
 
23
- // Modular Scale Ratios Map
24
- // This map contains common ratios used in modular scale calculations.
25
- $ratio: (
26
-
27
- // Musical Minor Interval
28
- // ------------------------------------------------------------------------
29
- "minor_second": 1.067, // Minor second interval
30
- "minor_third": 1.2, // Minor third interval
31
- "minor_fourth": 1.334, // Minor fourth interval (also known as diminished fifth)
32
- "minor_fifth": 1.5, // Minor fifth interval
33
- "minor_sixth": 1.6, // Minor sixth interval
34
- "minor_seventh": 1.778, // Minor seventh interval
35
- "minor_octave": 2, // Minor octave interval
36
-
37
- // Musical Major Interval
38
- // ------------------------------------------------------------------------
39
- "major_second": 1.125, // Major second interval
40
- "major_third": 1.25, // Major third interval
41
- "major_fourth": 1.333, // Major fourth interval (perfect fourth)
42
- "major_fifth": 1.5, // Major fifth interval (perfect fifth)
43
- "major_sixth": 1.667, // Major sixth interval
44
- "major_seventh": 1.875, // Major seventh interval
45
- "major_octave": 2, // Major octave interval (perfect octave)
46
-
47
- // Musical Perfect Interval
48
- // ------------------------------------------------------------------------
49
- "perfect_unison": 1, // Perfect unison, the same note
50
- "perfect_second": 1.125, // Perfect second interval
51
- "perfect_third": 1.25, // Perfect third interval
52
- "perfect_fourth": 1.333, // Perfect fourth interval
53
- "perfect_fifth": 1.5, // Perfect fifth interval
54
- "perfect_sixth": 1.667, // Perfect sixth interval
55
- "perfect_seventh": 1.875, // Perfect seventh interval
56
- "perfect_octave": 2, // Perfect octave, double the frequency
57
- "perfect_ninth": 2.25, // Perfect ninth interval
58
- "perfect_tenth": 2.5, // Perfect tenth interval
59
- "perfect_eleventh": 2.667, // Perfect eleventh interval
60
- "perfect_twelfth": 3, // Perfect twelfth interval
61
- "perfect_thirteenth": 3.333, // Perfect thirteenth interval
62
- "perfect_fourteenth": 3.667, // Perfect fourteenth interval
63
- "perfect_fifteenth": 4, // Perfect fifteenth interval, double octave
64
- "double_octave": 4, // Twice the frequency of the perfect octave
65
- "triple_octave": 8, // Three times the frequency of the perfect octave
66
-
67
- // Musical Augmented Interval
68
- // ------------------------------------------------------------------------
69
- "augmented_unison": 1.059, // Slightly higher than perfect unison
70
- "augmented_second": 1.122, // Slightly higher than major second
71
- "augmented_third": 1.189, // Slightly higher than major third
72
- "augmented_fourth": 1.414, // Augmented fourth, also known as tritone
73
- "augmented_fifth": 1.587, // Slightly higher than perfect fifth
74
- "augmented_sixth": 1.682, // Slightly higher than major sixth
75
- "augmented_seventh": 1.782, // Slightly higher than major seventh
76
- "augmented_octave": 2.059, // Slightly higher than perfect octave
77
-
78
- // Musical Diminished Interval
79
- // ------------------------------------------------------------------------
80
- "diminished_unison": 0.943, // A diminished unison, slightly less than a perfect unison
81
- "diminished_second": 1.053, // Diminished second interval, slightly less than a minor second
82
- "diminished_third": 1.122, // Diminished third interval, slightly less than a minor third
83
- "diminished_fourth": 1.260, // Diminished fourth, slightly less than a perfect fourth
84
- "diminished_fifth": 1.414, // Tritone, halfway between a perfect fourth and perfect fifth
85
- "diminished_sixth": 1.587, // Diminished sixth interval, slightly less than a major sixth
86
- "diminished_seventh": 1.782, // Diminished seventh interval, slightly less than a major seventh
87
- "diminished_octave": 1.961, // A diminished octave, slightly less than a perfect octave
88
-
89
- // Root
90
- // ------------------------------------------------------------------------
91
- "root_two": 1.414, // Square root of 2
92
- "root_three": 1.732, // Square root of 3
93
- "root_four": 2, // Square root of 4
94
- "root_five": 2.236, // Square root of 5
95
-
96
- // Special
97
- // ------------------------------------------------------------------------
98
- "golden_ratio": 1.618,
99
- "silver_ratio": 2.414, // Analogous to the golden ratio
100
- "bronze_ratio": 1.927, // Analogous to silver and golden ratios
101
- "pythagorean": 1.732, // Pythagorean constant, square root of 3
102
- "phi": 1.618, // Another name for the golden ratio
103
- "pi": 3.142, // Mathematical Pi value
104
- "euler": 2.718, // Euler's number
105
- "square": 1.414, // Square root of 2
106
- "fibonacci": 1.618, // Fibonacci sequence ratio
107
- "plastic_number": 1.324, // Plastic constant, another unique irrational number
108
- "feigenbaum": 4.669, // Feigenbaum constant in chaos theory
109
- "apollonian": 1.306, // Apollonian gasket, related to circle packing
110
- "cosmic_ratio": 1.273, // Based on cosmic geometry
111
- "parthenon_ratio": 1.618, // Ratio used in the Parthenon's architecture
112
- "le_corbusier": 1.618, // Le Corbusier's modulor ratio
113
- "vesica_piscis": 1.732, // Ratio from the vesica piscis shape
114
- "egyptian_fraction": 1.571, // Ancient Egyptian architecture ratio
115
- "harmonic_mean": 1.455, // Harmonic mean, a type of average
116
- "gauss_constant": 0.834, // Gauss's constant related to the arithmetic-geometric mean
117
- "super_golden": 2.058, // Super golden ratio, a higher order of the golden ratio
118
29
 
119
- ) !default;
30
+ // ============================================================================
31
+ // Functions
32
+ // ============================================================================
120
33
 
121
34
 
35
+ ///
122
36
  /// Golden Ratio Function
123
- /// A simple function to calculate sizes using the golden ratio, which can be
124
- /// used for spacing, sizing elements, etc.
125
- @function golden-ratio($size, $increment: 1) {
37
+ /// ---------------------------------------------------------------------------
38
+ ///
39
+ /// Calculates a size using the golden ratio (approximately 1.618), which is
40
+ /// widely used in design for its aesthetically pleasing proportions.
41
+ ///
42
+ /// @name ratio_golden
43
+ /// @param {Number} $size - The base size to scale.
44
+ /// @param {Number} $increment - The exponent applied to the golden ratio, default is 1.
45
+ /// @return {Number} - The calculated size based on the golden ratio.
46
+ ///
47
+ /// @example scss - Usage Example
48
+ /// // Increase size using the golden ratio
49
+ /// .element {
50
+ /// width: golden_ratio(16px, 1); // Output: 25.888px
51
+ /// }
52
+ ///
53
+ /// // Decrease size using the golden ratio
54
+ /// .small-element {
55
+ /// width: golden_ratio(16px, -1); // Output: 9.888px
56
+ /// }
57
+ ///
58
+ @function ratio_golden($size, $increment: 1) {
126
59
  $golden-ratio: 1.618;
127
- @return $size * pow($golden-ratio, $increment);
128
- }
129
-
130
-
131
60
 
61
+ // Validate the input size
62
+ @if not unitless($size) and type-of($size) != 'number' {
63
+ @error "The size parameter must be a valid number or unitless value.";
64
+ }
132
65
 
133
- // Modular Scale Function
134
- /// Calculates sizes (like font-size, spacing) based on a modular scale.
135
- /// This is useful for maintaining harmonious proportions in typography and layout.
136
- /// @param $increment - The step on the scale, can be positive or negative.
137
- /// @param $base - The base value to scale from, defaults to 1em (typographic base size).
138
- /// @param $ratio - The ratio to use for scaling, defaults to the Golden Ratio.
139
- /// @return - The calculated value based on the modular scale.
140
- @function modular-scale($increment: 1, $base: 1em, $ratio: 1.618) {
141
- // Validate inputs
66
+ // Validate the increment
142
67
  @if type-of($increment) != 'number' {
143
- @error "Step must be a number.";
144
- }
145
-
146
- @if type-of($base) != 'number' and not unitless($base) {
147
- @error "Base must be a number with or without units.";
148
- }
149
-
150
- @if type-of($ratio) != 'number' or $ratio <= 0 {
151
- @error "Ratio must be a positive number.";
68
+ @error "The increment parameter must be a valid number.";
152
69
  }
153
-
154
- // Calculate the modular scale value
155
- @return $base * pow($ratio, $increment);
156
- }
157
-
158
- // $ratio: map-get($ratio, $ratio-name);
159
-
160
-
161
- // body {
162
- // font-size: modular-scale(0); // Equal to the base size, 1em
163
- // }
164
-
165
- // h1 {
166
- // font-size: modular-scale(2); // Larger than the base size
167
- // }
168
-
169
- // .small-text {
170
- // font-size: modular-scale(-1); // Smaller than the base size
171
- // }
172
-
70
+
71
+ // Return the size scaled by the golden ratio raised to the increment
72
+ @return $size * pow($golden-ratio, $increment);
73
+ }
@@ -1,58 +1,64 @@
1
- // Copyright 2024 Scape Agency BV
2
-
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
-
7
- // http://www.apache.org/licenses/LICENSE-2.0
1
+ // ============================================================================
2
+ // Poster
3
+ // ============================================================================
8
4
 
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
5
+ ////
6
+ ///
7
+ /// Scale Functions Module
8
+ /// ===========================================================================
9
+ ///
10
+ /// This module defines various scales used for designing harmonious layouts
11
+ /// and typographies, including musical scales and a classic typographic scale.
12
+ /// It also provides a function to calculate values based on a modular scale,
13
+ /// which is essential for maintaining consistent design proportions.
14
+ ///
15
+ /// @group Scale
16
+ /// @author Scape Agency
17
+ /// @link https://unit.gl
18
+ /// @since 0.1.0 initial release
19
+ /// @todo None
20
+ /// @access public
21
+ ///
22
+ ////
14
23
 
15
24
 
16
25
  // ============================================================================
17
- // Math | Scales
26
+ // Use
18
27
  // ============================================================================
19
28
 
20
29
 
21
- $scale_musical: (
22
- "monotonic": 1,
23
- "ditonic": 2,
24
- "tritonic": 3,
25
- "tetratonic": 4,
26
- "pentatonic": 5,
27
- "hexatonic": 6,
28
- "peptatonic": 7,
29
- "octatonic": 8,
30
- "nonatonic": 9,
31
- "dodecatonic": 12,
32
- ) !default;
30
+ // ============================================================================
31
+ // Functions
32
+ // ============================================================================
33
33
 
34
34
 
35
- /// Classic Typographic Scale
36
- /// Design software, such as Adobe InDesig, usually has such a scale.
37
- /// This scale has historical significance — used by typographers of the early
38
- /// Renaissance; it has remained unchanged for 400 years.
39
- $typographic_scale_classic: (
40
- 1: q( 6),
41
- 2: q( 7), // +1
42
- 3: q( 8), // +1
43
- 4: q( 9), // +1
44
- 5: q(10), // +1
45
- 6: q(11), // +1
46
- 7: q(12), // +1
47
- 8: q(14), // +2
48
- 9: q(16), // +2
49
- 10: q(18), // +2
50
- 11: q(21), // +3
51
- 12: q(24), // +3
52
- 13: q(36), // +12
53
- 14: q(48), // +12
54
- 15: q(60), // +12
55
- 16: q(72), // +12
56
- 17: q(84), // +12
57
- 18: q(96), // +12
58
- ) !default;
35
+ ///
36
+ /// Modular Scale Function
37
+ /// ---------------------------------------------------------------------------
38
+ ///
39
+ /// Calculates sizes (like font-size, spacing) based on a modular
40
+ /// scale. This helps maintain harmonious proportions across a design.
41
+ ///
42
+ /// @name modular_scale
43
+ /// @param {Number} $increment - The step on the scale, can be positive or negative.
44
+ /// @param {Number} $base - The base value to scale from, defaults to 1em (typographic base size).
45
+ /// @param {Number} $ratio - The ratio to use for scaling, defaults to the Golden Ratio (1.618).
46
+ /// @return {Number} - The calculated value based on the modular scale.
47
+ ///
48
+ @function modular_scale($increment: 1, $base: 1em, $ratio: 1.618) {
49
+ // Validate inputs
50
+ @if type-of($increment) != 'number' {
51
+ @error "Step must be a number.";
52
+ }
53
+
54
+ @if type-of($base) != 'number' and not unitless($base) {
55
+ @error "Base must be a number with or without units.";
56
+ }
57
+
58
+ @if type-of($ratio) != 'number' or $ratio <= 0 {
59
+ @error "Ratio must be a positive number.";
60
+ }
61
+
62
+ // Calculate the modular scale value
63
+ @return $base * pow($ratio, $increment);
64
+ }