Skip to content

Commit c565a36

Browse files
committed
refactor to preact
1 parent 7468163 commit c565a36

20 files changed

+9767
-9176
lines changed

app/build/mojs-curve-editor.js

Lines changed: 9382 additions & 8987 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/code-panel.postcss.css

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,35 @@
44
position: absolute;
55
left: calc( 10 * $PX );
66
right: calc( 10 * $PX );
7-
margin-top: calc( -32 * $PX );
8-
border-radius: calc( 6 * $PX ) calc( 6 * $PX ) 0 0;
9-
background: rgba( 61, 27, 60, 1 );
7+
bottom: 100%;
8+
/*margin-top: calc( -32 * $PX );*/
109
z-index: 1;
11-
display: none;
10+
overflow: hidden;
11+
/*border: 1px solid red;*/
12+
padding-top: calc( 16*$PX );
13+
box-sizing: content-box;
14+
/*height: 0;*/
15+
/*transition: height .2s ease-out;*/
16+
/*transform: scale(0); */
17+
18+
&__inner {
19+
border-radius: calc( 6 * $PX ) calc( 6 * $PX ) 0 0;
20+
background: rgba( 61, 27, 60, 1 );
21+
padding: calc( 4 * $PX ) calc( 5 * $PX ) calc( 5 * $PX );
22+
/*width: 100%;
23+
height: 100%;
24+
position: absolute;*/
25+
transform: translateY(100%);
26+
transition: all .2s ease-out;
27+
}
28+
29+
[data-component="resize-handle"] {
30+
position: absolute;
31+
left: 50%;
32+
bottom: 100%;
33+
}
1234

1335
&__input-wrap {
14-
margin: calc( 4 * $PX ) calc( 5 * $PX ) calc( 5 * $PX );
1536
border-radius: calc( 2 * $PX );
1637
background: #42103F;
1738
border: 1px solid $c-pastel-purple;
@@ -24,14 +45,25 @@
2445
color: $c-white;
2546
font-size: 9px;
2647
font-family: Arial, Helvetica, sans-serif;
27-
letter-spacing: 0.45px;
48+
letter-spacing: calc(0.45 * $PX);
2849
font-weight: 100;
2950
padding: 0 0.3em 0 0.8em;
3051
border: none;
3152
width: 100%;
3253
height: calc( 21*$PX );
54+
white-space: nowrap;
55+
text-overflow: ellipsis;
56+
}
57+
& ::selection {
58+
background: $c-orange;
59+
}
60+
61+
/*&.is-open {
62+
transform: none;
63+
height: calc( 40*$PX );
64+
}*/
65+
66+
&.is-open &__inner {
67+
transform: translateY(0);
3368
}
34-
& ::selection {
35-
background: $c-orange;
36-
}
3769
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"code-panel":"_code-panel_1furt_3","code-panel__input-wrap":"_code-panel__input-wrap_1furt_1","code-panel__input-field":"_code-panel__input-field_1furt_1"}
1+
{"code-panel":"_code-panel_nnb9p_3","code-panel__inner":"_code-panel__inner_nnb9p_1","code-panel__input-wrap":"_code-panel__input-wrap_nnb9p_1","code-panel__input-field":"_code-panel__input-field_nnb9p_1","is-open":"_is-open_nnb9p_61"}

app/js/app.babel.jsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
// import './tags/curve-editor.tag';
22
require('../css/main');
3-
import {render, h} from 'preact';
4-
import CurveEditor from './tags/curve-editor';
5-
import store from './store';
63
import { Provider } from 'preact-redux';
4+
import {render, h} from 'preact';
5+
import CurveEditor from './tags/curve-editor';
6+
import store from './store';
7+
import C from './constants';
78

89
// TODO
9-
// - select at touch
10-
// - move bunch of points at once
10+
// - instance dropdown on code panel
11+
// - add orange point on seleced point control/ hightlight the control
12+
// - save state to LC
1113
// - add APIs
14+
// - import path data
15+
// - move bunch of points at once
1216

1317
document.addEventListener('DOMContentLoaded', () => {
1418
render(
1519
<Provider store={store}>
1620
<CurveEditor />
1721
</Provider>, document.body);
1822
});
23+
24+
store.dispatch({ type: 'POINT_ADD', data: { point: {x: 0, y: C.CURVE_SIZE, isLockedX: true}, index: 0 } });
25+
store.dispatch({ type: 'POINT_ADD', data: { point: {x: 100, y: 0, isLockedX: true}, index: 1 } });
26+
27+
// makePoint({ x: 0, y: C.CURVE_SIZE, isLockedX: true, type: 'straight' }),
28+
// // makePoint({ x: 50, y: C.CURVE_SIZE/2, type: 'mirrored' }),
29+
// makePoint({ x: 100, y: 0, isLockedX: true })
30+
31+
// curve
32+
// .getFunction({ isInverseX: false, isInverseY: true, name: 'Some name' })
33+
// .getCode()
34+
35+
36+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default (el, fn) => {
2+
if (window.navigator.msPointerEnabled) {
3+
el.addEventListener('MSPointerDown', fn);
4+
} else if ( window.ontouchstart !== undefined ) {
5+
el.addEventListener('touchstart', fn);
6+
el.addEventListener('mousedown', fn);
7+
} else {
8+
el.addEventListener('mousedown', fn);
9+
}
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
import calculateSegment from './calculate-segment';
3+
4+
export default (points) => {
5+
let path = '',
6+
segments = [];
7+
8+
for (let index = 0; index < points.length-1; index++) {
9+
const point = points[index],
10+
nextPoint = points[index+1];
11+
12+
const segment = calculateSegment( point, nextPoint, index );
13+
segments.push(segment);
14+
15+
path += segment.string;
16+
}
17+
18+
return { path, segments };
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import angleToPoint from './angle-to-point';
3+
import C from '../constants';
4+
5+
export default (point, handleIndex = 1) => {
6+
const x = point.x + point.tempX,
7+
y = point.y + point.tempY,
8+
handle = point[`handle${handleIndex}`];
9+
10+
const CHAR = ( handleIndex === 2 ) ? 'C' : '';
11+
if ( point.type !== 'straight' ) {
12+
const handleCoords = angleToPoint( handle.angle, handle.radius );
13+
return `${CHAR}${x + handleCoords.x/C.CURVE_PERCENT}, ${(y + handleCoords.y)/C.CURVE_PERCENT} `;
14+
} else {
15+
return `${CHAR}${x}, ${y/C.CURVE_PERCENT} `;
16+
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import C from '../constants';
2+
import calculatePoint from './calculate-point';
3+
4+
export default (point, nextPoint, index) => {
5+
if ( !nextPoint ) { return 1; }
6+
7+
let string = '',
8+
segmentString = '';
9+
10+
const x = point.x + point.tempX,
11+
y = point.y + point.tempY,
12+
xNext = nextPoint.x + nextPoint.tempX,
13+
yNext = nextPoint.y + nextPoint.tempY;
14+
15+
const part1 = `M${x}, ${y/C.CURVE_PERCENT} `;
16+
if ( index === 0 ) { string += part1 }
17+
segmentString += part1;
18+
19+
const part2 = calculatePoint( point, 2 );
20+
string += part2;
21+
segmentString += part2;
22+
23+
const part3 = calculatePoint( nextPoint, 1 );
24+
string += part3;
25+
segmentString += part3;
26+
27+
const part4 = `${xNext}, ${yNext/C.CURVE_PERCENT} `;
28+
string += part4;
29+
segmentString += part4;
30+
31+
return { string, segmentString, index };
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import calculatePath from '../helpers/calculate-path';
2+
3+
const INITIAL_STATE = {
4+
isCode: false
5+
}
6+
7+
const pointControls = (state = INITIAL_STATE, action) => {
8+
switch (action.type) {
9+
case 'CODE_TAP': {
10+
return { ...state, isCode: !state.isCode };
11+
}
12+
}
13+
return state;
14+
}
15+
16+
export default pointControls;

0 commit comments

Comments
 (0)