1 | import { __decorate } from "tslib";
|
2 | import { singleton } from 'mana-syringe';
|
3 | import { GeometryAABBUpdater } from './interfaces';
|
4 | import { Shape } from '../../types';
|
5 | import { CSSUnitValue, UnitType } from '../../css';
|
6 | import { isString } from '../../utils';
|
7 |
|
8 | var RectUpdater =
|
9 |
|
10 | function () {
|
11 | function RectUpdater() {}
|
12 |
|
13 | RectUpdater.prototype.update = function (parsedStyle, object) {
|
14 | var img = parsedStyle.img,
|
15 | width = parsedStyle.width,
|
16 | height = parsedStyle.height;
|
17 | var contentWidth = 0;
|
18 | var contentHeight = 0;
|
19 |
|
20 | if (width instanceof CSSUnitValue) {
|
21 | if (width.unit === UnitType.kPixels) {
|
22 | contentWidth = width.value;
|
23 | }
|
24 | }
|
25 |
|
26 | if (height instanceof CSSUnitValue) {
|
27 | if (height.unit === UnitType.kPixels) {
|
28 | contentHeight = height.value;
|
29 | }
|
30 | }
|
31 |
|
32 |
|
33 | if (img && !isString(img)) {
|
34 | if (!contentWidth) {
|
35 | contentWidth = img.width;
|
36 | }
|
37 |
|
38 | if (!contentHeight) {
|
39 | contentHeight = img.height;
|
40 | }
|
41 | }
|
42 |
|
43 | if (width instanceof CSSUnitValue) {
|
44 | width.value = contentWidth;
|
45 | }
|
46 |
|
47 | if (height instanceof CSSUnitValue) {
|
48 | height.value = contentHeight;
|
49 | }
|
50 |
|
51 | return {
|
52 | width: contentWidth,
|
53 | height: contentHeight
|
54 | };
|
55 | };
|
56 |
|
57 | RectUpdater = __decorate([singleton({
|
58 | token: [{
|
59 | token: GeometryAABBUpdater,
|
60 | named: Shape.RECT
|
61 | }, {
|
62 | token: GeometryAABBUpdater,
|
63 | named: Shape.IMAGE
|
64 | }, {
|
65 | token: GeometryAABBUpdater,
|
66 | named: Shape.GROUP
|
67 | }]
|
68 | })], RectUpdater);
|
69 | return RectUpdater;
|
70 | }();
|
71 |
|
72 | export { RectUpdater }; |
\ | No newline at end of file |