1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 52431× 52431× 52431× 1× 228041× 228041× 228041× 220211× 489684× 489684× 71904× 65896× 65896× 417780× 417780× 489684× 489684× 123812× 489684× 489684× 489684× 489684× 62951× 62951× 62666× 427018× 411585× 220080× 191505× 220211× 220080× 220080× 220080× 220080× 220080× 228041× 228041× 228041× 228041× 228041× 228041× 1× 153261× 153261× 149778× 149778× 149778× 372351× 372351× 239130× 239130× 3703× 239130× 239130× 239130× 239130× 239130× 239130× 162593× 162593× 68799× 68799× 239130× 76537× 76537× 162593× 239130× 239130× 372351× 838× 371513× 37740× 37740× 333773× 327765× 327765× 153261× 153261× 153261× 153261× 1× 76537× 1938× 1938× 19× 19× 74580× 74580× 76537× 58× 58× 1947× 1947× 74532× 74532× 76537× 1× 162593× 162593× 162593× 96326× 96326× 66072× 66072× 172× 172× 162593× 94028× 94028× 66312× 66312× 2230× 2230× 162593× 1× 1× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); define(["require", "exports", "./container", "../../utility/base-util", "../../enum/enum", "../../primitives/size", "../../primitives/rect", "../elements/text-element"], function (require, exports, container_1, base_util_1, enum_1, size_1, rect_1, text_element_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Canvas = (function (_super) { __extends(Canvas, _super); function Canvas() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.measureChildren = undefined; return _this; } Canvas.prototype.measure = function (availableSize, id, callback) { var desired = undefined; var desiredBounds = undefined; if (this.hasChildren()) { for (var _i = 0, _a = this.children; _i < _a.length; _i++) { var child = _a[_i]; if (child instanceof text_element_1.TextElement) { if (child.canMeasure) { availableSize.width = availableSize.width || this.maxWidth || this.minWidth; child.measure(availableSize); } } else Eif (!(child instanceof text_element_1.TextElement)) { child.measure(availableSize, id, callback); } var childSize = child.desiredSize.clone(); if (child.rotateAngle !== 0) { childSize = base_util_1.rotateSize(childSize, child.rotateAngle); } var right = childSize.width + child.margin.right; var bottom = childSize.height + child.margin.bottom; var childBounds = new rect_1.Rect(child.margin.left, child.margin.top, right, bottom); if (child.float) { var position = child.getAbsolutePosition(childSize); if (position !== undefined) { continue; } } if ((!(child instanceof text_element_1.TextElement)) || (child instanceof text_element_1.TextElement && child.canConsiderBounds)) { if (desiredBounds === undefined) { desiredBounds = childBounds; } else { desiredBounds.uniteRect(childBounds); } } } if (desiredBounds) { var leftMargin = 0; var topMargin = 0; leftMargin = Math.max(desiredBounds.left, 0); topMargin = Math.max(desiredBounds.top, 0); desired = new size_1.Size(desiredBounds.width + leftMargin, desiredBounds.height + topMargin); } } desired = _super.prototype.validateDesiredSize.call(this, desired, availableSize); _super.prototype.stretchChildren.call(this, desired); desired.width += this.padding.left + this.padding.right; desired.height += this.padding.top + this.padding.bottom; this.desiredSize = desired; return desired; }; Canvas.prototype.arrange = function (desiredSize, isStack) { this.outerBounds = new rect_1.Rect(); if (this.hasChildren()) { var y = this.offsetY - desiredSize.height * this.pivot.y + this.padding.top; var x = this.offsetX - desiredSize.width * this.pivot.x + this.padding.left; for (var _i = 0, _a = this.children; _i < _a.length; _i++) { var child = _a[_i]; if ((child.transform & enum_1.Transform.Parent) !== 0) { child.parentTransform = this.parentTransform + this.rotateAngle; if (this.flip !== 'None' || this.elementActions & enum_1.ElementAction.ElementIsGroup) { child.parentTransform = ((this.flip === 'Horizontal' || this.flip === 'Vertical') && (!(child instanceof text_element_1.TextElement && (this.flipMode === 'Port' || this.flipMode === 'Label' || this.flipMode === 'PortAndLabel' || this.flipMode === 'None')))) ? -child.parentTransform : child.parentTransform; } var childSize = child.desiredSize.clone(); var topLeft = void 0; var center = { x: 0, y: 0 }; var childX = x; var childY = y; if (child.relativeMode === 'Point') { var position = child.getAbsolutePosition(desiredSize); if (position !== undefined) { childX += position.x; childY += position.y; } } if (child.relativeMode === 'Object') { topLeft = this.alignChildBasedOnParent(child, childSize, desiredSize, childX, childY); child.flip = this.flip; } else { topLeft = this.alignChildBasedOnaPoint(child, childX, childY); } center = { x: topLeft.x + childSize.width / 2, y: topLeft.y + childSize.height / 2 }; _super.prototype.findChildOffsetFromCenter.call(this, child, center); } if (isStack && (child.horizontalAlignment === 'Stretch' || child.verticalAlignment === 'Stretch')) { child.arrange(desiredSize); } else { if (child instanceof text_element_1.TextElement && child.canMeasure) { child.arrange(child.desiredSize); this.outerBounds.uniteRect(child.outerBounds); } else if (!(child instanceof text_element_1.TextElement)) { child.arrange(child.desiredSize); this.outerBounds.uniteRect(child.outerBounds); } } } } this.actualSize = desiredSize; this.updateBounds(); this.outerBounds.uniteRect(this.bounds); return desiredSize; }; Canvas.prototype.alignChildBasedOnParent = function (child, childSize, parentSize, x, y) { switch (child.horizontalAlignment) { case 'Auto': case 'Left': x += child.margin.left; break; case 'Right': x += parentSize.width - childSize.width - child.margin.right; break; case 'Stretch': case 'Center': x += parentSize.width / 2 - childSize.width / 2; break; } switch (child.verticalAlignment) { case 'Auto': case 'Top': y += child.margin.top; break; case 'Bottom': y += parentSize.height - childSize.height - child.margin.bottom; break; case 'Stretch': case 'Center': y += parentSize.height / 2 - childSize.height / 2; break; } return { x: x, y: y }; }; Canvas.prototype.alignChildBasedOnaPoint = function (child, x, y) { x += child.margin.left - child.margin.right; y += child.margin.top - child.margin.bottom; switch (child.horizontalAlignment) { case 'Auto': case 'Left': x = child.inversedAlignment ? x : (x - child.desiredSize.width); break; case 'Stretch': case 'Center': x -= child.desiredSize.width * child.pivot.x; break; case 'Right': x = child.inversedAlignment ? (x - child.desiredSize.width) : x; break; } switch (child.verticalAlignment) { case 'Auto': case 'Top': y = child.inversedAlignment ? y : (y - child.desiredSize.height); break; case 'Stretch': case 'Center': y -= child.desiredSize.height * child.pivot.y; break; case 'Bottom': y = child.inversedAlignment ? (y - child.desiredSize.height) : y; break; } return { x: x, y: y }; }; return Canvas; }(container_1.Container)); exports.Canvas = Canvas; }); |