Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pixel ratio array for image mixin #304

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions lib/nib/image.styl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
*
* affected by github.com/LearnBoost/stylus/issues/1050 and
* github.com/LearnBoost/stylus/issues/1038 ... refactor when those are closed
*
* Nicola Guo <[email protected]> modified mixin to allow array pass in.
* Defaul will out put as @1.5x, @2x & @3x so as to have better resolution for popular hi-res devices.
* If wanna change the defaul, user can specify the array for min_pixel_ratio when they use.
* e.g. image: 'yourimage.png', 20px, 30px, 1.5; //will just output the @1.5x and the base.
*/

image(path, w = auto, h = auto, min_pixel_ratio = 1.5)
image(path, w = auto, h = auto, min_pixel_ratio=1.5 2 3)
background-image: url(path)
for i in 0...length(min_pixel_ratio)
s = 'all and (-webkit-min-device-pixel-ratio:' + min_pixel_ratio[i] + '),'
s = s + '(min--moz-device-pixel-ratio:' + min_pixel_ratio[i] + '),'
s = s + '(-o-min-device-pixel-ratio:' + min_pixel_ratio[i] + '/1),'
s = s + '(min-device-pixel-ratio:' + min_pixel_ratio[i] + '),'
s = s + '(min-resolution:' + unit(min_pixel_ratio[i]*92, dpi) + '),'
s = s + '(min-resolution:' + unit(min_pixel_ratio[i], dppx) + ')'

s = 'all and (-webkit-min-device-pixel-ratio:' + min_pixel_ratio + '),'
s = s + '(min--moz-device-pixel-ratio:' + min_pixel_ratio + '),'
s = s + '(-o-min-device-pixel-ratio:' + min_pixel_ratio + '/1),'
s = s + '(min-device-pixel-ratio:' + min_pixel_ratio + '),'
s = s + '(min-resolution:' + unit(min_pixel_ratio*92, dpi) + '),'
s = s + '(min-resolution:' + unit(min_pixel_ratio, dppx) + ')'

@media s
ext = extname(path)
path = pathjoin(dirname(path), basename(path, ext) + '@2x' + ext)
background-image: url(path)
if w in (cover contain) and h == auto
h = null
background-size: w h
@media s
ext = extname(path)
path = pathjoin(dirname(path), basename(path, ext) + '@'+min_pixel_ratio[i]+'x' + ext)
background-image: url(path)
if w in (cover contain) and h == auto
h = null
background-size: w h