| 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, testing) { | |
| 16 | |
| 17 function numberToString(x) { | |
| 18 return x.toFixed(3).replace('.000', ''); | |
| 19 } | |
| 20 | |
| 21 function clamp(min, max, x) { | |
| 22 return Math.min(max, Math.max(min, x)); | |
| 23 } | |
| 24 | |
| 25 function parseNumber(string) { | |
| 26 if (/^\s*[-+]?(\d*\.)?\d+\s*$/.test(string)) | |
| 27 return Number(string); | |
| 28 } | |
| 29 | |
| 30 function mergeNumbers(left, right) { | |
| 31 return [left, right, numberToString]; | |
| 32 } | |
| 33 | |
| 34 // FIXME: This should probably go in it's own handler. | |
| 35 function mergeFlex(left, right) { | |
| 36 if (left == 0) | |
| 37 return; | |
| 38 return clampedMergeNumbers(0, Infinity)(left, right); | |
| 39 } | |
| 40 | |
| 41 function mergePositiveIntegers(left, right) { | |
| 42 return [left, right, function(x) { | |
| 43 return Math.round(clamp(1, Infinity, x)); | |
| 44 }]; | |
| 45 } | |
| 46 | |
| 47 function clampedMergeNumbers(min, max) { | |
| 48 return function(left, right) { | |
| 49 return [left, right, function(x) { | |
| 50 return numberToString(clamp(min, max, x)); | |
| 51 }]; | |
| 52 }; | |
| 53 } | |
| 54 | |
| 55 function round(left, right) { | |
| 56 return [left, right, Math.round]; | |
| 57 } | |
| 58 | |
| 59 scope.clamp = clamp; | |
| 60 scope.addPropertiesHandler(parseNumber, clampedMergeNumbers(0, Infinity), ['bo
rder-image-width', 'line-height']); | |
| 61 scope.addPropertiesHandler(parseNumber, clampedMergeNumbers(0, 1), ['opacity',
'shape-image-threshold']); | |
| 62 scope.addPropertiesHandler(parseNumber, clampedMergeNumbers(0.01, Infinity), [
'zoom']); | |
| 63 scope.addPropertiesHandler(parseNumber, mergeFlex, ['flex-grow', 'flex-shrink'
]); | |
| 64 scope.addPropertiesHandler(parseNumber, mergeNumbers, ['zoom']); | |
| 65 scope.addPropertiesHandler(parseNumber, mergePositiveIntegers, ['orphans', 'wi
dows']); | |
| 66 scope.addPropertiesHandler(parseNumber, round, ['z-index']); | |
| 67 | |
| 68 scope.parseNumber = parseNumber; | |
| 69 scope.mergeNumbers = mergeNumbers; | |
| 70 scope.numberToString = numberToString; | |
| 71 | |
| 72 })(webAnimations1, webAnimationsTesting); | |
| OLD | NEW |