unit.gl 0.1.2 → 0.1.9

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/README.md +5 -5
  2. package/css/unit.gl.css +253 -122
  3. package/css/unit.gl.min.css +1 -1
  4. package/js/grids.js +59 -0
  5. package/js/grids.js.map +1 -0
  6. package/js/unit.gl.js +10 -0
  7. package/js/unit.gl.js.map +1 -0
  8. package/package.json +2 -2
  9. package/scss/_reset.scss +15 -1
  10. package/scss/classes/_guide.scss +56 -54
  11. package/scss/classes/_index.scss +1 -5
  12. package/scss/classes/_ratio.scss +56 -6
  13. package/scss/dev/_banner.scss +0 -4
  14. package/scss/functions/_color.scss +1 -5
  15. package/scss/functions/_index.scss +0 -4
  16. package/scss/functions/_layer.scss +3 -6
  17. package/scss/functions/_ratio.scss +2 -5
  18. package/scss/functions/_scale.scss +8 -14
  19. package/scss/functions/_sequence.scss +0 -5
  20. package/scss/functions/_view.scss +0 -4
  21. package/scss/functions/math/_arithmetic.scss +12 -10
  22. package/scss/functions/math/_index.scss +0 -4
  23. package/scss/functions/unit/_index.scss +0 -4
  24. package/scss/functions/unit/_unit_conversion.scss +6 -30
  25. package/scss/functions/unit/_unit_functions.scss +2 -16
  26. package/scss/index.scss +12 -1
  27. package/scss/maps/_color.scss +1 -5
  28. package/scss/{variables → maps}/_device.scss +78 -73
  29. package/scss/maps/_index.scss +36 -5
  30. package/scss/{variables/_ratio.scss → maps/_interval.scss} +1 -6
  31. package/scss/{variables → maps}/_layer.scss +24 -20
  32. package/scss/{variables → maps}/_paper.scss +613 -414
  33. package/scss/maps/_ratio.scss +76 -0
  34. package/scss/maps/_scale.scss +82 -0
  35. package/scss/mixins/_device.scss +11 -8
  36. package/scss/mixins/_display.scss +35 -72
  37. package/scss/mixins/_guide.scss +151 -43
  38. package/scss/mixins/_helper.scss +2 -6
  39. package/scss/mixins/_index.scss +0 -4
  40. package/scss/mixins/_paper.scss +3 -7
  41. package/scss/mixins/_ratio.scss +79 -238
  42. package/scss/mixins/_unit.scss +1 -10
  43. package/scss/mixins/_view.scss +1 -5
  44. package/scss/tags/_index.scss +0 -4
  45. package/scss/tags/_unit.scss +0 -4
  46. package/scss/test.scss +0 -0
  47. package/scss/variables/_color.scss +7 -7
  48. package/scss/variables/_guide.scss +0 -0
  49. package/scss/variables/_index.scss +6 -40
  50. package/scss/variables/_scale.scss +4 -89
  51. package/scss/variables/_unit.scss +2 -5
  52. package/scss/variables/_view.scss +2 -7
  53. package/ts/grids.ts +92 -0
  54. package/ts/index.ts +19 -1
  55. package/scss/classes/_guides.scss +0 -141
  56. package/ts/AspectRatio.ts +0 -50
  57. package/ts/Border.ts +0 -60
  58. package/ts/BoxModel.ts +0 -68
  59. package/ts/FlexContainer.ts +0 -75
  60. package/ts/Grid.ts +0 -46
  61. package/ts/GridContainer.ts +0 -59
  62. package/ts/Layout.ts +0 -64
  63. package/ts/Position.ts +0 -53
  64. package/ts/Rectangle.ts +0 -51
  65. package/ts/ResponsiveImage.ts +0 -47
  66. package/ts/ResponsiveScale.ts +0 -44
  67. package/ts/Size.ts +0 -54
  68. package/ts/Spacing.ts +0 -106
  69. package/ts/Transform.ts +0 -71
  70. package/ts/Typography.ts +0 -75
  71. package/ts/Unit.ts +0 -81
  72. package/ts/Viewport.ts +0 -52
package/ts/Layout.ts DELETED
@@ -1,64 +0,0 @@
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
- // ========================================================================
25
-
26
- width: Unit;
27
- height: Unit;
28
- align: Align;
29
- justify: Justify;
30
- direction: "row" | "column";
31
-
32
- // Constructor
33
- // ========================================================================
34
-
35
- constructor(
36
- width: Unit,
37
- height: Unit,
38
- align: Align = "stretch", justify: Justify = "start", direction: "row" | "column" = "row") {
39
- this.width = width;
40
- this.height = height;
41
- this.align = align;
42
- this.justify = justify;
43
- this.direction = direction;
44
- }
45
-
46
- // Methods
47
- // ========================================================================
48
-
49
- setAlign(align: Align): void {
50
- this.align = align;
51
- }
52
-
53
- setJustify(justify: Justify): void {
54
- this.justify = justify;
55
- }
56
-
57
- setDirection(direction: "row" | "column"): void {
58
- this.direction = direction;
59
- }
60
-
61
- toString(): string {
62
- return `Layout: ${this.direction}, width ${this.width.toString()}, height ${this.height.toString()}, align ${this.align}, justify ${this.justify}`;
63
- }
64
- }
package/ts/Position.ts DELETED
@@ -1,53 +0,0 @@
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
-
17
- x: Unit;
18
- y: Unit;
19
-
20
- // Constructor
21
- // ========================================================================
22
-
23
- constructor(
24
- x: Unit,
25
- y: Unit
26
- ) {
27
- if (x.unit !== y.unit) {
28
- throw new Error("X and Y must have the same unit");
29
- }
30
- this.x = x;
31
- this.y = y;
32
- }
33
-
34
- // Methods
35
- // ========================================================================
36
-
37
- add(other: Position): Position {
38
- return new Position(this.x.add(other.x), this.y.add(other.y));
39
- }
40
-
41
- subtract(other: Position): Position {
42
- return new Position(this.x.subtract(other.x), this.y.subtract(other.y));
43
- }
44
-
45
- convert(toUnit: UnitType): Position {
46
- return new Position(this.x.convert(toUnit), this.y.convert(toUnit));
47
- }
48
-
49
- toString(): string {
50
- return `Position: (${this.x.toString()}, ${this.y.toString()})`;
51
- }
52
-
53
- }
package/ts/Rectangle.ts DELETED
@@ -1,51 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
- import Position from "./Position";
6
- import Size from "./Size";
7
-
8
-
9
- // ============================================================================
10
- // Classes
11
- // ============================================================================
12
-
13
- export default class Rectangle {
14
-
15
- // Parameters
16
- // ========================================================================
17
-
18
- position: Position;
19
- size: Size;
20
-
21
- // Constructor
22
- // ========================================================================
23
-
24
- constructor(position: Position, size: Size) {
25
- if (position.x.unit !== size.width.unit || position.y.unit !== size.height.unit) {
26
- throw new Error("Position and Size units must match");
27
- }
28
- this.position = position;
29
- this.size = size;
30
- }
31
-
32
-
33
- // Methods
34
- // ========================================================================
35
-
36
- move(newPosition: Position): Rectangle {
37
- return new Rectangle(newPosition, this.size);
38
- }
39
-
40
- resize(newSize: Size): Rectangle {
41
- return new Rectangle(this.position, newSize);
42
- }
43
-
44
- scale(factor: number): Rectangle {
45
- return new Rectangle(this.position, this.size.scale(factor));
46
- }
47
-
48
- toString(): string {
49
- return `Rectangle: Position(${this.position.toString()}), Size(${this.size.toString()})`;
50
- }
51
- }
@@ -1,47 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
-
6
- // ============================================================================
7
- // Classes
8
- // ============================================================================
9
-
10
- export default class ResponsiveImage {
11
-
12
- // Parameters
13
- // ========================================================================
14
-
15
- sources: Map<number, string>; // Map of breakpoint to image URL
16
- altText: string;
17
-
18
- // Constructor
19
- // ========================================================================
20
-
21
- constructor(altText: string) {
22
- this.sources = new Map<number, string>();
23
- this.altText = altText;
24
- }
25
-
26
- // Methods
27
- // ========================================================================
28
-
29
- addSource(breakpoint: number, url: string): void {
30
- this.sources.set(breakpoint, url);
31
- }
32
-
33
- getSource(viewportWidth: number): string {
34
- let selectedSource = "";
35
- this.sources.forEach((url, breakpoint) => {
36
- if (viewportWidth >= breakpoint) {
37
- selectedSource = url;
38
- }
39
- });
40
- return selectedSource;
41
- }
42
-
43
- toString(viewportWidth: number): string {
44
- const source = this.getSource(viewportWidth);
45
- return `<img src="${source}" alt="${this.altText}" />`;
46
- }
47
- }
@@ -1,44 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
- import Unit from "./Unit";
6
- import Viewport from "./Viewport";
7
-
8
-
9
- // ============================================================================
10
- // Classes
11
- // ============================================================================
12
-
13
- export default class ResponsiveScale {
14
-
15
- // Parameters
16
- // ========================================================================
17
-
18
- viewport: Viewport;
19
- baseSize: Unit;
20
- scaleFactor: number;
21
-
22
- // Constructor
23
- // ========================================================================
24
-
25
- constructor(viewport: Viewport, baseSize: Unit, scaleFactor: number) {
26
- this.viewport = viewport;
27
- this.baseSize = baseSize;
28
- this.scaleFactor = scaleFactor;
29
- }
30
-
31
-
32
- // Methods
33
- // ========================================================================
34
-
35
- calculateResponsiveSize(): Unit {
36
- const ratio = this.viewport.width.value / 1920; // Assuming 1920px is the base
37
- const scaledValue = this.baseSize.value * Math.pow(this.scaleFactor, ratio);
38
- return new Unit(scaledValue, this.baseSize.unit);
39
- }
40
-
41
- toString(): string {
42
- return `ResponsiveScale: Base(${this.baseSize.toString()}) ScaleFactor(${this.scaleFactor}) Viewport(${this.viewport.toString()})`;
43
- }
44
- }
package/ts/Size.ts DELETED
@@ -1,54 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
- import Unit from "./Unit";
6
-
7
-
8
- // ============================================================================
9
- // Classes
10
- // ============================================================================
11
-
12
- export default class Size {
13
-
14
- // Parameters
15
- // ========================================================================
16
-
17
- width: Unit;
18
- height: Unit;
19
-
20
- // Constructor
21
- // ========================================================================
22
-
23
- constructor(width: Unit, height: Unit) {
24
- if (width.unit !== height.unit) {
25
- throw new Error("Width and height must have the same unit");
26
- }
27
- this.width = width;
28
- this.height = height;
29
- }
30
-
31
- // Methods
32
- // ========================================================================
33
-
34
- add(other: Size): Size {
35
- return new Size(this.width.add(other.width), this.height.add(other.height));
36
- }
37
-
38
- subtract(other: Size): Size {
39
- return new Size(this.width.subtract(other.width), this.height.subtract(other.height));
40
- }
41
-
42
- scale(factor: number): Size {
43
- return new Size(this.width.multiply(factor), this.height.multiply(factor));
44
- }
45
-
46
- convert(toUnit: UnitType): Size {
47
- return new Size(this.width.convert(toUnit), this.height.convert(toUnit));
48
- }
49
-
50
- toString(): string {
51
- return `Size: ${this.width.toString()} x ${this.height.toString()}`;
52
- }
53
-
54
- }
package/ts/Spacing.ts DELETED
@@ -1,106 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
- import { default as Unit, default as UnitType } from "./Unit";
6
-
7
-
8
- // ============================================================================
9
- // Classes
10
- // ============================================================================
11
-
12
- export default class Spacing {
13
-
14
- // Parameters
15
- // ========================================================================
16
-
17
- top: Unit;
18
- right: Unit;
19
- bottom: Unit;
20
- left: Unit;
21
-
22
- // Constructor
23
- // ========================================================================
24
-
25
- constructor(
26
- top: Unit,
27
- right: Unit,
28
- bottom: Unit,
29
- left: Unit
30
- ) {
31
- if (
32
- top.unit !== right.unit || top.unit !== bottom.unit || top.unit !== left.unit
33
- ) {
34
- throw new Error("All sides must have the same unit");
35
- }
36
- this.top = top;
37
- this.right = right;
38
- this.bottom = bottom;
39
- this.left = left;
40
- }
41
-
42
- // Methods
43
- // ========================================================================
44
-
45
- add(other: Spacing): Spacing {
46
- return new Spacing(
47
- this.top.add(other.top),
48
- this.right.add(other.right),
49
- this.bottom.add(other.bottom),
50
- this.left.add(other.left)
51
- );
52
- }
53
-
54
- subtract(other: Spacing): Spacing {
55
- return new Spacing(
56
- this.top.subtract(other.top),
57
- this.right.subtract(other.right),
58
- this.bottom.subtract(other.bottom),
59
- this.left.subtract(other.left)
60
- );
61
- }
62
-
63
- scale(factor: number): Spacing {
64
- return new Spacing(
65
- this.top.multiply(factor),
66
- this.right.multiply(factor),
67
- this.bottom.multiply(factor),
68
- this.left.multiply(factor)
69
- );
70
- }
71
-
72
- convert(toUnit: UnitType): Spacing {
73
- return new Spacing(
74
- this.top.convert(toUnit),
75
- this.right.convert(toUnit),
76
- this.bottom.convert(toUnit),
77
- this.left.convert(toUnit)
78
- );
79
- }
80
-
81
- toString(): string {
82
- return `Spacing: ${this.top.toString()} ${this.right.toString()} ${this.bottom.toString()} ${this.left.toString()}`;
83
- }
84
- }
85
-
86
- class Margin extends Spacing {
87
- constructor(
88
- top: Unit,
89
- right: Unit,
90
- bottom: Unit,
91
- left: Unit,
92
- ) {
93
- super(top, right, bottom, left);
94
- }
95
- }
96
-
97
- class Padding extends Spacing {
98
- constructor(
99
- top: Unit,
100
- right: Unit,
101
- bottom: Unit,
102
- left: Unit,
103
- ) {
104
- super(top, right, bottom, left);
105
- }
106
- }
package/ts/Transform.ts DELETED
@@ -1,71 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
- import Unit from "./Unit";
6
-
7
-
8
- // ============================================================================
9
- // Types
10
- // ============================================================================
11
-
12
- type AngleUnit = "deg" | "rad";
13
-
14
- // ============================================================================
15
- // Classes
16
- // ============================================================================
17
-
18
-
19
- export default class Transform {
20
-
21
- // Parameters
22
- // ========================================================================
23
-
24
- translateX: Unit;
25
- translateY: Unit;
26
- rotate: number;
27
- rotateUnit: AngleUnit;
28
- scaleX: number;
29
- scaleY: number;
30
-
31
- // Constructor
32
- // ========================================================================
33
-
34
- constructor(
35
- translateX: Unit,
36
- translateY: Unit,
37
- rotate: number,
38
- rotateUnit: AngleUnit,
39
- scaleX: number,
40
- scaleY: number
41
- ) {
42
- this.translateX = translateX;
43
- this.translateY = translateY;
44
- this.rotate = rotate;
45
- this.rotateUnit = rotateUnit;
46
- this.scaleX = scaleX;
47
- this.scaleY = scaleY;
48
- }
49
-
50
- // Methods
51
- // ========================================================================
52
-
53
- setTranslation(translateX: Unit, translateY: Unit): void {
54
- this.translateX = translateX;
55
- this.translateY = translateY;
56
- }
57
-
58
- setRotation(angle: number, unit: AngleUnit): void {
59
- this.rotate = angle;
60
- this.rotateUnit = unit;
61
- }
62
-
63
- setScale(scaleX: number, scaleY: number): void {
64
- this.scaleX = scaleX;
65
- this.scaleY = scaleY;
66
- }
67
-
68
- toString(): string {
69
- return `Transform: translate(${this.translateX.toString()}, ${this.translateY.toString()}) rotate(${this.rotate}${this.rotateUnit}) scale(${this.scaleX}, ${this.scaleY})`;
70
- }
71
- }
package/ts/Typography.ts DELETED
@@ -1,75 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
- import Unit from "./Unit";
6
-
7
-
8
- // ============================================================================
9
- // Types
10
- // ============================================================================
11
-
12
- type FontWeight = "normal" | "bold" | number;
13
-
14
-
15
- // ============================================================================
16
- // Classes
17
- // ============================================================================
18
-
19
- export default class Typography {
20
-
21
- // Parameters
22
- // ========================================================================
23
-
24
- fontSize: Unit;
25
- fontWeight: FontWeight;
26
- lineHeight: Unit;
27
- letterSpacing: Unit;
28
- textAlign: "left" | "right" | "center" | "justify";
29
-
30
- // Constructor
31
- // ========================================================================
32
-
33
- constructor(
34
- fontSize: Unit,
35
- fontWeight: FontWeight = "normal",
36
- lineHeight: Unit,
37
- letterSpacing: Unit,
38
- textAlign: "left" | "right" | "center" | "justify" = "left"
39
- ) {
40
- this.fontSize = fontSize;
41
- this.fontWeight = fontWeight;
42
- this.lineHeight = lineHeight;
43
- this.letterSpacing = letterSpacing;
44
- this.textAlign = textAlign;
45
- }
46
-
47
-
48
- // Methods
49
- // ========================================================================
50
-
51
- setFontSize(fontSize: Unit): void {
52
- this.fontSize = fontSize;
53
- }
54
-
55
- setFontWeight(fontWeight: FontWeight): void {
56
- this.fontWeight = fontWeight;
57
- }
58
-
59
- setLineHeight(lineHeight: Unit): void {
60
- this.lineHeight = lineHeight;
61
- }
62
-
63
- setLetterSpacing(letterSpacing: Unit): void {
64
- this.letterSpacing = letterSpacing;
65
- }
66
-
67
- setTextAlign(textAlign: "left" | "right" | "center" | "justify"): void {
68
- this.textAlign = textAlign;
69
- }
70
-
71
- toString(): string {
72
- return `Typography: font-size ${this.fontSize.toString()}, weight ${this.fontWeight}, line-height ${this.lineHeight.toString()}, letter-spacing ${this.letterSpacing.toString()}, text-align ${this.textAlign}`;
73
- }
74
-
75
- }
package/ts/Unit.ts DELETED
@@ -1,81 +0,0 @@
1
- // ============================================================================
2
- // Import
3
- // ============================================================================
4
-
5
-
6
- // ============================================================================
7
- // Types
8
- // ============================================================================
9
-
10
- type UnitType = "px" | "em" | "%" | "rem" | "mm" | "cm" | "in";
11
-
12
-
13
- // ============================================================================
14
- // Classes
15
- // ============================================================================
16
-
17
- export default class Unit {
18
-
19
- // Parameters
20
- // ========================================================================
21
-
22
- value: number;
23
- unit: UnitType;
24
-
25
- // Constructor
26
- // ========================================================================
27
-
28
- constructor(value: number, unit: UnitType) {
29
- this.value = value;
30
- this.unit = unit;
31
- }
32
-
33
- // Methods
34
- // ========================================================================
35
-
36
- add(other: Unit): Unit {
37
- if (this.unit !== other.unit) {
38
- throw new Error(`Cannot add units of different types: ${this.unit} and ${other.unit}`);
39
- }
40
- return new Unit(this.value + other.value, this.unit);
41
- }
42
-
43
- subtract(other: Unit): Unit {
44
- if (this.unit !== other.unit) {
45
- throw new Error(`Cannot subtract units of different types: ${this.unit} and ${other.unit}`);
46
- }
47
- return new Unit(this.value - other.value, this.unit);
48
- }
49
-
50
- multiply(factor: number): Unit {
51
- return new Unit(this.value * factor, this.unit);
52
- }
53
-
54
- divide(divisor: number): Unit {
55
- return new Unit(this.value / divisor, this.unit);
56
- }
57
-
58
- convert(toUnit: UnitType): Unit {
59
- // Example conversion: assumes 1in = 96px, 1cm = 37.7953px, etc.
60
- const conversionRates: { [key in UnitType]?: number } = {
61
- "px": 1,
62
- "em": 16,
63
- "rem": 16,
64
- "in": 96,
65
- "cm": 37.7953,
66
- "mm": 3.77953,
67
- "%": 1 // Conversion for percentages might be contextual
68
- };
69
-
70
- if (!conversionRates[this.unit] || !conversionRates[toUnit]) {
71
- throw new Error(`Conversion from ${this.unit} to ${toUnit} is not supported`);
72
- }
73
-
74
- const convertedValue = (this.value * conversionRates[this.unit]!) / conversionRates[toUnit]!;
75
- return new Unit(convertedValue, toUnit);
76
- }
77
-
78
- toString(): string {
79
- return `${this.value}${this.unit}`;
80
- }
81
- }