Skip to content

Commit 77b8b7c

Browse files
committed
point, little handle: refactor to preact
1 parent 9e6423a commit 77b8b7c

13 files changed

+807
-72
lines changed

app/build/mojs-curve-editor.js

Lines changed: 587 additions & 19 deletions
Large diffs are not rendered by default.

app/build/mojs-curve-editor.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/css/blocks/curve.postcss.css

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/css/blocks/curve.postcss.css.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"curve":"_curve_v5h9c_5","curve__background":"_curve__background_v5h9c_1","curve__svg-wrapper":"_curve__svg-wrapper_v5h9c_1","curve__svg":"_curve__svg_v5h9c_1","curve__svg-segment":"_curve__svg-segment_v5h9c_1"}
1+
{"curve":"_curve_1u41l_5","curve__background":"_curve__background_1u41l_1","curve__svg-wrapper":"_curve__svg-wrapper_1u41l_1","curve__svg":"_curve__svg_1u41l_1","curve__svg-segment":"_curve__svg-segment_1u41l_1"}

app/css/blocks/point.postcss.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $size: 10;
2525
margin-top: calc( -$size*$PX );
2626
}
2727

28-
little-handle { display: none; }
28+
[data-component="little-handle"] { display: none; }
2929

3030
&:hover,
3131
&.is-selected {
@@ -34,13 +34,13 @@ $size: 10;
3434
}
3535

3636
&.is-selected {
37-
& little-handle {
37+
& [data-component="little-handle"] {
3838
display: block;
3939
}
4040
}
4141

4242
&.is-hide-handles {
43-
& little-handle {
43+
& [data-component="little-handle"] {
4444
display: none;
4545
}
4646
}

app/css/blocks/point.postcss.css.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"point":"_point_1xqxg_5","point__touch":"_point__touch_1xqxg_1","is-selected":"_is-selected_1xqxg_31","is-hide-handles":"_is-hide-handles_1xqxg_42"}
1+
{"point":"_point_17pb1_5","point__touch":"_point__touch_17pb1_1","is-selected":"_is-selected_17pb1_31","is-hide-handles":"_is-hide-handles_17pb1_42"}

app/js/helpers/clamp.babel.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
export default (value, min, max) => {
4+
return (value < min)
5+
? min
6+
: (value > max) ? max : value;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default (x, y) => {
2+
let radius = Math.sqrt( x*x + y*y ),
3+
angle = Math.atan( y/x ) * (180/Math.PI) - 90;
4+
if ( x > 0 ) { angle = angle - 180 };
5+
6+
return { radius, angle };
7+
}

app/js/tags/curve-editor-right.babel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ResizeHandle from './resize-handle';
44

55
const CLASSES = require('../../css/blocks/curve-editor.postcss.css.json');
66

7-
const CurveEditorRight = (state) => {
7+
const CurveEditorRight = ({state}) => {
88
return (<div className={CLASSES['curve-editor__right']}>
99
<Curve state ={ state } />
1010
<ResizeHandle type="top" className={ CLASSES['curve-editor__resize-handle'] } />

app/js/tags/curve.babel.jsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,68 @@
11
import { h, Component } from 'preact';
22
import mod from '../helpers/resize-mod';
33
import C from '../constants';
4+
import Point from './point';
45
require('../../css/blocks/curve');
56

67
const CLASSES = require('../../css/blocks/curve.postcss.css.json');
78
class Curve extends Component {
89
render () {
9-
const styles = this._getStyle( this.props.state );
10+
const {state} = this.props,
11+
styles = this._getStyle( state ),
12+
points = this._renderPoints( state );
1013

1114
return <div className={CLASSES['curve']}>
12-
<div
13-
className={ CLASSES['curve__background']}
14-
style={styles.background} />
15-
<div
16-
className={ CLASSES['curve__svg-wrapper']}
17-
style={styles.transform}>
15+
<div className={ CLASSES['curve__background']}
16+
style={styles.background} />
17+
<div className={ CLASSES['curve__svg-wrapper']}
18+
style={styles.transform}>
19+
20+
{ points }
1821

1922
<svg height={ C.CURVE_SIZE }
2023
viewBox="0 0 100 100"
2124
preserveAspectRatio="none"
2225
class={ CLASSES['curve__svg'] }>
23-
2426
</svg>
2527

2628
</div>
2729

2830
</div>;
2931
}
3032

31-
_getStyle({state}) {
33+
_getStyle(state) {
3234
const {resize} = state;
33-
let {temp_top, temp_bottom, temp_right} = resize;
35+
let {temp_top, temp_right} = resize;
3436

3537
temp_top += resize.top;
36-
temp_bottom += resize.bottom;
3738
temp_right += resize.right;
3839

3940
if (C.CURVE_SIZE - temp_top < C.CURVE_SIZE) { temp_top = 0; }
4041
temp_top = mod( temp_top, -1 );
4142

4243
const scale = `transform: scaleX(${(C.CURVE_SIZE + Math.max(temp_right,0))/C.CURVE_SIZE})`,
4344
bgTransform = `${mojs.h.prefix.css}${scale}; ${scale};`,
44-
background = `background-position: 0 ${-temp_top - 1}px; height: ${C.CURVE_SIZE + Math.max(Math.abs(temp_top), 0) + Math.max(temp_bottom, 0)}px; ${bgTransform}`,
45+
background = `background-position: 0 ${-temp_top - 1}px; ${bgTransform}`,
4546
transform = `transform: translate(0px, ${-temp_top}px)`;
46-
4747
return {
4848
background,
4949
transform: `${mojs.h.prefix.css}${transform}; ${transform};`
5050
};
5151
}
52+
53+
_renderPoints (state) {
54+
const pointsData = state.points.present,
55+
points = [],
56+
len = pointsData.length;
57+
58+
for (var i = 0; i < len; i++) {
59+
points.push(
60+
<Point point={ pointsData[i] } state={state} index={i} pointsCount={len} />
61+
);
62+
}
63+
64+
return points;
65+
}
5266
}
5367

5468
export default Curve;

0 commit comments

Comments
 (0)