import React from 'react' ; import AsciiArt from './asciiArt' ; interface SakadaruPropertyType { name : string ; } function line ( center , length , decoration = ' ' ) { if ( length < center . length ) { return decoration . repeat ( length ) . substr ( 0 , length ) ; } else { const sideLength = ( length - center . length ) / 2 ; return ( decoration . repeat ( sideLength ) . substr ( 0 , sideLength ) + center + decoration . repeat ( sideLength ) . substr ( 0 , sideLength ) ) ; } } function spacer ( center , spaces , decoration = ' ' ) { return center . map ( ( value ) => decoration . repeat ( spaces ) . substr ( 0 , spaces ) + value ) ; } function header ( length ) { let output ; if ( length < 6 ) { output = [ '=' . repeat ( length ) ] ; } else if ( length < 10 ) { if ( length % 2 === 0 ) { output = [ '=' . repeat ( length ) ] ; output . push ( line ( ' 奉納 ' , length - 1 , '=' ) ) ; output . push ( '=' . repeat ( length ) ) ; } else { output = [ '=' . repeat ( length ) ] ; output . push ( line ( ' 奉 納 ' , length - 1 , '=' ) ) ; output . push ( '=' . repeat ( length ) ) ; } } else if ( length % 2 === 0 ) { output = [ line ( '____' , length ) ] ; output . push ( line ( line ( '@@@@' , length / 2 , '=' ) , length , '-' ) ) ; output . push ( line ( line ( ' 奉納 ' , length - 6 , '+' ) , length - 1 , '-' ) ) ; output . push ( '=' . repeat ( length ) ) ; } else { output = [ line ( '___' , length ) ] ; output . push ( line ( line ( '@@@' , length / 2 , '=' ) , length , '-' ) ) ; output . push ( line ( line ( ' 奉 納 ' , length - 6 , '+' ) , length - 1 , '-' ) ) ; output . push ( '=' . repeat ( length ) ) ; } return output ; } function footer ( length ) { let output ; if ( length < 8 ) { output = [ '=' . repeat ( length ) ] ; } else { output = [ '=' . repeat ( length ) ] ; output . push ( line ( '=' . repeat ( length - 4 ) , length ) ) ; } return output ; } function side ( content ) { const height = content . length ; let rownum = 0 ; let width ; return content . map ( function ( line ) { rownum ++ ; width = rownum > height / 2 ? height - rownum + 1 : rownum ; return ( ' ' . repeat ( height - width ) + '(' . repeat ( width ) + line + ')' . repeat ( width ) + ' ' . repeat ( height - width ) ) ; } ) ; } const Sakadaru = ( props ) => { const sakadaruDeoration = ( data ) => { let letters = data . split ( /\r?\n/g ) ; let length = 0 ; const height = letters . length ; letters = letters . map ( function ( line ) { length = line . length > length ? line . length + 1 : length ; return line + ' ' ; } ) ; let output = spacer ( header ( length ) , height ) ; output = output . concat ( side ( letters ) ) ; output = output . concat ( spacer ( footer ( length ) , height ) ) ; return output . join ( '\n' ) ; } ; return ( < AsciiArt name = { props . name } decoration = { sakadaruDeoration } / > ) ; } ; export default Sakadaru ;