@@ -75,7 +75,7 @@ return /******/ (function(modules) { // webpackBootstrap
7575/******/ }
7676/******/
7777/******/ var hotApplyOnUpdate = true ;
78- /******/ var hotCurrentHash = "eced036c9ccfa30d3859 " ; // eslint-disable-line no-unused-vars
78+ /******/ var hotCurrentHash = "13c3afd561d1cd32c030 " ; // eslint-disable-line no-unused-vars
7979/******/ var hotCurrentModuleData = { } ;
8080/******/ var hotCurrentParents = [ ] ; // eslint-disable-line no-unused-vars
8181/******/
@@ -621,9 +621,9 @@ return /******/ (function(modules) { // webpackBootstrap
621621
622622
623623 // TODO
624- // - init points with function
624+ // - select at touch
625625 // - move bunch of points at once
626- // - add grid background
626+ // - add APIs
627627
628628 document . addEventListener ( 'DOMContentLoaded' , function ( ) {
629629 ( 0 , _preact . render ) ( ( 0 , _preact . h ) (
@@ -1521,11 +1521,13 @@ return /******/ (function(modules) { // webpackBootstrap
15211521 } , {
15221522 key : '_addKeyUp' ,
15231523 value : function _addKeyUp ( ) {
1524- document . addEventListener ( 'keyup' , this . _onKeyUp ) ;
1524+ document . addEventListener ( 'keyup' , this . _onKeyUp . bind ( this ) ) ;
15251525 }
15261526 } , {
15271527 key : '_onKeyUp' ,
15281528 value : function _onKeyUp ( e ) {
1529+ var store = this . context . store ;
1530+
15291531 if ( ! e . altKey ) {
15301532 return ;
15311533 }
@@ -6848,17 +6850,13 @@ return /******/ (function(modules) { // webpackBootstrap
68486850 var _this2 = this ;
68496851
68506852 var store = this . context . store ;
6851- var resize = this . props . state . resize ;
6852- var _props3 = this . props ;
6853- var point = _props3 . point ;
6854- var index = _props3 . index ;
68556853
68566854
68576855 var getTempX = function getTempX ( e ) {
68586856 var resize = _this2 . props . state . resize ;
6859- var _props4 = _this2 . props ;
6860- var point = _props4 . point ;
6861- var index = _props4 . index ;
6857+ var _props3 = _this2 . props ;
6858+ var point = _props3 . point ;
6859+ var index = _props3 . index ;
68626860 // if point is not locked to x axes ->
68636861 // calculate delta regarding scaler
68646862
@@ -6877,9 +6875,9 @@ return /******/ (function(modules) { // webpackBootstrap
68776875
68786876 var getY = function getY ( e ) {
68796877 var resize = _this2 . props . state . resize ;
6880- var _props5 = _this2 . props ;
6881- var point = _props5 . point ;
6882- var index = _props5 . index ;
6878+ var _props4 = _this2 . props ;
6879+ var point = _props4 . point ;
6880+ var index = _props4 . index ;
68836881 var y = point . y + e . deltaY ;
68846882
68856883 // clamp y to the size of curve
@@ -6889,9 +6887,9 @@ return /******/ (function(modules) { // webpackBootstrap
68896887 // get y delta reagarding curve bounds
68906888 var getTempY = function getTempY ( e ) {
68916889 var resize = _this2 . props . state . resize ;
6892- var _props6 = _this2 . props ;
6893- var point = _props6 . point ;
6894- var index = _props6 . index ;
6890+ var _props5 = _this2 . props ;
6891+ var point = _props5 . point ;
6892+ var index = _props5 . index ;
68956893
68966894
68976895 var y = point . y + e . deltaY ,
@@ -6913,22 +6911,35 @@ return /******/ (function(modules) { // webpackBootstrap
69136911 mc . add ( new _hammerjs2 . default . Tap ( ) ) ;
69146912
69156913 mc . on ( 'pan' , function ( e ) {
6914+ var _props6 = _this2 . props ;
6915+ var point = _props6 . point ;
6916+ var index = _props6 . index ;
6917+
69166918 store . dispatch ( {
69176919 type : 'POINT_TRANSLATE' ,
69186920 data : { x : getTempX ( e ) , y : getTempY ( e ) , index : index }
69196921 } ) ;
69206922 e . stopPropagation ( ) ;
69216923 } ) . on ( 'panend' , function ( e ) {
6924+ var _props7 = _this2 . props ;
6925+ var point = _props7 . point ;
6926+ var index = _props7 . index ;
69226927 // fire translate end and save it to the store
6928+
69236929 store . dispatch ( {
69246930 type : 'POINT_TRANSLATE_END' , data : index , isRecord : true
69256931 } ) ;
69266932 e . stopPropagation ( ) ;
69276933 } ) . on ( 'tap' , function ( e ) {
6934+ var _props8 = _this2 . props ;
6935+ var point = _props8 . point ;
6936+ var index = _props8 . index ;
6937+
69286938 store . dispatch ( {
69296939 type : 'POINT_SELECT' ,
69306940 data : {
6931- index : index , type : point . type , isDeselect : ! e . srcEvent . shiftKey
6941+ index : index , isDeselect : ! e . srcEvent . shiftKey ,
6942+ type : point . type
69326943 }
69336944 } ) ;
69346945 e . stopPropagation ( ) ;
@@ -9520,6 +9531,10 @@ return /******/ (function(modules) { // webpackBootstrap
95209531
95219532 var _constants2 = _interopRequireDefault ( _constants ) ;
95229533
9534+ var _initPoints = __webpack_require__ ( 180 ) ;
9535+
9536+ var _initPoints2 = _interopRequireDefault ( _initPoints ) ;
9537+
95239538 function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
95249539
95259540 var INITIAL_STATE = [ ( 0 , _makePoint2 . default ) ( { x : 0 , y : _constants2 . default . CURVE_SIZE , isLockedX : true , type : 'straight' } ) , ( 0 , _makePoint2 . default ) ( { x : 50 , y : _constants2 . default . CURVE_SIZE / 2 , type : 'mirrored' } ) , ( 0 , _makePoint2 . default ) ( { x : 100 , y : 0 , isLockedX : true } ) ] ;
@@ -9541,7 +9556,7 @@ return /******/ (function(modules) { // webpackBootstrap
95419556 } ;
95429557
95439558 var pointsReducer = function pointsReducer ( ) {
9544- var state = arguments . length <= 0 || arguments [ 0 ] === undefined ? INITIAL_STATE : arguments [ 0 ] ;
9559+ var state = arguments . length <= 0 || arguments [ 0 ] === undefined ? ( 0 , _initPoints2 . default ) ( INITIAL_STATE ) : arguments [ 0 ] ;
95459560 var action = arguments [ 1 ] ;
95469561
95479562 switch ( action . type ) {
@@ -9576,39 +9591,9 @@ return /******/ (function(modules) { // webpackBootstrap
95769591 var _data = action . data ;
95779592 var _index2 = _data . index ;
95789593 var isDeselect = _data . isDeselect ;
9579- // if should de select all other points
95809594 var _newState2 = isDeselect ? deslectAll ( state ) : [ ] . concat ( ( 0 , _toConsumableArray3 . default ) ( state ) ) ;
95819595
95829596 var point = _newState2 [ _index2 ] ;
9583- var sibPoint = _index2 === _newState2 . length - 1 ? _newState2 [ _index2 - 1 ] : _newState2 [ _index2 + 1 ] ;
9584-
9585- var handleIndex = _index2 === _newState2 . length - 1 ? 1 : 2 ;
9586-
9587- var handleName = 'handle' + handleIndex ;
9588- var sibHandleIndex = handleIndex === 1 ? 2 : 1 ;
9589- var sibHandleName = 'handle' + sibHandleIndex ;
9590- var handle = ( 0 , _extends3 . default ) ( { } , point [ handleName ] ) ;
9591- var sibHandle = ( 0 , _extends3 . default ) ( { } , point [ sibHandleName ] ) ;
9592- point [ handleName ] = handle ;
9593- point [ sibHandleName ] = sibHandle ;
9594-
9595- var wasntSet = handle . angle == null || handle . radius == null ;
9596- var type = point . type ;
9597- if ( wasntSet ) {
9598- handle . radius = 50 ;
9599-
9600- var dy = ( sibPoint . y - point . y ) / _constants2 . default . CURVE_PERCENT ;
9601- var dx = sibPoint . x - point . x ;
9602- var angle = Math . atan ( dy / dx ) * ( 180 / Math . PI ) - 90 ;
9603- if ( dx > 0 ) {
9604- angle = angle - 180 ;
9605- } ;
9606- handle . angle = angle ;
9607-
9608- sibHandle . radius = handle . radius ;
9609- sibHandle . angle = handle . angle - 180 ;
9610- }
9611-
96129597 point . isSelected = true ;
96139598 return _newState2 ;
96149599 }
@@ -9619,60 +9604,61 @@ return /******/ (function(modules) { // webpackBootstrap
96199604 var x = _data2 . x ;
96209605 var y = _data2 . y ;
96219606 var _index3 = _data2 . index ;
9622-
9623-
96249607 var deselected = deslectAll ( state ) ;
96259608
9626- return [ ] . concat ( ( 0 , _toConsumableArray3 . default ) ( deselected . slice ( 0 , _index3 ) ) , [ ( 0 , _makePoint2 . default ) ( { x : x , y : y , isSelected : true } ) ] , ( 0 , _toConsumableArray3 . default ) ( deselected . slice ( _index3 ) ) ) ;
9609+ var _newState3 = [ ] . concat ( ( 0 , _toConsumableArray3 . default ) ( deselected . slice ( 0 , _index3 ) ) , [ ( 0 , _makePoint2 . default ) ( { x : x , y : y , isSelected : true } ) ] , ( 0 , _toConsumableArray3 . default ) ( deselected . slice ( _index3 ) ) ) ;
9610+
9611+ return ( 0 , _initPoints2 . default ) ( _newState3 ) ;
96279612 }
9613+
96289614 case 'POINT_DELETE' :
96299615 {
96309616 var selected = findSelectedIndecies ( state ) ;
96319617
9632- var _newState3 = [ ] ;
9618+ var _newState4 = [ ] ;
96339619 for ( var i = 0 ; i < state . length ; i ++ ) {
96349620 var item = state [ i ] ;
9635- ( selected . indexOf ( i ) === - 1 || item . isLockedX ) && _newState3 . push ( item ) ;
9621+ ( selected . indexOf ( i ) === - 1 || item . isLockedX ) && _newState4 . push ( item ) ;
96369622 }
96379623
9638- return _newState3 ;
9624+ return _newState4 ;
96399625 }
96409626
96419627 case 'POINT_CHANGE_TYPE' :
96429628 {
96439629 var _selected = findSelectedIndecies ( state ) ;
96449630
9645- var _newState4 = [ ] ;
9631+ var _newState5 = [ ] ;
96469632 for ( var i = 0 ; i < state . length ; i ++ ) {
96479633 var _item = state [ i ] ;
9648- var _type = action . data ;
9634+ var type = action . data ;
96499635 // copy all items from previous state
9650- _newState4 . push ( ( 0 , _extends3 . default ) ( { } , _item ) ) ;
9636+ _newState5 . push ( ( 0 , _extends3 . default ) ( { } , _item ) ) ;
96519637 // if item was selected - set the new `type`
9652- _selected . indexOf ( i ) !== - 1 && ( _newState4 [ i ] . type = _type ) ;
9638+ _selected . indexOf ( i ) !== - 1 && ( _newState5 [ i ] . type = type ) ;
96539639
96549640 var _index4 = i ;
9655- var _point = _newState4 [ _index4 ] ;
9656- var _sibPoint = _index4 === _newState4 . length - 1 ? _newState4 [ _index4 - 1 ] : _newState4 [ _index4 + 1 ] ;
9657-
9658- var _handleIndex = _index4 === _newState4 . length - 1 ? 1 : 2 ;
9659- var _sibHandleIndex = _handleIndex === 1 ? 2 : 1 ;
9660- var _handleName = 'handle' + _handleIndex ;
9661- var _sibHandleName = 'handle' + _sibHandleIndex ;
9662- var _handle = ( 0 , _extends3 . default ) ( { } , _point [ _handleName ] ) ;
9663- var _sibHandle = ( 0 , _extends3 . default ) ( { } , _point [ _sibHandleName ] ) ;
9664- _point [ _handleName ] = _handle ;
9665- _point [ _sibHandleName ] = _sibHandle ;
9666-
9667- if ( _type === 'mirrored' || _type === 'asymmetric' ) {
9668- _sibHandle . angle = _handle . angle - 180 ;
9669- if ( _type === 'mirrored' ) {
9670- _sibHandle . radius = _handle . radius ;
9641+ var _point = _newState5 [ _index4 ] ;
9642+ var sibPoint = _index4 === _newState5 . length - 1 ? _newState5 [ _index4 - 1 ] : _newState5 [ _index4 + 1 ] ;
9643+
9644+ var handleIndex = _index4 === _newState5 . length - 1 ? 1 : 2 ;
9645+ var sibHandleIndex = handleIndex === 1 ? 2 : 1 ;
9646+ var handleName = 'handle' + handleIndex ;
9647+ var sibHandleName = 'handle' + sibHandleIndex ;
9648+ var handle = ( 0 , _extends3 . default ) ( { } , _point [ handleName ] ) ;
9649+ var sibHandle = ( 0 , _extends3 . default ) ( { } , _point [ sibHandleName ] ) ;
9650+ _point [ handleName ] = handle ;
9651+ _point [ sibHandleName ] = sibHandle ;
9652+
9653+ if ( type === 'mirrored' || type === 'asymmetric' ) {
9654+ sibHandle . angle = handle . angle - 180 ;
9655+ if ( type === 'mirrored' ) {
9656+ sibHandle . radius = handle . radius ;
96719657 }
96729658 }
96739659 }
96749660
9675- return _newState4 ;
9661+ return _newState5 ;
96769662 }
96779663
96789664 case 'POINT_DESELECT_ALL' :
@@ -9686,18 +9672,18 @@ return /******/ (function(modules) { // webpackBootstrap
96869672 var _data3 = action . data ;
96879673 // create new state and copy the new point into it
96889674
9689- var _newState5 = [ ] . concat ( ( 0 , _toConsumableArray3 . default ) ( state ) ) ;
9690- var newPoint = ( 0 , _extends3 . default ) ( { } , _newState5 [ _data3 . parentIndex ] ) ;
9691- _newState5 [ _data3 . parentIndex ] = newPoint ;
9675+ var _newState6 = [ ] . concat ( ( 0 , _toConsumableArray3 . default ) ( state ) ) ;
9676+ var newPoint = ( 0 , _extends3 . default ) ( { } , _newState6 [ _data3 . parentIndex ] ) ;
9677+ _newState6 [ _data3 . parentIndex ] = newPoint ;
96929678 // create handle and copy it into the new point
9693- var _handleName2 = 'handle' + _data3 . index ;
9694- var newHandle = ( 0 , _extends3 . default ) ( { } , newPoint [ _handleName2 ] ) ;
9695- newPoint [ _handleName2 ] = newHandle ;
9679+ var _handleName = 'handle' + _data3 . index ;
9680+ var newHandle = ( 0 , _extends3 . default ) ( { } , newPoint [ _handleName ] ) ;
9681+ newPoint [ _handleName ] = newHandle ;
96969682 // finally add angle and radius
96979683 newHandle . angle = _data3 . angle ;
96989684 newHandle . radius = _data3 . radius ;
96999685
9700- return _newState5 ;
9686+ return _newState6 ;
97019687 }
97029688 }
97039689 return state ;
@@ -10850,6 +10836,88 @@ return /******/ (function(modules) { // webpackBootstrap
1085010836 // exports
1085110837
1085210838
10839+ /***/ } ,
10840+ /* 180 */
10841+ /***/ function ( module , exports , __webpack_require__ ) {
10842+
10843+ 'use strict' ;
10844+
10845+ Object . defineProperty ( exports , "__esModule" , {
10846+ value : true
10847+ } ) ;
10848+
10849+ var _initPoint = __webpack_require__ ( 181 ) ;
10850+
10851+ var _initPoint2 = _interopRequireDefault ( _initPoint ) ;
10852+
10853+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
10854+
10855+ exports . default = function ( points ) {
10856+
10857+ var newPoints = [ ] ;
10858+ for ( var i = 0 ; i < points . length ; i ++ ) {
10859+ var point = points [ i ] ,
10860+ sibPoint = i === points . length - 1 ? points [ i - 1 ] : points [ i + 1 ] ,
10861+ handleIndex = i === points . length - 1 ? 1 : 2 ;
10862+
10863+ newPoints . push ( ( 0 , _initPoint2 . default ) ( point , sibPoint , handleIndex ) ) ;
10864+ }
10865+ return newPoints ;
10866+ } ;
10867+
10868+ /***/ } ,
10869+ /* 181 */
10870+ /***/ function ( module , exports , __webpack_require__ ) {
10871+
10872+ 'use strict' ;
10873+
10874+ Object . defineProperty ( exports , "__esModule" , {
10875+ value : true
10876+ } ) ;
10877+
10878+ var _extends2 = __webpack_require__ ( 102 ) ;
10879+
10880+ var _extends3 = _interopRequireDefault ( _extends2 ) ;
10881+
10882+ var _constants = __webpack_require__ ( 92 ) ;
10883+
10884+ var _constants2 = _interopRequireDefault ( _constants ) ;
10885+
10886+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
10887+
10888+ exports . default = function ( point , sibPoint , handleIndex ) {
10889+
10890+ point = ( 0 , _extends3 . default ) ( { } , point ) ;
10891+
10892+ var handleName = 'handle' + handleIndex ,
10893+ sibHandleIndex = handleIndex === 1 ? 2 : 1 ,
10894+ sibHandleName = 'handle' + sibHandleIndex ,
10895+ handle = ( 0 , _extends3 . default ) ( { } , point [ handleName ] ) ,
10896+ sibHandle = ( 0 , _extends3 . default ) ( { } , point [ sibHandleName ] ) ,
10897+ type = point . type ;
10898+
10899+ point [ handleName ] = handle ;
10900+ point [ sibHandleName ] = sibHandle ;
10901+
10902+ if ( handle . angle == null || handle . radius == null ) {
10903+ handle . radius = 50 ;
10904+
10905+ var dy = ( sibPoint . y - point . y ) / _constants2 . default . CURVE_PERCENT ,
10906+ dx = sibPoint . x - point . x ;
10907+
10908+ var angle = Math . atan ( dy / dx ) * ( 180 / Math . PI ) - 90 ;
10909+ if ( dx > 0 ) {
10910+ angle = angle - 180 ;
10911+ } ;
10912+
10913+ handle . angle = angle ;
10914+ sibHandle . radius = handle . radius ;
10915+ sibHandle . angle = handle . angle - 180 ;
10916+ }
10917+
10918+ return point ;
10919+ } ;
10920+
1085310921/***/ }
1085410922/******/ ] )
1085510923} ) ;
0 commit comments