source: imaps-frontend/node_modules/html2canvas/dist/lib/render/bound-curves.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 5 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 13.6 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.calculatePaddingBoxPath = exports.calculateContentBoxPath = exports.calculateBorderBoxPath = exports.BoundCurves = void 0;
4var length_percentage_1 = require("../css/types/length-percentage");
5var vector_1 = require("./vector");
6var bezier_curve_1 = require("./bezier-curve");
7var BoundCurves = /** @class */ (function () {
8 function BoundCurves(element) {
9 var styles = element.styles;
10 var bounds = element.bounds;
11 var _a = length_percentage_1.getAbsoluteValueForTuple(styles.borderTopLeftRadius, bounds.width, bounds.height), tlh = _a[0], tlv = _a[1];
12 var _b = length_percentage_1.getAbsoluteValueForTuple(styles.borderTopRightRadius, bounds.width, bounds.height), trh = _b[0], trv = _b[1];
13 var _c = length_percentage_1.getAbsoluteValueForTuple(styles.borderBottomRightRadius, bounds.width, bounds.height), brh = _c[0], brv = _c[1];
14 var _d = length_percentage_1.getAbsoluteValueForTuple(styles.borderBottomLeftRadius, bounds.width, bounds.height), blh = _d[0], blv = _d[1];
15 var factors = [];
16 factors.push((tlh + trh) / bounds.width);
17 factors.push((blh + brh) / bounds.width);
18 factors.push((tlv + blv) / bounds.height);
19 factors.push((trv + brv) / bounds.height);
20 var maxFactor = Math.max.apply(Math, factors);
21 if (maxFactor > 1) {
22 tlh /= maxFactor;
23 tlv /= maxFactor;
24 trh /= maxFactor;
25 trv /= maxFactor;
26 brh /= maxFactor;
27 brv /= maxFactor;
28 blh /= maxFactor;
29 blv /= maxFactor;
30 }
31 var topWidth = bounds.width - trh;
32 var rightHeight = bounds.height - brv;
33 var bottomWidth = bounds.width - brh;
34 var leftHeight = bounds.height - blv;
35 var borderTopWidth = styles.borderTopWidth;
36 var borderRightWidth = styles.borderRightWidth;
37 var borderBottomWidth = styles.borderBottomWidth;
38 var borderLeftWidth = styles.borderLeftWidth;
39 var paddingTop = length_percentage_1.getAbsoluteValue(styles.paddingTop, element.bounds.width);
40 var paddingRight = length_percentage_1.getAbsoluteValue(styles.paddingRight, element.bounds.width);
41 var paddingBottom = length_percentage_1.getAbsoluteValue(styles.paddingBottom, element.bounds.width);
42 var paddingLeft = length_percentage_1.getAbsoluteValue(styles.paddingLeft, element.bounds.width);
43 this.topLeftBorderDoubleOuterBox =
44 tlh > 0 || tlv > 0
45 ? getCurvePoints(bounds.left + borderLeftWidth / 3, bounds.top + borderTopWidth / 3, tlh - borderLeftWidth / 3, tlv - borderTopWidth / 3, CORNER.TOP_LEFT)
46 : new vector_1.Vector(bounds.left + borderLeftWidth / 3, bounds.top + borderTopWidth / 3);
47 this.topRightBorderDoubleOuterBox =
48 tlh > 0 || tlv > 0
49 ? getCurvePoints(bounds.left + topWidth, bounds.top + borderTopWidth / 3, trh - borderRightWidth / 3, trv - borderTopWidth / 3, CORNER.TOP_RIGHT)
50 : new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 3, bounds.top + borderTopWidth / 3);
51 this.bottomRightBorderDoubleOuterBox =
52 brh > 0 || brv > 0
53 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - borderRightWidth / 3, brv - borderBottomWidth / 3, CORNER.BOTTOM_RIGHT)
54 : new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 3, bounds.top + bounds.height - borderBottomWidth / 3);
55 this.bottomLeftBorderDoubleOuterBox =
56 blh > 0 || blv > 0
57 ? getCurvePoints(bounds.left + borderLeftWidth / 3, bounds.top + leftHeight, blh - borderLeftWidth / 3, blv - borderBottomWidth / 3, CORNER.BOTTOM_LEFT)
58 : new vector_1.Vector(bounds.left + borderLeftWidth / 3, bounds.top + bounds.height - borderBottomWidth / 3);
59 this.topLeftBorderDoubleInnerBox =
60 tlh > 0 || tlv > 0
61 ? getCurvePoints(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + (borderTopWidth * 2) / 3, tlh - (borderLeftWidth * 2) / 3, tlv - (borderTopWidth * 2) / 3, CORNER.TOP_LEFT)
62 : new vector_1.Vector(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + (borderTopWidth * 2) / 3);
63 this.topRightBorderDoubleInnerBox =
64 tlh > 0 || tlv > 0
65 ? getCurvePoints(bounds.left + topWidth, bounds.top + (borderTopWidth * 2) / 3, trh - (borderRightWidth * 2) / 3, trv - (borderTopWidth * 2) / 3, CORNER.TOP_RIGHT)
66 : new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth * 2) / 3, bounds.top + (borderTopWidth * 2) / 3);
67 this.bottomRightBorderDoubleInnerBox =
68 brh > 0 || brv > 0
69 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - (borderRightWidth * 2) / 3, brv - (borderBottomWidth * 2) / 3, CORNER.BOTTOM_RIGHT)
70 : new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth * 2) / 3, bounds.top + bounds.height - (borderBottomWidth * 2) / 3);
71 this.bottomLeftBorderDoubleInnerBox =
72 blh > 0 || blv > 0
73 ? getCurvePoints(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + leftHeight, blh - (borderLeftWidth * 2) / 3, blv - (borderBottomWidth * 2) / 3, CORNER.BOTTOM_LEFT)
74 : new vector_1.Vector(bounds.left + (borderLeftWidth * 2) / 3, bounds.top + bounds.height - (borderBottomWidth * 2) / 3);
75 this.topLeftBorderStroke =
76 tlh > 0 || tlv > 0
77 ? getCurvePoints(bounds.left + borderLeftWidth / 2, bounds.top + borderTopWidth / 2, tlh - borderLeftWidth / 2, tlv - borderTopWidth / 2, CORNER.TOP_LEFT)
78 : new vector_1.Vector(bounds.left + borderLeftWidth / 2, bounds.top + borderTopWidth / 2);
79 this.topRightBorderStroke =
80 tlh > 0 || tlv > 0
81 ? getCurvePoints(bounds.left + topWidth, bounds.top + borderTopWidth / 2, trh - borderRightWidth / 2, trv - borderTopWidth / 2, CORNER.TOP_RIGHT)
82 : new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 2, bounds.top + borderTopWidth / 2);
83 this.bottomRightBorderStroke =
84 brh > 0 || brv > 0
85 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh - borderRightWidth / 2, brv - borderBottomWidth / 2, CORNER.BOTTOM_RIGHT)
86 : new vector_1.Vector(bounds.left + bounds.width - borderRightWidth / 2, bounds.top + bounds.height - borderBottomWidth / 2);
87 this.bottomLeftBorderStroke =
88 blh > 0 || blv > 0
89 ? getCurvePoints(bounds.left + borderLeftWidth / 2, bounds.top + leftHeight, blh - borderLeftWidth / 2, blv - borderBottomWidth / 2, CORNER.BOTTOM_LEFT)
90 : new vector_1.Vector(bounds.left + borderLeftWidth / 2, bounds.top + bounds.height - borderBottomWidth / 2);
91 this.topLeftBorderBox =
92 tlh > 0 || tlv > 0
93 ? getCurvePoints(bounds.left, bounds.top, tlh, tlv, CORNER.TOP_LEFT)
94 : new vector_1.Vector(bounds.left, bounds.top);
95 this.topRightBorderBox =
96 trh > 0 || trv > 0
97 ? getCurvePoints(bounds.left + topWidth, bounds.top, trh, trv, CORNER.TOP_RIGHT)
98 : new vector_1.Vector(bounds.left + bounds.width, bounds.top);
99 this.bottomRightBorderBox =
100 brh > 0 || brv > 0
101 ? getCurvePoints(bounds.left + bottomWidth, bounds.top + rightHeight, brh, brv, CORNER.BOTTOM_RIGHT)
102 : new vector_1.Vector(bounds.left + bounds.width, bounds.top + bounds.height);
103 this.bottomLeftBorderBox =
104 blh > 0 || blv > 0
105 ? getCurvePoints(bounds.left, bounds.top + leftHeight, blh, blv, CORNER.BOTTOM_LEFT)
106 : new vector_1.Vector(bounds.left, bounds.top + bounds.height);
107 this.topLeftPaddingBox =
108 tlh > 0 || tlv > 0
109 ? getCurvePoints(bounds.left + borderLeftWidth, bounds.top + borderTopWidth, Math.max(0, tlh - borderLeftWidth), Math.max(0, tlv - borderTopWidth), CORNER.TOP_LEFT)
110 : new vector_1.Vector(bounds.left + borderLeftWidth, bounds.top + borderTopWidth);
111 this.topRightPaddingBox =
112 trh > 0 || trv > 0
113 ? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width - borderRightWidth), bounds.top + borderTopWidth, topWidth > bounds.width + borderRightWidth ? 0 : Math.max(0, trh - borderRightWidth), Math.max(0, trv - borderTopWidth), CORNER.TOP_RIGHT)
114 : new vector_1.Vector(bounds.left + bounds.width - borderRightWidth, bounds.top + borderTopWidth);
115 this.bottomRightPaddingBox =
116 brh > 0 || brv > 0
117 ? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - borderLeftWidth), bounds.top + Math.min(rightHeight, bounds.height - borderBottomWidth), Math.max(0, brh - borderRightWidth), Math.max(0, brv - borderBottomWidth), CORNER.BOTTOM_RIGHT)
118 : new vector_1.Vector(bounds.left + bounds.width - borderRightWidth, bounds.top + bounds.height - borderBottomWidth);
119 this.bottomLeftPaddingBox =
120 blh > 0 || blv > 0
121 ? getCurvePoints(bounds.left + borderLeftWidth, bounds.top + Math.min(leftHeight, bounds.height - borderBottomWidth), Math.max(0, blh - borderLeftWidth), Math.max(0, blv - borderBottomWidth), CORNER.BOTTOM_LEFT)
122 : new vector_1.Vector(bounds.left + borderLeftWidth, bounds.top + bounds.height - borderBottomWidth);
123 this.topLeftContentBox =
124 tlh > 0 || tlv > 0
125 ? getCurvePoints(bounds.left + borderLeftWidth + paddingLeft, bounds.top + borderTopWidth + paddingTop, Math.max(0, tlh - (borderLeftWidth + paddingLeft)), Math.max(0, tlv - (borderTopWidth + paddingTop)), CORNER.TOP_LEFT)
126 : new vector_1.Vector(bounds.left + borderLeftWidth + paddingLeft, bounds.top + borderTopWidth + paddingTop);
127 this.topRightContentBox =
128 trh > 0 || trv > 0
129 ? getCurvePoints(bounds.left + Math.min(topWidth, bounds.width + borderLeftWidth + paddingLeft), bounds.top + borderTopWidth + paddingTop, topWidth > bounds.width + borderLeftWidth + paddingLeft ? 0 : trh - borderLeftWidth + paddingLeft, trv - (borderTopWidth + paddingTop), CORNER.TOP_RIGHT)
130 : new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth + paddingRight), bounds.top + borderTopWidth + paddingTop);
131 this.bottomRightContentBox =
132 brh > 0 || brv > 0
133 ? getCurvePoints(bounds.left + Math.min(bottomWidth, bounds.width - (borderLeftWidth + paddingLeft)), bounds.top + Math.min(rightHeight, bounds.height + borderTopWidth + paddingTop), Math.max(0, brh - (borderRightWidth + paddingRight)), brv - (borderBottomWidth + paddingBottom), CORNER.BOTTOM_RIGHT)
134 : new vector_1.Vector(bounds.left + bounds.width - (borderRightWidth + paddingRight), bounds.top + bounds.height - (borderBottomWidth + paddingBottom));
135 this.bottomLeftContentBox =
136 blh > 0 || blv > 0
137 ? getCurvePoints(bounds.left + borderLeftWidth + paddingLeft, bounds.top + leftHeight, Math.max(0, blh - (borderLeftWidth + paddingLeft)), blv - (borderBottomWidth + paddingBottom), CORNER.BOTTOM_LEFT)
138 : new vector_1.Vector(bounds.left + borderLeftWidth + paddingLeft, bounds.top + bounds.height - (borderBottomWidth + paddingBottom));
139 }
140 return BoundCurves;
141}());
142exports.BoundCurves = BoundCurves;
143var CORNER;
144(function (CORNER) {
145 CORNER[CORNER["TOP_LEFT"] = 0] = "TOP_LEFT";
146 CORNER[CORNER["TOP_RIGHT"] = 1] = "TOP_RIGHT";
147 CORNER[CORNER["BOTTOM_RIGHT"] = 2] = "BOTTOM_RIGHT";
148 CORNER[CORNER["BOTTOM_LEFT"] = 3] = "BOTTOM_LEFT";
149})(CORNER || (CORNER = {}));
150var getCurvePoints = function (x, y, r1, r2, position) {
151 var kappa = 4 * ((Math.sqrt(2) - 1) / 3);
152 var ox = r1 * kappa; // control point offset horizontal
153 var oy = r2 * kappa; // control point offset vertical
154 var xm = x + r1; // x-middle
155 var ym = y + r2; // y-middle
156 switch (position) {
157 case CORNER.TOP_LEFT:
158 return new bezier_curve_1.BezierCurve(new vector_1.Vector(x, ym), new vector_1.Vector(x, ym - oy), new vector_1.Vector(xm - ox, y), new vector_1.Vector(xm, y));
159 case CORNER.TOP_RIGHT:
160 return new bezier_curve_1.BezierCurve(new vector_1.Vector(x, y), new vector_1.Vector(x + ox, y), new vector_1.Vector(xm, ym - oy), new vector_1.Vector(xm, ym));
161 case CORNER.BOTTOM_RIGHT:
162 return new bezier_curve_1.BezierCurve(new vector_1.Vector(xm, y), new vector_1.Vector(xm, y + oy), new vector_1.Vector(x + ox, ym), new vector_1.Vector(x, ym));
163 case CORNER.BOTTOM_LEFT:
164 default:
165 return new bezier_curve_1.BezierCurve(new vector_1.Vector(xm, ym), new vector_1.Vector(xm - ox, ym), new vector_1.Vector(x, y + oy), new vector_1.Vector(x, y));
166 }
167};
168var calculateBorderBoxPath = function (curves) {
169 return [curves.topLeftBorderBox, curves.topRightBorderBox, curves.bottomRightBorderBox, curves.bottomLeftBorderBox];
170};
171exports.calculateBorderBoxPath = calculateBorderBoxPath;
172var calculateContentBoxPath = function (curves) {
173 return [
174 curves.topLeftContentBox,
175 curves.topRightContentBox,
176 curves.bottomRightContentBox,
177 curves.bottomLeftContentBox
178 ];
179};
180exports.calculateContentBoxPath = calculateContentBoxPath;
181var calculatePaddingBoxPath = function (curves) {
182 return [
183 curves.topLeftPaddingBox,
184 curves.topRightPaddingBox,
185 curves.bottomRightPaddingBox,
186 curves.bottomLeftPaddingBox
187 ];
188};
189exports.calculatePaddingBoxPath = calculatePaddingBoxPath;
190//# sourceMappingURL=bound-curves.js.map
Note: See TracBrowser for help on using the repository browser.