forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppStore.js
68 lines (64 loc) · 2.49 KB
/
AppStore.js
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
/**
* This source file is part of the Swift.org open source project
*
* Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
* Licensed under Apache License v2.0 with Runtime Library Exception
*
* See https://swift.org/LICENSE.txt for license information
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import ColorScheme from 'docc-render/constants/ColorScheme';
import ImageLoadingStrategy from 'docc-render/constants/ImageLoadingStrategy';
import Settings from 'docc-render/utils/settings';
import appLocales from 'theme/lang/locales.json';
const supportsAutoColorScheme = (typeof window.matchMedia !== 'undefined') && [
ColorScheme.light,
ColorScheme.dark,
'no-preference',
].some(scheme => window.matchMedia(`(prefers-color-scheme: ${scheme})`).matches);
const defaultColorScheme = supportsAutoColorScheme ? ColorScheme.auto : ColorScheme.light;
export default {
state: {
imageLoadingStrategy: process.env.VUE_APP_TARGET === 'ide'
? ImageLoadingStrategy.eager : ImageLoadingStrategy.lazy,
preferredColorScheme: Settings.preferredColorScheme || defaultColorScheme,
preferredLocale: Settings.preferredLocale,
supportsAutoColorScheme,
systemColorScheme: ColorScheme.light,
availableLocales: [],
},
reset() {
this.state.imageLoadingStrategy = process.env.VUE_APP_TARGET === 'ide'
? ImageLoadingStrategy.eager : ImageLoadingStrategy.lazy;
this.state.preferredColorScheme = Settings.preferredColorScheme || defaultColorScheme;
this.state.supportsAutoColorScheme = supportsAutoColorScheme;
this.state.systemColorScheme = ColorScheme.light;
},
setImageLoadingStrategy(strategy) {
this.state.imageLoadingStrategy = strategy;
},
setPreferredColorScheme(value) {
this.state.preferredColorScheme = value;
Settings.preferredColorScheme = value;
},
setAllLocalesAreAvailable() {
const allLocales = appLocales.map(locale => locale.code);
this.state.availableLocales = allLocales;
},
setAvailableLocales(locales = []) {
this.state.availableLocales = locales;
},
setPreferredLocale(locale) {
this.state.preferredLocale = locale;
Settings.preferredLocale = this.state.preferredLocale;
},
setSystemColorScheme(value) {
this.state.systemColorScheme = value;
},
syncPreferredColorScheme() {
if (!!Settings.preferredColorScheme
&& Settings.preferredColorScheme !== this.state.preferredColorScheme) {
this.state.preferredColorScheme = Settings.preferredColorScheme;
}
},
};