Skip to content

Commit d25ff49

Browse files
committed
strokeDasharray
1 parent a9b7235 commit d25ff49

6 files changed

+39
-5
lines changed

src/number-handler.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(function(scope, testing) {
1717

1818
function numberToString(x) {
19-
return x.toFixed(3).replace('.000', '');
19+
return x.toFixed(3).replace(/0+$/, '').replace(/\.$/, '');
2020
}
2121

2222
function clamp(min, max, x) {
@@ -53,11 +53,37 @@
5353
};
5454
}
5555

56+
function parseNumberList(string) {
57+
var items = string.trim().split(/\s*[\s,]\s*/);
58+
if (items.length === 0) {
59+
return;
60+
}
61+
var result = [];
62+
for (var i = 0; i < items.length; i++) {
63+
var number = parseNumber(items[i]);
64+
if (number === undefined) {
65+
return;
66+
}
67+
result.push(number);
68+
}
69+
return result;
70+
}
71+
72+
function mergeNumberLists(left, right) {
73+
if (left.length != right.length) {
74+
return;
75+
}
76+
return [left, right, function(numberList) {
77+
return numberList.map(numberToString).join(' ');
78+
}];
79+
}
80+
5681
function round(left, right) {
5782
return [left, right, Math.round];
5883
}
5984

6085
scope.clamp = clamp;
86+
scope.addPropertiesHandler(parseNumberList, mergeNumberLists, ['stroke-dasharray']);
6187
scope.addPropertiesHandler(parseNumber, clampedMergeNumbers(0, Infinity), ['border-image-width', 'line-height']);
6288
scope.addPropertiesHandler(parseNumber, clampedMergeNumbers(0, 1), ['opacity', 'shape-image-threshold']);
6389
scope.addPropertiesHandler(parseNumber, mergeFlex, ['flex-grow', 'flex-shrink']);

src/property-interpolation.js

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
paddingRight: '0px',
8080
paddingTop: '0px',
8181
right: 'auto',
82+
strokeDasharray: 'none',
8283
strokeDashoffset: '0px',
8384
textIndent: '0px',
8485
textShadow: '0px 0px 0px transparent',

test/js/box-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ suite('box-handler', function() {
4646
'Round interpolation result');
4747
assert.equal(
4848
webAnimations1.propertyInterpolation('clip', 'rect(10px, 10px, 10px, 10px)', 'rect(20px, 20px, 20px, 20px)')(0.25),
49-
'rect(12.500px, 12.500px, 12.500px, 12.500px)',
49+
'rect(12.5px, 12.5px, 12.5px, 12.5px)',
5050
'Round interpolation result');
5151
assert.equal(
5252
webAnimations1.propertyInterpolation('clip', 'rect(10px, 10%, 10px, 10%)', 'rect(10em, 10px, 10em, 10px)')(0.4),

test/js/color-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ suite('color-handler', function() {
1616
test('color interpolation', function() {
1717
assert.equal(webAnimations1.propertyInterpolation('color', '#00aa11', '#aa00bb')(0.2), 'rgba(34,136,51,1)');
1818
assert.equal(webAnimations1.propertyInterpolation('color', 'transparent', '#004488')(0), 'transparent');
19-
assert.equal(webAnimations1.propertyInterpolation('color', 'transparent', '#004488')(0.5), 'rgba(0,68,136,0.500)');
19+
assert.equal(webAnimations1.propertyInterpolation('color', 'transparent', '#004488')(0.5), 'rgba(0,68,136,0.5)');
2020
assert.equal(webAnimations1.propertyInterpolation('color', 'red', 'green')(2), 'rgba(0,255,0,1)');
2121
assert.equal(webAnimations1.propertyInterpolation('color', 'red', 'green')(-1), 'rgba(255,0,0,1)');
2222
});
@@ -28,6 +28,6 @@ suite('color-handler', function() {
2828
assert.equal(webAnimations1.propertyInterpolation('stroke', '#00fe00', '#180036')(0.5), 'rgba(12,127,27,1)');
2929
});
3030
test('interpolation to/from initial', function() {
31-
assert.equal(webAnimations1.propertyInterpolation('backgroundColor', 'initial', 'red')(0.5), 'rgba(255,0,0,0.500)');
31+
assert.equal(webAnimations1.propertyInterpolation('backgroundColor', 'initial', 'red')(0.5), 'rgba(255,0,0,0.5)');
3232
});
3333
});

test/js/dimension-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ suite('dimension-handler', function() {
4343
assert.equal(webAnimations1.propertyInterpolation('left', '10px', '50px')(0.25), '20px');
4444
assert.equal(webAnimations1.propertyInterpolation('left', '10%', '50%')(0.25), '20%');
4545
assert.equal(webAnimations1.propertyInterpolation('left', '0px', '0.001px')(0.05), '0px');
46-
assert.equal(webAnimations1.propertyInterpolation('left', '0px', '10px')(0.234), '2.340px');
46+
assert.equal(webAnimations1.propertyInterpolation('left', '0px', '10px')(0.234), '2.34px');
4747
assert.equal(webAnimations1.propertyInterpolation('left', '10px', '10em')(0.4), 'calc(6px + 4em)');
4848
assert.equal(webAnimations1.propertyInterpolation('left', '10px', '10%')(0.4), 'calc(6px + 4%)');
4949
assert.equal(webAnimations1.propertyInterpolation('left', 'calc(10px + 5em)', 'calc(20px + 35em)')(0.4), 'calc(14px + 17em)');

test/js/number-handler.js

+7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ suite('number-handler', function() {
1919
assert.equal(webAnimations1.parseNumber(string), tests[string], 'Parsing "' + string + '"');
2020
}
2121
});
22+
test('number list interpolation', function() {
23+
assert.equal(webAnimations1.propertyInterpolation('strokeDasharray', '10', '20')(0.25), '12.5');
24+
assert.equal(webAnimations1.propertyInterpolation('strokeDasharray', '10 100', '20 200')(0.25), '12.5 125');
25+
assert.equal(webAnimations1.propertyInterpolation('strokeDasharray', '10, 100', '20, 200')(0.25), '12.5 125');
26+
assert.equal(webAnimations1.propertyInterpolation('strokeDasharray', '10,100', '20 200')(0.25), '12.5 125');
27+
});
2228
test('invalid numbers fail to parse', function() {
2329
assert.isUndefined(webAnimations1.parseNumber(''));
2430
assert.isUndefined(webAnimations1.parseNumber('nine'));
2531
assert.isUndefined(webAnimations1.parseNumber('1 2'));
2632
assert.isUndefined(webAnimations1.parseNumber('+-0'));
2733
assert.isUndefined(webAnimations1.parseNumber('50px'));
2834
assert.isUndefined(webAnimations1.parseNumber('1.2.3'));
35+
assert.isUndefined(webAnimations1.parseNumberList('10,,20'));
2936
});
3037
test('opacity clamping', function() {
3138
var interpolation = webAnimations1.propertyInterpolation('opacity', '0', '1');

0 commit comments

Comments
 (0)