diff options
Diffstat (limited to 'src/_responsive.scss')
| -rw-r--r-- | src/_responsive.scss | 391 |
1 files changed, 198 insertions, 193 deletions
diff --git a/src/_responsive.scss b/src/_responsive.scss index 4d98638..f613a6d 100644 --- a/src/_responsive.scss +++ b/src/_responsive.scss | |||
| @@ -17,6 +17,11 @@ | |||
| 17 | /// @access public | 17 | /// @access public |
| 18 | //// | 18 | //// |
| 19 | 19 | ||
| 20 | @use 'sass:list'; | ||
| 21 | @use 'sass:map'; | ||
| 22 | @use 'sass:math'; | ||
| 23 | @use 'sass:meta'; | ||
| 24 | @use 'sass:string'; | ||
| 20 | @use './functions'; | 25 | @use './functions'; |
| 21 | @use './contexts'; | 26 | @use './contexts'; |
| 22 | 27 | ||
| @@ -99,15 +104,15 @@ $named-viewports: () !default; | |||
| 99 | /// } | 104 | /// } |
| 100 | /// | 105 | /// |
| 101 | @mixin property($props, $responsive-map, $fluid: true, $vertical: false) { | 106 | @mixin property($props, $responsive-map, $fluid: true, $vertical: false) { |
| 102 | @include env(map-keys($responsive-map), $fluid, $vertical) { | 107 | @include env(map.keys($responsive-map), $fluid, $vertical) { |
| 103 | @if type-of($props) == list { | 108 | @if meta.type-of($props) == list { |
| 104 | @each $prop in $props { | 109 | @each $prop in $props { |
| 105 | #{$prop}: set(map-values($responsive-map)); | 110 | #{$prop}: set(map.values($responsive-map)); |
| 106 | } | 111 | } |
| 107 | } @else { | 112 | } @else { |
| 108 | #{$props}: set(map-values($responsive-map)); | 113 | #{$props}: set(map.values($responsive-map)); |
| 109 | } | 114 | } |
| 110 | } | 115 | } |
| 111 | } | 116 | } |
| 112 | 117 | ||
| 113 | /// | 118 | /// |
| @@ -150,153 +155,153 @@ $named-viewports: () !default; | |||
| 150 | /// } | 155 | /// } |
| 151 | /// | 156 | /// |
| 152 | @mixin env($viewports, $fluid: true, $vertical: false) { | 157 | @mixin env($viewports, $fluid: true, $vertical: false) { |
| 153 | @if length($viewports) <= 1 { | 158 | @if list.length($viewports) <= 1 { |
| 154 | @error '$viewports must contain at least two viewports.'; | 159 | @error '$viewports must contain at least two viewports.'; |
| 155 | } | 160 | } |
| 156 | 161 | ||
| 157 | $new-viewports: (); | 162 | $new-viewports: (); |
| 158 | 163 | ||
| 159 | @each $viewport in $viewports { | 164 | @each $viewport in $viewports { |
| 160 | @if map-has-key($named-viewports, $viewport) { | 165 | @if map.has-key($named-viewports, $viewport) { |
| 161 | $viewport: map-get($named-viewports, $viewport); | 166 | $viewport: map.get($named-viewports, $viewport); |
| 162 | } | 167 | } |
| 163 | 168 | ||
| 164 | @if (type-of($viewport) != number) or unitless($viewport) { | 169 | @if (meta.type-of($viewport) != number) or math.is-unitless($viewport) { |
| 165 | @error '$viewports contains invalid viewports.'; | 170 | @error '$viewports contains invalid viewports.'; |
| 166 | } | 171 | } |
| 167 | 172 | ||
| 168 | $new-viewports: append($new-viewports, $viewport); | 173 | $new-viewports: list.append($new-viewports, $viewport); |
| 169 | } | 174 | } |
| 170 | 175 | ||
| 171 | $viewports: functions.quicksort($new-viewports); | 176 | $viewports: functions.quicksort($new-viewports); |
| 172 | 177 | ||
| 173 | @if $new-viewports != $viewports { | 178 | @if $new-viewports != $viewports { |
| 174 | @error '$viewports was not sorted in ascending order.'; | 179 | @error '$viewports was not sorted in ascending order.'; |
| 175 | } | 180 | } |
| 176 | 181 | ||
| 177 | @if $fluid { | 182 | @if $fluid { |
| 178 | $first-vp: nth($viewports, 1); | 183 | $first-vp: list.nth($viewports, 1); |
| 179 | $last-vp: nth($viewports, length($viewports)); | 184 | $last-vp: list.nth($viewports, list.length($viewports)); |
| 180 | 185 | ||
| 181 | @include contexts.push($context-id, 'env', ( | 186 | @include contexts.push($context-id, 'env', ( |
| 182 | 'viewports': $viewports, | 187 | 'viewports': $viewports, |
| 183 | 'mode': set, | 188 | 'mode': set, |
| 184 | 'index': 1, | 189 | 'index': 1, |
| 185 | 'fluid': $fluid, | 190 | 'fluid': $fluid, |
| 186 | 'vertical': $vertical, | 191 | 'vertical': $vertical, |
| 187 | )); | 192 | )); |
| 188 | 193 | ||
| 189 | @content; | 194 | @content; |
| 190 | 195 | ||
| 191 | @include contexts.pop($context-id); | 196 | @include contexts.pop($context-id); |
| 192 | 197 | ||
| 193 | @for $i from 1 to length($viewports) { | 198 | @for $i from 1 to list.length($viewports) { |
| 194 | $prev-vp: nth($viewports, $i); | 199 | $prev-vp: list.nth($viewports, $i); |
| 195 | $next-vp: nth($viewports, $i + 1); | 200 | $next-vp: list.nth($viewports, $i + 1); |
| 196 | 201 | ||
| 197 | @if not $vertical { | 202 | @if not $vertical { |
| 198 | @media (min-width: $prev-vp) and (max-width: $next-vp) { | 203 | @media (min-width: $prev-vp) and (max-width: $next-vp) { |
| 199 | @include contexts.push($context-id, 'env', ( | 204 | @include contexts.push($context-id, 'env', ( |
| 200 | 'viewports': $viewports, | 205 | 'viewports': $viewports, |
| 201 | 'mode': transition, | 206 | 'mode': transition, |
| 202 | 'index': $i, | 207 | 'index': $i, |
| 203 | 'fluid': $fluid, | 208 | 'fluid': $fluid, |
| 204 | 'vertical': $vertical, | 209 | 'vertical': $vertical, |
| 205 | )); | 210 | )); |
| 206 | 211 | ||
| 207 | @content; | 212 | @content; |
| 208 | 213 | ||
| 209 | @include contexts.pop($context-id); | 214 | @include contexts.pop($context-id); |
| 210 | } | 215 | } |
| 211 | } @else { | 216 | } @else { |
| 212 | @media (min-height: $prev-vp) and (max-height: $next-vp) { | 217 | @media (min-height: $prev-vp) and (max-height: $next-vp) { |
| 213 | @include contexts.push($context-id, 'env', ( | 218 | @include contexts.push($context-id, 'env', ( |
| 214 | 'viewports': $viewports, | 219 | 'viewports': $viewports, |
| 215 | 'mode': transition, | 220 | 'mode': transition, |
| 216 | 'index': $i, | 221 | 'index': $i, |
| 217 | 'fluid': $fluid, | 222 | 'fluid': $fluid, |
| 218 | 'vertical': $vertical, | 223 | 'vertical': $vertical, |
| 219 | )); | 224 | )); |
| 220 | 225 | ||
| 221 | @content; | 226 | @content; |
| 222 | 227 | ||
| 223 | @include contexts.pop($context-id); | 228 | @include contexts.pop($context-id); |
| 224 | } | 229 | } |
| 225 | } | 230 | } |
| 226 | } | 231 | } |
| 227 | 232 | ||
| 228 | @if not $vertical { | 233 | @if not $vertical { |
| 229 | @media (min-width: $last-vp) { | 234 | @media (min-width: $last-vp) { |
| 230 | @include contexts.push($context-id, 'env', ( | 235 | @include contexts.push($context-id, 'env', ( |
| 231 | 'viewports': $viewports, | 236 | 'viewports': $viewports, |
| 232 | 'mode': set, | 237 | 'mode': set, |
| 233 | 'index': length($viewports), | 238 | 'index': list.length($viewports), |
| 234 | 'fluid': $fluid, | 239 | 'fluid': $fluid, |
| 235 | 'vertical': $vertical, | 240 | 'vertical': $vertical, |
| 236 | )); | 241 | )); |
| 237 | 242 | ||
| 238 | @content; | 243 | @content; |
| 239 | 244 | ||
| 240 | @include contexts.pop($context-id); | 245 | @include contexts.pop($context-id); |
| 241 | } | 246 | } |
| 242 | } @else { | 247 | } @else { |
| 243 | @media (min-height: $last-vp) { | 248 | @media (min-height: $last-vp) { |
| 244 | @include contexts.push($context-id, 'env', ( | 249 | @include contexts.push($context-id, 'env', ( |
| 245 | 'viewports': $viewports, | 250 | 'viewports': $viewports, |
| 246 | 'mode': set, | 251 | 'mode': set, |
| 247 | 'index': length($viewports), | 252 | 'index': list.length($viewports), |
| 248 | 'fluid': $fluid, | 253 | 'fluid': $fluid, |
| 249 | 'vertical': $vertical, | 254 | 'vertical': $vertical, |
| 250 | )); | 255 | )); |
| 251 | 256 | ||
| 252 | @content; | 257 | @content; |
| 253 | 258 | ||
| 254 | @include contexts.pop($context-id); | 259 | @include contexts.pop($context-id); |
| 255 | } | 260 | } |
| 256 | } | 261 | } |
| 257 | } @else { | 262 | } @else { |
| 258 | @include contexts.push($context-id, 'env', ( | 263 | @include contexts.push($context-id, 'env', ( |
| 259 | 'viewports': $viewports, | 264 | 'viewports': $viewports, |
| 260 | 'mode': set, | 265 | 'mode': set, |
| 261 | 'index': 1, | 266 | 'index': 1, |
| 262 | 'fluid': $fluid, | 267 | 'fluid': $fluid, |
| 263 | 'vertical': $vertical, | 268 | 'vertical': $vertical, |
| 264 | )); | 269 | )); |
| 265 | 270 | ||
| 266 | @content; | 271 | @content; |
| 267 | 272 | ||
| 268 | @include contexts.pop($context-id); | 273 | @include contexts.pop($context-id); |
| 269 | 274 | ||
| 270 | @for $i from 2 through length($viewports) { | 275 | @for $i from 2 through list.length($viewports) { |
| 271 | $vp: nth($viewports, $i); | 276 | $vp: list.nth($viewports, $i); |
| 272 | 277 | ||
| 273 | @if not $vertical { | 278 | @if not $vertical { |
| 274 | @media (min-width: $vp) { | 279 | @media (min-width: $vp) { |
| 275 | @include contexts.push($context-id, 'env', ( | 280 | @include contexts.push($context-id, 'env', ( |
| 276 | 'viewports': $viewports, | 281 | 'viewports': $viewports, |
| 277 | 'mode': set, | 282 | 'mode': set, |
| 278 | 'index': $i | 283 | 'index': $i |
| 279 | )); | 284 | )); |
| 280 | 285 | ||
| 281 | @content; | 286 | @content; |
| 282 | 287 | ||
| 283 | @include contexts.pop($context-id); | 288 | @include contexts.pop($context-id); |
| 284 | } | 289 | } |
| 285 | } @else { | 290 | } @else { |
| 286 | @media (min-height: $vp) { | 291 | @media (min-height: $vp) { |
| 287 | @include contexts.push($context-id, 'env', ( | 292 | @include contexts.push($context-id, 'env', ( |
| 288 | 'viewports': $viewports, | 293 | 'viewports': $viewports, |
| 289 | 'mode': set, | 294 | 'mode': set, |
| 290 | 'index': $i | 295 | 'index': $i |
| 291 | )); | 296 | )); |
| 292 | 297 | ||
| 293 | @content; | 298 | @content; |
| 294 | 299 | ||
| 295 | @include contexts.pop($context-id); | 300 | @include contexts.pop($context-id); |
| 296 | } | 301 | } |
| 297 | } | 302 | } |
| 298 | } | 303 | } |
| 299 | } | 304 | } |
| 300 | } | 305 | } |
| 301 | 306 | ||
| 302 | /// | 307 | /// |
| @@ -307,29 +312,29 @@ $named-viewports: () !default; | |||
| 307 | /// @return {number|string} | 312 | /// @return {number|string} |
| 308 | /// | 313 | /// |
| 309 | @function set($values, $without-calc: false) { | 314 | @function set($values, $without-calc: false) { |
| 310 | $noop: contexts.assert-stack-must-contain($context-id, 'env'); | 315 | $noop: contexts.assert-stack-must-contain($context-id, 'env'); |
| 311 | 316 | ||
| 312 | $data: nth(contexts.get($context-id, 'env'), 2); | 317 | $data: list.nth(contexts.get($context-id, 'env'), 2); |
| 313 | $viewports: map-get($data, 'viewports'); | 318 | $viewports: map.get($data, 'viewports'); |
| 314 | $mode: map-get($data, 'mode'); | 319 | $mode: map.get($data, 'mode'); |
| 315 | $fluid: map-get($data, 'fluid'); | 320 | $fluid: map.get($data, 'fluid'); |
| 316 | $vertical: map-get($data, 'vertical'); | 321 | $vertical: map.get($data, 'vertical'); |
| 317 | 322 | ||
| 318 | @if length($values) != length($viewports) { | 323 | @if list.length($values) != list.length($viewports) { |
| 319 | @error '$values must contain the same number of items as the responsive environment\'s $viewports.'; | 324 | @error '$values must contain the same number of items as the responsive environment\'s $viewports.'; |
| 320 | } | 325 | } |
| 321 | 326 | ||
| 322 | @if $mode == set { | 327 | @if $mode == set { |
| 323 | @return nth($values, map-get($data, 'index')); | 328 | @return list.nth($values, map.get($data, 'index')); |
| 324 | } @else { | 329 | } @else { |
| 325 | $index: map-get($data, 'index'); | 330 | $index: map.get($data, 'index'); |
| 326 | $prev-vp: nth($viewports, $index); | 331 | $prev-vp: list.nth($viewports, $index); |
| 327 | $next-vp: nth($viewports, $index + 1); | 332 | $next-vp: list.nth($viewports, $index + 1); |
| 328 | $prev-value: nth($values, $index); | 333 | $prev-value: list.nth($values, $index); |
| 329 | $next-value: nth($values, $index + 1); | 334 | $next-value: list.nth($values, $index + 1); |
| 330 | 335 | ||
| 331 | @return fluid-calc($prev-value, $next-value, $prev-vp, $next-vp, $vertical, $without-calc); | 336 | @return fluid-calc($prev-value, $next-value, $prev-vp, $next-vp, $vertical, $without-calc); |
| 332 | } | 337 | } |
| 333 | } | 338 | } |
| 334 | 339 | ||
| 335 | /// | 340 | /// |
| @@ -345,62 +350,62 @@ $named-viewports: () !default; | |||
| 345 | /// @access private | 350 | /// @access private |
| 346 | /// | 351 | /// |
| 347 | @function fluid-calc($min-value, $max-value, $min-viewport, $max-viewport, $vertical: false, $without-calc: false) { | 352 | @function fluid-calc($min-value, $max-value, $min-viewport, $max-viewport, $vertical: false, $without-calc: false) { |
| 348 | $value-unit: unit($min-value); | 353 | $value-unit: math.unit($min-value); |
| 349 | $max-value-unit: unit($max-value); | 354 | $max-value-unit: math.unit($max-value); |
| 350 | $viewport-unit: unit($min-viewport); | 355 | $viewport-unit: math.unit($min-viewport); |
| 351 | $max-viewport-unit: unit($max-viewport); | 356 | $max-viewport-unit: math.unit($max-viewport); |
| 352 | 357 | ||
| 353 | @if $min-value == 0 { | 358 | @if $min-value == 0 { |
| 354 | $value-unit: $max-value-unit; | 359 | $value-unit: $max-value-unit; |
| 355 | } | 360 | } |
| 356 | @if $max-value == 0 { | 361 | @if $max-value == 0 { |
| 357 | $max-value-unit: $value-unit; | 362 | $max-value-unit: $value-unit; |
| 358 | } | 363 | } |
| 359 | @if $min-viewport == 0 { | 364 | @if $min-viewport == 0 { |
| 360 | $viewport-unit: $max-viewport-unit; | 365 | $viewport-unit: $max-viewport-unit; |
| 361 | } | 366 | } |
| 362 | @if $max-viewport == 0 { | 367 | @if $max-viewport == 0 { |
| 363 | $max-viewport-unit: $viewport-unit; | 368 | $max-viewport-unit: $viewport-unit; |
| 364 | } | 369 | } |
| 365 | 370 | ||
| 366 | @if ($value-unit != $max-value-unit) or ($viewport-unit != $max-viewport-unit) { | 371 | @if ($value-unit != $max-value-unit) or ($viewport-unit != $max-viewport-unit) { |
| 367 | @error 'Units of $min-value and $max-value, $min-viewport and $max-viewport must match.'; | 372 | @error 'Units of $min-value and $max-value, $min-viewport and $max-viewport must match.'; |
| 368 | } | 373 | } |
| 369 | 374 | ||
| 370 | @if ($value-unit == rem) and ($viewport-unit == px) { | 375 | @if ($value-unit == rem) and ($viewport-unit == px) { |
| 371 | $min-viewport: functions.px-to-rem($min-viewport); | 376 | $min-viewport: functions.px-to-rem($min-viewport); |
| 372 | $max-viewport: functions.px-to-rem($max-viewport); | 377 | $max-viewport: functions.px-to-rem($max-viewport); |
| 373 | $viewport-unit: rem; | 378 | $viewport-unit: rem; |
| 374 | } @else if ($value-unit == px) and ($viewport-unit == rem) { | 379 | } @else if ($value-unit == px) and ($viewport-unit == rem) { |
| 375 | $min-value: functions.px-to-rem($min-value); | 380 | $min-value: functions.px-to-rem($min-value); |
| 376 | $max-value: functions.px-to-rem($max-value); | 381 | $max-value: functions.px-to-rem($max-value); |
| 377 | $value-unit: rem; | 382 | $value-unit: rem; |
| 378 | } | 383 | } |
| 379 | 384 | ||
| 380 | @if $value-unit != $viewport-unit { | 385 | @if $value-unit != $viewport-unit { |
| 381 | @error 'This combination of units is not supported.'; | 386 | @error 'This combination of units is not supported.'; |
| 382 | } | 387 | } |
| 383 | 388 | ||
| 384 | $value-diff: functions.strip-unit($max-value - $min-value); | 389 | $value-diff: functions.strip-unit($max-value - $min-value); |
| 385 | $viewport-diff: functions.strip-unit($max-viewport - $min-viewport); | 390 | $viewport-diff: functions.strip-unit($max-viewport - $min-viewport); |
| 386 | 391 | ||
| 387 | $calc: ''; | 392 | $calc: ''; |
| 388 | 393 | ||
| 389 | @if $min-value != 0 { | 394 | @if $min-value != 0 { |
| 390 | $calc: '#{$min-value} + '; | 395 | $calc: '#{$min-value} + '; |
| 391 | } | 396 | } |
| 392 | 397 | ||
| 393 | @if not $vertical { | 398 | @if not $vertical { |
| 394 | $calc: unquote('#{$calc}#{$value-diff} * (100vw - #{$min-viewport}) / #{$viewport-diff}'); | 399 | $calc: string.unquote('#{$calc}#{$value-diff} * (100vw - #{$min-viewport}) / #{$viewport-diff}'); |
| 395 | } @else { | 400 | } @else { |
| 396 | $calc: unquote('#{$calc}#{$value-diff} * (100vh - #{$min-viewport}) / #{$viewport-diff}'); | 401 | $calc: string.unquote('#{$calc}#{$value-diff} * (100vh - #{$min-viewport}) / #{$viewport-diff}'); |
| 397 | } | 402 | } |
| 398 | 403 | ||
| 399 | @if $without-calc { | 404 | @if $without-calc { |
| 400 | @return $calc; | 405 | @return $calc; |
| 401 | } @else { | 406 | } @else { |
| 402 | @return calc(#{$calc}); | 407 | @return calc(#{$calc}); |
| 403 | } | 408 | } |
| 404 | } | 409 | } |
| 405 | 410 | ||
| 406 | @include contexts.create($context-id); | 411 | @include contexts.create($context-id); |
