@pie-lib/tools 0.28.0 → 0.29.0-mui-update.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.
- package/CHANGELOG.md +15 -2
- package/lib/anchor-utils.js +18 -74
- package/lib/anchor-utils.js.map +1 -1
- package/lib/anchor.js +24 -28
- package/lib/anchor.js.map +1 -1
- package/lib/index.js +1 -11
- package/lib/index.js.map +1 -1
- package/lib/protractor/graphic.js +68 -105
- package/lib/protractor/graphic.js.map +1 -1
- package/lib/protractor/index.js +36 -63
- package/lib/protractor/index.js.map +1 -1
- package/lib/rotatable.js +75 -140
- package/lib/rotatable.js.map +1 -1
- package/lib/ruler/graphic.js +29 -66
- package/lib/ruler/graphic.js.map +1 -1
- package/lib/ruler/index.js +44 -72
- package/lib/ruler/index.js.map +1 -1
- package/lib/ruler/unit-type.js +19 -36
- package/lib/ruler/unit-type.js.map +1 -1
- package/lib/ruler/unit.js +51 -88
- package/lib/ruler/unit.js.map +1 -1
- package/lib/style-utils.js +2 -9
- package/lib/style-utils.js.map +1 -1
- package/lib/transform-origin.js +2 -13
- package/lib/transform-origin.js.map +1 -1
- package/package.json +12 -8
- package/src/anchor.jsx +15 -16
- package/src/protractor/graphic.jsx +49 -54
- package/src/protractor/index.jsx +23 -20
- package/src/rotatable.jsx +24 -27
- package/src/ruler/graphic.jsx +11 -14
- package/src/ruler/index.jsx +25 -25
- package/src/ruler/unit-type.jsx +10 -9
- package/src/ruler/unit.jsx +25 -29
package/lib/transform-origin.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parse = void 0;
|
|
7
|
-
|
|
8
7
|
var keyWordToPercent = function keyWordToPercent(v) {
|
|
9
8
|
if (v === 'left' || v === 'top') {
|
|
10
9
|
return 0;
|
|
@@ -18,7 +17,6 @@ var keyWordToPercent = function keyWordToPercent(v) {
|
|
|
18
17
|
return v;
|
|
19
18
|
}
|
|
20
19
|
};
|
|
21
|
-
|
|
22
20
|
var getValue = function getValue(s, length) {
|
|
23
21
|
if (s.endsWith('px')) {
|
|
24
22
|
return parseFloat(s);
|
|
@@ -28,7 +26,6 @@ var getValue = function getValue(s, length) {
|
|
|
28
26
|
return v;
|
|
29
27
|
}
|
|
30
28
|
};
|
|
31
|
-
|
|
32
29
|
var normalize = function normalize(a) {
|
|
33
30
|
if (a[0] === 'bottom' || a[0] === 'top' || a[1] === 'left' || a[1] === 'right') {
|
|
34
31
|
return [a[1], a[0]];
|
|
@@ -36,24 +33,21 @@ var normalize = function normalize(a) {
|
|
|
36
33
|
return a;
|
|
37
34
|
}
|
|
38
35
|
};
|
|
36
|
+
|
|
39
37
|
/**
|
|
40
38
|
* Parse a transform origin string to x/y values.
|
|
41
39
|
* @param {{width: number, height: number}} rect
|
|
42
40
|
* @param {string} value
|
|
43
41
|
* @returns {x:number, y:number}
|
|
44
42
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var parse = function parse(rect, value) {
|
|
43
|
+
var parse = exports.parse = function parse(rect, value) {
|
|
48
44
|
if (!value) {
|
|
49
45
|
return {
|
|
50
46
|
x: rect.width / 2,
|
|
51
47
|
y: rect.height / 2
|
|
52
48
|
};
|
|
53
49
|
}
|
|
54
|
-
|
|
55
50
|
var arr = value.split(' ');
|
|
56
|
-
|
|
57
51
|
if (arr.length === 1) {
|
|
58
52
|
//1 val
|
|
59
53
|
var x = getValue(arr[0], rect.width);
|
|
@@ -64,11 +58,8 @@ var parse = function parse(rect, value) {
|
|
|
64
58
|
};
|
|
65
59
|
} else if (arr.length === 2) {
|
|
66
60
|
var sorted = normalize(arr);
|
|
67
|
-
|
|
68
61
|
var _x = getValue(sorted[0], rect.width);
|
|
69
|
-
|
|
70
62
|
var _y = getValue(sorted[1], rect.height);
|
|
71
|
-
|
|
72
63
|
return {
|
|
73
64
|
x: _x,
|
|
74
65
|
y: _y
|
|
@@ -77,6 +68,4 @@ var parse = function parse(rect, value) {
|
|
|
77
68
|
throw new Error('transform-origin values with 3 fields not supported.');
|
|
78
69
|
}
|
|
79
70
|
};
|
|
80
|
-
|
|
81
|
-
exports.parse = parse;
|
|
82
71
|
//# sourceMappingURL=transform-origin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"transform-origin.js","names":["keyWordToPercent","v","endsWith","parseFloat","getValue","s","length","normalize","a","parse","exports","rect","value","x","width","y","height","arr","split","sorted","Error"],"sources":["../src/transform-origin.jsx"],"sourcesContent":["const keyWordToPercent = (v) => {\n if (v === 'left' || v === 'top') {\n return 0;\n } else if (v === 'right' || v === 'bottom') {\n return 100;\n } else if (v === 'center') {\n return 50;\n } else if (v.endsWith('%')) {\n return parseFloat(v);\n } else {\n return v;\n }\n};\n\nconst getValue = (s, length) => {\n if (s.endsWith('px')) {\n return parseFloat(s);\n } else {\n s = keyWordToPercent(s);\n const v = length * (s / 100);\n return v;\n }\n};\n\nconst normalize = (a) => {\n if (a[0] === 'bottom' || a[0] === 'top' || a[1] === 'left' || a[1] === 'right') {\n return [a[1], a[0]];\n } else {\n return a;\n }\n};\n\n/**\n * Parse a transform origin string to x/y values.\n * @param {{width: number, height: number}} rect\n * @param {string} value\n * @returns {x:number, y:number}\n */\nexport const parse = (rect, value) => {\n if (!value) {\n return {\n x: rect.width / 2,\n y: rect.height / 2,\n };\n }\n const arr = value.split(' ');\n if (arr.length === 1) {\n //1 val\n const x = getValue(arr[0], rect.width);\n const y = getValue('50%', rect.height);\n return { x, y };\n } else if (arr.length === 2) {\n const sorted = normalize(arr);\n const x = getValue(sorted[0], rect.width);\n const y = getValue(sorted[1], rect.height);\n return { x, y };\n } else if (arr.length === 3) {\n throw new Error('transform-origin values with 3 fields not supported.');\n }\n};\n"],"mappings":";;;;;;AAAA,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAIC,CAAC,EAAK;EAC9B,IAAIA,CAAC,KAAK,MAAM,IAAIA,CAAC,KAAK,KAAK,EAAE;IAC/B,OAAO,CAAC;EACV,CAAC,MAAM,IAAIA,CAAC,KAAK,OAAO,IAAIA,CAAC,KAAK,QAAQ,EAAE;IAC1C,OAAO,GAAG;EACZ,CAAC,MAAM,IAAIA,CAAC,KAAK,QAAQ,EAAE;IACzB,OAAO,EAAE;EACX,CAAC,MAAM,IAAIA,CAAC,CAACC,QAAQ,CAAC,GAAG,CAAC,EAAE;IAC1B,OAAOC,UAAU,CAACF,CAAC,CAAC;EACtB,CAAC,MAAM;IACL,OAAOA,CAAC;EACV;AACF,CAAC;AAED,IAAMG,QAAQ,GAAG,SAAXA,QAAQA,CAAIC,CAAC,EAAEC,MAAM,EAAK;EAC9B,IAAID,CAAC,CAACH,QAAQ,CAAC,IAAI,CAAC,EAAE;IACpB,OAAOC,UAAU,CAACE,CAAC,CAAC;EACtB,CAAC,MAAM;IACLA,CAAC,GAAGL,gBAAgB,CAACK,CAAC,CAAC;IACvB,IAAMJ,CAAC,GAAGK,MAAM,IAAID,CAAC,GAAG,GAAG,CAAC;IAC5B,OAAOJ,CAAC;EACV;AACF,CAAC;AAED,IAAMM,SAAS,GAAG,SAAZA,SAASA,CAAIC,CAAC,EAAK;EACvB,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IAC9E,OAAO,CAACA,CAAC,CAAC,CAAC,CAAC,EAAEA,CAAC,CAAC,CAAC,CAAC,CAAC;EACrB,CAAC,MAAM;IACL,OAAOA,CAAC;EACV;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,KAAK,GAAAC,OAAA,CAAAD,KAAA,GAAG,SAARA,KAAKA,CAAIE,IAAI,EAAEC,KAAK,EAAK;EACpC,IAAI,CAACA,KAAK,EAAE;IACV,OAAO;MACLC,CAAC,EAAEF,IAAI,CAACG,KAAK,GAAG,CAAC;MACjBC,CAAC,EAAEJ,IAAI,CAACK,MAAM,GAAG;IACnB,CAAC;EACH;EACA,IAAMC,GAAG,GAAGL,KAAK,CAACM,KAAK,CAAC,GAAG,CAAC;EAC5B,IAAID,GAAG,CAACX,MAAM,KAAK,CAAC,EAAE;IACpB;IACA,IAAMO,CAAC,GAAGT,QAAQ,CAACa,GAAG,CAAC,CAAC,CAAC,EAAEN,IAAI,CAACG,KAAK,CAAC;IACtC,IAAMC,CAAC,GAAGX,QAAQ,CAAC,KAAK,EAAEO,IAAI,CAACK,MAAM,CAAC;IACtC,OAAO;MAAEH,CAAC,EAADA,CAAC;MAAEE,CAAC,EAADA;IAAE,CAAC;EACjB,CAAC,MAAM,IAAIE,GAAG,CAACX,MAAM,KAAK,CAAC,EAAE;IAC3B,IAAMa,MAAM,GAAGZ,SAAS,CAACU,GAAG,CAAC;IAC7B,IAAMJ,EAAC,GAAGT,QAAQ,CAACe,MAAM,CAAC,CAAC,CAAC,EAAER,IAAI,CAACG,KAAK,CAAC;IACzC,IAAMC,EAAC,GAAGX,QAAQ,CAACe,MAAM,CAAC,CAAC,CAAC,EAAER,IAAI,CAACK,MAAM,CAAC;IAC1C,OAAO;MAAEH,CAAC,EAADA,EAAC;MAAEE,CAAC,EAADA;IAAE,CAAC;EACjB,CAAC,MAAM,IAAIE,GAAG,CAACX,MAAM,KAAK,CAAC,EAAE;IAC3B,MAAM,IAAIc,KAAK,CAAC,sDAAsD,CAAC;EACzE;AACF,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.29.0-mui-update.0",
|
|
7
7
|
"description": "Some interactive tools",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -17,8 +17,12 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@emotion/react": "^11.14.0",
|
|
21
|
+
"@emotion/style": "^0.8.0",
|
|
20
22
|
"@mapbox/point-geometry": "^0.1.0",
|
|
21
|
-
"@
|
|
23
|
+
"@mui/icons-material": "^7.3.4",
|
|
24
|
+
"@mui/material": "^7.3.4",
|
|
25
|
+
"@pie-lib/style-utils": "^0.21.0-mui-update.0",
|
|
22
26
|
"assert": "^1.4.1",
|
|
23
27
|
"classnames": "^2.2.6",
|
|
24
28
|
"debug": "^4.1.1",
|
|
@@ -29,13 +33,13 @@
|
|
|
29
33
|
"trigonometry-calculator": "^2.0.0"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@material
|
|
33
|
-
"react": "^
|
|
34
|
-
"react-dom": "^
|
|
36
|
+
"@mui/material": "^7.3.4",
|
|
37
|
+
"react": "^18.2.0",
|
|
38
|
+
"react-dom": "^18.2.0"
|
|
35
39
|
},
|
|
36
40
|
"peerDependencies": {
|
|
37
|
-
"@material
|
|
38
|
-
"react": "^
|
|
41
|
+
"@mui/material": "^7.3.4",
|
|
42
|
+
"react": "^18.2.0"
|
|
39
43
|
},
|
|
40
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "622d5627dc85e393cdf13e3362970299cc485cc5"
|
|
41
45
|
}
|
package/src/anchor.jsx
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import classNames from 'classnames';
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
4
3
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
backgroundColor: `var(--ruler-bg-hover, ${theme.palette.primary.light})`,
|
|
17
|
-
},
|
|
4
|
+
const StyledAnchor = styled('div')(({ theme }) => ({
|
|
5
|
+
cursor: 'pointer',
|
|
6
|
+
width: '20px',
|
|
7
|
+
height: '20px',
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
borderRadius: '10px',
|
|
10
|
+
backgroundColor: `var(--ruler-bg, ${theme.palette.primary.contrastText})`,
|
|
11
|
+
transition: 'background-color 200ms ease-in',
|
|
12
|
+
border: `solid 1px var(--ruler-stroke, ${theme.palette.primary.dark})`,
|
|
13
|
+
'&:hover': {
|
|
14
|
+
backgroundColor: `var(--ruler-bg-hover, ${theme.palette.primary.light})`,
|
|
18
15
|
},
|
|
19
|
-
}))
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const Anchor = ({ className, ...props }) => <StyledAnchor className={className} {...props} />;
|
|
20
19
|
|
|
21
20
|
export default Anchor;
|
|
@@ -1,58 +1,67 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
3
|
import range from 'lodash/range';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
4
|
import { strokeColor, noSelect } from '../style-utils';
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<
|
|
6
|
+
const StyledLine = styled('line')(({ theme }) => ({
|
|
7
|
+
strokeWidth: '0.2',
|
|
8
|
+
stroke: strokeColor(theme),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const Line = ({ angle, major, minor }) => (
|
|
12
|
+
<StyledLine
|
|
14
13
|
transform={`rotate(${angle}, 50.5,50)`}
|
|
15
|
-
className={classes.line}
|
|
16
14
|
style={{}}
|
|
17
15
|
x1="1"
|
|
18
16
|
x2={major ? 10 : minor ? 6 : 3}
|
|
19
17
|
y1="50"
|
|
20
18
|
y2="50"
|
|
21
19
|
/>
|
|
22
|
-
)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const StyledSpikeLine = styled('line')(({ theme }) => ({
|
|
23
|
+
strokeWidth: '0.2',
|
|
24
|
+
stroke: strokeColor(theme),
|
|
25
|
+
}));
|
|
23
26
|
|
|
24
|
-
const Spike =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
stroke: strokeColor(theme),
|
|
28
|
-
},
|
|
29
|
-
}))(({ angle, classes }) => (
|
|
30
|
-
<line transform={`rotate(${angle}, 50.5,50)`} className={classes.line} style={{}} x1="15" x2={'46'} y1="50" y2="50" />
|
|
31
|
-
));
|
|
27
|
+
const Spike = ({ angle }) => (
|
|
28
|
+
<StyledSpikeLine transform={`rotate(${angle}, 50.5,50)`} style={{}} x1="15" x2={'46'} y1="50" y2="50" />
|
|
29
|
+
);
|
|
32
30
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<
|
|
31
|
+
const StyledText = styled('text')(({ theme }) => ({
|
|
32
|
+
fontSize: '2.5px',
|
|
33
|
+
textAnchor: 'middle',
|
|
34
|
+
fill: strokeColor(theme),
|
|
35
|
+
...noSelect(),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
const Text = ({ angle }) => (
|
|
39
|
+
<StyledText transform={`rotate(${angle - 90}, 50.5, 50)`} x="50" y="12.5">
|
|
42
40
|
{angle}
|
|
43
|
-
</
|
|
44
|
-
)
|
|
41
|
+
</StyledText>
|
|
42
|
+
);
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
const StyledPath = styled('path')(({ theme }) => ({
|
|
45
|
+
strokeWidth: '0.2',
|
|
46
|
+
stroke: strokeColor(theme),
|
|
47
|
+
}));
|
|
50
48
|
|
|
49
|
+
const StyledGraphicLine = styled('line')(({ theme }) => ({
|
|
50
|
+
strokeWidth: '0.2',
|
|
51
|
+
stroke: strokeColor(theme),
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
const StyledCircle = styled('circle')(({ theme }) => ({
|
|
55
|
+
strokeWidth: '0.2',
|
|
56
|
+
stroke: strokeColor(theme),
|
|
57
|
+
fill: 'none',
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
export class Graphic extends React.PureComponent {
|
|
51
61
|
render() {
|
|
52
|
-
const { classes } = this.props;
|
|
53
62
|
return (
|
|
54
63
|
<svg viewBox="0 0 102 61">
|
|
55
|
-
<
|
|
64
|
+
<StyledPath d="M 1,50 A 1,1 0 0 1 100,50 L 100,60 L 1,60 Z" fill="none" />
|
|
56
65
|
{range(0, 181).map((r) => (
|
|
57
66
|
<Line minor={r % 5 === 0} major={r % 10 === 0} angle={r} key={r} />
|
|
58
67
|
))}
|
|
@@ -62,26 +71,12 @@ export class Graphic extends React.PureComponent {
|
|
|
62
71
|
<Text angle={r} />
|
|
63
72
|
</React.Fragment>
|
|
64
73
|
))}
|
|
65
|
-
<
|
|
66
|
-
<
|
|
67
|
-
<
|
|
74
|
+
<StyledCircle r="4" cx="50.5" cy="50" />
|
|
75
|
+
<StyledGraphicLine x1="48.5" x2="52.5" y1="50" y2="50" />
|
|
76
|
+
<StyledGraphicLine transform={'rotate(90 50.5 50)'} x1="48.5" x2="52.5" y1="50" y2="50" />
|
|
68
77
|
</svg>
|
|
69
78
|
);
|
|
70
79
|
}
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
export default
|
|
74
|
-
path: {
|
|
75
|
-
strokeWidth: '0.2',
|
|
76
|
-
stroke: strokeColor(theme),
|
|
77
|
-
},
|
|
78
|
-
line: {
|
|
79
|
-
strokeWidth: '0.2',
|
|
80
|
-
stroke: strokeColor(theme),
|
|
81
|
-
},
|
|
82
|
-
circle: {
|
|
83
|
-
strokeWidth: '0.2',
|
|
84
|
-
stroke: strokeColor(theme),
|
|
85
|
-
fill: 'none',
|
|
86
|
-
},
|
|
87
|
-
}))(Graphic);
|
|
82
|
+
export default Graphic;
|
package/src/protractor/index.jsx
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import Graphic from './graphic';
|
|
5
5
|
import Anchor from '../anchor';
|
|
6
6
|
import Rotatable from '../rotatable';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
8
|
|
|
9
|
+
const StyledProtractor = styled('div')(() => ({
|
|
10
|
+
position: 'relative',
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const StyledLeftAnchor = styled(Anchor)(() => ({
|
|
14
|
+
position: 'absolute',
|
|
15
|
+
left: 0,
|
|
16
|
+
bottom: 0,
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const StyledRightAnchor = styled(Anchor)(() => ({
|
|
20
|
+
position: 'absolute',
|
|
21
|
+
right: 0,
|
|
22
|
+
bottom: 0,
|
|
23
|
+
}));
|
|
24
|
+
|
|
9
25
|
export class Protractor extends React.Component {
|
|
10
26
|
static propTypes = {
|
|
11
|
-
classes: PropTypes.object.isRequired,
|
|
12
27
|
width: PropTypes.number.isRequired,
|
|
13
28
|
className: PropTypes.string,
|
|
14
29
|
startPosition: PropTypes.shape({
|
|
@@ -23,7 +38,7 @@ export class Protractor extends React.Component {
|
|
|
23
38
|
};
|
|
24
39
|
|
|
25
40
|
render() {
|
|
26
|
-
const {
|
|
41
|
+
const { width, className, startPosition } = this.props;
|
|
27
42
|
return (
|
|
28
43
|
<Rotatable
|
|
29
44
|
className={className}
|
|
@@ -39,27 +54,15 @@ export class Protractor extends React.Component {
|
|
|
39
54
|
},
|
|
40
55
|
]}
|
|
41
56
|
>
|
|
42
|
-
<
|
|
57
|
+
<StyledProtractor style={{ width: `${width}px` }}>
|
|
43
58
|
<Graphic />
|
|
44
59
|
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
</
|
|
60
|
+
<StyledLeftAnchor className={classNames('leftAnchor')} />
|
|
61
|
+
<StyledRightAnchor className={classNames('rightAnchor')} />
|
|
62
|
+
</StyledProtractor>
|
|
48
63
|
</Rotatable>
|
|
49
64
|
);
|
|
50
65
|
}
|
|
51
66
|
}
|
|
52
67
|
|
|
53
|
-
export default
|
|
54
|
-
protractor: { position: 'relative' },
|
|
55
|
-
leftAnchor: {
|
|
56
|
-
position: 'absolute',
|
|
57
|
-
left: 0,
|
|
58
|
-
bottom: 0,
|
|
59
|
-
},
|
|
60
|
-
rightAnchor: {
|
|
61
|
-
position: 'absolute',
|
|
62
|
-
right: 0,
|
|
63
|
-
bottom: 0,
|
|
64
|
-
},
|
|
65
|
-
}))(Protractor);
|
|
68
|
+
export default Protractor;
|
package/src/rotatable.jsx
CHANGED
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
4
|
import { getAnchor as calcAnchor, distanceBetween, arctangent } from './anchor-utils';
|
|
5
5
|
import { Portal } from 'react-portal';
|
|
6
6
|
import Point from '@mapbox/point-geometry';
|
|
7
7
|
import { parse as parseOrigin } from './transform-origin';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})(({ classes, left, top, color, fill }) => {
|
|
8
|
+
|
|
9
|
+
const AnchorSvg = styled('svg')({
|
|
10
|
+
position: 'absolute',
|
|
11
|
+
zIndex: 100,
|
|
12
|
+
width: '200px',
|
|
13
|
+
height: '80px',
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const Anchor = ({ left, top, color, fill }) => {
|
|
18
17
|
color = color || 'green';
|
|
19
18
|
fill = fill || 'white';
|
|
20
19
|
return (
|
|
21
20
|
<Portal>
|
|
22
|
-
<
|
|
23
|
-
className={classes.anchor}
|
|
21
|
+
<AnchorSvg
|
|
24
22
|
style={{
|
|
25
23
|
left: left - 10,
|
|
26
24
|
top: top - 10,
|
|
27
25
|
}}
|
|
28
26
|
>
|
|
29
27
|
<circle cx={10} cy={10} r={8} strokeWidth={1} stroke={color} fill={fill} />
|
|
30
|
-
</
|
|
28
|
+
</AnchorSvg>
|
|
31
29
|
</Portal>
|
|
32
30
|
);
|
|
33
|
-
}
|
|
31
|
+
};
|
|
34
32
|
|
|
35
33
|
/**
|
|
36
34
|
* Tip o' the hat to:
|
|
37
35
|
* https://bl.ocks.org/joyrexus/7207044
|
|
38
36
|
*/
|
|
37
|
+
const RotatableContainer = styled('div')({
|
|
38
|
+
position: 'relative',
|
|
39
|
+
display: 'inline-block',
|
|
40
|
+
cursor: 'move',
|
|
41
|
+
});
|
|
42
|
+
|
|
39
43
|
export class Rotatable extends React.Component {
|
|
40
44
|
static propTypes = {
|
|
41
|
-
classes: PropTypes.object.isRequired,
|
|
42
45
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
43
46
|
showAnchor: PropTypes.bool,
|
|
44
47
|
handle: PropTypes.arrayOf(
|
|
@@ -259,7 +262,7 @@ export class Rotatable extends React.Component {
|
|
|
259
262
|
};
|
|
260
263
|
|
|
261
264
|
render() {
|
|
262
|
-
const { children,
|
|
265
|
+
const { children, showAnchor, className } = this.props;
|
|
263
266
|
const { rotation, anchor, origin, translate, position } = this.state;
|
|
264
267
|
|
|
265
268
|
const t = translate ? `translate(${translate.x}px, ${translate.y}px)` : '';
|
|
@@ -272,8 +275,8 @@ export class Rotatable extends React.Component {
|
|
|
272
275
|
};
|
|
273
276
|
|
|
274
277
|
return (
|
|
275
|
-
<
|
|
276
|
-
className={
|
|
278
|
+
<RotatableContainer
|
|
279
|
+
className={className}
|
|
277
280
|
style={style}
|
|
278
281
|
ref={(r) => (this.rotatable = r)}
|
|
279
282
|
onMouseDown={this.mouseDown}
|
|
@@ -281,15 +284,9 @@ export class Rotatable extends React.Component {
|
|
|
281
284
|
>
|
|
282
285
|
{anchor && showAnchor && <Anchor {...anchor} />}
|
|
283
286
|
{children}
|
|
284
|
-
</
|
|
287
|
+
</RotatableContainer>
|
|
285
288
|
);
|
|
286
289
|
}
|
|
287
290
|
}
|
|
288
291
|
|
|
289
|
-
export default
|
|
290
|
-
rotatable: {
|
|
291
|
-
position: 'relative',
|
|
292
|
-
display: 'inline-block',
|
|
293
|
-
cursor: 'move',
|
|
294
|
-
},
|
|
295
|
-
})(Rotatable);
|
|
292
|
+
export default Rotatable;
|
package/src/ruler/graphic.jsx
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
4
|
import UnitType from './unit-type';
|
|
5
5
|
import range from 'lodash/range';
|
|
6
6
|
import Unit from './unit';
|
|
7
7
|
import { strokeColor, fillColor } from '../style-utils';
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const StyledBg = styled('rect')(({ theme }) => ({
|
|
10
|
+
stroke: strokeColor(theme),
|
|
11
|
+
strokeWidth: '2px',
|
|
12
|
+
fill: fillColor(theme),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const Bg = ({ width, height }) => <StyledBg width={width} height={height} cx={0} cy={0} />;
|
|
10
16
|
|
|
11
17
|
Bg.propTypes = {
|
|
12
18
|
width: PropTypes.number.isRequired,
|
|
13
19
|
height: PropTypes.number.isRequired,
|
|
14
|
-
className: PropTypes.string.isRequired,
|
|
15
20
|
};
|
|
16
21
|
|
|
17
22
|
export class Graphic extends React.PureComponent {
|
|
@@ -20,18 +25,17 @@ export class Graphic extends React.PureComponent {
|
|
|
20
25
|
height: PropTypes.number.isRequired,
|
|
21
26
|
units: PropTypes.number.isRequired,
|
|
22
27
|
unit: PropTypes.object.isRequired,
|
|
23
|
-
classes: PropTypes.object.isRequired,
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
render() {
|
|
27
|
-
const { width, height,
|
|
31
|
+
const { width, height, units, unit } = this.props;
|
|
28
32
|
const viewBox = `0 0 ${width} ${height}`;
|
|
29
33
|
const unitWidth = width / units;
|
|
30
34
|
const unitHeight = height;
|
|
31
35
|
|
|
32
36
|
return (
|
|
33
37
|
<svg viewBox={viewBox}>
|
|
34
|
-
<Bg width={width} height={height}
|
|
38
|
+
<Bg width={width} height={height} />
|
|
35
39
|
<UnitType label={unit.type} />
|
|
36
40
|
{range(1, units + 1).map((r) => (
|
|
37
41
|
<Unit width={unitWidth} height={unitHeight} key={r} index={r} config={unit} last={r === units} />
|
|
@@ -40,12 +44,5 @@ export class Graphic extends React.PureComponent {
|
|
|
40
44
|
);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
|
-
const styles = (theme) => ({
|
|
44
|
-
bg: {
|
|
45
|
-
stroke: strokeColor(theme),
|
|
46
|
-
strokeWidth: '2px',
|
|
47
|
-
fill: fillColor(theme),
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
47
|
|
|
51
|
-
export default
|
|
48
|
+
export default Graphic;
|
package/src/ruler/index.jsx
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
3
|
import Rotatable from '../rotatable';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import RulerGraphic from './graphic';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import Anchor from '../anchor';
|
|
8
8
|
|
|
9
|
+
const StyledRuler = styled('div')(({ theme }) => ({
|
|
10
|
+
cursor: 'move',
|
|
11
|
+
position: 'relative',
|
|
12
|
+
backgroundColor: theme.palette.secondary.light,
|
|
13
|
+
opacity: 1.0,
|
|
14
|
+
border: `solid 0px ${theme.palette.primary.main}`,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const StyledLeftAnchor = styled(Anchor)(() => ({
|
|
18
|
+
left: '-10px',
|
|
19
|
+
top: '40%',
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const StyledRightAnchor = styled(Anchor)(() => ({
|
|
23
|
+
right: '-10px',
|
|
24
|
+
top: '40%',
|
|
25
|
+
}));
|
|
26
|
+
|
|
9
27
|
export class Ruler extends React.Component {
|
|
10
28
|
static propTypes = {
|
|
11
29
|
width: PropTypes.number,
|
|
12
30
|
height: PropTypes.number,
|
|
13
31
|
units: PropTypes.number.isRequired,
|
|
14
32
|
measure: PropTypes.oneOf(['imperial', 'metric']).isRequired,
|
|
15
|
-
classes: PropTypes.object.isRequired,
|
|
16
33
|
className: PropTypes.string,
|
|
17
34
|
startPosition: PropTypes.shape({
|
|
18
35
|
left: PropTypes.number.isRequired,
|
|
@@ -30,7 +47,7 @@ export class Ruler extends React.Component {
|
|
|
30
47
|
};
|
|
31
48
|
|
|
32
49
|
render() {
|
|
33
|
-
const {
|
|
50
|
+
const { width, height, units, measure, className, startPosition, label, tickCount } = this.props;
|
|
34
51
|
|
|
35
52
|
const unit =
|
|
36
53
|
measure === 'imperial'
|
|
@@ -51,31 +68,14 @@ export class Ruler extends React.Component {
|
|
|
51
68
|
{ class: 'rightAnchor', origin: 'bottom left' },
|
|
52
69
|
]}
|
|
53
70
|
>
|
|
54
|
-
<
|
|
71
|
+
<StyledRuler style={{ width: `${width}px`, height: `${height}px` }}>
|
|
55
72
|
<RulerGraphic width={width} height={height} units={units} unit={unit} />
|
|
56
|
-
<
|
|
57
|
-
<
|
|
58
|
-
</
|
|
73
|
+
<StyledLeftAnchor className={classNames('leftAnchor')} />
|
|
74
|
+
<StyledRightAnchor className={classNames('rightAnchor')} />
|
|
75
|
+
</StyledRuler>
|
|
59
76
|
</Rotatable>
|
|
60
77
|
);
|
|
61
78
|
}
|
|
62
79
|
}
|
|
63
|
-
const styles = (theme) => ({
|
|
64
|
-
ruler: {
|
|
65
|
-
cursor: 'move',
|
|
66
|
-
position: 'relative',
|
|
67
|
-
backgroundColor: theme.palette.secondary.light,
|
|
68
|
-
opacity: 1.0,
|
|
69
|
-
border: `solid 0px ${theme.palette.primary.main}`,
|
|
70
|
-
},
|
|
71
|
-
leftAnchor: {
|
|
72
|
-
left: '-10px',
|
|
73
|
-
top: '40%',
|
|
74
|
-
},
|
|
75
|
-
rightAnchor: {
|
|
76
|
-
right: '-10px',
|
|
77
|
-
top: '40%',
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
80
|
|
|
81
|
-
export default
|
|
81
|
+
export default Ruler;
|
package/src/ruler/unit-type.jsx
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { noSelect, strokeColor } from '../style-utils';
|
|
4
|
-
import {
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
|
|
6
|
+
const StyledText = styled('text')(({ theme }) => ({
|
|
7
|
+
...noSelect(),
|
|
8
|
+
fill: strokeColor(theme),
|
|
9
|
+
}));
|
|
5
10
|
|
|
6
11
|
export const UnitType = (props) => {
|
|
7
|
-
const {
|
|
12
|
+
const { label, x, y, textAlign, fill, fontSize, stroke } = props;
|
|
8
13
|
|
|
9
14
|
return (
|
|
10
|
-
<
|
|
11
|
-
className={classes.unitType}
|
|
15
|
+
<StyledText
|
|
12
16
|
x={x}
|
|
13
17
|
y={y}
|
|
14
18
|
textAnchor={textAlign}
|
|
@@ -17,12 +21,11 @@ export const UnitType = (props) => {
|
|
|
17
21
|
fontSize={fontSize}
|
|
18
22
|
>
|
|
19
23
|
{label}
|
|
20
|
-
</
|
|
24
|
+
</StyledText>
|
|
21
25
|
);
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
UnitType.propTypes = {
|
|
25
|
-
classes: PropTypes.object.isRequired,
|
|
26
29
|
label: PropTypes.string.isRequired,
|
|
27
30
|
x: PropTypes.number,
|
|
28
31
|
y: PropTypes.number,
|
|
@@ -40,6 +43,4 @@ UnitType.defaultProps = {
|
|
|
40
43
|
y: 14,
|
|
41
44
|
};
|
|
42
45
|
|
|
43
|
-
export default
|
|
44
|
-
unitType: { ...noSelect(), fill: strokeColor(theme) },
|
|
45
|
-
}))(UnitType);
|
|
46
|
+
export default UnitType;
|