| 1518 | }); |
| 1519 | |
| 1520 | function clamp(value, prop, allowEmpty) { |
| 1521 | var type = propTypes[prop.type] || {}; |
| 1522 | |
| 1523 | if (value == null) { |
| 1524 | return (allowEmpty || !prop.def) ? null : prop.def; |
| 1525 | } |
| 1526 | |
| 1527 | // ~~ is an short way of doing floor for positive numbers |
| 1528 | value = type.floor ? ~~value : parseFloat(value); |
| 1529 | |
| 1530 | // IE will pass in empty strings as value for alpha, |
| 1531 | // which will hit this case |
| 1532 | if (isNaN(value)) { |
| 1533 | return prop.def; |
| 1534 | } |
| 1535 | |
| 1536 | if (type.mod) { |
| 1537 | // We add mod before modding to make sure that negatives values |
| 1538 | // get converted properly: -10 -> 350 |
| 1539 | return (value + type.mod) % type.mod; |
| 1540 | } |
| 1541 | |
| 1542 | // For now all property types without mod have min and max |
| 1543 | return 0 > value ? 0 : type.max < value ? type.max : value; |
| 1544 | } |
| 1545 | |
| 1546 | function stringParse(string) { |
| 1547 | var inst = color(), |