import { IDrawOption , IDrawClassOption , TDrawType , TTestStatusType } from 'cnchar-types/plugin/draw/common' ; import { Json } from 'cnchar-types/main/common' ; export const TYPE = { NORMAL : 'normal' , ANIMATION : 'animation' , STROKE : 'stroke' , TEST : 'test' } ; export const TEST_STATUS = { MISTAKE : 'mistake' , CORRECT : 'correct' , COMPLETE : 'complete' } ; export const DrawOption = { showOutline : true , showCharacter : true , currentColor : '#b44' , clear : true , length : 60 , padding : 5 , outlineColor : '#ddd' , backgroundColor : '#fff' , strokeColor : '#555' , radicalColor : null , strokeFadeDuration : 400 , lineStraight : true , lineCross : true , lineWidth : 1 , lineColor : '#ddd' , lineDash : true , border : true , borderWidth : 1 , borderColor : '#ccc' , borderDash : false , strokeAnimationSpeed : 1 , delayBetweenStrokes : 1000 , delayBetweenLoops : 200 , autoAnimate : true , animateComplete ( ) { } , stepByStep : true , loopAnimate : false , strokeHighlightSpeed : 20 , highlightColor : '#aaf' , drawingColor : '#333' , drawingWidth : 4 , showHintAfterMisses : 3 , highlightOnComplete : true , highlightCompleteColor : null , onTestStatus : null , } ; function isUd ( v ) { return typeof v === 'undefined' ; } export function merge ( type , args ) { const json = { } ; for ( const key in args ) { const arg = args [ key ] ; for ( const k in arg ) { if ( ! isUd ( arg [ k ] ) ) { json [ k ] = arg [ k ] ; } } } check ( json ) ; json . width = json . length ; json . height = json . length ; checkTypeDefault ( type , args , json ) ; return json ; } function checkTypeDefault ( type , args , json ) { if ( type === TYPE . ANIMATION ) { if ( ! args . animation || isUd ( args . animation . showCharacter ) ) { json . showCharacter = false ; } } else if ( type === TYPE . STROKE ) { json . showCharacter = false ; } } function check ( json , attrs ? ) { attrs = attrs || Object . keys ( DrawOption ) ; attrs . forEach ( attr => { if ( isUd ( json [ attr ] ) ) { json [ attr ] = DrawOption [ attr ] ; } } ) ; return json ; }