unit.gl 0.2.3 → 0.3.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 +329 -1
- package/css/unit.gl.css +35819 -6
- package/css/unit.gl.docs.css +4156 -0
- package/css/unit.gl.docs.min.css +2 -0
- package/css/unit.gl.min.css +1 -1
- package/js/unit.gl.demo.js +708 -0
- package/js/unit.gl.demo.js.map +1 -0
- package/js/unit.gl.js +25 -0
- package/js/unit.gl.js.map +1 -1
- package/package.json +16 -3
- package/scss/classes/_docs.scss +4690 -0
- package/scss/classes/_index.scss +1 -0
- package/scss/classes/_utilities.scss +1488 -0
- package/scss/docs.scss +11 -0
- package/scss/formats.scss +27 -0
- package/scss/functions/_density.scss +311 -0
- package/scss/functions/_index.scss +3 -0
- package/scss/functions/_scale.scss +211 -1
- package/scss/guide.scss +22 -0
- package/scss/maps/_density.scss +141 -0
- package/scss/maps/_device.scss +13 -20
- package/scss/maps/_index.scss +6 -0
- package/scss/maps/_scale.scss +47 -4
- package/scss/mixins/_device.scss +1 -3
- package/scss/mixins/_display.scss +256 -0
- package/scss/mixins/_format.scss +75 -0
- package/scss/mixins/_index.scss +2 -1
- package/scss/mixins/_unit.scss +115 -6
- package/scss/mixins/_utilities.scss +303 -0
- package/scss/mixins/_view.scss +41 -11
- package/scss/tags/_global.scss +0 -3
- package/scss/tags/_unit.scss +1 -3
- package/scss/utilities.scss +20 -0
- package/scss/variables/_format.scss +80 -0
- package/scss/variables/_index.scss +4 -0
- package/scss/variables/_scale.scss +434 -63
- package/scss/variables/_view.scss +222 -64
- package/ts/demo.ts +889 -0
- package/ts/index.d.ts +72 -0
- package/ts/index.ts +45 -0
- package/scss/mixins/_paper.scss +0 -52
|
@@ -3,96 +3,254 @@
|
|
|
3
3
|
/// View Variables Module
|
|
4
4
|
/// ===========================================================================
|
|
5
5
|
///
|
|
6
|
-
/// This module defines
|
|
7
|
-
///
|
|
8
|
-
///
|
|
9
|
-
///
|
|
10
|
-
/// Breakpoint
|
|
11
|
-
///
|
|
12
|
-
///
|
|
13
|
-
///
|
|
14
|
-
///
|
|
15
|
-
///
|
|
16
|
-
///
|
|
17
|
-
///
|
|
18
|
-
///
|
|
19
|
-
///
|
|
20
|
-
///
|
|
21
|
-
///
|
|
22
|
-
///
|
|
23
|
-
///
|
|
24
|
-
///
|
|
25
|
-
///
|
|
6
|
+
/// This module defines breakpoints for responsive design, derived from the
|
|
7
|
+
/// Q format paper sizes. The system creates a unified physical-to-digital
|
|
8
|
+
/// mapping using a base multiplier of 4 (1mm = 4px at standard 96dpi/1× density).
|
|
9
|
+
///
|
|
10
|
+
/// Q Format to Breakpoint Mapping:
|
|
11
|
+
/// ───────────────────────────────────────────────────────────────────────────
|
|
12
|
+
/// | Breakpoint | Format | Orientation | Width (mm) | ×4 = px | Device |
|
|
13
|
+
/// |------------|--------|-------------|------------|---------|---------------|
|
|
14
|
+
/// | us | Q07 | Portrait | 60mm | 240px | Compact/Fold |
|
|
15
|
+
/// | ss | Q06 | Portrait | 90mm | 360px | Phones |
|
|
16
|
+
/// | xs | Q05 | Portrait | 135mm | 540px | Large phones |
|
|
17
|
+
/// | sm | Q04 | Portrait | 180mm | 720px | Tablets |
|
|
18
|
+
/// | md | Q03 | Landscape | 360mm | 1440px | Laptops |
|
|
19
|
+
/// | lg | Q02 | Landscape | 540mm | 2160px | QHD/Ultrawide |
|
|
20
|
+
/// | xl | Q01 | Landscape | 720mm | 2880px | 4K displays |
|
|
21
|
+
/// | ul | Q00 | Landscape | 1080mm | 4320px | 5K+ displays |
|
|
22
|
+
/// ───────────────────────────────────────────────────────────────────────────
|
|
23
|
+
///
|
|
24
|
+
/// Density Integration:
|
|
25
|
+
/// - Base multiplier: 4 (1mm = 4px at 1× DPR / 96dpi)
|
|
26
|
+
/// - At 2× DPR: 1mm = 8 physical pixels (but same CSS pixels)
|
|
27
|
+
/// - At 3× DPR: 1mm = 12 physical pixels (but same CSS pixels)
|
|
28
|
+
///
|
|
29
|
+
/// Small formats (Q06-Q04) use portrait width → mobile/tablet devices
|
|
30
|
+
/// Large formats (Q03-Q00) use landscape width → desktop devices
|
|
26
31
|
///
|
|
27
32
|
/// @group View
|
|
28
33
|
/// @author Scape Agency
|
|
29
34
|
/// @link https://unit.gl
|
|
30
35
|
/// @since 0.1.0 initial release
|
|
31
|
-
/// @todo None
|
|
32
36
|
/// @access public
|
|
33
37
|
///
|
|
34
38
|
////
|
|
35
39
|
|
|
36
|
-
|
|
37
40
|
// ============================================================================
|
|
38
41
|
// Use
|
|
39
42
|
// ============================================================================
|
|
40
43
|
|
|
41
44
|
@use "sass:map";
|
|
42
|
-
|
|
45
|
+
@use "sass:math";
|
|
43
46
|
|
|
44
47
|
// ============================================================================
|
|
45
|
-
//
|
|
48
|
+
// Physical-to-Digital Conversion
|
|
46
49
|
// ============================================================================
|
|
47
50
|
|
|
48
51
|
///
|
|
49
|
-
/// Base
|
|
52
|
+
/// Base multiplier for converting millimeters to CSS pixels.
|
|
53
|
+
/// At standard density (1× DPR / 96dpi), 1mm ≈ 4px.
|
|
54
|
+
/// This creates a clean bridge between physical Q formats and digital breakpoints.
|
|
50
55
|
///
|
|
51
|
-
/// @name $
|
|
52
|
-
/// @type
|
|
56
|
+
/// @name $mm_to_px_multiplier
|
|
57
|
+
/// @type Number
|
|
53
58
|
///
|
|
54
|
-
$
|
|
59
|
+
$mm_to_px_multiplier: 4 !default;
|
|
55
60
|
|
|
56
61
|
///
|
|
57
|
-
///
|
|
58
|
-
///
|
|
59
|
-
/// screen unit.
|
|
62
|
+
/// Reference DPI for the base multiplier calculation.
|
|
63
|
+
/// Standard screen density is 96dpi.
|
|
60
64
|
///
|
|
61
|
-
///
|
|
62
|
-
///
|
|
63
|
-
/// - **md**: 768px (Medium devices like laptops)
|
|
64
|
-
/// - **lg**: 1024px (Large devices like desktops)
|
|
65
|
-
/// - **xl**: 1280px (Extra large devices like TVs)
|
|
66
|
-
/// - **sl**: 1440px (Super large devices like large TVs)
|
|
65
|
+
/// @name $reference_dpi
|
|
66
|
+
/// @type Number
|
|
67
67
|
///
|
|
68
|
-
|
|
68
|
+
$reference_dpi: 96 !default;
|
|
69
|
+
|
|
70
|
+
///
|
|
71
|
+
/// Convert millimeters to CSS pixels using the base multiplier.
|
|
72
|
+
/// Density-aware: multiply result by DPR for physical pixels.
|
|
73
|
+
///
|
|
74
|
+
/// @name mm_to_px
|
|
75
|
+
/// @param {Number} $mm - Value in millimeters
|
|
76
|
+
/// @param {Number} $multiplier [$mm_to_px_multiplier] - Conversion multiplier
|
|
77
|
+
/// @return {Length} Value in pixels
|
|
78
|
+
///
|
|
79
|
+
/// @example scss - Usage
|
|
80
|
+
/// width: mm_to_px(90); // 360px (Q06 portrait)
|
|
81
|
+
/// width: mm_to_px(360); // 1440px (Q03 landscape)
|
|
82
|
+
///
|
|
83
|
+
@function mm_to_px($mm, $multiplier: $mm_to_px_multiplier) {
|
|
84
|
+
@return $mm * $multiplier * 1px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
///
|
|
88
|
+
/// Convert CSS pixels to millimeters using the base multiplier.
|
|
89
|
+
///
|
|
90
|
+
/// @name px_to_mm
|
|
91
|
+
/// @param {Length} $px - Value in pixels
|
|
92
|
+
/// @param {Number} $multiplier [$mm_to_px_multiplier] - Conversion multiplier
|
|
93
|
+
/// @return {Number} Value in millimeters
|
|
94
|
+
///
|
|
95
|
+
@function px_to_mm($px, $multiplier: $mm_to_px_multiplier) {
|
|
96
|
+
@return math.div($px, $multiplier * 1px);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ============================================================================
|
|
100
|
+
// Q Format Dimensions (in mm)
|
|
101
|
+
// ============================================================================
|
|
102
|
+
|
|
103
|
+
///
|
|
104
|
+
/// Q format paper sizes used as the basis for breakpoints.
|
|
105
|
+
/// Portrait orientation for mobile devices, landscape for desktop.
|
|
106
|
+
///
|
|
107
|
+
/// @name $q_formats
|
|
69
108
|
/// @type Map
|
|
70
109
|
///
|
|
110
|
+
$q_formats: (
|
|
111
|
+
q00: (
|
|
112
|
+
width: 720mm,
|
|
113
|
+
height: 1080mm
|
|
114
|
+
),
|
|
115
|
+
// Largest format
|
|
116
|
+
q01: (
|
|
117
|
+
width: 540mm,
|
|
118
|
+
height: 720mm
|
|
119
|
+
),
|
|
120
|
+
q02: (
|
|
121
|
+
width: 360mm,
|
|
122
|
+
height: 540mm
|
|
123
|
+
),
|
|
124
|
+
q03: (
|
|
125
|
+
width: 270mm,
|
|
126
|
+
height: 360mm
|
|
127
|
+
),
|
|
128
|
+
q04: (
|
|
129
|
+
width: 180mm,
|
|
130
|
+
height: 270mm
|
|
131
|
+
),
|
|
132
|
+
q05: (
|
|
133
|
+
width: 135mm,
|
|
134
|
+
height: 180mm
|
|
135
|
+
),
|
|
136
|
+
q06: (
|
|
137
|
+
width: 90mm,
|
|
138
|
+
height: 135mm
|
|
139
|
+
),
|
|
140
|
+
q07: (
|
|
141
|
+
width: 60mm,
|
|
142
|
+
height: 90mm
|
|
143
|
+
) // Ultrasmall format
|
|
144
|
+
) !default;
|
|
71
145
|
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
// md: calc_breakpoint($base_screen_unit, 48), // 768px - Medium devices (Laptops)
|
|
76
|
-
// lg: calc_breakpoint($base_screen_unit, 64), // 1024px - Large devices (Desktops)
|
|
77
|
-
// xl: calc_breakpoint($base_screen_unit, 80), // 1280px - Extra large devices (TV)
|
|
78
|
-
// sl: calc_breakpoint($base_screen_unit, 90), // 1440px - Super large devices (Large TV)
|
|
79
|
-
// ) !default;
|
|
146
|
+
// ============================================================================
|
|
147
|
+
// Breakpoint Definitions (derived from Q formats)
|
|
148
|
+
// ============================================================================
|
|
80
149
|
|
|
150
|
+
///
|
|
151
|
+
/// Breakpoints derived from Q format dimensions.
|
|
152
|
+
/// Small devices use portrait width, large devices use landscape width.
|
|
153
|
+
/// The 4× multiplier (1mm = 4px) bridges physical and digital.
|
|
154
|
+
///
|
|
155
|
+
/// @name $breakpoints
|
|
156
|
+
/// @type Map
|
|
157
|
+
///
|
|
81
158
|
$breakpoints: (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
//
|
|
159
|
+
// Portrait Q formats → Mobile/Tablet devices (held vertically)
|
|
160
|
+
us: mm_to_px(60),
|
|
161
|
+
// Q07 Portrait width → 240px - Compact/Fold phones
|
|
162
|
+
ss: mm_to_px(90),
|
|
163
|
+
// Q06 Portrait width → 360px - Phones
|
|
164
|
+
xs: mm_to_px(135),
|
|
165
|
+
// Q05 Portrait width → 540px - Large phones/Small tablets
|
|
166
|
+
sm: mm_to_px(180),
|
|
167
|
+
// Q04 Portrait width → 720px - Tablets/Small laptops
|
|
168
|
+
// Landscape Q formats → Desktop devices (horizontal displays)
|
|
169
|
+
md: mm_to_px(360),
|
|
170
|
+
// Q03 Landscape width → 1440px - Laptops/Desktops
|
|
171
|
+
lg: mm_to_px(540),
|
|
172
|
+
// Q02 Landscape width → 2160px - Ultrawide/QHD
|
|
173
|
+
xl: mm_to_px(720),
|
|
174
|
+
// Q01 Landscape width → 2880px - 4K displays
|
|
175
|
+
ul: mm_to_px(1080) // Q00 Landscape width → 4320px - 5K+ displays (ultralarge)
|
|
176
|
+
) !default;
|
|
177
|
+
|
|
178
|
+
///
|
|
179
|
+
/// Mapping between Q formats and breakpoints.
|
|
180
|
+
/// P = Portrait (mobile), L = Landscape (desktop)
|
|
181
|
+
///
|
|
182
|
+
/// @name $format_breakpoint_map
|
|
183
|
+
/// @type Map
|
|
184
|
+
///
|
|
185
|
+
$format_breakpoint_map: (
|
|
186
|
+
q07p: us,
|
|
187
|
+
// Q07 Portrait → us (240px)
|
|
188
|
+
q06p: ss,
|
|
189
|
+
// Q06 Portrait → ss (360px)
|
|
190
|
+
q05p: xs,
|
|
191
|
+
// Q05 Portrait → xs (540px)
|
|
192
|
+
q04p: sm,
|
|
193
|
+
// Q04 Portrait → sm (720px)
|
|
194
|
+
q03l: md,
|
|
195
|
+
// Q03 Landscape → md (1440px)
|
|
196
|
+
q02l: lg,
|
|
197
|
+
// Q02 Landscape → lg (2160px)
|
|
198
|
+
q01l: xl,
|
|
199
|
+
// Q01 Landscape → xl (2880px)
|
|
200
|
+
q00l: ul // Q00 Landscape → ul (4320px)
|
|
94
201
|
) !default;
|
|
95
202
|
|
|
203
|
+
///
|
|
204
|
+
/// Get the breakpoint name for a Q format.
|
|
205
|
+
///
|
|
206
|
+
/// @name format_to_breakpoint
|
|
207
|
+
/// @param {String} $format - Format name (e.g., "q07p", "q06p", "q03l")
|
|
208
|
+
/// @return {String} Breakpoint name (us, ss, xs, sm, md, lg, xl, ul)
|
|
209
|
+
///
|
|
210
|
+
@function format_to_breakpoint($format) {
|
|
211
|
+
@if map.has-key($format_breakpoint_map, $format) {
|
|
212
|
+
@return map.get($format_breakpoint_map, $format);
|
|
213
|
+
}
|
|
214
|
+
@warn "Unknown format: #{$format}. Returning null.";
|
|
215
|
+
@return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
///
|
|
219
|
+
/// Get breakpoint value adjusted for a target DPR.
|
|
220
|
+
/// Useful for understanding physical pixel requirements.
|
|
221
|
+
///
|
|
222
|
+
/// @name breakpoint_for_density
|
|
223
|
+
/// @param {String} $breakpoint - Breakpoint name
|
|
224
|
+
/// @param {Number} $target_dpr [1] - Target device pixel ratio
|
|
225
|
+
/// @return {Length} Breakpoint value in CSS pixels
|
|
226
|
+
///
|
|
227
|
+
@function breakpoint_for_density($breakpoint, $target_dpr: 1) {
|
|
228
|
+
$base_px: map.get($breakpoints, $breakpoint);
|
|
229
|
+
@if $base_px == null {
|
|
230
|
+
@warn "Unknown breakpoint: #{$breakpoint}";
|
|
231
|
+
@return null;
|
|
232
|
+
}
|
|
233
|
+
// Note: CSS media queries use CSS pixels, not physical pixels
|
|
234
|
+
// This function returns the physical pixel equivalent for reference
|
|
235
|
+
@return $base_px * $target_dpr;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
///
|
|
239
|
+
/// Exposes the value of the `us` breakpoint for direct access.
|
|
240
|
+
///
|
|
241
|
+
/// @name $media_us
|
|
242
|
+
/// @type Length
|
|
243
|
+
///
|
|
244
|
+
$media_us: map.get($breakpoints, us) !default;
|
|
245
|
+
|
|
246
|
+
///
|
|
247
|
+
/// Exposes the value of the `ss` breakpoint for direct access.
|
|
248
|
+
///
|
|
249
|
+
/// @name $media_ss
|
|
250
|
+
/// @type Length
|
|
251
|
+
///
|
|
252
|
+
$media_ss: map.get($breakpoints, ss) !default;
|
|
253
|
+
|
|
96
254
|
///
|
|
97
255
|
/// Exposes the value of the `xs` breakpoint for direct access.
|
|
98
256
|
///
|
|
@@ -134,22 +292,22 @@ $media_lg: map.get($breakpoints, lg) !default;
|
|
|
134
292
|
$media_xl: map.get($breakpoints, xl) !default;
|
|
135
293
|
|
|
136
294
|
///
|
|
137
|
-
/// Exposes the value of the `
|
|
295
|
+
/// Exposes the value of the `ul` breakpoint for direct access.
|
|
138
296
|
///
|
|
139
|
-
/// @name $
|
|
297
|
+
/// @name $media_ul
|
|
140
298
|
/// @type Length
|
|
141
299
|
///
|
|
142
|
-
$
|
|
300
|
+
$media_ul: map.get($breakpoints, ul) !default;
|
|
143
301
|
|
|
144
302
|
///
|
|
145
|
-
/// Calculates the difference between the `
|
|
303
|
+
/// Calculates the difference between the `ul` and `xs` breakpoints.
|
|
146
304
|
///
|
|
147
305
|
/// @name $media_dif
|
|
148
306
|
/// @type Length
|
|
149
307
|
///
|
|
150
|
-
$media_dif: calc($
|
|
308
|
+
$media_dif: calc($media_ul - $media_xs);
|
|
151
309
|
|
|
152
|
-
// Uncomment below if you want to use the following predefined breakpoints
|
|
310
|
+
// Uncomment below if you want to use the following predefined breakpoints
|
|
153
311
|
// for various devices:
|
|
154
312
|
|
|
155
313
|
// $media_min: 320px !default; // Mobile
|