@pie-lib/tools 0.9.22 → 0.9.25

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/src/rotatable.jsx CHANGED
@@ -12,8 +12,8 @@ const Anchor = withStyles({
12
12
  position: 'absolute',
13
13
  zIndex: 100,
14
14
  width: '200px',
15
- height: '80px'
16
- }
15
+ height: '80px',
16
+ },
17
17
  })(({ classes, left, top, color, fill }) => {
18
18
  color = color || 'green';
19
19
  fill = fill || 'white';
@@ -23,7 +23,7 @@ const Anchor = withStyles({
23
23
  className={classes.anchor}
24
24
  style={{
25
25
  left: left - 10,
26
- top: top - 10
26
+ top: top - 10,
27
27
  }}
28
28
  >
29
29
  <circle cx={10} cy={10} r={8} strokeWidth={1} stroke={color} fill={fill} />
@@ -44,19 +44,19 @@ export class Rotatable extends React.Component {
44
44
  handle: PropTypes.arrayOf(
45
45
  PropTypes.shape({
46
46
  class: PropTypes.string.isRequired,
47
- origin: PropTypes.string
48
- })
47
+ origin: PropTypes.string,
48
+ }),
49
49
  ),
50
50
  className: PropTypes.string,
51
51
  startPosition: PropTypes.shape({
52
52
  left: PropTypes.number,
53
- top: PropTypes.number
54
- })
53
+ top: PropTypes.number,
54
+ }),
55
55
  };
56
56
 
57
57
  static defaultProps = {
58
58
  showAnchor: false,
59
- startPosition: { left: 0, top: 0 }
59
+ startPosition: { left: 0, top: 0 },
60
60
  };
61
61
 
62
62
  constructor(props) {
@@ -68,8 +68,8 @@ export class Rotatable extends React.Component {
68
68
  angle: 0,
69
69
  position: {
70
70
  left: props.startPosition.left,
71
- top: props.startPosition.top
72
- }
71
+ top: props.startPosition.top,
72
+ },
73
73
  };
74
74
  }
75
75
 
@@ -78,7 +78,7 @@ export class Rotatable extends React.Component {
78
78
  document.removeEventListener('mousemove', this.drag);
79
79
  document.removeEventListener('mousemove', this.rotate);
80
80
 
81
- this.handles.forEach(h => {
81
+ this.handles.forEach((h) => {
82
82
  h.el.removeEventListener('mousedown', h.mousedownHandler);
83
83
  h.el.removeEventListener('mouseup', this.rotateStop);
84
84
  });
@@ -94,7 +94,7 @@ export class Rotatable extends React.Component {
94
94
 
95
95
  if (Array.isArray(handle)) {
96
96
  this.handles = [];
97
- handle.forEach(h => {
97
+ handle.forEach((h) => {
98
98
  const el = this.rotatable.querySelector(`.${h.class}`);
99
99
 
100
100
  if (el) {
@@ -111,7 +111,7 @@ export class Rotatable extends React.Component {
111
111
  document.addEventListener('mouseup', this.rotateStop);
112
112
  };
113
113
 
114
- originToXY = origin => {
114
+ originToXY = (origin) => {
115
115
  const { clientWidth: width, clientHeight: height } = this.rotatable;
116
116
  return parseOrigin({ width, height }, origin);
117
117
  };
@@ -120,7 +120,7 @@ export class Rotatable extends React.Component {
120
120
  * Get the anchor point for the given element, origin and rotation.
121
121
  * @returns {{left:number, top: number}} - the co-ordinates of the anchor point relative to the whole page.
122
122
  */
123
- getAnchor = origin => {
123
+ getAnchor = (origin) => {
124
124
  const { rotation } = this.state;
125
125
  const { clientWidth, clientHeight } = this.rotatable;
126
126
  const { top, left } = this.rotatable.getBoundingClientRect();
@@ -128,19 +128,19 @@ export class Rotatable extends React.Component {
128
128
  const { top: anchorTop, left: anchorLeft } = calcAnchor(
129
129
  {
130
130
  width: clientWidth,
131
- height: clientHeight
131
+ height: clientHeight,
132
132
  },
133
133
  xy,
134
- rotation
134
+ rotation,
135
135
  );
136
136
 
137
137
  return {
138
138
  top: top + anchorTop,
139
- left: left + anchorLeft
139
+ left: left + anchorLeft,
140
140
  };
141
141
  };
142
142
 
143
- rotateStart = origin => e => {
143
+ rotateStart = (origin) => (e) => {
144
144
  const { isRotating } = this.state;
145
145
  if (isRotating) {
146
146
  return;
@@ -166,16 +166,16 @@ export class Rotatable extends React.Component {
166
166
  anchor,
167
167
  position: {
168
168
  left: this.state.position.left + diff.x,
169
- top: this.state.position.top + diff.y
170
- }
169
+ top: this.state.position.top + diff.y,
170
+ },
171
171
  },
172
172
  () => {
173
173
  document.addEventListener('mousemove', this.rotate);
174
- }
174
+ },
175
175
  );
176
176
  };
177
177
 
178
- rotateStop = e => {
178
+ rotateStop = (e) => {
179
179
  const { isRotating } = this.state;
180
180
 
181
181
  if (!isRotating) {
@@ -189,12 +189,12 @@ export class Rotatable extends React.Component {
189
189
  isRotating: false,
190
190
  angle: this.state.rotation,
191
191
  anchor: null,
192
- current: null
192
+ current: null,
193
193
  },
194
194
  () => {
195
195
  document.removeEventListener('mousemove', this.rotate);
196
196
  document.removeEventListener('mousemove', this.drag);
197
- }
197
+ },
198
198
  );
199
199
  };
200
200
 
@@ -204,7 +204,7 @@ export class Rotatable extends React.Component {
204
204
  return { angle: arctangent(x, y), x, y };
205
205
  }
206
206
 
207
- rotate = e => {
207
+ rotate = (e) => {
208
208
  const { isRotating } = this.state;
209
209
  if (!isRotating) {
210
210
  return;
@@ -220,22 +220,22 @@ export class Rotatable extends React.Component {
220
220
  this.setState({ rotation, diff, current, computedAnchor });
221
221
  };
222
222
 
223
- mouseDown = e => {
224
- const handle = this.handles.find(h => h.el === e.target);
223
+ mouseDown = (e) => {
224
+ const handle = this.handles.find((h) => h.el === e.target);
225
225
 
226
226
  if (!handle) {
227
227
  this.dragStart(e);
228
228
  }
229
229
  };
230
230
 
231
- dragStart = e => {
231
+ dragStart = (e) => {
232
232
  const dragPoint = new Point(e.pageX, e.pageY);
233
233
  this.setState({ dragPoint }, () => {
234
234
  document.addEventListener('mousemove', this.drag);
235
235
  });
236
236
  };
237
237
 
238
- drag = e => {
238
+ drag = (e) => {
239
239
  e.preventDefault();
240
240
  const current = new Point(e.pageX, e.pageY);
241
241
  const translate = current.sub(this.state.dragPoint);
@@ -251,7 +251,7 @@ export class Rotatable extends React.Component {
251
251
 
252
252
  const position = {
253
253
  left: lastPosition.left + translate.x,
254
- top: lastPosition.top + translate.y
254
+ top: lastPosition.top + translate.y,
255
255
  };
256
256
 
257
257
  document.removeEventListener('mousemove', this.drag);
@@ -268,14 +268,14 @@ export class Rotatable extends React.Component {
268
268
  left: position.left,
269
269
  top: position.top,
270
270
  transformOrigin: origin,
271
- transform: `${t} rotate(${rotation}deg)`
271
+ transform: `${t} rotate(${rotation}deg)`,
272
272
  };
273
273
 
274
274
  return (
275
275
  <div
276
276
  className={classNames(classes.rotatable, className)}
277
277
  style={style}
278
- ref={r => (this.rotatable = r)}
278
+ ref={(r) => (this.rotatable = r)}
279
279
  onMouseDown={this.mouseDown}
280
280
  onMouseUp={this.mouseUp}
281
281
  >
@@ -290,6 +290,6 @@ export default withStyles({
290
290
  rotatable: {
291
291
  position: 'relative',
292
292
  display: 'inline-block',
293
- cursor: 'move'
294
- }
293
+ cursor: 'move',
294
+ },
295
295
  })(Rotatable);
@@ -6,14 +6,12 @@ import range from 'lodash/range';
6
6
  import Unit from './unit';
7
7
  import { strokeColor, fillColor } from '../style-utils';
8
8
 
9
- const Bg = ({ width, height, className }) => (
10
- <rect width={width} height={height} cx={0} cy={0} className={className} />
11
- );
9
+ const Bg = ({ width, height, className }) => <rect width={width} height={height} cx={0} cy={0} className={className} />;
12
10
 
13
11
  Bg.propTypes = {
14
12
  width: PropTypes.number.isRequired,
15
13
  height: PropTypes.number.isRequired,
16
- className: PropTypes.string.isRequired
14
+ className: PropTypes.string.isRequired,
17
15
  };
18
16
 
19
17
  export class Graphic extends React.PureComponent {
@@ -22,7 +20,7 @@ export class Graphic extends React.PureComponent {
22
20
  height: PropTypes.number.isRequired,
23
21
  units: PropTypes.number.isRequired,
24
22
  unit: PropTypes.object.isRequired,
25
- classes: PropTypes.object.isRequired
23
+ classes: PropTypes.object.isRequired,
26
24
  };
27
25
 
28
26
  render() {
@@ -35,26 +33,19 @@ export class Graphic extends React.PureComponent {
35
33
  <svg viewBox={viewBox}>
36
34
  <Bg width={width} height={height} className={classes.bg} />
37
35
  <UnitType label={unit.type} />
38
- {range(1, units + 1).map(r => (
39
- <Unit
40
- width={unitWidth}
41
- height={unitHeight}
42
- key={r}
43
- index={r}
44
- config={unit}
45
- last={r === units}
46
- />
36
+ {range(1, units + 1).map((r) => (
37
+ <Unit width={unitWidth} height={unitHeight} key={r} index={r} config={unit} last={r === units} />
47
38
  ))}
48
39
  </svg>
49
40
  );
50
41
  }
51
42
  }
52
- const styles = theme => ({
43
+ const styles = (theme) => ({
53
44
  bg: {
54
45
  stroke: strokeColor(theme),
55
46
  strokeWidth: '2px',
56
- fill: fillColor(theme)
57
- }
47
+ fill: fillColor(theme),
48
+ },
58
49
  });
59
50
 
60
51
  export default withStyles(styles)(Graphic);
@@ -16,41 +16,31 @@ export class Ruler extends React.Component {
16
16
  className: PropTypes.string,
17
17
  startPosition: PropTypes.shape({
18
18
  left: PropTypes.number.isRequired,
19
- top: PropTypes.number.isRequired
19
+ top: PropTypes.number.isRequired,
20
20
  }),
21
21
  label: PropTypes.string,
22
- tickCount: PropTypes.number
22
+ tickCount: PropTypes.number,
23
23
  };
24
24
 
25
25
  static defaultProps = {
26
26
  width: 480,
27
27
  height: 60,
28
28
  measure: 'imperial',
29
- units: 12
29
+ units: 12,
30
30
  };
31
31
 
32
32
  render() {
33
- const {
34
- classes,
35
- width,
36
- height,
37
- units,
38
- measure,
39
- className,
40
- startPosition,
41
- label,
42
- tickCount
43
- } = this.props;
33
+ const { classes, width, height, units, measure, className, startPosition, label, tickCount } = this.props;
44
34
 
45
35
  const unit =
46
36
  measure === 'imperial'
47
37
  ? {
48
38
  type: label,
49
- ticks: tickCount && tickCount % 4 === 0 ? tickCount : 16
39
+ ticks: tickCount && tickCount % 4 === 0 ? tickCount : 16,
50
40
  }
51
41
  : {
52
42
  type: label,
53
- ticks: 10
43
+ ticks: 10,
54
44
  };
55
45
  return (
56
46
  <Rotatable
@@ -58,7 +48,7 @@ export class Ruler extends React.Component {
58
48
  startPosition={startPosition}
59
49
  handle={[
60
50
  { class: 'leftAnchor', origin: 'bottom right' },
61
- { class: 'rightAnchor', origin: 'bottom left' }
51
+ { class: 'rightAnchor', origin: 'bottom left' },
62
52
  ]}
63
53
  >
64
54
  <div className={classes.ruler} style={{ width: `${width}px`, height: `${height}px` }}>
@@ -70,22 +60,22 @@ export class Ruler extends React.Component {
70
60
  );
71
61
  }
72
62
  }
73
- const styles = theme => ({
63
+ const styles = (theme) => ({
74
64
  ruler: {
75
65
  cursor: 'move',
76
66
  position: 'relative',
77
67
  backgroundColor: theme.palette.secondary.light,
78
68
  opacity: 1.0,
79
- border: `solid 0px ${theme.palette.primary.main}`
69
+ border: `solid 0px ${theme.palette.primary.main}`,
80
70
  },
81
71
  leftAnchor: {
82
72
  left: '-10px',
83
- top: '40%'
73
+ top: '40%',
84
74
  },
85
75
  rightAnchor: {
86
76
  right: '-10px',
87
- top: '40%'
88
- }
77
+ top: '40%',
78
+ },
89
79
  });
90
80
 
91
81
  export default withStyles(styles)(Ruler);
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { noSelect, strokeColor } from '../style-utils';
4
4
  import { withStyles } from '@material-ui/core/styles';
5
5
 
6
- export const UnitType = props => {
6
+ export const UnitType = (props) => {
7
7
  const { classes, label, x, y, textAlign, fill, fontSize, stroke } = props;
8
8
 
9
9
  return (
@@ -29,7 +29,7 @@ UnitType.propTypes = {
29
29
  textAlign: PropTypes.string,
30
30
  fill: PropTypes.string,
31
31
  fontSize: PropTypes.number,
32
- stroke: PropTypes.string
32
+ stroke: PropTypes.string,
33
33
  };
34
34
 
35
35
  UnitType.defaultProps = {
@@ -37,9 +37,9 @@ UnitType.defaultProps = {
37
37
  fontSize: 11,
38
38
  stroke: 'none',
39
39
  x: 8,
40
- y: 14
40
+ y: 14,
41
41
  };
42
42
 
43
- export default withStyles(theme => ({
44
- unitType: { ...noSelect(), fill: strokeColor(theme) }
43
+ export default withStyles((theme) => ({
44
+ unitType: { ...noSelect(), fill: strokeColor(theme) },
45
45
  }))(UnitType);
@@ -4,10 +4,10 @@ import { withStyles } from '@material-ui/core/styles';
4
4
  import { noSelect, strokeColor } from '../style-utils';
5
5
  import range from 'lodash/range';
6
6
 
7
- const Tick = withStyles(theme => ({
7
+ const Tick = withStyles((theme) => ({
8
8
  tick: {
9
- stroke: strokeColor(theme)
10
- }
9
+ stroke: strokeColor(theme),
10
+ },
11
11
  }))(({ x, height, bottom, classes, major, minor }) => {
12
12
  const y1 = major ? bottom - height * 2 : minor ? bottom - height * 1.5 : bottom - height;
13
13
 
@@ -17,7 +17,7 @@ const Tick = withStyles(theme => ({
17
17
  const Ticks = ({ count, width, height }) => {
18
18
  return (
19
19
  <React.Fragment>
20
- {range(1, count).map(r => {
20
+ {range(1, count).map((r) => {
21
21
  return (
22
22
  <Tick
23
23
  key={r}
@@ -37,7 +37,7 @@ const Ticks = ({ count, width, height }) => {
37
37
  Ticks.propTypes = {
38
38
  count: PropTypes.number.isRequired,
39
39
  width: PropTypes.number.isRequired,
40
- height: PropTypes.number.isRequired
40
+ height: PropTypes.number.isRequired,
41
41
  };
42
42
 
43
43
  export class Unit extends React.Component {
@@ -47,14 +47,14 @@ export class Unit extends React.Component {
47
47
  height: PropTypes.number.isRequired,
48
48
  classes: PropTypes.object.isRequired,
49
49
  last: PropTypes.bool.isRequired,
50
- config: PropTypes.object.isRequired
50
+ config: PropTypes.object.isRequired,
51
51
  };
52
52
 
53
53
  render() {
54
54
  const { index, width, height, classes, last, config } = this.props;
55
55
 
56
56
  const style = {
57
- transform: `translate(${width * (index - 1)}px, 0px)`
57
+ transform: `translate(${width * (index - 1)}px, 0px)`,
58
58
  };
59
59
  return (
60
60
  <g style={style}>
@@ -69,19 +69,19 @@ export class Unit extends React.Component {
69
69
  }
70
70
  }
71
71
 
72
- export default withStyles(theme => ({
72
+ export default withStyles((theme) => ({
73
73
  endTick: {
74
74
  stroke: strokeColor(theme),
75
- strokeWidth: 1
75
+ strokeWidth: 1,
76
76
  },
77
77
  label: {
78
78
  textAnchor: 'end',
79
79
  fontSize: '12px',
80
80
  fill: strokeColor(theme),
81
- ...noSelect()
81
+ ...noSelect(),
82
82
  },
83
83
  base: {
84
84
  fill: 'none',
85
- stroke: 'red'
86
- }
85
+ stroke: 'red',
86
+ },
87
87
  }))(Unit);
@@ -2,6 +2,6 @@ import { noSelect } from '@pie-lib/style-utils';
2
2
 
3
3
  export { noSelect };
4
4
 
5
- export const strokeColor = theme => `var(--ruler-stroke, ${theme.palette.primary.main})`;
5
+ export const strokeColor = (theme) => `var(--ruler-stroke, ${theme.palette.primary.main})`;
6
6
 
7
- export const fillColor = theme => `var(--ruler-bg, ${theme.palette.primary.contrastText})`;
7
+ export const fillColor = (theme) => `var(--ruler-bg, ${theme.palette.primary.contrastText})`;
@@ -1,4 +1,4 @@
1
- const keyWordToPercent = v => {
1
+ const keyWordToPercent = (v) => {
2
2
  if (v === 'left' || v === 'top') {
3
3
  return 0;
4
4
  } else if (v === 'right' || v === 'bottom') {
@@ -22,7 +22,7 @@ const getValue = (s, length) => {
22
22
  }
23
23
  };
24
24
 
25
- const normalize = a => {
25
+ const normalize = (a) => {
26
26
  if (a[0] === 'bottom' || a[0] === 'top' || a[1] === 'left' || a[1] === 'right') {
27
27
  return [a[1], a[0]];
28
28
  } else {
@@ -40,7 +40,7 @@ export const parse = (rect, value) => {
40
40
  if (!value) {
41
41
  return {
42
42
  x: rect.width / 2,
43
- y: rect.height / 2
43
+ y: rect.height / 2,
44
44
  };
45
45
  }
46
46
  const arr = value.split(' ');