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,10 +3,10 @@
|
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
5
|
////
|
|
6
|
-
///
|
|
6
|
+
///
|
|
7
7
|
/// View Variables Module
|
|
8
8
|
/// ===========================================================================
|
|
9
|
-
///
|
|
9
|
+
///
|
|
10
10
|
/// This module defines the breakpoints for responsive design, categorized by
|
|
11
11
|
/// device types. It leverages a base unit to calculate breakpoint values for
|
|
12
12
|
/// consistency across various screen sizes.
|
|
@@ -24,55 +24,55 @@
|
|
|
24
24
|
/// calculating breakpoints.
|
|
25
25
|
///
|
|
26
26
|
/// Example Usage:
|
|
27
|
-
/// @media (min-width: map
|
|
27
|
+
/// @media (min-width: map.get($breakpoints, md)) {
|
|
28
28
|
/// // Styles for medium devices and up
|
|
29
29
|
/// }
|
|
30
|
-
///
|
|
30
|
+
///
|
|
31
31
|
/// @group View
|
|
32
32
|
/// @author Scape Agency
|
|
33
33
|
/// @link https://unit.gl
|
|
34
34
|
/// @since 0.1.0 initial release
|
|
35
35
|
/// @todo None
|
|
36
36
|
/// @access public
|
|
37
|
-
///
|
|
37
|
+
///
|
|
38
38
|
////
|
|
39
39
|
|
|
40
|
-
|
|
41
40
|
// ============================================================================
|
|
42
41
|
// Use
|
|
43
42
|
// ============================================================================
|
|
44
43
|
|
|
44
|
+
@use "sass:map";
|
|
45
45
|
|
|
46
46
|
// ============================================================================
|
|
47
47
|
// Variables
|
|
48
48
|
// ============================================================================
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
///
|
|
50
|
+
///
|
|
52
51
|
/// Base unit size used for calculating breakpoints. Defaults to 16px.
|
|
53
|
-
///
|
|
52
|
+
///
|
|
54
53
|
/// @name $base_screen_unit
|
|
55
54
|
/// @type Length
|
|
56
|
-
///
|
|
55
|
+
///
|
|
57
56
|
$base_screen_unit: 16px !default;
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
///
|
|
58
|
+
///
|
|
62
59
|
/// A map defining the breakpoints for responsive design. Each key represents
|
|
63
60
|
/// a different device category, with the value calculated using the base
|
|
64
61
|
/// screen unit.
|
|
65
|
-
///
|
|
62
|
+
///
|
|
66
63
|
/// - **xs**: 320px (Extra small devices like mobile phones)
|
|
67
64
|
/// - **sm**: 480px (Small devices like tablets)
|
|
68
65
|
/// - **md**: 768px (Medium devices like laptops)
|
|
69
66
|
/// - **lg**: 1024px (Large devices like desktops)
|
|
70
67
|
/// - **xl**: 1280px (Extra large devices like TVs)
|
|
71
68
|
/// - **sl**: 1440px (Super large devices like large TVs)
|
|
72
|
-
///
|
|
69
|
+
///
|
|
73
70
|
/// @name $breakpoints
|
|
74
71
|
/// @type Map
|
|
75
|
-
///
|
|
72
|
+
///
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
76
|
// $breakpoints: (
|
|
77
77
|
// xs: calc_breakpoint($base_screen_unit, 20), // 320px - Extra small devices (Mobile)
|
|
78
78
|
// sm: calc_breakpoint($base_screen_unit, 30), // 480px - Small devices (Tablets)
|
|
@@ -83,78 +83,75 @@ $base_screen_unit: 16px !default;
|
|
|
83
83
|
// ) !default;
|
|
84
84
|
|
|
85
85
|
$breakpoints: (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
xs: 320px,
|
|
87
|
+
// 320px - Extra small devices (Mobile)
|
|
88
|
+
sm: 480px,
|
|
89
|
+
// 480px - Small devices (Tablets)
|
|
90
|
+
md: 768px,
|
|
91
|
+
// 768px - Medium devices (Laptops)
|
|
92
|
+
lg: 1024px,
|
|
93
|
+
// 1024px - Large devices (Desktops)
|
|
94
|
+
xl: 1280px,
|
|
95
|
+
// 1280px - Extra large devices (TV)
|
|
96
|
+
sl: 1440px, // 1440px - Super large devices (Large TV)
|
|
92
97
|
) !default;
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
///
|
|
99
|
+
///
|
|
96
100
|
/// Exposes the value of the `xs` breakpoint for direct access.
|
|
97
|
-
///
|
|
101
|
+
///
|
|
98
102
|
/// @name $media_xs
|
|
99
103
|
/// @type Length
|
|
100
|
-
///
|
|
101
|
-
$media_xs: map
|
|
102
|
-
|
|
104
|
+
///
|
|
105
|
+
$media_xs: map.get($breakpoints, xs) !default;
|
|
103
106
|
|
|
104
|
-
///
|
|
107
|
+
///
|
|
105
108
|
/// Exposes the value of the `sm` breakpoint for direct access.
|
|
106
|
-
///
|
|
109
|
+
///
|
|
107
110
|
/// @name $media_sm
|
|
108
111
|
/// @type Length
|
|
109
|
-
///
|
|
110
|
-
$media_sm: map
|
|
111
|
-
|
|
112
|
+
///
|
|
113
|
+
$media_sm: map.get($breakpoints, sm) !default;
|
|
112
114
|
|
|
113
|
-
///
|
|
115
|
+
///
|
|
114
116
|
/// Exposes the value of the `md` breakpoint for direct access.
|
|
115
|
-
///
|
|
117
|
+
///
|
|
116
118
|
/// @name $media_md
|
|
117
119
|
/// @type Length
|
|
118
|
-
///
|
|
119
|
-
$media_md: map
|
|
120
|
-
|
|
120
|
+
///
|
|
121
|
+
$media_md: map.get($breakpoints, md) !default;
|
|
121
122
|
|
|
122
|
-
///
|
|
123
|
+
///
|
|
123
124
|
/// Exposes the value of the `lg` breakpoint for direct access.
|
|
124
|
-
///
|
|
125
|
+
///
|
|
125
126
|
/// @name $media_lg
|
|
126
127
|
/// @type Length
|
|
127
|
-
///
|
|
128
|
-
$media_lg: map
|
|
129
|
-
|
|
128
|
+
///
|
|
129
|
+
$media_lg: map.get($breakpoints, lg) !default;
|
|
130
130
|
|
|
131
|
-
///
|
|
131
|
+
///
|
|
132
132
|
/// Exposes the value of the `xl` breakpoint for direct access.
|
|
133
|
-
///
|
|
133
|
+
///
|
|
134
134
|
/// @name $media_xl
|
|
135
135
|
/// @type Length
|
|
136
|
-
///
|
|
137
|
-
$media_xl: map
|
|
138
|
-
|
|
136
|
+
///
|
|
137
|
+
$media_xl: map.get($breakpoints, xl) !default;
|
|
139
138
|
|
|
140
|
-
///
|
|
139
|
+
///
|
|
141
140
|
/// Exposes the value of the `sl` breakpoint for direct access.
|
|
142
|
-
///
|
|
141
|
+
///
|
|
143
142
|
/// @name $media_sl
|
|
144
143
|
/// @type Length
|
|
145
|
-
///
|
|
146
|
-
$media_sl: map
|
|
147
|
-
|
|
144
|
+
///
|
|
145
|
+
$media_sl: map.get($breakpoints, sl) !default;
|
|
148
146
|
|
|
149
|
-
///
|
|
147
|
+
///
|
|
150
148
|
/// Calculates the difference between the `sl` and `xs` breakpoints.
|
|
151
|
-
///
|
|
149
|
+
///
|
|
152
150
|
/// @name $media_dif
|
|
153
151
|
/// @type Length
|
|
154
|
-
///
|
|
152
|
+
///
|
|
155
153
|
$media_dif: calc($media_sl - $media_xs);
|
|
156
154
|
|
|
157
|
-
|
|
158
155
|
// Uncomment below if you want to use the following predefined breakpoints for various devices:
|
|
159
156
|
|
|
160
157
|
// $media_min: 320px !default; // Mobile
|
package/ts/AspectRatio.ts
CHANGED
|
@@ -1,29 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import Unit from "./Unit";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Classes
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export default class AspectRatio {
|
|
13
|
+
|
|
14
|
+
// Parameters
|
|
15
|
+
// ========================================================================
|
|
16
|
+
|
|
2
17
|
width: Unit;
|
|
3
18
|
height: Unit;
|
|
4
19
|
|
|
20
|
+
// Constructor
|
|
21
|
+
// ========================================================================
|
|
22
|
+
|
|
5
23
|
constructor(width: Unit, height: Unit) {
|
|
6
24
|
this.width = width;
|
|
7
25
|
this.height = height;
|
|
8
26
|
}
|
|
9
27
|
|
|
28
|
+
// Methods
|
|
29
|
+
// ========================================================================
|
|
30
|
+
|
|
10
31
|
calculateRatio(): number {
|
|
11
32
|
return this.width.value / this.height.value;
|
|
12
33
|
}
|
|
13
34
|
|
|
14
35
|
scaleToWidth(newWidth: Unit): Unit {
|
|
15
|
-
const ratio = this.calculateRatio();
|
|
16
|
-
const newHeightValue = newWidth.value / ratio;
|
|
36
|
+
const ratio: number = this.calculateRatio();
|
|
37
|
+
const newHeightValue: number = newWidth.value / ratio;
|
|
17
38
|
return new Unit(newHeightValue, newWidth.unit);
|
|
18
39
|
}
|
|
19
40
|
|
|
20
41
|
scaleToHeight(newHeight: Unit): Unit {
|
|
21
|
-
const ratio = this.calculateRatio();
|
|
22
|
-
const newWidthValue = newHeight.value * ratio;
|
|
42
|
+
const ratio: number = this.calculateRatio();
|
|
43
|
+
const newWidthValue: number = newHeight.value * ratio;
|
|
23
44
|
return new Unit(newWidthValue, newHeight.unit);
|
|
24
45
|
}
|
|
25
46
|
|
|
26
47
|
toString(): string {
|
|
27
48
|
return `AspectRatio: width ${this.width.toString()}, height ${this.height.toString()}, ratio ${this.calculateRatio()}`;
|
|
28
49
|
}
|
|
29
|
-
}
|
|
50
|
+
}
|
package/ts/Border.ts
CHANGED
|
@@ -1,16 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import Unit from "./Unit";
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Types
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
type BorderStyle = "solid" | "dashed" | "dotted" | "double" | "none";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Classes
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
export default class Border {
|
|
19
|
+
|
|
20
|
+
// Parameters
|
|
21
|
+
// ========================================================================
|
|
2
22
|
|
|
3
|
-
class Border {
|
|
4
23
|
width: Unit;
|
|
5
24
|
style: BorderStyle;
|
|
6
25
|
color: string;
|
|
7
26
|
|
|
8
|
-
|
|
27
|
+
|
|
28
|
+
// Constructor
|
|
29
|
+
// ========================================================================
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
width: Unit,
|
|
33
|
+
style: BorderStyle,
|
|
34
|
+
color: string
|
|
35
|
+
) {
|
|
9
36
|
this.width = width;
|
|
10
37
|
this.style = style;
|
|
11
38
|
this.color = color;
|
|
12
39
|
}
|
|
13
40
|
|
|
41
|
+
// Methods
|
|
42
|
+
// ========================================================================
|
|
43
|
+
|
|
14
44
|
setWidth(newWidth: Unit): void {
|
|
15
45
|
this.width = newWidth;
|
|
16
46
|
}
|
|
@@ -26,4 +56,5 @@ class Border {
|
|
|
26
56
|
toString(): string {
|
|
27
57
|
return `Border: ${this.width.toString()} ${this.style} ${this.color}`;
|
|
28
58
|
}
|
|
29
|
-
|
|
59
|
+
|
|
60
|
+
}
|
package/ts/BoxModel.ts
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import Border from "./Border";
|
|
6
|
+
import Size from "./Size";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Classes
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
export default class BoxModel {
|
|
14
|
+
|
|
15
|
+
// Parameters
|
|
16
|
+
// ========================================================================
|
|
17
|
+
|
|
2
18
|
margin: Margin;
|
|
3
19
|
padding: Padding;
|
|
4
20
|
border: Border;
|
|
5
21
|
size: Size;
|
|
6
22
|
|
|
7
|
-
|
|
23
|
+
// Constructor
|
|
24
|
+
// ========================================================================
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
margin: Margin,
|
|
28
|
+
padding: Padding,
|
|
29
|
+
border: Border,
|
|
30
|
+
size: Size
|
|
31
|
+
) {
|
|
8
32
|
if (
|
|
9
33
|
margin.top.unit !== size.width.unit ||
|
|
10
34
|
padding.top.unit !== size.width.unit ||
|
|
11
35
|
border.width.unit !== size.width.unit
|
|
12
36
|
) {
|
|
13
|
-
throw new Error(
|
|
37
|
+
throw new Error("All units in BoxModel must match");
|
|
14
38
|
}
|
|
15
39
|
this.margin = margin;
|
|
16
40
|
this.padding = padding;
|
|
@@ -18,6 +42,10 @@ class BoxModel {
|
|
|
18
42
|
this.size = size;
|
|
19
43
|
}
|
|
20
44
|
|
|
45
|
+
|
|
46
|
+
// Methods
|
|
47
|
+
// ========================================================================
|
|
48
|
+
|
|
21
49
|
setMargin(margin: Margin): void {
|
|
22
50
|
this.margin = margin;
|
|
23
51
|
}
|
|
@@ -37,4 +65,4 @@ class BoxModel {
|
|
|
37
65
|
toString(): string {
|
|
38
66
|
return `BoxModel:\n Size: ${this.size.toString()}\n Margin: ${this.margin.toString()}\n Padding: ${this.padding.toString()}\n Border: ${this.border.toString()}`;
|
|
39
67
|
}
|
|
40
|
-
}
|
|
68
|
+
}
|
package/ts/FlexContainer.ts
CHANGED
|
@@ -1,19 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
type FlexDirection = "row" | "row-reverse" | "column" | "column-reverse";
|
|
11
|
+
type FlexWrap = "nowrap" | "wrap" | "wrap-reverse";
|
|
12
|
+
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Classes
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export default class FlexContainer {
|
|
20
|
+
|
|
21
|
+
// Parameters
|
|
22
|
+
// ========================================================================
|
|
3
23
|
|
|
4
|
-
class FlexContainer {
|
|
5
24
|
flexDirection: FlexDirection;
|
|
6
25
|
flexWrap: FlexWrap;
|
|
7
26
|
justifyContent: Justify;
|
|
8
27
|
alignItems: Align;
|
|
9
28
|
alignContent: Align;
|
|
10
29
|
|
|
30
|
+
|
|
31
|
+
// Constructor
|
|
32
|
+
// ========================================================================
|
|
33
|
+
|
|
11
34
|
constructor(
|
|
12
|
-
flexDirection: FlexDirection =
|
|
13
|
-
flexWrap: FlexWrap =
|
|
14
|
-
justifyContent: Justify =
|
|
15
|
-
alignItems: Align =
|
|
16
|
-
alignContent: Align =
|
|
35
|
+
flexDirection: FlexDirection = "row",
|
|
36
|
+
flexWrap: FlexWrap = "nowrap",
|
|
37
|
+
justifyContent: Justify = "start",
|
|
38
|
+
alignItems: Align = "stretch",
|
|
39
|
+
alignContent: Align = "stretch"
|
|
17
40
|
) {
|
|
18
41
|
this.flexDirection = flexDirection;
|
|
19
42
|
this.flexWrap = flexWrap;
|
|
@@ -22,6 +45,10 @@ class FlexContainer {
|
|
|
22
45
|
this.alignContent = alignContent;
|
|
23
46
|
}
|
|
24
47
|
|
|
48
|
+
|
|
49
|
+
// Methods
|
|
50
|
+
// ========================================================================
|
|
51
|
+
|
|
25
52
|
setDirection(direction: FlexDirection): void {
|
|
26
53
|
this.flexDirection = direction;
|
|
27
54
|
}
|
|
@@ -45,4 +72,4 @@ class FlexContainer {
|
|
|
45
72
|
toString(): string {
|
|
46
73
|
return `FlexContainer: direction ${this.flexDirection}, wrap ${this.flexWrap}, justify ${this.justifyContent}, align-items ${this.alignItems}, align-content ${this.alignContent}`;
|
|
47
74
|
}
|
|
48
|
-
}
|
|
75
|
+
}
|
package/ts/Grid.ts
CHANGED
|
@@ -1,14 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import Unit from "./Unit";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Classes
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export default class Grid {
|
|
13
|
+
|
|
14
|
+
// Parameters
|
|
15
|
+
// ========================================================================
|
|
16
|
+
|
|
2
17
|
columns: number;
|
|
3
18
|
gutter: Unit;
|
|
4
19
|
rowHeight: Unit;
|
|
5
20
|
|
|
6
|
-
|
|
21
|
+
// Constructor
|
|
22
|
+
// ========================================================================
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
columns: number,
|
|
26
|
+
gutter: Unit,
|
|
27
|
+
rowHeight: Unit
|
|
28
|
+
) {
|
|
7
29
|
this.columns = columns;
|
|
8
30
|
this.gutter = gutter;
|
|
9
31
|
this.rowHeight = rowHeight;
|
|
10
32
|
}
|
|
11
33
|
|
|
34
|
+
// Methods
|
|
35
|
+
// ========================================================================
|
|
36
|
+
|
|
12
37
|
getColumnWidth(containerWidth: Unit): Unit {
|
|
13
38
|
const totalGutterWidth = this.gutter.value * (this.columns - 1);
|
|
14
39
|
const columnWidth = (containerWidth.value - totalGutterWidth) / this.columns;
|
|
@@ -18,4 +43,4 @@ class Grid {
|
|
|
18
43
|
toString(): string {
|
|
19
44
|
return `Grid: ${this.columns} columns, gutter ${this.gutter.toString()}, row height ${this.rowHeight.toString()}`;
|
|
20
45
|
}
|
|
21
|
-
}
|
|
46
|
+
}
|
package/ts/GridContainer.ts
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import Unit from "./Unit";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Classes
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export default class GridContainer {
|
|
13
|
+
|
|
14
|
+
// Parameters
|
|
15
|
+
// ========================================================================
|
|
16
|
+
|
|
2
17
|
rows: number;
|
|
3
18
|
columns: number;
|
|
4
19
|
rowGap: Unit;
|
|
5
20
|
columnGap: Unit;
|
|
6
21
|
|
|
7
|
-
|
|
22
|
+
// Constructor
|
|
23
|
+
// ========================================================================
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
rows: number,
|
|
27
|
+
columns: number,
|
|
28
|
+
rowGap: Unit,
|
|
29
|
+
columnGap: Unit
|
|
30
|
+
) {
|
|
8
31
|
this.rows = rows;
|
|
9
32
|
this.columns = columns;
|
|
10
33
|
this.rowGap = rowGap;
|
|
11
34
|
this.columnGap = columnGap;
|
|
12
35
|
}
|
|
13
36
|
|
|
37
|
+
// Methods
|
|
38
|
+
// ========================================================================
|
|
39
|
+
|
|
14
40
|
setRows(rows: number): void {
|
|
15
41
|
this.rows = rows;
|
|
16
42
|
}
|
|
@@ -30,4 +56,4 @@ class GridContainer {
|
|
|
30
56
|
toString(): string {
|
|
31
57
|
return `GridContainer: ${this.rows} rows, ${this.columns} columns, row-gap ${this.rowGap.toString()}, column-gap ${this.columnGap.toString()}`;
|
|
32
58
|
}
|
|
33
|
-
}
|
|
59
|
+
}
|
package/ts/Layout.ts
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import Unit from "./Unit";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Types
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
type Align = "start" | "center" | "end" | "stretch";
|
|
13
|
+
type Justify = "start" | "center" | "end" | "space-between" | "space-around";
|
|
14
|
+
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Classes
|
|
17
|
+
// ============================================================================
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export default class Layout {
|
|
22
|
+
|
|
23
|
+
// Parameters
|
|
24
|
+
// ========================================================================
|
|
3
25
|
|
|
4
|
-
class Layout {
|
|
5
26
|
width: Unit;
|
|
6
27
|
height: Unit;
|
|
7
28
|
align: Align;
|
|
8
29
|
justify: Justify;
|
|
9
|
-
direction:
|
|
30
|
+
direction: "row" | "column";
|
|
10
31
|
|
|
11
|
-
|
|
32
|
+
// Constructor
|
|
33
|
+
// ========================================================================
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
width: Unit,
|
|
37
|
+
height: Unit,
|
|
38
|
+
align: Align = "stretch", justify: Justify = "start", direction: "row" | "column" = "row") {
|
|
12
39
|
this.width = width;
|
|
13
40
|
this.height = height;
|
|
14
41
|
this.align = align;
|
|
@@ -16,6 +43,9 @@ class Layout {
|
|
|
16
43
|
this.direction = direction;
|
|
17
44
|
}
|
|
18
45
|
|
|
46
|
+
// Methods
|
|
47
|
+
// ========================================================================
|
|
48
|
+
|
|
19
49
|
setAlign(align: Align): void {
|
|
20
50
|
this.align = align;
|
|
21
51
|
}
|
|
@@ -24,11 +54,11 @@ class Layout {
|
|
|
24
54
|
this.justify = justify;
|
|
25
55
|
}
|
|
26
56
|
|
|
27
|
-
setDirection(direction:
|
|
57
|
+
setDirection(direction: "row" | "column"): void {
|
|
28
58
|
this.direction = direction;
|
|
29
59
|
}
|
|
30
60
|
|
|
31
61
|
toString(): string {
|
|
32
62
|
return `Layout: ${this.direction}, width ${this.width.toString()}, height ${this.height.toString()}, align ${this.align}, justify ${this.justify}`;
|
|
33
63
|
}
|
|
34
|
-
}
|
|
64
|
+
}
|
package/ts/Position.ts
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import Unit from "./Unit";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Classes
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export default class Position {
|
|
13
|
+
|
|
14
|
+
// Parameters
|
|
15
|
+
// ========================================================================
|
|
16
|
+
|
|
2
17
|
x: Unit;
|
|
3
18
|
y: Unit;
|
|
4
19
|
|
|
5
|
-
|
|
20
|
+
// Constructor
|
|
21
|
+
// ========================================================================
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
x: Unit,
|
|
25
|
+
y: Unit
|
|
26
|
+
) {
|
|
6
27
|
if (x.unit !== y.unit) {
|
|
7
|
-
throw new Error(
|
|
28
|
+
throw new Error("X and Y must have the same unit");
|
|
8
29
|
}
|
|
9
30
|
this.x = x;
|
|
10
31
|
this.y = y;
|
|
11
32
|
}
|
|
12
33
|
|
|
34
|
+
// Methods
|
|
35
|
+
// ========================================================================
|
|
36
|
+
|
|
13
37
|
add(other: Position): Position {
|
|
14
38
|
return new Position(this.x.add(other.x), this.y.add(other.y));
|
|
15
39
|
}
|
|
@@ -25,4 +49,5 @@ class Position {
|
|
|
25
49
|
toString(): string {
|
|
26
50
|
return `Position: (${this.x.toString()}, ${this.y.toString()})`;
|
|
27
51
|
}
|
|
28
|
-
|
|
52
|
+
|
|
53
|
+
}
|