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.
- package/LICENSE +171 -0
- package/README.md +85 -0
- package/dist/js/main.bundle.js +1 -0
- package/package.json +110 -0
- package/src/scss/_guide.scss +194 -0
- package/src/scss/_helper.scss +107 -0
- package/src/scss/_layer.scss +40 -0
- package/src/scss/_paper.scss +414 -0
- package/src/scss/_ratio.scss +97 -0
- package/src/scss/_reset.scss +186 -0
- package/src/scss/_scale.scss +272 -0
- package/src/scss/_unit.scss +60 -0
- package/src/scss/_unit_conversion.scss +77 -0
- package/src/scss/_unit_functions.scss +104 -0
- package/src/scss/_view.scss +117 -0
- package/src/scss/display/_device.scss +106 -0
- package/src/scss/display/_display_orientation.scss +93 -0
- package/src/scss/index.scss +51 -0
- package/src/scss/math/_math_arithmetic.scss +64 -0
- package/src/scss/math/_math_ratio.scss +172 -0
- package/src/scss/math/_math_scale.scss +58 -0
- package/src/scss/math/_math_sequence.scss +278 -0
- package/src/ts/index.ts +0 -0
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
// Media | Screen
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
// 320px — 480px: Mobile devices
|
|
21
|
+
// 481px — 768px: iPads, Tablets
|
|
22
|
+
// 769px — 1024px: Small screens, laptops
|
|
23
|
+
// 1025px — 1200px: Desktops, large screens
|
|
24
|
+
// 1201px and more — Extra large screens, TV
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
$base_screen_unit: 16px !default; // Base unit size (16px)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@function calc_breakpoint($multiplier) {
|
|
31
|
+
@return $base_screen_unit * $multiplier;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// Define breakpoints using the function
|
|
36
|
+
$breakpoints: (
|
|
37
|
+
xs: calc_breakpoint(20), // 320px - Extra small devices (Mobile)
|
|
38
|
+
sm: calc_breakpoint(30), // 480px - Small devices (Tablets)
|
|
39
|
+
md: calc_breakpoint(48), // 768px - Medium devices (Laptops)
|
|
40
|
+
lg: calc_breakpoint(64), // 1024px - Large devices (Desktops)
|
|
41
|
+
xl: calc_breakpoint(80), // 1280px - Extra large devices (TV)
|
|
42
|
+
sl: calc_breakpoint(90), // 1440px - Super large devices (Large TV)
|
|
43
|
+
) !default;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
// Expose individual breakpoints for easier direct access
|
|
47
|
+
$media_xs: map-get($breakpoints, xs) !default;
|
|
48
|
+
$media_sm: map-get($breakpoints, sm) !default;
|
|
49
|
+
$media_md: map-get($breakpoints, md) !default;
|
|
50
|
+
$media_lg: map-get($breakpoints, lg) !default;
|
|
51
|
+
$media_xl: map-get($breakpoints, xl) !default;
|
|
52
|
+
$media_sl: map-get($breakpoints, sl) !default;
|
|
53
|
+
|
|
54
|
+
$media_dif: calc($media_sl - $media_xs);
|
|
55
|
+
|
|
56
|
+
// $media_min: 320px !default; // Mobile
|
|
57
|
+
// $media_med: 640px !default; // Tablet
|
|
58
|
+
// $media_max: 960px !default; // Screen
|
|
59
|
+
|
|
60
|
+
// Media Query Mixins
|
|
61
|
+
// ============================================================================
|
|
62
|
+
|
|
63
|
+
@mixin breakpoint($size) {
|
|
64
|
+
@if map-has-key($breakpoints, $size) {
|
|
65
|
+
@media (min-width: map-get($breakpoints, $size)) {
|
|
66
|
+
@content;
|
|
67
|
+
}
|
|
68
|
+
} @else {
|
|
69
|
+
@warn "Invalid breakpoint: #{$size}.";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@mixin media_xs {
|
|
74
|
+
@media (min-width: $media_xs) { @content; }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@mixin media_sm {
|
|
78
|
+
@media (min-width: $media_sm) { @content; }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@mixin media_md {
|
|
83
|
+
@media (min-width: $media_md) { @content; }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@mixin media_lg {
|
|
87
|
+
@media (min-width: $media_lg) { @content; }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@mixin media_xl {
|
|
92
|
+
@media (min-width: $media_xl) { @content; }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@mixin media_sl {
|
|
96
|
+
@media (min-width: $media_sl) { @content; }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
// Example
|
|
101
|
+
// @include breakpoint(md) {
|
|
102
|
+
// // Styles for medium screens and up
|
|
103
|
+
// }
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// Syntax
|
|
107
|
+
// @media media type and (condition: breakpoint) {
|
|
108
|
+
// // CSS rules
|
|
109
|
+
// }
|
|
110
|
+
|
|
111
|
+
// @media screen, print {
|
|
112
|
+
// /* … */
|
|
113
|
+
// }
|
|
114
|
+
|
|
115
|
+
// @media (min-width: 30em) and (orientation: landscape) {
|
|
116
|
+
// /* … */
|
|
117
|
+
// }
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
// Device Attribute Map
|
|
20
|
+
$devices: (
|
|
21
|
+
// iPhones
|
|
22
|
+
// ------------------------------------------------------------------------
|
|
23
|
+
"iphone-5": ("min-width": 320px, "max-width": 568px, "pixel-ratio": 2),
|
|
24
|
+
"iphone-6-7-8": ("min-width": 375px, "max-width": 667px, "pixel-ratio": 2),
|
|
25
|
+
"iphone-x": ("min-width": 375px, "max-width": 812px, "pixel-ratio": 3),
|
|
26
|
+
"iphone-11": ("min-width": 414px, "max-width": 896px, "pixel-ratio": 2),
|
|
27
|
+
"iphone-12": ("min-width": 390px, "max-width": 844px, "pixel-ratio": 3),
|
|
28
|
+
"iphone-13": ("min-width": 428px, "max-width": 926px, "pixel-ratio": 3),
|
|
29
|
+
|
|
30
|
+
// iPads
|
|
31
|
+
// ------------------------------------------------------------------------
|
|
32
|
+
"ipad": ("min-width": 768px, "max-width": 1024px, "pixel-ratio": 2),
|
|
33
|
+
"ipad-pro": ("min-width": 1024px, "max-width": 1366px, "pixel-ratio": 2),
|
|
34
|
+
"ipad-mini": ("min-width": 768px, "max-width": 1024px, "pixel-ratio": 2),
|
|
35
|
+
"ipad-air": ("min-width": 820px, "max-width": 1180px, "pixel-ratio": 2),
|
|
36
|
+
|
|
37
|
+
// Samsung Galaxy
|
|
38
|
+
// ------------------------------------------------------------------------
|
|
39
|
+
"samsung-s10": ("min-width": 360px, "max-width": 760px, "pixel-ratio": 3),
|
|
40
|
+
"samsung-s20": ("min-width": 320px, "max-width": 720px, "pixel-ratio": 4),
|
|
41
|
+
"samsung-s21": ("min-width": 320px, "max-width": 780px, "pixel-ratio": 3),
|
|
42
|
+
|
|
43
|
+
// Google Pixel
|
|
44
|
+
// ------------------------------------------------------------------------
|
|
45
|
+
"google-pixel": ("min-width": 411px, "max-width": 731px, "pixel-ratio": 2.6),
|
|
46
|
+
"google-pixel-5": ("min-width": 393px, "max-width": 851px, "pixel-ratio": 3),
|
|
47
|
+
|
|
48
|
+
// Microsoft Surface
|
|
49
|
+
// ------------------------------------------------------------------------
|
|
50
|
+
"surface-duo": ("min-width": 540px, "max-width": 720px, "pixel-ratio": 2.5),
|
|
51
|
+
"surface-pro": ("min-width": 768px, "max-width": 1366px, "pixel-ratio": 2),
|
|
52
|
+
|
|
53
|
+
// Samsung Galaxy Fold
|
|
54
|
+
// ------------------------------------------------------------------------
|
|
55
|
+
"galaxy-fold": ("min-width": 280px, "max-width": 653px, "pixel-ratio": 3),
|
|
56
|
+
|
|
57
|
+
// Other Tablets and Laptops
|
|
58
|
+
// ------------------------------------------------------------------------
|
|
59
|
+
"amazon-fire-hd": ("min-width": 800px, "max-width": 1280px, "pixel-ratio": 1.5),
|
|
60
|
+
"microsoft-laptop": ("min-width": 1504px, "max-width": 2256px, "pixel-ratio": 1.5),
|
|
61
|
+
|
|
62
|
+
// Desktops
|
|
63
|
+
// ------------------------------------------------------------------------
|
|
64
|
+
"macbook-air": ("min-width": 1440px, "max-width": 2560px, "pixel-ratio": 2),
|
|
65
|
+
"macbook-pro": ("min-width": 1680px, "max-width": 3072px, "pixel-ratio": 2),
|
|
66
|
+
"imac": ("min-width": 1920px, "max-width": 5120px, "pixel-ratio": 2)
|
|
67
|
+
|
|
68
|
+
// Additional Devices
|
|
69
|
+
// ------------------------------------------------------------------------
|
|
70
|
+
"lg-g6": ("min-width": 360px, "max-width": 720px, "pixel-ratio": 4),
|
|
71
|
+
"oneplus-7t": ("min-width": 412px, "max-width": 732px, "pixel-ratio": 2.5),
|
|
72
|
+
"sony-xperia-1": ("min-width": 384px, "max-width": 643px, "pixel-ratio": 3),
|
|
73
|
+
"huawei-p30": ("min-width": 360px, "max-width": 780px, "pixel-ratio": 3),
|
|
74
|
+
"xiaomi-mi9": ("min-width": 393px, "max-width": 851px, "pixel-ratio": 3),
|
|
75
|
+
"surface-book": ("min-width": 1500px, "max-width": 2000px, "pixel-ratio": 2),
|
|
76
|
+
"dell-xps": ("min-width": 1920px, "max-width": 3840px, "pixel-ratio": 2),
|
|
77
|
+
"lenovo-thinkpad": ("min-width": 1440px, "max-width": 2560px, "pixel-ratio": 2)
|
|
78
|
+
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
/// Generalized Media Query Mixin
|
|
83
|
+
/// Creates a media query based on device attributes defined in $devices map.
|
|
84
|
+
/// @param $device - The key name of the device in the $devices map.
|
|
85
|
+
/// Usage Example:
|
|
86
|
+
/// @include device-media-query('iphone-6-7-8') {// Styles specific to iPhone 6, 7, 8}
|
|
87
|
+
@mixin device-media-query($device) {
|
|
88
|
+
// Retrieve the device attributes from the map
|
|
89
|
+
$attributes: map-get($devices, $device);
|
|
90
|
+
|
|
91
|
+
// Extract individual attributes with default fallbacks
|
|
92
|
+
$min-width: if(map-has-key($attributes, "min-width"), map-get($attributes, "min-width"), null);
|
|
93
|
+
$max-width: if(map-has-key($attributes, "max-width"), map-get($attributes, "max-width"), null);
|
|
94
|
+
$pixel-ratio: if(map-has-key($attributes, "pixel-ratio"), map-get($attributes, "pixel-ratio"), 1); // Default to 1
|
|
95
|
+
|
|
96
|
+
// Construct the media query string
|
|
97
|
+
$media-query: "only screen";
|
|
98
|
+
$media-query: if($min-width != null, $media-query + " and (min-device-width: #{$min-width})", $media-query);
|
|
99
|
+
$media-query: if($max-width != null, $media-query + " and (max-device-width: #{$max-width})", $media-query);
|
|
100
|
+
$media-query: if($pixel-ratio != 1, $media-query + " and (-webkit-device-pixel-ratio: #{$pixel-ratio})", $media-query);
|
|
101
|
+
|
|
102
|
+
// Apply the media query
|
|
103
|
+
@media #{$media-query} {
|
|
104
|
+
@content;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
// Mixins for Media Queries Based on Device Orientation
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// These mixins provide a convenient way to apply styles based on the orientation of the device.
|
|
25
|
+
// Useful for responsive designs that need to adapt to landscape or portrait modes, especially on tablets and smartphones.
|
|
26
|
+
|
|
27
|
+
/// Mixin for landscape orientation with optional breakpoint
|
|
28
|
+
/// Use this mixin to apply styles when the device is in landscape mode.
|
|
29
|
+
/// @param $min-width (optional) - The minimum width at which the styles should apply
|
|
30
|
+
/// Example usage:
|
|
31
|
+
/// @include orientation-landscape(1024px) { /* styles */ }
|
|
32
|
+
@mixin orientation-landscape($min-width: null) {
|
|
33
|
+
@if $min-width {
|
|
34
|
+
@media (orientation: landscape) and (min-width: $min-width) {
|
|
35
|
+
@content;
|
|
36
|
+
}
|
|
37
|
+
} @else {
|
|
38
|
+
@media (orientation: landscape) {
|
|
39
|
+
@content; // The styles inside this mixin are applied in landscape mode
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Mixin for portrait orientation with optional breakpoint
|
|
45
|
+
/// Use this mixin to apply styles when the device is in portrait mode.
|
|
46
|
+
/// @param $min-width (optional) - The minimum width at which the styles should apply
|
|
47
|
+
/// Example usage:
|
|
48
|
+
/// @include orientation-portrait { /* styles */ }
|
|
49
|
+
@mixin orientation-portrait($min-width: null) {
|
|
50
|
+
@if $min-width {
|
|
51
|
+
@media (orientation: portrait) and (min-width: $min-width) {
|
|
52
|
+
@content;
|
|
53
|
+
}
|
|
54
|
+
} @else {
|
|
55
|
+
@media (orientation: portrait) {
|
|
56
|
+
@content;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/// Mixin for targeting specific aspect ratios
|
|
64
|
+
/// @param $width - Width of the aspect ratio
|
|
65
|
+
/// @param $height - Height of the aspect ratio
|
|
66
|
+
@mixin aspect-ratio($width, $height) {
|
|
67
|
+
@media (aspect-ratio: #{$width}/#{$height}) {
|
|
68
|
+
@content;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// Mixin for High-Density (Retina) Displays
|
|
79
|
+
// ============================================================================
|
|
80
|
+
/// This mixin targets high-density displays like Retina screens.
|
|
81
|
+
/// It covers various methods to detect high pixel density to ensure broad compatibility.
|
|
82
|
+
/// Usage:
|
|
83
|
+
/// @include retina { /* styles for retina displays */ }
|
|
84
|
+
@mixin retina {
|
|
85
|
+
// Webkit-based browsers
|
|
86
|
+
@media only screen and (-webkit-min-device-pixel-ratio: 2),
|
|
87
|
+
// Standard way to target high-resolution displays
|
|
88
|
+
only screen and (min-resolution: 192dpi),
|
|
89
|
+
// For devices with a high-resolution in dots per inch
|
|
90
|
+
only screen and (min-resolution: 2dppx) {
|
|
91
|
+
@content; // Styles for high-density displays
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
@charset "utf-8";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* unit.gl
|
|
20
|
+
*
|
|
21
|
+
* @description Unit System
|
|
22
|
+
* @author Scape Agency (https://www.scape.agency)
|
|
23
|
+
* @version v1.0.0
|
|
24
|
+
* @copyright 2020-2024 Scape Agency (https://www.scape.agency)
|
|
25
|
+
* @website https://www.unit.gl/
|
|
26
|
+
* @repository https://github.com/scape-agency/unit.gl/
|
|
27
|
+
* @license Apache 2.0 License (https://github.com/scape-agency/unit.gl/blob/main/LICENSE)
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
@use "sass:math";
|
|
31
|
+
|
|
32
|
+
@import "_reset";
|
|
33
|
+
@import "_layer";
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@import "_paper";
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@import "_view";
|
|
40
|
+
|
|
41
|
+
@import "_unit_functions";
|
|
42
|
+
@import "_unit";
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@import "_scale";
|
|
46
|
+
|
|
47
|
+
@import "_helper";
|
|
48
|
+
@import "_guide";
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// @import "base/base";
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
// Unitless Arithmetic Functions
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Functions to perform arithmetic operations while ensuring correct handling of units.
|
|
19
|
+
|
|
20
|
+
/// Adds two values, handling units.
|
|
21
|
+
/// @param $value1 - First value
|
|
22
|
+
/// @param $value2 - Second value
|
|
23
|
+
/// @return - Sum of the two values
|
|
24
|
+
@function add($value1, $value2) {
|
|
25
|
+
@if unitless($value1) and unitless($value2) {
|
|
26
|
+
// Both values are unitless, return simple addition
|
|
27
|
+
@return $value1 + $value2;
|
|
28
|
+
} @else if unitless($value1) {
|
|
29
|
+
// First value is unitless, convert it to the unit of the second value
|
|
30
|
+
@return $value1 + unit-strip($value2);
|
|
31
|
+
} @else if unitless($value2) {
|
|
32
|
+
// Second value is unitless, convert it to the unit of the first value
|
|
33
|
+
@return unit-strip($value1) + $value2;
|
|
34
|
+
} @else if unit($value1) == unit($value2) {
|
|
35
|
+
// Both values have the same unit
|
|
36
|
+
@return $value1 + $value2;
|
|
37
|
+
}
|
|
38
|
+
// Mismatched units, return a warning
|
|
39
|
+
@warn "Cannot add values with different units: #{$value1} and #{$value2}";
|
|
40
|
+
@return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Subtracts one value from another, handling units.
|
|
44
|
+
/// @param $value1 - First value
|
|
45
|
+
/// @param $value2 - Second value
|
|
46
|
+
/// @return - Difference of the two values
|
|
47
|
+
@function subtract($value1, $value2) {
|
|
48
|
+
@if unitless($value1) and unitless($value2) {
|
|
49
|
+
// Both values are unitless, return simple subtraction
|
|
50
|
+
@return $value1 - $value2;
|
|
51
|
+
} @else if unitless($value1) {
|
|
52
|
+
// First value is unitless, convert it to the unit of the second value
|
|
53
|
+
@return $value1 - unit-strip($value2);
|
|
54
|
+
} @else if unitless($value2) {
|
|
55
|
+
// Second value is unitless, convert it to the unit of the first value
|
|
56
|
+
@return unit-strip($value1) - $value2;
|
|
57
|
+
} @else if unit($value1) == unit($value2) {
|
|
58
|
+
// Both values have the same unit
|
|
59
|
+
@return $value1 - $value2;
|
|
60
|
+
}
|
|
61
|
+
// Mismatched units, return a warning
|
|
62
|
+
@warn "Cannot subtract values with different units: #{$value1} and #{$value2}";
|
|
63
|
+
@return null;
|
|
64
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
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
|
+
// Math | Ratio's
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
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
|
+
|
|
119
|
+
) !default;
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/// 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) {
|
|
126
|
+
$golden-ratio: 1.618;
|
|
127
|
+
@return $size * pow($golden-ratio, $increment);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
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
|
|
142
|
+
@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.";
|
|
152
|
+
}
|
|
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
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
// Math | Scales
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
|
|
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;
|
|
33
|
+
|
|
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;
|