unit.gl 0.0.1

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.
@@ -0,0 +1,186 @@
1
+ // Copyright 2023 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
+ // ============================================================================
17
+ // Base | Reset
18
+ // ============================================================================
19
+
20
+
21
+ @mixin reset_bleed {
22
+ margin: 0;
23
+ margin-block-start: 0;
24
+ margin-block-end: 0;
25
+ margin-inline-start: 0;
26
+ margin-inline-end: 0;
27
+ padding: 0;
28
+ }
29
+
30
+ a,
31
+ abbr,
32
+ acronym,
33
+ address,
34
+ applet,
35
+ area,
36
+ article,
37
+ aside,
38
+ audio,
39
+ b,
40
+ base,
41
+ basefont,
42
+ bb,
43
+ bdo,
44
+ big,
45
+ blockquote,
46
+ body,
47
+ br,
48
+ button,
49
+ canvas,
50
+ caption,
51
+ center,
52
+ cite,
53
+ code,
54
+ col,
55
+ colgroup,
56
+ command,
57
+ datalist,
58
+ dd,
59
+ del,
60
+ details,
61
+ dfn,
62
+ dialog,
63
+ dir,
64
+ div,
65
+ dl,
66
+ dt,
67
+ em,
68
+ embed,
69
+ eventsource,
70
+ fieldset,
71
+ figcaption,
72
+ figure,
73
+ font,
74
+ footer,
75
+ form,
76
+ frame,
77
+ frameset,
78
+ h1,
79
+ h2,
80
+ h3,
81
+ h4,
82
+ h5,
83
+ h6,
84
+ head,
85
+ header,
86
+ hgroup,
87
+ hr,
88
+ html,
89
+ i,
90
+ iframe,
91
+ img,
92
+ input,
93
+ ins,
94
+ isindex,
95
+ kbd,
96
+ keygen,
97
+ label,
98
+ legend,
99
+ li,
100
+ link,
101
+ map,
102
+ mark,
103
+ menu,
104
+ meta,
105
+ meter,
106
+ nav,
107
+ noframes,
108
+ noscript,
109
+ object,
110
+ ol,
111
+ optgroup,
112
+ option,
113
+ output,
114
+ p,
115
+ param,
116
+ pre,
117
+ progress,
118
+ q,
119
+ rp,
120
+ rt,
121
+ ruby,
122
+ s,
123
+ samp,
124
+ script,
125
+ section,
126
+ select,
127
+ small,
128
+ source,
129
+ span,
130
+ strike,
131
+ strong,
132
+ style,
133
+ sub,
134
+ sup,
135
+ table,
136
+ tbody,
137
+ td,
138
+ textarea,
139
+ tfoot,
140
+ th,
141
+ thead,
142
+ time,
143
+ title,
144
+ tr,
145
+ track,
146
+ tt,
147
+ u,
148
+ ul,
149
+ var,
150
+ video,
151
+ wbr
152
+ {
153
+ @include reset_bleed;
154
+ }
155
+
156
+ // *{
157
+ // padding: 0px;
158
+ // margin: 0px;
159
+ // }
160
+
161
+ // html, body, div, span, applet, object, iframe,
162
+ // h1, h2, h3, h4, h5, h6, p, blockquote, pre,
163
+ // a, abbr, acronym, address, big, cite, code,
164
+ // del, dfn, em, img, ins, kbd, q, s, samp,
165
+ // small, strike, strong, sub, sup, tt, var,
166
+ // b, u, i, center,
167
+ // dl, dt, dd, ol, ul, li,
168
+ // fieldset, form, label, legend,
169
+ // table, caption, tbody, tfoot, thead, tr, th, td,
170
+ // article, aside, canvas, details, embed,
171
+ // figure, figcaption, footer, header, hgroup,
172
+ // menu, nav, output, ruby, section, summary,
173
+ // time, mark, audio, video {
174
+ // margin: 0;
175
+ // padding: 0;
176
+ // border: 0;
177
+ // font-size: 100%;
178
+ // font: inherit;
179
+ // vertical-align: baseline;
180
+ // }
181
+
182
+ // /* HTML5 display-role reset for older browsers */
183
+ // article, aside, details, figcaption, figure,
184
+ // footer, header, hgroup, menu, nav, section, main {
185
+ // display: block;
186
+ // }
@@ -0,0 +1,272 @@
1
+ // Copyright 2020 Scape Agency BV
2
+
3
+ // Licensed under the Apache License, Version 2.00 (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.00
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
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ $rhythm_base: q(4);
25
+
26
+ $line_height_ratio: 1.5;
27
+
28
+ $font_size_scalar: 4;
29
+ $line_height_scalar: calc($line_height_ratio * $font_size_scalar);
30
+
31
+
32
+
33
+ $font_size_base: calc($font_size_scalar * $rhythm_base); // Base font size
34
+ $line_height_base: calc($line_height_scalar * $rhythm_base); // Base line height (1.5 times the font size is a good start)
35
+
36
+
37
+
38
+ $basepoint: (
39
+ 1: basepoint( 1),
40
+ 2: basepoint( 2),
41
+ 3: basepoint( 3),
42
+ 4: basepoint( 4),
43
+ 5: basepoint( 5),
44
+ 6: basepoint( 6),
45
+ 7: basepoint( 7),
46
+ 8: basepoint( 8),
47
+ 9: basepoint( 9),
48
+ 10: basepoint(10),
49
+ 11: basepoint(11),
50
+ 12: basepoint(12),
51
+ ) !default;
52
+
53
+
54
+ // Typography ladder map
55
+ $typographic_scale: (
56
+ 1: q( 4),
57
+ 2: q( 6), // +2
58
+ 3: q( 8), // +2
59
+ 4: q(10), // +2
60
+ 5: q(12), // +2
61
+ 6: q(14), // +2
62
+ 7: q(16), // +2
63
+ 8: q(20), // +4
64
+ 9: q(24), // +4
65
+ 10: q(28), // +4
66
+ 11: q(32), // +4
67
+ 12: q(36), // +4
68
+ 13: q(40), // +4
69
+ 14: q(48), // +8
70
+ 15: q(56), // +8
71
+ 16: q(64), // +8
72
+ 17: q(72), // +8
73
+ ) !default;
74
+
75
+ // 'display': $q-base * 96, // For large display text
76
+ // 'h1': $q-base * 48, // For primary headings
77
+ // 'h2': $q-base * 36, // For secondary headings
78
+ // 'h3': $q-base * 24, // For tertiary headings
79
+ // 'h4': $q-base * 20, // For quaternary headings
80
+ // 'h5': $q-base * 18, // For quinary headings
81
+ // 'h6': $q-base * 16, // For senary headings
82
+ // 'body-large': $q-base * 14, // For large body text
83
+ // 'body': $q-base * 12, // For main body text
84
+ // 'body-small': $q-base * 10, // For small body text
85
+ // 'caption': $q-base * 8, // For captions and overlines
86
+ // 'overline': $q-base * 6 // For the smallest size, like legal text
87
+ // ) !default;
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+ // point_base
116
+
117
+ // $rhythm_base: 4;
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+ // Vertical Rhythm Function
126
+ // Functions to maintain consistent vertical rhythm (spacing and heights) across your layout.
127
+
128
+
129
+
130
+ // $base-font-size: 16px; // Base font size
131
+ // $line-height: 24px; // Base line height
132
+
133
+ // @function rhythm($lines: 1) {
134
+ // @return $lines * $line-height;
135
+ // }
136
+
137
+ // @function font-size-to-line-height($font-size) {
138
+ // @return floor($font-size / $line-height) * $line-height;
139
+ // }
140
+
141
+
142
+
143
+ // @mixin heading-baseline($font-size) {
144
+ // font-size: $font-size;
145
+ // line-height: baseline-grid($font-size);
146
+ // }
147
+
148
+ // // Typography Ladder Definition
149
+ // $typography-ladder: (
150
+ // 'h1': (font-size: 2.5rem, line-height: 1.2),
151
+ // 'h2': (font-size: 2rem, line-height: 1.3),
152
+ // 'h3': (font-size: 1.75rem, line-height: 1.4),
153
+ // 'h4': (font-size: 1.5rem, line-height: 1.4),
154
+ // 'h5': (font-size: 1.25rem, line-height: 1.5),
155
+ // 'h6': (font-size: 1rem, line-height: 1.6),
156
+ // 'body-large': (font-size: 1.125rem, line-height: 1.6),
157
+ // 'body': (font-size: 1rem, line-height: 1.6),
158
+ // 'body-small': (font-size: 0.875rem, line-height: 1.7),
159
+ // 'caption': (font-size: 0.75rem, line-height: 1.8)
160
+ // ) !default;
161
+
162
+
163
+ // Calculate dynamic font size
164
+ $font_size: calc(($q_unit / $q_base) * $q) !default;
165
+
166
+ // Corresponding minimum and maximum font sizes
167
+ $font_min: calc(($q_unit / $q) * $q_min) !default;
168
+ $font_max: calc(($q_unit / $q) * $q_max) !default;
169
+
170
+
171
+
172
+
173
+ // Apply
174
+ // ============================================================================
175
+
176
+ // Apply Fluid Typography
177
+ html {
178
+ font-size: $font_size_base;
179
+ line-height: $line_height_base;
180
+ // font-size: $font_size;
181
+ }
182
+
183
+
184
+
185
+
186
+
187
+ $basepoint_scale: 4;
188
+
189
+ @function basepoint($value) {
190
+ @return calc($q * $value * $basepoint_scale);
191
+ }
192
+
193
+ $basepoint_01: basepoint( 1) !default;
194
+ $basepoint_02: basepoint( 2) !default;
195
+ $basepoint_03: basepoint( 3) !default;
196
+ $basepoint_04: basepoint( 4) !default;
197
+ $basepoint_05: basepoint( 5) !default;
198
+ $basepoint_06: basepoint( 6) !default;
199
+ $basepoint_07: basepoint( 7) !default;
200
+ $basepoint_08: basepoint( 8) !default;
201
+ $basepoint_09: basepoint( 9) !default;
202
+ $basepoint_10: basepoint(10) !default;
203
+ $basepoint_11: basepoint(11) !default;
204
+ $basepoint_12: basepoint(12) !default;
205
+
206
+ $basepoint: (
207
+ 1: basepoint( 1),
208
+ 2: basepoint( 2),
209
+ 3: basepoint( 3),
210
+ 4: basepoint( 4),
211
+ 5: basepoint( 5),
212
+ 6: basepoint( 6),
213
+ 7: basepoint( 7),
214
+ 8: basepoint( 8),
215
+ 9: basepoint( 9),
216
+ 10: basepoint(10),
217
+ 11: basepoint(11),
218
+ 12: basepoint(12),
219
+ ) !default;
220
+
221
+
222
+ // Kyu Baseline Scale
223
+ // ----------------------------------------------------------------------------
224
+
225
+ $baseline_scale: 5;
226
+
227
+ @function baseline($value) {
228
+ @return calc($q * $value * $baseline_scale);
229
+ }
230
+
231
+ $baseline_00: baseline( 1) !default;
232
+ $baseline_01: baseline( 1) !default;
233
+ $baseline_02: baseline( 2) !default;
234
+ $baseline_03: baseline( 3) !default;
235
+ $baseline_04: baseline( 4) !default;
236
+ $baseline_05: baseline( 5) !default;
237
+ $baseline_06: baseline( 6) !default;
238
+ $baseline_07: baseline( 7) !default;
239
+ $baseline_08: baseline( 8) !default;
240
+ $baseline_09: baseline( 9) !default;
241
+ $baseline_10: baseline(10) !default;
242
+ $baseline_11: baseline(11) !default;
243
+ $baseline_12: baseline(12) !default;
244
+
245
+ $baseline: (
246
+ 1: baseline( 1),
247
+ 2: baseline( 2),
248
+ 3: baseline( 3),
249
+ 4: baseline( 4),
250
+ 5: baseline( 5),
251
+ 6: baseline( 6),
252
+ 7: baseline( 7),
253
+ 8: baseline( 8),
254
+ 9: baseline( 9),
255
+ 10: baseline(10),
256
+ 11: baseline(11),
257
+ 12: baseline(12),
258
+ ) !default;
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+ // @function baseline-grid($font-size, $line-height: $base-line-height) {
269
+ // @return ceil($font-size / $line-height) * $line-height;
270
+ // }
271
+
272
+
@@ -0,0 +1,60 @@
1
+ // Copyright 2020 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
+ // ============================================================================
17
+ // Base | Unit
18
+ // ============================================================================
19
+
20
+ @use "sass:math";
21
+
22
+
23
+
24
+ // Kyū Measurement System for Responsive Typography
25
+ // Defines a base size and provides a mixin for fluid typography.
26
+
27
+
28
+ // Kyū base size definition (A Kyū is 1/16th of a Rem).
29
+ // 1rem equals the font size of the html element, which for most browsers has
30
+ // a default value of 16px.
31
+ $q_base: 0.0625rem !default; // 1px, or 0.25mm
32
+ $q_unit: 1.0000rem !default;
33
+
34
+
35
+ // Minimum and maximum Kyū sizes
36
+ $q_min: 0.75px !default;
37
+ $q_max: 1.50px !default;
38
+
39
+
40
+
41
+
42
+
43
+ // Calculate dynamic Kyū size using clamp function
44
+ // $q_size: scale_dynamic_clamp($media_xs, $media_sl, $q_min, $q_max);
45
+ $q: scale_dynamic_clamp($media_xs, $media_sl, $q_min, $q_max);
46
+
47
+ // Function to calculate multiples of 'q'
48
+ @function q($multiplier) {
49
+ @return calc($q * $multiplier);
50
+ }
51
+
52
+ // Mixin to apply multiples of 'q'
53
+ @mixin q($multiplier, $property) {
54
+ #{$property}: q($multiplier);
55
+ }
56
+
57
+ // Root custom properties for Kyū sizes
58
+ :root {
59
+ --q: $q;
60
+ }
@@ -0,0 +1,77 @@
1
+ // Copyright 2020 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
+
17
+
18
+ // Unit Conversion Functions
19
+ // Create functions to convert between different measurement units, such as pixels to rem, em to pixels, etc.
20
+
21
+ @function px-to-rem($size, $base: 16px) {
22
+ @return $size / $base * 1rem;
23
+ }
24
+
25
+ @function rem-to-px($size, $base: 16px) {
26
+ @return $size * $base;
27
+ }
28
+
29
+ @function em-to-px($size, $context: 16px) {
30
+ @return $size * $context;
31
+ }
32
+
33
+ @function px-to-em($size, $context: 16px) {
34
+ @return $size / $context * 1em;
35
+ }
36
+
37
+
38
+ // Base font-size for the document
39
+ $base-font-size: 16px !default;
40
+
41
+ // Validate that the input is a pixel value
42
+ @function validate-px($value) {
43
+ @if unit($value) != 'px' {
44
+ @error "Expected a pixel value, but got `#{$value}`.";
45
+ }
46
+ @return $value;
47
+ }
48
+
49
+ // Convert pixels to rem
50
+ @function px-to-rem($size) {
51
+ $validated-size: validate-px($size);
52
+ @return $validated-size / $base-font-size * 1rem;
53
+ }
54
+
55
+ // Convert rem to pixels
56
+ @function rem-to-px($size) {
57
+ @if unit($size) != 'rem' {
58
+ @error "Expected a rem value, but got `#{$size}`.";
59
+ }
60
+ @return $size * $base-font-size;
61
+ }
62
+
63
+ // Convert em to pixels
64
+ @function em-to-px($size, $context: $base-font-size) {
65
+ $validated-context: validate-px($context);
66
+ @if unit($size) != 'em' {
67
+ @error "Expected an em value, but got `#{$size}`.";
68
+ }
69
+ @return $size * $validated-context;
70
+ }
71
+
72
+ // Convert pixels to em
73
+ @function px-to-em($size, $context: $base-font-size) {
74
+ $validated-size: validate-px($size);
75
+ $validated-context: validate-px($context);
76
+ @return $validated-size / $validated-context * 1em;
77
+ }
@@ -0,0 +1,104 @@
1
+
2
+ // ============================================================================
3
+ // Unit | Functions
4
+ // ============================================================================
5
+
6
+
7
+ /// Strip Unit Function
8
+ /// Function to remove the unit from a numerical value
9
+ /// Ensures compatibility with various SCSS versions
10
+ /// @param $value - The numerical value with or without a unit
11
+ /// @return - The raw numerical value without its unit
12
+ @function unit_strip($value) {
13
+ // Check if the input is a number with a unit
14
+ @if type-of($value) == "number" and not unitless($value) {
15
+ // Convert the value to a string
16
+ $value-str: inspect($value);
17
+ // Remove the unit part from the string
18
+ $value-no-unit: str-slice(
19
+ $value-str,
20
+ 1,
21
+ str-index($value-str, unit($value)) - 1
22
+ );
23
+ // Return the number without its unit
24
+ @return $value-no-unit;
25
+ } @else if type-of($value) != "number" {
26
+ // Handle non-number inputs gracefully
27
+ // @warn "Input `#{$value}` is not a number. Returning value as-is.";
28
+ @return $value;
29
+ }
30
+ // Return the value as-is for unitless numbers or non-number inputs
31
+ @return $value;
32
+ }
33
+
34
+
35
+ /// Linear Interpolation Function
36
+ /// Interpolates linearly between two values across a range, useful for
37
+ /// fluid scaling.
38
+ /// @param $start - Starting value at the lower bound (can include units)
39
+ /// @param $end - Ending value at the upper bound (can include units)
40
+ /// @param $min - Lower bound for interpolation (must be unitless or in 'px')
41
+ /// @param $max - Upper bound for interpolation (must be unitless or in 'px')
42
+ /// @param $actual - Current value to interpolate (default is 100vw)
43
+ /// @return - Interpolated value (in the same units as $start and $end)
44
+ @function linear_interpolation($start, $end, $min, $max, $actual: 100vw) {
45
+
46
+ // Validate parameters
47
+ @if unitless($min) == false and unit($min) != 'px' {
48
+ @error "Parameter `$min` must be unitless or in 'px'.";
49
+ }
50
+ @if unitless($max) == false and unit($max) != 'px' {
51
+ @error "Parameter `$max` must be unitless or in 'px'.";
52
+ }
53
+ @if $max <= $min {
54
+ @error "Parameter `$max` must be greater than `$min`.";
55
+ }
56
+
57
+ // Convert all values to a common unit for calculation
58
+ $unit: 1#{unit($start)};
59
+
60
+ // Convert coordinate values to unitless for calculations
61
+ $x0: #{unit_strip($min)};
62
+ $x1: #{unit_strip($max)};
63
+ $y0: #{unit_strip($start)};
64
+ $y1: #{unit_strip($end)};
65
+
66
+ // Calculate the slope of the line
67
+ $slope: #{calc(($y1 - $y0) / ($x1 - $x0))};
68
+
69
+ // Calculate the interval
70
+ $interval: calc($actual - $min);
71
+
72
+ // Calculate and return the interpolated value
73
+ $value: calc($start + $slope * $interval);
74
+
75
+ // Return the `calc` expression
76
+ @return $value;
77
+
78
+ }
79
+
80
+
81
+ /// Function: scale_dynamic_clamp
82
+ /// Calculates font size using clamp-based responsive typography
83
+ /// @param $_font_size_min - Minimum font size
84
+ /// @param $_font_size_max - Maximum font size
85
+ /// @param $_viewport_width_min - Minimum viewport width where scaling starts
86
+ /// @param $_viewport_width_max - Maximum viewport width where scaling stops
87
+ /// @return - Calculated size using clamp
88
+ @function scale_dynamic_clamp(
89
+ $_viewport_width_min,
90
+ $_viewport_width_max,
91
+ $_font_size_min,
92
+ $_font_size_max,
93
+ ) {
94
+ @return clamp(
95
+ $_font_size_min,
96
+ linear_interpolation(
97
+ $_font_size_min,
98
+ $_font_size_max,
99
+ $_viewport_width_min,
100
+ $_viewport_width_max
101
+ ),
102
+ $_font_size_max
103
+ );
104
+ }