OLD | NEW |
| (Empty) |
1 // Copyright 2014 Google Inc. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 (function(scope) { | |
16 | |
17 function consumeShadow(string) { | |
18 var shadow = { | |
19 inset: false, | |
20 lengths: [], | |
21 color: null, | |
22 }; | |
23 function consumePart(string) { | |
24 var result = scope.consumeToken(/^inset/i, string); | |
25 if (result) { | |
26 shadow.inset = true; | |
27 return result; | |
28 } | |
29 var result = scope.consumeLengthOrPercent(string); | |
30 if (result) { | |
31 shadow.lengths.push(result[0]); | |
32 return result; | |
33 } | |
34 var result = scope.consumeColor(string); | |
35 if (result) { | |
36 shadow.color = result[0]; | |
37 return result; | |
38 } | |
39 } | |
40 var result = scope.consumeRepeated(consumePart, /^/, string); | |
41 if (result && result[0].length) { | |
42 return [shadow, result[1]]; | |
43 } | |
44 } | |
45 | |
46 function parseShadowList(string) { | |
47 var result = scope.consumeRepeated(consumeShadow, /^,/, string); | |
48 if (result && result[1] == '') { | |
49 return result[0]; | |
50 } | |
51 } | |
52 | |
53 function mergeShadow(left, right) { | |
54 while (left.lengths.length < Math.max(left.lengths.length, right.lengths.len
gth)) | |
55 left.lengths.push({px: 0}); | |
56 while (right.lengths.length < Math.max(left.lengths.length, right.lengths.le
ngth)) | |
57 right.lengths.push({px: 0}); | |
58 | |
59 if (left.inset != right.inset || !!left.color != !!right.color) { | |
60 return; | |
61 } | |
62 var lengthReconstitution = []; | |
63 var colorReconstitution; | |
64 var matchingLeft = [[], 0]; | |
65 var matchingRight = [[], 0]; | |
66 for (var i = 0; i < left.lengths.length; i++) { | |
67 var mergedDimensions = scope.mergeDimensions(left.lengths[i], right.length
s[i], i == 2); | |
68 matchingLeft[0].push(mergedDimensions[0]); | |
69 matchingRight[0].push(mergedDimensions[1]); | |
70 lengthReconstitution.push(mergedDimensions[2]); | |
71 } | |
72 if (left.color && right.color) { | |
73 var mergedColor = scope.mergeColors(left.color, right.color); | |
74 matchingLeft[1] = mergedColor[0]; | |
75 matchingRight[1] = mergedColor[1]; | |
76 colorReconstitution = mergedColor[2]; | |
77 } | |
78 return [matchingLeft, matchingRight, function(value) { | |
79 var result = left.inset ? 'inset ' : ' '; | |
80 for (var i = 0; i < lengthReconstitution.length; i++) { | |
81 result += lengthReconstitution[i](value[0][i]) + ' '; | |
82 } | |
83 if (colorReconstitution) { | |
84 result += colorReconstitution(value[1]); | |
85 } | |
86 return result; | |
87 }]; | |
88 } | |
89 | |
90 function mergeNestedRepeatedShadow(nestedMerge, separator, left, right) { | |
91 var leftCopy = []; | |
92 var rightCopy = []; | |
93 function defaultShadow(inset) { | |
94 return {inset: inset, color: [0, 0, 0, 0], lengths: [{px: 0}, {px: 0}, {px
: 0}, {px: 0}]}; | |
95 } | |
96 for (var i = 0; i < left.length || i < right.length; i++) { | |
97 var l = left[i] || defaultShadow(right[i].inset); | |
98 var r = right[i] || defaultShadow(left[i].inset); | |
99 leftCopy.push(l); | |
100 rightCopy.push(r); | |
101 } | |
102 return scope.mergeNestedRepeated(nestedMerge, separator, leftCopy, rightCopy
); | |
103 } | |
104 | |
105 var mergeShadowList = mergeNestedRepeatedShadow.bind(null, mergeShadow, ', '); | |
106 scope.addPropertiesHandler(parseShadowList, mergeShadowList, ['box-shadow', 't
ext-shadow']); | |
107 | |
108 })(webAnimations1); | |
OLD | NEW |