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.
Files changed (41) hide show
  1. package/README.md +329 -1
  2. package/css/unit.gl.css +35819 -6
  3. package/css/unit.gl.docs.css +4156 -0
  4. package/css/unit.gl.docs.min.css +2 -0
  5. package/css/unit.gl.min.css +1 -1
  6. package/js/unit.gl.demo.js +708 -0
  7. package/js/unit.gl.demo.js.map +1 -0
  8. package/js/unit.gl.js +25 -0
  9. package/js/unit.gl.js.map +1 -1
  10. package/package.json +16 -3
  11. package/scss/classes/_docs.scss +4690 -0
  12. package/scss/classes/_index.scss +1 -0
  13. package/scss/classes/_utilities.scss +1488 -0
  14. package/scss/docs.scss +11 -0
  15. package/scss/formats.scss +27 -0
  16. package/scss/functions/_density.scss +311 -0
  17. package/scss/functions/_index.scss +3 -0
  18. package/scss/functions/_scale.scss +211 -1
  19. package/scss/guide.scss +22 -0
  20. package/scss/maps/_density.scss +141 -0
  21. package/scss/maps/_device.scss +13 -20
  22. package/scss/maps/_index.scss +6 -0
  23. package/scss/maps/_scale.scss +47 -4
  24. package/scss/mixins/_device.scss +1 -3
  25. package/scss/mixins/_display.scss +256 -0
  26. package/scss/mixins/_format.scss +75 -0
  27. package/scss/mixins/_index.scss +2 -1
  28. package/scss/mixins/_unit.scss +115 -6
  29. package/scss/mixins/_utilities.scss +303 -0
  30. package/scss/mixins/_view.scss +41 -11
  31. package/scss/tags/_global.scss +0 -3
  32. package/scss/tags/_unit.scss +1 -3
  33. package/scss/utilities.scss +20 -0
  34. package/scss/variables/_format.scss +80 -0
  35. package/scss/variables/_index.scss +4 -0
  36. package/scss/variables/_scale.scss +434 -63
  37. package/scss/variables/_view.scss +222 -64
  38. package/ts/demo.ts +889 -0
  39. package/ts/index.d.ts +72 -0
  40. package/ts/index.ts +45 -0
  41. package/scss/mixins/_paper.scss +0 -52
@@ -5,8 +5,33 @@
5
5
  ///
6
6
  /// This module defines the base typographic and spacing scales used throughout
7
7
  /// the project, leveraging a rhythm-based approach for consistent vertical
8
- /// spacing and typographic hierarchy. The Kyū Point and Baseline scales
9
- /// provide a flexible system for responsive design.
8
+ /// spacing and typographic hierarchy.
9
+ ///
10
+ /// Hybrid Scale System
11
+ /// ───────────────────────────────────────────────────────────────────────────
12
+ /// The system uses two complementary scales:
13
+ ///
14
+ /// 1. TYPE SCALE (4Q = 1mm = 4px)
15
+ /// - Used for: font-size, letter-spacing, fine adjustments
16
+ /// - Clean 4px increments for typography
17
+ ///
18
+ /// 2. LINE SCALE (5Q = 1.25mm = 5px)
19
+ /// - Used for: line-height, vertical spacing, layout rhythm
20
+ /// - Aligns perfectly with Q format paper sizes and screen resolutions
21
+ ///
22
+ /// Key Relationships:
23
+ /// ───────────────────────────────────────────────────────────────────────────
24
+ /// | Format | mm (W×H) | Line Units | Pixels (×4) | Use Case |
25
+ /// |--------|-------------|------------|-------------|---------------------|
26
+ /// | Q07 | 60×90 | 12×18 | 240×360 | Compact/Watch |
27
+ /// | Q06 | 90×135 | 18×27 | 360×540 | Phone |
28
+ /// | Q05 | 135×180 | 27×36 | 540×720 | Large phone |
29
+ /// | Q04 | 180×270 | 36×54 | 720×1080 | Tablet (HD) |
30
+ /// | Q03 | 270×360 | 54×72 | 1080×1440 | Laptop |
31
+ /// | Q02 | 360×540 | 72×108 | 1440×2160 | Desktop (QHD) |
32
+ /// | Q01 | 540×720 | 108×144 | 2160×2880 | Large desktop |
33
+ /// | Q00 | 720×1080 | 144×216 | 2880×4320 | 5K display |
34
+ /// ───────────────────────────────────────────────────────────────────────────
10
35
  ///
11
36
  /// @group Scale
12
37
  /// @author Scape Agency
@@ -18,20 +43,19 @@
18
43
  ///
19
44
  ////
20
45
 
21
-
22
46
  // ============================================================================
23
47
  // Use
24
48
  // ============================================================================
25
49
 
26
50
  @use "unit" as *;
27
51
 
28
-
29
52
  // ============================================================================
30
- // Variables
53
+ // Core Rhythm Variables
31
54
  // ============================================================================
32
55
 
33
56
  ///
34
57
  /// The base rhythm unit used for vertical spacing and typography.
58
+ /// Based on 4Q (4px) for clean typographic increments.
35
59
  ///
36
60
  /// @name $rhythm_base
37
61
  /// @type Length
@@ -80,6 +104,100 @@ $font_size_base: calc($font_size_scalar * $rhythm_base) !default;
80
104
  ///
81
105
  $line_height_base: calc($line_height_scalar * $rhythm_base) !default;
82
106
 
107
+ // ============================================================================
108
+ // Type Scale (4Q = 1mm = 4px)
109
+ // ============================================================================
110
+
111
+ ///
112
+ /// Type Scale Multiplier
113
+ /// ---------------------------------------------------------------------------
114
+ ///
115
+ /// The base scaling factor for the type point scale.
116
+ /// 4Q = 4px = 1mm at standard density.
117
+ ///
118
+ /// @name $type_scale
119
+ /// @type Number
120
+ ///
121
+ $type_scale: 4 !default;
122
+
123
+ ///
124
+ /// Kyū Point Scale (Legacy Alias)
125
+ /// ---------------------------------------------------------------------------
126
+ ///
127
+ /// Alias for $type_scale for backward compatibility.
128
+ ///
129
+ /// @name $basepoint_scale
130
+ /// @type Number
131
+ /// @deprecated Use $type_scale instead
132
+ ///
133
+ $basepoint_scale: $type_scale !default;
134
+
135
+ ///
136
+ /// Calculates a type point value based on the type scale.
137
+ ///
138
+ /// @name basepoint
139
+ /// @param {Number} $value - The multiplier to apply to the type scale.
140
+ /// @return {Length} The calculated type point value.
141
+ /// @deprecated Use type() function from _scale.scss instead
142
+ ///
143
+ @function basepoint($value) {
144
+ @return calc($q * $value * $type_scale);
145
+ }
146
+
147
+ ///
148
+ /// Type Scale Map
149
+ /// ---------------------------------------------------------------------------
150
+ ///
151
+ /// A scale of type points (4Q-based), used for font sizing and fine spacing.
152
+ /// Each step represents multiples of 4Q (4px).
153
+ ///
154
+ /// @name $type_points
155
+ /// @type Map
156
+ ///
157
+ $type_points: (
158
+ 1: basepoint(1),
159
+ // 4px
160
+ 2: basepoint(2),
161
+ // 8px
162
+ 3: basepoint(3),
163
+ // 12px
164
+ 4: basepoint(4),
165
+ // 16px (base)
166
+ 5: basepoint(5),
167
+ // 20px ← aligns with line(4)
168
+ 6: basepoint(6),
169
+ // 24px
170
+ 7: basepoint(7),
171
+ // 28px
172
+ 8: basepoint(8),
173
+ // 32px
174
+ 9: basepoint(9),
175
+ // 36px
176
+ 10: basepoint(10),
177
+ // 40px ← aligns with line(8)
178
+ 11: basepoint(11),
179
+ // 44px
180
+ 12: basepoint(12),
181
+ // 48px
182
+ 13: basepoint(13),
183
+ // 52px
184
+ 14: basepoint(14),
185
+ // 56px
186
+ 15: basepoint(15),
187
+ // 60px ← aligns with line(12)
188
+ 16: basepoint(16),
189
+ // 64px
190
+ 17: basepoint(17),
191
+ // 68px
192
+ 18: basepoint(18) // 72px
193
+ ) !default;
194
+
195
+ ///
196
+ /// Legacy basepoint map alias
197
+ /// @deprecated Use $type_points instead
198
+ ///
199
+ $basepoint: $type_points !default;
200
+
83
201
  ///
84
202
  /// Typographic Scale Map
85
203
  /// ---------------------------------------------------------------------------
@@ -103,9 +221,9 @@ $typographic_scale: (
103
221
  6: q(14),
104
222
  // +2 units
105
223
  7: q(16),
106
- // +2 units
224
+ // +2 units (base)
107
225
  8: q(20),
108
- // +4 units
226
+ // +4 units ← aligns with line(4)
109
227
  9: q(24),
110
228
  // +4 units
111
229
  10: q(28),
@@ -115,101 +233,354 @@ $typographic_scale: (
115
233
  12: q(36),
116
234
  // +4 units
117
235
  13: q(40),
118
- // +4 units
236
+ // +4 units ← aligns with line(8)
119
237
  14: q(48),
120
238
  // +8 units
121
239
  15: q(56),
122
240
  // +8 units
123
241
  16: q(64),
124
242
  // +8 units
125
- 17: q(72),
126
- // +8 units
243
+ 17: q(72) // +8 units
127
244
  ) !default;
128
245
 
129
- ///
130
- /// Kyū Point Scale
131
- /// ---------------------------------------------------------------------------
132
- ///
133
- /// The base scaling factor for the Kyū point scale.
134
- ///
135
- /// @name $basepoint_scale
136
- /// @type Number
137
- ///
138
- $basepoint_scale: 4 !default;
246
+ // ============================================================================
247
+ // Line Scale (5Q = 1.25mm = 5px)
248
+ // ============================================================================
139
249
 
140
250
  ///
141
- /// Calculates a Kyū point value based on the basepoint scale.
142
- ///
143
- /// @name basepoint
144
- /// @param {Number} $value - The multiplier to apply to the base point scale.
145
- /// @return {Length} The calculated Kyū point value.
251
+ /// Line Scale Multiplier
252
+ /// ---------------------------------------------------------------------------
146
253
  ///
147
- @function basepoint($value) {
148
- @return calc($q * $value * $basepoint_scale);
149
- }
150
-
254
+ /// The base scaling factor for the line grid.
255
+ /// 5Q = 5px = 1.25mm at standard density.
151
256
  ///
152
- /// A scale of Kyū points, used for fine-tuned spacing and sizing.
257
+ /// This scale aligns perfectly with Q format paper sizes:
258
+ /// - Q04 (180×270mm) = 36×54 line units = 720×1080px
153
259
  ///
154
- /// @name $basepoint
155
- /// @type Map
260
+ /// @name $line_scale
261
+ /// @type Number
156
262
  ///
157
- $basepoint: (
158
- 1: basepoint(1),
159
- 2: basepoint(2),
160
- 3: basepoint(3),
161
- 4: basepoint(4),
162
- 5: basepoint(5),
163
- 6: basepoint(6),
164
- 7: basepoint(7),
165
- 8: basepoint(8),
166
- 9: basepoint(9),
167
- 10: basepoint(10),
168
- 11: basepoint(11),
169
- 12: basepoint(12)
170
- ) !default;
263
+ $line_scale: 5 !default;
171
264
 
172
265
  ///
173
- /// Kyū Baseline Scale
174
- /// ---------------------------------------------------------------------------
175
- ///
176
- /// The base scaling factor for the Kyū baseline grid.
266
+ /// Legacy Baseline Scale Alias
267
+ /// @deprecated Use $line_scale instead
177
268
  ///
178
- /// @name $baseline_scale
179
- /// @type Number
180
- ///
181
- $baseline_scale: 5 !default;
269
+ $baseline_scale: $line_scale !default;
182
270
 
183
271
  ///
184
- /// Calculates a baseline grid value based on the baseline scale.
272
+ /// Calculates a line grid value based on the line scale.
185
273
  ///
186
274
  /// @name baseline
187
275
  /// @type Function
188
- /// @param {Number} $value - The multiplier to apply to the baseline scale.
189
- /// @return {Length} The calculated baseline grid value.
276
+ /// @param {Number} $value - The multiplier to apply to the line scale.
277
+ /// @return {Length} The calculated line grid value.
278
+ /// @deprecated Use line() function from _scale.scss instead
190
279
  ///
191
280
  @function baseline($value) {
192
- @return calc($q * $value * $baseline_scale);
281
+ @return calc($q * $value * $line_scale);
193
282
  }
194
283
 
195
284
  ///
196
- /// A scale for the baseline grid, used for consistent vertical rhythm in
197
- /// layouts.
285
+ /// Line Scale Map
286
+ /// ---------------------------------------------------------------------------
198
287
  ///
199
- /// @name $baseline
288
+ /// A scale for the line grid (5Q-based), used for vertical rhythm and spacing.
289
+ /// Each step represents multiples of 5Q (5px).
290
+ ///
291
+ /// @name $line_units
200
292
  /// @type Map
201
293
  ///
202
- $baseline: (
294
+ $line_units: (
203
295
  1: baseline(1),
296
+ // 5px
204
297
  2: baseline(2),
298
+ // 10px
205
299
  3: baseline(3),
300
+ // 15px
206
301
  4: baseline(4),
302
+ // 20px ← aligns with type(5)
207
303
  5: baseline(5),
304
+ // 25px
208
305
  6: baseline(6),
306
+ // 30px
209
307
  7: baseline(7),
308
+ // 35px
210
309
  8: baseline(8),
310
+ // 40px ← aligns with type(10)
211
311
  9: baseline(9),
312
+ // 45px
212
313
  10: baseline(10),
314
+ // 50px
213
315
  11: baseline(11),
214
- 12: baseline(12)
316
+ // 55px
317
+ 12: baseline(12),
318
+ // 60px ← aligns with type(15)
319
+ 16: baseline(16),
320
+ // 80px ← aligns with type(20)
321
+ 18: baseline(18),
322
+ // 90px (Q07 width)
323
+ 20: baseline(20),
324
+ // 100px ← aligns with type(25)
325
+ 24: baseline(24),
326
+ // 120px
327
+ 27: baseline(27),
328
+ // 135px (Q05 width)
329
+ 36: baseline(36),
330
+ // 180px (Q04 width)
331
+ 54: baseline(54),
332
+ // 270px (Q04 height)
333
+ 72: baseline(72),
334
+ // 360px (Q03 width)
335
+ 108: baseline(108),
336
+ // 540px (Q02 width)
337
+ 144: baseline(144),
338
+ // 720px (Q01 width)
339
+ 216: baseline(216) // 1080px (Q04 height in px)
340
+ ) !default;
341
+
342
+ ///
343
+ /// Legacy baseline map alias
344
+ /// @deprecated Use $line_units instead
345
+ ///
346
+ $baseline: $line_units !default;
347
+
348
+ ///
349
+ /// Line Height Scale
350
+ /// ---------------------------------------------------------------------------
351
+ ///
352
+ /// Semantic line-height values based on the line scale (5Q).
353
+ /// These snap to the baseline grid for vertical rhythm.
354
+ ///
355
+ /// @name $line_height_scale
356
+ /// @type Map
357
+ ///
358
+ $line_height_scale: (
359
+ tight: baseline(3),
360
+ // 15px - for dense UI
361
+ snug: baseline(4),
362
+ // 20px - compact text ← aligns with type(5)
363
+ normal: baseline(5),
364
+ // 25px - body text
365
+ relaxed: baseline(6),
366
+ // 30px - comfortable reading
367
+ loose: baseline(8) // 40px - spacious ← aligns with type(10)
368
+ ) !default;
369
+
370
+ ///
371
+ /// Spacing Scale
372
+ /// ---------------------------------------------------------------------------
373
+ ///
374
+ /// Semantic spacing values based on the line scale (5Q).
375
+ /// Used for margins, padding, and gaps.
376
+ ///
377
+ /// @name $spacing_scale
378
+ /// @type Map
379
+ ///
380
+ $spacing_scale: (
381
+ 0: baseline(0),
382
+ // 0px
383
+ xs: baseline(1),
384
+ // 5px
385
+ sm: baseline(2),
386
+ // 10px
387
+ md: baseline(3),
388
+ // 15px
389
+ lg: baseline(4),
390
+ // 20px ← LCM alignment
391
+ xl: baseline(6),
392
+ // 30px
393
+ 2xl: baseline(8),
394
+ // 40px ← LCM alignment
395
+ 3xl: baseline(12),
396
+ // 60px ← LCM alignment
397
+ 4xl: baseline(16),
398
+ // 80px ← LCM alignment
399
+ 5xl: baseline(20) // 100px ← LCM alignment
400
+ ) !default;
401
+
402
+ // ============================================================================
403
+ // Q Format ↔ Line Grid Mapping
404
+ // ============================================================================
405
+
406
+ ///
407
+ /// Q Format Line Grid
408
+ /// ---------------------------------------------------------------------------
409
+ ///
410
+ /// Maps Q format paper sizes to their line grid dimensions.
411
+ /// Each entry shows (columns × rows) in line units.
412
+ ///
413
+ /// Formula: mm ÷ 1.25 = line units (since 5Q = 1.25mm)
414
+ ///
415
+ /// @name $q_format_lines
416
+ /// @type Map
417
+ ///
418
+ $q_format_lines: (
419
+ q07: (
420
+ columns: 48,
421
+ rows: 72
422
+ ),
423
+ // 60×90mm → 48×72 lines = 240×360px
424
+ q06: (
425
+ columns: 72,
426
+ rows: 108
427
+ ),
428
+ // 90×135mm → 72×108 lines = 360×540px
429
+ q05: (
430
+ columns: 108,
431
+ rows: 144
432
+ ),
433
+ // 135×180mm → 108×144 lines = 540×720px
434
+ q04: (
435
+ columns: 144,
436
+ rows: 216
437
+ ),
438
+ // 180×270mm → 144×216 lines = 720×1080px
439
+ q03: (
440
+ columns: 216,
441
+ rows: 288
442
+ ),
443
+ // 270×360mm → 216×288 lines = 1080×1440px
444
+ q02: (
445
+ columns: 288,
446
+ rows: 432
447
+ ),
448
+ // 360×540mm → 288×432 lines = 1440×2160px
449
+ q01: (
450
+ columns: 432,
451
+ rows: 576
452
+ ),
453
+ // 540×720mm → 432×576 lines = 2160×2880px
454
+ q00: (
455
+ columns: 576,
456
+ rows: 864
457
+ ) // 720×1080mm → 576×864 lines = 2880×4320px
215
458
  ) !default;
459
+
460
+ ///
461
+ /// Common Screen Resolutions in Line Units
462
+ /// ---------------------------------------------------------------------------
463
+ ///
464
+ /// Maps common screen resolutions to line grid dimensions.
465
+ ///
466
+ /// @name $resolution_lines
467
+ /// @type Map
468
+ ///
469
+ $resolution_lines: (
470
+ qvga: (
471
+ columns: 64,
472
+ rows: 48
473
+ ),
474
+ // 320×240 (÷5)
475
+ hvga: (
476
+ columns: 96,
477
+ rows: 64
478
+ ),
479
+ // 480×320 (÷5)
480
+ vga: (
481
+ columns: 128,
482
+ rows: 96
483
+ ),
484
+ // 640×480 (÷5)
485
+ svga: (
486
+ columns: 160,
487
+ rows: 120
488
+ ),
489
+ // 800×600 (÷5)
490
+ xga: (
491
+ columns: 204,
492
+ rows: 153
493
+ ),
494
+ // 1024×768 (÷5, rounded)
495
+ hd: (
496
+ columns: 144,
497
+ rows: 216
498
+ ),
499
+ // 720×1080 (÷5) = Q04
500
+ fhd: (
501
+ columns: 384,
502
+ rows: 216
503
+ ),
504
+ // 1920×1080 (÷5)
505
+ qhd: (
506
+ columns: 512,
507
+ rows: 288
508
+ ),
509
+ // 2560×1440 (÷5)
510
+ uhd: (
511
+ columns: 768,
512
+ rows: 432
513
+ ),
514
+ // 3840×2160 (÷5)
515
+ 5k: (
516
+ columns: 1024,
517
+ rows: 576
518
+ ) // 5120×2880 (÷5)
519
+ ) !default;
520
+
521
+ // ============================================================================
522
+ // Density-Aware Scale Functions
523
+ // ============================================================================
524
+
525
+ ///
526
+ /// Density-aware scale function.
527
+ /// Returns a typographic scale value adjusted for target DPR.
528
+ /// Useful for creating density-aware font sizes that maintain
529
+ /// optical consistency across different pixel densities.
530
+ ///
531
+ /// @name scale_density
532
+ /// @param {Number} $step - The typographic scale step (1-17)
533
+ /// @param {Number} $target_dpr [1] - Target device pixel ratio
534
+ /// @param {Number} $density_scale [0.9] - Scale factor per DPR step
535
+ /// @return {Length} Adjusted size value
536
+ ///
537
+ /// @example scss - Usage
538
+ /// font-size: scale_density(7); // q(16) at 1× DPR
539
+ /// font-size: scale_density(7, 2); // q(16) * 0.9 at 2× DPR
540
+ /// font-size: scale_density(7, 3); // q(16) * 0.81 at 3× DPR
541
+ ///
542
+ @function scale_density($step, $target_dpr: 1, $density_scale: 0.9) {
543
+ $base_size: map-get($typographic_scale, $step);
544
+
545
+ @if $base_size == null {
546
+ @warn "Invalid typographic scale step: #{$step}. Valid steps are 1-17.";
547
+ @return null;
548
+ }
549
+
550
+ @if $target_dpr <= 1 {
551
+ @return $base_size;
552
+ }
553
+
554
+ // Calculate the scale factor: scale^(dpr-1)
555
+ // For DPR 2: 0.9^1 = 0.9
556
+ // For DPR 3: 0.9^2 = 0.81
557
+ $factor: 1;
558
+ @for $i from 2 through $target_dpr {
559
+ $factor: $factor * $density_scale;
560
+ }
561
+
562
+ @return calc(#{$base_size} * #{$factor});
563
+ }
564
+
565
+ ///
566
+ /// Get scale value with CSS custom property density adjustment.
567
+ /// Uses var(--dpr-inverse) for runtime density adaptation.
568
+ /// Requires JavaScript DPR injection.
569
+ ///
570
+ /// @name scale_density_runtime
571
+ /// @param {Number} $step - The typographic scale step (1-17)
572
+ /// @return {String} calc() expression with runtime DPR adjustment
573
+ ///
574
+ /// @example scss - Usage
575
+ /// font-size: scale_density_runtime(7); // Scales with runtime DPR
576
+ ///
577
+ @function scale_density_runtime($step) {
578
+ $base_size: map-get($typographic_scale, $step);
579
+
580
+ @if $base_size == null {
581
+ @warn "Invalid typographic scale step: #{$step}. Valid steps are 1-17.";
582
+ @return null;
583
+ }
584
+
585
+ @return calc(#{$base_size} * var(--dpr-inverse, 1));
586
+ }