mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2025-01-09 22:22:23 -05:00
34 lines
866 B
JavaScript
34 lines
866 B
JavaScript
|
import log from '../log/log';
|
||
|
|
||
|
const CHANGE_STROKE_WIDTH = 'scratch-paint/stroke-width/CHANGE_STROKE_WIDTH';
|
||
|
const MAX_STROKE_WIDTH = 400;
|
||
|
const initialState = 2;
|
||
|
|
||
|
const reducer = function (state, action) {
|
||
|
if (typeof state === 'undefined') state = initialState;
|
||
|
switch (action.type) {
|
||
|
case CHANGE_STROKE_WIDTH:
|
||
|
if (isNaN(action.strokeWidth)) {
|
||
|
log.warn(`Invalid brush size: ${action.strokeWidth}`);
|
||
|
return state;
|
||
|
}
|
||
|
return Math.min(MAX_STROKE_WIDTH, Math.max(0, action.strokeWidth));
|
||
|
default:
|
||
|
return state;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Action creators ==================================
|
||
|
const changeStrokeWidth = function (strokeWidth) {
|
||
|
return {
|
||
|
type: CHANGE_STROKE_WIDTH,
|
||
|
strokeWidth: strokeWidth
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export {
|
||
|
reducer as default,
|
||
|
changeStrokeWidth,
|
||
|
MAX_STROKE_WIDTH
|
||
|
};
|