1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports["default"] = triangle;
|
5 | var _getValueAndUnit = _interopRequireDefault(require("../helpers/getValueAndUnit"));
|
6 | var _errors = _interopRequireDefault(require("../internalHelpers/_errors"));
|
7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
8 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
9 | var getBorderWidth = function getBorderWidth(pointingDirection, height, width) {
|
10 | var fullWidth = "" + width[0] + (width[1] || '');
|
11 | var halfWidth = "" + width[0] / 2 + (width[1] || '');
|
12 | var fullHeight = "" + height[0] + (height[1] || '');
|
13 | var halfHeight = "" + height[0] / 2 + (height[1] || '');
|
14 | switch (pointingDirection) {
|
15 | case 'top':
|
16 | return "0 " + halfWidth + " " + fullHeight + " " + halfWidth;
|
17 | case 'topLeft':
|
18 | return fullWidth + " " + fullHeight + " 0 0";
|
19 | case 'left':
|
20 | return halfHeight + " " + fullWidth + " " + halfHeight + " 0";
|
21 | case 'bottomLeft':
|
22 | return fullWidth + " 0 0 " + fullHeight;
|
23 | case 'bottom':
|
24 | return fullHeight + " " + halfWidth + " 0 " + halfWidth;
|
25 | case 'bottomRight':
|
26 | return "0 0 " + fullWidth + " " + fullHeight;
|
27 | case 'right':
|
28 | return halfHeight + " 0 " + halfHeight + " " + fullWidth;
|
29 | case 'topRight':
|
30 | default:
|
31 | return "0 " + fullWidth + " " + fullHeight + " 0";
|
32 | }
|
33 | };
|
34 | var getBorderColor = function getBorderColor(pointingDirection, foregroundColor) {
|
35 | switch (pointingDirection) {
|
36 | case 'top':
|
37 | case 'bottomRight':
|
38 | return {
|
39 | borderBottomColor: foregroundColor
|
40 | };
|
41 | case 'right':
|
42 | case 'bottomLeft':
|
43 | return {
|
44 | borderLeftColor: foregroundColor
|
45 | };
|
46 | case 'bottom':
|
47 | case 'topLeft':
|
48 | return {
|
49 | borderTopColor: foregroundColor
|
50 | };
|
51 | case 'left':
|
52 | case 'topRight':
|
53 | return {
|
54 | borderRightColor: foregroundColor
|
55 | };
|
56 | default:
|
57 | throw new _errors["default"](59);
|
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 | function triangle(_ref) {
|
88 | var pointingDirection = _ref.pointingDirection,
|
89 | height = _ref.height,
|
90 | width = _ref.width,
|
91 | foregroundColor = _ref.foregroundColor,
|
92 | _ref$backgroundColor = _ref.backgroundColor,
|
93 | backgroundColor = _ref$backgroundColor === void 0 ? 'transparent' : _ref$backgroundColor;
|
94 | var widthAndUnit = (0, _getValueAndUnit["default"])(width);
|
95 | var heightAndUnit = (0, _getValueAndUnit["default"])(height);
|
96 | if (isNaN(heightAndUnit[0]) || isNaN(widthAndUnit[0])) {
|
97 | throw new _errors["default"](60);
|
98 | }
|
99 | return _extends({
|
100 | width: '0',
|
101 | height: '0',
|
102 | borderColor: backgroundColor
|
103 | }, getBorderColor(pointingDirection, foregroundColor), {
|
104 | borderStyle: 'solid',
|
105 | borderWidth: getBorderWidth(pointingDirection, heightAndUnit, widthAndUnit)
|
106 | });
|
107 | }
|
108 | module.exports = exports.default; |
\ | No newline at end of file |