2020-07-11 12:12:35 +09:00
|
|
|
<template>
|
2021-01-09 17:18:45 +09:00
|
|
|
<FormBase class="cwepdizn">
|
|
|
|
<div class="_formItem colorPicker">
|
|
|
|
<div class="_formLabel">{{ $ts.backgroundColor }}</div>
|
|
|
|
<div class="_formPanel colors">
|
2021-01-09 21:47:07 +09:00
|
|
|
<div class="row">
|
2021-01-09 22:02:26 +09:00
|
|
|
<button v-for="color in bgColors.filter(x => x.kind === 'light')" :key="color.color" @click="bgColor = color" class="color _button" :class="{ active: bgColor?.color === color.color }">
|
2021-01-09 21:47:07 +09:00
|
|
|
<div class="preview" :style="{ background: color.forPreview }"></div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
2021-01-09 22:02:26 +09:00
|
|
|
<button v-for="color in bgColors.filter(x => x.kind === 'dark')" :key="color.color" @click="bgColor = color" class="color _button" :class="{ active: bgColor?.color === color.color }">
|
2021-01-09 21:47:07 +09:00
|
|
|
<div class="preview" :style="{ background: color.forPreview }"></div>
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
2021-01-09 17:18:45 +09:00
|
|
|
</div>
|
|
|
|
<div class="_formItem colorPicker">
|
|
|
|
<div class="_formLabel">{{ $ts.accentColor }}</div>
|
|
|
|
<div class="_formPanel colors">
|
2021-01-09 21:47:07 +09:00
|
|
|
<div class="row">
|
|
|
|
<button v-for="color in accentColors" :key="color" @click="accentColor = color" class="color rounded _button" :class="{ active: accentColor === color }">
|
|
|
|
<div class="preview" :style="{ background: color }"></div>
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-07-11 12:12:35 +09:00
|
|
|
</div>
|
2021-01-09 17:18:45 +09:00
|
|
|
</div>
|
|
|
|
<div class="_formItem colorPicker">
|
|
|
|
<div class="_formLabel">{{ $ts.textColor }}</div>
|
|
|
|
<div class="_formPanel colors">
|
2021-01-09 21:47:07 +09:00
|
|
|
<div class="row">
|
|
|
|
<button v-for="color in fgColors" :key="color" @click="fgColor = color" class="color char _button" :class="{ active: fgColor === color }">
|
2021-01-09 22:02:26 +09:00
|
|
|
<div class="preview" :style="{ color: color.forPreview ? color.forPreview : bgColor?.kind === 'light' ? '#5f5f5f' : '#dadada' }">A</div>
|
2021-01-09 21:47:07 +09:00
|
|
|
</button>
|
|
|
|
</div>
|
2020-07-11 12:12:35 +09:00
|
|
|
</div>
|
2021-01-09 17:18:45 +09:00
|
|
|
</div>
|
|
|
|
<div class="_formItem preview">
|
|
|
|
<div class="_formLabel">{{ $ts.preview }}</div>
|
|
|
|
<div class="_formPanel preview">
|
|
|
|
<MkSample class="preview"/>
|
2020-07-11 12:12:35 +09:00
|
|
|
</div>
|
2021-01-09 17:18:45 +09:00
|
|
|
</div>
|
|
|
|
<FormButton @click="saveAs">{{ $ts.saveAs }}</FormButton>
|
|
|
|
</FormBase>
|
2020-07-11 12:12:35 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2020-07-11 12:12:35 +09:00
|
|
|
import { faPalette, faChevronDown, faKeyboard } from '@fortawesome/free-solid-svg-icons';
|
2020-10-18 00:49:02 +09:00
|
|
|
import { toUnicode } from 'punycode';
|
2021-01-09 17:18:45 +09:00
|
|
|
import * as tinycolor from 'tinycolor2';
|
|
|
|
import { v4 as uuid} from 'uuid';
|
2020-07-11 12:12:35 +09:00
|
|
|
|
2021-01-09 17:18:45 +09:00
|
|
|
import FormBase from '@/components/form/base.vue';
|
|
|
|
import FormButton from '@/components/form/button.vue';
|
2020-10-18 00:49:02 +09:00
|
|
|
import MkSample from '@/components/sample.vue';
|
2020-07-11 12:12:35 +09:00
|
|
|
|
2021-01-09 17:18:45 +09:00
|
|
|
import { Theme, applyTheme, validateTheme } from '@/scripts/theme';
|
2020-10-17 20:12:00 +09:00
|
|
|
import { host } from '@/config';
|
|
|
|
import * as os from '@/os';
|
2020-12-19 10:55:52 +09:00
|
|
|
import { ColdDeviceStorage } from '@/store';
|
2020-07-11 12:12:35 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-07-11 12:12:35 +09:00
|
|
|
components: {
|
2021-01-09 17:18:45 +09:00
|
|
|
FormBase,
|
|
|
|
FormButton,
|
2020-10-18 00:49:02 +09:00
|
|
|
MkSample,
|
2020-07-11 12:12:35 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2020-10-17 20:12:00 +09:00
|
|
|
INFO: {
|
2020-12-26 10:47:36 +09:00
|
|
|
title: this.$ts.themeEditor,
|
2020-11-03 20:36:12 +09:00
|
|
|
icon: faPalette,
|
2020-10-17 20:12:00 +09:00
|
|
|
},
|
2021-01-09 17:18:45 +09:00
|
|
|
bgColors: [
|
|
|
|
{ color: '#f5f5f5', kind: 'light', forPreview: '#f5f5f5' },
|
|
|
|
{ color: '#f0eee9', kind: 'light', forPreview: '#f3e2b9' },
|
|
|
|
{ color: '#e9eff0', kind: 'light', forPreview: '#bfe3e8' },
|
|
|
|
{ color: '#f0e9ee', kind: 'light', forPreview: '#f1d1e8' },
|
2021-01-09 21:47:07 +09:00
|
|
|
{ color: '#dce2e0', kind: 'light', forPreview: '#a4dccc' },
|
|
|
|
{ color: '#e2e0dc', kind: 'light', forPreview: '#d8c7a5' },
|
|
|
|
{ color: '#d5dbe0', kind: 'light', forPreview: '#b0cae0' },
|
|
|
|
{ color: '#dad5d5', kind: 'light', forPreview: '#d6afaf' },
|
|
|
|
{ color: '#2b2b2b', kind: 'dark', forPreview: '#444444' },
|
2021-01-09 17:18:45 +09:00
|
|
|
{ color: '#362e29', kind: 'dark', forPreview: '#735c4d' },
|
|
|
|
{ color: '#303629', kind: 'dark', forPreview: '#506d2f' },
|
|
|
|
{ color: '#293436', kind: 'dark', forPreview: '#258192' },
|
2021-01-09 21:47:07 +09:00
|
|
|
{ color: '#2e2936', kind: 'dark', forPreview: '#504069' },
|
|
|
|
{ color: '#252722', kind: 'dark', forPreview: '#3c462f' },
|
|
|
|
{ color: '#212525', kind: 'dark', forPreview: '#303e3e' },
|
|
|
|
{ color: '#191919', kind: 'dark', forPreview: '#272727' },
|
2021-01-09 17:18:45 +09:00
|
|
|
],
|
|
|
|
bgColor: null,
|
|
|
|
accentColors: ['#e36749', '#f29924', '#98c934', '#34c9a9', '#34a1c9', '#606df7', '#8d34c9', '#e84d83'],
|
|
|
|
accentColor: null,
|
|
|
|
fgColors: [
|
|
|
|
{ color: 'none', forLight: '#5f5f5f', forDark: '#dadada', forPreview: null },
|
|
|
|
{ color: 'red', forLight: '#7f6666', forDark: '#e4d1d1', forPreview: '#ca4343' },
|
|
|
|
{ color: 'yellow', forLight: '#736955', forDark: '#e0d5c0', forPreview: '#d49923' },
|
|
|
|
{ color: 'green', forLight: '#586d5b', forDark: '#d1e4d4', forPreview: '#4cbd5c' },
|
|
|
|
{ color: 'cyan', forLight: '#5d7475', forDark: '#d1e3e4', forPreview: '#2abdc3' },
|
2021-01-09 21:47:07 +09:00
|
|
|
{ color: 'blue', forLight: '#676880', forDark: '#d1d2e4', forPreview: '#7275d8' },
|
2021-01-09 17:18:45 +09:00
|
|
|
{ color: 'pink', forLight: '#84667d', forDark: '#e4d1e0', forPreview: '#b12390' },
|
|
|
|
],
|
|
|
|
fgColor: null,
|
|
|
|
faPalette,
|
2020-07-11 12:12:35 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-01-09 17:18:45 +09:00
|
|
|
created() {
|
|
|
|
const currentBgColor = getComputedStyle(document.documentElement).getPropertyValue('--bg');
|
|
|
|
const matchedBgColor = this.bgColors.find(x => tinycolor(x.color).toRgbString() === tinycolor(currentBgColor).toRgbString());
|
2021-01-09 22:02:26 +09:00
|
|
|
if (matchedBgColor) this.bgColor = matchedBgColor;
|
2021-01-09 17:18:45 +09:00
|
|
|
const currentAccentColor = getComputedStyle(document.documentElement).getPropertyValue('--accent');
|
|
|
|
const matchedAccentColor = this.accentColors.find(x => tinycolor(x).toRgbString() === tinycolor(currentAccentColor).toRgbString());
|
2021-01-09 22:02:26 +09:00
|
|
|
if (matchedAccentColor) this.accentColor = matchedAccentColor;
|
2021-01-09 17:18:45 +09:00
|
|
|
const currentFgColor = getComputedStyle(document.documentElement).getPropertyValue('--fg');
|
|
|
|
const matchedFgColor = this.fgColors.find(x => [tinycolor(x.forLight).toRgbString(), tinycolor(x.forDark).toRgbString()].includes(tinycolor(currentFgColor).toRgbString()));
|
2021-01-09 22:02:26 +09:00
|
|
|
if (matchedFgColor) this.fgColor = matchedFgColor;
|
2021-01-09 17:18:45 +09:00
|
|
|
|
|
|
|
this.$watch('bgColor', this.apply);
|
|
|
|
this.$watch('accentColor', this.apply);
|
|
|
|
this.$watch('fgColor', this.apply);
|
2020-07-11 12:12:35 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2021-01-09 17:18:45 +09:00
|
|
|
convert() {
|
|
|
|
return {
|
|
|
|
id: '#MY_THEME#',
|
|
|
|
name: this.$ts.myTheme,
|
|
|
|
base: this.bgColor.kind,
|
|
|
|
props: {
|
|
|
|
bg: this.bgColor.color,
|
|
|
|
fg: this.bgColor.kind === 'light' ? this.fgColor.forLight : this.fgColor.forDark,
|
|
|
|
accent: this.accentColor,
|
|
|
|
}
|
|
|
|
};
|
2020-07-11 12:12:35 +09:00
|
|
|
},
|
|
|
|
|
2021-01-09 17:18:45 +09:00
|
|
|
apply() {
|
2021-01-09 22:02:26 +09:00
|
|
|
if (this.bgColor == null) this.bgColor = this.bgColors[0];
|
|
|
|
if (this.accentColor == null) this.accentColor = this.accentColors[0];
|
|
|
|
if (this.fgColor == null) this.fgColor = this.fgColors[0];
|
|
|
|
|
2021-01-09 17:18:45 +09:00
|
|
|
const theme = this.convert();
|
|
|
|
applyTheme(theme, true);
|
2020-07-11 12:12:35 +09:00
|
|
|
|
2021-01-09 17:18:45 +09:00
|
|
|
const themes = ColdDeviceStorage.get('themes').filter(t => t.id != '#MY_THEME#').concat(theme);
|
|
|
|
ColdDeviceStorage.set('themes', themes);
|
|
|
|
ColdDeviceStorage.set('lightTheme', theme.id);
|
|
|
|
ColdDeviceStorage.set('darkTheme', theme.id);
|
2020-07-11 12:12:35 +09:00
|
|
|
},
|
2021-01-09 17:18:45 +09:00
|
|
|
|
|
|
|
async saveAs() {
|
|
|
|
const { canceled, result: name } = await os.dialog({
|
|
|
|
title: this.$ts.name,
|
|
|
|
input: {
|
|
|
|
allowEmpty: false
|
|
|
|
}
|
2020-07-11 12:12:35 +09:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2021-01-09 17:18:45 +09:00
|
|
|
|
|
|
|
const theme = this.convert();
|
|
|
|
theme.id = uuid();
|
|
|
|
theme.name = name;
|
|
|
|
theme.author = `@${this.$i.username}@${toUnicode(host)}`;
|
2020-12-19 10:55:52 +09:00
|
|
|
const themes = ColdDeviceStorage.get('themes').concat(theme);
|
|
|
|
ColdDeviceStorage.set('themes', themes);
|
2021-01-09 17:18:45 +09:00
|
|
|
ColdDeviceStorage.set('lightTheme', theme.id);
|
|
|
|
ColdDeviceStorage.set('darkTheme', theme.id);
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-07-11 12:12:35 +09:00
|
|
|
type: 'success',
|
|
|
|
text: this.$t('_theme.installed', { name: theme.name })
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-01-09 17:18:45 +09:00
|
|
|
.cwepdizn {
|
|
|
|
max-width: 800px;
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
|
|
> .colorPicker {
|
|
|
|
> .colors {
|
|
|
|
padding: 32px;
|
|
|
|
text-align: center;
|
|
|
|
|
2021-01-09 21:47:07 +09:00
|
|
|
> .row {
|
|
|
|
> .color {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
border-radius: 8px;
|
2021-01-09 17:18:45 +09:00
|
|
|
|
|
|
|
> .preview {
|
2021-01-09 21:47:07 +09:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
margin: auto;
|
|
|
|
width: 42px;
|
|
|
|
height: 42px;
|
|
|
|
border-radius: 4px;
|
|
|
|
box-shadow: 0 2px 4px rgb(0 0 0 / 30%);
|
|
|
|
transition: transform 0.15s ease;
|
2020-07-11 12:12:35 +09:00
|
|
|
}
|
|
|
|
|
2021-01-09 21:47:07 +09:00
|
|
|
&:hover {
|
|
|
|
> .preview {
|
|
|
|
transform: scale(1.1);
|
|
|
|
}
|
|
|
|
}
|
2020-07-11 12:12:35 +09:00
|
|
|
|
2021-01-09 21:47:07 +09:00
|
|
|
&.active {
|
|
|
|
box-shadow: 0 0 0 2px var(--divider) inset;
|
|
|
|
}
|
2020-07-11 12:12:35 +09:00
|
|
|
|
2021-01-09 21:47:07 +09:00
|
|
|
&.rounded {
|
2021-01-09 17:18:45 +09:00
|
|
|
border-radius: 999px;
|
2021-01-09 21:47:07 +09:00
|
|
|
|
|
|
|
> .preview {
|
|
|
|
border-radius: 999px;
|
|
|
|
}
|
2020-07-11 12:12:35 +09:00
|
|
|
}
|
2021-01-09 17:18:45 +09:00
|
|
|
|
2021-01-09 21:47:07 +09:00
|
|
|
&.char {
|
|
|
|
line-height: 42px;
|
|
|
|
}
|
2021-01-09 17:18:45 +09:00
|
|
|
}
|
2020-07-11 12:12:35 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-09 17:18:45 +09:00
|
|
|
|
|
|
|
> .preview > .preview > .preview {
|
|
|
|
box-shadow: none;
|
|
|
|
background: transparent;
|
|
|
|
}
|
2020-07-11 12:12:35 +09:00
|
|
|
}
|
|
|
|
</style>
|