-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslides.view.ts
277 lines (206 loc) · 5.9 KB
/
slides.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
namespace $.$$ {
export class $hyoo_slides extends $.$hyoo_slides {
sub() {
if( !this.uri_slides() ) {
return [ this.Menu() ]
}
return [
this.Loader() ,
... this.$.$mol_print.active()
? $mol_range2(
index => this.Page( index ) ,
()=> this.slide_keys().length ,
)
: [ this.Page( this.slide() ) ]
]
}
uri_base() {
return this.uri_slides().replace( /[^/]*$/ , '' )
}
@ $mol_mem
menu_items() {
return Object.keys( this.menu_options() ).map( uri => this.Menu_item( uri ) )
}
menu_item_uri( uri: string ) {
return uri
}
menu_item_title( uri: string ) {
return this.menu_options()[ uri ]
}
@ $mol_mem
contents( next = '' ) {
if( !this.uri_slides() ) return ''
this.Loader().window()
return next
}
@ $mol_mem
message_listener() {
return new $mol_dom_listener(
$mol_dom_context,
'message',
$mol_wire_async( ( event: MessageEvent< any > )=> {
const data = event.data
if( event.source !== this.Loader().window() ) return
if( !Array.isArray( data ) ) return
if( data[0] !== 'done' ) return
this.contents( data[1] )
} )
)
}
@ $mol_mem
content_pages() {
return this.contents().split( /^(?=[#=])/mg ) as string[]
}
@ $mol_mem_key
page_tokens( index : number ) {
const tokens = [] as { name : string , found : string , chunks: string[] }[]
this.$.$mol_syntax2_md_flow.tokenize(
this.content_pages()[ index ] || '',
( name , found , chunks )=> tokens.push({ name , found , chunks }),
)
return tokens as Readonly< typeof tokens >
}
@ $mol_mem_key
page_title( index : number ) {
for( let token of this.page_tokens( index ) ) {
if( token.name === 'header' ) return token.chunks[2]
}
return ''
}
@ $mol_mem
title() {
return this.page_title( this.slide() ) || super.title()
}
@ $mol_mem_key
speaker_content( index : number ) {
return this.page_tokens( index ).filter( token => {
if( token.name === 'header' ) return false
if( token.name !== 'block' ) return false
if( token.found.indexOf( '![' ) >= 0 ) return false
if( token.found.indexOf( '""' ) >= 0 ) return false
return true
} )
}
@ $mol_mem_key
listener_content( index : number ) {
return this.page_tokens( index ).filter( token => {
if( token.name === 'header' ) return false
if( token.name !== 'block' ) return true
if( token.found.indexOf( '![' ) >= 0 ) return true
if( token.found.indexOf( '""' ) >= 0 ) return true
return false
} )
}
@ $mol_mem
slide( next? : number ) {
if( next !== undefined ) {
const count = this.content_pages().length
if( next >= count ) next = count - 1
if( next < 0 ) next = 0
}
const local = $mol_state_local.value( `slide(${ JSON.stringify( this.uri_slides() ) })`, next )
const arg = $mol_state_arg.value( 'slide', next?.valueOf && String( next ) )
return ( local ?? Number( arg ) ) || 0
}
page_slide( index : number , next? : number ) {
if( next !== undefined ) this.slide( next )
return index
}
@ $mol_mem
slide_keys() {
return this.content_pages().map( ( _ , index )=> index )
}
role( next? : 'speaker' | 'listener' ) {
return $mol_state_arg.value( this.state_key( 'role' ) , next ) || 'speaker'
}
uri_slides() {
return $mol_state_arg.value( this.state_key( 'slides' ) ) ?? ''
}
event_next( next? : Event ) {
this.slide( this.slide() + 1 )
}
event_prev( next? : Event ) {
this.slide( this.slide() - 1 )
}
event_start( next? : Event ) {
this.slide( 0 )
}
event_end( next? : Event ) {
this.slide( this.content_pages().length - 1 )
}
event_slide( [ numb ] : [ string ] ) {
this.slide( Number( numb ) )
}
event_about( [ topic ] : [ string ] ) {
let matcher = topic
const pages = this.content_pages()
while( matcher.length > 2 ) {
for( let i = 0 ; i < pages.length ; ++i ) {
if( !pages[i]!.toLowerCase().match( matcher ) ) continue
this.slide( i )
return
}
matcher = matcher.substring( 0 , matcher.length - 1 )
}
matcher = topic
while( matcher.length > 2 ) {
for( let i = 0 ; i < pages.length ; ++i ) {
if( !pages[i].toLowerCase().match( matcher ) ) continue
this.slide( i )
return
}
matcher = matcher.substring( 0 , matcher.length - 1 )
}
}
event_repeat( next? : Event ) {
const commands = $mol_speech.commands()
const command = commands[ commands.length - 2 ]
if( command ) $mol_speech.say( command )
}
event_speech_on( next? : Event ) {
$mol_speech.speaking( true )
}
event_speech_off( next? : Event ) {
$mol_speech.speaking( false )
}
event_sing() {
this.$.$mol_speech.say( 'Не хочу! Не буду!' )
}
speech_enabled( next? : boolean ) {
return $mol_speech.hearing( next )
}
speech_text() {
const commands = $mol_speech.commands()
return commands.length && commands[ commands.length - 1 ] || ''
}
@ $mol_mem
lights( next? : boolean ) {
return this.$.$mol_lights( next )
}
event_lights_toggle() {
this.lights( !this.lights() )
}
@ $mol_mem
timings() {
return this.content_pages().map( page => page.length )
}
@ $mol_mem
timing_total() {
return this.timings().slice( 1 ).reduce( ( a , b )=> a + b , 0 )
}
@ $mol_mem_key
progress( index : number ) {
const timing = this.timings().slice( 1 , index + 1 ).reduce( ( a , b )=> a + b , 0 )
return timing / this.timing_total()
}
@ $mol_mem
speech_next_auto() {
const texts = this.speaker_content( this.slide() )
if( texts.length === 0 ) return []
const found = /[\s\S]*\s([a-zа-яё]+)[^a-zа-яё]*?/ui.exec( texts[ texts.length - 1 ].found )
if( !found ) return []
const suffix = found[1].replace( /(.)$/ , '$1?' )
return [ suffix ]
}
}
}