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
@@ -1,7 +1,3 @@
1
- // ============================================================================
2
- // Poster
3
- // ============================================================================
4
-
5
1
  ////
6
2
  ///
7
3
  /// View Variables Module
@@ -71,8 +67,6 @@ $base_screen_unit: 16px !default;
71
67
  /// @type Map
72
68
  ///
73
69
 
74
-
75
-
76
70
  // $breakpoints: (
77
71
  // xs: calc_breakpoint($base_screen_unit, 20), // 320px - Extra small devices (Mobile)
78
72
  // sm: calc_breakpoint($base_screen_unit, 30), // 480px - Small devices (Tablets)
@@ -93,7 +87,8 @@ $breakpoints: (
93
87
  // 1024px - Large devices (Desktops)
94
88
  xl: 1280px,
95
89
  // 1280px - Extra large devices (TV)
96
- sl: 1440px, // 1440px - Super large devices (Large TV)
90
+ sl: 1440px,
91
+ // 1440px - Super large devices (Large TV)
97
92
  ) !default;
98
93
 
99
94
  ///
package/ts/grids.ts ADDED
@@ -0,0 +1,92 @@
1
+ type GridLayer = HTMLElement & { dataset: { grid: string } };
2
+ type ToggleButton = HTMLButtonElement & { dataset: { toggle: string } };
3
+ const STORAGE_KEY = 'unitgl:grid:visibility';
4
+
5
+ /**
6
+ * Load visibility map from localStorage.
7
+ */
8
+ function loadVisibility(): Record<string, boolean> {
9
+ try {
10
+ return JSON.parse(localStorage.getItem(STORAGE_KEY) || '{}');
11
+ } catch {
12
+ return {};
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Save updated visibility map to localStorage.
18
+ */
19
+ function saveVisibility(visibilityMap: Record<string, boolean>): void {
20
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(visibilityMap));
21
+ }
22
+
23
+ /**
24
+ * Update height of all grid overlays to match document scroll height.
25
+ */
26
+ function updateAllGridHeights(): void {
27
+ const height = Math.max(
28
+ document.body.scrollHeight,
29
+ document.documentElement.scrollHeight
30
+ );
31
+
32
+ document.querySelectorAll<HTMLElement>('.grid_layer').forEach(layer => {
33
+ // Avoid recursive layout inflation
34
+ if (layer.offsetHeight !== height) {
35
+ layer.style.height = `${height}px`;
36
+ }
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Update the indicator badge on a toggle button.
42
+ */
43
+ function updateStatusIndicator(id: string, isHidden: boolean): void {
44
+ const badge = document.querySelector<HTMLSpanElement>(`[data-status="${id}"]`);
45
+ if (badge) {
46
+ badge.textContent = isHidden ? '✕ Off' : '✓ On';
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Apply saved visibility state to grid layers and badges.
52
+ */
53
+ function applyVisibilityState(state: Record<string, boolean>): void {
54
+ document.querySelectorAll<GridLayer>('.grid_layer').forEach(layer => {
55
+ const id = layer.dataset.grid;
56
+ const hidden = !!state[id];
57
+ layer.classList.toggle('is-hidden', hidden);
58
+ updateStatusIndicator(id, hidden);
59
+ });
60
+ }
61
+
62
+ /**
63
+ * Hook up buttons to toggle grid visibility and update state.
64
+ */
65
+ function setupGridToggles(): void {
66
+ const visibility = loadVisibility();
67
+
68
+ const buttons = document.querySelectorAll<ToggleButton>('button[data-toggle]');
69
+ buttons.forEach(button => {
70
+ const id = button.dataset.toggle;
71
+ const layer = document.querySelector<GridLayer>(`[data-grid="${id}"]`);
72
+ if (!layer) return;
73
+
74
+ button.addEventListener('click', () => {
75
+ const isNowHidden = layer.classList.toggle('is-hidden');
76
+ visibility[id] = isNowHidden;
77
+ saveVisibility(visibility);
78
+ updateStatusIndicator(id, isNowHidden);
79
+ });
80
+ });
81
+
82
+ applyVisibilityState(visibility);
83
+ }
84
+
85
+ // Initialize on DOM ready
86
+ document.addEventListener('DOMContentLoaded', () => {
87
+ updateAllGridHeights();
88
+ setupGridToggles();
89
+
90
+ window.addEventListener('resize', updateAllGridHeights);
91
+ window.addEventListener('scroll', updateAllGridHeights);
92
+ });
package/ts/index.ts CHANGED
@@ -1 +1,19 @@
1
- export { };
1
+ import './grids.js';
2
+
3
+ // Additional imports could go here:
4
+ // import './typography';
5
+ // import './debug';
6
+ // import './viewport-tools';
7
+
8
+ document.addEventListener('DOMContentLoaded', () => {
9
+ console.log('[unit.gl] Test site initialized');
10
+
11
+ // Example: highlight current test page in nav
12
+ const current = location.pathname.split('/').pop();
13
+ const activeLink = document.querySelector(`a[href$="${current}"]`);
14
+ if (activeLink) {
15
+ activeLink.classList.add('active');
16
+ }
17
+
18
+ // Additional test tools or instrumentation could be bootstrapped here
19
+ });
@@ -1,141 +0,0 @@
1
- @use "../dev" as *;
2
- @use "../variables" as *;
3
- @use "../mixins" as *;
4
-
5
- // ============================================================================
6
- // Utilities | Guides
7
- // ============================================================================
8
-
9
- .guide {
10
- @include guide;
11
- }
12
-
13
- @mixin guide_graph {
14
- @include guide;
15
- background-size: 4 * $q 4 * $q;
16
- background-image: repeating-linear-gradient(
17
- rgb(66, 61, 61) 0 1px,
18
- transparent 1px 100%
19
- ),
20
- repeating-linear-gradient(
21
- 90deg,
22
- rgb(66, 61, 61) 0 1px,
23
- transparent 1px 100%
24
- );
25
- }
26
-
27
- .guide_graph {
28
- @include guide_graph;
29
- }
30
-
31
- @mixin guide_baseline {
32
- @include guide;
33
- // background: repeating-linear-gradient(#e66465, #e66465 20px, #9198e5 20px, #9198e5 25px);
34
- // background: repeating-linear-gradient(transparent, transparent 20px, transparent 20px, transparent 25px);
35
- // background-repeat: repeat-y;
36
- background-repeat: repeat;
37
-
38
- background-size: map-get($baseline, 4) map-get($baseline, 4);
39
- @include guide;
40
- background-image: repeating-linear-gradient(
41
- cyan 0 1px,
42
- transparent 1px 100%
43
- );
44
- }
45
-
46
- .guide_baseline {
47
- @include guide_baseline;
48
- }
49
-
50
- .baseline-grid {
51
- @include guide;
52
-
53
- background-image:
54
- // -webkit-linear-gradient(0deg, rgba(200,0,0,.2) 40px, transparent 40px),
55
- -webkit-linear-gradient(
56
- top,
57
- rgba(0, 0, 0, 0) 95%,
58
- rgba(56, 255, 255, 0.8) 100%
59
- );
60
-
61
- background-image:
62
- // -moz-linear-gradient(0deg, rgba(200,0,0,.2) 40px, transparent 40px),
63
- -moz-linear-gradient(
64
- top,
65
- rgba(0, 0, 0, 0) 95%,
66
- rgba(56, 255, 255, 0.8) 100%
67
- );
68
- background-image:
69
- // -o-linear-gradient(0deg, rgba(200,0,0,.2) 40px, transparent 40px),
70
- -o-linear-gradient(
71
- top,
72
- rgba(0, 0, 0, 0) 95%,
73
- rgba(56, 255, 255, 0.8) 100%
74
- );
75
-
76
- background-size:
77
- 100% 100%,
78
- 100% 100%;
79
- // background-size: 60px 100%, 100% 22px;
80
- // background-position: 10px 0px;
81
- }
82
-
83
- // .guide_graph {
84
- // @include guide;
85
- // background-image:
86
- // repeating-linear-gradient(#ccc 0 1px, transparent 1px 100%),
87
- // repeating-linear-gradient(90deg, #ccc 0 1px, transparent 1px 100%);
88
- // }
89
-
90
- // .guide_baseline {
91
- // @include guide;
92
- // background-image:
93
- // repeating-linear-gradient(cyan 0 2px, transparent 2px 100%);
94
- // }
95
-
96
- .page {
97
- border: $q * 2 solid red;
98
- }
99
-
100
- $body-width: 960px;
101
- $baseline: 22px;
102
- @mixin baseline-grid {
103
- $columns: 16;
104
- $column-color: rgba(200, 0, 0, 0.2);
105
- $baseline-color: rgba(56, 255, 255, 0.8);
106
-
107
- // These are all automatically calculated
108
- $gutter-width: 20px; // Change if you like
109
- $gutters: ($columns - 1);
110
- $column-width: calc($body-width / $columns);
111
-
112
- background-image:
113
- -webkit-linear-gradient(
114
- 0deg,
115
- $column-color $column-width,
116
- transparent $gutter-width
117
- ),
118
- -webkit-linear-gradient(top, rgba(0, 0, 0, 0) 95%, $baseline-color 100%);
119
- background-image:
120
- -moz-linear-gradient(
121
- 0deg,
122
- $column-color $column-width,
123
- transparent $gutter-width
124
- ),
125
- -moz-linear-gradient(top, rgba(0, 0, 0, 0) 95%, $baseline-color 100%);
126
- background-image:
127
- -o-linear-gradient(
128
- 0deg,
129
- $column-color $column-width,
130
- transparent $gutter-width
131
- ),
132
- -o-linear-gradient(top, rgba(0, 0, 0, 0) 95%, $baseline-color 100%);
133
- background-size:
134
- ($column-width + $gutter-width) 100%,
135
- 100% $baseline;
136
- background-position: 10px 0px; // Use to offset and center your grid
137
- }
138
-
139
- // Example call
140
- .baseline-grid {
141
- }
package/ts/AspectRatio.ts DELETED
@@ -1,50 +0,0 @@
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
-
17
- width: Unit;
18
- height: Unit;
19
-
20
- // Constructor
21
- // ========================================================================
22
-
23
- constructor(width: Unit, height: Unit) {
24
- this.width = width;
25
- this.height = height;
26
- }
27
-
28
- // Methods
29
- // ========================================================================
30
-
31
- calculateRatio(): number {
32
- return this.width.value / this.height.value;
33
- }
34
-
35
- scaleToWidth(newWidth: Unit): Unit {
36
- const ratio: number = this.calculateRatio();
37
- const newHeightValue: number = newWidth.value / ratio;
38
- return new Unit(newHeightValue, newWidth.unit);
39
- }
40
-
41
- scaleToHeight(newHeight: Unit): Unit {
42
- const ratio: number = this.calculateRatio();
43
- const newWidthValue: number = newHeight.value * ratio;
44
- return new Unit(newWidthValue, newHeight.unit);
45
- }
46
-
47
- toString(): string {
48
- return `AspectRatio: width ${this.width.toString()}, height ${this.height.toString()}, ratio ${this.calculateRatio()}`;
49
- }
50
- }
package/ts/Border.ts DELETED
@@ -1,60 +0,0 @@
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
- // ========================================================================
22
-
23
- width: Unit;
24
- style: BorderStyle;
25
- color: string;
26
-
27
-
28
- // Constructor
29
- // ========================================================================
30
-
31
- constructor(
32
- width: Unit,
33
- style: BorderStyle,
34
- color: string
35
- ) {
36
- this.width = width;
37
- this.style = style;
38
- this.color = color;
39
- }
40
-
41
- // Methods
42
- // ========================================================================
43
-
44
- setWidth(newWidth: Unit): void {
45
- this.width = newWidth;
46
- }
47
-
48
- setStyle(newStyle: BorderStyle): void {
49
- this.style = newStyle;
50
- }
51
-
52
- setColor(newColor: string): void {
53
- this.color = newColor;
54
- }
55
-
56
- toString(): string {
57
- return `Border: ${this.width.toString()} ${this.style} ${this.color}`;
58
- }
59
-
60
- }
package/ts/BoxModel.ts DELETED
@@ -1,68 +0,0 @@
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
-
18
- margin: Margin;
19
- padding: Padding;
20
- border: Border;
21
- size: Size;
22
-
23
- // Constructor
24
- // ========================================================================
25
-
26
- constructor(
27
- margin: Margin,
28
- padding: Padding,
29
- border: Border,
30
- size: Size
31
- ) {
32
- if (
33
- margin.top.unit !== size.width.unit ||
34
- padding.top.unit !== size.width.unit ||
35
- border.width.unit !== size.width.unit
36
- ) {
37
- throw new Error("All units in BoxModel must match");
38
- }
39
- this.margin = margin;
40
- this.padding = padding;
41
- this.border = border;
42
- this.size = size;
43
- }
44
-
45
-
46
- // Methods
47
- // ========================================================================
48
-
49
- setMargin(margin: Margin): void {
50
- this.margin = margin;
51
- }
52
-
53
- setPadding(padding: Padding): void {
54
- this.padding = padding;
55
- }
56
-
57
- setBorder(border: Border): void {
58
- this.border = border;
59
- }
60
-
61
- setSize(size: Size): void {
62
- this.size = size;
63
- }
64
-
65
- toString(): string {
66
- return `BoxModel:\n Size: ${this.size.toString()}\n Margin: ${this.margin.toString()}\n Padding: ${this.padding.toString()}\n Border: ${this.border.toString()}`;
67
- }
68
- }
@@ -1,75 +0,0 @@
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
- // ========================================================================
23
-
24
- flexDirection: FlexDirection;
25
- flexWrap: FlexWrap;
26
- justifyContent: Justify;
27
- alignItems: Align;
28
- alignContent: Align;
29
-
30
-
31
- // Constructor
32
- // ========================================================================
33
-
34
- constructor(
35
- flexDirection: FlexDirection = "row",
36
- flexWrap: FlexWrap = "nowrap",
37
- justifyContent: Justify = "start",
38
- alignItems: Align = "stretch",
39
- alignContent: Align = "stretch"
40
- ) {
41
- this.flexDirection = flexDirection;
42
- this.flexWrap = flexWrap;
43
- this.justifyContent = justifyContent;
44
- this.alignItems = alignItems;
45
- this.alignContent = alignContent;
46
- }
47
-
48
-
49
- // Methods
50
- // ========================================================================
51
-
52
- setDirection(direction: FlexDirection): void {
53
- this.flexDirection = direction;
54
- }
55
-
56
- setWrap(wrap: FlexWrap): void {
57
- this.flexWrap = wrap;
58
- }
59
-
60
- setJustifyContent(justify: Justify): void {
61
- this.justifyContent = justify;
62
- }
63
-
64
- setAlignItems(align: Align): void {
65
- this.alignItems = align;
66
- }
67
-
68
- setAlignContent(align: Align): void {
69
- this.alignContent = align;
70
- }
71
-
72
- toString(): string {
73
- return `FlexContainer: direction ${this.flexDirection}, wrap ${this.flexWrap}, justify ${this.justifyContent}, align-items ${this.alignItems}, align-content ${this.alignContent}`;
74
- }
75
- }
package/ts/Grid.ts DELETED
@@ -1,46 +0,0 @@
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
-
17
- columns: number;
18
- gutter: Unit;
19
- rowHeight: Unit;
20
-
21
- // Constructor
22
- // ========================================================================
23
-
24
- constructor(
25
- columns: number,
26
- gutter: Unit,
27
- rowHeight: Unit
28
- ) {
29
- this.columns = columns;
30
- this.gutter = gutter;
31
- this.rowHeight = rowHeight;
32
- }
33
-
34
- // Methods
35
- // ========================================================================
36
-
37
- getColumnWidth(containerWidth: Unit): Unit {
38
- const totalGutterWidth = this.gutter.value * (this.columns - 1);
39
- const columnWidth = (containerWidth.value - totalGutterWidth) / this.columns;
40
- return new Unit(columnWidth, containerWidth.unit);
41
- }
42
-
43
- toString(): string {
44
- return `Grid: ${this.columns} columns, gutter ${this.gutter.toString()}, row height ${this.rowHeight.toString()}`;
45
- }
46
- }
@@ -1,59 +0,0 @@
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
-
17
- rows: number;
18
- columns: number;
19
- rowGap: Unit;
20
- columnGap: Unit;
21
-
22
- // Constructor
23
- // ========================================================================
24
-
25
- constructor(
26
- rows: number,
27
- columns: number,
28
- rowGap: Unit,
29
- columnGap: Unit
30
- ) {
31
- this.rows = rows;
32
- this.columns = columns;
33
- this.rowGap = rowGap;
34
- this.columnGap = columnGap;
35
- }
36
-
37
- // Methods
38
- // ========================================================================
39
-
40
- setRows(rows: number): void {
41
- this.rows = rows;
42
- }
43
-
44
- setColumns(columns: number): void {
45
- this.columns = columns;
46
- }
47
-
48
- setRowGap(rowGap: Unit): void {
49
- this.rowGap = rowGap;
50
- }
51
-
52
- setColumnGap(columnGap: Unit): void {
53
- this.columnGap = columnGap;
54
- }
55
-
56
- toString(): string {
57
- return `GridContainer: ${this.rows} rows, ${this.columns} columns, row-gap ${this.rowGap.toString()}, column-gap ${this.columnGap.toString()}`;
58
- }
59
- }