responsive-scale-mixins 2.1.0 → 2.2.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 +21 -2
- package/index.scss +93 -113
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ Imagine building a beautiful UI in Figma, then seeing it perfectly scale on **ev
|
|
|
50
50
|
|
|
51
51
|
Works with React, Vue, Angular, Svelte, Next.js, Nuxt, Astro, and vanilla CSS. Your favorite framework + perfect responsive design = ❤️
|
|
52
52
|
|
|
53
|
-
## 🚀 v2.
|
|
53
|
+
## 🚀 v2.2.0 - Universal Browser Compatibility (No Breaking Changes)
|
|
54
54
|
|
|
55
55
|
**Automatic fallback generation for browsers without CSS variable support!**
|
|
56
56
|
|
|
@@ -89,7 +89,12 @@ Works with React, Vue, Angular, Svelte, Next.js, Nuxt, Astro, and vanilla CSS. Y
|
|
|
89
89
|
// v2.1.0 output (works everywhere!)
|
|
90
90
|
.hero-title {
|
|
91
91
|
font-size: 48px; /* Fallback for old browsers */
|
|
92
|
-
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@supports (font-size: calc(100vw / 1920px * 48px)) {
|
|
95
|
+
.hero-title {
|
|
96
|
+
font-size: calc(100vw / 1920px * 48px); /* Modern responsive scaling */
|
|
97
|
+
}
|
|
93
98
|
}
|
|
94
99
|
```
|
|
95
100
|
|
|
@@ -122,6 +127,8 @@ Works with React, Vue, Angular, Svelte, Next.js, Nuxt, Astro, and vanilla CSS. Y
|
|
|
122
127
|
}
|
|
123
128
|
```
|
|
124
129
|
|
|
130
|
+
> Note: Setting the last argument to `false` disables fallback output globally for all `rsm.responsive-scale()` calls. Individual declarations can still override this behavior by passing the `$enable-fallback` parameter explicitly.
|
|
131
|
+
|
|
125
132
|
### **📊 Performance Impact**
|
|
126
133
|
|
|
127
134
|
- **CSS size increase**: <1 KB (after GZip) on typical sites
|
|
@@ -186,6 +193,9 @@ npm update responsive-scale-mixins
|
|
|
186
193
|
/* OLD (v1.x) */
|
|
187
194
|
font-size: calc(var(--computed-scale-factor-px) * 40);
|
|
188
195
|
|
|
196
|
+
/* NEW (v2.0+) */
|
|
197
|
+
font-size: calc(var(--computed-scale-factor) * 40px);
|
|
198
|
+
|
|
189
199
|
@include rsm.responsive-scale(font-size, 24, 16);
|
|
190
200
|
```
|
|
191
201
|
|
|
@@ -1042,6 +1052,15 @@ The library includes a comprehensive test suite located in the `test/` directory
|
|
|
1042
1052
|
cd test && ./test.sh
|
|
1043
1053
|
```
|
|
1044
1054
|
|
|
1055
|
+
If `./test.sh` fails because `sass` is not installed globally, run this instead from the repository root:
|
|
1056
|
+
|
|
1057
|
+
```bash
|
|
1058
|
+
npx --yes sass test/test.scss test/test.css
|
|
1059
|
+
start test/test.html
|
|
1060
|
+
```
|
|
1061
|
+
|
|
1062
|
+
On Windows, you can also open `test/test.html` manually after compiling.
|
|
1063
|
+
|
|
1045
1064
|
See [`test/TEST_README.md`](test/TEST_README.md) for detailed testing instructions.
|
|
1046
1065
|
|
|
1047
1066
|
<!-- ## � Linking NPM Package to GitHub Packages
|
package/index.scss
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
// Responsive Scale Mixins v2.
|
|
1
|
+
// Responsive Scale Mixins v2.2.0
|
|
2
2
|
// A powerful SCSS mixin system for creating perfectly responsive designs
|
|
3
3
|
// with universal browser compatibility and static fallbacks
|
|
4
4
|
// Single-file distribution for maximum compatibility
|
|
5
5
|
|
|
6
|
+
@use "sass:math";
|
|
6
7
|
@use "sass:string";
|
|
7
8
|
@use "sass:meta";
|
|
8
9
|
@use "sass:list";
|
|
9
10
|
|
|
11
|
+
$rsm-fallback-enabled: true !default;
|
|
12
|
+
$rsm-desktop-width: 1920px !default;
|
|
13
|
+
$rsm-tablet-width: 768px !default;
|
|
14
|
+
$rsm-mobile-width: 390px !default;
|
|
15
|
+
|
|
10
16
|
/* Responsive Scale Variables Mixin
|
|
11
17
|
* Include this mixin in your root element to define the scaling factors.
|
|
12
18
|
* Adjust the design widths to match your design system breakpoints.
|
|
13
19
|
*
|
|
14
|
-
* v2.
|
|
20
|
+
* v2.2.0: Now includes fallback generation for browsers without CSS variable support
|
|
15
21
|
*/
|
|
16
22
|
|
|
17
23
|
@mixin responsive-scale-variables(
|
|
@@ -20,94 +26,69 @@
|
|
|
20
26
|
$mobile-width: 390px,
|
|
21
27
|
$enable-fallback: true
|
|
22
28
|
) {
|
|
29
|
+
$rsm-fallback-enabled: $enable-fallback !global;
|
|
30
|
+
$rsm-desktop-width: $desktop-width !global;
|
|
31
|
+
$rsm-tablet-width: $tablet-width !global;
|
|
32
|
+
$rsm-mobile-width: $mobile-width !global;
|
|
23
33
|
// Design widths for direct calc expressions
|
|
24
34
|
--desktop-width: #{$desktop-width};
|
|
25
35
|
--tablet-width: #{$tablet-width};
|
|
26
36
|
--mobile-width: #{$mobile-width};
|
|
27
37
|
|
|
28
38
|
// Desktop scale factor (generic - unit is appended in calc expressions)
|
|
29
|
-
--computed-scale-factor:
|
|
39
|
+
--computed-scale-factor: (100vw / #{$desktop-width});
|
|
30
40
|
|
|
31
41
|
// Tablet scale factor (generic - unit is appended in calc expressions)
|
|
32
|
-
--computed-tablet-scale-factor:
|
|
42
|
+
--computed-tablet-scale-factor: (100vw / #{$tablet-width});
|
|
33
43
|
|
|
34
44
|
// Mobile scale factor (generic - unit is appended in calc expressions)
|
|
35
|
-
--computed-mobile-scale-factor:
|
|
45
|
+
--computed-mobile-scale-factor: (100vw / #{$mobile-width});
|
|
36
46
|
|
|
37
47
|
// Tablet proportion scale factor for interpolation between mobile and desktop values
|
|
38
|
-
--tablet-proportion-scale-factor:
|
|
48
|
+
--tablet-proportion-scale-factor: (
|
|
39
49
|
(100vw - #{$mobile-width}) / (#{$desktop-width} - #{$mobile-width})
|
|
40
50
|
);
|
|
41
51
|
|
|
42
|
-
// v2.
|
|
52
|
+
// v2.2.0: Store original design widths as strings for fallback calculation
|
|
43
53
|
--rsm-desktop-width-value: #{strip-units($desktop-width)};
|
|
44
54
|
--rsm-tablet-width-value: #{strip-units($tablet-width)};
|
|
45
55
|
--rsm-mobile-width-value: #{strip-units($mobile-width)};
|
|
46
|
-
--rsm-fallback-enabled: 1;
|
|
56
|
+
--rsm-fallback-enabled: #{if(sass($enable-fallback): 1; else: 0)};
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
/* Utility function to strip units from values */
|
|
50
60
|
@function strip-units($value) {
|
|
51
|
-
@return $value
|
|
61
|
+
@return math.div($value, $value * 0 + 1);
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
/* Responsive Scale Mixins
|
|
55
65
|
* Core scaling functionality with support for all CSS units
|
|
56
|
-
* v2.
|
|
66
|
+
* v2.2.0: Generates both modern calc() AND static fallback values
|
|
57
67
|
*/
|
|
58
68
|
|
|
59
|
-
@function scaled-value($val, $
|
|
60
|
-
@
|
|
61
|
-
@return calc(100vw / var(--desktop-width) * #{$val}#{$unit});
|
|
62
|
-
} @else if $scale-var == "--computed-tablet-scale-factor" {
|
|
63
|
-
@return calc(100vw / var(--tablet-width) * #{$val}#{$unit});
|
|
64
|
-
} @else if $scale-var == "--computed-mobile-scale-factor" {
|
|
65
|
-
@return calc(100vw / var(--mobile-width) * #{$val}#{$unit});
|
|
66
|
-
} @else {
|
|
67
|
-
@return calc(var(#{$scale-var}) * #{$val}#{$unit});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/* v2.1.0: Calculate static fallback values for unsupported browsers
|
|
72
|
-
* These values are computed at compile time, not runtime
|
|
73
|
-
*/
|
|
74
|
-
@function fallback-value($val, $breakpoint: "desktop", $unit: px) {
|
|
75
|
-
// Default device widths for fallback calculation
|
|
76
|
-
$default-desktop: 1920;
|
|
77
|
-
$default-tablet: 768;
|
|
78
|
-
$default-mobile: 390;
|
|
79
|
-
|
|
80
|
-
@if $breakpoint == "desktop" {
|
|
81
|
-
$fallback: calc($val);
|
|
82
|
-
@return $fallback#{$unit};
|
|
83
|
-
} @else if $breakpoint == "tablet" {
|
|
84
|
-
// Use middle breakpoint for tablet fallback
|
|
85
|
-
$fallback: calc($val);
|
|
86
|
-
@return $fallback#{$unit};
|
|
87
|
-
} @else if $breakpoint == "mobile" {
|
|
88
|
-
$fallback: calc($val);
|
|
89
|
-
@return $fallback#{$unit};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@return $val#{$unit};
|
|
69
|
+
@function scaled-value($val, $width, $unit: px) {
|
|
70
|
+
@return calc((100vw / #{$width}) * #{$val}#{$unit});
|
|
93
71
|
}
|
|
94
72
|
|
|
95
|
-
@function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
73
|
+
@function tablet-interpolation($desktop-value, $mobile-value, $unit) {
|
|
74
|
+
@return calc(
|
|
75
|
+
(100vw / #{$rsm-tablet-width}) *
|
|
76
|
+
(
|
|
77
|
+
#{$mobile-value}#{$unit} +
|
|
78
|
+
(
|
|
79
|
+
(100vw - #{$rsm-mobile-width}) /
|
|
80
|
+
(#{$rsm-desktop-width} - #{$rsm-mobile-width})
|
|
81
|
+
) *
|
|
82
|
+
(#{$desktop-value}#{$unit} - #{$mobile-value}#{$unit})
|
|
83
|
+
)
|
|
84
|
+
);
|
|
103
85
|
}
|
|
104
86
|
|
|
105
|
-
@function
|
|
106
|
-
|
|
107
|
-
@return string.unquote("--computed-mobile-scale-factor");
|
|
87
|
+
@function mobile-scale-expression($mobile-value, $unit) {
|
|
88
|
+
@return calc((100vw / #{$rsm-mobile-width}) * #{$mobile-value}#{$unit});
|
|
108
89
|
}
|
|
109
90
|
|
|
110
|
-
/* v2.
|
|
91
|
+
/* v2.2.0: Main responsive scale mixin with fallback support
|
|
111
92
|
* Generates two CSS declarations:
|
|
112
93
|
* 1. Static fallback value for unsupported browsers
|
|
113
94
|
* 2. Modern calc() expression for modern browsers
|
|
@@ -121,34 +102,32 @@
|
|
|
121
102
|
$desktop-relative: null,
|
|
122
103
|
$mobile-relative: null,
|
|
123
104
|
$important: null,
|
|
124
|
-
$enable-fallback:
|
|
105
|
+
$enable-fallback: null
|
|
125
106
|
) {
|
|
126
|
-
$
|
|
107
|
+
@if $enable-fallback == null {
|
|
108
|
+
$enable-fallback: $rsm-fallback-enabled;
|
|
109
|
+
}
|
|
127
110
|
|
|
128
111
|
// If it's a percentage-based value (like letter-spacing), scale it based on the relative property
|
|
129
112
|
@if $is-percentage == true {
|
|
130
113
|
@if $desktop-relative != null {
|
|
131
|
-
// v2.1.0: Output fallback value first
|
|
132
114
|
@if $enable-fallback {
|
|
133
|
-
$fallback
|
|
134
|
-
#{$property}: #{$fallback
|
|
115
|
+
$desktop-fallback: calc(#{$desktop-value} / 100 * #{$desktop-relative});
|
|
116
|
+
#{$property}: #{$desktop-fallback}#{$unit}#{$important};
|
|
135
117
|
}
|
|
136
118
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
#{$desktop-value} /
|
|
140
|
-
100 *
|
|
141
|
-
(var(#{$scale-factor}) * #{$desktop-relative}#{$unit})
|
|
119
|
+
$modern-desktop: calc(
|
|
120
|
+
#{$desktop-value} / 100 * #{$desktop-relative}#{$unit}
|
|
142
121
|
);
|
|
143
|
-
#{$property}: #{$
|
|
122
|
+
@supports (#{$property}: #{$modern-desktop}) {
|
|
123
|
+
#{$property}: #{$modern-desktop}#{$important};
|
|
124
|
+
}
|
|
144
125
|
}
|
|
145
126
|
|
|
146
127
|
@media screen and (min-width: 768px) and (max-width: 991px) {
|
|
147
|
-
$tablet-scale-factor: get-tablet-scale-factor($unit);
|
|
148
128
|
@if $desktop-relative != null and $mobile-relative != null {
|
|
149
|
-
// v2.1.0: Fallback for tablet
|
|
150
129
|
@if $enable-fallback {
|
|
151
|
-
$fallback
|
|
130
|
+
$tablet-fallback: calc(
|
|
152
131
|
#{$mobile-value} /
|
|
153
132
|
100 *
|
|
154
133
|
(
|
|
@@ -157,48 +136,46 @@
|
|
|
157
136
|
(#{$desktop-relative}#{$unit} - #{$mobile-relative}#{$unit})
|
|
158
137
|
)
|
|
159
138
|
);
|
|
160
|
-
#{$property}: #{$fallback
|
|
139
|
+
#{$property}: #{$tablet-fallback}#{$important};
|
|
161
140
|
}
|
|
162
141
|
|
|
163
|
-
|
|
164
|
-
$calc-value: calc(
|
|
142
|
+
$modern-tablet: calc(
|
|
165
143
|
#{$mobile-value} /
|
|
166
144
|
100 *
|
|
167
145
|
(
|
|
168
|
-
|
|
146
|
+
#{$mobile-relative}#{$unit} +
|
|
169
147
|
(
|
|
170
|
-
#{$mobile-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
)
|
|
148
|
+
(100vw - #{$rsm-mobile-width}) /
|
|
149
|
+
(#{$rsm-desktop-width} - #{$rsm-mobile-width})
|
|
150
|
+
) *
|
|
151
|
+
(#{$desktop-relative}#{$unit} - #{$mobile-relative}#{$unit})
|
|
174
152
|
)
|
|
175
153
|
);
|
|
176
|
-
#{$property}: #{$
|
|
154
|
+
@supports (#{$property}: #{$modern-tablet}) {
|
|
155
|
+
#{$property}: #{$modern-tablet}#{$important};
|
|
156
|
+
}
|
|
177
157
|
}
|
|
178
158
|
}
|
|
179
159
|
|
|
180
160
|
@media screen and (max-width: 767px) {
|
|
181
|
-
$mobile-scale-factor: get-mobile-scale-factor($unit);
|
|
182
161
|
@if $mobile-relative != null {
|
|
183
|
-
// v2.1.0: Fallback for mobile
|
|
184
162
|
@if $enable-fallback {
|
|
185
|
-
$fallback
|
|
186
|
-
#{$property}: #{$fallback
|
|
163
|
+
$mobile-fallback: calc(#{$mobile-value} / 100 * #{$mobile-relative});
|
|
164
|
+
#{$property}: #{$mobile-fallback}#{$unit}#{$important};
|
|
187
165
|
}
|
|
188
166
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
#{$mobile-value} /
|
|
192
|
-
100 *
|
|
193
|
-
(var(#{$mobile-scale-factor}) * #{$mobile-relative}#{$unit})
|
|
167
|
+
$modern-mobile: calc(
|
|
168
|
+
#{$mobile-value} / 100 * #{$mobile-relative}#{$unit}
|
|
194
169
|
);
|
|
195
|
-
#{$property}: #{$
|
|
170
|
+
@supports (#{$property}: #{$modern-mobile}) {
|
|
171
|
+
#{$property}: #{$modern-mobile}#{$important};
|
|
172
|
+
}
|
|
196
173
|
}
|
|
197
174
|
}
|
|
198
175
|
} @else {
|
|
199
176
|
// Regular absolute scaling
|
|
200
177
|
@if meta.type-of($desktop-value) == list {
|
|
201
|
-
// v2.
|
|
178
|
+
// v2.2.0: Fallback for list values (padding: 20 40)
|
|
202
179
|
@if $enable-fallback {
|
|
203
180
|
$desktop-fallback: ();
|
|
204
181
|
@each $val in $desktop-value {
|
|
@@ -212,25 +189,27 @@
|
|
|
212
189
|
@each $val in $desktop-value {
|
|
213
190
|
$desktop-scaled: list.append(
|
|
214
191
|
$desktop-scaled,
|
|
215
|
-
scaled-value($val, $
|
|
192
|
+
scaled-value($val, $rsm-desktop-width, $unit)
|
|
216
193
|
);
|
|
217
194
|
}
|
|
218
195
|
#{$property}: #{$desktop-scaled}#{$important};
|
|
219
196
|
} @else {
|
|
220
|
-
// v2.
|
|
197
|
+
// v2.2.0: Fallback for single values
|
|
221
198
|
@if $enable-fallback {
|
|
222
199
|
#{$property}: #{$desktop-value}#{$unit}#{$important};
|
|
223
200
|
}
|
|
224
201
|
|
|
225
|
-
// Modern calc expression
|
|
226
|
-
$
|
|
227
|
-
#{$property}: #{$
|
|
202
|
+
// Modern calc expression (wrapped in @supports so Firefox will fallback)
|
|
203
|
+
$modern-desktop: scaled-value($desktop-value, $rsm-desktop-width, $unit);
|
|
204
|
+
@supports (#{$property}: #{$modern-desktop}) {
|
|
205
|
+
#{$property}: #{$modern-desktop}#{$important};
|
|
206
|
+
}
|
|
228
207
|
}
|
|
229
208
|
|
|
230
209
|
@media screen and (min-width: 768px) and (max-width: 991px) {
|
|
231
210
|
$tablet-scale-factor: get-tablet-scale-factor($unit);
|
|
232
211
|
@if meta.type-of($desktop-value) == list {
|
|
233
|
-
// v2.
|
|
212
|
+
// v2.2.0: Fallback for tablet list
|
|
234
213
|
@if $enable-fallback {
|
|
235
214
|
$tablet-fallback: ();
|
|
236
215
|
@for $i from 1 through list.length($desktop-value) {
|
|
@@ -259,28 +238,27 @@
|
|
|
259
238
|
}
|
|
260
239
|
#{$property}: #{$tablet-scaled}#{$important};
|
|
261
240
|
} @else {
|
|
262
|
-
// v2.
|
|
241
|
+
// v2.2.0: Fallback for tablet single value
|
|
263
242
|
@if $enable-fallback {
|
|
264
243
|
#{$property}: #{$mobile-value}#{$unit}#{$important};
|
|
265
244
|
}
|
|
266
245
|
|
|
267
|
-
// Modern expression
|
|
268
|
-
$
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
var(--tablet-proportion-scale-factor) *
|
|
273
|
-
(#{$desktop-value}#{$unit} - #{$mobile-value}#{$unit})
|
|
274
|
-
)
|
|
246
|
+
// Modern expression (wrapped in @supports so Firefox will fallback)
|
|
247
|
+
$modern-tablet: tablet-interpolation(
|
|
248
|
+
$desktop-value,
|
|
249
|
+
$mobile-value,
|
|
250
|
+
$unit
|
|
275
251
|
);
|
|
276
|
-
#{$property}: #{$
|
|
252
|
+
@supports (#{$property}: #{$modern-tablet}) {
|
|
253
|
+
#{$property}: #{$modern-tablet}#{$important};
|
|
254
|
+
}
|
|
277
255
|
}
|
|
278
256
|
}
|
|
279
257
|
|
|
280
258
|
@media screen and (max-width: 767px) {
|
|
281
259
|
$mobile-scale-factor: get-mobile-scale-factor($unit);
|
|
282
260
|
@if meta.type-of($mobile-value) == list {
|
|
283
|
-
// v2.
|
|
261
|
+
// v2.2.0: Fallback for mobile list
|
|
284
262
|
@if $enable-fallback {
|
|
285
263
|
$mobile-fallback: ();
|
|
286
264
|
@each $val in $mobile-value {
|
|
@@ -294,25 +272,27 @@
|
|
|
294
272
|
@each $val in $mobile-value {
|
|
295
273
|
$mobile-scaled: list.append(
|
|
296
274
|
$mobile-scaled,
|
|
297
|
-
scaled-value($val, $mobile-
|
|
275
|
+
scaled-value($val, $rsm-mobile-width, $unit)
|
|
298
276
|
);
|
|
299
277
|
}
|
|
300
278
|
#{$property}: #{$mobile-scaled}#{$important};
|
|
301
279
|
} @else {
|
|
302
|
-
// v2.
|
|
280
|
+
// v2.2.0: Fallback for mobile single value
|
|
303
281
|
@if $enable-fallback {
|
|
304
282
|
#{$property}: #{$mobile-value}#{$unit}#{$important};
|
|
305
283
|
}
|
|
306
284
|
|
|
307
|
-
// Modern expression
|
|
308
|
-
$
|
|
309
|
-
#{$property}: #{$
|
|
285
|
+
// Modern expression (wrapped in @supports so Firefox will fallback)
|
|
286
|
+
$modern-mobile: mobile-scale-expression($mobile-value, $unit);
|
|
287
|
+
@supports (#{$property}: #{$modern-mobile}) {
|
|
288
|
+
#{$property}: #{$modern-mobile}#{$important};
|
|
289
|
+
}
|
|
310
290
|
}
|
|
311
291
|
}
|
|
312
292
|
}
|
|
313
293
|
}
|
|
314
294
|
|
|
315
|
-
/* v2.
|
|
295
|
+
/* v2.2.0: New mixin to disable fallback for specific declarations
|
|
316
296
|
* Useful when you want only modern browsers to receive a style
|
|
317
297
|
*/
|
|
318
298
|
@mixin responsive-scale-no-fallback(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "responsive-scale-mixins",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "🎨 Revolutionary SCSS mixins for perfect responsive design with universal browser compatibility. Supports ALL CSS units (px, rem, em, vw, vh, %, etc.) with pixel-perfect scaling and automatic fallbacks for browsers without CSS variable support. Zero manual calculations - just flawless responsive typography, spacing, and dimensions across desktop, tablet, and mobile. Single-file distribution for maximum compatibility. Framework-agnostic, works everywhere including Firefox Mobile and old Android browsers.",
|
|
5
5
|
"main": "index.scss",
|
|
6
6
|
"style": "index.scss",
|