@pie-lib/tools 0.9.36-next.0 → 0.10.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +15 -19
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/package.json +4 -3
  4. package/src/__tests__/__snapshots__/rotatable.test.jsx.snap +37 -0
  5. package/src/__tests__/anchor-utils.test.js +131 -0
  6. package/src/__tests__/rotatable.test.jsx +220 -0
  7. package/src/__tests__/transform-origin.test.jsx +24 -0
  8. package/src/index.js +1 -0
  9. package/src/protractor/__tests__/__snapshots__/graphic.test.jsx.snap +1234 -0
  10. package/src/protractor/__tests__/__snapshots__/index.test.jsx.snap +40 -0
  11. package/src/protractor/__tests__/graphic.test.jsx +13 -0
  12. package/src/protractor/__tests__/index.test.jsx +13 -0
  13. package/src/ruler/__tests__/__snapshots__/graphic.test.jsx.snap +160 -0
  14. package/src/ruler/__tests__/__snapshots__/index.test.jsx.snap +45 -0
  15. package/src/ruler/__tests__/__snapshots__/unit-type.test.jsx.snap +12 -0
  16. package/src/ruler/__tests__/__snapshots__/unit.test.jsx.snap +30 -0
  17. package/src/ruler/__tests__/graphic.test.jsx +23 -0
  18. package/src/ruler/__tests__/index.test.jsx +28 -0
  19. package/src/ruler/__tests__/unit-type.test.jsx +13 -0
  20. package/src/ruler/__tests__/unit.test.jsx +15 -0
  21. package/lib/anchor-utils.js +0 -249
  22. package/lib/anchor-utils.js.map +0 -1
  23. package/lib/anchor.js +0 -41
  24. package/lib/anchor.js.map +0 -1
  25. package/lib/index.js +0 -43
  26. package/lib/index.js.map +0 -1
  27. package/lib/protractor/graphic.js +0 -184
  28. package/lib/protractor/graphic.js.map +0 -1
  29. package/lib/protractor/index.js +0 -120
  30. package/lib/protractor/index.js.map +0 -1
  31. package/lib/rotatable.js +0 -403
  32. package/lib/rotatable.js.map +0 -1
  33. package/lib/ruler/graphic.js +0 -126
  34. package/lib/ruler/graphic.js.map +0 -1
  35. package/lib/ruler/index.js +0 -146
  36. package/lib/ruler/index.js.map +0 -1
  37. package/lib/ruler/unit-type.js +0 -72
  38. package/lib/ruler/unit-type.js.map +0 -1
  39. package/lib/ruler/unit.js +0 -161
  40. package/lib/ruler/unit.js.map +0 -1
  41. package/lib/style-utils.js +0 -28
  42. package/lib/style-utils.js.map +0 -1
  43. package/lib/transform-origin.js +0 -82
  44. package/lib/transform-origin.js.map +0 -1
@@ -0,0 +1,40 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`protractor snapshot renders 1`] = `
4
+ <WithStyles(Rotatable)
5
+ handle={
6
+ Array [
7
+ Object {
8
+ "class": "leftAnchor",
9
+ "origin": "222.75px 220.5px",
10
+ },
11
+ Object {
12
+ "class": "rightAnchor",
13
+ "origin": "222.75px 220.5px",
14
+ },
15
+ ]
16
+ }
17
+ startPosition={
18
+ Object {
19
+ "left": 0,
20
+ "top": 0,
21
+ }
22
+ }
23
+ >
24
+ <div
25
+ style={
26
+ Object {
27
+ "width": "450px",
28
+ }
29
+ }
30
+ >
31
+ <WithStyles(Graphic) />
32
+ <WithStyles(Component)
33
+ className="leftAnchor"
34
+ />
35
+ <WithStyles(Component)
36
+ className="rightAnchor"
37
+ />
38
+ </div>
39
+ </WithStyles(Rotatable)>
40
+ `;
@@ -0,0 +1,13 @@
1
+ import toJson from 'enzyme-to-json';
2
+ import { shallow } from 'enzyme';
3
+ import { Graphic } from '../graphic';
4
+ import React from 'react';
5
+
6
+ describe('graphic', () => {
7
+ describe('snapshot', () => {
8
+ it('renders', () => {
9
+ const wrapper = shallow(<Graphic classes={{ path: 'path', line: 'line', circle: 'circle' }} />);
10
+ expect(toJson(wrapper)).toMatchSnapshot();
11
+ });
12
+ });
13
+ });
@@ -0,0 +1,13 @@
1
+ import toJson from 'enzyme-to-json';
2
+ import { shallow } from 'enzyme';
3
+ import { Protractor } from '../index';
4
+ import React from 'react';
5
+
6
+ describe('protractor', () => {
7
+ describe('snapshot', () => {
8
+ it('renders', () => {
9
+ const wrapper = shallow(<Protractor classes={{}} />);
10
+ expect(toJson(wrapper)).toMatchSnapshot();
11
+ });
12
+ });
13
+ });
@@ -0,0 +1,160 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`graphic snapshot renders 1`] = `
4
+ <svg
5
+ viewBox="0 0 300 100"
6
+ >
7
+ <Bg
8
+ className="bg"
9
+ height={100}
10
+ width={300}
11
+ />
12
+ <WithStyles(UnitType)
13
+ label="in"
14
+ />
15
+ <WithStyles(Unit)
16
+ config={
17
+ Object {
18
+ "type": "in",
19
+ }
20
+ }
21
+ height={100}
22
+ index={1}
23
+ key="1"
24
+ last={false}
25
+ width={25}
26
+ />
27
+ <WithStyles(Unit)
28
+ config={
29
+ Object {
30
+ "type": "in",
31
+ }
32
+ }
33
+ height={100}
34
+ index={2}
35
+ key="2"
36
+ last={false}
37
+ width={25}
38
+ />
39
+ <WithStyles(Unit)
40
+ config={
41
+ Object {
42
+ "type": "in",
43
+ }
44
+ }
45
+ height={100}
46
+ index={3}
47
+ key="3"
48
+ last={false}
49
+ width={25}
50
+ />
51
+ <WithStyles(Unit)
52
+ config={
53
+ Object {
54
+ "type": "in",
55
+ }
56
+ }
57
+ height={100}
58
+ index={4}
59
+ key="4"
60
+ last={false}
61
+ width={25}
62
+ />
63
+ <WithStyles(Unit)
64
+ config={
65
+ Object {
66
+ "type": "in",
67
+ }
68
+ }
69
+ height={100}
70
+ index={5}
71
+ key="5"
72
+ last={false}
73
+ width={25}
74
+ />
75
+ <WithStyles(Unit)
76
+ config={
77
+ Object {
78
+ "type": "in",
79
+ }
80
+ }
81
+ height={100}
82
+ index={6}
83
+ key="6"
84
+ last={false}
85
+ width={25}
86
+ />
87
+ <WithStyles(Unit)
88
+ config={
89
+ Object {
90
+ "type": "in",
91
+ }
92
+ }
93
+ height={100}
94
+ index={7}
95
+ key="7"
96
+ last={false}
97
+ width={25}
98
+ />
99
+ <WithStyles(Unit)
100
+ config={
101
+ Object {
102
+ "type": "in",
103
+ }
104
+ }
105
+ height={100}
106
+ index={8}
107
+ key="8"
108
+ last={false}
109
+ width={25}
110
+ />
111
+ <WithStyles(Unit)
112
+ config={
113
+ Object {
114
+ "type": "in",
115
+ }
116
+ }
117
+ height={100}
118
+ index={9}
119
+ key="9"
120
+ last={false}
121
+ width={25}
122
+ />
123
+ <WithStyles(Unit)
124
+ config={
125
+ Object {
126
+ "type": "in",
127
+ }
128
+ }
129
+ height={100}
130
+ index={10}
131
+ key="10"
132
+ last={false}
133
+ width={25}
134
+ />
135
+ <WithStyles(Unit)
136
+ config={
137
+ Object {
138
+ "type": "in",
139
+ }
140
+ }
141
+ height={100}
142
+ index={11}
143
+ key="11"
144
+ last={false}
145
+ width={25}
146
+ />
147
+ <WithStyles(Unit)
148
+ config={
149
+ Object {
150
+ "type": "in",
151
+ }
152
+ }
153
+ height={100}
154
+ index={12}
155
+ key="12"
156
+ last={true}
157
+ width={25}
158
+ />
159
+ </svg>
160
+ `;
@@ -0,0 +1,45 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ruler snapshot renders 1`] = `
4
+ <WithStyles(Rotatable)
5
+ handle={
6
+ Array [
7
+ Object {
8
+ "class": "leftAnchor",
9
+ "origin": "bottom right",
10
+ },
11
+ Object {
12
+ "class": "rightAnchor",
13
+ "origin": "bottom left",
14
+ },
15
+ ]
16
+ }
17
+ >
18
+ <div
19
+ style={
20
+ Object {
21
+ "height": "60px",
22
+ "width": "480px",
23
+ }
24
+ }
25
+ >
26
+ <WithStyles(Graphic)
27
+ height={60}
28
+ unit={
29
+ Object {
30
+ "ticks": 16,
31
+ "type": undefined,
32
+ }
33
+ }
34
+ units={12}
35
+ width={480}
36
+ />
37
+ <WithStyles(Component)
38
+ className="leftAnchor"
39
+ />
40
+ <WithStyles(Component)
41
+ className="rightAnchor"
42
+ />
43
+ </div>
44
+ </WithStyles(Rotatable)>
45
+ `;
@@ -0,0 +1,12 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`unit-type snapshot renders 1`] = `
4
+ <text
5
+ fontSize={11}
6
+ stroke="none"
7
+ x={8}
8
+ y={14}
9
+ >
10
+ cm
11
+ </text>
12
+ `;
@@ -0,0 +1,30 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`unit snapshot renders 1`] = `
4
+ <g
5
+ style={
6
+ Object {
7
+ "transform": "translate(30px, 0px)",
8
+ }
9
+ }
10
+ >
11
+ <line
12
+ x1={30}
13
+ x2={30}
14
+ y1={0}
15
+ y2={20}
16
+ />
17
+ <Ticks
18
+ count={10}
19
+ height={20}
20
+ width={30}
21
+ />
22
+ <text
23
+ width={30}
24
+ x={25}
25
+ y={15}
26
+ >
27
+ 2
28
+ </text>
29
+ </g>
30
+ `;
@@ -0,0 +1,23 @@
1
+ import toJson from 'enzyme-to-json';
2
+ import { shallow } from 'enzyme';
3
+ import { Graphic } from '../graphic';
4
+ import React from 'react';
5
+
6
+ describe('graphic', () => {
7
+ describe('snapshot', () => {
8
+ it('renders', () => {
9
+ const wrapper = shallow(
10
+ <Graphic
11
+ width={300}
12
+ height={100}
13
+ units={12}
14
+ unit={{
15
+ type: 'in',
16
+ }}
17
+ classes={{ bg: 'bg' }}
18
+ />,
19
+ );
20
+ expect(toJson(wrapper)).toMatchSnapshot();
21
+ });
22
+ });
23
+ });
@@ -0,0 +1,28 @@
1
+ import toJson from 'enzyme-to-json';
2
+ import { shallow } from 'enzyme';
3
+ import { Ruler } from '../index';
4
+ import RulerGraphic from '../graphic';
5
+ import React from 'react';
6
+
7
+ describe('ruler', () => {
8
+ describe('snapshot', () => {
9
+ it('renders', () => {
10
+ const wrapper = shallow(<Ruler classes={{}} />);
11
+ expect(toJson(wrapper)).toMatchSnapshot();
12
+ });
13
+ });
14
+
15
+ describe('logic', () => {
16
+ it('sets unit for imperial', () => {
17
+ const wrapper = shallow(<Ruler measure={'imperial'} classes={{}} label={'in'} />);
18
+ const r = wrapper.find(RulerGraphic);
19
+ expect(r.prop('unit')).toEqual({ ticks: 16, type: 'in' });
20
+ });
21
+
22
+ it('sets unit for metric', () => {
23
+ const wrapper = shallow(<Ruler measure={'metric'} classes={{}} label={'cm'} />);
24
+ const r = wrapper.find(RulerGraphic);
25
+ expect(r.prop('unit')).toEqual({ ticks: 10, type: 'cm' });
26
+ });
27
+ });
28
+ });
@@ -0,0 +1,13 @@
1
+ import toJson from 'enzyme-to-json';
2
+ import { shallow } from 'enzyme';
3
+ import { UnitType } from '../unit-type';
4
+ import React from 'react';
5
+
6
+ describe('unit-type', () => {
7
+ describe('snapshot', () => {
8
+ it('renders', () => {
9
+ const wrapper = shallow(<UnitType classes={{}} label={'cm'} />);
10
+ expect(toJson(wrapper)).toMatchSnapshot();
11
+ });
12
+ });
13
+ });
@@ -0,0 +1,15 @@
1
+ import toJson from 'enzyme-to-json';
2
+ import { shallow } from 'enzyme';
3
+ import { Unit } from '../unit';
4
+ import React from 'react';
5
+
6
+ describe('unit', () => {
7
+ describe('snapshot', () => {
8
+ it('renders', () => {
9
+ const wrapper = shallow(
10
+ <Unit index={2} width={30} height={20} last={false} config={{ ticks: 10 }} classes={{}} />,
11
+ );
12
+ expect(toJson(wrapper)).toMatchSnapshot();
13
+ });
14
+ });
15
+ });
@@ -1,249 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.toRadians = exports.toPoint = exports.toDegrees = exports.normalizeAngle = exports.getXAndY = exports.getTop = exports.getLeft = exports.getAngleAndHypotenuse = exports.getAnchor = exports.distanceBetween = exports.arctangent = void 0;
9
-
10
- var _trigonometryCalculator = require("trigonometry-calculator");
11
-
12
- var _pointGeometry = _interopRequireDefault(require("@mapbox/point-geometry"));
13
-
14
- var _debug = _interopRequireDefault(require("debug"));
15
-
16
- var _transformOrigin = require("./transform-origin");
17
-
18
- var log = (0, _debug["default"])('@pie-lib:tools:anchor-utils');
19
-
20
- var toDegrees = function toDegrees(radians) {
21
- return radians * (180 / Math.PI);
22
- };
23
-
24
- exports.toDegrees = toDegrees;
25
-
26
- var toRadians = function toRadians(degrees) {
27
- return degrees * (Math.PI / 180);
28
- };
29
-
30
- exports.toRadians = toRadians;
31
-
32
- var normalizeAngle = function normalizeAngle(a) {
33
- if (a > 360) {
34
- return a % 360;
35
- } else if (a < 0) {
36
- return 360 + a % 360;
37
- }
38
-
39
- return a;
40
- };
41
-
42
- exports.normalizeAngle = normalizeAngle;
43
-
44
- var toPoint = function toPoint(rect, edge) {
45
- var out = (0, _transformOrigin.parse)(rect, edge);
46
- return new _pointGeometry["default"](out.x, out.y);
47
- };
48
- /**
49
- * Get the distance between to anchor points in a rect.
50
- * @param {{width: number, height: number}} rect - the rect
51
- * @param {number} degrees - the degrees
52
- * @param {string} from - from anchor
53
- * @param {string} to - to anchor
54
- * @returns {Point} point - the distance as a Point
55
- */
56
-
57
-
58
- exports.toPoint = toPoint;
59
-
60
- var distanceBetween = function distanceBetween(rect, degrees, from, to) {
61
- var center = new _pointGeometry["default"](rect.width / 2, rect.height / 2);
62
- var radians = toRadians(degrees);
63
- var fromCenter = center.rotateAround(radians, toPoint(rect, from));
64
- var toCenter = center.rotateAround(radians, toPoint(rect, to));
65
- var diff = fromCenter.sub(toCenter);
66
- return diff;
67
- };
68
- /**
69
- * For a corner string, a point and a rect, return a relative x,y from that point to a corner.
70
- * Note that the y value descends as it goes down (unlike for a screen's y value), so this is only really useful for math functions.
71
- * @example
72
- * ```
73
- * getXAndY('top-left', {width: 100, height: 100}, 10, 10) //=> {x:10, y: -90}
74
- * ```
75
- * @param {*} corner
76
- * @param {*} rect
77
- * @param {*} point
78
- */
79
-
80
-
81
- exports.distanceBetween = distanceBetween;
82
-
83
- var getXAndY = function getXAndY(corner, rect, point) {
84
- if (corner === 'top-left') {
85
- var x = point.x * -1;
86
- var y = point.y;
87
- return {
88
- x: x,
89
- y: y
90
- };
91
- } else if (corner === 'bottom-left') {
92
- var _x = point.x * -1;
93
-
94
- var _y = point.y - rect.height;
95
-
96
- return {
97
- x: _x,
98
- y: _y
99
- };
100
- } else if (corner === 'top-right') {
101
- var _x2 = rect.width - point.x;
102
-
103
- var _y2 = point.y;
104
- return {
105
- x: _x2,
106
- y: _y2
107
- };
108
- } else if (corner === 'bottom-right') {
109
- var _x3 = rect.width - point.x;
110
-
111
- var _y3 = point.y - rect.height;
112
-
113
- return {
114
- x: _x3,
115
- y: _y3
116
- };
117
- }
118
- };
119
-
120
- exports.getXAndY = getXAndY;
121
-
122
- var arctangent = function arctangent(x, y) {
123
- return toDegrees(Math.atan2(x, y));
124
- };
125
-
126
- exports.arctangent = arctangent;
127
-
128
- var getAngleAndHypotenuse = function getAngleAndHypotenuse(corner, rect, point) {
129
- var _getXAndY = getXAndY(corner, rect, point),
130
- x = _getXAndY.x,
131
- y = _getXAndY.y;
132
-
133
- var degrees = arctangent(x, y);
134
- var hypotenuse = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
135
- return {
136
- x: x,
137
- y: y,
138
- degrees: degrees,
139
- hypotenuse: hypotenuse
140
- };
141
- };
142
-
143
- exports.getAngleAndHypotenuse = getAngleAndHypotenuse;
144
-
145
- var getPosition = function getPosition(side, rect, point, angle, calcAngle) {
146
- if (angle === 0) {
147
- return side === 'left' ? point.x : point.y;
148
- }
149
-
150
- var points = anglePoints(angle);
151
- var key = points[side];
152
-
153
- var _getAngleAndHypotenus = getAngleAndHypotenuse(key, rect, point),
154
- degrees = _getAngleAndHypotenus.degrees,
155
- hypotenuse = _getAngleAndHypotenus.hypotenuse;
156
-
157
- var ra = calcAngle(degrees);
158
-
159
- if (ra === 0) {
160
- return hypotenuse;
161
- }
162
-
163
- var t = {
164
- angles: {
165
- 0: ra,
166
- 1: 90
167
- },
168
- sides: {
169
- 1: hypotenuse
170
- }
171
- };
172
- var out = (0, _trigonometryCalculator.trigCalculator)(t);
173
- return out.sides[2];
174
- };
175
-
176
- var getTop = function getTop(rect, point, angle) {
177
- return getPosition('top', rect, point, angle, function (degrees) {
178
- return Math.abs(angle + degrees);
179
- });
180
- };
181
-
182
- exports.getTop = getTop;
183
-
184
- var getLeft = function getLeft(rect, point, angle) {
185
- return getPosition('left', rect, point, angle, function (degrees) {
186
- return Math.abs(angle + degrees + 90);
187
- });
188
- };
189
- /**
190
- * Calculate the position of an anchor within a bounding rect, if the source rect has been rotated by an angle.
191
- * It does this by finding the appropriate corner of the src rect, that touches the bounding rect, calculates
192
- * the hypotenuse (h) of that anchor to that point. Then using that plus the rotation it calculates
193
- * the sides of the triangle and returns the length of the side that touches the bounding rect.
194
- * @param {{width: number, height: number}} rect - the rect which contains the point
195
- * @param {{x:number, y: number}} point - the point within the rect
196
- * @param {number} angle - the angle in degrees that the rect has rotated.
197
- * @returns {{left: number, top: number}} position
198
- */
199
-
200
-
201
- exports.getLeft = getLeft;
202
-
203
- var getAnchor = function getAnchor(rect, point, angle) {
204
- log('[getAnchor] rect: ', rect, 'point:', point, 'angle: ', angle);
205
-
206
- if (point.x > rect.width) {
207
- throw new Error("x: ".concat(point.x, " cannot be greater than width: ").concat(rect.width));
208
- }
209
-
210
- if (point.y > rect.height) {
211
- throw new Error("y: ".concat(point.y, " cannot be greater than height: ").concat(rect.height));
212
- }
213
-
214
- var a = normalizeAngle(angle);
215
- var top = getTop(rect, point, a);
216
- var left = getLeft(rect, point, a);
217
- log('[getAnchor] top: ', top, 'left: ', left);
218
- return {
219
- top: top,
220
- left: left
221
- };
222
- };
223
-
224
- exports.getAnchor = getAnchor;
225
-
226
- var anglePoints = function anglePoints(angle) {
227
- if (angle <= 90) {
228
- return {
229
- top: 'top-left',
230
- left: 'bottom-left'
231
- };
232
- } else if (angle > 90 && angle <= 180) {
233
- return {
234
- top: 'bottom-left',
235
- left: 'bottom-right'
236
- };
237
- } else if (angle > 180 && angle <= 270) {
238
- return {
239
- top: 'bottom-right',
240
- left: 'top-right'
241
- };
242
- } else if (angle > 270 && angle < 360) {
243
- return {
244
- top: 'top-right',
245
- left: 'top-left'
246
- };
247
- }
248
- };
249
- //# sourceMappingURL=anchor-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/anchor-utils.js"],"names":["log","toDegrees","radians","Math","PI","toRadians","degrees","normalizeAngle","a","toPoint","rect","edge","out","Point","x","y","distanceBetween","from","to","center","width","height","fromCenter","rotateAround","toCenter","diff","sub","getXAndY","corner","point","arctangent","atan2","getAngleAndHypotenuse","hypotenuse","sqrt","pow","getPosition","side","angle","calcAngle","points","anglePoints","key","ra","t","angles","sides","getTop","abs","getLeft","getAnchor","Error","top","left"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA,IAAMA,GAAG,GAAG,uBAAM,6BAAN,CAAZ;;AAEO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,OAAD;AAAA,SAAaA,OAAO,IAAI,MAAMC,IAAI,CAACC,EAAf,CAApB;AAAA,CAAlB;;;;AACA,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,OAAD;AAAA,SAAaA,OAAO,IAAIH,IAAI,CAACC,EAAL,GAAU,GAAd,CAApB;AAAA,CAAlB;;;;AAEA,IAAMG,cAAc,GAAG,SAAjBA,cAAiB,CAACC,CAAD,EAAO;AACnC,MAAIA,CAAC,GAAG,GAAR,EAAa;AACX,WAAOA,CAAC,GAAG,GAAX;AACD,GAFD,MAEO,IAAIA,CAAC,GAAG,CAAR,EAAW;AAChB,WAAO,MAAOA,CAAC,GAAG,GAAlB;AACD;;AACD,SAAOA,CAAP;AACD,CAPM;;;;AASA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,IAAD,EAAOC,IAAP,EAAgB;AACrC,MAAMC,GAAG,GAAG,4BAAYF,IAAZ,EAAkBC,IAAlB,CAAZ;AACA,SAAO,IAAIE,yBAAJ,CAAUD,GAAG,CAACE,CA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crB,CAAd,CAApB;AAEAR,EAAAA,GAAG,CAAC,mBAAD,EAAsBoD,GAAtB,EAA2B,QAA3B,EAAqCC,IAArC,CAAH;AACA,SAAO;AAAED,IAAAA,GAAG,EAAHA,GAAF;AAAOC,IAAAA,IAAI,EAAJA;AAAP,GAAP;AACD,CAdM;;;;AAgBP,IAAMZ,WAAW,GAAG,SAAdA,WAAc,CAACH,KAAD,EAAW;AAC7B,MAAIA,KAAK,IAAI,EAAb,EAAiB;AACf,WAAO;AAAEc,MAAAA,GAAG,EAAE,UAAP;AAAmBC,MAAAA,IAAI,EAAE;AAAzB,KAAP;AACD,GAFD,MAEO,IAAIf,KAAK,GAAG,EAAR,IAAcA,KAAK,IAAI,GAA3B,EAAgC;AACrC,WAAO;AAAEc,MAAAA,GAAG,EAAE,aAAP;AAAsBC,MAAAA,IAAI,EAAE;AAA5B,KAAP;AACD,GAFM,MAEA,IAAIf,KAAK,GAAG,GAAR,IAAeA,KAAK,IAAI,GAA5B,EAAiC;AACtC,WAAO;AAAEc,MAAAA,GAAG,EAAE,cAAP;AAAuBC,MAAAA,IAAI,EAAE;AAA7B,KAAP;AACD,GAFM,MAEA,IAAIf,KAAK,GAAG,GAAR,IAAeA,KAAK,GAAG,GAA3B,EAAgC;AACrC,WAAO;AAAEc,MAAAA,GAAG,EAAE,WAAP;AAAoBC,MAAAA,IAAI,EAAE;AAA1B,KAAP;AACD;AACF,CAVD","sourcesContent":["import { trigCalculator } from 'trigonometry-calculator';\nimport Point from '@mapbox/point-geometry';\nimport debug from 'debug';\nimport { parse as parseOrigin } from './transform-origin';\nconst log = debug('@pie-lib:tools:anchor-utils');\n\nexport const toDegrees = (radians) => radians * (180 / Math.PI);\nexport const toRadians = (degrees) => degrees * (Math.PI / 180);\n\nexport const normalizeAngle = (a) => {\n if (a > 360) {\n return a % 360;\n } else if (a < 0) {\n return 360 + (a % 360);\n }\n return a;\n};\n\nexport const toPoint = (rect, edge) => {\n const out = parseOrigin(rect, edge);\n return new Point(out.x, out.y);\n};\n\n/**\n * Get the distance between to anchor points in a rect.\n * @param {{width: number, height: number}} rect - the rect\n * @param {number} degrees - the degrees\n * @param {string} from - from anchor\n * @param {string} to - to anchor\n * @returns {Point} point - the distance as a Point\n */\nexport const distanceBetween = (rect, degrees, from, to) => {\n const center = new Point(rect.width / 2, rect.height / 2);\n const radians = toRadians(degrees);\n const fromCenter = center.rotateAround(radians, toPoint(rect, from));\n const toCenter = center.rotateAround(radians, toPoint(rect, to));\n const diff = fromCenter.sub(toCenter);\n return diff;\n};\n\n/**\n * For a corner string, a point and a rect, return a relative x,y from that point to a corner.\n * Note that the y value descends as it goes down (unlike for a screen's y value), so this is only really useful for math functions.\n * @example\n * ```\n * getXAndY('top-left', {width: 100, height: 100}, 10, 10) //=> {x:10, y: -90}\n * ```\n * @param {*} corner\n * @param {*} rect\n * @param {*} point\n */\nexport const getXAndY = (corner, rect, point) => {\n if (corner === 'top-left') {\n const x = point.x * -1;\n const y = point.y;\n return { x, y };\n } else if (corner === 'bottom-left') {\n const x = point.x * -1;\n const y = point.y - rect.height;\n return { x, y };\n } else if (corner === 'top-right') {\n const x = rect.width - point.x;\n const y = point.y;\n return { x, y };\n } else if (corner === 'bottom-right') {\n const x = rect.width - point.x;\n const y = point.y - rect.height;\n return { x, y };\n }\n};\n\nexport const arctangent = (x, y) => toDegrees(Math.atan2(x, y));\n\nexport const getAngleAndHypotenuse = (corner, rect, point) => {\n const { x, y } = getXAndY(corner, rect, point);\n const degrees = arctangent(x, y);\n const hypotenuse = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));\n return { x, y, degrees, hypotenuse };\n};\n\nconst getPosition = (side, rect, point, angle, calcAngle) => {\n if (angle === 0) {\n return side === 'left' ? point.x : point.y;\n }\n const points = anglePoints(angle);\n const key = points[side];\n\n const { degrees, hypotenuse } = getAngleAndHypotenuse(key, rect, point);\n\n const ra = calcAngle(degrees);\n\n if (ra === 0) {\n return hypotenuse;\n }\n\n const t = {\n angles: { 0: ra, 1: 90 },\n sides: { 1: hypotenuse },\n };\n const out = trigCalculator(t);\n return out.sides[2];\n};\n\nexport const getTop = (rect, point, angle) => {\n return getPosition('top', rect, point, angle, (degrees) => {\n return Math.abs(angle + degrees);\n });\n};\n\nexport const getLeft = (rect, point, angle) => {\n return getPosition('left', rect, point, angle, (degrees) => {\n return Math.abs(angle + degrees + 90);\n });\n};\n\n/**\n * Calculate the position of an anchor within a bounding rect, if the source rect has been rotated by an angle.\n * It does this by finding the appropriate corner of the src rect, that touches the bounding rect, calculates\n * the hypotenuse (h) of that anchor to that point. Then using that plus the rotation it calculates\n * the sides of the triangle and returns the length of the side that touches the bounding rect.\n * @param {{width: number, height: number}} rect - the rect which contains the point\n * @param {{x:number, y: number}} point - the point within the rect\n * @param {number} angle - the angle in degrees that the rect has rotated.\n * @returns {{left: number, top: number}} position\n */\nexport const getAnchor = (rect, point, angle) => {\n log('[getAnchor] rect: ', rect, 'point:', point, 'angle: ', angle);\n if (point.x > rect.width) {\n throw new Error(`x: ${point.x} cannot be greater than width: ${rect.width}`);\n }\n if (point.y > rect.height) {\n throw new Error(`y: ${point.y} cannot be greater than height: ${rect.height}`);\n }\n const a = normalizeAngle(angle);\n const top = getTop(rect, point, a);\n const left = getLeft(rect, point, a);\n\n log('[getAnchor] top: ', top, 'left: ', left);\n return { top, left };\n};\n\nconst anglePoints = (angle) => {\n if (angle <= 90) {\n return { top: 'top-left', left: 'bottom-left' };\n } else if (angle > 90 && angle <= 180) {\n return { top: 'bottom-left', left: 'bottom-right' };\n } else if (angle > 180 && angle <= 270) {\n return { top: 'bottom-right', left: 'top-right' };\n } else if (angle > 270 && angle < 360) {\n return { top: 'top-right', left: 'top-left' };\n }\n};\n"],"file":"anchor-utils.js"}