Created
October 25, 2013 09:15
-
-
Save lunelson/7151916 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.3.0.rc.1) | |
// Compass (v0.13.alpha.7) | |
// ---- | |
@import "breakpoint"; | |
@function str-remove($str, $sub) { | |
$i: str-index($str, $sub); | |
@if $i == 0 { @return $str; } | |
@else { @return str-remove(str-slice($str, 1, $i - 1) + str-slice($str, $i + 1, str-length($str)), $sub); } | |
} | |
@function map-debug($map) { | |
$result: unquote("( "); | |
@each $key, $value in $map { | |
@if type_of($value) == 'map' { | |
$result: unquote("#{$result} #{$key}: #{map-debug($value)}"); | |
} @else { $result: unquote("#{$result}#{$key}: #{$value}, "); } | |
} | |
$result: unquote("#{$result} )"); | |
$result: str-remove($result,", )"); | |
$result: str-remove($result," "); | |
@return quote($result); | |
} | |
@function n-get($map, $keys...) { | |
@each $key in $keys { @if $map == null { @return null; } @else { $map: map-get($map, $key); } } | |
@return $map; } | |
$units: ( | |
'em': 1em, | |
'ex': 1ex, | |
'ch': 1ch, | |
'rem': 1rem, | |
'%': 1%, | |
'vw': 1vw, | |
'vh': 1vh, | |
'vmin': 1vmin, | |
'vmax': 1vmax, | |
'cm': 1cm, | |
'mm': 1mm, | |
'in': 1in, | |
'px': 1px, | |
'pt': 1pt, | |
'pc': 1pc, | |
'deg': 1deg, | |
'grad': 1grad, | |
'rad': 1rad, | |
'turn': 1turn, | |
's': 1s, | |
'ms': 1ms, | |
'dpi': 1dpi, | |
'dpcm': 1dpcm, | |
'dppx': 1dppx | |
); | |
@function one-unit($unit) { $one-unit: map-get($units, $unit); @return if($one-unit, $one-unit, 1); } | |
@function strip($value) { @return $value / one-unit(unit($value)); } | |
@function assert($value, $unit) { @return strip($value) * one-unit($unit); } | |
// width and gutter can be in rem or em; ideally rem | |
$bp-data: ( | |
a: ( | |
width: 30rem, | |
gutter: 1rem, | |
scale: 125% | |
), | |
b: ( | |
width: 45rem, | |
gutter: 1rem, | |
scale: 100% | |
), | |
c: ( | |
width: 60rem, | |
gutter: 1rem, | |
scale: 200% | |
) | |
); | |
$html-font-size: 100% !default; | |
@mixin breakpoint-setup($data) { | |
$breakpoints: () !global; | |
@each $alias, $spec in $data { | |
$width: map-get($spec, width); | |
$gutter: map-get($spec, gutter); | |
$scale: map-get($spec, scale); | |
$breakpoint: (em: ($width + 2 * $gutter) * $scale / 100%, rem: $width); | |
$breakpoints: map-merge($breakpoints, (#{$alias}: $breakpoint)); | |
@if $scale != 100% { @media (min-width: #{map-get($breakpoint, em)}) { html { font-size: $scale; } } } | |
} | |
} | |
@mixin bp-setup($data) { | |
$bp: () !global; | |
$prev-scale: strip($html-font-size); | |
@each $alias, $spec in $data { | |
$width: assert(map-get($spec, width), em); | |
$gutter: assert(map-get($spec, gutter), em); | |
$scale: strip(map-get($spec, scale)); | |
$breakpoint: map-merge(map-get($data, $alias), (query: ($width + 2 * $gutter) * $scale / 100)); | |
$bp: map-merge($bp, (#{$alias}: $breakpoint)) !global; | |
@if $scale != $prev-scale { @media (min-width: #{map-get($breakpoint, query)}) { html { font-size: assert($scale, '%'); } } } | |
$prev-scale: $scale; | |
} | |
} | |
// @include breakpoint-setup($bp-data); | |
@include bp-setup($bp-data); | |
.debug { | |
map: map-debug($bp); | |
bp1: n-get($bp, a, query); | |
bp2: n-get($bp, b, query); | |
bp3: n-get($bp, c, query); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@media (min-width: 40em) { | |
html { | |
font-size: 125%; } } | |
@media (min-width: 47em) { | |
html { | |
font-size: 100%; } } | |
@media (min-width: 124em) { | |
html { | |
font-size: 200%; } } | |
.debug { | |
map: "( a: ( width: 30rem, gutter: 1rem, scale: 125%, query: 40em ) b: ( width: 45rem, gutter: 1rem, scale: 100%, query: 47em ) c: ( width: 60rem, gutter: 1rem, scale: 200%, query: 124em ) )"; | |
bp1: 40em; | |
bp2: 47em; | |
bp3: 124em; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment