responsive-scale-mixins 1.1.1 → 2.0.0
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 +439 -16
- package/index.scss +3 -5
- package/package.json +14 -3
- package/scss/_mixins.scss +31 -34
- package/scss/_variables.scss +6 -9
package/README.md
CHANGED
|
@@ -2,8 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
A powerful SCSS mixin system for creating perfectly responsive designs that maintain Figma proportions across all screen sizes.
|
|
4
4
|
|
|
5
|
-
[](https://
|
|
5
|
+
[](https://www.npmjs.com/package/responsive-scale-mixins)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.npmjs.com/package/responsive-scale-mixins)
|
|
8
|
+
[](https://www.npmjs.com/package/responsive-scale-mixins)
|
|
9
|
+
|
|
10
|
+
## ⚠️ Breaking Changes in v2.0.0
|
|
11
|
+
|
|
12
|
+
**Pure CSS implementations are affected by this breaking change.**
|
|
13
|
+
|
|
14
|
+
- **CSS Variables**: Variable names changed from `--computed-scale-factor-px`/`--computed-scale-factor-rem` to generic `--computed-scale-factor`
|
|
15
|
+
- **Calc Expressions**: Units are now appended to multipliers (e.g., `* 2rem` instead of `* 2`)
|
|
16
|
+
- **SCSS Usage**: Unchanged - existing SCSS mixin calls continue to work
|
|
17
|
+
|
|
18
|
+
**SCSS implementations are NOT affected** - existing `@include responsive-scale()` calls work unchanged.
|
|
19
|
+
|
|
20
|
+
### Migration Guide (Pure CSS Users)
|
|
21
|
+
|
|
22
|
+
**Update your CSS variable definitions:**
|
|
23
|
+
|
|
24
|
+
```css
|
|
25
|
+
/* OLD (v1.x) */
|
|
26
|
+
:root {
|
|
27
|
+
--computed-scale-factor-px: calc(100vw / 1440);
|
|
28
|
+
--computed-scale-factor-rem: calc(100vw / 1440 / 16);
|
|
29
|
+
--computed-tablet-scale-factor-px: calc(100vw / 768);
|
|
30
|
+
--computed-tablet-scale-factor-rem: calc(100vw / 768 / 16);
|
|
31
|
+
--computed-mobile-scale-factor-px: calc(100vw / 375);
|
|
32
|
+
--computed-mobile-scale-factor-rem: calc(100vw / 375 / 16);
|
|
33
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* NEW (v2.0) */
|
|
37
|
+
:root {
|
|
38
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
39
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
40
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
41
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Update your calc expressions to include units:**
|
|
46
|
+
|
|
47
|
+
```css
|
|
48
|
+
/* OLD (v1.x) */
|
|
49
|
+
font-size: calc(var(--computed-scale-factor-px) * 40);
|
|
50
|
+
|
|
51
|
+
/* NEW (v2.0) */
|
|
52
|
+
font-size: calc(var(--computed-scale-factor) * 40px);
|
|
53
|
+
```
|
|
7
54
|
|
|
8
55
|
## ✨ Features
|
|
9
56
|
|
|
@@ -13,6 +60,7 @@ A powerful SCSS mixin system for creating perfectly responsive designs that main
|
|
|
13
60
|
- **CSS Custom Properties**: Uses modern CSS variables for optimal performance
|
|
14
61
|
- **Framework Agnostic**: Works with any CSS framework or vanilla CSS
|
|
15
62
|
- **TypeScript Ready**: Compatible with CSS Modules and CSS-in-JS solutions
|
|
63
|
+
- **Universal Unit Support**: Handles all CSS units including absolute (px, pt, cm, mm, in, pc) and relative (%, em, rem, vw, vh, vmin, vmax) units
|
|
16
64
|
|
|
17
65
|
## 🚀 Quick Start
|
|
18
66
|
|
|
@@ -45,6 +93,9 @@ pnpm add responsive-scale-mixins
|
|
|
45
93
|
@import "~responsive-scale-mixins";
|
|
46
94
|
|
|
47
95
|
:root {
|
|
96
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
97
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
98
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
48
99
|
// Define CSS variables globally (required)
|
|
49
100
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
50
101
|
// Or use defaults: @include responsive-scale-variables();
|
|
@@ -61,6 +112,10 @@ pnpm add responsive-scale-mixins
|
|
|
61
112
|
|
|
62
113
|
:root {
|
|
63
114
|
// Define CSS variables globally (required)
|
|
115
|
+
|
|
116
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
117
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
118
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
64
119
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
65
120
|
// Or use defaults: @include responsive-scale-variables();
|
|
66
121
|
}
|
|
@@ -82,6 +137,10 @@ pnpm add responsive-scale-mixins
|
|
|
82
137
|
|
|
83
138
|
:root {
|
|
84
139
|
// Define CSS variables globally (required)
|
|
140
|
+
|
|
141
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
142
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
143
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
85
144
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
86
145
|
// Or use defaults: @include responsive-scale-variables();
|
|
87
146
|
}
|
|
@@ -103,6 +162,10 @@ pnpm add responsive-scale-mixins
|
|
|
103
162
|
|
|
104
163
|
:root {
|
|
105
164
|
// Define CSS variables globally (required)
|
|
165
|
+
|
|
166
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
167
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
168
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
106
169
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
107
170
|
// Or use defaults: @include responsive-scale-variables();
|
|
108
171
|
}
|
|
@@ -124,6 +187,10 @@ pnpm add responsive-scale-mixins
|
|
|
124
187
|
|
|
125
188
|
:root {
|
|
126
189
|
// Define CSS variables globally (required)
|
|
190
|
+
|
|
191
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
192
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
193
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
127
194
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
128
195
|
// Or use defaults: @include responsive-scale-variables();
|
|
129
196
|
}
|
|
@@ -145,6 +212,10 @@ pnpm add responsive-scale-mixins
|
|
|
145
212
|
|
|
146
213
|
:root {
|
|
147
214
|
// Customize for your design system (optional)
|
|
215
|
+
|
|
216
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
217
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
218
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
148
219
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
149
220
|
// Or use defaults: @include responsive-scale-variables();
|
|
150
221
|
}
|
|
@@ -158,6 +229,10 @@ pnpm add responsive-scale-mixins
|
|
|
158
229
|
|
|
159
230
|
:root {
|
|
160
231
|
// Customize for your design system (optional)
|
|
232
|
+
|
|
233
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
234
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
235
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
161
236
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
162
237
|
// Or use defaults: @include responsive-scale-variables();
|
|
163
238
|
}
|
|
@@ -171,6 +246,10 @@ pnpm add responsive-scale-mixins
|
|
|
171
246
|
|
|
172
247
|
:root {
|
|
173
248
|
// Customize for your design system (optional)
|
|
249
|
+
|
|
250
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
251
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
252
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
174
253
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
175
254
|
// Or use defaults: @include responsive-scale-variables();
|
|
176
255
|
}
|
|
@@ -184,6 +263,10 @@ pnpm add responsive-scale-mixins
|
|
|
184
263
|
|
|
185
264
|
:root {
|
|
186
265
|
// Customize for your design system (optional)
|
|
266
|
+
|
|
267
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
268
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
269
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
187
270
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
188
271
|
// Or use defaults: @include responsive-scale-variables();
|
|
189
272
|
}
|
|
@@ -197,6 +280,10 @@ pnpm add responsive-scale-mixins
|
|
|
197
280
|
|
|
198
281
|
:root {
|
|
199
282
|
// Customize for your design system (optional)
|
|
283
|
+
|
|
284
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
285
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
286
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
200
287
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
201
288
|
// Or use defaults: @include responsive-scale-variables();
|
|
202
289
|
}
|
|
@@ -211,12 +298,12 @@ pnpm add responsive-scale-mixins
|
|
|
211
298
|
// Variables must be in global scope
|
|
212
299
|
// In your main CSS file:
|
|
213
300
|
:root {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
--computed-
|
|
218
|
-
--computed-
|
|
219
|
-
--computed-mobile-scale-factor
|
|
301
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
302
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
303
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
304
|
+
--computed-scale-factor: calc(100vw / 1920);
|
|
305
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
306
|
+
--computed-mobile-scale-factor: calc(100vw / 390);
|
|
220
307
|
--tablet-proportion-scale-factor: calc((100vw - 390px) / (1920px - 390px));
|
|
221
308
|
}
|
|
222
309
|
|
|
@@ -375,8 +462,13 @@ Easily customize the design widths to match your project's breakpoints:
|
|
|
375
462
|
|
|
376
463
|
```scss
|
|
377
464
|
:root {
|
|
465
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
466
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
467
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
468
|
+
|
|
378
469
|
// Custom design widths (desktop, tablet, mobile)
|
|
379
470
|
@include responsive-scale-variables(1440px, 768px, 375px);
|
|
471
|
+
// Or use defaults: @include responsive-scale-variables();
|
|
380
472
|
}
|
|
381
473
|
```
|
|
382
474
|
|
|
@@ -386,11 +478,56 @@ Easily customize the design widths to match your project's breakpoints:
|
|
|
386
478
|
- Tablet: 768px
|
|
387
479
|
- Mobile: 390px
|
|
388
480
|
|
|
389
|
-
### REM Units
|
|
481
|
+
### REM and EM Units
|
|
482
|
+
|
|
483
|
+
```scss
|
|
484
|
+
.element {
|
|
485
|
+
@include responsive-scale(
|
|
486
|
+
font-size,
|
|
487
|
+
3,
|
|
488
|
+
2,
|
|
489
|
+
rem
|
|
490
|
+
); // 3rem / 2rem - uses rem scale factor
|
|
491
|
+
@include responsive-scale(
|
|
492
|
+
font-size,
|
|
493
|
+
2,
|
|
494
|
+
1.5,
|
|
495
|
+
em
|
|
496
|
+
); // 2em / 1.5em - uses rem scale factor
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
**Universal Unit Support:**
|
|
501
|
+
|
|
502
|
+
The mixin supports **all CSS units** with a single generic scale factor:
|
|
503
|
+
|
|
504
|
+
**Absolute Units:**
|
|
505
|
+
|
|
506
|
+
- `@include responsive-scale(property, value, mobile-value, px)` → `* valuepx`
|
|
507
|
+
- `@include responsive-scale(property, value, mobile-value, pt)` → `* valuept`
|
|
508
|
+
- `@include responsive-scale(property, value, mobile-value, cm)` → `* valuecm`
|
|
509
|
+
- `@include responsive-scale(property, value, mobile-value, mm)` → `* valuemm`
|
|
510
|
+
- `@include responsive-scale(property, value, mobile-value, in)` → `* valuein`
|
|
511
|
+
- `@include responsive-scale(property, value, mobile-value, pc)` → `* valuepc`
|
|
512
|
+
|
|
513
|
+
**Relative Units:**
|
|
514
|
+
|
|
515
|
+
- `@include responsive-scale(property, value, mobile-value, em)` → `* valueem`
|
|
516
|
+
- `@include responsive-scale(property, value, mobile-value, rem)` → `* valuerem`
|
|
517
|
+
- `@include responsive-scale(property, value, mobile-value, %)` → `* value%`
|
|
518
|
+
- `@include responsive-scale(property, value, mobile-value, vw)` → `* valuevw`
|
|
519
|
+
- `@include responsive-scale(property, value, mobile-value, vh)` → `* valuevh`
|
|
520
|
+
- `@include responsive-scale(property, value, mobile-value, vmin)` → `* valuevmin`
|
|
521
|
+
- `@include responsive-scale(property, value, mobile-value, vmax)` → `* valuevmax`
|
|
522
|
+
|
|
523
|
+
**Example Usage:**
|
|
390
524
|
|
|
391
525
|
```scss
|
|
392
526
|
.element {
|
|
393
|
-
@include responsive-scale(
|
|
527
|
+
@include responsive-scale(margin, 2, 1, cm); // centimeters
|
|
528
|
+
@include responsive-scale(width, 50, 30, vw); // viewport width
|
|
529
|
+
@include responsive-scale(height, 80, 60, vh); // viewport height
|
|
530
|
+
@include responsive-scale(font-size, 1.5, 1, em); // em units
|
|
394
531
|
}
|
|
395
532
|
```
|
|
396
533
|
|
|
@@ -400,16 +537,275 @@ If you prefer manual control, you can set the CSS variables directly:
|
|
|
400
537
|
|
|
401
538
|
```scss
|
|
402
539
|
:root {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
--computed-
|
|
407
|
-
--computed-
|
|
408
|
-
--computed-mobile-scale-factor
|
|
540
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
541
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
542
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
543
|
+
--computed-scale-factor: calc(100vw / 1440); // Your desktop width
|
|
544
|
+
--computed-tablet-scale-factor: calc(100vw / 768); // Your tablet width
|
|
545
|
+
--computed-mobile-scale-factor: calc(100vw / 375); // Your mobile width
|
|
546
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
547
|
+
}
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
## 🔧 Troubleshooting
|
|
551
|
+
|
|
552
|
+
If the `@include responsive-scale-variables()` mixin doesn't work in your setup (e.g., due to SCSS compilation issues), use the manual CSS variables approach. Below are manual setups for each framework:
|
|
553
|
+
|
|
554
|
+
### Why the Manual Approach Works
|
|
555
|
+
|
|
556
|
+
The `@include responsive-scale-variables()` mixin may fail in certain SCSS compilation environments (like some Next.js setups) because the imported mixins aren't processed correctly. The manual CSS variables approach bypasses this by directly defining the required `--computed-scale-factor-*` variables in `:root`.
|
|
557
|
+
|
|
558
|
+
### Next.js (App Router) - Manual Setup
|
|
559
|
+
|
|
560
|
+
```scss
|
|
561
|
+
// app/globals.css or app/styles/globals.scss
|
|
562
|
+
:root {
|
|
563
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
564
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
565
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
566
|
+
--computed-scale-factor: calc(100vw / 1440); // Your design desktop width
|
|
567
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
568
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
569
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// In component files
|
|
573
|
+
@import "responsive-scale-mixins";
|
|
574
|
+
.my-element {
|
|
575
|
+
@include responsive-scale(font-size, 24, 16);
|
|
576
|
+
}
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### Next.js (Pages Router) - Manual Setup
|
|
580
|
+
|
|
581
|
+
```scss
|
|
582
|
+
// styles/globals.scss
|
|
583
|
+
:root {
|
|
584
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
585
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
586
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
587
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
588
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
589
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
590
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// In component files
|
|
594
|
+
@import "responsive-scale-mixins";
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
### Create React App - Manual Setup
|
|
598
|
+
|
|
599
|
+
```scss
|
|
600
|
+
// src/index.scss
|
|
601
|
+
:root {
|
|
602
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
603
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
604
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
605
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
606
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
607
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
608
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// In component files
|
|
612
|
+
@import "responsive-scale-mixins";
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Vue.js - Manual Setup
|
|
616
|
+
|
|
617
|
+
```scss
|
|
618
|
+
// src/assets/styles/main.scss
|
|
619
|
+
:root {
|
|
620
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
621
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
622
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
623
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
624
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
625
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
626
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// In component styles
|
|
630
|
+
@import "responsive-scale-mixins";
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
### Angular - Manual Setup
|
|
634
|
+
|
|
635
|
+
```scss
|
|
636
|
+
// src/styles.scss
|
|
637
|
+
:root {
|
|
638
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
639
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
640
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
641
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
642
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
643
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
409
644
|
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
410
645
|
}
|
|
646
|
+
|
|
647
|
+
// In component styles
|
|
648
|
+
@import "responsive-scale-mixins";
|
|
411
649
|
```
|
|
412
650
|
|
|
651
|
+
### Vite + Vue/React - Manual Setup
|
|
652
|
+
|
|
653
|
+
```scss
|
|
654
|
+
// src/styles/main.scss
|
|
655
|
+
:root {
|
|
656
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
657
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
658
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
659
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
660
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
661
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
662
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// In components
|
|
666
|
+
@import "responsive-scale-mixins";
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
### Gatsby - Manual Setup
|
|
670
|
+
|
|
671
|
+
```scss
|
|
672
|
+
// src/styles/global.scss
|
|
673
|
+
:root {
|
|
674
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
675
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
676
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
677
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
678
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
679
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
680
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// In components
|
|
684
|
+
@import "responsive-scale-mixins";
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
### Nuxt.js - Manual Setup
|
|
688
|
+
|
|
689
|
+
```scss
|
|
690
|
+
// assets/styles/main.scss
|
|
691
|
+
:root {
|
|
692
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
693
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
694
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
695
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
696
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
697
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
698
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// In components
|
|
702
|
+
@import "responsive-scale-mixins";
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
### SvelteKit - Manual Setup
|
|
706
|
+
|
|
707
|
+
```scss
|
|
708
|
+
// src/app.scss
|
|
709
|
+
:root {
|
|
710
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
711
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
712
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
713
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
714
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
715
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
716
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// In components
|
|
720
|
+
@import "responsive-scale-mixins";
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
### Astro - Manual Setup
|
|
724
|
+
|
|
725
|
+
```scss
|
|
726
|
+
// src/styles/global.scss
|
|
727
|
+
:root {
|
|
728
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
729
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
730
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
731
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
732
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
733
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
734
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// In components
|
|
738
|
+
@import "responsive-scale-mixins";
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
### CSS Modules - Manual Setup
|
|
742
|
+
|
|
743
|
+
```scss
|
|
744
|
+
// In your global CSS file (e.g., globals.scss)
|
|
745
|
+
:root {
|
|
746
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
747
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
748
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
749
|
+
--computed-scale-factor: calc(100vw / 1920);
|
|
750
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
751
|
+
--computed-mobile-scale-factor: calc(100vw / 390);
|
|
752
|
+
--tablet-proportion-scale-factor: calc((100vw - 390px) / (1920px - 390px));
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// In your module files
|
|
756
|
+
@import "responsive-scale-mixins";
|
|
757
|
+
.myClass {
|
|
758
|
+
@include responsive-scale(font-size, 24, 16);
|
|
759
|
+
}
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
### Tailwind CSS - Manual Setup
|
|
763
|
+
|
|
764
|
+
```scss
|
|
765
|
+
// styles/main.scss
|
|
766
|
+
:root {
|
|
767
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
768
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
769
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
770
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
771
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
772
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
773
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// In components
|
|
777
|
+
@import "responsive-scale-mixins";
|
|
778
|
+
.custom-element {
|
|
779
|
+
@include responsive-scale(padding, 20 40, 10 20);
|
|
780
|
+
@apply bg-blue-500 text-white;
|
|
781
|
+
}
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
### Styled Components - Manual Setup
|
|
785
|
+
|
|
786
|
+
```scss
|
|
787
|
+
// In your global styles
|
|
788
|
+
:root {
|
|
789
|
+
// Replace 1440 with your design width or leave default (desktop)
|
|
790
|
+
// Replace 768 with your design width or leave default (tablet)
|
|
791
|
+
// Replace 375 with your design width or leave default (mobile)
|
|
792
|
+
--computed-scale-factor: calc(100vw / 1440);
|
|
793
|
+
--computed-tablet-scale-factor: calc(100vw / 768);
|
|
794
|
+
--computed-mobile-scale-factor: calc(100vw / 375);
|
|
795
|
+
--tablet-proportion-scale-factor: calc((100vw - 375px) / (1440px - 375px));
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// In styled components with SCSS preprocessing
|
|
799
|
+
import styled from 'styled-components';
|
|
800
|
+
import './styles/responsive-mixins.scss';
|
|
801
|
+
|
|
802
|
+
const StyledComponent = styled.div`
|
|
803
|
+
${props => props.theme.responsiveScale('font-size', 24, 16)}
|
|
804
|
+
`;
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
**Note:** Replace `1440`, `768`, `375` with your actual design widths. The manual approach ensures compatibility across all build tools and frameworks.
|
|
808
|
+
|
|
413
809
|
## 📱 Breakpoints
|
|
414
810
|
|
|
415
811
|
- **Desktop**: ≥992px (scales from desktop design width)
|
|
@@ -449,11 +845,38 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
449
845
|
- Built for modern web development workflows
|
|
450
846
|
- Compatible with CSS Modules, Styled Components, and traditional CSS
|
|
451
847
|
|
|
452
|
-
##
|
|
848
|
+
## 🧪 Testing
|
|
849
|
+
|
|
850
|
+
The library includes a comprehensive test suite located in the `test/` directory:
|
|
851
|
+
|
|
852
|
+
```bash
|
|
853
|
+
# Run the test suite
|
|
854
|
+
cd test && ./test.sh # Unix/Linux/macOS
|
|
855
|
+
cd test && test.bat # Windows
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
See [`test/TEST_README.md`](test/TEST_README.md) for detailed testing instructions.
|
|
859
|
+
|
|
860
|
+
<!-- ## � Linking NPM Package to GitHub Packages
|
|
861
|
+
|
|
862
|
+
To connect your published NPM package to GitHub Packages:
|
|
863
|
+
|
|
864
|
+
1. **Go to your GitHub repository** → **Settings** → **Packages**
|
|
865
|
+
2. **Click "Connect repository"** or **"Link to repository"**
|
|
866
|
+
3. **Search for and select** your NPM package: `responsive-scale-mixins`
|
|
867
|
+
4. **Confirm the connection**
|
|
868
|
+
|
|
869
|
+
This will display your NPM package statistics and information in the GitHub Packages section of your repository.
|
|
870
|
+
|
|
871
|
+
**Note:** The package will automatically appear in GitHub Packages once published to NPM, as long as the repository URL in `package.json` matches your GitHub repository. -->
|
|
872
|
+
|
|
873
|
+
## �📞 Support
|
|
453
874
|
|
|
454
875
|
- 📧 Email: saheedodulaja@gmail.com
|
|
455
876
|
- 🐛 Issues: [GitHub Issues](https://github.com/Sidodus/responsive-scale-mixins/issues)
|
|
456
877
|
- 📖 Docs: [Full Documentation](https://github.com/Sidodus/responsive-scale-mixins#readme)
|
|
878
|
+
- 📦 NPM: [https://www.npmjs.com/package/responsive-scale-mixins](https://www.npmjs.com/package/responsive-scale-mixins)
|
|
879
|
+
- 👤 NPM Profile: [https://www.npmjs.com/~sidodus](https://www.npmjs.com/~sidodus)
|
|
457
880
|
|
|
458
881
|
---
|
|
459
882
|
|
package/index.scss
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// Responsive Scale Mixins
|
|
2
2
|
// A powerful SCSS mixin system for creating perfectly responsive designs
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
@
|
|
6
|
-
|
|
7
|
-
// Import the responsive scale mixin
|
|
8
|
-
@import "scss/mixins";
|
|
4
|
+
// Forward all mixins and functions from modules
|
|
5
|
+
@forward "scss/variables";
|
|
6
|
+
@forward "scss/mixins";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "responsive-scale-mixins",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "🎨 Revolutionary SCSS mixins for perfect responsive design. Supports ALL CSS units (px, rem, em, vw, vh, %, etc.) with pixel-perfect scaling. Zero manual calculations - just flawless responsive typography, spacing, and dimensions across desktop, tablet, and mobile. Framework-agnostic, modern CSS variables, works everywhere.",
|
|
5
5
|
"main": "index.scss",
|
|
6
6
|
"style": "index.scss",
|
|
7
7
|
"scripts": {
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
"responsive",
|
|
14
14
|
"mixins",
|
|
15
15
|
"figma",
|
|
16
|
+
"sketch",
|
|
17
|
+
"adobe-xd",
|
|
18
|
+
"invision",
|
|
19
|
+
"framer",
|
|
20
|
+
"zeplin",
|
|
21
|
+
"ui-design",
|
|
22
|
+
"ux-design",
|
|
23
|
+
"design-systems",
|
|
16
24
|
"typography",
|
|
17
25
|
"spacing",
|
|
18
26
|
"dimensions",
|
|
@@ -32,7 +40,10 @@
|
|
|
32
40
|
"mobile-first",
|
|
33
41
|
"responsive-design",
|
|
34
42
|
"css-variables",
|
|
35
|
-
"custom-properties"
|
|
43
|
+
"custom-properties",
|
|
44
|
+
"pixel-perfect",
|
|
45
|
+
"fluid-typography",
|
|
46
|
+
"responsive-scaling"
|
|
36
47
|
],
|
|
37
48
|
"author": "Saheed Odulaja",
|
|
38
49
|
"license": "MIT",
|
package/scss/_mixins.scss
CHANGED
|
@@ -24,7 +24,22 @@
|
|
|
24
24
|
// Media queries: Desktop (default), Tablet (768-991px), Mobile (≤767px). */
|
|
25
25
|
|
|
26
26
|
@function scaled-value($val, $scale-var, $unit: px) {
|
|
27
|
-
@return calc(var(#{$scale-var}) * #{$val});
|
|
27
|
+
@return calc(var(#{$scale-var}) * #{$val}#{$unit});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@function get-scale-factor($unit) {
|
|
31
|
+
// Use generic scale factor - unit is appended in calc expressions
|
|
32
|
+
@return unquote("--computed-scale-factor");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@function get-tablet-scale-factor($unit) {
|
|
36
|
+
// Use generic scale factor - unit is appended in calc expressions
|
|
37
|
+
@return unquote("--computed-tablet-scale-factor");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@function get-mobile-scale-factor($unit) {
|
|
41
|
+
// Use generic scale factor - unit is appended in calc expressions
|
|
42
|
+
@return unquote("--computed-mobile-scale-factor");
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
@mixin responsive-scale(
|
|
@@ -37,27 +52,21 @@
|
|
|
37
52
|
$mobile-relative: null,
|
|
38
53
|
$important: null
|
|
39
54
|
) {
|
|
40
|
-
$scale-factor:
|
|
41
|
-
$unit == px,
|
|
42
|
-
unquote("--computed-scale-factor-px"),
|
|
43
|
-
unquote("--computed-scale-factor-rem")
|
|
44
|
-
);
|
|
55
|
+
$scale-factor: get-scale-factor($unit);
|
|
45
56
|
|
|
46
57
|
// If it's a percentage-based value (like letter-spacing), scale it based on the relative property
|
|
47
58
|
@if $is-percentage == true {
|
|
48
59
|
@if $desktop-relative != null {
|
|
49
60
|
$calc-value: calc(
|
|
50
|
-
#{$desktop-value} /
|
|
61
|
+
#{$desktop-value} /
|
|
62
|
+
100 *
|
|
63
|
+
(var(#{$scale-factor}) * #{$desktop-relative}#{$unit})
|
|
51
64
|
);
|
|
52
65
|
#{$property}: #{$calc-value}#{$important};
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
@media screen and (min-width: 768px) and (max-width: 991px) {
|
|
56
|
-
$tablet-scale-factor:
|
|
57
|
-
$unit == px,
|
|
58
|
-
unquote("--computed-tablet-scale-factor-px"),
|
|
59
|
-
unquote("--computed-tablet-scale-factor-rem")
|
|
60
|
-
);
|
|
69
|
+
$tablet-scale-factor: get-tablet-scale-factor($unit);
|
|
61
70
|
@if $desktop-relative != null and $mobile-relative != null {
|
|
62
71
|
$calc-value: calc(
|
|
63
72
|
#{$mobile-value} /
|
|
@@ -65,9 +74,9 @@
|
|
|
65
74
|
(
|
|
66
75
|
var(#{$tablet-scale-factor}) *
|
|
67
76
|
(
|
|
68
|
-
#{$mobile-relative} +
|
|
77
|
+
#{$mobile-relative}#{$unit} +
|
|
69
78
|
var(--tablet-proportion-scale-factor) *
|
|
70
|
-
(#{$desktop-relative} - #{$mobile-relative})
|
|
79
|
+
(#{$desktop-relative}#{$unit} - #{$mobile-relative}#{$unit})
|
|
71
80
|
)
|
|
72
81
|
)
|
|
73
82
|
);
|
|
@@ -76,16 +85,12 @@
|
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
@media screen and (max-width: 767px) {
|
|
79
|
-
$mobile-scale-factor:
|
|
80
|
-
$unit == px,
|
|
81
|
-
unquote("--computed-mobile-scale-factor-px"),
|
|
82
|
-
unquote("--computed-mobile-scale-factor-rem")
|
|
83
|
-
);
|
|
88
|
+
$mobile-scale-factor: get-mobile-scale-factor($unit);
|
|
84
89
|
@if $mobile-relative != null {
|
|
85
90
|
$calc-value: calc(
|
|
86
91
|
#{$mobile-value} /
|
|
87
92
|
100 *
|
|
88
|
-
(var(#{$mobile-scale-factor}) * #{$mobile-relative})
|
|
93
|
+
(var(#{$mobile-scale-factor}) * #{$mobile-relative}#{$unit})
|
|
89
94
|
);
|
|
90
95
|
#{$property}: #{$calc-value}#{$important};
|
|
91
96
|
}
|
|
@@ -107,11 +112,7 @@
|
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
@media screen and (min-width: 768px) and (max-width: 991px) {
|
|
110
|
-
$tablet-scale-factor:
|
|
111
|
-
$unit == px,
|
|
112
|
-
unquote("--computed-tablet-scale-factor-px"),
|
|
113
|
-
unquote("--computed-tablet-scale-factor-rem")
|
|
114
|
-
);
|
|
115
|
+
$tablet-scale-factor: get-tablet-scale-factor($unit);
|
|
115
116
|
@if type-of($desktop-value) == list {
|
|
116
117
|
$tablet-scaled: ();
|
|
117
118
|
@for $i from 1 through length($desktop-value) {
|
|
@@ -122,9 +123,9 @@
|
|
|
122
123
|
calc(
|
|
123
124
|
var(#{$tablet-scale-factor}) *
|
|
124
125
|
(
|
|
125
|
-
#{$m-val} +
|
|
126
|
+
#{$m-val}#{$unit} +
|
|
126
127
|
var(--tablet-proportion-scale-factor) *
|
|
127
|
-
(#{$d-val} - #{$m-val})
|
|
128
|
+
(#{$d-val}#{$unit} - #{$m-val}#{$unit})
|
|
128
129
|
)
|
|
129
130
|
)
|
|
130
131
|
);
|
|
@@ -134,9 +135,9 @@
|
|
|
134
135
|
$calc-value: calc(
|
|
135
136
|
var(#{$tablet-scale-factor}) *
|
|
136
137
|
(
|
|
137
|
-
#{$mobile-value} +
|
|
138
|
+
#{$mobile-value}#{$unit} +
|
|
138
139
|
var(--tablet-proportion-scale-factor) *
|
|
139
|
-
(#{$desktop-value} - #{$mobile-value})
|
|
140
|
+
(#{$desktop-value}#{$unit} - #{$mobile-value}#{$unit})
|
|
140
141
|
)
|
|
141
142
|
);
|
|
142
143
|
#{$property}: #{$calc-value}#{$important};
|
|
@@ -144,11 +145,7 @@
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
@media screen and (max-width: 767px) {
|
|
147
|
-
$mobile-scale-factor:
|
|
148
|
-
$unit == px,
|
|
149
|
-
unquote("--computed-mobile-scale-factor-px"),
|
|
150
|
-
unquote("--computed-mobile-scale-factor-rem")
|
|
151
|
-
);
|
|
148
|
+
$mobile-scale-factor: get-mobile-scale-factor($unit);
|
|
152
149
|
@if type-of($mobile-value) == list {
|
|
153
150
|
$mobile-scaled: ();
|
|
154
151
|
@each $val in $mobile-value {
|
package/scss/_variables.scss
CHANGED
|
@@ -8,17 +8,14 @@
|
|
|
8
8
|
$tablet-width: 768px,
|
|
9
9
|
$mobile-width: 390px
|
|
10
10
|
) {
|
|
11
|
-
// Desktop scale factor
|
|
12
|
-
--computed-scale-factor
|
|
13
|
-
--computed-scale-factor-rem: calc(100vw / #{$desktop-width} / 16);
|
|
11
|
+
// Desktop scale factor (generic - unit is appended in calc expressions)
|
|
12
|
+
--computed-scale-factor: calc(100vw / #{$desktop-width});
|
|
14
13
|
|
|
15
|
-
// Tablet scale factor
|
|
16
|
-
--computed-tablet-scale-factor
|
|
17
|
-
--computed-tablet-scale-factor-rem: calc(100vw / #{$tablet-width} / 16);
|
|
14
|
+
// Tablet scale factor (generic - unit is appended in calc expressions)
|
|
15
|
+
--computed-tablet-scale-factor: calc(100vw / #{$tablet-width});
|
|
18
16
|
|
|
19
|
-
// Mobile scale factor
|
|
20
|
-
--computed-mobile-scale-factor
|
|
21
|
-
--computed-mobile-scale-factor-rem: calc(100vw / #{$mobile-width} / 16);
|
|
17
|
+
// Mobile scale factor (generic - unit is appended in calc expressions)
|
|
18
|
+
--computed-mobile-scale-factor: calc(100vw / #{$mobile-width});
|
|
22
19
|
|
|
23
20
|
// Tablet proportion scale factor for interpolation between mobile and desktop values
|
|
24
21
|
--tablet-proportion-scale-factor: calc(
|