@webwriter/quiz 1.1.2 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +8 -0
- package/LICENSE +6 -6
- package/custom.d.ts +175 -175
- package/dist/widgets/webwriter-choice-item.js +69 -205
- package/dist/widgets/webwriter-choice.js +99 -214
- package/dist/widgets/webwriter-cloze-gap.js +74 -213
- package/dist/widgets/webwriter-cloze.js +71 -204
- package/dist/widgets/webwriter-mark.js +72 -205
- package/dist/widgets/webwriter-order-item.js +68 -201
- package/dist/widgets/webwriter-order.js +99 -209
- package/dist/widgets/webwriter-pairing-item.js +57 -160
- package/dist/widgets/webwriter-pairing.js +69 -196
- package/dist/widgets/webwriter-quiz.js +72 -211
- package/dist/widgets/webwriter-speech.js +71 -204
- package/dist/widgets/webwriter-task-explainer.js +57 -160
- package/dist/widgets/webwriter-task-hint.js +55 -158
- package/dist/widgets/webwriter-task-prompt.js +61 -170
- package/dist/widgets/webwriter-task.js +80 -205
- package/dist/widgets/webwriter-text.js +94 -205
- package/lit-localize.json +14 -14
- package/localization/bg.xlf +72 -69
- package/localization/cs.xlf +72 -69
- package/localization/da.xlf +72 -69
- package/localization/de.xlf +77 -74
- package/localization/el.xlf +72 -69
- package/localization/es.xlf +72 -69
- package/localization/et.xlf +72 -69
- package/localization/fi.xlf +72 -69
- package/localization/fr.xlf +72 -69
- package/localization/generated/bg.ts +30 -29
- package/localization/generated/cs.ts +30 -29
- package/localization/generated/da.ts +30 -29
- package/localization/generated/de.ts +30 -29
- package/localization/generated/el.ts +30 -29
- package/localization/generated/es.ts +30 -29
- package/localization/generated/et.ts +30 -29
- package/localization/generated/fi.ts +30 -29
- package/localization/generated/fr.ts +30 -29
- package/localization/generated/hu.ts +30 -29
- package/localization/generated/id.ts +30 -29
- package/localization/generated/index.js +2 -2
- package/localization/generated/it.ts +30 -29
- package/localization/generated/ja.ts +30 -29
- package/localization/generated/ko.ts +30 -29
- package/localization/generated/locale-codes.js +79 -79
- package/localization/generated/lt.ts +30 -29
- package/localization/generated/lv.ts +30 -29
- package/localization/generated/nb.ts +30 -29
- package/localization/generated/nl.ts +30 -29
- package/localization/generated/pl.ts +30 -29
- package/localization/generated/pt-BR.ts +30 -29
- package/localization/generated/pt-PT.ts +30 -29
- package/localization/generated/ro.ts +30 -29
- package/localization/generated/ru.ts +30 -29
- package/localization/generated/sk.ts +30 -29
- package/localization/generated/sl.ts +30 -29
- package/localization/generated/sv.ts +30 -29
- package/localization/generated/tr.ts +30 -29
- package/localization/generated/uk.ts +30 -29
- package/localization/generated/zh-hans.ts +30 -29
- package/localization/hu.xlf +72 -69
- package/localization/id.xlf +72 -69
- package/localization/it.xlf +72 -69
- package/localization/ja.xlf +72 -69
- package/localization/ko.xlf +72 -69
- package/localization/lt.xlf +72 -69
- package/localization/lv.xlf +72 -69
- package/localization/nb.xlf +72 -69
- package/localization/nl.xlf +72 -69
- package/localization/pl.xlf +72 -69
- package/localization/pt-BR.xlf +72 -69
- package/localization/pt-PT.xlf +72 -69
- package/localization/ro.xlf +72 -69
- package/localization/ru.xlf +72 -69
- package/localization/sk.xlf +72 -69
- package/localization/sl.xlf +72 -69
- package/localization/sv.xlf +72 -69
- package/localization/tr.xlf +72 -69
- package/localization/uk.xlf +72 -69
- package/localization/zh-hans.xlf +72 -69
- package/package.json +4 -3
- package/src/lib/combobox.ts +455 -455
- package/src/lib/highlighter-fill.svg +5 -5
- package/src/snippets/Beispiel-Choice.html +57 -57
- package/src/snippets/Beispiel-Mark.html +13 -13
- package/src/snippets/Beispiel-Order.html +52 -52
- package/src/snippets/Beispiel-Text.html +20 -20
- package/src/snippets/choice.html +7 -7
- package/src/snippets/cloze.html +3 -3
- package/src/snippets/mark.html +3 -3
- package/src/snippets/order.html +7 -7
- package/src/snippets/pairing.html +9 -9
- package/src/snippets/speech.html +3 -3
- package/src/snippets/text.html +3 -3
- package/src/snippets/wordsearch.html +3 -3
- package/src/widgets/webwriter-choice-item.ts +256 -253
- package/src/widgets/webwriter-choice.ts +352 -336
- package/src/widgets/webwriter-cloze-gap.ts +215 -215
- package/src/widgets/webwriter-cloze.ts +135 -135
- package/src/widgets/webwriter-mark.ts +431 -431
- package/src/widgets/webwriter-order-item.ts +440 -440
- package/src/widgets/webwriter-order.ts +326 -309
- package/src/widgets/webwriter-pairing-item.ts +160 -160
- package/src/widgets/webwriter-pairing.ts +192 -192
- package/src/widgets/webwriter-quiz.ts +281 -281
- package/src/widgets/webwriter-speech.ts +272 -272
- package/src/widgets/webwriter-task-explainer.ts +42 -42
- package/src/widgets/webwriter-task-hint.ts +22 -22
- package/src/widgets/webwriter-task-prompt.ts +23 -23
- package/src/widgets/webwriter-task.ts +554 -546
- package/src/widgets/webwriter-text.ts +176 -155
- package/tsconfig.json +6 -6
|
@@ -1,273 +1,273 @@
|
|
|
1
|
-
import {html, css, PropertyValueMap} from "lit"
|
|
2
|
-
import {LitElementWw} from "@webwriter/lit"
|
|
3
|
-
import {customElement, property, query} from "lit/decorators.js"
|
|
4
|
-
import "@shoelace-style/shoelace/dist/themes/light.css"
|
|
5
|
-
|
|
6
|
-
import IconMic from "bootstrap-icons/icons/mic.svg"
|
|
7
|
-
import IconMicFill from "bootstrap-icons/icons/mic-fill.svg"
|
|
8
|
-
import IconStopFill from "bootstrap-icons/icons/stop-fill.svg"
|
|
9
|
-
import IconTrash from "bootstrap-icons/icons/trash.svg"
|
|
10
|
-
import IconPlay from "bootstrap-icons/icons/play.svg"
|
|
11
|
-
import IconPause from "bootstrap-icons/icons/pause.svg"
|
|
12
|
-
import IconVolumeDown from "bootstrap-icons/icons/volume-down.svg"
|
|
13
|
-
import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js"
|
|
14
|
-
import SlRange from "@shoelace-style/shoelace/dist/components/range/range.component.js"
|
|
15
|
-
import SlButtonGroup from "@shoelace-style/shoelace/dist/components/button-group/button-group.component.js"
|
|
16
|
-
import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.component.js"
|
|
17
|
-
import SlFormatDate from "@shoelace-style/shoelace/dist/components/format-date/format-date.component.js"
|
|
18
|
-
import SlPopup from "@shoelace-style/shoelace/dist/components/popup/popup.component.js"
|
|
19
|
-
|
|
20
|
-
declare global {interface HTMLElementTagNameMap {
|
|
21
|
-
"webwriter-speech": WebwriterSpeech;
|
|
22
|
-
}}
|
|
23
|
-
|
|
24
|
-
import LOCALIZE from "../../localization/generated"
|
|
25
|
-
import {msg} from "@lit/localize"
|
|
26
|
-
|
|
27
|
-
@customElement("webwriter-speech")
|
|
28
|
-
export class WebwriterSpeech extends LitElementWw {
|
|
29
|
-
|
|
30
|
-
localize = LOCALIZE
|
|
31
|
-
|
|
32
|
-
static scopedElements = {
|
|
33
|
-
"sl-button": SlButton,
|
|
34
|
-
"sl-icon": SlIcon,
|
|
35
|
-
"sl-button-group": SlButtonGroup,
|
|
36
|
-
"sl-range": SlRange,
|
|
37
|
-
"sl-format-date": SlFormatDate,
|
|
38
|
-
"sl-popup": SlPopup
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static styles = css`
|
|
42
|
-
|
|
43
|
-
@keyframes blinker {
|
|
44
|
-
50% {
|
|
45
|
-
opacity: 0;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
sl-icon {
|
|
50
|
-
height: 20px;
|
|
51
|
-
width: 20px;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
sl-button-group {
|
|
55
|
-
width: 100%;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
#record {
|
|
59
|
-
position: relative;
|
|
60
|
-
#recording-indicator {
|
|
61
|
-
background: darkred;
|
|
62
|
-
border-radius: 100%;
|
|
63
|
-
height: 10px;
|
|
64
|
-
width: 10px;
|
|
65
|
-
position: absolute;
|
|
66
|
-
top: 5px;
|
|
67
|
-
right: 5px;
|
|
68
|
-
animation: blinker 1.25s linear infinite;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
#record:hover .idle {
|
|
73
|
-
display: none;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
:host([recording]) #record .torecord, :host(:not([recording])) #record:not(:hover) .torecord {
|
|
77
|
-
display: none;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
:host(:not([recording])) #record .tostop, :host([recording]) #record:not(:hover) .tostop {
|
|
81
|
-
display: none;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
:host(:not([recording])) #recording-indicator {
|
|
85
|
-
display: none;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
#playback {
|
|
89
|
-
width: 100%;
|
|
90
|
-
display: flex;
|
|
91
|
-
flex-direction: row;
|
|
92
|
-
align-items: center;
|
|
93
|
-
border-top: 1px solid var(--sl-color-gray-300);
|
|
94
|
-
border-bottom: 1px solid var(--sl-color-gray-300);
|
|
95
|
-
padding: 0 1ch;
|
|
96
|
-
gap: 1ch;
|
|
97
|
-
color: var(--sl-color-gray-800);
|
|
98
|
-
font-size: var(--sl-font-size-small);
|
|
99
|
-
user-select: none;
|
|
100
|
-
|
|
101
|
-
sl-range {
|
|
102
|
-
flex-grow: 1;
|
|
103
|
-
display: flex;
|
|
104
|
-
flex-direction: row;
|
|
105
|
-
align-items: center;
|
|
106
|
-
|
|
107
|
-
&::part(form-control) {
|
|
108
|
-
width: 100%;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
:host(:not([src])) #playback {
|
|
114
|
-
opacity: 0.5;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
sl-button {
|
|
118
|
-
&::part(label) {
|
|
119
|
-
display: flex;
|
|
120
|
-
flex-direction: row;
|
|
121
|
-
align-items: center;
|
|
122
|
-
gap: 1ch;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
sl-tooltip {
|
|
127
|
-
z-index: 1;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
#volume {
|
|
131
|
-
--arrow-color: var(--sl-color-gray-600);
|
|
132
|
-
&::part(popup) {
|
|
133
|
-
background: var(--arrow-color);
|
|
134
|
-
height: 30px;
|
|
135
|
-
padding: 1ch;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
`
|
|
139
|
-
|
|
140
|
-
mediaRecorder: MediaRecorder
|
|
141
|
-
chunks = [] as Blob[]
|
|
142
|
-
|
|
143
|
-
@property({type: Boolean, attribute: true})
|
|
144
|
-
accessor loading = false
|
|
145
|
-
|
|
146
|
-
@property({type: String, attribute: true, reflect: true})
|
|
147
|
-
accessor src: string
|
|
148
|
-
|
|
149
|
-
firstUpdated() {
|
|
150
|
-
const evs = ["abort", "canplay", "canplaythrough", "durationchange", "emptied", "ended", "error", "loadeddata", "loadedmetadata", "loadstart", "pause", "play", "playing", "progress", "ratechange", "resize", "seeked", "seeking", "stalled", "suspend", "timeupdate", "volumechange", "waiting"] as const
|
|
151
|
-
evs.forEach(k => this.audioEl.addEventListener(k, ()=>this.requestUpdate()))
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
connectedCallback(): void {
|
|
155
|
-
super.connectedCallback()
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.mediaRecorder
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
reader.
|
|
177
|
-
|
|
178
|
-
this.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
await this.initializeRecorder()
|
|
195
|
-
this.mediaRecorder.start()
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
@query("audio")
|
|
200
|
-
accessor audioEl: HTMLAudioElement
|
|
201
|
-
|
|
202
|
-
get duration() {
|
|
203
|
-
const d = this.audioEl?.duration
|
|
204
|
-
return !Number.isNaN(d) && Number.isFinite(d)? d: 0
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
get currentTime() {
|
|
208
|
-
return this.audioEl?.currentTime
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
get playing() {
|
|
212
|
-
return !this.audioEl?.paused && !this.audioEl?.ended
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
get recording() {
|
|
217
|
-
return this.mediaRecorder?.state === "recording"
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
@property({type: Boolean, attribute: true, reflect: true})
|
|
221
|
-
set recording(value: boolean) {
|
|
222
|
-
return
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
get volume() {
|
|
226
|
-
return Math.round(this.audioEl?.volume * 100)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
set volume(value: number) {
|
|
230
|
-
this.audioEl.volume = value / 100
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
togglePlay = () => {
|
|
234
|
-
!this.playing? this.audioEl.play(): this.audioEl.pause()
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
@property({type: Boolean})
|
|
238
|
-
accessor volumeOpen = false
|
|
239
|
-
|
|
240
|
-
render() {
|
|
241
|
-
return html`<sl-button-group>
|
|
242
|
-
<sl-button id="record" @click=${this.toggleRecording} ?loading=${this.loading} ?disabled=${this.loading}>
|
|
243
|
-
<sl-icon class="idle" src=${IconMic}></sl-icon>
|
|
244
|
-
<sl-icon class="torecord" src=${IconMicFill}></sl-icon>
|
|
245
|
-
<sl-icon class="tostop" src=${IconStopFill}></sl-icon>
|
|
246
|
-
<div id="recording-indicator"></div>
|
|
247
|
-
</sl-button>
|
|
248
|
-
<sl-button id="playpause" ?disabled=${this.loading || !this.src} @click=${this.togglePlay}>
|
|
249
|
-
<sl-icon src=${!this.playing? IconPlay: IconPause}></sl-icon>
|
|
250
|
-
</sl-button>
|
|
251
|
-
<div id="playback">
|
|
252
|
-
<audio src=${this.src} preload="metadata"></audio>
|
|
253
|
-
<div>
|
|
254
|
-
<sl-format-date .date=${new Date(this.currentTime * 1000)} minute="numeric" second="numeric"></sl-format-date>
|
|
255
|
-
/
|
|
256
|
-
<sl-format-date .date=${new Date(this.duration * 1000)} minute="numeric" second="numeric"></sl-format-date>
|
|
257
|
-
</div>
|
|
258
|
-
<sl-range ?disabled=${this.loading || !this.src}></sl-range>
|
|
259
|
-
</div>
|
|
260
|
-
<sl-popup id="volume" ?active=${this.volumeOpen} hoist strategy="fixed" arrow distance="6">
|
|
261
|
-
<sl-button ?disabled=${this.loading || !this.src} slot="anchor" @click=${() => this.volumeOpen = !this.volumeOpen}>
|
|
262
|
-
<sl-icon src=${IconVolumeDown}></sl-icon>
|
|
263
|
-
</sl-button>
|
|
264
|
-
<sl-range ?disabled=${this.loading || !this.src} id="volume-range" value=${this.volume} @sl-change=${(e: any) => this.volume = e.target.value}>
|
|
265
|
-
|
|
266
|
-
</sl-range>
|
|
267
|
-
</sl-popup>
|
|
268
|
-
<sl-button ?disabled=${this.loading || !this.src} id="delete" @click=${() => this.src = undefined}>
|
|
269
|
-
<sl-icon src=${IconTrash}></sl-icon>
|
|
270
|
-
</sl-button>
|
|
271
|
-
</sl-button-group>`
|
|
272
|
-
}
|
|
1
|
+
import {html, css, PropertyValueMap} from "lit"
|
|
2
|
+
import {LitElementWw} from "@webwriter/lit"
|
|
3
|
+
import {customElement, property, query} from "lit/decorators.js"
|
|
4
|
+
import "@shoelace-style/shoelace/dist/themes/light.css"
|
|
5
|
+
|
|
6
|
+
import IconMic from "bootstrap-icons/icons/mic.svg"
|
|
7
|
+
import IconMicFill from "bootstrap-icons/icons/mic-fill.svg"
|
|
8
|
+
import IconStopFill from "bootstrap-icons/icons/stop-fill.svg"
|
|
9
|
+
import IconTrash from "bootstrap-icons/icons/trash.svg"
|
|
10
|
+
import IconPlay from "bootstrap-icons/icons/play.svg"
|
|
11
|
+
import IconPause from "bootstrap-icons/icons/pause.svg"
|
|
12
|
+
import IconVolumeDown from "bootstrap-icons/icons/volume-down.svg"
|
|
13
|
+
import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js"
|
|
14
|
+
import SlRange from "@shoelace-style/shoelace/dist/components/range/range.component.js"
|
|
15
|
+
import SlButtonGroup from "@shoelace-style/shoelace/dist/components/button-group/button-group.component.js"
|
|
16
|
+
import SlIcon from "@shoelace-style/shoelace/dist/components/icon/icon.component.js"
|
|
17
|
+
import SlFormatDate from "@shoelace-style/shoelace/dist/components/format-date/format-date.component.js"
|
|
18
|
+
import SlPopup from "@shoelace-style/shoelace/dist/components/popup/popup.component.js"
|
|
19
|
+
|
|
20
|
+
declare global {interface HTMLElementTagNameMap {
|
|
21
|
+
"webwriter-speech": WebwriterSpeech;
|
|
22
|
+
}}
|
|
23
|
+
|
|
24
|
+
import LOCALIZE from "../../localization/generated"
|
|
25
|
+
import {msg} from "@lit/localize"
|
|
26
|
+
|
|
27
|
+
@customElement("webwriter-speech")
|
|
28
|
+
export class WebwriterSpeech extends LitElementWw {
|
|
29
|
+
|
|
30
|
+
localize = LOCALIZE
|
|
31
|
+
|
|
32
|
+
static scopedElements = {
|
|
33
|
+
"sl-button": SlButton,
|
|
34
|
+
"sl-icon": SlIcon,
|
|
35
|
+
"sl-button-group": SlButtonGroup,
|
|
36
|
+
"sl-range": SlRange,
|
|
37
|
+
"sl-format-date": SlFormatDate,
|
|
38
|
+
"sl-popup": SlPopup
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static styles = css`
|
|
42
|
+
|
|
43
|
+
@keyframes blinker {
|
|
44
|
+
50% {
|
|
45
|
+
opacity: 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
sl-icon {
|
|
50
|
+
height: 20px;
|
|
51
|
+
width: 20px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
sl-button-group {
|
|
55
|
+
width: 100%;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#record {
|
|
59
|
+
position: relative;
|
|
60
|
+
#recording-indicator {
|
|
61
|
+
background: darkred;
|
|
62
|
+
border-radius: 100%;
|
|
63
|
+
height: 10px;
|
|
64
|
+
width: 10px;
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: 5px;
|
|
67
|
+
right: 5px;
|
|
68
|
+
animation: blinker 1.25s linear infinite;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#record:hover .idle {
|
|
73
|
+
display: none;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
:host([recording]) #record .torecord, :host(:not([recording])) #record:not(:hover) .torecord {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
:host(:not([recording])) #record .tostop, :host([recording]) #record:not(:hover) .tostop {
|
|
81
|
+
display: none;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
:host(:not([recording])) #recording-indicator {
|
|
85
|
+
display: none;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#playback {
|
|
89
|
+
width: 100%;
|
|
90
|
+
display: flex;
|
|
91
|
+
flex-direction: row;
|
|
92
|
+
align-items: center;
|
|
93
|
+
border-top: 1px solid var(--sl-color-gray-300);
|
|
94
|
+
border-bottom: 1px solid var(--sl-color-gray-300);
|
|
95
|
+
padding: 0 1ch;
|
|
96
|
+
gap: 1ch;
|
|
97
|
+
color: var(--sl-color-gray-800);
|
|
98
|
+
font-size: var(--sl-font-size-small);
|
|
99
|
+
user-select: none;
|
|
100
|
+
|
|
101
|
+
sl-range {
|
|
102
|
+
flex-grow: 1;
|
|
103
|
+
display: flex;
|
|
104
|
+
flex-direction: row;
|
|
105
|
+
align-items: center;
|
|
106
|
+
|
|
107
|
+
&::part(form-control) {
|
|
108
|
+
width: 100%;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
:host(:not([src])) #playback {
|
|
114
|
+
opacity: 0.5;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
sl-button {
|
|
118
|
+
&::part(label) {
|
|
119
|
+
display: flex;
|
|
120
|
+
flex-direction: row;
|
|
121
|
+
align-items: center;
|
|
122
|
+
gap: 1ch;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
sl-tooltip {
|
|
127
|
+
z-index: 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#volume {
|
|
131
|
+
--arrow-color: var(--sl-color-gray-600);
|
|
132
|
+
&::part(popup) {
|
|
133
|
+
background: var(--arrow-color);
|
|
134
|
+
height: 30px;
|
|
135
|
+
padding: 1ch;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
`
|
|
139
|
+
|
|
140
|
+
mediaRecorder: MediaRecorder
|
|
141
|
+
chunks = [] as Blob[]
|
|
142
|
+
|
|
143
|
+
@property({type: Boolean, attribute: true})
|
|
144
|
+
accessor loading = false
|
|
145
|
+
|
|
146
|
+
@property({type: String, attribute: true, reflect: true})
|
|
147
|
+
accessor src: string
|
|
148
|
+
|
|
149
|
+
firstUpdated() {
|
|
150
|
+
const evs = ["abort", "canplay", "canplaythrough", "durationchange", "emptied", "ended", "error", "loadeddata", "loadedmetadata", "loadstart", "pause", "play", "playing", "progress", "ratechange", "resize", "seeked", "seeking", "stalled", "suspend", "timeupdate", "volumechange", "waiting"] as const
|
|
151
|
+
evs.forEach(k => this.audioEl.addEventListener(k, ()=>this.requestUpdate()))
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
connectedCallback(): void {
|
|
155
|
+
super.connectedCallback()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async initializeRecorder() {
|
|
159
|
+
if(!this.mediaRecorder) {
|
|
160
|
+
this.loading = true
|
|
161
|
+
try {
|
|
162
|
+
const stream = await navigator.mediaDevices.getUserMedia({audio: true})
|
|
163
|
+
this.mediaRecorder = new MediaRecorder(stream)
|
|
164
|
+
this.mediaRecorder.addEventListener("start", e => {
|
|
165
|
+
this.requestUpdate("recording")
|
|
166
|
+
})
|
|
167
|
+
this.mediaRecorder.addEventListener("dataavailable", e => {
|
|
168
|
+
this.chunks.push(e.data)
|
|
169
|
+
})
|
|
170
|
+
this.mediaRecorder.addEventListener("stop", async e => {
|
|
171
|
+
const blob = new Blob(this.chunks, {type: "audio/ogg; codecs=opus"})
|
|
172
|
+
this.chunks = []
|
|
173
|
+
this.src = URL.createObjectURL(blob)
|
|
174
|
+
const reader = new FileReader()
|
|
175
|
+
reader.readAsDataURL(blob)
|
|
176
|
+
reader.addEventListener("load", e => {
|
|
177
|
+
this.src = reader.result as string
|
|
178
|
+
this.requestUpdate("recording")
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
this.loading = false
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
toggleRecording = async () => {
|
|
189
|
+
if(this.mediaRecorder?.state === "recording") {
|
|
190
|
+
this.mediaRecorder.stop()
|
|
191
|
+
this.mediaRecorder.stream.getTracks().forEach(track => track.stop())
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
await this.initializeRecorder()
|
|
195
|
+
this.mediaRecorder.start()
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@query("audio")
|
|
200
|
+
accessor audioEl: HTMLAudioElement
|
|
201
|
+
|
|
202
|
+
get duration() {
|
|
203
|
+
const d = this.audioEl?.duration
|
|
204
|
+
return !Number.isNaN(d) && Number.isFinite(d)? d: 0
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
get currentTime() {
|
|
208
|
+
return this.audioEl?.currentTime
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
get playing() {
|
|
212
|
+
return !this.audioEl?.paused && !this.audioEl?.ended
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
get recording() {
|
|
217
|
+
return this.mediaRecorder?.state === "recording"
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@property({type: Boolean, attribute: true, reflect: true})
|
|
221
|
+
set recording(value: boolean) {
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
get volume() {
|
|
226
|
+
return Math.round(this.audioEl?.volume * 100)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
set volume(value: number) {
|
|
230
|
+
this.audioEl.volume = value / 100
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
togglePlay = () => {
|
|
234
|
+
!this.playing? this.audioEl.play(): this.audioEl.pause()
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@property({type: Boolean})
|
|
238
|
+
accessor volumeOpen = false
|
|
239
|
+
|
|
240
|
+
render() {
|
|
241
|
+
return html`<sl-button-group>
|
|
242
|
+
<sl-button id="record" @click=${this.toggleRecording} ?loading=${this.loading} ?disabled=${this.loading}>
|
|
243
|
+
<sl-icon class="idle" src=${IconMic}></sl-icon>
|
|
244
|
+
<sl-icon class="torecord" src=${IconMicFill}></sl-icon>
|
|
245
|
+
<sl-icon class="tostop" src=${IconStopFill}></sl-icon>
|
|
246
|
+
<div id="recording-indicator"></div>
|
|
247
|
+
</sl-button>
|
|
248
|
+
<sl-button id="playpause" ?disabled=${this.loading || !this.src} @click=${this.togglePlay}>
|
|
249
|
+
<sl-icon src=${!this.playing? IconPlay: IconPause}></sl-icon>
|
|
250
|
+
</sl-button>
|
|
251
|
+
<div id="playback">
|
|
252
|
+
<audio src=${this.src} preload="metadata"></audio>
|
|
253
|
+
<div>
|
|
254
|
+
<sl-format-date .date=${new Date(this.currentTime * 1000)} minute="numeric" second="numeric"></sl-format-date>
|
|
255
|
+
/
|
|
256
|
+
<sl-format-date .date=${new Date(this.duration * 1000)} minute="numeric" second="numeric"></sl-format-date>
|
|
257
|
+
</div>
|
|
258
|
+
<sl-range ?disabled=${this.loading || !this.src}></sl-range>
|
|
259
|
+
</div>
|
|
260
|
+
<sl-popup id="volume" ?active=${this.volumeOpen} hoist strategy="fixed" arrow distance="6">
|
|
261
|
+
<sl-button ?disabled=${this.loading || !this.src} slot="anchor" @click=${() => this.volumeOpen = !this.volumeOpen}>
|
|
262
|
+
<sl-icon src=${IconVolumeDown}></sl-icon>
|
|
263
|
+
</sl-button>
|
|
264
|
+
<sl-range ?disabled=${this.loading || !this.src} id="volume-range" value=${this.volume} @sl-change=${(e: any) => this.volume = e.target.value}>
|
|
265
|
+
|
|
266
|
+
</sl-range>
|
|
267
|
+
</sl-popup>
|
|
268
|
+
<sl-button ?disabled=${this.loading || !this.src} id="delete" @click=${() => this.src = undefined}>
|
|
269
|
+
<sl-icon src=${IconTrash}></sl-icon>
|
|
270
|
+
</sl-button>
|
|
271
|
+
</sl-button-group>`
|
|
272
|
+
}
|
|
273
273
|
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import {html, css} from "lit"
|
|
2
|
-
import {LitElementWw} from "@webwriter/lit"
|
|
3
|
-
import {customElement, property} from "lit/decorators.js"
|
|
4
|
-
import "@shoelace-style/shoelace/dist/themes/light.css"
|
|
5
|
-
import { styleMap } from "lit/directives/style-map.js";
|
|
6
|
-
|
|
7
|
-
import LOCALIZE from "../../localization/generated"
|
|
8
|
-
import {msg} from "@lit/localize"
|
|
9
|
-
|
|
10
|
-
declare global {interface HTMLElementTagNameMap {
|
|
11
|
-
"webwriter-task-explainer": WebwriterTaskExplainer;
|
|
12
|
-
}}
|
|
13
|
-
|
|
14
|
-
@customElement("webwriter-task-explainer")
|
|
15
|
-
export class WebwriterTaskExplainer extends LitElementWw {
|
|
16
|
-
|
|
17
|
-
localize = LOCALIZE
|
|
18
|
-
|
|
19
|
-
@property({type: Boolean, attribute: true, reflect: true})
|
|
20
|
-
accessor active = false
|
|
21
|
-
|
|
22
|
-
static styles = css`
|
|
23
|
-
:host {
|
|
24
|
-
background: var(--sl-color-gray-100);
|
|
25
|
-
border: 2px solid var(--sl-color-gray-200);
|
|
26
|
-
box-sizing: border-box;
|
|
27
|
-
padding: 10px;
|
|
28
|
-
font-size: 0.8rem;
|
|
29
|
-
height: 100px;
|
|
30
|
-
min-height: 100px;
|
|
31
|
-
overflow-y: auto;
|
|
32
|
-
scrollbar-width: thin;
|
|
33
|
-
resize: vertical;
|
|
34
|
-
display: block;
|
|
35
|
-
}
|
|
36
|
-
`
|
|
37
|
-
|
|
38
|
-
render() {
|
|
39
|
-
return html`<slot>
|
|
40
|
-
|
|
41
|
-
</slot>`
|
|
42
|
-
}
|
|
1
|
+
import {html, css} from "lit"
|
|
2
|
+
import {LitElementWw} from "@webwriter/lit"
|
|
3
|
+
import {customElement, property} from "lit/decorators.js"
|
|
4
|
+
import "@shoelace-style/shoelace/dist/themes/light.css"
|
|
5
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
6
|
+
|
|
7
|
+
import LOCALIZE from "../../localization/generated"
|
|
8
|
+
import {msg} from "@lit/localize"
|
|
9
|
+
|
|
10
|
+
declare global {interface HTMLElementTagNameMap {
|
|
11
|
+
"webwriter-task-explainer": WebwriterTaskExplainer;
|
|
12
|
+
}}
|
|
13
|
+
|
|
14
|
+
@customElement("webwriter-task-explainer")
|
|
15
|
+
export class WebwriterTaskExplainer extends LitElementWw {
|
|
16
|
+
|
|
17
|
+
localize = LOCALIZE
|
|
18
|
+
|
|
19
|
+
@property({type: Boolean, attribute: true, reflect: true})
|
|
20
|
+
accessor active = false
|
|
21
|
+
|
|
22
|
+
static styles = css`
|
|
23
|
+
:host {
|
|
24
|
+
background: var(--sl-color-gray-100);
|
|
25
|
+
border: 2px solid var(--sl-color-gray-200);
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
padding: 10px;
|
|
28
|
+
font-size: 0.8rem;
|
|
29
|
+
height: 100px;
|
|
30
|
+
min-height: 100px;
|
|
31
|
+
overflow-y: auto;
|
|
32
|
+
scrollbar-width: thin;
|
|
33
|
+
resize: vertical;
|
|
34
|
+
display: block;
|
|
35
|
+
}
|
|
36
|
+
`
|
|
37
|
+
|
|
38
|
+
render() {
|
|
39
|
+
return html`<slot>
|
|
40
|
+
|
|
41
|
+
</slot>`
|
|
42
|
+
}
|
|
43
43
|
}
|