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
| import { defineStore } from 'pinia'
|
| const SPEED_PITCH_FIELDS = ['ttsVolume', 'ttsRate', 'ttsPitch'] as const
|
| type SpeedPitchField = typeof SPEED_PITCH_FIELDS[number]
| type SpeedPitchSettings = Record<SpeedPitchField, number>
|
| export const useSpeedPitch = defineStore('speedPitch', () => {
| const speedPitch = ref<SpeedPitchSettings>({
| ttsVolume: 0,
| ttsRate: 0,
| ttsPitch: 0,
| })
| const changedFields = ref<SpeedPitchField[]>([])
|
| const updateSpeedPitch = (val: SpeedPitchSettings, options: { changedFields?: SpeedPitchField[] } = {}) => {
| speedPitch.value = val
| if (options.changedFields) {
| changedFields.value = Array.from(new Set([
| ...changedFields.value,
| ...options.changedFields,
| ]))
| }
| }
|
| const resetChangedFields = () => {
| changedFields.value = []
| }
|
| return {
| speedPitch,
| changedFields,
| updateSpeedPitch,
| resetChangedFields,
| }
| }, {
| persist: {
| key: 'speedPitch',
| serializer: {
| serialize: state => JSON.stringify(state.speedPitch),
| deserialize: value => ({ speedPitch: JSON.parse(value) }),
| },
| },
| })
|
|