okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
9caf39495
main
1/** The pictures on the clipboard, named so each one is told apart in the composer (a pasted screenshot arrives as "image.png"). */ 2export function pastedFiles ( data :DataTransfer | null | undefined ) :File [] { 3const out :File [] = []; 4const found :File [] = Array . from ( data ?. files ?? []); 5// A screenshot from the clipboard (Win+Shift+S) often comes as an item and not in `files` (#3748). 6if ( ! found . some ( f => f . type . startsWith ( 'image/' ))) { 7for ( const item of Array . from ( data ?. items ?? [])) { 8if ( item . kind !== 'file' || ! item . type . startsWith ( 'image/' )) continue ; 9const file = item . getAsFile (); 10if ( file ) found . push ( file ); 11} 12} 13for ( const file of found ) { 14if ( ! file . type . startsWith ( 'image/' )) continue ; 15const extension = file . type . split ( '/' )[ 1 ]?. replace ( 'jpeg' , 'jpg' ). replace ( / [+].* / , '' ) || 'png' ; 16out . push ( new File ([ file ], `Pasted picture ${ new Date (). toLocaleTimeString (). replace ( / [^0-9]+ / g , '-' ). replace ( / -$ / , '' )} ${ out . length ? `- ${ out . length + 1 } ` : '' } . ${ extension } ` , { type :file . type })); 17} 18return out ; 19}