unit.gl 0.0.40 → 0.1.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/README.md +0 -1
- package/css/unit.gl.css +54 -42
- package/css/unit.gl.min.css +1 -1
- package/package.json +2 -22
- package/scss/_reset.scss +20 -12
- package/scss/classes/_guide.scss +35 -40
- package/scss/classes/_guides.scss +141 -0
- package/scss/classes/_index.scss +3 -5
- package/scss/classes/_ratio.scss +3 -5
- package/scss/dev/_banner.scss +4 -7
- package/scss/dev/_index.scss +7 -0
- package/scss/functions/_color.scss +8 -11
- package/scss/functions/_index.scss +18 -11
- package/scss/functions/_layer.scss +6 -10
- package/scss/functions/_ratio.scss +13 -16
- package/scss/functions/_scale.scss +20 -18
- package/scss/functions/_sequence.scss +64 -72
- package/scss/functions/_view.scss +6 -9
- package/scss/functions/math/_arithmetic.scss +21 -30
- package/scss/functions/math/_index.scss +4 -7
- package/scss/functions/unit/_index.scss +8 -7
- package/scss/functions/unit/_unit_conversion.scss +42 -29
- package/scss/functions/unit/_unit_functions.scss +55 -43
- package/scss/index.scss +0 -1
- package/scss/maps/_color.scss +14 -14
- package/scss/maps/_index.scss +26 -0
- package/scss/mixins/_device.scss +9 -10
- package/scss/mixins/_display.scss +52 -57
- package/scss/mixins/_guide.scss +59 -81
- package/scss/mixins/_helper.scss +74 -92
- package/scss/mixins/_index.scss +12 -14
- package/scss/mixins/_paper.scss +10 -11
- package/scss/mixins/_ratio.scss +172 -76
- package/scss/mixins/_unit.scss +33 -23
- package/scss/mixins/_view.scss +47 -54
- package/scss/{_global.scss → tags/_global.scss} +12 -11
- package/scss/tags/_index.scss +5 -6
- package/scss/tags/_unit.scss +4 -11
- package/scss/variables/_color.scss +18 -20
- package/scss/variables/_device.scss +179 -73
- package/scss/variables/_index.scss +21 -22
- package/scss/variables/_layer.scss +26 -35
- package/scss/variables/_paper.scss +1022 -241
- package/scss/variables/_ratio.scss +148 -90
- package/scss/variables/_scale.scss +141 -115
- package/scss/variables/_unit.scss +20 -35
- package/scss/variables/_view.scss +54 -57
- package/ts/AspectRatio.ts +27 -6
- package/ts/Border.ts +35 -4
- package/ts/BoxModel.ts +32 -4
- package/ts/FlexContainer.ts +36 -9
- package/ts/Grid.ts +28 -3
- package/ts/GridContainer.ts +29 -3
- package/ts/Layout.ts +37 -7
- package/ts/Position.ts +29 -4
- package/ts/Rectangle.ts +26 -3
- package/ts/ResponsiveImage.ts +22 -3
- package/ts/ResponsiveScale.ts +25 -2
- package/ts/Size.ts +25 -3
- package/ts/Spacing.ts +45 -7
- package/ts/Transform.ts +37 -4
- package/ts/Typography.ts +40 -6
- package/ts/Unit.ts +34 -10
- package/ts/Viewport.ts +31 -3
- package/ts/index.ts +1 -16
- package/scss/utilities/_guides.scss +0 -103
- package/scss/utilities/_index.scss +0 -6
|
@@ -3,38 +3,35 @@
|
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
5
|
////
|
|
6
|
-
///
|
|
6
|
+
///
|
|
7
7
|
/// Color Variables Module
|
|
8
8
|
/// ===========================================================================
|
|
9
|
-
///
|
|
10
|
-
/// These colors are used for visual guides such as grid overlays, baselines,
|
|
11
|
-
/// and alignment guides. The colors are defined with varying levels of opacity
|
|
9
|
+
///
|
|
10
|
+
/// These colors are used for visual guides such as grid overlays, baselines,
|
|
11
|
+
/// and alignment guides. The colors are defined with varying levels of opacity
|
|
12
12
|
/// to ensure they are visible yet non-intrusive on the design.
|
|
13
|
-
///
|
|
13
|
+
///
|
|
14
14
|
/// @group Color
|
|
15
15
|
/// @author Scape Agency
|
|
16
16
|
/// @link https://unit.gl
|
|
17
17
|
/// @since 0.1.0 initial release
|
|
18
18
|
/// @todo None
|
|
19
19
|
/// @access public
|
|
20
|
-
///
|
|
20
|
+
///
|
|
21
21
|
////
|
|
22
22
|
|
|
23
|
-
|
|
24
23
|
// ============================================================================
|
|
25
24
|
// Use
|
|
26
25
|
// ============================================================================
|
|
27
26
|
|
|
28
|
-
|
|
29
27
|
// ============================================================================
|
|
30
28
|
// Functions
|
|
31
29
|
// ============================================================================
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
///
|
|
31
|
+
///
|
|
35
32
|
/// Function to Retrieve Guide Colors (Optional for Flexibility)
|
|
36
33
|
/// ---------------------------------------------------------------------------
|
|
37
|
-
///
|
|
34
|
+
///
|
|
38
35
|
@function guide_color($name) {
|
|
39
36
|
@return map-get($guide_colors, $name);
|
|
40
37
|
}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
5
|
////
|
|
6
|
-
///
|
|
6
|
+
///
|
|
7
7
|
/// Functions Module
|
|
8
8
|
/// ===========================================================================
|
|
9
|
-
///
|
|
9
|
+
///
|
|
10
10
|
/// This module serves as a central hub for all core SCSS functions used across
|
|
11
11
|
/// the project. By forwarding various function modules, it allows for
|
|
12
12
|
/// consistent access to utilities like mathematical operations, ratio
|
|
@@ -18,28 +18,35 @@
|
|
|
18
18
|
/// - scale: Utilities for implementing modular scales in responsive design.
|
|
19
19
|
/// - sequence: Functions for generating and working with numeric sequences.
|
|
20
20
|
/// - unit: Functions for unit conversions and calculations.
|
|
21
|
-
///
|
|
21
|
+
///
|
|
22
22
|
/// @group Functions
|
|
23
23
|
/// @author Scape Agency
|
|
24
24
|
/// @link https://unit.gl
|
|
25
25
|
/// @since 0.1.0 initial release
|
|
26
26
|
/// @todo None
|
|
27
27
|
/// @access public
|
|
28
|
-
///
|
|
28
|
+
///
|
|
29
29
|
////
|
|
30
30
|
|
|
31
|
-
|
|
32
31
|
// ============================================================================
|
|
33
32
|
// Use
|
|
34
33
|
// ============================================================================
|
|
35
34
|
|
|
36
|
-
|
|
37
35
|
// ============================================================================
|
|
38
36
|
// Forward
|
|
39
37
|
// ============================================================================
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
@forward "
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@forward "
|
|
39
|
+
// Core mathematical operations and utilities
|
|
40
|
+
@forward "math";
|
|
41
|
+
|
|
42
|
+
// Functions for handling and calculating ratios
|
|
43
|
+
@forward "ratio";
|
|
44
|
+
|
|
45
|
+
// Scaling utilities for responsive design
|
|
46
|
+
@forward "scale";
|
|
47
|
+
|
|
48
|
+
// Functions for numeric sequence generation
|
|
49
|
+
@forward "sequence";
|
|
50
|
+
|
|
51
|
+
// Functions for unit conversion and calculations
|
|
52
|
+
@forward "unit";
|
|
@@ -3,46 +3,42 @@
|
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
5
|
////
|
|
6
|
-
///
|
|
6
|
+
///
|
|
7
7
|
/// Layer Functions Module
|
|
8
8
|
/// ===========================================================================
|
|
9
|
-
///
|
|
9
|
+
///
|
|
10
10
|
/// @group Layer
|
|
11
11
|
/// @author Scape Agency
|
|
12
12
|
/// @link https://unit.gl
|
|
13
13
|
/// @since 0.1.0 initial release
|
|
14
14
|
/// @todo None
|
|
15
15
|
/// @access public
|
|
16
|
-
///
|
|
16
|
+
///
|
|
17
17
|
////
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
// ============================================================================
|
|
21
20
|
// Use
|
|
22
21
|
// ============================================================================
|
|
23
22
|
|
|
24
|
-
|
|
25
23
|
// ============================================================================
|
|
26
24
|
// Functions
|
|
27
25
|
// ============================================================================
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
27
|
///
|
|
32
28
|
/// Z-Index Layer Function
|
|
33
29
|
/// ---------------------------------------------------------------------------
|
|
34
|
-
///
|
|
30
|
+
///
|
|
35
31
|
/// This function retrieves the z-index value from the $layers map based on
|
|
36
32
|
/// the provided layer name. If the layer is not found, a warning is issued.
|
|
37
33
|
///
|
|
38
34
|
/// @name z
|
|
39
35
|
/// @param {String} $layer - The name of the layer to retrieve the z-index for.
|
|
40
36
|
/// @return {Number | Null} - The z-index value associated with the layer, or null if not found.
|
|
41
|
-
///
|
|
37
|
+
///
|
|
42
38
|
@function z($layer) {
|
|
43
39
|
@if not map-has-key($layers, $layer) {
|
|
44
40
|
@warn "Layer `#{$layer}` not found in the $layers map. z-index property omitted.";
|
|
45
41
|
@return null;
|
|
46
42
|
}
|
|
47
43
|
@return map-get($layers, $layer);
|
|
48
|
-
}
|
|
44
|
+
}
|
|
@@ -3,47 +3,44 @@
|
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
5
|
////
|
|
6
|
-
///
|
|
6
|
+
///
|
|
7
7
|
/// Ratio Functions Module
|
|
8
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,
|
|
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
13
|
/// typography, and layout.
|
|
14
|
-
///
|
|
14
|
+
///
|
|
15
15
|
/// @group Ratio
|
|
16
16
|
/// @author Scape Agency
|
|
17
17
|
/// @link https://unit.gl
|
|
18
18
|
/// @since 0.1.0 initial release
|
|
19
19
|
/// @todo None
|
|
20
20
|
/// @access public
|
|
21
|
-
///
|
|
21
|
+
///
|
|
22
22
|
////
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
// ============================================================================
|
|
26
25
|
// Use
|
|
27
26
|
// ============================================================================
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
// ============================================================================
|
|
31
29
|
// Functions
|
|
32
30
|
// ============================================================================
|
|
33
31
|
|
|
34
|
-
|
|
35
32
|
///
|
|
36
33
|
/// Golden Ratio Function
|
|
37
34
|
/// ---------------------------------------------------------------------------
|
|
38
|
-
///
|
|
35
|
+
///
|
|
39
36
|
/// Calculates a size using the golden ratio (approximately 1.618), which is
|
|
40
37
|
/// widely used in design for its aesthetically pleasing proportions.
|
|
41
|
-
///
|
|
38
|
+
///
|
|
42
39
|
/// @name ratio_golden
|
|
43
40
|
/// @param {Number} $size - The base size to scale.
|
|
44
41
|
/// @param {Number} $increment - The exponent applied to the golden ratio, default is 1.
|
|
45
42
|
/// @return {Number} - The calculated size based on the golden ratio.
|
|
46
|
-
///
|
|
43
|
+
///
|
|
47
44
|
/// @example scss - Usage Example
|
|
48
45
|
/// // Increase size using the golden ratio
|
|
49
46
|
/// .element {
|
|
@@ -54,17 +51,17 @@
|
|
|
54
51
|
/// .small-element {
|
|
55
52
|
/// width: golden_ratio(16px, -1); // Output: 9.888px
|
|
56
53
|
/// }
|
|
57
|
-
///
|
|
54
|
+
///
|
|
58
55
|
@function ratio_golden($size, $increment: 1) {
|
|
59
56
|
$golden-ratio: 1.618;
|
|
60
57
|
|
|
61
58
|
// Validate the input size
|
|
62
|
-
@if not unitless($size) and type-of($size) !=
|
|
59
|
+
@if not unitless($size) and type-of($size) != "number" {
|
|
63
60
|
@error "The size parameter must be a valid number or unitless value.";
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
// Validate the increment
|
|
67
|
-
@if type-of($increment) !=
|
|
64
|
+
@if type-of($increment) != "number" {
|
|
68
65
|
@error "The increment parameter must be a valid number.";
|
|
69
66
|
}
|
|
70
67
|
|
|
@@ -3,62 +3,64 @@
|
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
5
|
////
|
|
6
|
-
///
|
|
6
|
+
///
|
|
7
7
|
/// Scale Functions Module
|
|
8
8
|
/// ===========================================================================
|
|
9
|
-
///
|
|
9
|
+
///
|
|
10
10
|
/// This module defines various scales used for designing harmonious layouts
|
|
11
11
|
/// and typographies, including musical scales and a classic typographic scale.
|
|
12
12
|
/// It also provides a function to calculate values based on a modular scale,
|
|
13
13
|
/// which is essential for maintaining consistent design proportions.
|
|
14
|
-
///
|
|
14
|
+
///
|
|
15
15
|
/// @group Scale
|
|
16
16
|
/// @author Scape Agency
|
|
17
17
|
/// @link https://unit.gl
|
|
18
18
|
/// @since 0.1.0 initial release
|
|
19
19
|
/// @todo None
|
|
20
20
|
/// @access public
|
|
21
|
-
///
|
|
21
|
+
///
|
|
22
22
|
////
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
// ============================================================================
|
|
26
25
|
// Use
|
|
27
26
|
// ============================================================================
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
// ============================================================================
|
|
31
29
|
// Functions
|
|
32
30
|
// ============================================================================
|
|
33
31
|
|
|
34
|
-
|
|
35
32
|
///
|
|
36
33
|
/// Modular Scale Function
|
|
37
34
|
/// ---------------------------------------------------------------------------
|
|
38
|
-
///
|
|
35
|
+
///
|
|
39
36
|
/// Calculates sizes (like font-size, spacing) based on a modular
|
|
40
37
|
/// scale. This helps maintain harmonious proportions across a design.
|
|
41
|
-
///
|
|
38
|
+
///
|
|
42
39
|
/// @name modular_scale
|
|
43
40
|
/// @param {Number} $increment - The step on the scale, can be positive or negative.
|
|
44
41
|
/// @param {Number} $base - The base value to scale from, defaults to 1em (typographic base size).
|
|
45
42
|
/// @param {Number} $ratio - The ratio to use for scaling, defaults to the Golden Ratio (1.618).
|
|
46
43
|
/// @return {Number} - The calculated value based on the modular scale.
|
|
47
|
-
///
|
|
48
|
-
@function modular_scale(
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
///
|
|
45
|
+
@function modular_scale(
|
|
46
|
+
$increment: 1,
|
|
47
|
+
$base: 1em,
|
|
48
|
+
$ratio: 1.618
|
|
49
|
+
) {
|
|
50
|
+
|
|
51
|
+
// Validate inputs
|
|
52
|
+
@if type-of($increment) != "number" {
|
|
51
53
|
@error "Step must be a number.";
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
@if type-of($base) !=
|
|
55
|
+
|
|
56
|
+
@if type-of($base) != "number" and not unitless($base) {
|
|
55
57
|
@error "Base must be a number with or without units.";
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
@if type-of($ratio) !=
|
|
59
|
+
|
|
60
|
+
@if type-of($ratio) != "number" or $ratio <= 0 {
|
|
59
61
|
@error "Ratio must be a positive number.";
|
|
60
62
|
}
|
|
61
|
-
|
|
63
|
+
|
|
62
64
|
// Calculate the modular scale value
|
|
63
65
|
@return $base * pow($ratio, $increment);
|
|
64
66
|
}
|
|
@@ -3,98 +3,99 @@
|
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
5
|
////
|
|
6
|
-
///
|
|
6
|
+
///
|
|
7
7
|
/// Sequence Functions Module
|
|
8
8
|
/// ===========================================================================
|
|
9
|
-
///
|
|
10
|
-
/// This module provides various functions to calculate terms in well-known
|
|
11
|
-
/// mathematical sequences such as Fibonacci, Lucas, Prime numbers, and more.
|
|
12
|
-
/// Each function is designed to compute the nth term in the respective
|
|
9
|
+
///
|
|
10
|
+
/// This module provides various functions to calculate terms in well-known
|
|
11
|
+
/// mathematical sequences such as Fibonacci, Lucas, Prime numbers, and more.
|
|
12
|
+
/// Each function is designed to compute the nth term in the respective
|
|
13
13
|
/// sequence using a straightforward algorithm.
|
|
14
|
-
///
|
|
14
|
+
///
|
|
15
15
|
/// @group Sequence
|
|
16
16
|
/// @author Scape Agency
|
|
17
17
|
/// @link https://unit.gl
|
|
18
18
|
/// @since 0.1.0 initial release
|
|
19
19
|
/// @todo None
|
|
20
20
|
/// @access public
|
|
21
|
-
///
|
|
21
|
+
///
|
|
22
22
|
////
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
// ============================================================================
|
|
26
25
|
// Use
|
|
27
26
|
// ============================================================================
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
// ============================================================================
|
|
31
29
|
// Functions
|
|
32
30
|
// ============================================================================
|
|
33
31
|
|
|
34
|
-
|
|
35
32
|
///
|
|
36
33
|
/// Fibonacci Number Sequence
|
|
37
34
|
/// ---------------------------------------------------------------------------
|
|
38
|
-
///
|
|
35
|
+
///
|
|
39
36
|
/// Calculates the nth Fibonacci number using a recursive approach.
|
|
40
|
-
/// Fibonacci numbers form a sequence where each number is the sum of the two
|
|
37
|
+
/// Fibonacci numbers form a sequence where each number is the sum of the two
|
|
41
38
|
/// preceding ones, starting with 0 and 1.
|
|
42
|
-
///
|
|
39
|
+
///
|
|
43
40
|
/// @name sequence_fibonacci
|
|
44
41
|
/// @param {Number} $n - The position in the Fibonacci sequence to calculate.
|
|
45
42
|
/// @return {Number} - The nth Fibonacci number.
|
|
46
|
-
///
|
|
47
|
-
|
|
43
|
+
///
|
|
44
|
+
@function sequence_fibonacci($n) {
|
|
48
45
|
@if $n < 0 {
|
|
49
46
|
@warn "Index #{$n} is not valid for the Fibonacci sequence.";
|
|
50
47
|
@return null;
|
|
51
48
|
}
|
|
52
|
-
@if $n == 0 {
|
|
53
|
-
|
|
54
|
-
@else {
|
|
49
|
+
@if $n == 0 {
|
|
50
|
+
@return 0;
|
|
51
|
+
} @else if $n == 1 {
|
|
52
|
+
@return 1;
|
|
53
|
+
} @else {
|
|
55
54
|
@return sequence_fibonacci($n - 1) + sequence_fibonacci($n - 2);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
|
|
60
58
|
///
|
|
61
59
|
/// Lucas Number Sequence
|
|
62
60
|
/// ---------------------------------------------------------------------------
|
|
63
61
|
///
|
|
64
62
|
/// Calculates the nth Lucas number using a recursive approach.
|
|
65
|
-
/// Lucas numbers form a sequence similar to Fibonacci numbers but start with
|
|
63
|
+
/// Lucas numbers form a sequence similar to Fibonacci numbers but start with
|
|
66
64
|
/// 2 and 1 instead of 0 and 1.
|
|
67
|
-
///
|
|
65
|
+
///
|
|
68
66
|
/// @name sequence_lucas
|
|
69
67
|
/// @param {Number} $n - The position in the Lucas sequence to calculate.
|
|
70
68
|
/// @return {Number} - The nth Lucas number.
|
|
71
|
-
///
|
|
69
|
+
///
|
|
72
70
|
@function sequence_lucas($n) {
|
|
73
71
|
@if $n < 0 {
|
|
74
72
|
@warn "Index #{$n} is not valid for the Lucas sequence.";
|
|
75
73
|
@return null;
|
|
76
74
|
}
|
|
77
|
-
@if $n == 0 {
|
|
78
|
-
|
|
79
|
-
@else {
|
|
75
|
+
@if $n == 0 {
|
|
76
|
+
@return 2;
|
|
77
|
+
} @else if $n == 1 {
|
|
78
|
+
@return 1;
|
|
79
|
+
} @else {
|
|
80
80
|
@return sequence_lucas($n - 1) + sequence_lucas($n - 2);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
85
84
|
///
|
|
86
85
|
/// Prime Number Check
|
|
87
86
|
/// ---------------------------------------------------------------------------
|
|
88
|
-
///
|
|
87
|
+
///
|
|
89
88
|
/// Checks if a number is prime.
|
|
90
|
-
/// A prime number is a natural number greater than 1 that has no positive
|
|
89
|
+
/// A prime number is a natural number greater than 1 that has no positive
|
|
91
90
|
/// divisors other than 1 and itself.
|
|
92
91
|
/// @name is_prime
|
|
93
92
|
/// @param {Number} $n - The number to check.
|
|
94
93
|
/// @return {Boolean} - `true` if the number is prime, `false` otherwise.
|
|
95
|
-
///
|
|
94
|
+
///
|
|
96
95
|
@function is_prime($n) {
|
|
97
|
-
@if $n <= 1 {
|
|
96
|
+
@if $n <= 1 {
|
|
97
|
+
@return false;
|
|
98
|
+
}
|
|
98
99
|
@for $i from 2 through math.sqrt($n) {
|
|
99
100
|
@if $n % $i == 0 {
|
|
100
101
|
@return false;
|
|
@@ -103,18 +104,17 @@
|
|
|
103
104
|
@return true;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
|
|
107
107
|
///
|
|
108
108
|
/// Factorial
|
|
109
109
|
/// ---------------------------------------------------------------------------
|
|
110
|
-
///
|
|
110
|
+
///
|
|
111
111
|
/// Calculates the factorial of a number.
|
|
112
112
|
/// Factorial is the product of all positive integers up to a given number.
|
|
113
|
-
///
|
|
113
|
+
///
|
|
114
114
|
/// @name factorial
|
|
115
115
|
/// @param {Number} $n - The number to calculate the factorial for.
|
|
116
116
|
/// @return {Number} - The factorial of $n.
|
|
117
|
-
///
|
|
117
|
+
///
|
|
118
118
|
@function factorial($n) {
|
|
119
119
|
$result: 1;
|
|
120
120
|
@for $i from 1 through $n {
|
|
@@ -126,31 +126,30 @@
|
|
|
126
126
|
///
|
|
127
127
|
/// Catalan Number Sequence
|
|
128
128
|
/// ---------------------------------------------------------------------------
|
|
129
|
-
///
|
|
129
|
+
///
|
|
130
130
|
/// Calculates the nth Catalan number.
|
|
131
|
-
/// Catalan numbers are a sequence of natural numbers with applications in
|
|
131
|
+
/// Catalan numbers are a sequence of natural numbers with applications in
|
|
132
132
|
/// combinatorial mathematics, such as counting certain types of lattice paths.
|
|
133
|
-
///
|
|
133
|
+
///
|
|
134
134
|
/// @name sequence_catalan
|
|
135
135
|
/// @param {Number} $n - The position in the Catalan sequence to calculate.
|
|
136
136
|
/// @return {Number} - The nth Catalan number.
|
|
137
|
-
///
|
|
137
|
+
///
|
|
138
138
|
@function sequence_catalan($n) {
|
|
139
139
|
@return factorial(2 * $n) / (factorial($n + 1) * factorial($n));
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
|
|
143
142
|
///
|
|
144
143
|
/// Harmonic Sequence
|
|
145
144
|
/// ---------------------------------------------------------------------------
|
|
146
|
-
///
|
|
145
|
+
///
|
|
147
146
|
/// Calculates the nth term of the harmonic series.
|
|
148
147
|
/// The harmonic series is the sum of the reciprocals of the positive integers.
|
|
149
|
-
///
|
|
148
|
+
///
|
|
150
149
|
/// @name sequence_harmonic
|
|
151
150
|
/// @param {Number} $n - The position in the harmonic series to calculate.
|
|
152
151
|
/// @return {Number} - The nth term of the harmonic series.
|
|
153
|
-
///
|
|
152
|
+
///
|
|
154
153
|
@function sequence_harmonic($n) {
|
|
155
154
|
@if $n <= 0 {
|
|
156
155
|
@warn "Index #{$n} is not valid for the harmonic series.";
|
|
@@ -159,19 +158,18 @@
|
|
|
159
158
|
@return 1 / $n;
|
|
160
159
|
}
|
|
161
160
|
|
|
162
|
-
|
|
163
161
|
///
|
|
164
162
|
/// Geometric Sequence
|
|
165
163
|
/// ----------------------------------------------------------------------------
|
|
166
|
-
///
|
|
164
|
+
///
|
|
167
165
|
/// Calculates the nth term of a geometric series with a ratio of 2.
|
|
168
|
-
/// A geometric series has a constant ratio between successive terms.
|
|
166
|
+
/// A geometric series has a constant ratio between successive terms.
|
|
169
167
|
/// This function calculates the nth term for a series where each term doubles.
|
|
170
|
-
///
|
|
168
|
+
///
|
|
171
169
|
/// @name sequence_geometric
|
|
172
170
|
/// @param {Number} $n - The position in the geometric series to calculate.
|
|
173
171
|
/// @return {Number} - The nth term of the geometric series.
|
|
174
|
-
///
|
|
172
|
+
///
|
|
175
173
|
@function sequence_geometric($n) {
|
|
176
174
|
@if $n < 0 {
|
|
177
175
|
@warn "Negative index #{$n} is not valid for the geometric series.";
|
|
@@ -180,18 +178,17 @@
|
|
|
180
178
|
@return pow(2, $n - 1);
|
|
181
179
|
}
|
|
182
180
|
|
|
183
|
-
|
|
184
181
|
///
|
|
185
182
|
/// Superfactorial Sequence
|
|
186
183
|
/// ---------------------------------------------------------------------------
|
|
187
|
-
///
|
|
184
|
+
///
|
|
188
185
|
/// Calculates the superfactorial of a number.
|
|
189
186
|
/// The superfactorial of a number n is the product of the first n factorials.
|
|
190
|
-
///
|
|
187
|
+
///
|
|
191
188
|
/// @name sequence_superfactorial
|
|
192
189
|
/// @param {Number} $n - The number to calculate the superfactorial for.
|
|
193
190
|
/// @return {Number} - The superfactorial of $n.
|
|
194
|
-
///
|
|
191
|
+
///
|
|
195
192
|
@function sequence_superfactorial($n) {
|
|
196
193
|
$result: 1;
|
|
197
194
|
@for $i from 1 through $n {
|
|
@@ -204,18 +201,17 @@
|
|
|
204
201
|
@return $result;
|
|
205
202
|
}
|
|
206
203
|
|
|
207
|
-
|
|
208
204
|
///
|
|
209
205
|
/// Triangular Number Sequence
|
|
210
206
|
/// ---------------------------------------------------------------------------
|
|
211
|
-
///
|
|
207
|
+
///
|
|
212
208
|
/// Calculates the nth triangular number.
|
|
213
209
|
/// Triangular numbers are the sum of the first n natural numbers.
|
|
214
|
-
///
|
|
210
|
+
///
|
|
215
211
|
/// @name sequence_triangular
|
|
216
212
|
/// @param {Number} $n - The position in the triangular series to calculate.
|
|
217
213
|
/// @return {Number} - The nth triangular number.
|
|
218
|
-
///
|
|
214
|
+
///
|
|
219
215
|
@function sequence_triangular($n) {
|
|
220
216
|
@if $n <= 0 {
|
|
221
217
|
@warn "Index #{$n} is not valid for the triangular series.";
|
|
@@ -224,19 +220,18 @@
|
|
|
224
220
|
@return $n * ($n + 1) / 2;
|
|
225
221
|
}
|
|
226
222
|
|
|
227
|
-
|
|
228
223
|
///
|
|
229
224
|
/// Square Number Sequence
|
|
230
225
|
/// ---------------------------------------------------------------------------
|
|
231
|
-
///
|
|
226
|
+
///
|
|
232
227
|
/// Calculates the nth square number.
|
|
233
|
-
/// Square numbers are numbers that can be expressed as the product of an
|
|
228
|
+
/// Square numbers are numbers that can be expressed as the product of an
|
|
234
229
|
/// integer with itself (n²).
|
|
235
|
-
///
|
|
230
|
+
///
|
|
236
231
|
/// @name sequence_square
|
|
237
232
|
/// @param {Number} $n - The position in the square series to calculate.
|
|
238
233
|
/// @return {Number} - The nth square number.
|
|
239
|
-
///
|
|
234
|
+
///
|
|
240
235
|
@function sequence_square($n) {
|
|
241
236
|
@if $n < 0 {
|
|
242
237
|
@warn "Negative index #{$n} is not valid for the square series.";
|
|
@@ -245,18 +240,17 @@
|
|
|
245
240
|
@return $n * $n;
|
|
246
241
|
}
|
|
247
242
|
|
|
248
|
-
|
|
249
243
|
///
|
|
250
244
|
/// Pentagonal Number Sequence
|
|
251
245
|
/// ---------------------------------------------------------------------------
|
|
252
|
-
///
|
|
246
|
+
///
|
|
253
247
|
/// Calculates the nth pentagonal number.
|
|
254
248
|
/// Pentagonal numbers are figurate numbers that represent a pentagon.
|
|
255
|
-
///
|
|
249
|
+
///
|
|
256
250
|
/// @name sequence_pentagonal
|
|
257
251
|
/// @param {Number} $n - The position in the pentagonal series to calculate.
|
|
258
252
|
/// @return {Number} - The nth pentagonal number.
|
|
259
|
-
///
|
|
253
|
+
///
|
|
260
254
|
@function sequence_pentagonal($n) {
|
|
261
255
|
@if $n <= 0 {
|
|
262
256
|
@warn "Index #{$n} is not valid for the pentagonal series.";
|
|
@@ -265,18 +259,17 @@
|
|
|
265
259
|
@return (3 * $n * $n - $n) / 2;
|
|
266
260
|
}
|
|
267
261
|
|
|
268
|
-
|
|
269
262
|
///
|
|
270
263
|
/// Hexagonal Number Sequence
|
|
271
264
|
/// ---------------------------------------------------------------------------
|
|
272
|
-
///
|
|
265
|
+
///
|
|
273
266
|
/// Calculates the nth hexagonal number.
|
|
274
267
|
/// Hexagonal numbers are figurate numbers that represent a hexagon.
|
|
275
|
-
///
|
|
268
|
+
///
|
|
276
269
|
/// @name sequence_hexagonal
|
|
277
270
|
/// @param {Number} $n - The position in the hexagonal series to calculate.
|
|
278
271
|
/// @return {Number} - The nth hexagonal number.
|
|
279
|
-
///
|
|
272
|
+
///
|
|
280
273
|
@function sequence_hexagonal($n) {
|
|
281
274
|
@if $n <= 0 {
|
|
282
275
|
@warn "Index #{$n} is not valid for the hexagonal series.";
|
|
@@ -285,18 +278,17 @@
|
|
|
285
278
|
@return 2 * $n * $n - $n;
|
|
286
279
|
}
|
|
287
280
|
|
|
288
|
-
|
|
289
281
|
///
|
|
290
282
|
/// Cube Number Sequence
|
|
291
283
|
/// ---------------------------------------------------------------------------
|
|
292
|
-
///
|
|
284
|
+
///
|
|
293
285
|
/// Calculates the nth cube number.
|
|
294
286
|
/// Cube numbers are numbers raised to the power of three (n³).
|
|
295
|
-
///
|
|
287
|
+
///
|
|
296
288
|
/// @name sequence_cube
|
|
297
289
|
/// @param {Number} $n - The position in the cube series to calculate.
|
|
298
290
|
/// @return {Number} - The nth cube number.
|
|
299
|
-
///
|
|
291
|
+
///
|
|
300
292
|
@function sequence_cube($n) {
|
|
301
293
|
@if $n < 0 {
|
|
302
294
|
@warn "Negative index #{$n} is not valid for the cube series.";
|