function mainView(state, emit) { if (state.fullscreen) { return html`
${Fullscreen(state, emit)}
` } return html`
{ if (!(e.target.id === 'display-image') && !(e.target.id === 'display')) { emit('deselect-display') } }}> ${Display(state, emit)} ${Toolbar(state, emit)} ${Keys(state, emit)}
${PhotoBooth(state, emit)} ${SoundRecorder(state, emit)}
${state.waiting ? Waiting(state, emit) : null} ${state.clickHere ? ClickHere(state, emit) : null} ${state.isTutorialOpen ? Tutorial(state, emit) : null}
` } function dataToDisplay(state, emit) { if (state.displayData === '') { imgData = state.images['display'] } else { imgData = state.displayData } return imgData } function Display(state, emit) { let selected = state.selectedKey === 'display' ? 'selected' : '' let imgData = dataToDisplay(state, emit) let style = `background-image: url('${imgData}')` //display onmousedown should not be triggered when clicking on the fullscreen button return html`
{ if (e.target.id === 'display-image' || e.target.id === 'display') { emit('select-display') } } }>
` } function Toolbar(state, emit) { let exportDisabledClass = '' if (isAllFalse(state.images) && isAllFalse(state.sounds)) { exportDisabledClass = 'disabled' } let uploadDisabledClass = !state.selectedKey && !state.isDisplaySelected ? 'disabled' : '' return html`
` } function Keys(state, emit) { let buttons = KEYS.filter(k => k !== 'display').map((key) => { let imageName = key === ' ' ? 'space' : key let image = html`${key}` let classList = [] if (state.selectedKey === key) { classList.push('primary') } else if (state.sounds[key] === null && state.images[key] === null) { classList.push('empty') } classList = classList.join(' ') return html` ` }) return html`
${buttons}
` } function PhotoBooth(state, emit) { let photoBoothEnabledClass = state.selectedKey ? '' : 'disabled' let image = state.images[state.selectedKey] let downloadEnabledClass = image ? '' : 'disabled' let previewElement = html`` function onCameraClick() { if (state.cameraStream === null) { emit('remove-image') emit('start-camera-stream') } else { if (image) { emit('remove-image') } else { emit('capture-image') } } } if (state.selectedKey) { if (image) { previewElement = html`
` } else if (state.cameraStream !== null) { previewElement = html`` previewElement.srcObject = state.cameraStream } } return html`
${previewElement}
` } function SoundRecorder(state, emit) { let photoBoothEnabledClass = (state.selectedKey && state.selectedKey !== 'display') ? '' : 'disabled' let sound = state.sounds[state.selectedKey] let controlsEnabledClass = sound ? '' : 'disabled' let meter = state.soundAmplitudes[state.selectedKey] let preview = html`
` if ( (sound && meter.length > 0) || (state.recorder && state.recorder.state === 'started') ) { preview = html`
emit('handle-crop-click', e)}> ${meter.map((p) => html`
`)}
` } else if (sound && meter.length === 0) { preview = html`
File
` } let micMessage = html`click to enable` if (state.recorder) { micMessage = html`hold to record` } let holdToRecord = html` ` let soundControl = html` ` if (state.sounds[state.selectedKey] && state.sounds[state.selectedKey].state === 'started') { soundControl = html` ` } return html`
${preview} ${holdToRecord}
${soundControl}
` } function Fullscreen(state, emit) { let imgData = dataToDisplay(state, emit) let style = `background-image: url('${imgData}')` return html`
` } function Waiting(state, emit) { return html`
false}>
` } function ClickHere(state, emit){ return html`
false}>
click to start
` } function Tutorial(state, emit) { return html`
emit('exit-tutorial')}>
` } window.addEventListener('load', () => { let app = Choo() app.use(store) app.route('*', mainView) app.mount('#app') })