1 | import { __decorate } from "tslib";
|
2 | import { singleton } from 'mana-syringe';
|
3 | import { UnitType, CSSUnitValue } from '../cssom';
|
4 | import { parseLengthOrPercentage, mergeDimensions } from '../parser';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var CSSPropertyLengthOrPercentage =
|
10 |
|
11 | function () {
|
12 | function CSSPropertyLengthOrPercentage() {
|
13 | this.parser = parseLengthOrPercentage;
|
14 | this.mixer = mergeDimensions;
|
15 | }
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | CSSPropertyLengthOrPercentage.prototype.calculator = function (name, oldParsed, computed, object, registry) {
|
25 | if (CSSUnitValue.isRelativeUnit(computed.unit)) {
|
26 | if (computed.unit === UnitType.kPercentage) {
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | return new CSSUnitValue(0, 'px');
|
43 | } else if (computed.unit === UnitType.kEms) {
|
44 |
|
45 | return new CSSUnitValue(0, 'px');
|
46 | }
|
47 | } else {
|
48 |
|
49 |
|
50 |
|
51 | return computed.clone();
|
52 | }
|
53 | };
|
54 |
|
55 | CSSPropertyLengthOrPercentage.prototype.nameToBoundsIndex = function (name) {
|
56 | if (name === 'x' || name === 'cx' || name === 'width') {
|
57 | return 0;
|
58 | } else if (name === 'y' || name === 'cy' || name === 'height') {
|
59 | return 1;
|
60 | }
|
61 |
|
62 | return 2;
|
63 | };
|
64 |
|
65 | CSSPropertyLengthOrPercentage.prototype.calculateUsedValueWithParentBounds = function (object, name) {
|
66 | var bounds = object.parentElement.getGeometryBounds();
|
67 | var computedValue = object.computedStyle[name].value;
|
68 | return new CSSUnitValue(bounds.halfExtents[this.nameToBoundsIndex(name)] * 2 * computedValue / 100, 'px');
|
69 | };
|
70 |
|
71 | CSSPropertyLengthOrPercentage = __decorate([singleton()], CSSPropertyLengthOrPercentage);
|
72 | return CSSPropertyLengthOrPercentage;
|
73 | }();
|
74 |
|
75 | export { CSSPropertyLengthOrPercentage }; |
\ | No newline at end of file |