@@ -6,28 +6,32 @@ import { config, configPath, configDownloadPath } from './static.js'
66import { generateSVG , generateShape } from './generate.js' ;
77import { parse } from './parse.js' ;
88import { preview } from './preview/index.js' ;
9- import { render } from './render.js' ;
9+ import { render } from './render/index .js' ;
1010import { read } from './read.js' ;
1111
1212export async function handleRender ( source , options ) {
1313 const { content, error, type } = await read ( source ) ;
1414 if ( error ) {
1515 return console . error ( error . message ) ;
1616 }
17- let title = 'image' ;
17+ options . type = type ;
18+ options . delay = readTime ( options . delay , { max : 30 * 1000 } ) || 0 ;
19+ options . time = readTime ( options . time , { max : 60 * 1000 } ) || 0 ;
20+ options . scale = Number ( options . scale ) || 2 ;
21+ options . selector ??= 'css-doodle' ;
22+
23+ let title = options . time ? 'record' : 'image' ;
1824 if ( source ) {
1925 const basename = path . basename ( source ) ;
2026 const extname = path . extname ( basename ) ;
2127 title = extname ? basename . split ( extname ) [ 0 ] : basename ;
2228 }
2329 options . title = title ;
24- options . type = type ;
2530
2631 try {
2732 const start = Date . now ( ) ;
2833 const output = await render ( content , options ) ;
2934 const time = ( Date . now ( ) - start ) / 1000 ;
30-
3135 if ( output ) {
3236 console . log ( `Saved to ${ output } . (${ time } s)` ) ;
3337 }
@@ -182,3 +186,17 @@ async function fetchResource(url) {
182186 let res = await fetch ( url , { redirect : 'follow' } ) ;
183187 return Buffer . from ( await res . arrayBuffer ( ) ) . toString ( ) ;
184188}
189+
190+ function readTime ( number , options = { } ) {
191+ let result = 0 ;
192+ if ( / ^ ( \d + ) ( m s ) ? $ / . test ( number ) ) {
193+ result = Number ( number . replace ( 'ms' , '' ) ) ;
194+ }
195+ if ( / ^ ( \d + ) s $ / . test ( number ) ) {
196+ result = Number ( number . replace ( 's' , '' ) ) * 1000 ;
197+ }
198+ if ( / ^ ( \d + ) m $ / . test ( number ) ) {
199+ result = Number ( number . replace ( 'm' , '' ) ) * 60 * 1000 ;
200+ }
201+ return Math . min ( result , options . max ?? Infinity ) ;
202+ }
0 commit comments