From 019bb943365e512132a4a309921c014d3b80a69a Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Wed, 11 May 2016 19:43:59 -0400 Subject: [PATCH] stylus: scaling spritesheets --- stylus_helpers.styl | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/stylus_helpers.styl b/stylus_helpers.styl index f8db4bf..8229b07 100644 --- a/stylus_helpers.styl +++ b/stylus_helpers.styl @@ -447,3 +447,116 @@ wfpl_columns(hash) } top.width = wfpl_columns_helper(top, hash, '', null, null) return top + +// internal helper +_pct_pos(offset, width, sheet_width) + if width is sheet_width + return 0 + ratio = offset / (sheet_width - width) + if ratio is 0 + return 0 + return unit(ratio * 100, '%') + +// wfpl_spritesheets documentation/example: +// +// wfpl_spritesheets({ +// main: { +// image: sha1['images/sprites.min.svg'] +// y_origin: 'bottom' // invert y coordinates below (thx inkscape) +// w: 200 // width of document (whatever units) +// h: 400 // height of document (whatever units) +// sprites: { +// ".icon": { +// y: 399 // top (regardless of y_origin) +// w: 48 // width of sprite (in doc coords) +// h: 48 // height of sprite (in doc coords) +// gap: 2 // space _between_ rows/columns +// hover: 'right' // can be 'right' or 'down', meaning: direction to +// // move in spritesheet to find the ":hover" graphic +// column: 'three' 'four' 'five' 'six' // key can be 'column' or 'row' +// // values are postfix for class names +// } +// ".logo": { +// y: 100 +// w: 200 +// h: 50 +// } +// } +// } +// }) +// +// HTML: +//