-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeme.view.ts
102 lines (83 loc) · 2.18 KB
/
meme.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
namespace $.$$ {
type Frame_data = ReturnType< $hyoo_meme_frame['data'] >
export class $hyoo_meme extends $.$hyoo_meme {
async load_file( blob: Blob ) {
return new Promise< string >( ( done, fail )=> {
const reader = new FileReader
reader.onerror = fail
reader.onload = event => done( event.target!.result as string )
reader.readAsDataURL( blob )
} )
}
@ $mol_mem
data( next?: readonly Frame_data[] ) {
return this.$.$mol_state_local.value( 'draft', next ) ?? [
{
back: "hyoo/meme/gallery/bus.jfif",
before: "Hype train ",
inside: "Your \nIdea ",
after: " Too $mol bus-factor",
}
]
}
@ $mol_mem
title() {
for( const frame of this.data() ) {
if( frame.before ) return frame.before
if( frame.after ) return frame.after
}
return super.title()
}
paste( event: ClipboardEvent ) {
const files = [ ... event.clipboardData!.files ]
$mol_wire_async( this ).add( files )
}
add( files: readonly File[] ) {
this.data([
... this.data(),
... [ ... files ]
.map( file => $mol_picture.fit( file, 800 ).format("image/webp" )! )
.map( file => ({
back: $mol_wire_sync( this as $hyoo_meme ).load_file( file ),
before: '',
inside: '',
after: '',
}) ),
])
return files
}
@ $mol_mem
frames() {
return this.data().map( ( _, i )=> this.Frame( i ) )
}
frame_data( index: number, next?: Frame_data | null ) {
const arg = next === undefined ? undefined : [
... this.data().slice( 0, index ),
... next ? [ next ] : [],
... this.data().slice( index + 1 ),
]
return this.data( arg )[ index ]
}
frame_drop( index: number ) {
this.frame_data( index, null )
}
@ $mol_mem
file_name() {
return this.title() + '.jpg'
}
@ $mol_action
picture() {
const node = this.Frames().dom_tree()
const img = $mol_wire_sync( this.$ ).$mol_dom_capture_image( node )
return $mol_picture.fit( img )
}
@ $mol_action
export_jpg() {
return this.picture().format( 'image/jpeg' )!
}
@ $mol_action
export_png() {
return this.picture().format( 'image/png' )!
}
}
}