1 // This program is in the public domain within the United States. Additionally,
2 // we waive copyright and related rights in the work worldwide through the CC0
3 // 1.0 Universal public domain dedication, which can be found at
4 // http://creativecommons.org/publicdomain/zero/1.0/
6 // This file contains helpers for using stylus in your project.
8 // Put something like this in your styl.styl:
9 // @require 'inc/wfpl/stylus-helpers.styl'
12 // set units to px if it doesn't have a unit already
14 unit(i) == '' ? unit(i, px) : i
16 // transparently support vender-specific tags
18 -webkit-border-radius: arguments
19 border-radius: arguments
21 -webkit-box-shadow: arguments
24 -webkit-box-sizing: arguments
25 -moz-box-sizing: arguments
28 -webkit-user-select: arguments
29 -moz-user-select: arguments
30 -ms-user-select: arguments
31 user-select: arguments
33 // map "whitespace:" to "white-space:"
35 white-space: arguments
39 position: unquote(type)
40 for i in (0...length(args))
41 if not args[i] is a 'unit'
42 {args[i]}: args[i + 1] is a 'unit' ? args[i + 1] : 0
44 // you can pass directions and units, or just directions. Examples:
45 // absolute: top 20px left 0
49 _pos('absolute', arguments)
51 _pos('fixed', arguments)
53 _pos('relative', arguments)
55 // Specify width and height on the same line
60 // generate (return) a "calc(Fpx + R%)" to scale linearly with parent
62 // pb: pixel width of parent (when biggest)
63 // ps: pixel width of parent (when smallest)
64 // cb: pixel width of child (when biggest)
65 // cs: pixel width of child (when smallest)
66 linear_scale_calc(pb, ps, cb, cs)
67 // math explained: (figuring out F and R in calc(Fpx + R%))
68 // f + r * pb = cb // known_1: formula(pb) -> cb
69 // f = cb - r * pb // solve_for_f: subtract (r * pb) from both sides
70 // f + r * ps = cs // known_2: formula(pb) -> cb
71 // cb - r * pb + r * ps = cs // substitute solved_for_f into known_2
72 // -r * pb + r * ps = cs - cb // subtract cb from both sides
73 // r * (-pb + ps) = cs - cb // factor out r from left side
74 // r = (cs - cb) / (-pb + ps) // divide both sides by (-pb + ps)
75 // r = (cb - cs) / (pb - ps) // multiply left side by -1/-1
76 r = (cb - cs) / (pb - ps)
78 unquote("calc(" + unit(f, "px") + ' + ' + unit(100 * r, "%") + ")")
80 // Make children of this element inline-blocks that are spaced evenly accross.
82 // To create a minimum distance between: don't use word-spacing, it's broken in
83 // firefox. Instead, try padding on the children and negative margin on the
85 space_evenly(line_height = 1.2em)
89 relative: top line_height
94 margin-bottom: -(line_height)
100 // image layout: left column has normal, right column hover versions
102 // arguments: width/height are pixel dimensions of a single sprite
104 // markup: put classes n1, n2, etc on the items.
111 // <li class="n0">home</li>
112 // <li class="n1">contact</li>
117 // sprites_rollover "images/nav.png" 150 35 2
118 sprites_rollover(image, width, height, count, v_offset = 0, h_offset = 0)
119 width: unit(width, px)
120 height: unit(height, px)
122 background: url(image[0])
123 background: url(image[1]), linear-gradient(transparent, transparent);
125 background-image: url(image)
126 background-position: top left
127 background-repeat: no-repeat;
130 y = - (@height * n) - unit(v_offset, px)
131 background-position: (0 - unit(h_offset, px)) y
133 background-position: (0 - unit(h_offset, px) - @width) y
134 sprite_rollover(image, width, height, v_offset = 0, h_offset = 0)
135 sprites_rollover(image, width, height, 1, v_offset, h_offset)
137 // see sprites_rollover
138 sprites(image, height, count, v_offset = 0, h_offset = 0)
139 height: unit(height, px)
141 background: url(image[0])
142 background: url(image[1]), linear-gradient(transparent, transparent);
144 background-image: url(image)
145 background-position: top left
146 background-repeat: no-repeat;
149 y = - (@height * n) - unit(v_offset, px)
150 background-position: (0 - unit(h_offset, px)) y
151 sprite(image, height, v_offset = 0, h_offset = 0)
152 sprites(image, height, 1, v_offset, h_offset)
154 // Styling for a variable height element with an image background where the
155 // middle repeats vertically. You must split your image into three images, and
156 // name them with "-top", "-mid" and "-bot" suffixes (right before the file
157 // extension.) then pass a filepath as the first argument to this function
158 // which does not have a suffix.
163 // i/foo-top.png (900x20)
164 // i/foo-mid.png (900xwhatever)
165 // i/foo-bot.png (900x30)
167 // dom layout: <div id="expando"><div><div><div>...</div></div></div></div>
172 // mangin: 10px auto;
174 // background_vertical_stretch("i/foo.png", 20, 30)
178 // You can (optionally) pass 1-4 additional arguments which
179 // (effectively) add padding to the inner most div. The default is to
180 // have the height and width of the inner div match exactly the outer
181 // one. Parameters you specify are relative to that (not the section
182 // filled with the "-mid" image).
183 background_vertical_stretch(image, top_height, bottom_height, top_pad = 0, right_pad = top_pad, bottom_pad = top_pad, left_pad = right_pad)
184 top_height = _px(top_height)
185 bottom_height = _px(bottom_height)
186 top_pad = _px(top_pad)
187 right_pad = _px(right_pad)
188 bottom_pad = _px(bottom_pad)
189 left_pad = _px(left_pad)
191 path = pathjoin(dirname(image), basename(image, ext))
193 // bottom image (outermost block)
194 background: transparent url(path + '-bot' + ext)
195 padding-bottom: bottom_height + 1 // +1 to prevent margin collapsing
197 background: transparent url(path + '-top' + ext) 0 0 no-repeat
198 padding-top: top_height + 1 // +1 to prevent margin collapsing
200 background: transparent url(path + '-mid' + ext) 0 0 repeat-y;
201 margin-top: -1px; // correct for above +1 from top
202 margin-bottom: -1px; // correct for above +1 from bottom
203 padding: 1px; // to prevent margin collapsing
205 // all "2px" below are to correct for 1px above padding and below
207 margin-top: 2px - top_height + top_pad
208 margin-left: left_pad - 2px
209 margin-right: right_pad - 2px
210 margin-bottom: 2px - bottom_height + bottom_pad
211 background: transparent;
223 &::-webkit-input-placeholder
225 &:-moz-placeholder // firefox 4-18
227 &::-moz-placeholder // firefox 19+
229 &:-ms-input-placeholder // ie
236 -webkit-touch-callout: none
237 -webkit-user-select: none
238 -khtml-user-select: none
239 -moz-user-select: none
240 -ms-user-select: none