| OLD | NEW |
| (Empty) | |
| 1 /** |
| 2 * Class representing a |
| 3 * [length measurement](https://developer.mozilla.org/en-US/docs/Web/CSS/length) |
| 4 * in CSS. |
| 5 */ |
| 6 @Experimental() |
| 7 class Dimension { |
| 8 num _value; |
| 9 String _unit; |
| 10 |
| 11 /** Set this CSS Dimension to a percentage `value`. */ |
| 12 Dimension.percent(this._value) : _unit = '%'; |
| 13 |
| 14 /** Set this CSS Dimension to a pixel `value`. */ |
| 15 Dimension.px(this._value) : _unit = 'px'; |
| 16 |
| 17 /** Set this CSS Dimension to a pica `value`. */ |
| 18 Dimension.pc(this._value) : _unit = 'pc'; |
| 19 |
| 20 /** Set this CSS Dimension to a point `value`. */ |
| 21 Dimension.pt(this._value) : _unit = 'pt'; |
| 22 |
| 23 /** Set this CSS Dimension to an inch `value`. */ |
| 24 Dimension.inch(this._value) : _unit = 'in'; |
| 25 |
| 26 /** Set this CSS Dimension to a centimeter `value`. */ |
| 27 Dimension.cm(this._value) : _unit = 'cm'; |
| 28 |
| 29 /** Set this CSS Dimension to a millimeter `value`. */ |
| 30 Dimension.mm(this._value) : _unit = 'mm'; |
| 31 |
| 32 /** |
| 33 * Set this CSS Dimension to the specified number of ems. |
| 34 * |
| 35 * 1em is equal to the current font size. (So 2ems is equal to double the font |
| 36 * size). This is useful for producing website layouts that scale nicely with |
| 37 * the user's desired font size. |
| 38 */ |
| 39 Dimension.em(this._value) : _unit = 'em'; |
| 40 |
| 41 /** |
| 42 * Set this CSS Dimension to the specified number of x-heights. |
| 43 * |
| 44 * One ex is equal to the the x-height of a font's baseline to its mean line, |
| 45 * generally the height of the letter "x" in the font, which is usually about |
| 46 * half the font-size. |
| 47 */ |
| 48 Dimension.ex(this._value) : _unit = 'ex'; |
| 49 |
| 50 /** |
| 51 * Construct a Dimension object from the valid, simple CSS string `cssValue` |
| 52 * that represents a distance measurement. |
| 53 * |
| 54 * This constructor is intended as a convenience method for working with |
| 55 * simplistic CSS length measurements. Non-numeric values such as `auto` or |
| 56 * `inherit` or invalid CSS will cause this constructor to throw a |
| 57 * FormatError. |
| 58 */ |
| 59 Dimension.css(String cssValue) { |
| 60 if (cssValue == '') cssValue = '0px'; |
| 61 if (cssValue.endsWith('%')) { |
| 62 _unit = '%'; |
| 63 } else { |
| 64 _unit = cssValue.substring(cssValue.length - 2); |
| 65 } |
| 66 if (cssValue.contains('.')) { |
| 67 _value = double.parse(cssValue.substring(0, |
| 68 cssValue.length - _unit.length)); |
| 69 } else { |
| 70 _value = int.parse(cssValue.substring(0, cssValue.length - _unit.length)); |
| 71 } |
| 72 } |
| 73 |
| 74 /** Print out the CSS String representation of this value. */ |
| 75 String toString() { |
| 76 return '${_value}${_unit}'; |
| 77 } |
| 78 |
| 79 /** Return a unitless, numerical value of this CSS value. */ |
| 80 num get value => this._value; |
| 81 } |
| OLD | NEW |