Skip to content

Commit 0157d95

Browse files
committed
curve-editor: add snap to grid
1 parent 7c42d4f commit 0157d95

12 files changed

+76
-48
lines changed

app/build/mojs-curve-editor.js

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ return /******/ (function(modules) { // webpackBootstrap
7575
/******/ }
7676
/******/
7777
/******/ var hotApplyOnUpdate = true;
78-
/******/ var hotCurrentHash = "eb4b9d857ba05af5b0bb"; // eslint-disable-line no-unused-vars
78+
/******/ var hotCurrentHash = "07485cea7385da19154c"; // eslint-disable-line no-unused-vars
7979
/******/ var hotCurrentModuleData = {};
8080
/******/ var hotCurrentParents = []; // eslint-disable-line no-unused-vars
8181
/******/
@@ -613,7 +613,6 @@ return /******/ (function(modules) { // webpackBootstrap
613613
__webpack_require__(137);
614614

615615
document.addEventListener('DOMContentLoaded', function () {
616-
// riot.mount('*',{ store: store })
617616
riot.mount('curve-editor', { store: _store2.default });
618617
});
619618
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)))
@@ -3798,7 +3797,7 @@ return /******/ (function(modules) { // webpackBootstrap
37983797
/* WEBPACK VAR INJECTION */(function(riot) {
37993798
__webpack_require__(13);
38003799

3801-
riot.tag2('curve', '<div class="{this.CLASSES[\'curve__svg-wrapper\']}" riot-style="{this.styles.transform}"> <point each="{point, _index in points}" points-count="{parent.points.length}"></point> <svg height="358" viewbox="0 0 100 100" preserveaspectratio="none" class="{this.CLASSES[\'curve__svg\']}"> <path riot-d="{this.path}" stroke="#000000" stroke-opacity="0.35" stroke-width="4" vector-effect="non-scaling-stroke" transform="translate(.75,.75)" fill="none"></path> <g id="js-segments"> <path each="{this.segments}" riot-d="{str}" data-index="{index}" stroke="white" fill="none" stroke-width="" vector-effect="non-scaling-stroke" class="{this.CLASSES[\'curve__svg-segment\']}"></path> </g> </svg> </div>', '', 'class="{this.CLASSES[\'curve\']}" riot-style="{this.styles.background}"', function(opts) {
3800+
riot.tag2('curve', '<div class="{this.CLASSES[\'curve__svg-wrapper\']}" riot-style="{this.styles.transform}"> <point each="{point, _index in points}" points-count="{parent.points.length}"></point> <svg height="350" viewbox="0 0 100 100" preserveaspectratio="none" class="{this.CLASSES[\'curve__svg\']}"> <path riot-d="{this.path}" stroke="#000000" stroke-opacity="0.35" stroke-width="4" vector-effect="non-scaling-stroke" transform="translate(.75,.75)" fill="none"></path> <g id="js-segments"> <path each="{this.segments}" riot-d="{str}" data-index="{index}" stroke="white" fill="none" stroke-width="" vector-effect="non-scaling-stroke" class="{this.CLASSES[\'curve__svg-segment\']}"></path> </g> </svg> </div>', '', 'class="{this.CLASSES[\'curve\']}" riot-style="{this.styles.background}"', function(opts) {
38023801
'use strict';
38033802

38043803
var _this = this;
@@ -3997,6 +3996,10 @@ return /******/ (function(modules) { // webpackBootstrap
39973996

39983997
var _resizeMod2 = _interopRequireDefault(_resizeMod);
39993998

3999+
var _roundTo = __webpack_require__(141);
4000+
4001+
var _roundTo2 = _interopRequireDefault(_roundTo);
4002+
40004003
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40014004

40024005
this.CLASSES = __webpack_require__(108);
@@ -4057,7 +4060,7 @@ return /******/ (function(modules) { // webpackBootstrap
40574060
} else if (_this.point.x + x > 100) {
40584061
return 100 - _this.point.x;
40594062
}
4060-
return x;
4063+
return (0, _roundTo2.default)(x, 5, 1.5);
40614064
};
40624065

40634066
var getY = function getY(e) {
@@ -4077,13 +4080,16 @@ return /******/ (function(modules) { // webpackBootstrap
40774080
var resize = _store$getState4.resize;
40784081
var y = _this.point.y + e.deltaY;
40794082

4083+
var returnValue = y;
40804084
if (y < resize.top) {
4081-
return resize.top - _this.point.y;
4082-
}
4083-
if (y > _constants2.default.CURVE_SIZE + resize.bottom) {
4084-
return _constants2.default.CURVE_SIZE + resize.bottom - _this.point.y;
4085+
returnValue = resize.top - _this.point.y;
4086+
} else if (y > _constants2.default.CURVE_SIZE + resize.bottom) {
4087+
returnValue = _constants2.default.CURVE_SIZE + resize.bottom - _this.point.y;
4088+
} else {
4089+
returnValue = e.deltaY;
40854090
}
4086-
return e.deltaY;
4091+
4092+
return (0, _roundTo2.default)(returnValue, 10 * _constants2.default.CURVE_PERCENT, 2 * _constants2.default.CURVE_PERCENT);
40874093
};
40884094

40894095
this.on('mount', function () {
@@ -10136,10 +10142,10 @@ return /******/ (function(modules) { // webpackBootstrap
1013610142
/***/ function(module, exports) {
1013710143

1013810144
module.exports = {
10139-
"curve": "_curve_1gafb_5",
10140-
"curve__svg-wrapper": "_curve__svg-wrapper_1gafb_1",
10141-
"curve__svg": "_curve__svg_1gafb_1",
10142-
"curve__svg-segment": "_curve__svg-segment_1gafb_1"
10145+
"curve": "_curve_1y7gw_5",
10146+
"curve__svg-wrapper": "_curve__svg-wrapper_1y7gw_1",
10147+
"curve__svg": "_curve__svg_1y7gw_1",
10148+
"curve__svg-segment": "_curve__svg-segment_1y7gw_1"
1014310149
};
1014410150

1014510151
/***/ },
@@ -10177,7 +10183,7 @@ return /******/ (function(modules) { // webpackBootstrap
1017710183

1017810184

1017910185
// module
10180-
exports.push([module.id, "._curve_1gafb_5{position:absolute;left:0;top:10px;right:10px;bottom:10px;border-radius:2px;background:rgba(58,8,58,.75);border:1px solid #9c829a;box-shadow:inset 4px 4px 0 rgba(0,0,0,.5);z-index:2}._curve__svg-wrapper_1gafb_1{position:absolute;left:-1px;top:-1px;width:100%}._curve__svg_1gafb_1{display:block;overflow:visible;width:100%}._curve__svg-segment_1gafb_1{stroke:#fff;stroke-width:2px;cursor:crosshair}._curve__svg-segment_1gafb_1:hover{stroke:#ff512f}", ""]);
10186+
exports.push([module.id, "._curve_1y7gw_5{position:absolute;left:0;top:10px;right:10px;bottom:10px;border-radius:2px;background:rgba(58,8,58,.75);border:1px solid #9c829a;box-shadow:inset 4px 4px 0 rgba(0,0,0,.5);z-index:2}._curve__svg-wrapper_1y7gw_1{position:absolute;left:-1px;right:-1px}._curve__svg_1y7gw_1{display:block;overflow:visible;width:100%}._curve__svg-segment_1y7gw_1{stroke:#fff;stroke-width:2px;cursor:crosshair}._curve__svg-segment_1y7gw_1:hover{stroke:#ff512f}", ""]);
1018110187

1018210188
// exports
1018310189

@@ -10187,7 +10193,6 @@ return /******/ (function(modules) { // webpackBootstrap
1018710193
/***/ function(module, exports, __webpack_require__) {
1018810194

1018910195
/* WEBPACK VAR INJECTION */(function(riot) {
10190-
1019110196
riot.tag2('code-panel', '<div class="{this.CLASSES[\'code-panel__input-wrap\']}"> <input class="{this.CLASSES[\'code-panel__input-field\']}" type="text" readonly="readonly" value="M0,100 C0,100 12.0486221,-124.260309 24,99.7583642 C28.9933624,142.723104"> </div>', '', 'class="{this.CLASSES[\'code-panel\']}"', function(opts) {
1019210197
'use strict';
1019310198

@@ -10647,7 +10652,7 @@ return /******/ (function(modules) { // webpackBootstrap
1064710652

1064810653

1064910654
// module
10650-
exports.push([module.id, "._curve-editor_1sc6s_4{position:fixed;left:0;top:0;width:411px;height:398px;border-radius:12px;background:rgba(58,8,58,.85);z-index:100;box-shadow:2px 2px 2px rgba(0,0,0,.38)}._curve-editor__left_1sc6s_1{position:absolute;width:42px;left:0;top:0;bottom:0;padding:10px}._curve-editor__left_1sc6s_1 icon-divider{margin:10px auto}._curve-editor__right_1sc6s_1{position:absolute;left:43px;top:0;right:0;bottom:0}._curve-editor__right_1sc6s_1 resize-handle{position:absolute}._curve-editor__right_1sc6s_1 resize-handle[type=top]{top:-16px}._curve-editor__right_1sc6s_1 resize-handle[type=bottom]{bottom:0}._curve-editor__right_1sc6s_1 resize-handle[type=bottom],._curve-editor__right_1sc6s_1 resize-handle[type=top]{left:50%;margin-left:-21px}._curve-editor__right_1sc6s_1 resize-handle[type=right]{right:-16px;top:50%;margin-top:-16px}._curve-editor__anchor-buttons_1sc6s_1{margin-top:10px}._curve-editor__anchor-buttons_1sc6s_1 icon-button{margin-bottom:5px}._curve-editor__mojs-logo_1sc6s_1{position:absolute;bottom:17px;left:50%;margin-left:1px;-webkit-transform:translateX(-50%);transform:translateX(-50%)}._curve-editor__mojs-logo_1sc6s_1 icon{fill:#ff512f;width:12px;height:12px}", ""]);
10655+
exports.push([module.id, "._curve-editor_1vq6l_4{position:fixed;left:0;top:0;width:403px;height:378px;border-radius:12px;background:rgba(58,8,58,.85);z-index:100;box-shadow:2px 2px 2px rgba(0,0,0,.38)}._curve-editor__left_1vq6l_1{position:absolute;width:42px;left:0;top:0;bottom:0;padding:10px}._curve-editor__left_1vq6l_1 icon-divider{margin:10px auto}._curve-editor__right_1vq6l_1{position:absolute;left:43px;top:0;right:0;bottom:0}._curve-editor__right_1vq6l_1 resize-handle{position:absolute}._curve-editor__right_1vq6l_1 resize-handle[type=top]{top:-16px}._curve-editor__right_1vq6l_1 resize-handle[type=bottom]{bottom:0}._curve-editor__right_1vq6l_1 resize-handle[type=bottom],._curve-editor__right_1vq6l_1 resize-handle[type=top]{left:50%;margin-left:-21px}._curve-editor__right_1vq6l_1 resize-handle[type=right]{right:-16px;top:50%;margin-top:-16px}._curve-editor__anchor-buttons_1vq6l_1{margin-top:10px}._curve-editor__anchor-buttons_1vq6l_1 icon-button{margin-bottom:5px}._curve-editor__mojs-logo_1vq6l_1{position:absolute;bottom:17px;left:50%;margin-left:1px;-webkit-transform:translateX(-50%);transform:translateX(-50%)}._curve-editor__mojs-logo_1vq6l_1 icon{fill:#ff512f;width:12px;height:12px}", ""]);
1065110656

1065210657
// exports
1065310658

@@ -10657,11 +10662,11 @@ return /******/ (function(modules) { // webpackBootstrap
1065710662
/***/ function(module, exports) {
1065810663

1065910664
module.exports = {
10660-
"curve-editor": "_curve-editor_1sc6s_4",
10661-
"curve-editor__left": "_curve-editor__left_1sc6s_1",
10662-
"curve-editor__right": "_curve-editor__right_1sc6s_1",
10663-
"curve-editor__anchor-buttons": "_curve-editor__anchor-buttons_1sc6s_1",
10664-
"curve-editor__mojs-logo": "_curve-editor__mojs-logo_1sc6s_1"
10665+
"curve-editor": "_curve-editor_1vq6l_4",
10666+
"curve-editor__left": "_curve-editor__left_1vq6l_1",
10667+
"curve-editor__right": "_curve-editor__right_1vq6l_1",
10668+
"curve-editor__anchor-buttons": "_curve-editor__anchor-buttons_1vq6l_1",
10669+
"curve-editor__mojs-logo": "_curve-editor__mojs-logo_1vq6l_1"
1066510670
};
1066610671

1066710672
/***/ },
@@ -10714,7 +10719,7 @@ return /******/ (function(modules) { // webpackBootstrap
1071410719
value: true
1071510720
});
1071610721

10717-
var CURVE_SIZE = 358;
10722+
var CURVE_SIZE = 350;
1071810723
exports.default = {
1071910724
CURVE_SIZE: CURVE_SIZE,
1072010725
CURVE_PERCENT: CURVE_SIZE / 100,
@@ -10735,6 +10740,22 @@ return /******/ (function(modules) { // webpackBootstrap
1073510740
return mojs.h.getRadialPoint({ angle: angle, radius: radius, center: { x: 0, y: 0 } });
1073610741
};
1073710742

10743+
/***/ },
10744+
/* 141 */
10745+
/***/ function(module, exports) {
10746+
10747+
"use strict";
10748+
10749+
Object.defineProperty(exports, "__esModule", {
10750+
value: true
10751+
});
10752+
10753+
exports.default = function (value, base, snap) {
10754+
var modified = Math.round(value / base) * base;
10755+
10756+
return Math.abs(value - modified) < snap ? modified : value;
10757+
};
10758+
1073810759
/***/ }
1073910760
/******/ ])
1074010761
});

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

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

app/css/blocks/curve-editor.postcss.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
position: fixed;
66
left: 0;
77
top: 0;
8-
width: calc( 411 * $PX );
9-
height: calc( 398 * $PX );
8+
width: calc( 403 * $PX );
9+
height: calc( 378 * $PX );
1010
border-radius: calc( 12 * $PX );
1111
background: rgba( 58, 8, 58, .85 );
1212
z-index: 100;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"curve-editor":"_curve-editor_1sc6s_4","curve-editor__left":"_curve-editor__left_1sc6s_1","curve-editor__right":"_curve-editor__right_1sc6s_1","curve-editor__anchor-buttons":"_curve-editor__anchor-buttons_1sc6s_1","curve-editor__mojs-logo":"_curve-editor__mojs-logo_1sc6s_1"}
1+
{"curve-editor":"_curve-editor_1vq6l_4","curve-editor__left":"_curve-editor__left_1vq6l_1","curve-editor__right":"_curve-editor__right_1vq6l_1","curve-editor__anchor-buttons":"_curve-editor__anchor-buttons_1vq6l_1","curve-editor__mojs-logo":"_curve-editor__mojs-logo_1vq6l_1"}

app/css/blocks/curve.postcss.css

Lines changed: 3 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.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"curve":"_curve_1gafb_5","curve__svg-wrapper":"_curve__svg-wrapper_1gafb_1","curve__svg":"_curve__svg_1gafb_1","curve__svg-segment":"_curve__svg-segment_1gafb_1"}
1+
{"curve":"_curve_1y7gw_5","curve__svg-wrapper":"_curve__svg-wrapper_1y7gw_1","curve__svg":"_curve__svg_1y7gw_1","curve__svg-segment":"_curve__svg-segment_1y7gw_1"}

app/js/app.babel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ require('../css/main');
44
import store from './store';
55

66
document.addEventListener('DOMContentLoaded', () => {
7-
// riot.mount('*',{ store: store })
87
riot.mount('curve-editor', { store });
98
});

app/js/constants.babel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
const CURVE_SIZE = 358;
2+
const CURVE_SIZE = 350;
33
export default {
44
CURVE_SIZE,
55
CURVE_PERCENT: CURVE_SIZE/100,

app/js/helpers/round-to.babel.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
export default (value, base, snap) => {
3+
const modified = Math.round(value/base)*base;
4+
5+
return ( Math.abs(value - modified) < snap ) ? modified : value;
6+
}

app/js/tags/code-panel.tag

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
32
<code-panel class={ this.CLASSES['code-panel'] }>
43
<div class={ this.CLASSES['code-panel__input-wrap'] }>
54
<input class={ this.CLASSES['code-panel__input-field'] } type="text" readonly="readonly" value="M0,100 C0,100 12.0486221,-124.260309 24,99.7583642 C28.9933624,142.723104" />

0 commit comments

Comments
 (0)