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,146 +1,272 @@
1
- // Copyright 2024 Scape Agency BV
1
+ // ============================================================================
2
+ // Poster
3
+ // ============================================================================
2
4
 
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
5
+ ////
6
+ ///
7
+ /// Scale Variables Module
8
+ /// ===========================================================================
9
+ ///
10
+ /// This module defines the base typographic and spacing scales used throughout
11
+ /// the project, leveraging a rhythm-based approach for consistent vertical
12
+ /// spacing and typographic hierarchy. The Kyū Point and Baseline scales
13
+ /// provide a flexible system for responsive design.
14
+ ///
15
+ /// @group Scale
16
+ /// @author Scape Agency
17
+ /// @link https://unit.gl
18
+ /// @since 0.1.0 initial release
19
+ /// @todo None
20
+ /// @requires "unit" - module for unit conversion and scaling functions.
21
+ /// @access public
22
+ ///
23
+ ////
6
24
 
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
25
 
26
+ // ============================================================================
27
+ // Use
28
+ // ============================================================================
15
29
 
16
30
  @use "unit" as *;
17
31
 
18
32
 
19
- // $rhythm_base: q(4);
20
- $rhythm_base: $q *4;
33
+ // ============================================================================
34
+ // Variables
35
+ // ============================================================================
21
36
 
22
- $line_height_ratio: 1.5;
23
37
 
24
- $font_size_scalar: 4;
25
- $line_height_scalar: calc($line_height_ratio * $font_size_scalar);
38
+ ///
39
+ /// The base rhythm unit used for vertical spacing and typography.
40
+ ///
41
+ /// @name $rhythm_base
42
+ /// @type Length
43
+ ///
44
+ $rhythm_base: $q * 4 !default;
26
45
 
27
46
 
47
+ ///
48
+ /// The ratio of line height to font size, defining the line height.
49
+ ///
50
+ /// @name $line_height_ratio
51
+ /// @type Number
52
+ ///
53
+ $line_height_ratio: 1.5 !default;
28
54
 
29
- $font_size_base: calc($font_size_scalar * $rhythm_base); // Base font size
30
- $line_height_base: calc($line_height_scalar * $rhythm_base); // Base line height (1.5 times the font size is a good start)
31
55
 
56
+ ///
57
+ /// A scalar to define the base font size relative to the rhythm base.
58
+ ///
59
+ /// @name $font_size_scalar
60
+ /// @type Number
61
+ ///
62
+ $font_size_scalar: 4 !default;
32
63
 
33
64
 
34
- // Typography ladder map
35
- $typographic_scale: (
36
- 1: q( 4),
37
- 2: q( 6), // +2
38
- 3: q( 8), // +2
39
- 4: q(10), // +2
40
- 5: q(12), // +2
41
- 6: q(14), // +2
42
- 7: q(16), // +2
43
- 8: q(20), // +4
44
- 9: q(24), // +4
45
- 10: q(28), // +4
46
- 11: q(32), // +4
47
- 12: q(36), // +4
48
- 13: q(40), // +4
49
- 14: q(48), // +8
50
- 15: q(56), // +8
51
- 16: q(64), // +8
52
- 17: q(72), // +8
53
- ) !default;
65
+ ///
66
+ /// A scalar to define the base line height, calculated from the line height
67
+ /// ratio and font size scalar.
68
+ ///
69
+ /// @name $line_height_scalar
70
+ /// @type Length
71
+ ///
72
+ $line_height_scalar: calc($line_height_ratio * $font_size_scalar) !default;
73
+
54
74
 
55
- // 'display': $q-base * 96, // For large display text
56
- // 'h1': $q-base * 48, // For primary headings
57
- // 'h2': $q-base * 36, // For secondary headings
58
- // 'h3': $q-base * 24, // For tertiary headings
59
- // 'h4': $q-base * 20, // For quaternary headings
60
- // 'h5': $q-base * 18, // For quinary headings
61
- // 'h6': $q-base * 16, // For senary headings
62
- // 'body-large': $q-base * 14, // For large body text
63
- // 'body': $q-base * 12, // For main body text
64
- // 'body-small': $q-base * 10, // For small body text
65
- // 'caption': $q-base * 8, // For captions and overlines
66
- // 'overline': $q-base * 6 // For the smallest size, like legal text
67
- // ) !default;
75
+ ///
76
+ /// The base font size, calculated as a multiple of the rhythm base.
77
+ ///
78
+ /// @name $font_size_base
79
+ /// @type Length
80
+ ///
81
+ $font_size_base: calc($font_size_scalar * $rhythm_base) !default;
68
82
 
69
83
 
84
+ ///
85
+ /// The base line height, calculated from the line height scalar and rhythm
86
+ /// base.
87
+ ///
88
+ /// @name $line_height_base
89
+ /// @type Length
90
+ ///
91
+ $line_height_base: calc($line_height_scalar * $rhythm_base) !default;
92
+
93
+
94
+ ///
95
+ /// Typographic Scale Map
96
+ /// ---------------------------------------------------------------------------
97
+ ///
98
+ /// A modular scale for typography, based on rhythm units. Each step in the
99
+ /// scale is a multiple of the rhythm base.
100
+ ///
101
+ /// @name $typographic_scale
102
+ /// @type Map
103
+ ///
104
+ $typographic_scale: (
105
+ 1: q(4),
106
+ 2: q(6), // +2 units
107
+ 3: q(8), // +2 units
108
+ 4: q(10), // +2 units
109
+ 5: q(12), // +2 units
110
+ 6: q(14), // +2 units
111
+ 7: q(16), // +2 units
112
+ 8: q(20), // +4 units
113
+ 9: q(24), // +4 units
114
+ 10: q(28), // +4 units
115
+ 11: q(32), // +4 units
116
+ 12: q(36), // +4 units
117
+ 13: q(40), // +4 units
118
+ 14: q(48), // +8 units
119
+ 15: q(56), // +8 units
120
+ 16: q(64), // +8 units
121
+ 17: q(72) // +8 units
122
+ ) !default;
70
123
 
71
- // Kyu Point Scale
72
- // ----------------------------------------------------------------------------
73
124
 
74
- $basepoint_scale: 4;
125
+ ///
126
+ /// Kyū Point Scale
127
+ /// ---------------------------------------------------------------------------
128
+ ///
129
+ /// The base scaling factor for the Kyū point scale.
130
+ ///
131
+ /// @name $basepoint_scale
132
+ /// @type Number
133
+ ///
134
+ $basepoint_scale: 4 !default;
75
135
 
136
+
137
+ ///
138
+ /// Calculates a Kyū point value based on the basepoint scale.
139
+ ///
140
+ /// @name basepoint
141
+ /// @param {Number} $value - The multiplier to apply to the base point scale.
142
+ /// @return {Length} The calculated Kyū point value.
143
+ ///
76
144
  @function basepoint($value) {
77
145
  @return calc($q * $value * $basepoint_scale);
78
146
  }
79
147
 
80
- $basepoint_01: basepoint( 1) !default;
81
- $basepoint_02: basepoint( 2) !default;
82
- $basepoint_03: basepoint( 3) !default;
83
- $basepoint_04: basepoint( 4) !default;
84
- $basepoint_05: basepoint( 5) !default;
85
- $basepoint_06: basepoint( 6) !default;
86
- $basepoint_07: basepoint( 7) !default;
87
- $basepoint_08: basepoint( 8) !default;
88
- $basepoint_09: basepoint( 9) !default;
89
- $basepoint_10: basepoint(10) !default;
90
- $basepoint_11: basepoint(11) !default;
91
- $basepoint_12: basepoint(12) !default;
92
148
 
149
+ ///
150
+ /// A scale of Kyū points, used for fine-tuned spacing and sizing.
151
+ ///
152
+ /// @name $basepoint
153
+ /// @type Map
154
+ ///
93
155
  $basepoint: (
94
- 1: basepoint( 1),
95
- 2: basepoint( 2),
96
- 3: basepoint( 3),
97
- 4: basepoint( 4),
98
- 5: basepoint( 5),
99
- 6: basepoint( 6),
100
- 7: basepoint( 7),
101
- 8: basepoint( 8),
102
- 9: basepoint( 9),
156
+ 1: basepoint(1),
157
+ 2: basepoint(2),
158
+ 3: basepoint(3),
159
+ 4: basepoint(4),
160
+ 5: basepoint(5),
161
+ 6: basepoint(6),
162
+ 7: basepoint(7),
163
+ 8: basepoint(8),
164
+ 9: basepoint(9),
103
165
  10: basepoint(10),
104
166
  11: basepoint(11),
105
- 12: basepoint(12),
167
+ 12: basepoint(12)
106
168
  ) !default;
107
169
 
108
170
 
109
- // Kyu Baseline Scale
110
- // ----------------------------------------------------------------------------
171
+ ///
172
+ /// Kyū Baseline Scale
173
+ /// ---------------------------------------------------------------------------
174
+ ///
175
+ /// The base scaling factor for the Kyū baseline grid.
176
+ ///
177
+ /// @name $baseline_scale
178
+ /// @type Number
179
+ ///
180
+ $baseline_scale: 5 !default;
111
181
 
112
- $baseline_scale: 5;
113
182
 
183
+ ///
184
+ /// Calculates a baseline grid value based on the baseline scale.
185
+ ///
186
+ /// @name baseline
187
+ /// @type Function
188
+ /// @param {Number} $value - The multiplier to apply to the baseline scale.
189
+ /// @return {Length} The calculated baseline grid value.
190
+ ///
114
191
  @function baseline($value) {
115
- @return calc($q * $value * $baseline_scale);
192
+ @return calc($q * $value * $baseline_scale);
116
193
  }
117
194
 
118
- $baseline_00: baseline( 1) !default;
119
- $baseline_01: baseline( 1) !default;
120
- $baseline_02: baseline( 2) !default;
121
- $baseline_03: baseline( 3) !default;
122
- $baseline_04: baseline( 4) !default;
123
- $baseline_05: baseline( 5) !default;
124
- $baseline_06: baseline( 6) !default;
125
- $baseline_07: baseline( 7) !default;
126
- $baseline_08: baseline( 8) !default;
127
- $baseline_09: baseline( 9) !default;
128
- $baseline_10: baseline(10) !default;
129
- $baseline_11: baseline(11) !default;
130
- $baseline_12: baseline(12) !default;
131
-
195
+ ///
196
+ /// A scale for the baseline grid, used for consistent vertical rhythm in
197
+ /// layouts.
198
+ ///
199
+ /// @name $baseline
200
+ /// @type Map
201
+ ///
132
202
  $baseline: (
133
- 1: baseline( 1),
134
- 2: baseline( 2),
135
- 3: baseline( 3),
136
- 4: baseline( 4),
137
- 5: baseline( 5),
138
- 6: baseline( 6),
139
- 7: baseline( 7),
140
- 8: baseline( 8),
141
- 9: baseline( 9),
203
+ 1: baseline(1),
204
+ 2: baseline(2),
205
+ 3: baseline(3),
206
+ 4: baseline(4),
207
+ 5: baseline(5),
208
+ 6: baseline(6),
209
+ 7: baseline(7),
210
+ 8: baseline(8),
211
+ 9: baseline(9),
142
212
  10: baseline(10),
143
213
  11: baseline(11),
144
- 12: baseline(12),
214
+ 12: baseline(12)
145
215
  ) !default;
146
216
 
217
+
218
+ ///
219
+ /// Musical Scales Map
220
+ /// ---------------------------------------------------------------------------
221
+ ///
222
+ /// A map representing various musical scales by their degree.
223
+ /// These scales can be used to inform design decisions, such as rhythm-based
224
+ /// spacing or modular scale ratios in typography.
225
+ ///
226
+ /// @name scale_musical
227
+ /// @type Map
228
+ ///
229
+ $scale_musical: (
230
+ "monotonic": 1, // Single tone scale
231
+ "ditonic": 2, // Two-tone scale
232
+ "tritonic": 3, // Three-tone scale
233
+ "tetratonic": 4, // Four-tone scale
234
+ "pentatonic": 5, // Five-tone scale, commonly used in music
235
+ "hexatonic": 6, // Six-tone scale
236
+ "peptatonic": 7, // Seven-tone scale
237
+ "octatonic": 8, // Eight-tone scale
238
+ "nonatonic": 9, // Nine-tone scale
239
+ "dodecatonic": 12 // Twelve-tone scale, covers all semitones in an octave
240
+ ) !default;
241
+
242
+
243
+ /// Classic Typographic Scale
244
+ /// ---------------------------------------------------------------------------
245
+ ///
246
+ /// A classic typographic scale that has historical significance,
247
+ /// often used in design software and by typographers since the Renaissance.
248
+ /// This scale ensures harmonious and aesthetically pleasing text sizing.
249
+ ///
250
+ /// @name typographic_scale_classic
251
+ /// @type Map
252
+ ///
253
+ $typographic_scale_classic: (
254
+ 1: q( 6), // 6q
255
+ 2: q( 7), // 7q (+1)
256
+ 3: q( 8), // 8q (+1)
257
+ 4: q( 9), // 9q (+1)
258
+ 5: q(10), // 10q (+1)
259
+ 6: q(11), // 11q (+1)
260
+ 7: q(12), // 12q (+1)
261
+ 8: q(14), // 14q (+2)
262
+ 9: q(16), // 16q (+2)
263
+ 10: q(18), // 18q (+2)
264
+ 11: q(21), // 21q (+3)
265
+ 12: q(24), // 24q (+3)
266
+ 13: q(36), // 36q (+12)
267
+ 14: q(48), // 48q (+12)
268
+ 15: q(60), // 60q (+12)
269
+ 16: q(72), // 72q (+12)
270
+ 17: q(84), // 84q (+12)
271
+ 18: q(96) // 96q (+12)
272
+ ) !default;
@@ -1,21 +1,33 @@
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.
1
+ // ============================================================================
2
+ // Poster
3
+ // ============================================================================
14
4
 
5
+ ////
6
+ ///
7
+ /// Unit Variables Module
8
+ /// ===========================================================================
9
+ ///
10
+ /// This module defines a responsive typography system using the Kyū
11
+ /// measurement system. The system is based on the rem unit and provides
12
+ /// utility functions and mixins to apply fluid typography across various
13
+ /// screen sizes.
14
+ ///
15
+ /// Dependencies:
16
+ /// - view: For viewport-related variables.
17
+ /// - functions: For utility functions such as `unit_strip`.
18
+ ///
19
+ /// @group Unit
20
+ /// @author Scape Agency
21
+ /// @link https://unit.gl
22
+ /// @since 0.1.0 initial release
23
+ /// @todo None
24
+ /// @access public
25
+ ///
26
+ ////
15
27
 
16
28
 
17
29
  // ============================================================================
18
- // Base | Unit
30
+ // Use
19
31
  // ============================================================================
20
32
 
21
33
  @use "sass:math";
@@ -23,81 +35,73 @@
23
35
  @use "../functions" as *;
24
36
 
25
37
 
26
- // Kyū Measurement System for Responsive Typography
27
- // Defines a base size and provides a mixin for fluid typography.
38
+ // ============================================================================
39
+ // Variables
40
+ // ============================================================================
28
41
 
29
42
 
30
- // Kyū base size definition (A Kyū is 1/16th of a Rem).
31
- // 1rem equals the font size of the html element, which for most browsers has
32
- // a default value of 16px.
43
+ ///
44
+ /// The base unit in the Kyū measurement system. It represents 1/16th of a rem,
45
+ /// which is equivalent to 1px or 0.25mm.
46
+ ///
47
+ /// @name $q
48
+ /// @type Length
49
+ ///
33
50
  $q: 0.0625rem !default; // 1px, or 0.25mm
34
51
 
35
52
 
36
- // Function to calculate multiples of 'q'
37
- @function q($multiplier) {
38
- @return calc($q * $multiplier);
39
- }
53
+ ///
54
+ /// The minimum Kyū size used for fluid typography.
55
+ ///
56
+ /// @type Length
57
+ /// @name $q_min
58
+ ///
59
+ $q_min: 0.75px !default;
40
60
 
41
- // Mixin to apply multiples of 'q'
42
- @mixin q($multiplier, $property) {
43
- #{$property}: q($multiplier);
44
- }
45
61
 
62
+ ///
63
+ /// The maximum Kyū size used for fluid typography.
64
+ ///
65
+ /// @type Length
66
+ /// @name $q_max
67
+ $q_max: 1.50px !default;
46
68
 
47
- // Root custom properties for Kyū sizes
48
- :root {
49
- --q: $q;
50
- }
51
69
 
70
+ ///
71
+ /// The minimum font size calculated using the minimum Kyū size, based on
72
+ /// the rem unit.
73
+ ///
74
+ /// @type Length
75
+ /// @name $font_min
76
+ ///
77
+ $font_min: calc((1rem / $q) * $q_min) !default;
52
78
 
53
- // Minimum and maximum Kyū sizes
54
- $q_min: 0.75px !default;
55
- $q_max: 1.50px !default;
56
79
 
57
- // Minimum and maximum Kyū sizes
58
- $font_min: calc((1rem / $q) * $q_min) !default;
80
+ ///
81
+ /// The maximum font size calculated using the maximum Kyū size, based on
82
+ /// the rem unit.
83
+ ///
84
+ /// @type Length
85
+ /// @name $font_max
59
86
  $font_max: calc((1rem / $q) * $q_max) !default;
60
87
 
61
- // @mixin fluid_type($min-vw, $max-vw, $min-font-size, $max-font-size) {
62
- // // Assign font-size for the starting viewport width
63
- // font-size: $min-font-size;
64
-
65
- // // Apply fluid scaling between the minimum and maximum viewport widths
66
- // @media screen and (min-width: $min-vw) {
67
- // font-size: calc(#{$min-font-size} + #{unitless($max-font-size - $min-font-size)} * ((100vw - #{$min-vw}) / #{unitless($max-vw - $min-vw)}));
68
- // }
69
-
70
- // // Fix the font-size at the maximum size beyond the maximum viewport width
71
- // @media screen and (min-width: $max-vw) {
72
- // font-size: $max-font-size;
73
- // }
74
- // }
75
-
76
- @mixin fluid_type($min-vw, $max-vw, $min-font-size, $max-font-size) {
77
- $u1: unit($min-vw);
78
- $u2: unit($max-vw);
79
- $u3: unit($min-font-size);
80
- $u4: unit($max-font-size);
81
-
82
- @if $u1 == $u2 and $u1 == $u3 and $u1 == $u4 {
83
- & {
84
- font-size: $min-font-size;
85
- @media screen and (min-width: $min-vw) {
86
- font-size: calc(#{$min-font-size} + #{unit_strip($max-font-size - $min-font-size)} * ((100vw - #{$min-vw}) / #{unit_strip($max-vw - $min-vw)}));
87
- }
88
- @media screen and (min-width: $max-vw) {
89
- font-size: $max-font-size;
90
- }
91
- }
92
- }
93
- }
94
88
 
95
89
 
96
90
 
97
- html {
98
- @include fluid_type($media_xs, $media_sl, $font_min, $font_max);
99
- }
100
91
 
101
92
 
102
93
 
103
94
 
95
+
96
+
97
+ ///
98
+ /// This function returns a calculated value in Kyū units, making it easy to
99
+ /// apply multiples of the base unit.
100
+ ///
101
+ /// @name q
102
+ /// @param {Number} $multiplier - The multiplier to apply to the base Kyū unit.
103
+ /// @return {Length} The calculated value in Kyū units.
104
+ ///
105
+ @function q($multiplier) {
106
+ @return calc($q * $multiplier);
107
+ }