unit.gl 0.0.35 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +30 -74
  3. package/css/unit.gl.css +28 -65
  4. package/css/unit.gl.min.css +1 -1
  5. package/package.json +13 -8
  6. package/scss/_global.scss +5 -23
  7. package/scss/_reset.scss +13 -15
  8. package/scss/classes/_guide.scss +126 -0
  9. package/scss/classes/_index.scss +25 -11
  10. package/scss/classes/_ratio.scss +30 -0
  11. package/scss/dev/_banner.scss +30 -1
  12. package/scss/dev/_index.scss +0 -0
  13. package/scss/functions/_color.scss +40 -0
  14. package/scss/functions/_index.scss +39 -16
  15. package/scss/functions/_layer.scss +48 -0
  16. package/scss/functions/_ratio.scss +58 -157
  17. package/scss/functions/_scale.scss +55 -49
  18. package/scss/functions/_sequence.scss +154 -126
  19. package/scss/functions/_view.scss +40 -0
  20. package/scss/functions/math/_arithmetic.scss +102 -0
  21. package/scss/functions/math/_index.scss +30 -0
  22. package/scss/functions/unit/_index.scss +30 -0
  23. package/scss/functions/unit/_unit_conversion.scss +94 -0
  24. package/scss/functions/{_unit_functions.scss → unit/_unit_functions.scss} +70 -36
  25. package/scss/index.scss +2 -16
  26. package/scss/maps/_color.scss +43 -0
  27. package/scss/maps/_index.scss +1 -0
  28. package/scss/mixins/_device.scss +63 -25
  29. package/scss/mixins/_display.scss +106 -44
  30. package/scss/mixins/_guide.scss +191 -158
  31. package/scss/mixins/_helper.scss +287 -52
  32. package/scss/mixins/_index.scss +50 -17
  33. package/scss/mixins/_paper.scss +38 -17
  34. package/scss/mixins/_ratio.scss +30 -13
  35. package/scss/mixins/_unit.scss +94 -0
  36. package/scss/mixins/_view.scss +123 -44
  37. package/scss/tags/_index.scss +30 -0
  38. package/scss/tags/_unit.scss +40 -0
  39. package/scss/utilities/_guides.scss +103 -0
  40. package/scss/utilities/_index.scss +6 -0
  41. package/scss/variables/_color.scss +83 -0
  42. package/scss/variables/_device.scss +140 -50
  43. package/scss/variables/_index.scss +84 -16
  44. package/scss/variables/_layer.scss +148 -51
  45. package/scss/variables/_paper.scss +243 -17
  46. package/scss/variables/_ratio.scss +224 -0
  47. package/scss/variables/_scale.scss +230 -104
  48. package/scss/variables/_unit.scss +76 -72
  49. package/scss/variables/_view.scss +135 -39
  50. package/ts/AspectRatio.ts +29 -0
  51. package/ts/Border.ts +29 -0
  52. package/ts/BoxModel.ts +40 -0
  53. package/ts/FlexContainer.ts +48 -0
  54. package/ts/Grid.ts +21 -0
  55. package/ts/GridContainer.ts +33 -0
  56. package/ts/Layout.ts +34 -0
  57. package/ts/Position.ts +28 -0
  58. package/ts/Rectangle.ts +28 -0
  59. package/ts/ResponsiveImage.ts +28 -0
  60. package/ts/ResponsiveScale.ts +21 -0
  61. package/ts/Size.ts +32 -0
  62. package/ts/Spacing.ts +68 -0
  63. package/ts/Transform.ts +38 -0
  64. package/ts/Typography.ts +41 -0
  65. package/ts/Unit.ts +57 -0
  66. package/ts/Viewport.ts +24 -0
  67. package/js/index.d.ts +0 -1
  68. package/js/index.js +0 -3
  69. package/js/unit.gl.min.js +0 -1
  70. package/scss/classes/_paper.scss +0 -97
  71. package/scss/functions/_arithmetic.scss +0 -64
  72. package/scss/functions/_unit_conversion.scss +0 -77
@@ -0,0 +1,41 @@
1
+ type FontWeight = 'normal' | 'bold' | number;
2
+
3
+ class Typography {
4
+ fontSize: Unit;
5
+ fontWeight: FontWeight;
6
+ lineHeight: Unit;
7
+ letterSpacing: Unit;
8
+ textAlign: 'left' | 'right' | 'center' | 'justify';
9
+
10
+ constructor(fontSize: Unit, fontWeight: FontWeight = 'normal', lineHeight: Unit, letterSpacing: Unit, textAlign: 'left' | 'right' | 'center' | 'justify' = 'left') {
11
+ this.fontSize = fontSize;
12
+ this.fontWeight = fontWeight;
13
+ this.lineHeight = lineHeight;
14
+ this.letterSpacing = letterSpacing;
15
+ this.textAlign = textAlign;
16
+ }
17
+
18
+ setFontSize(fontSize: Unit): void {
19
+ this.fontSize = fontSize;
20
+ }
21
+
22
+ setFontWeight(fontWeight: FontWeight): void {
23
+ this.fontWeight = fontWeight;
24
+ }
25
+
26
+ setLineHeight(lineHeight: Unit): void {
27
+ this.lineHeight = lineHeight;
28
+ }
29
+
30
+ setLetterSpacing(letterSpacing: Unit): void {
31
+ this.letterSpacing = letterSpacing;
32
+ }
33
+
34
+ setTextAlign(textAlign: 'left' | 'right' | 'center' | 'justify'): void {
35
+ this.textAlign = textAlign;
36
+ }
37
+
38
+ toString(): string {
39
+ return `Typography: font-size ${this.fontSize.toString()}, weight ${this.fontWeight}, line-height ${this.lineHeight.toString()}, letter-spacing ${this.letterSpacing.toString()}, text-align ${this.textAlign}`;
40
+ }
41
+ }
package/ts/Unit.ts ADDED
@@ -0,0 +1,57 @@
1
+ type UnitType = 'px' | 'em' | '%' | 'rem' | 'mm' | 'cm' | 'in';
2
+
3
+ class Unit {
4
+ value: number;
5
+ unit: UnitType;
6
+
7
+ constructor(value: number, unit: UnitType) {
8
+ this.value = value;
9
+ this.unit = unit;
10
+ }
11
+
12
+ add(other: Unit): Unit {
13
+ if (this.unit !== other.unit) {
14
+ throw new Error(`Cannot add units of different types: ${this.unit} and ${other.unit}`);
15
+ }
16
+ return new Unit(this.value + other.value, this.unit);
17
+ }
18
+
19
+ subtract(other: Unit): Unit {
20
+ if (this.unit !== other.unit) {
21
+ throw new Error(`Cannot subtract units of different types: ${this.unit} and ${other.unit}`);
22
+ }
23
+ return new Unit(this.value - other.value, this.unit);
24
+ }
25
+
26
+ multiply(factor: number): Unit {
27
+ return new Unit(this.value * factor, this.unit);
28
+ }
29
+
30
+ divide(divisor: number): Unit {
31
+ return new Unit(this.value / divisor, this.unit);
32
+ }
33
+
34
+ convert(toUnit: UnitType): Unit {
35
+ // Example conversion: assumes 1in = 96px, 1cm = 37.7953px, etc.
36
+ const conversionRates: { [key in UnitType]?: number } = {
37
+ 'px': 1,
38
+ 'em': 16,
39
+ 'rem': 16,
40
+ 'in': 96,
41
+ 'cm': 37.7953,
42
+ 'mm': 3.77953,
43
+ '%': 1 // Conversion for percentages might be contextual
44
+ };
45
+
46
+ if (!conversionRates[this.unit] || !conversionRates[toUnit]) {
47
+ throw new Error(`Conversion from ${this.unit} to ${toUnit} is not supported`);
48
+ }
49
+
50
+ const convertedValue = (this.value * conversionRates[this.unit]!) / conversionRates[toUnit]!;
51
+ return new Unit(convertedValue, toUnit);
52
+ }
53
+
54
+ toString(): string {
55
+ return `${this.value}${this.unit}`;
56
+ }
57
+ }
package/ts/Viewport.ts ADDED
@@ -0,0 +1,24 @@
1
+ class Viewport {
2
+ width: Unit;
3
+ height: Unit;
4
+ pixelRatio: number;
5
+
6
+ constructor(width: Unit, height: Unit, pixelRatio: number = 1) {
7
+ this.width = width;
8
+ this.height = height;
9
+ this.pixelRatio = pixelRatio;
10
+ }
11
+
12
+ resize(newWidth: Unit, newHeight: Unit): void {
13
+ this.width = newWidth;
14
+ this.height = newHeight;
15
+ }
16
+
17
+ setPixelRatio(ratio: number): void {
18
+ this.pixelRatio = ratio;
19
+ }
20
+
21
+ toString(): string {
22
+ return `Viewport: ${this.width.toString()} x ${this.height.toString()} @ ${this.pixelRatio}x pixel ratio`;
23
+ }
24
+ }
package/js/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/js/index.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // Copyright 2020 Scape Agency BV
3
- Object.defineProperty(exports, "__esModule", { value: true });
package/js/unit.gl.min.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"t",{value:!0});
@@ -1,97 +0,0 @@
1
- // Copyright 2024 Scape Agency BV
2
-
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
-
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
-
16
- // ============================================================================
17
- // Paper Module
18
- // ============================================================================
19
-
20
-
21
- @use "../variables" as *;
22
-
23
-
24
- // Usage
25
- // ============================================================================
26
-
27
- // .paper {
28
-
29
- // // Q Series
30
- // // ------------------------------------------------------------------------
31
- // &.q0 { @include set_paper_size("q0"); }
32
- // &.q1 { @include set_paper_size("q1"); }
33
- // &.q2 { @include set_paper_size("q2"); }
34
- // &.q3 { @include set_paper_size("q3"); }
35
- // &.q4 { @include set_paper_size("q4"); }
36
- // &.q5 { @include set_paper_size("q5"); }
37
- // &.q6 { @include set_paper_size("q6"); }
38
- // &.q7 { @include set_paper_size("q7"); }
39
- // &.q8 { @include set_paper_size("q8"); }
40
- // &.q9 { @include set_paper_size("q9"); }
41
- // &.q10 { @include set_paper_size("q10"); }
42
-
43
- // // ISO A Series
44
- // // ------------------------------------------------------------------------
45
- // &.iso_a0 { @include set_paper_size("iso_a0"); }
46
- // &.iso_a1 { @include set_paper_size("iso_a1"); }
47
- // &.iso_a2 { @include set_paper_size("iso_a2"); }
48
- // &.iso_a3 { @include set_paper_size("iso_a3"); }
49
- // &.iso_a4 { @include set_paper_size("iso_a4"); }
50
- // &.iso_a5 { @include set_paper_size("iso_a5"); }
51
- // &.iso_a6 { @include set_paper_size("iso_a6"); }
52
- // &.iso_a7 { @include set_paper_size("iso_a7"); }
53
- // &.iso_a8 { @include set_paper_size("iso_a8"); }
54
- // &.iso_a9 { @include set_paper_size("iso_a9"); }
55
- // &.iso_a10 { @include set_paper_size("iso_a10"); }
56
-
57
- // }
58
-
59
- // Function to calculate ISO paper sizes
60
- // @function iso-paper-size($number) {
61
- // $base-width: 841mm;
62
- // $base-height: 1189mm;
63
-
64
- // @for $i from 0 through $number {
65
- // $base-width: $base-width / if($i > 0, 2, 1);
66
- // $base-height: $base-height / if($i > 0 and $i % 2 == 0, 2, 1);
67
- // }
68
-
69
- // @return (width: $base-width, height: $base-height);
70
- // }
71
-
72
-
73
- // Function to calculate ISO B-series paper sizes
74
- // @function iso-paper-size-b($number) {
75
- // $base-width: 1000mm; // Approximate base width for B0
76
- // $base-height: 1414mm; // Approximate base height for B0
77
-
78
- // @for $i from 0 through $number {
79
- // $base-width: $base-width / if($i > 0, sqrt(2), 1);
80
- // $base-height: $base-height / if($i > 0 and $i % 2 == 0, sqrt(2), 1);
81
- // }
82
-
83
- // @return (width: $base-width, height: $base-height);
84
- // }
85
-
86
- // Function to calculate ISO C-series paper sizes
87
- // @function iso-paper-size-c($number) {
88
- // $base-width: 917mm; // Approximate base width for C0
89
- // $base-height: 1297mm; // Approximate base height for C0
90
-
91
- // @for $i from 0 through $number {
92
- // $base-width: $base-width / if($i > 0, sqrt(2), 1);
93
- // $base-height: $base-height / if($i > 0 and $i % 2 == 0, sqrt(2), 1);
94
- // }
95
-
96
- // @return (width: $base-width, height: $base-height);
97
- // }
@@ -1,64 +0,0 @@
1
- // Copyright 2024 Scape Agency BV
2
-
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
-
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
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
- }
@@ -1,77 +0,0 @@
1
- // Copyright 2024 Scape Agency BV
2
-
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
-
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
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
- }