Skip to content

Commit 47373f5

Browse files
kizunotslang
authored andcommitted
Changing the vendorize for gradients, border-images and transtions to external js function instead of buggy Stylus hacks, fixes #94
1 parent 5841522 commit 47373f5

File tree

3 files changed

+16
-83
lines changed

3 files changed

+16
-83
lines changed

lib/nib/gradients.styl

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ linear-gradient(start, stops...)
9595
// add-property(prop, replace(val, '__CALL__', img))
9696
// start = start[1]
9797

98-
stops = normalize-stops(stops)
99-
stops = join-stops(stops, std-stop)
100-
'linear-gradient(%s, %s)' % (start stops)
98+
unquote('linear-gradient(' + join(', ',arguments) + ')')
10199

102100
/*
103101
* Create a linear gradient image with the given start position

lib/nib/vendor.styl

+5-79
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,6 @@
66

77
no-wrap = unquote('nowrap')
88

9-
/*
10-
* Helper to find out is the list of arguments have commas
11-
*/
12-
13-
is-comma-list()
14-
return match('\), \(', ''+arguments)
15-
16-
/*
17-
* Helper to find out if a given value is a width
18-
*/
19-
20-
is-width(val)
21-
if auto == val
22-
return true
23-
else if val && 'unit' == type(val)
24-
// Stylus does not short circuit so we need to perform this as a distinct
25-
// operation to prevent errors
26-
return '' != unit(val)
27-
return false
28-
29-
/*
30-
* Literal joining
31-
*/
32-
33-
literal-join(string, literals)
34-
result = unquote('')
35-
first = true
36-
for args in literals
37-
subresult = unquote('')
38-
for arg in args
39-
subresult = subresult arg
40-
if first
41-
result = subresult
42-
first = false
43-
else
44-
result = s('%s%s%s', result, unquote(string), subresult)
45-
return result
46-
47-
/*
48-
* Modify matched arguments
49-
* set strict to false to check as “begin with”
50-
*/
51-
52-
modify-args(args, argument, prefix = '', postfix = '', replace = false, strict = true)
53-
result = ()
54-
argument = unquote(argument) if type(argument) == 'string'
55-
prefix = unquote(prefix)
56-
postfix = unquote(postfix)
57-
58-
// Checking if there are values divided by comma
59-
if is-comma-list(args)
60-
for subargs in args
61-
subresult = ()
62-
for arg in subargs
63-
if (arg == argument and strict) or (match(''+s('%s',argument),''+arg) and !strict)
64-
arg = s('%s%s%s', prefix, replace ? replace : arg, postfix)
65-
push(subresult, arg) if arg != unquote('')
66-
subresult = literal-join(' ', subresult) if length(subresult) > 1
67-
push(result, subresult)
68-
result = literal-join(', ', result)
69-
else
70-
for arg in args
71-
if (arg == argument and strict) or (match(''+s('%s',argument),''+arg) and !strict)
72-
arg = s('%s%s%s', prefix, replace ? replace : arg, postfix)
73-
push(result, arg) if arg != unquote('')
74-
return result
75-
76-
remove-args(args, argument, strict = true)
77-
return modify-args(args, argument, replace: unquote(''), strict: strict)
78-
799
/*
8010
* Vendor support for the given prop / arguments,
8111
* optionally specifying the only prefixes to utilize,
@@ -91,22 +21,18 @@ vendor(prop, args, only = null, ignore = null, vendor-property = true)
9121
newargs = args
9222

9323
// Transforms in transitions need the prefixes
94-
if prop in ('transition' 'transition-property')
95-
newargs = modify-args(newargs, transform, '-' + prefix + '-')
96-
97-
// Adding prefixes for gradients
98-
if prop in ('border-image' 'background' 'background-image' 'cursor' 'list-style' 'list-style-image')
99-
newargs = modify-args(newargs, "-gradient\(", '-' + prefix + '-', strict: false)
24+
// if prop in ('transition' 'transition-property')
25+
// newargs = modify-args(newargs, transform, '-' + prefix + '-')
10026

10127
// Removing the `fill` from prefixed border-images
102-
if prop in ('border-image' 'border-image-slice')
103-
newargs = remove-args(newargs, fill)
28+
// if prop in ('border-image' 'border-image-slice')
29+
// newargs = remove-args(newargs, fill)
10430

10531
newprop = prop
10632
newprop = '-' + prefix + '-' + prop if vendor-property
10733
// TODO: make the adjustments for differences
10834
// between the official syntax and vendor ones
109-
{newprop}: vendorize(newargs)
35+
{newprop}: vendorize(prop,('%s' % args),prefix)
11036

11137
/*
11238
* Vendorize the given value.

lib/nodes/vendor-helpers.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var stylus = require('stylus')
1111
* Expose `vendorize`.
1212
*/
1313

14-
module.exports = function(value) {
14+
module.exports = function(property,value,prefix) {
1515
var result = value.toString();
1616

1717
if (result.indexOf('gradient(') > -1) {
@@ -29,6 +29,15 @@ module.exports = function(value) {
2929
}
3030
return result;
3131
});
32+
result = result.replace(/((repeating-)?(linear|radial)-gradient\()/g,'-' + prefix + '-$1');
33+
}
34+
35+
if (property == "'transition'" || property == "'transition-property'") {
36+
result = result.replace(/\b(transform)\b/g,'-' + prefix + '-$1');
37+
}
38+
39+
if (property == "'border-image'" || property == "'border-image-slice'") {
40+
result = result.replace(/\b(fill)\b/g,'');
3241
}
3342

3443
return new nodes.Ident(result);

0 commit comments

Comments
 (0)